* config/i386/uwin.h: Remove SUBTARGET_PROLOGUE.
[official-gcc.git] / gcc / config / frv / frv.c
blobc2a8ef95c6cdc5e5c9b8d2e9f6507a7e8a325d66
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2 Contributed by Red Hat, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "tree.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "real.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-flags.h"
33 #include "output.h"
34 #include "insn-attr.h"
35 #include "flags.h"
36 #include "recog.h"
37 #include "reload.h"
38 #include "expr.h"
39 #include "obstack.h"
40 #include "except.h"
41 #include "function.h"
42 #include "optabs.h"
43 #include "toplev.h"
44 #include "basic-block.h"
45 #include "tm_p.h"
46 #include "ggc.h"
47 #include <ctype.h>
48 #include "target.h"
49 #include "target-def.h"
51 #ifndef FRV_INLINE
52 #define FRV_INLINE inline
53 #endif
55 /* Temporary register allocation support structure. */
56 typedef struct frv_tmp_reg_struct
58 HARD_REG_SET regs; /* possible registers to allocate */
59 int next_reg[N_REG_CLASSES]; /* next register to allocate per class */
61 frv_tmp_reg_t;
63 /* Register state information for VLIW re-packing phase. These values must fit
64 within an unsigned char. */
65 #define REGSTATE_DEAD 0x00 /* register is currently dead */
66 #define REGSTATE_CC_MASK 0x07 /* Mask to isolate CCn for cond exec */
67 #define REGSTATE_LIVE 0x08 /* register is live */
68 #define REGSTATE_MODIFIED 0x10 /* reg modified in current VLIW insn */
69 #define REGSTATE_IF_TRUE 0x20 /* reg modified in cond exec true */
70 #define REGSTATE_IF_FALSE 0x40 /* reg modified in cond exec false */
71 #define REGSTATE_UNUSED 0x80 /* bit for hire */
72 #define REGSTATE_MASK 0xff /* mask for the bits to set */
74 /* conditional expression used */
75 #define REGSTATE_IF_EITHER (REGSTATE_IF_TRUE | REGSTATE_IF_FALSE)
77 /* the following is not sure in the reg_state bytes, so can have a larger value
78 than 0xff. */
79 #define REGSTATE_CONDJUMP 0x100 /* conditional jump done in VLIW insn */
81 /* Used in frv_frame_accessor_t to indicate the direction of a register-to-
82 memory move. */
83 enum frv_stack_op
85 FRV_LOAD,
86 FRV_STORE
89 /* Information required by frv_frame_access. */
90 typedef struct
92 /* This field is FRV_LOAD if registers are to be loaded from the stack and
93 FRV_STORE if they should be stored onto the stack. FRV_STORE implies
94 the move is being done by the prologue code while FRV_LOAD implies it
95 is being done by the epilogue. */
96 enum frv_stack_op op;
98 /* The base register to use when accessing the stack. This may be the
99 frame pointer, stack pointer, or a temporary. The choice of register
100 depends on which part of the frame is being accessed and how big the
101 frame is. */
102 rtx base;
104 /* The offset of BASE from the bottom of the current frame, in bytes. */
105 int base_offset;
106 } frv_frame_accessor_t;
108 /* Define the information needed to generate branch and scc insns. This is
109 stored from the compare operation. */
110 rtx frv_compare_op0;
111 rtx frv_compare_op1;
113 /* Conditional execution support gathered together in one structure */
114 typedef struct
116 /* Linked list of insns to add if the conditional execution conversion was
117 successful. Each link points to an EXPR_LIST which points to the pattern
118 of the insn to add, and the insn to be inserted before. */
119 rtx added_insns_list;
121 /* Identify which registers are safe to allocate for if conversions to
122 conditional execution. We keep the last allocated register in the
123 register classes between COND_EXEC statements. This will mean we allocate
124 different registers for each different COND_EXEC group if we can. This
125 might allow the scheduler to intermix two different COND_EXEC sections. */
126 frv_tmp_reg_t tmp_reg;
128 /* For nested IFs, identify which CC registers are used outside of setting
129 via a compare isnsn, and using via a check insn. This will allow us to
130 know if we can rewrite the register to use a different register that will
131 be paired with the CR register controlling the nested IF-THEN blocks. */
132 HARD_REG_SET nested_cc_ok_rewrite;
134 /* Temporary registers allocated to hold constants during conditional
135 execution. */
136 rtx scratch_regs[FIRST_PSEUDO_REGISTER];
138 /* Current number of temp registers available. */
139 int cur_scratch_regs;
141 /* Number of nested conditional execution blocks */
142 int num_nested_cond_exec;
144 /* Map of insns that set up constants in scratch registers. */
145 bitmap scratch_insns_bitmap;
147 /* Conditional execution test register (CC0..CC7) */
148 rtx cr_reg;
150 /* Conditional execution compare register that is paired with cr_reg, so that
151 nested compares can be done. The csubcc and caddcc instructions don't
152 have enough bits to specify both a CC register to be set and a CR register
153 to do the test on, so the same bit number is used for both. Needless to
154 say, this is rather inconvient for GCC. */
155 rtx nested_cc_reg;
157 /* Extra CR registers used for &&, ||. */
158 rtx extra_int_cr;
159 rtx extra_fp_cr;
161 /* Previous CR used in nested if, to make sure we are dealing with the same
162 nested if as the previous statement. */
163 rtx last_nested_if_cr;
165 frv_ifcvt_t;
167 static /* GTY(()) */ frv_ifcvt_t frv_ifcvt;
169 /* Map register number to smallest register class. */
170 enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER];
172 /* Map class letter into register class */
173 enum reg_class reg_class_from_letter[256];
175 /* Cached value of frv_stack_info */
176 static frv_stack_t *frv_stack_cache = (frv_stack_t *)0;
178 /* -mbranch-cost= support */
179 const char *frv_branch_cost_string;
180 int frv_branch_cost_int = DEFAULT_BRANCH_COST;
182 /* -mcpu= support */
183 const char *frv_cpu_string; /* -mcpu= option */
184 frv_cpu_t frv_cpu_type = CPU_TYPE; /* value of -mcpu= */
186 /* -mcond-exec-insns= support */
187 const char *frv_condexec_insns_str; /* -mcond-exec-insns= option */
188 int frv_condexec_insns = DEFAULT_CONDEXEC_INSNS; /* value of -mcond-exec-insns*/
190 /* -mcond-exec-temps= support */
191 const char *frv_condexec_temps_str; /* -mcond-exec-temps= option */
192 int frv_condexec_temps = DEFAULT_CONDEXEC_TEMPS; /* value of -mcond-exec-temps*/
194 /* -msched-lookahead=n */
195 const char *frv_sched_lookahead_str; /* -msched-lookahead=n */
196 int frv_sched_lookahead = 4; /* -msched-lookahead=n */
198 /* Forward references */
199 static int frv_default_flags_for_cpu PARAMS ((void));
200 static int frv_string_begins_with PARAMS ((tree, const char *));
201 static FRV_INLINE int const_small_data_p PARAMS ((rtx));
202 static FRV_INLINE int plus_small_data_p PARAMS ((rtx, rtx));
203 static void frv_print_operand_memory_reference_reg
204 PARAMS ((FILE *, rtx));
205 static void frv_print_operand_memory_reference PARAMS ((FILE *, rtx, int));
206 static int frv_print_operand_jump_hint PARAMS ((rtx));
207 static FRV_INLINE int frv_regno_ok_for_base_p PARAMS ((int, int));
208 static rtx single_set_pattern PARAMS ((rtx));
209 static int frv_function_contains_far_jump PARAMS ((void));
210 static rtx frv_alloc_temp_reg PARAMS ((frv_tmp_reg_t *,
211 enum reg_class,
212 enum machine_mode,
213 int, int));
214 static rtx frv_frame_offset_rtx PARAMS ((int));
215 static rtx frv_frame_mem PARAMS ((enum machine_mode,
216 rtx, int));
217 static rtx frv_dwarf_store PARAMS ((rtx, int));
218 static void frv_frame_insn PARAMS ((rtx, rtx));
219 static void frv_frame_access PARAMS ((frv_frame_accessor_t*,
220 rtx, int));
221 static void frv_frame_access_multi PARAMS ((frv_frame_accessor_t*,
222 frv_stack_t *, int));
223 static void frv_frame_access_standard_regs PARAMS ((enum frv_stack_op,
224 frv_stack_t *));
225 static struct machine_function *frv_init_machine_status PARAMS ((void));
226 static int frv_legitimate_memory_operand PARAMS ((rtx,
227 enum machine_mode,
228 int));
229 static rtx frv_int_to_acc PARAMS ((enum insn_code,
230 int, rtx));
231 static enum machine_mode frv_matching_accg_mode PARAMS ((enum machine_mode));
232 static rtx frv_read_argument PARAMS ((tree *));
233 static int frv_check_constant_argument PARAMS ((enum insn_code,
234 int, rtx));
235 static rtx frv_legitimize_target PARAMS ((enum insn_code, rtx));
236 static rtx frv_legitimize_argument PARAMS ((enum insn_code,
237 int, rtx));
238 static rtx frv_expand_set_builtin PARAMS ((enum insn_code,
239 tree, rtx));
240 static rtx frv_expand_unop_builtin PARAMS ((enum insn_code,
241 tree, rtx));
242 static rtx frv_expand_binop_builtin PARAMS ((enum insn_code,
243 tree, rtx));
244 static rtx frv_expand_cut_builtin PARAMS ((enum insn_code,
245 tree, rtx));
246 static rtx frv_expand_binopimm_builtin PARAMS ((enum insn_code,
247 tree, rtx));
248 static rtx frv_expand_voidbinop_builtin PARAMS ((enum insn_code,
249 tree));
250 static rtx frv_expand_voidtriop_builtin PARAMS ((enum insn_code,
251 tree));
252 static rtx frv_expand_voidaccop_builtin PARAMS ((enum insn_code,
253 tree));
254 static rtx frv_expand_mclracc_builtin PARAMS ((tree));
255 static rtx frv_expand_mrdacc_builtin PARAMS ((enum insn_code,
256 tree));
257 static rtx frv_expand_mwtacc_builtin PARAMS ((enum insn_code,
258 tree));
259 static rtx frv_expand_noargs_builtin PARAMS ((enum insn_code));
260 static rtx frv_emit_comparison PARAMS ((enum rtx_code, rtx,
261 rtx));
262 static int frv_clear_registers_used PARAMS ((rtx *, void *));
263 static void frv_ifcvt_add_insn PARAMS ((rtx, rtx, int));
264 static rtx frv_ifcvt_rewrite_mem PARAMS ((rtx,
265 enum machine_mode,
266 rtx));
267 static rtx frv_ifcvt_load_value PARAMS ((rtx, rtx));
268 static void frv_registers_update PARAMS ((rtx, unsigned char [],
269 int [], int *, int));
270 static int frv_registers_used_p PARAMS ((rtx, unsigned char [],
271 int));
272 static int frv_registers_set_p PARAMS ((rtx, unsigned char [],
273 int));
274 static void frv_pack_insns PARAMS ((void));
275 static void frv_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
276 static void frv_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
277 static bool frv_assemble_integer PARAMS ((rtx, unsigned, int));
278 static void frv_init_builtins PARAMS ((void));
279 static rtx frv_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
280 static bool frv_in_small_data_p PARAMS ((tree));
281 static void frv_asm_output_mi_thunk
282 PARAMS ((FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree));
283 static bool frv_rtx_costs PARAMS ((rtx, int, int, int*));
284 static void frv_asm_out_constructor PARAMS ((rtx, int));
285 static void frv_asm_out_destructor PARAMS ((rtx, int));
287 /* Initialize the GCC target structure. */
288 #undef TARGET_ASM_FUNCTION_PROLOGUE
289 #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue
290 #undef TARGET_ASM_FUNCTION_EPILOGUE
291 #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue
292 #undef TARGET_ASM_INTEGER
293 #define TARGET_ASM_INTEGER frv_assemble_integer
294 #undef TARGET_INIT_BUILTINS
295 #define TARGET_INIT_BUILTINS frv_init_builtins
296 #undef TARGET_EXPAND_BUILTIN
297 #define TARGET_EXPAND_BUILTIN frv_expand_builtin
298 #undef TARGET_IN_SMALL_DATA_P
299 #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p
300 #undef TARGET_RTX_COSTS
301 #define TARGET_RTX_COSTS frv_rtx_costs
302 #undef TARGET_ASM_CONSTRUCTOR
303 #define TARGET_ASM_CONSTRUCTOR frv_asm_out_constructor
304 #undef TARGET_ASM_DESTRUCTOR
305 #define TARGET_ASM_DESTRUCTOR frv_asm_out_destructor
307 #undef TARGET_ASM_OUTPUT_MI_THUNK
308 #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk
309 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
310 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
312 struct gcc_target targetm = TARGET_INITIALIZER;
314 /* Given a CONST, return true if the symbol_ref points to small data. */
316 static FRV_INLINE int
317 const_small_data_p (x)
318 rtx x;
320 rtx x0, x1;
322 if (GET_CODE (XEXP (x, 0)) != PLUS)
323 return FALSE;
325 x0 = XEXP (XEXP (x, 0), 0);
326 if (GET_CODE (x0) != SYMBOL_REF || !SYMBOL_REF_SMALL_P (x0))
327 return FALSE;
329 x1 = XEXP (XEXP (x, 0), 1);
330 if (GET_CODE (x1) != CONST_INT
331 || !IN_RANGE_P (INTVAL (x1), -2048, 2047))
332 return FALSE;
334 return TRUE;
337 /* Given a PLUS, return true if this is a small data reference. */
339 static FRV_INLINE int
340 plus_small_data_p (op0, op1)
341 rtx op0;
342 rtx op1;
344 if (GET_MODE (op0) == SImode
345 && GET_CODE (op0) == REG
346 && REGNO (op0) == SDA_BASE_REG)
348 if (GET_CODE (op1) == SYMBOL_REF)
349 return SYMBOL_REF_SMALL_P (op1);
351 if (GET_CODE (op1) == CONST)
352 return const_small_data_p (op1);
355 return FALSE;
359 static int
360 frv_default_flags_for_cpu ()
362 switch (frv_cpu_type)
364 case FRV_CPU_GENERIC:
365 return MASK_DEFAULT_FRV;
367 case FRV_CPU_FR500:
368 case FRV_CPU_TOMCAT:
369 return MASK_DEFAULT_FR500;
371 case FRV_CPU_FR400:
372 return MASK_DEFAULT_FR400;
374 case FRV_CPU_FR300:
375 case FRV_CPU_SIMPLE:
376 return MASK_DEFAULT_SIMPLE;
378 abort ();
381 /* Sometimes certain combinations of command options do not make
382 sense on a particular target machine. You can define a macro
383 `OVERRIDE_OPTIONS' to take account of this. This macro, if
384 defined, is executed once just after all the command options have
385 been parsed.
387 Don't use this macro to turn on various extra optimizations for
388 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
390 void
391 frv_override_options ()
393 int regno, i;
395 /* Set the cpu type */
396 if (frv_cpu_string)
398 if (strcmp (frv_cpu_string, "simple") == 0)
399 frv_cpu_type = FRV_CPU_SIMPLE;
401 else if (strcmp (frv_cpu_string, "tomcat") == 0)
402 frv_cpu_type = FRV_CPU_TOMCAT;
404 else if (strncmp (frv_cpu_string, "fr", sizeof ("fr")-1) != 0)
405 error ("Unknown cpu: -mcpu=%s", frv_cpu_string);
407 else
409 const char *p = frv_cpu_string + sizeof ("fr") - 1;
410 if (strcmp (p, "500") == 0)
411 frv_cpu_type = FRV_CPU_FR500;
413 else if (strcmp (p, "400") == 0)
414 frv_cpu_type = FRV_CPU_FR400;
416 else if (strcmp (p, "300") == 0)
417 frv_cpu_type = FRV_CPU_FR300;
419 else if (strcmp (p, "v") == 0)
420 frv_cpu_type = FRV_CPU_GENERIC;
422 else
423 error ("Unknown cpu: -mcpu=%s", frv_cpu_string);
427 target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit);
429 /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the
430 linker about linking pic and non-pic code. */
431 if (TARGET_LIBPIC)
433 if (!flag_pic) /* -fPIC */
434 flag_pic = 2;
436 if (! g_switch_set) /* -G0 */
438 g_switch_set = 1;
439 g_switch_value = 0;
443 /* Both -fpic and -gdwarf want to use .previous and the assembler only keeps
444 one level. */
445 if (write_symbols == DWARF_DEBUG && flag_pic)
446 error ("-fpic and -gdwarf are incompatible (-fpic and -g/-gdwarf-2 are fine)");
448 /* Change the branch cost value */
449 if (frv_branch_cost_string)
450 frv_branch_cost_int = atoi (frv_branch_cost_string);
452 /* Change the # of insns to be converted to conditional execution */
453 if (frv_condexec_insns_str)
454 frv_condexec_insns = atoi (frv_condexec_insns_str);
456 /* Change # of temporary registers used to hold integer constants */
457 if (frv_condexec_temps_str)
458 frv_condexec_temps = atoi (frv_condexec_temps_str);
460 /* Change scheduling look ahead. */
461 if (frv_sched_lookahead_str)
462 frv_sched_lookahead = atoi (frv_sched_lookahead_str);
464 /* A C expression whose value is a register class containing hard
465 register REGNO. In general there is more than one such class;
466 choose a class which is "minimal", meaning that no smaller class
467 also contains the register. */
469 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
471 enum reg_class class;
473 if (GPR_P (regno))
475 int gpr_reg = regno - GPR_FIRST;
476 if ((gpr_reg & 3) == 0)
477 class = QUAD_REGS;
479 else if ((gpr_reg & 1) == 0)
480 class = EVEN_REGS;
482 else
483 class = GPR_REGS;
486 else if (FPR_P (regno))
488 int fpr_reg = regno - GPR_FIRST;
489 if ((fpr_reg & 3) == 0)
490 class = QUAD_FPR_REGS;
492 else if ((fpr_reg & 1) == 0)
493 class = FEVEN_REGS;
495 else
496 class = FPR_REGS;
499 else if (regno == LR_REGNO)
500 class = LR_REG;
502 else if (regno == LCR_REGNO)
503 class = LCR_REG;
505 else if (ICC_P (regno))
506 class = ICC_REGS;
508 else if (FCC_P (regno))
509 class = FCC_REGS;
511 else if (ICR_P (regno))
512 class = ICR_REGS;
514 else if (FCR_P (regno))
515 class = FCR_REGS;
517 else if (ACC_P (regno))
519 int r = regno - ACC_FIRST;
520 if ((r & 3) == 0)
521 class = QUAD_ACC_REGS;
522 else if ((r & 1) == 0)
523 class = EVEN_ACC_REGS;
524 else
525 class = ACC_REGS;
528 else if (ACCG_P (regno))
529 class = ACCG_REGS;
531 else
532 class = NO_REGS;
534 regno_reg_class[regno] = class;
537 /* Check for small data option */
538 if (!g_switch_set)
539 g_switch_value = SDATA_DEFAULT_SIZE;
541 /* A C expression which defines the machine-dependent operand
542 constraint letters for register classes. If CHAR is such a
543 letter, the value should be the register class corresponding to
544 it. Otherwise, the value should be `NO_REGS'. The register
545 letter `r', corresponding to class `GENERAL_REGS', will not be
546 passed to this macro; you do not need to handle it.
548 The following letters are unavailable, due to being used as
549 constraints:
550 '0'..'9'
551 '<', '>'
552 'E', 'F', 'G', 'H'
553 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
554 'Q', 'R', 'S', 'T', 'U'
555 'V', 'X'
556 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
558 for (i = 0; i < 256; i++)
559 reg_class_from_letter[i] = NO_REGS;
561 reg_class_from_letter['a'] = ACC_REGS;
562 reg_class_from_letter['b'] = EVEN_ACC_REGS;
563 reg_class_from_letter['c'] = CC_REGS;
564 reg_class_from_letter['d'] = GPR_REGS;
565 reg_class_from_letter['e'] = EVEN_REGS;
566 reg_class_from_letter['f'] = FPR_REGS;
567 reg_class_from_letter['h'] = FEVEN_REGS;
568 reg_class_from_letter['l'] = LR_REG;
569 reg_class_from_letter['q'] = QUAD_REGS;
570 reg_class_from_letter['t'] = ICC_REGS;
571 reg_class_from_letter['u'] = FCC_REGS;
572 reg_class_from_letter['v'] = ICR_REGS;
573 reg_class_from_letter['w'] = FCR_REGS;
574 reg_class_from_letter['x'] = QUAD_FPR_REGS;
575 reg_class_from_letter['y'] = LCR_REG;
576 reg_class_from_letter['z'] = SPR_REGS;
577 reg_class_from_letter['A'] = QUAD_ACC_REGS;
578 reg_class_from_letter['B'] = ACCG_REGS;
579 reg_class_from_letter['C'] = CR_REGS;
581 /* There is no single unaligned SI op for PIC code. Sometimes we
582 need to use ".4byte" and sometimes we need to use ".picptr".
583 See frv_assemble_integer for details. */
584 if (flag_pic)
585 targetm.asm_out.unaligned_op.si = 0;
587 init_machine_status = frv_init_machine_status;
591 /* Some machines may desire to change what optimizations are performed for
592 various optimization levels. This macro, if defined, is executed once just
593 after the optimization level is determined and before the remainder of the
594 command options have been parsed. Values set in this macro are used as the
595 default values for the other command line options.
597 LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if
598 `-O' is specified, and 0 if neither is specified.
600 SIZE is nonzero if `-Os' is specified, 0 otherwise.
602 You should not use this macro to change options that are not
603 machine-specific. These should uniformly selected by the same optimization
604 level on all supported machines. Use this macro to enable machbine-specific
605 optimizations.
607 *Do not examine `write_symbols' in this macro!* The debugging options are
608 *not supposed to alter the generated code. */
610 /* On the FRV, possibly disable VLIW packing which is done by the 2nd
611 scheduling pass at the current time. */
612 void
613 frv_optimization_options (level, size)
614 int level;
615 int size ATTRIBUTE_UNUSED;
617 if (level >= 2)
619 #ifdef DISABLE_SCHED2
620 flag_schedule_insns_after_reload = 0;
621 #endif
622 #ifdef ENABLE_RCSP
623 flag_rcsp = 1;
624 #endif
629 /* Return true if NAME (a STRING_CST node) begins with PREFIX. */
631 static int
632 frv_string_begins_with (name, prefix)
633 tree name;
634 const char *prefix;
636 int prefix_len = strlen (prefix);
638 /* Remember: NAME's length includes the null terminator. */
639 return (TREE_STRING_LENGTH (name) > prefix_len
640 && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0);
643 /* Zero or more C statements that may conditionally modify two variables
644 `fixed_regs' and `call_used_regs' (both of type `char []') after they have
645 been initialized from the two preceding macros.
647 This is necessary in case the fixed or call-clobbered registers depend on
648 target flags.
650 You need not define this macro if it has no work to do.
652 If the usage of an entire class of registers depends on the target flags,
653 you may indicate this to GCC by using this macro to modify `fixed_regs' and
654 `call_used_regs' to 1 for each of the registers in the classes which should
655 not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return
656 `NO_REGS' if it is called with a letter for a class that shouldn't be used.
658 (However, if this class is not included in `GENERAL_REGS' and all of the
659 insn patterns whose constraints permit this class are controlled by target
660 switches, then GCC will automatically avoid using these registers when the
661 target switches are opposed to them.) */
663 void
664 frv_conditional_register_usage ()
666 int i;
668 for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++)
669 fixed_regs[i] = call_used_regs[i] = 1;
671 for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++)
672 fixed_regs[i] = call_used_regs[i] = 1;
674 for (i = ACC_FIRST + NUM_ACCS; i <= ACC_LAST; i++)
675 fixed_regs[i] = call_used_regs[i] = 1;
677 for (i = ACCG_FIRST + NUM_ACCS; i <= ACCG_LAST; i++)
678 fixed_regs[i] = call_used_regs[i] = 1;
680 /* Reserve the registers used for conditional execution. At present, we need
681 1 ICC and 1 ICR register. */
682 fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1;
683 fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1;
685 if (TARGET_FIXED_CC)
687 fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1;
688 fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1;
689 fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1;
690 fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1;
693 #if 0
694 /* If -fpic, SDA_BASE_REG is the PIC register. */
695 if (g_switch_value == 0 && !flag_pic)
696 fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0;
698 if (!flag_pic)
699 fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0;
700 #endif
705 * Compute the stack frame layout
707 * Register setup:
708 * +---------------+-----------------------+-----------------------+
709 * |Register |type |caller-save/callee-save|
710 * +---------------+-----------------------+-----------------------+
711 * |GR0 |Zero register | - |
712 * |GR1 |Stack pointer(SP) | - |
713 * |GR2 |Frame pointer(FP) | - |
714 * |GR3 |Hidden parameter | caller save |
715 * |GR4-GR7 | - | caller save |
716 * |GR8-GR13 |Argument register | caller save |
717 * |GR14-GR15 | - | caller save |
718 * |GR16-GR31 | - | callee save |
719 * |GR32-GR47 | - | caller save |
720 * |GR48-GR63 | - | callee save |
721 * |FR0-FR15 | - | caller save |
722 * |FR16-FR31 | - | callee save |
723 * |FR32-FR47 | - | caller save |
724 * |FR48-FR63 | - | callee save |
725 * +---------------+-----------------------+-----------------------+
727 * Stack frame setup:
728 * Low
729 * SP-> |-----------------------------------|
730 * | Argument area |
731 * |-----------------------------------|
732 * | Register save area |
733 * |-----------------------------------|
734 * | Local variable save area |
735 * FP-> |-----------------------------------|
736 * | Old FP |
737 * |-----------------------------------|
738 * | Hidden parameter save area |
739 * |-----------------------------------|
740 * | Return address(LR) storage area |
741 * |-----------------------------------|
742 * | Padding for alignment |
743 * |-----------------------------------|
744 * | Register argument area |
745 * OLD SP-> |-----------------------------------|
746 * | Parameter area |
747 * |-----------------------------------|
748 * High
750 * Argument area/Parameter area:
752 * When a function is called, this area is used for argument transfer. When
753 * the argument is set up by the caller function, this area is referred to as
754 * the argument area. When the argument is referenced by the callee function,
755 * this area is referred to as the parameter area. The area is allocated when
756 * all arguments cannot be placed on the argument register at the time of
757 * argument transfer.
759 * Register save area:
761 * This is a register save area that must be guaranteed for the caller
762 * function. This area is not secured when the register save operation is not
763 * needed.
765 * Local variable save area:
767 * This is the area for local variables and temporary variables.
769 * Old FP:
771 * This area stores the FP value of the caller function.
773 * Hidden parameter save area:
775 * This area stores the start address of the return value storage
776 * area for a struct/union return function.
777 * When a struct/union is used as the return value, the caller
778 * function stores the return value storage area start address in
779 * register GR3 and passes it to the caller function.
780 * The callee function interprets the address stored in the GR3
781 * as the return value storage area start address.
782 * When register GR3 needs to be saved into memory, the callee
783 * function saves it in the hidden parameter save area. This
784 * area is not secured when the save operation is not needed.
786 * Return address(LR) storage area:
788 * This area saves the LR. The LR stores the address of a return to the caller
789 * function for the purpose of function calling.
791 * Argument register area:
793 * This area saves the argument register. This area is not secured when the
794 * save operation is not needed.
796 * Argument:
798 * Arguments, the count of which equals the count of argument registers (6
799 * words), are positioned in registers GR8 to GR13 and delivered to the callee
800 * function. When a struct/union return function is called, the return value
801 * area address is stored in register GR3. Arguments not placed in the
802 * argument registers will be stored in the stack argument area for transfer
803 * purposes. When an 8-byte type argument is to be delivered using registers,
804 * it is divided into two and placed in two registers for transfer. When
805 * argument registers must be saved to memory, the callee function secures an
806 * argument register save area in the stack. In this case, a continuous
807 * argument register save area must be established in the parameter area. The
808 * argument register save area must be allocated as needed to cover the size of
809 * the argument register to be saved. If the function has a variable count of
810 * arguments, it saves all argument registers in the argument register save
811 * area.
813 * Argument Extension Format:
815 * When an argument is to be stored in the stack, its type is converted to an
816 * extended type in accordance with the individual argument type. The argument
817 * is freed by the caller function after the return from the callee function is
818 * made.
820 * +-----------------------+---------------+------------------------+
821 * | Argument Type |Extended Type |Stack Storage Size(byte)|
822 * +-----------------------+---------------+------------------------+
823 * |char |int | 4 |
824 * |signed char |int | 4 |
825 * |unsigned char |int | 4 |
826 * |[signed] short int |int | 4 |
827 * |unsigned short int |int | 4 |
828 * |[signed] int |No extension | 4 |
829 * |unsigned int |No extension | 4 |
830 * |[signed] long int |No extension | 4 |
831 * |unsigned long int |No extension | 4 |
832 * |[signed] long long int |No extension | 8 |
833 * |unsigned long long int |No extension | 8 |
834 * |float |double | 8 |
835 * |double |No extension | 8 |
836 * |long double |No extension | 8 |
837 * |pointer |No extension | 4 |
838 * |struct/union |- | 4 (*1) |
839 * +-----------------------+---------------+------------------------+
841 * When a struct/union is to be delivered as an argument, the caller copies it
842 * to the local variable area and delivers the address of that area.
844 * Return Value:
846 * +-------------------------------+----------------------+
847 * |Return Value Type |Return Value Interface|
848 * +-------------------------------+----------------------+
849 * |void |None |
850 * |[signed|unsigned] char |GR8 |
851 * |[signed|unsigned] short int |GR8 |
852 * |[signed|unsigned] int |GR8 |
853 * |[signed|unsigned] long int |GR8 |
854 * |pointer |GR8 |
855 * |[signed|unsigned] long long int|GR8 & GR9 |
856 * |float |GR8 |
857 * |double |GR8 & GR9 |
858 * |long double |GR8 & GR9 |
859 * |struct/union |(*1) |
860 * +-------------------------------+----------------------+
862 * When a struct/union is used as the return value, the caller function stores
863 * the start address of the return value storage area into GR3 and then passes
864 * it to the callee function. The callee function interprets GR3 as the start
865 * address of the return value storage area. When this address needs to be
866 * saved in memory, the callee function secures the hidden parameter save area
867 * and saves the address in that area.
870 frv_stack_t *
871 frv_stack_info ()
873 static frv_stack_t info, zero_info;
874 frv_stack_t *info_ptr = &info;
875 tree fndecl = current_function_decl;
876 int varargs_p = 0;
877 tree cur_arg;
878 tree next_arg;
879 int range;
880 int alignment;
881 int offset;
883 /* If we've already calculated the values and reload is complete, just return now */
884 if (frv_stack_cache)
885 return frv_stack_cache;
887 /* Zero all fields */
888 info = zero_info;
890 /* Set up the register range information */
891 info_ptr->regs[STACK_REGS_GPR].name = "gpr";
892 info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1;
893 info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST;
894 info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE;
896 info_ptr->regs[STACK_REGS_FPR].name = "fpr";
897 info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST;
898 info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST;
899 info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE;
901 info_ptr->regs[STACK_REGS_LR].name = "lr";
902 info_ptr->regs[STACK_REGS_LR].first = LR_REGNO;
903 info_ptr->regs[STACK_REGS_LR].last = LR_REGNO;
904 info_ptr->regs[STACK_REGS_LR].special_p = 1;
906 info_ptr->regs[STACK_REGS_CC].name = "cc";
907 info_ptr->regs[STACK_REGS_CC].first = CC_FIRST;
908 info_ptr->regs[STACK_REGS_CC].last = CC_LAST;
909 info_ptr->regs[STACK_REGS_CC].field_p = TRUE;
911 info_ptr->regs[STACK_REGS_LCR].name = "lcr";
912 info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO;
913 info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO;
915 info_ptr->regs[STACK_REGS_STDARG].name = "stdarg";
916 info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM;
917 info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM;
918 info_ptr->regs[STACK_REGS_STDARG].dword_p = 1;
919 info_ptr->regs[STACK_REGS_STDARG].special_p = 1;
921 info_ptr->regs[STACK_REGS_STRUCT].name = "struct";
922 info_ptr->regs[STACK_REGS_STRUCT].first = STRUCT_VALUE_REGNUM;
923 info_ptr->regs[STACK_REGS_STRUCT].last = STRUCT_VALUE_REGNUM;
924 info_ptr->regs[STACK_REGS_STRUCT].special_p = 1;
926 info_ptr->regs[STACK_REGS_FP].name = "fp";
927 info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM;
928 info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM;
929 info_ptr->regs[STACK_REGS_FP].special_p = 1;
931 /* Determine if this is a stdarg function. If so, allocate space to store
932 the 6 arguments. */
933 if (cfun->stdarg)
934 varargs_p = 1;
936 else
938 /* Find the last argument, and see if it is __builtin_va_alist. */
939 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
941 next_arg = TREE_CHAIN (cur_arg);
942 if (next_arg == (tree)0)
944 if (DECL_NAME (cur_arg)
945 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
946 varargs_p = 1;
948 break;
953 /* Iterate over all of the register ranges */
954 for (range = 0; range < STACK_REGS_MAX; range++)
956 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
957 int first = reg_ptr->first;
958 int last = reg_ptr->last;
959 int size_1word = 0;
960 int size_2words = 0;
961 int regno;
963 /* Calculate which registers need to be saved & save area size */
964 switch (range)
966 default:
967 for (regno = first; regno <= last; regno++)
969 if ((regs_ever_live[regno] && !call_used_regs[regno])
970 || (current_function_calls_eh_return
971 && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM))
972 || (flag_pic && cfun->uses_pic_offset_table && regno == PIC_REGNO))
974 info_ptr->save_p[regno] = REG_SAVE_1WORD;
975 size_1word += UNITS_PER_WORD;
978 break;
980 /* Calculate whether we need to create a frame after everything else
981 has been processed. */
982 case STACK_REGS_FP:
983 break;
985 case STACK_REGS_LR:
986 if (regs_ever_live[LR_REGNO]
987 || profile_flag
988 || frame_pointer_needed
989 || (flag_pic && cfun->uses_pic_offset_table))
991 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
992 size_1word += UNITS_PER_WORD;
994 break;
996 case STACK_REGS_STDARG:
997 if (varargs_p)
999 /* If this is a stdarg function with a non varardic argument split
1000 between registers and the stack, adjust the saved registers
1001 downward */
1002 last -= (ADDR_ALIGN (cfun->pretend_args_size, UNITS_PER_WORD)
1003 / UNITS_PER_WORD);
1005 for (regno = first; regno <= last; regno++)
1007 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1008 size_1word += UNITS_PER_WORD;
1011 info_ptr->stdarg_size = size_1word;
1013 break;
1015 case STACK_REGS_STRUCT:
1016 if (cfun->returns_struct)
1018 info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1019 size_1word += UNITS_PER_WORD;
1021 break;
1025 if (size_1word)
1027 /* If this is a field, it only takes one word */
1028 if (reg_ptr->field_p)
1029 size_1word = UNITS_PER_WORD;
1031 /* Determine which register pairs can be saved together */
1032 else if (reg_ptr->dword_p && TARGET_DWORD)
1034 for (regno = first; regno < last; regno += 2)
1036 if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1])
1038 size_2words += 2 * UNITS_PER_WORD;
1039 size_1word -= 2 * UNITS_PER_WORD;
1040 info_ptr->save_p[regno] = REG_SAVE_2WORDS;
1041 info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE;
1046 reg_ptr->size_1word = size_1word;
1047 reg_ptr->size_2words = size_2words;
1049 if (! reg_ptr->special_p)
1051 info_ptr->regs_size_1word += size_1word;
1052 info_ptr->regs_size_2words += size_2words;
1057 /* Set up the sizes of each each field in the frame body, making the sizes
1058 of each be divisible by the size of a dword if dword operations might
1059 be used, or the size of a word otherwise. */
1060 alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD);
1062 info_ptr->parameter_size = ADDR_ALIGN (cfun->outgoing_args_size, alignment);
1063 info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words
1064 + info_ptr->regs_size_1word,
1065 alignment);
1066 info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment);
1068 info_ptr->pretend_size = cfun->pretend_args_size;
1070 /* Work out the size of the frame, excluding the header. Both the frame
1071 body and register parameter area will be dword-aligned. */
1072 info_ptr->total_size
1073 = (ADDR_ALIGN (info_ptr->parameter_size
1074 + info_ptr->regs_size
1075 + info_ptr->vars_size,
1076 2 * UNITS_PER_WORD)
1077 + ADDR_ALIGN (info_ptr->pretend_size
1078 + info_ptr->stdarg_size,
1079 2 * UNITS_PER_WORD));
1081 /* See if we need to create a frame at all, if so add header area. */
1082 if (info_ptr->total_size > 0
1083 || info_ptr->regs[STACK_REGS_LR].size_1word > 0
1084 || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0)
1086 offset = info_ptr->parameter_size;
1087 info_ptr->header_size = 4 * UNITS_PER_WORD;
1088 info_ptr->total_size += 4 * UNITS_PER_WORD;
1090 /* Calculate the offsets to save normal register pairs */
1091 for (range = 0; range < STACK_REGS_MAX; range++)
1093 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1094 if (! reg_ptr->special_p)
1096 int first = reg_ptr->first;
1097 int last = reg_ptr->last;
1098 int regno;
1100 for (regno = first; regno <= last; regno++)
1101 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS
1102 && regno != FRAME_POINTER_REGNUM
1103 && (regno < FIRST_ARG_REGNUM
1104 || regno > LAST_ARG_REGNUM))
1106 info_ptr->reg_offset[regno] = offset;
1107 offset += 2 * UNITS_PER_WORD;
1112 /* Calculate the offsets to save normal single registers */
1113 for (range = 0; range < STACK_REGS_MAX; range++)
1115 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1116 if (! reg_ptr->special_p)
1118 int first = reg_ptr->first;
1119 int last = reg_ptr->last;
1120 int regno;
1122 for (regno = first; regno <= last; regno++)
1123 if (info_ptr->save_p[regno] == REG_SAVE_1WORD
1124 && regno != FRAME_POINTER_REGNUM
1125 && (regno < FIRST_ARG_REGNUM
1126 || regno > LAST_ARG_REGNUM))
1128 info_ptr->reg_offset[regno] = offset;
1129 offset += UNITS_PER_WORD;
1134 /* Calculate the offset to save the local variables at. */
1135 offset = ADDR_ALIGN (offset, alignment);
1136 if (info_ptr->vars_size)
1138 info_ptr->vars_offset = offset;
1139 offset += info_ptr->vars_size;
1142 /* Align header to a dword-boundary. */
1143 offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD);
1145 /* Calculate the offsets in the fixed frame. */
1146 info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD;
1147 info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset;
1148 info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD;
1150 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1151 info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD;
1152 info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD;
1154 if (cfun->returns_struct)
1156 info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1157 info_ptr->reg_offset[STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD;
1158 info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD;
1161 /* Calculate the offsets to store the arguments passed in registers
1162 for stdarg functions. The register pairs are first and the single
1163 register if any is last. The register save area starts on a
1164 dword-boundary. */
1165 if (info_ptr->stdarg_size)
1167 int first = info_ptr->regs[STACK_REGS_STDARG].first;
1168 int last = info_ptr->regs[STACK_REGS_STDARG].last;
1169 int regno;
1171 /* Skip the header. */
1172 offset += 4 * UNITS_PER_WORD;
1173 for (regno = first; regno <= last; regno++)
1175 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS)
1177 info_ptr->reg_offset[regno] = offset;
1178 offset += 2 * UNITS_PER_WORD;
1180 else if (info_ptr->save_p[regno] == REG_SAVE_1WORD)
1182 info_ptr->reg_offset[regno] = offset;
1183 offset += UNITS_PER_WORD;
1189 if (reload_completed)
1190 frv_stack_cache = info_ptr;
1192 return info_ptr;
1196 /* Print the information about the frv stack offsets, etc. when debugging. */
1198 void
1199 frv_debug_stack (info)
1200 frv_stack_t *info;
1202 int range;
1204 if (!info)
1205 info = frv_stack_info ();
1207 fprintf (stderr, "\nStack information for function %s:\n",
1208 ((current_function_decl && DECL_NAME (current_function_decl))
1209 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1210 : "<unknown>"));
1212 fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size);
1213 fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size);
1214 fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size);
1215 fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n",
1216 info->regs_size, info->regs_size_1word, info->regs_size_2words);
1218 fprintf (stderr, "\theader_size\t= %6d\n", info->header_size);
1219 fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size);
1220 fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset);
1221 fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset);
1223 for (range = 0; range < STACK_REGS_MAX; range++)
1225 frv_stack_regs_t *regs = &(info->regs[range]);
1226 if ((regs->size_1word + regs->size_2words) > 0)
1228 int first = regs->first;
1229 int last = regs->last;
1230 int regno;
1232 fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =",
1233 regs->name, regs->size_1word + regs->size_2words,
1234 regs->size_1word, regs->size_2words);
1236 for (regno = first; regno <= last; regno++)
1238 if (info->save_p[regno] == REG_SAVE_1WORD)
1239 fprintf (stderr, " %s (%d)", reg_names[regno],
1240 info->reg_offset[regno]);
1242 else if (info->save_p[regno] == REG_SAVE_2WORDS)
1243 fprintf (stderr, " %s-%s (%d)", reg_names[regno],
1244 reg_names[regno+1], info->reg_offset[regno]);
1247 fputc ('\n', stderr);
1251 fflush (stderr);
1257 /* The following variable value is TRUE if the next output insn should
1258 finish cpu cycle. In order words the insn will have packing bit
1259 (which means absence of asm code suffix `.p' on assembler. */
1261 static int frv_insn_packing_flag;
1263 /* True if the current function contains a far jump. */
1265 static int
1266 frv_function_contains_far_jump ()
1268 rtx insn = get_insns ();
1269 while (insn != NULL
1270 && !(GET_CODE (insn) == JUMP_INSN
1271 /* Ignore tablejump patterns. */
1272 && GET_CODE (PATTERN (insn)) != ADDR_VEC
1273 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
1274 && get_attr_far_jump (insn) == FAR_JUMP_YES))
1275 insn = NEXT_INSN (insn);
1276 return (insn != NULL);
1279 /* For the FRV, this function makes sure that a function with far jumps
1280 will return correctly. It also does the VLIW packing. */
1282 static void
1283 frv_function_prologue (file, size)
1284 FILE *file;
1285 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
1287 /* If no frame was created, check whether the function uses a call
1288 instruction to implement a far jump. If so, save the link in gr3 and
1289 replace all returns to LR with returns to GR3. GR3 is used because it
1290 is call-clobbered, because is not available to the register allocator,
1291 and because all functions that take a hidden argument pointer will have
1292 a stack frame. */
1293 if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ())
1295 rtx insn;
1297 /* Just to check that the above comment is true. */
1298 if (regs_ever_live[GPR_FIRST + 3])
1299 abort ();
1301 /* Generate the instruction that saves the link register. */
1302 fprintf (file, "\tmovsg lr,gr3\n");
1304 /* Replace the LR with GR3 in *return_internal patterns. The insn
1305 will now return using jmpl @(gr3,0) rather than bralr. We cannot
1306 simply emit a different assembly directive because bralr and jmpl
1307 execute in different units. */
1308 for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn))
1309 if (GET_CODE (insn) == JUMP_INSN)
1311 rtx pattern = PATTERN (insn);
1312 if (GET_CODE (pattern) == PARALLEL
1313 && XVECLEN (pattern, 0) >= 2
1314 && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN
1315 && GET_CODE (XVECEXP (pattern, 0, 1)) == USE)
1317 rtx address = XEXP (XVECEXP (pattern, 0, 1), 0);
1318 if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO)
1319 REGNO (address) = GPR_FIRST + 3;
1324 frv_pack_insns ();
1325 frv_insn_packing_flag = TRUE;
1329 /* Return the next available temporary register in a given class. */
1331 static rtx
1332 frv_alloc_temp_reg (info, class, mode, mark_as_used, no_abort)
1333 frv_tmp_reg_t *info; /* which registers are available */
1334 enum reg_class class; /* register class desired */
1335 enum machine_mode mode; /* mode to allocate register with */
1336 int mark_as_used; /* register not available after allocation */
1337 int no_abort; /* return NULL instead of aborting */
1339 int regno = info->next_reg[ (int)class ];
1340 int orig_regno = regno;
1341 HARD_REG_SET *reg_in_class = &reg_class_contents[ (int)class ];
1342 int i, nr;
1344 for (;;)
1346 if (TEST_HARD_REG_BIT (*reg_in_class, regno)
1347 && TEST_HARD_REG_BIT (info->regs, regno))
1348 break;
1350 if (++regno >= FIRST_PSEUDO_REGISTER)
1351 regno = 0;
1352 if (regno == orig_regno)
1354 if (no_abort)
1355 return NULL_RTX;
1356 else
1357 abort ();
1361 nr = HARD_REGNO_NREGS (regno, mode);
1362 info->next_reg[ (int)class ] = regno + nr;
1364 if (mark_as_used)
1365 for (i = 0; i < nr; i++)
1366 CLEAR_HARD_REG_BIT (info->regs, regno+i);
1368 return gen_rtx_REG (mode, regno);
1372 /* Return an rtx with the value OFFSET, which will either be a register or a
1373 signed 12-bit integer. It can be used as the second operand in an "add"
1374 instruction, or as the index in a load or store.
1376 The function returns a constant rtx if OFFSET is small enough, otherwise
1377 it loads the constant into register OFFSET_REGNO and returns that. */
1378 static rtx
1379 frv_frame_offset_rtx (offset)
1380 int offset;
1382 rtx offset_rtx = GEN_INT (offset);
1383 if (IN_RANGE_P (offset, -2048, 2047))
1384 return offset_rtx;
1385 else
1387 rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO);
1388 if (IN_RANGE_P (offset, -32768, 32767))
1389 emit_insn (gen_movsi (reg_rtx, offset_rtx));
1390 else
1392 emit_insn (gen_movsi_high (reg_rtx, offset_rtx));
1393 emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx));
1395 return reg_rtx;
1399 /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The
1400 prologue and epilogue uses such expressions to access the stack. */
1401 static rtx
1402 frv_frame_mem (mode, base, offset)
1403 enum machine_mode mode;
1404 rtx base;
1405 int offset;
1407 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode,
1408 base,
1409 frv_frame_offset_rtx (offset)));
1412 /* Generate a frame-related expression:
1414 (set REG (mem (plus (sp) (const_int OFFSET)))).
1416 Such expressions are used in FRAME_RELATED_EXPR notes for more complex
1417 instructions. Marking the expressions as frame-related is superfluous if
1418 the note contains just a single set. But if the note contains a PARALLEL
1419 or SEQUENCE that has several sets, each set must be individually marked
1420 as frame-related. */
1421 static rtx
1422 frv_dwarf_store (reg, offset)
1423 rtx reg;
1424 int offset;
1426 rtx set = gen_rtx_SET (VOIDmode,
1427 gen_rtx_MEM (GET_MODE (reg),
1428 plus_constant (stack_pointer_rtx,
1429 offset)),
1430 reg);
1431 RTX_FRAME_RELATED_P (set) = 1;
1432 return set;
1435 /* Emit a frame-related instruction whose pattern is PATTERN. The
1436 instruction is the last in a sequence that cumulatively performs the
1437 operation described by DWARF_PATTERN. The instruction is marked as
1438 frame-related and has a REG_FRAME_RELATED_EXPR note containing
1439 DWARF_PATTERN. */
1440 static void
1441 frv_frame_insn (pattern, dwarf_pattern)
1442 rtx pattern;
1443 rtx dwarf_pattern;
1445 rtx insn = emit_insn (pattern);
1446 RTX_FRAME_RELATED_P (insn) = 1;
1447 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1448 dwarf_pattern,
1449 REG_NOTES (insn));
1452 /* Emit instructions that transfer REG to or from the memory location (sp +
1453 STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is
1454 FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this
1455 function to store registers and only the epilogue uses it to load them.
1457 The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET).
1458 The generated instruction will use BASE as its base register. BASE may
1459 simply be the stack pointer, but if several accesses are being made to a
1460 region far away from the stack pointer, it may be more efficient to set
1461 up a temporary instead.
1463 Store instructions will be frame-related and will be annotated with the
1464 overall effect of the store. Load instructions will be followed by a
1465 (use) to prevent later optimizations from zapping them.
1467 The function takes care of the moves to and from SPRs, using TEMP_REGNO
1468 as a temporary in such cases. */
1469 static void
1470 frv_frame_access (accessor, reg, stack_offset)
1471 frv_frame_accessor_t *accessor;
1472 rtx reg;
1473 int stack_offset;
1475 enum machine_mode mode = GET_MODE (reg);
1476 rtx mem = frv_frame_mem (mode,
1477 accessor->base,
1478 stack_offset - accessor->base_offset);
1480 if (accessor->op == FRV_LOAD)
1482 if (SPR_P (REGNO (reg)))
1484 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1485 emit_insn (gen_rtx_SET (VOIDmode, temp, mem));
1486 emit_insn (gen_rtx_SET (VOIDmode, reg, temp));
1488 else
1489 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
1490 emit_insn (gen_rtx_USE (VOIDmode, reg));
1492 else
1494 if (SPR_P (REGNO (reg)))
1496 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1497 emit_insn (gen_rtx_SET (VOIDmode, temp, reg));
1498 frv_frame_insn (gen_rtx_SET (Pmode, mem, temp),
1499 frv_dwarf_store (reg, stack_offset));
1501 else if (GET_MODE (reg) == DImode)
1503 /* For DImode saves, the dwarf2 version needs to be a SEQUENCE
1504 with a separate save for each register. */
1505 rtx reg1 = gen_rtx_REG (SImode, REGNO (reg));
1506 rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1);
1507 rtx set1 = frv_dwarf_store (reg1, stack_offset);
1508 rtx set2 = frv_dwarf_store (reg2, stack_offset + 4);
1509 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1510 gen_rtx_PARALLEL (VOIDmode,
1511 gen_rtvec (2, set1, set2)));
1513 else
1514 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1515 frv_dwarf_store (reg, stack_offset));
1519 /* A function that uses frv_frame_access to transfer a group of registers to
1520 or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO
1521 is the stack information generated by frv_stack_info, and REG_SET is the
1522 number of the register set to transfer. */
1523 static void
1524 frv_frame_access_multi (accessor, info, reg_set)
1525 frv_frame_accessor_t *accessor;
1526 frv_stack_t *info;
1527 int reg_set;
1529 frv_stack_regs_t *regs_info;
1530 int regno;
1532 regs_info = &info->regs[reg_set];
1533 for (regno = regs_info->first; regno <= regs_info->last; regno++)
1534 if (info->save_p[regno])
1535 frv_frame_access (accessor,
1536 info->save_p[regno] == REG_SAVE_2WORDS
1537 ? gen_rtx_REG (DImode, regno)
1538 : gen_rtx_REG (SImode, regno),
1539 info->reg_offset[regno]);
1542 /* Save or restore callee-saved registers that are kept outside the frame
1543 header. The function saves the registers if OP is FRV_STORE and restores
1544 them if OP is FRV_LOAD. INFO is the stack information generated by
1545 frv_stack_info. */
1546 static void
1547 frv_frame_access_standard_regs (op, info)
1548 enum frv_stack_op op;
1549 frv_stack_t *info;
1551 frv_frame_accessor_t accessor;
1553 accessor.op = op;
1554 accessor.base = stack_pointer_rtx;
1555 accessor.base_offset = 0;
1556 frv_frame_access_multi (&accessor, info, STACK_REGS_GPR);
1557 frv_frame_access_multi (&accessor, info, STACK_REGS_FPR);
1558 frv_frame_access_multi (&accessor, info, STACK_REGS_LCR);
1562 /* Called after register allocation to add any instructions needed for the
1563 prologue. Using a prologue insn is favored compared to putting all of the
1564 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
1565 to intermix instructions with the saves of the caller saved registers. In
1566 some cases, it might be necessary to emit a barrier instruction as the last
1567 insn to prevent such scheduling.
1569 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
1570 so that the debug info generation code can handle them properly. */
1571 void
1572 frv_expand_prologue ()
1574 frv_stack_t *info = frv_stack_info ();
1575 rtx sp = stack_pointer_rtx;
1576 rtx fp = frame_pointer_rtx;
1577 frv_frame_accessor_t accessor;
1579 if (TARGET_DEBUG_STACK)
1580 frv_debug_stack (info);
1582 if (info->total_size == 0)
1583 return;
1585 /* We're interested in three areas of the frame here:
1587 A: the register save area
1588 B: the old FP
1589 C: the header after B
1591 If the frame pointer isn't used, we'll have to set up A, B and C
1592 using the stack pointer. If the frame pointer is used, we'll access
1593 them as follows:
1595 A: set up using sp
1596 B: set up using sp or a temporary (see below)
1597 C: set up using fp
1599 We set up B using the stack pointer if the frame is small enough.
1600 Otherwise, it's more efficient to copy the old stack pointer into a
1601 temporary and use that.
1603 Note that it's important to make sure the prologue and epilogue use the
1604 same registers to access A and C, since doing otherwise will confuse
1605 the aliasing code. */
1607 /* Set up ACCESSOR for accessing region B above. If the frame pointer
1608 isn't used, the same method will serve for C. */
1609 accessor.op = FRV_STORE;
1610 if (frame_pointer_needed && info->total_size > 2048)
1612 rtx insn;
1614 accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO);
1615 accessor.base_offset = info->total_size;
1616 insn = emit_insn (gen_movsi (accessor.base, sp));
1618 else
1620 accessor.base = stack_pointer_rtx;
1621 accessor.base_offset = 0;
1624 /* Allocate the stack space. */
1626 rtx asm_offset = frv_frame_offset_rtx (-info->total_size);
1627 rtx dwarf_offset = GEN_INT (-info->total_size);
1629 frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset),
1630 gen_rtx_SET (Pmode,
1632 gen_rtx_PLUS (Pmode, sp, dwarf_offset)));
1635 /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET)
1636 and point the new one to that location. */
1637 if (frame_pointer_needed)
1639 int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1641 /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is
1642 based on ACCESSOR.BASE but DWARF_SRC is always based on the stack
1643 pointer. */
1644 rtx asm_src = plus_constant (accessor.base,
1645 fp_offset - accessor.base_offset);
1646 rtx dwarf_src = plus_constant (sp, fp_offset);
1648 /* Store the old frame pointer at (sp + FP_OFFSET). */
1649 frv_frame_access (&accessor, fp, fp_offset);
1651 /* Set up the new frame pointer. */
1652 frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src),
1653 gen_rtx_SET (VOIDmode, fp, dwarf_src));
1655 /* Access region C from the frame pointer. */
1656 accessor.base = fp;
1657 accessor.base_offset = fp_offset;
1660 /* Set up region C. */
1661 frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT);
1662 frv_frame_access_multi (&accessor, info, STACK_REGS_LR);
1663 frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG);
1665 /* Set up region A. */
1666 frv_frame_access_standard_regs (FRV_STORE, info);
1668 /* If this is a varargs/stdarg function, issue a blockage to prevent the
1669 scheduler from moving loads before the stores saving the registers. */
1670 if (info->stdarg_size > 0)
1671 emit_insn (gen_blockage ());
1673 /* Set up pic register/small data register for this function. */
1674 if (flag_pic && cfun->uses_pic_offset_table)
1675 emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO),
1676 gen_rtx_REG (Pmode, LR_REGNO),
1677 gen_rtx_REG (SImode, OFFSET_REGNO)));
1681 /* Under frv, all of the work is done via frv_expand_epilogue, but
1682 this function provides a convient place to do cleanup. */
1684 static void
1685 frv_function_epilogue (file, size)
1686 FILE *file ATTRIBUTE_UNUSED;
1687 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
1689 frv_stack_cache = (frv_stack_t *)0;
1691 /* zap last used registers for conditional execution. */
1692 memset ((PTR) &frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg));
1694 /* release the bitmap of created insns. */
1695 BITMAP_XFREE (frv_ifcvt.scratch_insns_bitmap);
1699 /* Called after register allocation to add any instructions needed for the
1700 epilogue. Using an epilogue insn is favored compared to putting all of the
1701 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
1702 to intermix instructions with the saves of the caller saved registers. In
1703 some cases, it might be necessary to emit a barrier instruction as the last
1704 insn to prevent such scheduling.
1706 If SIBCALL_P is true, the final branch back to the calling function is
1707 omitted, and is used for sibling call (aka tail call) sites. For sibcalls,
1708 we must not clobber any arguments used for parameter passing or any stack
1709 slots for arguments passed to the current function. */
1711 void
1712 frv_expand_epilogue (sibcall_p)
1713 int sibcall_p;
1715 frv_stack_t *info = frv_stack_info ();
1716 rtx fp = frame_pointer_rtx;
1717 rtx sp = stack_pointer_rtx;
1718 rtx return_addr;
1719 int fp_offset;
1721 fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1723 /* Restore the stack pointer to its original value if alloca or the like
1724 is used. */
1725 if (! current_function_sp_is_unchanging)
1726 emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset)));
1728 /* Restore the callee-saved registers that were used in this function. */
1729 frv_frame_access_standard_regs (FRV_LOAD, info);
1731 /* Set RETURN_ADDR to the address we should return to. Set it to NULL if
1732 no return instruction should be emitted. */
1733 if (sibcall_p)
1734 return_addr = 0;
1735 else if (info->save_p[LR_REGNO])
1737 int lr_offset;
1738 rtx mem;
1740 /* Use the same method to access the link register's slot as we did in
1741 the prologue. In other words, use the frame pointer if available,
1742 otherwise use the stack pointer.
1744 LR_OFFSET is the offset of the link register's slot from the start
1745 of the frame and MEM is a memory rtx for it. */
1746 lr_offset = info->reg_offset[LR_REGNO];
1747 if (frame_pointer_needed)
1748 mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset);
1749 else
1750 mem = frv_frame_mem (Pmode, sp, lr_offset);
1752 /* Load the old link register into a GPR. */
1753 return_addr = gen_rtx_REG (Pmode, TEMP_REGNO);
1754 emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem));
1756 else
1757 return_addr = gen_rtx_REG (Pmode, LR_REGNO);
1759 /* Restore the old frame pointer. Emit a USE afterwards to make sure
1760 the load is preserved. */
1761 if (frame_pointer_needed)
1763 emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp)));
1764 emit_insn (gen_rtx_USE (VOIDmode, fp));
1767 /* Deallocate the stack frame. */
1768 if (info->total_size != 0)
1770 rtx offset = frv_frame_offset_rtx (info->total_size);
1771 emit_insn (gen_stack_adjust (sp, sp, offset));
1774 /* If this function uses eh_return, add the final stack adjustment now. */
1775 if (current_function_calls_eh_return)
1776 emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX));
1778 if (return_addr)
1779 emit_jump_insn (gen_epilogue_return (return_addr));
1783 /* A C compound statement that outputs the assembler code for a thunk function,
1784 used to implement C++ virtual function calls with multiple inheritance. The
1785 thunk acts as a wrapper around a virtual function, adjusting the implicit
1786 object parameter before handing control off to the real function.
1788 First, emit code to add the integer DELTA to the location that contains the
1789 incoming first argument. Assume that this argument contains a pointer, and
1790 is the one used to pass the `this' pointer in C++. This is the incoming
1791 argument *before* the function prologue, e.g. `%o0' on a sparc. The
1792 addition must preserve the values of all other incoming arguments.
1794 After the addition, emit code to jump to FUNCTION, which is a
1795 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
1796 the return address. Hence returning from FUNCTION will return to whoever
1797 called the current `thunk'.
1799 The effect must be as if FUNCTION had been called directly with the adjusted
1800 first argument. This macro is responsible for emitting all of the code for
1801 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
1802 invoked.
1804 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
1805 extracted from it.) It might possibly be useful on some targets, but
1806 probably not.
1808 If you do not define this macro, the target-independent code in the C++
1809 frontend will generate a less efficient heavyweight thunk that calls
1810 FUNCTION instead of jumping to it. The generic approach does not support
1811 varargs. */
1813 static void
1814 frv_asm_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
1815 FILE *file;
1816 tree thunk_fndecl ATTRIBUTE_UNUSED;
1817 HOST_WIDE_INT delta;
1818 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED;
1819 tree function;
1821 const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0);
1822 const char *name_arg0 = reg_names[FIRST_ARG_REGNUM];
1823 const char *name_jmp = reg_names[JUMP_REGNO];
1824 const char *parallel = ((PACKING_FLAG_USED_P ()) ? ".p" : "");
1826 /* Do the add using an addi if possible */
1827 if (IN_RANGE_P (delta, -2048, 2047))
1828 fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0);
1829 else
1831 const char *const name_add = reg_names[TEMP_REGNO];
1832 fprintf (file, "\tsethi%s #hi(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1833 parallel, delta, name_add);
1834 fprintf (file, "\tsetlo #lo(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1835 delta, name_add);
1836 fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0);
1839 if (!flag_pic)
1841 fprintf (file, "\tsethi%s #hi(", parallel);
1842 assemble_name (file, name_func);
1843 fprintf (file, "),%s\n", name_jmp);
1845 fprintf (file, "\tsetlo #lo(");
1846 assemble_name (file, name_func);
1847 fprintf (file, "),%s\n", name_jmp);
1849 else
1851 /* Use JUMP_REGNO as a temporary PIC register. */
1852 const char *name_lr = reg_names[LR_REGNO];
1853 const char *name_gppic = name_jmp;
1854 const char *name_tmp = reg_names[TEMP_REGNO];
1856 fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp);
1857 fprintf (file, "\tcall 1f\n");
1858 fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic);
1859 fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr);
1860 fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp);
1861 fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp);
1862 fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic);
1864 fprintf (file, "\tsethi%s #gprelhi(", parallel);
1865 assemble_name (file, name_func);
1866 fprintf (file, "),%s\n", name_tmp);
1868 fprintf (file, "\tsetlo #gprello(");
1869 assemble_name (file, name_func);
1870 fprintf (file, "),%s\n", name_tmp);
1872 fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp);
1875 /* Jump to the function address */
1876 fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]);
1880 /* A C expression which is nonzero if a function must have and use a frame
1881 pointer. This expression is evaluated in the reload pass. If its value is
1882 nonzero the function will have a frame pointer.
1884 The expression can in principle examine the current function and decide
1885 according to the facts, but on most machines the constant 0 or the constant
1886 1 suffices. Use 0 when the machine allows code to be generated with no
1887 frame pointer, and doing so saves some time or space. Use 1 when there is
1888 no possible advantage to avoiding a frame pointer.
1890 In certain cases, the compiler does not know how to produce valid code
1891 without a frame pointer. The compiler recognizes those cases and
1892 automatically gives the function a frame pointer regardless of what
1893 `FRAME_POINTER_REQUIRED' says. You don't need to worry about them.
1895 In a function that does not require a frame pointer, the frame pointer
1896 register can be allocated for ordinary usage, unless you mark it as a fixed
1897 register. See `FIXED_REGISTERS' for more information. */
1899 /* On frv, create a frame whenever we need to create stack */
1902 frv_frame_pointer_required ()
1904 if (! current_function_is_leaf)
1905 return TRUE;
1907 if (get_frame_size () != 0)
1908 return TRUE;
1910 if (cfun->stdarg)
1911 return TRUE;
1913 if (!current_function_sp_is_unchanging)
1914 return TRUE;
1916 if (flag_pic && cfun->uses_pic_offset_table)
1917 return TRUE;
1919 if (profile_flag)
1920 return TRUE;
1922 if (cfun->machine->frame_needed)
1923 return TRUE;
1925 return FALSE;
1929 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the
1930 initial difference between the specified pair of registers. This macro must
1931 be defined if `ELIMINABLE_REGS' is defined. */
1933 /* See frv_stack_info for more details on the frv stack frame. */
1936 frv_initial_elimination_offset (from, to)
1937 int from;
1938 int to;
1940 frv_stack_t *info = frv_stack_info ();
1941 int ret = 0;
1943 if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
1944 ret = info->total_size - info->pretend_size;
1946 else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM)
1947 ret = - info->reg_offset[FRAME_POINTER_REGNUM];
1949 else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
1950 ret = (info->total_size
1951 - info->reg_offset[FRAME_POINTER_REGNUM]
1952 - info->pretend_size);
1954 else
1955 abort ();
1957 if (TARGET_DEBUG_STACK)
1958 fprintf (stderr, "Eliminate %s to %s by adding %d\n",
1959 reg_names [from], reg_names[to], ret);
1961 return ret;
1965 /* This macro offers an alternative to using `__builtin_saveregs' and defining
1966 the macro `EXPAND_BUILTIN_SAVEREGS'. Use it to store the anonymous register
1967 arguments into the stack so that all the arguments appear to have been
1968 passed consecutively on the stack. Once this is done, you can use the
1969 standard implementation of varargs that works for machines that pass all
1970 their arguments on the stack.
1972 The argument ARGS_SO_FAR is the `CUMULATIVE_ARGS' data structure, containing
1973 the values that obtain after processing of the named arguments. The
1974 arguments MODE and TYPE describe the last named argument--its machine mode
1975 and its data type as a tree node.
1977 The macro implementation should do two things: first, push onto the stack
1978 all the argument registers *not* used for the named arguments, and second,
1979 store the size of the data thus pushed into the `int'-valued variable whose
1980 name is supplied as the argument PRETEND_ARGS_SIZE. The value that you
1981 store here will serve as additional offset for setting up the stack frame.
1983 Because you must generate code to push the anonymous arguments at compile
1984 time without knowing their data types, `SETUP_INCOMING_VARARGS' is only
1985 useful on machines that have just a single category of argument register and
1986 use it uniformly for all data types.
1988 If the argument SECOND_TIME is nonzero, it means that the arguments of the
1989 function are being analyzed for the second time. This happens for an inline
1990 function, which is not actually compiled until the end of the source file.
1991 The macro `SETUP_INCOMING_VARARGS' should not generate any instructions in
1992 this case. */
1994 void
1995 frv_setup_incoming_varargs (cum, mode, type, pretend_size, second_time)
1996 CUMULATIVE_ARGS *cum;
1997 enum machine_mode mode;
1998 tree type ATTRIBUTE_UNUSED;
1999 int *pretend_size;
2000 int second_time;
2002 if (TARGET_DEBUG_ARG)
2003 fprintf (stderr,
2004 "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n",
2005 *cum, GET_MODE_NAME (mode), *pretend_size, second_time);
2009 /* If defined, is a C expression that produces the machine-specific code for a
2010 call to `__builtin_saveregs'. This code will be moved to the very beginning
2011 of the function, before any parameter access are made. The return value of
2012 this function should be an RTX that contains the value to use as the return
2013 of `__builtin_saveregs'.
2015 If this macro is not defined, the compiler will output an ordinary call to
2016 the library function `__builtin_saveregs'. */
2019 frv_expand_builtin_saveregs ()
2021 int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS;
2023 if (TARGET_DEBUG_ARG)
2024 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2025 offset);
2027 return gen_rtx (PLUS, Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2031 /* Expand __builtin_va_start to do the va_start macro. */
2033 void
2034 frv_expand_builtin_va_start (valist, nextarg)
2035 tree valist;
2036 rtx nextarg;
2038 tree t;
2039 int num = cfun->args_info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS;
2041 nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx,
2042 GEN_INT (UNITS_PER_WORD * num));
2044 if (TARGET_DEBUG_ARG)
2046 fprintf (stderr, "va_start: args_info = %d, num = %d\n",
2047 cfun->args_info, num);
2049 debug_rtx (nextarg);
2052 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2053 make_tree (ptr_type_node, nextarg));
2054 TREE_SIDE_EFFECTS (t) = 1;
2056 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2060 /* Expand __builtin_va_arg to do the va_arg macro. */
2063 frv_expand_builtin_va_arg(valist, type)
2064 tree valist;
2065 tree type;
2067 rtx addr;
2068 rtx mem;
2069 rtx reg;
2071 if (TARGET_DEBUG_ARG)
2073 fprintf (stderr, "va_arg:\n");
2074 debug_tree (type);
2077 if (! AGGREGATE_TYPE_P (type))
2078 return std_expand_builtin_va_arg (valist, type);
2080 addr = std_expand_builtin_va_arg (valist, ptr_type_node);
2081 mem = gen_rtx_MEM (Pmode, addr);
2082 reg = gen_reg_rtx (Pmode);
2084 set_mem_alias_set (mem, get_varargs_alias_set ());
2085 emit_move_insn (reg, mem);
2087 return reg;
2091 /* Expand a block move operation, and return 1 if successful. Return 0
2092 if we should let the compiler generate normal code.
2094 operands[0] is the destination
2095 operands[1] is the source
2096 operands[2] is the length
2097 operands[3] is the alignment */
2099 /* Maximum number of loads to do before doing the stores */
2100 #ifndef MAX_MOVE_REG
2101 #define MAX_MOVE_REG 4
2102 #endif
2104 /* Maximum number of total loads to do. */
2105 #ifndef TOTAL_MOVE_REG
2106 #define TOTAL_MOVE_REG 8
2107 #endif
2110 frv_expand_block_move (operands)
2111 rtx operands[];
2113 rtx orig_dest = operands[0];
2114 rtx orig_src = operands[1];
2115 rtx bytes_rtx = operands[2];
2116 rtx align_rtx = operands[3];
2117 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2118 int align;
2119 int bytes;
2120 int offset;
2121 int num_reg;
2122 int i;
2123 rtx src_reg;
2124 rtx dest_reg;
2125 rtx src_addr;
2126 rtx dest_addr;
2127 rtx src_mem;
2128 rtx dest_mem;
2129 rtx tmp_reg;
2130 rtx stores[MAX_MOVE_REG];
2131 int move_bytes;
2132 enum machine_mode mode;
2134 /* If this is not a fixed size move, just call memcpy */
2135 if (! constp)
2136 return FALSE;
2138 /* If this is not a fixed size alignment, abort */
2139 if (GET_CODE (align_rtx) != CONST_INT)
2140 abort ();
2142 align = INTVAL (align_rtx);
2144 /* Anything to move? */
2145 bytes = INTVAL (bytes_rtx);
2146 if (bytes <= 0)
2147 return TRUE;
2149 /* Don't support real large moves. */
2150 if (bytes > TOTAL_MOVE_REG*align)
2151 return FALSE;
2153 /* Move the address into scratch registers. */
2154 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2155 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2157 num_reg = offset = 0;
2158 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2160 /* Calculate the correct offset for src/dest */
2161 if (offset == 0)
2163 src_addr = src_reg;
2164 dest_addr = dest_reg;
2166 else
2168 src_addr = plus_constant (src_reg, offset);
2169 dest_addr = plus_constant (dest_reg, offset);
2172 /* Generate the appropriate load and store, saving the stores
2173 for later. */
2174 if (bytes >= 4 && align >= 4)
2175 mode = SImode;
2176 else if (bytes >= 2 && align >= 2)
2177 mode = HImode;
2178 else
2179 mode = QImode;
2181 move_bytes = GET_MODE_SIZE (mode);
2182 tmp_reg = gen_reg_rtx (mode);
2183 src_mem = change_address (orig_src, mode, src_addr);
2184 dest_mem = change_address (orig_dest, mode, dest_addr);
2185 emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem));
2186 stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg);
2188 if (num_reg >= MAX_MOVE_REG)
2190 for (i = 0; i < num_reg; i++)
2191 emit_insn (stores[i]);
2192 num_reg = 0;
2196 for (i = 0; i < num_reg; i++)
2197 emit_insn (stores[i]);
2199 return TRUE;
2203 /* Expand a block clear operation, and return 1 if successful. Return 0
2204 if we should let the compiler generate normal code.
2206 operands[0] is the destination
2207 operands[1] is the length
2208 operands[2] is the alignment */
2211 frv_expand_block_clear (operands)
2212 rtx operands[];
2214 rtx orig_dest = operands[0];
2215 rtx bytes_rtx = operands[1];
2216 rtx align_rtx = operands[2];
2217 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2218 int align;
2219 int bytes;
2220 int offset;
2221 int num_reg;
2222 rtx dest_reg;
2223 rtx dest_addr;
2224 rtx dest_mem;
2225 int clear_bytes;
2226 enum machine_mode mode;
2228 /* If this is not a fixed size move, just call memcpy */
2229 if (! constp)
2230 return FALSE;
2232 /* If this is not a fixed size alignment, abort */
2233 if (GET_CODE (align_rtx) != CONST_INT)
2234 abort ();
2236 align = INTVAL (align_rtx);
2238 /* Anything to move? */
2239 bytes = INTVAL (bytes_rtx);
2240 if (bytes <= 0)
2241 return TRUE;
2243 /* Don't support real large clears. */
2244 if (bytes > TOTAL_MOVE_REG*align)
2245 return FALSE;
2247 /* Move the address into a scratch register. */
2248 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2250 num_reg = offset = 0;
2251 for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes))
2253 /* Calculate the correct offset for src/dest */
2254 dest_addr = ((offset == 0)
2255 ? dest_reg
2256 : plus_constant (dest_reg, offset));
2258 /* Generate the appropriate store of gr0 */
2259 if (bytes >= 4 && align >= 4)
2260 mode = SImode;
2261 else if (bytes >= 2 && align >= 2)
2262 mode = HImode;
2263 else
2264 mode = QImode;
2266 clear_bytes = GET_MODE_SIZE (mode);
2267 dest_mem = change_address (orig_dest, mode, dest_addr);
2268 emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx));
2271 return TRUE;
2275 /* The following variable is used to output modifiers of assembler
2276 code of the current output insn.. */
2278 static rtx *frv_insn_operands;
2280 /* The following function is used to add assembler insn code suffix .p
2281 if it is necessary. */
2283 const char *
2284 frv_asm_output_opcode (f, ptr)
2285 FILE *f;
2286 const char *ptr;
2288 int c;
2290 if (! PACKING_FLAG_USED_P())
2291 return ptr;
2293 for (; *ptr && *ptr != ' ' && *ptr != '\t';)
2295 c = *ptr++;
2296 if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z')
2297 || (*ptr >= 'A' && *ptr <= 'Z')))
2299 int letter = *ptr++;
2301 c = atoi (ptr);
2302 frv_print_operand (f, frv_insn_operands [c], letter);
2303 while ((c = *ptr) >= '0' && c <= '9')
2304 ptr++;
2306 else
2307 fputc (c, f);
2310 if (!frv_insn_packing_flag)
2311 fprintf (f, ".p");
2313 return ptr;
2316 /* The following function sets up the packing bit for the current
2317 output insn. Remember that the function is not called for asm
2318 insns. */
2320 void
2321 frv_final_prescan_insn (insn, opvec, noperands)
2322 rtx insn;
2323 rtx *opvec;
2324 int noperands ATTRIBUTE_UNUSED;
2326 if (! PACKING_FLAG_USED_P())
2327 return;
2329 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
2330 return;
2332 frv_insn_operands = opvec;
2334 /* Look for the next printable instruction. frv_pack_insns () has set
2335 things up so that any printable instruction will have TImode if it
2336 starts a new packet and VOIDmode if it should be packed with the
2337 previous instruction.
2339 Printable instructions will be asm_operands or match one of the .md
2340 patterns. Since asm instructions cannot be packed -- and will
2341 therefore have TImode -- this loop terminates on any recognisable
2342 instruction, and on any unrecognisable instruction with TImode. */
2343 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
2345 if (NOTE_P (insn))
2346 continue;
2347 else if (!INSN_P (insn))
2348 break;
2349 else if (GET_MODE (insn) == TImode || INSN_CODE (insn) != -1)
2350 break;
2353 /* Set frv_insn_packing_flag to FALSE if the next instruction should
2354 be packed with this one. Set it to TRUE otherwise. If the next
2355 instruction is an asm insntruction, this statement will set the
2356 flag to TRUE, and that value will still hold when the asm operands
2357 themselves are printed. */
2358 frv_insn_packing_flag = ! (insn && INSN_P (insn)
2359 && GET_MODE (insn) != TImode);
2364 /* A C expression whose value is RTL representing the address in a stack frame
2365 where the pointer to the caller's frame is stored. Assume that FRAMEADDR is
2366 an RTL expression for the address of the stack frame itself.
2368 If you don't define this macro, the default is to return the value of
2369 FRAMEADDR--that is, the stack frame address is also the address of the stack
2370 word that points to the previous frame. */
2372 /* The default is correct, but we need to make sure the frame gets created. */
2374 frv_dynamic_chain_address (frame)
2375 rtx frame;
2377 cfun->machine->frame_needed = 1;
2378 return frame;
2382 /* A C expression whose value is RTL representing the value of the return
2383 address for the frame COUNT steps up from the current frame, after the
2384 prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame
2385 pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
2386 defined.
2388 The value of the expression must always be the correct address when COUNT is
2389 zero, but may be `NULL_RTX' if there is not way to determine the return
2390 address of other frames. */
2393 frv_return_addr_rtx (count, frame)
2394 int count ATTRIBUTE_UNUSED;
2395 rtx frame;
2397 cfun->machine->frame_needed = 1;
2398 return gen_rtx_MEM (Pmode, plus_constant (frame, 8));
2401 /* Given a memory reference MEMREF, interpret the referenced memory as
2402 an array of MODE values, and return a reference to the element
2403 specified by INDEX. Assume that any pre-modification implicit in
2404 MEMREF has already happened.
2406 MEMREF must be a legitimate operand for modes larger than SImode.
2407 GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which
2408 this function cannot handle. */
2410 frv_index_memory (memref, mode, index)
2411 rtx memref;
2412 enum machine_mode mode;
2413 int index;
2415 rtx base = XEXP (memref, 0);
2416 if (GET_CODE (base) == PRE_MODIFY)
2417 base = XEXP (base, 0);
2418 return change_address (memref, mode,
2419 plus_constant (base, index * GET_MODE_SIZE (mode)));
2423 /* Print a memory address as an operand to reference that memory location. */
2424 void
2425 frv_print_operand_address (stream, x)
2426 FILE * stream;
2427 rtx x;
2429 if (GET_CODE (x) == MEM)
2430 x = XEXP (x, 0);
2432 switch (GET_CODE (x))
2434 case REG:
2435 fputs (reg_names [ REGNO (x)], stream);
2436 return;
2438 case CONST_INT:
2439 fprintf (stream, "%ld", (long) INTVAL (x));
2440 return;
2442 case SYMBOL_REF:
2443 assemble_name (stream, XSTR (x, 0));
2444 return;
2446 case LABEL_REF:
2447 case CONST:
2448 output_addr_const (stream, x);
2449 return;
2451 default:
2452 break;
2455 fatal_insn ("Bad insn to frv_print_operand_address:", x);
2459 static void
2460 frv_print_operand_memory_reference_reg (stream, x)
2461 FILE *stream;
2462 rtx x;
2464 int regno = true_regnum (x);
2465 if (GPR_P (regno))
2466 fputs (reg_names[regno], stream);
2467 else
2468 fatal_insn ("Bad register to frv_print_operand_memory_reference_reg:", x);
2471 /* Print a memory reference suitable for the ld/st instructions. */
2473 static void
2474 frv_print_operand_memory_reference (stream, x, addr_offset)
2475 FILE *stream;
2476 rtx x;
2477 int addr_offset;
2479 rtx x0 = NULL_RTX;
2480 rtx x1 = NULL_RTX;
2482 switch (GET_CODE (x))
2484 case SUBREG:
2485 case REG:
2486 x0 = x;
2487 break;
2489 case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */
2490 x0 = XEXP (x, 0);
2491 x1 = XEXP (XEXP (x, 1), 1);
2492 break;
2494 case CONST_INT:
2495 x1 = x;
2496 break;
2498 case PLUS:
2499 x0 = XEXP (x, 0);
2500 x1 = XEXP (x, 1);
2501 if (GET_CODE (x0) == CONST_INT)
2503 x0 = XEXP (x, 1);
2504 x1 = XEXP (x, 0);
2506 break;
2508 default:
2509 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2510 break;
2514 if (addr_offset)
2516 if (!x1)
2517 x1 = const0_rtx;
2518 else if (GET_CODE (x1) != CONST_INT)
2519 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2522 fputs ("@(", stream);
2523 if (!x0)
2524 fputs (reg_names[GPR_R0], stream);
2525 else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG)
2526 frv_print_operand_memory_reference_reg (stream, x0);
2527 else
2528 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2530 fputs (",", stream);
2531 if (!x1)
2532 fputs (reg_names [GPR_R0], stream);
2534 else
2536 switch (GET_CODE (x1))
2538 case SUBREG:
2539 case REG:
2540 frv_print_operand_memory_reference_reg (stream, x1);
2541 break;
2543 case CONST_INT:
2544 fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset));
2545 break;
2547 case SYMBOL_REF:
2548 if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG
2549 && SYMBOL_REF_SMALL_P (x1))
2551 fputs ("#gprel12(", stream);
2552 assemble_name (stream, XSTR (x1, 0));
2553 fputs (")", stream);
2555 else
2556 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2557 break;
2559 case CONST:
2560 if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG
2561 && const_small_data_p (x1))
2563 fputs ("#gprel12(", stream);
2564 assemble_name (stream, XSTR (XEXP (XEXP (x1, 0), 0), 0));
2565 fprintf (stream, "+"HOST_WIDE_INT_PRINT_DEC")",
2566 INTVAL (XEXP (XEXP (x1, 0), 1)));
2568 else
2569 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2570 break;
2572 default:
2573 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2577 fputs (")", stream);
2581 /* Return 2 for likely branches and 0 for non-likely branches */
2583 #define FRV_JUMP_LIKELY 2
2584 #define FRV_JUMP_NOT_LIKELY 0
2586 static int
2587 frv_print_operand_jump_hint (insn)
2588 rtx insn;
2590 rtx note;
2591 rtx labelref;
2592 int ret;
2593 HOST_WIDE_INT prob = -1;
2594 enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN;
2596 if (GET_CODE (insn) != JUMP_INSN)
2597 abort ();
2599 /* Assume any non-conditional jump is likely. */
2600 if (! any_condjump_p (insn))
2601 ret = FRV_JUMP_LIKELY;
2603 else
2605 labelref = condjump_label (insn);
2606 if (labelref)
2608 rtx label = XEXP (labelref, 0);
2609 jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label))
2610 ? BACKWARD
2611 : FORWARD);
2614 note = find_reg_note (insn, REG_BR_PROB, 0);
2615 if (!note)
2616 ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY);
2618 else
2620 prob = INTVAL (XEXP (note, 0));
2621 ret = ((prob >= (REG_BR_PROB_BASE / 2))
2622 ? FRV_JUMP_LIKELY
2623 : FRV_JUMP_NOT_LIKELY);
2627 #if 0
2628 if (TARGET_DEBUG)
2630 char *direction;
2632 switch (jump_type)
2634 default:
2635 case UNKNOWN: direction = "unknown jump direction"; break;
2636 case BACKWARD: direction = "jump backward"; break;
2637 case FORWARD: direction = "jump forward"; break;
2640 fprintf (stderr,
2641 "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n",
2642 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
2643 (long)INSN_UID (insn), direction, (long)prob,
2644 (long)REG_BR_PROB_BASE, ret);
2646 #endif
2648 return ret;
2652 /* Print an operand to an assembler instruction.
2654 `%' followed by a letter and a digit says to output an operand in an
2655 alternate fashion. Four letters have standard, built-in meanings described
2656 below. The machine description macro `PRINT_OPERAND' can define additional
2657 letters with nonstandard meanings.
2659 `%cDIGIT' can be used to substitute an operand that is a constant value
2660 without the syntax that normally indicates an immediate operand.
2662 `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated
2663 before printing.
2665 `%aDIGIT' can be used to substitute an operand as if it were a memory
2666 reference, with the actual operand treated as the address. This may be
2667 useful when outputting a "load address" instruction, because often the
2668 assembler syntax for such an instruction requires you to write the operand
2669 as if it were a memory reference.
2671 `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
2673 `%=' outputs a number which is unique to each instruction in the entire
2674 compilation. This is useful for making local labels to be referred to more
2675 than once in a single template that generates multiple assembler
2676 instructions.
2678 `%' followed by a punctuation character specifies a substitution that does
2679 not use an operand. Only one case is standard: `%%' outputs a `%' into the
2680 assembler code. Other nonstandard cases can be defined in the
2681 `PRINT_OPERAND' macro. You must also define which punctuation characters
2682 are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */
2684 void
2685 frv_print_operand (file, x, code)
2686 FILE * file;
2687 rtx x;
2688 int code;
2690 HOST_WIDE_INT value;
2691 int offset;
2693 if (code != 0 && !isalpha (code))
2694 value = 0;
2696 else if (GET_CODE (x) == CONST_INT)
2697 value = INTVAL (x);
2699 else if (GET_CODE (x) == CONST_DOUBLE)
2701 if (GET_MODE (x) == SFmode)
2703 REAL_VALUE_TYPE rv;
2704 long l;
2706 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2707 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2708 value = l;
2711 else if (GET_MODE (x) == VOIDmode)
2712 value = CONST_DOUBLE_LOW (x);
2714 else
2715 fatal_insn ("Bad insn in frv_print_operand, bad const_double", x);
2718 else
2719 value = 0;
2721 switch (code)
2724 case '.':
2725 /* Output r0 */
2726 fputs (reg_names[GPR_R0], file);
2727 break;
2729 case '#':
2730 fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn));
2731 break;
2733 case '@':
2734 /* Output small data area base register (gr16). */
2735 fputs (reg_names[SDA_BASE_REG], file);
2736 break;
2738 case '~':
2739 /* Output pic register (gr17). */
2740 fputs (reg_names[PIC_REGNO], file);
2741 break;
2743 case '*':
2744 /* Output the temporary integer CCR register */
2745 fputs (reg_names[ICR_TEMP], file);
2746 break;
2748 case '&':
2749 /* Output the temporary integer CC register */
2750 fputs (reg_names[ICC_TEMP], file);
2751 break;
2753 /* case 'a': print an address */
2755 case 'C':
2756 /* Print appropriate test for integer branch false operation */
2757 switch (GET_CODE (x))
2759 default:
2760 fatal_insn ("Bad insn to frv_print_operand, 'C' modifier:", x);
2762 case EQ: fputs ("ne", file); break;
2763 case NE: fputs ("eq", file); break;
2764 case LT: fputs ("ge", file); break;
2765 case LE: fputs ("gt", file); break;
2766 case GT: fputs ("le", file); break;
2767 case GE: fputs ("lt", file); break;
2768 case LTU: fputs ("nc", file); break;
2769 case LEU: fputs ("hi", file); break;
2770 case GTU: fputs ("ls", file); break;
2771 case GEU: fputs ("c", file); break;
2773 break;
2775 /* case 'c': print a constant without the constant prefix. If
2776 CONSTANT_ADDRESS_P(x) is not true, PRINT_OPERAND is called. */
2778 case 'c':
2779 /* Print appropriate test for integer branch true operation */
2780 switch (GET_CODE (x))
2782 default:
2783 fatal_insn ("Bad insn to frv_print_operand, 'c' modifier:", x);
2785 case EQ: fputs ("eq", file); break;
2786 case NE: fputs ("ne", file); break;
2787 case LT: fputs ("lt", file); break;
2788 case LE: fputs ("le", file); break;
2789 case GT: fputs ("gt", file); break;
2790 case GE: fputs ("ge", file); break;
2791 case LTU: fputs ("c", file); break;
2792 case LEU: fputs ("ls", file); break;
2793 case GTU: fputs ("hi", file); break;
2794 case GEU: fputs ("nc", file); break;
2796 break;
2798 case 'e':
2799 /* Print 1 for a NE and 0 for an EQ to give the final argument
2800 for a conditional instruction. */
2801 if (GET_CODE (x) == NE)
2802 fputs ("1", file);
2804 else if (GET_CODE (x) == EQ)
2805 fputs ("0", file);
2807 else
2808 fatal_insn ("Bad insn to frv_print_operand, 'e' modifier:", x);
2809 break;
2811 case 'F':
2812 /* Print appropriate test for floating point branch false operation */
2813 switch (GET_CODE (x))
2815 default:
2816 fatal_insn ("Bad insn to frv_print_operand, 'F' modifier:", x);
2818 case EQ: fputs ("ne", file); break;
2819 case NE: fputs ("eq", file); break;
2820 case LT: fputs ("uge", file); break;
2821 case LE: fputs ("ug", file); break;
2822 case GT: fputs ("ule", file); break;
2823 case GE: fputs ("ul", file); break;
2825 break;
2827 case 'f':
2828 /* Print appropriate test for floating point branch true operation */
2829 switch (GET_CODE (x))
2831 default:
2832 fatal_insn ("Bad insn to frv_print_operand, 'f' modifier:", x);
2834 case EQ: fputs ("eq", file); break;
2835 case NE: fputs ("ne", file); break;
2836 case LT: fputs ("lt", file); break;
2837 case LE: fputs ("le", file); break;
2838 case GT: fputs ("gt", file); break;
2839 case GE: fputs ("ge", file); break;
2841 break;
2843 case 'I':
2844 /* Print 'i' if the operand is a constant, or is a memory reference that
2845 adds a constant */
2846 if (GET_CODE (x) == MEM)
2847 x = ((GET_CODE (XEXP (x, 0)) == PLUS)
2848 ? XEXP (XEXP (x, 0), 1)
2849 : XEXP (x, 0));
2851 switch (GET_CODE (x))
2853 default:
2854 break;
2856 case CONST_INT:
2857 case SYMBOL_REF:
2858 case CONST:
2859 fputs ("i", file);
2860 break;
2862 break;
2864 case 'i':
2865 /* For jump instructions, print 'i' if the operand is a constant or
2866 is an expression that adds a constant */
2867 if (GET_CODE (x) == CONST_INT)
2868 fputs ("i", file);
2870 else
2872 if (GET_CODE (x) == CONST_INT
2873 || (GET_CODE (x) == PLUS
2874 && (GET_CODE (XEXP (x, 1)) == CONST_INT
2875 || GET_CODE (XEXP (x, 0)) == CONST_INT)))
2876 fputs ("i", file);
2878 break;
2880 case 'L':
2881 /* Print the lower register of a double word register pair */
2882 if (GET_CODE (x) == REG)
2883 fputs (reg_names[ REGNO (x)+1 ], file);
2884 else
2885 fatal_insn ("Bad insn to frv_print_operand, 'L' modifier:", x);
2886 break;
2888 /* case 'l': print a LABEL_REF */
2890 case 'M':
2891 case 'N':
2892 /* Print a memory reference for ld/st/jmp, %N prints a memory reference
2893 for the second word of double memory operations. */
2894 offset = (code == 'M') ? 0 : UNITS_PER_WORD;
2895 switch (GET_CODE (x))
2897 default:
2898 fatal_insn ("Bad insn to frv_print_operand, 'M/N' modifier:", x);
2900 case MEM:
2901 frv_print_operand_memory_reference (file, XEXP (x, 0), offset);
2902 break;
2904 case REG:
2905 case SUBREG:
2906 case CONST_INT:
2907 case PLUS:
2908 case SYMBOL_REF:
2909 frv_print_operand_memory_reference (file, x, offset);
2910 break;
2912 break;
2914 case 'O':
2915 /* Print the opcode of a command. */
2916 switch (GET_CODE (x))
2918 default:
2919 fatal_insn ("Bad insn to frv_print_operand, 'O' modifier:", x);
2921 case PLUS: fputs ("add", file); break;
2922 case MINUS: fputs ("sub", file); break;
2923 case AND: fputs ("and", file); break;
2924 case IOR: fputs ("or", file); break;
2925 case XOR: fputs ("xor", file); break;
2926 case ASHIFT: fputs ("sll", file); break;
2927 case ASHIFTRT: fputs ("sra", file); break;
2928 case LSHIFTRT: fputs ("srl", file); break;
2930 break;
2932 /* case 'n': negate and print a constant int */
2934 case 'P':
2935 /* Print PIC label using operand as the number. */
2936 if (GET_CODE (x) != CONST_INT)
2937 fatal_insn ("Bad insn to frv_print_operand, P modifier:", x);
2939 fprintf (file, ".LCF%ld", (long)INTVAL (x));
2940 break;
2942 case 'U':
2943 /* Print 'u' if the operand is a update load/store */
2944 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
2945 fputs ("u", file);
2946 break;
2948 case 'z':
2949 /* If value is 0, print gr0, otherwise it must be a register */
2950 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
2951 fputs (reg_names[GPR_R0], file);
2953 else if (GET_CODE (x) == REG)
2954 fputs (reg_names [REGNO (x)], file);
2956 else
2957 fatal_insn ("Bad insn in frv_print_operand, z case", x);
2958 break;
2960 case 'x':
2961 /* Print constant in hex */
2962 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2964 fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value);
2965 break;
2968 /* fall through */
2970 case '\0':
2971 if (GET_CODE (x) == REG)
2972 fputs (reg_names [REGNO (x)], file);
2974 else if (GET_CODE (x) == CONST_INT
2975 || GET_CODE (x) == CONST_DOUBLE)
2976 fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value);
2978 else if (GET_CODE (x) == MEM)
2979 frv_print_operand_address (file, XEXP (x, 0));
2981 else if (CONSTANT_ADDRESS_P (x))
2982 frv_print_operand_address (file, x);
2984 else
2985 fatal_insn ("Bad insn in frv_print_operand, 0 case", x);
2987 break;
2989 default:
2990 fatal_insn ("frv_print_operand: unknown code", x);
2991 break;
2994 return;
2998 /* A C statement (sans semicolon) for initializing the variable CUM for the
2999 state at the beginning of the argument list. The variable has type
3000 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
3001 of the function which will receive the args, or 0 if the args are to a
3002 compiler support library function. The value of INDIRECT is nonzero when
3003 processing an indirect call, for example a call through a function pointer.
3004 The value of INDIRECT is zero for a call to an explicitly named function, a
3005 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
3006 arguments for the function being compiled.
3008 When processing a call to a compiler support library function, LIBNAME
3009 identifies which one. It is a `symbol_ref' rtx which contains the name of
3010 the function, as a string. LIBNAME is 0 when an ordinary C function call is
3011 being processed. Thus, each time this macro is called, either LIBNAME or
3012 FNTYPE is nonzero, but never both of them at once. */
3014 void
3015 frv_init_cumulative_args (cum, fntype, libname, fndecl, incoming)
3016 CUMULATIVE_ARGS *cum;
3017 tree fntype;
3018 rtx libname;
3019 tree fndecl;
3020 int incoming;
3022 *cum = FIRST_ARG_REGNUM;
3024 if (TARGET_DEBUG_ARG)
3026 fprintf (stderr, "\ninit_cumulative_args:");
3027 if (!fndecl && fntype)
3028 fputs (" indirect", stderr);
3030 if (incoming)
3031 fputs (" incoming", stderr);
3033 if (fntype)
3035 tree ret_type = TREE_TYPE (fntype);
3036 fprintf (stderr, " return=%s,",
3037 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3040 if (libname && GET_CODE (libname) == SYMBOL_REF)
3041 fprintf (stderr, " libname=%s", XSTR (libname, 0));
3043 if (cfun->returns_struct)
3044 fprintf (stderr, " return-struct");
3046 putc ('\n', stderr);
3051 /* If defined, a C expression that gives the alignment boundary, in bits, of an
3052 argument with the specified mode and type. If it is not defined,
3053 `PARM_BOUNDARY' is used for all arguments. */
3056 frv_function_arg_boundary (mode, type)
3057 enum machine_mode mode ATTRIBUTE_UNUSED;
3058 tree type ATTRIBUTE_UNUSED;
3060 return BITS_PER_WORD;
3064 /* A C expression that controls whether a function argument is passed in a
3065 register, and which register.
3067 The arguments are CUM, of type CUMULATIVE_ARGS, which summarizes (in a way
3068 defined by INIT_CUMULATIVE_ARGS and FUNCTION_ARG_ADVANCE) all of the previous
3069 arguments so far passed in registers; MODE, the machine mode of the argument;
3070 TYPE, the data type of the argument as a tree node or 0 if that is not known
3071 (which happens for C support library functions); and NAMED, which is 1 for an
3072 ordinary argument and 0 for nameless arguments that correspond to `...' in the
3073 called function's prototype.
3075 The value of the expression should either be a `reg' RTX for the hard
3076 register in which to pass the argument, or zero to pass the argument on the
3077 stack.
3079 For machines like the VAX and 68000, where normally all arguments are
3080 pushed, zero suffices as a definition.
3082 The usual way to make the ANSI library `stdarg.h' work on a machine where
3083 some arguments are usually passed in registers, is to cause nameless
3084 arguments to be passed on the stack instead. This is done by making
3085 `FUNCTION_ARG' return 0 whenever NAMED is 0.
3087 You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the definition of
3088 this macro to determine if this argument is of a type that must be passed in
3089 the stack. If `REG_PARM_STACK_SPACE' is not defined and `FUNCTION_ARG'
3090 returns nonzero for such an argument, the compiler will abort. If
3091 `REG_PARM_STACK_SPACE' is defined, the argument will be computed in the
3092 stack and then loaded into a register. */
3095 frv_function_arg (cum, mode, type, named, incoming)
3096 CUMULATIVE_ARGS *cum;
3097 enum machine_mode mode;
3098 tree type ATTRIBUTE_UNUSED;
3099 int named;
3100 int incoming ATTRIBUTE_UNUSED;
3102 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3103 int arg_num = *cum;
3104 rtx ret;
3105 const char *debstr;
3107 /* Return a marker for use in the call instruction. */
3108 if (xmode == VOIDmode)
3110 ret = const0_rtx;
3111 debstr = "<0>";
3114 else if (arg_num <= LAST_ARG_REGNUM)
3116 ret = gen_rtx (REG, xmode, arg_num);
3117 debstr = reg_names[arg_num];
3120 else
3122 ret = NULL_RTX;
3123 debstr = "memory";
3126 if (TARGET_DEBUG_ARG)
3127 fprintf (stderr,
3128 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n",
3129 arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr);
3131 return ret;
3135 /* A C statement (sans semicolon) to update the summarizer variable CUM to
3136 advance past an argument in the argument list. The values MODE, TYPE and
3137 NAMED describe that argument. Once this is done, the variable CUM is
3138 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
3140 This macro need not do anything if the argument in question was passed on
3141 the stack. The compiler knows how to track the amount of stack space used
3142 for arguments without any special help. */
3144 void
3145 frv_function_arg_advance (cum, mode, type, named)
3146 CUMULATIVE_ARGS *cum;
3147 enum machine_mode mode;
3148 tree type ATTRIBUTE_UNUSED;
3149 int named;
3151 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3152 int bytes = GET_MODE_SIZE (xmode);
3153 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3154 int arg_num = *cum;
3156 *cum = arg_num + words;
3158 if (TARGET_DEBUG_ARG)
3159 fprintf (stderr,
3160 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n",
3161 arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD);
3165 /* A C expression for the number of words, at the beginning of an argument,
3166 must be put in registers. The value must be zero for arguments that are
3167 passed entirely in registers or that are entirely pushed on the stack.
3169 On some machines, certain arguments must be passed partially in registers
3170 and partially in memory. On these machines, typically the first N words of
3171 arguments are passed in registers, and the rest on the stack. If a
3172 multi-word argument (a `double' or a structure) crosses that boundary, its
3173 first few words must be passed in registers and the rest must be pushed.
3174 This macro tells the compiler when this occurs, and how many of the words
3175 should go in registers.
3177 `FUNCTION_ARG' for these arguments should return the first register to be
3178 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
3179 the called function. */
3182 frv_function_arg_partial_nregs (cum, mode, type, named)
3183 CUMULATIVE_ARGS *cum;
3184 enum machine_mode mode;
3185 tree type ATTRIBUTE_UNUSED;
3186 int named ATTRIBUTE_UNUSED;
3188 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3189 int bytes = GET_MODE_SIZE (xmode);
3190 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3191 int arg_num = *cum;
3192 int ret;
3194 ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1)
3195 ? LAST_ARG_REGNUM - arg_num + 1
3196 : 0);
3198 if (TARGET_DEBUG_ARG && ret)
3199 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3201 return ret;
3207 /* A C expression that indicates when an argument must be passed by reference.
3208 If nonzero for an argument, a copy of that argument is made in memory and a
3209 pointer to the argument is passed instead of the argument itself. The
3210 pointer is passed in whatever way is appropriate for passing a pointer to
3211 that type.
3213 On machines where `REG_PARM_STACK_SPACE' is not defined, a suitable
3214 definition of this macro might be
3215 #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) \
3216 MUST_PASS_IN_STACK (MODE, TYPE) */
3219 frv_function_arg_pass_by_reference (cum, mode, type, named)
3220 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3221 enum machine_mode mode;
3222 tree type;
3223 int named ATTRIBUTE_UNUSED;
3225 return MUST_PASS_IN_STACK (mode, type);
3228 /* If defined, a C expression that indicates when it is the called function's
3229 responsibility to make a copy of arguments passed by invisible reference.
3230 Normally, the caller makes a copy and passes the address of the copy to the
3231 routine being called. When FUNCTION_ARG_CALLEE_COPIES is defined and is
3232 nonzero, the caller does not make a copy. Instead, it passes a pointer to
3233 the "live" value. The called function must not modify this value. If it
3234 can be determined that the value won't be modified, it need not make a copy;
3235 otherwise a copy must be made. */
3238 frv_function_arg_callee_copies (cum, mode, type, named)
3239 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3240 enum machine_mode mode ATTRIBUTE_UNUSED;
3241 tree type ATTRIBUTE_UNUSED;
3242 int named ATTRIBUTE_UNUSED;
3244 return 0;
3247 /* If defined, a C expression that indicates when it is more desirable to keep
3248 an argument passed by invisible reference as a reference, rather than
3249 copying it to a pseudo register. */
3252 frv_function_arg_keep_as_reference (cum, mode, type, named)
3253 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3254 enum machine_mode mode ATTRIBUTE_UNUSED;
3255 tree type ATTRIBUTE_UNUSED;
3256 int named ATTRIBUTE_UNUSED;
3258 return 0;
3262 /* Return true if a register is ok to use as a base or index register. */
3264 static FRV_INLINE int
3265 frv_regno_ok_for_base_p (regno, strict_p)
3266 int regno;
3267 int strict_p;
3269 if (GPR_P (regno))
3270 return TRUE;
3272 if (strict_p)
3273 return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno]));
3275 if (regno == ARG_POINTER_REGNUM)
3276 return TRUE;
3278 return (regno >= FIRST_PSEUDO_REGISTER);
3282 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3283 RTX) is a legitimate memory address on the target machine for a memory
3284 operand of mode MODE.
3286 It usually pays to define several simpler macros to serve as subroutines for
3287 this one. Otherwise it may be too complicated to understand.
3289 This macro must exist in two variants: a strict variant and a non-strict
3290 one. The strict variant is used in the reload pass. It must be defined so
3291 that any pseudo-register that has not been allocated a hard register is
3292 considered a memory reference. In contexts where some kind of register is
3293 required, a pseudo-register with no hard register must be rejected.
3295 The non-strict variant is used in other passes. It must be defined to
3296 accept all pseudo-registers in every context where some kind of register is
3297 required.
3299 Compiler source files that want to use the strict variant of this macro
3300 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3301 conditional to define the strict variant in that case and the non-strict
3302 variant otherwise.
3304 Subroutines to check for acceptable registers for various purposes (one for
3305 base registers, one for index registers, and so on) are typically among the
3306 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3307 subroutine macros need have two variants; the higher levels of macros may be
3308 the same whether strict or not.
3310 Normally, constant addresses which are the sum of a `symbol_ref' and an
3311 integer are stored inside a `const' RTX to mark them as constant.
3312 Therefore, there is no need to recognize such sums specifically as
3313 legitimate addresses. Normally you would simply recognize any `const' as
3314 legitimate.
3316 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3317 are not marked with `const'. It assumes that a naked `plus' indicates
3318 indexing. If so, then you *must* reject such naked constant sums as
3319 illegitimate addresses, so that none of them will be given to
3320 `PRINT_OPERAND_ADDRESS'.
3322 On some machines, whether a symbolic address is legitimate depends on the
3323 section that the address refers to. On these machines, define the macro
3324 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3325 then check for it here. When you see a `const', you will have to look
3326 inside it to find the `symbol_ref' in order to determine the section.
3328 The best way to modify the name string is by adding text to the beginning,
3329 with suitable punctuation to prevent any ambiguity. Allocate the new name
3330 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3331 remove and decode the added text and output the name accordingly, and define
3332 `(* targetm.strip_name_encoding)' to access the original name string.
3334 You can check the information stored here into the `symbol_ref' in the
3335 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3336 `PRINT_OPERAND_ADDRESS'. */
3339 frv_legitimate_address_p (mode, x, strict_p, condexec_p)
3340 enum machine_mode mode;
3341 rtx x;
3342 int strict_p;
3343 int condexec_p;
3345 rtx x0, x1;
3346 int ret = 0;
3347 HOST_WIDE_INT value;
3348 unsigned regno0;
3350 switch (GET_CODE (x))
3352 default:
3353 break;
3355 case SUBREG:
3356 x = SUBREG_REG (x);
3357 if (GET_CODE (x) != REG)
3358 break;
3360 /* fall through */
3362 case REG:
3363 ret = frv_regno_ok_for_base_p (REGNO (x), strict_p);
3364 break;
3366 case PRE_MODIFY:
3367 x0 = XEXP (x, 0);
3368 x1 = XEXP (x, 1);
3369 if (GET_CODE (x0) != REG
3370 || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p)
3371 || GET_CODE (x1) != PLUS
3372 || ! rtx_equal_p (x0, XEXP (x1, 0))
3373 || GET_CODE (XEXP (x1, 1)) != REG
3374 || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p))
3375 break;
3377 ret = 1;
3378 break;
3380 case CONST_INT:
3381 /* 12 bit immediate */
3382 if (condexec_p)
3383 ret = FALSE;
3384 else
3386 ret = IN_RANGE_P (INTVAL (x), -2048, 2047);
3388 /* If we can't use load/store double operations, make sure we can
3389 address the second word. */
3390 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3391 ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1,
3392 -2048, 2047);
3394 break;
3396 case PLUS:
3397 x0 = XEXP (x, 0);
3398 x1 = XEXP (x, 1);
3400 if (GET_CODE (x0) == SUBREG)
3401 x0 = SUBREG_REG (x0);
3403 if (GET_CODE (x0) != REG)
3404 break;
3406 regno0 = REGNO (x0);
3407 if (!frv_regno_ok_for_base_p (regno0, strict_p))
3408 break;
3410 switch (GET_CODE (x1))
3412 default:
3413 break;
3415 case SUBREG:
3416 x1 = SUBREG_REG (x1);
3417 if (GET_CODE (x1) != REG)
3418 break;
3420 /* fall through */
3422 case REG:
3423 /* Do not allow reg+reg addressing for modes > 1 word if we can't depend
3424 on having move double instructions */
3425 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3426 ret = FALSE;
3427 else
3428 ret = frv_regno_ok_for_base_p (REGNO (x1), strict_p);
3429 break;
3431 case CONST_INT:
3432 /* 12 bit immediate */
3433 if (condexec_p)
3434 ret = FALSE;
3435 else
3437 value = INTVAL (x1);
3438 ret = IN_RANGE_P (value, -2048, 2047);
3440 /* If we can't use load/store double operations, make sure we can
3441 address the second word. */
3442 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3443 ret = IN_RANGE_P (value + GET_MODE_SIZE (mode) - 1, -2048, 2047);
3445 break;
3447 case SYMBOL_REF:
3448 if (!condexec_p
3449 && regno0 == SDA_BASE_REG
3450 && SYMBOL_REF_SMALL_P (x1))
3451 ret = TRUE;
3452 break;
3454 case CONST:
3455 if (!condexec_p && regno0 == SDA_BASE_REG && const_small_data_p (x1))
3456 ret = TRUE;
3457 break;
3460 break;
3463 if (TARGET_DEBUG_ADDR)
3465 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict%s\n",
3466 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ",
3467 (condexec_p) ? ", inside conditional code" : "");
3468 debug_rtx (x);
3471 return ret;
3475 /* A C compound statement that attempts to replace X with a valid memory
3476 address for an operand of mode MODE. WIN will be a C statement label
3477 elsewhere in the code; the macro definition may use
3479 GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
3481 to avoid further processing if the address has become legitimate.
3483 X will always be the result of a call to `break_out_memory_refs', and OLDX
3484 will be the operand that was given to that function to produce X.
3486 The code generated by this macro should not alter the substructure of X. If
3487 it transforms X into a more legitimate form, it should assign X (which will
3488 always be a C variable) a new value.
3490 It is not necessary for this macro to come up with a legitimate address.
3491 The compiler has standard ways of doing so in all cases. In fact, it is
3492 safe for this macro to do nothing. But often a machine-dependent strategy
3493 can generate better code. */
3496 frv_legitimize_address (x, oldx, mode)
3497 rtx x;
3498 rtx oldx ATTRIBUTE_UNUSED;
3499 enum machine_mode mode ATTRIBUTE_UNUSED;
3501 rtx ret = NULL_RTX;
3503 /* Don't try to legitimize addresses if we are not optimizing, since the
3504 address we generate is not a general operand, and will horribly mess
3505 things up when force_reg is called to try and put it in a register because
3506 we aren't optimizing. */
3507 if (optimize
3508 && ((GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_SMALL_P (x))
3509 || (GET_CODE (x) == CONST && const_small_data_p (x))))
3511 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, SDA_BASE_REG), x);
3512 if (flag_pic)
3513 cfun->uses_pic_offset_table = TRUE;
3516 if (TARGET_DEBUG_ADDR && ret != NULL_RTX)
3518 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, mode = %s, modified address\n",
3519 GET_MODE_NAME (mode));
3520 debug_rtx (ret);
3523 return ret;
3526 /* Return 1 if operand is a valid FRV address. CONDEXEC_P is true if
3527 the operand is used by a predicated instruction. */
3529 static int
3530 frv_legitimate_memory_operand (op, mode, condexec_p)
3531 rtx op;
3532 enum machine_mode mode;
3533 int condexec_p;
3535 return ((GET_MODE (op) == mode || mode == VOIDmode)
3536 && GET_CODE (op) == MEM
3537 && frv_legitimate_address_p (mode, XEXP (op, 0),
3538 reload_completed, condexec_p));
3542 /* Return 1 is OP is a memory operand, or will be turned into one by
3543 reload. */
3545 int frv_load_operand (op, mode)
3546 rtx op;
3547 enum machine_mode mode;
3549 if (GET_MODE (op) != mode && mode != VOIDmode)
3550 return FALSE;
3552 if (reload_in_progress)
3554 rtx tmp = op;
3555 if (GET_CODE (tmp) == SUBREG)
3556 tmp = SUBREG_REG (tmp);
3557 if (GET_CODE (tmp) == REG
3558 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
3559 op = reg_equiv_memory_loc[REGNO (tmp)];
3562 return op && memory_operand (op, mode);
3566 /* Return 1 if operand is a GPR register or a FPR register. */
3568 int gpr_or_fpr_operand (op, mode)
3569 rtx op;
3570 enum machine_mode mode;
3572 int regno;
3574 if (GET_MODE (op) != mode && mode != VOIDmode)
3575 return FALSE;
3577 if (GET_CODE (op) == SUBREG)
3579 if (GET_CODE (SUBREG_REG (op)) != REG)
3580 return register_operand (op, mode);
3582 op = SUBREG_REG (op);
3585 if (GET_CODE (op) != REG)
3586 return FALSE;
3588 regno = REGNO (op);
3589 if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER)
3590 return TRUE;
3592 return FALSE;
3595 /* Return 1 if operand is a GPR register or 12 bit signed immediate. */
3597 int gpr_or_int12_operand (op, mode)
3598 rtx op;
3599 enum machine_mode mode;
3601 if (GET_CODE (op) == CONST_INT)
3602 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3604 if (GET_MODE (op) != mode && mode != VOIDmode)
3605 return FALSE;
3607 if (GET_CODE (op) == SUBREG)
3609 if (GET_CODE (SUBREG_REG (op)) != REG)
3610 return register_operand (op, mode);
3612 op = SUBREG_REG (op);
3615 if (GET_CODE (op) != REG)
3616 return FALSE;
3618 return GPR_OR_PSEUDO_P (REGNO (op));
3621 /* Return 1 if operand is a GPR register, or a FPR register, or a 12 bit
3622 signed immediate. */
3624 int gpr_fpr_or_int12_operand (op, mode)
3625 rtx op;
3626 enum machine_mode mode;
3628 int regno;
3630 if (GET_CODE (op) == CONST_INT)
3631 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3633 if (GET_MODE (op) != mode && mode != VOIDmode)
3634 return FALSE;
3636 if (GET_CODE (op) == SUBREG)
3638 if (GET_CODE (SUBREG_REG (op)) != REG)
3639 return register_operand (op, mode);
3641 op = SUBREG_REG (op);
3644 if (GET_CODE (op) != REG)
3645 return FALSE;
3647 regno = REGNO (op);
3648 if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER)
3649 return TRUE;
3651 return FALSE;
3654 /* Return 1 if operand is a register or 6 bit signed immediate. */
3656 int fpr_or_int6_operand (op, mode)
3657 rtx op;
3658 enum machine_mode mode;
3660 if (GET_CODE (op) == CONST_INT)
3661 return IN_RANGE_P (INTVAL (op), -32, 31);
3663 if (GET_MODE (op) != mode && mode != VOIDmode)
3664 return FALSE;
3666 if (GET_CODE (op) == SUBREG)
3668 if (GET_CODE (SUBREG_REG (op)) != REG)
3669 return register_operand (op, mode);
3671 op = SUBREG_REG (op);
3674 if (GET_CODE (op) != REG)
3675 return FALSE;
3677 return FPR_OR_PSEUDO_P (REGNO (op));
3680 /* Return 1 if operand is a register or 10 bit signed immediate. */
3682 int gpr_or_int10_operand (op, mode)
3683 rtx op;
3684 enum machine_mode mode;
3686 if (GET_CODE (op) == CONST_INT)
3687 return IN_RANGE_P (INTVAL (op), -512, 511);
3689 if (GET_MODE (op) != mode && mode != VOIDmode)
3690 return FALSE;
3692 if (GET_CODE (op) == SUBREG)
3694 if (GET_CODE (SUBREG_REG (op)) != REG)
3695 return register_operand (op, mode);
3697 op = SUBREG_REG (op);
3700 if (GET_CODE (op) != REG)
3701 return FALSE;
3703 return GPR_OR_PSEUDO_P (REGNO (op));
3706 /* Return 1 if operand is a register or an integer immediate. */
3708 int gpr_or_int_operand (op, mode)
3709 rtx op;
3710 enum machine_mode mode;
3712 if (GET_CODE (op) == CONST_INT)
3713 return TRUE;
3715 if (GET_MODE (op) != mode && mode != VOIDmode)
3716 return FALSE;
3718 if (GET_CODE (op) == SUBREG)
3720 if (GET_CODE (SUBREG_REG (op)) != REG)
3721 return register_operand (op, mode);
3723 op = SUBREG_REG (op);
3726 if (GET_CODE (op) != REG)
3727 return FALSE;
3729 return GPR_OR_PSEUDO_P (REGNO (op));
3732 /* Return 1 if operand is a 12 bit signed immediate. */
3734 int int12_operand (op, mode)
3735 rtx op;
3736 enum machine_mode mode ATTRIBUTE_UNUSED;
3738 if (GET_CODE (op) != CONST_INT)
3739 return FALSE;
3741 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3744 /* Return 1 if operand is a 6 bit signed immediate. */
3746 int int6_operand (op, mode)
3747 rtx op;
3748 enum machine_mode mode ATTRIBUTE_UNUSED;
3750 if (GET_CODE (op) != CONST_INT)
3751 return FALSE;
3753 return IN_RANGE_P (INTVAL (op), -32, 31);
3756 /* Return 1 if operand is a 5 bit signed immediate. */
3758 int int5_operand (op, mode)
3759 rtx op;
3760 enum machine_mode mode ATTRIBUTE_UNUSED;
3762 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), -16, 15);
3765 /* Return 1 if operand is a 5 bit unsigned immediate. */
3767 int uint5_operand (op, mode)
3768 rtx op;
3769 enum machine_mode mode ATTRIBUTE_UNUSED;
3771 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 31);
3774 /* Return 1 if operand is a 4 bit unsigned immediate. */
3776 int uint4_operand (op, mode)
3777 rtx op;
3778 enum machine_mode mode ATTRIBUTE_UNUSED;
3780 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 15);
3783 /* Return 1 if operand is a 1 bit unsigned immediate (0 or 1). */
3785 int uint1_operand (op, mode)
3786 rtx op;
3787 enum machine_mode mode ATTRIBUTE_UNUSED;
3789 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 1);
3792 /* Return 1 if operand is an integer constant that takes 2 instructions
3793 to load up and can be split into sethi/setlo instructions.. */
3795 int int_2word_operand (op, mode)
3796 rtx op;
3797 enum machine_mode mode ATTRIBUTE_UNUSED;
3799 HOST_WIDE_INT value;
3800 REAL_VALUE_TYPE rv;
3801 long l;
3803 switch (GET_CODE (op))
3805 default:
3806 break;
3808 case LABEL_REF:
3809 return (flag_pic == 0);
3811 case CONST:
3812 /* small data references are already 1 word */
3813 return (flag_pic == 0) && (! const_small_data_p (op));
3815 case SYMBOL_REF:
3816 /* small data references are already 1 word */
3817 return (flag_pic == 0) && (! SYMBOL_REF_SMALL_P (op));
3819 case CONST_INT:
3820 return ! IN_RANGE_P (INTVAL (op), -32768, 32767);
3822 case CONST_DOUBLE:
3823 if (GET_MODE (op) == SFmode)
3825 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
3826 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
3827 value = l;
3828 return ! IN_RANGE_P (value, -32768, 32767);
3830 else if (GET_MODE (op) == VOIDmode)
3832 value = CONST_DOUBLE_LOW (op);
3833 return ! IN_RANGE_P (value, -32768, 32767);
3835 break;
3838 return FALSE;
3841 /* Return 1 if operand is the pic address register. */
3843 pic_register_operand (op, mode)
3844 rtx op;
3845 enum machine_mode mode ATTRIBUTE_UNUSED;
3847 if (! flag_pic)
3848 return FALSE;
3850 if (GET_CODE (op) != REG)
3851 return FALSE;
3853 if (REGNO (op) != PIC_REGNO)
3854 return FALSE;
3856 return TRUE;
3859 /* Return 1 if operand is a symbolic reference when a PIC option is specified
3860 that takes 3 seperate instructions to form. */
3862 int pic_symbolic_operand (op, mode)
3863 rtx op;
3864 enum machine_mode mode ATTRIBUTE_UNUSED;
3866 if (! flag_pic)
3867 return FALSE;
3869 switch (GET_CODE (op))
3871 default:
3872 break;
3874 case LABEL_REF:
3875 return TRUE;
3877 case SYMBOL_REF:
3878 /* small data references are already 1 word */
3879 return ! SYMBOL_REF_SMALL_P (op);
3881 case CONST:
3882 /* small data references are already 1 word */
3883 return ! const_small_data_p (op);
3886 return FALSE;
3889 /* Return 1 if operand is the small data register. */
3891 small_data_register_operand (op, mode)
3892 rtx op;
3893 enum machine_mode mode ATTRIBUTE_UNUSED;
3895 if (GET_CODE (op) != REG)
3896 return FALSE;
3898 if (REGNO (op) != SDA_BASE_REG)
3899 return FALSE;
3901 return TRUE;
3904 /* Return 1 if operand is a symbolic reference to a small data area static or
3905 global object. */
3907 int small_data_symbolic_operand (op, mode)
3908 rtx op;
3909 enum machine_mode mode ATTRIBUTE_UNUSED;
3911 switch (GET_CODE (op))
3913 default:
3914 break;
3916 case CONST:
3917 return const_small_data_p (op);
3919 case SYMBOL_REF:
3920 return SYMBOL_REF_SMALL_P (op);
3923 return FALSE;
3926 /* Return 1 if operand is a 16 bit unsigned immediate */
3928 int uint16_operand (op, mode)
3929 rtx op;
3930 enum machine_mode mode ATTRIBUTE_UNUSED;
3932 if (GET_CODE (op) != CONST_INT)
3933 return FALSE;
3935 return IN_RANGE_P (INTVAL (op), 0, 0xffff);
3938 /* Return 1 if operand is an integer constant with the bottom 16 bits clear */
3940 int upper_int16_operand (op, mode)
3941 rtx op;
3942 enum machine_mode mode ATTRIBUTE_UNUSED;
3944 if (GET_CODE (op) != CONST_INT)
3945 return FALSE;
3947 return ((INTVAL (op) & 0xffff) == 0);
3950 /* Return true if operand is a GPR register. */
3953 integer_register_operand (op, mode)
3954 rtx op;
3955 enum machine_mode mode;
3957 if (GET_MODE (op) != mode && mode != VOIDmode)
3958 return FALSE;
3960 if (GET_CODE (op) == SUBREG)
3962 if (GET_CODE (SUBREG_REG (op)) != REG)
3963 return register_operand (op, mode);
3965 op = SUBREG_REG (op);
3968 if (GET_CODE (op) != REG)
3969 return FALSE;
3971 return GPR_OR_PSEUDO_P (REGNO (op));
3974 /* Return true if operand is a GPR register. Do not allow SUBREG's
3975 here, in order to prevent a combine bug. */
3978 gpr_no_subreg_operand (op, mode)
3979 rtx op;
3980 enum machine_mode mode;
3982 if (GET_MODE (op) != mode && mode != VOIDmode)
3983 return FALSE;
3985 if (GET_CODE (op) != REG)
3986 return FALSE;
3988 return GPR_OR_PSEUDO_P (REGNO (op));
3991 /* Return true if operand is a FPR register. */
3994 fpr_operand (op, mode)
3995 rtx op;
3996 enum machine_mode mode;
3998 if (GET_MODE (op) != mode && mode != VOIDmode)
3999 return FALSE;
4001 if (GET_CODE (op) == SUBREG)
4003 if (GET_CODE (SUBREG_REG (op)) != REG)
4004 return register_operand (op, mode);
4006 op = SUBREG_REG (op);
4009 if (GET_CODE (op) != REG)
4010 return FALSE;
4012 return FPR_OR_PSEUDO_P (REGNO (op));
4015 /* Return true if operand is an even GPR or FPR register. */
4018 even_reg_operand (op, mode)
4019 rtx op;
4020 enum machine_mode mode;
4022 int regno;
4024 if (GET_MODE (op) != mode && mode != VOIDmode)
4025 return FALSE;
4027 if (GET_CODE (op) == SUBREG)
4029 if (GET_CODE (SUBREG_REG (op)) != REG)
4030 return register_operand (op, mode);
4032 op = SUBREG_REG (op);
4035 if (GET_CODE (op) != REG)
4036 return FALSE;
4038 regno = REGNO (op);
4039 if (regno >= FIRST_PSEUDO_REGISTER)
4040 return TRUE;
4042 if (GPR_P (regno))
4043 return (((regno - GPR_FIRST) & 1) == 0);
4045 if (FPR_P (regno))
4046 return (((regno - FPR_FIRST) & 1) == 0);
4048 return FALSE;
4051 /* Return true if operand is an odd GPR register. */
4054 odd_reg_operand (op, mode)
4055 rtx op;
4056 enum machine_mode mode;
4058 int regno;
4060 if (GET_MODE (op) != mode && mode != VOIDmode)
4061 return FALSE;
4063 if (GET_CODE (op) == SUBREG)
4065 if (GET_CODE (SUBREG_REG (op)) != REG)
4066 return register_operand (op, mode);
4068 op = SUBREG_REG (op);
4071 if (GET_CODE (op) != REG)
4072 return FALSE;
4074 regno = REGNO (op);
4075 /* assume that reload will give us an even register */
4076 if (regno >= FIRST_PSEUDO_REGISTER)
4077 return FALSE;
4079 if (GPR_P (regno))
4080 return (((regno - GPR_FIRST) & 1) != 0);
4082 if (FPR_P (regno))
4083 return (((regno - FPR_FIRST) & 1) != 0);
4085 return FALSE;
4088 /* Return true if operand is an even GPR register. */
4091 even_gpr_operand (op, mode)
4092 rtx op;
4093 enum machine_mode mode;
4095 int regno;
4097 if (GET_MODE (op) != mode && mode != VOIDmode)
4098 return FALSE;
4100 if (GET_CODE (op) == SUBREG)
4102 if (GET_CODE (SUBREG_REG (op)) != REG)
4103 return register_operand (op, mode);
4105 op = SUBREG_REG (op);
4108 if (GET_CODE (op) != REG)
4109 return FALSE;
4111 regno = REGNO (op);
4112 if (regno >= FIRST_PSEUDO_REGISTER)
4113 return TRUE;
4115 if (! GPR_P (regno))
4116 return FALSE;
4118 return (((regno - GPR_FIRST) & 1) == 0);
4121 /* Return true if operand is an odd GPR register. */
4124 odd_gpr_operand (op, mode)
4125 rtx op;
4126 enum machine_mode mode;
4128 int regno;
4130 if (GET_MODE (op) != mode && mode != VOIDmode)
4131 return FALSE;
4133 if (GET_CODE (op) == SUBREG)
4135 if (GET_CODE (SUBREG_REG (op)) != REG)
4136 return register_operand (op, mode);
4138 op = SUBREG_REG (op);
4141 if (GET_CODE (op) != REG)
4142 return FALSE;
4144 regno = REGNO (op);
4145 /* assume that reload will give us an even register */
4146 if (regno >= FIRST_PSEUDO_REGISTER)
4147 return FALSE;
4149 if (! GPR_P (regno))
4150 return FALSE;
4152 return (((regno - GPR_FIRST) & 1) != 0);
4155 /* Return true if operand is a quad aligned FPR register. */
4158 quad_fpr_operand (op, mode)
4159 rtx op;
4160 enum machine_mode mode;
4162 int regno;
4164 if (GET_MODE (op) != mode && mode != VOIDmode)
4165 return FALSE;
4167 if (GET_CODE (op) == SUBREG)
4169 if (GET_CODE (SUBREG_REG (op)) != REG)
4170 return register_operand (op, mode);
4172 op = SUBREG_REG (op);
4175 if (GET_CODE (op) != REG)
4176 return FALSE;
4178 regno = REGNO (op);
4179 if (regno >= FIRST_PSEUDO_REGISTER)
4180 return TRUE;
4182 if (! FPR_P (regno))
4183 return FALSE;
4185 return (((regno - FPR_FIRST) & 3) == 0);
4188 /* Return true if operand is an even FPR register. */
4191 even_fpr_operand (op, mode)
4192 rtx op;
4193 enum machine_mode mode;
4195 int regno;
4197 if (GET_MODE (op) != mode && mode != VOIDmode)
4198 return FALSE;
4200 if (GET_CODE (op) == SUBREG)
4202 if (GET_CODE (SUBREG_REG (op)) != REG)
4203 return register_operand (op, mode);
4205 op = SUBREG_REG (op);
4208 if (GET_CODE (op) != REG)
4209 return FALSE;
4211 regno = REGNO (op);
4212 if (regno >= FIRST_PSEUDO_REGISTER)
4213 return TRUE;
4215 if (! FPR_P (regno))
4216 return FALSE;
4218 return (((regno - FPR_FIRST) & 1) == 0);
4221 /* Return true if operand is an odd FPR register. */
4224 odd_fpr_operand (op, mode)
4225 rtx op;
4226 enum machine_mode mode;
4228 int regno;
4230 if (GET_MODE (op) != mode && mode != VOIDmode)
4231 return FALSE;
4233 if (GET_CODE (op) == SUBREG)
4235 if (GET_CODE (SUBREG_REG (op)) != REG)
4236 return register_operand (op, mode);
4238 op = SUBREG_REG (op);
4241 if (GET_CODE (op) != REG)
4242 return FALSE;
4244 regno = REGNO (op);
4245 /* assume that reload will give us an even register */
4246 if (regno >= FIRST_PSEUDO_REGISTER)
4247 return FALSE;
4249 if (! FPR_P (regno))
4250 return FALSE;
4252 return (((regno - FPR_FIRST) & 1) != 0);
4255 /* Return true if operand is a 2 word memory address that can be loaded in one
4256 instruction to load or store. We assume the stack and frame pointers are
4257 suitably aligned, and variables in the small data area. FIXME -- at some we
4258 should recognize other globals and statics. We can't assume that any old
4259 pointer is aligned, given that arguments could be passed on an odd word on
4260 the stack and the address taken and passed through to another function. */
4263 dbl_memory_one_insn_operand (op, mode)
4264 rtx op;
4265 enum machine_mode mode;
4267 rtx addr;
4268 rtx addr_reg;
4270 if (! TARGET_DWORD)
4271 return FALSE;
4273 if (GET_CODE (op) != MEM)
4274 return FALSE;
4276 if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD)
4277 return FALSE;
4279 addr = XEXP (op, 0);
4280 if (GET_CODE (addr) == REG)
4281 addr_reg = addr;
4283 else if (GET_CODE (addr) == PLUS)
4285 rtx addr0 = XEXP (addr, 0);
4286 rtx addr1 = XEXP (addr, 1);
4288 if (GET_CODE (addr0) != REG)
4289 return FALSE;
4291 if (plus_small_data_p (addr0, addr1))
4292 return TRUE;
4294 if (GET_CODE (addr1) != CONST_INT)
4295 return FALSE;
4297 if ((INTVAL (addr1) & 7) != 0)
4298 return FALSE;
4300 addr_reg = addr0;
4303 else
4304 return FALSE;
4306 if (addr_reg == frame_pointer_rtx || addr_reg == stack_pointer_rtx)
4307 return TRUE;
4309 return FALSE;
4312 /* Return true if operand is a 2 word memory address that needs to
4313 use two instructions to load or store. */
4316 dbl_memory_two_insn_operand (op, mode)
4317 rtx op;
4318 enum machine_mode mode;
4320 if (GET_CODE (op) != MEM)
4321 return FALSE;
4323 if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD)
4324 return FALSE;
4326 if (! TARGET_DWORD)
4327 return TRUE;
4329 return ! dbl_memory_one_insn_operand (op, mode);
4332 /* Return true if operand is something that can be an output for a move
4333 operation. */
4336 move_destination_operand (op, mode)
4337 rtx op;
4338 enum machine_mode mode;
4340 rtx subreg;
4341 enum rtx_code code;
4343 switch (GET_CODE (op))
4345 default:
4346 break;
4348 case SUBREG:
4349 if (GET_MODE (op) != mode && mode != VOIDmode)
4350 return FALSE;
4352 subreg = SUBREG_REG (op);
4353 code = GET_CODE (subreg);
4354 if (code == MEM)
4355 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4356 reload_completed, FALSE);
4358 return (code == REG);
4360 case REG:
4361 if (GET_MODE (op) != mode && mode != VOIDmode)
4362 return FALSE;
4364 return TRUE;
4366 case MEM:
4367 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4368 return TRUE;
4370 return frv_legitimate_memory_operand (op, mode, FALSE);
4373 return FALSE;
4376 /* Return true if operand is something that can be an input for a move
4377 operation. */
4380 move_source_operand (op, mode)
4381 rtx op;
4382 enum machine_mode mode;
4384 rtx subreg;
4385 enum rtx_code code;
4387 switch (GET_CODE (op))
4389 default:
4390 break;
4392 case CONST_INT:
4393 case CONST_DOUBLE:
4394 case SYMBOL_REF:
4395 case LABEL_REF:
4396 case CONST:
4397 return immediate_operand (op, mode);
4399 case SUBREG:
4400 if (GET_MODE (op) != mode && mode != VOIDmode)
4401 return FALSE;
4403 subreg = SUBREG_REG (op);
4404 code = GET_CODE (subreg);
4405 if (code == MEM)
4406 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4407 reload_completed, FALSE);
4409 return (code == REG);
4411 case REG:
4412 if (GET_MODE (op) != mode && mode != VOIDmode)
4413 return FALSE;
4415 return TRUE;
4417 case MEM:
4418 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4419 return TRUE;
4421 return frv_legitimate_memory_operand (op, mode, FALSE);
4424 return FALSE;
4427 /* Return true if operand is something that can be an output for a conditional
4428 move operation. */
4431 condexec_dest_operand (op, mode)
4432 rtx op;
4433 enum machine_mode mode;
4435 rtx subreg;
4436 enum rtx_code code;
4438 switch (GET_CODE (op))
4440 default:
4441 break;
4443 case SUBREG:
4444 if (GET_MODE (op) != mode && mode != VOIDmode)
4445 return FALSE;
4447 subreg = SUBREG_REG (op);
4448 code = GET_CODE (subreg);
4449 if (code == MEM)
4450 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4451 reload_completed, TRUE);
4453 return (code == REG);
4455 case REG:
4456 if (GET_MODE (op) != mode && mode != VOIDmode)
4457 return FALSE;
4459 return TRUE;
4461 case MEM:
4462 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4463 return TRUE;
4465 return frv_legitimate_memory_operand (op, mode, TRUE);
4468 return FALSE;
4471 /* Return true if operand is something that can be an input for a conditional
4472 move operation. */
4475 condexec_source_operand (op, mode)
4476 rtx op;
4477 enum machine_mode mode;
4479 rtx subreg;
4480 enum rtx_code code;
4482 switch (GET_CODE (op))
4484 default:
4485 break;
4487 case CONST_INT:
4488 case CONST_DOUBLE:
4489 return ZERO_P (op);
4491 case SUBREG:
4492 if (GET_MODE (op) != mode && mode != VOIDmode)
4493 return FALSE;
4495 subreg = SUBREG_REG (op);
4496 code = GET_CODE (subreg);
4497 if (code == MEM)
4498 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4499 reload_completed, TRUE);
4501 return (code == REG);
4503 case REG:
4504 if (GET_MODE (op) != mode && mode != VOIDmode)
4505 return FALSE;
4507 return TRUE;
4509 case MEM:
4510 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4511 return TRUE;
4513 return frv_legitimate_memory_operand (op, mode, TRUE);
4516 return FALSE;
4519 /* Return true if operand is a register of any flavor or a 0 of the
4520 appropriate type. */
4523 reg_or_0_operand (op, mode)
4524 rtx op;
4525 enum machine_mode mode;
4527 switch (GET_CODE (op))
4529 default:
4530 break;
4532 case REG:
4533 case SUBREG:
4534 if (GET_MODE (op) != mode && mode != VOIDmode)
4535 return FALSE;
4537 return register_operand (op, mode);
4539 case CONST_INT:
4540 case CONST_DOUBLE:
4541 return ZERO_P (op);
4544 return FALSE;
4547 /* Return true if operand is the link register */
4550 lr_operand (op, mode)
4551 rtx op;
4552 enum machine_mode mode;
4554 if (GET_CODE (op) != REG)
4555 return FALSE;
4557 if (GET_MODE (op) != mode && mode != VOIDmode)
4558 return FALSE;
4560 if (REGNO (op) != LR_REGNO && REGNO (op) < FIRST_PSEUDO_REGISTER)
4561 return FALSE;
4563 return TRUE;
4566 /* Return true if operand is a gpr register or a valid memory operation. */
4569 gpr_or_memory_operand (op, mode)
4570 rtx op;
4571 enum machine_mode mode;
4573 return (integer_register_operand (op, mode)
4574 || frv_legitimate_memory_operand (op, mode, FALSE));
4577 /* Return true if operand is a fpr register or a valid memory operation. */
4580 fpr_or_memory_operand (op, mode)
4581 rtx op;
4582 enum machine_mode mode;
4584 return (fpr_operand (op, mode)
4585 || frv_legitimate_memory_operand (op, mode, FALSE));
4588 /* Return true if operand is an icc register */
4591 icc_operand (op, mode)
4592 rtx op;
4593 enum machine_mode mode;
4595 int regno;
4597 if (GET_MODE (op) != mode && mode != VOIDmode)
4598 return FALSE;
4600 if (GET_CODE (op) != REG)
4601 return FALSE;
4603 regno = REGNO (op);
4604 return ICC_OR_PSEUDO_P (regno);
4607 /* Return true if operand is an fcc register */
4610 fcc_operand (op, mode)
4611 rtx op;
4612 enum machine_mode mode;
4614 int regno;
4616 if (GET_MODE (op) != mode && mode != VOIDmode)
4617 return FALSE;
4619 if (GET_CODE (op) != REG)
4620 return FALSE;
4622 regno = REGNO (op);
4623 return FCC_OR_PSEUDO_P (regno);
4626 /* Return true if operand is either an fcc or icc register */
4629 cc_operand (op, mode)
4630 rtx op;
4631 enum machine_mode mode;
4633 int regno;
4635 if (GET_MODE (op) != mode && mode != VOIDmode)
4636 return FALSE;
4638 if (GET_CODE (op) != REG)
4639 return FALSE;
4641 regno = REGNO (op);
4642 if (CC_OR_PSEUDO_P (regno))
4643 return TRUE;
4645 return FALSE;
4648 /* Return true if operand is an integer CCR register */
4651 icr_operand (op, mode)
4652 rtx op;
4653 enum machine_mode mode;
4655 int regno;
4657 if (GET_MODE (op) != mode && mode != VOIDmode)
4658 return FALSE;
4660 if (GET_CODE (op) != REG)
4661 return FALSE;
4663 regno = REGNO (op);
4664 return ICR_OR_PSEUDO_P (regno);
4667 /* Return true if operand is an fcc register */
4670 fcr_operand (op, mode)
4671 rtx op;
4672 enum machine_mode mode;
4674 int regno;
4676 if (GET_MODE (op) != mode && mode != VOIDmode)
4677 return FALSE;
4679 if (GET_CODE (op) != REG)
4680 return FALSE;
4682 regno = REGNO (op);
4683 return FCR_OR_PSEUDO_P (regno);
4686 /* Return true if operand is either an fcc or icc register */
4689 cr_operand (op, mode)
4690 rtx op;
4691 enum machine_mode mode;
4693 int regno;
4695 if (GET_MODE (op) != mode && mode != VOIDmode)
4696 return FALSE;
4698 if (GET_CODE (op) != REG)
4699 return FALSE;
4701 regno = REGNO (op);
4702 if (CR_OR_PSEUDO_P (regno))
4703 return TRUE;
4705 return FALSE;
4708 /* Return true if operand is a memory reference suitable for a call. */
4711 call_operand (op, mode)
4712 rtx op;
4713 enum machine_mode mode;
4715 if (GET_MODE (op) != mode && mode != VOIDmode && GET_CODE (op) != CONST_INT)
4716 return FALSE;
4718 if (GET_CODE (op) == SYMBOL_REF)
4719 return TRUE;
4721 /* Note this doesn't allow reg+reg or reg+imm12 addressing (which should
4722 never occur anyway), but prevents reload from not handling the case
4723 properly of a call through a pointer on a function that calls
4724 vfork/setjmp, etc. due to the need to flush all of the registers to stack. */
4725 return gpr_or_int12_operand (op, mode);
4728 /* Return true if operator is a kind of relational operator. */
4731 relational_operator (op, mode)
4732 rtx op;
4733 enum machine_mode mode;
4735 rtx op0;
4736 rtx op1;
4737 int regno;
4739 if (mode != VOIDmode && mode != GET_MODE (op))
4740 return FALSE;
4742 switch (GET_CODE (op))
4744 default:
4745 return FALSE;
4747 case EQ:
4748 case NE:
4749 case LE:
4750 case LT:
4751 case GE:
4752 case GT:
4753 case LEU:
4754 case LTU:
4755 case GEU:
4756 case GTU:
4757 break;
4760 op1 = XEXP (op, 1);
4761 if (op1 != const0_rtx)
4762 return FALSE;
4764 op0 = XEXP (op, 0);
4765 if (GET_CODE (op0) != REG)
4766 return FALSE;
4768 regno = REGNO (op0);
4769 switch (GET_MODE (op0))
4771 default:
4772 break;
4774 case CCmode:
4775 case CC_UNSmode:
4776 return ICC_OR_PSEUDO_P (regno);
4778 case CC_FPmode:
4779 return FCC_OR_PSEUDO_P (regno);
4781 case CC_CCRmode:
4782 return CR_OR_PSEUDO_P (regno);
4785 return FALSE;
4788 /* Return true if operator is a signed integer relational operator */
4791 signed_relational_operator (op, mode)
4792 rtx op;
4793 enum machine_mode mode;
4795 rtx op0;
4796 rtx op1;
4797 int regno;
4799 if (mode != VOIDmode && mode != GET_MODE (op))
4800 return FALSE;
4802 switch (GET_CODE (op))
4804 default:
4805 return FALSE;
4807 case EQ:
4808 case NE:
4809 case LE:
4810 case LT:
4811 case GE:
4812 case GT:
4813 break;
4816 op1 = XEXP (op, 1);
4817 if (op1 != const0_rtx)
4818 return FALSE;
4820 op0 = XEXP (op, 0);
4821 if (GET_CODE (op0) != REG)
4822 return FALSE;
4824 regno = REGNO (op0);
4825 if (GET_MODE (op0) == CCmode && ICC_OR_PSEUDO_P (regno))
4826 return TRUE;
4828 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4829 return TRUE;
4831 return FALSE;
4834 /* Return true if operator is a signed integer relational operator */
4837 unsigned_relational_operator (op, mode)
4838 rtx op;
4839 enum machine_mode mode;
4841 rtx op0;
4842 rtx op1;
4843 int regno;
4845 if (mode != VOIDmode && mode != GET_MODE (op))
4846 return FALSE;
4848 switch (GET_CODE (op))
4850 default:
4851 return FALSE;
4853 case LEU:
4854 case LTU:
4855 case GEU:
4856 case GTU:
4857 break;
4860 op1 = XEXP (op, 1);
4861 if (op1 != const0_rtx)
4862 return FALSE;
4864 op0 = XEXP (op, 0);
4865 if (GET_CODE (op0) != REG)
4866 return FALSE;
4868 regno = REGNO (op0);
4869 if (GET_MODE (op0) == CC_UNSmode && ICC_OR_PSEUDO_P (regno))
4870 return TRUE;
4872 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4873 return TRUE;
4875 return FALSE;
4878 /* Return true if operator is a floating point relational operator */
4881 float_relational_operator (op, mode)
4882 rtx op;
4883 enum machine_mode mode;
4885 rtx op0;
4886 rtx op1;
4887 int regno;
4889 if (mode != VOIDmode && mode != GET_MODE (op))
4890 return FALSE;
4892 switch (GET_CODE (op))
4894 default:
4895 return FALSE;
4897 case EQ: case NE:
4898 case LE: case LT:
4899 case GE: case GT:
4900 #if 0
4901 case UEQ: case UNE:
4902 case ULE: case ULT:
4903 case UGE: case UGT:
4904 case ORDERED:
4905 case UNORDERED:
4906 #endif
4907 break;
4910 op1 = XEXP (op, 1);
4911 if (op1 != const0_rtx)
4912 return FALSE;
4914 op0 = XEXP (op, 0);
4915 if (GET_CODE (op0) != REG)
4916 return FALSE;
4918 regno = REGNO (op0);
4919 if (GET_MODE (op0) == CC_FPmode && FCC_OR_PSEUDO_P (regno))
4920 return TRUE;
4922 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4923 return TRUE;
4925 return FALSE;
4928 /* Return true if operator is EQ/NE of a conditional execution register. */
4931 ccr_eqne_operator (op, mode)
4932 rtx op;
4933 enum machine_mode mode;
4935 enum machine_mode op_mode = GET_MODE (op);
4936 rtx op0;
4937 rtx op1;
4938 int regno;
4940 if (mode != VOIDmode && op_mode != mode)
4941 return FALSE;
4943 switch (GET_CODE (op))
4945 default:
4946 return FALSE;
4948 case EQ:
4949 case NE:
4950 break;
4953 op1 = XEXP (op, 1);
4954 if (op1 != const0_rtx)
4955 return FALSE;
4957 op0 = XEXP (op, 0);
4958 if (GET_CODE (op0) != REG)
4959 return FALSE;
4961 regno = REGNO (op0);
4962 if (op_mode == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4963 return TRUE;
4965 return FALSE;
4968 /* Return true if operator is a minimum or maximum operator (both signed and
4969 unsigned). */
4972 minmax_operator (op, mode)
4973 rtx op;
4974 enum machine_mode mode;
4976 if (mode != VOIDmode && mode != GET_MODE (op))
4977 return FALSE;
4979 switch (GET_CODE (op))
4981 default:
4982 return FALSE;
4984 case SMIN:
4985 case SMAX:
4986 case UMIN:
4987 case UMAX:
4988 break;
4991 if (! integer_register_operand (XEXP (op, 0), mode))
4992 return FALSE;
4994 if (! gpr_or_int10_operand (XEXP (op, 1), mode))
4995 return FALSE;
4997 return TRUE;
5000 /* Return true if operator is an integer binary operator that can executed
5001 conditionally and takes 1 cycle. */
5004 condexec_si_binary_operator (op, mode)
5005 rtx op;
5006 enum machine_mode mode;
5008 enum machine_mode op_mode = GET_MODE (op);
5010 if (mode != VOIDmode && op_mode != mode)
5011 return FALSE;
5013 switch (GET_CODE (op))
5015 default:
5016 return FALSE;
5018 case PLUS:
5019 case MINUS:
5020 case AND:
5021 case IOR:
5022 case XOR:
5023 case ASHIFT:
5024 case ASHIFTRT:
5025 case LSHIFTRT:
5026 return TRUE;
5030 /* Return true if operator is an integer binary operator that can be
5031 executed conditionally by a media instruction. */
5034 condexec_si_media_operator (op, mode)
5035 rtx op;
5036 enum machine_mode mode;
5038 enum machine_mode op_mode = GET_MODE (op);
5040 if (mode != VOIDmode && op_mode != mode)
5041 return FALSE;
5043 switch (GET_CODE (op))
5045 default:
5046 return FALSE;
5048 case AND:
5049 case IOR:
5050 case XOR:
5051 return TRUE;
5055 /* Return true if operator is an integer division operator that can executed
5056 conditionally. */
5059 condexec_si_divide_operator (op, mode)
5060 rtx op;
5061 enum machine_mode mode;
5063 enum machine_mode op_mode = GET_MODE (op);
5065 if (mode != VOIDmode && op_mode != mode)
5066 return FALSE;
5068 switch (GET_CODE (op))
5070 default:
5071 return FALSE;
5073 case DIV:
5074 case UDIV:
5075 return TRUE;
5079 /* Return true if operator is an integer unary operator that can executed
5080 conditionally. */
5083 condexec_si_unary_operator (op, mode)
5084 rtx op;
5085 enum machine_mode mode;
5087 enum machine_mode op_mode = GET_MODE (op);
5089 if (mode != VOIDmode && op_mode != mode)
5090 return FALSE;
5092 switch (GET_CODE (op))
5094 default:
5095 return FALSE;
5097 case NEG:
5098 case NOT:
5099 return TRUE;
5103 /* Return true if operator is a conversion-type expression that can be
5104 evaluated conditionally by floating-point instructions. */
5107 condexec_sf_conv_operator (op, mode)
5108 rtx op;
5109 enum machine_mode mode;
5111 enum machine_mode op_mode = GET_MODE (op);
5113 if (mode != VOIDmode && op_mode != mode)
5114 return FALSE;
5116 switch (GET_CODE (op))
5118 default:
5119 return FALSE;
5121 case NEG:
5122 case ABS:
5123 return TRUE;
5127 /* Return true if operator is an addition or subtraction expression.
5128 Such expressions can be evaluated conditionally by floating-point
5129 instructions. */
5132 condexec_sf_add_operator (op, mode)
5133 rtx op;
5134 enum machine_mode mode;
5136 enum machine_mode op_mode = GET_MODE (op);
5138 if (mode != VOIDmode && op_mode != mode)
5139 return FALSE;
5141 switch (GET_CODE (op))
5143 default:
5144 return FALSE;
5146 case PLUS:
5147 case MINUS:
5148 return TRUE;
5152 /* Return true if the memory operand is one that can be conditionally
5153 executed. */
5156 condexec_memory_operand (op, mode)
5157 rtx op;
5158 enum machine_mode mode;
5160 enum machine_mode op_mode = GET_MODE (op);
5161 rtx addr;
5163 if (mode != VOIDmode && op_mode != mode)
5164 return FALSE;
5166 switch (op_mode)
5168 default:
5169 return FALSE;
5171 case QImode:
5172 case HImode:
5173 case SImode:
5174 case SFmode:
5175 break;
5178 if (GET_CODE (op) != MEM)
5179 return FALSE;
5181 addr = XEXP (op, 0);
5182 if (GET_CODE (addr) == ADDRESSOF)
5183 return TRUE;
5185 return frv_legitimate_address_p (mode, addr, reload_completed, TRUE);
5188 /* Return true if operator is an integer binary operator that can be combined
5189 with a setcc operation. Do not allow the arithmetic operations that could
5190 potentially overflow since the FR-V sets the condition code based on the
5191 "true" value of the result, not the result after truncating to a 32-bit
5192 register. */
5195 intop_compare_operator (op, mode)
5196 rtx op;
5197 enum machine_mode mode;
5199 enum machine_mode op_mode = GET_MODE (op);
5201 if (mode != VOIDmode && op_mode != mode)
5202 return FALSE;
5204 switch (GET_CODE (op))
5206 default:
5207 return FALSE;
5209 case AND:
5210 case IOR:
5211 case XOR:
5212 case ASHIFTRT:
5213 case LSHIFTRT:
5214 break;
5217 if (! integer_register_operand (XEXP (op, 0), SImode))
5218 return FALSE;
5220 if (! gpr_or_int10_operand (XEXP (op, 1), SImode))
5221 return FALSE;
5223 return TRUE;
5226 /* Return true if operator is an integer binary operator that can be combined
5227 with a setcc operation inside of a conditional execution. */
5230 condexec_intop_cmp_operator (op, mode)
5231 rtx op;
5232 enum machine_mode mode;
5234 enum machine_mode op_mode = GET_MODE (op);
5236 if (mode != VOIDmode && op_mode != mode)
5237 return FALSE;
5239 switch (GET_CODE (op))
5241 default:
5242 return FALSE;
5244 case AND:
5245 case IOR:
5246 case XOR:
5247 case ASHIFTRT:
5248 case LSHIFTRT:
5249 break;
5252 if (! integer_register_operand (XEXP (op, 0), SImode))
5253 return FALSE;
5255 if (! integer_register_operand (XEXP (op, 1), SImode))
5256 return FALSE;
5258 return TRUE;
5261 /* Return 1 if operand is a valid ACC register number */
5264 acc_operand (op, mode)
5265 rtx op;
5266 enum machine_mode mode;
5268 int regno;
5270 if (GET_MODE (op) != mode && mode != VOIDmode)
5271 return FALSE;
5273 if (GET_CODE (op) == SUBREG)
5275 if (GET_CODE (SUBREG_REG (op)) != REG)
5276 return register_operand (op, mode);
5278 op = SUBREG_REG (op);
5281 if (GET_CODE (op) != REG)
5282 return FALSE;
5284 regno = REGNO (op);
5285 return ACC_OR_PSEUDO_P (regno);
5288 /* Return 1 if operand is a valid even ACC register number */
5291 even_acc_operand (op, mode)
5292 rtx op;
5293 enum machine_mode mode;
5295 int regno;
5297 if (GET_MODE (op) != mode && mode != VOIDmode)
5298 return FALSE;
5300 if (GET_CODE (op) == SUBREG)
5302 if (GET_CODE (SUBREG_REG (op)) != REG)
5303 return register_operand (op, mode);
5305 op = SUBREG_REG (op);
5308 if (GET_CODE (op) != REG)
5309 return FALSE;
5311 regno = REGNO (op);
5312 return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 1) == 0);
5315 /* Return 1 if operand is zero or four */
5318 quad_acc_operand (op, mode)
5319 rtx op;
5320 enum machine_mode mode;
5322 int regno;
5324 if (GET_MODE (op) != mode && mode != VOIDmode)
5325 return FALSE;
5327 if (GET_CODE (op) == SUBREG)
5329 if (GET_CODE (SUBREG_REG (op)) != REG)
5330 return register_operand (op, mode);
5332 op = SUBREG_REG (op);
5335 if (GET_CODE (op) != REG)
5336 return FALSE;
5338 regno = REGNO (op);
5339 return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 3) == 0);
5342 /* Return 1 if operand is a valid ACCG register number */
5345 accg_operand (op, mode)
5346 rtx op;
5347 enum machine_mode mode;
5349 if (GET_MODE (op) != mode && mode != VOIDmode)
5350 return FALSE;
5352 if (GET_CODE (op) == SUBREG)
5354 if (GET_CODE (SUBREG_REG (op)) != REG)
5355 return register_operand (op, mode);
5357 op = SUBREG_REG (op);
5360 if (GET_CODE (op) != REG)
5361 return FALSE;
5363 return ACCG_OR_PSEUDO_P (REGNO (op));
5367 /* Return true if the bare return instruction can be used outside of the
5368 epilog code. For frv, we only do it if there was no stack allocation. */
5371 direct_return_p ()
5373 frv_stack_t *info;
5375 if (!reload_completed)
5376 return FALSE;
5378 info = frv_stack_info ();
5379 return (info->total_size == 0);
5383 /* Emit code to handle a MOVSI, adding in the small data register or pic
5384 register if needed to load up addresses. Return TRUE if the appropriate
5385 instructions are emitted. */
5388 frv_emit_movsi (dest, src)
5389 rtx dest;
5390 rtx src;
5392 int base_regno = -1;
5394 if (!reload_in_progress
5395 && !reload_completed
5396 && !register_operand (dest, SImode)
5397 && (!reg_or_0_operand (src, SImode)
5398 /* Virtual registers will almost always be replaced by an
5399 add instruction, so expose this to CSE by copying to
5400 an intermediate register */
5401 || (GET_CODE (src) == REG
5402 && IN_RANGE_P (REGNO (src),
5403 FIRST_VIRTUAL_REGISTER,
5404 LAST_VIRTUAL_REGISTER))))
5406 emit_insn (gen_rtx_SET (VOIDmode, dest, copy_to_mode_reg (SImode, src)));
5407 return TRUE;
5410 /* Explicitly add in the PIC or small data register if needed. */
5411 switch (GET_CODE (src))
5413 default:
5414 break;
5416 case LABEL_REF:
5417 if (flag_pic)
5418 base_regno = PIC_REGNO;
5420 break;
5422 case CONST:
5423 if (const_small_data_p (src))
5424 base_regno = SDA_BASE_REG;
5426 else if (flag_pic)
5427 base_regno = PIC_REGNO;
5429 break;
5431 case SYMBOL_REF:
5432 if (SYMBOL_REF_SMALL_P (src))
5433 base_regno = SDA_BASE_REG;
5435 else if (flag_pic)
5436 base_regno = PIC_REGNO;
5438 break;
5441 if (base_regno >= 0)
5443 emit_insn (gen_rtx_SET (VOIDmode, dest,
5444 gen_rtx_PLUS (Pmode,
5445 gen_rtx_REG (Pmode, base_regno),
5446 src)));
5448 if (base_regno == PIC_REGNO)
5449 cfun->uses_pic_offset_table = TRUE;
5451 return TRUE;
5454 return FALSE;
5458 /* Return a string to output a single word move. */
5460 const char *
5461 output_move_single (operands, insn)
5462 rtx operands[];
5463 rtx insn;
5465 rtx dest = operands[0];
5466 rtx src = operands[1];
5468 if (GET_CODE (dest) == REG)
5470 int dest_regno = REGNO (dest);
5471 enum machine_mode mode = GET_MODE (dest);
5473 if (GPR_P (dest_regno))
5475 if (GET_CODE (src) == REG)
5477 /* gpr <- some sort of register */
5478 int src_regno = REGNO (src);
5480 if (GPR_P (src_regno))
5481 return "mov %1, %0";
5483 else if (FPR_P (src_regno))
5484 return "movfg %1, %0";
5486 else if (SPR_P (src_regno))
5487 return "movsg %1, %0";
5490 else if (GET_CODE (src) == MEM)
5492 /* gpr <- memory */
5493 switch (mode)
5495 default:
5496 break;
5498 case QImode:
5499 return "ldsb%I1%U1 %M1,%0";
5501 case HImode:
5502 return "ldsh%I1%U1 %M1,%0";
5504 case SImode:
5505 case SFmode:
5506 return "ld%I1%U1 %M1, %0";
5510 else if (GET_CODE (src) == CONST_INT
5511 || GET_CODE (src) == CONST_DOUBLE)
5513 /* gpr <- integer/floating constant */
5514 HOST_WIDE_INT value;
5516 if (GET_CODE (src) == CONST_INT)
5517 value = INTVAL (src);
5519 else if (mode == SFmode)
5521 REAL_VALUE_TYPE rv;
5522 long l;
5524 REAL_VALUE_FROM_CONST_DOUBLE (rv, src);
5525 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5526 value = l;
5529 else
5530 value = CONST_DOUBLE_LOW (src);
5532 if (IN_RANGE_P (value, -32768, 32767))
5533 return "setlos %1, %0";
5535 return "#";
5538 else if (GET_CODE (src) == SYMBOL_REF
5539 || GET_CODE (src) == LABEL_REF
5540 || GET_CODE (src) == CONST)
5542 /* Silently fix up instances where the small data pointer is not
5543 used in the address. */
5544 if (small_data_symbolic_operand (src, GET_MODE (src)))
5545 return "addi %@, #gprel12(%1), %0";
5547 return "#";
5551 else if (FPR_P (dest_regno))
5553 if (GET_CODE (src) == REG)
5555 /* fpr <- some sort of register */
5556 int src_regno = REGNO (src);
5558 if (GPR_P (src_regno))
5559 return "movgf %1, %0";
5561 else if (FPR_P (src_regno))
5563 if (TARGET_HARD_FLOAT)
5564 return "fmovs %1, %0";
5565 else
5566 return "mor %1, %1, %0";
5570 else if (GET_CODE (src) == MEM)
5572 /* fpr <- memory */
5573 switch (mode)
5575 default:
5576 break;
5578 case QImode:
5579 return "ldbf%I1%U1 %M1,%0";
5581 case HImode:
5582 return "ldhf%I1%U1 %M1,%0";
5584 case SImode:
5585 case SFmode:
5586 return "ldf%I1%U1 %M1, %0";
5590 else if (ZERO_P (src))
5591 return "movgf %., %0";
5594 else if (SPR_P (dest_regno))
5596 if (GET_CODE (src) == REG)
5598 /* spr <- some sort of register */
5599 int src_regno = REGNO (src);
5601 if (GPR_P (src_regno))
5602 return "movgs %1, %0";
5607 else if (GET_CODE (dest) == MEM)
5609 if (GET_CODE (src) == REG)
5611 int src_regno = REGNO (src);
5612 enum machine_mode mode = GET_MODE (dest);
5614 if (GPR_P (src_regno))
5616 switch (mode)
5618 default:
5619 break;
5621 case QImode:
5622 return "stb%I0%U0 %1, %M0";
5624 case HImode:
5625 return "sth%I0%U0 %1, %M0";
5627 case SImode:
5628 case SFmode:
5629 return "st%I0%U0 %1, %M0";
5633 else if (FPR_P (src_regno))
5635 switch (mode)
5637 default:
5638 break;
5640 case QImode:
5641 return "stbf%I0%U0 %1, %M0";
5643 case HImode:
5644 return "sthf%I0%U0 %1, %M0";
5646 case SImode:
5647 case SFmode:
5648 return "stf%I0%U0 %1, %M0";
5653 else if (ZERO_P (src))
5655 switch (GET_MODE (dest))
5657 default:
5658 break;
5660 case QImode:
5661 return "stb%I0%U0 %., %M0";
5663 case HImode:
5664 return "sth%I0%U0 %., %M0";
5666 case SImode:
5667 case SFmode:
5668 return "st%I0%U0 %., %M0";
5673 fatal_insn ("Bad output_move_single operand", insn);
5674 return "";
5678 /* Return a string to output a double word move. */
5680 const char *
5681 output_move_double (operands, insn)
5682 rtx operands[];
5683 rtx insn;
5685 rtx dest = operands[0];
5686 rtx src = operands[1];
5687 enum machine_mode mode = GET_MODE (dest);
5689 if (GET_CODE (dest) == REG)
5691 int dest_regno = REGNO (dest);
5693 if (GPR_P (dest_regno))
5695 if (GET_CODE (src) == REG)
5697 /* gpr <- some sort of register */
5698 int src_regno = REGNO (src);
5700 if (GPR_P (src_regno))
5701 return "#";
5703 else if (FPR_P (src_regno))
5705 if (((dest_regno - GPR_FIRST) & 1) == 0
5706 && ((src_regno - FPR_FIRST) & 1) == 0)
5707 return "movfgd %1, %0";
5709 return "#";
5713 else if (GET_CODE (src) == MEM)
5715 /* gpr <- memory */
5716 if (dbl_memory_one_insn_operand (src, mode))
5717 return "ldd%I1%U1 %M1, %0";
5719 return "#";
5722 else if (GET_CODE (src) == CONST_INT
5723 || GET_CODE (src) == CONST_DOUBLE)
5724 return "#";
5727 else if (FPR_P (dest_regno))
5729 if (GET_CODE (src) == REG)
5731 /* fpr <- some sort of register */
5732 int src_regno = REGNO (src);
5734 if (GPR_P (src_regno))
5736 if (((dest_regno - FPR_FIRST) & 1) == 0
5737 && ((src_regno - GPR_FIRST) & 1) == 0)
5738 return "movgfd %1, %0";
5740 return "#";
5743 else if (FPR_P (src_regno))
5745 if (TARGET_DOUBLE
5746 && ((dest_regno - FPR_FIRST) & 1) == 0
5747 && ((src_regno - FPR_FIRST) & 1) == 0)
5748 return "fmovd %1, %0";
5750 return "#";
5754 else if (GET_CODE (src) == MEM)
5756 /* fpr <- memory */
5757 if (dbl_memory_one_insn_operand (src, mode))
5758 return "lddf%I1%U1 %M1, %0";
5760 return "#";
5763 else if (ZERO_P (src))
5764 return "#";
5768 else if (GET_CODE (dest) == MEM)
5770 if (GET_CODE (src) == REG)
5772 int src_regno = REGNO (src);
5774 if (GPR_P (src_regno))
5776 if (((src_regno - GPR_FIRST) & 1) == 0
5777 && dbl_memory_one_insn_operand (dest, mode))
5778 return "std%I0%U0 %1, %M0";
5780 return "#";
5783 if (FPR_P (src_regno))
5785 if (((src_regno - FPR_FIRST) & 1) == 0
5786 && dbl_memory_one_insn_operand (dest, mode))
5787 return "stdf%I0%U0 %1, %M0";
5789 return "#";
5793 else if (ZERO_P (src))
5795 if (dbl_memory_one_insn_operand (dest, mode))
5796 return "std%I0%U0 %., %M0";
5798 return "#";
5802 fatal_insn ("Bad output_move_double operand", insn);
5803 return "";
5807 /* Return a string to output a single word conditional move.
5808 Operand0 -- EQ/NE of ccr register and 0
5809 Operand1 -- CCR register
5810 Operand2 -- destination
5811 Operand3 -- source */
5813 const char *
5814 output_condmove_single (operands, insn)
5815 rtx operands[];
5816 rtx insn;
5818 rtx dest = operands[2];
5819 rtx src = operands[3];
5821 if (GET_CODE (dest) == REG)
5823 int dest_regno = REGNO (dest);
5824 enum machine_mode mode = GET_MODE (dest);
5826 if (GPR_P (dest_regno))
5828 if (GET_CODE (src) == REG)
5830 /* gpr <- some sort of register */
5831 int src_regno = REGNO (src);
5833 if (GPR_P (src_regno))
5834 return "cmov %z3, %2, %1, %e0";
5836 else if (FPR_P (src_regno))
5837 return "cmovfg %3, %2, %1, %e0";
5840 else if (GET_CODE (src) == MEM)
5842 /* gpr <- memory */
5843 switch (mode)
5845 default:
5846 break;
5848 case QImode:
5849 return "cldsb%I3%U3 %M3, %2, %1, %e0";
5851 case HImode:
5852 return "cldsh%I3%U3 %M3, %2, %1, %e0";
5854 case SImode:
5855 case SFmode:
5856 return "cld%I3%U3 %M3, %2, %1, %e0";
5860 else if (ZERO_P (src))
5861 return "cmov %., %2, %1, %e0";
5864 else if (FPR_P (dest_regno))
5866 if (GET_CODE (src) == REG)
5868 /* fpr <- some sort of register */
5869 int src_regno = REGNO (src);
5871 if (GPR_P (src_regno))
5872 return "cmovgf %3, %2, %1, %e0";
5874 else if (FPR_P (src_regno))
5876 if (TARGET_HARD_FLOAT)
5877 return "cfmovs %3,%2,%1,%e0";
5878 else
5879 return "cmor %3, %3, %2, %1, %e0";
5883 else if (GET_CODE (src) == MEM)
5885 /* fpr <- memory */
5886 if (mode == SImode || mode == SFmode)
5887 return "cldf%I3%U3 %M3, %2, %1, %e0";
5890 else if (ZERO_P (src))
5891 return "cmovgf %., %2, %1, %e0";
5895 else if (GET_CODE (dest) == MEM)
5897 if (GET_CODE (src) == REG)
5899 int src_regno = REGNO (src);
5900 enum machine_mode mode = GET_MODE (dest);
5902 if (GPR_P (src_regno))
5904 switch (mode)
5906 default:
5907 break;
5909 case QImode:
5910 return "cstb%I2%U2 %3, %M2, %1, %e0";
5912 case HImode:
5913 return "csth%I2%U2 %3, %M2, %1, %e0";
5915 case SImode:
5916 case SFmode:
5917 return "cst%I2%U2 %3, %M2, %1, %e0";
5921 else if (FPR_P (src_regno) && (mode == SImode || mode == SFmode))
5922 return "cstf%I2%U2 %3, %M2, %1, %e0";
5925 else if (ZERO_P (src))
5927 enum machine_mode mode = GET_MODE (dest);
5928 switch (mode)
5930 default:
5931 break;
5933 case QImode:
5934 return "cstb%I2%U2 %., %M2, %1, %e0";
5936 case HImode:
5937 return "csth%I2%U2 %., %M2, %1, %e0";
5939 case SImode:
5940 case SFmode:
5941 return "cst%I2%U2 %., %M2, %1, %e0";
5946 fatal_insn ("Bad output_condmove_single operand", insn);
5947 return "";
5951 /* Emit the appropriate code to do a comparison, returning the register the
5952 comparison was done it. */
5954 static rtx
5955 frv_emit_comparison (test, op0, op1)
5956 enum rtx_code test;
5957 rtx op0;
5958 rtx op1;
5960 enum machine_mode cc_mode;
5961 rtx cc_reg;
5963 /* Floating point doesn't have comparison against a constant */
5964 if (GET_MODE (op0) == CC_FPmode && GET_CODE (op1) != REG)
5965 op1 = force_reg (GET_MODE (op0), op1);
5967 /* Possibly disable using anything but a fixed register in order to work
5968 around cse moving comparisons past function calls. */
5969 cc_mode = SELECT_CC_MODE (test, op0, op1);
5970 cc_reg = ((TARGET_ALLOC_CC)
5971 ? gen_reg_rtx (cc_mode)
5972 : gen_rtx_REG (cc_mode,
5973 (cc_mode == CC_FPmode) ? FCC_FIRST : ICC_FIRST));
5975 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
5976 gen_rtx_COMPARE (cc_mode, op0, op1)));
5978 return cc_reg;
5982 /* Emit code for a conditional branch. The comparison operands were previously
5983 stored in frv_compare_op0 and frv_compare_op1.
5985 XXX: I originally wanted to add a clobber of a CCR register to use in
5986 conditional execution, but that confuses the rest of the compiler. */
5989 frv_emit_cond_branch (test, label)
5990 enum rtx_code test;
5991 rtx label;
5993 rtx test_rtx;
5994 rtx label_ref;
5995 rtx if_else;
5996 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
5997 enum machine_mode cc_mode = GET_MODE (cc_reg);
5999 /* Branches generate:
6000 (set (pc)
6001 (if_then_else (<test>, <cc_reg>, (const_int 0))
6002 (label_ref <branch_label>)
6003 (pc))) */
6004 label_ref = gen_rtx_LABEL_REF (VOIDmode, label);
6005 test_rtx = gen_rtx (test, cc_mode, cc_reg, const0_rtx);
6006 if_else = gen_rtx_IF_THEN_ELSE (cc_mode, test_rtx, label_ref, pc_rtx);
6007 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, if_else));
6008 return TRUE;
6012 /* Emit code to set a gpr to 1/0 based on a comparison. The comparison
6013 operands were previously stored in frv_compare_op0 and frv_compare_op1. */
6016 frv_emit_scc (test, target)
6017 enum rtx_code test;
6018 rtx target;
6020 rtx set;
6021 rtx test_rtx;
6022 rtx clobber;
6023 rtx cr_reg;
6024 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
6026 /* SCC instructions generate:
6027 (parallel [(set <target> (<test>, <cc_reg>, (const_int 0))
6028 (clobber (<ccr_reg>))]) */
6029 test_rtx = gen_rtx_fmt_ee (test, SImode, cc_reg, const0_rtx);
6030 set = gen_rtx_SET (VOIDmode, target, test_rtx);
6032 cr_reg = ((TARGET_ALLOC_CC)
6033 ? gen_reg_rtx (CC_CCRmode)
6034 : gen_rtx_REG (CC_CCRmode,
6035 ((GET_MODE (cc_reg) == CC_FPmode)
6036 ? FCR_FIRST
6037 : ICR_FIRST)));
6039 clobber = gen_rtx_CLOBBER (VOIDmode, cr_reg);
6040 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber)));
6041 return TRUE;
6045 /* Split a SCC instruction into component parts, returning a SEQUENCE to hold
6046 the seperate insns. */
6049 frv_split_scc (dest, test, cc_reg, cr_reg, value)
6050 rtx dest;
6051 rtx test;
6052 rtx cc_reg;
6053 rtx cr_reg;
6054 HOST_WIDE_INT value;
6056 rtx ret;
6058 start_sequence ();
6060 /* Set the appropriate CCR bit. */
6061 emit_insn (gen_rtx_SET (VOIDmode,
6062 cr_reg,
6063 gen_rtx_fmt_ee (GET_CODE (test),
6064 GET_MODE (cr_reg),
6065 cc_reg,
6066 const0_rtx)));
6068 /* Move the value into the destination. */
6069 emit_move_insn (dest, GEN_INT (value));
6071 /* Move 0 into the destination if the test failed */
6072 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6073 gen_rtx_EQ (GET_MODE (cr_reg),
6074 cr_reg,
6075 const0_rtx),
6076 gen_rtx_SET (VOIDmode, dest, const0_rtx)));
6078 /* Finish up, return sequence. */
6079 ret = get_insns ();
6080 end_sequence ();
6081 return ret;
6085 /* Emit the code for a conditional move, return TRUE if we could do the
6086 move. */
6089 frv_emit_cond_move (dest, test_rtx, src1, src2)
6090 rtx dest;
6091 rtx test_rtx;
6092 rtx src1;
6093 rtx src2;
6095 rtx set;
6096 rtx clobber_cc;
6097 rtx test2;
6098 rtx cr_reg;
6099 rtx if_rtx;
6100 enum rtx_code test = GET_CODE (test_rtx);
6101 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
6102 enum machine_mode cc_mode = GET_MODE (cc_reg);
6104 /* Conditional move instructions generate:
6105 (parallel [(set <target>
6106 (if_then_else (<test> <cc_reg> (const_int 0))
6107 <src1>
6108 <src2>))
6109 (clobber (<ccr_reg>))]) */
6111 /* Handle various cases of conditional move involving two constants. */
6112 if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT)
6114 HOST_WIDE_INT value1 = INTVAL (src1);
6115 HOST_WIDE_INT value2 = INTVAL (src2);
6117 /* having 0 as one of the constants can be done by loading the other
6118 constant, and optionally moving in gr0. */
6119 if (value1 == 0 || value2 == 0)
6122 /* If the first value is within an addi range and also the difference
6123 between the two fits in an addi's range, load up the difference, then
6124 conditionally move in 0, and then unconditionally add the first
6125 value. */
6126 else if (IN_RANGE_P (value1, -2048, 2047)
6127 && IN_RANGE_P (value2 - value1, -2048, 2047))
6130 /* If neither condition holds, just force the constant into a
6131 register. */
6132 else
6134 src1 = force_reg (GET_MODE (dest), src1);
6135 src2 = force_reg (GET_MODE (dest), src2);
6139 /* If one value is a register, insure the other value is either 0 or a
6140 register. */
6141 else
6143 if (GET_CODE (src1) == CONST_INT && INTVAL (src1) != 0)
6144 src1 = force_reg (GET_MODE (dest), src1);
6146 if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0)
6147 src2 = force_reg (GET_MODE (dest), src2);
6150 test2 = gen_rtx_fmt_ee (test, cc_mode, cc_reg, const0_rtx);
6151 if_rtx = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), test2, src1, src2);
6153 set = gen_rtx_SET (VOIDmode, dest, if_rtx);
6155 cr_reg = ((TARGET_ALLOC_CC)
6156 ? gen_reg_rtx (CC_CCRmode)
6157 : gen_rtx_REG (CC_CCRmode,
6158 (cc_mode == CC_FPmode) ? FCR_FIRST : ICR_FIRST));
6160 clobber_cc = gen_rtx_CLOBBER (VOIDmode, cr_reg);
6161 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber_cc)));
6162 return TRUE;
6166 /* Split a conditonal move into constituent parts, returning a SEQUENCE
6167 containing all of the insns. */
6170 frv_split_cond_move (operands)
6171 rtx operands[];
6173 rtx dest = operands[0];
6174 rtx test = operands[1];
6175 rtx cc_reg = operands[2];
6176 rtx src1 = operands[3];
6177 rtx src2 = operands[4];
6178 rtx cr_reg = operands[5];
6179 rtx ret;
6180 enum machine_mode cr_mode = GET_MODE (cr_reg);
6182 start_sequence ();
6184 /* Set the appropriate CCR bit. */
6185 emit_insn (gen_rtx_SET (VOIDmode,
6186 cr_reg,
6187 gen_rtx_fmt_ee (GET_CODE (test),
6188 GET_MODE (cr_reg),
6189 cc_reg,
6190 const0_rtx)));
6192 /* Handle various cases of conditional move involving two constants. */
6193 if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT)
6195 HOST_WIDE_INT value1 = INTVAL (src1);
6196 HOST_WIDE_INT value2 = INTVAL (src2);
6198 /* having 0 as one of the constants can be done by loading the other
6199 constant, and optionally moving in gr0. */
6200 if (value1 == 0)
6202 emit_move_insn (dest, src2);
6203 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6204 gen_rtx_NE (cr_mode, cr_reg,
6205 const0_rtx),
6206 gen_rtx_SET (VOIDmode, dest, src1)));
6209 else if (value2 == 0)
6211 emit_move_insn (dest, src1);
6212 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6213 gen_rtx_EQ (cr_mode, cr_reg,
6214 const0_rtx),
6215 gen_rtx_SET (VOIDmode, dest, src2)));
6218 /* If the first value is within an addi range and also the difference
6219 between the two fits in an addi's range, load up the difference, then
6220 conditionally move in 0, and then unconditionally add the first
6221 value. */
6222 else if (IN_RANGE_P (value1, -2048, 2047)
6223 && IN_RANGE_P (value2 - value1, -2048, 2047))
6225 rtx dest_si = ((GET_MODE (dest) == SImode)
6226 ? dest
6227 : gen_rtx_SUBREG (SImode, dest, 0));
6229 emit_move_insn (dest_si, GEN_INT (value2 - value1));
6230 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6231 gen_rtx_NE (cr_mode, cr_reg,
6232 const0_rtx),
6233 gen_rtx_SET (VOIDmode, dest_si,
6234 const0_rtx)));
6235 emit_insn (gen_addsi3 (dest_si, dest_si, src1));
6238 else
6239 abort ();
6241 else
6243 /* Emit the conditional move for the test being true if needed. */
6244 if (! rtx_equal_p (dest, src1))
6245 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6246 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6247 gen_rtx_SET (VOIDmode, dest, src1)));
6249 /* Emit the conditional move for the test being false if needed. */
6250 if (! rtx_equal_p (dest, src2))
6251 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6252 gen_rtx_EQ (cr_mode, cr_reg, const0_rtx),
6253 gen_rtx_SET (VOIDmode, dest, src2)));
6256 /* Finish up, return sequence. */
6257 ret = get_insns ();
6258 end_sequence ();
6259 return ret;
6263 /* Split (set DEST SOURCE), where DEST is a double register and SOURCE is a
6264 memory location that is not known to be dword-aligned. */
6265 void
6266 frv_split_double_load (dest, source)
6267 rtx dest;
6268 rtx source;
6270 int regno = REGNO (dest);
6271 rtx dest1 = gen_highpart (SImode, dest);
6272 rtx dest2 = gen_lowpart (SImode, dest);
6273 rtx address = XEXP (source, 0);
6275 /* If the address is pre-modified, load the lower-numbered register
6276 first, then load the other register using an integer offset from
6277 the modified base register. This order should always be safe,
6278 since the pre-modification cannot affect the same registers as the
6279 load does.
6281 The situation for other loads is more complicated. Loading one
6282 of the registers could affect the value of ADDRESS, so we must
6283 be careful which order we do them in. */
6284 if (GET_CODE (address) == PRE_MODIFY
6285 || ! refers_to_regno_p (regno, regno + 1, address, NULL))
6287 /* It is safe to load the lower-numbered register first. */
6288 emit_move_insn (dest1, change_address (source, SImode, NULL));
6289 emit_move_insn (dest2, frv_index_memory (source, SImode, 1));
6291 else
6293 /* ADDRESS is not pre-modified and the address depends on the
6294 lower-numbered register. Load the higher-numbered register
6295 first. */
6296 emit_move_insn (dest2, frv_index_memory (source, SImode, 1));
6297 emit_move_insn (dest1, change_address (source, SImode, NULL));
6301 /* Split (set DEST SOURCE), where DEST refers to a dword memory location
6302 and SOURCE is either a double register or the constant zero. */
6303 void
6304 frv_split_double_store (dest, source)
6305 rtx dest;
6306 rtx source;
6308 rtx dest1 = change_address (dest, SImode, NULL);
6309 rtx dest2 = frv_index_memory (dest, SImode, 1);
6310 if (ZERO_P (source))
6312 emit_move_insn (dest1, CONST0_RTX (SImode));
6313 emit_move_insn (dest2, CONST0_RTX (SImode));
6315 else
6317 emit_move_insn (dest1, gen_highpart (SImode, source));
6318 emit_move_insn (dest2, gen_lowpart (SImode, source));
6323 /* Split a min/max operation returning a SEQUENCE containing all of the
6324 insns. */
6327 frv_split_minmax (operands)
6328 rtx operands[];
6330 rtx dest = operands[0];
6331 rtx minmax = operands[1];
6332 rtx src1 = operands[2];
6333 rtx src2 = operands[3];
6334 rtx cc_reg = operands[4];
6335 rtx cr_reg = operands[5];
6336 rtx ret;
6337 enum rtx_code test_code;
6338 enum machine_mode cr_mode = GET_MODE (cr_reg);
6340 start_sequence ();
6342 /* Figure out which test to use */
6343 switch (GET_CODE (minmax))
6345 default:
6346 abort ();
6348 case SMIN: test_code = LT; break;
6349 case SMAX: test_code = GT; break;
6350 case UMIN: test_code = LTU; break;
6351 case UMAX: test_code = GTU; break;
6354 /* Issue the compare instruction. */
6355 emit_insn (gen_rtx_SET (VOIDmode,
6356 cc_reg,
6357 gen_rtx_COMPARE (GET_MODE (cc_reg),
6358 src1, src2)));
6360 /* Set the appropriate CCR bit. */
6361 emit_insn (gen_rtx_SET (VOIDmode,
6362 cr_reg,
6363 gen_rtx_fmt_ee (test_code,
6364 GET_MODE (cr_reg),
6365 cc_reg,
6366 const0_rtx)));
6368 /* If are taking the min/max of a nonzero constant, load that first, and
6369 then do a conditional move of the other value. */
6370 if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0)
6372 if (rtx_equal_p (dest, src1))
6373 abort ();
6375 emit_move_insn (dest, src2);
6376 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6377 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6378 gen_rtx_SET (VOIDmode, dest, src1)));
6381 /* Otherwise, do each half of the move. */
6382 else
6384 /* Emit the conditional move for the test being true if needed. */
6385 if (! rtx_equal_p (dest, src1))
6386 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6387 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6388 gen_rtx_SET (VOIDmode, dest, src1)));
6390 /* Emit the conditional move for the test being false if needed. */
6391 if (! rtx_equal_p (dest, src2))
6392 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6393 gen_rtx_EQ (cr_mode, cr_reg, const0_rtx),
6394 gen_rtx_SET (VOIDmode, dest, src2)));
6397 /* Finish up, return sequence. */
6398 ret = get_insns ();
6399 end_sequence ();
6400 return ret;
6404 /* Split an integer abs operation returning a SEQUENCE containing all of the
6405 insns. */
6408 frv_split_abs (operands)
6409 rtx operands[];
6411 rtx dest = operands[0];
6412 rtx src = operands[1];
6413 rtx cc_reg = operands[2];
6414 rtx cr_reg = operands[3];
6415 rtx ret;
6417 start_sequence ();
6419 /* Issue the compare < 0 instruction. */
6420 emit_insn (gen_rtx_SET (VOIDmode,
6421 cc_reg,
6422 gen_rtx_COMPARE (CCmode, src, const0_rtx)));
6424 /* Set the appropriate CCR bit. */
6425 emit_insn (gen_rtx_SET (VOIDmode,
6426 cr_reg,
6427 gen_rtx_fmt_ee (LT, CC_CCRmode, cc_reg, const0_rtx)));
6429 /* Emit the conditional negate if the value is negative */
6430 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6431 gen_rtx_NE (CC_CCRmode, cr_reg, const0_rtx),
6432 gen_negsi2 (dest, src)));
6434 /* Emit the conditional move for the test being false if needed. */
6435 if (! rtx_equal_p (dest, src))
6436 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6437 gen_rtx_EQ (CC_CCRmode, cr_reg, const0_rtx),
6438 gen_rtx_SET (VOIDmode, dest, src)));
6440 /* Finish up, return sequence. */
6441 ret = get_insns ();
6442 end_sequence ();
6443 return ret;
6447 /* An internal function called by for_each_rtx to clear in a hard_reg set each
6448 register used in an insn. */
6450 static int
6451 frv_clear_registers_used (ptr, data)
6452 rtx *ptr;
6453 void *data;
6455 if (GET_CODE (*ptr) == REG)
6457 int regno = REGNO (*ptr);
6458 HARD_REG_SET *p_regs = (HARD_REG_SET *)data;
6460 if (regno < FIRST_PSEUDO_REGISTER)
6462 int reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (*ptr));
6464 while (regno < reg_max)
6466 CLEAR_HARD_REG_BIT (*p_regs, regno);
6467 regno++;
6472 return 0;
6476 /* Initialize the extra fields provided by IFCVT_EXTRA_FIELDS. */
6478 /* On the FR-V, we don't have any extra fields per se, but it is useful hook to
6479 initialize the static storage. */
6480 void
6481 frv_ifcvt_init_extra_fields (ce_info)
6482 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
6484 frv_ifcvt.added_insns_list = NULL_RTX;
6485 frv_ifcvt.cur_scratch_regs = 0;
6486 frv_ifcvt.num_nested_cond_exec = 0;
6487 frv_ifcvt.cr_reg = NULL_RTX;
6488 frv_ifcvt.nested_cc_reg = NULL_RTX;
6489 frv_ifcvt.extra_int_cr = NULL_RTX;
6490 frv_ifcvt.extra_fp_cr = NULL_RTX;
6491 frv_ifcvt.last_nested_if_cr = NULL_RTX;
6495 /* Internal function to add a potenial insn to the list of insns to be inserted
6496 if the conditional execution conversion is successful. */
6498 static void
6499 frv_ifcvt_add_insn (pattern, insn, before_p)
6500 rtx pattern;
6501 rtx insn;
6502 int before_p;
6504 rtx link = alloc_EXPR_LIST (VOIDmode, pattern, insn);
6506 link->jump = before_p; /* mark to add this before or after insn */
6507 frv_ifcvt.added_insns_list = alloc_EXPR_LIST (VOIDmode, link,
6508 frv_ifcvt.added_insns_list);
6510 if (TARGET_DEBUG_COND_EXEC)
6512 fprintf (stderr,
6513 "\n:::::::::: frv_ifcvt_add_insn: add the following %s insn %d:\n",
6514 (before_p) ? "before" : "after",
6515 (int)INSN_UID (insn));
6517 debug_rtx (pattern);
6522 /* A C expression to modify the code described by the conditional if
6523 information CE_INFO, possibly updating the tests in TRUE_EXPR, and
6524 FALSE_EXPR for converting if-then and if-then-else code to conditional
6525 instructions. Set either TRUE_EXPR or FALSE_EXPR to a null pointer if the
6526 tests cannot be converted. */
6528 void
6529 frv_ifcvt_modify_tests (ce_info, p_true, p_false)
6530 ce_if_block_t *ce_info;
6531 rtx *p_true;
6532 rtx *p_false;
6534 basic_block test_bb = ce_info->test_bb; /* test basic block */
6535 basic_block then_bb = ce_info->then_bb; /* THEN */
6536 basic_block else_bb = ce_info->else_bb; /* ELSE or NULL */
6537 basic_block join_bb = ce_info->join_bb; /* join block or NULL */
6538 rtx true_expr = *p_true;
6539 rtx cr;
6540 rtx cc;
6541 rtx nested_cc;
6542 enum machine_mode mode = GET_MODE (true_expr);
6543 int j;
6544 basic_block *bb;
6545 int num_bb;
6546 frv_tmp_reg_t *tmp_reg = &frv_ifcvt.tmp_reg;
6547 rtx check_insn;
6548 rtx sub_cond_exec_reg;
6549 enum rtx_code code;
6550 enum rtx_code code_true;
6551 enum rtx_code code_false;
6552 enum reg_class cc_class;
6553 enum reg_class cr_class;
6554 int cc_first;
6555 int cc_last;
6557 /* Make sure we are only dealing with hard registers. Also honor the
6558 -mno-cond-exec switch, and -mno-nested-cond-exec switches if
6559 applicable. */
6560 if (!reload_completed || TARGET_NO_COND_EXEC
6561 || (TARGET_NO_NESTED_CE && ce_info->pass > 1))
6562 goto fail;
6564 /* Figure out which registers we can allocate for our own purposes. Only
6565 consider registers that are not preserved across function calls and are
6566 not fixed. However, allow the ICC/ICR temporary registers to be allocated
6567 if we did not need to use them in reloading other registers. */
6568 memset ((PTR) &tmp_reg->regs, 0, sizeof (tmp_reg->regs));
6569 COPY_HARD_REG_SET (tmp_reg->regs, call_used_reg_set);
6570 AND_COMPL_HARD_REG_SET (tmp_reg->regs, fixed_reg_set);
6571 SET_HARD_REG_BIT (tmp_reg->regs, ICC_TEMP);
6572 SET_HARD_REG_BIT (tmp_reg->regs, ICR_TEMP);
6574 /* If this is a nested IF, we need to discover whether the CC registers that
6575 are set/used inside of the block are used anywhere else. If not, we can
6576 change them to be the CC register that is paired with the CR register that
6577 controls the outermost IF block. */
6578 if (ce_info->pass > 1)
6580 CLEAR_HARD_REG_SET (frv_ifcvt.nested_cc_ok_rewrite);
6581 for (j = CC_FIRST; j <= CC_LAST; j++)
6582 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6584 if (REGNO_REG_SET_P (then_bb->global_live_at_start, j))
6585 continue;
6587 if (else_bb && REGNO_REG_SET_P (else_bb->global_live_at_start, j))
6588 continue;
6590 if (join_bb && REGNO_REG_SET_P (join_bb->global_live_at_start, j))
6591 continue;
6593 SET_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j);
6597 for (j = 0; j < frv_ifcvt.cur_scratch_regs; j++)
6598 frv_ifcvt.scratch_regs[j] = NULL_RTX;
6600 frv_ifcvt.added_insns_list = NULL_RTX;
6601 frv_ifcvt.cur_scratch_regs = 0;
6603 bb = (basic_block *) alloca ((2 + ce_info->num_multiple_test_blocks)
6604 * sizeof (basic_block));
6606 if (join_bb)
6608 int regno;
6610 /* Remove anything live at the beginning of the join block from being
6611 available for allocation. */
6612 EXECUTE_IF_SET_IN_REG_SET (join_bb->global_live_at_start, 0, regno,
6614 if (regno < FIRST_PSEUDO_REGISTER)
6615 CLEAR_HARD_REG_BIT (tmp_reg->regs, regno);
6619 /* Add in all of the blocks in multiple &&/|| blocks to be scanned. */
6620 num_bb = 0;
6621 if (ce_info->num_multiple_test_blocks)
6623 basic_block multiple_test_bb = ce_info->last_test_bb;
6625 while (multiple_test_bb != test_bb)
6627 bb[num_bb++] = multiple_test_bb;
6628 multiple_test_bb = multiple_test_bb->pred->src;
6632 /* Add in the THEN and ELSE blocks to be scanned. */
6633 bb[num_bb++] = then_bb;
6634 if (else_bb)
6635 bb[num_bb++] = else_bb;
6637 sub_cond_exec_reg = NULL_RTX;
6638 frv_ifcvt.num_nested_cond_exec = 0;
6640 /* Scan all of the blocks for registers that must not be allocated. */
6641 for (j = 0; j < num_bb; j++)
6643 rtx last_insn = bb[j]->end;
6644 rtx insn = bb[j]->head;
6645 int regno;
6647 if (rtl_dump_file)
6648 fprintf (rtl_dump_file, "Scanning %s block %d, start %d, end %d\n",
6649 (bb[j] == else_bb) ? "else" : ((bb[j] == then_bb) ? "then" : "test"),
6650 (int) bb[j]->index,
6651 (int) INSN_UID (bb[j]->head),
6652 (int) INSN_UID (bb[j]->end));
6654 /* Anything live at the beginning of the block is obviously unavailable
6655 for allocation. */
6656 EXECUTE_IF_SET_IN_REG_SET (bb[j]->global_live_at_start, 0, regno,
6658 if (regno < FIRST_PSEUDO_REGISTER)
6659 CLEAR_HARD_REG_BIT (tmp_reg->regs, regno);
6662 /* loop through the insns in the block. */
6663 for (;;)
6665 /* Mark any new registers that are created as being unavailable for
6666 allocation. Also see if the CC register used in nested IFs can be
6667 reallocated. */
6668 if (INSN_P (insn))
6670 rtx pattern;
6671 rtx set;
6672 int skip_nested_if = FALSE;
6674 for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
6675 (void *)&tmp_reg->regs);
6677 pattern = PATTERN (insn);
6678 if (GET_CODE (pattern) == COND_EXEC)
6680 rtx reg = XEXP (COND_EXEC_TEST (pattern), 0);
6682 if (reg != sub_cond_exec_reg)
6684 sub_cond_exec_reg = reg;
6685 frv_ifcvt.num_nested_cond_exec++;
6689 set = single_set_pattern (pattern);
6690 if (set)
6692 rtx dest = SET_DEST (set);
6693 rtx src = SET_SRC (set);
6695 if (GET_CODE (dest) == REG)
6697 int regno = REGNO (dest);
6698 enum rtx_code src_code = GET_CODE (src);
6700 if (CC_P (regno) && src_code == COMPARE)
6701 skip_nested_if = TRUE;
6703 else if (CR_P (regno)
6704 && (src_code == IF_THEN_ELSE
6705 || GET_RTX_CLASS (src_code) == '<'))
6706 skip_nested_if = TRUE;
6710 if (! skip_nested_if)
6711 for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
6712 (void *)&frv_ifcvt.nested_cc_ok_rewrite);
6715 if (insn == last_insn)
6716 break;
6718 insn = NEXT_INSN (insn);
6722 /* If this is a nested if, rewrite the CC registers that are available to
6723 include the ones that can be rewritten, to increase the chance of being
6724 able to allocate a paired CC/CR register combination. */
6725 if (ce_info->pass > 1)
6727 for (j = CC_FIRST; j <= CC_LAST; j++)
6728 if (TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j))
6729 SET_HARD_REG_BIT (tmp_reg->regs, j);
6730 else
6731 CLEAR_HARD_REG_BIT (tmp_reg->regs, j);
6734 if (rtl_dump_file)
6736 int num_gprs = 0;
6737 fprintf (rtl_dump_file, "Available GPRs: ");
6739 for (j = GPR_FIRST; j <= GPR_LAST; j++)
6740 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6742 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6743 if (++num_gprs > GPR_TEMP_NUM+2)
6744 break;
6747 fprintf (rtl_dump_file, "%s\nAvailable CRs: ",
6748 (num_gprs > GPR_TEMP_NUM+2) ? " ..." : "");
6750 for (j = CR_FIRST; j <= CR_LAST; j++)
6751 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6752 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6754 fputs ("\n", rtl_dump_file);
6756 if (ce_info->pass > 1)
6758 fprintf (rtl_dump_file, "Modifiable CCs: ");
6759 for (j = CC_FIRST; j <= CC_LAST; j++)
6760 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6761 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6763 fprintf (rtl_dump_file, "\n%d nested COND_EXEC statements\n",
6764 frv_ifcvt.num_nested_cond_exec);
6768 /* Allocate the appropriate temporary condition code register. Try to
6769 allocate the ICR/FCR register that corresponds to the ICC/FCC register so
6770 that conditional cmp's can be done. */
6771 if (mode == CCmode || mode == CC_UNSmode)
6773 cr_class = ICR_REGS;
6774 cc_class = ICC_REGS;
6775 cc_first = ICC_FIRST;
6776 cc_last = ICC_LAST;
6778 else if (mode == CC_FPmode)
6780 cr_class = FCR_REGS;
6781 cc_class = FCC_REGS;
6782 cc_first = FCC_FIRST;
6783 cc_last = FCC_LAST;
6785 else
6787 cc_first = cc_last = 0;
6788 cr_class = cc_class = NO_REGS;
6791 cc = XEXP (true_expr, 0);
6792 nested_cc = cr = NULL_RTX;
6793 if (cc_class != NO_REGS)
6795 /* For nested IFs and &&/||, see if we can find a CC and CR register pair
6796 so we can execute a csubcc/caddcc/cfcmps instruction. */
6797 int cc_regno;
6799 for (cc_regno = cc_first; cc_regno <= cc_last; cc_regno++)
6801 int cr_regno = cc_regno - CC_FIRST + CR_FIRST;
6803 if (TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cc_regno)
6804 && TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cr_regno))
6806 frv_ifcvt.tmp_reg.next_reg[ (int)cr_class ] = cr_regno;
6807 cr = frv_alloc_temp_reg (tmp_reg, cr_class, CC_CCRmode, TRUE,
6808 TRUE);
6810 frv_ifcvt.tmp_reg.next_reg[ (int)cc_class ] = cc_regno;
6811 nested_cc = frv_alloc_temp_reg (tmp_reg, cc_class, CCmode,
6812 TRUE, TRUE);
6813 break;
6818 if (! cr)
6820 if (rtl_dump_file)
6821 fprintf (rtl_dump_file, "Could not allocate a CR temporary register\n");
6823 goto fail;
6826 if (rtl_dump_file)
6827 fprintf (rtl_dump_file,
6828 "Will use %s for conditional execution, %s for nested comparisons\n",
6829 reg_names[ REGNO (cr)],
6830 (nested_cc) ? reg_names[ REGNO (nested_cc) ] : "<none>");
6832 /* Set the CCR bit. Note for integer tests, we reverse the condition so that
6833 in an IF-THEN-ELSE sequence, we are testing the TRUE case against the CCR
6834 bit being true. We don't do this for floating point, because of NaNs. */
6835 code = GET_CODE (true_expr);
6836 if (GET_MODE (cc) != CC_FPmode)
6838 code = reverse_condition (code);
6839 code_true = EQ;
6840 code_false = NE;
6842 else
6844 code_true = NE;
6845 code_false = EQ;
6848 check_insn = gen_rtx_SET (VOIDmode, cr,
6849 gen_rtx_fmt_ee (code, CC_CCRmode, cc, const0_rtx));
6851 /* Record the check insn to be inserted later. */
6852 frv_ifcvt_add_insn (check_insn, test_bb->end, TRUE);
6854 /* Update the tests. */
6855 frv_ifcvt.cr_reg = cr;
6856 frv_ifcvt.nested_cc_reg = nested_cc;
6857 *p_true = gen_rtx_fmt_ee (code_true, CC_CCRmode, cr, const0_rtx);
6858 *p_false = gen_rtx_fmt_ee (code_false, CC_CCRmode, cr, const0_rtx);
6859 return;
6861 /* Fail, don't do this conditional execution. */
6862 fail:
6863 *p_true = NULL_RTX;
6864 *p_false = NULL_RTX;
6865 if (rtl_dump_file)
6866 fprintf (rtl_dump_file, "Disabling this conditional execution.\n");
6868 return;
6872 /* A C expression to modify the code described by the conditional if
6873 information CE_INFO, for the basic block BB, possibly updating the tests in
6874 TRUE_EXPR, and FALSE_EXPR for converting the && and || parts of if-then or
6875 if-then-else code to conditional instructions. Set either TRUE_EXPR or
6876 FALSE_EXPR to a null pointer if the tests cannot be converted. */
6878 /* p_true and p_false are given expressions of the form:
6880 (and (eq:CC_CCR (reg:CC_CCR)
6881 (const_int 0))
6882 (eq:CC (reg:CC)
6883 (const_int 0))) */
6885 void
6886 frv_ifcvt_modify_multiple_tests (ce_info, bb, p_true, p_false)
6887 ce_if_block_t *ce_info;
6888 basic_block bb;
6889 rtx *p_true;
6890 rtx *p_false;
6892 rtx old_true = XEXP (*p_true, 0);
6893 rtx old_false = XEXP (*p_false, 0);
6894 rtx true_expr = XEXP (*p_true, 1);
6895 rtx false_expr = XEXP (*p_false, 1);
6896 rtx test_expr;
6897 rtx old_test;
6898 rtx cr = XEXP (old_true, 0);
6899 rtx check_insn;
6900 rtx new_cr = NULL_RTX;
6901 rtx *p_new_cr = (rtx *)0;
6902 rtx if_else;
6903 rtx compare;
6904 rtx cc;
6905 enum reg_class cr_class;
6906 enum machine_mode mode = GET_MODE (true_expr);
6907 rtx (*logical_func)(rtx, rtx, rtx);
6909 if (TARGET_DEBUG_COND_EXEC)
6911 fprintf (stderr,
6912 "\n:::::::::: frv_ifcvt_modify_multiple_tests, before modification for %s\ntrue insn:\n",
6913 ce_info->and_and_p ? "&&" : "||");
6915 debug_rtx (*p_true);
6917 fputs ("\nfalse insn:\n", stderr);
6918 debug_rtx (*p_false);
6921 if (TARGET_NO_MULTI_CE)
6922 goto fail;
6924 if (GET_CODE (cr) != REG)
6925 goto fail;
6927 if (mode == CCmode || mode == CC_UNSmode)
6929 cr_class = ICR_REGS;
6930 p_new_cr = &frv_ifcvt.extra_int_cr;
6932 else if (mode == CC_FPmode)
6934 cr_class = FCR_REGS;
6935 p_new_cr = &frv_ifcvt.extra_fp_cr;
6937 else
6938 goto fail;
6940 /* Allocate a temp CR, reusing a previously allocated temp CR if we have 3 or
6941 more &&/|| tests. */
6942 new_cr = *p_new_cr;
6943 if (! new_cr)
6945 new_cr = *p_new_cr = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, cr_class,
6946 CC_CCRmode, TRUE, TRUE);
6947 if (! new_cr)
6948 goto fail;
6951 if (ce_info->and_and_p)
6953 old_test = old_false;
6954 test_expr = true_expr;
6955 logical_func = (GET_CODE (old_true) == EQ) ? gen_andcr : gen_andncr;
6956 *p_true = gen_rtx_NE (CC_CCRmode, cr, const0_rtx);
6957 *p_false = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx);
6959 else
6961 old_test = old_false;
6962 test_expr = false_expr;
6963 logical_func = (GET_CODE (old_false) == EQ) ? gen_orcr : gen_orncr;
6964 *p_true = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx);
6965 *p_false = gen_rtx_NE (CC_CCRmode, cr, const0_rtx);
6968 /* First add the andcr/andncr/orcr/orncr, which will be added after the
6969 conditional check instruction, due to frv_ifcvt_add_insn being a LIFO
6970 stack. */
6971 frv_ifcvt_add_insn ((*logical_func) (cr, cr, new_cr), bb->end, TRUE);
6973 /* Now add the conditional check insn. */
6974 cc = XEXP (test_expr, 0);
6975 compare = gen_rtx_fmt_ee (GET_CODE (test_expr), CC_CCRmode, cc, const0_rtx);
6976 if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, old_test, compare, const0_rtx);
6978 check_insn = gen_rtx_SET (VOIDmode, new_cr, if_else);
6980 /* add the new check insn to the list of check insns that need to be
6981 inserted. */
6982 frv_ifcvt_add_insn (check_insn, bb->end, TRUE);
6984 if (TARGET_DEBUG_COND_EXEC)
6986 fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, after modification\ntrue insn:\n",
6987 stderr);
6989 debug_rtx (*p_true);
6991 fputs ("\nfalse insn:\n", stderr);
6992 debug_rtx (*p_false);
6995 return;
6997 fail:
6998 *p_true = *p_false = NULL_RTX;
7000 /* If we allocated a CR register, release it. */
7001 if (new_cr)
7003 CLEAR_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, REGNO (new_cr));
7004 *p_new_cr = NULL_RTX;
7007 if (TARGET_DEBUG_COND_EXEC)
7008 fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, failed.\n", stderr);
7010 return;
7014 /* Return a register which will be loaded with a value if an IF block is
7015 converted to conditional execution. This is used to rewrite instructions
7016 that use constants to ones that just use registers. */
7018 static rtx
7019 frv_ifcvt_load_value (value, insn)
7020 rtx value;
7021 rtx insn ATTRIBUTE_UNUSED;
7023 int num_alloc = frv_ifcvt.cur_scratch_regs;
7024 int i;
7025 rtx reg;
7027 /* We know gr0 == 0, so replace any errant uses. */
7028 if (value == const0_rtx)
7029 return gen_rtx_REG (SImode, GPR_FIRST);
7031 /* First search all registers currently loaded to see if we have an
7032 applicable constant. */
7033 if (CONSTANT_P (value)
7034 || (GET_CODE (value) == REG && REGNO (value) == LR_REGNO))
7036 for (i = 0; i < num_alloc; i++)
7038 if (rtx_equal_p (SET_SRC (frv_ifcvt.scratch_regs[i]), value))
7039 return SET_DEST (frv_ifcvt.scratch_regs[i]);
7043 /* Have we exhausted the number of registers available? */
7044 if (num_alloc >= GPR_TEMP_NUM)
7046 if (rtl_dump_file)
7047 fprintf (rtl_dump_file, "Too many temporary registers allocated\n");
7049 return NULL_RTX;
7052 /* Allocate the new register. */
7053 reg = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, GPR_REGS, SImode, TRUE, TRUE);
7054 if (! reg)
7056 if (rtl_dump_file)
7057 fputs ("Could not find a scratch register\n", rtl_dump_file);
7059 return NULL_RTX;
7062 frv_ifcvt.cur_scratch_regs++;
7063 frv_ifcvt.scratch_regs[num_alloc] = gen_rtx_SET (VOIDmode, reg, value);
7065 if (rtl_dump_file)
7067 if (GET_CODE (value) == CONST_INT)
7068 fprintf (rtl_dump_file, "Register %s will hold %ld\n",
7069 reg_names[ REGNO (reg)], (long)INTVAL (value));
7071 else if (GET_CODE (value) == REG && REGNO (value) == LR_REGNO)
7072 fprintf (rtl_dump_file, "Register %s will hold LR\n",
7073 reg_names[ REGNO (reg)]);
7075 else
7076 fprintf (rtl_dump_file, "Register %s will hold a saved value\n",
7077 reg_names[ REGNO (reg)]);
7080 return reg;
7084 /* Update a MEM used in conditional code that might contain an offset to put
7085 the offset into a scratch register, so that the conditional load/store
7086 operations can be used. This function returns the original pointer if the
7087 MEM is valid to use in conditional code, NULL if we can't load up the offset
7088 into a temporary register, or the new MEM if we were successful. */
7090 static rtx
7091 frv_ifcvt_rewrite_mem (mem, mode, insn)
7092 rtx mem;
7093 enum machine_mode mode;
7094 rtx insn;
7096 rtx addr = XEXP (mem, 0);
7098 if (!frv_legitimate_address_p (mode, addr, reload_completed, TRUE))
7100 if (GET_CODE (addr) == PLUS)
7102 rtx addr_op0 = XEXP (addr, 0);
7103 rtx addr_op1 = XEXP (addr, 1);
7105 if (plus_small_data_p (addr_op0, addr_op1))
7106 addr = frv_ifcvt_load_value (addr, insn);
7108 else if (GET_CODE (addr_op0) == REG && CONSTANT_P (addr_op1))
7110 rtx reg = frv_ifcvt_load_value (addr_op1, insn);
7111 if (!reg)
7112 return NULL_RTX;
7114 addr = gen_rtx_PLUS (Pmode, addr_op0, reg);
7117 else
7118 return NULL_RTX;
7121 else if (CONSTANT_P (addr))
7122 addr = frv_ifcvt_load_value (addr, insn);
7124 else
7125 return NULL_RTX;
7127 if (addr == NULL_RTX)
7128 return NULL_RTX;
7130 else if (XEXP (mem, 0) != addr)
7131 return change_address (mem, mode, addr);
7134 return mem;
7138 /* Given a PATTERN, return a SET expression if this PATTERN has only a single
7139 SET, possibly conditionally executed. It may also have CLOBBERs, USEs. */
7141 static rtx
7142 single_set_pattern (pattern)
7143 rtx pattern;
7145 rtx set;
7146 int i;
7148 if (GET_CODE (pattern) == COND_EXEC)
7149 pattern = COND_EXEC_CODE (pattern);
7151 if (GET_CODE (pattern) == SET)
7152 return pattern;
7154 else if (GET_CODE (pattern) == PARALLEL)
7156 for (i = 0, set = 0; i < XVECLEN (pattern, 0); i++)
7158 rtx sub = XVECEXP (pattern, 0, i);
7160 switch (GET_CODE (sub))
7162 case USE:
7163 case CLOBBER:
7164 break;
7166 case SET:
7167 if (set)
7168 return 0;
7169 else
7170 set = sub;
7171 break;
7173 default:
7174 return 0;
7177 return set;
7180 return 0;
7184 /* A C expression to modify the code described by the conditional if
7185 information CE_INFO with the new PATTERN in INSN. If PATTERN is a null
7186 pointer after the IFCVT_MODIFY_INSN macro executes, it is assumed that that
7187 insn cannot be converted to be executed conditionally. */
7190 frv_ifcvt_modify_insn (ce_info, pattern, insn)
7191 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
7192 rtx pattern;
7193 rtx insn;
7195 rtx orig_ce_pattern = pattern;
7196 rtx set;
7197 rtx op0;
7198 rtx op1;
7199 rtx test;
7201 if (GET_CODE (pattern) != COND_EXEC)
7202 abort ();
7204 test = COND_EXEC_TEST (pattern);
7205 if (GET_CODE (test) == AND)
7207 rtx cr = frv_ifcvt.cr_reg;
7208 rtx test_reg;
7210 op0 = XEXP (test, 0);
7211 if (! rtx_equal_p (cr, XEXP (op0, 0)))
7212 goto fail;
7214 op1 = XEXP (test, 1);
7215 test_reg = XEXP (op1, 0);
7216 if (GET_CODE (test_reg) != REG)
7217 goto fail;
7219 /* Is this the first nested if block in this sequence? If so, generate
7220 an andcr or andncr. */
7221 if (! frv_ifcvt.last_nested_if_cr)
7223 rtx and_op;
7225 frv_ifcvt.last_nested_if_cr = test_reg;
7226 if (GET_CODE (op0) == NE)
7227 and_op = gen_andcr (test_reg, cr, test_reg);
7228 else
7229 and_op = gen_andncr (test_reg, cr, test_reg);
7231 frv_ifcvt_add_insn (and_op, insn, TRUE);
7234 /* If this isn't the first statement in the nested if sequence, see if we
7235 are dealing with the same register. */
7236 else if (! rtx_equal_p (test_reg, frv_ifcvt.last_nested_if_cr))
7237 goto fail;
7239 COND_EXEC_TEST (pattern) = test = op1;
7242 /* If this isn't a nested if, reset state variables. */
7243 else
7245 frv_ifcvt.last_nested_if_cr = NULL_RTX;
7248 set = single_set_pattern (pattern);
7249 if (set)
7251 rtx dest = SET_DEST (set);
7252 rtx src = SET_SRC (set);
7253 enum machine_mode mode = GET_MODE (dest);
7255 /* Check for normal binary operators */
7256 if (mode == SImode
7257 && (GET_RTX_CLASS (GET_CODE (src)) == '2'
7258 || GET_RTX_CLASS (GET_CODE (src)) == 'c'))
7260 op0 = XEXP (src, 0);
7261 op1 = XEXP (src, 1);
7263 /* Special case load of small data address which looks like:
7264 r16+symbol_ref */
7265 if (GET_CODE (src) == PLUS && plus_small_data_p (op0, op1))
7267 src = frv_ifcvt_load_value (src, insn);
7268 if (src)
7269 COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src);
7270 else
7271 goto fail;
7274 else if (integer_register_operand (op0, SImode) && CONSTANT_P (op1))
7276 op1 = frv_ifcvt_load_value (op1, insn);
7277 if (op1)
7278 COND_EXEC_CODE (pattern)
7279 = gen_rtx_SET (VOIDmode, dest, gen_rtx_fmt_ee (GET_CODE (src),
7280 GET_MODE (src),
7281 op0, op1));
7282 else
7283 goto fail;
7287 /* For multiply by a constant, we need to handle the sign extending
7288 correctly. Add a USE of the value after the multiply to prevent flow
7289 from cratering because only one register out of the two were used. */
7290 else if (mode == DImode && GET_CODE (src) == MULT)
7292 op0 = XEXP (src, 0);
7293 op1 = XEXP (src, 1);
7294 if (GET_CODE (op0) == SIGN_EXTEND && GET_CODE (op1) == CONST_INT)
7296 op1 = frv_ifcvt_load_value (op1, insn);
7297 if (op1)
7299 op1 = gen_rtx_SIGN_EXTEND (DImode, op1);
7300 COND_EXEC_CODE (pattern)
7301 = gen_rtx_SET (VOIDmode, dest,
7302 gen_rtx_MULT (DImode, op0, op1));
7304 else
7305 goto fail;
7308 frv_ifcvt_add_insn (gen_rtx_USE (VOIDmode, dest), insn, FALSE);
7311 /* If we are just loading a constant created for a nested conditional
7312 execution statement, just load the constant without any conditional
7313 execution, since we know that the constant will not interfere with any
7314 other registers. */
7315 else if (frv_ifcvt.scratch_insns_bitmap
7316 && bitmap_bit_p (frv_ifcvt.scratch_insns_bitmap,
7317 INSN_UID (insn)))
7318 pattern = set;
7320 else if (mode == QImode || mode == HImode || mode == SImode
7321 || mode == SFmode)
7323 int changed_p = FALSE;
7325 /* Check for just loading up a constant */
7326 if (CONSTANT_P (src) && integer_register_operand (dest, mode))
7328 src = frv_ifcvt_load_value (src, insn);
7329 if (!src)
7330 goto fail;
7332 changed_p = TRUE;
7335 /* See if we need to fix up stores */
7336 if (GET_CODE (dest) == MEM)
7338 rtx new_mem = frv_ifcvt_rewrite_mem (dest, mode, insn);
7340 if (!new_mem)
7341 goto fail;
7343 else if (new_mem != dest)
7345 changed_p = TRUE;
7346 dest = new_mem;
7350 /* See if we need to fix up loads */
7351 if (GET_CODE (src) == MEM)
7353 rtx new_mem = frv_ifcvt_rewrite_mem (src, mode, insn);
7355 if (!new_mem)
7356 goto fail;
7358 else if (new_mem != src)
7360 changed_p = TRUE;
7361 src = new_mem;
7365 /* If either src or destination changed, redo SET. */
7366 if (changed_p)
7367 COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src);
7370 /* Rewrite a nested set cccr in terms of IF_THEN_ELSE. Also deal with
7371 rewriting the CC register to be the same as the paired CC/CR register
7372 for nested ifs. */
7373 else if (mode == CC_CCRmode && GET_RTX_CLASS (GET_CODE (src)) == '<')
7375 int regno = REGNO (XEXP (src, 0));
7376 rtx if_else;
7378 if (ce_info->pass > 1
7379 && regno != (int)REGNO (frv_ifcvt.nested_cc_reg)
7380 && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, regno))
7382 src = gen_rtx_fmt_ee (GET_CODE (src),
7383 CC_CCRmode,
7384 frv_ifcvt.nested_cc_reg,
7385 XEXP (src, 1));
7388 if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, test, src, const0_rtx);
7389 pattern = gen_rtx_SET (VOIDmode, dest, if_else);
7392 /* Remap a nested compare instruction to use the paired CC/CR reg. */
7393 else if (ce_info->pass > 1
7394 && GET_CODE (dest) == REG
7395 && CC_P (REGNO (dest))
7396 && REGNO (dest) != REGNO (frv_ifcvt.nested_cc_reg)
7397 && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite,
7398 REGNO (dest))
7399 && GET_CODE (src) == COMPARE)
7401 PUT_MODE (frv_ifcvt.nested_cc_reg, GET_MODE (dest));
7402 COND_EXEC_CODE (pattern)
7403 = gen_rtx_SET (VOIDmode, frv_ifcvt.nested_cc_reg, copy_rtx (src));
7407 if (TARGET_DEBUG_COND_EXEC)
7409 rtx orig_pattern = PATTERN (insn);
7411 PATTERN (insn) = pattern;
7412 fprintf (stderr,
7413 "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn after modification:\n",
7414 ce_info->pass);
7416 debug_rtx (insn);
7417 PATTERN (insn) = orig_pattern;
7420 return pattern;
7422 fail:
7423 if (TARGET_DEBUG_COND_EXEC)
7425 rtx orig_pattern = PATTERN (insn);
7427 PATTERN (insn) = orig_ce_pattern;
7428 fprintf (stderr,
7429 "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn could not be modified:\n",
7430 ce_info->pass);
7432 debug_rtx (insn);
7433 PATTERN (insn) = orig_pattern;
7436 return NULL_RTX;
7440 /* A C expression to perform any final machine dependent modifications in
7441 converting code to conditional execution in the code described by the
7442 conditional if information CE_INFO. */
7444 void
7445 frv_ifcvt_modify_final (ce_info)
7446 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
7448 rtx existing_insn;
7449 rtx check_insn;
7450 rtx p = frv_ifcvt.added_insns_list;
7451 int i;
7453 /* Loop inserting the check insns. The last check insn is the first test,
7454 and is the appropriate place to insert constants. */
7455 if (! p)
7456 abort ();
7460 rtx check_and_insert_insns = XEXP (p, 0);
7461 rtx old_p = p;
7463 check_insn = XEXP (check_and_insert_insns, 0);
7464 existing_insn = XEXP (check_and_insert_insns, 1);
7465 p = XEXP (p, 1);
7467 /* The jump bit is used to say that the new insn is to be inserted BEFORE
7468 the existing insn, otherwise it is to be inserted AFTER. */
7469 if (check_and_insert_insns->jump)
7471 emit_insn_before (check_insn, existing_insn);
7472 check_and_insert_insns->jump = 0;
7474 else
7475 emit_insn_after (check_insn, existing_insn);
7477 free_EXPR_LIST_node (check_and_insert_insns);
7478 free_EXPR_LIST_node (old_p);
7480 while (p != NULL_RTX);
7482 /* Load up any constants needed into temp gprs */
7483 for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++)
7485 rtx insn = emit_insn_before (frv_ifcvt.scratch_regs[i], existing_insn);
7486 if (! frv_ifcvt.scratch_insns_bitmap)
7487 frv_ifcvt.scratch_insns_bitmap = BITMAP_XMALLOC ();
7488 bitmap_set_bit (frv_ifcvt.scratch_insns_bitmap, INSN_UID (insn));
7489 frv_ifcvt.scratch_regs[i] = NULL_RTX;
7492 frv_ifcvt.added_insns_list = NULL_RTX;
7493 frv_ifcvt.cur_scratch_regs = 0;
7497 /* A C expression to cancel any machine dependent modifications in converting
7498 code to conditional execution in the code described by the conditional if
7499 information CE_INFO. */
7501 void
7502 frv_ifcvt_modify_cancel (ce_info)
7503 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
7505 int i;
7506 rtx p = frv_ifcvt.added_insns_list;
7508 /* Loop freeing up the EXPR_LIST's allocated. */
7509 while (p != NULL_RTX)
7511 rtx check_and_jump = XEXP (p, 0);
7512 rtx old_p = p;
7514 p = XEXP (p, 1);
7515 free_EXPR_LIST_node (check_and_jump);
7516 free_EXPR_LIST_node (old_p);
7519 /* Release any temporary gprs allocated. */
7520 for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++)
7521 frv_ifcvt.scratch_regs[i] = NULL_RTX;
7523 frv_ifcvt.added_insns_list = NULL_RTX;
7524 frv_ifcvt.cur_scratch_regs = 0;
7525 return;
7528 /* A C expression for the size in bytes of the trampoline, as an integer.
7529 The template is:
7531 setlo #0, <jmp_reg>
7532 setlo #0, <static_chain>
7533 sethi #0, <jmp_reg>
7534 sethi #0, <static_chain>
7535 jmpl @(gr0,<jmp_reg>) */
7538 frv_trampoline_size ()
7540 return 5 /* instructions */ * 4 /* instruction size */;
7544 /* A C statement to initialize the variable parts of a trampoline. ADDR is an
7545 RTX for the address of the trampoline; FNADDR is an RTX for the address of
7546 the nested function; STATIC_CHAIN is an RTX for the static chain value that
7547 should be passed to the function when it is called.
7549 The template is:
7551 setlo #0, <jmp_reg>
7552 setlo #0, <static_chain>
7553 sethi #0, <jmp_reg>
7554 sethi #0, <static_chain>
7555 jmpl @(gr0,<jmp_reg>) */
7557 void
7558 frv_initialize_trampoline (addr, fnaddr, static_chain)
7559 rtx addr;
7560 rtx fnaddr;
7561 rtx static_chain;
7563 rtx sc_reg = force_reg (Pmode, static_chain);
7565 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
7566 FALSE, VOIDmode, 4,
7567 addr, Pmode,
7568 GEN_INT (frv_trampoline_size ()), SImode,
7569 fnaddr, Pmode,
7570 sc_reg, Pmode);
7574 /* Many machines have some registers that cannot be copied directly to or from
7575 memory or even from other types of registers. An example is the `MQ'
7576 register, which on most machines, can only be copied to or from general
7577 registers, but not memory. Some machines allow copying all registers to and
7578 from memory, but require a scratch register for stores to some memory
7579 locations (e.g., those with symbolic address on the RT, and those with
7580 certain symbolic address on the SPARC when compiling PIC). In some cases,
7581 both an intermediate and a scratch register are required.
7583 You should define these macros to indicate to the reload phase that it may
7584 need to allocate at least one register for a reload in addition to the
7585 register to contain the data. Specifically, if copying X to a register
7586 CLASS in MODE requires an intermediate register, you should define
7587 `SECONDARY_INPUT_RELOAD_CLASS' to return the largest register class all of
7588 whose registers can be used as intermediate registers or scratch registers.
7590 If copying a register CLASS in MODE to X requires an intermediate or scratch
7591 register, `SECONDARY_OUTPUT_RELOAD_CLASS' should be defined to return the
7592 largest register class required. If the requirements for input and output
7593 reloads are the same, the macro `SECONDARY_RELOAD_CLASS' should be used
7594 instead of defining both macros identically.
7596 The values returned by these macros are often `GENERAL_REGS'. Return
7597 `NO_REGS' if no spare register is needed; i.e., if X can be directly copied
7598 to or from a register of CLASS in MODE without requiring a scratch register.
7599 Do not define this macro if it would always return `NO_REGS'.
7601 If a scratch register is required (either with or without an intermediate
7602 register), you should define patterns for `reload_inM' or `reload_outM', as
7603 required.. These patterns, which will normally be implemented with a
7604 `define_expand', should be similar to the `movM' patterns, except that
7605 operand 2 is the scratch register.
7607 Define constraints for the reload register and scratch register that contain
7608 a single register class. If the original reload register (whose class is
7609 CLASS) can meet the constraint given in the pattern, the value returned by
7610 these macros is used for the class of the scratch register. Otherwise, two
7611 additional reload registers are required. Their classes are obtained from
7612 the constraints in the insn pattern.
7614 X might be a pseudo-register or a `subreg' of a pseudo-register, which could
7615 either be in a hard register or in memory. Use `true_regnum' to find out;
7616 it will return -1 if the pseudo is in memory and the hard register number if
7617 it is in a register.
7619 These macros should not be used in the case where a particular class of
7620 registers can only be copied to memory and not to another class of
7621 registers. In that case, secondary reload registers are not needed and
7622 would not be helpful. Instead, a stack location must be used to perform the
7623 copy and the `movM' pattern should use memory as an intermediate storage.
7624 This case often occurs between floating-point and general registers. */
7626 enum reg_class
7627 frv_secondary_reload_class (class, mode, x, in_p)
7628 enum reg_class class;
7629 enum machine_mode mode ATTRIBUTE_UNUSED;
7630 rtx x;
7631 int in_p ATTRIBUTE_UNUSED;
7633 enum reg_class ret;
7635 switch (class)
7637 default:
7638 ret = NO_REGS;
7639 break;
7641 /* Accumulators/Accumulator guard registers need to go through floating
7642 point registers. */
7643 case QUAD_REGS:
7644 case EVEN_REGS:
7645 case GPR_REGS:
7646 ret = NO_REGS;
7647 if (x && GET_CODE (x) == REG)
7649 int regno = REGNO (x);
7651 if (ACC_P (regno) || ACCG_P (regno))
7652 ret = FPR_REGS;
7654 break;
7656 /* Nonzero constants should be loaded into an FPR through a GPR. */
7657 case QUAD_FPR_REGS:
7658 case FEVEN_REGS:
7659 case FPR_REGS:
7660 if (x && CONSTANT_P (x) && !ZERO_P (x))
7661 ret = GPR_REGS;
7662 else
7663 ret = NO_REGS;
7664 break;
7666 /* All of these types need gpr registers. */
7667 case ICC_REGS:
7668 case FCC_REGS:
7669 case CC_REGS:
7670 case ICR_REGS:
7671 case FCR_REGS:
7672 case CR_REGS:
7673 case LCR_REG:
7674 case LR_REG:
7675 ret = GPR_REGS;
7676 break;
7678 /* The accumulators need fpr registers */
7679 case ACC_REGS:
7680 case EVEN_ACC_REGS:
7681 case QUAD_ACC_REGS:
7682 case ACCG_REGS:
7683 ret = FPR_REGS;
7684 break;
7687 return ret;
7691 /* A C expression whose value is nonzero if pseudos that have been assigned to
7692 registers of class CLASS would likely be spilled because registers of CLASS
7693 are needed for spill registers.
7695 The default value of this macro returns 1 if CLASS has exactly one register
7696 and zero otherwise. On most machines, this default should be used. Only
7697 define this macro to some other expression if pseudo allocated by
7698 `local-alloc.c' end up in memory because their hard registers were needed
7699 for spill registers. If this macro returns nonzero for those classes, those
7700 pseudos will only be allocated by `global.c', which knows how to reallocate
7701 the pseudo to another register. If there would not be another register
7702 available for reallocation, you should not change the definition of this
7703 macro since the only effect of such a definition would be to slow down
7704 register allocation. */
7707 frv_class_likely_spilled_p (class)
7708 enum reg_class class;
7710 switch (class)
7712 default:
7713 break;
7715 case ICC_REGS:
7716 case FCC_REGS:
7717 case CC_REGS:
7718 case ICR_REGS:
7719 case FCR_REGS:
7720 case CR_REGS:
7721 case LCR_REG:
7722 case LR_REG:
7723 case SPR_REGS:
7724 case QUAD_ACC_REGS:
7725 case EVEN_ACC_REGS:
7726 case ACC_REGS:
7727 case ACCG_REGS:
7728 return TRUE;
7731 return FALSE;
7735 /* An expression for the alignment of a structure field FIELD if the
7736 alignment computed in the usual way is COMPUTED. GNU CC uses this
7737 value instead of the value in `BIGGEST_ALIGNMENT' or
7738 `BIGGEST_FIELD_ALIGNMENT', if defined, for structure fields only. */
7740 /* The definition type of the bit field data is either char, short, long or
7741 long long. The maximum bit size is the number of bits of its own type.
7743 The bit field data is assigned to a storage unit that has an adequate size
7744 for bit field data retention and is located at the smallest address.
7746 Consecutive bit field data are packed at consecutive bits having the same
7747 storage unit, with regard to the type, beginning with the MSB and continuing
7748 toward the LSB.
7750 If a field to be assigned lies over a bit field type boundary, its
7751 assignment is completed by aligning it with a boundary suitable for the
7752 type.
7754 When a bit field having a bit length of 0 is declared, it is forcibly
7755 assigned to the next storage unit.
7757 e.g)
7758 struct {
7759 int a:2;
7760 int b:6;
7761 char c:4;
7762 int d:10;
7763 int :0;
7764 int f:2;
7765 } x;
7767 +0 +1 +2 +3
7768 &x 00000000 00000000 00000000 00000000
7769 MLM----L
7771 &x+4 00000000 00000000 00000000 00000000
7772 M--L
7774 &x+8 00000000 00000000 00000000 00000000
7775 M----------L
7777 &x+12 00000000 00000000 00000000 00000000
7783 frv_adjust_field_align (field, computed)
7784 tree field;
7785 int computed;
7787 /* C++ provides a null DECL_CONTEXT if the bit field is wider than its
7788 type. */
7789 if (DECL_BIT_FIELD (field) && DECL_CONTEXT (field))
7791 tree parent = DECL_CONTEXT (field);
7792 tree prev = NULL_TREE;
7793 tree cur;
7795 /* Loop finding the previous field to the current one */
7796 for (cur = TYPE_FIELDS (parent); cur && cur != field; cur = TREE_CHAIN (cur))
7798 if (TREE_CODE (cur) != FIELD_DECL)
7799 continue;
7801 prev = cur;
7804 if (!cur)
7805 abort ();
7807 /* If this isn't a :0 field and if the previous element is a bitfield
7808 also, see if the type is different, if so, we will need to align the
7809 bit-field to the next boundary */
7810 if (prev
7811 && ! DECL_PACKED (field)
7812 && ! integer_zerop (DECL_SIZE (field))
7813 && DECL_BIT_FIELD_TYPE (field) != DECL_BIT_FIELD_TYPE (prev))
7815 int prev_align = TYPE_ALIGN (TREE_TYPE (prev));
7816 int cur_align = TYPE_ALIGN (TREE_TYPE (field));
7817 computed = (prev_align > cur_align) ? prev_align : cur_align;
7821 return computed;
7825 /* A C expression that is nonzero if it is permissible to store a value of mode
7826 MODE in hard register number REGNO (or in several registers starting with
7827 that one). For a machine where all registers are equivalent, a suitable
7828 definition is
7830 #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
7832 It is not necessary for this macro to check for the numbers of fixed
7833 registers, because the allocation mechanism considers them to be always
7834 occupied.
7836 On some machines, double-precision values must be kept in even/odd register
7837 pairs. The way to implement that is to define this macro to reject odd
7838 register numbers for such modes.
7840 The minimum requirement for a mode to be OK in a register is that the
7841 `movMODE' instruction pattern support moves between the register and any
7842 other hard register for which the mode is OK; and that moving a value into
7843 the register and back out not alter it.
7845 Since the same instruction used to move `SImode' will work for all narrower
7846 integer modes, it is not necessary on any machine for `HARD_REGNO_MODE_OK'
7847 to distinguish between these modes, provided you define patterns `movhi',
7848 etc., to take advantage of this. This is useful because of the interaction
7849 between `HARD_REGNO_MODE_OK' and `MODES_TIEABLE_P'; it is very desirable for
7850 all integer modes to be tieable.
7852 Many machines have special registers for floating point arithmetic. Often
7853 people assume that floating point machine modes are allowed only in floating
7854 point registers. This is not true. Any registers that can hold integers
7855 can safely *hold* a floating point machine mode, whether or not floating
7856 arithmetic can be done on it in those registers. Integer move instructions
7857 can be used to move the values.
7859 On some machines, though, the converse is true: fixed-point machine modes
7860 may not go in floating registers. This is true if the floating registers
7861 normalize any value stored in them, because storing a non-floating value
7862 there would garble it. In this case, `HARD_REGNO_MODE_OK' should reject
7863 fixed-point machine modes in floating registers. But if the floating
7864 registers do not automatically normalize, if you can store any bit pattern
7865 in one and retrieve it unchanged without a trap, then any machine mode may
7866 go in a floating register, so you can define this macro to say so.
7868 The primary significance of special floating registers is rather that they
7869 are the registers acceptable in floating point arithmetic instructions.
7870 However, this is of no concern to `HARD_REGNO_MODE_OK'. You handle it by
7871 writing the proper constraints for those instructions.
7873 On some machines, the floating registers are especially slow to access, so
7874 that it is better to store a value in a stack frame than in such a register
7875 if floating point arithmetic is not being done. As long as the floating
7876 registers are not in class `GENERAL_REGS', they will not be used unless some
7877 pattern's constraint asks for one. */
7880 frv_hard_regno_mode_ok (regno, mode)
7881 int regno;
7882 enum machine_mode mode;
7884 int base;
7885 int mask;
7887 switch (mode)
7889 case CCmode:
7890 case CC_UNSmode:
7891 return ICC_P (regno) || GPR_P (regno);
7893 case CC_CCRmode:
7894 return CR_P (regno) || GPR_P (regno);
7896 case CC_FPmode:
7897 return FCC_P (regno) || GPR_P (regno);
7899 default:
7900 break;
7903 /* Set BASE to the first register in REGNO's class. Set MASK to the
7904 bits that must be clear in (REGNO - BASE) for the register to be
7905 well-aligned. */
7906 if (INTEGRAL_MODE_P (mode) || FLOAT_MODE_P (mode) || VECTOR_MODE_P (mode))
7908 if (ACCG_P (regno))
7910 /* ACCGs store one byte. Two-byte quantities must start in
7911 even-numbered registers, four-byte ones in registers whose
7912 numbers are divisible by four, and so on. */
7913 base = ACCG_FIRST;
7914 mask = GET_MODE_SIZE (mode) - 1;
7916 else
7918 /* The other registers store one word. */
7919 if (GPR_P (regno))
7920 base = GPR_FIRST;
7922 else if (FPR_P (regno))
7923 base = FPR_FIRST;
7925 else if (ACC_P (regno))
7926 base = ACC_FIRST;
7928 else
7929 return 0;
7931 /* Anything smaller than an SI is OK in any word-sized register. */
7932 if (GET_MODE_SIZE (mode) < 4)
7933 return 1;
7935 mask = (GET_MODE_SIZE (mode) / 4) - 1;
7937 return (((regno - base) & mask) == 0);
7940 return 0;
7944 /* A C expression for the number of consecutive hard registers, starting at
7945 register number REGNO, required to hold a value of mode MODE.
7947 On a machine where all registers are exactly one word, a suitable definition
7948 of this macro is
7950 #define HARD_REGNO_NREGS(REGNO, MODE) \
7951 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
7952 / UNITS_PER_WORD)) */
7954 /* On the FRV, make the CC_FP mode take 3 words in the integer registers, so
7955 that we can build the appropriate instructions to properly reload the
7956 values. Also, make the byte-sized accumulator guards use one guard
7957 for each byte. */
7960 frv_hard_regno_nregs (regno, mode)
7961 int regno;
7962 enum machine_mode mode;
7964 if (ACCG_P (regno))
7965 return GET_MODE_SIZE (mode);
7966 else
7967 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7971 /* A C expression for the maximum number of consecutive registers of
7972 class CLASS needed to hold a value of mode MODE.
7974 This is closely related to the macro `HARD_REGNO_NREGS'. In fact, the value
7975 of the macro `CLASS_MAX_NREGS (CLASS, MODE)' should be the maximum value of
7976 `HARD_REGNO_NREGS (REGNO, MODE)' for all REGNO values in the class CLASS.
7978 This macro helps control the handling of multiple-word values in
7979 the reload pass.
7981 This declaration is required. */
7984 frv_class_max_nregs (class, mode)
7985 enum reg_class class;
7986 enum machine_mode mode;
7988 if (class == ACCG_REGS)
7989 /* An N-byte value requires N accumulator guards. */
7990 return GET_MODE_SIZE (mode);
7991 else
7992 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7996 /* A C expression that is nonzero if X is a legitimate constant for an
7997 immediate operand on the target machine. You can assume that X satisfies
7998 `CONSTANT_P', so you need not check this. In fact, `1' is a suitable
7999 definition for this macro on machines where anything `CONSTANT_P' is valid. */
8002 frv_legitimate_constant_p (x)
8003 rtx x;
8005 enum machine_mode mode = GET_MODE (x);
8007 /* All of the integer constants are ok */
8008 if (GET_CODE (x) != CONST_DOUBLE)
8009 return TRUE;
8011 /* double integer constants are ok */
8012 if (mode == VOIDmode || mode == DImode)
8013 return TRUE;
8015 /* 0 is always ok */
8016 if (x == CONST0_RTX (mode))
8017 return TRUE;
8019 /* If floating point is just emulated, allow any constant, since it will be
8020 constructed in the GPRs */
8021 if (!TARGET_HAS_FPRS)
8022 return TRUE;
8024 if (mode == DFmode && !TARGET_DOUBLE)
8025 return TRUE;
8027 /* Otherwise store the constant away and do a load. */
8028 return FALSE;
8031 /* A C expression for the cost of moving data from a register in class FROM to
8032 one in class TO. The classes are expressed using the enumeration values
8033 such as `GENERAL_REGS'. A value of 4 is the default; other values are
8034 interpreted relative to that.
8036 It is not required that the cost always equal 2 when FROM is the same as TO;
8037 on some machines it is expensive to move between registers if they are not
8038 general registers.
8040 If reload sees an insn consisting of a single `set' between two hard
8041 registers, and if `REGISTER_MOVE_COST' applied to their classes returns a
8042 value of 2, reload does not check to ensure that the constraints of the insn
8043 are met. Setting a cost of other than 2 will allow reload to verify that
8044 the constraints are met. You should do this if the `movM' pattern's
8045 constraints do not allow such copying. */
8047 #define HIGH_COST 40
8048 #define MEDIUM_COST 3
8049 #define LOW_COST 1
8052 frv_register_move_cost (from, to)
8053 enum reg_class from;
8054 enum reg_class to;
8056 switch (from)
8058 default:
8059 break;
8061 case QUAD_REGS:
8062 case EVEN_REGS:
8063 case GPR_REGS:
8064 switch (to)
8066 default:
8067 break;
8069 case QUAD_REGS:
8070 case EVEN_REGS:
8071 case GPR_REGS:
8072 return LOW_COST;
8074 case FEVEN_REGS:
8075 case FPR_REGS:
8076 return LOW_COST;
8078 case LCR_REG:
8079 case LR_REG:
8080 case SPR_REGS:
8081 return LOW_COST;
8084 case FEVEN_REGS:
8085 case FPR_REGS:
8086 switch (to)
8088 default:
8089 break;
8091 case QUAD_REGS:
8092 case EVEN_REGS:
8093 case GPR_REGS:
8094 case ACC_REGS:
8095 case EVEN_ACC_REGS:
8096 case QUAD_ACC_REGS:
8097 case ACCG_REGS:
8098 return MEDIUM_COST;
8100 case FEVEN_REGS:
8101 case FPR_REGS:
8102 return LOW_COST;
8105 case LCR_REG:
8106 case LR_REG:
8107 case SPR_REGS:
8108 switch (to)
8110 default:
8111 break;
8113 case QUAD_REGS:
8114 case EVEN_REGS:
8115 case GPR_REGS:
8116 return MEDIUM_COST;
8119 case ACC_REGS:
8120 case EVEN_ACC_REGS:
8121 case QUAD_ACC_REGS:
8122 case ACCG_REGS:
8123 switch (to)
8125 default:
8126 break;
8128 case FEVEN_REGS:
8129 case FPR_REGS:
8130 return MEDIUM_COST;
8135 return HIGH_COST;
8138 /* Implementation of TARGET_ASM_INTEGER. In the FRV case we need to
8139 use ".picptr" to generate safe relocations for PIC code. We also
8140 need a fixup entry for aligned (non-debugging) code. */
8142 static bool
8143 frv_assemble_integer (value, size, aligned_p)
8144 rtx value;
8145 unsigned int size;
8146 int aligned_p;
8148 if (flag_pic && size == UNITS_PER_WORD)
8150 if (GET_CODE (value) == CONST
8151 || GET_CODE (value) == SYMBOL_REF
8152 || GET_CODE (value) == LABEL_REF)
8154 if (aligned_p)
8156 static int label_num = 0;
8157 char buf[256];
8158 const char *p;
8160 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", label_num++);
8161 p = (* targetm.strip_name_encoding) (buf);
8163 fprintf (asm_out_file, "%s:\n", p);
8164 fprintf (asm_out_file, "%s\n", FIXUP_SECTION_ASM_OP);
8165 fprintf (asm_out_file, "\t.picptr\t%s\n", p);
8166 fprintf (asm_out_file, "\t.previous\n");
8168 assemble_integer_with_op ("\t.picptr\t", value);
8169 return true;
8171 if (!aligned_p)
8173 /* We've set the unaligned SI op to NULL, so we always have to
8174 handle the unaligned case here. */
8175 assemble_integer_with_op ("\t.4byte\t", value);
8176 return true;
8179 return default_assemble_integer (value, size, aligned_p);
8182 /* Function to set up the backend function structure. */
8184 static struct machine_function *
8185 frv_init_machine_status ()
8187 return ggc_alloc_cleared (sizeof (struct machine_function));
8191 /* Update the register state information, to know about which registers are set
8192 or clobbered. */
8194 static void
8195 frv_registers_update (x, reg_state, modified, p_num_mod, flag)
8196 rtx x;
8197 unsigned char reg_state[];
8198 int modified[];
8199 int *p_num_mod;
8200 int flag;
8202 int regno, reg_max;
8203 rtx reg;
8204 rtx cond;
8205 const char *format;
8206 int length;
8207 int j;
8209 switch (GET_CODE (x))
8211 default:
8212 break;
8214 /* Clobber just modifies a register, it doesn't make it live. */
8215 case CLOBBER:
8216 frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod,
8217 flag | REGSTATE_MODIFIED);
8218 return;
8220 /* Pre modify updates the first argument, just references the second. */
8221 case PRE_MODIFY:
8222 case SET:
8223 frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod,
8224 flag | REGSTATE_MODIFIED | REGSTATE_LIVE);
8225 frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod, flag);
8226 return;
8228 /* For COND_EXEC, pass the appropriate flag to evaluate the conditional
8229 statement, but just to be sure, make sure it is the type of cond_exec
8230 we expect. */
8231 case COND_EXEC:
8232 cond = XEXP (x, 0);
8233 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8234 && GET_CODE (XEXP (cond, 0)) == REG
8235 && CR_P (REGNO (XEXP (cond, 0)))
8236 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8237 && INTVAL (XEXP (cond, 1)) == 0
8238 && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0)
8240 frv_registers_update (cond, reg_state, modified, p_num_mod, flag);
8241 flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST)
8242 | ((GET_CODE (cond) == NE)
8243 ? REGSTATE_IF_TRUE
8244 : REGSTATE_IF_FALSE));
8246 frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod,
8247 flag);
8248 return;
8250 else
8251 fatal_insn ("frv_registers_update", x);
8253 /* MEM resets the modification bits. */
8254 case MEM:
8255 flag &= ~REGSTATE_MODIFIED;
8256 break;
8258 /* See if we need to set the modified flag. */
8259 case SUBREG:
8260 reg = SUBREG_REG (x);
8261 if (GET_CODE (reg) == REG)
8263 regno = subreg_regno (x);
8264 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8265 goto reg_common;
8267 break;
8269 case REG:
8270 regno = REGNO (x);
8271 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8272 /* fall through */
8274 reg_common:
8275 if (flag & REGSTATE_MODIFIED)
8277 flag &= REGSTATE_MASK;
8278 while (regno < reg_max)
8280 int rs = reg_state[regno];
8282 if (flag != rs)
8284 if ((rs & REGSTATE_MODIFIED) == 0)
8286 modified[ *p_num_mod ] = regno;
8287 (*p_num_mod)++;
8290 /* If the previous register state had the register as
8291 modified, possibly in some conditional execution context,
8292 and the current insn modifies in some other context, or
8293 outside of conditional execution, just mark the variable
8294 as modified. */
8295 else
8296 flag &= ~(REGSTATE_IF_EITHER | REGSTATE_CC_MASK);
8298 reg_state[regno] = (rs | flag);
8300 regno++;
8303 return;
8307 length = GET_RTX_LENGTH (GET_CODE (x));
8308 format = GET_RTX_FORMAT (GET_CODE (x));
8310 for (j = 0; j < length; ++j)
8312 switch (format[j])
8314 case 'e':
8315 frv_registers_update (XEXP (x, j), reg_state, modified, p_num_mod,
8316 flag);
8317 break;
8319 case 'V':
8320 case 'E':
8321 if (XVEC (x, j) != 0)
8323 int k;
8324 for (k = 0; k < XVECLEN (x, j); ++k)
8325 frv_registers_update (XVECEXP (x, j, k), reg_state, modified,
8326 p_num_mod, flag);
8328 break;
8330 default:
8331 /* Nothing to do. */
8332 break;
8336 return;
8340 /* Return if any registers in a hard register set were used an insn. */
8342 static int
8343 frv_registers_used_p (x, reg_state, flag)
8344 rtx x;
8345 unsigned char reg_state[];
8346 int flag;
8348 int regno, reg_max;
8349 rtx reg;
8350 rtx cond;
8351 rtx dest;
8352 const char *format;
8353 int result;
8354 int length;
8355 int j;
8357 switch (GET_CODE (x))
8359 default:
8360 break;
8362 /* Skip clobber, that doesn't use the previous value */
8363 case CLOBBER:
8364 return FALSE;
8366 /* For SET, if a conditional jump has occurred in the same insn, only
8367 allow a set of a CR register if that register is not currently live.
8368 This is because on the FR-V, B0/B1 instructions are always last.
8369 Otherwise, don't look at the result, except within a MEM, but do look
8370 at the source. */
8371 case SET:
8372 dest = SET_DEST (x);
8373 if (flag & REGSTATE_CONDJUMP
8374 && GET_CODE (dest) == REG && CR_P (REGNO (dest))
8375 && (reg_state[ REGNO (dest) ] & REGSTATE_LIVE) != 0)
8376 return TRUE;
8378 if (GET_CODE (dest) == MEM)
8380 result = frv_registers_used_p (XEXP (dest, 0), reg_state, flag);
8381 if (result)
8382 return result;
8385 return frv_registers_used_p (SET_SRC (x), reg_state, flag);
8387 /* For COND_EXEC, pass the appropriate flag to evaluate the conditional
8388 statement, but just to be sure, make sure it is the type of cond_exec
8389 we expect. */
8390 case COND_EXEC:
8391 cond = XEXP (x, 0);
8392 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8393 && GET_CODE (XEXP (cond, 0)) == REG
8394 && CR_P (REGNO (XEXP (cond, 0)))
8395 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8396 && INTVAL (XEXP (cond, 1)) == 0
8397 && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0)
8399 result = frv_registers_used_p (cond, reg_state, flag);
8400 if (result)
8401 return result;
8403 flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST)
8404 | ((GET_CODE (cond) == NE)
8405 ? REGSTATE_IF_TRUE
8406 : REGSTATE_IF_FALSE));
8408 return frv_registers_used_p (XEXP (x, 1), reg_state, flag);
8410 else
8411 fatal_insn ("frv_registers_used_p", x);
8413 /* See if a register or subreg was modified in the same VLIW insn. */
8414 case SUBREG:
8415 reg = SUBREG_REG (x);
8416 if (GET_CODE (reg) == REG)
8418 regno = subreg_regno (x);
8419 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8420 goto reg_common;
8422 break;
8424 case REG:
8425 regno = REGNO (x);
8426 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8427 /* fall through */
8429 reg_common:
8430 while (regno < reg_max)
8432 int rs = reg_state[regno];
8434 if (rs & REGSTATE_MODIFIED)
8436 int rs_if = rs & REGSTATE_IF_EITHER;
8437 int flag_if = flag & REGSTATE_IF_EITHER;
8439 /* Simple modification, no conditional execution */
8440 if ((rs & REGSTATE_IF_EITHER) == 0)
8441 return TRUE;
8443 /* See if the variable is only modified in a conditional
8444 execution expression opposite to the conditional execution
8445 expression that governs this expression (ie, true vs. false
8446 for the same CC register). If this isn't two halves of the
8447 same conditional expression, consider the register
8448 modified. */
8449 if (((rs_if == REGSTATE_IF_TRUE && flag_if == REGSTATE_IF_FALSE)
8450 || (rs_if == REGSTATE_IF_FALSE && flag_if == REGSTATE_IF_TRUE))
8451 && ((rs & REGSTATE_CC_MASK) == (flag & REGSTATE_CC_MASK)))
8453 else
8454 return TRUE;
8457 regno++;
8459 return FALSE;
8463 length = GET_RTX_LENGTH (GET_CODE (x));
8464 format = GET_RTX_FORMAT (GET_CODE (x));
8466 for (j = 0; j < length; ++j)
8468 switch (format[j])
8470 case 'e':
8471 result = frv_registers_used_p (XEXP (x, j), reg_state, flag);
8472 if (result != 0)
8473 return result;
8474 break;
8476 case 'V':
8477 case 'E':
8478 if (XVEC (x, j) != 0)
8480 int k;
8481 for (k = 0; k < XVECLEN (x, j); ++k)
8483 result = frv_registers_used_p (XVECEXP (x, j, k), reg_state,
8484 flag);
8485 if (result != 0)
8486 return result;
8489 break;
8491 default:
8492 /* Nothing to do. */
8493 break;
8497 return 0;
8500 /* Return if any registers in a hard register set were set in an insn. */
8502 static int
8503 frv_registers_set_p (x, reg_state, modify_p)
8504 rtx x;
8505 unsigned char reg_state[];
8506 int modify_p;
8508 int regno, reg_max;
8509 rtx reg;
8510 rtx cond;
8511 const char *format;
8512 int length;
8513 int j;
8515 switch (GET_CODE (x))
8517 default:
8518 break;
8520 case CLOBBER:
8521 return frv_registers_set_p (XEXP (x, 0), reg_state, TRUE);
8523 case PRE_MODIFY:
8524 case SET:
8525 return (frv_registers_set_p (XEXP (x, 0), reg_state, TRUE)
8526 || frv_registers_set_p (XEXP (x, 1), reg_state, FALSE));
8528 case COND_EXEC:
8529 cond = XEXP (x, 0);
8530 /* just to be sure, make sure it is the type of cond_exec we
8531 expect. */
8532 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8533 && GET_CODE (XEXP (cond, 0)) == REG
8534 && CR_P (REGNO (XEXP (cond, 0)))
8535 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8536 && INTVAL (XEXP (cond, 1)) == 0
8537 && !modify_p)
8538 return frv_registers_set_p (XEXP (x, 1), reg_state, modify_p);
8539 else
8540 fatal_insn ("frv_registers_set_p", x);
8542 /* MEM resets the modification bits. */
8543 case MEM:
8544 modify_p = FALSE;
8545 break;
8547 /* See if we need to set the modified modify_p. */
8548 case SUBREG:
8549 reg = SUBREG_REG (x);
8550 if (GET_CODE (reg) == REG)
8552 regno = subreg_regno (x);
8553 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8554 goto reg_common;
8556 break;
8558 case REG:
8559 regno = REGNO (x);
8560 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8561 /* fall through */
8563 reg_common:
8564 if (modify_p)
8565 while (regno < reg_max)
8567 int rs = reg_state[regno];
8569 if (rs & REGSTATE_MODIFIED)
8570 return TRUE;
8571 regno++;
8573 return FALSE;
8577 length = GET_RTX_LENGTH (GET_CODE (x));
8578 format = GET_RTX_FORMAT (GET_CODE (x));
8580 for (j = 0; j < length; ++j)
8582 switch (format[j])
8584 case 'e':
8585 if (frv_registers_set_p (XEXP (x, j), reg_state, modify_p))
8586 return TRUE;
8587 break;
8589 case 'V':
8590 case 'E':
8591 if (XVEC (x, j) != 0)
8593 int k;
8594 for (k = 0; k < XVECLEN (x, j); ++k)
8595 if (frv_registers_set_p (XVECEXP (x, j, k), reg_state,
8596 modify_p))
8597 return TRUE;
8599 break;
8601 default:
8602 /* Nothing to do. */
8603 break;
8607 return FALSE;
8611 /* On the FR-V, this pass is used to rescan the insn chain, and pack
8612 conditional branches/calls/jumps, etc. with previous insns where it can. It
8613 does not reorder the instructions. We assume the scheduler left the flow
8614 information in a reasonable state. */
8616 static void
8617 frv_pack_insns ()
8619 state_t frv_state; /* frv state machine */
8620 int cur_start_vliw_p; /* current insn starts a VLIW insn */
8621 int next_start_vliw_p; /* next insn starts a VLIW insn */
8622 int cur_condjump_p; /* flag if current insn is a cond jump*/
8623 int next_condjump_p; /* flag if next insn is a cond jump */
8624 rtx insn;
8625 rtx link;
8626 int j;
8627 int num_mod = 0; /* # of modified registers */
8628 int modified[FIRST_PSEUDO_REGISTER]; /* registers modified in current VLIW */
8629 /* register state information */
8630 unsigned char reg_state[FIRST_PSEUDO_REGISTER];
8632 /* If we weren't going to pack the insns, don't bother with this pass. */
8633 if (!optimize || !flag_schedule_insns_after_reload || TARGET_NO_VLIW_BRANCH)
8634 return;
8636 switch (frv_cpu_type)
8638 default:
8639 case FRV_CPU_FR300: /* FR300/simple are single issue */
8640 case FRV_CPU_SIMPLE:
8641 return;
8643 case FRV_CPU_GENERIC: /* FR-V and FR500 are multi-issue */
8644 case FRV_CPU_FR400:
8645 case FRV_CPU_FR500:
8646 case FRV_CPU_TOMCAT:
8647 break;
8650 /* Set up the instruction and register states. */
8651 dfa_start ();
8652 frv_state = (state_t) xmalloc (state_size ());
8653 memset ((PTR) reg_state, REGSTATE_DEAD, sizeof (reg_state));
8655 /* Go through the insns, and repack the insns. */
8656 state_reset (frv_state);
8657 cur_start_vliw_p = FALSE;
8658 next_start_vliw_p = TRUE;
8659 cur_condjump_p = 0;
8660 next_condjump_p = 0;
8662 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
8664 enum rtx_code code = GET_CODE (insn);
8665 enum rtx_code pattern_code;
8667 /* For basic block begin notes redo the live information, and skip other
8668 notes. */
8669 if (code == NOTE)
8671 if (NOTE_LINE_NUMBER (insn) == (int)NOTE_INSN_BASIC_BLOCK)
8673 regset live;
8675 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
8676 reg_state[j] &= ~ REGSTATE_LIVE;
8678 live = NOTE_BASIC_BLOCK (insn)->global_live_at_start;
8679 EXECUTE_IF_SET_IN_REG_SET(live, 0, j,
8681 reg_state[j] |= REGSTATE_LIVE;
8685 continue;
8688 /* things like labels reset everything. */
8689 if (GET_RTX_CLASS (code) != 'i')
8691 next_start_vliw_p = TRUE;
8692 continue;
8695 /* Clear the VLIW start flag on random USE and CLOBBER insns, which is
8696 set on the USE insn that preceeds the return, and potentially on
8697 CLOBBERs for setting multiword variables. Also skip the ADDR_VEC
8698 holding the case table labels. */
8699 pattern_code = GET_CODE (PATTERN (insn));
8700 if (pattern_code == USE || pattern_code == CLOBBER
8701 || pattern_code == ADDR_VEC || pattern_code == ADDR_DIFF_VEC)
8703 CLEAR_VLIW_START (insn);
8704 continue;
8707 cur_start_vliw_p = next_start_vliw_p;
8708 next_start_vliw_p = FALSE;
8710 cur_condjump_p |= next_condjump_p;
8711 next_condjump_p = 0;
8713 /* Unconditional branches and calls end the current VLIW insn. */
8714 if (code == CALL_INSN)
8716 next_start_vliw_p = TRUE;
8718 /* On a TOMCAT, calls must be alone in the VLIW insns. */
8719 if (frv_cpu_type == FRV_CPU_TOMCAT)
8720 cur_start_vliw_p = TRUE;
8722 else if (code == JUMP_INSN)
8724 if (any_condjump_p (insn))
8725 next_condjump_p = REGSTATE_CONDJUMP;
8726 else
8727 next_start_vliw_p = TRUE;
8730 /* Only allow setting a CCR register after a conditional branch. */
8731 else if (((cur_condjump_p & REGSTATE_CONDJUMP) != 0)
8732 && get_attr_type (insn) != TYPE_CCR)
8733 cur_start_vliw_p = TRUE;
8735 /* Determine if we need to start a new VLIW instruction. */
8736 if (cur_start_vliw_p
8737 /* Do not check for register conflicts in a setlo instruction
8738 because any output or true dependencies will be with the
8739 partnering sethi instruction, with which it can be packed.
8741 Although output dependencies are rare they are still
8742 possible. So check output dependencies in VLIW insn. */
8743 || (get_attr_type (insn) != TYPE_SETLO
8744 && (frv_registers_used_p (PATTERN (insn),
8745 reg_state,
8746 cur_condjump_p)
8747 || frv_registers_set_p (PATTERN (insn), reg_state, FALSE)))
8748 || state_transition (frv_state, insn) >= 0)
8750 SET_VLIW_START (insn);
8751 state_reset (frv_state);
8752 state_transition (frv_state, insn);
8753 cur_condjump_p = 0;
8755 /* Update the modified registers. */
8756 for (j = 0; j < num_mod; j++)
8757 reg_state[ modified[j] ] &= ~(REGSTATE_CC_MASK
8758 | REGSTATE_IF_EITHER
8759 | REGSTATE_MODIFIED);
8761 num_mod = 0;
8763 else
8764 CLEAR_VLIW_START (insn);
8766 /* Record which registers are modified. */
8767 frv_registers_update (PATTERN (insn), reg_state, modified, &num_mod, 0);
8769 /* Process the death notices */
8770 for (link = REG_NOTES (insn);
8771 link != NULL_RTX;
8772 link = XEXP (link, 1))
8774 rtx reg = XEXP (link, 0);
8776 if (REG_NOTE_KIND (link) == REG_DEAD && GET_CODE (reg) == REG)
8778 int regno = REGNO (reg);
8779 int n = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8780 for (; regno < n; regno++)
8781 reg_state[regno] &= ~REGSTATE_LIVE;
8786 free ((PTR) frv_state);
8787 dfa_finish ();
8788 return;
8792 #define def_builtin(name, type, code) \
8793 builtin_function ((name), (type), (code), BUILT_IN_MD, NULL, NULL)
8795 struct builtin_description
8797 enum insn_code icode;
8798 const char *name;
8799 enum frv_builtins code;
8800 enum rtx_code comparison;
8801 unsigned int flag;
8804 /* Media intrinsics that take a single, constant argument. */
8806 static struct builtin_description bdesc_set[] =
8808 { CODE_FOR_mhdsets, "__MHDSETS", FRV_BUILTIN_MHDSETS, 0, 0 }
8811 /* Media intrinsics that take just one argument. */
8813 static struct builtin_description bdesc_1arg[] =
8815 { CODE_FOR_mnot, "__MNOT", FRV_BUILTIN_MNOT, 0, 0 },
8816 { CODE_FOR_munpackh, "__MUNPACKH", FRV_BUILTIN_MUNPACKH, 0, 0 },
8817 { CODE_FOR_mbtoh, "__MBTOH", FRV_BUILTIN_MBTOH, 0, 0 },
8818 { CODE_FOR_mhtob, "__MHTOB", FRV_BUILTIN_MHTOB, 0, 0 },
8819 { CODE_FOR_mabshs, "__MABSHS", FRV_BUILTIN_MABSHS, 0, 0 }
8822 /* Media intrinsics that take two arguments. */
8824 static struct builtin_description bdesc_2arg[] =
8826 { CODE_FOR_mand, "__MAND", FRV_BUILTIN_MAND, 0, 0 },
8827 { CODE_FOR_mor, "__MOR", FRV_BUILTIN_MOR, 0, 0 },
8828 { CODE_FOR_mxor, "__MXOR", FRV_BUILTIN_MXOR, 0, 0 },
8829 { CODE_FOR_maveh, "__MAVEH", FRV_BUILTIN_MAVEH, 0, 0 },
8830 { CODE_FOR_msaths, "__MSATHS", FRV_BUILTIN_MSATHS, 0, 0 },
8831 { CODE_FOR_msathu, "__MSATHU", FRV_BUILTIN_MSATHU, 0, 0 },
8832 { CODE_FOR_maddhss, "__MADDHSS", FRV_BUILTIN_MADDHSS, 0, 0 },
8833 { CODE_FOR_maddhus, "__MADDHUS", FRV_BUILTIN_MADDHUS, 0, 0 },
8834 { CODE_FOR_msubhss, "__MSUBHSS", FRV_BUILTIN_MSUBHSS, 0, 0 },
8835 { CODE_FOR_msubhus, "__MSUBHUS", FRV_BUILTIN_MSUBHUS, 0, 0 },
8836 { CODE_FOR_mqaddhss, "__MQADDHSS", FRV_BUILTIN_MQADDHSS, 0, 0 },
8837 { CODE_FOR_mqaddhus, "__MQADDHUS", FRV_BUILTIN_MQADDHUS, 0, 0 },
8838 { CODE_FOR_mqsubhss, "__MQSUBHSS", FRV_BUILTIN_MQSUBHSS, 0, 0 },
8839 { CODE_FOR_mqsubhus, "__MQSUBHUS", FRV_BUILTIN_MQSUBHUS, 0, 0 },
8840 { CODE_FOR_mpackh, "__MPACKH", FRV_BUILTIN_MPACKH, 0, 0 },
8841 { CODE_FOR_mdpackh, "__MDPACKH", FRV_BUILTIN_MDPACKH, 0, 0 },
8842 { CODE_FOR_mcop1, "__Mcop1", FRV_BUILTIN_MCOP1, 0, 0 },
8843 { CODE_FOR_mcop2, "__Mcop2", FRV_BUILTIN_MCOP2, 0, 0 },
8844 { CODE_FOR_mwcut, "__MWCUT", FRV_BUILTIN_MWCUT, 0, 0 },
8845 { CODE_FOR_mqsaths, "__MQSATHS", FRV_BUILTIN_MQSATHS, 0, 0 }
8848 /* Media intrinsics that take two arguments, the first being an ACC number. */
8850 static struct builtin_description bdesc_cut[] =
8852 { CODE_FOR_mcut, "__MCUT", FRV_BUILTIN_MCUT, 0, 0 },
8853 { CODE_FOR_mcutss, "__MCUTSS", FRV_BUILTIN_MCUTSS, 0, 0 },
8854 { CODE_FOR_mdcutssi, "__MDCUTSSI", FRV_BUILTIN_MDCUTSSI, 0, 0 }
8857 /* Two-argument media intrinsics with an immediate second argument. */
8859 static struct builtin_description bdesc_2argimm[] =
8861 { CODE_FOR_mrotli, "__MROTLI", FRV_BUILTIN_MROTLI, 0, 0 },
8862 { CODE_FOR_mrotri, "__MROTRI", FRV_BUILTIN_MROTRI, 0, 0 },
8863 { CODE_FOR_msllhi, "__MSLLHI", FRV_BUILTIN_MSLLHI, 0, 0 },
8864 { CODE_FOR_msrlhi, "__MSRLHI", FRV_BUILTIN_MSRLHI, 0, 0 },
8865 { CODE_FOR_msrahi, "__MSRAHI", FRV_BUILTIN_MSRAHI, 0, 0 },
8866 { CODE_FOR_mexpdhw, "__MEXPDHW", FRV_BUILTIN_MEXPDHW, 0, 0 },
8867 { CODE_FOR_mexpdhd, "__MEXPDHD", FRV_BUILTIN_MEXPDHD, 0, 0 },
8868 { CODE_FOR_mdrotli, "__MDROTLI", FRV_BUILTIN_MDROTLI, 0, 0 },
8869 { CODE_FOR_mcplhi, "__MCPLHI", FRV_BUILTIN_MCPLHI, 0, 0 },
8870 { CODE_FOR_mcpli, "__MCPLI", FRV_BUILTIN_MCPLI, 0, 0 },
8871 { CODE_FOR_mhsetlos, "__MHSETLOS", FRV_BUILTIN_MHSETLOS, 0, 0 },
8872 { CODE_FOR_mhsetloh, "__MHSETLOH", FRV_BUILTIN_MHSETLOH, 0, 0 },
8873 { CODE_FOR_mhsethis, "__MHSETHIS", FRV_BUILTIN_MHSETHIS, 0, 0 },
8874 { CODE_FOR_mhsethih, "__MHSETHIH", FRV_BUILTIN_MHSETHIH, 0, 0 },
8875 { CODE_FOR_mhdseth, "__MHDSETH", FRV_BUILTIN_MHDSETH, 0, 0 }
8878 /* Media intrinsics that take two arguments and return void, the first argument
8879 being a pointer to 4 words in memory. */
8881 static struct builtin_description bdesc_void2arg[] =
8883 { CODE_FOR_mdunpackh, "__MDUNPACKH", FRV_BUILTIN_MDUNPACKH, 0, 0 },
8884 { CODE_FOR_mbtohe, "__MBTOHE", FRV_BUILTIN_MBTOHE, 0, 0 },
8887 /* Media intrinsics that take three arguments, the first being a const_int that
8888 denotes an accumulator, and that return void. */
8890 static struct builtin_description bdesc_void3arg[] =
8892 { CODE_FOR_mcpxrs, "__MCPXRS", FRV_BUILTIN_MCPXRS, 0, 0 },
8893 { CODE_FOR_mcpxru, "__MCPXRU", FRV_BUILTIN_MCPXRU, 0, 0 },
8894 { CODE_FOR_mcpxis, "__MCPXIS", FRV_BUILTIN_MCPXIS, 0, 0 },
8895 { CODE_FOR_mcpxiu, "__MCPXIU", FRV_BUILTIN_MCPXIU, 0, 0 },
8896 { CODE_FOR_mmulhs, "__MMULHS", FRV_BUILTIN_MMULHS, 0, 0 },
8897 { CODE_FOR_mmulhu, "__MMULHU", FRV_BUILTIN_MMULHU, 0, 0 },
8898 { CODE_FOR_mmulxhs, "__MMULXHS", FRV_BUILTIN_MMULXHS, 0, 0 },
8899 { CODE_FOR_mmulxhu, "__MMULXHU", FRV_BUILTIN_MMULXHU, 0, 0 },
8900 { CODE_FOR_mmachs, "__MMACHS", FRV_BUILTIN_MMACHS, 0, 0 },
8901 { CODE_FOR_mmachu, "__MMACHU", FRV_BUILTIN_MMACHU, 0, 0 },
8902 { CODE_FOR_mmrdhs, "__MMRDHS", FRV_BUILTIN_MMRDHS, 0, 0 },
8903 { CODE_FOR_mmrdhu, "__MMRDHU", FRV_BUILTIN_MMRDHU, 0, 0 },
8904 { CODE_FOR_mqcpxrs, "__MQCPXRS", FRV_BUILTIN_MQCPXRS, 0, 0 },
8905 { CODE_FOR_mqcpxru, "__MQCPXRU", FRV_BUILTIN_MQCPXRU, 0, 0 },
8906 { CODE_FOR_mqcpxis, "__MQCPXIS", FRV_BUILTIN_MQCPXIS, 0, 0 },
8907 { CODE_FOR_mqcpxiu, "__MQCPXIU", FRV_BUILTIN_MQCPXIU, 0, 0 },
8908 { CODE_FOR_mqmulhs, "__MQMULHS", FRV_BUILTIN_MQMULHS, 0, 0 },
8909 { CODE_FOR_mqmulhu, "__MQMULHU", FRV_BUILTIN_MQMULHU, 0, 0 },
8910 { CODE_FOR_mqmulxhs, "__MQMULXHS", FRV_BUILTIN_MQMULXHS, 0, 0 },
8911 { CODE_FOR_mqmulxhu, "__MQMULXHU", FRV_BUILTIN_MQMULXHU, 0, 0 },
8912 { CODE_FOR_mqmachs, "__MQMACHS", FRV_BUILTIN_MQMACHS, 0, 0 },
8913 { CODE_FOR_mqmachu, "__MQMACHU", FRV_BUILTIN_MQMACHU, 0, 0 },
8914 { CODE_FOR_mqxmachs, "__MQXMACHS", FRV_BUILTIN_MQXMACHS, 0, 0 },
8915 { CODE_FOR_mqxmacxhs, "__MQXMACXHS", FRV_BUILTIN_MQXMACXHS, 0, 0 },
8916 { CODE_FOR_mqmacxhs, "__MQMACXHS", FRV_BUILTIN_MQMACXHS, 0, 0 }
8919 /* Media intrinsics that take two accumulator numbers as argument and
8920 return void. */
8922 static struct builtin_description bdesc_voidacc[] =
8924 { CODE_FOR_maddaccs, "__MADDACCS", FRV_BUILTIN_MADDACCS, 0, 0 },
8925 { CODE_FOR_msubaccs, "__MSUBACCS", FRV_BUILTIN_MSUBACCS, 0, 0 },
8926 { CODE_FOR_masaccs, "__MASACCS", FRV_BUILTIN_MASACCS, 0, 0 },
8927 { CODE_FOR_mdaddaccs, "__MDADDACCS", FRV_BUILTIN_MDADDACCS, 0, 0 },
8928 { CODE_FOR_mdsubaccs, "__MDSUBACCS", FRV_BUILTIN_MDSUBACCS, 0, 0 },
8929 { CODE_FOR_mdasaccs, "__MDASACCS", FRV_BUILTIN_MDASACCS, 0, 0 }
8932 /* Initialize media builtins. */
8934 static void
8935 frv_init_builtins ()
8937 tree endlink = void_list_node;
8938 tree accumulator = integer_type_node;
8939 tree integer = integer_type_node;
8940 tree voidt = void_type_node;
8941 tree uhalf = short_unsigned_type_node;
8942 tree sword1 = long_integer_type_node;
8943 tree uword1 = long_unsigned_type_node;
8944 tree sword2 = long_long_integer_type_node;
8945 tree uword2 = long_long_unsigned_type_node;
8946 tree uword4 = build_pointer_type (uword1);
8948 #define UNARY(RET, T1) \
8949 build_function_type (RET, tree_cons (NULL_TREE, T1, endlink))
8951 #define BINARY(RET, T1, T2) \
8952 build_function_type (RET, tree_cons (NULL_TREE, T1, \
8953 tree_cons (NULL_TREE, T2, endlink)))
8955 #define TRINARY(RET, T1, T2, T3) \
8956 build_function_type (RET, tree_cons (NULL_TREE, T1, \
8957 tree_cons (NULL_TREE, T2, \
8958 tree_cons (NULL_TREE, T3, endlink))))
8960 tree void_ftype_void = build_function_type (voidt, endlink);
8962 tree void_ftype_acc = UNARY (voidt, accumulator);
8963 tree void_ftype_uw4_uw1 = BINARY (voidt, uword4, uword1);
8964 tree void_ftype_uw4_uw2 = BINARY (voidt, uword4, uword2);
8965 tree void_ftype_acc_uw1 = BINARY (voidt, accumulator, uword1);
8966 tree void_ftype_acc_acc = BINARY (voidt, accumulator, accumulator);
8967 tree void_ftype_acc_uw1_uw1 = TRINARY (voidt, accumulator, uword1, uword1);
8968 tree void_ftype_acc_sw1_sw1 = TRINARY (voidt, accumulator, sword1, sword1);
8969 tree void_ftype_acc_uw2_uw2 = TRINARY (voidt, accumulator, uword2, uword2);
8970 tree void_ftype_acc_sw2_sw2 = TRINARY (voidt, accumulator, sword2, sword2);
8972 tree uw1_ftype_uw1 = UNARY (uword1, uword1);
8973 tree uw1_ftype_sw1 = UNARY (uword1, sword1);
8974 tree uw1_ftype_uw2 = UNARY (uword1, uword2);
8975 tree uw1_ftype_acc = UNARY (uword1, accumulator);
8976 tree uw1_ftype_uh_uh = BINARY (uword1, uhalf, uhalf);
8977 tree uw1_ftype_uw1_uw1 = BINARY (uword1, uword1, uword1);
8978 tree uw1_ftype_uw1_int = BINARY (uword1, uword1, integer);
8979 tree uw1_ftype_acc_uw1 = BINARY (uword1, accumulator, uword1);
8980 tree uw1_ftype_acc_sw1 = BINARY (uword1, accumulator, sword1);
8981 tree uw1_ftype_uw2_uw1 = BINARY (uword1, uword2, uword1);
8982 tree uw1_ftype_uw2_int = BINARY (uword1, uword2, integer);
8984 tree sw1_ftype_int = UNARY (sword1, integer);
8985 tree sw1_ftype_sw1_sw1 = BINARY (sword1, sword1, sword1);
8986 tree sw1_ftype_sw1_int = BINARY (sword1, sword1, integer);
8988 tree uw2_ftype_uw1 = UNARY (uword2, uword1);
8989 tree uw2_ftype_uw1_int = BINARY (uword2, uword1, integer);
8990 tree uw2_ftype_uw2_uw2 = BINARY (uword2, uword2, uword2);
8991 tree uw2_ftype_uw2_int = BINARY (uword2, uword2, integer);
8992 tree uw2_ftype_acc_int = BINARY (uword2, accumulator, integer);
8994 tree sw2_ftype_sw2_sw2 = BINARY (sword2, sword2, sword2);
8996 def_builtin ("__MAND", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAND);
8997 def_builtin ("__MOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MOR);
8998 def_builtin ("__MXOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MXOR);
8999 def_builtin ("__MNOT", uw1_ftype_uw1, FRV_BUILTIN_MNOT);
9000 def_builtin ("__MROTLI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTLI);
9001 def_builtin ("__MROTRI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTRI);
9002 def_builtin ("__MWCUT", uw1_ftype_uw2_uw1, FRV_BUILTIN_MWCUT);
9003 def_builtin ("__MAVEH", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAVEH);
9004 def_builtin ("__MSLLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSLLHI);
9005 def_builtin ("__MSRLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSRLHI);
9006 def_builtin ("__MSRAHI", sw1_ftype_sw1_int, FRV_BUILTIN_MSRAHI);
9007 def_builtin ("__MSATHS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSATHS);
9008 def_builtin ("__MSATHU", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSATHU);
9009 def_builtin ("__MADDHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MADDHSS);
9010 def_builtin ("__MADDHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MADDHUS);
9011 def_builtin ("__MSUBHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSUBHSS);
9012 def_builtin ("__MSUBHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSUBHUS);
9013 def_builtin ("__MMULHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULHS);
9014 def_builtin ("__MMULHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULHU);
9015 def_builtin ("__MMULXHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULXHS);
9016 def_builtin ("__MMULXHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULXHU);
9017 def_builtin ("__MMACHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMACHS);
9018 def_builtin ("__MMACHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMACHU);
9019 def_builtin ("__MMRDHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMRDHS);
9020 def_builtin ("__MMRDHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMRDHU);
9021 def_builtin ("__MQADDHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQADDHSS);
9022 def_builtin ("__MQADDHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQADDHUS);
9023 def_builtin ("__MQSUBHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSUBHSS);
9024 def_builtin ("__MQSUBHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQSUBHUS);
9025 def_builtin ("__MQMULHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULHS);
9026 def_builtin ("__MQMULHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULHU);
9027 def_builtin ("__MQMULXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULXHS);
9028 def_builtin ("__MQMULXHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULXHU);
9029 def_builtin ("__MQMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACHS);
9030 def_builtin ("__MQMACHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMACHU);
9031 def_builtin ("__MCPXRS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXRS);
9032 def_builtin ("__MCPXRU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXRU);
9033 def_builtin ("__MCPXIS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXIS);
9034 def_builtin ("__MCPXIU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXIU);
9035 def_builtin ("__MQCPXRS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXRS);
9036 def_builtin ("__MQCPXRU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXRU);
9037 def_builtin ("__MQCPXIS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXIS);
9038 def_builtin ("__MQCPXIU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXIU);
9039 def_builtin ("__MCUT", uw1_ftype_acc_uw1, FRV_BUILTIN_MCUT);
9040 def_builtin ("__MCUTSS", uw1_ftype_acc_sw1, FRV_BUILTIN_MCUTSS);
9041 def_builtin ("__MEXPDHW", uw1_ftype_uw1_int, FRV_BUILTIN_MEXPDHW);
9042 def_builtin ("__MEXPDHD", uw2_ftype_uw1_int, FRV_BUILTIN_MEXPDHD);
9043 def_builtin ("__MPACKH", uw1_ftype_uh_uh, FRV_BUILTIN_MPACKH);
9044 def_builtin ("__MUNPACKH", uw2_ftype_uw1, FRV_BUILTIN_MUNPACKH);
9045 def_builtin ("__MDPACKH", uw2_ftype_uw2_uw2, FRV_BUILTIN_MDPACKH);
9046 def_builtin ("__MDUNPACKH", void_ftype_uw4_uw2, FRV_BUILTIN_MDUNPACKH);
9047 def_builtin ("__MBTOH", uw2_ftype_uw1, FRV_BUILTIN_MBTOH);
9048 def_builtin ("__MHTOB", uw1_ftype_uw2, FRV_BUILTIN_MHTOB);
9049 def_builtin ("__MBTOHE", void_ftype_uw4_uw1, FRV_BUILTIN_MBTOHE);
9050 def_builtin ("__MCLRACC", void_ftype_acc, FRV_BUILTIN_MCLRACC);
9051 def_builtin ("__MCLRACCA", void_ftype_void, FRV_BUILTIN_MCLRACCA);
9052 def_builtin ("__MRDACC", uw1_ftype_acc, FRV_BUILTIN_MRDACC);
9053 def_builtin ("__MRDACCG", uw1_ftype_acc, FRV_BUILTIN_MRDACCG);
9054 def_builtin ("__MWTACC", void_ftype_acc_uw1, FRV_BUILTIN_MWTACC);
9055 def_builtin ("__MWTACCG", void_ftype_acc_uw1, FRV_BUILTIN_MWTACCG);
9056 def_builtin ("__Mcop1", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP1);
9057 def_builtin ("__Mcop2", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP2);
9058 def_builtin ("__MTRAP", void_ftype_void, FRV_BUILTIN_MTRAP);
9059 def_builtin ("__MQXMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACHS);
9060 def_builtin ("__MQXMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACXHS);
9061 def_builtin ("__MQMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACXHS);
9062 def_builtin ("__MADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MADDACCS);
9063 def_builtin ("__MSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MSUBACCS);
9064 def_builtin ("__MASACCS", void_ftype_acc_acc, FRV_BUILTIN_MASACCS);
9065 def_builtin ("__MDADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MDADDACCS);
9066 def_builtin ("__MDSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MDSUBACCS);
9067 def_builtin ("__MDASACCS", void_ftype_acc_acc, FRV_BUILTIN_MDASACCS);
9068 def_builtin ("__MABSHS", uw1_ftype_sw1, FRV_BUILTIN_MABSHS);
9069 def_builtin ("__MDROTLI", uw2_ftype_uw2_int, FRV_BUILTIN_MDROTLI);
9070 def_builtin ("__MCPLHI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLHI);
9071 def_builtin ("__MCPLI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLI);
9072 def_builtin ("__MDCUTSSI", uw2_ftype_acc_int, FRV_BUILTIN_MDCUTSSI);
9073 def_builtin ("__MQSATHS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSATHS);
9074 def_builtin ("__MHSETLOS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETLOS);
9075 def_builtin ("__MHSETHIS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETHIS);
9076 def_builtin ("__MHDSETS", sw1_ftype_int, FRV_BUILTIN_MHDSETS);
9077 def_builtin ("__MHSETLOH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETLOH);
9078 def_builtin ("__MHSETHIH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETHIH);
9079 def_builtin ("__MHDSETH", uw1_ftype_uw1_int, FRV_BUILTIN_MHDSETH);
9081 #undef UNARY
9082 #undef BINARY
9083 #undef TRINARY
9086 /* Convert an integer constant to an accumulator register. ICODE is the
9087 code of the target instruction, OPNUM is the number of the
9088 accumulator operand and OPVAL is the constant integer. Try both
9089 ACC and ACCG registers; only report an error if neither fit the
9090 instruction. */
9092 static rtx
9093 frv_int_to_acc (icode, opnum, opval)
9094 enum insn_code icode;
9095 int opnum;
9096 rtx opval;
9098 rtx reg;
9100 if (GET_CODE (opval) != CONST_INT)
9102 error ("accumulator is not a constant integer");
9103 return NULL_RTX;
9105 if (! IN_RANGE_P (INTVAL (opval), 0, NUM_ACCS - 1))
9107 error ("accumulator number is out of bounds");
9108 return NULL_RTX;
9111 reg = gen_rtx_REG (insn_data[icode].operand[opnum].mode,
9112 ACC_FIRST + INTVAL (opval));
9113 if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode))
9114 REGNO (reg) = ACCG_FIRST + INTVAL (opval);
9116 if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode))
9118 error ("inappropriate accumulator for `%s'", insn_data[icode].name);
9119 return NULL_RTX;
9121 return reg;
9124 /* If an ACC rtx has mode MODE, return the mode that the matching ACCG
9125 should have. */
9127 static enum machine_mode
9128 frv_matching_accg_mode (mode)
9129 enum machine_mode mode;
9131 switch (mode)
9133 case V4SImode:
9134 return V4QImode;
9136 case DImode:
9137 return HImode;
9139 case SImode:
9140 return QImode;
9142 default:
9143 abort ();
9147 /* Return the accumulator guard that should be paired with accumulator
9148 register ACC. The mode of the returned register is in the same
9149 class as ACC, but is four times smaller. */
9152 frv_matching_accg_for_acc (acc)
9153 rtx acc;
9155 return gen_rtx_REG (frv_matching_accg_mode (GET_MODE (acc)),
9156 REGNO (acc) - ACC_FIRST + ACCG_FIRST);
9159 /* Read a value from the head of the tree list pointed to by ARGLISTPTR.
9160 Return the value as an rtx and replace *ARGLISTPTR with the tail of the
9161 list. */
9163 static rtx
9164 frv_read_argument (arglistptr)
9165 tree *arglistptr;
9167 tree next = TREE_VALUE (*arglistptr);
9168 *arglistptr = TREE_CHAIN (*arglistptr);
9169 return expand_expr (next, NULL_RTX, VOIDmode, 0);
9172 /* Return true if OPVAL can be used for operand OPNUM of instruction ICODE.
9173 The instruction should require a constant operand of some sort. The
9174 function prints an error if OPVAL is not valid. */
9176 static int
9177 frv_check_constant_argument (icode, opnum, opval)
9178 enum insn_code icode;
9179 int opnum;
9180 rtx opval;
9182 if (GET_CODE (opval) != CONST_INT)
9184 error ("`%s' expects a constant argument", insn_data[icode].name);
9185 return FALSE;
9187 if (! (*insn_data[icode].operand[opnum].predicate) (opval, VOIDmode))
9189 error ("constant argument out of range for `%s'", insn_data[icode].name);
9190 return FALSE;
9192 return TRUE;
9195 /* Return a legitimate rtx for instruction ICODE's return value. Use TARGET
9196 if it's not null, has the right mode, and satisfies operand 0's
9197 predicate. */
9199 static rtx
9200 frv_legitimize_target (icode, target)
9201 enum insn_code icode;
9202 rtx target;
9204 enum machine_mode mode = insn_data[icode].operand[0].mode;
9206 if (! target
9207 || GET_MODE (target) != mode
9208 || ! (*insn_data[icode].operand[0].predicate) (target, mode))
9209 return gen_reg_rtx (mode);
9210 else
9211 return target;
9214 /* Given that ARG is being passed as operand OPNUM to instruction ICODE,
9215 check whether ARG satisfies the operand's contraints. If it doesn't,
9216 copy ARG to a temporary register and return that. Otherwise return ARG
9217 itself. */
9219 static rtx
9220 frv_legitimize_argument (icode, opnum, arg)
9221 enum insn_code icode;
9222 int opnum;
9223 rtx arg;
9225 enum machine_mode mode = insn_data[icode].operand[opnum].mode;
9227 if ((*insn_data[icode].operand[opnum].predicate) (arg, mode))
9228 return arg;
9229 else
9230 return copy_to_mode_reg (mode, arg);
9233 /* Expand builtins that take a single, constant argument. At the moment,
9234 only MHDSETS falls into this category. */
9236 static rtx
9237 frv_expand_set_builtin (icode, arglist, target)
9238 enum insn_code icode;
9239 tree arglist;
9240 rtx target;
9242 rtx pat;
9243 rtx op0 = frv_read_argument (&arglist);
9245 if (! frv_check_constant_argument (icode, 1, op0))
9246 return NULL_RTX;
9248 target = frv_legitimize_target (icode, target);
9249 pat = GEN_FCN (icode) (target, op0);
9250 if (! pat)
9251 return NULL_RTX;
9253 emit_insn (pat);
9254 return target;
9257 /* Expand builtins that take one operand. */
9259 static rtx
9260 frv_expand_unop_builtin (icode, arglist, target)
9261 enum insn_code icode;
9262 tree arglist;
9263 rtx target;
9265 rtx pat;
9266 rtx op0 = frv_read_argument (&arglist);
9268 target = frv_legitimize_target (icode, target);
9269 op0 = frv_legitimize_argument (icode, 1, op0);
9270 pat = GEN_FCN (icode) (target, op0);
9271 if (! pat)
9272 return NULL_RTX;
9274 emit_insn (pat);
9275 return target;
9278 /* Expand builtins that take two operands. */
9280 static rtx
9281 frv_expand_binop_builtin (icode, arglist, target)
9282 enum insn_code icode;
9283 tree arglist;
9284 rtx target;
9286 rtx pat;
9287 rtx op0 = frv_read_argument (&arglist);
9288 rtx op1 = frv_read_argument (&arglist);
9290 target = frv_legitimize_target (icode, target);
9291 op0 = frv_legitimize_argument (icode, 1, op0);
9292 op1 = frv_legitimize_argument (icode, 2, op1);
9293 pat = GEN_FCN (icode) (target, op0, op1);
9294 if (! pat)
9295 return NULL_RTX;
9297 emit_insn (pat);
9298 return target;
9301 /* Expand cut-style builtins, which take two operands and an implicit ACCG
9302 one. */
9304 static rtx
9305 frv_expand_cut_builtin (icode, arglist, target)
9306 enum insn_code icode;
9307 tree arglist;
9308 rtx target;
9310 rtx pat;
9311 rtx op0 = frv_read_argument (&arglist);
9312 rtx op1 = frv_read_argument (&arglist);
9313 rtx op2;
9315 target = frv_legitimize_target (icode, target);
9316 op0 = frv_int_to_acc (icode, 1, op0);
9317 if (! op0)
9318 return NULL_RTX;
9320 if (icode == CODE_FOR_mdcutssi || GET_CODE (op1) == CONST_INT)
9322 if (! frv_check_constant_argument (icode, 2, op1))
9323 return NULL_RTX;
9325 else
9326 op1 = frv_legitimize_argument (icode, 2, op1);
9328 op2 = frv_matching_accg_for_acc (op0);
9329 pat = GEN_FCN (icode) (target, op0, op1, op2);
9330 if (! pat)
9331 return NULL_RTX;
9333 emit_insn (pat);
9334 return target;
9337 /* Expand builtins that take two operands and the second is immediate. */
9339 static rtx
9340 frv_expand_binopimm_builtin (icode, arglist, target)
9341 enum insn_code icode;
9342 tree arglist;
9343 rtx target;
9345 rtx pat;
9346 rtx op0 = frv_read_argument (&arglist);
9347 rtx op1 = frv_read_argument (&arglist);
9349 if (! frv_check_constant_argument (icode, 2, op1))
9350 return NULL_RTX;
9352 target = frv_legitimize_target (icode, target);
9353 op0 = frv_legitimize_argument (icode, 1, op0);
9354 pat = GEN_FCN (icode) (target, op0, op1);
9355 if (! pat)
9356 return NULL_RTX;
9358 emit_insn (pat);
9359 return target;
9362 /* Expand builtins that take two operands, the first operand being a pointer to
9363 ints and return void. */
9365 static rtx
9366 frv_expand_voidbinop_builtin (icode, arglist)
9367 enum insn_code icode;
9368 tree arglist;
9370 rtx pat;
9371 rtx op0 = frv_read_argument (&arglist);
9372 rtx op1 = frv_read_argument (&arglist);
9373 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
9374 rtx addr;
9376 if (GET_CODE (op0) != MEM)
9378 rtx reg = op0;
9380 if (! offsettable_address_p (0, mode0, op0))
9382 reg = gen_reg_rtx (Pmode);
9383 emit_insn (gen_rtx_SET (VOIDmode, reg, op0));
9386 op0 = gen_rtx_MEM (SImode, reg);
9389 addr = XEXP (op0, 0);
9390 if (! offsettable_address_p (0, mode0, addr))
9391 addr = copy_to_mode_reg (Pmode, op0);
9393 op0 = change_address (op0, V4SImode, addr);
9394 op1 = frv_legitimize_argument (icode, 1, op1);
9395 pat = GEN_FCN (icode) (op0, op1);
9396 if (! pat)
9397 return 0;
9399 emit_insn (pat);
9400 return 0;
9403 /* Expand builtins that take three operands and return void. The first
9404 argument must be a constant that describes a pair or quad accumulators. A
9405 fourth argument is created that is the accumulator guard register that
9406 corresponds to the accumulator. */
9408 static rtx
9409 frv_expand_voidtriop_builtin (icode, arglist)
9410 enum insn_code icode;
9411 tree arglist;
9413 rtx pat;
9414 rtx op0 = frv_read_argument (&arglist);
9415 rtx op1 = frv_read_argument (&arglist);
9416 rtx op2 = frv_read_argument (&arglist);
9417 rtx op3;
9419 op0 = frv_int_to_acc (icode, 0, op0);
9420 if (! op0)
9421 return NULL_RTX;
9423 op1 = frv_legitimize_argument (icode, 1, op1);
9424 op2 = frv_legitimize_argument (icode, 2, op2);
9425 op3 = frv_matching_accg_for_acc (op0);
9426 pat = GEN_FCN (icode) (op0, op1, op2, op3);
9427 if (! pat)
9428 return NULL_RTX;
9430 emit_insn (pat);
9431 return NULL_RTX;
9434 /* Expand builtins that perform accumulator-to-accumulator operations.
9435 These builtins take two accumulator numbers as argument and return
9436 void. */
9438 static rtx
9439 frv_expand_voidaccop_builtin (icode, arglist)
9440 enum insn_code icode;
9441 tree arglist;
9443 rtx pat;
9444 rtx op0 = frv_read_argument (&arglist);
9445 rtx op1 = frv_read_argument (&arglist);
9446 rtx op2;
9447 rtx op3;
9449 op0 = frv_int_to_acc (icode, 0, op0);
9450 if (! op0)
9451 return NULL_RTX;
9453 op1 = frv_int_to_acc (icode, 1, op1);
9454 if (! op1)
9455 return NULL_RTX;
9457 op2 = frv_matching_accg_for_acc (op0);
9458 op3 = frv_matching_accg_for_acc (op1);
9459 pat = GEN_FCN (icode) (op0, op1, op2, op3);
9460 if (! pat)
9461 return NULL_RTX;
9463 emit_insn (pat);
9464 return NULL_RTX;
9467 /* Expand the MCLRACC builtin. This builtin takes a single accumulator
9468 number as argument. */
9470 static rtx
9471 frv_expand_mclracc_builtin (arglist)
9472 tree arglist;
9474 enum insn_code icode = CODE_FOR_mclracc;
9475 rtx pat;
9476 rtx op0 = frv_read_argument (&arglist);
9478 op0 = frv_int_to_acc (icode, 0, op0);
9479 if (! op0)
9480 return NULL_RTX;
9482 pat = GEN_FCN (icode) (op0);
9483 if (pat)
9484 emit_insn (pat);
9486 return NULL_RTX;
9489 /* Expand builtins that take no arguments. */
9491 static rtx
9492 frv_expand_noargs_builtin (icode)
9493 enum insn_code icode;
9495 rtx pat = GEN_FCN (icode) (GEN_INT (0));
9496 if (pat)
9497 emit_insn (pat);
9499 return NULL_RTX;
9502 /* Expand MRDACC and MRDACCG. These builtins take a single accumulator
9503 number or accumulator guard number as argument and return an SI integer. */
9505 static rtx
9506 frv_expand_mrdacc_builtin (icode, arglist)
9507 enum insn_code icode;
9508 tree arglist;
9510 rtx pat;
9511 rtx target = gen_reg_rtx (SImode);
9512 rtx op0 = frv_read_argument (&arglist);
9514 op0 = frv_int_to_acc (icode, 1, op0);
9515 if (! op0)
9516 return NULL_RTX;
9518 pat = GEN_FCN (icode) (target, op0);
9519 if (! pat)
9520 return NULL_RTX;
9522 emit_insn (pat);
9523 return target;
9526 /* Expand MWTACC and MWTACCG. These builtins take an accumulator or
9527 accumulator guard as their first argument and an SImode value as their
9528 second. */
9530 static rtx
9531 frv_expand_mwtacc_builtin (icode, arglist)
9532 enum insn_code icode;
9533 tree arglist;
9535 rtx pat;
9536 rtx op0 = frv_read_argument (&arglist);
9537 rtx op1 = frv_read_argument (&arglist);
9539 op0 = frv_int_to_acc (icode, 0, op0);
9540 if (! op0)
9541 return NULL_RTX;
9543 op1 = frv_legitimize_argument (icode, 1, op1);
9544 pat = GEN_FCN (icode) (op0, op1);
9545 if (pat)
9546 emit_insn (pat);
9548 return NULL_RTX;
9551 /* Expand builtins. */
9553 static rtx
9554 frv_expand_builtin (exp, target, subtarget, mode, ignore)
9555 tree exp;
9556 rtx target;
9557 rtx subtarget ATTRIBUTE_UNUSED;
9558 enum machine_mode mode ATTRIBUTE_UNUSED;
9559 int ignore ATTRIBUTE_UNUSED;
9561 tree arglist = TREE_OPERAND (exp, 1);
9562 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
9563 unsigned fcode = (unsigned)DECL_FUNCTION_CODE (fndecl);
9564 unsigned i;
9565 struct builtin_description *d;
9567 if (! TARGET_MEDIA)
9569 error ("media functions are not available unless -mmedia is used");
9570 return NULL_RTX;
9573 switch (fcode)
9575 case FRV_BUILTIN_MCOP1:
9576 case FRV_BUILTIN_MCOP2:
9577 case FRV_BUILTIN_MDUNPACKH:
9578 case FRV_BUILTIN_MBTOHE:
9579 if (! TARGET_MEDIA_REV1)
9581 error ("this media function is only available on the fr500");
9582 return NULL_RTX;
9584 break;
9586 case FRV_BUILTIN_MQXMACHS:
9587 case FRV_BUILTIN_MQXMACXHS:
9588 case FRV_BUILTIN_MQMACXHS:
9589 case FRV_BUILTIN_MADDACCS:
9590 case FRV_BUILTIN_MSUBACCS:
9591 case FRV_BUILTIN_MASACCS:
9592 case FRV_BUILTIN_MDADDACCS:
9593 case FRV_BUILTIN_MDSUBACCS:
9594 case FRV_BUILTIN_MDASACCS:
9595 case FRV_BUILTIN_MABSHS:
9596 case FRV_BUILTIN_MDROTLI:
9597 case FRV_BUILTIN_MCPLHI:
9598 case FRV_BUILTIN_MCPLI:
9599 case FRV_BUILTIN_MDCUTSSI:
9600 case FRV_BUILTIN_MQSATHS:
9601 case FRV_BUILTIN_MHSETLOS:
9602 case FRV_BUILTIN_MHSETLOH:
9603 case FRV_BUILTIN_MHSETHIS:
9604 case FRV_BUILTIN_MHSETHIH:
9605 case FRV_BUILTIN_MHDSETS:
9606 case FRV_BUILTIN_MHDSETH:
9607 if (! TARGET_MEDIA_REV2)
9609 error ("this media function is only available on the fr400");
9610 return NULL_RTX;
9612 break;
9614 default:
9615 break;
9618 /* Expand unique builtins. */
9620 switch (fcode)
9622 case FRV_BUILTIN_MTRAP:
9623 return frv_expand_noargs_builtin (CODE_FOR_mtrap);
9625 case FRV_BUILTIN_MCLRACC:
9626 return frv_expand_mclracc_builtin (arglist);
9628 case FRV_BUILTIN_MCLRACCA:
9629 if (TARGET_ACC_8)
9630 return frv_expand_noargs_builtin (CODE_FOR_mclracca8);
9631 else
9632 return frv_expand_noargs_builtin (CODE_FOR_mclracca4);
9634 case FRV_BUILTIN_MRDACC:
9635 return frv_expand_mrdacc_builtin (CODE_FOR_mrdacc, arglist);
9637 case FRV_BUILTIN_MRDACCG:
9638 return frv_expand_mrdacc_builtin (CODE_FOR_mrdaccg, arglist);
9640 case FRV_BUILTIN_MWTACC:
9641 return frv_expand_mwtacc_builtin (CODE_FOR_mwtacc, arglist);
9643 case FRV_BUILTIN_MWTACCG:
9644 return frv_expand_mwtacc_builtin (CODE_FOR_mwtaccg, arglist);
9646 default:
9647 break;
9650 /* Expand groups of builtins. */
9652 for (i = 0, d = bdesc_set; i < sizeof (bdesc_set) / sizeof *d; i++, d++)
9653 if (d->code == fcode)
9654 return frv_expand_set_builtin (d->icode, arglist, target);
9656 for (i = 0, d = bdesc_1arg; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
9657 if (d->code == fcode)
9658 return frv_expand_unop_builtin (d->icode, arglist, target);
9660 for (i = 0, d = bdesc_2arg; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
9661 if (d->code == fcode)
9662 return frv_expand_binop_builtin (d->icode, arglist, target);
9664 for (i = 0, d = bdesc_cut; i < sizeof (bdesc_cut) / sizeof *d; i++, d++)
9665 if (d->code == fcode)
9666 return frv_expand_cut_builtin (d->icode, arglist, target);
9668 for (i = 0, d = bdesc_2argimm;
9669 i < sizeof (bdesc_2argimm) / sizeof *d;
9670 i++, d++)
9672 if (d->code == fcode)
9673 return frv_expand_binopimm_builtin (d->icode, arglist, target);
9676 for (i = 0, d = bdesc_void2arg;
9677 i < sizeof (bdesc_void2arg) / sizeof *d;
9678 i++, d++)
9680 if (d->code == fcode)
9681 return frv_expand_voidbinop_builtin (d->icode, arglist);
9684 for (i = 0, d = bdesc_void3arg;
9685 i < sizeof (bdesc_void3arg) / sizeof *d;
9686 i++, d++)
9688 if (d->code == fcode)
9689 return frv_expand_voidtriop_builtin (d->icode, arglist);
9692 for (i = 0, d = bdesc_voidacc;
9693 i < sizeof (bdesc_voidacc) / sizeof *d;
9694 i++, d++)
9696 if (d->code == fcode)
9697 return frv_expand_voidaccop_builtin (d->icode, arglist);
9699 return 0;
9702 static bool
9703 frv_in_small_data_p (decl)
9704 tree decl;
9706 HOST_WIDE_INT size;
9707 tree section_name;
9709 /* Don't apply the -G flag to internal compiler structures. We
9710 should leave such structures in the main data section, partly
9711 for efficiency and partly because the size of some of them
9712 (such as C++ typeinfos) is not known until later. */
9713 if (TREE_CODE (decl) != VAR_DECL || DECL_ARTIFICIAL (decl))
9714 return false;
9716 size = int_size_in_bytes (TREE_TYPE (decl));
9717 if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
9718 return true;
9720 /* If we already know which section the decl should be in, see if
9721 it's a small data section. */
9722 section_name = DECL_SECTION_NAME (decl);
9723 if (section_name)
9725 if (TREE_CODE (section_name) != STRING_CST)
9726 abort ();
9727 if (frv_string_begins_with (section_name, ".sdata"))
9728 return true;
9729 if (frv_string_begins_with (section_name, ".sbss"))
9730 return true;
9733 return false;
9736 static bool
9737 frv_rtx_costs (x, code, outer_code, total)
9738 rtx x;
9739 int code, outer_code ATTRIBUTE_UNUSED;
9740 int *total;
9742 switch (code)
9744 case CONST_INT:
9745 /* Make 12 bit integers really cheap. */
9746 if (IN_RANGE_P (INTVAL (x), -2048, 2047))
9748 *total = 0;
9749 return true;
9751 /* FALLTHRU */
9753 case CONST:
9754 case LABEL_REF:
9755 case SYMBOL_REF:
9756 case CONST_DOUBLE:
9757 *total = COSTS_N_INSNS (2);
9758 return true;
9760 case PLUS:
9761 case MINUS:
9762 case AND:
9763 case IOR:
9764 case XOR:
9765 case ASHIFT:
9766 case ASHIFTRT:
9767 case LSHIFTRT:
9768 case NOT:
9769 case NEG:
9770 case COMPARE:
9771 if (GET_MODE (x) == SImode)
9772 *total = COSTS_N_INSNS (1);
9773 else if (GET_MODE (x) == DImode)
9774 *total = COSTS_N_INSNS (2);
9775 else
9776 *total = COSTS_N_INSNS (3);
9777 return true;
9779 case MULT:
9780 if (GET_MODE (x) == SImode)
9781 *total = COSTS_N_INSNS (2);
9782 else
9783 *total = COSTS_N_INSNS (6); /* guess */
9784 return true;
9786 case DIV:
9787 case UDIV:
9788 case MOD:
9789 case UMOD:
9790 *total = COSTS_N_INSNS (18);
9791 return true;
9793 default:
9794 return false;
9798 static void
9799 frv_asm_out_constructor (symbol, priority)
9800 rtx symbol;
9801 int priority ATTRIBUTE_UNUSED;
9803 ctors_section ();
9804 assemble_align (POINTER_SIZE);
9805 assemble_integer_with_op ("\t.picptr\t", symbol);
9808 static void
9809 frv_asm_out_destructor (symbol, priority)
9810 rtx symbol;
9811 int priority ATTRIBUTE_UNUSED;
9813 dtors_section ();
9814 assemble_align (POINTER_SIZE);
9815 assemble_integer_with_op ("\t.picptr\t", symbol);