* Makefile.in (cse.o): Depend on TARGET_H.
[official-gcc.git] / gcc / config / frv / frv.c
blob1c8f56686719c3bd23e0e1ee71d5d99faeb4073c
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 symbol_ref_small_data_p PARAMS ((rtx));
202 static FRV_INLINE int const_small_data_p PARAMS ((rtx));
203 static FRV_INLINE int plus_small_data_p PARAMS ((rtx, rtx));
204 static void frv_print_operand_memory_reference_reg
205 PARAMS ((FILE *, rtx));
206 static void frv_print_operand_memory_reference PARAMS ((FILE *, rtx, int));
207 static int frv_print_operand_jump_hint PARAMS ((rtx));
208 static FRV_INLINE int frv_regno_ok_for_base_p PARAMS ((int, int));
209 static rtx single_set_pattern PARAMS ((rtx));
210 static int frv_function_contains_far_jump PARAMS ((void));
211 static rtx frv_alloc_temp_reg PARAMS ((frv_tmp_reg_t *,
212 enum reg_class,
213 enum machine_mode,
214 int, int));
215 static rtx frv_frame_offset_rtx PARAMS ((int));
216 static rtx frv_frame_mem PARAMS ((enum machine_mode,
217 rtx, int));
218 static rtx frv_dwarf_store PARAMS ((rtx, int));
219 static void frv_frame_insn PARAMS ((rtx, rtx));
220 static void frv_frame_access PARAMS ((frv_frame_accessor_t*,
221 rtx, int));
222 static void frv_frame_access_multi PARAMS ((frv_frame_accessor_t*,
223 frv_stack_t *, int));
224 static void frv_frame_access_standard_regs PARAMS ((enum frv_stack_op,
225 frv_stack_t *));
226 static struct machine_function *frv_init_machine_status PARAMS ((void));
227 static int frv_legitimate_memory_operand PARAMS ((rtx,
228 enum machine_mode,
229 int));
230 static rtx frv_int_to_acc PARAMS ((enum insn_code,
231 int, rtx));
232 static enum machine_mode frv_matching_accg_mode PARAMS ((enum machine_mode));
233 static rtx frv_read_argument PARAMS ((tree *));
234 static int frv_check_constant_argument PARAMS ((enum insn_code,
235 int, rtx));
236 static rtx frv_legitimize_target PARAMS ((enum insn_code, rtx));
237 static rtx frv_legitimize_argument PARAMS ((enum insn_code,
238 int, rtx));
239 static rtx frv_expand_set_builtin PARAMS ((enum insn_code,
240 tree, rtx));
241 static rtx frv_expand_unop_builtin PARAMS ((enum insn_code,
242 tree, rtx));
243 static rtx frv_expand_binop_builtin PARAMS ((enum insn_code,
244 tree, rtx));
245 static rtx frv_expand_cut_builtin PARAMS ((enum insn_code,
246 tree, rtx));
247 static rtx frv_expand_binopimm_builtin PARAMS ((enum insn_code,
248 tree, rtx));
249 static rtx frv_expand_voidbinop_builtin PARAMS ((enum insn_code,
250 tree));
251 static rtx frv_expand_voidtriop_builtin PARAMS ((enum insn_code,
252 tree));
253 static rtx frv_expand_voidaccop_builtin PARAMS ((enum insn_code,
254 tree));
255 static rtx frv_expand_mclracc_builtin PARAMS ((tree));
256 static rtx frv_expand_mrdacc_builtin PARAMS ((enum insn_code,
257 tree));
258 static rtx frv_expand_mwtacc_builtin PARAMS ((enum insn_code,
259 tree));
260 static rtx frv_expand_noargs_builtin PARAMS ((enum insn_code));
261 static rtx frv_emit_comparison PARAMS ((enum rtx_code, rtx,
262 rtx));
263 static int frv_clear_registers_used PARAMS ((rtx *, void *));
264 static void frv_ifcvt_add_insn PARAMS ((rtx, rtx, int));
265 static rtx frv_ifcvt_rewrite_mem PARAMS ((rtx,
266 enum machine_mode,
267 rtx));
268 static rtx frv_ifcvt_load_value PARAMS ((rtx, rtx));
269 static void frv_registers_update PARAMS ((rtx, unsigned char [],
270 int [], int *, int));
271 static int frv_registers_used_p PARAMS ((rtx, unsigned char [],
272 int));
273 static int frv_registers_set_p PARAMS ((rtx, unsigned char [],
274 int));
275 static void frv_pack_insns PARAMS ((void));
276 static void frv_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
277 static void frv_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
278 static bool frv_assemble_integer PARAMS ((rtx, unsigned, int));
279 static const char * frv_strip_name_encoding PARAMS ((const char *));
280 static void frv_encode_section_info PARAMS ((tree, int));
281 static void frv_init_builtins PARAMS ((void));
282 static rtx frv_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
283 static bool frv_in_small_data_p PARAMS ((tree));
284 static void frv_asm_output_mi_thunk
285 PARAMS ((FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree));
286 static bool frv_rtx_costs PARAMS ((rtx, int, int, int*));
288 /* Initialize the GCC target structure. */
289 #undef TARGET_ASM_FUNCTION_PROLOGUE
290 #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue
291 #undef TARGET_ASM_FUNCTION_EPILOGUE
292 #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue
293 #undef TARGET_ASM_INTEGER
294 #define TARGET_ASM_INTEGER frv_assemble_integer
295 #undef TARGET_STRIP_NAME_ENCODING
296 #define TARGET_STRIP_NAME_ENCODING frv_strip_name_encoding
297 #undef TARGET_ENCODE_SECTION_INFO
298 #define TARGET_ENCODE_SECTION_INFO frv_encode_section_info
299 #undef TARGET_INIT_BUILTINS
300 #define TARGET_INIT_BUILTINS frv_init_builtins
301 #undef TARGET_EXPAND_BUILTIN
302 #define TARGET_EXPAND_BUILTIN frv_expand_builtin
303 #undef TARGET_IN_SMALL_DATA_P
304 #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p
305 #undef TARGET_RTX_COSTS
306 #define TARGET_RTX_COSTS frv_rtx_costs
308 #undef TARGET_ASM_OUTPUT_MI_THUNK
309 #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk
310 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
311 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
313 struct gcc_target targetm = TARGET_INITIALIZER;
315 /* Given a SYMBOL_REF, return true if it points to small data. */
317 static FRV_INLINE int
318 symbol_ref_small_data_p (x)
319 rtx x;
321 return SDATA_NAME_P (XSTR (x, 0));
324 /* Given a CONST, return true if the symbol_ref points to small data. */
326 static FRV_INLINE int
327 const_small_data_p (x)
328 rtx x;
330 rtx x0, x1;
332 if (GET_CODE (XEXP (x, 0)) != PLUS)
333 return FALSE;
335 x0 = XEXP (XEXP (x, 0), 0);
336 if (GET_CODE (x0) != SYMBOL_REF || !SDATA_NAME_P (XSTR (x0, 0)))
337 return FALSE;
339 x1 = XEXP (XEXP (x, 0), 1);
340 if (GET_CODE (x1) != CONST_INT
341 || !IN_RANGE_P (INTVAL (x1), -2048, 2047))
342 return FALSE;
344 return TRUE;
347 /* Given a PLUS, return true if this is a small data reference. */
349 static FRV_INLINE int
350 plus_small_data_p (op0, op1)
351 rtx op0;
352 rtx op1;
354 if (GET_MODE (op0) == SImode
355 && GET_CODE (op0) == REG
356 && REGNO (op0) == SDA_BASE_REG)
358 if (GET_CODE (op1) == SYMBOL_REF)
359 return symbol_ref_small_data_p (op1);
361 if (GET_CODE (op1) == CONST)
362 return const_small_data_p (op1);
365 return FALSE;
369 static int
370 frv_default_flags_for_cpu ()
372 switch (frv_cpu_type)
374 case FRV_CPU_GENERIC:
375 return MASK_DEFAULT_FRV;
377 case FRV_CPU_FR500:
378 case FRV_CPU_TOMCAT:
379 return MASK_DEFAULT_FR500;
381 case FRV_CPU_FR400:
382 return MASK_DEFAULT_FR400;
384 case FRV_CPU_FR300:
385 case FRV_CPU_SIMPLE:
386 return MASK_DEFAULT_SIMPLE;
388 abort ();
391 /* Sometimes certain combinations of command options do not make
392 sense on a particular target machine. You can define a macro
393 `OVERRIDE_OPTIONS' to take account of this. This macro, if
394 defined, is executed once just after all the command options have
395 been parsed.
397 Don't use this macro to turn on various extra optimizations for
398 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
400 void
401 frv_override_options ()
403 int regno, i;
405 /* Set the cpu type */
406 if (frv_cpu_string)
408 if (strcmp (frv_cpu_string, "simple") == 0)
409 frv_cpu_type = FRV_CPU_SIMPLE;
411 else if (strcmp (frv_cpu_string, "tomcat") == 0)
412 frv_cpu_type = FRV_CPU_TOMCAT;
414 else if (strncmp (frv_cpu_string, "fr", sizeof ("fr")-1) != 0)
415 error ("Unknown cpu: -mcpu=%s", frv_cpu_string);
417 else
419 const char *p = frv_cpu_string + sizeof ("fr") - 1;
420 if (strcmp (p, "500") == 0)
421 frv_cpu_type = FRV_CPU_FR500;
423 else if (strcmp (p, "400") == 0)
424 frv_cpu_type = FRV_CPU_FR400;
426 else if (strcmp (p, "300") == 0)
427 frv_cpu_type = FRV_CPU_FR300;
429 else if (strcmp (p, "v") == 0)
430 frv_cpu_type = FRV_CPU_GENERIC;
432 else
433 error ("Unknown cpu: -mcpu=%s", frv_cpu_string);
437 target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit);
439 /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the
440 linker about linking pic and non-pic code. */
441 if (TARGET_LIBPIC)
443 if (!flag_pic) /* -fPIC */
444 flag_pic = 2;
446 if (! g_switch_set) /* -G0 */
448 g_switch_set = 1;
449 g_switch_value = 0;
453 /* Both -fpic and -gdwarf want to use .previous and the assembler only keeps
454 one level. */
455 if (write_symbols == DWARF_DEBUG && flag_pic)
456 error ("-fpic and -gdwarf are incompatible (-fpic and -g/-gdwarf-2 are fine)");
458 /* Change the branch cost value */
459 if (frv_branch_cost_string)
460 frv_branch_cost_int = atoi (frv_branch_cost_string);
462 /* Change the # of insns to be converted to conditional execution */
463 if (frv_condexec_insns_str)
464 frv_condexec_insns = atoi (frv_condexec_insns_str);
466 /* Change # of temporary registers used to hold integer constants */
467 if (frv_condexec_temps_str)
468 frv_condexec_temps = atoi (frv_condexec_temps_str);
470 /* Change scheduling look ahead. */
471 if (frv_sched_lookahead_str)
472 frv_sched_lookahead = atoi (frv_sched_lookahead_str);
474 /* A C expression whose value is a register class containing hard
475 register REGNO. In general there is more than one such class;
476 choose a class which is "minimal", meaning that no smaller class
477 also contains the register. */
479 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
481 enum reg_class class;
483 if (GPR_P (regno))
485 int gpr_reg = regno - GPR_FIRST;
486 if ((gpr_reg & 3) == 0)
487 class = QUAD_REGS;
489 else if ((gpr_reg & 1) == 0)
490 class = EVEN_REGS;
492 else
493 class = GPR_REGS;
496 else if (FPR_P (regno))
498 int fpr_reg = regno - GPR_FIRST;
499 if ((fpr_reg & 3) == 0)
500 class = QUAD_FPR_REGS;
502 else if ((fpr_reg & 1) == 0)
503 class = FEVEN_REGS;
505 else
506 class = FPR_REGS;
509 else if (regno == LR_REGNO)
510 class = LR_REG;
512 else if (regno == LCR_REGNO)
513 class = LCR_REG;
515 else if (ICC_P (regno))
516 class = ICC_REGS;
518 else if (FCC_P (regno))
519 class = FCC_REGS;
521 else if (ICR_P (regno))
522 class = ICR_REGS;
524 else if (FCR_P (regno))
525 class = FCR_REGS;
527 else if (ACC_P (regno))
529 int r = regno - ACC_FIRST;
530 if ((r & 3) == 0)
531 class = QUAD_ACC_REGS;
532 else if ((r & 1) == 0)
533 class = EVEN_ACC_REGS;
534 else
535 class = ACC_REGS;
538 else if (ACCG_P (regno))
539 class = ACCG_REGS;
541 else
542 class = NO_REGS;
544 regno_reg_class[regno] = class;
547 /* Check for small data option */
548 if (!g_switch_set)
549 g_switch_value = SDATA_DEFAULT_SIZE;
551 /* A C expression which defines the machine-dependent operand
552 constraint letters for register classes. If CHAR is such a
553 letter, the value should be the register class corresponding to
554 it. Otherwise, the value should be `NO_REGS'. The register
555 letter `r', corresponding to class `GENERAL_REGS', will not be
556 passed to this macro; you do not need to handle it.
558 The following letters are unavailable, due to being used as
559 constraints:
560 '0'..'9'
561 '<', '>'
562 'E', 'F', 'G', 'H'
563 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
564 'Q', 'R', 'S', 'T', 'U'
565 'V', 'X'
566 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
568 for (i = 0; i < 256; i++)
569 reg_class_from_letter[i] = NO_REGS;
571 reg_class_from_letter['a'] = ACC_REGS;
572 reg_class_from_letter['b'] = EVEN_ACC_REGS;
573 reg_class_from_letter['c'] = CC_REGS;
574 reg_class_from_letter['d'] = GPR_REGS;
575 reg_class_from_letter['e'] = EVEN_REGS;
576 reg_class_from_letter['f'] = FPR_REGS;
577 reg_class_from_letter['h'] = FEVEN_REGS;
578 reg_class_from_letter['l'] = LR_REG;
579 reg_class_from_letter['q'] = QUAD_REGS;
580 reg_class_from_letter['t'] = ICC_REGS;
581 reg_class_from_letter['u'] = FCC_REGS;
582 reg_class_from_letter['v'] = ICR_REGS;
583 reg_class_from_letter['w'] = FCR_REGS;
584 reg_class_from_letter['x'] = QUAD_FPR_REGS;
585 reg_class_from_letter['y'] = LCR_REG;
586 reg_class_from_letter['z'] = SPR_REGS;
587 reg_class_from_letter['A'] = QUAD_ACC_REGS;
588 reg_class_from_letter['B'] = ACCG_REGS;
589 reg_class_from_letter['C'] = CR_REGS;
591 /* There is no single unaligned SI op for PIC code. Sometimes we
592 need to use ".4byte" and sometimes we need to use ".picptr".
593 See frv_assemble_integer for details. */
594 if (flag_pic)
595 targetm.asm_out.unaligned_op.si = 0;
597 init_machine_status = frv_init_machine_status;
601 /* Some machines may desire to change what optimizations are performed for
602 various optimization levels. This macro, if defined, is executed once just
603 after the optimization level is determined and before the remainder of the
604 command options have been parsed. Values set in this macro are used as the
605 default values for the other command line options.
607 LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if
608 `-O' is specified, and 0 if neither is specified.
610 SIZE is nonzero if `-Os' is specified, 0 otherwise.
612 You should not use this macro to change options that are not
613 machine-specific. These should uniformly selected by the same optimization
614 level on all supported machines. Use this macro to enable machbine-specific
615 optimizations.
617 *Do not examine `write_symbols' in this macro!* The debugging options are
618 *not supposed to alter the generated code. */
620 /* On the FRV, possibly disable VLIW packing which is done by the 2nd
621 scheduling pass at the current time. */
622 void
623 frv_optimization_options (level, size)
624 int level;
625 int size ATTRIBUTE_UNUSED;
627 if (level >= 2)
629 #ifdef DISABLE_SCHED2
630 flag_schedule_insns_after_reload = 0;
631 #endif
632 #ifdef ENABLE_RCSP
633 flag_rcsp = 1;
634 #endif
639 /* Return true if NAME (a STRING_CST node) begins with PREFIX. */
641 static int
642 frv_string_begins_with (name, prefix)
643 tree name;
644 const char *prefix;
646 int prefix_len = strlen (prefix);
648 /* Remember: NAME's length includes the null terminator. */
649 return (TREE_STRING_LENGTH (name) > prefix_len
650 && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0);
653 /* Encode section information of DECL, which is either a VAR_DECL,
654 FUNCTION_DECL, STRING_CST, CONSTRUCTOR, or ???.
656 For the FRV we want to record:
658 - whether the object lives in .sdata/.sbss.
659 objects living in .sdata/.sbss are prefixed with SDATA_FLAG_CHAR
663 static void
664 frv_encode_section_info (decl, first)
665 tree decl;
666 int first;
668 if (! first)
669 return;
670 if (TREE_CODE (decl) == VAR_DECL)
672 int size = int_size_in_bytes (TREE_TYPE (decl));
673 tree section_name = DECL_SECTION_NAME (decl);
674 int is_small = 0;
676 /* Don't apply the -G flag to internal compiler structures. We
677 should leave such structures in the main data section, partly
678 for efficiency and partly because the size of some of them
679 (such as C++ typeinfos) is not known until later. */
680 if (!DECL_ARTIFICIAL (decl) && size > 0 && size <= g_switch_value)
681 is_small = 1;
683 /* If we already know which section the decl should be in, see if
684 it's a small data section. */
685 if (section_name)
687 if (TREE_CODE (section_name) == STRING_CST)
689 if (frv_string_begins_with (section_name, ".sdata"))
690 is_small = 1;
691 if (frv_string_begins_with (section_name, ".sbss"))
692 is_small = 1;
694 else
695 abort ();
698 if (is_small)
700 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
701 char * str = xmalloc (2 + strlen (XSTR (sym_ref, 0)));
703 str[0] = SDATA_FLAG_CHAR;
704 strcpy (&str[1], XSTR (sym_ref, 0));
705 XSTR (sym_ref, 0) = str;
711 /* Zero or more C statements that may conditionally modify two variables
712 `fixed_regs' and `call_used_regs' (both of type `char []') after they have
713 been initialized from the two preceding macros.
715 This is necessary in case the fixed or call-clobbered registers depend on
716 target flags.
718 You need not define this macro if it has no work to do.
720 If the usage of an entire class of registers depends on the target flags,
721 you may indicate this to GCC by using this macro to modify `fixed_regs' and
722 `call_used_regs' to 1 for each of the registers in the classes which should
723 not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return
724 `NO_REGS' if it is called with a letter for a class that shouldn't be used.
726 (However, if this class is not included in `GENERAL_REGS' and all of the
727 insn patterns whose constraints permit this class are controlled by target
728 switches, then GCC will automatically avoid using these registers when the
729 target switches are opposed to them.) */
731 void
732 frv_conditional_register_usage ()
734 int i;
736 for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++)
737 fixed_regs[i] = call_used_regs[i] = 1;
739 for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++)
740 fixed_regs[i] = call_used_regs[i] = 1;
742 for (i = ACC_FIRST + NUM_ACCS; i <= ACC_LAST; i++)
743 fixed_regs[i] = call_used_regs[i] = 1;
745 for (i = ACCG_FIRST + NUM_ACCS; i <= ACCG_LAST; i++)
746 fixed_regs[i] = call_used_regs[i] = 1;
748 /* Reserve the registers used for conditional execution. At present, we need
749 1 ICC and 1 ICR register. */
750 fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1;
751 fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1;
753 if (TARGET_FIXED_CC)
755 fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1;
756 fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1;
757 fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1;
758 fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1;
761 #if 0
762 /* If -fpic, SDA_BASE_REG is the PIC register. */
763 if (g_switch_value == 0 && !flag_pic)
764 fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0;
766 if (!flag_pic)
767 fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0;
768 #endif
773 * Compute the stack frame layout
775 * Register setup:
776 * +---------------+-----------------------+-----------------------+
777 * |Register |type |caller-save/callee-save|
778 * +---------------+-----------------------+-----------------------+
779 * |GR0 |Zero register | - |
780 * |GR1 |Stack pointer(SP) | - |
781 * |GR2 |Frame pointer(FP) | - |
782 * |GR3 |Hidden parameter | caller save |
783 * |GR4-GR7 | - | caller save |
784 * |GR8-GR13 |Argument register | caller save |
785 * |GR14-GR15 | - | caller save |
786 * |GR16-GR31 | - | callee save |
787 * |GR32-GR47 | - | caller save |
788 * |GR48-GR63 | - | callee save |
789 * |FR0-FR15 | - | caller save |
790 * |FR16-FR31 | - | callee save |
791 * |FR32-FR47 | - | caller save |
792 * |FR48-FR63 | - | callee save |
793 * +---------------+-----------------------+-----------------------+
795 * Stack frame setup:
796 * Low
797 * SP-> |-----------------------------------|
798 * | Argument area |
799 * |-----------------------------------|
800 * | Register save area |
801 * |-----------------------------------|
802 * | Local variable save area |
803 * FP-> |-----------------------------------|
804 * | Old FP |
805 * |-----------------------------------|
806 * | Hidden parameter save area |
807 * |-----------------------------------|
808 * | Return address(LR) storage area |
809 * |-----------------------------------|
810 * | Padding for alignment |
811 * |-----------------------------------|
812 * | Register argument area |
813 * OLD SP-> |-----------------------------------|
814 * | Parameter area |
815 * |-----------------------------------|
816 * High
818 * Argument area/Parameter area:
820 * When a function is called, this area is used for argument transfer. When
821 * the argument is set up by the caller function, this area is referred to as
822 * the argument area. When the argument is referenced by the callee function,
823 * this area is referred to as the parameter area. The area is allocated when
824 * all arguments cannot be placed on the argument register at the time of
825 * argument transfer.
827 * Register save area:
829 * This is a register save area that must be guaranteed for the caller
830 * function. This area is not secured when the register save operation is not
831 * needed.
833 * Local variable save area:
835 * This is the area for local variables and temporary variables.
837 * Old FP:
839 * This area stores the FP value of the caller function.
841 * Hidden parameter save area:
843 * This area stores the start address of the return value storage
844 * area for a struct/union return function.
845 * When a struct/union is used as the return value, the caller
846 * function stores the return value storage area start address in
847 * register GR3 and passes it to the caller function.
848 * The callee function interprets the address stored in the GR3
849 * as the return value storage area start address.
850 * When register GR3 needs to be saved into memory, the callee
851 * function saves it in the hidden parameter save area. This
852 * area is not secured when the save operation is not needed.
854 * Return address(LR) storage area:
856 * This area saves the LR. The LR stores the address of a return to the caller
857 * function for the purpose of function calling.
859 * Argument register area:
861 * This area saves the argument register. This area is not secured when the
862 * save operation is not needed.
864 * Argument:
866 * Arguments, the count of which equals the count of argument registers (6
867 * words), are positioned in registers GR8 to GR13 and delivered to the callee
868 * function. When a struct/union return function is called, the return value
869 * area address is stored in register GR3. Arguments not placed in the
870 * argument registers will be stored in the stack argument area for transfer
871 * purposes. When an 8-byte type argument is to be delivered using registers,
872 * it is divided into two and placed in two registers for transfer. When
873 * argument registers must be saved to memory, the callee function secures an
874 * argument register save area in the stack. In this case, a continuous
875 * argument register save area must be established in the parameter area. The
876 * argument register save area must be allocated as needed to cover the size of
877 * the argument register to be saved. If the function has a variable count of
878 * arguments, it saves all argument registers in the argument register save
879 * area.
881 * Argument Extension Format:
883 * When an argument is to be stored in the stack, its type is converted to an
884 * extended type in accordance with the individual argument type. The argument
885 * is freed by the caller function after the return from the callee function is
886 * made.
888 * +-----------------------+---------------+------------------------+
889 * | Argument Type |Extended Type |Stack Storage Size(byte)|
890 * +-----------------------+---------------+------------------------+
891 * |char |int | 4 |
892 * |signed char |int | 4 |
893 * |unsigned char |int | 4 |
894 * |[signed] short int |int | 4 |
895 * |unsigned short int |int | 4 |
896 * |[signed] int |No extension | 4 |
897 * |unsigned int |No extension | 4 |
898 * |[signed] long int |No extension | 4 |
899 * |unsigned long int |No extension | 4 |
900 * |[signed] long long int |No extension | 8 |
901 * |unsigned long long int |No extension | 8 |
902 * |float |double | 8 |
903 * |double |No extension | 8 |
904 * |long double |No extension | 8 |
905 * |pointer |No extension | 4 |
906 * |struct/union |- | 4 (*1) |
907 * +-----------------------+---------------+------------------------+
909 * When a struct/union is to be delivered as an argument, the caller copies it
910 * to the local variable area and delivers the address of that area.
912 * Return Value:
914 * +-------------------------------+----------------------+
915 * |Return Value Type |Return Value Interface|
916 * +-------------------------------+----------------------+
917 * |void |None |
918 * |[signed|unsigned] char |GR8 |
919 * |[signed|unsigned] short int |GR8 |
920 * |[signed|unsigned] int |GR8 |
921 * |[signed|unsigned] long int |GR8 |
922 * |pointer |GR8 |
923 * |[signed|unsigned] long long int|GR8 & GR9 |
924 * |float |GR8 |
925 * |double |GR8 & GR9 |
926 * |long double |GR8 & GR9 |
927 * |struct/union |(*1) |
928 * +-------------------------------+----------------------+
930 * When a struct/union is used as the return value, the caller function stores
931 * the start address of the return value storage area into GR3 and then passes
932 * it to the callee function. The callee function interprets GR3 as the start
933 * address of the return value storage area. When this address needs to be
934 * saved in memory, the callee function secures the hidden parameter save area
935 * and saves the address in that area.
938 frv_stack_t *
939 frv_stack_info ()
941 static frv_stack_t info, zero_info;
942 frv_stack_t *info_ptr = &info;
943 tree fndecl = current_function_decl;
944 int varargs_p = 0;
945 tree cur_arg;
946 tree next_arg;
947 int range;
948 int alignment;
949 int offset;
951 /* If we've already calculated the values and reload is complete, just return now */
952 if (frv_stack_cache)
953 return frv_stack_cache;
955 /* Zero all fields */
956 info = zero_info;
958 /* Set up the register range information */
959 info_ptr->regs[STACK_REGS_GPR].name = "gpr";
960 info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1;
961 info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST;
962 info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE;
964 info_ptr->regs[STACK_REGS_FPR].name = "fpr";
965 info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST;
966 info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST;
967 info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE;
969 info_ptr->regs[STACK_REGS_LR].name = "lr";
970 info_ptr->regs[STACK_REGS_LR].first = LR_REGNO;
971 info_ptr->regs[STACK_REGS_LR].last = LR_REGNO;
972 info_ptr->regs[STACK_REGS_LR].special_p = 1;
974 info_ptr->regs[STACK_REGS_CC].name = "cc";
975 info_ptr->regs[STACK_REGS_CC].first = CC_FIRST;
976 info_ptr->regs[STACK_REGS_CC].last = CC_LAST;
977 info_ptr->regs[STACK_REGS_CC].field_p = TRUE;
979 info_ptr->regs[STACK_REGS_LCR].name = "lcr";
980 info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO;
981 info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO;
983 info_ptr->regs[STACK_REGS_STDARG].name = "stdarg";
984 info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM;
985 info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM;
986 info_ptr->regs[STACK_REGS_STDARG].dword_p = 1;
987 info_ptr->regs[STACK_REGS_STDARG].special_p = 1;
989 info_ptr->regs[STACK_REGS_STRUCT].name = "struct";
990 info_ptr->regs[STACK_REGS_STRUCT].first = STRUCT_VALUE_REGNUM;
991 info_ptr->regs[STACK_REGS_STRUCT].last = STRUCT_VALUE_REGNUM;
992 info_ptr->regs[STACK_REGS_STRUCT].special_p = 1;
994 info_ptr->regs[STACK_REGS_FP].name = "fp";
995 info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM;
996 info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM;
997 info_ptr->regs[STACK_REGS_FP].special_p = 1;
999 /* Determine if this is a stdarg function. If so, allocate space to store
1000 the 6 arguments. */
1001 if (cfun->stdarg)
1002 varargs_p = 1;
1004 else
1006 /* Find the last argument, and see if it is __builtin_va_alist. */
1007 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
1009 next_arg = TREE_CHAIN (cur_arg);
1010 if (next_arg == (tree)0)
1012 if (DECL_NAME (cur_arg)
1013 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
1014 varargs_p = 1;
1016 break;
1021 /* Iterate over all of the register ranges */
1022 for (range = 0; range < STACK_REGS_MAX; range++)
1024 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1025 int first = reg_ptr->first;
1026 int last = reg_ptr->last;
1027 int size_1word = 0;
1028 int size_2words = 0;
1029 int regno;
1031 /* Calculate which registers need to be saved & save area size */
1032 switch (range)
1034 default:
1035 for (regno = first; regno <= last; regno++)
1037 if ((regs_ever_live[regno] && !call_used_regs[regno])
1038 || (current_function_calls_eh_return
1039 && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM))
1040 || (flag_pic && cfun->uses_pic_offset_table && regno == PIC_REGNO))
1042 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1043 size_1word += UNITS_PER_WORD;
1046 break;
1048 /* Calculate whether we need to create a frame after everything else
1049 has been processed. */
1050 case STACK_REGS_FP:
1051 break;
1053 case STACK_REGS_LR:
1054 if (regs_ever_live[LR_REGNO]
1055 || profile_flag
1056 || frame_pointer_needed
1057 || (flag_pic && cfun->uses_pic_offset_table))
1059 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1060 size_1word += UNITS_PER_WORD;
1062 break;
1064 case STACK_REGS_STDARG:
1065 if (varargs_p)
1067 /* If this is a stdarg function with a non varardic argument split
1068 between registers and the stack, adjust the saved registers
1069 downward */
1070 last -= (ADDR_ALIGN (cfun->pretend_args_size, UNITS_PER_WORD)
1071 / UNITS_PER_WORD);
1073 for (regno = first; regno <= last; regno++)
1075 info_ptr->save_p[regno] = REG_SAVE_1WORD;
1076 size_1word += UNITS_PER_WORD;
1079 info_ptr->stdarg_size = size_1word;
1081 break;
1083 case STACK_REGS_STRUCT:
1084 if (cfun->returns_struct)
1086 info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1087 size_1word += UNITS_PER_WORD;
1089 break;
1093 if (size_1word)
1095 /* If this is a field, it only takes one word */
1096 if (reg_ptr->field_p)
1097 size_1word = UNITS_PER_WORD;
1099 /* Determine which register pairs can be saved together */
1100 else if (reg_ptr->dword_p && TARGET_DWORD)
1102 for (regno = first; regno < last; regno += 2)
1104 if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1])
1106 size_2words += 2 * UNITS_PER_WORD;
1107 size_1word -= 2 * UNITS_PER_WORD;
1108 info_ptr->save_p[regno] = REG_SAVE_2WORDS;
1109 info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE;
1114 reg_ptr->size_1word = size_1word;
1115 reg_ptr->size_2words = size_2words;
1117 if (! reg_ptr->special_p)
1119 info_ptr->regs_size_1word += size_1word;
1120 info_ptr->regs_size_2words += size_2words;
1125 /* Set up the sizes of each each field in the frame body, making the sizes
1126 of each be divisible by the size of a dword if dword operations might
1127 be used, or the size of a word otherwise. */
1128 alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD);
1130 info_ptr->parameter_size = ADDR_ALIGN (cfun->outgoing_args_size, alignment);
1131 info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words
1132 + info_ptr->regs_size_1word,
1133 alignment);
1134 info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment);
1136 info_ptr->pretend_size = cfun->pretend_args_size;
1138 /* Work out the size of the frame, excluding the header. Both the frame
1139 body and register parameter area will be dword-aligned. */
1140 info_ptr->total_size
1141 = (ADDR_ALIGN (info_ptr->parameter_size
1142 + info_ptr->regs_size
1143 + info_ptr->vars_size,
1144 2 * UNITS_PER_WORD)
1145 + ADDR_ALIGN (info_ptr->pretend_size
1146 + info_ptr->stdarg_size,
1147 2 * UNITS_PER_WORD));
1149 /* See if we need to create a frame at all, if so add header area. */
1150 if (info_ptr->total_size > 0
1151 || info_ptr->regs[STACK_REGS_LR].size_1word > 0
1152 || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0)
1154 offset = info_ptr->parameter_size;
1155 info_ptr->header_size = 4 * UNITS_PER_WORD;
1156 info_ptr->total_size += 4 * UNITS_PER_WORD;
1158 /* Calculate the offsets to save normal register pairs */
1159 for (range = 0; range < STACK_REGS_MAX; range++)
1161 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1162 if (! reg_ptr->special_p)
1164 int first = reg_ptr->first;
1165 int last = reg_ptr->last;
1166 int regno;
1168 for (regno = first; regno <= last; regno++)
1169 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS
1170 && regno != FRAME_POINTER_REGNUM
1171 && (regno < FIRST_ARG_REGNUM
1172 || regno > LAST_ARG_REGNUM))
1174 info_ptr->reg_offset[regno] = offset;
1175 offset += 2 * UNITS_PER_WORD;
1180 /* Calculate the offsets to save normal single registers */
1181 for (range = 0; range < STACK_REGS_MAX; range++)
1183 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1184 if (! reg_ptr->special_p)
1186 int first = reg_ptr->first;
1187 int last = reg_ptr->last;
1188 int regno;
1190 for (regno = first; regno <= last; regno++)
1191 if (info_ptr->save_p[regno] == REG_SAVE_1WORD
1192 && regno != FRAME_POINTER_REGNUM
1193 && (regno < FIRST_ARG_REGNUM
1194 || regno > LAST_ARG_REGNUM))
1196 info_ptr->reg_offset[regno] = offset;
1197 offset += UNITS_PER_WORD;
1202 /* Calculate the offset to save the local variables at. */
1203 offset = ADDR_ALIGN (offset, alignment);
1204 if (info_ptr->vars_size)
1206 info_ptr->vars_offset = offset;
1207 offset += info_ptr->vars_size;
1210 /* Align header to a dword-boundary. */
1211 offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD);
1213 /* Calculate the offsets in the fixed frame. */
1214 info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD;
1215 info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset;
1216 info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD;
1218 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1219 info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD;
1220 info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD;
1222 if (cfun->returns_struct)
1224 info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1225 info_ptr->reg_offset[STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD;
1226 info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD;
1229 /* Calculate the offsets to store the arguments passed in registers
1230 for stdarg functions. The register pairs are first and the single
1231 register if any is last. The register save area starts on a
1232 dword-boundary. */
1233 if (info_ptr->stdarg_size)
1235 int first = info_ptr->regs[STACK_REGS_STDARG].first;
1236 int last = info_ptr->regs[STACK_REGS_STDARG].last;
1237 int regno;
1239 /* Skip the header. */
1240 offset += 4 * UNITS_PER_WORD;
1241 for (regno = first; regno <= last; regno++)
1243 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS)
1245 info_ptr->reg_offset[regno] = offset;
1246 offset += 2 * UNITS_PER_WORD;
1248 else if (info_ptr->save_p[regno] == REG_SAVE_1WORD)
1250 info_ptr->reg_offset[regno] = offset;
1251 offset += UNITS_PER_WORD;
1257 if (reload_completed)
1258 frv_stack_cache = info_ptr;
1260 return info_ptr;
1264 /* Print the information about the frv stack offsets, etc. when debugging. */
1266 void
1267 frv_debug_stack (info)
1268 frv_stack_t *info;
1270 int range;
1272 if (!info)
1273 info = frv_stack_info ();
1275 fprintf (stderr, "\nStack information for function %s:\n",
1276 ((current_function_decl && DECL_NAME (current_function_decl))
1277 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1278 : "<unknown>"));
1280 fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size);
1281 fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size);
1282 fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size);
1283 fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n",
1284 info->regs_size, info->regs_size_1word, info->regs_size_2words);
1286 fprintf (stderr, "\theader_size\t= %6d\n", info->header_size);
1287 fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size);
1288 fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset);
1289 fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset);
1291 for (range = 0; range < STACK_REGS_MAX; range++)
1293 frv_stack_regs_t *regs = &(info->regs[range]);
1294 if ((regs->size_1word + regs->size_2words) > 0)
1296 int first = regs->first;
1297 int last = regs->last;
1298 int regno;
1300 fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =",
1301 regs->name, regs->size_1word + regs->size_2words,
1302 regs->size_1word, regs->size_2words);
1304 for (regno = first; regno <= last; regno++)
1306 if (info->save_p[regno] == REG_SAVE_1WORD)
1307 fprintf (stderr, " %s (%d)", reg_names[regno],
1308 info->reg_offset[regno]);
1310 else if (info->save_p[regno] == REG_SAVE_2WORDS)
1311 fprintf (stderr, " %s-%s (%d)", reg_names[regno],
1312 reg_names[regno+1], info->reg_offset[regno]);
1315 fputc ('\n', stderr);
1319 fflush (stderr);
1325 /* The following variable value is TRUE if the next output insn should
1326 finish cpu cycle. In order words the insn will have packing bit
1327 (which means absence of asm code suffix `.p' on assembler. */
1329 static int frv_insn_packing_flag;
1331 /* True if the current function contains a far jump. */
1333 static int
1334 frv_function_contains_far_jump ()
1336 rtx insn = get_insns ();
1337 while (insn != NULL
1338 && !(GET_CODE (insn) == JUMP_INSN
1339 /* Ignore tablejump patterns. */
1340 && GET_CODE (PATTERN (insn)) != ADDR_VEC
1341 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
1342 && get_attr_far_jump (insn) == FAR_JUMP_YES))
1343 insn = NEXT_INSN (insn);
1344 return (insn != NULL);
1347 /* For the FRV, this function makes sure that a function with far jumps
1348 will return correctly. It also does the VLIW packing. */
1350 static void
1351 frv_function_prologue (file, size)
1352 FILE *file;
1353 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
1355 /* If no frame was created, check whether the function uses a call
1356 instruction to implement a far jump. If so, save the link in gr3 and
1357 replace all returns to LR with returns to GR3. GR3 is used because it
1358 is call-clobbered, because is not available to the register allocator,
1359 and because all functions that take a hidden argument pointer will have
1360 a stack frame. */
1361 if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ())
1363 rtx insn;
1365 /* Just to check that the above comment is true. */
1366 if (regs_ever_live[GPR_FIRST + 3])
1367 abort ();
1369 /* Generate the instruction that saves the link register. */
1370 fprintf (file, "\tmovsg lr,gr3\n");
1372 /* Replace the LR with GR3 in *return_internal patterns. The insn
1373 will now return using jmpl @(gr3,0) rather than bralr. We cannot
1374 simply emit a different assembly directive because bralr and jmpl
1375 execute in different units. */
1376 for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn))
1377 if (GET_CODE (insn) == JUMP_INSN)
1379 rtx pattern = PATTERN (insn);
1380 if (GET_CODE (pattern) == PARALLEL
1381 && XVECLEN (pattern, 0) >= 2
1382 && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN
1383 && GET_CODE (XVECEXP (pattern, 0, 1)) == USE)
1385 rtx address = XEXP (XVECEXP (pattern, 0, 1), 0);
1386 if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO)
1387 REGNO (address) = GPR_FIRST + 3;
1392 frv_pack_insns ();
1393 frv_insn_packing_flag = TRUE;
1397 /* Return the next available temporary register in a given class. */
1399 static rtx
1400 frv_alloc_temp_reg (info, class, mode, mark_as_used, no_abort)
1401 frv_tmp_reg_t *info; /* which registers are available */
1402 enum reg_class class; /* register class desired */
1403 enum machine_mode mode; /* mode to allocate register with */
1404 int mark_as_used; /* register not available after allocation */
1405 int no_abort; /* return NULL instead of aborting */
1407 int regno = info->next_reg[ (int)class ];
1408 int orig_regno = regno;
1409 HARD_REG_SET *reg_in_class = &reg_class_contents[ (int)class ];
1410 int i, nr;
1412 for (;;)
1414 if (TEST_HARD_REG_BIT (*reg_in_class, regno)
1415 && TEST_HARD_REG_BIT (info->regs, regno))
1416 break;
1418 if (++regno >= FIRST_PSEUDO_REGISTER)
1419 regno = 0;
1420 if (regno == orig_regno)
1422 if (no_abort)
1423 return NULL_RTX;
1424 else
1425 abort ();
1429 nr = HARD_REGNO_NREGS (regno, mode);
1430 info->next_reg[ (int)class ] = regno + nr;
1432 if (mark_as_used)
1433 for (i = 0; i < nr; i++)
1434 CLEAR_HARD_REG_BIT (info->regs, regno+i);
1436 return gen_rtx_REG (mode, regno);
1440 /* Return an rtx with the value OFFSET, which will either be a register or a
1441 signed 12-bit integer. It can be used as the second operand in an "add"
1442 instruction, or as the index in a load or store.
1444 The function returns a constant rtx if OFFSET is small enough, otherwise
1445 it loads the constant into register OFFSET_REGNO and returns that. */
1446 static rtx
1447 frv_frame_offset_rtx (offset)
1448 int offset;
1450 rtx offset_rtx = GEN_INT (offset);
1451 if (IN_RANGE_P (offset, -2048, 2047))
1452 return offset_rtx;
1453 else
1455 rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO);
1456 if (IN_RANGE_P (offset, -32768, 32767))
1457 emit_insn (gen_movsi (reg_rtx, offset_rtx));
1458 else
1460 emit_insn (gen_movsi_high (reg_rtx, offset_rtx));
1461 emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx));
1463 return reg_rtx;
1467 /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The
1468 prologue and epilogue uses such expressions to access the stack. */
1469 static rtx
1470 frv_frame_mem (mode, base, offset)
1471 enum machine_mode mode;
1472 rtx base;
1473 int offset;
1475 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode,
1476 base,
1477 frv_frame_offset_rtx (offset)));
1480 /* Generate a frame-related expression:
1482 (set REG (mem (plus (sp) (const_int OFFSET)))).
1484 Such expressions are used in FRAME_RELATED_EXPR notes for more complex
1485 instructions. Marking the expressions as frame-related is superfluous if
1486 the note contains just a single set. But if the note contains a PARALLEL
1487 or SEQUENCE that has several sets, each set must be individually marked
1488 as frame-related. */
1489 static rtx
1490 frv_dwarf_store (reg, offset)
1491 rtx reg;
1492 int offset;
1494 rtx set = gen_rtx_SET (VOIDmode,
1495 gen_rtx_MEM (GET_MODE (reg),
1496 plus_constant (stack_pointer_rtx,
1497 offset)),
1498 reg);
1499 RTX_FRAME_RELATED_P (set) = 1;
1500 return set;
1503 /* Emit a frame-related instruction whose pattern is PATTERN. The
1504 instruction is the last in a sequence that cumulatively performs the
1505 operation described by DWARF_PATTERN. The instruction is marked as
1506 frame-related and has a REG_FRAME_RELATED_EXPR note containing
1507 DWARF_PATTERN. */
1508 static void
1509 frv_frame_insn (pattern, dwarf_pattern)
1510 rtx pattern;
1511 rtx dwarf_pattern;
1513 rtx insn = emit_insn (pattern);
1514 RTX_FRAME_RELATED_P (insn) = 1;
1515 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1516 dwarf_pattern,
1517 REG_NOTES (insn));
1520 /* Emit instructions that transfer REG to or from the memory location (sp +
1521 STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is
1522 FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this
1523 function to store registers and only the epilogue uses it to load them.
1525 The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET).
1526 The generated instruction will use BASE as its base register. BASE may
1527 simply be the stack pointer, but if several accesses are being made to a
1528 region far away from the stack pointer, it may be more efficient to set
1529 up a temporary instead.
1531 Store instructions will be frame-related and will be annotated with the
1532 overall effect of the store. Load instructions will be followed by a
1533 (use) to prevent later optimizations from zapping them.
1535 The function takes care of the moves to and from SPRs, using TEMP_REGNO
1536 as a temporary in such cases. */
1537 static void
1538 frv_frame_access (accessor, reg, stack_offset)
1539 frv_frame_accessor_t *accessor;
1540 rtx reg;
1541 int stack_offset;
1543 enum machine_mode mode = GET_MODE (reg);
1544 rtx mem = frv_frame_mem (mode,
1545 accessor->base,
1546 stack_offset - accessor->base_offset);
1548 if (accessor->op == FRV_LOAD)
1550 if (SPR_P (REGNO (reg)))
1552 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1553 emit_insn (gen_rtx_SET (VOIDmode, temp, mem));
1554 emit_insn (gen_rtx_SET (VOIDmode, reg, temp));
1556 else
1557 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
1558 emit_insn (gen_rtx_USE (VOIDmode, reg));
1560 else
1562 if (SPR_P (REGNO (reg)))
1564 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1565 emit_insn (gen_rtx_SET (VOIDmode, temp, reg));
1566 frv_frame_insn (gen_rtx_SET (Pmode, mem, temp),
1567 frv_dwarf_store (reg, stack_offset));
1569 else if (GET_MODE (reg) == DImode)
1571 /* For DImode saves, the dwarf2 version needs to be a SEQUENCE
1572 with a separate save for each register. */
1573 rtx reg1 = gen_rtx_REG (SImode, REGNO (reg));
1574 rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1);
1575 rtx set1 = frv_dwarf_store (reg1, stack_offset);
1576 rtx set2 = frv_dwarf_store (reg2, stack_offset + 4);
1577 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1578 gen_rtx_PARALLEL (VOIDmode,
1579 gen_rtvec (2, set1, set2)));
1581 else
1582 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1583 frv_dwarf_store (reg, stack_offset));
1587 /* A function that uses frv_frame_access to transfer a group of registers to
1588 or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO
1589 is the stack information generated by frv_stack_info, and REG_SET is the
1590 number of the register set to transfer. */
1591 static void
1592 frv_frame_access_multi (accessor, info, reg_set)
1593 frv_frame_accessor_t *accessor;
1594 frv_stack_t *info;
1595 int reg_set;
1597 frv_stack_regs_t *regs_info;
1598 int regno;
1600 regs_info = &info->regs[reg_set];
1601 for (regno = regs_info->first; regno <= regs_info->last; regno++)
1602 if (info->save_p[regno])
1603 frv_frame_access (accessor,
1604 info->save_p[regno] == REG_SAVE_2WORDS
1605 ? gen_rtx_REG (DImode, regno)
1606 : gen_rtx_REG (SImode, regno),
1607 info->reg_offset[regno]);
1610 /* Save or restore callee-saved registers that are kept outside the frame
1611 header. The function saves the registers if OP is FRV_STORE and restores
1612 them if OP is FRV_LOAD. INFO is the stack information generated by
1613 frv_stack_info. */
1614 static void
1615 frv_frame_access_standard_regs (op, info)
1616 enum frv_stack_op op;
1617 frv_stack_t *info;
1619 frv_frame_accessor_t accessor;
1621 accessor.op = op;
1622 accessor.base = stack_pointer_rtx;
1623 accessor.base_offset = 0;
1624 frv_frame_access_multi (&accessor, info, STACK_REGS_GPR);
1625 frv_frame_access_multi (&accessor, info, STACK_REGS_FPR);
1626 frv_frame_access_multi (&accessor, info, STACK_REGS_LCR);
1630 /* Called after register allocation to add any instructions needed for the
1631 prologue. Using a prologue insn is favored compared to putting all of the
1632 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
1633 to intermix instructions with the saves of the caller saved registers. In
1634 some cases, it might be necessary to emit a barrier instruction as the last
1635 insn to prevent such scheduling.
1637 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
1638 so that the debug info generation code can handle them properly. */
1639 void
1640 frv_expand_prologue ()
1642 frv_stack_t *info = frv_stack_info ();
1643 rtx sp = stack_pointer_rtx;
1644 rtx fp = frame_pointer_rtx;
1645 frv_frame_accessor_t accessor;
1647 if (TARGET_DEBUG_STACK)
1648 frv_debug_stack (info);
1650 if (info->total_size == 0)
1651 return;
1653 /* We're interested in three areas of the frame here:
1655 A: the register save area
1656 B: the old FP
1657 C: the header after B
1659 If the frame pointer isn't used, we'll have to set up A, B and C
1660 using the stack pointer. If the frame pointer is used, we'll access
1661 them as follows:
1663 A: set up using sp
1664 B: set up using sp or a temporary (see below)
1665 C: set up using fp
1667 We set up B using the stack pointer if the frame is small enough.
1668 Otherwise, it's more efficient to copy the old stack pointer into a
1669 temporary and use that.
1671 Note that it's important to make sure the prologue and epilogue use the
1672 same registers to access A and C, since doing otherwise will confuse
1673 the aliasing code. */
1675 /* Set up ACCESSOR for accessing region B above. If the frame pointer
1676 isn't used, the same method will serve for C. */
1677 accessor.op = FRV_STORE;
1678 if (frame_pointer_needed && info->total_size > 2048)
1680 rtx insn;
1682 accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO);
1683 accessor.base_offset = info->total_size;
1684 insn = emit_insn (gen_movsi (accessor.base, sp));
1686 else
1688 accessor.base = stack_pointer_rtx;
1689 accessor.base_offset = 0;
1692 /* Allocate the stack space. */
1694 rtx asm_offset = frv_frame_offset_rtx (-info->total_size);
1695 rtx dwarf_offset = GEN_INT (-info->total_size);
1697 frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset),
1698 gen_rtx_SET (Pmode,
1700 gen_rtx_PLUS (Pmode, sp, dwarf_offset)));
1703 /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET)
1704 and point the new one to that location. */
1705 if (frame_pointer_needed)
1707 int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1709 /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is
1710 based on ACCESSOR.BASE but DWARF_SRC is always based on the stack
1711 pointer. */
1712 rtx asm_src = plus_constant (accessor.base,
1713 fp_offset - accessor.base_offset);
1714 rtx dwarf_src = plus_constant (sp, fp_offset);
1716 /* Store the old frame pointer at (sp + FP_OFFSET). */
1717 frv_frame_access (&accessor, fp, fp_offset);
1719 /* Set up the new frame pointer. */
1720 frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src),
1721 gen_rtx_SET (VOIDmode, fp, dwarf_src));
1723 /* Access region C from the frame pointer. */
1724 accessor.base = fp;
1725 accessor.base_offset = fp_offset;
1728 /* Set up region C. */
1729 frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT);
1730 frv_frame_access_multi (&accessor, info, STACK_REGS_LR);
1731 frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG);
1733 /* Set up region A. */
1734 frv_frame_access_standard_regs (FRV_STORE, info);
1736 /* If this is a varargs/stdarg function, issue a blockage to prevent the
1737 scheduler from moving loads before the stores saving the registers. */
1738 if (info->stdarg_size > 0)
1739 emit_insn (gen_blockage ());
1741 /* Set up pic register/small data register for this function. */
1742 if (flag_pic && cfun->uses_pic_offset_table)
1743 emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO),
1744 gen_rtx_REG (Pmode, LR_REGNO),
1745 gen_rtx_REG (SImode, OFFSET_REGNO)));
1749 /* Under frv, all of the work is done via frv_expand_epilogue, but
1750 this function provides a convient place to do cleanup. */
1752 static void
1753 frv_function_epilogue (file, size)
1754 FILE *file ATTRIBUTE_UNUSED;
1755 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
1757 frv_stack_cache = (frv_stack_t *)0;
1759 /* zap last used registers for conditional execution. */
1760 memset ((PTR) &frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg));
1762 /* release the bitmap of created insns. */
1763 BITMAP_XFREE (frv_ifcvt.scratch_insns_bitmap);
1767 /* Called after register allocation to add any instructions needed for the
1768 epilogue. Using an epilogue insn is favored compared to putting all of the
1769 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
1770 to intermix instructions with the saves of the caller saved registers. In
1771 some cases, it might be necessary to emit a barrier instruction as the last
1772 insn to prevent such scheduling.
1774 If SIBCALL_P is true, the final branch back to the calling function is
1775 omitted, and is used for sibling call (aka tail call) sites. For sibcalls,
1776 we must not clobber any arguments used for parameter passing or any stack
1777 slots for arguments passed to the current function. */
1779 void
1780 frv_expand_epilogue (sibcall_p)
1781 int sibcall_p;
1783 frv_stack_t *info = frv_stack_info ();
1784 rtx fp = frame_pointer_rtx;
1785 rtx sp = stack_pointer_rtx;
1786 rtx return_addr;
1787 int fp_offset;
1789 fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1791 /* Restore the stack pointer to its original value if alloca or the like
1792 is used. */
1793 if (! current_function_sp_is_unchanging)
1794 emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset)));
1796 /* Restore the callee-saved registers that were used in this function. */
1797 frv_frame_access_standard_regs (FRV_LOAD, info);
1799 /* Set RETURN_ADDR to the address we should return to. Set it to NULL if
1800 no return instruction should be emitted. */
1801 if (sibcall_p)
1802 return_addr = 0;
1803 else if (info->save_p[LR_REGNO])
1805 int lr_offset;
1806 rtx mem;
1808 /* Use the same method to access the link register's slot as we did in
1809 the prologue. In other words, use the frame pointer if available,
1810 otherwise use the stack pointer.
1812 LR_OFFSET is the offset of the link register's slot from the start
1813 of the frame and MEM is a memory rtx for it. */
1814 lr_offset = info->reg_offset[LR_REGNO];
1815 if (frame_pointer_needed)
1816 mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset);
1817 else
1818 mem = frv_frame_mem (Pmode, sp, lr_offset);
1820 /* Load the old link register into a GPR. */
1821 return_addr = gen_rtx_REG (Pmode, TEMP_REGNO);
1822 emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem));
1824 else
1825 return_addr = gen_rtx_REG (Pmode, LR_REGNO);
1827 /* Restore the old frame pointer. Emit a USE afterwards to make sure
1828 the load is preserved. */
1829 if (frame_pointer_needed)
1831 emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp)));
1832 emit_insn (gen_rtx_USE (VOIDmode, fp));
1835 /* Deallocate the stack frame. */
1836 if (info->total_size != 0)
1838 rtx offset = frv_frame_offset_rtx (info->total_size);
1839 emit_insn (gen_stack_adjust (sp, sp, offset));
1842 /* If this function uses eh_return, add the final stack adjustment now. */
1843 if (current_function_calls_eh_return)
1844 emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX));
1846 if (return_addr)
1847 emit_jump_insn (gen_epilogue_return (return_addr));
1851 /* A C compound statement that outputs the assembler code for a thunk function,
1852 used to implement C++ virtual function calls with multiple inheritance. The
1853 thunk acts as a wrapper around a virtual function, adjusting the implicit
1854 object parameter before handing control off to the real function.
1856 First, emit code to add the integer DELTA to the location that contains the
1857 incoming first argument. Assume that this argument contains a pointer, and
1858 is the one used to pass the `this' pointer in C++. This is the incoming
1859 argument *before* the function prologue, e.g. `%o0' on a sparc. The
1860 addition must preserve the values of all other incoming arguments.
1862 After the addition, emit code to jump to FUNCTION, which is a
1863 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
1864 the return address. Hence returning from FUNCTION will return to whoever
1865 called the current `thunk'.
1867 The effect must be as if FUNCTION had been called directly with the adjusted
1868 first argument. This macro is responsible for emitting all of the code for
1869 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
1870 invoked.
1872 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
1873 extracted from it.) It might possibly be useful on some targets, but
1874 probably not.
1876 If you do not define this macro, the target-independent code in the C++
1877 frontend will generate a less efficient heavyweight thunk that calls
1878 FUNCTION instead of jumping to it. The generic approach does not support
1879 varargs. */
1881 static void
1882 frv_asm_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
1883 FILE *file;
1884 tree thunk_fndecl ATTRIBUTE_UNUSED;
1885 HOST_WIDE_INT delta;
1886 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED;
1887 tree function;
1889 const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0);
1890 const char *name_arg0 = reg_names[FIRST_ARG_REGNUM];
1891 const char *name_jmp = reg_names[JUMP_REGNO];
1892 const char *parallel = ((PACKING_FLAG_USED_P ()) ? ".p" : "");
1894 /* Do the add using an addi if possible */
1895 if (IN_RANGE_P (delta, -2048, 2047))
1896 fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0);
1897 else
1899 const char *name_add = reg_names[TEMP_REGNO];
1900 fprintf (file, "\tsethi%s #hi(", parallel);
1901 fprintf (file, HOST_WIDE_INT_PRINT_DEC, delta);
1902 fprintf (file, "),%s\n", name_add);
1903 fprintf (file, "\tsetlo #lo(");
1904 fprintf (file, HOST_WIDE_INT_PRINT_DEC, delta);
1905 fprintf (file, "),%s\n", name_add);
1906 fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0);
1909 if (!flag_pic)
1911 fprintf (file, "\tsethi%s #hi(", parallel);
1912 assemble_name (file, name_func);
1913 fprintf (file, "),%s\n", name_jmp);
1915 fprintf (file, "\tsetlo #lo(");
1916 assemble_name (file, name_func);
1917 fprintf (file, "),%s\n", name_jmp);
1919 else
1921 /* Use JUMP_REGNO as a temporary PIC register. */
1922 const char *name_lr = reg_names[LR_REGNO];
1923 const char *name_gppic = name_jmp;
1924 const char *name_tmp = reg_names[TEMP_REGNO];
1926 fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp);
1927 fprintf (file, "\tcall 1f\n");
1928 fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic);
1929 fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr);
1930 fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp);
1931 fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp);
1932 fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic);
1934 fprintf (file, "\tsethi%s #gprelhi(", parallel);
1935 assemble_name (file, name_func);
1936 fprintf (file, "),%s\n", name_tmp);
1938 fprintf (file, "\tsetlo #gprello(");
1939 assemble_name (file, name_func);
1940 fprintf (file, "),%s\n", name_tmp);
1942 fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp);
1945 /* Jump to the function address */
1946 fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]);
1950 /* A C expression which is nonzero if a function must have and use a frame
1951 pointer. This expression is evaluated in the reload pass. If its value is
1952 nonzero the function will have a frame pointer.
1954 The expression can in principle examine the current function and decide
1955 according to the facts, but on most machines the constant 0 or the constant
1956 1 suffices. Use 0 when the machine allows code to be generated with no
1957 frame pointer, and doing so saves some time or space. Use 1 when there is
1958 no possible advantage to avoiding a frame pointer.
1960 In certain cases, the compiler does not know how to produce valid code
1961 without a frame pointer. The compiler recognizes those cases and
1962 automatically gives the function a frame pointer regardless of what
1963 `FRAME_POINTER_REQUIRED' says. You don't need to worry about them.
1965 In a function that does not require a frame pointer, the frame pointer
1966 register can be allocated for ordinary usage, unless you mark it as a fixed
1967 register. See `FIXED_REGISTERS' for more information. */
1969 /* On frv, create a frame whenever we need to create stack */
1972 frv_frame_pointer_required ()
1974 if (! current_function_is_leaf)
1975 return TRUE;
1977 if (get_frame_size () != 0)
1978 return TRUE;
1980 if (cfun->stdarg)
1981 return TRUE;
1983 if (!current_function_sp_is_unchanging)
1984 return TRUE;
1986 if (flag_pic && cfun->uses_pic_offset_table)
1987 return TRUE;
1989 if (profile_flag)
1990 return TRUE;
1992 if (cfun->machine->frame_needed)
1993 return TRUE;
1995 return FALSE;
1999 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the
2000 initial difference between the specified pair of registers. This macro must
2001 be defined if `ELIMINABLE_REGS' is defined. */
2003 /* See frv_stack_info for more details on the frv stack frame. */
2006 frv_initial_elimination_offset (from, to)
2007 int from;
2008 int to;
2010 frv_stack_t *info = frv_stack_info ();
2011 int ret = 0;
2013 if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2014 ret = info->total_size - info->pretend_size;
2016 else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM)
2017 ret = - info->reg_offset[FRAME_POINTER_REGNUM];
2019 else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
2020 ret = (info->total_size
2021 - info->reg_offset[FRAME_POINTER_REGNUM]
2022 - info->pretend_size);
2024 else
2025 abort ();
2027 if (TARGET_DEBUG_STACK)
2028 fprintf (stderr, "Eliminate %s to %s by adding %d\n",
2029 reg_names [from], reg_names[to], ret);
2031 return ret;
2035 /* This macro offers an alternative to using `__builtin_saveregs' and defining
2036 the macro `EXPAND_BUILTIN_SAVEREGS'. Use it to store the anonymous register
2037 arguments into the stack so that all the arguments appear to have been
2038 passed consecutively on the stack. Once this is done, you can use the
2039 standard implementation of varargs that works for machines that pass all
2040 their arguments on the stack.
2042 The argument ARGS_SO_FAR is the `CUMULATIVE_ARGS' data structure, containing
2043 the values that obtain after processing of the named arguments. The
2044 arguments MODE and TYPE describe the last named argument--its machine mode
2045 and its data type as a tree node.
2047 The macro implementation should do two things: first, push onto the stack
2048 all the argument registers *not* used for the named arguments, and second,
2049 store the size of the data thus pushed into the `int'-valued variable whose
2050 name is supplied as the argument PRETEND_ARGS_SIZE. The value that you
2051 store here will serve as additional offset for setting up the stack frame.
2053 Because you must generate code to push the anonymous arguments at compile
2054 time without knowing their data types, `SETUP_INCOMING_VARARGS' is only
2055 useful on machines that have just a single category of argument register and
2056 use it uniformly for all data types.
2058 If the argument SECOND_TIME is nonzero, it means that the arguments of the
2059 function are being analyzed for the second time. This happens for an inline
2060 function, which is not actually compiled until the end of the source file.
2061 The macro `SETUP_INCOMING_VARARGS' should not generate any instructions in
2062 this case. */
2064 void
2065 frv_setup_incoming_varargs (cum, mode, type, pretend_size, second_time)
2066 CUMULATIVE_ARGS *cum;
2067 enum machine_mode mode;
2068 tree type ATTRIBUTE_UNUSED;
2069 int *pretend_size;
2070 int second_time;
2072 if (TARGET_DEBUG_ARG)
2073 fprintf (stderr,
2074 "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n",
2075 *cum, GET_MODE_NAME (mode), *pretend_size, second_time);
2079 /* If defined, is a C expression that produces the machine-specific code for a
2080 call to `__builtin_saveregs'. This code will be moved to the very beginning
2081 of the function, before any parameter access are made. The return value of
2082 this function should be an RTX that contains the value to use as the return
2083 of `__builtin_saveregs'.
2085 If this macro is not defined, the compiler will output an ordinary call to
2086 the library function `__builtin_saveregs'. */
2089 frv_expand_builtin_saveregs ()
2091 int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS;
2093 if (TARGET_DEBUG_ARG)
2094 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
2095 offset);
2097 return gen_rtx (PLUS, Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
2101 /* Expand __builtin_va_start to do the va_start macro. */
2103 void
2104 frv_expand_builtin_va_start (valist, nextarg)
2105 tree valist;
2106 rtx nextarg;
2108 tree t;
2109 int num = cfun->args_info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS;
2111 nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx,
2112 GEN_INT (UNITS_PER_WORD * num));
2114 if (TARGET_DEBUG_ARG)
2116 fprintf (stderr, "va_start: args_info = %d, num = %d\n",
2117 cfun->args_info, num);
2119 debug_rtx (nextarg);
2122 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2123 make_tree (ptr_type_node, nextarg));
2124 TREE_SIDE_EFFECTS (t) = 1;
2126 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2130 /* Expand __builtin_va_arg to do the va_arg macro. */
2133 frv_expand_builtin_va_arg(valist, type)
2134 tree valist;
2135 tree type;
2137 rtx addr;
2138 rtx mem;
2139 rtx reg;
2141 if (TARGET_DEBUG_ARG)
2143 fprintf (stderr, "va_arg:\n");
2144 debug_tree (type);
2147 if (! AGGREGATE_TYPE_P (type))
2148 return std_expand_builtin_va_arg (valist, type);
2150 addr = std_expand_builtin_va_arg (valist, ptr_type_node);
2151 mem = gen_rtx_MEM (Pmode, addr);
2152 reg = gen_reg_rtx (Pmode);
2154 set_mem_alias_set (mem, get_varargs_alias_set ());
2155 emit_move_insn (reg, mem);
2157 return reg;
2161 /* Expand a block move operation, and return 1 if successful. Return 0
2162 if we should let the compiler generate normal code.
2164 operands[0] is the destination
2165 operands[1] is the source
2166 operands[2] is the length
2167 operands[3] is the alignment */
2169 /* Maximum number of loads to do before doing the stores */
2170 #ifndef MAX_MOVE_REG
2171 #define MAX_MOVE_REG 4
2172 #endif
2174 /* Maximum number of total loads to do. */
2175 #ifndef TOTAL_MOVE_REG
2176 #define TOTAL_MOVE_REG 8
2177 #endif
2180 frv_expand_block_move (operands)
2181 rtx operands[];
2183 rtx orig_dest = operands[0];
2184 rtx orig_src = operands[1];
2185 rtx bytes_rtx = operands[2];
2186 rtx align_rtx = operands[3];
2187 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2188 int align;
2189 int bytes;
2190 int offset;
2191 int num_reg;
2192 int i;
2193 rtx src_reg;
2194 rtx dest_reg;
2195 rtx src_addr;
2196 rtx dest_addr;
2197 rtx src_mem;
2198 rtx dest_mem;
2199 rtx tmp_reg;
2200 rtx stores[MAX_MOVE_REG];
2201 int move_bytes;
2202 enum machine_mode mode;
2204 /* If this is not a fixed size move, just call memcpy */
2205 if (! constp)
2206 return FALSE;
2208 /* If this is not a fixed size alignment, abort */
2209 if (GET_CODE (align_rtx) != CONST_INT)
2210 abort ();
2212 align = INTVAL (align_rtx);
2214 /* Anything to move? */
2215 bytes = INTVAL (bytes_rtx);
2216 if (bytes <= 0)
2217 return TRUE;
2219 /* Don't support real large moves. */
2220 if (bytes > TOTAL_MOVE_REG*align)
2221 return FALSE;
2223 /* Move the address into scratch registers. */
2224 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2225 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2227 num_reg = offset = 0;
2228 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2230 /* Calculate the correct offset for src/dest */
2231 if (offset == 0)
2233 src_addr = src_reg;
2234 dest_addr = dest_reg;
2236 else
2238 src_addr = plus_constant (src_reg, offset);
2239 dest_addr = plus_constant (dest_reg, offset);
2242 /* Generate the appropriate load and store, saving the stores
2243 for later. */
2244 if (bytes >= 4 && align >= 4)
2245 mode = SImode;
2246 else if (bytes >= 2 && align >= 2)
2247 mode = HImode;
2248 else
2249 mode = QImode;
2251 move_bytes = GET_MODE_SIZE (mode);
2252 tmp_reg = gen_reg_rtx (mode);
2253 src_mem = change_address (orig_src, mode, src_addr);
2254 dest_mem = change_address (orig_dest, mode, dest_addr);
2255 emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem));
2256 stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg);
2258 if (num_reg >= MAX_MOVE_REG)
2260 for (i = 0; i < num_reg; i++)
2261 emit_insn (stores[i]);
2262 num_reg = 0;
2266 for (i = 0; i < num_reg; i++)
2267 emit_insn (stores[i]);
2269 return TRUE;
2273 /* Expand a block clear operation, and return 1 if successful. Return 0
2274 if we should let the compiler generate normal code.
2276 operands[0] is the destination
2277 operands[1] is the length
2278 operands[2] is the alignment */
2281 frv_expand_block_clear (operands)
2282 rtx operands[];
2284 rtx orig_dest = operands[0];
2285 rtx bytes_rtx = operands[1];
2286 rtx align_rtx = operands[2];
2287 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2288 int align;
2289 int bytes;
2290 int offset;
2291 int num_reg;
2292 rtx dest_reg;
2293 rtx dest_addr;
2294 rtx dest_mem;
2295 int clear_bytes;
2296 enum machine_mode mode;
2298 /* If this is not a fixed size move, just call memcpy */
2299 if (! constp)
2300 return FALSE;
2302 /* If this is not a fixed size alignment, abort */
2303 if (GET_CODE (align_rtx) != CONST_INT)
2304 abort ();
2306 align = INTVAL (align_rtx);
2308 /* Anything to move? */
2309 bytes = INTVAL (bytes_rtx);
2310 if (bytes <= 0)
2311 return TRUE;
2313 /* Don't support real large clears. */
2314 if (bytes > TOTAL_MOVE_REG*align)
2315 return FALSE;
2317 /* Move the address into a scratch register. */
2318 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2320 num_reg = offset = 0;
2321 for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes))
2323 /* Calculate the correct offset for src/dest */
2324 dest_addr = ((offset == 0)
2325 ? dest_reg
2326 : plus_constant (dest_reg, offset));
2328 /* Generate the appropriate store of gr0 */
2329 if (bytes >= 4 && align >= 4)
2330 mode = SImode;
2331 else if (bytes >= 2 && align >= 2)
2332 mode = HImode;
2333 else
2334 mode = QImode;
2336 clear_bytes = GET_MODE_SIZE (mode);
2337 dest_mem = change_address (orig_dest, mode, dest_addr);
2338 emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx));
2341 return TRUE;
2345 /* The following variable is used to output modifiers of assembler
2346 code of the current output insn.. */
2348 static rtx *frv_insn_operands;
2350 /* The following function is used to add assembler insn code suffix .p
2351 if it is necessary. */
2353 const char *
2354 frv_asm_output_opcode (f, ptr)
2355 FILE *f;
2356 const char *ptr;
2358 int c;
2360 if (! PACKING_FLAG_USED_P())
2361 return ptr;
2363 for (; *ptr && *ptr != ' ' && *ptr != '\t';)
2365 c = *ptr++;
2366 if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z')
2367 || (*ptr >= 'A' && *ptr <= 'Z')))
2369 int letter = *ptr++;
2371 c = atoi (ptr);
2372 frv_print_operand (f, frv_insn_operands [c], letter);
2373 while ((c = *ptr) >= '0' && c <= '9')
2374 ptr++;
2376 else
2377 fputc (c, f);
2380 if (!frv_insn_packing_flag)
2381 fprintf (f, ".p");
2383 return ptr;
2386 /* The following function sets up the packing bit for the current
2387 output insn. Remember that the function is not called for asm
2388 insns. */
2390 void
2391 frv_final_prescan_insn (insn, opvec, noperands)
2392 rtx insn;
2393 rtx *opvec;
2394 int noperands ATTRIBUTE_UNUSED;
2396 if (! PACKING_FLAG_USED_P())
2397 return;
2399 if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
2400 return;
2402 frv_insn_operands = opvec;
2404 /* Look for the next printable instruction. frv_pack_insns () has set
2405 things up so that any printable instruction will have TImode if it
2406 starts a new packet and VOIDmode if it should be packed with the
2407 previous instruction.
2409 Printable instructions will be asm_operands or match one of the .md
2410 patterns. Since asm instructions cannot be packed -- and will
2411 therefore have TImode -- this loop terminates on any recognisable
2412 instruction, and on any unrecognisable instruction with TImode. */
2413 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
2415 if (NOTE_P (insn))
2416 continue;
2417 else if (!INSN_P (insn))
2418 break;
2419 else if (GET_MODE (insn) == TImode || INSN_CODE (insn) != -1)
2420 break;
2423 /* Set frv_insn_packing_flag to FALSE if the next instruction should
2424 be packed with this one. Set it to TRUE otherwise. If the next
2425 instruction is an asm insntruction, this statement will set the
2426 flag to TRUE, and that value will still hold when the asm operands
2427 themselves are printed. */
2428 frv_insn_packing_flag = ! (insn && INSN_P (insn)
2429 && GET_MODE (insn) != TImode);
2434 /* A C expression whose value is RTL representing the address in a stack frame
2435 where the pointer to the caller's frame is stored. Assume that FRAMEADDR is
2436 an RTL expression for the address of the stack frame itself.
2438 If you don't define this macro, the default is to return the value of
2439 FRAMEADDR--that is, the stack frame address is also the address of the stack
2440 word that points to the previous frame. */
2442 /* The default is correct, but we need to make sure the frame gets created. */
2444 frv_dynamic_chain_address (frame)
2445 rtx frame;
2447 cfun->machine->frame_needed = 1;
2448 return frame;
2452 /* A C expression whose value is RTL representing the value of the return
2453 address for the frame COUNT steps up from the current frame, after the
2454 prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame
2455 pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
2456 defined.
2458 The value of the expression must always be the correct address when COUNT is
2459 zero, but may be `NULL_RTX' if there is not way to determine the return
2460 address of other frames. */
2463 frv_return_addr_rtx (count, frame)
2464 int count ATTRIBUTE_UNUSED;
2465 rtx frame;
2467 cfun->machine->frame_needed = 1;
2468 return gen_rtx_MEM (Pmode, plus_constant (frame, 8));
2471 /* Given a memory reference MEMREF, interpret the referenced memory as
2472 an array of MODE values, and return a reference to the element
2473 specified by INDEX. Assume that any pre-modification implicit in
2474 MEMREF has already happened.
2476 MEMREF must be a legitimate operand for modes larger than SImode.
2477 GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which
2478 this function cannot handle. */
2480 frv_index_memory (memref, mode, index)
2481 rtx memref;
2482 enum machine_mode mode;
2483 int index;
2485 rtx base = XEXP (memref, 0);
2486 if (GET_CODE (base) == PRE_MODIFY)
2487 base = XEXP (base, 0);
2488 return change_address (memref, mode,
2489 plus_constant (base, index * GET_MODE_SIZE (mode)));
2493 /* Print a memory address as an operand to reference that memory location. */
2494 void
2495 frv_print_operand_address (stream, x)
2496 FILE * stream;
2497 rtx x;
2499 if (GET_CODE (x) == MEM)
2500 x = XEXP (x, 0);
2502 switch (GET_CODE (x))
2504 case REG:
2505 fputs (reg_names [ REGNO (x)], stream);
2506 return;
2508 case CONST_INT:
2509 fprintf (stream, "%ld", (long) INTVAL (x));
2510 return;
2512 case SYMBOL_REF:
2513 assemble_name (stream, XSTR (x, 0));
2514 return;
2516 case LABEL_REF:
2517 case CONST:
2518 output_addr_const (stream, x);
2519 return;
2521 default:
2522 break;
2525 fatal_insn ("Bad insn to frv_print_operand_address:", x);
2529 static void
2530 frv_print_operand_memory_reference_reg (stream, x)
2531 FILE *stream;
2532 rtx x;
2534 int regno = true_regnum (x);
2535 if (GPR_P (regno))
2536 fputs (reg_names[regno], stream);
2537 else
2538 fatal_insn ("Bad register to frv_print_operand_memory_reference_reg:", x);
2541 /* Print a memory reference suitable for the ld/st instructions. */
2543 static void
2544 frv_print_operand_memory_reference (stream, x, addr_offset)
2545 FILE *stream;
2546 rtx x;
2547 int addr_offset;
2549 rtx x0 = NULL_RTX;
2550 rtx x1 = NULL_RTX;
2552 switch (GET_CODE (x))
2554 case SUBREG:
2555 case REG:
2556 x0 = x;
2557 break;
2559 case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */
2560 x0 = XEXP (x, 0);
2561 x1 = XEXP (XEXP (x, 1), 1);
2562 break;
2564 case CONST_INT:
2565 x1 = x;
2566 break;
2568 case PLUS:
2569 x0 = XEXP (x, 0);
2570 x1 = XEXP (x, 1);
2571 if (GET_CODE (x0) == CONST_INT)
2573 x0 = XEXP (x, 1);
2574 x1 = XEXP (x, 0);
2576 break;
2578 default:
2579 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2580 break;
2584 if (addr_offset)
2586 if (!x1)
2587 x1 = const0_rtx;
2588 else if (GET_CODE (x1) != CONST_INT)
2589 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2592 fputs ("@(", stream);
2593 if (!x0)
2594 fputs (reg_names[GPR_R0], stream);
2595 else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG)
2596 frv_print_operand_memory_reference_reg (stream, x0);
2597 else
2598 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2600 fputs (",", stream);
2601 if (!x1)
2602 fputs (reg_names [GPR_R0], stream);
2604 else
2606 switch (GET_CODE (x1))
2608 case SUBREG:
2609 case REG:
2610 frv_print_operand_memory_reference_reg (stream, x1);
2611 break;
2613 case CONST_INT:
2614 fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset));
2615 break;
2617 case SYMBOL_REF:
2618 if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG
2619 && symbol_ref_small_data_p (x1))
2621 fputs ("#gprel12(", stream);
2622 assemble_name (stream, XSTR (x1, 0));
2623 fputs (")", stream);
2625 else
2626 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2627 break;
2629 case CONST:
2630 if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG
2631 && const_small_data_p (x1))
2633 fputs ("#gprel12(", stream);
2634 assemble_name (stream, XSTR (XEXP (XEXP (x1, 0), 0), 0));
2635 fprintf (stream, "+%d)", INTVAL (XEXP (XEXP (x1, 0), 1)));
2637 else
2638 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2639 break;
2641 default:
2642 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2646 fputs (")", stream);
2650 /* Return 2 for likely branches and 0 for non-likely branches */
2652 #define FRV_JUMP_LIKELY 2
2653 #define FRV_JUMP_NOT_LIKELY 0
2655 static int
2656 frv_print_operand_jump_hint (insn)
2657 rtx insn;
2659 rtx note;
2660 rtx labelref;
2661 int ret;
2662 HOST_WIDE_INT prob = -1;
2663 enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN;
2665 if (GET_CODE (insn) != JUMP_INSN)
2666 abort ();
2668 /* Assume any non-conditional jump is likely. */
2669 if (! any_condjump_p (insn))
2670 ret = FRV_JUMP_LIKELY;
2672 else
2674 labelref = condjump_label (insn);
2675 if (labelref)
2677 rtx label = XEXP (labelref, 0);
2678 jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label))
2679 ? BACKWARD
2680 : FORWARD);
2683 note = find_reg_note (insn, REG_BR_PROB, 0);
2684 if (!note)
2685 ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY);
2687 else
2689 prob = INTVAL (XEXP (note, 0));
2690 ret = ((prob >= (REG_BR_PROB_BASE / 2))
2691 ? FRV_JUMP_LIKELY
2692 : FRV_JUMP_NOT_LIKELY);
2696 #if 0
2697 if (TARGET_DEBUG)
2699 char *direction;
2701 switch (jump_type)
2703 default:
2704 case UNKNOWN: direction = "unknown jump direction"; break;
2705 case BACKWARD: direction = "jump backward"; break;
2706 case FORWARD: direction = "jump forward"; break;
2709 fprintf (stderr,
2710 "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n",
2711 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
2712 (long)INSN_UID (insn), direction, (long)prob,
2713 (long)REG_BR_PROB_BASE, ret);
2715 #endif
2717 return ret;
2721 /* Print an operand to an assembler instruction.
2723 `%' followed by a letter and a digit says to output an operand in an
2724 alternate fashion. Four letters have standard, built-in meanings described
2725 below. The machine description macro `PRINT_OPERAND' can define additional
2726 letters with nonstandard meanings.
2728 `%cDIGIT' can be used to substitute an operand that is a constant value
2729 without the syntax that normally indicates an immediate operand.
2731 `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated
2732 before printing.
2734 `%aDIGIT' can be used to substitute an operand as if it were a memory
2735 reference, with the actual operand treated as the address. This may be
2736 useful when outputting a "load address" instruction, because often the
2737 assembler syntax for such an instruction requires you to write the operand
2738 as if it were a memory reference.
2740 `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
2742 `%=' outputs a number which is unique to each instruction in the entire
2743 compilation. This is useful for making local labels to be referred to more
2744 than once in a single template that generates multiple assembler
2745 instructions.
2747 `%' followed by a punctuation character specifies a substitution that does
2748 not use an operand. Only one case is standard: `%%' outputs a `%' into the
2749 assembler code. Other nonstandard cases can be defined in the
2750 `PRINT_OPERAND' macro. You must also define which punctuation characters
2751 are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */
2753 void
2754 frv_print_operand (file, x, code)
2755 FILE * file;
2756 rtx x;
2757 int code;
2759 HOST_WIDE_INT value;
2760 int offset;
2762 if (code != 0 && !isalpha (code))
2763 value = 0;
2765 else if (GET_CODE (x) == CONST_INT)
2766 value = INTVAL (x);
2768 else if (GET_CODE (x) == CONST_DOUBLE)
2770 if (GET_MODE (x) == SFmode)
2772 REAL_VALUE_TYPE rv;
2773 long l;
2775 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2776 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2777 value = l;
2780 else if (GET_MODE (x) == VOIDmode)
2781 value = CONST_DOUBLE_LOW (x);
2783 else
2784 fatal_insn ("Bad insn in frv_print_operand, bad const_double", x);
2787 else
2788 value = 0;
2790 switch (code)
2793 case '.':
2794 /* Output r0 */
2795 fputs (reg_names[GPR_R0], file);
2796 break;
2798 case '#':
2799 fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn));
2800 break;
2802 case SDATA_FLAG_CHAR:
2803 /* Output small data area base register (gr16). */
2804 fputs (reg_names[SDA_BASE_REG], file);
2805 break;
2807 case '~':
2808 /* Output pic register (gr17). */
2809 fputs (reg_names[PIC_REGNO], file);
2810 break;
2812 case '*':
2813 /* Output the temporary integer CCR register */
2814 fputs (reg_names[ICR_TEMP], file);
2815 break;
2817 case '&':
2818 /* Output the temporary integer CC register */
2819 fputs (reg_names[ICC_TEMP], file);
2820 break;
2822 /* case 'a': print an address */
2824 case 'C':
2825 /* Print appropriate test for integer branch false operation */
2826 switch (GET_CODE (x))
2828 default:
2829 fatal_insn ("Bad insn to frv_print_operand, 'C' modifier:", x);
2831 case EQ: fputs ("ne", file); break;
2832 case NE: fputs ("eq", file); break;
2833 case LT: fputs ("ge", file); break;
2834 case LE: fputs ("gt", file); break;
2835 case GT: fputs ("le", file); break;
2836 case GE: fputs ("lt", file); break;
2837 case LTU: fputs ("nc", file); break;
2838 case LEU: fputs ("hi", file); break;
2839 case GTU: fputs ("ls", file); break;
2840 case GEU: fputs ("c", file); break;
2842 break;
2844 /* case 'c': print a constant without the constant prefix. If
2845 CONSTANT_ADDRESS_P(x) is not true, PRINT_OPERAND is called. */
2847 case 'c':
2848 /* Print appropriate test for integer branch true operation */
2849 switch (GET_CODE (x))
2851 default:
2852 fatal_insn ("Bad insn to frv_print_operand, 'c' modifier:", x);
2854 case EQ: fputs ("eq", file); break;
2855 case NE: fputs ("ne", file); break;
2856 case LT: fputs ("lt", file); break;
2857 case LE: fputs ("le", file); break;
2858 case GT: fputs ("gt", file); break;
2859 case GE: fputs ("ge", file); break;
2860 case LTU: fputs ("c", file); break;
2861 case LEU: fputs ("ls", file); break;
2862 case GTU: fputs ("hi", file); break;
2863 case GEU: fputs ("nc", file); break;
2865 break;
2867 case 'e':
2868 /* Print 1 for a NE and 0 for an EQ to give the final argument
2869 for a conditional instruction. */
2870 if (GET_CODE (x) == NE)
2871 fputs ("1", file);
2873 else if (GET_CODE (x) == EQ)
2874 fputs ("0", file);
2876 else
2877 fatal_insn ("Bad insn to frv_print_operand, 'e' modifier:", x);
2878 break;
2880 case 'F':
2881 /* Print appropriate test for floating point branch false operation */
2882 switch (GET_CODE (x))
2884 default:
2885 fatal_insn ("Bad insn to frv_print_operand, 'F' modifier:", x);
2887 case EQ: fputs ("ne", file); break;
2888 case NE: fputs ("eq", file); break;
2889 case LT: fputs ("uge", file); break;
2890 case LE: fputs ("ug", file); break;
2891 case GT: fputs ("ule", file); break;
2892 case GE: fputs ("ul", file); break;
2894 break;
2896 case 'f':
2897 /* Print appropriate test for floating point branch true operation */
2898 switch (GET_CODE (x))
2900 default:
2901 fatal_insn ("Bad insn to frv_print_operand, 'f' modifier:", x);
2903 case EQ: fputs ("eq", file); break;
2904 case NE: fputs ("ne", file); break;
2905 case LT: fputs ("lt", file); break;
2906 case LE: fputs ("le", file); break;
2907 case GT: fputs ("gt", file); break;
2908 case GE: fputs ("ge", file); break;
2910 break;
2912 case 'I':
2913 /* Print 'i' if the operand is a constant, or is a memory reference that
2914 adds a constant */
2915 if (GET_CODE (x) == MEM)
2916 x = ((GET_CODE (XEXP (x, 0)) == PLUS)
2917 ? XEXP (XEXP (x, 0), 1)
2918 : XEXP (x, 0));
2920 switch (GET_CODE (x))
2922 default:
2923 break;
2925 case CONST_INT:
2926 case SYMBOL_REF:
2927 case CONST:
2928 fputs ("i", file);
2929 break;
2931 break;
2933 case 'i':
2934 /* For jump instructions, print 'i' if the operand is a constant or
2935 is an expression that adds a constant */
2936 if (GET_CODE (x) == CONST_INT)
2937 fputs ("i", file);
2939 else
2941 if (GET_CODE (x) == CONST_INT
2942 || (GET_CODE (x) == PLUS
2943 && (GET_CODE (XEXP (x, 1)) == CONST_INT
2944 || GET_CODE (XEXP (x, 0)) == CONST_INT)))
2945 fputs ("i", file);
2947 break;
2949 case 'L':
2950 /* Print the lower register of a double word register pair */
2951 if (GET_CODE (x) == REG)
2952 fputs (reg_names[ REGNO (x)+1 ], file);
2953 else
2954 fatal_insn ("Bad insn to frv_print_operand, 'L' modifier:", x);
2955 break;
2957 /* case 'l': print a LABEL_REF */
2959 case 'M':
2960 case 'N':
2961 /* Print a memory reference for ld/st/jmp, %N prints a memory reference
2962 for the second word of double memory operations. */
2963 offset = (code == 'M') ? 0 : UNITS_PER_WORD;
2964 switch (GET_CODE (x))
2966 default:
2967 fatal_insn ("Bad insn to frv_print_operand, 'M/N' modifier:", x);
2969 case MEM:
2970 frv_print_operand_memory_reference (file, XEXP (x, 0), offset);
2971 break;
2973 case REG:
2974 case SUBREG:
2975 case CONST_INT:
2976 case PLUS:
2977 case SYMBOL_REF:
2978 frv_print_operand_memory_reference (file, x, offset);
2979 break;
2981 break;
2983 case 'O':
2984 /* Print the opcode of a command. */
2985 switch (GET_CODE (x))
2987 default:
2988 fatal_insn ("Bad insn to frv_print_operand, 'O' modifier:", x);
2990 case PLUS: fputs ("add", file); break;
2991 case MINUS: fputs ("sub", file); break;
2992 case AND: fputs ("and", file); break;
2993 case IOR: fputs ("or", file); break;
2994 case XOR: fputs ("xor", file); break;
2995 case ASHIFT: fputs ("sll", file); break;
2996 case ASHIFTRT: fputs ("sra", file); break;
2997 case LSHIFTRT: fputs ("srl", file); break;
2999 break;
3001 /* case 'n': negate and print a constant int */
3003 case 'P':
3004 /* Print PIC label using operand as the number. */
3005 if (GET_CODE (x) != CONST_INT)
3006 fatal_insn ("Bad insn to frv_print_operand, P modifier:", x);
3008 fprintf (file, ".LCF%ld", (long)INTVAL (x));
3009 break;
3011 case 'U':
3012 /* Print 'u' if the operand is a update load/store */
3013 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
3014 fputs ("u", file);
3015 break;
3017 case 'z':
3018 /* If value is 0, print gr0, otherwise it must be a register */
3019 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
3020 fputs (reg_names[GPR_R0], file);
3022 else if (GET_CODE (x) == REG)
3023 fputs (reg_names [REGNO (x)], file);
3025 else
3026 fatal_insn ("Bad insn in frv_print_operand, z case", x);
3027 break;
3029 case 'x':
3030 /* Print constant in hex */
3031 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
3033 fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value);
3034 break;
3037 /* fall through */
3039 case '\0':
3040 if (GET_CODE (x) == REG)
3041 fputs (reg_names [REGNO (x)], file);
3043 else if (GET_CODE (x) == CONST_INT
3044 || GET_CODE (x) == CONST_DOUBLE)
3045 fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value);
3047 else if (GET_CODE (x) == MEM)
3048 frv_print_operand_address (file, XEXP (x, 0));
3050 else if (CONSTANT_ADDRESS_P (x))
3051 frv_print_operand_address (file, x);
3053 else
3054 fatal_insn ("Bad insn in frv_print_operand, 0 case", x);
3056 break;
3058 default:
3059 fatal_insn ("frv_print_operand: unknown code", x);
3060 break;
3063 return;
3067 /* A C statement (sans semicolon) for initializing the variable CUM for the
3068 state at the beginning of the argument list. The variable has type
3069 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
3070 of the function which will receive the args, or 0 if the args are to a
3071 compiler support library function. The value of INDIRECT is nonzero when
3072 processing an indirect call, for example a call through a function pointer.
3073 The value of INDIRECT is zero for a call to an explicitly named function, a
3074 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
3075 arguments for the function being compiled.
3077 When processing a call to a compiler support library function, LIBNAME
3078 identifies which one. It is a `symbol_ref' rtx which contains the name of
3079 the function, as a string. LIBNAME is 0 when an ordinary C function call is
3080 being processed. Thus, each time this macro is called, either LIBNAME or
3081 FNTYPE is nonzero, but never both of them at once. */
3083 void
3084 frv_init_cumulative_args (cum, fntype, libname, indirect, incoming)
3085 CUMULATIVE_ARGS *cum;
3086 tree fntype;
3087 rtx libname;
3088 int indirect;
3089 int incoming;
3091 *cum = FIRST_ARG_REGNUM;
3093 if (TARGET_DEBUG_ARG)
3095 fprintf (stderr, "\ninit_cumulative_args:");
3096 if (indirect)
3097 fputs (" indirect", stderr);
3099 if (incoming)
3100 fputs (" incoming", stderr);
3102 if (fntype)
3104 tree ret_type = TREE_TYPE (fntype);
3105 fprintf (stderr, " return=%s,",
3106 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3109 if (libname && GET_CODE (libname) == SYMBOL_REF)
3110 fprintf (stderr, " libname=%s", XSTR (libname, 0));
3112 if (cfun->returns_struct)
3113 fprintf (stderr, " return-struct");
3115 putc ('\n', stderr);
3120 /* If defined, a C expression that gives the alignment boundary, in bits, of an
3121 argument with the specified mode and type. If it is not defined,
3122 `PARM_BOUNDARY' is used for all arguments. */
3125 frv_function_arg_boundary (mode, type)
3126 enum machine_mode mode ATTRIBUTE_UNUSED;
3127 tree type ATTRIBUTE_UNUSED;
3129 return BITS_PER_WORD;
3133 /* A C expression that controls whether a function argument is passed in a
3134 register, and which register.
3136 The arguments are CUM, of type CUMULATIVE_ARGS, which summarizes (in a way
3137 defined by INIT_CUMULATIVE_ARGS and FUNCTION_ARG_ADVANCE) all of the previous
3138 arguments so far passed in registers; MODE, the machine mode of the argument;
3139 TYPE, the data type of the argument as a tree node or 0 if that is not known
3140 (which happens for C support library functions); and NAMED, which is 1 for an
3141 ordinary argument and 0 for nameless arguments that correspond to `...' in the
3142 called function's prototype.
3144 The value of the expression should either be a `reg' RTX for the hard
3145 register in which to pass the argument, or zero to pass the argument on the
3146 stack.
3148 For machines like the VAX and 68000, where normally all arguments are
3149 pushed, zero suffices as a definition.
3151 The usual way to make the ANSI library `stdarg.h' work on a machine where
3152 some arguments are usually passed in registers, is to cause nameless
3153 arguments to be passed on the stack instead. This is done by making
3154 `FUNCTION_ARG' return 0 whenever NAMED is 0.
3156 You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the definition of
3157 this macro to determine if this argument is of a type that must be passed in
3158 the stack. If `REG_PARM_STACK_SPACE' is not defined and `FUNCTION_ARG'
3159 returns nonzero for such an argument, the compiler will abort. If
3160 `REG_PARM_STACK_SPACE' is defined, the argument will be computed in the
3161 stack and then loaded into a register. */
3164 frv_function_arg (cum, mode, type, named, incoming)
3165 CUMULATIVE_ARGS *cum;
3166 enum machine_mode mode;
3167 tree type ATTRIBUTE_UNUSED;
3168 int named;
3169 int incoming ATTRIBUTE_UNUSED;
3171 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3172 int arg_num = *cum;
3173 rtx ret;
3174 const char *debstr;
3176 /* Return a marker for use in the call instruction. */
3177 if (xmode == VOIDmode)
3179 ret = const0_rtx;
3180 debstr = "<0>";
3183 else if (arg_num <= LAST_ARG_REGNUM)
3185 ret = gen_rtx (REG, xmode, arg_num);
3186 debstr = reg_names[arg_num];
3189 else
3191 ret = NULL_RTX;
3192 debstr = "memory";
3195 if (TARGET_DEBUG_ARG)
3196 fprintf (stderr,
3197 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n",
3198 arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr);
3200 return ret;
3204 /* A C statement (sans semicolon) to update the summarizer variable CUM to
3205 advance past an argument in the argument list. The values MODE, TYPE and
3206 NAMED describe that argument. Once this is done, the variable CUM is
3207 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
3209 This macro need not do anything if the argument in question was passed on
3210 the stack. The compiler knows how to track the amount of stack space used
3211 for arguments without any special help. */
3213 void
3214 frv_function_arg_advance (cum, mode, type, named)
3215 CUMULATIVE_ARGS *cum;
3216 enum machine_mode mode;
3217 tree type ATTRIBUTE_UNUSED;
3218 int named;
3220 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3221 int bytes = GET_MODE_SIZE (xmode);
3222 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3223 int arg_num = *cum;
3225 *cum = arg_num + words;
3227 if (TARGET_DEBUG_ARG)
3228 fprintf (stderr,
3229 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n",
3230 arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD);
3234 /* A C expression for the number of words, at the beginning of an argument,
3235 must be put in registers. The value must be zero for arguments that are
3236 passed entirely in registers or that are entirely pushed on the stack.
3238 On some machines, certain arguments must be passed partially in registers
3239 and partially in memory. On these machines, typically the first N words of
3240 arguments are passed in registers, and the rest on the stack. If a
3241 multi-word argument (a `double' or a structure) crosses that boundary, its
3242 first few words must be passed in registers and the rest must be pushed.
3243 This macro tells the compiler when this occurs, and how many of the words
3244 should go in registers.
3246 `FUNCTION_ARG' for these arguments should return the first register to be
3247 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
3248 the called function. */
3251 frv_function_arg_partial_nregs (cum, mode, type, named)
3252 CUMULATIVE_ARGS *cum;
3253 enum machine_mode mode;
3254 tree type ATTRIBUTE_UNUSED;
3255 int named ATTRIBUTE_UNUSED;
3257 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3258 int bytes = GET_MODE_SIZE (xmode);
3259 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3260 int arg_num = *cum;
3261 int ret;
3263 ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1)
3264 ? LAST_ARG_REGNUM - arg_num + 1
3265 : 0);
3267 if (TARGET_DEBUG_ARG && ret)
3268 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3270 return ret;
3276 /* A C expression that indicates when an argument must be passed by reference.
3277 If nonzero for an argument, a copy of that argument is made in memory and a
3278 pointer to the argument is passed instead of the argument itself. The
3279 pointer is passed in whatever way is appropriate for passing a pointer to
3280 that type.
3282 On machines where `REG_PARM_STACK_SPACE' is not defined, a suitable
3283 definition of this macro might be
3284 #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) \
3285 MUST_PASS_IN_STACK (MODE, TYPE) */
3288 frv_function_arg_pass_by_reference (cum, mode, type, named)
3289 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3290 enum machine_mode mode;
3291 tree type;
3292 int named ATTRIBUTE_UNUSED;
3294 return MUST_PASS_IN_STACK (mode, type);
3297 /* If defined, a C expression that indicates when it is the called function's
3298 responsibility to make a copy of arguments passed by invisible reference.
3299 Normally, the caller makes a copy and passes the address of the copy to the
3300 routine being called. When FUNCTION_ARG_CALLEE_COPIES is defined and is
3301 nonzero, the caller does not make a copy. Instead, it passes a pointer to
3302 the "live" value. The called function must not modify this value. If it
3303 can be determined that the value won't be modified, it need not make a copy;
3304 otherwise a copy must be made. */
3307 frv_function_arg_callee_copies (cum, mode, type, named)
3308 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3309 enum machine_mode mode ATTRIBUTE_UNUSED;
3310 tree type ATTRIBUTE_UNUSED;
3311 int named ATTRIBUTE_UNUSED;
3313 return 0;
3316 /* If defined, a C expression that indicates when it is more desirable to keep
3317 an argument passed by invisible reference as a reference, rather than
3318 copying it to a pseudo register. */
3321 frv_function_arg_keep_as_reference (cum, mode, type, named)
3322 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3323 enum machine_mode mode ATTRIBUTE_UNUSED;
3324 tree type ATTRIBUTE_UNUSED;
3325 int named ATTRIBUTE_UNUSED;
3327 return 0;
3331 /* Return true if a register is ok to use as a base or index register. */
3333 static FRV_INLINE int
3334 frv_regno_ok_for_base_p (regno, strict_p)
3335 int regno;
3336 int strict_p;
3338 if (GPR_P (regno))
3339 return TRUE;
3341 if (strict_p)
3342 return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno]));
3344 if (regno == ARG_POINTER_REGNUM)
3345 return TRUE;
3347 return (regno >= FIRST_PSEUDO_REGISTER);
3351 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3352 RTX) is a legitimate memory address on the target machine for a memory
3353 operand of mode MODE.
3355 It usually pays to define several simpler macros to serve as subroutines for
3356 this one. Otherwise it may be too complicated to understand.
3358 This macro must exist in two variants: a strict variant and a non-strict
3359 one. The strict variant is used in the reload pass. It must be defined so
3360 that any pseudo-register that has not been allocated a hard register is
3361 considered a memory reference. In contexts where some kind of register is
3362 required, a pseudo-register with no hard register must be rejected.
3364 The non-strict variant is used in other passes. It must be defined to
3365 accept all pseudo-registers in every context where some kind of register is
3366 required.
3368 Compiler source files that want to use the strict variant of this macro
3369 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3370 conditional to define the strict variant in that case and the non-strict
3371 variant otherwise.
3373 Subroutines to check for acceptable registers for various purposes (one for
3374 base registers, one for index registers, and so on) are typically among the
3375 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3376 subroutine macros need have two variants; the higher levels of macros may be
3377 the same whether strict or not.
3379 Normally, constant addresses which are the sum of a `symbol_ref' and an
3380 integer are stored inside a `const' RTX to mark them as constant.
3381 Therefore, there is no need to recognize such sums specifically as
3382 legitimate addresses. Normally you would simply recognize any `const' as
3383 legitimate.
3385 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3386 are not marked with `const'. It assumes that a naked `plus' indicates
3387 indexing. If so, then you *must* reject such naked constant sums as
3388 illegitimate addresses, so that none of them will be given to
3389 `PRINT_OPERAND_ADDRESS'.
3391 On some machines, whether a symbolic address is legitimate depends on the
3392 section that the address refers to. On these machines, define the macro
3393 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3394 then check for it here. When you see a `const', you will have to look
3395 inside it to find the `symbol_ref' in order to determine the section.
3397 The best way to modify the name string is by adding text to the beginning,
3398 with suitable punctuation to prevent any ambiguity. Allocate the new name
3399 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3400 remove and decode the added text and output the name accordingly, and define
3401 `(* targetm.strip_name_encoding)' to access the original name string.
3403 You can check the information stored here into the `symbol_ref' in the
3404 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3405 `PRINT_OPERAND_ADDRESS'. */
3408 frv_legitimate_address_p (mode, x, strict_p, condexec_p)
3409 enum machine_mode mode;
3410 rtx x;
3411 int strict_p;
3412 int condexec_p;
3414 rtx x0, x1;
3415 int ret = 0;
3416 HOST_WIDE_INT value;
3417 unsigned regno0;
3419 switch (GET_CODE (x))
3421 default:
3422 break;
3424 case SUBREG:
3425 x = SUBREG_REG (x);
3426 if (GET_CODE (x) != REG)
3427 break;
3429 /* fall through */
3431 case REG:
3432 ret = frv_regno_ok_for_base_p (REGNO (x), strict_p);
3433 break;
3435 case PRE_MODIFY:
3436 x0 = XEXP (x, 0);
3437 x1 = XEXP (x, 1);
3438 if (GET_CODE (x0) != REG
3439 || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p)
3440 || GET_CODE (x1) != PLUS
3441 || ! rtx_equal_p (x0, XEXP (x1, 0))
3442 || GET_CODE (XEXP (x1, 1)) != REG
3443 || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p))
3444 break;
3446 ret = 1;
3447 break;
3449 case CONST_INT:
3450 /* 12 bit immediate */
3451 if (condexec_p)
3452 ret = FALSE;
3453 else
3455 ret = IN_RANGE_P (INTVAL (x), -2048, 2047);
3457 /* If we can't use load/store double operations, make sure we can
3458 address the second word. */
3459 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3460 ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1,
3461 -2048, 2047);
3463 break;
3465 case PLUS:
3466 x0 = XEXP (x, 0);
3467 x1 = XEXP (x, 1);
3469 if (GET_CODE (x0) == SUBREG)
3470 x0 = SUBREG_REG (x0);
3472 if (GET_CODE (x0) != REG)
3473 break;
3475 regno0 = REGNO (x0);
3476 if (!frv_regno_ok_for_base_p (regno0, strict_p))
3477 break;
3479 switch (GET_CODE (x1))
3481 default:
3482 break;
3484 case SUBREG:
3485 x1 = SUBREG_REG (x1);
3486 if (GET_CODE (x1) != REG)
3487 break;
3489 /* fall through */
3491 case REG:
3492 /* Do not allow reg+reg addressing for modes > 1 word if we can't depend
3493 on having move double instructions */
3494 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3495 ret = FALSE;
3496 else
3497 ret = frv_regno_ok_for_base_p (REGNO (x1), strict_p);
3498 break;
3500 case CONST_INT:
3501 /* 12 bit immediate */
3502 if (condexec_p)
3503 ret = FALSE;
3504 else
3506 value = INTVAL (x1);
3507 ret = IN_RANGE_P (value, -2048, 2047);
3509 /* If we can't use load/store double operations, make sure we can
3510 address the second word. */
3511 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3512 ret = IN_RANGE_P (value + GET_MODE_SIZE (mode) - 1, -2048, 2047);
3514 break;
3516 case SYMBOL_REF:
3517 if (!condexec_p
3518 && regno0 == SDA_BASE_REG
3519 && symbol_ref_small_data_p (x1))
3520 ret = TRUE;
3521 break;
3523 case CONST:
3524 if (!condexec_p && regno0 == SDA_BASE_REG && const_small_data_p (x1))
3525 ret = TRUE;
3526 break;
3529 break;
3532 if (TARGET_DEBUG_ADDR)
3534 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict%s\n",
3535 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ",
3536 (condexec_p) ? ", inside conditional code" : "");
3537 debug_rtx (x);
3540 return ret;
3544 /* A C compound statement that attempts to replace X with a valid memory
3545 address for an operand of mode MODE. WIN will be a C statement label
3546 elsewhere in the code; the macro definition may use
3548 GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
3550 to avoid further processing if the address has become legitimate.
3552 X will always be the result of a call to `break_out_memory_refs', and OLDX
3553 will be the operand that was given to that function to produce X.
3555 The code generated by this macro should not alter the substructure of X. If
3556 it transforms X into a more legitimate form, it should assign X (which will
3557 always be a C variable) a new value.
3559 It is not necessary for this macro to come up with a legitimate address.
3560 The compiler has standard ways of doing so in all cases. In fact, it is
3561 safe for this macro to do nothing. But often a machine-dependent strategy
3562 can generate better code. */
3565 frv_legitimize_address (x, oldx, mode)
3566 rtx x;
3567 rtx oldx ATTRIBUTE_UNUSED;
3568 enum machine_mode mode ATTRIBUTE_UNUSED;
3570 rtx ret = NULL_RTX;
3572 /* Don't try to legitimize addresses if we are not optimizing, since the
3573 address we generate is not a general operand, and will horribly mess
3574 things up when force_reg is called to try and put it in a register because
3575 we aren't optimizing. */
3576 if (optimize
3577 && ((GET_CODE (x) == SYMBOL_REF && symbol_ref_small_data_p (x))
3578 || (GET_CODE (x) == CONST && const_small_data_p (x))))
3580 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, SDA_BASE_REG), x);
3581 if (flag_pic)
3582 cfun->uses_pic_offset_table = TRUE;
3585 if (TARGET_DEBUG_ADDR && ret != NULL_RTX)
3587 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, mode = %s, modified address\n",
3588 GET_MODE_NAME (mode));
3589 debug_rtx (ret);
3592 return ret;
3595 /* Return 1 if operand is a valid FRV address. CONDEXEC_P is true if
3596 the operand is used by a predicated instruction. */
3598 static int
3599 frv_legitimate_memory_operand (op, mode, condexec_p)
3600 rtx op;
3601 enum machine_mode mode;
3602 int condexec_p;
3604 return ((GET_MODE (op) == mode || mode == VOIDmode)
3605 && GET_CODE (op) == MEM
3606 && frv_legitimate_address_p (mode, XEXP (op, 0),
3607 reload_completed, condexec_p));
3611 /* Return 1 is OP is a memory operand, or will be turned into one by
3612 reload. */
3614 int frv_load_operand (op, mode)
3615 rtx op;
3616 enum machine_mode mode;
3618 if (GET_MODE (op) != mode && mode != VOIDmode)
3619 return FALSE;
3621 if (reload_in_progress)
3623 rtx tmp = op;
3624 if (GET_CODE (tmp) == SUBREG)
3625 tmp = SUBREG_REG (tmp);
3626 if (GET_CODE (tmp) == REG
3627 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
3628 op = reg_equiv_memory_loc[REGNO (tmp)];
3631 return op && memory_operand (op, mode);
3635 /* Return 1 if operand is a GPR register or a FPR register. */
3637 int gpr_or_fpr_operand (op, mode)
3638 rtx op;
3639 enum machine_mode mode;
3641 int regno;
3643 if (GET_MODE (op) != mode && mode != VOIDmode)
3644 return FALSE;
3646 if (GET_CODE (op) == SUBREG)
3648 if (GET_CODE (SUBREG_REG (op)) != REG)
3649 return register_operand (op, mode);
3651 op = SUBREG_REG (op);
3654 if (GET_CODE (op) != REG)
3655 return FALSE;
3657 regno = REGNO (op);
3658 if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER)
3659 return TRUE;
3661 return FALSE;
3664 /* Return 1 if operand is a GPR register or 12 bit signed immediate. */
3666 int gpr_or_int12_operand (op, mode)
3667 rtx op;
3668 enum machine_mode mode;
3670 if (GET_CODE (op) == CONST_INT)
3671 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3673 if (GET_MODE (op) != mode && mode != VOIDmode)
3674 return FALSE;
3676 if (GET_CODE (op) == SUBREG)
3678 if (GET_CODE (SUBREG_REG (op)) != REG)
3679 return register_operand (op, mode);
3681 op = SUBREG_REG (op);
3684 if (GET_CODE (op) != REG)
3685 return FALSE;
3687 return GPR_OR_PSEUDO_P (REGNO (op));
3690 /* Return 1 if operand is a GPR register, or a FPR register, or a 12 bit
3691 signed immediate. */
3693 int gpr_fpr_or_int12_operand (op, mode)
3694 rtx op;
3695 enum machine_mode mode;
3697 int regno;
3699 if (GET_CODE (op) == CONST_INT)
3700 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3702 if (GET_MODE (op) != mode && mode != VOIDmode)
3703 return FALSE;
3705 if (GET_CODE (op) == SUBREG)
3707 if (GET_CODE (SUBREG_REG (op)) != REG)
3708 return register_operand (op, mode);
3710 op = SUBREG_REG (op);
3713 if (GET_CODE (op) != REG)
3714 return FALSE;
3716 regno = REGNO (op);
3717 if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER)
3718 return TRUE;
3720 return FALSE;
3723 /* Return 1 if operand is a register or 6 bit signed immediate. */
3725 int fpr_or_int6_operand (op, mode)
3726 rtx op;
3727 enum machine_mode mode;
3729 if (GET_CODE (op) == CONST_INT)
3730 return IN_RANGE_P (INTVAL (op), -32, 31);
3732 if (GET_MODE (op) != mode && mode != VOIDmode)
3733 return FALSE;
3735 if (GET_CODE (op) == SUBREG)
3737 if (GET_CODE (SUBREG_REG (op)) != REG)
3738 return register_operand (op, mode);
3740 op = SUBREG_REG (op);
3743 if (GET_CODE (op) != REG)
3744 return FALSE;
3746 return FPR_OR_PSEUDO_P (REGNO (op));
3749 /* Return 1 if operand is a register or 10 bit signed immediate. */
3751 int gpr_or_int10_operand (op, mode)
3752 rtx op;
3753 enum machine_mode mode;
3755 if (GET_CODE (op) == CONST_INT)
3756 return IN_RANGE_P (INTVAL (op), -512, 511);
3758 if (GET_MODE (op) != mode && mode != VOIDmode)
3759 return FALSE;
3761 if (GET_CODE (op) == SUBREG)
3763 if (GET_CODE (SUBREG_REG (op)) != REG)
3764 return register_operand (op, mode);
3766 op = SUBREG_REG (op);
3769 if (GET_CODE (op) != REG)
3770 return FALSE;
3772 return GPR_OR_PSEUDO_P (REGNO (op));
3775 /* Return 1 if operand is a register or an integer immediate. */
3777 int gpr_or_int_operand (op, mode)
3778 rtx op;
3779 enum machine_mode mode;
3781 if (GET_CODE (op) == CONST_INT)
3782 return TRUE;
3784 if (GET_MODE (op) != mode && mode != VOIDmode)
3785 return FALSE;
3787 if (GET_CODE (op) == SUBREG)
3789 if (GET_CODE (SUBREG_REG (op)) != REG)
3790 return register_operand (op, mode);
3792 op = SUBREG_REG (op);
3795 if (GET_CODE (op) != REG)
3796 return FALSE;
3798 return GPR_OR_PSEUDO_P (REGNO (op));
3801 /* Return 1 if operand is a 12 bit signed immediate. */
3803 int int12_operand (op, mode)
3804 rtx op;
3805 enum machine_mode mode ATTRIBUTE_UNUSED;
3807 if (GET_CODE (op) != CONST_INT)
3808 return FALSE;
3810 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3813 /* Return 1 if operand is a 6 bit signed immediate. */
3815 int int6_operand (op, mode)
3816 rtx op;
3817 enum machine_mode mode ATTRIBUTE_UNUSED;
3819 if (GET_CODE (op) != CONST_INT)
3820 return FALSE;
3822 return IN_RANGE_P (INTVAL (op), -32, 31);
3825 /* Return 1 if operand is a 5 bit signed immediate. */
3827 int int5_operand (op, mode)
3828 rtx op;
3829 enum machine_mode mode ATTRIBUTE_UNUSED;
3831 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), -16, 15);
3834 /* Return 1 if operand is a 5 bit unsigned immediate. */
3836 int uint5_operand (op, mode)
3837 rtx op;
3838 enum machine_mode mode ATTRIBUTE_UNUSED;
3840 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 31);
3843 /* Return 1 if operand is a 4 bit unsigned immediate. */
3845 int uint4_operand (op, mode)
3846 rtx op;
3847 enum machine_mode mode ATTRIBUTE_UNUSED;
3849 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 15);
3852 /* Return 1 if operand is a 1 bit unsigned immediate (0 or 1). */
3854 int uint1_operand (op, mode)
3855 rtx op;
3856 enum machine_mode mode ATTRIBUTE_UNUSED;
3858 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 1);
3861 /* Return 1 if operand is an integer constant that takes 2 instructions
3862 to load up and can be split into sethi/setlo instructions.. */
3864 int int_2word_operand (op, mode)
3865 rtx op;
3866 enum machine_mode mode ATTRIBUTE_UNUSED;
3868 HOST_WIDE_INT value;
3869 REAL_VALUE_TYPE rv;
3870 long l;
3872 switch (GET_CODE (op))
3874 default:
3875 break;
3877 case LABEL_REF:
3878 return (flag_pic == 0);
3880 case CONST:
3881 /* small data references are already 1 word */
3882 return (flag_pic == 0) && (! const_small_data_p (op));
3884 case SYMBOL_REF:
3885 /* small data references are already 1 word */
3886 return (flag_pic == 0) && (! symbol_ref_small_data_p (op));
3888 case CONST_INT:
3889 return ! IN_RANGE_P (INTVAL (op), -32768, 32767);
3891 case CONST_DOUBLE:
3892 if (GET_MODE (op) == SFmode)
3894 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
3895 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
3896 value = l;
3897 return ! IN_RANGE_P (value, -32768, 32767);
3899 else if (GET_MODE (op) == VOIDmode)
3901 value = CONST_DOUBLE_LOW (op);
3902 return ! IN_RANGE_P (value, -32768, 32767);
3904 break;
3907 return FALSE;
3910 /* Return 1 if operand is the pic address register. */
3912 pic_register_operand (op, mode)
3913 rtx op;
3914 enum machine_mode mode ATTRIBUTE_UNUSED;
3916 if (! flag_pic)
3917 return FALSE;
3919 if (GET_CODE (op) != REG)
3920 return FALSE;
3922 if (REGNO (op) != PIC_REGNO)
3923 return FALSE;
3925 return TRUE;
3928 /* Return 1 if operand is a symbolic reference when a PIC option is specified
3929 that takes 3 seperate instructions to form. */
3931 int pic_symbolic_operand (op, mode)
3932 rtx op;
3933 enum machine_mode mode ATTRIBUTE_UNUSED;
3935 if (! flag_pic)
3936 return FALSE;
3938 switch (GET_CODE (op))
3940 default:
3941 break;
3943 case LABEL_REF:
3944 return TRUE;
3946 case SYMBOL_REF:
3947 /* small data references are already 1 word */
3948 return ! symbol_ref_small_data_p (op);
3950 case CONST:
3951 /* small data references are already 1 word */
3952 return ! const_small_data_p (op);
3955 return FALSE;
3958 /* Return 1 if operand is the small data register. */
3960 small_data_register_operand (op, mode)
3961 rtx op;
3962 enum machine_mode mode ATTRIBUTE_UNUSED;
3964 if (GET_CODE (op) != REG)
3965 return FALSE;
3967 if (REGNO (op) != SDA_BASE_REG)
3968 return FALSE;
3970 return TRUE;
3973 /* Return 1 if operand is a symbolic reference to a small data area static or
3974 global object. */
3976 int small_data_symbolic_operand (op, mode)
3977 rtx op;
3978 enum machine_mode mode ATTRIBUTE_UNUSED;
3980 switch (GET_CODE (op))
3982 default:
3983 break;
3985 case CONST:
3986 return const_small_data_p (op);
3988 case SYMBOL_REF:
3989 return symbol_ref_small_data_p (op);
3992 return FALSE;
3995 /* Return 1 if operand is a 16 bit unsigned immediate */
3997 int uint16_operand (op, mode)
3998 rtx op;
3999 enum machine_mode mode ATTRIBUTE_UNUSED;
4001 if (GET_CODE (op) != CONST_INT)
4002 return FALSE;
4004 return IN_RANGE_P (INTVAL (op), 0, 0xffff);
4007 /* Return 1 if operand is an integer constant with the bottom 16 bits clear */
4009 int upper_int16_operand (op, mode)
4010 rtx op;
4011 enum machine_mode mode ATTRIBUTE_UNUSED;
4013 if (GET_CODE (op) != CONST_INT)
4014 return FALSE;
4016 return ((INTVAL (op) & 0xffff) == 0);
4019 /* Return true if operand is a GPR register. */
4022 integer_register_operand (op, mode)
4023 rtx op;
4024 enum machine_mode mode;
4026 if (GET_MODE (op) != mode && mode != VOIDmode)
4027 return FALSE;
4029 if (GET_CODE (op) == SUBREG)
4031 if (GET_CODE (SUBREG_REG (op)) != REG)
4032 return register_operand (op, mode);
4034 op = SUBREG_REG (op);
4037 if (GET_CODE (op) != REG)
4038 return FALSE;
4040 return GPR_OR_PSEUDO_P (REGNO (op));
4043 /* Return true if operand is a GPR register. Do not allow SUBREG's
4044 here, in order to prevent a combine bug. */
4047 gpr_no_subreg_operand (op, mode)
4048 rtx op;
4049 enum machine_mode mode;
4051 if (GET_MODE (op) != mode && mode != VOIDmode)
4052 return FALSE;
4054 if (GET_CODE (op) != REG)
4055 return FALSE;
4057 return GPR_OR_PSEUDO_P (REGNO (op));
4060 /* Return true if operand is a FPR register. */
4063 fpr_operand (op, mode)
4064 rtx op;
4065 enum machine_mode mode;
4067 if (GET_MODE (op) != mode && mode != VOIDmode)
4068 return FALSE;
4070 if (GET_CODE (op) == SUBREG)
4072 if (GET_CODE (SUBREG_REG (op)) != REG)
4073 return register_operand (op, mode);
4075 op = SUBREG_REG (op);
4078 if (GET_CODE (op) != REG)
4079 return FALSE;
4081 return FPR_OR_PSEUDO_P (REGNO (op));
4084 /* Return true if operand is an even GPR or FPR register. */
4087 even_reg_operand (op, mode)
4088 rtx op;
4089 enum machine_mode mode;
4091 int regno;
4093 if (GET_MODE (op) != mode && mode != VOIDmode)
4094 return FALSE;
4096 if (GET_CODE (op) == SUBREG)
4098 if (GET_CODE (SUBREG_REG (op)) != REG)
4099 return register_operand (op, mode);
4101 op = SUBREG_REG (op);
4104 if (GET_CODE (op) != REG)
4105 return FALSE;
4107 regno = REGNO (op);
4108 if (regno >= FIRST_PSEUDO_REGISTER)
4109 return TRUE;
4111 if (GPR_P (regno))
4112 return (((regno - GPR_FIRST) & 1) == 0);
4114 if (FPR_P (regno))
4115 return (((regno - FPR_FIRST) & 1) == 0);
4117 return FALSE;
4120 /* Return true if operand is an odd GPR register. */
4123 odd_reg_operand (op, mode)
4124 rtx op;
4125 enum machine_mode mode;
4127 int regno;
4129 if (GET_MODE (op) != mode && mode != VOIDmode)
4130 return FALSE;
4132 if (GET_CODE (op) == SUBREG)
4134 if (GET_CODE (SUBREG_REG (op)) != REG)
4135 return register_operand (op, mode);
4137 op = SUBREG_REG (op);
4140 if (GET_CODE (op) != REG)
4141 return FALSE;
4143 regno = REGNO (op);
4144 /* assume that reload will give us an even register */
4145 if (regno >= FIRST_PSEUDO_REGISTER)
4146 return FALSE;
4148 if (GPR_P (regno))
4149 return (((regno - GPR_FIRST) & 1) != 0);
4151 if (FPR_P (regno))
4152 return (((regno - FPR_FIRST) & 1) != 0);
4154 return FALSE;
4157 /* Return true if operand is an even GPR register. */
4160 even_gpr_operand (op, mode)
4161 rtx op;
4162 enum machine_mode mode;
4164 int regno;
4166 if (GET_MODE (op) != mode && mode != VOIDmode)
4167 return FALSE;
4169 if (GET_CODE (op) == SUBREG)
4171 if (GET_CODE (SUBREG_REG (op)) != REG)
4172 return register_operand (op, mode);
4174 op = SUBREG_REG (op);
4177 if (GET_CODE (op) != REG)
4178 return FALSE;
4180 regno = REGNO (op);
4181 if (regno >= FIRST_PSEUDO_REGISTER)
4182 return TRUE;
4184 if (! GPR_P (regno))
4185 return FALSE;
4187 return (((regno - GPR_FIRST) & 1) == 0);
4190 /* Return true if operand is an odd GPR register. */
4193 odd_gpr_operand (op, mode)
4194 rtx op;
4195 enum machine_mode mode;
4197 int regno;
4199 if (GET_MODE (op) != mode && mode != VOIDmode)
4200 return FALSE;
4202 if (GET_CODE (op) == SUBREG)
4204 if (GET_CODE (SUBREG_REG (op)) != REG)
4205 return register_operand (op, mode);
4207 op = SUBREG_REG (op);
4210 if (GET_CODE (op) != REG)
4211 return FALSE;
4213 regno = REGNO (op);
4214 /* assume that reload will give us an even register */
4215 if (regno >= FIRST_PSEUDO_REGISTER)
4216 return FALSE;
4218 if (! GPR_P (regno))
4219 return FALSE;
4221 return (((regno - GPR_FIRST) & 1) != 0);
4224 /* Return true if operand is a quad aligned FPR register. */
4227 quad_fpr_operand (op, mode)
4228 rtx op;
4229 enum machine_mode mode;
4231 int regno;
4233 if (GET_MODE (op) != mode && mode != VOIDmode)
4234 return FALSE;
4236 if (GET_CODE (op) == SUBREG)
4238 if (GET_CODE (SUBREG_REG (op)) != REG)
4239 return register_operand (op, mode);
4241 op = SUBREG_REG (op);
4244 if (GET_CODE (op) != REG)
4245 return FALSE;
4247 regno = REGNO (op);
4248 if (regno >= FIRST_PSEUDO_REGISTER)
4249 return TRUE;
4251 if (! FPR_P (regno))
4252 return FALSE;
4254 return (((regno - FPR_FIRST) & 3) == 0);
4257 /* Return true if operand is an even FPR register. */
4260 even_fpr_operand (op, mode)
4261 rtx op;
4262 enum machine_mode mode;
4264 int regno;
4266 if (GET_MODE (op) != mode && mode != VOIDmode)
4267 return FALSE;
4269 if (GET_CODE (op) == SUBREG)
4271 if (GET_CODE (SUBREG_REG (op)) != REG)
4272 return register_operand (op, mode);
4274 op = SUBREG_REG (op);
4277 if (GET_CODE (op) != REG)
4278 return FALSE;
4280 regno = REGNO (op);
4281 if (regno >= FIRST_PSEUDO_REGISTER)
4282 return TRUE;
4284 if (! FPR_P (regno))
4285 return FALSE;
4287 return (((regno - FPR_FIRST) & 1) == 0);
4290 /* Return true if operand is an odd FPR register. */
4293 odd_fpr_operand (op, mode)
4294 rtx op;
4295 enum machine_mode mode;
4297 int regno;
4299 if (GET_MODE (op) != mode && mode != VOIDmode)
4300 return FALSE;
4302 if (GET_CODE (op) == SUBREG)
4304 if (GET_CODE (SUBREG_REG (op)) != REG)
4305 return register_operand (op, mode);
4307 op = SUBREG_REG (op);
4310 if (GET_CODE (op) != REG)
4311 return FALSE;
4313 regno = REGNO (op);
4314 /* assume that reload will give us an even register */
4315 if (regno >= FIRST_PSEUDO_REGISTER)
4316 return FALSE;
4318 if (! FPR_P (regno))
4319 return FALSE;
4321 return (((regno - FPR_FIRST) & 1) != 0);
4324 /* Return true if operand is a 2 word memory address that can be loaded in one
4325 instruction to load or store. We assume the stack and frame pointers are
4326 suitably aligned, and variables in the small data area. FIXME -- at some we
4327 should recognize other globals and statics. We can't assume that any old
4328 pointer is aligned, given that arguments could be passed on an odd word on
4329 the stack and the address taken and passed through to another function. */
4332 dbl_memory_one_insn_operand (op, mode)
4333 rtx op;
4334 enum machine_mode mode;
4336 rtx addr;
4337 rtx addr_reg;
4339 if (! TARGET_DWORD)
4340 return FALSE;
4342 if (GET_CODE (op) != MEM)
4343 return FALSE;
4345 if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD)
4346 return FALSE;
4348 addr = XEXP (op, 0);
4349 if (GET_CODE (addr) == REG)
4350 addr_reg = addr;
4352 else if (GET_CODE (addr) == PLUS)
4354 rtx addr0 = XEXP (addr, 0);
4355 rtx addr1 = XEXP (addr, 1);
4357 if (GET_CODE (addr0) != REG)
4358 return FALSE;
4360 if (plus_small_data_p (addr0, addr1))
4361 return TRUE;
4363 if (GET_CODE (addr1) != CONST_INT)
4364 return FALSE;
4366 if ((INTVAL (addr1) & 7) != 0)
4367 return FALSE;
4369 addr_reg = addr0;
4372 else
4373 return FALSE;
4375 if (addr_reg == frame_pointer_rtx || addr_reg == stack_pointer_rtx)
4376 return TRUE;
4378 return FALSE;
4381 /* Return true if operand is a 2 word memory address that needs to
4382 use two instructions to load or store. */
4385 dbl_memory_two_insn_operand (op, mode)
4386 rtx op;
4387 enum machine_mode mode;
4389 if (GET_CODE (op) != MEM)
4390 return FALSE;
4392 if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD)
4393 return FALSE;
4395 if (! TARGET_DWORD)
4396 return TRUE;
4398 return ! dbl_memory_one_insn_operand (op, mode);
4401 /* Return true if operand is something that can be an output for a move
4402 operation. */
4405 move_destination_operand (op, mode)
4406 rtx op;
4407 enum machine_mode mode;
4409 rtx subreg;
4410 enum rtx_code code;
4412 switch (GET_CODE (op))
4414 default:
4415 break;
4417 case SUBREG:
4418 if (GET_MODE (op) != mode && mode != VOIDmode)
4419 return FALSE;
4421 subreg = SUBREG_REG (op);
4422 code = GET_CODE (subreg);
4423 if (code == MEM)
4424 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4425 reload_completed, FALSE);
4427 return (code == REG);
4429 case REG:
4430 if (GET_MODE (op) != mode && mode != VOIDmode)
4431 return FALSE;
4433 return TRUE;
4435 case MEM:
4436 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4437 return TRUE;
4439 return frv_legitimate_memory_operand (op, mode, FALSE);
4442 return FALSE;
4445 /* Return true if operand is something that can be an input for a move
4446 operation. */
4449 move_source_operand (op, mode)
4450 rtx op;
4451 enum machine_mode mode;
4453 rtx subreg;
4454 enum rtx_code code;
4456 switch (GET_CODE (op))
4458 default:
4459 break;
4461 case CONST_INT:
4462 case CONST_DOUBLE:
4463 case SYMBOL_REF:
4464 case LABEL_REF:
4465 case CONST:
4466 return immediate_operand (op, mode);
4468 case SUBREG:
4469 if (GET_MODE (op) != mode && mode != VOIDmode)
4470 return FALSE;
4472 subreg = SUBREG_REG (op);
4473 code = GET_CODE (subreg);
4474 if (code == MEM)
4475 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4476 reload_completed, FALSE);
4478 return (code == REG);
4480 case REG:
4481 if (GET_MODE (op) != mode && mode != VOIDmode)
4482 return FALSE;
4484 return TRUE;
4486 case MEM:
4487 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4488 return TRUE;
4490 return frv_legitimate_memory_operand (op, mode, FALSE);
4493 return FALSE;
4496 /* Return true if operand is something that can be an output for a conditional
4497 move operation. */
4500 condexec_dest_operand (op, mode)
4501 rtx op;
4502 enum machine_mode mode;
4504 rtx subreg;
4505 enum rtx_code code;
4507 switch (GET_CODE (op))
4509 default:
4510 break;
4512 case SUBREG:
4513 if (GET_MODE (op) != mode && mode != VOIDmode)
4514 return FALSE;
4516 subreg = SUBREG_REG (op);
4517 code = GET_CODE (subreg);
4518 if (code == MEM)
4519 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4520 reload_completed, TRUE);
4522 return (code == REG);
4524 case REG:
4525 if (GET_MODE (op) != mode && mode != VOIDmode)
4526 return FALSE;
4528 return TRUE;
4530 case MEM:
4531 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4532 return TRUE;
4534 return frv_legitimate_memory_operand (op, mode, TRUE);
4537 return FALSE;
4540 /* Return true if operand is something that can be an input for a conditional
4541 move operation. */
4544 condexec_source_operand (op, mode)
4545 rtx op;
4546 enum machine_mode mode;
4548 rtx subreg;
4549 enum rtx_code code;
4551 switch (GET_CODE (op))
4553 default:
4554 break;
4556 case CONST_INT:
4557 case CONST_DOUBLE:
4558 return ZERO_P (op);
4560 case SUBREG:
4561 if (GET_MODE (op) != mode && mode != VOIDmode)
4562 return FALSE;
4564 subreg = SUBREG_REG (op);
4565 code = GET_CODE (subreg);
4566 if (code == MEM)
4567 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4568 reload_completed, TRUE);
4570 return (code == REG);
4572 case REG:
4573 if (GET_MODE (op) != mode && mode != VOIDmode)
4574 return FALSE;
4576 return TRUE;
4578 case MEM:
4579 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4580 return TRUE;
4582 return frv_legitimate_memory_operand (op, mode, TRUE);
4585 return FALSE;
4588 /* Return true if operand is a register of any flavor or a 0 of the
4589 appropriate type. */
4592 reg_or_0_operand (op, mode)
4593 rtx op;
4594 enum machine_mode mode;
4596 switch (GET_CODE (op))
4598 default:
4599 break;
4601 case REG:
4602 case SUBREG:
4603 if (GET_MODE (op) != mode && mode != VOIDmode)
4604 return FALSE;
4606 return register_operand (op, mode);
4608 case CONST_INT:
4609 case CONST_DOUBLE:
4610 return ZERO_P (op);
4613 return FALSE;
4616 /* Return true if operand is the link register */
4619 lr_operand (op, mode)
4620 rtx op;
4621 enum machine_mode mode;
4623 if (GET_CODE (op) != REG)
4624 return FALSE;
4626 if (GET_MODE (op) != mode && mode != VOIDmode)
4627 return FALSE;
4629 if (REGNO (op) != LR_REGNO && REGNO (op) < FIRST_PSEUDO_REGISTER)
4630 return FALSE;
4632 return TRUE;
4635 /* Return true if operand is a gpr register or a valid memory operation. */
4638 gpr_or_memory_operand (op, mode)
4639 rtx op;
4640 enum machine_mode mode;
4642 return (integer_register_operand (op, mode)
4643 || frv_legitimate_memory_operand (op, mode, FALSE));
4646 /* Return true if operand is a fpr register or a valid memory operation. */
4649 fpr_or_memory_operand (op, mode)
4650 rtx op;
4651 enum machine_mode mode;
4653 return (fpr_operand (op, mode)
4654 || frv_legitimate_memory_operand (op, mode, FALSE));
4657 /* Return true if operand is an icc register */
4660 icc_operand (op, mode)
4661 rtx op;
4662 enum machine_mode mode;
4664 int regno;
4666 if (GET_MODE (op) != mode && mode != VOIDmode)
4667 return FALSE;
4669 if (GET_CODE (op) != REG)
4670 return FALSE;
4672 regno = REGNO (op);
4673 return ICC_OR_PSEUDO_P (regno);
4676 /* Return true if operand is an fcc register */
4679 fcc_operand (op, mode)
4680 rtx op;
4681 enum machine_mode mode;
4683 int regno;
4685 if (GET_MODE (op) != mode && mode != VOIDmode)
4686 return FALSE;
4688 if (GET_CODE (op) != REG)
4689 return FALSE;
4691 regno = REGNO (op);
4692 return FCC_OR_PSEUDO_P (regno);
4695 /* Return true if operand is either an fcc or icc register */
4698 cc_operand (op, mode)
4699 rtx op;
4700 enum machine_mode mode;
4702 int regno;
4704 if (GET_MODE (op) != mode && mode != VOIDmode)
4705 return FALSE;
4707 if (GET_CODE (op) != REG)
4708 return FALSE;
4710 regno = REGNO (op);
4711 if (CC_OR_PSEUDO_P (regno))
4712 return TRUE;
4714 return FALSE;
4717 /* Return true if operand is an integer CCR register */
4720 icr_operand (op, mode)
4721 rtx op;
4722 enum machine_mode mode;
4724 int regno;
4726 if (GET_MODE (op) != mode && mode != VOIDmode)
4727 return FALSE;
4729 if (GET_CODE (op) != REG)
4730 return FALSE;
4732 regno = REGNO (op);
4733 return ICR_OR_PSEUDO_P (regno);
4736 /* Return true if operand is an fcc register */
4739 fcr_operand (op, mode)
4740 rtx op;
4741 enum machine_mode mode;
4743 int regno;
4745 if (GET_MODE (op) != mode && mode != VOIDmode)
4746 return FALSE;
4748 if (GET_CODE (op) != REG)
4749 return FALSE;
4751 regno = REGNO (op);
4752 return FCR_OR_PSEUDO_P (regno);
4755 /* Return true if operand is either an fcc or icc register */
4758 cr_operand (op, mode)
4759 rtx op;
4760 enum machine_mode mode;
4762 int regno;
4764 if (GET_MODE (op) != mode && mode != VOIDmode)
4765 return FALSE;
4767 if (GET_CODE (op) != REG)
4768 return FALSE;
4770 regno = REGNO (op);
4771 if (CR_OR_PSEUDO_P (regno))
4772 return TRUE;
4774 return FALSE;
4777 /* Return true if operand is a memory reference suitable for a call. */
4780 call_operand (op, mode)
4781 rtx op;
4782 enum machine_mode mode;
4784 if (GET_MODE (op) != mode && mode != VOIDmode && GET_CODE (op) != CONST_INT)
4785 return FALSE;
4787 if (GET_CODE (op) == SYMBOL_REF)
4788 return TRUE;
4790 /* Note this doesn't allow reg+reg or reg+imm12 addressing (which should
4791 never occur anyway), but prevents reload from not handling the case
4792 properly of a call through a pointer on a function that calls
4793 vfork/setjmp, etc. due to the need to flush all of the registers to stack. */
4794 return gpr_or_int12_operand (op, mode);
4797 /* Return true if operator is a kind of relational operator. */
4800 relational_operator (op, mode)
4801 rtx op;
4802 enum machine_mode mode;
4804 rtx op0;
4805 rtx op1;
4806 int regno;
4808 if (mode != VOIDmode && mode != GET_MODE (op))
4809 return FALSE;
4811 switch (GET_CODE (op))
4813 default:
4814 return FALSE;
4816 case EQ:
4817 case NE:
4818 case LE:
4819 case LT:
4820 case GE:
4821 case GT:
4822 case LEU:
4823 case LTU:
4824 case GEU:
4825 case GTU:
4826 break;
4829 op1 = XEXP (op, 1);
4830 if (op1 != const0_rtx)
4831 return FALSE;
4833 op0 = XEXP (op, 0);
4834 if (GET_CODE (op0) != REG)
4835 return FALSE;
4837 regno = REGNO (op0);
4838 switch (GET_MODE (op0))
4840 default:
4841 break;
4843 case CCmode:
4844 case CC_UNSmode:
4845 return ICC_OR_PSEUDO_P (regno);
4847 case CC_FPmode:
4848 return FCC_OR_PSEUDO_P (regno);
4850 case CC_CCRmode:
4851 return CR_OR_PSEUDO_P (regno);
4854 return FALSE;
4857 /* Return true if operator is a signed integer relational operator */
4860 signed_relational_operator (op, mode)
4861 rtx op;
4862 enum machine_mode mode;
4864 rtx op0;
4865 rtx op1;
4866 int regno;
4868 if (mode != VOIDmode && mode != GET_MODE (op))
4869 return FALSE;
4871 switch (GET_CODE (op))
4873 default:
4874 return FALSE;
4876 case EQ:
4877 case NE:
4878 case LE:
4879 case LT:
4880 case GE:
4881 case GT:
4882 break;
4885 op1 = XEXP (op, 1);
4886 if (op1 != const0_rtx)
4887 return FALSE;
4889 op0 = XEXP (op, 0);
4890 if (GET_CODE (op0) != REG)
4891 return FALSE;
4893 regno = REGNO (op0);
4894 if (GET_MODE (op0) == CCmode && ICC_OR_PSEUDO_P (regno))
4895 return TRUE;
4897 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4898 return TRUE;
4900 return FALSE;
4903 /* Return true if operator is a signed integer relational operator */
4906 unsigned_relational_operator (op, mode)
4907 rtx op;
4908 enum machine_mode mode;
4910 rtx op0;
4911 rtx op1;
4912 int regno;
4914 if (mode != VOIDmode && mode != GET_MODE (op))
4915 return FALSE;
4917 switch (GET_CODE (op))
4919 default:
4920 return FALSE;
4922 case LEU:
4923 case LTU:
4924 case GEU:
4925 case GTU:
4926 break;
4929 op1 = XEXP (op, 1);
4930 if (op1 != const0_rtx)
4931 return FALSE;
4933 op0 = XEXP (op, 0);
4934 if (GET_CODE (op0) != REG)
4935 return FALSE;
4937 regno = REGNO (op0);
4938 if (GET_MODE (op0) == CC_UNSmode && ICC_OR_PSEUDO_P (regno))
4939 return TRUE;
4941 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4942 return TRUE;
4944 return FALSE;
4947 /* Return true if operator is a floating point relational operator */
4950 float_relational_operator (op, mode)
4951 rtx op;
4952 enum machine_mode mode;
4954 rtx op0;
4955 rtx op1;
4956 int regno;
4958 if (mode != VOIDmode && mode != GET_MODE (op))
4959 return FALSE;
4961 switch (GET_CODE (op))
4963 default:
4964 return FALSE;
4966 case EQ: case NE:
4967 case LE: case LT:
4968 case GE: case GT:
4969 #if 0
4970 case UEQ: case UNE:
4971 case ULE: case ULT:
4972 case UGE: case UGT:
4973 case ORDERED:
4974 case UNORDERED:
4975 #endif
4976 break;
4979 op1 = XEXP (op, 1);
4980 if (op1 != const0_rtx)
4981 return FALSE;
4983 op0 = XEXP (op, 0);
4984 if (GET_CODE (op0) != REG)
4985 return FALSE;
4987 regno = REGNO (op0);
4988 if (GET_MODE (op0) == CC_FPmode && FCC_OR_PSEUDO_P (regno))
4989 return TRUE;
4991 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4992 return TRUE;
4994 return FALSE;
4997 /* Return true if operator is EQ/NE of a conditional execution register. */
5000 ccr_eqne_operator (op, mode)
5001 rtx op;
5002 enum machine_mode mode;
5004 enum machine_mode op_mode = GET_MODE (op);
5005 rtx op0;
5006 rtx op1;
5007 int regno;
5009 if (mode != VOIDmode && op_mode != mode)
5010 return FALSE;
5012 switch (GET_CODE (op))
5014 default:
5015 return FALSE;
5017 case EQ:
5018 case NE:
5019 break;
5022 op1 = XEXP (op, 1);
5023 if (op1 != const0_rtx)
5024 return FALSE;
5026 op0 = XEXP (op, 0);
5027 if (GET_CODE (op0) != REG)
5028 return FALSE;
5030 regno = REGNO (op0);
5031 if (op_mode == CC_CCRmode && CR_OR_PSEUDO_P (regno))
5032 return TRUE;
5034 return FALSE;
5037 /* Return true if operator is a minimum or maximum operator (both signed and
5038 unsigned). */
5041 minmax_operator (op, mode)
5042 rtx op;
5043 enum machine_mode mode;
5045 if (mode != VOIDmode && mode != GET_MODE (op))
5046 return FALSE;
5048 switch (GET_CODE (op))
5050 default:
5051 return FALSE;
5053 case SMIN:
5054 case SMAX:
5055 case UMIN:
5056 case UMAX:
5057 break;
5060 if (! integer_register_operand (XEXP (op, 0), mode))
5061 return FALSE;
5063 if (! gpr_or_int10_operand (XEXP (op, 1), mode))
5064 return FALSE;
5066 return TRUE;
5069 /* Return true if operator is an integer binary operator that can executed
5070 conditionally and takes 1 cycle. */
5073 condexec_si_binary_operator (op, mode)
5074 rtx op;
5075 enum machine_mode mode;
5077 enum machine_mode op_mode = GET_MODE (op);
5079 if (mode != VOIDmode && op_mode != mode)
5080 return FALSE;
5082 switch (GET_CODE (op))
5084 default:
5085 return FALSE;
5087 case PLUS:
5088 case MINUS:
5089 case AND:
5090 case IOR:
5091 case XOR:
5092 case ASHIFT:
5093 case ASHIFTRT:
5094 case LSHIFTRT:
5095 return TRUE;
5099 /* Return true if operator is an integer binary operator that can be
5100 executed conditionally by a media instruction. */
5103 condexec_si_media_operator (op, mode)
5104 rtx op;
5105 enum machine_mode mode;
5107 enum machine_mode op_mode = GET_MODE (op);
5109 if (mode != VOIDmode && op_mode != mode)
5110 return FALSE;
5112 switch (GET_CODE (op))
5114 default:
5115 return FALSE;
5117 case AND:
5118 case IOR:
5119 case XOR:
5120 return TRUE;
5124 /* Return true if operator is an integer division operator that can executed
5125 conditionally. */
5128 condexec_si_divide_operator (op, mode)
5129 rtx op;
5130 enum machine_mode mode;
5132 enum machine_mode op_mode = GET_MODE (op);
5134 if (mode != VOIDmode && op_mode != mode)
5135 return FALSE;
5137 switch (GET_CODE (op))
5139 default:
5140 return FALSE;
5142 case DIV:
5143 case UDIV:
5144 return TRUE;
5148 /* Return true if operator is an integer unary operator that can executed
5149 conditionally. */
5152 condexec_si_unary_operator (op, mode)
5153 rtx op;
5154 enum machine_mode mode;
5156 enum machine_mode op_mode = GET_MODE (op);
5158 if (mode != VOIDmode && op_mode != mode)
5159 return FALSE;
5161 switch (GET_CODE (op))
5163 default:
5164 return FALSE;
5166 case NEG:
5167 case NOT:
5168 return TRUE;
5172 /* Return true if operator is a conversion-type expression that can be
5173 evaluated conditionally by floating-point instructions. */
5176 condexec_sf_conv_operator (op, mode)
5177 rtx op;
5178 enum machine_mode mode;
5180 enum machine_mode op_mode = GET_MODE (op);
5182 if (mode != VOIDmode && op_mode != mode)
5183 return FALSE;
5185 switch (GET_CODE (op))
5187 default:
5188 return FALSE;
5190 case NEG:
5191 case ABS:
5192 return TRUE;
5196 /* Return true if operator is an addition or subtraction expression.
5197 Such expressions can be evaluated conditionally by floating-point
5198 instructions. */
5201 condexec_sf_add_operator (op, mode)
5202 rtx op;
5203 enum machine_mode mode;
5205 enum machine_mode op_mode = GET_MODE (op);
5207 if (mode != VOIDmode && op_mode != mode)
5208 return FALSE;
5210 switch (GET_CODE (op))
5212 default:
5213 return FALSE;
5215 case PLUS:
5216 case MINUS:
5217 return TRUE;
5221 /* Return true if the memory operand is one that can be conditionally
5222 executed. */
5225 condexec_memory_operand (op, mode)
5226 rtx op;
5227 enum machine_mode mode;
5229 enum machine_mode op_mode = GET_MODE (op);
5230 rtx addr;
5232 if (mode != VOIDmode && op_mode != mode)
5233 return FALSE;
5235 switch (op_mode)
5237 default:
5238 return FALSE;
5240 case QImode:
5241 case HImode:
5242 case SImode:
5243 case SFmode:
5244 break;
5247 if (GET_CODE (op) != MEM)
5248 return FALSE;
5250 addr = XEXP (op, 0);
5251 if (GET_CODE (addr) == ADDRESSOF)
5252 return TRUE;
5254 return frv_legitimate_address_p (mode, addr, reload_completed, TRUE);
5257 /* Return true if operator is an integer binary operator that can be combined
5258 with a setcc operation. Do not allow the arithmetic operations that could
5259 potentially overflow since the FR-V sets the condition code based on the
5260 "true" value of the result, not the result after truncating to a 32-bit
5261 register. */
5264 intop_compare_operator (op, mode)
5265 rtx op;
5266 enum machine_mode mode;
5268 enum machine_mode op_mode = GET_MODE (op);
5270 if (mode != VOIDmode && op_mode != mode)
5271 return FALSE;
5273 switch (GET_CODE (op))
5275 default:
5276 return FALSE;
5278 case AND:
5279 case IOR:
5280 case XOR:
5281 case ASHIFTRT:
5282 case LSHIFTRT:
5283 break;
5286 if (! integer_register_operand (XEXP (op, 0), SImode))
5287 return FALSE;
5289 if (! gpr_or_int10_operand (XEXP (op, 1), SImode))
5290 return FALSE;
5292 return TRUE;
5295 /* Return true if operator is an integer binary operator that can be combined
5296 with a setcc operation inside of a conditional execution. */
5299 condexec_intop_cmp_operator (op, mode)
5300 rtx op;
5301 enum machine_mode mode;
5303 enum machine_mode op_mode = GET_MODE (op);
5305 if (mode != VOIDmode && op_mode != mode)
5306 return FALSE;
5308 switch (GET_CODE (op))
5310 default:
5311 return FALSE;
5313 case AND:
5314 case IOR:
5315 case XOR:
5316 case ASHIFTRT:
5317 case LSHIFTRT:
5318 break;
5321 if (! integer_register_operand (XEXP (op, 0), SImode))
5322 return FALSE;
5324 if (! integer_register_operand (XEXP (op, 1), SImode))
5325 return FALSE;
5327 return TRUE;
5330 /* Return 1 if operand is a valid ACC register number */
5333 acc_operand (op, mode)
5334 rtx op;
5335 enum machine_mode mode;
5337 int regno;
5339 if (GET_MODE (op) != mode && mode != VOIDmode)
5340 return FALSE;
5342 if (GET_CODE (op) == SUBREG)
5344 if (GET_CODE (SUBREG_REG (op)) != REG)
5345 return register_operand (op, mode);
5347 op = SUBREG_REG (op);
5350 if (GET_CODE (op) != REG)
5351 return FALSE;
5353 regno = REGNO (op);
5354 return ACC_OR_PSEUDO_P (regno);
5357 /* Return 1 if operand is a valid even ACC register number */
5360 even_acc_operand (op, mode)
5361 rtx op;
5362 enum machine_mode mode;
5364 int regno;
5366 if (GET_MODE (op) != mode && mode != VOIDmode)
5367 return FALSE;
5369 if (GET_CODE (op) == SUBREG)
5371 if (GET_CODE (SUBREG_REG (op)) != REG)
5372 return register_operand (op, mode);
5374 op = SUBREG_REG (op);
5377 if (GET_CODE (op) != REG)
5378 return FALSE;
5380 regno = REGNO (op);
5381 return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 1) == 0);
5384 /* Return 1 if operand is zero or four */
5387 quad_acc_operand (op, mode)
5388 rtx op;
5389 enum machine_mode mode;
5391 int regno;
5393 if (GET_MODE (op) != mode && mode != VOIDmode)
5394 return FALSE;
5396 if (GET_CODE (op) == SUBREG)
5398 if (GET_CODE (SUBREG_REG (op)) != REG)
5399 return register_operand (op, mode);
5401 op = SUBREG_REG (op);
5404 if (GET_CODE (op) != REG)
5405 return FALSE;
5407 regno = REGNO (op);
5408 return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 3) == 0);
5411 /* Return 1 if operand is a valid ACCG register number */
5414 accg_operand (op, mode)
5415 rtx op;
5416 enum machine_mode mode;
5418 if (GET_MODE (op) != mode && mode != VOIDmode)
5419 return FALSE;
5421 if (GET_CODE (op) == SUBREG)
5423 if (GET_CODE (SUBREG_REG (op)) != REG)
5424 return register_operand (op, mode);
5426 op = SUBREG_REG (op);
5429 if (GET_CODE (op) != REG)
5430 return FALSE;
5432 return ACCG_OR_PSEUDO_P (REGNO (op));
5436 /* Return true if the bare return instruction can be used outside of the
5437 epilog code. For frv, we only do it if there was no stack allocation. */
5440 direct_return_p ()
5442 frv_stack_t *info;
5444 if (!reload_completed)
5445 return FALSE;
5447 info = frv_stack_info ();
5448 return (info->total_size == 0);
5452 /* Emit code to handle a MOVSI, adding in the small data register or pic
5453 register if needed to load up addresses. Return TRUE if the appropriate
5454 instructions are emitted. */
5457 frv_emit_movsi (dest, src)
5458 rtx dest;
5459 rtx src;
5461 int base_regno = -1;
5463 if (!reload_in_progress
5464 && !reload_completed
5465 && !register_operand (dest, SImode)
5466 && (!reg_or_0_operand (src, SImode)
5467 /* Virtual registers will almost always be replaced by an
5468 add instruction, so expose this to CSE by copying to
5469 an intermediate register */
5470 || (GET_CODE (src) == REG
5471 && IN_RANGE_P (REGNO (src),
5472 FIRST_VIRTUAL_REGISTER,
5473 LAST_VIRTUAL_REGISTER))))
5475 emit_insn (gen_rtx_SET (VOIDmode, dest, copy_to_mode_reg (SImode, src)));
5476 return TRUE;
5479 /* Explicitly add in the PIC or small data register if needed. */
5480 switch (GET_CODE (src))
5482 default:
5483 break;
5485 case LABEL_REF:
5486 if (flag_pic)
5487 base_regno = PIC_REGNO;
5489 break;
5491 case CONST:
5492 if (const_small_data_p (src))
5493 base_regno = SDA_BASE_REG;
5495 else if (flag_pic)
5496 base_regno = PIC_REGNO;
5498 break;
5500 case SYMBOL_REF:
5501 if (symbol_ref_small_data_p (src))
5502 base_regno = SDA_BASE_REG;
5504 else if (flag_pic)
5505 base_regno = PIC_REGNO;
5507 break;
5510 if (base_regno >= 0)
5512 emit_insn (gen_rtx_SET (VOIDmode, dest,
5513 gen_rtx_PLUS (Pmode,
5514 gen_rtx_REG (Pmode, base_regno),
5515 src)));
5517 if (base_regno == PIC_REGNO)
5518 cfun->uses_pic_offset_table = TRUE;
5520 return TRUE;
5523 return FALSE;
5527 /* Return a string to output a single word move. */
5529 const char *
5530 output_move_single (operands, insn)
5531 rtx operands[];
5532 rtx insn;
5534 rtx dest = operands[0];
5535 rtx src = operands[1];
5537 if (GET_CODE (dest) == REG)
5539 int dest_regno = REGNO (dest);
5540 enum machine_mode mode = GET_MODE (dest);
5542 if (GPR_P (dest_regno))
5544 if (GET_CODE (src) == REG)
5546 /* gpr <- some sort of register */
5547 int src_regno = REGNO (src);
5549 if (GPR_P (src_regno))
5550 return "mov %1, %0";
5552 else if (FPR_P (src_regno))
5553 return "movfg %1, %0";
5555 else if (SPR_P (src_regno))
5556 return "movsg %1, %0";
5559 else if (GET_CODE (src) == MEM)
5561 /* gpr <- memory */
5562 switch (mode)
5564 default:
5565 break;
5567 case QImode:
5568 return "ldsb%I1%U1 %M1,%0";
5570 case HImode:
5571 return "ldsh%I1%U1 %M1,%0";
5573 case SImode:
5574 case SFmode:
5575 return "ld%I1%U1 %M1, %0";
5579 else if (GET_CODE (src) == CONST_INT
5580 || GET_CODE (src) == CONST_DOUBLE)
5582 /* gpr <- integer/floating constant */
5583 HOST_WIDE_INT value;
5585 if (GET_CODE (src) == CONST_INT)
5586 value = INTVAL (src);
5588 else if (mode == SFmode)
5590 REAL_VALUE_TYPE rv;
5591 long l;
5593 REAL_VALUE_FROM_CONST_DOUBLE (rv, src);
5594 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5595 value = l;
5598 else
5599 value = CONST_DOUBLE_LOW (src);
5601 if (IN_RANGE_P (value, -32768, 32767))
5602 return "setlos %1, %0";
5604 return "#";
5607 else if (GET_CODE (src) == SYMBOL_REF
5608 || GET_CODE (src) == LABEL_REF
5609 || GET_CODE (src) == CONST)
5611 /* Silently fix up instances where the small data pointer is not
5612 used in the address. */
5613 if (small_data_symbolic_operand (src, GET_MODE (src)))
5614 return "addi %@, #gprel12(%1), %0";
5616 return "#";
5620 else if (FPR_P (dest_regno))
5622 if (GET_CODE (src) == REG)
5624 /* fpr <- some sort of register */
5625 int src_regno = REGNO (src);
5627 if (GPR_P (src_regno))
5628 return "movgf %1, %0";
5630 else if (FPR_P (src_regno))
5632 if (TARGET_HARD_FLOAT)
5633 return "fmovs %1, %0";
5634 else
5635 return "mor %1, %1, %0";
5639 else if (GET_CODE (src) == MEM)
5641 /* fpr <- memory */
5642 switch (mode)
5644 default:
5645 break;
5647 case QImode:
5648 return "ldbf%I1%U1 %M1,%0";
5650 case HImode:
5651 return "ldhf%I1%U1 %M1,%0";
5653 case SImode:
5654 case SFmode:
5655 return "ldf%I1%U1 %M1, %0";
5659 else if (ZERO_P (src))
5660 return "movgf %., %0";
5663 else if (SPR_P (dest_regno))
5665 if (GET_CODE (src) == REG)
5667 /* spr <- some sort of register */
5668 int src_regno = REGNO (src);
5670 if (GPR_P (src_regno))
5671 return "movgs %1, %0";
5676 else if (GET_CODE (dest) == MEM)
5678 if (GET_CODE (src) == REG)
5680 int src_regno = REGNO (src);
5681 enum machine_mode mode = GET_MODE (dest);
5683 if (GPR_P (src_regno))
5685 switch (mode)
5687 default:
5688 break;
5690 case QImode:
5691 return "stb%I0%U0 %1, %M0";
5693 case HImode:
5694 return "sth%I0%U0 %1, %M0";
5696 case SImode:
5697 case SFmode:
5698 return "st%I0%U0 %1, %M0";
5702 else if (FPR_P (src_regno))
5704 switch (mode)
5706 default:
5707 break;
5709 case QImode:
5710 return "stbf%I0%U0 %1, %M0";
5712 case HImode:
5713 return "sthf%I0%U0 %1, %M0";
5715 case SImode:
5716 case SFmode:
5717 return "stf%I0%U0 %1, %M0";
5722 else if (ZERO_P (src))
5724 switch (GET_MODE (dest))
5726 default:
5727 break;
5729 case QImode:
5730 return "stb%I0%U0 %., %M0";
5732 case HImode:
5733 return "sth%I0%U0 %., %M0";
5735 case SImode:
5736 case SFmode:
5737 return "st%I0%U0 %., %M0";
5742 fatal_insn ("Bad output_move_single operand", insn);
5743 return "";
5747 /* Return a string to output a double word move. */
5749 const char *
5750 output_move_double (operands, insn)
5751 rtx operands[];
5752 rtx insn;
5754 rtx dest = operands[0];
5755 rtx src = operands[1];
5756 enum machine_mode mode = GET_MODE (dest);
5758 if (GET_CODE (dest) == REG)
5760 int dest_regno = REGNO (dest);
5762 if (GPR_P (dest_regno))
5764 if (GET_CODE (src) == REG)
5766 /* gpr <- some sort of register */
5767 int src_regno = REGNO (src);
5769 if (GPR_P (src_regno))
5770 return "#";
5772 else if (FPR_P (src_regno))
5774 if (((dest_regno - GPR_FIRST) & 1) == 0
5775 && ((src_regno - FPR_FIRST) & 1) == 0)
5776 return "movfgd %1, %0";
5778 return "#";
5782 else if (GET_CODE (src) == MEM)
5784 /* gpr <- memory */
5785 if (dbl_memory_one_insn_operand (src, mode))
5786 return "ldd%I1%U1 %M1, %0";
5788 return "#";
5791 else if (GET_CODE (src) == CONST_INT
5792 || GET_CODE (src) == CONST_DOUBLE)
5793 return "#";
5796 else if (FPR_P (dest_regno))
5798 if (GET_CODE (src) == REG)
5800 /* fpr <- some sort of register */
5801 int src_regno = REGNO (src);
5803 if (GPR_P (src_regno))
5805 if (((dest_regno - FPR_FIRST) & 1) == 0
5806 && ((src_regno - GPR_FIRST) & 1) == 0)
5807 return "movgfd %1, %0";
5809 return "#";
5812 else if (FPR_P (src_regno))
5814 if (TARGET_DOUBLE
5815 && ((dest_regno - FPR_FIRST) & 1) == 0
5816 && ((src_regno - FPR_FIRST) & 1) == 0)
5817 return "fmovd %1, %0";
5819 return "#";
5823 else if (GET_CODE (src) == MEM)
5825 /* fpr <- memory */
5826 if (dbl_memory_one_insn_operand (src, mode))
5827 return "lddf%I1%U1 %M1, %0";
5829 return "#";
5832 else if (ZERO_P (src))
5833 return "#";
5837 else if (GET_CODE (dest) == MEM)
5839 if (GET_CODE (src) == REG)
5841 int src_regno = REGNO (src);
5843 if (GPR_P (src_regno))
5845 if (((src_regno - GPR_FIRST) & 1) == 0
5846 && dbl_memory_one_insn_operand (dest, mode))
5847 return "std%I0%U0 %1, %M0";
5849 return "#";
5852 if (FPR_P (src_regno))
5854 if (((src_regno - FPR_FIRST) & 1) == 0
5855 && dbl_memory_one_insn_operand (dest, mode))
5856 return "stdf%I0%U0 %1, %M0";
5858 return "#";
5862 else if (ZERO_P (src))
5864 if (dbl_memory_one_insn_operand (dest, mode))
5865 return "std%I0%U0 %., %M0";
5867 return "#";
5871 fatal_insn ("Bad output_move_double operand", insn);
5872 return "";
5876 /* Return a string to output a single word conditional move.
5877 Operand0 -- EQ/NE of ccr register and 0
5878 Operand1 -- CCR register
5879 Operand2 -- destination
5880 Operand3 -- source */
5882 const char *
5883 output_condmove_single (operands, insn)
5884 rtx operands[];
5885 rtx insn;
5887 rtx dest = operands[2];
5888 rtx src = operands[3];
5890 if (GET_CODE (dest) == REG)
5892 int dest_regno = REGNO (dest);
5893 enum machine_mode mode = GET_MODE (dest);
5895 if (GPR_P (dest_regno))
5897 if (GET_CODE (src) == REG)
5899 /* gpr <- some sort of register */
5900 int src_regno = REGNO (src);
5902 if (GPR_P (src_regno))
5903 return "cmov %z3, %2, %1, %e0";
5905 else if (FPR_P (src_regno))
5906 return "cmovfg %3, %2, %1, %e0";
5909 else if (GET_CODE (src) == MEM)
5911 /* gpr <- memory */
5912 switch (mode)
5914 default:
5915 break;
5917 case QImode:
5918 return "cldsb%I3%U3 %M3, %2, %1, %e0";
5920 case HImode:
5921 return "cldsh%I3%U3 %M3, %2, %1, %e0";
5923 case SImode:
5924 case SFmode:
5925 return "cld%I3%U3 %M3, %2, %1, %e0";
5929 else if (ZERO_P (src))
5930 return "cmov %., %2, %1, %e0";
5933 else if (FPR_P (dest_regno))
5935 if (GET_CODE (src) == REG)
5937 /* fpr <- some sort of register */
5938 int src_regno = REGNO (src);
5940 if (GPR_P (src_regno))
5941 return "cmovgf %3, %2, %1, %e0";
5943 else if (FPR_P (src_regno))
5945 if (TARGET_HARD_FLOAT)
5946 return "cfmovs %3,%2,%1,%e0";
5947 else
5948 return "cmor %3, %3, %2, %1, %e0";
5952 else if (GET_CODE (src) == MEM)
5954 /* fpr <- memory */
5955 if (mode == SImode || mode == SFmode)
5956 return "cldf%I3%U3 %M3, %2, %1, %e0";
5959 else if (ZERO_P (src))
5960 return "cmovgf %., %2, %1, %e0";
5964 else if (GET_CODE (dest) == MEM)
5966 if (GET_CODE (src) == REG)
5968 int src_regno = REGNO (src);
5969 enum machine_mode mode = GET_MODE (dest);
5971 if (GPR_P (src_regno))
5973 switch (mode)
5975 default:
5976 break;
5978 case QImode:
5979 return "cstb%I2%U2 %3, %M2, %1, %e0";
5981 case HImode:
5982 return "csth%I2%U2 %3, %M2, %1, %e0";
5984 case SImode:
5985 case SFmode:
5986 return "cst%I2%U2 %3, %M2, %1, %e0";
5990 else if (FPR_P (src_regno) && (mode == SImode || mode == SFmode))
5991 return "cstf%I2%U2 %3, %M2, %1, %e0";
5994 else if (ZERO_P (src))
5996 enum machine_mode mode = GET_MODE (dest);
5997 switch (mode)
5999 default:
6000 break;
6002 case QImode:
6003 return "cstb%I2%U2 %., %M2, %1, %e0";
6005 case HImode:
6006 return "csth%I2%U2 %., %M2, %1, %e0";
6008 case SImode:
6009 case SFmode:
6010 return "cst%I2%U2 %., %M2, %1, %e0";
6015 fatal_insn ("Bad output_condmove_single operand", insn);
6016 return "";
6020 /* Emit the appropriate code to do a comparison, returning the register the
6021 comparison was done it. */
6023 static rtx
6024 frv_emit_comparison (test, op0, op1)
6025 enum rtx_code test;
6026 rtx op0;
6027 rtx op1;
6029 enum machine_mode cc_mode;
6030 rtx cc_reg;
6032 /* Floating point doesn't have comparison against a constant */
6033 if (GET_MODE (op0) == CC_FPmode && GET_CODE (op1) != REG)
6034 op1 = force_reg (GET_MODE (op0), op1);
6036 /* Possibly disable using anything but a fixed register in order to work
6037 around cse moving comparisons past function calls. */
6038 cc_mode = SELECT_CC_MODE (test, op0, op1);
6039 cc_reg = ((TARGET_ALLOC_CC)
6040 ? gen_reg_rtx (cc_mode)
6041 : gen_rtx_REG (cc_mode,
6042 (cc_mode == CC_FPmode) ? FCC_FIRST : ICC_FIRST));
6044 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
6045 gen_rtx_COMPARE (cc_mode, op0, op1)));
6047 return cc_reg;
6051 /* Emit code for a conditional branch. The comparison operands were previously
6052 stored in frv_compare_op0 and frv_compare_op1.
6054 XXX: I originally wanted to add a clobber of a CCR register to use in
6055 conditional execution, but that confuses the rest of the compiler. */
6058 frv_emit_cond_branch (test, label)
6059 enum rtx_code test;
6060 rtx label;
6062 rtx test_rtx;
6063 rtx label_ref;
6064 rtx if_else;
6065 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
6066 enum machine_mode cc_mode = GET_MODE (cc_reg);
6068 /* Branches generate:
6069 (set (pc)
6070 (if_then_else (<test>, <cc_reg>, (const_int 0))
6071 (label_ref <branch_label>)
6072 (pc))) */
6073 label_ref = gen_rtx_LABEL_REF (VOIDmode, label);
6074 test_rtx = gen_rtx (test, cc_mode, cc_reg, const0_rtx);
6075 if_else = gen_rtx_IF_THEN_ELSE (cc_mode, test_rtx, label_ref, pc_rtx);
6076 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, if_else));
6077 return TRUE;
6081 /* Emit code to set a gpr to 1/0 based on a comparison. The comparison
6082 operands were previously stored in frv_compare_op0 and frv_compare_op1. */
6085 frv_emit_scc (test, target)
6086 enum rtx_code test;
6087 rtx target;
6089 rtx set;
6090 rtx test_rtx;
6091 rtx clobber;
6092 rtx cr_reg;
6093 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
6095 /* SCC instructions generate:
6096 (parallel [(set <target> (<test>, <cc_reg>, (const_int 0))
6097 (clobber (<ccr_reg>))]) */
6098 test_rtx = gen_rtx_fmt_ee (test, SImode, cc_reg, const0_rtx);
6099 set = gen_rtx_SET (VOIDmode, target, test_rtx);
6101 cr_reg = ((TARGET_ALLOC_CC)
6102 ? gen_reg_rtx (CC_CCRmode)
6103 : gen_rtx_REG (CC_CCRmode,
6104 ((GET_MODE (cc_reg) == CC_FPmode)
6105 ? FCR_FIRST
6106 : ICR_FIRST)));
6108 clobber = gen_rtx_CLOBBER (VOIDmode, cr_reg);
6109 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber)));
6110 return TRUE;
6114 /* Split a SCC instruction into component parts, returning a SEQUENCE to hold
6115 the seperate insns. */
6118 frv_split_scc (dest, test, cc_reg, cr_reg, value)
6119 rtx dest;
6120 rtx test;
6121 rtx cc_reg;
6122 rtx cr_reg;
6123 HOST_WIDE_INT value;
6125 rtx ret;
6127 start_sequence ();
6129 /* Set the appropriate CCR bit. */
6130 emit_insn (gen_rtx_SET (VOIDmode,
6131 cr_reg,
6132 gen_rtx_fmt_ee (GET_CODE (test),
6133 GET_MODE (cr_reg),
6134 cc_reg,
6135 const0_rtx)));
6137 /* Move the value into the destination. */
6138 emit_move_insn (dest, GEN_INT (value));
6140 /* Move 0 into the destination if the test failed */
6141 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6142 gen_rtx_EQ (GET_MODE (cr_reg),
6143 cr_reg,
6144 const0_rtx),
6145 gen_rtx_SET (VOIDmode, dest, const0_rtx)));
6147 /* Finish up, return sequence. */
6148 ret = get_insns ();
6149 end_sequence ();
6150 return ret;
6154 /* Emit the code for a conditional move, return TRUE if we could do the
6155 move. */
6158 frv_emit_cond_move (dest, test_rtx, src1, src2)
6159 rtx dest;
6160 rtx test_rtx;
6161 rtx src1;
6162 rtx src2;
6164 rtx set;
6165 rtx clobber_cc;
6166 rtx test2;
6167 rtx cr_reg;
6168 rtx if_rtx;
6169 enum rtx_code test = GET_CODE (test_rtx);
6170 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
6171 enum machine_mode cc_mode = GET_MODE (cc_reg);
6173 /* Conditional move instructions generate:
6174 (parallel [(set <target>
6175 (if_then_else (<test> <cc_reg> (const_int 0))
6176 <src1>
6177 <src2>))
6178 (clobber (<ccr_reg>))]) */
6180 /* Handle various cases of conditional move involving two constants. */
6181 if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT)
6183 HOST_WIDE_INT value1 = INTVAL (src1);
6184 HOST_WIDE_INT value2 = INTVAL (src2);
6186 /* having 0 as one of the constants can be done by loading the other
6187 constant, and optionally moving in gr0. */
6188 if (value1 == 0 || value2 == 0)
6191 /* If the first value is within an addi range and also the difference
6192 between the two fits in an addi's range, load up the difference, then
6193 conditionally move in 0, and then unconditionally add the first
6194 value. */
6195 else if (IN_RANGE_P (value1, -2048, 2047)
6196 && IN_RANGE_P (value2 - value1, -2048, 2047))
6199 /* If neither condition holds, just force the constant into a
6200 register. */
6201 else
6203 src1 = force_reg (GET_MODE (dest), src1);
6204 src2 = force_reg (GET_MODE (dest), src2);
6208 /* If one value is a register, insure the other value is either 0 or a
6209 register. */
6210 else
6212 if (GET_CODE (src1) == CONST_INT && INTVAL (src1) != 0)
6213 src1 = force_reg (GET_MODE (dest), src1);
6215 if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0)
6216 src2 = force_reg (GET_MODE (dest), src2);
6219 test2 = gen_rtx_fmt_ee (test, cc_mode, cc_reg, const0_rtx);
6220 if_rtx = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), test2, src1, src2);
6222 set = gen_rtx_SET (VOIDmode, dest, if_rtx);
6224 cr_reg = ((TARGET_ALLOC_CC)
6225 ? gen_reg_rtx (CC_CCRmode)
6226 : gen_rtx_REG (CC_CCRmode,
6227 (cc_mode == CC_FPmode) ? FCR_FIRST : ICR_FIRST));
6229 clobber_cc = gen_rtx_CLOBBER (VOIDmode, cr_reg);
6230 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber_cc)));
6231 return TRUE;
6235 /* Split a conditonal move into constituent parts, returning a SEQUENCE
6236 containing all of the insns. */
6239 frv_split_cond_move (operands)
6240 rtx operands[];
6242 rtx dest = operands[0];
6243 rtx test = operands[1];
6244 rtx cc_reg = operands[2];
6245 rtx src1 = operands[3];
6246 rtx src2 = operands[4];
6247 rtx cr_reg = operands[5];
6248 rtx ret;
6249 enum machine_mode cr_mode = GET_MODE (cr_reg);
6251 start_sequence ();
6253 /* Set the appropriate CCR bit. */
6254 emit_insn (gen_rtx_SET (VOIDmode,
6255 cr_reg,
6256 gen_rtx_fmt_ee (GET_CODE (test),
6257 GET_MODE (cr_reg),
6258 cc_reg,
6259 const0_rtx)));
6261 /* Handle various cases of conditional move involving two constants. */
6262 if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT)
6264 HOST_WIDE_INT value1 = INTVAL (src1);
6265 HOST_WIDE_INT value2 = INTVAL (src2);
6267 /* having 0 as one of the constants can be done by loading the other
6268 constant, and optionally moving in gr0. */
6269 if (value1 == 0)
6271 emit_move_insn (dest, src2);
6272 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6273 gen_rtx_NE (cr_mode, cr_reg,
6274 const0_rtx),
6275 gen_rtx_SET (VOIDmode, dest, src1)));
6278 else if (value2 == 0)
6280 emit_move_insn (dest, src1);
6281 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6282 gen_rtx_EQ (cr_mode, cr_reg,
6283 const0_rtx),
6284 gen_rtx_SET (VOIDmode, dest, src2)));
6287 /* If the first value is within an addi range and also the difference
6288 between the two fits in an addi's range, load up the difference, then
6289 conditionally move in 0, and then unconditionally add the first
6290 value. */
6291 else if (IN_RANGE_P (value1, -2048, 2047)
6292 && IN_RANGE_P (value2 - value1, -2048, 2047))
6294 rtx dest_si = ((GET_MODE (dest) == SImode)
6295 ? dest
6296 : gen_rtx_SUBREG (SImode, dest, 0));
6298 emit_move_insn (dest_si, GEN_INT (value2 - value1));
6299 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6300 gen_rtx_NE (cr_mode, cr_reg,
6301 const0_rtx),
6302 gen_rtx_SET (VOIDmode, dest_si,
6303 const0_rtx)));
6304 emit_insn (gen_addsi3 (dest_si, dest_si, src1));
6307 else
6308 abort ();
6310 else
6312 /* Emit the conditional move for the test being true if needed. */
6313 if (! rtx_equal_p (dest, src1))
6314 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6315 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6316 gen_rtx_SET (VOIDmode, dest, src1)));
6318 /* Emit the conditional move for the test being false if needed. */
6319 if (! rtx_equal_p (dest, src2))
6320 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6321 gen_rtx_EQ (cr_mode, cr_reg, const0_rtx),
6322 gen_rtx_SET (VOIDmode, dest, src2)));
6325 /* Finish up, return sequence. */
6326 ret = get_insns ();
6327 end_sequence ();
6328 return ret;
6332 /* Split (set DEST SOURCE), where DEST is a double register and SOURCE is a
6333 memory location that is not known to be dword-aligned. */
6334 void
6335 frv_split_double_load (dest, source)
6336 rtx dest;
6337 rtx source;
6339 int regno = REGNO (dest);
6340 rtx dest1 = gen_highpart (SImode, dest);
6341 rtx dest2 = gen_lowpart (SImode, dest);
6342 rtx address = XEXP (source, 0);
6344 /* If the address is pre-modified, load the lower-numbered register
6345 first, then load the other register using an integer offset from
6346 the modified base register. This order should always be safe,
6347 since the pre-modification cannot affect the same registers as the
6348 load does.
6350 The situation for other loads is more complicated. Loading one
6351 of the registers could affect the value of ADDRESS, so we must
6352 be careful which order we do them in. */
6353 if (GET_CODE (address) == PRE_MODIFY
6354 || ! refers_to_regno_p (regno, regno + 1, address, NULL))
6356 /* It is safe to load the lower-numbered register first. */
6357 emit_move_insn (dest1, change_address (source, SImode, NULL));
6358 emit_move_insn (dest2, frv_index_memory (source, SImode, 1));
6360 else
6362 /* ADDRESS is not pre-modified and the address depends on the
6363 lower-numbered register. Load the higher-numbered register
6364 first. */
6365 emit_move_insn (dest2, frv_index_memory (source, SImode, 1));
6366 emit_move_insn (dest1, change_address (source, SImode, NULL));
6370 /* Split (set DEST SOURCE), where DEST refers to a dword memory location
6371 and SOURCE is either a double register or the constant zero. */
6372 void
6373 frv_split_double_store (dest, source)
6374 rtx dest;
6375 rtx source;
6377 rtx dest1 = change_address (dest, SImode, NULL);
6378 rtx dest2 = frv_index_memory (dest, SImode, 1);
6379 if (ZERO_P (source))
6381 emit_move_insn (dest1, CONST0_RTX (SImode));
6382 emit_move_insn (dest2, CONST0_RTX (SImode));
6384 else
6386 emit_move_insn (dest1, gen_highpart (SImode, source));
6387 emit_move_insn (dest2, gen_lowpart (SImode, source));
6392 /* Split a min/max operation returning a SEQUENCE containing all of the
6393 insns. */
6396 frv_split_minmax (operands)
6397 rtx operands[];
6399 rtx dest = operands[0];
6400 rtx minmax = operands[1];
6401 rtx src1 = operands[2];
6402 rtx src2 = operands[3];
6403 rtx cc_reg = operands[4];
6404 rtx cr_reg = operands[5];
6405 rtx ret;
6406 enum rtx_code test_code;
6407 enum machine_mode cr_mode = GET_MODE (cr_reg);
6409 start_sequence ();
6411 /* Figure out which test to use */
6412 switch (GET_CODE (minmax))
6414 default:
6415 abort ();
6417 case SMIN: test_code = LT; break;
6418 case SMAX: test_code = GT; break;
6419 case UMIN: test_code = LTU; break;
6420 case UMAX: test_code = GTU; break;
6423 /* Issue the compare instruction. */
6424 emit_insn (gen_rtx_SET (VOIDmode,
6425 cc_reg,
6426 gen_rtx_COMPARE (GET_MODE (cc_reg),
6427 src1, src2)));
6429 /* Set the appropriate CCR bit. */
6430 emit_insn (gen_rtx_SET (VOIDmode,
6431 cr_reg,
6432 gen_rtx_fmt_ee (test_code,
6433 GET_MODE (cr_reg),
6434 cc_reg,
6435 const0_rtx)));
6437 /* If are taking the min/max of a nonzero constant, load that first, and
6438 then do a conditional move of the other value. */
6439 if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0)
6441 if (rtx_equal_p (dest, src1))
6442 abort ();
6444 emit_move_insn (dest, src2);
6445 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6446 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6447 gen_rtx_SET (VOIDmode, dest, src1)));
6450 /* Otherwise, do each half of the move. */
6451 else
6453 /* Emit the conditional move for the test being true if needed. */
6454 if (! rtx_equal_p (dest, src1))
6455 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6456 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6457 gen_rtx_SET (VOIDmode, dest, src1)));
6459 /* Emit the conditional move for the test being false if needed. */
6460 if (! rtx_equal_p (dest, src2))
6461 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6462 gen_rtx_EQ (cr_mode, cr_reg, const0_rtx),
6463 gen_rtx_SET (VOIDmode, dest, src2)));
6466 /* Finish up, return sequence. */
6467 ret = get_insns ();
6468 end_sequence ();
6469 return ret;
6473 /* Split an integer abs operation returning a SEQUENCE containing all of the
6474 insns. */
6477 frv_split_abs (operands)
6478 rtx operands[];
6480 rtx dest = operands[0];
6481 rtx src = operands[1];
6482 rtx cc_reg = operands[2];
6483 rtx cr_reg = operands[3];
6484 rtx ret;
6486 start_sequence ();
6488 /* Issue the compare < 0 instruction. */
6489 emit_insn (gen_rtx_SET (VOIDmode,
6490 cc_reg,
6491 gen_rtx_COMPARE (CCmode, src, const0_rtx)));
6493 /* Set the appropriate CCR bit. */
6494 emit_insn (gen_rtx_SET (VOIDmode,
6495 cr_reg,
6496 gen_rtx_fmt_ee (LT, CC_CCRmode, cc_reg, const0_rtx)));
6498 /* Emit the conditional negate if the value is negative */
6499 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6500 gen_rtx_NE (CC_CCRmode, cr_reg, const0_rtx),
6501 gen_negsi2 (dest, src)));
6503 /* Emit the conditional move for the test being false if needed. */
6504 if (! rtx_equal_p (dest, src))
6505 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6506 gen_rtx_EQ (CC_CCRmode, cr_reg, const0_rtx),
6507 gen_rtx_SET (VOIDmode, dest, src)));
6509 /* Finish up, return sequence. */
6510 ret = get_insns ();
6511 end_sequence ();
6512 return ret;
6516 /* An internal function called by for_each_rtx to clear in a hard_reg set each
6517 register used in an insn. */
6519 static int
6520 frv_clear_registers_used (ptr, data)
6521 rtx *ptr;
6522 void *data;
6524 if (GET_CODE (*ptr) == REG)
6526 int regno = REGNO (*ptr);
6527 HARD_REG_SET *p_regs = (HARD_REG_SET *)data;
6529 if (regno < FIRST_PSEUDO_REGISTER)
6531 int reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (*ptr));
6533 while (regno < reg_max)
6535 CLEAR_HARD_REG_BIT (*p_regs, regno);
6536 regno++;
6541 return 0;
6545 /* Initialize the extra fields provided by IFCVT_EXTRA_FIELDS. */
6547 /* On the FR-V, we don't have any extra fields per se, but it is useful hook to
6548 initialize the static storage. */
6549 void
6550 frv_ifcvt_init_extra_fields (ce_info)
6551 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
6553 frv_ifcvt.added_insns_list = NULL_RTX;
6554 frv_ifcvt.cur_scratch_regs = 0;
6555 frv_ifcvt.num_nested_cond_exec = 0;
6556 frv_ifcvt.cr_reg = NULL_RTX;
6557 frv_ifcvt.nested_cc_reg = NULL_RTX;
6558 frv_ifcvt.extra_int_cr = NULL_RTX;
6559 frv_ifcvt.extra_fp_cr = NULL_RTX;
6560 frv_ifcvt.last_nested_if_cr = NULL_RTX;
6564 /* Internal function to add a potenial insn to the list of insns to be inserted
6565 if the conditional execution conversion is successful. */
6567 static void
6568 frv_ifcvt_add_insn (pattern, insn, before_p)
6569 rtx pattern;
6570 rtx insn;
6571 int before_p;
6573 rtx link = alloc_EXPR_LIST (VOIDmode, pattern, insn);
6575 link->jump = before_p; /* mark to add this before or after insn */
6576 frv_ifcvt.added_insns_list = alloc_EXPR_LIST (VOIDmode, link,
6577 frv_ifcvt.added_insns_list);
6579 if (TARGET_DEBUG_COND_EXEC)
6581 fprintf (stderr,
6582 "\n:::::::::: frv_ifcvt_add_insn: add the following %s insn %d:\n",
6583 (before_p) ? "before" : "after",
6584 (int)INSN_UID (insn));
6586 debug_rtx (pattern);
6591 /* A C expression to modify the code described by the conditional if
6592 information CE_INFO, possibly updating the tests in TRUE_EXPR, and
6593 FALSE_EXPR for converting if-then and if-then-else code to conditional
6594 instructions. Set either TRUE_EXPR or FALSE_EXPR to a null pointer if the
6595 tests cannot be converted. */
6597 void
6598 frv_ifcvt_modify_tests (ce_info, p_true, p_false)
6599 ce_if_block_t *ce_info;
6600 rtx *p_true;
6601 rtx *p_false;
6603 basic_block test_bb = ce_info->test_bb; /* test basic block */
6604 basic_block then_bb = ce_info->then_bb; /* THEN */
6605 basic_block else_bb = ce_info->else_bb; /* ELSE or NULL */
6606 basic_block join_bb = ce_info->join_bb; /* join block or NULL */
6607 rtx true_expr = *p_true;
6608 rtx cr;
6609 rtx cc;
6610 rtx nested_cc;
6611 enum machine_mode mode = GET_MODE (true_expr);
6612 int j;
6613 basic_block *bb;
6614 int num_bb;
6615 frv_tmp_reg_t *tmp_reg = &frv_ifcvt.tmp_reg;
6616 rtx check_insn;
6617 rtx sub_cond_exec_reg;
6618 enum rtx_code code;
6619 enum rtx_code code_true;
6620 enum rtx_code code_false;
6621 enum reg_class cc_class;
6622 enum reg_class cr_class;
6623 int cc_first;
6624 int cc_last;
6626 /* Make sure we are only dealing with hard registers. Also honor the
6627 -mno-cond-exec switch, and -mno-nested-cond-exec switches if
6628 applicable. */
6629 if (!reload_completed || TARGET_NO_COND_EXEC
6630 || (TARGET_NO_NESTED_CE && ce_info->pass > 1))
6631 goto fail;
6633 /* Figure out which registers we can allocate for our own purposes. Only
6634 consider registers that are not preserved across function calls and are
6635 not fixed. However, allow the ICC/ICR temporary registers to be allocated
6636 if we did not need to use them in reloading other registers. */
6637 memset ((PTR) &tmp_reg->regs, 0, sizeof (tmp_reg->regs));
6638 COPY_HARD_REG_SET (tmp_reg->regs, call_used_reg_set);
6639 AND_COMPL_HARD_REG_SET (tmp_reg->regs, fixed_reg_set);
6640 SET_HARD_REG_BIT (tmp_reg->regs, ICC_TEMP);
6641 SET_HARD_REG_BIT (tmp_reg->regs, ICR_TEMP);
6643 /* If this is a nested IF, we need to discover whether the CC registers that
6644 are set/used inside of the block are used anywhere else. If not, we can
6645 change them to be the CC register that is paired with the CR register that
6646 controls the outermost IF block. */
6647 if (ce_info->pass > 1)
6649 CLEAR_HARD_REG_SET (frv_ifcvt.nested_cc_ok_rewrite);
6650 for (j = CC_FIRST; j <= CC_LAST; j++)
6651 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6653 if (REGNO_REG_SET_P (then_bb->global_live_at_start, j))
6654 continue;
6656 if (else_bb && REGNO_REG_SET_P (else_bb->global_live_at_start, j))
6657 continue;
6659 if (join_bb && REGNO_REG_SET_P (join_bb->global_live_at_start, j))
6660 continue;
6662 SET_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j);
6666 for (j = 0; j < frv_ifcvt.cur_scratch_regs; j++)
6667 frv_ifcvt.scratch_regs[j] = NULL_RTX;
6669 frv_ifcvt.added_insns_list = NULL_RTX;
6670 frv_ifcvt.cur_scratch_regs = 0;
6672 bb = (basic_block *) alloca ((2 + ce_info->num_multiple_test_blocks)
6673 * sizeof (basic_block));
6675 if (join_bb)
6677 int regno;
6679 /* Remove anything live at the beginning of the join block from being
6680 available for allocation. */
6681 EXECUTE_IF_SET_IN_REG_SET (join_bb->global_live_at_start, 0, regno,
6683 if (regno < FIRST_PSEUDO_REGISTER)
6684 CLEAR_HARD_REG_BIT (tmp_reg->regs, regno);
6688 /* Add in all of the blocks in multiple &&/|| blocks to be scanned. */
6689 num_bb = 0;
6690 if (ce_info->num_multiple_test_blocks)
6692 basic_block multiple_test_bb = ce_info->last_test_bb;
6694 while (multiple_test_bb != test_bb)
6696 bb[num_bb++] = multiple_test_bb;
6697 multiple_test_bb = multiple_test_bb->pred->src;
6701 /* Add in the THEN and ELSE blocks to be scanned. */
6702 bb[num_bb++] = then_bb;
6703 if (else_bb)
6704 bb[num_bb++] = else_bb;
6706 sub_cond_exec_reg = NULL_RTX;
6707 frv_ifcvt.num_nested_cond_exec = 0;
6709 /* Scan all of the blocks for registers that must not be allocated. */
6710 for (j = 0; j < num_bb; j++)
6712 rtx last_insn = bb[j]->end;
6713 rtx insn = bb[j]->head;
6714 int regno;
6716 if (rtl_dump_file)
6717 fprintf (rtl_dump_file, "Scanning %s block %d, start %d, end %d\n",
6718 (bb[j] == else_bb) ? "else" : ((bb[j] == then_bb) ? "then" : "test"),
6719 (int) bb[j]->index,
6720 (int) INSN_UID (bb[j]->head),
6721 (int) INSN_UID (bb[j]->end));
6723 /* Anything live at the beginning of the block is obviously unavailable
6724 for allocation. */
6725 EXECUTE_IF_SET_IN_REG_SET (bb[j]->global_live_at_start, 0, regno,
6727 if (regno < FIRST_PSEUDO_REGISTER)
6728 CLEAR_HARD_REG_BIT (tmp_reg->regs, regno);
6731 /* loop through the insns in the block. */
6732 for (;;)
6734 /* Mark any new registers that are created as being unavailable for
6735 allocation. Also see if the CC register used in nested IFs can be
6736 reallocated. */
6737 if (INSN_P (insn))
6739 rtx pattern;
6740 rtx set;
6741 int skip_nested_if = FALSE;
6743 for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
6744 (void *)&tmp_reg->regs);
6746 pattern = PATTERN (insn);
6747 if (GET_CODE (pattern) == COND_EXEC)
6749 rtx reg = XEXP (COND_EXEC_TEST (pattern), 0);
6751 if (reg != sub_cond_exec_reg)
6753 sub_cond_exec_reg = reg;
6754 frv_ifcvt.num_nested_cond_exec++;
6758 set = single_set_pattern (pattern);
6759 if (set)
6761 rtx dest = SET_DEST (set);
6762 rtx src = SET_SRC (set);
6764 if (GET_CODE (dest) == REG)
6766 int regno = REGNO (dest);
6767 enum rtx_code src_code = GET_CODE (src);
6769 if (CC_P (regno) && src_code == COMPARE)
6770 skip_nested_if = TRUE;
6772 else if (CR_P (regno)
6773 && (src_code == IF_THEN_ELSE
6774 || GET_RTX_CLASS (src_code) == '<'))
6775 skip_nested_if = TRUE;
6779 if (! skip_nested_if)
6780 for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
6781 (void *)&frv_ifcvt.nested_cc_ok_rewrite);
6784 if (insn == last_insn)
6785 break;
6787 insn = NEXT_INSN (insn);
6791 /* If this is a nested if, rewrite the CC registers that are available to
6792 include the ones that can be rewritten, to increase the chance of being
6793 able to allocate a paired CC/CR register combination. */
6794 if (ce_info->pass > 1)
6796 for (j = CC_FIRST; j <= CC_LAST; j++)
6797 if (TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j))
6798 SET_HARD_REG_BIT (tmp_reg->regs, j);
6799 else
6800 CLEAR_HARD_REG_BIT (tmp_reg->regs, j);
6803 if (rtl_dump_file)
6805 int num_gprs = 0;
6806 fprintf (rtl_dump_file, "Available GPRs: ");
6808 for (j = GPR_FIRST; j <= GPR_LAST; j++)
6809 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6811 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6812 if (++num_gprs > GPR_TEMP_NUM+2)
6813 break;
6816 fprintf (rtl_dump_file, "%s\nAvailable CRs: ",
6817 (num_gprs > GPR_TEMP_NUM+2) ? " ..." : "");
6819 for (j = CR_FIRST; j <= CR_LAST; j++)
6820 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6821 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6823 fputs ("\n", rtl_dump_file);
6825 if (ce_info->pass > 1)
6827 fprintf (rtl_dump_file, "Modifiable CCs: ");
6828 for (j = CC_FIRST; j <= CC_LAST; j++)
6829 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6830 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6832 fprintf (rtl_dump_file, "\n%d nested COND_EXEC statements\n",
6833 frv_ifcvt.num_nested_cond_exec);
6837 /* Allocate the appropriate temporary condition code register. Try to
6838 allocate the ICR/FCR register that corresponds to the ICC/FCC register so
6839 that conditional cmp's can be done. */
6840 if (mode == CCmode || mode == CC_UNSmode)
6842 cr_class = ICR_REGS;
6843 cc_class = ICC_REGS;
6844 cc_first = ICC_FIRST;
6845 cc_last = ICC_LAST;
6847 else if (mode == CC_FPmode)
6849 cr_class = FCR_REGS;
6850 cc_class = FCC_REGS;
6851 cc_first = FCC_FIRST;
6852 cc_last = FCC_LAST;
6854 else
6856 cc_first = cc_last = 0;
6857 cr_class = cc_class = NO_REGS;
6860 cc = XEXP (true_expr, 0);
6861 nested_cc = cr = NULL_RTX;
6862 if (cc_class != NO_REGS)
6864 /* For nested IFs and &&/||, see if we can find a CC and CR register pair
6865 so we can execute a csubcc/caddcc/cfcmps instruction. */
6866 int cc_regno;
6868 for (cc_regno = cc_first; cc_regno <= cc_last; cc_regno++)
6870 int cr_regno = cc_regno - CC_FIRST + CR_FIRST;
6872 if (TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cc_regno)
6873 && TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cr_regno))
6875 frv_ifcvt.tmp_reg.next_reg[ (int)cr_class ] = cr_regno;
6876 cr = frv_alloc_temp_reg (tmp_reg, cr_class, CC_CCRmode, TRUE,
6877 TRUE);
6879 frv_ifcvt.tmp_reg.next_reg[ (int)cc_class ] = cc_regno;
6880 nested_cc = frv_alloc_temp_reg (tmp_reg, cc_class, CCmode,
6881 TRUE, TRUE);
6882 break;
6887 if (! cr)
6889 if (rtl_dump_file)
6890 fprintf (rtl_dump_file, "Could not allocate a CR temporary register\n");
6892 goto fail;
6895 if (rtl_dump_file)
6896 fprintf (rtl_dump_file,
6897 "Will use %s for conditional execution, %s for nested comparisons\n",
6898 reg_names[ REGNO (cr)],
6899 (nested_cc) ? reg_names[ REGNO (nested_cc) ] : "<none>");
6901 /* Set the CCR bit. Note for integer tests, we reverse the condition so that
6902 in an IF-THEN-ELSE sequence, we are testing the TRUE case against the CCR
6903 bit being true. We don't do this for floating point, because of NaNs. */
6904 code = GET_CODE (true_expr);
6905 if (GET_MODE (cc) != CC_FPmode)
6907 code = reverse_condition (code);
6908 code_true = EQ;
6909 code_false = NE;
6911 else
6913 code_true = NE;
6914 code_false = EQ;
6917 check_insn = gen_rtx_SET (VOIDmode, cr,
6918 gen_rtx_fmt_ee (code, CC_CCRmode, cc, const0_rtx));
6920 /* Record the check insn to be inserted later. */
6921 frv_ifcvt_add_insn (check_insn, test_bb->end, TRUE);
6923 /* Update the tests. */
6924 frv_ifcvt.cr_reg = cr;
6925 frv_ifcvt.nested_cc_reg = nested_cc;
6926 *p_true = gen_rtx_fmt_ee (code_true, CC_CCRmode, cr, const0_rtx);
6927 *p_false = gen_rtx_fmt_ee (code_false, CC_CCRmode, cr, const0_rtx);
6928 return;
6930 /* Fail, don't do this conditional execution. */
6931 fail:
6932 *p_true = NULL_RTX;
6933 *p_false = NULL_RTX;
6934 if (rtl_dump_file)
6935 fprintf (rtl_dump_file, "Disabling this conditional execution.\n");
6937 return;
6941 /* A C expression to modify the code described by the conditional if
6942 information CE_INFO, for the basic block BB, possibly updating the tests in
6943 TRUE_EXPR, and FALSE_EXPR for converting the && and || parts of if-then or
6944 if-then-else code to conditional instructions. Set either TRUE_EXPR or
6945 FALSE_EXPR to a null pointer if the tests cannot be converted. */
6947 /* p_true and p_false are given expressions of the form:
6949 (and (eq:CC_CCR (reg:CC_CCR)
6950 (const_int 0))
6951 (eq:CC (reg:CC)
6952 (const_int 0))) */
6954 void
6955 frv_ifcvt_modify_multiple_tests (ce_info, bb, p_true, p_false)
6956 ce_if_block_t *ce_info;
6957 basic_block bb;
6958 rtx *p_true;
6959 rtx *p_false;
6961 rtx old_true = XEXP (*p_true, 0);
6962 rtx old_false = XEXP (*p_false, 0);
6963 rtx true_expr = XEXP (*p_true, 1);
6964 rtx false_expr = XEXP (*p_false, 1);
6965 rtx test_expr;
6966 rtx old_test;
6967 rtx cr = XEXP (old_true, 0);
6968 rtx check_insn;
6969 rtx new_cr = NULL_RTX;
6970 rtx *p_new_cr = (rtx *)0;
6971 rtx if_else;
6972 rtx compare;
6973 rtx cc;
6974 enum reg_class cr_class;
6975 enum machine_mode mode = GET_MODE (true_expr);
6976 rtx (*logical_func)(rtx, rtx, rtx);
6978 if (TARGET_DEBUG_COND_EXEC)
6980 fprintf (stderr,
6981 "\n:::::::::: frv_ifcvt_modify_multiple_tests, before modification for %s\ntrue insn:\n",
6982 ce_info->and_and_p ? "&&" : "||");
6984 debug_rtx (*p_true);
6986 fputs ("\nfalse insn:\n", stderr);
6987 debug_rtx (*p_false);
6990 if (TARGET_NO_MULTI_CE)
6991 goto fail;
6993 if (GET_CODE (cr) != REG)
6994 goto fail;
6996 if (mode == CCmode || mode == CC_UNSmode)
6998 cr_class = ICR_REGS;
6999 p_new_cr = &frv_ifcvt.extra_int_cr;
7001 else if (mode == CC_FPmode)
7003 cr_class = FCR_REGS;
7004 p_new_cr = &frv_ifcvt.extra_fp_cr;
7006 else
7007 goto fail;
7009 /* Allocate a temp CR, reusing a previously allocated temp CR if we have 3 or
7010 more &&/|| tests. */
7011 new_cr = *p_new_cr;
7012 if (! new_cr)
7014 new_cr = *p_new_cr = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, cr_class,
7015 CC_CCRmode, TRUE, TRUE);
7016 if (! new_cr)
7017 goto fail;
7020 if (ce_info->and_and_p)
7022 old_test = old_false;
7023 test_expr = true_expr;
7024 logical_func = (GET_CODE (old_true) == EQ) ? gen_andcr : gen_andncr;
7025 *p_true = gen_rtx_NE (CC_CCRmode, cr, const0_rtx);
7026 *p_false = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx);
7028 else
7030 old_test = old_false;
7031 test_expr = false_expr;
7032 logical_func = (GET_CODE (old_false) == EQ) ? gen_orcr : gen_orncr;
7033 *p_true = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx);
7034 *p_false = gen_rtx_NE (CC_CCRmode, cr, const0_rtx);
7037 /* First add the andcr/andncr/orcr/orncr, which will be added after the
7038 conditional check instruction, due to frv_ifcvt_add_insn being a LIFO
7039 stack. */
7040 frv_ifcvt_add_insn ((*logical_func) (cr, cr, new_cr), bb->end, TRUE);
7042 /* Now add the conditional check insn. */
7043 cc = XEXP (test_expr, 0);
7044 compare = gen_rtx_fmt_ee (GET_CODE (test_expr), CC_CCRmode, cc, const0_rtx);
7045 if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, old_test, compare, const0_rtx);
7047 check_insn = gen_rtx_SET (VOIDmode, new_cr, if_else);
7049 /* add the new check insn to the list of check insns that need to be
7050 inserted. */
7051 frv_ifcvt_add_insn (check_insn, bb->end, TRUE);
7053 if (TARGET_DEBUG_COND_EXEC)
7055 fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, after modification\ntrue insn:\n",
7056 stderr);
7058 debug_rtx (*p_true);
7060 fputs ("\nfalse insn:\n", stderr);
7061 debug_rtx (*p_false);
7064 return;
7066 fail:
7067 *p_true = *p_false = NULL_RTX;
7069 /* If we allocated a CR register, release it. */
7070 if (new_cr)
7072 CLEAR_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, REGNO (new_cr));
7073 *p_new_cr = NULL_RTX;
7076 if (TARGET_DEBUG_COND_EXEC)
7077 fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, failed.\n", stderr);
7079 return;
7083 /* Return a register which will be loaded with a value if an IF block is
7084 converted to conditional execution. This is used to rewrite instructions
7085 that use constants to ones that just use registers. */
7087 static rtx
7088 frv_ifcvt_load_value (value, insn)
7089 rtx value;
7090 rtx insn ATTRIBUTE_UNUSED;
7092 int num_alloc = frv_ifcvt.cur_scratch_regs;
7093 int i;
7094 rtx reg;
7096 /* We know gr0 == 0, so replace any errant uses. */
7097 if (value == const0_rtx)
7098 return gen_rtx_REG (SImode, GPR_FIRST);
7100 /* First search all registers currently loaded to see if we have an
7101 applicable constant. */
7102 if (CONSTANT_P (value)
7103 || (GET_CODE (value) == REG && REGNO (value) == LR_REGNO))
7105 for (i = 0; i < num_alloc; i++)
7107 if (rtx_equal_p (SET_SRC (frv_ifcvt.scratch_regs[i]), value))
7108 return SET_DEST (frv_ifcvt.scratch_regs[i]);
7112 /* Have we exhausted the number of registers available? */
7113 if (num_alloc >= GPR_TEMP_NUM)
7115 if (rtl_dump_file)
7116 fprintf (rtl_dump_file, "Too many temporary registers allocated\n");
7118 return NULL_RTX;
7121 /* Allocate the new register. */
7122 reg = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, GPR_REGS, SImode, TRUE, TRUE);
7123 if (! reg)
7125 if (rtl_dump_file)
7126 fputs ("Could not find a scratch register\n", rtl_dump_file);
7128 return NULL_RTX;
7131 frv_ifcvt.cur_scratch_regs++;
7132 frv_ifcvt.scratch_regs[num_alloc] = gen_rtx_SET (VOIDmode, reg, value);
7134 if (rtl_dump_file)
7136 if (GET_CODE (value) == CONST_INT)
7137 fprintf (rtl_dump_file, "Register %s will hold %ld\n",
7138 reg_names[ REGNO (reg)], (long)INTVAL (value));
7140 else if (GET_CODE (value) == REG && REGNO (value) == LR_REGNO)
7141 fprintf (rtl_dump_file, "Register %s will hold LR\n",
7142 reg_names[ REGNO (reg)]);
7144 else
7145 fprintf (rtl_dump_file, "Register %s will hold a saved value\n",
7146 reg_names[ REGNO (reg)]);
7149 return reg;
7153 /* Update a MEM used in conditional code that might contain an offset to put
7154 the offset into a scratch register, so that the conditional load/store
7155 operations can be used. This function returns the original pointer if the
7156 MEM is valid to use in conditional code, NULL if we can't load up the offset
7157 into a temporary register, or the new MEM if we were successful. */
7159 static rtx
7160 frv_ifcvt_rewrite_mem (mem, mode, insn)
7161 rtx mem;
7162 enum machine_mode mode;
7163 rtx insn;
7165 rtx addr = XEXP (mem, 0);
7167 if (!frv_legitimate_address_p (mode, addr, reload_completed, TRUE))
7169 if (GET_CODE (addr) == PLUS)
7171 rtx addr_op0 = XEXP (addr, 0);
7172 rtx addr_op1 = XEXP (addr, 1);
7174 if (plus_small_data_p (addr_op0, addr_op1))
7175 addr = frv_ifcvt_load_value (addr, insn);
7177 else if (GET_CODE (addr_op0) == REG && CONSTANT_P (addr_op1))
7179 rtx reg = frv_ifcvt_load_value (addr_op1, insn);
7180 if (!reg)
7181 return NULL_RTX;
7183 addr = gen_rtx_PLUS (Pmode, addr_op0, reg);
7186 else
7187 return NULL_RTX;
7190 else if (CONSTANT_P (addr))
7191 addr = frv_ifcvt_load_value (addr, insn);
7193 else
7194 return NULL_RTX;
7196 if (addr == NULL_RTX)
7197 return NULL_RTX;
7199 else if (XEXP (mem, 0) != addr)
7200 return change_address (mem, mode, addr);
7203 return mem;
7207 /* Given a PATTERN, return a SET expression if this PATTERN has only a single
7208 SET, possibly conditionally executed. It may also have CLOBBERs, USEs. */
7210 static rtx
7211 single_set_pattern (pattern)
7212 rtx pattern;
7214 rtx set;
7215 int i;
7217 if (GET_CODE (pattern) == COND_EXEC)
7218 pattern = COND_EXEC_CODE (pattern);
7220 if (GET_CODE (pattern) == SET)
7221 return pattern;
7223 else if (GET_CODE (pattern) == PARALLEL)
7225 for (i = 0, set = 0; i < XVECLEN (pattern, 0); i++)
7227 rtx sub = XVECEXP (pattern, 0, i);
7229 switch (GET_CODE (sub))
7231 case USE:
7232 case CLOBBER:
7233 break;
7235 case SET:
7236 if (set)
7237 return 0;
7238 else
7239 set = sub;
7240 break;
7242 default:
7243 return 0;
7246 return set;
7249 return 0;
7253 /* A C expression to modify the code described by the conditional if
7254 information CE_INFO with the new PATTERN in INSN. If PATTERN is a null
7255 pointer after the IFCVT_MODIFY_INSN macro executes, it is assumed that that
7256 insn cannot be converted to be executed conditionally. */
7259 frv_ifcvt_modify_insn (ce_info, pattern, insn)
7260 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
7261 rtx pattern;
7262 rtx insn;
7264 rtx orig_ce_pattern = pattern;
7265 rtx set;
7266 rtx op0;
7267 rtx op1;
7268 rtx test;
7270 if (GET_CODE (pattern) != COND_EXEC)
7271 abort ();
7273 test = COND_EXEC_TEST (pattern);
7274 if (GET_CODE (test) == AND)
7276 rtx cr = frv_ifcvt.cr_reg;
7277 rtx test_reg;
7279 op0 = XEXP (test, 0);
7280 if (! rtx_equal_p (cr, XEXP (op0, 0)))
7281 goto fail;
7283 op1 = XEXP (test, 1);
7284 test_reg = XEXP (op1, 0);
7285 if (GET_CODE (test_reg) != REG)
7286 goto fail;
7288 /* Is this the first nested if block in this sequence? If so, generate
7289 an andcr or andncr. */
7290 if (! frv_ifcvt.last_nested_if_cr)
7292 rtx and_op;
7294 frv_ifcvt.last_nested_if_cr = test_reg;
7295 if (GET_CODE (op0) == NE)
7296 and_op = gen_andcr (test_reg, cr, test_reg);
7297 else
7298 and_op = gen_andncr (test_reg, cr, test_reg);
7300 frv_ifcvt_add_insn (and_op, insn, TRUE);
7303 /* If this isn't the first statement in the nested if sequence, see if we
7304 are dealing with the same register. */
7305 else if (! rtx_equal_p (test_reg, frv_ifcvt.last_nested_if_cr))
7306 goto fail;
7308 COND_EXEC_TEST (pattern) = test = op1;
7311 /* If this isn't a nested if, reset state variables. */
7312 else
7314 frv_ifcvt.last_nested_if_cr = NULL_RTX;
7317 set = single_set_pattern (pattern);
7318 if (set)
7320 rtx dest = SET_DEST (set);
7321 rtx src = SET_SRC (set);
7322 enum machine_mode mode = GET_MODE (dest);
7324 /* Check for normal binary operators */
7325 if (mode == SImode
7326 && (GET_RTX_CLASS (GET_CODE (src)) == '2'
7327 || GET_RTX_CLASS (GET_CODE (src)) == 'c'))
7329 op0 = XEXP (src, 0);
7330 op1 = XEXP (src, 1);
7332 /* Special case load of small data address which looks like:
7333 r16+symbol_ref */
7334 if (GET_CODE (src) == PLUS && plus_small_data_p (op0, op1))
7336 src = frv_ifcvt_load_value (src, insn);
7337 if (src)
7338 COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src);
7339 else
7340 goto fail;
7343 else if (integer_register_operand (op0, SImode) && CONSTANT_P (op1))
7345 op1 = frv_ifcvt_load_value (op1, insn);
7346 if (op1)
7347 COND_EXEC_CODE (pattern)
7348 = gen_rtx_SET (VOIDmode, dest, gen_rtx_fmt_ee (GET_CODE (src),
7349 GET_MODE (src),
7350 op0, op1));
7351 else
7352 goto fail;
7356 /* For multiply by a constant, we need to handle the sign extending
7357 correctly. Add a USE of the value after the multiply to prevent flow
7358 from cratering because only one register out of the two were used. */
7359 else if (mode == DImode && GET_CODE (src) == MULT)
7361 op0 = XEXP (src, 0);
7362 op1 = XEXP (src, 1);
7363 if (GET_CODE (op0) == SIGN_EXTEND && GET_CODE (op1) == CONST_INT)
7365 op1 = frv_ifcvt_load_value (op1, insn);
7366 if (op1)
7368 op1 = gen_rtx_SIGN_EXTEND (DImode, op1);
7369 COND_EXEC_CODE (pattern)
7370 = gen_rtx_SET (VOIDmode, dest,
7371 gen_rtx_MULT (DImode, op0, op1));
7373 else
7374 goto fail;
7377 frv_ifcvt_add_insn (gen_rtx_USE (VOIDmode, dest), insn, FALSE);
7380 /* If we are just loading a constant created for a nested conditional
7381 execution statement, just load the constant without any conditional
7382 execution, since we know that the constant will not interfere with any
7383 other registers. */
7384 else if (frv_ifcvt.scratch_insns_bitmap
7385 && bitmap_bit_p (frv_ifcvt.scratch_insns_bitmap,
7386 INSN_UID (insn)))
7387 pattern = set;
7389 else if (mode == QImode || mode == HImode || mode == SImode
7390 || mode == SFmode)
7392 int changed_p = FALSE;
7394 /* Check for just loading up a constant */
7395 if (CONSTANT_P (src) && integer_register_operand (dest, mode))
7397 src = frv_ifcvt_load_value (src, insn);
7398 if (!src)
7399 goto fail;
7401 changed_p = TRUE;
7404 /* See if we need to fix up stores */
7405 if (GET_CODE (dest) == MEM)
7407 rtx new_mem = frv_ifcvt_rewrite_mem (dest, mode, insn);
7409 if (!new_mem)
7410 goto fail;
7412 else if (new_mem != dest)
7414 changed_p = TRUE;
7415 dest = new_mem;
7419 /* See if we need to fix up loads */
7420 if (GET_CODE (src) == MEM)
7422 rtx new_mem = frv_ifcvt_rewrite_mem (src, mode, insn);
7424 if (!new_mem)
7425 goto fail;
7427 else if (new_mem != src)
7429 changed_p = TRUE;
7430 src = new_mem;
7434 /* If either src or destination changed, redo SET. */
7435 if (changed_p)
7436 COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src);
7439 /* Rewrite a nested set cccr in terms of IF_THEN_ELSE. Also deal with
7440 rewriting the CC register to be the same as the paired CC/CR register
7441 for nested ifs. */
7442 else if (mode == CC_CCRmode && GET_RTX_CLASS (GET_CODE (src)) == '<')
7444 int regno = REGNO (XEXP (src, 0));
7445 rtx if_else;
7447 if (ce_info->pass > 1
7448 && regno != (int)REGNO (frv_ifcvt.nested_cc_reg)
7449 && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, regno))
7451 src = gen_rtx_fmt_ee (GET_CODE (src),
7452 CC_CCRmode,
7453 frv_ifcvt.nested_cc_reg,
7454 XEXP (src, 1));
7457 if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, test, src, const0_rtx);
7458 pattern = gen_rtx_SET (VOIDmode, dest, if_else);
7461 /* Remap a nested compare instruction to use the paired CC/CR reg. */
7462 else if (ce_info->pass > 1
7463 && GET_CODE (dest) == REG
7464 && CC_P (REGNO (dest))
7465 && REGNO (dest) != REGNO (frv_ifcvt.nested_cc_reg)
7466 && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite,
7467 REGNO (dest))
7468 && GET_CODE (src) == COMPARE)
7470 PUT_MODE (frv_ifcvt.nested_cc_reg, GET_MODE (dest));
7471 COND_EXEC_CODE (pattern)
7472 = gen_rtx_SET (VOIDmode, frv_ifcvt.nested_cc_reg, copy_rtx (src));
7476 if (TARGET_DEBUG_COND_EXEC)
7478 rtx orig_pattern = PATTERN (insn);
7480 PATTERN (insn) = pattern;
7481 fprintf (stderr,
7482 "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn after modification:\n",
7483 ce_info->pass);
7485 debug_rtx (insn);
7486 PATTERN (insn) = orig_pattern;
7489 return pattern;
7491 fail:
7492 if (TARGET_DEBUG_COND_EXEC)
7494 rtx orig_pattern = PATTERN (insn);
7496 PATTERN (insn) = orig_ce_pattern;
7497 fprintf (stderr,
7498 "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn could not be modified:\n",
7499 ce_info->pass);
7501 debug_rtx (insn);
7502 PATTERN (insn) = orig_pattern;
7505 return NULL_RTX;
7509 /* A C expression to perform any final machine dependent modifications in
7510 converting code to conditional execution in the code described by the
7511 conditional if information CE_INFO. */
7513 void
7514 frv_ifcvt_modify_final (ce_info)
7515 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
7517 rtx existing_insn;
7518 rtx check_insn;
7519 rtx p = frv_ifcvt.added_insns_list;
7520 int i;
7522 /* Loop inserting the check insns. The last check insn is the first test,
7523 and is the appropriate place to insert constants. */
7524 if (! p)
7525 abort ();
7529 rtx check_and_insert_insns = XEXP (p, 0);
7530 rtx old_p = p;
7532 check_insn = XEXP (check_and_insert_insns, 0);
7533 existing_insn = XEXP (check_and_insert_insns, 1);
7534 p = XEXP (p, 1);
7536 /* The jump bit is used to say that the new insn is to be inserted BEFORE
7537 the existing insn, otherwise it is to be inserted AFTER. */
7538 if (check_and_insert_insns->jump)
7540 emit_insn_before (check_insn, existing_insn);
7541 check_and_insert_insns->jump = 0;
7543 else
7544 emit_insn_after (check_insn, existing_insn);
7546 free_EXPR_LIST_node (check_and_insert_insns);
7547 free_EXPR_LIST_node (old_p);
7549 while (p != NULL_RTX);
7551 /* Load up any constants needed into temp gprs */
7552 for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++)
7554 rtx insn = emit_insn_before (frv_ifcvt.scratch_regs[i], existing_insn);
7555 if (! frv_ifcvt.scratch_insns_bitmap)
7556 frv_ifcvt.scratch_insns_bitmap = BITMAP_XMALLOC ();
7557 bitmap_set_bit (frv_ifcvt.scratch_insns_bitmap, INSN_UID (insn));
7558 frv_ifcvt.scratch_regs[i] = NULL_RTX;
7561 frv_ifcvt.added_insns_list = NULL_RTX;
7562 frv_ifcvt.cur_scratch_regs = 0;
7566 /* A C expression to cancel any machine dependent modifications in converting
7567 code to conditional execution in the code described by the conditional if
7568 information CE_INFO. */
7570 void
7571 frv_ifcvt_modify_cancel (ce_info)
7572 ce_if_block_t *ce_info ATTRIBUTE_UNUSED;
7574 int i;
7575 rtx p = frv_ifcvt.added_insns_list;
7577 /* Loop freeing up the EXPR_LIST's allocated. */
7578 while (p != NULL_RTX)
7580 rtx check_and_jump = XEXP (p, 0);
7581 rtx old_p = p;
7583 p = XEXP (p, 1);
7584 free_EXPR_LIST_node (check_and_jump);
7585 free_EXPR_LIST_node (old_p);
7588 /* Release any temporary gprs allocated. */
7589 for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++)
7590 frv_ifcvt.scratch_regs[i] = NULL_RTX;
7592 frv_ifcvt.added_insns_list = NULL_RTX;
7593 frv_ifcvt.cur_scratch_regs = 0;
7594 return;
7597 /* A C expression for the size in bytes of the trampoline, as an integer.
7598 The template is:
7600 setlo #0, <jmp_reg>
7601 setlo #0, <static_chain>
7602 sethi #0, <jmp_reg>
7603 sethi #0, <static_chain>
7604 jmpl @(gr0,<jmp_reg>) */
7607 frv_trampoline_size ()
7609 return 5 /* instructions */ * 4 /* instruction size */;
7613 /* A C statement to initialize the variable parts of a trampoline. ADDR is an
7614 RTX for the address of the trampoline; FNADDR is an RTX for the address of
7615 the nested function; STATIC_CHAIN is an RTX for the static chain value that
7616 should be passed to the function when it is called.
7618 The template is:
7620 setlo #0, <jmp_reg>
7621 setlo #0, <static_chain>
7622 sethi #0, <jmp_reg>
7623 sethi #0, <static_chain>
7624 jmpl @(gr0,<jmp_reg>) */
7626 void
7627 frv_initialize_trampoline (addr, fnaddr, static_chain)
7628 rtx addr;
7629 rtx fnaddr;
7630 rtx static_chain;
7632 rtx sc_reg = force_reg (Pmode, static_chain);
7634 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
7635 FALSE, VOIDmode, 4,
7636 addr, Pmode,
7637 GEN_INT (frv_trampoline_size ()), SImode,
7638 fnaddr, Pmode,
7639 sc_reg, Pmode);
7643 /* Many machines have some registers that cannot be copied directly to or from
7644 memory or even from other types of registers. An example is the `MQ'
7645 register, which on most machines, can only be copied to or from general
7646 registers, but not memory. Some machines allow copying all registers to and
7647 from memory, but require a scratch register for stores to some memory
7648 locations (e.g., those with symbolic address on the RT, and those with
7649 certain symbolic address on the SPARC when compiling PIC). In some cases,
7650 both an intermediate and a scratch register are required.
7652 You should define these macros to indicate to the reload phase that it may
7653 need to allocate at least one register for a reload in addition to the
7654 register to contain the data. Specifically, if copying X to a register
7655 CLASS in MODE requires an intermediate register, you should define
7656 `SECONDARY_INPUT_RELOAD_CLASS' to return the largest register class all of
7657 whose registers can be used as intermediate registers or scratch registers.
7659 If copying a register CLASS in MODE to X requires an intermediate or scratch
7660 register, `SECONDARY_OUTPUT_RELOAD_CLASS' should be defined to return the
7661 largest register class required. If the requirements for input and output
7662 reloads are the same, the macro `SECONDARY_RELOAD_CLASS' should be used
7663 instead of defining both macros identically.
7665 The values returned by these macros are often `GENERAL_REGS'. Return
7666 `NO_REGS' if no spare register is needed; i.e., if X can be directly copied
7667 to or from a register of CLASS in MODE without requiring a scratch register.
7668 Do not define this macro if it would always return `NO_REGS'.
7670 If a scratch register is required (either with or without an intermediate
7671 register), you should define patterns for `reload_inM' or `reload_outM', as
7672 required.. These patterns, which will normally be implemented with a
7673 `define_expand', should be similar to the `movM' patterns, except that
7674 operand 2 is the scratch register.
7676 Define constraints for the reload register and scratch register that contain
7677 a single register class. If the original reload register (whose class is
7678 CLASS) can meet the constraint given in the pattern, the value returned by
7679 these macros is used for the class of the scratch register. Otherwise, two
7680 additional reload registers are required. Their classes are obtained from
7681 the constraints in the insn pattern.
7683 X might be a pseudo-register or a `subreg' of a pseudo-register, which could
7684 either be in a hard register or in memory. Use `true_regnum' to find out;
7685 it will return -1 if the pseudo is in memory and the hard register number if
7686 it is in a register.
7688 These macros should not be used in the case where a particular class of
7689 registers can only be copied to memory and not to another class of
7690 registers. In that case, secondary reload registers are not needed and
7691 would not be helpful. Instead, a stack location must be used to perform the
7692 copy and the `movM' pattern should use memory as an intermediate storage.
7693 This case often occurs between floating-point and general registers. */
7695 enum reg_class
7696 frv_secondary_reload_class (class, mode, x, in_p)
7697 enum reg_class class;
7698 enum machine_mode mode ATTRIBUTE_UNUSED;
7699 rtx x;
7700 int in_p ATTRIBUTE_UNUSED;
7702 enum reg_class ret;
7704 switch (class)
7706 default:
7707 ret = NO_REGS;
7708 break;
7710 /* Accumulators/Accumulator guard registers need to go through floating
7711 point registers. */
7712 case QUAD_REGS:
7713 case EVEN_REGS:
7714 case GPR_REGS:
7715 ret = NO_REGS;
7716 if (x && GET_CODE (x) == REG)
7718 int regno = REGNO (x);
7720 if (ACC_P (regno) || ACCG_P (regno))
7721 ret = FPR_REGS;
7723 break;
7725 /* Nonzero constants should be loaded into an FPR through a GPR. */
7726 case QUAD_FPR_REGS:
7727 case FEVEN_REGS:
7728 case FPR_REGS:
7729 if (x && CONSTANT_P (x) && !ZERO_P (x))
7730 ret = GPR_REGS;
7731 else
7732 ret = NO_REGS;
7733 break;
7735 /* All of these types need gpr registers. */
7736 case ICC_REGS:
7737 case FCC_REGS:
7738 case CC_REGS:
7739 case ICR_REGS:
7740 case FCR_REGS:
7741 case CR_REGS:
7742 case LCR_REG:
7743 case LR_REG:
7744 ret = GPR_REGS;
7745 break;
7747 /* The accumulators need fpr registers */
7748 case ACC_REGS:
7749 case EVEN_ACC_REGS:
7750 case QUAD_ACC_REGS:
7751 case ACCG_REGS:
7752 ret = FPR_REGS;
7753 break;
7756 return ret;
7760 /* A C expression whose value is nonzero if pseudos that have been assigned to
7761 registers of class CLASS would likely be spilled because registers of CLASS
7762 are needed for spill registers.
7764 The default value of this macro returns 1 if CLASS has exactly one register
7765 and zero otherwise. On most machines, this default should be used. Only
7766 define this macro to some other expression if pseudo allocated by
7767 `local-alloc.c' end up in memory because their hard registers were needed
7768 for spill registers. If this macro returns nonzero for those classes, those
7769 pseudos will only be allocated by `global.c', which knows how to reallocate
7770 the pseudo to another register. If there would not be another register
7771 available for reallocation, you should not change the definition of this
7772 macro since the only effect of such a definition would be to slow down
7773 register allocation. */
7776 frv_class_likely_spilled_p (class)
7777 enum reg_class class;
7779 switch (class)
7781 default:
7782 break;
7784 case ICC_REGS:
7785 case FCC_REGS:
7786 case CC_REGS:
7787 case ICR_REGS:
7788 case FCR_REGS:
7789 case CR_REGS:
7790 case LCR_REG:
7791 case LR_REG:
7792 case SPR_REGS:
7793 case QUAD_ACC_REGS:
7794 case EVEN_ACC_REGS:
7795 case ACC_REGS:
7796 case ACCG_REGS:
7797 return TRUE;
7800 return FALSE;
7804 /* An expression for the alignment of a structure field FIELD if the
7805 alignment computed in the usual way is COMPUTED. GNU CC uses this
7806 value instead of the value in `BIGGEST_ALIGNMENT' or
7807 `BIGGEST_FIELD_ALIGNMENT', if defined, for structure fields only. */
7809 /* The definition type of the bit field data is either char, short, long or
7810 long long. The maximum bit size is the number of bits of its own type.
7812 The bit field data is assigned to a storage unit that has an adequate size
7813 for bit field data retention and is located at the smallest address.
7815 Consecutive bit field data are packed at consecutive bits having the same
7816 storage unit, with regard to the type, beginning with the MSB and continuing
7817 toward the LSB.
7819 If a field to be assigned lies over a bit field type boundary, its
7820 assignment is completed by aligning it with a boundary suitable for the
7821 type.
7823 When a bit field having a bit length of 0 is declared, it is forcibly
7824 assigned to the next storage unit.
7826 e.g)
7827 struct {
7828 int a:2;
7829 int b:6;
7830 char c:4;
7831 int d:10;
7832 int :0;
7833 int f:2;
7834 } x;
7836 +0 +1 +2 +3
7837 &x 00000000 00000000 00000000 00000000
7838 MLM----L
7840 &x+4 00000000 00000000 00000000 00000000
7841 M--L
7843 &x+8 00000000 00000000 00000000 00000000
7844 M----------L
7846 &x+12 00000000 00000000 00000000 00000000
7852 frv_adjust_field_align (field, computed)
7853 tree field;
7854 int computed;
7856 /* C++ provides a null DECL_CONTEXT if the bit field is wider than its
7857 type. */
7858 if (DECL_BIT_FIELD (field) && DECL_CONTEXT (field))
7860 tree parent = DECL_CONTEXT (field);
7861 tree prev = NULL_TREE;
7862 tree cur;
7864 /* Loop finding the previous field to the current one */
7865 for (cur = TYPE_FIELDS (parent); cur && cur != field; cur = TREE_CHAIN (cur))
7867 if (TREE_CODE (cur) != FIELD_DECL)
7868 continue;
7870 prev = cur;
7873 if (!cur)
7874 abort ();
7876 /* If this isn't a :0 field and if the previous element is a bitfield
7877 also, see if the type is different, if so, we will need to align the
7878 bit-field to the next boundary */
7879 if (prev
7880 && ! DECL_PACKED (field)
7881 && ! integer_zerop (DECL_SIZE (field))
7882 && DECL_BIT_FIELD_TYPE (field) != DECL_BIT_FIELD_TYPE (prev))
7884 int prev_align = TYPE_ALIGN (TREE_TYPE (prev));
7885 int cur_align = TYPE_ALIGN (TREE_TYPE (field));
7886 computed = (prev_align > cur_align) ? prev_align : cur_align;
7890 return computed;
7894 /* A C expression that is nonzero if it is permissible to store a value of mode
7895 MODE in hard register number REGNO (or in several registers starting with
7896 that one). For a machine where all registers are equivalent, a suitable
7897 definition is
7899 #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
7901 It is not necessary for this macro to check for the numbers of fixed
7902 registers, because the allocation mechanism considers them to be always
7903 occupied.
7905 On some machines, double-precision values must be kept in even/odd register
7906 pairs. The way to implement that is to define this macro to reject odd
7907 register numbers for such modes.
7909 The minimum requirement for a mode to be OK in a register is that the
7910 `movMODE' instruction pattern support moves between the register and any
7911 other hard register for which the mode is OK; and that moving a value into
7912 the register and back out not alter it.
7914 Since the same instruction used to move `SImode' will work for all narrower
7915 integer modes, it is not necessary on any machine for `HARD_REGNO_MODE_OK'
7916 to distinguish between these modes, provided you define patterns `movhi',
7917 etc., to take advantage of this. This is useful because of the interaction
7918 between `HARD_REGNO_MODE_OK' and `MODES_TIEABLE_P'; it is very desirable for
7919 all integer modes to be tieable.
7921 Many machines have special registers for floating point arithmetic. Often
7922 people assume that floating point machine modes are allowed only in floating
7923 point registers. This is not true. Any registers that can hold integers
7924 can safely *hold* a floating point machine mode, whether or not floating
7925 arithmetic can be done on it in those registers. Integer move instructions
7926 can be used to move the values.
7928 On some machines, though, the converse is true: fixed-point machine modes
7929 may not go in floating registers. This is true if the floating registers
7930 normalize any value stored in them, because storing a non-floating value
7931 there would garble it. In this case, `HARD_REGNO_MODE_OK' should reject
7932 fixed-point machine modes in floating registers. But if the floating
7933 registers do not automatically normalize, if you can store any bit pattern
7934 in one and retrieve it unchanged without a trap, then any machine mode may
7935 go in a floating register, so you can define this macro to say so.
7937 The primary significance of special floating registers is rather that they
7938 are the registers acceptable in floating point arithmetic instructions.
7939 However, this is of no concern to `HARD_REGNO_MODE_OK'. You handle it by
7940 writing the proper constraints for those instructions.
7942 On some machines, the floating registers are especially slow to access, so
7943 that it is better to store a value in a stack frame than in such a register
7944 if floating point arithmetic is not being done. As long as the floating
7945 registers are not in class `GENERAL_REGS', they will not be used unless some
7946 pattern's constraint asks for one. */
7949 frv_hard_regno_mode_ok (regno, mode)
7950 int regno;
7951 enum machine_mode mode;
7953 int base;
7954 int mask;
7956 switch (mode)
7958 case CCmode:
7959 case CC_UNSmode:
7960 return ICC_P (regno) || GPR_P (regno);
7962 case CC_CCRmode:
7963 return CR_P (regno) || GPR_P (regno);
7965 case CC_FPmode:
7966 return FCC_P (regno) || GPR_P (regno);
7968 default:
7969 break;
7972 /* Set BASE to the first register in REGNO's class. Set MASK to the
7973 bits that must be clear in (REGNO - BASE) for the register to be
7974 well-aligned. */
7975 if (INTEGRAL_MODE_P (mode) || FLOAT_MODE_P (mode) || VECTOR_MODE_P (mode))
7977 if (ACCG_P (regno))
7979 /* ACCGs store one byte. Two-byte quantities must start in
7980 even-numbered registers, four-byte ones in registers whose
7981 numbers are divisible by four, and so on. */
7982 base = ACCG_FIRST;
7983 mask = GET_MODE_SIZE (mode) - 1;
7985 else
7987 /* The other registers store one word. */
7988 if (GPR_P (regno))
7989 base = GPR_FIRST;
7991 else if (FPR_P (regno))
7992 base = FPR_FIRST;
7994 else if (ACC_P (regno))
7995 base = ACC_FIRST;
7997 else
7998 return 0;
8000 /* Anything smaller than an SI is OK in any word-sized register. */
8001 if (GET_MODE_SIZE (mode) < 4)
8002 return 1;
8004 mask = (GET_MODE_SIZE (mode) / 4) - 1;
8006 return (((regno - base) & mask) == 0);
8009 return 0;
8013 /* A C expression for the number of consecutive hard registers, starting at
8014 register number REGNO, required to hold a value of mode MODE.
8016 On a machine where all registers are exactly one word, a suitable definition
8017 of this macro is
8019 #define HARD_REGNO_NREGS(REGNO, MODE) \
8020 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
8021 / UNITS_PER_WORD)) */
8023 /* On the FRV, make the CC_FP mode take 3 words in the integer registers, so
8024 that we can build the appropriate instructions to properly reload the
8025 values. Also, make the byte-sized accumulator guards use one guard
8026 for each byte. */
8029 frv_hard_regno_nregs (regno, mode)
8030 int regno;
8031 enum machine_mode mode;
8033 if (ACCG_P (regno))
8034 return GET_MODE_SIZE (mode);
8035 else
8036 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
8040 /* A C expression for the maximum number of consecutive registers of
8041 class CLASS needed to hold a value of mode MODE.
8043 This is closely related to the macro `HARD_REGNO_NREGS'. In fact, the value
8044 of the macro `CLASS_MAX_NREGS (CLASS, MODE)' should be the maximum value of
8045 `HARD_REGNO_NREGS (REGNO, MODE)' for all REGNO values in the class CLASS.
8047 This macro helps control the handling of multiple-word values in
8048 the reload pass.
8050 This declaration is required. */
8053 frv_class_max_nregs (class, mode)
8054 enum reg_class class;
8055 enum machine_mode mode;
8057 if (class == ACCG_REGS)
8058 /* An N-byte value requires N accumulator guards. */
8059 return GET_MODE_SIZE (mode);
8060 else
8061 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
8065 /* A C expression that is nonzero if X is a legitimate constant for an
8066 immediate operand on the target machine. You can assume that X satisfies
8067 `CONSTANT_P', so you need not check this. In fact, `1' is a suitable
8068 definition for this macro on machines where anything `CONSTANT_P' is valid. */
8071 frv_legitimate_constant_p (x)
8072 rtx x;
8074 enum machine_mode mode = GET_MODE (x);
8076 /* All of the integer constants are ok */
8077 if (GET_CODE (x) != CONST_DOUBLE)
8078 return TRUE;
8080 /* double integer constants are ok */
8081 if (mode == VOIDmode || mode == DImode)
8082 return TRUE;
8084 /* 0 is always ok */
8085 if (x == CONST0_RTX (mode))
8086 return TRUE;
8088 /* If floating point is just emulated, allow any constant, since it will be
8089 constructed in the GPRs */
8090 if (!TARGET_HAS_FPRS)
8091 return TRUE;
8093 if (mode == DFmode && !TARGET_DOUBLE)
8094 return TRUE;
8096 /* Otherwise store the constant away and do a load. */
8097 return FALSE;
8100 /* A C expression for the cost of moving data from a register in class FROM to
8101 one in class TO. The classes are expressed using the enumeration values
8102 such as `GENERAL_REGS'. A value of 4 is the default; other values are
8103 interpreted relative to that.
8105 It is not required that the cost always equal 2 when FROM is the same as TO;
8106 on some machines it is expensive to move between registers if they are not
8107 general registers.
8109 If reload sees an insn consisting of a single `set' between two hard
8110 registers, and if `REGISTER_MOVE_COST' applied to their classes returns a
8111 value of 2, reload does not check to ensure that the constraints of the insn
8112 are met. Setting a cost of other than 2 will allow reload to verify that
8113 the constraints are met. You should do this if the `movM' pattern's
8114 constraints do not allow such copying. */
8116 #define HIGH_COST 40
8117 #define MEDIUM_COST 3
8118 #define LOW_COST 1
8121 frv_register_move_cost (from, to)
8122 enum reg_class from;
8123 enum reg_class to;
8125 switch (from)
8127 default:
8128 break;
8130 case QUAD_REGS:
8131 case EVEN_REGS:
8132 case GPR_REGS:
8133 switch (to)
8135 default:
8136 break;
8138 case QUAD_REGS:
8139 case EVEN_REGS:
8140 case GPR_REGS:
8141 return LOW_COST;
8143 case FEVEN_REGS:
8144 case FPR_REGS:
8145 return LOW_COST;
8147 case LCR_REG:
8148 case LR_REG:
8149 case SPR_REGS:
8150 return LOW_COST;
8153 case FEVEN_REGS:
8154 case FPR_REGS:
8155 switch (to)
8157 default:
8158 break;
8160 case QUAD_REGS:
8161 case EVEN_REGS:
8162 case GPR_REGS:
8163 case ACC_REGS:
8164 case EVEN_ACC_REGS:
8165 case QUAD_ACC_REGS:
8166 case ACCG_REGS:
8167 return MEDIUM_COST;
8169 case FEVEN_REGS:
8170 case FPR_REGS:
8171 return LOW_COST;
8174 case LCR_REG:
8175 case LR_REG:
8176 case SPR_REGS:
8177 switch (to)
8179 default:
8180 break;
8182 case QUAD_REGS:
8183 case EVEN_REGS:
8184 case GPR_REGS:
8185 return MEDIUM_COST;
8188 case ACC_REGS:
8189 case EVEN_ACC_REGS:
8190 case QUAD_ACC_REGS:
8191 case ACCG_REGS:
8192 switch (to)
8194 default:
8195 break;
8197 case FEVEN_REGS:
8198 case FPR_REGS:
8199 return MEDIUM_COST;
8204 return HIGH_COST;
8207 /* Implementation of TARGET_ASM_INTEGER. In the FRV case we need to
8208 use ".picptr" to generate safe relocations for PIC code. We also
8209 need a fixup entry for aligned (non-debugging) code. */
8211 static bool
8212 frv_assemble_integer (value, size, aligned_p)
8213 rtx value;
8214 unsigned int size;
8215 int aligned_p;
8217 if (flag_pic && size == UNITS_PER_WORD)
8219 if (GET_CODE (value) == CONST
8220 || GET_CODE (value) == SYMBOL_REF
8221 || GET_CODE (value) == LABEL_REF)
8223 if (aligned_p)
8225 static int label_num = 0;
8226 char buf[256];
8227 const char *p;
8229 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", label_num++);
8230 p = (* targetm.strip_name_encoding) (buf);
8232 fprintf (asm_out_file, "%s:\n", p);
8233 fprintf (asm_out_file, "%s\n", FIXUP_SECTION_ASM_OP);
8234 fprintf (asm_out_file, "\t.picptr\t%s\n", p);
8235 fprintf (asm_out_file, "\t.previous\n");
8237 assemble_integer_with_op ("\t.picptr\t", value);
8238 return true;
8240 if (!aligned_p)
8242 /* We've set the unaligned SI op to NULL, so we always have to
8243 handle the unaligned case here. */
8244 assemble_integer_with_op ("\t.4byte\t", value);
8245 return true;
8248 return default_assemble_integer (value, size, aligned_p);
8251 /* Function to set up the backend function structure. */
8253 static struct machine_function *
8254 frv_init_machine_status ()
8256 return ggc_alloc_cleared (sizeof (struct machine_function));
8260 /* Update the register state information, to know about which registers are set
8261 or clobbered. */
8263 static void
8264 frv_registers_update (x, reg_state, modified, p_num_mod, flag)
8265 rtx x;
8266 unsigned char reg_state[];
8267 int modified[];
8268 int *p_num_mod;
8269 int flag;
8271 int regno, reg_max;
8272 rtx reg;
8273 rtx cond;
8274 const char *format;
8275 int length;
8276 int j;
8278 switch (GET_CODE (x))
8280 default:
8281 break;
8283 /* Clobber just modifies a register, it doesn't make it live. */
8284 case CLOBBER:
8285 frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod,
8286 flag | REGSTATE_MODIFIED);
8287 return;
8289 /* Pre modify updates the first argument, just references the second. */
8290 case PRE_MODIFY:
8291 case SET:
8292 frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod,
8293 flag | REGSTATE_MODIFIED | REGSTATE_LIVE);
8294 frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod, flag);
8295 return;
8297 /* For COND_EXEC, pass the appropriate flag to evaluate the conditional
8298 statement, but just to be sure, make sure it is the type of cond_exec
8299 we expect. */
8300 case COND_EXEC:
8301 cond = XEXP (x, 0);
8302 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8303 && GET_CODE (XEXP (cond, 0)) == REG
8304 && CR_P (REGNO (XEXP (cond, 0)))
8305 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8306 && INTVAL (XEXP (cond, 1)) == 0
8307 && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0)
8309 frv_registers_update (cond, reg_state, modified, p_num_mod, flag);
8310 flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST)
8311 | ((GET_CODE (cond) == NE)
8312 ? REGSTATE_IF_TRUE
8313 : REGSTATE_IF_FALSE));
8315 frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod,
8316 flag);
8317 return;
8319 else
8320 fatal_insn ("frv_registers_update", x);
8322 /* MEM resets the modification bits. */
8323 case MEM:
8324 flag &= ~REGSTATE_MODIFIED;
8325 break;
8327 /* See if we need to set the modified flag. */
8328 case SUBREG:
8329 reg = SUBREG_REG (x);
8330 if (GET_CODE (reg) == REG)
8332 regno = subreg_regno (x);
8333 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8334 goto reg_common;
8336 break;
8338 case REG:
8339 regno = REGNO (x);
8340 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8341 /* fall through */
8343 reg_common:
8344 if (flag & REGSTATE_MODIFIED)
8346 flag &= REGSTATE_MASK;
8347 while (regno < reg_max)
8349 int rs = reg_state[regno];
8351 if (flag != rs)
8353 if ((rs & REGSTATE_MODIFIED) == 0)
8355 modified[ *p_num_mod ] = regno;
8356 (*p_num_mod)++;
8359 /* If the previous register state had the register as
8360 modified, possibly in some conditional execution context,
8361 and the current insn modifies in some other context, or
8362 outside of conditional execution, just mark the variable
8363 as modified. */
8364 else
8365 flag &= ~(REGSTATE_IF_EITHER | REGSTATE_CC_MASK);
8367 reg_state[regno] = (rs | flag);
8369 regno++;
8372 return;
8376 length = GET_RTX_LENGTH (GET_CODE (x));
8377 format = GET_RTX_FORMAT (GET_CODE (x));
8379 for (j = 0; j < length; ++j)
8381 switch (format[j])
8383 case 'e':
8384 frv_registers_update (XEXP (x, j), reg_state, modified, p_num_mod,
8385 flag);
8386 break;
8388 case 'V':
8389 case 'E':
8390 if (XVEC (x, j) != 0)
8392 int k;
8393 for (k = 0; k < XVECLEN (x, j); ++k)
8394 frv_registers_update (XVECEXP (x, j, k), reg_state, modified,
8395 p_num_mod, flag);
8397 break;
8399 default:
8400 /* Nothing to do. */
8401 break;
8405 return;
8409 /* Return if any registers in a hard register set were used an insn. */
8411 static int
8412 frv_registers_used_p (x, reg_state, flag)
8413 rtx x;
8414 unsigned char reg_state[];
8415 int flag;
8417 int regno, reg_max;
8418 rtx reg;
8419 rtx cond;
8420 rtx dest;
8421 const char *format;
8422 int result;
8423 int length;
8424 int j;
8426 switch (GET_CODE (x))
8428 default:
8429 break;
8431 /* Skip clobber, that doesn't use the previous value */
8432 case CLOBBER:
8433 return FALSE;
8435 /* For SET, if a conditional jump has occurred in the same insn, only
8436 allow a set of a CR register if that register is not currently live.
8437 This is because on the FR-V, B0/B1 instructions are always last.
8438 Otherwise, don't look at the result, except within a MEM, but do look
8439 at the source. */
8440 case SET:
8441 dest = SET_DEST (x);
8442 if (flag & REGSTATE_CONDJUMP
8443 && GET_CODE (dest) == REG && CR_P (REGNO (dest))
8444 && (reg_state[ REGNO (dest) ] & REGSTATE_LIVE) != 0)
8445 return TRUE;
8447 if (GET_CODE (dest) == MEM)
8449 result = frv_registers_used_p (XEXP (dest, 0), reg_state, flag);
8450 if (result)
8451 return result;
8454 return frv_registers_used_p (SET_SRC (x), reg_state, flag);
8456 /* For COND_EXEC, pass the appropriate flag to evaluate the conditional
8457 statement, but just to be sure, make sure it is the type of cond_exec
8458 we expect. */
8459 case COND_EXEC:
8460 cond = XEXP (x, 0);
8461 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8462 && GET_CODE (XEXP (cond, 0)) == REG
8463 && CR_P (REGNO (XEXP (cond, 0)))
8464 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8465 && INTVAL (XEXP (cond, 1)) == 0
8466 && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0)
8468 result = frv_registers_used_p (cond, reg_state, flag);
8469 if (result)
8470 return result;
8472 flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST)
8473 | ((GET_CODE (cond) == NE)
8474 ? REGSTATE_IF_TRUE
8475 : REGSTATE_IF_FALSE));
8477 return frv_registers_used_p (XEXP (x, 1), reg_state, flag);
8479 else
8480 fatal_insn ("frv_registers_used_p", x);
8482 /* See if a register or subreg was modified in the same VLIW insn. */
8483 case SUBREG:
8484 reg = SUBREG_REG (x);
8485 if (GET_CODE (reg) == REG)
8487 regno = subreg_regno (x);
8488 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8489 goto reg_common;
8491 break;
8493 case REG:
8494 regno = REGNO (x);
8495 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8496 /* fall through */
8498 reg_common:
8499 while (regno < reg_max)
8501 int rs = reg_state[regno];
8503 if (rs & REGSTATE_MODIFIED)
8505 int rs_if = rs & REGSTATE_IF_EITHER;
8506 int flag_if = flag & REGSTATE_IF_EITHER;
8508 /* Simple modification, no conditional execution */
8509 if ((rs & REGSTATE_IF_EITHER) == 0)
8510 return TRUE;
8512 /* See if the variable is only modified in a conditional
8513 execution expression opposite to the conditional execution
8514 expression that governs this expression (ie, true vs. false
8515 for the same CC register). If this isn't two halves of the
8516 same conditional expression, consider the register
8517 modified. */
8518 if (((rs_if == REGSTATE_IF_TRUE && flag_if == REGSTATE_IF_FALSE)
8519 || (rs_if == REGSTATE_IF_FALSE && flag_if == REGSTATE_IF_TRUE))
8520 && ((rs & REGSTATE_CC_MASK) == (flag & REGSTATE_CC_MASK)))
8522 else
8523 return TRUE;
8526 regno++;
8528 return FALSE;
8532 length = GET_RTX_LENGTH (GET_CODE (x));
8533 format = GET_RTX_FORMAT (GET_CODE (x));
8535 for (j = 0; j < length; ++j)
8537 switch (format[j])
8539 case 'e':
8540 result = frv_registers_used_p (XEXP (x, j), reg_state, flag);
8541 if (result != 0)
8542 return result;
8543 break;
8545 case 'V':
8546 case 'E':
8547 if (XVEC (x, j) != 0)
8549 int k;
8550 for (k = 0; k < XVECLEN (x, j); ++k)
8552 result = frv_registers_used_p (XVECEXP (x, j, k), reg_state,
8553 flag);
8554 if (result != 0)
8555 return result;
8558 break;
8560 default:
8561 /* Nothing to do. */
8562 break;
8566 return 0;
8569 /* Return if any registers in a hard register set were set in an insn. */
8571 static int
8572 frv_registers_set_p (x, reg_state, modify_p)
8573 rtx x;
8574 unsigned char reg_state[];
8575 int modify_p;
8577 int regno, reg_max;
8578 rtx reg;
8579 rtx cond;
8580 const char *format;
8581 int length;
8582 int j;
8584 switch (GET_CODE (x))
8586 default:
8587 break;
8589 case CLOBBER:
8590 return frv_registers_set_p (XEXP (x, 0), reg_state, TRUE);
8592 case PRE_MODIFY:
8593 case SET:
8594 return (frv_registers_set_p (XEXP (x, 0), reg_state, TRUE)
8595 || frv_registers_set_p (XEXP (x, 1), reg_state, FALSE));
8597 case COND_EXEC:
8598 cond = XEXP (x, 0);
8599 /* just to be sure, make sure it is the type of cond_exec we
8600 expect. */
8601 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8602 && GET_CODE (XEXP (cond, 0)) == REG
8603 && CR_P (REGNO (XEXP (cond, 0)))
8604 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8605 && INTVAL (XEXP (cond, 1)) == 0
8606 && !modify_p)
8607 return frv_registers_set_p (XEXP (x, 1), reg_state, modify_p);
8608 else
8609 fatal_insn ("frv_registers_set_p", x);
8611 /* MEM resets the modification bits. */
8612 case MEM:
8613 modify_p = FALSE;
8614 break;
8616 /* See if we need to set the modified modify_p. */
8617 case SUBREG:
8618 reg = SUBREG_REG (x);
8619 if (GET_CODE (reg) == REG)
8621 regno = subreg_regno (x);
8622 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8623 goto reg_common;
8625 break;
8627 case REG:
8628 regno = REGNO (x);
8629 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8630 /* fall through */
8632 reg_common:
8633 if (modify_p)
8634 while (regno < reg_max)
8636 int rs = reg_state[regno];
8638 if (rs & REGSTATE_MODIFIED)
8639 return TRUE;
8640 regno++;
8642 return FALSE;
8646 length = GET_RTX_LENGTH (GET_CODE (x));
8647 format = GET_RTX_FORMAT (GET_CODE (x));
8649 for (j = 0; j < length; ++j)
8651 switch (format[j])
8653 case 'e':
8654 if (frv_registers_set_p (XEXP (x, j), reg_state, modify_p))
8655 return TRUE;
8656 break;
8658 case 'V':
8659 case 'E':
8660 if (XVEC (x, j) != 0)
8662 int k;
8663 for (k = 0; k < XVECLEN (x, j); ++k)
8664 if (frv_registers_set_p (XVECEXP (x, j, k), reg_state,
8665 modify_p))
8666 return TRUE;
8668 break;
8670 default:
8671 /* Nothing to do. */
8672 break;
8676 return FALSE;
8680 /* In rare cases, correct code generation requires extra machine dependent
8681 processing between the second jump optimization pass and delayed branch
8682 scheduling. On those machines, define this macro as a C statement to act on
8683 the code starting at INSN. */
8685 /* On the FR-V, this pass is used to rescan the insn chain, and pack
8686 conditional branches/calls/jumps, etc. with previous insns where it can. It
8687 does not reorder the instructions. We assume the scheduler left the flow
8688 information in a reasonable state. */
8690 static void
8691 frv_pack_insns ()
8693 state_t frv_state; /* frv state machine */
8694 int cur_start_vliw_p; /* current insn starts a VLIW insn */
8695 int next_start_vliw_p; /* next insn starts a VLIW insn */
8696 int cur_condjump_p; /* flag if current insn is a cond jump*/
8697 int next_condjump_p; /* flag if next insn is a cond jump */
8698 rtx insn;
8699 rtx link;
8700 int j;
8701 int num_mod = 0; /* # of modified registers */
8702 int modified[FIRST_PSEUDO_REGISTER]; /* registers modified in current VLIW */
8703 /* register state information */
8704 unsigned char reg_state[FIRST_PSEUDO_REGISTER];
8706 /* If we weren't going to pack the insns, don't bother with this pass. */
8707 if (!optimize || !flag_schedule_insns_after_reload || TARGET_NO_VLIW_BRANCH)
8708 return;
8710 switch (frv_cpu_type)
8712 default:
8713 case FRV_CPU_FR300: /* FR300/simple are single issue */
8714 case FRV_CPU_SIMPLE:
8715 return;
8717 case FRV_CPU_GENERIC: /* FR-V and FR500 are multi-issue */
8718 case FRV_CPU_FR400:
8719 case FRV_CPU_FR500:
8720 case FRV_CPU_TOMCAT:
8721 break;
8724 /* Set up the instruction and register states. */
8725 dfa_start ();
8726 frv_state = (state_t) xmalloc (state_size ());
8727 memset ((PTR) reg_state, REGSTATE_DEAD, sizeof (reg_state));
8729 /* Go through the insns, and repack the insns. */
8730 state_reset (frv_state);
8731 cur_start_vliw_p = FALSE;
8732 next_start_vliw_p = TRUE;
8733 cur_condjump_p = 0;
8734 next_condjump_p = 0;
8736 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
8738 enum rtx_code code = GET_CODE (insn);
8739 enum rtx_code pattern_code;
8741 /* For basic block begin notes redo the live information, and skip other
8742 notes. */
8743 if (code == NOTE)
8745 if (NOTE_LINE_NUMBER (insn) == (int)NOTE_INSN_BASIC_BLOCK)
8747 regset live;
8749 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
8750 reg_state[j] &= ~ REGSTATE_LIVE;
8752 live = NOTE_BASIC_BLOCK (insn)->global_live_at_start;
8753 EXECUTE_IF_SET_IN_REG_SET(live, 0, j,
8755 reg_state[j] |= REGSTATE_LIVE;
8759 continue;
8762 /* things like labels reset everything. */
8763 if (GET_RTX_CLASS (code) != 'i')
8765 next_start_vliw_p = TRUE;
8766 continue;
8769 /* Clear the VLIW start flag on random USE and CLOBBER insns, which is
8770 set on the USE insn that preceeds the return, and potentially on
8771 CLOBBERs for setting multiword variables. Also skip the ADDR_VEC
8772 holding the case table labels. */
8773 pattern_code = GET_CODE (PATTERN (insn));
8774 if (pattern_code == USE || pattern_code == CLOBBER
8775 || pattern_code == ADDR_VEC || pattern_code == ADDR_DIFF_VEC)
8777 CLEAR_VLIW_START (insn);
8778 continue;
8781 cur_start_vliw_p = next_start_vliw_p;
8782 next_start_vliw_p = FALSE;
8784 cur_condjump_p |= next_condjump_p;
8785 next_condjump_p = 0;
8787 /* Unconditional branches and calls end the current VLIW insn. */
8788 if (code == CALL_INSN)
8790 next_start_vliw_p = TRUE;
8792 /* On a TOMCAT, calls must be alone in the VLIW insns. */
8793 if (frv_cpu_type == FRV_CPU_TOMCAT)
8794 cur_start_vliw_p = TRUE;
8796 else if (code == JUMP_INSN)
8798 if (any_condjump_p (insn))
8799 next_condjump_p = REGSTATE_CONDJUMP;
8800 else
8801 next_start_vliw_p = TRUE;
8804 /* Only allow setting a CCR register after a conditional branch. */
8805 else if (((cur_condjump_p & REGSTATE_CONDJUMP) != 0)
8806 && get_attr_type (insn) != TYPE_CCR)
8807 cur_start_vliw_p = TRUE;
8809 /* Determine if we need to start a new VLIW instruction. */
8810 if (cur_start_vliw_p
8811 /* Do not check for register conflicts in a setlo instruction
8812 because any output or true dependencies will be with the
8813 partnering sethi instruction, with which it can be packed.
8815 Although output dependencies are rare they are still
8816 possible. So check output dependencies in VLIW insn. */
8817 || (get_attr_type (insn) != TYPE_SETLO
8818 && (frv_registers_used_p (PATTERN (insn),
8819 reg_state,
8820 cur_condjump_p)
8821 || frv_registers_set_p (PATTERN (insn), reg_state, FALSE)))
8822 || state_transition (frv_state, insn) >= 0)
8824 SET_VLIW_START (insn);
8825 state_reset (frv_state);
8826 state_transition (frv_state, insn);
8827 cur_condjump_p = 0;
8829 /* Update the modified registers. */
8830 for (j = 0; j < num_mod; j++)
8831 reg_state[ modified[j] ] &= ~(REGSTATE_CC_MASK
8832 | REGSTATE_IF_EITHER
8833 | REGSTATE_MODIFIED);
8835 num_mod = 0;
8837 else
8838 CLEAR_VLIW_START (insn);
8840 /* Record which registers are modified. */
8841 frv_registers_update (PATTERN (insn), reg_state, modified, &num_mod, 0);
8843 /* Process the death notices */
8844 for (link = REG_NOTES (insn);
8845 link != NULL_RTX;
8846 link = XEXP (link, 1))
8848 rtx reg = XEXP (link, 0);
8850 if (REG_NOTE_KIND (link) == REG_DEAD && GET_CODE (reg) == REG)
8852 int regno = REGNO (reg);
8853 int n = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8854 for (; regno < n; regno++)
8855 reg_state[regno] &= ~REGSTATE_LIVE;
8860 free ((PTR) frv_state);
8861 dfa_finish ();
8862 return;
8866 #define def_builtin(name, type, code) \
8867 builtin_function ((name), (type), (code), BUILT_IN_MD, NULL, NULL)
8869 struct builtin_description
8871 enum insn_code icode;
8872 const char *name;
8873 enum frv_builtins code;
8874 enum rtx_code comparison;
8875 unsigned int flag;
8878 /* Media intrinsics that take a single, constant argument. */
8880 static struct builtin_description bdesc_set[] =
8882 { CODE_FOR_mhdsets, "__MHDSETS", FRV_BUILTIN_MHDSETS, 0, 0 }
8885 /* Media intrinsics that take just one argument. */
8887 static struct builtin_description bdesc_1arg[] =
8889 { CODE_FOR_mnot, "__MNOT", FRV_BUILTIN_MNOT, 0, 0 },
8890 { CODE_FOR_munpackh, "__MUNPACKH", FRV_BUILTIN_MUNPACKH, 0, 0 },
8891 { CODE_FOR_mbtoh, "__MBTOH", FRV_BUILTIN_MBTOH, 0, 0 },
8892 { CODE_FOR_mhtob, "__MHTOB", FRV_BUILTIN_MHTOB, 0, 0 },
8893 { CODE_FOR_mabshs, "__MABSHS", FRV_BUILTIN_MABSHS, 0, 0 }
8896 /* Media intrinsics that take two arguments. */
8898 static struct builtin_description bdesc_2arg[] =
8900 { CODE_FOR_mand, "__MAND", FRV_BUILTIN_MAND, 0, 0 },
8901 { CODE_FOR_mor, "__MOR", FRV_BUILTIN_MOR, 0, 0 },
8902 { CODE_FOR_mxor, "__MXOR", FRV_BUILTIN_MXOR, 0, 0 },
8903 { CODE_FOR_maveh, "__MAVEH", FRV_BUILTIN_MAVEH, 0, 0 },
8904 { CODE_FOR_msaths, "__MSATHS", FRV_BUILTIN_MSATHS, 0, 0 },
8905 { CODE_FOR_msathu, "__MSATHU", FRV_BUILTIN_MSATHU, 0, 0 },
8906 { CODE_FOR_maddhss, "__MADDHSS", FRV_BUILTIN_MADDHSS, 0, 0 },
8907 { CODE_FOR_maddhus, "__MADDHUS", FRV_BUILTIN_MADDHUS, 0, 0 },
8908 { CODE_FOR_msubhss, "__MSUBHSS", FRV_BUILTIN_MSUBHSS, 0, 0 },
8909 { CODE_FOR_msubhus, "__MSUBHUS", FRV_BUILTIN_MSUBHUS, 0, 0 },
8910 { CODE_FOR_mqaddhss, "__MQADDHSS", FRV_BUILTIN_MQADDHSS, 0, 0 },
8911 { CODE_FOR_mqaddhus, "__MQADDHUS", FRV_BUILTIN_MQADDHUS, 0, 0 },
8912 { CODE_FOR_mqsubhss, "__MQSUBHSS", FRV_BUILTIN_MQSUBHSS, 0, 0 },
8913 { CODE_FOR_mqsubhus, "__MQSUBHUS", FRV_BUILTIN_MQSUBHUS, 0, 0 },
8914 { CODE_FOR_mpackh, "__MPACKH", FRV_BUILTIN_MPACKH, 0, 0 },
8915 { CODE_FOR_mdpackh, "__MDPACKH", FRV_BUILTIN_MDPACKH, 0, 0 },
8916 { CODE_FOR_mcop1, "__Mcop1", FRV_BUILTIN_MCOP1, 0, 0 },
8917 { CODE_FOR_mcop2, "__Mcop2", FRV_BUILTIN_MCOP2, 0, 0 },
8918 { CODE_FOR_mwcut, "__MWCUT", FRV_BUILTIN_MWCUT, 0, 0 },
8919 { CODE_FOR_mqsaths, "__MQSATHS", FRV_BUILTIN_MQSATHS, 0, 0 }
8922 /* Media intrinsics that take two arguments, the first being an ACC number. */
8924 static struct builtin_description bdesc_cut[] =
8926 { CODE_FOR_mcut, "__MCUT", FRV_BUILTIN_MCUT, 0, 0 },
8927 { CODE_FOR_mcutss, "__MCUTSS", FRV_BUILTIN_MCUTSS, 0, 0 },
8928 { CODE_FOR_mdcutssi, "__MDCUTSSI", FRV_BUILTIN_MDCUTSSI, 0, 0 }
8931 /* Two-argument media intrinsics with an immediate second argument. */
8933 static struct builtin_description bdesc_2argimm[] =
8935 { CODE_FOR_mrotli, "__MROTLI", FRV_BUILTIN_MROTLI, 0, 0 },
8936 { CODE_FOR_mrotri, "__MROTRI", FRV_BUILTIN_MROTRI, 0, 0 },
8937 { CODE_FOR_msllhi, "__MSLLHI", FRV_BUILTIN_MSLLHI, 0, 0 },
8938 { CODE_FOR_msrlhi, "__MSRLHI", FRV_BUILTIN_MSRLHI, 0, 0 },
8939 { CODE_FOR_msrahi, "__MSRAHI", FRV_BUILTIN_MSRAHI, 0, 0 },
8940 { CODE_FOR_mexpdhw, "__MEXPDHW", FRV_BUILTIN_MEXPDHW, 0, 0 },
8941 { CODE_FOR_mexpdhd, "__MEXPDHD", FRV_BUILTIN_MEXPDHD, 0, 0 },
8942 { CODE_FOR_mdrotli, "__MDROTLI", FRV_BUILTIN_MDROTLI, 0, 0 },
8943 { CODE_FOR_mcplhi, "__MCPLHI", FRV_BUILTIN_MCPLHI, 0, 0 },
8944 { CODE_FOR_mcpli, "__MCPLI", FRV_BUILTIN_MCPLI, 0, 0 },
8945 { CODE_FOR_mhsetlos, "__MHSETLOS", FRV_BUILTIN_MHSETLOS, 0, 0 },
8946 { CODE_FOR_mhsetloh, "__MHSETLOH", FRV_BUILTIN_MHSETLOH, 0, 0 },
8947 { CODE_FOR_mhsethis, "__MHSETHIS", FRV_BUILTIN_MHSETHIS, 0, 0 },
8948 { CODE_FOR_mhsethih, "__MHSETHIH", FRV_BUILTIN_MHSETHIH, 0, 0 },
8949 { CODE_FOR_mhdseth, "__MHDSETH", FRV_BUILTIN_MHDSETH, 0, 0 }
8952 /* Media intrinsics that take two arguments and return void, the first argument
8953 being a pointer to 4 words in memory. */
8955 static struct builtin_description bdesc_void2arg[] =
8957 { CODE_FOR_mdunpackh, "__MDUNPACKH", FRV_BUILTIN_MDUNPACKH, 0, 0 },
8958 { CODE_FOR_mbtohe, "__MBTOHE", FRV_BUILTIN_MBTOHE, 0, 0 },
8961 /* Media intrinsics that take three arguments, the first being a const_int that
8962 denotes an accumulator, and that return void. */
8964 static struct builtin_description bdesc_void3arg[] =
8966 { CODE_FOR_mcpxrs, "__MCPXRS", FRV_BUILTIN_MCPXRS, 0, 0 },
8967 { CODE_FOR_mcpxru, "__MCPXRU", FRV_BUILTIN_MCPXRU, 0, 0 },
8968 { CODE_FOR_mcpxis, "__MCPXIS", FRV_BUILTIN_MCPXIS, 0, 0 },
8969 { CODE_FOR_mcpxiu, "__MCPXIU", FRV_BUILTIN_MCPXIU, 0, 0 },
8970 { CODE_FOR_mmulhs, "__MMULHS", FRV_BUILTIN_MMULHS, 0, 0 },
8971 { CODE_FOR_mmulhu, "__MMULHU", FRV_BUILTIN_MMULHU, 0, 0 },
8972 { CODE_FOR_mmulxhs, "__MMULXHS", FRV_BUILTIN_MMULXHS, 0, 0 },
8973 { CODE_FOR_mmulxhu, "__MMULXHU", FRV_BUILTIN_MMULXHU, 0, 0 },
8974 { CODE_FOR_mmachs, "__MMACHS", FRV_BUILTIN_MMACHS, 0, 0 },
8975 { CODE_FOR_mmachu, "__MMACHU", FRV_BUILTIN_MMACHU, 0, 0 },
8976 { CODE_FOR_mmrdhs, "__MMRDHS", FRV_BUILTIN_MMRDHS, 0, 0 },
8977 { CODE_FOR_mmrdhu, "__MMRDHU", FRV_BUILTIN_MMRDHU, 0, 0 },
8978 { CODE_FOR_mqcpxrs, "__MQCPXRS", FRV_BUILTIN_MQCPXRS, 0, 0 },
8979 { CODE_FOR_mqcpxru, "__MQCPXRU", FRV_BUILTIN_MQCPXRU, 0, 0 },
8980 { CODE_FOR_mqcpxis, "__MQCPXIS", FRV_BUILTIN_MQCPXIS, 0, 0 },
8981 { CODE_FOR_mqcpxiu, "__MQCPXIU", FRV_BUILTIN_MQCPXIU, 0, 0 },
8982 { CODE_FOR_mqmulhs, "__MQMULHS", FRV_BUILTIN_MQMULHS, 0, 0 },
8983 { CODE_FOR_mqmulhu, "__MQMULHU", FRV_BUILTIN_MQMULHU, 0, 0 },
8984 { CODE_FOR_mqmulxhs, "__MQMULXHS", FRV_BUILTIN_MQMULXHS, 0, 0 },
8985 { CODE_FOR_mqmulxhu, "__MQMULXHU", FRV_BUILTIN_MQMULXHU, 0, 0 },
8986 { CODE_FOR_mqmachs, "__MQMACHS", FRV_BUILTIN_MQMACHS, 0, 0 },
8987 { CODE_FOR_mqmachu, "__MQMACHU", FRV_BUILTIN_MQMACHU, 0, 0 },
8988 { CODE_FOR_mqxmachs, "__MQXMACHS", FRV_BUILTIN_MQXMACHS, 0, 0 },
8989 { CODE_FOR_mqxmacxhs, "__MQXMACXHS", FRV_BUILTIN_MQXMACXHS, 0, 0 },
8990 { CODE_FOR_mqmacxhs, "__MQMACXHS", FRV_BUILTIN_MQMACXHS, 0, 0 }
8993 /* Media intrinsics that take two accumulator numbers as argument and
8994 return void. */
8996 static struct builtin_description bdesc_voidacc[] =
8998 { CODE_FOR_maddaccs, "__MADDACCS", FRV_BUILTIN_MADDACCS, 0, 0 },
8999 { CODE_FOR_msubaccs, "__MSUBACCS", FRV_BUILTIN_MSUBACCS, 0, 0 },
9000 { CODE_FOR_masaccs, "__MASACCS", FRV_BUILTIN_MASACCS, 0, 0 },
9001 { CODE_FOR_mdaddaccs, "__MDADDACCS", FRV_BUILTIN_MDADDACCS, 0, 0 },
9002 { CODE_FOR_mdsubaccs, "__MDSUBACCS", FRV_BUILTIN_MDSUBACCS, 0, 0 },
9003 { CODE_FOR_mdasaccs, "__MDASACCS", FRV_BUILTIN_MDASACCS, 0, 0 }
9006 /* Initialize media builtins. */
9008 static void
9009 frv_init_builtins ()
9011 tree endlink = void_list_node;
9012 tree accumulator = integer_type_node;
9013 tree integer = integer_type_node;
9014 tree voidt = void_type_node;
9015 tree uhalf = short_unsigned_type_node;
9016 tree sword1 = long_integer_type_node;
9017 tree uword1 = long_unsigned_type_node;
9018 tree sword2 = long_long_integer_type_node;
9019 tree uword2 = long_long_unsigned_type_node;
9020 tree uword4 = build_pointer_type (uword1);
9022 #define UNARY(RET, T1) \
9023 build_function_type (RET, tree_cons (NULL_TREE, T1, endlink))
9025 #define BINARY(RET, T1, T2) \
9026 build_function_type (RET, tree_cons (NULL_TREE, T1, \
9027 tree_cons (NULL_TREE, T2, endlink)))
9029 #define TRINARY(RET, T1, T2, T3) \
9030 build_function_type (RET, tree_cons (NULL_TREE, T1, \
9031 tree_cons (NULL_TREE, T2, \
9032 tree_cons (NULL_TREE, T3, endlink))))
9034 tree void_ftype_void = build_function_type (voidt, endlink);
9036 tree void_ftype_acc = UNARY (voidt, accumulator);
9037 tree void_ftype_uw4_uw1 = BINARY (voidt, uword4, uword1);
9038 tree void_ftype_uw4_uw2 = BINARY (voidt, uword4, uword2);
9039 tree void_ftype_acc_uw1 = BINARY (voidt, accumulator, uword1);
9040 tree void_ftype_acc_acc = BINARY (voidt, accumulator, accumulator);
9041 tree void_ftype_acc_uw1_uw1 = TRINARY (voidt, accumulator, uword1, uword1);
9042 tree void_ftype_acc_sw1_sw1 = TRINARY (voidt, accumulator, sword1, sword1);
9043 tree void_ftype_acc_uw2_uw2 = TRINARY (voidt, accumulator, uword2, uword2);
9044 tree void_ftype_acc_sw2_sw2 = TRINARY (voidt, accumulator, sword2, sword2);
9046 tree uw1_ftype_uw1 = UNARY (uword1, uword1);
9047 tree uw1_ftype_sw1 = UNARY (uword1, sword1);
9048 tree uw1_ftype_uw2 = UNARY (uword1, uword2);
9049 tree uw1_ftype_acc = UNARY (uword1, accumulator);
9050 tree uw1_ftype_uh_uh = BINARY (uword1, uhalf, uhalf);
9051 tree uw1_ftype_uw1_uw1 = BINARY (uword1, uword1, uword1);
9052 tree uw1_ftype_uw1_int = BINARY (uword1, uword1, integer);
9053 tree uw1_ftype_acc_uw1 = BINARY (uword1, accumulator, uword1);
9054 tree uw1_ftype_acc_sw1 = BINARY (uword1, accumulator, sword1);
9055 tree uw1_ftype_uw2_uw1 = BINARY (uword1, uword2, uword1);
9056 tree uw1_ftype_uw2_int = BINARY (uword1, uword2, integer);
9058 tree sw1_ftype_int = UNARY (sword1, integer);
9059 tree sw1_ftype_sw1_sw1 = BINARY (sword1, sword1, sword1);
9060 tree sw1_ftype_sw1_int = BINARY (sword1, sword1, integer);
9062 tree uw2_ftype_uw1 = UNARY (uword2, uword1);
9063 tree uw2_ftype_uw1_int = BINARY (uword2, uword1, integer);
9064 tree uw2_ftype_uw2_uw2 = BINARY (uword2, uword2, uword2);
9065 tree uw2_ftype_uw2_int = BINARY (uword2, uword2, integer);
9066 tree uw2_ftype_acc_int = BINARY (uword2, accumulator, integer);
9068 tree sw2_ftype_sw2_sw2 = BINARY (sword2, sword2, sword2);
9070 def_builtin ("__MAND", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAND);
9071 def_builtin ("__MOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MOR);
9072 def_builtin ("__MXOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MXOR);
9073 def_builtin ("__MNOT", uw1_ftype_uw1, FRV_BUILTIN_MNOT);
9074 def_builtin ("__MROTLI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTLI);
9075 def_builtin ("__MROTRI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTRI);
9076 def_builtin ("__MWCUT", uw1_ftype_uw2_uw1, FRV_BUILTIN_MWCUT);
9077 def_builtin ("__MAVEH", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAVEH);
9078 def_builtin ("__MSLLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSLLHI);
9079 def_builtin ("__MSRLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSRLHI);
9080 def_builtin ("__MSRAHI", sw1_ftype_sw1_int, FRV_BUILTIN_MSRAHI);
9081 def_builtin ("__MSATHS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSATHS);
9082 def_builtin ("__MSATHU", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSATHU);
9083 def_builtin ("__MADDHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MADDHSS);
9084 def_builtin ("__MADDHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MADDHUS);
9085 def_builtin ("__MSUBHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSUBHSS);
9086 def_builtin ("__MSUBHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSUBHUS);
9087 def_builtin ("__MMULHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULHS);
9088 def_builtin ("__MMULHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULHU);
9089 def_builtin ("__MMULXHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULXHS);
9090 def_builtin ("__MMULXHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULXHU);
9091 def_builtin ("__MMACHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMACHS);
9092 def_builtin ("__MMACHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMACHU);
9093 def_builtin ("__MMRDHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMRDHS);
9094 def_builtin ("__MMRDHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMRDHU);
9095 def_builtin ("__MQADDHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQADDHSS);
9096 def_builtin ("__MQADDHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQADDHUS);
9097 def_builtin ("__MQSUBHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSUBHSS);
9098 def_builtin ("__MQSUBHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQSUBHUS);
9099 def_builtin ("__MQMULHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULHS);
9100 def_builtin ("__MQMULHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULHU);
9101 def_builtin ("__MQMULXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULXHS);
9102 def_builtin ("__MQMULXHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULXHU);
9103 def_builtin ("__MQMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACHS);
9104 def_builtin ("__MQMACHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMACHU);
9105 def_builtin ("__MCPXRS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXRS);
9106 def_builtin ("__MCPXRU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXRU);
9107 def_builtin ("__MCPXIS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXIS);
9108 def_builtin ("__MCPXIU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXIU);
9109 def_builtin ("__MQCPXRS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXRS);
9110 def_builtin ("__MQCPXRU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXRU);
9111 def_builtin ("__MQCPXIS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXIS);
9112 def_builtin ("__MQCPXIU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXIU);
9113 def_builtin ("__MCUT", uw1_ftype_acc_uw1, FRV_BUILTIN_MCUT);
9114 def_builtin ("__MCUTSS", uw1_ftype_acc_sw1, FRV_BUILTIN_MCUTSS);
9115 def_builtin ("__MEXPDHW", uw1_ftype_uw1_int, FRV_BUILTIN_MEXPDHW);
9116 def_builtin ("__MEXPDHD", uw2_ftype_uw1_int, FRV_BUILTIN_MEXPDHD);
9117 def_builtin ("__MPACKH", uw1_ftype_uh_uh, FRV_BUILTIN_MPACKH);
9118 def_builtin ("__MUNPACKH", uw2_ftype_uw1, FRV_BUILTIN_MUNPACKH);
9119 def_builtin ("__MDPACKH", uw2_ftype_uw2_uw2, FRV_BUILTIN_MDPACKH);
9120 def_builtin ("__MDUNPACKH", void_ftype_uw4_uw2, FRV_BUILTIN_MDUNPACKH);
9121 def_builtin ("__MBTOH", uw2_ftype_uw1, FRV_BUILTIN_MBTOH);
9122 def_builtin ("__MHTOB", uw1_ftype_uw2, FRV_BUILTIN_MHTOB);
9123 def_builtin ("__MBTOHE", void_ftype_uw4_uw1, FRV_BUILTIN_MBTOHE);
9124 def_builtin ("__MCLRACC", void_ftype_acc, FRV_BUILTIN_MCLRACC);
9125 def_builtin ("__MCLRACCA", void_ftype_void, FRV_BUILTIN_MCLRACCA);
9126 def_builtin ("__MRDACC", uw1_ftype_acc, FRV_BUILTIN_MRDACC);
9127 def_builtin ("__MRDACCG", uw1_ftype_acc, FRV_BUILTIN_MRDACCG);
9128 def_builtin ("__MWTACC", void_ftype_acc_uw1, FRV_BUILTIN_MWTACC);
9129 def_builtin ("__MWTACCG", void_ftype_acc_uw1, FRV_BUILTIN_MWTACCG);
9130 def_builtin ("__Mcop1", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP1);
9131 def_builtin ("__Mcop2", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP2);
9132 def_builtin ("__MTRAP", void_ftype_void, FRV_BUILTIN_MTRAP);
9133 def_builtin ("__MQXMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACHS);
9134 def_builtin ("__MQXMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACXHS);
9135 def_builtin ("__MQMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACXHS);
9136 def_builtin ("__MADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MADDACCS);
9137 def_builtin ("__MSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MSUBACCS);
9138 def_builtin ("__MASACCS", void_ftype_acc_acc, FRV_BUILTIN_MASACCS);
9139 def_builtin ("__MDADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MDADDACCS);
9140 def_builtin ("__MDSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MDSUBACCS);
9141 def_builtin ("__MDASACCS", void_ftype_acc_acc, FRV_BUILTIN_MDASACCS);
9142 def_builtin ("__MABSHS", uw1_ftype_sw1, FRV_BUILTIN_MABSHS);
9143 def_builtin ("__MDROTLI", uw2_ftype_uw2_int, FRV_BUILTIN_MDROTLI);
9144 def_builtin ("__MCPLHI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLHI);
9145 def_builtin ("__MCPLI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLI);
9146 def_builtin ("__MDCUTSSI", uw2_ftype_acc_int, FRV_BUILTIN_MDCUTSSI);
9147 def_builtin ("__MQSATHS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSATHS);
9148 def_builtin ("__MHSETLOS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETLOS);
9149 def_builtin ("__MHSETHIS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETHIS);
9150 def_builtin ("__MHDSETS", sw1_ftype_int, FRV_BUILTIN_MHDSETS);
9151 def_builtin ("__MHSETLOH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETLOH);
9152 def_builtin ("__MHSETHIH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETHIH);
9153 def_builtin ("__MHDSETH", uw1_ftype_uw1_int, FRV_BUILTIN_MHDSETH);
9155 #undef UNARY
9156 #undef BINARY
9157 #undef TRINARY
9160 /* Convert an integer constant to an accumulator register. ICODE is the
9161 code of the target instruction, OPNUM is the number of the
9162 accumulator operand and OPVAL is the constant integer. Try both
9163 ACC and ACCG registers; only report an error if neither fit the
9164 instruction. */
9166 static rtx
9167 frv_int_to_acc (icode, opnum, opval)
9168 enum insn_code icode;
9169 int opnum;
9170 rtx opval;
9172 rtx reg;
9174 if (GET_CODE (opval) != CONST_INT)
9176 error ("accumulator is not a constant integer");
9177 return NULL_RTX;
9179 if (! IN_RANGE_P (INTVAL (opval), 0, NUM_ACCS - 1))
9181 error ("accumulator number is out of bounds");
9182 return NULL_RTX;
9185 reg = gen_rtx_REG (insn_data[icode].operand[opnum].mode,
9186 ACC_FIRST + INTVAL (opval));
9187 if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode))
9188 REGNO (reg) = ACCG_FIRST + INTVAL (opval);
9190 if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode))
9192 error ("inappropriate accumulator for `%s'", insn_data[icode].name);
9193 return NULL_RTX;
9195 return reg;
9198 /* If an ACC rtx has mode MODE, return the mode that the matching ACCG
9199 should have. */
9201 static enum machine_mode
9202 frv_matching_accg_mode (mode)
9203 enum machine_mode mode;
9205 switch (mode)
9207 case V4SImode:
9208 return V4QImode;
9210 case DImode:
9211 return HImode;
9213 case SImode:
9214 return QImode;
9216 default:
9217 abort ();
9221 /* Return the accumulator guard that should be paired with accumulator
9222 register ACC. The mode of the returned register is in the same
9223 class as ACC, but is four times smaller. */
9226 frv_matching_accg_for_acc (acc)
9227 rtx acc;
9229 return gen_rtx_REG (frv_matching_accg_mode (GET_MODE (acc)),
9230 REGNO (acc) - ACC_FIRST + ACCG_FIRST);
9233 /* Read a value from the head of the tree list pointed to by ARGLISTPTR.
9234 Return the value as an rtx and replace *ARGLISTPTR with the tail of the
9235 list. */
9237 static rtx
9238 frv_read_argument (arglistptr)
9239 tree *arglistptr;
9241 tree next = TREE_VALUE (*arglistptr);
9242 *arglistptr = TREE_CHAIN (*arglistptr);
9243 return expand_expr (next, NULL_RTX, VOIDmode, 0);
9246 /* Return true if OPVAL can be used for operand OPNUM of instruction ICODE.
9247 The instruction should require a constant operand of some sort. The
9248 function prints an error if OPVAL is not valid. */
9250 static int
9251 frv_check_constant_argument (icode, opnum, opval)
9252 enum insn_code icode;
9253 int opnum;
9254 rtx opval;
9256 if (GET_CODE (opval) != CONST_INT)
9258 error ("`%s' expects a constant argument", insn_data[icode].name);
9259 return FALSE;
9261 if (! (*insn_data[icode].operand[opnum].predicate) (opval, VOIDmode))
9263 error ("constant argument out of range for `%s'", insn_data[icode].name);
9264 return FALSE;
9266 return TRUE;
9269 /* Return a legitimate rtx for instruction ICODE's return value. Use TARGET
9270 if it's not null, has the right mode, and satisfies operand 0's
9271 predicate. */
9273 static rtx
9274 frv_legitimize_target (icode, target)
9275 enum insn_code icode;
9276 rtx target;
9278 enum machine_mode mode = insn_data[icode].operand[0].mode;
9280 if (! target
9281 || GET_MODE (target) != mode
9282 || ! (*insn_data[icode].operand[0].predicate) (target, mode))
9283 return gen_reg_rtx (mode);
9284 else
9285 return target;
9288 /* Given that ARG is being passed as operand OPNUM to instruction ICODE,
9289 check whether ARG satisfies the operand's contraints. If it doesn't,
9290 copy ARG to a temporary register and return that. Otherwise return ARG
9291 itself. */
9293 static rtx
9294 frv_legitimize_argument (icode, opnum, arg)
9295 enum insn_code icode;
9296 int opnum;
9297 rtx arg;
9299 enum machine_mode mode = insn_data[icode].operand[opnum].mode;
9301 if ((*insn_data[icode].operand[opnum].predicate) (arg, mode))
9302 return arg;
9303 else
9304 return copy_to_mode_reg (mode, arg);
9307 /* Expand builtins that take a single, constant argument. At the moment,
9308 only MHDSETS falls into this category. */
9310 static rtx
9311 frv_expand_set_builtin (icode, arglist, target)
9312 enum insn_code icode;
9313 tree arglist;
9314 rtx target;
9316 rtx pat;
9317 rtx op0 = frv_read_argument (&arglist);
9319 if (! frv_check_constant_argument (icode, 1, op0))
9320 return NULL_RTX;
9322 target = frv_legitimize_target (icode, target);
9323 pat = GEN_FCN (icode) (target, op0);
9324 if (! pat)
9325 return NULL_RTX;
9327 emit_insn (pat);
9328 return target;
9331 /* Expand builtins that take one operand. */
9333 static rtx
9334 frv_expand_unop_builtin (icode, arglist, target)
9335 enum insn_code icode;
9336 tree arglist;
9337 rtx target;
9339 rtx pat;
9340 rtx op0 = frv_read_argument (&arglist);
9342 target = frv_legitimize_target (icode, target);
9343 op0 = frv_legitimize_argument (icode, 1, op0);
9344 pat = GEN_FCN (icode) (target, op0);
9345 if (! pat)
9346 return NULL_RTX;
9348 emit_insn (pat);
9349 return target;
9352 /* Expand builtins that take two operands. */
9354 static rtx
9355 frv_expand_binop_builtin (icode, arglist, target)
9356 enum insn_code icode;
9357 tree arglist;
9358 rtx target;
9360 rtx pat;
9361 rtx op0 = frv_read_argument (&arglist);
9362 rtx op1 = frv_read_argument (&arglist);
9364 target = frv_legitimize_target (icode, target);
9365 op0 = frv_legitimize_argument (icode, 1, op0);
9366 op1 = frv_legitimize_argument (icode, 2, op1);
9367 pat = GEN_FCN (icode) (target, op0, op1);
9368 if (! pat)
9369 return NULL_RTX;
9371 emit_insn (pat);
9372 return target;
9375 /* Expand cut-style builtins, which take two operands and an implicit ACCG
9376 one. */
9378 static rtx
9379 frv_expand_cut_builtin (icode, arglist, target)
9380 enum insn_code icode;
9381 tree arglist;
9382 rtx target;
9384 rtx pat;
9385 rtx op0 = frv_read_argument (&arglist);
9386 rtx op1 = frv_read_argument (&arglist);
9387 rtx op2;
9389 target = frv_legitimize_target (icode, target);
9390 op0 = frv_int_to_acc (icode, 1, op0);
9391 if (! op0)
9392 return NULL_RTX;
9394 if (icode == CODE_FOR_mdcutssi || GET_CODE (op1) == CONST_INT)
9396 if (! frv_check_constant_argument (icode, 2, op1))
9397 return NULL_RTX;
9399 else
9400 op1 = frv_legitimize_argument (icode, 2, op1);
9402 op2 = frv_matching_accg_for_acc (op0);
9403 pat = GEN_FCN (icode) (target, op0, op1, op2);
9404 if (! pat)
9405 return NULL_RTX;
9407 emit_insn (pat);
9408 return target;
9411 /* Expand builtins that take two operands and the second is immediate. */
9413 static rtx
9414 frv_expand_binopimm_builtin (icode, arglist, target)
9415 enum insn_code icode;
9416 tree arglist;
9417 rtx target;
9419 rtx pat;
9420 rtx op0 = frv_read_argument (&arglist);
9421 rtx op1 = frv_read_argument (&arglist);
9423 if (! frv_check_constant_argument (icode, 2, op1))
9424 return NULL_RTX;
9426 target = frv_legitimize_target (icode, target);
9427 op0 = frv_legitimize_argument (icode, 1, op0);
9428 pat = GEN_FCN (icode) (target, op0, op1);
9429 if (! pat)
9430 return NULL_RTX;
9432 emit_insn (pat);
9433 return target;
9436 /* Expand builtins that take two operands, the first operand being a pointer to
9437 ints and return void. */
9439 static rtx
9440 frv_expand_voidbinop_builtin (icode, arglist)
9441 enum insn_code icode;
9442 tree arglist;
9444 rtx pat;
9445 rtx op0 = frv_read_argument (&arglist);
9446 rtx op1 = frv_read_argument (&arglist);
9447 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
9448 rtx addr;
9450 if (GET_CODE (op0) != MEM)
9452 rtx reg = op0;
9454 if (! offsettable_address_p (0, mode0, op0))
9456 reg = gen_reg_rtx (Pmode);
9457 emit_insn (gen_rtx_SET (VOIDmode, reg, op0));
9460 op0 = gen_rtx_MEM (SImode, reg);
9463 addr = XEXP (op0, 0);
9464 if (! offsettable_address_p (0, mode0, addr))
9465 addr = copy_to_mode_reg (Pmode, op0);
9467 op0 = change_address (op0, V4SImode, addr);
9468 op1 = frv_legitimize_argument (icode, 1, op1);
9469 pat = GEN_FCN (icode) (op0, op1);
9470 if (! pat)
9471 return 0;
9473 emit_insn (pat);
9474 return 0;
9477 /* Expand builtins that take three operands and return void. The first
9478 argument must be a constant that describes a pair or quad accumulators. A
9479 fourth argument is created that is the accumulator guard register that
9480 corresponds to the accumulator. */
9482 static rtx
9483 frv_expand_voidtriop_builtin (icode, arglist)
9484 enum insn_code icode;
9485 tree arglist;
9487 rtx pat;
9488 rtx op0 = frv_read_argument (&arglist);
9489 rtx op1 = frv_read_argument (&arglist);
9490 rtx op2 = frv_read_argument (&arglist);
9491 rtx op3;
9493 op0 = frv_int_to_acc (icode, 0, op0);
9494 if (! op0)
9495 return NULL_RTX;
9497 op1 = frv_legitimize_argument (icode, 1, op1);
9498 op2 = frv_legitimize_argument (icode, 2, op2);
9499 op3 = frv_matching_accg_for_acc (op0);
9500 pat = GEN_FCN (icode) (op0, op1, op2, op3);
9501 if (! pat)
9502 return NULL_RTX;
9504 emit_insn (pat);
9505 return NULL_RTX;
9508 /* Expand builtins that perform accumulator-to-accumulator operations.
9509 These builtins take two accumulator numbers as argument and return
9510 void. */
9512 static rtx
9513 frv_expand_voidaccop_builtin (icode, arglist)
9514 enum insn_code icode;
9515 tree arglist;
9517 rtx pat;
9518 rtx op0 = frv_read_argument (&arglist);
9519 rtx op1 = frv_read_argument (&arglist);
9520 rtx op2;
9521 rtx op3;
9523 op0 = frv_int_to_acc (icode, 0, op0);
9524 if (! op0)
9525 return NULL_RTX;
9527 op1 = frv_int_to_acc (icode, 1, op1);
9528 if (! op1)
9529 return NULL_RTX;
9531 op2 = frv_matching_accg_for_acc (op0);
9532 op3 = frv_matching_accg_for_acc (op1);
9533 pat = GEN_FCN (icode) (op0, op1, op2, op3);
9534 if (! pat)
9535 return NULL_RTX;
9537 emit_insn (pat);
9538 return NULL_RTX;
9541 /* Expand the MCLRACC builtin. This builtin takes a single accumulator
9542 number as argument. */
9544 static rtx
9545 frv_expand_mclracc_builtin (arglist)
9546 tree arglist;
9548 enum insn_code icode = CODE_FOR_mclracc;
9549 rtx pat;
9550 rtx op0 = frv_read_argument (&arglist);
9552 op0 = frv_int_to_acc (icode, 0, op0);
9553 if (! op0)
9554 return NULL_RTX;
9556 pat = GEN_FCN (icode) (op0);
9557 if (pat)
9558 emit_insn (pat);
9560 return NULL_RTX;
9563 /* Expand builtins that take no arguments. */
9565 static rtx
9566 frv_expand_noargs_builtin (icode)
9567 enum insn_code icode;
9569 rtx pat = GEN_FCN (icode) (GEN_INT (0));
9570 if (pat)
9571 emit_insn (pat);
9573 return NULL_RTX;
9576 /* Expand MRDACC and MRDACCG. These builtins take a single accumulator
9577 number or accumulator guard number as argument and return an SI integer. */
9579 static rtx
9580 frv_expand_mrdacc_builtin (icode, arglist)
9581 enum insn_code icode;
9582 tree arglist;
9584 rtx pat;
9585 rtx target = gen_reg_rtx (SImode);
9586 rtx op0 = frv_read_argument (&arglist);
9588 op0 = frv_int_to_acc (icode, 1, op0);
9589 if (! op0)
9590 return NULL_RTX;
9592 pat = GEN_FCN (icode) (target, op0);
9593 if (! pat)
9594 return NULL_RTX;
9596 emit_insn (pat);
9597 return target;
9600 /* Expand MWTACC and MWTACCG. These builtins take an accumulator or
9601 accumulator guard as their first argument and an SImode value as their
9602 second. */
9604 static rtx
9605 frv_expand_mwtacc_builtin (icode, arglist)
9606 enum insn_code icode;
9607 tree arglist;
9609 rtx pat;
9610 rtx op0 = frv_read_argument (&arglist);
9611 rtx op1 = frv_read_argument (&arglist);
9613 op0 = frv_int_to_acc (icode, 0, op0);
9614 if (! op0)
9615 return NULL_RTX;
9617 op1 = frv_legitimize_argument (icode, 1, op1);
9618 pat = GEN_FCN (icode) (op0, op1);
9619 if (pat)
9620 emit_insn (pat);
9622 return NULL_RTX;
9625 /* Expand builtins. */
9627 static rtx
9628 frv_expand_builtin (exp, target, subtarget, mode, ignore)
9629 tree exp;
9630 rtx target;
9631 rtx subtarget ATTRIBUTE_UNUSED;
9632 enum machine_mode mode ATTRIBUTE_UNUSED;
9633 int ignore ATTRIBUTE_UNUSED;
9635 tree arglist = TREE_OPERAND (exp, 1);
9636 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
9637 unsigned fcode = (unsigned)DECL_FUNCTION_CODE (fndecl);
9638 unsigned i;
9639 struct builtin_description *d;
9641 if (! TARGET_MEDIA)
9643 error ("media functions are not available unless -mmedia is used");
9644 return NULL_RTX;
9647 switch (fcode)
9649 case FRV_BUILTIN_MCOP1:
9650 case FRV_BUILTIN_MCOP2:
9651 case FRV_BUILTIN_MDUNPACKH:
9652 case FRV_BUILTIN_MBTOHE:
9653 if (! TARGET_MEDIA_REV1)
9655 error ("this media function is only available on the fr500");
9656 return NULL_RTX;
9658 break;
9660 case FRV_BUILTIN_MQXMACHS:
9661 case FRV_BUILTIN_MQXMACXHS:
9662 case FRV_BUILTIN_MQMACXHS:
9663 case FRV_BUILTIN_MADDACCS:
9664 case FRV_BUILTIN_MSUBACCS:
9665 case FRV_BUILTIN_MASACCS:
9666 case FRV_BUILTIN_MDADDACCS:
9667 case FRV_BUILTIN_MDSUBACCS:
9668 case FRV_BUILTIN_MDASACCS:
9669 case FRV_BUILTIN_MABSHS:
9670 case FRV_BUILTIN_MDROTLI:
9671 case FRV_BUILTIN_MCPLHI:
9672 case FRV_BUILTIN_MCPLI:
9673 case FRV_BUILTIN_MDCUTSSI:
9674 case FRV_BUILTIN_MQSATHS:
9675 case FRV_BUILTIN_MHSETLOS:
9676 case FRV_BUILTIN_MHSETLOH:
9677 case FRV_BUILTIN_MHSETHIS:
9678 case FRV_BUILTIN_MHSETHIH:
9679 case FRV_BUILTIN_MHDSETS:
9680 case FRV_BUILTIN_MHDSETH:
9681 if (! TARGET_MEDIA_REV2)
9683 error ("this media function is only available on the fr400");
9684 return NULL_RTX;
9686 break;
9688 default:
9689 break;
9692 /* Expand unique builtins. */
9694 switch (fcode)
9696 case FRV_BUILTIN_MTRAP:
9697 return frv_expand_noargs_builtin (CODE_FOR_mtrap);
9699 case FRV_BUILTIN_MCLRACC:
9700 return frv_expand_mclracc_builtin (arglist);
9702 case FRV_BUILTIN_MCLRACCA:
9703 if (TARGET_ACC_8)
9704 return frv_expand_noargs_builtin (CODE_FOR_mclracca8);
9705 else
9706 return frv_expand_noargs_builtin (CODE_FOR_mclracca4);
9708 case FRV_BUILTIN_MRDACC:
9709 return frv_expand_mrdacc_builtin (CODE_FOR_mrdacc, arglist);
9711 case FRV_BUILTIN_MRDACCG:
9712 return frv_expand_mrdacc_builtin (CODE_FOR_mrdaccg, arglist);
9714 case FRV_BUILTIN_MWTACC:
9715 return frv_expand_mwtacc_builtin (CODE_FOR_mwtacc, arglist);
9717 case FRV_BUILTIN_MWTACCG:
9718 return frv_expand_mwtacc_builtin (CODE_FOR_mwtaccg, arglist);
9720 default:
9721 break;
9724 /* Expand groups of builtins. */
9726 for (i = 0, d = bdesc_set; i < sizeof (bdesc_set) / sizeof *d; i++, d++)
9727 if (d->code == fcode)
9728 return frv_expand_set_builtin (d->icode, arglist, target);
9730 for (i = 0, d = bdesc_1arg; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
9731 if (d->code == fcode)
9732 return frv_expand_unop_builtin (d->icode, arglist, target);
9734 for (i = 0, d = bdesc_2arg; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
9735 if (d->code == fcode)
9736 return frv_expand_binop_builtin (d->icode, arglist, target);
9738 for (i = 0, d = bdesc_cut; i < sizeof (bdesc_cut) / sizeof *d; i++, d++)
9739 if (d->code == fcode)
9740 return frv_expand_cut_builtin (d->icode, arglist, target);
9742 for (i = 0, d = bdesc_2argimm;
9743 i < sizeof (bdesc_2argimm) / sizeof *d;
9744 i++, d++)
9746 if (d->code == fcode)
9747 return frv_expand_binopimm_builtin (d->icode, arglist, target);
9750 for (i = 0, d = bdesc_void2arg;
9751 i < sizeof (bdesc_void2arg) / sizeof *d;
9752 i++, d++)
9754 if (d->code == fcode)
9755 return frv_expand_voidbinop_builtin (d->icode, arglist);
9758 for (i = 0, d = bdesc_void3arg;
9759 i < sizeof (bdesc_void3arg) / sizeof *d;
9760 i++, d++)
9762 if (d->code == fcode)
9763 return frv_expand_voidtriop_builtin (d->icode, arglist);
9766 for (i = 0, d = bdesc_voidacc;
9767 i < sizeof (bdesc_voidacc) / sizeof *d;
9768 i++, d++)
9770 if (d->code == fcode)
9771 return frv_expand_voidaccop_builtin (d->icode, arglist);
9773 return 0;
9776 static const char *
9777 frv_strip_name_encoding (str)
9778 const char *str;
9780 while (*str == '*' || *str == SDATA_FLAG_CHAR)
9781 str++;
9782 return str;
9785 static bool
9786 frv_in_small_data_p (decl)
9787 tree decl;
9789 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
9791 return symbol_ref_small_data_p (XEXP (DECL_RTL (decl), 0))
9792 && size > 0 && size <= g_switch_value;
9795 static bool
9796 frv_rtx_costs (x, code, outer_code, total)
9797 rtx x;
9798 int code, outer_code;
9799 int *total;
9801 switch (code)
9803 case CONST_INT:
9804 /* Make 12 bit integers really cheap. */
9805 if (IN_RANGE_P (INTVAL (x), -2048, 2047))
9807 *total = 0;
9808 return true;
9810 /* FALLTHRU */
9812 case CONST:
9813 case LABEL_REF:
9814 case SYMBOL_REF:
9815 case CONST_DOUBLE:
9816 *total = COSTS_N_INSNS (2);
9817 return true;
9819 case PLUS:
9820 case MINUS:
9821 case AND:
9822 case IOR:
9823 case XOR:
9824 case ASHIFT:
9825 case ASHIFTRT:
9826 case LSHIFTRT:
9827 case NOT:
9828 case NEG:
9829 case COMPARE:
9830 if (GET_MODE (x) == SImode)
9831 *total = COSTS_N_INSNS (1);
9832 else if (GET_MODE (x) == DImode)
9833 *total = COSTS_N_INSNS (2);
9834 else
9835 *total = COSTS_N_INSNS (3);
9836 return true;
9838 case MULT:
9839 if (GET_MODE (x) == SImode)
9840 *total = COSTS_N_INSNS (2);
9841 else
9842 *total = COSTS_N_INSNS (6); /* guess */
9843 return true;
9845 case DIV:
9846 case UDIV:
9847 case MOD:
9848 case UMOD:
9849 *total = COSTS_N_INSNS (18);
9850 return true;
9852 default:
9853 return false;