1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
2 Free Software Foundation, Inc.
3 Contributed by Red Hat, Inc.
5 This file is part of GCC.
7 GCC 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 GCC 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 GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
35 #include "insn-attr.h"
45 #include "basic-block.h"
50 #include "target-def.h"
51 #include "targhooks.h"
52 #include "integrate.h"
53 #include "langhooks.h"
56 #define FRV_INLINE inline
59 /* The maximum number of distinct NOP patterns. There are three:
60 nop, fnop and mnop. */
61 #define NUM_NOP_PATTERNS 3
63 /* Classification of instructions and units: integer, floating-point/media,
64 branch and control. */
65 enum frv_insn_group { GROUP_I, GROUP_FM, GROUP_B, GROUP_C, NUM_GROUPS };
67 /* The DFA names of the units, in packet order. */
68 static const char *const frv_unit_names[] =
78 /* The classification of each unit in frv_unit_names[]. */
79 static const enum frv_insn_group frv_unit_groups[ARRAY_SIZE (frv_unit_names)] =
89 /* Return the DFA unit code associated with the Nth unit of integer
90 or floating-point group GROUP, */
91 #define NTH_UNIT(GROUP, N) frv_unit_codes[(GROUP) + (N) * 2 + 1]
93 /* Return the number of integer or floating-point unit UNIT
94 (1 for I1, 2 for F2, etc.). */
95 #define UNIT_NUMBER(UNIT) (((UNIT) - 1) / 2)
97 /* The DFA unit number for each unit in frv_unit_names[]. */
98 static int frv_unit_codes[ARRAY_SIZE (frv_unit_names)];
100 /* FRV_TYPE_TO_UNIT[T] is the last unit in frv_unit_names[] that can issue
101 an instruction of type T. The value is ARRAY_SIZE (frv_unit_names) if
102 no instruction of type T has been seen. */
103 static unsigned int frv_type_to_unit[TYPE_UNKNOWN + 1];
105 /* An array of dummy nop INSNs, one for each type of nop that the
107 static GTY(()) rtx frv_nops[NUM_NOP_PATTERNS];
109 /* The number of nop instructions in frv_nops[]. */
110 static unsigned int frv_num_nops;
112 /* Return true if instruction INSN should be packed with the following
114 #define PACKING_FLAG_P(INSN) (GET_MODE (INSN) == TImode)
116 /* Set the value of PACKING_FLAG_P(INSN). */
117 #define SET_PACKING_FLAG(INSN) PUT_MODE (INSN, TImode)
118 #define CLEAR_PACKING_FLAG(INSN) PUT_MODE (INSN, VOIDmode)
120 /* Loop with REG set to each hard register in rtx X. */
121 #define FOR_EACH_REGNO(REG, X) \
122 for (REG = REGNO (X); \
123 REG < REGNO (X) + HARD_REGNO_NREGS (REGNO (X), GET_MODE (X)); \
126 /* Temporary register allocation support structure. */
127 typedef struct frv_tmp_reg_struct
129 HARD_REG_SET regs; /* possible registers to allocate */
130 int next_reg[N_REG_CLASSES]; /* next register to allocate per class */
134 /* Register state information for VLIW re-packing phase. */
135 #define REGSTATE_CC_MASK 0x07 /* Mask to isolate CCn for cond exec */
136 #define REGSTATE_MODIFIED 0x08 /* reg modified in current VLIW insn */
137 #define REGSTATE_IF_TRUE 0x10 /* reg modified in cond exec true */
138 #define REGSTATE_IF_FALSE 0x20 /* reg modified in cond exec false */
140 #define REGSTATE_IF_EITHER (REGSTATE_IF_TRUE | REGSTATE_IF_FALSE)
142 typedef unsigned char regstate_t;
144 /* Used in frv_frame_accessor_t to indicate the direction of a register-to-
152 /* Information required by frv_frame_access. */
155 /* This field is FRV_LOAD if registers are to be loaded from the stack and
156 FRV_STORE if they should be stored onto the stack. FRV_STORE implies
157 the move is being done by the prologue code while FRV_LOAD implies it
158 is being done by the epilogue. */
159 enum frv_stack_op op;
161 /* The base register to use when accessing the stack. This may be the
162 frame pointer, stack pointer, or a temporary. The choice of register
163 depends on which part of the frame is being accessed and how big the
167 /* The offset of BASE from the bottom of the current frame, in bytes. */
169 } frv_frame_accessor_t;
171 /* Define the information needed to generate branch and scc insns. This is
172 stored from the compare operation. */
176 /* Conditional execution support gathered together in one structure. */
179 /* Linked list of insns to add if the conditional execution conversion was
180 successful. Each link points to an EXPR_LIST which points to the pattern
181 of the insn to add, and the insn to be inserted before. */
182 rtx added_insns_list;
184 /* Identify which registers are safe to allocate for if conversions to
185 conditional execution. We keep the last allocated register in the
186 register classes between COND_EXEC statements. This will mean we allocate
187 different registers for each different COND_EXEC group if we can. This
188 might allow the scheduler to intermix two different COND_EXEC sections. */
189 frv_tmp_reg_t tmp_reg;
191 /* For nested IFs, identify which CC registers are used outside of setting
192 via a compare isnsn, and using via a check insn. This will allow us to
193 know if we can rewrite the register to use a different register that will
194 be paired with the CR register controlling the nested IF-THEN blocks. */
195 HARD_REG_SET nested_cc_ok_rewrite;
197 /* Temporary registers allocated to hold constants during conditional
199 rtx scratch_regs[FIRST_PSEUDO_REGISTER];
201 /* Current number of temp registers available. */
202 int cur_scratch_regs;
204 /* Number of nested conditional execution blocks. */
205 int num_nested_cond_exec;
207 /* Map of insns that set up constants in scratch registers. */
208 bitmap scratch_insns_bitmap;
210 /* Conditional execution test register (CC0..CC7). */
213 /* Conditional execution compare register that is paired with cr_reg, so that
214 nested compares can be done. The csubcc and caddcc instructions don't
215 have enough bits to specify both a CC register to be set and a CR register
216 to do the test on, so the same bit number is used for both. Needless to
217 say, this is rather inconvenient for GCC. */
220 /* Extra CR registers used for &&, ||. */
224 /* Previous CR used in nested if, to make sure we are dealing with the same
225 nested if as the previous statement. */
226 rtx last_nested_if_cr;
230 static /* GTY(()) */ frv_ifcvt_t frv_ifcvt;
232 /* Map register number to smallest register class. */
233 enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER];
235 /* Map class letter into register class. */
236 enum reg_class reg_class_from_letter[256];
238 /* Cached value of frv_stack_info. */
239 static frv_stack_t *frv_stack_cache = (frv_stack_t *)0;
242 frv_cpu_t frv_cpu_type = CPU_TYPE; /* value of -mcpu= */
244 /* Forward references */
246 static bool frv_handle_option (size_t, const char *, int);
247 static int frv_default_flags_for_cpu (void);
248 static int frv_string_begins_with (tree, const char *);
249 static FRV_INLINE bool frv_small_data_reloc_p (rtx, int);
250 static void frv_print_operand_memory_reference_reg
252 static void frv_print_operand_memory_reference (FILE *, rtx, int);
253 static int frv_print_operand_jump_hint (rtx);
254 static const char *comparison_string (enum rtx_code, rtx);
255 static FRV_INLINE int frv_regno_ok_for_base_p (int, int);
256 static rtx single_set_pattern (rtx);
257 static int frv_function_contains_far_jump (void);
258 static rtx frv_alloc_temp_reg (frv_tmp_reg_t *,
262 static rtx frv_frame_offset_rtx (int);
263 static rtx frv_frame_mem (enum machine_mode, rtx, int);
264 static rtx frv_dwarf_store (rtx, int);
265 static void frv_frame_insn (rtx, rtx);
266 static void frv_frame_access (frv_frame_accessor_t*,
268 static void frv_frame_access_multi (frv_frame_accessor_t*,
270 static void frv_frame_access_standard_regs (enum frv_stack_op,
272 static struct machine_function *frv_init_machine_status (void);
273 static rtx frv_int_to_acc (enum insn_code, int, rtx);
274 static enum machine_mode frv_matching_accg_mode (enum machine_mode);
275 static rtx frv_read_argument (tree *);
276 static rtx frv_read_iacc_argument (enum machine_mode, tree *);
277 static int frv_check_constant_argument (enum insn_code, int, rtx);
278 static rtx frv_legitimize_target (enum insn_code, rtx);
279 static rtx frv_legitimize_argument (enum insn_code, int, rtx);
280 static rtx frv_legitimize_tls_address (rtx, enum tls_model);
281 static rtx frv_expand_set_builtin (enum insn_code, tree, rtx);
282 static rtx frv_expand_unop_builtin (enum insn_code, tree, rtx);
283 static rtx frv_expand_binop_builtin (enum insn_code, tree, rtx);
284 static rtx frv_expand_cut_builtin (enum insn_code, tree, rtx);
285 static rtx frv_expand_binopimm_builtin (enum insn_code, tree, rtx);
286 static rtx frv_expand_voidbinop_builtin (enum insn_code, tree);
287 static rtx frv_expand_int_void2arg (enum insn_code, tree);
288 static rtx frv_expand_prefetches (enum insn_code, tree);
289 static rtx frv_expand_voidtriop_builtin (enum insn_code, tree);
290 static rtx frv_expand_voidaccop_builtin (enum insn_code, tree);
291 static rtx frv_expand_mclracc_builtin (tree);
292 static rtx frv_expand_mrdacc_builtin (enum insn_code, tree);
293 static rtx frv_expand_mwtacc_builtin (enum insn_code, tree);
294 static rtx frv_expand_noargs_builtin (enum insn_code);
295 static void frv_split_iacc_move (rtx, rtx);
296 static rtx frv_emit_comparison (enum rtx_code, rtx, rtx);
297 static int frv_clear_registers_used (rtx *, void *);
298 static void frv_ifcvt_add_insn (rtx, rtx, int);
299 static rtx frv_ifcvt_rewrite_mem (rtx, enum machine_mode, rtx);
300 static rtx frv_ifcvt_load_value (rtx, rtx);
301 static int frv_acc_group_1 (rtx *, void *);
302 static unsigned int frv_insn_unit (rtx);
303 static bool frv_issues_to_branch_unit_p (rtx);
304 static int frv_cond_flags (rtx);
305 static bool frv_regstate_conflict_p (regstate_t, regstate_t);
306 static int frv_registers_conflict_p_1 (rtx *, void *);
307 static bool frv_registers_conflict_p (rtx);
308 static void frv_registers_update_1 (rtx, rtx, void *);
309 static void frv_registers_update (rtx);
310 static void frv_start_packet (void);
311 static void frv_start_packet_block (void);
312 static void frv_finish_packet (void (*) (void));
313 static bool frv_pack_insn_p (rtx);
314 static void frv_add_insn_to_packet (rtx);
315 static void frv_insert_nop_in_packet (rtx);
316 static bool frv_for_each_packet (void (*) (void));
317 static bool frv_sort_insn_group_1 (enum frv_insn_group,
318 unsigned int, unsigned int,
319 unsigned int, unsigned int,
321 static int frv_compare_insns (const void *, const void *);
322 static void frv_sort_insn_group (enum frv_insn_group);
323 static void frv_reorder_packet (void);
324 static void frv_fill_unused_units (enum frv_insn_group);
325 static void frv_align_label (void);
326 static void frv_reorg_packet (void);
327 static void frv_register_nop (rtx);
328 static void frv_reorg (void);
329 static void frv_pack_insns (void);
330 static void frv_function_prologue (FILE *, HOST_WIDE_INT);
331 static void frv_function_epilogue (FILE *, HOST_WIDE_INT);
332 static bool frv_assemble_integer (rtx, unsigned, int);
333 static void frv_init_builtins (void);
334 static rtx frv_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
335 static void frv_init_libfuncs (void);
336 static bool frv_in_small_data_p (tree);
337 static void frv_asm_output_mi_thunk
338 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
339 static void frv_setup_incoming_varargs (CUMULATIVE_ARGS *,
342 static rtx frv_expand_builtin_saveregs (void);
343 static bool frv_rtx_costs (rtx, int, int, int*);
344 static void frv_asm_out_constructor (rtx, int);
345 static void frv_asm_out_destructor (rtx, int);
346 static bool frv_function_symbol_referenced_p (rtx);
347 static bool frv_cannot_force_const_mem (rtx);
348 static const char *unspec_got_name (int);
349 static void frv_output_const_unspec (FILE *,
350 const struct frv_unspec *);
351 static bool frv_function_ok_for_sibcall (tree, tree);
352 static rtx frv_struct_value_rtx (tree, int);
353 static bool frv_must_pass_in_stack (enum machine_mode mode, tree type);
354 static int frv_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
356 static void frv_output_dwarf_dtprel (FILE *, int, rtx)
359 /* Allow us to easily change the default for -malloc-cc. */
360 #ifndef DEFAULT_NO_ALLOC_CC
361 #define MASK_DEFAULT_ALLOC_CC MASK_ALLOC_CC
363 #define MASK_DEFAULT_ALLOC_CC 0
366 /* Initialize the GCC target structure. */
367 #undef TARGET_ASM_FUNCTION_PROLOGUE
368 #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue
369 #undef TARGET_ASM_FUNCTION_EPILOGUE
370 #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue
371 #undef TARGET_ASM_INTEGER
372 #define TARGET_ASM_INTEGER frv_assemble_integer
373 #undef TARGET_DEFAULT_TARGET_FLAGS
374 #define TARGET_DEFAULT_TARGET_FLAGS \
375 (MASK_DEFAULT_ALLOC_CC \
382 #undef TARGET_HANDLE_OPTION
383 #define TARGET_HANDLE_OPTION frv_handle_option
384 #undef TARGET_INIT_BUILTINS
385 #define TARGET_INIT_BUILTINS frv_init_builtins
386 #undef TARGET_EXPAND_BUILTIN
387 #define TARGET_EXPAND_BUILTIN frv_expand_builtin
388 #undef TARGET_INIT_LIBFUNCS
389 #define TARGET_INIT_LIBFUNCS frv_init_libfuncs
390 #undef TARGET_IN_SMALL_DATA_P
391 #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p
392 #undef TARGET_RTX_COSTS
393 #define TARGET_RTX_COSTS frv_rtx_costs
394 #undef TARGET_ASM_CONSTRUCTOR
395 #define TARGET_ASM_CONSTRUCTOR frv_asm_out_constructor
396 #undef TARGET_ASM_DESTRUCTOR
397 #define TARGET_ASM_DESTRUCTOR frv_asm_out_destructor
399 #undef TARGET_ASM_OUTPUT_MI_THUNK
400 #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk
401 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
402 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
404 #undef TARGET_SCHED_ISSUE_RATE
405 #define TARGET_SCHED_ISSUE_RATE frv_issue_rate
407 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
408 #define TARGET_FUNCTION_OK_FOR_SIBCALL frv_function_ok_for_sibcall
409 #undef TARGET_CANNOT_FORCE_CONST_MEM
410 #define TARGET_CANNOT_FORCE_CONST_MEM frv_cannot_force_const_mem
412 #undef TARGET_HAVE_TLS
413 #define TARGET_HAVE_TLS HAVE_AS_TLS
415 #undef TARGET_STRUCT_VALUE_RTX
416 #define TARGET_STRUCT_VALUE_RTX frv_struct_value_rtx
417 #undef TARGET_MUST_PASS_IN_STACK
418 #define TARGET_MUST_PASS_IN_STACK frv_must_pass_in_stack
419 #undef TARGET_PASS_BY_REFERENCE
420 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
421 #undef TARGET_ARG_PARTIAL_BYTES
422 #define TARGET_ARG_PARTIAL_BYTES frv_arg_partial_bytes
424 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
425 #define TARGET_EXPAND_BUILTIN_SAVEREGS frv_expand_builtin_saveregs
426 #undef TARGET_SETUP_INCOMING_VARARGS
427 #define TARGET_SETUP_INCOMING_VARARGS frv_setup_incoming_varargs
428 #undef TARGET_MACHINE_DEPENDENT_REORG
429 #define TARGET_MACHINE_DEPENDENT_REORG frv_reorg
432 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
433 #define TARGET_ASM_OUTPUT_DWARF_DTPREL frv_output_dwarf_dtprel
436 struct gcc_target targetm = TARGET_INITIALIZER;
438 #define FRV_SYMBOL_REF_TLS_P(RTX) \
439 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
442 /* Any function call that satisfies the machine-independent
443 requirements is eligible on FR-V. */
446 frv_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
447 tree exp ATTRIBUTE_UNUSED)
452 /* Return true if SYMBOL is a small data symbol and relocation RELOC
453 can be used to access it directly in a load or store. */
455 static FRV_INLINE bool
456 frv_small_data_reloc_p (rtx symbol, int reloc)
458 return (GET_CODE (symbol) == SYMBOL_REF
459 && SYMBOL_REF_SMALL_P (symbol)
460 && (!TARGET_FDPIC || flag_pic == 1)
461 && (reloc == R_FRV_GOTOFF12 || reloc == R_FRV_GPREL12));
464 /* Return true if X is a valid relocation unspec. If it is, fill in UNSPEC
468 frv_const_unspec_p (rtx x, struct frv_unspec *unspec)
470 if (GET_CODE (x) == CONST)
474 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
476 unspec->offset += INTVAL (XEXP (x, 1));
479 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_GOT)
481 unspec->symbol = XVECEXP (x, 0, 0);
482 unspec->reloc = INTVAL (XVECEXP (x, 0, 1));
484 if (unspec->offset == 0)
487 if (frv_small_data_reloc_p (unspec->symbol, unspec->reloc)
488 && unspec->offset > 0
489 && (unsigned HOST_WIDE_INT) unspec->offset < g_switch_value)
496 /* Decide whether we can force certain constants to memory. If we
497 decide we can't, the caller should be able to cope with it in
500 We never allow constants to be forced into memory for TARGET_FDPIC.
501 This is necessary for several reasons:
503 1. Since LEGITIMATE_CONSTANT_P rejects constant pool addresses, the
504 target-independent code will try to force them into the constant
505 pool, thus leading to infinite recursion.
507 2. We can never introduce new constant pool references during reload.
508 Any such reference would require use of the pseudo FDPIC register.
510 3. We can't represent a constant added to a function pointer (which is
511 not the same as a pointer to a function+constant).
513 4. In many cases, it's more efficient to calculate the constant in-line. */
516 frv_cannot_force_const_mem (rtx x ATTRIBUTE_UNUSED)
521 /* Implement TARGET_HANDLE_OPTION. */
524 frv_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
529 if (strcmp (arg, "simple") == 0)
530 frv_cpu_type = FRV_CPU_SIMPLE;
531 else if (strcmp (arg, "tomcat") == 0)
532 frv_cpu_type = FRV_CPU_TOMCAT;
533 else if (strcmp (arg, "fr550") == 0)
534 frv_cpu_type = FRV_CPU_FR550;
535 else if (strcmp (arg, "fr500") == 0)
536 frv_cpu_type = FRV_CPU_FR500;
537 else if (strcmp (arg, "fr450") == 0)
538 frv_cpu_type = FRV_CPU_FR450;
539 else if (strcmp (arg, "fr405") == 0)
540 frv_cpu_type = FRV_CPU_FR405;
541 else if (strcmp (arg, "fr400") == 0)
542 frv_cpu_type = FRV_CPU_FR400;
543 else if (strcmp (arg, "fr300") == 0)
544 frv_cpu_type = FRV_CPU_FR300;
545 else if (strcmp (arg, "frv") == 0)
546 frv_cpu_type = FRV_CPU_GENERIC;
557 frv_default_flags_for_cpu (void)
559 switch (frv_cpu_type)
561 case FRV_CPU_GENERIC:
562 return MASK_DEFAULT_FRV;
565 return MASK_DEFAULT_FR550;
569 return MASK_DEFAULT_FR500;
572 return MASK_DEFAULT_FR450;
576 return MASK_DEFAULT_FR400;
580 return MASK_DEFAULT_SIMPLE;
587 /* Sometimes certain combinations of command options do not make
588 sense on a particular target machine. You can define a macro
589 `OVERRIDE_OPTIONS' to take account of this. This macro, if
590 defined, is executed once just after all the command options have
593 Don't use this macro to turn on various extra optimizations for
594 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
597 frv_override_options (void)
602 target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit);
604 /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the
605 linker about linking pic and non-pic code. */
608 if (!flag_pic) /* -fPIC */
611 if (! g_switch_set) /* -G0 */
618 /* A C expression whose value is a register class containing hard
619 register REGNO. In general there is more than one such class;
620 choose a class which is "minimal", meaning that no smaller class
621 also contains the register. */
623 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
625 enum reg_class class;
629 int gpr_reg = regno - GPR_FIRST;
631 if (gpr_reg == GR8_REG)
634 else if (gpr_reg == GR9_REG)
637 else if (gpr_reg == GR14_REG)
638 class = FDPIC_FPTR_REGS;
640 else if (gpr_reg == FDPIC_REGNO)
643 else if ((gpr_reg & 3) == 0)
646 else if ((gpr_reg & 1) == 0)
653 else if (FPR_P (regno))
655 int fpr_reg = regno - GPR_FIRST;
656 if ((fpr_reg & 3) == 0)
657 class = QUAD_FPR_REGS;
659 else if ((fpr_reg & 1) == 0)
666 else if (regno == LR_REGNO)
669 else if (regno == LCR_REGNO)
672 else if (ICC_P (regno))
675 else if (FCC_P (regno))
678 else if (ICR_P (regno))
681 else if (FCR_P (regno))
684 else if (ACC_P (regno))
686 int r = regno - ACC_FIRST;
688 class = QUAD_ACC_REGS;
689 else if ((r & 1) == 0)
690 class = EVEN_ACC_REGS;
695 else if (ACCG_P (regno))
701 regno_reg_class[regno] = class;
704 /* Check for small data option */
706 g_switch_value = SDATA_DEFAULT_SIZE;
708 /* A C expression which defines the machine-dependent operand
709 constraint letters for register classes. If CHAR is such a
710 letter, the value should be the register class corresponding to
711 it. Otherwise, the value should be `NO_REGS'. The register
712 letter `r', corresponding to class `GENERAL_REGS', will not be
713 passed to this macro; you do not need to handle it.
715 The following letters are unavailable, due to being used as
720 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
721 'Q', 'R', 'S', 'T', 'U'
723 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
725 for (i = 0; i < 256; i++)
726 reg_class_from_letter[i] = NO_REGS;
728 reg_class_from_letter['a'] = ACC_REGS;
729 reg_class_from_letter['b'] = EVEN_ACC_REGS;
730 reg_class_from_letter['c'] = CC_REGS;
731 reg_class_from_letter['d'] = GPR_REGS;
732 reg_class_from_letter['e'] = EVEN_REGS;
733 reg_class_from_letter['f'] = FPR_REGS;
734 reg_class_from_letter['h'] = FEVEN_REGS;
735 reg_class_from_letter['l'] = LR_REG;
736 reg_class_from_letter['q'] = QUAD_REGS;
737 reg_class_from_letter['t'] = ICC_REGS;
738 reg_class_from_letter['u'] = FCC_REGS;
739 reg_class_from_letter['v'] = ICR_REGS;
740 reg_class_from_letter['w'] = FCR_REGS;
741 reg_class_from_letter['x'] = QUAD_FPR_REGS;
742 reg_class_from_letter['y'] = LCR_REG;
743 reg_class_from_letter['z'] = SPR_REGS;
744 reg_class_from_letter['A'] = QUAD_ACC_REGS;
745 reg_class_from_letter['B'] = ACCG_REGS;
746 reg_class_from_letter['C'] = CR_REGS;
747 reg_class_from_letter['W'] = FDPIC_CALL_REGS; /* gp14+15 */
748 reg_class_from_letter['Z'] = FDPIC_REGS; /* gp15 */
750 /* There is no single unaligned SI op for PIC code. Sometimes we
751 need to use ".4byte" and sometimes we need to use ".picptr".
752 See frv_assemble_integer for details. */
753 if (flag_pic || TARGET_FDPIC)
754 targetm.asm_out.unaligned_op.si = 0;
756 if ((target_flags_explicit & MASK_LINKED_FP) == 0)
757 target_flags |= MASK_LINKED_FP;
759 for (i = 0; i < ARRAY_SIZE (frv_unit_names); i++)
760 frv_unit_codes[i] = get_cpu_unit_code (frv_unit_names[i]);
762 for (i = 0; i < ARRAY_SIZE (frv_type_to_unit); i++)
763 frv_type_to_unit[i] = ARRAY_SIZE (frv_unit_codes);
765 init_machine_status = frv_init_machine_status;
769 /* Some machines may desire to change what optimizations are performed for
770 various optimization levels. This macro, if defined, is executed once just
771 after the optimization level is determined and before the remainder of the
772 command options have been parsed. Values set in this macro are used as the
773 default values for the other command line options.
775 LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if
776 `-O' is specified, and 0 if neither is specified.
778 SIZE is nonzero if `-Os' is specified, 0 otherwise.
780 You should not use this macro to change options that are not
781 machine-specific. These should uniformly selected by the same optimization
782 level on all supported machines. Use this macro to enable machine-specific
785 *Do not examine `write_symbols' in this macro!* The debugging options are
786 *not supposed to alter the generated code. */
788 /* On the FRV, possibly disable VLIW packing which is done by the 2nd
789 scheduling pass at the current time. */
791 frv_optimization_options (int level, int size ATTRIBUTE_UNUSED)
795 #ifdef DISABLE_SCHED2
796 flag_schedule_insns_after_reload = 0;
805 /* Return true if NAME (a STRING_CST node) begins with PREFIX. */
808 frv_string_begins_with (tree name, const char *prefix)
810 int prefix_len = strlen (prefix);
812 /* Remember: NAME's length includes the null terminator. */
813 return (TREE_STRING_LENGTH (name) > prefix_len
814 && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0);
817 /* Zero or more C statements that may conditionally modify two variables
818 `fixed_regs' and `call_used_regs' (both of type `char []') after they have
819 been initialized from the two preceding macros.
821 This is necessary in case the fixed or call-clobbered registers depend on
824 You need not define this macro if it has no work to do.
826 If the usage of an entire class of registers depends on the target flags,
827 you may indicate this to GCC by using this macro to modify `fixed_regs' and
828 `call_used_regs' to 1 for each of the registers in the classes which should
829 not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return
830 `NO_REGS' if it is called with a letter for a class that shouldn't be used.
832 (However, if this class is not included in `GENERAL_REGS' and all of the
833 insn patterns whose constraints permit this class are controlled by target
834 switches, then GCC will automatically avoid using these registers when the
835 target switches are opposed to them.) */
838 frv_conditional_register_usage (void)
842 for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++)
843 fixed_regs[i] = call_used_regs[i] = 1;
845 for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++)
846 fixed_regs[i] = call_used_regs[i] = 1;
848 /* Reserve the registers used for conditional execution. At present, we need
849 1 ICC and 1 ICR register. */
850 fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1;
851 fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1;
855 fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1;
856 fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1;
857 fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1;
858 fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1;
862 fixed_regs[GPR_FIRST + 16] = fixed_regs[GPR_FIRST + 17] =
863 call_used_regs[GPR_FIRST + 16] = call_used_regs[GPR_FIRST + 17] = 0;
866 /* If -fpic, SDA_BASE_REG is the PIC register. */
867 if (g_switch_value == 0 && !flag_pic)
868 fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0;
871 fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0;
877 * Compute the stack frame layout
880 * +---------------+-----------------------+-----------------------+
881 * |Register |type |caller-save/callee-save|
882 * +---------------+-----------------------+-----------------------+
883 * |GR0 |Zero register | - |
884 * |GR1 |Stack pointer(SP) | - |
885 * |GR2 |Frame pointer(FP) | - |
886 * |GR3 |Hidden parameter | caller save |
887 * |GR4-GR7 | - | caller save |
888 * |GR8-GR13 |Argument register | caller save |
889 * |GR14-GR15 | - | caller save |
890 * |GR16-GR31 | - | callee save |
891 * |GR32-GR47 | - | caller save |
892 * |GR48-GR63 | - | callee save |
893 * |FR0-FR15 | - | caller save |
894 * |FR16-FR31 | - | callee save |
895 * |FR32-FR47 | - | caller save |
896 * |FR48-FR63 | - | callee save |
897 * +---------------+-----------------------+-----------------------+
901 * SP-> |-----------------------------------|
903 * |-----------------------------------|
904 * | Register save area |
905 * |-----------------------------------|
906 * | Local variable save area |
907 * FP-> |-----------------------------------|
909 * |-----------------------------------|
910 * | Hidden parameter save area |
911 * |-----------------------------------|
912 * | Return address(LR) storage area |
913 * |-----------------------------------|
914 * | Padding for alignment |
915 * |-----------------------------------|
916 * | Register argument area |
917 * OLD SP-> |-----------------------------------|
919 * |-----------------------------------|
922 * Argument area/Parameter area:
924 * When a function is called, this area is used for argument transfer. When
925 * the argument is set up by the caller function, this area is referred to as
926 * the argument area. When the argument is referenced by the callee function,
927 * this area is referred to as the parameter area. The area is allocated when
928 * all arguments cannot be placed on the argument register at the time of
931 * Register save area:
933 * This is a register save area that must be guaranteed for the caller
934 * function. This area is not secured when the register save operation is not
937 * Local variable save area:
939 * This is the area for local variables and temporary variables.
943 * This area stores the FP value of the caller function.
945 * Hidden parameter save area:
947 * This area stores the start address of the return value storage
948 * area for a struct/union return function.
949 * When a struct/union is used as the return value, the caller
950 * function stores the return value storage area start address in
951 * register GR3 and passes it to the caller function.
952 * The callee function interprets the address stored in the GR3
953 * as the return value storage area start address.
954 * When register GR3 needs to be saved into memory, the callee
955 * function saves it in the hidden parameter save area. This
956 * area is not secured when the save operation is not needed.
958 * Return address(LR) storage area:
960 * This area saves the LR. The LR stores the address of a return to the caller
961 * function for the purpose of function calling.
963 * Argument register area:
965 * This area saves the argument register. This area is not secured when the
966 * save operation is not needed.
970 * Arguments, the count of which equals the count of argument registers (6
971 * words), are positioned in registers GR8 to GR13 and delivered to the callee
972 * function. When a struct/union return function is called, the return value
973 * area address is stored in register GR3. Arguments not placed in the
974 * argument registers will be stored in the stack argument area for transfer
975 * purposes. When an 8-byte type argument is to be delivered using registers,
976 * it is divided into two and placed in two registers for transfer. When
977 * argument registers must be saved to memory, the callee function secures an
978 * argument register save area in the stack. In this case, a continuous
979 * argument register save area must be established in the parameter area. The
980 * argument register save area must be allocated as needed to cover the size of
981 * the argument register to be saved. If the function has a variable count of
982 * arguments, it saves all argument registers in the argument register save
985 * Argument Extension Format:
987 * When an argument is to be stored in the stack, its type is converted to an
988 * extended type in accordance with the individual argument type. The argument
989 * is freed by the caller function after the return from the callee function is
992 * +-----------------------+---------------+------------------------+
993 * | Argument Type |Extended Type |Stack Storage Size(byte)|
994 * +-----------------------+---------------+------------------------+
996 * |signed char |int | 4 |
997 * |unsigned char |int | 4 |
998 * |[signed] short int |int | 4 |
999 * |unsigned short int |int | 4 |
1000 * |[signed] int |No extension | 4 |
1001 * |unsigned int |No extension | 4 |
1002 * |[signed] long int |No extension | 4 |
1003 * |unsigned long int |No extension | 4 |
1004 * |[signed] long long int |No extension | 8 |
1005 * |unsigned long long int |No extension | 8 |
1006 * |float |double | 8 |
1007 * |double |No extension | 8 |
1008 * |long double |No extension | 8 |
1009 * |pointer |No extension | 4 |
1010 * |struct/union |- | 4 (*1) |
1011 * +-----------------------+---------------+------------------------+
1013 * When a struct/union is to be delivered as an argument, the caller copies it
1014 * to the local variable area and delivers the address of that area.
1018 * +-------------------------------+----------------------+
1019 * |Return Value Type |Return Value Interface|
1020 * +-------------------------------+----------------------+
1022 * |[signed|unsigned] char |GR8 |
1023 * |[signed|unsigned] short int |GR8 |
1024 * |[signed|unsigned] int |GR8 |
1025 * |[signed|unsigned] long int |GR8 |
1027 * |[signed|unsigned] long long int|GR8 & GR9 |
1029 * |double |GR8 & GR9 |
1030 * |long double |GR8 & GR9 |
1031 * |struct/union |(*1) |
1032 * +-------------------------------+----------------------+
1034 * When a struct/union is used as the return value, the caller function stores
1035 * the start address of the return value storage area into GR3 and then passes
1036 * it to the callee function. The callee function interprets GR3 as the start
1037 * address of the return value storage area. When this address needs to be
1038 * saved in memory, the callee function secures the hidden parameter save area
1039 * and saves the address in that area.
1043 frv_stack_info (void)
1045 static frv_stack_t info, zero_info;
1046 frv_stack_t *info_ptr = &info;
1047 tree fndecl = current_function_decl;
1055 /* If we've already calculated the values and reload is complete,
1057 if (frv_stack_cache)
1058 return frv_stack_cache;
1060 /* Zero all fields. */
1063 /* Set up the register range information. */
1064 info_ptr->regs[STACK_REGS_GPR].name = "gpr";
1065 info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1;
1066 info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST;
1067 info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE;
1069 info_ptr->regs[STACK_REGS_FPR].name = "fpr";
1070 info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST;
1071 info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST;
1072 info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE;
1074 info_ptr->regs[STACK_REGS_LR].name = "lr";
1075 info_ptr->regs[STACK_REGS_LR].first = LR_REGNO;
1076 info_ptr->regs[STACK_REGS_LR].last = LR_REGNO;
1077 info_ptr->regs[STACK_REGS_LR].special_p = 1;
1079 info_ptr->regs[STACK_REGS_CC].name = "cc";
1080 info_ptr->regs[STACK_REGS_CC].first = CC_FIRST;
1081 info_ptr->regs[STACK_REGS_CC].last = CC_LAST;
1082 info_ptr->regs[STACK_REGS_CC].field_p = TRUE;
1084 info_ptr->regs[STACK_REGS_LCR].name = "lcr";
1085 info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO;
1086 info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO;
1088 info_ptr->regs[STACK_REGS_STDARG].name = "stdarg";
1089 info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM;
1090 info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM;
1091 info_ptr->regs[STACK_REGS_STDARG].dword_p = 1;
1092 info_ptr->regs[STACK_REGS_STDARG].special_p = 1;
1094 info_ptr->regs[STACK_REGS_STRUCT].name = "struct";
1095 info_ptr->regs[STACK_REGS_STRUCT].first = FRV_STRUCT_VALUE_REGNUM;
1096 info_ptr->regs[STACK_REGS_STRUCT].last = FRV_STRUCT_VALUE_REGNUM;
1097 info_ptr->regs[STACK_REGS_STRUCT].special_p = 1;
1099 info_ptr->regs[STACK_REGS_FP].name = "fp";
1100 info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM;
1101 info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM;
1102 info_ptr->regs[STACK_REGS_FP].special_p = 1;
1104 /* Determine if this is a stdarg function. If so, allocate space to store
1111 /* Find the last argument, and see if it is __builtin_va_alist. */
1112 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
1114 next_arg = TREE_CHAIN (cur_arg);
1115 if (next_arg == (tree)0)
1117 if (DECL_NAME (cur_arg)
1118 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
1126 /* Iterate over all of the register ranges. */
1127 for (range = 0; range < STACK_REGS_MAX; range++)
1129 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1130 int first = reg_ptr->first;
1131 int last = reg_ptr->last;
1133 int size_2words = 0;
1136 /* Calculate which registers need to be saved & save area size. */
1140 for (regno = first; regno <= last; regno++)
1142 if ((regs_ever_live[regno] && !call_used_regs[regno])
1143 || (current_function_calls_eh_return
1144 && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM))
1145 || (!TARGET_FDPIC && flag_pic
1146 && cfun->uses_pic_offset_table && regno == PIC_REGNO))
1148 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1149 size_1word += UNITS_PER_WORD;
1154 /* Calculate whether we need to create a frame after everything else
1155 has been processed. */
1160 if (regs_ever_live[LR_REGNO]
1162 /* This is set for __builtin_return_address, etc. */
1163 || cfun->machine->frame_needed
1164 || (TARGET_LINKED_FP && frame_pointer_needed)
1165 || (!TARGET_FDPIC && flag_pic
1166 && cfun->uses_pic_offset_table))
1168 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1169 size_1word += UNITS_PER_WORD;
1173 case STACK_REGS_STDARG:
1176 /* If this is a stdarg function with a non varardic
1177 argument split between registers and the stack,
1178 adjust the saved registers downward. */
1179 last -= (ADDR_ALIGN (cfun->pretend_args_size, UNITS_PER_WORD)
1182 for (regno = first; regno <= last; regno++)
1184 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1185 size_1word += UNITS_PER_WORD;
1188 info_ptr->stdarg_size = size_1word;
1192 case STACK_REGS_STRUCT:
1193 if (cfun->returns_struct)
1195 info_ptr->save_p[FRV_STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1196 size_1word += UNITS_PER_WORD;
1204 /* If this is a field, it only takes one word. */
1205 if (reg_ptr->field_p)
1206 size_1word = UNITS_PER_WORD;
1208 /* Determine which register pairs can be saved together. */
1209 else if (reg_ptr->dword_p && TARGET_DWORD)
1211 for (regno = first; regno < last; regno += 2)
1213 if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1])
1215 size_2words += 2 * UNITS_PER_WORD;
1216 size_1word -= 2 * UNITS_PER_WORD;
1217 info_ptr->save_p[regno] = REG_SAVE_2WORDS;
1218 info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE;
1223 reg_ptr->size_1word = size_1word;
1224 reg_ptr->size_2words = size_2words;
1226 if (! reg_ptr->special_p)
1228 info_ptr->regs_size_1word += size_1word;
1229 info_ptr->regs_size_2words += size_2words;
1234 /* Set up the sizes of each each field in the frame body, making the sizes
1235 of each be divisible by the size of a dword if dword operations might
1236 be used, or the size of a word otherwise. */
1237 alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD);
1239 info_ptr->parameter_size = ADDR_ALIGN (cfun->outgoing_args_size, alignment);
1240 info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words
1241 + info_ptr->regs_size_1word,
1243 info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment);
1245 info_ptr->pretend_size = cfun->pretend_args_size;
1247 /* Work out the size of the frame, excluding the header. Both the frame
1248 body and register parameter area will be dword-aligned. */
1249 info_ptr->total_size
1250 = (ADDR_ALIGN (info_ptr->parameter_size
1251 + info_ptr->regs_size
1252 + info_ptr->vars_size,
1254 + ADDR_ALIGN (info_ptr->pretend_size
1255 + info_ptr->stdarg_size,
1256 2 * UNITS_PER_WORD));
1258 /* See if we need to create a frame at all, if so add header area. */
1259 if (info_ptr->total_size > 0
1260 || frame_pointer_needed
1261 || info_ptr->regs[STACK_REGS_LR].size_1word > 0
1262 || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0)
1264 offset = info_ptr->parameter_size;
1265 info_ptr->header_size = 4 * UNITS_PER_WORD;
1266 info_ptr->total_size += 4 * UNITS_PER_WORD;
1268 /* Calculate the offsets to save normal register pairs. */
1269 for (range = 0; range < STACK_REGS_MAX; range++)
1271 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1272 if (! reg_ptr->special_p)
1274 int first = reg_ptr->first;
1275 int last = reg_ptr->last;
1278 for (regno = first; regno <= last; regno++)
1279 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS
1280 && regno != FRAME_POINTER_REGNUM
1281 && (regno < FIRST_ARG_REGNUM
1282 || regno > LAST_ARG_REGNUM))
1284 info_ptr->reg_offset[regno] = offset;
1285 offset += 2 * UNITS_PER_WORD;
1290 /* Calculate the offsets to save normal single registers. */
1291 for (range = 0; range < STACK_REGS_MAX; range++)
1293 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1294 if (! reg_ptr->special_p)
1296 int first = reg_ptr->first;
1297 int last = reg_ptr->last;
1300 for (regno = first; regno <= last; regno++)
1301 if (info_ptr->save_p[regno] == REG_SAVE_1WORD
1302 && regno != FRAME_POINTER_REGNUM
1303 && (regno < FIRST_ARG_REGNUM
1304 || regno > LAST_ARG_REGNUM))
1306 info_ptr->reg_offset[regno] = offset;
1307 offset += UNITS_PER_WORD;
1312 /* Calculate the offset to save the local variables at. */
1313 offset = ADDR_ALIGN (offset, alignment);
1314 if (info_ptr->vars_size)
1316 info_ptr->vars_offset = offset;
1317 offset += info_ptr->vars_size;
1320 /* Align header to a dword-boundary. */
1321 offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD);
1323 /* Calculate the offsets in the fixed frame. */
1324 info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD;
1325 info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset;
1326 info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD;
1328 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1329 info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD;
1330 info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD;
1332 if (cfun->returns_struct)
1334 info_ptr->save_p[FRV_STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1335 info_ptr->reg_offset[FRV_STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD;
1336 info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD;
1339 /* Calculate the offsets to store the arguments passed in registers
1340 for stdarg functions. The register pairs are first and the single
1341 register if any is last. The register save area starts on a
1343 if (info_ptr->stdarg_size)
1345 int first = info_ptr->regs[STACK_REGS_STDARG].first;
1346 int last = info_ptr->regs[STACK_REGS_STDARG].last;
1349 /* Skip the header. */
1350 offset += 4 * UNITS_PER_WORD;
1351 for (regno = first; regno <= last; regno++)
1353 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS)
1355 info_ptr->reg_offset[regno] = offset;
1356 offset += 2 * UNITS_PER_WORD;
1358 else if (info_ptr->save_p[regno] == REG_SAVE_1WORD)
1360 info_ptr->reg_offset[regno] = offset;
1361 offset += UNITS_PER_WORD;
1367 if (reload_completed)
1368 frv_stack_cache = info_ptr;
1374 /* Print the information about the frv stack offsets, etc. when debugging. */
1377 frv_debug_stack (frv_stack_t *info)
1382 info = frv_stack_info ();
1384 fprintf (stderr, "\nStack information for function %s:\n",
1385 ((current_function_decl && DECL_NAME (current_function_decl))
1386 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1389 fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size);
1390 fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size);
1391 fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size);
1392 fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n",
1393 info->regs_size, info->regs_size_1word, info->regs_size_2words);
1395 fprintf (stderr, "\theader_size\t= %6d\n", info->header_size);
1396 fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size);
1397 fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset);
1398 fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset);
1400 for (range = 0; range < STACK_REGS_MAX; range++)
1402 frv_stack_regs_t *regs = &(info->regs[range]);
1403 if ((regs->size_1word + regs->size_2words) > 0)
1405 int first = regs->first;
1406 int last = regs->last;
1409 fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =",
1410 regs->name, regs->size_1word + regs->size_2words,
1411 regs->size_1word, regs->size_2words);
1413 for (regno = first; regno <= last; regno++)
1415 if (info->save_p[regno] == REG_SAVE_1WORD)
1416 fprintf (stderr, " %s (%d)", reg_names[regno],
1417 info->reg_offset[regno]);
1419 else if (info->save_p[regno] == REG_SAVE_2WORDS)
1420 fprintf (stderr, " %s-%s (%d)", reg_names[regno],
1421 reg_names[regno+1], info->reg_offset[regno]);
1424 fputc ('\n', stderr);
1434 /* Used during final to control the packing of insns. The value is
1435 1 if the current instruction should be packed with the next one,
1436 0 if it shouldn't or -1 if packing is disabled altogether. */
1438 static int frv_insn_packing_flag;
1440 /* True if the current function contains a far jump. */
1443 frv_function_contains_far_jump (void)
1445 rtx insn = get_insns ();
1447 && !(GET_CODE (insn) == JUMP_INSN
1448 /* Ignore tablejump patterns. */
1449 && GET_CODE (PATTERN (insn)) != ADDR_VEC
1450 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
1451 && get_attr_far_jump (insn) == FAR_JUMP_YES))
1452 insn = NEXT_INSN (insn);
1453 return (insn != NULL);
1456 /* For the FRV, this function makes sure that a function with far jumps
1457 will return correctly. It also does the VLIW packing. */
1460 frv_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1462 /* If no frame was created, check whether the function uses a call
1463 instruction to implement a far jump. If so, save the link in gr3 and
1464 replace all returns to LR with returns to GR3. GR3 is used because it
1465 is call-clobbered, because is not available to the register allocator,
1466 and because all functions that take a hidden argument pointer will have
1468 if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ())
1472 /* Just to check that the above comment is true. */
1473 gcc_assert (!regs_ever_live[GPR_FIRST + 3]);
1475 /* Generate the instruction that saves the link register. */
1476 fprintf (file, "\tmovsg lr,gr3\n");
1478 /* Replace the LR with GR3 in *return_internal patterns. The insn
1479 will now return using jmpl @(gr3,0) rather than bralr. We cannot
1480 simply emit a different assembly directive because bralr and jmpl
1481 execute in different units. */
1482 for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn))
1483 if (GET_CODE (insn) == JUMP_INSN)
1485 rtx pattern = PATTERN (insn);
1486 if (GET_CODE (pattern) == PARALLEL
1487 && XVECLEN (pattern, 0) >= 2
1488 && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN
1489 && GET_CODE (XVECEXP (pattern, 0, 1)) == USE)
1491 rtx address = XEXP (XVECEXP (pattern, 0, 1), 0);
1492 if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO)
1493 REGNO (address) = GPR_FIRST + 3;
1500 /* Allow the garbage collector to free the nops created by frv_reorg. */
1501 memset (frv_nops, 0, sizeof (frv_nops));
1505 /* Return the next available temporary register in a given class. */
1508 frv_alloc_temp_reg (
1509 frv_tmp_reg_t *info, /* which registers are available */
1510 enum reg_class class, /* register class desired */
1511 enum machine_mode mode, /* mode to allocate register with */
1512 int mark_as_used, /* register not available after allocation */
1513 int no_abort) /* return NULL instead of aborting */
1515 int regno = info->next_reg[ (int)class ];
1516 int orig_regno = regno;
1517 HARD_REG_SET *reg_in_class = ®_class_contents[ (int)class ];
1522 if (TEST_HARD_REG_BIT (*reg_in_class, regno)
1523 && TEST_HARD_REG_BIT (info->regs, regno))
1526 if (++regno >= FIRST_PSEUDO_REGISTER)
1528 if (regno == orig_regno)
1530 gcc_assert (no_abort);
1535 nr = HARD_REGNO_NREGS (regno, mode);
1536 info->next_reg[ (int)class ] = regno + nr;
1539 for (i = 0; i < nr; i++)
1540 CLEAR_HARD_REG_BIT (info->regs, regno+i);
1542 return gen_rtx_REG (mode, regno);
1546 /* Return an rtx with the value OFFSET, which will either be a register or a
1547 signed 12-bit integer. It can be used as the second operand in an "add"
1548 instruction, or as the index in a load or store.
1550 The function returns a constant rtx if OFFSET is small enough, otherwise
1551 it loads the constant into register OFFSET_REGNO and returns that. */
1553 frv_frame_offset_rtx (int offset)
1555 rtx offset_rtx = GEN_INT (offset);
1556 if (IN_RANGE_P (offset, -2048, 2047))
1560 rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO);
1561 if (IN_RANGE_P (offset, -32768, 32767))
1562 emit_insn (gen_movsi (reg_rtx, offset_rtx));
1565 emit_insn (gen_movsi_high (reg_rtx, offset_rtx));
1566 emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx));
1572 /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The
1573 prologue and epilogue uses such expressions to access the stack. */
1575 frv_frame_mem (enum machine_mode mode, rtx base, int offset)
1577 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode,
1579 frv_frame_offset_rtx (offset)));
1582 /* Generate a frame-related expression:
1584 (set REG (mem (plus (sp) (const_int OFFSET)))).
1586 Such expressions are used in FRAME_RELATED_EXPR notes for more complex
1587 instructions. Marking the expressions as frame-related is superfluous if
1588 the note contains just a single set. But if the note contains a PARALLEL
1589 or SEQUENCE that has several sets, each set must be individually marked
1590 as frame-related. */
1592 frv_dwarf_store (rtx reg, int offset)
1594 rtx set = gen_rtx_SET (VOIDmode,
1595 gen_rtx_MEM (GET_MODE (reg),
1596 plus_constant (stack_pointer_rtx,
1599 RTX_FRAME_RELATED_P (set) = 1;
1603 /* Emit a frame-related instruction whose pattern is PATTERN. The
1604 instruction is the last in a sequence that cumulatively performs the
1605 operation described by DWARF_PATTERN. The instruction is marked as
1606 frame-related and has a REG_FRAME_RELATED_EXPR note containing
1609 frv_frame_insn (rtx pattern, rtx dwarf_pattern)
1611 rtx insn = emit_insn (pattern);
1612 RTX_FRAME_RELATED_P (insn) = 1;
1613 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1618 /* Emit instructions that transfer REG to or from the memory location (sp +
1619 STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is
1620 FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this
1621 function to store registers and only the epilogue uses it to load them.
1623 The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET).
1624 The generated instruction will use BASE as its base register. BASE may
1625 simply be the stack pointer, but if several accesses are being made to a
1626 region far away from the stack pointer, it may be more efficient to set
1627 up a temporary instead.
1629 Store instructions will be frame-related and will be annotated with the
1630 overall effect of the store. Load instructions will be followed by a
1631 (use) to prevent later optimizations from zapping them.
1633 The function takes care of the moves to and from SPRs, using TEMP_REGNO
1634 as a temporary in such cases. */
1636 frv_frame_access (frv_frame_accessor_t *accessor, rtx reg, int stack_offset)
1638 enum machine_mode mode = GET_MODE (reg);
1639 rtx mem = frv_frame_mem (mode,
1641 stack_offset - accessor->base_offset);
1643 if (accessor->op == FRV_LOAD)
1645 if (SPR_P (REGNO (reg)))
1647 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1648 emit_insn (gen_rtx_SET (VOIDmode, temp, mem));
1649 emit_insn (gen_rtx_SET (VOIDmode, reg, temp));
1652 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
1653 emit_insn (gen_rtx_USE (VOIDmode, reg));
1657 if (SPR_P (REGNO (reg)))
1659 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1660 emit_insn (gen_rtx_SET (VOIDmode, temp, reg));
1661 frv_frame_insn (gen_rtx_SET (Pmode, mem, temp),
1662 frv_dwarf_store (reg, stack_offset));
1664 else if (GET_MODE (reg) == DImode)
1666 /* For DImode saves, the dwarf2 version needs to be a SEQUENCE
1667 with a separate save for each register. */
1668 rtx reg1 = gen_rtx_REG (SImode, REGNO (reg));
1669 rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1);
1670 rtx set1 = frv_dwarf_store (reg1, stack_offset);
1671 rtx set2 = frv_dwarf_store (reg2, stack_offset + 4);
1672 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1673 gen_rtx_PARALLEL (VOIDmode,
1674 gen_rtvec (2, set1, set2)));
1677 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1678 frv_dwarf_store (reg, stack_offset));
1682 /* A function that uses frv_frame_access to transfer a group of registers to
1683 or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO
1684 is the stack information generated by frv_stack_info, and REG_SET is the
1685 number of the register set to transfer. */
1687 frv_frame_access_multi (frv_frame_accessor_t *accessor,
1691 frv_stack_regs_t *regs_info;
1694 regs_info = &info->regs[reg_set];
1695 for (regno = regs_info->first; regno <= regs_info->last; regno++)
1696 if (info->save_p[regno])
1697 frv_frame_access (accessor,
1698 info->save_p[regno] == REG_SAVE_2WORDS
1699 ? gen_rtx_REG (DImode, regno)
1700 : gen_rtx_REG (SImode, regno),
1701 info->reg_offset[regno]);
1704 /* Save or restore callee-saved registers that are kept outside the frame
1705 header. The function saves the registers if OP is FRV_STORE and restores
1706 them if OP is FRV_LOAD. INFO is the stack information generated by
1709 frv_frame_access_standard_regs (enum frv_stack_op op, frv_stack_t *info)
1711 frv_frame_accessor_t accessor;
1714 accessor.base = stack_pointer_rtx;
1715 accessor.base_offset = 0;
1716 frv_frame_access_multi (&accessor, info, STACK_REGS_GPR);
1717 frv_frame_access_multi (&accessor, info, STACK_REGS_FPR);
1718 frv_frame_access_multi (&accessor, info, STACK_REGS_LCR);
1722 /* Called after register allocation to add any instructions needed for the
1723 prologue. Using a prologue insn is favored compared to putting all of the
1724 instructions in the TARGET_ASM_FUNCTION_PROLOGUE target hook, since
1725 it allows the scheduler to intermix instructions with the saves of
1726 the caller saved registers. In some cases, it might be necessary
1727 to emit a barrier instruction as the last insn to prevent such
1730 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
1731 so that the debug info generation code can handle them properly. */
1733 frv_expand_prologue (void)
1735 frv_stack_t *info = frv_stack_info ();
1736 rtx sp = stack_pointer_rtx;
1737 rtx fp = frame_pointer_rtx;
1738 frv_frame_accessor_t accessor;
1740 if (TARGET_DEBUG_STACK)
1741 frv_debug_stack (info);
1743 if (info->total_size == 0)
1746 /* We're interested in three areas of the frame here:
1748 A: the register save area
1750 C: the header after B
1752 If the frame pointer isn't used, we'll have to set up A, B and C
1753 using the stack pointer. If the frame pointer is used, we'll access
1757 B: set up using sp or a temporary (see below)
1760 We set up B using the stack pointer if the frame is small enough.
1761 Otherwise, it's more efficient to copy the old stack pointer into a
1762 temporary and use that.
1764 Note that it's important to make sure the prologue and epilogue use the
1765 same registers to access A and C, since doing otherwise will confuse
1766 the aliasing code. */
1768 /* Set up ACCESSOR for accessing region B above. If the frame pointer
1769 isn't used, the same method will serve for C. */
1770 accessor.op = FRV_STORE;
1771 if (frame_pointer_needed && info->total_size > 2048)
1775 accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO);
1776 accessor.base_offset = info->total_size;
1777 insn = emit_insn (gen_movsi (accessor.base, sp));
1781 accessor.base = stack_pointer_rtx;
1782 accessor.base_offset = 0;
1785 /* Allocate the stack space. */
1787 rtx asm_offset = frv_frame_offset_rtx (-info->total_size);
1788 rtx dwarf_offset = GEN_INT (-info->total_size);
1790 frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset),
1793 gen_rtx_PLUS (Pmode, sp, dwarf_offset)));
1796 /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET)
1797 and point the new one to that location. */
1798 if (frame_pointer_needed)
1800 int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1802 /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is
1803 based on ACCESSOR.BASE but DWARF_SRC is always based on the stack
1805 rtx asm_src = plus_constant (accessor.base,
1806 fp_offset - accessor.base_offset);
1807 rtx dwarf_src = plus_constant (sp, fp_offset);
1809 /* Store the old frame pointer at (sp + FP_OFFSET). */
1810 frv_frame_access (&accessor, fp, fp_offset);
1812 /* Set up the new frame pointer. */
1813 frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src),
1814 gen_rtx_SET (VOIDmode, fp, dwarf_src));
1816 /* Access region C from the frame pointer. */
1818 accessor.base_offset = fp_offset;
1821 /* Set up region C. */
1822 frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT);
1823 frv_frame_access_multi (&accessor, info, STACK_REGS_LR);
1824 frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG);
1826 /* Set up region A. */
1827 frv_frame_access_standard_regs (FRV_STORE, info);
1829 /* If this is a varargs/stdarg function, issue a blockage to prevent the
1830 scheduler from moving loads before the stores saving the registers. */
1831 if (info->stdarg_size > 0)
1832 emit_insn (gen_blockage ());
1834 /* Set up pic register/small data register for this function. */
1835 if (!TARGET_FDPIC && flag_pic && cfun->uses_pic_offset_table)
1836 emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO),
1837 gen_rtx_REG (Pmode, LR_REGNO),
1838 gen_rtx_REG (SImode, OFFSET_REGNO)));
1842 /* Under frv, all of the work is done via frv_expand_epilogue, but
1843 this function provides a convenient place to do cleanup. */
1846 frv_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
1847 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1849 frv_stack_cache = (frv_stack_t *)0;
1851 /* Zap last used registers for conditional execution. */
1852 memset (&frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg));
1854 /* Release the bitmap of created insns. */
1855 BITMAP_FREE (frv_ifcvt.scratch_insns_bitmap);
1859 /* Called after register allocation to add any instructions needed for the
1860 epilogue. Using an epilogue insn is favored compared to putting all of the
1861 instructions in the TARGET_ASM_FUNCTION_PROLOGUE target hook, since
1862 it allows the scheduler to intermix instructions with the saves of
1863 the caller saved registers. In some cases, it might be necessary
1864 to emit a barrier instruction as the last insn to prevent such
1868 frv_expand_epilogue (bool emit_return)
1870 frv_stack_t *info = frv_stack_info ();
1871 rtx fp = frame_pointer_rtx;
1872 rtx sp = stack_pointer_rtx;
1876 fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1878 /* Restore the stack pointer to its original value if alloca or the like
1880 if (! current_function_sp_is_unchanging)
1881 emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset)));
1883 /* Restore the callee-saved registers that were used in this function. */
1884 frv_frame_access_standard_regs (FRV_LOAD, info);
1886 /* Set RETURN_ADDR to the address we should return to. Set it to NULL if
1887 no return instruction should be emitted. */
1888 if (info->save_p[LR_REGNO])
1893 /* Use the same method to access the link register's slot as we did in
1894 the prologue. In other words, use the frame pointer if available,
1895 otherwise use the stack pointer.
1897 LR_OFFSET is the offset of the link register's slot from the start
1898 of the frame and MEM is a memory rtx for it. */
1899 lr_offset = info->reg_offset[LR_REGNO];
1900 if (frame_pointer_needed)
1901 mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset);
1903 mem = frv_frame_mem (Pmode, sp, lr_offset);
1905 /* Load the old link register into a GPR. */
1906 return_addr = gen_rtx_REG (Pmode, TEMP_REGNO);
1907 emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem));
1910 return_addr = gen_rtx_REG (Pmode, LR_REGNO);
1912 /* Restore the old frame pointer. Emit a USE afterwards to make sure
1913 the load is preserved. */
1914 if (frame_pointer_needed)
1916 emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp)));
1917 emit_insn (gen_rtx_USE (VOIDmode, fp));
1920 /* Deallocate the stack frame. */
1921 if (info->total_size != 0)
1923 rtx offset = frv_frame_offset_rtx (info->total_size);
1924 emit_insn (gen_stack_adjust (sp, sp, offset));
1927 /* If this function uses eh_return, add the final stack adjustment now. */
1928 if (current_function_calls_eh_return)
1929 emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX));
1932 emit_jump_insn (gen_epilogue_return (return_addr));
1935 rtx lr = return_addr;
1937 if (REGNO (return_addr) != LR_REGNO)
1939 lr = gen_rtx_REG (Pmode, LR_REGNO);
1940 emit_move_insn (lr, return_addr);
1943 emit_insn (gen_rtx_USE (VOIDmode, lr));
1948 /* Worker function for TARGET_ASM_OUTPUT_MI_THUNK. */
1951 frv_asm_output_mi_thunk (FILE *file,
1952 tree thunk_fndecl ATTRIBUTE_UNUSED,
1953 HOST_WIDE_INT delta,
1954 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
1957 const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0);
1958 const char *name_arg0 = reg_names[FIRST_ARG_REGNUM];
1959 const char *name_jmp = reg_names[JUMP_REGNO];
1960 const char *parallel = (frv_issue_rate () > 1 ? ".p" : "");
1962 /* Do the add using an addi if possible. */
1963 if (IN_RANGE_P (delta, -2048, 2047))
1964 fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0);
1967 const char *const name_add = reg_names[TEMP_REGNO];
1968 fprintf (file, "\tsethi%s #hi(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1969 parallel, delta, name_add);
1970 fprintf (file, "\tsetlo #lo(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1972 fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0);
1977 const char *name_pic = reg_names[FDPIC_REGNO];
1978 name_jmp = reg_names[FDPIC_FPTR_REGNO];
1982 fprintf (file, "\tsethi%s #gotofffuncdeschi(", parallel);
1983 assemble_name (file, name_func);
1984 fprintf (file, "),%s\n", name_jmp);
1986 fprintf (file, "\tsetlo #gotofffuncdesclo(");
1987 assemble_name (file, name_func);
1988 fprintf (file, "),%s\n", name_jmp);
1990 fprintf (file, "\tldd @(%s,%s), %s\n", name_jmp, name_pic, name_jmp);
1994 fprintf (file, "\tlddo @(%s,#gotofffuncdesc12(", name_pic);
1995 assemble_name (file, name_func);
1996 fprintf (file, "\t)), %s\n", name_jmp);
2001 fprintf (file, "\tsethi%s #hi(", parallel);
2002 assemble_name (file, name_func);
2003 fprintf (file, "),%s\n", name_jmp);
2005 fprintf (file, "\tsetlo #lo(");
2006 assemble_name (file, name_func);
2007 fprintf (file, "),%s\n", name_jmp);
2011 /* Use JUMP_REGNO as a temporary PIC register. */
2012 const char *name_lr = reg_names[LR_REGNO];
2013 const char *name_gppic = name_jmp;
2014 const char *name_tmp = reg_names[TEMP_REGNO];
2016 fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp);
2017 fprintf (file, "\tcall 1f\n");
2018 fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic);
2019 fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr);
2020 fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp);
2021 fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp);
2022 fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic);
2024 fprintf (file, "\tsethi%s #gprelhi(", parallel);
2025 assemble_name (file, name_func);
2026 fprintf (file, "),%s\n", name_tmp);
2028 fprintf (file, "\tsetlo #gprello(");
2029 assemble_name (file, name_func);
2030 fprintf (file, "),%s\n", name_tmp);
2032 fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp);
2035 /* Jump to the function address. */
2036 fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]);
2040 /* A C expression which is nonzero if a function must have and use a frame
2041 pointer. This expression is evaluated in the reload pass. If its value is
2042 nonzero the function will have a frame pointer.
2044 The expression can in principle examine the current function and decide
2045 according to the facts, but on most machines the constant 0 or the constant
2046 1 suffices. Use 0 when the machine allows code to be generated with no
2047 frame pointer, and doing so saves some time or space. Use 1 when there is
2048 no possible advantage to avoiding a frame pointer.
2050 In certain cases, the compiler does not know how to produce valid code
2051 without a frame pointer. The compiler recognizes those cases and
2052 automatically gives the function a frame pointer regardless of what
2053 `FRAME_POINTER_REQUIRED' says. You don't need to worry about them.
2055 In a function that does not require a frame pointer, the frame pointer
2056 register can be allocated for ordinary usage, unless you mark it as a fixed
2057 register. See `FIXED_REGISTERS' for more information. */
2059 /* On frv, create a frame whenever we need to create stack. */
2062 frv_frame_pointer_required (void)
2064 /* If we forgoing the usual linkage requirements, we only need
2065 a frame pointer if the stack pointer might change. */
2066 if (!TARGET_LINKED_FP)
2067 return !current_function_sp_is_unchanging;
2069 if (! current_function_is_leaf)
2072 if (get_frame_size () != 0)
2078 if (!current_function_sp_is_unchanging)
2081 if (!TARGET_FDPIC && flag_pic && cfun->uses_pic_offset_table)
2087 if (cfun->machine->frame_needed)
2094 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the
2095 initial difference between the specified pair of registers. This macro must
2096 be defined if `ELIMINABLE_REGS' is defined. */
2098 /* See frv_stack_info for more details on the frv stack frame. */
2101 frv_initial_elimination_offset (int from, int to)
2103 frv_stack_t *info = frv_stack_info ();
2106 if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2107 ret = info->total_size - info->pretend_size;
2109 else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM)
2110 ret = info->reg_offset[FRAME_POINTER_REGNUM];
2112 else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2113 ret = (info->total_size
2114 - info->reg_offset[FRAME_POINTER_REGNUM]
2115 - info->pretend_size);
2120 if (TARGET_DEBUG_STACK)
2121 fprintf (stderr, "Eliminate %s to %s by adding %d\n",
2122 reg_names [from], reg_names[to], ret);
2128 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2131 frv_setup_incoming_varargs (CUMULATIVE_ARGS *cum,
2132 enum machine_mode mode,
2133 tree type ATTRIBUTE_UNUSED,
2137 if (TARGET_DEBUG_ARG)
2139 "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n",
2140 *cum, GET_MODE_NAME (mode), *pretend_size, second_time);
2144 /* Worker function for TARGET_EXPAND_BUILTIN_SAVEREGS. */
2147 frv_expand_builtin_saveregs (void)
2149 int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS;
2151 if (TARGET_DEBUG_ARG)
2152 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2155 return gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2159 /* Expand __builtin_va_start to do the va_start macro. */
2162 frv_expand_builtin_va_start (tree valist, rtx nextarg)
2165 int num = cfun->args_info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS;
2167 nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx,
2168 GEN_INT (UNITS_PER_WORD * num));
2170 if (TARGET_DEBUG_ARG)
2172 fprintf (stderr, "va_start: args_info = %d, num = %d\n",
2173 cfun->args_info, num);
2175 debug_rtx (nextarg);
2178 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2179 make_tree (ptr_type_node, nextarg));
2180 TREE_SIDE_EFFECTS (t) = 1;
2182 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2186 /* Expand a block move operation, and return 1 if successful. Return 0
2187 if we should let the compiler generate normal code.
2189 operands[0] is the destination
2190 operands[1] is the source
2191 operands[2] is the length
2192 operands[3] is the alignment */
2194 /* Maximum number of loads to do before doing the stores */
2195 #ifndef MAX_MOVE_REG
2196 #define MAX_MOVE_REG 4
2199 /* Maximum number of total loads to do. */
2200 #ifndef TOTAL_MOVE_REG
2201 #define TOTAL_MOVE_REG 8
2205 frv_expand_block_move (rtx operands[])
2207 rtx orig_dest = operands[0];
2208 rtx orig_src = operands[1];
2209 rtx bytes_rtx = operands[2];
2210 rtx align_rtx = operands[3];
2211 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2224 rtx stores[MAX_MOVE_REG];
2226 enum machine_mode mode;
2228 /* If this is not a fixed size move, just call memcpy. */
2232 /* This should be a fixed size alignment. */
2233 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
2235 align = INTVAL (align_rtx);
2237 /* Anything to move? */
2238 bytes = INTVAL (bytes_rtx);
2242 /* Don't support real large moves. */
2243 if (bytes > TOTAL_MOVE_REG*align)
2246 /* Move the address into scratch registers. */
2247 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2248 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2250 num_reg = offset = 0;
2251 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2253 /* Calculate the correct offset for src/dest. */
2257 dest_addr = dest_reg;
2261 src_addr = plus_constant (src_reg, offset);
2262 dest_addr = plus_constant (dest_reg, offset);
2265 /* Generate the appropriate load and store, saving the stores
2267 if (bytes >= 4 && align >= 4)
2269 else if (bytes >= 2 && align >= 2)
2274 move_bytes = GET_MODE_SIZE (mode);
2275 tmp_reg = gen_reg_rtx (mode);
2276 src_mem = change_address (orig_src, mode, src_addr);
2277 dest_mem = change_address (orig_dest, mode, dest_addr);
2278 emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem));
2279 stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg);
2281 if (num_reg >= MAX_MOVE_REG)
2283 for (i = 0; i < num_reg; i++)
2284 emit_insn (stores[i]);
2289 for (i = 0; i < num_reg; i++)
2290 emit_insn (stores[i]);
2296 /* Expand a block clear operation, and return 1 if successful. Return 0
2297 if we should let the compiler generate normal code.
2299 operands[0] is the destination
2300 operands[1] is the length
2301 operands[3] is the alignment */
2304 frv_expand_block_clear (rtx operands[])
2306 rtx orig_dest = operands[0];
2307 rtx bytes_rtx = operands[1];
2308 rtx align_rtx = operands[3];
2309 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2318 enum machine_mode mode;
2320 /* If this is not a fixed size move, just call memcpy. */
2324 /* This should be a fixed size alignment. */
2325 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
2327 align = INTVAL (align_rtx);
2329 /* Anything to move? */
2330 bytes = INTVAL (bytes_rtx);
2334 /* Don't support real large clears. */
2335 if (bytes > TOTAL_MOVE_REG*align)
2338 /* Move the address into a scratch register. */
2339 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2341 num_reg = offset = 0;
2342 for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes))
2344 /* Calculate the correct offset for src/dest. */
2345 dest_addr = ((offset == 0)
2347 : plus_constant (dest_reg, offset));
2349 /* Generate the appropriate store of gr0. */
2350 if (bytes >= 4 && align >= 4)
2352 else if (bytes >= 2 && align >= 2)
2357 clear_bytes = GET_MODE_SIZE (mode);
2358 dest_mem = change_address (orig_dest, mode, dest_addr);
2359 emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx));
2366 /* The following variable is used to output modifiers of assembler
2367 code of the current output insn. */
2369 static rtx *frv_insn_operands;
2371 /* The following function is used to add assembler insn code suffix .p
2372 if it is necessary. */
2375 frv_asm_output_opcode (FILE *f, const char *ptr)
2379 if (frv_insn_packing_flag <= 0)
2382 for (; *ptr && *ptr != ' ' && *ptr != '\t';)
2385 if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z')
2386 || (*ptr >= 'A' && *ptr <= 'Z')))
2388 int letter = *ptr++;
2391 frv_print_operand (f, frv_insn_operands [c], letter);
2392 while ((c = *ptr) >= '0' && c <= '9')
2404 /* Set up the packing bit for the current output insn. Note that this
2405 function is not called for asm insns. */
2408 frv_final_prescan_insn (rtx insn, rtx *opvec,
2409 int noperands ATTRIBUTE_UNUSED)
2413 if (frv_insn_packing_flag >= 0)
2415 frv_insn_operands = opvec;
2416 frv_insn_packing_flag = PACKING_FLAG_P (insn);
2418 else if (recog_memoized (insn) >= 0
2419 && get_attr_acc_group (insn) == ACC_GROUP_ODD)
2420 /* Packing optimizations have been disabled, but INSN can only
2421 be issued in M1. Insert an mnop in M0. */
2422 fprintf (asm_out_file, "\tmnop.p\n");
2428 /* A C expression whose value is RTL representing the address in a stack frame
2429 where the pointer to the caller's frame is stored. Assume that FRAMEADDR is
2430 an RTL expression for the address of the stack frame itself.
2432 If you don't define this macro, the default is to return the value of
2433 FRAMEADDR--that is, the stack frame address is also the address of the stack
2434 word that points to the previous frame. */
2436 /* The default is correct, but we need to make sure the frame gets created. */
2438 frv_dynamic_chain_address (rtx frame)
2440 cfun->machine->frame_needed = 1;
2445 /* A C expression whose value is RTL representing the value of the return
2446 address for the frame COUNT steps up from the current frame, after the
2447 prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame
2448 pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
2451 The value of the expression must always be the correct address when COUNT is
2452 zero, but may be `NULL_RTX' if there is not way to determine the return
2453 address of other frames. */
2456 frv_return_addr_rtx (int count, rtx frame)
2460 cfun->machine->frame_needed = 1;
2461 return gen_rtx_MEM (Pmode, plus_constant (frame, 8));
2464 /* Given a memory reference MEMREF, interpret the referenced memory as
2465 an array of MODE values, and return a reference to the element
2466 specified by INDEX. Assume that any pre-modification implicit in
2467 MEMREF has already happened.
2469 MEMREF must be a legitimate operand for modes larger than SImode.
2470 GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which
2471 this function cannot handle. */
2473 frv_index_memory (rtx memref, enum machine_mode mode, int index)
2475 rtx base = XEXP (memref, 0);
2476 if (GET_CODE (base) == PRE_MODIFY)
2477 base = XEXP (base, 0);
2478 return change_address (memref, mode,
2479 plus_constant (base, index * GET_MODE_SIZE (mode)));
2483 /* Print a memory address as an operand to reference that memory location. */
2485 frv_print_operand_address (FILE * stream, rtx x)
2487 if (GET_CODE (x) == MEM)
2490 switch (GET_CODE (x))
2493 fputs (reg_names [ REGNO (x)], stream);
2497 fprintf (stream, "%ld", (long) INTVAL (x));
2501 assemble_name (stream, XSTR (x, 0));
2506 output_addr_const (stream, x);
2513 fatal_insn ("bad insn to frv_print_operand_address:", x);
2518 frv_print_operand_memory_reference_reg (FILE * stream, rtx x)
2520 int regno = true_regnum (x);
2522 fputs (reg_names[regno], stream);
2524 fatal_insn ("bad register to frv_print_operand_memory_reference_reg:", x);
2527 /* Print a memory reference suitable for the ld/st instructions. */
2530 frv_print_operand_memory_reference (FILE * stream, rtx x, int addr_offset)
2532 struct frv_unspec unspec;
2536 switch (GET_CODE (x))
2543 case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */
2545 x1 = XEXP (XEXP (x, 1), 1);
2555 if (GET_CODE (x0) == CONST_INT)
2563 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2572 else if (GET_CODE (x1) != CONST_INT)
2573 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2576 fputs ("@(", stream);
2578 fputs (reg_names[GPR_R0], stream);
2579 else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG)
2580 frv_print_operand_memory_reference_reg (stream, x0);
2582 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2584 fputs (",", stream);
2586 fputs (reg_names [GPR_R0], stream);
2590 switch (GET_CODE (x1))
2594 frv_print_operand_memory_reference_reg (stream, x1);
2598 fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset));
2602 if (!frv_const_unspec_p (x1, &unspec))
2603 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x1);
2604 frv_output_const_unspec (stream, &unspec);
2608 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2612 fputs (")", stream);
2616 /* Return 2 for likely branches and 0 for non-likely branches */
2618 #define FRV_JUMP_LIKELY 2
2619 #define FRV_JUMP_NOT_LIKELY 0
2622 frv_print_operand_jump_hint (rtx insn)
2627 HOST_WIDE_INT prob = -1;
2628 enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN;
2630 gcc_assert (GET_CODE (insn) == JUMP_INSN);
2632 /* Assume any non-conditional jump is likely. */
2633 if (! any_condjump_p (insn))
2634 ret = FRV_JUMP_LIKELY;
2638 labelref = condjump_label (insn);
2641 rtx label = XEXP (labelref, 0);
2642 jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label))
2647 note = find_reg_note (insn, REG_BR_PROB, 0);
2649 ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY);
2653 prob = INTVAL (XEXP (note, 0));
2654 ret = ((prob >= (REG_BR_PROB_BASE / 2))
2656 : FRV_JUMP_NOT_LIKELY);
2668 case UNKNOWN: direction = "unknown jump direction"; break;
2669 case BACKWARD: direction = "jump backward"; break;
2670 case FORWARD: direction = "jump forward"; break;
2674 "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n",
2675 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
2676 (long)INSN_UID (insn), direction, (long)prob,
2677 (long)REG_BR_PROB_BASE, ret);
2685 /* Return the comparison operator to use for CODE given that the ICC
2689 comparison_string (enum rtx_code code, rtx op0)
2691 bool is_nz_p = GET_MODE (op0) == CC_NZmode;
2694 default: output_operand_lossage ("bad condition code");
2695 case EQ: return "eq";
2696 case NE: return "ne";
2697 case LT: return is_nz_p ? "n" : "lt";
2698 case LE: return "le";
2699 case GT: return "gt";
2700 case GE: return is_nz_p ? "p" : "ge";
2701 case LTU: return is_nz_p ? "no" : "c";
2702 case LEU: return is_nz_p ? "eq" : "ls";
2703 case GTU: return is_nz_p ? "ne" : "hi";
2704 case GEU: return is_nz_p ? "ra" : "nc";
2708 /* Print an operand to an assembler instruction.
2710 `%' followed by a letter and a digit says to output an operand in an
2711 alternate fashion. Four letters have standard, built-in meanings described
2712 below. The machine description macro `PRINT_OPERAND' can define additional
2713 letters with nonstandard meanings.
2715 `%cDIGIT' can be used to substitute an operand that is a constant value
2716 without the syntax that normally indicates an immediate operand.
2718 `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated
2721 `%aDIGIT' can be used to substitute an operand as if it were a memory
2722 reference, with the actual operand treated as the address. This may be
2723 useful when outputting a "load address" instruction, because often the
2724 assembler syntax for such an instruction requires you to write the operand
2725 as if it were a memory reference.
2727 `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
2729 `%=' outputs a number which is unique to each instruction in the entire
2730 compilation. This is useful for making local labels to be referred to more
2731 than once in a single template that generates multiple assembler
2734 `%' followed by a punctuation character specifies a substitution that does
2735 not use an operand. Only one case is standard: `%%' outputs a `%' into the
2736 assembler code. Other nonstandard cases can be defined in the
2737 `PRINT_OPERAND' macro. You must also define which punctuation characters
2738 are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */
2741 frv_print_operand (FILE * file, rtx x, int code)
2743 struct frv_unspec unspec;
2744 HOST_WIDE_INT value;
2747 if (code != 0 && !isalpha (code))
2750 else if (GET_CODE (x) == CONST_INT)
2753 else if (GET_CODE (x) == CONST_DOUBLE)
2755 if (GET_MODE (x) == SFmode)
2760 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2761 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2765 else if (GET_MODE (x) == VOIDmode)
2766 value = CONST_DOUBLE_LOW (x);
2769 fatal_insn ("bad insn in frv_print_operand, bad const_double", x);
2780 fputs (reg_names[GPR_R0], file);
2784 fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn));
2788 /* Output small data area base register (gr16). */
2789 fputs (reg_names[SDA_BASE_REG], file);
2793 /* Output pic register (gr17). */
2794 fputs (reg_names[PIC_REGNO], file);
2798 /* Output the temporary integer CCR register. */
2799 fputs (reg_names[ICR_TEMP], file);
2803 /* Output the temporary integer CC register. */
2804 fputs (reg_names[ICC_TEMP], file);
2807 /* case 'a': print an address. */
2810 /* Print appropriate test for integer branch false operation. */
2811 fputs (comparison_string (reverse_condition (GET_CODE (x)),
2812 XEXP (x, 0)), file);
2816 /* Print appropriate test for integer branch true operation. */
2817 fputs (comparison_string (GET_CODE (x), XEXP (x, 0)), file);
2821 /* Print 1 for a NE and 0 for an EQ to give the final argument
2822 for a conditional instruction. */
2823 if (GET_CODE (x) == NE)
2826 else if (GET_CODE (x) == EQ)
2830 fatal_insn ("bad insn to frv_print_operand, 'e' modifier:", x);
2834 /* Print appropriate test for floating point branch false operation. */
2835 switch (GET_CODE (x))
2838 fatal_insn ("bad insn to frv_print_operand, 'F' modifier:", x);
2840 case EQ: fputs ("ne", file); break;
2841 case NE: fputs ("eq", file); break;
2842 case LT: fputs ("uge", file); break;
2843 case LE: fputs ("ug", file); break;
2844 case GT: fputs ("ule", file); break;
2845 case GE: fputs ("ul", file); break;
2850 /* Print appropriate test for floating point branch true operation. */
2851 switch (GET_CODE (x))
2854 fatal_insn ("bad insn to frv_print_operand, 'f' modifier:", x);
2856 case EQ: fputs ("eq", file); break;
2857 case NE: fputs ("ne", file); break;
2858 case LT: fputs ("lt", file); break;
2859 case LE: fputs ("le", file); break;
2860 case GT: fputs ("gt", file); break;
2861 case GE: fputs ("ge", file); break;
2866 /* Print appropriate GOT function. */
2867 if (GET_CODE (x) != CONST_INT)
2868 fatal_insn ("bad insn to frv_print_operand, 'g' modifier:", x);
2869 fputs (unspec_got_name (INTVAL (x)), file);
2873 /* Print 'i' if the operand is a constant, or is a memory reference that
2875 if (GET_CODE (x) == MEM)
2876 x = ((GET_CODE (XEXP (x, 0)) == PLUS)
2877 ? XEXP (XEXP (x, 0), 1)
2879 else if (GET_CODE (x) == PLUS)
2882 switch (GET_CODE (x))
2896 /* For jump instructions, print 'i' if the operand is a constant or
2897 is an expression that adds a constant. */
2898 if (GET_CODE (x) == CONST_INT)
2903 if (GET_CODE (x) == CONST_INT
2904 || (GET_CODE (x) == PLUS
2905 && (GET_CODE (XEXP (x, 1)) == CONST_INT
2906 || GET_CODE (XEXP (x, 0)) == CONST_INT)))
2912 /* Print the lower register of a double word register pair */
2913 if (GET_CODE (x) == REG)
2914 fputs (reg_names[ REGNO (x)+1 ], file);
2916 fatal_insn ("bad insn to frv_print_operand, 'L' modifier:", x);
2919 /* case 'l': print a LABEL_REF. */
2923 /* Print a memory reference for ld/st/jmp, %N prints a memory reference
2924 for the second word of double memory operations. */
2925 offset = (code == 'M') ? 0 : UNITS_PER_WORD;
2926 switch (GET_CODE (x))
2929 fatal_insn ("bad insn to frv_print_operand, 'M/N' modifier:", x);
2932 frv_print_operand_memory_reference (file, XEXP (x, 0), offset);
2940 frv_print_operand_memory_reference (file, x, offset);
2946 /* Print the opcode of a command. */
2947 switch (GET_CODE (x))
2950 fatal_insn ("bad insn to frv_print_operand, 'O' modifier:", x);
2952 case PLUS: fputs ("add", file); break;
2953 case MINUS: fputs ("sub", file); break;
2954 case AND: fputs ("and", file); break;
2955 case IOR: fputs ("or", file); break;
2956 case XOR: fputs ("xor", file); break;
2957 case ASHIFT: fputs ("sll", file); break;
2958 case ASHIFTRT: fputs ("sra", file); break;
2959 case LSHIFTRT: fputs ("srl", file); break;
2963 /* case 'n': negate and print a constant int. */
2966 /* Print PIC label using operand as the number. */
2967 if (GET_CODE (x) != CONST_INT)
2968 fatal_insn ("bad insn to frv_print_operand, P modifier:", x);
2970 fprintf (file, ".LCF%ld", (long)INTVAL (x));
2974 /* Print 'u' if the operand is a update load/store. */
2975 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
2980 /* If value is 0, print gr0, otherwise it must be a register. */
2981 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
2982 fputs (reg_names[GPR_R0], file);
2984 else if (GET_CODE (x) == REG)
2985 fputs (reg_names [REGNO (x)], file);
2988 fatal_insn ("bad insn in frv_print_operand, z case", x);
2992 /* Print constant in hex. */
2993 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2995 fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value);
3002 if (GET_CODE (x) == REG)
3003 fputs (reg_names [REGNO (x)], file);
3005 else if (GET_CODE (x) == CONST_INT
3006 || GET_CODE (x) == CONST_DOUBLE)
3007 fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value);
3009 else if (frv_const_unspec_p (x, &unspec))
3010 frv_output_const_unspec (file, &unspec);
3012 else if (GET_CODE (x) == MEM)
3013 frv_print_operand_address (file, XEXP (x, 0));
3015 else if (CONSTANT_ADDRESS_P (x))
3016 frv_print_operand_address (file, x);
3019 fatal_insn ("bad insn in frv_print_operand, 0 case", x);
3024 fatal_insn ("frv_print_operand: unknown code", x);
3032 /* A C statement (sans semicolon) for initializing the variable CUM for the
3033 state at the beginning of the argument list. The variable has type
3034 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
3035 of the function which will receive the args, or 0 if the args are to a
3036 compiler support library function. The value of INDIRECT is nonzero when
3037 processing an indirect call, for example a call through a function pointer.
3038 The value of INDIRECT is zero for a call to an explicitly named function, a
3039 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
3040 arguments for the function being compiled.
3042 When processing a call to a compiler support library function, LIBNAME
3043 identifies which one. It is a `symbol_ref' rtx which contains the name of
3044 the function, as a string. LIBNAME is 0 when an ordinary C function call is
3045 being processed. Thus, each time this macro is called, either LIBNAME or
3046 FNTYPE is nonzero, but never both of them at once. */
3049 frv_init_cumulative_args (CUMULATIVE_ARGS *cum,
3055 *cum = FIRST_ARG_REGNUM;
3057 if (TARGET_DEBUG_ARG)
3059 fprintf (stderr, "\ninit_cumulative_args:");
3060 if (!fndecl && fntype)
3061 fputs (" indirect", stderr);
3064 fputs (" incoming", stderr);
3068 tree ret_type = TREE_TYPE (fntype);
3069 fprintf (stderr, " return=%s,",
3070 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3073 if (libname && GET_CODE (libname) == SYMBOL_REF)
3074 fprintf (stderr, " libname=%s", XSTR (libname, 0));
3076 if (cfun->returns_struct)
3077 fprintf (stderr, " return-struct");
3079 putc ('\n', stderr);
3084 /* Return true if we should pass an argument on the stack rather than
3088 frv_must_pass_in_stack (enum machine_mode mode, tree type)
3090 if (mode == BLKmode)
3094 return AGGREGATE_TYPE_P (type);
3097 /* If defined, a C expression that gives the alignment boundary, in bits, of an
3098 argument with the specified mode and type. If it is not defined,
3099 `PARM_BOUNDARY' is used for all arguments. */
3102 frv_function_arg_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
3103 tree type ATTRIBUTE_UNUSED)
3105 return BITS_PER_WORD;
3109 frv_function_arg (CUMULATIVE_ARGS *cum,
3110 enum machine_mode mode,
3111 tree type ATTRIBUTE_UNUSED,
3113 int incoming ATTRIBUTE_UNUSED)
3115 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3120 /* Return a marker for use in the call instruction. */
3121 if (xmode == VOIDmode)
3127 else if (arg_num <= LAST_ARG_REGNUM)
3129 ret = gen_rtx_REG (xmode, arg_num);
3130 debstr = reg_names[arg_num];
3139 if (TARGET_DEBUG_ARG)
3141 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n",
3142 arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr);
3148 /* A C statement (sans semicolon) to update the summarizer variable CUM to
3149 advance past an argument in the argument list. The values MODE, TYPE and
3150 NAMED describe that argument. Once this is done, the variable CUM is
3151 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
3153 This macro need not do anything if the argument in question was passed on
3154 the stack. The compiler knows how to track the amount of stack space used
3155 for arguments without any special help. */
3158 frv_function_arg_advance (CUMULATIVE_ARGS *cum,
3159 enum machine_mode mode,
3160 tree type ATTRIBUTE_UNUSED,
3163 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3164 int bytes = GET_MODE_SIZE (xmode);
3165 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3168 *cum = arg_num + words;
3170 if (TARGET_DEBUG_ARG)
3172 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n",
3173 arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD);
3177 /* A C expression for the number of words, at the beginning of an argument,
3178 must be put in registers. The value must be zero for arguments that are
3179 passed entirely in registers or that are entirely pushed on the stack.
3181 On some machines, certain arguments must be passed partially in registers
3182 and partially in memory. On these machines, typically the first N words of
3183 arguments are passed in registers, and the rest on the stack. If a
3184 multi-word argument (a `double' or a structure) crosses that boundary, its
3185 first few words must be passed in registers and the rest must be pushed.
3186 This macro tells the compiler when this occurs, and how many of the words
3187 should go in registers.
3189 `FUNCTION_ARG' for these arguments should return the first register to be
3190 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
3191 the called function. */
3194 frv_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3195 tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
3197 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3198 int bytes = GET_MODE_SIZE (xmode);
3199 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3203 ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1)
3204 ? LAST_ARG_REGNUM - arg_num + 1
3206 ret *= UNITS_PER_WORD;
3208 if (TARGET_DEBUG_ARG && ret)
3209 fprintf (stderr, "frv_arg_partial_bytes: %d\n", ret);
3215 /* Return true if a register is ok to use as a base or index register. */
3217 static FRV_INLINE int
3218 frv_regno_ok_for_base_p (int regno, int strict_p)
3224 return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno]));
3226 if (regno == ARG_POINTER_REGNUM)
3229 return (regno >= FIRST_PSEUDO_REGISTER);
3233 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3234 RTX) is a legitimate memory address on the target machine for a memory
3235 operand of mode MODE.
3237 It usually pays to define several simpler macros to serve as subroutines for
3238 this one. Otherwise it may be too complicated to understand.
3240 This macro must exist in two variants: a strict variant and a non-strict
3241 one. The strict variant is used in the reload pass. It must be defined so
3242 that any pseudo-register that has not been allocated a hard register is
3243 considered a memory reference. In contexts where some kind of register is
3244 required, a pseudo-register with no hard register must be rejected.
3246 The non-strict variant is used in other passes. It must be defined to
3247 accept all pseudo-registers in every context where some kind of register is
3250 Compiler source files that want to use the strict variant of this macro
3251 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3252 conditional to define the strict variant in that case and the non-strict
3255 Subroutines to check for acceptable registers for various purposes (one for
3256 base registers, one for index registers, and so on) are typically among the
3257 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3258 subroutine macros need have two variants; the higher levels of macros may be
3259 the same whether strict or not.
3261 Normally, constant addresses which are the sum of a `symbol_ref' and an
3262 integer are stored inside a `const' RTX to mark them as constant.
3263 Therefore, there is no need to recognize such sums specifically as
3264 legitimate addresses. Normally you would simply recognize any `const' as
3267 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3268 are not marked with `const'. It assumes that a naked `plus' indicates
3269 indexing. If so, then you *must* reject such naked constant sums as
3270 illegitimate addresses, so that none of them will be given to
3271 `PRINT_OPERAND_ADDRESS'.
3273 On some machines, whether a symbolic address is legitimate depends on the
3274 section that the address refers to. On these machines, define the macro
3275 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3276 then check for it here. When you see a `const', you will have to look
3277 inside it to find the `symbol_ref' in order to determine the section.
3279 The best way to modify the name string is by adding text to the beginning,
3280 with suitable punctuation to prevent any ambiguity. Allocate the new name
3281 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3282 remove and decode the added text and output the name accordingly, and define
3283 `(* targetm.strip_name_encoding)' to access the original name string.
3285 You can check the information stored here into the `symbol_ref' in the
3286 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3287 `PRINT_OPERAND_ADDRESS'. */
3290 frv_legitimate_address_p (enum machine_mode mode,
3294 int allow_double_reg_p)
3298 HOST_WIDE_INT value;
3301 if (FRV_SYMBOL_REF_TLS_P (x))
3304 switch (GET_CODE (x))
3311 if (GET_CODE (x) != REG)
3317 ret = frv_regno_ok_for_base_p (REGNO (x), strict_p);
3323 if (GET_CODE (x0) != REG
3324 || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p)
3325 || GET_CODE (x1) != PLUS
3326 || ! rtx_equal_p (x0, XEXP (x1, 0))
3327 || GET_CODE (XEXP (x1, 1)) != REG
3328 || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p))
3335 /* 12 bit immediate */
3340 ret = IN_RANGE_P (INTVAL (x), -2048, 2047);
3342 /* If we can't use load/store double operations, make sure we can
3343 address the second word. */
3344 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3345 ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1,
3354 if (GET_CODE (x0) == SUBREG)
3355 x0 = SUBREG_REG (x0);
3357 if (GET_CODE (x0) != REG)
3360 regno0 = REGNO (x0);
3361 if (!frv_regno_ok_for_base_p (regno0, strict_p))
3364 switch (GET_CODE (x1))
3370 x1 = SUBREG_REG (x1);
3371 if (GET_CODE (x1) != REG)
3377 /* Do not allow reg+reg addressing for modes > 1 word if we
3378 can't depend on having move double instructions. */
3379 if (!allow_double_reg_p && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3382 ret = frv_regno_ok_for_base_p (REGNO (x1), strict_p);
3386 /* 12 bit immediate */
3391 value = INTVAL (x1);
3392 ret = IN_RANGE_P (value, -2048, 2047);
3394 /* If we can't use load/store double operations, make sure we can
3395 address the second word. */
3396 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3397 ret = IN_RANGE_P (value + GET_MODE_SIZE (mode) - 1, -2048, 2047);
3402 if (!condexec_p && got12_operand (x1, VOIDmode))
3410 if (TARGET_DEBUG_ADDR)
3412 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict%s\n",
3413 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ",
3414 (condexec_p) ? ", inside conditional code" : "");
3421 /* Given an ADDR, generate code to inline the PLT. */
3423 gen_inlined_tls_plt (rtx addr)
3426 rtx picreg = get_hard_reg_initial_val (Pmode, FDPIC_REG);
3429 dest = gen_reg_rtx (DImode);
3436 lddi.p @(gr15, #gottlsdesc12(ADDR)), gr8
3437 calll #gettlsoff(ADDR)@(gr8, gr0)
3439 emit_insn (gen_tls_lddi (dest, addr, picreg));