OSDN Git Service

df4d003176555c14f8563679e9b86a4b89ccae0d
[pf3gnuchains/gcc-fork.git] / gcc / config / v850 / v850.c
1 /* Subroutines for insn-output.c for NEC V850 series
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3    Free Software Foundation, Inc.
4    Contributed by Jeff Law (law@cygnus.com).
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "tree.h"
26 #include "rtl.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "real.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "output.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "recog.h"
36 #include "expr.h"
37 #include "function.h"
38 #include "toplev.h"
39 #include "cpplib.h"
40 #include "c-lex.h"
41 #include "ggc.h"
42 #include "integrate.h"
43 #include "tm_p.h"
44 #include "target.h"
45 #include "target-def.h"
46
47 #ifndef streq
48 #define streq(a,b) (strcmp (a, b) == 0)
49 #endif
50
51 /* Function prototypes for stupid compilers:  */
52 static void const_double_split       PARAMS ((rtx, HOST_WIDE_INT *, HOST_WIDE_INT *));
53 static int  const_costs_int          PARAMS ((HOST_WIDE_INT, int));
54 static void substitute_ep_register   PARAMS ((rtx, rtx, int, int, rtx *, rtx *));
55 static int  ep_memory_offset         PARAMS ((enum machine_mode, int));
56 static void v850_set_data_area       PARAMS ((tree, v850_data_area));
57 const struct attribute_spec v850_attribute_table[];
58 static tree v850_handle_interrupt_attribute PARAMS ((tree *, tree, tree, int, bool *));
59 static tree v850_handle_data_area_attribute PARAMS ((tree *, tree, tree, int, bool *));
60 static void v850_insert_attributes   PARAMS ((tree, tree *));
61 static void v850_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT));
62 static void v850_encode_data_area    PARAMS ((tree));
63 static void v850_encode_section_info PARAMS ((tree, int));
64
65 /* True if the current function has anonymous arguments.  */
66 int current_function_anonymous_args;
67
68 /* Information about the various small memory areas.  */
69 struct small_memory_info small_memory[ (int)SMALL_MEMORY_max ] =
70 {
71   /* name       value           max             physical max */
72   { "tda",      (char *)0,      0,              256 },
73   { "sda",      (char *)0,      0,              65536 },
74   { "zda",      (char *)0,      0,              32768 },
75 };
76
77 /* Names of the various data areas used on the v850.  */
78 tree GHS_default_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
79 tree GHS_current_section_names [(int) COUNT_OF_GHS_SECTION_KINDS];
80
81 /* Track the current data area set by the data area pragma (which 
82    can be nested).  Tested by check_default_data_area.  */
83 data_area_stack_element * data_area_stack = NULL;
84
85 /* True if we don't need to check any more if the current
86    function is an interrupt handler.  */
87 static int v850_interrupt_cache_p = FALSE;
88
89 /* Whether current function is an interrupt handler.  */
90 static int v850_interrupt_p = FALSE;
91 \f
92 /* Initialize the GCC target structure.  */
93 #undef TARGET_ASM_ALIGNED_HI_OP
94 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
95
96 #undef TARGET_ATTRIBUTE_TABLE
97 #define TARGET_ATTRIBUTE_TABLE v850_attribute_table
98
99 #undef TARGET_INSERT_ATTRIBUTES
100 #define TARGET_INSERT_ATTRIBUTES v850_insert_attributes
101
102 #undef  TARGET_ASM_SELECT_SECTION
103 #define TARGET_ASM_SELECT_SECTION  v850_select_section
104
105 #undef TARGET_ENCODE_SECTION_INFO
106 #define TARGET_ENCODE_SECTION_INFO v850_encode_section_info
107
108 struct gcc_target targetm = TARGET_INITIALIZER;
109 \f
110 /* Sometimes certain combinations of command options do not make
111    sense on a particular target machine.  You can define a macro
112    `OVERRIDE_OPTIONS' to take account of this.  This macro, if
113    defined, is executed once just after all the command options have
114    been parsed.
115
116    Don't use this macro to turn on various extra optimizations for
117    `-O'.  That is what `OPTIMIZATION_OPTIONS' is for.  */
118
119 void
120 override_options ()
121 {
122   int i;
123   extern int atoi PARAMS ((const char *));
124
125   /* Parse -m{s,t,z}da=nnn switches */
126   for (i = 0; i < (int)SMALL_MEMORY_max; i++)
127     {
128       if (small_memory[i].value)
129         {
130           if (!ISDIGIT (*small_memory[i].value))
131             error ("%s=%s is not numeric",
132                    small_memory[i].name,
133                    small_memory[i].value);
134           else
135             {
136               small_memory[i].max = atoi (small_memory[i].value);
137               if (small_memory[i].max > small_memory[i].physical_max)
138                 error ("%s=%s is too large",
139                    small_memory[i].name,
140                    small_memory[i].value);
141             }
142         }
143     }
144 }
145
146 \f
147 /* Output assembly code for the start of the file.  */
148
149 void
150 asm_file_start (file)
151      FILE *file;
152 {
153   output_file_directive (file, main_input_filename);
154 }
155 \f
156
157 /* Return an RTX to represent where a value with mode MODE will be returned
158    from a function.  If the result is 0, the argument is pushed.  */
159
160 rtx
161 function_arg (cum, mode, type, named)
162      CUMULATIVE_ARGS *cum;
163      enum machine_mode mode;
164      tree type;
165      int named;
166 {
167   rtx result = 0;
168   int size, align;
169
170   if (TARGET_GHS && !named)
171     return NULL_RTX;
172
173   if (mode == BLKmode)
174     size = int_size_in_bytes (type);
175   else
176     size = GET_MODE_SIZE (mode);
177
178   if (type)
179     align = TYPE_ALIGN (type) / BITS_PER_UNIT;
180   else
181     align = size;
182
183   cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
184
185   if (cum->nbytes > 4 * UNITS_PER_WORD)
186     return 0;
187
188   if (type == NULL_TREE
189       && cum->nbytes + size > 4 * UNITS_PER_WORD)
190     return 0;
191
192   switch (cum->nbytes / UNITS_PER_WORD)
193     {
194     case 0:
195       result = gen_rtx_REG (mode, 6);
196       break;
197     case 1:
198       result = gen_rtx_REG (mode, 7);
199       break;
200     case 2:
201       result = gen_rtx_REG (mode, 8);
202       break;
203     case 3:
204       result = gen_rtx_REG (mode, 9);
205       break;
206     default:
207       result = 0;
208     }
209
210   return result;
211 }
212
213 \f
214 /* Return the number of words which must be put into registers
215    for values which are part in registers and part in memory.  */
216
217 int
218 function_arg_partial_nregs (cum, mode, type, named)
219      CUMULATIVE_ARGS *cum;
220      enum machine_mode mode;
221      tree type;
222      int named;
223 {
224   int size, align;
225
226   if (TARGET_GHS && !named)
227     return 0;
228
229   if (mode == BLKmode)
230     size = int_size_in_bytes (type);
231   else
232     size = GET_MODE_SIZE (mode);
233
234   if (type)
235     align = TYPE_ALIGN (type) / BITS_PER_UNIT;
236   else
237     align = size;
238
239   cum->nbytes = (cum->nbytes + align - 1) &~(align - 1);
240
241   if (cum->nbytes > 4 * UNITS_PER_WORD)
242     return 0;
243
244   if (cum->nbytes + size <= 4 * UNITS_PER_WORD)
245     return 0;
246
247   if (type == NULL_TREE
248       && cum->nbytes + size > 4 * UNITS_PER_WORD)
249     return 0;
250
251   return (4 * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
252 }
253
254 \f
255 /* Return the high and low words of a CONST_DOUBLE */
256
257 static void
258 const_double_split (x, p_high, p_low)
259      rtx x;
260      HOST_WIDE_INT *p_high;
261      HOST_WIDE_INT *p_low;
262 {
263   if (GET_CODE (x) == CONST_DOUBLE)
264     {
265       long t[2];
266       REAL_VALUE_TYPE rv;
267
268       switch (GET_MODE (x))
269         {
270         case DFmode:
271           REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
272           REAL_VALUE_TO_TARGET_DOUBLE (rv, t);
273           *p_high = t[1];       /* since v850 is little endian */
274           *p_low = t[0];        /* high is second word */
275           return;
276
277         case SFmode:
278           REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
279           REAL_VALUE_TO_TARGET_SINGLE (rv, *p_high);
280           *p_low = 0;
281           return;
282
283         case VOIDmode:
284         case DImode:
285           *p_high = CONST_DOUBLE_HIGH (x);
286           *p_low  = CONST_DOUBLE_LOW (x);
287           return;
288
289         default:
290           break;
291         }
292     }
293
294   fatal_insn ("const_double_split got a bad insn:", x);
295 }
296
297 \f
298 /* Return the cost of the rtx R with code CODE.  */
299
300 static int
301 const_costs_int (value, zero_cost)
302      HOST_WIDE_INT value;
303      int zero_cost;
304 {
305   if (CONST_OK_FOR_I (value))
306       return zero_cost;
307   else if (CONST_OK_FOR_J (value))
308     return 1;
309   else if (CONST_OK_FOR_K (value))
310     return 2;
311   else
312     return 4;
313 }
314
315 int
316 const_costs (r, c)
317      rtx r;
318      enum rtx_code c;
319 {
320   HOST_WIDE_INT high, low;
321
322   switch (c)
323     {
324     case CONST_INT:
325       return const_costs_int (INTVAL (r), 0);
326
327     case CONST_DOUBLE:
328       const_double_split (r, &high, &low);
329       if (GET_MODE (r) == SFmode)
330         return const_costs_int (high, 1);
331       else
332         return const_costs_int (high, 1) + const_costs_int (low, 1);
333
334     case SYMBOL_REF:
335     case LABEL_REF:
336     case CONST:
337       return 2;
338
339     case HIGH:
340       return 1;
341
342     default:
343       return 4;
344     }
345 }
346
347 \f
348 /* Print operand X using operand code CODE to assembly language output file
349    FILE.  */
350
351 void
352 print_operand (file, x, code)
353      FILE *file;
354      rtx x;
355      int code;
356 {
357   HOST_WIDE_INT high, low;
358
359   switch (code)
360     {
361     case 'c':
362       /* We use 'c' operands with symbols for .vtinherit */
363       if (GET_CODE (x) == SYMBOL_REF)
364         {
365           output_addr_const(file, x);
366           break;
367         }
368       /* fall through */
369     case 'b':
370     case 'B':
371     case 'C':
372       switch ((code == 'B' || code == 'C')
373               ? reverse_condition (GET_CODE (x)) : GET_CODE (x))
374         {
375           case NE:
376             if (code == 'c' || code == 'C')
377               fprintf (file, "nz");
378             else
379               fprintf (file, "ne");
380             break;
381           case EQ:
382             if (code == 'c' || code == 'C')
383               fprintf (file, "z");
384             else
385               fprintf (file, "e");
386             break;
387           case GE:
388             fprintf (file, "ge");
389             break;
390           case GT:
391             fprintf (file, "gt");
392             break;
393           case LE:
394             fprintf (file, "le");
395             break;
396           case LT:
397             fprintf (file, "lt");
398             break;
399           case GEU:
400             fprintf (file, "nl");
401             break;
402           case GTU:
403             fprintf (file, "h");
404             break;
405           case LEU:
406             fprintf (file, "nh");
407             break;
408           case LTU:
409             fprintf (file, "l");
410             break;
411           default:
412             abort ();
413         }
414       break;
415     case 'F':                   /* high word of CONST_DOUBLE */
416       if (GET_CODE (x) == CONST_INT)
417         fprintf (file, "%d", (INTVAL (x) >= 0) ? 0 : -1);
418       else if (GET_CODE (x) == CONST_DOUBLE)
419         {
420           const_double_split (x, &high, &low);
421           fprintf (file, "%ld", (long) high);
422         }
423       else
424         abort ();
425       break;
426     case 'G':                   /* low word of CONST_DOUBLE */
427       if (GET_CODE (x) == CONST_INT)
428         fprintf (file, "%ld", (long) INTVAL (x));
429       else if (GET_CODE (x) == CONST_DOUBLE)
430         {
431           const_double_split (x, &high, &low);
432           fprintf (file, "%ld", (long) low);
433         }
434       else
435         abort ();
436       break;
437     case 'L':
438       fprintf (file, "%d\n", INTVAL (x) & 0xffff);
439       break;
440     case 'M':
441       fprintf (file, "%d", exact_log2 (INTVAL (x)));
442       break;
443     case 'O':
444       if (special_symbolref_operand (x, VOIDmode))
445         {
446           const char *name;
447
448           if (GET_CODE (x) == SYMBOL_REF)
449             name = XSTR (x, 0);
450           else if (GET_CODE (x) == CONST)
451             name = XSTR (XEXP (XEXP (x, 0), 0), 0);
452           else
453             abort ();
454
455           if (ZDA_NAME_P (name))
456             fprintf (file, "zdaoff");
457           else if (SDA_NAME_P (name))
458             fprintf (file, "sdaoff");
459           else if (TDA_NAME_P (name))
460             fprintf (file, "tdaoff");
461           else
462             abort ();
463         }
464       else
465         abort ();
466       break;
467     case 'P':
468       if (special_symbolref_operand (x, VOIDmode))
469         output_addr_const (file, x);
470       else
471         abort ();
472       break;
473     case 'Q':
474       if (special_symbolref_operand (x, VOIDmode))
475         {
476           const char *name;
477
478           if (GET_CODE (x) == SYMBOL_REF)
479             name = XSTR (x, 0);
480           else if (GET_CODE (x) == CONST)
481             name = XSTR (XEXP (XEXP (x, 0), 0), 0);
482           else
483             abort ();
484
485           if (ZDA_NAME_P (name))
486             fprintf (file, "r0");
487           else if (SDA_NAME_P (name))
488             fprintf (file, "gp");
489           else if (TDA_NAME_P (name))
490             fprintf (file, "ep");
491           else
492             abort ();
493         }
494       else
495         abort ();
496       break;
497     case 'R':           /* 2nd word of a double.  */
498       switch (GET_CODE (x))
499         {
500         case REG:
501           fprintf (file, reg_names[REGNO (x) + 1]);
502           break;
503         case MEM:
504           x = XEXP (adjust_address (x, SImode, 4), 0);
505           print_operand_address (file, x);
506           if (GET_CODE (x) == CONST_INT)
507             fprintf (file, "[r0]");
508           break;
509           
510         default:
511           break;
512         }
513       break;
514     case 'S':
515       {
516         /* if it's a reference to a TDA variable, use sst/sld vs. st/ld */
517         if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), FALSE))
518           fputs ("s", file);
519
520         break;
521       }
522     case 'T':
523       {
524         /* Like an 'S' operand above, but for unsigned loads only.  */
525         if (GET_CODE (x) == MEM && ep_memory_operand (x, GET_MODE (x), TRUE))
526           fputs ("s", file);
527
528         break;
529       }
530     case 'W':                   /* print the instruction suffix */
531       switch (GET_MODE (x))
532         {
533         default:
534           abort ();
535
536         case QImode: fputs (".b", file); break;
537         case HImode: fputs (".h", file); break;
538         case SImode: fputs (".w", file); break;
539         case SFmode: fputs (".w", file); break;
540         }
541       break;
542     case '.':                   /* register r0 */
543       fputs (reg_names[0], file);
544       break;
545     case 'z':                   /* reg or zero */
546       if (x == const0_rtx)
547         fputs (reg_names[0], file);
548       else if (GET_CODE (x) == REG)
549         fputs (reg_names[REGNO (x)], file);
550       else
551         abort ();
552       break;
553     default:
554       switch (GET_CODE (x))
555         {
556         case MEM:
557           if (GET_CODE (XEXP (x, 0)) == CONST_INT)
558             output_address (gen_rtx_PLUS (SImode, gen_rtx (REG, SImode, 0),
559                                           XEXP (x, 0)));
560           else
561             output_address (XEXP (x, 0));
562           break;
563
564         case REG:
565           fputs (reg_names[REGNO (x)], file);
566           break;
567         case SUBREG:
568           fputs (reg_names[subreg_regno (x)], file);
569           break;
570         case CONST_INT:
571         case SYMBOL_REF:
572         case CONST:
573         case LABEL_REF:
574         case CODE_LABEL:
575           print_operand_address (file, x);
576           break;
577         default:
578           abort ();
579         }
580       break;
581
582     }
583 }
584
585 \f
586 /* Output assembly language output for the address ADDR to FILE.  */
587
588 void
589 print_operand_address (file, addr)
590      FILE *file;
591      rtx addr;
592 {
593   switch (GET_CODE (addr))
594     {
595     case REG:
596       fprintf (file, "0[");
597       print_operand (file, addr, 0);
598       fprintf (file, "]");
599       break;
600     case LO_SUM:
601       if (GET_CODE (XEXP (addr, 0)) == REG)
602         {
603           /* reg,foo */
604           fprintf (file, "lo(");
605           print_operand (file, XEXP (addr, 1), 0);
606           fprintf (file, ")[");
607           print_operand (file, XEXP (addr, 0), 0);
608           fprintf (file, "]");
609         }
610       break;
611     case PLUS:
612       if (GET_CODE (XEXP (addr, 0)) == REG
613           || GET_CODE (XEXP (addr, 0)) == SUBREG)
614         {
615           /* reg,foo */
616           print_operand (file, XEXP (addr, 1), 0);
617           fprintf (file, "[");
618           print_operand (file, XEXP (addr, 0), 0);
619           fprintf (file, "]");
620         }
621       else
622         {
623           print_operand (file, XEXP (addr, 0), 0);
624           fprintf (file, "+");
625           print_operand (file, XEXP (addr, 1), 0);
626         }
627       break;
628     case SYMBOL_REF:
629       if (ENCODED_NAME_P (XSTR (addr, 0)))
630         {
631           const char *name = XSTR (addr, 0);
632           const char *off_name;
633           const char *reg_name;
634
635           if (ZDA_NAME_P (name))
636             {
637               off_name = "zdaoff";
638               reg_name = "r0";
639             }
640           else if (SDA_NAME_P (name))
641             {
642               off_name = "sdaoff";
643               reg_name = "gp";
644             }
645           else if (TDA_NAME_P (name))
646             {
647               off_name = "tdaoff";
648               reg_name = "ep";
649             }
650           else
651             abort ();
652
653           fprintf (file, "%s(", off_name);
654           output_addr_const (file, addr);
655           fprintf (file, ")[%s]", reg_name);
656         }
657       else
658         output_addr_const (file, addr);
659       break;
660     case CONST:
661       if (special_symbolref_operand (addr, VOIDmode))
662         {
663           const char *name = XSTR (XEXP (XEXP (addr, 0), 0), 0);
664           const char *off_name;
665           const char *reg_name;
666
667           if (ZDA_NAME_P (name))
668             {
669               off_name = "zdaoff";
670               reg_name = "r0";
671             }
672           else if (SDA_NAME_P (name))
673             {
674               off_name = "sdaoff";
675               reg_name = "gp";
676             }
677           else if (TDA_NAME_P (name))
678             {
679               off_name = "tdaoff";
680               reg_name = "ep";
681             }
682           else
683             abort ();
684
685           fprintf (file, "%s(", off_name);
686           output_addr_const (file, addr);
687           fprintf (file, ")[%s]", reg_name);
688         }
689       else
690         output_addr_const (file, addr);
691       break;
692     default:
693       output_addr_const (file, addr);
694       break;
695     }
696 }
697
698 \f
699 /* Return appropriate code to load up a 1, 2, or 4 integer/floating
700    point value.  */
701
702 const char *
703 output_move_single (operands)
704      rtx *operands;
705 {
706   rtx dst = operands[0];
707   rtx src = operands[1];
708
709   if (REG_P (dst))
710     {
711       if (REG_P (src))
712         return "mov %1,%0";
713
714       else if (GET_CODE (src) == CONST_INT)
715         {
716           HOST_WIDE_INT value = INTVAL (src);
717
718           if (CONST_OK_FOR_J (value))           /* signed 5 bit immediate */
719             return "mov %1,%0";
720
721           else if (CONST_OK_FOR_K (value))      /* signed 16 bit immediate */
722             return "movea lo(%1),%.,%0";
723
724           else if (CONST_OK_FOR_L (value))      /* upper 16 bits were set */
725             return "movhi hi(%1),%.,%0";
726
727           else                                  /* random constant */
728             return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
729         }
730
731       else if (GET_CODE (src) == CONST_DOUBLE && GET_MODE (src) == SFmode)
732         {
733           HOST_WIDE_INT high, low;
734
735           const_double_split (src, &high, &low);
736           if (CONST_OK_FOR_J (high))            /* signed 5 bit immediate */
737             return "mov %F1,%0";
738
739           else if (CONST_OK_FOR_K (high))       /* signed 16 bit immediate */
740             return "movea lo(%F1),%.,%0";
741
742           else if (CONST_OK_FOR_L (high))       /* upper 16 bits were set */
743             return "movhi hi(%F1),%.,%0";
744
745           else                                  /* random constant */
746             return "movhi hi(%F1),%.,%0\n\tmovea lo(%F1),%0,%0";
747         }
748
749       else if (GET_CODE (src) == MEM)
750         return "%S1ld%W1 %1,%0";
751
752       else if (special_symbolref_operand (src, VOIDmode))
753         return "movea %O1(%P1),%Q1,%0";
754
755       else if (GET_CODE (src) == LABEL_REF
756                || GET_CODE (src) == SYMBOL_REF
757                || GET_CODE (src) == CONST)
758         {
759           return "movhi hi(%1),%.,%0\n\tmovea lo(%1),%0,%0";
760         }
761
762       else if (GET_CODE (src) == HIGH)
763         return "movhi hi(%1),%.,%0";
764
765       else if (GET_CODE (src) == LO_SUM)
766         {
767           operands[2] = XEXP (src, 0);
768           operands[3] = XEXP (src, 1);
769           return "movea lo(%3),%2,%0";
770         }
771     }
772
773   else if (GET_CODE (dst) == MEM)
774     {
775       if (REG_P (src))
776         return "%S0st%W0 %1,%0";
777
778       else if (GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
779         return "%S0st%W0 %.,%0";
780
781       else if (GET_CODE (src) == CONST_DOUBLE
782                && CONST0_RTX (GET_MODE (dst)) == src)
783         return "%S0st%W0 %.,%0";
784     }
785
786   fatal_insn ("output_move_single:", gen_rtx_SET (VOIDmode, dst, src));
787   return "";
788 }
789
790 \f
791 /* Return appropriate code to load up an 8 byte integer or
792    floating point value */
793
794 const char *
795 output_move_double (operands)
796     rtx *operands;
797 {
798   enum machine_mode mode = GET_MODE (operands[0]);
799   rtx dst = operands[0];
800   rtx src = operands[1];
801
802   if (register_operand (dst, mode)
803       && register_operand (src, mode))
804     {
805       if (REGNO (src) + 1 == REGNO (dst))
806         return "mov %R1,%R0\n\tmov %1,%0";
807       else
808         return "mov %1,%0\n\tmov %R1,%R0";
809     }
810
811   /* Storing 0 */
812   if (GET_CODE (dst) == MEM
813       && ((GET_CODE (src) == CONST_INT && INTVAL (src) == 0)
814           || (GET_CODE (src) == CONST_DOUBLE && CONST_DOUBLE_OK_FOR_G (src))))
815     return "st.w %.,%0\n\tst.w %.,%R0";
816
817   if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
818     {
819       HOST_WIDE_INT high_low[2];
820       int i;
821       rtx xop[10];
822
823       if (GET_CODE (src) == CONST_DOUBLE)
824         const_double_split (src, &high_low[1], &high_low[0]);
825       else
826         {
827           high_low[0] = INTVAL (src);
828           high_low[1] = (INTVAL (src) >= 0) ? 0 : -1;
829         }
830
831       for (i = 0; i < 2; i++)
832         {
833           xop[0] = gen_rtx_REG (SImode, REGNO (dst)+i);
834           xop[1] = GEN_INT (high_low[i]);
835           output_asm_insn (output_move_single (xop), xop);
836         }
837
838       return "";
839     }
840
841   if (GET_CODE (src) == MEM)
842     {
843       int ptrreg = -1;
844       int dreg = REGNO (dst);
845       rtx inside = XEXP (src, 0);
846
847       if (GET_CODE (inside) == REG)
848         ptrreg = REGNO (inside);
849       else if (GET_CODE (inside) == SUBREG)
850         ptrreg = subreg_regno (inside);
851       else if (GET_CODE (inside) == PLUS)
852         ptrreg = REGNO (XEXP (inside, 0));
853       else if (GET_CODE (inside) == LO_SUM)
854         ptrreg = REGNO (XEXP (inside, 0));
855
856       if (dreg == ptrreg)
857         return "ld.w %R1,%R0\n\tld.w %1,%0";
858     }
859
860   if (GET_CODE (src) == MEM)
861     return "ld.w %1,%0\n\tld.w %R1,%R0";
862   
863   if (GET_CODE (dst) == MEM)
864     return "st.w %1,%0\n\tst.w %R1,%R0";
865
866   return "mov %1,%0\n\tmov %R1,%R0";
867 }
868
869 \f
870 /* Return maximum offset supported for a short EP memory reference of mode
871    MODE and signedness UNSIGNEDP.  */
872
873 static int
874 ep_memory_offset (mode, unsignedp)
875      enum machine_mode mode;
876      int ATTRIBUTE_UNUSED unsignedp;
877 {
878   int max_offset = 0;
879
880   switch (mode)
881     {
882     case QImode:
883       max_offset = (1 << 7);
884       break;
885
886     case HImode:
887       max_offset = (1 << 8);
888       break;
889
890     case SImode:
891     case SFmode:
892       max_offset = (1 << 8);
893       break;
894       
895     default:
896       break;
897     }
898
899   return max_offset;
900 }
901
902 /* Return true if OP is a valid short EP memory reference */
903
904 int
905 ep_memory_operand (op, mode, unsigned_load)
906      rtx op;
907      enum machine_mode mode;
908      int unsigned_load;
909 {
910   rtx addr, op0, op1;
911   int max_offset;
912   int mask;
913
914   if (GET_CODE (op) != MEM)
915     return FALSE;
916
917   max_offset = ep_memory_offset (mode, unsigned_load);
918
919   mask = GET_MODE_SIZE (mode) - 1;
920
921   addr = XEXP (op, 0);
922   if (GET_CODE (addr) == CONST)
923     addr = XEXP (addr, 0);
924
925   switch (GET_CODE (addr))
926     {
927     default:
928       break;
929
930     case SYMBOL_REF:
931       return TDA_NAME_P (XSTR (addr, 0));
932
933     case REG:
934       return REGNO (addr) == EP_REGNUM;
935
936     case PLUS:
937       op0 = XEXP (addr, 0);
938       op1 = XEXP (addr, 1);
939       if (GET_CODE (op1) == CONST_INT
940           && INTVAL (op1) < max_offset
941           && INTVAL (op1) >= 0
942           && (INTVAL (op1) & mask) == 0)
943         {
944           if (GET_CODE (op0) == REG && REGNO (op0) == EP_REGNUM)
945             return TRUE;
946
947           if (GET_CODE (op0) == SYMBOL_REF && TDA_NAME_P (XSTR (op0, 0)))
948             return TRUE;
949         }
950       break;
951     }
952
953   return FALSE;
954 }
955
956 /* Return true if OP is either a register or 0 */
957
958 int
959 reg_or_0_operand (op, mode)
960      rtx op;
961      enum machine_mode mode;
962 {
963   if (GET_CODE (op) == CONST_INT)
964     return INTVAL (op) == 0;
965
966   else if (GET_CODE (op) == CONST_DOUBLE)
967     return CONST_DOUBLE_OK_FOR_G (op);
968
969   else
970     return register_operand (op, mode);
971 }
972
973 /* Return true if OP is either a register or a signed five bit integer */
974
975 int
976 reg_or_int5_operand (op, mode)
977      rtx op;
978      enum machine_mode mode;
979 {
980   if (GET_CODE (op) == CONST_INT)
981     return CONST_OK_FOR_J (INTVAL (op));
982
983   else
984     return register_operand (op, mode);
985 }
986
987 /* Return true if OP is a valid call operand.  */
988
989 int
990 call_address_operand (op, mode)
991      rtx op;
992      enum machine_mode ATTRIBUTE_UNUSED mode;
993 {
994   /* Only registers are valid call operands if TARGET_LONG_CALLS.  */
995   if (TARGET_LONG_CALLS)
996     return GET_CODE (op) == REG;
997   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
998 }
999
1000 int
1001 special_symbolref_operand (op, mode)
1002      rtx op;
1003      enum machine_mode ATTRIBUTE_UNUSED mode;
1004 {
1005   if (GET_CODE (op) == SYMBOL_REF)
1006     return ENCODED_NAME_P (XSTR (op, 0));
1007
1008   else if (GET_CODE (op) == CONST)
1009     return (GET_CODE (XEXP (op, 0)) == PLUS
1010             && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
1011             && ENCODED_NAME_P (XSTR (XEXP (XEXP (op, 0), 0), 0))
1012             && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
1013             && CONST_OK_FOR_K (INTVAL (XEXP (XEXP (op, 0), 1))));
1014
1015   return FALSE;
1016 }
1017
1018 int
1019 movsi_source_operand (op, mode)
1020      rtx op;
1021      enum machine_mode mode;
1022 {
1023   /* Some constants, as well as symbolic operands
1024      must be done with HIGH & LO_SUM patterns.  */
1025   if (CONSTANT_P (op)
1026       && GET_CODE (op) != HIGH
1027       && GET_CODE (op) != CONSTANT_P_RTX
1028       && !(GET_CODE (op) == CONST_INT
1029            && (CONST_OK_FOR_J (INTVAL (op))
1030                || CONST_OK_FOR_K (INTVAL (op))
1031                || CONST_OK_FOR_L (INTVAL (op)))))
1032     return special_symbolref_operand (op, mode);
1033   else
1034     return general_operand (op, mode);
1035 }
1036
1037 int
1038 power_of_two_operand (op, mode)
1039      rtx op;
1040      enum machine_mode ATTRIBUTE_UNUSED mode;
1041 {
1042   if (GET_CODE (op) != CONST_INT)
1043     return 0;
1044
1045   if (exact_log2 (INTVAL (op)) == -1)
1046     return 0;
1047   return 1;
1048 }
1049
1050 int
1051 not_power_of_two_operand (op, mode)
1052      rtx op;
1053      enum machine_mode mode;
1054 {
1055   unsigned int mask;
1056
1057   if (mode == QImode)
1058     mask = 0xff;
1059   else if (mode == HImode)
1060     mask = 0xffff;
1061   else if (mode == SImode)
1062     mask = 0xffffffff;
1063   else
1064     return 0;
1065
1066   if (GET_CODE (op) != CONST_INT)
1067     return 0;
1068
1069   if (exact_log2 (~INTVAL (op) & mask) == -1)
1070     return 0;
1071   return 1;
1072 }
1073
1074 \f
1075 /* Substitute memory references involving a pointer, to use the ep pointer,
1076    taking care to save and preserve the ep.  */
1077
1078 static void
1079 substitute_ep_register (first_insn, last_insn, uses, regno, p_r1, p_ep)
1080      rtx first_insn;
1081      rtx last_insn;
1082      int uses;
1083      int regno;
1084      rtx *p_r1;
1085      rtx *p_ep;
1086 {
1087   rtx reg = gen_rtx_REG (Pmode, regno);
1088   rtx insn;
1089
1090   if (!*p_r1)
1091     {
1092       regs_ever_live[1] = 1;
1093       *p_r1 = gen_rtx_REG (Pmode, 1);
1094       *p_ep = gen_rtx_REG (Pmode, 30);
1095     }
1096
1097   if (TARGET_DEBUG)
1098     fprintf (stderr, "\
1099 Saved %d bytes (%d uses of register %s) in function %s, starting as insn %d, ending at %d\n",
1100              2 * (uses - 3), uses, reg_names[regno],
1101              IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
1102              INSN_UID (first_insn), INSN_UID (last_insn));
1103
1104   if (GET_CODE (first_insn) == NOTE)
1105     first_insn = next_nonnote_insn (first_insn);
1106
1107   last_insn = next_nonnote_insn (last_insn);
1108   for (insn = first_insn; insn && insn != last_insn; insn = NEXT_INSN (insn))
1109     {
1110       if (GET_CODE (insn) == INSN)
1111         {
1112           rtx pattern = single_set (insn);
1113
1114           /* Replace the memory references.  */
1115           if (pattern)
1116             {
1117               rtx *p_mem;
1118               /* Memory operands are signed by default.  */
1119               int unsignedp = FALSE;
1120
1121               if (GET_CODE (SET_DEST (pattern)) == MEM
1122                   && GET_CODE (SET_SRC (pattern)) == MEM)
1123                 p_mem = (rtx *)0;
1124
1125               else if (GET_CODE (SET_DEST (pattern)) == MEM)
1126                 p_mem = &SET_DEST (pattern);
1127
1128               else if (GET_CODE (SET_SRC (pattern)) == MEM)
1129                 p_mem = &SET_SRC (pattern);
1130
1131               else
1132                 p_mem = (rtx *)0;
1133
1134               if (p_mem)
1135                 {
1136                   rtx addr = XEXP (*p_mem, 0);
1137
1138                   if (GET_CODE (addr) == REG && REGNO (addr) == (unsigned) regno)
1139                     *p_mem = change_address (*p_mem, VOIDmode, *p_ep);
1140
1141                   else if (GET_CODE (addr) == PLUS
1142                            && GET_CODE (XEXP (addr, 0)) == REG
1143                            && REGNO (XEXP (addr, 0)) == (unsigned) regno
1144                            && GET_CODE (XEXP (addr, 1)) == CONST_INT
1145                            && ((INTVAL (XEXP (addr, 1)))
1146                                < ep_memory_offset (GET_MODE (*p_mem),
1147                                                    unsignedp))
1148                            && ((INTVAL (XEXP (addr, 1))) >= 0))
1149                     *p_mem = change_address (*p_mem, VOIDmode,
1150                                              gen_rtx_PLUS (Pmode,
1151                                                            *p_ep,
1152                                                            XEXP (addr, 1)));
1153                 }
1154             }
1155         }
1156     }
1157
1158   /* Optimize back to back cases of ep <- r1 & r1 <- ep.  */
1159   insn = prev_nonnote_insn (first_insn);
1160   if (insn && GET_CODE (insn) == INSN
1161       && GET_CODE (PATTERN (insn)) == SET
1162       && SET_DEST (PATTERN (insn)) == *p_ep
1163       && SET_SRC (PATTERN (insn)) == *p_r1)
1164     delete_insn (insn);
1165   else
1166     emit_insn_before (gen_rtx_SET (Pmode, *p_r1, *p_ep), first_insn);
1167
1168   emit_insn_before (gen_rtx_SET (Pmode, *p_ep, reg), first_insn);
1169   emit_insn_before (gen_rtx_SET (Pmode, *p_ep, *p_r1), last_insn);
1170 }
1171
1172 \f
1173 /* In rare cases, correct code generation requires extra machine
1174    dependent processing between the second jump optimization pass and
1175    delayed branch scheduling.  On those machines, define this macro
1176    as a C statement to act on the code starting at INSN.
1177
1178    On the 850, we use it to implement the -mep mode to copy heavily used
1179    pointers to ep to use the implicit addressing.  */
1180
1181 void v850_reorg (start_insn)
1182      rtx start_insn;
1183 {
1184   struct
1185   {
1186     int uses;
1187     rtx first_insn;
1188     rtx last_insn;
1189   }
1190   regs[FIRST_PSEUDO_REGISTER];
1191
1192   int i;
1193   int use_ep = FALSE;
1194   rtx r1 = NULL_RTX;
1195   rtx ep = NULL_RTX;
1196   rtx insn;
1197   rtx pattern;
1198
1199   /* If not ep mode, just return now.  */
1200   if (!TARGET_EP)
1201     return;
1202
1203   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1204     {
1205       regs[i].uses = 0;
1206       regs[i].first_insn = NULL_RTX;
1207       regs[i].last_insn = NULL_RTX;
1208     }
1209
1210   for (insn = start_insn; insn != NULL_RTX; insn = NEXT_INSN (insn))
1211     {
1212       switch (GET_CODE (insn))
1213         {
1214           /* End of basic block */
1215         default:
1216           if (!use_ep)
1217             {
1218               int max_uses = -1;
1219               int max_regno = -1;
1220
1221               for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1222                 {
1223                   if (max_uses < regs[i].uses)
1224                     {
1225                       max_uses = regs[i].uses;
1226                       max_regno = i;
1227                     }
1228                 }
1229
1230               if (max_uses > 3)
1231                 substitute_ep_register (regs[max_regno].first_insn,
1232                                         regs[max_regno].last_insn,
1233                                         max_uses, max_regno, &r1, &ep);
1234             }
1235
1236           use_ep = FALSE;
1237           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1238             {
1239               regs[i].uses = 0;
1240               regs[i].first_insn = NULL_RTX;
1241               regs[i].last_insn = NULL_RTX;
1242             }
1243           break;
1244
1245         case NOTE:
1246           break;
1247
1248         case INSN:
1249           pattern = single_set (insn);
1250
1251           /* See if there are any memory references we can shorten */
1252           if (pattern)
1253             {
1254               rtx src = SET_SRC (pattern);
1255               rtx dest = SET_DEST (pattern);
1256               rtx mem;
1257               /* Memory operands are signed by default.  */
1258               int unsignedp = FALSE;
1259
1260               /* We might have (SUBREG (MEM)) here, so just get rid of the
1261                  subregs to make this code simpler.  */
1262               if (GET_CODE (dest) == SUBREG
1263                   && (GET_CODE (SUBREG_REG (dest)) == MEM
1264                       || GET_CODE (SUBREG_REG (dest)) == REG))
1265                 alter_subreg (&dest);
1266               if (GET_CODE (src) == SUBREG
1267                   && (GET_CODE (SUBREG_REG (src)) == MEM
1268                       || GET_CODE (SUBREG_REG (src)) == REG))
1269                 alter_subreg (&src);
1270
1271               if (GET_CODE (dest) == MEM && GET_CODE (src) == MEM)
1272                 mem = NULL_RTX;
1273
1274               else if (GET_CODE (dest) == MEM)
1275                 mem = dest;
1276
1277               else if (GET_CODE (src) == MEM)
1278                 mem = src;
1279
1280               else
1281                 mem = NULL_RTX;
1282
1283               if (mem && ep_memory_operand (mem, GET_MODE (mem), unsignedp))
1284                 use_ep = TRUE;
1285
1286               else if (!use_ep && mem
1287                        && GET_MODE_SIZE (GET_MODE (mem)) <= UNITS_PER_WORD)
1288                 {
1289                   rtx addr = XEXP (mem, 0);
1290                   int regno = -1;
1291                   int short_p;
1292
1293                   if (GET_CODE (addr) == REG)
1294                     {
1295                       short_p = TRUE;
1296                       regno = REGNO (addr);
1297                     }
1298
1299                   else if (GET_CODE (addr) == PLUS
1300                            && GET_CODE (XEXP (addr, 0)) == REG
1301                            && GET_CODE (XEXP (addr, 1)) == CONST_INT
1302                            && ((INTVAL (XEXP (addr, 1)))
1303                                < ep_memory_offset (GET_MODE (mem), unsignedp))
1304                            && ((INTVAL (XEXP (addr, 1))) >= 0))
1305                     {
1306                       short_p = TRUE;
1307                       regno = REGNO (XEXP (addr, 0));
1308                     }
1309
1310                   else
1311                     short_p = FALSE;
1312
1313                   if (short_p)
1314                     {
1315                       regs[regno].uses++;
1316                       regs[regno].last_insn = insn;
1317                       if (!regs[regno].first_insn)
1318                         regs[regno].first_insn = insn;
1319                     }
1320                 }
1321
1322               /* Loading up a register in the basic block zaps any savings
1323                  for the register */
1324               if (GET_CODE (dest) == REG)
1325                 {
1326                   enum machine_mode mode = GET_MODE (dest);
1327                   int regno;
1328                   int endregno;
1329
1330                   regno = REGNO (dest);
1331                   endregno = regno + HARD_REGNO_NREGS (regno, mode);
1332
1333                   if (!use_ep)
1334                     {
1335                       /* See if we can use the pointer before this
1336                          modification.  */
1337                       int max_uses = -1;
1338                       int max_regno = -1;
1339
1340                       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1341                         {
1342                           if (max_uses < regs[i].uses)
1343                             {
1344                               max_uses = regs[i].uses;
1345                               max_regno = i;
1346                             }
1347                         }
1348
1349                       if (max_uses > 3
1350                           && max_regno >= regno
1351                           && max_regno < endregno)
1352                         {
1353                           substitute_ep_register (regs[max_regno].first_insn,
1354                                                   regs[max_regno].last_insn,
1355                                                   max_uses, max_regno, &r1,
1356                                                   &ep);
1357
1358                           /* Since we made a substitution, zap all remembered
1359                              registers.  */
1360                           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1361                             {
1362                               regs[i].uses = 0;
1363                               regs[i].first_insn = NULL_RTX;
1364                               regs[i].last_insn = NULL_RTX;
1365                             }
1366                         }
1367                     }
1368
1369                   for (i = regno; i < endregno; i++)
1370                     {
1371                       regs[i].uses = 0;
1372                       regs[i].first_insn = NULL_RTX;
1373                       regs[i].last_insn = NULL_RTX;
1374                     }
1375                 }
1376             }
1377         }
1378     }
1379 }
1380
1381 \f
1382 /* # of registers saved by the interrupt handler.  */
1383 #define INTERRUPT_FIXED_NUM 4
1384
1385 /* # of bytes for registers saved by the interrupt handler.  */
1386 #define INTERRUPT_FIXED_SAVE_SIZE (4 * INTERRUPT_FIXED_NUM)
1387
1388 /* # of registers saved in register parameter area.  */
1389 #define INTERRUPT_REGPARM_NUM 4
1390 /* # of words saved for other registers.  */
1391 #define INTERRUPT_ALL_SAVE_NUM \
1392   (30 - INTERRUPT_FIXED_NUM + INTERRUPT_REGPARM_NUM)
1393
1394 #define INTERRUPT_ALL_SAVE_SIZE (4 * INTERRUPT_ALL_SAVE_NUM)
1395
1396 int
1397 compute_register_save_size (p_reg_saved)
1398      long *p_reg_saved;
1399 {
1400   int size = 0;
1401   int i;
1402   int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1403   int call_p = regs_ever_live [LINK_POINTER_REGNUM];
1404   long reg_saved = 0;
1405
1406   /* Count the return pointer if we need to save it.  */
1407   if (current_function_profile && !call_p)
1408     regs_ever_live [LINK_POINTER_REGNUM] = call_p = 1;
1409  
1410   /* Count space for the register saves.  */
1411   if (interrupt_handler)
1412     {
1413       for (i = 0; i <= 31; i++)
1414         switch (i)
1415           {
1416           default:
1417             if (regs_ever_live[i] || call_p)
1418               {
1419                 size += 4;
1420                 reg_saved |= 1L << i;
1421               }
1422             break;
1423
1424             /* We don't save/restore r0 or the stack pointer */
1425           case 0:
1426           case STACK_POINTER_REGNUM:
1427             break;
1428
1429             /* For registers with fixed use, we save them, set them to the
1430                appropriate value, and then restore them.
1431                These registers are handled specially, so don't list them
1432                on the list of registers to save in the prologue.  */
1433           case 1:               /* temp used to hold ep */
1434           case 4:               /* gp */
1435           case 10:              /* temp used to call interrupt save/restore */
1436           case EP_REGNUM:       /* ep */
1437             size += 4;
1438             break;
1439           }
1440     }
1441   else
1442     {
1443       /* Find the first register that needs to be saved.  */
1444       for (i = 0; i <= 31; i++)
1445         if (regs_ever_live[i] && ((! call_used_regs[i])
1446                                   || i == LINK_POINTER_REGNUM))
1447           break;
1448
1449       /* If it is possible that an out-of-line helper function might be
1450          used to generate the prologue for the current function, then we
1451          need to cover the possibility that such a helper function will
1452          be used, despite the fact that there might be gaps in the list of
1453          registers that need to be saved.  To detect this we note that the
1454          helper functions always push at least register r29 (provided
1455          that the function is not an interrupt handler).  */
1456          
1457       if (TARGET_PROLOG_FUNCTION
1458           && (i == 2 || ((i >= 20) && (i < 30))))
1459         {
1460           if (i == 2)
1461             {
1462               size += 4;
1463               reg_saved |= 1L << i;
1464
1465               i = 20;
1466             }
1467
1468           /* Helper functions save all registers between the starting
1469              register and the last register, regardless of whether they
1470              are actually used by the function or not.  */
1471           for (; i <= 29; i++)
1472             {
1473               size += 4;
1474               reg_saved |= 1L << i;
1475             }
1476
1477           if (regs_ever_live [LINK_POINTER_REGNUM])
1478             {
1479               size += 4;
1480               reg_saved |= 1L << LINK_POINTER_REGNUM;
1481             }
1482         }
1483       else
1484         {
1485           for (; i <= 31; i++)
1486             if (regs_ever_live[i] && ((! call_used_regs[i])
1487                                       || i == LINK_POINTER_REGNUM))
1488               {
1489                 size += 4;
1490                 reg_saved |= 1L << i;
1491               }
1492         }
1493     }
1494   
1495   if (p_reg_saved)
1496     *p_reg_saved = reg_saved;
1497
1498   return size;
1499 }
1500
1501 int
1502 compute_frame_size (size, p_reg_saved)
1503      int size;
1504      long *p_reg_saved;
1505 {
1506   return (size
1507           + compute_register_save_size (p_reg_saved)
1508           + current_function_outgoing_args_size);
1509 }
1510
1511 \f
1512 void
1513 expand_prologue ()
1514 {
1515   unsigned int i;
1516   int offset;
1517   unsigned int size = get_frame_size ();
1518   unsigned int actual_fsize;
1519   unsigned int init_stack_alloc = 0;
1520   rtx save_regs[32];
1521   rtx save_all;
1522   unsigned int num_save;
1523   unsigned int default_stack;
1524   int code;
1525   int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1526   long reg_saved = 0;
1527
1528   actual_fsize = compute_frame_size (size, &reg_saved);
1529
1530   /* Save/setup global registers for interrupt functions right now.  */
1531   if (interrupt_handler)
1532     {
1533         emit_insn (gen_save_interrupt ());
1534       
1535       actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1536       
1537       if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1538         actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1539     }
1540
1541   /* Save arg registers to the stack if necessary.  */
1542   else if (current_function_anonymous_args)
1543     {
1544       if (TARGET_PROLOG_FUNCTION)
1545         {
1546           emit_insn (gen_save_r6_r9 ());
1547         }
1548       else
1549         {
1550           offset = 0;
1551           for (i = 6; i < 10; i++)
1552             {
1553               emit_move_insn (gen_rtx_MEM (SImode,
1554                                            plus_constant (stack_pointer_rtx,
1555                                                           offset)),
1556                               gen_rtx_REG (SImode, i));
1557               offset += 4;
1558             }
1559         }
1560     }
1561
1562   /* Identify all of the saved registers.  */
1563   num_save = 0;
1564   default_stack = 0;
1565   for (i = 1; i < 31; i++)
1566     {
1567       if (((1L << i) & reg_saved) != 0)
1568         save_regs[num_save++] = gen_rtx_REG (Pmode, i);
1569     }
1570
1571   /* If the return pointer is saved, the helper functions also allocate
1572      16 bytes of stack for arguments to be saved in.  */
1573   if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1574     {
1575       save_regs[num_save++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1576       default_stack = 16;
1577     }
1578
1579   /* See if we have an insn that allocates stack space and saves the particular
1580      registers we want to.  */
1581   save_all = NULL_RTX;
1582   if (TARGET_PROLOG_FUNCTION && num_save > 0 && actual_fsize >= default_stack)
1583     {
1584       int alloc_stack = (4 * num_save) + default_stack;
1585       int unalloc_stack = actual_fsize - alloc_stack;
1586       int save_func_len = 4;
1587       int save_normal_len;
1588
1589       if (unalloc_stack)
1590         save_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1591
1592       /* see if we would have used ep to save the stack */
1593       if (TARGET_EP && num_save > 3 && (unsigned)actual_fsize < 255)
1594         save_normal_len = (3 * 2) + (2 * num_save);
1595       else
1596         save_normal_len = 4 * num_save;
1597
1598       save_normal_len += CONST_OK_FOR_J (actual_fsize) ? 2 : 4;
1599
1600       /* Don't bother checking if we don't actually save any space.
1601          This happens for instance if one register is saved and additional
1602          stack space is allocated.  */
1603       if (save_func_len < save_normal_len)
1604         {
1605           save_all = gen_rtx_PARALLEL
1606             (VOIDmode,
1607              rtvec_alloc (num_save + (TARGET_V850 ? 2 : 1)));
1608
1609           XVECEXP (save_all, 0, 0)
1610             = gen_rtx_SET (VOIDmode,
1611                            stack_pointer_rtx,
1612                            plus_constant (stack_pointer_rtx, -alloc_stack));
1613
1614           if (TARGET_V850)
1615             {
1616               XVECEXP (save_all, 0, num_save+1)
1617                 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 10));
1618             }
1619
1620           offset = - default_stack;
1621           for (i = 0; i < num_save; i++)
1622             {
1623               XVECEXP (save_all, 0, i+1)
1624                 = gen_rtx_SET (VOIDmode,
1625                                gen_rtx_MEM (Pmode,
1626                                             plus_constant (stack_pointer_rtx,
1627                                                            offset)),
1628                                save_regs[i]);
1629               offset -= 4;
1630             }
1631
1632           code = recog (save_all, NULL_RTX, NULL);
1633           if (code >= 0)
1634             {
1635               rtx insn = emit_insn (save_all);
1636               INSN_CODE (insn) = code;
1637               actual_fsize -= alloc_stack;
1638               
1639               if (TARGET_DEBUG)
1640                 fprintf (stderr, "\
1641 Saved %d bytes via prologue function (%d vs. %d) for function %s\n",
1642                          save_normal_len - save_func_len,
1643                          save_normal_len, save_func_len,
1644                          IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1645             }
1646           else
1647             save_all = NULL_RTX;
1648         }
1649     }
1650
1651   /* If no prolog save function is available, store the registers the old
1652      fashioned way (one by one). */
1653   if (!save_all)
1654     {
1655       /* Special case interrupt functions that save all registers for a call.  */
1656       if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1657         {
1658           emit_insn (gen_save_all_interrupt ());
1659         }
1660       else
1661         {
1662           /* If the stack is too big, allocate it in chunks so we can do the
1663              register saves.  We use the register save size so we use the ep
1664              register.  */
1665           if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1666             init_stack_alloc = compute_register_save_size (NULL);
1667           else
1668             init_stack_alloc = actual_fsize;
1669               
1670           /* Save registers at the beginning of the stack frame */
1671           offset = init_stack_alloc - 4;
1672           
1673           if (init_stack_alloc)
1674             emit_insn (gen_addsi3 (stack_pointer_rtx,
1675                                    stack_pointer_rtx,
1676                                    GEN_INT (-init_stack_alloc)));
1677           
1678           /* Save the return pointer first.  */
1679           if (num_save > 0 && REGNO (save_regs[num_save-1]) == LINK_POINTER_REGNUM)
1680             {
1681               emit_move_insn (gen_rtx_MEM (SImode,
1682                                            plus_constant (stack_pointer_rtx,
1683                                                           offset)),
1684                               save_regs[--num_save]);
1685               offset -= 4;
1686             }
1687           
1688           for (i = 0; i < num_save; i++)
1689             {
1690               emit_move_insn (gen_rtx_MEM (SImode,
1691                                            plus_constant (stack_pointer_rtx,
1692                                                           offset)),
1693                               save_regs[i]);
1694               offset -= 4;
1695             }
1696         }
1697     }
1698
1699   /* Allocate the rest of the stack that was not allocated above (either it is
1700      > 32K or we just called a function to save the registers and needed more
1701      stack.  */
1702   if (actual_fsize > init_stack_alloc)
1703     {
1704       int diff = actual_fsize - init_stack_alloc;
1705       if (CONST_OK_FOR_K (diff))
1706         emit_insn (gen_addsi3 (stack_pointer_rtx,
1707                                stack_pointer_rtx,
1708                                GEN_INT (-diff)));
1709       else
1710         {
1711           rtx reg = gen_rtx_REG (Pmode, 12);
1712           emit_move_insn (reg, GEN_INT (-diff));
1713           emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg));
1714         }
1715     }
1716
1717   /* If we need a frame pointer, set it up now.  */
1718   if (frame_pointer_needed)
1719     emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
1720 }
1721 \f
1722
1723 void
1724 expand_epilogue ()
1725 {
1726   unsigned int i;
1727   int offset;
1728   unsigned int size = get_frame_size ();
1729   long reg_saved = 0;
1730   unsigned int actual_fsize = compute_frame_size (size, &reg_saved);
1731   unsigned int init_stack_free = 0;
1732   rtx restore_regs[32];
1733   rtx restore_all;
1734   unsigned int num_restore;
1735   unsigned int default_stack;
1736   int code;
1737   int interrupt_handler = v850_interrupt_function_p (current_function_decl);
1738
1739   /* Eliminate the initial stack stored by interrupt functions.  */
1740   if (interrupt_handler)
1741     {
1742       actual_fsize -= INTERRUPT_FIXED_SAVE_SIZE;
1743       if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1744         actual_fsize -= INTERRUPT_ALL_SAVE_SIZE;
1745     }
1746
1747   /* Cut off any dynamic stack created.  */
1748   if (frame_pointer_needed)
1749     emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx);
1750
1751   /* Identify all of the saved registers.  */
1752   num_restore = 0;
1753   default_stack = 0;
1754   for (i = 1; i < 31; i++)
1755     {
1756       if (((1L << i) & reg_saved) != 0)
1757         restore_regs[num_restore++] = gen_rtx_REG (Pmode, i);
1758     }
1759
1760   /* If the return pointer is saved, the helper functions also allocate
1761      16 bytes of stack for arguments to be saved in.  */
1762   if (((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1763     {
1764       restore_regs[num_restore++] = gen_rtx_REG (Pmode, LINK_POINTER_REGNUM);
1765       default_stack = 16;
1766     }
1767
1768   /* See if we have an insn that restores the particular registers we
1769      want to.  */
1770   restore_all = NULL_RTX;
1771   
1772   if (TARGET_PROLOG_FUNCTION
1773       && num_restore > 0
1774       && actual_fsize >= default_stack
1775       && !interrupt_handler)
1776     {
1777       int alloc_stack = (4 * num_restore) + default_stack;
1778       int unalloc_stack = actual_fsize - alloc_stack;
1779       int restore_func_len = 4;
1780       int restore_normal_len;
1781
1782       if (unalloc_stack)
1783         restore_func_len += CONST_OK_FOR_J (unalloc_stack) ? 2 : 4;
1784
1785       /* See if we would have used ep to restore the registers.  */
1786       if (TARGET_EP && num_restore > 3 && (unsigned)actual_fsize < 255)
1787         restore_normal_len = (3 * 2) + (2 * num_restore);
1788       else
1789         restore_normal_len = 4 * num_restore;
1790
1791       restore_normal_len += (CONST_OK_FOR_J (actual_fsize) ? 2 : 4) + 2;
1792
1793       /* Don't bother checking if we don't actually save any space.  */
1794       if (restore_func_len < restore_normal_len)
1795         {
1796           restore_all = gen_rtx_PARALLEL (VOIDmode,
1797                                           rtvec_alloc (num_restore + 2));
1798           XVECEXP (restore_all, 0, 0) = gen_rtx_RETURN (VOIDmode);
1799           XVECEXP (restore_all, 0, 1)
1800             = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1801                             gen_rtx_PLUS (Pmode,
1802                                           stack_pointer_rtx,
1803                                           GEN_INT (alloc_stack)));
1804
1805           offset = alloc_stack - 4;
1806           for (i = 0; i < num_restore; i++)
1807             {
1808               XVECEXP (restore_all, 0, i+2)
1809                 = gen_rtx_SET (VOIDmode,
1810                                restore_regs[i],
1811                                gen_rtx_MEM (Pmode,
1812                                             plus_constant (stack_pointer_rtx,
1813                                                            offset)));
1814               offset -= 4;
1815             }
1816
1817           code = recog (restore_all, NULL_RTX, NULL);
1818           
1819           if (code >= 0)
1820             {
1821               rtx insn;
1822
1823               actual_fsize -= alloc_stack;
1824               if (actual_fsize)
1825                 {
1826                   if (CONST_OK_FOR_K (actual_fsize))
1827                     emit_insn (gen_addsi3 (stack_pointer_rtx,
1828                                            stack_pointer_rtx,
1829                                            GEN_INT (actual_fsize)));
1830                   else
1831                     {
1832                       rtx reg = gen_rtx_REG (Pmode, 12);
1833                       emit_move_insn (reg, GEN_INT (actual_fsize));
1834                       emit_insn (gen_addsi3 (stack_pointer_rtx,
1835                                              stack_pointer_rtx,
1836                                              reg));
1837                     }
1838                 }
1839
1840               insn = emit_jump_insn (restore_all);
1841               INSN_CODE (insn) = code;
1842
1843               if (TARGET_DEBUG)
1844                 fprintf (stderr, "\
1845 Saved %d bytes via epilogue function (%d vs. %d) in function %s\n",
1846                          restore_normal_len - restore_func_len,
1847                          restore_normal_len, restore_func_len,
1848                          IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
1849             }
1850           else
1851             restore_all = NULL_RTX;
1852         }
1853     }
1854
1855   /* If no epilog save function is available, restore the registers the
1856      old fashioned way (one by one).  */
1857   if (!restore_all)
1858     {
1859       /* If the stack is large, we need to cut it down in 2 pieces.  */
1860       if (actual_fsize && !CONST_OK_FOR_K (-actual_fsize))
1861         init_stack_free = 4 * num_restore;
1862       else
1863         init_stack_free = actual_fsize;
1864
1865       /* Deallocate the rest of the stack if it is > 32K.  */
1866       if (actual_fsize > init_stack_free)
1867         {
1868           int diff;
1869
1870           diff = actual_fsize - ((interrupt_handler) ? 0 : init_stack_free);
1871
1872           if (CONST_OK_FOR_K (diff))
1873             emit_insn (gen_addsi3 (stack_pointer_rtx,
1874                                    stack_pointer_rtx,
1875                                    GEN_INT (diff)));
1876           else
1877             {
1878               rtx reg = gen_rtx_REG (Pmode, 12);
1879               emit_move_insn (reg, GEN_INT (diff));
1880               emit_insn (gen_addsi3 (stack_pointer_rtx,
1881                                      stack_pointer_rtx,
1882                                      reg));
1883             }
1884         }
1885
1886       /* Special case interrupt functions that save all registers
1887          for a call.  */
1888       if (interrupt_handler && ((1L << LINK_POINTER_REGNUM) & reg_saved) != 0)
1889         {
1890           emit_insn (gen_restore_all_interrupt ());
1891         }
1892       else
1893         {
1894           /* Restore registers from the beginning of the stack frame.  */
1895           offset = init_stack_free - 4;
1896
1897           /* Restore the return pointer first.  */
1898           if (num_restore > 0
1899               && REGNO (restore_regs [num_restore - 1]) == LINK_POINTER_REGNUM)
1900             {
1901               emit_move_insn (restore_regs[--num_restore],
1902                               gen_rtx_MEM (SImode,
1903                                            plus_constant (stack_pointer_rtx,
1904                                                           offset)));
1905               offset -= 4;
1906             }
1907
1908           for (i = 0; i < num_restore; i++)
1909             {
1910               emit_move_insn (restore_regs[i],
1911                               gen_rtx_MEM (SImode,
1912                                            plus_constant (stack_pointer_rtx,
1913                                                           offset)));
1914
1915               emit_insn (gen_rtx_USE (VOIDmode, restore_regs[i]));
1916               offset -= 4;
1917             }
1918
1919           /* Cut back the remainder of the stack.  */
1920           if (init_stack_free)
1921             emit_insn (gen_addsi3 (stack_pointer_rtx,
1922                                    stack_pointer_rtx,
1923                                    GEN_INT (init_stack_free)));
1924         }
1925
1926       /* And return or use reti for interrupt handlers.  */
1927       if (interrupt_handler)
1928         emit_jump_insn (gen_restore_interrupt ());
1929       else if (actual_fsize)
1930         emit_jump_insn (gen_return_internal ());
1931       else
1932         emit_jump_insn (gen_return ());
1933     }
1934
1935   current_function_anonymous_args = 0;
1936   v850_interrupt_cache_p = FALSE;
1937   v850_interrupt_p = FALSE;
1938 }
1939
1940 \f
1941 /* Update the condition code from the insn.  */
1942
1943 void
1944 notice_update_cc (body, insn)
1945      rtx body;
1946      rtx insn;
1947 {
1948   switch (get_attr_cc (insn))
1949     {
1950     case CC_NONE:
1951       /* Insn does not affect CC at all.  */
1952       break;
1953
1954     case CC_NONE_0HIT:
1955       /* Insn does not change CC, but the 0'th operand has been changed.  */
1956       if (cc_status.value1 != 0
1957           && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1958         cc_status.value1 = 0;
1959       break;
1960
1961     case CC_SET_ZN:
1962       /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1963          V,C is in an unusable state.  */
1964       CC_STATUS_INIT;
1965       cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY;
1966       cc_status.value1 = recog_data.operand[0];
1967       break;
1968
1969     case CC_SET_ZNV:
1970       /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1971          C is in an unusable state.  */
1972       CC_STATUS_INIT;
1973       cc_status.flags |= CC_NO_CARRY;
1974       cc_status.value1 = recog_data.operand[0];
1975       break;
1976
1977     case CC_COMPARE:
1978       /* The insn is a compare instruction.  */
1979       CC_STATUS_INIT;
1980       cc_status.value1 = SET_SRC (body);
1981       break;
1982
1983     case CC_CLOBBER:
1984       /* Insn doesn't leave CC in a usable state.  */
1985       CC_STATUS_INIT;
1986       break;
1987     }
1988 }
1989 \f
1990 /* Retrieve the data area that has been chosen for the given decl.  */
1991
1992 v850_data_area
1993 v850_get_data_area (decl)
1994      tree decl;
1995 {
1996   if (lookup_attribute ("sda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
1997     return DATA_AREA_SDA;
1998   
1999   if (lookup_attribute ("tda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2000     return DATA_AREA_TDA;
2001   
2002   if (lookup_attribute ("zda", DECL_ATTRIBUTES (decl)) != NULL_TREE)
2003     return DATA_AREA_ZDA;
2004
2005   return DATA_AREA_NORMAL;
2006 }
2007
2008 /* Store the indicated data area in the decl's attributes.  */
2009
2010 static void
2011 v850_set_data_area (decl, data_area)
2012      tree decl;
2013      v850_data_area data_area;
2014 {
2015   tree name;
2016   
2017   switch (data_area)
2018     {
2019     case DATA_AREA_SDA: name = get_identifier ("sda"); break;
2020     case DATA_AREA_TDA: name = get_identifier ("tda"); break;
2021     case DATA_AREA_ZDA: name = get_identifier ("zda"); break;
2022     default:
2023       return;
2024     }
2025
2026   DECL_ATTRIBUTES (decl) = tree_cons
2027     (name, NULL, DECL_ATTRIBUTES (decl));
2028 }
2029 \f
2030 const struct attribute_spec v850_attribute_table[] =
2031 {
2032   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
2033   { "interrupt_handler", 0, 0, true,  false, false, v850_handle_interrupt_attribute },
2034   { "interrupt",         0, 0, true,  false, false, v850_handle_interrupt_attribute },
2035   { "sda",               0, 0, true,  false, false, v850_handle_data_area_attribute },
2036   { "tda",               0, 0, true,  false, false, v850_handle_data_area_attribute },
2037   { "zda",               0, 0, true,  false, false, v850_handle_data_area_attribute },
2038   { NULL,                0, 0, false, false, false, NULL }
2039 };
2040
2041 /* Handle an "interrupt" attribute; arguments as in
2042    struct attribute_spec.handler.  */
2043 static tree
2044 v850_handle_interrupt_attribute (node, name, args, flags, no_add_attrs)
2045      tree *node;
2046      tree name;
2047      tree args ATTRIBUTE_UNUSED;
2048      int flags ATTRIBUTE_UNUSED;
2049      bool *no_add_attrs;
2050 {
2051   if (TREE_CODE (*node) != FUNCTION_DECL)
2052     {
2053       warning ("`%s' attribute only applies to functions",
2054                IDENTIFIER_POINTER (name));
2055       *no_add_attrs = true;
2056     }
2057
2058   return NULL_TREE;
2059 }
2060
2061 /* Handle a "sda", "tda" or "zda" attribute; arguments as in
2062    struct attribute_spec.handler.  */
2063 static tree
2064 v850_handle_data_area_attribute (node, name, args, flags, no_add_attrs)
2065      tree *node;
2066      tree name;
2067      tree args ATTRIBUTE_UNUSED;
2068      int flags ATTRIBUTE_UNUSED;
2069      bool *no_add_attrs;
2070 {
2071   v850_data_area data_area;
2072   v850_data_area area;
2073   tree decl = *node;
2074
2075   /* Implement data area attribute.  */
2076   if (is_attribute_p ("sda", name))
2077     data_area = DATA_AREA_SDA;
2078   else if (is_attribute_p ("tda", name))
2079     data_area = DATA_AREA_TDA;
2080   else if (is_attribute_p ("zda", name))
2081     data_area = DATA_AREA_ZDA;
2082   else
2083     abort ();
2084   
2085   switch (TREE_CODE (decl))
2086     {
2087     case VAR_DECL:
2088       if (current_function_decl != NULL_TREE)
2089         {
2090           error_with_decl (decl, "\
2091 a data area attribute cannot be specified for local variables");
2092           *no_add_attrs = true;
2093         }
2094
2095       /* Drop through.  */
2096
2097     case FUNCTION_DECL:
2098       area = v850_get_data_area (decl);
2099       if (area != DATA_AREA_NORMAL && data_area != area)
2100         {
2101           error_with_decl (decl, "\
2102 data area of '%s' conflicts with previous declaration");
2103           *no_add_attrs = true;
2104         }
2105       break;
2106       
2107     default:
2108       break;
2109     }
2110
2111   return NULL_TREE;
2112 }
2113
2114 \f
2115 /* Return nonzero if FUNC is an interrupt function as specified
2116    by the "interrupt" attribute.  */
2117
2118 int
2119 v850_interrupt_function_p (func)
2120      tree func;
2121 {
2122   tree a;
2123   int ret = 0;
2124
2125   if (v850_interrupt_cache_p)
2126     return v850_interrupt_p;
2127
2128   if (TREE_CODE (func) != FUNCTION_DECL)
2129     return 0;
2130
2131   a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
2132   if (a != NULL_TREE)
2133     ret = 1;
2134
2135   else
2136     {
2137       a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
2138       ret = a != NULL_TREE;
2139     }
2140
2141   /* Its not safe to trust global variables until after function inlining has
2142      been done.  */
2143   if (reload_completed | reload_in_progress)
2144     v850_interrupt_p = ret;
2145
2146   return ret;
2147 }
2148
2149 \f
2150 static void
2151 v850_encode_data_area (decl)
2152      tree decl;
2153 {
2154   const char *str = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2155   int    len = strlen (str);
2156   char * newstr;
2157
2158   /* Map explict sections into the appropriate attribute */
2159   if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2160     {
2161       if (DECL_SECTION_NAME (decl))
2162         {
2163           const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
2164           
2165           if (streq (name, ".zdata") || streq (name, ".zbss"))
2166             v850_set_data_area (decl, DATA_AREA_ZDA);
2167
2168           else if (streq (name, ".sdata") || streq (name, ".sbss"))
2169             v850_set_data_area (decl, DATA_AREA_SDA);
2170
2171           else if (streq (name, ".tdata"))
2172             v850_set_data_area (decl, DATA_AREA_TDA);
2173         }
2174
2175       /* If no attribute, support -m{zda,sda,tda}=n */
2176       else
2177         {
2178           int size = int_size_in_bytes (TREE_TYPE (decl));
2179           if (size <= 0)
2180             ;
2181
2182           else if (size <= small_memory [(int) SMALL_MEMORY_TDA].max)
2183             v850_set_data_area (decl, DATA_AREA_TDA);
2184
2185           else if (size <= small_memory [(int) SMALL_MEMORY_SDA].max)
2186             v850_set_data_area (decl, DATA_AREA_SDA);
2187
2188           else if (size <= small_memory [(int) SMALL_MEMORY_ZDA].max)
2189             v850_set_data_area (decl, DATA_AREA_ZDA);
2190         }
2191       
2192       if (v850_get_data_area (decl) == DATA_AREA_NORMAL)
2193         return;
2194     }
2195
2196   newstr = alloca (len + 2);
2197
2198   strcpy (newstr + 1, str);
2199
2200   switch (v850_get_data_area (decl))
2201     {
2202     case DATA_AREA_ZDA: *newstr = ZDA_NAME_FLAG_CHAR; break;
2203     case DATA_AREA_TDA: *newstr = TDA_NAME_FLAG_CHAR; break;
2204     case DATA_AREA_SDA: *newstr = SDA_NAME_FLAG_CHAR; break;
2205     default: abort ();
2206     }
2207
2208   XSTR (XEXP (DECL_RTL (decl), 0), 0) = ggc_alloc_string (newstr, len + 2);
2209 }
2210
2211 static void
2212 v850_encode_section_info (decl, first)
2213      tree decl;
2214      int first;
2215 {
2216   if (first && TREE_CODE (decl) == VAR_DECL
2217       && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
2218     v850_encode_data_area (decl);
2219 }
2220
2221 /* Return true if the given RTX is a register which can be restored
2222    by a function epilogue.  */
2223 int
2224 register_is_ok_for_epilogue (op, mode)
2225      rtx op;
2226      enum machine_mode ATTRIBUTE_UNUSED mode;
2227 {
2228   /* The save/restore routines can only cope with registers 2, and 20 - 31 */
2229   return (GET_CODE (op) == REG)
2230           && (((REGNO (op) >= 20) && REGNO (op) <= 31)
2231               || REGNO (op) == 2);
2232 }
2233
2234 /* Return non-zero if the given RTX is suitable for collapsing into
2235    jump to a function epilogue.  */
2236 int
2237 pattern_is_ok_for_epilogue (op, mode)
2238      rtx op;
2239      enum machine_mode ATTRIBUTE_UNUSED mode;
2240 {
2241   int count = XVECLEN (op, 0);
2242   int i;
2243   
2244   /* If there are no registers to restore then the function epilogue
2245      is not suitable.  */
2246   if (count <= 2)
2247     return 0;
2248
2249   /* The pattern matching has already established that we are performing a
2250      function epilogue and that we are popping at least one register.  We must
2251      now check the remaining entries in the vector to make sure that they are
2252      also register pops.  There is no good reason why there should ever be
2253      anything else in this vector, but being paranoid always helps...
2254
2255      The test below performs the C equivalent of this machine description
2256      pattern match:
2257
2258         (set (match_operand:SI n "register_is_ok_for_epilogue" "r")
2259           (mem:SI (plus:SI (reg:SI 3) (match_operand:SI n "immediate_operand" "i"))))
2260      */
2261
2262   for (i = 3; i < count; i++)
2263     {
2264       rtx vector_element = XVECEXP (op, 0, i);
2265       rtx dest;
2266       rtx src;
2267       rtx plus;
2268       
2269       if (GET_CODE (vector_element) != SET)
2270         return 0;
2271       
2272       dest = SET_DEST (vector_element);
2273       src = SET_SRC (vector_element);
2274
2275       if (GET_CODE (dest) != REG
2276           || GET_MODE (dest) != SImode
2277           || ! register_is_ok_for_epilogue (dest, SImode)
2278           || GET_CODE (src) != MEM
2279           || GET_MODE (src) != SImode)
2280         return 0;
2281
2282       plus = XEXP (src, 0);
2283
2284       if (GET_CODE (plus) != PLUS
2285           || GET_CODE (XEXP (plus, 0)) != REG
2286           || GET_MODE (XEXP (plus, 0)) != SImode
2287           || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2288           || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2289         return 0;
2290     }
2291
2292   return 1;
2293 }
2294
2295 /* Construct a JR instruction to a routine that will perform the equivalent of
2296    the RTL passed in as an argument.  This RTL is a function epilogue that
2297    pops registers off the stack and possibly releases some extra stack space
2298    as well.  The code has already verified that the RTL matches these
2299    requirements.  */
2300 char *
2301 construct_restore_jr (op)
2302      rtx op;
2303 {
2304   int count = XVECLEN (op, 0);
2305   int stack_bytes;
2306   unsigned long int mask;
2307   unsigned long int first;
2308   unsigned long int last;
2309   int i;
2310   static char buff [100]; /* XXX */
2311   
2312   if (count <= 2)
2313     {
2314       error ("bogus JR construction: %d\n", count);
2315       return NULL;
2316     }
2317
2318   /* Work out how many bytes to pop off the stack before retrieving
2319      registers.  */
2320   if (GET_CODE (XVECEXP (op, 0, 1)) != SET)
2321     abort ();
2322   if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) != PLUS)
2323     abort ();
2324   if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1)) != CONST_INT)
2325     abort ();
2326     
2327   stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1));
2328
2329   /* Each pop will remove 4 bytes from the stack... */
2330   stack_bytes -= (count - 2) * 4;
2331
2332   /* Make sure that the amount we are popping either 0 or 16 bytes.  */
2333   if (stack_bytes != 0 && stack_bytes != 16)
2334     {
2335       error ("bad amount of stack space removal: %d", stack_bytes);
2336       return NULL;
2337     }
2338
2339   /* Now compute the bit mask of registers to push.  */
2340   mask = 0;
2341   for (i = 2; i < count; i++)
2342     {
2343       rtx vector_element = XVECEXP (op, 0, i);
2344       
2345       if (GET_CODE (vector_element) != SET)
2346         abort ();
2347       if (GET_CODE (SET_DEST (vector_element)) != REG)
2348         abort ();
2349       if (! register_is_ok_for_epilogue (SET_DEST (vector_element), SImode))
2350         abort ();
2351       
2352       mask |= 1 << REGNO (SET_DEST (vector_element));
2353     }
2354
2355   /* Scan for the first register to pop.  */
2356   for (first = 0; first < 32; first++)
2357     {
2358       if (mask & (1 << first))
2359         break;
2360     }
2361
2362   if (first >= 32)
2363     abort ();
2364
2365   /* Discover the last register to pop.  */
2366   if (mask & (1 << LINK_POINTER_REGNUM))
2367     {
2368       if (stack_bytes != 16)
2369         abort ();
2370       
2371       last = LINK_POINTER_REGNUM;
2372     }
2373   else
2374     {
2375       if (stack_bytes != 0)
2376         abort ();
2377       
2378       if ((mask & (1 << 29)) == 0)
2379         abort ();
2380       
2381       last = 29;
2382     }
2383
2384   /* Note, it is possible to have gaps in the register mask.
2385      We ignore this here, and generate a JR anyway.  We will
2386      be popping more registers than is strictly necessary, but
2387      it does save code space.  */
2388   
2389   if (TARGET_LONG_CALLS)
2390     {
2391       char name[40];
2392       
2393       if (first == last)
2394         sprintf (name, "__return_%s", reg_names [first]);
2395       else
2396         sprintf (name, "__return_%s_%s", reg_names [first], reg_names [last]);
2397       
2398       sprintf (buff, "movhi hi(%s), r0, r6\n\tmovea lo(%s), r6, r6\n\tjmp r6",
2399                name, name);
2400     }
2401   else
2402     {
2403       if (first == last)
2404         sprintf (buff, "jr __return_%s", reg_names [first]);
2405       else
2406         sprintf (buff, "jr __return_%s_%s", reg_names [first], reg_names [last]);
2407     }
2408   
2409   return buff;
2410 }
2411
2412
2413 /* Return non-zero if the given RTX is suitable for collapsing into
2414    a jump to a function prologue.  */
2415 int
2416 pattern_is_ok_for_prologue (op, mode)
2417      rtx op;
2418      enum machine_mode ATTRIBUTE_UNUSED mode;
2419 {
2420   int count = XVECLEN (op, 0);
2421   int i; 
2422   rtx vector_element;
2423  
2424   /* If there are no registers to save then the function prologue
2425      is not suitable.  */
2426   if (count <= 2)
2427     return 0;
2428
2429   /* The pattern matching has already established that we are adjusting the
2430      stack and pushing at least one register.  We must now check that the
2431      remaining entries in the vector to make sure that they are also register
2432      pushes, except for the last entry which should be a CLOBBER of r10.
2433
2434      The test below performs the C equivalent of this machine description
2435      pattern match:
2436
2437      (set (mem:SI (plus:SI (reg:SI 3)
2438       (match_operand:SI 2 "immediate_operand" "i")))
2439       (match_operand:SI 3 "register_is_ok_for_epilogue" "r"))
2440
2441      */
2442
2443   for (i = 2; i < count - 1; i++)
2444     {
2445       rtx dest;
2446       rtx src;
2447       rtx plus;
2448       
2449       vector_element = XVECEXP (op, 0, i);
2450       
2451       if (GET_CODE (vector_element) != SET)
2452         return 0;
2453       
2454       dest = SET_DEST (vector_element);
2455       src = SET_SRC (vector_element);
2456
2457       if (GET_CODE (dest) != MEM
2458           || GET_MODE (dest) != SImode
2459           || GET_CODE (src) != REG
2460           || GET_MODE (src) != SImode
2461           || ! register_is_ok_for_epilogue (src, SImode))
2462         return 0;
2463
2464       plus = XEXP (dest, 0);
2465
2466       if ( GET_CODE (plus) != PLUS
2467           || GET_CODE (XEXP (plus, 0)) != REG
2468           || GET_MODE (XEXP (plus, 0)) != SImode
2469           || REGNO (XEXP (plus, 0)) != STACK_POINTER_REGNUM
2470           || GET_CODE (XEXP (plus, 1)) != CONST_INT)
2471         return 0;
2472
2473       /* If the register is being pushed somewhere other than the stack
2474          space just acquired by the first operand then abandon this quest.
2475          Note: the test is <= because both values are negative.  */
2476       if (INTVAL (XEXP (plus, 1))
2477           <= INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)))
2478         {
2479           return 0;
2480         }
2481     }
2482
2483   /* Make sure that the last entry in the vector is a clobber.  */
2484   vector_element = XVECEXP (op, 0, i);
2485   
2486   if (GET_CODE (vector_element) != CLOBBER
2487       || GET_CODE (XEXP (vector_element, 0)) != REG
2488       || REGNO (XEXP (vector_element, 0)) != 10)
2489     return 0;
2490   
2491   return 1;
2492 }
2493
2494 /* Construct a JARL instruction to a routine that will perform the equivalent
2495    of the RTL passed as a parameter.  This RTL is a function prologue that
2496    saves some of the registers r20 - r31 onto the stack, and possibly acquires
2497    some stack space as well.  The code has already verified that the RTL
2498    matches these requirements.  */
2499 char *
2500 construct_save_jarl (op)
2501      rtx op;
2502 {
2503   int count = XVECLEN (op, 0);
2504   int stack_bytes;
2505   unsigned long int mask;
2506   unsigned long int first;
2507   unsigned long int last;
2508   int i;
2509   static char buff [100]; /* XXX */
2510   
2511   if (count <= 2)
2512     {
2513       error ("bogus JARL construction: %d\n", count);
2514       return NULL;
2515     }
2516
2517   /* Paranoia.  */
2518   if (GET_CODE (XVECEXP (op, 0, 0)) != SET)
2519     abort ();
2520   if (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != PLUS)
2521     abort ();
2522   if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0)) != REG)
2523     abort ();
2524   if (GET_CODE (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1)) != CONST_INT)
2525     abort ();
2526     
2527   /* Work out how many bytes to push onto the stack after storing the
2528      registers.  */
2529   stack_bytes = INTVAL (XEXP (SET_SRC (XVECEXP (op, 0, 0)), 1));
2530
2531   /* Each push will put 4 bytes from the stack... */
2532   stack_bytes += (count - 2) * 4;
2533
2534   /* Make sure that the amount we are popping either 0 or 16 bytes.  */
2535   if (stack_bytes != 0 && stack_bytes != -16)
2536     {
2537       error ("bad amount of stack space removal: %d", stack_bytes);
2538       return NULL;
2539     }
2540
2541   /* Now compute the bit mask of registers to push.  */
2542   mask = 0;
2543   for (i = 1; i < count - 1; i++)
2544     {
2545       rtx vector_element = XVECEXP (op, 0, i);
2546       
2547       if (GET_CODE (vector_element) != SET)
2548         abort ();
2549       if (GET_CODE (SET_SRC (vector_element)) != REG)
2550         abort ();
2551       if (! register_is_ok_for_epilogue (SET_SRC (vector_element), SImode))
2552         abort ();
2553       
2554       mask |= 1 << REGNO (SET_SRC (vector_element));
2555     }
2556
2557   /* Scan for the first register to push.  */  
2558   for (first = 0; first < 32; first++)
2559     {
2560       if (mask & (1 << first))
2561         break;
2562     }
2563
2564   if (first >= 32)
2565     abort ();
2566
2567   /* Discover the last register to push.  */
2568   if (mask & (1 << LINK_POINTER_REGNUM))
2569     {
2570       if (stack_bytes != -16)
2571         abort ();
2572       
2573       last = LINK_POINTER_REGNUM;
2574     }
2575   else
2576     {
2577       if (stack_bytes != 0)
2578         abort ();
2579       if ((mask & (1 << 29)) == 0)
2580         abort ();
2581       
2582       last = 29;
2583     }
2584
2585   /* Note, it is possible to have gaps in the register mask.
2586      We ignore this here, and generate a JARL anyway.  We will
2587      be pushing more registers than is strictly necessary, but
2588      it does save code space.  */
2589   
2590   if (TARGET_LONG_CALLS)
2591     {
2592       char name[40];
2593       
2594       if (first == last)
2595         sprintf (name, "__save_%s", reg_names [first]);
2596       else
2597         sprintf (name, "__save_%s_%s", reg_names [first], reg_names [last]);
2598       
2599       sprintf (buff, "movhi hi(%s), r0, r11\n\tmovea lo(%s), r11, r11\n\tjarl .+4, r10\n\tadd 4, r10\n\tjmp r11",
2600                name, name);
2601     }
2602   else
2603     {
2604       if (first == last)
2605         sprintf (buff, "jarl __save_%s, r10", reg_names [first]);
2606       else
2607         sprintf (buff, "jarl __save_%s_%s, r10", reg_names [first],
2608                  reg_names [last]);
2609     }
2610
2611   return buff;
2612 }
2613
2614 extern tree last_assemble_variable_decl;
2615 extern int size_directive_output;
2616
2617 /* A version of asm_output_aligned_bss() that copes with the special
2618    data areas of the v850. */
2619 void
2620 v850_output_aligned_bss (file, decl, name, size, align)
2621      FILE * file;
2622      tree decl;
2623      const char * name;
2624      int size;
2625      int align;
2626 {
2627   ASM_GLOBALIZE_LABEL (file, name);
2628   
2629   switch (v850_get_data_area (decl))
2630     {
2631     case DATA_AREA_ZDA:
2632       zbss_section ();
2633       break;
2634
2635     case DATA_AREA_SDA:
2636       sbss_section ();
2637       break;
2638
2639     case DATA_AREA_TDA:
2640       tdata_section ();
2641       
2642     default:
2643       bss_section ();
2644       break;
2645     }
2646   
2647   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
2648 #ifdef ASM_DECLARE_OBJECT_NAME
2649   last_assemble_variable_decl = decl;
2650   ASM_DECLARE_OBJECT_NAME (file, name, decl);
2651 #else
2652   /* Standard thing is just output label for the object.  */
2653   ASM_OUTPUT_LABEL (file, name);
2654 #endif /* ASM_DECLARE_OBJECT_NAME */
2655   ASM_OUTPUT_SKIP (file, size ? size : 1);
2656 }
2657
2658 /* Called via the macro ASM_OUTPUT_DECL_COMMON */
2659 void
2660 v850_output_common (file, decl, name, size, align)
2661      FILE * file;
2662      tree decl;
2663      const char * name;
2664      int size;
2665      int align;
2666 {
2667   if (decl == NULL_TREE)
2668     {
2669       fprintf (file, "%s", COMMON_ASM_OP);
2670     }
2671   else
2672     {
2673       switch (v850_get_data_area (decl))
2674         {
2675         case DATA_AREA_ZDA:
2676           fprintf (file, "%s", ZCOMMON_ASM_OP);
2677           break;
2678
2679         case DATA_AREA_SDA:
2680           fprintf (file, "%s", SCOMMON_ASM_OP);
2681           break;
2682
2683         case DATA_AREA_TDA:
2684           fprintf (file, "%s", TCOMMON_ASM_OP);
2685           break;
2686       
2687         default:
2688           fprintf (file, "%s", COMMON_ASM_OP);
2689           break;
2690         }
2691     }
2692   
2693   assemble_name (file, name);
2694   fprintf (file, ",%u,%u\n", size, align / BITS_PER_UNIT);
2695 }
2696
2697 /* Called via the macro ASM_OUTPUT_DECL_LOCAL */
2698 void
2699 v850_output_local (file, decl, name, size, align)
2700      FILE * file;
2701      tree decl;
2702      const char * name;
2703      int size;
2704      int align;
2705 {
2706   fprintf (file, "%s", LOCAL_ASM_OP);
2707   assemble_name (file, name);
2708   fprintf (file, "\n");
2709   
2710   ASM_OUTPUT_ALIGNED_DECL_COMMON (file, decl, name, size, align);
2711 }
2712
2713 /* Add data area to the given declaration if a ghs data area pragma is
2714    currently in effect (#pragma ghs startXXX/endXXX).  */
2715 static void
2716 v850_insert_attributes (decl, attr_ptr)
2717      tree decl;
2718      tree *attr_ptr ATTRIBUTE_UNUSED;
2719 {
2720   if (data_area_stack
2721       && data_area_stack->data_area
2722       && current_function_decl == NULL_TREE
2723       && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == CONST_DECL)
2724       && v850_get_data_area (decl) == DATA_AREA_NORMAL)
2725     v850_set_data_area (decl, data_area_stack->data_area);
2726
2727   /* Initialise the default names of the v850 specific sections,
2728      if this has not been done before.  */
2729   
2730   if (GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA] == NULL)
2731     {
2732       GHS_default_section_names [(int) GHS_SECTION_KIND_SDATA]
2733         = build_string (sizeof (".sdata")-1, ".sdata");
2734
2735       GHS_default_section_names [(int) GHS_SECTION_KIND_ROSDATA]
2736         = build_string (sizeof (".rosdata")-1, ".rosdata");
2737
2738       GHS_default_section_names [(int) GHS_SECTION_KIND_TDATA]
2739         = build_string (sizeof (".tdata")-1, ".tdata");
2740       
2741       GHS_default_section_names [(int) GHS_SECTION_KIND_ZDATA]
2742         = build_string (sizeof (".zdata")-1, ".zdata");
2743
2744       GHS_default_section_names [(int) GHS_SECTION_KIND_ROZDATA]
2745         = build_string (sizeof (".rozdata")-1, ".rozdata");
2746     }
2747   
2748   if (current_function_decl == NULL_TREE
2749       && (TREE_CODE (decl) == VAR_DECL
2750           || TREE_CODE (decl) == CONST_DECL
2751           || TREE_CODE (decl) == FUNCTION_DECL)
2752       && (!DECL_EXTERNAL (decl) || DECL_INITIAL (decl))
2753       && !DECL_SECTION_NAME (decl))
2754     {
2755       enum GHS_section_kind kind = GHS_SECTION_KIND_DEFAULT;
2756       tree chosen_section;
2757
2758       if (TREE_CODE (decl) == FUNCTION_DECL)
2759         kind = GHS_SECTION_KIND_TEXT;
2760       else
2761         {
2762           /* First choose a section kind based on the data area of the decl. */
2763           switch (v850_get_data_area (decl))
2764             {
2765             default:
2766               abort ();
2767               
2768             case DATA_AREA_SDA:
2769               kind = ((TREE_READONLY (decl))
2770                       ? GHS_SECTION_KIND_ROSDATA
2771                       : GHS_SECTION_KIND_SDATA);
2772               break;
2773               
2774             case DATA_AREA_TDA:
2775               kind = GHS_SECTION_KIND_TDATA;
2776               break;
2777               
2778             case DATA_AREA_ZDA:
2779               kind = ((TREE_READONLY (decl))
2780                       ? GHS_SECTION_KIND_ROZDATA
2781                       : GHS_SECTION_KIND_ZDATA);
2782               break;
2783               
2784             case DATA_AREA_NORMAL:               /* default data area */
2785               if (TREE_READONLY (decl))
2786                 kind = GHS_SECTION_KIND_RODATA;
2787               else if (DECL_INITIAL (decl))
2788                 kind = GHS_SECTION_KIND_DATA;
2789               else
2790                 kind = GHS_SECTION_KIND_BSS;
2791             }
2792         }
2793
2794       /* Now, if the section kind has been explicitly renamed,
2795          then attach a section attribute. */
2796       chosen_section = GHS_current_section_names [(int) kind];
2797
2798       /* Otherwise, if this kind of section needs an explicit section
2799          attribute, then also attach one. */
2800       if (chosen_section == NULL)
2801         chosen_section = GHS_default_section_names [(int) kind];
2802
2803       if (chosen_section)
2804         {
2805           /* Only set the section name if specified by a pragma, because
2806              otherwise it will force those variables to get allocated storage
2807              in this module, rather than by the linker.  */
2808           DECL_SECTION_NAME (decl) = chosen_section;
2809         }
2810     }
2811 }
2812 \f
2813 /* Implement `va_arg'.  */
2814
2815 rtx
2816 v850_va_arg (valist, type)
2817      tree valist, type;
2818 {
2819   HOST_WIDE_INT size, rsize;
2820   tree addr, incr;
2821   rtx addr_rtx;
2822   int indirect;
2823
2824   /* Round up sizeof(type) to a word.  */
2825   size = int_size_in_bytes (type);
2826   rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
2827   indirect = 0;
2828
2829   if (size > 8)
2830     {
2831       size = rsize = UNITS_PER_WORD;
2832       indirect = 1;
2833     }
2834
2835   addr = save_expr (valist);
2836   incr = fold (build (PLUS_EXPR, ptr_type_node, addr,
2837                       build_int_2 (rsize, 0)));
2838
2839   incr = build (MODIFY_EXPR, ptr_type_node, valist, incr);
2840   TREE_SIDE_EFFECTS (incr) = 1;
2841   expand_expr (incr, const0_rtx, VOIDmode, EXPAND_NORMAL);
2842
2843   addr_rtx = expand_expr (addr, NULL, Pmode, EXPAND_NORMAL);
2844
2845   if (indirect)
2846     {
2847       addr_rtx = force_reg (Pmode, addr_rtx);
2848       addr_rtx = gen_rtx_MEM (Pmode, addr_rtx);
2849       set_mem_alias_set (addr_rtx, get_varargs_alias_set ());
2850     }
2851
2852   return addr_rtx;
2853 }
2854 \f
2855 /* Return an RTX indicating where the return address to the
2856    calling function can be found.  */
2857
2858 rtx
2859 v850_return_addr (count)
2860      int count;
2861 {
2862   if (count != 0)
2863     return const0_rtx;
2864
2865   return get_hard_reg_initial_val (Pmode, LINK_POINTER_REGNUM);
2866 }
2867 \f
2868 static void
2869 v850_select_section (exp, reloc, align)
2870      tree exp;
2871      int reloc;
2872      unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
2873 {
2874   if (TREE_CODE (exp) == VAR_DECL)
2875     {
2876       int is_const;
2877       if (!TREE_READONLY (exp)
2878           || TREE_SIDE_EFFECTS (exp)
2879           || !DECL_INITIAL (exp)
2880           || (DECL_INITIAL (exp) != error_mark_node
2881               && !TREE_CONSTANT (DECL_INITIAL (exp))))
2882         is_const = FALSE;
2883       else
2884         is_const = TRUE;
2885
2886       switch (v850_get_data_area (exp))
2887         {
2888         case DATA_AREA_ZDA:
2889           if (is_const)
2890             rozdata_section ();
2891           else
2892             zdata_section ();
2893           break;
2894
2895         case DATA_AREA_TDA:
2896           tdata_section ();
2897           break;
2898
2899         case DATA_AREA_SDA:
2900           if (is_const)
2901             rosdata_section ();
2902           else
2903             sdata_section ();
2904           break;
2905
2906         default:
2907           if (is_const)
2908             readonly_data_section ();
2909           else
2910             data_section ();
2911           break;
2912         }
2913     }
2914   else if (TREE_CODE (exp) == STRING_CST)
2915     {
2916       if (! flag_writable_strings)
2917         readonly_data_section ();
2918       else
2919         data_section ();
2920     }
2921   else
2922     readonly_data_section ();
2923 }