]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/frv/frv.c
vxlib.c: Fix comment typos.
[thirdparty/gcc.git] / gcc / config / frv / frv.c
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2 Contributed by Red Hat, Inc.
3
4 This file is part of GCC.
5
6 GCC 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.
10
11 GCC 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.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
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"
50
51 #ifndef FRV_INLINE
52 #define FRV_INLINE inline
53 #endif
54
55 /* Temporary register allocation support structure. */
56 typedef struct frv_tmp_reg_struct
57 {
58 HARD_REG_SET regs; /* possible registers to allocate */
59 int next_reg[N_REG_CLASSES]; /* next register to allocate per class */
60 }
61 frv_tmp_reg_t;
62
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 */
73
74 /* conditional expression used */
75 #define REGSTATE_IF_EITHER (REGSTATE_IF_TRUE | REGSTATE_IF_FALSE)
76
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 */
80
81 /* Used in frv_frame_accessor_t to indicate the direction of a register-to-
82 memory move. */
83 enum frv_stack_op
84 {
85 FRV_LOAD,
86 FRV_STORE
87 };
88
89 /* Information required by frv_frame_access. */
90 typedef struct
91 {
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;
97
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;
103
104 /* The offset of BASE from the bottom of the current frame, in bytes. */
105 int base_offset;
106 } frv_frame_accessor_t;
107
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;
112
113 /* Conditional execution support gathered together in one structure */
114 typedef struct
115 {
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;
120
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;
127
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;
133
134 /* Temporary registers allocated to hold constants during conditional
135 execution. */
136 rtx scratch_regs[FIRST_PSEUDO_REGISTER];
137
138 /* Current number of temp registers available. */
139 int cur_scratch_regs;
140
141 /* Number of nested conditional execution blocks */
142 int num_nested_cond_exec;
143
144 /* Map of insns that set up constants in scratch registers. */
145 bitmap scratch_insns_bitmap;
146
147 /* Conditional execution test register (CC0..CC7) */
148 rtx cr_reg;
149
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 inconvenient for GCC. */
155 rtx nested_cc_reg;
156
157 /* Extra CR registers used for &&, ||. */
158 rtx extra_int_cr;
159 rtx extra_fp_cr;
160
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;
164 }
165 frv_ifcvt_t;
166
167 static /* GTY(()) */ frv_ifcvt_t frv_ifcvt;
168
169 /* Map register number to smallest register class. */
170 enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER];
171
172 /* Map class letter into register class */
173 enum reg_class reg_class_from_letter[256];
174
175 /* Cached value of frv_stack_info */
176 static frv_stack_t *frv_stack_cache = (frv_stack_t *)0;
177
178 /* -mbranch-cost= support */
179 const char *frv_branch_cost_string;
180 int frv_branch_cost_int = DEFAULT_BRANCH_COST;
181
182 /* -mcpu= support */
183 const char *frv_cpu_string; /* -mcpu= option */
184 frv_cpu_t frv_cpu_type = CPU_TYPE; /* value of -mcpu= */
185
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*/
189
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*/
193
194 /* -msched-lookahead=n */
195 const char *frv_sched_lookahead_str; /* -msched-lookahead=n */
196 int frv_sched_lookahead = 4; /* -msched-lookahead=n */
197
198 /* Forward references */
199 static int frv_default_flags_for_cpu (void);
200 static int frv_string_begins_with (tree, const char *);
201 static FRV_INLINE int const_small_data_p (rtx);
202 static FRV_INLINE int plus_small_data_p (rtx, rtx);
203 static void frv_print_operand_memory_reference_reg
204 (FILE *, rtx);
205 static void frv_print_operand_memory_reference (FILE *, rtx, int);
206 static int frv_print_operand_jump_hint (rtx);
207 static FRV_INLINE int frv_regno_ok_for_base_p (int, int);
208 static rtx single_set_pattern (rtx);
209 static int frv_function_contains_far_jump (void);
210 static rtx frv_alloc_temp_reg (frv_tmp_reg_t *,
211 enum reg_class,
212 enum machine_mode,
213 int, int);
214 static rtx frv_frame_offset_rtx (int);
215 static rtx frv_frame_mem (enum machine_mode, rtx, int);
216 static rtx frv_dwarf_store (rtx, int);
217 static void frv_frame_insn (rtx, rtx);
218 static void frv_frame_access (frv_frame_accessor_t*,
219 rtx, int);
220 static void frv_frame_access_multi (frv_frame_accessor_t*,
221 frv_stack_t *, int);
222 static void frv_frame_access_standard_regs (enum frv_stack_op,
223 frv_stack_t *);
224 static struct machine_function *frv_init_machine_status (void);
225 static int frv_legitimate_memory_operand (rtx, enum machine_mode, int);
226 static rtx frv_int_to_acc (enum insn_code, int, rtx);
227 static enum machine_mode frv_matching_accg_mode (enum machine_mode);
228 static rtx frv_read_argument (tree *);
229 static int frv_check_constant_argument (enum insn_code, int, rtx);
230 static rtx frv_legitimize_target (enum insn_code, rtx);
231 static rtx frv_legitimize_argument (enum insn_code, int, rtx);
232 static rtx frv_expand_set_builtin (enum insn_code, tree, rtx);
233 static rtx frv_expand_unop_builtin (enum insn_code, tree, rtx);
234 static rtx frv_expand_binop_builtin (enum insn_code, tree, rtx);
235 static rtx frv_expand_cut_builtin (enum insn_code, tree, rtx);
236 static rtx frv_expand_binopimm_builtin (enum insn_code, tree, rtx);
237 static rtx frv_expand_voidbinop_builtin (enum insn_code, tree);
238 static rtx frv_expand_voidtriop_builtin (enum insn_code, tree);
239 static rtx frv_expand_voidaccop_builtin (enum insn_code, tree);
240 static rtx frv_expand_mclracc_builtin (tree);
241 static rtx frv_expand_mrdacc_builtin (enum insn_code, tree);
242 static rtx frv_expand_mwtacc_builtin (enum insn_code, tree);
243 static rtx frv_expand_noargs_builtin (enum insn_code);
244 static rtx frv_emit_comparison (enum rtx_code, rtx, rtx);
245 static int frv_clear_registers_used (rtx *, void *);
246 static void frv_ifcvt_add_insn (rtx, rtx, int);
247 static rtx frv_ifcvt_rewrite_mem (rtx, enum machine_mode, rtx);
248 static rtx frv_ifcvt_load_value (rtx, rtx);
249 static void frv_registers_update (rtx, unsigned char [],
250 int [], int *, int);
251 static int frv_registers_used_p (rtx, unsigned char [], int);
252 static int frv_registers_set_p (rtx, unsigned char [], int);
253 static int frv_issue_rate (void);
254 static int frv_use_dfa_pipeline_interface (void);
255 static void frv_pack_insns (void);
256 static void frv_function_prologue (FILE *, HOST_WIDE_INT);
257 static void frv_function_epilogue (FILE *, HOST_WIDE_INT);
258 static bool frv_assemble_integer (rtx, unsigned, int);
259 static void frv_init_builtins (void);
260 static rtx frv_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
261 static void frv_init_libfuncs (void);
262 static bool frv_in_small_data_p (tree);
263 static void frv_asm_output_mi_thunk
264 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
265 static bool frv_rtx_costs (rtx, int, int, int*);
266 static void frv_asm_out_constructor (rtx, int);
267 static void frv_asm_out_destructor (rtx, int);
268 \f
269 /* Initialize the GCC target structure. */
270 #undef TARGET_ASM_FUNCTION_PROLOGUE
271 #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue
272 #undef TARGET_ASM_FUNCTION_EPILOGUE
273 #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue
274 #undef TARGET_ASM_INTEGER
275 #define TARGET_ASM_INTEGER frv_assemble_integer
276 #undef TARGET_INIT_BUILTINS
277 #define TARGET_INIT_BUILTINS frv_init_builtins
278 #undef TARGET_EXPAND_BUILTIN
279 #define TARGET_EXPAND_BUILTIN frv_expand_builtin
280 #undef TARGET_INIT_LIBFUNCS
281 #define TARGET_INIT_LIBFUNCS frv_init_libfuncs
282 #undef TARGET_IN_SMALL_DATA_P
283 #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p
284 #undef TARGET_RTX_COSTS
285 #define TARGET_RTX_COSTS frv_rtx_costs
286 #undef TARGET_ASM_CONSTRUCTOR
287 #define TARGET_ASM_CONSTRUCTOR frv_asm_out_constructor
288 #undef TARGET_ASM_DESTRUCTOR
289 #define TARGET_ASM_DESTRUCTOR frv_asm_out_destructor
290
291 #undef TARGET_ASM_OUTPUT_MI_THUNK
292 #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk
293 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
294 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
295
296 #undef TARGET_SCHED_ISSUE_RATE
297 #define TARGET_SCHED_ISSUE_RATE frv_issue_rate
298 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
299 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE frv_use_dfa_pipeline_interface
300
301 struct gcc_target targetm = TARGET_INITIALIZER;
302 \f
303 /* Given a CONST, return true if the symbol_ref points to small data. */
304
305 static FRV_INLINE int
306 const_small_data_p (rtx x)
307 {
308 rtx x0, x1;
309
310 if (GET_CODE (XEXP (x, 0)) != PLUS)
311 return FALSE;
312
313 x0 = XEXP (XEXP (x, 0), 0);
314 if (GET_CODE (x0) != SYMBOL_REF || !SYMBOL_REF_SMALL_P (x0))
315 return FALSE;
316
317 x1 = XEXP (XEXP (x, 0), 1);
318 if (GET_CODE (x1) != CONST_INT
319 || !IN_RANGE_P (INTVAL (x1), -2048, 2047))
320 return FALSE;
321
322 return TRUE;
323 }
324
325 /* Given a PLUS, return true if this is a small data reference. */
326
327 static FRV_INLINE int
328 plus_small_data_p (rtx op0, rtx op1)
329 {
330 if (GET_MODE (op0) == SImode
331 && GET_CODE (op0) == REG
332 && REGNO (op0) == SDA_BASE_REG)
333 {
334 if (GET_CODE (op1) == SYMBOL_REF)
335 return SYMBOL_REF_SMALL_P (op1);
336
337 if (GET_CODE (op1) == CONST)
338 return const_small_data_p (op1);
339 }
340
341 return FALSE;
342 }
343
344 \f
345 static int
346 frv_default_flags_for_cpu (void)
347 {
348 switch (frv_cpu_type)
349 {
350 case FRV_CPU_GENERIC:
351 return MASK_DEFAULT_FRV;
352
353 case FRV_CPU_FR500:
354 case FRV_CPU_TOMCAT:
355 return MASK_DEFAULT_FR500;
356
357 case FRV_CPU_FR400:
358 return MASK_DEFAULT_FR400;
359
360 case FRV_CPU_FR300:
361 case FRV_CPU_SIMPLE:
362 return MASK_DEFAULT_SIMPLE;
363 }
364 abort ();
365 }
366
367 /* Sometimes certain combinations of command options do not make
368 sense on a particular target machine. You can define a macro
369 `OVERRIDE_OPTIONS' to take account of this. This macro, if
370 defined, is executed once just after all the command options have
371 been parsed.
372
373 Don't use this macro to turn on various extra optimizations for
374 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
375
376 void
377 frv_override_options (void)
378 {
379 int regno, i;
380
381 /* Set the cpu type */
382 if (frv_cpu_string)
383 {
384 if (strcmp (frv_cpu_string, "simple") == 0)
385 frv_cpu_type = FRV_CPU_SIMPLE;
386
387 else if (strcmp (frv_cpu_string, "tomcat") == 0)
388 frv_cpu_type = FRV_CPU_TOMCAT;
389
390 else if (strncmp (frv_cpu_string, "fr", sizeof ("fr")-1) != 0)
391 error ("Unknown cpu: -mcpu=%s", frv_cpu_string);
392
393 else
394 {
395 const char *p = frv_cpu_string + sizeof ("fr") - 1;
396 if (strcmp (p, "500") == 0)
397 frv_cpu_type = FRV_CPU_FR500;
398
399 else if (strcmp (p, "400") == 0)
400 frv_cpu_type = FRV_CPU_FR400;
401
402 else if (strcmp (p, "300") == 0)
403 frv_cpu_type = FRV_CPU_FR300;
404
405 else if (strcmp (p, "v") == 0)
406 frv_cpu_type = FRV_CPU_GENERIC;
407
408 else
409 error ("Unknown cpu: -mcpu=%s", frv_cpu_string);
410 }
411 }
412
413 target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit);
414
415 /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the
416 linker about linking pic and non-pic code. */
417 if (TARGET_LIBPIC)
418 {
419 if (!flag_pic) /* -fPIC */
420 flag_pic = 2;
421
422 if (! g_switch_set) /* -G0 */
423 {
424 g_switch_set = 1;
425 g_switch_value = 0;
426 }
427 }
428
429 /* Both -fpic and -gdwarf want to use .previous and the assembler only keeps
430 one level. */
431 if (write_symbols == DWARF_DEBUG && flag_pic)
432 error ("-fpic and -gdwarf are incompatible (-fpic and -g/-gdwarf-2 are fine)");
433
434 /* Change the branch cost value */
435 if (frv_branch_cost_string)
436 frv_branch_cost_int = atoi (frv_branch_cost_string);
437
438 /* Change the # of insns to be converted to conditional execution */
439 if (frv_condexec_insns_str)
440 frv_condexec_insns = atoi (frv_condexec_insns_str);
441
442 /* Change # of temporary registers used to hold integer constants */
443 if (frv_condexec_temps_str)
444 frv_condexec_temps = atoi (frv_condexec_temps_str);
445
446 /* Change scheduling look ahead. */
447 if (frv_sched_lookahead_str)
448 frv_sched_lookahead = atoi (frv_sched_lookahead_str);
449
450 /* A C expression whose value is a register class containing hard
451 register REGNO. In general there is more than one such class;
452 choose a class which is "minimal", meaning that no smaller class
453 also contains the register. */
454
455 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
456 {
457 enum reg_class class;
458
459 if (GPR_P (regno))
460 {
461 int gpr_reg = regno - GPR_FIRST;
462 if ((gpr_reg & 3) == 0)
463 class = QUAD_REGS;
464
465 else if ((gpr_reg & 1) == 0)
466 class = EVEN_REGS;
467
468 else
469 class = GPR_REGS;
470 }
471
472 else if (FPR_P (regno))
473 {
474 int fpr_reg = regno - GPR_FIRST;
475 if ((fpr_reg & 3) == 0)
476 class = QUAD_FPR_REGS;
477
478 else if ((fpr_reg & 1) == 0)
479 class = FEVEN_REGS;
480
481 else
482 class = FPR_REGS;
483 }
484
485 else if (regno == LR_REGNO)
486 class = LR_REG;
487
488 else if (regno == LCR_REGNO)
489 class = LCR_REG;
490
491 else if (ICC_P (regno))
492 class = ICC_REGS;
493
494 else if (FCC_P (regno))
495 class = FCC_REGS;
496
497 else if (ICR_P (regno))
498 class = ICR_REGS;
499
500 else if (FCR_P (regno))
501 class = FCR_REGS;
502
503 else if (ACC_P (regno))
504 {
505 int r = regno - ACC_FIRST;
506 if ((r & 3) == 0)
507 class = QUAD_ACC_REGS;
508 else if ((r & 1) == 0)
509 class = EVEN_ACC_REGS;
510 else
511 class = ACC_REGS;
512 }
513
514 else if (ACCG_P (regno))
515 class = ACCG_REGS;
516
517 else
518 class = NO_REGS;
519
520 regno_reg_class[regno] = class;
521 }
522
523 /* Check for small data option */
524 if (!g_switch_set)
525 g_switch_value = SDATA_DEFAULT_SIZE;
526
527 /* A C expression which defines the machine-dependent operand
528 constraint letters for register classes. If CHAR is such a
529 letter, the value should be the register class corresponding to
530 it. Otherwise, the value should be `NO_REGS'. The register
531 letter `r', corresponding to class `GENERAL_REGS', will not be
532 passed to this macro; you do not need to handle it.
533
534 The following letters are unavailable, due to being used as
535 constraints:
536 '0'..'9'
537 '<', '>'
538 'E', 'F', 'G', 'H'
539 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'
540 'Q', 'R', 'S', 'T', 'U'
541 'V', 'X'
542 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */
543
544 for (i = 0; i < 256; i++)
545 reg_class_from_letter[i] = NO_REGS;
546
547 reg_class_from_letter['a'] = ACC_REGS;
548 reg_class_from_letter['b'] = EVEN_ACC_REGS;
549 reg_class_from_letter['c'] = CC_REGS;
550 reg_class_from_letter['d'] = GPR_REGS;
551 reg_class_from_letter['e'] = EVEN_REGS;
552 reg_class_from_letter['f'] = FPR_REGS;
553 reg_class_from_letter['h'] = FEVEN_REGS;
554 reg_class_from_letter['l'] = LR_REG;
555 reg_class_from_letter['q'] = QUAD_REGS;
556 reg_class_from_letter['t'] = ICC_REGS;
557 reg_class_from_letter['u'] = FCC_REGS;
558 reg_class_from_letter['v'] = ICR_REGS;
559 reg_class_from_letter['w'] = FCR_REGS;
560 reg_class_from_letter['x'] = QUAD_FPR_REGS;
561 reg_class_from_letter['y'] = LCR_REG;
562 reg_class_from_letter['z'] = SPR_REGS;
563 reg_class_from_letter['A'] = QUAD_ACC_REGS;
564 reg_class_from_letter['B'] = ACCG_REGS;
565 reg_class_from_letter['C'] = CR_REGS;
566
567 /* There is no single unaligned SI op for PIC code. Sometimes we
568 need to use ".4byte" and sometimes we need to use ".picptr".
569 See frv_assemble_integer for details. */
570 if (flag_pic)
571 targetm.asm_out.unaligned_op.si = 0;
572
573 init_machine_status = frv_init_machine_status;
574 }
575
576 \f
577 /* Some machines may desire to change what optimizations are performed for
578 various optimization levels. This macro, if defined, is executed once just
579 after the optimization level is determined and before the remainder of the
580 command options have been parsed. Values set in this macro are used as the
581 default values for the other command line options.
582
583 LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if
584 `-O' is specified, and 0 if neither is specified.
585
586 SIZE is nonzero if `-Os' is specified, 0 otherwise.
587
588 You should not use this macro to change options that are not
589 machine-specific. These should uniformly selected by the same optimization
590 level on all supported machines. Use this macro to enable machbine-specific
591 optimizations.
592
593 *Do not examine `write_symbols' in this macro!* The debugging options are
594 *not supposed to alter the generated code. */
595
596 /* On the FRV, possibly disable VLIW packing which is done by the 2nd
597 scheduling pass at the current time. */
598 void
599 frv_optimization_options (int level, int size ATTRIBUTE_UNUSED)
600 {
601 if (level >= 2)
602 {
603 #ifdef DISABLE_SCHED2
604 flag_schedule_insns_after_reload = 0;
605 #endif
606 #ifdef ENABLE_RCSP
607 flag_rcsp = 1;
608 #endif
609 }
610 }
611
612 \f
613 /* Return true if NAME (a STRING_CST node) begins with PREFIX. */
614
615 static int
616 frv_string_begins_with (tree name, const char *prefix)
617 {
618 int prefix_len = strlen (prefix);
619
620 /* Remember: NAME's length includes the null terminator. */
621 return (TREE_STRING_LENGTH (name) > prefix_len
622 && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0);
623 }
624 \f
625 /* Zero or more C statements that may conditionally modify two variables
626 `fixed_regs' and `call_used_regs' (both of type `char []') after they have
627 been initialized from the two preceding macros.
628
629 This is necessary in case the fixed or call-clobbered registers depend on
630 target flags.
631
632 You need not define this macro if it has no work to do.
633
634 If the usage of an entire class of registers depends on the target flags,
635 you may indicate this to GCC by using this macro to modify `fixed_regs' and
636 `call_used_regs' to 1 for each of the registers in the classes which should
637 not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return
638 `NO_REGS' if it is called with a letter for a class that shouldn't be used.
639
640 (However, if this class is not included in `GENERAL_REGS' and all of the
641 insn patterns whose constraints permit this class are controlled by target
642 switches, then GCC will automatically avoid using these registers when the
643 target switches are opposed to them.) */
644
645 void
646 frv_conditional_register_usage (void)
647 {
648 int i;
649
650 for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++)
651 fixed_regs[i] = call_used_regs[i] = 1;
652
653 for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++)
654 fixed_regs[i] = call_used_regs[i] = 1;
655
656 for (i = ACC_FIRST + NUM_ACCS; i <= ACC_LAST; i++)
657 fixed_regs[i] = call_used_regs[i] = 1;
658
659 for (i = ACCG_FIRST + NUM_ACCS; i <= ACCG_LAST; i++)
660 fixed_regs[i] = call_used_regs[i] = 1;
661
662 /* Reserve the registers used for conditional execution. At present, we need
663 1 ICC and 1 ICR register. */
664 fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1;
665 fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1;
666
667 if (TARGET_FIXED_CC)
668 {
669 fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1;
670 fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1;
671 fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1;
672 fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1;
673 }
674
675 #if 0
676 /* If -fpic, SDA_BASE_REG is the PIC register. */
677 if (g_switch_value == 0 && !flag_pic)
678 fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0;
679
680 if (!flag_pic)
681 fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0;
682 #endif
683 }
684
685 \f
686 /*
687 * Compute the stack frame layout
688 *
689 * Register setup:
690 * +---------------+-----------------------+-----------------------+
691 * |Register |type |caller-save/callee-save|
692 * +---------------+-----------------------+-----------------------+
693 * |GR0 |Zero register | - |
694 * |GR1 |Stack pointer(SP) | - |
695 * |GR2 |Frame pointer(FP) | - |
696 * |GR3 |Hidden parameter | caller save |
697 * |GR4-GR7 | - | caller save |
698 * |GR8-GR13 |Argument register | caller save |
699 * |GR14-GR15 | - | caller save |
700 * |GR16-GR31 | - | callee save |
701 * |GR32-GR47 | - | caller save |
702 * |GR48-GR63 | - | callee save |
703 * |FR0-FR15 | - | caller save |
704 * |FR16-FR31 | - | callee save |
705 * |FR32-FR47 | - | caller save |
706 * |FR48-FR63 | - | callee save |
707 * +---------------+-----------------------+-----------------------+
708 *
709 * Stack frame setup:
710 * Low
711 * SP-> |-----------------------------------|
712 * | Argument area |
713 * |-----------------------------------|
714 * | Register save area |
715 * |-----------------------------------|
716 * | Local variable save area |
717 * FP-> |-----------------------------------|
718 * | Old FP |
719 * |-----------------------------------|
720 * | Hidden parameter save area |
721 * |-----------------------------------|
722 * | Return address(LR) storage area |
723 * |-----------------------------------|
724 * | Padding for alignment |
725 * |-----------------------------------|
726 * | Register argument area |
727 * OLD SP-> |-----------------------------------|
728 * | Parameter area |
729 * |-----------------------------------|
730 * High
731 *
732 * Argument area/Parameter area:
733 *
734 * When a function is called, this area is used for argument transfer. When
735 * the argument is set up by the caller function, this area is referred to as
736 * the argument area. When the argument is referenced by the callee function,
737 * this area is referred to as the parameter area. The area is allocated when
738 * all arguments cannot be placed on the argument register at the time of
739 * argument transfer.
740 *
741 * Register save area:
742 *
743 * This is a register save area that must be guaranteed for the caller
744 * function. This area is not secured when the register save operation is not
745 * needed.
746 *
747 * Local variable save area:
748 *
749 * This is the area for local variables and temporary variables.
750 *
751 * Old FP:
752 *
753 * This area stores the FP value of the caller function.
754 *
755 * Hidden parameter save area:
756 *
757 * This area stores the start address of the return value storage
758 * area for a struct/union return function.
759 * When a struct/union is used as the return value, the caller
760 * function stores the return value storage area start address in
761 * register GR3 and passes it to the caller function.
762 * The callee function interprets the address stored in the GR3
763 * as the return value storage area start address.
764 * When register GR3 needs to be saved into memory, the callee
765 * function saves it in the hidden parameter save area. This
766 * area is not secured when the save operation is not needed.
767 *
768 * Return address(LR) storage area:
769 *
770 * This area saves the LR. The LR stores the address of a return to the caller
771 * function for the purpose of function calling.
772 *
773 * Argument register area:
774 *
775 * This area saves the argument register. This area is not secured when the
776 * save operation is not needed.
777 *
778 * Argument:
779 *
780 * Arguments, the count of which equals the count of argument registers (6
781 * words), are positioned in registers GR8 to GR13 and delivered to the callee
782 * function. When a struct/union return function is called, the return value
783 * area address is stored in register GR3. Arguments not placed in the
784 * argument registers will be stored in the stack argument area for transfer
785 * purposes. When an 8-byte type argument is to be delivered using registers,
786 * it is divided into two and placed in two registers for transfer. When
787 * argument registers must be saved to memory, the callee function secures an
788 * argument register save area in the stack. In this case, a continuous
789 * argument register save area must be established in the parameter area. The
790 * argument register save area must be allocated as needed to cover the size of
791 * the argument register to be saved. If the function has a variable count of
792 * arguments, it saves all argument registers in the argument register save
793 * area.
794 *
795 * Argument Extension Format:
796 *
797 * When an argument is to be stored in the stack, its type is converted to an
798 * extended type in accordance with the individual argument type. The argument
799 * is freed by the caller function after the return from the callee function is
800 * made.
801 *
802 * +-----------------------+---------------+------------------------+
803 * | Argument Type |Extended Type |Stack Storage Size(byte)|
804 * +-----------------------+---------------+------------------------+
805 * |char |int | 4 |
806 * |signed char |int | 4 |
807 * |unsigned char |int | 4 |
808 * |[signed] short int |int | 4 |
809 * |unsigned short int |int | 4 |
810 * |[signed] int |No extension | 4 |
811 * |unsigned int |No extension | 4 |
812 * |[signed] long int |No extension | 4 |
813 * |unsigned long int |No extension | 4 |
814 * |[signed] long long int |No extension | 8 |
815 * |unsigned long long int |No extension | 8 |
816 * |float |double | 8 |
817 * |double |No extension | 8 |
818 * |long double |No extension | 8 |
819 * |pointer |No extension | 4 |
820 * |struct/union |- | 4 (*1) |
821 * +-----------------------+---------------+------------------------+
822 *
823 * When a struct/union is to be delivered as an argument, the caller copies it
824 * to the local variable area and delivers the address of that area.
825 *
826 * Return Value:
827 *
828 * +-------------------------------+----------------------+
829 * |Return Value Type |Return Value Interface|
830 * +-------------------------------+----------------------+
831 * |void |None |
832 * |[signed|unsigned] char |GR8 |
833 * |[signed|unsigned] short int |GR8 |
834 * |[signed|unsigned] int |GR8 |
835 * |[signed|unsigned] long int |GR8 |
836 * |pointer |GR8 |
837 * |[signed|unsigned] long long int|GR8 & GR9 |
838 * |float |GR8 |
839 * |double |GR8 & GR9 |
840 * |long double |GR8 & GR9 |
841 * |struct/union |(*1) |
842 * +-------------------------------+----------------------+
843 *
844 * When a struct/union is used as the return value, the caller function stores
845 * the start address of the return value storage area into GR3 and then passes
846 * it to the callee function. The callee function interprets GR3 as the start
847 * address of the return value storage area. When this address needs to be
848 * saved in memory, the callee function secures the hidden parameter save area
849 * and saves the address in that area.
850 */
851
852 frv_stack_t *
853 frv_stack_info (void)
854 {
855 static frv_stack_t info, zero_info;
856 frv_stack_t *info_ptr = &info;
857 tree fndecl = current_function_decl;
858 int varargs_p = 0;
859 tree cur_arg;
860 tree next_arg;
861 int range;
862 int alignment;
863 int offset;
864
865 /* If we've already calculated the values and reload is complete, just return now */
866 if (frv_stack_cache)
867 return frv_stack_cache;
868
869 /* Zero all fields */
870 info = zero_info;
871
872 /* Set up the register range information */
873 info_ptr->regs[STACK_REGS_GPR].name = "gpr";
874 info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1;
875 info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST;
876 info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE;
877
878 info_ptr->regs[STACK_REGS_FPR].name = "fpr";
879 info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST;
880 info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST;
881 info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE;
882
883 info_ptr->regs[STACK_REGS_LR].name = "lr";
884 info_ptr->regs[STACK_REGS_LR].first = LR_REGNO;
885 info_ptr->regs[STACK_REGS_LR].last = LR_REGNO;
886 info_ptr->regs[STACK_REGS_LR].special_p = 1;
887
888 info_ptr->regs[STACK_REGS_CC].name = "cc";
889 info_ptr->regs[STACK_REGS_CC].first = CC_FIRST;
890 info_ptr->regs[STACK_REGS_CC].last = CC_LAST;
891 info_ptr->regs[STACK_REGS_CC].field_p = TRUE;
892
893 info_ptr->regs[STACK_REGS_LCR].name = "lcr";
894 info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO;
895 info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO;
896
897 info_ptr->regs[STACK_REGS_STDARG].name = "stdarg";
898 info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM;
899 info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM;
900 info_ptr->regs[STACK_REGS_STDARG].dword_p = 1;
901 info_ptr->regs[STACK_REGS_STDARG].special_p = 1;
902
903 info_ptr->regs[STACK_REGS_STRUCT].name = "struct";
904 info_ptr->regs[STACK_REGS_STRUCT].first = STRUCT_VALUE_REGNUM;
905 info_ptr->regs[STACK_REGS_STRUCT].last = STRUCT_VALUE_REGNUM;
906 info_ptr->regs[STACK_REGS_STRUCT].special_p = 1;
907
908 info_ptr->regs[STACK_REGS_FP].name = "fp";
909 info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM;
910 info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM;
911 info_ptr->regs[STACK_REGS_FP].special_p = 1;
912
913 /* Determine if this is a stdarg function. If so, allocate space to store
914 the 6 arguments. */
915 if (cfun->stdarg)
916 varargs_p = 1;
917
918 else
919 {
920 /* Find the last argument, and see if it is __builtin_va_alist. */
921 for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg)
922 {
923 next_arg = TREE_CHAIN (cur_arg);
924 if (next_arg == (tree)0)
925 {
926 if (DECL_NAME (cur_arg)
927 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist"))
928 varargs_p = 1;
929
930 break;
931 }
932 }
933 }
934
935 /* Iterate over all of the register ranges */
936 for (range = 0; range < STACK_REGS_MAX; range++)
937 {
938 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
939 int first = reg_ptr->first;
940 int last = reg_ptr->last;
941 int size_1word = 0;
942 int size_2words = 0;
943 int regno;
944
945 /* Calculate which registers need to be saved & save area size */
946 switch (range)
947 {
948 default:
949 for (regno = first; regno <= last; regno++)
950 {
951 if ((regs_ever_live[regno] && !call_used_regs[regno])
952 || (current_function_calls_eh_return
953 && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM))
954 || (flag_pic && cfun->uses_pic_offset_table && regno == PIC_REGNO))
955 {
956 info_ptr->save_p[regno] = REG_SAVE_1WORD;
957 size_1word += UNITS_PER_WORD;
958 }
959 }
960 break;
961
962 /* Calculate whether we need to create a frame after everything else
963 has been processed. */
964 case STACK_REGS_FP:
965 break;
966
967 case STACK_REGS_LR:
968 if (regs_ever_live[LR_REGNO]
969 || profile_flag
970 || frame_pointer_needed
971 || (flag_pic && cfun->uses_pic_offset_table))
972 {
973 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
974 size_1word += UNITS_PER_WORD;
975 }
976 break;
977
978 case STACK_REGS_STDARG:
979 if (varargs_p)
980 {
981 /* If this is a stdarg function with a non varardic argument split
982 between registers and the stack, adjust the saved registers
983 downward */
984 last -= (ADDR_ALIGN (cfun->pretend_args_size, UNITS_PER_WORD)
985 / UNITS_PER_WORD);
986
987 for (regno = first; regno <= last; regno++)
988 {
989 info_ptr->save_p[regno] = REG_SAVE_1WORD;
990 size_1word += UNITS_PER_WORD;
991 }
992
993 info_ptr->stdarg_size = size_1word;
994 }
995 break;
996
997 case STACK_REGS_STRUCT:
998 if (cfun->returns_struct)
999 {
1000 info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1001 size_1word += UNITS_PER_WORD;
1002 }
1003 break;
1004 }
1005
1006
1007 if (size_1word)
1008 {
1009 /* If this is a field, it only takes one word */
1010 if (reg_ptr->field_p)
1011 size_1word = UNITS_PER_WORD;
1012
1013 /* Determine which register pairs can be saved together */
1014 else if (reg_ptr->dword_p && TARGET_DWORD)
1015 {
1016 for (regno = first; regno < last; regno += 2)
1017 {
1018 if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1])
1019 {
1020 size_2words += 2 * UNITS_PER_WORD;
1021 size_1word -= 2 * UNITS_PER_WORD;
1022 info_ptr->save_p[regno] = REG_SAVE_2WORDS;
1023 info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE;
1024 }
1025 }
1026 }
1027
1028 reg_ptr->size_1word = size_1word;
1029 reg_ptr->size_2words = size_2words;
1030
1031 if (! reg_ptr->special_p)
1032 {
1033 info_ptr->regs_size_1word += size_1word;
1034 info_ptr->regs_size_2words += size_2words;
1035 }
1036 }
1037 }
1038
1039 /* Set up the sizes of each each field in the frame body, making the sizes
1040 of each be divisible by the size of a dword if dword operations might
1041 be used, or the size of a word otherwise. */
1042 alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD);
1043
1044 info_ptr->parameter_size = ADDR_ALIGN (cfun->outgoing_args_size, alignment);
1045 info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words
1046 + info_ptr->regs_size_1word,
1047 alignment);
1048 info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment);
1049
1050 info_ptr->pretend_size = cfun->pretend_args_size;
1051
1052 /* Work out the size of the frame, excluding the header. Both the frame
1053 body and register parameter area will be dword-aligned. */
1054 info_ptr->total_size
1055 = (ADDR_ALIGN (info_ptr->parameter_size
1056 + info_ptr->regs_size
1057 + info_ptr->vars_size,
1058 2 * UNITS_PER_WORD)
1059 + ADDR_ALIGN (info_ptr->pretend_size
1060 + info_ptr->stdarg_size,
1061 2 * UNITS_PER_WORD));
1062
1063 /* See if we need to create a frame at all, if so add header area. */
1064 if (info_ptr->total_size > 0
1065 || info_ptr->regs[STACK_REGS_LR].size_1word > 0
1066 || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0)
1067 {
1068 offset = info_ptr->parameter_size;
1069 info_ptr->header_size = 4 * UNITS_PER_WORD;
1070 info_ptr->total_size += 4 * UNITS_PER_WORD;
1071
1072 /* Calculate the offsets to save normal register pairs */
1073 for (range = 0; range < STACK_REGS_MAX; range++)
1074 {
1075 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1076 if (! reg_ptr->special_p)
1077 {
1078 int first = reg_ptr->first;
1079 int last = reg_ptr->last;
1080 int regno;
1081
1082 for (regno = first; regno <= last; regno++)
1083 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS
1084 && regno != FRAME_POINTER_REGNUM
1085 && (regno < FIRST_ARG_REGNUM
1086 || regno > LAST_ARG_REGNUM))
1087 {
1088 info_ptr->reg_offset[regno] = offset;
1089 offset += 2 * UNITS_PER_WORD;
1090 }
1091 }
1092 }
1093
1094 /* Calculate the offsets to save normal single registers */
1095 for (range = 0; range < STACK_REGS_MAX; range++)
1096 {
1097 frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]);
1098 if (! reg_ptr->special_p)
1099 {
1100 int first = reg_ptr->first;
1101 int last = reg_ptr->last;
1102 int regno;
1103
1104 for (regno = first; regno <= last; regno++)
1105 if (info_ptr->save_p[regno] == REG_SAVE_1WORD
1106 && regno != FRAME_POINTER_REGNUM
1107 && (regno < FIRST_ARG_REGNUM
1108 || regno > LAST_ARG_REGNUM))
1109 {
1110 info_ptr->reg_offset[regno] = offset;
1111 offset += UNITS_PER_WORD;
1112 }
1113 }
1114 }
1115
1116 /* Calculate the offset to save the local variables at. */
1117 offset = ADDR_ALIGN (offset, alignment);
1118 if (info_ptr->vars_size)
1119 {
1120 info_ptr->vars_offset = offset;
1121 offset += info_ptr->vars_size;
1122 }
1123
1124 /* Align header to a dword-boundary. */
1125 offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD);
1126
1127 /* Calculate the offsets in the fixed frame. */
1128 info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD;
1129 info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset;
1130 info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD;
1131
1132 info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD;
1133 info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD;
1134 info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD;
1135
1136 if (cfun->returns_struct)
1137 {
1138 info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD;
1139 info_ptr->reg_offset[STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD;
1140 info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD;
1141 }
1142
1143 /* Calculate the offsets to store the arguments passed in registers
1144 for stdarg functions. The register pairs are first and the single
1145 register if any is last. The register save area starts on a
1146 dword-boundary. */
1147 if (info_ptr->stdarg_size)
1148 {
1149 int first = info_ptr->regs[STACK_REGS_STDARG].first;
1150 int last = info_ptr->regs[STACK_REGS_STDARG].last;
1151 int regno;
1152
1153 /* Skip the header. */
1154 offset += 4 * UNITS_PER_WORD;
1155 for (regno = first; regno <= last; regno++)
1156 {
1157 if (info_ptr->save_p[regno] == REG_SAVE_2WORDS)
1158 {
1159 info_ptr->reg_offset[regno] = offset;
1160 offset += 2 * UNITS_PER_WORD;
1161 }
1162 else if (info_ptr->save_p[regno] == REG_SAVE_1WORD)
1163 {
1164 info_ptr->reg_offset[regno] = offset;
1165 offset += UNITS_PER_WORD;
1166 }
1167 }
1168 }
1169 }
1170
1171 if (reload_completed)
1172 frv_stack_cache = info_ptr;
1173
1174 return info_ptr;
1175 }
1176
1177 \f
1178 /* Print the information about the frv stack offsets, etc. when debugging. */
1179
1180 void
1181 frv_debug_stack (frv_stack_t *info)
1182 {
1183 int range;
1184
1185 if (!info)
1186 info = frv_stack_info ();
1187
1188 fprintf (stderr, "\nStack information for function %s:\n",
1189 ((current_function_decl && DECL_NAME (current_function_decl))
1190 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
1191 : "<unknown>"));
1192
1193 fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size);
1194 fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size);
1195 fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size);
1196 fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n",
1197 info->regs_size, info->regs_size_1word, info->regs_size_2words);
1198
1199 fprintf (stderr, "\theader_size\t= %6d\n", info->header_size);
1200 fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size);
1201 fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset);
1202 fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset);
1203
1204 for (range = 0; range < STACK_REGS_MAX; range++)
1205 {
1206 frv_stack_regs_t *regs = &(info->regs[range]);
1207 if ((regs->size_1word + regs->size_2words) > 0)
1208 {
1209 int first = regs->first;
1210 int last = regs->last;
1211 int regno;
1212
1213 fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =",
1214 regs->name, regs->size_1word + regs->size_2words,
1215 regs->size_1word, regs->size_2words);
1216
1217 for (regno = first; regno <= last; regno++)
1218 {
1219 if (info->save_p[regno] == REG_SAVE_1WORD)
1220 fprintf (stderr, " %s (%d)", reg_names[regno],
1221 info->reg_offset[regno]);
1222
1223 else if (info->save_p[regno] == REG_SAVE_2WORDS)
1224 fprintf (stderr, " %s-%s (%d)", reg_names[regno],
1225 reg_names[regno+1], info->reg_offset[regno]);
1226 }
1227
1228 fputc ('\n', stderr);
1229 }
1230 }
1231
1232 fflush (stderr);
1233 }
1234
1235
1236 \f
1237
1238 /* The following variable value is TRUE if the next output insn should
1239 finish cpu cycle. In order words the insn will have packing bit
1240 (which means absence of asm code suffix `.p' on assembler. */
1241
1242 static int frv_insn_packing_flag;
1243
1244 /* True if the current function contains a far jump. */
1245
1246 static int
1247 frv_function_contains_far_jump (void)
1248 {
1249 rtx insn = get_insns ();
1250 while (insn != NULL
1251 && !(GET_CODE (insn) == JUMP_INSN
1252 /* Ignore tablejump patterns. */
1253 && GET_CODE (PATTERN (insn)) != ADDR_VEC
1254 && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC
1255 && get_attr_far_jump (insn) == FAR_JUMP_YES))
1256 insn = NEXT_INSN (insn);
1257 return (insn != NULL);
1258 }
1259
1260 /* For the FRV, this function makes sure that a function with far jumps
1261 will return correctly. It also does the VLIW packing. */
1262
1263 static void
1264 frv_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1265 {
1266 /* If no frame was created, check whether the function uses a call
1267 instruction to implement a far jump. If so, save the link in gr3 and
1268 replace all returns to LR with returns to GR3. GR3 is used because it
1269 is call-clobbered, because is not available to the register allocator,
1270 and because all functions that take a hidden argument pointer will have
1271 a stack frame. */
1272 if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ())
1273 {
1274 rtx insn;
1275
1276 /* Just to check that the above comment is true. */
1277 if (regs_ever_live[GPR_FIRST + 3])
1278 abort ();
1279
1280 /* Generate the instruction that saves the link register. */
1281 fprintf (file, "\tmovsg lr,gr3\n");
1282
1283 /* Replace the LR with GR3 in *return_internal patterns. The insn
1284 will now return using jmpl @(gr3,0) rather than bralr. We cannot
1285 simply emit a different assembly directive because bralr and jmpl
1286 execute in different units. */
1287 for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn))
1288 if (GET_CODE (insn) == JUMP_INSN)
1289 {
1290 rtx pattern = PATTERN (insn);
1291 if (GET_CODE (pattern) == PARALLEL
1292 && XVECLEN (pattern, 0) >= 2
1293 && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN
1294 && GET_CODE (XVECEXP (pattern, 0, 1)) == USE)
1295 {
1296 rtx address = XEXP (XVECEXP (pattern, 0, 1), 0);
1297 if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO)
1298 REGNO (address) = GPR_FIRST + 3;
1299 }
1300 }
1301 }
1302
1303 frv_pack_insns ();
1304 frv_insn_packing_flag = TRUE;
1305 }
1306
1307 \f
1308 /* Return the next available temporary register in a given class. */
1309
1310 static rtx
1311 frv_alloc_temp_reg (
1312 frv_tmp_reg_t *info, /* which registers are available */
1313 enum reg_class class, /* register class desired */
1314 enum machine_mode mode, /* mode to allocate register with */
1315 int mark_as_used, /* register not available after allocation */
1316 int no_abort) /* return NULL instead of aborting */
1317 {
1318 int regno = info->next_reg[ (int)class ];
1319 int orig_regno = regno;
1320 HARD_REG_SET *reg_in_class = &reg_class_contents[ (int)class ];
1321 int i, nr;
1322
1323 for (;;)
1324 {
1325 if (TEST_HARD_REG_BIT (*reg_in_class, regno)
1326 && TEST_HARD_REG_BIT (info->regs, regno))
1327 break;
1328
1329 if (++regno >= FIRST_PSEUDO_REGISTER)
1330 regno = 0;
1331 if (regno == orig_regno)
1332 {
1333 if (no_abort)
1334 return NULL_RTX;
1335 else
1336 abort ();
1337 }
1338 }
1339
1340 nr = HARD_REGNO_NREGS (regno, mode);
1341 info->next_reg[ (int)class ] = regno + nr;
1342
1343 if (mark_as_used)
1344 for (i = 0; i < nr; i++)
1345 CLEAR_HARD_REG_BIT (info->regs, regno+i);
1346
1347 return gen_rtx_REG (mode, regno);
1348 }
1349
1350 \f
1351 /* Return an rtx with the value OFFSET, which will either be a register or a
1352 signed 12-bit integer. It can be used as the second operand in an "add"
1353 instruction, or as the index in a load or store.
1354
1355 The function returns a constant rtx if OFFSET is small enough, otherwise
1356 it loads the constant into register OFFSET_REGNO and returns that. */
1357 static rtx
1358 frv_frame_offset_rtx (int offset)
1359 {
1360 rtx offset_rtx = GEN_INT (offset);
1361 if (IN_RANGE_P (offset, -2048, 2047))
1362 return offset_rtx;
1363 else
1364 {
1365 rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO);
1366 if (IN_RANGE_P (offset, -32768, 32767))
1367 emit_insn (gen_movsi (reg_rtx, offset_rtx));
1368 else
1369 {
1370 emit_insn (gen_movsi_high (reg_rtx, offset_rtx));
1371 emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx));
1372 }
1373 return reg_rtx;
1374 }
1375 }
1376
1377 /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The
1378 prologue and epilogue uses such expressions to access the stack. */
1379 static rtx
1380 frv_frame_mem (enum machine_mode mode, rtx base, int offset)
1381 {
1382 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode,
1383 base,
1384 frv_frame_offset_rtx (offset)));
1385 }
1386
1387 /* Generate a frame-related expression:
1388
1389 (set REG (mem (plus (sp) (const_int OFFSET)))).
1390
1391 Such expressions are used in FRAME_RELATED_EXPR notes for more complex
1392 instructions. Marking the expressions as frame-related is superfluous if
1393 the note contains just a single set. But if the note contains a PARALLEL
1394 or SEQUENCE that has several sets, each set must be individually marked
1395 as frame-related. */
1396 static rtx
1397 frv_dwarf_store (rtx reg, int offset)
1398 {
1399 rtx set = gen_rtx_SET (VOIDmode,
1400 gen_rtx_MEM (GET_MODE (reg),
1401 plus_constant (stack_pointer_rtx,
1402 offset)),
1403 reg);
1404 RTX_FRAME_RELATED_P (set) = 1;
1405 return set;
1406 }
1407
1408 /* Emit a frame-related instruction whose pattern is PATTERN. The
1409 instruction is the last in a sequence that cumulatively performs the
1410 operation described by DWARF_PATTERN. The instruction is marked as
1411 frame-related and has a REG_FRAME_RELATED_EXPR note containing
1412 DWARF_PATTERN. */
1413 static void
1414 frv_frame_insn (rtx pattern, rtx dwarf_pattern)
1415 {
1416 rtx insn = emit_insn (pattern);
1417 RTX_FRAME_RELATED_P (insn) = 1;
1418 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
1419 dwarf_pattern,
1420 REG_NOTES (insn));
1421 }
1422
1423 /* Emit instructions that transfer REG to or from the memory location (sp +
1424 STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is
1425 FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this
1426 function to store registers and only the epilogue uses it to load them.
1427
1428 The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET).
1429 The generated instruction will use BASE as its base register. BASE may
1430 simply be the stack pointer, but if several accesses are being made to a
1431 region far away from the stack pointer, it may be more efficient to set
1432 up a temporary instead.
1433
1434 Store instructions will be frame-related and will be annotated with the
1435 overall effect of the store. Load instructions will be followed by a
1436 (use) to prevent later optimizations from zapping them.
1437
1438 The function takes care of the moves to and from SPRs, using TEMP_REGNO
1439 as a temporary in such cases. */
1440 static void
1441 frv_frame_access (frv_frame_accessor_t *accessor, rtx reg, int stack_offset)
1442 {
1443 enum machine_mode mode = GET_MODE (reg);
1444 rtx mem = frv_frame_mem (mode,
1445 accessor->base,
1446 stack_offset - accessor->base_offset);
1447
1448 if (accessor->op == FRV_LOAD)
1449 {
1450 if (SPR_P (REGNO (reg)))
1451 {
1452 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1453 emit_insn (gen_rtx_SET (VOIDmode, temp, mem));
1454 emit_insn (gen_rtx_SET (VOIDmode, reg, temp));
1455 }
1456 else
1457 emit_insn (gen_rtx_SET (VOIDmode, reg, mem));
1458 emit_insn (gen_rtx_USE (VOIDmode, reg));
1459 }
1460 else
1461 {
1462 if (SPR_P (REGNO (reg)))
1463 {
1464 rtx temp = gen_rtx_REG (mode, TEMP_REGNO);
1465 emit_insn (gen_rtx_SET (VOIDmode, temp, reg));
1466 frv_frame_insn (gen_rtx_SET (Pmode, mem, temp),
1467 frv_dwarf_store (reg, stack_offset));
1468 }
1469 else if (GET_MODE (reg) == DImode)
1470 {
1471 /* For DImode saves, the dwarf2 version needs to be a SEQUENCE
1472 with a separate save for each register. */
1473 rtx reg1 = gen_rtx_REG (SImode, REGNO (reg));
1474 rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1);
1475 rtx set1 = frv_dwarf_store (reg1, stack_offset);
1476 rtx set2 = frv_dwarf_store (reg2, stack_offset + 4);
1477 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1478 gen_rtx_PARALLEL (VOIDmode,
1479 gen_rtvec (2, set1, set2)));
1480 }
1481 else
1482 frv_frame_insn (gen_rtx_SET (Pmode, mem, reg),
1483 frv_dwarf_store (reg, stack_offset));
1484 }
1485 }
1486
1487 /* A function that uses frv_frame_access to transfer a group of registers to
1488 or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO
1489 is the stack information generated by frv_stack_info, and REG_SET is the
1490 number of the register set to transfer. */
1491 static void
1492 frv_frame_access_multi (frv_frame_accessor_t *accessor,
1493 frv_stack_t *info,
1494 int reg_set)
1495 {
1496 frv_stack_regs_t *regs_info;
1497 int regno;
1498
1499 regs_info = &info->regs[reg_set];
1500 for (regno = regs_info->first; regno <= regs_info->last; regno++)
1501 if (info->save_p[regno])
1502 frv_frame_access (accessor,
1503 info->save_p[regno] == REG_SAVE_2WORDS
1504 ? gen_rtx_REG (DImode, regno)
1505 : gen_rtx_REG (SImode, regno),
1506 info->reg_offset[regno]);
1507 }
1508
1509 /* Save or restore callee-saved registers that are kept outside the frame
1510 header. The function saves the registers if OP is FRV_STORE and restores
1511 them if OP is FRV_LOAD. INFO is the stack information generated by
1512 frv_stack_info. */
1513 static void
1514 frv_frame_access_standard_regs (enum frv_stack_op op, frv_stack_t *info)
1515 {
1516 frv_frame_accessor_t accessor;
1517
1518 accessor.op = op;
1519 accessor.base = stack_pointer_rtx;
1520 accessor.base_offset = 0;
1521 frv_frame_access_multi (&accessor, info, STACK_REGS_GPR);
1522 frv_frame_access_multi (&accessor, info, STACK_REGS_FPR);
1523 frv_frame_access_multi (&accessor, info, STACK_REGS_LCR);
1524 }
1525
1526
1527 /* Called after register allocation to add any instructions needed for the
1528 prologue. Using a prologue insn is favored compared to putting all of the
1529 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
1530 to intermix instructions with the saves of the caller saved registers. In
1531 some cases, it might be necessary to emit a barrier instruction as the last
1532 insn to prevent such scheduling.
1533
1534 Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
1535 so that the debug info generation code can handle them properly. */
1536 void
1537 frv_expand_prologue (void)
1538 {
1539 frv_stack_t *info = frv_stack_info ();
1540 rtx sp = stack_pointer_rtx;
1541 rtx fp = frame_pointer_rtx;
1542 frv_frame_accessor_t accessor;
1543
1544 if (TARGET_DEBUG_STACK)
1545 frv_debug_stack (info);
1546
1547 if (info->total_size == 0)
1548 return;
1549
1550 /* We're interested in three areas of the frame here:
1551
1552 A: the register save area
1553 B: the old FP
1554 C: the header after B
1555
1556 If the frame pointer isn't used, we'll have to set up A, B and C
1557 using the stack pointer. If the frame pointer is used, we'll access
1558 them as follows:
1559
1560 A: set up using sp
1561 B: set up using sp or a temporary (see below)
1562 C: set up using fp
1563
1564 We set up B using the stack pointer if the frame is small enough.
1565 Otherwise, it's more efficient to copy the old stack pointer into a
1566 temporary and use that.
1567
1568 Note that it's important to make sure the prologue and epilogue use the
1569 same registers to access A and C, since doing otherwise will confuse
1570 the aliasing code. */
1571
1572 /* Set up ACCESSOR for accessing region B above. If the frame pointer
1573 isn't used, the same method will serve for C. */
1574 accessor.op = FRV_STORE;
1575 if (frame_pointer_needed && info->total_size > 2048)
1576 {
1577 rtx insn;
1578
1579 accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO);
1580 accessor.base_offset = info->total_size;
1581 insn = emit_insn (gen_movsi (accessor.base, sp));
1582 }
1583 else
1584 {
1585 accessor.base = stack_pointer_rtx;
1586 accessor.base_offset = 0;
1587 }
1588
1589 /* Allocate the stack space. */
1590 {
1591 rtx asm_offset = frv_frame_offset_rtx (-info->total_size);
1592 rtx dwarf_offset = GEN_INT (-info->total_size);
1593
1594 frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset),
1595 gen_rtx_SET (Pmode,
1596 sp,
1597 gen_rtx_PLUS (Pmode, sp, dwarf_offset)));
1598 }
1599
1600 /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET)
1601 and point the new one to that location. */
1602 if (frame_pointer_needed)
1603 {
1604 int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1605
1606 /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is
1607 based on ACCESSOR.BASE but DWARF_SRC is always based on the stack
1608 pointer. */
1609 rtx asm_src = plus_constant (accessor.base,
1610 fp_offset - accessor.base_offset);
1611 rtx dwarf_src = plus_constant (sp, fp_offset);
1612
1613 /* Store the old frame pointer at (sp + FP_OFFSET). */
1614 frv_frame_access (&accessor, fp, fp_offset);
1615
1616 /* Set up the new frame pointer. */
1617 frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src),
1618 gen_rtx_SET (VOIDmode, fp, dwarf_src));
1619
1620 /* Access region C from the frame pointer. */
1621 accessor.base = fp;
1622 accessor.base_offset = fp_offset;
1623 }
1624
1625 /* Set up region C. */
1626 frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT);
1627 frv_frame_access_multi (&accessor, info, STACK_REGS_LR);
1628 frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG);
1629
1630 /* Set up region A. */
1631 frv_frame_access_standard_regs (FRV_STORE, info);
1632
1633 /* If this is a varargs/stdarg function, issue a blockage to prevent the
1634 scheduler from moving loads before the stores saving the registers. */
1635 if (info->stdarg_size > 0)
1636 emit_insn (gen_blockage ());
1637
1638 /* Set up pic register/small data register for this function. */
1639 if (flag_pic && cfun->uses_pic_offset_table)
1640 emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO),
1641 gen_rtx_REG (Pmode, LR_REGNO),
1642 gen_rtx_REG (SImode, OFFSET_REGNO)));
1643 }
1644
1645 \f
1646 /* Under frv, all of the work is done via frv_expand_epilogue, but
1647 this function provides a convenient place to do cleanup. */
1648
1649 static void
1650 frv_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
1651 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
1652 {
1653 frv_stack_cache = (frv_stack_t *)0;
1654
1655 /* zap last used registers for conditional execution. */
1656 memset (&frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg));
1657
1658 /* release the bitmap of created insns. */
1659 BITMAP_XFREE (frv_ifcvt.scratch_insns_bitmap);
1660 }
1661
1662 \f
1663 /* Called after register allocation to add any instructions needed for the
1664 epilogue. Using an epilogue insn is favored compared to putting all of the
1665 instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
1666 to intermix instructions with the saves of the caller saved registers. In
1667 some cases, it might be necessary to emit a barrier instruction as the last
1668 insn to prevent such scheduling.
1669
1670 If SIBCALL_P is true, the final branch back to the calling function is
1671 omitted, and is used for sibling call (aka tail call) sites. For sibcalls,
1672 we must not clobber any arguments used for parameter passing or any stack
1673 slots for arguments passed to the current function. */
1674
1675 void
1676 frv_expand_epilogue (int sibcall_p)
1677 {
1678 frv_stack_t *info = frv_stack_info ();
1679 rtx fp = frame_pointer_rtx;
1680 rtx sp = stack_pointer_rtx;
1681 rtx return_addr;
1682 int fp_offset;
1683
1684 fp_offset = info->reg_offset[FRAME_POINTER_REGNUM];
1685
1686 /* Restore the stack pointer to its original value if alloca or the like
1687 is used. */
1688 if (! current_function_sp_is_unchanging)
1689 emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset)));
1690
1691 /* Restore the callee-saved registers that were used in this function. */
1692 frv_frame_access_standard_regs (FRV_LOAD, info);
1693
1694 /* Set RETURN_ADDR to the address we should return to. Set it to NULL if
1695 no return instruction should be emitted. */
1696 if (sibcall_p)
1697 return_addr = 0;
1698 else if (info->save_p[LR_REGNO])
1699 {
1700 int lr_offset;
1701 rtx mem;
1702
1703 /* Use the same method to access the link register's slot as we did in
1704 the prologue. In other words, use the frame pointer if available,
1705 otherwise use the stack pointer.
1706
1707 LR_OFFSET is the offset of the link register's slot from the start
1708 of the frame and MEM is a memory rtx for it. */
1709 lr_offset = info->reg_offset[LR_REGNO];
1710 if (frame_pointer_needed)
1711 mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset);
1712 else
1713 mem = frv_frame_mem (Pmode, sp, lr_offset);
1714
1715 /* Load the old link register into a GPR. */
1716 return_addr = gen_rtx_REG (Pmode, TEMP_REGNO);
1717 emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem));
1718 }
1719 else
1720 return_addr = gen_rtx_REG (Pmode, LR_REGNO);
1721
1722 /* Restore the old frame pointer. Emit a USE afterwards to make sure
1723 the load is preserved. */
1724 if (frame_pointer_needed)
1725 {
1726 emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp)));
1727 emit_insn (gen_rtx_USE (VOIDmode, fp));
1728 }
1729
1730 /* Deallocate the stack frame. */
1731 if (info->total_size != 0)
1732 {
1733 rtx offset = frv_frame_offset_rtx (info->total_size);
1734 emit_insn (gen_stack_adjust (sp, sp, offset));
1735 }
1736
1737 /* If this function uses eh_return, add the final stack adjustment now. */
1738 if (current_function_calls_eh_return)
1739 emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX));
1740
1741 if (return_addr)
1742 emit_jump_insn (gen_epilogue_return (return_addr));
1743 }
1744
1745 \f
1746 /* A C compound statement that outputs the assembler code for a thunk function,
1747 used to implement C++ virtual function calls with multiple inheritance. The
1748 thunk acts as a wrapper around a virtual function, adjusting the implicit
1749 object parameter before handing control off to the real function.
1750
1751 First, emit code to add the integer DELTA to the location that contains the
1752 incoming first argument. Assume that this argument contains a pointer, and
1753 is the one used to pass the `this' pointer in C++. This is the incoming
1754 argument *before* the function prologue, e.g. `%o0' on a sparc. The
1755 addition must preserve the values of all other incoming arguments.
1756
1757 After the addition, emit code to jump to FUNCTION, which is a
1758 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch
1759 the return address. Hence returning from FUNCTION will return to whoever
1760 called the current `thunk'.
1761
1762 The effect must be as if FUNCTION had been called directly with the adjusted
1763 first argument. This macro is responsible for emitting all of the code for
1764 a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not
1765 invoked.
1766
1767 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been
1768 extracted from it.) It might possibly be useful on some targets, but
1769 probably not.
1770
1771 If you do not define this macro, the target-independent code in the C++
1772 frontend will generate a less efficient heavyweight thunk that calls
1773 FUNCTION instead of jumping to it. The generic approach does not support
1774 varargs. */
1775
1776 static void
1777 frv_asm_output_mi_thunk (FILE *file,
1778 tree thunk_fndecl ATTRIBUTE_UNUSED,
1779 HOST_WIDE_INT delta,
1780 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
1781 tree function)
1782 {
1783 const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0);
1784 const char *name_arg0 = reg_names[FIRST_ARG_REGNUM];
1785 const char *name_jmp = reg_names[JUMP_REGNO];
1786 const char *parallel = ((PACKING_FLAG_USED_P ()) ? ".p" : "");
1787
1788 /* Do the add using an addi if possible */
1789 if (IN_RANGE_P (delta, -2048, 2047))
1790 fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0);
1791 else
1792 {
1793 const char *const name_add = reg_names[TEMP_REGNO];
1794 fprintf (file, "\tsethi%s #hi(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1795 parallel, delta, name_add);
1796 fprintf (file, "\tsetlo #lo(" HOST_WIDE_INT_PRINT_DEC "),%s\n",
1797 delta, name_add);
1798 fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0);
1799 }
1800
1801 if (!flag_pic)
1802 {
1803 fprintf (file, "\tsethi%s #hi(", parallel);
1804 assemble_name (file, name_func);
1805 fprintf (file, "),%s\n", name_jmp);
1806
1807 fprintf (file, "\tsetlo #lo(");
1808 assemble_name (file, name_func);
1809 fprintf (file, "),%s\n", name_jmp);
1810 }
1811 else
1812 {
1813 /* Use JUMP_REGNO as a temporary PIC register. */
1814 const char *name_lr = reg_names[LR_REGNO];
1815 const char *name_gppic = name_jmp;
1816 const char *name_tmp = reg_names[TEMP_REGNO];
1817
1818 fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp);
1819 fprintf (file, "\tcall 1f\n");
1820 fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic);
1821 fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr);
1822 fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp);
1823 fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp);
1824 fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic);
1825
1826 fprintf (file, "\tsethi%s #gprelhi(", parallel);
1827 assemble_name (file, name_func);
1828 fprintf (file, "),%s\n", name_tmp);
1829
1830 fprintf (file, "\tsetlo #gprello(");
1831 assemble_name (file, name_func);
1832 fprintf (file, "),%s\n", name_tmp);
1833
1834 fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp);
1835 }
1836
1837 /* Jump to the function address */
1838 fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]);
1839 }
1840
1841 \f
1842 /* A C expression which is nonzero if a function must have and use a frame
1843 pointer. This expression is evaluated in the reload pass. If its value is
1844 nonzero the function will have a frame pointer.
1845
1846 The expression can in principle examine the current function and decide
1847 according to the facts, but on most machines the constant 0 or the constant
1848 1 suffices. Use 0 when the machine allows code to be generated with no
1849 frame pointer, and doing so saves some time or space. Use 1 when there is
1850 no possible advantage to avoiding a frame pointer.
1851
1852 In certain cases, the compiler does not know how to produce valid code
1853 without a frame pointer. The compiler recognizes those cases and
1854 automatically gives the function a frame pointer regardless of what
1855 `FRAME_POINTER_REQUIRED' says. You don't need to worry about them.
1856
1857 In a function that does not require a frame pointer, the frame pointer
1858 register can be allocated for ordinary usage, unless you mark it as a fixed
1859 register. See `FIXED_REGISTERS' for more information. */
1860
1861 /* On frv, create a frame whenever we need to create stack */
1862
1863 int
1864 frv_frame_pointer_required (void)
1865 {
1866 if (! current_function_is_leaf)
1867 return TRUE;
1868
1869 if (get_frame_size () != 0)
1870 return TRUE;
1871
1872 if (cfun->stdarg)
1873 return TRUE;
1874
1875 if (!current_function_sp_is_unchanging)
1876 return TRUE;
1877
1878 if (flag_pic && cfun->uses_pic_offset_table)
1879 return TRUE;
1880
1881 if (profile_flag)
1882 return TRUE;
1883
1884 if (cfun->machine->frame_needed)
1885 return TRUE;
1886
1887 return FALSE;
1888 }
1889
1890 \f
1891 /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the
1892 initial difference between the specified pair of registers. This macro must
1893 be defined if `ELIMINABLE_REGS' is defined. */
1894
1895 /* See frv_stack_info for more details on the frv stack frame. */
1896
1897 int
1898 frv_initial_elimination_offset (int from, int to)
1899 {
1900 frv_stack_t *info = frv_stack_info ();
1901 int ret = 0;
1902
1903 if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
1904 ret = info->total_size - info->pretend_size;
1905
1906 else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM)
1907 ret = info->reg_offset[FRAME_POINTER_REGNUM];
1908
1909 else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM)
1910 ret = (info->total_size
1911 - info->reg_offset[FRAME_POINTER_REGNUM]
1912 - info->pretend_size);
1913
1914 else
1915 abort ();
1916
1917 if (TARGET_DEBUG_STACK)
1918 fprintf (stderr, "Eliminate %s to %s by adding %d\n",
1919 reg_names [from], reg_names[to], ret);
1920
1921 return ret;
1922 }
1923
1924 \f
1925 /* This macro offers an alternative to using `__builtin_saveregs' and defining
1926 the macro `EXPAND_BUILTIN_SAVEREGS'. Use it to store the anonymous register
1927 arguments into the stack so that all the arguments appear to have been
1928 passed consecutively on the stack. Once this is done, you can use the
1929 standard implementation of varargs that works for machines that pass all
1930 their arguments on the stack.
1931
1932 The argument ARGS_SO_FAR is the `CUMULATIVE_ARGS' data structure, containing
1933 the values that obtain after processing of the named arguments. The
1934 arguments MODE and TYPE describe the last named argument--its machine mode
1935 and its data type as a tree node.
1936
1937 The macro implementation should do two things: first, push onto the stack
1938 all the argument registers *not* used for the named arguments, and second,
1939 store the size of the data thus pushed into the `int'-valued variable whose
1940 name is supplied as the argument PRETEND_ARGS_SIZE. The value that you
1941 store here will serve as additional offset for setting up the stack frame.
1942
1943 Because you must generate code to push the anonymous arguments at compile
1944 time without knowing their data types, `SETUP_INCOMING_VARARGS' is only
1945 useful on machines that have just a single category of argument register and
1946 use it uniformly for all data types.
1947
1948 If the argument SECOND_TIME is nonzero, it means that the arguments of the
1949 function are being analyzed for the second time. This happens for an inline
1950 function, which is not actually compiled until the end of the source file.
1951 The macro `SETUP_INCOMING_VARARGS' should not generate any instructions in
1952 this case. */
1953
1954 void
1955 frv_setup_incoming_varargs (CUMULATIVE_ARGS *cum,
1956 enum machine_mode mode,
1957 tree type ATTRIBUTE_UNUSED,
1958 int *pretend_size,
1959 int second_time)
1960 {
1961 if (TARGET_DEBUG_ARG)
1962 fprintf (stderr,
1963 "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n",
1964 *cum, GET_MODE_NAME (mode), *pretend_size, second_time);
1965 }
1966
1967 \f
1968 /* If defined, is a C expression that produces the machine-specific code for a
1969 call to `__builtin_saveregs'. This code will be moved to the very beginning
1970 of the function, before any parameter access are made. The return value of
1971 this function should be an RTX that contains the value to use as the return
1972 of `__builtin_saveregs'.
1973
1974 If this macro is not defined, the compiler will output an ordinary call to
1975 the library function `__builtin_saveregs'. */
1976
1977 rtx
1978 frv_expand_builtin_saveregs (void)
1979 {
1980 int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS;
1981
1982 if (TARGET_DEBUG_ARG)
1983 fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n",
1984 offset);
1985
1986 return gen_rtx (PLUS, Pmode, virtual_incoming_args_rtx, GEN_INT (- offset));
1987 }
1988
1989 \f
1990 /* Expand __builtin_va_start to do the va_start macro. */
1991
1992 void
1993 frv_expand_builtin_va_start (tree valist, rtx nextarg)
1994 {
1995 tree t;
1996 int num = cfun->args_info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS;
1997
1998 nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx,
1999 GEN_INT (UNITS_PER_WORD * num));
2000
2001 if (TARGET_DEBUG_ARG)
2002 {
2003 fprintf (stderr, "va_start: args_info = %d, num = %d\n",
2004 cfun->args_info, num);
2005
2006 debug_rtx (nextarg);
2007 }
2008
2009 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2010 make_tree (ptr_type_node, nextarg));
2011 TREE_SIDE_EFFECTS (t) = 1;
2012
2013 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2014 }
2015
2016 \f
2017 /* Expand __builtin_va_arg to do the va_arg macro. */
2018
2019 rtx
2020 frv_expand_builtin_va_arg (tree valist, tree type)
2021 {
2022 rtx addr;
2023 rtx mem;
2024 rtx reg;
2025
2026 if (TARGET_DEBUG_ARG)
2027 {
2028 fprintf (stderr, "va_arg:\n");
2029 debug_tree (type);
2030 }
2031
2032 if (! AGGREGATE_TYPE_P (type))
2033 return std_expand_builtin_va_arg (valist, type);
2034
2035 addr = std_expand_builtin_va_arg (valist, ptr_type_node);
2036 mem = gen_rtx_MEM (Pmode, addr);
2037 reg = gen_reg_rtx (Pmode);
2038
2039 set_mem_alias_set (mem, get_varargs_alias_set ());
2040 emit_move_insn (reg, mem);
2041
2042 return reg;
2043 }
2044
2045 \f
2046 /* Expand a block move operation, and return 1 if successful. Return 0
2047 if we should let the compiler generate normal code.
2048
2049 operands[0] is the destination
2050 operands[1] is the source
2051 operands[2] is the length
2052 operands[3] is the alignment */
2053
2054 /* Maximum number of loads to do before doing the stores */
2055 #ifndef MAX_MOVE_REG
2056 #define MAX_MOVE_REG 4
2057 #endif
2058
2059 /* Maximum number of total loads to do. */
2060 #ifndef TOTAL_MOVE_REG
2061 #define TOTAL_MOVE_REG 8
2062 #endif
2063
2064 int
2065 frv_expand_block_move (rtx operands[])
2066 {
2067 rtx orig_dest = operands[0];
2068 rtx orig_src = operands[1];
2069 rtx bytes_rtx = operands[2];
2070 rtx align_rtx = operands[3];
2071 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2072 int align;
2073 int bytes;
2074 int offset;
2075 int num_reg;
2076 int i;
2077 rtx src_reg;
2078 rtx dest_reg;
2079 rtx src_addr;
2080 rtx dest_addr;
2081 rtx src_mem;
2082 rtx dest_mem;
2083 rtx tmp_reg;
2084 rtx stores[MAX_MOVE_REG];
2085 int move_bytes;
2086 enum machine_mode mode;
2087
2088 /* If this is not a fixed size move, just call memcpy */
2089 if (! constp)
2090 return FALSE;
2091
2092 /* If this is not a fixed size alignment, abort */
2093 if (GET_CODE (align_rtx) != CONST_INT)
2094 abort ();
2095
2096 align = INTVAL (align_rtx);
2097
2098 /* Anything to move? */
2099 bytes = INTVAL (bytes_rtx);
2100 if (bytes <= 0)
2101 return TRUE;
2102
2103 /* Don't support real large moves. */
2104 if (bytes > TOTAL_MOVE_REG*align)
2105 return FALSE;
2106
2107 /* Move the address into scratch registers. */
2108 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2109 src_reg = copy_addr_to_reg (XEXP (orig_src, 0));
2110
2111 num_reg = offset = 0;
2112 for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes))
2113 {
2114 /* Calculate the correct offset for src/dest */
2115 if (offset == 0)
2116 {
2117 src_addr = src_reg;
2118 dest_addr = dest_reg;
2119 }
2120 else
2121 {
2122 src_addr = plus_constant (src_reg, offset);
2123 dest_addr = plus_constant (dest_reg, offset);
2124 }
2125
2126 /* Generate the appropriate load and store, saving the stores
2127 for later. */
2128 if (bytes >= 4 && align >= 4)
2129 mode = SImode;
2130 else if (bytes >= 2 && align >= 2)
2131 mode = HImode;
2132 else
2133 mode = QImode;
2134
2135 move_bytes = GET_MODE_SIZE (mode);
2136 tmp_reg = gen_reg_rtx (mode);
2137 src_mem = change_address (orig_src, mode, src_addr);
2138 dest_mem = change_address (orig_dest, mode, dest_addr);
2139 emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem));
2140 stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg);
2141
2142 if (num_reg >= MAX_MOVE_REG)
2143 {
2144 for (i = 0; i < num_reg; i++)
2145 emit_insn (stores[i]);
2146 num_reg = 0;
2147 }
2148 }
2149
2150 for (i = 0; i < num_reg; i++)
2151 emit_insn (stores[i]);
2152
2153 return TRUE;
2154 }
2155
2156 \f
2157 /* Expand a block clear operation, and return 1 if successful. Return 0
2158 if we should let the compiler generate normal code.
2159
2160 operands[0] is the destination
2161 operands[1] is the length
2162 operands[2] is the alignment */
2163
2164 int
2165 frv_expand_block_clear (rtx operands[])
2166 {
2167 rtx orig_dest = operands[0];
2168 rtx bytes_rtx = operands[1];
2169 rtx align_rtx = operands[2];
2170 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
2171 int align;
2172 int bytes;
2173 int offset;
2174 int num_reg;
2175 rtx dest_reg;
2176 rtx dest_addr;
2177 rtx dest_mem;
2178 int clear_bytes;
2179 enum machine_mode mode;
2180
2181 /* If this is not a fixed size move, just call memcpy */
2182 if (! constp)
2183 return FALSE;
2184
2185 /* If this is not a fixed size alignment, abort */
2186 if (GET_CODE (align_rtx) != CONST_INT)
2187 abort ();
2188
2189 align = INTVAL (align_rtx);
2190
2191 /* Anything to move? */
2192 bytes = INTVAL (bytes_rtx);
2193 if (bytes <= 0)
2194 return TRUE;
2195
2196 /* Don't support real large clears. */
2197 if (bytes > TOTAL_MOVE_REG*align)
2198 return FALSE;
2199
2200 /* Move the address into a scratch register. */
2201 dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0));
2202
2203 num_reg = offset = 0;
2204 for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes))
2205 {
2206 /* Calculate the correct offset for src/dest */
2207 dest_addr = ((offset == 0)
2208 ? dest_reg
2209 : plus_constant (dest_reg, offset));
2210
2211 /* Generate the appropriate store of gr0 */
2212 if (bytes >= 4 && align >= 4)
2213 mode = SImode;
2214 else if (bytes >= 2 && align >= 2)
2215 mode = HImode;
2216 else
2217 mode = QImode;
2218
2219 clear_bytes = GET_MODE_SIZE (mode);
2220 dest_mem = change_address (orig_dest, mode, dest_addr);
2221 emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx));
2222 }
2223
2224 return TRUE;
2225 }
2226
2227 \f
2228 /* The following variable is used to output modifiers of assembler
2229 code of the current output insn.. */
2230
2231 static rtx *frv_insn_operands;
2232
2233 /* The following function is used to add assembler insn code suffix .p
2234 if it is necessary. */
2235
2236 const char *
2237 frv_asm_output_opcode (FILE *f, const char *ptr)
2238 {
2239 int c;
2240
2241 if (! PACKING_FLAG_USED_P())
2242 return ptr;
2243
2244 for (; *ptr && *ptr != ' ' && *ptr != '\t';)
2245 {
2246 c = *ptr++;
2247 if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z')
2248 || (*ptr >= 'A' && *ptr <= 'Z')))
2249 {
2250 int letter = *ptr++;
2251
2252 c = atoi (ptr);
2253 frv_print_operand (f, frv_insn_operands [c], letter);
2254 while ((c = *ptr) >= '0' && c <= '9')
2255 ptr++;
2256 }
2257 else
2258 fputc (c, f);
2259 }
2260
2261 if (!frv_insn_packing_flag)
2262 fprintf (f, ".p");
2263
2264 return ptr;
2265 }
2266
2267 /* The following function sets up the packing bit for the current
2268 output insn. Remember that the function is not called for asm
2269 insns. */
2270
2271 void
2272 frv_final_prescan_insn (rtx insn, rtx *opvec, int noperands ATTRIBUTE_UNUSED)
2273 {
2274 if (! PACKING_FLAG_USED_P())
2275 return;
2276
2277 if (!INSN_P (insn))
2278 return;
2279
2280 frv_insn_operands = opvec;
2281
2282 /* Look for the next printable instruction. frv_pack_insns () has set
2283 things up so that any printable instruction will have TImode if it
2284 starts a new packet and VOIDmode if it should be packed with the
2285 previous instruction.
2286
2287 Printable instructions will be asm_operands or match one of the .md
2288 patterns. Since asm instructions cannot be packed -- and will
2289 therefore have TImode -- this loop terminates on any recognizable
2290 instruction, and on any unrecognizable instruction with TImode. */
2291 for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
2292 {
2293 if (NOTE_P (insn))
2294 continue;
2295 else if (!INSN_P (insn))
2296 break;
2297 else if (GET_MODE (insn) == TImode || INSN_CODE (insn) != -1)
2298 break;
2299 }
2300
2301 /* Set frv_insn_packing_flag to FALSE if the next instruction should
2302 be packed with this one. Set it to TRUE otherwise. If the next
2303 instruction is an asm instruction, this statement will set the
2304 flag to TRUE, and that value will still hold when the asm operands
2305 themselves are printed. */
2306 frv_insn_packing_flag = ! (insn && INSN_P (insn)
2307 && GET_MODE (insn) != TImode);
2308 }
2309
2310
2311 \f
2312 /* A C expression whose value is RTL representing the address in a stack frame
2313 where the pointer to the caller's frame is stored. Assume that FRAMEADDR is
2314 an RTL expression for the address of the stack frame itself.
2315
2316 If you don't define this macro, the default is to return the value of
2317 FRAMEADDR--that is, the stack frame address is also the address of the stack
2318 word that points to the previous frame. */
2319
2320 /* The default is correct, but we need to make sure the frame gets created. */
2321 rtx
2322 frv_dynamic_chain_address (rtx frame)
2323 {
2324 cfun->machine->frame_needed = 1;
2325 return frame;
2326 }
2327
2328
2329 /* A C expression whose value is RTL representing the value of the return
2330 address for the frame COUNT steps up from the current frame, after the
2331 prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame
2332 pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is
2333 defined.
2334
2335 The value of the expression must always be the correct address when COUNT is
2336 zero, but may be `NULL_RTX' if there is not way to determine the return
2337 address of other frames. */
2338
2339 rtx
2340 frv_return_addr_rtx (int count ATTRIBUTE_UNUSED, rtx frame)
2341 {
2342 cfun->machine->frame_needed = 1;
2343 return gen_rtx_MEM (Pmode, plus_constant (frame, 8));
2344 }
2345
2346 /* Given a memory reference MEMREF, interpret the referenced memory as
2347 an array of MODE values, and return a reference to the element
2348 specified by INDEX. Assume that any pre-modification implicit in
2349 MEMREF has already happened.
2350
2351 MEMREF must be a legitimate operand for modes larger than SImode.
2352 GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which
2353 this function cannot handle. */
2354 rtx
2355 frv_index_memory (rtx memref, enum machine_mode mode, int index)
2356 {
2357 rtx base = XEXP (memref, 0);
2358 if (GET_CODE (base) == PRE_MODIFY)
2359 base = XEXP (base, 0);
2360 return change_address (memref, mode,
2361 plus_constant (base, index * GET_MODE_SIZE (mode)));
2362 }
2363
2364 \f
2365 /* Print a memory address as an operand to reference that memory location. */
2366 void
2367 frv_print_operand_address (FILE * stream, rtx x)
2368 {
2369 if (GET_CODE (x) == MEM)
2370 x = XEXP (x, 0);
2371
2372 switch (GET_CODE (x))
2373 {
2374 case REG:
2375 fputs (reg_names [ REGNO (x)], stream);
2376 return;
2377
2378 case CONST_INT:
2379 fprintf (stream, "%ld", (long) INTVAL (x));
2380 return;
2381
2382 case SYMBOL_REF:
2383 assemble_name (stream, XSTR (x, 0));
2384 return;
2385
2386 case LABEL_REF:
2387 case CONST:
2388 output_addr_const (stream, x);
2389 return;
2390
2391 default:
2392 break;
2393 }
2394
2395 fatal_insn ("Bad insn to frv_print_operand_address:", x);
2396 }
2397
2398 \f
2399 static void
2400 frv_print_operand_memory_reference_reg (FILE * stream, rtx x)
2401 {
2402 int regno = true_regnum (x);
2403 if (GPR_P (regno))
2404 fputs (reg_names[regno], stream);
2405 else
2406 fatal_insn ("Bad register to frv_print_operand_memory_reference_reg:", x);
2407 }
2408
2409 /* Print a memory reference suitable for the ld/st instructions. */
2410
2411 static void
2412 frv_print_operand_memory_reference (FILE * stream, rtx x, int addr_offset)
2413 {
2414 rtx x0 = NULL_RTX;
2415 rtx x1 = NULL_RTX;
2416
2417 switch (GET_CODE (x))
2418 {
2419 case SUBREG:
2420 case REG:
2421 x0 = x;
2422 break;
2423
2424 case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */
2425 x0 = XEXP (x, 0);
2426 x1 = XEXP (XEXP (x, 1), 1);
2427 break;
2428
2429 case CONST_INT:
2430 x1 = x;
2431 break;
2432
2433 case PLUS:
2434 x0 = XEXP (x, 0);
2435 x1 = XEXP (x, 1);
2436 if (GET_CODE (x0) == CONST_INT)
2437 {
2438 x0 = XEXP (x, 1);
2439 x1 = XEXP (x, 0);
2440 }
2441 break;
2442
2443 default:
2444 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2445 break;
2446
2447 }
2448
2449 if (addr_offset)
2450 {
2451 if (!x1)
2452 x1 = const0_rtx;
2453 else if (GET_CODE (x1) != CONST_INT)
2454 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2455 }
2456
2457 fputs ("@(", stream);
2458 if (!x0)
2459 fputs (reg_names[GPR_R0], stream);
2460 else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG)
2461 frv_print_operand_memory_reference_reg (stream, x0);
2462 else
2463 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2464
2465 fputs (",", stream);
2466 if (!x1)
2467 fputs (reg_names [GPR_R0], stream);
2468
2469 else
2470 {
2471 switch (GET_CODE (x1))
2472 {
2473 case SUBREG:
2474 case REG:
2475 frv_print_operand_memory_reference_reg (stream, x1);
2476 break;
2477
2478 case CONST_INT:
2479 fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset));
2480 break;
2481
2482 case SYMBOL_REF:
2483 if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG
2484 && SYMBOL_REF_SMALL_P (x1))
2485 {
2486 fputs ("#gprel12(", stream);
2487 assemble_name (stream, XSTR (x1, 0));
2488 fputs (")", stream);
2489 }
2490 else
2491 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2492 break;
2493
2494 case CONST:
2495 if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG
2496 && const_small_data_p (x1))
2497 {
2498 fputs ("#gprel12(", stream);
2499 assemble_name (stream, XSTR (XEXP (XEXP (x1, 0), 0), 0));
2500 fprintf (stream, "+"HOST_WIDE_INT_PRINT_DEC")",
2501 INTVAL (XEXP (XEXP (x1, 0), 1)));
2502 }
2503 else
2504 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2505 break;
2506
2507 default:
2508 fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x);
2509 }
2510 }
2511
2512 fputs (")", stream);
2513 }
2514
2515 \f
2516 /* Return 2 for likely branches and 0 for non-likely branches */
2517
2518 #define FRV_JUMP_LIKELY 2
2519 #define FRV_JUMP_NOT_LIKELY 0
2520
2521 static int
2522 frv_print_operand_jump_hint (rtx insn)
2523 {
2524 rtx note;
2525 rtx labelref;
2526 int ret;
2527 HOST_WIDE_INT prob = -1;
2528 enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN;
2529
2530 if (GET_CODE (insn) != JUMP_INSN)
2531 abort ();
2532
2533 /* Assume any non-conditional jump is likely. */
2534 if (! any_condjump_p (insn))
2535 ret = FRV_JUMP_LIKELY;
2536
2537 else
2538 {
2539 labelref = condjump_label (insn);
2540 if (labelref)
2541 {
2542 rtx label = XEXP (labelref, 0);
2543 jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label))
2544 ? BACKWARD
2545 : FORWARD);
2546 }
2547
2548 note = find_reg_note (insn, REG_BR_PROB, 0);
2549 if (!note)
2550 ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY);
2551
2552 else
2553 {
2554 prob = INTVAL (XEXP (note, 0));
2555 ret = ((prob >= (REG_BR_PROB_BASE / 2))
2556 ? FRV_JUMP_LIKELY
2557 : FRV_JUMP_NOT_LIKELY);
2558 }
2559 }
2560
2561 #if 0
2562 if (TARGET_DEBUG)
2563 {
2564 char *direction;
2565
2566 switch (jump_type)
2567 {
2568 default:
2569 case UNKNOWN: direction = "unknown jump direction"; break;
2570 case BACKWARD: direction = "jump backward"; break;
2571 case FORWARD: direction = "jump forward"; break;
2572 }
2573
2574 fprintf (stderr,
2575 "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n",
2576 IDENTIFIER_POINTER (DECL_NAME (current_function_decl)),
2577 (long)INSN_UID (insn), direction, (long)prob,
2578 (long)REG_BR_PROB_BASE, ret);
2579 }
2580 #endif
2581
2582 return ret;
2583 }
2584
2585 \f
2586 /* Print an operand to an assembler instruction.
2587
2588 `%' followed by a letter and a digit says to output an operand in an
2589 alternate fashion. Four letters have standard, built-in meanings described
2590 below. The machine description macro `PRINT_OPERAND' can define additional
2591 letters with nonstandard meanings.
2592
2593 `%cDIGIT' can be used to substitute an operand that is a constant value
2594 without the syntax that normally indicates an immediate operand.
2595
2596 `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated
2597 before printing.
2598
2599 `%aDIGIT' can be used to substitute an operand as if it were a memory
2600 reference, with the actual operand treated as the address. This may be
2601 useful when outputting a "load address" instruction, because often the
2602 assembler syntax for such an instruction requires you to write the operand
2603 as if it were a memory reference.
2604
2605 `%lDIGIT' is used to substitute a `label_ref' into a jump instruction.
2606
2607 `%=' outputs a number which is unique to each instruction in the entire
2608 compilation. This is useful for making local labels to be referred to more
2609 than once in a single template that generates multiple assembler
2610 instructions.
2611
2612 `%' followed by a punctuation character specifies a substitution that does
2613 not use an operand. Only one case is standard: `%%' outputs a `%' into the
2614 assembler code. Other nonstandard cases can be defined in the
2615 `PRINT_OPERAND' macro. You must also define which punctuation characters
2616 are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */
2617
2618 void
2619 frv_print_operand (FILE * file, rtx x, int code)
2620 {
2621 HOST_WIDE_INT value;
2622 int offset;
2623
2624 if (code != 0 && !isalpha (code))
2625 value = 0;
2626
2627 else if (GET_CODE (x) == CONST_INT)
2628 value = INTVAL (x);
2629
2630 else if (GET_CODE (x) == CONST_DOUBLE)
2631 {
2632 if (GET_MODE (x) == SFmode)
2633 {
2634 REAL_VALUE_TYPE rv;
2635 long l;
2636
2637 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
2638 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2639 value = l;
2640 }
2641
2642 else if (GET_MODE (x) == VOIDmode)
2643 value = CONST_DOUBLE_LOW (x);
2644
2645 else
2646 fatal_insn ("Bad insn in frv_print_operand, bad const_double", x);
2647 }
2648
2649 else
2650 value = 0;
2651
2652 switch (code)
2653 {
2654
2655 case '.':
2656 /* Output r0 */
2657 fputs (reg_names[GPR_R0], file);
2658 break;
2659
2660 case '#':
2661 fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn));
2662 break;
2663
2664 case '@':
2665 /* Output small data area base register (gr16). */
2666 fputs (reg_names[SDA_BASE_REG], file);
2667 break;
2668
2669 case '~':
2670 /* Output pic register (gr17). */
2671 fputs (reg_names[PIC_REGNO], file);
2672 break;
2673
2674 case '*':
2675 /* Output the temporary integer CCR register */
2676 fputs (reg_names[ICR_TEMP], file);
2677 break;
2678
2679 case '&':
2680 /* Output the temporary integer CC register */
2681 fputs (reg_names[ICC_TEMP], file);
2682 break;
2683
2684 /* case 'a': print an address */
2685
2686 case 'C':
2687 /* Print appropriate test for integer branch false operation */
2688 switch (GET_CODE (x))
2689 {
2690 default:
2691 fatal_insn ("Bad insn to frv_print_operand, 'C' modifier:", x);
2692
2693 case EQ: fputs ("ne", file); break;
2694 case NE: fputs ("eq", file); break;
2695 case LT: fputs ("ge", file); break;
2696 case LE: fputs ("gt", file); break;
2697 case GT: fputs ("le", file); break;
2698 case GE: fputs ("lt", file); break;
2699 case LTU: fputs ("nc", file); break;
2700 case LEU: fputs ("hi", file); break;
2701 case GTU: fputs ("ls", file); break;
2702 case GEU: fputs ("c", file); break;
2703 }
2704 break;
2705
2706 /* case 'c': print a constant without the constant prefix. If
2707 CONSTANT_ADDRESS_P(x) is not true, PRINT_OPERAND is called. */
2708
2709 case 'c':
2710 /* Print appropriate test for integer branch true operation */
2711 switch (GET_CODE (x))
2712 {
2713 default:
2714 fatal_insn ("Bad insn to frv_print_operand, 'c' modifier:", x);
2715
2716 case EQ: fputs ("eq", file); break;
2717 case NE: fputs ("ne", file); break;
2718 case LT: fputs ("lt", file); break;
2719 case LE: fputs ("le", file); break;
2720 case GT: fputs ("gt", file); break;
2721 case GE: fputs ("ge", file); break;
2722 case LTU: fputs ("c", file); break;
2723 case LEU: fputs ("ls", file); break;
2724 case GTU: fputs ("hi", file); break;
2725 case GEU: fputs ("nc", file); break;
2726 }
2727 break;
2728
2729 case 'e':
2730 /* Print 1 for a NE and 0 for an EQ to give the final argument
2731 for a conditional instruction. */
2732 if (GET_CODE (x) == NE)
2733 fputs ("1", file);
2734
2735 else if (GET_CODE (x) == EQ)
2736 fputs ("0", file);
2737
2738 else
2739 fatal_insn ("Bad insn to frv_print_operand, 'e' modifier:", x);
2740 break;
2741
2742 case 'F':
2743 /* Print appropriate test for floating point branch false operation */
2744 switch (GET_CODE (x))
2745 {
2746 default:
2747 fatal_insn ("Bad insn to frv_print_operand, 'F' modifier:", x);
2748
2749 case EQ: fputs ("ne", file); break;
2750 case NE: fputs ("eq", file); break;
2751 case LT: fputs ("uge", file); break;
2752 case LE: fputs ("ug", file); break;
2753 case GT: fputs ("ule", file); break;
2754 case GE: fputs ("ul", file); break;
2755 }
2756 break;
2757
2758 case 'f':
2759 /* Print appropriate test for floating point branch true operation */
2760 switch (GET_CODE (x))
2761 {
2762 default:
2763 fatal_insn ("Bad insn to frv_print_operand, 'f' modifier:", x);
2764
2765 case EQ: fputs ("eq", file); break;
2766 case NE: fputs ("ne", file); break;
2767 case LT: fputs ("lt", file); break;
2768 case LE: fputs ("le", file); break;
2769 case GT: fputs ("gt", file); break;
2770 case GE: fputs ("ge", file); break;
2771 }
2772 break;
2773
2774 case 'I':
2775 /* Print 'i' if the operand is a constant, or is a memory reference that
2776 adds a constant */
2777 if (GET_CODE (x) == MEM)
2778 x = ((GET_CODE (XEXP (x, 0)) == PLUS)
2779 ? XEXP (XEXP (x, 0), 1)
2780 : XEXP (x, 0));
2781
2782 switch (GET_CODE (x))
2783 {
2784 default:
2785 break;
2786
2787 case CONST_INT:
2788 case SYMBOL_REF:
2789 case CONST:
2790 fputs ("i", file);
2791 break;
2792 }
2793 break;
2794
2795 case 'i':
2796 /* For jump instructions, print 'i' if the operand is a constant or
2797 is an expression that adds a constant */
2798 if (GET_CODE (x) == CONST_INT)
2799 fputs ("i", file);
2800
2801 else
2802 {
2803 if (GET_CODE (x) == CONST_INT
2804 || (GET_CODE (x) == PLUS
2805 && (GET_CODE (XEXP (x, 1)) == CONST_INT
2806 || GET_CODE (XEXP (x, 0)) == CONST_INT)))
2807 fputs ("i", file);
2808 }
2809 break;
2810
2811 case 'L':
2812 /* Print the lower register of a double word register pair */
2813 if (GET_CODE (x) == REG)
2814 fputs (reg_names[ REGNO (x)+1 ], file);
2815 else
2816 fatal_insn ("Bad insn to frv_print_operand, 'L' modifier:", x);
2817 break;
2818
2819 /* case 'l': print a LABEL_REF */
2820
2821 case 'M':
2822 case 'N':
2823 /* Print a memory reference for ld/st/jmp, %N prints a memory reference
2824 for the second word of double memory operations. */
2825 offset = (code == 'M') ? 0 : UNITS_PER_WORD;
2826 switch (GET_CODE (x))
2827 {
2828 default:
2829 fatal_insn ("Bad insn to frv_print_operand, 'M/N' modifier:", x);
2830
2831 case MEM:
2832 frv_print_operand_memory_reference (file, XEXP (x, 0), offset);
2833 break;
2834
2835 case REG:
2836 case SUBREG:
2837 case CONST_INT:
2838 case PLUS:
2839 case SYMBOL_REF:
2840 frv_print_operand_memory_reference (file, x, offset);
2841 break;
2842 }
2843 break;
2844
2845 case 'O':
2846 /* Print the opcode of a command. */
2847 switch (GET_CODE (x))
2848 {
2849 default:
2850 fatal_insn ("Bad insn to frv_print_operand, 'O' modifier:", x);
2851
2852 case PLUS: fputs ("add", file); break;
2853 case MINUS: fputs ("sub", file); break;
2854 case AND: fputs ("and", file); break;
2855 case IOR: fputs ("or", file); break;
2856 case XOR: fputs ("xor", file); break;
2857 case ASHIFT: fputs ("sll", file); break;
2858 case ASHIFTRT: fputs ("sra", file); break;
2859 case LSHIFTRT: fputs ("srl", file); break;
2860 }
2861 break;
2862
2863 /* case 'n': negate and print a constant int */
2864
2865 case 'P':
2866 /* Print PIC label using operand as the number. */
2867 if (GET_CODE (x) != CONST_INT)
2868 fatal_insn ("Bad insn to frv_print_operand, P modifier:", x);
2869
2870 fprintf (file, ".LCF%ld", (long)INTVAL (x));
2871 break;
2872
2873 case 'U':
2874 /* Print 'u' if the operand is a update load/store */
2875 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
2876 fputs ("u", file);
2877 break;
2878
2879 case 'z':
2880 /* If value is 0, print gr0, otherwise it must be a register */
2881 if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0)
2882 fputs (reg_names[GPR_R0], file);
2883
2884 else if (GET_CODE (x) == REG)
2885 fputs (reg_names [REGNO (x)], file);
2886
2887 else
2888 fatal_insn ("Bad insn in frv_print_operand, z case", x);
2889 break;
2890
2891 case 'x':
2892 /* Print constant in hex */
2893 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2894 {
2895 fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value);
2896 break;
2897 }
2898
2899 /* fall through */
2900
2901 case '\0':
2902 if (GET_CODE (x) == REG)
2903 fputs (reg_names [REGNO (x)], file);
2904
2905 else if (GET_CODE (x) == CONST_INT
2906 || GET_CODE (x) == CONST_DOUBLE)
2907 fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value);
2908
2909 else if (GET_CODE (x) == MEM)
2910 frv_print_operand_address (file, XEXP (x, 0));
2911
2912 else if (CONSTANT_ADDRESS_P (x))
2913 frv_print_operand_address (file, x);
2914
2915 else
2916 fatal_insn ("Bad insn in frv_print_operand, 0 case", x);
2917
2918 break;
2919
2920 default:
2921 fatal_insn ("frv_print_operand: unknown code", x);
2922 break;
2923 }
2924
2925 return;
2926 }
2927
2928 \f
2929 /* A C statement (sans semicolon) for initializing the variable CUM for the
2930 state at the beginning of the argument list. The variable has type
2931 `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type
2932 of the function which will receive the args, or 0 if the args are to a
2933 compiler support library function. The value of INDIRECT is nonzero when
2934 processing an indirect call, for example a call through a function pointer.
2935 The value of INDIRECT is zero for a call to an explicitly named function, a
2936 library function call, or when `INIT_CUMULATIVE_ARGS' is used to find
2937 arguments for the function being compiled.
2938
2939 When processing a call to a compiler support library function, LIBNAME
2940 identifies which one. It is a `symbol_ref' rtx which contains the name of
2941 the function, as a string. LIBNAME is 0 when an ordinary C function call is
2942 being processed. Thus, each time this macro is called, either LIBNAME or
2943 FNTYPE is nonzero, but never both of them at once. */
2944
2945 void
2946 frv_init_cumulative_args (CUMULATIVE_ARGS *cum,
2947 tree fntype,
2948 rtx libname,
2949 tree fndecl,
2950 int incoming)
2951 {
2952 *cum = FIRST_ARG_REGNUM;
2953
2954 if (TARGET_DEBUG_ARG)
2955 {
2956 fprintf (stderr, "\ninit_cumulative_args:");
2957 if (!fndecl && fntype)
2958 fputs (" indirect", stderr);
2959
2960 if (incoming)
2961 fputs (" incoming", stderr);
2962
2963 if (fntype)
2964 {
2965 tree ret_type = TREE_TYPE (fntype);
2966 fprintf (stderr, " return=%s,",
2967 tree_code_name[ (int)TREE_CODE (ret_type) ]);
2968 }
2969
2970 if (libname && GET_CODE (libname) == SYMBOL_REF)
2971 fprintf (stderr, " libname=%s", XSTR (libname, 0));
2972
2973 if (cfun->returns_struct)
2974 fprintf (stderr, " return-struct");
2975
2976 putc ('\n', stderr);
2977 }
2978 }
2979
2980 \f
2981 /* If defined, a C expression that gives the alignment boundary, in bits, of an
2982 argument with the specified mode and type. If it is not defined,
2983 `PARM_BOUNDARY' is used for all arguments. */
2984
2985 int
2986 frv_function_arg_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
2987 tree type ATTRIBUTE_UNUSED)
2988 {
2989 return BITS_PER_WORD;
2990 }
2991
2992 \f
2993 /* A C expression that controls whether a function argument is passed in a
2994 register, and which register.
2995
2996 The arguments are CUM, of type CUMULATIVE_ARGS, which summarizes (in a way
2997 defined by INIT_CUMULATIVE_ARGS and FUNCTION_ARG_ADVANCE) all of the previous
2998 arguments so far passed in registers; MODE, the machine mode of the argument;
2999 TYPE, the data type of the argument as a tree node or 0 if that is not known
3000 (which happens for C support library functions); and NAMED, which is 1 for an
3001 ordinary argument and 0 for nameless arguments that correspond to `...' in the
3002 called function's prototype.
3003
3004 The value of the expression should either be a `reg' RTX for the hard
3005 register in which to pass the argument, or zero to pass the argument on the
3006 stack.
3007
3008 For machines like the VAX and 68000, where normally all arguments are
3009 pushed, zero suffices as a definition.
3010
3011 The usual way to make the ANSI library `stdarg.h' work on a machine where
3012 some arguments are usually passed in registers, is to cause nameless
3013 arguments to be passed on the stack instead. This is done by making
3014 `FUNCTION_ARG' return 0 whenever NAMED is 0.
3015
3016 You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the definition of
3017 this macro to determine if this argument is of a type that must be passed in
3018 the stack. If `REG_PARM_STACK_SPACE' is not defined and `FUNCTION_ARG'
3019 returns nonzero for such an argument, the compiler will abort. If
3020 `REG_PARM_STACK_SPACE' is defined, the argument will be computed in the
3021 stack and then loaded into a register. */
3022
3023 rtx
3024 frv_function_arg (CUMULATIVE_ARGS *cum,
3025 enum machine_mode mode,
3026 tree type ATTRIBUTE_UNUSED,
3027 int named,
3028 int incoming ATTRIBUTE_UNUSED)
3029 {
3030 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3031 int arg_num = *cum;
3032 rtx ret;
3033 const char *debstr;
3034
3035 /* Return a marker for use in the call instruction. */
3036 if (xmode == VOIDmode)
3037 {
3038 ret = const0_rtx;
3039 debstr = "<0>";
3040 }
3041
3042 else if (arg_num <= LAST_ARG_REGNUM)
3043 {
3044 ret = gen_rtx (REG, xmode, arg_num);
3045 debstr = reg_names[arg_num];
3046 }
3047
3048 else
3049 {
3050 ret = NULL_RTX;
3051 debstr = "memory";
3052 }
3053
3054 if (TARGET_DEBUG_ARG)
3055 fprintf (stderr,
3056 "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n",
3057 arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr);
3058
3059 return ret;
3060 }
3061
3062 \f
3063 /* A C statement (sans semicolon) to update the summarizer variable CUM to
3064 advance past an argument in the argument list. The values MODE, TYPE and
3065 NAMED describe that argument. Once this is done, the variable CUM is
3066 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
3067
3068 This macro need not do anything if the argument in question was passed on
3069 the stack. The compiler knows how to track the amount of stack space used
3070 for arguments without any special help. */
3071
3072 void
3073 frv_function_arg_advance (CUMULATIVE_ARGS *cum,
3074 enum machine_mode mode,
3075 tree type ATTRIBUTE_UNUSED,
3076 int named)
3077 {
3078 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3079 int bytes = GET_MODE_SIZE (xmode);
3080 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3081 int arg_num = *cum;
3082
3083 *cum = arg_num + words;
3084
3085 if (TARGET_DEBUG_ARG)
3086 fprintf (stderr,
3087 "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n",
3088 arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD);
3089 }
3090
3091 \f
3092 /* A C expression for the number of words, at the beginning of an argument,
3093 must be put in registers. The value must be zero for arguments that are
3094 passed entirely in registers or that are entirely pushed on the stack.
3095
3096 On some machines, certain arguments must be passed partially in registers
3097 and partially in memory. On these machines, typically the first N words of
3098 arguments are passed in registers, and the rest on the stack. If a
3099 multi-word argument (a `double' or a structure) crosses that boundary, its
3100 first few words must be passed in registers and the rest must be pushed.
3101 This macro tells the compiler when this occurs, and how many of the words
3102 should go in registers.
3103
3104 `FUNCTION_ARG' for these arguments should return the first register to be
3105 used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for
3106 the called function. */
3107
3108 int
3109 frv_function_arg_partial_nregs (CUMULATIVE_ARGS *cum,
3110 enum machine_mode mode,
3111 tree type ATTRIBUTE_UNUSED,
3112 int named ATTRIBUTE_UNUSED)
3113 {
3114 enum machine_mode xmode = (mode == BLKmode) ? SImode : mode;
3115 int bytes = GET_MODE_SIZE (xmode);
3116 int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3117 int arg_num = *cum;
3118 int ret;
3119
3120 ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1)
3121 ? LAST_ARG_REGNUM - arg_num + 1
3122 : 0);
3123
3124 if (TARGET_DEBUG_ARG && ret)
3125 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3126
3127 return ret;
3128
3129 }
3130
3131 \f
3132
3133 /* A C expression that indicates when an argument must be passed by reference.
3134 If nonzero for an argument, a copy of that argument is made in memory and a
3135 pointer to the argument is passed instead of the argument itself. The
3136 pointer is passed in whatever way is appropriate for passing a pointer to
3137 that type.
3138
3139 On machines where `REG_PARM_STACK_SPACE' is not defined, a suitable
3140 definition of this macro might be
3141 #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) \
3142 MUST_PASS_IN_STACK (MODE, TYPE) */
3143
3144 int
3145 frv_function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
3146 enum machine_mode mode,
3147 tree type,
3148 int named ATTRIBUTE_UNUSED)
3149 {
3150 return MUST_PASS_IN_STACK (mode, type);
3151 }
3152
3153 /* If defined, a C expression that indicates when it is the called function's
3154 responsibility to make a copy of arguments passed by invisible reference.
3155 Normally, the caller makes a copy and passes the address of the copy to the
3156 routine being called. When FUNCTION_ARG_CALLEE_COPIES is defined and is
3157 nonzero, the caller does not make a copy. Instead, it passes a pointer to
3158 the "live" value. The called function must not modify this value. If it
3159 can be determined that the value won't be modified, it need not make a copy;
3160 otherwise a copy must be made. */
3161
3162 int
3163 frv_function_arg_callee_copies (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
3164 enum machine_mode mode ATTRIBUTE_UNUSED,
3165 tree type ATTRIBUTE_UNUSED,
3166 int named ATTRIBUTE_UNUSED)
3167 {
3168 return 0;
3169 }
3170
3171 /* If defined, a C expression that indicates when it is more desirable to keep
3172 an argument passed by invisible reference as a reference, rather than
3173 copying it to a pseudo register. */
3174
3175 int
3176 frv_function_arg_keep_as_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
3177 enum machine_mode mode ATTRIBUTE_UNUSED,
3178 tree type ATTRIBUTE_UNUSED,
3179 int named ATTRIBUTE_UNUSED)
3180 {
3181 return 0;
3182 }
3183
3184 \f
3185 /* Return true if a register is ok to use as a base or index register. */
3186
3187 static FRV_INLINE int
3188 frv_regno_ok_for_base_p (int regno, int strict_p)
3189 {
3190 if (GPR_P (regno))
3191 return TRUE;
3192
3193 if (strict_p)
3194 return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno]));
3195
3196 if (regno == ARG_POINTER_REGNUM)
3197 return TRUE;
3198
3199 return (regno >= FIRST_PSEUDO_REGISTER);
3200 }
3201
3202 \f
3203 /* A C compound statement with a conditional `goto LABEL;' executed if X (an
3204 RTX) is a legitimate memory address on the target machine for a memory
3205 operand of mode MODE.
3206
3207 It usually pays to define several simpler macros to serve as subroutines for
3208 this one. Otherwise it may be too complicated to understand.
3209
3210 This macro must exist in two variants: a strict variant and a non-strict
3211 one. The strict variant is used in the reload pass. It must be defined so
3212 that any pseudo-register that has not been allocated a hard register is
3213 considered a memory reference. In contexts where some kind of register is
3214 required, a pseudo-register with no hard register must be rejected.
3215
3216 The non-strict variant is used in other passes. It must be defined to
3217 accept all pseudo-registers in every context where some kind of register is
3218 required.
3219
3220 Compiler source files that want to use the strict variant of this macro
3221 define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT'
3222 conditional to define the strict variant in that case and the non-strict
3223 variant otherwise.
3224
3225 Subroutines to check for acceptable registers for various purposes (one for
3226 base registers, one for index registers, and so on) are typically among the
3227 subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these
3228 subroutine macros need have two variants; the higher levels of macros may be
3229 the same whether strict or not.
3230
3231 Normally, constant addresses which are the sum of a `symbol_ref' and an
3232 integer are stored inside a `const' RTX to mark them as constant.
3233 Therefore, there is no need to recognize such sums specifically as
3234 legitimate addresses. Normally you would simply recognize any `const' as
3235 legitimate.
3236
3237 Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that
3238 are not marked with `const'. It assumes that a naked `plus' indicates
3239 indexing. If so, then you *must* reject such naked constant sums as
3240 illegitimate addresses, so that none of them will be given to
3241 `PRINT_OPERAND_ADDRESS'.
3242
3243 On some machines, whether a symbolic address is legitimate depends on the
3244 section that the address refers to. On these machines, define the macro
3245 `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and
3246 then check for it here. When you see a `const', you will have to look
3247 inside it to find the `symbol_ref' in order to determine the section.
3248
3249 The best way to modify the name string is by adding text to the beginning,
3250 with suitable punctuation to prevent any ambiguity. Allocate the new name
3251 in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to
3252 remove and decode the added text and output the name accordingly, and define
3253 `(* targetm.strip_name_encoding)' to access the original name string.
3254
3255 You can check the information stored here into the `symbol_ref' in the
3256 definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and
3257 `PRINT_OPERAND_ADDRESS'. */
3258
3259 int
3260 frv_legitimate_address_p (enum machine_mode mode,
3261 rtx x,
3262 int strict_p,
3263 int condexec_p)
3264 {
3265 rtx x0, x1;
3266 int ret = 0;
3267 HOST_WIDE_INT value;
3268 unsigned regno0;
3269
3270 switch (GET_CODE (x))
3271 {
3272 default:
3273 break;
3274
3275 case SUBREG:
3276 x = SUBREG_REG (x);
3277 if (GET_CODE (x) != REG)
3278 break;
3279
3280 /* fall through */
3281
3282 case REG:
3283 ret = frv_regno_ok_for_base_p (REGNO (x), strict_p);
3284 break;
3285
3286 case PRE_MODIFY:
3287 x0 = XEXP (x, 0);
3288 x1 = XEXP (x, 1);
3289 if (GET_CODE (x0) != REG
3290 || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p)
3291 || GET_CODE (x1) != PLUS
3292 || ! rtx_equal_p (x0, XEXP (x1, 0))
3293 || GET_CODE (XEXP (x1, 1)) != REG
3294 || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p))
3295 break;
3296
3297 ret = 1;
3298 break;
3299
3300 case CONST_INT:
3301 /* 12 bit immediate */
3302 if (condexec_p)
3303 ret = FALSE;
3304 else
3305 {
3306 ret = IN_RANGE_P (INTVAL (x), -2048, 2047);
3307
3308 /* If we can't use load/store double operations, make sure we can
3309 address the second word. */
3310 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3311 ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1,
3312 -2048, 2047);
3313 }
3314 break;
3315
3316 case PLUS:
3317 x0 = XEXP (x, 0);
3318 x1 = XEXP (x, 1);
3319
3320 if (GET_CODE (x0) == SUBREG)
3321 x0 = SUBREG_REG (x0);
3322
3323 if (GET_CODE (x0) != REG)
3324 break;
3325
3326 regno0 = REGNO (x0);
3327 if (!frv_regno_ok_for_base_p (regno0, strict_p))
3328 break;
3329
3330 switch (GET_CODE (x1))
3331 {
3332 default:
3333 break;
3334
3335 case SUBREG:
3336 x1 = SUBREG_REG (x1);
3337 if (GET_CODE (x1) != REG)
3338 break;
3339
3340 /* fall through */
3341
3342 case REG:
3343 /* Do not allow reg+reg addressing for modes > 1 word if we can't depend
3344 on having move double instructions */
3345 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3346 ret = FALSE;
3347 else
3348 ret = frv_regno_ok_for_base_p (REGNO (x1), strict_p);
3349 break;
3350
3351 case CONST_INT:
3352 /* 12 bit immediate */
3353 if (condexec_p)
3354 ret = FALSE;
3355 else
3356 {
3357 value = INTVAL (x1);
3358 ret = IN_RANGE_P (value, -2048, 2047);
3359
3360 /* If we can't use load/store double operations, make sure we can
3361 address the second word. */
3362 if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
3363 ret = IN_RANGE_P (value + GET_MODE_SIZE (mode) - 1, -2048, 2047);
3364 }
3365 break;
3366
3367 case SYMBOL_REF:
3368 if (!condexec_p
3369 && regno0 == SDA_BASE_REG
3370 && SYMBOL_REF_SMALL_P (x1))
3371 ret = TRUE;
3372 break;
3373
3374 case CONST:
3375 if (!condexec_p && regno0 == SDA_BASE_REG && const_small_data_p (x1))
3376 ret = TRUE;
3377 break;
3378
3379 }
3380 break;
3381 }
3382
3383 if (TARGET_DEBUG_ADDR)
3384 {
3385 fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict%s\n",
3386 GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ",
3387 (condexec_p) ? ", inside conditional code" : "");
3388 debug_rtx (x);
3389 }
3390
3391 return ret;
3392 }
3393
3394 \f
3395 /* A C compound statement that attempts to replace X with a valid memory
3396 address for an operand of mode MODE. WIN will be a C statement label
3397 elsewhere in the code; the macro definition may use
3398
3399 GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN);
3400
3401 to avoid further processing if the address has become legitimate.
3402
3403 X will always be the result of a call to `break_out_memory_refs', and OLDX
3404 will be the operand that was given to that function to produce X.
3405
3406 The code generated by this macro should not alter the substructure of X. If
3407 it transforms X into a more legitimate form, it should assign X (which will
3408 always be a C variable) a new value.
3409
3410 It is not necessary for this macro to come up with a legitimate address.
3411 The compiler has standard ways of doing so in all cases. In fact, it is
3412 safe for this macro to do nothing. But often a machine-dependent strategy
3413 can generate better code. */
3414
3415 rtx
3416 frv_legitimize_address (rtx x,
3417 rtx oldx ATTRIBUTE_UNUSED,
3418 enum machine_mode mode ATTRIBUTE_UNUSED)
3419 {
3420 rtx ret = NULL_RTX;
3421
3422 /* Don't try to legitimize addresses if we are not optimizing, since the
3423 address we generate is not a general operand, and will horribly mess
3424 things up when force_reg is called to try and put it in a register because
3425 we aren't optimizing. */
3426 if (optimize
3427 && ((GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_SMALL_P (x))
3428 || (GET_CODE (x) == CONST && const_small_data_p (x))))
3429 {
3430 ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, SDA_BASE_REG), x);
3431 if (flag_pic)
3432 cfun->uses_pic_offset_table = TRUE;
3433 }
3434
3435 if (TARGET_DEBUG_ADDR && ret != NULL_RTX)
3436 {
3437 fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, mode = %s, modified address\n",
3438 GET_MODE_NAME (mode));
3439 debug_rtx (ret);
3440 }
3441
3442 return ret;
3443 }
3444
3445 /* Return 1 if operand is a valid FRV address. CONDEXEC_P is true if
3446 the operand is used by a predicated instruction. */
3447
3448 static int
3449 frv_legitimate_memory_operand (rtx op, enum machine_mode mode, int condexec_p)
3450 {
3451 return ((GET_MODE (op) == mode || mode == VOIDmode)
3452 && GET_CODE (op) == MEM
3453 && frv_legitimate_address_p (mode, XEXP (op, 0),
3454 reload_completed, condexec_p));
3455 }
3456
3457 \f
3458 /* Return 1 is OP is a memory operand, or will be turned into one by
3459 reload. */
3460
3461 int
3462 frv_load_operand (rtx op, enum machine_mode mode)
3463 {
3464 if (GET_MODE (op) != mode && mode != VOIDmode)
3465 return FALSE;
3466
3467 if (reload_in_progress)
3468 {
3469 rtx tmp = op;
3470 if (GET_CODE (tmp) == SUBREG)
3471 tmp = SUBREG_REG (tmp);
3472 if (GET_CODE (tmp) == REG
3473 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
3474 op = reg_equiv_memory_loc[REGNO (tmp)];
3475 }
3476
3477 return op && memory_operand (op, mode);
3478 }
3479
3480
3481 /* Return 1 if operand is a GPR register or a FPR register. */
3482
3483 int
3484 gpr_or_fpr_operand (rtx op, enum machine_mode mode)
3485 {
3486 int regno;
3487
3488 if (GET_MODE (op) != mode && mode != VOIDmode)
3489 return FALSE;
3490
3491 if (GET_CODE (op) == SUBREG)
3492 {
3493 if (GET_CODE (SUBREG_REG (op)) != REG)
3494 return register_operand (op, mode);
3495
3496 op = SUBREG_REG (op);
3497 }
3498
3499 if (GET_CODE (op) != REG)
3500 return FALSE;
3501
3502 regno = REGNO (op);
3503 if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER)
3504 return TRUE;
3505
3506 return FALSE;
3507 }
3508
3509 /* Return 1 if operand is a GPR register or 12 bit signed immediate. */
3510
3511 int
3512 gpr_or_int12_operand (rtx op, enum machine_mode mode)
3513 {
3514 if (GET_CODE (op) == CONST_INT)
3515 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3516
3517 if (GET_MODE (op) != mode && mode != VOIDmode)
3518 return FALSE;
3519
3520 if (GET_CODE (op) == SUBREG)
3521 {
3522 if (GET_CODE (SUBREG_REG (op)) != REG)
3523 return register_operand (op, mode);
3524
3525 op = SUBREG_REG (op);
3526 }
3527
3528 if (GET_CODE (op) != REG)
3529 return FALSE;
3530
3531 return GPR_OR_PSEUDO_P (REGNO (op));
3532 }
3533
3534 /* Return 1 if operand is a GPR register, or a FPR register, or a 12 bit
3535 signed immediate. */
3536
3537 int
3538 gpr_fpr_or_int12_operand (rtx op, enum machine_mode mode)
3539 {
3540 int regno;
3541
3542 if (GET_CODE (op) == CONST_INT)
3543 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3544
3545 if (GET_MODE (op) != mode && mode != VOIDmode)
3546 return FALSE;
3547
3548 if (GET_CODE (op) == SUBREG)
3549 {
3550 if (GET_CODE (SUBREG_REG (op)) != REG)
3551 return register_operand (op, mode);
3552
3553 op = SUBREG_REG (op);
3554 }
3555
3556 if (GET_CODE (op) != REG)
3557 return FALSE;
3558
3559 regno = REGNO (op);
3560 if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER)
3561 return TRUE;
3562
3563 return FALSE;
3564 }
3565
3566 /* Return 1 if operand is a register or 6 bit signed immediate. */
3567
3568 int
3569 fpr_or_int6_operand (rtx op, enum machine_mode mode)
3570 {
3571 if (GET_CODE (op) == CONST_INT)
3572 return IN_RANGE_P (INTVAL (op), -32, 31);
3573
3574 if (GET_MODE (op) != mode && mode != VOIDmode)
3575 return FALSE;
3576
3577 if (GET_CODE (op) == SUBREG)
3578 {
3579 if (GET_CODE (SUBREG_REG (op)) != REG)
3580 return register_operand (op, mode);
3581
3582 op = SUBREG_REG (op);
3583 }
3584
3585 if (GET_CODE (op) != REG)
3586 return FALSE;
3587
3588 return FPR_OR_PSEUDO_P (REGNO (op));
3589 }
3590
3591 /* Return 1 if operand is a register or 10 bit signed immediate. */
3592
3593 int
3594 gpr_or_int10_operand (rtx op, enum machine_mode mode)
3595 {
3596 if (GET_CODE (op) == CONST_INT)
3597 return IN_RANGE_P (INTVAL (op), -512, 511);
3598
3599 if (GET_MODE (op) != mode && mode != VOIDmode)
3600 return FALSE;
3601
3602 if (GET_CODE (op) == SUBREG)
3603 {
3604 if (GET_CODE (SUBREG_REG (op)) != REG)
3605 return register_operand (op, mode);
3606
3607 op = SUBREG_REG (op);
3608 }
3609
3610 if (GET_CODE (op) != REG)
3611 return FALSE;
3612
3613 return GPR_OR_PSEUDO_P (REGNO (op));
3614 }
3615
3616 /* Return 1 if operand is a register or an integer immediate. */
3617
3618 int
3619 gpr_or_int_operand (rtx op, enum machine_mode mode)
3620 {
3621 if (GET_CODE (op) == CONST_INT)
3622 return TRUE;
3623
3624 if (GET_MODE (op) != mode && mode != VOIDmode)
3625 return FALSE;
3626
3627 if (GET_CODE (op) == SUBREG)
3628 {
3629 if (GET_CODE (SUBREG_REG (op)) != REG)
3630 return register_operand (op, mode);
3631
3632 op = SUBREG_REG (op);
3633 }
3634
3635 if (GET_CODE (op) != REG)
3636 return FALSE;
3637
3638 return GPR_OR_PSEUDO_P (REGNO (op));
3639 }
3640
3641 /* Return 1 if operand is a 12 bit signed immediate. */
3642
3643 int
3644 int12_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3645 {
3646 if (GET_CODE (op) != CONST_INT)
3647 return FALSE;
3648
3649 return IN_RANGE_P (INTVAL (op), -2048, 2047);
3650 }
3651
3652 /* Return 1 if operand is a 6 bit signed immediate. */
3653
3654 int
3655 int6_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3656 {
3657 if (GET_CODE (op) != CONST_INT)
3658 return FALSE;
3659
3660 return IN_RANGE_P (INTVAL (op), -32, 31);
3661 }
3662
3663 /* Return 1 if operand is a 5 bit signed immediate. */
3664
3665 int
3666 int5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3667 {
3668 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), -16, 15);
3669 }
3670
3671 /* Return 1 if operand is a 5 bit unsigned immediate. */
3672
3673 int
3674 uint5_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3675 {
3676 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 31);
3677 }
3678
3679 /* Return 1 if operand is a 4 bit unsigned immediate. */
3680
3681 int
3682 uint4_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3683 {
3684 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 15);
3685 }
3686
3687 /* Return 1 if operand is a 1 bit unsigned immediate (0 or 1). */
3688
3689 int
3690 uint1_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3691 {
3692 return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 1);
3693 }
3694
3695 /* Return 1 if operand is an integer constant that takes 2 instructions
3696 to load up and can be split into sethi/setlo instructions.. */
3697
3698 int
3699 int_2word_operand(rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3700 {
3701 HOST_WIDE_INT value;
3702 REAL_VALUE_TYPE rv;
3703 long l;
3704
3705 switch (GET_CODE (op))
3706 {
3707 default:
3708 break;
3709
3710 case LABEL_REF:
3711 return (flag_pic == 0);
3712
3713 case CONST:
3714 /* small data references are already 1 word */
3715 return (flag_pic == 0) && (! const_small_data_p (op));
3716
3717 case SYMBOL_REF:
3718 /* small data references are already 1 word */
3719 return (flag_pic == 0) && (! SYMBOL_REF_SMALL_P (op));
3720
3721 case CONST_INT:
3722 return ! IN_RANGE_P (INTVAL (op), -32768, 32767);
3723
3724 case CONST_DOUBLE:
3725 if (GET_MODE (op) == SFmode)
3726 {
3727 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
3728 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
3729 value = l;
3730 return ! IN_RANGE_P (value, -32768, 32767);
3731 }
3732 else if (GET_MODE (op) == VOIDmode)
3733 {
3734 value = CONST_DOUBLE_LOW (op);
3735 return ! IN_RANGE_P (value, -32768, 32767);
3736 }
3737 break;
3738 }
3739
3740 return FALSE;
3741 }
3742
3743 /* Return 1 if operand is the pic address register. */
3744 int
3745 pic_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3746 {
3747 if (! flag_pic)
3748 return FALSE;
3749
3750 if (GET_CODE (op) != REG)
3751 return FALSE;
3752
3753 if (REGNO (op) != PIC_REGNO)
3754 return FALSE;
3755
3756 return TRUE;
3757 }
3758
3759 /* Return 1 if operand is a symbolic reference when a PIC option is specified
3760 that takes 3 separate instructions to form. */
3761
3762 int
3763 pic_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3764 {
3765 if (! flag_pic)
3766 return FALSE;
3767
3768 switch (GET_CODE (op))
3769 {
3770 default:
3771 break;
3772
3773 case LABEL_REF:
3774 return TRUE;
3775
3776 case SYMBOL_REF:
3777 /* small data references are already 1 word */
3778 return ! SYMBOL_REF_SMALL_P (op);
3779
3780 case CONST:
3781 /* small data references are already 1 word */
3782 return ! const_small_data_p (op);
3783 }
3784
3785 return FALSE;
3786 }
3787
3788 /* Return 1 if operand is the small data register. */
3789 int
3790 small_data_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3791 {
3792 if (GET_CODE (op) != REG)
3793 return FALSE;
3794
3795 if (REGNO (op) != SDA_BASE_REG)
3796 return FALSE;
3797
3798 return TRUE;
3799 }
3800
3801 /* Return 1 if operand is a symbolic reference to a small data area static or
3802 global object. */
3803
3804 int
3805 small_data_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3806 {
3807 switch (GET_CODE (op))
3808 {
3809 default:
3810 break;
3811
3812 case CONST:
3813 return const_small_data_p (op);
3814
3815 case SYMBOL_REF:
3816 return SYMBOL_REF_SMALL_P (op);
3817 }
3818
3819 return FALSE;
3820 }
3821
3822 /* Return 1 if operand is a 16 bit unsigned immediate */
3823
3824 int
3825 uint16_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3826 {
3827 if (GET_CODE (op) != CONST_INT)
3828 return FALSE;
3829
3830 return IN_RANGE_P (INTVAL (op), 0, 0xffff);
3831 }
3832
3833 /* Return 1 if operand is an integer constant with the bottom 16 bits clear */
3834
3835 int
3836 upper_int16_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3837 {
3838 if (GET_CODE (op) != CONST_INT)
3839 return FALSE;
3840
3841 return ((INTVAL (op) & 0xffff) == 0);
3842 }
3843
3844 /* Return true if operand is a GPR register. */
3845
3846 int
3847 integer_register_operand (rtx op, enum machine_mode mode)
3848 {
3849 if (GET_MODE (op) != mode && mode != VOIDmode)
3850 return FALSE;
3851
3852 if (GET_CODE (op) == SUBREG)
3853 {
3854 if (GET_CODE (SUBREG_REG (op)) != REG)
3855 return register_operand (op, mode);
3856
3857 op = SUBREG_REG (op);
3858 }
3859
3860 if (GET_CODE (op) != REG)
3861 return FALSE;
3862
3863 return GPR_OR_PSEUDO_P (REGNO (op));
3864 }
3865
3866 /* Return true if operand is a GPR register. Do not allow SUBREG's
3867 here, in order to prevent a combine bug. */
3868
3869 int
3870 gpr_no_subreg_operand (rtx op, enum machine_mode mode)
3871 {
3872 if (GET_MODE (op) != mode && mode != VOIDmode)
3873 return FALSE;
3874
3875 if (GET_CODE (op) != REG)
3876 return FALSE;
3877
3878 return GPR_OR_PSEUDO_P (REGNO (op));
3879 }
3880
3881 /* Return true if operand is a FPR register. */
3882
3883 int
3884 fpr_operand (rtx op, enum machine_mode mode)
3885 {
3886 if (GET_MODE (op) != mode && mode != VOIDmode)
3887 return FALSE;
3888
3889 if (GET_CODE (op) == SUBREG)
3890 {
3891 if (GET_CODE (SUBREG_REG (op)) != REG)
3892 return register_operand (op, mode);
3893
3894 op = SUBREG_REG (op);
3895 }
3896
3897 if (GET_CODE (op) != REG)
3898 return FALSE;
3899
3900 return FPR_OR_PSEUDO_P (REGNO (op));
3901 }
3902
3903 /* Return true if operand is an even GPR or FPR register. */
3904
3905 int
3906 even_reg_operand (rtx op, enum machine_mode mode)
3907 {
3908 int regno;
3909
3910 if (GET_MODE (op) != mode && mode != VOIDmode)
3911 return FALSE;
3912
3913 if (GET_CODE (op) == SUBREG)
3914 {
3915 if (GET_CODE (SUBREG_REG (op)) != REG)
3916 return register_operand (op, mode);
3917
3918 op = SUBREG_REG (op);
3919 }
3920
3921 if (GET_CODE (op) != REG)
3922 return FALSE;
3923
3924 regno = REGNO (op);
3925 if (regno >= FIRST_PSEUDO_REGISTER)
3926 return TRUE;
3927
3928 if (GPR_P (regno))
3929 return (((regno - GPR_FIRST) & 1) == 0);
3930
3931 if (FPR_P (regno))
3932 return (((regno - FPR_FIRST) & 1) == 0);
3933
3934 return FALSE;
3935 }
3936
3937 /* Return true if operand is an odd GPR register. */
3938
3939 int
3940 odd_reg_operand (rtx op, enum machine_mode mode)
3941 {
3942 int regno;
3943
3944 if (GET_MODE (op) != mode && mode != VOIDmode)
3945 return FALSE;
3946
3947 if (GET_CODE (op) == SUBREG)
3948 {
3949 if (GET_CODE (SUBREG_REG (op)) != REG)
3950 return register_operand (op, mode);
3951
3952 op = SUBREG_REG (op);
3953 }
3954
3955 if (GET_CODE (op) != REG)
3956 return FALSE;
3957
3958 regno = REGNO (op);
3959 /* assume that reload will give us an even register */
3960 if (regno >= FIRST_PSEUDO_REGISTER)
3961 return FALSE;
3962
3963 if (GPR_P (regno))
3964 return (((regno - GPR_FIRST) & 1) != 0);
3965
3966 if (FPR_P (regno))
3967 return (((regno - FPR_FIRST) & 1) != 0);
3968
3969 return FALSE;
3970 }
3971
3972 /* Return true if operand is an even GPR register. */
3973
3974 int
3975 even_gpr_operand (rtx op, enum machine_mode mode)
3976 {
3977 int regno;
3978
3979 if (GET_MODE (op) != mode && mode != VOIDmode)
3980 return FALSE;
3981
3982 if (GET_CODE (op) == SUBREG)
3983 {
3984 if (GET_CODE (SUBREG_REG (op)) != REG)
3985 return register_operand (op, mode);
3986
3987 op = SUBREG_REG (op);
3988 }
3989
3990 if (GET_CODE (op) != REG)
3991 return FALSE;
3992
3993 regno = REGNO (op);
3994 if (regno >= FIRST_PSEUDO_REGISTER)
3995 return TRUE;
3996
3997 if (! GPR_P (regno))
3998 return FALSE;
3999
4000 return (((regno - GPR_FIRST) & 1) == 0);
4001 }
4002
4003 /* Return true if operand is an odd GPR register. */
4004
4005 int
4006 odd_gpr_operand (rtx op, enum machine_mode mode)
4007 {
4008 int regno;
4009
4010 if (GET_MODE (op) != mode && mode != VOIDmode)
4011 return FALSE;
4012
4013 if (GET_CODE (op) == SUBREG)
4014 {
4015 if (GET_CODE (SUBREG_REG (op)) != REG)
4016 return register_operand (op, mode);
4017
4018 op = SUBREG_REG (op);
4019 }
4020
4021 if (GET_CODE (op) != REG)
4022 return FALSE;
4023
4024 regno = REGNO (op);
4025 /* assume that reload will give us an even register */
4026 if (regno >= FIRST_PSEUDO_REGISTER)
4027 return FALSE;
4028
4029 if (! GPR_P (regno))
4030 return FALSE;
4031
4032 return (((regno - GPR_FIRST) & 1) != 0);
4033 }
4034
4035 /* Return true if operand is a quad aligned FPR register. */
4036
4037 int
4038 quad_fpr_operand (rtx op, enum machine_mode mode)
4039 {
4040 int regno;
4041
4042 if (GET_MODE (op) != mode && mode != VOIDmode)
4043 return FALSE;
4044
4045 if (GET_CODE (op) == SUBREG)
4046 {
4047 if (GET_CODE (SUBREG_REG (op)) != REG)
4048 return register_operand (op, mode);
4049
4050 op = SUBREG_REG (op);
4051 }
4052
4053 if (GET_CODE (op) != REG)
4054 return FALSE;
4055
4056 regno = REGNO (op);
4057 if (regno >= FIRST_PSEUDO_REGISTER)
4058 return TRUE;
4059
4060 if (! FPR_P (regno))
4061 return FALSE;
4062
4063 return (((regno - FPR_FIRST) & 3) == 0);
4064 }
4065
4066 /* Return true if operand is an even FPR register. */
4067
4068 int
4069 even_fpr_operand (rtx op, enum machine_mode mode)
4070 {
4071 int regno;
4072
4073 if (GET_MODE (op) != mode && mode != VOIDmode)
4074 return FALSE;
4075
4076 if (GET_CODE (op) == SUBREG)
4077 {
4078 if (GET_CODE (SUBREG_REG (op)) != REG)
4079 return register_operand (op, mode);
4080
4081 op = SUBREG_REG (op);
4082 }
4083
4084 if (GET_CODE (op) != REG)
4085 return FALSE;
4086
4087 regno = REGNO (op);
4088 if (regno >= FIRST_PSEUDO_REGISTER)
4089 return TRUE;
4090
4091 if (! FPR_P (regno))
4092 return FALSE;
4093
4094 return (((regno - FPR_FIRST) & 1) == 0);
4095 }
4096
4097 /* Return true if operand is an odd FPR register. */
4098
4099 int
4100 odd_fpr_operand (rtx op, enum machine_mode mode)
4101 {
4102 int regno;
4103
4104 if (GET_MODE (op) != mode && mode != VOIDmode)
4105 return FALSE;
4106
4107 if (GET_CODE (op) == SUBREG)
4108 {
4109 if (GET_CODE (SUBREG_REG (op)) != REG)
4110 return register_operand (op, mode);
4111
4112 op = SUBREG_REG (op);
4113 }
4114
4115 if (GET_CODE (op) != REG)
4116 return FALSE;
4117
4118 regno = REGNO (op);
4119 /* assume that reload will give us an even register */
4120 if (regno >= FIRST_PSEUDO_REGISTER)
4121 return FALSE;
4122
4123 if (! FPR_P (regno))
4124 return FALSE;
4125
4126 return (((regno - FPR_FIRST) & 1) != 0);
4127 }
4128
4129 /* Return true if operand is a 2 word memory address that can be loaded in one
4130 instruction to load or store. We assume the stack and frame pointers are
4131 suitably aligned, and variables in the small data area. FIXME -- at some we
4132 should recognize other globals and statics. We can't assume that any old
4133 pointer is aligned, given that arguments could be passed on an odd word on
4134 the stack and the address taken and passed through to another function. */
4135
4136 int
4137 dbl_memory_one_insn_operand (rtx op, enum machine_mode mode)
4138 {
4139 rtx addr;
4140 rtx addr_reg;
4141
4142 if (! TARGET_DWORD)
4143 return FALSE;
4144
4145 if (GET_CODE (op) != MEM)
4146 return FALSE;
4147
4148 if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD)
4149 return FALSE;
4150
4151 addr = XEXP (op, 0);
4152 if (GET_CODE (addr) == REG)
4153 addr_reg = addr;
4154
4155 else if (GET_CODE (addr) == PLUS)
4156 {
4157 rtx addr0 = XEXP (addr, 0);
4158 rtx addr1 = XEXP (addr, 1);
4159
4160 if (GET_CODE (addr0) != REG)
4161 return FALSE;
4162
4163 if (plus_small_data_p (addr0, addr1))
4164 return TRUE;
4165
4166 if (GET_CODE (addr1) != CONST_INT)
4167 return FALSE;
4168
4169 if ((INTVAL (addr1) & 7) != 0)
4170 return FALSE;
4171
4172 addr_reg = addr0;
4173 }
4174
4175 else
4176 return FALSE;
4177
4178 if (addr_reg == frame_pointer_rtx || addr_reg == stack_pointer_rtx)
4179 return TRUE;
4180
4181 return FALSE;
4182 }
4183
4184 /* Return true if operand is a 2 word memory address that needs to
4185 use two instructions to load or store. */
4186
4187 int
4188 dbl_memory_two_insn_operand (rtx op, enum machine_mode mode)
4189 {
4190 if (GET_CODE (op) != MEM)
4191 return FALSE;
4192
4193 if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD)
4194 return FALSE;
4195
4196 if (! TARGET_DWORD)
4197 return TRUE;
4198
4199 return ! dbl_memory_one_insn_operand (op, mode);
4200 }
4201
4202 /* Return true if operand is something that can be an output for a move
4203 operation. */
4204
4205 int
4206 move_destination_operand (rtx op, enum machine_mode mode)
4207 {
4208 rtx subreg;
4209 enum rtx_code code;
4210
4211 switch (GET_CODE (op))
4212 {
4213 default:
4214 break;
4215
4216 case SUBREG:
4217 if (GET_MODE (op) != mode && mode != VOIDmode)
4218 return FALSE;
4219
4220 subreg = SUBREG_REG (op);
4221 code = GET_CODE (subreg);
4222 if (code == MEM)
4223 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4224 reload_completed, FALSE);
4225
4226 return (code == REG);
4227
4228 case REG:
4229 if (GET_MODE (op) != mode && mode != VOIDmode)
4230 return FALSE;
4231
4232 return TRUE;
4233
4234 case MEM:
4235 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4236 return TRUE;
4237
4238 return frv_legitimate_memory_operand (op, mode, FALSE);
4239 }
4240
4241 return FALSE;
4242 }
4243
4244 /* Return true if operand is something that can be an input for a move
4245 operation. */
4246
4247 int
4248 move_source_operand (rtx op, enum machine_mode mode)
4249 {
4250 rtx subreg;
4251 enum rtx_code code;
4252
4253 switch (GET_CODE (op))
4254 {
4255 default:
4256 break;
4257
4258 case CONST_INT:
4259 case CONST_DOUBLE:
4260 case SYMBOL_REF:
4261 case LABEL_REF:
4262 case CONST:
4263 return immediate_operand (op, mode);
4264
4265 case SUBREG:
4266 if (GET_MODE (op) != mode && mode != VOIDmode)
4267 return FALSE;
4268
4269 subreg = SUBREG_REG (op);
4270 code = GET_CODE (subreg);
4271 if (code == MEM)
4272 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4273 reload_completed, FALSE);
4274
4275 return (code == REG);
4276
4277 case REG:
4278 if (GET_MODE (op) != mode && mode != VOIDmode)
4279 return FALSE;
4280
4281 return TRUE;
4282
4283 case MEM:
4284 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4285 return TRUE;
4286
4287 return frv_legitimate_memory_operand (op, mode, FALSE);
4288 }
4289
4290 return FALSE;
4291 }
4292
4293 /* Return true if operand is something that can be an output for a conditional
4294 move operation. */
4295
4296 int
4297 condexec_dest_operand (rtx op, enum machine_mode mode)
4298 {
4299 rtx subreg;
4300 enum rtx_code code;
4301
4302 switch (GET_CODE (op))
4303 {
4304 default:
4305 break;
4306
4307 case SUBREG:
4308 if (GET_MODE (op) != mode && mode != VOIDmode)
4309 return FALSE;
4310
4311 subreg = SUBREG_REG (op);
4312 code = GET_CODE (subreg);
4313 if (code == MEM)
4314 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4315 reload_completed, TRUE);
4316
4317 return (code == REG);
4318
4319 case REG:
4320 if (GET_MODE (op) != mode && mode != VOIDmode)
4321 return FALSE;
4322
4323 return TRUE;
4324
4325 case MEM:
4326 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4327 return TRUE;
4328
4329 return frv_legitimate_memory_operand (op, mode, TRUE);
4330 }
4331
4332 return FALSE;
4333 }
4334
4335 /* Return true if operand is something that can be an input for a conditional
4336 move operation. */
4337
4338 int
4339 condexec_source_operand (rtx op, enum machine_mode mode)
4340 {
4341 rtx subreg;
4342 enum rtx_code code;
4343
4344 switch (GET_CODE (op))
4345 {
4346 default:
4347 break;
4348
4349 case CONST_INT:
4350 case CONST_DOUBLE:
4351 return ZERO_P (op);
4352
4353 case SUBREG:
4354 if (GET_MODE (op) != mode && mode != VOIDmode)
4355 return FALSE;
4356
4357 subreg = SUBREG_REG (op);
4358 code = GET_CODE (subreg);
4359 if (code == MEM)
4360 return frv_legitimate_address_p (mode, XEXP (subreg, 0),
4361 reload_completed, TRUE);
4362
4363 return (code == REG);
4364
4365 case REG:
4366 if (GET_MODE (op) != mode && mode != VOIDmode)
4367 return FALSE;
4368
4369 return TRUE;
4370
4371 case MEM:
4372 if (GET_CODE (XEXP (op, 0)) == ADDRESSOF)
4373 return TRUE;
4374
4375 return frv_legitimate_memory_operand (op, mode, TRUE);
4376 }
4377
4378 return FALSE;
4379 }
4380
4381 /* Return true if operand is a register of any flavor or a 0 of the
4382 appropriate type. */
4383
4384 int
4385 reg_or_0_operand (rtx op, enum machine_mode mode)
4386 {
4387 switch (GET_CODE (op))
4388 {
4389 default:
4390 break;
4391
4392 case REG:
4393 case SUBREG:
4394 if (GET_MODE (op) != mode && mode != VOIDmode)
4395 return FALSE;
4396
4397 return register_operand (op, mode);
4398
4399 case CONST_INT:
4400 case CONST_DOUBLE:
4401 return ZERO_P (op);
4402 }
4403
4404 return FALSE;
4405 }
4406
4407 /* Return true if operand is the link register */
4408
4409 int
4410 lr_operand (rtx op, enum machine_mode mode)
4411 {
4412 if (GET_CODE (op) != REG)
4413 return FALSE;
4414
4415 if (GET_MODE (op) != mode && mode != VOIDmode)
4416 return FALSE;
4417
4418 if (REGNO (op) != LR_REGNO && REGNO (op) < FIRST_PSEUDO_REGISTER)
4419 return FALSE;
4420
4421 return TRUE;
4422 }
4423
4424 /* Return true if operand is a gpr register or a valid memory operation. */
4425
4426 int
4427 gpr_or_memory_operand (rtx op, enum machine_mode mode)
4428 {
4429 return (integer_register_operand (op, mode)
4430 || frv_legitimate_memory_operand (op, mode, FALSE));
4431 }
4432
4433 /* Return true if operand is a fpr register or a valid memory operation. */
4434
4435 int
4436 fpr_or_memory_operand (rtx op, enum machine_mode mode)
4437 {
4438 return (fpr_operand (op, mode)
4439 || frv_legitimate_memory_operand (op, mode, FALSE));
4440 }
4441
4442 /* Return true if operand is an icc register */
4443
4444 int
4445 icc_operand (rtx op, enum machine_mode mode)
4446 {
4447 int regno;
4448
4449 if (GET_MODE (op) != mode && mode != VOIDmode)
4450 return FALSE;
4451
4452 if (GET_CODE (op) != REG)
4453 return FALSE;
4454
4455 regno = REGNO (op);
4456 return ICC_OR_PSEUDO_P (regno);
4457 }
4458
4459 /* Return true if operand is an fcc register */
4460
4461 int
4462 fcc_operand (rtx op, enum machine_mode mode)
4463 {
4464 int regno;
4465
4466 if (GET_MODE (op) != mode && mode != VOIDmode)
4467 return FALSE;
4468
4469 if (GET_CODE (op) != REG)
4470 return FALSE;
4471
4472 regno = REGNO (op);
4473 return FCC_OR_PSEUDO_P (regno);
4474 }
4475
4476 /* Return true if operand is either an fcc or icc register */
4477
4478 int
4479 cc_operand (rtx op, enum machine_mode mode)
4480 {
4481 int regno;
4482
4483 if (GET_MODE (op) != mode && mode != VOIDmode)
4484 return FALSE;
4485
4486 if (GET_CODE (op) != REG)
4487 return FALSE;
4488
4489 regno = REGNO (op);
4490 if (CC_OR_PSEUDO_P (regno))
4491 return TRUE;
4492
4493 return FALSE;
4494 }
4495
4496 /* Return true if operand is an integer CCR register */
4497
4498 int
4499 icr_operand (rtx op, enum machine_mode mode)
4500 {
4501 int regno;
4502
4503 if (GET_MODE (op) != mode && mode != VOIDmode)
4504 return FALSE;
4505
4506 if (GET_CODE (op) != REG)
4507 return FALSE;
4508
4509 regno = REGNO (op);
4510 return ICR_OR_PSEUDO_P (regno);
4511 }
4512
4513 /* Return true if operand is an fcc register */
4514
4515 int
4516 fcr_operand (rtx op, enum machine_mode mode)
4517 {
4518 int regno;
4519
4520 if (GET_MODE (op) != mode && mode != VOIDmode)
4521 return FALSE;
4522
4523 if (GET_CODE (op) != REG)
4524 return FALSE;
4525
4526 regno = REGNO (op);
4527 return FCR_OR_PSEUDO_P (regno);
4528 }
4529
4530 /* Return true if operand is either an fcc or icc register */
4531
4532 int
4533 cr_operand (rtx op, enum machine_mode mode)
4534 {
4535 int regno;
4536
4537 if (GET_MODE (op) != mode && mode != VOIDmode)
4538 return FALSE;
4539
4540 if (GET_CODE (op) != REG)
4541 return FALSE;
4542
4543 regno = REGNO (op);
4544 if (CR_OR_PSEUDO_P (regno))
4545 return TRUE;
4546
4547 return FALSE;
4548 }
4549
4550 /* Return true if operand is a memory reference suitable for a call. */
4551
4552 int
4553 call_operand (rtx op, enum machine_mode mode)
4554 {
4555 if (GET_MODE (op) != mode && mode != VOIDmode && GET_CODE (op) != CONST_INT)
4556 return FALSE;
4557
4558 if (GET_CODE (op) == SYMBOL_REF)
4559 return TRUE;
4560
4561 /* Note this doesn't allow reg+reg or reg+imm12 addressing (which should
4562 never occur anyway), but prevents reload from not handling the case
4563 properly of a call through a pointer on a function that calls
4564 vfork/setjmp, etc. due to the need to flush all of the registers to stack. */
4565 return gpr_or_int12_operand (op, mode);
4566 }
4567
4568 /* Return true if operator is a kind of relational operator. */
4569
4570 int
4571 relational_operator (rtx op, enum machine_mode mode)
4572 {
4573 rtx op0;
4574 rtx op1;
4575 int regno;
4576
4577 if (mode != VOIDmode && mode != GET_MODE (op))
4578 return FALSE;
4579
4580 switch (GET_CODE (op))
4581 {
4582 default:
4583 return FALSE;
4584
4585 case EQ:
4586 case NE:
4587 case LE:
4588 case LT:
4589 case GE:
4590 case GT:
4591 case LEU:
4592 case LTU:
4593 case GEU:
4594 case GTU:
4595 break;
4596 }
4597
4598 op1 = XEXP (op, 1);
4599 if (op1 != const0_rtx)
4600 return FALSE;
4601
4602 op0 = XEXP (op, 0);
4603 if (GET_CODE (op0) != REG)
4604 return FALSE;
4605
4606 regno = REGNO (op0);
4607 switch (GET_MODE (op0))
4608 {
4609 default:
4610 break;
4611
4612 case CCmode:
4613 case CC_UNSmode:
4614 return ICC_OR_PSEUDO_P (regno);
4615
4616 case CC_FPmode:
4617 return FCC_OR_PSEUDO_P (regno);
4618
4619 case CC_CCRmode:
4620 return CR_OR_PSEUDO_P (regno);
4621 }
4622
4623 return FALSE;
4624 }
4625
4626 /* Return true if operator is a signed integer relational operator */
4627
4628 int
4629 signed_relational_operator (rtx op, enum machine_mode mode)
4630 {
4631 rtx op0;
4632 rtx op1;
4633 int regno;
4634
4635 if (mode != VOIDmode && mode != GET_MODE (op))
4636 return FALSE;
4637
4638 switch (GET_CODE (op))
4639 {
4640 default:
4641 return FALSE;
4642
4643 case EQ:
4644 case NE:
4645 case LE:
4646 case LT:
4647 case GE:
4648 case GT:
4649 break;
4650 }
4651
4652 op1 = XEXP (op, 1);
4653 if (op1 != const0_rtx)
4654 return FALSE;
4655
4656 op0 = XEXP (op, 0);
4657 if (GET_CODE (op0) != REG)
4658 return FALSE;
4659
4660 regno = REGNO (op0);
4661 if (GET_MODE (op0) == CCmode && ICC_OR_PSEUDO_P (regno))
4662 return TRUE;
4663
4664 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4665 return TRUE;
4666
4667 return FALSE;
4668 }
4669
4670 /* Return true if operator is a signed integer relational operator */
4671
4672 int
4673 unsigned_relational_operator (rtx op, enum machine_mode mode)
4674 {
4675 rtx op0;
4676 rtx op1;
4677 int regno;
4678
4679 if (mode != VOIDmode && mode != GET_MODE (op))
4680 return FALSE;
4681
4682 switch (GET_CODE (op))
4683 {
4684 default:
4685 return FALSE;
4686
4687 case LEU:
4688 case LTU:
4689 case GEU:
4690 case GTU:
4691 break;
4692 }
4693
4694 op1 = XEXP (op, 1);
4695 if (op1 != const0_rtx)
4696 return FALSE;
4697
4698 op0 = XEXP (op, 0);
4699 if (GET_CODE (op0) != REG)
4700 return FALSE;
4701
4702 regno = REGNO (op0);
4703 if (GET_MODE (op0) == CC_UNSmode && ICC_OR_PSEUDO_P (regno))
4704 return TRUE;
4705
4706 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4707 return TRUE;
4708
4709 return FALSE;
4710 }
4711
4712 /* Return true if operator is a floating point relational operator */
4713
4714 int
4715 float_relational_operator (rtx op, enum machine_mode mode)
4716 {
4717 rtx op0;
4718 rtx op1;
4719 int regno;
4720
4721 if (mode != VOIDmode && mode != GET_MODE (op))
4722 return FALSE;
4723
4724 switch (GET_CODE (op))
4725 {
4726 default:
4727 return FALSE;
4728
4729 case EQ: case NE:
4730 case LE: case LT:
4731 case GE: case GT:
4732 #if 0
4733 case UEQ: case UNE:
4734 case ULE: case ULT:
4735 case UGE: case UGT:
4736 case ORDERED:
4737 case UNORDERED:
4738 #endif
4739 break;
4740 }
4741
4742 op1 = XEXP (op, 1);
4743 if (op1 != const0_rtx)
4744 return FALSE;
4745
4746 op0 = XEXP (op, 0);
4747 if (GET_CODE (op0) != REG)
4748 return FALSE;
4749
4750 regno = REGNO (op0);
4751 if (GET_MODE (op0) == CC_FPmode && FCC_OR_PSEUDO_P (regno))
4752 return TRUE;
4753
4754 if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4755 return TRUE;
4756
4757 return FALSE;
4758 }
4759
4760 /* Return true if operator is EQ/NE of a conditional execution register. */
4761
4762 int
4763 ccr_eqne_operator (rtx op, enum machine_mode mode)
4764 {
4765 enum machine_mode op_mode = GET_MODE (op);
4766 rtx op0;
4767 rtx op1;
4768 int regno;
4769
4770 if (mode != VOIDmode && op_mode != mode)
4771 return FALSE;
4772
4773 switch (GET_CODE (op))
4774 {
4775 default:
4776 return FALSE;
4777
4778 case EQ:
4779 case NE:
4780 break;
4781 }
4782
4783 op1 = XEXP (op, 1);
4784 if (op1 != const0_rtx)
4785 return FALSE;
4786
4787 op0 = XEXP (op, 0);
4788 if (GET_CODE (op0) != REG)
4789 return FALSE;
4790
4791 regno = REGNO (op0);
4792 if (op_mode == CC_CCRmode && CR_OR_PSEUDO_P (regno))
4793 return TRUE;
4794
4795 return FALSE;
4796 }
4797
4798 /* Return true if operator is a minimum or maximum operator (both signed and
4799 unsigned). */
4800
4801 int
4802 minmax_operator (rtx op, enum machine_mode mode)
4803 {
4804 if (mode != VOIDmode && mode != GET_MODE (op))
4805 return FALSE;
4806
4807 switch (GET_CODE (op))
4808 {
4809 default:
4810 return FALSE;
4811
4812 case SMIN:
4813 case SMAX:
4814 case UMIN:
4815 case UMAX:
4816 break;
4817 }
4818
4819 if (! integer_register_operand (XEXP (op, 0), mode))
4820 return FALSE;
4821
4822 if (! gpr_or_int10_operand (XEXP (op, 1), mode))
4823 return FALSE;
4824
4825 return TRUE;
4826 }
4827
4828 /* Return true if operator is an integer binary operator that can executed
4829 conditionally and takes 1 cycle. */
4830
4831 int
4832 condexec_si_binary_operator (rtx op, enum machine_mode mode)
4833 {
4834 enum machine_mode op_mode = GET_MODE (op);
4835
4836 if (mode != VOIDmode && op_mode != mode)
4837 return FALSE;
4838
4839 switch (GET_CODE (op))
4840 {
4841 default:
4842 return FALSE;
4843
4844 case PLUS:
4845 case MINUS:
4846 case AND:
4847 case IOR:
4848 case XOR:
4849 case ASHIFT:
4850 case ASHIFTRT:
4851 case LSHIFTRT:
4852 return TRUE;
4853 }
4854 }
4855
4856 /* Return true if operator is an integer binary operator that can be
4857 executed conditionally by a media instruction. */
4858
4859 int
4860 condexec_si_media_operator (rtx op, enum machine_mode mode)
4861 {
4862 enum machine_mode op_mode = GET_MODE (op);
4863
4864 if (mode != VOIDmode && op_mode != mode)
4865 return FALSE;
4866
4867 switch (GET_CODE (op))
4868 {
4869 default:
4870 return FALSE;
4871
4872 case AND:
4873 case IOR:
4874 case XOR:
4875 return TRUE;
4876 }
4877 }
4878
4879 /* Return true if operator is an integer division operator that can executed
4880 conditionally. */
4881
4882 int
4883 condexec_si_divide_operator (rtx op, enum machine_mode mode)
4884 {
4885 enum machine_mode op_mode = GET_MODE (op);
4886
4887 if (mode != VOIDmode && op_mode != mode)
4888 return FALSE;
4889
4890 switch (GET_CODE (op))
4891 {
4892 default:
4893 return FALSE;
4894
4895 case DIV:
4896 case UDIV:
4897 return TRUE;
4898 }
4899 }
4900
4901 /* Return true if operator is an integer unary operator that can executed
4902 conditionally. */
4903
4904 int
4905 condexec_si_unary_operator (rtx op, enum machine_mode mode)
4906 {
4907 enum machine_mode op_mode = GET_MODE (op);
4908
4909 if (mode != VOIDmode && op_mode != mode)
4910 return FALSE;
4911
4912 switch (GET_CODE (op))
4913 {
4914 default:
4915 return FALSE;
4916
4917 case NEG:
4918 case NOT:
4919 return TRUE;
4920 }
4921 }
4922
4923 /* Return true if operator is a conversion-type expression that can be
4924 evaluated conditionally by floating-point instructions. */
4925
4926 int
4927 condexec_sf_conv_operator (rtx op, enum machine_mode mode)
4928 {
4929 enum machine_mode op_mode = GET_MODE (op);
4930
4931 if (mode != VOIDmode && op_mode != mode)
4932 return FALSE;
4933
4934 switch (GET_CODE (op))
4935 {
4936 default:
4937 return FALSE;
4938
4939 case NEG:
4940 case ABS:
4941 return TRUE;
4942 }
4943 }
4944
4945 /* Return true if operator is an addition or subtraction expression.
4946 Such expressions can be evaluated conditionally by floating-point
4947 instructions. */
4948
4949 int
4950 condexec_sf_add_operator (rtx op, enum machine_mode mode)
4951 {
4952 enum machine_mode op_mode = GET_MODE (op);
4953
4954 if (mode != VOIDmode && op_mode != mode)
4955 return FALSE;
4956
4957 switch (GET_CODE (op))
4958 {
4959 default:
4960 return FALSE;
4961
4962 case PLUS:
4963 case MINUS:
4964 return TRUE;
4965 }
4966 }
4967
4968 /* Return true if the memory operand is one that can be conditionally
4969 executed. */
4970
4971 int
4972 condexec_memory_operand (rtx op, enum machine_mode mode)
4973 {
4974 enum machine_mode op_mode = GET_MODE (op);
4975 rtx addr;
4976
4977 if (mode != VOIDmode && op_mode != mode)
4978 return FALSE;
4979
4980 switch (op_mode)
4981 {
4982 default:
4983 return FALSE;
4984
4985 case QImode:
4986 case HImode:
4987 case SImode:
4988 case SFmode:
4989 break;
4990 }
4991
4992 if (GET_CODE (op) != MEM)
4993 return FALSE;
4994
4995 addr = XEXP (op, 0);
4996 if (GET_CODE (addr) == ADDRESSOF)
4997 return TRUE;
4998
4999 return frv_legitimate_address_p (mode, addr, reload_completed, TRUE);
5000 }
5001
5002 /* Return true if operator is an integer binary operator that can be combined
5003 with a setcc operation. Do not allow the arithmetic operations that could
5004 potentially overflow since the FR-V sets the condition code based on the
5005 "true" value of the result, not the result after truncating to a 32-bit
5006 register. */
5007
5008 int
5009 intop_compare_operator (rtx op, enum machine_mode mode)
5010 {
5011 enum machine_mode op_mode = GET_MODE (op);
5012
5013 if (mode != VOIDmode && op_mode != mode)
5014 return FALSE;
5015
5016 switch (GET_CODE (op))
5017 {
5018 default:
5019 return FALSE;
5020
5021 case AND:
5022 case IOR:
5023 case XOR:
5024 case ASHIFTRT:
5025 case LSHIFTRT:
5026 break;
5027 }
5028
5029 if (! integer_register_operand (XEXP (op, 0), SImode))
5030 return FALSE;
5031
5032 if (! gpr_or_int10_operand (XEXP (op, 1), SImode))
5033 return FALSE;
5034
5035 return TRUE;
5036 }
5037
5038 /* Return true if operator is an integer binary operator that can be combined
5039 with a setcc operation inside of a conditional execution. */
5040
5041 int
5042 condexec_intop_cmp_operator (rtx op, enum machine_mode mode)
5043 {
5044 enum machine_mode op_mode = GET_MODE (op);
5045
5046 if (mode != VOIDmode && op_mode != mode)
5047 return FALSE;
5048
5049 switch (GET_CODE (op))
5050 {
5051 default:
5052 return FALSE;
5053
5054 case AND:
5055 case IOR:
5056 case XOR:
5057 case ASHIFTRT:
5058 case LSHIFTRT:
5059 break;
5060 }
5061
5062 if (! integer_register_operand (XEXP (op, 0), SImode))
5063 return FALSE;
5064
5065 if (! integer_register_operand (XEXP (op, 1), SImode))
5066 return FALSE;
5067
5068 return TRUE;
5069 }
5070
5071 /* Return 1 if operand is a valid ACC register number */
5072
5073 int
5074 acc_operand (rtx op, enum machine_mode mode)
5075 {
5076 int regno;
5077
5078 if (GET_MODE (op) != mode && mode != VOIDmode)
5079 return FALSE;
5080
5081 if (GET_CODE (op) == SUBREG)
5082 {
5083 if (GET_CODE (SUBREG_REG (op)) != REG)
5084 return register_operand (op, mode);
5085
5086 op = SUBREG_REG (op);
5087 }
5088
5089 if (GET_CODE (op) != REG)
5090 return FALSE;
5091
5092 regno = REGNO (op);
5093 return ACC_OR_PSEUDO_P (regno);
5094 }
5095
5096 /* Return 1 if operand is a valid even ACC register number */
5097
5098 int
5099 even_acc_operand (rtx op, enum machine_mode mode)
5100 {
5101 int regno;
5102
5103 if (GET_MODE (op) != mode && mode != VOIDmode)
5104 return FALSE;
5105
5106 if (GET_CODE (op) == SUBREG)
5107 {
5108 if (GET_CODE (SUBREG_REG (op)) != REG)
5109 return register_operand (op, mode);
5110
5111 op = SUBREG_REG (op);
5112 }
5113
5114 if (GET_CODE (op) != REG)
5115 return FALSE;
5116
5117 regno = REGNO (op);
5118 return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 1) == 0);
5119 }
5120
5121 /* Return 1 if operand is zero or four */
5122
5123 int
5124 quad_acc_operand (rtx op, enum machine_mode mode)
5125 {
5126 int regno;
5127
5128 if (GET_MODE (op) != mode && mode != VOIDmode)
5129 return FALSE;
5130
5131 if (GET_CODE (op) == SUBREG)
5132 {
5133 if (GET_CODE (SUBREG_REG (op)) != REG)
5134 return register_operand (op, mode);
5135
5136 op = SUBREG_REG (op);
5137 }
5138
5139 if (GET_CODE (op) != REG)
5140 return FALSE;
5141
5142 regno = REGNO (op);
5143 return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 3) == 0);
5144 }
5145
5146 /* Return 1 if operand is a valid ACCG register number */
5147
5148 int
5149 accg_operand (rtx op, enum machine_mode mode)
5150 {
5151 if (GET_MODE (op) != mode && mode != VOIDmode)
5152 return FALSE;
5153
5154 if (GET_CODE (op) == SUBREG)
5155 {
5156 if (GET_CODE (SUBREG_REG (op)) != REG)
5157 return register_operand (op, mode);
5158
5159 op = SUBREG_REG (op);
5160 }
5161
5162 if (GET_CODE (op) != REG)
5163 return FALSE;
5164
5165 return ACCG_OR_PSEUDO_P (REGNO (op));
5166 }
5167
5168 \f
5169 /* Return true if the bare return instruction can be used outside of the
5170 epilog code. For frv, we only do it if there was no stack allocation. */
5171
5172 int
5173 direct_return_p (void)
5174 {
5175 frv_stack_t *info;
5176
5177 if (!reload_completed)
5178 return FALSE;
5179
5180 info = frv_stack_info ();
5181 return (info->total_size == 0);
5182 }
5183
5184 \f
5185 /* Emit code to handle a MOVSI, adding in the small data register or pic
5186 register if needed to load up addresses. Return TRUE if the appropriate
5187 instructions are emitted. */
5188
5189 int
5190 frv_emit_movsi (rtx dest, rtx src)
5191 {
5192 int base_regno = -1;
5193
5194 if (!reload_in_progress
5195 && !reload_completed
5196 && !register_operand (dest, SImode)
5197 && (!reg_or_0_operand (src, SImode)
5198 /* Virtual registers will almost always be replaced by an
5199 add instruction, so expose this to CSE by copying to
5200 an intermediate register */
5201 || (GET_CODE (src) == REG
5202 && IN_RANGE_P (REGNO (src),
5203 FIRST_VIRTUAL_REGISTER,
5204 LAST_VIRTUAL_REGISTER))))
5205 {
5206 emit_insn (gen_rtx_SET (VOIDmode, dest, copy_to_mode_reg (SImode, src)));
5207 return TRUE;
5208 }
5209
5210 /* Explicitly add in the PIC or small data register if needed. */
5211 switch (GET_CODE (src))
5212 {
5213 default:
5214 break;
5215
5216 case LABEL_REF:
5217 if (flag_pic)
5218 base_regno = PIC_REGNO;
5219
5220 break;
5221
5222 case CONST:
5223 if (const_small_data_p (src))
5224 base_regno = SDA_BASE_REG;
5225
5226 else if (flag_pic)
5227 base_regno = PIC_REGNO;
5228
5229 break;
5230
5231 case SYMBOL_REF:
5232 if (SYMBOL_REF_SMALL_P (src))
5233 base_regno = SDA_BASE_REG;
5234
5235 else if (flag_pic)
5236 base_regno = PIC_REGNO;
5237
5238 break;
5239 }
5240
5241 if (base_regno >= 0)
5242 {
5243 emit_insn (gen_rtx_SET (VOIDmode, dest,
5244 gen_rtx_PLUS (Pmode,
5245 gen_rtx_REG (Pmode, base_regno),
5246 src)));
5247
5248 if (base_regno == PIC_REGNO)
5249 cfun->uses_pic_offset_table = TRUE;
5250
5251 return TRUE;
5252 }
5253
5254 return FALSE;
5255 }
5256
5257 \f
5258 /* Return a string to output a single word move. */
5259
5260 const char *
5261 output_move_single (rtx operands[], rtx insn)
5262 {
5263 rtx dest = operands[0];
5264 rtx src = operands[1];
5265
5266 if (GET_CODE (dest) == REG)
5267 {
5268 int dest_regno = REGNO (dest);
5269 enum machine_mode mode = GET_MODE (dest);
5270
5271 if (GPR_P (dest_regno))
5272 {
5273 if (GET_CODE (src) == REG)
5274 {
5275 /* gpr <- some sort of register */
5276 int src_regno = REGNO (src);
5277
5278 if (GPR_P (src_regno))
5279 return "mov %1, %0";
5280
5281 else if (FPR_P (src_regno))
5282 return "movfg %1, %0";
5283
5284 else if (SPR_P (src_regno))
5285 return "movsg %1, %0";
5286 }
5287
5288 else if (GET_CODE (src) == MEM)
5289 {
5290 /* gpr <- memory */
5291 switch (mode)
5292 {
5293 default:
5294 break;
5295
5296 case QImode:
5297 return "ldsb%I1%U1 %M1,%0";
5298
5299 case HImode:
5300 return "ldsh%I1%U1 %M1,%0";
5301
5302 case SImode:
5303 case SFmode:
5304 return "ld%I1%U1 %M1, %0";
5305 }
5306 }
5307
5308 else if (GET_CODE (src) == CONST_INT
5309 || GET_CODE (src) == CONST_DOUBLE)
5310 {
5311 /* gpr <- integer/floating constant */
5312 HOST_WIDE_INT value;
5313
5314 if (GET_CODE (src) == CONST_INT)
5315 value = INTVAL (src);
5316
5317 else if (mode == SFmode)
5318 {
5319 REAL_VALUE_TYPE rv;
5320 long l;
5321
5322 REAL_VALUE_FROM_CONST_DOUBLE (rv, src);
5323 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5324 value = l;
5325 }
5326
5327 else
5328 value = CONST_DOUBLE_LOW (src);
5329
5330 if (IN_RANGE_P (value, -32768, 32767))
5331 return "setlos %1, %0";
5332
5333 return "#";
5334 }
5335
5336 else if (GET_CODE (src) == SYMBOL_REF
5337 || GET_CODE (src) == LABEL_REF
5338 || GET_CODE (src) == CONST)
5339 {
5340 /* Silently fix up instances where the small data pointer is not
5341 used in the address. */
5342 if (small_data_symbolic_operand (src, GET_MODE (src)))
5343 return "addi %@, #gprel12(%1), %0";
5344
5345 return "#";
5346 }
5347 }
5348
5349 else if (FPR_P (dest_regno))
5350 {
5351 if (GET_CODE (src) == REG)
5352 {
5353 /* fpr <- some sort of register */
5354 int src_regno = REGNO (src);
5355
5356 if (GPR_P (src_regno))
5357 return "movgf %1, %0";
5358
5359 else if (FPR_P (src_regno))
5360 {
5361 if (TARGET_HARD_FLOAT)
5362 return "fmovs %1, %0";
5363 else
5364 return "mor %1, %1, %0";
5365 }
5366 }
5367
5368 else if (GET_CODE (src) == MEM)
5369 {
5370 /* fpr <- memory */
5371 switch (mode)
5372 {
5373 default:
5374 break;
5375
5376 case QImode:
5377 return "ldbf%I1%U1 %M1,%0";
5378
5379 case HImode:
5380 return "ldhf%I1%U1 %M1,%0";
5381
5382 case SImode:
5383 case SFmode:
5384 return "ldf%I1%U1 %M1, %0";
5385 }
5386 }
5387
5388 else if (ZERO_P (src))
5389 return "movgf %., %0";
5390 }
5391
5392 else if (SPR_P (dest_regno))
5393 {
5394 if (GET_CODE (src) == REG)
5395 {
5396 /* spr <- some sort of register */
5397 int src_regno = REGNO (src);
5398
5399 if (GPR_P (src_regno))
5400 return "movgs %1, %0";
5401 }
5402 }
5403 }
5404
5405 else if (GET_CODE (dest) == MEM)
5406 {
5407 if (GET_CODE (src) == REG)
5408 {
5409 int src_regno = REGNO (src);
5410 enum machine_mode mode = GET_MODE (dest);
5411
5412 if (GPR_P (src_regno))
5413 {
5414 switch (mode)
5415 {
5416 default:
5417 break;
5418
5419 case QImode:
5420 return "stb%I0%U0 %1, %M0";
5421
5422 case HImode:
5423 return "sth%I0%U0 %1, %M0";
5424
5425 case SImode:
5426 case SFmode:
5427 return "st%I0%U0 %1, %M0";
5428 }
5429 }
5430
5431 else if (FPR_P (src_regno))
5432 {
5433 switch (mode)
5434 {
5435 default:
5436 break;
5437
5438 case QImode:
5439 return "stbf%I0%U0 %1, %M0";
5440
5441 case HImode:
5442 return "sthf%I0%U0 %1, %M0";
5443
5444 case SImode:
5445 case SFmode:
5446 return "stf%I0%U0 %1, %M0";
5447 }
5448 }
5449 }
5450
5451 else if (ZERO_P (src))
5452 {
5453 switch (GET_MODE (dest))
5454 {
5455 default:
5456 break;
5457
5458 case QImode:
5459 return "stb%I0%U0 %., %M0";
5460
5461 case HImode:
5462 return "sth%I0%U0 %., %M0";
5463
5464 case SImode:
5465 case SFmode:
5466 return "st%I0%U0 %., %M0";
5467 }
5468 }
5469 }
5470
5471 fatal_insn ("Bad output_move_single operand", insn);
5472 return "";
5473 }
5474
5475 \f
5476 /* Return a string to output a double word move. */
5477
5478 const char *
5479 output_move_double (rtx operands[], rtx insn)
5480 {
5481 rtx dest = operands[0];
5482 rtx src = operands[1];
5483 enum machine_mode mode = GET_MODE (dest);
5484
5485 if (GET_CODE (dest) == REG)
5486 {
5487 int dest_regno = REGNO (dest);
5488
5489 if (GPR_P (dest_regno))
5490 {
5491 if (GET_CODE (src) == REG)
5492 {
5493 /* gpr <- some sort of register */
5494 int src_regno = REGNO (src);
5495
5496 if (GPR_P (src_regno))
5497 return "#";
5498
5499 else if (FPR_P (src_regno))
5500 {
5501 if (((dest_regno - GPR_FIRST) & 1) == 0
5502 && ((src_regno - FPR_FIRST) & 1) == 0)
5503 return "movfgd %1, %0";
5504
5505 return "#";
5506 }
5507 }
5508
5509 else if (GET_CODE (src) == MEM)
5510 {
5511 /* gpr <- memory */
5512 if (dbl_memory_one_insn_operand (src, mode))
5513 return "ldd%I1%U1 %M1, %0";
5514
5515 return "#";
5516 }
5517
5518 else if (GET_CODE (src) == CONST_INT
5519 || GET_CODE (src) == CONST_DOUBLE)
5520 return "#";
5521 }
5522
5523 else if (FPR_P (dest_regno))
5524 {
5525 if (GET_CODE (src) == REG)
5526 {
5527 /* fpr <- some sort of register */
5528 int src_regno = REGNO (src);
5529
5530 if (GPR_P (src_regno))
5531 {
5532 if (((dest_regno - FPR_FIRST) & 1) == 0
5533 && ((src_regno - GPR_FIRST) & 1) == 0)
5534 return "movgfd %1, %0";
5535
5536 return "#";
5537 }
5538
5539 else if (FPR_P (src_regno))
5540 {
5541 if (TARGET_DOUBLE
5542 && ((dest_regno - FPR_FIRST) & 1) == 0
5543 && ((src_regno - FPR_FIRST) & 1) == 0)
5544 return "fmovd %1, %0";
5545
5546 return "#";
5547 }
5548 }
5549
5550 else if (GET_CODE (src) == MEM)
5551 {
5552 /* fpr <- memory */
5553 if (dbl_memory_one_insn_operand (src, mode))
5554 return "lddf%I1%U1 %M1, %0";
5555
5556 return "#";
5557 }
5558
5559 else if (ZERO_P (src))
5560 return "#";
5561 }
5562 }
5563
5564 else if (GET_CODE (dest) == MEM)
5565 {
5566 if (GET_CODE (src) == REG)
5567 {
5568 int src_regno = REGNO (src);
5569
5570 if (GPR_P (src_regno))
5571 {
5572 if (((src_regno - GPR_FIRST) & 1) == 0
5573 && dbl_memory_one_insn_operand (dest, mode))
5574 return "std%I0%U0 %1, %M0";
5575
5576 return "#";
5577 }
5578
5579 if (FPR_P (src_regno))
5580 {
5581 if (((src_regno - FPR_FIRST) & 1) == 0
5582 && dbl_memory_one_insn_operand (dest, mode))
5583 return "stdf%I0%U0 %1, %M0";
5584
5585 return "#";
5586 }
5587 }
5588
5589 else if (ZERO_P (src))
5590 {
5591 if (dbl_memory_one_insn_operand (dest, mode))
5592 return "std%I0%U0 %., %M0";
5593
5594 return "#";
5595 }
5596 }
5597
5598 fatal_insn ("Bad output_move_double operand", insn);
5599 return "";
5600 }
5601
5602 \f
5603 /* Return a string to output a single word conditional move.
5604 Operand0 -- EQ/NE of ccr register and 0
5605 Operand1 -- CCR register
5606 Operand2 -- destination
5607 Operand3 -- source */
5608
5609 const char *
5610 output_condmove_single (rtx operands[], rtx insn)
5611 {
5612 rtx dest = operands[2];
5613 rtx src = operands[3];
5614
5615 if (GET_CODE (dest) == REG)
5616 {
5617 int dest_regno = REGNO (dest);
5618 enum machine_mode mode = GET_MODE (dest);
5619
5620 if (GPR_P (dest_regno))
5621 {
5622 if (GET_CODE (src) == REG)
5623 {
5624 /* gpr <- some sort of register */
5625 int src_regno = REGNO (src);
5626
5627 if (GPR_P (src_regno))
5628 return "cmov %z3, %2, %1, %e0";
5629
5630 else if (FPR_P (src_regno))
5631 return "cmovfg %3, %2, %1, %e0";
5632 }
5633
5634 else if (GET_CODE (src) == MEM)
5635 {
5636 /* gpr <- memory */
5637 switch (mode)
5638 {
5639 default:
5640 break;
5641
5642 case QImode:
5643 return "cldsb%I3%U3 %M3, %2, %1, %e0";
5644
5645 case HImode:
5646 return "cldsh%I3%U3 %M3, %2, %1, %e0";
5647
5648 case SImode:
5649 case SFmode:
5650 return "cld%I3%U3 %M3, %2, %1, %e0";
5651 }
5652 }
5653
5654 else if (ZERO_P (src))
5655 return "cmov %., %2, %1, %e0";
5656 }
5657
5658 else if (FPR_P (dest_regno))
5659 {
5660 if (GET_CODE (src) == REG)
5661 {
5662 /* fpr <- some sort of register */
5663 int src_regno = REGNO (src);
5664
5665 if (GPR_P (src_regno))
5666 return "cmovgf %3, %2, %1, %e0";
5667
5668 else if (FPR_P (src_regno))
5669 {
5670 if (TARGET_HARD_FLOAT)
5671 return "cfmovs %3,%2,%1,%e0";
5672 else
5673 return "cmor %3, %3, %2, %1, %e0";
5674 }
5675 }
5676
5677 else if (GET_CODE (src) == MEM)
5678 {
5679 /* fpr <- memory */
5680 if (mode == SImode || mode == SFmode)
5681 return "cldf%I3%U3 %M3, %2, %1, %e0";
5682 }
5683
5684 else if (ZERO_P (src))
5685 return "cmovgf %., %2, %1, %e0";
5686 }
5687 }
5688
5689 else if (GET_CODE (dest) == MEM)
5690 {
5691 if (GET_CODE (src) == REG)
5692 {
5693 int src_regno = REGNO (src);
5694 enum machine_mode mode = GET_MODE (dest);
5695
5696 if (GPR_P (src_regno))
5697 {
5698 switch (mode)
5699 {
5700 default:
5701 break;
5702
5703 case QImode:
5704 return "cstb%I2%U2 %3, %M2, %1, %e0";
5705
5706 case HImode:
5707 return "csth%I2%U2 %3, %M2, %1, %e0";
5708
5709 case SImode:
5710 case SFmode:
5711 return "cst%I2%U2 %3, %M2, %1, %e0";
5712 }
5713 }
5714
5715 else if (FPR_P (src_regno) && (mode == SImode || mode == SFmode))
5716 return "cstf%I2%U2 %3, %M2, %1, %e0";
5717 }
5718
5719 else if (ZERO_P (src))
5720 {
5721 enum machine_mode mode = GET_MODE (dest);
5722 switch (mode)
5723 {
5724 default:
5725 break;
5726
5727 case QImode:
5728 return "cstb%I2%U2 %., %M2, %1, %e0";
5729
5730 case HImode:
5731 return "csth%I2%U2 %., %M2, %1, %e0";
5732
5733 case SImode:
5734 case SFmode:
5735 return "cst%I2%U2 %., %M2, %1, %e0";
5736 }
5737 }
5738 }
5739
5740 fatal_insn ("Bad output_condmove_single operand", insn);
5741 return "";
5742 }
5743
5744 \f
5745 /* Emit the appropriate code to do a comparison, returning the register the
5746 comparison was done it. */
5747
5748 static rtx
5749 frv_emit_comparison (enum rtx_code test, rtx op0, rtx op1)
5750 {
5751 enum machine_mode cc_mode;
5752 rtx cc_reg;
5753
5754 /* Floating point doesn't have comparison against a constant */
5755 if (GET_MODE (op0) == CC_FPmode && GET_CODE (op1) != REG)
5756 op1 = force_reg (GET_MODE (op0), op1);
5757
5758 /* Possibly disable using anything but a fixed register in order to work
5759 around cse moving comparisons past function calls. */
5760 cc_mode = SELECT_CC_MODE (test, op0, op1);
5761 cc_reg = ((TARGET_ALLOC_CC)
5762 ? gen_reg_rtx (cc_mode)
5763 : gen_rtx_REG (cc_mode,
5764 (cc_mode == CC_FPmode) ? FCC_FIRST : ICC_FIRST));
5765
5766 emit_insn (gen_rtx_SET (VOIDmode, cc_reg,
5767 gen_rtx_COMPARE (cc_mode, op0, op1)));
5768
5769 return cc_reg;
5770 }
5771
5772 \f
5773 /* Emit code for a conditional branch. The comparison operands were previously
5774 stored in frv_compare_op0 and frv_compare_op1.
5775
5776 XXX: I originally wanted to add a clobber of a CCR register to use in
5777 conditional execution, but that confuses the rest of the compiler. */
5778
5779 int
5780 frv_emit_cond_branch (enum rtx_code test, rtx label)
5781 {
5782 rtx test_rtx;
5783 rtx label_ref;
5784 rtx if_else;
5785 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
5786 enum machine_mode cc_mode = GET_MODE (cc_reg);
5787
5788 /* Branches generate:
5789 (set (pc)
5790 (if_then_else (<test>, <cc_reg>, (const_int 0))
5791 (label_ref <branch_label>)
5792 (pc))) */
5793 label_ref = gen_rtx_LABEL_REF (VOIDmode, label);
5794 test_rtx = gen_rtx (test, cc_mode, cc_reg, const0_rtx);
5795 if_else = gen_rtx_IF_THEN_ELSE (cc_mode, test_rtx, label_ref, pc_rtx);
5796 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, if_else));
5797 return TRUE;
5798 }
5799
5800 \f
5801 /* Emit code to set a gpr to 1/0 based on a comparison. The comparison
5802 operands were previously stored in frv_compare_op0 and frv_compare_op1. */
5803
5804 int
5805 frv_emit_scc (enum rtx_code test, rtx target)
5806 {
5807 rtx set;
5808 rtx test_rtx;
5809 rtx clobber;
5810 rtx cr_reg;
5811 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
5812
5813 /* SCC instructions generate:
5814 (parallel [(set <target> (<test>, <cc_reg>, (const_int 0))
5815 (clobber (<ccr_reg>))]) */
5816 test_rtx = gen_rtx_fmt_ee (test, SImode, cc_reg, const0_rtx);
5817 set = gen_rtx_SET (VOIDmode, target, test_rtx);
5818
5819 cr_reg = ((TARGET_ALLOC_CC)
5820 ? gen_reg_rtx (CC_CCRmode)
5821 : gen_rtx_REG (CC_CCRmode,
5822 ((GET_MODE (cc_reg) == CC_FPmode)
5823 ? FCR_FIRST
5824 : ICR_FIRST)));
5825
5826 clobber = gen_rtx_CLOBBER (VOIDmode, cr_reg);
5827 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber)));
5828 return TRUE;
5829 }
5830
5831 \f
5832 /* Split a SCC instruction into component parts, returning a SEQUENCE to hold
5833 the separate insns. */
5834
5835 rtx
5836 frv_split_scc (rtx dest, rtx test, rtx cc_reg, rtx cr_reg, HOST_WIDE_INT value)
5837 {
5838 rtx ret;
5839
5840 start_sequence ();
5841
5842 /* Set the appropriate CCR bit. */
5843 emit_insn (gen_rtx_SET (VOIDmode,
5844 cr_reg,
5845 gen_rtx_fmt_ee (GET_CODE (test),
5846 GET_MODE (cr_reg),
5847 cc_reg,
5848 const0_rtx)));
5849
5850 /* Move the value into the destination. */
5851 emit_move_insn (dest, GEN_INT (value));
5852
5853 /* Move 0 into the destination if the test failed */
5854 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
5855 gen_rtx_EQ (GET_MODE (cr_reg),
5856 cr_reg,
5857 const0_rtx),
5858 gen_rtx_SET (VOIDmode, dest, const0_rtx)));
5859
5860 /* Finish up, return sequence. */
5861 ret = get_insns ();
5862 end_sequence ();
5863 return ret;
5864 }
5865
5866 \f
5867 /* Emit the code for a conditional move, return TRUE if we could do the
5868 move. */
5869
5870 int
5871 frv_emit_cond_move (rtx dest, rtx test_rtx, rtx src1, rtx src2)
5872 {
5873 rtx set;
5874 rtx clobber_cc;
5875 rtx test2;
5876 rtx cr_reg;
5877 rtx if_rtx;
5878 enum rtx_code test = GET_CODE (test_rtx);
5879 rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1);
5880 enum machine_mode cc_mode = GET_MODE (cc_reg);
5881
5882 /* Conditional move instructions generate:
5883 (parallel [(set <target>
5884 (if_then_else (<test> <cc_reg> (const_int 0))
5885 <src1>
5886 <src2>))
5887 (clobber (<ccr_reg>))]) */
5888
5889 /* Handle various cases of conditional move involving two constants. */
5890 if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT)
5891 {
5892 HOST_WIDE_INT value1 = INTVAL (src1);
5893 HOST_WIDE_INT value2 = INTVAL (src2);
5894
5895 /* having 0 as one of the constants can be done by loading the other
5896 constant, and optionally moving in gr0. */
5897 if (value1 == 0 || value2 == 0)
5898 ;
5899
5900 /* If the first value is within an addi range and also the difference
5901 between the two fits in an addi's range, load up the difference, then
5902 conditionally move in 0, and then unconditionally add the first
5903 value. */
5904 else if (IN_RANGE_P (value1, -2048, 2047)
5905 && IN_RANGE_P (value2 - value1, -2048, 2047))
5906 ;
5907
5908 /* If neither condition holds, just force the constant into a
5909 register. */
5910 else
5911 {
5912 src1 = force_reg (GET_MODE (dest), src1);
5913 src2 = force_reg (GET_MODE (dest), src2);
5914 }
5915 }
5916
5917 /* If one value is a register, insure the other value is either 0 or a
5918 register. */
5919 else
5920 {
5921 if (GET_CODE (src1) == CONST_INT && INTVAL (src1) != 0)
5922 src1 = force_reg (GET_MODE (dest), src1);
5923
5924 if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0)
5925 src2 = force_reg (GET_MODE (dest), src2);
5926 }
5927
5928 test2 = gen_rtx_fmt_ee (test, cc_mode, cc_reg, const0_rtx);
5929 if_rtx = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), test2, src1, src2);
5930
5931 set = gen_rtx_SET (VOIDmode, dest, if_rtx);
5932
5933 cr_reg = ((TARGET_ALLOC_CC)
5934 ? gen_reg_rtx (CC_CCRmode)
5935 : gen_rtx_REG (CC_CCRmode,
5936 (cc_mode == CC_FPmode) ? FCR_FIRST : ICR_FIRST));
5937
5938 clobber_cc = gen_rtx_CLOBBER (VOIDmode, cr_reg);
5939 emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber_cc)));
5940 return TRUE;
5941 }
5942
5943 \f
5944 /* Split a conditional move into constituent parts, returning a SEQUENCE
5945 containing all of the insns. */
5946
5947 rtx
5948 frv_split_cond_move (rtx operands[])
5949 {
5950 rtx dest = operands[0];
5951 rtx test = operands[1];
5952 rtx cc_reg = operands[2];
5953 rtx src1 = operands[3];
5954 rtx src2 = operands[4];
5955 rtx cr_reg = operands[5];
5956 rtx ret;
5957 enum machine_mode cr_mode = GET_MODE (cr_reg);
5958
5959 start_sequence ();
5960
5961 /* Set the appropriate CCR bit. */
5962 emit_insn (gen_rtx_SET (VOIDmode,
5963 cr_reg,
5964 gen_rtx_fmt_ee (GET_CODE (test),
5965 GET_MODE (cr_reg),
5966 cc_reg,
5967 const0_rtx)));
5968
5969 /* Handle various cases of conditional move involving two constants. */
5970 if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT)
5971 {
5972 HOST_WIDE_INT value1 = INTVAL (src1);
5973 HOST_WIDE_INT value2 = INTVAL (src2);
5974
5975 /* having 0 as one of the constants can be done by loading the other
5976 constant, and optionally moving in gr0. */
5977 if (value1 == 0)
5978 {
5979 emit_move_insn (dest, src2);
5980 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
5981 gen_rtx_NE (cr_mode, cr_reg,
5982 const0_rtx),
5983 gen_rtx_SET (VOIDmode, dest, src1)));
5984 }
5985
5986 else if (value2 == 0)
5987 {
5988 emit_move_insn (dest, src1);
5989 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
5990 gen_rtx_EQ (cr_mode, cr_reg,
5991 const0_rtx),
5992 gen_rtx_SET (VOIDmode, dest, src2)));
5993 }
5994
5995 /* If the first value is within an addi range and also the difference
5996 between the two fits in an addi's range, load up the difference, then
5997 conditionally move in 0, and then unconditionally add the first
5998 value. */
5999 else if (IN_RANGE_P (value1, -2048, 2047)
6000 && IN_RANGE_P (value2 - value1, -2048, 2047))
6001 {
6002 rtx dest_si = ((GET_MODE (dest) == SImode)
6003 ? dest
6004 : gen_rtx_SUBREG (SImode, dest, 0));
6005
6006 emit_move_insn (dest_si, GEN_INT (value2 - value1));
6007 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6008 gen_rtx_NE (cr_mode, cr_reg,
6009 const0_rtx),
6010 gen_rtx_SET (VOIDmode, dest_si,
6011 const0_rtx)));
6012 emit_insn (gen_addsi3 (dest_si, dest_si, src1));
6013 }
6014
6015 else
6016 abort ();
6017 }
6018 else
6019 {
6020 /* Emit the conditional move for the test being true if needed. */
6021 if (! rtx_equal_p (dest, src1))
6022 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6023 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6024 gen_rtx_SET (VOIDmode, dest, src1)));
6025
6026 /* Emit the conditional move for the test being false if needed. */
6027 if (! rtx_equal_p (dest, src2))
6028 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6029 gen_rtx_EQ (cr_mode, cr_reg, const0_rtx),
6030 gen_rtx_SET (VOIDmode, dest, src2)));
6031 }
6032
6033 /* Finish up, return sequence. */
6034 ret = get_insns ();
6035 end_sequence ();
6036 return ret;
6037 }
6038
6039 \f
6040 /* Split (set DEST SOURCE), where DEST is a double register and SOURCE is a
6041 memory location that is not known to be dword-aligned. */
6042 void
6043 frv_split_double_load (rtx dest, rtx source)
6044 {
6045 int regno = REGNO (dest);
6046 rtx dest1 = gen_highpart (SImode, dest);
6047 rtx dest2 = gen_lowpart (SImode, dest);
6048 rtx address = XEXP (source, 0);
6049
6050 /* If the address is pre-modified, load the lower-numbered register
6051 first, then load the other register using an integer offset from
6052 the modified base register. This order should always be safe,
6053 since the pre-modification cannot affect the same registers as the
6054 load does.
6055
6056 The situation for other loads is more complicated. Loading one
6057 of the registers could affect the value of ADDRESS, so we must
6058 be careful which order we do them in. */
6059 if (GET_CODE (address) == PRE_MODIFY
6060 || ! refers_to_regno_p (regno, regno + 1, address, NULL))
6061 {
6062 /* It is safe to load the lower-numbered register first. */
6063 emit_move_insn (dest1, change_address (source, SImode, NULL));
6064 emit_move_insn (dest2, frv_index_memory (source, SImode, 1));
6065 }
6066 else
6067 {
6068 /* ADDRESS is not pre-modified and the address depends on the
6069 lower-numbered register. Load the higher-numbered register
6070 first. */
6071 emit_move_insn (dest2, frv_index_memory (source, SImode, 1));
6072 emit_move_insn (dest1, change_address (source, SImode, NULL));
6073 }
6074 }
6075
6076 /* Split (set DEST SOURCE), where DEST refers to a dword memory location
6077 and SOURCE is either a double register or the constant zero. */
6078 void
6079 frv_split_double_store (rtx dest, rtx source)
6080 {
6081 rtx dest1 = change_address (dest, SImode, NULL);
6082 rtx dest2 = frv_index_memory (dest, SImode, 1);
6083 if (ZERO_P (source))
6084 {
6085 emit_move_insn (dest1, CONST0_RTX (SImode));
6086 emit_move_insn (dest2, CONST0_RTX (SImode));
6087 }
6088 else
6089 {
6090 emit_move_insn (dest1, gen_highpart (SImode, source));
6091 emit_move_insn (dest2, gen_lowpart (SImode, source));
6092 }
6093 }
6094
6095 \f
6096 /* Split a min/max operation returning a SEQUENCE containing all of the
6097 insns. */
6098
6099 rtx
6100 frv_split_minmax (rtx operands[])
6101 {
6102 rtx dest = operands[0];
6103 rtx minmax = operands[1];
6104 rtx src1 = operands[2];
6105 rtx src2 = operands[3];
6106 rtx cc_reg = operands[4];
6107 rtx cr_reg = operands[5];
6108 rtx ret;
6109 enum rtx_code test_code;
6110 enum machine_mode cr_mode = GET_MODE (cr_reg);
6111
6112 start_sequence ();
6113
6114 /* Figure out which test to use */
6115 switch (GET_CODE (minmax))
6116 {
6117 default:
6118 abort ();
6119
6120 case SMIN: test_code = LT; break;
6121 case SMAX: test_code = GT; break;
6122 case UMIN: test_code = LTU; break;
6123 case UMAX: test_code = GTU; break;
6124 }
6125
6126 /* Issue the compare instruction. */
6127 emit_insn (gen_rtx_SET (VOIDmode,
6128 cc_reg,
6129 gen_rtx_COMPARE (GET_MODE (cc_reg),
6130 src1, src2)));
6131
6132 /* Set the appropriate CCR bit. */
6133 emit_insn (gen_rtx_SET (VOIDmode,
6134 cr_reg,
6135 gen_rtx_fmt_ee (test_code,
6136 GET_MODE (cr_reg),
6137 cc_reg,
6138 const0_rtx)));
6139
6140 /* If are taking the min/max of a nonzero constant, load that first, and
6141 then do a conditional move of the other value. */
6142 if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0)
6143 {
6144 if (rtx_equal_p (dest, src1))
6145 abort ();
6146
6147 emit_move_insn (dest, src2);
6148 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6149 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6150 gen_rtx_SET (VOIDmode, dest, src1)));
6151 }
6152
6153 /* Otherwise, do each half of the move. */
6154 else
6155 {
6156 /* Emit the conditional move for the test being true if needed. */
6157 if (! rtx_equal_p (dest, src1))
6158 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6159 gen_rtx_NE (cr_mode, cr_reg, const0_rtx),
6160 gen_rtx_SET (VOIDmode, dest, src1)));
6161
6162 /* Emit the conditional move for the test being false if needed. */
6163 if (! rtx_equal_p (dest, src2))
6164 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6165 gen_rtx_EQ (cr_mode, cr_reg, const0_rtx),
6166 gen_rtx_SET (VOIDmode, dest, src2)));
6167 }
6168
6169 /* Finish up, return sequence. */
6170 ret = get_insns ();
6171 end_sequence ();
6172 return ret;
6173 }
6174
6175 \f
6176 /* Split an integer abs operation returning a SEQUENCE containing all of the
6177 insns. */
6178
6179 rtx
6180 frv_split_abs (rtx operands[])
6181 {
6182 rtx dest = operands[0];
6183 rtx src = operands[1];
6184 rtx cc_reg = operands[2];
6185 rtx cr_reg = operands[3];
6186 rtx ret;
6187
6188 start_sequence ();
6189
6190 /* Issue the compare < 0 instruction. */
6191 emit_insn (gen_rtx_SET (VOIDmode,
6192 cc_reg,
6193 gen_rtx_COMPARE (CCmode, src, const0_rtx)));
6194
6195 /* Set the appropriate CCR bit. */
6196 emit_insn (gen_rtx_SET (VOIDmode,
6197 cr_reg,
6198 gen_rtx_fmt_ee (LT, CC_CCRmode, cc_reg, const0_rtx)));
6199
6200 /* Emit the conditional negate if the value is negative */
6201 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6202 gen_rtx_NE (CC_CCRmode, cr_reg, const0_rtx),
6203 gen_negsi2 (dest, src)));
6204
6205 /* Emit the conditional move for the test being false if needed. */
6206 if (! rtx_equal_p (dest, src))
6207 emit_insn (gen_rtx_COND_EXEC (VOIDmode,
6208 gen_rtx_EQ (CC_CCRmode, cr_reg, const0_rtx),
6209 gen_rtx_SET (VOIDmode, dest, src)));
6210
6211 /* Finish up, return sequence. */
6212 ret = get_insns ();
6213 end_sequence ();
6214 return ret;
6215 }
6216
6217 \f
6218 /* An internal function called by for_each_rtx to clear in a hard_reg set each
6219 register used in an insn. */
6220
6221 static int
6222 frv_clear_registers_used (rtx *ptr, void *data)
6223 {
6224 if (GET_CODE (*ptr) == REG)
6225 {
6226 int regno = REGNO (*ptr);
6227 HARD_REG_SET *p_regs = (HARD_REG_SET *)data;
6228
6229 if (regno < FIRST_PSEUDO_REGISTER)
6230 {
6231 int reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (*ptr));
6232
6233 while (regno < reg_max)
6234 {
6235 CLEAR_HARD_REG_BIT (*p_regs, regno);
6236 regno++;
6237 }
6238 }
6239 }
6240
6241 return 0;
6242 }
6243
6244 \f
6245 /* Initialize the extra fields provided by IFCVT_EXTRA_FIELDS. */
6246
6247 /* On the FR-V, we don't have any extra fields per se, but it is useful hook to
6248 initialize the static storage. */
6249 void
6250 frv_ifcvt_init_extra_fields (ce_if_block_t *ce_info ATTRIBUTE_UNUSED)
6251 {
6252 frv_ifcvt.added_insns_list = NULL_RTX;
6253 frv_ifcvt.cur_scratch_regs = 0;
6254 frv_ifcvt.num_nested_cond_exec = 0;
6255 frv_ifcvt.cr_reg = NULL_RTX;
6256 frv_ifcvt.nested_cc_reg = NULL_RTX;
6257 frv_ifcvt.extra_int_cr = NULL_RTX;
6258 frv_ifcvt.extra_fp_cr = NULL_RTX;
6259 frv_ifcvt.last_nested_if_cr = NULL_RTX;
6260 }
6261
6262 \f
6263 /* Internal function to add a potenial insn to the list of insns to be inserted
6264 if the conditional execution conversion is successful. */
6265
6266 static void
6267 frv_ifcvt_add_insn (rtx pattern, rtx insn, int before_p)
6268 {
6269 rtx link = alloc_EXPR_LIST (VOIDmode, pattern, insn);
6270
6271 link->jump = before_p; /* mark to add this before or after insn */
6272 frv_ifcvt.added_insns_list = alloc_EXPR_LIST (VOIDmode, link,
6273 frv_ifcvt.added_insns_list);
6274
6275 if (TARGET_DEBUG_COND_EXEC)
6276 {
6277 fprintf (stderr,
6278 "\n:::::::::: frv_ifcvt_add_insn: add the following %s insn %d:\n",
6279 (before_p) ? "before" : "after",
6280 (int)INSN_UID (insn));
6281
6282 debug_rtx (pattern);
6283 }
6284 }
6285
6286 \f
6287 /* A C expression to modify the code described by the conditional if
6288 information CE_INFO, possibly updating the tests in TRUE_EXPR, and
6289 FALSE_EXPR for converting if-then and if-then-else code to conditional
6290 instructions. Set either TRUE_EXPR or FALSE_EXPR to a null pointer if the
6291 tests cannot be converted. */
6292
6293 void
6294 frv_ifcvt_modify_tests (ce_if_block_t *ce_info, rtx *p_true, rtx *p_false)
6295 {
6296 basic_block test_bb = ce_info->test_bb; /* test basic block */
6297 basic_block then_bb = ce_info->then_bb; /* THEN */
6298 basic_block else_bb = ce_info->else_bb; /* ELSE or NULL */
6299 basic_block join_bb = ce_info->join_bb; /* join block or NULL */
6300 rtx true_expr = *p_true;
6301 rtx cr;
6302 rtx cc;
6303 rtx nested_cc;
6304 enum machine_mode mode = GET_MODE (true_expr);
6305 int j;
6306 basic_block *bb;
6307 int num_bb;
6308 frv_tmp_reg_t *tmp_reg = &frv_ifcvt.tmp_reg;
6309 rtx check_insn;
6310 rtx sub_cond_exec_reg;
6311 enum rtx_code code;
6312 enum rtx_code code_true;
6313 enum rtx_code code_false;
6314 enum reg_class cc_class;
6315 enum reg_class cr_class;
6316 int cc_first;
6317 int cc_last;
6318
6319 /* Make sure we are only dealing with hard registers. Also honor the
6320 -mno-cond-exec switch, and -mno-nested-cond-exec switches if
6321 applicable. */
6322 if (!reload_completed || TARGET_NO_COND_EXEC
6323 || (TARGET_NO_NESTED_CE && ce_info->pass > 1))
6324 goto fail;
6325
6326 /* Figure out which registers we can allocate for our own purposes. Only
6327 consider registers that are not preserved across function calls and are
6328 not fixed. However, allow the ICC/ICR temporary registers to be allocated
6329 if we did not need to use them in reloading other registers. */
6330 memset (&tmp_reg->regs, 0, sizeof (tmp_reg->regs));
6331 COPY_HARD_REG_SET (tmp_reg->regs, call_used_reg_set);
6332 AND_COMPL_HARD_REG_SET (tmp_reg->regs, fixed_reg_set);
6333 SET_HARD_REG_BIT (tmp_reg->regs, ICC_TEMP);
6334 SET_HARD_REG_BIT (tmp_reg->regs, ICR_TEMP);
6335
6336 /* If this is a nested IF, we need to discover whether the CC registers that
6337 are set/used inside of the block are used anywhere else. If not, we can
6338 change them to be the CC register that is paired with the CR register that
6339 controls the outermost IF block. */
6340 if (ce_info->pass > 1)
6341 {
6342 CLEAR_HARD_REG_SET (frv_ifcvt.nested_cc_ok_rewrite);
6343 for (j = CC_FIRST; j <= CC_LAST; j++)
6344 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6345 {
6346 if (REGNO_REG_SET_P (then_bb->global_live_at_start, j))
6347 continue;
6348
6349 if (else_bb && REGNO_REG_SET_P (else_bb->global_live_at_start, j))
6350 continue;
6351
6352 if (join_bb && REGNO_REG_SET_P (join_bb->global_live_at_start, j))
6353 continue;
6354
6355 SET_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j);
6356 }
6357 }
6358
6359 for (j = 0; j < frv_ifcvt.cur_scratch_regs; j++)
6360 frv_ifcvt.scratch_regs[j] = NULL_RTX;
6361
6362 frv_ifcvt.added_insns_list = NULL_RTX;
6363 frv_ifcvt.cur_scratch_regs = 0;
6364
6365 bb = (basic_block *) alloca ((2 + ce_info->num_multiple_test_blocks)
6366 * sizeof (basic_block));
6367
6368 if (join_bb)
6369 {
6370 int regno;
6371
6372 /* Remove anything live at the beginning of the join block from being
6373 available for allocation. */
6374 EXECUTE_IF_SET_IN_REG_SET (join_bb->global_live_at_start, 0, regno,
6375 {
6376 if (regno < FIRST_PSEUDO_REGISTER)
6377 CLEAR_HARD_REG_BIT (tmp_reg->regs, regno);
6378 });
6379 }
6380
6381 /* Add in all of the blocks in multiple &&/|| blocks to be scanned. */
6382 num_bb = 0;
6383 if (ce_info->num_multiple_test_blocks)
6384 {
6385 basic_block multiple_test_bb = ce_info->last_test_bb;
6386
6387 while (multiple_test_bb != test_bb)
6388 {
6389 bb[num_bb++] = multiple_test_bb;
6390 multiple_test_bb = multiple_test_bb->pred->src;
6391 }
6392 }
6393
6394 /* Add in the THEN and ELSE blocks to be scanned. */
6395 bb[num_bb++] = then_bb;
6396 if (else_bb)
6397 bb[num_bb++] = else_bb;
6398
6399 sub_cond_exec_reg = NULL_RTX;
6400 frv_ifcvt.num_nested_cond_exec = 0;
6401
6402 /* Scan all of the blocks for registers that must not be allocated. */
6403 for (j = 0; j < num_bb; j++)
6404 {
6405 rtx last_insn = BB_END (bb[j]);
6406 rtx insn = BB_HEAD (bb[j]);
6407 int regno;
6408
6409 if (rtl_dump_file)
6410 fprintf (rtl_dump_file, "Scanning %s block %d, start %d, end %d\n",
6411 (bb[j] == else_bb) ? "else" : ((bb[j] == then_bb) ? "then" : "test"),
6412 (int) bb[j]->index,
6413 (int) INSN_UID (BB_HEAD (bb[j])),
6414 (int) INSN_UID (BB_END (bb[j])));
6415
6416 /* Anything live at the beginning of the block is obviously unavailable
6417 for allocation. */
6418 EXECUTE_IF_SET_IN_REG_SET (bb[j]->global_live_at_start, 0, regno,
6419 {
6420 if (regno < FIRST_PSEUDO_REGISTER)
6421 CLEAR_HARD_REG_BIT (tmp_reg->regs, regno);
6422 });
6423
6424 /* loop through the insns in the block. */
6425 for (;;)
6426 {
6427 /* Mark any new registers that are created as being unavailable for
6428 allocation. Also see if the CC register used in nested IFs can be
6429 reallocated. */
6430 if (INSN_P (insn))
6431 {
6432 rtx pattern;
6433 rtx set;
6434 int skip_nested_if = FALSE;
6435
6436 for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
6437 (void *)&tmp_reg->regs);
6438
6439 pattern = PATTERN (insn);
6440 if (GET_CODE (pattern) == COND_EXEC)
6441 {
6442 rtx reg = XEXP (COND_EXEC_TEST (pattern), 0);
6443
6444 if (reg != sub_cond_exec_reg)
6445 {
6446 sub_cond_exec_reg = reg;
6447 frv_ifcvt.num_nested_cond_exec++;
6448 }
6449 }
6450
6451 set = single_set_pattern (pattern);
6452 if (set)
6453 {
6454 rtx dest = SET_DEST (set);
6455 rtx src = SET_SRC (set);
6456
6457 if (GET_CODE (dest) == REG)
6458 {
6459 int regno = REGNO (dest);
6460 enum rtx_code src_code = GET_CODE (src);
6461
6462 if (CC_P (regno) && src_code == COMPARE)
6463 skip_nested_if = TRUE;
6464
6465 else if (CR_P (regno)
6466 && (src_code == IF_THEN_ELSE
6467 || GET_RTX_CLASS (src_code) == '<'))
6468 skip_nested_if = TRUE;
6469 }
6470 }
6471
6472 if (! skip_nested_if)
6473 for_each_rtx (&PATTERN (insn), frv_clear_registers_used,
6474 (void *)&frv_ifcvt.nested_cc_ok_rewrite);
6475 }
6476
6477 if (insn == last_insn)
6478 break;
6479
6480 insn = NEXT_INSN (insn);
6481 }
6482 }
6483
6484 /* If this is a nested if, rewrite the CC registers that are available to
6485 include the ones that can be rewritten, to increase the chance of being
6486 able to allocate a paired CC/CR register combination. */
6487 if (ce_info->pass > 1)
6488 {
6489 for (j = CC_FIRST; j <= CC_LAST; j++)
6490 if (TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j))
6491 SET_HARD_REG_BIT (tmp_reg->regs, j);
6492 else
6493 CLEAR_HARD_REG_BIT (tmp_reg->regs, j);
6494 }
6495
6496 if (rtl_dump_file)
6497 {
6498 int num_gprs = 0;
6499 fprintf (rtl_dump_file, "Available GPRs: ");
6500
6501 for (j = GPR_FIRST; j <= GPR_LAST; j++)
6502 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6503 {
6504 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6505 if (++num_gprs > GPR_TEMP_NUM+2)
6506 break;
6507 }
6508
6509 fprintf (rtl_dump_file, "%s\nAvailable CRs: ",
6510 (num_gprs > GPR_TEMP_NUM+2) ? " ..." : "");
6511
6512 for (j = CR_FIRST; j <= CR_LAST; j++)
6513 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6514 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6515
6516 fputs ("\n", rtl_dump_file);
6517
6518 if (ce_info->pass > 1)
6519 {
6520 fprintf (rtl_dump_file, "Modifiable CCs: ");
6521 for (j = CC_FIRST; j <= CC_LAST; j++)
6522 if (TEST_HARD_REG_BIT (tmp_reg->regs, j))
6523 fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]);
6524
6525 fprintf (rtl_dump_file, "\n%d nested COND_EXEC statements\n",
6526 frv_ifcvt.num_nested_cond_exec);
6527 }
6528 }
6529
6530 /* Allocate the appropriate temporary condition code register. Try to
6531 allocate the ICR/FCR register that corresponds to the ICC/FCC register so
6532 that conditional cmp's can be done. */
6533 if (mode == CCmode || mode == CC_UNSmode)
6534 {
6535 cr_class = ICR_REGS;
6536 cc_class = ICC_REGS;
6537 cc_first = ICC_FIRST;
6538 cc_last = ICC_LAST;
6539 }
6540 else if (mode == CC_FPmode)
6541 {
6542 cr_class = FCR_REGS;
6543 cc_class = FCC_REGS;
6544 cc_first = FCC_FIRST;
6545 cc_last = FCC_LAST;
6546 }
6547 else
6548 {
6549 cc_first = cc_last = 0;
6550 cr_class = cc_class = NO_REGS;
6551 }
6552
6553 cc = XEXP (true_expr, 0);
6554 nested_cc = cr = NULL_RTX;
6555 if (cc_class != NO_REGS)
6556 {
6557 /* For nested IFs and &&/||, see if we can find a CC and CR register pair
6558 so we can execute a csubcc/caddcc/cfcmps instruction. */
6559 int cc_regno;
6560
6561 for (cc_regno = cc_first; cc_regno <= cc_last; cc_regno++)
6562 {
6563 int cr_regno = cc_regno - CC_FIRST + CR_FIRST;
6564
6565 if (TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cc_regno)
6566 && TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cr_regno))
6567 {
6568 frv_ifcvt.tmp_reg.next_reg[ (int)cr_class ] = cr_regno;
6569 cr = frv_alloc_temp_reg (tmp_reg, cr_class, CC_CCRmode, TRUE,
6570 TRUE);
6571
6572 frv_ifcvt.tmp_reg.next_reg[ (int)cc_class ] = cc_regno;
6573 nested_cc = frv_alloc_temp_reg (tmp_reg, cc_class, CCmode,
6574 TRUE, TRUE);
6575 break;
6576 }
6577 }
6578 }
6579
6580 if (! cr)
6581 {
6582 if (rtl_dump_file)
6583 fprintf (rtl_dump_file, "Could not allocate a CR temporary register\n");
6584
6585 goto fail;
6586 }
6587
6588 if (rtl_dump_file)
6589 fprintf (rtl_dump_file,
6590 "Will use %s for conditional execution, %s for nested comparisons\n",
6591 reg_names[ REGNO (cr)],
6592 (nested_cc) ? reg_names[ REGNO (nested_cc) ] : "<none>");
6593
6594 /* Set the CCR bit. Note for integer tests, we reverse the condition so that
6595 in an IF-THEN-ELSE sequence, we are testing the TRUE case against the CCR
6596 bit being true. We don't do this for floating point, because of NaNs. */
6597 code = GET_CODE (true_expr);
6598 if (GET_MODE (cc) != CC_FPmode)
6599 {
6600 code = reverse_condition (code);
6601 code_true = EQ;
6602 code_false = NE;
6603 }
6604 else
6605 {
6606 code_true = NE;
6607 code_false = EQ;
6608 }
6609
6610 check_insn = gen_rtx_SET (VOIDmode, cr,
6611 gen_rtx_fmt_ee (code, CC_CCRmode, cc, const0_rtx));
6612
6613 /* Record the check insn to be inserted later. */
6614 frv_ifcvt_add_insn (check_insn, BB_END (test_bb), TRUE);
6615
6616 /* Update the tests. */
6617 frv_ifcvt.cr_reg = cr;
6618 frv_ifcvt.nested_cc_reg = nested_cc;
6619 *p_true = gen_rtx_fmt_ee (code_true, CC_CCRmode, cr, const0_rtx);
6620 *p_false = gen_rtx_fmt_ee (code_false, CC_CCRmode, cr, const0_rtx);
6621 return;
6622
6623 /* Fail, don't do this conditional execution. */
6624 fail:
6625 *p_true = NULL_RTX;
6626 *p_false = NULL_RTX;
6627 if (rtl_dump_file)
6628 fprintf (rtl_dump_file, "Disabling this conditional execution.\n");
6629
6630 return;
6631 }
6632
6633 \f
6634 /* A C expression to modify the code described by the conditional if
6635 information CE_INFO, for the basic block BB, possibly updating the tests in
6636 TRUE_EXPR, and FALSE_EXPR for converting the && and || parts of if-then or
6637 if-then-else code to conditional instructions. Set either TRUE_EXPR or
6638 FALSE_EXPR to a null pointer if the tests cannot be converted. */
6639
6640 /* p_true and p_false are given expressions of the form:
6641
6642 (and (eq:CC_CCR (reg:CC_CCR)
6643 (const_int 0))
6644 (eq:CC (reg:CC)
6645 (const_int 0))) */
6646
6647 void
6648 frv_ifcvt_modify_multiple_tests (ce_if_block_t *ce_info,
6649 basic_block bb,
6650 rtx *p_true,
6651 rtx *p_false)
6652 {
6653 rtx old_true = XEXP (*p_true, 0);
6654 rtx old_false = XEXP (*p_false, 0);
6655 rtx true_expr = XEXP (*p_true, 1);
6656 rtx false_expr = XEXP (*p_false, 1);
6657 rtx test_expr;
6658 rtx old_test;
6659 rtx cr = XEXP (old_true, 0);
6660 rtx check_insn;
6661 rtx new_cr = NULL_RTX;
6662 rtx *p_new_cr = (rtx *)0;
6663 rtx if_else;
6664 rtx compare;
6665 rtx cc;
6666 enum reg_class cr_class;
6667 enum machine_mode mode = GET_MODE (true_expr);
6668 rtx (*logical_func)(rtx, rtx, rtx);
6669
6670 if (TARGET_DEBUG_COND_EXEC)
6671 {
6672 fprintf (stderr,
6673 "\n:::::::::: frv_ifcvt_modify_multiple_tests, before modification for %s\ntrue insn:\n",
6674 ce_info->and_and_p ? "&&" : "||");
6675
6676 debug_rtx (*p_true);
6677
6678 fputs ("\nfalse insn:\n", stderr);
6679 debug_rtx (*p_false);
6680 }
6681
6682 if (TARGET_NO_MULTI_CE)
6683 goto fail;
6684
6685 if (GET_CODE (cr) != REG)
6686 goto fail;
6687
6688 if (mode == CCmode || mode == CC_UNSmode)
6689 {
6690 cr_class = ICR_REGS;
6691 p_new_cr = &frv_ifcvt.extra_int_cr;
6692 }
6693 else if (mode == CC_FPmode)
6694 {
6695 cr_class = FCR_REGS;
6696 p_new_cr = &frv_ifcvt.extra_fp_cr;
6697 }
6698 else
6699 goto fail;
6700
6701 /* Allocate a temp CR, reusing a previously allocated temp CR if we have 3 or
6702 more &&/|| tests. */
6703 new_cr = *p_new_cr;
6704 if (! new_cr)
6705 {
6706 new_cr = *p_new_cr = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, cr_class,
6707 CC_CCRmode, TRUE, TRUE);
6708 if (! new_cr)
6709 goto fail;
6710 }
6711
6712 if (ce_info->and_and_p)
6713 {
6714 old_test = old_false;
6715 test_expr = true_expr;
6716 logical_func = (GET_CODE (old_true) == EQ) ? gen_andcr : gen_andncr;
6717 *p_true = gen_rtx_NE (CC_CCRmode, cr, const0_rtx);
6718 *p_false = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx);
6719 }
6720 else
6721 {
6722 old_test = old_false;
6723 test_expr = false_expr;
6724 logical_func = (GET_CODE (old_false) == EQ) ? gen_orcr : gen_orncr;
6725 *p_true = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx);
6726 *p_false = gen_rtx_NE (CC_CCRmode, cr, const0_rtx);
6727 }
6728
6729 /* First add the andcr/andncr/orcr/orncr, which will be added after the
6730 conditional check instruction, due to frv_ifcvt_add_insn being a LIFO
6731 stack. */
6732 frv_ifcvt_add_insn ((*logical_func) (cr, cr, new_cr), BB_END (bb), TRUE);
6733
6734 /* Now add the conditional check insn. */
6735 cc = XEXP (test_expr, 0);
6736 compare = gen_rtx_fmt_ee (GET_CODE (test_expr), CC_CCRmode, cc, const0_rtx);
6737 if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, old_test, compare, const0_rtx);
6738
6739 check_insn = gen_rtx_SET (VOIDmode, new_cr, if_else);
6740
6741 /* add the new check insn to the list of check insns that need to be
6742 inserted. */
6743 frv_ifcvt_add_insn (check_insn, BB_END (bb), TRUE);
6744
6745 if (TARGET_DEBUG_COND_EXEC)
6746 {
6747 fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, after modification\ntrue insn:\n",
6748 stderr);
6749
6750 debug_rtx (*p_true);
6751
6752 fputs ("\nfalse insn:\n", stderr);
6753 debug_rtx (*p_false);
6754 }
6755
6756 return;
6757
6758 fail:
6759 *p_true = *p_false = NULL_RTX;
6760
6761 /* If we allocated a CR register, release it. */
6762 if (new_cr)
6763 {
6764 CLEAR_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, REGNO (new_cr));
6765 *p_new_cr = NULL_RTX;
6766 }
6767
6768 if (TARGET_DEBUG_COND_EXEC)
6769 fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, failed.\n", stderr);
6770
6771 return;
6772 }
6773
6774 \f
6775 /* Return a register which will be loaded with a value if an IF block is
6776 converted to conditional execution. This is used to rewrite instructions
6777 that use constants to ones that just use registers. */
6778
6779 static rtx
6780 frv_ifcvt_load_value (rtx value, rtx insn ATTRIBUTE_UNUSED)
6781 {
6782 int num_alloc = frv_ifcvt.cur_scratch_regs;
6783 int i;
6784 rtx reg;
6785
6786 /* We know gr0 == 0, so replace any errant uses. */
6787 if (value == const0_rtx)
6788 return gen_rtx_REG (SImode, GPR_FIRST);
6789
6790 /* First search all registers currently loaded to see if we have an
6791 applicable constant. */
6792 if (CONSTANT_P (value)
6793 || (GET_CODE (value) == REG && REGNO (value) == LR_REGNO))
6794 {
6795 for (i = 0; i < num_alloc; i++)
6796 {
6797 if (rtx_equal_p (SET_SRC (frv_ifcvt.scratch_regs[i]), value))
6798 return SET_DEST (frv_ifcvt.scratch_regs[i]);
6799 }
6800 }
6801
6802 /* Have we exhausted the number of registers available? */
6803 if (num_alloc >= GPR_TEMP_NUM)
6804 {
6805 if (rtl_dump_file)
6806 fprintf (rtl_dump_file, "Too many temporary registers allocated\n");
6807
6808 return NULL_RTX;
6809 }
6810
6811 /* Allocate the new register. */
6812 reg = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, GPR_REGS, SImode, TRUE, TRUE);
6813 if (! reg)
6814 {
6815 if (rtl_dump_file)
6816 fputs ("Could not find a scratch register\n", rtl_dump_file);
6817
6818 return NULL_RTX;
6819 }
6820
6821 frv_ifcvt.cur_scratch_regs++;
6822 frv_ifcvt.scratch_regs[num_alloc] = gen_rtx_SET (VOIDmode, reg, value);
6823
6824 if (rtl_dump_file)
6825 {
6826 if (GET_CODE (value) == CONST_INT)
6827 fprintf (rtl_dump_file, "Register %s will hold %ld\n",
6828 reg_names[ REGNO (reg)], (long)INTVAL (value));
6829
6830 else if (GET_CODE (value) == REG && REGNO (value) == LR_REGNO)
6831 fprintf (rtl_dump_file, "Register %s will hold LR\n",
6832 reg_names[ REGNO (reg)]);
6833
6834 else
6835 fprintf (rtl_dump_file, "Register %s will hold a saved value\n",
6836 reg_names[ REGNO (reg)]);
6837 }
6838
6839 return reg;
6840 }
6841
6842 \f
6843 /* Update a MEM used in conditional code that might contain an offset to put
6844 the offset into a scratch register, so that the conditional load/store
6845 operations can be used. This function returns the original pointer if the
6846 MEM is valid to use in conditional code, NULL if we can't load up the offset
6847 into a temporary register, or the new MEM if we were successful. */
6848
6849 static rtx
6850 frv_ifcvt_rewrite_mem (rtx mem, enum machine_mode mode, rtx insn)
6851 {
6852 rtx addr = XEXP (mem, 0);
6853
6854 if (!frv_legitimate_address_p (mode, addr, reload_completed, TRUE))
6855 {
6856 if (GET_CODE (addr) == PLUS)
6857 {
6858 rtx addr_op0 = XEXP (addr, 0);
6859 rtx addr_op1 = XEXP (addr, 1);
6860
6861 if (plus_small_data_p (addr_op0, addr_op1))
6862 addr = frv_ifcvt_load_value (addr, insn);
6863
6864 else if (GET_CODE (addr_op0) == REG && CONSTANT_P (addr_op1))
6865 {
6866 rtx reg = frv_ifcvt_load_value (addr_op1, insn);
6867 if (!reg)
6868 return NULL_RTX;
6869
6870 addr = gen_rtx_PLUS (Pmode, addr_op0, reg);
6871 }
6872
6873 else
6874 return NULL_RTX;
6875 }
6876
6877 else if (CONSTANT_P (addr))
6878 addr = frv_ifcvt_load_value (addr, insn);
6879
6880 else
6881 return NULL_RTX;
6882
6883 if (addr == NULL_RTX)
6884 return NULL_RTX;
6885
6886 else if (XEXP (mem, 0) != addr)
6887 return change_address (mem, mode, addr);
6888 }
6889
6890 return mem;
6891 }
6892
6893 \f
6894 /* Given a PATTERN, return a SET expression if this PATTERN has only a single
6895 SET, possibly conditionally executed. It may also have CLOBBERs, USEs. */
6896
6897 static rtx
6898 single_set_pattern (rtx pattern)
6899 {
6900 rtx set;
6901 int i;
6902
6903 if (GET_CODE (pattern) == COND_EXEC)
6904 pattern = COND_EXEC_CODE (pattern);
6905
6906 if (GET_CODE (pattern) == SET)
6907 return pattern;
6908
6909 else if (GET_CODE (pattern) == PARALLEL)
6910 {
6911 for (i = 0, set = 0; i < XVECLEN (pattern, 0); i++)
6912 {
6913 rtx sub = XVECEXP (pattern, 0, i);
6914
6915 switch (GET_CODE (sub))
6916 {
6917 case USE:
6918 case CLOBBER:
6919 break;
6920
6921 case SET:
6922 if (set)
6923 return 0;
6924 else
6925 set = sub;
6926 break;
6927
6928 default:
6929 return 0;
6930 }
6931 }
6932 return set;
6933 }
6934
6935 return 0;
6936 }
6937
6938 \f
6939 /* A C expression to modify the code described by the conditional if
6940 information CE_INFO with the new PATTERN in INSN. If PATTERN is a null
6941 pointer after the IFCVT_MODIFY_INSN macro executes, it is assumed that that
6942 insn cannot be converted to be executed conditionally. */
6943
6944 rtx
6945 frv_ifcvt_modify_insn (ce_if_block_t *ce_info ATTRIBUTE_UNUSED,
6946 rtx pattern,
6947 rtx insn)
6948 {
6949 rtx orig_ce_pattern = pattern;
6950 rtx set;
6951 rtx op0;
6952 rtx op1;
6953 rtx test;
6954
6955 if (GET_CODE (pattern) != COND_EXEC)
6956 abort ();
6957
6958 test = COND_EXEC_TEST (pattern);
6959 if (GET_CODE (test) == AND)
6960 {
6961 rtx cr = frv_ifcvt.cr_reg;
6962 rtx test_reg;
6963
6964 op0 = XEXP (test, 0);
6965 if (! rtx_equal_p (cr, XEXP (op0, 0)))
6966 goto fail;
6967
6968 op1 = XEXP (test, 1);
6969 test_reg = XEXP (op1, 0);
6970 if (GET_CODE (test_reg) != REG)
6971 goto fail;
6972
6973 /* Is this the first nested if block in this sequence? If so, generate
6974 an andcr or andncr. */
6975 if (! frv_ifcvt.last_nested_if_cr)
6976 {
6977 rtx and_op;
6978
6979 frv_ifcvt.last_nested_if_cr = test_reg;
6980 if (GET_CODE (op0) == NE)
6981 and_op = gen_andcr (test_reg, cr, test_reg);
6982 else
6983 and_op = gen_andncr (test_reg, cr, test_reg);
6984
6985 frv_ifcvt_add_insn (and_op, insn, TRUE);
6986 }
6987
6988 /* If this isn't the first statement in the nested if sequence, see if we
6989 are dealing with the same register. */
6990 else if (! rtx_equal_p (test_reg, frv_ifcvt.last_nested_if_cr))
6991 goto fail;
6992
6993 COND_EXEC_TEST (pattern) = test = op1;
6994 }
6995
6996 /* If this isn't a nested if, reset state variables. */
6997 else
6998 {
6999 frv_ifcvt.last_nested_if_cr = NULL_RTX;
7000 }
7001
7002 set = single_set_pattern (pattern);
7003 if (set)
7004 {
7005 rtx dest = SET_DEST (set);
7006 rtx src = SET_SRC (set);
7007 enum machine_mode mode = GET_MODE (dest);
7008
7009 /* Check for normal binary operators */
7010 if (mode == SImode
7011 && (GET_RTX_CLASS (GET_CODE (src)) == '2'
7012 || GET_RTX_CLASS (GET_CODE (src)) == 'c'))
7013 {
7014 op0 = XEXP (src, 0);
7015 op1 = XEXP (src, 1);
7016
7017 /* Special case load of small data address which looks like:
7018 r16+symbol_ref */
7019 if (GET_CODE (src) == PLUS && plus_small_data_p (op0, op1))
7020 {
7021 src = frv_ifcvt_load_value (src, insn);
7022 if (src)
7023 COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src);
7024 else
7025 goto fail;
7026 }
7027
7028 else if (integer_register_operand (op0, SImode) && CONSTANT_P (op1))
7029 {
7030 op1 = frv_ifcvt_load_value (op1, insn);
7031 if (op1)
7032 COND_EXEC_CODE (pattern)
7033 = gen_rtx_SET (VOIDmode, dest, gen_rtx_fmt_ee (GET_CODE (src),
7034 GET_MODE (src),
7035 op0, op1));
7036 else
7037 goto fail;
7038 }
7039 }
7040
7041 /* For multiply by a constant, we need to handle the sign extending
7042 correctly. Add a USE of the value after the multiply to prevent flow
7043 from cratering because only one register out of the two were used. */
7044 else if (mode == DImode && GET_CODE (src) == MULT)
7045 {
7046 op0 = XEXP (src, 0);
7047 op1 = XEXP (src, 1);
7048 if (GET_CODE (op0) == SIGN_EXTEND && GET_CODE (op1) == CONST_INT)
7049 {
7050 op1 = frv_ifcvt_load_value (op1, insn);
7051 if (op1)
7052 {
7053 op1 = gen_rtx_SIGN_EXTEND (DImode, op1);
7054 COND_EXEC_CODE (pattern)
7055 = gen_rtx_SET (VOIDmode, dest,
7056 gen_rtx_MULT (DImode, op0, op1));
7057 }
7058 else
7059 goto fail;
7060 }
7061
7062 frv_ifcvt_add_insn (gen_rtx_USE (VOIDmode, dest), insn, FALSE);
7063 }
7064
7065 /* If we are just loading a constant created for a nested conditional
7066 execution statement, just load the constant without any conditional
7067 execution, since we know that the constant will not interfere with any
7068 other registers. */
7069 else if (frv_ifcvt.scratch_insns_bitmap
7070 && bitmap_bit_p (frv_ifcvt.scratch_insns_bitmap,
7071 INSN_UID (insn)))
7072 pattern = set;
7073
7074 else if (mode == QImode || mode == HImode || mode == SImode
7075 || mode == SFmode)
7076 {
7077 int changed_p = FALSE;
7078
7079 /* Check for just loading up a constant */
7080 if (CONSTANT_P (src) && integer_register_operand (dest, mode))
7081 {
7082 src = frv_ifcvt_load_value (src, insn);
7083 if (!src)
7084 goto fail;
7085
7086 changed_p = TRUE;
7087 }
7088
7089 /* See if we need to fix up stores */
7090 if (GET_CODE (dest) == MEM)
7091 {
7092 rtx new_mem = frv_ifcvt_rewrite_mem (dest, mode, insn);
7093
7094 if (!new_mem)
7095 goto fail;
7096
7097 else if (new_mem != dest)
7098 {
7099 changed_p = TRUE;
7100 dest = new_mem;
7101 }
7102 }
7103
7104 /* See if we need to fix up loads */
7105 if (GET_CODE (src) == MEM)
7106 {
7107 rtx new_mem = frv_ifcvt_rewrite_mem (src, mode, insn);
7108
7109 if (!new_mem)
7110 goto fail;
7111
7112 else if (new_mem != src)
7113 {
7114 changed_p = TRUE;
7115 src = new_mem;
7116 }
7117 }
7118
7119 /* If either src or destination changed, redo SET. */
7120 if (changed_p)
7121 COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src);
7122 }
7123
7124 /* Rewrite a nested set cccr in terms of IF_THEN_ELSE. Also deal with
7125 rewriting the CC register to be the same as the paired CC/CR register
7126 for nested ifs. */
7127 else if (mode == CC_CCRmode && GET_RTX_CLASS (GET_CODE (src)) == '<')
7128 {
7129 int regno = REGNO (XEXP (src, 0));
7130 rtx if_else;
7131
7132 if (ce_info->pass > 1
7133 && regno != (int)REGNO (frv_ifcvt.nested_cc_reg)
7134 && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, regno))
7135 {
7136 src = gen_rtx_fmt_ee (GET_CODE (src),
7137 CC_CCRmode,
7138 frv_ifcvt.nested_cc_reg,
7139 XEXP (src, 1));
7140 }
7141
7142 if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, test, src, const0_rtx);
7143 pattern = gen_rtx_SET (VOIDmode, dest, if_else);
7144 }
7145
7146 /* Remap a nested compare instruction to use the paired CC/CR reg. */
7147 else if (ce_info->pass > 1
7148 && GET_CODE (dest) == REG
7149 && CC_P (REGNO (dest))
7150 && REGNO (dest) != REGNO (frv_ifcvt.nested_cc_reg)
7151 && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite,
7152 REGNO (dest))
7153 && GET_CODE (src) == COMPARE)
7154 {
7155 PUT_MODE (frv_ifcvt.nested_cc_reg, GET_MODE (dest));
7156 COND_EXEC_CODE (pattern)
7157 = gen_rtx_SET (VOIDmode, frv_ifcvt.nested_cc_reg, copy_rtx (src));
7158 }
7159 }
7160
7161 if (TARGET_DEBUG_COND_EXEC)
7162 {
7163 rtx orig_pattern = PATTERN (insn);
7164
7165 PATTERN (insn) = pattern;
7166 fprintf (stderr,
7167 "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn after modification:\n",
7168 ce_info->pass);
7169
7170 debug_rtx (insn);
7171 PATTERN (insn) = orig_pattern;
7172 }
7173
7174 return pattern;
7175
7176 fail:
7177 if (TARGET_DEBUG_COND_EXEC)
7178 {
7179 rtx orig_pattern = PATTERN (insn);
7180
7181 PATTERN (insn) = orig_ce_pattern;
7182 fprintf (stderr,
7183 "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn could not be modified:\n",
7184 ce_info->pass);
7185
7186 debug_rtx (insn);
7187 PATTERN (insn) = orig_pattern;
7188 }
7189
7190 return NULL_RTX;
7191 }
7192
7193 \f
7194 /* A C expression to perform any final machine dependent modifications in
7195 converting code to conditional execution in the code described by the
7196 conditional if information CE_INFO. */
7197
7198 void
7199 frv_ifcvt_modify_final (ce_if_block_t *ce_info ATTRIBUTE_UNUSED)
7200 {
7201 rtx existing_insn;
7202 rtx check_insn;
7203 rtx p = frv_ifcvt.added_insns_list;
7204 int i;
7205
7206 /* Loop inserting the check insns. The last check insn is the first test,
7207 and is the appropriate place to insert constants. */
7208 if (! p)
7209 abort ();
7210
7211 do
7212 {
7213 rtx check_and_insert_insns = XEXP (p, 0);
7214 rtx old_p = p;
7215
7216 check_insn = XEXP (check_and_insert_insns, 0);
7217 existing_insn = XEXP (check_and_insert_insns, 1);
7218 p = XEXP (p, 1);
7219
7220 /* The jump bit is used to say that the new insn is to be inserted BEFORE
7221 the existing insn, otherwise it is to be inserted AFTER. */
7222 if (check_and_insert_insns->jump)
7223 {
7224 emit_insn_before (check_insn, existing_insn);
7225 check_and_insert_insns->jump = 0;
7226 }
7227 else
7228 emit_insn_after (check_insn, existing_insn);
7229
7230 free_EXPR_LIST_node (check_and_insert_insns);
7231 free_EXPR_LIST_node (old_p);
7232 }
7233 while (p != NULL_RTX);
7234
7235 /* Load up any constants needed into temp gprs */
7236 for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++)
7237 {
7238 rtx insn = emit_insn_before (frv_ifcvt.scratch_regs[i], existing_insn);
7239 if (! frv_ifcvt.scratch_insns_bitmap)
7240 frv_ifcvt.scratch_insns_bitmap = BITMAP_XMALLOC ();
7241 bitmap_set_bit (frv_ifcvt.scratch_insns_bitmap, INSN_UID (insn));
7242 frv_ifcvt.scratch_regs[i] = NULL_RTX;
7243 }
7244
7245 frv_ifcvt.added_insns_list = NULL_RTX;
7246 frv_ifcvt.cur_scratch_regs = 0;
7247 }
7248
7249 \f
7250 /* A C expression to cancel any machine dependent modifications in converting
7251 code to conditional execution in the code described by the conditional if
7252 information CE_INFO. */
7253
7254 void
7255 frv_ifcvt_modify_cancel (ce_if_block_t *ce_info ATTRIBUTE_UNUSED)
7256 {
7257 int i;
7258 rtx p = frv_ifcvt.added_insns_list;
7259
7260 /* Loop freeing up the EXPR_LIST's allocated. */
7261 while (p != NULL_RTX)
7262 {
7263 rtx check_and_jump = XEXP (p, 0);
7264 rtx old_p = p;
7265
7266 p = XEXP (p, 1);
7267 free_EXPR_LIST_node (check_and_jump);
7268 free_EXPR_LIST_node (old_p);
7269 }
7270
7271 /* Release any temporary gprs allocated. */
7272 for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++)
7273 frv_ifcvt.scratch_regs[i] = NULL_RTX;
7274
7275 frv_ifcvt.added_insns_list = NULL_RTX;
7276 frv_ifcvt.cur_scratch_regs = 0;
7277 return;
7278 }
7279 \f
7280 /* A C expression for the size in bytes of the trampoline, as an integer.
7281 The template is:
7282
7283 setlo #0, <jmp_reg>
7284 setlo #0, <static_chain>
7285 sethi #0, <jmp_reg>
7286 sethi #0, <static_chain>
7287 jmpl @(gr0,<jmp_reg>) */
7288
7289 int
7290 frv_trampoline_size (void)
7291 {
7292 return 5 /* instructions */ * 4 /* instruction size */;
7293 }
7294
7295 \f
7296 /* A C statement to initialize the variable parts of a trampoline. ADDR is an
7297 RTX for the address of the trampoline; FNADDR is an RTX for the address of
7298 the nested function; STATIC_CHAIN is an RTX for the static chain value that
7299 should be passed to the function when it is called.
7300
7301 The template is:
7302
7303 setlo #0, <jmp_reg>
7304 setlo #0, <static_chain>
7305 sethi #0, <jmp_reg>
7306 sethi #0, <static_chain>
7307 jmpl @(gr0,<jmp_reg>) */
7308
7309 void
7310 frv_initialize_trampoline (rtx addr, rtx fnaddr, rtx static_chain)
7311 {
7312 rtx sc_reg = force_reg (Pmode, static_chain);
7313
7314 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
7315 FALSE, VOIDmode, 4,
7316 addr, Pmode,
7317 GEN_INT (frv_trampoline_size ()), SImode,
7318 fnaddr, Pmode,
7319 sc_reg, Pmode);
7320 }
7321
7322 \f
7323 /* Many machines have some registers that cannot be copied directly to or from
7324 memory or even from other types of registers. An example is the `MQ'
7325 register, which on most machines, can only be copied to or from general
7326 registers, but not memory. Some machines allow copying all registers to and
7327 from memory, but require a scratch register for stores to some memory
7328 locations (e.g., those with symbolic address on the RT, and those with
7329 certain symbolic address on the SPARC when compiling PIC). In some cases,
7330 both an intermediate and a scratch register are required.
7331
7332 You should define these macros to indicate to the reload phase that it may
7333 need to allocate at least one register for a reload in addition to the
7334 register to contain the data. Specifically, if copying X to a register
7335 CLASS in MODE requires an intermediate register, you should define
7336 `SECONDARY_INPUT_RELOAD_CLASS' to return the largest register class all of
7337 whose registers can be used as intermediate registers or scratch registers.
7338
7339 If copying a register CLASS in MODE to X requires an intermediate or scratch
7340 register, `SECONDARY_OUTPUT_RELOAD_CLASS' should be defined to return the
7341 largest register class required. If the requirements for input and output
7342 reloads are the same, the macro `SECONDARY_RELOAD_CLASS' should be used
7343 instead of defining both macros identically.
7344
7345 The values returned by these macros are often `GENERAL_REGS'. Return
7346 `NO_REGS' if no spare register is needed; i.e., if X can be directly copied
7347 to or from a register of CLASS in MODE without requiring a scratch register.
7348 Do not define this macro if it would always return `NO_REGS'.
7349
7350 If a scratch register is required (either with or without an intermediate
7351 register), you should define patterns for `reload_inM' or `reload_outM', as
7352 required.. These patterns, which will normally be implemented with a
7353 `define_expand', should be similar to the `movM' patterns, except that
7354 operand 2 is the scratch register.
7355
7356 Define constraints for the reload register and scratch register that contain
7357 a single register class. If the original reload register (whose class is
7358 CLASS) can meet the constraint given in the pattern, the value returned by
7359 these macros is used for the class of the scratch register. Otherwise, two
7360 additional reload registers are required. Their classes are obtained from
7361 the constraints in the insn pattern.
7362
7363 X might be a pseudo-register or a `subreg' of a pseudo-register, which could
7364 either be in a hard register or in memory. Use `true_regnum' to find out;
7365 it will return -1 if the pseudo is in memory and the hard register number if
7366 it is in a register.
7367
7368 These macros should not be used in the case where a particular class of
7369 registers can only be copied to memory and not to another class of
7370 registers. In that case, secondary reload registers are not needed and
7371 would not be helpful. Instead, a stack location must be used to perform the
7372 copy and the `movM' pattern should use memory as an intermediate storage.
7373 This case often occurs between floating-point and general registers. */
7374
7375 enum reg_class
7376 frv_secondary_reload_class (enum reg_class class,
7377 enum machine_mode mode ATTRIBUTE_UNUSED,
7378 rtx x,
7379 int in_p ATTRIBUTE_UNUSED)
7380 {
7381 enum reg_class ret;
7382
7383 switch (class)
7384 {
7385 default:
7386 ret = NO_REGS;
7387 break;
7388
7389 /* Accumulators/Accumulator guard registers need to go through floating
7390 point registers. */
7391 case QUAD_REGS:
7392 case EVEN_REGS:
7393 case GPR_REGS:
7394 ret = NO_REGS;
7395 if (x && GET_CODE (x) == REG)
7396 {
7397 int regno = REGNO (x);
7398
7399 if (ACC_P (regno) || ACCG_P (regno))
7400 ret = FPR_REGS;
7401 }
7402 break;
7403
7404 /* Nonzero constants should be loaded into an FPR through a GPR. */
7405 case QUAD_FPR_REGS:
7406 case FEVEN_REGS:
7407 case FPR_REGS:
7408 if (x && CONSTANT_P (x) && !ZERO_P (x))
7409 ret = GPR_REGS;
7410 else
7411 ret = NO_REGS;
7412 break;
7413
7414 /* All of these types need gpr registers. */
7415 case ICC_REGS:
7416 case FCC_REGS:
7417 case CC_REGS:
7418 case ICR_REGS:
7419 case FCR_REGS:
7420 case CR_REGS:
7421 case LCR_REG:
7422 case LR_REG:
7423 ret = GPR_REGS;
7424 break;
7425
7426 /* The accumulators need fpr registers */
7427 case ACC_REGS:
7428 case EVEN_ACC_REGS:
7429 case QUAD_ACC_REGS:
7430 case ACCG_REGS:
7431 ret = FPR_REGS;
7432 break;
7433 }
7434
7435 return ret;
7436 }
7437
7438 \f
7439 /* A C expression whose value is nonzero if pseudos that have been assigned to
7440 registers of class CLASS would likely be spilled because registers of CLASS
7441 are needed for spill registers.
7442
7443 The default value of this macro returns 1 if CLASS has exactly one register
7444 and zero otherwise. On most machines, this default should be used. Only
7445 define this macro to some other expression if pseudo allocated by
7446 `local-alloc.c' end up in memory because their hard registers were needed
7447 for spill registers. If this macro returns nonzero for those classes, those
7448 pseudos will only be allocated by `global.c', which knows how to reallocate
7449 the pseudo to another register. If there would not be another register
7450 available for reallocation, you should not change the definition of this
7451 macro since the only effect of such a definition would be to slow down
7452 register allocation. */
7453
7454 int
7455 frv_class_likely_spilled_p (enum reg_class class)
7456 {
7457 switch (class)
7458 {
7459 default:
7460 break;
7461
7462 case ICC_REGS:
7463 case FCC_REGS:
7464 case CC_REGS:
7465 case ICR_REGS:
7466 case FCR_REGS:
7467 case CR_REGS:
7468 case LCR_REG:
7469 case LR_REG:
7470 case SPR_REGS:
7471 case QUAD_ACC_REGS:
7472 case EVEN_ACC_REGS:
7473 case ACC_REGS:
7474 case ACCG_REGS:
7475 return TRUE;
7476 }
7477
7478 return FALSE;
7479 }
7480
7481 \f
7482 /* An expression for the alignment of a structure field FIELD if the
7483 alignment computed in the usual way is COMPUTED. GCC uses this
7484 value instead of the value in `BIGGEST_ALIGNMENT' or
7485 `BIGGEST_FIELD_ALIGNMENT', if defined, for structure fields only. */
7486
7487 /* The definition type of the bit field data is either char, short, long or
7488 long long. The maximum bit size is the number of bits of its own type.
7489
7490 The bit field data is assigned to a storage unit that has an adequate size
7491 for bit field data retention and is located at the smallest address.
7492
7493 Consecutive bit field data are packed at consecutive bits having the same
7494 storage unit, with regard to the type, beginning with the MSB and continuing
7495 toward the LSB.
7496
7497 If a field to be assigned lies over a bit field type boundary, its
7498 assignment is completed by aligning it with a boundary suitable for the
7499 type.
7500
7501 When a bit field having a bit length of 0 is declared, it is forcibly
7502 assigned to the next storage unit.
7503
7504 e.g)
7505 struct {
7506 int a:2;
7507 int b:6;
7508 char c:4;
7509 int d:10;
7510 int :0;
7511 int f:2;
7512 } x;
7513
7514 +0 +1 +2 +3
7515 &x 00000000 00000000 00000000 00000000
7516 MLM----L
7517 a b
7518 &x+4 00000000 00000000 00000000 00000000
7519 M--L
7520 c
7521 &x+8 00000000 00000000 00000000 00000000
7522 M----------L
7523 d
7524 &x+12 00000000 00000000 00000000 00000000
7525 ML
7526 f
7527 */
7528
7529 int
7530 frv_adjust_field_align (tree field, int computed)
7531 {
7532 /* Make sure that the bitfield is not wider than the type. */
7533 if (DECL_BIT_FIELD (field)
7534 && !DECL_ARTIFICIAL (field))
7535 {
7536 tree parent = DECL_CONTEXT (field);
7537 tree prev = NULL_TREE;
7538 tree cur;
7539
7540 for (cur = TYPE_FIELDS (parent); cur && cur != field; cur = TREE_CHAIN (cur))
7541 {
7542 if (TREE_CODE (cur) != FIELD_DECL)
7543 continue;
7544
7545 prev = cur;
7546 }
7547
7548 if (!cur)
7549 abort ();
7550
7551 /* If this isn't a :0 field and if the previous element is a bitfield
7552 also, see if the type is different, if so, we will need to align the
7553 bit-field to the next boundary */
7554 if (prev
7555 && ! DECL_PACKED (field)
7556 && ! integer_zerop (DECL_SIZE (field))
7557 && DECL_BIT_FIELD_TYPE (field) != DECL_BIT_FIELD_TYPE (prev))
7558 {
7559 int prev_align = TYPE_ALIGN (TREE_TYPE (prev));
7560 int cur_align = TYPE_ALIGN (TREE_TYPE (field));
7561 computed = (prev_align > cur_align) ? prev_align : cur_align;
7562 }
7563 }
7564
7565 return computed;
7566 }
7567
7568 \f
7569 /* A C expression that is nonzero if it is permissible to store a value of mode
7570 MODE in hard register number REGNO (or in several registers starting with
7571 that one). For a machine where all registers are equivalent, a suitable
7572 definition is
7573
7574 #define HARD_REGNO_MODE_OK(REGNO, MODE) 1
7575
7576 It is not necessary for this macro to check for the numbers of fixed
7577 registers, because the allocation mechanism considers them to be always
7578 occupied.
7579
7580 On some machines, double-precision values must be kept in even/odd register
7581 pairs. The way to implement that is to define this macro to reject odd
7582 register numbers for such modes.
7583
7584 The minimum requirement for a mode to be OK in a register is that the
7585 `movMODE' instruction pattern support moves between the register and any
7586 other hard register for which the mode is OK; and that moving a value into
7587 the register and back out not alter it.
7588
7589 Since the same instruction used to move `SImode' will work for all narrower
7590 integer modes, it is not necessary on any machine for `HARD_REGNO_MODE_OK'
7591 to distinguish between these modes, provided you define patterns `movhi',
7592 etc., to take advantage of this. This is useful because of the interaction
7593 between `HARD_REGNO_MODE_OK' and `MODES_TIEABLE_P'; it is very desirable for
7594 all integer modes to be tieable.
7595
7596 Many machines have special registers for floating point arithmetic. Often
7597 people assume that floating point machine modes are allowed only in floating
7598 point registers. This is not true. Any registers that can hold integers
7599 can safely *hold* a floating point machine mode, whether or not floating
7600 arithmetic can be done on it in those registers. Integer move instructions
7601 can be used to move the values.
7602
7603 On some machines, though, the converse is true: fixed-point machine modes
7604 may not go in floating registers. This is true if the floating registers
7605 normalize any value stored in them, because storing a non-floating value
7606 there would garble it. In this case, `HARD_REGNO_MODE_OK' should reject
7607 fixed-point machine modes in floating registers. But if the floating
7608 registers do not automatically normalize, if you can store any bit pattern
7609 in one and retrieve it unchanged without a trap, then any machine mode may
7610 go in a floating register, so you can define this macro to say so.
7611
7612 The primary significance of special floating registers is rather that they
7613 are the registers acceptable in floating point arithmetic instructions.
7614 However, this is of no concern to `HARD_REGNO_MODE_OK'. You handle it by
7615 writing the proper constraints for those instructions.
7616
7617 On some machines, the floating registers are especially slow to access, so
7618 that it is better to store a value in a stack frame than in such a register
7619 if floating point arithmetic is not being done. As long as the floating
7620 registers are not in class `GENERAL_REGS', they will not be used unless some
7621 pattern's constraint asks for one. */
7622
7623 int
7624 frv_hard_regno_mode_ok (int regno, enum machine_mode mode)
7625 {
7626 int base;
7627 int mask;
7628
7629 switch (mode)
7630 {
7631 case CCmode:
7632 case CC_UNSmode:
7633 return ICC_P (regno) || GPR_P (regno);
7634
7635 case CC_CCRmode:
7636 return CR_P (regno) || GPR_P (regno);
7637
7638 case CC_FPmode:
7639 return FCC_P (regno) || GPR_P (regno);
7640
7641 default:
7642 break;
7643 }
7644
7645 /* Set BASE to the first register in REGNO's class. Set MASK to the
7646 bits that must be clear in (REGNO - BASE) for the register to be
7647 well-aligned. */
7648 if (INTEGRAL_MODE_P (mode) || FLOAT_MODE_P (mode) || VECTOR_MODE_P (mode))
7649 {
7650 if (ACCG_P (regno))
7651 {
7652 /* ACCGs store one byte. Two-byte quantities must start in
7653 even-numbered registers, four-byte ones in registers whose
7654 numbers are divisible by four, and so on. */
7655 base = ACCG_FIRST;
7656 mask = GET_MODE_SIZE (mode) - 1;
7657 }
7658 else
7659 {
7660 /* The other registers store one word. */
7661 if (GPR_P (regno) || regno == AP_FIRST)
7662 base = GPR_FIRST;
7663
7664 else if (FPR_P (regno))
7665 base = FPR_FIRST;
7666
7667 else if (ACC_P (regno))
7668 base = ACC_FIRST;
7669
7670 else if (SPR_P (regno))
7671 return mode == SImode;
7672
7673 /* Fill in the table. */
7674 else
7675 return 0;
7676
7677 /* Anything smaller than an SI is OK in any word-sized register. */
7678 if (GET_MODE_SIZE (mode) < 4)
7679 return 1;
7680
7681 mask = (GET_MODE_SIZE (mode) / 4) - 1;
7682 }
7683 return (((regno - base) & mask) == 0);
7684 }
7685
7686 return 0;
7687 }
7688
7689 \f
7690 /* A C expression for the number of consecutive hard registers, starting at
7691 register number REGNO, required to hold a value of mode MODE.
7692
7693 On a machine where all registers are exactly one word, a suitable definition
7694 of this macro is
7695
7696 #define HARD_REGNO_NREGS(REGNO, MODE) \
7697 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \
7698 / UNITS_PER_WORD)) */
7699
7700 /* On the FRV, make the CC_FP mode take 3 words in the integer registers, so
7701 that we can build the appropriate instructions to properly reload the
7702 values. Also, make the byte-sized accumulator guards use one guard
7703 for each byte. */
7704
7705 int
7706 frv_hard_regno_nregs (int regno, enum machine_mode mode)
7707 {
7708 if (ACCG_P (regno))
7709 return GET_MODE_SIZE (mode);
7710 else
7711 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7712 }
7713
7714 \f
7715 /* A C expression for the maximum number of consecutive registers of
7716 class CLASS needed to hold a value of mode MODE.
7717
7718 This is closely related to the macro `HARD_REGNO_NREGS'. In fact, the value
7719 of the macro `CLASS_MAX_NREGS (CLASS, MODE)' should be the maximum value of
7720 `HARD_REGNO_NREGS (REGNO, MODE)' for all REGNO values in the class CLASS.
7721
7722 This macro helps control the handling of multiple-word values in
7723 the reload pass.
7724
7725 This declaration is required. */
7726
7727 int
7728 frv_class_max_nregs (enum reg_class class, enum machine_mode mode)
7729 {
7730 if (class == ACCG_REGS)
7731 /* An N-byte value requires N accumulator guards. */
7732 return GET_MODE_SIZE (mode);
7733 else
7734 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7735 }
7736
7737 \f
7738 /* A C expression that is nonzero if X is a legitimate constant for an
7739 immediate operand on the target machine. You can assume that X satisfies
7740 `CONSTANT_P', so you need not check this. In fact, `1' is a suitable
7741 definition for this macro on machines where anything `CONSTANT_P' is valid. */
7742
7743 int
7744 frv_legitimate_constant_p (rtx x)
7745 {
7746 enum machine_mode mode = GET_MODE (x);
7747
7748 /* All of the integer constants are ok */
7749 if (GET_CODE (x) != CONST_DOUBLE)
7750 return TRUE;
7751
7752 /* double integer constants are ok */
7753 if (mode == VOIDmode || mode == DImode)
7754 return TRUE;
7755
7756 /* 0 is always ok */
7757 if (x == CONST0_RTX (mode))
7758 return TRUE;
7759
7760 /* If floating point is just emulated, allow any constant, since it will be
7761 constructed in the GPRs */
7762 if (!TARGET_HAS_FPRS)
7763 return TRUE;
7764
7765 if (mode == DFmode && !TARGET_DOUBLE)
7766 return TRUE;
7767
7768 /* Otherwise store the constant away and do a load. */
7769 return FALSE;
7770 }
7771 \f
7772 /* A C expression for the cost of moving data from a register in class FROM to
7773 one in class TO. The classes are expressed using the enumeration values
7774 such as `GENERAL_REGS'. A value of 4 is the default; other values are
7775 interpreted relative to that.
7776
7777 It is not required that the cost always equal 2 when FROM is the same as TO;
7778 on some machines it is expensive to move between registers if they are not
7779 general registers.
7780
7781 If reload sees an insn consisting of a single `set' between two hard
7782 registers, and if `REGISTER_MOVE_COST' applied to their classes returns a
7783 value of 2, reload does not check to ensure that the constraints of the insn
7784 are met. Setting a cost of other than 2 will allow reload to verify that
7785 the constraints are met. You should do this if the `movM' pattern's
7786 constraints do not allow such copying. */
7787
7788 #define HIGH_COST 40
7789 #define MEDIUM_COST 3
7790 #define LOW_COST 1
7791
7792 int
7793 frv_register_move_cost (enum reg_class from, enum reg_class to)
7794 {
7795 switch (from)
7796 {
7797 default:
7798 break;
7799
7800 case QUAD_REGS:
7801 case EVEN_REGS:
7802 case GPR_REGS:
7803 switch (to)
7804 {
7805 default:
7806 break;
7807
7808 case QUAD_REGS:
7809 case EVEN_REGS:
7810 case GPR_REGS:
7811 return LOW_COST;
7812
7813 case FEVEN_REGS:
7814 case FPR_REGS:
7815 return LOW_COST;
7816
7817 case LCR_REG:
7818 case LR_REG:
7819 case SPR_REGS:
7820 return LOW_COST;
7821 }
7822
7823 case FEVEN_REGS:
7824 case FPR_REGS:
7825 switch (to)
7826 {
7827 default:
7828 break;
7829
7830 case QUAD_REGS:
7831 case EVEN_REGS:
7832 case GPR_REGS:
7833 case ACC_REGS:
7834 case EVEN_ACC_REGS:
7835 case QUAD_ACC_REGS:
7836 case ACCG_REGS:
7837 return MEDIUM_COST;
7838
7839 case FEVEN_REGS:
7840 case FPR_REGS:
7841 return LOW_COST;
7842 }
7843
7844 case LCR_REG:
7845 case LR_REG:
7846 case SPR_REGS:
7847 switch (to)
7848 {
7849 default:
7850 break;
7851
7852 case QUAD_REGS:
7853 case EVEN_REGS:
7854 case GPR_REGS:
7855 return MEDIUM_COST;
7856 }
7857
7858 case ACC_REGS:
7859 case EVEN_ACC_REGS:
7860 case QUAD_ACC_REGS:
7861 case ACCG_REGS:
7862 switch (to)
7863 {
7864 default:
7865 break;
7866
7867 case FEVEN_REGS:
7868 case FPR_REGS:
7869 return MEDIUM_COST;
7870
7871 }
7872 }
7873
7874 return HIGH_COST;
7875 }
7876 \f
7877 /* Implementation of TARGET_ASM_INTEGER. In the FRV case we need to
7878 use ".picptr" to generate safe relocations for PIC code. We also
7879 need a fixup entry for aligned (non-debugging) code. */
7880
7881 static bool
7882 frv_assemble_integer (rtx value, unsigned int size, int aligned_p)
7883 {
7884 if (flag_pic && size == UNITS_PER_WORD)
7885 {
7886 if (GET_CODE (value) == CONST
7887 || GET_CODE (value) == SYMBOL_REF
7888 || GET_CODE (value) == LABEL_REF)
7889 {
7890 if (aligned_p)
7891 {
7892 static int label_num = 0;
7893 char buf[256];
7894 const char *p;
7895
7896 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", label_num++);
7897 p = (* targetm.strip_name_encoding) (buf);
7898
7899 fprintf (asm_out_file, "%s:\n", p);
7900 fprintf (asm_out_file, "%s\n", FIXUP_SECTION_ASM_OP);
7901 fprintf (asm_out_file, "\t.picptr\t%s\n", p);
7902 fprintf (asm_out_file, "\t.previous\n");
7903 }
7904 assemble_integer_with_op ("\t.picptr\t", value);
7905 return true;
7906 }
7907 if (!aligned_p)
7908 {
7909 /* We've set the unaligned SI op to NULL, so we always have to
7910 handle the unaligned case here. */
7911 assemble_integer_with_op ("\t.4byte\t", value);
7912 return true;
7913 }
7914 }
7915 return default_assemble_integer (value, size, aligned_p);
7916 }
7917
7918 /* Function to set up the backend function structure. */
7919
7920 static struct machine_function *
7921 frv_init_machine_status (void)
7922 {
7923 return ggc_alloc_cleared (sizeof (struct machine_function));
7924 }
7925 \f
7926 /* Implement TARGET_SCHED_ISSUE_RATE. */
7927
7928 static int
7929 frv_issue_rate (void)
7930 {
7931 if (!TARGET_PACK)
7932 return 1;
7933
7934 switch (frv_cpu_type)
7935 {
7936 default:
7937 case FRV_CPU_FR300:
7938 case FRV_CPU_SIMPLE:
7939 return 1;
7940
7941 case FRV_CPU_FR400:
7942 return 2;
7943
7944 case FRV_CPU_GENERIC:
7945 case FRV_CPU_FR500:
7946 case FRV_CPU_TOMCAT:
7947 return 4;
7948 }
7949 }
7950
7951
7952 /* Implement TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE. */
7953
7954 static int
7955 frv_use_dfa_pipeline_interface (void)
7956 {
7957 return true;
7958 }
7959 \f
7960 /* Update the register state information, to know about which registers are set
7961 or clobbered. */
7962
7963 static void
7964 frv_registers_update (rtx x,
7965 unsigned char reg_state[],
7966 int modified[],
7967 int *p_num_mod,
7968 int flag)
7969 {
7970 int regno, reg_max;
7971 rtx reg;
7972 rtx cond;
7973 const char *format;
7974 int length;
7975 int j;
7976
7977 switch (GET_CODE (x))
7978 {
7979 default:
7980 break;
7981
7982 /* Clobber just modifies a register, it doesn't make it live. */
7983 case CLOBBER:
7984 frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod,
7985 flag | REGSTATE_MODIFIED);
7986 return;
7987
7988 /* Pre modify updates the first argument, just references the second. */
7989 case PRE_MODIFY:
7990 case SET:
7991 frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod,
7992 flag | REGSTATE_MODIFIED | REGSTATE_LIVE);
7993 frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod, flag);
7994 return;
7995
7996 /* For COND_EXEC, pass the appropriate flag to evaluate the conditional
7997 statement, but just to be sure, make sure it is the type of cond_exec
7998 we expect. */
7999 case COND_EXEC:
8000 cond = XEXP (x, 0);
8001 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8002 && GET_CODE (XEXP (cond, 0)) == REG
8003 && CR_P (REGNO (XEXP (cond, 0)))
8004 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8005 && INTVAL (XEXP (cond, 1)) == 0
8006 && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0)
8007 {
8008 frv_registers_update (cond, reg_state, modified, p_num_mod, flag);
8009 flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST)
8010 | ((GET_CODE (cond) == NE)
8011 ? REGSTATE_IF_TRUE
8012 : REGSTATE_IF_FALSE));
8013
8014 frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod,
8015 flag);
8016 return;
8017 }
8018 else
8019 fatal_insn ("frv_registers_update", x);
8020
8021 /* MEM resets the modification bits. */
8022 case MEM:
8023 flag &= ~REGSTATE_MODIFIED;
8024 break;
8025
8026 /* See if we need to set the modified flag. */
8027 case SUBREG:
8028 reg = SUBREG_REG (x);
8029 if (GET_CODE (reg) == REG)
8030 {
8031 regno = subreg_regno (x);
8032 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8033 goto reg_common;
8034 }
8035 break;
8036
8037 case REG:
8038 regno = REGNO (x);
8039 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8040 /* fall through */
8041
8042 reg_common:
8043 if (flag & REGSTATE_MODIFIED)
8044 {
8045 flag &= REGSTATE_MASK;
8046 while (regno < reg_max)
8047 {
8048 int rs = reg_state[regno];
8049
8050 if (flag != rs)
8051 {
8052 if ((rs & REGSTATE_MODIFIED) == 0)
8053 {
8054 modified[ *p_num_mod ] = regno;
8055 (*p_num_mod)++;
8056 }
8057
8058 /* If the previous register state had the register as
8059 modified, possibly in some conditional execution context,
8060 and the current insn modifies in some other context, or
8061 outside of conditional execution, just mark the variable
8062 as modified. */
8063 else
8064 flag &= ~(REGSTATE_IF_EITHER | REGSTATE_CC_MASK);
8065
8066 reg_state[regno] = (rs | flag);
8067 }
8068 regno++;
8069 }
8070 }
8071 return;
8072 }
8073
8074
8075 length = GET_RTX_LENGTH (GET_CODE (x));
8076 format = GET_RTX_FORMAT (GET_CODE (x));
8077
8078 for (j = 0; j < length; ++j)
8079 {
8080 switch (format[j])
8081 {
8082 case 'e':
8083 frv_registers_update (XEXP (x, j), reg_state, modified, p_num_mod,
8084 flag);
8085 break;
8086
8087 case 'V':
8088 case 'E':
8089 if (XVEC (x, j) != 0)
8090 {
8091 int k;
8092 for (k = 0; k < XVECLEN (x, j); ++k)
8093 frv_registers_update (XVECEXP (x, j, k), reg_state, modified,
8094 p_num_mod, flag);
8095 }
8096 break;
8097
8098 default:
8099 /* Nothing to do. */
8100 break;
8101 }
8102 }
8103
8104 return;
8105 }
8106
8107 \f
8108 /* Return if any registers in a hard register set were used an insn. */
8109
8110 static int
8111 frv_registers_used_p (rtx x, unsigned char reg_state[], int flag)
8112 {
8113 int regno, reg_max;
8114 rtx reg;
8115 rtx cond;
8116 rtx dest;
8117 const char *format;
8118 int result;
8119 int length;
8120 int j;
8121
8122 switch (GET_CODE (x))
8123 {
8124 default:
8125 break;
8126
8127 /* Skip clobber, that doesn't use the previous value */
8128 case CLOBBER:
8129 return FALSE;
8130
8131 /* For SET, if a conditional jump has occurred in the same insn, only
8132 allow a set of a CR register if that register is not currently live.
8133 This is because on the FR-V, B0/B1 instructions are always last.
8134 Otherwise, don't look at the result, except within a MEM, but do look
8135 at the source. */
8136 case SET:
8137 dest = SET_DEST (x);
8138 if (flag & REGSTATE_CONDJUMP
8139 && GET_CODE (dest) == REG && CR_P (REGNO (dest))
8140 && (reg_state[ REGNO (dest) ] & REGSTATE_LIVE) != 0)
8141 return TRUE;
8142
8143 if (GET_CODE (dest) == MEM)
8144 {
8145 result = frv_registers_used_p (XEXP (dest, 0), reg_state, flag);
8146 if (result)
8147 return result;
8148 }
8149
8150 return frv_registers_used_p (SET_SRC (x), reg_state, flag);
8151
8152 /* For COND_EXEC, pass the appropriate flag to evaluate the conditional
8153 statement, but just to be sure, make sure it is the type of cond_exec
8154 we expect. */
8155 case COND_EXEC:
8156 cond = XEXP (x, 0);
8157 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8158 && GET_CODE (XEXP (cond, 0)) == REG
8159 && CR_P (REGNO (XEXP (cond, 0)))
8160 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8161 && INTVAL (XEXP (cond, 1)) == 0
8162 && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0)
8163 {
8164 result = frv_registers_used_p (cond, reg_state, flag);
8165 if (result)
8166 return result;
8167
8168 flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST)
8169 | ((GET_CODE (cond) == NE)
8170 ? REGSTATE_IF_TRUE
8171 : REGSTATE_IF_FALSE));
8172
8173 return frv_registers_used_p (XEXP (x, 1), reg_state, flag);
8174 }
8175 else
8176 fatal_insn ("frv_registers_used_p", x);
8177
8178 /* See if a register or subreg was modified in the same VLIW insn. */
8179 case SUBREG:
8180 reg = SUBREG_REG (x);
8181 if (GET_CODE (reg) == REG)
8182 {
8183 regno = subreg_regno (x);
8184 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8185 goto reg_common;
8186 }
8187 break;
8188
8189 case REG:
8190 regno = REGNO (x);
8191 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8192 /* fall through */
8193
8194 reg_common:
8195 while (regno < reg_max)
8196 {
8197 int rs = reg_state[regno];
8198
8199 if (rs & REGSTATE_MODIFIED)
8200 {
8201 int rs_if = rs & REGSTATE_IF_EITHER;
8202 int flag_if = flag & REGSTATE_IF_EITHER;
8203
8204 /* Simple modification, no conditional execution */
8205 if ((rs & REGSTATE_IF_EITHER) == 0)
8206 return TRUE;
8207
8208 /* See if the variable is only modified in a conditional
8209 execution expression opposite to the conditional execution
8210 expression that governs this expression (ie, true vs. false
8211 for the same CC register). If this isn't two halves of the
8212 same conditional expression, consider the register
8213 modified. */
8214 if (((rs_if == REGSTATE_IF_TRUE && flag_if == REGSTATE_IF_FALSE)
8215 || (rs_if == REGSTATE_IF_FALSE && flag_if == REGSTATE_IF_TRUE))
8216 && ((rs & REGSTATE_CC_MASK) == (flag & REGSTATE_CC_MASK)))
8217 ;
8218 else
8219 return TRUE;
8220 }
8221
8222 regno++;
8223 }
8224 return FALSE;
8225 }
8226
8227
8228 length = GET_RTX_LENGTH (GET_CODE (x));
8229 format = GET_RTX_FORMAT (GET_CODE (x));
8230
8231 for (j = 0; j < length; ++j)
8232 {
8233 switch (format[j])
8234 {
8235 case 'e':
8236 result = frv_registers_used_p (XEXP (x, j), reg_state, flag);
8237 if (result != 0)
8238 return result;
8239 break;
8240
8241 case 'V':
8242 case 'E':
8243 if (XVEC (x, j) != 0)
8244 {
8245 int k;
8246 for (k = 0; k < XVECLEN (x, j); ++k)
8247 {
8248 result = frv_registers_used_p (XVECEXP (x, j, k), reg_state,
8249 flag);
8250 if (result != 0)
8251 return result;
8252 }
8253 }
8254 break;
8255
8256 default:
8257 /* Nothing to do. */
8258 break;
8259 }
8260 }
8261
8262 return 0;
8263 }
8264
8265 /* Return if any registers in a hard register set were set in an insn. */
8266
8267 static int
8268 frv_registers_set_p (rtx x, unsigned char reg_state[], int modify_p)
8269 {
8270 int regno, reg_max;
8271 rtx reg;
8272 rtx cond;
8273 const char *format;
8274 int length;
8275 int j;
8276
8277 switch (GET_CODE (x))
8278 {
8279 default:
8280 break;
8281
8282 case CLOBBER:
8283 return frv_registers_set_p (XEXP (x, 0), reg_state, TRUE);
8284
8285 case PRE_MODIFY:
8286 case SET:
8287 return (frv_registers_set_p (XEXP (x, 0), reg_state, TRUE)
8288 || frv_registers_set_p (XEXP (x, 1), reg_state, FALSE));
8289
8290 case COND_EXEC:
8291 cond = XEXP (x, 0);
8292 /* just to be sure, make sure it is the type of cond_exec we
8293 expect. */
8294 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
8295 && GET_CODE (XEXP (cond, 0)) == REG
8296 && CR_P (REGNO (XEXP (cond, 0)))
8297 && GET_CODE (XEXP (cond, 1)) == CONST_INT
8298 && INTVAL (XEXP (cond, 1)) == 0
8299 && !modify_p)
8300 return frv_registers_set_p (XEXP (x, 1), reg_state, modify_p);
8301 else
8302 fatal_insn ("frv_registers_set_p", x);
8303
8304 /* MEM resets the modification bits. */
8305 case MEM:
8306 modify_p = FALSE;
8307 break;
8308
8309 /* See if we need to set the modified modify_p. */
8310 case SUBREG:
8311 reg = SUBREG_REG (x);
8312 if (GET_CODE (reg) == REG)
8313 {
8314 regno = subreg_regno (x);
8315 reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8316 goto reg_common;
8317 }
8318 break;
8319
8320 case REG:
8321 regno = REGNO (x);
8322 reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x));
8323 /* fall through */
8324
8325 reg_common:
8326 if (modify_p)
8327 while (regno < reg_max)
8328 {
8329 int rs = reg_state[regno];
8330
8331 if (rs & REGSTATE_MODIFIED)
8332 return TRUE;
8333 regno++;
8334 }
8335 return FALSE;
8336 }
8337
8338
8339 length = GET_RTX_LENGTH (GET_CODE (x));
8340 format = GET_RTX_FORMAT (GET_CODE (x));
8341
8342 for (j = 0; j < length; ++j)
8343 {
8344 switch (format[j])
8345 {
8346 case 'e':
8347 if (frv_registers_set_p (XEXP (x, j), reg_state, modify_p))
8348 return TRUE;
8349 break;
8350
8351 case 'V':
8352 case 'E':
8353 if (XVEC (x, j) != 0)
8354 {
8355 int k;
8356 for (k = 0; k < XVECLEN (x, j); ++k)
8357 if (frv_registers_set_p (XVECEXP (x, j, k), reg_state,
8358 modify_p))
8359 return TRUE;
8360 }
8361 break;
8362
8363 default:
8364 /* Nothing to do. */
8365 break;
8366 }
8367 }
8368
8369 return FALSE;
8370 }
8371
8372 \f
8373 /* On the FR-V, this pass is used to rescan the insn chain, and pack
8374 conditional branches/calls/jumps, etc. with previous insns where it can. It
8375 does not reorder the instructions. We assume the scheduler left the flow
8376 information in a reasonable state. */
8377
8378 static void
8379 frv_pack_insns (void)
8380 {
8381 state_t frv_state; /* frv state machine */
8382 int cur_start_vliw_p; /* current insn starts a VLIW insn */
8383 int next_start_vliw_p; /* next insn starts a VLIW insn */
8384 int cur_condjump_p; /* flag if current insn is a cond jump*/
8385 int next_condjump_p; /* flag if next insn is a cond jump */
8386 rtx insn;
8387 rtx link;
8388 int j;
8389 int num_mod = 0; /* # of modified registers */
8390 int modified[FIRST_PSEUDO_REGISTER]; /* registers modified in current VLIW */
8391 /* register state information */
8392 unsigned char reg_state[FIRST_PSEUDO_REGISTER];
8393
8394 /* If we weren't going to pack the insns, don't bother with this pass. */
8395 if (!optimize
8396 || !flag_schedule_insns_after_reload
8397 || TARGET_NO_VLIW_BRANCH
8398 || frv_issue_rate () == 1)
8399 return;
8400
8401 /* Set up the instruction and register states. */
8402 dfa_start ();
8403 frv_state = (state_t) xmalloc (state_size ());
8404 memset (reg_state, REGSTATE_DEAD, sizeof (reg_state));
8405
8406 /* Go through the insns, and repack the insns. */
8407 state_reset (frv_state);
8408 cur_start_vliw_p = FALSE;
8409 next_start_vliw_p = TRUE;
8410 cur_condjump_p = 0;
8411 next_condjump_p = 0;
8412
8413 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
8414 {
8415 enum rtx_code code = GET_CODE (insn);
8416 enum rtx_code pattern_code;
8417
8418 /* For basic block begin notes redo the live information, and skip other
8419 notes. */
8420 if (code == NOTE)
8421 {
8422 if (NOTE_LINE_NUMBER (insn) == (int)NOTE_INSN_BASIC_BLOCK)
8423 {
8424 regset live;
8425
8426 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
8427 reg_state[j] &= ~ REGSTATE_LIVE;
8428
8429 live = NOTE_BASIC_BLOCK (insn)->global_live_at_start;
8430 EXECUTE_IF_SET_IN_REG_SET(live, 0, j,
8431 {
8432 reg_state[j] |= REGSTATE_LIVE;
8433 });
8434 }
8435
8436 continue;
8437 }
8438
8439 /* things like labels reset everything. */
8440 if (GET_RTX_CLASS (code) != 'i')
8441 {
8442 next_start_vliw_p = TRUE;
8443 continue;
8444 }
8445
8446 /* Clear the VLIW start flag on random USE and CLOBBER insns, which is
8447 set on the USE insn that precedes the return, and potentially on
8448 CLOBBERs for setting multiword variables. Also skip the ADDR_VEC
8449 holding the case table labels. */
8450 pattern_code = GET_CODE (PATTERN (insn));
8451 if (pattern_code == USE || pattern_code == CLOBBER
8452 || pattern_code == ADDR_VEC || pattern_code == ADDR_DIFF_VEC)
8453 {
8454 CLEAR_VLIW_START (insn);
8455 continue;
8456 }
8457
8458 cur_start_vliw_p = next_start_vliw_p;
8459 next_start_vliw_p = FALSE;
8460
8461 cur_condjump_p |= next_condjump_p;
8462 next_condjump_p = 0;
8463
8464 /* Unconditional branches and calls end the current VLIW insn. */
8465 if (code == CALL_INSN)
8466 {
8467 next_start_vliw_p = TRUE;
8468
8469 /* On a TOMCAT, calls must be alone in the VLIW insns. */
8470 if (frv_cpu_type == FRV_CPU_TOMCAT)
8471 cur_start_vliw_p = TRUE;
8472 }
8473 else if (code == JUMP_INSN)
8474 {
8475 if (any_condjump_p (insn))
8476 next_condjump_p = REGSTATE_CONDJUMP;
8477 else
8478 next_start_vliw_p = TRUE;
8479 }
8480
8481 /* Only allow setting a CCR register after a conditional branch. */
8482 else if (((cur_condjump_p & REGSTATE_CONDJUMP) != 0)
8483 && get_attr_type (insn) != TYPE_CCR)
8484 cur_start_vliw_p = TRUE;
8485
8486 /* Determine if we need to start a new VLIW instruction. */
8487 if (cur_start_vliw_p
8488 /* Do not check for register conflicts in a setlo instruction
8489 because any output or true dependencies will be with the
8490 partnering sethi instruction, with which it can be packed.
8491
8492 Although output dependencies are rare they are still
8493 possible. So check output dependencies in VLIW insn. */
8494 || (get_attr_type (insn) != TYPE_SETLO
8495 && (frv_registers_used_p (PATTERN (insn),
8496 reg_state,
8497 cur_condjump_p)
8498 || frv_registers_set_p (PATTERN (insn), reg_state, FALSE)))
8499 || state_transition (frv_state, insn) >= 0)
8500 {
8501 SET_VLIW_START (insn);
8502 state_reset (frv_state);
8503 state_transition (frv_state, insn);
8504 cur_condjump_p = 0;
8505
8506 /* Update the modified registers. */
8507 for (j = 0; j < num_mod; j++)
8508 reg_state[ modified[j] ] &= ~(REGSTATE_CC_MASK
8509 | REGSTATE_IF_EITHER
8510 | REGSTATE_MODIFIED);
8511
8512 num_mod = 0;
8513 }
8514 else
8515 CLEAR_VLIW_START (insn);
8516
8517 /* Record which registers are modified. */
8518 frv_registers_update (PATTERN (insn), reg_state, modified, &num_mod, 0);
8519
8520 /* Process the death notices */
8521 for (link = REG_NOTES (insn);
8522 link != NULL_RTX;
8523 link = XEXP (link, 1))
8524 {
8525 rtx reg = XEXP (link, 0);
8526
8527 if (REG_NOTE_KIND (link) == REG_DEAD && GET_CODE (reg) == REG)
8528 {
8529 int regno = REGNO (reg);
8530 int n = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
8531 for (; regno < n; regno++)
8532 reg_state[regno] &= ~REGSTATE_LIVE;
8533 }
8534 }
8535 }
8536
8537 free (frv_state);
8538 dfa_finish ();
8539 return;
8540 }
8541
8542 \f
8543 #define def_builtin(name, type, code) \
8544 builtin_function ((name), (type), (code), BUILT_IN_MD, NULL, NULL)
8545
8546 struct builtin_description
8547 {
8548 enum insn_code icode;
8549 const char *name;
8550 enum frv_builtins code;
8551 enum rtx_code comparison;
8552 unsigned int flag;
8553 };
8554
8555 /* Media intrinsics that take a single, constant argument. */
8556
8557 static struct builtin_description bdesc_set[] =
8558 {
8559 { CODE_FOR_mhdsets, "__MHDSETS", FRV_BUILTIN_MHDSETS, 0, 0 }
8560 };
8561
8562 /* Media intrinsics that take just one argument. */
8563
8564 static struct builtin_description bdesc_1arg[] =
8565 {
8566 { CODE_FOR_mnot, "__MNOT", FRV_BUILTIN_MNOT, 0, 0 },
8567 { CODE_FOR_munpackh, "__MUNPACKH", FRV_BUILTIN_MUNPACKH, 0, 0 },
8568 { CODE_FOR_mbtoh, "__MBTOH", FRV_BUILTIN_MBTOH, 0, 0 },
8569 { CODE_FOR_mhtob, "__MHTOB", FRV_BUILTIN_MHTOB, 0, 0 },
8570 { CODE_FOR_mabshs, "__MABSHS", FRV_BUILTIN_MABSHS, 0, 0 }
8571 };
8572
8573 /* Media intrinsics that take two arguments. */
8574
8575 static struct builtin_description bdesc_2arg[] =
8576 {
8577 { CODE_FOR_mand, "__MAND", FRV_BUILTIN_MAND, 0, 0 },
8578 { CODE_FOR_mor, "__MOR", FRV_BUILTIN_MOR, 0, 0 },
8579 { CODE_FOR_mxor, "__MXOR", FRV_BUILTIN_MXOR, 0, 0 },
8580 { CODE_FOR_maveh, "__MAVEH", FRV_BUILTIN_MAVEH, 0, 0 },
8581 { CODE_FOR_msaths, "__MSATHS", FRV_BUILTIN_MSATHS, 0, 0 },
8582 { CODE_FOR_msathu, "__MSATHU", FRV_BUILTIN_MSATHU, 0, 0 },
8583 { CODE_FOR_maddhss, "__MADDHSS", FRV_BUILTIN_MADDHSS, 0, 0 },
8584 { CODE_FOR_maddhus, "__MADDHUS", FRV_BUILTIN_MADDHUS, 0, 0 },
8585 { CODE_FOR_msubhss, "__MSUBHSS", FRV_BUILTIN_MSUBHSS, 0, 0 },
8586 { CODE_FOR_msubhus, "__MSUBHUS", FRV_BUILTIN_MSUBHUS, 0, 0 },
8587 { CODE_FOR_mqaddhss, "__MQADDHSS", FRV_BUILTIN_MQADDHSS, 0, 0 },
8588 { CODE_FOR_mqaddhus, "__MQADDHUS", FRV_BUILTIN_MQADDHUS, 0, 0 },
8589 { CODE_FOR_mqsubhss, "__MQSUBHSS", FRV_BUILTIN_MQSUBHSS, 0, 0 },
8590 { CODE_FOR_mqsubhus, "__MQSUBHUS", FRV_BUILTIN_MQSUBHUS, 0, 0 },
8591 { CODE_FOR_mpackh, "__MPACKH", FRV_BUILTIN_MPACKH, 0, 0 },
8592 { CODE_FOR_mdpackh, "__MDPACKH", FRV_BUILTIN_MDPACKH, 0, 0 },
8593 { CODE_FOR_mcop1, "__Mcop1", FRV_BUILTIN_MCOP1, 0, 0 },
8594 { CODE_FOR_mcop2, "__Mcop2", FRV_BUILTIN_MCOP2, 0, 0 },
8595 { CODE_FOR_mwcut, "__MWCUT", FRV_BUILTIN_MWCUT, 0, 0 },
8596 { CODE_FOR_mqsaths, "__MQSATHS", FRV_BUILTIN_MQSATHS, 0, 0 }
8597 };
8598
8599 /* Media intrinsics that take two arguments, the first being an ACC number. */
8600
8601 static struct builtin_description bdesc_cut[] =
8602 {
8603 { CODE_FOR_mcut, "__MCUT", FRV_BUILTIN_MCUT, 0, 0 },
8604 { CODE_FOR_mcutss, "__MCUTSS", FRV_BUILTIN_MCUTSS, 0, 0 },
8605 { CODE_FOR_mdcutssi, "__MDCUTSSI", FRV_BUILTIN_MDCUTSSI, 0, 0 }
8606 };
8607
8608 /* Two-argument media intrinsics with an immediate second argument. */
8609
8610 static struct builtin_description bdesc_2argimm[] =
8611 {
8612 { CODE_FOR_mrotli, "__MROTLI", FRV_BUILTIN_MROTLI, 0, 0 },
8613 { CODE_FOR_mrotri, "__MROTRI", FRV_BUILTIN_MROTRI, 0, 0 },
8614 { CODE_FOR_msllhi, "__MSLLHI", FRV_BUILTIN_MSLLHI, 0, 0 },
8615 { CODE_FOR_msrlhi, "__MSRLHI", FRV_BUILTIN_MSRLHI, 0, 0 },
8616 { CODE_FOR_msrahi, "__MSRAHI", FRV_BUILTIN_MSRAHI, 0, 0 },
8617 { CODE_FOR_mexpdhw, "__MEXPDHW", FRV_BUILTIN_MEXPDHW, 0, 0 },
8618 { CODE_FOR_mexpdhd, "__MEXPDHD", FRV_BUILTIN_MEXPDHD, 0, 0 },
8619 { CODE_FOR_mdrotli, "__MDROTLI", FRV_BUILTIN_MDROTLI, 0, 0 },
8620 { CODE_FOR_mcplhi, "__MCPLHI", FRV_BUILTIN_MCPLHI, 0, 0 },
8621 { CODE_FOR_mcpli, "__MCPLI", FRV_BUILTIN_MCPLI, 0, 0 },
8622 { CODE_FOR_mhsetlos, "__MHSETLOS", FRV_BUILTIN_MHSETLOS, 0, 0 },
8623 { CODE_FOR_mhsetloh, "__MHSETLOH", FRV_BUILTIN_MHSETLOH, 0, 0 },
8624 { CODE_FOR_mhsethis, "__MHSETHIS", FRV_BUILTIN_MHSETHIS, 0, 0 },
8625 { CODE_FOR_mhsethih, "__MHSETHIH", FRV_BUILTIN_MHSETHIH, 0, 0 },
8626 { CODE_FOR_mhdseth, "__MHDSETH", FRV_BUILTIN_MHDSETH, 0, 0 }
8627 };
8628
8629 /* Media intrinsics that take two arguments and return void, the first argument
8630 being a pointer to 4 words in memory. */
8631
8632 static struct builtin_description bdesc_void2arg[] =
8633 {
8634 { CODE_FOR_mdunpackh, "__MDUNPACKH", FRV_BUILTIN_MDUNPACKH, 0, 0 },
8635 { CODE_FOR_mbtohe, "__MBTOHE", FRV_BUILTIN_MBTOHE, 0, 0 },
8636 };
8637
8638 /* Media intrinsics that take three arguments, the first being a const_int that
8639 denotes an accumulator, and that return void. */
8640
8641 static struct builtin_description bdesc_void3arg[] =
8642 {
8643 { CODE_FOR_mcpxrs, "__MCPXRS", FRV_BUILTIN_MCPXRS, 0, 0 },
8644 { CODE_FOR_mcpxru, "__MCPXRU", FRV_BUILTIN_MCPXRU, 0, 0 },
8645 { CODE_FOR_mcpxis, "__MCPXIS", FRV_BUILTIN_MCPXIS, 0, 0 },
8646 { CODE_FOR_mcpxiu, "__MCPXIU", FRV_BUILTIN_MCPXIU, 0, 0 },
8647 { CODE_FOR_mmulhs, "__MMULHS", FRV_BUILTIN_MMULHS, 0, 0 },
8648 { CODE_FOR_mmulhu, "__MMULHU", FRV_BUILTIN_MMULHU, 0, 0 },
8649 { CODE_FOR_mmulxhs, "__MMULXHS", FRV_BUILTIN_MMULXHS, 0, 0 },
8650 { CODE_FOR_mmulxhu, "__MMULXHU", FRV_BUILTIN_MMULXHU, 0, 0 },
8651 { CODE_FOR_mmachs, "__MMACHS", FRV_BUILTIN_MMACHS, 0, 0 },
8652 { CODE_FOR_mmachu, "__MMACHU", FRV_BUILTIN_MMACHU, 0, 0 },
8653 { CODE_FOR_mmrdhs, "__MMRDHS", FRV_BUILTIN_MMRDHS, 0, 0 },
8654 { CODE_FOR_mmrdhu, "__MMRDHU", FRV_BUILTIN_MMRDHU, 0, 0 },
8655 { CODE_FOR_mqcpxrs, "__MQCPXRS", FRV_BUILTIN_MQCPXRS, 0, 0 },
8656 { CODE_FOR_mqcpxru, "__MQCPXRU", FRV_BUILTIN_MQCPXRU, 0, 0 },
8657 { CODE_FOR_mqcpxis, "__MQCPXIS", FRV_BUILTIN_MQCPXIS, 0, 0 },
8658 { CODE_FOR_mqcpxiu, "__MQCPXIU", FRV_BUILTIN_MQCPXIU, 0, 0 },
8659 { CODE_FOR_mqmulhs, "__MQMULHS", FRV_BUILTIN_MQMULHS, 0, 0 },
8660 { CODE_FOR_mqmulhu, "__MQMULHU", FRV_BUILTIN_MQMULHU, 0, 0 },
8661 { CODE_FOR_mqmulxhs, "__MQMULXHS", FRV_BUILTIN_MQMULXHS, 0, 0 },
8662 { CODE_FOR_mqmulxhu, "__MQMULXHU", FRV_BUILTIN_MQMULXHU, 0, 0 },
8663 { CODE_FOR_mqmachs, "__MQMACHS", FRV_BUILTIN_MQMACHS, 0, 0 },
8664 { CODE_FOR_mqmachu, "__MQMACHU", FRV_BUILTIN_MQMACHU, 0, 0 },
8665 { CODE_FOR_mqxmachs, "__MQXMACHS", FRV_BUILTIN_MQXMACHS, 0, 0 },
8666 { CODE_FOR_mqxmacxhs, "__MQXMACXHS", FRV_BUILTIN_MQXMACXHS, 0, 0 },
8667 { CODE_FOR_mqmacxhs, "__MQMACXHS", FRV_BUILTIN_MQMACXHS, 0, 0 }
8668 };
8669
8670 /* Media intrinsics that take two accumulator numbers as argument and
8671 return void. */
8672
8673 static struct builtin_description bdesc_voidacc[] =
8674 {
8675 { CODE_FOR_maddaccs, "__MADDACCS", FRV_BUILTIN_MADDACCS, 0, 0 },
8676 { CODE_FOR_msubaccs, "__MSUBACCS", FRV_BUILTIN_MSUBACCS, 0, 0 },
8677 { CODE_FOR_masaccs, "__MASACCS", FRV_BUILTIN_MASACCS, 0, 0 },
8678 { CODE_FOR_mdaddaccs, "__MDADDACCS", FRV_BUILTIN_MDADDACCS, 0, 0 },
8679 { CODE_FOR_mdsubaccs, "__MDSUBACCS", FRV_BUILTIN_MDSUBACCS, 0, 0 },
8680 { CODE_FOR_mdasaccs, "__MDASACCS", FRV_BUILTIN_MDASACCS, 0, 0 }
8681 };
8682
8683 /* Initialize media builtins. */
8684
8685 static void
8686 frv_init_builtins (void)
8687 {
8688 tree endlink = void_list_node;
8689 tree accumulator = integer_type_node;
8690 tree integer = integer_type_node;
8691 tree voidt = void_type_node;
8692 tree uhalf = short_unsigned_type_node;
8693 tree sword1 = long_integer_type_node;
8694 tree uword1 = long_unsigned_type_node;
8695 tree sword2 = long_long_integer_type_node;
8696 tree uword2 = long_long_unsigned_type_node;
8697 tree uword4 = build_pointer_type (uword1);
8698
8699 #define UNARY(RET, T1) \
8700 build_function_type (RET, tree_cons (NULL_TREE, T1, endlink))
8701
8702 #define BINARY(RET, T1, T2) \
8703 build_function_type (RET, tree_cons (NULL_TREE, T1, \
8704 tree_cons (NULL_TREE, T2, endlink)))
8705
8706 #define TRINARY(RET, T1, T2, T3) \
8707 build_function_type (RET, tree_cons (NULL_TREE, T1, \
8708 tree_cons (NULL_TREE, T2, \
8709 tree_cons (NULL_TREE, T3, endlink))))
8710
8711 tree void_ftype_void = build_function_type (voidt, endlink);
8712
8713 tree void_ftype_acc = UNARY (voidt, accumulator);
8714 tree void_ftype_uw4_uw1 = BINARY (voidt, uword4, uword1);
8715 tree void_ftype_uw4_uw2 = BINARY (voidt, uword4, uword2);
8716 tree void_ftype_acc_uw1 = BINARY (voidt, accumulator, uword1);
8717 tree void_ftype_acc_acc = BINARY (voidt, accumulator, accumulator);
8718 tree void_ftype_acc_uw1_uw1 = TRINARY (voidt, accumulator, uword1, uword1);
8719 tree void_ftype_acc_sw1_sw1 = TRINARY (voidt, accumulator, sword1, sword1);
8720 tree void_ftype_acc_uw2_uw2 = TRINARY (voidt, accumulator, uword2, uword2);
8721 tree void_ftype_acc_sw2_sw2 = TRINARY (voidt, accumulator, sword2, sword2);
8722
8723 tree uw1_ftype_uw1 = UNARY (uword1, uword1);
8724 tree uw1_ftype_sw1 = UNARY (uword1, sword1);
8725 tree uw1_ftype_uw2 = UNARY (uword1, uword2);
8726 tree uw1_ftype_acc = UNARY (uword1, accumulator);
8727 tree uw1_ftype_uh_uh = BINARY (uword1, uhalf, uhalf);
8728 tree uw1_ftype_uw1_uw1 = BINARY (uword1, uword1, uword1);
8729 tree uw1_ftype_uw1_int = BINARY (uword1, uword1, integer);
8730 tree uw1_ftype_acc_uw1 = BINARY (uword1, accumulator, uword1);
8731 tree uw1_ftype_acc_sw1 = BINARY (uword1, accumulator, sword1);
8732 tree uw1_ftype_uw2_uw1 = BINARY (uword1, uword2, uword1);
8733 tree uw1_ftype_uw2_int = BINARY (uword1, uword2, integer);
8734
8735 tree sw1_ftype_int = UNARY (sword1, integer);
8736 tree sw1_ftype_sw1_sw1 = BINARY (sword1, sword1, sword1);
8737 tree sw1_ftype_sw1_int = BINARY (sword1, sword1, integer);
8738
8739 tree uw2_ftype_uw1 = UNARY (uword2, uword1);
8740 tree uw2_ftype_uw1_int = BINARY (uword2, uword1, integer);
8741 tree uw2_ftype_uw2_uw2 = BINARY (uword2, uword2, uword2);
8742 tree uw2_ftype_uw2_int = BINARY (uword2, uword2, integer);
8743 tree uw2_ftype_acc_int = BINARY (uword2, accumulator, integer);
8744
8745 tree sw2_ftype_sw2_sw2 = BINARY (sword2, sword2, sword2);
8746
8747 def_builtin ("__MAND", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAND);
8748 def_builtin ("__MOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MOR);
8749 def_builtin ("__MXOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MXOR);
8750 def_builtin ("__MNOT", uw1_ftype_uw1, FRV_BUILTIN_MNOT);
8751 def_builtin ("__MROTLI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTLI);
8752 def_builtin ("__MROTRI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTRI);
8753 def_builtin ("__MWCUT", uw1_ftype_uw2_uw1, FRV_BUILTIN_MWCUT);
8754 def_builtin ("__MAVEH", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAVEH);
8755 def_builtin ("__MSLLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSLLHI);
8756 def_builtin ("__MSRLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSRLHI);
8757 def_builtin ("__MSRAHI", sw1_ftype_sw1_int, FRV_BUILTIN_MSRAHI);
8758 def_builtin ("__MSATHS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSATHS);
8759 def_builtin ("__MSATHU", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSATHU);
8760 def_builtin ("__MADDHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MADDHSS);
8761 def_builtin ("__MADDHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MADDHUS);
8762 def_builtin ("__MSUBHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSUBHSS);
8763 def_builtin ("__MSUBHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSUBHUS);
8764 def_builtin ("__MMULHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULHS);
8765 def_builtin ("__MMULHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULHU);
8766 def_builtin ("__MMULXHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULXHS);
8767 def_builtin ("__MMULXHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULXHU);
8768 def_builtin ("__MMACHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMACHS);
8769 def_builtin ("__MMACHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMACHU);
8770 def_builtin ("__MMRDHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMRDHS);
8771 def_builtin ("__MMRDHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMRDHU);
8772 def_builtin ("__MQADDHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQADDHSS);
8773 def_builtin ("__MQADDHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQADDHUS);
8774 def_builtin ("__MQSUBHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSUBHSS);
8775 def_builtin ("__MQSUBHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQSUBHUS);
8776 def_builtin ("__MQMULHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULHS);
8777 def_builtin ("__MQMULHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULHU);
8778 def_builtin ("__MQMULXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULXHS);
8779 def_builtin ("__MQMULXHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULXHU);
8780 def_builtin ("__MQMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACHS);
8781 def_builtin ("__MQMACHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMACHU);
8782 def_builtin ("__MCPXRS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXRS);
8783 def_builtin ("__MCPXRU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXRU);
8784 def_builtin ("__MCPXIS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXIS);
8785 def_builtin ("__MCPXIU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXIU);
8786 def_builtin ("__MQCPXRS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXRS);
8787 def_builtin ("__MQCPXRU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXRU);
8788 def_builtin ("__MQCPXIS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXIS);
8789 def_builtin ("__MQCPXIU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXIU);
8790 def_builtin ("__MCUT", uw1_ftype_acc_uw1, FRV_BUILTIN_MCUT);
8791 def_builtin ("__MCUTSS", uw1_ftype_acc_sw1, FRV_BUILTIN_MCUTSS);
8792 def_builtin ("__MEXPDHW", uw1_ftype_uw1_int, FRV_BUILTIN_MEXPDHW);
8793 def_builtin ("__MEXPDHD", uw2_ftype_uw1_int, FRV_BUILTIN_MEXPDHD);
8794 def_builtin ("__MPACKH", uw1_ftype_uh_uh, FRV_BUILTIN_MPACKH);
8795 def_builtin ("__MUNPACKH", uw2_ftype_uw1, FRV_BUILTIN_MUNPACKH);
8796 def_builtin ("__MDPACKH", uw2_ftype_uw2_uw2, FRV_BUILTIN_MDPACKH);
8797 def_builtin ("__MDUNPACKH", void_ftype_uw4_uw2, FRV_BUILTIN_MDUNPACKH);
8798 def_builtin ("__MBTOH", uw2_ftype_uw1, FRV_BUILTIN_MBTOH);
8799 def_builtin ("__MHTOB", uw1_ftype_uw2, FRV_BUILTIN_MHTOB);
8800 def_builtin ("__MBTOHE", void_ftype_uw4_uw1, FRV_BUILTIN_MBTOHE);
8801 def_builtin ("__MCLRACC", void_ftype_acc, FRV_BUILTIN_MCLRACC);
8802 def_builtin ("__MCLRACCA", void_ftype_void, FRV_BUILTIN_MCLRACCA);
8803 def_builtin ("__MRDACC", uw1_ftype_acc, FRV_BUILTIN_MRDACC);
8804 def_builtin ("__MRDACCG", uw1_ftype_acc, FRV_BUILTIN_MRDACCG);
8805 def_builtin ("__MWTACC", void_ftype_acc_uw1, FRV_BUILTIN_MWTACC);
8806 def_builtin ("__MWTACCG", void_ftype_acc_uw1, FRV_BUILTIN_MWTACCG);
8807 def_builtin ("__Mcop1", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP1);
8808 def_builtin ("__Mcop2", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP2);
8809 def_builtin ("__MTRAP", void_ftype_void, FRV_BUILTIN_MTRAP);
8810 def_builtin ("__MQXMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACHS);
8811 def_builtin ("__MQXMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACXHS);
8812 def_builtin ("__MQMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACXHS);
8813 def_builtin ("__MADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MADDACCS);
8814 def_builtin ("__MSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MSUBACCS);
8815 def_builtin ("__MASACCS", void_ftype_acc_acc, FRV_BUILTIN_MASACCS);
8816 def_builtin ("__MDADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MDADDACCS);
8817 def_builtin ("__MDSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MDSUBACCS);
8818 def_builtin ("__MDASACCS", void_ftype_acc_acc, FRV_BUILTIN_MDASACCS);
8819 def_builtin ("__MABSHS", uw1_ftype_sw1, FRV_BUILTIN_MABSHS);
8820 def_builtin ("__MDROTLI", uw2_ftype_uw2_int, FRV_BUILTIN_MDROTLI);
8821 def_builtin ("__MCPLHI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLHI);
8822 def_builtin ("__MCPLI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLI);
8823 def_builtin ("__MDCUTSSI", uw2_ftype_acc_int, FRV_BUILTIN_MDCUTSSI);
8824 def_builtin ("__MQSATHS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSATHS);
8825 def_builtin ("__MHSETLOS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETLOS);
8826 def_builtin ("__MHSETHIS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETHIS);
8827 def_builtin ("__MHDSETS", sw1_ftype_int, FRV_BUILTIN_MHDSETS);
8828 def_builtin ("__MHSETLOH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETLOH);
8829 def_builtin ("__MHSETHIH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETHIH);
8830 def_builtin ("__MHDSETH", uw1_ftype_uw1_int, FRV_BUILTIN_MHDSETH);
8831
8832 #undef UNARY
8833 #undef BINARY
8834 #undef TRINARY
8835 }
8836
8837 /* Set the names for various arithmetic operations according to the
8838 FRV ABI. */
8839 static void
8840 frv_init_libfuncs (void)
8841 {
8842 set_optab_libfunc (smod_optab, SImode, "__modi");
8843 set_optab_libfunc (umod_optab, SImode, "__umodi");
8844
8845 set_optab_libfunc (add_optab, DImode, "__addll");
8846 set_optab_libfunc (sub_optab, DImode, "__subll");
8847 set_optab_libfunc (smul_optab, DImode, "__mulll");
8848 set_optab_libfunc (sdiv_optab, DImode, "__divll");
8849 set_optab_libfunc (smod_optab, DImode, "__modll");
8850 set_optab_libfunc (umod_optab, DImode, "__umodll");
8851 set_optab_libfunc (and_optab, DImode, "__andll");
8852 set_optab_libfunc (ior_optab, DImode, "__orll");
8853 set_optab_libfunc (xor_optab, DImode, "__xorll");
8854 set_optab_libfunc (one_cmpl_optab, DImode, "__notll");
8855
8856 set_optab_libfunc (add_optab, SFmode, "__addf");
8857 set_optab_libfunc (sub_optab, SFmode, "__subf");
8858 set_optab_libfunc (smul_optab, SFmode, "__mulf");
8859 set_optab_libfunc (sdiv_optab, SFmode, "__divf");
8860
8861 set_optab_libfunc (add_optab, DFmode, "__addd");
8862 set_optab_libfunc (sub_optab, DFmode, "__subd");
8863 set_optab_libfunc (smul_optab, DFmode, "__muld");
8864 set_optab_libfunc (sdiv_optab, DFmode, "__divd");
8865
8866 set_conv_libfunc (sext_optab, DFmode, SFmode, "__ftod");
8867 set_conv_libfunc (trunc_optab, SFmode, DFmode, "__dtof");
8868
8869 set_conv_libfunc (sfix_optab, SImode, SFmode, "__ftoi");
8870 set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll");
8871 set_conv_libfunc (sfix_optab, SImode, DFmode, "__dtoi");
8872 set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll");
8873
8874 set_conv_libfunc (ufix_optab, SImode, SFmode, "__ftoui");
8875 set_conv_libfunc (ufix_optab, DImode, SFmode, "__ftoull");
8876 set_conv_libfunc (ufix_optab, SImode, DFmode, "__dtoui");
8877 set_conv_libfunc (ufix_optab, DImode, DFmode, "__dtoull");
8878
8879 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__itof");
8880 set_conv_libfunc (sfloat_optab, SFmode, DImode, "__lltof");
8881 set_conv_libfunc (sfloat_optab, DFmode, SImode, "__itod");
8882 set_conv_libfunc (sfloat_optab, DFmode, DImode, "__lltod");
8883 }
8884
8885 /* Convert an integer constant to an accumulator register. ICODE is the
8886 code of the target instruction, OPNUM is the number of the
8887 accumulator operand and OPVAL is the constant integer. Try both
8888 ACC and ACCG registers; only report an error if neither fit the
8889 instruction. */
8890
8891 static rtx
8892 frv_int_to_acc (enum insn_code icode, int opnum, rtx opval)
8893 {
8894 rtx reg;
8895
8896 if (GET_CODE (opval) != CONST_INT)
8897 {
8898 error ("accumulator is not a constant integer");
8899 return NULL_RTX;
8900 }
8901 if (! IN_RANGE_P (INTVAL (opval), 0, NUM_ACCS - 1))
8902 {
8903 error ("accumulator number is out of bounds");
8904 return NULL_RTX;
8905 }
8906
8907 reg = gen_rtx_REG (insn_data[icode].operand[opnum].mode,
8908 ACC_FIRST + INTVAL (opval));
8909 if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode))
8910 REGNO (reg) = ACCG_FIRST + INTVAL (opval);
8911
8912 if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode))
8913 {
8914 error ("inappropriate accumulator for `%s'", insn_data[icode].name);
8915 return NULL_RTX;
8916 }
8917 return reg;
8918 }
8919
8920 /* If an ACC rtx has mode MODE, return the mode that the matching ACCG
8921 should have. */
8922
8923 static enum machine_mode
8924 frv_matching_accg_mode (enum machine_mode mode)
8925 {
8926 switch (mode)
8927 {
8928 case V4SImode:
8929 return V4QImode;
8930
8931 case DImode:
8932 return HImode;
8933
8934 case SImode:
8935 return QImode;
8936
8937 default:
8938 abort ();
8939 }
8940 }
8941
8942 /* Return the accumulator guard that should be paired with accumulator
8943 register ACC. The mode of the returned register is in the same
8944 class as ACC, but is four times smaller. */
8945
8946 rtx
8947 frv_matching_accg_for_acc (rtx acc)
8948 {
8949 return gen_rtx_REG (frv_matching_accg_mode (GET_MODE (acc)),
8950 REGNO (acc) - ACC_FIRST + ACCG_FIRST);
8951 }
8952
8953 /* Read a value from the head of the tree list pointed to by ARGLISTPTR.
8954 Return the value as an rtx and replace *ARGLISTPTR with the tail of the
8955 list. */
8956
8957 static rtx
8958 frv_read_argument (tree *arglistptr)
8959 {
8960 tree next = TREE_VALUE (*arglistptr);
8961 *arglistptr = TREE_CHAIN (*arglistptr);
8962 return expand_expr (next, NULL_RTX, VOIDmode, 0);
8963 }
8964
8965 /* Return true if OPVAL can be used for operand OPNUM of instruction ICODE.
8966 The instruction should require a constant operand of some sort. The
8967 function prints an error if OPVAL is not valid. */
8968
8969 static int
8970 frv_check_constant_argument (enum insn_code icode, int opnum, rtx opval)
8971 {
8972 if (GET_CODE (opval) != CONST_INT)
8973 {
8974 error ("`%s' expects a constant argument", insn_data[icode].name);
8975 return FALSE;
8976 }
8977 if (! (*insn_data[icode].operand[opnum].predicate) (opval, VOIDmode))
8978 {
8979 error ("constant argument out of range for `%s'", insn_data[icode].name);
8980 return FALSE;
8981 }
8982 return TRUE;
8983 }
8984
8985 /* Return a legitimate rtx for instruction ICODE's return value. Use TARGET
8986 if it's not null, has the right mode, and satisfies operand 0's
8987 predicate. */
8988
8989 static rtx
8990 frv_legitimize_target (enum insn_code icode, rtx target)
8991 {
8992 enum machine_mode mode = insn_data[icode].operand[0].mode;
8993
8994 if (! target
8995 || GET_MODE (target) != mode
8996 || ! (*insn_data[icode].operand[0].predicate) (target, mode))
8997 return gen_reg_rtx (mode);
8998 else
8999 return target;
9000 }
9001
9002 /* Given that ARG is being passed as operand OPNUM to instruction ICODE,
9003 check whether ARG satisfies the operand's constraints. If it doesn't,
9004 copy ARG to a temporary register and return that. Otherwise return ARG
9005 itself. */
9006
9007 static rtx
9008 frv_legitimize_argument (enum insn_code icode, int opnum, rtx arg)
9009 {
9010 enum machine_mode mode = insn_data[icode].operand[opnum].mode;
9011
9012 if ((*insn_data[icode].operand[opnum].predicate) (arg, mode))
9013 return arg;
9014 else
9015 return copy_to_mode_reg (mode, arg);
9016 }
9017
9018 /* Expand builtins that take a single, constant argument. At the moment,
9019 only MHDSETS falls into this category. */
9020
9021 static rtx
9022 frv_expand_set_builtin (enum insn_code icode, tree arglist, rtx target)
9023 {
9024 rtx pat;
9025 rtx op0 = frv_read_argument (&arglist);
9026
9027 if (! frv_check_constant_argument (icode, 1, op0))
9028 return NULL_RTX;
9029
9030 target = frv_legitimize_target (icode, target);
9031 pat = GEN_FCN (icode) (target, op0);
9032 if (! pat)
9033 return NULL_RTX;
9034
9035 emit_insn (pat);
9036 return target;
9037 }
9038
9039 /* Expand builtins that take one operand. */
9040
9041 static rtx
9042 frv_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
9043 {
9044 rtx pat;
9045 rtx op0 = frv_read_argument (&arglist);
9046
9047 target = frv_legitimize_target (icode, target);
9048 op0 = frv_legitimize_argument (icode, 1, op0);
9049 pat = GEN_FCN (icode) (target, op0);
9050 if (! pat)
9051 return NULL_RTX;
9052
9053 emit_insn (pat);
9054 return target;
9055 }
9056
9057 /* Expand builtins that take two operands. */
9058
9059 static rtx
9060 frv_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
9061 {
9062 rtx pat;
9063 rtx op0 = frv_read_argument (&arglist);
9064 rtx op1 = frv_read_argument (&arglist);
9065
9066 target = frv_legitimize_target (icode, target);
9067 op0 = frv_legitimize_argument (icode, 1, op0);
9068 op1 = frv_legitimize_argument (icode, 2, op1);
9069 pat = GEN_FCN (icode) (target, op0, op1);
9070 if (! pat)
9071 return NULL_RTX;
9072
9073 emit_insn (pat);
9074 return target;
9075 }
9076
9077 /* Expand cut-style builtins, which take two operands and an implicit ACCG
9078 one. */
9079
9080 static rtx
9081 frv_expand_cut_builtin (enum insn_code icode, tree arglist, rtx target)
9082 {
9083 rtx pat;
9084 rtx op0 = frv_read_argument (&arglist);
9085 rtx op1 = frv_read_argument (&arglist);
9086 rtx op2;
9087
9088 target = frv_legitimize_target (icode, target);
9089 op0 = frv_int_to_acc (icode, 1, op0);
9090 if (! op0)
9091 return NULL_RTX;
9092
9093 if (icode == CODE_FOR_mdcutssi || GET_CODE (op1) == CONST_INT)
9094 {
9095 if (! frv_check_constant_argument (icode, 2, op1))
9096 return NULL_RTX;
9097 }
9098 else
9099 op1 = frv_legitimize_argument (icode, 2, op1);
9100
9101 op2 = frv_matching_accg_for_acc (op0);
9102 pat = GEN_FCN (icode) (target, op0, op1, op2);
9103 if (! pat)
9104 return NULL_RTX;
9105
9106 emit_insn (pat);
9107 return target;
9108 }
9109
9110 /* Expand builtins that take two operands and the second is immediate. */
9111
9112 static rtx
9113 frv_expand_binopimm_builtin (enum insn_code icode, tree arglist, rtx target)
9114 {
9115 rtx pat;
9116 rtx op0 = frv_read_argument (&arglist);
9117 rtx op1 = frv_read_argument (&arglist);
9118
9119 if (! frv_check_constant_argument (icode, 2, op1))
9120 return NULL_RTX;
9121
9122 target = frv_legitimize_target (icode, target);
9123 op0 = frv_legitimize_argument (icode, 1, op0);
9124 pat = GEN_FCN (icode) (target, op0, op1);
9125 if (! pat)
9126 return NULL_RTX;
9127
9128 emit_insn (pat);
9129 return target;
9130 }
9131
9132 /* Expand builtins that take two operands, the first operand being a pointer to
9133 ints and return void. */
9134
9135 static rtx
9136 frv_expand_voidbinop_builtin (enum insn_code icode, tree arglist)
9137 {
9138 rtx pat;
9139 rtx op0 = frv_read_argument (&arglist);
9140 rtx op1 = frv_read_argument (&arglist);
9141 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
9142 rtx addr;
9143
9144 if (GET_CODE (op0) != MEM)
9145 {
9146 rtx reg = op0;
9147
9148 if (! offsettable_address_p (0, mode0, op0))
9149 {
9150 reg = gen_reg_rtx (Pmode);
9151 emit_insn (gen_rtx_SET (VOIDmode, reg, op0));
9152 }
9153
9154 op0 = gen_rtx_MEM (SImode, reg);
9155 }
9156
9157 addr = XEXP (op0, 0);
9158 if (! offsettable_address_p (0, mode0, addr))
9159 addr = copy_to_mode_reg (Pmode, op0);
9160
9161 op0 = change_address (op0, V4SImode, addr);
9162 op1 = frv_legitimize_argument (icode, 1, op1);
9163 pat = GEN_FCN (icode) (op0, op1);
9164 if (! pat)
9165 return 0;
9166
9167 emit_insn (pat);
9168 return 0;
9169 }
9170
9171 /* Expand builtins that take three operands and return void. The first
9172 argument must be a constant that describes a pair or quad accumulators. A
9173 fourth argument is created that is the accumulator guard register that
9174 corresponds to the accumulator. */
9175
9176 static rtx
9177 frv_expand_voidtriop_builtin (enum insn_code icode, tree arglist)
9178 {
9179 rtx pat;
9180 rtx op0 = frv_read_argument (&arglist);
9181 rtx op1 = frv_read_argument (&arglist);
9182 rtx op2 = frv_read_argument (&arglist);
9183 rtx op3;
9184
9185 op0 = frv_int_to_acc (icode, 0, op0);
9186 if (! op0)
9187 return NULL_RTX;
9188
9189 op1 = frv_legitimize_argument (icode, 1, op1);
9190 op2 = frv_legitimize_argument (icode, 2, op2);
9191 op3 = frv_matching_accg_for_acc (op0);
9192 pat = GEN_FCN (icode) (op0, op1, op2, op3);
9193 if (! pat)
9194 return NULL_RTX;
9195
9196 emit_insn (pat);
9197 return NULL_RTX;
9198 }
9199
9200 /* Expand builtins that perform accumulator-to-accumulator operations.
9201 These builtins take two accumulator numbers as argument and return
9202 void. */
9203
9204 static rtx
9205 frv_expand_voidaccop_builtin (enum insn_code icode, tree arglist)
9206 {
9207 rtx pat;
9208 rtx op0 = frv_read_argument (&arglist);
9209 rtx op1 = frv_read_argument (&arglist);
9210 rtx op2;
9211 rtx op3;
9212
9213 op0 = frv_int_to_acc (icode, 0, op0);
9214 if (! op0)
9215 return NULL_RTX;
9216
9217 op1 = frv_int_to_acc (icode, 1, op1);
9218 if (! op1)
9219 return NULL_RTX;
9220
9221 op2 = frv_matching_accg_for_acc (op0);
9222 op3 = frv_matching_accg_for_acc (op1);
9223 pat = GEN_FCN (icode) (op0, op1, op2, op3);
9224 if (! pat)
9225 return NULL_RTX;
9226
9227 emit_insn (pat);
9228 return NULL_RTX;
9229 }
9230
9231 /* Expand the MCLRACC builtin. This builtin takes a single accumulator
9232 number as argument. */
9233
9234 static rtx
9235 frv_expand_mclracc_builtin (tree arglist)
9236 {
9237 enum insn_code icode = CODE_FOR_mclracc;
9238 rtx pat;
9239 rtx op0 = frv_read_argument (&arglist);
9240
9241 op0 = frv_int_to_acc (icode, 0, op0);
9242 if (! op0)
9243 return NULL_RTX;
9244
9245 pat = GEN_FCN (icode) (op0);
9246 if (pat)
9247 emit_insn (pat);
9248
9249 return NULL_RTX;
9250 }
9251
9252 /* Expand builtins that take no arguments. */
9253
9254 static rtx
9255 frv_expand_noargs_builtin (enum insn_code icode)
9256 {
9257 rtx pat = GEN_FCN (icode) (GEN_INT (0));
9258 if (pat)
9259 emit_insn (pat);
9260
9261 return NULL_RTX;
9262 }
9263
9264 /* Expand MRDACC and MRDACCG. These builtins take a single accumulator
9265 number or accumulator guard number as argument and return an SI integer. */
9266
9267 static rtx
9268 frv_expand_mrdacc_builtin (enum insn_code icode, tree arglist)
9269 {
9270 rtx pat;
9271 rtx target = gen_reg_rtx (SImode);
9272 rtx op0 = frv_read_argument (&arglist);
9273
9274 op0 = frv_int_to_acc (icode, 1, op0);
9275 if (! op0)
9276 return NULL_RTX;
9277
9278 pat = GEN_FCN (icode) (target, op0);
9279 if (! pat)
9280 return NULL_RTX;
9281
9282 emit_insn (pat);
9283 return target;
9284 }
9285
9286 /* Expand MWTACC and MWTACCG. These builtins take an accumulator or
9287 accumulator guard as their first argument and an SImode value as their
9288 second. */
9289
9290 static rtx
9291 frv_expand_mwtacc_builtin (enum insn_code icode, tree arglist)
9292 {
9293 rtx pat;
9294 rtx op0 = frv_read_argument (&arglist);
9295 rtx op1 = frv_read_argument (&arglist);
9296
9297 op0 = frv_int_to_acc (icode, 0, op0);
9298 if (! op0)
9299 return NULL_RTX;
9300
9301 op1 = frv_legitimize_argument (icode, 1, op1);
9302 pat = GEN_FCN (icode) (op0, op1);
9303 if (pat)
9304 emit_insn (pat);
9305
9306 return NULL_RTX;
9307 }
9308
9309 /* Expand builtins. */
9310
9311 static rtx
9312 frv_expand_builtin (tree exp,
9313 rtx target,
9314 rtx subtarget ATTRIBUTE_UNUSED,
9315 enum machine_mode mode ATTRIBUTE_UNUSED,
9316 int ignore ATTRIBUTE_UNUSED)
9317 {
9318 tree arglist = TREE_OPERAND (exp, 1);
9319 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
9320 unsigned fcode = (unsigned)DECL_FUNCTION_CODE (fndecl);
9321 unsigned i;
9322 struct builtin_description *d;
9323
9324 if (! TARGET_MEDIA)
9325 {
9326 error ("media functions are not available unless -mmedia is used");
9327 return NULL_RTX;
9328 }
9329
9330 switch (fcode)
9331 {
9332 case FRV_BUILTIN_MCOP1:
9333 case FRV_BUILTIN_MCOP2:
9334 case FRV_BUILTIN_MDUNPACKH:
9335 case FRV_BUILTIN_MBTOHE:
9336 if (! TARGET_MEDIA_REV1)
9337 {
9338 error ("this media function is only available on the fr500");
9339 return NULL_RTX;
9340 }
9341 break;
9342
9343 case FRV_BUILTIN_MQXMACHS:
9344 case FRV_BUILTIN_MQXMACXHS:
9345 case FRV_BUILTIN_MQMACXHS:
9346 case FRV_BUILTIN_MADDACCS:
9347 case FRV_BUILTIN_MSUBACCS:
9348 case FRV_BUILTIN_MASACCS:
9349 case FRV_BUILTIN_MDADDACCS:
9350 case FRV_BUILTIN_MDSUBACCS:
9351 case FRV_BUILTIN_MDASACCS:
9352 case FRV_BUILTIN_MABSHS:
9353 case FRV_BUILTIN_MDROTLI:
9354 case FRV_BUILTIN_MCPLHI:
9355 case FRV_BUILTIN_MCPLI:
9356 case FRV_BUILTIN_MDCUTSSI:
9357 case FRV_BUILTIN_MQSATHS:
9358 case FRV_BUILTIN_MHSETLOS:
9359 case FRV_BUILTIN_MHSETLOH:
9360 case FRV_BUILTIN_MHSETHIS:
9361 case FRV_BUILTIN_MHSETHIH:
9362 case FRV_BUILTIN_MHDSETS:
9363 case FRV_BUILTIN_MHDSETH:
9364 if (! TARGET_MEDIA_REV2)
9365 {
9366 error ("this media function is only available on the fr400");
9367 return NULL_RTX;
9368 }
9369 break;
9370
9371 default:
9372 break;
9373 }
9374
9375 /* Expand unique builtins. */
9376
9377 switch (fcode)
9378 {
9379 case FRV_BUILTIN_MTRAP:
9380 return frv_expand_noargs_builtin (CODE_FOR_mtrap);
9381
9382 case FRV_BUILTIN_MCLRACC:
9383 return frv_expand_mclracc_builtin (arglist);
9384
9385 case FRV_BUILTIN_MCLRACCA:
9386 if (TARGET_ACC_8)
9387 return frv_expand_noargs_builtin (CODE_FOR_mclracca8);
9388 else
9389 return frv_expand_noargs_builtin (CODE_FOR_mclracca4);
9390
9391 case FRV_BUILTIN_MRDACC:
9392 return frv_expand_mrdacc_builtin (CODE_FOR_mrdacc, arglist);
9393
9394 case FRV_BUILTIN_MRDACCG:
9395 return frv_expand_mrdacc_builtin (CODE_FOR_mrdaccg, arglist);
9396
9397 case FRV_BUILTIN_MWTACC:
9398 return frv_expand_mwtacc_builtin (CODE_FOR_mwtacc, arglist);
9399
9400 case FRV_BUILTIN_MWTACCG:
9401 return frv_expand_mwtacc_builtin (CODE_FOR_mwtaccg, arglist);
9402
9403 default:
9404 break;
9405 }
9406
9407 /* Expand groups of builtins. */
9408
9409 for (i = 0, d = bdesc_set; i < ARRAY_SIZE (bdesc_set); i++, d++)
9410 if (d->code == fcode)
9411 return frv_expand_set_builtin (d->icode, arglist, target);
9412
9413 for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
9414 if (d->code == fcode)
9415 return frv_expand_unop_builtin (d->icode, arglist, target);
9416
9417 for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
9418 if (d->code == fcode)
9419 return frv_expand_binop_builtin (d->icode, arglist, target);
9420
9421 for (i = 0, d = bdesc_cut; i < ARRAY_SIZE (bdesc_cut); i++, d++)
9422 if (d->code == fcode)
9423 return frv_expand_cut_builtin (d->icode, arglist, target);
9424
9425 for (i = 0, d = bdesc_2argimm; i < ARRAY_SIZE (bdesc_2argimm); i++, d++)
9426 if (d->code == fcode)
9427 return frv_expand_binopimm_builtin (d->icode, arglist, target);
9428
9429 for (i = 0, d = bdesc_void2arg; i < ARRAY_SIZE (bdesc_void2arg); i++, d++)
9430 if (d->code == fcode)
9431 return frv_expand_voidbinop_builtin (d->icode, arglist);
9432
9433 for (i = 0, d = bdesc_void3arg; i < ARRAY_SIZE (bdesc_void3arg); i++, d++)
9434 if (d->code == fcode)
9435 return frv_expand_voidtriop_builtin (d->icode, arglist);
9436
9437 for (i = 0, d = bdesc_voidacc; i < ARRAY_SIZE (bdesc_voidacc); i++, d++)
9438 if (d->code == fcode)
9439 return frv_expand_voidaccop_builtin (d->icode, arglist);
9440
9441 return 0;
9442 }
9443
9444 static bool
9445 frv_in_small_data_p (tree decl)
9446 {
9447 HOST_WIDE_INT size;
9448 tree section_name;
9449
9450 /* Don't apply the -G flag to internal compiler structures. We
9451 should leave such structures in the main data section, partly
9452 for efficiency and partly because the size of some of them
9453 (such as C++ typeinfos) is not known until later. */
9454 if (TREE_CODE (decl) != VAR_DECL || DECL_ARTIFICIAL (decl))
9455 return false;
9456
9457 /* If we already know which section the decl should be in, see if
9458 it's a small data section. */
9459 section_name = DECL_SECTION_NAME (decl);
9460 if (section_name)
9461 {
9462 if (TREE_CODE (section_name) != STRING_CST)
9463 abort ();
9464 if (frv_string_begins_with (section_name, ".sdata"))
9465 return true;
9466 if (frv_string_begins_with (section_name, ".sbss"))
9467 return true;
9468 return false;
9469 }
9470
9471 size = int_size_in_bytes (TREE_TYPE (decl));
9472 if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
9473 return true;
9474
9475 return false;
9476 }
9477 \f
9478 static bool
9479 frv_rtx_costs (rtx x,
9480 int code ATTRIBUTE_UNUSED,
9481 int outer_code ATTRIBUTE_UNUSED,
9482 int *total)
9483 {
9484 switch (code)
9485 {
9486 case CONST_INT:
9487 /* Make 12 bit integers really cheap. */
9488 if (IN_RANGE_P (INTVAL (x), -2048, 2047))
9489 {
9490 *total = 0;
9491 return true;
9492 }
9493 /* FALLTHRU */
9494
9495 case CONST:
9496 case LABEL_REF:
9497 case SYMBOL_REF:
9498 case CONST_DOUBLE:
9499 *total = COSTS_N_INSNS (2);
9500 return true;
9501
9502 case PLUS:
9503 case MINUS:
9504 case AND:
9505 case IOR:
9506 case XOR:
9507 case ASHIFT:
9508 case ASHIFTRT:
9509 case LSHIFTRT:
9510 case NOT:
9511 case NEG:
9512 case COMPARE:
9513 if (GET_MODE (x) == SImode)
9514 *total = COSTS_N_INSNS (1);
9515 else if (GET_MODE (x) == DImode)
9516 *total = COSTS_N_INSNS (2);
9517 else
9518 *total = COSTS_N_INSNS (3);
9519 return true;
9520
9521 case MULT:
9522 if (GET_MODE (x) == SImode)
9523 *total = COSTS_N_INSNS (2);
9524 else
9525 *total = COSTS_N_INSNS (6); /* guess */
9526 return true;
9527
9528 case DIV:
9529 case UDIV:
9530 case MOD:
9531 case UMOD:
9532 *total = COSTS_N_INSNS (18);
9533 return true;
9534
9535 default:
9536 return false;
9537 }
9538 }
9539 \f
9540 static void
9541 frv_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9542 {
9543 ctors_section ();
9544 assemble_align (POINTER_SIZE);
9545 assemble_integer_with_op ("\t.picptr\t", symbol);
9546 }
9547
9548 static void
9549 frv_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9550 {
9551 dtors_section ();
9552 assemble_align (POINTER_SIZE);
9553 assemble_integer_with_op ("\t.picptr\t", symbol);
9554 }