]>
Commit | Line | Data |
---|---|---|
79e68feb | 1 | /* Subroutines for insn-output.c for Motorola 68000 family. |
23a5b65a | 2 | Copyright (C) 1987-2014 Free Software Foundation, Inc. |
79e68feb | 3 | |
7ec022b2 | 4 | This file is part of GCC. |
79e68feb | 5 | |
7ec022b2 | 6 | GCC is free software; you can redistribute it and/or modify |
79e68feb | 7 | it under the terms of the GNU General Public License as published by |
2f83c7d6 | 8 | the Free Software Foundation; either version 3, or (at your option) |
79e68feb RS |
9 | any later version. |
10 | ||
7ec022b2 | 11 | GCC is distributed in the hope that it will be useful, |
79e68feb RS |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
2f83c7d6 NC |
17 | along with GCC; see the file COPYING3. If not see |
18 | <http://www.gnu.org/licenses/>. */ | |
79e68feb | 19 | |
79e68feb | 20 | #include "config.h" |
f5220a5d | 21 | #include "system.h" |
4977bab6 ZW |
22 | #include "coretypes.h" |
23 | #include "tm.h" | |
da932f04 | 24 | #include "tree.h" |
d8a2d370 DN |
25 | #include "calls.h" |
26 | #include "stor-layout.h" | |
27 | #include "varasm.h" | |
79e68feb | 28 | #include "rtl.h" |
83685514 AM |
29 | #include "hashtab.h" |
30 | #include "hash-set.h" | |
31 | #include "vec.h" | |
32 | #include "machmode.h" | |
33 | #include "hard-reg-set.h" | |
34 | #include "input.h" | |
49ad7cfa | 35 | #include "function.h" |
79e68feb | 36 | #include "regs.h" |
79e68feb RS |
37 | #include "insn-config.h" |
38 | #include "conditions.h" | |
79e68feb RS |
39 | #include "output.h" |
40 | #include "insn-attr.h" | |
1d8eaa6b | 41 | #include "recog.h" |
718f9c0f | 42 | #include "diagnostic-core.h" |
6d5f49b2 RH |
43 | #include "expr.h" |
44 | #include "reload.h" | |
5505f548 | 45 | #include "tm_p.h" |
672a6f42 NB |
46 | #include "target.h" |
47 | #include "target-def.h" | |
2cc07db4 | 48 | #include "debug.h" |
79e68feb | 49 | #include "flags.h" |
6fb5fa3c | 50 | #include "df.h" |
b8c96320 MK |
51 | /* ??? Need to add a dependency between m68k.o and sched-int.h. */ |
52 | #include "sched-int.h" | |
53 | #include "insn-codes.h" | |
75df395f | 54 | #include "ggc.h" |
96e45421 | 55 | #include "opts.h" |
8b281334 | 56 | #include "optabs.h" |
9b2b7279 | 57 | #include "builtins.h" |
82eee4f1 | 58 | #include "rtl-iter.h" |
79e68feb | 59 | |
a4e9467d RZ |
60 | enum reg_class regno_reg_class[] = |
61 | { | |
62 | DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS, | |
63 | DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS, | |
64 | ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS, | |
65 | ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS, | |
66 | FP_REGS, FP_REGS, FP_REGS, FP_REGS, | |
67 | FP_REGS, FP_REGS, FP_REGS, FP_REGS, | |
68 | ADDR_REGS | |
69 | }; | |
70 | ||
71 | ||
a40ed0f3 KH |
72 | /* The minimum number of integer registers that we want to save with the |
73 | movem instruction. Using two movel instructions instead of a single | |
74 | moveml is about 15% faster for the 68020 and 68030 at no expense in | |
75 | code size. */ | |
76 | #define MIN_MOVEM_REGS 3 | |
77 | ||
78 | /* The minimum number of floating point registers that we want to save | |
79 | with the fmovem instruction. */ | |
80 | #define MIN_FMOVEM_REGS 1 | |
81 | ||
ff482c8d | 82 | /* Structure describing stack frame layout. */ |
3d74bc09 BI |
83 | struct m68k_frame |
84 | { | |
85 | /* Stack pointer to frame pointer offset. */ | |
48ed72a4 | 86 | HOST_WIDE_INT offset; |
3d74bc09 BI |
87 | |
88 | /* Offset of FPU registers. */ | |
89 | HOST_WIDE_INT foffset; | |
90 | ||
91 | /* Frame size in bytes (rounded up). */ | |
48ed72a4 | 92 | HOST_WIDE_INT size; |
3d74bc09 BI |
93 | |
94 | /* Data and address register. */ | |
48ed72a4 PB |
95 | int reg_no; |
96 | unsigned int reg_mask; | |
3d74bc09 BI |
97 | |
98 | /* FPU registers. */ | |
48ed72a4 PB |
99 | int fpu_no; |
100 | unsigned int fpu_mask; | |
3d74bc09 BI |
101 | |
102 | /* Offsets relative to ARG_POINTER. */ | |
48ed72a4 PB |
103 | HOST_WIDE_INT frame_pointer_offset; |
104 | HOST_WIDE_INT stack_pointer_offset; | |
3d74bc09 BI |
105 | |
106 | /* Function which the above information refers to. */ | |
107 | int funcdef_no; | |
48ed72a4 PB |
108 | }; |
109 | ||
3d74bc09 BI |
110 | /* Current frame information calculated by m68k_compute_frame_layout(). */ |
111 | static struct m68k_frame current_frame; | |
112 | ||
fc2241eb RS |
113 | /* Structure describing an m68k address. |
114 | ||
115 | If CODE is UNKNOWN, the address is BASE + INDEX * SCALE + OFFSET, | |
116 | with null fields evaluating to 0. Here: | |
117 | ||
118 | - BASE satisfies m68k_legitimate_base_reg_p | |
119 | - INDEX satisfies m68k_legitimate_index_reg_p | |
120 | - OFFSET satisfies m68k_legitimate_constant_address_p | |
121 | ||
122 | INDEX is either HImode or SImode. The other fields are SImode. | |
123 | ||
124 | If CODE is PRE_DEC, the address is -(BASE). If CODE is POST_INC, | |
125 | the address is (BASE)+. */ | |
126 | struct m68k_address { | |
127 | enum rtx_code code; | |
128 | rtx base; | |
129 | rtx index; | |
130 | rtx offset; | |
131 | int scale; | |
132 | }; | |
133 | ||
ac44248e | 134 | static int m68k_sched_adjust_cost (rtx_insn *, rtx, rtx_insn *, int); |
96fcacb7 | 135 | static int m68k_sched_issue_rate (void); |
ac44248e | 136 | static int m68k_sched_variable_issue (FILE *, int, rtx_insn *, int); |
b8c96320 MK |
137 | static void m68k_sched_md_init_global (FILE *, int, int); |
138 | static void m68k_sched_md_finish_global (FILE *, int); | |
139 | static void m68k_sched_md_init (FILE *, int, int); | |
140 | static void m68k_sched_dfa_pre_advance_cycle (void); | |
141 | static void m68k_sched_dfa_post_advance_cycle (void); | |
96fcacb7 | 142 | static int m68k_sched_first_cycle_multipass_dfa_lookahead (void); |
b8c96320 | 143 | |
7b5cbb57 | 144 | static bool m68k_can_eliminate (const int, const int); |
5efd84c5 | 145 | static void m68k_conditional_register_usage (void); |
c6c3dba9 | 146 | static bool m68k_legitimate_address_p (enum machine_mode, rtx, bool); |
c5387660 | 147 | static void m68k_option_override (void); |
03e69b12 | 148 | static void m68k_override_options_after_change (void); |
8a4a2253 BI |
149 | static rtx find_addr_reg (rtx); |
150 | static const char *singlemove_string (rtx *); | |
8a4a2253 BI |
151 | static void m68k_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, |
152 | HOST_WIDE_INT, tree); | |
8636be86 | 153 | static rtx m68k_struct_value_rtx (tree, int); |
48ed72a4 PB |
154 | static tree m68k_handle_fndecl_attribute (tree *node, tree name, |
155 | tree args, int flags, | |
156 | bool *no_add_attrs); | |
3d74bc09 | 157 | static void m68k_compute_frame_layout (void); |
48ed72a4 | 158 | static bool m68k_save_reg (unsigned int regno, bool interrupt_handler); |
f7e70894 | 159 | static bool m68k_ok_for_sibcall_p (tree, tree); |
75df395f | 160 | static bool m68k_tls_symbol_p (rtx); |
506d7b68 | 161 | static rtx m68k_legitimize_address (rtx, rtx, enum machine_mode); |
68f932c4 | 162 | static bool m68k_rtx_costs (rtx, int, int, int, int *, bool); |
1c445f03 | 163 | #if M68K_HONOR_TARGET_STRICT_ALIGNMENT |
511e41e5 | 164 | static bool m68k_return_in_memory (const_tree, const_tree); |
1c445f03 | 165 | #endif |
75df395f | 166 | static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; |
e0601576 | 167 | static void m68k_trampoline_init (rtx, tree, rtx); |
079e7538 | 168 | static int m68k_return_pops_args (tree, tree, int); |
7b0f476d | 169 | static rtx m68k_delegitimize_address (rtx); |
d5cc9181 | 170 | static void m68k_function_arg_advance (cumulative_args_t, enum machine_mode, |
13d3961c | 171 | const_tree, bool); |
d5cc9181 | 172 | static rtx m68k_function_arg (cumulative_args_t, enum machine_mode, |
13d3961c | 173 | const_tree, bool); |
fbbf66e7 | 174 | static bool m68k_cannot_force_const_mem (enum machine_mode mode, rtx x); |
cb69db4f | 175 | static bool m68k_output_addr_const_extra (FILE *, rtx); |
8b281334 | 176 | static void m68k_init_sync_libfuncs (void) ATTRIBUTE_UNUSED; |
79e68feb | 177 | \f |
672a6f42 | 178 | /* Initialize the GCC target structure. */ |
301d03af RS |
179 | |
180 | #if INT_OP_GROUP == INT_OP_DOT_WORD | |
181 | #undef TARGET_ASM_ALIGNED_HI_OP | |
182 | #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t" | |
183 | #endif | |
184 | ||
185 | #if INT_OP_GROUP == INT_OP_NO_DOT | |
186 | #undef TARGET_ASM_BYTE_OP | |
187 | #define TARGET_ASM_BYTE_OP "\tbyte\t" | |
188 | #undef TARGET_ASM_ALIGNED_HI_OP | |
189 | #define TARGET_ASM_ALIGNED_HI_OP "\tshort\t" | |
190 | #undef TARGET_ASM_ALIGNED_SI_OP | |
191 | #define TARGET_ASM_ALIGNED_SI_OP "\tlong\t" | |
192 | #endif | |
193 | ||
194 | #if INT_OP_GROUP == INT_OP_DC | |
195 | #undef TARGET_ASM_BYTE_OP | |
196 | #define TARGET_ASM_BYTE_OP "\tdc.b\t" | |
197 | #undef TARGET_ASM_ALIGNED_HI_OP | |
198 | #define TARGET_ASM_ALIGNED_HI_OP "\tdc.w\t" | |
199 | #undef TARGET_ASM_ALIGNED_SI_OP | |
200 | #define TARGET_ASM_ALIGNED_SI_OP "\tdc.l\t" | |
201 | #endif | |
202 | ||
203 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
204 | #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP | |
205 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
206 | #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP | |
207 | ||
c590b625 RH |
208 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
209 | #define TARGET_ASM_OUTPUT_MI_THUNK m68k_output_mi_thunk | |
bdabc150 | 210 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
3101faab | 211 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true |
c590b625 | 212 | |
1bc7c5b6 ZW |
213 | #undef TARGET_ASM_FILE_START_APP_OFF |
214 | #define TARGET_ASM_FILE_START_APP_OFF true | |
215 | ||
506d7b68 PB |
216 | #undef TARGET_LEGITIMIZE_ADDRESS |
217 | #define TARGET_LEGITIMIZE_ADDRESS m68k_legitimize_address | |
218 | ||
b8c96320 MK |
219 | #undef TARGET_SCHED_ADJUST_COST |
220 | #define TARGET_SCHED_ADJUST_COST m68k_sched_adjust_cost | |
221 | ||
96fcacb7 MK |
222 | #undef TARGET_SCHED_ISSUE_RATE |
223 | #define TARGET_SCHED_ISSUE_RATE m68k_sched_issue_rate | |
224 | ||
b8c96320 MK |
225 | #undef TARGET_SCHED_VARIABLE_ISSUE |
226 | #define TARGET_SCHED_VARIABLE_ISSUE m68k_sched_variable_issue | |
227 | ||
228 | #undef TARGET_SCHED_INIT_GLOBAL | |
229 | #define TARGET_SCHED_INIT_GLOBAL m68k_sched_md_init_global | |
230 | ||
231 | #undef TARGET_SCHED_FINISH_GLOBAL | |
232 | #define TARGET_SCHED_FINISH_GLOBAL m68k_sched_md_finish_global | |
233 | ||
234 | #undef TARGET_SCHED_INIT | |
235 | #define TARGET_SCHED_INIT m68k_sched_md_init | |
236 | ||
237 | #undef TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE | |
238 | #define TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE m68k_sched_dfa_pre_advance_cycle | |
239 | ||
240 | #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE | |
241 | #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE m68k_sched_dfa_post_advance_cycle | |
242 | ||
96fcacb7 MK |
243 | #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD |
244 | #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \ | |
245 | m68k_sched_first_cycle_multipass_dfa_lookahead | |
246 | ||
c5387660 JM |
247 | #undef TARGET_OPTION_OVERRIDE |
248 | #define TARGET_OPTION_OVERRIDE m68k_option_override | |
249 | ||
03e69b12 MP |
250 | #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE |
251 | #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE m68k_override_options_after_change | |
252 | ||
3c50106f RH |
253 | #undef TARGET_RTX_COSTS |
254 | #define TARGET_RTX_COSTS m68k_rtx_costs | |
255 | ||
48ed72a4 PB |
256 | #undef TARGET_ATTRIBUTE_TABLE |
257 | #define TARGET_ATTRIBUTE_TABLE m68k_attribute_table | |
258 | ||
8636be86 | 259 | #undef TARGET_PROMOTE_PROTOTYPES |
586de218 | 260 | #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true |
8636be86 KH |
261 | |
262 | #undef TARGET_STRUCT_VALUE_RTX | |
263 | #define TARGET_STRUCT_VALUE_RTX m68k_struct_value_rtx | |
264 | ||
7ffb5e78 | 265 | #undef TARGET_CANNOT_FORCE_CONST_MEM |
fbbf66e7 | 266 | #define TARGET_CANNOT_FORCE_CONST_MEM m68k_cannot_force_const_mem |
7ffb5e78 | 267 | |
f7e70894 RS |
268 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
269 | #define TARGET_FUNCTION_OK_FOR_SIBCALL m68k_ok_for_sibcall_p | |
270 | ||
1c445f03 NS |
271 | #if M68K_HONOR_TARGET_STRICT_ALIGNMENT |
272 | #undef TARGET_RETURN_IN_MEMORY | |
273 | #define TARGET_RETURN_IN_MEMORY m68k_return_in_memory | |
274 | #endif | |
275 | ||
75df395f MK |
276 | #ifdef HAVE_AS_TLS |
277 | #undef TARGET_HAVE_TLS | |
278 | #define TARGET_HAVE_TLS (true) | |
279 | ||
280 | #undef TARGET_ASM_OUTPUT_DWARF_DTPREL | |
281 | #define TARGET_ASM_OUTPUT_DWARF_DTPREL m68k_output_dwarf_dtprel | |
282 | #endif | |
283 | ||
c6c3dba9 PB |
284 | #undef TARGET_LEGITIMATE_ADDRESS_P |
285 | #define TARGET_LEGITIMATE_ADDRESS_P m68k_legitimate_address_p | |
286 | ||
7b5cbb57 AS |
287 | #undef TARGET_CAN_ELIMINATE |
288 | #define TARGET_CAN_ELIMINATE m68k_can_eliminate | |
289 | ||
5efd84c5 NF |
290 | #undef TARGET_CONDITIONAL_REGISTER_USAGE |
291 | #define TARGET_CONDITIONAL_REGISTER_USAGE m68k_conditional_register_usage | |
292 | ||
e0601576 RH |
293 | #undef TARGET_TRAMPOLINE_INIT |
294 | #define TARGET_TRAMPOLINE_INIT m68k_trampoline_init | |
295 | ||
079e7538 NF |
296 | #undef TARGET_RETURN_POPS_ARGS |
297 | #define TARGET_RETURN_POPS_ARGS m68k_return_pops_args | |
298 | ||
7b0f476d AS |
299 | #undef TARGET_DELEGITIMIZE_ADDRESS |
300 | #define TARGET_DELEGITIMIZE_ADDRESS m68k_delegitimize_address | |
301 | ||
13d3961c NF |
302 | #undef TARGET_FUNCTION_ARG |
303 | #define TARGET_FUNCTION_ARG m68k_function_arg | |
304 | ||
305 | #undef TARGET_FUNCTION_ARG_ADVANCE | |
306 | #define TARGET_FUNCTION_ARG_ADVANCE m68k_function_arg_advance | |
307 | ||
1a627b35 RS |
308 | #undef TARGET_LEGITIMATE_CONSTANT_P |
309 | #define TARGET_LEGITIMATE_CONSTANT_P m68k_legitimate_constant_p | |
310 | ||
cb69db4f AS |
311 | #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA |
312 | #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA m68k_output_addr_const_extra | |
313 | ||
4c1fd084 RH |
314 | /* The value stored by TAS. */ |
315 | #undef TARGET_ATOMIC_TEST_AND_SET_TRUEVAL | |
316 | #define TARGET_ATOMIC_TEST_AND_SET_TRUEVAL 128 | |
317 | ||
48ed72a4 PB |
318 | static const struct attribute_spec m68k_attribute_table[] = |
319 | { | |
62d784f7 KT |
320 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, |
321 | affects_type_identity } */ | |
322 | { "interrupt", 0, 0, true, false, false, m68k_handle_fndecl_attribute, | |
323 | false }, | |
324 | { "interrupt_handler", 0, 0, true, false, false, | |
325 | m68k_handle_fndecl_attribute, false }, | |
326 | { "interrupt_thread", 0, 0, true, false, false, | |
327 | m68k_handle_fndecl_attribute, false }, | |
328 | { NULL, 0, 0, false, false, false, NULL, false } | |
48ed72a4 PB |
329 | }; |
330 | ||
f6897b10 | 331 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 332 | \f |
900ec02d JB |
333 | /* Base flags for 68k ISAs. */ |
334 | #define FL_FOR_isa_00 FL_ISA_68000 | |
335 | #define FL_FOR_isa_10 (FL_FOR_isa_00 | FL_ISA_68010) | |
336 | /* FL_68881 controls the default setting of -m68881. gcc has traditionally | |
337 | generated 68881 code for 68020 and 68030 targets unless explicitly told | |
338 | not to. */ | |
339 | #define FL_FOR_isa_20 (FL_FOR_isa_10 | FL_ISA_68020 \ | |
6a2b269b | 340 | | FL_BITFIELD | FL_68881 | FL_CAS) |
900ec02d JB |
341 | #define FL_FOR_isa_40 (FL_FOR_isa_20 | FL_ISA_68040) |
342 | #define FL_FOR_isa_cpu32 (FL_FOR_isa_10 | FL_ISA_68020) | |
343 | ||
344 | /* Base flags for ColdFire ISAs. */ | |
345 | #define FL_FOR_isa_a (FL_COLDFIRE | FL_ISA_A) | |
346 | #define FL_FOR_isa_aplus (FL_FOR_isa_a | FL_ISA_APLUS | FL_CF_USP) | |
347 | /* Note ISA_B doesn't necessarily include USP (user stack pointer) support. */ | |
348 | #define FL_FOR_isa_b (FL_FOR_isa_a | FL_ISA_B | FL_CF_HWDIV) | |
4e2b26aa | 349 | /* ISA_C is not upwardly compatible with ISA_B. */ |
8c5c99dc | 350 | #define FL_FOR_isa_c (FL_FOR_isa_a | FL_ISA_C | FL_CF_USP) |
900ec02d JB |
351 | |
352 | enum m68k_isa | |
353 | { | |
354 | /* Traditional 68000 instruction sets. */ | |
355 | isa_00, | |
356 | isa_10, | |
357 | isa_20, | |
358 | isa_40, | |
359 | isa_cpu32, | |
360 | /* ColdFire instruction set variants. */ | |
361 | isa_a, | |
362 | isa_aplus, | |
363 | isa_b, | |
364 | isa_c, | |
365 | isa_max | |
366 | }; | |
367 | ||
368 | /* Information about one of the -march, -mcpu or -mtune arguments. */ | |
369 | struct m68k_target_selection | |
370 | { | |
371 | /* The argument being described. */ | |
372 | const char *name; | |
373 | ||
374 | /* For -mcpu, this is the device selected by the option. | |
375 | For -mtune and -march, it is a representative device | |
376 | for the microarchitecture or ISA respectively. */ | |
377 | enum target_device device; | |
378 | ||
379 | /* The M68K_DEVICE fields associated with DEVICE. See the comment | |
380 | in m68k-devices.def for details. FAMILY is only valid for -mcpu. */ | |
381 | const char *family; | |
382 | enum uarch_type microarch; | |
383 | enum m68k_isa isa; | |
384 | unsigned long flags; | |
385 | }; | |
386 | ||
387 | /* A list of all devices in m68k-devices.def. Used for -mcpu selection. */ | |
388 | static const struct m68k_target_selection all_devices[] = | |
389 | { | |
390 | #define M68K_DEVICE(NAME,ENUM_VALUE,FAMILY,MULTILIB,MICROARCH,ISA,FLAGS) \ | |
391 | { NAME, ENUM_VALUE, FAMILY, u##MICROARCH, ISA, FLAGS | FL_FOR_##ISA }, | |
392 | #include "m68k-devices.def" | |
393 | #undef M68K_DEVICE | |
394 | { NULL, unk_device, NULL, unk_arch, isa_max, 0 } | |
395 | }; | |
396 | ||
397 | /* A list of all ISAs, mapping each one to a representative device. | |
398 | Used for -march selection. */ | |
399 | static const struct m68k_target_selection all_isas[] = | |
400 | { | |
47c94d21 JM |
401 | #define M68K_ISA(NAME,DEVICE,MICROARCH,ISA,FLAGS) \ |
402 | { NAME, DEVICE, NULL, u##MICROARCH, ISA, FLAGS }, | |
403 | #include "m68k-isas.def" | |
404 | #undef M68K_ISA | |
900ec02d JB |
405 | { NULL, unk_device, NULL, unk_arch, isa_max, 0 } |
406 | }; | |
407 | ||
408 | /* A list of all microarchitectures, mapping each one to a representative | |
409 | device. Used for -mtune selection. */ | |
410 | static const struct m68k_target_selection all_microarchs[] = | |
411 | { | |
47c94d21 JM |
412 | #define M68K_MICROARCH(NAME,DEVICE,MICROARCH,ISA,FLAGS) \ |
413 | { NAME, DEVICE, NULL, u##MICROARCH, ISA, FLAGS }, | |
414 | #include "m68k-microarchs.def" | |
415 | #undef M68K_MICROARCH | |
900ec02d JB |
416 | { NULL, unk_device, NULL, unk_arch, isa_max, 0 } |
417 | }; | |
418 | \f | |
419 | /* The entries associated with the -mcpu, -march and -mtune settings, | |
420 | or null for options that have not been used. */ | |
421 | const struct m68k_target_selection *m68k_cpu_entry; | |
422 | const struct m68k_target_selection *m68k_arch_entry; | |
423 | const struct m68k_target_selection *m68k_tune_entry; | |
424 | ||
425 | /* Which CPU we are generating code for. */ | |
426 | enum target_device m68k_cpu; | |
427 | ||
428 | /* Which microarchitecture to tune for. */ | |
429 | enum uarch_type m68k_tune; | |
430 | ||
431 | /* Which FPU to use. */ | |
432 | enum fpu_type m68k_fpu; | |
4af06170 | 433 | |
900ec02d JB |
434 | /* The set of FL_* flags that apply to the target processor. */ |
435 | unsigned int m68k_cpu_flags; | |
29ca003a | 436 | |
03b3e271 KH |
437 | /* The set of FL_* flags that apply to the processor to be tuned for. */ |
438 | unsigned int m68k_tune_flags; | |
439 | ||
29ca003a RS |
440 | /* Asm templates for calling or jumping to an arbitrary symbolic address, |
441 | or NULL if such calls or jumps are not supported. The address is held | |
442 | in operand 0. */ | |
443 | const char *m68k_symbolic_call; | |
444 | const char *m68k_symbolic_jump; | |
c47b0cb4 MK |
445 | |
446 | /* Enum variable that corresponds to m68k_symbolic_call values. */ | |
447 | enum M68K_SYMBOLIC_CALL m68k_symbolic_call_var; | |
448 | ||
900ec02d | 449 | \f |
c5387660 | 450 | /* Implement TARGET_OPTION_OVERRIDE. */ |
ef1dbfb0 | 451 | |
c5387660 JM |
452 | static void |
453 | m68k_option_override (void) | |
ef1dbfb0 | 454 | { |
900ec02d JB |
455 | const struct m68k_target_selection *entry; |
456 | unsigned long target_mask; | |
457 | ||
47c94d21 JM |
458 | if (global_options_set.x_m68k_arch_option) |
459 | m68k_arch_entry = &all_isas[m68k_arch_option]; | |
460 | ||
461 | if (global_options_set.x_m68k_cpu_option) | |
462 | m68k_cpu_entry = &all_devices[(int) m68k_cpu_option]; | |
463 | ||
464 | if (global_options_set.x_m68k_tune_option) | |
465 | m68k_tune_entry = &all_microarchs[(int) m68k_tune_option]; | |
466 | ||
900ec02d JB |
467 | /* User can choose: |
468 | ||
469 | -mcpu= | |
470 | -march= | |
471 | -mtune= | |
472 | ||
473 | -march=ARCH should generate code that runs any processor | |
474 | implementing architecture ARCH. -mcpu=CPU should override -march | |
475 | and should generate code that runs on processor CPU, making free | |
476 | use of any instructions that CPU understands. -mtune=UARCH applies | |
9f5ed61a | 477 | on top of -mcpu or -march and optimizes the code for UARCH. It does |
900ec02d JB |
478 | not change the target architecture. */ |
479 | if (m68k_cpu_entry) | |
480 | { | |
481 | /* Complain if the -march setting is for a different microarchitecture, | |
482 | or includes flags that the -mcpu setting doesn't. */ | |
483 | if (m68k_arch_entry | |
484 | && (m68k_arch_entry->microarch != m68k_cpu_entry->microarch | |
485 | || (m68k_arch_entry->flags & ~m68k_cpu_entry->flags) != 0)) | |
486 | warning (0, "-mcpu=%s conflicts with -march=%s", | |
487 | m68k_cpu_entry->name, m68k_arch_entry->name); | |
488 | ||
489 | entry = m68k_cpu_entry; | |
490 | } | |
491 | else | |
492 | entry = m68k_arch_entry; | |
493 | ||
494 | if (!entry) | |
495 | entry = all_devices + TARGET_CPU_DEFAULT; | |
496 | ||
497 | m68k_cpu_flags = entry->flags; | |
498 | ||
499 | /* Use the architecture setting to derive default values for | |
500 | certain flags. */ | |
501 | target_mask = 0; | |
8785d88c KH |
502 | |
503 | /* ColdFire is lenient about alignment. */ | |
504 | if (!TARGET_COLDFIRE) | |
505 | target_mask |= MASK_STRICT_ALIGNMENT; | |
506 | ||
900ec02d JB |
507 | if ((m68k_cpu_flags & FL_BITFIELD) != 0) |
508 | target_mask |= MASK_BITFIELD; | |
509 | if ((m68k_cpu_flags & FL_CF_HWDIV) != 0) | |
510 | target_mask |= MASK_CF_HWDIV; | |
511 | if ((m68k_cpu_flags & (FL_68881 | FL_CF_FPU)) != 0) | |
512 | target_mask |= MASK_HARD_FLOAT; | |
513 | target_flags |= target_mask & ~target_flags_explicit; | |
514 | ||
515 | /* Set the directly-usable versions of the -mcpu and -mtune settings. */ | |
516 | m68k_cpu = entry->device; | |
517 | if (m68k_tune_entry) | |
03b3e271 KH |
518 | { |
519 | m68k_tune = m68k_tune_entry->microarch; | |
520 | m68k_tune_flags = m68k_tune_entry->flags; | |
521 | } | |
900ec02d JB |
522 | #ifdef M68K_DEFAULT_TUNE |
523 | else if (!m68k_cpu_entry && !m68k_arch_entry) | |
03b3e271 KH |
524 | { |
525 | enum target_device dev; | |
526 | dev = all_microarchs[M68K_DEFAULT_TUNE].device; | |
3b891d26 | 527 | m68k_tune_flags = all_devices[dev].flags; |
03b3e271 | 528 | } |
900ec02d JB |
529 | #endif |
530 | else | |
03b3e271 KH |
531 | { |
532 | m68k_tune = entry->microarch; | |
533 | m68k_tune_flags = entry->flags; | |
534 | } | |
900ec02d JB |
535 | |
536 | /* Set the type of FPU. */ | |
537 | m68k_fpu = (!TARGET_HARD_FLOAT ? FPUTYPE_NONE | |
538 | : (m68k_cpu_flags & FL_COLDFIRE) != 0 ? FPUTYPE_COLDFIRE | |
539 | : FPUTYPE_68881); | |
540 | ||
a2ef3db7 BI |
541 | /* Sanity check to ensure that msep-data and mid-sahred-library are not |
542 | * both specified together. Doing so simply doesn't make sense. | |
543 | */ | |
544 | if (TARGET_SEP_DATA && TARGET_ID_SHARED_LIBRARY) | |
545 | error ("cannot specify both -msep-data and -mid-shared-library"); | |
546 | ||
547 | /* If we're generating code for a separate A5 relative data segment, | |
548 | * we've got to enable -fPIC as well. This might be relaxable to | |
549 | * -fpic but it hasn't been tested properly. | |
550 | */ | |
551 | if (TARGET_SEP_DATA || TARGET_ID_SHARED_LIBRARY) | |
552 | flag_pic = 2; | |
553 | ||
abe92a04 RS |
554 | /* -mpcrel -fPIC uses 32-bit pc-relative displacements. Raise an |
555 | error if the target does not support them. */ | |
556 | if (TARGET_PCREL && !TARGET_68020 && flag_pic == 2) | |
557 | error ("-mpcrel -fPIC is not currently supported on selected cpu"); | |
adf2ac37 RH |
558 | |
559 | /* ??? A historic way of turning on pic, or is this intended to | |
560 | be an embedded thing that doesn't have the same name binding | |
561 | significance that it does on hosted ELF systems? */ | |
562 | if (TARGET_PCREL && flag_pic == 0) | |
563 | flag_pic = 1; | |
564 | ||
29ca003a RS |
565 | if (!flag_pic) |
566 | { | |
c47b0cb4 MK |
567 | m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_JSR; |
568 | ||
29ca003a | 569 | m68k_symbolic_jump = "jra %a0"; |
29ca003a RS |
570 | } |
571 | else if (TARGET_ID_SHARED_LIBRARY) | |
572 | /* All addresses must be loaded from the GOT. */ | |
573 | ; | |
4e2b26aa | 574 | else if (TARGET_68020 || TARGET_ISAB || TARGET_ISAC) |
29ca003a RS |
575 | { |
576 | if (TARGET_PCREL) | |
c47b0cb4 | 577 | m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_BSR_C; |
4e2b26aa | 578 | else |
c47b0cb4 MK |
579 | m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_BSR_P; |
580 | ||
4e2b26aa NS |
581 | if (TARGET_ISAC) |
582 | /* No unconditional long branch */; | |
583 | else if (TARGET_PCREL) | |
da398bb5 | 584 | m68k_symbolic_jump = "bra%.l %c0"; |
29ca003a | 585 | else |
da398bb5 | 586 | m68k_symbolic_jump = "bra%.l %p0"; |
29ca003a RS |
587 | /* Turn off function cse if we are doing PIC. We always want |
588 | function call to be done as `bsr foo@PLTPC'. */ | |
589 | /* ??? It's traditional to do this for -mpcrel too, but it isn't | |
590 | clear how intentional that is. */ | |
591 | flag_no_function_cse = 1; | |
592 | } | |
adf2ac37 | 593 | |
c47b0cb4 MK |
594 | switch (m68k_symbolic_call_var) |
595 | { | |
596 | case M68K_SYMBOLIC_CALL_JSR: | |
c47b0cb4 | 597 | m68k_symbolic_call = "jsr %a0"; |
c47b0cb4 MK |
598 | break; |
599 | ||
600 | case M68K_SYMBOLIC_CALL_BSR_C: | |
da398bb5 | 601 | m68k_symbolic_call = "bsr%.l %c0"; |
c47b0cb4 MK |
602 | break; |
603 | ||
604 | case M68K_SYMBOLIC_CALL_BSR_P: | |
da398bb5 | 605 | m68k_symbolic_call = "bsr%.l %p0"; |
c47b0cb4 MK |
606 | break; |
607 | ||
608 | case M68K_SYMBOLIC_CALL_NONE: | |
609 | gcc_assert (m68k_symbolic_call == NULL); | |
610 | break; | |
611 | ||
612 | default: | |
613 | gcc_unreachable (); | |
614 | } | |
615 | ||
aaca7021 RZ |
616 | #ifndef ASM_OUTPUT_ALIGN_WITH_NOP |
617 | if (align_labels > 2) | |
618 | { | |
619 | warning (0, "-falign-labels=%d is not supported", align_labels); | |
620 | align_labels = 0; | |
621 | } | |
622 | if (align_loops > 2) | |
623 | { | |
624 | warning (0, "-falign-loops=%d is not supported", align_loops); | |
625 | align_loops = 0; | |
626 | } | |
627 | #endif | |
628 | ||
8e22f79f AS |
629 | if (stack_limit_rtx != NULL_RTX && !TARGET_68020) |
630 | { | |
631 | warning (0, "-fstack-limit- options are not supported on this cpu"); | |
632 | stack_limit_rtx = NULL_RTX; | |
633 | } | |
634 | ||
adf2ac37 | 635 | SUBTARGET_OVERRIDE_OPTIONS; |
c47b0cb4 MK |
636 | |
637 | /* Setup scheduling options. */ | |
826fadba MK |
638 | if (TUNE_CFV1) |
639 | m68k_sched_cpu = CPU_CFV1; | |
640 | else if (TUNE_CFV2) | |
641 | m68k_sched_cpu = CPU_CFV2; | |
642 | else if (TUNE_CFV3) | |
643 | m68k_sched_cpu = CPU_CFV3; | |
96fcacb7 MK |
644 | else if (TUNE_CFV4) |
645 | m68k_sched_cpu = CPU_CFV4; | |
c47b0cb4 MK |
646 | else |
647 | { | |
648 | m68k_sched_cpu = CPU_UNKNOWN; | |
649 | flag_schedule_insns = 0; | |
650 | flag_schedule_insns_after_reload = 0; | |
651 | flag_modulo_sched = 0; | |
1ee6eb01 | 652 | flag_live_range_shrinkage = 0; |
c47b0cb4 | 653 | } |
826fadba MK |
654 | |
655 | if (m68k_sched_cpu != CPU_UNKNOWN) | |
656 | { | |
657 | if ((m68k_cpu_flags & (FL_CF_EMAC | FL_CF_EMAC_B)) != 0) | |
658 | m68k_sched_mac = MAC_CF_EMAC; | |
659 | else if ((m68k_cpu_flags & FL_CF_MAC) != 0) | |
660 | m68k_sched_mac = MAC_CF_MAC; | |
661 | else | |
662 | m68k_sched_mac = MAC_NO; | |
663 | } | |
ef1dbfb0 | 664 | } |
7eb4f044 | 665 | |
03e69b12 MP |
666 | /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE. */ |
667 | ||
668 | static void | |
669 | m68k_override_options_after_change (void) | |
670 | { | |
671 | if (m68k_sched_cpu == CPU_UNKNOWN) | |
672 | { | |
673 | flag_schedule_insns = 0; | |
674 | flag_schedule_insns_after_reload = 0; | |
675 | flag_modulo_sched = 0; | |
1ee6eb01 | 676 | flag_live_range_shrinkage = 0; |
03e69b12 MP |
677 | } |
678 | } | |
679 | ||
7eb4f044 NS |
680 | /* Generate a macro of the form __mPREFIX_cpu_NAME, where PREFIX is the |
681 | given argument and NAME is the argument passed to -mcpu. Return NULL | |
682 | if -mcpu was not passed. */ | |
683 | ||
684 | const char * | |
685 | m68k_cpp_cpu_ident (const char *prefix) | |
686 | { | |
687 | if (!m68k_cpu_entry) | |
688 | return NULL; | |
689 | return concat ("__m", prefix, "_cpu_", m68k_cpu_entry->name, NULL); | |
690 | } | |
691 | ||
692 | /* Generate a macro of the form __mPREFIX_family_NAME, where PREFIX is the | |
693 | given argument and NAME is the name of the representative device for | |
694 | the -mcpu argument's family. Return NULL if -mcpu was not passed. */ | |
695 | ||
696 | const char * | |
697 | m68k_cpp_cpu_family (const char *prefix) | |
698 | { | |
699 | if (!m68k_cpu_entry) | |
700 | return NULL; | |
701 | return concat ("__m", prefix, "_family_", m68k_cpu_entry->family, NULL); | |
702 | } | |
79e68feb | 703 | \f |
2bccb817 KH |
704 | /* Return m68k_fk_interrupt_handler if FUNC has an "interrupt" or |
705 | "interrupt_handler" attribute and interrupt_thread if FUNC has an | |
706 | "interrupt_thread" attribute. Otherwise, return | |
707 | m68k_fk_normal_function. */ | |
a4242737 KH |
708 | |
709 | enum m68k_function_kind | |
710 | m68k_get_function_kind (tree func) | |
48ed72a4 PB |
711 | { |
712 | tree a; | |
713 | ||
fa157b28 NS |
714 | gcc_assert (TREE_CODE (func) == FUNCTION_DECL); |
715 | ||
2bccb817 KH |
716 | a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func)); |
717 | if (a != NULL_TREE) | |
718 | return m68k_fk_interrupt_handler; | |
719 | ||
48ed72a4 | 720 | a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func)); |
a4242737 KH |
721 | if (a != NULL_TREE) |
722 | return m68k_fk_interrupt_handler; | |
723 | ||
724 | a = lookup_attribute ("interrupt_thread", DECL_ATTRIBUTES (func)); | |
725 | if (a != NULL_TREE) | |
726 | return m68k_fk_interrupt_thread; | |
727 | ||
728 | return m68k_fk_normal_function; | |
48ed72a4 PB |
729 | } |
730 | ||
731 | /* Handle an attribute requiring a FUNCTION_DECL; arguments as in | |
732 | struct attribute_spec.handler. */ | |
733 | static tree | |
734 | m68k_handle_fndecl_attribute (tree *node, tree name, | |
735 | tree args ATTRIBUTE_UNUSED, | |
736 | int flags ATTRIBUTE_UNUSED, | |
737 | bool *no_add_attrs) | |
738 | { | |
739 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
740 | { | |
29d08eba JM |
741 | warning (OPT_Wattributes, "%qE attribute only applies to functions", |
742 | name); | |
48ed72a4 PB |
743 | *no_add_attrs = true; |
744 | } | |
745 | ||
a4242737 KH |
746 | if (m68k_get_function_kind (*node) != m68k_fk_normal_function) |
747 | { | |
748 | error ("multiple interrupt attributes not allowed"); | |
749 | *no_add_attrs = true; | |
750 | } | |
751 | ||
752 | if (!TARGET_FIDOA | |
753 | && !strcmp (IDENTIFIER_POINTER (name), "interrupt_thread")) | |
754 | { | |
755 | error ("interrupt_thread is available only on fido"); | |
756 | *no_add_attrs = true; | |
757 | } | |
758 | ||
48ed72a4 PB |
759 | return NULL_TREE; |
760 | } | |
860c4900 BI |
761 | |
762 | static void | |
3d74bc09 | 763 | m68k_compute_frame_layout (void) |
860c4900 BI |
764 | { |
765 | int regno, saved; | |
a40ed0f3 | 766 | unsigned int mask; |
a4242737 KH |
767 | enum m68k_function_kind func_kind = |
768 | m68k_get_function_kind (current_function_decl); | |
769 | bool interrupt_handler = func_kind == m68k_fk_interrupt_handler; | |
770 | bool interrupt_thread = func_kind == m68k_fk_interrupt_thread; | |
860c4900 | 771 | |
3d74bc09 BI |
772 | /* Only compute the frame once per function. |
773 | Don't cache information until reload has been completed. */ | |
774 | if (current_frame.funcdef_no == current_function_funcdef_no | |
775 | && reload_completed) | |
776 | return; | |
777 | ||
778 | current_frame.size = (get_frame_size () + 3) & -4; | |
860c4900 | 779 | |
a40ed0f3 | 780 | mask = saved = 0; |
a4242737 KH |
781 | |
782 | /* Interrupt thread does not need to save any register. */ | |
783 | if (!interrupt_thread) | |
784 | for (regno = 0; regno < 16; regno++) | |
785 | if (m68k_save_reg (regno, interrupt_handler)) | |
786 | { | |
787 | mask |= 1 << (regno - D0_REG); | |
788 | saved++; | |
789 | } | |
3d74bc09 BI |
790 | current_frame.offset = saved * 4; |
791 | current_frame.reg_no = saved; | |
792 | current_frame.reg_mask = mask; | |
860c4900 | 793 | |
57047680 | 794 | current_frame.foffset = 0; |
a40ed0f3 | 795 | mask = saved = 0; |
dcc21c4c | 796 | if (TARGET_HARD_FLOAT) |
860c4900 | 797 | { |
a4242737 KH |
798 | /* Interrupt thread does not need to save any register. */ |
799 | if (!interrupt_thread) | |
800 | for (regno = 16; regno < 24; regno++) | |
801 | if (m68k_save_reg (regno, interrupt_handler)) | |
802 | { | |
803 | mask |= 1 << (regno - FP0_REG); | |
804 | saved++; | |
805 | } | |
dcc21c4c | 806 | current_frame.foffset = saved * TARGET_FP_REG_SIZE; |
3d74bc09 | 807 | current_frame.offset += current_frame.foffset; |
860c4900 | 808 | } |
57047680 GN |
809 | current_frame.fpu_no = saved; |
810 | current_frame.fpu_mask = mask; | |
3d74bc09 BI |
811 | |
812 | /* Remember what function this frame refers to. */ | |
813 | current_frame.funcdef_no = current_function_funcdef_no; | |
860c4900 BI |
814 | } |
815 | ||
7b5cbb57 AS |
816 | /* Worker function for TARGET_CAN_ELIMINATE. */ |
817 | ||
818 | bool | |
819 | m68k_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to) | |
820 | { | |
821 | return (to == STACK_POINTER_REGNUM ? ! frame_pointer_needed : true); | |
822 | } | |
823 | ||
860c4900 BI |
824 | HOST_WIDE_INT |
825 | m68k_initial_elimination_offset (int from, int to) | |
826 | { | |
42b67c06 PB |
827 | int argptr_offset; |
828 | /* The arg pointer points 8 bytes before the start of the arguments, | |
829 | as defined by FIRST_PARM_OFFSET. This makes it coincident with the | |
830 | frame pointer in most frames. */ | |
831 | argptr_offset = frame_pointer_needed ? 0 : UNITS_PER_WORD; | |
860c4900 | 832 | if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) |
42b67c06 | 833 | return argptr_offset; |
860c4900 | 834 | |
3d74bc09 | 835 | m68k_compute_frame_layout (); |
860c4900 | 836 | |
4761e388 NS |
837 | gcc_assert (to == STACK_POINTER_REGNUM); |
838 | switch (from) | |
839 | { | |
a0a7fbc9 | 840 | case ARG_POINTER_REGNUM: |
42b67c06 | 841 | return current_frame.offset + current_frame.size - argptr_offset; |
4761e388 NS |
842 | case FRAME_POINTER_REGNUM: |
843 | return current_frame.offset + current_frame.size; | |
844 | default: | |
845 | gcc_unreachable (); | |
846 | } | |
860c4900 BI |
847 | } |
848 | ||
97c55091 GN |
849 | /* Refer to the array `regs_ever_live' to determine which registers |
850 | to save; `regs_ever_live[I]' is nonzero if register number I | |
851 | is ever used in the function. This function is responsible for | |
852 | knowing which registers should not be saved even if used. | |
853 | Return true if we need to save REGNO. */ | |
854 | ||
48ed72a4 PB |
855 | static bool |
856 | m68k_save_reg (unsigned int regno, bool interrupt_handler) | |
2cff4a6e | 857 | { |
4ab870f5 | 858 | if (flag_pic && regno == PIC_REG) |
b86ba8a3 | 859 | { |
e3b5732b | 860 | if (crtl->saves_all_registers) |
afcb440c | 861 | return true; |
e3b5732b | 862 | if (crtl->uses_pic_offset_table) |
b86ba8a3 | 863 | return true; |
6357eb0d RS |
864 | /* Reload may introduce constant pool references into a function |
865 | that thitherto didn't need a PIC register. Note that the test | |
866 | above will not catch that case because we will only set | |
e3b5732b | 867 | crtl->uses_pic_offset_table when emitting |
6357eb0d | 868 | the address reloads. */ |
e3b5732b | 869 | if (crtl->uses_const_pool) |
6357eb0d | 870 | return true; |
b86ba8a3 | 871 | } |
2cff4a6e | 872 | |
e3b5732b | 873 | if (crtl->calls_eh_return) |
2cff4a6e AS |
874 | { |
875 | unsigned int i; | |
876 | for (i = 0; ; i++) | |
877 | { | |
878 | unsigned int test = EH_RETURN_DATA_REGNO (i); | |
879 | if (test == INVALID_REGNUM) | |
880 | break; | |
881 | if (test == regno) | |
48ed72a4 | 882 | return true; |
2cff4a6e AS |
883 | } |
884 | } | |
885 | ||
48ed72a4 PB |
886 | /* Fixed regs we never touch. */ |
887 | if (fixed_regs[regno]) | |
888 | return false; | |
889 | ||
890 | /* The frame pointer (if it is such) is handled specially. */ | |
891 | if (regno == FRAME_POINTER_REGNUM && frame_pointer_needed) | |
892 | return false; | |
893 | ||
894 | /* Interrupt handlers must also save call_used_regs | |
895 | if they are live or when calling nested functions. */ | |
896 | if (interrupt_handler) | |
a0a7fbc9 | 897 | { |
6fb5fa3c | 898 | if (df_regs_ever_live_p (regno)) |
a0a7fbc9 | 899 | return true; |
48ed72a4 | 900 | |
416ff32e | 901 | if (!crtl->is_leaf && call_used_regs[regno]) |
a0a7fbc9 AS |
902 | return true; |
903 | } | |
48ed72a4 PB |
904 | |
905 | /* Never need to save registers that aren't touched. */ | |
6fb5fa3c | 906 | if (!df_regs_ever_live_p (regno)) |
48ed72a4 PB |
907 | return false; |
908 | ||
b2e08ed4 | 909 | /* Otherwise save everything that isn't call-clobbered. */ |
48ed72a4 | 910 | return !call_used_regs[regno]; |
2cff4a6e AS |
911 | } |
912 | ||
a40ed0f3 KH |
913 | /* Emit RTL for a MOVEM or FMOVEM instruction. BASE + OFFSET represents |
914 | the lowest memory address. COUNT is the number of registers to be | |
915 | moved, with register REGNO + I being moved if bit I of MASK is set. | |
916 | STORE_P specifies the direction of the move and ADJUST_STACK_P says | |
917 | whether or not this is pre-decrement (if STORE_P) or post-increment | |
918 | (if !STORE_P) operation. */ | |
919 | ||
c85e862a | 920 | static rtx_insn * |
a40ed0f3 KH |
921 | m68k_emit_movem (rtx base, HOST_WIDE_INT offset, |
922 | unsigned int count, unsigned int regno, | |
923 | unsigned int mask, bool store_p, bool adjust_stack_p) | |
924 | { | |
925 | int i; | |
926 | rtx body, addr, src, operands[2]; | |
927 | enum machine_mode mode; | |
928 | ||
929 | body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (adjust_stack_p + count)); | |
930 | mode = reg_raw_mode[regno]; | |
931 | i = 0; | |
932 | ||
933 | if (adjust_stack_p) | |
934 | { | |
0a81f074 RS |
935 | src = plus_constant (Pmode, base, |
936 | (count | |
937 | * GET_MODE_SIZE (mode) | |
938 | * (HOST_WIDE_INT) (store_p ? -1 : 1))); | |
a40ed0f3 KH |
939 | XVECEXP (body, 0, i++) = gen_rtx_SET (VOIDmode, base, src); |
940 | } | |
941 | ||
942 | for (; mask != 0; mask >>= 1, regno++) | |
943 | if (mask & 1) | |
944 | { | |
0a81f074 | 945 | addr = plus_constant (Pmode, base, offset); |
a40ed0f3 KH |
946 | operands[!store_p] = gen_frame_mem (mode, addr); |
947 | operands[store_p] = gen_rtx_REG (mode, regno); | |
948 | XVECEXP (body, 0, i++) | |
949 | = gen_rtx_SET (VOIDmode, operands[0], operands[1]); | |
950 | offset += GET_MODE_SIZE (mode); | |
951 | } | |
952 | gcc_assert (i == XVECLEN (body, 0)); | |
953 | ||
954 | return emit_insn (body); | |
955 | } | |
956 | ||
957 | /* Make INSN a frame-related instruction. */ | |
79e68feb | 958 | |
08c148a8 | 959 | static void |
c85e862a | 960 | m68k_set_frame_related (rtx_insn *insn) |
a40ed0f3 KH |
961 | { |
962 | rtx body; | |
963 | int i; | |
964 | ||
965 | RTX_FRAME_RELATED_P (insn) = 1; | |
966 | body = PATTERN (insn); | |
967 | if (GET_CODE (body) == PARALLEL) | |
968 | for (i = 0; i < XVECLEN (body, 0); i++) | |
969 | RTX_FRAME_RELATED_P (XVECEXP (body, 0, i)) = 1; | |
970 | } | |
971 | ||
972 | /* Emit RTL for the "prologue" define_expand. */ | |
973 | ||
974 | void | |
975 | m68k_expand_prologue (void) | |
79e68feb | 976 | { |
860c4900 | 977 | HOST_WIDE_INT fsize_with_regs; |
2dc8bd76 | 978 | rtx limit, src, dest; |
3d74bc09 | 979 | |
a40ed0f3 | 980 | m68k_compute_frame_layout (); |
3d74bc09 | 981 | |
a11e0df4 | 982 | if (flag_stack_usage_info) |
f69ea688 AS |
983 | current_function_static_stack_size |
984 | = current_frame.size + current_frame.offset; | |
985 | ||
a157febd GK |
986 | /* If the stack limit is a symbol, we can check it here, |
987 | before actually allocating the space. */ | |
e3b5732b | 988 | if (crtl->limit_stack |
a157febd | 989 | && GET_CODE (stack_limit_rtx) == SYMBOL_REF) |
a40ed0f3 | 990 | { |
0a81f074 | 991 | limit = plus_constant (Pmode, stack_limit_rtx, current_frame.size + 4); |
1a627b35 | 992 | if (!m68k_legitimate_constant_p (Pmode, limit)) |
a40ed0f3 KH |
993 | { |
994 | emit_move_insn (gen_rtx_REG (Pmode, D0_REG), limit); | |
995 | limit = gen_rtx_REG (Pmode, D0_REG); | |
996 | } | |
f90b7a5a PB |
997 | emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode, |
998 | stack_pointer_rtx, limit), | |
999 | stack_pointer_rtx, limit, | |
1000 | const1_rtx)); | |
a40ed0f3 | 1001 | } |
79e68feb | 1002 | |
a89e3f21 | 1003 | fsize_with_regs = current_frame.size; |
dcc21c4c PB |
1004 | if (TARGET_COLDFIRE) |
1005 | { | |
a40ed0f3 KH |
1006 | /* ColdFire's move multiple instructions do not allow pre-decrement |
1007 | addressing. Add the size of movem saves to the initial stack | |
1008 | allocation instead. */ | |
1009 | if (current_frame.reg_no >= MIN_MOVEM_REGS) | |
1010 | fsize_with_regs += current_frame.reg_no * GET_MODE_SIZE (SImode); | |
1011 | if (current_frame.fpu_no >= MIN_FMOVEM_REGS) | |
1012 | fsize_with_regs += current_frame.fpu_no * GET_MODE_SIZE (DFmode); | |
dcc21c4c | 1013 | } |
860c4900 | 1014 | |
79e68feb RS |
1015 | if (frame_pointer_needed) |
1016 | { | |
a40ed0f3 | 1017 | if (fsize_with_regs == 0 && TUNE_68040) |
79e68feb | 1018 | { |
a40ed0f3 KH |
1019 | /* On the 68040, two separate moves are faster than link.w 0. */ |
1020 | dest = gen_frame_mem (Pmode, | |
1021 | gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)); | |
1022 | m68k_set_frame_related (emit_move_insn (dest, frame_pointer_rtx)); | |
1023 | m68k_set_frame_related (emit_move_insn (frame_pointer_rtx, | |
1024 | stack_pointer_rtx)); | |
79e68feb | 1025 | } |
a40ed0f3 KH |
1026 | else if (fsize_with_regs < 0x8000 || TARGET_68020) |
1027 | m68k_set_frame_related | |
1028 | (emit_insn (gen_link (frame_pointer_rtx, | |
1029 | GEN_INT (-4 - fsize_with_regs)))); | |
d9e88af0 | 1030 | else |
a40ed0f3 KH |
1031 | { |
1032 | m68k_set_frame_related | |
1033 | (emit_insn (gen_link (frame_pointer_rtx, GEN_INT (-4)))); | |
1034 | m68k_set_frame_related | |
1035 | (emit_insn (gen_addsi3 (stack_pointer_rtx, | |
1036 | stack_pointer_rtx, | |
1037 | GEN_INT (-fsize_with_regs)))); | |
1038 | } | |
96fcacb7 MK |
1039 | |
1040 | /* If the frame pointer is needed, emit a special barrier that | |
1041 | will prevent the scheduler from moving stores to the frame | |
1042 | before the stack adjustment. */ | |
1043 | emit_insn (gen_stack_tie (stack_pointer_rtx, frame_pointer_rtx)); | |
d9e88af0 | 1044 | } |
a40ed0f3 KH |
1045 | else if (fsize_with_regs != 0) |
1046 | m68k_set_frame_related | |
1047 | (emit_insn (gen_addsi3 (stack_pointer_rtx, | |
1048 | stack_pointer_rtx, | |
1049 | GEN_INT (-fsize_with_regs)))); | |
860c4900 | 1050 | |
57047680 | 1051 | if (current_frame.fpu_mask) |
79e68feb | 1052 | { |
a40ed0f3 | 1053 | gcc_assert (current_frame.fpu_no >= MIN_FMOVEM_REGS); |
dcc21c4c | 1054 | if (TARGET_68881) |
a40ed0f3 KH |
1055 | m68k_set_frame_related |
1056 | (m68k_emit_movem (stack_pointer_rtx, | |
1057 | current_frame.fpu_no * -GET_MODE_SIZE (XFmode), | |
1058 | current_frame.fpu_no, FP0_REG, | |
1059 | current_frame.fpu_mask, true, true)); | |
dcc21c4c PB |
1060 | else |
1061 | { | |
1062 | int offset; | |
1063 | ||
a40ed0f3 KH |
1064 | /* If we're using moveml to save the integer registers, |
1065 | the stack pointer will point to the bottom of the moveml | |
1066 | save area. Find the stack offset of the first FP register. */ | |
1067 | if (current_frame.reg_no < MIN_MOVEM_REGS) | |
dcc21c4c PB |
1068 | offset = 0; |
1069 | else | |
a40ed0f3 KH |
1070 | offset = current_frame.reg_no * GET_MODE_SIZE (SImode); |
1071 | m68k_set_frame_related | |
1072 | (m68k_emit_movem (stack_pointer_rtx, offset, | |
1073 | current_frame.fpu_no, FP0_REG, | |
1074 | current_frame.fpu_mask, true, false)); | |
f277471f | 1075 | } |
79e68feb | 1076 | } |
99df2465 | 1077 | |
01bbf777 | 1078 | /* If the stack limit is not a symbol, check it here. |
a157febd | 1079 | This has the disadvantage that it may be too late... */ |
e3b5732b | 1080 | if (crtl->limit_stack) |
a157febd GK |
1081 | { |
1082 | if (REG_P (stack_limit_rtx)) | |
f90b7a5a PB |
1083 | emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode, stack_pointer_rtx, |
1084 | stack_limit_rtx), | |
1085 | stack_pointer_rtx, stack_limit_rtx, | |
1086 | const1_rtx)); | |
1087 | ||
a157febd | 1088 | else if (GET_CODE (stack_limit_rtx) != SYMBOL_REF) |
d4ee4d25 | 1089 | warning (0, "stack limit expression is not supported"); |
a157febd | 1090 | } |
01bbf777 | 1091 | |
a40ed0f3 | 1092 | if (current_frame.reg_no < MIN_MOVEM_REGS) |
79e68feb | 1093 | { |
a40ed0f3 | 1094 | /* Store each register separately in the same order moveml does. */ |
79e68feb RS |
1095 | int i; |
1096 | ||
a40ed0f3 KH |
1097 | for (i = 16; i-- > 0; ) |
1098 | if (current_frame.reg_mask & (1 << i)) | |
078e983e | 1099 | { |
a40ed0f3 KH |
1100 | src = gen_rtx_REG (SImode, D0_REG + i); |
1101 | dest = gen_frame_mem (SImode, | |
1102 | gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)); | |
1103 | m68k_set_frame_related (emit_insn (gen_movsi (dest, src))); | |
078e983e | 1104 | } |
79e68feb | 1105 | } |
a40ed0f3 | 1106 | else |
79e68feb | 1107 | { |
9425fb04 | 1108 | if (TARGET_COLDFIRE) |
a40ed0f3 KH |
1109 | /* The required register save space has already been allocated. |
1110 | The first register should be stored at (%sp). */ | |
1111 | m68k_set_frame_related | |
1112 | (m68k_emit_movem (stack_pointer_rtx, 0, | |
1113 | current_frame.reg_no, D0_REG, | |
1114 | current_frame.reg_mask, true, false)); | |
afaff477 | 1115 | else |
a40ed0f3 KH |
1116 | m68k_set_frame_related |
1117 | (m68k_emit_movem (stack_pointer_rtx, | |
1118 | current_frame.reg_no * -GET_MODE_SIZE (SImode), | |
1119 | current_frame.reg_no, D0_REG, | |
1120 | current_frame.reg_mask, true, true)); | |
79e68feb | 1121 | } |
a40ed0f3 | 1122 | |
75df395f | 1123 | if (!TARGET_SEP_DATA |
e3b5732b | 1124 | && crtl->uses_pic_offset_table) |
2dc8bd76 | 1125 | emit_insn (gen_load_got (pic_offset_table_rtx)); |
79e68feb RS |
1126 | } |
1127 | \f | |
413ac1b2 RS |
1128 | /* Return true if a simple (return) instruction is sufficient for this |
1129 | instruction (i.e. if no epilogue is needed). */ | |
79e68feb | 1130 | |
3d74bc09 | 1131 | bool |
a2bda628 | 1132 | m68k_use_return_insn (void) |
79e68feb | 1133 | { |
79e68feb | 1134 | if (!reload_completed || frame_pointer_needed || get_frame_size () != 0) |
3d74bc09 | 1135 | return false; |
125ed86f | 1136 | |
a0a7fbc9 | 1137 | m68k_compute_frame_layout (); |
413ac1b2 | 1138 | return current_frame.offset == 0; |
79e68feb RS |
1139 | } |
1140 | ||
f7e70894 RS |
1141 | /* Emit RTL for the "epilogue" or "sibcall_epilogue" define_expand; |
1142 | SIBCALL_P says which. | |
79e68feb RS |
1143 | |
1144 | The function epilogue should not depend on the current stack pointer! | |
1145 | It should use the frame pointer only, if there is a frame pointer. | |
1146 | This is mandatory because of alloca; we also take advantage of it to | |
1147 | omit stack adjustments before returning. */ | |
1148 | ||
a40ed0f3 | 1149 | void |
f7e70894 | 1150 | m68k_expand_epilogue (bool sibcall_p) |
08c148a8 | 1151 | { |
3d74bc09 | 1152 | HOST_WIDE_INT fsize, fsize_with_regs; |
a40ed0f3 | 1153 | bool big, restore_from_sp; |
3d74bc09 | 1154 | |
a0a7fbc9 | 1155 | m68k_compute_frame_layout (); |
3d74bc09 | 1156 | |
3d74bc09 | 1157 | fsize = current_frame.size; |
a40ed0f3 KH |
1158 | big = false; |
1159 | restore_from_sp = false; | |
3d74bc09 | 1160 | |
416ff32e | 1161 | /* FIXME : crtl->is_leaf below is too strong. |
c67ddce5 | 1162 | What we really need to know there is if there could be pending |
7a1929e1 | 1163 | stack adjustment needed at that point. */ |
a40ed0f3 | 1164 | restore_from_sp = (!frame_pointer_needed |
416ff32e | 1165 | || (!cfun->calls_alloca && crtl->is_leaf)); |
860c4900 BI |
1166 | |
1167 | /* fsize_with_regs is the size we need to adjust the sp when | |
97c55091 | 1168 | popping the frame. */ |
860c4900 | 1169 | fsize_with_regs = fsize; |
dcc21c4c PB |
1170 | if (TARGET_COLDFIRE && restore_from_sp) |
1171 | { | |
a40ed0f3 KH |
1172 | /* ColdFire's move multiple instructions do not allow post-increment |
1173 | addressing. Add the size of movem loads to the final deallocation | |
1174 | instead. */ | |
1175 | if (current_frame.reg_no >= MIN_MOVEM_REGS) | |
1176 | fsize_with_regs += current_frame.reg_no * GET_MODE_SIZE (SImode); | |
1177 | if (current_frame.fpu_no >= MIN_FMOVEM_REGS) | |
1178 | fsize_with_regs += current_frame.fpu_no * GET_MODE_SIZE (DFmode); | |
dcc21c4c | 1179 | } |
860c4900 | 1180 | |
3d74bc09 | 1181 | if (current_frame.offset + fsize >= 0x8000 |
a40ed0f3 | 1182 | && !restore_from_sp |
3d74bc09 | 1183 | && (current_frame.reg_mask || current_frame.fpu_mask)) |
79e68feb | 1184 | { |
a40ed0f3 KH |
1185 | if (TARGET_COLDFIRE |
1186 | && (current_frame.reg_no >= MIN_MOVEM_REGS | |
1187 | || current_frame.fpu_no >= MIN_FMOVEM_REGS)) | |
1188 | { | |
1189 | /* ColdFire's move multiple instructions do not support the | |
1190 | (d8,Ax,Xi) addressing mode, so we're as well using a normal | |
1191 | stack-based restore. */ | |
1192 | emit_move_insn (gen_rtx_REG (Pmode, A1_REG), | |
1193 | GEN_INT (-(current_frame.offset + fsize))); | |
1194 | emit_insn (gen_addsi3 (stack_pointer_rtx, | |
1195 | gen_rtx_REG (Pmode, A1_REG), | |
1196 | frame_pointer_rtx)); | |
1197 | restore_from_sp = true; | |
1198 | } | |
1199 | else | |
1200 | { | |
1201 | emit_move_insn (gen_rtx_REG (Pmode, A1_REG), GEN_INT (-fsize)); | |
1202 | fsize = 0; | |
1203 | big = true; | |
1204 | } | |
79e68feb | 1205 | } |
79e68feb | 1206 | |
a40ed0f3 KH |
1207 | if (current_frame.reg_no < MIN_MOVEM_REGS) |
1208 | { | |
1209 | /* Restore each register separately in the same order moveml does. */ | |
79e68feb | 1210 | int i; |
a40ed0f3 | 1211 | HOST_WIDE_INT offset; |
79e68feb | 1212 | |
a40ed0f3 | 1213 | offset = current_frame.offset + fsize; |
3d74bc09 BI |
1214 | for (i = 0; i < 16; i++) |
1215 | if (current_frame.reg_mask & (1 << i)) | |
79e68feb | 1216 | { |
a40ed0f3 KH |
1217 | rtx addr; |
1218 | ||
1219 | if (big) | |
79e68feb | 1220 | { |
a40ed0f3 KH |
1221 | /* Generate the address -OFFSET(%fp,%a1.l). */ |
1222 | addr = gen_rtx_REG (Pmode, A1_REG); | |
1223 | addr = gen_rtx_PLUS (Pmode, addr, frame_pointer_rtx); | |
0a81f074 | 1224 | addr = plus_constant (Pmode, addr, -offset); |
79e68feb | 1225 | } |
a40ed0f3 KH |
1226 | else if (restore_from_sp) |
1227 | addr = gen_rtx_POST_INC (Pmode, stack_pointer_rtx); | |
1228 | else | |
0a81f074 | 1229 | addr = plus_constant (Pmode, frame_pointer_rtx, -offset); |
a40ed0f3 KH |
1230 | emit_move_insn (gen_rtx_REG (SImode, D0_REG + i), |
1231 | gen_frame_mem (SImode, addr)); | |
1232 | offset -= GET_MODE_SIZE (SImode); | |
1233 | } | |
79e68feb | 1234 | } |
3d74bc09 | 1235 | else if (current_frame.reg_mask) |
79e68feb | 1236 | { |
a40ed0f3 KH |
1237 | if (big) |
1238 | m68k_emit_movem (gen_rtx_PLUS (Pmode, | |
1239 | gen_rtx_REG (Pmode, A1_REG), | |
1240 | frame_pointer_rtx), | |
1241 | -(current_frame.offset + fsize), | |
1242 | current_frame.reg_no, D0_REG, | |
1243 | current_frame.reg_mask, false, false); | |
1244 | else if (restore_from_sp) | |
1245 | m68k_emit_movem (stack_pointer_rtx, 0, | |
1246 | current_frame.reg_no, D0_REG, | |
1247 | current_frame.reg_mask, false, | |
1248 | !TARGET_COLDFIRE); | |
1249 | else | |
1250 | m68k_emit_movem (frame_pointer_rtx, | |
1251 | -(current_frame.offset + fsize), | |
1252 | current_frame.reg_no, D0_REG, | |
1253 | current_frame.reg_mask, false, false); | |
79e68feb | 1254 | } |
a40ed0f3 KH |
1255 | |
1256 | if (current_frame.fpu_no > 0) | |
79e68feb RS |
1257 | { |
1258 | if (big) | |
a40ed0f3 KH |
1259 | m68k_emit_movem (gen_rtx_PLUS (Pmode, |
1260 | gen_rtx_REG (Pmode, A1_REG), | |
1261 | frame_pointer_rtx), | |
1262 | -(current_frame.foffset + fsize), | |
1263 | current_frame.fpu_no, FP0_REG, | |
1264 | current_frame.fpu_mask, false, false); | |
6910dd70 | 1265 | else if (restore_from_sp) |
79e68feb | 1266 | { |
dcc21c4c PB |
1267 | if (TARGET_COLDFIRE) |
1268 | { | |
1269 | int offset; | |
1270 | ||
a40ed0f3 KH |
1271 | /* If we used moveml to restore the integer registers, the |
1272 | stack pointer will still point to the bottom of the moveml | |
1273 | save area. Find the stack offset of the first FP | |
1274 | register. */ | |
1275 | if (current_frame.reg_no < MIN_MOVEM_REGS) | |
dcc21c4c PB |
1276 | offset = 0; |
1277 | else | |
a40ed0f3 KH |
1278 | offset = current_frame.reg_no * GET_MODE_SIZE (SImode); |
1279 | m68k_emit_movem (stack_pointer_rtx, offset, | |
1280 | current_frame.fpu_no, FP0_REG, | |
1281 | current_frame.fpu_mask, false, false); | |
dcc21c4c | 1282 | } |
884b74f0 | 1283 | else |
a40ed0f3 KH |
1284 | m68k_emit_movem (stack_pointer_rtx, 0, |
1285 | current_frame.fpu_no, FP0_REG, | |
1286 | current_frame.fpu_mask, false, true); | |
79e68feb RS |
1287 | } |
1288 | else | |
a40ed0f3 KH |
1289 | m68k_emit_movem (frame_pointer_rtx, |
1290 | -(current_frame.foffset + fsize), | |
1291 | current_frame.fpu_no, FP0_REG, | |
1292 | current_frame.fpu_mask, false, false); | |
79e68feb | 1293 | } |
a40ed0f3 | 1294 | |
79e68feb | 1295 | if (frame_pointer_needed) |
a40ed0f3 | 1296 | emit_insn (gen_unlink (frame_pointer_rtx)); |
860c4900 | 1297 | else if (fsize_with_regs) |
a40ed0f3 KH |
1298 | emit_insn (gen_addsi3 (stack_pointer_rtx, |
1299 | stack_pointer_rtx, | |
1300 | GEN_INT (fsize_with_regs))); | |
1301 | ||
e3b5732b | 1302 | if (crtl->calls_eh_return) |
a40ed0f3 KH |
1303 | emit_insn (gen_addsi3 (stack_pointer_rtx, |
1304 | stack_pointer_rtx, | |
1305 | EH_RETURN_STACKADJ_RTX)); | |
1306 | ||
f7e70894 | 1307 | if (!sibcall_p) |
3810076b | 1308 | emit_jump_insn (ret_rtx); |
79e68feb RS |
1309 | } |
1310 | \f | |
8a4a2253 | 1311 | /* Return true if X is a valid comparison operator for the dbcc |
64a184e9 RS |
1312 | instruction. |
1313 | ||
1314 | Note it rejects floating point comparison operators. | |
1315 | (In the future we could use Fdbcc). | |
1316 | ||
1317 | It also rejects some comparisons when CC_NO_OVERFLOW is set. */ | |
1318 | ||
1319 | int | |
41b6a5e2 | 1320 | valid_dbcc_comparison_p_2 (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED) |
64a184e9 | 1321 | { |
64a184e9 RS |
1322 | switch (GET_CODE (x)) |
1323 | { | |
64a184e9 RS |
1324 | case EQ: case NE: case GTU: case LTU: |
1325 | case GEU: case LEU: | |
1326 | return 1; | |
1327 | ||
1328 | /* Reject some when CC_NO_OVERFLOW is set. This may be over | |
1329 | conservative */ | |
1330 | case GT: case LT: case GE: case LE: | |
1331 | return ! (cc_prev_status.flags & CC_NO_OVERFLOW); | |
1332 | default: | |
1333 | return 0; | |
1334 | } | |
1335 | } | |
1336 | ||
a0ab749a | 1337 | /* Return nonzero if flags are currently in the 68881 flag register. */ |
6a0f85e3 | 1338 | int |
8a4a2253 | 1339 | flags_in_68881 (void) |
6a0f85e3 TG |
1340 | { |
1341 | /* We could add support for these in the future */ | |
1342 | return cc_status.flags & CC_IN_68881; | |
1343 | } | |
1344 | ||
db5e2d51 MK |
1345 | /* Return true if PARALLEL contains register REGNO. */ |
1346 | static bool | |
1347 | m68k_reg_present_p (const_rtx parallel, unsigned int regno) | |
1348 | { | |
1349 | int i; | |
1350 | ||
1351 | if (REG_P (parallel) && REGNO (parallel) == regno) | |
1352 | return true; | |
1353 | ||
1354 | if (GET_CODE (parallel) != PARALLEL) | |
1355 | return false; | |
1356 | ||
1357 | for (i = 0; i < XVECLEN (parallel, 0); ++i) | |
1358 | { | |
1359 | const_rtx x; | |
1360 | ||
1361 | x = XEXP (XVECEXP (parallel, 0, i), 0); | |
1362 | if (REG_P (x) && REGNO (x) == regno) | |
1363 | return true; | |
1364 | } | |
1365 | ||
1366 | return false; | |
1367 | } | |
1368 | ||
fa157b28 | 1369 | /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL_P. */ |
f7e70894 RS |
1370 | |
1371 | static bool | |
fa157b28 | 1372 | m68k_ok_for_sibcall_p (tree decl, tree exp) |
f7e70894 | 1373 | { |
fa157b28 NS |
1374 | enum m68k_function_kind kind; |
1375 | ||
1376 | /* We cannot use sibcalls for nested functions because we use the | |
1377 | static chain register for indirect calls. */ | |
1378 | if (CALL_EXPR_STATIC_CHAIN (exp)) | |
1379 | return false; | |
1380 | ||
db5e2d51 MK |
1381 | if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl)))) |
1382 | { | |
1383 | /* Check that the return value locations are the same. For | |
1384 | example that we aren't returning a value from the sibling in | |
1385 | a D0 register but then need to transfer it to a A0 register. */ | |
1386 | rtx cfun_value; | |
1387 | rtx call_value; | |
1388 | ||
1389 | cfun_value = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (cfun->decl)), | |
1390 | cfun->decl); | |
1391 | call_value = FUNCTION_VALUE (TREE_TYPE (exp), decl); | |
1392 | ||
1393 | /* Check that the values are equal or that the result the callee | |
1394 | function returns is superset of what the current function returns. */ | |
1395 | if (!(rtx_equal_p (cfun_value, call_value) | |
1396 | || (REG_P (cfun_value) | |
1397 | && m68k_reg_present_p (call_value, REGNO (cfun_value))))) | |
1398 | return false; | |
1399 | } | |
1400 | ||
fa157b28 NS |
1401 | kind = m68k_get_function_kind (current_function_decl); |
1402 | if (kind == m68k_fk_normal_function) | |
1403 | /* We can always sibcall from a normal function, because it's | |
1404 | undefined if it is calling an interrupt function. */ | |
1405 | return true; | |
1406 | ||
1407 | /* Otherwise we can only sibcall if the function kind is known to be | |
1408 | the same. */ | |
1409 | if (decl && m68k_get_function_kind (decl) == kind) | |
1410 | return true; | |
1411 | ||
1412 | return false; | |
f7e70894 RS |
1413 | } |
1414 | ||
13d3961c NF |
1415 | /* On the m68k all args are always pushed. */ |
1416 | ||
1417 | static rtx | |
d5cc9181 | 1418 | m68k_function_arg (cumulative_args_t cum ATTRIBUTE_UNUSED, |
13d3961c NF |
1419 | enum machine_mode mode ATTRIBUTE_UNUSED, |
1420 | const_tree type ATTRIBUTE_UNUSED, | |
1421 | bool named ATTRIBUTE_UNUSED) | |
1422 | { | |
1423 | return NULL_RTX; | |
1424 | } | |
1425 | ||
1426 | static void | |
d5cc9181 | 1427 | m68k_function_arg_advance (cumulative_args_t cum_v, enum machine_mode mode, |
13d3961c NF |
1428 | const_tree type, bool named ATTRIBUTE_UNUSED) |
1429 | { | |
d5cc9181 JR |
1430 | CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); |
1431 | ||
13d3961c NF |
1432 | *cum += (mode != BLKmode |
1433 | ? (GET_MODE_SIZE (mode) + 3) & ~3 | |
1434 | : (int_size_in_bytes (type) + 3) & ~3); | |
1435 | } | |
1436 | ||
29ca003a RS |
1437 | /* Convert X to a legitimate function call memory reference and return the |
1438 | result. */ | |
a2ef3db7 | 1439 | |
29ca003a RS |
1440 | rtx |
1441 | m68k_legitimize_call_address (rtx x) | |
1442 | { | |
1443 | gcc_assert (MEM_P (x)); | |
1444 | if (call_operand (XEXP (x, 0), VOIDmode)) | |
1445 | return x; | |
1446 | return replace_equiv_address (x, force_reg (Pmode, XEXP (x, 0))); | |
a2ef3db7 BI |
1447 | } |
1448 | ||
f7e70894 RS |
1449 | /* Likewise for sibling calls. */ |
1450 | ||
1451 | rtx | |
1452 | m68k_legitimize_sibcall_address (rtx x) | |
1453 | { | |
1454 | gcc_assert (MEM_P (x)); | |
1455 | if (sibcall_operand (XEXP (x, 0), VOIDmode)) | |
1456 | return x; | |
1457 | ||
1458 | emit_move_insn (gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM), XEXP (x, 0)); | |
1459 | return replace_equiv_address (x, gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM)); | |
1460 | } | |
1461 | ||
506d7b68 PB |
1462 | /* Convert X to a legitimate address and return it if successful. Otherwise |
1463 | return X. | |
1464 | ||
1465 | For the 68000, we handle X+REG by loading X into a register R and | |
1466 | using R+REG. R will go in an address reg and indexing will be used. | |
1467 | However, if REG is a broken-out memory address or multiplication, | |
1468 | nothing needs to be done because REG can certainly go in an address reg. */ | |
1469 | ||
ab7256e4 | 1470 | static rtx |
506d7b68 PB |
1471 | m68k_legitimize_address (rtx x, rtx oldx, enum machine_mode mode) |
1472 | { | |
75df395f MK |
1473 | if (m68k_tls_symbol_p (x)) |
1474 | return m68k_legitimize_tls_address (x); | |
1475 | ||
506d7b68 PB |
1476 | if (GET_CODE (x) == PLUS) |
1477 | { | |
1478 | int ch = (x) != (oldx); | |
1479 | int copied = 0; | |
1480 | ||
1481 | #define COPY_ONCE(Y) if (!copied) { Y = copy_rtx (Y); copied = ch = 1; } | |
1482 | ||
1483 | if (GET_CODE (XEXP (x, 0)) == MULT) | |
1484 | { | |
1485 | COPY_ONCE (x); | |
1486 | XEXP (x, 0) = force_operand (XEXP (x, 0), 0); | |
1487 | } | |
1488 | if (GET_CODE (XEXP (x, 1)) == MULT) | |
1489 | { | |
1490 | COPY_ONCE (x); | |
1491 | XEXP (x, 1) = force_operand (XEXP (x, 1), 0); | |
1492 | } | |
1493 | if (ch) | |
1494 | { | |
1495 | if (GET_CODE (XEXP (x, 1)) == REG | |
1496 | && GET_CODE (XEXP (x, 0)) == REG) | |
1497 | { | |
1498 | if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT) | |
1499 | { | |
1500 | COPY_ONCE (x); | |
1501 | x = force_operand (x, 0); | |
1502 | } | |
1503 | return x; | |
1504 | } | |
1505 | if (memory_address_p (mode, x)) | |
1506 | return x; | |
1507 | } | |
1508 | if (GET_CODE (XEXP (x, 0)) == REG | |
1509 | || (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND | |
1510 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
1511 | && GET_MODE (XEXP (XEXP (x, 0), 0)) == HImode)) | |
1512 | { | |
1513 | rtx temp = gen_reg_rtx (Pmode); | |
1514 | rtx val = force_operand (XEXP (x, 1), 0); | |
1515 | emit_move_insn (temp, val); | |
1516 | COPY_ONCE (x); | |
1517 | XEXP (x, 1) = temp; | |
1518 | if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT | |
1519 | && GET_CODE (XEXP (x, 0)) == REG) | |
1520 | x = force_operand (x, 0); | |
1521 | } | |
1522 | else if (GET_CODE (XEXP (x, 1)) == REG | |
1523 | || (GET_CODE (XEXP (x, 1)) == SIGN_EXTEND | |
1524 | && GET_CODE (XEXP (XEXP (x, 1), 0)) == REG | |
1525 | && GET_MODE (XEXP (XEXP (x, 1), 0)) == HImode)) | |
1526 | { | |
1527 | rtx temp = gen_reg_rtx (Pmode); | |
1528 | rtx val = force_operand (XEXP (x, 0), 0); | |
1529 | emit_move_insn (temp, val); | |
1530 | COPY_ONCE (x); | |
1531 | XEXP (x, 0) = temp; | |
1532 | if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT | |
1533 | && GET_CODE (XEXP (x, 1)) == REG) | |
1534 | x = force_operand (x, 0); | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | return x; | |
1539 | } | |
1540 | ||
1541 | ||
64a184e9 RS |
1542 | /* Output a dbCC; jCC sequence. Note we do not handle the |
1543 | floating point version of this sequence (Fdbcc). We also | |
1544 | do not handle alternative conditions when CC_NO_OVERFLOW is | |
6a0f85e3 TG |
1545 | set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will |
1546 | kick those out before we get here. */ | |
64a184e9 | 1547 | |
1d8eaa6b | 1548 | void |
8a4a2253 | 1549 | output_dbcc_and_branch (rtx *operands) |
64a184e9 | 1550 | { |
64a184e9 RS |
1551 | switch (GET_CODE (operands[3])) |
1552 | { | |
1553 | case EQ: | |
da398bb5 | 1554 | output_asm_insn ("dbeq %0,%l1\n\tjeq %l2", operands); |
e6d98cb0 | 1555 | break; |
64a184e9 RS |
1556 | |
1557 | case NE: | |
da398bb5 | 1558 | output_asm_insn ("dbne %0,%l1\n\tjne %l2", operands); |
e6d98cb0 | 1559 | break; |
64a184e9 RS |
1560 | |
1561 | case GT: | |
da398bb5 | 1562 | output_asm_insn ("dbgt %0,%l1\n\tjgt %l2", operands); |
e6d98cb0 | 1563 | break; |
64a184e9 RS |
1564 | |
1565 | case GTU: | |
da398bb5 | 1566 | output_asm_insn ("dbhi %0,%l1\n\tjhi %l2", operands); |
e6d98cb0 | 1567 | break; |
64a184e9 RS |
1568 | |
1569 | case LT: | |
da398bb5 | 1570 | output_asm_insn ("dblt %0,%l1\n\tjlt %l2", operands); |
e6d98cb0 | 1571 | break; |
64a184e9 RS |
1572 | |
1573 | case LTU: | |
da398bb5 | 1574 | output_asm_insn ("dbcs %0,%l1\n\tjcs %l2", operands); |
e6d98cb0 | 1575 | break; |
64a184e9 RS |
1576 | |
1577 | case GE: | |
da398bb5 | 1578 | output_asm_insn ("dbge %0,%l1\n\tjge %l2", operands); |
e6d98cb0 | 1579 | break; |
64a184e9 RS |
1580 | |
1581 | case GEU: | |
da398bb5 | 1582 | output_asm_insn ("dbcc %0,%l1\n\tjcc %l2", operands); |
e6d98cb0 | 1583 | break; |
64a184e9 RS |
1584 | |
1585 | case LE: | |
da398bb5 | 1586 | output_asm_insn ("dble %0,%l1\n\tjle %l2", operands); |
e6d98cb0 | 1587 | break; |
64a184e9 RS |
1588 | |
1589 | case LEU: | |
da398bb5 | 1590 | output_asm_insn ("dbls %0,%l1\n\tjls %l2", operands); |
e6d98cb0 | 1591 | break; |
64a184e9 RS |
1592 | |
1593 | default: | |
4761e388 | 1594 | gcc_unreachable (); |
64a184e9 RS |
1595 | } |
1596 | ||
1597 | /* If the decrement is to be done in SImode, then we have | |
7a1929e1 | 1598 | to compensate for the fact that dbcc decrements in HImode. */ |
64a184e9 RS |
1599 | switch (GET_MODE (operands[0])) |
1600 | { | |
1601 | case SImode: | |
da398bb5 | 1602 | output_asm_insn ("clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1", operands); |
64a184e9 RS |
1603 | break; |
1604 | ||
1605 | case HImode: | |
1606 | break; | |
1607 | ||
1608 | default: | |
4761e388 | 1609 | gcc_unreachable (); |
64a184e9 RS |
1610 | } |
1611 | } | |
1612 | ||
5505f548 | 1613 | const char * |
4761e388 | 1614 | output_scc_di (rtx op, rtx operand1, rtx operand2, rtx dest) |
c59c3b1c RK |
1615 | { |
1616 | rtx loperands[7]; | |
d9832fd2 | 1617 | enum rtx_code op_code = GET_CODE (op); |
c59c3b1c | 1618 | |
f710504c | 1619 | /* This does not produce a useful cc. */ |
906a2d3c RK |
1620 | CC_STATUS_INIT; |
1621 | ||
d9832fd2 RK |
1622 | /* The m68k cmp.l instruction requires operand1 to be a reg as used |
1623 | below. Swap the operands and change the op if these requirements | |
1624 | are not fulfilled. */ | |
1625 | if (GET_CODE (operand2) == REG && GET_CODE (operand1) != REG) | |
1626 | { | |
1627 | rtx tmp = operand1; | |
1628 | ||
1629 | operand1 = operand2; | |
1630 | operand2 = tmp; | |
1631 | op_code = swap_condition (op_code); | |
1632 | } | |
c59c3b1c RK |
1633 | loperands[0] = operand1; |
1634 | if (GET_CODE (operand1) == REG) | |
1d8eaa6b | 1635 | loperands[1] = gen_rtx_REG (SImode, REGNO (operand1) + 1); |
c59c3b1c | 1636 | else |
b72f00af | 1637 | loperands[1] = adjust_address (operand1, SImode, 4); |
c59c3b1c RK |
1638 | if (operand2 != const0_rtx) |
1639 | { | |
1640 | loperands[2] = operand2; | |
1641 | if (GET_CODE (operand2) == REG) | |
1d8eaa6b | 1642 | loperands[3] = gen_rtx_REG (SImode, REGNO (operand2) + 1); |
c59c3b1c | 1643 | else |
b72f00af | 1644 | loperands[3] = adjust_address (operand2, SImode, 4); |
c59c3b1c | 1645 | } |
428511bb | 1646 | loperands[4] = gen_label_rtx (); |
c59c3b1c | 1647 | if (operand2 != const0_rtx) |
da398bb5 | 1648 | output_asm_insn ("cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1", loperands); |
392582fa | 1649 | else |
4a8c52e0 | 1650 | { |
9425fb04 | 1651 | if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[0])) |
4a8c52e0 AS |
1652 | output_asm_insn ("tst%.l %0", loperands); |
1653 | else | |
a0a7fbc9 | 1654 | output_asm_insn ("cmp%.w #0,%0", loperands); |
4a8c52e0 | 1655 | |
da398bb5 | 1656 | output_asm_insn ("jne %l4", loperands); |
4a8c52e0 | 1657 | |
9425fb04 | 1658 | if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[1])) |
4a8c52e0 AS |
1659 | output_asm_insn ("tst%.l %1", loperands); |
1660 | else | |
3b4b85c9 | 1661 | output_asm_insn ("cmp%.w #0,%1", loperands); |
4a8c52e0 AS |
1662 | } |
1663 | ||
c59c3b1c | 1664 | loperands[5] = dest; |
3b4b85c9 | 1665 | |
d9832fd2 | 1666 | switch (op_code) |
c59c3b1c RK |
1667 | { |
1668 | case EQ: | |
4977bab6 | 1669 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1670 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c RK |
1671 | output_asm_insn ("seq %5", loperands); |
1672 | break; | |
1673 | ||
1674 | case NE: | |
4977bab6 | 1675 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1676 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c RK |
1677 | output_asm_insn ("sne %5", loperands); |
1678 | break; | |
1679 | ||
1680 | case GT: | |
428511bb | 1681 | loperands[6] = gen_label_rtx (); |
da398bb5 | 1682 | output_asm_insn ("shi %5\n\tjra %l6", loperands); |
4977bab6 | 1683 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1684 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c | 1685 | output_asm_insn ("sgt %5", loperands); |
4977bab6 | 1686 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1687 | CODE_LABEL_NUMBER (loperands[6])); |
c59c3b1c RK |
1688 | break; |
1689 | ||
1690 | case GTU: | |
4977bab6 | 1691 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1692 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c RK |
1693 | output_asm_insn ("shi %5", loperands); |
1694 | break; | |
1695 | ||
1696 | case LT: | |
428511bb | 1697 | loperands[6] = gen_label_rtx (); |
da398bb5 | 1698 | output_asm_insn ("scs %5\n\tjra %l6", loperands); |
4977bab6 | 1699 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1700 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c | 1701 | output_asm_insn ("slt %5", loperands); |
4977bab6 | 1702 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1703 | CODE_LABEL_NUMBER (loperands[6])); |
c59c3b1c RK |
1704 | break; |
1705 | ||
1706 | case LTU: | |
4977bab6 | 1707 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1708 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c RK |
1709 | output_asm_insn ("scs %5", loperands); |
1710 | break; | |
1711 | ||
1712 | case GE: | |
428511bb | 1713 | loperands[6] = gen_label_rtx (); |
da398bb5 | 1714 | output_asm_insn ("scc %5\n\tjra %l6", loperands); |
4977bab6 | 1715 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1716 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c | 1717 | output_asm_insn ("sge %5", loperands); |
4977bab6 | 1718 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1719 | CODE_LABEL_NUMBER (loperands[6])); |
c59c3b1c RK |
1720 | break; |
1721 | ||
1722 | case GEU: | |
4977bab6 | 1723 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1724 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c RK |
1725 | output_asm_insn ("scc %5", loperands); |
1726 | break; | |
1727 | ||
1728 | case LE: | |
428511bb | 1729 | loperands[6] = gen_label_rtx (); |
da398bb5 | 1730 | output_asm_insn ("sls %5\n\tjra %l6", loperands); |
4977bab6 | 1731 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1732 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c | 1733 | output_asm_insn ("sle %5", loperands); |
4977bab6 | 1734 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1735 | CODE_LABEL_NUMBER (loperands[6])); |
c59c3b1c RK |
1736 | break; |
1737 | ||
1738 | case LEU: | |
4977bab6 | 1739 | (*targetm.asm_out.internal_label) (asm_out_file, "L", |
a0a7fbc9 | 1740 | CODE_LABEL_NUMBER (loperands[4])); |
c59c3b1c RK |
1741 | output_asm_insn ("sls %5", loperands); |
1742 | break; | |
1743 | ||
1744 | default: | |
4761e388 | 1745 | gcc_unreachable (); |
c59c3b1c RK |
1746 | } |
1747 | return ""; | |
1748 | } | |
1749 | ||
5505f548 | 1750 | const char * |
c85e862a | 1751 | output_btst (rtx *operands, rtx countop, rtx dataop, rtx_insn *insn, int signpos) |
79e68feb RS |
1752 | { |
1753 | operands[0] = countop; | |
1754 | operands[1] = dataop; | |
1755 | ||
1756 | if (GET_CODE (countop) == CONST_INT) | |
1757 | { | |
1758 | register int count = INTVAL (countop); | |
1759 | /* If COUNT is bigger than size of storage unit in use, | |
1760 | advance to the containing unit of same size. */ | |
1761 | if (count > signpos) | |
1762 | { | |
1763 | int offset = (count & ~signpos) / 8; | |
1764 | count = count & signpos; | |
b72f00af | 1765 | operands[1] = dataop = adjust_address (dataop, QImode, offset); |
79e68feb RS |
1766 | } |
1767 | if (count == signpos) | |
1768 | cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N; | |
1769 | else | |
1770 | cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N; | |
1771 | ||
1772 | /* These three statements used to use next_insns_test_no... | |
1773 | but it appears that this should do the same job. */ | |
1774 | if (count == 31 | |
1775 | && next_insn_tests_no_inequality (insn)) | |
1776 | return "tst%.l %1"; | |
1777 | if (count == 15 | |
1778 | && next_insn_tests_no_inequality (insn)) | |
1779 | return "tst%.w %1"; | |
1780 | if (count == 7 | |
1781 | && next_insn_tests_no_inequality (insn)) | |
1782 | return "tst%.b %1"; | |
5083912d PDM |
1783 | /* Try to use `movew to ccr' followed by the appropriate branch insn. |
1784 | On some m68k variants unfortunately that's slower than btst. | |
1785 | On 68000 and higher, that should also work for all HImode operands. */ | |
1786 | if (TUNE_CPU32 || TARGET_COLDFIRE || optimize_size) | |
1787 | { | |
1788 | if (count == 3 && DATA_REG_P (operands[1]) | |
1789 | && next_insn_tests_no_inequality (insn)) | |
1790 | { | |
1791 | cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N | CC_NO_OVERFLOW; | |
1792 | return "move%.w %1,%%ccr"; | |
1793 | } | |
1794 | if (count == 2 && DATA_REG_P (operands[1]) | |
1795 | && next_insn_tests_no_inequality (insn)) | |
1796 | { | |
1797 | cc_status.flags = CC_NOT_NEGATIVE | CC_INVERTED | CC_NO_OVERFLOW; | |
1798 | return "move%.w %1,%%ccr"; | |
1799 | } | |
1800 | /* count == 1 followed by bvc/bvs and | |
1801 | count == 0 followed by bcc/bcs are also possible, but need | |
1802 | m68k-specific CC_Z_IN_NOT_V and CC_Z_IN_NOT_C flags. */ | |
1803 | } | |
79e68feb RS |
1804 | |
1805 | cc_status.flags = CC_NOT_NEGATIVE; | |
1806 | } | |
1807 | return "btst %0,%1"; | |
1808 | } | |
79e68feb | 1809 | \f |
fc2241eb RS |
1810 | /* Return true if X is a legitimate base register. STRICT_P says |
1811 | whether we need strict checking. */ | |
1812 | ||
1813 | bool | |
1814 | m68k_legitimate_base_reg_p (rtx x, bool strict_p) | |
1815 | { | |
1816 | /* Allow SUBREG everywhere we allow REG. This results in better code. */ | |
1817 | if (!strict_p && GET_CODE (x) == SUBREG) | |
1818 | x = SUBREG_REG (x); | |
1819 | ||
1820 | return (REG_P (x) | |
1821 | && (strict_p | |
1822 | ? REGNO_OK_FOR_BASE_P (REGNO (x)) | |
bf32249e | 1823 | : REGNO_OK_FOR_BASE_NONSTRICT_P (REGNO (x)))); |
fc2241eb RS |
1824 | } |
1825 | ||
1826 | /* Return true if X is a legitimate index register. STRICT_P says | |
1827 | whether we need strict checking. */ | |
1828 | ||
1829 | bool | |
1830 | m68k_legitimate_index_reg_p (rtx x, bool strict_p) | |
1831 | { | |
1832 | if (!strict_p && GET_CODE (x) == SUBREG) | |
1833 | x = SUBREG_REG (x); | |
1834 | ||
1835 | return (REG_P (x) | |
1836 | && (strict_p | |
1837 | ? REGNO_OK_FOR_INDEX_P (REGNO (x)) | |
bf32249e | 1838 | : REGNO_OK_FOR_INDEX_NONSTRICT_P (REGNO (x)))); |
fc2241eb RS |
1839 | } |
1840 | ||
1841 | /* Return true if X is a legitimate index expression for a (d8,An,Xn) or | |
1842 | (bd,An,Xn) addressing mode. Fill in the INDEX and SCALE fields of | |
1843 | ADDRESS if so. STRICT_P says whether we need strict checking. */ | |
1844 | ||
1845 | static bool | |
1846 | m68k_decompose_index (rtx x, bool strict_p, struct m68k_address *address) | |
1847 | { | |
1848 | int scale; | |
1849 | ||
1850 | /* Check for a scale factor. */ | |
1851 | scale = 1; | |
1852 | if ((TARGET_68020 || TARGET_COLDFIRE) | |
1853 | && GET_CODE (x) == MULT | |
1854 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1855 | && (INTVAL (XEXP (x, 1)) == 2 | |
1856 | || INTVAL (XEXP (x, 1)) == 4 | |
1857 | || (INTVAL (XEXP (x, 1)) == 8 | |
1858 | && (TARGET_COLDFIRE_FPU || !TARGET_COLDFIRE)))) | |
1859 | { | |
1860 | scale = INTVAL (XEXP (x, 1)); | |
1861 | x = XEXP (x, 0); | |
1862 | } | |
1863 | ||
1864 | /* Check for a word extension. */ | |
1865 | if (!TARGET_COLDFIRE | |
1866 | && GET_CODE (x) == SIGN_EXTEND | |
1867 | && GET_MODE (XEXP (x, 0)) == HImode) | |
1868 | x = XEXP (x, 0); | |
1869 | ||
1870 | if (m68k_legitimate_index_reg_p (x, strict_p)) | |
1871 | { | |
1872 | address->scale = scale; | |
1873 | address->index = x; | |
1874 | return true; | |
1875 | } | |
1876 | ||
1877 | return false; | |
1878 | } | |
1879 | ||
7ffb5e78 RS |
1880 | /* Return true if X is an illegitimate symbolic constant. */ |
1881 | ||
1882 | bool | |
1883 | m68k_illegitimate_symbolic_constant_p (rtx x) | |
1884 | { | |
1885 | rtx base, offset; | |
1886 | ||
1887 | if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P) | |
1888 | { | |
1889 | split_const (x, &base, &offset); | |
1890 | if (GET_CODE (base) == SYMBOL_REF | |
1891 | && !offset_within_block_p (base, INTVAL (offset))) | |
1892 | return true; | |
1893 | } | |
75df395f | 1894 | return m68k_tls_reference_p (x, false); |
7ffb5e78 RS |
1895 | } |
1896 | ||
fbbf66e7 RS |
1897 | /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */ |
1898 | ||
1899 | static bool | |
1900 | m68k_cannot_force_const_mem (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x) | |
1901 | { | |
1902 | return m68k_illegitimate_symbolic_constant_p (x); | |
1903 | } | |
1904 | ||
fc2241eb RS |
1905 | /* Return true if X is a legitimate constant address that can reach |
1906 | bytes in the range [X, X + REACH). STRICT_P says whether we need | |
1907 | strict checking. */ | |
1908 | ||
1909 | static bool | |
1910 | m68k_legitimate_constant_address_p (rtx x, unsigned int reach, bool strict_p) | |
1911 | { | |
1912 | rtx base, offset; | |
1913 | ||
1914 | if (!CONSTANT_ADDRESS_P (x)) | |
1915 | return false; | |
1916 | ||
1917 | if (flag_pic | |
1918 | && !(strict_p && TARGET_PCREL) | |
1919 | && symbolic_operand (x, VOIDmode)) | |
1920 | return false; | |
1921 | ||
1922 | if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P && reach > 1) | |
1923 | { | |
1924 | split_const (x, &base, &offset); | |
1925 | if (GET_CODE (base) == SYMBOL_REF | |
1926 | && !offset_within_block_p (base, INTVAL (offset) + reach - 1)) | |
1927 | return false; | |
1928 | } | |
1929 | ||
75df395f | 1930 | return !m68k_tls_reference_p (x, false); |
fc2241eb RS |
1931 | } |
1932 | ||
1933 | /* Return true if X is a LABEL_REF for a jump table. Assume that unplaced | |
1934 | labels will become jump tables. */ | |
1935 | ||
1936 | static bool | |
1937 | m68k_jump_table_ref_p (rtx x) | |
1938 | { | |
1939 | if (GET_CODE (x) != LABEL_REF) | |
1940 | return false; | |
1941 | ||
b32d5189 DM |
1942 | rtx_insn *insn = as_a <rtx_insn *> (XEXP (x, 0)); |
1943 | if (!NEXT_INSN (insn) && !PREV_INSN (insn)) | |
fc2241eb RS |
1944 | return true; |
1945 | ||
b32d5189 DM |
1946 | insn = next_nonnote_insn (insn); |
1947 | return insn && JUMP_TABLE_DATA_P (insn); | |
fc2241eb RS |
1948 | } |
1949 | ||
1950 | /* Return true if X is a legitimate address for values of mode MODE. | |
1951 | STRICT_P says whether strict checking is needed. If the address | |
1952 | is valid, describe its components in *ADDRESS. */ | |
1953 | ||
1954 | static bool | |
1955 | m68k_decompose_address (enum machine_mode mode, rtx x, | |
1956 | bool strict_p, struct m68k_address *address) | |
1957 | { | |
1958 | unsigned int reach; | |
1959 | ||
1960 | memset (address, 0, sizeof (*address)); | |
1961 | ||
1962 | if (mode == BLKmode) | |
1963 | reach = 1; | |
1964 | else | |
1965 | reach = GET_MODE_SIZE (mode); | |
1966 | ||
1967 | /* Check for (An) (mode 2). */ | |
1968 | if (m68k_legitimate_base_reg_p (x, strict_p)) | |
1969 | { | |
1970 | address->base = x; | |
1971 | return true; | |
1972 | } | |
1973 | ||
1974 | /* Check for -(An) and (An)+ (modes 3 and 4). */ | |
1975 | if ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_INC) | |
1976 | && m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p)) | |
1977 | { | |
1978 | address->code = GET_CODE (x); | |
1979 | address->base = XEXP (x, 0); | |
1980 | return true; | |
1981 | } | |
1982 | ||
1983 | /* Check for (d16,An) (mode 5). */ | |
1984 | if (GET_CODE (x) == PLUS | |
1985 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1986 | && IN_RANGE (INTVAL (XEXP (x, 1)), -0x8000, 0x8000 - reach) | |
1987 | && m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p)) | |
1988 | { | |
1989 | address->base = XEXP (x, 0); | |
1990 | address->offset = XEXP (x, 1); | |
1991 | return true; | |
1992 | } | |
1993 | ||
1994 | /* Check for GOT loads. These are (bd,An,Xn) addresses if | |
1995 | TARGET_68020 && flag_pic == 2, otherwise they are (d16,An) | |
1996 | addresses. */ | |
75df395f MK |
1997 | if (GET_CODE (x) == PLUS |
1998 | && XEXP (x, 0) == pic_offset_table_rtx) | |
fc2241eb | 1999 | { |
75df395f MK |
2000 | /* As we are processing a PLUS, do not unwrap RELOC32 symbols -- |
2001 | they are invalid in this context. */ | |
2002 | if (m68k_unwrap_symbol (XEXP (x, 1), false) != XEXP (x, 1)) | |
2003 | { | |
2004 | address->base = XEXP (x, 0); | |
2005 | address->offset = XEXP (x, 1); | |
2006 | return true; | |
2007 | } | |
fc2241eb RS |
2008 | } |
2009 | ||
2010 | /* The ColdFire FPU only accepts addressing modes 2-5. */ | |
2011 | if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT) | |
2012 | return false; | |
2013 | ||
2014 | /* Check for (xxx).w and (xxx).l. Also, in the TARGET_PCREL case, | |
2015 | check for (d16,PC) or (bd,PC,Xn) with a suppressed index register. | |
2016 | All these modes are variations of mode 7. */ | |
2017 | if (m68k_legitimate_constant_address_p (x, reach, strict_p)) | |
2018 | { | |
2019 | address->offset = x; | |
2020 | return true; | |
2021 | } | |
2022 | ||
2023 | /* Check for (d8,PC,Xn), a mode 7 form. This case is needed for | |
2024 | tablejumps. | |
2025 | ||
2026 | ??? do_tablejump creates these addresses before placing the target | |
2027 | label, so we have to assume that unplaced labels are jump table | |
2028 | references. It seems unlikely that we would ever generate indexed | |
2029 | accesses to unplaced labels in other cases. */ | |
2030 | if (GET_CODE (x) == PLUS | |
2031 | && m68k_jump_table_ref_p (XEXP (x, 1)) | |
2032 | && m68k_decompose_index (XEXP (x, 0), strict_p, address)) | |
2033 | { | |
2034 | address->offset = XEXP (x, 1); | |
2035 | return true; | |
2036 | } | |
2037 | ||
2038 | /* Everything hereafter deals with (d8,An,Xn.SIZE*SCALE) or | |
2039 | (bd,An,Xn.SIZE*SCALE) addresses. */ | |
2040 | ||
2041 | if (TARGET_68020) | |
2042 | { | |
2043 | /* Check for a nonzero base displacement. */ | |
2044 | if (GET_CODE (x) == PLUS | |
2045 | && m68k_legitimate_constant_address_p (XEXP (x, 1), reach, strict_p)) | |
2046 | { | |
2047 | address->offset = XEXP (x, 1); | |
2048 | x = XEXP (x, 0); | |
2049 | } | |
2050 | ||
2051 | /* Check for a suppressed index register. */ | |
2052 | if (m68k_legitimate_base_reg_p (x, strict_p)) | |
2053 | { | |
2054 | address->base = x; | |
2055 | return true; | |
2056 | } | |
2057 | ||
2058 | /* Check for a suppressed base register. Do not allow this case | |
2059 | for non-symbolic offsets as it effectively gives gcc freedom | |
2060 | to treat data registers as base registers, which can generate | |
2061 | worse code. */ | |
2062 | if (address->offset | |
2063 | && symbolic_operand (address->offset, VOIDmode) | |
2064 | && m68k_decompose_index (x, strict_p, address)) | |
2065 | return true; | |
2066 | } | |
2067 | else | |
2068 | { | |
2069 | /* Check for a nonzero base displacement. */ | |
2070 | if (GET_CODE (x) == PLUS | |
2071 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2072 | && IN_RANGE (INTVAL (XEXP (x, 1)), -0x80, 0x80 - reach)) | |
2073 | { | |
2074 | address->offset = XEXP (x, 1); | |
2075 | x = XEXP (x, 0); | |
2076 | } | |
2077 | } | |
2078 | ||
2079 | /* We now expect the sum of a base and an index. */ | |
2080 | if (GET_CODE (x) == PLUS) | |
2081 | { | |
2082 | if (m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p) | |
2083 | && m68k_decompose_index (XEXP (x, 1), strict_p, address)) | |
2084 | { | |
2085 | address->base = XEXP (x, 0); | |
2086 | return true; | |
2087 | } | |
2088 | ||
2089 | if (m68k_legitimate_base_reg_p (XEXP (x, 1), strict_p) | |
2090 | && m68k_decompose_index (XEXP (x, 0), strict_p, address)) | |
2091 | { | |
2092 | address->base = XEXP (x, 1); | |
2093 | return true; | |
2094 | } | |
2095 | } | |
2096 | return false; | |
2097 | } | |
2098 | ||
2099 | /* Return true if X is a legitimate address for values of mode MODE. | |
2100 | STRICT_P says whether strict checking is needed. */ | |
2101 | ||
2102 | bool | |
2103 | m68k_legitimate_address_p (enum machine_mode mode, rtx x, bool strict_p) | |
2104 | { | |
2105 | struct m68k_address address; | |
2106 | ||
2107 | return m68k_decompose_address (mode, x, strict_p, &address); | |
2108 | } | |
2109 | ||
2110 | /* Return true if X is a memory, describing its address in ADDRESS if so. | |
2111 | Apply strict checking if called during or after reload. */ | |
2112 | ||
2113 | static bool | |
2114 | m68k_legitimate_mem_p (rtx x, struct m68k_address *address) | |
2115 | { | |
2116 | return (MEM_P (x) | |
2117 | && m68k_decompose_address (GET_MODE (x), XEXP (x, 0), | |
2118 | reload_in_progress || reload_completed, | |
2119 | address)); | |
2120 | } | |
2121 | ||
1a627b35 RS |
2122 | /* Implement TARGET_LEGITIMATE_CONSTANT_P. */ |
2123 | ||
2124 | bool | |
2125 | m68k_legitimate_constant_p (enum machine_mode mode, rtx x) | |
2126 | { | |
2127 | return mode != XFmode && !m68k_illegitimate_symbolic_constant_p (x); | |
2128 | } | |
2129 | ||
fc2241eb RS |
2130 | /* Return true if X matches the 'Q' constraint. It must be a memory |
2131 | with a base address and no constant offset or index. */ | |
2132 | ||
2133 | bool | |
2134 | m68k_matches_q_p (rtx x) | |
2135 | { | |
2136 | struct m68k_address address; | |
2137 | ||
2138 | return (m68k_legitimate_mem_p (x, &address) | |
2139 | && address.code == UNKNOWN | |
2140 | && address.base | |
2141 | && !address.offset | |
2142 | && !address.index); | |
2143 | } | |
2144 | ||
2145 | /* Return true if X matches the 'U' constraint. It must be a base address | |
2146 | with a constant offset and no index. */ | |
2147 | ||
2148 | bool | |
2149 | m68k_matches_u_p (rtx x) | |
2150 | { | |
2151 | struct m68k_address address; | |
2152 | ||
2153 | return (m68k_legitimate_mem_p (x, &address) | |
2154 | && address.code == UNKNOWN | |
2155 | && address.base | |
2156 | && address.offset | |
2157 | && !address.index); | |
2158 | } | |
2159 | ||
75df395f MK |
2160 | /* Return GOT pointer. */ |
2161 | ||
2162 | static rtx | |
2163 | m68k_get_gp (void) | |
2164 | { | |
2165 | if (pic_offset_table_rtx == NULL_RTX) | |
2166 | pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_REG); | |
2167 | ||
2168 | crtl->uses_pic_offset_table = 1; | |
2169 | ||
2170 | return pic_offset_table_rtx; | |
2171 | } | |
2172 | ||
2173 | /* M68K relocations, used to distinguish GOT and TLS relocations in UNSPEC | |
2174 | wrappers. */ | |
2175 | enum m68k_reloc { RELOC_GOT, RELOC_TLSGD, RELOC_TLSLDM, RELOC_TLSLDO, | |
2176 | RELOC_TLSIE, RELOC_TLSLE }; | |
2177 | ||
2178 | #define TLS_RELOC_P(RELOC) ((RELOC) != RELOC_GOT) | |
2179 | ||
2180 | /* Wrap symbol X into unspec representing relocation RELOC. | |
2181 | BASE_REG - register that should be added to the result. | |
2182 | TEMP_REG - if non-null, temporary register. */ | |
2183 | ||
2184 | static rtx | |
2185 | m68k_wrap_symbol (rtx x, enum m68k_reloc reloc, rtx base_reg, rtx temp_reg) | |
2186 | { | |
2187 | bool use_x_p; | |
2188 | ||
2189 | use_x_p = (base_reg == pic_offset_table_rtx) ? TARGET_XGOT : TARGET_XTLS; | |
2190 | ||
2191 | if (TARGET_COLDFIRE && use_x_p) | |
2192 | /* When compiling with -mx{got, tls} switch the code will look like this: | |
2193 | ||
2194 | move.l <X>@<RELOC>,<TEMP_REG> | |
2195 | add.l <BASE_REG>,<TEMP_REG> */ | |
2196 | { | |
2197 | /* Wrap X in UNSPEC_??? to tip m68k_output_addr_const_extra | |
2198 | to put @RELOC after reference. */ | |
2199 | x = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)), | |
2200 | UNSPEC_RELOC32); | |
2201 | x = gen_rtx_CONST (Pmode, x); | |
2202 | ||
2203 | if (temp_reg == NULL) | |
2204 | { | |
2205 | gcc_assert (can_create_pseudo_p ()); | |
2206 | temp_reg = gen_reg_rtx (Pmode); | |
2207 | } | |
2208 | ||
2209 | emit_move_insn (temp_reg, x); | |
2210 | emit_insn (gen_addsi3 (temp_reg, temp_reg, base_reg)); | |
2211 | x = temp_reg; | |
2212 | } | |
2213 | else | |
2214 | { | |
2215 | x = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)), | |
2216 | UNSPEC_RELOC16); | |
2217 | x = gen_rtx_CONST (Pmode, x); | |
2218 | ||
2219 | x = gen_rtx_PLUS (Pmode, base_reg, x); | |
2220 | } | |
2221 | ||
2222 | return x; | |
2223 | } | |
2224 | ||
2225 | /* Helper for m68k_unwrap_symbol. | |
2226 | Also, if unwrapping was successful (that is if (ORIG != <return value>)), | |
2227 | sets *RELOC_PTR to relocation type for the symbol. */ | |
2228 | ||
2229 | static rtx | |
2230 | m68k_unwrap_symbol_1 (rtx orig, bool unwrap_reloc32_p, | |
2231 | enum m68k_reloc *reloc_ptr) | |
2232 | { | |
2233 | if (GET_CODE (orig) == CONST) | |
2234 | { | |
2235 | rtx x; | |
2236 | enum m68k_reloc dummy; | |
2237 | ||
2238 | x = XEXP (orig, 0); | |
2239 | ||
2240 | if (reloc_ptr == NULL) | |
2241 | reloc_ptr = &dummy; | |
2242 | ||
2243 | /* Handle an addend. */ | |
2244 | if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS) | |
2245 | && CONST_INT_P (XEXP (x, 1))) | |
2246 | x = XEXP (x, 0); | |
2247 | ||
2248 | if (GET_CODE (x) == UNSPEC) | |
2249 | { | |
2250 | switch (XINT (x, 1)) | |
2251 | { | |
2252 | case UNSPEC_RELOC16: | |
2253 | orig = XVECEXP (x, 0, 0); | |
2254 | *reloc_ptr = (enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1)); | |
2255 | break; | |
2256 | ||
2257 | case UNSPEC_RELOC32: | |
2258 | if (unwrap_reloc32_p) | |
2259 | { | |
2260 | orig = XVECEXP (x, 0, 0); | |
2261 | *reloc_ptr = (enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1)); | |
2262 | } | |
2263 | break; | |
2264 | ||
2265 | default: | |
2266 | break; | |
2267 | } | |
2268 | } | |
2269 | } | |
2270 | ||
2271 | return orig; | |
2272 | } | |
2273 | ||
2274 | /* Unwrap symbol from UNSPEC_RELOC16 and, if unwrap_reloc32_p, | |
2275 | UNSPEC_RELOC32 wrappers. */ | |
2276 | ||
2277 | rtx | |
2278 | m68k_unwrap_symbol (rtx orig, bool unwrap_reloc32_p) | |
2279 | { | |
2280 | return m68k_unwrap_symbol_1 (orig, unwrap_reloc32_p, NULL); | |
2281 | } | |
2282 | ||
75df395f MK |
2283 | /* Prescan insn before outputing assembler for it. */ |
2284 | ||
2285 | void | |
c85e862a | 2286 | m68k_final_prescan_insn (rtx_insn *insn ATTRIBUTE_UNUSED, |
75df395f MK |
2287 | rtx *operands, int n_operands) |
2288 | { | |
2289 | int i; | |
2290 | ||
2291 | /* Combine and, possibly, other optimizations may do good job | |
2292 | converting | |
2293 | (const (unspec [(symbol)])) | |
2294 | into | |
2295 | (const (plus (unspec [(symbol)]) | |
2296 | (const_int N))). | |
2297 | The problem with this is emitting @TLS or @GOT decorations. | |
2298 | The decoration is emitted when processing (unspec), so the | |
2299 | result would be "#symbol@TLSLE+N" instead of "#symbol+N@TLSLE". | |
2300 | ||
2301 | It seems that the easiest solution to this is to convert such | |
2302 | operands to | |
2303 | (const (unspec [(plus (symbol) | |
2304 | (const_int N))])). | |
2305 | Note, that the top level of operand remains intact, so we don't have | |
2306 | to patch up anything outside of the operand. */ | |
2307 | ||
82eee4f1 | 2308 | subrtx_var_iterator::array_type array; |
75df395f MK |
2309 | for (i = 0; i < n_operands; ++i) |
2310 | { | |
2311 | rtx op; | |
2312 | ||
2313 | op = operands[i]; | |
2314 | ||
82eee4f1 RS |
2315 | FOR_EACH_SUBRTX_VAR (iter, array, op, ALL) |
2316 | { | |
2317 | rtx x = *iter; | |
2318 | if (m68k_unwrap_symbol (x, true) != x) | |
2319 | { | |
2320 | rtx plus; | |
2321 | ||
2322 | gcc_assert (GET_CODE (x) == CONST); | |
2323 | plus = XEXP (x, 0); | |
2324 | ||
2325 | if (GET_CODE (plus) == PLUS || GET_CODE (plus) == MINUS) | |
2326 | { | |
2327 | rtx unspec; | |
2328 | rtx addend; | |
2329 | ||
2330 | unspec = XEXP (plus, 0); | |
2331 | gcc_assert (GET_CODE (unspec) == UNSPEC); | |
2332 | addend = XEXP (plus, 1); | |
2333 | gcc_assert (CONST_INT_P (addend)); | |
2334 | ||
2335 | /* We now have all the pieces, rearrange them. */ | |
2336 | ||
2337 | /* Move symbol to plus. */ | |
2338 | XEXP (plus, 0) = XVECEXP (unspec, 0, 0); | |
2339 | ||
2340 | /* Move plus inside unspec. */ | |
2341 | XVECEXP (unspec, 0, 0) = plus; | |
2342 | ||
2343 | /* Move unspec to top level of const. */ | |
2344 | XEXP (x, 0) = unspec; | |
2345 | } | |
2346 | iter.skip_subrtxes (); | |
2347 | } | |
2348 | } | |
75df395f MK |
2349 | } |
2350 | } | |
2351 | ||
2352 | /* Move X to a register and add REG_EQUAL note pointing to ORIG. | |
2353 | If REG is non-null, use it; generate new pseudo otherwise. */ | |
2354 | ||
2355 | static rtx | |
2356 | m68k_move_to_reg (rtx x, rtx orig, rtx reg) | |
2357 | { | |
c85e862a | 2358 | rtx_insn *insn; |
75df395f MK |
2359 | |
2360 | if (reg == NULL_RTX) | |
2361 | { | |
2362 | gcc_assert (can_create_pseudo_p ()); | |
2363 | reg = gen_reg_rtx (Pmode); | |
2364 | } | |
2365 | ||
2366 | insn = emit_move_insn (reg, x); | |
2367 | /* Put a REG_EQUAL note on this insn, so that it can be optimized | |
2368 | by loop. */ | |
2369 | set_unique_reg_note (insn, REG_EQUAL, orig); | |
2370 | ||
2371 | return reg; | |
2372 | } | |
2373 | ||
2374 | /* Does the same as m68k_wrap_symbol, but returns a memory reference to | |
2375 | GOT slot. */ | |
2376 | ||
2377 | static rtx | |
2378 | m68k_wrap_symbol_into_got_ref (rtx x, enum m68k_reloc reloc, rtx temp_reg) | |
2379 | { | |
2380 | x = m68k_wrap_symbol (x, reloc, m68k_get_gp (), temp_reg); | |
2381 | ||
2382 | x = gen_rtx_MEM (Pmode, x); | |
2383 | MEM_READONLY_P (x) = 1; | |
2384 | ||
2385 | return x; | |
2386 | } | |
2387 | ||
79e68feb RS |
2388 | /* Legitimize PIC addresses. If the address is already |
2389 | position-independent, we return ORIG. Newly generated | |
2390 | position-independent addresses go to REG. If we need more | |
2391 | than one register, we lose. | |
2392 | ||
2393 | An address is legitimized by making an indirect reference | |
2394 | through the Global Offset Table with the name of the symbol | |
2395 | used as an offset. | |
2396 | ||
2397 | The assembler and linker are responsible for placing the | |
2398 | address of the symbol in the GOT. The function prologue | |
2399 | is responsible for initializing a5 to the starting address | |
2400 | of the GOT. | |
2401 | ||
2402 | The assembler is also responsible for translating a symbol name | |
2403 | into a constant displacement from the start of the GOT. | |
2404 | ||
2405 | A quick example may make things a little clearer: | |
2406 | ||
2407 | When not generating PIC code to store the value 12345 into _foo | |
2408 | we would generate the following code: | |
2409 | ||
2410 | movel #12345, _foo | |
2411 | ||
2412 | When generating PIC two transformations are made. First, the compiler | |
2413 | loads the address of foo into a register. So the first transformation makes: | |
2414 | ||
2415 | lea _foo, a0 | |
2416 | movel #12345, a0@ | |
2417 | ||
2418 | The code in movsi will intercept the lea instruction and call this | |
2419 | routine which will transform the instructions into: | |
2420 | ||
2421 | movel a5@(_foo:w), a0 | |
2422 | movel #12345, a0@ | |
2423 | ||
2424 | ||
2425 | That (in a nutshell) is how *all* symbol and label references are | |
2426 | handled. */ | |
2427 | ||
2428 | rtx | |
8a4a2253 BI |
2429 | legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED, |
2430 | rtx reg) | |
79e68feb RS |
2431 | { |
2432 | rtx pic_ref = orig; | |
2433 | ||
2434 | /* First handle a simple SYMBOL_REF or LABEL_REF */ | |
2435 | if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF) | |
2436 | { | |
4761e388 | 2437 | gcc_assert (reg); |
79e68feb | 2438 | |
75df395f MK |
2439 | pic_ref = m68k_wrap_symbol_into_got_ref (orig, RELOC_GOT, reg); |
2440 | pic_ref = m68k_move_to_reg (pic_ref, orig, reg); | |
79e68feb RS |
2441 | } |
2442 | else if (GET_CODE (orig) == CONST) | |
2443 | { | |
1d8eaa6b | 2444 | rtx base; |
79e68feb | 2445 | |
b2e08ed4 | 2446 | /* Make sure this has not already been legitimized. */ |
75df395f | 2447 | if (m68k_unwrap_symbol (orig, true) != orig) |
79e68feb RS |
2448 | return orig; |
2449 | ||
4761e388 | 2450 | gcc_assert (reg); |
79e68feb RS |
2451 | |
2452 | /* legitimize both operands of the PLUS */ | |
4761e388 NS |
2453 | gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS); |
2454 | ||
2455 | base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg); | |
2456 | orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, | |
2457 | base == reg ? 0 : reg); | |
79e68feb RS |
2458 | |
2459 | if (GET_CODE (orig) == CONST_INT) | |
0a81f074 | 2460 | pic_ref = plus_constant (Pmode, base, INTVAL (orig)); |
75df395f MK |
2461 | else |
2462 | pic_ref = gen_rtx_PLUS (Pmode, base, orig); | |
79e68feb | 2463 | } |
75df395f | 2464 | |
79e68feb RS |
2465 | return pic_ref; |
2466 | } | |
2467 | ||
75df395f MK |
2468 | /* The __tls_get_addr symbol. */ |
2469 | static GTY(()) rtx m68k_tls_get_addr; | |
2470 | ||
2471 | /* Return SYMBOL_REF for __tls_get_addr. */ | |
2472 | ||
2473 | static rtx | |
2474 | m68k_get_tls_get_addr (void) | |
2475 | { | |
2476 | if (m68k_tls_get_addr == NULL_RTX) | |
2477 | m68k_tls_get_addr = init_one_libfunc ("__tls_get_addr"); | |
2478 | ||
2479 | return m68k_tls_get_addr; | |
2480 | } | |
2481 | ||
2482 | /* Return libcall result in A0 instead of usual D0. */ | |
2483 | static bool m68k_libcall_value_in_a0_p = false; | |
2484 | ||
2485 | /* Emit instruction sequence that calls __tls_get_addr. X is | |
2486 | the TLS symbol we are referencing and RELOC is the symbol type to use | |
2487 | (either TLSGD or TLSLDM). EQV is the REG_EQUAL note for the sequence | |
2488 | emitted. A pseudo register with result of __tls_get_addr call is | |
2489 | returned. */ | |
2490 | ||
2491 | static rtx | |
2492 | m68k_call_tls_get_addr (rtx x, rtx eqv, enum m68k_reloc reloc) | |
2493 | { | |
2494 | rtx a0; | |
c85e862a | 2495 | rtx_insn *insns; |
75df395f MK |
2496 | rtx dest; |
2497 | ||
2498 | /* Emit the call sequence. */ | |
2499 | start_sequence (); | |
2500 | ||
2501 | /* FIXME: Unfortunately, emit_library_call_value does not | |
2502 | consider (plus (%a5) (const (unspec))) to be a good enough | |
2503 | operand for push, so it forces it into a register. The bad | |
2504 | thing about this is that combiner, due to copy propagation and other | |
2505 | optimizations, sometimes can not later fix this. As a consequence, | |
2506 | additional register may be allocated resulting in a spill. | |
2507 | For reference, see args processing loops in | |
2508 | calls.c:emit_library_call_value_1. | |
2509 | For testcase, see gcc.target/m68k/tls-{gd, ld}.c */ | |
2510 | x = m68k_wrap_symbol (x, reloc, m68k_get_gp (), NULL_RTX); | |
2511 | ||
2512 | /* __tls_get_addr() is not a libcall, but emitting a libcall_value | |
2513 | is the simpliest way of generating a call. The difference between | |
2514 | __tls_get_addr() and libcall is that the result is returned in D0 | |
2515 | instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p | |
2516 | which temporarily switches returning the result to A0. */ | |
2517 | ||
2518 | m68k_libcall_value_in_a0_p = true; | |
2519 | a0 = emit_library_call_value (m68k_get_tls_get_addr (), NULL_RTX, LCT_PURE, | |
2520 | Pmode, 1, x, Pmode); | |
2521 | m68k_libcall_value_in_a0_p = false; | |
2522 | ||
2523 | insns = get_insns (); | |
2524 | end_sequence (); | |
2525 | ||
2526 | gcc_assert (can_create_pseudo_p ()); | |
2527 | dest = gen_reg_rtx (Pmode); | |
2528 | emit_libcall_block (insns, dest, a0, eqv); | |
2529 | ||
2530 | return dest; | |
2531 | } | |
2532 | ||
2533 | /* The __tls_get_addr symbol. */ | |
2534 | static GTY(()) rtx m68k_read_tp; | |
2535 | ||
2536 | /* Return SYMBOL_REF for __m68k_read_tp. */ | |
2537 | ||
2538 | static rtx | |
2539 | m68k_get_m68k_read_tp (void) | |
2540 | { | |
2541 | if (m68k_read_tp == NULL_RTX) | |
2542 | m68k_read_tp = init_one_libfunc ("__m68k_read_tp"); | |
2543 | ||
2544 | return m68k_read_tp; | |
2545 | } | |
2546 | ||
2547 | /* Emit instruction sequence that calls __m68k_read_tp. | |
2548 | A pseudo register with result of __m68k_read_tp call is returned. */ | |
2549 | ||
2550 | static rtx | |
2551 | m68k_call_m68k_read_tp (void) | |
2552 | { | |
2553 | rtx a0; | |
2554 | rtx eqv; | |
c85e862a | 2555 | rtx_insn *insns; |
75df395f MK |
2556 | rtx dest; |
2557 | ||
2558 | start_sequence (); | |
2559 | ||
2560 | /* __m68k_read_tp() is not a libcall, but emitting a libcall_value | |
2561 | is the simpliest way of generating a call. The difference between | |
2562 | __m68k_read_tp() and libcall is that the result is returned in D0 | |
2563 | instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p | |
2564 | which temporarily switches returning the result to A0. */ | |
2565 | ||
2566 | /* Emit the call sequence. */ | |
2567 | m68k_libcall_value_in_a0_p = true; | |
2568 | a0 = emit_library_call_value (m68k_get_m68k_read_tp (), NULL_RTX, LCT_PURE, | |
2569 | Pmode, 0); | |
2570 | m68k_libcall_value_in_a0_p = false; | |
2571 | insns = get_insns (); | |
2572 | end_sequence (); | |
2573 | ||
2574 | /* Attach a unique REG_EQUIV, to allow the RTL optimizers to | |
2575 | share the m68k_read_tp result with other IE/LE model accesses. */ | |
2576 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), UNSPEC_RELOC32); | |
2577 | ||
2578 | gcc_assert (can_create_pseudo_p ()); | |
2579 | dest = gen_reg_rtx (Pmode); | |
2580 | emit_libcall_block (insns, dest, a0, eqv); | |
2581 | ||
2582 | return dest; | |
2583 | } | |
2584 | ||
2585 | /* Return a legitimized address for accessing TLS SYMBOL_REF X. | |
2586 | For explanations on instructions sequences see TLS/NPTL ABI for m68k and | |
2587 | ColdFire. */ | |
2588 | ||
2589 | rtx | |
2590 | m68k_legitimize_tls_address (rtx orig) | |
2591 | { | |
2592 | switch (SYMBOL_REF_TLS_MODEL (orig)) | |
2593 | { | |
2594 | case TLS_MODEL_GLOBAL_DYNAMIC: | |
2595 | orig = m68k_call_tls_get_addr (orig, orig, RELOC_TLSGD); | |
2596 | break; | |
2597 | ||
2598 | case TLS_MODEL_LOCAL_DYNAMIC: | |
2599 | { | |
2600 | rtx eqv; | |
2601 | rtx a0; | |
2602 | rtx x; | |
2603 | ||
2604 | /* Attach a unique REG_EQUIV, to allow the RTL optimizers to | |
2605 | share the LDM result with other LD model accesses. */ | |
2606 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), | |
2607 | UNSPEC_RELOC32); | |
2608 | ||
2609 | a0 = m68k_call_tls_get_addr (orig, eqv, RELOC_TLSLDM); | |
2610 | ||
2611 | x = m68k_wrap_symbol (orig, RELOC_TLSLDO, a0, NULL_RTX); | |
2612 | ||
2613 | if (can_create_pseudo_p ()) | |
2614 | x = m68k_move_to_reg (x, orig, NULL_RTX); | |
2615 | ||
2616 | orig = x; | |
2617 | break; | |
2618 | } | |
2619 | ||
2620 | case TLS_MODEL_INITIAL_EXEC: | |
2621 | { | |
2622 | rtx a0; | |
2623 | rtx x; | |
2624 | ||
2625 | a0 = m68k_call_m68k_read_tp (); | |
2626 | ||
2627 | x = m68k_wrap_symbol_into_got_ref (orig, RELOC_TLSIE, NULL_RTX); | |
2628 | x = gen_rtx_PLUS (Pmode, x, a0); | |
2629 | ||
2630 | if (can_create_pseudo_p ()) | |
2631 | x = m68k_move_to_reg (x, orig, NULL_RTX); | |
2632 | ||
2633 | orig = x; | |
2634 | break; | |
2635 | } | |
2636 | ||
2637 | case TLS_MODEL_LOCAL_EXEC: | |
2638 | { | |
2639 | rtx a0; | |
2640 | rtx x; | |
2641 | ||
2642 | a0 = m68k_call_m68k_read_tp (); | |
2643 | ||
2644 | x = m68k_wrap_symbol (orig, RELOC_TLSLE, a0, NULL_RTX); | |
2645 | ||
2646 | if (can_create_pseudo_p ()) | |
2647 | x = m68k_move_to_reg (x, orig, NULL_RTX); | |
2648 | ||
2649 | orig = x; | |
2650 | break; | |
2651 | } | |
2652 | ||
2653 | default: | |
2654 | gcc_unreachable (); | |
2655 | } | |
2656 | ||
2657 | return orig; | |
2658 | } | |
2659 | ||
2660 | /* Return true if X is a TLS symbol. */ | |
2661 | ||
2662 | static bool | |
2663 | m68k_tls_symbol_p (rtx x) | |
2664 | { | |
2665 | if (!TARGET_HAVE_TLS) | |
2666 | return false; | |
2667 | ||
2668 | if (GET_CODE (x) != SYMBOL_REF) | |
2669 | return false; | |
2670 | ||
2671 | return SYMBOL_REF_TLS_MODEL (x) != 0; | |
2672 | } | |
2673 | ||
2674 | /* Helper for m68k_tls_referenced_p. */ | |
2675 | ||
2676 | static int | |
2677 | m68k_tls_reference_p_1 (rtx *x_ptr, void *data ATTRIBUTE_UNUSED) | |
2678 | { | |
2679 | /* Note: this is not the same as m68k_tls_symbol_p. */ | |
2680 | if (GET_CODE (*x_ptr) == SYMBOL_REF) | |
2681 | return SYMBOL_REF_TLS_MODEL (*x_ptr) != 0 ? 1 : 0; | |
2682 | ||
2683 | /* Don't recurse into legitimate TLS references. */ | |
2684 | if (m68k_tls_reference_p (*x_ptr, true)) | |
2685 | return -1; | |
2686 | ||
2687 | return 0; | |
2688 | } | |
2689 | ||
2690 | /* If !LEGITIMATE_P, return true if X is a TLS symbol reference, | |
2691 | though illegitimate one. | |
2692 | If LEGITIMATE_P, return true if X is a legitimate TLS symbol reference. */ | |
2693 | ||
2694 | bool | |
2695 | m68k_tls_reference_p (rtx x, bool legitimate_p) | |
2696 | { | |
2697 | if (!TARGET_HAVE_TLS) | |
2698 | return false; | |
2699 | ||
2700 | if (!legitimate_p) | |
2701 | return for_each_rtx (&x, m68k_tls_reference_p_1, NULL) == 1 ? true : false; | |
2702 | else | |
2703 | { | |
2704 | enum m68k_reloc reloc = RELOC_GOT; | |
2705 | ||
2706 | return (m68k_unwrap_symbol_1 (x, true, &reloc) != x | |
2707 | && TLS_RELOC_P (reloc)); | |
2708 | } | |
2709 | } | |
2710 | ||
79e68feb | 2711 | \f |
0ce6f9fb | 2712 | |
a0a7fbc9 | 2713 | #define USE_MOVQ(i) ((unsigned) ((i) + 128) <= 255) |
0ce6f9fb | 2714 | |
bda2a571 RS |
2715 | /* Return the type of move that should be used for integer I. */ |
2716 | ||
c47b0cb4 MK |
2717 | M68K_CONST_METHOD |
2718 | m68k_const_method (HOST_WIDE_INT i) | |
0ce6f9fb | 2719 | { |
0ce6f9fb RK |
2720 | unsigned u; |
2721 | ||
6910dd70 | 2722 | if (USE_MOVQ (i)) |
0ce6f9fb | 2723 | return MOVQ; |
24092242 | 2724 | |
c16eadc7 | 2725 | /* The ColdFire doesn't have byte or word operations. */ |
97c55091 | 2726 | /* FIXME: This may not be useful for the m68060 either. */ |
85dbf7e2 | 2727 | if (!TARGET_COLDFIRE) |
24092242 RK |
2728 | { |
2729 | /* if -256 < N < 256 but N is not in range for a moveq | |
7a1929e1 | 2730 | N^ff will be, so use moveq #N^ff, dreg; not.b dreg. */ |
24092242 RK |
2731 | if (USE_MOVQ (i ^ 0xff)) |
2732 | return NOTB; | |
2733 | /* Likewise, try with not.w */ | |
2734 | if (USE_MOVQ (i ^ 0xffff)) | |
2735 | return NOTW; | |
2736 | /* This is the only value where neg.w is useful */ | |
2737 | if (i == -65408) | |
2738 | return NEGW; | |
24092242 | 2739 | } |
28bad6d1 | 2740 | |
5e04daf3 PB |
2741 | /* Try also with swap. */ |
2742 | u = i; | |
2743 | if (USE_MOVQ ((u >> 16) | (u << 16))) | |
2744 | return SWAP; | |
2745 | ||
986e74d5 | 2746 | if (TARGET_ISAB) |
28bad6d1 | 2747 | { |
72edf146 | 2748 | /* Try using MVZ/MVS with an immediate value to load constants. */ |
28bad6d1 PB |
2749 | if (i >= 0 && i <= 65535) |
2750 | return MVZ; | |
2751 | if (i >= -32768 && i <= 32767) | |
2752 | return MVS; | |
2753 | } | |
2754 | ||
0ce6f9fb RK |
2755 | /* Otherwise, use move.l */ |
2756 | return MOVL; | |
2757 | } | |
2758 | ||
bda2a571 RS |
2759 | /* Return the cost of moving constant I into a data register. */ |
2760 | ||
3c50106f | 2761 | static int |
bda2a571 | 2762 | const_int_cost (HOST_WIDE_INT i) |
0ce6f9fb | 2763 | { |
c47b0cb4 | 2764 | switch (m68k_const_method (i)) |
0ce6f9fb | 2765 | { |
a0a7fbc9 AS |
2766 | case MOVQ: |
2767 | /* Constants between -128 and 127 are cheap due to moveq. */ | |
2768 | return 0; | |
2769 | case MVZ: | |
2770 | case MVS: | |
2771 | case NOTB: | |
2772 | case NOTW: | |
2773 | case NEGW: | |
2774 | case SWAP: | |
2775 | /* Constants easily generated by moveq + not.b/not.w/neg.w/swap. */ | |
2776 | return 1; | |
2777 | case MOVL: | |
2778 | return 2; | |
2779 | default: | |
2780 | gcc_unreachable (); | |
0ce6f9fb RK |
2781 | } |
2782 | } | |
2783 | ||
3c50106f | 2784 | static bool |
68f932c4 RS |
2785 | m68k_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED, |
2786 | int *total, bool speed ATTRIBUTE_UNUSED) | |
3c50106f RH |
2787 | { |
2788 | switch (code) | |
2789 | { | |
2790 | case CONST_INT: | |
2791 | /* Constant zero is super cheap due to clr instruction. */ | |
2792 | if (x == const0_rtx) | |
2793 | *total = 0; | |
2794 | else | |
bda2a571 | 2795 | *total = const_int_cost (INTVAL (x)); |
3c50106f RH |
2796 | return true; |
2797 | ||
2798 | case CONST: | |
2799 | case LABEL_REF: | |
2800 | case SYMBOL_REF: | |
2801 | *total = 3; | |
2802 | return true; | |
2803 | ||
2804 | case CONST_DOUBLE: | |
2805 | /* Make 0.0 cheaper than other floating constants to | |
2806 | encourage creating tstsf and tstdf insns. */ | |
2807 | if (outer_code == COMPARE | |
2808 | && (x == CONST0_RTX (SFmode) || x == CONST0_RTX (DFmode))) | |
2809 | *total = 4; | |
2810 | else | |
2811 | *total = 5; | |
2812 | return true; | |
2813 | ||
2814 | /* These are vaguely right for a 68020. */ | |
2815 | /* The costs for long multiply have been adjusted to work properly | |
2816 | in synth_mult on the 68020, relative to an average of the time | |
2817 | for add and the time for shift, taking away a little more because | |
2818 | sometimes move insns are needed. */ | |
a0a7fbc9 AS |
2819 | /* div?.w is relatively cheaper on 68000 counted in COSTS_N_INSNS |
2820 | terms. */ | |
fe95f2f7 JB |
2821 | #define MULL_COST \ |
2822 | (TUNE_68060 ? 2 \ | |
2823 | : TUNE_68040 ? 5 \ | |
03b3e271 KH |
2824 | : (TUNE_CFV2 && TUNE_EMAC) ? 3 \ |
2825 | : (TUNE_CFV2 && TUNE_MAC) ? 4 \ | |
2826 | : TUNE_CFV2 ? 8 \ | |
fe95f2f7 JB |
2827 | : TARGET_COLDFIRE ? 3 : 13) |
2828 | ||
2829 | #define MULW_COST \ | |
2830 | (TUNE_68060 ? 2 \ | |
2831 | : TUNE_68040 ? 3 \ | |
03b3e271 KH |
2832 | : TUNE_68000_10 ? 5 \ |
2833 | : (TUNE_CFV2 && TUNE_EMAC) ? 3 \ | |
2834 | : (TUNE_CFV2 && TUNE_MAC) ? 2 \ | |
2835 | : TUNE_CFV2 ? 8 \ | |
fe95f2f7 JB |
2836 | : TARGET_COLDFIRE ? 2 : 8) |
2837 | ||
2838 | #define DIVW_COST \ | |
2839 | (TARGET_CF_HWDIV ? 11 \ | |
2840 | : TUNE_68000_10 || TARGET_COLDFIRE ? 12 : 27) | |
3c50106f RH |
2841 | |
2842 | case PLUS: | |
2843 | /* An lea costs about three times as much as a simple add. */ | |
2844 | if (GET_MODE (x) == SImode | |
2845 | && GET_CODE (XEXP (x, 1)) == REG | |
2846 | && GET_CODE (XEXP (x, 0)) == MULT | |
2847 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
2848 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
2849 | && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2 | |
2850 | || INTVAL (XEXP (XEXP (x, 0), 1)) == 4 | |
2851 | || INTVAL (XEXP (XEXP (x, 0), 1)) == 8)) | |
eb849993 BI |
2852 | { |
2853 | /* lea an@(dx:l:i),am */ | |
2854 | *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3); | |
2855 | return true; | |
2856 | } | |
3c50106f RH |
2857 | return false; |
2858 | ||
2859 | case ASHIFT: | |
2860 | case ASHIFTRT: | |
2861 | case LSHIFTRT: | |
fe95f2f7 | 2862 | if (TUNE_68060) |
3c50106f RH |
2863 | { |
2864 | *total = COSTS_N_INSNS(1); | |
2865 | return true; | |
2866 | } | |
fe95f2f7 | 2867 | if (TUNE_68000_10) |
3c50106f RH |
2868 | { |
2869 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2870 | { | |
2871 | if (INTVAL (XEXP (x, 1)) < 16) | |
2872 | *total = COSTS_N_INSNS (2) + INTVAL (XEXP (x, 1)) / 2; | |
2873 | else | |
2874 | /* We're using clrw + swap for these cases. */ | |
2875 | *total = COSTS_N_INSNS (4) + (INTVAL (XEXP (x, 1)) - 16) / 2; | |
2876 | } | |
2877 | else | |
a0a7fbc9 | 2878 | *total = COSTS_N_INSNS (10); /* Worst case. */ |
3c50106f RH |
2879 | return true; |
2880 | } | |
2881 | /* A shift by a big integer takes an extra instruction. */ | |
2882 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
2883 | && (INTVAL (XEXP (x, 1)) == 16)) | |
2884 | { | |
2885 | *total = COSTS_N_INSNS (2); /* clrw;swap */ | |
2886 | return true; | |
2887 | } | |
2888 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
2889 | && !(INTVAL (XEXP (x, 1)) > 0 | |
2890 | && INTVAL (XEXP (x, 1)) <= 8)) | |
2891 | { | |
eb849993 | 2892 | *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 1 : 3); /* lsr #i,dn */ |
3c50106f RH |
2893 | return true; |
2894 | } | |
2895 | return false; | |
2896 | ||
2897 | case MULT: | |
2898 | if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
2899 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND) | |
2900 | && GET_MODE (x) == SImode) | |
2901 | *total = COSTS_N_INSNS (MULW_COST); | |
2902 | else if (GET_MODE (x) == QImode || GET_MODE (x) == HImode) | |
2903 | *total = COSTS_N_INSNS (MULW_COST); | |
2904 | else | |
2905 | *total = COSTS_N_INSNS (MULL_COST); | |
2906 | return true; | |
2907 | ||
2908 | case DIV: | |
2909 | case UDIV: | |
2910 | case MOD: | |
2911 | case UMOD: | |
2912 | if (GET_MODE (x) == QImode || GET_MODE (x) == HImode) | |
2913 | *total = COSTS_N_INSNS (DIVW_COST); /* div.w */ | |
eb849993 BI |
2914 | else if (TARGET_CF_HWDIV) |
2915 | *total = COSTS_N_INSNS (18); | |
3c50106f RH |
2916 | else |
2917 | *total = COSTS_N_INSNS (43); /* div.l */ | |
2918 | return true; | |
2919 | ||
f90b7a5a PB |
2920 | case ZERO_EXTRACT: |
2921 | if (outer_code == COMPARE) | |
2922 | *total = 0; | |
2923 | return false; | |
2924 | ||
3c50106f RH |
2925 | default: |
2926 | return false; | |
2927 | } | |
2928 | } | |
2929 | ||
88512ba0 | 2930 | /* Return an instruction to move CONST_INT OPERANDS[1] into data register |
bda2a571 RS |
2931 | OPERANDS[0]. */ |
2932 | ||
2933 | static const char * | |
8a4a2253 | 2934 | output_move_const_into_data_reg (rtx *operands) |
0ce6f9fb | 2935 | { |
bda2a571 | 2936 | HOST_WIDE_INT i; |
0ce6f9fb RK |
2937 | |
2938 | i = INTVAL (operands[1]); | |
c47b0cb4 | 2939 | switch (m68k_const_method (i)) |
0ce6f9fb | 2940 | { |
28bad6d1 | 2941 | case MVZ: |
28bad6d1 | 2942 | return "mvzw %1,%0"; |
1cbae84f PB |
2943 | case MVS: |
2944 | return "mvsw %1,%0"; | |
a0a7fbc9 | 2945 | case MOVQ: |
0ce6f9fb | 2946 | return "moveq %1,%0"; |
a0a7fbc9 | 2947 | case NOTB: |
66e07510 | 2948 | CC_STATUS_INIT; |
1d8eaa6b | 2949 | operands[1] = GEN_INT (i ^ 0xff); |
0ce6f9fb | 2950 | return "moveq %1,%0\n\tnot%.b %0"; |
a0a7fbc9 | 2951 | case NOTW: |
66e07510 | 2952 | CC_STATUS_INIT; |
1d8eaa6b | 2953 | operands[1] = GEN_INT (i ^ 0xffff); |
0ce6f9fb | 2954 | return "moveq %1,%0\n\tnot%.w %0"; |
a0a7fbc9 | 2955 | case NEGW: |
66e07510 | 2956 | CC_STATUS_INIT; |
3b4b85c9 | 2957 | return "moveq #-128,%0\n\tneg%.w %0"; |
a0a7fbc9 | 2958 | case SWAP: |
0ce6f9fb RK |
2959 | { |
2960 | unsigned u = i; | |
2961 | ||
1d8eaa6b | 2962 | operands[1] = GEN_INT ((u << 16) | (u >> 16)); |
0ce6f9fb | 2963 | return "moveq %1,%0\n\tswap %0"; |
0ce6f9fb | 2964 | } |
a0a7fbc9 | 2965 | case MOVL: |
bda2a571 | 2966 | return "move%.l %1,%0"; |
a0a7fbc9 | 2967 | default: |
bda2a571 | 2968 | gcc_unreachable (); |
0ce6f9fb RK |
2969 | } |
2970 | } | |
2971 | ||
bda2a571 | 2972 | /* Return true if I can be handled by ISA B's mov3q instruction. */ |
5e04daf3 | 2973 | |
bda2a571 RS |
2974 | bool |
2975 | valid_mov3q_const (HOST_WIDE_INT i) | |
2976 | { | |
2977 | return TARGET_ISAB && (i == -1 || IN_RANGE (i, 1, 7)); | |
5e04daf3 PB |
2978 | } |
2979 | ||
bda2a571 RS |
2980 | /* Return an instruction to move CONST_INT OPERANDS[1] into OPERANDS[0]. |
2981 | I is the value of OPERANDS[1]. */ | |
5e04daf3 | 2982 | |
bda2a571 | 2983 | static const char * |
8a4a2253 | 2984 | output_move_simode_const (rtx *operands) |
02ed0c07 | 2985 | { |
bda2a571 RS |
2986 | rtx dest; |
2987 | HOST_WIDE_INT src; | |
2988 | ||
2989 | dest = operands[0]; | |
2990 | src = INTVAL (operands[1]); | |
2991 | if (src == 0 | |
2992 | && (DATA_REG_P (dest) || MEM_P (dest)) | |
3197c489 RS |
2993 | /* clr insns on 68000 read before writing. */ |
2994 | && ((TARGET_68010 || TARGET_COLDFIRE) | |
bda2a571 | 2995 | || !(MEM_P (dest) && MEM_VOLATILE_P (dest)))) |
02ed0c07 | 2996 | return "clr%.l %0"; |
bda2a571 | 2997 | else if (GET_MODE (dest) == SImode && valid_mov3q_const (src)) |
a0a7fbc9 | 2998 | return "mov3q%.l %1,%0"; |
bda2a571 | 2999 | else if (src == 0 && ADDRESS_REG_P (dest)) |
38198304 | 3000 | return "sub%.l %0,%0"; |
bda2a571 | 3001 | else if (DATA_REG_P (dest)) |
02ed0c07 | 3002 | return output_move_const_into_data_reg (operands); |
bda2a571 | 3003 | else if (ADDRESS_REG_P (dest) && IN_RANGE (src, -0x8000, 0x7fff)) |
5e04daf3 | 3004 | { |
bda2a571 | 3005 | if (valid_mov3q_const (src)) |
5e04daf3 PB |
3006 | return "mov3q%.l %1,%0"; |
3007 | return "move%.w %1,%0"; | |
3008 | } | |
bda2a571 RS |
3009 | else if (MEM_P (dest) |
3010 | && GET_CODE (XEXP (dest, 0)) == PRE_DEC | |
3011 | && REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM | |
3012 | && IN_RANGE (src, -0x8000, 0x7fff)) | |
5e04daf3 | 3013 | { |
bda2a571 | 3014 | if (valid_mov3q_const (src)) |
5e04daf3 PB |
3015 | return "mov3q%.l %1,%-"; |
3016 | return "pea %a1"; | |
3017 | } | |
02ed0c07 RK |
3018 | return "move%.l %1,%0"; |
3019 | } | |
3020 | ||
5505f548 | 3021 | const char * |
8a4a2253 | 3022 | output_move_simode (rtx *operands) |
f4e80198 RK |
3023 | { |
3024 | if (GET_CODE (operands[1]) == CONST_INT) | |
3025 | return output_move_simode_const (operands); | |
3026 | else if ((GET_CODE (operands[1]) == SYMBOL_REF | |
3027 | || GET_CODE (operands[1]) == CONST) | |
3028 | && push_operand (operands[0], SImode)) | |
3029 | return "pea %a1"; | |
3030 | else if ((GET_CODE (operands[1]) == SYMBOL_REF | |
3031 | || GET_CODE (operands[1]) == CONST) | |
3032 | && ADDRESS_REG_P (operands[0])) | |
3033 | return "lea %a1,%0"; | |
3034 | return "move%.l %1,%0"; | |
3035 | } | |
3036 | ||
5505f548 | 3037 | const char * |
8a4a2253 | 3038 | output_move_himode (rtx *operands) |
f4e80198 RK |
3039 | { |
3040 | if (GET_CODE (operands[1]) == CONST_INT) | |
3041 | { | |
3042 | if (operands[1] == const0_rtx | |
3043 | && (DATA_REG_P (operands[0]) | |
3044 | || GET_CODE (operands[0]) == MEM) | |
3197c489 RS |
3045 | /* clr insns on 68000 read before writing. */ |
3046 | && ((TARGET_68010 || TARGET_COLDFIRE) | |
f4e80198 RK |
3047 | || !(GET_CODE (operands[0]) == MEM |
3048 | && MEM_VOLATILE_P (operands[0])))) | |
3049 | return "clr%.w %0"; | |
38198304 AS |
3050 | else if (operands[1] == const0_rtx |
3051 | && ADDRESS_REG_P (operands[0])) | |
3052 | return "sub%.l %0,%0"; | |
f4e80198 RK |
3053 | else if (DATA_REG_P (operands[0]) |
3054 | && INTVAL (operands[1]) < 128 | |
3055 | && INTVAL (operands[1]) >= -128) | |
a0a7fbc9 | 3056 | return "moveq %1,%0"; |
f4e80198 RK |
3057 | else if (INTVAL (operands[1]) < 0x8000 |
3058 | && INTVAL (operands[1]) >= -0x8000) | |
3059 | return "move%.w %1,%0"; | |
3060 | } | |
3061 | else if (CONSTANT_P (operands[1])) | |
3062 | return "move%.l %1,%0"; | |
f4e80198 RK |
3063 | return "move%.w %1,%0"; |
3064 | } | |
3065 | ||
5505f548 | 3066 | const char * |
8a4a2253 | 3067 | output_move_qimode (rtx *operands) |
f4e80198 | 3068 | { |
102701ff | 3069 | /* 68k family always modifies the stack pointer by at least 2, even for |
c16eadc7 | 3070 | byte pushes. The 5200 (ColdFire) does not do this. */ |
4761e388 | 3071 | |
a0a7fbc9 | 3072 | /* This case is generated by pushqi1 pattern now. */ |
4761e388 NS |
3073 | gcc_assert (!(GET_CODE (operands[0]) == MEM |
3074 | && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC | |
3075 | && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx | |
3076 | && ! ADDRESS_REG_P (operands[1]) | |
3077 | && ! TARGET_COLDFIRE)); | |
f4e80198 | 3078 | |
3197c489 | 3079 | /* clr and st insns on 68000 read before writing. */ |
f4e80198 | 3080 | if (!ADDRESS_REG_P (operands[0]) |
3197c489 | 3081 | && ((TARGET_68010 || TARGET_COLDFIRE) |
f4e80198 RK |
3082 | || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0])))) |
3083 | { | |
3084 | if (operands[1] == const0_rtx) | |
3085 | return "clr%.b %0"; | |
9425fb04 | 3086 | if ((!TARGET_COLDFIRE || DATA_REG_P (operands[0])) |
f4e80198 RK |
3087 | && GET_CODE (operands[1]) == CONST_INT |
3088 | && (INTVAL (operands[1]) & 255) == 255) | |
3089 | { | |
3090 | CC_STATUS_INIT; | |
3091 | return "st %0"; | |
3092 | } | |
3093 | } | |
3094 | if (GET_CODE (operands[1]) == CONST_INT | |
3095 | && DATA_REG_P (operands[0]) | |
3096 | && INTVAL (operands[1]) < 128 | |
3097 | && INTVAL (operands[1]) >= -128) | |
a0a7fbc9 | 3098 | return "moveq %1,%0"; |
38198304 AS |
3099 | if (operands[1] == const0_rtx && ADDRESS_REG_P (operands[0])) |
3100 | return "sub%.l %0,%0"; | |
f4e80198 RK |
3101 | if (GET_CODE (operands[1]) != CONST_INT && CONSTANT_P (operands[1])) |
3102 | return "move%.l %1,%0"; | |
c16eadc7 | 3103 | /* 68k family (including the 5200 ColdFire) does not support byte moves to |
37834fc8 JL |
3104 | from address registers. */ |
3105 | if (ADDRESS_REG_P (operands[0]) || ADDRESS_REG_P (operands[1])) | |
f4e80198 RK |
3106 | return "move%.w %1,%0"; |
3107 | return "move%.b %1,%0"; | |
3108 | } | |
3109 | ||
5505f548 | 3110 | const char * |
8a4a2253 | 3111 | output_move_stricthi (rtx *operands) |
9b55bf04 RK |
3112 | { |
3113 | if (operands[1] == const0_rtx | |
3197c489 RS |
3114 | /* clr insns on 68000 read before writing. */ |
3115 | && ((TARGET_68010 || TARGET_COLDFIRE) | |
9b55bf04 RK |
3116 | || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0])))) |
3117 | return "clr%.w %0"; | |
3118 | return "move%.w %1,%0"; | |
3119 | } | |
3120 | ||
5505f548 | 3121 | const char * |
8a4a2253 | 3122 | output_move_strictqi (rtx *operands) |
9b55bf04 RK |
3123 | { |
3124 | if (operands[1] == const0_rtx | |
3197c489 RS |
3125 | /* clr insns on 68000 read before writing. */ |
3126 | && ((TARGET_68010 || TARGET_COLDFIRE) | |
9b55bf04 RK |
3127 | || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0])))) |
3128 | return "clr%.b %0"; | |
3129 | return "move%.b %1,%0"; | |
3130 | } | |
3131 | ||
79e68feb RS |
3132 | /* Return the best assembler insn template |
3133 | for moving operands[1] into operands[0] as a fullword. */ | |
3134 | ||
5505f548 | 3135 | static const char * |
8a4a2253 | 3136 | singlemove_string (rtx *operands) |
79e68feb | 3137 | { |
02ed0c07 RK |
3138 | if (GET_CODE (operands[1]) == CONST_INT) |
3139 | return output_move_simode_const (operands); | |
3140 | return "move%.l %1,%0"; | |
79e68feb RS |
3141 | } |
3142 | ||
2505bc97 | 3143 | |
c47b0cb4 MK |
3144 | /* Output assembler or rtl code to perform a doubleword move insn |
3145 | with operands OPERANDS. | |
3146 | Pointers to 3 helper functions should be specified: | |
3147 | HANDLE_REG_ADJUST to adjust a register by a small value, | |
3148 | HANDLE_COMPADR to compute an address and | |
3149 | HANDLE_MOVSI to move 4 bytes. */ | |
79e68feb | 3150 | |
c47b0cb4 MK |
3151 | static void |
3152 | handle_move_double (rtx operands[2], | |
3153 | void (*handle_reg_adjust) (rtx, int), | |
3154 | void (*handle_compadr) (rtx [2]), | |
3155 | void (*handle_movsi) (rtx [2])) | |
79e68feb | 3156 | { |
2505bc97 RS |
3157 | enum |
3158 | { | |
3159 | REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP | |
3160 | } optype0, optype1; | |
79e68feb | 3161 | rtx latehalf[2]; |
2505bc97 | 3162 | rtx middlehalf[2]; |
7f98eeb6 | 3163 | rtx xops[2]; |
79e68feb | 3164 | rtx addreg0 = 0, addreg1 = 0; |
7f98eeb6 | 3165 | int dest_overlapped_low = 0; |
184916bc | 3166 | int size = GET_MODE_SIZE (GET_MODE (operands[0])); |
2505bc97 RS |
3167 | |
3168 | middlehalf[0] = 0; | |
3169 | middlehalf[1] = 0; | |
79e68feb RS |
3170 | |
3171 | /* First classify both operands. */ | |
3172 | ||
3173 | if (REG_P (operands[0])) | |
3174 | optype0 = REGOP; | |
3175 | else if (offsettable_memref_p (operands[0])) | |
3176 | optype0 = OFFSOP; | |
3177 | else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC) | |
3178 | optype0 = POPOP; | |
3179 | else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC) | |
3180 | optype0 = PUSHOP; | |
3181 | else if (GET_CODE (operands[0]) == MEM) | |
3182 | optype0 = MEMOP; | |
3183 | else | |
3184 | optype0 = RNDOP; | |
3185 | ||
3186 | if (REG_P (operands[1])) | |
3187 | optype1 = REGOP; | |
3188 | else if (CONSTANT_P (operands[1])) | |
3189 | optype1 = CNSTOP; | |
3190 | else if (offsettable_memref_p (operands[1])) | |
3191 | optype1 = OFFSOP; | |
3192 | else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC) | |
3193 | optype1 = POPOP; | |
3194 | else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC) | |
3195 | optype1 = PUSHOP; | |
3196 | else if (GET_CODE (operands[1]) == MEM) | |
3197 | optype1 = MEMOP; | |
3198 | else | |
3199 | optype1 = RNDOP; | |
3200 | ||
4761e388 NS |
3201 | /* Check for the cases that the operand constraints are not supposed |
3202 | to allow to happen. Generating code for these cases is | |
3203 | painful. */ | |
3204 | gcc_assert (optype0 != RNDOP && optype1 != RNDOP); | |
79e68feb RS |
3205 | |
3206 | /* If one operand is decrementing and one is incrementing | |
3207 | decrement the former register explicitly | |
3208 | and change that operand into ordinary indexing. */ | |
3209 | ||
3210 | if (optype0 == PUSHOP && optype1 == POPOP) | |
3211 | { | |
3212 | operands[0] = XEXP (XEXP (operands[0], 0), 0); | |
c47b0cb4 MK |
3213 | |
3214 | handle_reg_adjust (operands[0], -size); | |
3215 | ||
2505bc97 | 3216 | if (GET_MODE (operands[1]) == XFmode) |
1d8eaa6b | 3217 | operands[0] = gen_rtx_MEM (XFmode, operands[0]); |
2505bc97 | 3218 | else if (GET_MODE (operands[0]) == DFmode) |
1d8eaa6b | 3219 | operands[0] = gen_rtx_MEM (DFmode, operands[0]); |
2505bc97 | 3220 | else |
1d8eaa6b | 3221 | operands[0] = gen_rtx_MEM (DImode, operands[0]); |
79e68feb RS |
3222 | optype0 = OFFSOP; |
3223 | } | |
3224 | if (optype0 == POPOP && optype1 == PUSHOP) | |
3225 | { | |
3226 | operands[1] = XEXP (XEXP (operands[1], 0), 0); | |
c47b0cb4 MK |
3227 | |
3228 | handle_reg_adjust (operands[1], -size); | |
3229 | ||
2505bc97 | 3230 | if (GET_MODE (operands[1]) == XFmode) |
1d8eaa6b | 3231 | operands[1] = gen_rtx_MEM (XFmode, operands[1]); |
2505bc97 | 3232 | else if (GET_MODE (operands[1]) == DFmode) |
1d8eaa6b | 3233 | operands[1] = gen_rtx_MEM (DFmode, operands[1]); |
2505bc97 | 3234 | else |
1d8eaa6b | 3235 | operands[1] = gen_rtx_MEM (DImode, operands[1]); |
79e68feb RS |
3236 | optype1 = OFFSOP; |
3237 | } | |
3238 | ||
3239 | /* If an operand is an unoffsettable memory ref, find a register | |
3240 | we can increment temporarily to make it refer to the second word. */ | |
3241 | ||
3242 | if (optype0 == MEMOP) | |
3243 | addreg0 = find_addr_reg (XEXP (operands[0], 0)); | |
3244 | ||
3245 | if (optype1 == MEMOP) | |
3246 | addreg1 = find_addr_reg (XEXP (operands[1], 0)); | |
3247 | ||
3248 | /* Ok, we can do one word at a time. | |
3249 | Normally we do the low-numbered word first, | |
3250 | but if either operand is autodecrementing then we | |
3251 | do the high-numbered word first. | |
3252 | ||
3253 | In either case, set up in LATEHALF the operands to use | |
3254 | for the high-numbered word and in some cases alter the | |
3255 | operands in OPERANDS to be suitable for the low-numbered word. */ | |
3256 | ||
2505bc97 RS |
3257 | if (size == 12) |
3258 | { | |
3259 | if (optype0 == REGOP) | |
3260 | { | |
1d8eaa6b AS |
3261 | latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2); |
3262 | middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1); | |
2505bc97 RS |
3263 | } |
3264 | else if (optype0 == OFFSOP) | |
3265 | { | |
b72f00af RK |
3266 | middlehalf[0] = adjust_address (operands[0], SImode, 4); |
3267 | latehalf[0] = adjust_address (operands[0], SImode, size - 4); | |
2505bc97 RS |
3268 | } |
3269 | else | |
3270 | { | |
c47b0cb4 MK |
3271 | middlehalf[0] = adjust_address (operands[0], SImode, 0); |
3272 | latehalf[0] = adjust_address (operands[0], SImode, 0); | |
2505bc97 RS |
3273 | } |
3274 | ||
3275 | if (optype1 == REGOP) | |
3276 | { | |
1d8eaa6b AS |
3277 | latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2); |
3278 | middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1); | |
2505bc97 RS |
3279 | } |
3280 | else if (optype1 == OFFSOP) | |
3281 | { | |
b72f00af RK |
3282 | middlehalf[1] = adjust_address (operands[1], SImode, 4); |
3283 | latehalf[1] = adjust_address (operands[1], SImode, size - 4); | |
2505bc97 RS |
3284 | } |
3285 | else if (optype1 == CNSTOP) | |
3286 | { | |
3287 | if (GET_CODE (operands[1]) == CONST_DOUBLE) | |
3288 | { | |
3289 | REAL_VALUE_TYPE r; | |
3290 | long l[3]; | |
3291 | ||
3292 | REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]); | |
3293 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l); | |
3294 | operands[1] = GEN_INT (l[0]); | |
3295 | middlehalf[1] = GEN_INT (l[1]); | |
3296 | latehalf[1] = GEN_INT (l[2]); | |
3297 | } | |
4761e388 | 3298 | else |
2505bc97 | 3299 | { |
4761e388 NS |
3300 | /* No non-CONST_DOUBLE constant should ever appear |
3301 | here. */ | |
3302 | gcc_assert (!CONSTANT_P (operands[1])); | |
2505bc97 RS |
3303 | } |
3304 | } | |
3305 | else | |
3306 | { | |
c47b0cb4 MK |
3307 | middlehalf[1] = adjust_address (operands[1], SImode, 0); |
3308 | latehalf[1] = adjust_address (operands[1], SImode, 0); | |
2505bc97 RS |
3309 | } |
3310 | } | |
79e68feb | 3311 | else |
2505bc97 RS |
3312 | /* size is not 12: */ |
3313 | { | |
3314 | if (optype0 == REGOP) | |
1d8eaa6b | 3315 | latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1); |
2505bc97 | 3316 | else if (optype0 == OFFSOP) |
b72f00af | 3317 | latehalf[0] = adjust_address (operands[0], SImode, size - 4); |
2505bc97 | 3318 | else |
c47b0cb4 | 3319 | latehalf[0] = adjust_address (operands[0], SImode, 0); |
2505bc97 RS |
3320 | |
3321 | if (optype1 == REGOP) | |
1d8eaa6b | 3322 | latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1); |
2505bc97 | 3323 | else if (optype1 == OFFSOP) |
b72f00af | 3324 | latehalf[1] = adjust_address (operands[1], SImode, size - 4); |
2505bc97 RS |
3325 | else if (optype1 == CNSTOP) |
3326 | split_double (operands[1], &operands[1], &latehalf[1]); | |
3327 | else | |
c47b0cb4 | 3328 | latehalf[1] = adjust_address (operands[1], SImode, 0); |
2505bc97 | 3329 | } |
79e68feb | 3330 | |
e864837a AS |
3331 | /* If insn is effectively movd N(REG),-(REG) then we will do the high |
3332 | word first. We should use the adjusted operand 1 (which is N+4(REG)) | |
3333 | for the low word as well, to compensate for the first decrement of | |
3334 | REG. */ | |
79e68feb | 3335 | if (optype0 == PUSHOP |
e864837a | 3336 | && reg_overlap_mentioned_p (XEXP (XEXP (operands[0], 0), 0), operands[1])) |
c88aeaf8 | 3337 | operands[1] = middlehalf[1] = latehalf[1]; |
79e68feb | 3338 | |
7f98eeb6 RS |
3339 | /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)), |
3340 | if the upper part of reg N does not appear in the MEM, arrange to | |
3341 | emit the move late-half first. Otherwise, compute the MEM address | |
3342 | into the upper part of N and use that as a pointer to the memory | |
3343 | operand. */ | |
3344 | if (optype0 == REGOP | |
3345 | && (optype1 == OFFSOP || optype1 == MEMOP)) | |
3346 | { | |
1d8eaa6b | 3347 | rtx testlow = gen_rtx_REG (SImode, REGNO (operands[0])); |
3a58400f RS |
3348 | |
3349 | if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)) | |
d7e8d581 | 3350 | && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0))) |
7f98eeb6 RS |
3351 | { |
3352 | /* If both halves of dest are used in the src memory address, | |
3a58400f RS |
3353 | compute the address into latehalf of dest. |
3354 | Note that this can't happen if the dest is two data regs. */ | |
4761e388 | 3355 | compadr: |
7f98eeb6 RS |
3356 | xops[0] = latehalf[0]; |
3357 | xops[1] = XEXP (operands[1], 0); | |
c47b0cb4 MK |
3358 | |
3359 | handle_compadr (xops); | |
3360 | if (GET_MODE (operands[1]) == XFmode) | |
7f98eeb6 | 3361 | { |
1d8eaa6b | 3362 | operands[1] = gen_rtx_MEM (XFmode, latehalf[0]); |
b72f00af RK |
3363 | middlehalf[1] = adjust_address (operands[1], DImode, size - 8); |
3364 | latehalf[1] = adjust_address (operands[1], DImode, size - 4); | |
7f98eeb6 RS |
3365 | } |
3366 | else | |
3367 | { | |
1d8eaa6b | 3368 | operands[1] = gen_rtx_MEM (DImode, latehalf[0]); |
b72f00af | 3369 | latehalf[1] = adjust_address (operands[1], DImode, size - 4); |
7f98eeb6 RS |
3370 | } |
3371 | } | |
3372 | else if (size == 12 | |
d7e8d581 RS |
3373 | && reg_overlap_mentioned_p (middlehalf[0], |
3374 | XEXP (operands[1], 0))) | |
7f98eeb6 | 3375 | { |
3a58400f RS |
3376 | /* Check for two regs used by both source and dest. |
3377 | Note that this can't happen if the dest is all data regs. | |
3378 | It can happen if the dest is d6, d7, a0. | |
3379 | But in that case, latehalf is an addr reg, so | |
3380 | the code at compadr does ok. */ | |
3381 | ||
3382 | if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)) | |
d7e8d581 RS |
3383 | || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0))) |
3384 | goto compadr; | |
7f98eeb6 RS |
3385 | |
3386 | /* JRV says this can't happen: */ | |
4761e388 | 3387 | gcc_assert (!addreg0 && !addreg1); |
7f98eeb6 | 3388 | |
7a1929e1 | 3389 | /* Only the middle reg conflicts; simply put it last. */ |
c47b0cb4 MK |
3390 | handle_movsi (operands); |
3391 | handle_movsi (latehalf); | |
3392 | handle_movsi (middlehalf); | |
3393 | ||
3394 | return; | |
7f98eeb6 | 3395 | } |
2fb8a81d | 3396 | else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))) |
7f98eeb6 RS |
3397 | /* If the low half of dest is mentioned in the source memory |
3398 | address, the arrange to emit the move late half first. */ | |
3399 | dest_overlapped_low = 1; | |
3400 | } | |
3401 | ||
79e68feb RS |
3402 | /* If one or both operands autodecrementing, |
3403 | do the two words, high-numbered first. */ | |
3404 | ||
3405 | /* Likewise, the first move would clobber the source of the second one, | |
3406 | do them in the other order. This happens only for registers; | |
3407 | such overlap can't happen in memory unless the user explicitly | |
3408 | sets it up, and that is an undefined circumstance. */ | |
3409 | ||
3410 | if (optype0 == PUSHOP || optype1 == PUSHOP | |
3411 | || (optype0 == REGOP && optype1 == REGOP | |
2505bc97 | 3412 | && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1])) |
7f98eeb6 RS |
3413 | || REGNO (operands[0]) == REGNO (latehalf[1]))) |
3414 | || dest_overlapped_low) | |
79e68feb RS |
3415 | { |
3416 | /* Make any unoffsettable addresses point at high-numbered word. */ | |
3417 | if (addreg0) | |
c47b0cb4 | 3418 | handle_reg_adjust (addreg0, size - 4); |
79e68feb | 3419 | if (addreg1) |
c47b0cb4 | 3420 | handle_reg_adjust (addreg1, size - 4); |
79e68feb RS |
3421 | |
3422 | /* Do that word. */ | |
c47b0cb4 | 3423 | handle_movsi (latehalf); |
79e68feb RS |
3424 | |
3425 | /* Undo the adds we just did. */ | |
3426 | if (addreg0) | |
c47b0cb4 | 3427 | handle_reg_adjust (addreg0, -4); |
79e68feb | 3428 | if (addreg1) |
c47b0cb4 | 3429 | handle_reg_adjust (addreg1, -4); |
79e68feb | 3430 | |
2505bc97 RS |
3431 | if (size == 12) |
3432 | { | |
c47b0cb4 MK |
3433 | handle_movsi (middlehalf); |
3434 | ||
2505bc97 | 3435 | if (addreg0) |
c47b0cb4 | 3436 | handle_reg_adjust (addreg0, -4); |
2505bc97 | 3437 | if (addreg1) |
c47b0cb4 | 3438 | handle_reg_adjust (addreg1, -4); |
2505bc97 RS |
3439 | } |
3440 | ||
79e68feb | 3441 | /* Do low-numbered word. */ |
c47b0cb4 MK |
3442 | |
3443 | handle_movsi (operands); | |
3444 | return; | |
79e68feb RS |
3445 | } |
3446 | ||
3447 | /* Normal case: do the two words, low-numbered first. */ | |
3448 | ||
dcac2e64 | 3449 | m68k_final_prescan_insn (NULL, operands, 2); |
c47b0cb4 | 3450 | handle_movsi (operands); |
79e68feb | 3451 | |
2505bc97 RS |
3452 | /* Do the middle one of the three words for long double */ |
3453 | if (size == 12) | |
3454 | { | |
3455 | if (addreg0) | |
c47b0cb4 | 3456 | handle_reg_adjust (addreg0, 4); |
2505bc97 | 3457 | if (addreg1) |
c47b0cb4 | 3458 | handle_reg_adjust (addreg1, 4); |
2505bc97 | 3459 | |
dcac2e64 | 3460 | m68k_final_prescan_insn (NULL, middlehalf, 2); |
c47b0cb4 | 3461 | handle_movsi (middlehalf); |
2505bc97 RS |
3462 | } |
3463 | ||
79e68feb RS |
3464 | /* Make any unoffsettable addresses point at high-numbered word. */ |
3465 | if (addreg0) | |
c47b0cb4 | 3466 | handle_reg_adjust (addreg0, 4); |
79e68feb | 3467 | if (addreg1) |
c47b0cb4 | 3468 | handle_reg_adjust (addreg1, 4); |
79e68feb RS |
3469 | |
3470 | /* Do that word. */ | |
dcac2e64 | 3471 | m68k_final_prescan_insn (NULL, latehalf, 2); |
c47b0cb4 | 3472 | handle_movsi (latehalf); |
79e68feb RS |
3473 | |
3474 | /* Undo the adds we just did. */ | |
3475 | if (addreg0) | |
c47b0cb4 MK |
3476 | handle_reg_adjust (addreg0, -(size - 4)); |
3477 | if (addreg1) | |
3478 | handle_reg_adjust (addreg1, -(size - 4)); | |
3479 | ||
3480 | return; | |
3481 | } | |
3482 | ||
3483 | /* Output assembler code to adjust REG by N. */ | |
3484 | static void | |
3485 | output_reg_adjust (rtx reg, int n) | |
3486 | { | |
3487 | const char *s; | |
3488 | ||
3489 | gcc_assert (GET_MODE (reg) == SImode | |
3490 | && -12 <= n && n != 0 && n <= 12); | |
3491 | ||
3492 | switch (n) | |
2505bc97 | 3493 | { |
c47b0cb4 MK |
3494 | case 12: |
3495 | s = "add%.l #12,%0"; | |
3496 | break; | |
3497 | ||
3498 | case 8: | |
3499 | s = "addq%.l #8,%0"; | |
3500 | break; | |
3501 | ||
3502 | case 4: | |
3503 | s = "addq%.l #4,%0"; | |
3504 | break; | |
3505 | ||
3506 | case -12: | |
3507 | s = "sub%.l #12,%0"; | |
3508 | break; | |
3509 | ||
3510 | case -8: | |
3511 | s = "subq%.l #8,%0"; | |
3512 | break; | |
3513 | ||
3514 | case -4: | |
3515 | s = "subq%.l #4,%0"; | |
3516 | break; | |
3517 | ||
3518 | default: | |
3519 | gcc_unreachable (); | |
3520 | s = NULL; | |
2505bc97 | 3521 | } |
c47b0cb4 MK |
3522 | |
3523 | output_asm_insn (s, ®); | |
3524 | } | |
3525 | ||
3526 | /* Emit rtl code to adjust REG by N. */ | |
3527 | static void | |
3528 | emit_reg_adjust (rtx reg1, int n) | |
3529 | { | |
3530 | rtx reg2; | |
3531 | ||
3532 | gcc_assert (GET_MODE (reg1) == SImode | |
3533 | && -12 <= n && n != 0 && n <= 12); | |
3534 | ||
3535 | reg1 = copy_rtx (reg1); | |
3536 | reg2 = copy_rtx (reg1); | |
3537 | ||
3538 | if (n < 0) | |
3539 | emit_insn (gen_subsi3 (reg1, reg2, GEN_INT (-n))); | |
3540 | else if (n > 0) | |
3541 | emit_insn (gen_addsi3 (reg1, reg2, GEN_INT (n))); | |
3542 | else | |
3543 | gcc_unreachable (); | |
3544 | } | |
3545 | ||
3546 | /* Output assembler to load address OPERANDS[0] to register OPERANDS[1]. */ | |
3547 | static void | |
3548 | output_compadr (rtx operands[2]) | |
3549 | { | |
3550 | output_asm_insn ("lea %a1,%0", operands); | |
3551 | } | |
3552 | ||
3553 | /* Output the best assembler insn for moving operands[1] into operands[0] | |
3554 | as a fullword. */ | |
3555 | static void | |
3556 | output_movsi (rtx operands[2]) | |
3557 | { | |
3558 | output_asm_insn (singlemove_string (operands), operands); | |
3559 | } | |
3560 | ||
3561 | /* Copy OP and change its mode to MODE. */ | |
3562 | static rtx | |
3563 | copy_operand (rtx op, enum machine_mode mode) | |
3564 | { | |
3565 | /* ??? This looks really ugly. There must be a better way | |
3566 | to change a mode on the operand. */ | |
3567 | if (GET_MODE (op) != VOIDmode) | |
2505bc97 | 3568 | { |
c47b0cb4 MK |
3569 | if (REG_P (op)) |
3570 | op = gen_rtx_REG (mode, REGNO (op)); | |
2505bc97 | 3571 | else |
c47b0cb4 MK |
3572 | { |
3573 | op = copy_rtx (op); | |
3574 | PUT_MODE (op, mode); | |
3575 | } | |
2505bc97 | 3576 | } |
79e68feb | 3577 | |
c47b0cb4 MK |
3578 | return op; |
3579 | } | |
3580 | ||
3581 | /* Emit rtl code for moving operands[1] into operands[0] as a fullword. */ | |
3582 | static void | |
3583 | emit_movsi (rtx operands[2]) | |
3584 | { | |
3585 | operands[0] = copy_operand (operands[0], SImode); | |
3586 | operands[1] = copy_operand (operands[1], SImode); | |
3587 | ||
3588 | emit_insn (gen_movsi (operands[0], operands[1])); | |
3589 | } | |
3590 | ||
3591 | /* Output assembler code to perform a doubleword move insn | |
3592 | with operands OPERANDS. */ | |
3593 | const char * | |
3594 | output_move_double (rtx *operands) | |
3595 | { | |
3596 | handle_move_double (operands, | |
3597 | output_reg_adjust, output_compadr, output_movsi); | |
3598 | ||
79e68feb RS |
3599 | return ""; |
3600 | } | |
3601 | ||
c47b0cb4 MK |
3602 | /* Output rtl code to perform a doubleword move insn |
3603 | with operands OPERANDS. */ | |
3604 | void | |
3605 | m68k_emit_move_double (rtx operands[2]) | |
3606 | { | |
3607 | handle_move_double (operands, emit_reg_adjust, emit_movsi, emit_movsi); | |
3608 | } | |
dcc21c4c PB |
3609 | |
3610 | /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a | |
3611 | new rtx with the correct mode. */ | |
3612 | ||
3613 | static rtx | |
3614 | force_mode (enum machine_mode mode, rtx orig) | |
3615 | { | |
3616 | if (mode == GET_MODE (orig)) | |
3617 | return orig; | |
3618 | ||
3619 | if (REGNO (orig) >= FIRST_PSEUDO_REGISTER) | |
3620 | abort (); | |
3621 | ||
3622 | return gen_rtx_REG (mode, REGNO (orig)); | |
3623 | } | |
3624 | ||
3625 | static int | |
3626 | fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) | |
3627 | { | |
3628 | return reg_renumber && FP_REG_P (op); | |
3629 | } | |
3630 | ||
3631 | /* Emit insns to move operands[1] into operands[0]. | |
3632 | ||
3633 | Return 1 if we have written out everything that needs to be done to | |
3634 | do the move. Otherwise, return 0 and the caller will emit the move | |
3635 | normally. | |
3636 | ||
3637 | Note SCRATCH_REG may not be in the proper mode depending on how it | |
c0220ea4 | 3638 | will be used. This routine is responsible for creating a new copy |
dcc21c4c PB |
3639 | of SCRATCH_REG in the proper mode. */ |
3640 | ||
3641 | int | |
3642 | emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg) | |
3643 | { | |
3644 | register rtx operand0 = operands[0]; | |
3645 | register rtx operand1 = operands[1]; | |
3646 | register rtx tem; | |
3647 | ||
3648 | if (scratch_reg | |
3649 | && reload_in_progress && GET_CODE (operand0) == REG | |
3650 | && REGNO (operand0) >= FIRST_PSEUDO_REGISTER) | |
f2034d06 | 3651 | operand0 = reg_equiv_mem (REGNO (operand0)); |
dcc21c4c PB |
3652 | else if (scratch_reg |
3653 | && reload_in_progress && GET_CODE (operand0) == SUBREG | |
3654 | && GET_CODE (SUBREG_REG (operand0)) == REG | |
3655 | && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER) | |
3656 | { | |
3657 | /* We must not alter SUBREG_BYTE (operand0) since that would confuse | |
3658 | the code which tracks sets/uses for delete_output_reload. */ | |
3659 | rtx temp = gen_rtx_SUBREG (GET_MODE (operand0), | |
f2034d06 | 3660 | reg_equiv_mem (REGNO (SUBREG_REG (operand0))), |
dcc21c4c | 3661 | SUBREG_BYTE (operand0)); |
55a2c322 | 3662 | operand0 = alter_subreg (&temp, true); |
dcc21c4c PB |
3663 | } |
3664 | ||
3665 | if (scratch_reg | |
3666 | && reload_in_progress && GET_CODE (operand1) == REG | |
3667 | && REGNO (operand1) >= FIRST_PSEUDO_REGISTER) | |
f2034d06 | 3668 | operand1 = reg_equiv_mem (REGNO (operand1)); |
dcc21c4c PB |
3669 | else if (scratch_reg |
3670 | && reload_in_progress && GET_CODE (operand1) == SUBREG | |
3671 | && GET_CODE (SUBREG_REG (operand1)) == REG | |
3672 | && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER) | |
3673 | { | |
3674 | /* We must not alter SUBREG_BYTE (operand0) since that would confuse | |
3675 | the code which tracks sets/uses for delete_output_reload. */ | |
3676 | rtx temp = gen_rtx_SUBREG (GET_MODE (operand1), | |
f2034d06 | 3677 | reg_equiv_mem (REGNO (SUBREG_REG (operand1))), |
dcc21c4c | 3678 | SUBREG_BYTE (operand1)); |
55a2c322 | 3679 | operand1 = alter_subreg (&temp, true); |
dcc21c4c PB |
3680 | } |
3681 | ||
3682 | if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM | |
3683 | && ((tem = find_replacement (&XEXP (operand0, 0))) | |
3684 | != XEXP (operand0, 0))) | |
3685 | operand0 = gen_rtx_MEM (GET_MODE (operand0), tem); | |
3686 | if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM | |
3687 | && ((tem = find_replacement (&XEXP (operand1, 0))) | |
3688 | != XEXP (operand1, 0))) | |
3689 | operand1 = gen_rtx_MEM (GET_MODE (operand1), tem); | |
3690 | ||
3691 | /* Handle secondary reloads for loads/stores of FP registers where | |
3692 | the address is symbolic by using the scratch register */ | |
3693 | if (fp_reg_operand (operand0, mode) | |
3694 | && ((GET_CODE (operand1) == MEM | |
3695 | && ! memory_address_p (DFmode, XEXP (operand1, 0))) | |
3696 | || ((GET_CODE (operand1) == SUBREG | |
3697 | && GET_CODE (XEXP (operand1, 0)) == MEM | |
3698 | && !memory_address_p (DFmode, XEXP (XEXP (operand1, 0), 0))))) | |
3699 | && scratch_reg) | |
3700 | { | |
3701 | if (GET_CODE (operand1) == SUBREG) | |
3702 | operand1 = XEXP (operand1, 0); | |
3703 | ||
3704 | /* SCRATCH_REG will hold an address. We want | |
3705 | it in SImode regardless of what mode it was originally given | |
3706 | to us. */ | |
3707 | scratch_reg = force_mode (SImode, scratch_reg); | |
3708 | ||
3709 | /* D might not fit in 14 bits either; for such cases load D into | |
3710 | scratch reg. */ | |
3711 | if (!memory_address_p (Pmode, XEXP (operand1, 0))) | |
3712 | { | |
3713 | emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1)); | |
3714 | emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)), | |
3715 | Pmode, | |
3716 | XEXP (XEXP (operand1, 0), 0), | |
3717 | scratch_reg)); | |
3718 | } | |
3719 | else | |
3720 | emit_move_insn (scratch_reg, XEXP (operand1, 0)); | |
3721 | emit_insn (gen_rtx_SET (VOIDmode, operand0, | |
3722 | gen_rtx_MEM (mode, scratch_reg))); | |
3723 | return 1; | |
3724 | } | |
3725 | else if (fp_reg_operand (operand1, mode) | |
3726 | && ((GET_CODE (operand0) == MEM | |
3727 | && ! memory_address_p (DFmode, XEXP (operand0, 0))) | |
3728 | || ((GET_CODE (operand0) == SUBREG) | |
3729 | && GET_CODE (XEXP (operand0, 0)) == MEM | |
3730 | && !memory_address_p (DFmode, XEXP (XEXP (operand0, 0), 0)))) | |
3731 | && scratch_reg) | |
3732 | { | |
3733 | if (GET_CODE (operand0) == SUBREG) | |
3734 | operand0 = XEXP (operand0, 0); | |
3735 | ||
3736 | /* SCRATCH_REG will hold an address and maybe the actual data. We want | |
3737 | it in SIMODE regardless of what mode it was originally given | |
3738 | to us. */ | |
3739 | scratch_reg = force_mode (SImode, scratch_reg); | |
3740 | ||
3741 | /* D might not fit in 14 bits either; for such cases load D into | |
3742 | scratch reg. */ | |
3743 | if (!memory_address_p (Pmode, XEXP (operand0, 0))) | |
3744 | { | |
3745 | emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1)); | |
3746 | emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0, | |
3747 | 0)), | |
3748 | Pmode, | |
3749 | XEXP (XEXP (operand0, 0), | |
3750 | 0), | |
3751 | scratch_reg)); | |
3752 | } | |
3753 | else | |
3754 | emit_move_insn (scratch_reg, XEXP (operand0, 0)); | |
3755 | emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg), | |
3756 | operand1)); | |
3757 | return 1; | |
3758 | } | |
3759 | /* Handle secondary reloads for loads of FP registers from constant | |
3760 | expressions by forcing the constant into memory. | |
3761 | ||
3762 | use scratch_reg to hold the address of the memory location. | |
3763 | ||
3764 | The proper fix is to change PREFERRED_RELOAD_CLASS to return | |
3765 | NO_REGS when presented with a const_int and an register class | |
3766 | containing only FP registers. Doing so unfortunately creates | |
3767 | more problems than it solves. Fix this for 2.5. */ | |
3768 | else if (fp_reg_operand (operand0, mode) | |
3769 | && CONSTANT_P (operand1) | |
3770 | && scratch_reg) | |
3771 | { | |
3772 | rtx xoperands[2]; | |
3773 | ||
3774 | /* SCRATCH_REG will hold an address and maybe the actual data. We want | |
3775 | it in SIMODE regardless of what mode it was originally given | |
3776 | to us. */ | |
3777 | scratch_reg = force_mode (SImode, scratch_reg); | |
3778 | ||
3779 | /* Force the constant into memory and put the address of the | |
3780 | memory location into scratch_reg. */ | |
3781 | xoperands[0] = scratch_reg; | |
3782 | xoperands[1] = XEXP (force_const_mem (mode, operand1), 0); | |
3783 | emit_insn (gen_rtx_SET (mode, scratch_reg, xoperands[1])); | |
3784 | ||
3785 | /* Now load the destination register. */ | |
3786 | emit_insn (gen_rtx_SET (mode, operand0, | |
3787 | gen_rtx_MEM (mode, scratch_reg))); | |
3788 | return 1; | |
3789 | } | |
3790 | ||
3791 | /* Now have insn-emit do whatever it normally does. */ | |
3792 | return 0; | |
3793 | } | |
3794 | ||
01e304f8 RZ |
3795 | /* Split one or more DImode RTL references into pairs of SImode |
3796 | references. The RTL can be REG, offsettable MEM, integer constant, or | |
3797 | CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to | |
3798 | split and "num" is its length. lo_half and hi_half are output arrays | |
3799 | that parallel "operands". */ | |
3800 | ||
3801 | void | |
3802 | split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[]) | |
3803 | { | |
3804 | while (num--) | |
3805 | { | |
3806 | rtx op = operands[num]; | |
3807 | ||
3808 | /* simplify_subreg refuses to split volatile memory addresses, | |
3809 | but we still have to handle it. */ | |
3810 | if (GET_CODE (op) == MEM) | |
3811 | { | |
3812 | lo_half[num] = adjust_address (op, SImode, 4); | |
3813 | hi_half[num] = adjust_address (op, SImode, 0); | |
3814 | } | |
3815 | else | |
3816 | { | |
3817 | lo_half[num] = simplify_gen_subreg (SImode, op, | |
3818 | GET_MODE (op) == VOIDmode | |
3819 | ? DImode : GET_MODE (op), 4); | |
3820 | hi_half[num] = simplify_gen_subreg (SImode, op, | |
3821 | GET_MODE (op) == VOIDmode | |
3822 | ? DImode : GET_MODE (op), 0); | |
3823 | } | |
3824 | } | |
3825 | } | |
3826 | ||
a40ed0f3 KH |
3827 | /* Split X into a base and a constant offset, storing them in *BASE |
3828 | and *OFFSET respectively. */ | |
3829 | ||
3830 | static void | |
3831 | m68k_split_offset (rtx x, rtx *base, HOST_WIDE_INT *offset) | |
3832 | { | |
3833 | *offset = 0; | |
3834 | if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
3835 | { | |
3836 | *offset += INTVAL (XEXP (x, 1)); | |
3837 | x = XEXP (x, 0); | |
3838 | } | |
3839 | *base = x; | |
3840 | } | |
3841 | ||
3842 | /* Return true if PATTERN is a PARALLEL suitable for a movem or fmovem | |
3843 | instruction. STORE_P says whether the move is a load or store. | |
3844 | ||
3845 | If the instruction uses post-increment or pre-decrement addressing, | |
3846 | AUTOMOD_BASE is the base register and AUTOMOD_OFFSET is the total | |
3847 | adjustment. This adjustment will be made by the first element of | |
3848 | PARALLEL, with the loads or stores starting at element 1. If the | |
3849 | instruction does not use post-increment or pre-decrement addressing, | |
3850 | AUTOMOD_BASE is null, AUTOMOD_OFFSET is 0, and the loads or stores | |
3851 | start at element 0. */ | |
3852 | ||
3853 | bool | |
3854 | m68k_movem_pattern_p (rtx pattern, rtx automod_base, | |
3855 | HOST_WIDE_INT automod_offset, bool store_p) | |
3856 | { | |
3857 | rtx base, mem_base, set, mem, reg, last_reg; | |
3858 | HOST_WIDE_INT offset, mem_offset; | |
3859 | int i, first, len; | |
3860 | enum reg_class rclass; | |
3861 | ||
3862 | len = XVECLEN (pattern, 0); | |
3863 | first = (automod_base != NULL); | |
3864 | ||
3865 | if (automod_base) | |
3866 | { | |
3867 | /* Stores must be pre-decrement and loads must be post-increment. */ | |
3868 | if (store_p != (automod_offset < 0)) | |
3869 | return false; | |
3870 | ||
3871 | /* Work out the base and offset for lowest memory location. */ | |
3872 | base = automod_base; | |
3873 | offset = (automod_offset < 0 ? automod_offset : 0); | |
3874 | } | |
3875 | else | |
3876 | { | |
3877 | /* Allow any valid base and offset in the first access. */ | |
3878 | base = NULL; | |
3879 | offset = 0; | |
3880 | } | |
3881 | ||
3882 | last_reg = NULL; | |
3883 | rclass = NO_REGS; | |
3884 | for (i = first; i < len; i++) | |
3885 | { | |
3886 | /* We need a plain SET. */ | |
3887 | set = XVECEXP (pattern, 0, i); | |
3888 | if (GET_CODE (set) != SET) | |
3889 | return false; | |
3890 | ||
3891 | /* Check that we have a memory location... */ | |
3892 | mem = XEXP (set, !store_p); | |
3893 | if (!MEM_P (mem) || !memory_operand (mem, VOIDmode)) | |
3894 | return false; | |
3895 | ||
3896 | /* ...with the right address. */ | |
3897 | if (base == NULL) | |
3898 | { | |
3899 | m68k_split_offset (XEXP (mem, 0), &base, &offset); | |
3900 | /* The ColdFire instruction only allows (An) and (d16,An) modes. | |
3901 | There are no mode restrictions for 680x0 besides the | |
3902 | automodification rules enforced above. */ | |
3903 | if (TARGET_COLDFIRE | |
3904 | && !m68k_legitimate_base_reg_p (base, reload_completed)) | |
3905 | return false; | |
3906 | } | |
3907 | else | |
3908 | { | |
3909 | m68k_split_offset (XEXP (mem, 0), &mem_base, &mem_offset); | |
3910 | if (!rtx_equal_p (base, mem_base) || offset != mem_offset) | |
3911 | return false; | |
3912 | } | |
3913 | ||
3914 | /* Check that we have a register of the required mode and class. */ | |
3915 | reg = XEXP (set, store_p); | |
3916 | if (!REG_P (reg) | |
3917 | || !HARD_REGISTER_P (reg) | |
3918 | || GET_MODE (reg) != reg_raw_mode[REGNO (reg)]) | |
3919 | return false; | |
3920 | ||
3921 | if (last_reg) | |
3922 | { | |
3923 | /* The register must belong to RCLASS and have a higher number | |
3924 | than the register in the previous SET. */ | |
3925 | if (!TEST_HARD_REG_BIT (reg_class_contents[rclass], REGNO (reg)) | |
3926 | || REGNO (last_reg) >= REGNO (reg)) | |
3927 | return false; | |
3928 | } | |
3929 | else | |
3930 | { | |
3931 | /* Work out which register class we need. */ | |
3932 | if (INT_REGNO_P (REGNO (reg))) | |
3933 | rclass = GENERAL_REGS; | |
3934 | else if (FP_REGNO_P (REGNO (reg))) | |
3935 | rclass = FP_REGS; | |
3936 | else | |
3937 | return false; | |
3938 | } | |
3939 | ||
3940 | last_reg = reg; | |
3941 | offset += GET_MODE_SIZE (GET_MODE (reg)); | |
3942 | } | |
3943 | ||
3944 | /* If we have an automodification, check whether the final offset is OK. */ | |
3945 | if (automod_base && offset != (automod_offset < 0 ? 0 : automod_offset)) | |
3946 | return false; | |
3947 | ||
3948 | /* Reject unprofitable cases. */ | |
3949 | if (len < first + (rclass == FP_REGS ? MIN_FMOVEM_REGS : MIN_MOVEM_REGS)) | |
3950 | return false; | |
3951 | ||
3952 | return true; | |
3953 | } | |
3954 | ||
3955 | /* Return the assembly code template for a movem or fmovem instruction | |
3956 | whose pattern is given by PATTERN. Store the template's operands | |
3957 | in OPERANDS. | |
3958 | ||
3959 | If the instruction uses post-increment or pre-decrement addressing, | |
3960 | AUTOMOD_OFFSET is the total adjustment, otherwise it is 0. STORE_P | |
3961 | is true if this is a store instruction. */ | |
3962 | ||
3963 | const char * | |
3964 | m68k_output_movem (rtx *operands, rtx pattern, | |
3965 | HOST_WIDE_INT automod_offset, bool store_p) | |
3966 | { | |
3967 | unsigned int mask; | |
3968 | int i, first; | |
3969 | ||
3970 | gcc_assert (GET_CODE (pattern) == PARALLEL); | |
3971 | mask = 0; | |
3972 | first = (automod_offset != 0); | |
3973 | for (i = first; i < XVECLEN (pattern, 0); i++) | |
3974 | { | |
3975 | /* When using movem with pre-decrement addressing, register X + D0_REG | |
3976 | is controlled by bit 15 - X. For all other addressing modes, | |
3977 | register X + D0_REG is controlled by bit X. Confusingly, the | |
3978 | register mask for fmovem is in the opposite order to that for | |
3979 | movem. */ | |
3980 | unsigned int regno; | |
3981 | ||
3982 | gcc_assert (MEM_P (XEXP (XVECEXP (pattern, 0, i), !store_p))); | |
3983 | gcc_assert (REG_P (XEXP (XVECEXP (pattern, 0, i), store_p))); | |
3984 | regno = REGNO (XEXP (XVECEXP (pattern, 0, i), store_p)); | |
3985 | if (automod_offset < 0) | |
3986 | { | |
3987 | if (FP_REGNO_P (regno)) | |
3988 | mask |= 1 << (regno - FP0_REG); | |
3989 | else | |
3990 | mask |= 1 << (15 - (regno - D0_REG)); | |
3991 | } | |
3992 | else | |
3993 | { | |
3994 | if (FP_REGNO_P (regno)) | |
3995 | mask |= 1 << (7 - (regno - FP0_REG)); | |
3996 | else | |
3997 | mask |= 1 << (regno - D0_REG); | |
3998 | } | |
3999 | } | |
4000 | CC_STATUS_INIT; | |
4001 | ||
4002 | if (automod_offset == 0) | |
4003 | operands[0] = XEXP (XEXP (XVECEXP (pattern, 0, first), !store_p), 0); | |
4004 | else if (automod_offset < 0) | |
4005 | operands[0] = gen_rtx_PRE_DEC (Pmode, SET_DEST (XVECEXP (pattern, 0, 0))); | |
4006 | else | |
4007 | operands[0] = gen_rtx_POST_INC (Pmode, SET_DEST (XVECEXP (pattern, 0, 0))); | |
4008 | operands[1] = GEN_INT (mask); | |
4009 | if (FP_REGNO_P (REGNO (XEXP (XVECEXP (pattern, 0, first), store_p)))) | |
4010 | { | |
4011 | if (store_p) | |
1fae2d80 | 4012 | return "fmovem %1,%a0"; |
a40ed0f3 | 4013 | else |
1fae2d80 | 4014 | return "fmovem %a0,%1"; |
a40ed0f3 KH |
4015 | } |
4016 | else | |
4017 | { | |
4018 | if (store_p) | |
1fae2d80 | 4019 | return "movem%.l %1,%a0"; |
a40ed0f3 | 4020 | else |
1fae2d80 | 4021 | return "movem%.l %a0,%1"; |
a40ed0f3 KH |
4022 | } |
4023 | } | |
4024 | ||
79e68feb RS |
4025 | /* Return a REG that occurs in ADDR with coefficient 1. |
4026 | ADDR can be effectively incremented by incrementing REG. */ | |
4027 | ||
4028 | static rtx | |
8a4a2253 | 4029 | find_addr_reg (rtx addr) |
79e68feb RS |
4030 | { |
4031 | while (GET_CODE (addr) == PLUS) | |
4032 | { | |
4033 | if (GET_CODE (XEXP (addr, 0)) == REG) | |
4034 | addr = XEXP (addr, 0); | |
4035 | else if (GET_CODE (XEXP (addr, 1)) == REG) | |
4036 | addr = XEXP (addr, 1); | |
4037 | else if (CONSTANT_P (XEXP (addr, 0))) | |
4038 | addr = XEXP (addr, 1); | |
4039 | else if (CONSTANT_P (XEXP (addr, 1))) | |
4040 | addr = XEXP (addr, 0); | |
4041 | else | |
4761e388 | 4042 | gcc_unreachable (); |
79e68feb | 4043 | } |
4761e388 NS |
4044 | gcc_assert (GET_CODE (addr) == REG); |
4045 | return addr; | |
79e68feb | 4046 | } |
9ee3c687 | 4047 | |
c16eadc7 | 4048 | /* Output assembler code to perform a 32-bit 3-operand add. */ |
9ee3c687 | 4049 | |
5505f548 | 4050 | const char * |
8a4a2253 | 4051 | output_addsi3 (rtx *operands) |
9ee3c687 JW |
4052 | { |
4053 | if (! operands_match_p (operands[0], operands[1])) | |
4054 | { | |
4055 | if (!ADDRESS_REG_P (operands[1])) | |
4056 | { | |
4057 | rtx tmp = operands[1]; | |
4058 | ||
4059 | operands[1] = operands[2]; | |
4060 | operands[2] = tmp; | |
4061 | } | |
4062 | ||
4063 | /* These insns can result from reloads to access | |
4064 | stack slots over 64k from the frame pointer. */ | |
4065 | if (GET_CODE (operands[2]) == CONST_INT | |
218d5a87 | 4066 | && (INTVAL (operands[2]) < -32768 || INTVAL (operands[2]) > 32767)) |
8c61b6c1 | 4067 | return "move%.l %2,%0\n\tadd%.l %1,%0"; |
9ee3c687 | 4068 | if (GET_CODE (operands[2]) == REG) |
4b3d1177 KH |
4069 | return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0"; |
4070 | return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0"; | |
9ee3c687 JW |
4071 | } |
4072 | if (GET_CODE (operands[2]) == CONST_INT) | |
4073 | { | |
9ee3c687 JW |
4074 | if (INTVAL (operands[2]) > 0 |
4075 | && INTVAL (operands[2]) <= 8) | |
4076 | return "addq%.l %2,%0"; | |
4077 | if (INTVAL (operands[2]) < 0 | |
4078 | && INTVAL (operands[2]) >= -8) | |
4079 | { | |
c5c76735 | 4080 | operands[2] = GEN_INT (- INTVAL (operands[2])); |
9ee3c687 JW |
4081 | return "subq%.l %2,%0"; |
4082 | } | |
4083 | /* On the CPU32 it is faster to use two addql instructions to | |
4084 | add a small integer (8 < N <= 16) to a register. | |
7a1929e1 | 4085 | Likewise for subql. */ |
fe95f2f7 | 4086 | if (TUNE_CPU32 && REG_P (operands[0])) |
9ee3c687 JW |
4087 | { |
4088 | if (INTVAL (operands[2]) > 8 | |
4089 | && INTVAL (operands[2]) <= 16) | |
4090 | { | |
1d8eaa6b | 4091 | operands[2] = GEN_INT (INTVAL (operands[2]) - 8); |
3b4b85c9 | 4092 | return "addq%.l #8,%0\n\taddq%.l %2,%0"; |
9ee3c687 JW |
4093 | } |
4094 | if (INTVAL (operands[2]) < -8 | |
4095 | && INTVAL (operands[2]) >= -16) | |
4096 | { | |
c5c76735 | 4097 | operands[2] = GEN_INT (- INTVAL (operands[2]) - 8); |
3b4b85c9 | 4098 | return "subq%.l #8,%0\n\tsubq%.l %2,%0"; |
9ee3c687 JW |
4099 | } |
4100 | } | |
9ee3c687 JW |
4101 | if (ADDRESS_REG_P (operands[0]) |
4102 | && INTVAL (operands[2]) >= -0x8000 | |
4103 | && INTVAL (operands[2]) < 0x8000) | |
4104 | { | |
fe95f2f7 | 4105 | if (TUNE_68040) |
9ee3c687 JW |
4106 | return "add%.w %2,%0"; |
4107 | else | |
4b3d1177 | 4108 | return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0"; |
9ee3c687 JW |
4109 | } |
4110 | } | |
4111 | return "add%.l %2,%0"; | |
4112 | } | |
79e68feb RS |
4113 | \f |
4114 | /* Store in cc_status the expressions that the condition codes will | |
4115 | describe after execution of an instruction whose pattern is EXP. | |
4116 | Do not alter them if the instruction would not alter the cc's. */ | |
4117 | ||
4118 | /* On the 68000, all the insns to store in an address register fail to | |
4119 | set the cc's. However, in some cases these instructions can make it | |
4120 | possibly invalid to use the saved cc's. In those cases we clear out | |
4121 | some or all of the saved cc's so they won't be used. */ | |
4122 | ||
1d8eaa6b | 4123 | void |
8a4a2253 | 4124 | notice_update_cc (rtx exp, rtx insn) |
79e68feb | 4125 | { |
1a8965c4 | 4126 | if (GET_CODE (exp) == SET) |
79e68feb RS |
4127 | { |
4128 | if (GET_CODE (SET_SRC (exp)) == CALL) | |
a0a7fbc9 | 4129 | CC_STATUS_INIT; |
79e68feb RS |
4130 | else if (ADDRESS_REG_P (SET_DEST (exp))) |
4131 | { | |
f5963e61 | 4132 | if (cc_status.value1 && modified_in_p (cc_status.value1, insn)) |
79e68feb | 4133 | cc_status.value1 = 0; |
f5963e61 | 4134 | if (cc_status.value2 && modified_in_p (cc_status.value2, insn)) |
79e68feb RS |
4135 | cc_status.value2 = 0; |
4136 | } | |
f6ab62e8 RS |
4137 | /* fmoves to memory or data registers do not set the condition |
4138 | codes. Normal moves _do_ set the condition codes, but not in | |
4139 | a way that is appropriate for comparison with 0, because -0.0 | |
4140 | would be treated as a negative nonzero number. Note that it | |
88512ba0 | 4141 | isn't appropriate to conditionalize this restriction on |
f6ab62e8 RS |
4142 | HONOR_SIGNED_ZEROS because that macro merely indicates whether |
4143 | we care about the difference between -0.0 and +0.0. */ | |
79e68feb RS |
4144 | else if (!FP_REG_P (SET_DEST (exp)) |
4145 | && SET_DEST (exp) != cc0_rtx | |
4146 | && (FP_REG_P (SET_SRC (exp)) | |
4147 | || GET_CODE (SET_SRC (exp)) == FIX | |
f6ab62e8 | 4148 | || FLOAT_MODE_P (GET_MODE (SET_DEST (exp))))) |
a0a7fbc9 | 4149 | CC_STATUS_INIT; |
79e68feb RS |
4150 | /* A pair of move insns doesn't produce a useful overall cc. */ |
4151 | else if (!FP_REG_P (SET_DEST (exp)) | |
4152 | && !FP_REG_P (SET_SRC (exp)) | |
4153 | && GET_MODE_SIZE (GET_MODE (SET_SRC (exp))) > 4 | |
4154 | && (GET_CODE (SET_SRC (exp)) == REG | |
4155 | || GET_CODE (SET_SRC (exp)) == MEM | |
4156 | || GET_CODE (SET_SRC (exp)) == CONST_DOUBLE)) | |
a0a7fbc9 | 4157 | CC_STATUS_INIT; |
e1dff52a | 4158 | else if (SET_DEST (exp) != pc_rtx) |
79e68feb RS |
4159 | { |
4160 | cc_status.flags = 0; | |
e1dff52a KH |
4161 | cc_status.value1 = SET_DEST (exp); |
4162 | cc_status.value2 = SET_SRC (exp); | |
79e68feb RS |
4163 | } |
4164 | } | |
4165 | else if (GET_CODE (exp) == PARALLEL | |
4166 | && GET_CODE (XVECEXP (exp, 0, 0)) == SET) | |
4167 | { | |
e1dff52a KH |
4168 | rtx dest = SET_DEST (XVECEXP (exp, 0, 0)); |
4169 | rtx src = SET_SRC (XVECEXP (exp, 0, 0)); | |
4170 | ||
4171 | if (ADDRESS_REG_P (dest)) | |
79e68feb | 4172 | CC_STATUS_INIT; |
e1dff52a | 4173 | else if (dest != pc_rtx) |
79e68feb RS |
4174 | { |
4175 | cc_status.flags = 0; | |
e1dff52a KH |
4176 | cc_status.value1 = dest; |
4177 | cc_status.value2 = src; | |
79e68feb RS |
4178 | } |
4179 | } | |
4180 | else | |
4181 | CC_STATUS_INIT; | |
4182 | if (cc_status.value2 != 0 | |
4183 | && ADDRESS_REG_P (cc_status.value2) | |
4184 | && GET_MODE (cc_status.value2) == QImode) | |
4185 | CC_STATUS_INIT; | |
1a8965c4 | 4186 | if (cc_status.value2 != 0) |
79e68feb RS |
4187 | switch (GET_CODE (cc_status.value2)) |
4188 | { | |
996a5f59 | 4189 | case ASHIFT: case ASHIFTRT: case LSHIFTRT: |
79e68feb | 4190 | case ROTATE: case ROTATERT: |
a126dc3a RH |
4191 | /* These instructions always clear the overflow bit, and set |
4192 | the carry to the bit shifted out. */ | |
1afac9a6 | 4193 | cc_status.flags |= CC_OVERFLOW_UNUSABLE | CC_NO_CARRY; |
a126dc3a RH |
4194 | break; |
4195 | ||
4196 | case PLUS: case MINUS: case MULT: | |
4197 | case DIV: case UDIV: case MOD: case UMOD: case NEG: | |
79e68feb RS |
4198 | if (GET_MODE (cc_status.value2) != VOIDmode) |
4199 | cc_status.flags |= CC_NO_OVERFLOW; | |
4200 | break; | |
4201 | case ZERO_EXTEND: | |
4202 | /* (SET r1 (ZERO_EXTEND r2)) on this machine | |
4203 | ends with a move insn moving r2 in r2's mode. | |
4204 | Thus, the cc's are set for r2. | |
7a1929e1 | 4205 | This can set N bit spuriously. */ |
79e68feb | 4206 | cc_status.flags |= CC_NOT_NEGATIVE; |
1d8eaa6b AS |
4207 | |
4208 | default: | |
4209 | break; | |
79e68feb RS |
4210 | } |
4211 | if (cc_status.value1 && GET_CODE (cc_status.value1) == REG | |
4212 | && cc_status.value2 | |
4213 | && reg_overlap_mentioned_p (cc_status.value1, cc_status.value2)) | |
4214 | cc_status.value2 = 0; | |
1adb2fb9 AS |
4215 | /* Check for PRE_DEC in dest modifying a register used in src. */ |
4216 | if (cc_status.value1 && GET_CODE (cc_status.value1) == MEM | |
4217 | && GET_CODE (XEXP (cc_status.value1, 0)) == PRE_DEC | |
4218 | && cc_status.value2 | |
4219 | && reg_overlap_mentioned_p (XEXP (XEXP (cc_status.value1, 0), 0), | |
4220 | cc_status.value2)) | |
4221 | cc_status.value2 = 0; | |
79e68feb | 4222 | if (((cc_status.value1 && FP_REG_P (cc_status.value1)) |
1a8965c4 | 4223 | || (cc_status.value2 && FP_REG_P (cc_status.value2)))) |
79e68feb | 4224 | cc_status.flags = CC_IN_68881; |
67595cbb RZ |
4225 | if (cc_status.value2 && GET_CODE (cc_status.value2) == COMPARE |
4226 | && GET_MODE_CLASS (GET_MODE (XEXP (cc_status.value2, 0))) == MODE_FLOAT) | |
4227 | { | |
4228 | cc_status.flags = CC_IN_68881; | |
695074be JB |
4229 | if (!FP_REG_P (XEXP (cc_status.value2, 0)) |
4230 | && FP_REG_P (XEXP (cc_status.value2, 1))) | |
67595cbb RZ |
4231 | cc_status.flags |= CC_REVERSED; |
4232 | } | |
79e68feb RS |
4233 | } |
4234 | \f | |
5505f548 | 4235 | const char * |
8a4a2253 | 4236 | output_move_const_double (rtx *operands) |
79e68feb | 4237 | { |
1a8965c4 | 4238 | int code = standard_68881_constant_p (operands[1]); |
79e68feb | 4239 | |
1a8965c4 | 4240 | if (code != 0) |
79e68feb | 4241 | { |
1a8965c4 | 4242 | static char buf[40]; |
79e68feb | 4243 | |
3b4b85c9 | 4244 | sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff); |
1a8965c4 | 4245 | return buf; |
79e68feb | 4246 | } |
1a8965c4 | 4247 | return "fmove%.d %1,%0"; |
79e68feb RS |
4248 | } |
4249 | ||
5505f548 | 4250 | const char * |
8a4a2253 | 4251 | output_move_const_single (rtx *operands) |
79e68feb | 4252 | { |
1a8965c4 | 4253 | int code = standard_68881_constant_p (operands[1]); |
79e68feb | 4254 | |
1a8965c4 | 4255 | if (code != 0) |
79e68feb | 4256 | { |
1a8965c4 | 4257 | static char buf[40]; |
79e68feb | 4258 | |
3b4b85c9 | 4259 | sprintf (buf, "fmovecr #0x%x,%%0", code & 0xff); |
1a8965c4 | 4260 | return buf; |
79e68feb | 4261 | } |
1a8965c4 | 4262 | return "fmove%.s %f1,%0"; |
79e68feb RS |
4263 | } |
4264 | ||
4265 | /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get | |
4266 | from the "fmovecr" instruction. | |
4267 | The value, anded with 0xff, gives the code to use in fmovecr | |
4268 | to get the desired constant. */ | |
4269 | ||
7a1929e1 | 4270 | /* This code has been fixed for cross-compilation. */ |
c1cfb2ae RS |
4271 | |
4272 | static int inited_68881_table = 0; | |
4273 | ||
5505f548 | 4274 | static const char *const strings_68881[7] = { |
c1cfb2ae RS |
4275 | "0.0", |
4276 | "1.0", | |
4277 | "10.0", | |
4278 | "100.0", | |
4279 | "10000.0", | |
4280 | "1e8", | |
4281 | "1e16" | |
a0a7fbc9 | 4282 | }; |
c1cfb2ae | 4283 | |
8b60264b | 4284 | static const int codes_68881[7] = { |
c1cfb2ae RS |
4285 | 0x0f, |
4286 | 0x32, | |
4287 | 0x33, | |
4288 | 0x34, | |
4289 | 0x35, | |
4290 | 0x36, | |
4291 | 0x37 | |
a0a7fbc9 | 4292 | }; |
c1cfb2ae RS |
4293 | |
4294 | REAL_VALUE_TYPE values_68881[7]; | |
4295 | ||
4296 | /* Set up values_68881 array by converting the decimal values | |
7a1929e1 | 4297 | strings_68881 to binary. */ |
c1cfb2ae RS |
4298 | |
4299 | void | |
8a4a2253 | 4300 | init_68881_table (void) |
c1cfb2ae RS |
4301 | { |
4302 | int i; | |
4303 | REAL_VALUE_TYPE r; | |
4304 | enum machine_mode mode; | |
4305 | ||
16d82c3c | 4306 | mode = SFmode; |
c1cfb2ae RS |
4307 | for (i = 0; i < 7; i++) |
4308 | { | |
4309 | if (i == 6) | |
16d82c3c | 4310 | mode = DFmode; |
c1cfb2ae RS |
4311 | r = REAL_VALUE_ATOF (strings_68881[i], mode); |
4312 | values_68881[i] = r; | |
4313 | } | |
4314 | inited_68881_table = 1; | |
4315 | } | |
79e68feb RS |
4316 | |
4317 | int | |
8a4a2253 | 4318 | standard_68881_constant_p (rtx x) |
79e68feb | 4319 | { |
c1cfb2ae RS |
4320 | REAL_VALUE_TYPE r; |
4321 | int i; | |
79e68feb | 4322 | |
e18db50d | 4323 | /* fmovecr must be emulated on the 68040 and 68060, so it shouldn't be |
7a1929e1 | 4324 | used at all on those chips. */ |
9cf106c8 | 4325 | if (TUNE_68040_60) |
79e68feb RS |
4326 | return 0; |
4327 | ||
c1cfb2ae RS |
4328 | if (! inited_68881_table) |
4329 | init_68881_table (); | |
4330 | ||
4331 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
4332 | ||
64c0b414 AS |
4333 | /* Use REAL_VALUES_IDENTICAL instead of REAL_VALUES_EQUAL so that -0.0 |
4334 | is rejected. */ | |
c1cfb2ae RS |
4335 | for (i = 0; i < 6; i++) |
4336 | { | |
64c0b414 | 4337 | if (REAL_VALUES_IDENTICAL (r, values_68881[i])) |
c1cfb2ae RS |
4338 | return (codes_68881[i]); |
4339 | } | |
4340 | ||
79e68feb RS |
4341 | if (GET_MODE (x) == SFmode) |
4342 | return 0; | |
c1cfb2ae RS |
4343 | |
4344 | if (REAL_VALUES_EQUAL (r, values_68881[6])) | |
4345 | return (codes_68881[6]); | |
4346 | ||
79e68feb RS |
4347 | /* larger powers of ten in the constants ram are not used |
4348 | because they are not equal to a `double' C constant. */ | |
4349 | return 0; | |
4350 | } | |
4351 | ||
4352 | /* If X is a floating-point constant, return the logarithm of X base 2, | |
4353 | or 0 if X is not a power of 2. */ | |
4354 | ||
4355 | int | |
8a4a2253 | 4356 | floating_exact_log2 (rtx x) |
79e68feb | 4357 | { |
c1cfb2ae | 4358 | REAL_VALUE_TYPE r, r1; |
eaff3bf8 | 4359 | int exp; |
79e68feb | 4360 | |
c1cfb2ae | 4361 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
79e68feb | 4362 | |
eaff3bf8 | 4363 | if (REAL_VALUES_LESS (r, dconst1)) |
79e68feb RS |
4364 | return 0; |
4365 | ||
eaff3bf8 | 4366 | exp = real_exponent (&r); |
6ef9a246 | 4367 | real_2expN (&r1, exp, DFmode); |
eaff3bf8 RH |
4368 | if (REAL_VALUES_EQUAL (r1, r)) |
4369 | return exp; | |
4370 | ||
79e68feb RS |
4371 | return 0; |
4372 | } | |
4373 | \f | |
79e68feb RS |
4374 | /* A C compound statement to output to stdio stream STREAM the |
4375 | assembler syntax for an instruction operand X. X is an RTL | |
4376 | expression. | |
4377 | ||
4378 | CODE is a value that can be used to specify one of several ways | |
4379 | of printing the operand. It is used when identical operands | |
4380 | must be printed differently depending on the context. CODE | |
4381 | comes from the `%' specification that was used to request | |
4382 | printing of the operand. If the specification was just `%DIGIT' | |
4383 | then CODE is 0; if the specification was `%LTR DIGIT' then CODE | |
4384 | is the ASCII code for LTR. | |
4385 | ||
4386 | If X is a register, this macro should print the register's name. | |
4387 | The names can be found in an array `reg_names' whose type is | |
4388 | `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'. | |
4389 | ||
4390 | When the machine description has a specification `%PUNCT' (a `%' | |
4391 | followed by a punctuation character), this macro is called with | |
4392 | a null pointer for X and the punctuation character for CODE. | |
4393 | ||
4394 | The m68k specific codes are: | |
4395 | ||
4396 | '.' for dot needed in Motorola-style opcode names. | |
4397 | '-' for an operand pushing on the stack: | |
4398 | sp@-, -(sp) or -(%sp) depending on the style of syntax. | |
4399 | '+' for an operand pushing on the stack: | |
4400 | sp@+, (sp)+ or (%sp)+ depending on the style of syntax. | |
4401 | '@' for a reference to the top word on the stack: | |
4402 | sp@, (sp) or (%sp) depending on the style of syntax. | |
4403 | '#' for an immediate operand prefix (# in MIT and Motorola syntax | |
5ee084df | 4404 | but & in SGS syntax). |
79e68feb RS |
4405 | '!' for the cc register (used in an `and to cc' insn). |
4406 | '$' for the letter `s' in an op code, but only on the 68040. | |
4407 | '&' for the letter `d' in an op code, but only on the 68040. | |
2ac5f14a | 4408 | '/' for register prefix needed by longlong.h. |
a40ed0f3 | 4409 | '?' for m68k_library_id_string |
79e68feb RS |
4410 | |
4411 | 'b' for byte insn (no effect, on the Sun; this is for the ISI). | |
4412 | 'd' to force memory addressing to be absolute, not relative. | |
4413 | 'f' for float insn (print a CONST_DOUBLE as a float rather than in hex) | |
79e68feb RS |
4414 | 'x' for float insn (print a CONST_DOUBLE as a float rather than in hex), |
4415 | or print pair of registers as rx:ry. | |
29ca003a RS |
4416 | 'p' print an address with @PLTPC attached, but only if the operand |
4417 | is not locally-bound. */ | |
79e68feb RS |
4418 | |
4419 | void | |
8a4a2253 | 4420 | print_operand (FILE *file, rtx op, int letter) |
79e68feb | 4421 | { |
79e68feb RS |
4422 | if (letter == '.') |
4423 | { | |
e6d98cb0 BI |
4424 | if (MOTOROLA) |
4425 | fprintf (file, "."); | |
79e68feb RS |
4426 | } |
4427 | else if (letter == '#') | |
e6d98cb0 | 4428 | asm_fprintf (file, "%I"); |
79e68feb | 4429 | else if (letter == '-') |
4b3d1177 | 4430 | asm_fprintf (file, MOTOROLA ? "-(%Rsp)" : "%Rsp@-"); |
79e68feb | 4431 | else if (letter == '+') |
4b3d1177 | 4432 | asm_fprintf (file, MOTOROLA ? "(%Rsp)+" : "%Rsp@+"); |
79e68feb | 4433 | else if (letter == '@') |
4b3d1177 | 4434 | asm_fprintf (file, MOTOROLA ? "(%Rsp)" : "%Rsp@"); |
79e68feb | 4435 | else if (letter == '!') |
e6d98cb0 | 4436 | asm_fprintf (file, "%Rfpcr"); |
79e68feb RS |
4437 | else if (letter == '$') |
4438 | { | |
b101567e | 4439 | if (TARGET_68040) |
e6d98cb0 | 4440 | fprintf (file, "s"); |
79e68feb RS |
4441 | } |
4442 | else if (letter == '&') | |
4443 | { | |
b101567e | 4444 | if (TARGET_68040) |
e6d98cb0 | 4445 | fprintf (file, "d"); |
79e68feb | 4446 | } |
2ac5f14a | 4447 | else if (letter == '/') |
e6d98cb0 | 4448 | asm_fprintf (file, "%R"); |
a40ed0f3 KH |
4449 | else if (letter == '?') |
4450 | asm_fprintf (file, m68k_library_id_string); | |
29ca003a | 4451 | else if (letter == 'p') |
2c8ec431 | 4452 | { |
29ca003a RS |
4453 | output_addr_const (file, op); |
4454 | if (!(GET_CODE (op) == SYMBOL_REF && SYMBOL_REF_LOCAL_P (op))) | |
4455 | fprintf (file, "@PLTPC"); | |
2c8ec431 | 4456 | } |
79e68feb RS |
4457 | else if (GET_CODE (op) == REG) |
4458 | { | |
1a8965c4 AS |
4459 | if (letter == 'R') |
4460 | /* Print out the second register name of a register pair. | |
4461 | I.e., R (6) => 7. */ | |
01bbf777 | 4462 | fputs (M68K_REGNAME(REGNO (op) + 1), file); |
79e68feb | 4463 | else |
01bbf777 | 4464 | fputs (M68K_REGNAME(REGNO (op)), file); |
79e68feb RS |
4465 | } |
4466 | else if (GET_CODE (op) == MEM) | |
4467 | { | |
4468 | output_address (XEXP (op, 0)); | |
4469 | if (letter == 'd' && ! TARGET_68020 | |
4470 | && CONSTANT_ADDRESS_P (XEXP (op, 0)) | |
4471 | && !(GET_CODE (XEXP (op, 0)) == CONST_INT | |
4472 | && INTVAL (XEXP (op, 0)) < 0x8000 | |
4473 | && INTVAL (XEXP (op, 0)) >= -0x8000)) | |
4b3d1177 | 4474 | fprintf (file, MOTOROLA ? ".l" : ":l"); |
79e68feb | 4475 | } |
79e68feb RS |
4476 | else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == SFmode) |
4477 | { | |
c1cfb2ae | 4478 | REAL_VALUE_TYPE r; |
6ae89ea8 | 4479 | long l; |
c1cfb2ae | 4480 | REAL_VALUE_FROM_CONST_DOUBLE (r, op); |
6ae89ea8 | 4481 | REAL_VALUE_TO_TARGET_SINGLE (r, l); |
429ce992 | 4482 | asm_fprintf (file, "%I0x%lx", l & 0xFFFFFFFF); |
c1cfb2ae RS |
4483 | } |
4484 | else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == XFmode) | |
4485 | { | |
4486 | REAL_VALUE_TYPE r; | |
6ae89ea8 | 4487 | long l[3]; |
c1cfb2ae | 4488 | REAL_VALUE_FROM_CONST_DOUBLE (r, op); |
6ae89ea8 | 4489 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l); |
429ce992 AS |
4490 | asm_fprintf (file, "%I0x%lx%08lx%08lx", l[0] & 0xFFFFFFFF, |
4491 | l[1] & 0xFFFFFFFF, l[2] & 0xFFFFFFFF); | |
79e68feb | 4492 | } |
e2c0a924 | 4493 | else if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == DFmode) |
79e68feb | 4494 | { |
c1cfb2ae | 4495 | REAL_VALUE_TYPE r; |
6ae89ea8 | 4496 | long l[2]; |
c1cfb2ae | 4497 | REAL_VALUE_FROM_CONST_DOUBLE (r, op); |
6ae89ea8 | 4498 | REAL_VALUE_TO_TARGET_DOUBLE (r, l); |
429ce992 | 4499 | asm_fprintf (file, "%I0x%lx%08lx", l[0] & 0xFFFFFFFF, l[1] & 0xFFFFFFFF); |
79e68feb RS |
4500 | } |
4501 | else | |
4502 | { | |
2c8ec431 DL |
4503 | /* Use `print_operand_address' instead of `output_addr_const' |
4504 | to ensure that we print relevant PIC stuff. */ | |
1f85a612 | 4505 | asm_fprintf (file, "%I"); |
2c8ec431 DL |
4506 | if (TARGET_PCREL |
4507 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)) | |
4508 | print_operand_address (file, op); | |
4509 | else | |
4510 | output_addr_const (file, op); | |
79e68feb RS |
4511 | } |
4512 | } | |
4513 | ||
75df395f MK |
4514 | /* Return string for TLS relocation RELOC. */ |
4515 | ||
4516 | static const char * | |
4517 | m68k_get_reloc_decoration (enum m68k_reloc reloc) | |
4518 | { | |
4519 | /* To my knowledge, !MOTOROLA assemblers don't support TLS. */ | |
4520 | gcc_assert (MOTOROLA || reloc == RELOC_GOT); | |
4521 | ||
4522 | switch (reloc) | |
4523 | { | |
4524 | case RELOC_GOT: | |
4525 | if (MOTOROLA) | |
4526 | { | |
4527 | if (flag_pic == 1 && TARGET_68020) | |
4528 | return "@GOT.w"; | |
4529 | else | |
4530 | return "@GOT"; | |
4531 | } | |
4532 | else | |
4533 | { | |
4534 | if (TARGET_68020) | |
4535 | { | |
4536 | switch (flag_pic) | |
4537 | { | |
4538 | case 1: | |
4539 | return ":w"; | |
4540 | case 2: | |
4541 | return ":l"; | |
4542 | default: | |
4543 | return ""; | |
4544 | } | |
4545 | } | |
4546 | } | |
4547 | ||
4548 | case RELOC_TLSGD: | |
4549 | return "@TLSGD"; | |
4550 | ||
4551 | case RELOC_TLSLDM: | |
4552 | return "@TLSLDM"; | |
4553 | ||
4554 | case RELOC_TLSLDO: | |
4555 | return "@TLSLDO"; | |
4556 | ||
4557 | case RELOC_TLSIE: | |
4558 | return "@TLSIE"; | |
4559 | ||
4560 | case RELOC_TLSLE: | |
4561 | return "@TLSLE"; | |
4562 | ||
4563 | default: | |
4564 | gcc_unreachable (); | |
4565 | } | |
4566 | } | |
4567 | ||
cb69db4f | 4568 | /* m68k implementation of TARGET_OUTPUT_ADDR_CONST_EXTRA. */ |
884316ff | 4569 | |
cb69db4f | 4570 | static bool |
884316ff JM |
4571 | m68k_output_addr_const_extra (FILE *file, rtx x) |
4572 | { | |
75df395f MK |
4573 | if (GET_CODE (x) == UNSPEC) |
4574 | { | |
4575 | switch (XINT (x, 1)) | |
4576 | { | |
4577 | case UNSPEC_RELOC16: | |
4578 | case UNSPEC_RELOC32: | |
4579 | output_addr_const (file, XVECEXP (x, 0, 0)); | |
f878882b AS |
4580 | fputs (m68k_get_reloc_decoration |
4581 | ((enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1))), file); | |
75df395f | 4582 | return true; |
884316ff | 4583 | |
75df395f MK |
4584 | default: |
4585 | break; | |
4586 | } | |
4587 | } | |
4588 | ||
4589 | return false; | |
4590 | } | |
4591 | ||
4592 | /* M68K implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */ | |
4593 | ||
4594 | static void | |
4595 | m68k_output_dwarf_dtprel (FILE *file, int size, rtx x) | |
4596 | { | |
4597 | gcc_assert (size == 4); | |
4598 | fputs ("\t.long\t", file); | |
4599 | output_addr_const (file, x); | |
4600 | fputs ("@TLSLDO+0x8000", file); | |
884316ff JM |
4601 | } |
4602 | ||
7b0f476d AS |
4603 | /* In the name of slightly smaller debug output, and to cater to |
4604 | general assembler lossage, recognize various UNSPEC sequences | |
4605 | and turn them back into a direct symbol reference. */ | |
4606 | ||
4607 | static rtx | |
33d67485 | 4608 | m68k_delegitimize_address (rtx orig_x) |
7b0f476d | 4609 | { |
8390b335 AS |
4610 | rtx x; |
4611 | struct m68k_address addr; | |
4612 | rtx unspec; | |
7b0f476d | 4613 | |
33d67485 | 4614 | orig_x = delegitimize_mem_from_attrs (orig_x); |
8390b335 AS |
4615 | x = orig_x; |
4616 | if (MEM_P (x)) | |
4617 | x = XEXP (x, 0); | |
4618 | ||
4619 | if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode) | |
33d67485 AS |
4620 | return orig_x; |
4621 | ||
8390b335 AS |
4622 | if (!m68k_decompose_address (GET_MODE (x), x, false, &addr) |
4623 | || addr.offset == NULL_RTX | |
4624 | || GET_CODE (addr.offset) != CONST) | |
4625 | return orig_x; | |
7b0f476d | 4626 | |
8390b335 AS |
4627 | unspec = XEXP (addr.offset, 0); |
4628 | if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1))) | |
4629 | unspec = XEXP (unspec, 0); | |
4630 | if (GET_CODE (unspec) != UNSPEC | |
4631 | || (XINT (unspec, 1) != UNSPEC_RELOC16 | |
4632 | && XINT (unspec, 1) != UNSPEC_RELOC32)) | |
4633 | return orig_x; | |
4634 | x = XVECEXP (unspec, 0, 0); | |
92cf7399 | 4635 | gcc_assert (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF); |
8390b335 AS |
4636 | if (unspec != XEXP (addr.offset, 0)) |
4637 | x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.offset, 0), 1)); | |
4638 | if (addr.index) | |
7b0f476d | 4639 | { |
8390b335 AS |
4640 | rtx idx = addr.index; |
4641 | if (addr.scale != 1) | |
4642 | idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale)); | |
4643 | x = gen_rtx_PLUS (Pmode, idx, x); | |
7b0f476d | 4644 | } |
8390b335 AS |
4645 | if (addr.base) |
4646 | x = gen_rtx_PLUS (Pmode, addr.base, x); | |
4647 | if (MEM_P (orig_x)) | |
4648 | x = replace_equiv_address_nv (orig_x, x); | |
4649 | return x; | |
7b0f476d AS |
4650 | } |
4651 | ||
79e68feb RS |
4652 | \f |
4653 | /* A C compound statement to output to stdio stream STREAM the | |
4654 | assembler syntax for an instruction operand that is a memory | |
4655 | reference whose address is ADDR. ADDR is an RTL expression. | |
4656 | ||
4657 | Note that this contains a kludge that knows that the only reason | |
4658 | we have an address (plus (label_ref...) (reg...)) when not generating | |
4659 | PIC code is in the insn before a tablejump, and we know that m68k.md | |
4660 | generates a label LInnn: on such an insn. | |
4661 | ||
4662 | It is possible for PIC to generate a (plus (label_ref...) (reg...)) | |
4663 | and we handle that just like we would a (plus (symbol_ref...) (reg...)). | |
4664 | ||
79e68feb RS |
4665 | This routine is responsible for distinguishing between -fpic and -fPIC |
4666 | style relocations in an address. When generating -fpic code the | |
112cdef5 KH |
4667 | offset is output in word mode (e.g. movel a5@(_foo:w), a0). When generating |
4668 | -fPIC code the offset is output in long mode (e.g. movel a5@(_foo:l), a0) */ | |
79e68feb RS |
4669 | |
4670 | void | |
8a4a2253 | 4671 | print_operand_address (FILE *file, rtx addr) |
79e68feb | 4672 | { |
fc2241eb RS |
4673 | struct m68k_address address; |
4674 | ||
4675 | if (!m68k_decompose_address (QImode, addr, true, &address)) | |
4676 | gcc_unreachable (); | |
4677 | ||
4678 | if (address.code == PRE_DEC) | |
4b3d1177 KH |
4679 | fprintf (file, MOTOROLA ? "-(%s)" : "%s@-", |
4680 | M68K_REGNAME (REGNO (address.base))); | |
fc2241eb | 4681 | else if (address.code == POST_INC) |
4b3d1177 KH |
4682 | fprintf (file, MOTOROLA ? "(%s)+" : "%s@+", |
4683 | M68K_REGNAME (REGNO (address.base))); | |
fc2241eb RS |
4684 | else if (!address.base && !address.index) |
4685 | { | |
4686 | /* A constant address. */ | |
4687 | gcc_assert (address.offset == addr); | |
4688 | if (GET_CODE (addr) == CONST_INT) | |
4689 | { | |
4690 | /* (xxx).w or (xxx).l. */ | |
4691 | if (IN_RANGE (INTVAL (addr), -0x8000, 0x7fff)) | |
4b3d1177 | 4692 | fprintf (file, MOTOROLA ? "%d.w" : "%d:w", (int) INTVAL (addr)); |
a0a7fbc9 | 4693 | else |
fc2241eb | 4694 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr)); |
a0a7fbc9 | 4695 | } |
fc2241eb | 4696 | else if (TARGET_PCREL) |
a0a7fbc9 | 4697 | { |
fc2241eb RS |
4698 | /* (d16,PC) or (bd,PC,Xn) (with suppressed index register). */ |
4699 | fputc ('(', file); | |
4700 | output_addr_const (file, addr); | |
4701 | asm_fprintf (file, flag_pic == 1 ? ":w,%Rpc)" : ":l,%Rpc)"); | |
a0a7fbc9 | 4702 | } |
fc2241eb | 4703 | else |
a0a7fbc9 | 4704 | { |
fc2241eb RS |
4705 | /* (xxx).l. We need a special case for SYMBOL_REF if the symbol |
4706 | name ends in `.<letter>', as the last 2 characters can be | |
4707 | mistaken as a size suffix. Put the name in parentheses. */ | |
4708 | if (GET_CODE (addr) == SYMBOL_REF | |
4709 | && strlen (XSTR (addr, 0)) > 2 | |
4710 | && XSTR (addr, 0)[strlen (XSTR (addr, 0)) - 2] == '.') | |
a0a7fbc9 | 4711 | { |
fc2241eb RS |
4712 | putc ('(', file); |
4713 | output_addr_const (file, addr); | |
4714 | putc (')', file); | |
a0a7fbc9 AS |
4715 | } |
4716 | else | |
fc2241eb | 4717 | output_addr_const (file, addr); |
a0a7fbc9 | 4718 | } |
fc2241eb RS |
4719 | } |
4720 | else | |
4721 | { | |
4722 | int labelno; | |
4723 | ||
4724 | /* If ADDR is a (d8,pc,Xn) address, this is the number of the | |
44c7bd63 | 4725 | label being accessed, otherwise it is -1. */ |
fc2241eb RS |
4726 | labelno = (address.offset |
4727 | && !address.base | |
4728 | && GET_CODE (address.offset) == LABEL_REF | |
4729 | ? CODE_LABEL_NUMBER (XEXP (address.offset, 0)) | |
4730 | : -1); | |
4731 | if (MOTOROLA) | |
a0a7fbc9 | 4732 | { |
fc2241eb RS |
4733 | /* Print the "offset(base" component. */ |
4734 | if (labelno >= 0) | |
e59d83aa | 4735 | asm_fprintf (file, "%LL%d(%Rpc,", labelno); |
fc2241eb | 4736 | else |
a0a7fbc9 | 4737 | { |
fc2241eb | 4738 | if (address.offset) |
75df395f MK |
4739 | output_addr_const (file, address.offset); |
4740 | ||
fc2241eb RS |
4741 | putc ('(', file); |
4742 | if (address.base) | |
4743 | fputs (M68K_REGNAME (REGNO (address.base)), file); | |
a0a7fbc9 | 4744 | } |
fc2241eb RS |
4745 | /* Print the ",index" component, if any. */ |
4746 | if (address.index) | |
a0a7fbc9 | 4747 | { |
fc2241eb RS |
4748 | if (address.base) |
4749 | putc (',', file); | |
4750 | fprintf (file, "%s.%c", | |
4751 | M68K_REGNAME (REGNO (address.index)), | |
4752 | GET_MODE (address.index) == HImode ? 'w' : 'l'); | |
4753 | if (address.scale != 1) | |
4754 | fprintf (file, "*%d", address.scale); | |
a0a7fbc9 | 4755 | } |
a0a7fbc9 | 4756 | putc (')', file); |
a0a7fbc9 | 4757 | } |
fc2241eb | 4758 | else /* !MOTOROLA */ |
a0a7fbc9 | 4759 | { |
fc2241eb RS |
4760 | if (!address.offset && !address.index) |
4761 | fprintf (file, "%s@", M68K_REGNAME (REGNO (address.base))); | |
a0a7fbc9 | 4762 | else |
a0a7fbc9 | 4763 | { |
fc2241eb RS |
4764 | /* Print the "base@(offset" component. */ |
4765 | if (labelno >= 0) | |
e59d83aa | 4766 | asm_fprintf (file, "%Rpc@(%LL%d", labelno); |
fc2241eb RS |
4767 | else |
4768 | { | |
4769 | if (address.base) | |
4770 | fputs (M68K_REGNAME (REGNO (address.base)), file); | |
4771 | fprintf (file, "@("); | |
4772 | if (address.offset) | |
75df395f | 4773 | output_addr_const (file, address.offset); |
fc2241eb RS |
4774 | } |
4775 | /* Print the ",index" component, if any. */ | |
4776 | if (address.index) | |
4777 | { | |
4778 | fprintf (file, ",%s:%c", | |
4779 | M68K_REGNAME (REGNO (address.index)), | |
4780 | GET_MODE (address.index) == HImode ? 'w' : 'l'); | |
4781 | if (address.scale != 1) | |
4782 | fprintf (file, ":%d", address.scale); | |
4783 | } | |
a0a7fbc9 AS |
4784 | putc (')', file); |
4785 | } | |
a0a7fbc9 | 4786 | } |
79e68feb RS |
4787 | } |
4788 | } | |
af13f02d JW |
4789 | \f |
4790 | /* Check for cases where a clr insns can be omitted from code using | |
4791 | strict_low_part sets. For example, the second clrl here is not needed: | |
4792 | clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ... | |
4793 | ||
4794 | MODE is the mode of this STRICT_LOW_PART set. FIRST_INSN is the clear | |
4795 | insn we are checking for redundancy. TARGET is the register set by the | |
4796 | clear insn. */ | |
4797 | ||
8a4a2253 | 4798 | bool |
c85e862a | 4799 | strict_low_part_peephole_ok (enum machine_mode mode, rtx_insn *first_insn, |
8a4a2253 | 4800 | rtx target) |
af13f02d | 4801 | { |
c85e862a | 4802 | rtx_insn *p = first_insn; |
af13f02d | 4803 | |
39250081 | 4804 | while ((p = PREV_INSN (p))) |
af13f02d | 4805 | { |
39250081 RZ |
4806 | if (NOTE_INSN_BASIC_BLOCK_P (p)) |
4807 | return false; | |
4808 | ||
4809 | if (NOTE_P (p)) | |
4810 | continue; | |
4811 | ||
af13f02d | 4812 | /* If it isn't an insn, then give up. */ |
39250081 | 4813 | if (!INSN_P (p)) |
8a4a2253 | 4814 | return false; |
af13f02d JW |
4815 | |
4816 | if (reg_set_p (target, p)) | |
4817 | { | |
4818 | rtx set = single_set (p); | |
4819 | rtx dest; | |
4820 | ||
4821 | /* If it isn't an easy to recognize insn, then give up. */ | |
4822 | if (! set) | |
8a4a2253 | 4823 | return false; |
af13f02d JW |
4824 | |
4825 | dest = SET_DEST (set); | |
4826 | ||
4827 | /* If this sets the entire target register to zero, then our | |
4828 | first_insn is redundant. */ | |
4829 | if (rtx_equal_p (dest, target) | |
4830 | && SET_SRC (set) == const0_rtx) | |
8a4a2253 | 4831 | return true; |
af13f02d JW |
4832 | else if (GET_CODE (dest) == STRICT_LOW_PART |
4833 | && GET_CODE (XEXP (dest, 0)) == REG | |
4834 | && REGNO (XEXP (dest, 0)) == REGNO (target) | |
4835 | && (GET_MODE_SIZE (GET_MODE (XEXP (dest, 0))) | |
4836 | <= GET_MODE_SIZE (mode))) | |
4837 | /* This is a strict low part set which modifies less than | |
4838 | we are using, so it is safe. */ | |
4839 | ; | |
4840 | else | |
8a4a2253 | 4841 | return false; |
af13f02d | 4842 | } |
af13f02d JW |
4843 | } |
4844 | ||
8a4a2253 | 4845 | return false; |
af13f02d | 4846 | } |
67cd4f83 | 4847 | |
2c8ec431 DL |
4848 | /* Operand predicates for implementing asymmetric pc-relative addressing |
4849 | on m68k. The m68k supports pc-relative addressing (mode 7, register 2) | |
dab66575 | 4850 | when used as a source operand, but not as a destination operand. |
2c8ec431 DL |
4851 | |
4852 | We model this by restricting the meaning of the basic predicates | |
4853 | (general_operand, memory_operand, etc) to forbid the use of this | |
4854 | addressing mode, and then define the following predicates that permit | |
4855 | this addressing mode. These predicates can then be used for the | |
4856 | source operands of the appropriate instructions. | |
4857 | ||
4858 | n.b. While it is theoretically possible to change all machine patterns | |
4859 | to use this addressing more where permitted by the architecture, | |
4860 | it has only been implemented for "common" cases: SImode, HImode, and | |
4861 | QImode operands, and only for the principle operations that would | |
4862 | require this addressing mode: data movement and simple integer operations. | |
4863 | ||
4864 | In parallel with these new predicates, two new constraint letters | |
4865 | were defined: 'S' and 'T'. 'S' is the -mpcrel analog of 'm'. | |
4866 | 'T' replaces 's' in the non-pcrel case. It is a no-op in the pcrel case. | |
4867 | In the pcrel case 's' is only valid in combination with 'a' registers. | |
4868 | See addsi3, subsi3, cmpsi, and movsi patterns for a better understanding | |
4869 | of how these constraints are used. | |
4870 | ||
4871 | The use of these predicates is strictly optional, though patterns that | |
4872 | don't will cause an extra reload register to be allocated where one | |
4873 | was not necessary: | |
4874 | ||
4875 | lea (abc:w,%pc),%a0 ; need to reload address | |
4876 | moveq &1,%d1 ; since write to pc-relative space | |
4877 | movel %d1,%a0@ ; is not allowed | |
4878 | ... | |
4879 | lea (abc:w,%pc),%a1 ; no need to reload address here | |
4880 | movel %a1@,%d0 ; since "movel (abc:w,%pc),%d0" is ok | |
4881 | ||
4882 | For more info, consult tiemann@cygnus.com. | |
4883 | ||
4884 | ||
4885 | All of the ugliness with predicates and constraints is due to the | |
4886 | simple fact that the m68k does not allow a pc-relative addressing | |
4887 | mode as a destination. gcc does not distinguish between source and | |
4888 | destination addresses. Hence, if we claim that pc-relative address | |
331d9186 | 4889 | modes are valid, e.g. TARGET_LEGITIMATE_ADDRESS_P accepts them, then we |
2c8ec431 DL |
4890 | end up with invalid code. To get around this problem, we left |
4891 | pc-relative modes as invalid addresses, and then added special | |
4892 | predicates and constraints to accept them. | |
4893 | ||
4894 | A cleaner way to handle this is to modify gcc to distinguish | |
4895 | between source and destination addresses. We can then say that | |
4896 | pc-relative is a valid source address but not a valid destination | |
4897 | address, and hopefully avoid a lot of the predicate and constraint | |
4898 | hackery. Unfortunately, this would be a pretty big change. It would | |
4899 | be a useful change for a number of ports, but there aren't any current | |
4900 | plans to undertake this. | |
4901 | ||
4902 | ***************************************************************************/ | |
4903 | ||
4904 | ||
5505f548 | 4905 | const char * |
8a4a2253 | 4906 | output_andsi3 (rtx *operands) |
29ae8a3c RK |
4907 | { |
4908 | int logval; | |
4909 | if (GET_CODE (operands[2]) == CONST_INT | |
25c99d8f | 4910 | && (INTVAL (operands[2]) | 0xffff) == -1 |
29ae8a3c RK |
4911 | && (DATA_REG_P (operands[0]) |
4912 | || offsettable_memref_p (operands[0])) | |
9425fb04 | 4913 | && !TARGET_COLDFIRE) |
29ae8a3c RK |
4914 | { |
4915 | if (GET_CODE (operands[0]) != REG) | |
b72f00af | 4916 | operands[0] = adjust_address (operands[0], HImode, 2); |
1d8eaa6b | 4917 | operands[2] = GEN_INT (INTVAL (operands[2]) & 0xffff); |
29ae8a3c RK |
4918 | /* Do not delete a following tstl %0 insn; that would be incorrect. */ |
4919 | CC_STATUS_INIT; | |
4920 | if (operands[2] == const0_rtx) | |
4921 | return "clr%.w %0"; | |
4922 | return "and%.w %2,%0"; | |
4923 | } | |
4924 | if (GET_CODE (operands[2]) == CONST_INT | |
c4406f74 | 4925 | && (logval = exact_log2 (~ INTVAL (operands[2]) & 0xffffffff)) >= 0 |
29ae8a3c RK |
4926 | && (DATA_REG_P (operands[0]) |
4927 | || offsettable_memref_p (operands[0]))) | |
4928 | { | |
4929 | if (DATA_REG_P (operands[0])) | |
a0a7fbc9 | 4930 | operands[1] = GEN_INT (logval); |
29ae8a3c RK |
4931 | else |
4932 | { | |
b72f00af | 4933 | operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8)); |
1d8eaa6b | 4934 | operands[1] = GEN_INT (logval % 8); |
29ae8a3c RK |
4935 | } |
4936 | /* This does not set condition codes in a standard way. */ | |
4937 | CC_STATUS_INIT; | |
4938 | return "bclr %1,%0"; | |
4939 | } | |
4940 | return "and%.l %2,%0"; | |
4941 | } | |
4942 | ||
5505f548 | 4943 | const char * |
8a4a2253 | 4944 | output_iorsi3 (rtx *operands) |
29ae8a3c RK |
4945 | { |
4946 | register int logval; | |
4947 | if (GET_CODE (operands[2]) == CONST_INT | |
4948 | && INTVAL (operands[2]) >> 16 == 0 | |
4949 | && (DATA_REG_P (operands[0]) | |
4950 | || offsettable_memref_p (operands[0])) | |
9425fb04 | 4951 | && !TARGET_COLDFIRE) |
29ae8a3c RK |
4952 | { |
4953 | if (GET_CODE (operands[0]) != REG) | |
b72f00af | 4954 | operands[0] = adjust_address (operands[0], HImode, 2); |
29ae8a3c RK |
4955 | /* Do not delete a following tstl %0 insn; that would be incorrect. */ |
4956 | CC_STATUS_INIT; | |
4957 | if (INTVAL (operands[2]) == 0xffff) | |
4958 | return "mov%.w %2,%0"; | |
4959 | return "or%.w %2,%0"; | |
4960 | } | |
4961 | if (GET_CODE (operands[2]) == CONST_INT | |
c4406f74 | 4962 | && (logval = exact_log2 (INTVAL (operands[2]) & 0xffffffff)) >= 0 |
29ae8a3c RK |
4963 | && (DATA_REG_P (operands[0]) |
4964 | || offsettable_memref_p (operands[0]))) | |
4965 | { | |
4966 | if (DATA_REG_P (operands[0])) | |
b72f00af | 4967 | operands[1] = GEN_INT (logval); |
29ae8a3c RK |
4968 | else |
4969 | { | |
b72f00af | 4970 | operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8)); |
1d8eaa6b | 4971 | operands[1] = GEN_INT (logval % 8); |
29ae8a3c RK |
4972 | } |
4973 | CC_STATUS_INIT; | |
4974 | return "bset %1,%0"; | |
4975 | } | |
4976 | return "or%.l %2,%0"; | |
4977 | } | |
4978 | ||
5505f548 | 4979 | const char * |
8a4a2253 | 4980 | output_xorsi3 (rtx *operands) |
29ae8a3c RK |
4981 | { |
4982 | register int logval; | |
4983 | if (GET_CODE (operands[2]) == CONST_INT | |
4984 | && INTVAL (operands[2]) >> 16 == 0 | |
4985 | && (offsettable_memref_p (operands[0]) || DATA_REG_P (operands[0])) | |
9425fb04 | 4986 | && !TARGET_COLDFIRE) |
29ae8a3c RK |
4987 | { |
4988 | if (! DATA_REG_P (operands[0])) | |
b72f00af | 4989 | operands[0] = adjust_address (operands[0], HImode, 2); |
29ae8a3c RK |
4990 | /* Do not delete a following tstl %0 insn; that would be incorrect. */ |
4991 | CC_STATUS_INIT; | |
4992 | if (INTVAL (operands[2]) == 0xffff) | |
4993 | return "not%.w %0"; | |
4994 | return "eor%.w %2,%0"; | |
4995 | } | |
4996 | if (GET_CODE (operands[2]) == CONST_INT | |
c4406f74 | 4997 | && (logval = exact_log2 (INTVAL (operands[2]) & 0xffffffff)) >= 0 |
29ae8a3c RK |
4998 | && (DATA_REG_P (operands[0]) |
4999 | || offsettable_memref_p (operands[0]))) | |
5000 | { | |
5001 | if (DATA_REG_P (operands[0])) | |
b72f00af | 5002 | operands[1] = GEN_INT (logval); |
29ae8a3c RK |
5003 | else |
5004 | { | |
b72f00af | 5005 | operands[0] = adjust_address (operands[0], SImode, 3 - (logval / 8)); |
1d8eaa6b | 5006 | operands[1] = GEN_INT (logval % 8); |
29ae8a3c RK |
5007 | } |
5008 | CC_STATUS_INIT; | |
5009 | return "bchg %1,%0"; | |
5010 | } | |
5011 | return "eor%.l %2,%0"; | |
5012 | } | |
7c262518 | 5013 | |
29ca003a RS |
5014 | /* Return the instruction that should be used for a call to address X, |
5015 | which is known to be in operand 0. */ | |
5016 | ||
5017 | const char * | |
5018 | output_call (rtx x) | |
5019 | { | |
5020 | if (symbolic_operand (x, VOIDmode)) | |
5021 | return m68k_symbolic_call; | |
5022 | else | |
5023 | return "jsr %a0"; | |
5024 | } | |
5025 | ||
f7e70894 RS |
5026 | /* Likewise sibling calls. */ |
5027 | ||
5028 | const char * | |
5029 | output_sibcall (rtx x) | |
5030 | { | |
5031 | if (symbolic_operand (x, VOIDmode)) | |
5032 | return m68k_symbolic_jump; | |
5033 | else | |
5034 | return "jmp %a0"; | |
5035 | } | |
5036 | ||
c590b625 | 5037 | static void |
8a4a2253 | 5038 | m68k_output_mi_thunk (FILE *file, tree thunk ATTRIBUTE_UNUSED, |
4ab870f5 | 5039 | HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, |
8a4a2253 | 5040 | tree function) |
483ab821 | 5041 | { |
c85e862a DM |
5042 | rtx this_slot, offset, addr, mem, tmp; |
5043 | rtx_insn *insn; | |
e0601576 RH |
5044 | |
5045 | /* Avoid clobbering the struct value reg by using the | |
5046 | static chain reg as a temporary. */ | |
5047 | tmp = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM); | |
4ab870f5 RS |
5048 | |
5049 | /* Pretend to be a post-reload pass while generating rtl. */ | |
4ab870f5 | 5050 | reload_completed = 1; |
4ab870f5 RS |
5051 | |
5052 | /* The "this" pointer is stored at 4(%sp). */ | |
0a81f074 RS |
5053 | this_slot = gen_rtx_MEM (Pmode, plus_constant (Pmode, |
5054 | stack_pointer_rtx, 4)); | |
4ab870f5 RS |
5055 | |
5056 | /* Add DELTA to THIS. */ | |
5057 | if (delta != 0) | |
5050d266 | 5058 | { |
4ab870f5 RS |
5059 | /* Make the offset a legitimate operand for memory addition. */ |
5060 | offset = GEN_INT (delta); | |
5061 | if ((delta < -8 || delta > 8) | |
5062 | && (TARGET_COLDFIRE || USE_MOVQ (delta))) | |
5063 | { | |
5064 | emit_move_insn (gen_rtx_REG (Pmode, D0_REG), offset); | |
5065 | offset = gen_rtx_REG (Pmode, D0_REG); | |
5066 | } | |
5067 | emit_insn (gen_add3_insn (copy_rtx (this_slot), | |
5068 | copy_rtx (this_slot), offset)); | |
5050d266 | 5069 | } |
c590b625 | 5070 | |
4ab870f5 RS |
5071 | /* If needed, add *(*THIS + VCALL_OFFSET) to THIS. */ |
5072 | if (vcall_offset != 0) | |
5073 | { | |
5074 | /* Set the static chain register to *THIS. */ | |
e0601576 RH |
5075 | emit_move_insn (tmp, this_slot); |
5076 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
4ab870f5 RS |
5077 | |
5078 | /* Set ADDR to a legitimate address for *THIS + VCALL_OFFSET. */ | |
0a81f074 | 5079 | addr = plus_constant (Pmode, tmp, vcall_offset); |
4ab870f5 RS |
5080 | if (!m68k_legitimate_address_p (Pmode, addr, true)) |
5081 | { | |
e0601576 RH |
5082 | emit_insn (gen_rtx_SET (VOIDmode, tmp, addr)); |
5083 | addr = tmp; | |
4ab870f5 | 5084 | } |
c590b625 | 5085 | |
4ab870f5 RS |
5086 | /* Load the offset into %d0 and add it to THIS. */ |
5087 | emit_move_insn (gen_rtx_REG (Pmode, D0_REG), | |
5088 | gen_rtx_MEM (Pmode, addr)); | |
5089 | emit_insn (gen_add3_insn (copy_rtx (this_slot), | |
5090 | copy_rtx (this_slot), | |
5091 | gen_rtx_REG (Pmode, D0_REG))); | |
5092 | } | |
29ca003a | 5093 | |
4ab870f5 RS |
5094 | /* Jump to the target function. Use a sibcall if direct jumps are |
5095 | allowed, otherwise load the address into a register first. */ | |
5096 | mem = DECL_RTL (function); | |
5097 | if (!sibcall_operand (XEXP (mem, 0), VOIDmode)) | |
5098 | { | |
5099 | gcc_assert (flag_pic); | |
c590b625 | 5100 | |
4ab870f5 RS |
5101 | if (!TARGET_SEP_DATA) |
5102 | { | |
5103 | /* Use the static chain register as a temporary (call-clobbered) | |
5104 | GOT pointer for this function. We can use the static chain | |
5105 | register because it isn't live on entry to the thunk. */ | |
6fb5fa3c | 5106 | SET_REGNO (pic_offset_table_rtx, STATIC_CHAIN_REGNUM); |
4ab870f5 RS |
5107 | emit_insn (gen_load_got (pic_offset_table_rtx)); |
5108 | } | |
e0601576 RH |
5109 | legitimize_pic_address (XEXP (mem, 0), Pmode, tmp); |
5110 | mem = replace_equiv_address (mem, tmp); | |
4ab870f5 RS |
5111 | } |
5112 | insn = emit_call_insn (gen_sibcall (mem, const0_rtx)); | |
5113 | SIBLING_CALL_P (insn) = 1; | |
5114 | ||
5115 | /* Run just enough of rest_of_compilation. */ | |
5116 | insn = get_insns (); | |
5117 | split_all_insns_noflow (); | |
5118 | final_start_function (insn, file, 1); | |
5119 | final (insn, file, 1); | |
5120 | final_end_function (); | |
5121 | ||
5122 | /* Clean up the vars set above. */ | |
5123 | reload_completed = 0; | |
4ab870f5 RS |
5124 | |
5125 | /* Restore the original PIC register. */ | |
5126 | if (flag_pic) | |
6fb5fa3c | 5127 | SET_REGNO (pic_offset_table_rtx, PIC_REG); |
483ab821 | 5128 | } |
8636be86 KH |
5129 | |
5130 | /* Worker function for TARGET_STRUCT_VALUE_RTX. */ | |
5131 | ||
5132 | static rtx | |
5133 | m68k_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED, | |
5134 | int incoming ATTRIBUTE_UNUSED) | |
5135 | { | |
5136 | return gen_rtx_REG (Pmode, M68K_STRUCT_VALUE_REGNUM); | |
5137 | } | |
cfca21cb PB |
5138 | |
5139 | /* Return nonzero if register old_reg can be renamed to register new_reg. */ | |
5140 | int | |
5141 | m68k_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED, | |
5142 | unsigned int new_reg) | |
5143 | { | |
5144 | ||
5145 | /* Interrupt functions can only use registers that have already been | |
5146 | saved by the prologue, even if they would normally be | |
5147 | call-clobbered. */ | |
5148 | ||
a4242737 KH |
5149 | if ((m68k_get_function_kind (current_function_decl) |
5150 | == m68k_fk_interrupt_handler) | |
6fb5fa3c | 5151 | && !df_regs_ever_live_p (new_reg)) |
cfca21cb PB |
5152 | return 0; |
5153 | ||
5154 | return 1; | |
5155 | } | |
70028b61 | 5156 | |
ffa2596e RS |
5157 | /* Value is true if hard register REGNO can hold a value of machine-mode |
5158 | MODE. On the 68000, we let the cpu registers can hold any mode, but | |
5159 | restrict the 68881 registers to floating-point modes. */ | |
5160 | ||
70028b61 PB |
5161 | bool |
5162 | m68k_regno_mode_ok (int regno, enum machine_mode mode) | |
5163 | { | |
36e04090 | 5164 | if (DATA_REGNO_P (regno)) |
70028b61 | 5165 | { |
a0a7fbc9 AS |
5166 | /* Data Registers, can hold aggregate if fits in. */ |
5167 | if (regno + GET_MODE_SIZE (mode) / 4 <= 8) | |
5168 | return true; | |
70028b61 | 5169 | } |
36e04090 | 5170 | else if (ADDRESS_REGNO_P (regno)) |
70028b61 | 5171 | { |
a0a7fbc9 AS |
5172 | if (regno + GET_MODE_SIZE (mode) / 4 <= 16) |
5173 | return true; | |
70028b61 | 5174 | } |
36e04090 | 5175 | else if (FP_REGNO_P (regno)) |
70028b61 PB |
5176 | { |
5177 | /* FPU registers, hold float or complex float of long double or | |
a0a7fbc9 AS |
5178 | smaller. */ |
5179 | if ((GET_MODE_CLASS (mode) == MODE_FLOAT | |
5180 | || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) | |
dcc21c4c | 5181 | && GET_MODE_UNIT_SIZE (mode) <= TARGET_FP_REG_SIZE) |
a0a7fbc9 | 5182 | return true; |
70028b61 PB |
5183 | } |
5184 | return false; | |
5185 | } | |
dcc21c4c | 5186 | |
ffa2596e RS |
5187 | /* Implement SECONDARY_RELOAD_CLASS. */ |
5188 | ||
5189 | enum reg_class | |
5190 | m68k_secondary_reload_class (enum reg_class rclass, | |
5191 | enum machine_mode mode, rtx x) | |
5192 | { | |
5193 | int regno; | |
5194 | ||
5195 | regno = true_regnum (x); | |
5196 | ||
5197 | /* If one operand of a movqi is an address register, the other | |
5198 | operand must be a general register or constant. Other types | |
5199 | of operand must be reloaded through a data register. */ | |
5200 | if (GET_MODE_SIZE (mode) == 1 | |
5201 | && reg_classes_intersect_p (rclass, ADDR_REGS) | |
5202 | && !(INT_REGNO_P (regno) || CONSTANT_P (x))) | |
5203 | return DATA_REGS; | |
5204 | ||
5205 | /* PC-relative addresses must be loaded into an address register first. */ | |
5206 | if (TARGET_PCREL | |
5207 | && !reg_class_subset_p (rclass, ADDR_REGS) | |
5208 | && symbolic_operand (x, VOIDmode)) | |
5209 | return ADDR_REGS; | |
5210 | ||
5211 | return NO_REGS; | |
5212 | } | |
5213 | ||
5214 | /* Implement PREFERRED_RELOAD_CLASS. */ | |
5215 | ||
5216 | enum reg_class | |
5217 | m68k_preferred_reload_class (rtx x, enum reg_class rclass) | |
5218 | { | |
5219 | enum reg_class secondary_class; | |
5220 | ||
5221 | /* If RCLASS might need a secondary reload, try restricting it to | |
5222 | a class that doesn't. */ | |
5223 | secondary_class = m68k_secondary_reload_class (rclass, GET_MODE (x), x); | |
5224 | if (secondary_class != NO_REGS | |
5225 | && reg_class_subset_p (secondary_class, rclass)) | |
5226 | return secondary_class; | |
5227 | ||
5228 | /* Prefer to use moveq for in-range constants. */ | |
5229 | if (GET_CODE (x) == CONST_INT | |
5230 | && reg_class_subset_p (DATA_REGS, rclass) | |
5231 | && IN_RANGE (INTVAL (x), -0x80, 0x7f)) | |
5232 | return DATA_REGS; | |
5233 | ||
5234 | /* ??? Do we really need this now? */ | |
5235 | if (GET_CODE (x) == CONST_DOUBLE | |
5236 | && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
5237 | { | |
5238 | if (TARGET_HARD_FLOAT && reg_class_subset_p (FP_REGS, rclass)) | |
5239 | return FP_REGS; | |
5240 | ||
5241 | return NO_REGS; | |
5242 | } | |
5243 | ||
5244 | return rclass; | |
5245 | } | |
5246 | ||
dcc21c4c PB |
5247 | /* Return floating point values in a 68881 register. This makes 68881 code |
5248 | a little bit faster. It also makes -msoft-float code incompatible with | |
5249 | hard-float code, so people have to be careful not to mix the two. | |
c0220ea4 | 5250 | For ColdFire it was decided the ABI incompatibility is undesirable. |
dcc21c4c PB |
5251 | If there is need for a hard-float ABI it is probably worth doing it |
5252 | properly and also passing function arguments in FP registers. */ | |
5253 | rtx | |
5254 | m68k_libcall_value (enum machine_mode mode) | |
5255 | { | |
5256 | switch (mode) { | |
5257 | case SFmode: | |
5258 | case DFmode: | |
5259 | case XFmode: | |
5260 | if (TARGET_68881) | |
8d989403 | 5261 | return gen_rtx_REG (mode, FP0_REG); |
dcc21c4c PB |
5262 | break; |
5263 | default: | |
5264 | break; | |
5265 | } | |
75df395f MK |
5266 | |
5267 | return gen_rtx_REG (mode, m68k_libcall_value_in_a0_p ? A0_REG : D0_REG); | |
dcc21c4c PB |
5268 | } |
5269 | ||
db5e2d51 MK |
5270 | /* Location in which function value is returned. |
5271 | NOTE: Due to differences in ABIs, don't call this function directly, | |
5272 | use FUNCTION_VALUE instead. */ | |
dcc21c4c | 5273 | rtx |
586de218 | 5274 | m68k_function_value (const_tree valtype, const_tree func ATTRIBUTE_UNUSED) |
dcc21c4c PB |
5275 | { |
5276 | enum machine_mode mode; | |
5277 | ||
5278 | mode = TYPE_MODE (valtype); | |
5279 | switch (mode) { | |
5280 | case SFmode: | |
5281 | case DFmode: | |
5282 | case XFmode: | |
5283 | if (TARGET_68881) | |
8d989403 | 5284 | return gen_rtx_REG (mode, FP0_REG); |
dcc21c4c PB |
5285 | break; |
5286 | default: | |
5287 | break; | |
5288 | } | |
5289 | ||
576c9028 KH |
5290 | /* If the function returns a pointer, push that into %a0. */ |
5291 | if (func && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (func)))) | |
5292 | /* For compatibility with the large body of existing code which | |
5293 | does not always properly declare external functions returning | |
5294 | pointer types, the m68k/SVR4 convention is to copy the value | |
5295 | returned for pointer functions from a0 to d0 in the function | |
5296 | epilogue, so that callers that have neglected to properly | |
5297 | declare the callee can still find the correct return value in | |
5298 | d0. */ | |
5299 | return gen_rtx_PARALLEL | |
5300 | (mode, | |
5301 | gen_rtvec (2, | |
5302 | gen_rtx_EXPR_LIST (VOIDmode, | |
5303 | gen_rtx_REG (mode, A0_REG), | |
5304 | const0_rtx), | |
5305 | gen_rtx_EXPR_LIST (VOIDmode, | |
5306 | gen_rtx_REG (mode, D0_REG), | |
5307 | const0_rtx))); | |
5308 | else if (POINTER_TYPE_P (valtype)) | |
5309 | return gen_rtx_REG (mode, A0_REG); | |
dcc21c4c | 5310 | else |
576c9028 | 5311 | return gen_rtx_REG (mode, D0_REG); |
dcc21c4c | 5312 | } |
1c445f03 NS |
5313 | |
5314 | /* Worker function for TARGET_RETURN_IN_MEMORY. */ | |
5315 | #if M68K_HONOR_TARGET_STRICT_ALIGNMENT | |
5316 | static bool | |
511e41e5 | 5317 | m68k_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED) |
1c445f03 NS |
5318 | { |
5319 | enum machine_mode mode = TYPE_MODE (type); | |
5320 | ||
5321 | if (mode == BLKmode) | |
5322 | return true; | |
5323 | ||
5324 | /* If TYPE's known alignment is less than the alignment of MODE that | |
5325 | would contain the structure, then return in memory. We need to | |
5326 | do so to maintain the compatibility between code compiled with | |
5327 | -mstrict-align and that compiled with -mno-strict-align. */ | |
5328 | if (AGGREGATE_TYPE_P (type) | |
5329 | && TYPE_ALIGN (type) < GET_MODE_ALIGNMENT (mode)) | |
5330 | return true; | |
5331 | ||
5332 | return false; | |
5333 | } | |
5334 | #endif | |
c47b0cb4 MK |
5335 | |
5336 | /* CPU to schedule the program for. */ | |
5337 | enum attr_cpu m68k_sched_cpu; | |
5338 | ||
826fadba MK |
5339 | /* MAC to schedule the program for. */ |
5340 | enum attr_mac m68k_sched_mac; | |
5341 | ||
c47b0cb4 MK |
5342 | /* Operand type. */ |
5343 | enum attr_op_type | |
5344 | { | |
5345 | /* No operand. */ | |
5346 | OP_TYPE_NONE, | |
5347 | ||
96fcacb7 MK |
5348 | /* Integer register. */ |
5349 | OP_TYPE_RN, | |
5350 | ||
5351 | /* FP register. */ | |
5352 | OP_TYPE_FPN, | |
c47b0cb4 MK |
5353 | |
5354 | /* Implicit mem reference (e.g. stack). */ | |
5355 | OP_TYPE_MEM1, | |
5356 | ||
5357 | /* Memory without offset or indexing. EA modes 2, 3 and 4. */ | |
5358 | OP_TYPE_MEM234, | |
5359 | ||
5360 | /* Memory with offset but without indexing. EA mode 5. */ | |
5361 | OP_TYPE_MEM5, | |
5362 | ||
5363 | /* Memory with indexing. EA mode 6. */ | |
5364 | OP_TYPE_MEM6, | |
5365 | ||
5366 | /* Memory referenced by absolute address. EA mode 7. */ | |
5367 | OP_TYPE_MEM7, | |
5368 | ||
5369 | /* Immediate operand that doesn't require extension word. */ | |
5370 | OP_TYPE_IMM_Q, | |
5371 | ||
5372 | /* Immediate 16 bit operand. */ | |
5373 | OP_TYPE_IMM_W, | |
5374 | ||
5375 | /* Immediate 32 bit operand. */ | |
5376 | OP_TYPE_IMM_L | |
5377 | }; | |
5378 | ||
c47b0cb4 MK |
5379 | /* Return type of memory ADDR_RTX refers to. */ |
5380 | static enum attr_op_type | |
5381 | sched_address_type (enum machine_mode mode, rtx addr_rtx) | |
5382 | { | |
5383 | struct m68k_address address; | |
5384 | ||
96fcacb7 MK |
5385 | if (symbolic_operand (addr_rtx, VOIDmode)) |
5386 | return OP_TYPE_MEM7; | |
5387 | ||
c47b0cb4 MK |
5388 | if (!m68k_decompose_address (mode, addr_rtx, |
5389 | reload_completed, &address)) | |
5390 | { | |
96fcacb7 | 5391 | gcc_assert (!reload_completed); |
c47b0cb4 MK |
5392 | /* Reload will likely fix the address to be in the register. */ |
5393 | return OP_TYPE_MEM234; | |
5394 | } | |
5395 | ||
5396 | if (address.scale != 0) | |
5397 | return OP_TYPE_MEM6; | |
5398 | ||
5399 | if (address.base != NULL_RTX) | |
5400 | { | |
5401 | if (address.offset == NULL_RTX) | |
5402 | return OP_TYPE_MEM234; | |
5403 | ||
5404 | return OP_TYPE_MEM5; | |
5405 | } | |
5406 | ||
5407 | gcc_assert (address.offset != NULL_RTX); | |
5408 | ||
5409 | return OP_TYPE_MEM7; | |
5410 | } | |
5411 | ||
96fcacb7 MK |
5412 | /* Return X or Y (depending on OPX_P) operand of INSN. */ |
5413 | static rtx | |
647d790d | 5414 | sched_get_operand (rtx_insn *insn, bool opx_p) |
96fcacb7 MK |
5415 | { |
5416 | int i; | |
5417 | ||
5418 | if (recog_memoized (insn) < 0) | |
5419 | gcc_unreachable (); | |
5420 | ||
5421 | extract_constrain_insn_cached (insn); | |
5422 | ||
5423 | if (opx_p) | |
5424 | i = get_attr_opx (insn); | |
5425 | else | |
5426 | i = get_attr_opy (insn); | |
5427 | ||
5428 | if (i >= recog_data.n_operands) | |
5429 | return NULL; | |
5430 | ||
5431 | return recog_data.operand[i]; | |
5432 | } | |
5433 | ||
5434 | /* Return type of INSN's operand X (if OPX_P) or operand Y (if !OPX_P). | |
5435 | If ADDRESS_P is true, return type of memory location operand refers to. */ | |
c47b0cb4 | 5436 | static enum attr_op_type |
647d790d | 5437 | sched_attr_op_type (rtx_insn *insn, bool opx_p, bool address_p) |
c47b0cb4 | 5438 | { |
96fcacb7 MK |
5439 | rtx op; |
5440 | ||
5441 | op = sched_get_operand (insn, opx_p); | |
5442 | ||
5443 | if (op == NULL) | |
5444 | { | |
5445 | gcc_assert (!reload_completed); | |
5446 | return OP_TYPE_RN; | |
5447 | } | |
c47b0cb4 MK |
5448 | |
5449 | if (address_p) | |
5450 | return sched_address_type (QImode, op); | |
5451 | ||
5452 | if (memory_operand (op, VOIDmode)) | |
5453 | return sched_address_type (GET_MODE (op), XEXP (op, 0)); | |
5454 | ||
5455 | if (register_operand (op, VOIDmode)) | |
96fcacb7 MK |
5456 | { |
5457 | if ((!reload_completed && FLOAT_MODE_P (GET_MODE (op))) | |
5458 | || (reload_completed && FP_REG_P (op))) | |
5459 | return OP_TYPE_FPN; | |
5460 | ||
5461 | return OP_TYPE_RN; | |
5462 | } | |
c47b0cb4 MK |
5463 | |
5464 | if (GET_CODE (op) == CONST_INT) | |
5465 | { | |
96fcacb7 MK |
5466 | int ival; |
5467 | ||
5468 | ival = INTVAL (op); | |
5469 | ||
5470 | /* Check for quick constants. */ | |
5471 | switch (get_attr_type (insn)) | |
5472 | { | |
5473 | case TYPE_ALUQ_L: | |
5474 | if (IN_RANGE (ival, 1, 8) || IN_RANGE (ival, -8, -1)) | |
5475 | return OP_TYPE_IMM_Q; | |
5476 | ||
5477 | gcc_assert (!reload_completed); | |
5478 | break; | |
5479 | ||
5480 | case TYPE_MOVEQ_L: | |
5481 | if (USE_MOVQ (ival)) | |
5482 | return OP_TYPE_IMM_Q; | |
5483 | ||
5484 | gcc_assert (!reload_completed); | |
5485 | break; | |
5486 | ||
5487 | case TYPE_MOV3Q_L: | |
5488 | if (valid_mov3q_const (ival)) | |
5489 | return OP_TYPE_IMM_Q; | |
5490 | ||
5491 | gcc_assert (!reload_completed); | |
5492 | break; | |
5493 | ||
5494 | default: | |
5495 | break; | |
5496 | } | |
5497 | ||
5498 | if (IN_RANGE (ival, -0x8000, 0x7fff)) | |
c47b0cb4 MK |
5499 | return OP_TYPE_IMM_W; |
5500 | ||
5501 | return OP_TYPE_IMM_L; | |
5502 | } | |
5503 | ||
5504 | if (GET_CODE (op) == CONST_DOUBLE) | |
5505 | { | |
5506 | switch (GET_MODE (op)) | |
5507 | { | |
5508 | case SFmode: | |
5509 | return OP_TYPE_IMM_W; | |
5510 | ||
5511 | case VOIDmode: | |
5512 | case DFmode: | |
5513 | return OP_TYPE_IMM_L; | |
5514 | ||
5515 | default: | |
5516 | gcc_unreachable (); | |
5517 | } | |
5518 | } | |
5519 | ||
00b2ef14 MK |
5520 | if (GET_CODE (op) == CONST |
5521 | || symbolic_operand (op, VOIDmode) | |
c47b0cb4 MK |
5522 | || LABEL_P (op)) |
5523 | { | |
5524 | switch (GET_MODE (op)) | |
5525 | { | |
5526 | case QImode: | |
5527 | return OP_TYPE_IMM_Q; | |
5528 | ||
5529 | case HImode: | |
5530 | return OP_TYPE_IMM_W; | |
5531 | ||
5532 | case SImode: | |
5533 | return OP_TYPE_IMM_L; | |
5534 | ||
5535 | default: | |
75df395f MK |
5536 | if (symbolic_operand (m68k_unwrap_symbol (op, false), VOIDmode)) |
5537 | /* Just a guess. */ | |
c47b0cb4 MK |
5538 | return OP_TYPE_IMM_W; |
5539 | ||
5540 | return OP_TYPE_IMM_L; | |
5541 | } | |
5542 | } | |
5543 | ||
96fcacb7 | 5544 | gcc_assert (!reload_completed); |
c47b0cb4 | 5545 | |
96fcacb7 MK |
5546 | if (FLOAT_MODE_P (GET_MODE (op))) |
5547 | return OP_TYPE_FPN; | |
c47b0cb4 | 5548 | |
96fcacb7 | 5549 | return OP_TYPE_RN; |
c47b0cb4 MK |
5550 | } |
5551 | ||
5552 | /* Implement opx_type attribute. | |
5553 | Return type of INSN's operand X. | |
5554 | If ADDRESS_P is true, return type of memory location operand refers to. */ | |
5555 | enum attr_opx_type | |
647d790d | 5556 | m68k_sched_attr_opx_type (rtx_insn *insn, int address_p) |
c47b0cb4 | 5557 | { |
c47b0cb4 MK |
5558 | switch (sched_attr_op_type (insn, true, address_p != 0)) |
5559 | { | |
96fcacb7 MK |
5560 | case OP_TYPE_RN: |
5561 | return OPX_TYPE_RN; | |
5562 | ||
5563 | case OP_TYPE_FPN: | |
5564 | return OPX_TYPE_FPN; | |
c47b0cb4 MK |
5565 | |
5566 | case OP_TYPE_MEM1: | |
5567 | return OPX_TYPE_MEM1; | |
5568 | ||
5569 | case OP_TYPE_MEM234: | |
5570 | return OPX_TYPE_MEM234; | |
5571 | ||
5572 | case OP_TYPE_MEM5: | |
5573 | return OPX_TYPE_MEM5; | |
5574 | ||
5575 | case OP_TYPE_MEM6: | |
5576 | return OPX_TYPE_MEM6; | |
5577 | ||
5578 | case OP_TYPE_MEM7: | |
5579 | return OPX_TYPE_MEM7; | |
5580 | ||
5581 | case OP_TYPE_IMM_Q: | |
5582 | return OPX_TYPE_IMM_Q; | |
5583 | ||
5584 | case OP_TYPE_IMM_W: | |
5585 | return OPX_TYPE_IMM_W; | |
5586 | ||
5587 | case OP_TYPE_IMM_L: | |
5588 | return OPX_TYPE_IMM_L; | |
5589 | ||
5590 | default: | |
5591 | gcc_unreachable (); | |
c47b0cb4 MK |
5592 | } |
5593 | } | |
5594 | ||
5595 | /* Implement opy_type attribute. | |
5596 | Return type of INSN's operand Y. | |
5597 | If ADDRESS_P is true, return type of memory location operand refers to. */ | |
5598 | enum attr_opy_type | |
647d790d | 5599 | m68k_sched_attr_opy_type (rtx_insn *insn, int address_p) |
c47b0cb4 | 5600 | { |
c47b0cb4 MK |
5601 | switch (sched_attr_op_type (insn, false, address_p != 0)) |
5602 | { | |
96fcacb7 MK |
5603 | case OP_TYPE_RN: |
5604 | return OPY_TYPE_RN; | |
5605 | ||
5606 | case OP_TYPE_FPN: | |
5607 | return OPY_TYPE_FPN; | |
c47b0cb4 MK |
5608 | |
5609 | case OP_TYPE_MEM1: | |
5610 | return OPY_TYPE_MEM1; | |
5611 | ||
5612 | case OP_TYPE_MEM234: | |
5613 | return OPY_TYPE_MEM234; | |
5614 | ||
5615 | case OP_TYPE_MEM5: | |
5616 | return OPY_TYPE_MEM5; | |
5617 | ||
5618 | case OP_TYPE_MEM6: | |
5619 | return OPY_TYPE_MEM6; | |
5620 | ||
5621 | case OP_TYPE_MEM7: | |
5622 | return OPY_TYPE_MEM7; | |
5623 | ||
5624 | case OP_TYPE_IMM_Q: | |
5625 | return OPY_TYPE_IMM_Q; | |
5626 | ||
5627 | case OP_TYPE_IMM_W: | |
5628 | return OPY_TYPE_IMM_W; | |
5629 | ||
5630 | case OP_TYPE_IMM_L: | |
5631 | return OPY_TYPE_IMM_L; | |
5632 | ||
5633 | default: | |
5634 | gcc_unreachable (); | |
c47b0cb4 MK |
5635 | } |
5636 | } | |
5637 | ||
96fcacb7 MK |
5638 | /* Return size of INSN as int. */ |
5639 | static int | |
84034c69 | 5640 | sched_get_attr_size_int (rtx_insn *insn) |
c47b0cb4 MK |
5641 | { |
5642 | int size; | |
5643 | ||
96fcacb7 | 5644 | switch (get_attr_type (insn)) |
c47b0cb4 | 5645 | { |
96fcacb7 MK |
5646 | case TYPE_IGNORE: |
5647 | /* There should be no references to m68k_sched_attr_size for 'ignore' | |
5648 | instructions. */ | |
5649 | gcc_unreachable (); | |
5650 | return 0; | |
5651 | ||
5652 | case TYPE_MUL_L: | |
c47b0cb4 MK |
5653 | size = 2; |
5654 | break; | |
5655 | ||
5656 | default: | |
5657 | size = 1; | |
5658 | break; | |
5659 | } | |
5660 | ||
5661 | switch (get_attr_opx_type (insn)) | |
5662 | { | |
5663 | case OPX_TYPE_NONE: | |
96fcacb7 MK |
5664 | case OPX_TYPE_RN: |
5665 | case OPX_TYPE_FPN: | |
c47b0cb4 MK |
5666 | case OPX_TYPE_MEM1: |
5667 | case OPX_TYPE_MEM234: | |
5668 | case OPY_TYPE_IMM_Q: | |
5669 | break; | |
5670 | ||
5671 | case OPX_TYPE_MEM5: | |
5672 | case OPX_TYPE_MEM6: | |
5673 | /* Here we assume that most absolute references are short. */ | |
5674 | case OPX_TYPE_MEM7: | |
5675 | case OPY_TYPE_IMM_W: | |
5676 | ++size; | |
5677 | break; | |
5678 | ||
5679 | case OPY_TYPE_IMM_L: | |
5680 | size += 2; | |
5681 | break; | |
5682 | ||
5683 | default: | |
5684 | gcc_unreachable (); | |
5685 | } | |
5686 | ||
5687 | switch (get_attr_opy_type (insn)) | |
5688 | { | |
5689 | case OPY_TYPE_NONE: | |
96fcacb7 MK |
5690 | case OPY_TYPE_RN: |
5691 | case OPY_TYPE_FPN: | |
c47b0cb4 MK |
5692 | case OPY_TYPE_MEM1: |
5693 | case OPY_TYPE_MEM234: | |
5694 | case OPY_TYPE_IMM_Q: | |
5695 | break; | |
5696 | ||
5697 | case OPY_TYPE_MEM5: | |
5698 | case OPY_TYPE_MEM6: | |
5699 | /* Here we assume that most absolute references are short. */ | |
5700 | case OPY_TYPE_MEM7: | |
5701 | case OPY_TYPE_IMM_W: | |
5702 | ++size; | |
5703 | break; | |
5704 | ||
5705 | case OPY_TYPE_IMM_L: | |
5706 | size += 2; | |
5707 | break; | |
5708 | ||
5709 | default: | |
5710 | gcc_unreachable (); | |
5711 | } | |
5712 | ||
5713 | if (size > 3) | |
5714 | { | |
96fcacb7 | 5715 | gcc_assert (!reload_completed); |
c47b0cb4 MK |
5716 | |
5717 | size = 3; | |
5718 | } | |
5719 | ||
5720 | return size; | |
5721 | } | |
5722 | ||
96fcacb7 MK |
5723 | /* Return size of INSN as attribute enum value. */ |
5724 | enum attr_size | |
84034c69 | 5725 | m68k_sched_attr_size (rtx_insn *insn) |
96fcacb7 MK |
5726 | { |
5727 | switch (sched_get_attr_size_int (insn)) | |
5728 | { | |
5729 | case 1: | |
5730 | return SIZE_1; | |
5731 | ||
5732 | case 2: | |
5733 | return SIZE_2; | |
5734 | ||
5735 | case 3: | |
5736 | return SIZE_3; | |
5737 | ||
5738 | default: | |
5739 | gcc_unreachable (); | |
96fcacb7 MK |
5740 | } |
5741 | } | |
5742 | ||
5743 | /* Return operand X or Y (depending on OPX_P) of INSN, | |
5744 | if it is a MEM, or NULL overwise. */ | |
5745 | static enum attr_op_type | |
84034c69 | 5746 | sched_get_opxy_mem_type (rtx_insn *insn, bool opx_p) |
96fcacb7 MK |
5747 | { |
5748 | if (opx_p) | |
5749 | { | |
5750 | switch (get_attr_opx_type (insn)) | |
5751 | { | |
5752 | case OPX_TYPE_NONE: | |
5753 | case OPX_TYPE_RN: | |
5754 | case OPX_TYPE_FPN: | |
5755 | case OPX_TYPE_IMM_Q: | |
5756 | case OPX_TYPE_IMM_W: | |
5757 | case OPX_TYPE_IMM_L: | |
5758 | return OP_TYPE_RN; | |
5759 | ||
5760 | case OPX_TYPE_MEM1: | |
5761 | case OPX_TYPE_MEM234: | |
5762 | case OPX_TYPE_MEM5: | |
5763 | case OPX_TYPE_MEM7: | |
5764 | return OP_TYPE_MEM1; | |
5765 | ||
5766 | case OPX_TYPE_MEM6: | |
5767 | return OP_TYPE_MEM6; | |
5768 | ||
5769 | default: | |
5770 | gcc_unreachable (); | |
96fcacb7 MK |
5771 | } |
5772 | } | |
5773 | else | |
5774 | { | |
5775 | switch (get_attr_opy_type (insn)) | |
5776 | { | |
5777 | case OPY_TYPE_NONE: | |
5778 | case OPY_TYPE_RN: | |
5779 | case OPY_TYPE_FPN: | |
5780 | case OPY_TYPE_IMM_Q: | |
5781 | case OPY_TYPE_IMM_W: | |
5782 | case OPY_TYPE_IMM_L: | |
5783 | return OP_TYPE_RN; | |
5784 | ||
5785 | case OPY_TYPE_MEM1: | |
5786 | case OPY_TYPE_MEM234: | |
5787 | case OPY_TYPE_MEM5: | |
5788 | case OPY_TYPE_MEM7: | |
5789 | return OP_TYPE_MEM1; | |
5790 | ||
5791 | case OPY_TYPE_MEM6: | |
5792 | return OP_TYPE_MEM6; | |
5793 | ||
5794 | default: | |
5795 | gcc_unreachable (); | |
96fcacb7 MK |
5796 | } |
5797 | } | |
5798 | } | |
5799 | ||
c47b0cb4 MK |
5800 | /* Implement op_mem attribute. */ |
5801 | enum attr_op_mem | |
84034c69 | 5802 | m68k_sched_attr_op_mem (rtx_insn *insn) |
c47b0cb4 | 5803 | { |
96fcacb7 MK |
5804 | enum attr_op_type opx; |
5805 | enum attr_op_type opy; | |
c47b0cb4 | 5806 | |
96fcacb7 MK |
5807 | opx = sched_get_opxy_mem_type (insn, true); |
5808 | opy = sched_get_opxy_mem_type (insn, false); | |
c47b0cb4 | 5809 | |
96fcacb7 | 5810 | if (opy == OP_TYPE_RN && opx == OP_TYPE_RN) |
c47b0cb4 MK |
5811 | return OP_MEM_00; |
5812 | ||
96fcacb7 | 5813 | if (opy == OP_TYPE_RN && opx == OP_TYPE_MEM1) |
c47b0cb4 MK |
5814 | { |
5815 | switch (get_attr_opx_access (insn)) | |
5816 | { | |
5817 | case OPX_ACCESS_R: | |
5818 | return OP_MEM_10; | |
5819 | ||
5820 | case OPX_ACCESS_W: | |
5821 | return OP_MEM_01; | |
5822 | ||
5823 | case OPX_ACCESS_RW: | |
5824 | return OP_MEM_11; | |
5825 | ||
5826 | default: | |
96fcacb7 | 5827 | gcc_unreachable (); |
c47b0cb4 MK |
5828 | } |
5829 | } | |
5830 | ||
96fcacb7 | 5831 | if (opy == OP_TYPE_RN && opx == OP_TYPE_MEM6) |
c47b0cb4 MK |
5832 | { |
5833 | switch (get_attr_opx_access (insn)) | |
5834 | { | |
5835 | case OPX_ACCESS_R: | |
5836 | return OP_MEM_I0; | |
5837 | ||
5838 | case OPX_ACCESS_W: | |
5839 | return OP_MEM_0I; | |
5840 | ||
5841 | case OPX_ACCESS_RW: | |
5842 | return OP_MEM_I1; | |
5843 | ||
5844 | default: | |
96fcacb7 | 5845 | gcc_unreachable (); |
c47b0cb4 MK |
5846 | } |
5847 | } | |
5848 | ||
96fcacb7 | 5849 | if (opy == OP_TYPE_MEM1 && opx == OP_TYPE_RN) |
c47b0cb4 MK |
5850 | return OP_MEM_10; |
5851 | ||
96fcacb7 | 5852 | if (opy == OP_TYPE_MEM1 && opx == OP_TYPE_MEM1) |
c47b0cb4 MK |
5853 | { |
5854 | switch (get_attr_opx_access (insn)) | |
5855 | { | |
5856 | case OPX_ACCESS_W: | |
5857 | return OP_MEM_11; | |
5858 | ||
5859 | default: | |
96fcacb7 MK |
5860 | gcc_assert (!reload_completed); |
5861 | return OP_MEM_11; | |
c47b0cb4 MK |
5862 | } |
5863 | } | |
5864 | ||
96fcacb7 | 5865 | if (opy == OP_TYPE_MEM1 && opx == OP_TYPE_MEM6) |
c47b0cb4 MK |
5866 | { |
5867 | switch (get_attr_opx_access (insn)) | |
5868 | { | |
5869 | case OPX_ACCESS_W: | |
5870 | return OP_MEM_1I; | |
5871 | ||
5872 | default: | |
96fcacb7 MK |
5873 | gcc_assert (!reload_completed); |
5874 | return OP_MEM_1I; | |
c47b0cb4 MK |
5875 | } |
5876 | } | |
5877 | ||
96fcacb7 | 5878 | if (opy == OP_TYPE_MEM6 && opx == OP_TYPE_RN) |
c47b0cb4 MK |
5879 | return OP_MEM_I0; |
5880 | ||
96fcacb7 | 5881 | if (opy == OP_TYPE_MEM6 && opx == OP_TYPE_MEM1) |
c47b0cb4 MK |
5882 | { |
5883 | switch (get_attr_opx_access (insn)) | |
5884 | { | |
5885 | case OPX_ACCESS_W: | |
5886 | return OP_MEM_I1; | |
5887 | ||
5888 | default: | |
96fcacb7 MK |
5889 | gcc_assert (!reload_completed); |
5890 | return OP_MEM_I1; | |
c47b0cb4 MK |
5891 | } |
5892 | } | |
5893 | ||
96fcacb7 MK |
5894 | gcc_assert (opy == OP_TYPE_MEM6 && opx == OP_TYPE_MEM6); |
5895 | gcc_assert (!reload_completed); | |
5896 | return OP_MEM_I1; | |
c47b0cb4 MK |
5897 | } |
5898 | ||
96fcacb7 MK |
5899 | /* Data for ColdFire V4 index bypass. |
5900 | Producer modifies register that is used as index in consumer with | |
5901 | specified scale. */ | |
5902 | static struct | |
b8c96320 | 5903 | { |
96fcacb7 MK |
5904 | /* Producer instruction. */ |
5905 | rtx pro; | |
826fadba | 5906 | |
96fcacb7 MK |
5907 | /* Consumer instruction. */ |
5908 | rtx con; | |
b8c96320 | 5909 | |
96fcacb7 MK |
5910 | /* Scale of indexed memory access within consumer. |
5911 | Or zero if bypass should not be effective at the moment. */ | |
5912 | int scale; | |
5913 | } sched_cfv4_bypass_data; | |
b8c96320 MK |
5914 | |
5915 | /* An empty state that is used in m68k_sched_adjust_cost. */ | |
5916 | static state_t sched_adjust_cost_state; | |
5917 | ||
5918 | /* Implement adjust_cost scheduler hook. | |
5919 | Return adjusted COST of dependency LINK between DEF_INSN and INSN. */ | |
5920 | static int | |
ac44248e DM |
5921 | m68k_sched_adjust_cost (rtx_insn *insn, rtx link ATTRIBUTE_UNUSED, |
5922 | rtx_insn *def_insn, int cost) | |
b8c96320 MK |
5923 | { |
5924 | int delay; | |
5925 | ||
5926 | if (recog_memoized (def_insn) < 0 | |
5927 | || recog_memoized (insn) < 0) | |
5928 | return cost; | |
5929 | ||
96fcacb7 MK |
5930 | if (sched_cfv4_bypass_data.scale == 1) |
5931 | /* Handle ColdFire V4 bypass for indexed address with 1x scale. */ | |
5932 | { | |
5933 | /* haifa-sched.c: insn_cost () calls bypass_p () just before | |
5934 | targetm.sched.adjust_cost (). Hence, we can be relatively sure | |
5935 | that the data in sched_cfv4_bypass_data is up to date. */ | |
5936 | gcc_assert (sched_cfv4_bypass_data.pro == def_insn | |
5937 | && sched_cfv4_bypass_data.con == insn); | |
5938 | ||
5939 | if (cost < 3) | |
5940 | cost = 3; | |
5941 | ||
5942 | sched_cfv4_bypass_data.pro = NULL; | |
5943 | sched_cfv4_bypass_data.con = NULL; | |
5944 | sched_cfv4_bypass_data.scale = 0; | |
5945 | } | |
5946 | else | |
5947 | gcc_assert (sched_cfv4_bypass_data.pro == NULL | |
5948 | && sched_cfv4_bypass_data.con == NULL | |
5949 | && sched_cfv4_bypass_data.scale == 0); | |
5950 | ||
b8c96320 MK |
5951 | /* Don't try to issue INSN earlier than DFA permits. |
5952 | This is especially useful for instructions that write to memory, | |
5953 | as their true dependence (default) latency is better to be set to 0 | |
5954 | to workaround alias analysis limitations. | |
5955 | This is, in fact, a machine independent tweak, so, probably, | |
5956 | it should be moved to haifa-sched.c: insn_cost (). */ | |
b8c96320 MK |
5957 | delay = min_insn_conflict_delay (sched_adjust_cost_state, def_insn, insn); |
5958 | if (delay > cost) | |
5959 | cost = delay; | |
5960 | ||
5961 | return cost; | |
5962 | } | |
5963 | ||
96fcacb7 MK |
5964 | /* Return maximal number of insns that can be scheduled on a single cycle. */ |
5965 | static int | |
5966 | m68k_sched_issue_rate (void) | |
5967 | { | |
5968 | switch (m68k_sched_cpu) | |
5969 | { | |
5970 | case CPU_CFV1: | |
5971 | case CPU_CFV2: | |
5972 | case CPU_CFV3: | |
5973 | return 1; | |
5974 | ||
5975 | case CPU_CFV4: | |
5976 | return 2; | |
5977 | ||
5978 | default: | |
5979 | gcc_unreachable (); | |
5980 | return 0; | |
5981 | } | |
5982 | } | |
5983 | ||
826fadba MK |
5984 | /* Maximal length of instruction for current CPU. |
5985 | E.g. it is 3 for any ColdFire core. */ | |
5986 | static int max_insn_size; | |
5987 | ||
5988 | /* Data to model instruction buffer of CPU. */ | |
5989 | struct _sched_ib | |
5990 | { | |
96fcacb7 MK |
5991 | /* True if instruction buffer model is modeled for current CPU. */ |
5992 | bool enabled_p; | |
5993 | ||
826fadba MK |
5994 | /* Size of the instruction buffer in words. */ |
5995 | int size; | |
5996 | ||
5997 | /* Number of filled words in the instruction buffer. */ | |
5998 | int filled; | |
5999 | ||
6000 | /* Additional information about instruction buffer for CPUs that have | |
6001 | a buffer of instruction records, rather then a plain buffer | |
6002 | of instruction words. */ | |
6003 | struct _sched_ib_records | |
6004 | { | |
6005 | /* Size of buffer in records. */ | |
6006 | int n_insns; | |
b8c96320 | 6007 | |
826fadba MK |
6008 | /* Array to hold data on adjustements made to the size of the buffer. */ |
6009 | int *adjust; | |
b8c96320 | 6010 | |
826fadba MK |
6011 | /* Index of the above array. */ |
6012 | int adjust_index; | |
6013 | } records; | |
6014 | ||
6015 | /* An insn that reserves (marks empty) one word in the instruction buffer. */ | |
6016 | rtx insn; | |
6017 | }; | |
6018 | ||
6019 | static struct _sched_ib sched_ib; | |
b8c96320 MK |
6020 | |
6021 | /* ID of memory unit. */ | |
6022 | static int sched_mem_unit_code; | |
6023 | ||
6024 | /* Implementation of the targetm.sched.variable_issue () hook. | |
6025 | It is called after INSN was issued. It returns the number of insns | |
6026 | that can possibly get scheduled on the current cycle. | |
6027 | It is used here to determine the effect of INSN on the instruction | |
6028 | buffer. */ | |
6029 | static int | |
6030 | m68k_sched_variable_issue (FILE *sched_dump ATTRIBUTE_UNUSED, | |
6031 | int sched_verbose ATTRIBUTE_UNUSED, | |
ac44248e | 6032 | rtx_insn *insn, int can_issue_more) |
b8c96320 MK |
6033 | { |
6034 | int insn_size; | |
6035 | ||
96fcacb7 | 6036 | if (recog_memoized (insn) >= 0 && get_attr_type (insn) != TYPE_IGNORE) |
b8c96320 | 6037 | { |
826fadba MK |
6038 | switch (m68k_sched_cpu) |
6039 | { | |
6040 | case CPU_CFV1: | |
6041 | case CPU_CFV2: | |
96fcacb7 | 6042 | insn_size = sched_get_attr_size_int (insn); |
826fadba MK |
6043 | break; |
6044 | ||
6045 | case CPU_CFV3: | |
96fcacb7 | 6046 | insn_size = sched_get_attr_size_int (insn); |
826fadba MK |
6047 | |
6048 | /* ColdFire V3 and V4 cores have instruction buffers that can | |
6049 | accumulate up to 8 instructions regardless of instructions' | |
6050 | sizes. So we should take care not to "prefetch" 24 one-word | |
6051 | or 12 two-words instructions. | |
6052 | To model this behavior we temporarily decrease size of the | |
6053 | buffer by (max_insn_size - insn_size) for next 7 instructions. */ | |
6054 | { | |
6055 | int adjust; | |
6056 | ||
6057 | adjust = max_insn_size - insn_size; | |
6058 | sched_ib.size -= adjust; | |
6059 | ||
6060 | if (sched_ib.filled > sched_ib.size) | |
6061 | sched_ib.filled = sched_ib.size; | |
6062 | ||
6063 | sched_ib.records.adjust[sched_ib.records.adjust_index] = adjust; | |
6064 | } | |
6065 | ||
6066 | ++sched_ib.records.adjust_index; | |
6067 | if (sched_ib.records.adjust_index == sched_ib.records.n_insns) | |
6068 | sched_ib.records.adjust_index = 0; | |
6069 | ||
6070 | /* Undo adjustement we did 7 instructions ago. */ | |
6071 | sched_ib.size | |
6072 | += sched_ib.records.adjust[sched_ib.records.adjust_index]; | |
6073 | ||
6074 | break; | |
b8c96320 | 6075 | |
96fcacb7 MK |
6076 | case CPU_CFV4: |
6077 | gcc_assert (!sched_ib.enabled_p); | |
6078 | insn_size = 0; | |
6079 | break; | |
6080 | ||
826fadba MK |
6081 | default: |
6082 | gcc_unreachable (); | |
6083 | } | |
b8c96320 | 6084 | |
3162fdf4 MK |
6085 | if (insn_size > sched_ib.filled) |
6086 | /* Scheduling for register pressure does not always take DFA into | |
6087 | account. Workaround instruction buffer not being filled enough. */ | |
6088 | { | |
60867e8c | 6089 | gcc_assert (sched_pressure == SCHED_PRESSURE_WEIGHTED); |
3162fdf4 MK |
6090 | insn_size = sched_ib.filled; |
6091 | } | |
6092 | ||
b8c96320 MK |
6093 | --can_issue_more; |
6094 | } | |
6095 | else if (GET_CODE (PATTERN (insn)) == ASM_INPUT | |
6096 | || asm_noperands (PATTERN (insn)) >= 0) | |
826fadba | 6097 | insn_size = sched_ib.filled; |
b8c96320 MK |
6098 | else |
6099 | insn_size = 0; | |
6100 | ||
826fadba | 6101 | sched_ib.filled -= insn_size; |
b8c96320 MK |
6102 | |
6103 | return can_issue_more; | |
6104 | } | |
6105 | ||
96fcacb7 MK |
6106 | /* Return how many instructions should scheduler lookahead to choose the |
6107 | best one. */ | |
6108 | static int | |
6109 | m68k_sched_first_cycle_multipass_dfa_lookahead (void) | |
b8c96320 | 6110 | { |
96fcacb7 | 6111 | return m68k_sched_issue_rate () - 1; |
b8c96320 MK |
6112 | } |
6113 | ||
7ecb00a6 | 6114 | /* Implementation of targetm.sched.init_global () hook. |
b8c96320 MK |
6115 | It is invoked once per scheduling pass and is used here |
6116 | to initialize scheduler constants. */ | |
6117 | static void | |
6118 | m68k_sched_md_init_global (FILE *sched_dump ATTRIBUTE_UNUSED, | |
6119 | int sched_verbose ATTRIBUTE_UNUSED, | |
6120 | int n_insns ATTRIBUTE_UNUSED) | |
6121 | { | |
96fcacb7 MK |
6122 | #ifdef ENABLE_CHECKING |
6123 | /* Check that all instructions have DFA reservations and | |
6124 | that all instructions can be issued from a clean state. */ | |
6125 | { | |
b32d5189 | 6126 | rtx_insn *insn; |
96fcacb7 | 6127 | state_t state; |
b8c96320 | 6128 | |
96fcacb7 | 6129 | state = alloca (state_size ()); |
b8c96320 | 6130 | |
b32d5189 | 6131 | for (insn = get_insns (); insn != NULL; insn = NEXT_INSN (insn)) |
96fcacb7 MK |
6132 | { |
6133 | if (INSN_P (insn) && recog_memoized (insn) >= 0) | |
6134 | { | |
6135 | gcc_assert (insn_has_dfa_reservation_p (insn)); | |
b8c96320 | 6136 | |
96fcacb7 MK |
6137 | state_reset (state); |
6138 | if (state_transition (state, insn) >= 0) | |
6139 | gcc_unreachable (); | |
6140 | } | |
6141 | } | |
6142 | } | |
6143 | #endif | |
b8c96320 MK |
6144 | |
6145 | /* Setup target cpu. */ | |
96fcacb7 MK |
6146 | |
6147 | /* ColdFire V4 has a set of features to keep its instruction buffer full | |
6148 | (e.g., a separate memory bus for instructions) and, hence, we do not model | |
6149 | buffer for this CPU. */ | |
6150 | sched_ib.enabled_p = (m68k_sched_cpu != CPU_CFV4); | |
6151 | ||
b8c96320 MK |
6152 | switch (m68k_sched_cpu) |
6153 | { | |
96fcacb7 MK |
6154 | case CPU_CFV4: |
6155 | sched_ib.filled = 0; | |
6156 | ||
6157 | /* FALLTHRU */ | |
6158 | ||
826fadba MK |
6159 | case CPU_CFV1: |
6160 | case CPU_CFV2: | |
6161 | max_insn_size = 3; | |
6162 | sched_ib.records.n_insns = 0; | |
6163 | sched_ib.records.adjust = NULL; | |
6164 | break; | |
6165 | ||
6166 | case CPU_CFV3: | |
6167 | max_insn_size = 3; | |
6168 | sched_ib.records.n_insns = 8; | |
5ead67f6 | 6169 | sched_ib.records.adjust = XNEWVEC (int, sched_ib.records.n_insns); |
b8c96320 MK |
6170 | break; |
6171 | ||
6172 | default: | |
6173 | gcc_unreachable (); | |
6174 | } | |
6175 | ||
826fadba MK |
6176 | sched_mem_unit_code = get_cpu_unit_code ("cf_mem1"); |
6177 | ||
b8c96320 MK |
6178 | sched_adjust_cost_state = xmalloc (state_size ()); |
6179 | state_reset (sched_adjust_cost_state); | |
6180 | ||
6181 | start_sequence (); | |
6182 | emit_insn (gen_ib ()); | |
826fadba | 6183 | sched_ib.insn = get_insns (); |
b8c96320 MK |
6184 | end_sequence (); |
6185 | } | |
6186 | ||
6187 | /* Scheduling pass is now finished. Free/reset static variables. */ | |
6188 | static void | |
6189 | m68k_sched_md_finish_global (FILE *dump ATTRIBUTE_UNUSED, | |
6190 | int verbose ATTRIBUTE_UNUSED) | |
6191 | { | |
826fadba | 6192 | sched_ib.insn = NULL; |
b8c96320 MK |
6193 | |
6194 | free (sched_adjust_cost_state); | |
6195 | sched_adjust_cost_state = NULL; | |
6196 | ||
6197 | sched_mem_unit_code = 0; | |
826fadba MK |
6198 | |
6199 | free (sched_ib.records.adjust); | |
6200 | sched_ib.records.adjust = NULL; | |
6201 | sched_ib.records.n_insns = 0; | |
6202 | max_insn_size = 0; | |
b8c96320 MK |
6203 | } |
6204 | ||
7ecb00a6 | 6205 | /* Implementation of targetm.sched.init () hook. |
b8c96320 MK |
6206 | It is invoked each time scheduler starts on the new block (basic block or |
6207 | extended basic block). */ | |
6208 | static void | |
6209 | m68k_sched_md_init (FILE *sched_dump ATTRIBUTE_UNUSED, | |
6210 | int sched_verbose ATTRIBUTE_UNUSED, | |
6211 | int n_insns ATTRIBUTE_UNUSED) | |
6212 | { | |
826fadba MK |
6213 | switch (m68k_sched_cpu) |
6214 | { | |
6215 | case CPU_CFV1: | |
6216 | case CPU_CFV2: | |
6217 | sched_ib.size = 6; | |
6218 | break; | |
6219 | ||
6220 | case CPU_CFV3: | |
6221 | sched_ib.size = sched_ib.records.n_insns * max_insn_size; | |
6222 | ||
6223 | memset (sched_ib.records.adjust, 0, | |
6224 | sched_ib.records.n_insns * sizeof (*sched_ib.records.adjust)); | |
6225 | sched_ib.records.adjust_index = 0; | |
6226 | break; | |
6227 | ||
96fcacb7 MK |
6228 | case CPU_CFV4: |
6229 | gcc_assert (!sched_ib.enabled_p); | |
6230 | sched_ib.size = 0; | |
6231 | break; | |
6232 | ||
826fadba MK |
6233 | default: |
6234 | gcc_unreachable (); | |
6235 | } | |
6236 | ||
96fcacb7 MK |
6237 | if (sched_ib.enabled_p) |
6238 | /* haifa-sched.c: schedule_block () calls advance_cycle () just before | |
6239 | the first cycle. Workaround that. */ | |
6240 | sched_ib.filled = -2; | |
b8c96320 MK |
6241 | } |
6242 | ||
6243 | /* Implementation of targetm.sched.dfa_pre_advance_cycle () hook. | |
6244 | It is invoked just before current cycle finishes and is used here | |
6245 | to track if instruction buffer got its two words this cycle. */ | |
6246 | static void | |
6247 | m68k_sched_dfa_pre_advance_cycle (void) | |
6248 | { | |
96fcacb7 MK |
6249 | if (!sched_ib.enabled_p) |
6250 | return; | |
6251 | ||
b8c96320 MK |
6252 | if (!cpu_unit_reservation_p (curr_state, sched_mem_unit_code)) |
6253 | { | |
826fadba | 6254 | sched_ib.filled += 2; |
b8c96320 | 6255 | |
826fadba MK |
6256 | if (sched_ib.filled > sched_ib.size) |
6257 | sched_ib.filled = sched_ib.size; | |
b8c96320 MK |
6258 | } |
6259 | } | |
6260 | ||
6261 | /* Implementation of targetm.sched.dfa_post_advance_cycle () hook. | |
6262 | It is invoked just after new cycle begins and is used here | |
6263 | to setup number of filled words in the instruction buffer so that | |
6264 | instructions which won't have all their words prefetched would be | |
6265 | stalled for a cycle. */ | |
6266 | static void | |
6267 | m68k_sched_dfa_post_advance_cycle (void) | |
6268 | { | |
6269 | int i; | |
b8c96320 | 6270 | |
96fcacb7 MK |
6271 | if (!sched_ib.enabled_p) |
6272 | return; | |
6273 | ||
b8c96320 MK |
6274 | /* Setup number of prefetched instruction words in the instruction |
6275 | buffer. */ | |
826fadba MK |
6276 | i = max_insn_size - sched_ib.filled; |
6277 | ||
6278 | while (--i >= 0) | |
b8c96320 | 6279 | { |
826fadba | 6280 | if (state_transition (curr_state, sched_ib.insn) >= 0) |
5f3b7d7c MK |
6281 | /* Pick up scheduler state. */ |
6282 | ++sched_ib.filled; | |
b8c96320 MK |
6283 | } |
6284 | } | |
96fcacb7 MK |
6285 | |
6286 | /* Return X or Y (depending on OPX_P) operand of INSN, | |
6287 | if it is an integer register, or NULL overwise. */ | |
6288 | static rtx | |
647d790d | 6289 | sched_get_reg_operand (rtx_insn *insn, bool opx_p) |
96fcacb7 MK |
6290 | { |
6291 | rtx op = NULL; | |
6292 | ||
6293 | if (opx_p) | |
6294 | { | |
6295 | if (get_attr_opx_type (insn) == OPX_TYPE_RN) | |
6296 | { | |
6297 | op = sched_get_operand (insn, true); | |
6298 | gcc_assert (op != NULL); | |
6299 | ||
6300 | if (!reload_completed && !REG_P (op)) | |
6301 | return NULL; | |
6302 | } | |
6303 | } | |
6304 | else | |
6305 | { | |
6306 | if (get_attr_opy_type (insn) == OPY_TYPE_RN) | |
6307 | { | |
6308 | op = sched_get_operand (insn, false); | |
6309 | gcc_assert (op != NULL); | |
6310 | ||
6311 | if (!reload_completed && !REG_P (op)) | |
6312 | return NULL; | |
6313 | } | |
6314 | } | |
6315 | ||
6316 | return op; | |
6317 | } | |
6318 | ||
6319 | /* Return true, if X or Y (depending on OPX_P) operand of INSN | |
6320 | is a MEM. */ | |
6321 | static bool | |
84034c69 | 6322 | sched_mem_operand_p (rtx_insn *insn, bool opx_p) |
96fcacb7 MK |
6323 | { |
6324 | switch (sched_get_opxy_mem_type (insn, opx_p)) | |
6325 | { | |
6326 | case OP_TYPE_MEM1: | |
6327 | case OP_TYPE_MEM6: | |
6328 | return true; | |
6329 | ||
6330 | default: | |
6331 | return false; | |
6332 | } | |
6333 | } | |
6334 | ||
6335 | /* Return X or Y (depending on OPX_P) operand of INSN, | |
6336 | if it is a MEM, or NULL overwise. */ | |
6337 | static rtx | |
647d790d | 6338 | sched_get_mem_operand (rtx_insn *insn, bool must_read_p, bool must_write_p) |
96fcacb7 MK |
6339 | { |
6340 | bool opx_p; | |
6341 | bool opy_p; | |
6342 | ||
6343 | opx_p = false; | |
6344 | opy_p = false; | |
6345 | ||
6346 | if (must_read_p) | |
6347 | { | |
6348 | opx_p = true; | |
6349 | opy_p = true; | |
6350 | } | |
6351 | ||
6352 | if (must_write_p) | |
6353 | { | |
6354 | opx_p = true; | |
6355 | opy_p = false; | |
6356 | } | |
6357 | ||
6358 | if (opy_p && sched_mem_operand_p (insn, false)) | |
6359 | return sched_get_operand (insn, false); | |
6360 | ||
6361 | if (opx_p && sched_mem_operand_p (insn, true)) | |
6362 | return sched_get_operand (insn, true); | |
6363 | ||
6364 | gcc_unreachable (); | |
6365 | return NULL; | |
6366 | } | |
6367 | ||
6368 | /* Return non-zero if PRO modifies register used as part of | |
6369 | address in CON. */ | |
6370 | int | |
647d790d | 6371 | m68k_sched_address_bypass_p (rtx_insn *pro, rtx_insn *con) |
96fcacb7 MK |
6372 | { |
6373 | rtx pro_x; | |
6374 | rtx con_mem_read; | |
6375 | ||
6376 | pro_x = sched_get_reg_operand (pro, true); | |
6377 | if (pro_x == NULL) | |
6378 | return 0; | |
6379 | ||
6380 | con_mem_read = sched_get_mem_operand (con, true, false); | |
6381 | gcc_assert (con_mem_read != NULL); | |
6382 | ||
6383 | if (reg_mentioned_p (pro_x, con_mem_read)) | |
6384 | return 1; | |
6385 | ||
6386 | return 0; | |
6387 | } | |
6388 | ||
6389 | /* Helper function for m68k_sched_indexed_address_bypass_p. | |
6390 | if PRO modifies register used as index in CON, | |
6391 | return scale of indexed memory access in CON. Return zero overwise. */ | |
6392 | static int | |
647d790d | 6393 | sched_get_indexed_address_scale (rtx_insn *pro, rtx_insn *con) |
96fcacb7 MK |
6394 | { |
6395 | rtx reg; | |
6396 | rtx mem; | |
6397 | struct m68k_address address; | |
6398 | ||
6399 | reg = sched_get_reg_operand (pro, true); | |
6400 | if (reg == NULL) | |
6401 | return 0; | |
6402 | ||
6403 | mem = sched_get_mem_operand (con, true, false); | |
6404 | gcc_assert (mem != NULL && MEM_P (mem)); | |
6405 | ||
6406 | if (!m68k_decompose_address (GET_MODE (mem), XEXP (mem, 0), reload_completed, | |
6407 | &address)) | |
6408 | gcc_unreachable (); | |
6409 | ||
6410 | if (REGNO (reg) == REGNO (address.index)) | |
6411 | { | |
6412 | gcc_assert (address.scale != 0); | |
6413 | return address.scale; | |
6414 | } | |
6415 | ||
6416 | return 0; | |
6417 | } | |
6418 | ||
6419 | /* Return non-zero if PRO modifies register used | |
6420 | as index with scale 2 or 4 in CON. */ | |
6421 | int | |
647d790d | 6422 | m68k_sched_indexed_address_bypass_p (rtx_insn *pro, rtx_insn *con) |
96fcacb7 MK |
6423 | { |
6424 | gcc_assert (sched_cfv4_bypass_data.pro == NULL | |
6425 | && sched_cfv4_bypass_data.con == NULL | |
6426 | && sched_cfv4_bypass_data.scale == 0); | |
6427 | ||
6428 | switch (sched_get_indexed_address_scale (pro, con)) | |
6429 | { | |
6430 | case 1: | |
6431 | /* We can't have a variable latency bypass, so | |
6432 | remember to adjust the insn cost in adjust_cost hook. */ | |
6433 | sched_cfv4_bypass_data.pro = pro; | |
6434 | sched_cfv4_bypass_data.con = con; | |
6435 | sched_cfv4_bypass_data.scale = 1; | |
6436 | return 0; | |
6437 | ||
6438 | case 2: | |
6439 | case 4: | |
6440 | return 1; | |
6441 | ||
6442 | default: | |
6443 | return 0; | |
6444 | } | |
6445 | } | |
75df395f | 6446 | |
e0601576 RH |
6447 | /* We generate a two-instructions program at M_TRAMP : |
6448 | movea.l &CHAIN_VALUE,%a0 | |
6449 | jmp FNADDR | |
6450 | where %a0 can be modified by changing STATIC_CHAIN_REGNUM. */ | |
6451 | ||
6452 | static void | |
6453 | m68k_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) | |
6454 | { | |
6455 | rtx fnaddr = XEXP (DECL_RTL (fndecl), 0); | |
6456 | rtx mem; | |
6457 | ||
6458 | gcc_assert (ADDRESS_REGNO_P (STATIC_CHAIN_REGNUM)); | |
6459 | ||
6460 | mem = adjust_address (m_tramp, HImode, 0); | |
6461 | emit_move_insn (mem, GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM-8) << 9))); | |
6462 | mem = adjust_address (m_tramp, SImode, 2); | |
6463 | emit_move_insn (mem, chain_value); | |
6464 | ||
6465 | mem = adjust_address (m_tramp, HImode, 6); | |
6466 | emit_move_insn (mem, GEN_INT(0x4EF9)); | |
6467 | mem = adjust_address (m_tramp, SImode, 8); | |
6468 | emit_move_insn (mem, fnaddr); | |
6469 | ||
6470 | FINALIZE_TRAMPOLINE (XEXP (m_tramp, 0)); | |
6471 | } | |
6472 | ||
079e7538 NF |
6473 | /* On the 68000, the RTS insn cannot pop anything. |
6474 | On the 68010, the RTD insn may be used to pop them if the number | |
6475 | of args is fixed, but if the number is variable then the caller | |
6476 | must pop them all. RTD can't be used for library calls now | |
6477 | because the library is compiled with the Unix compiler. | |
6478 | Use of RTD is a selectable option, since it is incompatible with | |
6479 | standard Unix calling sequences. If the option is not selected, | |
6480 | the caller must always pop the args. */ | |
6481 | ||
6482 | static int | |
6483 | m68k_return_pops_args (tree fundecl, tree funtype, int size) | |
6484 | { | |
6485 | return ((TARGET_RTD | |
6486 | && (!fundecl | |
6487 | || TREE_CODE (fundecl) != IDENTIFIER_NODE) | |
f38958e8 | 6488 | && (!stdarg_p (funtype))) |
079e7538 NF |
6489 | ? size : 0); |
6490 | } | |
6491 | ||
5efd84c5 NF |
6492 | /* Make sure everything's fine if we *don't* have a given processor. |
6493 | This assumes that putting a register in fixed_regs will keep the | |
6494 | compiler's mitts completely off it. We don't bother to zero it out | |
6495 | of register classes. */ | |
6496 | ||
6497 | static void | |
6498 | m68k_conditional_register_usage (void) | |
6499 | { | |
6500 | int i; | |
6501 | HARD_REG_SET x; | |
6502 | if (!TARGET_HARD_FLOAT) | |
6503 | { | |
6504 | COPY_HARD_REG_SET (x, reg_class_contents[(int)FP_REGS]); | |
6505 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
6506 | if (TEST_HARD_REG_BIT (x, i)) | |
6507 | fixed_regs[i] = call_used_regs[i] = 1; | |
6508 | } | |
6509 | if (flag_pic) | |
6510 | fixed_regs[PIC_REG] = call_used_regs[PIC_REG] = 1; | |
6511 | } | |
6512 | ||
8b281334 RH |
6513 | static void |
6514 | m68k_init_sync_libfuncs (void) | |
6515 | { | |
6516 | init_sync_libfuncs (UNITS_PER_WORD); | |
6517 | } | |
6518 | ||
175aed00 AS |
6519 | /* Implements EPILOGUE_USES. All registers are live on exit from an |
6520 | interrupt routine. */ | |
6521 | bool | |
6522 | m68k_epilogue_uses (int regno ATTRIBUTE_UNUSED) | |
6523 | { | |
6524 | return (reload_completed | |
6525 | && (m68k_get_function_kind (current_function_decl) | |
6526 | == m68k_fk_interrupt_handler)); | |
6527 | } | |
6528 | ||
75df395f | 6529 | #include "gt-m68k.h" |