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