OSDN Git Service

* common.opt (-G): Don't define option here.
[pf3gnuchains/gcc-fork.git] / gcc / config / m32r / m32r.c
1 /* Subroutines used for code generation on the Renesas M32R cpu.
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3    2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
5    This file is part of GCC.
6
7    GCC is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published
9    by the Free Software Foundation; either version 3, or (at your
10    option) any later version.
11
12    GCC is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15    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 "tree.h"
26 #include "rtl.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "output.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "expr.h"
35 #include "function.h"
36 #include "recog.h"
37 #include "diagnostic-core.h"
38 #include "toplev.h"
39 #include "ggc.h"
40 #include "integrate.h"
41 #include "df.h"
42 #include "tm_p.h"
43 #include "target.h"
44 #include "target-def.h"
45 #include "tm-constrs.h"
46
47 /* Array of valid operand punctuation characters.  */
48 static char m32r_punct_chars[256];
49
50 /* Selected code model.  */
51 enum m32r_model m32r_model = M32R_MODEL_DEFAULT;
52
53 /* Selected SDA support.  */
54 enum m32r_sdata m32r_sdata = M32R_SDATA_DEFAULT;
55
56 /* Machine-specific symbol_ref flags.  */
57 #define SYMBOL_FLAG_MODEL_SHIFT         SYMBOL_FLAG_MACH_DEP_SHIFT
58 #define SYMBOL_REF_MODEL(X) \
59   ((enum m32r_model) ((SYMBOL_REF_FLAGS (X) >> SYMBOL_FLAG_MODEL_SHIFT) & 3))
60
61 /* For string literals, etc.  */
62 #define LIT_NAME_P(NAME) ((NAME)[0] == '*' && (NAME)[1] == '.')
63
64 /* Forward declaration.  */
65 static bool  m32r_handle_option (size_t, const char *, int);
66 static void  init_reg_tables (void);
67 static void  block_move_call (rtx, rtx, rtx);
68 static int   m32r_is_insn (rtx);
69 static rtx   m32r_legitimize_address (rtx, rtx, enum machine_mode);
70 static tree  m32r_handle_model_attribute (tree *, tree, tree, int, bool *);
71 static void  m32r_print_operand (FILE *, rtx, int);
72 static void  m32r_print_operand_address (FILE *, rtx);
73 static bool  m32r_print_operand_punct_valid_p (unsigned char code);
74 static void  m32r_output_function_prologue (FILE *, HOST_WIDE_INT);
75 static void  m32r_output_function_epilogue (FILE *, HOST_WIDE_INT);
76
77 static void  m32r_file_start (void);
78
79 static int    m32r_adjust_priority (rtx, int);
80 static int    m32r_issue_rate (void);
81
82 static void m32r_encode_section_info (tree, rtx, int);
83 static bool m32r_in_small_data_p (const_tree);
84 static bool m32r_return_in_memory (const_tree, const_tree);
85 static void m32r_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
86                                          tree, int *, int);
87 static void init_idents (void);
88 static bool m32r_rtx_costs (rtx, int, int, int *, bool speed);
89 static bool m32r_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
90                                     const_tree, bool);
91 static int m32r_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
92                                    tree, bool);
93 static bool m32r_can_eliminate (const int, const int);
94 static void m32r_trampoline_init (rtx, tree, rtx);
95 \f
96 /* M32R specific attributes.  */
97
98 static const struct attribute_spec m32r_attribute_table[] =
99 {
100   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
101   { "interrupt", 0, 0, true,  false, false, NULL },
102   { "model",     1, 1, true,  false, false, m32r_handle_model_attribute },
103   { NULL,        0, 0, false, false, false, NULL }
104 };
105 \f
106 /* Initialize the GCC target structure.  */
107 #undef  TARGET_ATTRIBUTE_TABLE
108 #define TARGET_ATTRIBUTE_TABLE m32r_attribute_table
109
110 #undef TARGET_LEGITIMIZE_ADDRESS
111 #define TARGET_LEGITIMIZE_ADDRESS m32r_legitimize_address
112
113 #undef  TARGET_ASM_ALIGNED_HI_OP
114 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
115 #undef  TARGET_ASM_ALIGNED_SI_OP
116 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
117
118 #undef  TARGET_PRINT_OPERAND
119 #define TARGET_PRINT_OPERAND m32r_print_operand
120 #undef  TARGET_PRINT_OPERAND_ADDRESS
121 #define TARGET_PRINT_OPERAND_ADDRESS m32r_print_operand_address
122 #undef  TARGET_PRINT_OPERAND_PUNCT_VALID_P
123 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P m32r_print_operand_punct_valid_p
124
125 #undef  TARGET_ASM_FUNCTION_PROLOGUE
126 #define TARGET_ASM_FUNCTION_PROLOGUE m32r_output_function_prologue
127 #undef  TARGET_ASM_FUNCTION_EPILOGUE
128 #define TARGET_ASM_FUNCTION_EPILOGUE m32r_output_function_epilogue
129
130 #undef  TARGET_ASM_FILE_START
131 #define TARGET_ASM_FILE_START m32r_file_start
132
133 #undef  TARGET_SCHED_ADJUST_PRIORITY
134 #define TARGET_SCHED_ADJUST_PRIORITY m32r_adjust_priority
135 #undef  TARGET_SCHED_ISSUE_RATE
136 #define TARGET_SCHED_ISSUE_RATE m32r_issue_rate
137
138 #undef  TARGET_DEFAULT_TARGET_FLAGS
139 #define TARGET_DEFAULT_TARGET_FLAGS TARGET_CPU_DEFAULT
140 #undef  TARGET_HANDLE_OPTION
141 #define TARGET_HANDLE_OPTION m32r_handle_option
142
143 #undef  TARGET_ENCODE_SECTION_INFO
144 #define TARGET_ENCODE_SECTION_INFO m32r_encode_section_info
145 #undef  TARGET_IN_SMALL_DATA_P
146 #define TARGET_IN_SMALL_DATA_P m32r_in_small_data_p
147
148 #undef  TARGET_RTX_COSTS
149 #define TARGET_RTX_COSTS m32r_rtx_costs
150 #undef  TARGET_ADDRESS_COST
151 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
152
153 #undef  TARGET_PROMOTE_PROTOTYPES
154 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
155 #undef  TARGET_RETURN_IN_MEMORY
156 #define TARGET_RETURN_IN_MEMORY m32r_return_in_memory
157 #undef  TARGET_SETUP_INCOMING_VARARGS
158 #define TARGET_SETUP_INCOMING_VARARGS m32r_setup_incoming_varargs
159 #undef  TARGET_MUST_PASS_IN_STACK
160 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
161 #undef  TARGET_PASS_BY_REFERENCE
162 #define TARGET_PASS_BY_REFERENCE m32r_pass_by_reference
163 #undef  TARGET_ARG_PARTIAL_BYTES
164 #define TARGET_ARG_PARTIAL_BYTES m32r_arg_partial_bytes
165
166 #undef TARGET_CAN_ELIMINATE
167 #define TARGET_CAN_ELIMINATE m32r_can_eliminate
168
169 #undef TARGET_TRAMPOLINE_INIT
170 #define TARGET_TRAMPOLINE_INIT m32r_trampoline_init
171
172 struct gcc_target targetm = TARGET_INITIALIZER;
173 \f
174 /* Implement TARGET_HANDLE_OPTION.  */
175
176 static bool
177 m32r_handle_option (size_t code, const char *arg, int value)
178 {
179   switch (code)
180     {
181     case OPT_G:
182       g_switch_value = value;
183       g_switch_set = true;
184       return true;
185
186     case OPT_m32r:
187       target_flags &= ~(MASK_M32R2 | MASK_M32RX);
188       return true;
189
190     case OPT_mmodel_:
191       if (strcmp (arg, "small") == 0)
192         m32r_model = M32R_MODEL_SMALL;
193       else if (strcmp (arg, "medium") == 0)
194         m32r_model = M32R_MODEL_MEDIUM;
195       else if (strcmp (arg, "large") == 0)
196         m32r_model = M32R_MODEL_LARGE;
197       else
198         return false;
199       return true;
200
201     case OPT_msdata_:
202       if (strcmp (arg, "none") == 0)
203         m32r_sdata = M32R_SDATA_NONE;
204       else if (strcmp (arg, "sdata") == 0)
205         m32r_sdata = M32R_SDATA_SDATA;
206       else if (strcmp (arg, "use") == 0)
207         m32r_sdata = M32R_SDATA_USE;
208       else
209         return false;
210       return true;
211
212     case OPT_mno_flush_func:
213       m32r_cache_flush_func = NULL;
214       return true;
215
216     case OPT_mflush_trap_:
217       return value <= 15;
218
219     case OPT_mno_flush_trap:
220       m32r_cache_flush_trap = -1;
221       return true;
222
223     default:
224       return true;
225     }
226 }
227
228 /* Called by OVERRIDE_OPTIONS to initialize various things.  */
229
230 void
231 m32r_init (void)
232 {
233   init_reg_tables ();
234
235   /* Initialize array for TARGET_PRINT_OPERAND_PUNCT_VALID_P.  */
236   memset (m32r_punct_chars, 0, sizeof (m32r_punct_chars));
237   m32r_punct_chars['#'] = 1;
238   m32r_punct_chars['@'] = 1; /* ??? no longer used */
239
240   /* Provide default value if not specified.  */
241   if (!g_switch_set)
242     g_switch_value = SDATA_DEFAULT_SIZE;
243 }
244
245 /* Vectors to keep interesting information about registers where it can easily
246    be got.  We use to use the actual mode value as the bit number, but there
247    is (or may be) more than 32 modes now.  Instead we use two tables: one
248    indexed by hard register number, and one indexed by mode.  */
249
250 /* The purpose of m32r_mode_class is to shrink the range of modes so that
251    they all fit (as bit numbers) in a 32-bit word (again).  Each real mode is
252    mapped into one m32r_mode_class mode.  */
253
254 enum m32r_mode_class
255 {
256   C_MODE,
257   S_MODE, D_MODE, T_MODE, O_MODE,
258   SF_MODE, DF_MODE, TF_MODE, OF_MODE, A_MODE
259 };
260
261 /* Modes for condition codes.  */
262 #define C_MODES (1 << (int) C_MODE)
263
264 /* Modes for single-word and smaller quantities.  */
265 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
266
267 /* Modes for double-word and smaller quantities.  */
268 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
269
270 /* Modes for quad-word and smaller quantities.  */
271 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
272
273 /* Modes for accumulators.  */
274 #define A_MODES (1 << (int) A_MODE)
275
276 /* Value is 1 if register/mode pair is acceptable on arc.  */
277
278 const unsigned int m32r_hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] =
279 {
280   T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES,
281   T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, S_MODES, S_MODES, S_MODES,
282   S_MODES, C_MODES, A_MODES, A_MODES
283 };
284
285 unsigned int m32r_mode_class [NUM_MACHINE_MODES];
286
287 enum reg_class m32r_regno_reg_class[FIRST_PSEUDO_REGISTER];
288
289 static void
290 init_reg_tables (void)
291 {
292   int i;
293
294   for (i = 0; i < NUM_MACHINE_MODES; i++)
295     {
296       switch (GET_MODE_CLASS (i))
297         {
298         case MODE_INT:
299         case MODE_PARTIAL_INT:
300         case MODE_COMPLEX_INT:
301           if (GET_MODE_SIZE (i) <= 4)
302             m32r_mode_class[i] = 1 << (int) S_MODE;
303           else if (GET_MODE_SIZE (i) == 8)
304             m32r_mode_class[i] = 1 << (int) D_MODE;
305           else if (GET_MODE_SIZE (i) == 16)
306             m32r_mode_class[i] = 1 << (int) T_MODE;
307           else if (GET_MODE_SIZE (i) == 32)
308             m32r_mode_class[i] = 1 << (int) O_MODE;
309           else
310             m32r_mode_class[i] = 0;
311           break;
312         case MODE_FLOAT:
313         case MODE_COMPLEX_FLOAT:
314           if (GET_MODE_SIZE (i) <= 4)
315             m32r_mode_class[i] = 1 << (int) SF_MODE;
316           else if (GET_MODE_SIZE (i) == 8)
317             m32r_mode_class[i] = 1 << (int) DF_MODE;
318           else if (GET_MODE_SIZE (i) == 16)
319             m32r_mode_class[i] = 1 << (int) TF_MODE;
320           else if (GET_MODE_SIZE (i) == 32)
321             m32r_mode_class[i] = 1 << (int) OF_MODE;
322           else
323             m32r_mode_class[i] = 0;
324           break;
325         case MODE_CC:
326           m32r_mode_class[i] = 1 << (int) C_MODE;
327           break;
328         default:
329           m32r_mode_class[i] = 0;
330           break;
331         }
332     }
333
334   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
335     {
336       if (GPR_P (i))
337         m32r_regno_reg_class[i] = GENERAL_REGS;
338       else if (i == ARG_POINTER_REGNUM)
339         m32r_regno_reg_class[i] = GENERAL_REGS;
340       else
341         m32r_regno_reg_class[i] = NO_REGS;
342     }
343 }
344 \f
345 /* M32R specific attribute support.
346
347    interrupt - for interrupt functions
348
349    model - select code model used to access object
350
351         small: addresses use 24 bits, use bl to make calls
352         medium: addresses use 32 bits, use bl to make calls
353         large: addresses use 32 bits, use seth/add3/jl to make calls
354
355         Grep for MODEL in m32r.h for more info.  */
356
357 static tree small_ident1;
358 static tree small_ident2;
359 static tree medium_ident1;
360 static tree medium_ident2;
361 static tree large_ident1;
362 static tree large_ident2;
363
364 static void
365 init_idents (void)
366 {
367   if (small_ident1 == 0)
368     {
369       small_ident1 = get_identifier ("small");
370       small_ident2 = get_identifier ("__small__");
371       medium_ident1 = get_identifier ("medium");
372       medium_ident2 = get_identifier ("__medium__");
373       large_ident1 = get_identifier ("large");
374       large_ident2 = get_identifier ("__large__");
375     }
376 }
377
378 /* Handle an "model" attribute; arguments as in
379    struct attribute_spec.handler.  */
380 static tree
381 m32r_handle_model_attribute (tree *node ATTRIBUTE_UNUSED, tree name,
382                              tree args, int flags ATTRIBUTE_UNUSED,
383                              bool *no_add_attrs)
384 {
385   tree arg;
386
387   init_idents ();
388   arg = TREE_VALUE (args);
389
390   if (arg != small_ident1
391       && arg != small_ident2
392       && arg != medium_ident1
393       && arg != medium_ident2
394       && arg != large_ident1
395       && arg != large_ident2)
396     {
397       warning (OPT_Wattributes, "invalid argument of %qs attribute",
398                IDENTIFIER_POINTER (name));
399       *no_add_attrs = true;
400     }
401
402   return NULL_TREE;
403 }
404 \f
405 /* Encode section information of DECL, which is either a VAR_DECL,
406    FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
407
408    For the M32R we want to record:
409
410    - whether the object lives in .sdata/.sbss.
411    - what code model should be used to access the object
412 */
413
414 static void
415 m32r_encode_section_info (tree decl, rtx rtl, int first)
416 {
417   int extra_flags = 0;
418   tree model_attr;
419   enum m32r_model model;
420
421   default_encode_section_info (decl, rtl, first);
422
423   if (!DECL_P (decl))
424     return;
425
426   model_attr = lookup_attribute ("model", DECL_ATTRIBUTES (decl));
427   if (model_attr)
428     {
429       tree id;
430
431       init_idents ();
432
433       id = TREE_VALUE (TREE_VALUE (model_attr));
434
435       if (id == small_ident1 || id == small_ident2)
436         model = M32R_MODEL_SMALL;
437       else if (id == medium_ident1 || id == medium_ident2)
438         model = M32R_MODEL_MEDIUM;
439       else if (id == large_ident1 || id == large_ident2)
440         model = M32R_MODEL_LARGE;
441       else
442         gcc_unreachable (); /* shouldn't happen */
443     }
444   else
445     {
446       if (TARGET_MODEL_SMALL)
447         model = M32R_MODEL_SMALL;
448       else if (TARGET_MODEL_MEDIUM)
449         model = M32R_MODEL_MEDIUM;
450       else if (TARGET_MODEL_LARGE)
451         model = M32R_MODEL_LARGE;
452       else
453         gcc_unreachable (); /* shouldn't happen */
454     }
455   extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
456
457   if (extra_flags)
458     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= extra_flags;
459 }
460
461 /* Only mark the object as being small data area addressable if
462    it hasn't been explicitly marked with a code model.
463
464    The user can explicitly put an object in the small data area with the
465    section attribute.  If the object is in sdata/sbss and marked with a
466    code model do both [put the object in .sdata and mark it as being
467    addressed with a specific code model - don't mark it as being addressed
468    with an SDA reloc though].  This is ok and might be useful at times.  If
469    the object doesn't fit the linker will give an error.  */
470
471 static bool
472 m32r_in_small_data_p (const_tree decl)
473 {
474   const_tree section;
475
476   if (TREE_CODE (decl) != VAR_DECL)
477     return false;
478
479   if (lookup_attribute ("model", DECL_ATTRIBUTES (decl)))
480     return false;
481
482   section = DECL_SECTION_NAME (decl);
483   if (section)
484     {
485       const char *const name = TREE_STRING_POINTER (section);
486       if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
487         return true;
488     }
489   else
490     {
491       if (! TREE_READONLY (decl) && ! TARGET_SDATA_NONE)
492         {
493           int size = int_size_in_bytes (TREE_TYPE (decl));
494
495           if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
496             return true;
497         }
498     }
499
500   return false;
501 }
502
503 /* Do anything needed before RTL is emitted for each function.  */
504
505 void
506 m32r_init_expanders (void)
507 {
508   /* ??? At one point there was code here.  The function is left in
509      to make it easy to experiment.  */
510 }
511 \f
512 int
513 call_operand (rtx op, enum machine_mode mode)
514 {
515   if (!MEM_P (op))
516     return 0;
517   op = XEXP (op, 0);
518   return call_address_operand (op, mode);
519 }
520
521 /* Return 1 if OP is a reference to an object in .sdata/.sbss.  */
522
523 int
524 small_data_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
525 {
526   if (! TARGET_SDATA_USE)
527     return 0;
528
529   if (GET_CODE (op) == SYMBOL_REF)
530     return SYMBOL_REF_SMALL_P (op);
531
532   if (GET_CODE (op) == CONST
533       && GET_CODE (XEXP (op, 0)) == PLUS
534       && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
535       && satisfies_constraint_J (XEXP (XEXP (op, 0), 1)))
536     return SYMBOL_REF_SMALL_P (XEXP (XEXP (op, 0), 0));
537
538   return 0;
539 }
540
541 /* Return 1 if OP is a symbol that can use 24-bit addressing.  */
542
543 int
544 addr24_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
545 {
546   rtx sym;
547
548   if (flag_pic)
549     return 0;
550
551   if (GET_CODE (op) == LABEL_REF)
552     return TARGET_ADDR24;
553
554   if (GET_CODE (op) == SYMBOL_REF)
555     sym = op;
556   else if (GET_CODE (op) == CONST
557            && GET_CODE (XEXP (op, 0)) == PLUS
558            && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
559            && satisfies_constraint_M (XEXP (XEXP (op, 0), 1)))
560     sym = XEXP (XEXP (op, 0), 0);
561   else
562     return 0;
563
564   if (SYMBOL_REF_MODEL (sym) == M32R_MODEL_SMALL)
565     return 1;
566
567   if (TARGET_ADDR24
568       && (CONSTANT_POOL_ADDRESS_P (sym)
569           || LIT_NAME_P (XSTR (sym, 0))))
570     return 1;
571
572   return 0;
573 }
574
575 /* Return 1 if OP is a symbol that needs 32-bit addressing.  */
576
577 int
578 addr32_operand (rtx op, enum machine_mode mode)
579 {
580   rtx sym;
581
582   if (GET_CODE (op) == LABEL_REF)
583     return TARGET_ADDR32;
584
585   if (GET_CODE (op) == SYMBOL_REF)
586     sym = op;
587   else if (GET_CODE (op) == CONST
588            && GET_CODE (XEXP (op, 0)) == PLUS
589            && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
590            && CONST_INT_P (XEXP (XEXP (op, 0), 1))
591            && ! flag_pic)
592     sym = XEXP (XEXP (op, 0), 0);
593   else
594     return 0;
595
596   return (! addr24_operand (sym, mode)
597           && ! small_data_operand (sym, mode));
598 }
599
600 /* Return 1 if OP is a function that can be called with the `bl' insn.  */
601
602 int
603 call26_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
604 {
605   if (flag_pic)
606     return 1;
607
608   if (GET_CODE (op) == SYMBOL_REF)
609     return SYMBOL_REF_MODEL (op) != M32R_MODEL_LARGE;
610
611   return TARGET_CALL26;
612 }
613
614 /* Return 1 if OP is a DImode const we want to handle inline.
615    This must match the code in the movdi pattern.
616    It is used by the 'G' CONST_DOUBLE_OK_FOR_LETTER.  */
617
618 int
619 easy_di_const (rtx op)
620 {
621   rtx high_rtx, low_rtx;
622   HOST_WIDE_INT high, low;
623
624   split_double (op, &high_rtx, &low_rtx);
625   high = INTVAL (high_rtx);
626   low = INTVAL (low_rtx);
627   /* Pick constants loadable with 2 16-bit `ldi' insns.  */
628   if (high >= -128 && high <= 127
629       && low >= -128 && low <= 127)
630     return 1;
631   return 0;
632 }
633
634 /* Return 1 if OP is a DFmode const we want to handle inline.
635    This must match the code in the movdf pattern.
636    It is used by the 'H' CONST_DOUBLE_OK_FOR_LETTER.  */
637
638 int
639 easy_df_const (rtx op)
640 {
641   REAL_VALUE_TYPE r;
642   long l[2];
643
644   REAL_VALUE_FROM_CONST_DOUBLE (r, op);
645   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
646   if (l[0] == 0 && l[1] == 0)
647     return 1;
648   if ((l[0] & 0xffff) == 0 && l[1] == 0)
649     return 1;
650   return 0;
651 }
652
653 /* Return 1 if OP is (mem (reg ...)).
654    This is used in insn length calcs.  */
655
656 int
657 memreg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
658 {
659   return MEM_P (op) && REG_P (XEXP (op, 0));
660 }
661
662 /* Return nonzero if TYPE must be passed by indirect reference.  */
663
664 static bool
665 m32r_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
666                         enum machine_mode mode, const_tree type,
667                         bool named ATTRIBUTE_UNUSED)
668 {
669   int size;
670
671   if (type)
672     size = int_size_in_bytes (type);
673   else
674     size = GET_MODE_SIZE (mode);
675
676   return (size < 0 || size > 8);
677 }
678 \f
679 /* Comparisons.  */
680
681 /* X and Y are two things to compare using CODE.  Emit the compare insn and
682    return the rtx for compare [arg0 of the if_then_else].
683    If need_compare is true then the comparison insn must be generated, rather
684    than being subsumed into the following branch instruction.  */
685
686 rtx
687 gen_compare (enum rtx_code code, rtx x, rtx y, int need_compare)
688 {
689   enum rtx_code compare_code;
690   enum rtx_code branch_code;
691   rtx cc_reg = gen_rtx_REG (CCmode, CARRY_REGNUM);
692   int must_swap = 0;
693
694   switch (code)
695     {
696     case EQ:  compare_code = EQ;  branch_code = NE; break;
697     case NE:  compare_code = EQ;  branch_code = EQ; break;
698     case LT:  compare_code = LT;  branch_code = NE; break;
699     case LE:  compare_code = LT;  branch_code = EQ; must_swap = 1; break;
700     case GT:  compare_code = LT;  branch_code = NE; must_swap = 1; break;
701     case GE:  compare_code = LT;  branch_code = EQ; break;
702     case LTU: compare_code = LTU; branch_code = NE; break;
703     case LEU: compare_code = LTU; branch_code = EQ; must_swap = 1; break;
704     case GTU: compare_code = LTU; branch_code = NE; must_swap = 1; break;
705     case GEU: compare_code = LTU; branch_code = EQ; break;
706
707     default:
708       gcc_unreachable ();
709     }
710
711   if (need_compare)
712     {
713       switch (compare_code)
714         {
715         case EQ:
716           if (satisfies_constraint_P (y)                /* Reg equal to small const.  */
717               && y != const0_rtx)
718             {
719               rtx tmp = gen_reg_rtx (SImode);
720
721               emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
722               x = tmp;
723               y = const0_rtx;
724             }
725           else if (CONSTANT_P (y))                      /* Reg equal to const.  */
726             {
727               rtx tmp = force_reg (GET_MODE (x), y);
728               y = tmp;
729             }
730
731           if (register_operand (y, SImode)              /* Reg equal to reg.  */
732               || y == const0_rtx)                       /* Reg equal to zero.  */
733             {
734               emit_insn (gen_cmp_eqsi_insn (x, y));
735
736               return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
737             }
738           break;
739
740         case LT:
741           if (register_operand (y, SImode)
742               || satisfies_constraint_P (y))
743             {
744               rtx tmp = gen_reg_rtx (SImode);         /* Reg compared to reg.  */
745
746               switch (code)
747                 {
748                 case LT:
749                   emit_insn (gen_cmp_ltsi_insn (x, y));
750                   code = EQ;
751                   break;
752                 case LE:
753                   if (y == const0_rtx)
754                     tmp = const1_rtx;
755                   else
756                     emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
757                   emit_insn (gen_cmp_ltsi_insn (x, tmp));
758                   code = EQ;
759                   break;
760                 case GT:
761                   if (CONST_INT_P (y))
762                     tmp = gen_rtx_PLUS (SImode, y, const1_rtx);
763                   else
764                     emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
765                   emit_insn (gen_cmp_ltsi_insn (x, tmp));
766                   code = NE;
767                   break;
768                 case GE:
769                   emit_insn (gen_cmp_ltsi_insn (x, y));
770                   code = NE;
771                   break;
772                 default:
773                   gcc_unreachable ();
774                 }
775
776               return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
777             }
778           break;
779
780         case LTU:
781           if (register_operand (y, SImode)
782               || satisfies_constraint_P (y))
783             {
784               rtx tmp = gen_reg_rtx (SImode);         /* Reg (unsigned) compared to reg.  */
785
786               switch (code)
787                 {
788                 case LTU:
789                   emit_insn (gen_cmp_ltusi_insn (x, y));
790                   code = EQ;
791                   break;
792                 case LEU:
793                   if (y == const0_rtx)
794                     tmp = const1_rtx;
795                   else
796                     emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
797                   emit_insn (gen_cmp_ltusi_insn (x, tmp));
798                   code = EQ;
799                   break;
800                 case GTU:
801                   if (CONST_INT_P (y))
802                     tmp = gen_rtx_PLUS (SImode, y, const1_rtx);
803                   else
804                     emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
805                   emit_insn (gen_cmp_ltusi_insn (x, tmp));
806                   code = NE;
807                   break;
808                 case GEU:
809                   emit_insn (gen_cmp_ltusi_insn (x, y));
810                   code = NE;
811                   break;
812                 default:
813                   gcc_unreachable ();
814                 }
815
816               return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
817             }
818           break;
819
820         default:
821           gcc_unreachable ();
822         }
823     }
824   else
825     {
826       /* Reg/reg equal comparison.  */
827       if (compare_code == EQ
828           && register_operand (y, SImode))
829         return gen_rtx_fmt_ee (code, CCmode, x, y);
830
831       /* Reg/zero signed comparison.  */
832       if ((compare_code == EQ || compare_code == LT)
833           && y == const0_rtx)
834         return gen_rtx_fmt_ee (code, CCmode, x, y);
835
836       /* Reg/smallconst equal comparison.  */
837       if (compare_code == EQ
838           && satisfies_constraint_P (y))
839         {
840           rtx tmp = gen_reg_rtx (SImode);
841
842           emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
843           return gen_rtx_fmt_ee (code, CCmode, tmp, const0_rtx);
844         }
845
846       /* Reg/const equal comparison.  */
847       if (compare_code == EQ
848           && CONSTANT_P (y))
849         {
850           rtx tmp = force_reg (GET_MODE (x), y);
851
852           return gen_rtx_fmt_ee (code, CCmode, x, tmp);
853         }
854     }
855
856   if (CONSTANT_P (y))
857     {
858       if (must_swap)
859         y = force_reg (GET_MODE (x), y);
860       else
861         {
862           int ok_const = reg_or_int16_operand (y, GET_MODE (y));
863
864           if (! ok_const)
865             y = force_reg (GET_MODE (x), y);
866         }
867     }
868
869   switch (compare_code)
870     {
871     case EQ :
872       emit_insn (gen_cmp_eqsi_insn (must_swap ? y : x, must_swap ? x : y));
873       break;
874     case LT :
875       emit_insn (gen_cmp_ltsi_insn (must_swap ? y : x, must_swap ? x : y));
876       break;
877     case LTU :
878       emit_insn (gen_cmp_ltusi_insn (must_swap ? y : x, must_swap ? x : y));
879       break;
880
881     default:
882       gcc_unreachable ();
883     }
884
885   return gen_rtx_fmt_ee (branch_code, VOIDmode, cc_reg, CONST0_RTX (CCmode));
886 }
887
888 bool
889 gen_cond_store (enum rtx_code code, rtx op0, rtx op1, rtx op2)
890 {
891   enum machine_mode mode = GET_MODE (op0);
892
893   gcc_assert (mode == SImode);
894   switch (code)
895     {
896     case EQ:
897       if (!register_operand (op1, mode))
898         op1 = force_reg (mode, op1);
899
900       if (TARGET_M32RX || TARGET_M32R2)
901         {
902           if (!reg_or_zero_operand (op2, mode))
903             op2 = force_reg (mode, op2);
904
905           emit_insn (gen_seq_insn_m32rx (op0, op1, op2));
906           return true;
907         }
908       if (CONST_INT_P (op2) && INTVAL (op2) == 0)
909         {
910           emit_insn (gen_seq_zero_insn (op0, op1));
911           return true;
912         }
913
914       if (!reg_or_eq_int16_operand (op2, mode))
915         op2 = force_reg (mode, op2);
916
917       emit_insn (gen_seq_insn (op0, op1, op2));
918       return true;
919
920     case NE:
921       if (!CONST_INT_P (op2)
922           || (INTVAL (op2) != 0 && satisfies_constraint_K (op2)))
923         {
924           rtx reg;
925
926           if (reload_completed || reload_in_progress)
927             return false;
928
929           reg = gen_reg_rtx (SImode);
930           emit_insn (gen_xorsi3 (reg, op1, op2));
931           op1 = reg;
932
933           if (!register_operand (op1, mode))
934             op1 = force_reg (mode, op1);
935
936           emit_insn (gen_sne_zero_insn (op0, op1));
937           return true;
938         }
939       return false;
940
941     case LT:
942     case GT:
943       if (code == GT)
944         {
945           rtx tmp = op2;
946           op2 = op1;
947           op1 = tmp;
948           code = LT;
949         }
950
951       if (!register_operand (op1, mode))
952         op1 = force_reg (mode, op1);
953
954       if (!reg_or_int16_operand (op2, mode))
955         op2 = force_reg (mode, op2);
956
957       emit_insn (gen_slt_insn (op0, op1, op2));
958       return true;
959
960     case LTU:
961     case GTU:
962       if (code == GTU)
963         {
964           rtx tmp = op2;
965           op2 = op1;
966           op1 = tmp;
967           code = LTU;
968         }
969
970       if (!register_operand (op1, mode))
971         op1 = force_reg (mode, op1);
972
973       if (!reg_or_int16_operand (op2, mode))
974         op2 = force_reg (mode, op2);
975
976       emit_insn (gen_sltu_insn (op0, op1, op2));
977       return true;
978
979     case GE:
980     case GEU:
981       if (!register_operand (op1, mode))
982         op1 = force_reg (mode, op1);
983
984       if (!reg_or_int16_operand (op2, mode))
985         op2 = force_reg (mode, op2);
986
987       if (code == GE)
988         emit_insn (gen_sge_insn (op0, op1, op2));
989       else
990         emit_insn (gen_sgeu_insn (op0, op1, op2));
991       return true;
992
993     case LE:
994     case LEU:
995       if (!register_operand (op1, mode))
996         op1 = force_reg (mode, op1);
997
998       if (CONST_INT_P (op2))
999         {
1000           HOST_WIDE_INT value = INTVAL (op2);
1001           if (value >= 2147483647)
1002             {
1003               emit_move_insn (op0, const1_rtx);
1004               return true;
1005             }
1006
1007           op2 = GEN_INT (value + 1);
1008           if (value < -32768 || value >= 32767)
1009             op2 = force_reg (mode, op2);
1010
1011           if (code == LEU)
1012             emit_insn (gen_sltu_insn (op0, op1, op2));
1013           else
1014             emit_insn (gen_slt_insn (op0, op1, op2));
1015           return true;
1016         }
1017
1018       if (!register_operand (op2, mode))
1019         op2 = force_reg (mode, op2);
1020
1021       if (code == LEU)
1022         emit_insn (gen_sleu_insn (op0, op1, op2));
1023       else
1024         emit_insn (gen_sle_insn (op0, op1, op2));
1025       return true;
1026
1027     default:
1028       gcc_unreachable ();
1029     }
1030 }
1031
1032 \f
1033 /* Split a 2 word move (DI or DF) into component parts.  */
1034
1035 rtx
1036 gen_split_move_double (rtx operands[])
1037 {
1038   enum machine_mode mode = GET_MODE (operands[0]);
1039   rtx dest = operands[0];
1040   rtx src  = operands[1];
1041   rtx val;
1042
1043   /* We might have (SUBREG (MEM)) here, so just get rid of the
1044      subregs to make this code simpler.  It is safe to call
1045      alter_subreg any time after reload.  */
1046   if (GET_CODE (dest) == SUBREG)
1047     alter_subreg (&dest);
1048   if (GET_CODE (src) == SUBREG)
1049     alter_subreg (&src);
1050
1051   start_sequence ();
1052   if (REG_P (dest))
1053     {
1054       int dregno = REGNO (dest);
1055
1056       /* Reg = reg.  */
1057       if (REG_P (src))
1058         {
1059           int sregno = REGNO (src);
1060
1061           int reverse = (dregno == sregno + 1);
1062
1063           /* We normally copy the low-numbered register first.  However, if
1064              the first register operand 0 is the same as the second register of
1065              operand 1, we must copy in the opposite order.  */
1066           emit_insn (gen_rtx_SET (VOIDmode,
1067                                   operand_subword (dest, reverse, TRUE, mode),
1068                                   operand_subword (src,  reverse, TRUE, mode)));
1069
1070           emit_insn (gen_rtx_SET (VOIDmode,
1071                                   operand_subword (dest, !reverse, TRUE, mode),
1072                                   operand_subword (src,  !reverse, TRUE, mode)));
1073         }
1074
1075       /* Reg = constant.  */
1076       else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
1077         {
1078           rtx words[2];
1079           split_double (src, &words[0], &words[1]);
1080           emit_insn (gen_rtx_SET (VOIDmode,
1081                                   operand_subword (dest, 0, TRUE, mode),
1082                                   words[0]));
1083
1084           emit_insn (gen_rtx_SET (VOIDmode,
1085                                   operand_subword (dest, 1, TRUE, mode),
1086                                   words[1]));
1087         }
1088
1089       /* Reg = mem.  */
1090       else if (MEM_P (src))
1091         {
1092           /* If the high-address word is used in the address, we must load it
1093              last.  Otherwise, load it first.  */
1094           int reverse
1095             = (refers_to_regno_p (dregno, dregno + 1, XEXP (src, 0), 0) != 0);
1096
1097           /* We used to optimize loads from single registers as
1098
1099                 ld r1,r3+; ld r2,r3
1100
1101              if r3 were not used subsequently.  However, the REG_NOTES aren't
1102              propagated correctly by the reload phase, and it can cause bad
1103              code to be generated.  We could still try:
1104
1105                 ld r1,r3+; ld r2,r3; addi r3,-4
1106
1107              which saves 2 bytes and doesn't force longword alignment.  */
1108           emit_insn (gen_rtx_SET (VOIDmode,
1109                                   operand_subword (dest, reverse, TRUE, mode),
1110                                   adjust_address (src, SImode,
1111                                                   reverse * UNITS_PER_WORD)));
1112
1113           emit_insn (gen_rtx_SET (VOIDmode,
1114                                   operand_subword (dest, !reverse, TRUE, mode),
1115                                   adjust_address (src, SImode,
1116                                                   !reverse * UNITS_PER_WORD)));
1117         }
1118       else
1119         gcc_unreachable ();
1120     }
1121
1122   /* Mem = reg.  */
1123   /* We used to optimize loads from single registers as
1124
1125         st r1,r3; st r2,+r3
1126
1127      if r3 were not used subsequently.  However, the REG_NOTES aren't
1128      propagated correctly by the reload phase, and it can cause bad
1129      code to be generated.  We could still try:
1130
1131         st r1,r3; st r2,+r3; addi r3,-4
1132
1133      which saves 2 bytes and doesn't force longword alignment.  */
1134   else if (MEM_P (dest) && REG_P (src))
1135     {
1136       emit_insn (gen_rtx_SET (VOIDmode,
1137                               adjust_address (dest, SImode, 0),
1138                               operand_subword (src, 0, TRUE, mode)));
1139
1140       emit_insn (gen_rtx_SET (VOIDmode,
1141                               adjust_address (dest, SImode, UNITS_PER_WORD),
1142                               operand_subword (src, 1, TRUE, mode)));
1143     }
1144
1145   else
1146     gcc_unreachable ();
1147
1148   val = get_insns ();
1149   end_sequence ();
1150   return val;
1151 }
1152
1153 \f
1154 static int
1155 m32r_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1156                         tree type, bool named ATTRIBUTE_UNUSED)
1157 {
1158   int words;
1159   unsigned int size =
1160     (((mode == BLKmode && type)
1161       ? (unsigned int) int_size_in_bytes (type)
1162       : GET_MODE_SIZE (mode)) + UNITS_PER_WORD - 1)
1163     / UNITS_PER_WORD;
1164
1165   if (*cum >= M32R_MAX_PARM_REGS)
1166     words = 0;
1167   else if (*cum + size > M32R_MAX_PARM_REGS)
1168     words = (*cum + size) - M32R_MAX_PARM_REGS;
1169   else
1170     words = 0;
1171
1172   return words * UNITS_PER_WORD;
1173 }
1174
1175 /* Worker function for TARGET_RETURN_IN_MEMORY.  */
1176
1177 static bool
1178 m32r_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1179 {
1180   return m32r_pass_by_reference (NULL, TYPE_MODE (type), type, false);
1181 }
1182
1183 /* Do any needed setup for a variadic function.  For the M32R, we must
1184    create a register parameter block, and then copy any anonymous arguments
1185    in registers to memory.
1186
1187    CUM has not been updated for the last named argument which has type TYPE
1188    and mode MODE, and we rely on this fact.  */
1189
1190 static void
1191 m32r_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1192                              tree type, int *pretend_size, int no_rtl)
1193 {
1194   int first_anon_arg;
1195
1196   if (no_rtl)
1197     return;
1198
1199   /* All BLKmode values are passed by reference.  */
1200   gcc_assert (mode != BLKmode);
1201
1202   first_anon_arg = (ROUND_ADVANCE_CUM (*cum, mode, type)
1203                     + ROUND_ADVANCE_ARG (mode, type));
1204
1205   if (first_anon_arg < M32R_MAX_PARM_REGS)
1206     {
1207       /* Note that first_reg_offset < M32R_MAX_PARM_REGS.  */
1208       int first_reg_offset = first_anon_arg;
1209       /* Size in words to "pretend" allocate.  */
1210       int size = M32R_MAX_PARM_REGS - first_reg_offset;
1211       rtx regblock;
1212
1213       regblock = gen_frame_mem (BLKmode,
1214                                 plus_constant (arg_pointer_rtx,
1215                                                FIRST_PARM_OFFSET (0)));
1216       set_mem_alias_set (regblock, get_varargs_alias_set ());
1217       move_block_from_reg (first_reg_offset, regblock, size);
1218
1219       *pretend_size = (size * UNITS_PER_WORD);
1220     }
1221 }
1222
1223 \f
1224 /* Return true if INSN is real instruction bearing insn.  */
1225
1226 static int
1227 m32r_is_insn (rtx insn)
1228 {
1229   return (NONDEBUG_INSN_P (insn)
1230           && GET_CODE (PATTERN (insn)) != USE
1231           && GET_CODE (PATTERN (insn)) != CLOBBER
1232           && GET_CODE (PATTERN (insn)) != ADDR_VEC);
1233 }
1234
1235 /* Increase the priority of long instructions so that the
1236    short instructions are scheduled ahead of the long ones.  */
1237
1238 static int
1239 m32r_adjust_priority (rtx insn, int priority)
1240 {
1241   if (m32r_is_insn (insn)
1242       && get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1243     priority <<= 3;
1244
1245   return priority;
1246 }
1247
1248 \f
1249 /* Indicate how many instructions can be issued at the same time.
1250    This is sort of a lie.  The m32r can issue only 1 long insn at
1251    once, but it can issue 2 short insns.  The default therefore is
1252    set at 2, but this can be overridden by the command line option
1253    -missue-rate=1.  */
1254
1255 static int
1256 m32r_issue_rate (void)
1257 {
1258   return ((TARGET_LOW_ISSUE_RATE) ? 1 : 2);
1259 }
1260 \f
1261 /* Cost functions.  */
1262
1263 static bool
1264 m32r_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, int *total,
1265                 bool speed ATTRIBUTE_UNUSED)
1266 {
1267   switch (code)
1268     {
1269       /* Small integers are as cheap as registers.  4 byte values can be
1270          fetched as immediate constants - let's give that the cost of an
1271          extra insn.  */
1272     case CONST_INT:
1273       if (INT16_P (INTVAL (x)))
1274         {
1275           *total = 0;
1276           return true;
1277         }
1278       /* FALLTHRU */
1279
1280     case CONST:
1281     case LABEL_REF:
1282     case SYMBOL_REF:
1283       *total = COSTS_N_INSNS (1);
1284       return true;
1285
1286     case CONST_DOUBLE:
1287       {
1288         rtx high, low;
1289
1290         split_double (x, &high, &low);
1291         *total = COSTS_N_INSNS (!INT16_P (INTVAL (high))
1292                                 + !INT16_P (INTVAL (low)));
1293         return true;
1294       }
1295
1296     case MULT:
1297       *total = COSTS_N_INSNS (3);
1298       return true;
1299
1300     case DIV:
1301     case UDIV:
1302     case MOD:
1303     case UMOD:
1304       *total = COSTS_N_INSNS (10);
1305       return true;
1306
1307     default:
1308       return false;
1309     }
1310 }
1311 \f
1312 /* Type of function DECL.
1313
1314    The result is cached.  To reset the cache at the end of a function,
1315    call with DECL = NULL_TREE.  */
1316
1317 enum m32r_function_type
1318 m32r_compute_function_type (tree decl)
1319 {
1320   /* Cached value.  */
1321   static enum m32r_function_type fn_type = M32R_FUNCTION_UNKNOWN;
1322   /* Last function we were called for.  */
1323   static tree last_fn = NULL_TREE;
1324
1325   /* Resetting the cached value?  */
1326   if (decl == NULL_TREE)
1327     {
1328       fn_type = M32R_FUNCTION_UNKNOWN;
1329       last_fn = NULL_TREE;
1330       return fn_type;
1331     }
1332
1333   if (decl == last_fn && fn_type != M32R_FUNCTION_UNKNOWN)
1334     return fn_type;
1335
1336   /* Compute function type.  */
1337   fn_type = (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE
1338              ? M32R_FUNCTION_INTERRUPT
1339              : M32R_FUNCTION_NORMAL);
1340
1341   last_fn = decl;
1342   return fn_type;
1343 }
1344 \f/* Function prologue/epilogue handlers.  */
1345
1346 /* M32R stack frames look like:
1347
1348              Before call                       After call
1349         +-----------------------+       +-----------------------+
1350         |                       |       |                       |
1351    high |  local variables,     |       |  local variables,     |
1352    mem  |  reg save area, etc.  |       |  reg save area, etc.  |
1353         |                       |       |                       |
1354         +-----------------------+       +-----------------------+
1355         |                       |       |                       |
1356         |  arguments on stack.  |       |  arguments on stack.  |
1357         |                       |       |                       |
1358   SP+0->+-----------------------+       +-----------------------+
1359                                         |  reg parm save area,  |
1360                                         |  only created for     |
1361                                         |  variable argument    |
1362                                         |  functions            |
1363                                         +-----------------------+
1364                                         |   previous frame ptr  |
1365                                         +-----------------------+
1366                                         |                       |
1367                                         |  register save area   |
1368                                         |                       |
1369                                         +-----------------------+
1370                                         |    return address     |
1371                                         +-----------------------+
1372                                         |                       |
1373                                         |  local variables      |
1374                                         |                       |
1375                                         +-----------------------+
1376                                         |                       |
1377                                         |  alloca allocations   |
1378                                         |                       |
1379                                         +-----------------------+
1380                                         |                       |
1381    low                                  |  arguments on stack   |
1382    memory                               |                       |
1383                                   SP+0->+-----------------------+
1384
1385 Notes:
1386 1) The "reg parm save area" does not exist for non variable argument fns.
1387 2) The "reg parm save area" can be eliminated completely if we saved regs
1388    containing anonymous args separately but that complicates things too
1389    much (so it's not done).
1390 3) The return address is saved after the register save area so as to have as
1391    many insns as possible between the restoration of `lr' and the `jmp lr'.  */
1392
1393 /* Structure to be filled in by m32r_compute_frame_size with register
1394    save masks, and offsets for the current function.  */
1395 struct m32r_frame_info
1396 {
1397   unsigned int total_size;      /* # bytes that the entire frame takes up.  */
1398   unsigned int extra_size;      /* # bytes of extra stuff.  */
1399   unsigned int pretend_size;    /* # bytes we push and pretend caller did.  */
1400   unsigned int args_size;       /* # bytes that outgoing arguments take up.  */
1401   unsigned int reg_size;        /* # bytes needed to store regs.  */
1402   unsigned int var_size;        /* # bytes that variables take up.  */
1403   unsigned int gmask;           /* Mask of saved gp registers.  */
1404   unsigned int save_fp;         /* Nonzero if fp must be saved.  */
1405   unsigned int save_lr;         /* Nonzero if lr (return addr) must be saved.  */
1406   int          initialized;     /* Nonzero if frame size already calculated.  */
1407 };
1408
1409 /* Current frame information calculated by m32r_compute_frame_size.  */
1410 static struct m32r_frame_info current_frame_info;
1411
1412 /* Zero structure to initialize current_frame_info.  */
1413 static struct m32r_frame_info zero_frame_info;
1414
1415 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1416 #define RETURN_ADDR_MASK   (1 << (RETURN_ADDR_REGNUM))
1417
1418 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1419    The return address and frame pointer are treated separately.
1420    Don't consider them here.  */
1421 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1422   ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1423    && (df_regs_ever_live_p (regno) && (!call_really_used_regs[regno] || interrupt_p)))
1424
1425 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM))
1426 #define MUST_SAVE_RETURN_ADDR   (df_regs_ever_live_p (RETURN_ADDR_REGNUM) || crtl->profile)
1427
1428 #define SHORT_INSN_SIZE 2       /* Size of small instructions.  */
1429 #define LONG_INSN_SIZE 4        /* Size of long instructions.  */
1430
1431 /* Return the bytes needed to compute the frame pointer from the current
1432    stack pointer.
1433
1434    SIZE is the size needed for local variables.  */
1435
1436 unsigned int
1437 m32r_compute_frame_size (int size)      /* # of var. bytes allocated.  */
1438 {
1439   unsigned int regno;
1440   unsigned int total_size, var_size, args_size, pretend_size, extra_size;
1441   unsigned int reg_size, frame_size;
1442   unsigned int gmask;
1443   enum m32r_function_type fn_type;
1444   int interrupt_p;
1445   int pic_reg_used = flag_pic && (crtl->uses_pic_offset_table
1446                                   | crtl->profile);
1447
1448   var_size      = M32R_STACK_ALIGN (size);
1449   args_size     = M32R_STACK_ALIGN (crtl->outgoing_args_size);
1450   pretend_size  = crtl->args.pretend_args_size;
1451   extra_size    = FIRST_PARM_OFFSET (0);
1452   total_size    = extra_size + pretend_size + args_size + var_size;
1453   reg_size      = 0;
1454   gmask         = 0;
1455
1456   /* See if this is an interrupt handler.  Call used registers must be saved
1457      for them too.  */
1458   fn_type = m32r_compute_function_type (current_function_decl);
1459   interrupt_p = M32R_INTERRUPT_P (fn_type);
1460
1461   /* Calculate space needed for registers.  */
1462   for (regno = 0; regno < M32R_MAX_INT_REGS; regno++)
1463     {
1464       if (MUST_SAVE_REGISTER (regno, interrupt_p)
1465           || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1466         {
1467           reg_size += UNITS_PER_WORD;
1468           gmask |= 1 << regno;
1469         }
1470     }
1471
1472   current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
1473   current_frame_info.save_lr = MUST_SAVE_RETURN_ADDR || pic_reg_used;
1474
1475   reg_size += ((current_frame_info.save_fp + current_frame_info.save_lr)
1476                * UNITS_PER_WORD);
1477   total_size += reg_size;
1478
1479   /* ??? Not sure this is necessary, and I don't think the epilogue
1480      handler will do the right thing if this changes total_size.  */
1481   total_size = M32R_STACK_ALIGN (total_size);
1482
1483   frame_size = total_size - (pretend_size + reg_size);
1484
1485   /* Save computed information.  */
1486   current_frame_info.total_size   = total_size;
1487   current_frame_info.extra_size   = extra_size;
1488   current_frame_info.pretend_size = pretend_size;
1489   current_frame_info.var_size     = var_size;
1490   current_frame_info.args_size    = args_size;
1491   current_frame_info.reg_size     = reg_size;
1492   current_frame_info.gmask        = gmask;
1493   current_frame_info.initialized  = reload_completed;
1494
1495   /* Ok, we're done.  */
1496   return total_size;
1497 }
1498
1499 /* Worker function for TARGET_CAN_ELIMINATE.  */
1500
1501 bool
1502 m32r_can_eliminate (const int from, const int to)
1503 {
1504   return (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM
1505           ? ! frame_pointer_needed
1506           : true);
1507 }
1508
1509 \f
1510 /* The table we use to reference PIC data.  */
1511 static rtx global_offset_table;
1512
1513 static void
1514 m32r_reload_lr (rtx sp, int size)
1515 {
1516   rtx lr = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
1517
1518   if (size == 0)
1519     emit_insn (gen_movsi (lr, gen_frame_mem (Pmode, sp)));
1520   else if (size < 32768)
1521     emit_insn (gen_movsi (lr, gen_frame_mem (Pmode,
1522                                              gen_rtx_PLUS (Pmode, sp,
1523                                                            GEN_INT (size)))));
1524   else
1525     {
1526       rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1527
1528       emit_insn (gen_movsi (tmp, GEN_INT (size)));
1529       emit_insn (gen_addsi3 (tmp, tmp, sp));
1530       emit_insn (gen_movsi (lr, gen_frame_mem (Pmode, tmp)));
1531     }
1532
1533   emit_use (lr);
1534 }
1535
1536 void
1537 m32r_load_pic_register (void)
1538 {
1539   global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
1540   emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
1541                          GEN_INT (TARGET_MODEL_SMALL)));
1542
1543   /* Need to emit this whether or not we obey regdecls,
1544      since setjmp/longjmp can cause life info to screw up.  */
1545   emit_use (pic_offset_table_rtx);
1546 }
1547
1548 /* Expand the m32r prologue as a series of insns.  */
1549
1550 void
1551 m32r_expand_prologue (void)
1552 {
1553   int regno;
1554   int frame_size;
1555   unsigned int gmask;
1556   int pic_reg_used = flag_pic && (crtl->uses_pic_offset_table
1557                                   | crtl->profile);
1558
1559   if (! current_frame_info.initialized)
1560     m32r_compute_frame_size (get_frame_size ());
1561
1562   gmask = current_frame_info.gmask;
1563
1564   /* These cases shouldn't happen.  Catch them now.  */
1565   gcc_assert (current_frame_info.total_size || !gmask);
1566
1567   /* Allocate space for register arguments if this is a variadic function.  */
1568   if (current_frame_info.pretend_size != 0)
1569     {
1570       /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1571          the wrong result on a 64-bit host.  */
1572       HOST_WIDE_INT pretend_size = current_frame_info.pretend_size;
1573       emit_insn (gen_addsi3 (stack_pointer_rtx,
1574                              stack_pointer_rtx,
1575                              GEN_INT (-pretend_size)));
1576     }
1577
1578   /* Save any registers we need to and set up fp.  */
1579   if (current_frame_info.save_fp)
1580     emit_insn (gen_movsi_push (stack_pointer_rtx, frame_pointer_rtx));
1581
1582   gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1583
1584   /* Save any needed call-saved regs (and call-used if this is an
1585      interrupt handler).  */
1586   for (regno = 0; regno <= M32R_MAX_INT_REGS; ++regno)
1587     {
1588       if ((gmask & (1 << regno)) != 0)
1589         emit_insn (gen_movsi_push (stack_pointer_rtx,
1590                                    gen_rtx_REG (Pmode, regno)));
1591     }
1592
1593   if (current_frame_info.save_lr)
1594     emit_insn (gen_movsi_push (stack_pointer_rtx,
1595                                gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1596
1597   /* Allocate the stack frame.  */
1598   frame_size = (current_frame_info.total_size
1599                 - (current_frame_info.pretend_size
1600                    + current_frame_info.reg_size));
1601
1602   if (frame_size == 0)
1603     ; /* Nothing to do.  */
1604   else if (frame_size <= 32768)
1605     emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1606                            GEN_INT (-frame_size)));
1607   else
1608     {
1609       rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1610
1611       emit_insn (gen_movsi (tmp, GEN_INT (frame_size)));
1612       emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
1613     }
1614
1615   if (frame_pointer_needed)
1616     emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
1617
1618   if (crtl->profile)
1619     /* Push lr for mcount (form_pc, x).  */
1620     emit_insn (gen_movsi_push (stack_pointer_rtx,
1621                                gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1622
1623   if (pic_reg_used)
1624     {
1625       m32r_load_pic_register ();
1626       m32r_reload_lr (stack_pointer_rtx,
1627                       (crtl->profile ? 0 : frame_size));
1628     }
1629
1630   if (crtl->profile && !pic_reg_used)
1631     emit_insn (gen_blockage ());
1632 }
1633
1634 \f
1635 /* Set up the stack and frame pointer (if desired) for the function.
1636    Note, if this is changed, you need to mirror the changes in
1637    m32r_compute_frame_size which calculates the prolog size.  */
1638
1639 static void
1640 m32r_output_function_prologue (FILE * file, HOST_WIDE_INT size)
1641 {
1642   enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1643
1644   /* If this is an interrupt handler, mark it as such.  */
1645   if (M32R_INTERRUPT_P (fn_type))
1646     fprintf (file, "\t%s interrupt handler\n", ASM_COMMENT_START);
1647
1648   if (! current_frame_info.initialized)
1649     m32r_compute_frame_size (size);
1650
1651   /* This is only for the human reader.  */
1652   fprintf (file,
1653            "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
1654            ASM_COMMENT_START,
1655            current_frame_info.var_size,
1656            current_frame_info.reg_size / 4,
1657            current_frame_info.args_size,
1658            current_frame_info.extra_size);
1659 }
1660 \f
1661 /* Output RTL to pop register REGNO from the stack.  */
1662
1663 static void
1664 pop (int regno)
1665 {
1666   rtx x;
1667
1668   x = emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno),
1669                                 stack_pointer_rtx));
1670   add_reg_note (x, REG_INC, stack_pointer_rtx);
1671 }
1672
1673 /* Expand the m32r epilogue as a series of insns.  */
1674
1675 void
1676 m32r_expand_epilogue (void)
1677 {
1678   int regno;
1679   int noepilogue = FALSE;
1680   int total_size;
1681
1682   gcc_assert (current_frame_info.initialized);
1683   total_size = current_frame_info.total_size;
1684
1685   if (total_size == 0)
1686     {
1687       rtx insn = get_last_insn ();
1688
1689       /* If the last insn was a BARRIER, we don't have to write any code
1690          because a jump (aka return) was put there.  */
1691       if (insn && NOTE_P (insn))
1692         insn = prev_nonnote_insn (insn);
1693       if (insn && BARRIER_P (insn))
1694         noepilogue = TRUE;
1695     }
1696
1697   if (!noepilogue)
1698     {
1699       unsigned int var_size = current_frame_info.var_size;
1700       unsigned int args_size = current_frame_info.args_size;
1701       unsigned int gmask = current_frame_info.gmask;
1702       int can_trust_sp_p = !cfun->calls_alloca;
1703
1704       if (flag_exceptions)
1705         emit_insn (gen_blockage ());
1706
1707       /* The first thing to do is point the sp at the bottom of the register
1708          save area.  */
1709       if (can_trust_sp_p)
1710         {
1711           unsigned int reg_offset = var_size + args_size;
1712
1713           if (reg_offset == 0)
1714             ; /* Nothing to do.  */
1715           else if (reg_offset < 32768)
1716             emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1717                            GEN_INT (reg_offset)));
1718           else
1719             {
1720               rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1721
1722               emit_insn (gen_movsi (tmp, GEN_INT (reg_offset)));
1723               emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1724                                      tmp));
1725             }
1726         }
1727       else if (frame_pointer_needed)
1728         {
1729           unsigned int reg_offset = var_size + args_size;
1730
1731           if (reg_offset == 0)
1732             emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1733           else if (reg_offset < 32768)
1734             emit_insn (gen_addsi3 (stack_pointer_rtx, frame_pointer_rtx,
1735                            GEN_INT (reg_offset)));
1736           else
1737             {
1738               rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1739
1740               emit_insn (gen_movsi (tmp, GEN_INT (reg_offset)));
1741               emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1742               emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1743                                      tmp));
1744             }
1745         }
1746       else
1747         gcc_unreachable ();
1748
1749       if (current_frame_info.save_lr)
1750         pop (RETURN_ADDR_REGNUM);
1751
1752       /* Restore any saved registers, in reverse order of course.  */
1753       gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1754       for (regno = M32R_MAX_INT_REGS - 1; regno >= 0; --regno)
1755         {
1756           if ((gmask & (1L << regno)) != 0)
1757             pop (regno);
1758         }
1759
1760       if (current_frame_info.save_fp)
1761         pop (FRAME_POINTER_REGNUM);
1762
1763       /* Remove varargs area if present.  */
1764       if (current_frame_info.pretend_size != 0)
1765         emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1766                                GEN_INT (current_frame_info.pretend_size)));
1767
1768       emit_insn (gen_blockage ());
1769     }
1770 }
1771
1772 /* Do any necessary cleanup after a function to restore stack, frame,
1773    and regs.  */
1774
1775 static void
1776 m32r_output_function_epilogue (FILE * file ATTRIBUTE_UNUSED,
1777                                HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1778 {
1779   /* Reset state info for each function.  */
1780   current_frame_info = zero_frame_info;
1781   m32r_compute_function_type (NULL_TREE);
1782 }
1783 \f
1784 /* Return nonzero if this function is known to have a null or 1 instruction
1785    epilogue.  */
1786
1787 int
1788 direct_return (void)
1789 {
1790   if (!reload_completed)
1791     return FALSE;
1792
1793   if (M32R_INTERRUPT_P (m32r_compute_function_type (current_function_decl)))
1794     return FALSE;
1795
1796   if (! current_frame_info.initialized)
1797     m32r_compute_frame_size (get_frame_size ());
1798
1799   return current_frame_info.total_size == 0;
1800 }
1801
1802 \f
1803 /* PIC.  */
1804
1805 int
1806 m32r_legitimate_pic_operand_p (rtx x)
1807 {
1808   if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1809     return 0;
1810
1811   if (GET_CODE (x) == CONST
1812       && GET_CODE (XEXP (x, 0)) == PLUS
1813       && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1814           || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
1815       && (CONST_INT_P (XEXP (XEXP (x, 0), 1))))
1816     return 0;
1817
1818   return 1;
1819 }
1820
1821 rtx
1822 m32r_legitimize_pic_address (rtx orig, rtx reg)
1823 {
1824 #ifdef DEBUG_PIC
1825   printf("m32r_legitimize_pic_address()\n");
1826 #endif
1827
1828   if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
1829     {
1830       rtx pic_ref, address;
1831       rtx insn;
1832       int subregs = 0;
1833
1834       if (reg == 0)
1835         {
1836           gcc_assert (!reload_in_progress && !reload_completed);
1837           reg = gen_reg_rtx (Pmode);
1838
1839           subregs = 1;
1840         }
1841
1842       if (subregs)
1843         address = gen_reg_rtx (Pmode);
1844       else
1845         address = reg;
1846
1847       crtl->uses_pic_offset_table = 1;
1848
1849       if (GET_CODE (orig) == LABEL_REF
1850           || (GET_CODE (orig) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (orig)))
1851         {
1852           emit_insn (gen_gotoff_load_addr (reg, orig));
1853           emit_insn (gen_addsi3 (reg, reg, pic_offset_table_rtx));
1854           return reg;
1855         }
1856
1857       emit_insn (gen_pic_load_addr (address, orig));
1858
1859       emit_insn (gen_addsi3 (address, address, pic_offset_table_rtx));
1860       pic_ref = gen_const_mem (Pmode, address);
1861       insn = emit_move_insn (reg, pic_ref);
1862 #if 0
1863       /* Put a REG_EQUAL note on this insn, so that it can be optimized
1864          by loop.  */
1865       set_unique_reg_note (insn, REG_EQUAL, orig);
1866 #endif
1867       return reg;
1868     }
1869   else if (GET_CODE (orig) == CONST)
1870     {
1871       rtx base, offset;
1872
1873       if (GET_CODE (XEXP (orig, 0)) == PLUS
1874           && XEXP (XEXP (orig, 0), 1) == pic_offset_table_rtx)
1875         return orig;
1876
1877       if (reg == 0)
1878         {
1879           gcc_assert (!reload_in_progress && !reload_completed);
1880           reg = gen_reg_rtx (Pmode);
1881         }
1882
1883       if (GET_CODE (XEXP (orig, 0)) == PLUS)
1884         {
1885           base = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
1886           if (base == reg)
1887             offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), NULL_RTX);
1888           else
1889             offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), reg);
1890         }
1891       else
1892         return orig;
1893
1894       if (CONST_INT_P (offset))
1895         {
1896           if (INT16_P (INTVAL (offset)))
1897             return plus_constant (base, INTVAL (offset));
1898           else
1899             {
1900               gcc_assert (! reload_in_progress && ! reload_completed);
1901               offset = force_reg (Pmode, offset);
1902             }
1903         }
1904
1905       return gen_rtx_PLUS (Pmode, base, offset);
1906     }
1907
1908   return orig;
1909 }
1910
1911 static rtx
1912 m32r_legitimize_address (rtx x, rtx orig_x ATTRIBUTE_UNUSED,
1913                          enum machine_mode mode ATTRIBUTE_UNUSED)
1914 {
1915   if (flag_pic)
1916     return m32r_legitimize_pic_address (x, NULL_RTX);
1917   else
1918     return x;
1919 }
1920 \f
1921 /* Nested function support.  */
1922
1923 /* Emit RTL insns to initialize the variable parts of a trampoline.
1924    FNADDR is an RTX for the address of the function's pure code.
1925    CXT is an RTX for the static chain value for the function.  */
1926
1927 void
1928 m32r_initialize_trampoline (rtx tramp ATTRIBUTE_UNUSED,
1929                             rtx fnaddr ATTRIBUTE_UNUSED,
1930                             rtx cxt ATTRIBUTE_UNUSED)
1931 {
1932 }
1933 \f
1934 static void
1935 m32r_file_start (void)
1936 {
1937   default_file_start ();
1938
1939   if (flag_verbose_asm)
1940     fprintf (asm_out_file,
1941              "%s M32R/D special options: -G " HOST_WIDE_INT_PRINT_UNSIGNED "\n",
1942              ASM_COMMENT_START, g_switch_value);
1943
1944   if (TARGET_LITTLE_ENDIAN)
1945     fprintf (asm_out_file, "\t.little\n");
1946 }
1947 \f
1948 /* Print operand X (an rtx) in assembler syntax to file FILE.
1949    CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
1950    For `%' followed by punctuation, CODE is the punctuation and X is null.  */
1951
1952 static void
1953 m32r_print_operand (FILE * file, rtx x, int code)
1954 {
1955   rtx addr;
1956
1957   switch (code)
1958     {
1959       /* The 's' and 'p' codes are used by output_block_move() to
1960          indicate post-increment 's'tores and 'p're-increment loads.  */
1961     case 's':
1962       if (REG_P (x))
1963         fprintf (file, "@+%s", reg_names [REGNO (x)]);
1964       else
1965         output_operand_lossage ("invalid operand to %%s code");
1966       return;
1967
1968     case 'p':
1969       if (REG_P (x))
1970         fprintf (file, "@%s+", reg_names [REGNO (x)]);
1971       else
1972         output_operand_lossage ("invalid operand to %%p code");
1973       return;
1974
1975     case 'R' :
1976       /* Write second word of DImode or DFmode reference,
1977          register or memory.  */
1978       if (REG_P (x))
1979         fputs (reg_names[REGNO (x)+1], file);
1980       else if (MEM_P (x))
1981         {
1982           fprintf (file, "@(");
1983           /* Handle possible auto-increment.  Since it is pre-increment and
1984              we have already done it, we can just use an offset of four.  */
1985           /* ??? This is taken from rs6000.c I think.  I don't think it is
1986              currently necessary, but keep it around.  */
1987           if (GET_CODE (XEXP (x, 0)) == PRE_INC
1988               || GET_CODE (XEXP (x, 0)) == PRE_DEC)
1989             output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
1990           else
1991             output_address (plus_constant (XEXP (x, 0), 4));
1992           fputc (')', file);
1993         }
1994       else
1995         output_operand_lossage ("invalid operand to %%R code");
1996       return;
1997
1998     case 'H' : /* High word.  */
1999     case 'L' : /* Low word.  */
2000       if (REG_P (x))
2001         {
2002           /* L = least significant word, H = most significant word.  */
2003           if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L'))
2004             fputs (reg_names[REGNO (x)], file);
2005           else
2006             fputs (reg_names[REGNO (x)+1], file);
2007         }
2008       else if (CONST_INT_P (x)
2009                || GET_CODE (x) == CONST_DOUBLE)
2010         {
2011           rtx first, second;
2012
2013           split_double (x, &first, &second);
2014           fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2015                    code == 'L' ? INTVAL (first) : INTVAL (second));
2016         }
2017       else
2018         output_operand_lossage ("invalid operand to %%H/%%L code");
2019       return;
2020
2021     case 'A' :
2022       {
2023         char str[30];
2024
2025         if (GET_CODE (x) != CONST_DOUBLE
2026             || GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
2027           fatal_insn ("bad insn for 'A'", x);
2028
2029         real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1);
2030         fprintf (file, "%s", str);
2031         return;
2032       }
2033
2034     case 'B' : /* Bottom half.  */
2035     case 'T' : /* Top half.  */
2036       /* Output the argument to a `seth' insn (sets the Top half-word).
2037          For constants output arguments to a seth/or3 pair to set Top and
2038          Bottom halves.  For symbols output arguments to a seth/add3 pair to
2039          set Top and Bottom halves.  The difference exists because for
2040          constants seth/or3 is more readable but for symbols we need to use
2041          the same scheme as `ld' and `st' insns (16-bit addend is signed).  */
2042       switch (GET_CODE (x))
2043         {
2044         case CONST_INT :
2045         case CONST_DOUBLE :
2046           {
2047             rtx first, second;
2048
2049             split_double (x, &first, &second);
2050             x = WORDS_BIG_ENDIAN ? second : first;
2051             fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2052                      (code == 'B'
2053                       ? INTVAL (x) & 0xffff
2054                       : (INTVAL (x) >> 16) & 0xffff));
2055           }
2056           return;
2057         case CONST :
2058         case SYMBOL_REF :
2059           if (code == 'B'
2060               && small_data_operand (x, VOIDmode))
2061             {
2062               fputs ("sda(", file);
2063               output_addr_const (file, x);
2064               fputc (')', file);
2065               return;
2066             }
2067           /* fall through */
2068         case LABEL_REF :
2069           fputs (code == 'T' ? "shigh(" : "low(", file);
2070           output_addr_const (file, x);
2071           fputc (')', file);
2072           return;
2073         default :
2074           output_operand_lossage ("invalid operand to %%T/%%B code");
2075           return;
2076         }
2077       break;
2078
2079     case 'U' :
2080       /* ??? wip */
2081       /* Output a load/store with update indicator if appropriate.  */
2082       if (MEM_P (x))
2083         {
2084           if (GET_CODE (XEXP (x, 0)) == PRE_INC
2085               || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2086             fputs (".a", file);
2087         }
2088       else
2089         output_operand_lossage ("invalid operand to %%U code");
2090       return;
2091
2092     case 'N' :
2093       /* Print a constant value negated.  */
2094       if (CONST_INT_P (x))
2095         output_addr_const (file, GEN_INT (- INTVAL (x)));
2096       else
2097         output_operand_lossage ("invalid operand to %%N code");
2098       return;
2099
2100     case 'X' :
2101       /* Print a const_int in hex.  Used in comments.  */
2102       if (CONST_INT_P (x))
2103         fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
2104       return;
2105
2106     case '#' :
2107       fputs (IMMEDIATE_PREFIX, file);
2108       return;
2109
2110     case 0 :
2111       /* Do nothing special.  */
2112       break;
2113
2114     default :
2115       /* Unknown flag.  */
2116       output_operand_lossage ("invalid operand output code");
2117     }
2118
2119   switch (GET_CODE (x))
2120     {
2121     case REG :
2122       fputs (reg_names[REGNO (x)], file);
2123       break;
2124
2125     case MEM :
2126       addr = XEXP (x, 0);
2127       if (GET_CODE (addr) == PRE_INC)
2128         {
2129           if (!REG_P (XEXP (addr, 0)))
2130             fatal_insn ("pre-increment address is not a register", x);
2131
2132           fprintf (file, "@+%s", reg_names[REGNO (XEXP (addr, 0))]);
2133         }
2134       else if (GET_CODE (addr) == PRE_DEC)
2135         {
2136           if (!REG_P (XEXP (addr, 0)))
2137             fatal_insn ("pre-decrement address is not a register", x);
2138
2139           fprintf (file, "@-%s", reg_names[REGNO (XEXP (addr, 0))]);
2140         }
2141       else if (GET_CODE (addr) == POST_INC)
2142         {
2143           if (!REG_P (XEXP (addr, 0)))
2144             fatal_insn ("post-increment address is not a register", x);
2145
2146           fprintf (file, "@%s+", reg_names[REGNO (XEXP (addr, 0))]);
2147         }
2148       else
2149         {
2150           fputs ("@(", file);
2151           output_address (XEXP (x, 0));
2152           fputc (')', file);
2153         }
2154       break;
2155
2156     case CONST_DOUBLE :
2157       /* We handle SFmode constants here as output_addr_const doesn't.  */
2158       if (GET_MODE (x) == SFmode)
2159         {
2160           REAL_VALUE_TYPE d;
2161           long l;
2162
2163           REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2164           REAL_VALUE_TO_TARGET_SINGLE (d, l);
2165           fprintf (file, "0x%08lx", l);
2166           break;
2167         }
2168
2169       /* Fall through.  Let output_addr_const deal with it.  */
2170
2171     default :
2172       output_addr_const (file, x);
2173       break;
2174     }
2175 }
2176
2177 /* Print a memory address as an operand to reference that memory location.  */
2178
2179 static void
2180 m32r_print_operand_address (FILE * file, rtx addr)
2181 {
2182   rtx base;
2183   rtx index = 0;
2184   int offset = 0;
2185
2186   switch (GET_CODE (addr))
2187     {
2188     case REG :
2189       fputs (reg_names[REGNO (addr)], file);
2190       break;
2191
2192     case PLUS :
2193       if (CONST_INT_P (XEXP (addr, 0)))
2194         offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
2195       else if (CONST_INT_P (XEXP (addr, 1)))
2196         offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
2197       else
2198         base = XEXP (addr, 0), index = XEXP (addr, 1);
2199       if (REG_P (base))
2200         {
2201           /* Print the offset first (if present) to conform to the manual.  */
2202           if (index == 0)
2203             {
2204               if (offset != 0)
2205                 fprintf (file, "%d,", offset);
2206               fputs (reg_names[REGNO (base)], file);
2207             }
2208           /* The chip doesn't support this, but left in for generality.  */
2209           else if (REG_P (index))
2210             fprintf (file, "%s,%s",
2211                      reg_names[REGNO (base)], reg_names[REGNO (index)]);
2212           /* Not sure this can happen, but leave in for now.  */
2213           else if (GET_CODE (index) == SYMBOL_REF)
2214             {
2215               output_addr_const (file, index);
2216               fputc (',', file);
2217               fputs (reg_names[REGNO (base)], file);
2218             }
2219           else
2220             fatal_insn ("bad address", addr);
2221         }
2222       else if (GET_CODE (base) == LO_SUM)
2223         {
2224           gcc_assert (!index && REG_P (XEXP (base, 0)));
2225           if (small_data_operand (XEXP (base, 1), VOIDmode))
2226             fputs ("sda(", file);
2227           else
2228             fputs ("low(", file);
2229           output_addr_const (file, plus_constant (XEXP (base, 1), offset));
2230           fputs ("),", file);
2231           fputs (reg_names[REGNO (XEXP (base, 0))], file);
2232         }
2233       else
2234         fatal_insn ("bad address", addr);
2235       break;
2236
2237     case LO_SUM :
2238       if (!REG_P (XEXP (addr, 0)))
2239         fatal_insn ("lo_sum not of register", addr);
2240       if (small_data_operand (XEXP (addr, 1), VOIDmode))
2241         fputs ("sda(", file);
2242       else
2243         fputs ("low(", file);
2244       output_addr_const (file, XEXP (addr, 1));
2245       fputs ("),", file);
2246       fputs (reg_names[REGNO (XEXP (addr, 0))], file);
2247       break;
2248
2249     case PRE_INC :      /* Assume SImode.  */
2250       fprintf (file, "+%s", reg_names[REGNO (XEXP (addr, 0))]);
2251       break;
2252
2253     case PRE_DEC :      /* Assume SImode.  */
2254       fprintf (file, "-%s", reg_names[REGNO (XEXP (addr, 0))]);
2255       break;
2256
2257     case POST_INC :     /* Assume SImode.  */
2258       fprintf (file, "%s+", reg_names[REGNO (XEXP (addr, 0))]);
2259       break;
2260
2261     default :
2262       output_addr_const (file, addr);
2263       break;
2264     }
2265 }
2266
2267 static bool
2268 m32r_print_operand_punct_valid_p (unsigned char code)
2269 {
2270   return m32r_punct_chars[code];
2271 }
2272
2273 /* Return true if the operands are the constants 0 and 1.  */
2274
2275 int
2276 zero_and_one (rtx operand1, rtx operand2)
2277 {
2278   return
2279        CONST_INT_P (operand1)
2280     && CONST_INT_P (operand2)
2281     && (  ((INTVAL (operand1) == 0) && (INTVAL (operand2) == 1))
2282         ||((INTVAL (operand1) == 1) && (INTVAL (operand2) == 0)));
2283 }
2284
2285 /* Generate the correct assembler code to handle the conditional loading of a
2286    value into a register.  It is known that the operands satisfy the
2287    conditional_move_operand() function above.  The destination is operand[0].
2288    The condition is operand [1].  The 'true' value is operand [2] and the
2289    'false' value is operand [3].  */
2290
2291 char *
2292 emit_cond_move (rtx * operands, rtx insn ATTRIBUTE_UNUSED)
2293 {
2294   static char buffer [100];
2295   const char * dest = reg_names [REGNO (operands [0])];
2296
2297   buffer [0] = 0;
2298
2299   /* Destination must be a register.  */
2300   gcc_assert (REG_P (operands [0]));
2301   gcc_assert (conditional_move_operand (operands [2], SImode));
2302   gcc_assert (conditional_move_operand (operands [3], SImode));
2303
2304   /* Check to see if the test is reversed.  */
2305   if (GET_CODE (operands [1]) == NE)
2306     {
2307       rtx tmp = operands [2];
2308       operands [2] = operands [3];
2309       operands [3] = tmp;
2310     }
2311
2312   sprintf (buffer, "mvfc %s, cbr", dest);
2313
2314   /* If the true value was '0' then we need to invert the results of the move.  */
2315   if (INTVAL (operands [2]) == 0)
2316     sprintf (buffer + strlen (buffer), "\n\txor3 %s, %s, #1",
2317              dest, dest);
2318
2319   return buffer;
2320 }
2321
2322 /* Returns true if the registers contained in the two
2323    rtl expressions are different.  */
2324
2325 int
2326 m32r_not_same_reg (rtx a, rtx b)
2327 {
2328   int reg_a = -1;
2329   int reg_b = -2;
2330
2331   while (GET_CODE (a) == SUBREG)
2332     a = SUBREG_REG (a);
2333
2334   if (REG_P (a))
2335     reg_a = REGNO (a);
2336
2337   while (GET_CODE (b) == SUBREG)
2338     b = SUBREG_REG (b);
2339
2340   if (REG_P (b))
2341     reg_b = REGNO (b);
2342
2343   return reg_a != reg_b;
2344 }
2345
2346 \f
2347 rtx
2348 m32r_function_symbol (const char *name)
2349 {
2350   int extra_flags = 0;
2351   enum m32r_model model;
2352   rtx sym = gen_rtx_SYMBOL_REF (Pmode, name);
2353
2354   if (TARGET_MODEL_SMALL)
2355     model = M32R_MODEL_SMALL;
2356   else if (TARGET_MODEL_MEDIUM)
2357     model = M32R_MODEL_MEDIUM;
2358   else if (TARGET_MODEL_LARGE)
2359     model = M32R_MODEL_LARGE;
2360   else
2361     gcc_unreachable (); /* Shouldn't happen.  */
2362   extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
2363
2364   if (extra_flags)
2365     SYMBOL_REF_FLAGS (sym) |= extra_flags;
2366
2367   return sym;
2368 }
2369
2370 /* Use a library function to move some bytes.  */
2371
2372 static void
2373 block_move_call (rtx dest_reg, rtx src_reg, rtx bytes_rtx)
2374 {
2375   /* We want to pass the size as Pmode, which will normally be SImode
2376      but will be DImode if we are using 64-bit longs and pointers.  */
2377   if (GET_MODE (bytes_rtx) != VOIDmode
2378       && GET_MODE (bytes_rtx) != Pmode)
2379     bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
2380
2381   emit_library_call (m32r_function_symbol ("memcpy"), LCT_NORMAL,
2382                      VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
2383                      convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
2384                                       TYPE_UNSIGNED (sizetype)),
2385                      TYPE_MODE (sizetype));
2386 }
2387
2388 /* Expand string/block move operations.
2389
2390    operands[0] is the pointer to the destination.
2391    operands[1] is the pointer to the source.
2392    operands[2] is the number of bytes to move.
2393    operands[3] is the alignment.
2394
2395    Returns 1 upon success, 0 otherwise.  */
2396
2397 int
2398 m32r_expand_block_move (rtx operands[])
2399 {
2400   rtx           orig_dst  = operands[0];
2401   rtx           orig_src  = operands[1];
2402   rtx           bytes_rtx = operands[2];
2403   rtx           align_rtx = operands[3];
2404   int           constp    = CONST_INT_P (bytes_rtx);
2405   HOST_WIDE_INT bytes     = constp ? INTVAL (bytes_rtx) : 0;
2406   int           align     = INTVAL (align_rtx);
2407   int           leftover;
2408   rtx           src_reg;
2409   rtx           dst_reg;
2410
2411   if (constp && bytes <= 0)
2412     return 1;
2413
2414   /* Move the address into scratch registers.  */
2415   dst_reg = copy_addr_to_reg (XEXP (orig_dst, 0));
2416   src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2417
2418   if (align > UNITS_PER_WORD)
2419     align = UNITS_PER_WORD;
2420
2421   /* If we prefer size over speed, always use a function call.
2422      If we do not know the size, use a function call.
2423      If the blocks are not word aligned, use a function call.  */
2424   if (optimize_size || ! constp || align != UNITS_PER_WORD)
2425     {
2426       block_move_call (dst_reg, src_reg, bytes_rtx);
2427       return 0;
2428     }
2429
2430   leftover = bytes % MAX_MOVE_BYTES;
2431   bytes   -= leftover;
2432
2433   /* If necessary, generate a loop to handle the bulk of the copy.  */
2434   if (bytes)
2435     {
2436       rtx label = NULL_RTX;
2437       rtx final_src = NULL_RTX;
2438       rtx at_a_time = GEN_INT (MAX_MOVE_BYTES);
2439       rtx rounded_total = GEN_INT (bytes);
2440       rtx new_dst_reg = gen_reg_rtx (SImode);
2441       rtx new_src_reg = gen_reg_rtx (SImode);
2442
2443       /* If we are going to have to perform this loop more than
2444          once, then generate a label and compute the address the
2445          source register will contain upon completion of the final
2446          iteration.  */
2447       if (bytes > MAX_MOVE_BYTES)
2448         {
2449           final_src = gen_reg_rtx (Pmode);
2450
2451           if (INT16_P(bytes))
2452             emit_insn (gen_addsi3 (final_src, src_reg, rounded_total));
2453           else
2454             {
2455               emit_insn (gen_movsi (final_src, rounded_total));
2456               emit_insn (gen_addsi3 (final_src, final_src, src_reg));
2457             }
2458
2459           label = gen_label_rtx ();
2460           emit_label (label);
2461         }
2462
2463       /* It is known that output_block_move() will update src_reg to point
2464          to the word after the end of the source block, and dst_reg to point
2465          to the last word of the destination block, provided that the block
2466          is MAX_MOVE_BYTES long.  */
2467       emit_insn (gen_movmemsi_internal (dst_reg, src_reg, at_a_time,
2468                                         new_dst_reg, new_src_reg));
2469       emit_move_insn (dst_reg, new_dst_reg);
2470       emit_move_insn (src_reg, new_src_reg);
2471       emit_insn (gen_addsi3 (dst_reg, dst_reg, GEN_INT (4)));
2472
2473       if (bytes > MAX_MOVE_BYTES)
2474         {
2475           rtx test = gen_rtx_NE (VOIDmode, src_reg, final_src);
2476           emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label));
2477         }
2478     }
2479
2480   if (leftover)
2481     emit_insn (gen_movmemsi_internal (dst_reg, src_reg, GEN_INT (leftover),
2482                                       gen_reg_rtx (SImode),
2483                                       gen_reg_rtx (SImode)));
2484   return 1;
2485 }
2486
2487 \f
2488 /* Emit load/stores for a small constant word aligned block_move.
2489
2490    operands[0] is the memory address of the destination.
2491    operands[1] is the memory address of the source.
2492    operands[2] is the number of bytes to move.
2493    operands[3] is a temp register.
2494    operands[4] is a temp register.  */
2495
2496 void
2497 m32r_output_block_move (rtx insn ATTRIBUTE_UNUSED, rtx operands[])
2498 {
2499   HOST_WIDE_INT bytes = INTVAL (operands[2]);
2500   int           first_time;
2501   int           got_extra = 0;
2502
2503   gcc_assert (bytes >= 1 && bytes <= MAX_MOVE_BYTES);
2504
2505   /* We do not have a post-increment store available, so the first set of
2506      stores are done without any increment, then the remaining ones can use
2507      the pre-increment addressing mode.
2508
2509      Note: expand_block_move() also relies upon this behavior when building
2510      loops to copy large blocks.  */
2511   first_time = 1;
2512
2513   while (bytes > 0)
2514     {
2515       if (bytes >= 8)
2516         {
2517           if (first_time)
2518             {
2519               output_asm_insn ("ld\t%5, %p1", operands);
2520               output_asm_insn ("ld\t%6, %p1", operands);
2521               output_asm_insn ("st\t%5, @%0", operands);
2522               output_asm_insn ("st\t%6, %s0", operands);
2523             }
2524           else
2525             {
2526               output_asm_insn ("ld\t%5, %p1", operands);
2527               output_asm_insn ("ld\t%6, %p1", operands);
2528               output_asm_insn ("st\t%5, %s0", operands);
2529               output_asm_insn ("st\t%6, %s0", operands);
2530             }
2531
2532           bytes -= 8;
2533         }
2534       else if (bytes >= 4)
2535         {
2536           if (bytes > 4)
2537             got_extra = 1;
2538
2539           output_asm_insn ("ld\t%5, %p1", operands);
2540
2541           if (got_extra)
2542             output_asm_insn ("ld\t%6, %p1", operands);
2543
2544           if (first_time)
2545             output_asm_insn ("st\t%5, @%0", operands);
2546           else
2547             output_asm_insn ("st\t%5, %s0", operands);
2548
2549           bytes -= 4;
2550         }
2551       else
2552         {
2553           /* Get the entire next word, even though we do not want all of it.
2554              The saves us from doing several smaller loads, and we assume that
2555              we cannot cause a page fault when at least part of the word is in
2556              valid memory [since we don't get called if things aren't properly
2557              aligned].  */
2558           int dst_offset = first_time ? 0 : 4;
2559           /* The amount of increment we have to make to the
2560              destination pointer.  */
2561           int dst_inc_amount = dst_offset + bytes - 4;
2562           /* The same for the source pointer.  */
2563           int src_inc_amount = bytes;
2564           int last_shift;
2565           rtx my_operands[3];
2566
2567           /* If got_extra is true then we have already loaded
2568              the next word as part of loading and storing the previous word.  */
2569           if (! got_extra)
2570             output_asm_insn ("ld\t%6, @%1", operands);
2571
2572           if (bytes >= 2)
2573             {
2574               bytes -= 2;
2575
2576               output_asm_insn ("sra3\t%5, %6, #16", operands);
2577               my_operands[0] = operands[5];
2578               my_operands[1] = GEN_INT (dst_offset);
2579               my_operands[2] = operands[0];
2580               output_asm_insn ("sth\t%0, @(%1,%2)", my_operands);
2581
2582               /* If there is a byte left to store then increment the
2583                  destination address and shift the contents of the source
2584                  register down by 8 bits.  We could not do the address
2585                  increment in the store half word instruction, because it does
2586                  not have an auto increment mode.  */
2587               if (bytes > 0)  /* assert (bytes == 1) */
2588                 {
2589                   dst_offset += 2;
2590                   last_shift = 8;
2591                 }
2592             }
2593           else
2594             last_shift = 24;
2595
2596           if (bytes > 0)
2597             {
2598               my_operands[0] = operands[6];
2599               my_operands[1] = GEN_INT (last_shift);
2600               output_asm_insn ("srai\t%0, #%1", my_operands);
2601               my_operands[0] = operands[6];
2602               my_operands[1] = GEN_INT (dst_offset);
2603               my_operands[2] = operands[0];
2604               output_asm_insn ("stb\t%0, @(%1,%2)", my_operands);
2605             }
2606
2607           /* Update the destination pointer if needed.  We have to do
2608              this so that the patterns matches what we output in this
2609              function.  */
2610           if (dst_inc_amount
2611               && !find_reg_note (insn, REG_UNUSED, operands[0]))
2612             {
2613               my_operands[0] = operands[0];
2614               my_operands[1] = GEN_INT (dst_inc_amount);
2615               output_asm_insn ("addi\t%0, #%1", my_operands);
2616             }
2617
2618           /* Update the source pointer if needed.  We have to do this
2619              so that the patterns matches what we output in this
2620              function.  */
2621           if (src_inc_amount
2622               && !find_reg_note (insn, REG_UNUSED, operands[1]))
2623             {
2624               my_operands[0] = operands[1];
2625               my_operands[1] = GEN_INT (src_inc_amount);
2626               output_asm_insn ("addi\t%0, #%1", my_operands);
2627             }
2628
2629           bytes = 0;
2630         }
2631
2632       first_time = 0;
2633     }
2634 }
2635
2636 /* Return true if using NEW_REG in place of OLD_REG is ok.  */
2637
2638 int
2639 m32r_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
2640                            unsigned int new_reg)
2641 {
2642   /* Interrupt routines can't clobber any register that isn't already used.  */
2643   if (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl))
2644       && !df_regs_ever_live_p (new_reg))
2645     return 0;
2646
2647   return 1;
2648 }
2649
2650 rtx
2651 m32r_return_addr (int count)
2652 {
2653   if (count != 0)
2654     return const0_rtx;
2655
2656   return get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM);
2657 }
2658
2659 static void
2660 m32r_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2661 {
2662   emit_move_insn (adjust_address (m_tramp, SImode, 0),
2663                   gen_int_mode (TARGET_LITTLE_ENDIAN ?
2664                                 0x017e8e17 : 0x178e7e01, SImode));
2665   emit_move_insn (adjust_address (m_tramp, SImode, 4),
2666                   gen_int_mode (TARGET_LITTLE_ENDIAN ?
2667                                 0x0c00ae86 : 0x86ae000c, SImode));
2668   emit_move_insn (adjust_address (m_tramp, SImode, 8),
2669                   gen_int_mode (TARGET_LITTLE_ENDIAN ?
2670                                 0xe627871e : 0x1e8727e6, SImode));
2671   emit_move_insn (adjust_address (m_tramp, SImode, 12),
2672                   gen_int_mode (TARGET_LITTLE_ENDIAN ?
2673                                 0xc616c626 : 0x26c61fc6, SImode));
2674   emit_move_insn (adjust_address (m_tramp, SImode, 16),
2675                   chain_value);
2676   emit_move_insn (adjust_address (m_tramp, SImode, 20),
2677                   XEXP (DECL_RTL (fndecl), 0));
2678
2679   if (m32r_cache_flush_trap >= 0)
2680     emit_insn (gen_flush_icache
2681                (validize_mem (adjust_address (m_tramp, SImode, 0)),
2682                 gen_int_mode (m32r_cache_flush_trap, SImode)));
2683   else if (m32r_cache_flush_func && m32r_cache_flush_func[0])
2684     emit_library_call (m32r_function_symbol (m32r_cache_flush_func),
2685                        LCT_NORMAL, VOIDmode, 3, XEXP (m_tramp, 0), Pmode,
2686                        gen_int_mode (TRAMPOLINE_SIZE, SImode), SImode,
2687                        GEN_INT (3), SImode);
2688 }