1 /* FR30 specific functions.
2 Copyright (C) 1998-2014 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
36 #include "stor-layout.h"
48 #include "dominance.h"
54 #include "cfgcleanup.h"
56 #include "basic-block.h"
58 #include "diagnostic-core.h"
61 #include "target-def.h"
65 /*{{{ Function Prologues & Epilogues */
67 /* The FR30 stack looks like this:
69 Before call After call
71 +-----------------------+ +-----------------------+ high
73 | local variables, | | local variables, |
74 | reg save area, etc. | | reg save area, etc. |
76 +-----------------------+ +-----------------------+
78 | args to the func that | | args to this func. |
79 | is being called that | | |
80 SP ->| do not fit in regs | | |
81 +-----------------------+ +-----------------------+
82 | args that used to be | \
83 | in regs; only created | | pretend_size
84 AP-> | for vararg funcs | /
85 +-----------------------+
87 | register save area | |
89 +-----------------------+ | reg_size
91 +-----------------------+ |
92 FP ->| previous frame ptr | /
93 +-----------------------+
95 | local variables | | var_size
97 +-----------------------+
99 low | room for args to | |
100 memory | other funcs called | | args_size
103 +-----------------------+
105 Note, AP is a fake hard register. It will be eliminated in favor of
106 SP or FP as appropriate.
108 Note, Some or all of the stack sections above may be omitted if they
111 /* Structure to be filled in by fr30_compute_frame_size() with register
112 save masks, and offsets for the current function. */
113 struct fr30_frame_info
115 unsigned int total_size
; /* # Bytes that the entire frame takes up. */
116 unsigned int pretend_size
; /* # Bytes we push and pretend caller did. */
117 unsigned int args_size
; /* # Bytes that outgoing arguments take up. */
118 unsigned int reg_size
; /* # Bytes needed to store regs. */
119 unsigned int var_size
; /* # Bytes that variables take up. */
120 unsigned int frame_size
; /* # Bytes in current frame. */
121 unsigned int gmask
; /* Mask of saved registers. */
122 unsigned int save_fp
; /* Nonzero if frame pointer must be saved. */
123 unsigned int save_rp
; /* Nonzero if return pointer must be saved. */
124 int initialised
; /* Nonzero if frame size already calculated. */
127 /* Current frame information calculated by fr30_compute_frame_size(). */
128 static struct fr30_frame_info current_frame_info
;
130 /* Zero structure to initialize current_frame_info. */
131 static struct fr30_frame_info zero_frame_info
;
133 static void fr30_setup_incoming_varargs (cumulative_args_t
, machine_mode
,
135 static bool fr30_must_pass_in_stack (machine_mode
, const_tree
);
136 static int fr30_arg_partial_bytes (cumulative_args_t
, machine_mode
,
138 static rtx
fr30_function_arg (cumulative_args_t
, machine_mode
,
140 static void fr30_function_arg_advance (cumulative_args_t
, machine_mode
,
142 static bool fr30_frame_pointer_required (void);
143 static rtx
fr30_function_value (const_tree
, const_tree
, bool);
144 static rtx
fr30_libcall_value (machine_mode
, const_rtx
);
145 static bool fr30_function_value_regno_p (const unsigned int);
146 static bool fr30_can_eliminate (const int, const int);
147 static void fr30_asm_trampoline_template (FILE *);
148 static void fr30_trampoline_init (rtx
, tree
, rtx
);
149 static int fr30_num_arg_regs (machine_mode
, const_tree
);
151 #define FRAME_POINTER_MASK (1 << (FRAME_POINTER_REGNUM))
152 #define RETURN_POINTER_MASK (1 << (RETURN_POINTER_REGNUM))
154 /* Tell prologue and epilogue if register REGNO should be saved / restored.
155 The return address and frame pointer are treated separately.
156 Don't consider them here. */
157 #define MUST_SAVE_REGISTER(regno) \
158 ( (regno) != RETURN_POINTER_REGNUM \
159 && (regno) != FRAME_POINTER_REGNUM \
160 && df_regs_ever_live_p (regno) \
161 && ! call_used_regs [regno] )
163 #define MUST_SAVE_FRAME_POINTER (df_regs_ever_live_p (FRAME_POINTER_REGNUM) || frame_pointer_needed)
164 #define MUST_SAVE_RETURN_POINTER (df_regs_ever_live_p (RETURN_POINTER_REGNUM) || crtl->profile)
166 #if UNITS_PER_WORD == 4
167 #define WORD_ALIGN(SIZE) (((SIZE) + 3) & ~3)
170 /* Initialize the GCC target structure. */
171 #undef TARGET_ASM_ALIGNED_HI_OP
172 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
173 #undef TARGET_ASM_ALIGNED_SI_OP
174 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
176 #undef TARGET_PROMOTE_PROTOTYPES
177 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
178 #undef TARGET_PASS_BY_REFERENCE
179 #define TARGET_PASS_BY_REFERENCE hook_pass_by_reference_must_pass_in_stack
180 #undef TARGET_ARG_PARTIAL_BYTES
181 #define TARGET_ARG_PARTIAL_BYTES fr30_arg_partial_bytes
182 #undef TARGET_FUNCTION_ARG
183 #define TARGET_FUNCTION_ARG fr30_function_arg
184 #undef TARGET_FUNCTION_ARG_ADVANCE
185 #define TARGET_FUNCTION_ARG_ADVANCE fr30_function_arg_advance
187 #undef TARGET_FUNCTION_VALUE
188 #define TARGET_FUNCTION_VALUE fr30_function_value
189 #undef TARGET_LIBCALL_VALUE
190 #define TARGET_LIBCALL_VALUE fr30_libcall_value
191 #undef TARGET_FUNCTION_VALUE_REGNO_P
192 #define TARGET_FUNCTION_VALUE_REGNO_P fr30_function_value_regno_p
194 #undef TARGET_SETUP_INCOMING_VARARGS
195 #define TARGET_SETUP_INCOMING_VARARGS fr30_setup_incoming_varargs
196 #undef TARGET_MUST_PASS_IN_STACK
197 #define TARGET_MUST_PASS_IN_STACK fr30_must_pass_in_stack
199 #undef TARGET_FRAME_POINTER_REQUIRED
200 #define TARGET_FRAME_POINTER_REQUIRED fr30_frame_pointer_required
202 #undef TARGET_CAN_ELIMINATE
203 #define TARGET_CAN_ELIMINATE fr30_can_eliminate
205 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
206 #define TARGET_ASM_TRAMPOLINE_TEMPLATE fr30_asm_trampoline_template
207 #undef TARGET_TRAMPOLINE_INIT
208 #define TARGET_TRAMPOLINE_INIT fr30_trampoline_init
210 struct gcc_target targetm
= TARGET_INITIALIZER
;
213 /* Worker function for TARGET_CAN_ELIMINATE. */
216 fr30_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
218 return (to
== FRAME_POINTER_REGNUM
|| ! frame_pointer_needed
);
221 /* Returns the number of bytes offset between FROM_REG and TO_REG
222 for the current function. As a side effect it fills in the
223 current_frame_info structure, if the data is available. */
225 fr30_compute_frame_size (int from_reg
, int to_reg
)
228 unsigned int return_value
;
229 unsigned int var_size
;
230 unsigned int args_size
;
231 unsigned int pretend_size
;
232 unsigned int reg_size
;
235 var_size
= WORD_ALIGN (get_frame_size ());
236 args_size
= WORD_ALIGN (crtl
->outgoing_args_size
);
237 pretend_size
= crtl
->args
.pretend_args_size
;
242 /* Calculate space needed for registers. */
243 for (regno
= 0; regno
< FIRST_PSEUDO_REGISTER
; regno
++)
245 if (MUST_SAVE_REGISTER (regno
))
247 reg_size
+= UNITS_PER_WORD
;
252 current_frame_info
.save_fp
= MUST_SAVE_FRAME_POINTER
;
253 current_frame_info
.save_rp
= MUST_SAVE_RETURN_POINTER
;
255 reg_size
+= (current_frame_info
.save_fp
+ current_frame_info
.save_rp
)
258 /* Save computed information. */
259 current_frame_info
.pretend_size
= pretend_size
;
260 current_frame_info
.var_size
= var_size
;
261 current_frame_info
.args_size
= args_size
;
262 current_frame_info
.reg_size
= reg_size
;
263 current_frame_info
.frame_size
= args_size
+ var_size
;
264 current_frame_info
.total_size
= args_size
+ var_size
+ reg_size
+ pretend_size
;
265 current_frame_info
.gmask
= gmask
;
266 current_frame_info
.initialised
= reload_completed
;
268 /* Calculate the required distance. */
271 if (to_reg
== STACK_POINTER_REGNUM
)
272 return_value
+= args_size
+ var_size
;
274 if (from_reg
== ARG_POINTER_REGNUM
)
275 return_value
+= reg_size
;
280 /* Called after register allocation to add any instructions needed for the
281 prologue. Using a prologue insn is favored compared to putting all of the
282 instructions in output_function_prologue(), since it allows the scheduler
283 to intermix instructions with the saves of the caller saved registers. In
284 some cases, it might be necessary to emit a barrier instruction as the last
285 insn to prevent such scheduling. */
288 fr30_expand_prologue (void)
293 if (! current_frame_info
.initialised
)
294 fr30_compute_frame_size (0, 0);
296 /* This cases shouldn't happen. Catch it now. */
297 gcc_assert (current_frame_info
.total_size
|| !current_frame_info
.gmask
);
299 /* Allocate space for register arguments if this is a variadic function. */
300 if (current_frame_info
.pretend_size
)
302 int regs_to_save
= current_frame_info
.pretend_size
/ UNITS_PER_WORD
;
304 /* Push argument registers into the pretend arg area. */
305 for (regno
= FIRST_ARG_REGNUM
+ FR30_NUM_ARG_REGS
; regno
--, regs_to_save
--;)
307 insn
= emit_insn (gen_movsi_push (gen_rtx_REG (Pmode
, regno
)));
308 RTX_FRAME_RELATED_P (insn
) = 1;
312 if (current_frame_info
.gmask
)
314 /* Save any needed call-saved regs. */
315 for (regno
= STACK_POINTER_REGNUM
; regno
--;)
317 if ((current_frame_info
.gmask
& (1 << regno
)) != 0)
319 insn
= emit_insn (gen_movsi_push (gen_rtx_REG (Pmode
, regno
)));
320 RTX_FRAME_RELATED_P (insn
) = 1;
325 /* Save return address if necessary. */
326 if (current_frame_info
.save_rp
)
328 insn
= emit_insn (gen_movsi_push (gen_rtx_REG (Pmode
,
329 RETURN_POINTER_REGNUM
)));
330 RTX_FRAME_RELATED_P (insn
) = 1;
333 /* Save old frame pointer and create new one, if necessary. */
334 if (current_frame_info
.save_fp
)
336 if (current_frame_info
.frame_size
< ((1 << 10) - UNITS_PER_WORD
))
338 int enter_size
= current_frame_info
.frame_size
+ UNITS_PER_WORD
;
341 insn
= emit_insn (gen_enter_func (GEN_INT (enter_size
)));
342 RTX_FRAME_RELATED_P (insn
) = 1;
344 pattern
= PATTERN (insn
);
346 /* Also mark all 3 subexpressions as RTX_FRAME_RELATED_P. */
347 if (GET_CODE (pattern
) == PARALLEL
)
350 for (x
= XVECLEN (pattern
, 0); x
--;)
352 rtx part
= XVECEXP (pattern
, 0, x
);
354 /* One of the insns in the ENTER pattern updates the
355 frame pointer. If we do not actually need the frame
356 pointer in this function then this is a side effect
357 rather than a desired effect, so we do not mark that
358 insn as being related to the frame set up. Doing this
359 allows us to compile the crash66.C test file in the
361 if (! frame_pointer_needed
362 && GET_CODE (part
) == SET
363 && SET_DEST (part
) == hard_frame_pointer_rtx
)
364 RTX_FRAME_RELATED_P (part
) = 0;
366 RTX_FRAME_RELATED_P (part
) = 1;
372 insn
= emit_insn (gen_movsi_push (frame_pointer_rtx
));
373 RTX_FRAME_RELATED_P (insn
) = 1;
375 if (frame_pointer_needed
)
377 insn
= emit_insn (gen_movsi (frame_pointer_rtx
, stack_pointer_rtx
));
378 RTX_FRAME_RELATED_P (insn
) = 1;
383 /* Allocate the stack frame. */
384 if (current_frame_info
.frame_size
== 0)
385 ; /* Nothing to do. */
386 else if (current_frame_info
.save_fp
387 && current_frame_info
.frame_size
< ((1 << 10) - UNITS_PER_WORD
))
388 ; /* Nothing to do. */
389 else if (current_frame_info
.frame_size
<= 512)
391 insn
= emit_insn (gen_add_to_stack
392 (GEN_INT (- (signed) current_frame_info
.frame_size
)));
393 RTX_FRAME_RELATED_P (insn
) = 1;
397 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
398 insn
= emit_insn (gen_movsi (tmp
, GEN_INT (current_frame_info
.frame_size
)));
399 RTX_FRAME_RELATED_P (insn
) = 1;
400 insn
= emit_insn (gen_subsi3 (stack_pointer_rtx
, stack_pointer_rtx
, tmp
));
401 RTX_FRAME_RELATED_P (insn
) = 1;
405 emit_insn (gen_blockage ());
408 /* Called after register allocation to add any instructions needed for the
409 epilogue. Using an epilogue insn is favored compared to putting all of the
410 instructions in output_function_epilogue(), since it allows the scheduler
411 to intermix instructions with the restores of the caller saved registers.
412 In some cases, it might be necessary to emit a barrier instruction as the
413 first insn to prevent such scheduling. */
415 fr30_expand_epilogue (void)
419 /* Perform the inversion operations of the prologue. */
420 gcc_assert (current_frame_info
.initialised
);
422 /* Pop local variables and arguments off the stack.
423 If frame_pointer_needed is TRUE then the frame pointer register
424 has actually been used as a frame pointer, and we can recover
425 the stack pointer from it, otherwise we must unwind the stack
427 if (current_frame_info
.frame_size
> 0)
429 if (current_frame_info
.save_fp
&& frame_pointer_needed
)
431 emit_insn (gen_leave_func ());
432 current_frame_info
.save_fp
= 0;
434 else if (current_frame_info
.frame_size
<= 508)
435 emit_insn (gen_add_to_stack
436 (GEN_INT (current_frame_info
.frame_size
)));
439 rtx tmp
= gen_rtx_REG (Pmode
, PROLOGUE_TMP_REGNUM
);
440 emit_insn (gen_movsi (tmp
, GEN_INT (current_frame_info
.frame_size
)));
441 emit_insn (gen_addsi3 (stack_pointer_rtx
, stack_pointer_rtx
, tmp
));
445 if (current_frame_info
.save_fp
)
446 emit_insn (gen_movsi_pop (frame_pointer_rtx
));
448 /* Pop all the registers that were pushed. */
449 if (current_frame_info
.save_rp
)
450 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode
, RETURN_POINTER_REGNUM
)));
452 for (regno
= 0; regno
< STACK_POINTER_REGNUM
; regno
++)
453 if (current_frame_info
.gmask
& (1 << regno
))
454 emit_insn (gen_movsi_pop (gen_rtx_REG (Pmode
, regno
)));
456 if (current_frame_info
.pretend_size
)
457 emit_insn (gen_add_to_stack (GEN_INT (current_frame_info
.pretend_size
)));
459 /* Reset state info for each function. */
460 current_frame_info
= zero_frame_info
;
462 emit_jump_insn (gen_return_from_func ());
465 /* Do any needed setup for a variadic function. We must create a register
466 parameter block, and then copy any anonymous arguments, plus the last
467 named argument, from registers into memory. * copying actually done in
468 fr30_expand_prologue().
470 ARG_REGS_USED_SO_FAR has *not* been updated for the last named argument
471 which has type TYPE and mode MODE, and we rely on this fact. */
473 fr30_setup_incoming_varargs (cumulative_args_t arg_regs_used_so_far_v
,
475 tree type ATTRIBUTE_UNUSED
,
477 int second_time ATTRIBUTE_UNUSED
)
479 CUMULATIVE_ARGS
*arg_regs_used_so_far
480 = get_cumulative_args (arg_regs_used_so_far_v
);
483 /* All BLKmode values are passed by reference. */
484 gcc_assert (mode
!= BLKmode
);
486 /* ??? This run-time test as well as the code inside the if
487 statement is probably unnecessary. */
488 if (targetm
.calls
.strict_argument_naming (arg_regs_used_so_far_v
))
489 /* If TARGET_STRICT_ARGUMENT_NAMING returns true, then the last named
490 arg must not be treated as an anonymous arg. */
491 /* ??? This is a pointer increment, which makes no sense. */
492 arg_regs_used_so_far
+= fr30_num_arg_regs (mode
, type
);
494 size
= FR30_NUM_ARG_REGS
- (* arg_regs_used_so_far
);
499 * pretend_size
= (size
* UNITS_PER_WORD
);
503 /*{{{ Printing operands */
505 /* Print a memory address as an operand to reference that memory location. */
508 fr30_print_operand_address (FILE *stream
, rtx address
)
510 switch (GET_CODE (address
))
513 output_addr_const (stream
, address
);
517 fprintf (stderr
, "code = %x\n", GET_CODE (address
));
519 output_operand_lossage ("fr30_print_operand_address: unhandled address");
524 /* Print an operand. */
527 fr30_print_operand (FILE *file
, rtx x
, int code
)
534 /* Output a :D if this instruction is delayed. */
535 if (dbr_sequence_length () != 0)
540 /* Compute the register name of the second register in a hi/lo
542 if (GET_CODE (x
) != REG
)
543 output_operand_lossage ("fr30_print_operand: unrecognized %%p code");
545 fprintf (file
, "r%d", REGNO (x
) + 1);
549 /* Convert GCC's comparison operators into FR30 comparison codes. */
550 switch (GET_CODE (x
))
552 case EQ
: fprintf (file
, "eq"); break;
553 case NE
: fprintf (file
, "ne"); break;
554 case LT
: fprintf (file
, "lt"); break;
555 case LE
: fprintf (file
, "le"); break;
556 case GT
: fprintf (file
, "gt"); break;
557 case GE
: fprintf (file
, "ge"); break;
558 case LTU
: fprintf (file
, "c"); break;
559 case LEU
: fprintf (file
, "ls"); break;
560 case GTU
: fprintf (file
, "hi"); break;
561 case GEU
: fprintf (file
, "nc"); break;
563 output_operand_lossage ("fr30_print_operand: unrecognized %%b code");
569 /* Convert GCC's comparison operators into the complimentary FR30
571 switch (GET_CODE (x
))
573 case EQ
: fprintf (file
, "ne"); break;
574 case NE
: fprintf (file
, "eq"); break;
575 case LT
: fprintf (file
, "ge"); break;
576 case LE
: fprintf (file
, "gt"); break;
577 case GT
: fprintf (file
, "le"); break;
578 case GE
: fprintf (file
, "lt"); break;
579 case LTU
: fprintf (file
, "nc"); break;
580 case LEU
: fprintf (file
, "hi"); break;
581 case GTU
: fprintf (file
, "ls"); break;
582 case GEU
: fprintf (file
, "c"); break;
584 output_operand_lossage ("fr30_print_operand: unrecognized %%B code");
590 /* Print a signed byte value as an unsigned value. */
591 if (GET_CODE (x
) != CONST_INT
)
592 output_operand_lossage ("fr30_print_operand: invalid operand to %%A code");
601 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, val
);
606 if (GET_CODE (x
) != CONST_INT
609 output_operand_lossage ("fr30_print_operand: invalid %%x code");
611 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (x
) - 16);
615 if (GET_CODE (x
) != CONST_DOUBLE
)
616 output_operand_lossage ("fr30_print_operand: invalid %%F code");
621 real_to_decimal (str
, CONST_DOUBLE_REAL_VALUE (x
),
632 fprintf (stderr
, "unknown code = %x\n", code
);
633 output_operand_lossage ("fr30_print_operand: unknown code");
637 switch (GET_CODE (x
))
640 fputs (reg_names
[REGNO (x
)], file
);
646 switch (GET_CODE (x0
))
649 gcc_assert ((unsigned) REGNO (x0
) < ARRAY_SIZE (reg_names
));
650 fprintf (file
, "@%s", reg_names
[REGNO (x0
)]);
654 if (GET_CODE (XEXP (x0
, 0)) != REG
655 || REGNO (XEXP (x0
, 0)) < FRAME_POINTER_REGNUM
656 || REGNO (XEXP (x0
, 0)) > STACK_POINTER_REGNUM
657 || GET_CODE (XEXP (x0
, 1)) != CONST_INT
)
659 fprintf (stderr
, "bad INDEXed address:");
661 output_operand_lossage ("fr30_print_operand: unhandled MEM");
663 else if (REGNO (XEXP (x0
, 0)) == FRAME_POINTER_REGNUM
)
665 HOST_WIDE_INT val
= INTVAL (XEXP (x0
, 1));
666 if (val
< -(1 << 9) || val
> ((1 << 9) - 4))
668 fprintf (stderr
, "frame INDEX out of range:");
670 output_operand_lossage ("fr30_print_operand: unhandled MEM");
672 fprintf (file
, "@(r14, #" HOST_WIDE_INT_PRINT_DEC
")", val
);
676 HOST_WIDE_INT val
= INTVAL (XEXP (x0
, 1));
677 if (val
< 0 || val
> ((1 << 6) - 4))
679 fprintf (stderr
, "stack INDEX out of range:");
681 output_operand_lossage ("fr30_print_operand: unhandled MEM");
683 fprintf (file
, "@(r15, #" HOST_WIDE_INT_PRINT_DEC
")", val
);
692 fprintf (stderr
, "bad MEM code = %x\n", GET_CODE (x0
));
694 output_operand_lossage ("fr30_print_operand: unhandled MEM");
700 /* We handle SFmode constants here as output_addr_const doesn't. */
701 if (GET_MODE (x
) == SFmode
)
706 REAL_VALUE_FROM_CONST_DOUBLE (d
, x
);
707 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
708 fprintf (file
, "0x%08lx", l
);
712 /* Fall through. Let output_addr_const deal with it. */
714 output_addr_const (file
, x
);
723 /* Implements TARGET_FUNCTION_VALUE. */
726 fr30_function_value (const_tree valtype
,
727 const_tree fntype_or_decli ATTRIBUTE_UNUSED
,
728 bool outgoing ATTRIBUTE_UNUSED
)
730 return gen_rtx_REG (TYPE_MODE (valtype
), RETURN_VALUE_REGNUM
);
733 /* Implements TARGET_LIBCALL_VALUE. */
736 fr30_libcall_value (machine_mode mode
,
737 const_rtx fun ATTRIBUTE_UNUSED
)
739 return gen_rtx_REG (mode
, RETURN_VALUE_REGNUM
);
742 /* Implements TARGET_FUNCTION_VALUE_REGNO_P. */
745 fr30_function_value_regno_p (const unsigned int regno
)
747 return (regno
== RETURN_VALUE_REGNUM
);
750 /*{{{ Function arguments */
752 /* Return true if we should pass an argument on the stack rather than
756 fr30_must_pass_in_stack (machine_mode mode
, const_tree type
)
762 return AGGREGATE_TYPE_P (type
);
765 /* Compute the number of word sized registers needed to hold a
766 function argument of mode INT_MODE and tree type TYPE. */
768 fr30_num_arg_regs (machine_mode mode
, const_tree type
)
772 if (targetm
.calls
.must_pass_in_stack (mode
, type
))
775 if (type
&& mode
== BLKmode
)
776 size
= int_size_in_bytes (type
);
778 size
= GET_MODE_SIZE (mode
);
780 return (size
+ UNITS_PER_WORD
- 1) / UNITS_PER_WORD
;
783 /* Returns the number of bytes in which *part* of a parameter of machine
784 mode MODE and tree type TYPE (which may be NULL if the type is not known).
785 If the argument fits entirely in the argument registers, or entirely on
786 the stack, then 0 is returned.
787 CUM is the number of argument registers already used by earlier
788 parameters to the function. */
791 fr30_arg_partial_bytes (cumulative_args_t cum_v
, machine_mode mode
,
792 tree type
, bool named
)
794 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
796 /* Unnamed arguments, i.e. those that are prototyped as ...
797 are always passed on the stack.
798 Also check here to see if all the argument registers are full. */
799 if (named
== 0 || *cum
>= FR30_NUM_ARG_REGS
)
802 /* Work out how many argument registers would be needed if this
803 parameter were to be passed entirely in registers. If there
804 are sufficient argument registers available (or if no registers
805 are needed because the parameter must be passed on the stack)
806 then return zero, as this parameter does not require partial
807 register, partial stack stack space. */
808 if (*cum
+ fr30_num_arg_regs (mode
, type
) <= FR30_NUM_ARG_REGS
)
811 return (FR30_NUM_ARG_REGS
- *cum
) * UNITS_PER_WORD
;
815 fr30_function_arg (cumulative_args_t cum_v
, machine_mode mode
,
816 const_tree type
, bool named
)
818 CUMULATIVE_ARGS
*cum
= get_cumulative_args (cum_v
);
821 || fr30_must_pass_in_stack (mode
, type
)
822 || *cum
>= FR30_NUM_ARG_REGS
)
825 return gen_rtx_REG (mode
, *cum
+ FIRST_ARG_REGNUM
);
828 /* A C statement (sans semicolon) to update the summarizer variable CUM to
829 advance past an argument in the argument list. The values MODE, TYPE and
830 NAMED describe that argument. Once this is done, the variable CUM is
831 suitable for analyzing the *following* argument with `FUNCTION_ARG', etc.
833 This macro need not do anything if the argument in question was passed on
834 the stack. The compiler knows how to track the amount of stack space used
835 for arguments without any special help. */
837 fr30_function_arg_advance (cumulative_args_t cum
, machine_mode mode
,
838 const_tree type
, bool named
)
840 *get_cumulative_args (cum
) += named
* fr30_num_arg_regs (mode
, type
);
844 /*{{{ Operand predicates */
847 #define Mmode machine_mode
850 /* Returns true iff all the registers in the operands array
851 are in descending or ascending order. */
853 fr30_check_multiple_regs (rtx
*operands
, int num_operands
, int descending
)
857 unsigned int prev_regno
= 0;
859 while (num_operands
--)
861 if (GET_CODE (operands
[num_operands
]) != REG
)
864 if (REGNO (operands
[num_operands
]) < prev_regno
)
867 prev_regno
= REGNO (operands
[num_operands
]);
872 unsigned int prev_regno
= CONDITION_CODE_REGNUM
;
874 while (num_operands
--)
876 if (GET_CODE (operands
[num_operands
]) != REG
)
879 if (REGNO (operands
[num_operands
]) > prev_regno
)
882 prev_regno
= REGNO (operands
[num_operands
]);
890 fr30_const_double_is_zero (rtx operand
)
894 if (operand
== NULL
|| GET_CODE (operand
) != CONST_DOUBLE
)
897 REAL_VALUE_FROM_CONST_DOUBLE (d
, operand
);
899 return REAL_VALUES_EQUAL (d
, dconst0
);
903 /*{{{ Instruction Output Routines */
905 /* Output a double word move.
906 It must be REG<-REG, REG<-MEM, MEM<-REG or REG<-CONST.
907 On the FR30 we are constrained by the fact that it does not
908 support offsetable addresses, and so we have to load the
909 address of the secnd word into the second destination register
910 before we can use it. */
913 fr30_move_double (rtx
* operands
)
915 rtx src
= operands
[1];
916 rtx dest
= operands
[0];
917 enum rtx_code src_code
= GET_CODE (src
);
918 enum rtx_code dest_code
= GET_CODE (dest
);
919 machine_mode mode
= GET_MODE (dest
);
924 if (dest_code
== REG
)
928 int reverse
= (REGNO (dest
) == REGNO (src
) + 1);
930 /* We normally copy the low-numbered register first. However, if
931 the first register of operand 0 is the same as the second register
932 of operand 1, we must copy in the opposite order. */
933 emit_insn (gen_rtx_SET (VOIDmode
,
934 operand_subword (dest
, reverse
, TRUE
, mode
),
935 operand_subword (src
, reverse
, TRUE
, mode
)));
937 emit_insn (gen_rtx_SET (VOIDmode
,
938 operand_subword (dest
, !reverse
, TRUE
, mode
),
939 operand_subword (src
, !reverse
, TRUE
, mode
)));
941 else if (src_code
== MEM
)
943 rtx addr
= XEXP (src
, 0);
944 rtx dest0
= operand_subword (dest
, 0, TRUE
, mode
);
945 rtx dest1
= operand_subword (dest
, 1, TRUE
, mode
);
948 gcc_assert (GET_CODE (addr
) == REG
);
950 /* Copy the address before clobbering it. See PR 34174. */
951 emit_insn (gen_rtx_SET (SImode
, dest1
, addr
));
952 emit_insn (gen_rtx_SET (VOIDmode
, dest0
,
953 adjust_address (src
, SImode
, 0)));
954 emit_insn (gen_rtx_SET (SImode
, dest1
,
955 plus_constant (SImode
, dest1
,
958 new_mem
= gen_rtx_MEM (SImode
, dest1
);
959 MEM_COPY_ATTRIBUTES (new_mem
, src
);
961 emit_insn (gen_rtx_SET (VOIDmode
, dest1
, new_mem
));
963 else if (src_code
== CONST_INT
|| src_code
== CONST_DOUBLE
)
966 split_double (src
, &words
[0], &words
[1]);
967 emit_insn (gen_rtx_SET (VOIDmode
,
968 operand_subword (dest
, 0, TRUE
, mode
),
971 emit_insn (gen_rtx_SET (VOIDmode
,
972 operand_subword (dest
, 1, TRUE
, mode
),
976 else if (src_code
== REG
&& dest_code
== MEM
)
978 rtx addr
= XEXP (dest
, 0);
982 gcc_assert (GET_CODE (addr
) == REG
);
984 src0
= operand_subword (src
, 0, TRUE
, mode
);
985 src1
= operand_subword (src
, 1, TRUE
, mode
);
987 emit_move_insn (adjust_address (dest
, SImode
, 0), src0
);
989 if (REGNO (addr
) == STACK_POINTER_REGNUM
990 || REGNO (addr
) == FRAME_POINTER_REGNUM
)
991 emit_insn (gen_rtx_SET (VOIDmode
,
992 adjust_address (dest
, SImode
, UNITS_PER_WORD
),
997 rtx scratch_reg_r0
= gen_rtx_REG (SImode
, 0);
999 /* We need a scratch register to hold the value of 'address + 4'.
1000 We use r0 for this purpose. It is used for example for long
1001 jumps and is already marked to not be used by normal register
1003 emit_insn (gen_movsi_internal (scratch_reg_r0
, addr
));
1004 emit_insn (gen_addsi_small_int (scratch_reg_r0
, scratch_reg_r0
,
1005 GEN_INT (UNITS_PER_WORD
)));
1006 new_mem
= gen_rtx_MEM (SImode
, scratch_reg_r0
);
1007 MEM_COPY_ATTRIBUTES (new_mem
, dest
);
1008 emit_move_insn (new_mem
, src1
);
1009 emit_insn (gen_blockage ());
1013 /* This should have been prevented by the constraints on movdi_insn. */
1022 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
1025 fr30_frame_pointer_required (void)
1027 return (flag_omit_frame_pointer
== 0 || crtl
->args
.pretend_args_size
> 0);
1031 /*{{{ Trampoline Output Routines */
1033 /* Implement TARGET_ASM_TRAMPOLINE_TEMPLATE.
1034 On the FR30, the trampoline is:
1042 The no-ops are to guarantee that the static chain and final
1043 target are 32 bit aligned within the trampoline. That allows us to
1044 initialize those locations with simple SImode stores. The alternative
1045 would be to use HImode stores. */
1048 fr30_asm_trampoline_template (FILE *f
)
1050 fprintf (f
, "\tnop\n");
1051 fprintf (f
, "\tldi:32\t#0, %s\n", reg_names
[STATIC_CHAIN_REGNUM
]);
1052 fprintf (f
, "\tnop\n");
1053 fprintf (f
, "\tldi:32\t#0, %s\n", reg_names
[COMPILER_SCRATCH_REGISTER
]);
1054 fprintf (f
, "\tjmp\t@%s\n", reg_names
[COMPILER_SCRATCH_REGISTER
]);
1057 /* Implement TARGET_TRAMPOLINE_INIT. */
1060 fr30_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
1062 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
1065 emit_block_move (m_tramp
, assemble_trampoline_template (),
1066 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
1068 mem
= adjust_address (m_tramp
, SImode
, 4);
1069 emit_move_insn (mem
, chain_value
);
1070 mem
= adjust_address (m_tramp
, SImode
, 12);
1071 emit_move_insn (mem
, fnaddr
);
1075 /* Local Variables: */
1076 /* folded-file: t */