1 /* Subroutines used for code generation on Vitesse IQ2000 processors
2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #define IN_TARGET_CODE 1
24 #include "coretypes.h"
29 #include "stringpool.h"
38 #include "diagnostic-core.h"
39 #include "stor-layout.h"
43 #include "insn-attr.h"
46 #include "langhooks.h"
49 /* This file should be included last. */
50 #include "target-def.h"
52 /* Enumeration for all of the relational tests, so that we can build
53 arrays indexed by the test type, and not worry about the order
74 /* Structure to be filled in by compute_frame_size with register
75 save masks, and offsets for the current function. */
77 struct iq2000_frame_info
79 long total_size
; /* # bytes that the entire frame takes up. */
80 long var_size
; /* # bytes that variables take up. */
81 long args_size
; /* # bytes that outgoing arguments take up. */
82 long extra_size
; /* # bytes of extra gunk. */
83 int gp_reg_size
; /* # bytes needed to store gp regs. */
84 int fp_reg_size
; /* # bytes needed to store fp regs. */
85 long mask
; /* Mask of saved gp registers. */
86 long gp_save_offset
; /* Offset from vfp to store gp registers. */
87 long fp_save_offset
; /* Offset from vfp to store fp registers. */
88 long gp_sp_offset
; /* Offset from new sp to store gp registers. */
89 long fp_sp_offset
; /* Offset from new sp to store fp registers. */
90 int initialized
; /* != 0 if frame size already calculated. */
91 int num_gp
; /* Number of gp registers saved. */
94 struct GTY(()) machine_function
96 /* Current frame information, calculated by compute_frame_size. */
97 long total_size
; /* # bytes that the entire frame takes up. */
98 long var_size
; /* # bytes that variables take up. */
99 long args_size
; /* # bytes that outgoing arguments take up. */
100 long extra_size
; /* # bytes of extra gunk. */
101 int gp_reg_size
; /* # bytes needed to store gp regs. */
102 int fp_reg_size
; /* # bytes needed to store fp regs. */
103 long mask
; /* Mask of saved gp registers. */
104 long gp_save_offset
; /* Offset from vfp to store gp registers. */
105 long fp_save_offset
; /* Offset from vfp to store fp registers. */
106 long gp_sp_offset
; /* Offset from new sp to store gp registers. */
107 long fp_sp_offset
; /* Offset from new sp to store fp registers. */
108 int initialized
; /* != 0 if frame size already calculated. */
109 int num_gp
; /* Number of gp registers saved. */
112 /* Global variables for machine-dependent things. */
114 /* List of all IQ2000 punctuation characters used by iq2000_print_operand. */
115 static char iq2000_print_operand_punct
[256];
117 /* Which instruction set architecture to use. */
120 /* Local variables. */
122 /* The next branch instruction is a branch likely, not branch normal. */
123 static int iq2000_branch_likely
;
125 /* Count of delay slots and how many are filled. */
126 static int dslots_load_total
;
127 static int dslots_load_filled
;
128 static int dslots_jump_total
;
130 /* # of nops needed by previous insn. */
131 static int dslots_number_nops
;
133 /* Number of 1/2/3 word references to data items (i.e., not jal's). */
134 static int num_refs
[3];
136 /* Registers to check for load delay. */
137 static rtx iq2000_load_reg
;
138 static rtx iq2000_load_reg2
;
139 static rtx iq2000_load_reg3
;
140 static rtx iq2000_load_reg4
;
142 /* Mode used for saving/restoring general purpose registers. */
143 static machine_mode gpr_mode
;
146 /* Initialize the GCC target structure. */
147 static struct machine_function
* iq2000_init_machine_status (void);
148 static void iq2000_option_override (void);
149 static section
*iq2000_select_rtx_section (machine_mode
, rtx
,
150 unsigned HOST_WIDE_INT
);
151 static void iq2000_init_builtins (void);
152 static rtx
iq2000_expand_builtin (tree
, rtx
, rtx
, machine_mode
, int);
153 static bool iq2000_return_in_memory (const_tree
, const_tree
);
154 static void iq2000_setup_incoming_varargs (cumulative_args_t
,
155 const function_arg_info
&,
157 static bool iq2000_rtx_costs (rtx
, machine_mode
, int, int, int *, bool);
158 static int iq2000_address_cost (rtx
, machine_mode
, addr_space_t
,
160 static section
*iq2000_select_section (tree
, int, unsigned HOST_WIDE_INT
);
161 static rtx
iq2000_legitimize_address (rtx
, rtx
, machine_mode
);
162 static bool iq2000_pass_by_reference (cumulative_args_t
,
163 const function_arg_info
&);
164 static int iq2000_arg_partial_bytes (cumulative_args_t
,
165 const function_arg_info
&arg
);
166 static rtx
iq2000_function_arg (cumulative_args_t
,
167 const function_arg_info
&);
168 static void iq2000_function_arg_advance (cumulative_args_t
,
169 const function_arg_info
&);
170 static pad_direction
iq2000_function_arg_padding (machine_mode
, const_tree
);
171 static unsigned int iq2000_function_arg_boundary (machine_mode
,
173 static void iq2000_va_start (tree
, rtx
);
174 static bool iq2000_legitimate_address_p (machine_mode
, rtx
, bool);
175 static bool iq2000_can_eliminate (const int, const int);
176 static void iq2000_asm_trampoline_template (FILE *);
177 static void iq2000_trampoline_init (rtx
, tree
, rtx
);
178 static rtx
iq2000_function_value (const_tree
, const_tree
, bool);
179 static rtx
iq2000_libcall_value (machine_mode
, const_rtx
);
180 static void iq2000_print_operand (FILE *, rtx
, int);
181 static void iq2000_print_operand_address (FILE *, machine_mode
, rtx
);
182 static bool iq2000_print_operand_punct_valid_p (unsigned char code
);
183 static bool iq2000_hard_regno_mode_ok (unsigned int, machine_mode
);
184 static bool iq2000_modes_tieable_p (machine_mode
, machine_mode
);
185 static HOST_WIDE_INT
iq2000_constant_alignment (const_tree
, HOST_WIDE_INT
);
186 static HOST_WIDE_INT
iq2000_starting_frame_offset (void);
188 #undef TARGET_INIT_BUILTINS
189 #define TARGET_INIT_BUILTINS iq2000_init_builtins
190 #undef TARGET_EXPAND_BUILTIN
191 #define TARGET_EXPAND_BUILTIN iq2000_expand_builtin
192 #undef TARGET_ASM_SELECT_RTX_SECTION
193 #define TARGET_ASM_SELECT_RTX_SECTION iq2000_select_rtx_section
194 #undef TARGET_OPTION_OVERRIDE
195 #define TARGET_OPTION_OVERRIDE iq2000_option_override
196 #undef TARGET_RTX_COSTS
197 #define TARGET_RTX_COSTS iq2000_rtx_costs
198 #undef TARGET_ADDRESS_COST
199 #define TARGET_ADDRESS_COST iq2000_address_cost
200 #undef TARGET_ASM_SELECT_SECTION
201 #define TARGET_ASM_SELECT_SECTION iq2000_select_section
203 #undef TARGET_LEGITIMIZE_ADDRESS
204 #define TARGET_LEGITIMIZE_ADDRESS iq2000_legitimize_address
206 /* The assembler supports switchable .bss sections, but
207 iq2000_select_section doesn't yet make use of them. */
208 #undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
209 #define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS false
211 #undef TARGET_PRINT_OPERAND
212 #define TARGET_PRINT_OPERAND iq2000_print_operand
213 #undef TARGET_PRINT_OPERAND_ADDRESS
214 #define TARGET_PRINT_OPERAND_ADDRESS iq2000_print_operand_address
215 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
216 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P iq2000_print_operand_punct_valid_p
218 #undef TARGET_PROMOTE_FUNCTION_MODE
219 #define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote
220 #undef TARGET_PROMOTE_PROTOTYPES
221 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
223 #undef TARGET_FUNCTION_VALUE
224 #define TARGET_FUNCTION_VALUE iq2000_function_value
225 #undef TARGET_LIBCALL_VALUE
226 #define TARGET_LIBCALL_VALUE iq2000_libcall_value
227 #undef TARGET_RETURN_IN_MEMORY
228 #define TARGET_RETURN_IN_MEMORY iq2000_return_in_memory
229 #undef TARGET_PASS_BY_REFERENCE
230 #define TARGET_PASS_BY_REFERENCE iq2000_pass_by_reference
231 #undef TARGET_CALLEE_COPIES
232 #define TARGET_CALLEE_COPIES hook_callee_copies_named
233 #undef TARGET_ARG_PARTIAL_BYTES
234 #define TARGET_ARG_PARTIAL_BYTES iq2000_arg_partial_bytes
235 #undef TARGET_FUNCTION_ARG
236 #define TARGET_FUNCTION_ARG iq2000_function_arg
237 #undef TARGET_FUNCTION_ARG_ADVANCE
238 #define TARGET_FUNCTION_ARG_ADVANCE iq2000_function_arg_advance
239 #undef TARGET_FUNCTION_ARG_PADDING
240 #define TARGET_FUNCTION_ARG_PADDING iq2000_function_arg_padding
241 #undef TARGET_FUNCTION_ARG_BOUNDARY
242 #define TARGET_FUNCTION_ARG_BOUNDARY iq2000_function_arg_boundary
244 #undef TARGET_SETUP_INCOMING_VARARGS
245 #define TARGET_SETUP_INCOMING_VARARGS iq2000_setup_incoming_varargs
246 #undef TARGET_STRICT_ARGUMENT_NAMING
247 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
249 #undef TARGET_EXPAND_BUILTIN_VA_START
250 #define TARGET_EXPAND_BUILTIN_VA_START iq2000_va_start
253 #define TARGET_LRA_P hook_bool_void_false
255 #undef TARGET_LEGITIMATE_ADDRESS_P
256 #define TARGET_LEGITIMATE_ADDRESS_P iq2000_legitimate_address_p
258 #undef TARGET_CAN_ELIMINATE
259 #define TARGET_CAN_ELIMINATE iq2000_can_eliminate
261 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
262 #define TARGET_ASM_TRAMPOLINE_TEMPLATE iq2000_asm_trampoline_template
263 #undef TARGET_TRAMPOLINE_INIT
264 #define TARGET_TRAMPOLINE_INIT iq2000_trampoline_init
266 #undef TARGET_HARD_REGNO_MODE_OK
267 #define TARGET_HARD_REGNO_MODE_OK iq2000_hard_regno_mode_ok
268 #undef TARGET_MODES_TIEABLE_P
269 #define TARGET_MODES_TIEABLE_P iq2000_modes_tieable_p
271 #undef TARGET_CONSTANT_ALIGNMENT
272 #define TARGET_CONSTANT_ALIGNMENT iq2000_constant_alignment
274 #undef TARGET_STARTING_FRAME_OFFSET
275 #define TARGET_STARTING_FRAME_OFFSET iq2000_starting_frame_offset
277 #undef TARGET_HAVE_SPECULATION_SAFE_VALUE
278 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
280 struct gcc_target targetm
= TARGET_INITIALIZER
;
282 /* Return nonzero if we split the address into high and low parts. */
285 iq2000_check_split (rtx address
, machine_mode mode
)
287 /* This is the same check used in simple_memory_operand.
288 We use it here because LO_SUM is not offsettable. */
289 if (GET_MODE_SIZE (mode
) > (unsigned) UNITS_PER_WORD
)
292 if ((GET_CODE (address
) == SYMBOL_REF
)
293 || (GET_CODE (address
) == CONST
294 && GET_CODE (XEXP (XEXP (address
, 0), 0)) == SYMBOL_REF
)
295 || GET_CODE (address
) == LABEL_REF
)
301 /* Return nonzero if REG is valid for MODE. */
304 iq2000_reg_mode_ok_for_base_p (rtx reg
,
305 machine_mode mode ATTRIBUTE_UNUSED
,
309 ? REGNO_MODE_OK_FOR_BASE_P (REGNO (reg
), mode
)
310 : GP_REG_OR_PSEUDO_NONSTRICT_P (REGNO (reg
), mode
));
313 /* Return a nonzero value if XINSN is a legitimate address for a
314 memory operand of the indicated MODE. STRICT is nonzero if this
315 function is called during reload. */
318 iq2000_legitimate_address_p (machine_mode mode
, rtx xinsn
, bool strict
)
320 if (TARGET_DEBUG_A_MODE
)
322 GO_PRINTF2 ("\n========== legitimate_address_p, %sstrict\n",
323 strict
? "" : "not ");
324 GO_DEBUG_RTX (xinsn
);
327 /* Check for constant before stripping off SUBREG, so that we don't
328 accept (subreg (const_int)) which will fail to reload. */
329 if (CONSTANT_ADDRESS_P (xinsn
)
330 && ! (iq2000_check_split (xinsn
, mode
))
331 && ! (GET_CODE (xinsn
) == CONST_INT
&& ! SMALL_INT (xinsn
)))
334 while (GET_CODE (xinsn
) == SUBREG
)
335 xinsn
= SUBREG_REG (xinsn
);
337 if (GET_CODE (xinsn
) == REG
338 && iq2000_reg_mode_ok_for_base_p (xinsn
, mode
, strict
))
341 if (GET_CODE (xinsn
) == LO_SUM
)
343 rtx xlow0
= XEXP (xinsn
, 0);
344 rtx xlow1
= XEXP (xinsn
, 1);
346 while (GET_CODE (xlow0
) == SUBREG
)
347 xlow0
= SUBREG_REG (xlow0
);
348 if (GET_CODE (xlow0
) == REG
349 && iq2000_reg_mode_ok_for_base_p (xlow0
, mode
, strict
)
350 && iq2000_check_split (xlow1
, mode
))
354 if (GET_CODE (xinsn
) == PLUS
)
356 rtx xplus0
= XEXP (xinsn
, 0);
357 rtx xplus1
= XEXP (xinsn
, 1);
361 while (GET_CODE (xplus0
) == SUBREG
)
362 xplus0
= SUBREG_REG (xplus0
);
363 code0
= GET_CODE (xplus0
);
365 while (GET_CODE (xplus1
) == SUBREG
)
366 xplus1
= SUBREG_REG (xplus1
);
367 code1
= GET_CODE (xplus1
);
370 && iq2000_reg_mode_ok_for_base_p (xplus0
, mode
, strict
))
372 if (code1
== CONST_INT
&& SMALL_INT (xplus1
)
373 && SMALL_INT_UNSIGNED (xplus1
) /* No negative offsets */)
378 if (TARGET_DEBUG_A_MODE
)
379 GO_PRINTF ("Not a machine_mode mode, legitimate address\n");
381 /* The address was not legitimate. */
385 /* Returns an operand string for the given instruction's delay slot,
386 after updating filled delay slot statistics.
388 We assume that operands[0] is the target register that is set.
390 In order to check the next insn, most of this functionality is moved
391 to FINAL_PRESCAN_INSN, and we just set the global variables that
395 iq2000_fill_delay_slot (const char *ret
, enum delay_type type
, rtx operands
[],
400 rtx_insn
*next_insn
= cur_insn
? NEXT_INSN (cur_insn
) : NULL
;
403 if (type
== DELAY_LOAD
|| type
== DELAY_FCMP
)
409 /* Make sure that we don't put nop's after labels. */
410 next_insn
= NEXT_INSN (cur_insn
);
411 while (next_insn
!= 0
412 && (NOTE_P (next_insn
) || LABEL_P (next_insn
)))
413 next_insn
= NEXT_INSN (next_insn
);
415 dslots_load_total
+= num_nops
;
416 if (TARGET_DEBUG_C_MODE
417 || type
== DELAY_NONE
421 || LABEL_P (next_insn
)
422 || (set_reg
= operands
[0]) == 0)
424 dslots_number_nops
= 0;
426 iq2000_load_reg2
= 0;
427 iq2000_load_reg3
= 0;
428 iq2000_load_reg4
= 0;
433 set_reg
= operands
[0];
437 while (GET_CODE (set_reg
) == SUBREG
)
438 set_reg
= SUBREG_REG (set_reg
);
440 mode
= GET_MODE (set_reg
);
441 dslots_number_nops
= num_nops
;
442 iq2000_load_reg
= set_reg
;
443 if (GET_MODE_SIZE (mode
)
444 > (unsigned) (UNITS_PER_WORD
))
445 iq2000_load_reg2
= gen_rtx_REG (SImode
, REGNO (set_reg
) + 1);
447 iq2000_load_reg2
= 0;
452 /* Determine whether a memory reference takes one (based off of the GP
453 pointer), two (normal), or three (label + reg) instructions, and bump the
454 appropriate counter for -mstats. */
457 iq2000_count_memory_refs (rtx op
, int num
)
461 rtx addr
, plus0
, plus1
;
462 enum rtx_code code0
, code1
;
465 if (TARGET_DEBUG_B_MODE
)
467 fprintf (stderr
, "\n========== iq2000_count_memory_refs:\n");
471 /* Skip MEM if passed, otherwise handle movsi of address. */
472 addr
= (GET_CODE (op
) != MEM
) ? op
: XEXP (op
, 0);
474 /* Loop, going through the address RTL. */
478 switch (GET_CODE (addr
))
486 plus0
= XEXP (addr
, 0);
487 plus1
= XEXP (addr
, 1);
488 code0
= GET_CODE (plus0
);
489 code1
= GET_CODE (plus1
);
499 if (code0
== CONST_INT
)
514 if (code1
== CONST_INT
)
521 if (code0
== SYMBOL_REF
|| code0
== LABEL_REF
|| code0
== CONST
)
528 if (code1
== SYMBOL_REF
|| code1
== LABEL_REF
|| code1
== CONST
)
538 n_words
= 2; /* Always 2 words. */
542 addr
= XEXP (addr
, 0);
547 n_words
= SYMBOL_REF_FLAG (addr
) ? 1 : 2;
559 n_words
+= additional
;
563 num_refs
[n_words
-1] += num
;
566 /* Abort after printing out a specific insn. */
569 abort_with_insn (rtx insn
, const char * reason
)
573 fancy_abort (__FILE__
, __LINE__
, __FUNCTION__
);
576 /* Return the appropriate instructions to move one operand to another. */
579 iq2000_move_1word (rtx operands
[], rtx_insn
*insn
, int unsignedp
)
582 rtx op0
= operands
[0];
583 rtx op1
= operands
[1];
584 enum rtx_code code0
= GET_CODE (op0
);
585 enum rtx_code code1
= GET_CODE (op1
);
586 machine_mode mode
= GET_MODE (op0
);
587 int subreg_offset0
= 0;
588 int subreg_offset1
= 0;
589 enum delay_type delay
= DELAY_NONE
;
591 while (code0
== SUBREG
)
593 subreg_offset0
+= subreg_regno_offset (REGNO (SUBREG_REG (op0
)),
594 GET_MODE (SUBREG_REG (op0
)),
597 op0
= SUBREG_REG (op0
);
598 code0
= GET_CODE (op0
);
601 while (code1
== SUBREG
)
603 subreg_offset1
+= subreg_regno_offset (REGNO (SUBREG_REG (op1
)),
604 GET_MODE (SUBREG_REG (op1
)),
607 op1
= SUBREG_REG (op1
);
608 code1
= GET_CODE (op1
);
611 /* For our purposes, a condition code mode is the same as SImode. */
617 int regno0
= REGNO (op0
) + subreg_offset0
;
621 int regno1
= REGNO (op1
) + subreg_offset1
;
623 /* Do not do anything for assigning a register to itself */
624 if (regno0
== regno1
)
627 else if (GP_REG_P (regno0
))
629 if (GP_REG_P (regno1
))
630 ret
= "or\t%0,%%0,%1";
635 else if (code1
== MEM
)
640 iq2000_count_memory_refs (op1
, 1);
642 if (GP_REG_P (regno0
))
644 /* For loads, use the mode of the memory item, instead of the
645 target, so zero/sign extend can use this code as well. */
646 switch (GET_MODE (op1
))
658 ret
= (unsignedp
) ? "lhu\t%0,%1" : "lh\t%0,%1";
661 ret
= (unsignedp
) ? "lbu\t%0,%1" : "lb\t%0,%1";
667 else if (code1
== CONST_INT
668 || (code1
== CONST_DOUBLE
669 && GET_MODE (op1
) == VOIDmode
))
671 if (code1
== CONST_DOUBLE
)
673 /* This can happen when storing constants into long long
674 bitfields. Just store the least significant word of
676 operands
[1] = op1
= GEN_INT (CONST_DOUBLE_LOW (op1
));
679 if (INTVAL (op1
) == 0)
681 if (GP_REG_P (regno0
))
682 ret
= "or\t%0,%%0,%z1";
684 else if (GP_REG_P (regno0
))
686 if (SMALL_INT_UNSIGNED (op1
))
687 ret
= "ori\t%0,%%0,%x1\t\t\t# %1";
688 else if (SMALL_INT (op1
))
689 ret
= "addiu\t%0,%%0,%1\t\t\t# %1";
691 ret
= "lui\t%0,%X1\t\t\t# %1\n\tori\t%0,%0,%x1";
695 else if (code1
== CONST_DOUBLE
&& mode
== SFmode
)
697 if (op1
== CONST0_RTX (SFmode
))
699 if (GP_REG_P (regno0
))
700 ret
= "or\t%0,%%0,%.";
710 else if (code1
== LABEL_REF
)
713 iq2000_count_memory_refs (op1
, 1);
718 else if (code1
== SYMBOL_REF
|| code1
== CONST
)
721 iq2000_count_memory_refs (op1
, 1);
726 else if (code1
== PLUS
)
728 rtx add_op0
= XEXP (op1
, 0);
729 rtx add_op1
= XEXP (op1
, 1);
731 if (GET_CODE (XEXP (op1
, 1)) == REG
732 && GET_CODE (XEXP (op1
, 0)) == CONST_INT
)
733 add_op0
= XEXP (op1
, 1), add_op1
= XEXP (op1
, 0);
735 operands
[2] = add_op0
;
736 operands
[3] = add_op1
;
737 ret
= "add%:\t%0,%2,%3";
740 else if (code1
== HIGH
)
742 operands
[1] = XEXP (op1
, 0);
743 ret
= "lui\t%0,%%hi(%1)";
747 else if (code0
== MEM
)
750 iq2000_count_memory_refs (op0
, 1);
754 int regno1
= REGNO (op1
) + subreg_offset1
;
756 if (GP_REG_P (regno1
))
760 case E_SFmode
: ret
= "sw\t%1,%0"; break;
761 case E_SImode
: ret
= "sw\t%1,%0"; break;
762 case E_HImode
: ret
= "sh\t%1,%0"; break;
763 case E_QImode
: ret
= "sb\t%1,%0"; break;
769 else if (code1
== CONST_INT
&& INTVAL (op1
) == 0)
773 case E_SFmode
: ret
= "sw\t%z1,%0"; break;
774 case E_SImode
: ret
= "sw\t%z1,%0"; break;
775 case E_HImode
: ret
= "sh\t%z1,%0"; break;
776 case E_QImode
: ret
= "sb\t%z1,%0"; break;
781 else if (code1
== CONST_DOUBLE
&& op1
== CONST0_RTX (mode
))
785 case E_SFmode
: ret
= "sw\t%.,%0"; break;
786 case E_SImode
: ret
= "sw\t%.,%0"; break;
787 case E_HImode
: ret
= "sh\t%.,%0"; break;
788 case E_QImode
: ret
= "sb\t%.,%0"; break;
796 abort_with_insn (insn
, "Bad move");
800 if (delay
!= DELAY_NONE
)
801 return iq2000_fill_delay_slot (ret
, delay
, operands
, insn
);
806 /* Provide the costs of an addressing mode that contains ADDR. */
809 iq2000_address_cost (rtx addr
, machine_mode mode
, addr_space_t as
,
812 switch (GET_CODE (addr
))
822 rtx offset
= const0_rtx
;
824 addr
= eliminate_constant_term (XEXP (addr
, 0), & offset
);
825 if (GET_CODE (addr
) == LABEL_REF
)
828 if (GET_CODE (addr
) != SYMBOL_REF
)
831 if (! SMALL_INT (offset
))
838 return SYMBOL_REF_FLAG (addr
) ? 1 : 2;
842 rtx plus0
= XEXP (addr
, 0);
843 rtx plus1
= XEXP (addr
, 1);
845 if (GET_CODE (plus0
) != REG
&& GET_CODE (plus1
) == REG
)
846 plus0
= XEXP (addr
, 1), plus1
= XEXP (addr
, 0);
848 if (GET_CODE (plus0
) != REG
)
851 switch (GET_CODE (plus1
))
854 return SMALL_INT (plus1
) ? 1 : 2;
861 return iq2000_address_cost (plus1
, mode
, as
, speed
) + 1;
875 /* Make normal rtx_code into something we can index from an array. */
877 static enum internal_test
878 map_test_to_internal_test (enum rtx_code test_code
)
880 enum internal_test test
= ITEST_MAX
;
884 case EQ
: test
= ITEST_EQ
; break;
885 case NE
: test
= ITEST_NE
; break;
886 case GT
: test
= ITEST_GT
; break;
887 case GE
: test
= ITEST_GE
; break;
888 case LT
: test
= ITEST_LT
; break;
889 case LE
: test
= ITEST_LE
; break;
890 case GTU
: test
= ITEST_GTU
; break;
891 case GEU
: test
= ITEST_GEU
; break;
892 case LTU
: test
= ITEST_LTU
; break;
893 case LEU
: test
= ITEST_LEU
; break;
900 /* Generate the code to do a TEST_CODE comparison on two integer values CMP0
901 and CMP1. P_INVERT is NULL or ptr if branch needs to reverse its test.
902 The return value RESULT is:
903 (reg:SI xx) The pseudo register the comparison is in
904 0 No register, generate a simple branch. */
907 gen_int_relational (enum rtx_code test_code
, rtx result
, rtx cmp0
, rtx cmp1
,
912 enum rtx_code test_code
; /* Code to use in instruction (LT vs. LTU). */
913 int const_low
; /* Low bound of constant we can accept. */
914 int const_high
; /* High bound of constant we can accept. */
915 int const_add
; /* Constant to add (convert LE -> LT). */
916 int reverse_regs
; /* Reverse registers in test. */
917 int invert_const
; /* != 0 if invert value if cmp1 is constant. */
918 int invert_reg
; /* != 0 if invert value if cmp1 is register. */
919 int unsignedp
; /* != 0 for unsigned comparisons. */
922 static struct cmp_info info
[ (int)ITEST_MAX
] =
924 { XOR
, 0, 65535, 0, 0, 0, 0, 0 }, /* EQ */
925 { XOR
, 0, 65535, 0, 0, 1, 1, 0 }, /* NE */
926 { LT
, -32769, 32766, 1, 1, 1, 0, 0 }, /* GT */
927 { LT
, -32768, 32767, 0, 0, 1, 1, 0 }, /* GE */
928 { LT
, -32768, 32767, 0, 0, 0, 0, 0 }, /* LT */
929 { LT
, -32769, 32766, 1, 1, 0, 1, 0 }, /* LE */
930 { LTU
, -32769, 32766, 1, 1, 1, 0, 1 }, /* GTU */
931 { LTU
, -32768, 32767, 0, 0, 1, 1, 1 }, /* GEU */
932 { LTU
, -32768, 32767, 0, 0, 0, 0, 1 }, /* LTU */
933 { LTU
, -32769, 32766, 1, 1, 0, 1, 1 }, /* LEU */
936 enum internal_test test
;
938 struct cmp_info
*p_info
;
945 test
= map_test_to_internal_test (test_code
);
946 gcc_assert (test
!= ITEST_MAX
);
948 p_info
= &info
[(int) test
];
949 eqne_p
= (p_info
->test_code
== XOR
);
951 mode
= GET_MODE (cmp0
);
952 if (mode
== VOIDmode
)
953 mode
= GET_MODE (cmp1
);
955 /* Eliminate simple branches. */
956 branch_p
= (result
== 0);
959 if (GET_CODE (cmp0
) == REG
|| GET_CODE (cmp0
) == SUBREG
)
961 /* Comparisons against zero are simple branches. */
962 if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0)
965 /* Test for beq/bne. */
970 /* Allocate a pseudo to calculate the value in. */
971 result
= gen_reg_rtx (mode
);
974 /* Make sure we can handle any constants given to us. */
975 if (GET_CODE (cmp0
) == CONST_INT
)
976 cmp0
= force_reg (mode
, cmp0
);
978 if (GET_CODE (cmp1
) == CONST_INT
)
980 HOST_WIDE_INT value
= INTVAL (cmp1
);
982 if (value
< p_info
->const_low
983 || value
> p_info
->const_high
)
984 cmp1
= force_reg (mode
, cmp1
);
987 /* See if we need to invert the result. */
988 invert
= (GET_CODE (cmp1
) == CONST_INT
989 ? p_info
->invert_const
: p_info
->invert_reg
);
991 if (p_invert
!= (int *)0)
997 /* Comparison to constants, may involve adding 1 to change a LT into LE.
998 Comparison between two registers, may involve switching operands. */
999 if (GET_CODE (cmp1
) == CONST_INT
)
1001 if (p_info
->const_add
!= 0)
1003 HOST_WIDE_INT new_const
= INTVAL (cmp1
) + p_info
->const_add
;
1005 /* If modification of cmp1 caused overflow,
1006 we would get the wrong answer if we follow the usual path;
1007 thus, x > 0xffffffffU would turn into x > 0U. */
1008 if ((p_info
->unsignedp
1009 ? (unsigned HOST_WIDE_INT
) new_const
>
1010 (unsigned HOST_WIDE_INT
) INTVAL (cmp1
)
1011 : new_const
> INTVAL (cmp1
))
1012 != (p_info
->const_add
> 0))
1014 /* This test is always true, but if INVERT is true then
1015 the result of the test needs to be inverted so 0 should
1016 be returned instead. */
1017 emit_move_insn (result
, invert
? const0_rtx
: const_true_rtx
);
1021 cmp1
= GEN_INT (new_const
);
1025 else if (p_info
->reverse_regs
)
1032 if (test
== ITEST_NE
&& GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) == 0)
1036 reg
= (invert
|| eqne_p
) ? gen_reg_rtx (mode
) : result
;
1037 convert_move (reg
, gen_rtx_fmt_ee (p_info
->test_code
, mode
, cmp0
, cmp1
), 0);
1040 if (test
== ITEST_NE
)
1042 convert_move (result
, gen_rtx_GTU (mode
, reg
, const0_rtx
), 0);
1043 if (p_invert
!= NULL
)
1048 else if (test
== ITEST_EQ
)
1050 reg2
= invert
? gen_reg_rtx (mode
) : result
;
1051 convert_move (reg2
, gen_rtx_LTU (mode
, reg
, const1_rtx
), 0);
1060 convert_move (result
, gen_rtx_XOR (mode
, reg
, one
), 0);
1066 /* Emit the common code for doing conditional branches.
1067 operand[0] is the label to jump to.
1068 The comparison operands are saved away by cmp{si,di,sf,df}. */
1071 gen_conditional_branch (rtx operands
[], machine_mode mode
)
1073 enum rtx_code test_code
= GET_CODE (operands
[0]);
1074 rtx cmp0
= operands
[1];
1075 rtx cmp1
= operands
[2];
1081 reg
= gen_int_relational (test_code
, NULL_RTX
, cmp0
, cmp1
, &invert
);
1089 else if (GET_CODE (cmp1
) == CONST_INT
&& INTVAL (cmp1
) != 0)
1090 /* We don't want to build a comparison against a nonzero
1092 cmp1
= force_reg (mode
, cmp1
);
1094 /* Generate the branch. */
1095 label1
= gen_rtx_LABEL_REF (VOIDmode
, operands
[3]);
1104 emit_jump_insn (gen_rtx_SET (pc_rtx
,
1105 gen_rtx_IF_THEN_ELSE (VOIDmode
,
1106 gen_rtx_fmt_ee (test_code
,
1112 /* Initialize CUM for a function FNTYPE. */
1115 init_cumulative_args (CUMULATIVE_ARGS
*cum
, tree fntype
,
1116 rtx libname ATTRIBUTE_UNUSED
)
1118 static CUMULATIVE_ARGS zero_cum
;
1122 if (TARGET_DEBUG_D_MODE
)
1125 "\ninit_cumulative_args, fntype = 0x%.8lx", (long) fntype
);
1128 fputc ('\n', stderr
);
1132 tree ret_type
= TREE_TYPE (fntype
);
1134 fprintf (stderr
, ", fntype code = %s, ret code = %s\n",
1135 get_tree_code_name (TREE_CODE (fntype
)),
1136 get_tree_code_name (TREE_CODE (ret_type
)));
1142 /* Determine if this function has variable arguments. This is
1143 indicated by the last argument being 'void_type_mode' if there
1144 are no variable arguments. The standard IQ2000 calling sequence
1145 passes all arguments in the general purpose registers in this case. */
1147 for (param
= fntype
? TYPE_ARG_TYPES (fntype
) : 0;
1148 param
!= 0; param
= next_param
)
1150 next_param
= TREE_CHAIN (param
);
1151 if (next_param
== 0 && TREE_VALUE (param
) != void_type_node
)
1152 cum
->gp_reg_found
= 1;
1156 /* Implement TARGET_FUNCTION_ARG_ADVANCE. */
1159 iq2000_function_arg_advance (cumulative_args_t cum_v
,
1160 const function_arg_info
&arg
)
1162 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1164 if (TARGET_DEBUG_D_MODE
)
1167 "function_adv({gp reg found = %d, arg # = %2d, words = %2d}, %4s, ",
1168 cum
->gp_reg_found
, cum
->arg_number
, cum
->arg_words
,
1169 GET_MODE_NAME (arg
.mode
));
1170 fprintf (stderr
, "%p", (const void *) arg
.type
);
1171 fprintf (stderr
, ", %d )\n\n", arg
.named
);
1181 gcc_assert (GET_MODE_CLASS (arg
.mode
) == MODE_COMPLEX_INT
1182 || GET_MODE_CLASS (arg
.mode
) == MODE_COMPLEX_FLOAT
);
1184 cum
->gp_reg_found
= 1;
1185 cum
->arg_words
+= ((GET_MODE_SIZE (arg
.mode
) + UNITS_PER_WORD
- 1)
1190 cum
->gp_reg_found
= 1;
1191 cum
->arg_words
+= ((int_size_in_bytes (arg
.type
) + UNITS_PER_WORD
- 1)
1197 if (! cum
->gp_reg_found
&& cum
->arg_number
<= 2)
1198 cum
->fp_code
+= 1 << ((cum
->arg_number
- 1) * 2);
1202 cum
->arg_words
+= 2;
1203 if (! cum
->gp_reg_found
&& cum
->arg_number
<= 2)
1204 cum
->fp_code
+= 2 << ((cum
->arg_number
- 1) * 2);
1208 cum
->gp_reg_found
= 1;
1209 cum
->arg_words
+= 2;
1213 cum
->gp_reg_found
= 1;
1214 cum
->arg_words
+= 4;
1220 cum
->gp_reg_found
= 1;
1226 /* Return an RTL expression containing the register for argument ARG in CUM,
1227 or 0 if the argument is to be passed on the stack. */
1230 iq2000_function_arg (cumulative_args_t cum_v
, const function_arg_info
&arg
)
1232 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1233 tree type
= arg
.type
;
1234 machine_mode mode
= arg
.mode
;
1238 unsigned int *arg_words
= &cum
->arg_words
;
1239 int struct_p
= (type
!= 0
1240 && (TREE_CODE (type
) == RECORD_TYPE
1241 || TREE_CODE (type
) == UNION_TYPE
1242 || TREE_CODE (type
) == QUAL_UNION_TYPE
));
1244 if (TARGET_DEBUG_D_MODE
)
1247 "function_arg( {gp reg found = %d, arg # = %2d, words = %2d}, %4s, ",
1248 cum
->gp_reg_found
, cum
->arg_number
, cum
->arg_words
,
1249 GET_MODE_NAME (mode
));
1250 fprintf (stderr
, "%p", (const void *) type
);
1251 fprintf (stderr
, ", %d ) = ", arg
.named
);
1255 cum
->last_arg_fp
= 0;
1259 regbase
= GP_ARG_FIRST
;
1263 cum
->arg_words
+= cum
->arg_words
& 1;
1265 regbase
= GP_ARG_FIRST
;
1269 gcc_assert (GET_MODE_CLASS (mode
) == MODE_COMPLEX_INT
1270 || GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
);
1274 if (type
!= NULL_TREE
&& TYPE_ALIGN (type
) > (unsigned) BITS_PER_WORD
)
1275 cum
->arg_words
+= (cum
->arg_words
& 1);
1276 regbase
= GP_ARG_FIRST
;
1283 regbase
= GP_ARG_FIRST
;
1287 cum
->arg_words
+= (cum
->arg_words
& 1);
1288 regbase
= GP_ARG_FIRST
;
1292 cum
->arg_words
+= (cum
->arg_words
& 3);
1293 regbase
= GP_ARG_FIRST
;
1297 if (*arg_words
>= (unsigned) MAX_ARGS_IN_REGISTERS
)
1299 if (TARGET_DEBUG_D_MODE
)
1300 fprintf (stderr
, "<stack>%s\n", struct_p
? ", [struct]" : "");
1306 gcc_assert (regbase
!= -1);
1308 if (! type
|| TREE_CODE (type
) != RECORD_TYPE
1309 || ! arg
.named
|| ! TYPE_SIZE_UNIT (type
)
1310 || ! tree_fits_uhwi_p (TYPE_SIZE_UNIT (type
)))
1311 ret
= gen_rtx_REG (mode
, regbase
+ *arg_words
+ bias
);
1316 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
1317 if (TREE_CODE (field
) == FIELD_DECL
1318 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
1319 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
1320 && tree_fits_shwi_p (bit_position (field
))
1321 && int_bit_position (field
) % BITS_PER_WORD
== 0)
1324 /* If the whole struct fits a DFmode register,
1325 we don't need the PARALLEL. */
1326 if (! field
|| mode
== DFmode
)
1327 ret
= gen_rtx_REG (mode
, regbase
+ *arg_words
+ bias
);
1330 unsigned int chunks
;
1331 HOST_WIDE_INT bitpos
;
1335 /* ??? If this is a packed structure, then the last hunk won't
1338 = tree_to_uhwi (TYPE_SIZE_UNIT (type
)) / UNITS_PER_WORD
;
1339 if (chunks
+ *arg_words
+ bias
> (unsigned) MAX_ARGS_IN_REGISTERS
)
1340 chunks
= MAX_ARGS_IN_REGISTERS
- *arg_words
- bias
;
1342 /* Assign_parms checks the mode of ENTRY_PARM, so we must
1343 use the actual mode here. */
1344 ret
= gen_rtx_PARALLEL (mode
, rtvec_alloc (chunks
));
1347 regno
= regbase
+ *arg_words
+ bias
;
1348 field
= TYPE_FIELDS (type
);
1349 for (i
= 0; i
< chunks
; i
++)
1353 for (; field
; field
= DECL_CHAIN (field
))
1354 if (TREE_CODE (field
) == FIELD_DECL
1355 && int_bit_position (field
) >= bitpos
)
1359 && int_bit_position (field
) == bitpos
1360 && TREE_CODE (TREE_TYPE (field
)) == REAL_TYPE
1361 && TYPE_PRECISION (TREE_TYPE (field
)) == BITS_PER_WORD
)
1362 reg
= gen_rtx_REG (DFmode
, regno
++);
1364 reg
= gen_rtx_REG (word_mode
, regno
);
1367 = gen_rtx_EXPR_LIST (VOIDmode
, reg
,
1368 GEN_INT (bitpos
/ BITS_PER_UNIT
));
1376 if (TARGET_DEBUG_D_MODE
)
1377 fprintf (stderr
, "%s%s\n", reg_names
[regbase
+ *arg_words
+ bias
],
1378 struct_p
? ", [struct]" : "");
1381 /* We will be called with an end marker after the last argument
1382 has been seen. Whatever we return will be passed to the call
1383 insn. If we need any shifts for small structures, return them in
1385 if (arg
.end_marker_p ())
1387 if (cum
->num_adjusts
> 0)
1388 ret
= gen_rtx_PARALLEL ((machine_mode
) cum
->fp_code
,
1389 gen_rtvec_v (cum
->num_adjusts
, cum
->adjust
));
1395 /* Implement TARGET_FUNCTION_ARG_PADDING. */
1397 static pad_direction
1398 iq2000_function_arg_padding (machine_mode mode
, const_tree type
)
1400 return (! BYTES_BIG_ENDIAN
1404 && TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
1405 && int_size_in_bytes (type
) < (PARM_BOUNDARY
/ BITS_PER_UNIT
))
1406 : (GET_MODE_BITSIZE (mode
) < PARM_BOUNDARY
1407 && GET_MODE_CLASS (mode
) == MODE_INT
))
1408 ? PAD_DOWNWARD
: PAD_UPWARD
));
1412 iq2000_function_arg_boundary (machine_mode mode
, const_tree type
)
1414 return (type
!= NULL_TREE
1415 ? (TYPE_ALIGN (type
) <= PARM_BOUNDARY
1417 : TYPE_ALIGN (type
))
1418 : (GET_MODE_ALIGNMENT (mode
) <= PARM_BOUNDARY
1420 : GET_MODE_ALIGNMENT (mode
)));
1424 iq2000_arg_partial_bytes (cumulative_args_t cum_v
,
1425 const function_arg_info
&arg
)
1427 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
1429 if (arg
.mode
== DImode
&& cum
->arg_words
== MAX_ARGS_IN_REGISTERS
- 1)
1431 if (TARGET_DEBUG_D_MODE
)
1432 fprintf (stderr
, "iq2000_arg_partial_bytes=%d\n", UNITS_PER_WORD
);
1433 return UNITS_PER_WORD
;
1439 /* Implement va_start. */
1442 iq2000_va_start (tree valist
, rtx nextarg
)
1445 /* Find out how many non-float named formals. */
1446 int gpr_save_area_size
;
1447 /* Note UNITS_PER_WORD is 4 bytes. */
1448 int_arg_words
= crtl
->args
.info
.arg_words
;
1450 if (int_arg_words
< 8 )
1451 /* Adjust for the prologue's economy measure. */
1452 gpr_save_area_size
= (8 - int_arg_words
) * UNITS_PER_WORD
;
1454 gpr_save_area_size
= 0;
1456 /* Everything is in the GPR save area, or in the overflow
1457 area which is contiguous with it. */
1458 nextarg
= plus_constant (Pmode
, nextarg
, - gpr_save_area_size
);
1459 std_expand_builtin_va_start (valist
, nextarg
);
1462 /* Allocate a chunk of memory for per-function machine-dependent data. */
1464 static struct machine_function
*
1465 iq2000_init_machine_status (void)
1467 return ggc_cleared_alloc
<machine_function
> ();
1470 /* Detect any conflicts in the switches. */
1473 iq2000_option_override (void)
1475 target_flags
&= ~MASK_GPOPT
;
1477 iq2000_isa
= IQ2000_ISA_DEFAULT
;
1479 /* Identify the processor type. */
1481 iq2000_print_operand_punct
['?'] = 1;
1482 iq2000_print_operand_punct
['#'] = 1;
1483 iq2000_print_operand_punct
['&'] = 1;
1484 iq2000_print_operand_punct
['!'] = 1;
1485 iq2000_print_operand_punct
['*'] = 1;
1486 iq2000_print_operand_punct
['@'] = 1;
1487 iq2000_print_operand_punct
['.'] = 1;
1488 iq2000_print_operand_punct
['('] = 1;
1489 iq2000_print_operand_punct
[')'] = 1;
1490 iq2000_print_operand_punct
['['] = 1;
1491 iq2000_print_operand_punct
[']'] = 1;
1492 iq2000_print_operand_punct
['<'] = 1;
1493 iq2000_print_operand_punct
['>'] = 1;
1494 iq2000_print_operand_punct
['{'] = 1;
1495 iq2000_print_operand_punct
['}'] = 1;
1496 iq2000_print_operand_punct
['^'] = 1;
1497 iq2000_print_operand_punct
['$'] = 1;
1498 iq2000_print_operand_punct
['+'] = 1;
1499 iq2000_print_operand_punct
['~'] = 1;
1501 /* Save GPR registers in word_mode sized hunks. word_mode hasn't been
1502 initialized yet, so we can't use that here. */
1505 /* Function to allocate machine-dependent function status. */
1506 init_machine_status
= iq2000_init_machine_status
;
1509 /* The arg pointer (which is eliminated) points to the virtual frame pointer,
1510 while the frame pointer (which may be eliminated) points to the stack
1511 pointer after the initial adjustments. */
1514 iq2000_debugger_offset (rtx addr
, HOST_WIDE_INT offset
)
1516 rtx offset2
= const0_rtx
;
1517 rtx reg
= eliminate_constant_term (addr
, & offset2
);
1520 offset
= INTVAL (offset2
);
1522 if (reg
== stack_pointer_rtx
|| reg
== frame_pointer_rtx
1523 || reg
== hard_frame_pointer_rtx
)
1525 HOST_WIDE_INT frame_size
= (!cfun
->machine
->initialized
)
1526 ? compute_frame_size (get_frame_size ())
1527 : cfun
->machine
->total_size
;
1529 offset
= offset
- frame_size
;
1535 /* If defined, a C statement to be executed just prior to the output of
1536 assembler code for INSN, to modify the extracted operands so they will be
1539 Here the argument OPVEC is the vector containing the operands extracted
1540 from INSN, and NOPERANDS is the number of elements of the vector which
1541 contain meaningful data for this insn. The contents of this vector are
1542 what will be used to convert the insn template into assembler code, so you
1543 can change the assembler output by changing the contents of the vector.
1545 We use it to check if the current insn needs a nop in front of it because
1546 of load delays, and also to update the delay slot statistics. */
1549 final_prescan_insn (rtx_insn
*insn
, rtx opvec
[] ATTRIBUTE_UNUSED
,
1550 int noperands ATTRIBUTE_UNUSED
)
1552 if (dslots_number_nops
> 0)
1554 rtx pattern
= PATTERN (insn
);
1555 int length
= get_attr_length (insn
);
1557 /* Do we need to emit a NOP? */
1559 || (iq2000_load_reg
!= 0 && reg_mentioned_p (iq2000_load_reg
, pattern
))
1560 || (iq2000_load_reg2
!= 0 && reg_mentioned_p (iq2000_load_reg2
, pattern
))
1561 || (iq2000_load_reg3
!= 0 && reg_mentioned_p (iq2000_load_reg3
, pattern
))
1562 || (iq2000_load_reg4
!= 0
1563 && reg_mentioned_p (iq2000_load_reg4
, pattern
)))
1564 fputs ("\tnop\n", asm_out_file
);
1567 dslots_load_filled
++;
1569 while (--dslots_number_nops
> 0)
1570 fputs ("\tnop\n", asm_out_file
);
1572 iq2000_load_reg
= 0;
1573 iq2000_load_reg2
= 0;
1574 iq2000_load_reg3
= 0;
1575 iq2000_load_reg4
= 0;
1580 || (GET_CODE (PATTERN (insn
)) == RETURN
))
1581 && NEXT_INSN (PREV_INSN (insn
)) == insn
)
1583 rtx_insn
*nop_insn
= emit_insn_after (gen_nop (), insn
);
1584 INSN_ADDRESSES_NEW (nop_insn
, -1);
1588 && (JUMP_P (insn
) || CALL_P (insn
)))
1589 dslots_jump_total
++;
1592 /* Return the bytes needed to compute the frame pointer from the current
1593 stack pointer where SIZE is the # of var. bytes allocated.
1595 IQ2000 stack frames look like:
1597 Before call After call
1598 +-----------------------+ +-----------------------+
1601 | caller's temps. | | caller's temps. |
1603 +-----------------------+ +-----------------------+
1605 | arguments on stack. | | arguments on stack. |
1607 +-----------------------+ +-----------------------+
1608 | 4 words to save | | 4 words to save |
1609 | arguments passed | | arguments passed |
1610 | in registers, even | | in registers, even |
1611 SP->| if not passed. | VFP->| if not passed. |
1612 +-----------------------+ +-----------------------+
1614 | fp register save |
1616 +-----------------------+
1618 | gp register save |
1620 +-----------------------+
1624 +-----------------------+
1626 | alloca allocations |
1628 +-----------------------+
1630 | GP save for V.4 abi |
1632 +-----------------------+
1634 | arguments on stack |
1636 +-----------------------+
1638 | arguments passed |
1639 | in registers, even |
1640 low SP->| if not passed. |
1641 memory +-----------------------+ */
1644 compute_frame_size (HOST_WIDE_INT size
)
1647 HOST_WIDE_INT total_size
; /* # bytes that the entire frame takes up. */
1648 HOST_WIDE_INT var_size
; /* # bytes that variables take up. */
1649 HOST_WIDE_INT args_size
; /* # bytes that outgoing arguments take up. */
1650 HOST_WIDE_INT extra_size
; /* # extra bytes. */
1651 HOST_WIDE_INT gp_reg_rounded
; /* # bytes needed to store gp after rounding. */
1652 HOST_WIDE_INT gp_reg_size
; /* # bytes needed to store gp regs. */
1653 HOST_WIDE_INT fp_reg_size
; /* # bytes needed to store fp regs. */
1654 long mask
; /* mask of saved gp registers. */
1659 extra_size
= IQ2000_STACK_ALIGN ((0));
1660 var_size
= IQ2000_STACK_ALIGN (size
);
1661 args_size
= IQ2000_STACK_ALIGN (crtl
->outgoing_args_size
);
1663 /* If a function dynamically allocates the stack and
1664 has 0 for STACK_DYNAMIC_OFFSET then allocate some stack space. */
1665 if (args_size
== 0 && cfun
->calls_alloca
)
1666 args_size
= 4 * UNITS_PER_WORD
;
1668 total_size
= var_size
+ args_size
+ extra_size
;
1670 /* Calculate space needed for gp registers. */
1671 for (regno
= GP_REG_FIRST
; regno
<= GP_REG_LAST
; regno
++)
1673 if (MUST_SAVE_REGISTER (regno
))
1675 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
1676 mask
|= 1L << (regno
- GP_REG_FIRST
);
1680 /* We need to restore these for the handler. */
1681 if (crtl
->calls_eh_return
)
1687 regno
= EH_RETURN_DATA_REGNO (i
);
1688 if (regno
== (int) INVALID_REGNUM
)
1690 gp_reg_size
+= GET_MODE_SIZE (gpr_mode
);
1691 mask
|= 1L << (regno
- GP_REG_FIRST
);
1695 gp_reg_rounded
= IQ2000_STACK_ALIGN (gp_reg_size
);
1696 total_size
+= gp_reg_rounded
+ IQ2000_STACK_ALIGN (fp_reg_size
);
1698 /* The gp reg is caller saved, so there is no need for leaf routines
1699 (total_size == extra_size) to save the gp reg. */
1700 if (total_size
== extra_size
1702 total_size
= extra_size
= 0;
1704 total_size
+= IQ2000_STACK_ALIGN (crtl
->args
.pretend_args_size
);
1706 /* Save other computed information. */
1707 cfun
->machine
->total_size
= total_size
;
1708 cfun
->machine
->var_size
= var_size
;
1709 cfun
->machine
->args_size
= args_size
;
1710 cfun
->machine
->extra_size
= extra_size
;
1711 cfun
->machine
->gp_reg_size
= gp_reg_size
;
1712 cfun
->machine
->fp_reg_size
= fp_reg_size
;
1713 cfun
->machine
->mask
= mask
;
1714 cfun
->machine
->initialized
= reload_completed
;
1715 cfun
->machine
->num_gp
= gp_reg_size
/ UNITS_PER_WORD
;
1719 unsigned long offset
;
1721 offset
= (args_size
+ extra_size
+ var_size
1722 + gp_reg_size
- GET_MODE_SIZE (gpr_mode
));
1724 cfun
->machine
->gp_sp_offset
= offset
;
1725 cfun
->machine
->gp_save_offset
= offset
- total_size
;
1729 cfun
->machine
->gp_sp_offset
= 0;
1730 cfun
->machine
->gp_save_offset
= 0;
1733 cfun
->machine
->fp_sp_offset
= 0;
1734 cfun
->machine
->fp_save_offset
= 0;
1736 /* Ok, we're done. */
1741 /* We can always eliminate to the frame pointer. We can eliminate to the
1742 stack pointer unless a frame pointer is needed. */
1745 iq2000_can_eliminate (const int from
, const int to
)
1747 return (from
== RETURN_ADDRESS_POINTER_REGNUM
1748 && (! leaf_function_p ()
1749 || (to
== GP_REG_FIRST
+ 31 && leaf_function_p ())))
1750 || (from
!= RETURN_ADDRESS_POINTER_REGNUM
1751 && (to
== HARD_FRAME_POINTER_REGNUM
1752 || (to
== STACK_POINTER_REGNUM
1753 && ! frame_pointer_needed
)));
1756 /* Implement INITIAL_ELIMINATION_OFFSET. FROM is either the frame
1757 pointer, argument pointer, or return address pointer. TO is either
1758 the stack pointer or hard frame pointer. */
1761 iq2000_initial_elimination_offset (int from
, int to ATTRIBUTE_UNUSED
)
1765 compute_frame_size (get_frame_size ());
1766 if ((from
) == FRAME_POINTER_REGNUM
)
1768 else if ((from
) == ARG_POINTER_REGNUM
)
1769 (offset
) = (cfun
->machine
->total_size
);
1770 else if ((from
) == RETURN_ADDRESS_POINTER_REGNUM
)
1772 if (leaf_function_p ())
1774 else (offset
) = cfun
->machine
->gp_sp_offset
1775 + ((UNITS_PER_WORD
- (POINTER_SIZE
/ BITS_PER_UNIT
))
1776 * (BYTES_BIG_ENDIAN
!= 0));
1784 /* Common code to emit the insns (or to write the instructions to a file)
1785 to save/restore registers.
1786 Other parts of the code assume that IQ2000_TEMP1_REGNUM (aka large_reg)
1787 is not modified within save_restore_insns. */
1789 #define BITSET_P(VALUE,BIT) (((VALUE) & (1L << (BIT))) != 0)
1791 /* Emit instructions to load the value (SP + OFFSET) into IQ2000_TEMP2_REGNUM
1792 and return an rtl expression for the register. Write the assembly
1793 instructions directly to FILE if it is not null, otherwise emit them as
1796 This function is a subroutine of save_restore_insns. It is used when
1797 OFFSET is too large to add in a single instruction. */
1800 iq2000_add_large_offset_to_sp (HOST_WIDE_INT offset
)
1802 rtx reg
= gen_rtx_REG (Pmode
, IQ2000_TEMP2_REGNUM
);
1803 rtx offset_rtx
= GEN_INT (offset
);
1805 emit_move_insn (reg
, offset_rtx
);
1806 emit_insn (gen_addsi3 (reg
, reg
, stack_pointer_rtx
));
1810 /* Make INSN frame related and note that it performs the frame-related
1811 operation DWARF_PATTERN. */
1814 iq2000_annotate_frame_insn (rtx_insn
*insn
, rtx dwarf_pattern
)
1816 RTX_FRAME_RELATED_P (insn
) = 1;
1817 REG_NOTES (insn
) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR
,
1822 /* Emit a move instruction that stores REG in MEM. Make the instruction
1823 frame related and note that it stores REG at (SP + OFFSET). */
1826 iq2000_emit_frame_related_store (rtx mem
, rtx reg
, HOST_WIDE_INT offset
)
1828 rtx dwarf_address
= plus_constant (Pmode
, stack_pointer_rtx
, offset
);
1829 rtx dwarf_mem
= gen_rtx_MEM (GET_MODE (reg
), dwarf_address
);
1831 iq2000_annotate_frame_insn (emit_move_insn (mem
, reg
),
1832 gen_rtx_SET (dwarf_mem
, reg
));
1835 /* Emit instructions to save/restore registers, as determined by STORE_P. */
1838 save_restore_insns (int store_p
)
1840 long mask
= cfun
->machine
->mask
;
1843 HOST_WIDE_INT base_offset
;
1844 HOST_WIDE_INT gp_offset
;
1845 HOST_WIDE_INT end_offset
;
1847 gcc_assert (!frame_pointer_needed
1848 || BITSET_P (mask
, HARD_FRAME_POINTER_REGNUM
- GP_REG_FIRST
));
1852 base_reg_rtx
= 0, base_offset
= 0;
1856 /* Save registers starting from high to low. The debuggers prefer at least
1857 the return register be stored at func+4, and also it allows us not to
1858 need a nop in the epilog if at least one register is reloaded in
1859 addition to return address. */
1861 /* Save GP registers if needed. */
1862 /* Pick which pointer to use as a base register. For small frames, just
1863 use the stack pointer. Otherwise, use a temporary register. Save 2
1864 cycles if the save area is near the end of a large frame, by reusing
1865 the constant created in the prologue/epilogue to adjust the stack
1868 gp_offset
= cfun
->machine
->gp_sp_offset
;
1870 = gp_offset
- (cfun
->machine
->gp_reg_size
1871 - GET_MODE_SIZE (gpr_mode
));
1873 if (gp_offset
< 0 || end_offset
< 0)
1875 ("gp_offset (%ld) or end_offset (%ld) is less than zero",
1876 (long) gp_offset
, (long) end_offset
);
1878 else if (gp_offset
< 32768)
1879 base_reg_rtx
= stack_pointer_rtx
, base_offset
= 0;
1883 int reg_save_count
= 0;
1885 for (regno
= GP_REG_LAST
; regno
>= GP_REG_FIRST
; regno
--)
1886 if (BITSET_P (mask
, regno
- GP_REG_FIRST
)) reg_save_count
+= 1;
1887 base_offset
= gp_offset
- ((reg_save_count
- 1) * 4);
1888 base_reg_rtx
= iq2000_add_large_offset_to_sp (base_offset
);
1891 for (regno
= GP_REG_LAST
; regno
>= GP_REG_FIRST
; regno
--)
1893 if (BITSET_P (mask
, regno
- GP_REG_FIRST
))
1897 = gen_rtx_MEM (gpr_mode
,
1898 gen_rtx_PLUS (Pmode
, base_reg_rtx
,
1899 GEN_INT (gp_offset
- base_offset
)));
1901 reg_rtx
= gen_rtx_REG (gpr_mode
, regno
);
1904 iq2000_emit_frame_related_store (mem_rtx
, reg_rtx
, gp_offset
);
1907 emit_move_insn (reg_rtx
, mem_rtx
);
1909 gp_offset
-= GET_MODE_SIZE (gpr_mode
);
1914 /* Expand the prologue into a bunch of separate insns. */
1917 iq2000_expand_prologue (void)
1920 HOST_WIDE_INT tsize
;
1921 int last_arg_is_vararg_marker
= 0;
1922 tree fndecl
= current_function_decl
;
1923 tree fntype
= TREE_TYPE (fndecl
);
1924 tree fnargs
= DECL_ARGUMENTS (fndecl
);
1929 CUMULATIVE_ARGS args_so_far_v
;
1930 cumulative_args_t args_so_far
;
1931 int store_args_on_stack
= (iq2000_can_use_return_insn ());
1933 /* If struct value address is treated as the first argument. */
1934 if (aggregate_value_p (DECL_RESULT (fndecl
), fndecl
)
1935 && !cfun
->returns_pcc_struct
1936 && targetm
.calls
.struct_value_rtx (TREE_TYPE (fndecl
), 1) == 0)
1938 tree type
= build_pointer_type (fntype
);
1939 tree function_result_decl
= build_decl (BUILTINS_LOCATION
,
1940 PARM_DECL
, NULL_TREE
, type
);
1942 DECL_ARG_TYPE (function_result_decl
) = type
;
1943 DECL_CHAIN (function_result_decl
) = fnargs
;
1944 fnargs
= function_result_decl
;
1947 /* For arguments passed in registers, find the register number
1948 of the first argument in the variable part of the argument list,
1949 otherwise GP_ARG_LAST+1. Note also if the last argument is
1950 the varargs special argument, and treat it as part of the
1953 This is only needed if store_args_on_stack is true. */
1954 INIT_CUMULATIVE_ARGS (args_so_far_v
, fntype
, NULL_RTX
, 0, 0);
1955 args_so_far
= pack_cumulative_args (&args_so_far_v
);
1956 regno
= GP_ARG_FIRST
;
1958 for (cur_arg
= fnargs
; cur_arg
!= 0; cur_arg
= next_arg
)
1960 tree passed_type
= DECL_ARG_TYPE (cur_arg
);
1961 machine_mode passed_mode
= TYPE_MODE (passed_type
);
1964 if (TREE_ADDRESSABLE (passed_type
))
1966 passed_type
= build_pointer_type (passed_type
);
1967 passed_mode
= Pmode
;
1970 function_arg_info
arg (passed_type
, passed_mode
, /*named=*/true);
1971 entry_parm
= iq2000_function_arg (args_so_far
, arg
);
1973 iq2000_function_arg_advance (args_so_far
, arg
);
1974 next_arg
= DECL_CHAIN (cur_arg
);
1976 if (entry_parm
&& store_args_on_stack
)
1979 && DECL_NAME (cur_arg
)
1980 && (strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg
)),
1981 "__builtin_va_alist") == 0
1982 || strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg
)),
1985 last_arg_is_vararg_marker
= 1;
1992 gcc_assert (GET_CODE (entry_parm
) == REG
);
1994 /* Passed in a register, so will get homed automatically. */
1995 if (GET_MODE (entry_parm
) == BLKmode
)
1996 words
= (int_size_in_bytes (passed_type
) + 3) / 4;
1998 words
= (GET_MODE_SIZE (GET_MODE (entry_parm
)) + 3) / 4;
2000 regno
= REGNO (entry_parm
) + words
- 1;
2005 regno
= GP_ARG_LAST
+1;
2010 /* In order to pass small structures by value in registers we need to
2011 shift the value into the high part of the register.
2012 iq2000_unction_arg has encoded a PARALLEL rtx, holding a vector of
2013 adjustments to be made as the next_arg_reg variable, so we split up
2014 the insns, and emit them separately. */
2015 next_arg_reg
= iq2000_function_arg (args_so_far
,
2016 function_arg_info::end_marker ());
2017 if (next_arg_reg
!= 0 && GET_CODE (next_arg_reg
) == PARALLEL
)
2019 rtvec adjust
= XVEC (next_arg_reg
, 0);
2020 int num
= GET_NUM_ELEM (adjust
);
2022 for (i
= 0; i
< num
; i
++)
2026 pattern
= RTVEC_ELT (adjust
, i
);
2027 if (GET_CODE (pattern
) != SET
2028 || GET_CODE (SET_SRC (pattern
)) != ASHIFT
)
2029 abort_with_insn (pattern
, "Insn is not a shift");
2030 PUT_CODE (SET_SRC (pattern
), ASHIFTRT
);
2032 emit_insn (pattern
);
2036 tsize
= compute_frame_size (get_frame_size ());
2038 /* If this function is a varargs function, store any registers that
2039 would normally hold arguments ($4 - $7) on the stack. */
2040 if (store_args_on_stack
2041 && (stdarg_p (fntype
)
2042 || last_arg_is_vararg_marker
))
2044 int offset
= (regno
- GP_ARG_FIRST
) * UNITS_PER_WORD
;
2045 rtx ptr
= stack_pointer_rtx
;
2047 for (; regno
<= GP_ARG_LAST
; regno
++)
2050 ptr
= gen_rtx_PLUS (Pmode
, stack_pointer_rtx
, GEN_INT (offset
));
2051 emit_move_insn (gen_rtx_MEM (gpr_mode
, ptr
),
2052 gen_rtx_REG (gpr_mode
, regno
));
2054 offset
+= GET_MODE_SIZE (gpr_mode
);
2060 rtx tsize_rtx
= GEN_INT (tsize
);
2061 rtx adjustment_rtx
, dwarf_pattern
;
2066 adjustment_rtx
= gen_rtx_REG (Pmode
, IQ2000_TEMP1_REGNUM
);
2067 emit_move_insn (adjustment_rtx
, tsize_rtx
);
2070 adjustment_rtx
= tsize_rtx
;
2072 insn
= emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2075 dwarf_pattern
= gen_rtx_SET (stack_pointer_rtx
,
2076 plus_constant (Pmode
, stack_pointer_rtx
,
2079 iq2000_annotate_frame_insn (insn
, dwarf_pattern
);
2081 save_restore_insns (1);
2083 if (frame_pointer_needed
)
2087 insn
= emit_insn (gen_movsi (hard_frame_pointer_rtx
,
2088 stack_pointer_rtx
));
2091 RTX_FRAME_RELATED_P (insn
) = 1;
2095 if (flag_stack_usage_info
)
2096 current_function_static_stack_size
= cfun
->machine
->total_size
;
2098 emit_insn (gen_blockage ());
2101 /* Expand the epilogue into a bunch of separate insns. */
2104 iq2000_expand_epilogue (void)
2106 HOST_WIDE_INT tsize
= cfun
->machine
->total_size
;
2107 rtx tsize_rtx
= GEN_INT (tsize
);
2108 rtx tmp_rtx
= (rtx
)0;
2110 if (iq2000_can_use_return_insn ())
2112 emit_jump_insn (gen_return ());
2118 tmp_rtx
= gen_rtx_REG (Pmode
, IQ2000_TEMP1_REGNUM
);
2119 emit_move_insn (tmp_rtx
, tsize_rtx
);
2120 tsize_rtx
= tmp_rtx
;
2125 if (frame_pointer_needed
)
2127 emit_insn (gen_blockage ());
2129 emit_insn (gen_movsi (stack_pointer_rtx
, hard_frame_pointer_rtx
));
2132 save_restore_insns (0);
2134 if (crtl
->calls_eh_return
)
2136 rtx eh_ofs
= EH_RETURN_STACKADJ_RTX
;
2137 emit_insn (gen_addsi3 (eh_ofs
, eh_ofs
, tsize_rtx
));
2141 emit_insn (gen_blockage ());
2143 if (tsize
!= 0 || crtl
->calls_eh_return
)
2145 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
,
2150 if (crtl
->calls_eh_return
)
2152 /* Perform the additional bump for __throw. */
2153 emit_move_insn (gen_rtx_REG (Pmode
, HARD_FRAME_POINTER_REGNUM
),
2155 emit_use (gen_rtx_REG (Pmode
, HARD_FRAME_POINTER_REGNUM
));
2156 emit_jump_insn (gen_eh_return_internal ());
2159 emit_jump_insn (gen_return_internal (gen_rtx_REG (Pmode
,
2160 GP_REG_FIRST
+ 31)));
2164 iq2000_expand_eh_return (rtx address
)
2166 HOST_WIDE_INT gp_offset
= cfun
->machine
->gp_sp_offset
;
2169 scratch
= plus_constant (Pmode
, stack_pointer_rtx
, gp_offset
);
2170 emit_move_insn (gen_rtx_MEM (GET_MODE (address
), scratch
), address
);
2173 /* Return nonzero if this function is known to have a null epilogue.
2174 This allows the optimizer to omit jumps to jumps if no stack
2178 iq2000_can_use_return_insn (void)
2180 if (! reload_completed
)
2183 if (df_regs_ever_live_p (31) || profile_flag
)
2186 if (cfun
->machine
->initialized
)
2187 return cfun
->machine
->total_size
== 0;
2189 return compute_frame_size (get_frame_size ()) == 0;
2192 /* Choose the section to use for the constant rtx expression X that has
2196 iq2000_select_rtx_section (machine_mode mode
, rtx x ATTRIBUTE_UNUSED
,
2197 unsigned HOST_WIDE_INT align
)
2199 /* For embedded applications, always put constants in read-only data,
2200 in order to reduce RAM usage. */
2201 return mergeable_constant_section (mode
, align
, 0);
2204 /* Choose the section to use for DECL. RELOC is true if its value contains
2205 any relocatable expression.
2207 Some of the logic used here needs to be replicated in
2208 ENCODE_SECTION_INFO in iq2000.h so that references to these symbols
2209 are done correctly. */
2212 iq2000_select_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
2213 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
2215 if (TARGET_EMBEDDED_DATA
)
2217 /* For embedded applications, always put an object in read-only data
2218 if possible, in order to reduce RAM usage. */
2219 if ((TREE_CODE (decl
) == VAR_DECL
2220 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
)
2221 && DECL_INITIAL (decl
)
2222 && (DECL_INITIAL (decl
) == error_mark_node
2223 || TREE_CONSTANT (DECL_INITIAL (decl
))))
2224 /* Deal with calls from output_constant_def_contents. */
2225 || TREE_CODE (decl
) != VAR_DECL
)
2226 return readonly_data_section
;
2228 return data_section
;
2232 /* For hosted applications, always put an object in small data if
2233 possible, as this gives the best performance. */
2234 if ((TREE_CODE (decl
) == VAR_DECL
2235 && TREE_READONLY (decl
) && !TREE_SIDE_EFFECTS (decl
)
2236 && DECL_INITIAL (decl
)
2237 && (DECL_INITIAL (decl
) == error_mark_node
2238 || TREE_CONSTANT (DECL_INITIAL (decl
))))
2239 /* Deal with calls from output_constant_def_contents. */
2240 || TREE_CODE (decl
) != VAR_DECL
)
2241 return readonly_data_section
;
2243 return data_section
;
2246 /* Return register to use for a function return value with VALTYPE for function
2250 iq2000_function_value (const_tree valtype
,
2251 const_tree fn_decl_or_type
,
2252 bool outgoing ATTRIBUTE_UNUSED
)
2254 int reg
= GP_RETURN
;
2255 machine_mode mode
= TYPE_MODE (valtype
);
2256 int unsignedp
= TYPE_UNSIGNED (valtype
);
2257 const_tree func
= fn_decl_or_type
;
2260 && !DECL_P (fn_decl_or_type
))
2261 fn_decl_or_type
= NULL
;
2263 /* Since we promote return types, we must promote the mode here too. */
2264 mode
= promote_function_mode (valtype
, mode
, &unsignedp
, func
, 1);
2266 return gen_rtx_REG (mode
, reg
);
2269 /* Worker function for TARGET_LIBCALL_VALUE. */
2272 iq2000_libcall_value (machine_mode mode
, const_rtx fun ATTRIBUTE_UNUSED
)
2274 return gen_rtx_REG (((GET_MODE_CLASS (mode
) != MODE_INT
2275 || GET_MODE_SIZE (mode
) >= 4)
2280 /* Worker function for FUNCTION_VALUE_REGNO_P.
2282 On the IQ2000, R2 and R3 are the only register thus used. */
2285 iq2000_function_value_regno_p (const unsigned int regno
)
2287 return (regno
== GP_RETURN
);
2291 /* Return true when an argument must be passed by reference. */
2294 iq2000_pass_by_reference (cumulative_args_t cum_v
,
2295 const function_arg_info
&arg
)
2297 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
2300 /* We must pass by reference if we would be both passing in registers
2301 and the stack. This is because any subsequent partial arg would be
2302 handled incorrectly in this case. */
2303 if (cum
&& targetm
.calls
.must_pass_in_stack (arg
.mode
, arg
.type
))
2305 /* Don't pass the actual CUM to FUNCTION_ARG, because we would
2306 get double copies of any offsets generated for small structs
2307 passed in registers. */
2308 CUMULATIVE_ARGS temp
;
2311 if (iq2000_function_arg (pack_cumulative_args (&temp
), arg
) != 0)
2315 if (arg
.type
== NULL_TREE
|| arg
.mode
== DImode
|| arg
.mode
== DFmode
)
2318 size
= int_size_in_bytes (arg
.type
);
2319 return size
== -1 || size
> UNITS_PER_WORD
;
2322 /* Return the length of INSN. LENGTH is the initial length computed by
2323 attributes in the machine-description file. */
2326 iq2000_adjust_insn_length (rtx_insn
*insn
, int length
)
2328 /* A unconditional jump has an unfilled delay slot if it is not part
2329 of a sequence. A conditional jump normally has a delay slot. */
2330 if (simplejump_p (insn
)
2338 /* Output assembly instructions to perform a conditional branch.
2340 INSN is the branch instruction. OPERANDS[0] is the condition.
2341 OPERANDS[1] is the target of the branch. OPERANDS[2] is the target
2342 of the first operand to the condition. If TWO_OPERANDS_P is
2343 nonzero the comparison takes two operands; OPERANDS[3] will be the
2346 If INVERTED_P is nonzero we are to branch if the condition does
2347 not hold. If FLOAT_P is nonzero this is a floating-point comparison.
2349 LENGTH is the length (in bytes) of the sequence we are to generate.
2350 That tells us whether to generate a simple conditional branch, or a
2351 reversed conditional branch around a `jr' instruction. */
2354 iq2000_output_conditional_branch (rtx_insn
*insn
, rtx
* operands
,
2355 int two_operands_p
, int float_p
,
2356 int inverted_p
, int length
)
2358 static char buffer
[200];
2359 /* The kind of comparison we are doing. */
2360 enum rtx_code code
= GET_CODE (operands
[0]);
2361 /* Nonzero if the opcode for the comparison needs a `z' indicating
2362 that it is a comparison against zero. */
2364 /* A string to use in the assembly output to represent the first
2366 const char *op1
= "%z2";
2367 /* A string to use in the assembly output to represent the second
2368 operand. Use the hard-wired zero register if there's no second
2370 const char *op2
= (two_operands_p
? ",%z3" : ",%.");
2371 /* The operand-printing string for the comparison. */
2372 const char *comp
= (float_p
? "%F0" : "%C0");
2373 /* The operand-printing string for the inverted comparison. */
2374 const char *inverted_comp
= (float_p
? "%W0" : "%N0");
2376 /* Likely variants of each branch instruction annul the instruction
2377 in the delay slot if the branch is not taken. */
2378 iq2000_branch_likely
= (final_sequence
&& INSN_ANNULLED_BRANCH_P (insn
));
2380 if (!two_operands_p
)
2382 /* To compute whether than A > B, for example, we normally
2383 subtract B from A and then look at the sign bit. But, if we
2384 are doing an unsigned comparison, and B is zero, we don't
2385 have to do the subtraction. Instead, we can just check to
2386 see if A is nonzero. Thus, we change the CODE here to
2387 reflect the simpler comparison operation. */
2399 /* A condition which will always be true. */
2405 /* A condition which will always be false. */
2411 /* Not a special case. */
2416 /* Relative comparisons are always done against zero. But
2417 equality comparisons are done between two operands, and therefore
2418 do not require a `z' in the assembly language output. */
2419 need_z_p
= (!float_p
&& code
!= EQ
&& code
!= NE
);
2420 /* For comparisons against zero, the zero is not provided
2425 /* Begin by terminating the buffer. That way we can always use
2426 strcat to add to it. */
2433 /* Just a simple conditional branch. */
2435 sprintf (buffer
, "b%s%%?\t%%Z2%%1",
2436 inverted_p
? inverted_comp
: comp
);
2438 sprintf (buffer
, "b%s%s%%?\t%s%s,%%1",
2439 inverted_p
? inverted_comp
: comp
,
2440 need_z_p
? "z" : "",
2448 /* Generate a reversed conditional branch around ` j'
2460 Because we have to jump four bytes *past* the following
2461 instruction if this branch was annulled, we can't just use
2462 a label, as in the picture above; there's no way to put the
2463 label after the next instruction, as the assembler does not
2464 accept `.L+4' as the target of a branch. (We can't just
2465 wait until the next instruction is output; it might be a
2466 macro and take up more than four bytes. Once again, we see
2467 why we want to eliminate macros.)
2469 If the branch is annulled, we jump four more bytes that we
2470 would otherwise; that way we skip the annulled instruction
2471 in the delay slot. */
2474 = ((iq2000_branch_likely
|| length
== 16) ? ".+16" : ".+12");
2477 c
= strchr (buffer
, '\0');
2478 /* Generate the reversed comparison. This takes four
2481 sprintf (c
, "b%s\t%%Z2%s",
2482 inverted_p
? comp
: inverted_comp
,
2485 sprintf (c
, "b%s%s\t%s%s,%s",
2486 inverted_p
? comp
: inverted_comp
,
2487 need_z_p
? "z" : "",
2491 strcat (c
, "\n\tnop\n\tj\t%1");
2493 /* The delay slot was unfilled. Since we're inside
2494 .noreorder, the assembler will not fill in the NOP for
2495 us, so we must do it ourselves. */
2496 strcat (buffer
, "\n\tnop");
2508 #define def_builtin(NAME, TYPE, CODE) \
2509 add_builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
2513 iq2000_init_builtins (void)
2515 tree void_ftype
, void_ftype_int
, void_ftype_int_int
;
2516 tree void_ftype_int_int_int
;
2517 tree int_ftype_int
, int_ftype_int_int
, int_ftype_int_int_int
;
2518 tree int_ftype_int_int_int_int
;
2522 = build_function_type_list (void_type_node
, NULL_TREE
);
2526 = build_function_type_list (void_type_node
, integer_type_node
, NULL_TREE
);
2528 /* void func (int, int) */
2530 = build_function_type_list (void_type_node
,
2535 /* int func (int) */
2537 = build_function_type_list (integer_type_node
,
2538 integer_type_node
, NULL_TREE
);
2540 /* int func (int, int) */
2542 = build_function_type_list (integer_type_node
,
2547 /* void func (int, int, int) */
2548 void_ftype_int_int_int
2549 = build_function_type_list (void_type_node
,
2555 /* int func (int, int, int) */
2556 int_ftype_int_int_int
2557 = build_function_type_list (integer_type_node
,
2563 /* int func (int, int, int, int) */
2564 int_ftype_int_int_int_int
2565 = build_function_type_list (integer_type_node
,
2572 def_builtin ("__builtin_ado16", int_ftype_int_int
, IQ2000_BUILTIN_ADO16
);
2573 def_builtin ("__builtin_ram", int_ftype_int_int_int_int
, IQ2000_BUILTIN_RAM
);
2574 def_builtin ("__builtin_chkhdr", void_ftype_int_int
, IQ2000_BUILTIN_CHKHDR
);
2575 def_builtin ("__builtin_pkrl", void_ftype_int_int
, IQ2000_BUILTIN_PKRL
);
2576 def_builtin ("__builtin_cfc0", int_ftype_int
, IQ2000_BUILTIN_CFC0
);
2577 def_builtin ("__builtin_cfc1", int_ftype_int
, IQ2000_BUILTIN_CFC1
);
2578 def_builtin ("__builtin_cfc2", int_ftype_int
, IQ2000_BUILTIN_CFC2
);
2579 def_builtin ("__builtin_cfc3", int_ftype_int
, IQ2000_BUILTIN_CFC3
);
2580 def_builtin ("__builtin_ctc0", void_ftype_int_int
, IQ2000_BUILTIN_CTC0
);
2581 def_builtin ("__builtin_ctc1", void_ftype_int_int
, IQ2000_BUILTIN_CTC1
);
2582 def_builtin ("__builtin_ctc2", void_ftype_int_int
, IQ2000_BUILTIN_CTC2
);
2583 def_builtin ("__builtin_ctc3", void_ftype_int_int
, IQ2000_BUILTIN_CTC3
);
2584 def_builtin ("__builtin_mfc0", int_ftype_int
, IQ2000_BUILTIN_MFC0
);
2585 def_builtin ("__builtin_mfc1", int_ftype_int
, IQ2000_BUILTIN_MFC1
);
2586 def_builtin ("__builtin_mfc2", int_ftype_int
, IQ2000_BUILTIN_MFC2
);
2587 def_builtin ("__builtin_mfc3", int_ftype_int
, IQ2000_BUILTIN_MFC3
);
2588 def_builtin ("__builtin_mtc0", void_ftype_int_int
, IQ2000_BUILTIN_MTC0
);
2589 def_builtin ("__builtin_mtc1", void_ftype_int_int
, IQ2000_BUILTIN_MTC1
);
2590 def_builtin ("__builtin_mtc2", void_ftype_int_int
, IQ2000_BUILTIN_MTC2
);
2591 def_builtin ("__builtin_mtc3", void_ftype_int_int
, IQ2000_BUILTIN_MTC3
);
2592 def_builtin ("__builtin_lur", void_ftype_int_int
, IQ2000_BUILTIN_LUR
);
2593 def_builtin ("__builtin_rb", void_ftype_int_int
, IQ2000_BUILTIN_RB
);
2594 def_builtin ("__builtin_rx", void_ftype_int_int
, IQ2000_BUILTIN_RX
);
2595 def_builtin ("__builtin_srrd", void_ftype_int
, IQ2000_BUILTIN_SRRD
);
2596 def_builtin ("__builtin_srwr", void_ftype_int_int
, IQ2000_BUILTIN_SRWR
);
2597 def_builtin ("__builtin_wb", void_ftype_int_int
, IQ2000_BUILTIN_WB
);
2598 def_builtin ("__builtin_wx", void_ftype_int_int
, IQ2000_BUILTIN_WX
);
2599 def_builtin ("__builtin_luc32l", void_ftype_int_int
, IQ2000_BUILTIN_LUC32L
);
2600 def_builtin ("__builtin_luc64", void_ftype_int_int
, IQ2000_BUILTIN_LUC64
);
2601 def_builtin ("__builtin_luc64l", void_ftype_int_int
, IQ2000_BUILTIN_LUC64L
);
2602 def_builtin ("__builtin_luk", void_ftype_int_int
, IQ2000_BUILTIN_LUK
);
2603 def_builtin ("__builtin_lulck", void_ftype_int
, IQ2000_BUILTIN_LULCK
);
2604 def_builtin ("__builtin_lum32", void_ftype_int_int
, IQ2000_BUILTIN_LUM32
);
2605 def_builtin ("__builtin_lum32l", void_ftype_int_int
, IQ2000_BUILTIN_LUM32L
);
2606 def_builtin ("__builtin_lum64", void_ftype_int_int
, IQ2000_BUILTIN_LUM64
);
2607 def_builtin ("__builtin_lum64l", void_ftype_int_int
, IQ2000_BUILTIN_LUM64L
);
2608 def_builtin ("__builtin_lurl", void_ftype_int_int
, IQ2000_BUILTIN_LURL
);
2609 def_builtin ("__builtin_mrgb", int_ftype_int_int_int
, IQ2000_BUILTIN_MRGB
);
2610 def_builtin ("__builtin_srrdl", void_ftype_int
, IQ2000_BUILTIN_SRRDL
);
2611 def_builtin ("__builtin_srulck", void_ftype_int
, IQ2000_BUILTIN_SRULCK
);
2612 def_builtin ("__builtin_srwru", void_ftype_int_int
, IQ2000_BUILTIN_SRWRU
);
2613 def_builtin ("__builtin_trapqfl", void_ftype
, IQ2000_BUILTIN_TRAPQFL
);
2614 def_builtin ("__builtin_trapqne", void_ftype
, IQ2000_BUILTIN_TRAPQNE
);
2615 def_builtin ("__builtin_traprel", void_ftype_int
, IQ2000_BUILTIN_TRAPREL
);
2616 def_builtin ("__builtin_wbu", void_ftype_int_int_int
, IQ2000_BUILTIN_WBU
);
2617 def_builtin ("__builtin_syscall", void_ftype
, IQ2000_BUILTIN_SYSCALL
);
2620 /* Builtin for ICODE having ARGCOUNT args in EXP where each arg
2624 expand_one_builtin (enum insn_code icode
, rtx target
, tree exp
,
2625 enum rtx_code
*code
, int argcount
)
2630 machine_mode mode
[5];
2633 mode
[0] = insn_data
[icode
].operand
[0].mode
;
2634 for (i
= 0; i
< argcount
; i
++)
2636 arg
[i
] = CALL_EXPR_ARG (exp
, i
);
2637 op
[i
] = expand_normal (arg
[i
]);
2638 mode
[i
] = insn_data
[icode
].operand
[i
].mode
;
2639 if (code
[i
] == CONST_INT
&& GET_CODE (op
[i
]) != CONST_INT
)
2640 error ("argument %qd is not a constant", i
+ 1);
2642 && ! (*insn_data
[icode
].operand
[i
].predicate
) (op
[i
], mode
[i
]))
2643 op
[i
] = copy_to_mode_reg (mode
[i
], op
[i
]);
2646 if (insn_data
[icode
].operand
[0].constraint
[0] == '=')
2649 || GET_MODE (target
) != mode
[0]
2650 || ! (*insn_data
[icode
].operand
[0].predicate
) (target
, mode
[0]))
2651 target
= gen_reg_rtx (mode
[0]);
2659 pat
= GEN_FCN (icode
) (target
);
2663 pat
= GEN_FCN (icode
) (target
, op
[0]);
2665 pat
= GEN_FCN (icode
) (op
[0]);
2669 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1]);
2671 pat
= GEN_FCN (icode
) (op
[0], op
[1]);
2675 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1], op
[2]);
2677 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2]);
2681 pat
= GEN_FCN (icode
) (target
, op
[0], op
[1], op
[2], op
[3]);
2683 pat
= GEN_FCN (icode
) (op
[0], op
[1], op
[2], op
[3]);
2695 /* Expand an expression EXP that calls a built-in function,
2696 with result going to TARGET if that's convenient
2697 (and in mode MODE if that's convenient).
2698 SUBTARGET may be used as the target for computing one of EXP's operands.
2699 IGNORE is nonzero if the value is to be ignored. */
2702 iq2000_expand_builtin (tree exp
, rtx target
, rtx subtarget ATTRIBUTE_UNUSED
,
2703 machine_mode mode ATTRIBUTE_UNUSED
,
2704 int ignore ATTRIBUTE_UNUSED
)
2706 tree fndecl
= TREE_OPERAND (CALL_EXPR_FN (exp
), 0);
2707 int fcode
= DECL_MD_FUNCTION_CODE (fndecl
);
2708 enum rtx_code code
[5];
2720 case IQ2000_BUILTIN_ADO16
:
2721 return expand_one_builtin (CODE_FOR_ado16
, target
, exp
, code
, 2);
2723 case IQ2000_BUILTIN_RAM
:
2724 code
[1] = CONST_INT
;
2725 code
[2] = CONST_INT
;
2726 code
[3] = CONST_INT
;
2727 return expand_one_builtin (CODE_FOR_ram
, target
, exp
, code
, 4);
2729 case IQ2000_BUILTIN_CHKHDR
:
2730 return expand_one_builtin (CODE_FOR_chkhdr
, target
, exp
, code
, 2);
2732 case IQ2000_BUILTIN_PKRL
:
2733 return expand_one_builtin (CODE_FOR_pkrl
, target
, exp
, code
, 2);
2735 case IQ2000_BUILTIN_CFC0
:
2736 code
[0] = CONST_INT
;
2737 return expand_one_builtin (CODE_FOR_cfc0
, target
, exp
, code
, 1);
2739 case IQ2000_BUILTIN_CFC1
:
2740 code
[0] = CONST_INT
;
2741 return expand_one_builtin (CODE_FOR_cfc1
, target
, exp
, code
, 1);
2743 case IQ2000_BUILTIN_CFC2
:
2744 code
[0] = CONST_INT
;
2745 return expand_one_builtin (CODE_FOR_cfc2
, target
, exp
, code
, 1);
2747 case IQ2000_BUILTIN_CFC3
:
2748 code
[0] = CONST_INT
;
2749 return expand_one_builtin (CODE_FOR_cfc3
, target
, exp
, code
, 1);
2751 case IQ2000_BUILTIN_CTC0
:
2752 code
[1] = CONST_INT
;
2753 return expand_one_builtin (CODE_FOR_ctc0
, target
, exp
, code
, 2);
2755 case IQ2000_BUILTIN_CTC1
:
2756 code
[1] = CONST_INT
;
2757 return expand_one_builtin (CODE_FOR_ctc1
, target
, exp
, code
, 2);
2759 case IQ2000_BUILTIN_CTC2
:
2760 code
[1] = CONST_INT
;
2761 return expand_one_builtin (CODE_FOR_ctc2
, target
, exp
, code
, 2);
2763 case IQ2000_BUILTIN_CTC3
:
2764 code
[1] = CONST_INT
;
2765 return expand_one_builtin (CODE_FOR_ctc3
, target
, exp
, code
, 2);
2767 case IQ2000_BUILTIN_MFC0
:
2768 code
[0] = CONST_INT
;
2769 return expand_one_builtin (CODE_FOR_mfc0
, target
, exp
, code
, 1);
2771 case IQ2000_BUILTIN_MFC1
:
2772 code
[0] = CONST_INT
;
2773 return expand_one_builtin (CODE_FOR_mfc1
, target
, exp
, code
, 1);
2775 case IQ2000_BUILTIN_MFC2
:
2776 code
[0] = CONST_INT
;
2777 return expand_one_builtin (CODE_FOR_mfc2
, target
, exp
, code
, 1);
2779 case IQ2000_BUILTIN_MFC3
:
2780 code
[0] = CONST_INT
;
2781 return expand_one_builtin (CODE_FOR_mfc3
, target
, exp
, code
, 1);
2783 case IQ2000_BUILTIN_MTC0
:
2784 code
[1] = CONST_INT
;
2785 return expand_one_builtin (CODE_FOR_mtc0
, target
, exp
, code
, 2);
2787 case IQ2000_BUILTIN_MTC1
:
2788 code
[1] = CONST_INT
;
2789 return expand_one_builtin (CODE_FOR_mtc1
, target
, exp
, code
, 2);
2791 case IQ2000_BUILTIN_MTC2
:
2792 code
[1] = CONST_INT
;
2793 return expand_one_builtin (CODE_FOR_mtc2
, target
, exp
, code
, 2);
2795 case IQ2000_BUILTIN_MTC3
:
2796 code
[1] = CONST_INT
;
2797 return expand_one_builtin (CODE_FOR_mtc3
, target
, exp
, code
, 2);
2799 case IQ2000_BUILTIN_LUR
:
2800 return expand_one_builtin (CODE_FOR_lur
, target
, exp
, code
, 2);
2802 case IQ2000_BUILTIN_RB
:
2803 return expand_one_builtin (CODE_FOR_rb
, target
, exp
, code
, 2);
2805 case IQ2000_BUILTIN_RX
:
2806 return expand_one_builtin (CODE_FOR_rx
, target
, exp
, code
, 2);
2808 case IQ2000_BUILTIN_SRRD
:
2809 return expand_one_builtin (CODE_FOR_srrd
, target
, exp
, code
, 1);
2811 case IQ2000_BUILTIN_SRWR
:
2812 return expand_one_builtin (CODE_FOR_srwr
, target
, exp
, code
, 2);
2814 case IQ2000_BUILTIN_WB
:
2815 return expand_one_builtin (CODE_FOR_wb
, target
, exp
, code
, 2);
2817 case IQ2000_BUILTIN_WX
:
2818 return expand_one_builtin (CODE_FOR_wx
, target
, exp
, code
, 2);
2820 case IQ2000_BUILTIN_LUC32L
:
2821 return expand_one_builtin (CODE_FOR_luc32l
, target
, exp
, code
, 2);
2823 case IQ2000_BUILTIN_LUC64
:
2824 return expand_one_builtin (CODE_FOR_luc64
, target
, exp
, code
, 2);
2826 case IQ2000_BUILTIN_LUC64L
:
2827 return expand_one_builtin (CODE_FOR_luc64l
, target
, exp
, code
, 2);
2829 case IQ2000_BUILTIN_LUK
:
2830 return expand_one_builtin (CODE_FOR_luk
, target
, exp
, code
, 2);
2832 case IQ2000_BUILTIN_LULCK
:
2833 return expand_one_builtin (CODE_FOR_lulck
, target
, exp
, code
, 1);
2835 case IQ2000_BUILTIN_LUM32
:
2836 return expand_one_builtin (CODE_FOR_lum32
, target
, exp
, code
, 2);
2838 case IQ2000_BUILTIN_LUM32L
:
2839 return expand_one_builtin (CODE_FOR_lum32l
, target
, exp
, code
, 2);
2841 case IQ2000_BUILTIN_LUM64
:
2842 return expand_one_builtin (CODE_FOR_lum64
, target
, exp
, code
, 2);
2844 case IQ2000_BUILTIN_LUM64L
:
2845 return expand_one_builtin (CODE_FOR_lum64l
, target
, exp
, code
, 2);
2847 case IQ2000_BUILTIN_LURL
:
2848 return expand_one_builtin (CODE_FOR_lurl
, target
, exp
, code
, 2);
2850 case IQ2000_BUILTIN_MRGB
:
2851 code
[2] = CONST_INT
;
2852 return expand_one_builtin (CODE_FOR_mrgb
, target
, exp
, code
, 3);
2854 case IQ2000_BUILTIN_SRRDL
:
2855 return expand_one_builtin (CODE_FOR_srrdl
, target
, exp
, code
, 1);
2857 case IQ2000_BUILTIN_SRULCK
:
2858 return expand_one_builtin (CODE_FOR_srulck
, target
, exp
, code
, 1);
2860 case IQ2000_BUILTIN_SRWRU
:
2861 return expand_one_builtin (CODE_FOR_srwru
, target
, exp
, code
, 2);
2863 case IQ2000_BUILTIN_TRAPQFL
:
2864 return expand_one_builtin (CODE_FOR_trapqfl
, target
, exp
, code
, 0);
2866 case IQ2000_BUILTIN_TRAPQNE
:
2867 return expand_one_builtin (CODE_FOR_trapqne
, target
, exp
, code
, 0);
2869 case IQ2000_BUILTIN_TRAPREL
:
2870 return expand_one_builtin (CODE_FOR_traprel
, target
, exp
, code
, 1);
2872 case IQ2000_BUILTIN_WBU
:
2873 return expand_one_builtin (CODE_FOR_wbu
, target
, exp
, code
, 3);
2875 case IQ2000_BUILTIN_SYSCALL
:
2876 return expand_one_builtin (CODE_FOR_syscall
, target
, exp
, code
, 0);
2882 /* Worker function for TARGET_RETURN_IN_MEMORY. */
2885 iq2000_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
2887 return ((int_size_in_bytes (type
) > (2 * UNITS_PER_WORD
))
2888 || (int_size_in_bytes (type
) == -1));
2891 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2894 iq2000_setup_incoming_varargs (cumulative_args_t cum_v
,
2895 const function_arg_info
&,
2896 int *pretend_size
, int no_rtl
)
2898 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
2899 unsigned int iq2000_off
= ! cum
->last_arg_fp
;
2900 unsigned int iq2000_fp_off
= cum
->last_arg_fp
;
2902 if ((cum
->arg_words
< MAX_ARGS_IN_REGISTERS
- iq2000_off
))
2904 int iq2000_save_gp_regs
2905 = MAX_ARGS_IN_REGISTERS
- cum
->arg_words
- iq2000_off
;
2906 int iq2000_save_fp_regs
2907 = (MAX_ARGS_IN_REGISTERS
- cum
->fp_arg_words
- iq2000_fp_off
);
2909 if (iq2000_save_gp_regs
< 0)
2910 iq2000_save_gp_regs
= 0;
2911 if (iq2000_save_fp_regs
< 0)
2912 iq2000_save_fp_regs
= 0;
2914 *pretend_size
= ((iq2000_save_gp_regs
* UNITS_PER_WORD
)
2915 + (iq2000_save_fp_regs
* UNITS_PER_FPREG
));
2919 if (cum
->arg_words
< MAX_ARGS_IN_REGISTERS
- iq2000_off
)
2922 ptr
= plus_constant (Pmode
, virtual_incoming_args_rtx
,
2923 - (iq2000_save_gp_regs
2925 mem
= gen_rtx_MEM (BLKmode
, ptr
);
2927 (cum
->arg_words
+ GP_ARG_FIRST
+ iq2000_off
,
2929 iq2000_save_gp_regs
);
2935 /* A C compound statement to output to stdio stream STREAM the
2936 assembler syntax for an instruction operand that is a memory
2937 reference whose address is ADDR. ADDR is an RTL expression. */
2940 iq2000_print_operand_address (FILE * file
, machine_mode mode
, rtx addr
)
2943 error ("PRINT_OPERAND_ADDRESS, null pointer");
2946 switch (GET_CODE (addr
))
2949 if (REGNO (addr
) == ARG_POINTER_REGNUM
)
2950 abort_with_insn (addr
, "Arg pointer not eliminated.");
2952 fprintf (file
, "0(%s)", reg_names
[REGNO (addr
)]);
2957 rtx arg0
= XEXP (addr
, 0);
2958 rtx arg1
= XEXP (addr
, 1);
2960 if (GET_CODE (arg0
) != REG
)
2961 abort_with_insn (addr
,
2962 "PRINT_OPERAND_ADDRESS, LO_SUM with #1 not REG.");
2964 fprintf (file
, "%%lo(");
2965 iq2000_print_operand_address (file
, mode
, arg1
);
2966 fprintf (file
, ")(%s)", reg_names
[REGNO (arg0
)]);
2974 rtx arg0
= XEXP (addr
, 0);
2975 rtx arg1
= XEXP (addr
, 1);
2977 if (GET_CODE (arg0
) == REG
)
2981 if (GET_CODE (offset
) == REG
)
2982 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, 2 regs");
2985 else if (GET_CODE (arg1
) == REG
)
2986 reg
= arg1
, offset
= arg0
;
2987 else if (CONSTANT_P (arg0
) && CONSTANT_P (arg1
))
2989 output_addr_const (file
, addr
);
2993 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, no regs");
2995 if (! CONSTANT_P (offset
))
2996 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, invalid insn #2");
2998 if (REGNO (reg
) == ARG_POINTER_REGNUM
)
2999 abort_with_insn (addr
, "Arg pointer not eliminated.");
3001 output_addr_const (file
, offset
);
3002 fprintf (file
, "(%s)", reg_names
[REGNO (reg
)]);
3010 output_addr_const (file
, addr
);
3011 if (GET_CODE (addr
) == CONST_INT
)
3012 fprintf (file
, "(%s)", reg_names
[0]);
3016 abort_with_insn (addr
, "PRINT_OPERAND_ADDRESS, invalid insn #1");
3021 /* A C compound statement to output to stdio stream FILE the
3022 assembler syntax for an instruction operand OP.
3024 LETTER is a value that can be used to specify one of several ways
3025 of printing the operand. It is used when identical operands
3026 must be printed differently depending on the context. LETTER
3027 comes from the `%' specification that was used to request
3028 printing of the operand. If the specification was just `%DIGIT'
3029 then LETTER is 0; if the specification was `%LTR DIGIT' then LETTER
3030 is the ASCII code for LTR.
3032 If OP is a register, this macro should print the register's name.
3033 The names can be found in an array `reg_names' whose type is
3034 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
3036 When the machine description has a specification `%PUNCT' (a `%'
3037 followed by a punctuation character), this macro is called with
3038 a null pointer for X and the punctuation character for LETTER.
3040 The IQ2000 specific codes are:
3042 'X' X is CONST_INT, prints upper 16 bits in hexadecimal format = "0x%04x",
3043 'x' X is CONST_INT, prints lower 16 bits in hexadecimal format = "0x%04x",
3044 'd' output integer constant in decimal,
3045 'z' if the operand is 0, use $0 instead of normal operand.
3046 'D' print second part of double-word register or memory operand.
3047 'L' print low-order register of double-word register operand.
3048 'M' print high-order register of double-word register operand.
3049 'C' print part of opcode for a branch condition.
3050 'F' print part of opcode for a floating-point branch condition.
3051 'N' print part of opcode for a branch condition, inverted.
3052 'W' print part of opcode for a floating-point branch condition, inverted.
3053 'A' Print part of opcode for a bit test condition.
3054 'P' Print label for a bit test.
3055 'p' Print log for a bit test.
3056 'B' print 'z' for EQ, 'n' for NE
3057 'b' print 'n' for EQ, 'z' for NE
3058 'T' print 'f' for EQ, 't' for NE
3059 't' print 't' for EQ, 'f' for NE
3060 'Z' print register and a comma, but print nothing for $fcc0
3061 '?' Print 'l' if we are to use a branch likely instead of normal branch.
3062 '@' Print the name of the assembler temporary register (at or $1).
3063 '.' Print the name of the register with a hard-wired zero (zero or $0).
3064 '$' Print the name of the stack pointer register (sp or $29).
3065 '+' Print the name of the gp register (gp or $28). */
3068 iq2000_print_operand (FILE *file
, rtx op
, int letter
)
3072 if (iq2000_print_operand_punct_valid_p (letter
))
3077 if (iq2000_branch_likely
)
3082 fputs (reg_names
[GP_REG_FIRST
+ 1], file
);
3086 fputs (reg_names
[GP_REG_FIRST
+ 0], file
);
3090 fputs (reg_names
[STACK_POINTER_REGNUM
], file
);
3094 fputs (reg_names
[GP_REG_FIRST
+ 28], file
);
3098 error ("PRINT_OPERAND: Unknown punctuation %<%c%>", letter
);
3107 error ("PRINT_OPERAND null pointer");
3111 code
= GET_CODE (op
);
3113 if (code
== SIGN_EXTEND
)
3114 op
= XEXP (op
, 0), code
= GET_CODE (op
);
3119 case EQ
: fputs ("eq", file
); break;
3120 case NE
: fputs ("ne", file
); break;
3121 case GT
: fputs ("gt", file
); break;
3122 case GE
: fputs ("ge", file
); break;
3123 case LT
: fputs ("lt", file
); break;
3124 case LE
: fputs ("le", file
); break;
3125 case GTU
: fputs ("ne", file
); break;
3126 case GEU
: fputs ("geu", file
); break;
3127 case LTU
: fputs ("ltu", file
); break;
3128 case LEU
: fputs ("eq", file
); break;
3130 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%C");
3133 else if (letter
== 'N')
3136 case EQ
: fputs ("ne", file
); break;
3137 case NE
: fputs ("eq", file
); break;
3138 case GT
: fputs ("le", file
); break;
3139 case GE
: fputs ("lt", file
); break;
3140 case LT
: fputs ("ge", file
); break;
3141 case LE
: fputs ("gt", file
); break;
3142 case GTU
: fputs ("leu", file
); break;
3143 case GEU
: fputs ("ltu", file
); break;
3144 case LTU
: fputs ("geu", file
); break;
3145 case LEU
: fputs ("gtu", file
); break;
3147 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%N");
3150 else if (letter
== 'F')
3153 case EQ
: fputs ("c1f", file
); break;
3154 case NE
: fputs ("c1t", file
); break;
3156 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%F");
3159 else if (letter
== 'W')
3162 case EQ
: fputs ("c1t", file
); break;
3163 case NE
: fputs ("c1f", file
); break;
3165 abort_with_insn (op
, "PRINT_OPERAND, invalid insn for %%W");
3168 else if (letter
== 'A')
3169 fputs (code
== LABEL_REF
? "i" : "in", file
);
3171 else if (letter
== 'P')
3173 if (code
== LABEL_REF
)
3174 output_addr_const (file
, op
);
3175 else if (code
!= PC
)
3176 output_operand_lossage ("invalid %%P operand");
3179 else if (letter
== 'p')
3182 if (code
!= CONST_INT
3183 || (value
= exact_log2 (INTVAL (op
))) < 0)
3184 output_operand_lossage ("invalid %%p value");
3186 fprintf (file
, "%d", value
);
3189 else if (letter
== 'Z')
3194 else if (code
== REG
|| code
== SUBREG
)
3199 regnum
= REGNO (op
);
3201 regnum
= true_regnum (op
);
3203 if ((letter
== 'M' && ! WORDS_BIG_ENDIAN
)
3204 || (letter
== 'L' && WORDS_BIG_ENDIAN
)
3208 fprintf (file
, "%s", reg_names
[regnum
]);
3211 else if (code
== MEM
)
3213 machine_mode mode
= GET_MODE (op
);
3216 output_address (mode
, plus_constant (Pmode
, XEXP (op
, 0), 4));
3218 output_address (mode
, XEXP (op
, 0));
3221 else if (code
== CONST_DOUBLE
3222 && GET_MODE_CLASS (GET_MODE (op
)) == MODE_FLOAT
)
3226 real_to_decimal (s
, CONST_DOUBLE_REAL_VALUE (op
), sizeof (s
), 0, 1);
3230 else if (letter
== 'x' && GET_CODE (op
) == CONST_INT
)
3231 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, 0xffff & INTVAL(op
));
3233 else if (letter
== 'X' && GET_CODE(op
) == CONST_INT
)
3234 fprintf (file
, HOST_WIDE_INT_PRINT_HEX
, 0xffff & (INTVAL (op
) >> 16));
3236 else if (letter
== 'd' && GET_CODE(op
) == CONST_INT
)
3237 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, (INTVAL(op
)));
3239 else if (letter
== 'z' && GET_CODE (op
) == CONST_INT
&& INTVAL (op
) == 0)
3240 fputs (reg_names
[GP_REG_FIRST
], file
);
3242 else if (letter
== 'd' || letter
== 'x' || letter
== 'X')
3243 output_operand_lossage ("invalid use of %%d, %%x, or %%X");
3245 else if (letter
== 'B')
3246 fputs (code
== EQ
? "z" : "n", file
);
3247 else if (letter
== 'b')
3248 fputs (code
== EQ
? "n" : "z", file
);
3249 else if (letter
== 'T')
3250 fputs (code
== EQ
? "f" : "t", file
);
3251 else if (letter
== 't')
3252 fputs (code
== EQ
? "t" : "f", file
);
3254 else if (code
== CONST
&& GET_CODE (XEXP (op
, 0)) == REG
)
3256 iq2000_print_operand (file
, XEXP (op
, 0), letter
);
3260 output_addr_const (file
, op
);
3264 iq2000_print_operand_punct_valid_p (unsigned char code
)
3266 return iq2000_print_operand_punct
[code
];
3269 /* For the IQ2000, transform:
3271 memory(X + <large int>)
3273 Y = <large int> & ~0x7fff;
3275 memory (Z + (<large int> & 0x7fff));
3279 iq2000_legitimize_address (rtx xinsn
, rtx old_x ATTRIBUTE_UNUSED
,
3282 if (TARGET_DEBUG_B_MODE
)
3284 GO_PRINTF ("\n========== LEGITIMIZE_ADDRESS\n");
3285 GO_DEBUG_RTX (xinsn
);
3288 if (iq2000_check_split (xinsn
, mode
))
3290 return gen_rtx_LO_SUM (Pmode
,
3291 copy_to_mode_reg (Pmode
,
3292 gen_rtx_HIGH (Pmode
, xinsn
)),
3296 if (GET_CODE (xinsn
) == PLUS
)
3298 rtx xplus0
= XEXP (xinsn
, 0);
3299 rtx xplus1
= XEXP (xinsn
, 1);
3300 enum rtx_code code0
= GET_CODE (xplus0
);
3301 enum rtx_code code1
= GET_CODE (xplus1
);
3303 if (code0
!= REG
&& code1
== REG
)
3305 xplus0
= XEXP (xinsn
, 1);
3306 xplus1
= XEXP (xinsn
, 0);
3307 code0
= GET_CODE (xplus0
);
3308 code1
= GET_CODE (xplus1
);
3311 if (code0
== REG
&& REG_MODE_OK_FOR_BASE_P (xplus0
, mode
)
3312 && code1
== CONST_INT
&& !SMALL_INT (xplus1
))
3314 rtx int_reg
= gen_reg_rtx (Pmode
);
3315 rtx ptr_reg
= gen_reg_rtx (Pmode
);
3317 emit_move_insn (int_reg
,
3318 GEN_INT (INTVAL (xplus1
) & ~ 0x7fff));
3320 emit_insn (gen_rtx_SET (ptr_reg
,
3321 gen_rtx_PLUS (Pmode
, xplus0
, int_reg
)));
3323 return plus_constant (Pmode
, ptr_reg
, INTVAL (xplus1
) & 0x7fff);
3327 if (TARGET_DEBUG_B_MODE
)
3328 GO_PRINTF ("LEGITIMIZE_ADDRESS could not fix.\n");
3335 iq2000_rtx_costs (rtx x
, machine_mode mode
, int outer_code ATTRIBUTE_UNUSED
,
3336 int opno ATTRIBUTE_UNUSED
, int * total
,
3337 bool speed ATTRIBUTE_UNUSED
)
3339 int code
= GET_CODE (x
);
3345 int num_words
= (GET_MODE_SIZE (mode
) > UNITS_PER_WORD
) ? 2 : 1;
3347 if (simple_memory_operand (x
, mode
))
3348 return COSTS_N_INSNS (num_words
) != 0;
3350 * total
= COSTS_N_INSNS (2 * num_words
);
3355 * total
= COSTS_N_INSNS (6);
3362 * total
= COSTS_N_INSNS (mode
== DImode
? 2 : 1);
3369 * total
= COSTS_N_INSNS ((GET_CODE (XEXP (x
, 1)) == CONST_INT
) ? 4 : 12);
3371 * total
= COSTS_N_INSNS (1);
3375 if (mode
== SFmode
|| mode
== DFmode
)
3376 * total
= COSTS_N_INSNS (1);
3378 * total
= COSTS_N_INSNS (4);
3383 if (mode
== SFmode
|| mode
== DFmode
)
3384 * total
= COSTS_N_INSNS (6);
3385 else if (mode
== DImode
)
3386 * total
= COSTS_N_INSNS (4);
3388 * total
= COSTS_N_INSNS (1);
3392 * total
= (mode
== DImode
) ? 4 : 1;
3397 * total
= COSTS_N_INSNS (7);
3398 else if (mode
== DFmode
)
3399 * total
= COSTS_N_INSNS (8);
3401 * total
= COSTS_N_INSNS (10);
3407 * total
= COSTS_N_INSNS (23);
3408 else if (mode
== DFmode
)
3409 * total
= COSTS_N_INSNS (36);
3411 * total
= COSTS_N_INSNS (69);
3416 * total
= COSTS_N_INSNS (69);
3420 * total
= COSTS_N_INSNS (2);
3424 * total
= COSTS_N_INSNS (1);
3432 * total
= COSTS_N_INSNS (2);
3437 rtx offset
= const0_rtx
;
3438 rtx symref
= eliminate_constant_term (XEXP (x
, 0), & offset
);
3440 if (GET_CODE (symref
) == LABEL_REF
)
3441 * total
= COSTS_N_INSNS (2);
3442 else if (GET_CODE (symref
) != SYMBOL_REF
)
3443 * total
= COSTS_N_INSNS (4);
3444 /* Let's be paranoid.... */
3445 else if (INTVAL (offset
) < -32768 || INTVAL (offset
) > 32767)
3446 * total
= COSTS_N_INSNS (2);
3448 * total
= COSTS_N_INSNS (SYMBOL_REF_FLAG (symref
) ? 1 : 2);
3453 * total
= COSTS_N_INSNS (SYMBOL_REF_FLAG (x
) ? 1 : 2);
3460 split_double (x
, & high
, & low
);
3462 * total
= COSTS_N_INSNS ( (high
== CONST0_RTX (GET_MODE (high
))
3463 || low
== CONST0_RTX (GET_MODE (low
)))
3474 /* Worker for TARGET_ASM_TRAMPOLINE_TEMPLATE. */
3477 iq2000_asm_trampoline_template (FILE *f
)
3479 fprintf (f
, "\t.word\t0x03e00821\t\t# move $1,$31\n");
3480 fprintf (f
, "\t.word\t0x04110001\t\t# bgezal $0,.+8\n");
3481 fprintf (f
, "\t.word\t0x00000000\t\t# nop\n");
3482 if (Pmode
== DImode
)
3484 fprintf (f
, "\t.word\t0xdfe30014\t\t# ld $3,20($31)\n");
3485 fprintf (f
, "\t.word\t0xdfe2001c\t\t# ld $2,28($31)\n");
3489 fprintf (f
, "\t.word\t0x8fe30014\t\t# lw $3,20($31)\n");
3490 fprintf (f
, "\t.word\t0x8fe20018\t\t# lw $2,24($31)\n");
3492 fprintf (f
, "\t.word\t0x0060c821\t\t# move $25,$3 (abicalls)\n");
3493 fprintf (f
, "\t.word\t0x00600008\t\t# jr $3\n");
3494 fprintf (f
, "\t.word\t0x0020f821\t\t# move $31,$1\n");
3495 fprintf (f
, "\t.word\t0x00000000\t\t# <function address>\n");
3496 fprintf (f
, "\t.word\t0x00000000\t\t# <static chain value>\n");
3499 /* Worker for TARGET_TRAMPOLINE_INIT. */
3502 iq2000_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
3504 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
3507 emit_block_move (m_tramp
, assemble_trampoline_template (),
3508 GEN_INT (TRAMPOLINE_CODE_SIZE
), BLOCK_OP_NORMAL
);
3510 mem
= adjust_address (m_tramp
, Pmode
, TRAMPOLINE_CODE_SIZE
);
3511 emit_move_insn (mem
, fnaddr
);
3512 mem
= adjust_address (m_tramp
, Pmode
,
3513 TRAMPOLINE_CODE_SIZE
+ GET_MODE_SIZE (Pmode
));
3514 emit_move_insn (mem
, chain_value
);
3517 /* Implement TARGET_HARD_REGNO_MODE_OK. */
3520 iq2000_hard_regno_mode_ok (unsigned int regno
, machine_mode mode
)
3522 return (REGNO_REG_CLASS (regno
) == GR_REGS
3523 ? (regno
& 1) == 0 || GET_MODE_SIZE (mode
) <= 4
3524 : (regno
& 1) == 0 || GET_MODE_SIZE (mode
) == 4);
3527 /* Implement TARGET_MODES_TIEABLE_P. */
3530 iq2000_modes_tieable_p (machine_mode mode1
, machine_mode mode2
)
3532 return ((GET_MODE_CLASS (mode1
) == MODE_FLOAT
3533 || GET_MODE_CLASS (mode1
) == MODE_COMPLEX_FLOAT
)
3534 == (GET_MODE_CLASS (mode2
) == MODE_FLOAT
3535 || GET_MODE_CLASS (mode2
) == MODE_COMPLEX_FLOAT
));
3538 /* Implement TARGET_CONSTANT_ALIGNMENT. */
3540 static HOST_WIDE_INT
3541 iq2000_constant_alignment (const_tree exp
, HOST_WIDE_INT align
)
3543 if (TREE_CODE (exp
) == STRING_CST
|| TREE_CODE (exp
) == CONSTRUCTOR
)
3544 return MAX (align
, BITS_PER_WORD
);
3548 /* Implement TARGET_STARTING_FRAME_OFFSET. */
3550 static HOST_WIDE_INT
3551 iq2000_starting_frame_offset (void)
3553 return crtl
->outgoing_args_size
;
3556 #include "gt-iq2000.h"