1 /* Subroutines used for code generation on the Mitsubishi M32R cpu.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; 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 /* Scheduler support */
61 static int m32r_sched_odd_word_p
;
63 /* Forward declaration. */
64 static void init_reg_tables
PARAMS ((void));
65 static void block_move_call
PARAMS ((rtx
, rtx
, rtx
));
66 static int m32r_is_insn
PARAMS ((rtx
));
67 const struct attribute_spec m32r_attribute_table
[];
68 static tree m32r_handle_model_attribute
PARAMS ((tree
*, tree
, tree
, int, bool *));
69 static void m32r_output_function_prologue
PARAMS ((FILE *, HOST_WIDE_INT
));
70 static void m32r_output_function_epilogue
PARAMS ((FILE *, HOST_WIDE_INT
));
72 static int m32r_adjust_cost
PARAMS ((rtx
, rtx
, rtx
, int));
73 static int m32r_adjust_priority
PARAMS ((rtx
, int));
74 static void m32r_sched_init
PARAMS ((FILE *, int, int));
75 static int m32r_sched_reorder
PARAMS ((FILE *, int, rtx
*, int *, int));
76 static int m32r_variable_issue
PARAMS ((FILE *, int, rtx
, int));
77 static int m32r_issue_rate
PARAMS ((void));
79 static void m32r_select_section
PARAMS ((tree
, int, unsigned HOST_WIDE_INT
));
80 static void m32r_encode_section_info
PARAMS ((tree
, int));
81 static const char *m32r_strip_name_encoding
PARAMS ((const char *));
82 static void init_idents
PARAMS ((void));
84 /* Initialize the GCC target structure. */
85 #undef TARGET_ATTRIBUTE_TABLE
86 #define TARGET_ATTRIBUTE_TABLE m32r_attribute_table
88 #undef TARGET_ASM_ALIGNED_HI_OP
89 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
90 #undef TARGET_ASM_ALIGNED_SI_OP
91 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
93 #undef TARGET_ASM_FUNCTION_PROLOGUE
94 #define TARGET_ASM_FUNCTION_PROLOGUE m32r_output_function_prologue
95 #undef TARGET_ASM_FUNCTION_EPILOGUE
96 #define TARGET_ASM_FUNCTION_EPILOGUE m32r_output_function_epilogue
98 #undef TARGET_SCHED_ADJUST_COST
99 #define TARGET_SCHED_ADJUST_COST m32r_adjust_cost
100 #undef TARGET_SCHED_ADJUST_PRIORITY
101 #define TARGET_SCHED_ADJUST_PRIORITY m32r_adjust_priority
102 #undef TARGET_SCHED_ISSUE_RATE
103 #define TARGET_SCHED_ISSUE_RATE m32r_issue_rate
104 #undef TARGET_SCHED_VARIABLE_ISSUE
105 #define TARGET_SCHED_VARIABLE_ISSUE m32r_variable_issue
106 #undef TARGET_SCHED_INIT
107 #define TARGET_SCHED_INIT m32r_sched_init
108 #undef TARGET_SCHED_REORDER
109 #define TARGET_SCHED_REORDER m32r_sched_reorder
111 #undef TARGET_ENCODE_SECTION_INFO
112 #define TARGET_ENCODE_SECTION_INFO m32r_encode_section_info
113 #undef TARGET_STRIP_NAME_ENCODING
114 #define TARGET_STRIP_NAME_ENCODING m32r_strip_name_encoding
116 struct gcc_target targetm
= TARGET_INITIALIZER
;
118 /* Called by OVERRIDE_OPTIONS to initialize various things. */
125 /* Initialize array for PRINT_OPERAND_PUNCT_VALID_P. */
126 memset (m32r_punct_chars
, 0, sizeof (m32r_punct_chars
));
127 m32r_punct_chars
['#'] = 1;
128 m32r_punct_chars
['@'] = 1; /* ??? no longer used */
130 /* Provide default value if not specified. */
132 g_switch_value
= SDATA_DEFAULT_SIZE
;
134 if (strcmp (m32r_model_string
, "small") == 0)
135 m32r_model
= M32R_MODEL_SMALL
;
136 else if (strcmp (m32r_model_string
, "medium") == 0)
137 m32r_model
= M32R_MODEL_MEDIUM
;
138 else if (strcmp (m32r_model_string
, "large") == 0)
139 m32r_model
= M32R_MODEL_LARGE
;
141 error ("bad value (%s) for -mmodel switch", m32r_model_string
);
143 if (strcmp (m32r_sdata_string
, "none") == 0)
144 m32r_sdata
= M32R_SDATA_NONE
;
145 else if (strcmp (m32r_sdata_string
, "sdata") == 0)
146 m32r_sdata
= M32R_SDATA_SDATA
;
147 else if (strcmp (m32r_sdata_string
, "use") == 0)
148 m32r_sdata
= M32R_SDATA_USE
;
150 error ("bad value (%s) for -msdata switch", m32r_sdata_string
);
153 /* Vectors to keep interesting information about registers where it can easily
154 be got. We use to use the actual mode value as the bit number, but there
155 is (or may be) more than 32 modes now. Instead we use two tables: one
156 indexed by hard register number, and one indexed by mode. */
158 /* The purpose of m32r_mode_class is to shrink the range of modes so that
159 they all fit (as bit numbers) in a 32 bit word (again). Each real mode is
160 mapped into one m32r_mode_class mode. */
165 S_MODE
, D_MODE
, T_MODE
, O_MODE
,
166 SF_MODE
, DF_MODE
, TF_MODE
, OF_MODE
, A_MODE
169 /* Modes for condition codes. */
170 #define C_MODES (1 << (int) C_MODE)
172 /* Modes for single-word and smaller quantities. */
173 #define S_MODES ((1 << (int) S_MODE) | (1 << (int) SF_MODE))
175 /* Modes for double-word and smaller quantities. */
176 #define D_MODES (S_MODES | (1 << (int) D_MODE) | (1 << DF_MODE))
178 /* Modes for quad-word and smaller quantities. */
179 #define T_MODES (D_MODES | (1 << (int) T_MODE) | (1 << (int) TF_MODE))
181 /* Modes for accumulators. */
182 #define A_MODES (1 << (int) A_MODE)
184 /* Value is 1 if register/mode pair is acceptable on arc. */
186 const unsigned int m32r_hard_regno_mode_ok
[FIRST_PSEUDO_REGISTER
] =
188 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
,
189 T_MODES
, T_MODES
, T_MODES
, T_MODES
, T_MODES
, S_MODES
, S_MODES
, S_MODES
,
190 S_MODES
, C_MODES
, A_MODES
, A_MODES
193 unsigned int m32r_mode_class
[NUM_MACHINE_MODES
];
195 enum reg_class m32r_regno_reg_class
[FIRST_PSEUDO_REGISTER
];
202 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
204 switch (GET_MODE_CLASS (i
))
207 case MODE_PARTIAL_INT
:
208 case MODE_COMPLEX_INT
:
209 if (GET_MODE_SIZE (i
) <= 4)
210 m32r_mode_class
[i
] = 1 << (int) S_MODE
;
211 else if (GET_MODE_SIZE (i
) == 8)
212 m32r_mode_class
[i
] = 1 << (int) D_MODE
;
213 else if (GET_MODE_SIZE (i
) == 16)
214 m32r_mode_class
[i
] = 1 << (int) T_MODE
;
215 else if (GET_MODE_SIZE (i
) == 32)
216 m32r_mode_class
[i
] = 1 << (int) O_MODE
;
218 m32r_mode_class
[i
] = 0;
221 case MODE_COMPLEX_FLOAT
:
222 if (GET_MODE_SIZE (i
) <= 4)
223 m32r_mode_class
[i
] = 1 << (int) SF_MODE
;
224 else if (GET_MODE_SIZE (i
) == 8)
225 m32r_mode_class
[i
] = 1 << (int) DF_MODE
;
226 else if (GET_MODE_SIZE (i
) == 16)
227 m32r_mode_class
[i
] = 1 << (int) TF_MODE
;
228 else if (GET_MODE_SIZE (i
) == 32)
229 m32r_mode_class
[i
] = 1 << (int) OF_MODE
;
231 m32r_mode_class
[i
] = 0;
235 /* mode_class hasn't been initialized yet for EXTRA_CC_MODES, so
236 we must explicitly check for them here. */
237 if (i
== (int) CCmode
)
238 m32r_mode_class
[i
] = 1 << (int) C_MODE
;
240 m32r_mode_class
[i
] = 0;
245 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
248 m32r_regno_reg_class
[i
] = GENERAL_REGS
;
249 else if (i
== ARG_POINTER_REGNUM
)
250 m32r_regno_reg_class
[i
] = GENERAL_REGS
;
252 m32r_regno_reg_class
[i
] = NO_REGS
;
256 /* M32R specific attribute support.
258 interrupt - for interrupt functions
260 model - select code model used to access object
262 small: addresses use 24 bits, use bl to make calls
263 medium: addresses use 32 bits, use bl to make calls
264 large: addresses use 32 bits, use seth/add3/jl to make calls
266 Grep for MODEL in m32r.h for more info.
269 static tree small_ident1
;
270 static tree small_ident2
;
271 static tree medium_ident1
;
272 static tree medium_ident2
;
273 static tree large_ident1
;
274 static tree large_ident2
;
279 if (small_ident1
== 0)
281 small_ident1
= get_identifier ("small");
282 small_ident2
= get_identifier ("__small__");
283 medium_ident1
= get_identifier ("medium");
284 medium_ident2
= get_identifier ("__medium__");
285 large_ident1
= get_identifier ("large");
286 large_ident2
= get_identifier ("__large__");
290 const struct attribute_spec m32r_attribute_table
[] =
292 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
293 { "interrupt", 0, 0, true, false, false, NULL
},
294 { "model", 1, 1, true, false, false, m32r_handle_model_attribute
},
295 { NULL
, 0, 0, false, false, false, NULL
}
299 /* Handle an "model" attribute; arguments as in
300 struct attribute_spec.handler. */
302 m32r_handle_model_attribute (node
, name
, args
, flags
, no_add_attrs
)
303 tree
*node ATTRIBUTE_UNUSED
;
306 int flags ATTRIBUTE_UNUSED
;
312 arg
= TREE_VALUE (args
);
314 if (arg
!= small_ident1
315 && arg
!= small_ident2
316 && arg
!= medium_ident1
317 && arg
!= medium_ident2
318 && arg
!= large_ident1
319 && arg
!= large_ident2
)
321 warning ("invalid argument of `%s' attribute",
322 IDENTIFIER_POINTER (name
));
323 *no_add_attrs
= true;
329 /* A C statement or statements to switch to the appropriate
330 section for output of DECL. DECL is either a `VAR_DECL' node
331 or a constant of some sort. RELOC indicates whether forming
332 the initial value of DECL requires link-time relocations. */
335 m32r_select_section (decl
, reloc
, align
)
338 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
340 if (TREE_CODE (decl
) == STRING_CST
)
342 if (! flag_writable_strings
)
343 readonly_data_section ();
347 else if (TREE_CODE (decl
) == VAR_DECL
)
349 if (SDATA_NAME_P (XSTR (XEXP (DECL_RTL (decl
), 0), 0)))
351 else if ((flag_pic
&& reloc
)
352 || !TREE_READONLY (decl
)
353 || TREE_SIDE_EFFECTS (decl
)
354 || !DECL_INITIAL (decl
)
355 || (DECL_INITIAL (decl
) != error_mark_node
356 && !TREE_CONSTANT (DECL_INITIAL (decl
))))
359 readonly_data_section ();
362 readonly_data_section ();
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 objects living in .sdata/.sbss are prefixed with SDATA_FLAG_CHAR
373 - what code model should be used to access the object
374 small: recorded with no flag - for space efficiency since they'll
376 medium: prefixed with MEDIUM_FLAG_CHAR
377 large: prefixed with LARGE_FLAG_CHAR
381 m32r_encode_section_info (decl
, first
)
391 switch (TREE_CODE (decl
))
395 model
= lookup_attribute ("model", DECL_ATTRIBUTES (decl
));
399 /* ??? document all others that can appear here */
404 /* Only mark the object as being small data area addressable if
405 it hasn't been explicitly marked with a code model.
407 The user can explicitly put an object in the small data area with the
408 section attribute. If the object is in sdata/sbss and marked with a
409 code model do both [put the object in .sdata and mark it as being
410 addressed with a specific code model - don't mark it as being addressed
411 with an SDA reloc though]. This is ok and might be useful at times. If
412 the object doesn't fit the linker will give an error. */
416 if (TREE_CODE_CLASS (TREE_CODE (decl
)) == 'd'
417 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
419 char *name
= (char *) TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
420 if (! strcmp (name
, ".sdata") || ! strcmp (name
, ".sbss"))
422 #if 0 /* ??? There's no reason to disallow this, is there? */
423 if (TREE_READONLY (decl
))
424 error_with_decl (decl
, "const objects cannot go in .sdata/.sbss");
426 prefix
= SDATA_FLAG_CHAR
;
431 if (TREE_CODE (decl
) == VAR_DECL
432 && ! TREE_READONLY (decl
)
433 && ! TARGET_SDATA_NONE
)
435 int size
= int_size_in_bytes (TREE_TYPE (decl
));
437 if (size
> 0 && size
<= g_switch_value
)
438 prefix
= SDATA_FLAG_CHAR
;
443 /* If data area not decided yet, check for a code model. */
452 id
= TREE_VALUE (TREE_VALUE (model
));
454 if (id
== small_ident1
|| id
== small_ident2
)
455 ; /* don't mark the symbol specially */
456 else if (id
== medium_ident1
|| id
== medium_ident2
)
457 prefix
= MEDIUM_FLAG_CHAR
;
458 else if (id
== large_ident1
|| id
== large_ident2
)
459 prefix
= LARGE_FLAG_CHAR
;
461 abort (); /* shouldn't happen */
465 if (TARGET_MODEL_SMALL
)
466 ; /* don't mark the symbol specially */
467 else if (TARGET_MODEL_MEDIUM
)
468 prefix
= MEDIUM_FLAG_CHAR
;
469 else if (TARGET_MODEL_LARGE
)
470 prefix
= LARGE_FLAG_CHAR
;
472 abort (); /* shouldn't happen */
478 rtx rtl
= (TREE_CODE_CLASS (TREE_CODE (decl
)) != 'd'
479 ? TREE_CST_RTL (decl
) : DECL_RTL (decl
));
480 const char *str
= XSTR (XEXP (rtl
, 0), 0);
481 int len
= strlen (str
);
482 char *newstr
= ggc_alloc (len
+ 2);
484 strcpy (newstr
+ 1, str
);
486 /* Note - we cannot leave the string in the ggc_alloc'ed space.
487 It must reside in the stringtable's domain. */
488 newstr
= (char *) ggc_alloc_string (newstr
, len
+ 2);
490 XSTR (XEXP (rtl
, 0), 0) = newstr
;
494 /* Undo the effects of the above. */
497 m32r_strip_name_encoding (str
)
500 str
+= ENCODED_NAME_P (str
);
505 /* Do anything needed before RTL is emitted for each function. */
508 m32r_init_expanders ()
510 /* ??? At one point there was code here. The function is left in
511 to make it easy to experiment. */
514 /* Acceptable arguments to the call insn. */
517 call_address_operand (op
, mode
)
519 enum machine_mode mode
;
521 return symbolic_operand (op
, mode
);
523 /* Constants and values in registers are not OK, because
524 the m32r BL instruction can only support PC relative branching. */
528 call_operand (op
, mode
)
530 enum machine_mode mode
;
532 if (GET_CODE (op
) != MEM
)
535 return call_address_operand (op
, mode
);
538 /* Returns 1 if OP is a symbol reference. */
541 symbolic_operand (op
, mode
)
543 enum machine_mode mode ATTRIBUTE_UNUSED
;
545 switch (GET_CODE (op
))
557 /* Return 1 if OP is a reference to an object in .sdata/.sbss. */
560 small_data_operand (op
, mode
)
562 enum machine_mode mode ATTRIBUTE_UNUSED
;
564 if (! TARGET_SDATA_USE
)
567 if (GET_CODE (op
) == SYMBOL_REF
)
568 return SDATA_NAME_P (XSTR (op
, 0));
570 if (GET_CODE (op
) == CONST
571 && GET_CODE (XEXP (op
, 0)) == PLUS
572 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
573 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
574 && INT16_P (INTVAL (XEXP (XEXP (op
, 0), 1))))
575 return SDATA_NAME_P (XSTR (XEXP (XEXP (op
, 0), 0), 0));
580 /* Return 1 if OP is a symbol that can use 24 bit addressing. */
583 addr24_operand (op
, mode
)
585 enum machine_mode mode ATTRIBUTE_UNUSED
;
587 if (GET_CODE (op
) == LABEL_REF
)
588 return TARGET_ADDR24
;
590 if (GET_CODE (op
) == SYMBOL_REF
)
591 return (SMALL_NAME_P (XSTR (op
, 0))
593 && (CONSTANT_POOL_ADDRESS_P (op
)
594 || LIT_NAME_P (XSTR (op
, 0)))));
596 if (GET_CODE (op
) == CONST
597 && GET_CODE (XEXP (op
, 0)) == PLUS
598 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
599 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
600 && UINT24_P (INTVAL (XEXP (XEXP (op
, 0), 1))))
602 rtx sym
= XEXP (XEXP (op
, 0), 0);
603 return (SMALL_NAME_P (XSTR (sym
, 0))
605 && (CONSTANT_POOL_ADDRESS_P (op
)
606 || LIT_NAME_P (XSTR (op
, 0)))));
612 /* Return 1 if OP is a symbol that needs 32 bit addressing. */
615 addr32_operand (op
, mode
)
617 enum machine_mode mode
;
619 if (GET_CODE (op
) == LABEL_REF
)
620 return TARGET_ADDR32
;
622 if (GET_CODE (op
) == SYMBOL_REF
)
623 return (! addr24_operand (op
, mode
)
624 && ! small_data_operand (op
, mode
));
626 if (GET_CODE (op
) == CONST
627 && GET_CODE (XEXP (op
, 0)) == PLUS
628 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
629 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
)
631 return (! addr24_operand (op
, mode
)
632 && ! small_data_operand (op
, mode
));
638 /* Return 1 if OP is a function that can be called with the `bl' insn. */
641 call26_operand (op
, mode
)
643 enum machine_mode mode ATTRIBUTE_UNUSED
;
645 if (GET_CODE (op
) == SYMBOL_REF
)
646 return ! LARGE_NAME_P (XSTR (op
, 0));
648 return TARGET_CALL26
;
651 /* Returns 1 if OP is an acceptable operand for seth/add3. */
654 seth_add3_operand (op
, mode
)
656 enum machine_mode mode ATTRIBUTE_UNUSED
;
658 if (GET_CODE (op
) == SYMBOL_REF
659 || GET_CODE (op
) == LABEL_REF
)
662 if (GET_CODE (op
) == CONST
663 && GET_CODE (XEXP (op
, 0)) == PLUS
664 && GET_CODE (XEXP (XEXP (op
, 0), 0)) == SYMBOL_REF
665 && GET_CODE (XEXP (XEXP (op
, 0), 1)) == CONST_INT
666 && INT16_P (INTVAL (XEXP (XEXP (op
, 0), 1))))
672 /* Return true if OP is a signed 8 bit immediate value. */
675 int8_operand (op
, mode
)
677 enum machine_mode mode ATTRIBUTE_UNUSED
;
679 if (GET_CODE (op
) != CONST_INT
)
681 return INT8_P (INTVAL (op
));
684 /* Return true if OP is a signed 16 bit immediate value
685 useful in comparisons. */
688 cmp_int16_operand (op
, mode
)
690 enum machine_mode mode ATTRIBUTE_UNUSED
;
692 if (GET_CODE (op
) != CONST_INT
)
694 return CMP_INT16_P (INTVAL (op
));
697 /* Return true if OP is an unsigned 16 bit immediate value. */
700 uint16_operand (op
, mode
)
702 enum machine_mode mode ATTRIBUTE_UNUSED
;
704 if (GET_CODE (op
) != CONST_INT
)
706 return UINT16_P (INTVAL (op
));
709 /* Return true if OP is a register or signed 16 bit value. */
712 reg_or_int16_operand (op
, mode
)
714 enum machine_mode mode
;
716 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
717 return register_operand (op
, mode
);
718 if (GET_CODE (op
) != CONST_INT
)
720 return INT16_P (INTVAL (op
));
723 /* Return true if OP is a register or an unsigned 16 bit value. */
726 reg_or_uint16_operand (op
, mode
)
728 enum machine_mode mode
;
730 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
731 return register_operand (op
, mode
);
732 if (GET_CODE (op
) != CONST_INT
)
734 return UINT16_P (INTVAL (op
));
737 /* Return true if OP is a register or an integer value that can be
738 used is SEQ/SNE. We can use either XOR of the value or ADD of
739 the negative of the value for the constant. Don't allow 0,
740 because that is special cased. */
743 reg_or_eq_int16_operand (op
, mode
)
745 enum machine_mode mode
;
749 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
750 return register_operand (op
, mode
);
752 if (GET_CODE (op
) != CONST_INT
)
756 return (value
!= 0) && (UINT16_P (value
) || CMP_INT16_P (-value
));
759 /* Return true if OP is a register or signed 16 bit value for compares. */
762 reg_or_cmp_int16_operand (op
, mode
)
764 enum machine_mode mode
;
766 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
767 return register_operand (op
, mode
);
768 if (GET_CODE (op
) != CONST_INT
)
770 return CMP_INT16_P (INTVAL (op
));
773 /* Return true if OP is a register or the constant 0. */
776 reg_or_zero_operand (op
, mode
)
778 enum machine_mode mode
;
780 if (GET_CODE (op
) == REG
|| GET_CODE (op
) == SUBREG
)
781 return register_operand (op
, mode
);
783 if (GET_CODE (op
) != CONST_INT
)
786 return INTVAL (op
) == 0;
789 /* Return true if OP is a const_int requiring two instructions to load. */
792 two_insn_const_operand (op
, mode
)
794 enum machine_mode mode ATTRIBUTE_UNUSED
;
796 if (GET_CODE (op
) != CONST_INT
)
798 if (INT16_P (INTVAL (op
))
799 || UINT24_P (INTVAL (op
))
800 || UPPER16_P (INTVAL (op
)))
805 /* Return true if OP is an acceptable argument for a single word
809 move_src_operand (op
, mode
)
811 enum machine_mode mode
;
813 switch (GET_CODE (op
))
817 return addr24_operand (op
, mode
);
819 /* ??? We allow more cse opportunities if we only allow constants
820 loadable with one insn, and split the rest into two. The instances
821 where this would help should be rare and the current way is
823 if (HOST_BITS_PER_WIDE_INT
> 32)
825 HOST_WIDE_INT rest
= INTVAL (op
) >> 31;
826 return (rest
== 0 || rest
== -1);
831 return TARGET_ADDR24
;
835 else if (mode
== SImode
)
837 /* Large unsigned constants are represented as const_double's. */
838 unsigned HOST_WIDE_INT low
, high
;
840 low
= CONST_DOUBLE_LOW (op
);
841 high
= CONST_DOUBLE_HIGH (op
);
842 return high
== 0 && low
<= 0xffffffff;
847 return register_operand (op
, mode
);
849 /* (subreg (mem ...) ...) can occur here if the inner part was once a
850 pseudo-reg and is now a stack slot. */
851 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
852 return address_operand (XEXP (SUBREG_REG (op
), 0), mode
);
854 return register_operand (op
, mode
);
856 if (GET_CODE (XEXP (op
, 0)) == PRE_INC
857 || GET_CODE (XEXP (op
, 0)) == PRE_DEC
)
858 return 0; /* loads can't do pre-{inc,dec} */
859 return address_operand (XEXP (op
, 0), mode
);
865 /* Return true if OP is an acceptable argument for a double word
869 move_double_src_operand (op
, mode
)
871 enum machine_mode mode
;
873 switch (GET_CODE (op
))
879 return register_operand (op
, mode
);
881 /* (subreg (mem ...) ...) can occur here if the inner part was once a
882 pseudo-reg and is now a stack slot. */
883 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
884 return move_double_src_operand (SUBREG_REG (op
), mode
);
886 return register_operand (op
, mode
);
888 /* Disallow auto inc/dec for now. */
889 if (GET_CODE (XEXP (op
, 0)) == PRE_DEC
890 || GET_CODE (XEXP (op
, 0)) == PRE_INC
)
892 return address_operand (XEXP (op
, 0), mode
);
898 /* Return true if OP is an acceptable argument for a move destination. */
901 move_dest_operand (op
, mode
)
903 enum machine_mode mode
;
905 switch (GET_CODE (op
))
908 return register_operand (op
, mode
);
910 /* (subreg (mem ...) ...) can occur here if the inner part was once a
911 pseudo-reg and is now a stack slot. */
912 if (GET_CODE (SUBREG_REG (op
)) == MEM
)
913 return address_operand (XEXP (SUBREG_REG (op
), 0), mode
);
915 return register_operand (op
, mode
);
917 if (GET_CODE (XEXP (op
, 0)) == POST_INC
)
918 return 0; /* stores can't do post inc */
919 return address_operand (XEXP (op
, 0), mode
);
925 /* Return 1 if OP is a DImode const we want to handle inline.
926 This must match the code in the movdi pattern.
927 It is used by the 'G' CONST_DOUBLE_OK_FOR_LETTER. */
933 rtx high_rtx
, low_rtx
;
934 HOST_WIDE_INT high
, low
;
936 split_double (op
, &high_rtx
, &low_rtx
);
937 high
= INTVAL (high_rtx
);
938 low
= INTVAL (low_rtx
);
939 /* Pick constants loadable with 2 16 bit `ldi' insns. */
940 if (high
>= -128 && high
<= 127
941 && low
>= -128 && low
<= 127)
946 /* Return 1 if OP is a DFmode const we want to handle inline.
947 This must match the code in the movdf pattern.
948 It is used by the 'H' CONST_DOUBLE_OK_FOR_LETTER. */
957 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
958 REAL_VALUE_TO_TARGET_DOUBLE (r
, l
);
959 if (l
[0] == 0 && l
[1] == 0)
961 if ((l
[0] & 0xffff) == 0 && l
[1] == 0)
966 /* Return 1 if OP is an EQ or NE comparison operator. */
969 eqne_comparison_operator (op
, mode
)
971 enum machine_mode mode ATTRIBUTE_UNUSED
;
973 enum rtx_code code
= GET_CODE (op
);
975 if (GET_RTX_CLASS (code
) != '<')
977 return (code
== EQ
|| code
== NE
);
980 /* Return 1 if OP is a signed comparison operator. */
983 signed_comparison_operator (op
, mode
)
985 enum machine_mode mode ATTRIBUTE_UNUSED
;
987 enum rtx_code code
= GET_CODE (op
);
989 if (GET_RTX_CLASS (code
) != '<')
991 return (code
== EQ
|| code
== NE
992 || code
== LT
|| code
== LE
|| code
== GT
|| code
== GE
);
995 /* Return 1 if OP is (mem (reg ...)).
996 This is used in insn length calcs. */
999 memreg_operand (op
, mode
)
1001 enum machine_mode mode ATTRIBUTE_UNUSED
;
1003 return GET_CODE (op
) == MEM
&& GET_CODE (XEXP (op
, 0)) == REG
;
1006 /* Return true if OP is an acceptable input argument for a zero/sign extend
1010 extend_operand (op
, mode
)
1012 enum machine_mode mode
;
1016 switch (GET_CODE (op
))
1020 return register_operand (op
, mode
);
1023 addr
= XEXP (op
, 0);
1024 if (GET_CODE (addr
) == PRE_INC
|| GET_CODE (addr
) == PRE_DEC
)
1025 return 0; /* loads can't do pre inc/pre dec */
1027 return address_operand (addr
, mode
);
1034 /* Return nonzero if the operand is an insn that is a small insn.
1035 Allow const_int 0 as well, which is a placeholder for NOP slots. */
1038 small_insn_p (op
, mode
)
1040 enum machine_mode mode ATTRIBUTE_UNUSED
;
1042 if (GET_CODE (op
) == CONST_INT
&& INTVAL (op
) == 0)
1048 return get_attr_length (op
) == 2;
1051 /* Return nonzero if the operand is an insn that is a large insn. */
1054 large_insn_p (op
, mode
)
1056 enum machine_mode mode ATTRIBUTE_UNUSED
;
1061 return get_attr_length (op
) != 2;
1067 /* X and Y are two things to compare using CODE. Emit the compare insn and
1068 return the rtx for compare [arg0 of the if_then_else].
1069 If need_compare is true then the comparison insn must be generated, rather
1070 than being susummed into the following branch instruction. */
1073 gen_compare (code
, x
, y
, need_compare
)
1078 enum rtx_code compare_code
, branch_code
;
1079 rtx cc_reg
= gen_rtx_REG (CCmode
, CARRY_REGNUM
);
1084 case EQ
: compare_code
= EQ
; branch_code
= NE
; break;
1085 case NE
: compare_code
= EQ
; branch_code
= EQ
; break;
1086 case LT
: compare_code
= LT
; branch_code
= NE
; break;
1087 case LE
: compare_code
= LT
; branch_code
= EQ
; must_swap
= 1; break;
1088 case GT
: compare_code
= LT
; branch_code
= NE
; must_swap
= 1; break;
1089 case GE
: compare_code
= LT
; branch_code
= EQ
; break;
1090 case LTU
: compare_code
= LTU
; branch_code
= NE
; break;
1091 case LEU
: compare_code
= LTU
; branch_code
= EQ
; must_swap
= 1; break;
1092 case GTU
: compare_code
= LTU
; branch_code
= NE
; must_swap
= 1; break;
1093 case GEU
: compare_code
= LTU
; branch_code
= EQ
; break;
1101 switch (compare_code
)
1104 if (GET_CODE (y
) == CONST_INT
1105 && CMP_INT16_P (INTVAL (y
)) /* reg equal to small const. */
1108 rtx tmp
= gen_reg_rtx (SImode
);
1110 emit_insn (gen_cmp_ne_small_const_insn (tmp
, x
, y
));
1114 else if (CONSTANT_P (y
)) /* reg equal to const. */
1116 rtx tmp
= force_reg (GET_MODE (x
), y
);
1120 if (register_operand (y
, SImode
) /* reg equal to reg. */
1121 || y
== const0_rtx
) /* req equal to zero. */
1123 emit_insn (gen_cmp_eqsi_insn (x
, y
));
1125 return gen_rtx (code
, CCmode
, cc_reg
, const0_rtx
);
1130 if (register_operand (y
, SImode
)
1131 || (GET_CODE (y
) == CONST_INT
&& CMP_INT16_P (INTVAL (y
))))
1133 rtx tmp
= gen_reg_rtx (SImode
); /* reg compared to reg. */
1138 emit_insn (gen_cmp_ltsi_insn (x
, y
));
1142 if (y
== const0_rtx
)
1145 emit_insn (gen_cmp_ne_small_const_insn (tmp
, y
, const1_rtx
));
1146 emit_insn (gen_cmp_ltsi_insn (x
, tmp
));
1150 if (GET_CODE (y
) == CONST_INT
)
1151 tmp
= gen_rtx (PLUS
, SImode
, y
, const1_rtx
);
1153 emit_insn (gen_cmp_ne_small_const_insn (tmp
, y
, const1_rtx
));
1154 emit_insn (gen_cmp_ltsi_insn (x
, tmp
));
1158 emit_insn (gen_cmp_ltsi_insn (x
, y
));
1165 return gen_rtx (code
, CCmode
, cc_reg
, const0_rtx
);
1170 if (register_operand (y
, SImode
)
1171 || (GET_CODE (y
) == CONST_INT
&& CMP_INT16_P (INTVAL (y
))))
1173 rtx tmp
= gen_reg_rtx (SImode
); /* reg (unsigned) compared to reg. */
1178 emit_insn (gen_cmp_ltusi_insn (x
, y
));
1182 if (y
== const0_rtx
)
1185 emit_insn (gen_cmp_ne_small_const_insn (tmp
, y
, const1_rtx
));
1186 emit_insn (gen_cmp_ltusi_insn (x
, tmp
));
1190 if (GET_CODE (y
) == CONST_INT
)
1191 tmp
= gen_rtx (PLUS
, SImode
, y
, const1_rtx
);
1193 emit_insn (gen_cmp_ne_small_const_insn (tmp
, y
, const1_rtx
));
1194 emit_insn (gen_cmp_ltusi_insn (x
, tmp
));
1198 emit_insn (gen_cmp_ltusi_insn (x
, y
));
1205 return gen_rtx (code
, CCmode
, cc_reg
, const0_rtx
);
1215 /* reg/reg equal comparison */
1216 if (compare_code
== EQ
1217 && register_operand (y
, SImode
))
1218 return gen_rtx (code
, CCmode
, x
, y
);
1220 /* reg/zero signed comparison */
1221 if ((compare_code
== EQ
|| compare_code
== LT
)
1223 return gen_rtx (code
, CCmode
, x
, y
);
1225 /* reg/smallconst equal comparison */
1226 if (compare_code
== EQ
1227 && GET_CODE (y
) == CONST_INT
1228 && CMP_INT16_P (INTVAL (y
)))
1230 rtx tmp
= gen_reg_rtx (SImode
);
1231 emit_insn (gen_cmp_ne_small_const_insn (tmp
, x
, y
));
1232 return gen_rtx (code
, CCmode
, tmp
, const0_rtx
);
1235 /* reg/const equal comparison */
1236 if (compare_code
== EQ
1239 rtx tmp
= force_reg (GET_MODE (x
), y
);
1240 return gen_rtx (code
, CCmode
, x
, tmp
);
1247 y
= force_reg (GET_MODE (x
), y
);
1251 (code
== LTU
|| code
== LEU
|| code
== GTU
|| code
== GEU
)
1252 ? uint16_operand (y
, GET_MODE (y
))
1253 : reg_or_cmp_int16_operand (y
, GET_MODE (y
));
1256 y
= force_reg (GET_MODE (x
), y
);
1260 switch (compare_code
)
1263 emit_insn (gen_cmp_eqsi_insn (must_swap
? y
: x
, must_swap
? x
: y
));
1266 emit_insn (gen_cmp_ltsi_insn (must_swap
? y
: x
, must_swap
? x
: y
));
1269 emit_insn (gen_cmp_ltusi_insn (must_swap
? y
: x
, must_swap
? x
: y
));
1276 return gen_rtx (branch_code
, VOIDmode
, cc_reg
, CONST0_RTX (CCmode
));
1279 /* Split a 2 word move (DI or DF) into component parts. */
1282 gen_split_move_double (operands
)
1285 enum machine_mode mode
= GET_MODE (operands
[0]);
1286 rtx dest
= operands
[0];
1287 rtx src
= operands
[1];
1290 /* We might have (SUBREG (MEM)) here, so just get rid of the
1291 subregs to make this code simpler. It is safe to call
1292 alter_subreg any time after reload. */
1293 if (GET_CODE (dest
) == SUBREG
)
1294 alter_subreg (&dest
);
1295 if (GET_CODE (src
) == SUBREG
)
1296 alter_subreg (&src
);
1299 if (GET_CODE (dest
) == REG
)
1301 int dregno
= REGNO (dest
);
1304 if (GET_CODE (src
) == REG
)
1306 int sregno
= REGNO (src
);
1308 int reverse
= (dregno
== sregno
+ 1);
1310 /* We normally copy the low-numbered register first. However, if
1311 the first register operand 0 is the same as the second register of
1312 operand 1, we must copy in the opposite order. */
1313 emit_insn (gen_rtx_SET (VOIDmode
,
1314 operand_subword (dest
, reverse
, TRUE
, mode
),
1315 operand_subword (src
, reverse
, TRUE
, mode
)));
1317 emit_insn (gen_rtx_SET (VOIDmode
,
1318 operand_subword (dest
, !reverse
, TRUE
, mode
),
1319 operand_subword (src
, !reverse
, TRUE
, mode
)));
1322 /* reg = constant */
1323 else if (GET_CODE (src
) == CONST_INT
|| GET_CODE (src
) == CONST_DOUBLE
)
1326 split_double (src
, &words
[0], &words
[1]);
1327 emit_insn (gen_rtx_SET (VOIDmode
,
1328 operand_subword (dest
, 0, TRUE
, mode
),
1331 emit_insn (gen_rtx_SET (VOIDmode
,
1332 operand_subword (dest
, 1, TRUE
, mode
),
1337 else if (GET_CODE (src
) == MEM
)
1339 /* If the high-address word is used in the address, we must load it
1340 last. Otherwise, load it first. */
1342 = (refers_to_regno_p (dregno
, dregno
+ 1, XEXP (src
, 0), 0) != 0);
1344 /* We used to optimize loads from single registers as
1348 if r3 were not used subsequently. However, the REG_NOTES aren't
1349 propigated correctly by the reload phase, and it can cause bad
1350 code to be generated. We could still try:
1352 ld r1,r3+; ld r2,r3; addi r3,-4
1354 which saves 2 bytes and doesn't force longword alignment. */
1355 emit_insn (gen_rtx_SET (VOIDmode
,
1356 operand_subword (dest
, reverse
, TRUE
, mode
),
1357 adjust_address (src
, SImode
,
1358 reverse
* UNITS_PER_WORD
)));
1360 emit_insn (gen_rtx_SET (VOIDmode
,
1361 operand_subword (dest
, !reverse
, TRUE
, mode
),
1362 adjust_address (src
, SImode
,
1363 !reverse
* UNITS_PER_WORD
)));
1371 /* We used to optimize loads from single registers as
1375 if r3 were not used subsequently. However, the REG_NOTES aren't
1376 propigated correctly by the reload phase, and it can cause bad
1377 code to be generated. We could still try:
1379 st r1,r3; st r2,+r3; addi r3,-4
1381 which saves 2 bytes and doesn't force longword alignment. */
1382 else if (GET_CODE (dest
) == MEM
&& GET_CODE (src
) == REG
)
1384 emit_insn (gen_rtx_SET (VOIDmode
,
1385 adjust_address (dest
, SImode
, 0),
1386 operand_subword (src
, 0, TRUE
, mode
)));
1388 emit_insn (gen_rtx_SET (VOIDmode
,
1389 adjust_address (dest
, SImode
, UNITS_PER_WORD
),
1390 operand_subword (src
, 1, TRUE
, mode
)));
1402 /* Implements the FUNCTION_ARG_PARTIAL_NREGS macro. */
1405 function_arg_partial_nregs (cum
, mode
, type
, named
)
1406 CUMULATIVE_ARGS
*cum
;
1407 enum machine_mode mode
;
1409 int named ATTRIBUTE_UNUSED
;
1413 (((mode
== BLKmode
&& type
)
1414 ? (unsigned int) int_size_in_bytes (type
)
1415 : GET_MODE_SIZE (mode
)) + UNITS_PER_WORD
- 1)
1418 if (*cum
>= M32R_MAX_PARM_REGS
)
1420 else if (*cum
+ size
> M32R_MAX_PARM_REGS
)
1421 ret
= (*cum
+ size
) - M32R_MAX_PARM_REGS
;
1428 /* Do any needed setup for a variadic function. For the M32R, we must
1429 create a register parameter block, and then copy any anonymous arguments
1430 in registers to memory.
1432 CUM has not been updated for the last named argument which has type TYPE
1433 and mode MODE, and we rely on this fact. */
1436 m32r_setup_incoming_varargs (cum
, mode
, type
, pretend_size
, no_rtl
)
1437 CUMULATIVE_ARGS
*cum
;
1438 enum machine_mode mode
;
1448 /* All BLKmode values are passed by reference. */
1449 if (mode
== BLKmode
)
1452 first_anon_arg
= (ROUND_ADVANCE_CUM (*cum
, mode
, type
)
1453 + ROUND_ADVANCE_ARG (mode
, type
));
1455 if (first_anon_arg
< M32R_MAX_PARM_REGS
)
1457 /* Note that first_reg_offset < M32R_MAX_PARM_REGS. */
1458 int first_reg_offset
= first_anon_arg
;
1459 /* Size in words to "pretend" allocate. */
1460 int size
= M32R_MAX_PARM_REGS
- first_reg_offset
;
1463 regblock
= gen_rtx_MEM (BLKmode
,
1464 plus_constant (arg_pointer_rtx
,
1465 FIRST_PARM_OFFSET (0)));
1466 set_mem_alias_set (regblock
, get_varargs_alias_set ());
1467 move_block_from_reg (first_reg_offset
, regblock
,
1468 size
, size
* UNITS_PER_WORD
);
1470 *pretend_size
= (size
* UNITS_PER_WORD
);
1475 /* Implement `va_arg'. */
1478 m32r_va_arg (valist
, type
)
1481 HOST_WIDE_INT size
, rsize
;
1485 size
= int_size_in_bytes (type
);
1486 rsize
= (size
+ UNITS_PER_WORD
- 1) & -UNITS_PER_WORD
;
1490 tree type_ptr
, type_ptr_ptr
;
1492 /* Pass by reference. */
1494 type_ptr
= build_pointer_type (type
);
1495 type_ptr_ptr
= build_pointer_type (type_ptr
);
1497 t
= build (POSTINCREMENT_EXPR
, va_list_type_node
, valist
,
1498 build_int_2 (UNITS_PER_WORD
, 0));
1499 TREE_SIDE_EFFECTS (t
) = 1;
1500 t
= build1 (NOP_EXPR
, type_ptr_ptr
, t
);
1501 TREE_SIDE_EFFECTS (t
) = 1;
1502 t
= build1 (INDIRECT_REF
, type_ptr
, t
);
1504 addr_rtx
= expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
1508 /* Pass by value. */
1510 if (size
< UNITS_PER_WORD
)
1512 /* Care for bigendian correction on the aligned address. */
1513 t
= build (PLUS_EXPR
, ptr_type_node
, valist
,
1514 build_int_2 (rsize
- size
, 0));
1515 addr_rtx
= expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
1516 addr_rtx
= copy_to_reg (addr_rtx
);
1519 t
= build (PLUS_EXPR
, va_list_type_node
, valist
,
1520 build_int_2 (rsize
, 0));
1521 t
= build (MODIFY_EXPR
, va_list_type_node
, valist
, t
);
1522 TREE_SIDE_EFFECTS (t
) = 1;
1523 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
1527 t
= build (POSTINCREMENT_EXPR
, va_list_type_node
, valist
,
1528 build_int_2 (rsize
, 0));
1529 TREE_SIDE_EFFECTS (t
) = 1;
1530 addr_rtx
= expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
1538 m32r_adjust_cost (insn
, link
, dep_insn
, cost
)
1539 rtx insn ATTRIBUTE_UNUSED
;
1540 rtx link ATTRIBUTE_UNUSED
;
1541 rtx dep_insn ATTRIBUTE_UNUSED
;
1548 /* Return true if INSN is real instruction bearing insn. */
1554 return (INSN_P (insn
)
1555 && GET_CODE (PATTERN (insn
)) != USE
1556 && GET_CODE (PATTERN (insn
)) != CLOBBER
1557 && GET_CODE (PATTERN (insn
)) != ADDR_VEC
);
1560 /* Increase the priority of long instructions so that the
1561 short instructions are scheduled ahead of the long ones. */
1564 m32r_adjust_priority (insn
, priority
)
1568 if (m32r_is_insn (insn
)
1569 && get_attr_insn_size (insn
) != INSN_SIZE_SHORT
)
1576 /* Initialize for scheduling a group of instructions. */
1579 m32r_sched_init (stream
, verbose
, max_ready
)
1580 FILE * stream ATTRIBUTE_UNUSED
;
1581 int verbose ATTRIBUTE_UNUSED
;
1582 int max_ready ATTRIBUTE_UNUSED
;
1584 m32r_sched_odd_word_p
= FALSE
;
1588 /* Reorder the schedulers priority list if needed */
1591 m32r_sched_reorder (stream
, verbose
, ready
, n_readyp
, clock
)
1596 int clock ATTRIBUTE_UNUSED
;
1598 int n_ready
= *n_readyp
;
1601 return m32r_issue_rate ();
1608 ";;\t\t::: Looking at %d insn(s) on ready list, boundary is %s word\n",
1610 (m32r_sched_odd_word_p
) ? "odd" : "even");
1614 rtx
* long_head
= (rtx
*) alloca (sizeof (rtx
) * n_ready
);
1615 rtx
* long_tail
= long_head
;
1616 rtx
* short_head
= (rtx
*) alloca (sizeof (rtx
) * n_ready
);
1617 rtx
* short_tail
= short_head
;
1618 rtx
* new_head
= (rtx
*) alloca (sizeof (rtx
) * n_ready
);
1619 rtx
* new_tail
= new_head
+ (n_ready
- 1);
1622 /* Loop through the instructions, classifing them as short/long. Try
1623 to keep 2 short together and/or 1 long. Note, the ready list is
1624 actually ordered backwards, so keep it in that manner. */
1625 for (i
= n_ready
-1; i
>= 0; i
--)
1627 rtx insn
= ready
[i
];
1629 if (! m32r_is_insn (insn
))
1631 /* Dump all current short/long insns just in case. */
1632 while (long_head
!= long_tail
)
1633 *new_tail
-- = *long_head
++;
1635 while (short_head
!= short_tail
)
1636 *new_tail
-- = *short_head
++;
1641 ";;\t\t::: Skipping non instruction %d\n",
1648 if (get_attr_insn_size (insn
) != INSN_SIZE_SHORT
)
1649 *long_tail
++ = insn
;
1652 *short_tail
++ = insn
;
1656 /* If we are on an odd word, emit a single short instruction if
1658 if (m32r_sched_odd_word_p
&& short_head
!= short_tail
)
1659 *new_tail
-- = *short_head
++;
1661 /* Now dump out all of the long instructions */
1662 while (long_head
!= long_tail
)
1663 *new_tail
-- = *long_head
++;
1665 /* Now dump out all of the short instructions */
1666 while (short_head
!= short_tail
)
1667 *new_tail
-- = *short_head
++;
1669 if (new_tail
+1 != new_head
)
1672 memcpy (ready
, new_head
, sizeof (rtx
) * n_ready
);
1676 fprintf (stream
, ";;\t\t::: New ready list: ");
1677 for (i
= 0; i
< n_ready
; i
++)
1679 rtx insn
= ready
[i
];
1681 fprintf (stream
, " %d", INSN_UID (ready
[i
]));
1683 if (! m32r_is_insn (insn
))
1684 fputs ("(?)", stream
);
1686 else if (get_attr_insn_size (insn
) != INSN_SIZE_SHORT
)
1687 fputs ("(l)", stream
);
1690 fputs ("(s)", stream
);
1693 fprintf (stream
, "\n");
1696 return m32r_issue_rate ();
1699 /* Indicate how many instructions can be issued at the same time.
1700 This is sort of a lie. The m32r can issue only 1 long insn at
1701 once, but it can issue 2 short insns. The default therefore is
1702 set at 2, but this can be overridden by the command line option
1707 return ((TARGET_LOW_ISSUE_RATE
) ? 1 : 2);
1710 /* If we have a machine that can issue a variable # of instructions
1711 per cycle, indicate how many more instructions can be issued
1712 after the current one. */
1714 m32r_variable_issue (stream
, verbose
, insn
, how_many
)
1720 int orig_odd_word_p
= m32r_sched_odd_word_p
;
1721 int short_p
= FALSE
;
1724 if (how_many
> 0 && !TARGET_DEBUG
)
1726 if (! m32r_is_insn (insn
))
1729 else if (get_attr_insn_size (insn
) != INSN_SIZE_SHORT
)
1732 m32r_sched_odd_word_p
= 0;
1736 m32r_sched_odd_word_p
= !m32r_sched_odd_word_p
;
1741 if (verbose
> 7 && stream
)
1743 ";;\t\t::: %s insn %d starts on an %s word, can emit %d more instruction(s)\n",
1744 short_p
? "short" : "long",
1746 orig_odd_word_p
? "odd" : "even",
1752 /* Cost functions. */
1754 /* Provide the costs of an addressing mode that contains ADDR.
1755 If ADDR is not a valid address, its cost is irrelevant.
1757 This function is trivial at the moment. This code doesn't live
1758 in m32r.h so it's easy to experiment. */
1761 m32r_address_cost (addr
)
1762 rtx addr ATTRIBUTE_UNUSED
;
1767 /* Type of function DECL.
1769 The result is cached. To reset the cache at the end of a function,
1770 call with DECL = NULL_TREE. */
1772 enum m32r_function_type
1773 m32r_compute_function_type (decl
)
1777 static enum m32r_function_type fn_type
= M32R_FUNCTION_UNKNOWN
;
1778 /* Last function we were called for. */
1779 static tree last_fn
= NULL_TREE
;
1781 /* Resetting the cached value? */
1782 if (decl
== NULL_TREE
)
1784 fn_type
= M32R_FUNCTION_UNKNOWN
;
1785 last_fn
= NULL_TREE
;
1789 if (decl
== last_fn
&& fn_type
!= M32R_FUNCTION_UNKNOWN
)
1792 /* Compute function type. */
1793 fn_type
= (lookup_attribute ("interrupt", DECL_ATTRIBUTES (current_function_decl
)) != NULL_TREE
1794 ? M32R_FUNCTION_INTERRUPT
1795 : M32R_FUNCTION_NORMAL
);
1800 \f/* Function prologue/epilogue handlers. */
1802 /* M32R stack frames look like:
1804 Before call After call
1805 +-----------------------+ +-----------------------+
1807 high | local variables, | | local variables, |
1808 mem | reg save area, etc. | | reg save area, etc. |
1810 +-----------------------+ +-----------------------+
1812 | arguments on stack. | | arguments on stack. |
1814 SP+0->+-----------------------+ +-----------------------+
1815 | reg parm save area, |
1816 | only created for |
1817 | variable argument |
1819 +-----------------------+
1820 | previous frame ptr |
1821 +-----------------------+
1823 | register save area |
1825 +-----------------------+
1827 +-----------------------+
1831 +-----------------------+
1833 | alloca allocations |
1835 +-----------------------+
1837 low | arguments on stack |
1839 SP+0->+-----------------------+
1842 1) The "reg parm save area" does not exist for non variable argument fns.
1843 2) The "reg parm save area" can be eliminated completely if we saved regs
1844 containing anonymous args separately but that complicates things too
1845 much (so it's not done).
1846 3) The return address is saved after the register save area so as to have as
1847 many insns as possible between the restoration of `lr' and the `jmp lr'.
1850 /* Structure to be filled in by m32r_compute_frame_size with register
1851 save masks, and offsets for the current function. */
1852 struct m32r_frame_info
1854 unsigned int total_size
; /* # bytes that the entire frame takes up */
1855 unsigned int extra_size
; /* # bytes of extra stuff */
1856 unsigned int pretend_size
; /* # bytes we push and pretend caller did */
1857 unsigned int args_size
; /* # bytes that outgoing arguments take up */
1858 unsigned int reg_size
; /* # bytes needed to store regs */
1859 unsigned int var_size
; /* # bytes that variables take up */
1860 unsigned int gmask
; /* mask of saved gp registers */
1861 unsigned int save_fp
; /* nonzero if fp must be saved */
1862 unsigned int save_lr
; /* nonzero if lr (return addr) must be saved */
1863 int initialized
; /* nonzero if frame size already calculated */
1866 /* Current frame information calculated by m32r_compute_frame_size. */
1867 static struct m32r_frame_info current_frame_info
;
1869 /* Zero structure to initialize current_frame_info. */
1870 static struct m32r_frame_info zero_frame_info
;
1872 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
1873 #define RETURN_ADDR_MASK (1 << (RETURN_ADDR_REGNUM))
1875 /* Tell prologue and epilogue if register REGNO should be saved / restored.
1876 The return address and frame pointer are treated separately.
1877 Don't consider them here. */
1878 #define MUST_SAVE_REGISTER(regno, interrupt_p) \
1879 ((regno) != RETURN_ADDR_REGNUM && (regno) != FRAME_POINTER_REGNUM \
1880 && (regs_ever_live[regno] && (!call_used_regs[regno] || interrupt_p)))
1882 #define MUST_SAVE_FRAME_POINTER (regs_ever_live[FRAME_POINTER_REGNUM])
1883 #define MUST_SAVE_RETURN_ADDR (regs_ever_live[RETURN_ADDR_REGNUM] || current_function_profile)
1885 #define SHORT_INSN_SIZE 2 /* size of small instructions */
1886 #define LONG_INSN_SIZE 4 /* size of long instructions */
1888 /* Return the bytes needed to compute the frame pointer from the current
1891 SIZE is the size needed for local variables. */
1894 m32r_compute_frame_size (size
)
1895 int size
; /* # of var. bytes allocated. */
1898 unsigned int total_size
, var_size
, args_size
, pretend_size
, extra_size
;
1899 unsigned int reg_size
, frame_size
;
1901 enum m32r_function_type fn_type
;
1904 var_size
= M32R_STACK_ALIGN (size
);
1905 args_size
= M32R_STACK_ALIGN (current_function_outgoing_args_size
);
1906 pretend_size
= current_function_pretend_args_size
;
1907 extra_size
= FIRST_PARM_OFFSET (0);
1908 total_size
= extra_size
+ pretend_size
+ args_size
+ var_size
;
1912 /* See if this is an interrupt handler. Call used registers must be saved
1914 fn_type
= m32r_compute_function_type (current_function_decl
);
1915 interrupt_p
= M32R_INTERRUPT_P (fn_type
);
1917 /* Calculate space needed for registers. */
1919 for (regno
= 0; regno
< M32R_MAX_INT_REGS
; regno
++)
1921 if (MUST_SAVE_REGISTER (regno
, interrupt_p
))
1923 reg_size
+= UNITS_PER_WORD
;
1924 gmask
|= 1 << regno
;
1928 current_frame_info
.save_fp
= MUST_SAVE_FRAME_POINTER
;
1929 current_frame_info
.save_lr
= MUST_SAVE_RETURN_ADDR
;
1931 reg_size
+= ((current_frame_info
.save_fp
+ current_frame_info
.save_lr
)
1933 total_size
+= reg_size
;
1935 /* ??? Not sure this is necessary, and I don't think the epilogue
1936 handler will do the right thing if this changes total_size. */
1937 total_size
= M32R_STACK_ALIGN (total_size
);
1939 frame_size
= total_size
- (pretend_size
+ reg_size
);
1941 /* Save computed information. */
1942 current_frame_info
.total_size
= total_size
;
1943 current_frame_info
.extra_size
= extra_size
;
1944 current_frame_info
.pretend_size
= pretend_size
;
1945 current_frame_info
.var_size
= var_size
;
1946 current_frame_info
.args_size
= args_size
;
1947 current_frame_info
.reg_size
= reg_size
;
1948 current_frame_info
.gmask
= gmask
;
1949 current_frame_info
.initialized
= reload_completed
;
1951 /* Ok, we're done. */
1955 /* When the `length' insn attribute is used, this macro specifies the
1956 value to be assigned to the address of the first insn in a
1957 function. If not specified, 0 is used. */
1960 m32r_first_insn_address ()
1962 if (! current_frame_info
.initialized
)
1963 m32r_compute_frame_size (get_frame_size ());
1968 /* Expand the m32r prologue as a series of insns. */
1971 m32r_expand_prologue ()
1977 if (! current_frame_info
.initialized
)
1978 m32r_compute_frame_size (get_frame_size ());
1980 gmask
= current_frame_info
.gmask
;
1982 /* These cases shouldn't happen. Catch them now. */
1983 if (current_frame_info
.total_size
== 0 && gmask
)
1986 /* Allocate space for register arguments if this is a variadic function. */
1987 if (current_frame_info
.pretend_size
!= 0)
1989 /* Use a HOST_WIDE_INT temporary, since negating an unsigned int gives
1990 the wrong result on a 64-bit host. */
1991 HOST_WIDE_INT pretend_size
= current_frame_info
.pretend_size
;
1992 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1994 GEN_INT (-pretend_size
)));
1997 /* Save any registers we need to and set up fp. */
1999 if (current_frame_info
.save_fp
)
2000 emit_insn (gen_movsi_push (stack_pointer_rtx
, frame_pointer_rtx
));
2002 gmask
&= ~(FRAME_POINTER_MASK
| RETURN_ADDR_MASK
);
2004 /* Save any needed call-saved regs (and call-used if this is an
2005 interrupt handler). */
2006 for (regno
= 0; regno
<= M32R_MAX_INT_REGS
; ++regno
)
2008 if ((gmask
& (1 << regno
)) != 0)
2009 emit_insn (gen_movsi_push (stack_pointer_rtx
,
2010 gen_rtx_REG (Pmode
, regno
)));
2013 if (current_frame_info
.save_lr
)
2014 emit_insn (gen_movsi_push (stack_pointer_rtx
,
2015 gen_rtx_REG (Pmode
, RETURN_ADDR_REGNUM
)));
2017 /* Allocate the stack frame. */
2018 frame_size
= (current_frame_info
.total_size
2019 - (current_frame_info
.pretend_size
2020 + current_frame_info
.reg_size
));
2022 if (frame_size
== 0)
2023 ; /* nothing to do */
2024 else if (frame_size
<= 32768)
2025 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2026 GEN_INT (-frame_size
)));
2029 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
2030 emit_insn (gen_movsi (tmp
, GEN_INT (frame_size
)));
2031 emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
, tmp
));
2034 if (frame_pointer_needed
)
2035 emit_insn (gen_movsi (frame_pointer_rtx
, stack_pointer_rtx
));
2037 if (current_function_profile
)
2038 emit_insn (gen_blockage ());
2042 /* Set up the stack and frame pointer (if desired) for the function.
2043 Note, if this is changed, you need to mirror the changes in
2044 m32r_compute_frame_size which calculates the prolog size. */
2047 m32r_output_function_prologue (file
, size
)
2051 enum m32r_function_type fn_type
= m32r_compute_function_type (current_function_decl
);
2053 /* If this is an interrupt handler, mark it as such. */
2054 if (M32R_INTERRUPT_P (fn_type
))
2056 fprintf (file
, "\t%s interrupt handler\n",
2060 if (! current_frame_info
.initialized
)
2061 m32r_compute_frame_size (size
);
2063 /* This is only for the human reader. */
2065 "\t%s PROLOGUE, vars= %d, regs= %d, args= %d, extra= %d\n",
2067 current_frame_info
.var_size
,
2068 current_frame_info
.reg_size
/ 4,
2069 current_frame_info
.args_size
,
2070 current_frame_info
.extra_size
);
2073 /* Do any necessary cleanup after a function to restore stack, frame,
2077 m32r_output_function_epilogue (file
, size
)
2079 HOST_WIDE_INT size ATTRIBUTE_UNUSED
;
2082 int noepilogue
= FALSE
;
2084 enum m32r_function_type fn_type
= m32r_compute_function_type (current_function_decl
);
2086 /* This is only for the human reader. */
2087 fprintf (file
, "\t%s EPILOGUE\n", ASM_COMMENT_START
);
2089 if (!current_frame_info
.initialized
)
2091 total_size
= current_frame_info
.total_size
;
2093 if (total_size
== 0)
2095 rtx insn
= get_last_insn ();
2097 /* If the last insn was a BARRIER, we don't have to write any code
2098 because a jump (aka return) was put there. */
2099 if (GET_CODE (insn
) == NOTE
)
2100 insn
= prev_nonnote_insn (insn
);
2101 if (insn
&& GET_CODE (insn
) == BARRIER
)
2107 unsigned int var_size
= current_frame_info
.var_size
;
2108 unsigned int args_size
= current_frame_info
.args_size
;
2109 unsigned int gmask
= current_frame_info
.gmask
;
2110 int can_trust_sp_p
= !current_function_calls_alloca
;
2111 const char * sp_str
= reg_names
[STACK_POINTER_REGNUM
];
2112 const char * fp_str
= reg_names
[FRAME_POINTER_REGNUM
];
2114 /* The first thing to do is point the sp at the bottom of the register
2118 unsigned int reg_offset
= var_size
+ args_size
;
2119 if (reg_offset
== 0)
2120 ; /* nothing to do */
2121 else if (reg_offset
< 128)
2122 fprintf (file
, "\taddi %s,%s%d\n",
2123 sp_str
, IMMEDIATE_PREFIX
, reg_offset
);
2124 else if (reg_offset
< 32768)
2125 fprintf (file
, "\tadd3 %s,%s,%s%d\n",
2126 sp_str
, sp_str
, IMMEDIATE_PREFIX
, reg_offset
);
2128 fprintf (file
, "\tld24 %s,%s%d\n\tadd %s,%s\n",
2129 reg_names
[PROLOGUE_TMP_REGNUM
],
2130 IMMEDIATE_PREFIX
, reg_offset
,
2131 sp_str
, reg_names
[PROLOGUE_TMP_REGNUM
]);
2133 else if (frame_pointer_needed
)
2135 unsigned int reg_offset
= var_size
+ args_size
;
2136 if (reg_offset
== 0)
2137 fprintf (file
, "\tmv %s,%s\n", sp_str
, fp_str
);
2138 else if (reg_offset
< 32768)
2139 fprintf (file
, "\tadd3 %s,%s,%s%d\n",
2140 sp_str
, fp_str
, IMMEDIATE_PREFIX
, reg_offset
);
2142 fprintf (file
, "\tld24 %s,%s%d\n\tadd %s,%s\n",
2143 reg_names
[PROLOGUE_TMP_REGNUM
],
2144 IMMEDIATE_PREFIX
, reg_offset
,
2145 sp_str
, reg_names
[PROLOGUE_TMP_REGNUM
]);
2150 if (current_frame_info
.save_lr
)
2151 fprintf (file
, "\tpop %s\n", reg_names
[RETURN_ADDR_REGNUM
]);
2153 /* Restore any saved registers, in reverse order of course. */
2154 gmask
&= ~(FRAME_POINTER_MASK
| RETURN_ADDR_MASK
);
2155 for (regno
= M32R_MAX_INT_REGS
- 1; regno
>= 0; --regno
)
2157 if ((gmask
& (1L << regno
)) != 0)
2158 fprintf (file
, "\tpop %s\n", reg_names
[regno
]);
2161 if (current_frame_info
.save_fp
)
2162 fprintf (file
, "\tpop %s\n", fp_str
);
2164 /* Remove varargs area if present. */
2165 if (current_frame_info
.pretend_size
!= 0)
2166 fprintf (file
, "\taddi %s,%s%d\n",
2167 sp_str
, IMMEDIATE_PREFIX
, current_frame_info
.pretend_size
);
2169 /* Emit the return instruction. */
2170 if (M32R_INTERRUPT_P (fn_type
))
2171 fprintf (file
, "\trte\n");
2173 fprintf (file
, "\tjmp %s\n", reg_names
[RETURN_ADDR_REGNUM
]);
2176 #if 0 /* no longer needed */
2177 /* Ensure the function cleanly ends on a 32 bit boundary. */
2178 fprintf (file
, "\t.fillinsn\n");
2181 /* Reset state info for each function. */
2182 current_frame_info
= zero_frame_info
;
2183 m32r_compute_function_type (NULL_TREE
);
2186 /* Return nonzero if this function is known to have a null or 1 instruction
2192 if (!reload_completed
)
2195 if (! current_frame_info
.initialized
)
2196 m32r_compute_frame_size (get_frame_size ());
2198 return current_frame_info
.total_size
== 0;
2204 /* Emit special PIC prologues and epilogues. */
2207 m32r_finalize_pic ()
2212 /* Nested function support. */
2214 /* Emit RTL insns to initialize the variable parts of a trampoline.
2215 FNADDR is an RTX for the address of the function's pure code.
2216 CXT is an RTX for the static chain value for the function. */
2219 m32r_initialize_trampoline (tramp
, fnaddr
, cxt
)
2220 rtx tramp ATTRIBUTE_UNUSED
;
2221 rtx fnaddr ATTRIBUTE_UNUSED
;
2222 rtx cxt ATTRIBUTE_UNUSED
;
2226 /* Set the cpu type and print out other fancy things,
2227 at the top of the file. */
2230 m32r_asm_file_start (file
)
2233 if (flag_verbose_asm
)
2234 fprintf (file
, "%s M32R/D special options: -G %d\n",
2235 ASM_COMMENT_START
, g_switch_value
);
2238 /* Print operand X (an rtx) in assembler syntax to file FILE.
2239 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
2240 For `%' followed by punctuation, CODE is the punctuation and X is null. */
2243 m32r_print_operand (file
, x
, code
)
2252 /* The 's' and 'p' codes are used by output_block_move() to
2253 indicate post-increment 's'tores and 'p're-increment loads. */
2255 if (GET_CODE (x
) == REG
)
2256 fprintf (file
, "@+%s", reg_names
[REGNO (x
)]);
2258 output_operand_lossage ("invalid operand to %%s code");
2262 if (GET_CODE (x
) == REG
)
2263 fprintf (file
, "@%s+", reg_names
[REGNO (x
)]);
2265 output_operand_lossage ("invalid operand to %%p code");
2269 /* Write second word of DImode or DFmode reference,
2270 register or memory. */
2271 if (GET_CODE (x
) == REG
)
2272 fputs (reg_names
[REGNO (x
)+1], file
);
2273 else if (GET_CODE (x
) == MEM
)
2275 fprintf (file
, "@(");
2276 /* Handle possible auto-increment. Since it is pre-increment and
2277 we have already done it, we can just use an offset of four. */
2278 /* ??? This is taken from rs6000.c I think. I don't think it is
2279 currently necessary, but keep it around. */
2280 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
2281 || GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
2282 output_address (plus_constant (XEXP (XEXP (x
, 0), 0), 4));
2284 output_address (plus_constant (XEXP (x
, 0), 4));
2288 output_operand_lossage ("invalid operand to %%R code");
2291 case 'H' : /* High word */
2292 case 'L' : /* Low word */
2293 if (GET_CODE (x
) == REG
)
2295 /* L = least significant word, H = most significant word */
2296 if ((WORDS_BIG_ENDIAN
!= 0) ^ (code
== 'L'))
2297 fputs (reg_names
[REGNO (x
)], file
);
2299 fputs (reg_names
[REGNO (x
)+1], file
);
2301 else if (GET_CODE (x
) == CONST_INT
2302 || GET_CODE (x
) == CONST_DOUBLE
)
2306 split_double (x
, &first
, &second
);
2307 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
,
2308 code
== 'L' ? INTVAL (first
) : INTVAL (second
));
2311 output_operand_lossage ("invalid operand to %%H/%%L code");
2318 if (GET_CODE (x
) != CONST_DOUBLE
2319 || GET_MODE_CLASS (GET_MODE (x
)) != MODE_FLOAT
)
2320 fatal_insn ("bad insn for 'A'", x
);
2322 real_to_decimal (str
, CONST_DOUBLE_REAL_VALUE (x
), sizeof (str
), 0, 1);
2323 fprintf (file
, "%s", str
);
2327 case 'B' : /* Bottom half */
2328 case 'T' : /* Top half */
2329 /* Output the argument to a `seth' insn (sets the Top half-word).
2330 For constants output arguments to a seth/or3 pair to set Top and
2331 Bottom halves. For symbols output arguments to a seth/add3 pair to
2332 set Top and Bottom halves. The difference exists because for
2333 constants seth/or3 is more readable but for symbols we need to use
2334 the same scheme as `ld' and `st' insns (16 bit addend is signed). */
2335 switch (GET_CODE (x
))
2342 split_double (x
, &first
, &second
);
2343 x
= WORDS_BIG_ENDIAN
? second
: first
;
2345 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2351 ? INTVAL (x
) & 0xffff
2352 : (INTVAL (x
) >> 16) & 0xffff));
2358 && small_data_operand (x
, VOIDmode
))
2360 fputs ("sda(", file
);
2361 output_addr_const (file
, x
);
2367 fputs (code
== 'T' ? "shigh(" : "low(", file
);
2368 output_addr_const (file
, x
);
2372 output_operand_lossage ("invalid operand to %%T/%%B code");
2379 /* Output a load/store with update indicator if appropriate. */
2380 if (GET_CODE (x
) == MEM
)
2382 if (GET_CODE (XEXP (x
, 0)) == PRE_INC
2383 || GET_CODE (XEXP (x
, 0)) == PRE_DEC
)
2387 output_operand_lossage ("invalid operand to %%U code");
2391 /* Print a constant value negated. */
2392 if (GET_CODE (x
) == CONST_INT
)
2393 output_addr_const (file
, GEN_INT (- INTVAL (x
)));
2395 output_operand_lossage ("invalid operand to %%N code");
2399 /* Print a const_int in hex. Used in comments. */
2400 if (GET_CODE (x
) == CONST_INT
)
2402 #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
2411 fputs (IMMEDIATE_PREFIX
, file
);
2414 #if 0 /* ??? no longer used */
2416 fputs (reg_names
[SDA_REGNUM
], file
);
2421 /* Do nothing special. */
2426 output_operand_lossage ("invalid operand output code");
2429 switch (GET_CODE (x
))
2432 fputs (reg_names
[REGNO (x
)], file
);
2437 if (GET_CODE (addr
) == PRE_INC
)
2439 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2440 fatal_insn ("pre-increment address is not a register", x
);
2442 fprintf (file
, "@+%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2444 else if (GET_CODE (addr
) == PRE_DEC
)
2446 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2447 fatal_insn ("pre-decrement address is not a register", x
);
2449 fprintf (file
, "@-%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2451 else if (GET_CODE (addr
) == POST_INC
)
2453 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2454 fatal_insn ("post-increment address is not a register", x
);
2456 fprintf (file
, "@%s+", reg_names
[REGNO (XEXP (addr
, 0))]);
2461 output_address (XEXP (x
, 0));
2467 /* We handle SFmode constants here as output_addr_const doesn't. */
2468 if (GET_MODE (x
) == SFmode
)
2473 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
2474 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2475 fprintf (file
, "0x%08lx", l
);
2479 /* Fall through. Let output_addr_const deal with it. */
2482 output_addr_const (file
, x
);
2487 /* Print a memory address as an operand to reference that memory location. */
2490 m32r_print_operand_address (file
, addr
)
2495 register rtx index
= 0;
2498 switch (GET_CODE (addr
))
2501 fputs (reg_names
[REGNO (addr
)], file
);
2505 if (GET_CODE (XEXP (addr
, 0)) == CONST_INT
)
2506 offset
= INTVAL (XEXP (addr
, 0)), base
= XEXP (addr
, 1);
2507 else if (GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
2508 offset
= INTVAL (XEXP (addr
, 1)), base
= XEXP (addr
, 0);
2510 base
= XEXP (addr
, 0), index
= XEXP (addr
, 1);
2511 if (GET_CODE (base
) == REG
)
2513 /* Print the offset first (if present) to conform to the manual. */
2517 fprintf (file
, "%d,", offset
);
2518 fputs (reg_names
[REGNO (base
)], file
);
2520 /* The chip doesn't support this, but left in for generality. */
2521 else if (GET_CODE (index
) == REG
)
2522 fprintf (file
, "%s,%s",
2523 reg_names
[REGNO (base
)], reg_names
[REGNO (index
)]);
2524 /* Not sure this can happen, but leave in for now. */
2525 else if (GET_CODE (index
) == SYMBOL_REF
)
2527 output_addr_const (file
, index
);
2529 fputs (reg_names
[REGNO (base
)], file
);
2532 fatal_insn ("bad address", addr
);
2534 else if (GET_CODE (base
) == LO_SUM
)
2537 || GET_CODE (XEXP (base
, 0)) != REG
)
2539 if (small_data_operand (XEXP (base
, 1), VOIDmode
))
2540 fputs ("sda(", file
);
2542 fputs ("low(", file
);
2543 output_addr_const (file
, plus_constant (XEXP (base
, 1), offset
));
2545 fputs (reg_names
[REGNO (XEXP (base
, 0))], file
);
2548 fatal_insn ("bad address", addr
);
2552 if (GET_CODE (XEXP (addr
, 0)) != REG
)
2553 fatal_insn ("lo_sum not of register", addr
);
2554 if (small_data_operand (XEXP (addr
, 1), VOIDmode
))
2555 fputs ("sda(", file
);
2557 fputs ("low(", file
);
2558 output_addr_const (file
, XEXP (addr
, 1));
2560 fputs (reg_names
[REGNO (XEXP (addr
, 0))], file
);
2563 case PRE_INC
: /* Assume SImode */
2564 fprintf (file
, "+%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2567 case PRE_DEC
: /* Assume SImode */
2568 fprintf (file
, "-%s", reg_names
[REGNO (XEXP (addr
, 0))]);
2571 case POST_INC
: /* Assume SImode */
2572 fprintf (file
, "%s+", reg_names
[REGNO (XEXP (addr
, 0))]);
2576 output_addr_const (file
, addr
);
2581 /* Return true if the operands are the constants 0 and 1. */
2583 zero_and_one (operand1
, operand2
)
2588 GET_CODE (operand1
) == CONST_INT
2589 && GET_CODE (operand2
) == CONST_INT
2590 && ( ((INTVAL (operand1
) == 0) && (INTVAL (operand2
) == 1))
2591 ||((INTVAL (operand1
) == 1) && (INTVAL (operand2
) == 0)));
2594 /* Return nonzero if the operand is suitable for use in a conditional move sequence. */
2596 conditional_move_operand (operand
, mode
)
2598 enum machine_mode mode
;
2600 /* Only defined for simple integers so far... */
2601 if (mode
!= SImode
&& mode
!= HImode
&& mode
!= QImode
)
2604 /* At the moment we can hanndle moving registers and loading constants. */
2605 /* To be added: Addition/subtraction/bitops/multiplication of registers. */
2607 switch (GET_CODE (operand
))
2613 return INT8_P (INTVAL (operand
));
2617 fprintf (stderr
, "Test for cond move op of type: %s\n",
2618 GET_RTX_NAME (GET_CODE (operand
)));
2624 /* Return true if the code is a test of the carry bit */
2626 carry_compare_operand (op
, mode
)
2628 enum machine_mode mode ATTRIBUTE_UNUSED
;
2632 if (GET_MODE (op
) != CCmode
&& GET_MODE (op
) != VOIDmode
)
2635 if (GET_CODE (op
) != NE
&& GET_CODE (op
) != EQ
)
2639 if (GET_CODE (x
) != REG
|| REGNO (x
) != CARRY_REGNUM
)
2643 if (GET_CODE (x
) != CONST_INT
|| INTVAL (x
) != 0)
2649 /* Generate the correct assembler code to handle the conditional loading of a
2650 value into a register. It is known that the operands satisfy the
2651 conditional_move_operand() function above. The destination is operand[0].
2652 The condition is operand [1]. The 'true' value is operand [2] and the
2653 'false' value is operand [3]. */
2655 emit_cond_move (operands
, insn
)
2657 rtx insn ATTRIBUTE_UNUSED
;
2659 static char buffer
[100];
2660 const char * dest
= reg_names
[REGNO (operands
[0])];
2664 /* Destination must be a register. */
2665 if (GET_CODE (operands
[0]) != REG
)
2667 if (! conditional_move_operand (operands
[2], SImode
))
2669 if (! conditional_move_operand (operands
[3], SImode
))
2672 /* Check to see if the test is reversed. */
2673 if (GET_CODE (operands
[1]) == NE
)
2675 rtx tmp
= operands
[2];
2676 operands
[2] = operands
[3];
2680 sprintf (buffer
, "mvfc %s, cbr", dest
);
2682 /* If the true value was '0' then we need to invert the results of the move. */
2683 if (INTVAL (operands
[2]) == 0)
2684 sprintf (buffer
+ strlen (buffer
), "\n\txor3 %s, %s, #1",
2690 /* Returns true if the registers contained in the two
2691 rtl expressions are different. */
2693 m32r_not_same_reg (a
, b
)
2700 while (GET_CODE (a
) == SUBREG
)
2703 if (GET_CODE (a
) == REG
)
2706 while (GET_CODE (b
) == SUBREG
)
2709 if (GET_CODE (b
) == REG
)
2712 return reg_a
!= reg_b
;
2716 /* Use a library function to move some bytes. */
2718 block_move_call (dest_reg
, src_reg
, bytes_rtx
)
2723 /* We want to pass the size as Pmode, which will normally be SImode
2724 but will be DImode if we are using 64 bit longs and pointers. */
2725 if (GET_MODE (bytes_rtx
) != VOIDmode
2726 && GET_MODE (bytes_rtx
) != Pmode
)
2727 bytes_rtx
= convert_to_mode (Pmode
, bytes_rtx
, 1);
2729 #ifdef TARGET_MEM_FUNCTIONS
2730 emit_library_call (gen_rtx (SYMBOL_REF
, Pmode
, "memcpy"), 0,
2731 VOIDmode
, 3, dest_reg
, Pmode
, src_reg
, Pmode
,
2732 convert_to_mode (TYPE_MODE (sizetype
), bytes_rtx
,
2733 TREE_UNSIGNED (sizetype
)),
2734 TYPE_MODE (sizetype
));
2736 emit_library_call (gen_rtx (SYMBOL_REF
, Pmode
, "bcopy"), 0,
2737 VOIDmode
, 3, src_reg
, Pmode
, dest_reg
, Pmode
,
2738 convert_to_mode (TYPE_MODE (integer_type_node
), bytes_rtx
,
2739 TREE_UNSIGNED (integer_type_node
)),
2740 TYPE_MODE (integer_type_node
));
2744 /* The maximum number of bytes to copy using pairs of load/store instructions.
2745 If a block is larger than this then a loop will be generated to copy
2746 MAX_MOVE_BYTES chunks at a time. The value of 32 is a semi-arbitary choice.
2747 A customer uses Dhrystome as their benchmark, and Dhrystone has a 31 byte
2748 string copy in it. */
2749 #define MAX_MOVE_BYTES 32
2751 /* Expand string/block move operations.
2753 operands[0] is the pointer to the destination.
2754 operands[1] is the pointer to the source.
2755 operands[2] is the number of bytes to move.
2756 operands[3] is the alignment. */
2759 m32r_expand_block_move (operands
)
2762 rtx orig_dst
= operands
[0];
2763 rtx orig_src
= operands
[1];
2764 rtx bytes_rtx
= operands
[2];
2765 rtx align_rtx
= operands
[3];
2766 int constp
= GET_CODE (bytes_rtx
) == CONST_INT
;
2767 HOST_WIDE_INT bytes
= constp
? INTVAL (bytes_rtx
) : 0;
2768 int align
= INTVAL (align_rtx
);
2773 if (constp
&& bytes
<= 0)
2776 /* Move the address into scratch registers. */
2777 dst_reg
= copy_addr_to_reg (XEXP (orig_dst
, 0));
2778 src_reg
= copy_addr_to_reg (XEXP (orig_src
, 0));
2780 if (align
> UNITS_PER_WORD
)
2781 align
= UNITS_PER_WORD
;
2783 /* If we prefer size over speed, always use a function call.
2784 If we do not know the size, use a function call.
2785 If the blocks are not word aligned, use a function call. */
2786 if (optimize_size
|| ! constp
|| align
!= UNITS_PER_WORD
)
2788 block_move_call (dst_reg
, src_reg
, bytes_rtx
);
2792 leftover
= bytes
% MAX_MOVE_BYTES
;
2795 /* If necessary, generate a loop to handle the bulk of the copy. */
2798 rtx label
= NULL_RTX
;
2799 rtx final_src
= NULL_RTX
;
2800 rtx at_a_time
= GEN_INT (MAX_MOVE_BYTES
);
2801 rtx rounded_total
= GEN_INT (bytes
);
2803 /* If we are going to have to perform this loop more than
2804 once, then generate a label and compute the address the
2805 source register will contain upon completion of the final
2807 if (bytes
> MAX_MOVE_BYTES
)
2809 final_src
= gen_reg_rtx (Pmode
);
2812 emit_insn (gen_addsi3 (final_src
, src_reg
, rounded_total
));
2815 emit_insn (gen_movsi (final_src
, rounded_total
));
2816 emit_insn (gen_addsi3 (final_src
, final_src
, src_reg
));
2819 label
= gen_label_rtx ();
2823 /* It is known that output_block_move() will update src_reg to point
2824 to the word after the end of the source block, and dst_reg to point
2825 to the last word of the destination block, provided that the block
2826 is MAX_MOVE_BYTES long. */
2827 emit_insn (gen_movstrsi_internal (dst_reg
, src_reg
, at_a_time
));
2828 emit_insn (gen_addsi3 (dst_reg
, dst_reg
, GEN_INT (4)));
2830 if (bytes
> MAX_MOVE_BYTES
)
2832 emit_insn (gen_cmpsi (src_reg
, final_src
));
2833 emit_jump_insn (gen_bne (label
));
2838 emit_insn (gen_movstrsi_internal (dst_reg
, src_reg
, GEN_INT (leftover
)));
2842 /* Emit load/stores for a small constant word aligned block_move.
2844 operands[0] is the memory address of the destination.
2845 operands[1] is the memory address of the source.
2846 operands[2] is the number of bytes to move.
2847 operands[3] is a temp register.
2848 operands[4] is a temp register. */
2851 m32r_output_block_move (insn
, operands
)
2852 rtx insn ATTRIBUTE_UNUSED
;
2855 HOST_WIDE_INT bytes
= INTVAL (operands
[2]);
2859 if (bytes
< 1 || bytes
> MAX_MOVE_BYTES
)
2862 /* We do not have a post-increment store available, so the first set of
2863 stores are done without any increment, then the remaining ones can use
2864 the pre-increment addressing mode.
2866 Note: expand_block_move() also relies upon this behavior when building
2867 loops to copy large blocks. */
2876 output_asm_insn ("ld\t%3, %p1", operands
);
2877 output_asm_insn ("ld\t%4, %p1", operands
);
2878 output_asm_insn ("st\t%3, @%0", operands
);
2879 output_asm_insn ("st\t%4, %s0", operands
);
2883 output_asm_insn ("ld\t%3, %p1", operands
);
2884 output_asm_insn ("ld\t%4, %p1", operands
);
2885 output_asm_insn ("st\t%3, %s0", operands
);
2886 output_asm_insn ("st\t%4, %s0", operands
);
2891 else if (bytes
>= 4)
2896 output_asm_insn ("ld\t%3, %p1", operands
);
2899 output_asm_insn ("ld\t%4, %p1", operands
);
2902 output_asm_insn ("st\t%3, @%0", operands
);
2904 output_asm_insn ("st\t%3, %s0", operands
);
2910 /* Get the entire next word, even though we do not want all of it.
2911 The saves us from doing several smaller loads, and we assume that
2912 we cannot cause a page fault when at least part of the word is in
2913 valid memory [since we don't get called if things aren't properly
2915 int dst_offset
= first_time
? 0 : 4;
2919 /* If got_extra is true then we have already loaded
2920 the next word as part of loading and storing the previous word. */
2922 output_asm_insn ("ld\t%4, @%1", operands
);
2928 output_asm_insn ("sra3\t%3, %4, #16", operands
);
2929 my_operands
[0] = operands
[3];
2930 my_operands
[1] = GEN_INT (dst_offset
);
2931 my_operands
[2] = operands
[0];
2932 output_asm_insn ("sth\t%0, @(%1,%2)", my_operands
);
2934 /* If there is a byte left to store then increment the
2935 destination address and shift the contents of the source
2936 register down by 8 bits. We could not do the address
2937 increment in the store half word instruction, because it does
2938 not have an auto increment mode. */
2939 if (bytes
> 0) /* assert (bytes == 1) */
2950 my_operands
[0] = operands
[4];
2951 my_operands
[1] = GEN_INT (last_shift
);
2952 output_asm_insn ("srai\t%0, #%1", my_operands
);
2953 my_operands
[0] = operands
[4];
2954 my_operands
[1] = GEN_INT (dst_offset
);
2955 my_operands
[2] = operands
[0];
2956 output_asm_insn ("stb\t%0, @(%1,%2)", my_operands
);
2966 /* Return true if op is an integer constant, less than or equal to
2969 m32r_block_immediate_operand (op
, mode
)
2971 enum machine_mode mode ATTRIBUTE_UNUSED
;
2973 if (GET_CODE (op
) != CONST_INT
2974 || INTVAL (op
) > MAX_MOVE_BYTES
2975 || INTVAL (op
) <= 0)