Rebase.
[official-gcc.git] / gcc / config / m32r / m32r.c
blob35c136edb994a59f963c48b9a79afc43deb38fac
1 /* Subroutines used for code generation on the Renesas M32R cpu.
2 Copyright (C) 1996-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "tree.h"
25 #include "stor-layout.h"
26 #include "varasm.h"
27 #include "stringpool.h"
28 #include "calls.h"
29 #include "rtl.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "output.h"
35 #include "dbxout.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "expr.h"
39 #include "function.h"
40 #include "recog.h"
41 #include "diagnostic-core.h"
42 #include "ggc.h"
43 #include "df.h"
44 #include "tm_p.h"
45 #include "target.h"
46 #include "target-def.h"
47 #include "tm-constrs.h"
48 #include "opts.h"
49 #include "builtins.h"
51 /* Array of valid operand punctuation characters. */
52 static char m32r_punct_chars[256];
54 /* Machine-specific symbol_ref flags. */
55 #define SYMBOL_FLAG_MODEL_SHIFT SYMBOL_FLAG_MACH_DEP_SHIFT
56 #define SYMBOL_REF_MODEL(X) \
57 ((enum m32r_model) ((SYMBOL_REF_FLAGS (X) >> SYMBOL_FLAG_MODEL_SHIFT) & 3))
59 /* For string literals, etc. */
60 #define LIT_NAME_P(NAME) ((NAME)[0] == '*' && (NAME)[1] == '.')
62 /* Forward declaration. */
63 static void m32r_option_override (void);
64 static void init_reg_tables (void);
65 static void block_move_call (rtx, rtx, rtx);
66 static int m32r_is_insn (rtx);
67 static bool m32r_legitimate_address_p (enum machine_mode, rtx, bool);
68 static rtx m32r_legitimize_address (rtx, rtx, enum machine_mode);
69 static bool m32r_mode_dependent_address_p (const_rtx, addr_space_t);
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);
77 static void m32r_file_start (void);
79 static int m32r_adjust_priority (rtx, int);
80 static int m32r_issue_rate (void);
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 rtx m32r_function_value (const_tree, const_tree, bool);
86 static rtx m32r_libcall_value (enum machine_mode, const_rtx);
87 static bool m32r_function_value_regno_p (const unsigned int);
88 static void m32r_setup_incoming_varargs (cumulative_args_t, enum machine_mode,
89 tree, int *, int);
90 static void init_idents (void);
91 static bool m32r_rtx_costs (rtx, int, int, int, int *, bool speed);
92 static int m32r_memory_move_cost (enum machine_mode, reg_class_t, bool);
93 static bool m32r_pass_by_reference (cumulative_args_t, enum machine_mode,
94 const_tree, bool);
95 static int m32r_arg_partial_bytes (cumulative_args_t, enum machine_mode,
96 tree, bool);
97 static rtx m32r_function_arg (cumulative_args_t, enum machine_mode,
98 const_tree, bool);
99 static void m32r_function_arg_advance (cumulative_args_t, enum machine_mode,
100 const_tree, bool);
101 static bool m32r_can_eliminate (const int, const int);
102 static void m32r_conditional_register_usage (void);
103 static void m32r_trampoline_init (rtx, tree, rtx);
104 static bool m32r_legitimate_constant_p (enum machine_mode, rtx);
106 /* M32R specific attributes. */
108 static const struct attribute_spec m32r_attribute_table[] =
110 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
111 affects_type_identity } */
112 { "interrupt", 0, 0, true, false, false, NULL, false },
113 { "model", 1, 1, true, false, false, m32r_handle_model_attribute,
114 false },
115 { NULL, 0, 0, false, false, false, NULL, false }
118 /* Initialize the GCC target structure. */
119 #undef TARGET_ATTRIBUTE_TABLE
120 #define TARGET_ATTRIBUTE_TABLE m32r_attribute_table
122 #undef TARGET_LEGITIMATE_ADDRESS_P
123 #define TARGET_LEGITIMATE_ADDRESS_P m32r_legitimate_address_p
124 #undef TARGET_LEGITIMIZE_ADDRESS
125 #define TARGET_LEGITIMIZE_ADDRESS m32r_legitimize_address
126 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
127 #define TARGET_MODE_DEPENDENT_ADDRESS_P m32r_mode_dependent_address_p
129 #undef TARGET_ASM_ALIGNED_HI_OP
130 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
131 #undef TARGET_ASM_ALIGNED_SI_OP
132 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
134 #undef TARGET_PRINT_OPERAND
135 #define TARGET_PRINT_OPERAND m32r_print_operand
136 #undef TARGET_PRINT_OPERAND_ADDRESS
137 #define TARGET_PRINT_OPERAND_ADDRESS m32r_print_operand_address
138 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
139 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P m32r_print_operand_punct_valid_p
141 #undef TARGET_ASM_FUNCTION_PROLOGUE
142 #define TARGET_ASM_FUNCTION_PROLOGUE m32r_output_function_prologue
143 #undef TARGET_ASM_FUNCTION_EPILOGUE
144 #define TARGET_ASM_FUNCTION_EPILOGUE m32r_output_function_epilogue
146 #undef TARGET_ASM_FILE_START
147 #define TARGET_ASM_FILE_START m32r_file_start
149 #undef TARGET_SCHED_ADJUST_PRIORITY
150 #define TARGET_SCHED_ADJUST_PRIORITY m32r_adjust_priority
151 #undef TARGET_SCHED_ISSUE_RATE
152 #define TARGET_SCHED_ISSUE_RATE m32r_issue_rate
154 #undef TARGET_OPTION_OVERRIDE
155 #define TARGET_OPTION_OVERRIDE m32r_option_override
157 #undef TARGET_ENCODE_SECTION_INFO
158 #define TARGET_ENCODE_SECTION_INFO m32r_encode_section_info
159 #undef TARGET_IN_SMALL_DATA_P
160 #define TARGET_IN_SMALL_DATA_P m32r_in_small_data_p
163 #undef TARGET_MEMORY_MOVE_COST
164 #define TARGET_MEMORY_MOVE_COST m32r_memory_move_cost
165 #undef TARGET_RTX_COSTS
166 #define TARGET_RTX_COSTS m32r_rtx_costs
167 #undef TARGET_ADDRESS_COST
168 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
170 #undef TARGET_PROMOTE_PROTOTYPES
171 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
172 #undef TARGET_RETURN_IN_MEMORY
173 #define TARGET_RETURN_IN_MEMORY m32r_return_in_memory
175 #undef TARGET_FUNCTION_VALUE
176 #define TARGET_FUNCTION_VALUE m32r_function_value
177 #undef TARGET_LIBCALL_VALUE
178 #define TARGET_LIBCALL_VALUE m32r_libcall_value
179 #undef TARGET_FUNCTION_VALUE_REGNO_P
180 #define TARGET_FUNCTION_VALUE_REGNO_P m32r_function_value_regno_p
182 #undef TARGET_SETUP_INCOMING_VARARGS
183 #define TARGET_SETUP_INCOMING_VARARGS m32r_setup_incoming_varargs
184 #undef TARGET_MUST_PASS_IN_STACK
185 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
186 #undef TARGET_PASS_BY_REFERENCE
187 #define TARGET_PASS_BY_REFERENCE m32r_pass_by_reference
188 #undef TARGET_ARG_PARTIAL_BYTES
189 #define TARGET_ARG_PARTIAL_BYTES m32r_arg_partial_bytes
190 #undef TARGET_FUNCTION_ARG
191 #define TARGET_FUNCTION_ARG m32r_function_arg
192 #undef TARGET_FUNCTION_ARG_ADVANCE
193 #define TARGET_FUNCTION_ARG_ADVANCE m32r_function_arg_advance
195 #undef TARGET_CAN_ELIMINATE
196 #define TARGET_CAN_ELIMINATE m32r_can_eliminate
198 #undef TARGET_CONDITIONAL_REGISTER_USAGE
199 #define TARGET_CONDITIONAL_REGISTER_USAGE m32r_conditional_register_usage
201 #undef TARGET_TRAMPOLINE_INIT
202 #define TARGET_TRAMPOLINE_INIT m32r_trampoline_init
204 #undef TARGET_LEGITIMATE_CONSTANT_P
205 #define TARGET_LEGITIMATE_CONSTANT_P m32r_legitimate_constant_p
207 struct gcc_target targetm = TARGET_INITIALIZER;
209 /* Called by m32r_option_override to initialize various things. */
211 void
212 m32r_init (void)
214 init_reg_tables ();
216 /* Initialize array for TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
217 memset (m32r_punct_chars, 0, sizeof (m32r_punct_chars));
218 m32r_punct_chars['#'] = 1;
219 m32r_punct_chars['@'] = 1; /* ??? no longer used */
221 /* Provide default value if not specified. */
222 if (!global_options_set.x_g_switch_value)
223 g_switch_value = SDATA_DEFAULT_SIZE;
226 static void
227 m32r_option_override (void)
229 /* These need to be done at start up.
230 It's convenient to do them here. */
231 m32r_init ();
232 SUBTARGET_OVERRIDE_OPTIONS;
235 /* Vectors to keep interesting information about registers where it can easily
236 be got. We use to use the actual mode value as the bit number, but there
237 is (or may be) more than 32 modes now. Instead we use two tables: one
238 indexed by hard register number, and one indexed by mode. */
240 /* The purpose of m32r_mode_class is to shrink the range of modes so that
241 they all fit (as bit numbers) in a 32-bit word (again). Each real mode is
242 mapped into one m32r_mode_class mode. */
244 enum m32r_mode_class
246 C_MODE,
247 S_MODE, D_MODE, T_MODE, O_MODE,
248 SF_MODE, DF_MODE, TF_MODE, OF_MODE, A_MODE
251 /* Modes for condition codes. */
252 #define C_MODES (1 << (int) C_MODE)
254 /* Modes for single-word and smaller quantities. */
255 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
257 /* Modes for double-word and smaller quantities. */
258 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
260 /* Modes for quad-word and smaller quantities. */
261 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
263 /* Modes for accumulators. */
264 #define A_MODES (1 << (int) A_MODE)
266 /* Value is 1 if register/mode pair is acceptable on arc. */
268 const unsigned int m32r_hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] =
270 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES,
271 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, S_MODES, S_MODES, S_MODES,
272 S_MODES, C_MODES, A_MODES, A_MODES
275 unsigned int m32r_mode_class [NUM_MACHINE_MODES];
277 enum reg_class m32r_regno_reg_class[FIRST_PSEUDO_REGISTER];
279 static void
280 init_reg_tables (void)
282 int i;
284 for (i = 0; i < NUM_MACHINE_MODES; i++)
286 enum machine_mode m = (enum machine_mode) i;
288 switch (GET_MODE_CLASS (m))
290 case MODE_INT:
291 case MODE_PARTIAL_INT:
292 case MODE_COMPLEX_INT:
293 if (GET_MODE_SIZE (m) <= 4)
294 m32r_mode_class[i] = 1 << (int) S_MODE;
295 else if (GET_MODE_SIZE (m) == 8)
296 m32r_mode_class[i] = 1 << (int) D_MODE;
297 else if (GET_MODE_SIZE (m) == 16)
298 m32r_mode_class[i] = 1 << (int) T_MODE;
299 else if (GET_MODE_SIZE (m) == 32)
300 m32r_mode_class[i] = 1 << (int) O_MODE;
301 else
302 m32r_mode_class[i] = 0;
303 break;
304 case MODE_FLOAT:
305 case MODE_COMPLEX_FLOAT:
306 if (GET_MODE_SIZE (m) <= 4)
307 m32r_mode_class[i] = 1 << (int) SF_MODE;
308 else if (GET_MODE_SIZE (m) == 8)
309 m32r_mode_class[i] = 1 << (int) DF_MODE;
310 else if (GET_MODE_SIZE (m) == 16)
311 m32r_mode_class[i] = 1 << (int) TF_MODE;
312 else if (GET_MODE_SIZE (m) == 32)
313 m32r_mode_class[i] = 1 << (int) OF_MODE;
314 else
315 m32r_mode_class[i] = 0;
316 break;
317 case MODE_CC:
318 m32r_mode_class[i] = 1 << (int) C_MODE;
319 break;
320 default:
321 m32r_mode_class[i] = 0;
322 break;
326 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
328 if (GPR_P (i))
329 m32r_regno_reg_class[i] = GENERAL_REGS;
330 else if (i == ARG_POINTER_REGNUM)
331 m32r_regno_reg_class[i] = GENERAL_REGS;
332 else
333 m32r_regno_reg_class[i] = NO_REGS;
337 /* M32R specific attribute support.
339 interrupt - for interrupt functions
341 model - select code model used to access object
343 small: addresses use 24 bits, use bl to make calls
344 medium: addresses use 32 bits, use bl to make calls
345 large: addresses use 32 bits, use seth/add3/jl to make calls
347 Grep for MODEL in m32r.h for more info. */
349 static tree small_ident1;
350 static tree small_ident2;
351 static tree medium_ident1;
352 static tree medium_ident2;
353 static tree large_ident1;
354 static tree large_ident2;
356 static void
357 init_idents (void)
359 if (small_ident1 == 0)
361 small_ident1 = get_identifier ("small");
362 small_ident2 = get_identifier ("__small__");
363 medium_ident1 = get_identifier ("medium");
364 medium_ident2 = get_identifier ("__medium__");
365 large_ident1 = get_identifier ("large");
366 large_ident2 = get_identifier ("__large__");
370 /* Handle an "model" attribute; arguments as in
371 struct attribute_spec.handler. */
372 static tree
373 m32r_handle_model_attribute (tree *node ATTRIBUTE_UNUSED, tree name,
374 tree args, int flags ATTRIBUTE_UNUSED,
375 bool *no_add_attrs)
377 tree arg;
379 init_idents ();
380 arg = TREE_VALUE (args);
382 if (arg != small_ident1
383 && arg != small_ident2
384 && arg != medium_ident1
385 && arg != medium_ident2
386 && arg != large_ident1
387 && arg != large_ident2)
389 warning (OPT_Wattributes, "invalid argument of %qs attribute",
390 IDENTIFIER_POINTER (name));
391 *no_add_attrs = true;
394 return NULL_TREE;
397 /* Encode section information of DECL, which is either a VAR_DECL,
398 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
400 For the M32R we want to record:
402 - whether the object lives in .sdata/.sbss.
403 - what code model should be used to access the object
406 static void
407 m32r_encode_section_info (tree decl, rtx rtl, int first)
409 int extra_flags = 0;
410 tree model_attr;
411 enum m32r_model model;
413 default_encode_section_info (decl, rtl, first);
415 if (!DECL_P (decl))
416 return;
418 model_attr = lookup_attribute ("model", DECL_ATTRIBUTES (decl));
419 if (model_attr)
421 tree id;
423 init_idents ();
425 id = TREE_VALUE (TREE_VALUE (model_attr));
427 if (id == small_ident1 || id == small_ident2)
428 model = M32R_MODEL_SMALL;
429 else if (id == medium_ident1 || id == medium_ident2)
430 model = M32R_MODEL_MEDIUM;
431 else if (id == large_ident1 || id == large_ident2)
432 model = M32R_MODEL_LARGE;
433 else
434 gcc_unreachable (); /* shouldn't happen */
436 else
438 if (TARGET_MODEL_SMALL)
439 model = M32R_MODEL_SMALL;
440 else if (TARGET_MODEL_MEDIUM)
441 model = M32R_MODEL_MEDIUM;
442 else if (TARGET_MODEL_LARGE)
443 model = M32R_MODEL_LARGE;
444 else
445 gcc_unreachable (); /* shouldn't happen */
447 extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
449 if (extra_flags)
450 SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= extra_flags;
453 /* Only mark the object as being small data area addressable if
454 it hasn't been explicitly marked with a code model.
456 The user can explicitly put an object in the small data area with the
457 section attribute. If the object is in sdata/sbss and marked with a
458 code model do both [put the object in .sdata and mark it as being
459 addressed with a specific code model - don't mark it as being addressed
460 with an SDA reloc though]. This is ok and might be useful at times. If
461 the object doesn't fit the linker will give an error. */
463 static bool
464 m32r_in_small_data_p (const_tree decl)
466 const char *section;
468 if (TREE_CODE (decl) != VAR_DECL)
469 return false;
471 if (lookup_attribute ("model", DECL_ATTRIBUTES (decl)))
472 return false;
474 section = DECL_SECTION_NAME (decl);
475 if (section)
477 if (strcmp (section, ".sdata") == 0 || strcmp (section, ".sbss") == 0)
478 return true;
480 else
482 if (! TREE_READONLY (decl) && ! TARGET_SDATA_NONE)
484 int size = int_size_in_bytes (TREE_TYPE (decl));
486 if (size > 0 && size <= g_switch_value)
487 return true;
491 return false;
494 /* Do anything needed before RTL is emitted for each function. */
496 void
497 m32r_init_expanders (void)
499 /* ??? At one point there was code here. The function is left in
500 to make it easy to experiment. */
504 call_operand (rtx op, enum machine_mode mode)
506 if (!MEM_P (op))
507 return 0;
508 op = XEXP (op, 0);
509 return call_address_operand (op, mode);
512 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
515 small_data_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
517 if (! TARGET_SDATA_USE)
518 return 0;
520 if (GET_CODE (op) == SYMBOL_REF)
521 return SYMBOL_REF_SMALL_P (op);
523 if (GET_CODE (op) == CONST
524 && GET_CODE (XEXP (op, 0)) == PLUS
525 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
526 && satisfies_constraint_J (XEXP (XEXP (op, 0), 1)))
527 return SYMBOL_REF_SMALL_P (XEXP (XEXP (op, 0), 0));
529 return 0;
532 /* Return 1 if OP is a symbol that can use 24-bit addressing. */
535 addr24_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
537 rtx sym;
539 if (flag_pic)
540 return 0;
542 if (GET_CODE (op) == LABEL_REF)
543 return TARGET_ADDR24;
545 if (GET_CODE (op) == SYMBOL_REF)
546 sym = op;
547 else if (GET_CODE (op) == CONST
548 && GET_CODE (XEXP (op, 0)) == PLUS
549 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
550 && satisfies_constraint_M (XEXP (XEXP (op, 0), 1)))
551 sym = XEXP (XEXP (op, 0), 0);
552 else
553 return 0;
555 if (SYMBOL_REF_MODEL (sym) == M32R_MODEL_SMALL)
556 return 1;
558 if (TARGET_ADDR24
559 && (CONSTANT_POOL_ADDRESS_P (sym)
560 || LIT_NAME_P (XSTR (sym, 0))))
561 return 1;
563 return 0;
566 /* Return 1 if OP is a symbol that needs 32-bit addressing. */
569 addr32_operand (rtx op, enum machine_mode mode)
571 rtx sym;
573 if (GET_CODE (op) == LABEL_REF)
574 return TARGET_ADDR32;
576 if (GET_CODE (op) == SYMBOL_REF)
577 sym = op;
578 else if (GET_CODE (op) == CONST
579 && GET_CODE (XEXP (op, 0)) == PLUS
580 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
581 && CONST_INT_P (XEXP (XEXP (op, 0), 1))
582 && ! flag_pic)
583 sym = XEXP (XEXP (op, 0), 0);
584 else
585 return 0;
587 return (! addr24_operand (sym, mode)
588 && ! small_data_operand (sym, mode));
591 /* Return 1 if OP is a function that can be called with the `bl' insn. */
594 call26_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
596 if (flag_pic)
597 return 1;
599 if (GET_CODE (op) == SYMBOL_REF)
600 return SYMBOL_REF_MODEL (op) != M32R_MODEL_LARGE;
602 return TARGET_CALL26;
605 /* Return 1 if OP is a DImode const we want to handle inline.
606 This must match the code in the movdi pattern.
607 It is used by the 'G' constraint. */
610 easy_di_const (rtx op)
612 rtx high_rtx, low_rtx;
613 HOST_WIDE_INT high, low;
615 split_double (op, &high_rtx, &low_rtx);
616 high = INTVAL (high_rtx);
617 low = INTVAL (low_rtx);
618 /* Pick constants loadable with 2 16-bit `ldi' insns. */
619 if (high >= -128 && high <= 127
620 && low >= -128 && low <= 127)
621 return 1;
622 return 0;
625 /* Return 1 if OP is a DFmode const we want to handle inline.
626 This must match the code in the movdf pattern.
627 It is used by the 'H' constraint. */
630 easy_df_const (rtx op)
632 REAL_VALUE_TYPE r;
633 long l[2];
635 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
636 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
637 if (l[0] == 0 && l[1] == 0)
638 return 1;
639 if ((l[0] & 0xffff) == 0 && l[1] == 0)
640 return 1;
641 return 0;
644 /* Return 1 if OP is (mem (reg ...)).
645 This is used in insn length calcs. */
648 memreg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
650 return MEM_P (op) && REG_P (XEXP (op, 0));
653 /* Return nonzero if TYPE must be passed by indirect reference. */
655 static bool
656 m32r_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED,
657 enum machine_mode mode, const_tree type,
658 bool named ATTRIBUTE_UNUSED)
660 int size;
662 if (type)
663 size = int_size_in_bytes (type);
664 else
665 size = GET_MODE_SIZE (mode);
667 return (size < 0 || size > 8);
670 /* Comparisons. */
672 /* X and Y are two things to compare using CODE. Emit the compare insn and
673 return the rtx for compare [arg0 of the if_then_else].
674 If need_compare is true then the comparison insn must be generated, rather
675 than being subsumed into the following branch instruction. */
678 gen_compare (enum rtx_code code, rtx x, rtx y, int need_compare)
680 enum rtx_code compare_code;
681 enum rtx_code branch_code;
682 rtx cc_reg = gen_rtx_REG (CCmode, CARRY_REGNUM);
683 int must_swap = 0;
685 switch (code)
687 case EQ: compare_code = EQ; branch_code = NE; break;
688 case NE: compare_code = EQ; branch_code = EQ; break;
689 case LT: compare_code = LT; branch_code = NE; break;
690 case LE: compare_code = LT; branch_code = EQ; must_swap = 1; break;
691 case GT: compare_code = LT; branch_code = NE; must_swap = 1; break;
692 case GE: compare_code = LT; branch_code = EQ; break;
693 case LTU: compare_code = LTU; branch_code = NE; break;
694 case LEU: compare_code = LTU; branch_code = EQ; must_swap = 1; break;
695 case GTU: compare_code = LTU; branch_code = NE; must_swap = 1; break;
696 case GEU: compare_code = LTU; branch_code = EQ; break;
698 default:
699 gcc_unreachable ();
702 if (need_compare)
704 switch (compare_code)
706 case EQ:
707 if (satisfies_constraint_P (y) /* Reg equal to small const. */
708 && y != const0_rtx)
710 rtx tmp = gen_reg_rtx (SImode);
712 emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
713 x = tmp;
714 y = const0_rtx;
716 else if (CONSTANT_P (y)) /* Reg equal to const. */
718 rtx tmp = force_reg (GET_MODE (x), y);
719 y = tmp;
722 if (register_operand (y, SImode) /* Reg equal to reg. */
723 || y == const0_rtx) /* Reg equal to zero. */
725 emit_insn (gen_cmp_eqsi_insn (x, y));
727 return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
729 break;
731 case LT:
732 if (register_operand (y, SImode)
733 || satisfies_constraint_P (y))
735 rtx tmp = gen_reg_rtx (SImode); /* Reg compared to reg. */
737 switch (code)
739 case LT:
740 emit_insn (gen_cmp_ltsi_insn (x, y));
741 code = EQ;
742 break;
743 case LE:
744 if (y == const0_rtx)
745 tmp = const1_rtx;
746 else
747 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
748 emit_insn (gen_cmp_ltsi_insn (x, tmp));
749 code = EQ;
750 break;
751 case GT:
752 if (CONST_INT_P (y))
753 tmp = gen_rtx_PLUS (SImode, y, const1_rtx);
754 else
755 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
756 emit_insn (gen_cmp_ltsi_insn (x, tmp));
757 code = NE;
758 break;
759 case GE:
760 emit_insn (gen_cmp_ltsi_insn (x, y));
761 code = NE;
762 break;
763 default:
764 gcc_unreachable ();
767 return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
769 break;
771 case LTU:
772 if (register_operand (y, SImode)
773 || satisfies_constraint_P (y))
775 rtx tmp = gen_reg_rtx (SImode); /* Reg (unsigned) compared to reg. */
777 switch (code)
779 case LTU:
780 emit_insn (gen_cmp_ltusi_insn (x, y));
781 code = EQ;
782 break;
783 case LEU:
784 if (y == const0_rtx)
785 tmp = const1_rtx;
786 else
787 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
788 emit_insn (gen_cmp_ltusi_insn (x, tmp));
789 code = EQ;
790 break;
791 case GTU:
792 if (CONST_INT_P (y))
793 tmp = gen_rtx_PLUS (SImode, y, const1_rtx);
794 else
795 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
796 emit_insn (gen_cmp_ltusi_insn (x, tmp));
797 code = NE;
798 break;
799 case GEU:
800 emit_insn (gen_cmp_ltusi_insn (x, y));
801 code = NE;
802 break;
803 default:
804 gcc_unreachable ();
807 return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
809 break;
811 default:
812 gcc_unreachable ();
815 else
817 /* Reg/reg equal comparison. */
818 if (compare_code == EQ
819 && register_operand (y, SImode))
820 return gen_rtx_fmt_ee (code, CCmode, x, y);
822 /* Reg/zero signed comparison. */
823 if ((compare_code == EQ || compare_code == LT)
824 && y == const0_rtx)
825 return gen_rtx_fmt_ee (code, CCmode, x, y);
827 /* Reg/smallconst equal comparison. */
828 if (compare_code == EQ
829 && satisfies_constraint_P (y))
831 rtx tmp = gen_reg_rtx (SImode);
833 emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
834 return gen_rtx_fmt_ee (code, CCmode, tmp, const0_rtx);
837 /* Reg/const equal comparison. */
838 if (compare_code == EQ
839 && CONSTANT_P (y))
841 rtx tmp = force_reg (GET_MODE (x), y);
843 return gen_rtx_fmt_ee (code, CCmode, x, tmp);
847 if (CONSTANT_P (y))
849 if (must_swap)
850 y = force_reg (GET_MODE (x), y);
851 else
853 int ok_const = reg_or_int16_operand (y, GET_MODE (y));
855 if (! ok_const)
856 y = force_reg (GET_MODE (x), y);
860 switch (compare_code)
862 case EQ :
863 emit_insn (gen_cmp_eqsi_insn (must_swap ? y : x, must_swap ? x : y));
864 break;
865 case LT :
866 emit_insn (gen_cmp_ltsi_insn (must_swap ? y : x, must_swap ? x : y));
867 break;
868 case LTU :
869 emit_insn (gen_cmp_ltusi_insn (must_swap ? y : x, must_swap ? x : y));
870 break;
872 default:
873 gcc_unreachable ();
876 return gen_rtx_fmt_ee (branch_code, VOIDmode, cc_reg, CONST0_RTX (CCmode));
879 bool
880 gen_cond_store (enum rtx_code code, rtx op0, rtx op1, rtx op2)
882 enum machine_mode mode = GET_MODE (op0);
884 gcc_assert (mode == SImode);
885 switch (code)
887 case EQ:
888 if (!register_operand (op1, mode))
889 op1 = force_reg (mode, op1);
891 if (TARGET_M32RX || TARGET_M32R2)
893 if (!reg_or_zero_operand (op2, mode))
894 op2 = force_reg (mode, op2);
896 emit_insn (gen_seq_insn_m32rx (op0, op1, op2));
897 return true;
899 if (CONST_INT_P (op2) && INTVAL (op2) == 0)
901 emit_insn (gen_seq_zero_insn (op0, op1));
902 return true;
905 if (!reg_or_eq_int16_operand (op2, mode))
906 op2 = force_reg (mode, op2);
908 emit_insn (gen_seq_insn (op0, op1, op2));
909 return true;
911 case NE:
912 if (!CONST_INT_P (op2)
913 || (INTVAL (op2) != 0 && satisfies_constraint_K (op2)))
915 rtx reg;
917 if (reload_completed || reload_in_progress)
918 return false;
920 reg = gen_reg_rtx (SImode);
921 emit_insn (gen_xorsi3 (reg, op1, op2));
922 op1 = reg;
924 if (!register_operand (op1, mode))
925 op1 = force_reg (mode, op1);
927 emit_insn (gen_sne_zero_insn (op0, op1));
928 return true;
930 return false;
932 case LT:
933 case GT:
934 if (code == GT)
936 rtx tmp = op2;
937 op2 = op1;
938 op1 = tmp;
939 code = LT;
942 if (!register_operand (op1, mode))
943 op1 = force_reg (mode, op1);
945 if (!reg_or_int16_operand (op2, mode))
946 op2 = force_reg (mode, op2);
948 emit_insn (gen_slt_insn (op0, op1, op2));
949 return true;
951 case LTU:
952 case GTU:
953 if (code == GTU)
955 rtx tmp = op2;
956 op2 = op1;
957 op1 = tmp;
958 code = LTU;
961 if (!register_operand (op1, mode))
962 op1 = force_reg (mode, op1);
964 if (!reg_or_int16_operand (op2, mode))
965 op2 = force_reg (mode, op2);
967 emit_insn (gen_sltu_insn (op0, op1, op2));
968 return true;
970 case GE:
971 case GEU:
972 if (!register_operand (op1, mode))
973 op1 = force_reg (mode, op1);
975 if (!reg_or_int16_operand (op2, mode))
976 op2 = force_reg (mode, op2);
978 if (code == GE)
979 emit_insn (gen_sge_insn (op0, op1, op2));
980 else
981 emit_insn (gen_sgeu_insn (op0, op1, op2));
982 return true;
984 case LE:
985 case LEU:
986 if (!register_operand (op1, mode))
987 op1 = force_reg (mode, op1);
989 if (CONST_INT_P (op2))
991 HOST_WIDE_INT value = INTVAL (op2);
992 if (value >= 2147483647)
994 emit_move_insn (op0, const1_rtx);
995 return true;
998 op2 = GEN_INT (value + 1);
999 if (value < -32768 || value >= 32767)
1000 op2 = force_reg (mode, op2);
1002 if (code == LEU)
1003 emit_insn (gen_sltu_insn (op0, op1, op2));
1004 else
1005 emit_insn (gen_slt_insn (op0, op1, op2));
1006 return true;
1009 if (!register_operand (op2, mode))
1010 op2 = force_reg (mode, op2);
1012 if (code == LEU)
1013 emit_insn (gen_sleu_insn (op0, op1, op2));
1014 else
1015 emit_insn (gen_sle_insn (op0, op1, op2));
1016 return true;
1018 default:
1019 gcc_unreachable ();
1024 /* Split a 2 word move (DI or DF) into component parts. */
1027 gen_split_move_double (rtx operands[])
1029 enum machine_mode mode = GET_MODE (operands[0]);
1030 rtx dest = operands[0];
1031 rtx src = operands[1];
1032 rtx val;
1034 /* We might have (SUBREG (MEM)) here, so just get rid of the
1035 subregs to make this code simpler. It is safe to call
1036 alter_subreg any time after reload. */
1037 if (GET_CODE (dest) == SUBREG)
1038 alter_subreg (&dest, true);
1039 if (GET_CODE (src) == SUBREG)
1040 alter_subreg (&src, true);
1042 start_sequence ();
1043 if (REG_P (dest))
1045 int dregno = REGNO (dest);
1047 /* Reg = reg. */
1048 if (REG_P (src))
1050 int sregno = REGNO (src);
1052 int reverse = (dregno == sregno + 1);
1054 /* We normally copy the low-numbered register first. However, if
1055 the first register operand 0 is the same as the second register of
1056 operand 1, we must copy in the opposite order. */
1057 emit_insn (gen_rtx_SET (VOIDmode,
1058 operand_subword (dest, reverse, TRUE, mode),
1059 operand_subword (src, reverse, TRUE, mode)));
1061 emit_insn (gen_rtx_SET (VOIDmode,
1062 operand_subword (dest, !reverse, TRUE, mode),
1063 operand_subword (src, !reverse, TRUE, mode)));
1066 /* Reg = constant. */
1067 else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
1069 rtx words[2];
1070 split_double (src, &words[0], &words[1]);
1071 emit_insn (gen_rtx_SET (VOIDmode,
1072 operand_subword (dest, 0, TRUE, mode),
1073 words[0]));
1075 emit_insn (gen_rtx_SET (VOIDmode,
1076 operand_subword (dest, 1, TRUE, mode),
1077 words[1]));
1080 /* Reg = mem. */
1081 else if (MEM_P (src))
1083 /* If the high-address word is used in the address, we must load it
1084 last. Otherwise, load it first. */
1085 int reverse
1086 = (refers_to_regno_p (dregno, dregno + 1, XEXP (src, 0), 0) != 0);
1088 /* We used to optimize loads from single registers as
1090 ld r1,r3+; ld r2,r3
1092 if r3 were not used subsequently. However, the REG_NOTES aren't
1093 propagated correctly by the reload phase, and it can cause bad
1094 code to be generated. We could still try:
1096 ld r1,r3+; ld r2,r3; addi r3,-4
1098 which saves 2 bytes and doesn't force longword alignment. */
1099 emit_insn (gen_rtx_SET (VOIDmode,
1100 operand_subword (dest, reverse, TRUE, mode),
1101 adjust_address (src, SImode,
1102 reverse * UNITS_PER_WORD)));
1104 emit_insn (gen_rtx_SET (VOIDmode,
1105 operand_subword (dest, !reverse, TRUE, mode),
1106 adjust_address (src, SImode,
1107 !reverse * UNITS_PER_WORD)));
1109 else
1110 gcc_unreachable ();
1113 /* Mem = reg. */
1114 /* We used to optimize loads from single registers as
1116 st r1,r3; st r2,+r3
1118 if r3 were not used subsequently. However, the REG_NOTES aren't
1119 propagated correctly by the reload phase, and it can cause bad
1120 code to be generated. We could still try:
1122 st r1,r3; st r2,+r3; addi r3,-4
1124 which saves 2 bytes and doesn't force longword alignment. */
1125 else if (MEM_P (dest) && REG_P (src))
1127 emit_insn (gen_rtx_SET (VOIDmode,
1128 adjust_address (dest, SImode, 0),
1129 operand_subword (src, 0, TRUE, mode)));
1131 emit_insn (gen_rtx_SET (VOIDmode,
1132 adjust_address (dest, SImode, UNITS_PER_WORD),
1133 operand_subword (src, 1, TRUE, mode)));
1136 else
1137 gcc_unreachable ();
1139 val = get_insns ();
1140 end_sequence ();
1141 return val;
1145 static int
1146 m32r_arg_partial_bytes (cumulative_args_t cum_v, enum machine_mode mode,
1147 tree type, bool named ATTRIBUTE_UNUSED)
1149 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1151 int words;
1152 unsigned int size =
1153 (((mode == BLKmode && type)
1154 ? (unsigned int) int_size_in_bytes (type)
1155 : GET_MODE_SIZE (mode)) + UNITS_PER_WORD - 1)
1156 / UNITS_PER_WORD;
1158 if (*cum >= M32R_MAX_PARM_REGS)
1159 words = 0;
1160 else if (*cum + size > M32R_MAX_PARM_REGS)
1161 words = (*cum + size) - M32R_MAX_PARM_REGS;
1162 else
1163 words = 0;
1165 return words * UNITS_PER_WORD;
1168 /* The ROUND_ADVANCE* macros are local to this file. */
1169 /* Round SIZE up to a word boundary. */
1170 #define ROUND_ADVANCE(SIZE) \
1171 (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1173 /* Round arg MODE/TYPE up to the next word boundary. */
1174 #define ROUND_ADVANCE_ARG(MODE, TYPE) \
1175 ((MODE) == BLKmode \
1176 ? ROUND_ADVANCE ((unsigned int) int_size_in_bytes (TYPE)) \
1177 : ROUND_ADVANCE ((unsigned int) GET_MODE_SIZE (MODE)))
1179 /* Round CUM up to the necessary point for argument MODE/TYPE. */
1180 #define ROUND_ADVANCE_CUM(CUM, MODE, TYPE) (CUM)
1182 /* Return boolean indicating arg of type TYPE and mode MODE will be passed in
1183 a reg. This includes arguments that have to be passed by reference as the
1184 pointer to them is passed in a reg if one is available (and that is what
1185 we're given).
1186 This macro is only used in this file. */
1187 #define PASS_IN_REG_P(CUM, MODE, TYPE) \
1188 (ROUND_ADVANCE_CUM ((CUM), (MODE), (TYPE)) < M32R_MAX_PARM_REGS)
1190 /* Determine where to put an argument to a function.
1191 Value is zero to push the argument on the stack,
1192 or a hard register in which to store the argument.
1194 MODE is the argument's machine mode.
1195 TYPE is the data type of the argument (as a tree).
1196 This is null for libcalls where that information may
1197 not be available.
1198 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1199 the preceding args and about the function being called.
1200 NAMED is nonzero if this argument is a named parameter
1201 (otherwise it is an extra parameter matching an ellipsis). */
1202 /* On the M32R the first M32R_MAX_PARM_REGS args are normally in registers
1203 and the rest are pushed. */
1205 static rtx
1206 m32r_function_arg (cumulative_args_t cum_v, enum machine_mode mode,
1207 const_tree type ATTRIBUTE_UNUSED,
1208 bool named ATTRIBUTE_UNUSED)
1210 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1212 return (PASS_IN_REG_P (*cum, mode, type)
1213 ? gen_rtx_REG (mode, ROUND_ADVANCE_CUM (*cum, mode, type))
1214 : NULL_RTX);
1217 /* Update the data in CUM to advance over an argument
1218 of mode MODE and data type TYPE.
1219 (TYPE is null for libcalls where that information may not be available.) */
1221 static void
1222 m32r_function_arg_advance (cumulative_args_t cum_v, enum machine_mode mode,
1223 const_tree type, bool named ATTRIBUTE_UNUSED)
1225 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1227 *cum = (ROUND_ADVANCE_CUM (*cum, mode, type)
1228 + ROUND_ADVANCE_ARG (mode, type));
1231 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1233 static bool
1234 m32r_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1236 cumulative_args_t dummy = pack_cumulative_args (NULL);
1238 return m32r_pass_by_reference (dummy, TYPE_MODE (type), type, false);
1241 /* Worker function for TARGET_FUNCTION_VALUE. */
1243 static rtx
1244 m32r_function_value (const_tree valtype,
1245 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
1246 bool outgoing ATTRIBUTE_UNUSED)
1248 return gen_rtx_REG (TYPE_MODE (valtype), 0);
1251 /* Worker function for TARGET_LIBCALL_VALUE. */
1253 static rtx
1254 m32r_libcall_value (enum machine_mode mode,
1255 const_rtx fun ATTRIBUTE_UNUSED)
1257 return gen_rtx_REG (mode, 0);
1260 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
1262 ??? What about r1 in DI/DF values. */
1264 static bool
1265 m32r_function_value_regno_p (const unsigned int regno)
1267 return (regno == 0);
1270 /* Do any needed setup for a variadic function. For the M32R, we must
1271 create a register parameter block, and then copy any anonymous arguments
1272 in registers to memory.
1274 CUM has not been updated for the last named argument which has type TYPE
1275 and mode MODE, and we rely on this fact. */
1277 static void
1278 m32r_setup_incoming_varargs (cumulative_args_t cum, enum machine_mode mode,
1279 tree type, int *pretend_size, int no_rtl)
1281 int first_anon_arg;
1283 if (no_rtl)
1284 return;
1286 /* All BLKmode values are passed by reference. */
1287 gcc_assert (mode != BLKmode);
1289 first_anon_arg = (ROUND_ADVANCE_CUM (*get_cumulative_args (cum), mode, type)
1290 + ROUND_ADVANCE_ARG (mode, type));
1292 if (first_anon_arg < M32R_MAX_PARM_REGS)
1294 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1295 int first_reg_offset = first_anon_arg;
1296 /* Size in words to "pretend" allocate. */
1297 int size = M32R_MAX_PARM_REGS - first_reg_offset;
1298 rtx regblock;
1300 regblock = gen_frame_mem (BLKmode,
1301 plus_constant (Pmode, arg_pointer_rtx,
1302 FIRST_PARM_OFFSET (0)));
1303 set_mem_alias_set (regblock, get_varargs_alias_set ());
1304 move_block_from_reg (first_reg_offset, regblock, size);
1306 *pretend_size = (size * UNITS_PER_WORD);
1311 /* Return true if INSN is real instruction bearing insn. */
1313 static int
1314 m32r_is_insn (rtx insn)
1316 return (NONDEBUG_INSN_P (insn)
1317 && GET_CODE (PATTERN (insn)) != USE
1318 && GET_CODE (PATTERN (insn)) != CLOBBER);
1321 /* Increase the priority of long instructions so that the
1322 short instructions are scheduled ahead of the long ones. */
1324 static int
1325 m32r_adjust_priority (rtx insn, int priority)
1327 if (m32r_is_insn (insn)
1328 && get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1329 priority <<= 3;
1331 return priority;
1335 /* Indicate how many instructions can be issued at the same time.
1336 This is sort of a lie. The m32r can issue only 1 long insn at
1337 once, but it can issue 2 short insns. The default therefore is
1338 set at 2, but this can be overridden by the command line option
1339 -missue-rate=1. */
1341 static int
1342 m32r_issue_rate (void)
1344 return ((TARGET_LOW_ISSUE_RATE) ? 1 : 2);
1347 /* Cost functions. */
1348 /* Memory is 3 times as expensive as registers.
1349 ??? Is that the right way to look at it? */
1351 static int
1352 m32r_memory_move_cost (enum machine_mode mode,
1353 reg_class_t rclass ATTRIBUTE_UNUSED,
1354 bool in ATTRIBUTE_UNUSED)
1356 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
1357 return 6;
1358 else
1359 return 12;
1362 static bool
1363 m32r_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
1364 int opno ATTRIBUTE_UNUSED, int *total,
1365 bool speed ATTRIBUTE_UNUSED)
1367 switch (code)
1369 /* Small integers are as cheap as registers. 4 byte values can be
1370 fetched as immediate constants - let's give that the cost of an
1371 extra insn. */
1372 case CONST_INT:
1373 if (INT16_P (INTVAL (x)))
1375 *total = 0;
1376 return true;
1378 /* FALLTHRU */
1380 case CONST:
1381 case LABEL_REF:
1382 case SYMBOL_REF:
1383 *total = COSTS_N_INSNS (1);
1384 return true;
1386 case CONST_DOUBLE:
1388 rtx high, low;
1390 split_double (x, &high, &low);
1391 *total = COSTS_N_INSNS (!INT16_P (INTVAL (high))
1392 + !INT16_P (INTVAL (low)));
1393 return true;
1396 case MULT:
1397 *total = COSTS_N_INSNS (3);
1398 return true;
1400 case DIV:
1401 case UDIV:
1402 case MOD:
1403 case UMOD:
1404 *total = COSTS_N_INSNS (10);
1405 return true;
1407 default:
1408 return false;
1412 /* Type of function DECL.
1414 The result is cached. To reset the cache at the end of a function,
1415 call with DECL = NULL_TREE. */
1417 enum m32r_function_type
1418 m32r_compute_function_type (tree decl)
1420 /* Cached value. */
1421 static enum m32r_function_type fn_type = M32R_FUNCTION_UNKNOWN;
1422 /* Last function we were called for. */
1423 static tree last_fn = NULL_TREE;
1425 /* Resetting the cached value? */
1426 if (decl == NULL_TREE)
1428 fn_type = M32R_FUNCTION_UNKNOWN;
1429 last_fn = NULL_TREE;
1430 return fn_type;
1433 if (decl == last_fn && fn_type != M32R_FUNCTION_UNKNOWN)
1434 return fn_type;
1436 /* Compute function type. */
1437 fn_type = (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE
1438 ? M32R_FUNCTION_INTERRUPT
1439 : M32R_FUNCTION_NORMAL);
1441 last_fn = decl;
1442 return fn_type;
1444 \f/* Function prologue/epilogue handlers. */
1446 /* M32R stack frames look like:
1448 Before call After call
1449 +-----------------------+ +-----------------------+
1450 | | | |
1451 high | local variables, | | local variables, |
1452 mem | reg save area, etc. | | reg save area, etc. |
1453 | | | |
1454 +-----------------------+ +-----------------------+
1455 | | | |
1456 | arguments on stack. | | arguments on stack. |
1457 | | | |
1458 SP+0->+-----------------------+ +-----------------------+
1459 | reg parm save area, |
1460 | only created for |
1461 | variable argument |
1462 | functions |
1463 +-----------------------+
1464 | previous frame ptr |
1465 +-----------------------+
1467 | register save area |
1469 +-----------------------+
1470 | return address |
1471 +-----------------------+
1473 | local variables |
1475 +-----------------------+
1477 | alloca allocations |
1479 +-----------------------+
1481 low | arguments on stack |
1482 memory | |
1483 SP+0->+-----------------------+
1485 Notes:
1486 1) The "reg parm save area" does not exist for non variable argument fns.
1487 2) The "reg parm save area" can be eliminated completely if we saved regs
1488 containing anonymous args separately but that complicates things too
1489 much (so it's not done).
1490 3) The return address is saved after the register save area so as to have as
1491 many insns as possible between the restoration of `lr' and the `jmp lr'. */
1493 /* Structure to be filled in by m32r_compute_frame_size with register
1494 save masks, and offsets for the current function. */
1495 struct m32r_frame_info
1497 unsigned int total_size; /* # bytes that the entire frame takes up. */
1498 unsigned int extra_size; /* # bytes of extra stuff. */
1499 unsigned int pretend_size; /* # bytes we push and pretend caller did. */
1500 unsigned int args_size; /* # bytes that outgoing arguments take up. */
1501 unsigned int reg_size; /* # bytes needed to store regs. */
1502 unsigned int var_size; /* # bytes that variables take up. */
1503 unsigned int gmask; /* Mask of saved gp registers. */
1504 unsigned int save_fp; /* Nonzero if fp must be saved. */
1505 unsigned int save_lr; /* Nonzero if lr (return addr) must be saved. */
1506 int initialized; /* Nonzero if frame size already calculated. */
1509 /* Current frame information calculated by m32r_compute_frame_size. */
1510 static struct m32r_frame_info current_frame_info;
1512 /* Zero structure to initialize current_frame_info. */
1513 static struct m32r_frame_info zero_frame_info;
1515 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1516 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1518 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1519 The return address and frame pointer are treated separately.
1520 Don't consider them here. */
1521 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1522 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1523 && (df_regs_ever_live_p (regno) && (!call_really_used_regs[regno] || interrupt_p)))
1525 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM))
1526 #define MUST_SAVE_RETURN_ADDR (df_regs_ever_live_p (RETURN_ADDR_REGNUM) || crtl->profile)
1528 #define SHORT_INSN_SIZE 2 /* Size of small instructions. */
1529 #define LONG_INSN_SIZE 4 /* Size of long instructions. */
1531 /* Return the bytes needed to compute the frame pointer from the current
1532 stack pointer.
1534 SIZE is the size needed for local variables. */
1536 unsigned int
1537 m32r_compute_frame_size (int size) /* # of var. bytes allocated. */
1539 unsigned int regno;
1540 unsigned int total_size, var_size, args_size, pretend_size, extra_size;
1541 unsigned int reg_size;
1542 unsigned int gmask;
1543 enum m32r_function_type fn_type;
1544 int interrupt_p;
1545 int pic_reg_used = flag_pic && (crtl->uses_pic_offset_table
1546 | crtl->profile);
1548 var_size = M32R_STACK_ALIGN (size);
1549 args_size = M32R_STACK_ALIGN (crtl->outgoing_args_size);
1550 pretend_size = crtl->args.pretend_args_size;
1551 extra_size = FIRST_PARM_OFFSET (0);
1552 total_size = extra_size + pretend_size + args_size + var_size;
1553 reg_size = 0;
1554 gmask = 0;
1556 /* See if this is an interrupt handler. Call used registers must be saved
1557 for them too. */
1558 fn_type = m32r_compute_function_type (current_function_decl);
1559 interrupt_p = M32R_INTERRUPT_P (fn_type);
1561 /* Calculate space needed for registers. */
1562 for (regno = 0; regno < M32R_MAX_INT_REGS; regno++)
1564 if (MUST_SAVE_REGISTER (regno, interrupt_p)
1565 || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1567 reg_size += UNITS_PER_WORD;
1568 gmask |= 1 << regno;
1572 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
1573 current_frame_info.save_lr = MUST_SAVE_RETURN_ADDR || pic_reg_used;
1575 reg_size += ((current_frame_info.save_fp + current_frame_info.save_lr)
1576 * UNITS_PER_WORD);
1577 total_size += reg_size;
1579 /* ??? Not sure this is necessary, and I don't think the epilogue
1580 handler will do the right thing if this changes total_size. */
1581 total_size = M32R_STACK_ALIGN (total_size);
1583 /* frame_size = total_size - (pretend_size + reg_size); */
1585 /* Save computed information. */
1586 current_frame_info.total_size = total_size;
1587 current_frame_info.extra_size = extra_size;
1588 current_frame_info.pretend_size = pretend_size;
1589 current_frame_info.var_size = var_size;
1590 current_frame_info.args_size = args_size;
1591 current_frame_info.reg_size = reg_size;
1592 current_frame_info.gmask = gmask;
1593 current_frame_info.initialized = reload_completed;
1595 /* Ok, we're done. */
1596 return total_size;
1599 /* Worker function for TARGET_CAN_ELIMINATE. */
1601 bool
1602 m32r_can_eliminate (const int from, const int to)
1604 return (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM
1605 ? ! frame_pointer_needed
1606 : true);
1610 /* The table we use to reference PIC data. */
1611 static rtx global_offset_table;
1613 static void
1614 m32r_reload_lr (rtx sp, int size)
1616 rtx lr = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
1618 if (size == 0)
1619 emit_insn (gen_movsi (lr, gen_frame_mem (Pmode, sp)));
1620 else if (size < 32768)
1621 emit_insn (gen_movsi (lr, gen_frame_mem (Pmode,
1622 gen_rtx_PLUS (Pmode, sp,
1623 GEN_INT (size)))));
1624 else
1626 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1628 emit_insn (gen_movsi (tmp, GEN_INT (size)));
1629 emit_insn (gen_addsi3 (tmp, tmp, sp));
1630 emit_insn (gen_movsi (lr, gen_frame_mem (Pmode, tmp)));
1633 emit_use (lr);
1636 void
1637 m32r_load_pic_register (void)
1639 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
1640 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
1641 GEN_INT (TARGET_MODEL_SMALL)));
1643 /* Need to emit this whether or not we obey regdecls,
1644 since setjmp/longjmp can cause life info to screw up. */
1645 emit_use (pic_offset_table_rtx);
1648 /* Expand the m32r prologue as a series of insns. */
1650 void
1651 m32r_expand_prologue (void)
1653 int regno;
1654 int frame_size;
1655 unsigned int gmask;
1656 int pic_reg_used = flag_pic && (crtl->uses_pic_offset_table
1657 | crtl->profile);
1659 if (! current_frame_info.initialized)
1660 m32r_compute_frame_size (get_frame_size ());
1662 gmask = current_frame_info.gmask;
1664 /* These cases shouldn't happen. Catch them now. */
1665 gcc_assert (current_frame_info.total_size || !gmask);
1667 /* Allocate space for register arguments if this is a variadic function. */
1668 if (current_frame_info.pretend_size != 0)
1670 /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1671 the wrong result on a 64-bit host. */
1672 HOST_WIDE_INT pretend_size = current_frame_info.pretend_size;
1673 emit_insn (gen_addsi3 (stack_pointer_rtx,
1674 stack_pointer_rtx,
1675 GEN_INT (-pretend_size)));
1678 /* Save any registers we need to and set up fp. */
1679 if (current_frame_info.save_fp)
1680 emit_insn (gen_movsi_push (stack_pointer_rtx, frame_pointer_rtx));
1682 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1684 /* Save any needed call-saved regs (and call-used if this is an
1685 interrupt handler). */
1686 for (regno = 0; regno <= M32R_MAX_INT_REGS; ++regno)
1688 if ((gmask & (1 << regno)) != 0)
1689 emit_insn (gen_movsi_push (stack_pointer_rtx,
1690 gen_rtx_REG (Pmode, regno)));
1693 if (current_frame_info.save_lr)
1694 emit_insn (gen_movsi_push (stack_pointer_rtx,
1695 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1697 /* Allocate the stack frame. */
1698 frame_size = (current_frame_info.total_size
1699 - (current_frame_info.pretend_size
1700 + current_frame_info.reg_size));
1702 if (frame_size == 0)
1703 ; /* Nothing to do. */
1704 else if (frame_size <= 32768)
1705 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1706 GEN_INT (-frame_size)));
1707 else
1709 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1711 emit_insn (gen_movsi (tmp, GEN_INT (frame_size)));
1712 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
1715 if (frame_pointer_needed)
1716 emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
1718 if (crtl->profile)
1719 /* Push lr for mcount (form_pc, x). */
1720 emit_insn (gen_movsi_push (stack_pointer_rtx,
1721 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1723 if (pic_reg_used)
1725 m32r_load_pic_register ();
1726 m32r_reload_lr (stack_pointer_rtx,
1727 (crtl->profile ? 0 : frame_size));
1730 if (crtl->profile && !pic_reg_used)
1731 emit_insn (gen_blockage ());
1735 /* Set up the stack and frame pointer (if desired) for the function.
1736 Note, if this is changed, you need to mirror the changes in
1737 m32r_compute_frame_size which calculates the prolog size. */
1739 static void
1740 m32r_output_function_prologue (FILE * file, HOST_WIDE_INT size)
1742 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1744 /* If this is an interrupt handler, mark it as such. */
1745 if (M32R_INTERRUPT_P (fn_type))
1746 fprintf (file, "\t%s interrupt handler\n", ASM_COMMENT_START);
1748 if (! current_frame_info.initialized)
1749 m32r_compute_frame_size (size);
1751 /* This is only for the human reader. */
1752 fprintf (file,
1753 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
1754 ASM_COMMENT_START,
1755 current_frame_info.var_size,
1756 current_frame_info.reg_size / 4,
1757 current_frame_info.args_size,
1758 current_frame_info.extra_size);
1761 /* Output RTL to pop register REGNO from the stack. */
1763 static void
1764 pop (int regno)
1766 rtx x;
1768 x = emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno),
1769 stack_pointer_rtx));
1770 add_reg_note (x, REG_INC, stack_pointer_rtx);
1773 /* Expand the m32r epilogue as a series of insns. */
1775 void
1776 m32r_expand_epilogue (void)
1778 int regno;
1779 int noepilogue = FALSE;
1780 int total_size;
1782 gcc_assert (current_frame_info.initialized);
1783 total_size = current_frame_info.total_size;
1785 if (total_size == 0)
1787 rtx insn = get_last_insn ();
1789 /* If the last insn was a BARRIER, we don't have to write any code
1790 because a jump (aka return) was put there. */
1791 if (insn && NOTE_P (insn))
1792 insn = prev_nonnote_insn (insn);
1793 if (insn && BARRIER_P (insn))
1794 noepilogue = TRUE;
1797 if (!noepilogue)
1799 unsigned int var_size = current_frame_info.var_size;
1800 unsigned int args_size = current_frame_info.args_size;
1801 unsigned int gmask = current_frame_info.gmask;
1802 int can_trust_sp_p = !cfun->calls_alloca;
1804 if (flag_exceptions)
1805 emit_insn (gen_blockage ());
1807 /* The first thing to do is point the sp at the bottom of the register
1808 save area. */
1809 if (can_trust_sp_p)
1811 unsigned int reg_offset = var_size + args_size;
1813 if (reg_offset == 0)
1814 ; /* Nothing to do. */
1815 else if (reg_offset < 32768)
1816 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1817 GEN_INT (reg_offset)));
1818 else
1820 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1822 emit_insn (gen_movsi (tmp, GEN_INT (reg_offset)));
1823 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1824 tmp));
1827 else if (frame_pointer_needed)
1829 unsigned int reg_offset = var_size + args_size;
1831 if (reg_offset == 0)
1832 emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1833 else if (reg_offset < 32768)
1834 emit_insn (gen_addsi3 (stack_pointer_rtx, frame_pointer_rtx,
1835 GEN_INT (reg_offset)));
1836 else
1838 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1840 emit_insn (gen_movsi (tmp, GEN_INT (reg_offset)));
1841 emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1842 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1843 tmp));
1846 else
1847 gcc_unreachable ();
1849 if (current_frame_info.save_lr)
1850 pop (RETURN_ADDR_REGNUM);
1852 /* Restore any saved registers, in reverse order of course. */
1853 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1854 for (regno = M32R_MAX_INT_REGS - 1; regno >= 0; --regno)
1856 if ((gmask & (1L << regno)) != 0)
1857 pop (regno);
1860 if (current_frame_info.save_fp)
1861 pop (FRAME_POINTER_REGNUM);
1863 /* Remove varargs area if present. */
1864 if (current_frame_info.pretend_size != 0)
1865 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1866 GEN_INT (current_frame_info.pretend_size)));
1868 emit_insn (gen_blockage ());
1872 /* Do any necessary cleanup after a function to restore stack, frame,
1873 and regs. */
1875 static void
1876 m32r_output_function_epilogue (FILE * file ATTRIBUTE_UNUSED,
1877 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1879 /* Reset state info for each function. */
1880 current_frame_info = zero_frame_info;
1881 m32r_compute_function_type (NULL_TREE);
1884 /* Return nonzero if this function is known to have a null or 1 instruction
1885 epilogue. */
1888 direct_return (void)
1890 if (!reload_completed)
1891 return FALSE;
1893 if (M32R_INTERRUPT_P (m32r_compute_function_type (current_function_decl)))
1894 return FALSE;
1896 if (! current_frame_info.initialized)
1897 m32r_compute_frame_size (get_frame_size ());
1899 return current_frame_info.total_size == 0;
1903 /* PIC. */
1906 m32r_legitimate_pic_operand_p (rtx x)
1908 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1909 return 0;
1911 if (GET_CODE (x) == CONST
1912 && GET_CODE (XEXP (x, 0)) == PLUS
1913 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1914 || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
1915 && (CONST_INT_P (XEXP (XEXP (x, 0), 1))))
1916 return 0;
1918 return 1;
1922 m32r_legitimize_pic_address (rtx orig, rtx reg)
1924 #ifdef DEBUG_PIC
1925 printf("m32r_legitimize_pic_address()\n");
1926 #endif
1928 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
1930 rtx pic_ref, address;
1931 int subregs = 0;
1933 if (reg == 0)
1935 gcc_assert (!reload_in_progress && !reload_completed);
1936 reg = gen_reg_rtx (Pmode);
1938 subregs = 1;
1941 if (subregs)
1942 address = gen_reg_rtx (Pmode);
1943 else
1944 address = reg;
1946 crtl->uses_pic_offset_table = 1;
1948 if (GET_CODE (orig) == LABEL_REF
1949 || (GET_CODE (orig) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (orig)))
1951 emit_insn (gen_gotoff_load_addr (reg, orig));
1952 emit_insn (gen_addsi3 (reg, reg, pic_offset_table_rtx));
1953 return reg;
1956 emit_insn (gen_pic_load_addr (address, orig));
1958 emit_insn (gen_addsi3 (address, address, pic_offset_table_rtx));
1959 pic_ref = gen_const_mem (Pmode, address);
1960 emit_move_insn (reg, pic_ref);
1961 return reg;
1963 else if (GET_CODE (orig) == CONST)
1965 rtx base, offset;
1967 if (GET_CODE (XEXP (orig, 0)) == PLUS
1968 && XEXP (XEXP (orig, 0), 1) == pic_offset_table_rtx)
1969 return orig;
1971 if (reg == 0)
1973 gcc_assert (!reload_in_progress && !reload_completed);
1974 reg = gen_reg_rtx (Pmode);
1977 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1979 base = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
1980 if (base == reg)
1981 offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), NULL_RTX);
1982 else
1983 offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), reg);
1985 else
1986 return orig;
1988 if (CONST_INT_P (offset))
1990 if (INT16_P (INTVAL (offset)))
1991 return plus_constant (Pmode, base, INTVAL (offset));
1992 else
1994 gcc_assert (! reload_in_progress && ! reload_completed);
1995 offset = force_reg (Pmode, offset);
1999 return gen_rtx_PLUS (Pmode, base, offset);
2002 return orig;
2005 static rtx
2006 m32r_legitimize_address (rtx x, rtx orig_x ATTRIBUTE_UNUSED,
2007 enum machine_mode mode ATTRIBUTE_UNUSED)
2009 if (flag_pic)
2010 return m32r_legitimize_pic_address (x, NULL_RTX);
2011 else
2012 return x;
2015 /* Worker function for TARGET_MODE_DEPENDENT_ADDRESS_P. */
2017 static bool
2018 m32r_mode_dependent_address_p (const_rtx addr, addr_space_t as ATTRIBUTE_UNUSED)
2020 if (GET_CODE (addr) == LO_SUM)
2021 return true;
2023 return false;
2026 /* Nested function support. */
2028 /* Emit RTL insns to initialize the variable parts of a trampoline.
2029 FNADDR is an RTX for the address of the function's pure code.
2030 CXT is an RTX for the static chain value for the function. */
2032 void
2033 m32r_initialize_trampoline (rtx tramp ATTRIBUTE_UNUSED,
2034 rtx fnaddr ATTRIBUTE_UNUSED,
2035 rtx cxt ATTRIBUTE_UNUSED)
2039 static void
2040 m32r_file_start (void)
2042 default_file_start ();
2044 if (flag_verbose_asm)
2045 fprintf (asm_out_file,
2046 "%s M32R/D special options: -G %d\n",
2047 ASM_COMMENT_START, g_switch_value);
2049 if (TARGET_LITTLE_ENDIAN)
2050 fprintf (asm_out_file, "\t.little\n");
2053 /* Print operand X (an rtx) in assembler syntax to file FILE.
2054 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2055 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2057 static void
2058 m32r_print_operand (FILE * file, rtx x, int code)
2060 rtx addr;
2062 switch (code)
2064 /* The 's' and 'p' codes are used by output_block_move() to
2065 indicate post-increment 's'tores and 'p're-increment loads. */
2066 case 's':
2067 if (REG_P (x))
2068 fprintf (file, "@+%s", reg_names [REGNO (x)]);
2069 else
2070 output_operand_lossage ("invalid operand to %%s code");
2071 return;
2073 case 'p':
2074 if (REG_P (x))
2075 fprintf (file, "@%s+", reg_names [REGNO (x)]);
2076 else
2077 output_operand_lossage ("invalid operand to %%p code");
2078 return;
2080 case 'R' :
2081 /* Write second word of DImode or DFmode reference,
2082 register or memory. */
2083 if (REG_P (x))
2084 fputs (reg_names[REGNO (x)+1], file);
2085 else if (MEM_P (x))
2087 fprintf (file, "@(");
2088 /* Handle possible auto-increment. Since it is pre-increment and
2089 we have already done it, we can just use an offset of four. */
2090 /* ??? This is taken from rs6000.c I think. I don't think it is
2091 currently necessary, but keep it around. */
2092 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2093 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2094 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 4));
2095 else
2096 output_address (plus_constant (Pmode, XEXP (x, 0), 4));
2097 fputc (')', file);
2099 else
2100 output_operand_lossage ("invalid operand to %%R code");
2101 return;
2103 case 'H' : /* High word. */
2104 case 'L' : /* Low word. */
2105 if (REG_P (x))
2107 /* L = least significant word, H = most significant word. */
2108 if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L'))
2109 fputs (reg_names[REGNO (x)], file);
2110 else
2111 fputs (reg_names[REGNO (x)+1], file);
2113 else if (CONST_INT_P (x)
2114 || GET_CODE (x) == CONST_DOUBLE)
2116 rtx first, second;
2118 split_double (x, &first, &second);
2119 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2120 code == 'L' ? INTVAL (first) : INTVAL (second));
2122 else
2123 output_operand_lossage ("invalid operand to %%H/%%L code");
2124 return;
2126 case 'A' :
2128 char str[30];
2130 if (GET_CODE (x) != CONST_DOUBLE
2131 || GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
2132 fatal_insn ("bad insn for 'A'", x);
2134 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1);
2135 fprintf (file, "%s", str);
2136 return;
2139 case 'B' : /* Bottom half. */
2140 case 'T' : /* Top half. */
2141 /* Output the argument to a `seth' insn (sets the Top half-word).
2142 For constants output arguments to a seth/or3 pair to set Top and
2143 Bottom halves. For symbols output arguments to a seth/add3 pair to
2144 set Top and Bottom halves. The difference exists because for
2145 constants seth/or3 is more readable but for symbols we need to use
2146 the same scheme as `ld' and `st' insns (16-bit addend is signed). */
2147 switch (GET_CODE (x))
2149 case CONST_INT :
2150 case CONST_DOUBLE :
2152 rtx first, second;
2154 split_double (x, &first, &second);
2155 x = WORDS_BIG_ENDIAN ? second : first;
2156 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2157 (code == 'B'
2158 ? INTVAL (x) & 0xffff
2159 : (INTVAL (x) >> 16) & 0xffff));
2161 return;
2162 case CONST :
2163 case SYMBOL_REF :
2164 if (code == 'B'
2165 && small_data_operand (x, VOIDmode))
2167 fputs ("sda(", file);
2168 output_addr_const (file, x);
2169 fputc (')', file);
2170 return;
2172 /* fall through */
2173 case LABEL_REF :
2174 fputs (code == 'T' ? "shigh(" : "low(", file);
2175 output_addr_const (file, x);
2176 fputc (')', file);
2177 return;
2178 default :
2179 output_operand_lossage ("invalid operand to %%T/%%B code");
2180 return;
2182 break;
2184 case 'U' :
2185 /* ??? wip */
2186 /* Output a load/store with update indicator if appropriate. */
2187 if (MEM_P (x))
2189 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2190 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2191 fputs (".a", file);
2193 else
2194 output_operand_lossage ("invalid operand to %%U code");
2195 return;
2197 case 'N' :
2198 /* Print a constant value negated. */
2199 if (CONST_INT_P (x))
2200 output_addr_const (file, GEN_INT (- INTVAL (x)));
2201 else
2202 output_operand_lossage ("invalid operand to %%N code");
2203 return;
2205 case 'X' :
2206 /* Print a const_int in hex. Used in comments. */
2207 if (CONST_INT_P (x))
2208 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
2209 return;
2211 case '#' :
2212 fputs (IMMEDIATE_PREFIX, file);
2213 return;
2215 case 0 :
2216 /* Do nothing special. */
2217 break;
2219 default :
2220 /* Unknown flag. */
2221 output_operand_lossage ("invalid operand output code");
2224 switch (GET_CODE (x))
2226 case REG :
2227 fputs (reg_names[REGNO (x)], file);
2228 break;
2230 case MEM :
2231 addr = XEXP (x, 0);
2232 if (GET_CODE (addr) == PRE_INC)
2234 if (!REG_P (XEXP (addr, 0)))
2235 fatal_insn ("pre-increment address is not a register", x);
2237 fprintf (file, "@+%s", reg_names[REGNO (XEXP (addr, 0))]);
2239 else if (GET_CODE (addr) == PRE_DEC)
2241 if (!REG_P (XEXP (addr, 0)))
2242 fatal_insn ("pre-decrement address is not a register", x);
2244 fprintf (file, "@-%s", reg_names[REGNO (XEXP (addr, 0))]);
2246 else if (GET_CODE (addr) == POST_INC)
2248 if (!REG_P (XEXP (addr, 0)))
2249 fatal_insn ("post-increment address is not a register", x);
2251 fprintf (file, "@%s+", reg_names[REGNO (XEXP (addr, 0))]);
2253 else
2255 fputs ("@(", file);
2256 output_address (XEXP (x, 0));
2257 fputc (')', file);
2259 break;
2261 case CONST_DOUBLE :
2262 /* We handle SFmode constants here as output_addr_const doesn't. */
2263 if (GET_MODE (x) == SFmode)
2265 REAL_VALUE_TYPE d;
2266 long l;
2268 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2269 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2270 fprintf (file, "0x%08lx", l);
2271 break;
2274 /* Fall through. Let output_addr_const deal with it. */
2276 default :
2277 output_addr_const (file, x);
2278 break;
2282 /* Print a memory address as an operand to reference that memory location. */
2284 static void
2285 m32r_print_operand_address (FILE * file, rtx addr)
2287 rtx base;
2288 rtx index = 0;
2289 int offset = 0;
2291 switch (GET_CODE (addr))
2293 case REG :
2294 fputs (reg_names[REGNO (addr)], file);
2295 break;
2297 case PLUS :
2298 if (CONST_INT_P (XEXP (addr, 0)))
2299 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
2300 else if (CONST_INT_P (XEXP (addr, 1)))
2301 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
2302 else
2303 base = XEXP (addr, 0), index = XEXP (addr, 1);
2304 if (REG_P (base))
2306 /* Print the offset first (if present) to conform to the manual. */
2307 if (index == 0)
2309 if (offset != 0)
2310 fprintf (file, "%d,", offset);
2311 fputs (reg_names[REGNO (base)], file);
2313 /* The chip doesn't support this, but left in for generality. */
2314 else if (REG_P (index))
2315 fprintf (file, "%s,%s",
2316 reg_names[REGNO (base)], reg_names[REGNO (index)]);
2317 /* Not sure this can happen, but leave in for now. */
2318 else if (GET_CODE (index) == SYMBOL_REF)
2320 output_addr_const (file, index);
2321 fputc (',', file);
2322 fputs (reg_names[REGNO (base)], file);
2324 else
2325 fatal_insn ("bad address", addr);
2327 else if (GET_CODE (base) == LO_SUM)
2329 gcc_assert (!index && REG_P (XEXP (base, 0)));
2330 if (small_data_operand (XEXP (base, 1), VOIDmode))
2331 fputs ("sda(", file);
2332 else
2333 fputs ("low(", file);
2334 output_addr_const (file, plus_constant (Pmode, XEXP (base, 1),
2335 offset));
2336 fputs ("),", file);
2337 fputs (reg_names[REGNO (XEXP (base, 0))], file);
2339 else
2340 fatal_insn ("bad address", addr);
2341 break;
2343 case LO_SUM :
2344 if (!REG_P (XEXP (addr, 0)))
2345 fatal_insn ("lo_sum not of register", addr);
2346 if (small_data_operand (XEXP (addr, 1), VOIDmode))
2347 fputs ("sda(", file);
2348 else
2349 fputs ("low(", file);
2350 output_addr_const (file, XEXP (addr, 1));
2351 fputs ("),", file);
2352 fputs (reg_names[REGNO (XEXP (addr, 0))], file);
2353 break;
2355 case PRE_INC : /* Assume SImode. */
2356 fprintf (file, "+%s", reg_names[REGNO (XEXP (addr, 0))]);
2357 break;
2359 case PRE_DEC : /* Assume SImode. */
2360 fprintf (file, "-%s", reg_names[REGNO (XEXP (addr, 0))]);
2361 break;
2363 case POST_INC : /* Assume SImode. */
2364 fprintf (file, "%s+", reg_names[REGNO (XEXP (addr, 0))]);
2365 break;
2367 default :
2368 output_addr_const (file, addr);
2369 break;
2373 static bool
2374 m32r_print_operand_punct_valid_p (unsigned char code)
2376 return m32r_punct_chars[code];
2379 /* Return true if the operands are the constants 0 and 1. */
2382 zero_and_one (rtx operand1, rtx operand2)
2384 return
2385 CONST_INT_P (operand1)
2386 && CONST_INT_P (operand2)
2387 && ( ((INTVAL (operand1) == 0) && (INTVAL (operand2) == 1))
2388 ||((INTVAL (operand1) == 1) && (INTVAL (operand2) == 0)));
2391 /* Generate the correct assembler code to handle the conditional loading of a
2392 value into a register. It is known that the operands satisfy the
2393 conditional_move_operand() function above. The destination is operand[0].
2394 The condition is operand [1]. The 'true' value is operand [2] and the
2395 'false' value is operand [3]. */
2397 char *
2398 emit_cond_move (rtx * operands, rtx insn ATTRIBUTE_UNUSED)
2400 static char buffer [100];
2401 const char * dest = reg_names [REGNO (operands [0])];
2403 buffer [0] = 0;
2405 /* Destination must be a register. */
2406 gcc_assert (REG_P (operands [0]));
2407 gcc_assert (conditional_move_operand (operands [2], SImode));
2408 gcc_assert (conditional_move_operand (operands [3], SImode));
2410 /* Check to see if the test is reversed. */
2411 if (GET_CODE (operands [1]) == NE)
2413 rtx tmp = operands [2];
2414 operands [2] = operands [3];
2415 operands [3] = tmp;
2418 sprintf (buffer, "mvfc %s, cbr", dest);
2420 /* If the true value was '0' then we need to invert the results of the move. */
2421 if (INTVAL (operands [2]) == 0)
2422 sprintf (buffer + strlen (buffer), "\n\txor3 %s, %s, #1",
2423 dest, dest);
2425 return buffer;
2428 /* Returns true if the registers contained in the two
2429 rtl expressions are different. */
2432 m32r_not_same_reg (rtx a, rtx b)
2434 int reg_a = -1;
2435 int reg_b = -2;
2437 while (GET_CODE (a) == SUBREG)
2438 a = SUBREG_REG (a);
2440 if (REG_P (a))
2441 reg_a = REGNO (a);
2443 while (GET_CODE (b) == SUBREG)
2444 b = SUBREG_REG (b);
2446 if (REG_P (b))
2447 reg_b = REGNO (b);
2449 return reg_a != reg_b;
2454 m32r_function_symbol (const char *name)
2456 int extra_flags = 0;
2457 enum m32r_model model;
2458 rtx sym = gen_rtx_SYMBOL_REF (Pmode, name);
2460 if (TARGET_MODEL_SMALL)
2461 model = M32R_MODEL_SMALL;
2462 else if (TARGET_MODEL_MEDIUM)
2463 model = M32R_MODEL_MEDIUM;
2464 else if (TARGET_MODEL_LARGE)
2465 model = M32R_MODEL_LARGE;
2466 else
2467 gcc_unreachable (); /* Shouldn't happen. */
2468 extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
2470 if (extra_flags)
2471 SYMBOL_REF_FLAGS (sym) |= extra_flags;
2473 return sym;
2476 /* Use a library function to move some bytes. */
2478 static void
2479 block_move_call (rtx dest_reg, rtx src_reg, rtx bytes_rtx)
2481 /* We want to pass the size as Pmode, which will normally be SImode
2482 but will be DImode if we are using 64-bit longs and pointers. */
2483 if (GET_MODE (bytes_rtx) != VOIDmode
2484 && GET_MODE (bytes_rtx) != Pmode)
2485 bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
2487 emit_library_call (m32r_function_symbol ("memcpy"), LCT_NORMAL,
2488 VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
2489 convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
2490 TYPE_UNSIGNED (sizetype)),
2491 TYPE_MODE (sizetype));
2494 /* Expand string/block move operations.
2496 operands[0] is the pointer to the destination.
2497 operands[1] is the pointer to the source.
2498 operands[2] is the number of bytes to move.
2499 operands[3] is the alignment.
2501 Returns 1 upon success, 0 otherwise. */
2504 m32r_expand_block_move (rtx operands[])
2506 rtx orig_dst = operands[0];
2507 rtx orig_src = operands[1];
2508 rtx bytes_rtx = operands[2];
2509 rtx align_rtx = operands[3];
2510 int constp = CONST_INT_P (bytes_rtx);
2511 HOST_WIDE_INT bytes = constp ? INTVAL (bytes_rtx) : 0;
2512 int align = INTVAL (align_rtx);
2513 int leftover;
2514 rtx src_reg;
2515 rtx dst_reg;
2517 if (constp && bytes <= 0)
2518 return 1;
2520 /* Move the address into scratch registers. */
2521 dst_reg = copy_addr_to_reg (XEXP (orig_dst, 0));
2522 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2524 if (align > UNITS_PER_WORD)
2525 align = UNITS_PER_WORD;
2527 /* If we prefer size over speed, always use a function call.
2528 If we do not know the size, use a function call.
2529 If the blocks are not word aligned, use a function call. */
2530 if (optimize_size || ! constp || align != UNITS_PER_WORD)
2532 block_move_call (dst_reg, src_reg, bytes_rtx);
2533 return 0;
2536 leftover = bytes % MAX_MOVE_BYTES;
2537 bytes -= leftover;
2539 /* If necessary, generate a loop to handle the bulk of the copy. */
2540 if (bytes)
2542 rtx label = NULL_RTX;
2543 rtx final_src = NULL_RTX;
2544 rtx at_a_time = GEN_INT (MAX_MOVE_BYTES);
2545 rtx rounded_total = GEN_INT (bytes);
2546 rtx new_dst_reg = gen_reg_rtx (SImode);
2547 rtx new_src_reg = gen_reg_rtx (SImode);
2549 /* If we are going to have to perform this loop more than
2550 once, then generate a label and compute the address the
2551 source register will contain upon completion of the final
2552 iteration. */
2553 if (bytes > MAX_MOVE_BYTES)
2555 final_src = gen_reg_rtx (Pmode);
2557 if (INT16_P(bytes))
2558 emit_insn (gen_addsi3 (final_src, src_reg, rounded_total));
2559 else
2561 emit_insn (gen_movsi (final_src, rounded_total));
2562 emit_insn (gen_addsi3 (final_src, final_src, src_reg));
2565 label = gen_label_rtx ();
2566 emit_label (label);
2569 /* It is known that output_block_move() will update src_reg to point
2570 to the word after the end of the source block, and dst_reg to point
2571 to the last word of the destination block, provided that the block
2572 is MAX_MOVE_BYTES long. */
2573 emit_insn (gen_movmemsi_internal (dst_reg, src_reg, at_a_time,
2574 new_dst_reg, new_src_reg));
2575 emit_move_insn (dst_reg, new_dst_reg);
2576 emit_move_insn (src_reg, new_src_reg);
2577 emit_insn (gen_addsi3 (dst_reg, dst_reg, GEN_INT (4)));
2579 if (bytes > MAX_MOVE_BYTES)
2581 rtx test = gen_rtx_NE (VOIDmode, src_reg, final_src);
2582 emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label));
2586 if (leftover)
2587 emit_insn (gen_movmemsi_internal (dst_reg, src_reg, GEN_INT (leftover),
2588 gen_reg_rtx (SImode),
2589 gen_reg_rtx (SImode)));
2590 return 1;
2594 /* Emit load/stores for a small constant word aligned block_move.
2596 operands[0] is the memory address of the destination.
2597 operands[1] is the memory address of the source.
2598 operands[2] is the number of bytes to move.
2599 operands[3] is a temp register.
2600 operands[4] is a temp register. */
2602 void
2603 m32r_output_block_move (rtx insn ATTRIBUTE_UNUSED, rtx operands[])
2605 HOST_WIDE_INT bytes = INTVAL (operands[2]);
2606 int first_time;
2607 int got_extra = 0;
2609 gcc_assert (bytes >= 1 && bytes <= MAX_MOVE_BYTES);
2611 /* We do not have a post-increment store available, so the first set of
2612 stores are done without any increment, then the remaining ones can use
2613 the pre-increment addressing mode.
2615 Note: expand_block_move() also relies upon this behavior when building
2616 loops to copy large blocks. */
2617 first_time = 1;
2619 while (bytes > 0)
2621 if (bytes >= 8)
2623 if (first_time)
2625 output_asm_insn ("ld\t%5, %p1", operands);
2626 output_asm_insn ("ld\t%6, %p1", operands);
2627 output_asm_insn ("st\t%5, @%0", operands);
2628 output_asm_insn ("st\t%6, %s0", operands);
2630 else
2632 output_asm_insn ("ld\t%5, %p1", operands);
2633 output_asm_insn ("ld\t%6, %p1", operands);
2634 output_asm_insn ("st\t%5, %s0", operands);
2635 output_asm_insn ("st\t%6, %s0", operands);
2638 bytes -= 8;
2640 else if (bytes >= 4)
2642 if (bytes > 4)
2643 got_extra = 1;
2645 output_asm_insn ("ld\t%5, %p1", operands);
2647 if (got_extra)
2648 output_asm_insn ("ld\t%6, %p1", operands);
2650 if (first_time)
2651 output_asm_insn ("st\t%5, @%0", operands);
2652 else
2653 output_asm_insn ("st\t%5, %s0", operands);
2655 bytes -= 4;
2657 else
2659 /* Get the entire next word, even though we do not want all of it.
2660 The saves us from doing several smaller loads, and we assume that
2661 we cannot cause a page fault when at least part of the word is in
2662 valid memory [since we don't get called if things aren't properly
2663 aligned]. */
2664 int dst_offset = first_time ? 0 : 4;
2665 /* The amount of increment we have to make to the
2666 destination pointer. */
2667 int dst_inc_amount = dst_offset + bytes - 4;
2668 /* The same for the source pointer. */
2669 int src_inc_amount = bytes;
2670 int last_shift;
2671 rtx my_operands[3];
2673 /* If got_extra is true then we have already loaded
2674 the next word as part of loading and storing the previous word. */
2675 if (! got_extra)
2676 output_asm_insn ("ld\t%6, @%1", operands);
2678 if (bytes >= 2)
2680 bytes -= 2;
2682 output_asm_insn ("sra3\t%5, %6, #16", operands);
2683 my_operands[0] = operands[5];
2684 my_operands[1] = GEN_INT (dst_offset);
2685 my_operands[2] = operands[0];
2686 output_asm_insn ("sth\t%0, @(%1,%2)", my_operands);
2688 /* If there is a byte left to store then increment the
2689 destination address and shift the contents of the source
2690 register down by 8 bits. We could not do the address
2691 increment in the store half word instruction, because it does
2692 not have an auto increment mode. */
2693 if (bytes > 0) /* assert (bytes == 1) */
2695 dst_offset += 2;
2696 last_shift = 8;
2699 else
2700 last_shift = 24;
2702 if (bytes > 0)
2704 my_operands[0] = operands[6];
2705 my_operands[1] = GEN_INT (last_shift);
2706 output_asm_insn ("srai\t%0, #%1", my_operands);
2707 my_operands[0] = operands[6];
2708 my_operands[1] = GEN_INT (dst_offset);
2709 my_operands[2] = operands[0];
2710 output_asm_insn ("stb\t%0, @(%1,%2)", my_operands);
2713 /* Update the destination pointer if needed. We have to do
2714 this so that the patterns matches what we output in this
2715 function. */
2716 if (dst_inc_amount
2717 && !find_reg_note (insn, REG_UNUSED, operands[0]))
2719 my_operands[0] = operands[0];
2720 my_operands[1] = GEN_INT (dst_inc_amount);
2721 output_asm_insn ("addi\t%0, #%1", my_operands);
2724 /* Update the source pointer if needed. We have to do this
2725 so that the patterns matches what we output in this
2726 function. */
2727 if (src_inc_amount
2728 && !find_reg_note (insn, REG_UNUSED, operands[1]))
2730 my_operands[0] = operands[1];
2731 my_operands[1] = GEN_INT (src_inc_amount);
2732 output_asm_insn ("addi\t%0, #%1", my_operands);
2735 bytes = 0;
2738 first_time = 0;
2742 /* Return true if using NEW_REG in place of OLD_REG is ok. */
2745 m32r_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
2746 unsigned int new_reg)
2748 /* Interrupt routines can't clobber any register that isn't already used. */
2749 if (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl))
2750 && !df_regs_ever_live_p (new_reg))
2751 return 0;
2753 return 1;
2757 m32r_return_addr (int count)
2759 if (count != 0)
2760 return const0_rtx;
2762 return get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM);
2765 static void
2766 m32r_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2768 emit_move_insn (adjust_address (m_tramp, SImode, 0),
2769 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2770 0x017e8e17 : 0x178e7e01, SImode));
2771 emit_move_insn (adjust_address (m_tramp, SImode, 4),
2772 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2773 0x0c00ae86 : 0x86ae000c, SImode));
2774 emit_move_insn (adjust_address (m_tramp, SImode, 8),
2775 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2776 0xe627871e : 0x1e8727e6, SImode));
2777 emit_move_insn (adjust_address (m_tramp, SImode, 12),
2778 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2779 0xc616c626 : 0x26c61fc6, SImode));
2780 emit_move_insn (adjust_address (m_tramp, SImode, 16),
2781 chain_value);
2782 emit_move_insn (adjust_address (m_tramp, SImode, 20),
2783 XEXP (DECL_RTL (fndecl), 0));
2785 if (m32r_cache_flush_trap >= 0)
2786 emit_insn (gen_flush_icache
2787 (validize_mem (adjust_address (m_tramp, SImode, 0)),
2788 gen_int_mode (m32r_cache_flush_trap, SImode)));
2789 else if (m32r_cache_flush_func && m32r_cache_flush_func[0])
2790 emit_library_call (m32r_function_symbol (m32r_cache_flush_func),
2791 LCT_NORMAL, VOIDmode, 3, XEXP (m_tramp, 0), Pmode,
2792 gen_int_mode (TRAMPOLINE_SIZE, SImode), SImode,
2793 GEN_INT (3), SImode);
2796 /* True if X is a reg that can be used as a base reg. */
2798 static bool
2799 m32r_rtx_ok_for_base_p (const_rtx x, bool strict)
2801 if (! REG_P (x))
2802 return false;
2804 if (strict)
2806 if (GPR_P (REGNO (x)))
2807 return true;
2809 else
2811 if (GPR_P (REGNO (x))
2812 || REGNO (x) == ARG_POINTER_REGNUM
2813 || ! HARD_REGISTER_P (x))
2814 return true;
2817 return false;
2820 static inline bool
2821 m32r_rtx_ok_for_offset_p (const_rtx x)
2823 return (CONST_INT_P (x) && INT16_P (INTVAL (x)));
2826 static inline bool
2827 m32r_legitimate_offset_addres_p (enum machine_mode mode ATTRIBUTE_UNUSED,
2828 const_rtx x, bool strict)
2830 if (GET_CODE (x) == PLUS
2831 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict)
2832 && m32r_rtx_ok_for_offset_p (XEXP (x, 1)))
2833 return true;
2835 return false;
2838 /* For LO_SUM addresses, do not allow them if the MODE is > 1 word,
2839 since more than one instruction will be required. */
2841 static inline bool
2842 m32r_legitimate_lo_sum_addres_p (enum machine_mode mode, const_rtx x,
2843 bool strict)
2845 if (GET_CODE (x) == LO_SUM
2846 && (mode != BLKmode && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
2847 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict)
2848 && CONSTANT_P (XEXP (x, 1)))
2849 return true;
2851 return false;
2854 /* Is this a load and increment operation. */
2856 static inline bool
2857 m32r_load_postinc_p (enum machine_mode mode, const_rtx x, bool strict)
2859 if ((mode == SImode || mode == SFmode)
2860 && GET_CODE (x) == POST_INC
2861 && REG_P (XEXP (x, 0))
2862 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict))
2863 return true;
2865 return false;
2868 /* Is this an increment/decrement and store operation. */
2870 static inline bool
2871 m32r_store_preinc_predec_p (enum machine_mode mode, const_rtx x, bool strict)
2873 if ((mode == SImode || mode == SFmode)
2874 && (GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
2875 && REG_P (XEXP (x, 0)) \
2876 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict))
2877 return true;
2879 return false;
2882 /* Implement TARGET_LEGITIMATE_ADDRESS_P. */
2884 static bool
2885 m32r_legitimate_address_p (enum machine_mode mode, rtx x, bool strict)
2887 if (m32r_rtx_ok_for_base_p (x, strict)
2888 || m32r_legitimate_offset_addres_p (mode, x, strict)
2889 || m32r_legitimate_lo_sum_addres_p (mode, x, strict)
2890 || m32r_load_postinc_p (mode, x, strict)
2891 || m32r_store_preinc_predec_p (mode, x, strict))
2892 return true;
2894 return false;
2897 static void
2898 m32r_conditional_register_usage (void)
2900 if (flag_pic)
2902 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
2903 call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
2907 /* Implement TARGET_LEGITIMATE_CONSTANT_P
2909 We don't allow (plus symbol large-constant) as the relocations can't
2910 describe it. INTVAL > 32767 handles both 16-bit and 24-bit relocations.
2911 We allow all CONST_DOUBLE's as the md file patterns will force the
2912 constant to memory if they can't handle them. */
2914 static bool
2915 m32r_legitimate_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x)
2917 return !(GET_CODE (x) == CONST
2918 && GET_CODE (XEXP (x, 0)) == PLUS
2919 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2920 || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
2921 && CONST_INT_P (XEXP (XEXP (x, 0), 1))
2922 && UINTVAL (XEXP (XEXP (x, 0), 1)) > 32767);