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