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