OSDN Git Service

* system.h (STRIP_NAME_ENCODING): Poison it.
[pf3gnuchains/gcc-fork.git] / gcc / config / cris / cris.c
1 /* Definitions for GCC.  Part of the machine description for CRIS.
2    Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3    Contributed by Axis Communications.  Written by Hans-Peter Nilsson.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "regs.h"
26 #include "hard-reg-set.h"
27 #include "real.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-attr.h"
31 #include "flags.h"
32 #include "tree.h"
33 #include "expr.h"
34 #include "except.h"
35 #include "function.h"
36 #include "toplev.h"
37 #include "recog.h"
38 #include "tm_p.h"
39 #include "debug.h"
40 #include "output.h"
41 #include "target.h"
42 #include "target-def.h"
43
44 /* Usable when we have an amount to add or subtract, and want the
45    optimal size of the insn.  */
46 #define ADDITIVE_SIZE_MODIFIER(size) \
47  ((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d")
48
49 #define ASSERT_PLT_UNSPEC(x)                                    \
50   do                                                            \
51     {                                                           \
52       if (XEXP (x, 1) != NULL_RTX                               \
53           || (GET_CODE (XVECEXP (x, 0, 0)) != SYMBOL_REF        \
54               && GET_CODE (XVECEXP (x, 0, 0)) != LABEL_REF))    \
55         abort ();                                               \
56     } while (0)
57
58 #define LOSE_AND_RETURN(msgid, x)                       \
59   do                                            \
60     {                                           \
61       cris_operand_lossage (msgid, x);          \
62       return;                                   \
63     } while (0)
64
65 /* Per-function machine data.  */
66 struct machine_function
67  {
68    int needs_return_address_on_stack;
69  };
70
71 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
72    pattern.  */
73 static char cris_output_insn_is_bound = 0;
74
75 /* This one suppresses printing out the "rPIC+" in
76    "rPIC+sym:GOTOFF+offset" when doing PIC.  For a PLT symbol, it
77    suppresses outputting it as [rPIC+sym:GOTPLT] and outputs similarly
78    just the "sym:GOTOFF" part.  */
79 static int cris_pic_sympart_only = 0;
80
81 /* Fix for reg_overlap_mentioned_p.  */
82 static int cris_reg_overlap_mentioned_p PARAMS ((rtx, rtx));
83
84 static void cris_print_base PARAMS ((rtx, FILE *));
85
86 static void cris_print_index PARAMS ((rtx, FILE *));
87
88 static void cris_init_machine_status PARAMS ((struct function *));
89
90 static int cris_initial_frame_pointer_offset PARAMS ((void));
91
92 static int saved_regs_mentioned PARAMS ((rtx));
93
94 static void cris_target_asm_function_prologue
95   PARAMS ((FILE *, HOST_WIDE_INT));
96
97 static void cris_target_asm_function_epilogue
98   PARAMS ((FILE *, HOST_WIDE_INT));
99
100 static void cris_encode_section_info PARAMS ((tree, int));
101 static void cris_operand_lossage PARAMS ((const char *, rtx));
102
103 /* The function cris_target_asm_function_epilogue puts the last insn to
104    output here.  It always fits; there won't be a symbol operand.  Used in
105    delay_slots_for_epilogue and function_epilogue.  */
106 static char save_last[80];
107
108 /* This is the argument from the "-max-stack-stackframe=" option.  */
109 const char *cris_max_stackframe_str;
110
111 /* This is the argument from the "-march=" option.  */
112 const char *cris_cpu_str;
113
114 /* This is the argument from the "-mtune=" option.  */
115 const char *cris_tune_str;
116
117 /* This is the argument from the "-melinux-stacksize=" option.  */
118 const char *cris_elinux_stacksize_str;
119
120 /* This is the parsed result of the "-max-stack-stackframe=" option.  If
121    it (still) is zero, then there was no such option given.  */
122 int cris_max_stackframe = 0;
123
124 /* This is the parsed result of the "-march=" option, if given.  */
125 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
126
127 #undef TARGET_ASM_ALIGNED_HI_OP
128 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
129 #undef TARGET_ASM_ALIGNED_SI_OP
130 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
131 #undef TARGET_ASM_ALIGNED_DI_OP
132 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
133
134 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
135    available in ELF.  These "normal" pseudos do not have any alignment
136    constraints or side-effects.  */
137 #undef TARGET_ASM_UNALIGNED_HI_OP
138 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
139
140 #undef TARGET_ASM_UNALIGNED_SI_OP
141 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
142
143 #undef TARGET_ASM_UNALIGNED_DI_OP
144 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
145
146 #undef TARGET_ASM_FUNCTION_PROLOGUE
147 #define TARGET_ASM_FUNCTION_PROLOGUE cris_target_asm_function_prologue
148
149 #undef TARGET_ASM_FUNCTION_EPILOGUE
150 #define TARGET_ASM_FUNCTION_EPILOGUE cris_target_asm_function_epilogue
151
152 #undef TARGET_ENCODE_SECTION_INFO
153 #define TARGET_ENCODE_SECTION_INFO cris_encode_section_info
154
155 struct gcc_target targetm = TARGET_INITIALIZER;
156
157 /* Predicate functions.  */
158
159 /* This checks a part of an address, the one that is not a plain register
160    for an addressing mode using BDAP.
161    Allowed operands is either:
162    a) a register
163    b) a CONST operand (but not a symbol when generating PIC)
164    c) a [r] or [r+] in SImode, or sign-extend from HI or QI.  */
165
166 int
167 cris_bdap_operand (op, mode)
168      rtx op;
169      enum machine_mode mode;
170 {
171   register enum rtx_code code = GET_CODE (op);
172
173   if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
174     return 0;
175
176   /* Just return whether this is a simple register or constant.  */
177   if (register_operand (op, mode)
178       || (CONSTANT_P (op) && !(flag_pic && cris_symbol (op))))
179     return 1;
180
181   /* Is it a [r] or possibly a [r+]?  */
182   if (code == MEM)
183     {
184       rtx tem = XEXP (op, 0);
185
186       if (mode == SImode
187           && (register_operand (tem, SImode)
188               || (GET_CODE (tem) == POST_INC
189                   && register_operand (XEXP (tem, 0), SImode))))
190         return 1;
191       else
192         return 0;
193     }
194
195   /* Perhaps a sign-extended mem: [r].(b|w) or [r+].(b|w)?  */
196   if (code == SIGN_EXTEND)
197     {
198       rtx tem = XEXP (op, 0);
199
200       if (GET_CODE (tem) != MEM)
201         return 0;
202
203       tem = XEXP (tem, 0);
204       if (mode == SImode
205           && (register_operand (tem, SImode)
206               || (GET_CODE (tem) == POST_INC
207                   && register_operand (XEXP (tem, 0), SImode))))
208         return 1;
209       else
210         return 0;
211     }
212
213   return 0;
214 }
215
216 /* This is similar to cris_bdap_operand:
217    It checks a part of an address, the one that is not a plain register
218    for an addressing mode using BDAP *or* BIAP.
219    Allowed operands is either:
220    a) a register
221    b) a CONST operand (but not a symbol when generating PIC)
222    c) a mult of (1, 2 or 4) and a register
223    d) a [r] or [r+] in SImode, or sign-extend from HI or QI.  */
224
225 int
226 cris_bdap_biap_operand (op, mode)
227      rtx op;
228      enum machine_mode mode;
229 {
230   register enum rtx_code code = GET_CODE (op);
231   rtx reg;
232   rtx val;
233
234   /* Check for bdap operand.  */
235   if (cris_bdap_operand (op, mode))
236     return 1;
237
238   if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
239     return 0;
240
241   /* Check that we're looking at a BIAP operand.  */
242   if (code != MULT)
243     return 0;
244
245   /* Canonicalize register and multiplicand.  */
246   if (GET_CODE (XEXP (op, 0)) == CONST_INT)
247     {
248       val = XEXP (op, 0);
249       reg = XEXP (op, 1);
250     }
251   else
252     {
253       val = XEXP (op, 1);
254       reg = XEXP (op, 0);
255     }
256
257   /* Check that the operands are correct after canonicalization.  */
258   if (! register_operand (reg, SImode) || GET_CODE (val) != CONST_INT)
259     return 0;
260
261   /* Check that the multiplicand has a valid value.  */
262   if ((code == MULT
263        && (INTVAL (val) == 1 || INTVAL (val) == 2 || INTVAL (val) == 4)))
264     return 1;
265
266   return 0;
267 }
268
269 /* Check if MODE is same as mode for X, and X is PLUS, MINUS, IOR or
270    AND or UMIN.  */
271
272 int
273 cris_orthogonal_operator (x, mode)
274      rtx x;
275      enum machine_mode mode;
276 {
277   enum rtx_code code = GET_CODE (x);
278
279   if (mode == VOIDmode)
280     mode = GET_MODE (x);
281
282   return (GET_MODE (x) == mode
283           && (code == PLUS || code == MINUS
284               || code == IOR || code == AND || code == UMIN));
285 }
286
287 /* Check if MODE is same as mode for X, and X is PLUS, IOR or AND or
288    UMIN.  */
289
290 int
291 cris_commutative_orth_op (x, mode)
292      rtx x;
293      enum machine_mode mode;
294 {
295   enum rtx_code code = GET_CODE (x);
296
297   if (mode == VOIDmode)
298     mode = GET_MODE (x);
299
300   return (GET_MODE (x) == mode &&
301           (code == PLUS
302            || code == IOR || code == AND || code == UMIN));
303 }
304
305 /* Check if MODE is same as mode for X, and X is PLUS or MINUS or UMIN.  */
306
307 int
308 cris_operand_extend_operator (x, mode)
309      rtx x;
310      enum machine_mode mode;
311 {
312   enum rtx_code code = GET_CODE (x);
313
314   if (mode == VOIDmode)
315     mode = GET_MODE (x);
316
317   return (GET_MODE (x) == mode
318           && (code == PLUS || code == MINUS || code == UMIN));
319 }
320
321 /* Check to see if MODE is same as mode for X, and X is SIGN_EXTEND or
322    ZERO_EXTEND.  */
323
324 int
325 cris_extend_operator (x, mode)
326      rtx x;
327      enum machine_mode mode;
328 {
329   enum rtx_code code = GET_CODE (x);
330
331   if (mode == VOIDmode)
332     mode = GET_MODE (x);
333
334   return
335     (GET_MODE (x) == mode && (code == SIGN_EXTEND || code == ZERO_EXTEND));
336 }
337
338 /* Check to see if MODE is same as mode for X, and X is PLUS or BOUND.  */
339
340 int
341 cris_plus_or_bound_operator (x, mode)
342      rtx x;
343      enum machine_mode mode;
344 {
345   enum rtx_code code = GET_CODE (x);
346
347   if (mode == VOIDmode)
348     mode = GET_MODE (x);
349
350   return
351     (GET_MODE (x) == mode && (code == UMIN || code == PLUS));
352 }
353
354 /* Since with -fPIC, not all symbols are valid PIC symbols or indeed
355    general_operands, we have to have a predicate that matches it for the
356    "movsi" expander.  */
357
358 int
359 cris_general_operand_or_symbol (op, mode)
360      rtx op;
361      enum machine_mode mode;
362 {
363   return general_operand (op, mode)
364     || (CONSTANT_P (op) && cris_symbol (op));
365 }
366
367 /* Since a PIC symbol without a GOT entry is not a general_operand, we
368    have to have a predicate that matches it.  We use this in the expanded
369    "movsi" anonymous pattern for PIC symbols.  */
370
371 int
372 cris_general_operand_or_gotless_symbol (op, mode)
373      rtx op;
374      enum machine_mode mode;
375 {
376   return general_operand (op, mode)
377     || (CONSTANT_P (op) && cris_gotless_symbol (op));
378 }
379
380 /* Since a PLT symbol is not a general_operand, we have to have a
381    predicate that matches it when we need it.  We use this in the expanded
382    "call" and "call_value" anonymous patterns.  */
383
384 int
385 cris_general_operand_or_plt_symbol (op, mode)
386      rtx op;
387      enum machine_mode mode;
388 {
389   return general_operand (op, mode)
390     || (GET_CODE (op) == CONST
391         && GET_CODE (XEXP (op, 0)) == UNSPEC
392         && !TARGET_AVOID_GOTPLT);
393 }
394
395 /* This matches a (MEM (general_operand)) or
396    (MEM (cris_general_operand_or_symbol)).  The second one isn't a valid
397    memory_operand, so we need this predicate to recognize call
398    destinations before we change them to a PLT operand (by wrapping in
399    UNSPEC 0).  */
400
401 int
402 cris_mem_call_operand (op, mode)
403      rtx op;
404      enum machine_mode mode;
405 {
406   rtx xmem;
407
408   if (GET_CODE (op) != MEM)
409     return 0;
410
411   if (memory_operand (op, mode))
412     return 1;
413
414   xmem = XEXP (op, 0);
415
416   return cris_general_operand_or_symbol (xmem, GET_MODE (op));
417 }
418
419 /* The CONDITIONAL_REGISTER_USAGE worker.   */
420
421 void
422 cris_conditional_register_usage ()
423 {
424   /* FIXME: This isn't nice.  We should be able to use that register for
425      something else if the PIC table isn't needed.  */
426   if (flag_pic)
427     fixed_regs[PIC_OFFSET_TABLE_REGNUM]
428       = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
429 }
430
431 /* Return current_function_uses_pic_offset_table.  For use in cris.md,
432    since some generated files do not include function.h.  */
433
434 int
435 cris_cfun_uses_pic_table ()
436 {
437   return current_function_uses_pic_offset_table;
438 }
439
440 /* Given an rtx, return the text string corresponding to the CODE of X.
441    Intended for use in the assembly language output section of a
442    define_insn.  */
443
444 const char *
445 cris_op_str (x)
446      rtx x;
447 {
448   cris_output_insn_is_bound = 0;
449   switch (GET_CODE (x))
450     {
451     case PLUS:
452       return "add";
453       break;
454
455     case MINUS:
456       return "sub";
457       break;
458
459     case MULT:
460       return "mul";
461       break;
462
463     case DIV:
464       return "div";
465       break;
466
467     case AND:
468       return "and";
469       break;
470
471     case IOR:
472       return "or";
473       break;
474
475     case XOR:
476       return "xor";
477       break;
478
479     case NOT:
480       return "not";
481       break;
482
483     case ASHIFT:
484       return "lsl";
485       break;
486
487     case LSHIFTRT:
488       return "lsr";
489       break;
490
491     case ASHIFTRT:
492       return "asr";
493       break;
494
495     case UMIN:
496       /* Used to control the sign/zero-extend character for the 'e' modifier.
497          BOUND has none.  */
498       cris_output_insn_is_bound = 1;
499       return "bound";
500       break;
501
502     default:
503       return "Unknown operator";
504       break;
505   }
506 }
507
508 /* Emit an error message when we're in an asm, and a fatal error for
509    "normal" insns.  Formatted output isn't easily implemented, since we
510    use output_operand_lossage to output the actual message and handle the
511    categorization of the error.  */
512
513 static void
514 cris_operand_lossage (msgid, op)
515      const char *msgid;
516      rtx op;
517 {
518   debug_rtx (op);
519   output_operand_lossage ("%s", msgid);
520 }
521
522 /* Print an index part of an address to file.  */
523
524 static void
525 cris_print_index (index, file)
526      rtx index;
527      FILE * file;
528 {
529   rtx inner = XEXP (index, 0);
530
531   /* Make the index "additive" unless we'll output a negative number, in
532      which case the sign character is free (as in free beer).  */
533   if (GET_CODE (index) != CONST_INT || INTVAL (index) >= 0)
534     putc ('+', file);
535
536   if (REG_P (index))
537     fprintf (file, "$%s.b", reg_names[REGNO (index)]);
538   else if (CONSTANT_P (index))
539     cris_output_addr_const (file, index);
540   else if (GET_CODE (index) == MULT)
541     {
542       fprintf (file, "$%s.",
543                reg_names[REGNO (XEXP (index, 0))]);
544
545       putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
546     }
547   else if (GET_CODE (index) == SIGN_EXTEND &&
548            GET_CODE (inner) == MEM)
549     {
550       rtx inner_inner = XEXP (inner, 0);
551
552       if (GET_CODE (inner_inner) == POST_INC)
553         {
554           fprintf (file, "[$%s+].",
555                    reg_names[REGNO (XEXP (inner_inner, 0))]);
556           putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
557         }
558       else
559         {
560           fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
561
562           putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
563         }
564     }
565   else if (GET_CODE (index) == MEM)
566     {
567       if (GET_CODE (inner) == POST_INC)
568         fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
569       else
570         fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
571     }
572   else
573     cris_operand_lossage ("unexpected index-type in cris_print_index",
574                           index);
575 }
576
577 /* Print a base rtx of an address to file.  */
578
579 static void
580 cris_print_base (base, file)
581      rtx base;
582      FILE *file;
583 {
584   if (REG_P (base))
585     fprintf (file, "$%s", reg_names[REGNO (base)]);
586   else if (GET_CODE (base) == POST_INC)
587     fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
588   else
589     cris_operand_lossage ("unexpected base-type in cris_print_base",
590                           base);
591 }
592
593 /* Usable as a guard in expressions.  */
594
595 int
596 cris_fatal (arg)
597      char *arg;
598 {
599   internal_error (arg);
600
601   /* We'll never get here; this is just to appease compilers.  */
602   return 0;
603 }
604
605 /* Textual function prologue.  */
606
607 static void
608 cris_target_asm_function_prologue (file, size)
609      FILE *file;
610      HOST_WIDE_INT size;
611 {
612   int regno;
613
614   /* Shorten the used name for readability.  */
615   int cfoa_size = current_function_outgoing_args_size;
616   int last_movem_reg = -1;
617   int doing_dwarf = dwarf2out_do_frame ();
618   int framesize;
619   int faked_args_size = 0;
620   int cfa_write_offset = 0;
621   char *cfa_label = NULL;
622   int return_address_on_stack
623     = regs_ever_live[CRIS_SRP_REGNUM]
624     || cfun->machine->needs_return_address_on_stack != 0;
625
626   /* Don't do anything if no prologues or epilogues are wanted.  */
627   if (!TARGET_PROLOGUE_EPILOGUE)
628     return;
629
630   if (size < 0)
631     abort ();
632
633   /* Align the size to what's best for the CPU model.  */
634   if (TARGET_STACK_ALIGN)
635     size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
636
637   if (current_function_pretend_args_size)
638     {
639       int pretend = current_function_pretend_args_size;
640       for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
641            pretend > 0;
642            regno--, pretend -= 4)
643         {
644           fprintf (file, "\tpush $%s\n", reg_names[regno]);
645           faked_args_size += 4;
646         }
647     }
648
649   framesize = faked_args_size;
650
651   if (doing_dwarf)
652     {
653       /* FIXME: Slightly redundant calculation, as we do the same in
654          pieces below.  This offset must be the total adjustment of the
655          stack-pointer.  We can then def_cfa call at the end of this
656          function with the current implementation of execute_cfa_insn, but
657          that wouldn't really be clean.  */
658
659       int cfa_offset
660         = faked_args_size
661         + (return_address_on_stack ? 4 : 0)
662         + (frame_pointer_needed ? 4 : 0);
663
664       int cfa_reg;
665
666       if (frame_pointer_needed)
667         cfa_reg = FRAME_POINTER_REGNUM;
668       else
669         {
670           cfa_reg = STACK_POINTER_REGNUM;
671           cfa_offset += cris_initial_frame_pointer_offset ();
672         }
673
674       cfa_label = dwarf2out_cfi_label ();
675       dwarf2out_def_cfa (cfa_label, cfa_reg, cfa_offset);
676
677       cfa_write_offset = - faked_args_size - 4;
678     }
679
680   /* Save SRP if not a leaf function.  */
681   if (return_address_on_stack)
682     {
683       fprintf (file, "\tPush $srp\n");
684       framesize += 4;
685
686       if (doing_dwarf)
687         {
688           dwarf2out_return_save (cfa_label, cfa_write_offset);
689           cfa_write_offset -= 4;
690         }
691     }
692
693   /* Set up frame pointer if needed.  */
694   if (frame_pointer_needed)
695     {
696       fprintf (file, "\tpush $%s\n\tmove.d $sp,$%s\n",
697                reg_names[FRAME_POINTER_REGNUM],
698                reg_names[FRAME_POINTER_REGNUM]);
699       framesize += 4;
700
701       if (doing_dwarf)
702         {
703           dwarf2out_reg_save (cfa_label, FRAME_POINTER_REGNUM,
704                               cfa_write_offset);
705           cfa_write_offset -= 4;
706         }
707     }
708
709   /* Local vars are located above saved regs.  */
710   cfa_write_offset -= size;
711
712   /* Get a contiguous sequence of registers, starting with r0, that need
713      to be saved.  */
714   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
715     {
716       if ((((regs_ever_live[regno]
717              && !call_used_regs[regno])
718             || (regno == (int) PIC_OFFSET_TABLE_REGNUM
719                 && (current_function_uses_pic_offset_table
720                     /* It is saved anyway, if there would be a gap.  */
721                     || (flag_pic
722                         && regs_ever_live[regno + 1]
723                         && !call_used_regs[regno + 1]))))
724            && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
725            && regno != CRIS_SRP_REGNUM)
726           || (current_function_calls_eh_return
727               && (regno == EH_RETURN_DATA_REGNO (0)
728                   || regno == EH_RETURN_DATA_REGNO (1)
729                   || regno == EH_RETURN_DATA_REGNO (2)
730                   || regno == EH_RETURN_DATA_REGNO (3))))
731         {
732           /* Check if movem may be used for registers so far.  */
733           if (regno == last_movem_reg + 1)
734             /* Yes, update next expected register.  */
735             last_movem_reg++;
736           else
737             {
738               /* We cannot use movem for all registers.  We have to flush
739                  any movem:ed registers we got so far.  */
740               if (last_movem_reg != -1)
741                 {
742                   /* It is a win to use a side-effect assignment for
743                      64 <= size <= 128.  But side-effect on movem was
744                      not usable for CRIS v0..3.  Also only do it if
745                      side-effects insns are allowed.  */
746                   if ((last_movem_reg + 1) * 4 + size >= 64
747                       && (last_movem_reg + 1) * 4 + size <= 128
748                       && cris_cpu_version >= CRIS_CPU_SVINTO
749                       && TARGET_SIDE_EFFECT_PREFIXES)
750                     fprintf (file, "\tmovem $%s,[$sp=$sp-%d]\n",
751                              reg_names[last_movem_reg],
752                              (last_movem_reg + 1) * 4 + size);
753                   else
754                     {
755                       /* Avoid printing multiple subsequent sub:s for sp.  */
756                       fprintf (file, "\tsub%s %d,$sp\n",
757                                ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1)
758                                                        * 4 + size),
759                                (last_movem_reg + 1) * 4 + size);
760
761                       fprintf (file, "\tmovem $%s,[$sp]\n",
762                                reg_names[last_movem_reg]);
763                     }
764
765                   framesize += (last_movem_reg + 1) * 4 + size;
766
767                   if (TARGET_PDEBUG)
768                     fprintf (file, "; frame %d, #regs %d, bytes %d args %d\n",
769                              size,
770                              last_movem_reg + 1,
771                              (last_movem_reg + 1) * 4,
772                              current_function_args_size);
773
774                   last_movem_reg = -1;
775                   size = 0;
776                 }
777               else if (size > 0)
778                 {
779                   /* Local vars on stack, but there are no movem:s.
780                      Just allocate space.  */
781                   fprintf (file, "\tSub%s %d,$sp\n",
782                            ADDITIVE_SIZE_MODIFIER (size),
783                            size);
784                   framesize += size;
785                   size = 0;
786                 }
787
788               fprintf (file, "\tPush $%s\n", reg_names[regno]);
789               framesize += 4;
790             }
791
792           if (doing_dwarf)
793             {
794               /* Registers are stored lowest numbered at highest address,
795                  which matches the loop order; we just need to update the
796                  write-offset.  */
797               dwarf2out_reg_save (cfa_label, regno, cfa_write_offset);
798               cfa_write_offset -= 4;
799             }
800         }
801     }
802
803   /* Check after, if we can movem all registers.  This is the normal
804      case.  */
805   if (last_movem_reg != -1)
806     {
807       /* Side-effect assignment on movem was not supported for CRIS v0..3,
808          and don't do it if we're asked not to.
809
810          The movem is already accounted for, for unwind.  */
811
812       if ((last_movem_reg + 1) * 4 + size >= 64
813           && (last_movem_reg + 1) * 4 + size <= 128
814           && cris_cpu_version >= CRIS_CPU_SVINTO
815           && TARGET_SIDE_EFFECT_PREFIXES)
816         fprintf (file, "\tmovem $%s,[$sp=$sp-%d]\n",
817                  reg_names[last_movem_reg],
818                  (last_movem_reg+1) * 4 + size);
819       else
820         {
821           /* Avoid printing multiple subsequent sub:s for sp.  FIXME:
822              Clean up the conditional expression.  */
823           fprintf (file, "\tsub%s %d,$sp\n",
824                    ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1) * 4 + size),
825                    (last_movem_reg + 1) * 4 + size);
826           /* To be compatible with v0..v3 means we do not use an assignment
827              addressing mode with movem.  We normally don't need that
828              anyway.  It would only be slightly more efficient for 64..128
829              bytes frame size.  */
830           fprintf (file, "\tmovem $%s,[$sp]\n", reg_names[last_movem_reg]);
831         }
832
833       framesize += (last_movem_reg + 1) * 4 + size;
834
835       if (TARGET_PDEBUG)
836         fprintf (file, "; frame %d, #regs %d, bytes %d args %d\n",
837                  size,
838                  last_movem_reg + 1,
839                  (last_movem_reg + 1) * 4,
840                  current_function_args_size);
841
842       /* We have to put outgoing argument space after regs.  */
843       if (cfoa_size)
844         {
845           /* This does not need to be accounted for, for unwind.  */
846
847           fprintf (file, "\tSub%s %d,$sp\n",
848                    ADDITIVE_SIZE_MODIFIER (cfoa_size),
849                    cfoa_size);
850           framesize += cfoa_size;
851         }
852     }
853   else if ((size + cfoa_size) > 0)
854     {
855       /* This does not need to be accounted for, for unwind.  */
856
857       /* Local vars on stack, and we could not use movem.  Add a sub here.  */
858       fprintf (file, "\tSub%s %d,$sp\n",
859                ADDITIVE_SIZE_MODIFIER (size + cfoa_size),
860                cfoa_size + size);
861       framesize += size + cfoa_size;
862     }
863
864   /* Set up the PIC register.  */
865   if (current_function_uses_pic_offset_table)
866     asm_fprintf (file, "\tmove.d $pc,$%s\n\tsub.d .:GOTOFF,$%s\n",
867                  reg_names[PIC_OFFSET_TABLE_REGNUM],
868                  reg_names[PIC_OFFSET_TABLE_REGNUM]);
869
870   if (TARGET_PDEBUG)
871     fprintf (file,
872              "; parm #%d @ %d; frame %d, FP-SP is %d; leaf: %s%s; fp %s, outg: %d arg %d\n",
873              CRIS_MAX_ARGS_IN_REGS + 1, FIRST_PARM_OFFSET (0),
874              get_frame_size (),
875              cris_initial_frame_pointer_offset (),
876              leaf_function_p () ? "yes" : "no",
877              return_address_on_stack ? "no" :"yes",
878              frame_pointer_needed ? "yes" : "no",
879              cfoa_size, current_function_args_size);
880
881   if (cris_max_stackframe && framesize > cris_max_stackframe)
882     warning ("stackframe too big: %d bytes", framesize);
883 }
884
885 /* Return nonzero if there are regs mentioned in the insn that are not all
886    in the call_used regs.  This is part of the decision whether an insn
887    can be put in the epilogue.  */
888
889 static int
890 saved_regs_mentioned (x)
891      rtx x;
892 {
893   int i;
894   const char *fmt;
895   RTX_CODE code;
896
897   /* Mainly stolen from refers_to_regno_p in rtlanal.c.  */
898
899   code = GET_CODE (x);
900
901   switch (code)
902     {
903     case REG:
904       i = REGNO (x);
905       return !call_used_regs[i];
906
907     case SUBREG:
908       /* If this is a SUBREG of a hard reg, we can see exactly which
909          registers are being modified.  Otherwise, handle normally.  */
910       i = REGNO (SUBREG_REG (x));
911       return !call_used_regs[i];
912
913     default:
914       ;
915     }
916
917   fmt = GET_RTX_FORMAT (code);
918   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
919     {
920       if (fmt[i] == 'e')
921         {
922           if (saved_regs_mentioned (XEXP (x, i)))
923             return 1;
924         }
925       else if (fmt[i] == 'E')
926         {
927           int j;
928           for (j = XVECLEN (x, i) - 1; j >=0; j--)
929             if (saved_regs_mentioned (XEXP (x, i)))
930               return 1;
931         }
932     }
933
934   return 0;
935 }
936
937 /* Figure out if the insn may be put in the epilogue.  */
938
939 int
940 cris_eligible_for_epilogue_delay (insn)
941      rtx insn;
942 {
943   /* First of all, it must be as slottable as for a delayed branch insn.  */
944   if (get_attr_slottable (insn) != SLOTTABLE_YES)
945     return 0;
946
947   /* It must not refer to the stack pointer (may be valid for some cases
948      that I can't think of).  */
949   if (reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)))
950     return 0;
951
952   /* The frame pointer will be restored in the epilogue, before the
953      "ret", so it can't be referred to.  */
954   if (frame_pointer_needed
955       && reg_mentioned_p (frame_pointer_rtx, PATTERN (insn)))
956     return 0;
957
958   /* All saved regs are restored before the delayed insn.
959      This means that we cannot have any instructions that mention the
960      registers that are restored by the epilogue.  */
961   if (saved_regs_mentioned (PATTERN (insn)))
962     return 0;
963
964   /* It seems to be ok.  */
965   return 1;
966 }
967
968 /* Return the number of delay-slots in the epilogue: return 1 if it
969    contains "ret", else 0.  */
970
971 int
972 cris_delay_slots_for_epilogue ()
973 {
974   /* Check if we use a return insn, which we only do for leaf functions.
975      Else there is no slot to fill.  */
976   if (regs_ever_live[CRIS_SRP_REGNUM]
977       || cfun->machine->needs_return_address_on_stack != 0)
978     return 0;
979
980   /* By calling function_epilogue with the same parameters as from gcc
981      we can get info about if the epilogue can fill the delay-slot by itself.
982      If it is filled from the epilogue, then the corresponding string
983      is in save_last.
984       This depends on that the "size" argument to function_epilogue
985      always is get_frame_size.
986      FIXME:  Kludgy.  At least make it a separate function that is not
987      misnamed or abuses the stream parameter.  */
988   cris_target_asm_function_epilogue (NULL, get_frame_size ());
989
990   if (*save_last)
991     return 1;
992   return 0;
993 }
994
995 /* Textual function epilogue.  When file is NULL, it serves doubly as
996    a test for whether the epilogue can fill any "ret" delay-slots by
997    itself by storing the delay insn in save_last.  */
998
999 static void
1000 cris_target_asm_function_epilogue (file, size)
1001      FILE *file;
1002      HOST_WIDE_INT size;
1003 {
1004   int regno;
1005   int last_movem_reg = -1;
1006   rtx insn = get_last_insn ();
1007   int argspace_offset = current_function_outgoing_args_size;
1008   int pretend =  current_function_pretend_args_size;
1009   int return_address_on_stack
1010     = regs_ever_live[CRIS_SRP_REGNUM]
1011     || cfun->machine->needs_return_address_on_stack != 0;
1012
1013   save_last[0] = 0;
1014
1015   if (file && !TARGET_PROLOGUE_EPILOGUE)
1016     return;
1017
1018   if (TARGET_PDEBUG && file)
1019     fprintf (file, ";;\n");
1020
1021   /* Align byte count of stack frame.  */
1022   if (TARGET_STACK_ALIGN)
1023     size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
1024
1025   /* If the last insn was a BARRIER, we don't have to write any code,
1026      then all returns were covered by "return" insns.  */
1027   if (GET_CODE (insn) == NOTE)
1028     insn = prev_nonnote_insn (insn);
1029   if (insn
1030       && (GET_CODE (insn) == BARRIER
1031           /* We must make sure that the insn really is a "return" and
1032              not a conditional branch.  Try to match the return exactly,
1033              and if it doesn't match, assume it is a conditional branch
1034              (and output an epilogue).  */
1035           || (GET_CODE (insn) == JUMP_INSN
1036               && GET_CODE (PATTERN (insn)) == RETURN)))
1037     {
1038       if (TARGET_PDEBUG && file)
1039         fprintf (file, ";;;;;\n");
1040       return;
1041     }
1042
1043   /* Check how many saved regs we can movem.  They start at r0 and must
1044      be contiguous.  */
1045   for (regno = 0;
1046        regno < FIRST_PSEUDO_REGISTER;
1047        regno++)
1048     if ((((regs_ever_live[regno]
1049            && !call_used_regs[regno])
1050           || (regno == (int) PIC_OFFSET_TABLE_REGNUM
1051               && (current_function_uses_pic_offset_table
1052                   /* It is saved anyway, if there would be a gap.  */
1053                   || (flag_pic
1054                       && regs_ever_live[regno + 1]
1055                       && !call_used_regs[regno + 1]))))
1056          && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1057          && regno != CRIS_SRP_REGNUM)
1058         || (current_function_calls_eh_return
1059             && (regno == EH_RETURN_DATA_REGNO (0)
1060                 || regno == EH_RETURN_DATA_REGNO (1)
1061                 || regno == EH_RETURN_DATA_REGNO (2)
1062                 || regno == EH_RETURN_DATA_REGNO (3))))
1063
1064       {
1065         if (regno == last_movem_reg + 1)
1066           last_movem_reg++;
1067         else
1068           break;
1069       }
1070
1071   for (regno = FIRST_PSEUDO_REGISTER - 1;
1072        regno > last_movem_reg;
1073        regno--)
1074     if ((((regs_ever_live[regno]
1075            && !call_used_regs[regno])
1076           || (regno == (int) PIC_OFFSET_TABLE_REGNUM
1077               && (current_function_uses_pic_offset_table
1078                   /* It is saved anyway, if there would be a gap.  */
1079                   || (flag_pic
1080                       && regs_ever_live[regno + 1]
1081                       && !call_used_regs[regno + 1]))))
1082          && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1083          && regno != CRIS_SRP_REGNUM)
1084         || (current_function_calls_eh_return
1085             && (regno == EH_RETURN_DATA_REGNO (0)
1086                 || regno == EH_RETURN_DATA_REGNO (1)
1087                 || regno == EH_RETURN_DATA_REGNO (2)
1088                 || regno == EH_RETURN_DATA_REGNO (3))))
1089       {
1090         if (argspace_offset)
1091           {
1092             /* There is an area for outgoing parameters located before
1093                the saved registers.  We have to adjust for that.  */
1094             if (file)
1095               fprintf (file, "\tAdd%s %d,$sp\n",
1096                        ADDITIVE_SIZE_MODIFIER (argspace_offset),
1097                        argspace_offset);
1098
1099             /* Make sure we only do this once.  */
1100             argspace_offset = 0;
1101           }
1102
1103         /* Flush previous non-movem:ed registers.  */
1104         if (*save_last && file)
1105           fprintf (file, save_last);
1106         sprintf (save_last, "\tPop $%s\n", reg_names[regno]);
1107       }
1108
1109   if (last_movem_reg != -1)
1110     {
1111       if (argspace_offset)
1112         {
1113           /* Adjust for the outgoing parameters area, if that's not
1114              handled yet.  */
1115           if (*save_last && file)
1116             {
1117               fprintf (file, save_last);
1118               *save_last = 0;
1119             }
1120
1121           if (file)
1122             fprintf (file, "\tAdd%s %d,$sp\n",
1123                      ADDITIVE_SIZE_MODIFIER (argspace_offset),
1124                      argspace_offset);
1125           argspace_offset = 0;
1126         }
1127       /* Flush previous non-movem:ed registers.  */
1128       else if (*save_last && file)
1129         fprintf (file, save_last);
1130       sprintf (save_last, "\tmovem [$sp+],$%s\n", reg_names[last_movem_reg]);
1131     }
1132
1133   /* Restore frame pointer if necessary.  */
1134   if (frame_pointer_needed)
1135     {
1136       if (*save_last && file)
1137         fprintf (file, save_last);
1138
1139       if (file)
1140         fprintf (file, "\tmove.d $%s,$sp\n",
1141                  reg_names[FRAME_POINTER_REGNUM]);
1142       sprintf (save_last, "\tPop $%s\n",
1143                reg_names[FRAME_POINTER_REGNUM]);
1144     }
1145   else
1146     {
1147       /* If there was no frame-pointer to restore sp from, we must
1148          explicitly deallocate local variables.  */
1149
1150       /* Handle space for outgoing parameters that hasn't been handled
1151          yet.  */
1152       size += argspace_offset;
1153
1154       if (size)
1155         {
1156           if (*save_last && file)
1157             fprintf (file, save_last);
1158
1159           sprintf (save_last, "\tadd%s %d,$sp\n",
1160                    ADDITIVE_SIZE_MODIFIER (size), size);
1161         }
1162
1163       /* If the size was not in the range for a "quick", we must flush
1164          it here.  */
1165       if (size > 63)
1166         {
1167           if (file)
1168             fprintf (file, save_last);
1169           *save_last = 0;
1170         }
1171     }
1172
1173   /* If this function has no pushed register parameters
1174      (stdargs/varargs), and if it is not a leaf function, then we can
1175      just jump-return here.  */
1176   if (return_address_on_stack && pretend == 0)
1177     {
1178       if (*save_last && file)
1179         fprintf (file, save_last);
1180       *save_last = 0;
1181
1182       if (file)
1183         {
1184           if (current_function_calls_eh_return)
1185             {
1186               /* The installed EH-return address is in *this* frame, so we
1187                  need to pop it before we return.  */
1188               fprintf (file, "\tpop $srp\n");
1189               fprintf (file, "\tret\n");
1190               fprintf (file, "\tadd.d $%s,$sp\n", reg_names[CRIS_STACKADJ_REG]);
1191             }
1192           else
1193             fprintf (file, "\tJump [$sp+]\n");
1194
1195           /* Do a sanity check to avoid generating invalid code.  */
1196           if (current_function_epilogue_delay_list)
1197             internal_error ("allocated but unused delay list in epilogue");
1198         }
1199       return;
1200     }
1201
1202   /* Rather than add current_function_calls_eh_return conditions
1203      everywhere in the following code (and not be able to test it
1204      thoroughly), assert the assumption that all usage of
1205      __builtin_eh_return are handled above.  */
1206   if (current_function_calls_eh_return)
1207     internal_error ("unexpected function type needing stack adjustment for\
1208  __builtin_eh_return");
1209
1210   /* If we pushed some register parameters, then adjust the stack for
1211      them.  */
1212   if (pretend)
1213     {
1214       /* Since srp is stored on the way, we need to restore it first.  */
1215       if (return_address_on_stack)
1216         {
1217           if (*save_last && file)
1218             fprintf (file, save_last);
1219           *save_last = 0;
1220
1221           if (file)
1222             fprintf (file, "\tpop $srp\n");
1223         }
1224
1225       if (*save_last && file)
1226         fprintf (file, save_last);
1227
1228       sprintf (save_last, "\tadd%s %d,$sp\n",
1229                ADDITIVE_SIZE_MODIFIER (pretend), pretend);
1230     }
1231
1232   /* Here's where we have a delay-slot we need to fill.  */
1233   if (file && current_function_epilogue_delay_list)
1234     {
1235       /* If gcc has allocated an insn for the epilogue delay slot, but
1236          things were arranged so we now thought we could do it
1237          ourselves, don't forget to flush that insn.  */
1238       if (*save_last)
1239         fprintf (file, save_last);
1240
1241       fprintf (file, "\tRet\n");
1242
1243       /* Output the delay-slot-insn the mandated way.  */
1244       final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1245                        file, 1, -2, 1);
1246     }
1247   else if (file)
1248     {
1249       fprintf (file, "\tRet\n");
1250
1251       /* If the GCC did not do it, we have to use whatever insn we have,
1252          or a nop.  */
1253       if (*save_last)
1254         fprintf (file, save_last);
1255       else
1256         fprintf (file, "\tnOp\n");
1257     }
1258 }
1259
1260 /* The PRINT_OPERAND worker.  */
1261
1262 void
1263 cris_print_operand (file, x, code)
1264      FILE *file;
1265      rtx x;
1266      int code;
1267 {
1268   rtx operand = x;
1269
1270   /* Size-strings corresponding to MULT expressions.  */
1271   static const char *const mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
1272
1273   /* New code entries should just be added to the switch below.  If
1274      handling is finished, just return.  If handling was just a
1275      modification of the operand, the modified operand should be put in
1276      "operand", and then do a break to let default handling
1277      (zero-modifier) output the operand.  */
1278
1279   switch (code)
1280     {
1281     case 'b':
1282       /* Print the unsigned supplied integer as if it was signed
1283          and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc.  */
1284       if (GET_CODE (x) != CONST_INT
1285           || ! CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
1286         LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
1287       fprintf (file, "%d", INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
1288       return;
1289
1290     case 'x':
1291       /* Print assembler code for operator.  */
1292       fprintf (file, "%s", cris_op_str (operand));
1293       return;
1294
1295     case 'v':
1296       /* Print the operand without the PIC register.  */
1297       if (! flag_pic || ! CONSTANT_P (x) || ! cris_gotless_symbol (x))
1298         LOSE_AND_RETURN ("invalid operand for 'v' modifier", x);
1299       cris_pic_sympart_only++;
1300       cris_output_addr_const (file, x);
1301       cris_pic_sympart_only--;
1302       return;
1303
1304     case 'P':
1305       /* Print the PIC register.  Applied to a GOT-less PIC symbol for
1306          sanity.  */
1307       if (! flag_pic || ! CONSTANT_P (x) || ! cris_gotless_symbol (x))
1308         LOSE_AND_RETURN ("invalid operand for 'P' modifier", x);
1309       fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
1310       return;
1311
1312     case 'p':
1313       /* Adjust a power of two to its log2.  */
1314       if (GET_CODE (x) != CONST_INT || exact_log2 (INTVAL (x)) < 0 )
1315         LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
1316       fprintf (file, "%d", exact_log2 (INTVAL (x)));
1317       return;
1318
1319     case 's':
1320       /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
1321          respectively.  This modifier also terminates the inhibiting
1322          effects of the 'x' modifier.  */
1323       cris_output_insn_is_bound = 0;
1324       if (GET_MODE (x) == VOIDmode && GET_CODE (x) == CONST_INT)
1325         {
1326           if (INTVAL (x) >= 0)
1327             {
1328               if (INTVAL (x) <= 255)
1329                 putc ('b', file);
1330               else if (INTVAL (x) <= 65535)
1331                 putc ('w', file);
1332               else
1333                 putc ('d', file);
1334             }
1335           else
1336             putc ('d', file);
1337           return;
1338         }
1339
1340       /* For a non-integer, print the size of the operand.  */
1341       putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
1342             ? 'd' : GET_MODE (x) == HImode ? 'w'
1343             : GET_MODE (x) == QImode ? 'b'
1344             /* If none of the above, emit an erroneous size letter.  */
1345             : 'X',
1346             file);
1347       return;
1348
1349     case 'z':
1350       /* Const_int: print b for -127 <= x <= 255,
1351          w for -32768 <= x <= 65535, else abort.  */
1352       if (GET_CODE (x) != CONST_INT
1353           || INTVAL (x) < -32768 || INTVAL (x) > 65535)
1354         LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
1355       putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
1356       return;
1357
1358     case '#':
1359       /* Output a 'nop' if there's nothing for the delay slot.
1360          This method stolen from the sparc files.  */
1361       if (dbr_sequence_length () == 0)
1362         fputs ("\n\tnop", file);
1363       return;
1364
1365     case 'H':
1366       /* Print high (most significant) part of something.  */
1367       switch (GET_CODE (operand))
1368         {
1369         case CONST_INT:
1370           if (HOST_BITS_PER_WIDE_INT == 32)
1371             /* Sign-extension from a normal int to a long long.  */
1372             fprintf (file, INTVAL (operand) < 0 ? "-1" : "0");
1373           else
1374             fprintf (file, "0x%x", (unsigned int)(INTVAL (x) >> 31 >> 1));
1375           return;
1376
1377         case CONST_DOUBLE:
1378           /* High part of a long long constant.  */
1379           if (GET_MODE (operand) == VOIDmode)
1380             {
1381               fprintf (file, "0x%x", CONST_DOUBLE_HIGH (x));
1382               return;
1383             }
1384           else
1385             LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
1386
1387         case REG:
1388           /* Print reg + 1.  Check that there's not an attempt to print
1389              high-parts of registers like stack-pointer or higher.  */
1390           if (REGNO (operand) > STACK_POINTER_REGNUM - 2)
1391             LOSE_AND_RETURN ("bad register", operand);
1392           fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
1393           return;
1394
1395         case MEM:
1396           /* Adjust memory address to high part.  */
1397           {
1398             rtx adj_mem = operand;
1399             int size
1400               = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
1401
1402             /* Adjust so we can use two SImode in DImode.
1403                Calling adj_offsettable_operand will make sure it is an
1404                offsettable address.  Don't do this for a postincrement
1405                though; it should remain as it was.  */
1406             if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
1407               adj_mem
1408                 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
1409
1410             output_address (XEXP (adj_mem, 0));
1411             return;
1412           }
1413
1414         default:
1415           LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
1416         }
1417
1418     case 'L':
1419       /* Strip the MEM expression.  */
1420       operand = XEXP (operand, 0);
1421       break;
1422
1423     case 'e':
1424       /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
1425          cris_output_insn_is_bound is nonzero.  */
1426       if (GET_CODE (operand) != SIGN_EXTEND
1427           && GET_CODE (operand) != ZERO_EXTEND
1428           && GET_CODE (operand) != CONST_INT)
1429         LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
1430
1431       if (cris_output_insn_is_bound)
1432         {
1433           cris_output_insn_is_bound = 0;
1434           return;
1435         }
1436
1437       putc (GET_CODE (operand) == SIGN_EXTEND
1438             || (GET_CODE (operand) == CONST_INT && INTVAL (operand) < 0)
1439             ? 's' : 'u', file);
1440       return;
1441
1442     case 'm':
1443       /* Print the size letter of the inner element.  We can do it by
1444          calling ourselves with the 's' modifier.  */
1445       if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
1446         LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
1447       cris_print_operand (file, XEXP (operand, 0), 's');
1448       return;
1449
1450     case 'M':
1451       /* Print the least significant part of operand.  */
1452       if (GET_CODE (operand) == CONST_DOUBLE)
1453         {
1454           fprintf (file, "0x%x", CONST_DOUBLE_LOW (x));
1455           return;
1456         }
1457       else if (HOST_BITS_PER_WIDE_INT > 32 && GET_CODE (operand) == CONST_INT)
1458         {
1459           fprintf (file, "0x%x",
1460                    INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1));
1461           return;
1462         }
1463       /* Otherwise the least significant part equals the normal part,
1464          so handle it normally.  */
1465       break;
1466
1467     case 'A':
1468       /* When emitting an add for the high part of a DImode constant, we
1469          want to use addq for 0 and adds.w for -1.  */
1470       if (GET_CODE (operand) != CONST_INT)
1471         LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
1472       fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
1473       return;
1474
1475     case 'D':
1476       /* When emitting an sub for the high part of a DImode constant, we
1477          want to use subq for 0 and subs.w for -1.  */
1478       if (GET_CODE (operand) != CONST_INT)
1479         LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
1480       fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
1481       return;
1482
1483     case 'S':
1484       /* Print the operand as the index-part of an address.
1485          Easiest way out is to use cris_print_index.  */
1486       cris_print_index (operand, file);
1487       return;
1488
1489     case 'T':
1490       /* Print the size letter for an operand to a MULT, which must be a
1491          const_int with a suitable value.  */
1492       if (GET_CODE (operand) != CONST_INT || INTVAL (operand) > 4)
1493         LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
1494       fprintf (file, "%s", mults[INTVAL (operand)]);
1495       return;
1496
1497     case 0:
1498       /* No code, print as usual.  */
1499       break;
1500
1501     default:
1502       LOSE_AND_RETURN ("invalid operand modifier letter", x);
1503     }
1504
1505   /* Print an operand as without a modifier letter.  */
1506   switch (GET_CODE (operand))
1507     {
1508     case REG:
1509       if (REGNO (operand) > 15)
1510         internal_error ("internal error: bad register: %d", REGNO (operand));
1511       fprintf (file, "$%s", reg_names[REGNO (operand)]);
1512       return;
1513
1514     case MEM:
1515       output_address (XEXP (operand, 0));
1516       return;
1517
1518     case CONST_DOUBLE:
1519       if (GET_MODE (operand) == VOIDmode)
1520         /* A long long constant.  */
1521         output_addr_const (file, operand);
1522       else
1523         {
1524           /* Only single precision is allowed as plain operands the
1525              moment.  FIXME:  REAL_VALUE_FROM_CONST_DOUBLE isn't
1526              documented.  */
1527           REAL_VALUE_TYPE r;
1528           long l;
1529
1530           /* FIXME:  Perhaps check overflow of the "single".  */
1531           REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1532           REAL_VALUE_TO_TARGET_SINGLE (r, l);
1533
1534           fprintf (file, "0x%lx", l);
1535         }
1536       return;
1537
1538     case UNSPEC:
1539       ASSERT_PLT_UNSPEC (operand);
1540       /* Fall through.  */
1541
1542     case CONST:
1543       cris_output_addr_const (file, operand);
1544       return;
1545
1546     case MULT:
1547     case ASHIFT:
1548       {
1549         /* For a (MULT (reg X) const_int) we output "rX.S".  */
1550         int i = GET_CODE (XEXP (operand, 1)) == CONST_INT
1551           ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1552         rtx reg = GET_CODE (XEXP (operand, 1)) == CONST_INT
1553           ? XEXP (operand, 0) : XEXP (operand, 1);
1554
1555         if (GET_CODE (reg) != REG
1556             || (GET_CODE (XEXP (operand, 0)) != CONST_INT
1557                 && GET_CODE (XEXP (operand, 1)) != CONST_INT))
1558           LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1559
1560         cris_print_base (reg, file);
1561         fprintf (file, ".%c",
1562                  i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1563                  : i == 4 ? 'd'
1564                  : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1565                  : 'd');
1566         return;
1567       }
1568
1569     default:
1570       /* No need to handle all strange variants, let output_addr_const
1571          do it for us.  */
1572       if (CONSTANT_P (operand))
1573         {
1574           cris_output_addr_const (file, operand);
1575           return;
1576         }
1577
1578       LOSE_AND_RETURN ("unexpected operand", x);
1579     }
1580 }
1581
1582 /* The PRINT_OPERAND_ADDRESS worker.  */
1583
1584 void
1585 cris_print_operand_address (file, x)
1586      FILE *file;
1587      rtx x;
1588 {
1589   /* All these were inside MEM:s so output indirection characters.  */
1590   putc ('[', file);
1591
1592   if (CONSTANT_ADDRESS_P (x))
1593     cris_output_addr_const (file, x);
1594   else if (BASE_OR_AUTOINCR_P (x))
1595     cris_print_base (x, file);
1596   else if (GET_CODE (x) == PLUS)
1597     {
1598       rtx x1, x2;
1599
1600       x1 = XEXP (x, 0);
1601       x2 = XEXP (x, 1);
1602       if (BASE_P (x1))
1603         {
1604           cris_print_base (x1, file);
1605           cris_print_index (x2, file);
1606         }
1607       else if (BASE_P (x2))
1608         {
1609           cris_print_base (x2, file);
1610           cris_print_index (x1, file);
1611         }
1612       else
1613         LOSE_AND_RETURN ("unrecognized address", x);
1614     }
1615   else if (GET_CODE (x) == MEM)
1616     {
1617       /* A DIP.  Output more indirection characters.  */
1618       putc ('[', file);
1619       cris_print_base (XEXP (x, 0), file);
1620       putc (']', file);
1621     }
1622   else
1623     LOSE_AND_RETURN ("unrecognized address", x);
1624
1625   putc (']', file);
1626 }
1627
1628 /* The RETURN_ADDR_RTX worker.
1629    We mark that the return address is used, either by EH or
1630    __builtin_return_address, for use by the function prologue and
1631    epilogue.  FIXME: This isn't optimal; we just use the mark in the
1632    prologue and epilogue to say that the return address is to be stored
1633    in the stack frame.  We could return SRP for leaf-functions and use the
1634    initial-value machinery.  */
1635
1636 rtx
1637 cris_return_addr_rtx (count, frameaddr)
1638      int count;
1639      rtx frameaddr ATTRIBUTE_UNUSED;
1640 {
1641   cfun->machine->needs_return_address_on_stack = 1;
1642
1643   /* The return-address is stored just above the saved frame-pointer (if
1644      present).  Apparently we can't eliminate from the frame-pointer in
1645      that direction, so use the incoming args (maybe pretended) pointer.  */
1646   return count == 0
1647     ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1648     : NULL_RTX;
1649 }
1650
1651 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1652    handles FP -> SP elimination offset.  */
1653
1654 static int
1655 cris_initial_frame_pointer_offset ()
1656 {
1657   int regno;
1658
1659   /* Initial offset is 0 if we don't have a frame pointer.  */
1660   int offs = 0;
1661
1662   /* And 4 for each register pushed.  */
1663   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1664     if ((((regs_ever_live[regno]
1665            && !call_used_regs[regno])
1666           || (regno == (int) PIC_OFFSET_TABLE_REGNUM
1667               && (current_function_uses_pic_offset_table
1668                   /* It is saved anyway, if there would be a gap.  */
1669                   || (flag_pic
1670                       && regs_ever_live[regno + 1]
1671                       && !call_used_regs[regno + 1]))))
1672          && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1673          && regno != CRIS_SRP_REGNUM)
1674         || (current_function_calls_eh_return
1675             && (regno == EH_RETURN_DATA_REGNO (0)
1676                 || regno == EH_RETURN_DATA_REGNO (1)
1677                 || regno == EH_RETURN_DATA_REGNO (2)
1678                 || regno == EH_RETURN_DATA_REGNO (3))))
1679       offs += 4;
1680
1681   /* And then, last, we add the locals allocated.  */
1682   offs += get_frame_size ();
1683
1684   /* And more; the accumulated args size.  */
1685   offs += current_function_outgoing_args_size;
1686
1687   /* Then round it off, in case we use aligned stack.  */
1688   if (TARGET_STACK_ALIGN)
1689     offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1690
1691   return offs;
1692 }
1693
1694 /* The INITIAL_ELIMINATION_OFFSET worker.
1695    Calculate the difference between imaginary registers such as frame
1696    pointer and the stack pointer.  Used to eliminate the frame pointer
1697    and imaginary arg pointer.  */
1698
1699 int
1700 cris_initial_elimination_offset (fromreg, toreg)
1701      int fromreg;
1702      int toreg;
1703 {
1704   int fp_sp_offset
1705     = cris_initial_frame_pointer_offset ();
1706
1707   /* We should be able to use regs_ever_live and related prologue
1708      information here, or alpha should not as well.  */
1709   int return_address_on_stack
1710     = regs_ever_live[CRIS_SRP_REGNUM]
1711     || cfun->machine->needs_return_address_on_stack != 0;
1712
1713   /* Here we act as if the frame-pointer is needed.  */
1714   int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1715
1716   if (fromreg == ARG_POINTER_REGNUM
1717       && toreg == FRAME_POINTER_REGNUM)
1718     return ap_fp_offset;
1719
1720   /* Between the frame pointer and the stack are only "normal" stack
1721      variables and saved registers.  */
1722   if (fromreg == FRAME_POINTER_REGNUM
1723       && toreg == STACK_POINTER_REGNUM)
1724     return fp_sp_offset;
1725
1726   /* We need to balance out the frame pointer here.  */
1727   if (fromreg == ARG_POINTER_REGNUM
1728       && toreg == STACK_POINTER_REGNUM)
1729     return ap_fp_offset + fp_sp_offset - 4;
1730
1731   abort ();
1732 }
1733
1734 /*  This function looks into the pattern to see how this insn affects
1735     condition codes.
1736
1737     Used when to eliminate test insns before a condition-code user,
1738     such as a "scc" insn or a conditional branch.  This includes
1739     checking if the entities that cc was updated by, are changed by the
1740     operation.
1741
1742     Currently a jumble of the old peek-inside-the-insn and the newer
1743     check-cc-attribute methods.  */
1744
1745 void
1746 cris_notice_update_cc (exp, insn)
1747      rtx exp;
1748      rtx insn;
1749 {
1750   /* Check if user specified "-mcc-init" as a bug-workaround.  FIXME:
1751      TARGET_CCINIT does not work; we must set CC_REVERSED as below.
1752      Several test-cases will otherwise fail, for example
1753      gcc.c-torture/execute/20000217-1.c -O0 and -O1.  */
1754   if (TARGET_CCINIT)
1755     {
1756       CC_STATUS_INIT;
1757       return;
1758     }
1759
1760   /* Slowly, we're converting to using attributes to control the setting
1761      of condition-code status.  */
1762   switch (get_attr_cc (insn))
1763     {
1764     case CC_NONE:
1765       /* Even if it is "none", a setting may clobber a previous
1766          cc-value, so check.  */
1767       if (GET_CODE (exp) == SET)
1768         {
1769           if (cc_status.value1
1770               && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1771                                              cc_status.value1))
1772             cc_status.value1 = 0;
1773
1774           if (cc_status.value2
1775               && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1776                                              cc_status.value2))
1777             cc_status.value2 = 0;
1778         }
1779       return;
1780
1781     case CC_CLOBBER:
1782       CC_STATUS_INIT;
1783       break;
1784
1785     case CC_NORMAL:
1786       /* Which means, for:
1787          (set (cc0) (...)):
1788          CC is (...).
1789
1790          (set (reg) (...)):
1791          CC is (reg) and (...) - unless (...) is 0, then CC does not change.
1792          CC_NO_OVERFLOW unless (...) is reg or mem.
1793
1794          (set (mem) (...)):
1795          CC does not change.
1796
1797          (set (pc) (...)):
1798          CC does not change.
1799
1800          (parallel
1801           (set (reg1) (mem (bdap/biap)))
1802           (set (reg2) (bdap/biap))):
1803          CC is (reg1) and (mem (reg2))
1804
1805          (parallel
1806           (set (mem (bdap/biap)) (reg1)) [or 0]
1807           (set (reg2) (bdap/biap))):
1808          CC does not change.
1809
1810          (where reg and mem includes strict_low_parts variants thereof)
1811
1812          For all others, assume CC is clobbered.
1813          Note that we do not have to care about setting CC_NO_OVERFLOW,
1814          since the overflow flag is set to 0 (i.e. right) for
1815          instructions where it does not have any sane sense, but where
1816          other flags have meanings.  (This includes shifts; the carry is
1817          not set by them).
1818
1819          Note that there are other parallel constructs we could match,
1820          but we don't do that yet.  */
1821
1822       if (GET_CODE (exp) == SET)
1823         {
1824           /* FIXME: Check when this happens.  It looks like we should
1825              actually do a CC_STATUS_INIT here to be safe.  */
1826           if (SET_DEST (exp) == pc_rtx)
1827             return;
1828
1829           /* Record CC0 changes, so we do not have to output multiple
1830              test insns.  */
1831           if (SET_DEST (exp) == cc0_rtx)
1832             {
1833               cc_status.value1 = SET_SRC (exp);
1834               cc_status.value2 = 0;
1835
1836               /* Handle flags for the special btstq on one bit.  */
1837               if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1838                   && XEXP (SET_SRC (exp), 1) == const1_rtx)
1839                 {
1840                   if (GET_CODE (XEXP (SET_SRC (exp), 0)) == CONST_INT)
1841                     /* Using cmpq.  */
1842                     cc_status.flags = CC_INVERTED;
1843                   else
1844                     /* A one-bit btstq.  */
1845                     cc_status.flags = CC_Z_IN_NOT_N;
1846                 }
1847               else
1848                 cc_status.flags = 0;
1849
1850               if (GET_CODE (SET_SRC (exp)) == COMPARE)
1851                 {
1852                   if (!REG_P (XEXP (SET_SRC (exp), 0))
1853                       && XEXP (SET_SRC (exp), 1) != const0_rtx)
1854                     /* For some reason gcc will not canonicalize compare
1855                        operations, reversing the sign by itself if
1856                        operands are in wrong order.  */
1857                     /* (But NOT inverted; eq is still eq.) */
1858                     cc_status.flags = CC_REVERSED;
1859
1860                   /* This seems to be overlooked by gcc.  FIXME: Check again.
1861                      FIXME:  Is it really safe?  */
1862                   cc_status.value2
1863                     = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1864                                      XEXP (SET_SRC (exp), 0),
1865                                      XEXP (SET_SRC (exp), 1));
1866                 }
1867               return;
1868             }
1869           else if (REG_P (SET_DEST (exp))
1870                    || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1871                        && REG_P (XEXP (SET_DEST (exp), 0))))
1872             {
1873               /* A register is set; normally CC is set to show that no
1874                  test insn is needed.  Catch the exceptions.  */
1875
1876               /* If not to cc0, then no "set"s in non-natural mode give
1877                  ok cc0...  */
1878               if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1879                   || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1880                 {
1881                   /* ... except add:s and sub:s in DImode.  */
1882                   if (GET_MODE (SET_DEST (exp)) == DImode
1883                       && (GET_CODE (SET_SRC (exp)) == PLUS
1884                           || GET_CODE (SET_SRC (exp)) == MINUS))
1885                     {
1886                       cc_status.flags = 0;
1887                       cc_status.value1 = SET_DEST (exp);
1888                       cc_status.value2 = SET_SRC (exp);
1889
1890                       if (cris_reg_overlap_mentioned_p (cc_status.value1,
1891                                                         cc_status.value2))
1892                         cc_status.value2 = 0;
1893
1894                       /* Add and sub may set V, which gets us
1895                          unoptimizable results in "gt" and "le" condition
1896                          codes.  */
1897                       cc_status.flags |= CC_NO_OVERFLOW;
1898
1899                       return;
1900                     }
1901                 }
1902               else if (SET_SRC (exp) == const0_rtx)
1903                 {
1904                   /* There's no CC0 change when clearing a register or
1905                      memory.  Just check for overlap.  */
1906                   if ((cc_status.value1
1907                        && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1908                                                         cc_status.value1)))
1909                     cc_status.value1 = 0;
1910
1911                   if ((cc_status.value2
1912                        && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1913                                                         cc_status.value2)))
1914                     cc_status.value2 = 0;
1915
1916                   return;
1917                 }
1918               else
1919                 {
1920                   cc_status.flags = 0;
1921                   cc_status.value1 = SET_DEST (exp);
1922                   cc_status.value2 = SET_SRC (exp);
1923
1924                   if (cris_reg_overlap_mentioned_p (cc_status.value1,
1925                                                     cc_status.value2))
1926                     cc_status.value2 = 0;
1927
1928                   /* Some operations may set V, which gets us
1929                      unoptimizable results in "gt" and "le" condition
1930                      codes.  */
1931                   if (GET_CODE (SET_SRC (exp)) == PLUS
1932                       || GET_CODE (SET_SRC (exp)) == MINUS
1933                       || GET_CODE (SET_SRC (exp)) == NEG)
1934                     cc_status.flags |= CC_NO_OVERFLOW;
1935
1936                   return;
1937                 }
1938             }
1939           else if (GET_CODE (SET_DEST (exp)) == MEM
1940                    || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1941                        && GET_CODE (XEXP (SET_DEST (exp), 0)) == MEM))
1942             {
1943               /* When SET to MEM, then CC is not changed (except for
1944                  overlap).  */
1945               if ((cc_status.value1
1946                    && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1947                                                     cc_status.value1)))
1948                 cc_status.value1 = 0;
1949
1950               if ((cc_status.value2
1951                    && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1952                                                     cc_status.value2)))
1953                 cc_status.value2 = 0;
1954
1955               return;
1956             }
1957         }
1958       else if (GET_CODE (exp) == PARALLEL)
1959         {
1960           if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1961               && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1962               && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1963             {
1964               if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1965                   && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 1)) == MEM)
1966                 {
1967                   /* For "move.S [rx=ry+o],rz", say CC reflects
1968                      value1=rz and value2=[rx] */
1969                   cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1970                   cc_status.value2
1971                     = gen_rtx_MEM (GET_MODE (XEXP (XVECEXP (exp, 0, 0), 0)),
1972                                    XEXP (XVECEXP (exp, 0, 1), 0));
1973                   cc_status.flags = 0;
1974
1975                   /* Huh?  A side-effect cannot change the destination
1976                      register.  */
1977                   if (cris_reg_overlap_mentioned_p (cc_status.value1,
1978                                                     cc_status.value2))
1979                     internal_error ("internal error: sideeffect-insn affecting main effect");
1980                   return;
1981                 }
1982               else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1983                         || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1984                        && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 0)) == MEM)
1985                 {
1986                   /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1987                      say flags are not changed, except for overlap.  */
1988                   if (cc_status.value1
1989                       && cris_reg_overlap_mentioned_p (XEXP
1990                                                        (XVECEXP
1991                                                         (exp, 0, 0), 0),
1992                                                        cc_status.value1))
1993                     cc_status.value1 = 0;
1994
1995                   if (cc_status.value1
1996                       && cris_reg_overlap_mentioned_p (XEXP
1997                                                        (XVECEXP
1998                                                         (exp, 0, 1), 0),
1999                                                        cc_status.value1))
2000                     cc_status.value1 = 0;
2001
2002                   if (cc_status.value2
2003                       && cris_reg_overlap_mentioned_p (XEXP
2004                                                        (XVECEXP
2005                                                         (exp, 0, 0), 0),
2006                                                        cc_status.value2))
2007                     cc_status.value2 = 0;
2008
2009                   if (cc_status.value2
2010                       && cris_reg_overlap_mentioned_p (XEXP
2011                                                        (XVECEXP
2012                                                         (exp, 0, 1), 0),
2013                                                        cc_status.value2))
2014                     cc_status.value2 = 0;
2015
2016                   return;
2017                 }
2018             }
2019         }
2020       break;
2021
2022     default:
2023       /* Unknown cc_attr value.  */
2024       abort ();
2025     }
2026
2027   CC_STATUS_INIT;
2028 }
2029
2030 /* Return != 0 if the return sequence for the current function is short,
2031    like "ret" or "jump [sp+]".  Prior to reloading, we can't tell how
2032    many registers must be saved, so return 0 then.  */
2033
2034 int
2035 cris_simple_epilogue ()
2036 {
2037   int regno;
2038   int reglimit = STACK_POINTER_REGNUM;
2039   int lastreg = -1;
2040
2041   if (! reload_completed
2042       || frame_pointer_needed
2043       || get_frame_size () != 0
2044       || current_function_pretend_args_size
2045       || current_function_args_size
2046       || current_function_outgoing_args_size
2047       || current_function_calls_eh_return
2048
2049       /* If we're not supposed to emit prologue and epilogue, we must
2050          not emit return-type instructions.  */
2051       || !TARGET_PROLOGUE_EPILOGUE)
2052     return 0;
2053
2054   /* We allow a "movem [sp+],rN" to sit in front if the "jump [sp+]" or
2055      in the delay-slot of the "ret".  */
2056   for (regno = 0; regno < reglimit; regno++)
2057     if ((regs_ever_live[regno] && ! call_used_regs[regno])
2058         || (regno == (int) PIC_OFFSET_TABLE_REGNUM
2059             && (current_function_uses_pic_offset_table
2060                 /* It is saved anyway, if there would be a gap.  */
2061                 || (flag_pic
2062                     && regs_ever_live[regno + 1]
2063                     && !call_used_regs[regno + 1]))))
2064       {
2065         if (lastreg != regno - 1)
2066           return 0;
2067         lastreg = regno;
2068       }
2069
2070   return 1;
2071 }
2072
2073 /* The ADDRESS_COST worker.  */
2074
2075 int
2076 cris_address_cost (x)
2077      rtx x;
2078 {
2079   /* The metric to use for the cost-macros is unclear.
2080      The metric used here is (the number of cycles needed) / 2,
2081      where we consider equal a cycle for a word of code and a cycle to
2082      read memory.  */
2083
2084   /* The cheapest addressing modes get 0, since nothing extra is needed.  */
2085   if (BASE_OR_AUTOINCR_P (x))
2086     return 0;
2087
2088   /* An indirect mem must be a DIP.  This means two bytes extra for code,
2089      and 4 bytes extra for memory read, i.e.  (2 + 4) / 2.  */
2090   if (GET_CODE (x) == MEM)
2091     return (2 + 4) / 2;
2092
2093   /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
2094      an extra DIP prefix and 4 bytes of constant in most cases.
2095      For PIC and a symbol with a GOT entry, we double the cost since we
2096      add a [rPIC+...] offset.  A GOT-less symbol uses a BDAP prefix
2097      equivalent to the DIP prefix for non-PIC, hence the same cost.  */
2098   if (CONSTANT_P (x))
2099     return flag_pic && cris_got_symbol (x) ? 2 * (2 + 4) / 2 : (2 + 4) / 2;
2100
2101   /* Handle BIAP and BDAP prefixes.  */
2102   if (GET_CODE (x) == PLUS)
2103     {
2104       rtx tem1 = XEXP (x, 0);
2105       rtx tem2 = XEXP (x, 1);
2106
2107     /* A BIAP is 2 extra bytes for the prefix insn, nothing more.  We
2108        recognize the typical MULT which is always in tem1 because of
2109        insn canonicalization.  */
2110     if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
2111         || REG_P (tem1))
2112       return 2 / 2;
2113
2114     /* A BDAP (quick) is 2 extra bytes.  Any constant operand to the
2115        PLUS is always found in tem2.  */
2116     if (GET_CODE (tem2) == CONST_INT
2117         && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
2118       return 2 / 2;
2119
2120     /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
2121        bytes.  */
2122     if (GET_CODE (tem2) == CONST_INT
2123         && CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
2124       return (2 + 2) / 2;
2125
2126     /* A BDAP with some other constant is 2 bytes extra.  */
2127     if (CONSTANT_P (tem2))
2128       return (2 + 2 + 2) / 2;
2129
2130     /* BDAP with something indirect should have a higher cost than
2131        BIAP with register.   FIXME: Should it cost like a MEM or more?  */
2132     /* Don't need to check it, it's the only one left.
2133        FIXME:  There was a REG test missing, perhaps there are others.
2134        Think more.  */
2135     return (2 + 2 + 2) / 2;
2136   }
2137
2138   /* What else?  Return a high cost.  It matters only for valid
2139      addressing modes.  */
2140   return 10;
2141 }
2142
2143 /* Check various objections to the side-effect.  Used in the test-part
2144    of an anonymous insn describing an insn with a possible side-effect.
2145    Returns nonzero if the implied side-effect is ok.
2146
2147    code     : PLUS or MULT
2148    ops      : An array of rtx:es. lreg, rreg, rval,
2149               The variables multop and other_op are indexes into this,
2150               or -1 if they are not applicable.
2151    lreg     : The register that gets assigned in the side-effect.
2152    rreg     : One register in the side-effect expression
2153    rval     : The other register, or an int.
2154    multop   : An integer to multiply rval with.
2155    other_op : One of the entities of the main effect,
2156               whose mode we must consider.  */
2157
2158 int
2159 cris_side_effect_mode_ok (code, ops, lreg, rreg, rval, multop, other_op)
2160      enum rtx_code code;
2161      rtx *ops;
2162      int lreg, rreg, rval, multop, other_op;
2163 {
2164   /* Find what value to multiply with, for rx =ry + rz * n.  */
2165   int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
2166
2167   rtx reg_rtx = ops[rreg];
2168   rtx val_rtx = ops[rval];
2169
2170   /* The operands may be swapped.  Canonicalize them in reg_rtx and
2171      val_rtx, where reg_rtx always is a reg (for this constraint to
2172      match).  */
2173   if (! BASE_P (reg_rtx))
2174     reg_rtx = val_rtx, val_rtx = ops[rreg];
2175
2176   /* Don't forget to check that reg_rtx really is a reg.  If it isn't,
2177      we have no business.  */
2178   if (! BASE_P (reg_rtx))
2179     return 0;
2180
2181   /* Don't do this when -mno-split.  */
2182   if (!TARGET_SIDE_EFFECT_PREFIXES)
2183     return 0;
2184
2185   /* The mult expression may be hidden in lreg.  FIXME:  Add more
2186      commentary about that.  */
2187   if (GET_CODE (val_rtx) == MULT)
2188     {
2189       mult = INTVAL (XEXP (val_rtx, 1));
2190       val_rtx = XEXP (val_rtx, 0);
2191       code = MULT;
2192     }
2193
2194   /* First check the "other operand".  */
2195   if (other_op >= 0)
2196     {
2197       if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2198         return 0;
2199
2200       /* Check if the lvalue register is the same as the "other
2201          operand".  If so, the result is undefined and we shouldn't do
2202          this.  FIXME:  Check again.  */
2203       if ((BASE_P (ops[lreg])
2204            && BASE_P (ops[other_op])
2205            && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2206           || rtx_equal_p (ops[other_op], ops[lreg]))
2207       return 0;
2208     }
2209
2210   /* Do not accept frame_pointer_rtx as any operand.  */
2211   if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2212       || ops[rval] == frame_pointer_rtx
2213       || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2214     return 0;
2215
2216   if (code == PLUS
2217       && ! BASE_P (val_rtx))
2218     {
2219
2220       /* Do not allow rx = rx + n if a normal add or sub with same size
2221          would do.  */
2222       if (rtx_equal_p (ops[lreg], reg_rtx)
2223           && GET_CODE (val_rtx) == CONST_INT
2224           && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2225         return 0;
2226
2227       /* Check allowed cases, like [r(+)?].[bwd] and const.
2228          A symbol is not allowed with PIC.  */
2229       if (CONSTANT_P (val_rtx))
2230         return flag_pic == 0 || cris_symbol (val_rtx) == 0;
2231
2232       if (GET_CODE (val_rtx) == MEM
2233           && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2234         return 1;
2235
2236       if (GET_CODE (val_rtx) == SIGN_EXTEND
2237           && GET_CODE (XEXP (val_rtx, 0)) == MEM
2238           && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2239         return 1;
2240
2241       /* If we got here, it's not a valid addressing mode.  */
2242       return 0;
2243     }
2244   else if (code == MULT
2245            || (code == PLUS && BASE_P (val_rtx)))
2246     {
2247       /* Do not allow rx = rx + ry.S, since it doesn't give better code.  */
2248       if (rtx_equal_p (ops[lreg], reg_rtx)
2249           || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2250         return 0;
2251
2252       /* Do not allow bad multiply-values.  */
2253       if (mult != 1 && mult != 2 && mult != 4)
2254         return 0;
2255
2256       /* Only allow  r + ...  */
2257       if (! BASE_P (reg_rtx))
2258         return 0;
2259
2260       /* If we got here, all seems ok.
2261          (All checks need to be done above).  */
2262       return 1;
2263     }
2264
2265   /* If we get here, the caller got its initial tests wrong.  */
2266   internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2267 }
2268
2269 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2270    does not handle the case where the IN operand is strict_low_part; it
2271    does handle it for X.  Test-case in Axis-20010516.  This function takes
2272    care of that for THIS port.  FIXME: strict_low_part is going away
2273    anyway.  */
2274
2275 static int
2276 cris_reg_overlap_mentioned_p (x, in)
2277      rtx x, in;
2278 {
2279   /* The function reg_overlap_mentioned now handles when X is
2280      strict_low_part, but not when IN is a STRICT_LOW_PART.  */
2281   if (GET_CODE (in) == STRICT_LOW_PART)
2282     in = XEXP (in, 0);
2283
2284   return reg_overlap_mentioned_p (x, in);
2285 }
2286
2287 /* The TARGET_ASM_NAMED_SECTION worker.
2288    We just dispatch to the functions for ELF and a.out.  */
2289
2290 void
2291 cris_target_asm_named_section (name, flags)
2292      const char *name;
2293      unsigned int flags;
2294 {
2295   if (! TARGET_ELF)
2296     default_no_named_section (name, flags);
2297   else
2298     default_elf_asm_named_section (name, flags);
2299 }
2300
2301 /* The LEGITIMATE_PIC_OPERAND_P worker.  */
2302
2303 int
2304 cris_legitimate_pic_operand (x)
2305      rtx x;
2306 {
2307   /* The PIC representation of a symbol with a GOT entry will be (for
2308      example; relocations differ):
2309       sym => [rPIC+sym:GOT]
2310      and for a GOT-less symbol it will be (for example, relocation differ):
2311       sym => rPIC+sym:GOTOFF
2312      so only a symbol with a GOT is by itself a valid operand, and it
2313      can't be a sum of a symbol and an offset.  */
2314   return ! cris_symbol (x) || cris_got_symbol (x);
2315 }
2316
2317 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2318    CONSTANT_P.  */
2319
2320 int
2321 cris_symbol (x)
2322      rtx x;
2323 {
2324   switch (GET_CODE (x))
2325     {
2326     case SYMBOL_REF:
2327     case LABEL_REF:
2328       return 1;
2329
2330     case UNSPEC:
2331       /* A PLT reference.  */
2332       ASSERT_PLT_UNSPEC (x);
2333       return 1;
2334
2335     case CONST:
2336       return cris_symbol (XEXP (x, 0));
2337
2338     case PLUS:
2339     case MINUS:
2340       return cris_symbol (XEXP (x, 0)) || cris_symbol (XEXP (x, 1));
2341
2342     case CONST_INT:
2343     case CONST_DOUBLE:
2344     case CONSTANT_P_RTX:
2345       return 0;
2346
2347     default:
2348       fatal_insn ("unrecognized supposed constant", x);
2349     }
2350
2351   return 1;
2352 }
2353
2354 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2355    CONSTANT_P, and the symbol does not need a GOT entry.  Also set
2356    current_function_uses_pic_offset_table if we're generating PIC and ever
2357    see something that would need one.  */
2358
2359 int
2360 cris_gotless_symbol (x)
2361      rtx x;
2362 {
2363   switch (GET_CODE (x))
2364     {
2365     case UNSPEC:
2366       ASSERT_PLT_UNSPEC (x);
2367       return 1;
2368
2369     case SYMBOL_REF:
2370       if (flag_pic && cfun != NULL)
2371         current_function_uses_pic_offset_table = 1;
2372       return SYMBOL_REF_FLAG (x);
2373
2374     case LABEL_REF:
2375       /* We don't set current_function_uses_pic_offset_table for
2376          LABEL_REF:s in here, since they are almost always originating
2377          from some branch.  The only time it does not come from a label is
2378          when GCC does something like __builtin_setjmp.  Then we get the
2379          LABEL_REF from the movsi expander, so we mark it there as a
2380          special case.  */
2381       return 1;
2382
2383     case CONST:
2384       return cris_gotless_symbol (XEXP (x, 0));
2385
2386     case PLUS:
2387     case MINUS:
2388       {
2389         int x0 = cris_gotless_symbol (XEXP (x, 0)) != 0;
2390         int x1 = cris_gotless_symbol (XEXP (x, 1)) != 0;
2391
2392         /* One and only one of them must be a local symbol.  Neither must
2393            be some other, more general kind of symbol.  */
2394         return
2395           (x0 ^ x1)
2396           && ! (x0 == 0 && cris_symbol (XEXP (x, 0)))
2397           && ! (x1 == 0 && cris_symbol (XEXP (x, 1)));
2398       }
2399
2400     case CONST_INT:
2401     case CONST_DOUBLE:
2402     case CONSTANT_P_RTX:
2403       return 0;
2404
2405     default:
2406       fatal_insn ("unrecognized supposed constant", x);
2407     }
2408
2409   return 1;
2410 }
2411
2412 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2413    CONSTANT_P, and the symbol needs a GOT entry.  */
2414
2415 int
2416 cris_got_symbol (x)
2417      rtx x;
2418 {
2419   switch (GET_CODE (x))
2420     {
2421     case UNSPEC:
2422       ASSERT_PLT_UNSPEC (x);
2423       return 0;
2424
2425     case SYMBOL_REF:
2426       if (flag_pic && cfun != NULL)
2427         current_function_uses_pic_offset_table = 1;
2428       return ! SYMBOL_REF_FLAG (x);
2429
2430     case CONST:
2431       return cris_got_symbol (XEXP (x, 0));
2432
2433     case LABEL_REF:
2434       /* A LABEL_REF is never visible as a symbol outside the local
2435          function.  */
2436     case PLUS:
2437     case MINUS:
2438       /* Nope, can't access the GOT for "symbol + offset".  */
2439       return 0;
2440
2441     case CONST_INT:
2442     case CONST_DOUBLE:
2443     case CONSTANT_P_RTX:
2444       return 0;
2445
2446     default:
2447       fatal_insn ("unrecognized supposed constant in cris_global_pic_symbol",
2448                   x);
2449     }
2450
2451   return 1;
2452 }
2453
2454 /* The OVERRIDE_OPTIONS worker.
2455    As is the norm, this also parses -mfoo=bar type parameters.  */
2456
2457 void
2458 cris_override_options ()
2459 {
2460   if (cris_max_stackframe_str)
2461     {
2462       cris_max_stackframe = atoi (cris_max_stackframe_str);
2463
2464       /* Do some sanity checking.  */
2465       if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2466         internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2467                         cris_max_stackframe, 0x20000000);
2468     }
2469
2470   /* Let "-metrax4" and "-metrax100" change the cpu version.  */
2471   if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2472     cris_cpu_version = CRIS_CPU_SVINTO;
2473   else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2474     cris_cpu_version = CRIS_CPU_ETRAX4;
2475
2476   /* Parse -march=... and its synonym, the deprecated -mcpu=...  */
2477   if (cris_cpu_str)
2478     {
2479       cris_cpu_version
2480         = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2481
2482       if (strcmp ("etrax4", cris_cpu_str) == 0)
2483         cris_cpu_version = 3;
2484
2485       if (strcmp ("svinto", cris_cpu_str) == 0
2486           || strcmp ("etrax100", cris_cpu_str) == 0)
2487         cris_cpu_version = 8;
2488
2489       if (strcmp ("ng", cris_cpu_str) == 0
2490           || strcmp ("etrax100lx", cris_cpu_str) == 0)
2491         cris_cpu_version = 10;
2492
2493       if (cris_cpu_version < 0 || cris_cpu_version > 10)
2494         error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2495                cris_cpu_str);
2496
2497       /* Set the target flags.  */
2498       if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2499         target_flags |= TARGET_MASK_ETRAX4_ADD;
2500
2501       /* If this is Svinto or higher, align for 32 bit accesses.  */
2502       if (cris_cpu_version >= CRIS_CPU_SVINTO)
2503         target_flags
2504           |= (TARGET_MASK_SVINTO | TARGET_MASK_ALIGN_BY_32
2505               | TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2506               | TARGET_MASK_DATA_ALIGN);
2507
2508       /* Note that we do not add new flags when it can be completely
2509          described with a macro that uses -mcpu=X.  So
2510          TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG).  */
2511     }
2512
2513   if (cris_tune_str)
2514     {
2515       int cris_tune
2516         = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2517
2518       if (strcmp ("etrax4", cris_tune_str) == 0)
2519         cris_tune = 3;
2520
2521       if (strcmp ("svinto", cris_tune_str) == 0
2522           || strcmp ("etrax100", cris_tune_str) == 0)
2523         cris_tune = 8;
2524
2525       if (strcmp ("ng", cris_tune_str) == 0
2526           || strcmp ("etrax100lx", cris_tune_str) == 0)
2527         cris_tune = 10;
2528
2529       if (cris_tune < 0 || cris_tune > 10)
2530         error ("unknown CRIS cpu version specification in -mtune= : %s",
2531                cris_tune_str);
2532
2533       if (cris_tune >= CRIS_CPU_SVINTO)
2534         /* We have currently nothing more to tune than alignment for
2535            memory accesses.  */
2536         target_flags
2537           |= (TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2538               | TARGET_MASK_DATA_ALIGN | TARGET_MASK_ALIGN_BY_32);
2539     }
2540
2541   if (flag_pic)
2542     {
2543       /* Use error rather than warning, so invalid use is easily
2544          detectable.  Still change to the values we expect, to avoid
2545          further errors.  */
2546       if (! TARGET_LINUX)
2547         {
2548           error ("-fPIC and -fpic are not supported in this configuration");
2549           flag_pic = 0;
2550         }
2551
2552       /* Turn off function CSE.  We need to have the addresses reach the
2553          call expanders to get PLT-marked, as they could otherwise be
2554          compared against zero directly or indirectly.  After visiting the
2555          call expanders they will then be cse:ed, as the call expanders
2556          force_reg the addresses, effectively forcing flag_no_function_cse
2557          to 0.  */
2558       flag_no_function_cse = 1;
2559     }
2560
2561   if ((write_symbols == DWARF_DEBUG
2562        || write_symbols == DWARF2_DEBUG) && ! TARGET_ELF)
2563     {
2564       warning ("that particular -g option is invalid with -maout and -melinux");
2565       write_symbols = DBX_DEBUG;
2566     }
2567
2568   /* Set the per-function-data initializer.  */
2569   init_machine_status = cris_init_machine_status;
2570 }
2571
2572 /* The ASM_OUTPUT_MI_THUNK worker.  */
2573
2574 void
2575 cris_asm_output_mi_thunk (stream, thunkdecl, delta, funcdecl)
2576      FILE *stream;
2577      tree thunkdecl ATTRIBUTE_UNUSED;
2578      int delta;
2579      tree funcdecl;
2580 {
2581   if (delta > 0)
2582     asm_fprintf (stream, "\tadd%s %d,$%s\n",
2583                  ADDITIVE_SIZE_MODIFIER (delta), delta,
2584                  reg_names[CRIS_FIRST_ARG_REG]);
2585   else if (delta < 0)
2586     asm_fprintf (stream, "\tsub%s %d,$%s\n",
2587                  ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2588                  reg_names[CRIS_FIRST_ARG_REG]);
2589
2590   if (flag_pic)
2591     {
2592       const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2593
2594       name = (* targetm.strip_name_encoding) (name);
2595       fprintf (stream, "add.d ");
2596       assemble_name (stream, name);
2597       fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2598     }
2599   else
2600     {
2601       fprintf (stream, "jump ");
2602       assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2603       fprintf (stream, "\n");
2604     }
2605 }
2606
2607 /* The EXPAND_BUILTIN_VA_ARG worker.  This is modified from the
2608    "standard" implementation of va_arg: read the value from the current
2609    address and increment by the size of one or two registers.  The
2610    important difference for CRIS is that if the type is
2611    pass-by-reference, then perform an indirection.  */
2612
2613 rtx
2614 cris_expand_builtin_va_arg (valist, type)
2615      tree valist;
2616      tree type;
2617 {
2618   tree addr_tree, t;
2619   rtx addr;
2620   tree passed_size = size_zero_node;
2621   tree type_size = NULL;
2622   tree size3 = size_int (3);
2623   tree size4 = size_int (4);
2624   tree size8 = size_int (8);
2625   tree rounded_size;
2626
2627   /* Get AP.  */
2628   addr_tree = valist;
2629
2630   if (type == error_mark_node
2631       || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
2632       || TREE_OVERFLOW (type_size))
2633     /* Presumably an error; the size isn't computable.  A message has
2634        supposedly been emitted elsewhere.  */
2635     rounded_size = size_zero_node;
2636   else
2637     rounded_size
2638       = fold (build (MULT_EXPR, sizetype,
2639                      fold (build (TRUNC_DIV_EXPR, sizetype,
2640                                   fold (build (PLUS_EXPR, sizetype,
2641                                                type_size, size3)),
2642                                   size4)),
2643                      size4));
2644
2645   if (!integer_zerop (rounded_size))
2646     {
2647       /* Check if the type is passed by value or by reference.  Values up
2648          to 8 bytes are passed by-value, padded to register-size (4
2649          bytes).  Larger values and varying-size types are passed
2650          by reference.  */
2651       passed_size
2652         = (!really_constant_p (type_size)
2653            ? size4
2654            : fold (build (COND_EXPR, sizetype,
2655                           fold (build (GT_EXPR, sizetype,
2656                                        rounded_size,
2657                                        size8)),
2658                           size4,
2659                           rounded_size)));
2660
2661       addr_tree
2662         = (!really_constant_p (type_size)
2663            ? build1 (INDIRECT_REF, build_pointer_type (type), addr_tree)
2664            : fold (build (COND_EXPR, TREE_TYPE (addr_tree),
2665                           fold (build (GT_EXPR, sizetype,
2666                                        rounded_size,
2667                                        size8)),
2668                           build1 (INDIRECT_REF, build_pointer_type (type),
2669                                   addr_tree),
2670                           addr_tree)));
2671     }
2672
2673   addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2674   addr = copy_to_reg (addr);
2675
2676   if (!integer_zerop (rounded_size))
2677     {
2678       /* Compute new value for AP.  */
2679       t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2680                  build (PLUS_EXPR, TREE_TYPE (valist), valist,
2681                         passed_size));
2682       TREE_SIDE_EFFECTS (t) = 1;
2683       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2684     }
2685
2686   return addr;
2687 }
2688
2689 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2690    mark functions.  */
2691
2692 void
2693 cris_init_expanders ()
2694 {
2695   /* Nothing here at the moment.  */
2696 }
2697
2698 /* Zero initialization is OK for all current fields.  */
2699
2700 static void
2701 cris_init_machine_status (p)
2702      struct function *p;
2703 {
2704   p->machine = xcalloc (1, sizeof (struct machine_function));
2705 }
2706
2707 /* Split a 2 word move (DI or presumably DF) into component parts.
2708    Originally a copy of gen_split_move_double in m32r.c.  */
2709
2710 rtx
2711 cris_split_movdx (operands)
2712      rtx *operands;
2713 {
2714   enum machine_mode mode = GET_MODE (operands[0]);
2715   rtx dest = operands[0];
2716   rtx src  = operands[1];
2717   rtx val;
2718
2719   /* We used to have to handle (SUBREG (MEM)) here, but that should no
2720      longer happen; after reload there are no SUBREGs any more, and we're
2721      only called after reload.  */
2722   if (GET_CODE (dest) == SUBREG || GET_CODE (src) == SUBREG)
2723     abort ();
2724
2725   start_sequence ();
2726   if (GET_CODE (dest) == REG)
2727     {
2728       int dregno = REGNO (dest);
2729
2730       /* Reg-to-reg copy.  */
2731       if (GET_CODE (src) == REG)
2732         {
2733           int sregno = REGNO (src);
2734
2735           int reverse = (dregno == sregno + 1);
2736
2737           /* We normally copy the low-numbered register first.  However, if
2738              the first register operand 0 is the same as the second register of
2739              operand 1, we must copy in the opposite order.  */
2740           emit_insn (gen_rtx_SET (VOIDmode,
2741                                   operand_subword (dest, reverse, TRUE, mode),
2742                                   operand_subword (src, reverse, TRUE, mode)));
2743
2744           emit_insn (gen_rtx_SET (VOIDmode,
2745                                   operand_subword (dest, !reverse, TRUE, mode),
2746                                   operand_subword (src, !reverse, TRUE, mode)));
2747         }
2748       /* Constant-to-reg copy.  */
2749       else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
2750         {
2751           rtx words[2];
2752           split_double (src, &words[0], &words[1]);
2753           emit_insn (gen_rtx_SET (VOIDmode,
2754                                   operand_subword (dest, 0, TRUE, mode),
2755                                   words[0]));
2756
2757           emit_insn (gen_rtx_SET (VOIDmode,
2758                                   operand_subword (dest, 1, TRUE, mode),
2759                                   words[1]));
2760         }
2761       /* Mem-to-reg copy.  */
2762       else if (GET_CODE (src) == MEM)
2763         {
2764           /* If the high-address word is used in the address, we must load it
2765              last.  Otherwise, load it first.  */
2766           rtx addr = XEXP (src, 0);
2767           int reverse
2768             = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2769
2770           /* The original code imples that we can't do
2771              move.x [rN+],rM  move.x [rN],rM+1
2772              when rN is dead, because of REG_NOTES damage.  That is
2773              consistent with what I've seen, so don't try it.
2774
2775              We have two different cases here; if the addr is POST_INC,
2776              just pass it through, otherwise add constants.  */
2777
2778           if (GET_CODE (addr) == POST_INC)
2779             {
2780               emit_insn (gen_rtx_SET (VOIDmode,
2781                                       operand_subword (dest, 0, TRUE, mode),
2782                                       change_address (src, SImode, addr)));
2783               emit_insn (gen_rtx_SET (VOIDmode,
2784                                       operand_subword (dest, 1, TRUE, mode),
2785                                       change_address (src, SImode, addr)));
2786             }
2787           else
2788             {
2789               /* Make sure we don't get any other addresses with
2790                  embedded postincrements.  They should be stopped in
2791                  GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2792                  safety.  */
2793               if (side_effects_p (addr))
2794                 fatal_insn ("unexpected side-effects in address", addr);
2795
2796               emit_insn (gen_rtx_SET
2797                          (VOIDmode,
2798                           operand_subword (dest, reverse, TRUE, mode),
2799                           change_address
2800                           (src, SImode,
2801                            plus_constant (addr,
2802                                           reverse * UNITS_PER_WORD))));
2803               emit_insn (gen_rtx_SET
2804                          (VOIDmode,
2805                           operand_subword (dest, ! reverse, TRUE, mode),
2806                           change_address
2807                           (src, SImode,
2808                            plus_constant (addr,
2809                                           (! reverse) *
2810                                           UNITS_PER_WORD))));
2811             }
2812         }
2813       else
2814         abort ();
2815     }
2816   /* Reg-to-mem copy or clear mem.  */
2817   else if (GET_CODE (dest) == MEM
2818            && (GET_CODE (src) == REG
2819                || src == const0_rtx
2820                || src == CONST0_RTX (DFmode)))
2821     {
2822       rtx addr = XEXP (dest, 0);
2823
2824       if (GET_CODE (addr) == POST_INC)
2825         {
2826           emit_insn (gen_rtx_SET (VOIDmode,
2827                                   change_address (dest, SImode, addr),
2828                                   operand_subword (src, 0, TRUE, mode)));
2829           emit_insn (gen_rtx_SET (VOIDmode,
2830                                   change_address (dest, SImode, addr),
2831                                   operand_subword (src, 1, TRUE, mode)));
2832         }
2833       else
2834         {
2835           /* Make sure we don't get any other addresses with embedded
2836              postincrements.  They should be stopped in
2837              GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety.  */
2838           if (side_effects_p (addr))
2839             fatal_insn ("unexpected side-effects in address", addr);
2840
2841           emit_insn (gen_rtx_SET
2842                      (VOIDmode,
2843                       change_address (dest, SImode, addr),
2844                       operand_subword (src, 0, TRUE, mode)));
2845
2846           emit_insn (gen_rtx_SET
2847                      (VOIDmode,
2848                       change_address (dest, SImode,
2849                                       plus_constant (addr,
2850                                                      UNITS_PER_WORD)),
2851                       operand_subword (src, 1, TRUE, mode)));
2852         }
2853     }
2854
2855   else
2856     abort ();
2857
2858   val = gen_sequence ();
2859   end_sequence ();
2860   return val;
2861 }
2862
2863 /* This is in essence a copy of output_addr_const altered to output
2864    symbolic operands as PIC.
2865
2866    FIXME: Add hooks similar to ASM_OUTPUT_SYMBOL_REF to get this effect in
2867    the "real" output_addr_const.  All we need is one for LABEL_REF (and
2868    one for CODE_LABEL?).  */
2869
2870 void
2871 cris_output_addr_const (file, x)
2872      FILE *file;
2873      rtx x;
2874 {
2875   int is_plt = 0;
2876
2877 restart:
2878   switch (GET_CODE (x))
2879     {
2880     case UNSPEC:
2881       ASSERT_PLT_UNSPEC (x);
2882       x = XVECEXP (x, 0, 0);
2883       is_plt = 1;
2884
2885       /* Fall through.  */
2886     case SYMBOL_REF:
2887       if (flag_pic)
2888         {
2889           const char *origstr = XSTR (x, 0);
2890           const char *str;
2891
2892           str = (* targetm.strip_name_encoding) (origstr);
2893
2894           if (is_plt)
2895             {
2896               if (cris_pic_sympart_only)
2897                 {
2898                   assemble_name (file, str);
2899                   fprintf (file, ":PLTG");
2900                 }
2901               else
2902                 {
2903                   if (TARGET_AVOID_GOTPLT)
2904                     /* We shouldn't get here.  */
2905                     abort ();
2906
2907                   fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2908                   assemble_name (file, XSTR (x, 0));
2909
2910                   if (flag_pic == 1)
2911                     fprintf (file, ":GOTPLT16]");
2912                   else
2913                     fprintf (file, ":GOTPLT]");
2914                 }
2915             }
2916           else if (cris_gotless_symbol (x))
2917             {
2918               if (! cris_pic_sympart_only)
2919                 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2920               assemble_name (file, str);
2921               fprintf (file, ":GOTOFF");
2922             }
2923           else if (cris_got_symbol (x))
2924             {
2925               if (cris_pic_sympart_only)
2926                 abort ();
2927               fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2928               assemble_name (file, XSTR (x, 0));
2929
2930               if (flag_pic == 1)
2931                 fprintf (file, ":GOT16]");
2932               else
2933                 fprintf (file, ":GOT]");
2934             }
2935           else
2936             LOSE_AND_RETURN ("unexpected PIC symbol", x);
2937
2938           /* Sanity check.  */
2939           if (! current_function_uses_pic_offset_table)
2940             output_operand_lossage ("PIC register isn't set up");
2941         }
2942       else
2943         assemble_name (file, XSTR (x, 0));
2944       break;
2945
2946     case LABEL_REF:
2947       /* If we get one of those here, it should be dressed as PIC.  Branch
2948          labels are normally output with the 'l' specifier, which means it
2949          will go directly to output_asm_label and not end up here.  */
2950       if (GET_CODE (XEXP (x, 0)) != CODE_LABEL
2951           && (GET_CODE (XEXP (x, 0)) != NOTE
2952               || NOTE_LINE_NUMBER (XEXP (x, 0)) != NOTE_INSN_DELETED_LABEL))
2953         fatal_insn ("unexpected address expression", x);
2954
2955       if (flag_pic)
2956         {
2957           if (cris_gotless_symbol (x))
2958             {
2959               if (! cris_pic_sympart_only)
2960                 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2961               cris_output_addr_const (file, XEXP (x, 0));
2962
2963               fprintf (file, ":GOTOFF");
2964             }
2965           else
2966             /* Labels are never marked as global symbols.  */
2967             fatal_insn ("unexpected PIC symbol", x);
2968
2969           /* Sanity check.  */
2970           if (! current_function_uses_pic_offset_table)
2971             internal_error ("emitting PIC operand, but PIC register isn't set up");
2972           break;
2973         }
2974
2975       output_addr_const (file, x);
2976       break;
2977
2978     case NOTE:
2979       if (NOTE_LINE_NUMBER (x) != NOTE_INSN_DELETED_LABEL)
2980         fatal_insn ("unexpected NOTE as addr_const:", x);
2981     case CODE_LABEL:
2982     case CONST_INT:
2983     case CONST_DOUBLE:
2984     case ZERO_EXTEND:
2985     case SIGN_EXTEND:
2986       output_addr_const (file, x);
2987       break;
2988
2989     case CONST:
2990       /* This used to output parentheses around the expression,
2991          but that does not work on the 386 (either ATT or BSD assembler).  */
2992       cris_output_addr_const (file, XEXP (x, 0));
2993       break;
2994
2995     case PLUS:
2996       /* Some assemblers need integer constants to appear last (eg masm).  */
2997       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2998         {
2999           cris_output_addr_const (file, XEXP (x, 1));
3000           if (INTVAL (XEXP (x, 0)) >= 0)
3001             fprintf (file, "+");
3002           output_addr_const (file, XEXP (x, 0));
3003         }
3004       else
3005         {
3006           cris_output_addr_const (file, XEXP (x, 0));
3007           if (GET_CODE (XEXP (x, 1)) != CONST_INT
3008               || INTVAL (XEXP (x, 1)) >= 0)
3009             fprintf (file, "+");
3010           cris_output_addr_const (file, XEXP (x, 1));
3011         }
3012       break;
3013
3014     case MINUS:
3015       /* Avoid outputting things like x-x or x+5-x,
3016          since some assemblers can't handle that.  */
3017       x = simplify_subtraction (x);
3018       if (GET_CODE (x) != MINUS)
3019         goto restart;
3020
3021       cris_output_addr_const (file, XEXP (x, 0));
3022       fprintf (file, "-");
3023       if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3024            && INTVAL (XEXP (x, 1)) < 0)
3025           || GET_CODE (XEXP (x, 1)) != CONST_INT)
3026         {
3027           fprintf (file, "%s", targetm.asm_out.open_paren);
3028           cris_output_addr_const (file, XEXP (x, 1));
3029           fprintf (file, "%s", targetm.asm_out.close_paren);
3030         }
3031       else
3032         output_addr_const (file, XEXP (x, 1));
3033       break;
3034
3035     default:
3036       LOSE_AND_RETURN ("unexpected address expression", x);
3037     }
3038 }
3039
3040 /* Code-in whether we can get away without a GOT entry (needed for
3041    externally visible objects but not for functions) into
3042    SYMBOL_REF_FLAG and add the PLT suffix for global functions.  */
3043
3044 static void
3045 cris_encode_section_info (exp, first)
3046      tree exp;
3047      int first ATTRIBUTE_UNUSED;
3048 {
3049   if (flag_pic)
3050     {
3051       if (DECL_P (exp))
3052         {
3053           if (TREE_CODE (exp) == FUNCTION_DECL
3054               && (TREE_PUBLIC (exp) || DECL_WEAK (exp))
3055               && ! MODULE_LOCAL_P (exp))
3056             SYMBOL_REF_FLAG (XEXP (DECL_RTL (exp), 0)) = 0;
3057           else
3058             SYMBOL_REF_FLAG (XEXP (DECL_RTL (exp), 0))
3059               = ((! TREE_PUBLIC (exp) && ! DECL_WEAK (exp))
3060                  || MODULE_LOCAL_P (exp));
3061         }
3062       else
3063         /* Others are local entities.  */
3064         SYMBOL_REF_FLAG (XEXP (TREE_CST_RTL (exp), 0)) = 1;
3065     }
3066 }
3067
3068 #if 0
3069 /* Various small functions to replace macros.  Only called from a
3070    debugger.  They might collide with gcc functions or system functions,
3071    so only emit them when '#if 1' above.  */
3072
3073 enum rtx_code Get_code PARAMS ((rtx));
3074
3075 enum rtx_code
3076 Get_code (x)
3077      rtx x;
3078 {
3079   return GET_CODE (x);
3080 }
3081
3082 const char *Get_mode PARAMS ((rtx));
3083
3084 const char *
3085 Get_mode (x)
3086      rtx x;
3087 {
3088   return GET_MODE_NAME (GET_MODE (x));
3089 }
3090
3091 rtx Xexp PARAMS ((rtx, int));
3092
3093 rtx
3094 Xexp (x, n)
3095      rtx x;
3096      int n;
3097 {
3098   return XEXP (x, n);
3099 }
3100
3101 rtx Xvecexp PARAMS ((rtx, int, int));
3102
3103 rtx
3104 Xvecexp (x, n, m)
3105      rtx x;
3106      int n;
3107 {
3108   return XVECEXP (x, n, m);
3109 }
3110
3111 int Get_rtx_len PARAMS ((rtx));
3112
3113 int
3114 Get_rtx_len (x)
3115      rtx x;
3116 {
3117   return GET_RTX_LENGTH (GET_CODE (x));
3118 }
3119
3120 /* Use upper-case to distinguish from local variables that are sometimes
3121    called next_insn and prev_insn.  */
3122
3123 rtx Next_insn PARAMS ((rtx));
3124
3125 rtx
3126 Next_insn (insn)
3127      rtx insn;
3128 {
3129   return NEXT_INSN (insn);
3130 }
3131
3132 rtx Prev_insn PARAMS ((rtx));
3133
3134 rtx
3135 Prev_insn (insn)
3136      rtx insn;
3137 {
3138   return PREV_INSN (insn);
3139 }
3140 #endif
3141
3142 /*
3143  * Local variables:
3144  * eval: (c-set-style "gnu")
3145  * indent-tabs-mode: t
3146  * End:
3147  */