1 /* FR30 specific functions.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include "coretypes.h"
31 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "insn-attr.h"
47 #include "target-def.h"
50 /*{{{ Function Prologues & Epilogues */
52 /* Define the information needed to generate branch and scc insns. This is
53 stored from the compare operation. */
55 struct rtx_def
* fr30_compare_op0
;
56 struct rtx_def
* fr30_compare_op1
;
58 /* The FR30 stack looks like this:
60 Before call After call
62 +-----------------------+ +-----------------------+ high
64 | local variables, | | local variables, |
65 | reg save area, etc. | | reg save area, etc. |
67 +-----------------------+ +-----------------------+
69 | args to the func that | | args to this func. |
70 | is being called that | | |
71 SP ->| do not fit in regs | | |
72 +-----------------------+ +-----------------------+
73 | args that used to be | \
74 | in regs; only created | | pretend_size
75 AP-> | for vararg funcs | /
76 +-----------------------+
78 | register save area | |
80 +-----------------------+ | reg_size
82 +-----------------------+ |
83 FP ->| previous frame ptr | /
84 +-----------------------+
86 | local variables | | var_size
88 +-----------------------+
90 low | room for args to | |
91 memory | other funcs called | | args_size
94 +-----------------------+
96 Note, AP is a fake hard register. It will be eliminated in favor of
97 SP or FP as appropriate.
99 Note, Some or all of the stack sections above may be omitted if they
102 /* Structure to be filled in by fr30_compute_frame_size() with register
103 save masks, and offsets for the current function. */
104 struct fr30_frame_info
106 unsigned int total_size
; /* # Bytes that the entire frame takes up. */
107 unsigned int pretend_size
; /* # Bytes we push and pretend caller did. */
108 unsigned int args_size
; /* # Bytes that outgoing arguments take up. */
109 unsigned int reg_size
; /* # Bytes needed to store regs. */
110 unsigned int var_size
; /* # Bytes that variables take up. */
111 unsigned int frame_size
; /* # Bytes in current frame. */
112 unsigned int gmask
; /* Mask of saved registers. */
113 unsigned int save_fp
; /* Nonzero if frame pointer must be saved. */
114 unsigned int save_rp
; /* Nonzero if return pointer must be saved. */
115 int initialised
; /* Nonzero if frame size already calculated. */
118 /* Current frame information calculated by fr30_compute_frame_size(). */
119 static struct fr30_frame_info current_frame_info
;
121 /* Zero structure to initialize current_frame_info. */
122 static struct fr30_frame_info zero_frame_info
;
124 static void fr30_setup_incoming_varargs (CUMULATIVE_ARGS
*, enum machine_mode
,
126 static rtx
fr30_pass_by_reference (tree
, tree
);
127 static rtx
fr30_pass_by_value (tree
, tree
);
129 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
130 #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
132 /* Tell prologue and epilogue if register REGNO should be saved / restored.
133 The return address and frame pointer are treated separately.
134 Don't consider them here. */
135 #define MUST_SAVE_REGISTER(regno) \
136 ( (regno) != RETURN_POINTER_REGNUM \
137 && (regno) != FRAME_POINTER_REGNUM \
138 && regs_ever_live [regno] \
139 && ! call_used_regs [regno] )
141 #define MUST_SAVE_FRAME_POINTER (regs_ever_live [FRAME_POINTER_REGNUM] || frame_pointer_needed)
142 #define MUST_SAVE_RETURN_POINTER (regs_ever_live [RETURN_POINTER_REGNUM] || current_function_profile)
144 #if UNITS_PER_WORD == 4
145 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
148 /* Initialize the GCC target structure. */
149 #undef TARGET_ASM_ALIGNED_HI_OP
150 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
151 #undef TARGET_ASM_ALIGNED_SI_OP
152 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
154 #undef TARGET_PROMOTE_PROTOTYPES
155 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
157 #undef TARGET_STRUCT_VALUE_RTX
158 #define TARGET_STRUCT_VALUE_RTX hook_rtx_tree_int_null
160 #undef TARGET_SETUP_INCOMING_VARARGS
161 #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
163 struct gcc_target targetm
= TARGET_INITIALIZER
;
165 /* Returns the number of bytes offset between FROM_REG and TO_REG
166 for the current function. As a side effect it fills in the
167 current_frame_info structure, if the data is available. */
169 fr30_compute_frame_size (int from_reg
, int to_reg
)
172 unsigned int return_value
;
173 unsigned int var_size
;
174 unsigned int args_size
;
175 unsigned int pretend_size
;
176 unsigned int reg_size
;
179 var_size
= WORD_ALIGN (get_frame_size ());
180 args_size
= WORD_ALIGN (current_function_outgoing_args_size
);
181 pretend_size
= current_function_pretend_args_size
;
186 /* Calculate space needed for registers. */
187 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
189 if (MUST_SAVE_REGISTER (regno
))
191 reg_size
+= UNITS_PER_WORD
;
196 current_frame_info
.save_fp
= MUST_SAVE_FRAME_POINTER
;
197 current_frame_info
.save_rp
= MUST_SAVE_RETURN_POINTER
;
199 reg_size
+= (current_frame_info
.save_fp
+ current_frame_info
.save_rp
)
202 /* Save computed information. */
203 current_frame_info
.pretend_size
= pretend_size
;
204 current_frame_info
.var_size
= var_size
;
205 current_frame_info
.args_size
= args_size
;
206 current_frame_info
.reg_size
= reg_size
;
207 current_frame_info
.frame_size
= args_size
+ var_size
;
208 current_frame_info
.total_size
= args_size
+ var_size
+ reg_size
+ pretend_size
;
209 current_frame_info
.gmask
= gmask
;
210 current_frame_info
.initialised
= reload_completed
;
212 /* Calculate the required distance. */
215 if (to_reg
== STACK_POINTER_REGNUM
)
216 return_value
+= args_size
+ var_size
;
218 if (from_reg
== ARG_POINTER_REGNUM
)
219 return_value
+= reg_size
;
224 /* Called after register allocation to add any instructions needed for the
225 prologue. Using a prologue insn is favored compared to putting all of the
226 instructions in output_function_prologue(), since it allows the scheduler
227 to intermix instructions with the saves of the caller saved registers. In
228 some cases, it might be necessary to emit a barrier instruction as the last
229 insn to prevent such scheduling. */
232 fr30_expand_prologue (void)
237 if (! current_frame_info
.initialised
)
238 fr30_compute_frame_size (0, 0);
240 /* This cases shouldn't happen. Catch it now. */
241 if (current_frame_info
.total_size
== 0
242 && current_frame_info
.gmask
)
245 /* Allocate space for register arguments if this is a variadic function. */
246 if (current_frame_info
.pretend_size
)
248 int regs_to_save
= current_frame_info
.pretend_size
/ UNITS_PER_WORD
;
250 /* Push argument registers into the pretend arg area. */
251 for (regno
= FIRST_ARG_REGNUM
+ FR30_NUM_ARG_REGS
; regno
--, regs_to_save
--;)
253 insn
= emit_insn (gen_movsi_push (gen_rtx_REG (Pmode
, regno
)));
254 RTX_FRAME_RELATED_P (insn
) = 1;
258 if (current_frame_info
.gmask
)
260 /* Save any needed call-saved regs. */
261 for (regno
= STACK_POINTER_REGNUM
; regno
--;)
263 if ((current_frame_info
.gmask
& (1 << regno
)) != 0)
265 insn
= emit_insn (gen_movsi_push (gen_rtx_REG (Pmode
, regno
)));
266 RTX_FRAME_RELATED_P (insn
) = 1;
271 /* Save return address if necessary. */
272 if (current_frame_info
.save_rp
)
274 insn
= emit_insn (gen_movsi_push (gen_rtx_REG (Pmode
,
275 RETURN_POINTER_REGNUM
)));
276 RTX_FRAME_RELATED_P (insn
) = 1;
279 /* Save old frame pointer and create new one, if necessary. */
280 if (current_frame_info
.save_fp
)
282 if (current_frame_info
.frame_size
< ((1 << 10) - UNITS_PER_WORD
))
284 int enter_size
= current_frame_info
.frame_size
+ UNITS_PER_WORD
;
287 insn
= emit_insn (gen_enter_func (GEN_INT (enter_size
)));
288 RTX_FRAME_RELATED_P (insn
) = 1;
290 pattern
= PATTERN (insn
);
292 /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
293 if (GET_CODE (pattern
) == PARALLEL
)
296 for (x
= XVECLEN (pattern
, 0); x
--;)
298 rtx part
= XVECEXP (pattern
, 0, x
);
300 /* One of the insns in the ENTER pattern updates the
301 frame pointer. If we do not actually need the frame
302 pointer in this function then this is a side effect
303 rather than a desired effect, so we do not mark that
304 insn as being related to the frame set up. Doing this
305 allows us to compile the crash66.C test file in the
307 if (! frame_pointer_needed
308 && GET_CODE (part
) == SET
309 && REGNO (SET_DEST (part
)) == HARD_FRAME_POINTER_REGNUM
)
310 RTX_FRAME_RELATED_P (part
) = 0;
312 RTX_FRAME_RELATED_P (part
) = 1;
318 insn
= emit_insn (gen_movsi_push (frame_pointer_rtx
));
319 RTX_FRAME_RELATED_P (insn
) = 1;
321 if (frame_pointer_needed
)
323 insn
= emit_insn (gen_movsi (frame_pointer_rtx
, stack_pointer_rtx
));
324 RTX_FRAME_RELATED_P (insn
) = 1;
329 /* Allocate the stack frame. */
330 if (current_frame_info
.frame_size
== 0)
331 ; /* Nothing to do. */
332 else if (current_frame_info
.save_fp
333 && current_frame_info
.frame_size
< ((1 << 10) - UNITS_PER_WORD
))
334 ; /* Nothing to do. */
335 else if (current_frame_info
.frame_size
<= 512)
337 insn
= emit_insn (gen_add_to_stack (GEN_INT (- current_frame_info
.frame_size
)));
338 RTX_FRAME_RELATED_P (insn
) = 1;
342 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
343 insn
= emit_insn (gen_movsi (tmp
, GEN_INT (current_frame_info
.frame_size
)));
344 RTX_FRAME_RELATED_P (insn
) = 1;
345 insn
= emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
, tmp
));
346 RTX_FRAME_RELATED_P (insn
) = 1;
349 if (current_function_profile
)
350 emit_insn (gen_blockage ());
353 /* Called after register allocation to add any instructions needed for the
354 epilogue. Using an epilogue insn is favored compared to putting all of the
355 instructions in output_function_epilogue(), since it allows the scheduler
356 to intermix instructions with the restores of the caller saved registers.
357 In some cases, it might be necessary to emit a barrier instruction as the
358 first insn to prevent such scheduling. */
360 fr30_expand_epilogue (void)
364 /* Perform the inversion operations of the prologue. */
365 if (! current_frame_info
.initialised
)
368 /* Pop local variables and arguments off the stack.
369 If frame_pointer_needed is TRUE then the frame pointer register
370 has actually been used as a frame pointer, and we can recover
371 the stack pointer from it, otherwise we must unwind the stack
373 if (current_frame_info
.frame_size
> 0)
375 if (current_frame_info
.save_fp
&& frame_pointer_needed
)
377 emit_insn (gen_leave_func ());
378 current_frame_info
.save_fp
= 0;
380 else if (current_frame_info
.frame_size
<= 508)
381 emit_insn (gen_add_to_stack
382 (GEN_INT (current_frame_info
.frame_size
)));
385 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
386 emit_insn (gen_movsi (tmp
, GEN_INT (current_frame_info
.frame_size
)));
387 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, tmp
));
391 if (current_frame_info
.save_fp
)
392 emit_insn (gen_movsi_pop (frame_pointer_rtx
));
394 /* Pop all the registers that were pushed. */
395 if (current_frame_info
.save_rp
)
396 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode
, RETURN_POINTER_REGNUM
)));
398 for (regno
= 0; regno
< STACK_POINTER_REGNUM
; regno
++)
399 if (current_frame_info
.gmask
& (1 << regno
))
400 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode
, regno
)));
402 if (current_frame_info
.pretend_size
)
403 emit_insn (gen_add_to_stack (GEN_INT (current_frame_info
.pretend_size
)));
405 /* Reset state info for each function. */
406 current_frame_info
= zero_frame_info
;
408 emit_jump_insn (gen_return_from_func ());
411 /* Do any needed setup for a variadic function. We must create a register
412 parameter block, and then copy any anonymous arguments, plus the last
413 named argument, from registers into memory. * copying actually done in
414 fr30_expand_prologue().
416 ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
417 which has type TYPE and mode MODE, and we rely on this fact. */
419 fr30_setup_incoming_varargs (CUMULATIVE_ARGS arg_regs_used_so_far
,
421 tree type ATTRIBUTE_UNUSED
,
424 enum machine_mode mode
= (enum machine_mode
)int_mode
;
428 /* All BLKmode values are passed by reference. */
432 /* ??? This run-time test as well as the code inside the if
433 statement is probably unnecessary. */
434 if (targetm
.calls
.strict_argument_naming (&arg_regs_used_so_far
))
435 /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
436 arg must not be treated as an anonymous arg. */
437 arg_regs_used_so_far
+= fr30_num_arg_regs (int_mode
, type
);
439 size
= FR30_NUM_ARG_REGS
- arg_regs_used_so_far
;
444 * pretend_size
= (size
* UNITS_PER_WORD
);
448 /*{{{ Printing operands */
450 /* Print a memory address as an operand to reference that memory location. */
453 fr30_print_operand_address (FILE *stream
, rtx address
)
455 switch (GET_CODE (address
))
458 output_addr_const (stream
, address
);
462 fprintf (stderr
, "code = %x\n", GET_CODE (address
));
464 output_operand_lossage ("fr30_print_operand_address: unhandled address");
469 /* Print an operand. */
472 fr30_print_operand (FILE *file
, rtx x
, int code
)
479 /* Output a :D if this instruction is delayed. */
480 if (dbr_sequence_length () != 0)
485 /* Compute the register name of the second register in a hi/lo
487 if (GET_CODE (x
) != REG
)
488 output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
490 fprintf (file
, "r%d", REGNO (x
) + 1);
494 /* Convert GCC's comparison operators into FR30 comparison codes. */
495 switch (GET_CODE (x
))
497 case EQ
: fprintf (file
, "eq"); break;
498 case NE
: fprintf (file
, "ne"); break;
499 case LT
: fprintf (file
, "lt"); break;
500 case LE
: fprintf (file
, "le"); break;
501 case GT
: fprintf (file
, "gt"); break;
502 case GE
: fprintf (file
, "ge"); break;
503 case LTU
: fprintf (file
, "c"); break;
504 case LEU
: fprintf (file
, "ls"); break;
505 case GTU
: fprintf (file
, "hi"); break;
506 case GEU
: fprintf (file
, "nc"); break;
508 output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
514 /* Convert GCC's comparison operators into the complimentary FR30
516 switch (GET_CODE (x
))
518 case EQ
: fprintf (file
, "ne"); break;
519 case NE
: fprintf (file
, "eq"); break;
520 case LT
: fprintf (file
, "ge"); break;
521 case LE
: fprintf (file
, "gt"); break;
522 case GT
: fprintf (file
, "le"); break;
523 case GE
: fprintf (file
, "lt"); break;
524 case LTU
: fprintf (file
, "nc"); break;
525 case LEU
: fprintf (file
, "hi"); break;
526 case GTU
: fprintf (file
, "ls"); break;
527 case GEU
: fprintf (file
, "c"); break;
529 output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
535 /* Print a signed byte value as an unsigned value. */
536 if (GET_CODE (x
) != CONST_INT
)
537 output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
546 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, val
);
551 if (GET_CODE (x
) != CONST_INT
554 output_operand_lossage ("fr30_print_operand: invalid %%x code");
556 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) - 16);
560 if (GET_CODE (x
) != CONST_DOUBLE
)
561 output_operand_lossage ("fr30_print_operand: invalid %%F code");
566 real_to_decimal (str
, CONST_DOUBLE_REAL_VALUE (x
),
577 fprintf (stderr
, "unknown code = %x\n", code
);
578 output_operand_lossage ("fr30_print_operand: unknown code");
582 switch (GET_CODE (x
))
585 fputs (reg_names
[REGNO (x
)], file
);
591 switch (GET_CODE (x0
))
594 if ((unsigned) REGNO (x0
) >= ARRAY_SIZE (reg_names
))
596 fprintf (file
, "@%s", reg_names
[REGNO (x0
)]);
600 if (GET_CODE (XEXP (x0
, 0)) != REG
601 || REGNO (XEXP (x0
, 0)) < FRAME_POINTER_REGNUM
602 || REGNO (XEXP (x0
, 0)) > STACK_POINTER_REGNUM
603 || GET_CODE (XEXP (x0
, 1)) != CONST_INT
)
605 fprintf (stderr
, "bad INDEXed address:");
607 output_operand_lossage ("fr30_print_operand: unhandled MEM");
609 else if (REGNO (XEXP (x0
, 0)) == FRAME_POINTER_REGNUM
)
611 HOST_WIDE_INT val
= INTVAL (XEXP (x0
, 1));
612 if (val
< -(1 << 9) || val
> ((1 << 9) - 4))
614 fprintf (stderr
, "frame INDEX out of range:");
616 output_operand_lossage ("fr30_print_operand: unhandled MEM");
618 fprintf (file
, "@(r14, #" HOST_WIDE_INT_PRINT_DEC
")", val
);
622 HOST_WIDE_INT val
= INTVAL (XEXP (x0
, 1));
623 if (val
< 0 || val
> ((1 << 6) - 4))
625 fprintf (stderr
, "stack INDEX out of range:");
627 output_operand_lossage ("fr30_print_operand: unhandled MEM");
629 fprintf (file
, "@(r15, #" HOST_WIDE_INT_PRINT_DEC
")", val
);
638 fprintf (stderr
, "bad MEM code = %x\n", GET_CODE (x0
));
640 output_operand_lossage ("fr30_print_operand: unhandled MEM");
646 /* We handle SFmode constants here as output_addr_const doesn't. */
647 if (GET_MODE (x
) == SFmode
)
652 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
653 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
654 fprintf (file
, "0x%08lx", l
);
658 /* Fall through. Let output_addr_const deal with it. */
660 output_addr_const (file
, x
);
668 /*{{{ Function arguments */
670 /* Compute the number of word sized registers needed to hold a
671 function argument of mode INT_MODE and tree type TYPE. */
673 fr30_num_arg_regs (enum machine_mode mode
, tree type
)
677 if (MUST_PASS_IN_STACK (mode
, type
))
680 if (type
&& mode
== BLKmode
)
681 size
= int_size_in_bytes (type
);
683 size
= GET_MODE_SIZE (mode
);
685 return (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
688 /* Implements the FUNCTION_ARG_PARTIAL_NREGS macro.
689 Returns the number of argument registers required to hold *part* of
690 a parameter of machine mode MODE and tree type TYPE (which may be
691 NULL if the type is not known). If the argument fits entirely in
692 the argument registers, or entirely on the stack, then 0 is returned.
693 CUM is the number of argument registers already used by earlier
694 parameters to the function. */
697 fr30_function_arg_partial_nregs (CUMULATIVE_ARGS cum
, enum machine_mode mode
,
698 tree type
, int named
)
700 /* Unnamed arguments, ie those that are prototyped as ...
701 are always passed on the stack.
702 Also check here to see if all the argument registers are full. */
703 if (named
== 0 || cum
>= FR30_NUM_ARG_REGS
)
706 /* Work out how many argument registers would be needed if this
707 parameter were to be passed entirely in registers. If there
708 are sufficient argument registers available (or if no registers
709 are needed because the parameter must be passed on the stack)
710 then return zero, as this parameter does not require partial
711 register, partial stack stack space. */
712 if (cum
+ fr30_num_arg_regs (mode
, type
) <= FR30_NUM_ARG_REGS
)
715 /* Otherwise return the number of registers that would be used. */
716 return FR30_NUM_ARG_REGS
- cum
;
720 fr30_pass_by_reference (tree valist
, tree type
)
726 type_ptr
= build_pointer_type (type
);
727 type_ptr_ptr
= build_pointer_type (type_ptr
);
729 t
= build (POSTINCREMENT_EXPR
, va_list_type_node
, valist
, build_int_2 (UNITS_PER_WORD
, 0));
730 TREE_SIDE_EFFECTS (t
) = 1;
731 t
= build1 (NOP_EXPR
, type_ptr_ptr
, t
);
732 TREE_SIDE_EFFECTS (t
) = 1;
733 t
= build1 (INDIRECT_REF
, type_ptr
, t
);
735 return expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
739 fr30_pass_by_value (tree valist
, tree type
)
741 HOST_WIDE_INT size
= int_size_in_bytes (type
);
746 if ((size
% UNITS_PER_WORD
) == 0)
748 t
= build (POSTINCREMENT_EXPR
, va_list_type_node
, valist
, build_int_2 (size
, 0));
749 TREE_SIDE_EFFECTS (t
) = 1;
751 return expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
754 rsize
= (size
+ UNITS_PER_WORD
- 1) & - UNITS_PER_WORD
;
756 /* Care for bigendian correction on the aligned address. */
757 t
= build (PLUS_EXPR
, ptr_type_node
, valist
, build_int_2 (rsize
- size
, 0));
758 addr_rtx
= expand_expr (t
, NULL_RTX
, Pmode
, EXPAND_NORMAL
);
759 addr_rtx
= copy_to_reg (addr_rtx
);
762 t
= build (PLUS_EXPR
, va_list_type_node
, valist
, build_int_2 (rsize
, 0));
763 t
= build (MODIFY_EXPR
, va_list_type_node
, valist
, t
);
764 TREE_SIDE_EFFECTS (t
) = 1;
765 expand_expr (t
, const0_rtx
, VOIDmode
, EXPAND_NORMAL
);
770 /* Implement `va_arg'. */
773 fr30_va_arg (tree valist
, tree type
)
777 if (AGGREGATE_TYPE_P (type
))
778 return fr30_pass_by_reference (valist
, type
);
780 size
= int_size_in_bytes (type
);
782 if ((size
% sizeof (int)) == 0
784 return fr30_pass_by_value (valist
, type
);
786 return fr30_pass_by_reference (valist
, type
);
790 /*{{{ Operand predicates */
793 #define Mmode enum machine_mode
796 /* Returns true if OPERAND is an integer value suitable for use in
797 an ADDSP instruction. */
799 stack_add_operand (rtx operand
, Mmode mode ATTRIBUTE_UNUSED
)
802 (GET_CODE (operand
) == CONST_INT
803 && INTVAL (operand
) >= -512
804 && INTVAL (operand
) <= 508
805 && ((INTVAL (operand
) & 3) == 0));
808 /* Returns true if OPERAND is an integer value suitable for use in
809 an ADD por ADD2 instruction, or if it is a register. */
811 add_immediate_operand (rtx operand
, Mmode mode ATTRIBUTE_UNUSED
)
814 (GET_CODE (operand
) == REG
815 || (GET_CODE (operand
) == CONST_INT
816 && INTVAL (operand
) >= -16
817 && INTVAL (operand
) <= 15));
820 /* Returns true if OPERAND is hard register in the range 8 - 15. */
822 high_register_operand (rtx operand
, Mmode mode ATTRIBUTE_UNUSED
)
825 (GET_CODE (operand
) == REG
826 && REGNO (operand
) <= 15
827 && REGNO (operand
) >= 8);
830 /* Returns true if OPERAND is hard register in the range 0 - 7. */
832 low_register_operand (rtx operand
, Mmode mode ATTRIBUTE_UNUSED
)
835 (GET_CODE (operand
) == REG
836 && REGNO (operand
) <= 7);
839 /* Returns true if OPERAND is suitable for use in a CALL insn. */
841 call_operand (rtx operand
, Mmode mode ATTRIBUTE_UNUSED
)
843 return (GET_CODE (operand
) == MEM
844 && (GET_CODE (XEXP (operand
, 0)) == SYMBOL_REF
845 || GET_CODE (XEXP (operand
, 0)) == REG
));
848 /* Returns TRUE if OP is a valid operand of a DImode operation. */
850 di_operand (rtx op
, Mmode mode
)
852 if (register_operand (op
, mode
))
855 if (mode
!= VOIDmode
&& GET_MODE (op
) != VOIDmode
&& GET_MODE (op
) != DImode
)
858 if (GET_CODE (op
) == SUBREG
)
859 op
= SUBREG_REG (op
);
861 switch (GET_CODE (op
))
868 return memory_address_p (DImode
, XEXP (op
, 0));
875 /* Returns TRUE if OP is a DImode register or MEM. */
877 nonimmediate_di_operand (rtx op
, Mmode mode
)
879 if (register_operand (op
, mode
))
882 if (mode
!= VOIDmode
&& GET_MODE (op
) != VOIDmode
&& GET_MODE (op
) != DImode
)
885 if (GET_CODE (op
) == SUBREG
)
886 op
= SUBREG_REG (op
);
888 if (GET_CODE (op
) == MEM
)
889 return memory_address_p (DImode
, XEXP (op
, 0));
894 /* Returns true iff all the registers in the operands array
895 are in descending or ascending order. */
897 fr30_check_multiple_regs (rtx
*operands
, int num_operands
, int descending
)
901 unsigned int prev_regno
= 0;
903 while (num_operands
--)
905 if (GET_CODE (operands
[num_operands
]) != REG
)
908 if (REGNO (operands
[num_operands
]) < prev_regno
)
911 prev_regno
= REGNO (operands
[num_operands
]);
916 unsigned int prev_regno
= CONDITION_CODE_REGNUM
;
918 while (num_operands
--)
920 if (GET_CODE (operands
[num_operands
]) != REG
)
923 if (REGNO (operands
[num_operands
]) > prev_regno
)
926 prev_regno
= REGNO (operands
[num_operands
]);
934 fr30_const_double_is_zero (rtx operand
)
938 if (operand
== NULL
|| GET_CODE (operand
) != CONST_DOUBLE
)
941 REAL_VALUE_FROM_CONST_DOUBLE (d
, operand
);
943 return REAL_VALUES_EQUAL (d
, dconst0
);
947 /*{{{ Instruction Output Routines */
949 /* Output a double word move.
950 It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
951 On the FR30 we are constrained by the fact that it does not
952 support offsetable addresses, and so we have to load the
953 address of the secnd word into the second destination register
954 before we can use it. */
957 fr30_move_double (rtx
* operands
)
959 rtx src
= operands
[1];
960 rtx dest
= operands
[0];
961 enum rtx_code src_code
= GET_CODE (src
);
962 enum rtx_code dest_code
= GET_CODE (dest
);
963 enum machine_mode mode
= GET_MODE (dest
);
968 if (dest_code
== REG
)
972 int reverse
= (REGNO (dest
) == REGNO (src
) + 1);
974 /* We normally copy the low-numbered register first. However, if
975 the first register of operand 0 is the same as the second register
976 of operand 1, we must copy in the opposite order. */
977 emit_insn (gen_rtx_SET (VOIDmode
,
978 operand_subword (dest
, reverse
, TRUE
, mode
),
979 operand_subword (src
, reverse
, TRUE
, mode
)));
981 emit_insn (gen_rtx_SET (VOIDmode
,
982 operand_subword (dest
, !reverse
, TRUE
, mode
),
983 operand_subword (src
, !reverse
, TRUE
, mode
)));
985 else if (src_code
== MEM
)
987 rtx addr
= XEXP (src
, 0);
988 int dregno
= REGNO (dest
);
993 /* If the high-address word is used in the address, we
994 must load it last. Otherwise, load it first. */
995 int reverse
= (refers_to_regno_p (dregno
, dregno
+ 1, addr
, 0) != 0);
997 if (GET_CODE (addr
) != REG
)
1000 dest0
= operand_subword (dest
, reverse
, TRUE
, mode
);
1001 dest1
= operand_subword (dest
, !reverse
, TRUE
, mode
);
1005 emit_insn (gen_rtx_SET (VOIDmode
, dest1
,
1006 adjust_address (src
, SImode
, 0)));
1007 emit_insn (gen_rtx_SET (SImode
, dest0
,
1008 gen_rtx_REG (SImode
, REGNO (addr
))));
1009 emit_insn (gen_rtx_SET (SImode
, dest0
,
1010 plus_constant (dest0
, UNITS_PER_WORD
)));
1012 new_mem
= gen_rtx_MEM (SImode
, dest0
);
1013 MEM_COPY_ATTRIBUTES (new_mem
, src
);
1015 emit_insn (gen_rtx_SET (VOIDmode
, dest0
, new_mem
));
1019 emit_insn (gen_rtx_SET (VOIDmode
, dest0
,
1020 adjust_address (src
, SImode
, 0)));
1021 emit_insn (gen_rtx_SET (SImode
, dest1
,
1022 gen_rtx_REG (SImode
, REGNO (addr
))));
1023 emit_insn (gen_rtx_SET (SImode
, dest1
,
1024 plus_constant (dest1
, UNITS_PER_WORD
)));
1026 new_mem
= gen_rtx_MEM (SImode
, dest1
);
1027 MEM_COPY_ATTRIBUTES (new_mem
, src
);
1029 emit_insn (gen_rtx_SET (VOIDmode
, dest1
, new_mem
));
1032 else if (src_code
== CONST_INT
|| src_code
== CONST_DOUBLE
)
1035 split_double (src
, &words
[0], &words
[1]);
1036 emit_insn (gen_rtx_SET (VOIDmode
,
1037 operand_subword (dest
, 0, TRUE
, mode
),
1040 emit_insn (gen_rtx_SET (VOIDmode
,
1041 operand_subword (dest
, 1, TRUE
, mode
),
1045 else if (src_code
== REG
&& dest_code
== MEM
)
1047 rtx addr
= XEXP (dest
, 0);
1051 if (GET_CODE (addr
) != REG
)
1054 src0
= operand_subword (src
, 0, TRUE
, mode
);
1055 src1
= operand_subword (src
, 1, TRUE
, mode
);
1057 emit_insn (gen_rtx_SET (VOIDmode
, adjust_address (dest
, SImode
, 0),
1060 if (REGNO (addr
) == STACK_POINTER_REGNUM
1061 || REGNO (addr
) == FRAME_POINTER_REGNUM
)
1062 emit_insn (gen_rtx_SET (VOIDmode
,
1063 adjust_address (dest
, SImode
, UNITS_PER_WORD
),
1069 /* We need a scratch register to hold the value of 'address + 4'.
1070 We ought to allow gcc to find one for us, but for now, just
1071 push one of the source registers. */
1072 emit_insn (gen_movsi_push (src0
));
1073 emit_insn (gen_movsi_internal (src0
, addr
));
1074 emit_insn (gen_addsi_small_int (src0
, src0
, GEN_INT (UNITS_PER_WORD
)));
1076 new_mem
= gen_rtx_MEM (SImode
, src0
);
1077 MEM_COPY_ATTRIBUTES (new_mem
, dest
);
1079 emit_insn (gen_rtx_SET (VOIDmode
, new_mem
, src1
));
1080 emit_insn (gen_movsi_pop (src0
));
1084 /* This should have been prevented by the constraints on movdi_insn. */
1093 /* Local Variables: */
1094 /* folded-file: t */