OSDN Git Service

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