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