This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / gcc / config / m32r / m32r.c
bloba1d63fbdbf114e2311471fdf69f2939a0445f50d
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. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "regs.h"
29 #include "hard-reg-set.h"
30 #include "real.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "output.h"
34 #include "insn-attr.h"
35 #include "flags.h"
36 #include "expr.h"
37 #include "function.h"
38 #include "recog.h"
39 #include "toplev.h"
40 #include "ggc.h"
41 #include "tm_p.h"
42 #include "target.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 /* Scheduler support */
61 static int m32r_sched_odd_word_p;
63 /* Machine-specific symbol_ref flags. */
64 #define SYMBOL_FLAG_MODEL_SHIFT SYMBOL_FLAG_MACH_DEP_SHIFT
65 #define SYMBOL_REF_MODEL(X) \
66 ((enum m32r_model) ((SYMBOL_REF_FLAGS (X) >> SYMBOL_FLAG_MODEL_SHIFT) & 3))
68 /* For string literals, etc. */
69 #define LIT_NAME_P(NAME) ((NAME)[0] == '*' && (NAME)[1] == '.')
71 /* Cache-flush support. Cache-flush is used at trampoline.
72 Default cache-flush is "trap 12".
73 default cache-flush function is "_flush_cache" (CACHE_FLUSH_FUNC)
74 default cache-flush trap-interrupt number is "12". (CACHE_FLUSH_TRAP)
75 You can change how to generate code of cache-flush with following options.
76 -flush-func=FLUSH-FUNC-NAME
77 -no-flush-func
78 -fluch-trap=TRAP-NUMBER
79 -no-flush-trap. */
80 const char *m32r_cache_flush_func = CACHE_FLUSH_FUNC;
81 const char *m32r_cache_flush_trap_string = CACHE_FLUSH_TRAP;
82 int m32r_cache_flush_trap = 12;
84 /* Forward declaration. */
85 static void init_reg_tables (void);
86 static void block_move_call (rtx, rtx, rtx);
87 static int m32r_is_insn (rtx);
88 const struct attribute_spec m32r_attribute_table[];
89 static tree m32r_handle_model_attribute (tree *, tree, tree, int, bool *);
90 static void m32r_output_function_prologue (FILE *, HOST_WIDE_INT);
91 static void m32r_output_function_epilogue (FILE *, HOST_WIDE_INT);
93 static void m32r_file_start (void);
95 static int m32r_adjust_cost (rtx, rtx, rtx, int);
96 static int m32r_adjust_priority (rtx, int);
97 static void m32r_sched_init (FILE *, int, int);
98 static int m32r_sched_reorder (FILE *, int, rtx *, int *, int);
99 static int m32r_variable_issue (FILE *, int, rtx, int);
100 static int m32r_issue_rate (void);
102 static void m32r_encode_section_info (tree, rtx, int);
103 static bool m32r_in_small_data_p (tree);
104 static void init_idents (void);
105 static bool m32r_rtx_costs (rtx, int, int, int *);
107 /* Initialize the GCC target structure. */
108 #undef TARGET_ATTRIBUTE_TABLE
109 #define TARGET_ATTRIBUTE_TABLE m32r_attribute_table
111 #undef TARGET_ASM_ALIGNED_HI_OP
112 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
113 #undef TARGET_ASM_ALIGNED_SI_OP
114 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
116 #undef TARGET_ASM_FUNCTION_PROLOGUE
117 #define TARGET_ASM_FUNCTION_PROLOGUE m32r_output_function_prologue
118 #undef TARGET_ASM_FUNCTION_EPILOGUE
119 #define TARGET_ASM_FUNCTION_EPILOGUE m32r_output_function_epilogue
121 #undef TARGET_ASM_FILE_START
122 #define TARGET_ASM_FILE_START m32r_file_start
124 #undef TARGET_SCHED_ADJUST_COST
125 #define TARGET_SCHED_ADJUST_COST m32r_adjust_cost
126 #undef TARGET_SCHED_ADJUST_PRIORITY
127 #define TARGET_SCHED_ADJUST_PRIORITY m32r_adjust_priority
128 #undef TARGET_SCHED_ISSUE_RATE
129 #define TARGET_SCHED_ISSUE_RATE m32r_issue_rate
130 #undef TARGET_SCHED_VARIABLE_ISSUE
131 #define TARGET_SCHED_VARIABLE_ISSUE m32r_variable_issue
132 #undef TARGET_SCHED_INIT
133 #define TARGET_SCHED_INIT m32r_sched_init
134 #undef TARGET_SCHED_REORDER
135 #define TARGET_SCHED_REORDER m32r_sched_reorder
137 #undef TARGET_ENCODE_SECTION_INFO
138 #define TARGET_ENCODE_SECTION_INFO m32r_encode_section_info
139 #undef TARGET_IN_SMALL_DATA_P
140 #define TARGET_IN_SMALL_DATA_P m32r_in_small_data_p
142 #undef TARGET_RTX_COSTS
143 #define TARGET_RTX_COSTS m32r_rtx_costs
144 #undef TARGET_ADDRESS_COST
145 #define TARGET_ADDRESS_COST hook_int_rtx_0
147 struct gcc_target targetm = TARGET_INITIALIZER;
149 /* Called by OVERRIDE_OPTIONS to initialize various things. */
151 void
152 m32r_init (void)
154 init_reg_tables ();
156 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
157 memset (m32r_punct_chars, 0, sizeof (m32r_punct_chars));
158 m32r_punct_chars['#'] = 1;
159 m32r_punct_chars['@'] = 1; /* ??? no longer used */
161 /* Provide default value if not specified. */
162 if (!g_switch_set)
163 g_switch_value = SDATA_DEFAULT_SIZE;
165 if (strcmp (m32r_model_string, "small") == 0)
166 m32r_model = M32R_MODEL_SMALL;
167 else if (strcmp (m32r_model_string, "medium") == 0)
168 m32r_model = M32R_MODEL_MEDIUM;
169 else if (strcmp (m32r_model_string, "large") == 0)
170 m32r_model = M32R_MODEL_LARGE;
171 else
172 error ("bad value (%s) for -mmodel switch", m32r_model_string);
174 if (strcmp (m32r_sdata_string, "none") == 0)
175 m32r_sdata = M32R_SDATA_NONE;
176 else if (strcmp (m32r_sdata_string, "sdata") == 0)
177 m32r_sdata = M32R_SDATA_SDATA;
178 else if (strcmp (m32r_sdata_string, "use") == 0)
179 m32r_sdata = M32R_SDATA_USE;
180 else
181 error ("bad value (%s) for -msdata switch", m32r_sdata_string);
183 if (m32r_cache_flush_trap_string)
185 /* Change trap-number (12) for cache-flush to the others (0 - 15). */
186 m32r_cache_flush_trap = atoi (m32r_cache_flush_trap_string);
187 if (m32r_cache_flush_trap < 0 || m32r_cache_flush_trap > 15)
188 error ("bad value (%s) for -flush-trap=n (0=<n<=15)",
189 m32r_cache_flush_trap_string);
193 /* Vectors to keep interesting information about registers where it can easily
194 be got. We use to use the actual mode value as the bit number, but there
195 is (or may be) more than 32 modes now. Instead we use two tables: one
196 indexed by hard register number, and one indexed by mode. */
198 /* The purpose of m32r_mode_class is to shrink the range of modes so that
199 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
200 mapped into one m32r_mode_class mode. */
202 enum m32r_mode_class
204 C_MODE,
205 S_MODE, D_MODE, T_MODE, O_MODE,
206 SF_MODE, DF_MODE, TF_MODE, OF_MODE, A_MODE
209 /* Modes for condition codes. */
210 #define C_MODES (1 << (int) C_MODE)
212 /* Modes for single-word and smaller quantities. */
213 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
215 /* Modes for double-word and smaller quantities. */
216 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
218 /* Modes for quad-word and smaller quantities. */
219 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
221 /* Modes for accumulators. */
222 #define A_MODES (1 << (int) A_MODE)
224 /* Value is 1 if register/mode pair is acceptable on arc. */
226 const unsigned int m32r_hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] =
228 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, T_MODES,
229 T_MODES, T_MODES, T_MODES, T_MODES, T_MODES, S_MODES, S_MODES, S_MODES,
230 S_MODES, C_MODES, A_MODES, A_MODES
233 unsigned int m32r_mode_class [NUM_MACHINE_MODES];
235 enum reg_class m32r_regno_reg_class[FIRST_PSEUDO_REGISTER];
237 static void
238 init_reg_tables (void)
240 int i;
242 for (i = 0; i < NUM_MACHINE_MODES; i++)
244 switch (GET_MODE_CLASS (i))
246 case MODE_INT:
247 case MODE_PARTIAL_INT:
248 case MODE_COMPLEX_INT:
249 if (GET_MODE_SIZE (i) <= 4)
250 m32r_mode_class[i] = 1 << (int) S_MODE;
251 else if (GET_MODE_SIZE (i) == 8)
252 m32r_mode_class[i] = 1 << (int) D_MODE;
253 else if (GET_MODE_SIZE (i) == 16)
254 m32r_mode_class[i] = 1 << (int) T_MODE;
255 else if (GET_MODE_SIZE (i) == 32)
256 m32r_mode_class[i] = 1 << (int) O_MODE;
257 else
258 m32r_mode_class[i] = 0;
259 break;
260 case MODE_FLOAT:
261 case MODE_COMPLEX_FLOAT:
262 if (GET_MODE_SIZE (i) <= 4)
263 m32r_mode_class[i] = 1 << (int) SF_MODE;
264 else if (GET_MODE_SIZE (i) == 8)
265 m32r_mode_class[i] = 1 << (int) DF_MODE;
266 else if (GET_MODE_SIZE (i) == 16)
267 m32r_mode_class[i] = 1 << (int) TF_MODE;
268 else if (GET_MODE_SIZE (i) == 32)
269 m32r_mode_class[i] = 1 << (int) OF_MODE;
270 else
271 m32r_mode_class[i] = 0;
272 break;
273 case MODE_CC:
274 m32r_mode_class[i] = 1 << (int) C_MODE;
275 break;
276 default:
277 m32r_mode_class[i] = 0;
278 break;
282 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
284 if (GPR_P (i))
285 m32r_regno_reg_class[i] = GENERAL_REGS;
286 else if (i == ARG_POINTER_REGNUM)
287 m32r_regno_reg_class[i] = GENERAL_REGS;
288 else
289 m32r_regno_reg_class[i] = NO_REGS;
293 /* M32R specific attribute support.
295 interrupt - for interrupt functions
297 model - select code model used to access object
299 small: addresses use 24 bits, use bl to make calls
300 medium: addresses use 32 bits, use bl to make calls
301 large: addresses use 32 bits, use seth/add3/jl to make calls
303 Grep for MODEL in m32r.h for more info. */
305 static tree small_ident1;
306 static tree small_ident2;
307 static tree medium_ident1;
308 static tree medium_ident2;
309 static tree large_ident1;
310 static tree large_ident2;
312 static void
313 init_idents (void)
315 if (small_ident1 == 0)
317 small_ident1 = get_identifier ("small");
318 small_ident2 = get_identifier ("__small__");
319 medium_ident1 = get_identifier ("medium");
320 medium_ident2 = get_identifier ("__medium__");
321 large_ident1 = get_identifier ("large");
322 large_ident2 = get_identifier ("__large__");
326 const struct attribute_spec m32r_attribute_table[] =
328 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
329 { "interrupt", 0, 0, true, false, false, NULL },
330 { "model", 1, 1, true, false, false, m32r_handle_model_attribute },
331 { NULL, 0, 0, false, false, false, NULL }
335 /* Handle an "model" attribute; arguments as in
336 struct attribute_spec.handler. */
337 static tree
338 m32r_handle_model_attribute (tree *node ATTRIBUTE_UNUSED, tree name,
339 tree args, int flags ATTRIBUTE_UNUSED,
340 bool *no_add_attrs)
342 tree arg;
344 init_idents ();
345 arg = TREE_VALUE (args);
347 if (arg != small_ident1
348 && arg != small_ident2
349 && arg != medium_ident1
350 && arg != medium_ident2
351 && arg != large_ident1
352 && arg != large_ident2)
354 warning ("invalid argument of `%s' attribute",
355 IDENTIFIER_POINTER (name));
356 *no_add_attrs = true;
359 return NULL_TREE;
362 /* Encode section information of DECL, which is either a VAR_DECL,
363 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
365 For the M32R we want to record:
367 - whether the object lives in .sdata/.sbss.
368 - what code model should be used to access the object
371 static void
372 m32r_encode_section_info (tree decl, rtx rtl, int first)
374 int extra_flags = 0;
375 tree model_attr;
376 enum m32r_model model;
378 default_encode_section_info (decl, rtl, first);
380 if (!DECL_P (decl))
381 return;
383 model_attr = lookup_attribute ("model", DECL_ATTRIBUTES (decl));
384 if (model_attr)
386 tree id;
388 init_idents ();
390 id = TREE_VALUE (TREE_VALUE (model_attr));
392 if (id == small_ident1 || id == small_ident2)
393 model = M32R_MODEL_SMALL;
394 else if (id == medium_ident1 || id == medium_ident2)
395 model = M32R_MODEL_MEDIUM;
396 else if (id == large_ident1 || id == large_ident2)
397 model = M32R_MODEL_LARGE;
398 else
399 abort (); /* shouldn't happen */
401 else
403 if (TARGET_MODEL_SMALL)
404 model = M32R_MODEL_SMALL;
405 else if (TARGET_MODEL_MEDIUM)
406 model = M32R_MODEL_MEDIUM;
407 else if (TARGET_MODEL_LARGE)
408 model = M32R_MODEL_LARGE;
409 else
410 abort (); /* shouldn't happen */
412 extra_flags |= model << SYMBOL_FLAG_MODEL_SHIFT;
414 if (extra_flags)
415 SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= extra_flags;
418 /* Only mark the object as being small data area addressable if
419 it hasn't been explicitly marked with a code model.
421 The user can explicitly put an object in the small data area with the
422 section attribute. If the object is in sdata/sbss and marked with a
423 code model do both [put the object in .sdata and mark it as being
424 addressed with a specific code model - don't mark it as being addressed
425 with an SDA reloc though]. This is ok and might be useful at times. If
426 the object doesn't fit the linker will give an error. */
428 static bool
429 m32r_in_small_data_p (tree decl)
431 tree section;
433 if (TREE_CODE (decl) != VAR_DECL)
434 return false;
436 if (lookup_attribute ("model", DECL_ATTRIBUTES (decl)))
437 return false;
439 section = DECL_SECTION_NAME (decl);
440 if (section)
442 char *name = (char *) TREE_STRING_POINTER (section);
443 if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
444 return true;
446 else
448 if (! TREE_READONLY (decl) && ! TARGET_SDATA_NONE)
450 int size = int_size_in_bytes (TREE_TYPE (decl));
452 if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
453 return true;
457 return false;
460 /* Do anything needed before RTL is emitted for each function. */
462 void
463 m32r_init_expanders (void)
465 /* ??? At one point there was code here. The function is left in
466 to make it easy to experiment. */
469 /* Acceptable arguments to the call insn. */
472 call_address_operand (rtx op, enum machine_mode mode)
474 return symbolic_operand (op, mode);
476 /* Constants and values in registers are not OK, because
477 the m32r BL instruction can only support PC relative branching. */
481 call_operand (rtx op, enum machine_mode mode)
483 if (GET_CODE (op) != MEM)
484 return 0;
485 op = XEXP (op, 0);
486 return call_address_operand (op, mode);
489 /* Returns 1 if OP is a symbol reference. */
492 symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
494 switch (GET_CODE (op))
496 case SYMBOL_REF:
497 case LABEL_REF:
498 case CONST :
499 return 1;
501 default:
502 return 0;
506 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
509 small_data_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
511 if (! TARGET_SDATA_USE)
512 return 0;
514 if (GET_CODE (op) == SYMBOL_REF)
515 return SYMBOL_REF_SMALL_P (op);
517 if (GET_CODE (op) == CONST
518 && GET_CODE (XEXP (op, 0)) == PLUS
519 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
520 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
521 && INT16_P (INTVAL (XEXP (XEXP (op, 0), 1))))
522 return SYMBOL_REF_SMALL_P (XEXP (XEXP (op, 0), 0));
524 return 0;
527 /* Return 1 if OP is a symbol that can use 24 bit addressing. */
530 addr24_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
532 rtx sym;
534 if (flag_pic)
535 return 0;
537 if (GET_CODE (op) == LABEL_REF)
538 return TARGET_ADDR24;
540 if (GET_CODE (op) == SYMBOL_REF)
541 sym = op;
542 else if (GET_CODE (op) == CONST
543 && GET_CODE (XEXP (op, 0)) == PLUS
544 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
545 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
546 && UINT24_P (INTVAL (XEXP (XEXP (op, 0), 1))))
547 sym = XEXP (XEXP (op, 0), 0);
548 else
549 return 0;
551 if (SYMBOL_REF_MODEL (sym) == M32R_MODEL_SMALL)
552 return 1;
554 if (TARGET_ADDR24
555 && (CONSTANT_POOL_ADDRESS_P (sym)
556 || LIT_NAME_P (XSTR (sym, 0))))
557 return 1;
559 return 0;
562 /* Return 1 if OP is a symbol that needs 32 bit addressing. */
565 addr32_operand (rtx op, enum machine_mode mode)
567 rtx sym;
569 if (GET_CODE (op) == LABEL_REF)
570 return TARGET_ADDR32;
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 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
578 && ! flag_pic)
579 sym = XEXP (XEXP (op, 0), 0);
580 else
581 return 0;
583 return (! addr24_operand (sym, mode)
584 && ! small_data_operand (sym, mode));
587 /* Return 1 if OP is a function that can be called with the `bl' insn. */
590 call26_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
592 if (flag_pic)
593 return 1;
595 if (GET_CODE (op) == SYMBOL_REF)
596 return SYMBOL_REF_MODEL (op) != M32R_MODEL_LARGE;
598 return TARGET_CALL26;
601 /* Returns 1 if OP is an acceptable operand for seth/add3. */
604 seth_add3_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
606 if (flag_pic)
607 return 0;
609 if (GET_CODE (op) == SYMBOL_REF
610 || GET_CODE (op) == LABEL_REF)
611 return 1;
613 if (GET_CODE (op) == CONST
614 && GET_CODE (XEXP (op, 0)) == PLUS
615 && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF
616 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT
617 && INT16_P (INTVAL (XEXP (XEXP (op, 0), 1))))
618 return 1;
620 return 0;
623 /* Return true if OP is a signed 8 bit immediate value. */
626 int8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
628 if (GET_CODE (op) != CONST_INT)
629 return 0;
630 return INT8_P (INTVAL (op));
633 /* Return true if OP is a signed 16 bit immediate value
634 useful in comparisons. */
637 cmp_int16_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
639 if (GET_CODE (op) != CONST_INT)
640 return 0;
641 return CMP_INT16_P (INTVAL (op));
644 /* Return true if OP is an unsigned 16 bit immediate value. */
647 uint16_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
649 if (GET_CODE (op) != CONST_INT)
650 return 0;
651 return UINT16_P (INTVAL (op));
654 /* Return true if OP is a register or signed 16 bit value. */
657 reg_or_int16_operand (rtx op, enum machine_mode mode)
659 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
660 return register_operand (op, mode);
661 if (GET_CODE (op) != CONST_INT)
662 return 0;
663 return INT16_P (INTVAL (op));
666 /* Return true if OP is a register or an unsigned 16 bit value. */
669 reg_or_uint16_operand (rtx op, enum machine_mode mode)
671 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
672 return register_operand (op, mode);
673 if (GET_CODE (op) != CONST_INT)
674 return 0;
675 return UINT16_P (INTVAL (op));
678 /* Return true if OP is a register or an integer value that can be
679 used is SEQ/SNE. We can use either XOR of the value or ADD of
680 the negative of the value for the constant. Don't allow 0,
681 because that is special cased. */
684 reg_or_eq_int16_operand (rtx op, enum machine_mode mode)
686 HOST_WIDE_INT value;
688 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
689 return register_operand (op, mode);
691 if (GET_CODE (op) != CONST_INT)
692 return 0;
694 value = INTVAL (op);
695 return (value != 0) && (UINT16_P (value) || CMP_INT16_P (-value));
698 /* Return true if OP is a register or signed 16 bit value for compares. */
701 reg_or_cmp_int16_operand (rtx op, enum machine_mode mode)
703 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
704 return register_operand (op, mode);
705 if (GET_CODE (op) != CONST_INT)
706 return 0;
707 return CMP_INT16_P (INTVAL (op));
710 /* Return true if OP is a register or the constant 0. */
713 reg_or_zero_operand (rtx op, enum machine_mode mode)
715 if (GET_CODE (op) == REG || GET_CODE (op) == SUBREG)
716 return register_operand (op, mode);
718 if (GET_CODE (op) != CONST_INT)
719 return 0;
721 return INTVAL (op) == 0;
724 /* Return true if OP is a const_int requiring two instructions to load. */
727 two_insn_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
729 if (GET_CODE (op) != CONST_INT)
730 return 0;
731 if (INT16_P (INTVAL (op))
732 || UINT24_P (INTVAL (op))
733 || UPPER16_P (INTVAL (op)))
734 return 0;
735 return 1;
738 /* Return true if OP is an acceptable argument for a single word
739 move source. */
742 move_src_operand (rtx op, enum machine_mode mode)
744 switch (GET_CODE (op))
746 case LABEL_REF :
747 case SYMBOL_REF :
748 case CONST :
749 return addr24_operand (op, mode);
750 case CONST_INT :
751 /* ??? We allow more cse opportunities if we only allow constants
752 loadable with one insn, and split the rest into two. The instances
753 where this would help should be rare and the current way is
754 simpler. */
755 if (HOST_BITS_PER_WIDE_INT > 32)
757 HOST_WIDE_INT rest = INTVAL (op) >> 31;
758 return (rest == 0 || rest == -1);
760 else
761 return 1;
762 case CONSTANT_P_RTX:
763 return 1;
764 case CONST_DOUBLE :
765 if (mode == SFmode)
766 return 1;
767 else if (mode == SImode)
769 /* Large unsigned constants are represented as const_double's. */
770 unsigned HOST_WIDE_INT low, high;
772 low = CONST_DOUBLE_LOW (op);
773 high = CONST_DOUBLE_HIGH (op);
774 return high == 0 && low <= (unsigned) 0xffffffff;
776 else
777 return 0;
778 case REG :
779 return register_operand (op, mode);
780 case SUBREG :
781 /* (subreg (mem ...) ...) can occur here if the inner part was once a
782 pseudo-reg and is now a stack slot. */
783 if (GET_CODE (SUBREG_REG (op)) == MEM)
784 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
785 else
786 return register_operand (op, mode);
787 case MEM :
788 if (GET_CODE (XEXP (op, 0)) == PRE_INC
789 || GET_CODE (XEXP (op, 0)) == PRE_DEC)
790 return 0; /* loads can't do pre-{inc,dec} */
791 return address_operand (XEXP (op, 0), mode);
792 default :
793 return 0;
797 /* Return true if OP is an acceptable argument for a double word
798 move source. */
801 move_double_src_operand (rtx op, enum machine_mode mode)
803 switch (GET_CODE (op))
805 case CONST_INT :
806 case CONST_DOUBLE :
807 return 1;
808 case REG :
809 return register_operand (op, mode);
810 case SUBREG :
811 /* (subreg (mem ...) ...) can occur here if the inner part was once a
812 pseudo-reg and is now a stack slot. */
813 if (GET_CODE (SUBREG_REG (op)) == MEM)
814 return move_double_src_operand (SUBREG_REG (op), mode);
815 else
816 return register_operand (op, mode);
817 case MEM :
818 /* Disallow auto inc/dec for now. */
819 if (GET_CODE (XEXP (op, 0)) == PRE_DEC
820 || GET_CODE (XEXP (op, 0)) == PRE_INC)
821 return 0;
822 return address_operand (XEXP (op, 0), mode);
823 default :
824 return 0;
828 /* Return true if OP is an acceptable argument for a move destination. */
831 move_dest_operand (rtx op, enum machine_mode mode)
833 switch (GET_CODE (op))
835 case REG :
836 return register_operand (op, mode);
837 case SUBREG :
838 /* (subreg (mem ...) ...) can occur here if the inner part was once a
839 pseudo-reg and is now a stack slot. */
840 if (GET_CODE (SUBREG_REG (op)) == MEM)
841 return address_operand (XEXP (SUBREG_REG (op), 0), mode);
842 else
843 return register_operand (op, mode);
844 case MEM :
845 if (GET_CODE (XEXP (op, 0)) == POST_INC)
846 return 0; /* stores can't do post inc */
847 return address_operand (XEXP (op, 0), mode);
848 default :
849 return 0;
853 /* Return 1 if OP is a DImode const we want to handle inline.
854 This must match the code in the movdi pattern.
855 It is used by the 'G' CONST_DOUBLE_OK_FOR_LETTER. */
858 easy_di_const (rtx op)
860 rtx high_rtx, low_rtx;
861 HOST_WIDE_INT high, low;
863 split_double (op, &high_rtx, &low_rtx);
864 high = INTVAL (high_rtx);
865 low = INTVAL (low_rtx);
866 /* Pick constants loadable with 2 16 bit `ldi' insns. */
867 if (high >= -128 && high <= 127
868 && low >= -128 && low <= 127)
869 return 1;
870 return 0;
873 /* Return 1 if OP is a DFmode const we want to handle inline.
874 This must match the code in the movdf pattern.
875 It is used by the 'H' CONST_DOUBLE_OK_FOR_LETTER. */
878 easy_df_const (rtx op)
880 REAL_VALUE_TYPE r;
881 long l[2];
883 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
884 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
885 if (l[0] == 0 && l[1] == 0)
886 return 1;
887 if ((l[0] & 0xffff) == 0 && l[1] == 0)
888 return 1;
889 return 0;
892 /* Return 1 if OP is an EQ or NE comparison operator. */
895 eqne_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
897 enum rtx_code code = GET_CODE (op);
899 if (GET_RTX_CLASS (code) != '<')
900 return 0;
901 return (code == EQ || code == NE);
904 /* Return 1 if OP is a signed comparison operator. */
907 signed_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
909 enum rtx_code code = GET_CODE (op);
911 if (GET_RTX_CLASS (code) != '<')
912 return 0;
913 return (code == EQ || code == NE
914 || code == LT || code == LE || code == GT || code == GE);
917 /* Return 1 if OP is (mem (reg ...)).
918 This is used in insn length calcs. */
921 memreg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
923 return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) == REG;
926 /* Return true if OP is an acceptable input argument for a zero/sign extend
927 operation. */
930 extend_operand (rtx op, enum machine_mode mode)
932 rtx addr;
934 switch (GET_CODE (op))
936 case REG :
937 case SUBREG :
938 return register_operand (op, mode);
940 case MEM :
941 addr = XEXP (op, 0);
942 if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
943 return 0; /* loads can't do pre inc/pre dec */
945 return address_operand (addr, mode);
947 default :
948 return 0;
952 /* Return nonzero if the operand is an insn that is a small insn.
953 Allow const_int 0 as well, which is a placeholder for NOP slots. */
956 small_insn_p (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
958 if (GET_CODE (op) == CONST_INT && INTVAL (op) == 0)
959 return 1;
961 if (! INSN_P (op))
962 return 0;
964 return get_attr_length (op) == 2;
967 /* Return nonzero if the operand is an insn that is a large insn. */
970 large_insn_p (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
972 if (! INSN_P (op))
973 return 0;
975 return get_attr_length (op) != 2;
978 /* Return nonzero if TYPE must be passed or returned in memory.
979 The m32r treats both directions the same so we handle both directions
980 in this function. */
983 m32r_pass_by_reference (tree type)
985 int size = int_size_in_bytes (type);
987 if (size < 0 || size > 8)
988 return 1;
990 return 0;
993 /* Comparisons. */
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);
1006 int must_swap = 0;
1008 switch (code)
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;
1021 default:
1022 abort ();
1025 if (need_compare)
1027 switch (compare_code)
1029 case EQ:
1030 if (GET_CODE (y) == CONST_INT
1031 && CMP_INT16_P (INTVAL (y)) /* Reg equal to small const. */
1032 && y != const0_rtx)
1034 rtx tmp = gen_reg_rtx (SImode);
1036 emit_insn (gen_addsi3 (tmp, x, GEN_INT (-INTVAL (y))));
1037 x = tmp;
1038 y = const0_rtx;
1040 else if (CONSTANT_P (y)) /* Reg equal to const. */
1042 rtx tmp = force_reg (GET_MODE (x), y);
1043 y = tmp;
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 (code, CCmode, cc_reg, const0_rtx);
1053 break;
1055 case LT:
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. */
1061 switch (code)
1063 case LT:
1064 emit_insn (gen_cmp_ltsi_insn (x, y));
1065 code = EQ;
1066 break;
1067 case LE:
1068 if (y == const0_rtx)
1069 tmp = const1_rtx;
1070 else
1071 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
1072 emit_insn (gen_cmp_ltsi_insn (x, tmp));
1073 code = EQ;
1074 break;
1075 case GT:
1076 if (GET_CODE (y) == CONST_INT)
1077 tmp = gen_rtx (PLUS, SImode, y, const1_rtx);
1078 else
1079 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
1080 emit_insn (gen_cmp_ltsi_insn (x, tmp));
1081 code = NE;
1082 break;
1083 case GE:
1084 emit_insn (gen_cmp_ltsi_insn (x, y));
1085 code = NE;
1086 break;
1087 default:
1088 abort ();
1091 return gen_rtx (code, CCmode, cc_reg, const0_rtx);
1093 break;
1095 case LTU:
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. */
1101 switch (code)
1103 case LTU:
1104 emit_insn (gen_cmp_ltusi_insn (x, y));
1105 code = EQ;
1106 break;
1107 case LEU:
1108 if (y == const0_rtx)
1109 tmp = const1_rtx;
1110 else
1111 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
1112 emit_insn (gen_cmp_ltusi_insn (x, tmp));
1113 code = EQ;
1114 break;
1115 case GTU:
1116 if (GET_CODE (y) == CONST_INT)
1117 tmp = gen_rtx (PLUS, SImode, y, const1_rtx);
1118 else
1119 emit_insn (gen_addsi3 (tmp, y, constm1_rtx));
1120 emit_insn (gen_cmp_ltusi_insn (x, tmp));
1121 code = NE;
1122 break;
1123 case GEU:
1124 emit_insn (gen_cmp_ltusi_insn (x, y));
1125 code = NE;
1126 break;
1127 default:
1128 abort();
1131 return gen_rtx (code, CCmode, cc_reg, const0_rtx);
1133 break;
1135 default:
1136 abort();
1139 else
1141 /* Reg/reg equal comparison. */
1142 if (compare_code == EQ
1143 && register_operand (y, SImode))
1144 return gen_rtx (code, CCmode, x, y);
1146 /* Reg/zero signed comparison. */
1147 if ((compare_code == EQ || compare_code == LT)
1148 && y == const0_rtx)
1149 return gen_rtx (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 (code, CCmode, tmp, const0_rtx);
1162 /* Reg/const equal comparison. */
1163 if (compare_code == EQ
1164 && CONSTANT_P (y))
1166 rtx tmp = force_reg (GET_MODE (x), y);
1168 return gen_rtx (code, CCmode, x, tmp);
1172 if (CONSTANT_P (y))
1174 if (must_swap)
1175 y = force_reg (GET_MODE (x), y);
1176 else
1178 int ok_const =
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));
1183 if (! ok_const)
1184 y = force_reg (GET_MODE (x), y);
1188 switch (compare_code)
1190 case EQ :
1191 emit_insn (gen_cmp_eqsi_insn (must_swap ? y : x, must_swap ? x : y));
1192 break;
1193 case LT :
1194 emit_insn (gen_cmp_ltsi_insn (must_swap ? y : x, must_swap ? x : y));
1195 break;
1196 case LTU :
1197 emit_insn (gen_cmp_ltusi_insn (must_swap ? y : x, must_swap ? x : y));
1198 break;
1200 default:
1201 abort ();
1204 return gen_rtx (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];
1215 rtx val;
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);
1225 start_sequence ();
1226 if (GET_CODE (dest) == REG)
1228 int dregno = REGNO (dest);
1230 /* Reg = reg. */
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)
1252 rtx words[2];
1253 split_double (src, &words[0], &words[1]);
1254 emit_insn (gen_rtx_SET (VOIDmode,
1255 operand_subword (dest, 0, TRUE, mode),
1256 words[0]));
1258 emit_insn (gen_rtx_SET (VOIDmode,
1259 operand_subword (dest, 1, TRUE, mode),
1260 words[1]));
1263 /* Reg = mem. */
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. */
1268 int reverse
1269 = (refers_to_regno_p (dregno, dregno + 1, XEXP (src, 0), 0) != 0);
1271 /* We used to optimize loads from single registers as
1273 ld r1,r3+; ld r2,r3
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)));
1292 else
1293 abort ();
1296 /* Mem = reg. */
1297 /* We used to optimize loads from single registers as
1299 st r1,r3; st r2,+r3
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)));
1319 else
1320 abort ();
1322 val = get_insns ();
1323 end_sequence ();
1324 return val;
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)
1334 int ret;
1335 unsigned int size =
1336 (((mode == BLKmode && type)
1337 ? (unsigned int) int_size_in_bytes (type)
1338 : GET_MODE_SIZE (mode)) + UNITS_PER_WORD - 1)
1339 / UNITS_PER_WORD;
1341 if (*cum >= M32R_MAX_PARM_REGS)
1342 ret = 0;
1343 else if (*cum + size > M32R_MAX_PARM_REGS)
1344 ret = (*cum + size) - M32R_MAX_PARM_REGS;
1345 else
1346 ret = 0;
1348 return ret;
1351 /* Do any needed setup for a variadic function. For the M32R, we must
1352 create a register parameter block, and then copy any anonymous arguments
1353 in registers to memory.
1355 CUM has not been updated for the last named argument which has type TYPE
1356 and mode MODE, and we rely on this fact. */
1358 void
1359 m32r_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1360 tree type, int *pretend_size, int no_rtl)
1362 int first_anon_arg;
1364 if (no_rtl)
1365 return;
1367 /* All BLKmode values are passed by reference. */
1368 if (mode == BLKmode)
1369 abort ();
1371 first_anon_arg = (ROUND_ADVANCE_CUM (*cum, mode, type)
1372 + ROUND_ADVANCE_ARG (mode, type));
1374 if (first_anon_arg < M32R_MAX_PARM_REGS)
1376 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1377 int first_reg_offset = first_anon_arg;
1378 /* Size in words to "pretend" allocate. */
1379 int size = M32R_MAX_PARM_REGS - first_reg_offset;
1380 rtx regblock;
1382 regblock = gen_rtx_MEM (BLKmode,
1383 plus_constant (arg_pointer_rtx,
1384 FIRST_PARM_OFFSET (0)));
1385 set_mem_alias_set (regblock, get_varargs_alias_set ());
1386 move_block_from_reg (first_reg_offset, regblock, size);
1388 *pretend_size = (size * UNITS_PER_WORD);
1393 /* Implement `va_arg'. */
1396 m32r_va_arg (tree valist, tree type)
1398 HOST_WIDE_INT size, rsize;
1399 tree t;
1400 rtx addr_rtx;
1402 size = int_size_in_bytes (type);
1403 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
1405 if (m32r_pass_by_reference (type))
1407 tree type_ptr, type_ptr_ptr;
1409 /* Pass by reference. */
1410 type_ptr = build_pointer_type (type);
1411 type_ptr_ptr = build_pointer_type (type_ptr);
1413 t = build (POSTINCREMENT_EXPR, va_list_type_node, valist,
1414 build_int_2 (UNITS_PER_WORD, 0));
1415 TREE_SIDE_EFFECTS (t) = 1;
1416 t = build1 (NOP_EXPR, type_ptr_ptr, t);
1417 TREE_SIDE_EFFECTS (t) = 1;
1418 t = build1 (INDIRECT_REF, type_ptr, t);
1420 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
1422 else
1424 /* Pass by value. */
1425 if (size < UNITS_PER_WORD)
1427 /* Care for bigendian correction on the aligned address. */
1428 t = build (PLUS_EXPR, ptr_type_node, valist,
1429 build_int_2 (rsize - size, 0));
1430 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
1431 addr_rtx = copy_to_reg (addr_rtx);
1433 /* Increment AP. */
1434 t = build (PLUS_EXPR, va_list_type_node, valist,
1435 build_int_2 (rsize, 0));
1436 t = build (MODIFY_EXPR, va_list_type_node, valist, t);
1437 TREE_SIDE_EFFECTS (t) = 1;
1438 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
1440 else
1442 t = build (POSTINCREMENT_EXPR, va_list_type_node, valist,
1443 build_int_2 (rsize, 0));
1444 TREE_SIDE_EFFECTS (t) = 1;
1445 addr_rtx = expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL);
1449 return addr_rtx;
1452 static int
1453 m32r_adjust_cost (rtx insn ATTRIBUTE_UNUSED, rtx link ATTRIBUTE_UNUSED,
1454 rtx dep_insn ATTRIBUTE_UNUSED, int cost)
1456 return cost;
1460 /* Return true if INSN is real instruction bearing insn. */
1462 static int
1463 m32r_is_insn (rtx insn)
1465 return (INSN_P (insn)
1466 && GET_CODE (PATTERN (insn)) != USE
1467 && GET_CODE (PATTERN (insn)) != CLOBBER
1468 && GET_CODE (PATTERN (insn)) != ADDR_VEC);
1471 /* Increase the priority of long instructions so that the
1472 short instructions are scheduled ahead of the long ones. */
1474 static int
1475 m32r_adjust_priority (rtx insn, int priority)
1477 if (m32r_is_insn (insn)
1478 && get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1479 priority <<= 3;
1481 return priority;
1485 /* Initialize for scheduling a group of instructions. */
1487 static void
1488 m32r_sched_init (FILE * stream ATTRIBUTE_UNUSED,
1489 int verbose ATTRIBUTE_UNUSED,
1490 int max_ready ATTRIBUTE_UNUSED)
1492 m32r_sched_odd_word_p = FALSE;
1496 /* Reorder the schedulers priority list if needed */
1498 static int
1499 m32r_sched_reorder (FILE * stream, int verbose, rtx * ready,
1500 int *n_readyp, int clock ATTRIBUTE_UNUSED)
1502 int n_ready = *n_readyp;
1504 if (TARGET_DEBUG)
1505 return m32r_issue_rate ();
1507 if (verbose <= 7)
1508 stream = (FILE *)0;
1510 if (stream)
1511 fprintf (stream,
1512 ";;\t\t::: Looking at %d insn(s) on ready list, boundary is %s word\n",
1513 n_ready,
1514 (m32r_sched_odd_word_p) ? "odd" : "even");
1516 if (n_ready > 1)
1518 rtx * long_head = alloca (sizeof (rtx) * n_ready);
1519 rtx * long_tail = long_head;
1520 rtx * short_head = alloca (sizeof (rtx) * n_ready);
1521 rtx * short_tail = short_head;
1522 rtx * new_head = alloca (sizeof (rtx) * n_ready);
1523 rtx * new_tail = new_head + (n_ready - 1);
1524 int i;
1526 /* Loop through the instructions, classifying them as short/long. Try
1527 to keep 2 short together and/or 1 long. Note, the ready list is
1528 actually ordered backwards, so keep it in that manner. */
1529 for (i = n_ready-1; i >= 0; i--)
1531 rtx insn = ready[i];
1533 if (! m32r_is_insn (insn))
1535 /* Dump all current short/long insns just in case. */
1536 while (long_head != long_tail)
1537 *new_tail-- = *long_head++;
1539 while (short_head != short_tail)
1540 *new_tail-- = *short_head++;
1542 *new_tail-- = insn;
1543 if (stream)
1544 fprintf (stream,
1545 ";;\t\t::: Skipping non instruction %d\n",
1546 INSN_UID (insn));
1550 else
1552 if (get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1553 *long_tail++ = insn;
1555 else
1556 *short_tail++ = insn;
1560 /* If we are on an odd word, emit a single short instruction if
1561 we can. */
1562 if (m32r_sched_odd_word_p && short_head != short_tail)
1563 *new_tail-- = *short_head++;
1565 /* Now dump out all of the long instructions. */
1566 while (long_head != long_tail)
1567 *new_tail-- = *long_head++;
1569 /* Now dump out all of the short instructions. */
1570 while (short_head != short_tail)
1571 *new_tail-- = *short_head++;
1573 if (new_tail + 1 != new_head)
1574 abort ();
1576 memcpy (ready, new_head, sizeof (rtx) * n_ready);
1577 if (stream)
1579 int i;
1580 fprintf (stream, ";;\t\t::: New ready list: ");
1581 for (i = 0; i < n_ready; i++)
1583 rtx insn = ready[i];
1585 fprintf (stream, " %d", INSN_UID (ready[i]));
1587 if (! m32r_is_insn (insn))
1588 fputs ("(?)", stream);
1590 else if (get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1591 fputs ("(l)", stream);
1593 else
1594 fputs ("(s)", stream);
1597 fprintf (stream, "\n");
1600 return m32r_issue_rate ();
1603 /* Indicate how many instructions can be issued at the same time.
1604 This is sort of a lie. The m32r can issue only 1 long insn at
1605 once, but it can issue 2 short insns. The default therefore is
1606 set at 2, but this can be overridden by the command line option
1607 -missue-rate=1. */
1609 static int
1610 m32r_issue_rate (void)
1612 return ((TARGET_LOW_ISSUE_RATE) ? 1 : 2);
1615 /* If we have a machine that can issue a variable # of instructions
1616 per cycle, indicate how many more instructions can be issued
1617 after the current one. */
1619 static int
1620 m32r_variable_issue (FILE * stream, int verbose, rtx insn, int how_many)
1622 int orig_odd_word_p = m32r_sched_odd_word_p;
1623 int short_p = FALSE;
1625 how_many--;
1626 if (how_many > 0 && !TARGET_DEBUG)
1628 if (! m32r_is_insn (insn))
1629 how_many++;
1631 else if (get_attr_insn_size (insn) != INSN_SIZE_SHORT)
1633 how_many = 0;
1634 m32r_sched_odd_word_p = 0;
1636 else
1638 m32r_sched_odd_word_p = !m32r_sched_odd_word_p;
1639 short_p = TRUE;
1643 if (verbose > 7 && stream)
1644 fprintf (stream,
1645 ";;\t\t::: %s insn %d starts on an %s word, can emit %d more instruction(s)\n",
1646 short_p ? "short" : "long",
1647 INSN_UID (insn),
1648 orig_odd_word_p ? "odd" : "even",
1649 how_many);
1651 return how_many;
1654 /* Cost functions. */
1656 static bool
1657 m32r_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, int *total)
1659 switch (code)
1661 /* Small integers are as cheap as registers. 4 byte values can be
1662 fetched as immediate constants - let's give that the cost of an
1663 extra insn. */
1664 case CONST_INT:
1665 if (INT16_P (INTVAL (x)))
1667 *total = 0;
1668 return true;
1670 /* FALLTHRU */
1672 case CONST:
1673 case LABEL_REF:
1674 case SYMBOL_REF:
1675 *total = COSTS_N_INSNS (1);
1676 return true;
1678 case CONST_DOUBLE:
1680 rtx high, low;
1682 split_double (x, &high, &low);
1683 *total = COSTS_N_INSNS (!INT16_P (INTVAL (high))
1684 + !INT16_P (INTVAL (low)));
1685 return true;
1688 case MULT:
1689 *total = COSTS_N_INSNS (3);
1690 return true;
1692 case DIV:
1693 case UDIV:
1694 case MOD:
1695 case UMOD:
1696 *total = COSTS_N_INSNS (10);
1697 return true;
1699 default:
1700 return false;
1704 /* Type of function DECL.
1706 The result is cached. To reset the cache at the end of a function,
1707 call with DECL = NULL_TREE. */
1709 enum m32r_function_type
1710 m32r_compute_function_type (tree decl)
1712 /* Cached value. */
1713 static enum m32r_function_type fn_type = M32R_FUNCTION_UNKNOWN;
1714 /* Last function we were called for. */
1715 static tree last_fn = NULL_TREE;
1717 /* Resetting the cached value? */
1718 if (decl == NULL_TREE)
1720 fn_type = M32R_FUNCTION_UNKNOWN;
1721 last_fn = NULL_TREE;
1722 return fn_type;
1725 if (decl == last_fn && fn_type != M32R_FUNCTION_UNKNOWN)
1726 return fn_type;
1728 /* Compute function type. */
1729 fn_type = (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl)) != NULL_TREE
1730 ? M32R_FUNCTION_INTERRUPT
1731 : M32R_FUNCTION_NORMAL);
1733 last_fn = decl;
1734 return fn_type;
1736 \f/* Function prologue/epilogue handlers. */
1738 /* M32R stack frames look like:
1740 Before call After call
1741 +-----------------------+ +-----------------------+
1742 | | | |
1743 high | local variables, | | local variables, |
1744 mem | reg save area, etc. | | reg save area, etc. |
1745 | | | |
1746 +-----------------------+ +-----------------------+
1747 | | | |
1748 | arguments on stack. | | arguments on stack. |
1749 | | | |
1750 SP+0->+-----------------------+ +-----------------------+
1751 | reg parm save area, |
1752 | only created for |
1753 | variable argument |
1754 | functions |
1755 +-----------------------+
1756 | previous frame ptr |
1757 +-----------------------+
1758 | |
1759 | register save area |
1760 | |
1761 +-----------------------+
1762 | return address |
1763 +-----------------------+
1764 | |
1765 | local variables |
1766 | |
1767 +-----------------------+
1768 | |
1769 | alloca allocations |
1770 | |
1771 +-----------------------+
1772 | |
1773 low | arguments on stack |
1774 memory | |
1775 SP+0->+-----------------------+
1777 Notes:
1778 1) The "reg parm save area" does not exist for non variable argument fns.
1779 2) The "reg parm save area" can be eliminated completely if we saved regs
1780 containing anonymous args separately but that complicates things too
1781 much (so it's not done).
1782 3) The return address is saved after the register save area so as to have as
1783 many insns as possible between the restoration of `lr' and the `jmp lr'. */
1785 /* Structure to be filled in by m32r_compute_frame_size with register
1786 save masks, and offsets for the current function. */
1787 struct m32r_frame_info
1789 unsigned int total_size; /* # bytes that the entire frame takes up. */
1790 unsigned int extra_size; /* # bytes of extra stuff. */
1791 unsigned int pretend_size; /* # bytes we push and pretend caller did. */
1792 unsigned int args_size; /* # bytes that outgoing arguments take up. */
1793 unsigned int reg_size; /* # bytes needed to store regs. */
1794 unsigned int var_size; /* # bytes that variables take up. */
1795 unsigned int gmask; /* Mask of saved gp registers. */
1796 unsigned int save_fp; /* Nonzero if fp must be saved. */
1797 unsigned int save_lr; /* Nonzero if lr (return addr) must be saved. */
1798 int initialized; /* Nonzero if frame size already calculated. */
1801 /* Current frame information calculated by m32r_compute_frame_size. */
1802 static struct m32r_frame_info current_frame_info;
1804 /* Zero structure to initialize current_frame_info. */
1805 static struct m32r_frame_info zero_frame_info;
1807 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1808 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1810 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1811 The return address and frame pointer are treated separately.
1812 Don't consider them here. */
1813 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1814 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1815 && (regs_ever_live[regno] && (!call_used_regs[regno] || interrupt_p)))
1817 #define MUST_SAVE_FRAME_POINTER (regs_ever_live[FRAME_POINTER_REGNUM])
1818 #define MUST_SAVE_RETURN_ADDR (regs_ever_live[RETURN_ADDR_REGNUM] || current_function_profile)
1820 #define SHORT_INSN_SIZE 2 /* Size of small instructions. */
1821 #define LONG_INSN_SIZE 4 /* Size of long instructions. */
1823 /* Return the bytes needed to compute the frame pointer from the current
1824 stack pointer.
1826 SIZE is the size needed for local variables. */
1828 unsigned int
1829 m32r_compute_frame_size (int size) /* # of var. bytes allocated. */
1831 int regno;
1832 unsigned int total_size, var_size, args_size, pretend_size, extra_size;
1833 unsigned int reg_size, frame_size;
1834 unsigned int gmask;
1835 enum m32r_function_type fn_type;
1836 int interrupt_p;
1837 int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table);
1839 var_size = M32R_STACK_ALIGN (size);
1840 args_size = M32R_STACK_ALIGN (current_function_outgoing_args_size);
1841 pretend_size = current_function_pretend_args_size;
1842 extra_size = FIRST_PARM_OFFSET (0);
1843 total_size = extra_size + pretend_size + args_size + var_size;
1844 reg_size = 0;
1845 gmask = 0;
1847 /* See if this is an interrupt handler. Call used registers must be saved
1848 for them too. */
1849 fn_type = m32r_compute_function_type (current_function_decl);
1850 interrupt_p = M32R_INTERRUPT_P (fn_type);
1852 /* Calculate space needed for registers. */
1853 for (regno = 0; regno < M32R_MAX_INT_REGS; regno++)
1855 if (MUST_SAVE_REGISTER (regno, interrupt_p)
1856 || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used))
1858 reg_size += UNITS_PER_WORD;
1859 gmask |= 1 << regno;
1863 current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER;
1864 current_frame_info.save_lr = MUST_SAVE_RETURN_ADDR || pic_reg_used;
1866 reg_size += ((current_frame_info.save_fp + current_frame_info.save_lr)
1867 * UNITS_PER_WORD);
1868 total_size += reg_size;
1870 /* ??? Not sure this is necessary, and I don't think the epilogue
1871 handler will do the right thing if this changes total_size. */
1872 total_size = M32R_STACK_ALIGN (total_size);
1874 frame_size = total_size - (pretend_size + reg_size);
1876 /* Save computed information. */
1877 current_frame_info.total_size = total_size;
1878 current_frame_info.extra_size = extra_size;
1879 current_frame_info.pretend_size = pretend_size;
1880 current_frame_info.var_size = var_size;
1881 current_frame_info.args_size = args_size;
1882 current_frame_info.reg_size = reg_size;
1883 current_frame_info.gmask = gmask;
1884 current_frame_info.initialized = reload_completed;
1886 /* Ok, we're done. */
1887 return total_size;
1890 /* The table we use to reference PIC data. */
1891 static rtx global_offset_table;
1893 void
1894 m32r_load_pic_register (void)
1896 global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
1897 emit_insn (gen_get_pc (pic_offset_table_rtx, global_offset_table,
1898 gen_rtx_CONST_INT(SImode, TARGET_MODEL_SMALL)));
1900 /* Need to emit this whether or not we obey regdecls,
1901 since setjmp/longjmp can cause life info to screw up. */
1902 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
1905 /* Expand the m32r prologue as a series of insns. */
1907 void
1908 m32r_expand_prologue (void)
1910 int regno;
1911 int frame_size;
1912 unsigned int gmask;
1913 int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table);
1915 if (! current_frame_info.initialized)
1916 m32r_compute_frame_size (get_frame_size ());
1918 gmask = current_frame_info.gmask;
1920 /* These cases shouldn't happen. Catch them now. */
1921 if (current_frame_info.total_size == 0 && gmask)
1922 abort ();
1924 /* Allocate space for register arguments if this is a variadic function. */
1925 if (current_frame_info.pretend_size != 0)
1927 /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1928 the wrong result on a 64-bit host. */
1929 HOST_WIDE_INT pretend_size = current_frame_info.pretend_size;
1930 emit_insn (gen_addsi3 (stack_pointer_rtx,
1931 stack_pointer_rtx,
1932 GEN_INT (-pretend_size)));
1935 /* Save any registers we need to and set up fp. */
1936 if (current_frame_info.save_fp)
1937 emit_insn (gen_movsi_push (stack_pointer_rtx, frame_pointer_rtx));
1939 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
1941 /* Save any needed call-saved regs (and call-used if this is an
1942 interrupt handler). */
1943 for (regno = 0; regno <= M32R_MAX_INT_REGS; ++regno)
1945 if ((gmask & (1 << regno)) != 0)
1946 emit_insn (gen_movsi_push (stack_pointer_rtx,
1947 gen_rtx_REG (Pmode, regno)));
1950 if (current_frame_info.save_lr)
1951 emit_insn (gen_movsi_push (stack_pointer_rtx,
1952 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1954 /* Allocate the stack frame. */
1955 frame_size = (current_frame_info.total_size
1956 - (current_frame_info.pretend_size
1957 + current_frame_info.reg_size));
1959 if (frame_size == 0)
1960 ; /* Nothing to do. */
1961 else if (frame_size <= 32768)
1962 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1963 GEN_INT (-frame_size)));
1964 else
1966 rtx tmp = gen_rtx_REG (Pmode, PROLOGUE_TMP_REGNUM);
1968 emit_insn (gen_movsi (tmp, GEN_INT (frame_size)));
1969 emit_insn (gen_subsi3 (stack_pointer_rtx, stack_pointer_rtx, tmp));
1972 if (frame_pointer_needed)
1973 emit_insn (gen_movsi (frame_pointer_rtx, stack_pointer_rtx));
1975 if (current_function_profile)
1976 /* Push lr for mcount (form_pc, x). */
1977 emit_insn (gen_movsi_push (stack_pointer_rtx,
1978 gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM)));
1980 if (pic_reg_used)
1981 m32r_load_pic_register ();
1983 if (current_function_profile && !pic_reg_used)
1984 emit_insn (gen_blockage ());
1988 /* Set up the stack and frame pointer (if desired) for the function.
1989 Note, if this is changed, you need to mirror the changes in
1990 m32r_compute_frame_size which calculates the prolog size. */
1992 static void
1993 m32r_output_function_prologue (FILE * file, HOST_WIDE_INT size)
1995 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
1997 /* If this is an interrupt handler, mark it as such. */
1998 if (M32R_INTERRUPT_P (fn_type))
1999 fprintf (file, "\t%s interrupt handler\n", ASM_COMMENT_START);
2001 if (! current_frame_info.initialized)
2002 m32r_compute_frame_size (size);
2004 /* This is only for the human reader. */
2005 fprintf (file,
2006 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
2007 ASM_COMMENT_START,
2008 current_frame_info.var_size,
2009 current_frame_info.reg_size / 4,
2010 current_frame_info.args_size,
2011 current_frame_info.extra_size);
2014 /* Do any necessary cleanup after a function to restore stack, frame,
2015 and regs. */
2017 static void
2018 m32r_output_function_epilogue (FILE * file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
2020 int regno;
2021 int noepilogue = FALSE;
2022 int total_size;
2023 enum m32r_function_type fn_type = m32r_compute_function_type (current_function_decl);
2025 /* This is only for the human reader. */
2026 fprintf (file, "\t%s EPILOGUE\n", ASM_COMMENT_START);
2028 if (!current_frame_info.initialized)
2029 abort ();
2030 total_size = current_frame_info.total_size;
2032 if (total_size == 0)
2034 rtx insn = get_last_insn ();
2036 /* If the last insn was a BARRIER, we don't have to write any code
2037 because a jump (aka return) was put there. */
2038 if (GET_CODE (insn) == NOTE)
2039 insn = prev_nonnote_insn (insn);
2040 if (insn && GET_CODE (insn) == BARRIER)
2041 noepilogue = TRUE;
2044 if (!noepilogue)
2046 unsigned int var_size = current_frame_info.var_size;
2047 unsigned int args_size = current_frame_info.args_size;
2048 unsigned int gmask = current_frame_info.gmask;
2049 int can_trust_sp_p = !current_function_calls_alloca;
2050 const char * sp_str = reg_names[STACK_POINTER_REGNUM];
2051 const char * fp_str = reg_names[FRAME_POINTER_REGNUM];
2053 /* The first thing to do is point the sp at the bottom of the register
2054 save area. */
2055 if (can_trust_sp_p)
2057 unsigned int reg_offset = var_size + args_size;
2058 if (reg_offset == 0)
2059 ; /* Nothing to do. */
2060 else if (reg_offset < 128)
2061 fprintf (file, "\taddi %s,%s%d\n",
2062 sp_str, IMMEDIATE_PREFIX, reg_offset);
2063 else if (reg_offset < 32768)
2064 fprintf (file, "\tadd3 %s,%s,%s%d\n",
2065 sp_str, sp_str, IMMEDIATE_PREFIX, reg_offset);
2066 else
2067 fprintf (file, "\tld24 %s,%s%d\n\tadd %s,%s\n",
2068 reg_names[PROLOGUE_TMP_REGNUM],
2069 IMMEDIATE_PREFIX, reg_offset,
2070 sp_str, reg_names[PROLOGUE_TMP_REGNUM]);
2072 else if (frame_pointer_needed)
2074 unsigned int reg_offset = var_size + args_size;
2076 if (reg_offset == 0)
2077 fprintf (file, "\tmv %s,%s\n", sp_str, fp_str);
2078 else if (reg_offset < 32768)
2079 fprintf (file, "\tadd3 %s,%s,%s%d\n",
2080 sp_str, fp_str, IMMEDIATE_PREFIX, reg_offset);
2081 else
2082 fprintf (file, "\tld24 %s,%s%d\n\tadd %s,%s\n",
2083 reg_names[PROLOGUE_TMP_REGNUM],
2084 IMMEDIATE_PREFIX, reg_offset,
2085 sp_str, reg_names[PROLOGUE_TMP_REGNUM]);
2087 else
2088 abort ();
2090 if (current_frame_info.save_lr)
2091 fprintf (file, "\tpop %s\n", reg_names[RETURN_ADDR_REGNUM]);
2093 /* Restore any saved registers, in reverse order of course. */
2094 gmask &= ~(FRAME_POINTER_MASK | RETURN_ADDR_MASK);
2095 for (regno = M32R_MAX_INT_REGS - 1; regno >= 0; --regno)
2097 if ((gmask & (1L << regno)) != 0)
2098 fprintf (file, "\tpop %s\n", reg_names[regno]);
2101 if (current_frame_info.save_fp)
2102 fprintf (file, "\tpop %s\n", fp_str);
2104 /* Remove varargs area if present. */
2105 if (current_frame_info.pretend_size != 0)
2106 fprintf (file, "\taddi %s,%s%d\n",
2107 sp_str, IMMEDIATE_PREFIX, current_frame_info.pretend_size);
2109 /* Emit the return instruction. */
2110 if (M32R_INTERRUPT_P (fn_type))
2111 fprintf (file, "\trte\n");
2112 else
2113 fprintf (file, "\tjmp %s\n", reg_names[RETURN_ADDR_REGNUM]);
2116 /* Reset state info for each function. */
2117 current_frame_info = zero_frame_info;
2118 m32r_compute_function_type (NULL_TREE);
2121 /* Return nonzero if this function is known to have a null or 1 instruction
2122 epilogue. */
2125 direct_return (void)
2127 if (!reload_completed)
2128 return FALSE;
2130 if (! current_frame_info.initialized)
2131 m32r_compute_frame_size (get_frame_size ());
2133 return current_frame_info.total_size == 0;
2137 /* PIC. */
2140 m32r_legitimate_pic_operand_p (rtx x)
2142 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
2143 return 0;
2145 if (GET_CODE (x) == CONST
2146 && GET_CODE (XEXP (x, 0)) == PLUS
2147 && (GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
2148 || GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF)
2149 && (GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT))
2150 return 0;
2152 return 1;
2156 m32r_legitimize_pic_address (rtx orig, rtx reg)
2158 #ifdef DEBUG_PIC
2159 printf("m32r_legitimize_pic_address()\n");
2160 #endif
2162 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
2164 rtx pic_ref, address;
2165 rtx insn;
2166 int subregs = 0;
2168 if (reg == 0)
2170 if (reload_in_progress || reload_completed)
2171 abort ();
2172 else
2173 reg = gen_reg_rtx (Pmode);
2175 subregs = 1;
2178 if (subregs)
2179 address = gen_reg_rtx (Pmode);
2180 else
2181 address = reg;
2183 emit_insn (gen_pic_load_addr (address, orig));
2185 emit_insn (gen_addsi3 (address, address, pic_offset_table_rtx));
2186 pic_ref = gen_rtx (MEM, Pmode, address);
2188 RTX_UNCHANGING_P (pic_ref) = 1;
2189 insn = emit_move_insn (reg, pic_ref);
2190 current_function_uses_pic_offset_table = 1;
2191 #if 0
2192 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2193 by loop. */
2194 REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, orig,
2195 REG_NOTES (insn));
2196 #endif
2197 return reg;
2199 else if (GET_CODE (orig) == CONST)
2201 rtx base, offset;
2203 if (GET_CODE (XEXP (orig, 0)) == PLUS
2204 && XEXP (XEXP (orig, 0), 1) == pic_offset_table_rtx)
2205 return orig;
2207 if (reg == 0)
2209 if (reload_in_progress || reload_completed)
2210 abort ();
2211 else
2212 reg = gen_reg_rtx (Pmode);
2215 if (GET_CODE (XEXP (orig, 0)) == PLUS)
2217 base = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), reg);
2218 if (base == reg)
2219 offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), NULL_RTX);
2220 else
2221 offset = m32r_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), reg);
2223 else
2224 return orig;
2226 if (GET_CODE (offset) == CONST_INT)
2228 if (INT16_P (INTVAL (offset)))
2229 return plus_constant (base, INTVAL (offset));
2230 else if (! reload_in_progress && ! reload_completed)
2231 offset = force_reg (Pmode, offset);
2232 else
2233 /* If we reach here, then something is seriously wrong. */
2234 abort ();
2237 return gen_rtx (PLUS, Pmode, base, offset);
2240 return orig;
2243 /* Emit special PIC prologues and epilogues. */
2245 void
2246 m32r_finalize_pic (void)
2248 current_function_uses_pic_offset_table |= current_function_profile;
2251 /* Nested function support. */
2253 /* Emit RTL insns to initialize the variable parts of a trampoline.
2254 FNADDR is an RTX for the address of the function's pure code.
2255 CXT is an RTX for the static chain value for the function. */
2257 void
2258 m32r_initialize_trampoline (rtx tramp ATTRIBUTE_UNUSED,
2259 rtx fnaddr ATTRIBUTE_UNUSED,
2260 rtx cxt ATTRIBUTE_UNUSED)
2264 static void
2265 m32r_file_start (void)
2267 default_file_start ();
2269 if (flag_verbose_asm)
2270 fprintf (asm_out_file,
2271 "%s M32R/D special options: -G " HOST_WIDE_INT_PRINT_UNSIGNED "\n",
2272 ASM_COMMENT_START, g_switch_value);
2274 if (TARGET_LITTLE_ENDIAN)
2275 fprintf (asm_out_file, "\t.little\n");
2278 /* Print operand X (an rtx) in assembler syntax to file FILE.
2279 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2280 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2282 void
2283 m32r_print_operand (FILE * file, rtx x, int code)
2285 rtx addr;
2287 switch (code)
2289 /* The 's' and 'p' codes are used by output_block_move() to
2290 indicate post-increment 's'tores and 'p're-increment loads. */
2291 case 's':
2292 if (GET_CODE (x) == REG)
2293 fprintf (file, "@+%s", reg_names [REGNO (x)]);
2294 else
2295 output_operand_lossage ("invalid operand to %%s code");
2296 return;
2298 case 'p':
2299 if (GET_CODE (x) == REG)
2300 fprintf (file, "@%s+", reg_names [REGNO (x)]);
2301 else
2302 output_operand_lossage ("invalid operand to %%p code");
2303 return;
2305 case 'R' :
2306 /* Write second word of DImode or DFmode reference,
2307 register or memory. */
2308 if (GET_CODE (x) == REG)
2309 fputs (reg_names[REGNO (x)+1], file);
2310 else if (GET_CODE (x) == MEM)
2312 fprintf (file, "@(");
2313 /* Handle possible auto-increment. Since it is pre-increment and
2314 we have already done it, we can just use an offset of four. */
2315 /* ??? This is taken from rs6000.c I think. I don't think it is
2316 currently necessary, but keep it around. */
2317 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2318 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2319 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 4));
2320 else
2321 output_address (plus_constant (XEXP (x, 0), 4));
2322 fputc (')', file);
2324 else
2325 output_operand_lossage ("invalid operand to %%R code");
2326 return;
2328 case 'H' : /* High word. */
2329 case 'L' : /* Low word. */
2330 if (GET_CODE (x) == REG)
2332 /* L = least significant word, H = most significant word. */
2333 if ((WORDS_BIG_ENDIAN != 0) ^ (code == 'L'))
2334 fputs (reg_names[REGNO (x)], file);
2335 else
2336 fputs (reg_names[REGNO (x)+1], file);
2338 else if (GET_CODE (x) == CONST_INT
2339 || GET_CODE (x) == CONST_DOUBLE)
2341 rtx first, second;
2343 split_double (x, &first, &second);
2344 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2345 code == 'L' ? INTVAL (first) : INTVAL (second));
2347 else
2348 output_operand_lossage ("invalid operand to %%H/%%L code");
2349 return;
2351 case 'A' :
2353 char str[30];
2355 if (GET_CODE (x) != CONST_DOUBLE
2356 || GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT)
2357 fatal_insn ("bad insn for 'A'", x);
2359 real_to_decimal (str, CONST_DOUBLE_REAL_VALUE (x), sizeof (str), 0, 1);
2360 fprintf (file, "%s", str);
2361 return;
2364 case 'B' : /* Bottom half. */
2365 case 'T' : /* Top half. */
2366 /* Output the argument to a `seth' insn (sets the Top half-word).
2367 For constants output arguments to a seth/or3 pair to set Top and
2368 Bottom halves. For symbols output arguments to a seth/add3 pair to
2369 set Top and Bottom halves. The difference exists because for
2370 constants seth/or3 is more readable but for symbols we need to use
2371 the same scheme as `ld' and `st' insns (16 bit addend is signed). */
2372 switch (GET_CODE (x))
2374 case CONST_INT :
2375 case CONST_DOUBLE :
2377 rtx first, second;
2379 split_double (x, &first, &second);
2380 x = WORDS_BIG_ENDIAN ? second : first;
2381 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
2382 (code == 'B'
2383 ? INTVAL (x) & 0xffff
2384 : (INTVAL (x) >> 16) & 0xffff));
2386 return;
2387 case CONST :
2388 case SYMBOL_REF :
2389 if (code == 'B'
2390 && small_data_operand (x, VOIDmode))
2392 fputs ("sda(", file);
2393 output_addr_const (file, x);
2394 fputc (')', file);
2395 return;
2397 /* fall through */
2398 case LABEL_REF :
2399 fputs (code == 'T' ? "shigh(" : "low(", file);
2400 output_addr_const (file, x);
2401 fputc (')', file);
2402 return;
2403 default :
2404 output_operand_lossage ("invalid operand to %%T/%%B code");
2405 return;
2407 break;
2409 case 'U' :
2410 /* ??? wip */
2411 /* Output a load/store with update indicator if appropriate. */
2412 if (GET_CODE (x) == MEM)
2414 if (GET_CODE (XEXP (x, 0)) == PRE_INC
2415 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
2416 fputs (".a", file);
2418 else
2419 output_operand_lossage ("invalid operand to %%U code");
2420 return;
2422 case 'N' :
2423 /* Print a constant value negated. */
2424 if (GET_CODE (x) == CONST_INT)
2425 output_addr_const (file, GEN_INT (- INTVAL (x)));
2426 else
2427 output_operand_lossage ("invalid operand to %%N code");
2428 return;
2430 case 'X' :
2431 /* Print a const_int in hex. Used in comments. */
2432 if (GET_CODE (x) == CONST_INT)
2433 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (x));
2434 return;
2436 case '#' :
2437 fputs (IMMEDIATE_PREFIX, file);
2438 return;
2440 case 0 :
2441 /* Do nothing special. */
2442 break;
2444 default :
2445 /* Unknown flag. */
2446 output_operand_lossage ("invalid operand output code");
2449 switch (GET_CODE (x))
2451 case REG :
2452 fputs (reg_names[REGNO (x)], file);
2453 break;
2455 case MEM :
2456 addr = XEXP (x, 0);
2457 if (GET_CODE (addr) == PRE_INC)
2459 if (GET_CODE (XEXP (addr, 0)) != REG)
2460 fatal_insn ("pre-increment address is not a register", x);
2462 fprintf (file, "@+%s", reg_names[REGNO (XEXP (addr, 0))]);
2464 else if (GET_CODE (addr) == PRE_DEC)
2466 if (GET_CODE (XEXP (addr, 0)) != REG)
2467 fatal_insn ("pre-decrement address is not a register", x);
2469 fprintf (file, "@-%s", reg_names[REGNO (XEXP (addr, 0))]);
2471 else if (GET_CODE (addr) == POST_INC)
2473 if (GET_CODE (XEXP (addr, 0)) != REG)
2474 fatal_insn ("post-increment address is not a register", x);
2476 fprintf (file, "@%s+", reg_names[REGNO (XEXP (addr, 0))]);
2478 else
2480 fputs ("@(", file);
2481 output_address (XEXP (x, 0));
2482 fputc (')', file);
2484 break;
2486 case CONST_DOUBLE :
2487 /* We handle SFmode constants here as output_addr_const doesn't. */
2488 if (GET_MODE (x) == SFmode)
2490 REAL_VALUE_TYPE d;
2491 long l;
2493 REAL_VALUE_FROM_CONST_DOUBLE (d, x);
2494 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2495 fprintf (file, "0x%08lx", l);
2496 break;
2499 /* Fall through. Let output_addr_const deal with it. */
2501 default :
2502 output_addr_const (file, x);
2503 break;
2507 /* Print a memory address as an operand to reference that memory location. */
2509 void
2510 m32r_print_operand_address (FILE * file, rtx addr)
2512 rtx base;
2513 rtx index = 0;
2514 int offset = 0;
2516 switch (GET_CODE (addr))
2518 case REG :
2519 fputs (reg_names[REGNO (addr)], file);
2520 break;
2522 case PLUS :
2523 if (GET_CODE (XEXP (addr, 0)) == CONST_INT)
2524 offset = INTVAL (XEXP (addr, 0)), base = XEXP (addr, 1);
2525 else if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
2526 offset = INTVAL (XEXP (addr, 1)), base = XEXP (addr, 0);
2527 else
2528 base = XEXP (addr, 0), index = XEXP (addr, 1);
2529 if (GET_CODE (base) == REG)
2531 /* Print the offset first (if present) to conform to the manual. */
2532 if (index == 0)
2534 if (offset != 0)
2535 fprintf (file, "%d,", offset);
2536 fputs (reg_names[REGNO (base)], file);
2538 /* The chip doesn't support this, but left in for generality. */
2539 else if (GET_CODE (index) == REG)
2540 fprintf (file, "%s,%s",
2541 reg_names[REGNO (base)], reg_names[REGNO (index)]);
2542 /* Not sure this can happen, but leave in for now. */
2543 else if (GET_CODE (index) == SYMBOL_REF)
2545 output_addr_const (file, index);
2546 fputc (',', file);
2547 fputs (reg_names[REGNO (base)], file);
2549 else
2550 fatal_insn ("bad address", addr);
2552 else if (GET_CODE (base) == LO_SUM)
2554 if (index != 0
2555 || GET_CODE (XEXP (base, 0)) != REG)
2556 abort ();
2557 if (small_data_operand (XEXP (base, 1), VOIDmode))
2558 fputs ("sda(", file);
2559 else
2560 fputs ("low(", file);
2561 output_addr_const (file, plus_constant (XEXP (base, 1), offset));
2562 fputs ("),", file);
2563 fputs (reg_names[REGNO (XEXP (base, 0))], file);
2565 else
2566 fatal_insn ("bad address", addr);
2567 break;
2569 case LO_SUM :
2570 if (GET_CODE (XEXP (addr, 0)) != REG)
2571 fatal_insn ("lo_sum not of register", addr);
2572 if (small_data_operand (XEXP (addr, 1), VOIDmode))
2573 fputs ("sda(", file);
2574 else
2575 fputs ("low(", file);
2576 output_addr_const (file, XEXP (addr, 1));
2577 fputs ("),", file);
2578 fputs (reg_names[REGNO (XEXP (addr, 0))], file);
2579 break;
2581 case PRE_INC : /* Assume SImode. */
2582 fprintf (file, "+%s", reg_names[REGNO (XEXP (addr, 0))]);
2583 break;
2585 case PRE_DEC : /* Assume SImode. */
2586 fprintf (file, "-%s", reg_names[REGNO (XEXP (addr, 0))]);
2587 break;
2589 case POST_INC : /* Assume SImode. */
2590 fprintf (file, "%s+", reg_names[REGNO (XEXP (addr, 0))]);
2591 break;
2593 default :
2594 output_addr_const (file, addr);
2595 break;
2599 /* Return true if the operands are the constants 0 and 1. */
2602 zero_and_one (rtx operand1, rtx operand2)
2604 return
2605 GET_CODE (operand1) == CONST_INT
2606 && GET_CODE (operand2) == CONST_INT
2607 && ( ((INTVAL (operand1) == 0) && (INTVAL (operand2) == 1))
2608 ||((INTVAL (operand1) == 1) && (INTVAL (operand2) == 0)));
2611 /* Return nonzero if the operand is suitable for use in a conditional move sequence. */
2614 conditional_move_operand (rtx operand, enum machine_mode mode)
2616 /* Only defined for simple integers so far... */
2617 if (mode != SImode && mode != HImode && mode != QImode)
2618 return FALSE;
2620 /* At the moment we can handle moving registers and loading constants. */
2621 /* To be added: Addition/subtraction/bitops/multiplication of registers. */
2623 switch (GET_CODE (operand))
2625 case REG:
2626 return 1;
2628 case CONST_INT:
2629 return INT8_P (INTVAL (operand));
2631 default:
2632 #if 0
2633 fprintf (stderr, "Test for cond move op of type: %s\n",
2634 GET_RTX_NAME (GET_CODE (operand)));
2635 #endif
2636 return 0;
2640 /* Return true if the code is a test of the carry bit. */
2643 carry_compare_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2645 rtx x;
2647 if (GET_MODE (op) != CCmode && GET_MODE (op) != VOIDmode)
2648 return FALSE;
2650 if (GET_CODE (op) != NE && GET_CODE (op) != EQ)
2651 return FALSE;
2653 x = XEXP (op, 0);
2654 if (GET_CODE (x) != REG || REGNO (x) != CARRY_REGNUM)
2655 return FALSE;
2657 x = XEXP (op, 1);
2658 if (GET_CODE (x) != CONST_INT || INTVAL (x) != 0)
2659 return FALSE;
2661 return TRUE;
2664 /* Generate the correct assembler code to handle the conditional loading of a
2665 value into a register. It is known that the operands satisfy the
2666 conditional_move_operand() function above. The destination is operand[0].
2667 The condition is operand [1]. The 'true' value is operand [2] and the
2668 'false' value is operand [3]. */
2670 char *
2671 emit_cond_move (rtx * operands, rtx insn ATTRIBUTE_UNUSED)
2673 static char buffer [100];
2674 const char * dest = reg_names [REGNO (operands [0])];
2676 buffer [0] = 0;
2678 /* Destination must be a register. */
2679 if (GET_CODE (operands [0]) != REG)
2680 abort();
2681 if (! conditional_move_operand (operands [2], SImode))
2682 abort();
2683 if (! conditional_move_operand (operands [3], SImode))
2684 abort();
2686 /* Check to see if the test is reversed. */
2687 if (GET_CODE (operands [1]) == NE)
2689 rtx tmp = operands [2];
2690 operands [2] = operands [3];
2691 operands [3] = tmp;
2694 sprintf (buffer, "mvfc %s, cbr", dest);
2696 /* If the true value was '0' then we need to invert the results of the move. */
2697 if (INTVAL (operands [2]) == 0)
2698 sprintf (buffer + strlen (buffer), "\n\txor3 %s, %s, #1",
2699 dest, dest);
2701 return buffer;
2704 /* Returns true if the registers contained in the two
2705 rtl expressions are different. */
2708 m32r_not_same_reg (rtx a, rtx b)
2710 int reg_a = -1;
2711 int reg_b = -2;
2713 while (GET_CODE (a) == SUBREG)
2714 a = SUBREG_REG (a);
2716 if (GET_CODE (a) == REG)
2717 reg_a = REGNO (a);
2719 while (GET_CODE (b) == SUBREG)
2720 b = SUBREG_REG (b);
2722 if (GET_CODE (b) == REG)
2723 reg_b = REGNO (b);
2725 return reg_a != reg_b;
2729 /* Use a library function to move some bytes. */
2731 static void
2732 block_move_call (rtx dest_reg, rtx src_reg, rtx bytes_rtx)
2734 /* We want to pass the size as Pmode, which will normally be SImode
2735 but will be DImode if we are using 64 bit longs and pointers. */
2736 if (GET_MODE (bytes_rtx) != VOIDmode
2737 && GET_MODE (bytes_rtx) != Pmode)
2738 bytes_rtx = convert_to_mode (Pmode, bytes_rtx, 1);
2740 #ifdef TARGET_MEM_FUNCTIONS
2741 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "memcpy"), 0,
2742 VOIDmode, 3, dest_reg, Pmode, src_reg, Pmode,
2743 convert_to_mode (TYPE_MODE (sizetype), bytes_rtx,
2744 TREE_UNSIGNED (sizetype)),
2745 TYPE_MODE (sizetype));
2746 #else
2747 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, "bcopy"), 0,
2748 VOIDmode, 3, src_reg, Pmode, dest_reg, Pmode,
2749 convert_to_mode (TYPE_MODE (integer_type_node), bytes_rtx,
2750 TREE_UNSIGNED (integer_type_node)),
2751 TYPE_MODE (integer_type_node));
2752 #endif
2755 /* The maximum number of bytes to copy using pairs of load/store instructions.
2756 If a block is larger than this then a loop will be generated to copy
2757 MAX_MOVE_BYTES chunks at a time. The value of 32 is a semi-arbitrary choice.
2758 A customer uses Dhrystome as their benchmark, and Dhrystone has a 31 byte
2759 string copy in it. */
2760 #define MAX_MOVE_BYTES 32
2762 /* Expand string/block move operations.
2764 operands[0] is the pointer to the destination.
2765 operands[1] is the pointer to the source.
2766 operands[2] is the number of bytes to move.
2767 operands[3] is the alignment. */
2769 void
2770 m32r_expand_block_move (rtx operands[])
2772 rtx orig_dst = operands[0];
2773 rtx orig_src = operands[1];
2774 rtx bytes_rtx = operands[2];
2775 rtx align_rtx = operands[3];
2776 int constp = GET_CODE (bytes_rtx) == CONST_INT;
2777 HOST_WIDE_INT bytes = constp ? INTVAL (bytes_rtx) : 0;
2778 int align = INTVAL (align_rtx);
2779 int leftover;
2780 rtx src_reg;
2781 rtx dst_reg;
2783 if (constp && bytes <= 0)
2784 return;
2786 /* Move the address into scratch registers. */
2787 dst_reg = copy_addr_to_reg (XEXP (orig_dst, 0));
2788 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2790 if (align > UNITS_PER_WORD)
2791 align = UNITS_PER_WORD;
2793 /* If we prefer size over speed, always use a function call.
2794 If we do not know the size, use a function call.
2795 If the blocks are not word aligned, use a function call. */
2796 if (optimize_size || ! constp || align != UNITS_PER_WORD)
2798 block_move_call (dst_reg, src_reg, bytes_rtx);
2799 return;
2802 leftover = bytes % MAX_MOVE_BYTES;
2803 bytes -= leftover;
2805 /* If necessary, generate a loop to handle the bulk of the copy. */
2806 if (bytes)
2808 rtx label = NULL_RTX;
2809 rtx final_src = NULL_RTX;
2810 rtx at_a_time = GEN_INT (MAX_MOVE_BYTES);
2811 rtx rounded_total = GEN_INT (bytes);
2812 rtx new_dst_reg = gen_reg_rtx (SImode);
2813 rtx new_src_reg = gen_reg_rtx (SImode);
2815 /* If we are going to have to perform this loop more than
2816 once, then generate a label and compute the address the
2817 source register will contain upon completion of the final
2818 iteration. */
2819 if (bytes > MAX_MOVE_BYTES)
2821 final_src = gen_reg_rtx (Pmode);
2823 if (INT16_P(bytes))
2824 emit_insn (gen_addsi3 (final_src, src_reg, rounded_total));
2825 else
2827 emit_insn (gen_movsi (final_src, rounded_total));
2828 emit_insn (gen_addsi3 (final_src, final_src, src_reg));
2831 label = gen_label_rtx ();
2832 emit_label (label);
2835 /* It is known that output_block_move() will update src_reg to point
2836 to the word after the end of the source block, and dst_reg to point
2837 to the last word of the destination block, provided that the block
2838 is MAX_MOVE_BYTES long. */
2839 emit_insn (gen_movstrsi_internal (dst_reg, src_reg, at_a_time,
2840 new_dst_reg, new_src_reg));
2841 emit_move_insn (dst_reg, new_dst_reg);
2842 emit_move_insn (src_reg, new_src_reg);
2843 emit_insn (gen_addsi3 (dst_reg, dst_reg, GEN_INT (4)));
2845 if (bytes > MAX_MOVE_BYTES)
2847 emit_insn (gen_cmpsi (src_reg, final_src));
2848 emit_jump_insn (gen_bne (label));
2852 if (leftover)
2853 emit_insn (gen_movstrsi_internal (dst_reg, src_reg, GEN_INT (leftover),
2854 gen_reg_rtx (SImode),
2855 gen_reg_rtx (SImode)));
2859 /* Emit load/stores for a small constant word aligned block_move.
2861 operands[0] is the memory address of the destination.
2862 operands[1] is the memory address of the source.
2863 operands[2] is the number of bytes to move.
2864 operands[3] is a temp register.
2865 operands[4] is a temp register. */
2867 void
2868 m32r_output_block_move (rtx insn ATTRIBUTE_UNUSED, rtx operands[])
2870 HOST_WIDE_INT bytes = INTVAL (operands[2]);
2871 int first_time;
2872 int got_extra = 0;
2874 if (bytes < 1 || bytes > MAX_MOVE_BYTES)
2875 abort ();
2877 /* We do not have a post-increment store available, so the first set of
2878 stores are done without any increment, then the remaining ones can use
2879 the pre-increment addressing mode.
2881 Note: expand_block_move() also relies upon this behavior when building
2882 loops to copy large blocks. */
2883 first_time = 1;
2885 while (bytes > 0)
2887 if (bytes >= 8)
2889 if (first_time)
2891 output_asm_insn ("ld\t%5, %p1", operands);
2892 output_asm_insn ("ld\t%6, %p1", operands);
2893 output_asm_insn ("st\t%5, @%0", operands);
2894 output_asm_insn ("st\t%6, %s0", operands);
2896 else
2898 output_asm_insn ("ld\t%5, %p1", operands);
2899 output_asm_insn ("ld\t%6, %p1", operands);
2900 output_asm_insn ("st\t%5, %s0", operands);
2901 output_asm_insn ("st\t%6, %s0", operands);
2904 bytes -= 8;
2906 else if (bytes >= 4)
2908 if (bytes > 4)
2909 got_extra = 1;
2911 output_asm_insn ("ld\t%5, %p1", operands);
2913 if (got_extra)
2914 output_asm_insn ("ld\t%6, %p1", operands);
2916 if (first_time)
2917 output_asm_insn ("st\t%5, @%0", operands);
2918 else
2919 output_asm_insn ("st\t%5, %s0", operands);
2921 bytes -= 4;
2923 else
2925 /* Get the entire next word, even though we do not want all of it.
2926 The saves us from doing several smaller loads, and we assume that
2927 we cannot cause a page fault when at least part of the word is in
2928 valid memory [since we don't get called if things aren't properly
2929 aligned]. */
2930 int dst_offset = first_time ? 0 : 4;
2931 /* The amount of increment we have to make to the
2932 destination pointer. */
2933 int dst_inc_amount = dst_offset + bytes - 4;
2934 /* The same for the source pointer. */
2935 int src_inc_amount = bytes;
2936 int last_shift;
2937 rtx my_operands[3];
2939 /* If got_extra is true then we have already loaded
2940 the next word as part of loading and storing the previous word. */
2941 if (! got_extra)
2942 output_asm_insn ("ld\t%6, @%1", operands);
2944 if (bytes >= 2)
2946 bytes -= 2;
2948 output_asm_insn ("sra3\t%5, %6, #16", operands);
2949 my_operands[0] = operands[5];
2950 my_operands[1] = GEN_INT (dst_offset);
2951 my_operands[2] = operands[0];
2952 output_asm_insn ("sth\t%0, @(%1,%2)", my_operands);
2954 /* If there is a byte left to store then increment the
2955 destination address and shift the contents of the source
2956 register down by 8 bits. We could not do the address
2957 increment in the store half word instruction, because it does
2958 not have an auto increment mode. */
2959 if (bytes > 0) /* assert (bytes == 1) */
2961 dst_offset += 2;
2962 last_shift = 8;
2965 else
2966 last_shift = 24;
2968 if (bytes > 0)
2970 my_operands[0] = operands[6];
2971 my_operands[1] = GEN_INT (last_shift);
2972 output_asm_insn ("srai\t%0, #%1", my_operands);
2973 my_operands[0] = operands[6];
2974 my_operands[1] = GEN_INT (dst_offset);
2975 my_operands[2] = operands[0];
2976 output_asm_insn ("stb\t%0, @(%1,%2)", my_operands);
2979 /* Update the destination pointer if needed. We have to do
2980 this so that the patterns matches what we output in this
2981 function. */
2982 if (dst_inc_amount
2983 && !find_reg_note (insn, REG_UNUSED, operands[0]))
2985 my_operands[0] = operands[0];
2986 my_operands[1] = GEN_INT (dst_inc_amount);
2987 output_asm_insn ("addi\t%0, #%1", my_operands);
2990 /* Update the source pointer if needed. We have to do this
2991 so that the patterns matches what we output in this
2992 function. */
2993 if (src_inc_amount
2994 && !find_reg_note (insn, REG_UNUSED, operands[1]))
2996 my_operands[0] = operands[1];
2997 my_operands[1] = GEN_INT (src_inc_amount);
2998 output_asm_insn ("addi\t%0, #%1", my_operands);
3001 bytes = 0;
3004 first_time = 0;
3008 /* Return true if op is an integer constant, less than or equal to
3009 MAX_MOVE_BYTES. */
3012 m32r_block_immediate_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3014 if (GET_CODE (op) != CONST_INT
3015 || INTVAL (op) > MAX_MOVE_BYTES
3016 || INTVAL (op) <= 0)
3017 return 0;
3019 return 1;
3022 /* Return true if using NEW_REG in place of OLD_REG is ok. */
3025 m32r_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
3026 unsigned int new_reg)
3028 /* Interrupt routines can't clobber any register that isn't already used. */
3029 if (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl))
3030 && !regs_ever_live[new_reg])
3031 return 0;
3033 /* We currently emit epilogues as text, not rtl, so the liveness
3034 of the return address register isn't visible. */
3035 if (current_function_is_leaf && new_reg == RETURN_ADDR_REGNUM)
3036 return 0;
3038 return 1;