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