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