1 /* Subroutines used for code generation on the Renesas M32R cpu.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 2, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
34 #include "insn-attr.h"
43 #include "target-def.h"
45 /* Save the operands last given to a compare for use when we
46 generate a scc or bcc insn. */
47 rtx m32r_compare_op0
, m32r_compare_op1
;
49 /* Array of valid operand punctuation characters. */
50 char m32r_punct_chars
[256];
52 /* Selected code model. */
53 const char * m32r_model_string
= M32R_MODEL_DEFAULT
;
54 enum m32r_model m32r_model
;
56 /* Selected SDA support. */
57 const char * m32r_sdata_string
= M32R_SDATA_DEFAULT
;
58 enum m32r_sdata m32r_sdata
;
60 /* Machine-specific symbol_ref flags. */
61 #define SYMBOL_FLAG_MODEL_SHIFT SYMBOL_FLAG_MACH_DEP_SHIFT
62 #define SYMBOL_REF_MODEL(X) \
63 ((enum m32r_model) ((SYMBOL_REF_FLAGS (X) >> SYMBOL_FLAG_MODEL_SHIFT) & 3))
65 /* For string literals, etc. */
66 #define LIT_NAME_P(NAME) ((NAME)[0] == '*' && (NAME)[1] == '.')
68 /* Cache-flush support. Cache-flush is used at trampoline.
69 Default cache-flush is "trap 12".
70 default cache-flush function is "_flush_cache" (CACHE_FLUSH_FUNC)
71 default cache-flush trap-interrupt number is "12". (CACHE_FLUSH_TRAP)
72 You can change how to generate code of cache-flush with following options.
73 -flush-func=FLUSH-FUNC-NAME
75 -fluch-trap=TRAP-NUMBER
77 const char *m32r_cache_flush_func
= CACHE_FLUSH_FUNC
;
78 const char *m32r_cache_flush_trap_string
= CACHE_FLUSH_TRAP
;
79 int m32r_cache_flush_trap
= 12;
81 /* Forward declaration. */
82 static void init_reg_tables (void);
83 static void block_move_call (rtx
, rtx
, rtx
);
84 static int m32r_is_insn (rtx
);
85 const struct attribute_spec m32r_attribute_table
[];
86 static tree
m32r_handle_model_attribute (tree
*, tree
, tree
, int, bool *);
87 static void m32r_output_function_prologue (FILE *, HOST_WIDE_INT
);
88 static void m32r_output_function_epilogue (FILE *, HOST_WIDE_INT
);
90 static void m32r_file_start (void);
92 static int m32r_adjust_priority (rtx
, int);
93 static int m32r_issue_rate (void);
95 static void m32r_encode_section_info (tree
, rtx
, int);
96 static bool m32r_in_small_data_p (tree
);
97 static bool m32r_return_in_memory (tree
, tree
);
98 static void m32r_setup_incoming_varargs (CUMULATIVE_ARGS
*, enum machine_mode
,
100 static void init_idents (void);
101 static bool m32r_rtx_costs (rtx
, int, int, int *);
102 static bool m32r_pass_by_reference (CUMULATIVE_ARGS
*, enum machine_mode
,
105 /* Initialize the GCC target structure. */
106 #undef TARGET_ATTRIBUTE_TABLE
107 #define TARGET_ATTRIBUTE_TABLE m32r_attribute_table
109 #undef TARGET_ASM_ALIGNED_HI_OP
110 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
111 #undef TARGET_ASM_ALIGNED_SI_OP
112 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
114 #undef TARGET_ASM_FUNCTION_PROLOGUE
115 #define TARGET_ASM_FUNCTION_PROLOGUE m32r_output_function_prologue
116 #undef TARGET_ASM_FUNCTION_EPILOGUE
117 #define TARGET_ASM_FUNCTION_EPILOGUE m32r_output_function_epilogue
119 #undef TARGET_ASM_FILE_START
120 #define TARGET_ASM_FILE_START m32r_file_start
122 #undef TARGET_SCHED_ADJUST_PRIORITY
123 #define TARGET_SCHED_ADJUST_PRIORITY m32r_adjust_priority
124 #undef TARGET_SCHED_ISSUE_RATE
125 #define TARGET_SCHED_ISSUE_RATE m32r_issue_rate
126 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
127 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE hook_int_void_1
129 #undef TARGET_ENCODE_SECTION_INFO
130 #define TARGET_ENCODE_SECTION_INFO m32r_encode_section_info
131 #undef TARGET_IN_SMALL_DATA_P
132 #define TARGET_IN_SMALL_DATA_P m32r_in_small_data_p
134 #undef TARGET_RTX_COSTS
135 #define TARGET_RTX_COSTS m32r_rtx_costs
136 #undef TARGET_ADDRESS_COST
137 #define TARGET_ADDRESS_COST hook_int_rtx_0
139 #undef TARGET_PROMOTE_PROTOTYPES
140 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
141 #undef TARGET_RETURN_IN_MEMORY
142 #define TARGET_RETURN_IN_MEMORY m32r_return_in_memory
143 #undef TARGET_SETUP_INCOMING_VARARGS
144 #define TARGET_SETUP_INCOMING_VARARGS m32r_setup_incoming_varargs
145 #undef TARGET_MUST_PASS_IN_STACK
146 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
147 #undef TARGET_PASS_BY_REFERENCE
148 #define TARGET_PASS_BY_REFERENCE m32r_pass_by_reference
150 struct gcc_target targetm
= TARGET_INITIALIZER
;
152 /* Called by OVERRIDE_OPTIONS to initialize various things. */
159 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
160 memset (m32r_punct_chars
, 0, sizeof (m32r_punct_chars
));
161 m32r_punct_chars
['#'] = 1;
162 m32r_punct_chars
['@'] = 1; /* ??? no longer used */
164 /* Provide default value if not specified. */
166 g_switch_value
= SDATA_DEFAULT_SIZE
;
168 if (strcmp (m32r_model_string
, "small") == 0)
169 m32r_model
= M32R_MODEL_SMALL
;
170 else if (strcmp (m32r_model_string
, "medium") == 0)
171 m32r_model
= M32R_MODEL_MEDIUM
;
172 else if (strcmp (m32r_model_string
, "large") == 0)
173 m32r_model
= M32R_MODEL_LARGE
;
175 error ("bad value (%s) for -mmodel switch", m32r_model_string
);
177 if (strcmp (m32r_sdata_string
, "none") == 0)
178 m32r_sdata
= M32R_SDATA_NONE
;
179 else if (strcmp (m32r_sdata_string
, "sdata") == 0)
180 m32r_sdata
= M32R_SDATA_SDATA
;
181 else if (strcmp (m32r_sdata_string
, "use") == 0)
182 m32r_sdata
= M32R_SDATA_USE
;
184 error ("bad value (%s) for -msdata switch", m32r_sdata_string
);
186 if (m32r_cache_flush_trap_string
)
188 /* Change trap-number (12) for cache-flush to the others (0 - 15). */
189 m32r_cache_flush_trap
= atoi (m32r_cache_flush_trap_string
);
190 if (m32r_cache_flush_trap
< 0 || m32r_cache_flush_trap
> 15)
191 error ("bad value (%s) for -flush-trap=n (0=<n<=15)",
192 m32r_cache_flush_trap_string
);
196 /* Vectors to keep interesting information about registers where it can easily
197 be got. We use to use the actual mode value as the bit number, but there
198 is (or may be) more than 32 modes now. Instead we use two tables: one
199 indexed by hard register number, and one indexed by mode. */
201 /* The purpose of m32r_mode_class is to shrink the range of modes so that
202 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
203 mapped into one m32r_mode_class mode. */
208 S_MODE
, D_MODE
, T_MODE
, O_MODE
,
209 SF_MODE
, DF_MODE
, TF_MODE
, OF_MODE
, A_MODE
212 /* Modes for condition codes. */
213 #define C_MODES (1 << (int) C_MODE)
215 /* Modes for single-word and smaller quantities. */
216 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
218 /* Modes for double-word and smaller quantities. */
219 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
221 /* Modes for quad-word and smaller quantities. */
222 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
224 /* Modes for accumulators. */
225 #define A_MODES (1 << (int) A_MODE)
227 /* Value is 1 if register/mode pair is acceptable on arc. */
229 const unsigned int m32r_hard_regno_mode_ok
[FIRST_PSEUDO_REGISTER
] =
231 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
,
232 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, S_MODES
, S_MODES
, S_MODES
,
233 S_MODES
, C_MODES
, A_MODES
, A_MODES
236 unsigned int m32r_mode_class
[NUM_MACHINE_MODES
];
238 enum reg_class m32r_regno_reg_class
[FIRST_PSEUDO_REGISTER
];
241 init_reg_tables (void)
245 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
247 switch (GET_MODE_CLASS (i
))
250 case MODE_PARTIAL_INT
:
251 case MODE_COMPLEX_INT
:
252 if (GET_MODE_SIZE (i
) <= 4)
253 m32r_mode_class
[i
] = 1 << (int) S_MODE
;
254 else if (GET_MODE_SIZE (i
) == 8)
255 m32r_mode_class
[i
] = 1 << (int) D_MODE
;
256 else if (GET_MODE_SIZE (i
) == 16)
257 m32r_mode_class
[i
] = 1 << (int) T_MODE
;
258 else if (GET_MODE_SIZE (i
) == 32)
259 m32r_mode_class
[i
] = 1 << (int) O_MODE
;
261 m32r_mode_class
[i
] = 0;
264 case MODE_COMPLEX_FLOAT
:
265 if (GET_MODE_SIZE (i
) <= 4)
266 m32r_mode_class
[i
] = 1 << (int) SF_MODE
;
267 else if (GET_MODE_SIZE (i
) == 8)
268 m32r_mode_class
[i
] = 1 << (int) DF_MODE
;
269 else if (GET_MODE_SIZE (i
) == 16)
270 m32r_mode_class
[i
] = 1 << (int) TF_MODE
;
271 else if (GET_MODE_SIZE (i
) == 32)
272 m32r_mode_class
[i
] = 1 << (int) OF_MODE
;
274 m32r_mode_class
[i
] = 0;
277 m32r_mode_class
[i
] = 1 << (int) C_MODE
;
280 m32r_mode_class
[i
] = 0;
285 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
288 m32r_regno_reg_class
[i
] = GENERAL_REGS
;
289 else if (i
== ARG_POINTER_REGNUM
)
290 m32r_regno_reg_class
[i
] = GENERAL_REGS
;
292 m32r_regno_reg_class
[i
] = NO_REGS
;
296 /* M32R specific attribute support.
298 interrupt - for interrupt functions
300 model - select code model used to access object
302 small: addresses use 24 bits, use bl to make calls
303 medium: addresses use 32 bits, use bl to make calls
304 large: addresses use 32 bits, use seth/add3/jl to make calls
306 Grep for MODEL in m32r.h for more info. */
308 static tree small_ident1
;
309 static tree small_ident2
;
310 static tree medium_ident1
;
311 static tree medium_ident2
;
312 static tree large_ident1
;
313 static tree large_ident2
;
318 if (small_ident1
== 0)
320 small_ident1
= get_identifier ("small");
321 small_ident2
= get_identifier ("__small__");
322 medium_ident1
= get_identifier ("medium");
323 medium_ident2
= get_identifier ("__medium__");
324 large_ident1
= get_identifier ("large");
325 large_ident2
= get_identifier ("__large__");
329 const struct attribute_spec m32r_attribute_table
[] =
331 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
332 { "interrupt", 0, 0, true, false, false, NULL
},
333 { "model", 1, 1, true, false, false, m32r_handle_model_attribute
},
334 { NULL
, 0, 0, false, false, false, NULL
}
338 /* Handle an "model" attribute; arguments as in
339 struct attribute_spec.handler. */
341 m32r_handle_model_attribute (tree
*node ATTRIBUTE_UNUSED
, tree name
,
342 tree args
, int flags ATTRIBUTE_UNUSED
,
348 arg
= TREE_VALUE (args
);
350 if (arg
!= small_ident1
351 && arg
!= small_ident2
352 && arg
!= medium_ident1
353 && arg
!= medium_ident2
354 && arg
!= large_ident1
355 && arg
!= large_ident2
)
357 warning ("invalid argument of `%s' attribute",
358 IDENTIFIER_POINTER (name
));
359 *no_add_attrs
= true;
365 /* Encode section information of DECL, which is either a VAR_DECL,
366 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
368 For the M32R we want to record:
370 - whether the object lives in .sdata/.sbss.
371 - what code model should be used to access the object
375 m32r_encode_section_info (tree decl
, rtx rtl
, int first
)
379 enum m32r_model model
;
381 default_encode_section_info (decl
, rtl
, first
);
386 model_attr
= lookup_attribute ("model", DECL_ATTRIBUTES (decl
));
393 id
= TREE_VALUE (TREE_VALUE (model_attr
));
395 if (id
== small_ident1
|| id
== small_ident2
)
396 model
= M32R_MODEL_SMALL
;
397 else if (id
== medium_ident1
|| id
== medium_ident2
)
398 model
= M32R_MODEL_MEDIUM
;
399 else if (id
== large_ident1
|| id
== large_ident2
)
400 model
= M32R_MODEL_LARGE
;
402 abort (); /* shouldn't happen */
406 if (TARGET_MODEL_SMALL
)
407 model
= M32R_MODEL_SMALL
;
408 else if (TARGET_MODEL_MEDIUM
)
409 model
= M32R_MODEL_MEDIUM
;
410 else if (TARGET_MODEL_LARGE
)
411 model
= M32R_MODEL_LARGE
;
413 abort (); /* shouldn't happen */
415 extra_flags
|= model
<< SYMBOL_FLAG_MODEL_SHIFT
;
418 SYMBOL_REF_FLAGS (XEXP (rtl
, 0)) |= extra_flags
;
421 /* Only mark the object as being small data area addressable if
422 it hasn't been explicitly marked with a code model.
424 The user can explicitly put an object in the small data area with the
425 section attribute. If the object is in sdata/sbss and marked with a
426 code model do both [put the object in .sdata and mark it as being
427 addressed with a specific code model - don't mark it as being addressed
428 with an SDA reloc though]. This is ok and might be useful at times. If
429 the object doesn't fit the linker will give an error. */
432 m32r_in_small_data_p (tree decl
)
436 if (TREE_CODE (decl
) != VAR_DECL
)
439 if (lookup_attribute ("model", DECL_ATTRIBUTES (decl
)))
442 section
= DECL_SECTION_NAME (decl
);
445 char *name
= (char *) TREE_STRING_POINTER (section
);
446 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
451 if (! TREE_READONLY (decl
) && ! TARGET_SDATA_NONE
)
453 int size
= int_size_in_bytes (TREE_TYPE (decl
));
455 if (size
> 0 && (unsigned HOST_WIDE_INT
) size
<= g_switch_value
)
463 /* Do anything needed before RTL is emitted for each function. */
466 m32r_init_expanders (void)
468 /* ??? At one point there was code here. The function is left in
469 to make it easy to experiment. */
472 /* Acceptable arguments to the call insn. */
475 call_address_operand (rtx op
, enum machine_mode mode
)
477 return symbolic_operand (op
, mode
);
479 /* Constants and values in registers are not OK, because
480 the m32r BL instruction can only support PC relative branching. */
484 call_operand (rtx op
, enum machine_mode mode
)
486 if (GET_CODE (op
) != MEM
)
489 return call_address_operand (op
, mode
);
492 /* Returns 1 if OP is a symbol reference. */
495 symbolic_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
497 switch (GET_CODE (op
))
509 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
512 small_data_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
514 if (! TARGET_SDATA_USE
)
517 if (GET_CODE (op
) == SYMBOL_REF
)
518 return SYMBOL_REF_SMALL_P (op
);
520 if (GET_CODE (op
) == CONST
521 && GET_CODE (XEXP (op
, 0)) == PLUS
522 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
523 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
524 && INT16_P (INTVAL (XEXP (XEXP (op
, 0), 1))))
525 return SYMBOL_REF_SMALL_P (XEXP (XEXP (op
, 0), 0));
530 /* Return 1 if OP is a symbol that can use 24 bit addressing. */
533 addr24_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
540 if (GET_CODE (op
) == LABEL_REF
)
541 return TARGET_ADDR24
;
543 if (GET_CODE (op
) == SYMBOL_REF
)
545 else if (GET_CODE (op
) == CONST
546 && GET_CODE (XEXP (op
, 0)) == PLUS
547 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
548 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
549 && UINT24_P (INTVAL (XEXP (XEXP (op
, 0), 1))))
550 sym
= XEXP (XEXP (op
, 0), 0);
554 if (SYMBOL_REF_MODEL (sym
) == M32R_MODEL_SMALL
)
558 && (CONSTANT_POOL_ADDRESS_P (sym
)
559 || LIT_NAME_P (XSTR (sym
, 0))))
565 /* Return 1 if OP is a symbol that needs 32 bit addressing. */
568 addr32_operand (rtx op
, enum machine_mode mode
)
572 if (GET_CODE (op
) == LABEL_REF
)
573 return TARGET_ADDR32
;
575 if (GET_CODE (op
) == SYMBOL_REF
)
577 else if (GET_CODE (op
) == CONST
578 && GET_CODE (XEXP (op
, 0)) == PLUS
579 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
580 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
582 sym
= XEXP (XEXP (op
, 0), 0);
586 return (! addr24_operand (sym
, mode
)
587 && ! small_data_operand (sym
, mode
));
590 /* Return 1 if OP is a function that can be called with the `bl' insn. */
593 call26_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
598 if (GET_CODE (op
) == SYMBOL_REF
)
599 return SYMBOL_REF_MODEL (op
) != M32R_MODEL_LARGE
;
601 return TARGET_CALL26
;
604 /* Returns 1 if OP is an acceptable operand for seth/add3. */
607 seth_add3_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
612 if (GET_CODE (op
) == SYMBOL_REF
613 || GET_CODE (op
) == LABEL_REF
)
616 if (GET_CODE (op
) == CONST
617 && GET_CODE (XEXP (op
, 0)) == PLUS
618 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
619 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
620 && INT16_P (INTVAL (XEXP (XEXP (op
, 0), 1))))
626 /* Return true if OP is a signed 8 bit immediate value. */
629 int8_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
631 if (GET_CODE (op
) != CONST_INT
)
633 return INT8_P (INTVAL (op
));
636 /* Return true if OP is a signed 16 bit immediate value
637 useful in comparisons. */
640 cmp_int16_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
642 if (GET_CODE (op
) != CONST_INT
)
644 return CMP_INT16_P (INTVAL (op
));
647 /* Return true if OP is an unsigned 16 bit immediate value. */
650 uint16_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
652 if (GET_CODE (op
) != CONST_INT
)
654 return UINT16_P (INTVAL (op
));
657 /* Return true if OP is a register or signed 16 bit value. */
660 reg_or_int16_operand (rtx op
, enum machine_mode mode
)
662 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
663 return register_operand (op
, mode
);
664 if (GET_CODE (op
) != CONST_INT
)
666 return INT16_P (INTVAL (op
));
669 /* Return true if OP is a register or an unsigned 16 bit value. */
672 reg_or_uint16_operand (rtx op
, enum machine_mode mode
)
674 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
675 return register_operand (op
, mode
);
676 if (GET_CODE (op
) != CONST_INT
)
678 return UINT16_P (INTVAL (op
));
681 /* Return true if OP is a register or an integer value that can be
682 used is SEQ/SNE. We can use either XOR of the value or ADD of
683 the negative of the value for the constant. Don't allow 0,
684 because that is special cased. */
687 reg_or_eq_int16_operand (rtx op
, enum machine_mode mode
)
691 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
692 return register_operand (op
, mode
);
694 if (GET_CODE (op
) != CONST_INT
)
698 return (value
!= 0) && (UINT16_P (value
) || CMP_INT16_P (-value
));
701 /* Return true if OP is a register or signed 16 bit value for compares. */
704 reg_or_cmp_int16_operand (rtx op
, enum machine_mode mode
)
706 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
707 return register_operand (op
, mode
);
708 if (GET_CODE (op
) != CONST_INT
)
710 return CMP_INT16_P (INTVAL (op
));
713 /* Return true if OP is a register or the constant 0. */
716 reg_or_zero_operand (rtx op
, enum machine_mode mode
)
718 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
719 return register_operand (op
, mode
);
721 if (GET_CODE (op
) != CONST_INT
)
724 return INTVAL (op
) == 0;
727 /* Return true if OP is a const_int requiring two instructions to load. */
730 two_insn_const_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
732 if (GET_CODE (op
) != CONST_INT
)
734 if (INT16_P (INTVAL (op
))
735 || UINT24_P (INTVAL (op
))
736 || UPPER16_P (INTVAL (op
)))
741 /* Return true if OP is an acceptable argument for a single word
745 move_src_operand (rtx op
, enum machine_mode mode
)
747 switch (GET_CODE (op
))
752 return addr24_operand (op
, mode
);
754 /* ??? We allow more cse opportunities if we only allow constants
755 loadable with one insn, and split the rest into two. The instances
756 where this would help should be rare and the current way is
758 if (HOST_BITS_PER_WIDE_INT
> 32)
760 HOST_WIDE_INT rest
= INTVAL (op
) >> 31;
761 return (rest
== 0 || rest
== -1);
768 else if (mode
== SImode
)
770 /* Large unsigned constants are represented as const_double's. */
771 unsigned HOST_WIDE_INT low
, high
;
773 low
= CONST_DOUBLE_LOW (op
);
774 high
= CONST_DOUBLE_HIGH (op
);
775 return high
== 0 && low
<= (unsigned) 0xffffffff;
780 return register_operand (op
, mode
);
782 /* (subreg (mem ...) ...) can occur here if the inner part was once a
783 pseudo-reg and is now a stack slot. */
784 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
785 return address_operand (XEXP (SUBREG_REG (op
), 0), mode
);
787 return register_operand (op
, mode
);
789 if (GET_CODE (XEXP (op
, 0)) == PRE_INC
790 || GET_CODE (XEXP (op
, 0)) == PRE_DEC
)
791 return 0; /* loads can't do pre-{inc,dec} */
792 return address_operand (XEXP (op
, 0), mode
);
798 /* Return true if OP is an acceptable argument for a double word
802 move_double_src_operand (rtx op
, enum machine_mode mode
)
804 switch (GET_CODE (op
))
810 return register_operand (op
, mode
);
812 /* (subreg (mem ...) ...) can occur here if the inner part was once a
813 pseudo-reg and is now a stack slot. */
814 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
815 return move_double_src_operand (SUBREG_REG (op
), mode
);
817 return register_operand (op
, mode
);
819 /* Disallow auto inc/dec for now. */
820 if (GET_CODE (XEXP (op
, 0)) == PRE_DEC
821 || GET_CODE (XEXP (op
, 0)) == PRE_INC
)
823 return address_operand (XEXP (op
, 0), mode
);
829 /* Return true if OP is an acceptable argument for a move destination. */
832 move_dest_operand (rtx op
, enum machine_mode mode
)
834 switch (GET_CODE (op
))
837 return register_operand (op
, mode
);
839 /* (subreg (mem ...) ...) can occur here if the inner part was once a
840 pseudo-reg and is now a stack slot. */
841 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
842 return address_operand (XEXP (SUBREG_REG (op
), 0), mode
);
844 return register_operand (op
, mode
);
846 if (GET_CODE (XEXP (op
, 0)) == POST_INC
)
847 return 0; /* stores can't do post inc */
848 return address_operand (XEXP (op
, 0), mode
);
854 /* Return 1 if OP is a DImode const we want to handle inline.
855 This must match the code in the movdi pattern.
856 It is used by the 'G' CONST_DOUBLE_OK_FOR_LETTER. */
859 easy_di_const (rtx op
)
861 rtx high_rtx
, low_rtx
;
862 HOST_WIDE_INT high
, low
;
864 split_double (op
, &high_rtx
, &low_rtx
);
865 high
= INTVAL (high_rtx
);
866 low
= INTVAL (low_rtx
);
867 /* Pick constants loadable with 2 16 bit `ldi' insns. */
868 if (high
>= -128 && high
<= 127
869 && low
>= -128 && low
<= 127)
874 /* Return 1 if OP is a DFmode const we want to handle inline.
875 This must match the code in the movdf pattern.
876 It is used by the 'H' CONST_DOUBLE_OK_FOR_LETTER. */
879 easy_df_const (rtx op
)
884 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
885 REAL_VALUE_TO_TARGET_DOUBLE (r
, l
);
886 if (l
[0] == 0 && l
[1] == 0)
888 if ((l
[0] & 0xffff) == 0 && l
[1] == 0)
893 /* Return 1 if OP is an EQ or NE comparison operator. */
896 eqne_comparison_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
898 enum rtx_code code
= GET_CODE (op
);
900 return (code
== EQ
|| code
== NE
);
903 /* Return 1 if OP is a signed comparison operator. */
906 signed_comparison_operator (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
908 enum rtx_code code
= GET_CODE (op
);
910 return (COMPARISON_P (op
)
911 && (code
== EQ
|| code
== NE
912 || code
== LT
|| code
== LE
|| code
== GT
|| code
== GE
));
915 /* Return 1 if OP is (mem (reg ...)).
916 This is used in insn length calcs. */
919 memreg_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
921 return GET_CODE (op
) == MEM
&& GET_CODE (XEXP (op
, 0)) == REG
;
924 /* Return true if OP is an acceptable input argument for a zero/sign extend
928 extend_operand (rtx op
, enum machine_mode mode
)
932 switch (GET_CODE (op
))
936 return register_operand (op
, mode
);
940 if (GET_CODE (addr
) == PRE_INC
|| GET_CODE (addr
) == PRE_DEC
)
941 return 0; /* loads can't do pre inc/pre dec */
943 return address_operand (addr
, mode
);
950 /* Return nonzero if the operand is an insn that is a small insn.
951 Allow const_int 0 as well, which is a placeholder for NOP slots. */
954 small_insn_p (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
956 if (GET_CODE (op
) == CONST_INT
&& INTVAL (op
) == 0)
962 return get_attr_length (op
) == 2;
965 /* Return nonzero if the operand is an insn that is a large insn. */
968 large_insn_p (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
973 return get_attr_length (op
) != 2;
976 /* Return nonzero if TYPE must be passed by indirect reference. */
979 m32r_pass_by_reference (CUMULATIVE_ARGS
*ca ATTRIBUTE_UNUSED
,
980 enum machine_mode mode
, tree type
,
981 bool named ATTRIBUTE_UNUSED
)
986 size
= int_size_in_bytes (type
);
988 size
= GET_MODE_SIZE (mode
);
990 return (size
< 0 || size
> 8);
995 /* X and Y are two things to compare using CODE. Emit the compare insn and
996 return the rtx for compare [arg0 of the if_then_else].
997 If need_compare is true then the comparison insn must be generated, rather
998 than being subsumed into the following branch instruction. */
1001 gen_compare (enum rtx_code code
, rtx x
, rtx y
, int need_compare
)
1003 enum rtx_code compare_code
;
1004 enum rtx_code branch_code
;
1005 rtx cc_reg
= gen_rtx_REG (CCmode
, CARRY_REGNUM
);
1010 case EQ
: compare_code
= EQ
; branch_code
= NE
; break;
1011 case NE
: compare_code
= EQ
; branch_code
= EQ
; break;
1012 case LT
: compare_code
= LT
; branch_code
= NE
; break;
1013 case LE
: compare_code
= LT
; branch_code
= EQ
; must_swap
= 1; break;
1014 case GT
: compare_code
= LT
; branch_code
= NE
; must_swap
= 1; break;
1015 case GE
: compare_code
= LT
; branch_code
= EQ
; break;
1016 case LTU
: compare_code
= LTU
; branch_code
= NE
; break;
1017 case LEU
: compare_code
= LTU
; branch_code
= EQ
; must_swap
= 1; break;
1018 case GTU
: compare_code
= LTU
; branch_code
= NE
; must_swap
= 1; break;
1019 case GEU
: compare_code
= LTU
; branch_code
= EQ
; break;
1027 switch (compare_code
)
1030 if (GET_CODE (y
) == CONST_INT
1031 && CMP_INT16_P (INTVAL (y
)) /* Reg equal to small const. */
1034 rtx tmp
= gen_reg_rtx (SImode
);
1036 emit_insn (gen_addsi3 (tmp
, x
, GEN_INT (-INTVAL (y
))));
1040 else if (CONSTANT_P (y
)) /* Reg equal to const. */
1042 rtx tmp
= force_reg (GET_MODE (x
), y
);
1046 if (register_operand (y
, SImode
) /* Reg equal to reg. */
1047 || y
== const0_rtx
) /* Reg equal to zero. */
1049 emit_insn (gen_cmp_eqsi_insn (x
, y
));
1051 return gen_rtx_fmt_ee (code
, CCmode
, cc_reg
, const0_rtx
);
1056 if (register_operand (y
, SImode
)
1057 || (GET_CODE (y
) == CONST_INT
&& CMP_INT16_P (INTVAL (y
))))
1059 rtx tmp
= gen_reg_rtx (SImode
); /* Reg compared to reg. */
1064 emit_insn (gen_cmp_ltsi_insn (x
, y
));
1068 if (y
== const0_rtx
)
1071 emit_insn (gen_addsi3 (tmp
, y
, constm1_rtx
));
1072 emit_insn (gen_cmp_ltsi_insn (x
, tmp
));
1076 if (GET_CODE (y
) == CONST_INT
)
1077 tmp
= gen_rtx_PLUS (SImode
, y
, const1_rtx
);
1079 emit_insn (gen_addsi3 (tmp
, y
, constm1_rtx
));
1080 emit_insn (gen_cmp_ltsi_insn (x
, tmp
));
1084 emit_insn (gen_cmp_ltsi_insn (x
, y
));
1091 return gen_rtx_fmt_ee (code
, CCmode
, cc_reg
, const0_rtx
);
1096 if (register_operand (y
, SImode
)
1097 || (GET_CODE (y
) == CONST_INT
&& CMP_INT16_P (INTVAL (y
))))
1099 rtx tmp
= gen_reg_rtx (SImode
); /* Reg (unsigned) compared to reg. */
1104 emit_insn (gen_cmp_ltusi_insn (x
, y
));
1108 if (y
== const0_rtx
)
1111 emit_insn (gen_addsi3 (tmp
, y
, constm1_rtx
));
1112 emit_insn (gen_cmp_ltusi_insn (x
, tmp
));
1116 if (GET_CODE (y
) == CONST_INT
)
1117 tmp
= gen_rtx_PLUS (SImode
, y
, const1_rtx
);
1119 emit_insn (gen_addsi3 (tmp
, y
, constm1_rtx
));
1120 emit_insn (gen_cmp_ltusi_insn (x
, tmp
));
1124 emit_insn (gen_cmp_ltusi_insn (x
, y
));
1131 return gen_rtx_fmt_ee (code
, CCmode
, cc_reg
, const0_rtx
);
1141 /* Reg/reg equal comparison. */
1142 if (compare_code
== EQ
1143 && register_operand (y
, SImode
))
1144 return gen_rtx_fmt_ee (code
, CCmode
, x
, y
);
1146 /* Reg/zero signed comparison. */
1147 if ((compare_code
== EQ
|| compare_code
== LT
)
1149 return gen_rtx_fmt_ee (code
, CCmode
, x
, y
);
1151 /* Reg/smallconst equal comparison. */
1152 if (compare_code
== EQ
1153 && GET_CODE (y
) == CONST_INT
1154 && CMP_INT16_P (INTVAL (y
)))
1156 rtx tmp
= gen_reg_rtx (SImode
);
1158 emit_insn (gen_addsi3 (tmp
, x
, GEN_INT (-INTVAL (y
))));
1159 return gen_rtx_fmt_ee (code
, CCmode
, tmp
, const0_rtx
);
1162 /* Reg/const equal comparison. */
1163 if (compare_code
== EQ
1166 rtx tmp
= force_reg (GET_MODE (x
), y
);
1168 return gen_rtx_fmt_ee (code
, CCmode
, x
, tmp
);
1175 y
= force_reg (GET_MODE (x
), y
);
1179 (code
== LTU
|| code
== LEU
|| code
== GTU
|| code
== GEU
)
1180 ? uint16_operand (y
, GET_MODE (y
))
1181 : reg_or_cmp_int16_operand (y
, GET_MODE (y
));
1184 y
= force_reg (GET_MODE (x
), y
);
1188 switch (compare_code
)
1191 emit_insn (gen_cmp_eqsi_insn (must_swap
? y
: x
, must_swap
? x
: y
));
1194 emit_insn (gen_cmp_ltsi_insn (must_swap
? y
: x
, must_swap
? x
: y
));
1197 emit_insn (gen_cmp_ltusi_insn (must_swap
? y
: x
, must_swap
? x
: y
));
1204 return gen_rtx_fmt_ee (branch_code
, VOIDmode
, cc_reg
, CONST0_RTX (CCmode
));
1207 /* Split a 2 word move (DI or DF) into component parts. */
1210 gen_split_move_double (rtx operands
[])
1212 enum machine_mode mode
= GET_MODE (operands
[0]);
1213 rtx dest
= operands
[0];
1214 rtx src
= operands
[1];
1217 /* We might have (SUBREG (MEM)) here, so just get rid of the
1218 subregs to make this code simpler. It is safe to call
1219 alter_subreg any time after reload. */
1220 if (GET_CODE (dest
) == SUBREG
)
1221 alter_subreg (&dest
);
1222 if (GET_CODE (src
) == SUBREG
)
1223 alter_subreg (&src
);
1226 if (GET_CODE (dest
) == REG
)
1228 int dregno
= REGNO (dest
);
1231 if (GET_CODE (src
) == REG
)
1233 int sregno
= REGNO (src
);
1235 int reverse
= (dregno
== sregno
+ 1);
1237 /* We normally copy the low-numbered register first. However, if
1238 the first register operand 0 is the same as the second register of
1239 operand 1, we must copy in the opposite order. */
1240 emit_insn (gen_rtx_SET (VOIDmode
,
1241 operand_subword (dest
, reverse
, TRUE
, mode
),
1242 operand_subword (src
, reverse
, TRUE
, mode
)));
1244 emit_insn (gen_rtx_SET (VOIDmode
,
1245 operand_subword (dest
, !reverse
, TRUE
, mode
),
1246 operand_subword (src
, !reverse
, TRUE
, mode
)));
1249 /* Reg = constant. */
1250 else if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
1253 split_double (src
, &words
[0], &words
[1]);
1254 emit_insn (gen_rtx_SET (VOIDmode
,
1255 operand_subword (dest
, 0, TRUE
, mode
),
1258 emit_insn (gen_rtx_SET (VOIDmode
,
1259 operand_subword (dest
, 1, TRUE
, mode
),
1264 else if (GET_CODE (src
) == MEM
)
1266 /* If the high-address word is used in the address, we must load it
1267 last. Otherwise, load it first. */
1269 = (refers_to_regno_p (dregno
, dregno
+ 1, XEXP (src
, 0), 0) != 0);
1271 /* We used to optimize loads from single registers as
1275 if r3 were not used subsequently. However, the REG_NOTES aren't
1276 propagated correctly by the reload phase, and it can cause bad
1277 code to be generated. We could still try:
1279 ld r1,r3+; ld r2,r3; addi r3,-4
1281 which saves 2 bytes and doesn't force longword alignment. */
1282 emit_insn (gen_rtx_SET (VOIDmode
,
1283 operand_subword (dest
, reverse
, TRUE
, mode
),
1284 adjust_address (src
, SImode
,
1285 reverse
* UNITS_PER_WORD
)));
1287 emit_insn (gen_rtx_SET (VOIDmode
,
1288 operand_subword (dest
, !reverse
, TRUE
, mode
),
1289 adjust_address (src
, SImode
,
1290 !reverse
* UNITS_PER_WORD
)));
1297 /* We used to optimize loads from single registers as
1301 if r3 were not used subsequently. However, the REG_NOTES aren't
1302 propagated correctly by the reload phase, and it can cause bad
1303 code to be generated. We could still try:
1305 st r1,r3; st r2,+r3; addi r3,-4
1307 which saves 2 bytes and doesn't force longword alignment. */
1308 else if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == REG
)
1310 emit_insn (gen_rtx_SET (VOIDmode
,
1311 adjust_address (dest
, SImode
, 0),
1312 operand_subword (src
, 0, TRUE
, mode
)));
1314 emit_insn (gen_rtx_SET (VOIDmode
,
1315 adjust_address (dest
, SImode
, UNITS_PER_WORD
),
1316 operand_subword (src
, 1, TRUE
, mode
)));
1328 /* Implements the FUNCTION_ARG_PARTIAL_NREGS macro. */
1331 function_arg_partial_nregs (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1332 tree type
, int named ATTRIBUTE_UNUSED
)
1336 (((mode
== BLKmode
&& type
)
1337 ? (unsigned int) int_size_in_bytes (type
)
1338 : GET_MODE_SIZE (mode
)) + UNITS_PER_WORD
- 1)
1341 if (*cum
>= M32R_MAX_PARM_REGS
)
1343 else if (*cum
+ size
> M32R_MAX_PARM_REGS
)
1344 ret
= (*cum
+ size
) - M32R_MAX_PARM_REGS
;
1351 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1354 m32r_return_in_memory (tree type
, tree fntype ATTRIBUTE_UNUSED
)
1356 return m32r_pass_by_reference (NULL
, TYPE_MODE (type
), type
, false);
1359 /* Do any needed setup for a variadic function. For the M32R, we must
1360 create a register parameter block, and then copy any anonymous arguments
1361 in registers to memory.
1363 CUM has not been updated for the last named argument which has type TYPE
1364 and mode MODE, and we rely on this fact. */
1367 m32r_setup_incoming_varargs (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1368 tree type
, int *pretend_size
, int no_rtl
)
1375 /* All BLKmode values are passed by reference. */
1376 if (mode
== BLKmode
)
1379 first_anon_arg
= (ROUND_ADVANCE_CUM (*cum
, mode
, type
)
1380 + ROUND_ADVANCE_ARG (mode
, type
));
1382 if (first_anon_arg
< M32R_MAX_PARM_REGS
)
1384 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1385 int first_reg_offset
= first_anon_arg
;
1386 /* Size in words to "pretend" allocate. */
1387 int size
= M32R_MAX_PARM_REGS
- first_reg_offset
;
1390 regblock
= gen_rtx_MEM (BLKmode
,
1391 plus_constant (arg_pointer_rtx
,
1392 FIRST_PARM_OFFSET (0)));
1393 set_mem_alias_set (regblock
, get_varargs_alias_set ());
1394 move_block_from_reg (first_reg_offset
, regblock
, size
);
1396 *pretend_size
= (size
* UNITS_PER_WORD
);
1401 /* Return true if INSN is real instruction bearing insn. */
1404 m32r_is_insn (rtx insn
)
1406 return (INSN_P (insn
)
1407 && GET_CODE (PATTERN (insn
)) != USE
1408 && GET_CODE (PATTERN (insn
)) != CLOBBER
1409 && GET_CODE (PATTERN (insn
)) != ADDR_VEC
);
1412 /* Increase the priority of long instructions so that the
1413 short instructions are scheduled ahead of the long ones. */
1416 m32r_adjust_priority (rtx insn
, int priority
)
1418 if (m32r_is_insn (insn
)
1419 && get_attr_insn_size (insn
) != INSN_SIZE_SHORT
)
1426 /* Indicate how many instructions can be issued at the same time.
1427 This is sort of a lie. The m32r can issue only 1 long insn at
1428 once, but it can issue 2 short insns. The default therefore is
1429 set at 2, but this can be overridden by the command line option
1433 m32r_issue_rate (void)
1435 return ((TARGET_LOW_ISSUE_RATE
) ? 1 : 2);
1438 /* Cost functions. */
1441 m32r_rtx_costs (rtx x
, int code
, int outer_code ATTRIBUTE_UNUSED
, int *total
)
1445 /* Small integers are as cheap as registers. 4 byte values can be
1446 fetched as immediate constants - let's give that the cost of an
1449 if (INT16_P (INTVAL (x
)))
1459 *total
= COSTS_N_INSNS (1);
1466 split_double (x
, &high
, &low
);
1467 *total
= COSTS_N_INSNS (!INT16_P (INTVAL (high
))
1468 + !INT16_P (INTVAL (low
)));
1473 *total
= COSTS_N_INSNS (3);
1480 *total
= COSTS_N_INSNS (10);
1488 /* Type of function DECL.
1490 The result is cached. To reset the cache at the end of a function,
1491 call with DECL = NULL_TREE. */
1493 enum m32r_function_type
1494 m32r_compute_function_type (tree decl
)
1497 static enum m32r_function_type fn_type
= M32R_FUNCTION_UNKNOWN
;
1498 /* Last function we were called for. */
1499 static tree last_fn
= NULL_TREE
;
1501 /* Resetting the cached value? */
1502 if (decl
== NULL_TREE
)
1504 fn_type
= M32R_FUNCTION_UNKNOWN
;
1505 last_fn
= NULL_TREE
;
1509 if (decl
== last_fn
&& fn_type
!= M32R_FUNCTION_UNKNOWN
)
1512 /* Compute function type. */
1513 fn_type
= (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl
)) != NULL_TREE
1514 ? M32R_FUNCTION_INTERRUPT
1515 : M32R_FUNCTION_NORMAL
);
1520 \f/* Function prologue/epilogue handlers. */
1522 /* M32R stack frames look like:
1524 Before call After call
1525 +-----------------------+ +-----------------------+
1527 high | local variables, | | local variables, |
1528 mem | reg save area, etc. | | reg save area, etc. |
1530 +-----------------------+ +-----------------------+
1532 | arguments on stack. | | arguments on stack. |
1534 SP+0->+-----------------------+ +-----------------------+
1535 | reg parm save area, |
1536 | only created for |
1537 | variable argument |
1539 +-----------------------+
1540 | previous frame ptr |
1541 +-----------------------+
1543 | register save area |
1545 +-----------------------+
1547 +-----------------------+
1551 +-----------------------+
1553 | alloca allocations |
1555 +-----------------------+
1557 low | arguments on stack |
1559 SP+0->+-----------------------+
1562 1) The "reg parm save area" does not exist for non variable argument fns.
1563 2) The "reg parm save area" can be eliminated completely if we saved regs
1564 containing anonymous args separately but that complicates things too
1565 much (so it's not done).
1566 3) The return address is saved after the register save area so as to have as
1567 many insns as possible between the restoration of `lr' and the `jmp lr'. */
1569 /* Structure to be filled in by m32r_compute_frame_size with register
1570 save masks, and offsets for the current function. */
1571 struct m32r_frame_info
1573 unsigned int total_size
; /* # bytes that the entire frame takes up. */
1574 unsigned int extra_size
; /* # bytes of extra stuff. */
1575 unsigned int pretend_size
; /* # bytes we push and pretend caller did. */
1576 unsigned int args_size
; /* # bytes that outgoing arguments take up. */
1577 unsigned int reg_size
; /* # bytes needed to store regs. */
1578 unsigned int var_size
; /* # bytes that variables take up. */
1579 unsigned int gmask
; /* Mask of saved gp registers. */
1580 unsigned int save_fp
; /* Nonzero if fp must be saved. */
1581 unsigned int save_lr
; /* Nonzero if lr (return addr) must be saved. */
1582 int initialized
; /* Nonzero if frame size already calculated. */
1585 /* Current frame information calculated by m32r_compute_frame_size. */
1586 static struct m32r_frame_info current_frame_info
;
1588 /* Zero structure to initialize current_frame_info. */
1589 static struct m32r_frame_info zero_frame_info
;
1591 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1592 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1594 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1595 The return address and frame pointer are treated separately.
1596 Don't consider them here. */
1597 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1598 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1599 && (regs_ever_live[regno] && (!call_used_regs[regno] || interrupt_p)))
1601 #define MUST_SAVE_FRAME_POINTER (regs_ever_live[FRAME_POINTER_REGNUM])
1602 #define MUST_SAVE_RETURN_ADDR (regs_ever_live[RETURN_ADDR_REGNUM] || current_function_profile)
1604 #define SHORT_INSN_SIZE 2 /* Size of small instructions. */
1605 #define LONG_INSN_SIZE 4 /* Size of long instructions. */
1607 /* Return the bytes needed to compute the frame pointer from the current
1610 SIZE is the size needed for local variables. */
1613 m32r_compute_frame_size (int size
) /* # of var. bytes allocated. */
1616 unsigned int total_size
, var_size
, args_size
, pretend_size
, extra_size
;
1617 unsigned int reg_size
, frame_size
;
1619 enum m32r_function_type fn_type
;
1621 int pic_reg_used
= flag_pic
&& (current_function_uses_pic_offset_table
);
1623 var_size
= M32R_STACK_ALIGN (size
);
1624 args_size
= M32R_STACK_ALIGN (current_function_outgoing_args_size
);
1625 pretend_size
= current_function_pretend_args_size
;
1626 extra_size
= FIRST_PARM_OFFSET (0);
1627 total_size
= extra_size
+ pretend_size
+ args_size
+ var_size
;
1631 /* See if this is an interrupt handler. Call used registers must be saved
1633 fn_type
= m32r_compute_function_type (current_function_decl
);
1634 interrupt_p
= M32R_INTERRUPT_P (fn_type
);
1636 /* Calculate space needed for registers. */
1637 for (regno
= 0; regno
< M32R_MAX_INT_REGS
; regno
++)
1639 if (MUST_SAVE_REGISTER (regno
, interrupt_p
)
1640 || (regno
== PIC_OFFSET_TABLE_REGNUM
&& pic_reg_used
))
1642 reg_size
+= UNITS_PER_WORD
;
1643 gmask
|= 1 << regno
;
1647 current_frame_info
.save_fp
= MUST_SAVE_FRAME_POINTER
;
1648 current_frame_info
.save_lr
= MUST_SAVE_RETURN_ADDR
|| pic_reg_used
;
1650 reg_size
+= ((current_frame_info
.save_fp
+ current_frame_info
.save_lr
)
1652 total_size
+= reg_size
;
1654 /* ??? Not sure this is necessary, and I don't think the epilogue
1655 handler will do the right thing if this changes total_size. */
1656 total_size
= M32R_STACK_ALIGN (total_size
);
1658 frame_size
= total_size
- (pretend_size
+ reg_size
);
1660 /* Save computed information. */
1661 current_frame_info
.total_size
= total_size
;
1662 current_frame_info
.extra_size
= extra_size
;
1663 current_frame_info
.pretend_size
= pretend_size
;
1664 current_frame_info
.var_size
= var_size
;
1665 current_frame_info
.args_size
= args_size
;
1666 current_frame_info
.reg_size
= reg_size
;
1667 current_frame_info
.gmask
= gmask
;
1668 current_frame_info
.initialized
= reload_completed
;
1670 /* Ok, we're done. */
1674 /* The table we use to reference PIC data. */
1675 static rtx global_offset_table
;
1678 m32r_reload_lr (rtx sp
, int size
)
1680 rtx lr
= gen_rtx_REG (Pmode
, RETURN_ADDR_REGNUM
);
1683 emit_insn (gen_movsi (lr
, gen_rtx_MEM (Pmode
, sp
)));
1684 else if (size
<= 32768)
1685 emit_insn (gen_movsi (lr
, gen_rtx_MEM (Pmode
,
1686 gen_rtx_PLUS (Pmode
, sp
,
1690 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
1692 emit_insn (gen_movsi (tmp
, GEN_INT (size
)));
1693 emit_insn (gen_addsi3 (tmp
, tmp
, sp
));
1694 emit_insn (gen_movsi (lr
, gen_rtx_MEM (Pmode
, tmp
)));
1697 emit_insn (gen_rtx_USE (VOIDmode
, lr
));
1701 m32r_load_pic_register (void)
1703 global_offset_table
= gen_rtx_SYMBOL_REF (Pmode
, "_GLOBAL_OFFSET_TABLE_");
1704 emit_insn (gen_get_pc (pic_offset_table_rtx
, global_offset_table
,
1705 GEN_INT (TARGET_MODEL_SMALL
)));
1707 /* Need to emit this whether or not we obey regdecls,
1708 since setjmp/longjmp can cause life info to screw up. */
1709 emit_insn (gen_rtx_USE (VOIDmode
, pic_offset_table_rtx
));
1712 /* Expand the m32r prologue as a series of insns. */
1715 m32r_expand_prologue (void)
1720 int pic_reg_used
= flag_pic
&& (current_function_uses_pic_offset_table
);
1722 if (! current_frame_info
.initialized
)
1723 m32r_compute_frame_size (get_frame_size ());
1725 gmask
= current_frame_info
.gmask
;
1727 /* These cases shouldn't happen. Catch them now. */
1728 if (current_frame_info
.total_size
== 0 && gmask
)
1731 /* Allocate space for register arguments if this is a variadic function. */
1732 if (current_frame_info
.pretend_size
!= 0)
1734 /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1735 the wrong result on a 64-bit host. */
1736 HOST_WIDE_INT pretend_size
= current_frame_info
.pretend_size
;
1737 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1739 GEN_INT (-pretend_size
)));
1742 /* Save any registers we need to and set up fp. */
1743 if (current_frame_info
.save_fp
)
1744 emit_insn (gen_movsi_push (stack_pointer_rtx
, frame_pointer_rtx
));
1746 gmask
&= ~(FRAME_POINTER_MASK
| RETURN_ADDR_MASK
);
1748 /* Save any needed call-saved regs (and call-used if this is an
1749 interrupt handler). */
1750 for (regno
= 0; regno
<= M32R_MAX_INT_REGS
; ++regno
)
1752 if ((gmask
& (1 << regno
)) != 0)
1753 emit_insn (gen_movsi_push (stack_pointer_rtx
,
1754 gen_rtx_REG (Pmode
, regno
)));
1757 if (current_frame_info
.save_lr
)
1758 emit_insn (gen_movsi_push (stack_pointer_rtx
,
1759 gen_rtx_REG (Pmode
, RETURN_ADDR_REGNUM
)));
1761 /* Allocate the stack frame. */
1762 frame_size
= (current_frame_info
.total_size
1763 - (current_frame_info
.pretend_size
1764 + current_frame_info
.reg_size
));
1766 if (frame_size
== 0)
1767 ; /* Nothing to do. */
1768 else if (frame_size
<= 32768)
1769 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
1770 GEN_INT (-frame_size
)));
1773 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
1775 emit_insn (gen_movsi (tmp
, GEN_INT (frame_size
)));
1776 emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
, tmp
));
1779 if (frame_pointer_needed
)
1780 emit_insn (gen_movsi (frame_pointer_rtx
, stack_pointer_rtx
));
1782 if (current_function_profile
)
1783 /* Push lr for mcount (form_pc, x). */
1784 emit_insn (gen_movsi_push (stack_pointer_rtx
,
1785 gen_rtx_REG (Pmode
, RETURN_ADDR_REGNUM
)));
1789 m32r_load_pic_register ();
1790 m32r_reload_lr (stack_pointer_rtx
,
1791 (current_function_profile
? 0 : frame_size
));
1794 if (current_function_profile
&& !pic_reg_used
)
1795 emit_insn (gen_blockage ());
1799 /* Set up the stack and frame pointer (if desired) for the function.
1800 Note, if this is changed, you need to mirror the changes in
1801 m32r_compute_frame_size which calculates the prolog size. */
1804 m32r_output_function_prologue (FILE * file
, HOST_WIDE_INT size
)
1806 enum m32r_function_type fn_type
= m32r_compute_function_type (current_function_decl
);
1808 /* If this is an interrupt handler, mark it as such. */
1809 if (M32R_INTERRUPT_P (fn_type
))
1810 fprintf (file
, "\t%s interrupt handler\n", ASM_COMMENT_START
);
1812 if (! current_frame_info
.initialized
)
1813 m32r_compute_frame_size (size
);
1815 /* This is only for the human reader. */
1817 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
1819 current_frame_info
.var_size
,
1820 current_frame_info
.reg_size
/ 4,
1821 current_frame_info
.args_size
,
1822 current_frame_info
.extra_size
);
1825 /* Do any necessary cleanup after a function to restore stack, frame,
1829 m32r_output_function_epilogue (FILE * file
, HOST_WIDE_INT size ATTRIBUTE_UNUSED
)
1832 int noepilogue
= FALSE
;
1834 enum m32r_function_type fn_type
= m32r_compute_function_type (current_function_decl
);
1836 /* This is only for the human reader. */
1837 fprintf (file
, "\t%s EPILOGUE\n", ASM_COMMENT_START
);
1839 if (!current_frame_info
.initialized
)
1841 total_size
= current_frame_info
.total_size
;
1843 if (total_size
== 0)
1845 rtx insn
= get_last_insn ();
1847 /* If the last insn was a BARRIER, we don't have to write any code
1848 because a jump (aka return) was put there. */
1849 if (GET_CODE (insn
) == NOTE
)
1850 insn
= prev_nonnote_insn (insn
);
1851 if (insn
&& GET_CODE (insn
) == BARRIER
)
1857 unsigned int var_size
= current_frame_info
.var_size
;
1858 unsigned int args_size
= current_frame_info
.args_size
;
1859 unsigned int gmask
= current_frame_info
.gmask
;
1860 int can_trust_sp_p
= !current_function_calls_alloca
;
1861 const char * sp_str
= reg_names
[STACK_POINTER_REGNUM
];
1862 const char * fp_str
= reg_names
[FRAME_POINTER_REGNUM
];
1864 /* The first thing to do is point the sp at the bottom of the register
1868 unsigned int reg_offset
= var_size
+ args_size
;
1869 if (reg_offset
== 0)
1870 ; /* Nothing to do. */
1871 else if (reg_offset
< 128)
1872 fprintf (file
, "\taddi %s,%s%d\n",
1873 sp_str
, IMMEDIATE_PREFIX
, reg_offset
);
1874 else if (reg_offset
< 32768)
1875 fprintf (file
, "\tadd3 %s,%s,%s%d\n",
1876 sp_str
, sp_str
, IMMEDIATE_PREFIX
, reg_offset
);
1878 fprintf (file
, "\tld24 %s,%s%d\n\tadd %s,%s\n",
1879 reg_names
[PROLOGUE_TMP_REGNUM
],
1880 IMMEDIATE_PREFIX
, reg_offset
,
1881 sp_str
, reg_names
[PROLOGUE_TMP_REGNUM
]);
1883 else if (frame_pointer_needed
)
1885 unsigned int reg_offset
= var_size
+ args_size
;
1887 if (reg_offset
== 0)
1888 fprintf (file
, "\tmv %s,%s\n", sp_str
, fp_str
);
1889 else if (reg_offset
< 32768)
1890 fprintf (file
, "\tadd3 %s,%s,%s%d\n",
1891 sp_str
, fp_str
, IMMEDIATE_PREFIX
, reg_offset
);
1893 fprintf (file
, "\tld24 %s,%s%d\n\tadd %s,%s\n",
1894 reg_names
[PROLOGUE_TMP_REGNUM
],
1895 IMMEDIATE_PREFIX
, reg_offset
,
1896 sp_str
, reg_names
[PROLOGUE_TMP_REGNUM
]);
1901 if (current_frame_info
.save_lr
)
1902 fprintf (file
, "\tpop %s\n", reg_names
[RETURN_ADDR_REGNUM
]);
1904 /* Restore any saved registers, in reverse order of course. */
1905 gmask
&= ~(FRAME_POINTER_MASK
| RETURN_ADDR_MASK
);
1906 for (regno
= M32R_MAX_INT_REGS
- 1; regno
>= 0; --regno
)
1908 if ((gmask
& (1L << regno
)) != 0)
1909 fprintf (file
, "\tpop %s\n", reg_names
[regno
]);
1912 if (current_frame_info
.save_fp
)
1913 fprintf (file
, "\tpop %s\n", fp_str
);
1915 /* Remove varargs area if present. */
1916 if (current_frame_info
.pretend_size
!= 0)
1917 fprintf (file
, "\taddi %s,%s%d\n",
1918 sp_str
, IMMEDIATE_PREFIX
, current_frame_info
.pretend_size
);
1920 /* Emit the return instruction. */
1921 if (M32R_INTERRUPT_P (fn_type
))
1922 fprintf (file
, "\trte\n");
1924 fprintf (file
, "\tjmp %s\n", reg_names
[RETURN_ADDR_REGNUM
]);
1927 /* Reset state info for each function. */
1928 current_frame_info
= zero_frame_info
;
1929 m32r_compute_function_type (NULL_TREE
);
1932 /* Return nonzero if this function is known to have a null or 1 instruction
1936 direct_return (void)
1938 if (!reload_completed
)
1941 if (! current_frame_info
.initialized
)
1942 m32r_compute_frame_size (get_frame_size ());
1944 return current_frame_info
.total_size
== 0;
1951 m32r_legitimate_pic_operand_p (rtx x
)
1953 if (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
)
1956 if (GET_CODE (x
) == CONST
1957 && GET_CODE (XEXP (x
, 0)) == PLUS
1958 && (GET_CODE (XEXP (XEXP (x
, 0), 0)) == SYMBOL_REF
1959 || GET_CODE (XEXP (XEXP (x
, 0), 0)) == LABEL_REF
)
1960 && (GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
))
1967 m32r_legitimize_pic_address (rtx orig
, rtx reg
)
1970 printf("m32r_legitimize_pic_address()\n");
1973 if (GET_CODE (orig
) == SYMBOL_REF
|| GET_CODE (orig
) == LABEL_REF
)
1975 rtx pic_ref
, address
;
1981 if (reload_in_progress
|| reload_completed
)
1984 reg
= gen_reg_rtx (Pmode
);
1990 address
= gen_reg_rtx (Pmode
);
1994 emit_insn (gen_pic_load_addr (address
, orig
));
1996 emit_insn (gen_addsi3 (address
, address
, pic_offset_table_rtx
));
1997 pic_ref
= gen_rtx_MEM (Pmode
, address
);
1999 RTX_UNCHANGING_P (pic_ref
) = 1;
2000 insn
= emit_move_insn (reg
, pic_ref
);
2001 current_function_uses_pic_offset_table
= 1;
2003 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2005 REG_NOTES (insn
) = gen_rtx_EXPR_LIST (REG_EQUAL
, orig
,
2010 else if (GET_CODE (orig
) == CONST
)
2014 if (GET_CODE (XEXP (orig
, 0)) == PLUS
2015 && XEXP (XEXP (orig
, 0), 1) == pic_offset_table_rtx
)
2020 if (reload_in_progress
|| reload_completed
)
2023 reg
= gen_reg_rtx (Pmode
);
2026 if (GET_CODE (XEXP (orig
, 0)) == PLUS
)
2028 base
= m32r_legitimize_pic_address (XEXP (XEXP (orig
, 0), 0), reg
);
2030 offset
= m32r_legitimize_pic_address (XEXP (XEXP (orig
, 0), 1), NULL_RTX
);
2032 offset
= m32r_legitimize_pic_address (XEXP (XEXP (orig
, 0), 1), reg
);
2037 if (GET_CODE (offset
) == CONST_INT
)
2039 if (INT16_P (INTVAL (offset
)))
2040 return plus_constant (base
, INTVAL (offset
));
2041 else if (! reload_in_progress
&& ! reload_completed
)
2042 offset
= force_reg (Pmode
, offset
);
2044 /* If we reach here, then something is seriously wrong. */
2048 return gen_rtx_PLUS (Pmode
, base
, offset
);
2054 /* Emit special PIC prologues and epilogues. */
2057 m32r_finalize_pic (void)
2059 current_function_uses_pic_offset_table
|= current_function_profile
;
2062 /* Nested function support. */
2064 /* Emit RTL insns to initialize the variable parts of a trampoline.
2065 FNADDR is an RTX for the address of the function's pure code.
2066 CXT is an RTX for the static chain value for the function. */
2069 m32r_initialize_trampoline (rtx tramp ATTRIBUTE_UNUSED
,
2070 rtx fnaddr ATTRIBUTE_UNUSED
,
2071 rtx cxt ATTRIBUTE_UNUSED
)
2076 m32r_file_start (void)
2078 default_file_start ();
2080 if (flag_verbose_asm
)
2081 fprintf (asm_out_file
,
2082 "%s M32R/D special options: -G " HOST_WIDE_INT_PRINT_UNSIGNED
"\n",
2083 ASM_COMMENT_START
, g_switch_value
);
2085 if (TARGET_LITTLE_ENDIAN
)
2086 fprintf (asm_out_file
, "\t.little\n");
2089 /* Print operand X (an rtx) in assembler syntax to file FILE.
2090 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2091 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2094 m32r_print_operand (FILE * file
, rtx x
, int code
)
2100 /* The 's' and 'p' codes are used by output_block_move() to
2101 indicate post-increment 's'tores and 'p're-increment loads. */
2103 if (GET_CODE (x
) == REG
)
2104 fprintf (file
, "@+%s", reg_names
[REGNO (x
)]);
2106 output_operand_lossage ("invalid operand to %%s code");
2110 if (GET_CODE (x
) == REG
)
2111 fprintf (file
, "@%s+", reg_names
[REGNO (x
)]);
2113 output_operand_lossage ("invalid operand to %%p code");
2117 /* Write second word of DImode or DFmode reference,
2118 register or memory. */
2119 if (GET_CODE (x
) == REG
)
2120 fputs (reg_names
[REGNO (x
)+1], file
);
2121 else if (GET_CODE (x
) == MEM
)
2123 fprintf (file
, "@(");
2124 /* Handle possible auto-increment. Since it is pre-increment and
2125 we have already done it, we can just use an offset of four. */
2126 /* ??? This is taken from rs6000.c I think. I don't think it is
2127 currently necessary, but keep it around. */
2128 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
2129 || GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
2130 output_address (plus_constant (XEXP (XEXP (x
, 0), 0), 4));
2132 output_address (plus_constant (XEXP (x
, 0), 4));
2136 output_operand_lossage ("invalid operand to %%R code");
2139 case 'H' : /* High word. */
2140 case 'L' : /* Low word. */
2141 if (GET_CODE (x
) == REG
)
2143 /* L = least significant word, H = most significant word. */
2144 if ((WORDS_BIG_ENDIAN
!= 0) ^ (code
== 'L'))
2145 fputs (reg_names
[REGNO (x
)], file
);
2147 fputs (reg_names
[REGNO (x
)+1], file
);
2149 else if (GET_CODE (x
) == CONST_INT
2150 || GET_CODE (x
) == CONST_DOUBLE
)
2154 split_double (x
, &first
, &second
);
2155 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
,
2156 code
== 'L' ? INTVAL (first
) : INTVAL (second
));
2159 output_operand_lossage ("invalid operand to %%H/%%L code");
2166 if (GET_CODE (x
) != CONST_DOUBLE
2167 || GET_MODE_CLASS (GET_MODE (x
)) != MODE_FLOAT
)
2168 fatal_insn ("bad insn for 'A'", x
);
2170 real_to_decimal (str
, CONST_DOUBLE_REAL_VALUE (x
), sizeof (str
), 0, 1);
2171 fprintf (file
, "%s", str
);
2175 case 'B' : /* Bottom half. */
2176 case 'T' : /* Top half. */
2177 /* Output the argument to a `seth' insn (sets the Top half-word).
2178 For constants output arguments to a seth/or3 pair to set Top and
2179 Bottom halves. For symbols output arguments to a seth/add3 pair to
2180 set Top and Bottom halves. The difference exists because for
2181 constants seth/or3 is more readable but for symbols we need to use
2182 the same scheme as `ld' and `st' insns (16 bit addend is signed). */
2183 switch (GET_CODE (x
))
2190 split_double (x
, &first
, &second
);
2191 x
= WORDS_BIG_ENDIAN
? second
: first
;
2192 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
,
2194 ? INTVAL (x
) & 0xffff
2195 : (INTVAL (x
) >> 16) & 0xffff));
2201 && small_data_operand (x
, VOIDmode
))
2203 fputs ("sda(", file
);
2204 output_addr_const (file
, x
);
2210 fputs (code
== 'T' ? "shigh(" : "low(", file
);
2211 output_addr_const (file
, x
);
2215 output_operand_lossage ("invalid operand to %%T/%%B code");
2222 /* Output a load/store with update indicator if appropriate. */
2223 if (GET_CODE (x
) == MEM
)
2225 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
2226 || GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
2230 output_operand_lossage ("invalid operand to %%U code");
2234 /* Print a constant value negated. */
2235 if (GET_CODE (x
) == CONST_INT
)
2236 output_addr_const (file
, GEN_INT (- INTVAL (x
)));
2238 output_operand_lossage ("invalid operand to %%N code");
2242 /* Print a const_int in hex. Used in comments. */
2243 if (GET_CODE (x
) == CONST_INT
)
2244 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, INTVAL (x
));
2248 fputs (IMMEDIATE_PREFIX
, file
);
2252 /* Do nothing special. */
2257 output_operand_lossage ("invalid operand output code");
2260 switch (GET_CODE (x
))
2263 fputs (reg_names
[REGNO (x
)], file
);
2268 if (GET_CODE (addr
) == PRE_INC
)
2270 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2271 fatal_insn ("pre-increment address is not a register", x
);
2273 fprintf (file
, "@+%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2275 else if (GET_CODE (addr
) == PRE_DEC
)
2277 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2278 fatal_insn ("pre-decrement address is not a register", x
);
2280 fprintf (file
, "@-%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2282 else if (GET_CODE (addr
) == POST_INC
)
2284 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2285 fatal_insn ("post-increment address is not a register", x
);
2287 fprintf (file
, "@%s+", reg_names
[REGNO (XEXP (addr
, 0))]);
2292 output_address (XEXP (x
, 0));
2298 /* We handle SFmode constants here as output_addr_const doesn't. */
2299 if (GET_MODE (x
) == SFmode
)
2304 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
2305 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2306 fprintf (file
, "0x%08lx", l
);
2310 /* Fall through. Let output_addr_const deal with it. */
2313 output_addr_const (file
, x
);
2318 /* Print a memory address as an operand to reference that memory location. */
2321 m32r_print_operand_address (FILE * file
, rtx addr
)
2327 switch (GET_CODE (addr
))
2330 fputs (reg_names
[REGNO (addr
)], file
);
2334 if (GET_CODE (XEXP (addr
, 0)) == CONST_INT
)
2335 offset
= INTVAL (XEXP (addr
, 0)), base
= XEXP (addr
, 1);
2336 else if (GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
2337 offset
= INTVAL (XEXP (addr
, 1)), base
= XEXP (addr
, 0);
2339 base
= XEXP (addr
, 0), index
= XEXP (addr
, 1);
2340 if (GET_CODE (base
) == REG
)
2342 /* Print the offset first (if present) to conform to the manual. */
2346 fprintf (file
, "%d,", offset
);
2347 fputs (reg_names
[REGNO (base
)], file
);
2349 /* The chip doesn't support this, but left in for generality. */
2350 else if (GET_CODE (index
) == REG
)
2351 fprintf (file
, "%s,%s",
2352 reg_names
[REGNO (base
)], reg_names
[REGNO (index
)]);
2353 /* Not sure this can happen, but leave in for now. */
2354 else if (GET_CODE (index
) == SYMBOL_REF
)
2356 output_addr_const (file
, index
);
2358 fputs (reg_names
[REGNO (base
)], file
);
2361 fatal_insn ("bad address", addr
);
2363 else if (GET_CODE (base
) == LO_SUM
)
2366 || GET_CODE (XEXP (base
, 0)) != REG
)
2368 if (small_data_operand (XEXP (base
, 1), VOIDmode
))
2369 fputs ("sda(", file
);
2371 fputs ("low(", file
);
2372 output_addr_const (file
, plus_constant (XEXP (base
, 1), offset
));
2374 fputs (reg_names
[REGNO (XEXP (base
, 0))], file
);
2377 fatal_insn ("bad address", addr
);
2381 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2382 fatal_insn ("lo_sum not of register", addr
);
2383 if (small_data_operand (XEXP (addr
, 1), VOIDmode
))
2384 fputs ("sda(", file
);
2386 fputs ("low(", file
);
2387 output_addr_const (file
, XEXP (addr
, 1));
2389 fputs (reg_names
[REGNO (XEXP (addr
, 0))], file
);
2392 case PRE_INC
: /* Assume SImode. */
2393 fprintf (file
, "+%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2396 case PRE_DEC
: /* Assume SImode. */
2397 fprintf (file
, "-%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2400 case POST_INC
: /* Assume SImode. */
2401 fprintf (file
, "%s+", reg_names
[REGNO (XEXP (addr
, 0))]);
2405 output_addr_const (file
, addr
);
2410 /* Return true if the operands are the constants 0 and 1. */
2413 zero_and_one (rtx operand1
, rtx operand2
)
2416 GET_CODE (operand1
) == CONST_INT
2417 && GET_CODE (operand2
) == CONST_INT
2418 && ( ((INTVAL (operand1
) == 0) && (INTVAL (operand2
) == 1))
2419 ||((INTVAL (operand1
) == 1) && (INTVAL (operand2
) == 0)));
2422 /* Return nonzero if the operand is suitable for use in a conditional move sequence. */
2425 conditional_move_operand (rtx operand
, enum machine_mode mode
)
2427 /* Only defined for simple integers so far... */
2428 if (mode
!= SImode
&& mode
!= HImode
&& mode
!= QImode
)
2431 /* At the moment we can handle moving registers and loading constants. */
2432 /* To be added: Addition/subtraction/bitops/multiplication of registers. */
2434 switch (GET_CODE (operand
))
2440 return INT8_P (INTVAL (operand
));
2444 fprintf (stderr
, "Test for cond move op of type: %s\n",
2445 GET_RTX_NAME (GET_CODE (operand
)));
2451 /* Return true if the code is a test of the carry bit. */
2454 carry_compare_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2458 if (GET_MODE (op
) != CCmode
&& GET_MODE (op
) != VOIDmode
)
2461 if (GET_CODE (op
) != NE
&& GET_CODE (op
) != EQ
)
2465 if (GET_CODE (x
) != REG
|| REGNO (x
) != CARRY_REGNUM
)
2469 if (GET_CODE (x
) != CONST_INT
|| INTVAL (x
) != 0)
2475 /* Generate the correct assembler code to handle the conditional loading of a
2476 value into a register. It is known that the operands satisfy the
2477 conditional_move_operand() function above. The destination is operand[0].
2478 The condition is operand [1]. The 'true' value is operand [2] and the
2479 'false' value is operand [3]. */
2482 emit_cond_move (rtx
* operands
, rtx insn ATTRIBUTE_UNUSED
)
2484 static char buffer
[100];
2485 const char * dest
= reg_names
[REGNO (operands
[0])];
2489 /* Destination must be a register. */
2490 if (GET_CODE (operands
[0]) != REG
)
2492 if (! conditional_move_operand (operands
[2], SImode
))
2494 if (! conditional_move_operand (operands
[3], SImode
))
2497 /* Check to see if the test is reversed. */
2498 if (GET_CODE (operands
[1]) == NE
)
2500 rtx tmp
= operands
[2];
2501 operands
[2] = operands
[3];
2505 sprintf (buffer
, "mvfc %s, cbr", dest
);
2507 /* If the true value was '0' then we need to invert the results of the move. */
2508 if (INTVAL (operands
[2]) == 0)
2509 sprintf (buffer
+ strlen (buffer
), "\n\txor3 %s, %s, #1",
2515 /* Returns true if the registers contained in the two
2516 rtl expressions are different. */
2519 m32r_not_same_reg (rtx a
, rtx b
)
2524 while (GET_CODE (a
) == SUBREG
)
2527 if (GET_CODE (a
) == REG
)
2530 while (GET_CODE (b
) == SUBREG
)
2533 if (GET_CODE (b
) == REG
)
2536 return reg_a
!= reg_b
;
2541 m32r_function_symbol (const char *name
)
2543 int extra_flags
= 0;
2544 enum m32r_model model
;
2545 rtx sym
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2547 if (TARGET_MODEL_SMALL
)
2548 model
= M32R_MODEL_SMALL
;
2549 else if (TARGET_MODEL_MEDIUM
)
2550 model
= M32R_MODEL_MEDIUM
;
2551 else if (TARGET_MODEL_LARGE
)
2552 model
= M32R_MODEL_LARGE
;
2554 abort (); /* Shouldn't happen. */
2555 extra_flags
|= model
<< SYMBOL_FLAG_MODEL_SHIFT
;
2558 SYMBOL_REF_FLAGS (sym
) |= extra_flags
;
2563 /* Use a library function to move some bytes. */
2566 block_move_call (rtx dest_reg
, rtx src_reg
, rtx bytes_rtx
)
2568 /* We want to pass the size as Pmode, which will normally be SImode
2569 but will be DImode if we are using 64 bit longs and pointers. */
2570 if (GET_MODE (bytes_rtx
) != VOIDmode
2571 && GET_MODE (bytes_rtx
) != Pmode
)
2572 bytes_rtx
= convert_to_mode (Pmode
, bytes_rtx
, 1);
2574 emit_library_call (m32r_function_symbol ("memcpy"), 0,
2575 VOIDmode
, 3, dest_reg
, Pmode
, src_reg
, Pmode
,
2576 convert_to_mode (TYPE_MODE (sizetype
), bytes_rtx
,
2577 TYPE_UNSIGNED (sizetype
)),
2578 TYPE_MODE (sizetype
));
2581 /* The maximum number of bytes to copy using pairs of load/store instructions.
2582 If a block is larger than this then a loop will be generated to copy
2583 MAX_MOVE_BYTES chunks at a time. The value of 32 is a semi-arbitrary choice.
2584 A customer uses Dhrystome as their benchmark, and Dhrystone has a 31 byte
2585 string copy in it. */
2586 #define MAX_MOVE_BYTES 32
2588 /* Expand string/block move operations.
2590 operands[0] is the pointer to the destination.
2591 operands[1] is the pointer to the source.
2592 operands[2] is the number of bytes to move.
2593 operands[3] is the alignment. */
2596 m32r_expand_block_move (rtx operands
[])
2598 rtx orig_dst
= operands
[0];
2599 rtx orig_src
= operands
[1];
2600 rtx bytes_rtx
= operands
[2];
2601 rtx align_rtx
= operands
[3];
2602 int constp
= GET_CODE (bytes_rtx
) == CONST_INT
;
2603 HOST_WIDE_INT bytes
= constp
? INTVAL (bytes_rtx
) : 0;
2604 int align
= INTVAL (align_rtx
);
2609 if (constp
&& bytes
<= 0)
2612 /* Move the address into scratch registers. */
2613 dst_reg
= copy_addr_to_reg (XEXP (orig_dst
, 0));
2614 src_reg
= copy_addr_to_reg (XEXP (orig_src
, 0));
2616 if (align
> UNITS_PER_WORD
)
2617 align
= UNITS_PER_WORD
;
2619 /* If we prefer size over speed, always use a function call.
2620 If we do not know the size, use a function call.
2621 If the blocks are not word aligned, use a function call. */
2622 if (optimize_size
|| ! constp
|| align
!= UNITS_PER_WORD
)
2624 block_move_call (dst_reg
, src_reg
, bytes_rtx
);
2628 leftover
= bytes
% MAX_MOVE_BYTES
;
2631 /* If necessary, generate a loop to handle the bulk of the copy. */
2634 rtx label
= NULL_RTX
;
2635 rtx final_src
= NULL_RTX
;
2636 rtx at_a_time
= GEN_INT (MAX_MOVE_BYTES
);
2637 rtx rounded_total
= GEN_INT (bytes
);
2638 rtx new_dst_reg
= gen_reg_rtx (SImode
);
2639 rtx new_src_reg
= gen_reg_rtx (SImode
);
2641 /* If we are going to have to perform this loop more than
2642 once, then generate a label and compute the address the
2643 source register will contain upon completion of the final
2645 if (bytes
> MAX_MOVE_BYTES
)
2647 final_src
= gen_reg_rtx (Pmode
);
2650 emit_insn (gen_addsi3 (final_src
, src_reg
, rounded_total
));
2653 emit_insn (gen_movsi (final_src
, rounded_total
));
2654 emit_insn (gen_addsi3 (final_src
, final_src
, src_reg
));
2657 label
= gen_label_rtx ();
2661 /* It is known that output_block_move() will update src_reg to point
2662 to the word after the end of the source block, and dst_reg to point
2663 to the last word of the destination block, provided that the block
2664 is MAX_MOVE_BYTES long. */
2665 emit_insn (gen_movmemsi_internal (dst_reg
, src_reg
, at_a_time
,
2666 new_dst_reg
, new_src_reg
));
2667 emit_move_insn (dst_reg
, new_dst_reg
);
2668 emit_move_insn (src_reg
, new_src_reg
);
2669 emit_insn (gen_addsi3 (dst_reg
, dst_reg
, GEN_INT (4)));
2671 if (bytes
> MAX_MOVE_BYTES
)
2673 emit_insn (gen_cmpsi (src_reg
, final_src
));
2674 emit_jump_insn (gen_bne (label
));
2679 emit_insn (gen_movmemsi_internal (dst_reg
, src_reg
, GEN_INT (leftover
),
2680 gen_reg_rtx (SImode
),
2681 gen_reg_rtx (SImode
)));
2685 /* Emit load/stores for a small constant word aligned block_move.
2687 operands[0] is the memory address of the destination.
2688 operands[1] is the memory address of the source.
2689 operands[2] is the number of bytes to move.
2690 operands[3] is a temp register.
2691 operands[4] is a temp register. */
2694 m32r_output_block_move (rtx insn ATTRIBUTE_UNUSED
, rtx operands
[])
2696 HOST_WIDE_INT bytes
= INTVAL (operands
[2]);
2700 if (bytes
< 1 || bytes
> MAX_MOVE_BYTES
)
2703 /* We do not have a post-increment store available, so the first set of
2704 stores are done without any increment, then the remaining ones can use
2705 the pre-increment addressing mode.
2707 Note: expand_block_move() also relies upon this behavior when building
2708 loops to copy large blocks. */
2717 output_asm_insn ("ld\t%5, %p1", operands
);
2718 output_asm_insn ("ld\t%6, %p1", operands
);
2719 output_asm_insn ("st\t%5, @%0", operands
);
2720 output_asm_insn ("st\t%6, %s0", operands
);
2724 output_asm_insn ("ld\t%5, %p1", operands
);
2725 output_asm_insn ("ld\t%6, %p1", operands
);
2726 output_asm_insn ("st\t%5, %s0", operands
);
2727 output_asm_insn ("st\t%6, %s0", operands
);
2732 else if (bytes
>= 4)
2737 output_asm_insn ("ld\t%5, %p1", operands
);
2740 output_asm_insn ("ld\t%6, %p1", operands
);
2743 output_asm_insn ("st\t%5, @%0", operands
);
2745 output_asm_insn ("st\t%5, %s0", operands
);
2751 /* Get the entire next word, even though we do not want all of it.
2752 The saves us from doing several smaller loads, and we assume that
2753 we cannot cause a page fault when at least part of the word is in
2754 valid memory [since we don't get called if things aren't properly
2756 int dst_offset
= first_time
? 0 : 4;
2757 /* The amount of increment we have to make to the
2758 destination pointer. */
2759 int dst_inc_amount
= dst_offset
+ bytes
- 4;
2760 /* The same for the source pointer. */
2761 int src_inc_amount
= bytes
;
2765 /* If got_extra is true then we have already loaded
2766 the next word as part of loading and storing the previous word. */
2768 output_asm_insn ("ld\t%6, @%1", operands
);
2774 output_asm_insn ("sra3\t%5, %6, #16", operands
);
2775 my_operands
[0] = operands
[5];
2776 my_operands
[1] = GEN_INT (dst_offset
);
2777 my_operands
[2] = operands
[0];
2778 output_asm_insn ("sth\t%0, @(%1,%2)", my_operands
);
2780 /* If there is a byte left to store then increment the
2781 destination address and shift the contents of the source
2782 register down by 8 bits. We could not do the address
2783 increment in the store half word instruction, because it does
2784 not have an auto increment mode. */
2785 if (bytes
> 0) /* assert (bytes == 1) */
2796 my_operands
[0] = operands
[6];
2797 my_operands
[1] = GEN_INT (last_shift
);
2798 output_asm_insn ("srai\t%0, #%1", my_operands
);
2799 my_operands
[0] = operands
[6];
2800 my_operands
[1] = GEN_INT (dst_offset
);
2801 my_operands
[2] = operands
[0];
2802 output_asm_insn ("stb\t%0, @(%1,%2)", my_operands
);
2805 /* Update the destination pointer if needed. We have to do
2806 this so that the patterns matches what we output in this
2809 && !find_reg_note (insn
, REG_UNUSED
, operands
[0]))
2811 my_operands
[0] = operands
[0];
2812 my_operands
[1] = GEN_INT (dst_inc_amount
);
2813 output_asm_insn ("addi\t%0, #%1", my_operands
);
2816 /* Update the source pointer if needed. We have to do this
2817 so that the patterns matches what we output in this
2820 && !find_reg_note (insn
, REG_UNUSED
, operands
[1]))
2822 my_operands
[0] = operands
[1];
2823 my_operands
[1] = GEN_INT (src_inc_amount
);
2824 output_asm_insn ("addi\t%0, #%1", my_operands
);
2834 /* Return true if op is an integer constant, less than or equal to
2838 m32r_block_immediate_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
2840 if (GET_CODE (op
) != CONST_INT
2841 || INTVAL (op
) > MAX_MOVE_BYTES
2842 || INTVAL (op
) <= 0)
2848 /* Return true if using NEW_REG in place of OLD_REG is ok. */
2851 m32r_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
2852 unsigned int new_reg
)
2854 /* Interrupt routines can't clobber any register that isn't already used. */
2855 if (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl
))
2856 && !regs_ever_live
[new_reg
])
2859 /* We currently emit epilogues as text, not rtl, so the liveness
2860 of the return address register isn't visible. */
2861 if (current_function_is_leaf
&& new_reg
== RETURN_ADDR_REGNUM
)
2868 m32r_return_addr (int count
)
2873 return get_hard_reg_initial_val (Pmode
, RETURN_ADDR_REGNUM
);