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