1 /* Subroutines for insn-output.c for Matsushita MN10300 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
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 3, 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 COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
29 #include "hard-reg-set.h"
30 #include "insn-config.h"
31 #include "conditions.h"
33 #include "insn-attr.h"
41 #include "diagnostic-core.h"
45 #include "target-def.h"
47 /* This is used by GOTaddr2picreg to uniquely identify
49 int mn10300_unspec_int_label_counter
;
51 /* This is used in the am33_2.0-linux-gnu port, in which global symbol
52 names are not prefixed by underscores, to tell whether to prefix a
53 label with a plus sign or not, so that the assembler can tell
54 symbol names from register names. */
55 int mn10300_protect_label
;
57 /* The selected processor. */
58 enum processor_type mn10300_processor
= PROCESSOR_DEFAULT
;
60 /* The size of the callee register save area. Right now we save everything
61 on entry since it costs us nothing in code size. It does cost us from a
62 speed standpoint, so we want to optimize this sooner or later. */
63 #define REG_SAVE_BYTES (4 * df_regs_ever_live_p (2) \
64 + 4 * df_regs_ever_live_p (3) \
65 + 4 * df_regs_ever_live_p (6) \
66 + 4 * df_regs_ever_live_p (7) \
67 + 16 * (df_regs_ever_live_p (14) || df_regs_ever_live_p (15) \
68 || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)))
71 static bool mn10300_handle_option (size_t, const char *, int);
72 static void mn10300_option_override (void);
73 static bool mn10300_legitimate_address_p (enum machine_mode
, rtx
, bool);
74 static int mn10300_address_cost_1 (rtx
, int *);
75 static int mn10300_address_cost (rtx
, bool);
76 static bool mn10300_rtx_costs (rtx
, int, int, int *, bool);
77 static void mn10300_file_start (void);
78 static bool mn10300_return_in_memory (const_tree
, const_tree
);
79 static rtx
mn10300_builtin_saveregs (void);
80 static void mn10300_va_start (tree
, rtx
);
81 static rtx
mn10300_legitimize_address (rtx
, rtx
, enum machine_mode
);
82 static bool mn10300_pass_by_reference (CUMULATIVE_ARGS
*, enum machine_mode
,
84 static int mn10300_arg_partial_bytes (CUMULATIVE_ARGS
*, enum machine_mode
,
86 static unsigned int mn10300_case_values_threshold (void);
87 static void mn10300_encode_section_info (tree
, rtx
, int);
88 static void mn10300_asm_trampoline_template (FILE *);
89 static void mn10300_trampoline_init (rtx
, tree
, rtx
);
90 static rtx
mn10300_function_value (const_tree
, const_tree
, bool);
91 static rtx
mn10300_libcall_value (enum machine_mode
, const_rtx
);
92 static void mn10300_asm_output_mi_thunk (FILE *, tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, tree
);
93 static bool mn10300_can_output_mi_thunk (const_tree
, HOST_WIDE_INT
, HOST_WIDE_INT
, const_tree
);
95 /* Initialize the GCC target structure. */
96 #undef TARGET_ASM_ALIGNED_HI_OP
97 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
99 #undef TARGET_LEGITIMIZE_ADDRESS
100 #define TARGET_LEGITIMIZE_ADDRESS mn10300_legitimize_address
102 #undef TARGET_RTX_COSTS
103 #define TARGET_RTX_COSTS mn10300_rtx_costs
104 #undef TARGET_ADDRESS_COST
105 #define TARGET_ADDRESS_COST mn10300_address_cost
107 #undef TARGET_ASM_FILE_START
108 #define TARGET_ASM_FILE_START mn10300_file_start
109 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
110 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
112 #undef TARGET_DEFAULT_TARGET_FLAGS
113 #define TARGET_DEFAULT_TARGET_FLAGS MASK_MULT_BUG | MASK_PTR_A0D0
114 #undef TARGET_HANDLE_OPTION
115 #define TARGET_HANDLE_OPTION mn10300_handle_option
116 #undef TARGET_OPTION_OVERRIDE
117 #define TARGET_OPTION_OVERRIDE mn10300_option_override
119 #undef TARGET_ENCODE_SECTION_INFO
120 #define TARGET_ENCODE_SECTION_INFO mn10300_encode_section_info
122 #undef TARGET_PROMOTE_PROTOTYPES
123 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
124 #undef TARGET_RETURN_IN_MEMORY
125 #define TARGET_RETURN_IN_MEMORY mn10300_return_in_memory
126 #undef TARGET_PASS_BY_REFERENCE
127 #define TARGET_PASS_BY_REFERENCE mn10300_pass_by_reference
128 #undef TARGET_CALLEE_COPIES
129 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
130 #undef TARGET_ARG_PARTIAL_BYTES
131 #define TARGET_ARG_PARTIAL_BYTES mn10300_arg_partial_bytes
133 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
134 #define TARGET_EXPAND_BUILTIN_SAVEREGS mn10300_builtin_saveregs
135 #undef TARGET_EXPAND_BUILTIN_VA_START
136 #define TARGET_EXPAND_BUILTIN_VA_START mn10300_va_start
138 #undef TARGET_CASE_VALUES_THRESHOLD
139 #define TARGET_CASE_VALUES_THRESHOLD mn10300_case_values_threshold
141 #undef TARGET_LEGITIMATE_ADDRESS_P
142 #define TARGET_LEGITIMATE_ADDRESS_P mn10300_legitimate_address_p
144 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
145 #define TARGET_ASM_TRAMPOLINE_TEMPLATE mn10300_asm_trampoline_template
146 #undef TARGET_TRAMPOLINE_INIT
147 #define TARGET_TRAMPOLINE_INIT mn10300_trampoline_init
149 #undef TARGET_FUNCTION_VALUE
150 #define TARGET_FUNCTION_VALUE mn10300_function_value
151 #undef TARGET_LIBCALL_VALUE
152 #define TARGET_LIBCALL_VALUE mn10300_libcall_value
154 #undef TARGET_ASM_OUTPUT_MI_THUNK
155 #define TARGET_ASM_OUTPUT_MI_THUNK mn10300_asm_output_mi_thunk
156 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
157 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK mn10300_can_output_mi_thunk
159 struct gcc_target targetm
= TARGET_INITIALIZER
;
161 /* Implement TARGET_HANDLE_OPTION. */
164 mn10300_handle_option (size_t code
,
165 const char *arg ATTRIBUTE_UNUSED
,
171 mn10300_processor
= value
? PROCESSOR_AM33
: PROCESSOR_MN10300
;
174 mn10300_processor
= (value
176 : MIN (PROCESSOR_AM33
, PROCESSOR_DEFAULT
));
183 /* Implement TARGET_OPTION_OVERRIDE. */
186 mn10300_option_override (void)
189 target_flags
&= ~MASK_MULT_BUG
;
193 mn10300_file_start (void)
195 default_file_start ();
198 fprintf (asm_out_file
, "\t.am33_2\n");
199 else if (TARGET_AM33
)
200 fprintf (asm_out_file
, "\t.am33\n");
204 /* Print operand X using operand code CODE to assembly language output file
208 print_operand (FILE *file
, rtx x
, int code
)
214 if (cc_status
.mdep
.fpCC
)
216 switch (code
== 'b' ? GET_CODE (x
)
217 : reverse_condition_maybe_unordered (GET_CODE (x
)))
220 fprintf (file
, "ne");
223 fprintf (file
, "eq");
226 fprintf (file
, "ge");
229 fprintf (file
, "gt");
232 fprintf (file
, "le");
235 fprintf (file
, "lt");
238 fprintf (file
, "lge");
241 fprintf (file
, "uo");
244 fprintf (file
, "lg");
247 fprintf (file
, "ue");
250 fprintf (file
, "uge");
253 fprintf (file
, "ug");
256 fprintf (file
, "ule");
259 fprintf (file
, "ul");
266 /* These are normal and reversed branches. */
267 switch (code
== 'b' ? GET_CODE (x
) : reverse_condition (GET_CODE (x
)))
270 fprintf (file
, "ne");
273 fprintf (file
, "eq");
276 fprintf (file
, "ge");
279 fprintf (file
, "gt");
282 fprintf (file
, "le");
285 fprintf (file
, "lt");
288 fprintf (file
, "cc");
291 fprintf (file
, "hi");
294 fprintf (file
, "ls");
297 fprintf (file
, "cs");
304 /* This is used for the operand to a call instruction;
305 if it's a REG, enclose it in parens, else output
306 the operand normally. */
307 if (GET_CODE (x
) == REG
)
310 print_operand (file
, x
, 0);
314 print_operand (file
, x
, 0);
318 switch (GET_CODE (x
))
322 output_address (XEXP (x
, 0));
327 fprintf (file
, "fd%d", REGNO (x
) - 18);
335 /* These are the least significant word in a 64bit value. */
337 switch (GET_CODE (x
))
341 output_address (XEXP (x
, 0));
346 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
350 fprintf (file
, "%s", reg_names
[subreg_regno (x
)]);
358 switch (GET_MODE (x
))
361 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
362 REAL_VALUE_TO_TARGET_DOUBLE (rv
, val
);
363 fprintf (file
, "0x%lx", val
[0]);
366 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
367 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
[0]);
368 fprintf (file
, "0x%lx", val
[0]);
372 print_operand_address (file
,
373 GEN_INT (CONST_DOUBLE_LOW (x
)));
384 split_double (x
, &low
, &high
);
385 fprintf (file
, "%ld", (long)INTVAL (low
));
394 /* Similarly, but for the most significant word. */
396 switch (GET_CODE (x
))
400 x
= adjust_address (x
, SImode
, 4);
401 output_address (XEXP (x
, 0));
406 fprintf (file
, "%s", reg_names
[REGNO (x
) + 1]);
410 fprintf (file
, "%s", reg_names
[subreg_regno (x
) + 1]);
418 switch (GET_MODE (x
))
421 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
422 REAL_VALUE_TO_TARGET_DOUBLE (rv
, val
);
423 fprintf (file
, "0x%lx", val
[1]);
429 print_operand_address (file
,
430 GEN_INT (CONST_DOUBLE_HIGH (x
)));
441 split_double (x
, &low
, &high
);
442 fprintf (file
, "%ld", (long)INTVAL (high
));
453 if (GET_CODE (XEXP (x
, 0)) == REG
)
454 output_address (gen_rtx_PLUS (SImode
, XEXP (x
, 0), const0_rtx
));
456 output_address (XEXP (x
, 0));
461 gcc_assert (INTVAL (x
) >= -128 && INTVAL (x
) <= 255);
462 fprintf (file
, "%d", (int)((~INTVAL (x
)) & 0xff));
466 gcc_assert (INTVAL (x
) >= -128 && INTVAL (x
) <= 255);
467 fprintf (file
, "%d", (int)(INTVAL (x
) & 0xff));
470 /* For shift counts. The hardware ignores the upper bits of
471 any immediate, but the assembler will flag an out of range
472 shift count as an error. So we mask off the high bits
473 of the immediate here. */
475 if (GET_CODE (x
) == CONST_INT
)
477 fprintf (file
, "%d", (int)(INTVAL (x
) & 0x1f));
483 switch (GET_CODE (x
))
487 output_address (XEXP (x
, 0));
496 fprintf (file
, "%s", reg_names
[REGNO (x
)]);
500 fprintf (file
, "%s", reg_names
[subreg_regno (x
)]);
503 /* This will only be single precision.... */
509 REAL_VALUE_FROM_CONST_DOUBLE (rv
, x
);
510 REAL_VALUE_TO_TARGET_SINGLE (rv
, val
);
511 fprintf (file
, "0x%lx", val
);
521 print_operand_address (file
, x
);
530 /* Output assembly language output for the address ADDR to FILE. */
533 print_operand_address (FILE *file
, rtx addr
)
535 switch (GET_CODE (addr
))
538 print_operand_address (file
, XEXP (addr
, 0));
542 print_operand (file
, addr
, 0);
547 if (REG_P (XEXP (addr
, 0))
548 && REG_OK_FOR_BASE_P (XEXP (addr
, 0)))
549 base
= XEXP (addr
, 0), index
= XEXP (addr
, 1);
550 else if (REG_P (XEXP (addr
, 1))
551 && REG_OK_FOR_BASE_P (XEXP (addr
, 1)))
552 base
= XEXP (addr
, 1), index
= XEXP (addr
, 0);
555 print_operand (file
, index
, 0);
557 print_operand (file
, base
, 0);;
561 output_addr_const (file
, addr
);
564 output_addr_const (file
, addr
);
569 /* Count the number of FP registers that have to be saved. */
571 fp_regs_to_save (void)
578 for (i
= FIRST_FP_REGNUM
; i
<= LAST_FP_REGNUM
; ++i
)
579 if (df_regs_ever_live_p (i
) && ! call_really_used_regs
[i
])
585 /* Print a set of registers in the format required by "movm" and "ret".
586 Register K is saved if bit K of MASK is set. The data and address
587 registers can be stored individually, but the extended registers cannot.
588 We assume that the mask already takes that into account. For instance,
589 bits 14 to 17 must have the same value. */
592 mn10300_print_reg_list (FILE *file
, int mask
)
600 for (i
= 0; i
< FIRST_EXTENDED_REGNUM
; i
++)
601 if ((mask
& (1 << i
)) != 0)
605 fputs (reg_names
[i
], file
);
609 if ((mask
& 0x3c000) != 0)
611 gcc_assert ((mask
& 0x3c000) == 0x3c000);
614 fputs ("exreg1", file
);
622 can_use_return_insn (void)
624 /* size includes the fixed stack space needed for function calls. */
625 int size
= get_frame_size () + crtl
->outgoing_args_size
;
627 /* And space for the return pointer. */
628 size
+= crtl
->outgoing_args_size
? 4 : 0;
630 return (reload_completed
632 && !df_regs_ever_live_p (2)
633 && !df_regs_ever_live_p (3)
634 && !df_regs_ever_live_p (6)
635 && !df_regs_ever_live_p (7)
636 && !df_regs_ever_live_p (14)
637 && !df_regs_ever_live_p (15)
638 && !df_regs_ever_live_p (16)
639 && !df_regs_ever_live_p (17)
640 && fp_regs_to_save () == 0
641 && !frame_pointer_needed
);
644 /* Returns the set of live, callee-saved registers as a bitmask. The
645 callee-saved extended registers cannot be stored individually, so
646 all of them will be included in the mask if any one of them is used. */
649 mn10300_get_live_callee_saved_regs (void)
655 for (i
= 0; i
<= LAST_EXTENDED_REGNUM
; i
++)
656 if (df_regs_ever_live_p (i
) && ! call_really_used_regs
[i
])
658 if ((mask
& 0x3c000) != 0)
664 /* Generate an instruction that pushes several registers onto the stack.
665 Register K will be saved if bit K in MASK is set. The function does
666 nothing if MASK is zero.
668 To be compatible with the "movm" instruction, the lowest-numbered
669 register must be stored in the lowest slot. If MASK is the set
670 { R1,...,RN }, where R1...RN are ordered least first, the generated
671 instruction will have the form:
674 (set (reg:SI 9) (plus:SI (reg:SI 9) (const_int -N*4)))
675 (set (mem:SI (plus:SI (reg:SI 9)
679 (set (mem:SI (plus:SI (reg:SI 9)
684 mn10300_gen_multiple_store (int mask
)
693 /* Count how many registers need to be saved. */
695 for (i
= 0; i
<= LAST_EXTENDED_REGNUM
; i
++)
696 if ((mask
& (1 << i
)) != 0)
699 /* We need one PARALLEL element to update the stack pointer and
700 an additional element for each register that is stored. */
701 par
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (count
+ 1));
703 /* Create the instruction that updates the stack pointer. */
705 = gen_rtx_SET (SImode
,
707 gen_rtx_PLUS (SImode
,
709 GEN_INT (-count
* 4)));
711 /* Create each store. */
713 for (i
= LAST_EXTENDED_REGNUM
; i
>= 0; i
--)
714 if ((mask
& (1 << i
)) != 0)
716 rtx address
= gen_rtx_PLUS (SImode
,
718 GEN_INT (-pari
* 4));
719 XVECEXP(par
, 0, pari
)
720 = gen_rtx_SET (VOIDmode
,
721 gen_rtx_MEM (SImode
, address
),
722 gen_rtx_REG (SImode
, i
));
726 par
= emit_insn (par
);
727 RTX_FRAME_RELATED_P (par
) = 1;
732 expand_prologue (void)
736 /* SIZE includes the fixed stack space needed for function calls. */
737 size
= get_frame_size () + crtl
->outgoing_args_size
;
738 size
+= (crtl
->outgoing_args_size
? 4 : 0);
740 /* If we use any of the callee-saved registers, save them now. */
741 mn10300_gen_multiple_store (mn10300_get_live_callee_saved_regs ());
743 if (TARGET_AM33_2
&& fp_regs_to_save ())
745 int num_regs_to_save
= fp_regs_to_save (), i
;
747 enum { save_sp_merge
,
749 save_sp_partial_merge
,
751 save_a0_no_merge
} strategy
;
752 unsigned int strategy_size
= (unsigned)-1, this_strategy_size
;
756 /* We have several different strategies to save FP registers.
757 We can store them using SP offsets, which is beneficial if
758 there are just a few registers to save, or we can use `a0' in
759 post-increment mode (`a0' is the only call-clobbered address
760 register that is never used to pass information to a
761 function). Furthermore, if we don't need a frame pointer, we
762 can merge the two SP adds into a single one, but this isn't
763 always beneficial; sometimes we can just split the two adds
764 so that we don't exceed a 16-bit constant size. The code
765 below will select which strategy to use, so as to generate
766 smallest code. Ties are broken in favor or shorter sequences
767 (in terms of number of instructions). */
769 #define SIZE_ADD_AX(S) ((((S) >= (1 << 15)) || ((S) < -(1 << 15))) ? 6 \
770 : (((S) >= (1 << 7)) || ((S) < -(1 << 7))) ? 4 : 2)
771 #define SIZE_ADD_SP(S) ((((S) >= (1 << 15)) || ((S) < -(1 << 15))) ? 6 \
772 : (((S) >= (1 << 7)) || ((S) < -(1 << 7))) ? 4 : 3)
773 #define SIZE_FMOV_LIMIT(S,N,L,SIZE1,SIZE2,ELSE) \
774 (((S) >= (L)) ? (SIZE1) * (N) \
775 : ((S) + 4 * (N) >= (L)) ? (((L) - (S)) / 4 * (SIZE2) \
776 + ((S) + 4 * (N) - (L)) / 4 * (SIZE1)) \
778 #define SIZE_FMOV_SP_(S,N) \
779 (SIZE_FMOV_LIMIT ((S), (N), (1 << 24), 7, 6, \
780 SIZE_FMOV_LIMIT ((S), (N), (1 << 8), 6, 4, \
781 (S) ? 4 * (N) : 3 + 4 * ((N) - 1))))
782 #define SIZE_FMOV_SP(S,N) (SIZE_FMOV_SP_ ((unsigned HOST_WIDE_INT)(S), (N)))
784 /* Consider alternative save_sp_merge only if we don't need the
785 frame pointer and size is nonzero. */
786 if (! frame_pointer_needed
&& size
)
788 /* Insn: add -(size + 4 * num_regs_to_save), sp. */
789 this_strategy_size
= SIZE_ADD_SP (-(size
+ 4 * num_regs_to_save
));
790 /* Insn: fmov fs#, (##, sp), for each fs# to be saved. */
791 this_strategy_size
+= SIZE_FMOV_SP (size
, num_regs_to_save
);
793 if (this_strategy_size
< strategy_size
)
795 strategy
= save_sp_merge
;
796 strategy_size
= this_strategy_size
;
800 /* Consider alternative save_sp_no_merge unconditionally. */
801 /* Insn: add -4 * num_regs_to_save, sp. */
802 this_strategy_size
= SIZE_ADD_SP (-4 * num_regs_to_save
);
803 /* Insn: fmov fs#, (##, sp), for each fs# to be saved. */
804 this_strategy_size
+= SIZE_FMOV_SP (0, num_regs_to_save
);
807 /* Insn: add -size, sp. */
808 this_strategy_size
+= SIZE_ADD_SP (-size
);
811 if (this_strategy_size
< strategy_size
)
813 strategy
= save_sp_no_merge
;
814 strategy_size
= this_strategy_size
;
817 /* Consider alternative save_sp_partial_merge only if we don't
818 need a frame pointer and size is reasonably large. */
819 if (! frame_pointer_needed
&& size
+ 4 * num_regs_to_save
> 128)
821 /* Insn: add -128, sp. */
822 this_strategy_size
= SIZE_ADD_SP (-128);
823 /* Insn: fmov fs#, (##, sp), for each fs# to be saved. */
824 this_strategy_size
+= SIZE_FMOV_SP (128 - 4 * num_regs_to_save
,
828 /* Insn: add 128-size, sp. */
829 this_strategy_size
+= SIZE_ADD_SP (128 - size
);
832 if (this_strategy_size
< strategy_size
)
834 strategy
= save_sp_partial_merge
;
835 strategy_size
= this_strategy_size
;
839 /* Consider alternative save_a0_merge only if we don't need a
840 frame pointer, size is nonzero and the user hasn't
841 changed the calling conventions of a0. */
842 if (! frame_pointer_needed
&& size
843 && call_really_used_regs
[FIRST_ADDRESS_REGNUM
]
844 && ! fixed_regs
[FIRST_ADDRESS_REGNUM
])
846 /* Insn: add -(size + 4 * num_regs_to_save), sp. */
847 this_strategy_size
= SIZE_ADD_SP (-(size
+ 4 * num_regs_to_save
));
848 /* Insn: mov sp, a0. */
849 this_strategy_size
++;
852 /* Insn: add size, a0. */
853 this_strategy_size
+= SIZE_ADD_AX (size
);
855 /* Insn: fmov fs#, (a0+), for each fs# to be saved. */
856 this_strategy_size
+= 3 * num_regs_to_save
;
858 if (this_strategy_size
< strategy_size
)
860 strategy
= save_a0_merge
;
861 strategy_size
= this_strategy_size
;
865 /* Consider alternative save_a0_no_merge if the user hasn't
866 changed the calling conventions of a0. */
867 if (call_really_used_regs
[FIRST_ADDRESS_REGNUM
]
868 && ! fixed_regs
[FIRST_ADDRESS_REGNUM
])
870 /* Insn: add -4 * num_regs_to_save, sp. */
871 this_strategy_size
= SIZE_ADD_SP (-4 * num_regs_to_save
);
872 /* Insn: mov sp, a0. */
873 this_strategy_size
++;
874 /* Insn: fmov fs#, (a0+), for each fs# to be saved. */
875 this_strategy_size
+= 3 * num_regs_to_save
;
878 /* Insn: add -size, sp. */
879 this_strategy_size
+= SIZE_ADD_SP (-size
);
882 if (this_strategy_size
< strategy_size
)
884 strategy
= save_a0_no_merge
;
885 strategy_size
= this_strategy_size
;
889 /* Emit the initial SP add, common to all strategies. */
892 case save_sp_no_merge
:
893 case save_a0_no_merge
:
894 emit_insn (gen_addsi3 (stack_pointer_rtx
,
896 GEN_INT (-4 * num_regs_to_save
)));
900 case save_sp_partial_merge
:
901 emit_insn (gen_addsi3 (stack_pointer_rtx
,
904 xsize
= 128 - 4 * num_regs_to_save
;
910 emit_insn (gen_addsi3 (stack_pointer_rtx
,
912 GEN_INT (-(size
+ 4 * num_regs_to_save
))));
913 /* We'll have to adjust FP register saves according to the
916 /* Since we've already created the stack frame, don't do it
917 again at the end of the function. */
925 /* Now prepare register a0, if we have decided to use it. */
929 case save_sp_no_merge
:
930 case save_sp_partial_merge
:
935 case save_a0_no_merge
:
936 reg
= gen_rtx_REG (SImode
, FIRST_ADDRESS_REGNUM
);
937 emit_insn (gen_movsi (reg
, stack_pointer_rtx
));
939 emit_insn (gen_addsi3 (reg
, reg
, GEN_INT (xsize
)));
940 reg
= gen_rtx_POST_INC (SImode
, reg
);
947 /* Now actually save the FP registers. */
948 for (i
= FIRST_FP_REGNUM
; i
<= LAST_FP_REGNUM
; ++i
)
949 if (df_regs_ever_live_p (i
) && ! call_really_used_regs
[i
])
957 /* If we aren't using `a0', use an SP offset. */
960 addr
= gen_rtx_PLUS (SImode
,
965 addr
= stack_pointer_rtx
;
970 insn
= emit_insn (gen_movsi (gen_rtx_MEM (SImode
, addr
),
971 gen_rtx_REG (SImode
, i
)));
973 RTX_FRAME_RELATED_P (insn
) = 1;
977 /* Now put the frame pointer into the frame pointer register. */
978 if (frame_pointer_needed
)
979 emit_move_insn (frame_pointer_rtx
, stack_pointer_rtx
);
981 /* Allocate stack for this frame. */
983 emit_insn (gen_addsi3 (stack_pointer_rtx
,
986 if (flag_pic
&& df_regs_ever_live_p (PIC_OFFSET_TABLE_REGNUM
))
987 emit_insn (gen_GOTaddr2picreg ());
991 expand_epilogue (void)
995 /* SIZE includes the fixed stack space needed for function calls. */
996 size
= get_frame_size () + crtl
->outgoing_args_size
;
997 size
+= (crtl
->outgoing_args_size
? 4 : 0);
999 if (TARGET_AM33_2
&& fp_regs_to_save ())
1001 int num_regs_to_save
= fp_regs_to_save (), i
;
1004 /* We have several options to restore FP registers. We could
1005 load them from SP offsets, but, if there are enough FP
1006 registers to restore, we win if we use a post-increment
1009 /* If we have a frame pointer, it's the best option, because we
1010 already know it has the value we want. */
1011 if (frame_pointer_needed
)
1012 reg
= gen_rtx_REG (SImode
, FRAME_POINTER_REGNUM
);
1013 /* Otherwise, we may use `a1', since it's call-clobbered and
1014 it's never used for return values. But only do so if it's
1015 smaller than using SP offsets. */
1018 enum { restore_sp_post_adjust
,
1019 restore_sp_pre_adjust
,
1020 restore_sp_partial_adjust
,
1021 restore_a1
} strategy
;
1022 unsigned int this_strategy_size
, strategy_size
= (unsigned)-1;
1024 /* Consider using sp offsets before adjusting sp. */
1025 /* Insn: fmov (##,sp),fs#, for each fs# to be restored. */
1026 this_strategy_size
= SIZE_FMOV_SP (size
, num_regs_to_save
);
1027 /* If size is too large, we'll have to adjust SP with an
1029 if (size
+ 4 * num_regs_to_save
+ REG_SAVE_BYTES
> 255)
1031 /* Insn: add size + 4 * num_regs_to_save, sp. */
1032 this_strategy_size
+= SIZE_ADD_SP (size
+ 4 * num_regs_to_save
);
1034 /* If we don't have to restore any non-FP registers,
1035 we'll be able to save one byte by using rets. */
1036 if (! REG_SAVE_BYTES
)
1037 this_strategy_size
--;
1039 if (this_strategy_size
< strategy_size
)
1041 strategy
= restore_sp_post_adjust
;
1042 strategy_size
= this_strategy_size
;
1045 /* Consider using sp offsets after adjusting sp. */
1046 /* Insn: add size, sp. */
1047 this_strategy_size
= SIZE_ADD_SP (size
);
1048 /* Insn: fmov (##,sp),fs#, for each fs# to be restored. */
1049 this_strategy_size
+= SIZE_FMOV_SP (0, num_regs_to_save
);
1050 /* We're going to use ret to release the FP registers
1051 save area, so, no savings. */
1053 if (this_strategy_size
< strategy_size
)
1055 strategy
= restore_sp_pre_adjust
;
1056 strategy_size
= this_strategy_size
;
1059 /* Consider using sp offsets after partially adjusting sp.
1060 When size is close to 32Kb, we may be able to adjust SP
1061 with an imm16 add instruction while still using fmov
1063 if (size
+ 4 * num_regs_to_save
+ REG_SAVE_BYTES
> 255)
1065 /* Insn: add size + 4 * num_regs_to_save
1066 + REG_SAVE_BYTES - 252,sp. */
1067 this_strategy_size
= SIZE_ADD_SP (size
+ 4 * num_regs_to_save
1068 + REG_SAVE_BYTES
- 252);
1069 /* Insn: fmov (##,sp),fs#, fo each fs# to be restored. */
1070 this_strategy_size
+= SIZE_FMOV_SP (252 - REG_SAVE_BYTES
1071 - 4 * num_regs_to_save
,
1073 /* We're going to use ret to release the FP registers
1074 save area, so, no savings. */
1076 if (this_strategy_size
< strategy_size
)
1078 strategy
= restore_sp_partial_adjust
;
1079 strategy_size
= this_strategy_size
;
1083 /* Consider using a1 in post-increment mode, as long as the
1084 user hasn't changed the calling conventions of a1. */
1085 if (call_really_used_regs
[FIRST_ADDRESS_REGNUM
+ 1]
1086 && ! fixed_regs
[FIRST_ADDRESS_REGNUM
+1])
1088 /* Insn: mov sp,a1. */
1089 this_strategy_size
= 1;
1092 /* Insn: add size,a1. */
1093 this_strategy_size
+= SIZE_ADD_AX (size
);
1095 /* Insn: fmov (a1+),fs#, for each fs# to be restored. */
1096 this_strategy_size
+= 3 * num_regs_to_save
;
1097 /* If size is large enough, we may be able to save a
1099 if (size
+ 4 * num_regs_to_save
+ REG_SAVE_BYTES
> 255)
1101 /* Insn: mov a1,sp. */
1102 this_strategy_size
+= 2;
1104 /* If we don't have to restore any non-FP registers,
1105 we'll be able to save one byte by using rets. */
1106 if (! REG_SAVE_BYTES
)
1107 this_strategy_size
--;
1109 if (this_strategy_size
< strategy_size
)
1111 strategy
= restore_a1
;
1112 strategy_size
= this_strategy_size
;
1118 case restore_sp_post_adjust
:
1121 case restore_sp_pre_adjust
:
1122 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1128 case restore_sp_partial_adjust
:
1129 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1131 GEN_INT (size
+ 4 * num_regs_to_save
1132 + REG_SAVE_BYTES
- 252)));
1133 size
= 252 - REG_SAVE_BYTES
- 4 * num_regs_to_save
;
1137 reg
= gen_rtx_REG (SImode
, FIRST_ADDRESS_REGNUM
+ 1);
1138 emit_insn (gen_movsi (reg
, stack_pointer_rtx
));
1140 emit_insn (gen_addsi3 (reg
, reg
, GEN_INT (size
)));
1148 /* Adjust the selected register, if any, for post-increment. */
1150 reg
= gen_rtx_POST_INC (SImode
, reg
);
1152 for (i
= FIRST_FP_REGNUM
; i
<= LAST_FP_REGNUM
; ++i
)
1153 if (df_regs_ever_live_p (i
) && ! call_really_used_regs
[i
])
1161 /* If we aren't using a post-increment register, use an
1163 addr
= gen_rtx_PLUS (SImode
,
1168 addr
= stack_pointer_rtx
;
1172 emit_insn (gen_movsi (gen_rtx_REG (SImode
, i
),
1173 gen_rtx_MEM (SImode
, addr
)));
1176 /* If we were using the restore_a1 strategy and the number of
1177 bytes to be released won't fit in the `ret' byte, copy `a1'
1178 to `sp', to avoid having to use `add' to adjust it. */
1179 if (! frame_pointer_needed
&& reg
&& size
+ REG_SAVE_BYTES
> 255)
1181 emit_move_insn (stack_pointer_rtx
, XEXP (reg
, 0));
1186 /* Maybe cut back the stack, except for the register save area.
1188 If the frame pointer exists, then use the frame pointer to
1191 If the stack size + register save area is more than 255 bytes,
1192 then the stack must be cut back here since the size + register
1193 save size is too big for a ret/retf instruction.
1195 Else leave it alone, it will be cut back as part of the
1196 ret/retf instruction, or there wasn't any stack to begin with.
1198 Under no circumstances should the register save area be
1199 deallocated here, that would leave a window where an interrupt
1200 could occur and trash the register save area. */
1201 if (frame_pointer_needed
)
1203 emit_move_insn (stack_pointer_rtx
, frame_pointer_rtx
);
1206 else if (size
+ REG_SAVE_BYTES
> 255)
1208 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1214 /* Adjust the stack and restore callee-saved registers, if any. */
1215 if (size
|| df_regs_ever_live_p (2) || df_regs_ever_live_p (3)
1216 || df_regs_ever_live_p (6) || df_regs_ever_live_p (7)
1217 || df_regs_ever_live_p (14) || df_regs_ever_live_p (15)
1218 || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)
1219 || frame_pointer_needed
)
1220 emit_jump_insn (gen_return_internal_regs
1221 (GEN_INT (size
+ REG_SAVE_BYTES
)));
1223 emit_jump_insn (gen_return_internal ());
1226 /* Update the condition code from the insn. */
1229 notice_update_cc (rtx body
, rtx insn
)
1231 switch (get_attr_cc (insn
))
1234 /* Insn does not affect CC at all. */
1238 /* Insn does not change CC, but the 0'th operand has been changed. */
1239 if (cc_status
.value1
!= 0
1240 && reg_overlap_mentioned_p (recog_data
.operand
[0], cc_status
.value1
))
1241 cc_status
.value1
= 0;
1245 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1246 V,C are unusable. */
1248 cc_status
.flags
|= CC_NO_CARRY
| CC_OVERFLOW_UNUSABLE
;
1249 cc_status
.value1
= recog_data
.operand
[0];
1253 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1256 cc_status
.flags
|= CC_NO_CARRY
;
1257 cc_status
.value1
= recog_data
.operand
[0];
1261 /* The insn is a compare instruction. */
1263 cc_status
.value1
= SET_SRC (body
);
1264 if (GET_CODE (cc_status
.value1
) == COMPARE
1265 && GET_MODE (XEXP (cc_status
.value1
, 0)) == SFmode
)
1266 cc_status
.mdep
.fpCC
= 1;
1270 /* Insn doesn't leave CC in a usable state. */
1279 /* Recognize the PARALLEL rtx generated by mn10300_gen_multiple_store().
1280 This function is for MATCH_PARALLEL and so assumes OP is known to be
1281 parallel. If OP is a multiple store, return a mask indicating which
1282 registers it saves. Return 0 otherwise. */
1285 store_multiple_operation (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1293 count
= XVECLEN (op
, 0);
1297 /* Check that first instruction has the form (set (sp) (plus A B)) */
1298 elt
= XVECEXP (op
, 0, 0);
1299 if (GET_CODE (elt
) != SET
1300 || GET_CODE (SET_DEST (elt
)) != REG
1301 || REGNO (SET_DEST (elt
)) != STACK_POINTER_REGNUM
1302 || GET_CODE (SET_SRC (elt
)) != PLUS
)
1305 /* Check that A is the stack pointer and B is the expected stack size.
1306 For OP to match, each subsequent instruction should push a word onto
1307 the stack. We therefore expect the first instruction to create
1308 COUNT-1 stack slots. */
1309 elt
= SET_SRC (elt
);
1310 if (GET_CODE (XEXP (elt
, 0)) != REG
1311 || REGNO (XEXP (elt
, 0)) != STACK_POINTER_REGNUM
1312 || GET_CODE (XEXP (elt
, 1)) != CONST_INT
1313 || INTVAL (XEXP (elt
, 1)) != -(count
- 1) * 4)
1316 /* Now go through the rest of the vector elements. They must be
1317 ordered so that the first instruction stores the highest-numbered
1318 register to the highest stack slot and that subsequent instructions
1319 store a lower-numbered register to the slot below.
1321 LAST keeps track of the smallest-numbered register stored so far.
1322 MASK is the set of stored registers. */
1323 last
= LAST_EXTENDED_REGNUM
+ 1;
1325 for (i
= 1; i
< count
; i
++)
1327 /* Check that element i is a (set (mem M) R) and that R is valid. */
1328 elt
= XVECEXP (op
, 0, i
);
1329 if (GET_CODE (elt
) != SET
1330 || GET_CODE (SET_DEST (elt
)) != MEM
1331 || GET_CODE (SET_SRC (elt
)) != REG
1332 || REGNO (SET_SRC (elt
)) >= last
)
1335 /* R was OK, so provisionally add it to MASK. We return 0 in any
1336 case if the rest of the instruction has a flaw. */
1337 last
= REGNO (SET_SRC (elt
));
1338 mask
|= (1 << last
);
1340 /* Check that M has the form (plus (sp) (const_int -I*4)) */
1341 elt
= XEXP (SET_DEST (elt
), 0);
1342 if (GET_CODE (elt
) != PLUS
1343 || GET_CODE (XEXP (elt
, 0)) != REG
1344 || REGNO (XEXP (elt
, 0)) != STACK_POINTER_REGNUM
1345 || GET_CODE (XEXP (elt
, 1)) != CONST_INT
1346 || INTVAL (XEXP (elt
, 1)) != -i
* 4)
1350 /* All or none of the callee-saved extended registers must be in the set. */
1351 if ((mask
& 0x3c000) != 0
1352 && (mask
& 0x3c000) != 0x3c000)
1358 /* What (if any) secondary registers are needed to move IN with mode
1359 MODE into a register in register class RCLASS.
1361 We might be able to simplify this. */
1363 mn10300_secondary_reload_class (enum reg_class rclass
, enum machine_mode mode
,
1368 /* Strip off any SUBREG expressions from IN. Basically we want
1369 to know if IN is a pseudo or (subreg (pseudo)) as those can
1370 turn into MEMs during reload. */
1371 while (GET_CODE (inner
) == SUBREG
)
1372 inner
= SUBREG_REG (inner
);
1374 /* Memory loads less than a full word wide can't have an
1375 address or stack pointer destination. They must use
1376 a data register as an intermediate register. */
1377 if ((GET_CODE (in
) == MEM
1378 || (GET_CODE (inner
) == REG
1379 && REGNO (inner
) >= FIRST_PSEUDO_REGISTER
))
1380 && (mode
== QImode
|| mode
== HImode
)
1381 && (rclass
== ADDRESS_REGS
|| rclass
== SP_REGS
1382 || rclass
== SP_OR_ADDRESS_REGS
))
1385 return DATA_OR_EXTENDED_REGS
;
1389 /* We can't directly load sp + const_int into a data register;
1390 we must use an address register as an intermediate. */
1391 if (rclass
!= SP_REGS
1392 && rclass
!= ADDRESS_REGS
1393 && rclass
!= SP_OR_ADDRESS_REGS
1394 && rclass
!= SP_OR_EXTENDED_REGS
1395 && rclass
!= ADDRESS_OR_EXTENDED_REGS
1396 && rclass
!= SP_OR_ADDRESS_OR_EXTENDED_REGS
1397 && (in
== stack_pointer_rtx
1398 || (GET_CODE (in
) == PLUS
1399 && (XEXP (in
, 0) == stack_pointer_rtx
1400 || XEXP (in
, 1) == stack_pointer_rtx
))))
1401 return ADDRESS_REGS
;
1403 if (GET_CODE (in
) == PLUS
1404 && (XEXP (in
, 0) == stack_pointer_rtx
1405 || XEXP (in
, 1) == stack_pointer_rtx
))
1406 return GENERAL_REGS
;
1409 && rclass
== FP_REGS
)
1411 /* We can't load directly into an FP register from a
1412 constant address. */
1413 if (GET_CODE (in
) == MEM
1414 && CONSTANT_ADDRESS_P (XEXP (in
, 0)))
1415 return (TARGET_AM33
? DATA_OR_EXTENDED_REGS
: DATA_REGS
);
1417 /* Handle case were a pseudo may not get a hard register
1418 but has an equivalent memory location defined. */
1419 if (GET_CODE (inner
) == REG
1420 && REGNO (inner
) >= FIRST_PSEUDO_REGISTER
1421 && reg_equiv_mem
[REGNO (inner
)]
1422 && CONSTANT_ADDRESS_P (XEXP (reg_equiv_mem
[REGNO (inner
)], 0)))
1423 return (TARGET_AM33
? DATA_OR_EXTENDED_REGS
: DATA_REGS
);
1426 /* Otherwise assume no secondary reloads are needed. */
1431 initial_offset (int from
, int to
)
1433 /* The difference between the argument pointer and the frame pointer
1434 is the size of the callee register save area. */
1435 if (from
== ARG_POINTER_REGNUM
&& to
== FRAME_POINTER_REGNUM
)
1437 if (df_regs_ever_live_p (2) || df_regs_ever_live_p (3)
1438 || df_regs_ever_live_p (6) || df_regs_ever_live_p (7)
1439 || df_regs_ever_live_p (14) || df_regs_ever_live_p (15)
1440 || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)
1441 || fp_regs_to_save ()
1442 || frame_pointer_needed
)
1443 return REG_SAVE_BYTES
1444 + 4 * fp_regs_to_save ();
1449 /* The difference between the argument pointer and the stack pointer is
1450 the sum of the size of this function's frame, the callee register save
1451 area, and the fixed stack space needed for function calls (if any). */
1452 if (from
== ARG_POINTER_REGNUM
&& to
== STACK_POINTER_REGNUM
)
1454 if (df_regs_ever_live_p (2) || df_regs_ever_live_p (3)
1455 || df_regs_ever_live_p (6) || df_regs_ever_live_p (7)
1456 || df_regs_ever_live_p (14) || df_regs_ever_live_p (15)
1457 || df_regs_ever_live_p (16) || df_regs_ever_live_p (17)
1458 || fp_regs_to_save ()
1459 || frame_pointer_needed
)
1460 return (get_frame_size () + REG_SAVE_BYTES
1461 + 4 * fp_regs_to_save ()
1462 + (crtl
->outgoing_args_size
1463 ? crtl
->outgoing_args_size
+ 4 : 0));
1465 return (get_frame_size ()
1466 + (crtl
->outgoing_args_size
1467 ? crtl
->outgoing_args_size
+ 4 : 0));
1470 /* The difference between the frame pointer and stack pointer is the sum
1471 of the size of this function's frame and the fixed stack space needed
1472 for function calls (if any). */
1473 if (from
== FRAME_POINTER_REGNUM
&& to
== STACK_POINTER_REGNUM
)
1474 return (get_frame_size ()
1475 + (crtl
->outgoing_args_size
1476 ? crtl
->outgoing_args_size
+ 4 : 0));
1481 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1484 mn10300_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
1486 /* Return values > 8 bytes in length in memory. */
1487 return (int_size_in_bytes (type
) > 8
1488 || int_size_in_bytes (type
) == 0
1489 || TYPE_MODE (type
) == BLKmode
);
1492 /* Flush the argument registers to the stack for a stdarg function;
1493 return the new argument pointer. */
1495 mn10300_builtin_saveregs (void)
1498 tree fntype
= TREE_TYPE (current_function_decl
);
1499 int argadj
= ((!stdarg_p (fntype
))
1500 ? UNITS_PER_WORD
: 0);
1501 alias_set_type set
= get_varargs_alias_set ();
1504 offset
= plus_constant (crtl
->args
.arg_offset_rtx
, argadj
);
1506 offset
= crtl
->args
.arg_offset_rtx
;
1508 mem
= gen_rtx_MEM (SImode
, crtl
->args
.internal_arg_pointer
);
1509 set_mem_alias_set (mem
, set
);
1510 emit_move_insn (mem
, gen_rtx_REG (SImode
, 0));
1512 mem
= gen_rtx_MEM (SImode
,
1513 plus_constant (crtl
->args
.internal_arg_pointer
, 4));
1514 set_mem_alias_set (mem
, set
);
1515 emit_move_insn (mem
, gen_rtx_REG (SImode
, 1));
1517 return copy_to_reg (expand_binop (Pmode
, add_optab
,
1518 crtl
->args
.internal_arg_pointer
,
1519 offset
, 0, 0, OPTAB_LIB_WIDEN
));
1523 mn10300_va_start (tree valist
, rtx nextarg
)
1525 nextarg
= expand_builtin_saveregs ();
1526 std_expand_builtin_va_start (valist
, nextarg
);
1529 /* Return true when a parameter should be passed by reference. */
1532 mn10300_pass_by_reference (CUMULATIVE_ARGS
*cum ATTRIBUTE_UNUSED
,
1533 enum machine_mode mode
, const_tree type
,
1534 bool named ATTRIBUTE_UNUSED
)
1536 unsigned HOST_WIDE_INT size
;
1539 size
= int_size_in_bytes (type
);
1541 size
= GET_MODE_SIZE (mode
);
1543 return (size
> 8 || size
== 0);
1546 /* Return an RTX to represent where a value with mode MODE will be returned
1547 from a function. If the result is NULL_RTX, the argument is pushed. */
1550 function_arg (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1551 tree type
, int named ATTRIBUTE_UNUSED
)
1553 rtx result
= NULL_RTX
;
1556 /* We only support using 2 data registers as argument registers. */
1559 /* Figure out the size of the object to be passed. */
1560 if (mode
== BLKmode
)
1561 size
= int_size_in_bytes (type
);
1563 size
= GET_MODE_SIZE (mode
);
1565 /* Figure out the alignment of the object to be passed. */
1568 cum
->nbytes
= (cum
->nbytes
+ 3) & ~3;
1570 /* Don't pass this arg via a register if all the argument registers
1572 if (cum
->nbytes
> nregs
* UNITS_PER_WORD
)
1575 /* Don't pass this arg via a register if it would be split between
1576 registers and memory. */
1577 if (type
== NULL_TREE
1578 && cum
->nbytes
+ size
> nregs
* UNITS_PER_WORD
)
1581 switch (cum
->nbytes
/ UNITS_PER_WORD
)
1584 result
= gen_rtx_REG (mode
, FIRST_ARGUMENT_REGNUM
);
1587 result
= gen_rtx_REG (mode
, FIRST_ARGUMENT_REGNUM
+ 1);
1596 /* Return the number of bytes of registers to use for an argument passed
1597 partially in registers and partially in memory. */
1600 mn10300_arg_partial_bytes (CUMULATIVE_ARGS
*cum
, enum machine_mode mode
,
1601 tree type
, bool named ATTRIBUTE_UNUSED
)
1605 /* We only support using 2 data registers as argument registers. */
1608 /* Figure out the size of the object to be passed. */
1609 if (mode
== BLKmode
)
1610 size
= int_size_in_bytes (type
);
1612 size
= GET_MODE_SIZE (mode
);
1614 /* Figure out the alignment of the object to be passed. */
1617 cum
->nbytes
= (cum
->nbytes
+ 3) & ~3;
1619 /* Don't pass this arg via a register if all the argument registers
1621 if (cum
->nbytes
> nregs
* UNITS_PER_WORD
)
1624 if (cum
->nbytes
+ size
<= nregs
* UNITS_PER_WORD
)
1627 /* Don't pass this arg via a register if it would be split between
1628 registers and memory. */
1629 if (type
== NULL_TREE
1630 && cum
->nbytes
+ size
> nregs
* UNITS_PER_WORD
)
1633 return nregs
* UNITS_PER_WORD
- cum
->nbytes
;
1636 /* Return the location of the function's value. This will be either
1637 $d0 for integer functions, $a0 for pointers, or a PARALLEL of both
1638 $d0 and $a0 if the -mreturn-pointer-on-do flag is set. Note that
1639 we only return the PARALLEL for outgoing values; we do not want
1640 callers relying on this extra copy. */
1643 mn10300_function_value (const_tree valtype
,
1644 const_tree fn_decl_or_type ATTRIBUTE_UNUSED
,
1648 enum machine_mode mode
= TYPE_MODE (valtype
);
1650 if (! POINTER_TYPE_P (valtype
))
1651 return gen_rtx_REG (mode
, FIRST_DATA_REGNUM
);
1652 else if (! TARGET_PTR_A0D0
|| ! outgoing
1653 || cfun
->returns_struct
)
1654 return gen_rtx_REG (mode
, FIRST_ADDRESS_REGNUM
);
1656 rv
= gen_rtx_PARALLEL (mode
, rtvec_alloc (2));
1658 = gen_rtx_EXPR_LIST (VOIDmode
,
1659 gen_rtx_REG (mode
, FIRST_ADDRESS_REGNUM
),
1663 = gen_rtx_EXPR_LIST (VOIDmode
,
1664 gen_rtx_REG (mode
, FIRST_DATA_REGNUM
),
1669 /* Implements TARGET_LIBCALL_VALUE. */
1672 mn10300_libcall_value (enum machine_mode mode
,
1673 const_rtx fun ATTRIBUTE_UNUSED
)
1675 return gen_rtx_REG (mode
, FIRST_DATA_REGNUM
);
1678 /* Implements FUNCTION_VALUE_REGNO_P. */
1681 mn10300_function_value_regno_p (const unsigned int regno
)
1683 return (regno
== FIRST_DATA_REGNUM
|| regno
== FIRST_ADDRESS_REGNUM
);
1686 /* Output a tst insn. */
1688 output_tst (rtx operand
, rtx insn
)
1693 /* We can save a byte if we can find a register which has the value
1695 temp
= PREV_INSN (insn
);
1696 while (optimize
&& temp
)
1700 /* We allow the search to go through call insns. We record
1701 the fact that we've past a CALL_INSN and reject matches which
1702 use call clobbered registers. */
1703 if (GET_CODE (temp
) == CODE_LABEL
1704 || GET_CODE (temp
) == JUMP_INSN
1705 || GET_CODE (temp
) == BARRIER
)
1708 if (GET_CODE (temp
) == CALL_INSN
)
1711 if (GET_CODE (temp
) == NOTE
)
1713 temp
= PREV_INSN (temp
);
1717 /* It must be an insn, see if it is a simple set. */
1718 set
= single_set (temp
);
1721 temp
= PREV_INSN (temp
);
1725 /* Are we setting a data register to zero (this does not win for
1728 If it's a call clobbered register, have we past a call?
1730 Make sure the register we find isn't the same as ourself;
1731 the mn10300 can't encode that.
1733 ??? reg_set_between_p return nonzero anytime we pass a CALL_INSN
1734 so the code to detect calls here isn't doing anything useful. */
1735 if (REG_P (SET_DEST (set
))
1736 && SET_SRC (set
) == CONST0_RTX (GET_MODE (SET_DEST (set
)))
1737 && !reg_set_between_p (SET_DEST (set
), temp
, insn
)
1738 && (REGNO_REG_CLASS (REGNO (SET_DEST (set
)))
1739 == REGNO_REG_CLASS (REGNO (operand
)))
1740 && REGNO_REG_CLASS (REGNO (SET_DEST (set
))) != EXTENDED_REGS
1741 && REGNO (SET_DEST (set
)) != REGNO (operand
)
1743 || ! call_really_used_regs
[REGNO (SET_DEST (set
))]))
1746 xoperands
[0] = operand
;
1747 xoperands
[1] = SET_DEST (set
);
1749 output_asm_insn ("cmp %1,%0", xoperands
);
1753 if (REGNO_REG_CLASS (REGNO (operand
)) == EXTENDED_REGS
1754 && REG_P (SET_DEST (set
))
1755 && SET_SRC (set
) == CONST0_RTX (GET_MODE (SET_DEST (set
)))
1756 && !reg_set_between_p (SET_DEST (set
), temp
, insn
)
1757 && (REGNO_REG_CLASS (REGNO (SET_DEST (set
)))
1758 != REGNO_REG_CLASS (REGNO (operand
)))
1759 && REGNO_REG_CLASS (REGNO (SET_DEST (set
))) == EXTENDED_REGS
1760 && REGNO (SET_DEST (set
)) != REGNO (operand
)
1762 || ! call_really_used_regs
[REGNO (SET_DEST (set
))]))
1765 xoperands
[0] = operand
;
1766 xoperands
[1] = SET_DEST (set
);
1768 output_asm_insn ("cmp %1,%0", xoperands
);
1771 temp
= PREV_INSN (temp
);
1777 impossible_plus_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1779 if (GET_CODE (op
) != PLUS
)
1782 if (XEXP (op
, 0) == stack_pointer_rtx
1783 || XEXP (op
, 1) == stack_pointer_rtx
)
1789 /* Similarly, but when using a zero_extract pattern for a btst where
1790 the source operand might end up in memory. */
1792 mask_ok_for_mem_btst (int len
, int bit
)
1794 unsigned int mask
= 0;
1803 /* MASK must bit into an 8bit value. */
1804 return (((mask
& 0xff) == mask
)
1805 || ((mask
& 0xff00) == mask
)
1806 || ((mask
& 0xff0000) == mask
)
1807 || ((mask
& 0xff000000) == mask
));
1810 /* Return 1 if X contains a symbolic expression. We know these
1811 expressions will have one of a few well defined forms, so
1812 we need only check those forms. */
1814 symbolic_operand (register rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1816 switch (GET_CODE (op
))
1823 return ((GET_CODE (XEXP (op
, 0)) == SYMBOL_REF
1824 || GET_CODE (XEXP (op
, 0)) == LABEL_REF
)
1825 && GET_CODE (XEXP (op
, 1)) == CONST_INT
);
1831 /* Try machine dependent ways of modifying an illegitimate address
1832 to be legitimate. If we find one, return the new valid address.
1833 This macro is used in only one place: `memory_address' in explow.c.
1835 OLDX is the address as it was before break_out_memory_refs was called.
1836 In some cases it is useful to look at this to decide what needs to be done.
1838 Normally it is always safe for this macro to do nothing. It exists to
1839 recognize opportunities to optimize the output.
1841 But on a few ports with segmented architectures and indexed addressing
1842 (mn10300, hppa) it is used to rewrite certain problematical addresses. */
1844 mn10300_legitimize_address (rtx x
, rtx oldx ATTRIBUTE_UNUSED
,
1845 enum machine_mode mode ATTRIBUTE_UNUSED
)
1847 if (flag_pic
&& ! legitimate_pic_operand_p (x
))
1848 x
= legitimize_pic_address (oldx
, NULL_RTX
);
1850 /* Uh-oh. We might have an address for x[n-100000]. This needs
1851 special handling to avoid creating an indexed memory address
1852 with x-100000 as the base. */
1853 if (GET_CODE (x
) == PLUS
1854 && symbolic_operand (XEXP (x
, 1), VOIDmode
))
1856 /* Ugly. We modify things here so that the address offset specified
1857 by the index expression is computed first, then added to x to form
1858 the entire address. */
1860 rtx regx1
, regy1
, regy2
, y
;
1862 /* Strip off any CONST. */
1864 if (GET_CODE (y
) == CONST
)
1867 if (GET_CODE (y
) == PLUS
|| GET_CODE (y
) == MINUS
)
1869 regx1
= force_reg (Pmode
, force_operand (XEXP (x
, 0), 0));
1870 regy1
= force_reg (Pmode
, force_operand (XEXP (y
, 0), 0));
1871 regy2
= force_reg (Pmode
, force_operand (XEXP (y
, 1), 0));
1872 regx1
= force_reg (Pmode
,
1873 gen_rtx_fmt_ee (GET_CODE (y
), Pmode
, regx1
, regy2
));
1874 return force_reg (Pmode
, gen_rtx_PLUS (Pmode
, regx1
, regy1
));
1880 /* Convert a non-PIC address in `orig' to a PIC address using @GOT or
1881 @GOTOFF in `reg'. */
1883 legitimize_pic_address (rtx orig
, rtx reg
)
1885 if (GET_CODE (orig
) == LABEL_REF
1886 || (GET_CODE (orig
) == SYMBOL_REF
1887 && (CONSTANT_POOL_ADDRESS_P (orig
)
1888 || ! MN10300_GLOBAL_P (orig
))))
1891 reg
= gen_reg_rtx (Pmode
);
1893 emit_insn (gen_symGOTOFF2reg (reg
, orig
));
1896 else if (GET_CODE (orig
) == SYMBOL_REF
)
1899 reg
= gen_reg_rtx (Pmode
);
1901 emit_insn (gen_symGOT2reg (reg
, orig
));
1907 /* Return zero if X references a SYMBOL_REF or LABEL_REF whose symbol
1908 isn't protected by a PIC unspec; nonzero otherwise. */
1910 legitimate_pic_operand_p (rtx x
)
1912 register const char *fmt
;
1915 if (GET_CODE (x
) == SYMBOL_REF
|| GET_CODE (x
) == LABEL_REF
)
1918 if (GET_CODE (x
) == UNSPEC
1919 && (XINT (x
, 1) == UNSPEC_PIC
1920 || XINT (x
, 1) == UNSPEC_GOT
1921 || XINT (x
, 1) == UNSPEC_GOTOFF
1922 || XINT (x
, 1) == UNSPEC_PLT
1923 || XINT (x
, 1) == UNSPEC_GOTSYM_OFF
))
1926 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
1927 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
1933 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1934 if (! legitimate_pic_operand_p (XVECEXP (x
, i
, j
)))
1937 else if (fmt
[i
] == 'e' && ! legitimate_pic_operand_p (XEXP (x
, i
)))
1944 /* Return TRUE if the address X, taken from a (MEM:MODE X) rtx, is
1945 legitimate, and FALSE otherwise.
1947 On the mn10300, the value in the address register must be
1948 in the same memory space/segment as the effective address.
1950 This is problematical for reload since it does not understand
1951 that base+index != index+base in a memory reference.
1953 Note it is still possible to use reg+reg addressing modes,
1954 it's just much more difficult. For a discussion of a possible
1955 workaround and solution, see the comments in pa.c before the
1956 function record_unscaled_index_insn_codes. */
1959 mn10300_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict
)
1961 if (CONSTANT_ADDRESS_P (x
)
1962 && (! flag_pic
|| legitimate_pic_operand_p (x
)))
1965 if (RTX_OK_FOR_BASE_P (x
, strict
))
1969 && GET_CODE (x
) == POST_INC
1970 && RTX_OK_FOR_BASE_P (XEXP (x
, 0), strict
)
1971 && (mode
== SImode
|| mode
== SFmode
|| mode
== HImode
))
1974 if (GET_CODE (x
) == PLUS
)
1976 rtx base
= 0, index
= 0;
1978 if (REG_P (XEXP (x
, 0))
1979 && REGNO_STRICT_OK_FOR_BASE_P (REGNO (XEXP (x
, 0)), strict
))
1982 index
= XEXP (x
, 1);
1985 if (REG_P (XEXP (x
, 1))
1986 && REGNO_STRICT_OK_FOR_BASE_P (REGNO (XEXP (x
, 1)), strict
))
1989 index
= XEXP (x
, 0);
1992 if (base
!= 0 && index
!= 0)
1994 if (GET_CODE (index
) == CONST_INT
)
1996 if (GET_CODE (index
) == CONST
1997 && GET_CODE (XEXP (index
, 0)) != PLUS
1999 || legitimate_pic_operand_p (index
)))
2008 mn10300_address_cost_1 (rtx x
, int *unsig
)
2010 switch (GET_CODE (x
))
2013 switch (REGNO_REG_CLASS (REGNO (x
)))
2039 return (mn10300_address_cost_1 (XEXP (x
, 0), unsig
)
2040 + mn10300_address_cost_1 (XEXP (x
, 1), unsig
));
2045 return mn10300_address_cost (XEXP (x
, 0), !optimize_size
);
2049 return mn10300_address_cost_1 (XEXP (x
, 0), unsig
);
2052 if (INTVAL (x
) == 0)
2054 if (INTVAL (x
) + (*unsig
? 0 : 0x80) < 0x100)
2056 if (INTVAL (x
) + (*unsig
? 0 : 0x8000) < 0x10000)
2058 if (INTVAL (x
) + (*unsig
? 0 : 0x800000) < 0x1000000)
2074 mn10300_address_cost (rtx x
, bool speed ATTRIBUTE_UNUSED
)
2077 return mn10300_address_cost_1 (x
, &s
);
2081 mn10300_rtx_costs (rtx x
, int code
, int outer_code
, int *total
, bool speed ATTRIBUTE_UNUSED
)
2086 /* Zeros are extremely cheap. */
2087 if (INTVAL (x
) == 0 && (outer_code
== SET
|| outer_code
== COMPARE
))
2089 /* If it fits in 8 bits, then it's still relatively cheap. */
2090 else if (INT_8_BITS (INTVAL (x
)))
2092 /* This is the "base" cost, includes constants where either the
2093 upper or lower 16bits are all zeros. */
2094 else if (INT_16_BITS (INTVAL (x
))
2095 || (INTVAL (x
) & 0xffff) == 0
2096 || (INTVAL (x
) & 0xffff0000) == 0)
2105 /* These are more costly than a CONST_INT, but we can relax them,
2106 so they're less costly than a CONST_DOUBLE. */
2111 /* We don't optimize CONST_DOUBLEs well nor do we relax them well,
2112 so their cost is very high. */
2117 /* This is cheap, we can use btst. */
2118 if (outer_code
== COMPARE
)
2122 /* ??? This probably needs more work. */
2134 /* Check whether a constant used to initialize a DImode or DFmode can
2135 use a clr instruction. The code here must be kept in sync with
2139 mn10300_wide_const_load_uses_clr (rtx operands
[2])
2143 if (GET_CODE (operands
[0]) != REG
2144 || REGNO_REG_CLASS (REGNO (operands
[0])) != DATA_REGS
)
2147 switch (GET_CODE (operands
[1]))
2152 split_double (operands
[1], &low
, &high
);
2153 val
[0] = INTVAL (low
);
2154 val
[1] = INTVAL (high
);
2159 if (GET_MODE (operands
[1]) == DFmode
)
2163 REAL_VALUE_FROM_CONST_DOUBLE (rv
, operands
[1]);
2164 REAL_VALUE_TO_TARGET_DOUBLE (rv
, val
);
2166 else if (GET_MODE (operands
[1]) == VOIDmode
2167 || GET_MODE (operands
[1]) == DImode
)
2169 val
[0] = CONST_DOUBLE_LOW (operands
[1]);
2170 val
[1] = CONST_DOUBLE_HIGH (operands
[1]);
2178 return val
[0] == 0 || val
[1] == 0;
2180 /* If using PIC, mark a SYMBOL_REF for a non-global symbol so that we
2181 may access it using GOTOFF instead of GOT. */
2184 mn10300_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
2188 if (GET_CODE (rtl
) != MEM
)
2190 symbol
= XEXP (rtl
, 0);
2191 if (GET_CODE (symbol
) != SYMBOL_REF
)
2195 SYMBOL_REF_FLAG (symbol
) = (*targetm
.binds_local_p
) (decl
);
2198 /* Dispatch tables on the mn10300 are extremely expensive in terms of code
2199 and readonly data size. So we crank up the case threshold value to
2200 encourage a series of if/else comparisons to implement many small switch
2201 statements. In theory, this value could be increased much more if we
2202 were solely optimizing for space, but we keep it "reasonable" to avoid
2203 serious code efficiency lossage. */
2205 unsigned int mn10300_case_values_threshold (void)
2210 /* Worker function for TARGET_ASM_TRAMPOLINE_TEMPLATE. */
2213 mn10300_asm_trampoline_template (FILE *f
)
2215 fprintf (f
, "\tadd -4,sp\n");
2216 fprintf (f
, "\t.long 0x0004fffa\n");
2217 fprintf (f
, "\tmov (0,sp),a0\n");
2218 fprintf (f
, "\tadd 4,sp\n");
2219 fprintf (f
, "\tmov (13,a0),a1\n");
2220 fprintf (f
, "\tmov (17,a0),a0\n");
2221 fprintf (f
, "\tjmp (a0)\n");
2222 fprintf (f
, "\t.long 0\n");
2223 fprintf (f
, "\t.long 0\n");
2226 /* Worker function for TARGET_TRAMPOLINE_INIT. */
2229 mn10300_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
2231 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
2234 emit_block_move (m_tramp
, assemble_trampoline_template (),
2235 GEN_INT (TRAMPOLINE_SIZE
), BLOCK_OP_NORMAL
);
2237 mem
= adjust_address (m_tramp
, SImode
, 0x14);
2238 emit_move_insn (mem
, chain_value
);
2239 mem
= adjust_address (m_tramp
, SImode
, 0x18);
2240 emit_move_insn (mem
, fnaddr
);
2243 /* Output the assembler code for a C++ thunk function.
2244 THUNK_DECL is the declaration for the thunk function itself, FUNCTION
2245 is the decl for the target function. DELTA is an immediate constant
2246 offset to be added to the THIS parameter. If VCALL_OFFSET is nonzero
2247 the word at the adjusted address *(*THIS' + VCALL_OFFSET) should be
2248 additionally added to THIS. Finally jump to the entry point of
2252 mn10300_asm_output_mi_thunk (FILE * file
,
2253 tree thunk_fndecl ATTRIBUTE_UNUSED
,
2254 HOST_WIDE_INT delta
,
2255 HOST_WIDE_INT vcall_offset
,
2260 /* Get the register holding the THIS parameter. Handle the case
2261 where there is a hidden first argument for a returned structure. */
2262 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function
)), function
))
2263 _this
= reg_names
[FIRST_ARGUMENT_REGNUM
+ 1];
2265 _this
= reg_names
[FIRST_ARGUMENT_REGNUM
];
2267 fprintf (file
, "\t%s Thunk Entry Point:\n", ASM_COMMENT_START
);
2270 fprintf (file
, "\tadd %d, %s\n", (int) delta
, _this
);
2274 const char * scratch
= reg_names
[FIRST_ADDRESS_REGNUM
+ 1];
2276 fprintf (file
, "\tmov %s, %s\n", _this
, scratch
);
2277 fprintf (file
, "\tmov (%s), %s\n", scratch
, scratch
);
2278 fprintf (file
, "\tadd %d, %s\n", (int) vcall_offset
, scratch
);
2279 fprintf (file
, "\tmov (%s), %s\n", scratch
, scratch
);
2280 fprintf (file
, "\tadd %s, %s\n", scratch
, _this
);
2283 fputs ("\tjmp ", file
);
2284 assemble_name (file
, XSTR (XEXP (DECL_RTL (function
), 0), 0));
2288 /* Return true if mn10300_output_mi_thunk would be able to output the
2289 assembler code for the thunk function specified by the arguments
2290 it is passed, and false otherwise. */
2293 mn10300_can_output_mi_thunk (const_tree thunk_fndecl ATTRIBUTE_UNUSED
,
2294 HOST_WIDE_INT delta ATTRIBUTE_UNUSED
,
2295 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED
,
2296 const_tree function ATTRIBUTE_UNUSED
)