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