1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
2 Free Software Foundation, Inc.
3 Contributed by Red Hat, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-flags.h"
35 #include "insn-attr.h"
45 #include "basic-block.h"
50 #include "target-def.h"
51 #include "targhooks.h"
52 #include "integrate.h"
53 #include "langhooks.h"
56 #define FRV_INLINE inline
59 /* The maximum number of distinct NOP patterns. There are three:
60 nop, fnop and mnop. */
61 #define NUM_NOP_PATTERNS 3
63 /* Classification of instructions and units: integer, floating-point/media,
64 branch and control. */
65 enum frv_insn_group { GROUP_I, GROUP_FM, GROUP_B, GROUP_C, NUM_GROUPS };
67 /* The DFA names of the units, in packet order. */
68 static const char *const frv_unit_names[] =
78 /* The classification of each unit in frv_unit_names[]. */
79 static const enum frv_insn_group frv_unit_groups[ARRAY_SIZE (frv_unit_names)] =
89 /* Return the DFA unit code associated with the Nth unit of integer
90 or floating-point group GROUP, */
91 #define NTH_UNIT(GROUP, N) frv_unit_codes[(GROUP) + (N) * 2 + 1]
93 /* Return the number of integer or floating-point unit UNIT
94 (1 for I1, 2 for F2, etc.). */
95 #define UNIT_NUMBER(UNIT) (((UNIT) - 1) / 2)
97 /* The DFA unit number for each unit in frv_unit_names[]. */
98 static int frv_unit_codes[ARRAY_SIZE (frv_unit_names)];
100 /* FRV_TYPE_TO_UNIT[T] is the last unit in frv_unit_names[] that can issue
101 an instruction of type T. The value is ARRAY_SIZE (frv_unit_names) if
102 no instruction of type T has been seen. */
103 static unsigned int frv_type_to_unit[TYPE_UNKNOWN + 1];
105 /* An array of dummy nop INSNs, one for each type of nop that the
107 static GTY(()) rtx frv_nops[NUM_NOP_PATTERNS];
109 /* The number of nop instructions in frv_nops[]. */
110 static unsigned int frv_num_nops;
112 /* 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 machine_function GTY(())
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 (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, 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 (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 bool frv_rtx_costs (rtx, int, int, int*);
369 static void frv_asm_out_constructor (rtx, int);
370 static void frv_asm_out_destructor (rtx, int);
371 static bool frv_function_symbol_referenced_p (rtx);
372 static bool frv_cannot_force_const_mem (rtx);
373 static const char *unspec_got_name (int);
374 static void frv_output_const_unspec (FILE *,
375 const struct frv_unspec *);
376 static bool frv_function_ok_for_sibcall (tree, tree);
377 static rtx frv_struct_value_rtx (tree, int);
378 static bool frv_must_pass_in_stack (enum machine_mode mode, tree type);
379 static int frv_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
381 static void frv_output_dwarf_dtprel (FILE *, int, rtx)
384 /* Allow us to easily change the default for -malloc-cc. */
385 #ifndef DEFAULT_NO_ALLOC_CC
386 #define MASK_DEFAULT_ALLOC_CC MASK_ALLOC_CC
388 #define MASK_DEFAULT_ALLOC_CC 0
391 /* Initialize the GCC target structure. */
392 #undef TARGET_ASM_FUNCTION_PROLOGUE
393 #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue
394 #undef TARGET_ASM_FUNCTION_EPILOGUE
395 #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue
396 #undef TARGET_ASM_INTEGER
397 #define TARGET_ASM_INTEGER frv_assemble_integer
398 #undef TARGET_DEFAULT_TARGET_FLAGS
399 #define TARGET_DEFAULT_TARGET_FLAGS \
400 (MASK_DEFAULT_ALLOC_CC \
407 #undef TARGET_HANDLE_OPTION
408 #define TARGET_HANDLE_OPTION frv_handle_option
409 #undef TARGET_INIT_BUILTINS
410 #define TARGET_INIT_BUILTINS frv_init_builtins
411 #undef TARGET_EXPAND_BUILTIN
412 #define TARGET_EXPAND_BUILTIN frv_expand_builtin
413 #undef TARGET_INIT_LIBFUNCS
414 #define TARGET_INIT_LIBFUNCS frv_init_libfuncs
415 #undef TARGET_IN_SMALL_DATA_P
416 #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p
417 #undef TARGET_RTX_COSTS
418 #define TARGET_RTX_COSTS frv_rtx_costs
419 #undef TARGET_ASM_CONSTRUCTOR
420 #define TARGET_ASM_CONSTRUCTOR frv_asm_out_constructor
421 #undef TARGET_ASM_DESTRUCTOR
422 #define TARGET_ASM_DESTRUCTOR frv_asm_out_destructor
424 #undef TARGET_ASM_OUTPUT_MI_THUNK
425 #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk
426 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
427 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
429 #undef TARGET_SCHED_ISSUE_RATE
430 #define TARGET_SCHED_ISSUE_RATE frv_issue_rate
432 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
433 #define TARGET_FUNCTION_OK_FOR_SIBCALL frv_function_ok_for_sibcall
434 #undef TARGET_CANNOT_FORCE_CONST_MEM
435 #define TARGET_CANNOT_FORCE_CONST_MEM frv_cannot_force_const_mem
437 #undef TARGET_HAVE_TLS
438 #define TARGET_HAVE_TLS HAVE_AS_TLS
440 #undef TARGET_STRUCT_VALUE_RTX
441 #define TARGET_STRUCT_VALUE_RTX frv_struct_value_rtx
442 #undef TARGET_MUST_PASS_IN_STACK
443 #define TARGET_MUST_PASS_IN_STACK frv_must_pass_in_stack
444 #undef TARGET_PASS_BY_REFERENCE
445 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
446 #undef TARGET_ARG_PARTIAL_BYTES
447 #define TARGET_ARG_PARTIAL_BYTES frv_arg_partial_bytes
449 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
450 #define TARGET_EXPAND_BUILTIN_SAVEREGS frv_expand_builtin_saveregs
451 #undef TARGET_SETUP_INCOMING_VARARGS
452 #define TARGET_SETUP_INCOMING_VARARGS frv_setup_incoming_varargs
453 #undef TARGET_MACHINE_DEPENDENT_REORG
454 #define TARGET_MACHINE_DEPENDENT_REORG frv_reorg
457 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
458 #define TARGET_ASM_OUTPUT_DWARF_DTPREL frv_output_dwarf_dtprel
461 struct gcc_target targetm = TARGET_INITIALIZER;
463 #define FRV_SYMBOL_REF_TLS_P(RTX) \
464 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
467 /* Any function call that satisfies the machine-independent
468 requirements is eligible on FR-V. */
471 frv_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
472 tree exp ATTRIBUTE_UNUSED)
477 /* Return true if SYMBOL is a small data symbol and relocation RELOC
478 can be used to access it directly in a load or store. */
480 static FRV_INLINE bool
481 frv_small_data_reloc_p (rtx symbol, int reloc)
483 return (GET_CODE (symbol) == SYMBOL_REF
484 && SYMBOL_REF_SMALL_P (symbol)
485 && (!TARGET_FDPIC || flag_pic == 1)
486 && (reloc == R_FRV_GOTOFF12 || reloc == R_FRV_GPREL12));
489 /* Return true if X is a valid relocation unspec. If it is, fill in UNSPEC
493 frv_const_unspec_p (rtx x, struct frv_unspec *unspec)
495 if (GET_CODE (x) == CONST)
499 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
501 unspec->offset += INTVAL (XEXP (x, 1));
504 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_GOT)
506 unspec->symbol = XVECEXP (x, 0, 0);
507 unspec->reloc = INTVAL (XVECEXP (x, 0, 1));
509 if (unspec->offset == 0)
512 if (frv_small_data_reloc_p (unspec->symbol, unspec->reloc)
513 && unspec->offset > 0
514 && (unsigned HOST_WIDE_INT) unspec->offset < g_switch_value)
521 /* Decide whether we can force certain constants to memory. If we
522 decide we can't, the caller should be able to cope with it in
525 We never allow constants to be forced into memory for TARGET_FDPIC.
526 This is necessary for several reasons:
528 1. Since LEGITIMATE_CONSTANT_P rejects constant pool addresses, the
529 target-independent code will try to force them into the constant
530 pool, thus leading to infinite recursion.
532 2. We can never introduce new constant pool references during reload.
533 Any such reference would require use of the pseudo FDPIC register.
535 3. We can't represent a constant added to a function pointer (which is
536 not the same as a pointer to a function+constant).
538 4. In many cases, it's more efficient to calculate the constant in-line. */
541 frv_cannot_force_const_mem (rtx x ATTRIBUTE_UNUSED)
546 /* Implement TARGET_HANDLE_OPTION. */
549 frv_handle_option (size_t code, const char *arg, int value ATTRIBUTE_UNUSED)
554 if (strcmp (arg, "simple") == 0)
555 frv_cpu_type = FRV_CPU_SIMPLE;
556 else if (strcmp (arg, "tomcat") == 0)
557 frv_cpu_type = FRV_CPU_TOMCAT;
558 else if (strcmp (arg, "fr550") == 0)
559 frv_cpu_type = FRV_CPU_FR550;
560 else if (strcmp (arg, "fr500") == 0)
561 frv_cpu_type = FRV_CPU_FR500;
562 else if (strcmp (arg, "fr450") == 0)
563 frv_cpu_type = FRV_CPU_FR450;
564 else if (strcmp (arg, "fr405") == 0)
565 frv_cpu_type = FRV_CPU_FR405;
566 else if (strcmp (arg, "fr400") == 0)
567 frv_cpu_type = FRV_CPU_FR400;
568 else if (strcmp (arg, "fr300") == 0)
569 frv_cpu_type = FRV_CPU_FR300;
570 else if (strcmp (arg, "frv") == 0)
571 frv_cpu_type = FRV_CPU_GENERIC;
582 frv_default_flags_for_cpu (void)
584 switch (frv_cpu_type)
586 case FRV_CPU_GENERIC:
587 return MASK_DEFAULT_FRV;
590 return MASK_DEFAULT_FR550;
594 return MASK_DEFAULT_FR500;
597 return MASK_DEFAULT_FR450;
601 return MASK_DEFAULT_FR400;
605 return MASK_DEFAULT_SIMPLE;
612 /* Sometimes certain combinations of command options do not make
613 sense on a particular target machine. You can define a macro
614 `OVERRIDE_OPTIONS' to take account of this. This macro, if
615 defined, is executed once just after all the command options have
618 Don't use this macro to turn on various extra optimizations for
619 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
622 frv_override_options (void)
627 target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit);
629 /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the
630 linker about linking pic and non-pic code. */
633 if (!flag_pic) /* -fPIC */
636 if (! g_switch_set) /* -G0 */
643 /* A C expression whose value is a register class containing hard
644 register REGNO. In general there is more than one such class;
645 choose a class which is "minimal", meaning that no smaller class
646 also contains the register. */
648 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
650 enum reg_class class;
654 int gpr_reg = regno - GPR_FIRST;
656 if (gpr_reg == GR8_REG)
659 else if (gpr_reg == GR9_REG)
662 else if (gpr_reg == GR14_REG)
663 class = FDPIC_FPTR_REGS;
665 else if (gpr_reg == FDPIC_REGNO)
668 else if ((gpr_reg & 3) == 0)
671 else if ((gpr_reg & 1) == 0)
678 else if (FPR_P (regno))
680 int fpr_reg = regno - GPR_FIRST;
681 if ((fpr_reg & 3) == 0)
682 class = QUAD_FPR_REGS;
684 else if ((fpr_reg & 1) == 0)
691 else if (regno == LR_REGNO)
694 else if (regno == LCR_REGNO)
697 else if (ICC_P (regno))
700 else if (FCC_P (regno))
703 else if (ICR_P (regno))
706 else if (FCR_P (regno))
709 else if (ACC_P (regno))
711 int r = regno - ACC_FIRST;
713 class = QUAD_ACC_REGS;
714 else if ((r & 1) == 0)
715 class = EVEN_ACC_REGS;
720 else if (ACCG_P (regno))
726 regno_reg_class[regno] = class;
729 /* Check for small data option */
731 g_switch_value = SDATA_DEFAULT_SIZE;
733 /* A C expression which defines the machine-dependent operand
734 constraint letters for register classes. If CHAR is such a
735 letter, the value should be the register class corresponding to
736 it. Otherwise, the value should be `NO_REGS'. The register
737 letter `r', corresponding to class `GENERAL_REGS', will not be
738 passed to this macro; you do not need to handle it.
740 The following letters are unavailable, due to being used as
745 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
746 'Q', 'R', 'S', 'T', 'U'
748 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
750 for (i = 0; i < 256; i++)
751 reg_class_from_letter[i] = NO_REGS;
753 reg_class_from_letter['a'] = ACC_REGS;
754 reg_class_from_letter['b'] = EVEN_ACC_REGS;
755 reg_class_from_letter['c'] = CC_REGS;
756 reg_class_from_letter['d'] = GPR_REGS;
757 reg_class_from_letter['e'] = EVEN_REGS;
758 reg_class_from_letter['f'] = FPR_REGS;
759 reg_class_from_letter['h'] = FEVEN_REGS;
760 reg_class_from_letter['l'] = LR_REG;
761 reg_class_from_letter['q'] = QUAD_REGS;
762 reg_class_from_letter['t'] = ICC_REGS;
763 reg_class_from_letter['u'] = FCC_REGS;
764 reg_class_from_letter['v'] = ICR_REGS;
765 reg_class_from_letter['w'] = FCR_REGS;
766 reg_class_from_letter['x'] = QUAD_FPR_REGS;
767 reg_class_from_letter['y'] = LCR_REG;
768 reg_class_from_letter['z'] = SPR_REGS;
769 reg_class_from_letter['A'] = QUAD_ACC_REGS;
770 reg_class_from_letter['B'] = ACCG_REGS;
771 reg_class_from_letter['C'] = CR_REGS;
772 reg_class_from_letter['W'] = FDPIC_CALL_REGS; /* gp14+15 */
773 reg_class_from_letter['Z'] = FDPIC_REGS; /* gp15 */
775 /* There is no single unaligned SI op for PIC code. Sometimes we
776 need to use ".4byte" and sometimes we need to use ".picptr".
777 See frv_assemble_integer for details. */
778 if (flag_pic || TARGET_FDPIC)
779 targetm.asm_out.unaligned_op.si = 0;
781 if ((target_flags_explicit & MASK_LINKED_FP) == 0)
782 target_flags |= MASK_LINKED_FP;
784 if ((target_flags_explicit & MASK_OPTIMIZE_MEMBAR) == 0)
785 target_flags |= MASK_OPTIMIZE_MEMBAR;
787 for (i = 0; i < ARRAY_SIZE (frv_unit_names); i++)
788 frv_unit_codes[i] = get_cpu_unit_code (frv_unit_names[i]);
790 for (i = 0; i < ARRAY_SIZE (frv_type_to_unit); i++)
791 frv_type_to_unit[i] = ARRAY_SIZE (frv_unit_codes);
793 init_machine_status = frv_init_machine_status;
797 /* Some machines may desire to change what optimizations are performed for
798 various optimization levels. This macro, if defined, is executed once just
799 after the optimization level is determined and before the remainder of the
800 command options have been parsed. Values set in this macro are used as the
801 default values for the other command line options.
803 LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if
804 `-O' is specified, and 0 if neither is specified.
806 SIZE is nonzero if `-Os' is specified, 0 otherwise.
808 You should not use this macro to change options that are not
809 machine-specific. These should uniformly selected by the same optimization
810 level on all supported machines. Use this macro to enable machine-specific
813 *Do not examine `write_symbols' in this macro!* The debugging options are
814 *not supposed to alter the generated code. */
816 /* On the FRV, possibly disable VLIW packing which is done by the 2nd
817 scheduling pass at the current time. */
819 frv_optimization_options (int level, int size ATTRIBUTE_UNUSED)
823 #ifdef DISABLE_SCHED2
824 flag_schedule_insns_after_reload = 0;
833 /* Return true if NAME (a STRING_CST node) begins with PREFIX. */
836 frv_string_begins_with (tree name, const char *prefix)
838 int prefix_len = strlen (prefix);
840 /* Remember: NAME's length includes the null terminator. */
841 return (TREE_STRING_LENGTH (name) > prefix_len
842 && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0);
845 /* Zero or more C statements that may conditionally modify two variables
846 `fixed_regs' and `call_used_regs' (both of type `char []') after they have
847 been initialized from the two preceding macros.
849 This is necessary in case the fixed or call-clobbered registers depend on
852 You need not define this macro if it has no work to do.
854 If the usage of an entire class of registers depends on the target flags,
855 you may indicate this to GCC by using this macro to modify `fixed_regs' and
856 `call_used_regs' to 1 for each of the registers in the classes which should
857 not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return
858 `NO_REGS' if it is called with a letter for a class that shouldn't be used.
860 (However, if this class is not included in `GENERAL_REGS' and all of the
861 insn patterns whose constraints permit this class are controlled by target
862 switches, then GCC will automatically avoid using these registers when the
863 target switches are opposed to them.) */
866 frv_conditional_register_usage (void)
870 for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++)
871 fixed_regs[i] = call_used_regs[i] = 1;
873 for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++)
874 fixed_regs[i] = call_used_regs[i] = 1;
876 /* Reserve the registers used for conditional execution. At present, we need
877 1 ICC and 1 ICR register. */
878 fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1;
879 fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1;
883 fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1;
884 fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1;
885 fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1;
886 fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1;
890 fixed_regs[GPR_FIRST + 16] = fixed_regs[GPR_FIRST + 17] =
891 call_used_regs[GPR_FIRST + 16] = call_used_regs[GPR_FIRST + 17] = 0;
894 /* If -fpic, SDA_BASE_REG is the PIC register. */
895 if (g_switch_value == 0 && !flag_pic)
896 fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0;
899 fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0;
905 * Compute the stack frame layout
908 * +---------------+-----------------------+-----------------------+
909 * |Register |type |caller-save/callee-save|
910 * +---------------+-----------------------+-----------------------+
911 * |GR0 |Zero register | - |
912 * |GR1 |Stack pointer(SP) | - |
913 * |GR2 |Frame pointer(FP) | - |
914 * |GR3 |Hidden parameter | caller save |
915 * |GR4-GR7 | - | caller save |
916 * |GR8-GR13 |Argument register | caller save |
917 * |GR14-GR15 | - | caller save |
918 * |GR16-GR31 | - | callee save |
919 * |GR32-GR47 | - | caller save |
920 * |GR48-GR63 | - | callee save |
921 * |FR0-FR15 | - | caller save |
922 * |FR16-FR31 | - | callee save |
923 * |FR32-FR47 | - | caller save |
924 * |FR48-FR63 | - | callee save |
925 * +---------------+-----------------------+-----------------------+
929 * SP-> |-----------------------------------|
931 * |-----------------------------------|
932 * | Register save area |
933 * |-----------------------------------|
934 * | Local variable save area |
935 * FP-> |-----------------------------------|
937 * |-----------------------------------|
938 * | Hidden parameter save area |
939 * |-----------------------------------|
940 * | Return address(LR) storage area |
941 * |-----------------------------------|
942 * | Padding for alignment |
943 * |-----------------------------------|
944 * | Register argument area |
945 * OLD SP-> |-----------------------------------|
947 * |-----------------------------------|
950 * Argument area/Parameter area:
952 * When a function is called, this area is used for argument transfer. When
953 * the argument is set up by the caller function, this area is referred to as
954 * the argument area. When the argument is referenced by the callee function,
955 * this area is referred to as the parameter area. The area is allocated when
956 * all arguments cannot be placed on the argument register at the time of
959 * Register save area:
961 * This is a register save area that must be guaranteed for the caller
962 * function. This area is not secured when the register save operation is not
965 * Local variable save area:
967 * This is the area for local variables and temporary variables.
971 * This area stores the FP value of the caller function.
973 * Hidden parameter save area:
975 * This area stores the start address of the return value storage
976 * area for a struct/union return function.
977 * When a struct/union is used as the return value, the caller
978 * function stores the return value storage area start address in
979 * register GR3 and passes it to the caller function.
980 * The callee function interprets the address stored in the GR3
981 * as the return value storage area start address.
982 * When register GR3 needs to be saved into memory, the callee
983 * function saves it in the hidden parameter save area. This
984 * area is not secured when the save operation is not needed.
986 * Return address(LR) storage area:
988 * This area saves the LR. The LR stores the address of a return to the caller
989 * function for the purpose of function calling.
991 * Argument register area:
993 * This area saves the argument register. This area is not secured when the
994 * save operation is not needed.
998 * Arguments, the count of which equals the count of argument registers (6
999 * words), are positioned in registers GR8 to GR13 and delivered to the callee
1000 * function. When a struct/union return function is called, the return value
1001 * area address is stored in register GR3. Arguments not placed in the
1002 * argument registers will be stored in the stack argument area for transfer
1003 * purposes. When an 8-byte type argument is to be delivered using registers,
1004 * it is divided into two and placed in two registers for transfer. When
1005 * argument registers must be saved to memory, the callee function secures an
1006 * argument register save area in the stack. In this case, a continuous
1007 * argument register save area must be established in the parameter area. The
1008 * argument register save area must be allocated as needed to cover the size of
1009 * the argument register to be saved. If the function has a variable count of
1010 * arguments, it saves all argument registers in the argument register save
1013 * Argument Extension Format:
1015 * When an argument is to be stored in the stack, its type is converted to an
1016 * extended type in accordance with the individual argument type. The argument
1017 * is freed by the caller function after the return from the callee function is
1020 * +-----------------------+---------------+------------------------+
1021 * | Argument Type |Extended Type |Stack Storage Size(byte)|
1022 * +-----------------------+---------------+------------------------+
1024 * |signed char |int | 4 |
1025 * |unsigned char |int | 4 |
1026 * |[signed] short int |int | 4 |
1027 * |unsigned short int |int | 4 |
1028 * |[signed] int |No extension | 4 |
1029 * |unsigned int |No extension | 4 |
1030 * |[signed] long int |No extension | 4 |
1031 * |unsigned long int |No extension | 4 |
1032 * |[signed] long long int |No extension | 8 |
1033 * |unsigned long long int |No extension | 8 |
1034 * |float |double | 8 |
1035 * |double |No extension | 8 |
1036 * |long double |No extension | 8 |
1037 * |pointer |No extension | 4 |
1038 * |struct/union |- | 4 (*1) |
1039 * +-----------------------+---------------+------------------------+
1041 * When a struct/union is to be delivered as an argument, the caller copies it
1042 * to the local variable area and delivers the address of that area.
1046 * +-------------------------------+----------------------+
1047 * |Return Value Type |Return Value Interface|
1048 * +-------------------------------+----------------------+
1050 * |[signed|unsigned] char |GR8 |
1051 * |[signed|unsigned] short int |GR8 |
1052 * |[signed|unsigned] int |GR8 |
1053 * |[signed|unsigned] long int |GR8 |
1055 * |[signed|unsigned] long long int|GR8 & GR9 |
1057 * |double |GR8 & GR9 |
1058 * |long double |GR8 & GR9 |
1059 * |struct/union |(*1) |
1060 * +-------------------------------+----------------------+
1062 * When a struct/union is used as the return value, the caller function stores
1063 * the start address of the return value storage area into GR3 and then passes
1064 * it to the callee function. The callee function interprets GR3 as the start
1065 * address of the return value storage area. When this address needs to be
1066 * saved in memory, the callee function secures the hidden parameter save area
1067 * and saves the address in that area.
1071 frv_stack_info (void)
1073 static frv_stack_t info, zero_info;
1074 frv_stack_t *info_ptr = &info;
1075 tree fndecl = current_function_decl;
1083 /* If we've already calculated the values and reload is complete,
1085 if (frv_stack_cache)
1086 return frv_stack_cache;
1088 /* Zero all fields. */
1091 /* Set up the register range information. */
1092 info_ptr->regs[STACK_REGS_GPR].name = "gpr";
1093 info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1;
1094 info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST;
1095 info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE;
1097 info_ptr->regs[STACK_REGS_FPR].name = "fpr";
1098 info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST;
1099 info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST;
1100 info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE;
1102 info_ptr->regs[STACK_REGS_LR].name = "lr";
1103 info_ptr->regs[STACK_REGS_LR].first = LR_REGNO;
1104 info_ptr->regs[STACK_REGS_LR].last = LR_REGNO;
1105 info_ptr->regs[STACK_REGS_LR].special_p = 1;
1107 info_ptr->regs[STACK_REGS_CC].name = "cc";
1108 info_ptr->regs[STACK_REGS_CC].first = CC_FIRST;
1109 info_ptr->regs[STACK_REGS_CC].last = CC_LAST;
1110 info_ptr->regs[STACK_REGS_CC].field_p = TRUE;
1112 info_ptr->regs[STACK_REGS_LCR].name = "lcr";
1113 info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO;
1114 info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO;
1116 info_ptr->regs[STACK_REGS_STDARG].name = "stdarg";
1117 info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM;
1118 info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM;
1119 info_ptr->regs[STACK_REGS_STDARG].dword_p = 1;
1120 info_ptr->regs[STACK_REGS_STDARG].special_p = 1;
1122 info_ptr->regs[STACK_REGS_STRUCT].name = "struct";
1123 info_ptr->regs[STACK_REGS_STRUCT].first = FRV_STRUCT_VALUE_REGNUM;
1124 info_ptr->regs[STACK_REGS_STRUCT].last = FRV_STRUCT_VALUE_REGNUM;
1125 info_ptr->regs[STACK_REGS_STRUCT].special_p = 1;
1127 info_ptr->regs[STACK_REGS_FP].name = "fp";
1128 info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM;
1129 info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM;
1130 info_ptr->regs[STACK_REGS_FP].special_p = 1;
1132 /* Determine if this is a stdarg function. If so, allocate space to store
1139 /* Find the last argument, and see if it is __builtin_va_alist. */
1140 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
1142 next_arg = TREE_CHAIN (cur_arg);
1143 if (next_arg == (tree)0)
1145 if (DECL_NAME (cur_arg)
1146 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
1154 /* Iterate over all of the register ranges. */
1155 for (range = 0; range < STACK_REGS_MAX; range++)
1157 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1158 int first = reg_ptr->first;
1159 int last = reg_ptr->last;
1161 int size_2words = 0;
1164 /* Calculate which registers need to be saved & save area size. */
1168 for (regno = first; regno <= last; regno++)
1170 if ((regs_ever_live[regno] && !call_used_regs[regno])
1171 || (current_function_calls_eh_return
1172 && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM))
1173 || (!TARGET_FDPIC && flag_pic
1174 && cfun->uses_pic_offset_table && regno == PIC_REGNO))
1176 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1177 size_1word += UNITS_PER_WORD;
1182 /* Calculate whether we need to create a frame after everything else
1183 has been processed. */
1188 if (regs_ever_live[LR_REGNO]
1190 /* This is set for __builtin_return_address, etc. */
1191 || cfun->machine->frame_needed
1192 || (TARGET_LINKED_FP && frame_pointer_needed)
1193 || (!TARGET_FDPIC && flag_pic
1194 && cfun->uses_pic_offset_table))
1196 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1197 size_1word += UNITS_PER_WORD;
1201 case STACK_REGS_STDARG:
1204 /* If this is a stdarg function with a non varardic
1205 argument split between registers and the stack,
1206 adjust the saved registers downward. */
1207 last -= (ADDR_ALIGN (cfun->pretend_args_size, UNITS_PER_WORD)
1210 for (regno = first; regno <= last; regno++)
1212 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1213 size_1word += UNITS_PER_WORD;
1216 info_ptr->stdarg_size = size_1word;
1220 case STACK_REGS_STRUCT:
1221 if (cfun->returns_struct)
1223 info_ptr->save_p[FRV_STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1224 size_1word += UNITS_PER_WORD;
1232 /* If this is a field, it only takes one word. */
1233 if (reg_ptr->field_p)
1234 size_1word = UNITS_PER_WORD;
1236 /* Determine which register pairs can be saved together. */
1237 else if (reg_ptr->dword_p && TARGET_DWORD)
1239 for (regno = first; regno < last; regno += 2)
1241 if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1])
1243 size_2words += 2 * UNITS_PER_WORD;
1244 size_1word -= 2 * UNITS_PER_WORD;
1245 info_ptr->save_p[regno] = REG_SAVE_2WORDS;
1246 info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE;
1251 reg_ptr->size_1word = size_1word;
1252 reg_ptr->size_2words = size_2words;
1254 if (! reg_ptr->special_p)
1256 info_ptr->regs_size_1word += size_1word;
1257 info_ptr->regs_size_2words += size_2words;
1262 /* Set up the sizes of each each field in the frame body, making the sizes
1263 of each be divisible by the size of a dword if dword operations might
1264 be used, or the size of a word otherwise. */
1265 alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD);
1267 info_ptr->parameter_size = ADDR_ALIGN (cfun->outgoing_args_size, alignment);
1268 info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words
1269 + info_ptr->regs_size_1word,
1271 info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment);
1273 info_ptr->pretend_size = cfun->pretend_args_size;
1275 /* Work out the size of the frame, excluding the header. Both the frame
1276 body and register parameter area will be dword-aligned. */
1277 info_ptr->total_size
1278 = (ADDR_ALIGN (info_ptr->parameter_size
1279 + info_ptr->regs_size
1280 + info_ptr->vars_size,
1282 + ADDR_ALIGN (info_ptr->pretend_size
1283 + info_ptr->stdarg_size,
1284 2 * UNITS_PER_WORD));
1286 /* See if we need to create a frame at all, if so add header area. */
1287 if (info_ptr->total_size > 0
1288 || frame_pointer_needed
1289 || info_ptr->regs[STACK_REGS_LR].size_1word > 0
1290 || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0)
1292 offset = info_ptr->parameter_size;
1293 info_ptr->header_size = 4 * UNITS_PER_WORD;
1294 info_ptr->total_size += 4 * UNITS_PER_WORD;
1296 /* Calculate the offsets to save normal register pairs. */
1297 for (range = 0; range < STACK_REGS_MAX; range++)
1299 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1300 if (! reg_ptr->special_p)
1302 int first = reg_ptr->first;
1303 int last = reg_ptr->last;
1306 for (regno = first; regno <= last; regno++)
1307 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS
1308 && regno != FRAME_POINTER_REGNUM
1309 && (regno < FIRST_ARG_REGNUM
1310 || regno > LAST_ARG_REGNUM))
1312 info_ptr->reg_offset[regno] = offset;
1313 offset += 2 * UNITS_PER_WORD;
1318 /* Calculate the offsets to save normal single registers. */
1319 for (range = 0; range < STACK_REGS_MAX; range++)
1321 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1322 if (! reg_ptr->special_p)
1324 int first = reg_ptr->first;
1325 int last = reg_ptr->last;
1328 for (regno = first; regno <= last; regno++)
1329 if (info_ptr->save_p[regno] == REG_SAVE_1WORD
1330 && regno != FRAME_POINTER_REGNUM
1331 && (regno < FIRST_ARG_REGNUM
1332 || regno > LAST_ARG_REGNUM))
1334 info_ptr->reg_offset[regno] = offset;
1335 offset += UNITS_PER_WORD;
1340 /* Calculate the offset to save the local variables at. */
1341 offset = ADDR_ALIGN (offset, alignment);
1342 if (info_ptr->vars_size)
1344 info_ptr->vars_offset = offset;
1345 offset += info_ptr->vars_size;
1348 /* Align header to a dword-boundary. */
1349 offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD);
1351 /* Calculate the offsets in the fixed frame. */
1352 info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD;
1353 info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset;
1354 info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD;
1356 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1357 info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD;
1358 info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD;
1360 if (cfun->returns_struct)
1362 info_ptr->save_p[FRV_STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1363 info_ptr->reg_offset[FRV_STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD;
1364 info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD;
1367 /* Calculate the offsets to store the arguments passed in registers
1368 for stdarg functions. The register pairs are first and the single
1369 register if any is last. The register save area starts on a
1371 if (info_ptr->stdarg_size)
1373 int first = info_ptr->regs[STACK_REGS_STDARG].first;
1374 int last = info_ptr->regs[STACK_REGS_STDARG].last;
1377 /* Skip the header. */
1378 offset += 4 * UNITS_PER_WORD;
1379 for (regno = first; regno <= last; regno++)
1381 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS)
1383 info_ptr->reg_offset[regno] = offset;
1384 offset += 2 * UNITS_PER_WORD;
1386 else if (info_ptr->save_p[regno] == REG_SAVE_1WORD)
1388 info_ptr->reg_offset[regno] = offset;
1389 offset += UNITS_PER_WORD;
1395 if (reload_completed)
1396 frv_stack_cache = info_ptr;
1402 /* Print the information about the frv stack offsets, etc. when debugging. */
1405 frv_debug_stack (frv_stack_t *info)
1410 info = frv_stack_info ();
1412 fprintf (stderr, "\nStack information for function %s:\n",
1413 ((current_function_decl && DECL_NAME (current_function_decl))
1414 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1417 fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size);
1418 fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size);
1419 fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size);
1420 fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n",
1421 info->regs_size, info->regs_size_1word, info->regs_size_2words);
1423 fprintf (stderr, "\theader_size\t= %6d\n", info->header_size);
1424 fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size);
1425 fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset);
1426 fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset);
1428 for (range = 0; range < STACK_REGS_MAX; range++)
1430 frv_stack_regs_t *regs = &(info->regs[range]);
1431 if ((regs->size_1word + regs->size_2words) > 0)
1433 int first = regs->first;
1434 int last = regs->last;
1437 fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =",
1438 regs->name, regs->size_1word + regs->size_2words,
1439 regs->size_1word, regs->size_2words);
1441 for (regno = first; regno <= last; regno++)
1443 if (info->save_p[regno] == REG_SAVE_1WORD)
1444 fprintf (stderr, " %s (%d)", reg_names[regno],
1445 info->reg_offset[regno]);
1447 else if (info->save_p[regno] == REG_SAVE_2WORDS)
1448 fprintf (stderr, " %s-%s (%d)", reg_names[regno],
1449 reg_names[regno+1], info->reg_offset[regno]);
1452 fputc ('\n', stderr);
1462 /* Used during final to control the packing of insns. The value is
1463 1 if the current instruction should be packed with the next one,
1464 0 if it shouldn't or -1 if packing is disabled altogether. */
1466 static int frv_insn_packing_flag;
1468 /* True if the current function contains a far jump. */
1471 frv_function_contains_far_jump (void)
1473 rtx insn = get_insns ();
1475 && !(GET_CODE (insn) == JUMP_INSN
1476 /* Ignore tablejump patterns. */
1477 && GET_CODE (PATTERN (insn)) != ADDR_VEC
1478 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
1479 && get_attr_far_jump (insn) == FAR_JUMP_YES))
1480 insn = NEXT_INSN (insn);
1481 return (insn != NULL);
1484 /* For the FRV, this function makes sure that a function with far jumps
1485 will return correctly. It also does the VLIW packing. */
1488 frv_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1490 /* If no frame was created, check whether the function uses a call
1491 instruction to implement a far jump. If so, save the link in gr3 and
1492 replace all returns to LR with returns to GR3. GR3 is used because it
1493 is call-clobbered, because is not available to the register allocator,
1494 and because all functions that take a hidden argument pointer will have
1496 if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ())
1500 /* Just to check that the above comment is true. */
1501 gcc_assert (!regs_ever_live[GPR_FIRST + 3]);
1503 /* Generate the instruction that saves the link register. */
1504 fprintf (file, "\tmovsg lr,gr3\n");
1506 /* Replace the LR with GR3 in *return_internal patterns. The insn
1507 will now return using jmpl @(gr3,0) rather than bralr. We cannot
1508 simply emit a different assembly directive because bralr and jmpl
1509 execute in different units. */
1510 for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn))
1511 if (GET_CODE (insn) == JUMP_INSN)
1513 rtx pattern = PATTERN (insn);
1514 if (GET_CODE (pattern) == PARALLEL
1515 && XVECLEN (pattern, 0) >= 2
1516 && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN
1517 && GET_CODE (XVECEXP (pattern, 0, 1)) == USE)
1519 rtx address = XEXP (XVECEXP (pattern, 0, 1), 0);
1520 if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO)
1521 REGNO (address) = GPR_FIRST + 3;
1528 /* Allow the garbage collector to free the nops created by frv_reorg. */
1529 memset (frv_nops, 0, sizeof (frv_nops));
1533 /* Return the next available temporary register in a given class. */
1536 frv_alloc_temp_reg (
1537 frv_tmp_reg_t *info, /* which registers are available */
1538 enum reg_class class, /* register class desired */
1539 enum machine_mode mode, /* mode to allocate register with */
1540 int mark_as_used, /* register not available after allocation */
1541 int no_abort) /* return NULL instead of aborting */
1543 int regno = info->next_reg[ (int)class ];
1544 int orig_regno = regno;
1545 HARD_REG_SET *reg_in_class = ®_class_contents[ (int)class ];
1550 if (TEST_HARD_REG_BIT (*reg_in_class, regno)
1551 && TEST_HARD_REG_BIT (info->regs, regno))
1554 if (++regno >= FIRST_PSEUDO_REGISTER)
1556 if (regno == orig_regno)
1558 gcc_assert (no_abort);
1563 nr = HARD_REGNO_NREGS (regno, mode);
1564 info->next_reg[ (int)class ] = regno + nr;
1567 for (i = 0; i < nr; i++)
1568 CLEAR_HARD_REG_BIT (info->regs, regno+i);
1570 return gen_rtx_REG (mode, regno);
1574 /* Return an rtx with the value OFFSET, which will either be a register or a
1575 signed 12-bit integer. It can be used as the second operand in an "add"
1576 instruction, or as the index in a load or store.
1578 The function returns a constant rtx if OFFSET is small enough, otherwise
1579 it loads the constant into register OFFSET_REGNO and returns that. */
1581 frv_frame_offset_rtx (int offset)
1583 rtx offset_rtx = GEN_INT (offset);
1584 if (IN_RANGE_P (offset, -2048, 2047))
1588 rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO);
1589 if (IN_RANGE_P (offset, -32768, 32767))
1590 emit_insn (gen_movsi (reg_rtx, offset_rtx));
1593 emit_insn (gen_movsi_high (reg_rtx, offset_rtx));
1594 emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx));
1600 /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The
1601 prologue and epilogue uses such expressions to access the stack. */
1603 frv_frame_mem (enum machine_mode mode, rtx base, int offset)
1605 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode,
1607 frv_frame_offset_rtx (offset)));
1610 /* Generate a frame-related expression:
1612 (set REG (mem (plus (sp) (const_int OFFSET)))).
1614 Such expressions are used in FRAME_RELATED_EXPR notes for more complex
1615 instructions. Marking the expressions as frame-related is superfluous if
1616 the note contains just a single set. But if the note contains a PARALLEL
1617 or SEQUENCE that has several sets, each set must be individually marked
1618 as frame-related. */
1620 frv_dwarf_store (rtx reg, int offset)
1622 rtx set = gen_rtx_SET (VOIDmode,
1623 gen_rtx_MEM (GET_MODE (reg),
1624 plus_constant (stack_pointer_rtx,
1627 RTX_FRAME_RELATED_P (set) = 1;
1631 /* Emit a frame-related instruction whose pattern is PATTERN. The
1632 instruction is the last in a sequence that cumulatively performs the
1633 operation described by DWARF_PATTERN. The instruction is marked as
1634 frame-related and has a REG_FRAME_RELATED_EXPR note containing
1637 frv_frame_insn (rtx pattern, rtx dwarf_pattern)
1639 rtx insn = emit_insn (pattern);
1640 RTX_FRAME_RELATED_P (insn) = 1;
1641 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1646 /* Emit instructions that transfer REG to or from the memory location (sp +
1647 STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is
1648 FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this
1649 function to store registers and only the epilogue uses it to load them.
1651 The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET).
1652 The generated instruction will use BASE as its base register. BASE may
1653 simply be the stack pointer, but if several accesses are being made to a
1654 region far away from the stack pointer, it may be more efficient to set
1655 up a temporary instead.
1657 Store instructions will be frame-related and will be annotated with the
1658 overall effect of the store. Load instructions will be followed by a
1659 (use) to prevent later optimizations from zapping them.
1661 The function takes care of the moves to and from SPRs, using TEMP_REGNO
1662 as a temporary in such cases. */
1664 frv_frame_access (frv_frame_accessor_t *accessor, rtx reg, int stack_offset)
1666 enum machine_mode mode = GET_MODE (reg);
1667 rtx mem = frv_frame_mem (mode,
1669 stack_offset - accessor->base_offset);
1671 if (accessor->op == FRV_LOAD)
1673 if (SPR_P (REGNO (reg)))
1675 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1676 emit_insn (gen_rtx_SET (VOIDmode, temp, mem));
1677 emit_insn (gen_rtx_SET (VOIDmode, reg, temp));
1680 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
1681 emit_insn (gen_rtx_USE (VOIDmode, reg));
1685 if (SPR_P (REGNO (reg)))
1687 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1688 emit_insn (gen_rtx_SET (VOIDmode, temp, reg));
1689 frv_frame_insn (gen_rtx_SET (Pmode, mem, temp),
1690 frv_dwarf_store (reg, stack_offset));
1692 else if (GET_MODE (reg) == DImode)
1694 /* For DImode saves, the dwarf2 version needs to be a SEQUENCE
1695 with a separate save for each register. */
1696 rtx reg1 = gen_rtx_REG (SImode, REGNO (reg));
1697 rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1);
1698 rtx set1 = frv_dwarf_store (reg1, stack_offset);
1699 rtx set2 = frv_dwarf_store (reg2, stack_offset + 4);
1700 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1701 gen_rtx_PARALLEL (VOIDmode,
1702 gen_rtvec (2, set1, set2)));
1705 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1706 frv_dwarf_store (reg, stack_offset));
1710 /* A function that uses frv_frame_access to transfer a group of registers to
1711 or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO
1712 is the stack information generated by frv_stack_info, and REG_SET is the
1713 number of the register set to transfer. */
1715 frv_frame_access_multi (frv_frame_accessor_t *accessor,
1719 frv_stack_regs_t *regs_info;
1722 regs_info = &info->regs[reg_set];
1723 for (regno = regs_info->first; regno <= regs_info->last; regno++)
1724 if (info->save_p[regno])
1725 frv_frame_access (accessor,
1726 info->save_p[regno] == REG_SAVE_2WORDS
1727 ? gen_rtx_REG (DImode, regno)
1728 : gen_rtx_REG (SImode, regno),
1729 info->reg_offset[regno]);
1732 /* Save or restore callee-saved registers that are kept outside the frame
1733 header. The function saves the registers if OP is FRV_STORE and restores
1734 them if OP is FRV_LOAD. INFO is the stack information generated by
1737 frv_frame_access_standard_regs (enum frv_stack_op op, frv_stack_t *info)
1739 frv_frame_accessor_t accessor;
1742 accessor.base = stack_pointer_rtx;
1743 accessor.base_offset = 0;
1744 frv_frame_access_multi (&accessor, info, STACK_REGS_GPR);
1745 frv_frame_access_multi (&accessor, info, STACK_REGS_FPR);
1746 frv_frame_access_multi (&accessor, info, STACK_REGS_LCR);
1750 /* Called after register allocation to add any instructions needed for the
1751 prologue. Using a prologue insn is favored compared to putting all of the
1752 instructions in the TARGET_ASM_FUNCTION_PROLOGUE target hook, since
1753 it allows the scheduler to intermix instructions with the saves of
1754 the caller saved registers. In some cases, it might be necessary
1755 to emit a barrier instruction as the last insn to prevent such
1758 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
1759 so that the debug info generation code can handle them properly. */
1761 frv_expand_prologue (void)
1763 frv_stack_t *info = frv_stack_info ();
1764 rtx sp = stack_pointer_rtx;
1765 rtx fp = frame_pointer_rtx;
1766 frv_frame_accessor_t accessor;
1768 if (TARGET_DEBUG_STACK)
1769 frv_debug_stack (info);
1771 if (info->total_size == 0)
1774 /* We're interested in three areas of the frame here:
1776 A: the register save area
1778 C: the header after B
1780 If the frame pointer isn't used, we'll have to set up A, B and C
1781 using the stack pointer. If the frame pointer is used, we'll access
1785 B: set up using sp or a temporary (see below)
1788 We set up B using the stack pointer if the frame is small enough.
1789 Otherwise, it's more efficient to copy the old stack pointer into a
1790 temporary and use that.
1792 Note that it's important to make sure the prologue and epilogue use the
1793 same registers to access A and C, since doing otherwise will confuse
1794 the aliasing code. */
1796 /* Set up ACCESSOR for accessing region B above. If the frame pointer
1797 isn't used, the same method will serve for C. */
1798 accessor.op = FRV_STORE;
1799 if (frame_pointer_needed && info->total_size > 2048)
1803 accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO);
1804 accessor.base_offset = info->total_size;
1805 insn = emit_insn (gen_movsi (accessor.base, sp));
1809 accessor.base = stack_pointer_rtx;
1810 accessor.base_offset = 0;
1813 /* Allocate the stack space. */
1815 rtx asm_offset = frv_frame_offset_rtx (-info->total_size);
1816 rtx dwarf_offset = GEN_INT (-info->total_size);
1818 frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset),
1821 gen_rtx_PLUS (Pmode, sp, dwarf_offset)));
1824 /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET)
1825 and point the new one to that location. */
1826 if (frame_pointer_needed)
1828 int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1830 /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is
1831 based on ACCESSOR.BASE but DWARF_SRC is always based on the stack
1833 rtx asm_src = plus_constant (accessor.base,
1834 fp_offset - accessor.base_offset);
1835 rtx dwarf_src = plus_constant (sp, fp_offset);
1837 /* Store the old frame pointer at (sp + FP_OFFSET). */
1838 frv_frame_access (&accessor, fp, fp_offset);
1840 /* Set up the new frame pointer. */
1841 frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src),
1842 gen_rtx_SET (VOIDmode, fp, dwarf_src));
1844 /* Access region C from the frame pointer. */
1846 accessor.base_offset = fp_offset;
1849 /* Set up region C. */
1850 frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT);
1851 frv_frame_access_multi (&accessor, info, STACK_REGS_LR);
1852 frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG);
1854 /* Set up region A. */
1855 frv_frame_access_standard_regs (FRV_STORE, info);
1857 /* If this is a varargs/stdarg function, issue a blockage to prevent the
1858 scheduler from moving loads before the stores saving the registers. */
1859 if (info->stdarg_size > 0)
1860 emit_insn (gen_blockage ());
1862 /* Set up pic register/small data register for this function. */
1863 if (!TARGET_FDPIC && flag_pic && cfun->uses_pic_offset_table)
1864 emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO),
1865 gen_rtx_REG (Pmode, LR_REGNO),
1866 gen_rtx_REG (SImode, OFFSET_REGNO)));
1870 /* Under frv, all of the work is done via frv_expand_epilogue, but
1871 this function provides a convenient place to do cleanup. */
1874 frv_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
1875 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1877 frv_stack_cache = (frv_stack_t *)0;
1879 /* Zap last used registers for conditional execution. */
1880 memset (&frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg));
1882 /* Release the bitmap of created insns. */
1883 BITMAP_FREE (frv_ifcvt.scratch_insns_bitmap);
1887 /* Called after register allocation to add any instructions needed for the
1888 epilogue. Using an epilogue insn is favored compared to putting all of the
1889 instructions in the TARGET_ASM_FUNCTION_PROLOGUE target hook, since
1890 it allows the scheduler to intermix instructions with the saves of
1891 the caller saved registers. In some cases, it might be necessary
1892 to emit a barrier instruction as the last insn to prevent such
1896 frv_expand_epilogue (bool emit_return)
1898 frv_stack_t *info = frv_stack_info ();
1899 rtx fp = frame_pointer_rtx;
1900 rtx sp = stack_pointer_rtx;
1904 fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1906 /* Restore the stack pointer to its original value if alloca or the like
1908 if (! current_function_sp_is_unchanging)
1909 emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset)));
1911 /* Restore the callee-saved registers that were used in this function. */
1912 frv_frame_access_standard_regs (FRV_LOAD, info);
1914 /* Set RETURN_ADDR to the address we should return to. Set it to NULL if
1915 no return instruction should be emitted. */
1916 if (info->save_p[LR_REGNO])
1921 /* Use the same method to access the link register's slot as we did in
1922 the prologue. In other words, use the frame pointer if available,
1923 otherwise use the stack pointer.
1925 LR_OFFSET is the offset of the link register's slot from the start
1926 of the frame and MEM is a memory rtx for it. */
1927 lr_offset = info->reg_offset[LR_REGNO];
1928 if (frame_pointer_needed)
1929 mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset);
1931 mem = frv_frame_mem (Pmode, sp, lr_offset);
1933 /* Load the old link register into a GPR. */
1934 return_addr = gen_rtx_REG (Pmode, TEMP_REGNO);
1935 emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem));
1938 return_addr = gen_rtx_REG (Pmode, LR_REGNO);
1940 /* Restore the old frame pointer. Emit a USE afterwards to make sure
1941 the load is preserved. */
1942 if (frame_pointer_needed)
1944 emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp)));
1945 emit_insn (gen_rtx_USE (VOIDmode, fp));
1948 /* Deallocate the stack frame. */
1949 if (info->total_size != 0)
1951 rtx offset = frv_frame_offset_rtx (info->total_size);
1952 emit_insn (gen_stack_adjust (sp, sp, offset));
1955 /* If this function uses eh_return, add the final stack adjustment now. */
1956 if (current_function_calls_eh_return)
1957 emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX));
1960 emit_jump_insn (gen_epilogue_return (return_addr));
1963 rtx lr = return_addr;
1965 if (REGNO (return_addr) != LR_REGNO)
1967 lr = gen_rtx_REG (Pmode, LR_REGNO);
1968 emit_move_insn (lr, return_addr);
1971 emit_insn (gen_rtx_USE (VOIDmode, lr));
1976 /* Worker function for TARGET_ASM_OUTPUT_MI_THUNK. */
1979 frv_asm_output_mi_thunk (FILE *file,
1980 tree thunk_fndecl ATTRIBUTE_UNUSED,
1981 HOST_WIDE_INT delta,
1982 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
1985 const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0);
1986 const char *name_arg0 = reg_names[FIRST_ARG_REGNUM];
1987 const char *name_jmp = reg_names[JUMP_REGNO];
1988 const char *parallel = (frv_issue_rate () > 1 ? ".p" : "");
1990 /* Do the add using an addi if possible. */
1991 if (IN_RANGE_P (delta, -2048, 2047))
1992 fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0);
1995 const char *const name_add = reg_names[TEMP_REGNO];
1996 fprintf (file, "\tsethi%s #hi(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1997 parallel, delta, name_add);
1998 fprintf (file, "\tsetlo #lo(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
2000 fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0);
2005 const char *name_pic = reg_names[FDPIC_REGNO];
2006 name_jmp = reg_names[FDPIC_FPTR_REGNO];
2010 fprintf (file, "\tsethi%s #gotofffuncdeschi(", parallel);
2011 assemble_name (file, name_func);
2012 fprintf (file, "),%s\n", name_jmp);
2014 fprintf (file, "\tsetlo #gotofffuncdesclo(");
2015 assemble_name (file, name_func);
2016 fprintf (file, "),%s\n", name_jmp);
2018 fprintf (file, "\tldd @(%s,%s), %s\n", name_jmp, name_pic, name_jmp);
2022 fprintf (file, "\tlddo @(%s,#gotofffuncdesc12(", name_pic);
2023 assemble_name (file, name_func);
2024 fprintf (file, "\t)), %s\n", name_jmp);
2029 fprintf (file, "\tsethi%s #hi(", parallel);
2030 assemble_name (file, name_func);
2031 fprintf (file, "),%s\n", name_jmp);
2033 fprintf (file, "\tsetlo #lo(");
2034 assemble_name (file, name_func);
2035 fprintf (file, "),%s\n", name_jmp);
2039 /* Use JUMP_REGNO as a temporary PIC register. */
2040 const char *name_lr = reg_names[LR_REGNO];
2041 const char *name_gppic = name_jmp;
2042 const char *name_tmp = reg_names[TEMP_REGNO];
2044 fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp);
2045 fprintf (file, "\tcall 1f\n");
2046 fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic);
2047 fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr);
2048 fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp);
2049 fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp);
2050 fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic);
2052 fprintf (file, "\tsethi%s #gprelhi(", parallel);
2053 assemble_name (file, name_func);
2054 fprintf (file, "),%s\n", name_tmp);
2056 fprintf (file, "\tsetlo #gprello(");
2057 assemble_name (file, name_func);
2058 fprintf (file, "),%s\n", name_tmp);
2060 fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp);
2063 /* Jump to the function address. */
2064 fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]);
2068 /* A C expression which is nonzero if a function must have and use a frame
2069 pointer. This expression is evaluated in the reload pass. If its value is
2070 nonzero the function will have a frame pointer.
2072 The expression can in principle examine the current function and decide
2073 according to the facts, but on most machines the constant 0 or the constant
2074 1 suffices. Use 0 when the machine allows code to be generated with no
2075 frame pointer, and doing so saves some time or space. Use 1 when there is
2076 no possible advantage to avoiding a frame pointer.
2078 In certain cases, the compiler does not know how to produce valid code
2079 without a frame pointer. The compiler recognizes those cases and
2080 automatically gives the function a frame pointer regardless of what
2081 `FRAME_POINTER_REQUIRED' says. You don't need to worry about them.
2083 In a function that does not require a frame pointer, the frame pointer
2084 register can be allocated for ordinary usage, unless you mark it as a fixed
2085 register. See `FIXED_REGISTERS' for more information. */
2087 /* On frv, create a frame whenever we need to create stack. */
2090 frv_frame_pointer_required (void)
2092 /* If we forgoing the usual linkage requirements, we only need
2093 a frame pointer if the stack pointer might change. */
2094 if (!TARGET_LINKED_FP)
2095 return !current_function_sp_is_unchanging;
2097 if (! current_function_is_leaf)
2100 if (get_frame_size () != 0)
2106 if (!current_function_sp_is_unchanging)
2109 if (!TARGET_FDPIC && flag_pic && cfun->uses_pic_offset_table)
2115 if (cfun->machine->frame_needed)
2122 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the
2123 initial difference between the specified pair of registers. This macro must
2124 be defined if `ELIMINABLE_REGS' is defined. */
2126 /* See frv_stack_info for more details on the frv stack frame. */
2129 frv_initial_elimination_offset (int from, int to)
2131 frv_stack_t *info = frv_stack_info ();
2134 if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2135 ret = info->total_size - info->pretend_size;
2137 else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM)
2138 ret = info->reg_offset[FRAME_POINTER_REGNUM];
2140 else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2141 ret = (info->total_size
2142 - info->reg_offset[FRAME_POINTER_REGNUM]
2143 - info->pretend_size);
2148 if (TARGET_DEBUG_STACK)
2149 fprintf (stderr, "Eliminate %s to %s by adding %d\n",
2150 reg_names [from], reg_names[to], ret);
2156 /* Worker function for TARGET_SETUP_INCOMING_VARARGS. */
2159 frv_setup_incoming_varargs (CUMULATIVE_ARGS *cum,
2160 enum machine_mode mode,
2161 tree type ATTRIBUTE_UNUSED,
2165 if (TARGET_DEBUG_ARG)
2167 "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n",
2168 *cum, GET_MODE_NAME (mode), *pretend_size, second_time);
2172 /* Worker function for TARGET_EXPAND_BUILTIN_SAVEREGS. */
2175 frv_expand_builtin_saveregs (void)
2177 int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS;
2179 if (TARGET_DEBUG_ARG)
2180 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2183 return gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2187 /* Expand __builtin_va_start to do the va_start macro. */
2190 frv_expand_builtin_va_start (tree valist, rtx nextarg)
2193 int num = cfun->args_info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS;
2195 nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx,
2196 GEN_INT (UNITS_PER_WORD * num));
2198 if (TARGET_DEBUG_ARG)
2200 fprintf (stderr, "va_start: args_info = %d, num = %d\n",
2201 cfun->args_info, num);
2203 debug_rtx (nextarg);
2206 t = build2 (GIMPLE_MODIFY_STMT, TREE_TYPE (valist), valist,
2207 make_tree (ptr_type_node, nextarg));
2208 TREE_SIDE_EFFECTS (t) = 1;
2210 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2214 /* Expand a block move operation, and return 1 if successful. Return 0
2215 if we should let the compiler generate normal code.
2217 operands[0] is the destination
2218 operands[1] is the source
2219 operands[2] is the length
2220 operands[3] is the alignment */
2222 /* Maximum number of loads to do before doing the stores */
2223 #ifndef MAX_MOVE_REG
2224 #define MAX_MOVE_REG 4
2227 /* Maximum number of total loads to do. */
2228 #ifndef TOTAL_MOVE_REG
2229 #define TOTAL_MOVE_REG 8
2233 frv_expand_block_move (rtx operands[])
2235 rtx orig_dest = operands[0];
2236 rtx orig_src = operands[1];
2237 rtx bytes_rtx = operands[2];
2238 rtx align_rtx = operands[3];
2239 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2252 rtx stores[MAX_MOVE_REG];
2254 enum machine_mode mode;
2256 /* If this is not a fixed size move, just call memcpy. */
2260 /* This should be a fixed size alignment. */
2261 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
2263 align = INTVAL (align_rtx);
2265 /* Anything to move? */
2266 bytes = INTVAL (bytes_rtx);
2270 /* Don't support real large moves. */
2271 if (bytes > TOTAL_MOVE_REG*align)
2274 /* Move the address into scratch registers. */
2275 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2276 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2278 num_reg = offset = 0;
2279 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2281 /* Calculate the correct offset for src/dest. */
2285 dest_addr = dest_reg;
2289 src_addr = plus_constant (src_reg, offset);
2290 dest_addr = plus_constant (dest_reg, offset);
2293 /* Generate the appropriate load and store, saving the stores
2295 if (bytes >= 4 && align >= 4)
2297 else if (bytes >= 2 && align >= 2)
2302 move_bytes = GET_MODE_SIZE (mode);
2303 tmp_reg = gen_reg_rtx (mode);
2304 src_mem = change_address (orig_src, mode, src_addr);
2305 dest_mem = change_address (orig_dest, mode, dest_addr);
2306 emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem));
2307 stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg);
2309 if (num_reg >= MAX_MOVE_REG)
2311 for (i = 0; i < num_reg; i++)
2312 emit_insn (stores[i]);
2317 for (i = 0; i < num_reg; i++)
2318 emit_insn (stores[i]);
2324 /* Expand a block clear operation, and return 1 if successful. Return 0
2325 if we should let the compiler generate normal code.
2327 operands[0] is the destination
2328 operands[1] is the length
2329 operands[3] is the alignment */
2332 frv_expand_block_clear (rtx operands[])
2334 rtx orig_dest = operands[0];
2335 rtx bytes_rtx = operands[1];
2336 rtx align_rtx = operands[3];
2337 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2346 enum machine_mode mode;
2348 /* If this is not a fixed size move, just call memcpy. */
2352 /* This should be a fixed size alignment. */
2353 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
2355 align = INTVAL (align_rtx);
2357 /* Anything to move? */
2358 bytes = INTVAL (bytes_rtx);
2362 /* Don't support real large clears. */
2363 if (bytes > TOTAL_MOVE_REG*align)
2366 /* Move the address into a scratch register. */
2367 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2369 num_reg = offset = 0;
2370 for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes))
2372 /* Calculate the correct offset for src/dest. */
2373 dest_addr = ((offset == 0)
2375 : plus_constant (dest_reg, offset));
2377 /* Generate the appropriate store of gr0. */
2378 if (bytes >= 4 && align >= 4)
2380 else if (bytes >= 2 && align >= 2)
2385 clear_bytes = GET_MODE_SIZE (mode);
2386 dest_mem = change_address (orig_dest, mode, dest_addr);
2387 emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx));
2394 /* The following variable is used to output modifiers of assembler
2395 code of the current output insn. */
2397 static rtx *frv_insn_operands;
2399 /* The following function is used to add assembler insn code suffix .p
2400 if it is necessary. */
2403 frv_asm_output_opcode (FILE *f, const char *ptr)
2407 if (frv_insn_packing_flag <= 0)
2410 for (; *ptr && *ptr != ' ' && *ptr != '\t';)
2413 if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z')
2414 || (*ptr >= 'A' && *ptr <= 'Z')))
2416 int letter = *ptr++;
2419 frv_print_operand (f, frv_insn_operands [c], letter);
2420 while ((c = *ptr) >= '0' && c <= '9')
2432 /* Set up the packing bit for the current output insn. Note that this
2433 function is not called for asm insns. */
2436 frv_final_prescan_insn (rtx insn, rtx *opvec,
2437 int noperands ATTRIBUTE_UNUSED)
2441 if (frv_insn_packing_flag >= 0)
2443 frv_insn_operands = opvec;
2444 frv_insn_packing_flag = PACKING_FLAG_P (insn);
2446 else if (recog_memoized (insn) >= 0
2447 && get_attr_acc_group (insn) == ACC_GROUP_ODD)
2448 /* Packing optimizations have been disabled, but INSN can only
2449 be issued in M1. Insert an mnop in M0. */
2450 fprintf (asm_out_file, "\tmnop.p\n");
2456 /* A C expression whose value is RTL representing the address in a stack frame
2457 where the pointer to the caller's frame is stored. Assume that FRAMEADDR is
2458 an RTL expression for the address of the stack frame itself.
2460 If you don't define this macro, the default is to return the value of
2461 FRAMEADDR--that is, the stack frame address is also the address of the stack
2462 word that points to the previous frame. */
2464 /* The default is correct, but we need to make sure the frame gets created. */
2466 frv_dynamic_chain_address (rtx frame)
2468 cfun->machine->frame_needed = 1;
2473 /* A C expression whose value is RTL representing the value of the return
2474 address for the frame COUNT steps up from the current frame, after the
2475 prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame
2476 pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
2479 The value of the expression must always be the correct address when COUNT is
2480 zero, but may be `NULL_RTX' if there is not way to determine the return
2481 address of other frames. */
2484 frv_return_addr_rtx (int count, rtx frame)
2488 cfun->machine->frame_needed = 1;
2489 return gen_rtx_MEM (Pmode, plus_constant (frame, 8));
2492 /* Given a memory reference MEMREF, interpret the referenced memory as
2493 an array of MODE values, and return a reference to the element
2494 specified by INDEX. Assume that any pre-modification implicit in
2495 MEMREF has already happened.
2497 MEMREF must be a legitimate operand for modes larger than SImode.
2498 GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which
2499 this function cannot handle. */
2501 frv_index_memory (rtx memref, enum machine_mode mode, int index)
2503 rtx base = XEXP (memref, 0);
2504 if (GET_CODE (base) == PRE_MODIFY)
2505 base = XEXP (base, 0);
2506 return change_address (memref, mode,
2507 plus_constant (base, index * GET_MODE_SIZE (mode)));
2511 /* Print a memory address as an operand to reference that memory location. */
2513 frv_print_operand_address (FILE * stream, rtx x)
2515 if (GET_CODE (x) == MEM)
2518 switch (GET_CODE (x))
2521 fputs (reg_names [ REGNO (x)], stream);
2525 fprintf (stream, "%ld", (long) INTVAL (x));
2529 assemble_name (stream, XSTR (x, 0));
2534 output_addr_const (stream, x);
2541 fatal_insn ("bad insn to frv_print_operand_address:", x);
2546 frv_print_operand_memory_reference_reg (FILE * stream, rtx x)
2548 int regno = true_regnum (x);
2550 fputs (reg_names[regno], stream);
2552 fatal_insn ("bad register to frv_print_operand_memory_reference_reg:", x);
2555 /* Print a memory reference suitable for the ld/st instructions. */
2558 frv_print_operand_memory_reference (FILE * stream, rtx x, int addr_offset)
2560 struct frv_unspec unspec;
2564 switch (GET_CODE (x))
2571 case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */
2573 x1 = XEXP (XEXP (x, 1), 1);
2583 if (GET_CODE (x0) == CONST_INT)
2591 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2600 else if (GET_CODE (x1) != CONST_INT)
2601 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2604 fputs ("@(", stream);
2606 fputs (reg_names[GPR_R0], stream);
2607 else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG)
2608 frv_print_operand_memory_reference_reg (stream, x0);
2610 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2612 fputs (",", stream);
2614 fputs (reg_names [GPR_R0], stream);
2618 switch (GET_CODE (x1))
2622 frv_print_operand_memory_reference_reg (stream, x1);
2626 fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset));
2630 if (!frv_const_unspec_p (x1, &unspec))
2631 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x1);
2632 frv_output_const_unspec (stream, &unspec);
2636 fatal_insn ("bad insn to frv_print_operand_memory_reference:", x);
2640 fputs (")", stream);
2644 /* Return 2 for likely branches and 0 for non-likely branches */
2646 #define FRV_JUMP_LIKELY 2
2647 #define FRV_JUMP_NOT_LIKELY 0
2650 frv_print_operand_jump_hint (rtx insn)
2655 HOST_WIDE_INT prob = -1;
2656 enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN;
2658 gcc_assert (GET_CODE (insn) == JUMP_INSN);
2660 /* Assume any non-conditional jump is likely. */
2661 if (! any_condjump_p (insn))
2662 ret = FRV_JUMP_LIKELY;
2666 labelref = condjump_label (insn);
2669 rtx label = XEXP (labelref, 0);
2670 jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label))
2675 note = find_reg_note (insn, REG_BR_PROB, 0);
2677 ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY);
2681 prob = INTVAL (XEXP (note, 0));
2682 ret = ((prob >= (REG_BR_PROB_BASE / 2))
2684 : FRV_JUMP_NOT_LIKELY);
2696 case UNKNOWN: direction = "unknown jump direction"; break;
2697 case BACKWARD: direction = "jump backward"; break;
2698 case FORWARD: direction = "jump forward"; break;
2702 "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n",
2703 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
2704 (long)INSN_UID (insn), direction, (long)prob,
2705 (long)REG_BR_PROB_BASE, ret);
2713 /* Return the comparison operator to use for CODE given that the ICC
2717 comparison_string (enum rtx_code code, rtx op0)
2719 bool is_nz_p = GET_MODE (op0) == CC_NZmode;
2722 default: output_operand_lossage ("bad condition code");
2723 case EQ: return "eq";
2724 case NE: return "ne";
2725 case LT: return is_nz_p ? "n" : "lt";
2726 case LE: return "le";
2727 case GT: return "gt";
2728 case GE: return is_nz_p ? "p" : "ge";
2729 case LTU: return is_nz_p ? "no" : "c";
2730 case LEU: return is_nz_p ? "eq" : "ls";
2731 case GTU: return is_nz_p ? "ne" : "hi";
2732 case GEU: return is_nz_p ? "ra" : "nc";
2736 /* Print an operand to an assembler instruction.
2738 `%' followed by a letter and a digit says to output an operand in an
2739 alternate fashion. Four letters have standard, built-in meanings described
2740 below. The machine description macro `PRINT_OPERAND' can define additional
2741 letters with nonstandard meanings.
2743 `%cDIGIT' can be used to substitute an operand that is a constant value
2744 without the syntax that normally indicates an immediate operand.
2746 `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated
2749 `%aDIGIT' can be used to substitute an operand as if it were a memory
2750 reference, with the actual operand treated as the address. This may be
2751 useful when outputting a "load address" instruction, because often the
2752 assembler syntax for such an instruction requires you to write the operand
2753 as if it were a memory reference.
2755 `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
2757 `%=' outputs a number which is unique to each instruction in the entire
2758 compilation. This is useful for making local labels to be referred to more
2759 than once in a single template that generates multiple assembler
2762 `%' followed by a punctuation character specifies a substitution that does
2763 not use an operand. Only one case is standard: `%%' outputs a `%' into the
2764 assembler code. Other nonstandard cases can be defined in the
2765 `PRINT_OPERAND' macro. You must also define which punctuation characters
2766 are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */
2769 frv_print_operand (FILE * file, rtx x, int code)
2771 struct frv_unspec unspec;
2772 HOST_WIDE_INT value;
2775 if (code != 0 && !isalpha (code))
2778 else if (GET_CODE (x) == CONST_INT)
2781 else if (GET_CODE (x) == CONST_DOUBLE)
2783 if (GET_MODE (x) == SFmode)
2788 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2789 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2793 else if (GET_MODE (x) == VOIDmode)
2794 value = CONST_DOUBLE_LOW (x);
2797 fatal_insn ("bad insn in frv_print_operand, bad const_double", x);
2808 fputs (reg_names[GPR_R0], file);
2812 fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn));
2816 /* Output small data area base register (gr16). */
2817 fputs (reg_names[SDA_BASE_REG], file);
2821 /* Output pic register (gr17). */
2822 fputs (reg_names[PIC_REGNO], file);
2826 /* Output the temporary integer CCR register. */
2827 fputs (reg_names[ICR_TEMP], file);
2831 /* Output the temporary integer CC register. */
2832 fputs (reg_names[ICC_TEMP], file);
2835 /* case 'a': print an address. */
2838 /* Print appropriate test for integer branch false operation. */
2839 fputs (comparison_string (reverse_condition (GET_CODE (x)),
2840 XEXP (x, 0)), file);
2844 /* Print appropriate test for integer branch true operation. */
2845 fputs (comparison_string (GET_CODE (x), XEXP (x, 0)), file);
2849 /* Print 1 for a NE and 0 for an EQ to give the final argument
2850 for a conditional instruction. */
2851 if (GET_CODE (x) == NE)
2854 else if (GET_CODE (x) == EQ)
2858 fatal_insn ("bad insn to frv_print_operand, 'e' modifier:", x);
2862 /* Print appropriate test for floating point branch false operation. */
2863 switch (GET_CODE (x))
2866 fatal_insn ("bad insn to frv_print_operand, 'F' modifier:", x);
2868 case EQ: fputs ("ne", file); break;
2869 case NE: fputs ("eq", file); break;
2870 case LT: fputs ("uge", file); break;
2871 case LE: fputs ("ug", file); break;
2872 case GT: fputs ("ule", file); break;
2873 case GE: fputs ("ul", file); break;
2878 /* Print appropriate test for floating point branch true operation. */
2879 switch (GET_CODE (x))
2882 fatal_insn ("bad insn to frv_print_operand, 'f' modifier:", x);
2884 case EQ: fputs ("eq", file); break;
2885 case NE: fputs ("ne", file); break;
2886 case LT: fputs ("lt", file); break;
2887 case LE: fputs ("le", file); break;
2888 case GT: fputs ("gt", file); break;
2889 case GE: fputs ("ge", file); break;
2894 /* Print appropriate GOT function. */
2895 if (GET_CODE (x) != CONST_INT)
2896 fatal_insn ("bad insn to frv_print_operand, 'g' modifier:", x);
2897 fputs (unspec_got_name (INTVAL (x)), file);
2901 /* Print 'i' if the operand is a constant, or is a memory reference that
2903 if (GET_CODE (x) == MEM)
2904 x = ((GET_CODE (XEXP (x, 0)) == PLUS)
2905 ? XEXP (XEXP (x, 0), 1)
2907 else if (GET_CODE (x) == PLUS)
2910 switch (GET_CODE (x))
2924 /* For jump instructions, print 'i' if the operand is a constant or
2925 is an expression that adds a constant. */
2926 if (GET_CODE (x) == CONST_INT)
2931 if (GET_CODE (x) == CONST_INT
2932 || (GET_CODE (x) == PLUS
2933 && (GET_CODE (XEXP (x, 1)) == CONST_INT
2934 || GET_CODE (XEXP (x, 0)) == CONST_INT)))
2940 /* Print the lower register of a double word register pair */
2941 if (GET_CODE (x) == REG)
2942 fputs (reg_names[ REGNO (x)+1 ], file);
2944 fatal_insn ("bad insn to frv_print_operand, 'L' modifier:", x);
2947 /* case 'l': print a LABEL_REF. */
2951 /* Print a memory reference for ld/st/jmp, %N prints a memory reference
2952 for the second word of double memory operations. */
2953 offset = (code == 'M') ? 0 : UNITS_PER_WORD;
2954 switch (GET_CODE (x))
2957 fatal_insn ("bad insn to frv_print_operand, 'M/N' modifier:", x);
2960 frv_print_operand_memory_reference (file, XEXP (x, 0), offset);
2968 frv_print_operand_memory_reference (file, x, offset);
2974 /* Print the opcode of a command. */
2975 switch (GET_CODE (x))
2978 fatal_insn ("bad insn to frv_print_operand, 'O' modifier:", x);
2980 case PLUS: fputs ("add", file); break;
2981 case MINUS: fputs ("sub", file); break;
2982 case AND: fputs ("and", file); break;
2983 case IOR: fputs ("or", file); break;
2984 case XOR: fputs ("xor", file); break;
2985 case ASHIFT: fputs ("sll", file); break;
2986 case ASHIFTRT: fputs ("sra", file); break;
2987 case LSHIFTRT: fputs ("srl", file); break;
2991 /* case 'n': negate and print a constant int. */
2994 /* Print PIC label using operand as the number. */
2995 if (GET_CODE (x) != CONST_INT)
2996 fatal_insn ("bad insn to frv_print_operand, P modifier:", x);
2998 fprintf (file, ".LCF%ld", (long)INTVAL (x));
3002 /* Print 'u' if the operand is a update load/store. */
3003 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
3008 /* If value is 0, print gr0, otherwise it must be a register. */
3009 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
3010 fputs (reg_names[GPR_R0], file);
3012 else if (GET_CODE (x) == REG)
3013 fputs (reg_names [REGNO (x)], file);
3016 fatal_insn ("bad insn in frv_print_operand, z case", x);
3020 /* Print constant in hex. */
3021 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
3023 fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value);
3030 if (GET_CODE (x) == REG)
3031 fputs (reg_names [REGNO (x)], file);
3033 else if (GET_CODE (x) == CONST_INT
3034 || GET_CODE (x) == CONST_DOUBLE)
3035 fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value);
3037 else if (frv_const_unspec_p (x, &unspec))
3038 frv_output_const_unspec (file, &unspec);
3040 else if (GET_CODE (x) == MEM)
3041 frv_print_operand_address (file, XEXP (x, 0));
3043 else if (CONSTANT_ADDRESS_P (x))
3044 frv_print_operand_address (file, x);
3047 fatal_insn ("bad insn in frv_print_operand, 0 case", x);
3052 fatal_insn ("frv_print_operand: unknown code", x);
3060 /* A C statement (sans semicolon) for initializing the variable CUM for the
3061 state at the beginning of the argument list. The variable has type
3062 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
3063 of the function which will receive the args, or 0 if the args are to a
3064 compiler support library function. The value of INDIRECT is nonzero when
3065 processing an indirect call, for example a call through a function pointer.
3066 The value of INDIRECT is zero for a call to an explicitly named function, a
3067 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
3068 arguments for the function being compiled.
3070 When processing a call to a compiler support library function, LIBNAME
3071 identifies which one. It is a `symbol_ref' rtx which contains the name of
3072 the function, as a string. LIBNAME is 0 when an ordinary C function call is
3073 being processed. Thus, each time this macro is called, either LIBNAME or
3074 FNTYPE is nonzero, but never both of them at once. */
3077 frv_init_cumulative_args (CUMULATIVE_ARGS *cum,
3083 *cum = FIRST_ARG_REGNUM;
3085 if (TARGET_DEBUG_ARG)
3087 fprintf (stderr, "\ninit_cumulative_args:");
3088 if (!fndecl && fntype)
3089 fputs (" indirect", stderr);
3092 fputs (" incoming", stderr);
3096 tree ret_type = TREE_TYPE (fntype);
3097 fprintf (stderr, " return=%s,",
3098 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3101 if (libname && GET_CODE (libname) == SYMBOL_REF)
3102 fprintf (stderr, " libname=%s", XSTR (libname, 0));
3104 if (cfun->returns_struct)
3105 fprintf (stderr, " return-struct");
3107 putc ('\n', stderr);
3112 /* Return true if we should pass an argument on the stack rather than
3116 frv_must_pass_in_stack (enum machine_mode mode, tree type)
3118 if (mode == BLKmode)
3122 return AGGREGATE_TYPE_P (type);
3125 /* If defined, a C expression that gives the alignment boundary, in bits, of an
3126 argument with the specified mode and type. If it is not defined,
3127 `PARM_BOUNDARY' is used for all arguments. */
3130 frv_function_arg_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
3131 tree type ATTRIBUTE_UNUSED)
3133 return BITS_PER_WORD;
3137 frv_function_arg (CUMULATIVE_ARGS *cum,
3138 enum machine_mode mode,
3139 tree type ATTRIBUTE_UNUSED,
3141 int incoming ATTRIBUTE_UNUSED)
3143 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3148 /* Return a marker for use in the call instruction. */
3149 if (xmode == VOIDmode)
3155 else if (arg_num <= LAST_ARG_REGNUM)
3157 ret = gen_rtx_REG (xmode, arg_num);
3158 debstr = reg_names[arg_num];
3167 if (TARGET_DEBUG_ARG)
3169 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n",
3170 arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr);
3176 /* A C statement (sans semicolon) to update the summarizer variable CUM to
3177 advance past an argument in the argument list. The values MODE, TYPE and
3178 NAMED describe that argument. Once this is done, the variable CUM is
3179 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
3181 This macro need not do anything if the argument in question was passed on
3182 the stack. The compiler knows how to track the amount of stack space used
3183 for arguments without any special help. */
3186 frv_function_arg_advance (CUMULATIVE_ARGS *cum,
3187 enum machine_mode mode,
3188 tree type ATTRIBUTE_UNUSED,
3191 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3192 int bytes = GET_MODE_SIZE (xmode);
3193 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3196 *cum = arg_num + words;
3198 if (TARGET_DEBUG_ARG)
3200 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n",
3201 arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD);
3205 /* A C expression for the number of words, at the beginning of an argument,
3206 must be put in registers. The value must be zero for arguments that are
3207 passed entirely in registers or that are entirely pushed on the stack.
3209 On some machines, certain arguments must be passed partially in registers
3210 and partially in memory. On these machines, typically the first N words of
3211 arguments are passed in registers, and the rest on the stack. If a
3212 multi-word argument (a `double' or a structure) crosses that boundary, its
3213 first few words must be passed in registers and the rest must be pushed.
3214 This macro tells the compiler when this occurs, and how many of the words
3215 should go in registers.
3217 `FUNCTION_ARG' for these arguments should return the first register to be
3218 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
3219 the called function. */
3222 frv_arg_partial_bytes (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3223 tree type ATTRIBUTE_UNUSED, bool named ATTRIBUTE_UNUSED)
3225 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3226 int bytes = GET_MODE_SIZE (xmode);
3227 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3231 ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1)
3232 ? LAST_ARG_REGNUM - arg_num + 1
3234 ret *= UNITS_PER_WORD;
3236 if (TARGET_DEBUG_ARG && ret)
3237 fprintf (stderr, "frv_arg_partial_bytes: %d\n", ret);
3243 /* Return true if a register is ok to use as a base or index register. */
3245 static FRV_INLINE int
3246 frv_regno_ok_for_base_p (int regno, int strict_p)
3252 return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno]));
3254 if (regno == ARG_POINTER_REGNUM)
3257 return (regno >= FIRST_PSEUDO_REGISTER);
3261 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3262 RTX) is a legitimate memory address on the target machine for a memory
3263 operand of mode MODE.
3265 It usually pays to define several simpler macros to serve as subroutines for
3266 this one. Otherwise it may be too complicated to understand.
3268 This macro must exist in two variants: a strict variant and a non-strict
3269 one. The strict variant is used in the reload pass. It must be defined so
3270 that any pseudo-register that has not been allocated a hard register is
3271 considered a memory reference. In contexts where some kind of register is
3272 required, a pseudo-register with no hard register must be rejected.
3274 The non-strict variant is used in other passes. It must be defined to
3275 accept all pseudo-registers in every context where some kind of register is
3278 Compiler source files that want to use the strict variant of this macro
3279 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3280 conditional to define the strict variant in that case and the non-strict
3283 Subroutines to check for acceptable registers for various purposes (one for
3284 base registers, one for index registers, and so on) are typically among the
3285 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3286 subroutine macros need have two variants; the higher levels of macros may be
3287 the same whether strict or not.
3289 Normally, constant addresses which are the sum of a `symbol_ref' and an
3290 integer are stored inside a `const' RTX to mark them as constant.
3291 Therefore, there is no need to recognize such sums specifically as
3292 legitimate addresses. Normally you would simply recognize any `const' as
3295 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3296 are not marked with `const'. It assumes that a naked `plus' indicates
3297 indexing. If so, then you *must* reject such naked constant sums as
3298 illegitimate addresses, so that none of them will be given to
3299 `PRINT_OPERAND_ADDRESS'.
3301 On some machines, whether a symbolic address is legitimate depends on the
3302 section that the address refers to. On these machines, define the macro
3303 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3304 then check for it here. When you see a `const', you will have to look
3305 inside it to find the `symbol_ref' in order to determine the section.
3307 The best way to modify the name string is by adding text to the beginning,
3308 with suitable punctuation to prevent any ambiguity. Allocate the new name
3309 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3310 remove and decode the added text and output the name accordingly, and define
3311 `(* targetm.strip_name_encoding)' to access the original name string.
3313 You can check the information stored here into the `symbol_ref' in the
3314 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3315 `PRINT_OPERAND_ADDRESS'. */
3318 frv_legitimate_address_p (enum machine_mode mode,
3322 int allow_double_reg_p)
3326 HOST_WIDE_INT value;
3329 if (FRV_SYMBOL_REF_TLS_P (x))
3332 switch (GET_CODE (x))
3339 if (GET_CODE (x) != REG)
3345 ret = frv_regno_ok_for_base_p (REGNO (x), strict_p);
3351 if (GET_CODE (x0) != REG
3352 || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p)
3353 || GET_CODE (x1) != PLUS
3354 || ! rtx_equal_p (x0, XEXP (x1, 0))
3355 || GET_CODE (XEXP (x1, 1)) != REG
3356 || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p))
3363 /* 12-bit immediate */
3368 ret = IN_RANGE_P (INTVAL (x), -2048, 2047);
3370 /* If we can't use load/store double operations, make sure we can
3371 address the second word. */
3372 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3373 ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1,
3382 if (GET_CODE (x0) == SUBREG)
3383 x0 = SUBREG_REG (x0);
3385 if (GET_CODE (x0) != REG)
3388 regno0 = REGNO (x0);
3389 if (!frv_regno_ok_for_base_p (regno0, strict_p))
3392 switch (GET_CODE (x1))
3398 x1 = SUBREG_REG (x1);
3399 if (GET_CODE (x1) != REG)
3405 /* Do not allow reg+reg addressing for modes > 1 word if we
3406 can't depend on having move double instructions. */
3407 if (!allow_double_reg_p && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3410 ret = frv_regno_ok_for_base_p (REGNO (x1), strict_p);
3414 /* 12-bit immediate */
3419 value = INTVAL (x1);
3420 ret = IN_RANGE_P (value, -2048, 2047);
3422 /* If we can't use load/store double operations, make sure we can
3423 address the second word. */
3424 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3425 ret = IN_RANGE_P (value + GET_MODE_SIZE (mode) - 1, -2048, 2047);
3430 if (!condexec_p && got12_operand (x1, VOIDmode))
3438 if (TARGET_DEBUG_ADDR)
3440 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict%s\n",
3441 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ",
3442 (condexec_p) ? ", inside conditional code" : "");