OSDN Git Service

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