Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / config / cris / cris.c
1 /* Definitions for GCC.  Part of the machine description for CRIS.
2    Copyright (C) 1998-2013 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 3, 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 COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-attr.h"
31 #include "flags.h"
32 #include "tree.h"
33 #include "expr.h"
34 #include "except.h"
35 #include "function.h"
36 #include "diagnostic-core.h"
37 #include "recog.h"
38 #include "reload.h"
39 #include "tm_p.h"
40 #include "debug.h"
41 #include "output.h"
42 #include "tm-constrs.h"
43 #include "target.h"
44 #include "target-def.h"
45 #include "ggc.h"
46 #include "optabs.h"
47 #include "df.h"
48 #include "opts.h"
49 #include "cgraph.h"
50
51 /* Usable when we have an amount to add or subtract, and want the
52    optimal size of the insn.  */
53 #define ADDITIVE_SIZE_MODIFIER(size) \
54  ((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d")
55
56 #define LOSE_AND_RETURN(msgid, x)                       \
57   do                                            \
58     {                                           \
59       cris_operand_lossage (msgid, x);          \
60       return;                                   \
61     } while (0)
62
63 enum cris_retinsn_type
64  { CRIS_RETINSN_UNKNOWN = 0, CRIS_RETINSN_RET, CRIS_RETINSN_JUMP };
65
66 /* Per-function machine data.  */
67 struct GTY(()) machine_function
68  {
69    int needs_return_address_on_stack;
70
71    /* This is the number of registers we save in the prologue due to
72       stdarg.  */
73    int stdarg_regs;
74
75    enum cris_retinsn_type return_type;
76  };
77
78 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
79    pattern.  */
80 static char cris_output_insn_is_bound = 0;
81
82 /* In code for output macros, this is how we know whether e.g. constant
83    goes in code or in a static initializer.  */
84 static int in_code = 0;
85
86 /* Fix for reg_overlap_mentioned_p.  */
87 static int cris_reg_overlap_mentioned_p (rtx, rtx);
88
89 static enum machine_mode cris_promote_function_mode (const_tree, enum machine_mode,
90                                                      int *, const_tree, int);
91
92 static void cris_print_base (rtx, FILE *);
93
94 static void cris_print_index (rtx, FILE *);
95
96 static void cris_output_addr_const (FILE *, rtx);
97
98 static struct machine_function * cris_init_machine_status (void);
99
100 static rtx cris_struct_value_rtx (tree, int);
101
102 static void cris_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
103                                          tree type, int *, int);
104
105 static int cris_initial_frame_pointer_offset (void);
106
107 static void cris_operand_lossage (const char *, rtx);
108
109 static int cris_reg_saved_in_regsave_area  (unsigned int, bool);
110
111 static void cris_print_operand (FILE *, rtx, int);
112
113 static void cris_print_operand_address (FILE *, rtx);
114
115 static bool cris_print_operand_punct_valid_p (unsigned char code);
116
117 static bool cris_output_addr_const_extra (FILE *, rtx);
118
119 static void cris_conditional_register_usage (void);
120
121 static void cris_asm_output_mi_thunk
122   (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
123
124 static void cris_file_start (void);
125 static void cris_init_libfuncs (void);
126
127 static reg_class_t cris_preferred_reload_class (rtx, reg_class_t);
128
129 static int cris_register_move_cost (enum machine_mode, reg_class_t, reg_class_t);
130 static int cris_memory_move_cost (enum machine_mode, reg_class_t, bool);
131 static bool cris_rtx_costs (rtx, int, int, int, int *, bool);
132 static int cris_address_cost (rtx, enum machine_mode, addr_space_t, bool);
133 static bool cris_pass_by_reference (cumulative_args_t, enum machine_mode,
134                                     const_tree, bool);
135 static int cris_arg_partial_bytes (cumulative_args_t, enum machine_mode,
136                                    tree, bool);
137 static rtx cris_function_arg (cumulative_args_t, enum machine_mode,
138                               const_tree, bool);
139 static rtx cris_function_incoming_arg (cumulative_args_t,
140                                        enum machine_mode, const_tree, bool);
141 static void cris_function_arg_advance (cumulative_args_t, enum machine_mode,
142                                        const_tree, bool);
143 static tree cris_md_asm_clobbers (tree, tree, tree);
144
145 static void cris_option_override (void);
146
147 static bool cris_frame_pointer_required (void);
148
149 static void cris_asm_trampoline_template (FILE *);
150 static void cris_trampoline_init (rtx, tree, rtx);
151
152 static rtx cris_function_value(const_tree, const_tree, bool);
153 static rtx cris_libcall_value (enum machine_mode, const_rtx);
154 static bool cris_function_value_regno_p (const unsigned int);
155 static void cris_file_end (void);
156
157 /* This is the parsed result of the "-max-stack-stackframe=" option.  If
158    it (still) is zero, then there was no such option given.  */
159 int cris_max_stackframe = 0;
160
161 /* This is the parsed result of the "-march=" option, if given.  */
162 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
163
164 #undef TARGET_ASM_ALIGNED_HI_OP
165 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
166 #undef TARGET_ASM_ALIGNED_SI_OP
167 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
168 #undef TARGET_ASM_ALIGNED_DI_OP
169 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
170
171 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
172    available in ELF.  These "normal" pseudos do not have any alignment
173    constraints or side-effects.  */
174 #undef TARGET_ASM_UNALIGNED_HI_OP
175 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
176
177 #undef TARGET_ASM_UNALIGNED_SI_OP
178 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
179
180 #undef TARGET_ASM_UNALIGNED_DI_OP
181 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
182
183 #undef TARGET_PRINT_OPERAND
184 #define TARGET_PRINT_OPERAND cris_print_operand
185 #undef TARGET_PRINT_OPERAND_ADDRESS
186 #define TARGET_PRINT_OPERAND_ADDRESS cris_print_operand_address
187 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
188 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P cris_print_operand_punct_valid_p
189 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
190 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA cris_output_addr_const_extra
191
192 #undef TARGET_CONDITIONAL_REGISTER_USAGE
193 #define TARGET_CONDITIONAL_REGISTER_USAGE cris_conditional_register_usage
194
195 #undef TARGET_ASM_OUTPUT_MI_THUNK
196 #define TARGET_ASM_OUTPUT_MI_THUNK cris_asm_output_mi_thunk
197 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
198 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
199
200 #undef TARGET_ASM_FILE_START
201 #define TARGET_ASM_FILE_START cris_file_start
202 #undef TARGET_ASM_FILE_END
203 #define TARGET_ASM_FILE_END cris_file_end
204
205 #undef TARGET_INIT_LIBFUNCS
206 #define TARGET_INIT_LIBFUNCS cris_init_libfuncs
207
208 #undef TARGET_LEGITIMATE_ADDRESS_P
209 #define TARGET_LEGITIMATE_ADDRESS_P cris_legitimate_address_p
210
211 #undef TARGET_PREFERRED_RELOAD_CLASS
212 #define TARGET_PREFERRED_RELOAD_CLASS cris_preferred_reload_class
213
214 #undef TARGET_REGISTER_MOVE_COST
215 #define TARGET_REGISTER_MOVE_COST cris_register_move_cost
216 #undef TARGET_MEMORY_MOVE_COST
217 #define TARGET_MEMORY_MOVE_COST cris_memory_move_cost
218 #undef TARGET_RTX_COSTS
219 #define TARGET_RTX_COSTS cris_rtx_costs
220 #undef TARGET_ADDRESS_COST
221 #define TARGET_ADDRESS_COST cris_address_cost
222
223 #undef TARGET_PROMOTE_FUNCTION_MODE
224 #define TARGET_PROMOTE_FUNCTION_MODE cris_promote_function_mode
225
226 #undef TARGET_STRUCT_VALUE_RTX
227 #define TARGET_STRUCT_VALUE_RTX cris_struct_value_rtx
228 #undef TARGET_SETUP_INCOMING_VARARGS
229 #define TARGET_SETUP_INCOMING_VARARGS cris_setup_incoming_varargs
230 #undef TARGET_PASS_BY_REFERENCE
231 #define TARGET_PASS_BY_REFERENCE cris_pass_by_reference
232 #undef TARGET_ARG_PARTIAL_BYTES
233 #define TARGET_ARG_PARTIAL_BYTES cris_arg_partial_bytes
234 #undef TARGET_FUNCTION_ARG
235 #define TARGET_FUNCTION_ARG cris_function_arg
236 #undef TARGET_FUNCTION_INCOMING_ARG
237 #define TARGET_FUNCTION_INCOMING_ARG cris_function_incoming_arg
238 #undef TARGET_FUNCTION_ARG_ADVANCE
239 #define TARGET_FUNCTION_ARG_ADVANCE cris_function_arg_advance
240 #undef TARGET_MD_ASM_CLOBBERS
241 #define TARGET_MD_ASM_CLOBBERS cris_md_asm_clobbers
242 #undef TARGET_FRAME_POINTER_REQUIRED
243 #define TARGET_FRAME_POINTER_REQUIRED cris_frame_pointer_required
244
245 #undef TARGET_OPTION_OVERRIDE
246 #define TARGET_OPTION_OVERRIDE cris_option_override
247
248 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
249 #define TARGET_ASM_TRAMPOLINE_TEMPLATE cris_asm_trampoline_template
250 #undef TARGET_TRAMPOLINE_INIT
251 #define TARGET_TRAMPOLINE_INIT cris_trampoline_init
252
253 #undef TARGET_FUNCTION_VALUE
254 #define TARGET_FUNCTION_VALUE cris_function_value
255 #undef TARGET_LIBCALL_VALUE
256 #define TARGET_LIBCALL_VALUE cris_libcall_value
257 #undef TARGET_FUNCTION_VALUE_REGNO_P
258 #define TARGET_FUNCTION_VALUE_REGNO_P cris_function_value_regno_p
259
260 struct gcc_target targetm = TARGET_INITIALIZER;
261
262 /* Helper for cris_load_multiple_op and cris_ret_movem_op.  */
263
264 bool
265 cris_movem_load_rest_p (rtx op, int offs)
266 {
267   unsigned int reg_count = XVECLEN (op, 0) - offs;
268   rtx src_addr;
269   int i;
270   rtx elt;
271   int setno;
272   int regno_dir = 1;
273   unsigned int regno = 0;
274
275   /* Perform a quick check so we don't blow up below.  FIXME: Adjust for
276      other than (MEM reg).  */
277   if (reg_count <= 1
278       || GET_CODE (XVECEXP (op, 0, offs)) != SET
279       || !REG_P (SET_DEST (XVECEXP (op, 0, offs)))
280       || !MEM_P (SET_SRC (XVECEXP (op, 0, offs))))
281     return false;
282
283   /* Check a possible post-inc indicator.  */
284   if (GET_CODE (SET_SRC (XVECEXP (op, 0, offs + 1))) == PLUS)
285     {
286       rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 0);
287       rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 1);
288
289       reg_count--;
290
291       if (reg_count == 1
292           || !REG_P (reg)
293           || !REG_P (SET_DEST (XVECEXP (op, 0, offs + 1)))
294           || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, offs + 1)))
295           || !CONST_INT_P (inc)
296           || INTVAL (inc) != (HOST_WIDE_INT) reg_count * 4)
297         return false;
298       i = offs + 2;
299     }
300   else
301     i = offs + 1;
302
303   if (!TARGET_V32)
304     {
305       regno_dir = -1;
306       regno = reg_count - 1;
307     }
308
309   elt = XVECEXP (op, 0, offs);
310   src_addr = XEXP (SET_SRC (elt), 0);
311
312   if (GET_CODE (elt) != SET
313       || !REG_P (SET_DEST (elt))
314       || GET_MODE (SET_DEST (elt)) != SImode
315       || REGNO (SET_DEST (elt)) != regno
316       || !MEM_P (SET_SRC (elt))
317       || GET_MODE (SET_SRC (elt)) != SImode
318       || !memory_address_p (SImode, src_addr))
319     return false;
320
321   for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
322     {
323       rtx elt = XVECEXP (op, 0, i);
324       regno += regno_dir;
325
326       if (GET_CODE (elt) != SET
327           || !REG_P (SET_DEST (elt))
328           || GET_MODE (SET_DEST (elt)) != SImode
329           || REGNO (SET_DEST (elt)) != regno
330           || !MEM_P (SET_SRC (elt))
331           || GET_MODE (SET_SRC (elt)) != SImode
332           || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
333           || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
334           || !CONST_INT_P (XEXP (XEXP (SET_SRC (elt), 0), 1))
335           || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != setno * 4)
336         return false;
337     }
338
339   return true;
340 }
341
342 /* Worker function for predicate for the parallel contents in a movem
343    to-memory.  */
344
345 bool
346 cris_store_multiple_op_p (rtx op)
347 {
348   int reg_count = XVECLEN (op, 0);
349   rtx dest;
350   rtx dest_addr;
351   rtx dest_base;
352   int i;
353   rtx elt;
354   int setno;
355   int regno_dir = 1;
356   int regno = 0;
357   int offset = 0;
358
359   /* Perform a quick check so we don't blow up below.  FIXME: Adjust for
360      other than (MEM reg) and (MEM (PLUS reg const)).  */
361   if (reg_count <= 1)
362     return false;
363
364   elt = XVECEXP (op, 0, 0);
365
366   if (GET_CODE (elt) != SET)
367     return  false;
368
369   dest = SET_DEST (elt);
370
371   if (!REG_P (SET_SRC (elt)) || !MEM_P (dest))
372     return false;
373
374   dest_addr = XEXP (dest, 0);
375
376   /* Check a possible post-inc indicator.  */
377   if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS)
378     {
379       rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 0);
380       rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1);
381
382       reg_count--;
383
384       if (reg_count == 1
385           || !REG_P (reg)
386           || !REG_P (SET_DEST (XVECEXP (op, 0, 1)))
387           || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, 1)))
388           || !CONST_INT_P (inc)
389           /* Support increment by number of registers, and by the offset
390              of the destination, if it has the form (MEM (PLUS reg
391              offset)).  */
392           || !((REG_P (dest_addr)
393                 && REGNO (dest_addr) == REGNO (reg)
394                 && INTVAL (inc) == (HOST_WIDE_INT) reg_count * 4)
395                || (GET_CODE (dest_addr) == PLUS
396                    && REG_P (XEXP (dest_addr, 0))
397                    && REGNO (XEXP (dest_addr, 0)) == REGNO (reg)
398                    && CONST_INT_P (XEXP (dest_addr, 1))
399                    && INTVAL (XEXP (dest_addr, 1)) == INTVAL (inc))))
400         return false;
401
402       i = 2;
403     }
404   else
405     i = 1;
406
407   if (!TARGET_V32)
408     {
409       regno_dir = -1;
410       regno = reg_count - 1;
411     }
412
413   if (GET_CODE (elt) != SET
414       || !REG_P (SET_SRC (elt))
415       || GET_MODE (SET_SRC (elt)) != SImode
416       || REGNO (SET_SRC (elt)) != (unsigned int) regno
417       || !MEM_P (SET_DEST (elt))
418       || GET_MODE (SET_DEST (elt)) != SImode)
419     return false;
420
421   if (REG_P (dest_addr))
422     {
423       dest_base = dest_addr;
424       offset = 0;
425     }
426   else if (GET_CODE (dest_addr) == PLUS
427            && REG_P (XEXP (dest_addr, 0))
428            && CONST_INT_P (XEXP (dest_addr, 1)))
429     {
430       dest_base = XEXP (dest_addr, 0);
431       offset = INTVAL (XEXP (dest_addr, 1));
432     }
433   else
434     return false;
435
436   for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
437     {
438       rtx elt = XVECEXP (op, 0, i);
439       regno += regno_dir;
440
441       if (GET_CODE (elt) != SET
442           || !REG_P (SET_SRC (elt))
443           || GET_MODE (SET_SRC (elt)) != SImode
444           || REGNO (SET_SRC (elt)) != (unsigned int) regno
445           || !MEM_P (SET_DEST (elt))
446           || GET_MODE (SET_DEST (elt)) != SImode
447           || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
448           || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_base)
449           || !CONST_INT_P (XEXP (XEXP (SET_DEST (elt), 0), 1))
450           || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != setno * 4 + offset)
451         return false;
452     }
453
454   return true;
455 }
456
457 /* The TARGET_CONDITIONAL_REGISTER_USAGE worker.  */
458
459 static void
460 cris_conditional_register_usage (void)
461 {
462   /* FIXME: This isn't nice.  We should be able to use that register for
463      something else if the PIC table isn't needed.  */
464   if (flag_pic)
465     fixed_regs[PIC_OFFSET_TABLE_REGNUM]
466       = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
467
468   /* Allow use of ACR (PC in pre-V32) and tweak order.  */
469   if (TARGET_V32)
470     {
471       static const int reg_alloc_order_v32[] = REG_ALLOC_ORDER_V32;
472       unsigned int i;
473
474       fixed_regs[CRIS_ACR_REGNUM] = 0;
475
476       for (i = 0;
477           i < sizeof (reg_alloc_order_v32)/sizeof (reg_alloc_order_v32[0]);
478           i++)
479        reg_alloc_order[i] = reg_alloc_order_v32[i];
480     }
481
482   if (TARGET_HAS_MUL_INSNS)
483     fixed_regs[CRIS_MOF_REGNUM] = 0;
484
485   /* On early versions, we must use the 16-bit condition-code register,
486      which has another name.  */
487   if (cris_cpu_version < 8)
488     reg_names[CRIS_CC0_REGNUM] = "ccr";
489 }
490
491 /* Return crtl->uses_pic_offset_table.  For use in cris.md,
492    since some generated files do not include function.h.  */
493
494 int
495 cris_cfun_uses_pic_table (void)
496 {
497   return crtl->uses_pic_offset_table;
498 }
499
500 /* Given an rtx, return the text string corresponding to the CODE of X.
501    Intended for use in the assembly language output section of a
502    define_insn.  */
503
504 const char *
505 cris_op_str (rtx x)
506 {
507   cris_output_insn_is_bound = 0;
508   switch (GET_CODE (x))
509     {
510     case PLUS:
511       return "add";
512       break;
513
514     case MINUS:
515       return "sub";
516       break;
517
518     case MULT:
519       /* This function is for retrieving a part of an instruction name for
520          an operator, for immediate output.  If that ever happens for
521          MULT, we need to apply TARGET_MUL_BUG in the caller.  Make sure
522          we notice.  */
523       internal_error ("MULT case in cris_op_str");
524       break;
525
526     case DIV:
527       return "div";
528       break;
529
530     case AND:
531       return "and";
532       break;
533
534     case IOR:
535       return "or";
536       break;
537
538     case XOR:
539       return "xor";
540       break;
541
542     case NOT:
543       return "not";
544       break;
545
546     case ASHIFT:
547       return "lsl";
548       break;
549
550     case LSHIFTRT:
551       return "lsr";
552       break;
553
554     case ASHIFTRT:
555       return "asr";
556       break;
557
558     case UMIN:
559       /* Used to control the sign/zero-extend character for the 'E' modifier.
560          BOUND has none.  */
561       cris_output_insn_is_bound = 1;
562       return "bound";
563       break;
564
565     default:
566       return "Unknown operator";
567       break;
568   }
569 }
570
571 /* Emit an error message when we're in an asm, and a fatal error for
572    "normal" insns.  Formatted output isn't easily implemented, since we
573    use output_operand_lossage to output the actual message and handle the
574    categorization of the error.  */
575
576 static void
577 cris_operand_lossage (const char *msgid, rtx op)
578 {
579   debug_rtx (op);
580   output_operand_lossage ("%s", msgid);
581 }
582
583 /* Print an index part of an address to file.  */
584
585 static void
586 cris_print_index (rtx index, FILE *file)
587 {
588   /* Make the index "additive" unless we'll output a negative number, in
589      which case the sign character is free (as in free beer).  */
590   if (!CONST_INT_P (index) || INTVAL (index) >= 0)
591     putc ('+', file);
592
593   if (REG_P (index))
594     fprintf (file, "$%s.b", reg_names[REGNO (index)]);
595   else if (CONSTANT_P (index))
596     cris_output_addr_const (file, index);
597   else if (GET_CODE (index) == MULT)
598     {
599       fprintf (file, "$%s.",
600                reg_names[REGNO (XEXP (index, 0))]);
601
602       putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
603     }
604   else if (GET_CODE (index) == SIGN_EXTEND && MEM_P (XEXP (index, 0)))
605     {
606       rtx inner = XEXP (index, 0);
607       rtx inner_inner = XEXP (inner, 0);
608
609       if (GET_CODE (inner_inner) == POST_INC)
610         {
611           fprintf (file, "[$%s+].",
612                    reg_names[REGNO (XEXP (inner_inner, 0))]);
613           putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
614         }
615       else
616         {
617           fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
618
619           putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
620         }
621     }
622   else if (MEM_P (index))
623     {
624       rtx inner = XEXP (index, 0);
625       if (GET_CODE (inner) == POST_INC)
626         fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
627       else
628         fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
629     }
630   else
631     cris_operand_lossage ("unexpected index-type in cris_print_index",
632                           index);
633 }
634
635 /* Print a base rtx of an address to file.  */
636
637 static void
638 cris_print_base (rtx base, FILE *file)
639 {
640   if (REG_P (base))
641     fprintf (file, "$%s", reg_names[REGNO (base)]);
642   else if (GET_CODE (base) == POST_INC)
643     {
644       gcc_assert (REGNO (XEXP (base, 0)) != CRIS_ACR_REGNUM);
645       fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
646     }
647   else
648     cris_operand_lossage ("unexpected base-type in cris_print_base",
649                           base);
650 }
651
652 /* Usable as a guard in expressions.  */
653
654 int
655 cris_fatal (char *arg)
656 {
657   internal_error (arg);
658
659   /* We'll never get here; this is just to appease compilers.  */
660   return 0;
661 }
662
663 /* Return nonzero if REGNO is an ordinary register that *needs* to be
664    saved together with other registers, possibly by a MOVEM instruction,
665    or is saved for target-independent reasons.  There may be
666    target-dependent reasons to save the register anyway; this is just a
667    wrapper for a complicated conditional.  */
668
669 static int
670 cris_reg_saved_in_regsave_area (unsigned int regno, bool got_really_used)
671 {
672   return
673     (((df_regs_ever_live_p (regno)
674        && !call_used_regs[regno])
675       || (regno == PIC_OFFSET_TABLE_REGNUM
676           && (got_really_used
677               /* It is saved anyway, if there would be a gap.  */
678               || (flag_pic
679                   && df_regs_ever_live_p (regno + 1)
680                   && !call_used_regs[regno + 1]))))
681      && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
682      && regno != CRIS_SRP_REGNUM)
683     || (crtl->calls_eh_return
684         && (regno == EH_RETURN_DATA_REGNO (0)
685             || regno == EH_RETURN_DATA_REGNO (1)
686             || regno == EH_RETURN_DATA_REGNO (2)
687             || regno == EH_RETURN_DATA_REGNO (3)));
688 }
689
690 /* The PRINT_OPERAND worker.  */
691
692 static void
693 cris_print_operand (FILE *file, rtx x, int code)
694 {
695   rtx operand = x;
696
697   /* Size-strings corresponding to MULT expressions.  */
698   static const char *const mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
699
700   /* New code entries should just be added to the switch below.  If
701      handling is finished, just return.  If handling was just a
702      modification of the operand, the modified operand should be put in
703      "operand", and then do a break to let default handling
704      (zero-modifier) output the operand.  */
705
706   switch (code)
707     {
708     case 'b':
709       /* Print the unsigned supplied integer as if it were signed
710          and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc.  */
711       if (!satisfies_constraint_O (x))
712         LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
713       fprintf (file, HOST_WIDE_INT_PRINT_DEC,
714                INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
715       return;
716
717     case 'x':
718       /* Print assembler code for operator.  */
719       fprintf (file, "%s", cris_op_str (operand));
720       return;
721
722     case 'o':
723       {
724         /* A movem modifier working on a parallel; output the register
725            name.  */
726         int regno;
727
728         if (GET_CODE (x) != PARALLEL)
729           LOSE_AND_RETURN ("invalid operand for 'o' modifier", x);
730
731         /* The second item can be (set reg (plus reg const)) to denote a
732            postincrement.  */
733         regno
734           = (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS
735              ? XVECLEN (x, 0) - 2
736              : XVECLEN (x, 0) - 1);
737
738         fprintf (file, "$%s", reg_names [regno]);
739       }
740       return;
741
742     case 'O':
743       {
744         /* A similar movem modifier; output the memory operand.  */
745         rtx addr;
746
747         if (GET_CODE (x) != PARALLEL)
748           LOSE_AND_RETURN ("invalid operand for 'O' modifier", x);
749
750         /* The lowest mem operand is in the first item, but perhaps it
751            needs to be output as postincremented.  */
752         addr = MEM_P (SET_SRC (XVECEXP (x, 0, 0)))
753           ? XEXP (SET_SRC (XVECEXP (x, 0, 0)), 0)
754           : XEXP (SET_DEST (XVECEXP (x, 0, 0)), 0);
755
756         /* The second item can be a (set reg (plus reg const)) to denote
757            a modification.  */
758         if (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS)
759           {
760             /* It's a post-increment, if the address is a naked (reg).  */
761             if (REG_P (addr))
762               addr = gen_rtx_POST_INC (SImode, addr);
763             else
764               {
765                 /* Otherwise, it's a side-effect; RN=RN+M.  */
766                 fprintf (file, "[$%s=$%s%s%d]",
767                          reg_names [REGNO (SET_DEST (XVECEXP (x, 0, 1)))],
768                          reg_names [REGNO (XEXP (addr, 0))],
769                          INTVAL (XEXP (addr, 1)) < 0 ? "" : "+",
770                          (int) INTVAL (XEXP (addr, 1)));
771                 return;
772               }
773           }
774         output_address (addr);
775       }
776       return;
777
778     case 'p':
779       /* Adjust a power of two to its log2.  */
780       if (!CONST_INT_P (x) || exact_log2 (INTVAL (x)) < 0 )
781         LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
782       fprintf (file, "%d", exact_log2 (INTVAL (x)));
783       return;
784
785     case 's':
786       /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
787          respectively.  This modifier also terminates the inhibiting
788          effects of the 'x' modifier.  */
789       cris_output_insn_is_bound = 0;
790       if (GET_MODE (x) == VOIDmode && CONST_INT_P (x))
791         {
792           if (INTVAL (x) >= 0)
793             {
794               if (INTVAL (x) <= 255)
795                 putc ('b', file);
796               else if (INTVAL (x) <= 65535)
797                 putc ('w', file);
798               else
799                 putc ('d', file);
800             }
801           else
802             putc ('d', file);
803           return;
804         }
805
806       /* For a non-integer, print the size of the operand.  */
807       putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
808             ? 'd' : GET_MODE (x) == HImode ? 'w'
809             : GET_MODE (x) == QImode ? 'b'
810             /* If none of the above, emit an erroneous size letter.  */
811             : 'X',
812             file);
813       return;
814
815     case 'z':
816       /* Const_int: print b for -127 <= x <= 255,
817          w for -32768 <= x <= 65535, else die.  */
818       if (!CONST_INT_P (x)
819           || INTVAL (x) < -32768 || INTVAL (x) > 65535)
820         LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
821       putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
822       return;
823
824     case 'Z':
825       /* If this is a GOT-symbol, print the size-letter corresponding to
826          -fpic/-fPIC.  For everything else, print "d".  */
827       putc ((flag_pic == 1
828              && GET_CODE (x) == CONST
829              && GET_CODE (XEXP (x, 0)) == UNSPEC
830              && XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREAD)
831             ? 'w' : 'd', file);
832       return;
833
834     case '#':
835       /* Output a 'nop' if there's nothing for the delay slot.
836          This method stolen from the sparc files.  */
837       if (dbr_sequence_length () == 0)
838         fputs ("\n\tnop", file);
839       return;
840
841     case '!':
842       /* Output directive for alignment padded with "nop" insns.
843          Optimizing for size, it's plain 4-byte alignment, otherwise we
844          align the section to a cache-line (32 bytes) and skip at max 2
845          bytes, i.e. we skip if it's the last insn on a cache-line.  The
846          latter is faster by a small amount (for two test-programs 99.6%
847          and 99.9%) and larger by a small amount (ditto 100.1% and
848          100.2%).  This is supposed to be the simplest yet performance-
849          wise least intrusive way to make sure the immediately following
850          (supposed) muls/mulu insn isn't located at the end of a
851          cache-line.  */
852       if (TARGET_MUL_BUG)
853         fputs (optimize_size
854                ? ".p2alignw 2,0x050f\n\t"
855                : ".p2alignw 5,0x050f,2\n\t", file);
856       return;
857
858     case ':':
859       /* The PIC register.  */
860       if (! flag_pic)
861         internal_error ("invalid use of ':' modifier");
862       fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
863       return;
864
865     case 'H':
866       /* Print high (most significant) part of something.  */
867       switch (GET_CODE (operand))
868         {
869         case CONST_INT:
870           /* If we're having 64-bit HOST_WIDE_INTs, the whole (DImode)
871              value is kept here, and so may be other than 0 or -1.  */
872           fprintf (file, HOST_WIDE_INT_PRINT_DEC,
873                    INTVAL (operand_subword (operand, 1, 0, DImode)));
874           return;
875
876         case CONST_DOUBLE:
877           /* High part of a long long constant.  */
878           if (GET_MODE (operand) == VOIDmode)
879             {
880               fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_HIGH (x));
881               return;
882             }
883           else
884             LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
885
886         case REG:
887           /* Print reg + 1.  Check that there's not an attempt to print
888              high-parts of registers like stack-pointer or higher, except
889              for SRP (where the "high part" is MOF).  */
890           if (REGNO (operand) > STACK_POINTER_REGNUM - 2
891               && (REGNO (operand) != CRIS_SRP_REGNUM
892                   || CRIS_SRP_REGNUM + 1 != CRIS_MOF_REGNUM
893                   || fixed_regs[CRIS_MOF_REGNUM] != 0))
894             LOSE_AND_RETURN ("bad register", operand);
895           fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
896           return;
897
898         case MEM:
899           /* Adjust memory address to high part.  */
900           {
901             rtx adj_mem = operand;
902             int size
903               = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
904
905             /* Adjust so we can use two SImode in DImode.
906                Calling adj_offsettable_operand will make sure it is an
907                offsettable address.  Don't do this for a postincrement
908                though; it should remain as it was.  */
909             if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
910               adj_mem
911                 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
912
913             output_address (XEXP (adj_mem, 0));
914             return;
915           }
916
917         default:
918           LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
919         }
920
921     case 'L':
922       /* Strip the MEM expression.  */
923       operand = XEXP (operand, 0);
924       break;
925
926     case 'e':
927       /* Like 'E', but ignore state set by 'x'.  FIXME: Use code
928          iterators and attributes in cris.md to avoid the need for %x
929          and %E (and %e) and state passed between those modifiers.  */
930       cris_output_insn_is_bound = 0;
931       /* FALL THROUGH.  */
932     case 'E':
933       /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
934          cris_output_insn_is_bound is nonzero.  */
935       if (GET_CODE (operand) != SIGN_EXTEND
936           && GET_CODE (operand) != ZERO_EXTEND
937           && !CONST_INT_P (operand))
938         LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
939
940       if (cris_output_insn_is_bound)
941         {
942           cris_output_insn_is_bound = 0;
943           return;
944         }
945
946       putc (GET_CODE (operand) == SIGN_EXTEND
947             || (CONST_INT_P (operand) && INTVAL (operand) < 0)
948             ? 's' : 'u', file);
949       return;
950
951     case 'm':
952       /* Print the size letter of the inner element.  We can do it by
953          calling ourselves with the 's' modifier.  */
954       if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
955         LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
956       cris_print_operand (file, XEXP (operand, 0), 's');
957       return;
958
959     case 'M':
960       /* Print the least significant part of operand.  */
961       if (GET_CODE (operand) == CONST_DOUBLE)
962         {
963           fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
964           return;
965         }
966       else if (HOST_BITS_PER_WIDE_INT > 32 && CONST_INT_P (operand))
967         {
968           fprintf (file, HOST_WIDE_INT_PRINT_HEX,
969                    INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1));
970           return;
971         }
972       /* Otherwise the least significant part equals the normal part,
973          so handle it normally.  */
974       break;
975
976     case 'A':
977       /* When emitting an add for the high part of a DImode constant, we
978          want to use addq for 0 and adds.w for -1.  */
979       if (!CONST_INT_P (operand))
980         LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
981       fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
982       return;
983
984     case 'P':
985       /* For const_int operands, print the additive mnemonic and the
986          modified operand (byte-sized operands don't save anything):
987           N=MIN_INT..-65536: add.d N
988           -65535..-64: subu.w -N
989           -63..-1: subq -N
990           0..63: addq N
991           64..65535: addu.w N
992           65536..MAX_INT: add.d N.
993          (Emitted mnemonics are capitalized to simplify testing.)
994          For anything else (N.B: only register is valid), print "add.d".  */
995       if (REG_P (operand))
996         {
997           fprintf (file, "Add.d ");
998
999           /* Deal with printing the operand by dropping through to the
1000              normal path.  */
1001           break;
1002         }
1003       else
1004         {
1005           int val;
1006           gcc_assert (CONST_INT_P (operand));
1007
1008           val = INTVAL (operand);
1009           if (!IN_RANGE (val, -65535, 65535))
1010               fprintf (file, "Add.d %d", val);
1011           else if (val <= -64)
1012             fprintf (file, "Subu.w %d", -val);
1013           else if (val <= -1)
1014             fprintf (file, "Subq %d", -val);
1015           else if (val <= 63)
1016               fprintf (file, "Addq %d", val);
1017           else if (val <= 65535)
1018             fprintf (file, "Addu.w %d", val);
1019           return;
1020         }
1021       break;
1022
1023     case 'q':
1024       /* If the operand is an integer -31..31, print "q" else ".d".  */
1025       if (CONST_INT_P (operand) && IN_RANGE (INTVAL (operand), -31, 31))
1026         fprintf (file, "q");
1027       else
1028         fprintf (file, ".d");
1029       return;
1030
1031     case 'd':
1032       /* If this is a GOT symbol, force it to be emitted as :GOT and
1033          :GOTPLT regardless of -fpic (i.e. not as :GOT16, :GOTPLT16).
1034          Avoid making this too much of a special case.  */
1035       if (flag_pic == 1 && CONSTANT_P (operand))
1036         {
1037           int flag_pic_save = flag_pic;
1038
1039           flag_pic = 2;
1040           cris_output_addr_const (file, operand);
1041           flag_pic = flag_pic_save;
1042           return;
1043         }
1044       break;
1045
1046     case 'D':
1047       /* When emitting an sub for the high part of a DImode constant, we
1048          want to use subq for 0 and subs.w for -1.  */
1049       if (!CONST_INT_P (operand))
1050         LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
1051       fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
1052       return;
1053
1054     case 'S':
1055       /* Print the operand as the index-part of an address.
1056          Easiest way out is to use cris_print_index.  */
1057       cris_print_index (operand, file);
1058       return;
1059
1060     case 'T':
1061       /* Print the size letter for an operand to a MULT, which must be a
1062          const_int with a suitable value.  */
1063       if (!CONST_INT_P (operand) || INTVAL (operand) > 4)
1064         LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
1065       fprintf (file, "%s", mults[INTVAL (operand)]);
1066       return;
1067
1068     case 'u':
1069       /* Print "u.w" if a GOT symbol and flag_pic == 1, else ".d".  */
1070       if (flag_pic == 1
1071           && GET_CODE (operand) == CONST
1072           && GET_CODE (XEXP (operand, 0)) == UNSPEC
1073           && XINT (XEXP (operand, 0), 1) == CRIS_UNSPEC_GOTREAD)
1074         fprintf (file, "u.w");
1075       else
1076         fprintf (file, ".d");
1077       return;
1078
1079     case 0:
1080       /* No code, print as usual.  */
1081       break;
1082
1083     default:
1084       LOSE_AND_RETURN ("invalid operand modifier letter", x);
1085     }
1086
1087   /* Print an operand as without a modifier letter.  */
1088   switch (GET_CODE (operand))
1089     {
1090     case REG:
1091       if (REGNO (operand) > 15
1092           && REGNO (operand) != CRIS_MOF_REGNUM
1093           && REGNO (operand) != CRIS_SRP_REGNUM
1094           && REGNO (operand) != CRIS_CC0_REGNUM)
1095         internal_error ("internal error: bad register: %d", REGNO (operand));
1096       fprintf (file, "$%s", reg_names[REGNO (operand)]);
1097       return;
1098
1099     case MEM:
1100       output_address (XEXP (operand, 0));
1101       return;
1102
1103     case CONST_DOUBLE:
1104       if (GET_MODE (operand) == VOIDmode)
1105         /* A long long constant.  */
1106         output_addr_const (file, operand);
1107       else
1108         {
1109           /* Only single precision is allowed as plain operands the
1110              moment.  FIXME:  REAL_VALUE_FROM_CONST_DOUBLE isn't
1111              documented.  */
1112           REAL_VALUE_TYPE r;
1113           long l;
1114
1115           /* FIXME:  Perhaps check overflow of the "single".  */
1116           REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1117           REAL_VALUE_TO_TARGET_SINGLE (r, l);
1118
1119           fprintf (file, "0x%lx", l);
1120         }
1121       return;
1122
1123     case UNSPEC:
1124       /* Fall through.  */
1125     case CONST:
1126       cris_output_addr_const (file, operand);
1127       return;
1128
1129     case MULT:
1130     case ASHIFT:
1131       {
1132         /* For a (MULT (reg X) const_int) we output "rX.S".  */
1133         int i = CONST_INT_P (XEXP (operand, 1))
1134           ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1135         rtx reg = CONST_INT_P (XEXP (operand, 1))
1136           ? XEXP (operand, 0) : XEXP (operand, 1);
1137
1138         if (!REG_P (reg)
1139             || (!CONST_INT_P (XEXP (operand, 0))
1140                 && !CONST_INT_P (XEXP (operand, 1))))
1141           LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1142
1143         cris_print_base (reg, file);
1144         fprintf (file, ".%c",
1145                  i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1146                  : i == 4 ? 'd'
1147                  : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1148                  : 'd');
1149         return;
1150       }
1151
1152     default:
1153       /* No need to handle all strange variants, let output_addr_const
1154          do it for us.  */
1155       if (CONSTANT_P (operand))
1156         {
1157           cris_output_addr_const (file, operand);
1158           return;
1159         }
1160
1161       LOSE_AND_RETURN ("unexpected operand", x);
1162     }
1163 }
1164
1165 static bool
1166 cris_print_operand_punct_valid_p (unsigned char code)
1167 {
1168   return (code == '#' || code == '!' || code == ':');
1169 }
1170
1171 /* The PRINT_OPERAND_ADDRESS worker.  */
1172
1173 static void
1174 cris_print_operand_address (FILE *file, rtx x)
1175 {
1176   /* All these were inside MEM:s so output indirection characters.  */
1177   putc ('[', file);
1178
1179   if (CONSTANT_ADDRESS_P (x))
1180     cris_output_addr_const (file, x);
1181   else if (cris_base_or_autoincr_p (x, true))
1182     cris_print_base (x, file);
1183   else if (GET_CODE (x) == PLUS)
1184     {
1185       rtx x1, x2;
1186
1187       x1 = XEXP (x, 0);
1188       x2 = XEXP (x, 1);
1189       if (cris_base_p (x1, true))
1190         {
1191           cris_print_base (x1, file);
1192           cris_print_index (x2, file);
1193         }
1194       else if (cris_base_p (x2, true))
1195         {
1196           cris_print_base (x2, file);
1197           cris_print_index (x1, file);
1198         }
1199       else
1200         LOSE_AND_RETURN ("unrecognized address", x);
1201     }
1202   else if (MEM_P (x))
1203     {
1204       /* A DIP.  Output more indirection characters.  */
1205       putc ('[', file);
1206       cris_print_base (XEXP (x, 0), file);
1207       putc (']', file);
1208     }
1209   else
1210     LOSE_AND_RETURN ("unrecognized address", x);
1211
1212   putc (']', file);
1213 }
1214
1215 /* The RETURN_ADDR_RTX worker.
1216    We mark that the return address is used, either by EH or
1217    __builtin_return_address, for use by the function prologue and
1218    epilogue.  FIXME: This isn't optimal; we just use the mark in the
1219    prologue and epilogue to say that the return address is to be stored
1220    in the stack frame.  We could return SRP for leaf-functions and use the
1221    initial-value machinery.  */
1222
1223 rtx
1224 cris_return_addr_rtx (int count, rtx frameaddr ATTRIBUTE_UNUSED)
1225 {
1226   cfun->machine->needs_return_address_on_stack = 1;
1227
1228   /* The return-address is stored just above the saved frame-pointer (if
1229      present).  Apparently we can't eliminate from the frame-pointer in
1230      that direction, so use the incoming args (maybe pretended) pointer.  */
1231   return count == 0
1232     ? gen_rtx_MEM (Pmode, plus_constant (Pmode, virtual_incoming_args_rtx, -4))
1233     : NULL_RTX;
1234 }
1235
1236 /* Accessor used in cris.md:return because cfun->machine isn't available
1237    there.  */
1238
1239 bool
1240 cris_return_address_on_stack (void)
1241 {
1242   return df_regs_ever_live_p (CRIS_SRP_REGNUM)
1243     || cfun->machine->needs_return_address_on_stack;
1244 }
1245
1246 /* Accessor used in cris.md:return because cfun->machine isn't available
1247    there.  */
1248
1249 bool
1250 cris_return_address_on_stack_for_return (void)
1251 {
1252   return cfun->machine->return_type == CRIS_RETINSN_RET ? false
1253     : cris_return_address_on_stack ();
1254 }
1255
1256 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1257    handles FP -> SP elimination offset.  */
1258
1259 static int
1260 cris_initial_frame_pointer_offset (void)
1261 {
1262   int regno;
1263
1264   /* Initial offset is 0 if we don't have a frame pointer.  */
1265   int offs = 0;
1266   bool got_really_used = false;
1267
1268   if (crtl->uses_pic_offset_table)
1269     {
1270       push_topmost_sequence ();
1271       got_really_used
1272         = reg_used_between_p (pic_offset_table_rtx, get_insns (),
1273                               NULL_RTX);
1274       pop_topmost_sequence ();
1275     }
1276
1277   /* And 4 for each register pushed.  */
1278   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1279     if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1280       offs += 4;
1281
1282   /* And then, last, we add the locals allocated.  */
1283   offs += get_frame_size ();
1284
1285   /* And more; the accumulated args size.  */
1286   offs += crtl->outgoing_args_size;
1287
1288   /* Then round it off, in case we use aligned stack.  */
1289   if (TARGET_STACK_ALIGN)
1290     offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1291
1292   return offs;
1293 }
1294
1295 /* The INITIAL_ELIMINATION_OFFSET worker.
1296    Calculate the difference between imaginary registers such as frame
1297    pointer and the stack pointer.  Used to eliminate the frame pointer
1298    and imaginary arg pointer.  */
1299
1300 int
1301 cris_initial_elimination_offset (int fromreg, int toreg)
1302 {
1303   int fp_sp_offset
1304     = cris_initial_frame_pointer_offset ();
1305
1306   /* We should be able to use regs_ever_live and related prologue
1307      information here, or alpha should not as well.  */
1308   bool return_address_on_stack = cris_return_address_on_stack ();
1309
1310   /* Here we act as if the frame-pointer were needed.  */
1311   int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1312
1313   if (fromreg == ARG_POINTER_REGNUM
1314       && toreg == FRAME_POINTER_REGNUM)
1315     return ap_fp_offset;
1316
1317   /* Between the frame pointer and the stack are only "normal" stack
1318      variables and saved registers.  */
1319   if (fromreg == FRAME_POINTER_REGNUM
1320       && toreg == STACK_POINTER_REGNUM)
1321     return fp_sp_offset;
1322
1323   /* We need to balance out the frame pointer here.  */
1324   if (fromreg == ARG_POINTER_REGNUM
1325       && toreg == STACK_POINTER_REGNUM)
1326     return ap_fp_offset + fp_sp_offset - 4;
1327
1328   gcc_unreachable ();
1329 }
1330
1331 /* Nonzero if X is a hard reg that can be used as an index.  */
1332 static inline bool
1333 reg_ok_for_base_p (const_rtx x, bool strict)
1334 {
1335   return ((! strict && ! HARD_REGISTER_P (x))
1336           || REGNO_OK_FOR_BASE_P (REGNO (x)));
1337 }
1338
1339 /* Nonzero if X is a hard reg that can be used as an index.  */
1340 static inline bool
1341 reg_ok_for_index_p (const_rtx x, bool strict)
1342 {
1343   return reg_ok_for_base_p (x, strict);
1344 }
1345
1346 /* No symbol can be used as an index (or more correct, as a base) together
1347    with a register with PIC; the PIC register must be there.  */
1348
1349 bool
1350 cris_constant_index_p (const_rtx x)
1351 {
1352   return (CONSTANT_P (x) && (!flag_pic || cris_valid_pic_const (x, true)));
1353 }
1354
1355 /* True if X is a valid base register.  */
1356
1357 bool
1358 cris_base_p (const_rtx x, bool strict)
1359 {
1360   return (REG_P (x) && reg_ok_for_base_p (x, strict));
1361 }
1362
1363 /* True if X is a valid index register.  */
1364
1365 static inline bool
1366 cris_index_p (const_rtx x, bool strict)
1367 {
1368   return (REG_P (x) && reg_ok_for_index_p (x, strict));
1369 }
1370
1371 /* True if X is a valid base register with or without autoincrement.  */
1372
1373 bool
1374 cris_base_or_autoincr_p (const_rtx x, bool strict)
1375 {
1376   return (cris_base_p (x, strict)
1377           || (GET_CODE (x) == POST_INC
1378               && cris_base_p (XEXP (x, 0), strict)
1379               && REGNO (XEXP (x, 0)) != CRIS_ACR_REGNUM));
1380 }
1381
1382 /* True if X is a valid (register) index for BDAP, i.e. [Rs].S or [Rs+].S.  */
1383
1384 bool
1385 cris_bdap_index_p (const_rtx x, bool strict)
1386 {
1387   return ((MEM_P (x)
1388            && GET_MODE (x) == SImode
1389            && cris_base_or_autoincr_p (XEXP (x, 0), strict))
1390           || (GET_CODE (x) == SIGN_EXTEND
1391               && MEM_P (XEXP (x, 0))
1392               && (GET_MODE (XEXP (x, 0)) == HImode
1393                   || GET_MODE (XEXP (x, 0)) == QImode)
1394               && cris_base_or_autoincr_p (XEXP (XEXP (x, 0), 0), strict)));
1395 }
1396
1397 /* True if X is a valid (register) index for BIAP, i.e. Rd.m.  */
1398
1399 bool
1400 cris_biap_index_p (const_rtx x, bool strict)
1401 {
1402   return (cris_index_p (x, strict)
1403           || (GET_CODE (x) == MULT
1404               && cris_index_p (XEXP (x, 0), strict)
1405               && cris_scale_int_operand (XEXP (x, 1), VOIDmode)));
1406 }
1407
1408 /* Worker function for TARGET_LEGITIMATE_ADDRESS_P.
1409
1410    A PIC operand looks like a normal symbol here.  At output we dress it
1411    in "[rPIC+symbol:GOT]" (global symbol) or "rPIC+symbol:GOTOFF" (local
1412    symbol) so we exclude all addressing modes where we can't replace a
1413    plain "symbol" with that.  A global PIC symbol does not fit anywhere
1414    here (but is thankfully a general_operand in itself).  A local PIC
1415    symbol is valid for the plain "symbol + offset" case.  */
1416
1417 bool
1418 cris_legitimate_address_p (enum machine_mode mode, rtx x, bool strict)
1419 {
1420   const_rtx x1, x2;
1421
1422   if (cris_base_or_autoincr_p (x, strict))
1423     return true;
1424   else if (TARGET_V32)
1425     /* Nothing else is valid then.  */
1426     return false;
1427   else if (cris_constant_index_p (x))
1428     return true;
1429   /* Indexed?  */
1430   else if (GET_CODE (x) == PLUS)
1431     {
1432       x1 = XEXP (x, 0);
1433       x2 = XEXP (x, 1);
1434       /* BDAP o, Rd.  */
1435       if ((cris_base_p (x1, strict) && cris_constant_index_p (x2))
1436           || (cris_base_p (x2, strict) && cris_constant_index_p (x1))
1437            /* BDAP Rs[+], Rd.  */
1438           || (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
1439               && ((cris_base_p (x1, strict)
1440                    && cris_bdap_index_p (x2, strict))
1441                   || (cris_base_p (x2, strict)
1442                       && cris_bdap_index_p (x1, strict))
1443                   /* BIAP.m Rs, Rd */
1444                   || (cris_base_p (x1, strict)
1445                       && cris_biap_index_p (x2, strict))
1446                   || (cris_base_p (x2, strict)
1447                       && cris_biap_index_p (x1, strict)))))
1448         return true;
1449      }
1450   else if (MEM_P (x))
1451     {
1452       /* DIP (Rs).  Reject [[reg+]] and [[reg]] for DImode (long long).  */
1453       if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
1454           && cris_base_or_autoincr_p (XEXP (x, 0), strict))
1455         return true;
1456     }
1457
1458   return false;
1459 }
1460
1461 /* Worker function for LEGITIMIZE_RELOAD_ADDRESS.  */
1462
1463 bool
1464 cris_reload_address_legitimized (rtx x,
1465                                  enum machine_mode mode ATTRIBUTE_UNUSED,
1466                                  int opnum ATTRIBUTE_UNUSED,
1467                                  int itype,
1468                                  int ind_levels ATTRIBUTE_UNUSED)
1469 {
1470   enum reload_type type = (enum reload_type) itype;
1471   rtx op0, op1;
1472   rtx *op1p;
1473
1474   if (GET_CODE (x) != PLUS)
1475     return false;
1476
1477   if (TARGET_V32)
1478     return false;
1479
1480   op0 = XEXP (x, 0);
1481   op1 = XEXP (x, 1);
1482   op1p = &XEXP (x, 1);
1483
1484   if (!REG_P (op1))
1485     return false;
1486
1487   if (GET_CODE (op0) == SIGN_EXTEND && MEM_P (XEXP (op0, 0)))
1488     {
1489       rtx op00 = XEXP (op0, 0);
1490       rtx op000 = XEXP (op00, 0);
1491       rtx *op000p = &XEXP (op00, 0);
1492
1493       if ((GET_MODE (op00) == HImode || GET_MODE (op00) == QImode)
1494           && (REG_P (op000)
1495               || (GET_CODE (op000) == POST_INC && REG_P (XEXP (op000, 0)))))
1496         {
1497           bool something_reloaded = false;
1498
1499           if (GET_CODE (op000) == POST_INC
1500               && REG_P (XEXP (op000, 0))
1501               && REGNO (XEXP (op000, 0)) > CRIS_LAST_GENERAL_REGISTER)
1502             /* No, this gets too complicated and is too rare to care
1503                about trying to improve on the general code Here.
1504                As the return-value is an all-or-nothing indicator, we
1505                punt on the other register too.  */
1506             return false;
1507
1508           if ((REG_P (op000)
1509                && REGNO (op000) > CRIS_LAST_GENERAL_REGISTER))
1510             {
1511               /* The address of the inner mem is a pseudo or wrong
1512                  reg: reload that.  */
1513               push_reload (op000, NULL_RTX, op000p, NULL, GENERAL_REGS,
1514                            GET_MODE (x), VOIDmode, 0, 0, opnum, type);
1515               something_reloaded = true;
1516             }
1517
1518           if (REGNO (op1) > CRIS_LAST_GENERAL_REGISTER)
1519             {
1520               /* Base register is a pseudo or wrong reg: reload it.  */
1521               push_reload (op1, NULL_RTX, op1p, NULL, GENERAL_REGS,
1522                            GET_MODE (x), VOIDmode, 0, 0,
1523                            opnum, type);
1524               something_reloaded = true;
1525             }
1526
1527           gcc_assert (something_reloaded);
1528
1529           return true;
1530         }
1531     }
1532
1533   return false;
1534 }
1535
1536
1537 /* Worker function for TARGET_PREFERRED_RELOAD_CLASS.
1538
1539    It seems like gcc (2.7.2 and 2.9x of 2000-03-22) may send "NO_REGS" as
1540    the class for a constant (testcase: __Mul in arit.c).  To avoid forcing
1541    out a constant into the constant pool, we will trap this case and
1542    return something a bit more sane.  FIXME: Check if this is a bug.
1543    Beware that we must not "override" classes that can be specified as
1544    constraint letters, or else asm operands using them will fail when
1545    they need to be reloaded.  FIXME: Investigate whether that constitutes
1546    a bug.  */
1547
1548 static reg_class_t
1549 cris_preferred_reload_class (rtx x ATTRIBUTE_UNUSED, reg_class_t rclass)
1550 {
1551   if (rclass != ACR_REGS
1552       && rclass != MOF_REGS
1553       && rclass != MOF_SRP_REGS
1554       && rclass != SRP_REGS
1555       && rclass != CC0_REGS
1556       && rclass != SPECIAL_REGS)
1557     return GENERAL_REGS;
1558
1559   return rclass;
1560 }
1561
1562 /* Worker function for TARGET_REGISTER_MOVE_COST.  */
1563
1564 static int
1565 cris_register_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
1566                          reg_class_t from, reg_class_t to)
1567 {
1568   /* Can't move to and from a SPECIAL_REGS register, so we have to say
1569      their move cost within that class is higher.  How about 7?  That's 3
1570      for a move to a GENERAL_REGS register, 3 for the move from the
1571      GENERAL_REGS register, and 1 for the increased register pressure.
1572      Also, it's higher than the memory move cost, as it should.
1573      We also do this for ALL_REGS, since we don't want that class to be
1574      preferred (even to memory) at all where GENERAL_REGS doesn't fit.
1575      Whenever it's about to be used, it's for SPECIAL_REGS.  If we don't
1576      present a higher cost for ALL_REGS than memory, a SPECIAL_REGS may be
1577      used when a GENERAL_REGS should be used, even if there are call-saved
1578      GENERAL_REGS left to allocate.  This is because the fall-back when
1579      the most preferred register class isn't available, isn't the next
1580      (or next good) wider register class, but the *most widest* register
1581      class.  FIXME: pre-IRA comment, perhaps obsolete now.  */
1582
1583   if ((reg_classes_intersect_p (from, SPECIAL_REGS)
1584        && reg_classes_intersect_p (to, SPECIAL_REGS))
1585       || from == ALL_REGS || to == ALL_REGS)
1586     return 7;
1587
1588   /* Make moves to/from SPECIAL_REGS slightly more expensive, as we
1589      generally prefer GENERAL_REGS.  */
1590   if (reg_classes_intersect_p (from, SPECIAL_REGS)
1591       || reg_classes_intersect_p (to, SPECIAL_REGS))
1592     return 3;
1593
1594   return 2;
1595 }
1596
1597 /* Worker function for TARGET_MEMORY_MOVE_COST.
1598
1599    This isn't strictly correct for v0..3 in buswidth-8bit mode, but should
1600    suffice.  */
1601
1602 static int
1603 cris_memory_move_cost (enum machine_mode mode,
1604                        reg_class_t rclass ATTRIBUTE_UNUSED,
1605                        bool in ATTRIBUTE_UNUSED)
1606 {
1607   if (mode == QImode
1608       || mode == HImode)
1609     return 4;
1610   else
1611     return 6;
1612 }
1613
1614 /* Worker for cris_notice_update_cc; handles the "normal" cases.
1615    FIXME: this code is historical; its functionality should be
1616    refactored to look at insn attributes and moved to
1617    cris_notice_update_cc.  Except, we better lose cc0 entirely.  */
1618
1619 static void
1620 cris_normal_notice_update_cc (rtx exp, rtx insn)
1621 {
1622   /* "Normal" means, for:
1623      (set (cc0) (...)):
1624      CC is (...).
1625
1626      (set (reg) (...)):
1627      CC is (reg) and (...) - unless (...) is 0 or reg is a special
1628         register or (v32 and (...) is -32..-1), then CC does not change.
1629      CC_NO_OVERFLOW unless (...) is reg or mem.
1630
1631      (set (mem) (...)):
1632      CC does not change.
1633
1634      (set (pc) (...)):
1635      CC does not change.
1636
1637      (parallel
1638       (set (reg1) (mem (bdap/biap)))
1639       (set (reg2) (bdap/biap))):
1640      CC is (reg1) and (mem (reg2))
1641
1642      (parallel
1643       (set (mem (bdap/biap)) (reg1)) [or 0]
1644       (set (reg2) (bdap/biap))):
1645      CC does not change.
1646
1647      (where reg and mem includes strict_low_parts variants thereof)
1648
1649      For all others, assume CC is clobbered.
1650      Note that we do not have to care about setting CC_NO_OVERFLOW,
1651      since the overflow flag is set to 0 (i.e. right) for
1652      instructions where it does not have any sane sense, but where
1653      other flags have meanings.  (This includes shifts; the carry is
1654      not set by them).
1655
1656      Note that there are other parallel constructs we could match,
1657      but we don't do that yet.  */
1658
1659   if (GET_CODE (exp) == SET)
1660     {
1661       /* FIXME: Check when this happens.  It looks like we should
1662          actually do a CC_STATUS_INIT here to be safe.  */
1663       if (SET_DEST (exp) == pc_rtx)
1664         return;
1665
1666       /* Record CC0 changes, so we do not have to output multiple
1667          test insns.  */
1668       if (SET_DEST (exp) == cc0_rtx)
1669         {
1670           CC_STATUS_INIT;
1671
1672           if (GET_CODE (SET_SRC (exp)) == COMPARE
1673               && XEXP (SET_SRC (exp), 1) == const0_rtx)
1674             cc_status.value1 = XEXP (SET_SRC (exp), 0);
1675           else
1676             cc_status.value1 = SET_SRC (exp);
1677
1678           /* Handle flags for the special btstq on one bit.  */
1679           if (GET_CODE (cc_status.value1) == ZERO_EXTRACT
1680               && XEXP (cc_status.value1, 1) == const1_rtx)
1681             {
1682               if (CONST_INT_P (XEXP (cc_status.value1, 0)))
1683                 /* Using cmpq.  */
1684                 cc_status.flags = CC_INVERTED;
1685               else
1686                 /* A one-bit btstq.  */
1687                 cc_status.flags = CC_Z_IN_NOT_N;
1688             }
1689
1690           else if (GET_CODE (SET_SRC (exp)) == COMPARE)
1691             {
1692               if (!REG_P (XEXP (SET_SRC (exp), 0))
1693                   && XEXP (SET_SRC (exp), 1) != const0_rtx)
1694                 /* For some reason gcc will not canonicalize compare
1695                    operations, reversing the sign by itself if
1696                    operands are in wrong order.  */
1697                 /* (But NOT inverted; eq is still eq.) */
1698                 cc_status.flags = CC_REVERSED;
1699
1700               /* This seems to be overlooked by gcc.  FIXME: Check again.
1701                  FIXME:  Is it really safe?  */
1702               cc_status.value2
1703                 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1704                                  XEXP (SET_SRC (exp), 0),
1705                                  XEXP (SET_SRC (exp), 1));
1706             }
1707           return;
1708         }
1709       else if (REG_P (SET_DEST (exp))
1710                || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1711                    && REG_P (XEXP (SET_DEST (exp), 0))))
1712         {
1713           /* A register is set; normally CC is set to show that no
1714              test insn is needed.  Catch the exceptions.  */
1715
1716           /* If not to cc0, then no "set"s in non-natural mode give
1717              ok cc0...  */
1718           if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1719               || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1720             {
1721               /* ... except add:s and sub:s in DImode.  */
1722               if (GET_MODE (SET_DEST (exp)) == DImode
1723                   && (GET_CODE (SET_SRC (exp)) == PLUS
1724                       || GET_CODE (SET_SRC (exp)) == MINUS))
1725                 {
1726                   CC_STATUS_INIT;
1727                   cc_status.value1 = SET_DEST (exp);
1728                   cc_status.value2 = SET_SRC (exp);
1729
1730                   if (cris_reg_overlap_mentioned_p (cc_status.value1,
1731                                                     cc_status.value2))
1732                     cc_status.value2 = 0;
1733
1734                   /* Add and sub may set V, which gets us
1735                      unoptimizable results in "gt" and "le" condition
1736                      codes.  */
1737                   cc_status.flags |= CC_NO_OVERFLOW;
1738
1739                   return;
1740                 }
1741             }
1742           else if (SET_SRC (exp) == const0_rtx
1743                    || (REG_P (SET_SRC (exp))
1744                        && (REGNO (SET_SRC (exp))
1745                            > CRIS_LAST_GENERAL_REGISTER))
1746                    || (TARGET_V32
1747                        && REG_P (SET_DEST (exp))
1748                        && satisfies_constraint_I (SET_SRC (exp))))
1749             {
1750               /* There's no CC0 change for this case.  Just check
1751                  for overlap.  */
1752               if (cc_status.value1
1753                   && modified_in_p (cc_status.value1, insn))
1754                 cc_status.value1 = 0;
1755
1756               if (cc_status.value2
1757                   && modified_in_p (cc_status.value2, insn))
1758                 cc_status.value2 = 0;
1759
1760               return;
1761             }
1762           else
1763             {
1764               CC_STATUS_INIT;
1765               cc_status.value1 = SET_DEST (exp);
1766               cc_status.value2 = SET_SRC (exp);
1767
1768               if (cris_reg_overlap_mentioned_p (cc_status.value1,
1769                                                 cc_status.value2))
1770                 cc_status.value2 = 0;
1771
1772               /* Some operations may set V, which gets us
1773                  unoptimizable results in "gt" and "le" condition
1774                  codes.  */
1775               if (GET_CODE (SET_SRC (exp)) == PLUS
1776                   || GET_CODE (SET_SRC (exp)) == MINUS
1777                   || GET_CODE (SET_SRC (exp)) == NEG)
1778                 cc_status.flags |= CC_NO_OVERFLOW;
1779
1780               /* For V32, nothing with a register destination sets
1781                  C and V usefully.  */
1782               if (TARGET_V32)
1783                 cc_status.flags |= CC_NO_OVERFLOW;
1784
1785               return;
1786             }
1787         }
1788       else if (MEM_P (SET_DEST (exp))
1789                || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1790                    && MEM_P (XEXP (SET_DEST (exp), 0))))
1791         {
1792           /* When SET to MEM, then CC is not changed (except for
1793              overlap).  */
1794           if (cc_status.value1
1795               && modified_in_p (cc_status.value1, insn))
1796             cc_status.value1 = 0;
1797
1798           if (cc_status.value2
1799               && modified_in_p (cc_status.value2, insn))
1800             cc_status.value2 = 0;
1801
1802           return;
1803         }
1804     }
1805   else if (GET_CODE (exp) == PARALLEL)
1806     {
1807       if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1808           && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1809           && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1810         {
1811           if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1812               && MEM_P (XEXP (XVECEXP (exp, 0, 0), 1)))
1813             {
1814               CC_STATUS_INIT;
1815
1816               /* For "move.S [rx=ry+o],rz", say CC reflects
1817                  value1=rz and value2=[rx] */
1818               cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1819               cc_status.value2
1820                 = replace_equiv_address (XEXP (XVECEXP (exp, 0, 0), 1),
1821                                          XEXP (XVECEXP (exp, 0, 1), 0));
1822
1823               /* Huh?  A side-effect cannot change the destination
1824                  register.  */
1825               if (cris_reg_overlap_mentioned_p (cc_status.value1,
1826                                                 cc_status.value2))
1827                 internal_error ("internal error: sideeffect-insn affecting main effect");
1828
1829               /* For V32, moves to registers don't set C and V.  */
1830               if (TARGET_V32)
1831                 cc_status.flags |= CC_NO_OVERFLOW;
1832               return;
1833             }
1834           else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1835                     || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1836                    && MEM_P (XEXP (XVECEXP (exp, 0, 0), 0)))
1837             {
1838               /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1839                  say flags are not changed, except for overlap.  */
1840               if (cc_status.value1
1841                   && modified_in_p (cc_status.value1, insn))
1842                 cc_status.value1 = 0;
1843
1844               if (cc_status.value2
1845                   && modified_in_p (cc_status.value2, insn))
1846                 cc_status.value2 = 0;
1847
1848               return;
1849             }
1850         }
1851     }
1852
1853   /* If we got here, the case wasn't covered by the code above.  */
1854   CC_STATUS_INIT;
1855 }
1856
1857 /*  This function looks into the pattern to see how this insn affects
1858     condition codes.
1859
1860     Used when to eliminate test insns before a condition-code user,
1861     such as a "scc" insn or a conditional branch.  This includes
1862     checking if the entities that cc was updated by, are changed by the
1863     operation.
1864
1865     Currently a jumble of the old peek-inside-the-insn and the newer
1866     check-cc-attribute methods.  */
1867
1868 void
1869 cris_notice_update_cc (rtx exp, rtx insn)
1870 {
1871   enum attr_cc attrval = get_attr_cc (insn);
1872
1873   /* Check if user specified "-mcc-init" as a bug-workaround.  Remember
1874      to still set CC_REVERSED as below, since that's required by some
1875      compare insn alternatives.  (FIXME: GCC should do this virtual
1876      operand swap by itself.)  A test-case that may otherwise fail is
1877      gcc.c-torture/execute/20000217-1.c -O0 and -O1.  */
1878   if (TARGET_CCINIT)
1879     {
1880       CC_STATUS_INIT;
1881
1882       if (attrval == CC_REV)
1883         cc_status.flags = CC_REVERSED;
1884       return;
1885     }
1886
1887   /* Slowly, we're converting to using attributes to control the setting
1888      of condition-code status.  */
1889   switch (attrval)
1890     {
1891     case CC_NONE:
1892       /* Even if it is "none", a setting may clobber a previous
1893          cc-value, so check.  */
1894       if (GET_CODE (exp) == SET)
1895         {
1896           if (cc_status.value1
1897               && modified_in_p (cc_status.value1, insn))
1898             cc_status.value1 = 0;
1899
1900           if (cc_status.value2
1901               && modified_in_p (cc_status.value2, insn))
1902             cc_status.value2 = 0;
1903         }
1904       return;
1905
1906     case CC_CLOBBER:
1907       CC_STATUS_INIT;
1908       return;
1909
1910     case CC_REV:
1911     case CC_NOOV32:
1912     case CC_NORMAL:
1913       cris_normal_notice_update_cc (exp, insn);
1914
1915       /* The "test" insn doesn't clear (carry and) overflow on V32.  We
1916         can change bge => bpl and blt => bmi by passing on to the cc0
1917         user that V should not be considered; bgt and ble are taken
1918         care of by other methods (see {tst,cmp}{si,hi,qi}).  */
1919       if (attrval == CC_NOOV32 && TARGET_V32)
1920         cc_status.flags |= CC_NO_OVERFLOW;
1921       return;
1922
1923     default:
1924       internal_error ("unknown cc_attr value");
1925     }
1926
1927   CC_STATUS_INIT;
1928 }
1929
1930 /* Return != 0 if the return sequence for the current function is short,
1931    like "ret" or "jump [sp+]".  Prior to reloading, we can't tell if
1932    registers must be saved, so return 0 then.  */
1933
1934 bool
1935 cris_simple_epilogue (void)
1936 {
1937   unsigned int regno;
1938   unsigned int reglimit = STACK_POINTER_REGNUM;
1939   bool got_really_used = false;
1940
1941   if (! reload_completed
1942       || frame_pointer_needed
1943       || get_frame_size () != 0
1944       || crtl->args.pretend_args_size
1945       || crtl->args.size
1946       || crtl->outgoing_args_size
1947       || crtl->calls_eh_return
1948
1949       /* If we're not supposed to emit prologue and epilogue, we must
1950          not emit return-type instructions.  */
1951       || !TARGET_PROLOGUE_EPILOGUE)
1952     return false;
1953
1954   /* Can't return from stacked return address with v32.  */
1955   if (TARGET_V32 && cris_return_address_on_stack ())
1956     return false;
1957
1958   if (crtl->uses_pic_offset_table)
1959     {
1960       push_topmost_sequence ();
1961       got_really_used
1962         = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
1963       pop_topmost_sequence ();
1964     }
1965
1966   /* No simple epilogue if there are saved registers.  */
1967   for (regno = 0; regno < reglimit; regno++)
1968     if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1969       return false;
1970
1971   return true;
1972 }
1973
1974 /* Emit checking that MEM is aligned for an access in MODE, failing
1975    that, executing a "break 8" (or call to abort, if "break 8" is
1976    disabled).  */
1977
1978 void
1979 cris_emit_trap_for_misalignment (rtx mem)
1980 {
1981   rtx addr, reg, ok_label, andop, jmp;
1982   int natural_alignment;
1983   gcc_assert (MEM_P (mem));
1984
1985   natural_alignment = GET_MODE_SIZE (GET_MODE (mem));
1986   addr = XEXP (mem, 0);
1987   reg = force_reg (Pmode, addr);
1988   ok_label = gen_label_rtx ();
1989
1990   /* This will yield a btstq without a separate register used, usually -
1991      with the exception for PRE hoisting the "and" but not the branch
1992      around the trap: see gcc.dg/target/cris/sync-3s.c.  */
1993   andop = gen_rtx_AND (Pmode, reg, GEN_INT (natural_alignment - 1));
1994   emit_cmp_and_jump_insns (force_reg (SImode, andop), const0_rtx, EQ,
1995                            NULL_RTX, Pmode, 1, ok_label);
1996   jmp = get_last_insn ();
1997   gcc_assert (JUMP_P (jmp));
1998
1999   /* While this isn't mudflap, it is a similar kind of assertion.
2000      If PRED_MUDFLAP stops working, use something else or introduce a
2001      more suitable assertion predication type.  */
2002   predict_insn_def (jmp, PRED_MUDFLAP, TAKEN);
2003   expand_builtin_trap ();
2004   emit_label (ok_label);
2005 }
2006
2007 /* Expand a return insn (just one insn) marked as using SRP or stack
2008    slot depending on parameter ON_STACK.  */
2009
2010 void
2011 cris_expand_return (bool on_stack)
2012 {
2013   /* FIXME: emit a parallel with a USE for SRP or the stack-slot, to
2014      tell "ret" from "jump [sp+]".  Some, but not all, other parts of
2015      GCC expect just (return) to do the right thing when optimizing, so
2016      we do that until they're fixed.  Currently, all return insns in a
2017      function must be the same (not really a limiting factor) so we need
2018      to check that it doesn't change half-way through.  */
2019   emit_jump_insn (ret_rtx);
2020
2021   CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack);
2022   CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack);
2023
2024   cfun->machine->return_type
2025     = on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET;
2026 }
2027
2028 /* Compute a (partial) cost for rtx X.  Return true if the complete
2029    cost has been computed, and false if subexpressions should be
2030    scanned.  In either case, *TOTAL contains the cost result.  */
2031
2032 static bool
2033 cris_rtx_costs (rtx x, int code, int outer_code, int opno, int *total,
2034                 bool speed)
2035 {
2036   switch (code)
2037     {
2038     case CONST_INT:
2039       {
2040         HOST_WIDE_INT val = INTVAL (x);
2041         if (val == 0)
2042           *total = 0;
2043         else if (val < 32 && val >= -32)
2044           *total = 1;
2045         /* Eight or 16 bits are a word and cycle more expensive.  */
2046         else if (val <= 32767 && val >= -32768)
2047           *total = 2;
2048         /* A 32-bit constant (or very seldom, unsigned 16 bits) costs
2049            another word.  FIXME: This isn't linear to 16 bits.  */
2050         else
2051           *total = 4;
2052         return true;
2053       }
2054
2055     case LABEL_REF:
2056       *total = 6;
2057       return true;
2058
2059     case CONST:
2060     case SYMBOL_REF:
2061       *total = 6;
2062       return true;
2063
2064     case CONST_DOUBLE:
2065       if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
2066         *total = 12;
2067       else
2068         /* Make 0.0 cheap, else test-insns will not be used.  */
2069         *total = 0;
2070       return true;
2071
2072     case MULT:
2073       /* If we have one arm of an ADDI, make sure it gets the cost of
2074          one insn, i.e. zero cost for this operand, and just the cost
2075          of the PLUS, as the insn is created by combine from a PLUS
2076          and an ASHIFT, and the MULT cost below would make the
2077          combined value be larger than the separate insns.  The insn
2078          validity is checked elsewhere by combine.
2079
2080          FIXME: this case is a stop-gap for 4.3 and 4.4, this whole
2081          function should be rewritten.  */
2082       if (outer_code == PLUS && cris_biap_index_p (x, false))
2083         {
2084           *total = 0;
2085           return true;
2086         }
2087
2088       /* Identify values that are no powers of two.  Powers of 2 are
2089          taken care of already and those values should not be changed.  */
2090       if (!CONST_INT_P (XEXP (x, 1))
2091           || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
2092         {
2093           /* If we have a multiply insn, then the cost is between
2094              1 and 2 "fast" instructions.  */
2095           if (TARGET_HAS_MUL_INSNS)
2096             {
2097               *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
2098               return true;
2099             }
2100
2101           /* Estimate as 4 + 4 * #ofbits.  */
2102           *total = COSTS_N_INSNS (132);
2103           return true;
2104         }
2105       return false;
2106
2107     case UDIV:
2108     case MOD:
2109     case UMOD:
2110     case DIV:
2111       if (!CONST_INT_P (XEXP (x, 1))
2112           || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
2113         {
2114           /* Estimate this as 4 + 8 * #of bits.  */
2115           *total = COSTS_N_INSNS (260);
2116           return true;
2117         }
2118       return false;
2119
2120     case AND:
2121       if (CONST_INT_P (XEXP (x, 1))
2122           /* Two constants may actually happen before optimization.  */
2123           && !CONST_INT_P (XEXP (x, 0))
2124           && !satisfies_constraint_I (XEXP (x, 1)))
2125         {
2126           *total
2127             = (rtx_cost (XEXP (x, 0), (enum rtx_code) outer_code,
2128                          opno, speed) + 2
2129                + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
2130           return true;
2131         }
2132       return false;
2133
2134     case ZERO_EXTRACT:
2135       if (outer_code != COMPARE)
2136         return false;
2137       /* fall through */
2138
2139     case ZERO_EXTEND: case SIGN_EXTEND:
2140       *total = rtx_cost (XEXP (x, 0), (enum rtx_code) outer_code, opno, speed);
2141       return true;
2142
2143     default:
2144       return false;
2145     }
2146 }
2147
2148 /* The ADDRESS_COST worker.  */
2149
2150 static int
2151 cris_address_cost (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED,
2152                    addr_space_t as ATTRIBUTE_UNUSED,
2153                    bool speed ATTRIBUTE_UNUSED)
2154 {
2155   /* The metric to use for the cost-macros is unclear.
2156      The metric used here is (the number of cycles needed) / 2,
2157      where we consider equal a cycle for a word of code and a cycle to
2158      read memory.  FIXME: Adding "+ 1" to all values would avoid
2159      returning 0, as tree-ssa-loop-ivopts.c as of r128272 "normalizes"
2160      0 to 1, thereby giving equal costs to [rN + rM] and [rN].
2161      Unfortunately(?) such a hack would expose other pessimizations,
2162      at least with g++.dg/tree-ssa/ivopts-1.C, adding insns to the
2163      loop there, without apparent reason.  */
2164
2165   /* The cheapest addressing modes get 0, since nothing extra is needed.  */
2166   if (cris_base_or_autoincr_p (x, false))
2167     return 0;
2168
2169   /* An indirect mem must be a DIP.  This means two bytes extra for code,
2170      and 4 bytes extra for memory read, i.e.  (2 + 4) / 2.  */
2171   if (MEM_P (x))
2172     return (2 + 4) / 2;
2173
2174   /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
2175      an extra DIP prefix and 4 bytes of constant in most cases.  */
2176   if (CONSTANT_P (x))
2177     return (2 + 4) / 2;
2178
2179   /* Handle BIAP and BDAP prefixes.  */
2180   if (GET_CODE (x) == PLUS)
2181     {
2182       rtx tem1 = XEXP (x, 0);
2183       rtx tem2 = XEXP (x, 1);
2184
2185       /* Local extended canonicalization rule: the first operand must
2186          be REG, unless it's an operation (MULT).  */
2187       if (!REG_P (tem1) && GET_CODE (tem1) != MULT)
2188         tem1 = tem2, tem2 = XEXP (x, 0);
2189
2190       /* We'll "assume" we have canonical RTX now.  */
2191       gcc_assert (REG_P (tem1) || GET_CODE (tem1) == MULT);
2192
2193       /* A BIAP is 2 extra bytes for the prefix insn, nothing more.  We
2194          recognize the typical MULT which is always in tem1 because of
2195          insn canonicalization.  */
2196       if ((GET_CODE (tem1) == MULT && cris_biap_index_p (tem1, false))
2197           || REG_P (tem2))
2198         return 2 / 2;
2199
2200       /* A BDAP (quick) is 2 extra bytes.  Any constant operand to the
2201          PLUS is always found in tem2.  */
2202       if (CONST_INT_P (tem2) && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
2203         return 2 / 2;
2204
2205       /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
2206          bytes.  */
2207       if (satisfies_constraint_L (tem2))
2208         return (2 + 2) / 2;
2209
2210       /* A BDAP with some other constant is 2 bytes extra.  */
2211       if (CONSTANT_P (tem2))
2212         return (2 + 2 + 2) / 2;
2213
2214       /* BDAP with something indirect should have a higher cost than
2215          BIAP with register.   FIXME: Should it cost like a MEM or more?  */
2216       return (2 + 2 + 2) / 2;
2217     }
2218
2219   /* What else?  Return a high cost.  It matters only for valid
2220      addressing modes.  */
2221   return 10;
2222 }
2223
2224 /* Check various objections to the side-effect.  Used in the test-part
2225    of an anonymous insn describing an insn with a possible side-effect.
2226    Returns nonzero if the implied side-effect is ok.
2227
2228    code     : PLUS or MULT
2229    ops      : An array of rtx:es. lreg, rreg, rval,
2230               The variables multop and other_op are indexes into this,
2231               or -1 if they are not applicable.
2232    lreg     : The register that gets assigned in the side-effect.
2233    rreg     : One register in the side-effect expression
2234    rval     : The other register, or an int.
2235    multop   : An integer to multiply rval with.
2236    other_op : One of the entities of the main effect,
2237               whose mode we must consider.  */
2238
2239 int
2240 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
2241                           int lreg, int rreg, int rval,
2242                           int multop, int other_op)
2243 {
2244   /* Find what value to multiply with, for rx =ry + rz * n.  */
2245   int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
2246
2247   rtx reg_rtx = ops[rreg];
2248   rtx val_rtx = ops[rval];
2249
2250   /* The operands may be swapped.  Canonicalize them in reg_rtx and
2251      val_rtx, where reg_rtx always is a reg (for this constraint to
2252      match).  */
2253   if (! cris_base_p (reg_rtx, reload_in_progress || reload_completed))
2254     reg_rtx = val_rtx, val_rtx = ops[rreg];
2255
2256   /* Don't forget to check that reg_rtx really is a reg.  If it isn't,
2257      we have no business.  */
2258   if (! cris_base_p (reg_rtx, reload_in_progress || reload_completed))
2259     return 0;
2260
2261   /* Don't do this when -mno-split.  */
2262   if (!TARGET_SIDE_EFFECT_PREFIXES)
2263     return 0;
2264
2265   /* The mult expression may be hidden in lreg.  FIXME:  Add more
2266      commentary about that.  */
2267   if (GET_CODE (val_rtx) == MULT)
2268     {
2269       mult = INTVAL (XEXP (val_rtx, 1));
2270       val_rtx = XEXP (val_rtx, 0);
2271       code = MULT;
2272     }
2273
2274   /* First check the "other operand".  */
2275   if (other_op >= 0)
2276     {
2277       if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2278         return 0;
2279
2280       /* Check if the lvalue register is the same as the "other
2281          operand".  If so, the result is undefined and we shouldn't do
2282          this.  FIXME:  Check again.  */
2283       if ((cris_base_p (ops[lreg], reload_in_progress || reload_completed)
2284            && cris_base_p (ops[other_op],
2285                            reload_in_progress || reload_completed)
2286            && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2287           || rtx_equal_p (ops[other_op], ops[lreg]))
2288       return 0;
2289     }
2290
2291   /* Do not accept frame_pointer_rtx as any operand.  */
2292   if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2293       || ops[rval] == frame_pointer_rtx
2294       || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2295     return 0;
2296
2297   if (code == PLUS
2298       && ! cris_base_p (val_rtx, reload_in_progress || reload_completed))
2299     {
2300
2301       /* Do not allow rx = rx + n if a normal add or sub with same size
2302          would do.  */
2303       if (rtx_equal_p (ops[lreg], reg_rtx)
2304           && CONST_INT_P (val_rtx)
2305           && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2306         return 0;
2307
2308       /* Check allowed cases, like [r(+)?].[bwd] and const.  */
2309       if (CONSTANT_P (val_rtx))
2310         return 1;
2311
2312       if (MEM_P (val_rtx)
2313           && cris_base_or_autoincr_p (XEXP (val_rtx, 0),
2314                                       reload_in_progress || reload_completed))
2315         return 1;
2316
2317       if (GET_CODE (val_rtx) == SIGN_EXTEND
2318           && MEM_P (XEXP (val_rtx, 0))
2319           && cris_base_or_autoincr_p (XEXP (XEXP (val_rtx, 0), 0),
2320                                       reload_in_progress || reload_completed))
2321         return 1;
2322
2323       /* If we got here, it's not a valid addressing mode.  */
2324       return 0;
2325     }
2326   else if (code == MULT
2327            || (code == PLUS
2328                && cris_base_p (val_rtx,
2329                                reload_in_progress || reload_completed)))
2330     {
2331       /* Do not allow rx = rx + ry.S, since it doesn't give better code.  */
2332       if (rtx_equal_p (ops[lreg], reg_rtx)
2333           || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2334         return 0;
2335
2336       /* Do not allow bad multiply-values.  */
2337       if (mult != 1 && mult != 2 && mult != 4)
2338         return 0;
2339
2340       /* Only allow  r + ...  */
2341       if (! cris_base_p (reg_rtx, reload_in_progress || reload_completed))
2342         return 0;
2343
2344       /* If we got here, all seems ok.
2345          (All checks need to be done above).  */
2346       return 1;
2347     }
2348
2349   /* If we get here, the caller got its initial tests wrong.  */
2350   internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2351 }
2352
2353 /* Whether next_cc0_user of insn is LE or GT or requires a real compare
2354    insn for other reasons.  */
2355
2356 bool
2357 cris_cc0_user_requires_cmp (rtx insn)
2358 {
2359   rtx cc0_user = NULL;
2360   rtx body;
2361   rtx set;
2362
2363   gcc_assert (insn != NULL);
2364
2365   if (!TARGET_V32)
2366     return false;
2367
2368   cc0_user = next_cc0_user (insn);
2369   if (cc0_user == NULL)
2370     return false;
2371
2372   body = PATTERN (cc0_user);
2373   set = single_set (cc0_user);
2374
2375   /* Users can be sCC and bCC.  */
2376   if (JUMP_P (cc0_user)
2377       && GET_CODE (body) == SET
2378       && SET_DEST (body) == pc_rtx
2379       && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
2380       && XEXP (XEXP (SET_SRC (body), 0), 0) == cc0_rtx)
2381     {
2382       return
2383         GET_CODE (XEXP (SET_SRC (body), 0)) == GT
2384         || GET_CODE (XEXP (SET_SRC (body), 0)) == LE;
2385     }
2386   else if (set)
2387     {
2388       return
2389         GET_CODE (SET_SRC (body)) == GT
2390         || GET_CODE (SET_SRC (body)) == LE;
2391     }
2392
2393   gcc_unreachable ();
2394 }
2395
2396 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2397    does not handle the case where the IN operand is strict_low_part; it
2398    does handle it for X.  Test-case in Axis-20010516.  This function takes
2399    care of that for THIS port.  FIXME: strict_low_part is going away
2400    anyway.  */
2401
2402 static int
2403 cris_reg_overlap_mentioned_p (rtx x, rtx in)
2404 {
2405   /* The function reg_overlap_mentioned now handles when X is
2406      strict_low_part, but not when IN is a STRICT_LOW_PART.  */
2407   if (GET_CODE (in) == STRICT_LOW_PART)
2408     in = XEXP (in, 0);
2409
2410   return reg_overlap_mentioned_p (x, in);
2411 }
2412
2413 /* Return TRUE iff X is a CONST valid for e.g. indexing.
2414    ANY_OPERAND is 0 if X is in a CALL_P insn or movsi, 1
2415    elsewhere.  */
2416
2417 bool
2418 cris_valid_pic_const (const_rtx x, bool any_operand)
2419 {
2420   gcc_assert (flag_pic);
2421
2422   switch (GET_CODE (x))
2423     {
2424     case CONST_INT:
2425     case CONST_DOUBLE:
2426       return true;
2427     default:
2428       ;
2429     }
2430
2431   if (GET_CODE (x) != CONST)
2432     return false;
2433
2434   x = XEXP (x, 0);
2435
2436   /* Handle (const (plus (unspec .. UNSPEC_GOTREL) (const_int ...))).  */
2437   if (GET_CODE (x) == PLUS
2438       && GET_CODE (XEXP (x, 0)) == UNSPEC
2439       && (XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREL
2440           || XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_PCREL)
2441       && CONST_INT_P (XEXP (x, 1)))
2442     x = XEXP (x, 0);
2443
2444   if (GET_CODE (x) == UNSPEC)
2445     switch (XINT (x, 1))
2446       {
2447         /* A PCREL operand is only valid for call and movsi.  */
2448       case CRIS_UNSPEC_PLT_PCREL:
2449       case CRIS_UNSPEC_PCREL:
2450         return !any_operand;
2451
2452       case CRIS_UNSPEC_PLT_GOTREL:
2453       case CRIS_UNSPEC_PLTGOTREAD:
2454       case CRIS_UNSPEC_GOTREAD:
2455       case CRIS_UNSPEC_GOTREL:
2456         return true;
2457       default:
2458         gcc_unreachable ();
2459       }
2460
2461   return cris_pic_symbol_type_of (x) == cris_no_symbol;
2462 }
2463
2464 /* Helper function to find the right PIC-type symbol to generate,
2465    given the original (non-PIC) representation.  */
2466
2467 enum cris_pic_symbol_type
2468 cris_pic_symbol_type_of (const_rtx x)
2469 {
2470   switch (GET_CODE (x))
2471     {
2472     case SYMBOL_REF:
2473       return SYMBOL_REF_LOCAL_P (x)
2474         ? cris_rel_symbol : cris_got_symbol;
2475
2476     case LABEL_REF:
2477       return cris_rel_symbol;
2478
2479     case CONST:
2480       return cris_pic_symbol_type_of (XEXP (x, 0));
2481
2482     case PLUS:
2483     case MINUS:
2484       {
2485         enum cris_pic_symbol_type t1 = cris_pic_symbol_type_of (XEXP (x, 0));
2486         enum cris_pic_symbol_type t2 = cris_pic_symbol_type_of (XEXP (x, 1));
2487
2488         gcc_assert (t1 == cris_no_symbol || t2 == cris_no_symbol);
2489
2490         if (t1 == cris_got_symbol || t1 == cris_got_symbol)
2491           return cris_got_symbol_needing_fixup;
2492
2493         return t1 != cris_no_symbol ? t1 : t2;
2494       }
2495
2496     case CONST_INT:
2497     case CONST_DOUBLE:
2498       return cris_no_symbol;
2499
2500     case UNSPEC:
2501       /* Likely an offsettability-test attempting to add a constant to
2502          a GOTREAD symbol, which can't be handled.  */
2503       return cris_invalid_pic_symbol;
2504
2505     default:
2506       fatal_insn ("unrecognized supposed constant", x);
2507     }
2508
2509   gcc_unreachable ();
2510 }
2511
2512 /* The LEGITIMATE_PIC_OPERAND_P worker.  */
2513
2514 int
2515 cris_legitimate_pic_operand (rtx x)
2516 {
2517   /* Symbols are not valid PIC operands as-is; just constants.  */
2518   return cris_valid_pic_const (x, true);
2519 }
2520
2521 /* Queue an .ident string in the queue of top-level asm statements.
2522    If the front-end is done, we must be being called from toplev.c.
2523    In that case, do nothing.  */
2524 void 
2525 cris_asm_output_ident (const char *string)
2526 {
2527   if (cgraph_state != CGRAPH_STATE_PARSING)
2528     return;
2529
2530   default_asm_output_ident_directive (string);
2531 }
2532
2533 /* The ASM_OUTPUT_CASE_END worker.  */
2534
2535 void
2536 cris_asm_output_case_end (FILE *stream, int num, rtx table)
2537 {
2538   /* Step back, over the label for the table, to the actual casejump and
2539      assert that we find only what's expected.  */
2540   rtx whole_jump_insn = prev_nonnote_nondebug_insn (table);
2541   gcc_assert (whole_jump_insn != NULL_RTX && LABEL_P (whole_jump_insn));
2542   whole_jump_insn = prev_nonnote_nondebug_insn (whole_jump_insn);
2543   gcc_assert (whole_jump_insn != NULL_RTX
2544               && (JUMP_P (whole_jump_insn)
2545                   || (TARGET_V32 && INSN_P (whole_jump_insn)
2546                       && GET_CODE (PATTERN (whole_jump_insn)) == SEQUENCE)));
2547   /* Get the pattern of the casejump, so we can extract the default label.  */
2548   whole_jump_insn = PATTERN (whole_jump_insn);
2549
2550   if (TARGET_V32)
2551     {
2552       /* This can be a SEQUENCE, meaning the delay-slot of the jump is
2553          filled.  We also output the offset word a little differently.  */
2554       rtx parallel_jump
2555         = (GET_CODE (whole_jump_insn) == SEQUENCE
2556            ? PATTERN (XVECEXP (whole_jump_insn, 0, 0)) : whole_jump_insn);
2557
2558       asm_fprintf (stream,
2559                    "\t.word %LL%d-.%s\n",
2560                    CODE_LABEL_NUMBER (XEXP (XEXP (XEXP (XVECEXP
2561                                                         (parallel_jump, 0, 0),
2562                                                         1), 2), 0)),
2563                    (TARGET_PDEBUG ? "; default" : ""));
2564       return;
2565     }
2566
2567   asm_fprintf (stream,
2568                "\t.word %LL%d-%LL%d%s\n",
2569                CODE_LABEL_NUMBER (XEXP
2570                                   (XEXP
2571                                    (XEXP (XVECEXP (whole_jump_insn, 0, 0), 1), 
2572                                     2), 0)),
2573                num,
2574                (TARGET_PDEBUG ? "; default" : ""));
2575 }
2576
2577 /* The TARGET_OPTION_OVERRIDE worker.
2578    As is the norm, this also parses -mfoo=bar type parameters.  */
2579
2580 static void
2581 cris_option_override (void)
2582 {
2583   if (cris_max_stackframe_str)
2584     {
2585       cris_max_stackframe = atoi (cris_max_stackframe_str);
2586
2587       /* Do some sanity checking.  */
2588       if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2589         internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2590                         cris_max_stackframe, 0x20000000);
2591     }
2592
2593   /* Let "-metrax4" and "-metrax100" change the cpu version.  */
2594   if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2595     cris_cpu_version = CRIS_CPU_SVINTO;
2596   else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2597     cris_cpu_version = CRIS_CPU_ETRAX4;
2598
2599   /* Parse -march=... and its synonym, the deprecated -mcpu=...  */
2600   if (cris_cpu_str)
2601     {
2602       cris_cpu_version
2603         = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2604
2605       if (strcmp ("etrax4", cris_cpu_str) == 0)
2606         cris_cpu_version = 3;
2607
2608       if (strcmp ("svinto", cris_cpu_str) == 0
2609           || strcmp ("etrax100", cris_cpu_str) == 0)
2610         cris_cpu_version = 8;
2611
2612       if (strcmp ("ng", cris_cpu_str) == 0
2613           || strcmp ("etrax100lx", cris_cpu_str) == 0)
2614         cris_cpu_version = 10;
2615
2616       if (cris_cpu_version < 0 || cris_cpu_version > 32)
2617         error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2618                cris_cpu_str);
2619
2620       /* Set the target flags.  */
2621       if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2622         target_flags |= MASK_ETRAX4_ADD;
2623
2624       /* If this is Svinto or higher, align for 32 bit accesses.  */
2625       if (cris_cpu_version >= CRIS_CPU_SVINTO)
2626         target_flags
2627           |= (MASK_SVINTO | MASK_ALIGN_BY_32
2628               | MASK_STACK_ALIGN | MASK_CONST_ALIGN
2629               | MASK_DATA_ALIGN);
2630
2631       /* Note that we do not add new flags when it can be completely
2632          described with a macro that uses -mcpu=X.  So
2633          TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG).  */
2634     }
2635
2636   if (cris_tune_str)
2637     {
2638       int cris_tune
2639         = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2640
2641       if (strcmp ("etrax4", cris_tune_str) == 0)
2642         cris_tune = 3;
2643
2644       if (strcmp ("svinto", cris_tune_str) == 0
2645           || strcmp ("etrax100", cris_tune_str) == 0)
2646         cris_tune = 8;
2647
2648       if (strcmp ("ng", cris_tune_str) == 0
2649           || strcmp ("etrax100lx", cris_tune_str) == 0)
2650         cris_tune = 10;
2651
2652       if (cris_tune < 0 || cris_tune > 32)
2653         error ("unknown CRIS cpu version specification in -mtune= : %s",
2654                cris_tune_str);
2655
2656       if (cris_tune >= CRIS_CPU_SVINTO)
2657         /* We have currently nothing more to tune than alignment for
2658            memory accesses.  */
2659         target_flags
2660           |= (MASK_STACK_ALIGN | MASK_CONST_ALIGN
2661               | MASK_DATA_ALIGN | MASK_ALIGN_BY_32);
2662     }
2663
2664   if (cris_cpu_version >= CRIS_CPU_V32)
2665     target_flags &= ~(MASK_SIDE_EFFECT_PREFIXES|MASK_MUL_BUG);
2666
2667   if (flag_pic)
2668     {
2669       /* Use error rather than warning, so invalid use is easily
2670          detectable.  Still change to the values we expect, to avoid
2671          further errors.  */
2672       if (! TARGET_LINUX)
2673         {
2674           error ("-fPIC and -fpic are not supported in this configuration");
2675           flag_pic = 0;
2676         }
2677
2678       /* Turn off function CSE.  We need to have the addresses reach the
2679          call expanders to get PLT-marked, as they could otherwise be
2680          compared against zero directly or indirectly.  After visiting the
2681          call expanders they will then be cse:ed, as the call expanders
2682          force_reg the addresses, effectively forcing flag_no_function_cse
2683          to 0.  */
2684       flag_no_function_cse = 1;
2685     }
2686
2687   /* Set the per-function-data initializer.  */
2688   init_machine_status = cris_init_machine_status;
2689 }
2690
2691 /* The TARGET_ASM_OUTPUT_MI_THUNK worker.  */
2692
2693 static void
2694 cris_asm_output_mi_thunk (FILE *stream,
2695                           tree thunkdecl ATTRIBUTE_UNUSED,
2696                           HOST_WIDE_INT delta,
2697                           HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2698                           tree funcdecl)
2699 {
2700   /* Make sure unwind info is emitted for the thunk if needed.  */
2701   final_start_function (emit_barrier (), stream, 1);
2702
2703   if (delta > 0)
2704     fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2705              ADDITIVE_SIZE_MODIFIER (delta), delta,
2706              reg_names[CRIS_FIRST_ARG_REG]);
2707   else if (delta < 0)
2708     fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2709              ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2710              reg_names[CRIS_FIRST_ARG_REG]);
2711
2712   if (flag_pic)
2713     {
2714       const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2715
2716       name = (* targetm.strip_name_encoding) (name);
2717
2718       if (TARGET_V32)
2719         {
2720           fprintf (stream, "\tba ");
2721           assemble_name (stream, name);
2722           fprintf (stream, "%s\n", CRIS_PLT_PCOFFSET_SUFFIX);
2723         }
2724       else
2725         {
2726           fprintf (stream, "add.d ");
2727           assemble_name (stream, name);
2728           fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2729         }
2730     }
2731   else
2732     {
2733       fprintf (stream, "jump ");
2734       assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2735       fprintf (stream, "\n");
2736
2737       if (TARGET_V32)
2738         fprintf (stream, "\tnop\n");
2739     }
2740
2741   final_end_function ();
2742 }
2743
2744 /* Boilerplate emitted at start of file.
2745
2746    NO_APP *only at file start* means faster assembly.  It also means
2747    comments are not allowed.  In some cases comments will be output
2748    for debugging purposes.  Make sure they are allowed then.  */
2749 static void
2750 cris_file_start (void)
2751 {
2752   /* These expressions can vary at run time, so we cannot put
2753      them into TARGET_INITIALIZER.  */
2754   targetm.asm_file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2755
2756   default_file_start ();
2757 }
2758
2759 /* Output that goes at the end of the file, similarly.  */
2760
2761 static void
2762 cris_file_end (void)
2763 {
2764   /* For CRIS, the default is to assume *no* executable stack, so output
2765      an executable-stack-note only when needed.  */
2766   if (TARGET_LINUX && trampolines_created)
2767     file_end_indicate_exec_stack ();
2768 }
2769
2770 /* Rename the function calls for integer multiply and divide.  */
2771 static void
2772 cris_init_libfuncs (void)
2773 {
2774   set_optab_libfunc (smul_optab, SImode, "__Mul");
2775   set_optab_libfunc (sdiv_optab, SImode, "__Div");
2776   set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2777   set_optab_libfunc (smod_optab, SImode, "__Mod");
2778   set_optab_libfunc (umod_optab, SImode, "__Umod");
2779
2780   /* Atomic data being unaligned is unfortunately a reality.
2781      Deal with it.  */
2782   if (TARGET_ATOMICS_MAY_CALL_LIBFUNCS)
2783     {
2784       set_optab_libfunc (sync_compare_and_swap_optab, SImode,
2785                          "__cris_atcmpxchgr32");
2786       set_optab_libfunc (sync_compare_and_swap_optab, HImode,
2787                          "__cris_atcmpxchgr16");
2788     }
2789 }
2790
2791 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2792    mark functions.  */
2793
2794 void
2795 cris_init_expanders (void)
2796 {
2797   /* Nothing here at the moment.  */
2798 }
2799
2800 /* Zero initialization is OK for all current fields.  */
2801
2802 static struct machine_function *
2803 cris_init_machine_status (void)
2804 {
2805   return ggc_alloc_cleared_machine_function ();
2806 }
2807
2808 /* Split a 2 word move (DI or presumably DF) into component parts.
2809    Originally a copy of gen_split_move_double in m32r.c.  */
2810
2811 rtx
2812 cris_split_movdx (rtx *operands)
2813 {
2814   enum machine_mode mode = GET_MODE (operands[0]);
2815   rtx dest = operands[0];
2816   rtx src  = operands[1];
2817   rtx val;
2818
2819   /* We used to have to handle (SUBREG (MEM)) here, but that should no
2820      longer happen; after reload there are no SUBREGs any more, and we're
2821      only called after reload.  */
2822   CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG);
2823
2824   start_sequence ();
2825   if (REG_P (dest))
2826     {
2827       int dregno = REGNO (dest);
2828
2829       /* Reg-to-reg copy.  */
2830       if (REG_P (src))
2831         {
2832           int sregno = REGNO (src);
2833
2834           int reverse = (dregno == sregno + 1);
2835
2836           /* We normally copy the low-numbered register first.  However, if
2837              the first register operand 0 is the same as the second register of
2838              operand 1, we must copy in the opposite order.  */
2839           emit_insn (gen_rtx_SET (VOIDmode,
2840                                   operand_subword (dest, reverse, TRUE, mode),
2841                                   operand_subword (src, reverse, TRUE, mode)));
2842
2843           emit_insn (gen_rtx_SET (VOIDmode,
2844                                   operand_subword (dest, !reverse, TRUE, mode),
2845                                   operand_subword (src, !reverse, TRUE, mode)));
2846         }
2847       /* Constant-to-reg copy.  */
2848       else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
2849         {
2850           rtx words[2];
2851           split_double (src, &words[0], &words[1]);
2852           emit_insn (gen_rtx_SET (VOIDmode,
2853                                   operand_subword (dest, 0, TRUE, mode),
2854                                   words[0]));
2855
2856           emit_insn (gen_rtx_SET (VOIDmode,
2857                                   operand_subword (dest, 1, TRUE, mode),
2858                                   words[1]));
2859         }
2860       /* Mem-to-reg copy.  */
2861       else if (MEM_P (src))
2862         {
2863           /* If the high-address word is used in the address, we must load it
2864              last.  Otherwise, load it first.  */
2865           rtx addr = XEXP (src, 0);
2866           int reverse
2867             = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2868
2869           /* The original code implies that we can't do
2870              move.x [rN+],rM  move.x [rN],rM+1
2871              when rN is dead, because of REG_NOTES damage.  That is
2872              consistent with what I've seen, so don't try it.
2873
2874              We have two different cases here; if the addr is POST_INC,
2875              just pass it through, otherwise add constants.  */
2876
2877           if (GET_CODE (addr) == POST_INC)
2878             {
2879               rtx mem;
2880               rtx insn;
2881
2882               /* Whenever we emit insns with post-incremented
2883                  addresses ourselves, we must add a post-inc note
2884                  manually.  */
2885               mem = change_address (src, SImode, addr);
2886               insn
2887                 = gen_rtx_SET (VOIDmode,
2888                                operand_subword (dest, 0, TRUE, mode), mem);
2889               insn = emit_insn (insn);
2890               if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2891                 REG_NOTES (insn)
2892                   = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2893                                      REG_NOTES (insn));
2894
2895               mem = copy_rtx (mem);
2896               insn
2897                 = gen_rtx_SET (VOIDmode,
2898                                operand_subword (dest, 1, TRUE, mode), mem);
2899               insn = emit_insn (insn);
2900               if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2901                 REG_NOTES (insn)
2902                   = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2903                                      REG_NOTES (insn));
2904             }
2905           else
2906             {
2907               /* Make sure we don't get any other addresses with
2908                  embedded postincrements.  They should be stopped in
2909                  GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2910                  safety.  */
2911               if (side_effects_p (addr))
2912                 fatal_insn ("unexpected side-effects in address", addr);
2913
2914               emit_insn (gen_rtx_SET
2915                          (VOIDmode,
2916                           operand_subword (dest, reverse, TRUE, mode),
2917                           change_address
2918                           (src, SImode,
2919                            plus_constant (Pmode, addr,
2920                                           reverse * UNITS_PER_WORD))));
2921               emit_insn (gen_rtx_SET
2922                          (VOIDmode,
2923                           operand_subword (dest, ! reverse, TRUE, mode),
2924                           change_address
2925                           (src, SImode,
2926                            plus_constant (Pmode, addr,
2927                                           (! reverse) *
2928                                           UNITS_PER_WORD))));
2929             }
2930         }
2931       else
2932         internal_error ("unknown src");
2933     }
2934   /* Reg-to-mem copy or clear mem.  */
2935   else if (MEM_P (dest)
2936            && (REG_P (src)
2937                || src == const0_rtx
2938                || src == CONST0_RTX (DFmode)))
2939     {
2940       rtx addr = XEXP (dest, 0);
2941
2942       if (GET_CODE (addr) == POST_INC)
2943         {
2944           rtx mem;
2945           rtx insn;
2946
2947           /* Whenever we emit insns with post-incremented addresses
2948              ourselves, we must add a post-inc note manually.  */
2949           mem = change_address (dest, SImode, addr);
2950           insn
2951             = gen_rtx_SET (VOIDmode,
2952                            mem, operand_subword (src, 0, TRUE, mode));
2953           insn = emit_insn (insn);
2954           if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2955             REG_NOTES (insn)
2956               = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2957                                  REG_NOTES (insn));
2958
2959           mem = copy_rtx (mem);
2960           insn
2961             = gen_rtx_SET (VOIDmode,
2962                            mem,
2963                            operand_subword (src, 1, TRUE, mode));
2964           insn = emit_insn (insn);
2965           if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2966             REG_NOTES (insn)
2967               = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2968                                  REG_NOTES (insn));
2969         }
2970       else
2971         {
2972           /* Make sure we don't get any other addresses with embedded
2973              postincrements.  They should be stopped in
2974              GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety.  */
2975           if (side_effects_p (addr))
2976             fatal_insn ("unexpected side-effects in address", addr);
2977
2978           emit_insn (gen_rtx_SET
2979                      (VOIDmode,
2980                       change_address (dest, SImode, addr),
2981                       operand_subword (src, 0, TRUE, mode)));
2982
2983           emit_insn (gen_rtx_SET
2984                      (VOIDmode,
2985                       change_address (dest, SImode,
2986                                       plus_constant (Pmode, addr,
2987                                                      UNITS_PER_WORD)),
2988                       operand_subword (src, 1, TRUE, mode)));
2989         }
2990     }
2991
2992   else
2993     internal_error ("unknown dest");
2994
2995   val = get_insns ();
2996   end_sequence ();
2997   return val;
2998 }
2999
3000 /* The expander for the prologue pattern name.  */
3001
3002 void
3003 cris_expand_prologue (void)
3004 {
3005   int regno;
3006   int size = get_frame_size ();
3007   /* Shorten the used name for readability.  */
3008   int cfoa_size = crtl->outgoing_args_size;
3009   int last_movem_reg = -1;
3010   int framesize = 0;
3011   rtx mem, insn;
3012   int return_address_on_stack = cris_return_address_on_stack ();
3013   int got_really_used = false;
3014   int n_movem_regs = 0;
3015   int pretend = crtl->args.pretend_args_size;
3016
3017   /* Don't do anything if no prologues or epilogues are wanted.  */
3018   if (!TARGET_PROLOGUE_EPILOGUE)
3019     return;
3020
3021   CRIS_ASSERT (size >= 0);
3022
3023   if (crtl->uses_pic_offset_table)
3024     {
3025       /* A reference may have been optimized out (like the abort () in
3026          fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
3027          it's still used.  */
3028       push_topmost_sequence ();
3029       got_really_used
3030         = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
3031       pop_topmost_sequence ();
3032     }
3033
3034   /* Align the size to what's best for the CPU model.  */
3035   if (TARGET_STACK_ALIGN)
3036     size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
3037
3038   if (pretend)
3039     {
3040       /* See also cris_setup_incoming_varargs where
3041          cfun->machine->stdarg_regs is set.  There are other setters of
3042          crtl->args.pretend_args_size than stdarg handling, like
3043          for an argument passed with parts in R13 and stack.  We must
3044          not store R13 into the pretend-area for that case, as GCC does
3045          that itself.  "Our" store would be marked as redundant and GCC
3046          will attempt to remove it, which will then be flagged as an
3047          internal error; trying to remove a frame-related insn.  */
3048       int stdarg_regs = cfun->machine->stdarg_regs;
3049
3050       framesize += pretend;
3051
3052       for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
3053            stdarg_regs > 0;
3054            regno--, pretend -= 4, stdarg_regs--)
3055         {
3056           insn = emit_insn (gen_rtx_SET (VOIDmode,
3057                                          stack_pointer_rtx,
3058                                          plus_constant (Pmode,
3059                                                         stack_pointer_rtx,
3060                                                         -4)));
3061           /* FIXME: When dwarf2 frame output and unless asynchronous
3062              exceptions, make dwarf2 bundle together all stack
3063              adjustments like it does for registers between stack
3064              adjustments.  */
3065           RTX_FRAME_RELATED_P (insn) = 1;
3066
3067           mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
3068           set_mem_alias_set (mem, get_varargs_alias_set ());
3069           insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
3070
3071           /* Note the absence of RTX_FRAME_RELATED_P on the above insn:
3072              the value isn't restored, so we don't want to tell dwarf2
3073              that it's been stored to stack, else EH handling info would
3074              get confused.  */
3075         }
3076
3077       /* For other setters of crtl->args.pretend_args_size, we
3078          just adjust the stack by leaving the remaining size in
3079          "pretend", handled below.  */
3080     }
3081
3082   /* Save SRP if not a leaf function.  */
3083   if (return_address_on_stack)
3084     {
3085       insn = emit_insn (gen_rtx_SET (VOIDmode,
3086                                      stack_pointer_rtx,
3087                                      plus_constant (Pmode, stack_pointer_rtx,
3088                                                     -4 - pretend)));
3089       pretend = 0;
3090       RTX_FRAME_RELATED_P (insn) = 1;
3091
3092       mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
3093       set_mem_alias_set (mem, get_frame_alias_set ());
3094       insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM));
3095       RTX_FRAME_RELATED_P (insn) = 1;
3096       framesize += 4;
3097     }
3098
3099   /* Set up the frame pointer, if needed.  */
3100   if (frame_pointer_needed)
3101     {
3102       insn = emit_insn (gen_rtx_SET (VOIDmode,
3103                                      stack_pointer_rtx,
3104                                      plus_constant (Pmode, stack_pointer_rtx,
3105                                                     -4 - pretend)));
3106       pretend = 0;
3107       RTX_FRAME_RELATED_P (insn) = 1;
3108
3109       mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
3110       set_mem_alias_set (mem, get_frame_alias_set ());
3111       insn = emit_move_insn (mem, frame_pointer_rtx);
3112       RTX_FRAME_RELATED_P (insn) = 1;
3113
3114       insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
3115       RTX_FRAME_RELATED_P (insn) = 1;
3116
3117       framesize += 4;
3118     }
3119
3120   /* Between frame-pointer and saved registers lie the area for local
3121      variables.  If we get here with "pretended" size remaining, count
3122      it into the general stack size.  */
3123   size += pretend;
3124
3125   /* Get a contiguous sequence of registers, starting with R0, that need
3126      to be saved.  */
3127   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
3128     {
3129       if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3130         {
3131           n_movem_regs++;
3132
3133           /* Check if movem may be used for registers so far.  */
3134           if (regno == last_movem_reg + 1)
3135             /* Yes, update next expected register.  */
3136             last_movem_reg = regno;
3137           else
3138             {
3139               /* We cannot use movem for all registers.  We have to flush
3140                  any movem:ed registers we got so far.  */
3141               if (last_movem_reg != -1)
3142                 {
3143                   int n_saved
3144                     = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
3145
3146                   /* It is a win to use a side-effect assignment for
3147                      64 <= size <= 128.  But side-effect on movem was
3148                      not usable for CRIS v0..3.  Also only do it if
3149                      side-effects insns are allowed.  */
3150                   if ((last_movem_reg + 1) * 4 + size >= 64
3151                       && (last_movem_reg + 1) * 4 + size <= 128
3152                       && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
3153                       && TARGET_SIDE_EFFECT_PREFIXES)
3154                     {
3155                       mem
3156                         = gen_rtx_MEM (SImode,
3157                                        plus_constant (Pmode, stack_pointer_rtx,
3158                                                       -(n_saved * 4 + size)));
3159                       set_mem_alias_set (mem, get_frame_alias_set ());
3160                       insn
3161                         = cris_emit_movem_store (mem, GEN_INT (n_saved),
3162                                                  -(n_saved * 4 + size),
3163                                                  true);
3164                     }
3165                   else
3166                     {
3167                       insn
3168                         = gen_rtx_SET (VOIDmode,
3169                                        stack_pointer_rtx,
3170                                        plus_constant (Pmode, stack_pointer_rtx,
3171                                                       -(n_saved * 4 + size)));
3172                       insn = emit_insn (insn);
3173                       RTX_FRAME_RELATED_P (insn) = 1;
3174
3175                       mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
3176                       set_mem_alias_set (mem, get_frame_alias_set ());
3177                       insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
3178                                                     0, true);
3179                     }
3180
3181                   framesize += n_saved * 4 + size;
3182                   last_movem_reg = -1;
3183                   size = 0;
3184                 }
3185
3186               insn = emit_insn (gen_rtx_SET (VOIDmode,
3187                                              stack_pointer_rtx,
3188                                              plus_constant (Pmode,
3189                                                             stack_pointer_rtx,
3190                                                             -4 - size)));
3191               RTX_FRAME_RELATED_P (insn) = 1;
3192
3193               mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
3194               set_mem_alias_set (mem, get_frame_alias_set ());
3195               insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
3196               RTX_FRAME_RELATED_P (insn) = 1;
3197
3198               framesize += 4 + size;
3199               size = 0;
3200             }
3201         }
3202     }
3203
3204   /* Check after, if we could movem all registers.  This is the normal case.  */
3205   if (last_movem_reg != -1)
3206     {
3207       int n_saved
3208         = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
3209
3210       /* Side-effect on movem was not usable for CRIS v0..3.  Also only
3211          do it if side-effects insns are allowed.  */
3212       if ((last_movem_reg + 1) * 4 + size >= 64
3213           && (last_movem_reg + 1) * 4 + size <= 128
3214           && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
3215           && TARGET_SIDE_EFFECT_PREFIXES)
3216         {
3217           mem
3218             = gen_rtx_MEM (SImode,
3219                            plus_constant (Pmode, stack_pointer_rtx,
3220                                           -(n_saved * 4 + size)));
3221           set_mem_alias_set (mem, get_frame_alias_set ());
3222           insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
3223                                         -(n_saved * 4 + size), true);
3224         }
3225       else
3226         {
3227           insn
3228             = gen_rtx_SET (VOIDmode,
3229                            stack_pointer_rtx,
3230                            plus_constant (Pmode, stack_pointer_rtx,
3231                                           -(n_saved * 4 + size)));
3232           insn = emit_insn (insn);
3233           RTX_FRAME_RELATED_P (insn) = 1;
3234
3235           mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
3236           set_mem_alias_set (mem, get_frame_alias_set ());
3237           insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true);
3238         }
3239
3240       framesize += n_saved * 4 + size;
3241       /* We have to put outgoing argument space after regs.  */
3242       if (cfoa_size)
3243         {
3244           insn = emit_insn (gen_rtx_SET (VOIDmode,
3245                                          stack_pointer_rtx,
3246                                          plus_constant (Pmode,
3247                                                         stack_pointer_rtx,
3248                                                         -cfoa_size)));
3249           RTX_FRAME_RELATED_P (insn) = 1;
3250           framesize += cfoa_size;
3251         }
3252     }
3253   else if ((size + cfoa_size) > 0)
3254     {
3255       insn = emit_insn (gen_rtx_SET (VOIDmode,
3256                                      stack_pointer_rtx,
3257                                      plus_constant (Pmode,
3258                                                     stack_pointer_rtx,
3259                                                     -(cfoa_size + size))));
3260       RTX_FRAME_RELATED_P (insn) = 1;
3261       framesize += size + cfoa_size;
3262     }
3263
3264   /* Set up the PIC register, if it is used.  */
3265   if (got_really_used)
3266     {
3267       rtx got
3268         = gen_rtx_UNSPEC (SImode, gen_rtvec (1, const0_rtx), CRIS_UNSPEC_GOT);
3269       emit_move_insn (pic_offset_table_rtx, got);
3270
3271       /* FIXME: This is a cover-up for flow2 messing up; it doesn't
3272          follow exceptional paths and tries to delete the GOT load as
3273          unused, if it isn't used on the non-exceptional paths.  Other
3274          ports have similar or other cover-ups, or plain bugs marking
3275          the GOT register load as maybe-dead.  To see this, remove the
3276          line below and try libsupc++/vec.cc or a trivial
3277          "static void y (); void x () {try {y ();} catch (...) {}}".  */
3278       emit_use (pic_offset_table_rtx);
3279     }
3280
3281   if (cris_max_stackframe && framesize > cris_max_stackframe)
3282     warning (0, "stackframe too big: %d bytes", framesize);
3283 }
3284
3285 /* The expander for the epilogue pattern.  */
3286
3287 void
3288 cris_expand_epilogue (void)
3289 {
3290   int regno;
3291   int size = get_frame_size ();
3292   int last_movem_reg = -1;
3293   int argspace_offset = crtl->outgoing_args_size;
3294   int pretend =  crtl->args.pretend_args_size;
3295   rtx mem;
3296   bool return_address_on_stack = cris_return_address_on_stack ();
3297   /* A reference may have been optimized out
3298      (like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1)
3299      so check that it's still used.  */
3300   int got_really_used = false;
3301   int n_movem_regs = 0;
3302
3303   if (!TARGET_PROLOGUE_EPILOGUE)
3304     return;
3305
3306   if (crtl->uses_pic_offset_table)
3307     {
3308       /* A reference may have been optimized out (like the abort () in
3309          fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
3310          it's still used.  */
3311       push_topmost_sequence ();
3312       got_really_used
3313         = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
3314       pop_topmost_sequence ();
3315     }
3316
3317   /* Align byte count of stack frame.  */
3318   if (TARGET_STACK_ALIGN)
3319     size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
3320
3321   /* Check how many saved regs we can movem.  They start at r0 and must
3322      be contiguous.  */
3323   for (regno = 0;
3324        regno < FIRST_PSEUDO_REGISTER;
3325        regno++)
3326     if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3327       {
3328         n_movem_regs++;
3329
3330         if (regno == last_movem_reg + 1)
3331           last_movem_reg = regno;
3332         else
3333           break;
3334       }
3335
3336   /* If there was only one register that really needed to be saved
3337      through movem, don't use movem.  */
3338   if (n_movem_regs == 1)
3339     last_movem_reg = -1;
3340
3341   /* Now emit "normal" move insns for all regs higher than the movem
3342      regs.  */
3343   for (regno = FIRST_PSEUDO_REGISTER - 1;
3344        regno > last_movem_reg;
3345        regno--)
3346     if (cris_reg_saved_in_regsave_area (regno, got_really_used))
3347       {
3348         rtx insn;
3349
3350         if (argspace_offset)
3351           {
3352             /* There is an area for outgoing parameters located before
3353                the saved registers.  We have to adjust for that.  */
3354             emit_insn (gen_rtx_SET (VOIDmode,
3355                                     stack_pointer_rtx,
3356                                     plus_constant (Pmode, stack_pointer_rtx,
3357                                                    argspace_offset)));
3358             /* Make sure we only do this once.  */
3359             argspace_offset = 0;
3360           }
3361
3362         mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3363                                                      stack_pointer_rtx));
3364         set_mem_alias_set (mem, get_frame_alias_set ());
3365         insn = emit_move_insn (gen_rtx_raw_REG (SImode, regno), mem);
3366
3367         /* Whenever we emit insns with post-incremented addresses
3368            ourselves, we must add a post-inc note manually.  */
3369         REG_NOTES (insn)
3370           = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3371       }
3372
3373   /* If we have any movem-restore, do it now.  */
3374   if (last_movem_reg != -1)
3375     {
3376       rtx insn;
3377
3378       if (argspace_offset)
3379         {
3380           emit_insn (gen_rtx_SET (VOIDmode,
3381                                   stack_pointer_rtx,
3382                                   plus_constant (Pmode, stack_pointer_rtx,
3383                                                  argspace_offset)));
3384           argspace_offset = 0;
3385         }
3386
3387       mem = gen_rtx_MEM (SImode,
3388                          gen_rtx_POST_INC (SImode, stack_pointer_rtx));
3389       set_mem_alias_set (mem, get_frame_alias_set ());
3390       insn
3391         = emit_insn (cris_gen_movem_load (mem,
3392                                           GEN_INT (last_movem_reg + 1), 0));
3393       /* Whenever we emit insns with post-incremented addresses
3394          ourselves, we must add a post-inc note manually.  */
3395       if (side_effects_p (PATTERN (insn)))
3396         REG_NOTES (insn)
3397           = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3398     }
3399
3400   /* If we don't clobber all of the allocated stack area (we've already
3401      deallocated saved registers), GCC might want to schedule loads from
3402      the stack to *after* the stack-pointer restore, which introduces an
3403      interrupt race condition.  This happened for the initial-value
3404      SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of
3405      other failure for that test).  It also happened for the stack slot
3406      for the return value in (one version of)
3407      linux/fs/dcache.c:__d_lookup, at least with "-O2
3408      -fno-omit-frame-pointer".  */
3409
3410   /* Restore frame pointer if necessary.  */
3411   if (frame_pointer_needed)
3412     {
3413       rtx insn;
3414
3415       emit_insn (gen_cris_frame_deallocated_barrier ());
3416
3417       emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
3418       mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
3419                                                    stack_pointer_rtx));
3420       set_mem_alias_set (mem, get_frame_alias_set ());
3421       insn = emit_move_insn (frame_pointer_rtx, mem);
3422
3423       /* Whenever we emit insns with post-incremented addresses
3424          ourselves, we must add a post-inc note manually.  */
3425       REG_NOTES (insn)
3426         = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3427     }
3428   else if ((size + argspace_offset) != 0)
3429     {
3430       emit_insn (gen_cris_frame_deallocated_barrier ());
3431
3432       /* If there was no frame-pointer to restore sp from, we must
3433          explicitly deallocate local variables.  */
3434
3435       /* Handle space for outgoing parameters that hasn't been handled
3436          yet.  */
3437       size += argspace_offset;
3438
3439       emit_insn (gen_rtx_SET (VOIDmode,
3440                               stack_pointer_rtx,
3441                               plus_constant (Pmode, stack_pointer_rtx, size)));
3442     }
3443
3444   /* If this function has no pushed register parameters
3445      (stdargs/varargs), and if it is not a leaf function, then we have
3446      the return address on the stack.  */
3447   if (return_address_on_stack && pretend == 0)
3448     {
3449       if (TARGET_V32 || crtl->calls_eh_return)
3450         {
3451           rtx mem;
3452           rtx insn;
3453           rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3454           mem = gen_rtx_MEM (SImode,
3455                              gen_rtx_POST_INC (SImode,
3456                                                stack_pointer_rtx));
3457           set_mem_alias_set (mem, get_frame_alias_set ());
3458           insn = emit_move_insn (srpreg, mem);
3459
3460           /* Whenever we emit insns with post-incremented addresses
3461              ourselves, we must add a post-inc note manually.  */
3462           REG_NOTES (insn)
3463             = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3464
3465           if (crtl->calls_eh_return)
3466             emit_insn (gen_addsi3 (stack_pointer_rtx,
3467                                    stack_pointer_rtx,
3468                                    gen_rtx_raw_REG (SImode,
3469                                                     CRIS_STACKADJ_REG)));
3470           cris_expand_return (false);
3471         }
3472       else
3473         cris_expand_return (true);
3474
3475       return;
3476     }
3477
3478   /* If we pushed some register parameters, then adjust the stack for
3479      them.  */
3480   if (pretend != 0)
3481     {
3482       /* If SRP is stored on the way, we need to restore it first.  */
3483       if (return_address_on_stack)
3484         {
3485           rtx mem;
3486           rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
3487           rtx insn;
3488
3489           mem = gen_rtx_MEM (SImode,
3490                              gen_rtx_POST_INC (SImode,
3491                                                stack_pointer_rtx));
3492           set_mem_alias_set (mem, get_frame_alias_set ());
3493           insn = emit_move_insn (srpreg, mem);
3494
3495           /* Whenever we emit insns with post-incremented addresses
3496              ourselves, we must add a post-inc note manually.  */
3497           REG_NOTES (insn)
3498             = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
3499         }
3500
3501       emit_insn (gen_rtx_SET (VOIDmode,
3502                               stack_pointer_rtx,
3503                               plus_constant (Pmode, stack_pointer_rtx,
3504                                              pretend)));
3505     }
3506
3507   /* Perform the "physical" unwinding that the EH machinery calculated.  */
3508   if (crtl->calls_eh_return)
3509     emit_insn (gen_addsi3 (stack_pointer_rtx,
3510                            stack_pointer_rtx,
3511                            gen_rtx_raw_REG (SImode,
3512                                             CRIS_STACKADJ_REG)));
3513   cris_expand_return (false);
3514 }
3515
3516 /* Worker function for generating movem from mem for load_multiple.  */
3517
3518 rtx
3519 cris_gen_movem_load (rtx src, rtx nregs_rtx, int nprefix)
3520 {
3521   int nregs = INTVAL (nregs_rtx);
3522   rtvec vec;
3523   int eltno = 1;
3524   int i;
3525   rtx srcreg = XEXP (src, 0);
3526   unsigned int regno = nregs - 1;
3527   int regno_inc = -1;
3528
3529   if (TARGET_V32)
3530     {
3531       regno = 0;
3532       regno_inc = 1;
3533     }
3534
3535   if (GET_CODE (srcreg) == POST_INC)
3536     srcreg = XEXP (srcreg, 0);
3537
3538   CRIS_ASSERT (REG_P (srcreg));
3539
3540   /* Don't use movem for just one insn.  The insns are equivalent except
3541      for the pipeline hazard (on v32); movem does not forward the loaded
3542      registers so there's a three cycles penalty for their use.  */
3543   if (nregs == 1)
3544     return gen_movsi (gen_rtx_REG (SImode, 0), src);
3545
3546   vec = rtvec_alloc (nprefix + nregs
3547                      + (GET_CODE (XEXP (src, 0)) == POST_INC));
3548
3549   if (GET_CODE (XEXP (src, 0)) == POST_INC)
3550     {
3551       RTVEC_ELT (vec, nprefix + 1)
3552         = gen_rtx_SET (VOIDmode, srcreg,
3553                        plus_constant (Pmode, srcreg, nregs * 4));
3554       eltno++;
3555     }
3556
3557   src = replace_equiv_address (src, srcreg);
3558   RTVEC_ELT (vec, nprefix)
3559     = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno), src);
3560   regno += regno_inc;
3561
3562   for (i = 1; i < nregs; i++, eltno++)
3563     {
3564       RTVEC_ELT (vec, nprefix + eltno)
3565         = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno),
3566                        adjust_address_nv (src, SImode, i * 4));
3567       regno += regno_inc;
3568     }
3569
3570   return gen_rtx_PARALLEL (VOIDmode, vec);
3571 }
3572
3573 /* Worker function for generating movem to mem.  If FRAME_RELATED, notes
3574    are added that the dwarf2 machinery understands.  */
3575
3576 rtx
3577 cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment,
3578                        bool frame_related)
3579 {
3580   int nregs = INTVAL (nregs_rtx);
3581   rtvec vec;
3582   int eltno = 1;
3583   int i;
3584   rtx insn;
3585   rtx destreg = XEXP (dest, 0);
3586   unsigned int regno = nregs - 1;
3587   int regno_inc = -1;
3588
3589   if (TARGET_V32)
3590     {
3591       regno = 0;
3592       regno_inc = 1;
3593     }
3594
3595   if (GET_CODE (destreg) == POST_INC)
3596     increment += nregs * 4;
3597
3598   if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS)
3599     destreg = XEXP (destreg, 0);
3600
3601   CRIS_ASSERT (REG_P (destreg));
3602
3603   /* Don't use movem for just one insn.  The insns are equivalent except
3604      for the pipeline hazard (on v32); movem does not forward the loaded
3605      registers so there's a three cycles penalty for use.  */
3606   if (nregs == 1)
3607     {
3608       rtx mov = gen_rtx_SET (VOIDmode, dest, gen_rtx_REG (SImode, 0));
3609
3610       if (increment == 0)
3611         {
3612           insn = emit_insn (mov);
3613           if (frame_related)
3614             RTX_FRAME_RELATED_P (insn) = 1;
3615           return insn;
3616         }
3617
3618       /* If there was a request for a side-effect, create the ordinary
3619          parallel.  */
3620       vec = rtvec_alloc (2);
3621
3622       RTVEC_ELT (vec, 0) = mov;
3623       RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, destreg,
3624                                         plus_constant (Pmode, destreg,
3625                                                        increment));
3626       if (frame_related)
3627         {
3628           RTX_FRAME_RELATED_P (mov) = 1;
3629           RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3630         }
3631     }
3632   else
3633     {
3634       vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0));
3635       RTVEC_ELT (vec, 0)
3636         = gen_rtx_SET (VOIDmode,
3637                        replace_equiv_address (dest,
3638                                               plus_constant (Pmode, destreg,
3639                                                              increment)),
3640                        gen_rtx_REG (SImode, regno));
3641       regno += regno_inc;
3642
3643       /* The dwarf2 info wants this mark on each component in a parallel
3644          that's part of the prologue (though it's optional on the first
3645          component).  */
3646       if (frame_related)
3647         RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1;
3648
3649       if (increment != 0)
3650         {
3651           RTVEC_ELT (vec, 1)
3652             = gen_rtx_SET (VOIDmode, destreg,
3653                            plus_constant (Pmode, destreg,
3654                                           increment != 0
3655                                           ? increment : nregs * 4));
3656           eltno++;
3657
3658           if (frame_related)
3659             RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3660
3661           /* Don't call adjust_address_nv on a post-incremented address if
3662              we can help it.  */
3663           if (GET_CODE (XEXP (dest, 0)) == POST_INC)
3664             dest = replace_equiv_address (dest, destreg);
3665         }
3666
3667       for (i = 1; i < nregs; i++, eltno++)
3668         {
3669           RTVEC_ELT (vec, eltno)
3670             = gen_rtx_SET (VOIDmode, adjust_address_nv (dest, SImode, i * 4),
3671                            gen_rtx_REG (SImode, regno));
3672           if (frame_related)
3673             RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1;
3674           regno += regno_inc;
3675         }
3676     }
3677
3678   insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec));
3679
3680   /* Because dwarf2out.c handles the insns in a parallel as a sequence,
3681      we need to keep the stack adjustment separate, after the
3682      MEM-setters.  Else the stack-adjustment in the second component of
3683      the parallel would be mishandled; the offsets for the SETs that
3684      follow it would be wrong.  We prepare for this by adding a
3685      REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE
3686      followed by the increment.  Note that we have FRAME_RELATED_P on
3687      all the SETs, including the original stack adjustment SET in the
3688      parallel.  */
3689   if (frame_related)
3690     {
3691       if (increment != 0)
3692         {
3693           rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1));
3694           XVECEXP (seq, 0, 0) = copy_rtx (XVECEXP (PATTERN (insn), 0, 0));
3695           for (i = 1; i < nregs; i++)
3696             XVECEXP (seq, 0, i)
3697               = copy_rtx (XVECEXP (PATTERN (insn), 0, i + 1));
3698           XVECEXP (seq, 0, nregs) = copy_rtx (XVECEXP (PATTERN (insn), 0, 1));
3699           add_reg_note (insn, REG_FRAME_RELATED_EXPR, seq);
3700         }
3701
3702       RTX_FRAME_RELATED_P (insn) = 1;
3703     }
3704
3705   return insn;
3706 }
3707
3708 /* Worker function for expanding the address for PIC function calls.  */
3709
3710 void
3711 cris_expand_pic_call_address (rtx *opp)
3712 {
3713   rtx op = *opp;
3714
3715   gcc_assert (MEM_P (op));
3716   op = XEXP (op, 0);
3717
3718   /* It might be that code can be generated that jumps to 0 (or to a
3719      specific address).  Don't die on that.  (There is a
3720      testcase.)  */
3721   if (CONSTANT_ADDRESS_P (op) && !CONST_INT_P (op))
3722     {
3723       enum cris_pic_symbol_type t = cris_pic_symbol_type_of (op);
3724
3725       CRIS_ASSERT (can_create_pseudo_p ());
3726
3727       /* For local symbols (non-PLT), just get the plain symbol
3728          reference into a register.  For symbols that can be PLT, make
3729          them PLT.  */
3730       if (t == cris_rel_symbol)
3731         {
3732           /* For v32, we're fine as-is; just PICify the symbol.  Forcing
3733              into a register caused performance regression for 3.2.1,
3734              observable in __floatdidf and elsewhere in libgcc.  */
3735           if (TARGET_V32)
3736             {
3737               rtx sym = GET_CODE (op) != CONST ? op : get_related_value (op);
3738               HOST_WIDE_INT offs = get_integer_term (op);
3739
3740               /* We can't get calls to sym+N, N integer, can we?  */
3741               gcc_assert (offs == 0);
3742
3743               op = gen_rtx_CONST (Pmode,
3744                                   gen_rtx_UNSPEC (Pmode, gen_rtvec (1, sym),
3745                                                   CRIS_UNSPEC_PCREL));
3746             }
3747           else
3748             op = force_reg (Pmode, op);
3749         }
3750       else if (t == cris_got_symbol)
3751         {
3752           if (TARGET_AVOID_GOTPLT)
3753             {
3754               /* Change a "jsr sym" into (allocate register rM, rO)
3755                  "move.d (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_GOTREL)),rM"
3756                  "add.d rPIC,rM,rO", "jsr rO" for pre-v32 and
3757                  "jsr (const (unspec [sym rPIC] CRIS_UNSPEC_PLT_PCREL))"
3758                  for v32.  */
3759               rtx tem, rm, ro;
3760               gcc_assert (can_create_pseudo_p ());
3761               crtl->uses_pic_offset_table = 1;
3762               tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3763                                     TARGET_V32
3764                                     ? CRIS_UNSPEC_PLT_PCREL
3765                                     : CRIS_UNSPEC_PLT_GOTREL);
3766               tem = gen_rtx_CONST (Pmode, tem);
3767               if (TARGET_V32)
3768                 op = tem;
3769               else
3770                 {
3771                   rm = gen_reg_rtx (Pmode);
3772                   emit_move_insn (rm, tem);
3773                   ro = gen_reg_rtx (Pmode);
3774                   if (expand_binop (Pmode, add_optab, rm,
3775                                     pic_offset_table_rtx,
3776                                     ro, 0, OPTAB_LIB_WIDEN) != ro)
3777                     internal_error ("expand_binop failed in movsi got");
3778                   op = ro;
3779                 }
3780             }
3781           else
3782             {
3783               /* Change a "jsr sym" into (allocate register rM, rO)
3784                  "move.d (const (unspec [sym] CRIS_UNSPEC_PLTGOTREAD)),rM"
3785                  "add.d rPIC,rM,rO" "jsr [rO]" with the memory access
3786                  marked as not trapping and not aliasing.  No "move.d
3787                  [rO],rP" as that would invite to re-use of a value
3788                  that should not be reused.  FIXME: Need a peephole2
3789                  for cases when this is cse:d from the call, to change
3790                  back to just get the PLT entry address, so we don't
3791                  resolve the same symbol over and over (the memory
3792                  access of the PLTGOT isn't constant).  */
3793               rtx tem, mem, rm, ro;
3794
3795               gcc_assert (can_create_pseudo_p ());
3796               crtl->uses_pic_offset_table = 1;
3797               tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3798                                     CRIS_UNSPEC_PLTGOTREAD);
3799               rm = gen_reg_rtx (Pmode);
3800               emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3801               ro = gen_reg_rtx (Pmode);
3802               if (expand_binop (Pmode, add_optab, rm,
3803                                 pic_offset_table_rtx,
3804                                 ro, 0, OPTAB_LIB_WIDEN) != ro)
3805                 internal_error ("expand_binop failed in movsi got");
3806               mem = gen_rtx_MEM (Pmode, ro);
3807
3808               /* This MEM doesn't alias anything.  Whether it aliases
3809                  other same symbols is unimportant.  */
3810               set_mem_alias_set (mem, new_alias_set ());
3811               MEM_NOTRAP_P (mem) = 1;
3812               op = mem;
3813             }
3814         }
3815       else
3816         /* Can't possibly get a GOT-needing-fixup for a function-call,
3817            right?  */
3818         fatal_insn ("unidentifiable call op", op);
3819
3820       *opp = replace_equiv_address (*opp, op);
3821     }
3822 }
3823
3824 /* Make sure operands are in the right order for an addsi3 insn as
3825    generated by a define_split.  Nothing but REG_P as the first
3826    operand is recognized by addsi3 after reload.  OPERANDS contains
3827    the operands, with the first at OPERANDS[N] and the second at
3828    OPERANDS[N+1].  */
3829
3830 void
3831 cris_order_for_addsi3 (rtx *operands, int n)
3832 {
3833   if (!REG_P (operands[n]))
3834     {
3835       rtx tem = operands[n];
3836       operands[n] = operands[n + 1];
3837       operands[n + 1] = tem;
3838     }
3839 }
3840
3841 /* Use from within code, from e.g. PRINT_OPERAND and
3842    PRINT_OPERAND_ADDRESS.  Macros used in output_addr_const need to emit
3843    different things depending on whether code operand or constant is
3844    emitted.  */
3845
3846 static void
3847 cris_output_addr_const (FILE *file, rtx x)
3848 {
3849   in_code++;
3850   output_addr_const (file, x);
3851   in_code--;
3852 }
3853
3854 /* Worker function for ASM_OUTPUT_SYMBOL_REF.  */
3855
3856 void
3857 cris_asm_output_symbol_ref (FILE *file, rtx x)
3858 {
3859   gcc_assert (GET_CODE (x) == SYMBOL_REF);
3860
3861   if (flag_pic && in_code > 0)
3862     {
3863      const char *origstr = XSTR (x, 0);
3864      const char *str;
3865      str = (* targetm.strip_name_encoding) (origstr);
3866      assemble_name (file, str);
3867
3868      /* Sanity check.  */
3869      if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3870        output_operand_lossage ("PIC register isn't set up");
3871     }
3872   else
3873     assemble_name (file, XSTR (x, 0));
3874 }
3875
3876 /* Worker function for ASM_OUTPUT_LABEL_REF.  */
3877
3878 void
3879 cris_asm_output_label_ref (FILE *file, char *buf)
3880 {
3881   if (flag_pic && in_code > 0)
3882     {
3883       assemble_name (file, buf);
3884
3885       /* Sanity check.  */
3886       if (!TARGET_V32 && !crtl->uses_pic_offset_table)
3887         internal_error ("emitting PIC operand, but PIC register "
3888                         "isn%'t set up");
3889     }
3890   else
3891     assemble_name (file, buf);
3892 }
3893
3894 /* Worker function for TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
3895
3896 static bool
3897 cris_output_addr_const_extra (FILE *file, rtx xconst)
3898 {
3899   switch (GET_CODE (xconst))
3900     {
3901       rtx x;
3902
3903     case UNSPEC:
3904       x = XVECEXP (xconst, 0, 0);
3905       CRIS_ASSERT (GET_CODE (x) == SYMBOL_REF
3906                    || GET_CODE (x) == LABEL_REF
3907                    || GET_CODE (x) == CONST);
3908       output_addr_const (file, x);
3909       switch (XINT (xconst, 1))
3910         {
3911         case CRIS_UNSPEC_PCREL:
3912           /* We only get this with -fpic/PIC to tell it apart from an
3913              invalid symbol.  We can't tell here, but it should only
3914              be the operand of a call or movsi.  */
3915           gcc_assert (TARGET_V32 && flag_pic);
3916           break;
3917
3918         case CRIS_UNSPEC_PLT_PCREL:
3919           gcc_assert (TARGET_V32);
3920           fprintf (file, ":PLT");
3921           break;
3922
3923         case CRIS_UNSPEC_PLT_GOTREL:
3924           gcc_assert (!TARGET_V32);
3925           fprintf (file, ":PLTG");
3926           break;
3927
3928         case CRIS_UNSPEC_GOTREL:
3929           gcc_assert (!TARGET_V32);
3930           fprintf (file, ":GOTOFF");
3931           break;
3932
3933         case CRIS_UNSPEC_GOTREAD:
3934           if (flag_pic == 1)
3935             fprintf (file, ":GOT16");
3936           else
3937             fprintf (file, ":GOT");
3938           break;
3939
3940         case CRIS_UNSPEC_PLTGOTREAD:
3941           if (flag_pic == 1)
3942             fprintf (file, CRIS_GOTPLT_SUFFIX "16");
3943           else
3944             fprintf (file, CRIS_GOTPLT_SUFFIX);
3945           break;
3946
3947         default:
3948           gcc_unreachable ();
3949         }
3950       return true;
3951
3952     default:
3953       return false;
3954     }
3955 }
3956
3957 /* Worker function for TARGET_STRUCT_VALUE_RTX.  */
3958
3959 static rtx
3960 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3961                        int incoming ATTRIBUTE_UNUSED)
3962 {
3963   return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM);
3964 }
3965
3966 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
3967
3968 static void
3969 cris_setup_incoming_varargs (cumulative_args_t ca_v,
3970                              enum machine_mode mode ATTRIBUTE_UNUSED,
3971                              tree type ATTRIBUTE_UNUSED,
3972                              int *pretend_arg_size,
3973                              int second_time)
3974 {
3975   CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v);
3976
3977   if (ca->regs < CRIS_MAX_ARGS_IN_REGS)
3978     {
3979       int stdarg_regs = CRIS_MAX_ARGS_IN_REGS - ca->regs;
3980       cfun->machine->stdarg_regs = stdarg_regs;
3981       *pretend_arg_size = stdarg_regs * 4;
3982     }
3983
3984   if (TARGET_PDEBUG)
3985     fprintf (asm_out_file,
3986              "\n; VA:: ANSI: %d args before, anon @ #%d, %dtime\n",
3987              ca->regs, *pretend_arg_size, second_time);
3988 }
3989
3990 /* Return true if TYPE must be passed by invisible reference.
3991    For cris, we pass <= 8 bytes by value, others by reference.  */
3992
3993 static bool
3994 cris_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED,
3995                         enum machine_mode mode, const_tree type,
3996                         bool named ATTRIBUTE_UNUSED)
3997 {
3998   return (targetm.calls.must_pass_in_stack (mode, type)
3999           || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8);
4000 }
4001
4002 /* A combination of defining TARGET_PROMOTE_FUNCTION_MODE, promoting arguments
4003    and *not* defining TARGET_PROMOTE_PROTOTYPES or PROMOTE_MODE gives the
4004    best code size and speed for gcc, ipps and products in gcc-2.7.2.  */
4005
4006 enum machine_mode
4007 cris_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
4008                             enum machine_mode mode,
4009                             int *punsignedp ATTRIBUTE_UNUSED,
4010                             const_tree fntype ATTRIBUTE_UNUSED,
4011                             int for_return)
4012 {
4013   /* Defining PROMOTE_FUNCTION_RETURN in gcc-2.7.2 uncovered bug 981110 (even
4014      when modifying TARGET_FUNCTION_VALUE to return the promoted mode).
4015      Maybe pointless as of now, but let's keep the old behavior.  */
4016   if (for_return == 1)
4017     return mode;
4018   return CRIS_PROMOTED_MODE (mode, *punsignedp, type);
4019
4020
4021 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
4022    time being.  */
4023
4024 static rtx
4025 cris_function_value(const_tree type,
4026                     const_tree func ATTRIBUTE_UNUSED,
4027                     bool outgoing ATTRIBUTE_UNUSED)
4028 {
4029   return gen_rtx_REG (TYPE_MODE (type), CRIS_FIRST_ARG_REG);
4030 }
4031
4032 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
4033    time being.  */
4034
4035 static rtx
4036 cris_libcall_value (enum machine_mode mode,
4037                     const_rtx fun ATTRIBUTE_UNUSED)
4038 {
4039   return gen_rtx_REG (mode, CRIS_FIRST_ARG_REG);
4040 }
4041
4042 /* Let's assume all functions return in r[CRIS_FIRST_ARG_REG] for the
4043    time being.  */
4044
4045 static bool
4046 cris_function_value_regno_p (const unsigned int regno)
4047 {
4048   return (regno == CRIS_FIRST_ARG_REG);
4049 }
4050
4051 static int
4052 cris_arg_partial_bytes (cumulative_args_t ca, enum machine_mode mode,
4053                         tree type, bool named ATTRIBUTE_UNUSED)
4054 {
4055   if (get_cumulative_args (ca)->regs == CRIS_MAX_ARGS_IN_REGS - 1
4056       && !targetm.calls.must_pass_in_stack (mode, type)
4057       && CRIS_FUNCTION_ARG_SIZE (mode, type) > 4
4058       && CRIS_FUNCTION_ARG_SIZE (mode, type) <= 8)
4059     return UNITS_PER_WORD;
4060   else
4061     return 0;
4062 }
4063
4064 static rtx
4065 cris_function_arg_1 (cumulative_args_t ca_v,
4066                      enum machine_mode mode ATTRIBUTE_UNUSED,
4067                      const_tree type ATTRIBUTE_UNUSED,
4068                      bool named, bool incoming)
4069 {
4070   const CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v);
4071
4072   if ((!incoming || named) && ca->regs < CRIS_MAX_ARGS_IN_REGS)
4073     return gen_rtx_REG (mode, CRIS_FIRST_ARG_REG + ca->regs);
4074   else
4075     return NULL_RTX;
4076 }
4077
4078 /* Worker function for TARGET_FUNCTION_ARG.
4079    The void_type_node is sent as a "closing" call.  */
4080
4081 static rtx
4082 cris_function_arg (cumulative_args_t ca, enum machine_mode mode,
4083                    const_tree type, bool named)
4084 {
4085   return cris_function_arg_1 (ca, mode, type, named, false);
4086 }
4087
4088 /* Worker function for TARGET_FUNCTION_INCOMING_ARG.
4089
4090    The differences between this and the previous, is that this one checks
4091    that an argument is named, since incoming stdarg/varargs arguments are
4092    pushed onto the stack, and we don't have to check against the "closing"
4093    void_type_node TYPE parameter.  */
4094
4095 static rtx
4096 cris_function_incoming_arg (cumulative_args_t ca, enum machine_mode mode,
4097                             const_tree type, bool named)
4098 {
4099   return cris_function_arg_1 (ca, mode, type, named, true);
4100 }
4101
4102 /* Worker function for TARGET_FUNCTION_ARG_ADVANCE.  */
4103
4104 static void
4105 cris_function_arg_advance (cumulative_args_t ca_v, enum machine_mode mode,
4106                            const_tree type, bool named ATTRIBUTE_UNUSED)
4107 {
4108   CUMULATIVE_ARGS *ca = get_cumulative_args (ca_v);
4109
4110   ca->regs += (3 + CRIS_FUNCTION_ARG_SIZE (mode, type)) / 4;
4111 }
4112
4113 /* Worker function for TARGET_MD_ASM_CLOBBERS.  */
4114
4115 static tree
4116 cris_md_asm_clobbers (tree outputs, tree inputs, tree in_clobbers)
4117 {
4118   HARD_REG_SET mof_set;
4119   tree clobbers;
4120   tree t;
4121
4122   CLEAR_HARD_REG_SET (mof_set);
4123   SET_HARD_REG_BIT (mof_set, CRIS_MOF_REGNUM);
4124
4125   /* For the time being, all asms clobber condition codes.  Revisit when
4126      there's a reasonable use for inputs/outputs that mention condition
4127      codes.  */
4128   clobbers
4129     = tree_cons (NULL_TREE,
4130                  build_string (strlen (reg_names[CRIS_CC0_REGNUM]),
4131                                reg_names[CRIS_CC0_REGNUM]),
4132                  in_clobbers);
4133
4134   for (t = outputs; t != NULL; t = TREE_CHAIN (t))
4135     {
4136       tree val = TREE_VALUE (t);
4137
4138       /* The constraint letter for the singleton register class of MOF
4139          is 'h'.  If it's mentioned in the constraints, the asm is
4140          MOF-aware and adding it to the clobbers would cause it to have
4141          impossible constraints.  */
4142       if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
4143                   'h') != NULL
4144           || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
4145         return clobbers;
4146     }
4147
4148   for (t = inputs; t != NULL; t = TREE_CHAIN (t))
4149     {
4150       tree val = TREE_VALUE (t);
4151
4152       if (strchr (TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t))),
4153                   'h') != NULL
4154           || tree_overlaps_hard_reg_set (val, &mof_set) != NULL_TREE)
4155         return clobbers;
4156     }
4157
4158   return tree_cons (NULL_TREE,
4159                     build_string (strlen (reg_names[CRIS_MOF_REGNUM]),
4160                                   reg_names[CRIS_MOF_REGNUM]),
4161                     clobbers);
4162 }
4163
4164 /* Implement TARGET_FRAME_POINTER_REQUIRED.
4165
4166    Really only needed if the stack frame has variable length (alloca
4167    or variable sized local arguments (GNU C extension).  See PR39499 and
4168    PR38609 for the reason this isn't just 0.  */
4169
4170 bool
4171 cris_frame_pointer_required (void)
4172 {
4173   return !crtl->sp_is_unchanging;
4174 }
4175
4176 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
4177
4178    This looks too complicated, and it is.  I assigned r7 to be the
4179    static chain register, but it is call-saved, so we have to save it,
4180    and come back to restore it after the call, so we have to save srp...
4181    Anyway, trampolines are rare enough that we can cope with this
4182    somewhat lack of elegance.
4183     (Do not be tempted to "straighten up" whitespace in the asms; the
4184    assembler #NO_APP state mandates strict spacing).  */
4185 /* ??? See the i386 regparm=3 implementation that pushes the static
4186    chain value to the stack in the trampoline, and uses a call-saved
4187    register when called directly.  */
4188
4189 static void
4190 cris_asm_trampoline_template (FILE *f)
4191 {
4192   if (TARGET_V32)
4193     {
4194       /* This normally-unused nop insn acts as an instruction to
4195          the simulator to flush its instruction cache.  None of
4196          the other instructions in the trampoline template suits
4197          as a trigger for V32.  The pc-relative addressing mode
4198          works nicely as a trigger for V10.
4199          FIXME: Have specific V32 template (possibly avoiding the
4200          use of a special instruction).  */
4201       fprintf (f, "\tclearf x\n");
4202       /* We have to use a register as an intermediate, choosing
4203          semi-randomly R1 (which has to not be the STATIC_CHAIN_REGNUM),
4204          so we can use it for address indirection and jsr target.  */
4205       fprintf (f, "\tmove $r1,$mof\n");
4206       /* +4 */
4207       fprintf (f, "\tmove.d 0,$r1\n");
4208       fprintf (f, "\tmove.d $%s,[$r1]\n", reg_names[STATIC_CHAIN_REGNUM]);
4209       fprintf (f, "\taddq 6,$r1\n");
4210       fprintf (f, "\tmove $mof,[$r1]\n");
4211       fprintf (f, "\taddq 6,$r1\n");
4212       fprintf (f, "\tmove $srp,[$r1]\n");
4213       /* +20 */
4214       fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
4215       /* +26 */
4216       fprintf (f, "\tmove.d 0,$r1\n");
4217       fprintf (f, "\tjsr $r1\n");
4218       fprintf (f, "\tsetf\n");
4219       /* +36 */
4220       fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
4221       /* +42 */
4222       fprintf (f, "\tmove.d 0,$r1\n");
4223       /* +48 */
4224       fprintf (f, "\tmove.d 0,$r9\n");
4225       fprintf (f, "\tjump $r9\n");
4226       fprintf (f, "\tsetf\n");
4227     }
4228   else
4229     {
4230       fprintf (f, "\tmove.d $%s,[$pc+20]\n", reg_names[STATIC_CHAIN_REGNUM]);
4231       fprintf (f, "\tmove $srp,[$pc+22]\n");
4232       fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
4233       fprintf (f, "\tjsr 0\n");
4234       fprintf (f, "\tmove.d 0,$%s\n", reg_names[STATIC_CHAIN_REGNUM]);
4235       fprintf (f, "\tjump 0\n");
4236     }
4237 }
4238
4239 /* Implement TARGET_TRAMPOLINE_INIT.  */
4240
4241 static void
4242 cris_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
4243 {
4244   rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
4245   rtx tramp = XEXP (m_tramp, 0);
4246   rtx mem;
4247
4248   emit_block_move (m_tramp, assemble_trampoline_template (),
4249                    GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
4250
4251   if (TARGET_V32)
4252     {
4253       mem = adjust_address (m_tramp, SImode, 6);
4254       emit_move_insn (mem, plus_constant (Pmode, tramp, 38));
4255       mem = adjust_address (m_tramp, SImode, 22);
4256       emit_move_insn (mem, chain_value);
4257       mem = adjust_address (m_tramp, SImode, 28);
4258       emit_move_insn (mem, fnaddr);
4259     }
4260   else
4261     {
4262       mem = adjust_address (m_tramp, SImode, 10);
4263       emit_move_insn (mem, chain_value);
4264       mem = adjust_address (m_tramp, SImode, 16);
4265       emit_move_insn (mem, fnaddr);
4266     }
4267
4268   /* Note that there is no need to do anything with the cache for
4269      sake of a trampoline.  */
4270 }
4271
4272
4273 #if 0
4274 /* Various small functions to replace macros.  Only called from a
4275    debugger.  They might collide with gcc functions or system functions,
4276    so only emit them when '#if 1' above.  */
4277
4278 enum rtx_code Get_code (rtx);
4279
4280 enum rtx_code
4281 Get_code (rtx x)
4282 {
4283   return GET_CODE (x);
4284 }
4285
4286 const char *Get_mode (rtx);
4287
4288 const char *
4289 Get_mode (rtx x)
4290 {
4291   return GET_MODE_NAME (GET_MODE (x));
4292 }
4293
4294 rtx Xexp (rtx, int);
4295
4296 rtx
4297 Xexp (rtx x, int n)
4298 {
4299   return XEXP (x, n);
4300 }
4301
4302 rtx Xvecexp (rtx, int, int);
4303
4304 rtx
4305 Xvecexp (rtx x, int n, int m)
4306 {
4307   return XVECEXP (x, n, m);
4308 }
4309
4310 int Get_rtx_len (rtx);
4311
4312 int
4313 Get_rtx_len (rtx x)
4314 {
4315   return GET_RTX_LENGTH (GET_CODE (x));
4316 }
4317
4318 /* Use upper-case to distinguish from local variables that are sometimes
4319    called next_insn and prev_insn.  */
4320
4321 rtx Next_insn (rtx);
4322
4323 rtx
4324 Next_insn (rtx insn)
4325 {
4326   return NEXT_INSN (insn);
4327 }
4328
4329 rtx Prev_insn (rtx);
4330
4331 rtx
4332 Prev_insn (rtx insn)
4333 {
4334   return PREV_INSN (insn);
4335 }
4336 #endif
4337
4338 #include "gt-cris.h"
4339
4340 /*
4341  * Local variables:
4342  * eval: (c-set-style "gnu")
4343  * indent-tabs-mode: t
4344  * End:
4345  */