gcc/
[official-gcc.git] / gcc / config / m32r / m32r.c
blob4c33b93eb1897aae00771481508838c3e015a22b
1 /* Subroutines used for code generation on the Renesas M32R cpu.
2 Copyright (C) 1996-2015 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 "hash-set.h"
25 #include "machmode.h"
26 #include "vec.h"
27 #include "double-int.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "symtab.h"
31 #include "wide-int.h"
32 #include "inchash.h"
33 #include "tree.h"
34 #include "stor-layout.h"
35 #include "varasm.h"
36 #include "stringpool.h"
37 #include "calls.h"
38 #include "rtl.h"
39 #include "regs.h"
40 #include "hard-reg-set.h"
41 #include "insn-config.h"
42 #include "conditions.h"
43 #include "output.h"
44 #include "dbxout.h"
45 #include "insn-attr.h"
46 #include "flags.h"
47 #include "hashtab.h"
48 #include "function.h"
49 #include "statistics.h"
50 #include "real.h"
51 #include "fixed-value.h"
52 #include "expmed.h"
53 #include "dojump.h"
54 #include "explow.h"
55 #include "emit-rtl.h"
56 #include "stmt.h"
57 #include "expr.h"
58 #include "recog.h"
59 #include "diagnostic-core.h"
60 #include "ggc.h"
61 #include "dominance.h"
62 #include "cfg.h"
63 #include "cfgrtl.h"
64 #include "cfganal.h"
65 #include "lcm.h"
66 #include "cfgbuild.h"
67 #include "cfgcleanup.h"
68 #include "predict.h"
69 #include "basic-block.h"
70 #include "df.h"
71 #include "tm_p.h"
72 #include "target.h"
73 #include "target-def.h"
74 #include "tm-constrs.h"
75 #include "opts.h"
76 #include "builtins.h"
78 /* Array of valid operand punctuation characters. */
79 static char m32r_punct_chars[256];
81 /* Machine-specific symbol_ref flags. */
82 #define SYMBOL_FLAG_MODEL_SHIFT SYMBOL_FLAG_MACH_DEP_SHIFT
83 #define SYMBOL_REF_MODEL(X) \
84 ((enum m32r_model) ((SYMBOL_REF_FLAGS (X) >> SYMBOL_FLAG_MODEL_SHIFT) & 3))
86 /* For string literals, etc. */
87 #define LIT_NAME_P(NAME) ((NAME)[0] == '*' && (NAME)[1] == '.')
89 /* Forward declaration. */
90 static void m32r_option_override (void);
91 static void init_reg_tables (void);
92 static void block_move_call (rtx, rtx, rtx);
93 static int m32r_is_insn (rtx);
94 static bool m32r_legitimate_address_p (machine_mode, rtx, bool);
95 static rtx m32r_legitimize_address (rtx, rtx, machine_mode);
96 static bool m32r_mode_dependent_address_p (const_rtx, addr_space_t);
97 static tree m32r_handle_model_attribute (tree *, tree, tree, int, bool *);
98 static void m32r_print_operand (FILE *, rtx, int);
99 static void m32r_print_operand_address (FILE *, rtx);
100 static bool m32r_print_operand_punct_valid_p (unsigned char code);
101 static void m32r_output_function_prologue (FILE *, HOST_WIDE_INT);
102 static void m32r_output_function_epilogue (FILE *, HOST_WIDE_INT);
104 static void m32r_file_start (void);
106 static int m32r_adjust_priority (rtx_insn *, int);
107 static int m32r_issue_rate (void);
109 static void m32r_encode_section_info (tree, rtx, int);
110 static bool m32r_in_small_data_p (const_tree);
111 static bool m32r_return_in_memory (const_tree, const_tree);
112 static rtx m32r_function_value (const_tree, const_tree, bool);
113 static rtx m32r_libcall_value (machine_mode, const_rtx);
114 static bool m32r_function_value_regno_p (const unsigned int);
115 static void m32r_setup_incoming_varargs (cumulative_args_t, machine_mode,
116 tree, int *, int);
117 static void init_idents (void);
118 static bool m32r_rtx_costs (rtx, int, int, int, int *, bool speed);
119 static int m32r_memory_move_cost (machine_mode, reg_class_t, bool);
120 static bool m32r_pass_by_reference (cumulative_args_t, machine_mode,
121 const_tree, bool);
122 static int m32r_arg_partial_bytes (cumulative_args_t, machine_mode,
123 tree, bool);
124 static rtx m32r_function_arg (cumulative_args_t, machine_mode,
125 const_tree, bool);
126 static void m32r_function_arg_advance (cumulative_args_t, machine_mode,
127 const_tree, bool);
128 static bool m32r_can_eliminate (const int, const int);
129 static void m32r_conditional_register_usage (void);
130 static void m32r_trampoline_init (rtx, tree, rtx);
131 static bool m32r_legitimate_constant_p (machine_mode, rtx);
133 /* M32R specific attributes. */
135 static const struct attribute_spec m32r_attribute_table[] =
137 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
138 affects_type_identity } */
139 { "interrupt", 0, 0, true, false, false, NULL, false },
140 { "model", 1, 1, true, false, false, m32r_handle_model_attribute,
141 false },
142 { NULL, 0, 0, false, false, false, NULL, false }
145 /* Initialize the GCC target structure. */
146 #undef TARGET_ATTRIBUTE_TABLE
147 #define TARGET_ATTRIBUTE_TABLE m32r_attribute_table
149 #undef TARGET_LEGITIMATE_ADDRESS_P
150 #define TARGET_LEGITIMATE_ADDRESS_P m32r_legitimate_address_p
151 #undef TARGET_LEGITIMIZE_ADDRESS
152 #define TARGET_LEGITIMIZE_ADDRESS m32r_legitimize_address
153 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
154 #define TARGET_MODE_DEPENDENT_ADDRESS_P m32r_mode_dependent_address_p
156 #undef TARGET_ASM_ALIGNED_HI_OP
157 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
158 #undef TARGET_ASM_ALIGNED_SI_OP
159 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
161 #undef TARGET_PRINT_OPERAND
162 #define TARGET_PRINT_OPERAND m32r_print_operand
163 #undef TARGET_PRINT_OPERAND_ADDRESS
164 #define TARGET_PRINT_OPERAND_ADDRESS m32r_print_operand_address
165 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
166 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P m32r_print_operand_punct_valid_p
168 #undef TARGET_ASM_FUNCTION_PROLOGUE
169 #define TARGET_ASM_FUNCTION_PROLOGUE m32r_output_function_prologue
170 #undef TARGET_ASM_FUNCTION_EPILOGUE
171 #define TARGET_ASM_FUNCTION_EPILOGUE m32r_output_function_epilogue
173 #undef TARGET_ASM_FILE_START
174 #define TARGET_ASM_FILE_START m32r_file_start
176 #undef TARGET_SCHED_ADJUST_PRIORITY
177 #define TARGET_SCHED_ADJUST_PRIORITY m32r_adjust_priority
178 #undef TARGET_SCHED_ISSUE_RATE
179 #define TARGET_SCHED_ISSUE_RATE m32r_issue_rate
181 #undef TARGET_OPTION_OVERRIDE
182 #define TARGET_OPTION_OVERRIDE m32r_option_override
184 #undef TARGET_ENCODE_SECTION_INFO
185 #define TARGET_ENCODE_SECTION_INFO m32r_encode_section_info
186 #undef TARGET_IN_SMALL_DATA_P
187 #define TARGET_IN_SMALL_DATA_P m32r_in_small_data_p
190 #undef TARGET_MEMORY_MOVE_COST
191 #define TARGET_MEMORY_MOVE_COST m32r_memory_move_cost
192 #undef TARGET_RTX_COSTS
193 #define TARGET_RTX_COSTS m32r_rtx_costs
194 #undef TARGET_ADDRESS_COST
195 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
197 #undef TARGET_PROMOTE_PROTOTYPES
198 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
199 #undef TARGET_RETURN_IN_MEMORY
200 #define TARGET_RETURN_IN_MEMORY m32r_return_in_memory
202 #undef TARGET_FUNCTION_VALUE
203 #define TARGET_FUNCTION_VALUE m32r_function_value
204 #undef TARGET_LIBCALL_VALUE
205 #define TARGET_LIBCALL_VALUE m32r_libcall_value
206 #undef TARGET_FUNCTION_VALUE_REGNO_P
207 #define TARGET_FUNCTION_VALUE_REGNO_P m32r_function_value_regno_p
209 #undef TARGET_SETUP_INCOMING_VARARGS
210 #define TARGET_SETUP_INCOMING_VARARGS m32r_setup_incoming_varargs
211 #undef TARGET_MUST_PASS_IN_STACK
212 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
213 #undef TARGET_PASS_BY_REFERENCE
214 #define TARGET_PASS_BY_REFERENCE m32r_pass_by_reference
215 #undef TARGET_ARG_PARTIAL_BYTES
216 #define TARGET_ARG_PARTIAL_BYTES m32r_arg_partial_bytes
217 #undef TARGET_FUNCTION_ARG
218 #define TARGET_FUNCTION_ARG m32r_function_arg
219 #undef TARGET_FUNCTION_ARG_ADVANCE
220 #define TARGET_FUNCTION_ARG_ADVANCE m32r_function_arg_advance
222 #undef TARGET_CAN_ELIMINATE
223 #define TARGET_CAN_ELIMINATE m32r_can_eliminate
225 #undef TARGET_CONDITIONAL_REGISTER_USAGE
226 #define TARGET_CONDITIONAL_REGISTER_USAGE m32r_conditional_register_usage
228 #undef TARGET_TRAMPOLINE_INIT
229 #define TARGET_TRAMPOLINE_INIT m32r_trampoline_init
231 #undef TARGET_LEGITIMATE_CONSTANT_P
232 #define TARGET_LEGITIMATE_CONSTANT_P m32r_legitimate_constant_p
234 struct gcc_target targetm = TARGET_INITIALIZER;
236 /* Called by m32r_option_override to initialize various things. */
238 void
239 m32r_init (void)
241 init_reg_tables ();
243 /* Initialize array for TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
244 memset (m32r_punct_chars, 0, sizeof (m32r_punct_chars));
245 m32r_punct_chars['#'] = 1;
246 m32r_punct_chars['@'] = 1; /* ??? no longer used */
248 /* Provide default value if not specified. */
249 if (!global_options_set.x_g_switch_value)
250 g_switch_value = SDATA_DEFAULT_SIZE;
253 static void
254 m32r_option_override (void)
256 /* These need to be done at start up.
257 It's convenient to do them here. */
258 m32r_init ();
259 SUBTARGET_OVERRIDE_OPTIONS;
262 /* Vectors to keep interesting information about registers where it can easily
263 be got. We use to use the actual mode value as the bit number, but there
264 is (or may be) more than 32 modes now. Instead we use two tables: one
265 indexed by hard register number, and one indexed by mode. */
267 /* The purpose of m32r_mode_class is to shrink the range of modes so that
268 they all fit (as bit numbers) in a 32-bit word (again). Each real mode is
269 mapped into one m32r_mode_class mode. */
271 enum m32r_mode_class
273 C_MODE,
274 S_MODE, D_MODE, T_MODE, O_MODE,
275 SF_MODE, DF_MODE, TF_MODE, OF_MODE, A_MODE
278 /* Modes for condition codes. */
279 #define C_MODES (1 << (int) C_MODE)
281 /* Modes for single-word and smaller quantities. */
282 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
284 /* Modes for double-word and smaller quantities. */
285 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
287 /* Modes for quad-word and smaller quantities. */
288 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
290 /* Modes for accumulators. */
291 #define A_MODES (1 << (int) A_MODE)
293 /* Value is 1 if register/mode pair is acceptable on arc. */
295 const unsigned int m32r_hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] =
297 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES,
298 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, S_MODES, S_MODES, S_MODES,
299 S_MODES, C_MODES, A_MODES, A_MODES
302 unsigned int m32r_mode_class [NUM_MACHINE_MODES];
304 enum reg_class m32r_regno_reg_class[FIRST_PSEUDO_REGISTER];
306 static void
307 init_reg_tables (void)
309 int i;
311 for (i = 0; i < NUM_MACHINE_MODES; i++)
313 machine_mode m = (machine_mode) i;
315 switch (GET_MODE_CLASS (m))
317 case MODE_INT:
318 case MODE_PARTIAL_INT:
319 case MODE_COMPLEX_INT:
320 if (GET_MODE_SIZE (m) <= 4)
321 m32r_mode_class[i] = 1 << (int) S_MODE;
322 else if (GET_MODE_SIZE (m) == 8)
323 m32r_mode_class[i] = 1 << (int) D_MODE;
324 else if (GET_MODE_SIZE (m) == 16)
325 m32r_mode_class[i] = 1 << (int) T_MODE;
326 else if (GET_MODE_SIZE (m) == 32)
327 m32r_mode_class[i] = 1 << (int) O_MODE;
328 else
329 m32r_mode_class[i] = 0;
330 break;
331 case MODE_FLOAT:
332 case MODE_COMPLEX_FLOAT:
333 if (GET_MODE_SIZE (m) <= 4)
334 m32r_mode_class[i] = 1 << (int) SF_MODE;
335 else if (GET_MODE_SIZE (m) == 8)
336 m32r_mode_class[i] = 1 << (int) DF_MODE;
337 else if (GET_MODE_SIZE (m) == 16)
338 m32r_mode_class[i] = 1 << (int) TF_MODE;
339 else if (GET_MODE_SIZE (m) == 32)
340 m32r_mode_class[i] = 1 << (int) OF_MODE;
341 else
342 m32r_mode_class[i] = 0;
343 break;
344 case MODE_CC:
345 m32r_mode_class[i] = 1 << (int) C_MODE;
346 break;
347 default:
348 m32r_mode_class[i] = 0;
349 break;
353 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
355 if (GPR_P (i))
356 m32r_regno_reg_class[i] = GENERAL_REGS;
357 else if (i == ARG_POINTER_REGNUM)
358 m32r_regno_reg_class[i] = GENERAL_REGS;
359 else
360 m32r_regno_reg_class[i] = NO_REGS;
364 /* M32R specific attribute support.
366 interrupt - for interrupt functions
368 model - select code model used to access object
370 small: addresses use 24 bits, use bl to make calls
371 medium: addresses use 32 bits, use bl to make calls
372 large: addresses use 32 bits, use seth/add3/jl to make calls
374 Grep for MODEL in m32r.h for more info. */
376 static tree small_ident1;
377 static tree small_ident2;
378 static tree medium_ident1;
379 static tree medium_ident2;
380 static tree large_ident1;
381 static tree large_ident2;
383 static void
384 init_idents (void)
386 if (small_ident1 == 0)
388 small_ident1 = get_identifier ("small");
389 small_ident2 = get_identifier ("__small__");
390 medium_ident1 = get_identifier ("medium");
391 medium_ident2 = get_identifier ("__medium__");
392 large_ident1 = get_identifier ("large");
393 large_ident2 = get_identifier ("__large__");
397 /* Handle an "model" attribute; arguments as in
398 struct attribute_spec.handler. */
399 static tree
400 m32r_handle_model_attribute (tree *node ATTRIBUTE_UNUSED, tree name,
401 tree args, int flags ATTRIBUTE_UNUSED,
402 bool *no_add_attrs)
404 tree arg;
406 init_idents ();
407 arg = TREE_VALUE (args);
409 if (arg != small_ident1
410 && arg != small_ident2
411 && arg != medium_ident1
412 && arg != medium_ident2
413 && arg != large_ident1
414 && arg != large_ident2)
416 warning (OPT_Wattributes, "invalid argument of %qs attribute",
417 IDENTIFIER_POINTER (name));
418 *no_add_attrs = true;
421 return NULL_TREE;
424 /* Encode section information of DECL, which is either a VAR_DECL,
425 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
427 For the M32R we want to record:
429 - whether the object lives in .sdata/.sbss.
430 - what code model should be used to access the object
433 static void
434 m32r_encode_section_info (tree decl, rtx rtl, int first)
436 int extra_flags = 0;
437 tree model_attr;
438 enum m32r_model model;
440 default_encode_section_info (decl, rtl, first);
442 if (!DECL_P (decl))
443 return;
445 model_attr = lookup_attribute ("model", DECL_ATTRIBUTES (decl));
446 if (model_attr)
448 tree id;
450 init_idents ();
452 id = TREE_VALUE (TREE_VALUE (model_attr));
454 if (id == small_ident1 || id == small_ident2)
455 model = M32R_MODEL_SMALL;
456 else if (id == medium_ident1 || id == medium_ident2)
457 model = M32R_MODEL_MEDIUM;
458 else if (id == large_ident1 || id == large_ident2)
459 model = M32R_MODEL_LARGE;
460 else
461 gcc_unreachable (); /* shouldn't happen */
463 else
465 if (TARGET_MODEL_SMALL)
466 model = M32R_MODEL_SMALL;
467 else if (TARGET_MODEL_MEDIUM)
468 model = M32R_MODEL_MEDIUM;
469 else if (TARGET_MODEL_LARGE)
470 model = M32R_MODEL_LARGE;
471 else
472 gcc_unreachable (); /* shouldn't happen */
474 extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
476 if (extra_flags)
477 SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= extra_flags;
480 /* Only mark the object as being small data area addressable if
481 it hasn't been explicitly marked with a code model.
483 The user can explicitly put an object in the small data area with the
484 section attribute. If the object is in sdata/sbss and marked with a
485 code model do both [put the object in .sdata and mark it as being
486 addressed with a specific code model - don't mark it as being addressed
487 with an SDA reloc though]. This is ok and might be useful at times. If
488 the object doesn't fit the linker will give an error. */
490 static bool
491 m32r_in_small_data_p (const_tree decl)
493 const char *section;
495 if (TREE_CODE (decl) != VAR_DECL)
496 return false;
498 if (lookup_attribute ("model", DECL_ATTRIBUTES (decl)))
499 return false;
501 section = DECL_SECTION_NAME (decl);
502 if (section)
504 if (strcmp (section, ".sdata") == 0 || strcmp (section, ".sbss") == 0)
505 return true;
507 else
509 if (! TREE_READONLY (decl) && ! TARGET_SDATA_NONE)
511 int size = int_size_in_bytes (TREE_TYPE (decl));
513 if (size > 0 && size <= g_switch_value)
514 return true;
518 return false;
521 /* Do anything needed before RTL is emitted for each function. */
523 void
524 m32r_init_expanders (void)
526 /* ??? At one point there was code here. The function is left in
527 to make it easy to experiment. */
531 call_operand (rtx op, machine_mode mode)
533 if (!MEM_P (op))
534 return 0;
535 op = XEXP (op, 0);
536 return call_address_operand (op, mode);
539 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
542 small_data_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
544 if (! TARGET_SDATA_USE)
545 return 0;
547 if (GET_CODE (op) == SYMBOL_REF)
548 return SYMBOL_REF_SMALL_P (op);
550 if (GET_CODE (op) == CONST
551 && GET_CODE (XEXP (op, 0)) == PLUS
552 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
553 && satisfies_constraint_J (XEXP (XEXP (op, 0), 1)))
554 return SYMBOL_REF_SMALL_P (XEXP (XEXP (op, 0), 0));
556 return 0;
559 /* Return 1 if OP is a symbol that can use 24-bit addressing. */
562 addr24_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
564 rtx sym;
566 if (flag_pic)
567 return 0;
569 if (GET_CODE (op) == LABEL_REF)
570 return TARGET_ADDR24;
572 if (GET_CODE (op) == SYMBOL_REF)
573 sym = op;
574 else if (GET_CODE (op) == CONST
575 && GET_CODE (XEXP (op, 0)) == PLUS
576 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
577 && satisfies_constraint_M (XEXP (XEXP (op, 0), 1)))
578 sym = XEXP (XEXP (op, 0), 0);
579 else
580 return 0;
582 if (SYMBOL_REF_MODEL (sym) == M32R_MODEL_SMALL)
583 return 1;
585 if (TARGET_ADDR24
586 && (CONSTANT_POOL_ADDRESS_P (sym)
587 || LIT_NAME_P (XSTR (sym, 0))))
588 return 1;
590 return 0;
593 /* Return 1 if OP is a symbol that needs 32-bit addressing. */
596 addr32_operand (rtx op, machine_mode mode)
598 rtx sym;
600 if (GET_CODE (op) == LABEL_REF)
601 return TARGET_ADDR32;
603 if (GET_CODE (op) == SYMBOL_REF)
604 sym = op;
605 else if (GET_CODE (op) == CONST
606 && GET_CODE (XEXP (op, 0)) == PLUS
607 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
608 && CONST_INT_P (XEXP (XEXP (op, 0), 1))
609 && ! flag_pic)
610 sym = XEXP (XEXP (op, 0), 0);
611 else
612 return 0;
614 return (! addr24_operand (sym, mode)
615 && ! small_data_operand (sym, mode));
618 /* Return 1 if OP is a function that can be called with the `bl' insn. */
621 call26_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
623 if (flag_pic)
624 return 1;
626 if (GET_CODE (op) == SYMBOL_REF)
627 return SYMBOL_REF_MODEL (op) != M32R_MODEL_LARGE;
629 return TARGET_CALL26;
632 /* Return 1 if OP is a DImode const we want to handle inline.
633 This must match the code in the movdi pattern.
634 It is used by the 'G' constraint. */
637 easy_di_const (rtx op)
639 rtx high_rtx, low_rtx;
640 HOST_WIDE_INT high, low;
642 split_double (op, &high_rtx, &low_rtx);
643 high = INTVAL (high_rtx);
644 low = INTVAL (low_rtx);
645 /* Pick constants loadable with 2 16-bit `ldi' insns. */
646 if (high >= -128 && high <= 127
647 && low >= -128 && low <= 127)
648 return 1;
649 return 0;
652 /* Return 1 if OP is a DFmode const we want to handle inline.
653 This must match the code in the movdf pattern.
654 It is used by the 'H' constraint. */
657 easy_df_const (rtx op)
659 REAL_VALUE_TYPE r;
660 long l[2];
662 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
663 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
664 if (l[0] == 0 && l[1] == 0)
665 return 1;
666 if ((l[0] & 0xffff) == 0 && l[1] == 0)
667 return 1;
668 return 0;
671 /* Return 1 if OP is (mem (reg ...)).
672 This is used in insn length calcs. */
675 memreg_operand (rtx op, machine_mode mode ATTRIBUTE_UNUSED)
677 return MEM_P (op) && REG_P (XEXP (op, 0));
680 /* Return nonzero if TYPE must be passed by indirect reference. */
682 static bool
683 m32r_pass_by_reference (cumulative_args_t ca ATTRIBUTE_UNUSED,
684 machine_mode mode, const_tree type,
685 bool named ATTRIBUTE_UNUSED)
687 int size;
689 if (type)
690 size = int_size_in_bytes (type);
691 else
692 size = GET_MODE_SIZE (mode);
694 return (size < 0 || size > 8);
697 /* Comparisons. */
699 /* X and Y are two things to compare using CODE. Emit the compare insn and
700 return the rtx for compare [arg0 of the if_then_else].
701 If need_compare is true then the comparison insn must be generated, rather
702 than being subsumed into the following branch instruction. */
705 gen_compare (enum rtx_code code, rtx x, rtx y, int need_compare)
707 enum rtx_code compare_code;
708 enum rtx_code branch_code;
709 rtx cc_reg = gen_rtx_REG (CCmode, CARRY_REGNUM);
710 int must_swap = 0;
712 switch (code)
714 case EQ: compare_code = EQ; branch_code = NE; break;
715 case NE: compare_code = EQ; branch_code = EQ; break;
716 case LT: compare_code = LT; branch_code = NE; break;
717 case LE: compare_code = LT; branch_code = EQ; must_swap = 1; break;
718 case GT: compare_code = LT; branch_code = NE; must_swap = 1; break;
719 case GE: compare_code = LT; branch_code = EQ; break;
720 case LTU: compare_code = LTU; branch_code = NE; break;
721 case LEU: compare_code = LTU; branch_code = EQ; must_swap = 1; break;
722 case GTU: compare_code = LTU; branch_code = NE; must_swap = 1; break;
723 case GEU: compare_code = LTU; branch_code = EQ; break;
725 default:
726 gcc_unreachable ();
729 if (need_compare)
731 switch (compare_code)
733 case EQ:
734 if (satisfies_constraint_P (y) /* Reg equal to small const. */
735 && y != const0_rtx)
737 rtx tmp = gen_reg_rtx (SImode);
739 emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
740 x = tmp;
741 y = const0_rtx;
743 else if (CONSTANT_P (y)) /* Reg equal to const. */
745 rtx tmp = force_reg (GET_MODE (x), y);
746 y = tmp;
749 if (register_operand (y, SImode) /* Reg equal to reg. */
750 || y == const0_rtx) /* Reg equal to zero. */
752 emit_insn (gen_cmp_eqsi_insn (x, y));
754 return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
756 break;
758 case LT:
759 if (register_operand (y, SImode)
760 || satisfies_constraint_P (y))
762 rtx tmp = gen_reg_rtx (SImode); /* Reg compared to reg. */
764 switch (code)
766 case LT:
767 emit_insn (gen_cmp_ltsi_insn (x, y));
768 code = EQ;
769 break;
770 case LE:
771 if (y == const0_rtx)
772 tmp = const1_rtx;
773 else
774 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
775 emit_insn (gen_cmp_ltsi_insn (x, tmp));
776 code = EQ;
777 break;
778 case GT:
779 if (CONST_INT_P (y))
780 tmp = gen_rtx_PLUS (SImode, y, const1_rtx);
781 else
782 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
783 emit_insn (gen_cmp_ltsi_insn (x, tmp));
784 code = NE;
785 break;
786 case GE:
787 emit_insn (gen_cmp_ltsi_insn (x, y));
788 code = NE;
789 break;
790 default:
791 gcc_unreachable ();
794 return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
796 break;
798 case LTU:
799 if (register_operand (y, SImode)
800 || satisfies_constraint_P (y))
802 rtx tmp = gen_reg_rtx (SImode); /* Reg (unsigned) compared to reg. */
804 switch (code)
806 case LTU:
807 emit_insn (gen_cmp_ltusi_insn (x, y));
808 code = EQ;
809 break;
810 case LEU:
811 if (y == const0_rtx)
812 tmp = const1_rtx;
813 else
814 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
815 emit_insn (gen_cmp_ltusi_insn (x, tmp));
816 code = EQ;
817 break;
818 case GTU:
819 if (CONST_INT_P (y))
820 tmp = gen_rtx_PLUS (SImode, y, const1_rtx);
821 else
822 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
823 emit_insn (gen_cmp_ltusi_insn (x, tmp));
824 code = NE;
825 break;
826 case GEU:
827 emit_insn (gen_cmp_ltusi_insn (x, y));
828 code = NE;
829 break;
830 default:
831 gcc_unreachable ();
834 return gen_rtx_fmt_ee (code, CCmode, cc_reg, const0_rtx);
836 break;
838 default:
839 gcc_unreachable ();
842 else
844 /* Reg/reg equal comparison. */
845 if (compare_code == EQ
846 && register_operand (y, SImode))
847 return gen_rtx_fmt_ee (code, CCmode, x, y);
849 /* Reg/zero signed comparison. */
850 if ((compare_code == EQ || compare_code == LT)
851 && y == const0_rtx)
852 return gen_rtx_fmt_ee (code, CCmode, x, y);
854 /* Reg/smallconst equal comparison. */
855 if (compare_code == EQ
856 && satisfies_constraint_P (y))
858 rtx tmp = gen_reg_rtx (SImode);
860 emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
861 return gen_rtx_fmt_ee (code, CCmode, tmp, const0_rtx);
864 /* Reg/const equal comparison. */
865 if (compare_code == EQ
866 && CONSTANT_P (y))
868 rtx tmp = force_reg (GET_MODE (x), y);
870 return gen_rtx_fmt_ee (code, CCmode, x, tmp);
874 if (CONSTANT_P (y))
876 if (must_swap)
877 y = force_reg (GET_MODE (x), y);
878 else
880 int ok_const = reg_or_int16_operand (y, GET_MODE (y));
882 if (! ok_const)
883 y = force_reg (GET_MODE (x), y);
887 switch (compare_code)
889 case EQ :
890 emit_insn (gen_cmp_eqsi_insn (must_swap ? y : x, must_swap ? x : y));
891 break;
892 case LT :
893 emit_insn (gen_cmp_ltsi_insn (must_swap ? y : x, must_swap ? x : y));
894 break;
895 case LTU :
896 emit_insn (gen_cmp_ltusi_insn (must_swap ? y : x, must_swap ? x : y));
897 break;
899 default:
900 gcc_unreachable ();
903 return gen_rtx_fmt_ee (branch_code, VOIDmode, cc_reg, CONST0_RTX (CCmode));
906 bool
907 gen_cond_store (enum rtx_code code, rtx op0, rtx op1, rtx op2)
909 machine_mode mode = GET_MODE (op0);
911 gcc_assert (mode == SImode);
912 switch (code)
914 case EQ:
915 if (!register_operand (op1, mode))
916 op1 = force_reg (mode, op1);
918 if (TARGET_M32RX || TARGET_M32R2)
920 if (!reg_or_zero_operand (op2, mode))
921 op2 = force_reg (mode, op2);
923 emit_insn (gen_seq_insn_m32rx (op0, op1, op2));
924 return true;
926 if (CONST_INT_P (op2) && INTVAL (op2) == 0)
928 emit_insn (gen_seq_zero_insn (op0, op1));
929 return true;
932 if (!reg_or_eq_int16_operand (op2, mode))
933 op2 = force_reg (mode, op2);
935 emit_insn (gen_seq_insn (op0, op1, op2));
936 return true;
938 case NE:
939 if (!CONST_INT_P (op2)
940 || (INTVAL (op2) != 0 && satisfies_constraint_K (op2)))
942 rtx reg;
944 if (reload_completed || reload_in_progress)
945 return false;
947 reg = gen_reg_rtx (SImode);
948 emit_insn (gen_xorsi3 (reg, op1, op2));
949 op1 = reg;
951 if (!register_operand (op1, mode))
952 op1 = force_reg (mode, op1);
954 emit_insn (gen_sne_zero_insn (op0, op1));
955 return true;
957 return false;
959 case LT:
960 case GT:
961 if (code == GT)
963 rtx tmp = op2;
964 op2 = op1;
965 op1 = tmp;
966 code = LT;
969 if (!register_operand (op1, mode))
970 op1 = force_reg (mode, op1);
972 if (!reg_or_int16_operand (op2, mode))
973 op2 = force_reg (mode, op2);
975 emit_insn (gen_slt_insn (op0, op1, op2));
976 return true;
978 case LTU:
979 case GTU:
980 if (code == GTU)
982 rtx tmp = op2;
983 op2 = op1;
984 op1 = tmp;
985 code = LTU;
988 if (!register_operand (op1, mode))
989 op1 = force_reg (mode, op1);
991 if (!reg_or_int16_operand (op2, mode))
992 op2 = force_reg (mode, op2);
994 emit_insn (gen_sltu_insn (op0, op1, op2));
995 return true;
997 case GE:
998 case GEU:
999 if (!register_operand (op1, mode))
1000 op1 = force_reg (mode, op1);
1002 if (!reg_or_int16_operand (op2, mode))
1003 op2 = force_reg (mode, op2);
1005 if (code == GE)
1006 emit_insn (gen_sge_insn (op0, op1, op2));
1007 else
1008 emit_insn (gen_sgeu_insn (op0, op1, op2));
1009 return true;
1011 case LE:
1012 case LEU:
1013 if (!register_operand (op1, mode))
1014 op1 = force_reg (mode, op1);
1016 if (CONST_INT_P (op2))
1018 HOST_WIDE_INT value = INTVAL (op2);
1019 if (value >= 2147483647)
1021 emit_move_insn (op0, const1_rtx);
1022 return true;
1025 op2 = GEN_INT (value + 1);
1026 if (value < -32768 || value >= 32767)
1027 op2 = force_reg (mode, op2);
1029 if (code == LEU)
1030 emit_insn (gen_sltu_insn (op0, op1, op2));
1031 else
1032 emit_insn (gen_slt_insn (op0, op1, op2));
1033 return true;
1036 if (!register_operand (op2, mode))
1037 op2 = force_reg (mode, op2);
1039 if (code == LEU)
1040 emit_insn (gen_sleu_insn (op0, op1, op2));
1041 else
1042 emit_insn (gen_sle_insn (op0, op1, op2));
1043 return true;
1045 default:
1046 gcc_unreachable ();
1051 /* Split a 2 word move (DI or DF) into component parts. */
1054 gen_split_move_double (rtx operands[])
1056 machine_mode mode = GET_MODE (operands[0]);
1057 rtx dest = operands[0];
1058 rtx src = operands[1];
1059 rtx val;
1061 /* We might have (SUBREG (MEM)) here, so just get rid of the
1062 subregs to make this code simpler. It is safe to call
1063 alter_subreg any time after reload. */
1064 if (GET_CODE (dest) == SUBREG)
1065 alter_subreg (&dest, true);
1066 if (GET_CODE (src) == SUBREG)
1067 alter_subreg (&src, true);
1069 start_sequence ();
1070 if (REG_P (dest))
1072 int dregno = REGNO (dest);
1074 /* Reg = reg. */
1075 if (REG_P (src))
1077 int sregno = REGNO (src);
1079 int reverse = (dregno == sregno + 1);
1081 /* We normally copy the low-numbered register first. However, if
1082 the first register operand 0 is the same as the second register of
1083 operand 1, we must copy in the opposite order. */
1084 emit_insn (gen_rtx_SET (operand_subword (dest, reverse, TRUE, mode),
1085 operand_subword (src, reverse, TRUE, mode)));
1087 emit_insn (gen_rtx_SET (operand_subword (dest, !reverse, TRUE, mode),
1088 operand_subword (src, !reverse, TRUE, mode)));
1091 /* Reg = constant. */
1092 else if (CONST_INT_P (src) || GET_CODE (src) == CONST_DOUBLE)
1094 rtx words[2];
1095 split_double (src, &words[0], &words[1]);
1096 emit_insn (gen_rtx_SET (operand_subword (dest, 0, TRUE, mode),
1097 words[0]));
1099 emit_insn (gen_rtx_SET (operand_subword (dest, 1, TRUE, mode),
1100 words[1]));
1103 /* Reg = mem. */
1104 else if (MEM_P (src))
1106 /* If the high-address word is used in the address, we must load it
1107 last. Otherwise, load it first. */
1108 int reverse = refers_to_regno_p (dregno, XEXP (src, 0));
1110 /* We used to optimize loads from single registers as
1112 ld r1,r3+; ld r2,r3
1114 if r3 were not used subsequently. However, the REG_NOTES aren't
1115 propagated correctly by the reload phase, and it can cause bad
1116 code to be generated. We could still try:
1118 ld r1,r3+; ld r2,r3; addi r3,-4
1120 which saves 2 bytes and doesn't force longword alignment. */
1121 emit_insn (gen_rtx_SET (operand_subword (dest, reverse, TRUE, mode),
1122 adjust_address (src, SImode,
1123 reverse * UNITS_PER_WORD)));
1125 emit_insn (gen_rtx_SET (operand_subword (dest, !reverse, TRUE, mode),
1126 adjust_address (src, SImode,
1127 !reverse * UNITS_PER_WORD)));
1129 else
1130 gcc_unreachable ();
1133 /* Mem = reg. */
1134 /* We used to optimize loads from single registers as
1136 st r1,r3; st r2,+r3
1138 if r3 were not used subsequently. However, the REG_NOTES aren't
1139 propagated correctly by the reload phase, and it can cause bad
1140 code to be generated. We could still try:
1142 st r1,r3; st r2,+r3; addi r3,-4
1144 which saves 2 bytes and doesn't force longword alignment. */
1145 else if (MEM_P (dest) && REG_P (src))
1147 emit_insn (gen_rtx_SET (adjust_address (dest, SImode, 0),
1148 operand_subword (src, 0, TRUE, mode)));
1150 emit_insn (gen_rtx_SET (adjust_address (dest, SImode, UNITS_PER_WORD),
1151 operand_subword (src, 1, TRUE, mode)));
1154 else
1155 gcc_unreachable ();
1157 val = get_insns ();
1158 end_sequence ();
1159 return val;
1163 static int
1164 m32r_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode,
1165 tree type, bool named ATTRIBUTE_UNUSED)
1167 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1169 int words;
1170 unsigned int size =
1171 (((mode == BLKmode && type)
1172 ? (unsigned int) int_size_in_bytes (type)
1173 : GET_MODE_SIZE (mode)) + UNITS_PER_WORD - 1)
1174 / UNITS_PER_WORD;
1176 if (*cum >= M32R_MAX_PARM_REGS)
1177 words = 0;
1178 else if (*cum + size > M32R_MAX_PARM_REGS)
1179 words = (*cum + size) - M32R_MAX_PARM_REGS;
1180 else
1181 words = 0;
1183 return words * UNITS_PER_WORD;
1186 /* The ROUND_ADVANCE* macros are local to this file. */
1187 /* Round SIZE up to a word boundary. */
1188 #define ROUND_ADVANCE(SIZE) \
1189 (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1191 /* Round arg MODE/TYPE up to the next word boundary. */
1192 #define ROUND_ADVANCE_ARG(MODE, TYPE) \
1193 ((MODE) == BLKmode \
1194 ? ROUND_ADVANCE ((unsigned int) int_size_in_bytes (TYPE)) \
1195 : ROUND_ADVANCE ((unsigned int) GET_MODE_SIZE (MODE)))
1197 /* Round CUM up to the necessary point for argument MODE/TYPE. */
1198 #define ROUND_ADVANCE_CUM(CUM, MODE, TYPE) (CUM)
1200 /* Return boolean indicating arg of type TYPE and mode MODE will be passed in
1201 a reg. This includes arguments that have to be passed by reference as the
1202 pointer to them is passed in a reg if one is available (and that is what
1203 we're given).
1204 This macro is only used in this file. */
1205 #define PASS_IN_REG_P(CUM, MODE, TYPE) \
1206 (ROUND_ADVANCE_CUM ((CUM), (MODE), (TYPE)) < M32R_MAX_PARM_REGS)
1208 /* Determine where to put an argument to a function.
1209 Value is zero to push the argument on the stack,
1210 or a hard register in which to store the argument.
1212 MODE is the argument's machine mode.
1213 TYPE is the data type of the argument (as a tree).
1214 This is null for libcalls where that information may
1215 not be available.
1216 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1217 the preceding args and about the function being called.
1218 NAMED is nonzero if this argument is a named parameter
1219 (otherwise it is an extra parameter matching an ellipsis). */
1220 /* On the M32R the first M32R_MAX_PARM_REGS args are normally in registers
1221 and the rest are pushed. */
1223 static rtx
1224 m32r_function_arg (cumulative_args_t cum_v, machine_mode mode,
1225 const_tree type ATTRIBUTE_UNUSED,
1226 bool named ATTRIBUTE_UNUSED)
1228 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1230 return (PASS_IN_REG_P (*cum, mode, type)
1231 ? gen_rtx_REG (mode, ROUND_ADVANCE_CUM (*cum, mode, type))
1232 : NULL_RTX);
1235 /* Update the data in CUM to advance over an argument
1236 of mode MODE and data type TYPE.
1237 (TYPE is null for libcalls where that information may not be available.) */
1239 static void
1240 m32r_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
1241 const_tree type, bool named ATTRIBUTE_UNUSED)
1243 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
1245 *cum = (ROUND_ADVANCE_CUM (*cum, mode, type)
1246 + ROUND_ADVANCE_ARG (mode, type));
1249 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1251 static bool
1252 m32r_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1254 cumulative_args_t dummy = pack_cumulative_args (NULL);
1256 return m32r_pass_by_reference (dummy, TYPE_MODE (type), type, false);
1259 /* Worker function for TARGET_FUNCTION_VALUE. */
1261 static rtx
1262 m32r_function_value (const_tree valtype,
1263 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
1264 bool outgoing ATTRIBUTE_UNUSED)
1266 return gen_rtx_REG (TYPE_MODE (valtype), 0);
1269 /* Worker function for TARGET_LIBCALL_VALUE. */
1271 static rtx
1272 m32r_libcall_value (machine_mode mode,
1273 const_rtx fun ATTRIBUTE_UNUSED)
1275 return gen_rtx_REG (mode, 0);
1278 /* Worker function for TARGET_FUNCTION_VALUE_REGNO_P.
1280 ??? What about r1 in DI/DF values. */
1282 static bool
1283 m32r_function_value_regno_p (const unsigned int regno)
1285 return (regno == 0);
1288 /* Do any needed setup for a variadic function. For the M32R, we must
1289 create a register parameter block, and then copy any anonymous arguments
1290 in registers to memory.
1292 CUM has not been updated for the last named argument which has type TYPE
1293 and mode MODE, and we rely on this fact. */
1295 static void
1296 m32r_setup_incoming_varargs (cumulative_args_t cum, machine_mode mode,
1297 tree type, int *pretend_size, int no_rtl)
1299 int first_anon_arg;
1301 if (no_rtl)
1302 return;
1304 /* All BLKmode values are passed by reference. */
1305 gcc_assert (mode != BLKmode);
1307 first_anon_arg = (ROUND_ADVANCE_CUM (*get_cumulative_args (cum), mode, type)
1308 + ROUND_ADVANCE_ARG (mode, type));
1310 if (first_anon_arg < M32R_MAX_PARM_REGS)
1312 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1313 int first_reg_offset = first_anon_arg;
1314 /* Size in words to "pretend" allocate. */
1315 int size = M32R_MAX_PARM_REGS - first_reg_offset;
1316 rtx regblock;
1318 regblock = gen_frame_mem (BLKmode,
1319 plus_constant (Pmode, arg_pointer_rtx,
1320 FIRST_PARM_OFFSET (0)));
1321 set_mem_alias_set (regblock, get_varargs_alias_set ());
1322 move_block_from_reg (first_reg_offset, regblock, size);
1324 *pretend_size = (size * UNITS_PER_WORD);
1329 /* Return true if INSN is real instruction bearing insn. */
1331 static int
1332 m32r_is_insn (rtx insn)
1334 return (NONDEBUG_INSN_P (insn)
1335 && GET_CODE (PATTERN (insn)) != USE
1336 && GET_CODE (PATTERN (insn)) != CLOBBER);
1339 /* Increase the priority of long instructions so that the
1340 short instructions are scheduled ahead of the long ones. */
1342 static int
1343 m32r_adjust_priority (rtx_insn *insn, int priority)
1345 if (m32r_is_insn (insn)
1346 && get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1347 priority <<= 3;
1349 return priority;
1353 /* Indicate how many instructions can be issued at the same time.
1354 This is sort of a lie. The m32r can issue only 1 long insn at
1355 once, but it can issue 2 short insns. The default therefore is
1356 set at 2, but this can be overridden by the command line option
1357 -missue-rate=1. */
1359 static int
1360 m32r_issue_rate (void)
1362 return ((TARGET_LOW_ISSUE_RATE) ? 1 : 2);
1365 /* Cost functions. */
1366 /* Memory is 3 times as expensive as registers.
1367 ??? Is that the right way to look at it? */
1369 static int
1370 m32r_memory_move_cost (machine_mode mode,
1371 reg_class_t rclass ATTRIBUTE_UNUSED,
1372 bool in ATTRIBUTE_UNUSED)
1374 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
1375 return 6;
1376 else
1377 return 12;
1380 static bool
1381 m32r_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
1382 int opno ATTRIBUTE_UNUSED, int *total,
1383 bool speed ATTRIBUTE_UNUSED)
1385 switch (code)
1387 /* Small integers are as cheap as registers. 4 byte values can be
1388 fetched as immediate constants - let's give that the cost of an
1389 extra insn. */
1390 case CONST_INT:
1391 if (INT16_P (INTVAL (x)))
1393 *total = 0;
1394 return true;
1396 /* FALLTHRU */
1398 case CONST:
1399 case LABEL_REF:
1400 case SYMBOL_REF:
1401 *total = COSTS_N_INSNS (1);
1402 return true;
1404 case CONST_DOUBLE:
1406 rtx high, low;
1408 split_double (x, &high, &low);
1409 *total = COSTS_N_INSNS (!INT16_P (INTVAL (high))
1410 + !INT16_P (INTVAL (low)));
1411 return true;
1414 case MULT:
1415 *total = COSTS_N_INSNS (3);
1416 return true;
1418 case DIV:
1419 case UDIV:
1420 case MOD:
1421 case UMOD:
1422 *total = COSTS_N_INSNS (10);
1423 return true;
1425 default:
1426 return false;
1430 /* Type of function DECL.
1432 The result is cached. To reset the cache at the end of a function,
1433 call with DECL = NULL_TREE. */
1435 enum m32r_function_type
1436 m32r_compute_function_type (tree decl)
1438 /* Cached value. */
1439 static enum m32r_function_type fn_type = M32R_FUNCTION_UNKNOWN;
1440 /* Last function we were called for. */
1441 static tree last_fn = NULL_TREE;
1443 /* Resetting the cached value? */
1444 if (decl == NULL_TREE)
1446 fn_type = M32R_FUNCTION_UNKNOWN;
1447 last_fn = NULL_TREE;
1448 return fn_type;
1451 if (decl == last_fn && fn_type != M32R_FUNCTION_UNKNOWN)
1452 return fn_type;
1454 /* Compute function type. */
1455 fn_type = (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE
1456 ? M32R_FUNCTION_INTERRUPT
1457 : M32R_FUNCTION_NORMAL);
1459 last_fn = decl;
1460 return fn_type;
1462 \f/* Function prologue/epilogue handlers. */
1464 /* M32R stack frames look like:
1466 Before call After call
1467 +-----------------------+ +-----------------------+
1468 | | | |
1469 high | local variables, | | local variables, |
1470 mem | reg save area, etc. | | reg save area, etc. |
1471 | | | |
1472 +-----------------------+ +-----------------------+
1473 | | | |
1474 | arguments on stack. | | arguments on stack. |
1475 | | | |
1476 SP+0->+-----------------------+ +-----------------------+
1477 | reg parm save area, |
1478 | only created for |
1479 | variable argument |
1480 | functions |
1481 +-----------------------+
1482 | previous frame ptr |
1483 +-----------------------+
1485 | register save area |
1487 +-----------------------+
1488 | return address |
1489 +-----------------------+
1491 | local variables |
1493 +-----------------------+
1495 | alloca allocations |
1497 +-----------------------+
1499 low | arguments on stack |
1500 memory | |
1501 SP+0->+-----------------------+
1503 Notes:
1504 1) The "reg parm save area" does not exist for non variable argument fns.
1505 2) The "reg parm save area" can be eliminated completely if we saved regs
1506 containing anonymous args separately but that complicates things too
1507 much (so it's not done).
1508 3) The return address is saved after the register save area so as to have as
1509 many insns as possible between the restoration of `lr' and the `jmp lr'. */
1511 /* Structure to be filled in by m32r_compute_frame_size with register
1512 save masks, and offsets for the current function. */
1513 struct m32r_frame_info
1515 unsigned int total_size; /* # bytes that the entire frame takes up. */
1516 unsigned int extra_size; /* # bytes of extra stuff. */
1517 unsigned int pretend_size; /* # bytes we push and pretend caller did. */
1518 unsigned int args_size; /* # bytes that outgoing arguments take up. */
1519 unsigned int reg_size; /* # bytes needed to store regs. */
1520 unsigned int var_size; /* # bytes that variables take up. */
1521 unsigned int gmask; /* Mask of saved gp registers. */
1522 unsigned int save_fp; /* Nonzero if fp must be saved. */
1523 unsigned int save_lr; /* Nonzero if lr (return addr) must be saved. */
1524 int initialized; /* Nonzero if frame size already calculated. */
1527 /* Current frame information calculated by m32r_compute_frame_size. */
1528 static struct m32r_frame_info current_frame_info;
1530 /* Zero structure to initialize current_frame_info. */
1531 static struct m32r_frame_info zero_frame_info;
1533 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1534 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1536 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1537 The return address and frame pointer are treated separately.
1538 Don't consider them here. */
1539 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1540 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1541 && (df_regs_ever_live_p (regno) && (!call_really_used_regs[regno] || interrupt_p)))
1543 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM))
1544 #define MUST_SAVE_RETURN_ADDR (df_regs_ever_live_p (RETURN_ADDR_REGNUM) || crtl->profile)
1546 #define SHORT_INSN_SIZE 2 /* Size of small instructions. */
1547 #define LONG_INSN_SIZE 4 /* Size of long instructions. */
1549 /* Return the bytes needed to compute the frame pointer from the current
1550 stack pointer.
1552 SIZE is the size needed for local variables. */
1554 unsigned int
1555 m32r_compute_frame_size (int size) /* # of var. bytes allocated. */
1557 unsigned int regno;
1558 unsigned int total_size, var_size, args_size, pretend_size, extra_size;
1559 unsigned int reg_size;
1560 unsigned int gmask;
1561 enum m32r_function_type fn_type;
1562 int interrupt_p;
1563 int pic_reg_used = flag_pic && (crtl->uses_pic_offset_table
1564 | crtl->profile);
1566 var_size = M32R_STACK_ALIGN (size);
1567 args_size = M32R_STACK_ALIGN (crtl->outgoing_args_size);
1568 pretend_size = crtl->args.pretend_args_size;
1569 extra_size = FIRST_PARM_OFFSET (0);
1570 total_size = extra_size + pretend_size + args_size + var_size;
1571 reg_size = 0;
1572 gmask = 0;
1574 /* See if this is an interrupt handler. Call used registers must be saved
1575 for them too. */
1576 fn_type = m32r_compute_function_type (current_function_decl);
1577 interrupt_p = M32R_INTERRUPT_P (fn_type);
1579 /* Calculate space needed for registers. */
1580 for (regno = 0; regno < M32R_MAX_INT_REGS; regno++)
1582 if (MUST_SAVE_REGISTER (regno, interrupt_p)
1583 || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1585 reg_size += UNITS_PER_WORD;
1586 gmask |= 1 << regno;
1590 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
1591 current_frame_info.save_lr = MUST_SAVE_RETURN_ADDR || pic_reg_used;
1593 reg_size += ((current_frame_info.save_fp + current_frame_info.save_lr)
1594 * UNITS_PER_WORD);
1595 total_size += reg_size;
1597 /* ??? Not sure this is necessary, and I don't think the epilogue
1598 handler will do the right thing if this changes total_size. */
1599 total_size = M32R_STACK_ALIGN (total_size);
1601 /* frame_size = total_size - (pretend_size + reg_size); */
1603 /* Save computed information. */
1604 current_frame_info.total_size = total_size;
1605 current_frame_info.extra_size = extra_size;
1606 current_frame_info.pretend_size = pretend_size;
1607 current_frame_info.var_size = var_size;
1608 current_frame_info.args_size = args_size;
1609 current_frame_info.reg_size = reg_size;
1610 current_frame_info.gmask = gmask;
1611 current_frame_info.initialized = reload_completed;
1613 /* Ok, we're done. */
1614 return total_size;
1617 /* Worker function for TARGET_CAN_ELIMINATE. */
1619 bool
1620 m32r_can_eliminate (const int from, const int to)
1622 return (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM
1623 ? ! frame_pointer_needed
1624 : true);
1628 /* The table we use to reference PIC data. */
1629 static rtx global_offset_table;
1631 static void
1632 m32r_reload_lr (rtx sp, int size)
1634 rtx lr = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
1636 if (size == 0)
1637 emit_insn (gen_movsi (lr, gen_frame_mem (Pmode, sp)));
1638 else if (size < 32768)
1639 emit_insn (gen_movsi (lr, gen_frame_mem (Pmode,
1640 gen_rtx_PLUS (Pmode, sp,
1641 GEN_INT (size)))));
1642 else
1644 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1646 emit_insn (gen_movsi (tmp, GEN_INT (size)));
1647 emit_insn (gen_addsi3 (tmp, tmp, sp));
1648 emit_insn (gen_movsi (lr, gen_frame_mem (Pmode, tmp)));
1651 emit_use (lr);
1654 void
1655 m32r_load_pic_register (void)
1657 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
1658 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
1659 GEN_INT (TARGET_MODEL_SMALL)));
1661 /* Need to emit this whether or not we obey regdecls,
1662 since setjmp/longjmp can cause life info to screw up. */
1663 emit_use (pic_offset_table_rtx);
1666 /* Expand the m32r prologue as a series of insns. */
1668 void
1669 m32r_expand_prologue (void)
1671 int regno;
1672 int frame_size;
1673 unsigned int gmask;
1674 int pic_reg_used = flag_pic && (crtl->uses_pic_offset_table
1675 | crtl->profile);
1677 if (! current_frame_info.initialized)
1678 m32r_compute_frame_size (get_frame_size ());
1680 gmask = current_frame_info.gmask;
1682 /* These cases shouldn't happen. Catch them now. */
1683 gcc_assert (current_frame_info.total_size || !gmask);
1685 /* Allocate space for register arguments if this is a variadic function. */
1686 if (current_frame_info.pretend_size != 0)
1688 /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1689 the wrong result on a 64-bit host. */
1690 HOST_WIDE_INT pretend_size = current_frame_info.pretend_size;
1691 emit_insn (gen_addsi3 (stack_pointer_rtx,
1692 stack_pointer_rtx,
1693 GEN_INT (-pretend_size)));
1696 /* Save any registers we need to and set up fp. */
1697 if (current_frame_info.save_fp)
1698 emit_insn (gen_movsi_push (stack_pointer_rtx, frame_pointer_rtx));
1700 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1702 /* Save any needed call-saved regs (and call-used if this is an
1703 interrupt handler). */
1704 for (regno = 0; regno <= M32R_MAX_INT_REGS; ++regno)
1706 if ((gmask & (1 << regno)) != 0)
1707 emit_insn (gen_movsi_push (stack_pointer_rtx,
1708 gen_rtx_REG (Pmode, regno)));
1711 if (current_frame_info.save_lr)
1712 emit_insn (gen_movsi_push (stack_pointer_rtx,
1713 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1715 /* Allocate the stack frame. */
1716 frame_size = (current_frame_info.total_size
1717 - (current_frame_info.pretend_size
1718 + current_frame_info.reg_size));
1720 if (frame_size == 0)
1721 ; /* Nothing to do. */
1722 else if (frame_size <= 32768)
1723 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1724 GEN_INT (-frame_size)));
1725 else
1727 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1729 emit_insn (gen_movsi (tmp, GEN_INT (frame_size)));
1730 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
1733 if (frame_pointer_needed)
1734 emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
1736 if (crtl->profile)
1737 /* Push lr for mcount (form_pc, x). */
1738 emit_insn (gen_movsi_push (stack_pointer_rtx,
1739 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1741 if (pic_reg_used)
1743 m32r_load_pic_register ();
1744 m32r_reload_lr (stack_pointer_rtx,
1745 (crtl->profile ? 0 : frame_size));
1748 if (crtl->profile && !pic_reg_used)
1749 emit_insn (gen_blockage ());
1753 /* Set up the stack and frame pointer (if desired) for the function.
1754 Note, if this is changed, you need to mirror the changes in
1755 m32r_compute_frame_size which calculates the prolog size. */
1757 static void
1758 m32r_output_function_prologue (FILE * file, HOST_WIDE_INT size)
1760 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1762 /* If this is an interrupt handler, mark it as such. */
1763 if (M32R_INTERRUPT_P (fn_type))
1764 fprintf (file, "\t%s interrupt handler\n", ASM_COMMENT_START);
1766 if (! current_frame_info.initialized)
1767 m32r_compute_frame_size (size);
1769 /* This is only for the human reader. */
1770 fprintf (file,
1771 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
1772 ASM_COMMENT_START,
1773 current_frame_info.var_size,
1774 current_frame_info.reg_size / 4,
1775 current_frame_info.args_size,
1776 current_frame_info.extra_size);
1779 /* Output RTL to pop register REGNO from the stack. */
1781 static void
1782 pop (int regno)
1784 rtx x;
1786 x = emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode, regno),
1787 stack_pointer_rtx));
1788 add_reg_note (x, REG_INC, stack_pointer_rtx);
1791 /* Expand the m32r epilogue as a series of insns. */
1793 void
1794 m32r_expand_epilogue (void)
1796 int regno;
1797 int noepilogue = FALSE;
1798 int total_size;
1800 gcc_assert (current_frame_info.initialized);
1801 total_size = current_frame_info.total_size;
1803 if (total_size == 0)
1805 rtx insn = get_last_insn ();
1807 /* If the last insn was a BARRIER, we don't have to write any code
1808 because a jump (aka return) was put there. */
1809 if (insn && NOTE_P (insn))
1810 insn = prev_nonnote_insn (insn);
1811 if (insn && BARRIER_P (insn))
1812 noepilogue = TRUE;
1815 if (!noepilogue)
1817 unsigned int var_size = current_frame_info.var_size;
1818 unsigned int args_size = current_frame_info.args_size;
1819 unsigned int gmask = current_frame_info.gmask;
1820 int can_trust_sp_p = !cfun->calls_alloca;
1822 if (flag_exceptions)
1823 emit_insn (gen_blockage ());
1825 /* The first thing to do is point the sp at the bottom of the register
1826 save area. */
1827 if (can_trust_sp_p)
1829 unsigned int reg_offset = var_size + args_size;
1831 if (reg_offset == 0)
1832 ; /* Nothing to do. */
1833 else if (reg_offset < 32768)
1834 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_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_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1842 tmp));
1845 else if (frame_pointer_needed)
1847 unsigned int reg_offset = var_size + args_size;
1849 if (reg_offset == 0)
1850 emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1851 else if (reg_offset < 32768)
1852 emit_insn (gen_addsi3 (stack_pointer_rtx, frame_pointer_rtx,
1853 GEN_INT (reg_offset)));
1854 else
1856 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1858 emit_insn (gen_movsi (tmp, GEN_INT (reg_offset)));
1859 emit_insn (gen_movsi (stack_pointer_rtx, frame_pointer_rtx));
1860 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1861 tmp));
1864 else
1865 gcc_unreachable ();
1867 if (current_frame_info.save_lr)
1868 pop (RETURN_ADDR_REGNUM);
1870 /* Restore any saved registers, in reverse order of course. */
1871 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1872 for (regno = M32R_MAX_INT_REGS - 1; regno >= 0; --regno)
1874 if ((gmask & (1L << regno)) != 0)
1875 pop (regno);
1878 if (current_frame_info.save_fp)
1879 pop (FRAME_POINTER_REGNUM);
1881 /* Remove varargs area if present. */
1882 if (current_frame_info.pretend_size != 0)
1883 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1884 GEN_INT (current_frame_info.pretend_size)));
1886 emit_insn (gen_blockage ());
1890 /* Do any necessary cleanup after a function to restore stack, frame,
1891 and regs. */
1893 static void
1894 m32r_output_function_epilogue (FILE * file ATTRIBUTE_UNUSED,
1895 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1897 /* Reset state info for each function. */
1898 current_frame_info = zero_frame_info;
1899 m32r_compute_function_type (NULL_TREE);
1902 /* Return nonzero if this function is known to have a null or 1 instruction
1903 epilogue. */
1906 direct_return (void)
1908 if (!reload_completed)
1909 return FALSE;
1911 if (M32R_INTERRUPT_P (m32r_compute_function_type (current_function_decl)))
1912 return FALSE;
1914 if (! current_frame_info.initialized)
1915 m32r_compute_frame_size (get_frame_size ());
1917 return current_frame_info.total_size == 0;
1921 /* PIC. */
1924 m32r_legitimate_pic_operand_p (rtx x)
1926 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1927 return 0;
1929 if (GET_CODE (x) == CONST
1930 && GET_CODE (XEXP (x, 0)) == PLUS
1931 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1932 || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
1933 && (CONST_INT_P (XEXP (XEXP (x, 0), 1))))
1934 return 0;
1936 return 1;
1940 m32r_legitimize_pic_address (rtx orig, rtx reg)
1942 #ifdef DEBUG_PIC
1943 printf("m32r_legitimize_pic_address()\n");
1944 #endif
1946 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
1948 rtx pic_ref, address;
1949 int subregs = 0;
1951 if (reg == 0)
1953 gcc_assert (!reload_in_progress && !reload_completed);
1954 reg = gen_reg_rtx (Pmode);
1956 subregs = 1;
1959 if (subregs)
1960 address = gen_reg_rtx (Pmode);
1961 else
1962 address = reg;
1964 crtl->uses_pic_offset_table = 1;
1966 if (GET_CODE (orig) == LABEL_REF
1967 || (GET_CODE (orig) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (orig)))
1969 emit_insn (gen_gotoff_load_addr (reg, orig));
1970 emit_insn (gen_addsi3 (reg, reg, pic_offset_table_rtx));
1971 return reg;
1974 emit_insn (gen_pic_load_addr (address, orig));
1976 emit_insn (gen_addsi3 (address, address, pic_offset_table_rtx));
1977 pic_ref = gen_const_mem (Pmode, address);
1978 emit_move_insn (reg, pic_ref);
1979 return reg;
1981 else if (GET_CODE (orig) == CONST)
1983 rtx base, offset;
1985 if (GET_CODE (XEXP (orig, 0)) == PLUS
1986 && XEXP (XEXP (orig, 0), 1) == pic_offset_table_rtx)
1987 return orig;
1989 if (reg == 0)
1991 gcc_assert (!reload_in_progress && !reload_completed);
1992 reg = gen_reg_rtx (Pmode);
1995 if (GET_CODE (XEXP (orig, 0)) == PLUS)
1997 base = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
1998 if (base == reg)
1999 offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), NULL_RTX);
2000 else
2001 offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), reg);
2003 else
2004 return orig;
2006 if (CONST_INT_P (offset))
2008 if (INT16_P (INTVAL (offset)))
2009 return plus_constant (Pmode, base, INTVAL (offset));
2010 else
2012 gcc_assert (! reload_in_progress && ! reload_completed);
2013 offset = force_reg (Pmode, offset);
2017 return gen_rtx_PLUS (Pmode, base, offset);
2020 return orig;
2023 static rtx
2024 m32r_legitimize_address (rtx x, rtx orig_x ATTRIBUTE_UNUSED,
2025 machine_mode mode ATTRIBUTE_UNUSED)
2027 if (flag_pic)
2028 return m32r_legitimize_pic_address (x, NULL_RTX);
2029 else
2030 return x;
2033 /* Worker function for TARGET_MODE_DEPENDENT_ADDRESS_P. */
2035 static bool
2036 m32r_mode_dependent_address_p (const_rtx addr, addr_space_t as ATTRIBUTE_UNUSED)
2038 if (GET_CODE (addr) == LO_SUM)
2039 return true;
2041 return false;
2044 /* Nested function support. */
2046 /* Emit RTL insns to initialize the variable parts of a trampoline.
2047 FNADDR is an RTX for the address of the function's pure code.
2048 CXT is an RTX for the static chain value for the function. */
2050 void
2051 m32r_initialize_trampoline (rtx tramp ATTRIBUTE_UNUSED,
2052 rtx fnaddr ATTRIBUTE_UNUSED,
2053 rtx cxt ATTRIBUTE_UNUSED)
2057 static void
2058 m32r_file_start (void)
2060 default_file_start ();
2062 if (flag_verbose_asm)
2063 fprintf (asm_out_file,
2064 "%s M32R/D special options: -G %d\n",
2065 ASM_COMMENT_START, g_switch_value);
2067 if (TARGET_LITTLE_ENDIAN)
2068 fprintf (asm_out_file, "\t.little\n");
2071 /* Print operand X (an rtx) in assembler syntax to file FILE.
2072 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2073 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2075 static void
2076 m32r_print_operand (FILE * file, rtx x, int code)
2078 rtx addr;
2080 switch (code)
2082 /* The 's' and 'p' codes are used by output_block_move() to
2083 indicate post-increment 's'tores and 'p're-increment loads. */
2084 case 's':
2085 if (REG_P (x))
2086 fprintf (file, "@+%s", reg_names [REGNO (x)]);
2087 else
2088 output_operand_lossage ("invalid operand to %%s code");
2089 return;
2091 case 'p':
2092 if (REG_P (x))
2093 fprintf (file, "@%s+", reg_names [REGNO (x)]);
2094 else
2095 output_operand_lossage ("invalid operand to %%p code");
2096 return;
2098 case 'R' :
2099 /* Write second word of DImode or DFmode reference,
2100 register or memory. */
2101 if (REG_P (x))
2102 fputs (reg_names[REGNO (x)+1], file);
2103 else if (MEM_P (x))
2105 fprintf (file, "@(");
2106 /* Handle possible auto-increment. Since it is pre-increment and
2107 we have already done it, we can just use an offset of four. */
2108 /* ??? This is taken from rs6000.c I think. I don't think it is
2109 currently necessary, but keep it around. */
2110 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2111 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2112 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 4));
2113 else
2114 output_address (plus_constant (Pmode, XEXP (x, 0), 4));
2115 fputc (')', file);
2117 else
2118 output_operand_lossage ("invalid operand to %%R code");
2119 return;
2121 case 'H' : /* High word. */
2122 case 'L' : /* Low word. */
2123 if (REG_P (x))
2125 /* L = least significant word, H = most significant word. */
2126 if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L'))
2127 fputs (reg_names[REGNO (x)], file);
2128 else
2129 fputs (reg_names[REGNO (x)+1], file);
2131 else if (CONST_INT_P (x)
2132 || GET_CODE (x) == CONST_DOUBLE)
2134 rtx first, second;
2136 split_double (x, &first, &second);
2137 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2138 code == 'L' ? INTVAL (first) : INTVAL (second));
2140 else
2141 output_operand_lossage ("invalid operand to %%H/%%L code");
2142 return;
2144 case 'A' :
2146 char str[30];
2148 if (GET_CODE (x) != CONST_DOUBLE
2149 || GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
2150 fatal_insn ("bad insn for 'A'", x);
2152 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1);
2153 fprintf (file, "%s", str);
2154 return;
2157 case 'B' : /* Bottom half. */
2158 case 'T' : /* Top half. */
2159 /* Output the argument to a `seth' insn (sets the Top half-word).
2160 For constants output arguments to a seth/or3 pair to set Top and
2161 Bottom halves. For symbols output arguments to a seth/add3 pair to
2162 set Top and Bottom halves. The difference exists because for
2163 constants seth/or3 is more readable but for symbols we need to use
2164 the same scheme as `ld' and `st' insns (16-bit addend is signed). */
2165 switch (GET_CODE (x))
2167 case CONST_INT :
2168 case CONST_DOUBLE :
2170 rtx first, second;
2172 split_double (x, &first, &second);
2173 x = WORDS_BIG_ENDIAN ? second : first;
2174 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2175 (code == 'B'
2176 ? INTVAL (x) & 0xffff
2177 : (INTVAL (x) >> 16) & 0xffff));
2179 return;
2180 case CONST :
2181 case SYMBOL_REF :
2182 if (code == 'B'
2183 && small_data_operand (x, VOIDmode))
2185 fputs ("sda(", file);
2186 output_addr_const (file, x);
2187 fputc (')', file);
2188 return;
2190 /* fall through */
2191 case LABEL_REF :
2192 fputs (code == 'T' ? "shigh(" : "low(", file);
2193 output_addr_const (file, x);
2194 fputc (')', file);
2195 return;
2196 default :
2197 output_operand_lossage ("invalid operand to %%T/%%B code");
2198 return;
2200 break;
2202 case 'U' :
2203 /* ??? wip */
2204 /* Output a load/store with update indicator if appropriate. */
2205 if (MEM_P (x))
2207 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2208 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2209 fputs (".a", file);
2211 else
2212 output_operand_lossage ("invalid operand to %%U code");
2213 return;
2215 case 'N' :
2216 /* Print a constant value negated. */
2217 if (CONST_INT_P (x))
2218 output_addr_const (file, GEN_INT (- INTVAL (x)));
2219 else
2220 output_operand_lossage ("invalid operand to %%N code");
2221 return;
2223 case 'X' :
2224 /* Print a const_int in hex. Used in comments. */
2225 if (CONST_INT_P (x))
2226 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
2227 return;
2229 case '#' :
2230 fputs (IMMEDIATE_PREFIX, file);
2231 return;
2233 case 0 :
2234 /* Do nothing special. */
2235 break;
2237 default :
2238 /* Unknown flag. */
2239 output_operand_lossage ("invalid operand output code");
2242 switch (GET_CODE (x))
2244 case REG :
2245 fputs (reg_names[REGNO (x)], file);
2246 break;
2248 case MEM :
2249 addr = XEXP (x, 0);
2250 if (GET_CODE (addr) == PRE_INC)
2252 if (!REG_P (XEXP (addr, 0)))
2253 fatal_insn ("pre-increment address is not a register", x);
2255 fprintf (file, "@+%s", reg_names[REGNO (XEXP (addr, 0))]);
2257 else if (GET_CODE (addr) == PRE_DEC)
2259 if (!REG_P (XEXP (addr, 0)))
2260 fatal_insn ("pre-decrement address is not a register", x);
2262 fprintf (file, "@-%s", reg_names[REGNO (XEXP (addr, 0))]);
2264 else if (GET_CODE (addr) == POST_INC)
2266 if (!REG_P (XEXP (addr, 0)))
2267 fatal_insn ("post-increment address is not a register", x);
2269 fprintf (file, "@%s+", reg_names[REGNO (XEXP (addr, 0))]);
2271 else
2273 fputs ("@(", file);
2274 output_address (XEXP (x, 0));
2275 fputc (')', file);
2277 break;
2279 case CONST_DOUBLE :
2280 /* We handle SFmode constants here as output_addr_const doesn't. */
2281 if (GET_MODE (x) == SFmode)
2283 REAL_VALUE_TYPE d;
2284 long l;
2286 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2287 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2288 fprintf (file, "0x%08lx", l);
2289 break;
2292 /* Fall through. Let output_addr_const deal with it. */
2294 default :
2295 output_addr_const (file, x);
2296 break;
2300 /* Print a memory address as an operand to reference that memory location. */
2302 static void
2303 m32r_print_operand_address (FILE * file, rtx addr)
2305 rtx base;
2306 rtx index = 0;
2307 int offset = 0;
2309 switch (GET_CODE (addr))
2311 case REG :
2312 fputs (reg_names[REGNO (addr)], file);
2313 break;
2315 case PLUS :
2316 if (CONST_INT_P (XEXP (addr, 0)))
2317 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
2318 else if (CONST_INT_P (XEXP (addr, 1)))
2319 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
2320 else
2321 base = XEXP (addr, 0), index = XEXP (addr, 1);
2322 if (REG_P (base))
2324 /* Print the offset first (if present) to conform to the manual. */
2325 if (index == 0)
2327 if (offset != 0)
2328 fprintf (file, "%d,", offset);
2329 fputs (reg_names[REGNO (base)], file);
2331 /* The chip doesn't support this, but left in for generality. */
2332 else if (REG_P (index))
2333 fprintf (file, "%s,%s",
2334 reg_names[REGNO (base)], reg_names[REGNO (index)]);
2335 /* Not sure this can happen, but leave in for now. */
2336 else if (GET_CODE (index) == SYMBOL_REF)
2338 output_addr_const (file, index);
2339 fputc (',', file);
2340 fputs (reg_names[REGNO (base)], file);
2342 else
2343 fatal_insn ("bad address", addr);
2345 else if (GET_CODE (base) == LO_SUM)
2347 gcc_assert (!index && REG_P (XEXP (base, 0)));
2348 if (small_data_operand (XEXP (base, 1), VOIDmode))
2349 fputs ("sda(", file);
2350 else
2351 fputs ("low(", file);
2352 output_addr_const (file, plus_constant (Pmode, XEXP (base, 1),
2353 offset));
2354 fputs ("),", file);
2355 fputs (reg_names[REGNO (XEXP (base, 0))], file);
2357 else
2358 fatal_insn ("bad address", addr);
2359 break;
2361 case LO_SUM :
2362 if (!REG_P (XEXP (addr, 0)))
2363 fatal_insn ("lo_sum not of register", addr);
2364 if (small_data_operand (XEXP (addr, 1), VOIDmode))
2365 fputs ("sda(", file);
2366 else
2367 fputs ("low(", file);
2368 output_addr_const (file, XEXP (addr, 1));
2369 fputs ("),", file);
2370 fputs (reg_names[REGNO (XEXP (addr, 0))], file);
2371 break;
2373 case PRE_INC : /* Assume SImode. */
2374 fprintf (file, "+%s", reg_names[REGNO (XEXP (addr, 0))]);
2375 break;
2377 case PRE_DEC : /* Assume SImode. */
2378 fprintf (file, "-%s", reg_names[REGNO (XEXP (addr, 0))]);
2379 break;
2381 case POST_INC : /* Assume SImode. */
2382 fprintf (file, "%s+", reg_names[REGNO (XEXP (addr, 0))]);
2383 break;
2385 default :
2386 output_addr_const (file, addr);
2387 break;
2391 static bool
2392 m32r_print_operand_punct_valid_p (unsigned char code)
2394 return m32r_punct_chars[code];
2397 /* Return true if the operands are the constants 0 and 1. */
2400 zero_and_one (rtx operand1, rtx operand2)
2402 return
2403 CONST_INT_P (operand1)
2404 && CONST_INT_P (operand2)
2405 && ( ((INTVAL (operand1) == 0) && (INTVAL (operand2) == 1))
2406 ||((INTVAL (operand1) == 1) && (INTVAL (operand2) == 0)));
2409 /* Generate the correct assembler code to handle the conditional loading of a
2410 value into a register. It is known that the operands satisfy the
2411 conditional_move_operand() function above. The destination is operand[0].
2412 The condition is operand [1]. The 'true' value is operand [2] and the
2413 'false' value is operand [3]. */
2415 char *
2416 emit_cond_move (rtx * operands, rtx insn ATTRIBUTE_UNUSED)
2418 static char buffer [100];
2419 const char * dest = reg_names [REGNO (operands [0])];
2421 buffer [0] = 0;
2423 /* Destination must be a register. */
2424 gcc_assert (REG_P (operands [0]));
2425 gcc_assert (conditional_move_operand (operands [2], SImode));
2426 gcc_assert (conditional_move_operand (operands [3], SImode));
2428 /* Check to see if the test is reversed. */
2429 if (GET_CODE (operands [1]) == NE)
2431 rtx tmp = operands [2];
2432 operands [2] = operands [3];
2433 operands [3] = tmp;
2436 sprintf (buffer, "mvfc %s, cbr", dest);
2438 /* If the true value was '0' then we need to invert the results of the move. */
2439 if (INTVAL (operands [2]) == 0)
2440 sprintf (buffer + strlen (buffer), "\n\txor3 %s, %s, #1",
2441 dest, dest);
2443 return buffer;
2446 /* Returns true if the registers contained in the two
2447 rtl expressions are different. */
2450 m32r_not_same_reg (rtx a, rtx b)
2452 int reg_a = -1;
2453 int reg_b = -2;
2455 while (GET_CODE (a) == SUBREG)
2456 a = SUBREG_REG (a);
2458 if (REG_P (a))
2459 reg_a = REGNO (a);
2461 while (GET_CODE (b) == SUBREG)
2462 b = SUBREG_REG (b);
2464 if (REG_P (b))
2465 reg_b = REGNO (b);
2467 return reg_a != reg_b;
2472 m32r_function_symbol (const char *name)
2474 int extra_flags = 0;
2475 enum m32r_model model;
2476 rtx sym = gen_rtx_SYMBOL_REF (Pmode, name);
2478 if (TARGET_MODEL_SMALL)
2479 model = M32R_MODEL_SMALL;
2480 else if (TARGET_MODEL_MEDIUM)
2481 model = M32R_MODEL_MEDIUM;
2482 else if (TARGET_MODEL_LARGE)
2483 model = M32R_MODEL_LARGE;
2484 else
2485 gcc_unreachable (); /* Shouldn't happen. */
2486 extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
2488 if (extra_flags)
2489 SYMBOL_REF_FLAGS (sym) |= extra_flags;
2491 return sym;
2494 /* Use a library function to move some bytes. */
2496 static void
2497 block_move_call (rtx dest_reg, rtx src_reg, rtx bytes_rtx)
2499 /* We want to pass the size as Pmode, which will normally be SImode
2500 but will be DImode if we are using 64-bit longs and pointers. */
2501 if (GET_MODE (bytes_rtx) != VOIDmode
2502 && GET_MODE (bytes_rtx) != Pmode)
2503 bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
2505 emit_library_call (m32r_function_symbol ("memcpy"), LCT_NORMAL,
2506 VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
2507 convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
2508 TYPE_UNSIGNED (sizetype)),
2509 TYPE_MODE (sizetype));
2512 /* Expand string/block move operations.
2514 operands[0] is the pointer to the destination.
2515 operands[1] is the pointer to the source.
2516 operands[2] is the number of bytes to move.
2517 operands[3] is the alignment.
2519 Returns 1 upon success, 0 otherwise. */
2522 m32r_expand_block_move (rtx operands[])
2524 rtx orig_dst = operands[0];
2525 rtx orig_src = operands[1];
2526 rtx bytes_rtx = operands[2];
2527 rtx align_rtx = operands[3];
2528 int constp = CONST_INT_P (bytes_rtx);
2529 HOST_WIDE_INT bytes = constp ? INTVAL (bytes_rtx) : 0;
2530 int align = INTVAL (align_rtx);
2531 int leftover;
2532 rtx src_reg;
2533 rtx dst_reg;
2535 if (constp && bytes <= 0)
2536 return 1;
2538 /* Move the address into scratch registers. */
2539 dst_reg = copy_addr_to_reg (XEXP (orig_dst, 0));
2540 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2542 if (align > UNITS_PER_WORD)
2543 align = UNITS_PER_WORD;
2545 /* If we prefer size over speed, always use a function call.
2546 If we do not know the size, use a function call.
2547 If the blocks are not word aligned, use a function call. */
2548 if (optimize_size || ! constp || align != UNITS_PER_WORD)
2550 block_move_call (dst_reg, src_reg, bytes_rtx);
2551 return 0;
2554 leftover = bytes % MAX_MOVE_BYTES;
2555 bytes -= leftover;
2557 /* If necessary, generate a loop to handle the bulk of the copy. */
2558 if (bytes)
2560 rtx_code_label *label = NULL;
2561 rtx final_src = NULL_RTX;
2562 rtx at_a_time = GEN_INT (MAX_MOVE_BYTES);
2563 rtx rounded_total = GEN_INT (bytes);
2564 rtx new_dst_reg = gen_reg_rtx (SImode);
2565 rtx new_src_reg = gen_reg_rtx (SImode);
2567 /* If we are going to have to perform this loop more than
2568 once, then generate a label and compute the address the
2569 source register will contain upon completion of the final
2570 iteration. */
2571 if (bytes > MAX_MOVE_BYTES)
2573 final_src = gen_reg_rtx (Pmode);
2575 if (INT16_P(bytes))
2576 emit_insn (gen_addsi3 (final_src, src_reg, rounded_total));
2577 else
2579 emit_insn (gen_movsi (final_src, rounded_total));
2580 emit_insn (gen_addsi3 (final_src, final_src, src_reg));
2583 label = gen_label_rtx ();
2584 emit_label (label);
2587 /* It is known that output_block_move() will update src_reg to point
2588 to the word after the end of the source block, and dst_reg to point
2589 to the last word of the destination block, provided that the block
2590 is MAX_MOVE_BYTES long. */
2591 emit_insn (gen_movmemsi_internal (dst_reg, src_reg, at_a_time,
2592 new_dst_reg, new_src_reg));
2593 emit_move_insn (dst_reg, new_dst_reg);
2594 emit_move_insn (src_reg, new_src_reg);
2595 emit_insn (gen_addsi3 (dst_reg, dst_reg, GEN_INT (4)));
2597 if (bytes > MAX_MOVE_BYTES)
2599 rtx test = gen_rtx_NE (VOIDmode, src_reg, final_src);
2600 emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label));
2604 if (leftover)
2605 emit_insn (gen_movmemsi_internal (dst_reg, src_reg, GEN_INT (leftover),
2606 gen_reg_rtx (SImode),
2607 gen_reg_rtx (SImode)));
2608 return 1;
2612 /* Emit load/stores for a small constant word aligned block_move.
2614 operands[0] is the memory address of the destination.
2615 operands[1] is the memory address of the source.
2616 operands[2] is the number of bytes to move.
2617 operands[3] is a temp register.
2618 operands[4] is a temp register. */
2620 void
2621 m32r_output_block_move (rtx insn ATTRIBUTE_UNUSED, rtx operands[])
2623 HOST_WIDE_INT bytes = INTVAL (operands[2]);
2624 int first_time;
2625 int got_extra = 0;
2627 gcc_assert (bytes >= 1 && bytes <= MAX_MOVE_BYTES);
2629 /* We do not have a post-increment store available, so the first set of
2630 stores are done without any increment, then the remaining ones can use
2631 the pre-increment addressing mode.
2633 Note: expand_block_move() also relies upon this behavior when building
2634 loops to copy large blocks. */
2635 first_time = 1;
2637 while (bytes > 0)
2639 if (bytes >= 8)
2641 if (first_time)
2643 output_asm_insn ("ld\t%5, %p1", operands);
2644 output_asm_insn ("ld\t%6, %p1", operands);
2645 output_asm_insn ("st\t%5, @%0", operands);
2646 output_asm_insn ("st\t%6, %s0", operands);
2648 else
2650 output_asm_insn ("ld\t%5, %p1", operands);
2651 output_asm_insn ("ld\t%6, %p1", operands);
2652 output_asm_insn ("st\t%5, %s0", operands);
2653 output_asm_insn ("st\t%6, %s0", operands);
2656 bytes -= 8;
2658 else if (bytes >= 4)
2660 if (bytes > 4)
2661 got_extra = 1;
2663 output_asm_insn ("ld\t%5, %p1", operands);
2665 if (got_extra)
2666 output_asm_insn ("ld\t%6, %p1", operands);
2668 if (first_time)
2669 output_asm_insn ("st\t%5, @%0", operands);
2670 else
2671 output_asm_insn ("st\t%5, %s0", operands);
2673 bytes -= 4;
2675 else
2677 /* Get the entire next word, even though we do not want all of it.
2678 The saves us from doing several smaller loads, and we assume that
2679 we cannot cause a page fault when at least part of the word is in
2680 valid memory [since we don't get called if things aren't properly
2681 aligned]. */
2682 int dst_offset = first_time ? 0 : 4;
2683 /* The amount of increment we have to make to the
2684 destination pointer. */
2685 int dst_inc_amount = dst_offset + bytes - 4;
2686 /* The same for the source pointer. */
2687 int src_inc_amount = bytes;
2688 int last_shift;
2689 rtx my_operands[3];
2691 /* If got_extra is true then we have already loaded
2692 the next word as part of loading and storing the previous word. */
2693 if (! got_extra)
2694 output_asm_insn ("ld\t%6, @%1", operands);
2696 if (bytes >= 2)
2698 bytes -= 2;
2700 output_asm_insn ("sra3\t%5, %6, #16", operands);
2701 my_operands[0] = operands[5];
2702 my_operands[1] = GEN_INT (dst_offset);
2703 my_operands[2] = operands[0];
2704 output_asm_insn ("sth\t%0, @(%1,%2)", my_operands);
2706 /* If there is a byte left to store then increment the
2707 destination address and shift the contents of the source
2708 register down by 8 bits. We could not do the address
2709 increment in the store half word instruction, because it does
2710 not have an auto increment mode. */
2711 if (bytes > 0) /* assert (bytes == 1) */
2713 dst_offset += 2;
2714 last_shift = 8;
2717 else
2718 last_shift = 24;
2720 if (bytes > 0)
2722 my_operands[0] = operands[6];
2723 my_operands[1] = GEN_INT (last_shift);
2724 output_asm_insn ("srai\t%0, #%1", my_operands);
2725 my_operands[0] = operands[6];
2726 my_operands[1] = GEN_INT (dst_offset);
2727 my_operands[2] = operands[0];
2728 output_asm_insn ("stb\t%0, @(%1,%2)", my_operands);
2731 /* Update the destination pointer if needed. We have to do
2732 this so that the patterns matches what we output in this
2733 function. */
2734 if (dst_inc_amount
2735 && !find_reg_note (insn, REG_UNUSED, operands[0]))
2737 my_operands[0] = operands[0];
2738 my_operands[1] = GEN_INT (dst_inc_amount);
2739 output_asm_insn ("addi\t%0, #%1", my_operands);
2742 /* Update the source pointer if needed. We have to do this
2743 so that the patterns matches what we output in this
2744 function. */
2745 if (src_inc_amount
2746 && !find_reg_note (insn, REG_UNUSED, operands[1]))
2748 my_operands[0] = operands[1];
2749 my_operands[1] = GEN_INT (src_inc_amount);
2750 output_asm_insn ("addi\t%0, #%1", my_operands);
2753 bytes = 0;
2756 first_time = 0;
2760 /* Return true if using NEW_REG in place of OLD_REG is ok. */
2763 m32r_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
2764 unsigned int new_reg)
2766 /* Interrupt routines can't clobber any register that isn't already used. */
2767 if (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl))
2768 && !df_regs_ever_live_p (new_reg))
2769 return 0;
2771 return 1;
2775 m32r_return_addr (int count)
2777 if (count != 0)
2778 return const0_rtx;
2780 return get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM);
2783 static void
2784 m32r_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
2786 emit_move_insn (adjust_address (m_tramp, SImode, 0),
2787 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2788 0x017e8e17 : 0x178e7e01, SImode));
2789 emit_move_insn (adjust_address (m_tramp, SImode, 4),
2790 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2791 0x0c00ae86 : 0x86ae000c, SImode));
2792 emit_move_insn (adjust_address (m_tramp, SImode, 8),
2793 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2794 0xe627871e : 0x1e8727e6, SImode));
2795 emit_move_insn (adjust_address (m_tramp, SImode, 12),
2796 gen_int_mode (TARGET_LITTLE_ENDIAN ?
2797 0xc616c626 : 0x26c61fc6, SImode));
2798 emit_move_insn (adjust_address (m_tramp, SImode, 16),
2799 chain_value);
2800 emit_move_insn (adjust_address (m_tramp, SImode, 20),
2801 XEXP (DECL_RTL (fndecl), 0));
2803 if (m32r_cache_flush_trap >= 0)
2804 emit_insn (gen_flush_icache
2805 (validize_mem (adjust_address (m_tramp, SImode, 0)),
2806 gen_int_mode (m32r_cache_flush_trap, SImode)));
2807 else if (m32r_cache_flush_func && m32r_cache_flush_func[0])
2808 emit_library_call (m32r_function_symbol (m32r_cache_flush_func),
2809 LCT_NORMAL, VOIDmode, 3, XEXP (m_tramp, 0), Pmode,
2810 gen_int_mode (TRAMPOLINE_SIZE, SImode), SImode,
2811 GEN_INT (3), SImode);
2814 /* True if X is a reg that can be used as a base reg. */
2816 static bool
2817 m32r_rtx_ok_for_base_p (const_rtx x, bool strict)
2819 if (! REG_P (x))
2820 return false;
2822 if (strict)
2824 if (GPR_P (REGNO (x)))
2825 return true;
2827 else
2829 if (GPR_P (REGNO (x))
2830 || REGNO (x) == ARG_POINTER_REGNUM
2831 || ! HARD_REGISTER_P (x))
2832 return true;
2835 return false;
2838 static inline bool
2839 m32r_rtx_ok_for_offset_p (const_rtx x)
2841 return (CONST_INT_P (x) && INT16_P (INTVAL (x)));
2844 static inline bool
2845 m32r_legitimate_offset_addres_p (machine_mode mode ATTRIBUTE_UNUSED,
2846 const_rtx x, bool strict)
2848 if (GET_CODE (x) == PLUS
2849 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict)
2850 && m32r_rtx_ok_for_offset_p (XEXP (x, 1)))
2851 return true;
2853 return false;
2856 /* For LO_SUM addresses, do not allow them if the MODE is > 1 word,
2857 since more than one instruction will be required. */
2859 static inline bool
2860 m32r_legitimate_lo_sum_addres_p (machine_mode mode, const_rtx x,
2861 bool strict)
2863 if (GET_CODE (x) == LO_SUM
2864 && (mode != BLKmode && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
2865 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict)
2866 && CONSTANT_P (XEXP (x, 1)))
2867 return true;
2869 return false;
2872 /* Is this a load and increment operation. */
2874 static inline bool
2875 m32r_load_postinc_p (machine_mode mode, const_rtx x, bool strict)
2877 if ((mode == SImode || mode == SFmode)
2878 && GET_CODE (x) == POST_INC
2879 && REG_P (XEXP (x, 0))
2880 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict))
2881 return true;
2883 return false;
2886 /* Is this an increment/decrement and store operation. */
2888 static inline bool
2889 m32r_store_preinc_predec_p (machine_mode mode, const_rtx x, bool strict)
2891 if ((mode == SImode || mode == SFmode)
2892 && (GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
2893 && REG_P (XEXP (x, 0)) \
2894 && m32r_rtx_ok_for_base_p (XEXP (x, 0), strict))
2895 return true;
2897 return false;
2900 /* Implement TARGET_LEGITIMATE_ADDRESS_P. */
2902 static bool
2903 m32r_legitimate_address_p (machine_mode mode, rtx x, bool strict)
2905 if (m32r_rtx_ok_for_base_p (x, strict)
2906 || m32r_legitimate_offset_addres_p (mode, x, strict)
2907 || m32r_legitimate_lo_sum_addres_p (mode, x, strict)
2908 || m32r_load_postinc_p (mode, x, strict)
2909 || m32r_store_preinc_predec_p (mode, x, strict))
2910 return true;
2912 return false;
2915 static void
2916 m32r_conditional_register_usage (void)
2918 if (flag_pic)
2920 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
2921 call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
2925 /* Implement TARGET_LEGITIMATE_CONSTANT_P
2927 We don't allow (plus symbol large-constant) as the relocations can't
2928 describe it. INTVAL > 32767 handles both 16-bit and 24-bit relocations.
2929 We allow all CONST_DOUBLE's as the md file patterns will force the
2930 constant to memory if they can't handle them. */
2932 static bool
2933 m32r_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
2935 return !(GET_CODE (x) == CONST
2936 && GET_CODE (XEXP (x, 0)) == PLUS
2937 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2938 || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
2939 && CONST_INT_P (XEXP (XEXP (x, 0), 1))
2940 && UINTVAL (XEXP (XEXP (x, 0), 1)) > 32767);