1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007,
2 2008 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 3, 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 COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
28 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-flags.h"
34 #include "insn-attr.h"
44 #include "basic-block.h"
49 #include "target-def.h"
50 #include "targhooks.h"
51 #include "integrate.h"
52 #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 /* Information about one __builtin_read or __builtin_write access, or
113 the combination of several such accesses. The most general value
114 is all-zeros (an unknown access to an unknown address). */
116 /* The type of access. FRV_IO_UNKNOWN means the access can be either
117 a read or a write. */
118 enum { FRV_IO_UNKNOWN, FRV_IO_READ, FRV_IO_WRITE } type;
120 /* The constant address being accessed, or zero if not known. */
121 HOST_WIDE_INT const_address;
123 /* The run-time address, as used in operand 0 of the membar pattern. */
127 /* Return true if instruction INSN should be packed with the following
129 #define PACKING_FLAG_P(INSN) (GET_MODE (INSN) == TImode)
131 /* Set the value of PACKING_FLAG_P(INSN). */
132 #define SET_PACKING_FLAG(INSN) PUT_MODE (INSN, TImode)
133 #define CLEAR_PACKING_FLAG(INSN) PUT_MODE (INSN, VOIDmode)
135 /* Loop with REG set to each hard register in rtx X. */
136 #define FOR_EACH_REGNO(REG, X) \
137 for (REG = REGNO (X); \
138 REG < REGNO (X) + HARD_REGNO_NREGS (REGNO (X), GET_MODE (X)); \
141 /* This structure contains machine specific function data. */
142 struct GTY(()) machine_function
144 /* True if we have created an rtx that relies on the stack frame. */
147 /* True if this function contains at least one __builtin_{read,write}*. */
151 /* Temporary register allocation support structure. */
152 typedef struct frv_tmp_reg_struct
154 HARD_REG_SET regs; /* possible registers to allocate */
155 int next_reg[N_REG_CLASSES]; /* next register to allocate per class */
159 /* Register state information for VLIW re-packing phase. */
160 #define REGSTATE_CC_MASK 0x07 /* Mask to isolate CCn for cond exec */
161 #define REGSTATE_MODIFIED 0x08 /* reg modified in current VLIW insn */
162 #define REGSTATE_IF_TRUE 0x10 /* reg modified in cond exec true */
163 #define REGSTATE_IF_FALSE 0x20 /* reg modified in cond exec false */
165 #define REGSTATE_IF_EITHER (REGSTATE_IF_TRUE | REGSTATE_IF_FALSE)
167 typedef unsigned char regstate_t;
169 /* Used in frv_frame_accessor_t to indicate the direction of a register-to-
177 /* Information required by frv_frame_access. */
180 /* This field is FRV_LOAD if registers are to be loaded from the stack and
181 FRV_STORE if they should be stored onto the stack. FRV_STORE implies
182 the move is being done by the prologue code while FRV_LOAD implies it
183 is being done by the epilogue. */
184 enum frv_stack_op op;
186 /* The base register to use when accessing the stack. This may be the
187 frame pointer, stack pointer, or a temporary. The choice of register
188 depends on which part of the frame is being accessed and how big the
192 /* The offset of BASE from the bottom of the current frame, in bytes. */
194 } frv_frame_accessor_t;
196 /* Define the information needed to generate branch and scc insns. This is
197 stored from the compare operation. */
201 /* Conditional execution support gathered together in one structure. */
204 /* Linked list of insns to add if the conditional execution conversion was
205 successful. Each link points to an EXPR_LIST which points to the pattern
206 of the insn to add, and the insn to be inserted before. */
207 rtx added_insns_list;
209 /* Identify which registers are safe to allocate for if conversions to
210 conditional execution. We keep the last allocated register in the
211 register classes between COND_EXEC statements. This will mean we allocate
212 different registers for each different COND_EXEC group if we can. This
213 might allow the scheduler to intermix two different COND_EXEC sections. */
214 frv_tmp_reg_t tmp_reg;
216 /* For nested IFs, identify which CC registers are used outside of setting
217 via a compare isnsn, and using via a check insn. This will allow us to
218 know if we can rewrite the register to use a different register that will
219 be paired with the CR register controlling the nested IF-THEN blocks. */
220 HARD_REG_SET nested_cc_ok_rewrite;
222 /* Temporary registers allocated to hold constants during conditional
224 rtx scratch_regs[FIRST_PSEUDO_REGISTER];
226 /* Current number of temp registers available. */
227 int cur_scratch_regs;
229 /* Number of nested conditional execution blocks. */
230 int num_nested_cond_exec;
232 /* Map of insns that set up constants in scratch registers. */
233 bitmap scratch_insns_bitmap;
235 /* Conditional execution test register (CC0..CC7). */
238 /* Conditional execution compare register that is paired with cr_reg, so that
239 nested compares can be done. The csubcc and caddcc instructions don't
240 have enough bits to specify both a CC register to be set and a CR register
241 to do the test on, so the same bit number is used for both. Needless to
242 say, this is rather inconvenient for GCC. */
245 /* Extra CR registers used for &&, ||. */
249 /* Previous CR used in nested if, to make sure we are dealing with the same
250 nested if as the previous statement. */
251 rtx last_nested_if_cr;
255 static /* GTY(()) */ frv_ifcvt_t frv_ifcvt;
257 /* Map register number to smallest register class. */
258 enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER];
260 /* Map class letter into register class. */
261 enum reg_class reg_class_from_letter[256];
263 /* Cached value of frv_stack_info. */
264 static frv_stack_t *frv_stack_cache = (frv_stack_t *)0;
267 frv_cpu_t frv_cpu_type = CPU_TYPE; /* value of -mcpu= */
269 /* Forward references */
271 static bool frv_handle_option (size_t, const char *, int);
272 static int frv_default_flags_for_cpu (void);
273 static int frv_string_begins_with (const_tree, const char *);
274 static FRV_INLINE bool frv_small_data_reloc_p (rtx, int);
275 static void frv_print_operand_memory_reference_reg
277 static void frv_print_operand_memory_reference (FILE *, rtx, int);
278 static int frv_print_operand_jump_hint (rtx);
279 static const char *comparison_string (enum rtx_code, rtx);
280 static FRV_INLINE int frv_regno_ok_for_base_p (int, int);
281 static rtx single_set_pattern (rtx);
282 static int frv_function_contains_far_jump (void);
283 static rtx frv_alloc_temp_reg (frv_tmp_reg_t *,
287 static rtx frv_frame_offset_rtx (int);
288 static rtx frv_frame_mem (enum machine_mode, rtx, int);
289 static rtx frv_dwarf_store (rtx, int);
290 static void frv_frame_insn (rtx, rtx);
291 static void frv_frame_access (frv_frame_accessor_t*,
293 static void frv_frame_access_multi (frv_frame_accessor_t*,
295 static void frv_frame_access_standard_regs (enum frv_stack_op,
297 static struct machine_function *frv_init_machine_status (void);
298 static rtx frv_int_to_acc (enum insn_code, int, rtx);
299 static enum machine_mode frv_matching_accg_mode (enum machine_mode);
300 static rtx frv_read_argument (tree, unsigned int);
301 static rtx frv_read_iacc_argument (enum machine_mode, tree, unsigned int);
302 static int frv_check_constant_argument (enum insn_code, int, rtx);
303 static rtx frv_legitimize_target (enum insn_code, rtx);
304 static rtx frv_legitimize_argument (enum insn_code, int, rtx);
305 static rtx frv_legitimize_tls_address (rtx, enum tls_model);
306 static rtx frv_expand_set_builtin (enum insn_code, tree, rtx);
307 static rtx frv_expand_unop_builtin (enum insn_code, tree, rtx);
308 static rtx frv_expand_binop_builtin (enum insn_code, tree, rtx);
309 static rtx frv_expand_cut_builtin (enum insn_code, tree, rtx);
310 static rtx frv_expand_binopimm_builtin (enum insn_code, tree, rtx);
311 static rtx frv_expand_voidbinop_builtin (enum insn_code, tree);
312 static rtx frv_expand_int_void2arg (enum insn_code, tree);
313 static rtx frv_expand_prefetches (enum insn_code, tree);
314 static rtx frv_expand_voidtriop_builtin (enum insn_code, tree);
315 static rtx frv_expand_voidaccop_builtin (enum insn_code, tree);
316 static rtx frv_expand_mclracc_builtin (tree);
317 static rtx frv_expand_mrdacc_builtin (enum insn_code, tree);
318 static rtx frv_expand_mwtacc_builtin (enum insn_code, tree);
319 static rtx frv_expand_noargs_builtin (enum insn_code);
320 static void frv_split_iacc_move (rtx, rtx);
321 static rtx frv_emit_comparison (enum rtx_code, rtx, rtx);
322 static int frv_clear_registers_used (rtx *, void *);
323 static void frv_ifcvt_add_insn (rtx, rtx, int);
324 static rtx frv_ifcvt_rewrite_mem (rtx, enum machine_mode, rtx);
325 static rtx frv_ifcvt_load_value (rtx, rtx);
326 static int frv_acc_group_1 (rtx *, void *);
327 static unsigned int frv_insn_unit (rtx);
328 static bool frv_issues_to_branch_unit_p (rtx);
329 static int frv_cond_flags (rtx);
330 static bool frv_regstate_conflict_p (regstate_t, regstate_t);
331 static int frv_registers_conflict_p_1 (rtx *, void *);
332 static bool frv_registers_conflict_p (rtx);
333 static void frv_registers_update_1 (rtx, const_rtx, void *);
334 static void frv_registers_update (rtx);
335 static void frv_start_packet (void);
336 static void frv_start_packet_block (void);
337 static void frv_finish_packet (void (*) (void));
338 static bool frv_pack_insn_p (rtx);
339 static void frv_add_insn_to_packet (rtx);
340 static void frv_insert_nop_in_packet (rtx);
341 static bool frv_for_each_packet (void (*) (void));
342 static bool frv_sort_insn_group_1 (enum frv_insn_group,
343 unsigned int, unsigned int,
344 unsigned int, unsigned int,
346 static int frv_compare_insns (const void *, const void *);
347 static void frv_sort_insn_group (enum frv_insn_group);
348 static void frv_reorder_packet (void);
349 static void frv_fill_unused_units (enum frv_insn_group);
350 static void frv_align_label (void);
351 static void frv_reorg_packet (void);
352 static void frv_register_nop (rtx);
353 static void frv_reorg (void);
354 static void frv_pack_insns (void);
355 static void frv_function_prologue (FILE *, HOST_WIDE_INT);
356 static void frv_function_epilogue (FILE *, HOST_WIDE_INT);
357 static bool frv_assemble_integer (rtx, unsigned, int);
358 static void frv_init_builtins (void);
359 static rtx frv_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
360 static void frv_init_libfuncs (void);
361 static bool frv_in_small_data_p (const_tree);
362 static void frv_asm_output_mi_thunk
363 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
364 static void frv_setup_incoming_varargs (CUMULATIVE_ARGS *,
367 static rtx frv_expand_builtin_saveregs (void);
368 static void frv_expand_builtin_va_start (tree, rtx);
369 static bool frv_rtx_costs (rtx, int, int, int*, bool);
370 static void frv_asm_out_constructor (rtx, int);
371 static void frv_asm_out_destructor (rtx, int);
372 static bool frv_function_symbol_referenced_p (rtx);
373 static bool frv_cannot_force_const_mem (rtx);
374 static const char *unspec_got_name (int);
375 static void frv_output_const_unspec (FILE *,
376 const struct frv_unspec *);
377 static bool frv_function_ok_for_sibcall (tree, tree);
378 static rtx frv_struct_value_rtx (tree, int);
379 static bool frv_must_pass_in_stack (enum machine_mode mode, const_tree type);
380 static int frv_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
382 static void frv_output_dwarf_dtprel (FILE *, int, rtx)
384 static bool frv_secondary_reload (bool, rtx, enum reg_class,
386 secondary_reload_info *);
388 /* Allow us to easily change the default for -malloc-cc. */
389 #ifndef DEFAULT_NO_ALLOC_CC
390 #define MASK_DEFAULT_ALLOC_CC MASK_ALLOC_CC
392 #define MASK_DEFAULT_ALLOC_CC 0
395 /* Initialize the GCC target structure. */
396 #undef TARGET_ASM_FUNCTION_PROLOGUE
397 #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue
398 #undef TARGET_ASM_FUNCTION_EPILOGUE
399 #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue
400 #undef TARGET_ASM_INTEGER
401 #define TARGET_ASM_INTEGER frv_assemble_integer
402 #undef TARGET_DEFAULT_TARGET_FLAGS
403 #define TARGET_DEFAULT_TARGET_FLAGS \
404 (MASK_DEFAULT_ALLOC_CC \
411 #undef TARGET_HANDLE_OPTION
412 #define TARGET_HANDLE_OPTION frv_handle_option
413 #undef TARGET_INIT_BUILTINS
414 #define TARGET_INIT_BUILTINS frv_init_builtins
415 #undef TARGET_EXPAND_BUILTIN
416 #define TARGET_EXPAND_BUILTIN frv_expand_builtin
417 #undef TARGET_INIT_LIBFUNCS
418 #define TARGET_INIT_LIBFUNCS frv_init_libfuncs
419 #undef TARGET_IN_SMALL_DATA_P
420 #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p
421 #undef TARGET_RTX_COSTS
422 #define TARGET_RTX_COSTS frv_rtx_costs
423 #undef TARGET_ASM_CONSTRUCTOR
424 #define TARGET_ASM_CONSTRUCTOR frv_asm_out_constructor
425 #undef TARGET_ASM_DESTRUCTOR
426 #define TARGET_ASM_DESTRUCTOR frv_asm_out_destructor
428 #undef TARGET_ASM_OUTPUT_MI_THUNK
429 #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk
430 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
431 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
433 #undef TARGET_SCHED_ISSUE_RATE
434 #define TARGET_SCHED_ISSUE_RATE frv_issue_rate
436 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
437 #define TARGET_FUNCTION_OK_FOR_SIBCALL frv_function_ok_for_sibcall
438 #undef TARGET_CANNOT_FORCE_CONST_MEM
439 #define TARGET_CANNOT_FORCE_CONST_MEM frv_cannot_force_const_mem
441 #undef TARGET_HAVE_TLS
442 #define TARGET_HAVE_TLS HAVE_AS_TLS
444 #undef TARGET_STRUCT_VALUE_RTX
445 #define TARGET_STRUCT_VALUE_RTX frv_struct_value_rtx
446 #undef TARGET_MUST_PASS_IN_STACK
447 #define TARGET_MUST_PASS_IN_STACK frv_must_pass_in_stack
448 #undef TARGET_PASS_BY_REFERENCE
449 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
450 #undef TARGET_ARG_PARTIAL_BYTES
451 #define TARGET_ARG_PARTIAL_BYTES frv_arg_partial_bytes
453 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
454 #define TARGET_EXPAND_BUILTIN_SAVEREGS frv_expand_builtin_saveregs
455 #undef TARGET_SETUP_INCOMING_VARARGS
456 #define TARGET_SETUP_INCOMING_VARARGS frv_setup_incoming_varargs
457 #undef TARGET_MACHINE_DEPENDENT_REORG
458 #define TARGET_MACHINE_DEPENDENT_REORG frv_reorg
460 #undef TARGET_EXPAND_BUILTIN_VA_START
461 #define TARGET_EXPAND_BUILTIN_VA_START frv_expand_builtin_va_start
464 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
465 #define TARGET_ASM_OUTPUT_DWARF_DTPREL frv_output_dwarf_dtprel
468 #undef TARGET_SECONDARY_RELOAD
469 #define TARGET_SECONDARY_RELOAD frv_secondary_reload
471 struct gcc_target targetm = TARGET_INITIALIZER;
473 #define FRV_SYMBOL_REF_TLS_P(RTX) \
474 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
477 /* Any function call that satisfies the machine-independent
478 requirements is eligible on FR-V. */
481 frv_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
482 tree exp ATTRIBUTE_UNUSED)
487 /* Return true if SYMBOL is a small data symbol and relocation RELOC
488 can be used to access it directly in a load or store. */
490 static FRV_INLINE bool
491 frv_small_data_reloc_p (rtx symbol, int reloc)
493 return (GET_CODE (symbol) == SYMBOL_REF
494 && SYMBOL_REF_SMALL_P (symbol)
495 && (!TARGET_FDPIC || flag_pic == 1)
496 && (reloc == R_FRV_GOTOFF12 || reloc == R_FRV_GPREL12));
499 /* Return true if X is a valid relocation unspec. If it is, fill in UNSPEC
503 frv_const_unspec_p (rtx x, struct frv_unspec *unspec)
505 if (GET_CODE (x) == CONST)
509 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
511 unspec->offset += INTVAL (XEXP (x, 1));
514 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_GOT)
516 unspec->symbol = XVECEXP (x, 0, 0);
517 unspec->reloc = INTVAL (XVECEXP (x, 0, 1));
519 if (unspec->offset == 0)
522 if (frv_small_data_reloc_p (unspec->symbol, unspec->reloc)
523 && unspec->offset > 0
524 && (unsigned HOST_WIDE_INT) unspec->offset < g_switch_value)
531 /* Decide whether we can force certain constants to memory. If we
532 decide we can't, the caller should be able to cope with it in
535 We never allow constants to be forced into memory for TARGET_FDPIC.
536 This is necessary for several reasons:
538 1. Since LEGITIMATE_CONSTANT_P rejects constant pool addresses, the
539 target-independent code will try to force them into the constant
540 pool, thus leading to infinite recursion.
542 2. We can never introduce new constant pool references during reload.
543 Any such reference would require use of the pseudo FDPIC register.
545 3. We can't represent a constant added to a function pointer (which is
546 not the same as a pointer to a function+constant).
548 4. In many cases, it's more efficient to calculate the constant in-line. */
551 frv_cannot_force_const_mem (rtx x ATTRIBUTE_UNUSED)
556 /* Implement TARGET_HANDLE_OPTION. */
559 frv_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
564 if (strcmp (arg, "simple") == 0)
565 frv_cpu_type = FRV_CPU_SIMPLE;
566 else if (strcmp (arg, "tomcat") == 0)
567 frv_cpu_type = FRV_CPU_TOMCAT;
568 else if (strcmp (arg, "fr550") == 0)
569 frv_cpu_type = FRV_CPU_FR550;
570 else if (strcmp (arg, "fr500") == 0)
571 frv_cpu_type = FRV_CPU_FR500;
572 else if (strcmp (arg, "fr450") == 0)
573 frv_cpu_type = FRV_CPU_FR450;
574 else if (strcmp (arg, "fr405") == 0)
575 frv_cpu_type = FRV_CPU_FR405;
576 else if (strcmp (arg, "fr400") == 0)
577 frv_cpu_type = FRV_CPU_FR400;
578 else if (strcmp (arg, "fr300") == 0)
579 frv_cpu_type = FRV_CPU_FR300;
580 else if (strcmp (arg, "frv") == 0)
581 frv_cpu_type = FRV_CPU_GENERIC;
592 frv_default_flags_for_cpu (void)
594 switch (frv_cpu_type)
596 case FRV_CPU_GENERIC:
597 return MASK_DEFAULT_FRV;
600 return MASK_DEFAULT_FR550;
604 return MASK_DEFAULT_FR500;
607 return MASK_DEFAULT_FR450;
611 return MASK_DEFAULT_FR400;
615 return MASK_DEFAULT_SIMPLE;
622 /* Sometimes certain combinations of command options do not make
623 sense on a particular target machine. You can define a macro
624 `OVERRIDE_OPTIONS' to take account of this. This macro, if
625 defined, is executed once just after all the command options have
628 Don't use this macro to turn on various extra optimizations for
629 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
632 frv_override_options (void)
637 target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit);
639 /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the
640 linker about linking pic and non-pic code. */
643 if (!flag_pic) /* -fPIC */
646 if (! g_switch_set) /* -G0 */
653 /* A C expression whose value is a register class containing hard
654 register REGNO. In general there is more than one such class;
655 choose a class which is "minimal", meaning that no smaller class
656 also contains the register. */
658 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
660 enum reg_class rclass;
664 int gpr_reg = regno - GPR_FIRST;
666 if (gpr_reg == GR8_REG)
669 else if (gpr_reg == GR9_REG)
672 else if (gpr_reg == GR14_REG)
673 rclass = FDPIC_FPTR_REGS;
675 else if (gpr_reg == FDPIC_REGNO)
678 else if ((gpr_reg & 3) == 0)
681 else if ((gpr_reg & 1) == 0)
688 else if (FPR_P (regno))
690 int fpr_reg = regno - GPR_FIRST;
691 if ((fpr_reg & 3) == 0)
692 rclass = QUAD_FPR_REGS;
694 else if ((fpr_reg & 1) == 0)
701 else if (regno == LR_REGNO)
704 else if (regno == LCR_REGNO)
707 else if (ICC_P (regno))
710 else if (FCC_P (regno))
713 else if (ICR_P (regno))
716 else if (FCR_P (regno))
719 else if (ACC_P (regno))
721 int r = regno - ACC_FIRST;
723 rclass = QUAD_ACC_REGS;
724 else if ((r & 1) == 0)
725 rclass = EVEN_ACC_REGS;
730 else if (ACCG_P (regno))
736 regno_reg_class[regno] = rclass;
739 /* Check for small data option */
741 g_switch_value = SDATA_DEFAULT_SIZE;
743 /* A C expression which defines the machine-dependent operand
744 constraint letters for register classes. If CHAR is such a
745 letter, the value should be the register class corresponding to
746 it. Otherwise, the value should be `NO_REGS'. The register
747 letter `r', corresponding to class `GENERAL_REGS', will not be
748 passed to this macro; you do not need to handle it.
750 The following letters are unavailable, due to being used as
755 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
756 'Q', 'R', 'S', 'T', 'U'
758 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
760 for (i = 0; i < 256; i++)
761 reg_class_from_letter[i] = NO_REGS;
763 reg_class_from_letter['a'] = ACC_REGS;
764 reg_class_from_letter['b'] = EVEN_ACC_REGS;
765 reg_class_from_letter['c'] = CC_REGS;
766 reg_class_from_letter['d'] = GPR_REGS;
767 reg_class_from_letter['e'] = EVEN_REGS;
768 reg_class_from_letter['f'] = FPR_REGS;
769 reg_class_from_letter['h'] = FEVEN_REGS;
770 reg_class_from_letter['l'] = LR_REG;
771 reg_class_from_letter['q'] = QUAD_REGS;
772 reg_class_from_letter['t'] = ICC_REGS;
773 reg_class_from_letter['u'] = FCC_REGS;
774 reg_class_from_letter['v'] = ICR_REGS;
775 reg_class_from_letter['w'] = FCR_REGS;
776 reg_class_from_letter['x'] = QUAD_FPR_REGS;
777 reg_class_from_letter['y'] = LCR_REG;
778 reg_class_from_letter['z'] = SPR_REGS;
779 reg_class_from_letter['A'] = QUAD_ACC_REGS;
780 reg_class_from_letter['B'] = ACCG_REGS;
781 reg_class_from_letter['C'] = CR_REGS;
782 reg_class_from_letter['W'] = FDPIC_CALL_REGS; /* gp14+15 */
783 reg_class_from_letter['Z'] = FDPIC_REGS; /* gp15 */
785 /* There is no single unaligned SI op for PIC code. Sometimes we
786 need to use ".4byte" and sometimes we need to use ".picptr".
787 See frv_assemble_integer for details. */
788 if (flag_pic || TARGET_FDPIC)
789 targetm.asm_out.unaligned_op.si = 0;
791 if ((target_flags_explicit & MASK_LINKED_FP) == 0)
792 target_flags |= MASK_LINKED_FP;
794 if ((target_flags_explicit & MASK_OPTIMIZE_MEMBAR) == 0)
795 target_flags |= MASK_OPTIMIZE_MEMBAR;
797 for (i = 0; i < ARRAY_SIZE (frv_unit_names); i++)
798 frv_unit_codes[i] = get_cpu_unit_code (frv_unit_names[i]);
800 for (i = 0; i < ARRAY_SIZE (frv_type_to_unit); i++)
801 frv_type_to_unit[i] = ARRAY_SIZE (frv_unit_codes);
803 init_machine_status = frv_init_machine_status;
807 /* Some machines may desire to change what optimizations are performed for
808 various optimization levels. This macro, if defined, is executed once just
809 after the optimization level is determined and before the remainder of the
810 command options have been parsed. Values set in this macro are used as the
811 default values for the other command line options.
813 LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if
814 `-O' is specified, and 0 if neither is specified.
816 SIZE is nonzero if `-Os' is specified, 0 otherwise.
818 You should not use this macro to change options that are not
819 machine-specific. These should uniformly selected by the same optimization
820 level on all supported machines. Use this macro to enable machine-specific
823 *Do not examine `write_symbols' in this macro!* The debugging options are
824 *not supposed to alter the generated code. */
826 /* On the FRV, possibly disable VLIW packing which is done by the 2nd
827 scheduling pass at the current time. */
829 frv_optimization_options (int level, int size ATTRIBUTE_UNUSED)
833 #ifdef DISABLE_SCHED2
834 flag_schedule_insns_after_reload = 0;
843 /* Return true if NAME (a STRING_CST node) begins with PREFIX. */
846 frv_string_begins_with (const_tree name, const char *prefix)
848 const int prefix_len = strlen (prefix);
850 /* Remember: NAME's length includes the null terminator. */
851 return (TREE_STRING_LENGTH (name) > prefix_len
852 && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0);
855 /* Zero or more C statements that may conditionally modify two variables
856 `fixed_regs' and `call_used_regs' (both of type `char []') after they have
857 been initialized from the two preceding macros.
859 This is necessary in case the fixed or call-clobbered registers depend on
862 You need not define this macro if it has no work to do.
864 If the usage of an entire class of registers depends on the target flags,
865 you may indicate this to GCC by using this macro to modify `fixed_regs' and
866 `call_used_regs' to 1 for each of the registers in the classes which should
867 not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return
868 `NO_REGS' if it is called with a letter for a class that shouldn't be used.
870 (However, if this class is not included in `GENERAL_REGS' and all of the
871 insn patterns whose constraints permit this class are controlled by target
872 switches, then GCC will automatically avoid using these registers when the
873 target switches are opposed to them.) */
876 frv_conditional_register_usage (void)
880 for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++)
881 fixed_regs[i] = call_used_regs[i] = 1;
883 for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++)
884 fixed_regs[i] = call_used_regs[i] = 1;
886 /* Reserve the registers used for conditional execution. At present, we need
887 1 ICC and 1 ICR register. */
888 fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1;
889 fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1;
893 fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1;
894 fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1;
895 fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1;
896 fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1;
900 fixed_regs[GPR_FIRST + 16] = fixed_regs[GPR_FIRST + 17] =
901 call_used_regs[GPR_FIRST + 16] = call_used_regs[GPR_FIRST + 17] = 0;
904 /* If -fpic, SDA_BASE_REG is the PIC register. */
905 if (g_switch_value == 0 && !flag_pic)
906 fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0;
909 fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0;
915 * Compute the stack frame layout
918 * +---------------+-----------------------+-----------------------+
919 * |Register |type |caller-save/callee-save|
920 * +---------------+-----------------------+-----------------------+
921 * |GR0 |Zero register | - |
922 * |GR1 |Stack pointer(SP) | - |
923 * |GR2 |Frame pointer(FP) | - |
924 * |GR3 |Hidden parameter | caller save |
925 * |GR4-GR7 | - | caller save |
926 * |GR8-GR13 |Argument register | caller save |
927 * |GR14-GR15 | - | caller save |
928 * |GR16-GR31 | - | callee save |
929 * |GR32-GR47 | - | caller save |
930 * |GR48-GR63 | - | callee save |
931 * |FR0-FR15 | - | caller save |
932 * |FR16-FR31 | - | callee save |
933 * |FR32-FR47 | - | caller save |
934 * |FR48-FR63 | - | callee save |
935 * +---------------+-----------------------+-----------------------+
939 * SP-> |-----------------------------------|
941 * |-----------------------------------|
942 * | Register save area |
943 * |-----------------------------------|
944 * | Local variable save area |
945 * FP-> |-----------------------------------|
947 * |-----------------------------------|
948 * | Hidden parameter save area |
949 * |-----------------------------------|
950 * | Return address(LR) storage area |
951 * |-----------------------------------|
952 * | Padding for alignment |
953 * |-----------------------------------|
954 * | Register argument area |
955 * OLD SP-> |-----------------------------------|
957 * |-----------------------------------|
960 * Argument area/Parameter area:
962 * When a function is called, this area is used for argument transfer. When
963 * the argument is set up by the caller function, this area is referred to as
964 * the argument area. When the argument is referenced by the callee function,
965 * this area is referred to as the parameter area. The area is allocated when
966 * all arguments cannot be placed on the argument register at the time of
969 * Register save area:
971 * This is a register save area that must be guaranteed for the caller
972 * function. This area is not secured when the register save operation is not
975 * Local variable save area:
977 * This is the area for local variables and temporary variables.
981 * This area stores the FP value of the caller function.
983 * Hidden parameter save area:
985 * This area stores the start address of the return value storage
986 * area for a struct/union return function.
987 * When a struct/union is used as the return value, the caller
988 * function stores the return value storage area start address in
989 * register GR3 and passes it to the caller function.
990 * The callee function interprets the address stored in the GR3
991 * as the return value storage area start address.
992 * When register GR3 needs to be saved into memory, the callee
993 * function saves it in the hidden parameter save area. This
994 * area is not secured when the save operation is not needed.
996 * Return address(LR) storage area:
998 * This area saves the LR. The LR stores the address of a return to the caller
999 * function for the purpose of function calling.
1001 * Argument register area:
1003 * This area saves the argument register. This area is not secured when the
1004 * save operation is not needed.
1008 * Arguments, the count of which equals the count of argument registers (6
1009 * words), are positioned in registers GR8 to GR13 and delivered to the callee
1010 * function. When a struct/union return function is called, the return value
1011 * area address is stored in register GR3. Arguments not placed in the
1012 * argument registers will be stored in the stack argument area for transfer
1013 * purposes. When an 8-byte type argument is to be delivered using registers,
1014 * it is divided into two and placed in two registers for transfer. When
1015 * argument registers must be saved to memory, the callee function secures an
1016 * argument register save area in the stack. In this case, a continuous
1017 * argument register save area must be established in the parameter area. The
1018 * argument register save area must be allocated as needed to cover the size of
1019 * the argument register to be saved. If the function has a variable count of
1020 * arguments, it saves all argument registers in the argument register save
1023 * Argument Extension Format:
1025 * When an argument is to be stored in the stack, its type is converted to an
1026 * extended type in accordance with the individual argument type. The argument
1027 * is freed by the caller function after the return from the callee function is
1030 * +-----------------------+---------------+------------------------+
1031 * | Argument Type |Extended Type |Stack Storage Size(byte)|
1032 * +-----------------------+---------------+------------------------+
1034 * |signed char |int | 4 |
1035 * |unsigned char |int | 4 |
1036 * |[signed] short int |int | 4 |
1037 * |unsigned short int |int | 4 |
1038 * |[signed] int |No extension | 4 |
1039 * |unsigned int |No extension | 4 |
1040 * |[signed] long int |No extension | 4 |
1041 * |unsigned long int |No extension | 4 |
1042 * |[signed] long long int |No extension | 8 |
1043 * |unsigned long long int |No extension | 8 |
1044 * |float |double | 8 |
1045 * |double |No extension | 8 |
1046 * |long double |No extension | 8 |
1047 * |pointer |No extension | 4 |
1048 * |struct/union |- | 4 (*1) |
1049 * +-----------------------+---------------+------------------------+
1051 * When a struct/union is to be delivered as an argument, the caller copies it
1052 * to the local variable area and delivers the address of that area.
1056 * +-------------------------------+----------------------+
1057 * |Return Value Type |Return Value Interface|
1058 * +-------------------------------+----------------------+
1060 * |[signed|unsigned] char |GR8 |
1061 * |[signed|unsigned] short int |GR8 |
1062 * |[signed|unsigned] int |GR8 |
1063 * |[signed|unsigned] long int |GR8 |
1065 * |[signed|unsigned] long long int|GR8 & GR9 |
1067 * |double |GR8 & GR9 |
1068 * |long double |GR8 & GR9 |
1069 * |struct/union |(*1) |
1070 * +-------------------------------+----------------------+
1072 * When a struct/union is used as the return value, the caller function stores
1073 * the start address of the return value storage area into GR3 and then passes
1074 * it to the callee function. The callee function interprets GR3 as the start
1075 * address of the return value storage area. When this address needs to be
1076 * saved in memory, the callee function secures the hidden parameter save area
1077 * and saves the address in that area.
1081 frv_stack_info (void)
1083 static frv_stack_t info, zero_info;
1084 frv_stack_t *info_ptr = &info;
1085 tree fndecl = current_function_decl;
1093 /* If we've already calculated the values and reload is complete,
1095 if (frv_stack_cache)
1096 return frv_stack_cache;
1098 /* Zero all fields. */
1101 /* Set up the register range information. */
1102 info_ptr->regs[STACK_REGS_GPR].name = "gpr";
1103 info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1;
1104 info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST;
1105 info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE;
1107 info_ptr->regs[STACK_REGS_FPR].name = "fpr";
1108 info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST;
1109 info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST;
1110 info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE;
1112 info_ptr->regs[STACK_REGS_LR].name = "lr";
1113 info_ptr->regs[STACK_REGS_LR].first = LR_REGNO;
1114 info_ptr->regs[STACK_REGS_LR].last = LR_REGNO;
1115 info_ptr->regs[STACK_REGS_LR].special_p = 1;
1117 info_ptr->regs[STACK_REGS_CC].name = "cc";
1118 info_ptr->regs[STACK_REGS_CC].first = CC_FIRST;
1119 info_ptr->regs[STACK_REGS_CC].last = CC_LAST;
1120 info_ptr->regs[STACK_REGS_CC].field_p = TRUE;
1122 info_ptr->regs[STACK_REGS_LCR].name = "lcr";
1123 info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO;
1124 info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO;
1126 info_ptr->regs[STACK_REGS_STDARG].name = "stdarg";
1127 info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM;
1128 info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM;
1129 info_ptr->regs[STACK_REGS_STDARG].dword_p = 1;
1130 info_ptr->regs[STACK_REGS_STDARG].special_p = 1;
1132 info_ptr->regs[STACK_REGS_STRUCT].name = "struct";
1133 info_ptr->regs[STACK_REGS_STRUCT].first = FRV_STRUCT_VALUE_REGNUM;
1134 info_ptr->regs[STACK_REGS_STRUCT].last = FRV_STRUCT_VALUE_REGNUM;
1135 info_ptr->regs[STACK_REGS_STRUCT].special_p = 1;
1137 info_ptr->regs[STACK_REGS_FP].name = "fp";
1138 info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM;
1139 info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM;
1140 info_ptr->regs[STACK_REGS_FP].special_p = 1;
1142 /* Determine if this is a stdarg function. If so, allocate space to store
1149 /* Find the last argument, and see if it is __builtin_va_alist. */
1150 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
1152 next_arg = TREE_CHAIN (cur_arg);
1153 if (next_arg == (tree)0)
1155 if (DECL_NAME (cur_arg)
1156 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
1164 /* Iterate over all of the register ranges. */
1165 for (range = 0; range < STACK_REGS_MAX; range++)
1167 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1168 int first = reg_ptr->first;
1169 int last = reg_ptr->last;
1171 int size_2words = 0;
1174 /* Calculate which registers need to be saved & save area size. */
1178 for (regno = first; regno <= last; regno++)
1180 if ((df_regs_ever_live_p (regno) && !call_used_regs[regno])
1181 || (crtl->calls_eh_return
1182 && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM))
1183 || (!TARGET_FDPIC && flag_pic
1184 && crtl->uses_pic_offset_table && regno == PIC_REGNO))
1186 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1187 size_1word += UNITS_PER_WORD;
1192 /* Calculate whether we need to create a frame after everything else
1193 has been processed. */
1198 if (df_regs_ever_live_p (LR_REGNO)
1200 /* This is set for __builtin_return_address, etc. */
1201 || cfun->machine->frame_needed
1202 || (TARGET_LINKED_FP && frame_pointer_needed)
1203 || (!TARGET_FDPIC && flag_pic
1204 && crtl->uses_pic_offset_table))
1206 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1207 size_1word += UNITS_PER_WORD;
1211 case STACK_REGS_STDARG:
1214 /* If this is a stdarg function with a non varardic
1215 argument split between registers and the stack,
1216 adjust the saved registers downward. */
1217 last -= (ADDR_ALIGN (crtl->args.pretend_args_size, UNITS_PER_WORD)
1220 for (regno = first; regno <= last; regno++)
1222 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1223 size_1word += UNITS_PER_WORD;
1226 info_ptr->stdarg_size = size_1word;
1230 case STACK_REGS_STRUCT:
1231 if (cfun->returns_struct)
1233 info_ptr->save_p[FRV_STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1234 size_1word += UNITS_PER_WORD;
1242 /* If this is a field, it only takes one word. */
1243 if (reg_ptr->field_p)
1244 size_1word = UNITS_PER_WORD;
1246 /* Determine which register pairs can be saved together. */
1247 else if (reg_ptr->dword_p && TARGET_DWORD)
1249 for (regno = first; regno < last; regno += 2)
1251 if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1])
1253 size_2words += 2 * UNITS_PER_WORD;
1254 size_1word -= 2 * UNITS_PER_WORD;
1255 info_ptr->save_p[regno] = REG_SAVE_2WORDS;
1256 info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE;
1261 reg_ptr->size_1word = size_1word;
1262 reg_ptr->size_2words = size_2words;
1264 if (! reg_ptr->special_p)
1266 info_ptr->regs_size_1word += size_1word;
1267 info_ptr->regs_size_2words += size_2words;
1272 /* Set up the sizes of each each field in the frame body, making the sizes
1273 of each be divisible by the size of a dword if dword operations might
1274 be used, or the size of a word otherwise. */
1275 alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD);
1277 info_ptr->parameter_size = ADDR_ALIGN (crtl->outgoing_args_size, alignment);
1278 info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words
1279 + info_ptr->regs_size_1word,
1281 info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment);
1283 info_ptr->pretend_size = crtl->args.pretend_args_size;
1285 /* Work out the size of the frame, excluding the header. Both the frame
1286 body and register parameter area will be dword-aligned. */
1287 info_ptr->total_size
1288 = (ADDR_ALIGN (info_ptr->parameter_size
1289 + info_ptr->regs_size
1290 + info_ptr->vars_size,
1292 + ADDR_ALIGN (info_ptr->pretend_size
1293 + info_ptr->stdarg_size,
1294 2 * UNITS_PER_WORD));
1296 /* See if we need to create a frame at all, if so add header area. */
1297 if (info_ptr->total_size > 0
1298 || frame_pointer_needed
1299 || info_ptr->regs[STACK_REGS_LR].size_1word > 0
1300 || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0)
1302 offset = info_ptr->parameter_size;
1303 info_ptr->header_size = 4 * UNITS_PER_WORD;
1304 info_ptr->total_size += 4 * UNITS_PER_WORD;
1306 /* Calculate the offsets to save normal register pairs. */
1307 for (range = 0; range < STACK_REGS_MAX; range++)
1309 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1310 if (! reg_ptr->special_p)
1312 int first = reg_ptr->first;
1313 int last = reg_ptr->last;
1316 for (regno = first; regno <= last; regno++)
1317 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS
1318 && regno != FRAME_POINTER_REGNUM
1319 && (regno < FIRST_ARG_REGNUM
1320 || regno > LAST_ARG_REGNUM))
1322 info_ptr->reg_offset[regno] = offset;
1323 offset += 2 * UNITS_PER_WORD;
1328 /* Calculate the offsets to save normal single registers. */
1329 for (range = 0; range < STACK_REGS_MAX; range++)
1331 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1332 if (! reg_ptr->special_p)
1334 int first = reg_ptr->first;
1335 int last = reg_ptr->last;
1338 for (regno = first; regno <= last; regno++)
1339 if (info_ptr->save_p[regno] == REG_SAVE_1WORD
1340 && regno != FRAME_POINTER_REGNUM
1341 && (regno < FIRST_ARG_REGNUM
1342 || regno > LAST_ARG_REGNUM))
1344 info_ptr->reg_offset[regno] = offset;
1345 offset += UNITS_PER_WORD;
1350 /* Calculate the offset to save the local variables at. */
1351 offset = ADDR_ALIGN (offset, alignment);
1352 if (info_ptr->vars_size)
1354 info_ptr->vars_offset = offset;
1355 offset += info_ptr->vars_size;
1358 /* Align header to a dword-boundary. */
1359 offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD);
1361 /* Calculate the offsets in the fixed frame. */
1362 info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD;
1363 info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset;
1364 info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD;
1366 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1367 info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD;
1368 info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD;
1370 if (cfun->returns_struct)
1372 info_ptr->save_p[FRV_STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1373 info_ptr->reg_offset[FRV_STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD;
1374 info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD;
1377 /* Calculate the offsets to store the arguments passed in registers
1378 for stdarg functions. The register pairs are first and the single
1379 register if any is last. The register save area starts on a
1381 if (info_ptr->stdarg_size)
1383 int first = info_ptr->regs[STACK_REGS_STDARG].first;
1384 int last = info_ptr->regs[STACK_REGS_STDARG].last;
1387 /* Skip the header. */
1388 offset += 4 * UNITS_PER_WORD;
1389 for (regno = first; regno <= last; regno++)
1391 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS)
1393 info_ptr->reg_offset[regno] = offset;
1394 offset += 2 * UNITS_PER_WORD;
1396 else if (info_ptr->save_p[regno] == REG_SAVE_1WORD)
1398 info_ptr->reg_offset[regno] = offset;
1399 offset += UNITS_PER_WORD;
1405 if (reload_completed)
1406 frv_stack_cache = info_ptr;
1412 /* Print the information about the frv stack offsets, etc. when debugging. */
1415 frv_debug_stack (frv_stack_t *info)
1420 info = frv_stack_info ();
1422 fprintf (stderr, "\nStack information for function %s:\n",
1423 ((current_function_decl && DECL_NAME (current_function_decl))
1424 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1427 fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size);
1428 fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size);
1429 fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size);
1430 fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n",
1431 info->regs_size, info->regs_size_1word, info->regs_size_2words);
1433 fprintf (stderr, "\theader_size\t= %6d\n", info->header_size);
1434 fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size);
1435 fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset);
1436 fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset);
1438 for (range = 0; range < STACK_REGS_MAX; range++)
1440 frv_stack_regs_t *regs = &(info->regs[range]);
1441 if ((regs->size_1word + regs->size_2words) > 0)
1443 int first = regs->first;
1444 int last = regs->last;
1447 fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =",
1448 regs->name, regs->size_1word + regs->size_2words,
1449 regs->size_1word, regs->size_2words);
1451 for (regno = first; regno <= last; regno++)
1453 if (info->save_p[regno] == REG_SAVE_1WORD)
1454 fprintf (stderr, " %s (%d)", reg_names[regno],
1455 info->reg_offset[regno]);
1457 else if (info->save_p[regno] == REG_SAVE_2WORDS)
1458 fprintf (stderr, " %s-%s (%d)", reg_names[regno],
1459 reg_names[regno+1], info->reg_offset[regno]);
1462 fputc ('\n', stderr);
1472 /* Used during final to control the packing of insns. The value is
1473 1 if the current instruction should be packed with the next one,
1474 0 if it shouldn't or -1 if packing is disabled altogether. */
1476 static int frv_insn_packing_flag;
1478 /* True if the current function contains a far jump. */
1481 frv_function_contains_far_jump (void)
1483 rtx insn = get_insns ();
1485 && !(GET_CODE (insn) == JUMP_INSN
1486 /* Ignore tablejump patterns. */
1487 && GET_CODE (PATTERN (insn)) != ADDR_VEC
1488 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
1489 && get_attr_far_jump (insn) == FAR_JUMP_YES))
1490 insn = NEXT_INSN (insn);
1491 return (insn != NULL);
1494 /* For the FRV, this function makes sure that a function with far jumps
1495 will return correctly. It also does the VLIW packing. */
1498 frv_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1500 /* If no frame was created, check whether the function uses a call
1501 instruction to implement a far jump. If so, save the link in gr3 and
1502 replace all returns to LR with returns to GR3. GR3 is used because it
1503 is call-clobbered, because is not available to the register allocator,
1504 and because all functions that take a hidden argument pointer will have
1506 if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ())
1510 /* Just to check that the above comment is true. */
1511 gcc_assert (!df_regs_ever_live_p (GPR_FIRST + 3));
1513 /* Generate the instruction that saves the link register. */
1514 fprintf (file, "\tmovsg lr,gr3\n");
1516 /* Replace the LR with GR3 in *return_internal patterns. The insn
1517 will now return using jmpl @(gr3,0) rather than bralr. We cannot
1518 simply emit a different assembly directive because bralr and jmpl
1519 execute in different units. */
1520 for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn))
1521 if (GET_CODE (insn) == JUMP_INSN)
1523 rtx pattern = PATTERN (insn);
1524 if (GET_CODE (pattern) == PARALLEL
1525 && XVECLEN (pattern, 0) >= 2
1526 && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN
1527 && GET_CODE (XVECEXP (pattern, 0, 1)) == USE)
1529 rtx address = XEXP (XVECEXP (pattern, 0, 1), 0);
1530 if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO)
1531 SET_REGNO (address, GPR_FIRST + 3);
1538 /* Allow the garbage collector to free the nops created by frv_reorg. */
1539 memset (frv_nops, 0, sizeof (frv_nops));
1543 /* Return the next available temporary register in a given class. */
1546 frv_alloc_temp_reg (
1547 frv_tmp_reg_t *info, /* which registers are available */
1548 enum reg_class rclass, /* register class desired */
1549 enum machine_mode mode, /* mode to allocate register with */
1550 int mark_as_used, /* register not available after allocation */
1551 int no_abort) /* return NULL instead of aborting */
1553 int regno = info->next_reg[ (int)rclass ];
1554 int orig_regno = regno;
1555 HARD_REG_SET *reg_in_class = ®_class_contents[ (int)rclass ];
1560 if (TEST_HARD_REG_BIT (*reg_in_class, regno)
1561 && TEST_HARD_REG_BIT (info->regs, regno))
1564 if (++regno >= FIRST_PSEUDO_REGISTER)
1566 if (regno == orig_regno)
1568 gcc_assert (no_abort);
1573 nr = HARD_REGNO_NREGS (regno, mode);
1574 info->next_reg[ (int)rclass ] = regno + nr;
1577 for (i = 0; i < nr; i++)
1578 CLEAR_HARD_REG_BIT (info->regs, regno+i);
1580 return gen_rtx_REG (mode, regno);
1584 /* Return an rtx with the value OFFSET, which will either be a register or a
1585 signed 12-bit integer. It can be used as the second operand in an "add"
1586 instruction, or as the index in a load or store.
1588 The function returns a constant rtx if OFFSET is small enough, otherwise
1589 it loads the constant into register OFFSET_REGNO and returns that. */
1591 frv_frame_offset_rtx (int offset)
1593 rtx offset_rtx = GEN_INT (offset);
1594 if (IN_RANGE_P (offset, -2048, 2047))
1598 rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO);
1599 if (IN_RANGE_P (offset, -32768, 32767))
1600 emit_insn (gen_movsi (reg_rtx, offset_rtx));
1603 emit_insn (gen_movsi_high (reg_rtx, offset_rtx));
1604 emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx));
1610 /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The
1611 prologue and epilogue uses such expressions to access the stack. */
1613 frv_frame_mem (enum machine_mode mode, rtx base, int offset)
1615 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode,
1617 frv_frame_offset_rtx (offset)));
1620 /* Generate a frame-related expression:
1622 (set REG (mem (plus (sp) (const_int OFFSET)))).
1624 Such expressions are used in FRAME_RELATED_EXPR notes for more complex
1625 instructions. Marking the expressions as frame-related is superfluous if
1626 the note contains just a single set. But if the note contains a PARALLEL
1627 or SEQUENCE that has several sets, each set must be individually marked
1628 as frame-related. */
1630 frv_dwarf_store (rtx reg, int offset)
1632 rtx set = gen_rtx_SET (VOIDmode,
1633 gen_rtx_MEM (GET_MODE (reg),
1634 plus_constant (stack_pointer_rtx,
1637 RTX_FRAME_RELATED_P (set) = 1;
1641 /* Emit a frame-related instruction whose pattern is PATTERN. The
1642 instruction is the last in a sequence that cumulatively performs the
1643 operation described by DWARF_PATTERN. The instruction is marked as
1644 frame-related and has a REG_FRAME_RELATED_EXPR note containing
1647 frv_frame_insn (rtx pattern, rtx dwarf_pattern)
1649 rtx insn = emit_insn (pattern);
1650 RTX_FRAME_RELATED_P (insn) = 1;
1651 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1656 /* Emit instructions that transfer REG to or from the memory location (sp +
1657 STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is
1658 FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this
1659 function to store registers and only the epilogue uses it to load them.
1661 The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET).
1662 The generated instruction will use BASE as its base register. BASE may
1663 simply be the stack pointer, but if several accesses are being made to a
1664 region far away from the stack pointer, it may be more efficient to set
1665 up a temporary instead.
1667 Store instructions will be frame-related and will be annotated with the
1668 overall effect of the store. Load instructions will be followed by a
1669 (use) to prevent later optimizations from zapping them.
1671 The function takes care of the moves to and from SPRs, using TEMP_REGNO
1672 as a temporary in such cases. */
1674 frv_frame_access (frv_frame_accessor_t *accessor, rtx reg, int stack_offset)
1676 enum machine_mode mode = GET_MODE (reg);
1677 rtx mem = frv_frame_mem (mode,
1679 stack_offset - accessor->base_offset);
1681 if (accessor->op == FRV_LOAD)
1683 if (SPR_P (REGNO (reg)))
1685 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1686 emit_insn (gen_rtx_SET (VOIDmode, temp, mem));
1687 emit_insn (gen_rtx_SET (VOIDmode, reg, temp));
1691 /* We cannot use reg+reg addressing for DImode access. */
1693 && GET_CODE (XEXP (mem, 0)) == PLUS
1694 && GET_CODE (XEXP (XEXP (mem, 0), 0)) == REG
1695 && GET_CODE (XEXP (XEXP (mem, 0), 1)) == REG)
1697 rtx temp = gen_rtx_REG (SImode, TEMP_REGNO);
1698 rtx insn = emit_move_insn (temp,
1699 gen_rtx_PLUS (SImode, XEXP (XEXP (mem, 0), 0),
1700 XEXP (XEXP (mem, 0), 1)));
1701 mem = gen_rtx_MEM (DImode, temp);
1703 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
1709 if (SPR_P (REGNO (reg)))
1711 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1712 emit_insn (gen_rtx_SET (VOIDmode, temp, reg));
1713 frv_frame_insn (gen_rtx_SET (Pmode, mem, temp),
1714 frv_dwarf_store (reg, stack_offset));
1716 else if (mode == DImode)
1718 /* For DImode saves, the dwarf2 version needs to be a SEQUENCE
1719 with a separate save for each register. */
1720 rtx reg1 = gen_rtx_REG (SImode, REGNO (reg));
1721 rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1);
1722 rtx set1 = frv_dwarf_store (reg1, stack_offset);
1723 rtx set2 = frv_dwarf_store (reg2, stack_offset + 4);
1725 /* Also we cannot use reg+reg addressing. */
1726 if (GET_CODE (XEXP (mem, 0)) == PLUS
1727 && GET_CODE (XEXP (XEXP (mem, 0), 0)) == REG
1728 && GET_CODE (XEXP (XEXP (mem, 0), 1)) == REG)
1730 rtx temp = gen_rtx_REG (SImode, TEMP_REGNO);
1731 rtx insn = emit_move_insn (temp,
1732 gen_rtx_PLUS (SImode, XEXP (XEXP (mem, 0), 0),
1733 XEXP (XEXP (mem, 0), 1)));
1734 mem = gen_rtx_MEM (DImode, temp);
1737 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1738 gen_rtx_PARALLEL (VOIDmode,
1739 gen_rtvec (2, set1, set2)));
1742 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1743 frv_dwarf_store (reg, stack_offset));
1747 /* A function that uses frv_frame_access to transfer a group of registers to
1748 or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO
1749 is the stack information generated by frv_stack_info, and REG_SET is the
1750 number of the register set to transfer. */
1752 frv_frame_access_multi (frv_frame_accessor_t *accessor,
1756 frv_stack_regs_t *regs_info;
1759 regs_info = &info->regs[reg_set];
1760 for (regno = regs_info->first; regno <= regs_info->last; regno++)
1761 if (info->save_p[regno])
1762 frv_frame_access (accessor,
1763 info->save_p[regno] == REG_SAVE_2WORDS
1764 ? gen_rtx_REG (DImode, regno)
1765 : gen_rtx_REG (SImode, regno),
1766 info->reg_offset[regno]);
1769 /* Save or restore callee-saved registers that are kept outside the frame
1770 header. The function saves the registers if OP is FRV_STORE and restores
1771 them if OP is FRV_LOAD. INFO is the stack information generated by
1774 frv_frame_access_standard_regs (enum frv_stack_op op, frv_stack_t *info)
1776 frv_frame_accessor_t accessor;
1779 accessor.base = stack_pointer_rtx;
1780 accessor.base_offset = 0;
1781 frv_frame_access_multi (&accessor, info, STACK_REGS_GPR);
1782 frv_frame_access_multi (&accessor, info, STACK_REGS_FPR);
1783 frv_frame_access_multi (&accessor, info, STACK_REGS_LCR);
1787 /* Called after register allocation to add any instructions needed for the
1788 prologue. Using a prologue insn is favored compared to putting all of the
1789 instructions in the TARGET_ASM_FUNCTION_PROLOGUE target hook, since
1790 it allows the scheduler to intermix instructions with the saves of
1791 the caller saved registers. In some cases, it might be necessary
1792 to emit a barrier instruction as the last insn to prevent such
1795 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
1796 so that the debug info generation code can handle them properly. */
1798 frv_expand_prologue (void)
1800 frv_stack_t *info = frv_stack_info ();
1801 rtx sp = stack_pointer_rtx;
1802 rtx fp = frame_pointer_rtx;
1803 frv_frame_accessor_t accessor;
1805 if (TARGET_DEBUG_STACK)
1806 frv_debug_stack (info);
1808 if (info->total_size == 0)
1811 /* We're interested in three areas of the frame here:
1813 A: the register save area
1815 C: the header after B
1817 If the frame pointer isn't used, we'll have to set up A, B and C
1818 using the stack pointer. If the frame pointer is used, we'll access
1822 B: set up using sp or a temporary (see below)
1825 We set up B using the stack pointer if the frame is small enough.
1826 Otherwise, it's more efficient to copy the old stack pointer into a
1827 temporary and use that.
1829 Note that it's important to make sure the prologue and epilogue use the
1830 same registers to access A and C, since doing otherwise will confuse
1831 the aliasing code. */
1833 /* Set up ACCESSOR for accessing region B above. If the frame pointer
1834 isn't used, the same method will serve for C. */
1835 accessor.op = FRV_STORE;
1836 if (frame_pointer_needed && info->total_size > 2048)
1840 accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO);
1841 accessor.base_offset = info->total_size;
1842 insn = emit_insn (gen_movsi (accessor.base, sp));
1846 accessor.base = stack_pointer_rtx;
1847 accessor.base_offset = 0;
1850 /* Allocate the stack space. */
1852 rtx asm_offset = frv_frame_offset_rtx (-info->total_size);
1853 rtx dwarf_offset = GEN_INT (-info->total_size);
1855 frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset),
1858 gen_rtx_PLUS (Pmode, sp, dwarf_offset)));
1861 /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET)
1862 and point the new one to that location. */
1863 if (frame_pointer_needed)
1865 int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1867 /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is
1868 based on ACCESSOR.BASE but DWARF_SRC is always based on the stack
1870 rtx asm_src = plus_constant (accessor.base,
1871 fp_offset - accessor.base_offset);
1872 rtx dwarf_src = plus_constant (sp, fp_offset);
1874 /* Store the old frame pointer at (sp + FP_OFFSET). */
1875 frv_frame_access (&accessor, fp, fp_offset);
1877 /* Set up the new frame pointer. */
1878 frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src),
1879 gen_rtx_SET (VOIDmode, fp, dwarf_src));
1881 /* Access region C from the frame pointer. */
1883 accessor.base_offset = fp_offset;
1886 /* Set up region C. */
1887 frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT);
1888 frv_frame_access_multi (&accessor, info, STACK_REGS_LR);
1889 frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG);
1891 /* Set up region A. */
1892 frv_frame_access_standard_regs (FRV_STORE, info);
1894 /* If this is a varargs/stdarg function, issue a blockage to prevent the
1895 scheduler from moving loads before the stores saving the registers. */
1896 if (info->stdarg_size > 0)
1897 emit_insn (gen_blockage ());
1899 /* Set up pic register/small data register for this function. */
1900 if (!TARGET_FDPIC && flag_pic && crtl->uses_pic_offset_table)
1901 emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO),
1902 gen_rtx_REG (Pmode, LR_REGNO),
1903 gen_rtx_REG (SImode, OFFSET_REGNO)));
1907 /* Under frv, all of the work is done via frv_expand_epilogue, but
1908 this function provides a convenient place to do cleanup. */
1911 frv_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
1912 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1914 frv_stack_cache = (frv_stack_t *)0;
1916 /* Zap last used registers for conditional execution. */
1917 memset (&frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg));
1919 /* Release the bitmap of created insns. */
1920 BITMAP_FREE (frv_ifcvt.scratch_insns_bitmap);
1924 /* Called after register allocation to add any instructions needed for the
1925 epilogue. Using an epilogue insn is favored compared to putting all of the
1926 instructions in the TARGET_ASM_FUNCTION_PROLOGUE target hook, since
1927 it allows the scheduler to intermix instructions with the saves of
1928 the caller saved registers. In some cases, it might be necessary
1929 to emit a barrier instruction as the last insn to prevent such
1933 frv_expand_epilogue (bool emit_return)
1935 frv_stack_t *info = frv_stack_info ();
1936 rtx fp = frame_pointer_rtx;
1937 rtx sp = stack_pointer_rtx;
1941 fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1943 /* Restore the stack pointer to its original value if alloca or the like
1945 if (! current_function_sp_is_unchanging)
1946 emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset)));
1948 /* Restore the callee-saved registers that were used in this function. */
1949 frv_frame_access_standard_regs (FRV_LOAD, info);
1951 /* Set RETURN_ADDR to the address we should return to. Set it to NULL if
1952 no return instruction should be emitted. */
1953 if (info->save_p[LR_REGNO])
1958 /* Use the same method to access the link register's slot as we did in
1959 the prologue. In other words, use the frame pointer if available,
1960 otherwise use the stack pointer.
1962 LR_OFFSET is the offset of the link register's slot from the start
1963 of the frame and MEM is a memory rtx for it. */
1964 lr_offset = info->reg_offset[LR_REGNO];
1965 if (frame_pointer_needed)
1966 mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset);
1968 mem = frv_frame_mem (Pmode, sp, lr_offset);
1970 /* Load the old link register into a GPR. */
1971 return_addr = gen_rtx_REG (Pmode, TEMP_REGNO);
1972 emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem));
1975 return_addr = gen_rtx_REG (Pmode, LR_REGNO);
1977 /* Restore the old frame pointer. Emit a USE afterwards to make sure
1978 the load is preserved. */
1979 if (frame_pointer_needed)
1981 emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp)));
1985 /* Deallocate the stack frame. */
1986 if (info->total_size != 0)
1988 rtx offset = frv_frame_offset_rtx (info->total_size);
1989 emit_insn (gen_stack_adjust (sp, sp, offset));
1992 /* If this function uses eh_return, add the final stack adjustment now. */
1993 if (crtl->calls_eh_return)
1994 emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX));
1997 emit_jump_insn (gen_epilogue_return (return_addr));
2000 rtx lr = return_addr;
2002 if (REGNO (return_addr) != LR_REGNO)
2004 lr = gen_rtx_REG (Pmode, LR_REGNO);
2005 emit_move_insn (lr, return_addr);
2013 /* Worker function for TARGET_ASM_OUTPUT_MI_THUNK. */
2016 frv_asm_output_mi_thunk (FILE *file,
2017 tree thunk_fndecl ATTRIBUTE_UNUSED,
2018 HOST_WIDE_INT delta,
2019 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2022 const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0);
2023 const char *name_arg0 = reg_names[FIRST_ARG_REGNUM];
2024 const char *name_jmp = reg_names[JUMP_REGNO];
2025 const char *parallel = (frv_issue_rate () > 1 ? ".p" : "");
2027 /* Do the add using an addi if possible. */
2028 if (IN_RANGE_P (delta, -2048, 2047))
2029 fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0);
2032 const char *const name_add = reg_names[TEMP_REGNO];
2033 fprintf (file, "\tsethi%s #hi(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
2034 parallel, delta, name_add);
2035 fprintf (file, "\tsetlo #lo(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
2037 fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0);
2042 const char *name_pic = reg_names[FDPIC_REGNO];
2043 name_jmp = reg_names[FDPIC_FPTR_REGNO];
2047 fprintf (file, "\tsethi%s #gotofffuncdeschi(", parallel);
2048 assemble_name (file, name_func);
2049 fprintf (file, "),%s\n", name_jmp);
2051 fprintf (file, "\tsetlo #gotofffuncdesclo(");
2052 assemble_name (file, name_func);
2053 fprintf (file, "),%s\n", name_jmp);
2055 fprintf (file, "\tldd @(%s,%s), %s\n", name_jmp, name_pic, name_jmp);
2059 fprintf (file, "\tlddo @(%s,#gotofffuncdesc12(", name_pic);
2060 assemble_name (file, name_func);
2061 fprintf (file, "\t)), %s\n", name_jmp);
2066 fprintf (file, "\tsethi%s #hi(", parallel);
2067 assemble_name (file, name_func);
2068 fprintf (file, "),%s\n", name_jmp);
2070 fprintf (file, "\tsetlo #lo(");
2071 assemble_name (file, name_func);
2072 fprintf (file, "),%s\n", name_jmp);
2076 /* Use JUMP_REGNO as a temporary PIC register. */
2077 const char *name_lr = reg_names[LR_REGNO];
2078 const char *name_gppic = name_jmp;
2079 const char *name_tmp = reg_names[TEMP_REGNO];
2081 fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp);
2082 fprintf (file, "\tcall 1f\n");
2083 fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic);
2084 fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr);
2085 fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp);
2086 fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp);
2087 fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic);
2089 fprintf (file, "\tsethi%s #gprelhi(", parallel);
2090 assemble_name (file, name_func);
2091 fprintf (file, "),%s\n", name_tmp);
2093 fprintf (file, "\tsetlo #gprello(");
2094 assemble_name (file, name_func);
2095 fprintf (file, "),%s\n", name_tmp);
2097 fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp);
2100 /* Jump to the function address. */
2101 fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]);
2105 /* A C expression which is nonzero if a function must have and use a frame
2106 pointer. This expression is evaluated in the reload pass. If its value is
2107 nonzero the function will have a frame pointer.
2109 The expression can in principle examine the current function and decide
2110 according to the facts, but on most machines the constant 0 or the constant
2111 1 suffices. Use 0 when the machine allows code to be generated with no
2112 frame pointer, and doing so saves some time or space. Use 1 when there is
2113 no possible advantage to avoiding a frame pointer.
2115 In certain cases, the compiler does not know how to produce valid code
2116 without a frame pointer. The compiler recognizes those cases and
2117 automatically gives the function a frame pointer regardless of what
2118 `FRAME_POINTER_REQUIRED' says. You don't need to worry about them.
2120 In a function that does not require a frame pointer, the frame pointer
2121 register can be allocated for ordinary usage, unless you mark it as a fixed
2122 register. See `FIXED_REGISTERS' for more information. */
2124 /* On frv, create a frame whenever we need to create stack. */
2127 frv_frame_pointer_required (void)
2129 /* If we forgoing the usual linkage requirements, we only need
2130 a frame pointer if the stack pointer might change. */
2131 if (!TARGET_LINKED_FP)
2132 return !current_function_sp_is_unchanging;
2134 if (! current_function_is_leaf)
2137 if (get_frame_size () != 0)
2143 if (!current_function_sp_is_unchanging)
2146 if (!TARGET_FDPIC && flag_pic && crtl->uses_pic_offset_table)
2152 if (cfun->machine->frame_needed)
2159 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the
2160 initial difference between the specified pair of registers. This macro must
2161 be defined if `ELIMINABLE_REGS' is defined. */
2163 /* See frv_stack_info for more details on the frv stack frame. */
2166 frv_initial_elimination_offset (int from, int to)
2168 frv_stack_t *info = frv_stack_info ();
2171 if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2172 ret = info->total_size - info->pretend_size;
2174 else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM)
2175 ret = info->reg_offset[FRAME_POINTER_REGNUM];
2177 else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2178 ret = (info->total_size
2179 - info->reg_offset[FRAME_POINTER_REGNUM]
2180 - info->pretend_size);
2185 if (TARGET_DEBUG_STACK)
2186 fprintf (stderr, "Eliminate %s to %s by adding %d\n",
2187 reg_names [from], reg_names[to], ret);
2193 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2196 frv_setup_incoming_varargs (CUMULATIVE_ARGS *cum,
2197 enum machine_mode mode,
2198 tree type ATTRIBUTE_UNUSED,
2202 if (TARGET_DEBUG_ARG)
2204 "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n",
2205 *cum, GET_MODE_NAME (mode), *pretend_size, second_time);
2209 /* Worker function for TARGET_EXPAND_BUILTIN_SAVEREGS. */
2212 frv_expand_builtin_saveregs (void)
2214 int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS;
2216 if (TARGET_DEBUG_ARG)
2217 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2220 return gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2224 /* Expand __builtin_va_start to do the va_start macro. */
2227 frv_expand_builtin_va_start (tree valist, rtx nextarg)
2230 int num = crtl->args.info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS;
2232 nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx,
2233 GEN_INT (UNITS_PER_WORD * num));
2235 if (TARGET_DEBUG_ARG)
2237 fprintf (stderr, "va_start: args_info = %d, num = %d\n",
2238 crtl->args.info, num);
2240 debug_rtx (nextarg);
2243 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist,
2244 fold_convert (TREE_TYPE (valist),
2245 make_tree (sizetype, nextarg)));
2246 TREE_SIDE_EFFECTS (t) = 1;
2248 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2252 /* Expand a block move operation, and return 1 if successful. Return 0
2253 if we should let the compiler generate normal code.
2255 operands[0] is the destination
2256 operands[1] is the source
2257 operands[2] is the length
2258 operands[3] is the alignment */
2260 /* Maximum number of loads to do before doing the stores */
2261 #ifndef MAX_MOVE_REG
2262 #define MAX_MOVE_REG 4
2265 /* Maximum number of total loads to do. */
2266 #ifndef TOTAL_MOVE_REG
2267 #define TOTAL_MOVE_REG 8
2271 frv_expand_block_move (rtx operands[])
2273 rtx orig_dest = operands[0];
2274 rtx orig_src = operands[1];
2275 rtx bytes_rtx = operands[2];
2276 rtx align_rtx = operands[3];
2277 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2290 rtx stores[MAX_MOVE_REG];
2292 enum machine_mode mode;
2294 /* If this is not a fixed size move, just call memcpy. */
2298 /* This should be a fixed size alignment. */
2299 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
2301 align = INTVAL (align_rtx);
2303 /* Anything to move? */
2304 bytes = INTVAL (bytes_rtx);
2308 /* Don't support real large moves. */
2309 if (bytes > TOTAL_MOVE_REG*align)
2312 /* Move the address into scratch registers. */
2313 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2314 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2316 num_reg = offset = 0;
2317 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2319 /* Calculate the correct offset for src/dest. */
2323 dest_addr = dest_reg;
2327 src_addr = plus_constant (src_reg, offset);
2328 dest_addr = plus_constant (dest_reg, offset);
2331 /* Generate the appropriate load and store, saving the stores
2333 if (bytes >= 4 && align >= 4)
2335 else if (bytes >= 2 && align >= 2)
2340 move_bytes = GET_MODE_SIZE (mode);
2341 tmp_reg = gen_reg_rtx (mode);
2342 src_mem = change_address (orig_src, mode, src_addr);
2343 dest_mem = change_address (orig_dest, mode, dest_addr);
2344 emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem));
2345 stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg);
2347 if (num_reg >= MAX_MOVE_REG)
2349 for (i = 0; i < num_reg; i++)
2350 emit_insn (stores[i]);
2355 for (i = 0; i < num_reg; i++)
2356 emit_insn (stores[i]);
2362 /* Expand a block clear operation, and return 1 if successful. Return 0
2363 if we should let the compiler generate normal code.
2365 operands[0] is the destination
2366 operands[1] is the length
2367 operands[3] is the alignment */
2370 frv_expand_block_clear (rtx operands[])
2372 rtx orig_dest = operands[0];
2373 rtx bytes_rtx = operands[1];
2374 rtx align_rtx = operands[3];
2375 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2384 enum machine_mode mode;
2386 /* If this is not a fixed size move, just call memcpy. */
2390 /* This should be a fixed size alignment. */
2391 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
2393 align = INTVAL (align_rtx);
2395 /* Anything to move? */
2396 bytes = INTVAL (bytes_rtx);
2400 /* Don't support real large clears. */
2401 if (bytes > TOTAL_MOVE_REG*align)
2404 /* Move the address into a scratch register. */
2405 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2407 num_reg = offset = 0;
2408 for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes))
2410 /* Calculate the correct offset for src/dest. */
2411 dest_addr = ((offset == 0)
2413 : plus_constant (dest_reg, offset));
2415 /* Generate the appropriate store of gr0. */
2416 if (bytes >= 4 && align >= 4)
2418 else if (bytes >= 2 && align >= 2)
2423 clear_bytes = GET_MODE_SIZE (mode);
2424 dest_mem = change_address (orig_dest, mode, dest_addr);
2425 emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx));
2432 /* The following variable is used to output modifiers of assembler
2433 code of the current output insn. */
2435 static rtx *frv_insn_operands;
2437 /* The following function is used to add assembler insn code suffix .p
2438 if it is necessary. */
2441 frv_asm_output_opcode (FILE *f, const char *ptr)
2445 if (frv_insn_packing_flag <= 0)
2448 for (; *ptr && *ptr != ' ' && *ptr != '\t';)
2451 if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z')
2452 || (*ptr >= 'A' && *ptr <= 'Z')))
2454 int letter = *ptr++;
2457 frv_print_operand (f, frv_insn_operands [c], letter);
2458 while ((c = *ptr) >= '0' && c <= '9')
2470 /* Set up the packing bit for the current output insn. Note that this
2471 function is not called for asm insns. */
2474 frv_final_prescan_insn (rtx insn, rtx *opvec,
2475 int noperands ATTRIBUTE_UNUSED)
2479 if (frv_insn_packing_flag >= 0)
2481 frv_insn_operands = opvec;
2482 frv_insn_packing_flag = PACKING_FLAG_P (insn);
2484 else if (recog_memoized (insn) >= 0
2485 && get_attr_acc_group (insn) == ACC_GROUP_ODD)
2486 /* Packing optimizations have been disabled, but INSN can only
2487 be issued in M1. Insert an mnop in M0. */
2488 fprintf (asm_out_file, "\tmnop.p\n");
2494 /* A C expression whose value is RTL representing the address in a stack frame
2495 where the pointer to the caller's frame is stored. Assume that FRAMEADDR is
2496 an RTL expression for the address of the stack frame itself.
2498 If you don't define this macro, the default is to return the value of
2499 FRAMEADDR--that is, the stack frame address is also the address of the stack
2500 word that points to the previous frame. */
2502 /* The default is correct, but we need to make sure the frame gets created. */
2504 frv_dynamic_chain_address (rtx frame)
2506 cfun->machine->frame_needed = 1;
2511 /* A C expression whose value is RTL representing the value of the return
2512 address for the frame COUNT steps up from the current frame, after the
2513 prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame
2514 pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
2517 The value of the expression must always be the correct address when COUNT is
2518 zero, but may be `NULL_RTX' if there is not way to determine the return
2519 address of other frames. */
2522 frv_return_addr_rtx (int count, rtx frame)
2526 cfun->machine->frame_needed = 1;
2527 return gen_rtx_MEM (Pmode, plus_constant (frame, 8));
2530 /* Given a memory reference MEMREF, interpret the referenced memory as
2531 an array of MODE values, and return a reference to the element
2532 specified by INDEX. Assume that any pre-modification implicit in
2533 MEMREF has already happened.
2535 MEMREF must be a legitimate operand for modes larger than SImode.
2536 GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which
2537 this function cannot handle. */
2539 frv_index_memory (rtx memref, enum machine_mode mode, int index)
2541 rtx base = XEXP (memref, 0);
2542 if (GET_CODE (base) == PRE_MODIFY)
2543 base = XEXP (base, 0);
2544 return change_address (memref, mode,
2545 plus_constant (base, index * GET_MODE_SIZE (mode)));
2549 /* Print a memory address as an operand to reference that memory location. */
2551 frv_print_operand_address (FILE * stream, rtx x)
2553 if (GET_CODE (x) == MEM)
2556 switch (GET_CODE (x))
2559 fputs (reg_names [ REGNO (x)], stream);
2563 fprintf (stream, "%ld", (long) INTVAL (x));
2567 assemble_name (stream, XSTR (x, 0));
2572 output_addr_const (stream, x);
2576 /* Poorly constructed asm statements can trigger this alternative.
2577 See gcc/testsuite/gcc.dg/asm-4.c for an example. */
2578 frv_print_operand_memory_reference (stream, x, 0);
2585 fatal_insn ("bad insn to frv_print_operand_address:", x);
2590 frv_print_operand_memory_reference_reg (FILE * stream, rtx x)
2592 int regno = true_regnum (x);
2594 fputs (reg_names[regno], stream);
2596 fatal_insn ("bad register to frv_print_operand_memory_reference_reg:", x);
2599 /* Print a memory reference suitable for the ld/st instructions. */
2602 frv_print_operand_memory_reference (FILE * stream, rtx x, int addr_offset)
2604 struct frv_unspec unspec;
2608 switch (GET_CODE (x))
2615 case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */
2617 x1 = XEXP (XEXP (x, 1), 1);
2627 if (GET_CODE (x0) == CONST_INT)
2635 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2644 else if (GET_CODE (x1) != CONST_INT)
2645 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2648 fputs ("@(", stream);
2650 fputs (reg_names[GPR_R0], stream);
2651 else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG)
2652 frv_print_operand_memory_reference_reg (stream, x0);
2654 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2656 fputs (",", stream);
2658 fputs (reg_names [GPR_R0], stream);
2662 switch (GET_CODE (x1))
2666 frv_print_operand_memory_reference_reg (stream, x1);
2670 fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset));
2674 if (!frv_const_unspec_p (x1, &unspec))
2675 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x1);
2676 frv_output_const_unspec (stream, &unspec);
2680 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2684 fputs (")", stream);
2688 /* Return 2 for likely branches and 0 for non-likely branches */
2690 #define FRV_JUMP_LIKELY 2
2691 #define FRV_JUMP_NOT_LIKELY 0
2694 frv_print_operand_jump_hint (rtx insn)
2699 HOST_WIDE_INT prob = -1;
2700 enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN;
2702 gcc_assert (GET_CODE (insn) == JUMP_INSN);
2704 /* Assume any non-conditional jump is likely. */
2705 if (! any_condjump_p (insn))
2706 ret = FRV_JUMP_LIKELY;
2710 labelref = condjump_label (insn);
2713 rtx label = XEXP (labelref, 0);
2714 jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label))
2719 note = find_reg_note (insn, REG_BR_PROB, 0);
2721 ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY);
2725 prob = INTVAL (XEXP (note, 0));
2726 ret = ((prob >= (REG_BR_PROB_BASE / 2))
2728 : FRV_JUMP_NOT_LIKELY);
2740 case UNKNOWN: direction = "unknown jump direction"; break;
2741 case BACKWARD: direction = "jump backward"; break;
2742 case FORWARD: direction = "jump forward"; break;
2746 "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n",
2747 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
2748 (long)INSN_UID (insn), direction, (long)prob,
2749 (long)REG_BR_PROB_BASE, ret);
2757 /* Return the comparison operator to use for CODE given that the ICC
2761 comparison_string (enum rtx_code code, rtx op0)
2763 bool is_nz_p = GET_MODE (op0) == CC_NZmode;
2766 default: output_operand_lossage ("bad condition code");
2767 case EQ: return "eq";
2768 case NE: return "ne";
2769 case LT: return is_nz_p ? "n" : "lt";
2770 case LE: return "le";
2771 case GT: return "gt";
2772 case GE: return is_nz_p ? "p" : "ge";
2773 case LTU: return is_nz_p ? "no" : "c";
2774 case LEU: return is_nz_p ? "eq" : "ls";
2775 case GTU: return is_nz_p ? "ne" : "hi";
2776 case GEU: return is_nz_p ? "ra" : "nc";
2780 /* Print an operand to an assembler instruction.
2782 `%' followed by a letter and a digit says to output an operand in an
2783 alternate fashion. Four letters have standard, built-in meanings described
2784 below. The machine description macro `PRINT_OPERAND' can define additional
2785 letters with nonstandard meanings.
2787 `%cDIGIT' can be used to substitute an operand that is a constant value
2788 without the syntax that normally indicates an immediate operand.
2790 `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated
2793 `%aDIGIT' can be used to substitute an operand as if it were a memory
2794 reference, with the actual operand treated as the address. This may be
2795 useful when outputting a "load address" instruction, because often the
2796 assembler syntax for such an instruction requires you to write the operand
2797 as if it were a memory reference.
2799 `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
2801 `%=' outputs a number which is unique to each instruction in the entire
2802 compilation. This is useful for making local labels to be referred to more
2803 than once in a single template that generates multiple assembler
2806 `%' followed by a punctuation character specifies a substitution that does
2807 not use an operand. Only one case is standard: `%%' outputs a `%' into the
2808 assembler code. Other nonstandard cases can be defined in the
2809 `PRINT_OPERAND' macro. You must also define which punctuation characters
2810 are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */
2813 frv_print_operand (FILE * file, rtx x, int code)
2815 struct frv_unspec unspec;
2816 HOST_WIDE_INT value;
2819 if (code != 0 && !ISALPHA (code))
2822 else if (GET_CODE (x) == CONST_INT)
2825 else if (GET_CODE (x) == CONST_DOUBLE)
2827 if (GET_MODE (x) == SFmode)
2832 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2833 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2837 else if (GET_MODE (x) == VOIDmode)
2838 value = CONST_DOUBLE_LOW (x);
2841 fatal_insn ("bad insn in frv_print_operand, bad const_double", x);
2852 fputs (reg_names[GPR_R0], file);
2856 fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn));
2860 /* Output small data area base register (gr16). */
2861 fputs (reg_names[SDA_BASE_REG], file);
2865 /* Output pic register (gr17). */
2866 fputs (reg_names[PIC_REGNO], file);
2870 /* Output the temporary integer CCR register. */
2871 fputs (reg_names[ICR_TEMP], file);
2875 /* Output the temporary integer CC register. */
2876 fputs (reg_names[ICC_TEMP], file);
2879 /* case 'a': print an address. */
2882 /* Print appropriate test for integer branch false operation. */
2883 fputs (comparison_string (reverse_condition (GET_CODE (x)),
2884 XEXP (x, 0)), file);
2888 /* Print appropriate test for integer branch true operation. */
2889 fputs (comparison_string (GET_CODE (x), XEXP (x, 0)), file);
2893 /* Print 1 for a NE and 0 for an EQ to give the final argument
2894 for a conditional instruction. */
2895 if (GET_CODE (x) == NE)
2898 else if (GET_CODE (x) == EQ)
2902 fatal_insn ("bad insn to frv_print_operand, 'e' modifier:", x);
2906 /* Print appropriate test for floating point branch false operation. */
2907 switch (GET_CODE (x))
2910 fatal_insn ("bad insn to frv_print_operand, 'F' modifier:", x);
2912 case EQ: fputs ("ne", file); break;
2913 case NE: fputs ("eq", file); break;
2914 case LT: fputs ("uge", file); break;
2915 case LE: fputs ("ug", file); break;
2916 case GT: fputs ("ule", file); break;
2917 case GE: fputs ("ul", file); break;
2922 /* Print appropriate test for floating point branch true operation. */
2923 switch (GET_CODE (x))
2926 fatal_insn ("bad insn to frv_print_operand, 'f' modifier:", x);
2928 case EQ: fputs ("eq", file); break;
2929 case NE: fputs ("ne", file); break;
2930 case LT: fputs ("lt", file); break;
2931 case LE: fputs ("le", file); break;
2932 case GT: fputs ("gt", file); break;
2933 case GE: fputs ("ge", file); break;
2938 /* Print appropriate GOT function. */
2939 if (GET_CODE (x) != CONST_INT)
2940 fatal_insn ("bad insn to frv_print_operand, 'g' modifier:", x);
2941 fputs (unspec_got_name (INTVAL (x)), file);
2945 /* Print 'i' if the operand is a constant, or is a memory reference that
2947 if (GET_CODE (x) == MEM)
2948 x = ((GET_CODE (XEXP (x, 0)) == PLUS)
2949 ? XEXP (XEXP (x, 0), 1)
2951 else if (GET_CODE (x) == PLUS)
2954 switch (GET_CODE (x))
2968 /* For jump instructions, print 'i' if the operand is a constant or
2969 is an expression that adds a constant. */
2970 if (GET_CODE (x) == CONST_INT)
2975 if (GET_CODE (x) == CONST_INT
2976 || (GET_CODE (x) == PLUS
2977 && (GET_CODE (XEXP (x, 1)) == CONST_INT
2978 || GET_CODE (XEXP (x, 0)) == CONST_INT)))
2984 /* Print the lower register of a double word register pair */
2985 if (GET_CODE (x) == REG)
2986 fputs (reg_names[ REGNO (x)+1 ], file);
2988 fatal_insn ("bad insn to frv_print_operand, 'L' modifier:", x);
2991 /* case 'l': print a LABEL_REF. */
2995 /* Print a memory reference for ld/st/jmp, %N prints a memory reference
2996 for the second word of double memory operations. */
2997 offset = (code == 'M') ? 0 : UNITS_PER_WORD;
2998 switch (GET_CODE (x))
3001 fatal_insn ("bad insn to frv_print_operand, 'M/N' modifier:", x);
3004 frv_print_operand_memory_reference (file, XEXP (x, 0), offset);
3012 frv_print_operand_memory_reference (file, x, offset);
3018 /* Print the opcode of a command. */
3019 switch (GET_CODE (x))
3022 fatal_insn ("bad insn to frv_print_operand, 'O' modifier:", x);
3024 case PLUS: fputs ("add", file); break;
3025 case MINUS: fputs ("sub", file); break;
3026 case AND: fputs ("and", file); break;
3027 case IOR: fputs ("or", file); break;
3028 case XOR: fputs ("xor", file); break;
3029 case ASHIFT: fputs ("sll", file); break;
3030 case ASHIFTRT: fputs ("sra", file); break;
3031 case LSHIFTRT: fputs ("srl", file); break;
3035 /* case 'n': negate and print a constant int. */
3038 /* Print PIC label using operand as the number. */
3039 if (GET_CODE (x) != CONST_INT)
3040 fatal_insn ("bad insn to frv_print_operand, P modifier:", x);
3042 fprintf (file, ".LCF%ld", (long)INTVAL (x));
3046 /* Print 'u' if the operand is a update load/store. */
3047 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
3052 /* If value is 0, print gr0, otherwise it must be a register. */
3053 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
3054 fputs (reg_names[GPR_R0], file);
3056 else if (GET_CODE (x) == REG)
3057 fputs (reg_names [REGNO (x)], file);
3060 fatal_insn ("bad insn in frv_print_operand, z case", x);
3064 /* Print constant in hex. */
3065 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
3067 fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value);
3074 if (GET_CODE (x) == REG)
3075 fputs (reg_names [REGNO (x)], file);
3077 else if (GET_CODE (x) == CONST_INT
3078 || GET_CODE (x) == CONST_DOUBLE)
3079 fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value);
3081 else if (frv_const_unspec_p (x, &unspec))
3082 frv_output_const_unspec (file, &unspec);
3084 else if (GET_CODE (x) == MEM)
3085 frv_print_operand_address (file, XEXP (x, 0));
3087 else if (CONSTANT_ADDRESS_P (x))
3088 frv_print_operand_address (file, x);
3091 fatal_insn ("bad insn in frv_print_operand, 0 case", x);
3096 fatal_insn ("frv_print_operand: unknown code", x);
3104 /* A C statement (sans semicolon) for initializing the variable CUM for the
3105 state at the beginning of the argument list. The variable has type
3106 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
3107 of the function which will receive the args, or 0 if the args are to a
3108 compiler support library function. The value of INDIRECT is nonzero when
3109 processing an indirect call, for example a call through a function pointer.
3110 The value of INDIRECT is zero for a call to an explicitly named function, a
3111 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
3112 arguments for the function being compiled.
3114 When processing a call to a compiler support library function, LIBNAME
3115 identifies which one. It is a `symbol_ref' rtx which contains the name of
3116 the function, as a string. LIBNAME is 0 when an ordinary C function call is
3117 being processed. Thus, each time this macro is called, either LIBNAME or
3118 FNTYPE is nonzero, but never both of them at once. */
3121 frv_init_cumulative_args (CUMULATIVE_ARGS *cum,
3127 *cum = FIRST_ARG_REGNUM;
3129 if (TARGET_DEBUG_ARG)
3131 fprintf (stderr, "\ninit_cumulative_args:");
3132 if (!fndecl && fntype)
3133 fputs (" indirect", stderr);
3136 fputs (" incoming", stderr);
3140 tree ret_type = TREE_TYPE (fntype);
3141 fprintf (stderr, " return=%s,",
3142 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3145 if (libname && GET_CODE (libname) == SYMBOL_REF)
3146 fprintf (stderr, " libname=%s", XSTR (libname, 0));
3148 if (cfun->returns_struct)
3149 fprintf (stderr, " return-struct");
3151 putc ('\n', stderr);
3156 /* Return true if we should pass an argument on the stack rather than
3160 frv_must_pass_in_stack (enum machine_mode mode, const_tree type)
3162 if (mode == BLKmode)
3166 return AGGREGATE_TYPE_P (type);
3169 /* If defined, a C expression that gives the alignment boundary, in bits, of an
3170 argument with the specified mode and type. If it is not defined,
3171 `PARM_BOUNDARY' is used for all arguments. */
3174 frv_function_arg_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
3175 tree type ATTRIBUTE_UNUSED)
3177 return BITS_PER_WORD;
3181 frv_function_arg (CUMULATIVE_ARGS *cum,
3182 enum machine_mode mode,
3183 tree type ATTRIBUTE_UNUSED,
3185 int incoming ATTRIBUTE_UNUSED)
3187 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3192 /* Return a marker for use in the call instruction. */
3193 if (xmode == VOIDmode)
3199 else if (arg_num <= LAST_ARG_REGNUM)
3201 ret = gen_rtx_REG (xmode, arg_num);
3202 debstr = reg_names[arg_num];
3211 if (TARGET_DEBUG_ARG)
3213 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n",
3214 arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr);
3220 /* A C statement (sans semicolon) to update the summarizer variable CUM to
3221 advance past an argument in the argument list. The values MODE, TYPE and
3222 NAMED describe that argument. Once this is done, the variable CUM is
3223 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
3225 This macro need not do anything if the argument in question was passed on
3226 the stack. The compiler knows how to track the amount of stack space used
3227 for arguments without any special help. */
3230 frv_function_arg_advance (CUMULATIVE_ARGS *cum,
3231 enum machine_mode mode,
3232 tree type ATTRIBUTE_UNUSED,
3235 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3236 int bytes = GET_MODE_SIZE (xmode);
3237 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3240 *cum = arg_num + words;
3242 if (TARGET_DEBUG_ARG)
3244 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n",
3245 arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD);
3249 /* A C expression for the number of words, at the beginning of an argument,
3250 must be put in registers. The value must be zero for arguments that are
3251 passed entirely in registers or that are entirely pushed on the stack.
3253 On some machines, certain arguments must be passed partially in registers
3254 and partially in memory. On these machines, typically the first N words of
3255 arguments are passed in registers, and the rest on the stack. If a
3256 multi-word argument (a `double' or a structure) crosses that boundary, its
3257 first few words must be passed in registers and the rest must be pushed.
3258 This macro tells the compiler when this occurs, and how many of the words
3259 should go in registers.
3261 `FUNCTION_ARG' for these arguments should return the first register to be
3262 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
3263 the called function. */
3266 frv_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3267 tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
3269 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3270 int bytes = GET_MODE_SIZE (xmode);
3271 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3275 ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1)
3276 ? LAST_ARG_REGNUM - arg_num + 1
3278 ret *= UNITS_PER_WORD;
3280 if (TARGET_DEBUG_ARG && ret)
3281 fprintf (stderr, "frv_arg_partial_bytes: %d\n", ret);
3287 /* Return true if a register is ok to use as a base or index register. */
3289 static FRV_INLINE int
3290 frv_regno_ok_for_base_p (int regno, int strict_p)
3296 return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno]));
3298 if (regno == ARG_POINTER_REGNUM)
3301 return (regno >= FIRST_PSEUDO_REGISTER);
3305 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3306 RTX) is a legitimate memory address on the target machine for a memory
3307 operand of mode MODE.
3309 It usually pays to define several simpler macros to serve as subroutines for
3310 this one. Otherwise it may be too complicated to understand.
3312 This macro must exist in two variants: a strict variant and a non-strict
3313 one. The strict variant is used in the reload pass. It must be defined so
3314 that any pseudo-register that has not been allocated a hard register is
3315 considered a memory reference. In contexts where some kind of register is
3316 required, a pseudo-register with no hard register must be rejected.
3318 The non-strict variant is used in other passes. It must be defined to
3319 accept all pseudo-registers in every context where some kind of register is
3322 Compiler source files that want to use the strict variant of this macro
3323 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3324 conditional to define the strict variant in that case and the non-strict
3327 Subroutines to check for acceptable registers for various purposes (one for
3328 base registers, one for index registers, and so on) are typically among the
3329 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3330 subroutine macros need have two variants; the higher levels of macros may be
3331 the same whether strict or not.
3333 Normally, constant addresses which are the sum of a `symbol_ref' and an
3334 integer are stored inside a `const' RTX to mark them as constant.
3335 Therefore, there is no need to recognize such sums specifically as
3336 legitimate addresses. Normally you would simply recognize any `const' as
3339 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3340 are not marked with `const'. It assumes that a naked `plus' indicates
3341 indexing. If so, then you *must* reject such naked constant sums as
3342 illegitimate addresses, so that none of them will be given to
3343 `PRINT_OPERAND_ADDRESS'.
3345 On some machines, whether a symbolic address is legitimate depends on the
3346 section that the address refers to. On these machines, define the macro
3347 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3348 then check for it here. When you see a `const', you will have to look
3349 inside it to find the `symbol_ref' in order to determine the section.
3351 The best way to modify the name string is by adding text to the beginning,
3352 with suitable punctuation to prevent any ambiguity. Allocate the new name
3353 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3354 remove and decode the added text and output the name accordingly, and define
3355 `(* targetm.strip_name_encoding)' to access the original name string.
3357 You can check the information stored here into the `symbol_ref' in the
3358 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3359 `PRINT_OPERAND_ADDRESS'. */
3362 frv_legitimate_address_p (enum machine_mode mode,
3366 int allow_double_reg_p)
3370 HOST_WIDE_INT value;
3373 if (FRV_SYMBOL_REF_TLS_P (x))
3376 switch (GET_CODE (x))
3383 if (GET_CODE (x) != REG)
3389 ret = frv_regno_ok_for_base_p (REGNO (x), strict_p);
3395 if (GET_CODE (x0) != REG
3396 || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p)
3397 || GET_CODE (x1) != PLUS
3398 || ! rtx_equal_p (x0, XEXP (x1, 0))
3399 || GET_CODE (XEXP (x1, 1)) != REG
3400 || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p))
3407 /* 12-bit immediate */
3412 ret = IN_RANGE_P (INTVAL (x), -2048, 2047);
3414 /* If we can't use load/store double operations, make sure we can
3415 address the second word. */
3416 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3417 ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1,
3426 if (GET_CODE (x0) == SUBREG)
3427 x0 = SUBREG_REG (x0);
3429 if (GET_CODE (x0) != REG)
3432 regno0 = REGNO (x0);
3433 if (!frv_regno_ok_for_base_p (regno0, strict_p))