1 /* Subroutines for insn-output.c for Motorola 68000 family.
2 Copyright (C) 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
42 #include "target-def.h"
46 /* ??? Need to add a dependency between m68k.o and sched-int.h. */
47 #include "sched-int.h"
48 #include "insn-codes.h"
51 enum reg_class regno_reg_class[] =
53 DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS,
54 DATA_REGS, DATA_REGS, DATA_REGS, DATA_REGS,
55 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
56 ADDR_REGS, ADDR_REGS, ADDR_REGS, ADDR_REGS,
57 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
58 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
63 /* The minimum number of integer registers that we want to save with the
64 movem instruction. Using two movel instructions instead of a single
65 moveml is about 15% faster for the 68020 and 68030 at no expense in
67 #define MIN_MOVEM_REGS 3
69 /* The minimum number of floating point registers that we want to save
70 with the fmovem instruction. */
71 #define MIN_FMOVEM_REGS 1
73 /* Structure describing stack frame layout. */
76 /* Stack pointer to frame pointer offset. */
79 /* Offset of FPU registers. */
80 HOST_WIDE_INT foffset;
82 /* Frame size in bytes (rounded up). */
85 /* Data and address register. */
87 unsigned int reg_mask;
91 unsigned int fpu_mask;
93 /* Offsets relative to ARG_POINTER. */
94 HOST_WIDE_INT frame_pointer_offset;
95 HOST_WIDE_INT stack_pointer_offset;
97 /* Function which the above information refers to. */
101 /* Current frame information calculated by m68k_compute_frame_layout(). */
102 static struct m68k_frame current_frame;
104 /* Structure describing an m68k address.
106 If CODE is UNKNOWN, the address is BASE + INDEX * SCALE + OFFSET,
107 with null fields evaluating to 0. Here:
109 - BASE satisfies m68k_legitimate_base_reg_p
110 - INDEX satisfies m68k_legitimate_index_reg_p
111 - OFFSET satisfies m68k_legitimate_constant_address_p
113 INDEX is either HImode or SImode. The other fields are SImode.
115 If CODE is PRE_DEC, the address is -(BASE). If CODE is POST_INC,
116 the address is (BASE)+. */
117 struct m68k_address {
125 static int m68k_sched_adjust_cost (rtx, rtx, rtx, int);
126 static int m68k_sched_issue_rate (void);
127 static int m68k_sched_variable_issue (FILE *, int, rtx, int);
128 static void m68k_sched_md_init_global (FILE *, int, int);
129 static void m68k_sched_md_finish_global (FILE *, int);
130 static void m68k_sched_md_init (FILE *, int, int);
131 static void m68k_sched_dfa_pre_advance_cycle (void);
132 static void m68k_sched_dfa_post_advance_cycle (void);
133 static int m68k_sched_first_cycle_multipass_dfa_lookahead (void);
135 static bool m68k_can_eliminate (const int, const int);
136 static bool m68k_legitimate_address_p (enum machine_mode, rtx, bool);
137 static bool m68k_handle_option (size_t, const char *, int);
138 static rtx find_addr_reg (rtx);
139 static const char *singlemove_string (rtx *);
140 static void m68k_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
141 HOST_WIDE_INT, tree);
142 static rtx m68k_struct_value_rtx (tree, int);
143 static tree m68k_handle_fndecl_attribute (tree *node, tree name,
144 tree args, int flags,
146 static void m68k_compute_frame_layout (void);
147 static bool m68k_save_reg (unsigned int regno, bool interrupt_handler);
148 static bool m68k_ok_for_sibcall_p (tree, tree);
149 static bool m68k_tls_symbol_p (rtx);
150 static rtx m68k_legitimize_address (rtx, rtx, enum machine_mode);
151 static bool m68k_rtx_costs (rtx, int, int, int *, bool);
152 #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
153 static bool m68k_return_in_memory (const_tree, const_tree);
155 static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
158 /* Specify the identification number of the library being built */
159 const char *m68k_library_id_string = "_current_shared_library_a5_offset_";
161 /* Initialize the GCC target structure. */
163 #if INT_OP_GROUP == INT_OP_DOT_WORD
164 #undef TARGET_ASM_ALIGNED_HI_OP
165 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
168 #if INT_OP_GROUP == INT_OP_NO_DOT
169 #undef TARGET_ASM_BYTE_OP
170 #define TARGET_ASM_BYTE_OP "\tbyte\t"
171 #undef TARGET_ASM_ALIGNED_HI_OP
172 #define TARGET_ASM_ALIGNED_HI_OP "\tshort\t"
173 #undef TARGET_ASM_ALIGNED_SI_OP
174 #define TARGET_ASM_ALIGNED_SI_OP "\tlong\t"
177 #if INT_OP_GROUP == INT_OP_DC
178 #undef TARGET_ASM_BYTE_OP
179 #define TARGET_ASM_BYTE_OP "\tdc.b\t"
180 #undef TARGET_ASM_ALIGNED_HI_OP
181 #define TARGET_ASM_ALIGNED_HI_OP "\tdc.w\t"
182 #undef TARGET_ASM_ALIGNED_SI_OP
183 #define TARGET_ASM_ALIGNED_SI_OP "\tdc.l\t"
186 #undef TARGET_ASM_UNALIGNED_HI_OP
187 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
188 #undef TARGET_ASM_UNALIGNED_SI_OP
189 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
191 #undef TARGET_ASM_OUTPUT_MI_THUNK
192 #define TARGET_ASM_OUTPUT_MI_THUNK m68k_output_mi_thunk
193 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
194 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
196 #undef TARGET_ASM_FILE_START_APP_OFF
197 #define TARGET_ASM_FILE_START_APP_OFF true
199 #undef TARGET_LEGITIMIZE_ADDRESS
200 #define TARGET_LEGITIMIZE_ADDRESS m68k_legitimize_address
202 #undef TARGET_SCHED_ADJUST_COST
203 #define TARGET_SCHED_ADJUST_COST m68k_sched_adjust_cost
205 #undef TARGET_SCHED_ISSUE_RATE
206 #define TARGET_SCHED_ISSUE_RATE m68k_sched_issue_rate
208 #undef TARGET_SCHED_VARIABLE_ISSUE
209 #define TARGET_SCHED_VARIABLE_ISSUE m68k_sched_variable_issue
211 #undef TARGET_SCHED_INIT_GLOBAL
212 #define TARGET_SCHED_INIT_GLOBAL m68k_sched_md_init_global
214 #undef TARGET_SCHED_FINISH_GLOBAL
215 #define TARGET_SCHED_FINISH_GLOBAL m68k_sched_md_finish_global
217 #undef TARGET_SCHED_INIT
218 #define TARGET_SCHED_INIT m68k_sched_md_init
220 #undef TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE
221 #define TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE m68k_sched_dfa_pre_advance_cycle
223 #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE
224 #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE m68k_sched_dfa_post_advance_cycle
226 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
227 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
228 m68k_sched_first_cycle_multipass_dfa_lookahead
230 #undef TARGET_HANDLE_OPTION
231 #define TARGET_HANDLE_OPTION m68k_handle_option
233 #undef TARGET_RTX_COSTS
234 #define TARGET_RTX_COSTS m68k_rtx_costs
236 #undef TARGET_ATTRIBUTE_TABLE
237 #define TARGET_ATTRIBUTE_TABLE m68k_attribute_table
239 #undef TARGET_PROMOTE_PROTOTYPES
240 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
242 #undef TARGET_STRUCT_VALUE_RTX
243 #define TARGET_STRUCT_VALUE_RTX m68k_struct_value_rtx
245 #undef TARGET_CANNOT_FORCE_CONST_MEM
246 #define TARGET_CANNOT_FORCE_CONST_MEM m68k_illegitimate_symbolic_constant_p
248 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
249 #define TARGET_FUNCTION_OK_FOR_SIBCALL m68k_ok_for_sibcall_p
251 #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
252 #undef TARGET_RETURN_IN_MEMORY
253 #define TARGET_RETURN_IN_MEMORY m68k_return_in_memory
257 #undef TARGET_HAVE_TLS
258 #define TARGET_HAVE_TLS (true)
260 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
261 #define TARGET_ASM_OUTPUT_DWARF_DTPREL m68k_output_dwarf_dtprel
264 #undef TARGET_LEGITIMATE_ADDRESS_P
265 #define TARGET_LEGITIMATE_ADDRESS_P m68k_legitimate_address_p
267 #undef TARGET_CAN_ELIMINATE
268 #define TARGET_CAN_ELIMINATE m68k_can_eliminate
270 static const struct attribute_spec m68k_attribute_table[] =
272 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
273 { "interrupt", 0, 0, true, false, false, m68k_handle_fndecl_attribute },
274 { "interrupt_handler", 0, 0, true, false, false, m68k_handle_fndecl_attribute },
275 { "interrupt_thread", 0, 0, true, false, false, m68k_handle_fndecl_attribute },
276 { NULL, 0, 0, false, false, false, NULL }
279 struct gcc_target targetm = TARGET_INITIALIZER;
281 /* Base flags for 68k ISAs. */
282 #define FL_FOR_isa_00 FL_ISA_68000
283 #define FL_FOR_isa_10 (FL_FOR_isa_00 | FL_ISA_68010)
284 /* FL_68881 controls the default setting of -m68881. gcc has traditionally
285 generated 68881 code for 68020 and 68030 targets unless explicitly told
287 #define FL_FOR_isa_20 (FL_FOR_isa_10 | FL_ISA_68020 \
288 | FL_BITFIELD | FL_68881)
289 #define FL_FOR_isa_40 (FL_FOR_isa_20 | FL_ISA_68040)
290 #define FL_FOR_isa_cpu32 (FL_FOR_isa_10 | FL_ISA_68020)
292 /* Base flags for ColdFire ISAs. */
293 #define FL_FOR_isa_a (FL_COLDFIRE | FL_ISA_A)
294 #define FL_FOR_isa_aplus (FL_FOR_isa_a | FL_ISA_APLUS | FL_CF_USP)
295 /* Note ISA_B doesn't necessarily include USP (user stack pointer) support. */
296 #define FL_FOR_isa_b (FL_FOR_isa_a | FL_ISA_B | FL_CF_HWDIV)
297 /* ISA_C is not upwardly compatible with ISA_B. */
298 #define FL_FOR_isa_c (FL_FOR_isa_a | FL_ISA_C | FL_CF_USP)
302 /* Traditional 68000 instruction sets. */
308 /* ColdFire instruction set variants. */
316 /* Information about one of the -march, -mcpu or -mtune arguments. */
317 struct m68k_target_selection
319 /* The argument being described. */
322 /* For -mcpu, this is the device selected by the option.
323 For -mtune and -march, it is a representative device
324 for the microarchitecture or ISA respectively. */
325 enum target_device device;
327 /* The M68K_DEVICE fields associated with DEVICE. See the comment
328 in m68k-devices.def for details. FAMILY is only valid for -mcpu. */
330 enum uarch_type microarch;
335 /* A list of all devices in m68k-devices.def. Used for -mcpu selection. */
336 static const struct m68k_target_selection all_devices[] =
338 #define M68K_DEVICE(NAME,ENUM_VALUE,FAMILY,MULTILIB,MICROARCH,ISA,FLAGS) \
339 { NAME, ENUM_VALUE, FAMILY, u##MICROARCH, ISA, FLAGS | FL_FOR_##ISA },
340 #include "m68k-devices.def"
342 { NULL, unk_device, NULL, unk_arch, isa_max, 0 }
345 /* A list of all ISAs, mapping each one to a representative device.
346 Used for -march selection. */
347 static const struct m68k_target_selection all_isas[] =
349 { "68000", m68000, NULL, u68000, isa_00, FL_FOR_isa_00 },
350 { "68010", m68010, NULL, u68010, isa_10, FL_FOR_isa_10 },
351 { "68020", m68020, NULL, u68020, isa_20, FL_FOR_isa_20 },
352 { "68030", m68030, NULL, u68030, isa_20, FL_FOR_isa_20 },
353 { "68040", m68040, NULL, u68040, isa_40, FL_FOR_isa_40 },
354 { "68060", m68060, NULL, u68060, isa_40, FL_FOR_isa_40 },
355 { "cpu32", cpu32, NULL, ucpu32, isa_20, FL_FOR_isa_cpu32 },
356 { "isaa", mcf5206e, NULL, ucfv2, isa_a, (FL_FOR_isa_a
358 { "isaaplus", mcf5271, NULL, ucfv2, isa_aplus, (FL_FOR_isa_aplus
360 { "isab", mcf5407, NULL, ucfv4, isa_b, FL_FOR_isa_b },
361 { "isac", unk_device, NULL, ucfv4, isa_c, (FL_FOR_isa_c
363 { NULL, unk_device, NULL, unk_arch, isa_max, 0 }
366 /* A list of all microarchitectures, mapping each one to a representative
367 device. Used for -mtune selection. */
368 static const struct m68k_target_selection all_microarchs[] =
370 { "68000", m68000, NULL, u68000, isa_00, FL_FOR_isa_00 },
371 { "68010", m68010, NULL, u68010, isa_10, FL_FOR_isa_10 },
372 { "68020", m68020, NULL, u68020, isa_20, FL_FOR_isa_20 },
373 { "68020-40", m68020, NULL, u68020_40, isa_20, FL_FOR_isa_20 },
374 { "68020-60", m68020, NULL, u68020_60, isa_20, FL_FOR_isa_20 },
375 { "68030", m68030, NULL, u68030, isa_20, FL_FOR_isa_20 },
376 { "68040", m68040, NULL, u68040, isa_40, FL_FOR_isa_40 },
377 { "68060", m68060, NULL, u68060, isa_40, FL_FOR_isa_40 },
378 { "cpu32", cpu32, NULL, ucpu32, isa_20, FL_FOR_isa_cpu32 },
379 { "cfv1", mcf51qe, NULL, ucfv1, isa_c, FL_FOR_isa_c },
380 { "cfv2", mcf5206, NULL, ucfv2, isa_a, FL_FOR_isa_a },
381 { "cfv3", mcf5307, NULL, ucfv3, isa_a, (FL_FOR_isa_a
383 { "cfv4", mcf5407, NULL, ucfv4, isa_b, FL_FOR_isa_b },
384 { "cfv4e", mcf547x, NULL, ucfv4e, isa_b, (FL_FOR_isa_b
388 { NULL, unk_device, NULL, unk_arch, isa_max, 0 }
391 /* The entries associated with the -mcpu, -march and -mtune settings,
392 or null for options that have not been used. */
393 const struct m68k_target_selection *m68k_cpu_entry;
394 const struct m68k_target_selection *m68k_arch_entry;
395 const struct m68k_target_selection *m68k_tune_entry;
397 /* Which CPU we are generating code for. */
398 enum target_device m68k_cpu;
400 /* Which microarchitecture to tune for. */
401 enum uarch_type m68k_tune;
403 /* Which FPU to use. */
404 enum fpu_type m68k_fpu;
406 /* The set of FL_* flags that apply to the target processor. */
407 unsigned int m68k_cpu_flags;
409 /* The set of FL_* flags that apply to the processor to be tuned for. */
410 unsigned int m68k_tune_flags;
412 /* Asm templates for calling or jumping to an arbitrary symbolic address,
413 or NULL if such calls or jumps are not supported. The address is held
415 const char *m68k_symbolic_call;
416 const char *m68k_symbolic_jump;
418 /* Enum variable that corresponds to m68k_symbolic_call values. */
419 enum M68K_SYMBOLIC_CALL m68k_symbolic_call_var;
422 /* See whether TABLE has an entry with name NAME. Return true and
423 store the entry in *ENTRY if so, otherwise return false and
424 leave *ENTRY alone. */
427 m68k_find_selection (const struct m68k_target_selection **entry,
428 const struct m68k_target_selection *table,
433 for (i = 0; table[i].name; i++)
434 if (strcmp (table[i].name, name) == 0)
442 /* Implement TARGET_HANDLE_OPTION. */
445 m68k_handle_option (size_t code, const char *arg, int value)
450 return m68k_find_selection (&m68k_arch_entry, all_isas, arg);
453 return m68k_find_selection (&m68k_cpu_entry, all_devices, arg);
456 return m68k_find_selection (&m68k_tune_entry, all_microarchs, arg);
459 return m68k_find_selection (&m68k_cpu_entry, all_devices, "5206");
462 return m68k_find_selection (&m68k_cpu_entry, all_devices, "5206e");
465 return m68k_find_selection (&m68k_cpu_entry, all_devices, "528x");
468 return m68k_find_selection (&m68k_cpu_entry, all_devices, "5307");
471 return m68k_find_selection (&m68k_cpu_entry, all_devices, "5407");
474 return m68k_find_selection (&m68k_cpu_entry, all_devices, "547x");
478 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68000");
481 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68010");
485 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68020");
488 return (m68k_find_selection (&m68k_tune_entry, all_microarchs,
490 && m68k_find_selection (&m68k_cpu_entry, all_devices, "68020"));
493 return (m68k_find_selection (&m68k_tune_entry, all_microarchs,
495 && m68k_find_selection (&m68k_cpu_entry, all_devices, "68020"));
498 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68030");
501 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68040");
504 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68060");
507 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68302");
511 return m68k_find_selection (&m68k_cpu_entry, all_devices, "68332");
513 case OPT_mshared_library_id_:
514 if (value > MAX_LIBRARY_ID)
515 error ("-mshared-library-id=%s is not between 0 and %d",
516 arg, MAX_LIBRARY_ID);
520 asprintf (&tmp, "%d", (value * -4) - 4);
521 m68k_library_id_string = tmp;
530 /* Sometimes certain combinations of command options do not make
531 sense on a particular target machine. You can define a macro
532 `OVERRIDE_OPTIONS' to take account of this. This macro, if
533 defined, is executed once just after all the command options have
536 Don't use this macro to turn on various extra optimizations for
537 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
540 override_options (void)
542 const struct m68k_target_selection *entry;
543 unsigned long target_mask;
551 -march=ARCH should generate code that runs any processor
552 implementing architecture ARCH. -mcpu=CPU should override -march
553 and should generate code that runs on processor CPU, making free
554 use of any instructions that CPU understands. -mtune=UARCH applies
555 on top of -mcpu or -march and optimizes the code for UARCH. It does
556 not change the target architecture. */
559 /* Complain if the -march setting is for a different microarchitecture,
560 or includes flags that the -mcpu setting doesn't. */
562 && (m68k_arch_entry->microarch != m68k_cpu_entry->microarch
563 || (m68k_arch_entry->flags & ~m68k_cpu_entry->flags) != 0))
564 warning (0, "-mcpu=%s conflicts with -march=%s",
565 m68k_cpu_entry->name, m68k_arch_entry->name);
567 entry = m68k_cpu_entry;
570 entry = m68k_arch_entry;
573 entry = all_devices + TARGET_CPU_DEFAULT;
575 m68k_cpu_flags = entry->flags;
577 /* Use the architecture setting to derive default values for
581 /* ColdFire is lenient about alignment. */
582 if (!TARGET_COLDFIRE)
583 target_mask |= MASK_STRICT_ALIGNMENT;
585 if ((m68k_cpu_flags & FL_BITFIELD) != 0)
586 target_mask |= MASK_BITFIELD;
587 if ((m68k_cpu_flags & FL_CF_HWDIV) != 0)
588 target_mask |= MASK_CF_HWDIV;
589 if ((m68k_cpu_flags & (FL_68881 | FL_CF_FPU)) != 0)
590 target_mask |= MASK_HARD_FLOAT;
591 target_flags |= target_mask & ~target_flags_explicit;
593 /* Set the directly-usable versions of the -mcpu and -mtune settings. */
594 m68k_cpu = entry->device;
597 m68k_tune = m68k_tune_entry->microarch;
598 m68k_tune_flags = m68k_tune_entry->flags;
600 #ifdef M68K_DEFAULT_TUNE
601 else if (!m68k_cpu_entry && !m68k_arch_entry)
603 enum target_device dev;
604 dev = all_microarchs[M68K_DEFAULT_TUNE].device;
605 m68k_tune_flags = all_devices[dev]->flags;
610 m68k_tune = entry->microarch;
611 m68k_tune_flags = entry->flags;
614 /* Set the type of FPU. */
615 m68k_fpu = (!TARGET_HARD_FLOAT ? FPUTYPE_NONE
616 : (m68k_cpu_flags & FL_COLDFIRE) != 0 ? FPUTYPE_COLDFIRE
619 /* Sanity check to ensure that msep-data and mid-sahred-library are not
620 * both specified together. Doing so simply doesn't make sense.
622 if (TARGET_SEP_DATA && TARGET_ID_SHARED_LIBRARY)
623 error ("cannot specify both -msep-data and -mid-shared-library");
625 /* If we're generating code for a separate A5 relative data segment,
626 * we've got to enable -fPIC as well. This might be relaxable to
627 * -fpic but it hasn't been tested properly.
629 if (TARGET_SEP_DATA || TARGET_ID_SHARED_LIBRARY)
632 /* -mpcrel -fPIC uses 32-bit pc-relative displacements. Raise an
633 error if the target does not support them. */
634 if (TARGET_PCREL && !TARGET_68020 && flag_pic == 2)
635 error ("-mpcrel -fPIC is not currently supported on selected cpu");
637 /* ??? A historic way of turning on pic, or is this intended to
638 be an embedded thing that doesn't have the same name binding
639 significance that it does on hosted ELF systems? */
640 if (TARGET_PCREL && flag_pic == 0)
645 m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_JSR;
647 m68k_symbolic_jump = "jra %a0";
649 else if (TARGET_ID_SHARED_LIBRARY)
650 /* All addresses must be loaded from the GOT. */
652 else if (TARGET_68020 || TARGET_ISAB || TARGET_ISAC)
655 m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_BSR_C;
657 m68k_symbolic_call_var = M68K_SYMBOLIC_CALL_BSR_P;
660 /* No unconditional long branch */;
661 else if (TARGET_PCREL)
662 m68k_symbolic_jump = "bra%.l %c0";
664 m68k_symbolic_jump = "bra%.l %p0";
665 /* Turn off function cse if we are doing PIC. We always want
666 function call to be done as `bsr foo@PLTPC'. */
667 /* ??? It's traditional to do this for -mpcrel too, but it isn't
668 clear how intentional that is. */
669 flag_no_function_cse = 1;
672 switch (m68k_symbolic_call_var)
674 case M68K_SYMBOLIC_CALL_JSR:
675 m68k_symbolic_call = "jsr %a0";
678 case M68K_SYMBOLIC_CALL_BSR_C:
679 m68k_symbolic_call = "bsr%.l %c0";
682 case M68K_SYMBOLIC_CALL_BSR_P:
683 m68k_symbolic_call = "bsr%.l %p0";
686 case M68K_SYMBOLIC_CALL_NONE:
687 gcc_assert (m68k_symbolic_call == NULL);
694 #ifndef ASM_OUTPUT_ALIGN_WITH_NOP
695 if (align_labels > 2)
697 warning (0, "-falign-labels=%d is not supported", align_labels);
702 warning (0, "-falign-loops=%d is not supported", align_loops);
707 SUBTARGET_OVERRIDE_OPTIONS;
709 /* Setup scheduling options. */
711 m68k_sched_cpu = CPU_CFV1;
713 m68k_sched_cpu = CPU_CFV2;
715 m68k_sched_cpu = CPU_CFV3;
717 m68k_sched_cpu = CPU_CFV4;
720 m68k_sched_cpu = CPU_UNKNOWN;
721 flag_schedule_insns = 0;
722 flag_schedule_insns_after_reload = 0;
723 flag_modulo_sched = 0;
726 if (m68k_sched_cpu != CPU_UNKNOWN)
728 if ((m68k_cpu_flags & (FL_CF_EMAC | FL_CF_EMAC_B)) != 0)
729 m68k_sched_mac = MAC_CF_EMAC;
730 else if ((m68k_cpu_flags & FL_CF_MAC) != 0)
731 m68k_sched_mac = MAC_CF_MAC;
733 m68k_sched_mac = MAC_NO;
737 /* Generate a macro of the form __mPREFIX_cpu_NAME, where PREFIX is the
738 given argument and NAME is the argument passed to -mcpu. Return NULL
739 if -mcpu was not passed. */
742 m68k_cpp_cpu_ident (const char *prefix)
746 return concat ("__m", prefix, "_cpu_", m68k_cpu_entry->name, NULL);
749 /* Generate a macro of the form __mPREFIX_family_NAME, where PREFIX is the
750 given argument and NAME is the name of the representative device for
751 the -mcpu argument's family. Return NULL if -mcpu was not passed. */
754 m68k_cpp_cpu_family (const char *prefix)
758 return concat ("__m", prefix, "_family_", m68k_cpu_entry->family, NULL);
761 /* Return m68k_fk_interrupt_handler if FUNC has an "interrupt" or
762 "interrupt_handler" attribute and interrupt_thread if FUNC has an
763 "interrupt_thread" attribute. Otherwise, return
764 m68k_fk_normal_function. */
766 enum m68k_function_kind
767 m68k_get_function_kind (tree func)
771 gcc_assert (TREE_CODE (func) == FUNCTION_DECL);
773 a = lookup_attribute ("interrupt", DECL_ATTRIBUTES (func));
775 return m68k_fk_interrupt_handler;
777 a = lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func));
779 return m68k_fk_interrupt_handler;
781 a = lookup_attribute ("interrupt_thread", DECL_ATTRIBUTES (func));
783 return m68k_fk_interrupt_thread;
785 return m68k_fk_normal_function;
788 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
789 struct attribute_spec.handler. */
791 m68k_handle_fndecl_attribute (tree *node, tree name,
792 tree args ATTRIBUTE_UNUSED,
793 int flags ATTRIBUTE_UNUSED,
796 if (TREE_CODE (*node) != FUNCTION_DECL)
798 warning (OPT_Wattributes, "%qE attribute only applies to functions",
800 *no_add_attrs = true;
803 if (m68k_get_function_kind (*node) != m68k_fk_normal_function)
805 error ("multiple interrupt attributes not allowed");
806 *no_add_attrs = true;
810 && !strcmp (IDENTIFIER_POINTER (name), "interrupt_thread"))
812 error ("interrupt_thread is available only on fido");
813 *no_add_attrs = true;
820 m68k_compute_frame_layout (void)
824 enum m68k_function_kind func_kind =
825 m68k_get_function_kind (current_function_decl);
826 bool interrupt_handler = func_kind == m68k_fk_interrupt_handler;
827 bool interrupt_thread = func_kind == m68k_fk_interrupt_thread;
829 /* Only compute the frame once per function.
830 Don't cache information until reload has been completed. */
831 if (current_frame.funcdef_no == current_function_funcdef_no
835 current_frame.size = (get_frame_size () + 3) & -4;
839 /* Interrupt thread does not need to save any register. */
840 if (!interrupt_thread)
841 for (regno = 0; regno < 16; regno++)
842 if (m68k_save_reg (regno, interrupt_handler))
844 mask |= 1 << (regno - D0_REG);
847 current_frame.offset = saved * 4;
848 current_frame.reg_no = saved;
849 current_frame.reg_mask = mask;
851 current_frame.foffset = 0;
853 if (TARGET_HARD_FLOAT)
855 /* Interrupt thread does not need to save any register. */
856 if (!interrupt_thread)
857 for (regno = 16; regno < 24; regno++)
858 if (m68k_save_reg (regno, interrupt_handler))
860 mask |= 1 << (regno - FP0_REG);
863 current_frame.foffset = saved * TARGET_FP_REG_SIZE;
864 current_frame.offset += current_frame.foffset;
866 current_frame.fpu_no = saved;
867 current_frame.fpu_mask = mask;
869 /* Remember what function this frame refers to. */
870 current_frame.funcdef_no = current_function_funcdef_no;
873 /* Worker function for TARGET_CAN_ELIMINATE. */
876 m68k_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
878 return (to == STACK_POINTER_REGNUM ? ! frame_pointer_needed : true);
882 m68k_initial_elimination_offset (int from, int to)
885 /* The arg pointer points 8 bytes before the start of the arguments,
886 as defined by FIRST_PARM_OFFSET. This makes it coincident with the
887 frame pointer in most frames. */
888 argptr_offset = frame_pointer_needed ? 0 : UNITS_PER_WORD;
889 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
890 return argptr_offset;
892 m68k_compute_frame_layout ();
894 gcc_assert (to == STACK_POINTER_REGNUM);
897 case ARG_POINTER_REGNUM:
898 return current_frame.offset + current_frame.size - argptr_offset;
899 case FRAME_POINTER_REGNUM:
900 return current_frame.offset + current_frame.size;
906 /* Refer to the array `regs_ever_live' to determine which registers
907 to save; `regs_ever_live[I]' is nonzero if register number I
908 is ever used in the function. This function is responsible for
909 knowing which registers should not be saved even if used.
910 Return true if we need to save REGNO. */
913 m68k_save_reg (unsigned int regno, bool interrupt_handler)
915 if (flag_pic && regno == PIC_REG)
917 if (crtl->saves_all_registers)
919 if (crtl->uses_pic_offset_table)
921 /* Reload may introduce constant pool references into a function
922 that thitherto didn't need a PIC register. Note that the test
923 above will not catch that case because we will only set
924 crtl->uses_pic_offset_table when emitting
925 the address reloads. */
926 if (crtl->uses_const_pool)
930 if (crtl->calls_eh_return)
935 unsigned int test = EH_RETURN_DATA_REGNO (i);
936 if (test == INVALID_REGNUM)
943 /* Fixed regs we never touch. */
944 if (fixed_regs[regno])
947 /* The frame pointer (if it is such) is handled specially. */
948 if (regno == FRAME_POINTER_REGNUM && frame_pointer_needed)
951 /* Interrupt handlers must also save call_used_regs
952 if they are live or when calling nested functions. */
953 if (interrupt_handler)
955 if (df_regs_ever_live_p (regno))
958 if (!current_function_is_leaf && call_used_regs[regno])
962 /* Never need to save registers that aren't touched. */
963 if (!df_regs_ever_live_p (regno))
966 /* Otherwise save everything that isn't call-clobbered. */
967 return !call_used_regs[regno];
970 /* Emit RTL for a MOVEM or FMOVEM instruction. BASE + OFFSET represents
971 the lowest memory address. COUNT is the number of registers to be
972 moved, with register REGNO + I being moved if bit I of MASK is set.
973 STORE_P specifies the direction of the move and ADJUST_STACK_P says
974 whether or not this is pre-decrement (if STORE_P) or post-increment
975 (if !STORE_P) operation. */
978 m68k_emit_movem (rtx base, HOST_WIDE_INT offset,
979 unsigned int count, unsigned int regno,
980 unsigned int mask, bool store_p, bool adjust_stack_p)
983 rtx body, addr, src, operands[2];
984 enum machine_mode mode;
986 body = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (adjust_stack_p + count));
987 mode = reg_raw_mode[regno];
992 src = plus_constant (base, (count
993 * GET_MODE_SIZE (mode)
994 * (HOST_WIDE_INT) (store_p ? -1 : 1)));
995 XVECEXP (body, 0, i++) = gen_rtx_SET (VOIDmode, base, src);
998 for (; mask != 0; mask >>= 1, regno++)
1001 addr = plus_constant (base, offset);
1002 operands[!store_p] = gen_frame_mem (mode, addr);
1003 operands[store_p] = gen_rtx_REG (mode, regno);
1004 XVECEXP (body, 0, i++)
1005 = gen_rtx_SET (VOIDmode, operands[0], operands[1]);
1006 offset += GET_MODE_SIZE (mode);
1008 gcc_assert (i == XVECLEN (body, 0));
1010 return emit_insn (body);
1013 /* Make INSN a frame-related instruction. */
1016 m68k_set_frame_related (rtx insn)
1021 RTX_FRAME_RELATED_P (insn) = 1;
1022 body = PATTERN (insn);
1023 if (GET_CODE (body) == PARALLEL)
1024 for (i = 0; i < XVECLEN (body, 0); i++)
1025 RTX_FRAME_RELATED_P (XVECEXP (body, 0, i)) = 1;
1028 /* Emit RTL for the "prologue" define_expand. */
1031 m68k_expand_prologue (void)
1033 HOST_WIDE_INT fsize_with_regs;
1034 rtx limit, src, dest, insn;
1036 m68k_compute_frame_layout ();
1038 /* If the stack limit is a symbol, we can check it here,
1039 before actually allocating the space. */
1040 if (crtl->limit_stack
1041 && GET_CODE (stack_limit_rtx) == SYMBOL_REF)
1043 limit = plus_constant (stack_limit_rtx, current_frame.size + 4);
1044 if (!LEGITIMATE_CONSTANT_P (limit))
1046 emit_move_insn (gen_rtx_REG (Pmode, D0_REG), limit);
1047 limit = gen_rtx_REG (Pmode, D0_REG);
1049 emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode,
1050 stack_pointer_rtx, limit),
1051 stack_pointer_rtx, limit,
1055 fsize_with_regs = current_frame.size;
1056 if (TARGET_COLDFIRE)
1058 /* ColdFire's move multiple instructions do not allow pre-decrement
1059 addressing. Add the size of movem saves to the initial stack
1060 allocation instead. */
1061 if (current_frame.reg_no >= MIN_MOVEM_REGS)
1062 fsize_with_regs += current_frame.reg_no * GET_MODE_SIZE (SImode);
1063 if (current_frame.fpu_no >= MIN_FMOVEM_REGS)
1064 fsize_with_regs += current_frame.fpu_no * GET_MODE_SIZE (DFmode);
1067 if (frame_pointer_needed)
1069 if (fsize_with_regs == 0 && TUNE_68040)
1071 /* On the 68040, two separate moves are faster than link.w 0. */
1072 dest = gen_frame_mem (Pmode,
1073 gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
1074 m68k_set_frame_related (emit_move_insn (dest, frame_pointer_rtx));
1075 m68k_set_frame_related (emit_move_insn (frame_pointer_rtx,
1076 stack_pointer_rtx));
1078 else if (fsize_with_regs < 0x8000 || TARGET_68020)
1079 m68k_set_frame_related
1080 (emit_insn (gen_link (frame_pointer_rtx,
1081 GEN_INT (-4 - fsize_with_regs))));
1084 m68k_set_frame_related
1085 (emit_insn (gen_link (frame_pointer_rtx, GEN_INT (-4))));
1086 m68k_set_frame_related
1087 (emit_insn (gen_addsi3 (stack_pointer_rtx,
1089 GEN_INT (-fsize_with_regs))));
1092 /* If the frame pointer is needed, emit a special barrier that
1093 will prevent the scheduler from moving stores to the frame
1094 before the stack adjustment. */
1095 emit_insn (gen_stack_tie (stack_pointer_rtx, frame_pointer_rtx));
1097 else if (fsize_with_regs != 0)
1098 m68k_set_frame_related
1099 (emit_insn (gen_addsi3 (stack_pointer_rtx,
1101 GEN_INT (-fsize_with_regs))));
1103 if (current_frame.fpu_mask)
1105 gcc_assert (current_frame.fpu_no >= MIN_FMOVEM_REGS);
1107 m68k_set_frame_related
1108 (m68k_emit_movem (stack_pointer_rtx,
1109 current_frame.fpu_no * -GET_MODE_SIZE (XFmode),
1110 current_frame.fpu_no, FP0_REG,
1111 current_frame.fpu_mask, true, true));
1116 /* If we're using moveml to save the integer registers,
1117 the stack pointer will point to the bottom of the moveml
1118 save area. Find the stack offset of the first FP register. */
1119 if (current_frame.reg_no < MIN_MOVEM_REGS)
1122 offset = current_frame.reg_no * GET_MODE_SIZE (SImode);
1123 m68k_set_frame_related
1124 (m68k_emit_movem (stack_pointer_rtx, offset,
1125 current_frame.fpu_no, FP0_REG,
1126 current_frame.fpu_mask, true, false));
1130 /* If the stack limit is not a symbol, check it here.
1131 This has the disadvantage that it may be too late... */
1132 if (crtl->limit_stack)
1134 if (REG_P (stack_limit_rtx))
1135 emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode, stack_pointer_rtx,
1137 stack_pointer_rtx, stack_limit_rtx,
1140 else if (GET_CODE (stack_limit_rtx) != SYMBOL_REF)
1141 warning (0, "stack limit expression is not supported");
1144 if (current_frame.reg_no < MIN_MOVEM_REGS)
1146 /* Store each register separately in the same order moveml does. */
1149 for (i = 16; i-- > 0; )
1150 if (current_frame.reg_mask & (1 << i))
1152 src = gen_rtx_REG (SImode, D0_REG + i);
1153 dest = gen_frame_mem (SImode,
1154 gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx));
1155 m68k_set_frame_related (emit_insn (gen_movsi (dest, src)));
1160 if (TARGET_COLDFIRE)
1161 /* The required register save space has already been allocated.
1162 The first register should be stored at (%sp). */
1163 m68k_set_frame_related
1164 (m68k_emit_movem (stack_pointer_rtx, 0,
1165 current_frame.reg_no, D0_REG,
1166 current_frame.reg_mask, true, false));
1168 m68k_set_frame_related
1169 (m68k_emit_movem (stack_pointer_rtx,
1170 current_frame.reg_no * -GET_MODE_SIZE (SImode),
1171 current_frame.reg_no, D0_REG,
1172 current_frame.reg_mask, true, true));
1175 if (!TARGET_SEP_DATA
1176 && crtl->uses_pic_offset_table)
1177 insn = emit_insn (gen_load_got (pic_offset_table_rtx));
1180 /* Return true if a simple (return) instruction is sufficient for this
1181 instruction (i.e. if no epilogue is needed). */
1184 m68k_use_return_insn (void)
1186 if (!reload_completed || frame_pointer_needed || get_frame_size () != 0)
1189 m68k_compute_frame_layout ();
1190 return current_frame.offset == 0;
1193 /* Emit RTL for the "epilogue" or "sibcall_epilogue" define_expand;
1194 SIBCALL_P says which.
1196 The function epilogue should not depend on the current stack pointer!
1197 It should use the frame pointer only, if there is a frame pointer.
1198 This is mandatory because of alloca; we also take advantage of it to
1199 omit stack adjustments before returning. */
1202 m68k_expand_epilogue (bool sibcall_p)
1204 HOST_WIDE_INT fsize, fsize_with_regs;
1205 bool big, restore_from_sp;
1207 m68k_compute_frame_layout ();
1209 fsize = current_frame.size;
1211 restore_from_sp = false;
1213 /* FIXME : current_function_is_leaf below is too strong.
1214 What we really need to know there is if there could be pending
1215 stack adjustment needed at that point. */
1216 restore_from_sp = (!frame_pointer_needed
1217 || (!cfun->calls_alloca
1218 && current_function_is_leaf));
1220 /* fsize_with_regs is the size we need to adjust the sp when
1221 popping the frame. */
1222 fsize_with_regs = fsize;
1223 if (TARGET_COLDFIRE && restore_from_sp)
1225 /* ColdFire's move multiple instructions do not allow post-increment
1226 addressing. Add the size of movem loads to the final deallocation
1228 if (current_frame.reg_no >= MIN_MOVEM_REGS)
1229 fsize_with_regs += current_frame.reg_no * GET_MODE_SIZE (SImode);
1230 if (current_frame.fpu_no >= MIN_FMOVEM_REGS)
1231 fsize_with_regs += current_frame.fpu_no * GET_MODE_SIZE (DFmode);
1234 if (current_frame.offset + fsize >= 0x8000
1236 && (current_frame.reg_mask || current_frame.fpu_mask))
1239 && (current_frame.reg_no >= MIN_MOVEM_REGS
1240 || current_frame.fpu_no >= MIN_FMOVEM_REGS))
1242 /* ColdFire's move multiple instructions do not support the
1243 (d8,Ax,Xi) addressing mode, so we're as well using a normal
1244 stack-based restore. */
1245 emit_move_insn (gen_rtx_REG (Pmode, A1_REG),
1246 GEN_INT (-(current_frame.offset + fsize)));
1247 emit_insn (gen_addsi3 (stack_pointer_rtx,
1248 gen_rtx_REG (Pmode, A1_REG),
1249 frame_pointer_rtx));
1250 restore_from_sp = true;
1254 emit_move_insn (gen_rtx_REG (Pmode, A1_REG), GEN_INT (-fsize));
1260 if (current_frame.reg_no < MIN_MOVEM_REGS)
1262 /* Restore each register separately in the same order moveml does. */
1264 HOST_WIDE_INT offset;
1266 offset = current_frame.offset + fsize;
1267 for (i = 0; i < 16; i++)
1268 if (current_frame.reg_mask & (1 << i))
1274 /* Generate the address -OFFSET(%fp,%a1.l). */
1275 addr = gen_rtx_REG (Pmode, A1_REG);
1276 addr = gen_rtx_PLUS (Pmode, addr, frame_pointer_rtx);
1277 addr = plus_constant (addr, -offset);
1279 else if (restore_from_sp)
1280 addr = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
1282 addr = plus_constant (frame_pointer_rtx, -offset);
1283 emit_move_insn (gen_rtx_REG (SImode, D0_REG + i),
1284 gen_frame_mem (SImode, addr));
1285 offset -= GET_MODE_SIZE (SImode);
1288 else if (current_frame.reg_mask)
1291 m68k_emit_movem (gen_rtx_PLUS (Pmode,
1292 gen_rtx_REG (Pmode, A1_REG),
1294 -(current_frame.offset + fsize),
1295 current_frame.reg_no, D0_REG,
1296 current_frame.reg_mask, false, false);
1297 else if (restore_from_sp)
1298 m68k_emit_movem (stack_pointer_rtx, 0,
1299 current_frame.reg_no, D0_REG,
1300 current_frame.reg_mask, false,
1303 m68k_emit_movem (frame_pointer_rtx,
1304 -(current_frame.offset + fsize),
1305 current_frame.reg_no, D0_REG,
1306 current_frame.reg_mask, false, false);
1309 if (current_frame.fpu_no > 0)
1312 m68k_emit_movem (gen_rtx_PLUS (Pmode,
1313 gen_rtx_REG (Pmode, A1_REG),
1315 -(current_frame.foffset + fsize),
1316 current_frame.fpu_no, FP0_REG,
1317 current_frame.fpu_mask, false, false);
1318 else if (restore_from_sp)
1320 if (TARGET_COLDFIRE)
1324 /* If we used moveml to restore the integer registers, the
1325 stack pointer will still point to the bottom of the moveml
1326 save area. Find the stack offset of the first FP
1328 if (current_frame.reg_no < MIN_MOVEM_REGS)
1331 offset = current_frame.reg_no * GET_MODE_SIZE (SImode);
1332 m68k_emit_movem (stack_pointer_rtx, offset,
1333 current_frame.fpu_no, FP0_REG,
1334 current_frame.fpu_mask, false, false);
1337 m68k_emit_movem (stack_pointer_rtx, 0,
1338 current_frame.fpu_no, FP0_REG,
1339 current_frame.fpu_mask, false, true);
1342 m68k_emit_movem (frame_pointer_rtx,
1343 -(current_frame.foffset + fsize),
1344 current_frame.fpu_no, FP0_REG,
1345 current_frame.fpu_mask, false, false);
1348 if (frame_pointer_needed)
1349 emit_insn (gen_unlink (frame_pointer_rtx));
1350 else if (fsize_with_regs)
1351 emit_insn (gen_addsi3 (stack_pointer_rtx,
1353 GEN_INT (fsize_with_regs)));
1355 if (crtl->calls_eh_return)
1356 emit_insn (gen_addsi3 (stack_pointer_rtx,
1358 EH_RETURN_STACKADJ_RTX));
1361 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
1364 /* Return true if X is a valid comparison operator for the dbcc
1367 Note it rejects floating point comparison operators.
1368 (In the future we could use Fdbcc).
1370 It also rejects some comparisons when CC_NO_OVERFLOW is set. */
1373 valid_dbcc_comparison_p_2 (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1375 switch (GET_CODE (x))
1377 case EQ: case NE: case GTU: case LTU:
1381 /* Reject some when CC_NO_OVERFLOW is set. This may be over
1383 case GT: case LT: case GE: case LE:
1384 return ! (cc_prev_status.flags & CC_NO_OVERFLOW);
1390 /* Return nonzero if flags are currently in the 68881 flag register. */
1392 flags_in_68881 (void)
1394 /* We could add support for these in the future */
1395 return cc_status.flags & CC_IN_68881;
1398 /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL_P. */
1401 m68k_ok_for_sibcall_p (tree decl, tree exp)
1403 enum m68k_function_kind kind;
1405 /* We cannot use sibcalls for nested functions because we use the
1406 static chain register for indirect calls. */
1407 if (CALL_EXPR_STATIC_CHAIN (exp))
1410 kind = m68k_get_function_kind (current_function_decl);
1411 if (kind == m68k_fk_normal_function)
1412 /* We can always sibcall from a normal function, because it's
1413 undefined if it is calling an interrupt function. */
1416 /* Otherwise we can only sibcall if the function kind is known to be
1418 if (decl && m68k_get_function_kind (decl) == kind)
1424 /* Convert X to a legitimate function call memory reference and return the
1428 m68k_legitimize_call_address (rtx x)
1430 gcc_assert (MEM_P (x));
1431 if (call_operand (XEXP (x, 0), VOIDmode))
1433 return replace_equiv_address (x, force_reg (Pmode, XEXP (x, 0)));
1436 /* Likewise for sibling calls. */
1439 m68k_legitimize_sibcall_address (rtx x)
1441 gcc_assert (MEM_P (x));
1442 if (sibcall_operand (XEXP (x, 0), VOIDmode))
1445 emit_move_insn (gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM), XEXP (x, 0));
1446 return replace_equiv_address (x, gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM));
1449 /* Convert X to a legitimate address and return it if successful. Otherwise
1452 For the 68000, we handle X+REG by loading X into a register R and
1453 using R+REG. R will go in an address reg and indexing will be used.
1454 However, if REG is a broken-out memory address or multiplication,
1455 nothing needs to be done because REG can certainly go in an address reg. */
1458 m68k_legitimize_address (rtx x, rtx oldx, enum machine_mode mode)
1460 if (m68k_tls_symbol_p (x))
1461 return m68k_legitimize_tls_address (x);
1463 if (GET_CODE (x) == PLUS)
1465 int ch = (x) != (oldx);
1468 #define COPY_ONCE(Y) if (!copied) { Y = copy_rtx (Y); copied = ch = 1; }
1470 if (GET_CODE (XEXP (x, 0)) == MULT)
1473 XEXP (x, 0) = force_operand (XEXP (x, 0), 0);
1475 if (GET_CODE (XEXP (x, 1)) == MULT)
1478 XEXP (x, 1) = force_operand (XEXP (x, 1), 0);
1482 if (GET_CODE (XEXP (x, 1)) == REG
1483 && GET_CODE (XEXP (x, 0)) == REG)
1485 if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT)
1488 x = force_operand (x, 0);
1492 if (memory_address_p (mode, x))
1495 if (GET_CODE (XEXP (x, 0)) == REG
1496 || (GET_CODE (XEXP (x, 0)) == SIGN_EXTEND
1497 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
1498 && GET_MODE (XEXP (XEXP (x, 0), 0)) == HImode))
1500 rtx temp = gen_reg_rtx (Pmode);
1501 rtx val = force_operand (XEXP (x, 1), 0);
1502 emit_move_insn (temp, val);
1505 if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT
1506 && GET_CODE (XEXP (x, 0)) == REG)
1507 x = force_operand (x, 0);
1509 else if (GET_CODE (XEXP (x, 1)) == REG
1510 || (GET_CODE (XEXP (x, 1)) == SIGN_EXTEND
1511 && GET_CODE (XEXP (XEXP (x, 1), 0)) == REG
1512 && GET_MODE (XEXP (XEXP (x, 1), 0)) == HImode))
1514 rtx temp = gen_reg_rtx (Pmode);
1515 rtx val = force_operand (XEXP (x, 0), 0);
1516 emit_move_insn (temp, val);
1519 if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT
1520 && GET_CODE (XEXP (x, 1)) == REG)
1521 x = force_operand (x, 0);
1529 /* Output a dbCC; jCC sequence. Note we do not handle the
1530 floating point version of this sequence (Fdbcc). We also
1531 do not handle alternative conditions when CC_NO_OVERFLOW is
1532 set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will
1533 kick those out before we get here. */
1536 output_dbcc_and_branch (rtx *operands)
1538 switch (GET_CODE (operands[3]))
1541 output_asm_insn ("dbeq %0,%l1\n\tjeq %l2", operands);
1545 output_asm_insn ("dbne %0,%l1\n\tjne %l2", operands);
1549 output_asm_insn ("dbgt %0,%l1\n\tjgt %l2", operands);
1553 output_asm_insn ("dbhi %0,%l1\n\tjhi %l2", operands);
1557 output_asm_insn ("dblt %0,%l1\n\tjlt %l2", operands);
1561 output_asm_insn ("dbcs %0,%l1\n\tjcs %l2", operands);
1565 output_asm_insn ("dbge %0,%l1\n\tjge %l2", operands);
1569 output_asm_insn ("dbcc %0,%l1\n\tjcc %l2", operands);
1573 output_asm_insn ("dble %0,%l1\n\tjle %l2", operands);
1577 output_asm_insn ("dbls %0,%l1\n\tjls %l2", operands);
1584 /* If the decrement is to be done in SImode, then we have
1585 to compensate for the fact that dbcc decrements in HImode. */
1586 switch (GET_MODE (operands[0]))
1589 output_asm_insn ("clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1", operands);
1601 output_scc_di (rtx op, rtx operand1, rtx operand2, rtx dest)
1604 enum rtx_code op_code = GET_CODE (op);
1606 /* This does not produce a useful cc. */
1609 /* The m68k cmp.l instruction requires operand1 to be a reg as used
1610 below. Swap the operands and change the op if these requirements
1611 are not fulfilled. */
1612 if (GET_CODE (operand2) == REG && GET_CODE (operand1) != REG)
1616 operand1 = operand2;
1618 op_code = swap_condition (op_code);
1620 loperands[0] = operand1;
1621 if (GET_CODE (operand1) == REG)
1622 loperands[1] = gen_rtx_REG (SImode, REGNO (operand1) + 1);
1624 loperands[1] = adjust_address (operand1, SImode, 4);
1625 if (operand2 != const0_rtx)
1627 loperands[2] = operand2;
1628 if (GET_CODE (operand2) == REG)
1629 loperands[3] = gen_rtx_REG (SImode, REGNO (operand2) + 1);
1631 loperands[3] = adjust_address (operand2, SImode, 4);
1633 loperands[4] = gen_label_rtx ();
1634 if (operand2 != const0_rtx)
1635 output_asm_insn ("cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1", loperands);
1638 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[0]))
1639 output_asm_insn ("tst%.l %0", loperands);
1641 output_asm_insn ("cmp%.w #0,%0", loperands);
1643 output_asm_insn ("jne %l4", loperands);
1645 if (TARGET_68020 || TARGET_COLDFIRE || ! ADDRESS_REG_P (loperands[1]))
1646 output_asm_insn ("tst%.l %1", loperands);
1648 output_asm_insn ("cmp%.w #0,%1", loperands);
1651 loperands[5] = dest;
1656 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1657 CODE_LABEL_NUMBER (loperands[4]));
1658 output_asm_insn ("seq %5", loperands);
1662 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1663 CODE_LABEL_NUMBER (loperands[4]));
1664 output_asm_insn ("sne %5", loperands);
1668 loperands[6] = gen_label_rtx ();
1669 output_asm_insn ("shi %5\n\tjra %l6", loperands);
1670 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1671 CODE_LABEL_NUMBER (loperands[4]));
1672 output_asm_insn ("sgt %5", loperands);
1673 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1674 CODE_LABEL_NUMBER (loperands[6]));
1678 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1679 CODE_LABEL_NUMBER (loperands[4]));
1680 output_asm_insn ("shi %5", loperands);
1684 loperands[6] = gen_label_rtx ();
1685 output_asm_insn ("scs %5\n\tjra %l6", loperands);
1686 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1687 CODE_LABEL_NUMBER (loperands[4]));
1688 output_asm_insn ("slt %5", loperands);
1689 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1690 CODE_LABEL_NUMBER (loperands[6]));
1694 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1695 CODE_LABEL_NUMBER (loperands[4]));
1696 output_asm_insn ("scs %5", loperands);
1700 loperands[6] = gen_label_rtx ();
1701 output_asm_insn ("scc %5\n\tjra %l6", loperands);
1702 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1703 CODE_LABEL_NUMBER (loperands[4]));
1704 output_asm_insn ("sge %5", loperands);
1705 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1706 CODE_LABEL_NUMBER (loperands[6]));
1710 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1711 CODE_LABEL_NUMBER (loperands[4]));
1712 output_asm_insn ("scc %5", loperands);
1716 loperands[6] = gen_label_rtx ();
1717 output_asm_insn ("sls %5\n\tjra %l6", loperands);
1718 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1719 CODE_LABEL_NUMBER (loperands[4]));
1720 output_asm_insn ("sle %5", loperands);
1721 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1722 CODE_LABEL_NUMBER (loperands[6]));
1726 (*targetm.asm_out.internal_label) (asm_out_file, "L",
1727 CODE_LABEL_NUMBER (loperands[4]));
1728 output_asm_insn ("sls %5", loperands);
1738 output_btst (rtx *operands, rtx countop, rtx dataop, rtx insn, int signpos)
1740 operands[0] = countop;
1741 operands[1] = dataop;
1743 if (GET_CODE (countop) == CONST_INT)
1745 register int count = INTVAL (countop);
1746 /* If COUNT is bigger than size of storage unit in use,
1747 advance to the containing unit of same size. */
1748 if (count > signpos)
1750 int offset = (count & ~signpos) / 8;
1751 count = count & signpos;
1752 operands[1] = dataop = adjust_address (dataop, QImode, offset);
1754 if (count == signpos)
1755 cc_status.flags = CC_NOT_POSITIVE | CC_Z_IN_NOT_N;
1757 cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N;
1759 /* These three statements used to use next_insns_test_no...
1760 but it appears that this should do the same job. */
1762 && next_insn_tests_no_inequality (insn))
1765 && next_insn_tests_no_inequality (insn))
1768 && next_insn_tests_no_inequality (insn))
1770 /* Try to use `movew to ccr' followed by the appropriate branch insn.
1771 On some m68k variants unfortunately that's slower than btst.
1772 On 68000 and higher, that should also work for all HImode operands. */
1773 if (TUNE_CPU32 || TARGET_COLDFIRE || optimize_size)
1775 if (count == 3 && DATA_REG_P (operands[1])
1776 && next_insn_tests_no_inequality (insn))
1778 cc_status.flags = CC_NOT_NEGATIVE | CC_Z_IN_NOT_N | CC_NO_OVERFLOW;
1779 return "move%.w %1,%%ccr";
1781 if (count == 2 && DATA_REG_P (operands[1])
1782 && next_insn_tests_no_inequality (insn))
1784 cc_status.flags = CC_NOT_NEGATIVE | CC_INVERTED | CC_NO_OVERFLOW;
1785 return "move%.w %1,%%ccr";
1787 /* count == 1 followed by bvc/bvs and
1788 count == 0 followed by bcc/bcs are also possible, but need
1789 m68k-specific CC_Z_IN_NOT_V and CC_Z_IN_NOT_C flags. */
1792 cc_status.flags = CC_NOT_NEGATIVE;
1794 return "btst %0,%1";
1797 /* Return true if X is a legitimate base register. STRICT_P says
1798 whether we need strict checking. */
1801 m68k_legitimate_base_reg_p (rtx x, bool strict_p)
1803 /* Allow SUBREG everywhere we allow REG. This results in better code. */
1804 if (!strict_p && GET_CODE (x) == SUBREG)
1809 ? REGNO_OK_FOR_BASE_P (REGNO (x))
1810 : REGNO_OK_FOR_BASE_NONSTRICT_P (REGNO (x))));
1813 /* Return true if X is a legitimate index register. STRICT_P says
1814 whether we need strict checking. */
1817 m68k_legitimate_index_reg_p (rtx x, bool strict_p)
1819 if (!strict_p && GET_CODE (x) == SUBREG)
1824 ? REGNO_OK_FOR_INDEX_P (REGNO (x))
1825 : REGNO_OK_FOR_INDEX_NONSTRICT_P (REGNO (x))));
1828 /* Return true if X is a legitimate index expression for a (d8,An,Xn) or
1829 (bd,An,Xn) addressing mode. Fill in the INDEX and SCALE fields of
1830 ADDRESS if so. STRICT_P says whether we need strict checking. */
1833 m68k_decompose_index (rtx x, bool strict_p, struct m68k_address *address)
1837 /* Check for a scale factor. */
1839 if ((TARGET_68020 || TARGET_COLDFIRE)
1840 && GET_CODE (x) == MULT
1841 && GET_CODE (XEXP (x, 1)) == CONST_INT
1842 && (INTVAL (XEXP (x, 1)) == 2
1843 || INTVAL (XEXP (x, 1)) == 4
1844 || (INTVAL (XEXP (x, 1)) == 8
1845 && (TARGET_COLDFIRE_FPU || !TARGET_COLDFIRE))))
1847 scale = INTVAL (XEXP (x, 1));
1851 /* Check for a word extension. */
1852 if (!TARGET_COLDFIRE
1853 && GET_CODE (x) == SIGN_EXTEND
1854 && GET_MODE (XEXP (x, 0)) == HImode)
1857 if (m68k_legitimate_index_reg_p (x, strict_p))
1859 address->scale = scale;
1867 /* Return true if X is an illegitimate symbolic constant. */
1870 m68k_illegitimate_symbolic_constant_p (rtx x)
1874 if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
1876 split_const (x, &base, &offset);
1877 if (GET_CODE (base) == SYMBOL_REF
1878 && !offset_within_block_p (base, INTVAL (offset)))
1881 return m68k_tls_reference_p (x, false);
1884 /* Return true if X is a legitimate constant address that can reach
1885 bytes in the range [X, X + REACH). STRICT_P says whether we need
1889 m68k_legitimate_constant_address_p (rtx x, unsigned int reach, bool strict_p)
1893 if (!CONSTANT_ADDRESS_P (x))
1897 && !(strict_p && TARGET_PCREL)
1898 && symbolic_operand (x, VOIDmode))
1901 if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P && reach > 1)
1903 split_const (x, &base, &offset);
1904 if (GET_CODE (base) == SYMBOL_REF
1905 && !offset_within_block_p (base, INTVAL (offset) + reach - 1))
1909 return !m68k_tls_reference_p (x, false);
1912 /* Return true if X is a LABEL_REF for a jump table. Assume that unplaced
1913 labels will become jump tables. */
1916 m68k_jump_table_ref_p (rtx x)
1918 if (GET_CODE (x) != LABEL_REF)
1922 if (!NEXT_INSN (x) && !PREV_INSN (x))
1925 x = next_nonnote_insn (x);
1926 return x && JUMP_TABLE_DATA_P (x);
1929 /* Return true if X is a legitimate address for values of mode MODE.
1930 STRICT_P says whether strict checking is needed. If the address
1931 is valid, describe its components in *ADDRESS. */
1934 m68k_decompose_address (enum machine_mode mode, rtx x,
1935 bool strict_p, struct m68k_address *address)
1939 memset (address, 0, sizeof (*address));
1941 if (mode == BLKmode)
1944 reach = GET_MODE_SIZE (mode);
1946 /* Check for (An) (mode 2). */
1947 if (m68k_legitimate_base_reg_p (x, strict_p))
1953 /* Check for -(An) and (An)+ (modes 3 and 4). */
1954 if ((GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_INC)
1955 && m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p))
1957 address->code = GET_CODE (x);
1958 address->base = XEXP (x, 0);
1962 /* Check for (d16,An) (mode 5). */
1963 if (GET_CODE (x) == PLUS
1964 && GET_CODE (XEXP (x, 1)) == CONST_INT
1965 && IN_RANGE (INTVAL (XEXP (x, 1)), -0x8000, 0x8000 - reach)
1966 && m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p))
1968 address->base = XEXP (x, 0);
1969 address->offset = XEXP (x, 1);
1973 /* Check for GOT loads. These are (bd,An,Xn) addresses if
1974 TARGET_68020 && flag_pic == 2, otherwise they are (d16,An)
1976 if (GET_CODE (x) == PLUS
1977 && XEXP (x, 0) == pic_offset_table_rtx)
1979 /* As we are processing a PLUS, do not unwrap RELOC32 symbols --
1980 they are invalid in this context. */
1981 if (m68k_unwrap_symbol (XEXP (x, 1), false) != XEXP (x, 1))
1983 address->base = XEXP (x, 0);
1984 address->offset = XEXP (x, 1);
1989 /* The ColdFire FPU only accepts addressing modes 2-5. */
1990 if (TARGET_COLDFIRE_FPU && GET_MODE_CLASS (mode) == MODE_FLOAT)
1993 /* Check for (xxx).w and (xxx).l. Also, in the TARGET_PCREL case,
1994 check for (d16,PC) or (bd,PC,Xn) with a suppressed index register.
1995 All these modes are variations of mode 7. */
1996 if (m68k_legitimate_constant_address_p (x, reach, strict_p))
1998 address->offset = x;
2002 /* Check for (d8,PC,Xn), a mode 7 form. This case is needed for
2005 ??? do_tablejump creates these addresses before placing the target
2006 label, so we have to assume that unplaced labels are jump table
2007 references. It seems unlikely that we would ever generate indexed
2008 accesses to unplaced labels in other cases. */
2009 if (GET_CODE (x) == PLUS
2010 && m68k_jump_table_ref_p (XEXP (x, 1))
2011 && m68k_decompose_index (XEXP (x, 0), strict_p, address))
2013 address->offset = XEXP (x, 1);
2017 /* Everything hereafter deals with (d8,An,Xn.SIZE*SCALE) or
2018 (bd,An,Xn.SIZE*SCALE) addresses. */
2022 /* Check for a nonzero base displacement. */
2023 if (GET_CODE (x) == PLUS
2024 && m68k_legitimate_constant_address_p (XEXP (x, 1), reach, strict_p))
2026 address->offset = XEXP (x, 1);
2030 /* Check for a suppressed index register. */
2031 if (m68k_legitimate_base_reg_p (x, strict_p))
2037 /* Check for a suppressed base register. Do not allow this case
2038 for non-symbolic offsets as it effectively gives gcc freedom
2039 to treat data registers as base registers, which can generate
2042 && symbolic_operand (address->offset, VOIDmode)
2043 && m68k_decompose_index (x, strict_p, address))
2048 /* Check for a nonzero base displacement. */
2049 if (GET_CODE (x) == PLUS
2050 && GET_CODE (XEXP (x, 1)) == CONST_INT
2051 && IN_RANGE (INTVAL (XEXP (x, 1)), -0x80, 0x80 - reach))
2053 address->offset = XEXP (x, 1);
2058 /* We now expect the sum of a base and an index. */
2059 if (GET_CODE (x) == PLUS)
2061 if (m68k_legitimate_base_reg_p (XEXP (x, 0), strict_p)
2062 && m68k_decompose_index (XEXP (x, 1), strict_p, address))
2064 address->base = XEXP (x, 0);
2068 if (m68k_legitimate_base_reg_p (XEXP (x, 1), strict_p)
2069 && m68k_decompose_index (XEXP (x, 0), strict_p, address))
2071 address->base = XEXP (x, 1);
2078 /* Return true if X is a legitimate address for values of mode MODE.
2079 STRICT_P says whether strict checking is needed. */
2082 m68k_legitimate_address_p (enum machine_mode mode, rtx x, bool strict_p)
2084 struct m68k_address address;
2086 return m68k_decompose_address (mode, x, strict_p, &address);
2089 /* Return true if X is a memory, describing its address in ADDRESS if so.
2090 Apply strict checking if called during or after reload. */
2093 m68k_legitimate_mem_p (rtx x, struct m68k_address *address)
2096 && m68k_decompose_address (GET_MODE (x), XEXP (x, 0),
2097 reload_in_progress || reload_completed,
2101 /* Return true if X matches the 'Q' constraint. It must be a memory
2102 with a base address and no constant offset or index. */
2105 m68k_matches_q_p (rtx x)
2107 struct m68k_address address;
2109 return (m68k_legitimate_mem_p (x, &address)
2110 && address.code == UNKNOWN
2116 /* Return true if X matches the 'U' constraint. It must be a base address
2117 with a constant offset and no index. */
2120 m68k_matches_u_p (rtx x)
2122 struct m68k_address address;
2124 return (m68k_legitimate_mem_p (x, &address)
2125 && address.code == UNKNOWN
2131 /* Return GOT pointer. */
2136 if (pic_offset_table_rtx == NULL_RTX)
2137 pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_REG);
2139 crtl->uses_pic_offset_table = 1;
2141 return pic_offset_table_rtx;
2144 /* M68K relocations, used to distinguish GOT and TLS relocations in UNSPEC
2146 enum m68k_reloc { RELOC_GOT, RELOC_TLSGD, RELOC_TLSLDM, RELOC_TLSLDO,
2147 RELOC_TLSIE, RELOC_TLSLE };
2149 #define TLS_RELOC_P(RELOC) ((RELOC) != RELOC_GOT)
2151 /* Wrap symbol X into unspec representing relocation RELOC.
2152 BASE_REG - register that should be added to the result.
2153 TEMP_REG - if non-null, temporary register. */
2156 m68k_wrap_symbol (rtx x, enum m68k_reloc reloc, rtx base_reg, rtx temp_reg)
2160 use_x_p = (base_reg == pic_offset_table_rtx) ? TARGET_XGOT : TARGET_XTLS;
2162 if (TARGET_COLDFIRE && use_x_p)
2163 /* When compiling with -mx{got, tls} switch the code will look like this:
2165 move.l <X>@<RELOC>,<TEMP_REG>
2166 add.l <BASE_REG>,<TEMP_REG> */
2168 /* Wrap X in UNSPEC_??? to tip m68k_output_addr_const_extra
2169 to put @RELOC after reference. */
2170 x = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)),
2172 x = gen_rtx_CONST (Pmode, x);
2174 if (temp_reg == NULL)
2176 gcc_assert (can_create_pseudo_p ());
2177 temp_reg = gen_reg_rtx (Pmode);
2180 emit_move_insn (temp_reg, x);
2181 emit_insn (gen_addsi3 (temp_reg, temp_reg, base_reg));
2186 x = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, x, GEN_INT (reloc)),
2188 x = gen_rtx_CONST (Pmode, x);
2190 x = gen_rtx_PLUS (Pmode, base_reg, x);
2196 /* Helper for m68k_unwrap_symbol.
2197 Also, if unwrapping was successful (that is if (ORIG != <return value>)),
2198 sets *RELOC_PTR to relocation type for the symbol. */
2201 m68k_unwrap_symbol_1 (rtx orig, bool unwrap_reloc32_p,
2202 enum m68k_reloc *reloc_ptr)
2204 if (GET_CODE (orig) == CONST)
2207 enum m68k_reloc dummy;
2211 if (reloc_ptr == NULL)
2214 /* Handle an addend. */
2215 if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS)
2216 && CONST_INT_P (XEXP (x, 1)))
2219 if (GET_CODE (x) == UNSPEC)
2221 switch (XINT (x, 1))
2223 case UNSPEC_RELOC16:
2224 orig = XVECEXP (x, 0, 0);
2225 *reloc_ptr = (enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1));
2228 case UNSPEC_RELOC32:
2229 if (unwrap_reloc32_p)
2231 orig = XVECEXP (x, 0, 0);
2232 *reloc_ptr = (enum m68k_reloc) INTVAL (XVECEXP (x, 0, 1));
2245 /* Unwrap symbol from UNSPEC_RELOC16 and, if unwrap_reloc32_p,
2246 UNSPEC_RELOC32 wrappers. */
2249 m68k_unwrap_symbol (rtx orig, bool unwrap_reloc32_p)
2251 return m68k_unwrap_symbol_1 (orig, unwrap_reloc32_p, NULL);
2254 /* Helper for m68k_final_prescan_insn. */
2257 m68k_final_prescan_insn_1 (rtx *x_ptr, void *data ATTRIBUTE_UNUSED)
2261 if (m68k_unwrap_symbol (x, true) != x)
2262 /* For rationale of the below, see comment in m68k_final_prescan_insn. */
2266 gcc_assert (GET_CODE (x) == CONST);
2269 if (GET_CODE (plus) == PLUS || GET_CODE (plus) == MINUS)
2274 unspec = XEXP (plus, 0);
2275 gcc_assert (GET_CODE (unspec) == UNSPEC);
2276 addend = XEXP (plus, 1);
2277 gcc_assert (CONST_INT_P (addend));
2279 /* We now have all the pieces, rearrange them. */
2281 /* Move symbol to plus. */
2282 XEXP (plus, 0) = XVECEXP (unspec, 0, 0);
2284 /* Move plus inside unspec. */
2285 XVECEXP (unspec, 0, 0) = plus;
2287 /* Move unspec to top level of const. */
2288 XEXP (x, 0) = unspec;
2297 /* Prescan insn before outputing assembler for it. */
2300 m68k_final_prescan_insn (rtx insn ATTRIBUTE_UNUSED,
2301 rtx *operands, int n_operands)
2305 /* Combine and, possibly, other optimizations may do good job
2307 (const (unspec [(symbol)]))
2309 (const (plus (unspec [(symbol)])
2311 The problem with this is emitting @TLS or @GOT decorations.
2312 The decoration is emitted when processing (unspec), so the
2313 result would be "#symbol@TLSLE+N" instead of "#symbol+N@TLSLE".
2315 It seems that the easiest solution to this is to convert such
2317 (const (unspec [(plus (symbol)
2319 Note, that the top level of operand remains intact, so we don't have
2320 to patch up anything outside of the operand. */
2322 for (i = 0; i < n_operands; ++i)
2328 for_each_rtx (&op, m68k_final_prescan_insn_1, NULL);
2332 /* Move X to a register and add REG_EQUAL note pointing to ORIG.
2333 If REG is non-null, use it; generate new pseudo otherwise. */
2336 m68k_move_to_reg (rtx x, rtx orig, rtx reg)
2340 if (reg == NULL_RTX)
2342 gcc_assert (can_create_pseudo_p ());
2343 reg = gen_reg_rtx (Pmode);
2346 insn = emit_move_insn (reg, x);
2347 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2349 set_unique_reg_note (insn, REG_EQUAL, orig);
2354 /* Does the same as m68k_wrap_symbol, but returns a memory reference to
2358 m68k_wrap_symbol_into_got_ref (rtx x, enum m68k_reloc reloc, rtx temp_reg)
2360 x = m68k_wrap_symbol (x, reloc, m68k_get_gp (), temp_reg);
2362 x = gen_rtx_MEM (Pmode, x);
2363 MEM_READONLY_P (x) = 1;
2368 /* Legitimize PIC addresses. If the address is already
2369 position-independent, we return ORIG. Newly generated
2370 position-independent addresses go to REG. If we need more
2371 than one register, we lose.
2373 An address is legitimized by making an indirect reference
2374 through the Global Offset Table with the name of the symbol
2377 The assembler and linker are responsible for placing the
2378 address of the symbol in the GOT. The function prologue
2379 is responsible for initializing a5 to the starting address
2382 The assembler is also responsible for translating a symbol name
2383 into a constant displacement from the start of the GOT.
2385 A quick example may make things a little clearer:
2387 When not generating PIC code to store the value 12345 into _foo
2388 we would generate the following code:
2392 When generating PIC two transformations are made. First, the compiler
2393 loads the address of foo into a register. So the first transformation makes:
2398 The code in movsi will intercept the lea instruction and call this
2399 routine which will transform the instructions into:
2401 movel a5@(_foo:w), a0
2405 That (in a nutshell) is how *all* symbol and label references are
2409 legitimize_pic_address (rtx orig, enum machine_mode mode ATTRIBUTE_UNUSED,
2414 /* First handle a simple SYMBOL_REF or LABEL_REF */
2415 if (GET_CODE (orig) == SYMBOL_REF || GET_CODE (orig) == LABEL_REF)
2419 pic_ref = m68k_wrap_symbol_into_got_ref (orig, RELOC_GOT, reg);
2420 pic_ref = m68k_move_to_reg (pic_ref, orig, reg);
2422 else if (GET_CODE (orig) == CONST)
2426 /* Make sure this has not already been legitimized. */
2427 if (m68k_unwrap_symbol (orig, true) != orig)
2432 /* legitimize both operands of the PLUS */
2433 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
2435 base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg);
2436 orig = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode,
2437 base == reg ? 0 : reg);
2439 if (GET_CODE (orig) == CONST_INT)
2440 pic_ref = plus_constant (base, INTVAL (orig));
2442 pic_ref = gen_rtx_PLUS (Pmode, base, orig);
2448 /* The __tls_get_addr symbol. */
2449 static GTY(()) rtx m68k_tls_get_addr;
2451 /* Return SYMBOL_REF for __tls_get_addr. */
2454 m68k_get_tls_get_addr (void)
2456 if (m68k_tls_get_addr == NULL_RTX)
2457 m68k_tls_get_addr = init_one_libfunc ("__tls_get_addr");
2459 return m68k_tls_get_addr;
2462 /* Return libcall result in A0 instead of usual D0. */
2463 static bool m68k_libcall_value_in_a0_p = false;
2465 /* Emit instruction sequence that calls __tls_get_addr. X is
2466 the TLS symbol we are referencing and RELOC is the symbol type to use
2467 (either TLSGD or TLSLDM). EQV is the REG_EQUAL note for the sequence
2468 emitted. A pseudo register with result of __tls_get_addr call is
2472 m68k_call_tls_get_addr (rtx x, rtx eqv, enum m68k_reloc reloc)
2478 /* Emit the call sequence. */
2481 /* FIXME: Unfortunately, emit_library_call_value does not
2482 consider (plus (%a5) (const (unspec))) to be a good enough
2483 operand for push, so it forces it into a register. The bad
2484 thing about this is that combiner, due to copy propagation and other
2485 optimizations, sometimes can not later fix this. As a consequence,
2486 additional register may be allocated resulting in a spill.
2487 For reference, see args processing loops in
2488 calls.c:emit_library_call_value_1.
2489 For testcase, see gcc.target/m68k/tls-{gd, ld}.c */
2490 x = m68k_wrap_symbol (x, reloc, m68k_get_gp (), NULL_RTX);
2492 /* __tls_get_addr() is not a libcall, but emitting a libcall_value
2493 is the simpliest way of generating a call. The difference between
2494 __tls_get_addr() and libcall is that the result is returned in D0
2495 instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p
2496 which temporarily switches returning the result to A0. */
2498 m68k_libcall_value_in_a0_p = true;
2499 a0 = emit_library_call_value (m68k_get_tls_get_addr (), NULL_RTX, LCT_PURE,
2500 Pmode, 1, x, Pmode);
2501 m68k_libcall_value_in_a0_p = false;
2503 insns = get_insns ();
2506 gcc_assert (can_create_pseudo_p ());
2507 dest = gen_reg_rtx (Pmode);
2508 emit_libcall_block (insns, dest, a0, eqv);
2513 /* The __tls_get_addr symbol. */
2514 static GTY(()) rtx m68k_read_tp;
2516 /* Return SYMBOL_REF for __m68k_read_tp. */
2519 m68k_get_m68k_read_tp (void)
2521 if (m68k_read_tp == NULL_RTX)
2522 m68k_read_tp = init_one_libfunc ("__m68k_read_tp");
2524 return m68k_read_tp;
2527 /* Emit instruction sequence that calls __m68k_read_tp.
2528 A pseudo register with result of __m68k_read_tp call is returned. */
2531 m68k_call_m68k_read_tp (void)
2540 /* __m68k_read_tp() is not a libcall, but emitting a libcall_value
2541 is the simpliest way of generating a call. The difference between
2542 __m68k_read_tp() and libcall is that the result is returned in D0
2543 instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p
2544 which temporarily switches returning the result to A0. */
2546 /* Emit the call sequence. */
2547 m68k_libcall_value_in_a0_p = true;
2548 a0 = emit_library_call_value (m68k_get_m68k_read_tp (), NULL_RTX, LCT_PURE,
2550 m68k_libcall_value_in_a0_p = false;
2551 insns = get_insns ();
2554 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2555 share the m68k_read_tp result with other IE/LE model accesses. */
2556 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const1_rtx), UNSPEC_RELOC32);
2558 gcc_assert (can_create_pseudo_p ());
2559 dest = gen_reg_rtx (Pmode);
2560 emit_libcall_block (insns, dest, a0, eqv);
2565 /* Return a legitimized address for accessing TLS SYMBOL_REF X.
2566 For explanations on instructions sequences see TLS/NPTL ABI for m68k and
2570 m68k_legitimize_tls_address (rtx orig)
2572 switch (SYMBOL_REF_TLS_MODEL (orig))
2574 case TLS_MODEL_GLOBAL_DYNAMIC:
2575 orig = m68k_call_tls_get_addr (orig, orig, RELOC_TLSGD);
2578 case TLS_MODEL_LOCAL_DYNAMIC:
2584 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2585 share the LDM result with other LD model accesses. */
2586 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2589 a0 = m68k_call_tls_get_addr (orig, eqv, RELOC_TLSLDM);
2591 x = m68k_wrap_symbol (orig, RELOC_TLSLDO, a0, NULL_RTX);
2593 if (can_create_pseudo_p ())
2594 x = m68k_move_to_reg (x, orig, NULL_RTX);
2600 case TLS_MODEL_INITIAL_EXEC:
2605 a0 = m68k_call_m68k_read_tp ();
2607 x = m68k_wrap_symbol_into_got_ref (orig, RELOC_TLSIE, NULL_RTX);
2608 x = gen_rtx_PLUS (Pmode, x, a0);
2610 if (can_create_pseudo_p ())
2611 x = m68k_move_to_reg (x, orig, NULL_RTX);
2617 case TLS_MODEL_LOCAL_EXEC:
2622 a0 = m68k_call_m68k_read_tp ();
2624 x = m68k_wrap_symbol (orig, RELOC_TLSLE, a0, NULL_RTX);
2626 if (can_create_pseudo_p ())
2627 x = m68k_move_to_reg (x, orig, NULL_RTX);
2640 /* Return true if X is a TLS symbol. */
2643 m68k_tls_symbol_p (rtx x)
2645 if (!TARGET_HAVE_TLS)
2648 if (GET_CODE (x) != SYMBOL_REF)
2651 return SYMBOL_REF_TLS_MODEL (x) != 0;
2654 /* Helper for m68k_tls_referenced_p. */
2657 m68k_tls_reference_p_1 (rtx *x_ptr, void *data ATTRIBUTE_UNUSED)
2659 /* Note: this is not the same as m68k_tls_symbol_p. */
2660 if (GET_CODE (*x_ptr) == SYMBOL_REF)
2661 return SYMBOL_REF_TLS_MODEL (*x_ptr) != 0 ? 1 : 0;
2663 /* Don't recurse into legitimate TLS references. */
2664 if (m68k_tls_reference_p (*x_ptr, true))
2670 /* If !LEGITIMATE_P, return true if X is a TLS symbol reference,
2671 though illegitimate one.
2672 If LEGITIMATE_P, return true if X is a legitimate TLS symbol reference. */
2675 m68k_tls_reference_p (rtx x, bool legitimate_p)
2677 if (!TARGET_HAVE_TLS)
2681 return for_each_rtx (&x, m68k_tls_reference_p_1, NULL) == 1 ? true : false;
2684 enum m68k_reloc reloc = RELOC_GOT;
2686 return (m68k_unwrap_symbol_1 (x, true, &reloc) != x
2687 && TLS_RELOC_P (reloc));
2693 #define USE_MOVQ(i) ((unsigned) ((i) + 128) <= 255)
2695 /* Return the type of move that should be used for integer I. */
2698 m68k_const_method (HOST_WIDE_INT i)
2705 /* The ColdFire doesn't have byte or word operations. */
2706 /* FIXME: This may not be useful for the m68060 either. */
2707 if (!TARGET_COLDFIRE)
2709 /* if -256 < N < 256 but N is not in range for a moveq
2710 N^ff will be, so use moveq #N^ff, dreg; not.b dreg. */
2711 if (USE_MOVQ (i ^ 0xff))
2713 /* Likewise, try with not.w */
2714 if (USE_MOVQ (i ^ 0xffff))
2716 /* This is the only value where neg.w is useful */
2721 /* Try also with swap. */
2723 if (USE_MOVQ ((u >> 16) | (u << 16)))
2728 /* Try using MVZ/MVS with an immediate value to load constants. */
2729 if (i >= 0 && i <= 65535)
2731 if (i >= -32768 && i <= 32767)
2735 /* Otherwise, use move.l */
2739 /* Return the cost of moving constant I into a data register. */
2742 const_int_cost (HOST_WIDE_INT i)
2744 switch (m68k_const_method (i))
2747 /* Constants between -128 and 127 are cheap due to moveq. */
2755 /* Constants easily generated by moveq + not.b/not.w/neg.w/swap. */
2765 m68k_rtx_costs (rtx x, int code, int outer_code, int *total,
2766 bool speed ATTRIBUTE_UNUSED)
2771 /* Constant zero is super cheap due to clr instruction. */
2772 if (x == const0_rtx)
2775 *total = const_int_cost (INTVAL (x));
2785 /* Make 0.0 cheaper than other floating constants to
2786 encourage creating tstsf and tstdf insns. */
2787 if (outer_code == COMPARE
2788 && (x == CONST0_RTX (SFmode) || x == CONST0_RTX (DFmode)))
2794 /* These are vaguely right for a 68020. */
2795 /* The costs for long multiply have been adjusted to work properly
2796 in synth_mult on the 68020, relative to an average of the time
2797 for add and the time for shift, taking away a little more because
2798 sometimes move insns are needed. */
2799 /* div?.w is relatively cheaper on 68000 counted in COSTS_N_INSNS
2804 : (TUNE_CFV2 && TUNE_EMAC) ? 3 \
2805 : (TUNE_CFV2 && TUNE_MAC) ? 4 \
2807 : TARGET_COLDFIRE ? 3 : 13)
2812 : TUNE_68000_10 ? 5 \
2813 : (TUNE_CFV2 && TUNE_EMAC) ? 3 \
2814 : (TUNE_CFV2 && TUNE_MAC) ? 2 \
2816 : TARGET_COLDFIRE ? 2 : 8)
2819 (TARGET_CF_HWDIV ? 11 \
2820 : TUNE_68000_10 || TARGET_COLDFIRE ? 12 : 27)
2823 /* An lea costs about three times as much as a simple add. */
2824 if (GET_MODE (x) == SImode
2825 && GET_CODE (XEXP (x, 1)) == REG
2826 && GET_CODE (XEXP (x, 0)) == MULT
2827 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2828 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2829 && (INTVAL (XEXP (XEXP (x, 0), 1)) == 2
2830 || INTVAL (XEXP (XEXP (x, 0), 1)) == 4
2831 || INTVAL (XEXP (XEXP (x, 0), 1)) == 8))
2833 /* lea an@(dx:l:i),am */
2834 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 2 : 3);
2844 *total = COSTS_N_INSNS(1);
2849 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
2851 if (INTVAL (XEXP (x, 1)) < 16)
2852 *total = COSTS_N_INSNS (2) + INTVAL (XEXP (x, 1)) / 2;
2854 /* We're using clrw + swap for these cases. */
2855 *total = COSTS_N_INSNS (4) + (INTVAL (XEXP (x, 1)) - 16) / 2;
2858 *total = COSTS_N_INSNS (10); /* Worst case. */
2861 /* A shift by a big integer takes an extra instruction. */
2862 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2863 && (INTVAL (XEXP (x, 1)) == 16))
2865 *total = COSTS_N_INSNS (2); /* clrw;swap */
2868 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2869 && !(INTVAL (XEXP (x, 1)) > 0
2870 && INTVAL (XEXP (x, 1)) <= 8))
2872 *total = COSTS_N_INSNS (TARGET_COLDFIRE ? 1 : 3); /* lsr #i,dn */
2878 if ((GET_CODE (XEXP (x, 0)) == ZERO_EXTEND
2879 || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)
2880 && GET_MODE (x) == SImode)
2881 *total = COSTS_N_INSNS (MULW_COST);
2882 else if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
2883 *total = COSTS_N_INSNS (MULW_COST);
2885 *total = COSTS_N_INSNS (MULL_COST);
2892 if (GET_MODE (x) == QImode || GET_MODE (x) == HImode)
2893 *total = COSTS_N_INSNS (DIVW_COST); /* div.w */
2894 else if (TARGET_CF_HWDIV)
2895 *total = COSTS_N_INSNS (18);
2897 *total = COSTS_N_INSNS (43); /* div.l */
2901 if (outer_code == COMPARE)
2910 /* Return an instruction to move CONST_INT OPERANDS[1] into data register
2914 output_move_const_into_data_reg (rtx *operands)
2918 i = INTVAL (operands[1]);
2919 switch (m68k_const_method (i))
2922 return "mvzw %1,%0";
2924 return "mvsw %1,%0";
2926 return "moveq %1,%0";
2929 operands[1] = GEN_INT (i ^ 0xff);
2930 return "moveq %1,%0\n\tnot%.b %0";
2933 operands[1] = GEN_INT (i ^ 0xffff);
2934 return "moveq %1,%0\n\tnot%.w %0";
2937 return "moveq #-128,%0\n\tneg%.w %0";
2942 operands[1] = GEN_INT ((u << 16) | (u >> 16));
2943 return "moveq %1,%0\n\tswap %0";
2946 return "move%.l %1,%0";
2952 /* Return true if I can be handled by ISA B's mov3q instruction. */
2955 valid_mov3q_const (HOST_WIDE_INT i)
2957 return TARGET_ISAB && (i == -1 || IN_RANGE (i, 1, 7));
2960 /* Return an instruction to move CONST_INT OPERANDS[1] into OPERANDS[0].
2961 I is the value of OPERANDS[1]. */
2964 output_move_simode_const (rtx *operands)
2970 src = INTVAL (operands[1]);
2972 && (DATA_REG_P (dest) || MEM_P (dest))
2973 /* clr insns on 68000 read before writing. */
2974 && ((TARGET_68010 || TARGET_COLDFIRE)
2975 || !(MEM_P (dest) && MEM_VOLATILE_P (dest))))
2977 else if (GET_MODE (dest) == SImode && valid_mov3q_const (src))
2978 return "mov3q%.l %1,%0";
2979 else if (src == 0 && ADDRESS_REG_P (dest))
2980 return "sub%.l %0,%0";
2981 else if (DATA_REG_P (dest))
2982 return output_move_const_into_data_reg (operands);
2983 else if (ADDRESS_REG_P (dest) && IN_RANGE (src, -0x8000, 0x7fff))
2985 if (valid_mov3q_const (src))
2986 return "mov3q%.l %1,%0";
2987 return "move%.w %1,%0";
2989 else if (MEM_P (dest)
2990 && GET_CODE (XEXP (dest, 0)) == PRE_DEC
2991 && REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2992 && IN_RANGE (src, -0x8000, 0x7fff))
2994 if (valid_mov3q_const (src))
2995 return "mov3q%.l %1,%-";
2998 return "move%.l %1,%0";
3002 output_move_simode (rtx *operands)
3004 if (GET_CODE (operands[1]) == CONST_INT)
3005 return output_move_simode_const (operands);
3006 else if ((GET_CODE (operands[1]) == SYMBOL_REF
3007 || GET_CODE (operands[1]) == CONST)
3008 && push_operand (operands[0], SImode))
3010 else if ((GET_CODE (operands[1]) == SYMBOL_REF
3011 || GET_CODE (operands[1]) == CONST)
3012 && ADDRESS_REG_P (operands[0]))
3013 return "lea %a1,%0";
3014 return "move%.l %1,%0";
3018 output_move_himode (rtx *operands)
3020 if (GET_CODE (operands[1]) == CONST_INT)
3022 if (operands[1] == const0_rtx
3023 && (DATA_REG_P (operands[0])
3024 || GET_CODE (operands[0]) == MEM)
3025 /* clr insns on 68000 read before writing. */
3026 && ((TARGET_68010 || TARGET_COLDFIRE)
3027 || !(GET_CODE (operands[0]) == MEM
3028 && MEM_VOLATILE_P (operands[0]))))
3030 else if (operands[1] == const0_rtx
3031 && ADDRESS_REG_P (operands[0]))
3032 return "sub%.l %0,%0";
3033 else if (DATA_REG_P (operands[0])
3034 && INTVAL (operands[1]) < 128
3035 && INTVAL (operands[1]) >= -128)
3036 return "moveq %1,%0";
3037 else if (INTVAL (operands[1]) < 0x8000
3038 && INTVAL (operands[1]) >= -0x8000)
3039 return "move%.w %1,%0";
3041 else if (CONSTANT_P (operands[1]))
3042 return "move%.l %1,%0";
3043 return "move%.w %1,%0";
3047 output_move_qimode (rtx *operands)
3049 /* 68k family always modifies the stack pointer by at least 2, even for
3050 byte pushes. The 5200 (ColdFire) does not do this. */
3052 /* This case is generated by pushqi1 pattern now. */
3053 gcc_assert (!(GET_CODE (operands[0]) == MEM
3054 && GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
3055 && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx
3056 && ! ADDRESS_REG_P (operands[1])
3057 && ! TARGET_COLDFIRE));
3059 /* clr and st insns on 68000 read before writing. */
3060 if (!ADDRESS_REG_P (operands[0])
3061 && ((TARGET_68010 || TARGET_COLDFIRE)
3062 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
3064 if (operands[1] == const0_rtx)
3066 if ((!TARGET_COLDFIRE || DATA_REG_P (operands[0]))
3067 && GET_CODE (operands[1]) == CONST_INT
3068 && (INTVAL (operands[1]) & 255) == 255)
3074 if (GET_CODE (operands[1]) == CONST_INT
3075 && DATA_REG_P (operands[0])
3076 && INTVAL (operands[1]) < 128
3077 && INTVAL (operands[1]) >= -128)
3078 return "moveq %1,%0";
3079 if (operands[1] == const0_rtx && ADDRESS_REG_P (operands[0]))
3080 return "sub%.l %0,%0";
3081 if (GET_CODE (operands[1]) != CONST_INT && CONSTANT_P (operands[1]))
3082 return "move%.l %1,%0";
3083 /* 68k family (including the 5200 ColdFire) does not support byte moves to
3084 from address registers. */
3085 if (ADDRESS_REG_P (operands[0]) || ADDRESS_REG_P (operands[1]))
3086 return "move%.w %1,%0";
3087 return "move%.b %1,%0";
3091 output_move_stricthi (rtx *operands)
3093 if (operands[1] == const0_rtx
3094 /* clr insns on 68000 read before writing. */
3095 && ((TARGET_68010 || TARGET_COLDFIRE)
3096 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
3098 return "move%.w %1,%0";
3102 output_move_strictqi (rtx *operands)
3104 if (operands[1] == const0_rtx
3105 /* clr insns on 68000 read before writing. */
3106 && ((TARGET_68010 || TARGET_COLDFIRE)
3107 || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
3109 return "move%.b %1,%0";
3112 /* Return the best assembler insn template
3113 for moving operands[1] into operands[0] as a fullword. */
3116 singlemove_string (rtx *operands)
3118 if (GET_CODE (operands[1]) == CONST_INT)
3119 return output_move_simode_const (operands);
3120 return "move%.l %1,%0";
3124 /* Output assembler or rtl code to perform a doubleword move insn
3125 with operands OPERANDS.
3126 Pointers to 3 helper functions should be specified:
3127 HANDLE_REG_ADJUST to adjust a register by a small value,
3128 HANDLE_COMPADR to compute an address and
3129 HANDLE_MOVSI to move 4 bytes. */
3132 handle_move_double (rtx operands[2],
3133 void (*handle_reg_adjust) (rtx, int),
3134 void (*handle_compadr) (rtx [2]),
3135 void (*handle_movsi) (rtx [2]))
3139 REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP
3144 rtx addreg0 = 0, addreg1 = 0;
3145 int dest_overlapped_low = 0;
3146 int size = GET_MODE_SIZE (GET_MODE (operands[0]));
3151 /* First classify both operands. */
3153 if (REG_P (operands[0]))
3155 else if (offsettable_memref_p (operands[0]))
3157 else if (GET_CODE (XEXP (operands[0], 0)) == POST_INC)
3159 else if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)
3161 else if (GET_CODE (operands[0]) == MEM)
3166 if (REG_P (operands[1]))
3168 else if (CONSTANT_P (operands[1]))
3170 else if (offsettable_memref_p (operands[1]))
3172 else if (GET_CODE (XEXP (operands[1], 0)) == POST_INC)
3174 else if (GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)
3176 else if (GET_CODE (operands[1]) == MEM)
3181 /* Check for the cases that the operand constraints are not supposed
3182 to allow to happen. Generating code for these cases is
3184 gcc_assert (optype0 != RNDOP && optype1 != RNDOP);
3186 /* If one operand is decrementing and one is incrementing
3187 decrement the former register explicitly
3188 and change that operand into ordinary indexing. */
3190 if (optype0 == PUSHOP && optype1 == POPOP)
3192 operands[0] = XEXP (XEXP (operands[0], 0), 0);
3194 handle_reg_adjust (operands[0], -size);
3196 if (GET_MODE (operands[1]) == XFmode)
3197 operands[0] = gen_rtx_MEM (XFmode, operands[0]);
3198 else if (GET_MODE (operands[0]) == DFmode)
3199 operands[0] = gen_rtx_MEM (DFmode, operands[0]);
3201 operands[0] = gen_rtx_MEM (DImode, operands[0]);
3204 if (optype0 == POPOP && optype1 == PUSHOP)
3206 operands[1] = XEXP (XEXP (operands[1], 0), 0);
3208 handle_reg_adjust (operands[1], -size);
3210 if (GET_MODE (operands[1]) == XFmode)
3211 operands[1] = gen_rtx_MEM (XFmode, operands[1]);
3212 else if (GET_MODE (operands[1]) == DFmode)
3213 operands[1] = gen_rtx_MEM (DFmode, operands[1]);
3215 operands[1] = gen_rtx_MEM (DImode, operands[1]);
3219 /* If an operand is an unoffsettable memory ref, find a register
3220 we can increment temporarily to make it refer to the second word. */
3222 if (optype0 == MEMOP)
3223 addreg0 = find_addr_reg (XEXP (operands[0], 0));
3225 if (optype1 == MEMOP)
3226 addreg1 = find_addr_reg (XEXP (operands[1], 0));
3228 /* Ok, we can do one word at a time.
3229 Normally we do the low-numbered word first,
3230 but if either operand is autodecrementing then we
3231 do the high-numbered word first.
3233 In either case, set up in LATEHALF the operands to use
3234 for the high-numbered word and in some cases alter the
3235 operands in OPERANDS to be suitable for the low-numbered word. */
3239 if (optype0 == REGOP)
3241 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 2);
3242 middlehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3244 else if (optype0 == OFFSOP)
3246 middlehalf[0] = adjust_address (operands[0], SImode, 4);
3247 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
3251 middlehalf[0] = adjust_address (operands[0], SImode, 0);
3252 latehalf[0] = adjust_address (operands[0], SImode, 0);
3255 if (optype1 == REGOP)
3257 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 2);
3258 middlehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
3260 else if (optype1 == OFFSOP)
3262 middlehalf[1] = adjust_address (operands[1], SImode, 4);
3263 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
3265 else if (optype1 == CNSTOP)
3267 if (GET_CODE (operands[1]) == CONST_DOUBLE)
3272 REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
3273 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l);
3274 operands[1] = GEN_INT (l[0]);
3275 middlehalf[1] = GEN_INT (l[1]);
3276 latehalf[1] = GEN_INT (l[2]);
3280 /* No non-CONST_DOUBLE constant should ever appear
3282 gcc_assert (!CONSTANT_P (operands[1]));
3287 middlehalf[1] = adjust_address (operands[1], SImode, 0);
3288 latehalf[1] = adjust_address (operands[1], SImode, 0);
3292 /* size is not 12: */
3294 if (optype0 == REGOP)
3295 latehalf[0] = gen_rtx_REG (SImode, REGNO (operands[0]) + 1);
3296 else if (optype0 == OFFSOP)
3297 latehalf[0] = adjust_address (operands[0], SImode, size - 4);
3299 latehalf[0] = adjust_address (operands[0], SImode, 0);
3301 if (optype1 == REGOP)
3302 latehalf[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
3303 else if (optype1 == OFFSOP)
3304 latehalf[1] = adjust_address (operands[1], SImode, size - 4);
3305 else if (optype1 == CNSTOP)
3306 split_double (operands[1], &operands[1], &latehalf[1]);
3308 latehalf[1] = adjust_address (operands[1], SImode, 0);
3311 /* If insn is effectively movd N(sp),-(sp) then we will do the
3312 high word first. We should use the adjusted operand 1 (which is N+4(sp))
3313 for the low word as well, to compensate for the first decrement of sp. */
3314 if (optype0 == PUSHOP
3315 && REGNO (XEXP (XEXP (operands[0], 0), 0)) == STACK_POINTER_REGNUM
3316 && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
3317 operands[1] = middlehalf[1] = latehalf[1];
3319 /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
3320 if the upper part of reg N does not appear in the MEM, arrange to
3321 emit the move late-half first. Otherwise, compute the MEM address
3322 into the upper part of N and use that as a pointer to the memory
3324 if (optype0 == REGOP
3325 && (optype1 == OFFSOP || optype1 == MEMOP))
3327 rtx testlow = gen_rtx_REG (SImode, REGNO (operands[0]));
3329 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
3330 && reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
3332 /* If both halves of dest are used in the src memory address,
3333 compute the address into latehalf of dest.
3334 Note that this can't happen if the dest is two data regs. */
3336 xops[0] = latehalf[0];
3337 xops[1] = XEXP (operands[1], 0);
3339 handle_compadr (xops);
3340 if (GET_MODE (operands[1]) == XFmode)
3342 operands[1] = gen_rtx_MEM (XFmode, latehalf[0]);
3343 middlehalf[1] = adjust_address (operands[1], DImode, size - 8);
3344 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
3348 operands[1] = gen_rtx_MEM (DImode, latehalf[0]);
3349 latehalf[1] = adjust_address (operands[1], DImode, size - 4);
3353 && reg_overlap_mentioned_p (middlehalf[0],
3354 XEXP (operands[1], 0)))
3356 /* Check for two regs used by both source and dest.
3357 Note that this can't happen if the dest is all data regs.
3358 It can happen if the dest is d6, d7, a0.
3359 But in that case, latehalf is an addr reg, so
3360 the code at compadr does ok. */
3362 if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0))
3363 || reg_overlap_mentioned_p (latehalf[0], XEXP (operands[1], 0)))
3366 /* JRV says this can't happen: */
3367 gcc_assert (!addreg0 && !addreg1);
3369 /* Only the middle reg conflicts; simply put it last. */
3370 handle_movsi (operands);
3371 handle_movsi (latehalf);
3372 handle_movsi (middlehalf);
3376 else if (reg_overlap_mentioned_p (testlow, XEXP (operands[1], 0)))
3377 /* If the low half of dest is mentioned in the source memory
3378 address, the arrange to emit the move late half first. */
3379 dest_overlapped_low = 1;
3382 /* If one or both operands autodecrementing,
3383 do the two words, high-numbered first. */
3385 /* Likewise, the first move would clobber the source of the second one,
3386 do them in the other order. This happens only for registers;
3387 such overlap can't happen in memory unless the user explicitly
3388 sets it up, and that is an undefined circumstance. */
3390 if (optype0 == PUSHOP || optype1 == PUSHOP
3391 || (optype0 == REGOP && optype1 == REGOP
3392 && ((middlehalf[1] && REGNO (operands[0]) == REGNO (middlehalf[1]))
3393 || REGNO (operands[0]) == REGNO (latehalf[1])))
3394 || dest_overlapped_low)
3396 /* Make any unoffsettable addresses point at high-numbered word. */
3398 handle_reg_adjust (addreg0, size - 4);
3400 handle_reg_adjust (addreg1, size - 4);
3403 handle_movsi (latehalf);
3405 /* Undo the adds we just did. */
3407 handle_reg_adjust (addreg0, -4);
3409 handle_reg_adjust (addreg1, -4);
3413 handle_movsi (middlehalf);
3416 handle_reg_adjust (addreg0, -4);
3418 handle_reg_adjust (addreg1, -4);
3421 /* Do low-numbered word. */
3423 handle_movsi (operands);
3427 /* Normal case: do the two words, low-numbered first. */
3429 handle_movsi (operands);
3431 /* Do the middle one of the three words for long double */
3435 handle_reg_adjust (addreg0, 4);
3437 handle_reg_adjust (addreg1, 4);
3439 handle_movsi (middlehalf);
3442 /* Make any unoffsettable addresses point at high-numbered word. */
3444 handle_reg_adjust (addreg0, 4);
3446 handle_reg_adjust (addreg1, 4);
3449 handle_movsi (latehalf);
3451 /* Undo the adds we just did. */
3453 handle_reg_adjust (addreg0, -(size - 4));
3455 handle_reg_adjust (addreg1, -(size - 4));
3460 /* Output assembler code to adjust REG by N. */
3462 output_reg_adjust (rtx reg, int n)
3466 gcc_assert (GET_MODE (reg) == SImode
3467 && -12 <= n && n != 0 && n <= 12);
3472 s = "add%.l #12,%0";
3476 s = "addq%.l #8,%0";
3480 s = "addq%.l #4,%0";
3484 s = "sub%.l #12,%0";
3488 s = "subq%.l #8,%0";
3492 s = "subq%.l #4,%0";
3500 output_asm_insn (s, ®);
3503 /* Emit rtl code to adjust REG by N. */
3505 emit_reg_adjust (rtx reg1, int n)
3509 gcc_assert (GET_MODE (reg1) == SImode
3510 && -12 <= n && n != 0 && n <= 12);
3512 reg1 = copy_rtx (reg1);
3513 reg2 = copy_rtx (reg1);
3516 emit_insn (gen_subsi3 (reg1, reg2, GEN_INT (-n)));
3518 emit_insn (gen_addsi3 (reg1, reg2, GEN_INT (n)));
3523 /* Output assembler to load address OPERANDS[0] to register OPERANDS[1]. */
3525 output_compadr (rtx operands[2])
3527 output_asm_insn ("lea %a1,%0", operands);
3530 /* Output the best assembler insn for moving operands[1] into operands[0]
3533 output_movsi (rtx operands[2])
3535 output_asm_insn (singlemove_string (operands), operands);
3538 /* Copy OP and change its mode to MODE. */
3540 copy_operand (rtx op, enum machine_mode mode)
3542 /* ??? This looks really ugly. There must be a better way
3543 to change a mode on the operand. */
3544 if (GET_MODE (op) != VOIDmode)
3547 op = gen_rtx_REG (mode, REGNO (op));
3551 PUT_MODE (op, mode);
3558 /* Emit rtl code for moving operands[1] into operands[0] as a fullword. */
3560 emit_movsi (rtx operands[2])
3562 operands[0] = copy_operand (operands[0], SImode);
3563 operands[1] = copy_operand (operands[1], SImode);
3565 emit_insn (gen_movsi (operands[0], operands[1]));
3568 /* Output assembler code to perform a doubleword move insn
3569 with operands OPERANDS. */
3571 output_move_double (rtx *operands)
3573 handle_move_double (operands,
3574 output_reg_adjust, output_compadr, output_movsi);
3579 /* Output rtl code to perform a doubleword move insn
3580 with operands OPERANDS. */
3582 m68k_emit_move_double (rtx operands[2])
3584 handle_move_double (operands, emit_reg_adjust, emit_movsi, emit_movsi);
3587 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
3588 new rtx with the correct mode. */
3591 force_mode (enum machine_mode mode, rtx orig)
3593 if (mode == GET_MODE (orig))
3596 if (REGNO (orig) >= FIRST_PSEUDO_REGISTER)
3599 return gen_rtx_REG (mode, REGNO (orig));
3603 fp_reg_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3605 return reg_renumber && FP_REG_P (op);
3608 /* Emit insns to move operands[1] into operands[0].
3610 Return 1 if we have written out everything that needs to be done to
3611 do the move. Otherwise, return 0 and the caller will emit the move
3614 Note SCRATCH_REG may not be in the proper mode depending on how it
3615 will be used. This routine is responsible for creating a new copy
3616 of SCRATCH_REG in the proper mode. */
3619 emit_move_sequence (rtx *operands, enum machine_mode mode, rtx scratch_reg)
3621 register rtx operand0 = operands[0];
3622 register rtx operand1 = operands[1];
3626 && reload_in_progress && GET_CODE (operand0) == REG
3627 && REGNO (operand0) >= FIRST_PSEUDO_REGISTER)
3628 operand0 = reg_equiv_mem[REGNO (operand0)];
3629 else if (scratch_reg
3630 && reload_in_progress && GET_CODE (operand0) == SUBREG
3631 && GET_CODE (SUBREG_REG (operand0)) == REG
3632 && REGNO (SUBREG_REG (operand0)) >= FIRST_PSEUDO_REGISTER)
3634 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
3635 the code which tracks sets/uses for delete_output_reload. */
3636 rtx temp = gen_rtx_SUBREG (GET_MODE (operand0),
3637 reg_equiv_mem [REGNO (SUBREG_REG (operand0))],
3638 SUBREG_BYTE (operand0));
3639 operand0 = alter_subreg (&temp);
3643 && reload_in_progress && GET_CODE (operand1) == REG
3644 && REGNO (operand1) >= FIRST_PSEUDO_REGISTER)
3645 operand1 = reg_equiv_mem[REGNO (operand1)];
3646 else if (scratch_reg
3647 && reload_in_progress && GET_CODE (operand1) == SUBREG
3648 && GET_CODE (SUBREG_REG (operand1)) == REG
3649 && REGNO (SUBREG_REG (operand1)) >= FIRST_PSEUDO_REGISTER)
3651 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
3652 the code which tracks sets/uses for delete_output_reload. */
3653 rtx temp = gen_rtx_SUBREG (GET_MODE (operand1),
3654 reg_equiv_mem [REGNO (SUBREG_REG (operand1))],
3655 SUBREG_BYTE (operand1));
3656 operand1 = alter_subreg (&temp);
3659 if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
3660 && ((tem = find_replacement (&XEXP (operand0, 0)))
3661 != XEXP (operand0, 0)))
3662 operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
3663 if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
3664 && ((tem = find_replacement (&XEXP (operand1, 0)))
3665 != XEXP (operand1, 0)))
3666 operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
3668 /* Handle secondary reloads for loads/stores of FP registers where
3669 the address is symbolic by using the scratch register */
3670 if (fp_reg_operand (operand0, mode)
3671 && ((GET_CODE (operand1) == MEM
3672 && ! memory_address_p (DFmode, XEXP (operand1, 0)))
3673 || ((GET_CODE (operand1) == SUBREG
3674 && GET_CODE (XEXP (operand1, 0)) == MEM
3675 && !memory_address_p (DFmode, XEXP (XEXP (operand1, 0), 0)))))
3678 if (GET_CODE (operand1) == SUBREG)
3679 operand1 = XEXP (operand1, 0);
3681 /* SCRATCH_REG will hold an address. We want
3682 it in SImode regardless of what mode it was originally given
3684 scratch_reg = force_mode (SImode, scratch_reg);
3686 /* D might not fit in 14 bits either; for such cases load D into
3688 if (!memory_address_p (Pmode, XEXP (operand1, 0)))
3690 emit_move_insn (scratch_reg, XEXP (XEXP (operand1, 0), 1));
3691 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1, 0)),
3693 XEXP (XEXP (operand1, 0), 0),
3697 emit_move_insn (scratch_reg, XEXP (operand1, 0));
3698 emit_insn (gen_rtx_SET (VOIDmode, operand0,
3699 gen_rtx_MEM (mode, scratch_reg)));
3702 else if (fp_reg_operand (operand1, mode)
3703 && ((GET_CODE (operand0) == MEM
3704 && ! memory_address_p (DFmode, XEXP (operand0, 0)))
3705 || ((GET_CODE (operand0) == SUBREG)
3706 && GET_CODE (XEXP (operand0, 0)) == MEM
3707 && !memory_address_p (DFmode, XEXP (XEXP (operand0, 0), 0))))
3710 if (GET_CODE (operand0) == SUBREG)
3711 operand0 = XEXP (operand0, 0);
3713 /* SCRATCH_REG will hold an address and maybe the actual data. We want
3714 it in SIMODE regardless of what mode it was originally given
3716 scratch_reg = force_mode (SImode, scratch_reg);
3718 /* D might not fit in 14 bits either; for such cases load D into
3720 if (!memory_address_p (Pmode, XEXP (operand0, 0)))
3722 emit_move_insn (scratch_reg, XEXP (XEXP (operand0, 0), 1));
3723 emit_move_insn (scratch_reg, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0,
3726 XEXP (XEXP (operand0, 0),
3731 emit_move_insn (scratch_reg, XEXP (operand0, 0));
3732 emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_MEM (mode, scratch_reg),
3736 /* Handle secondary reloads for loads of FP registers from constant
3737 expressions by forcing the constant into memory.
3739 use scratch_reg to hold the address of the memory location.
3741 The proper fix is to change PREFERRED_RELOAD_CLASS to return
3742 NO_REGS when presented with a const_int and an register class
3743 containing only FP registers. Doing so unfortunately creates
3744 more problems than it solves. Fix this for 2.5. */
3745 else if (fp_reg_operand (operand0, mode)
3746 && CONSTANT_P (operand1)
3751 /* SCRATCH_REG will hold an address and maybe the actual data. We want
3752 it in SIMODE regardless of what mode it was originally given
3754 scratch_reg = force_mode (SImode, scratch_reg);
3756 /* Force the constant into memory and put the address of the
3757 memory location into scratch_reg. */
3758 xoperands[0] = scratch_reg;
3759 xoperands[1] = XEXP (force_const_mem (mode, operand1), 0);
3760 emit_insn (gen_rtx_SET (mode, scratch_reg, xoperands[1]));
3762 /* Now load the destination register. */
3763 emit_insn (gen_rtx_SET (mode, operand0,
3764 gen_rtx_MEM (mode, scratch_reg)));
3768 /* Now have insn-emit do whatever it normally does. */
3772 /* Split one or more DImode RTL references into pairs of SImode
3773 references. The RTL can be REG, offsettable MEM, integer constant, or
3774 CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to
3775 split and "num" is its length. lo_half and hi_half are output arrays
3776 that parallel "operands". */
3779 split_di (rtx operands[], int num, rtx lo_half[], rtx hi_half[])
3783 rtx op = operands[num];
3785 /* simplify_subreg refuses to split volatile memory addresses,
3786 but we still have to handle it. */
3787 if (GET_CODE (op) == MEM)
3789 lo_half[num] = adjust_address (op, SImode, 4);
3790 hi_half[num] = adjust_address (op, SImode, 0);
3794 lo_half[num] = simplify_gen_subreg (SImode, op,
3795 GET_MODE (op) == VOIDmode
3796 ? DImode : GET_MODE (op), 4);
3797 hi_half[num] = simplify_gen_subreg (SImode, op,
3798 GET_MODE (op) == VOIDmode
3799 ? DImode : GET_MODE (op), 0);
3804 /* Split X into a base and a constant offset, storing them in *BASE
3805 and *OFFSET respectively. */
3808 m68k_split_offset (rtx x, rtx *base, HOST_WIDE_INT *offset)
3811 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3813 *offset += INTVAL (XEXP (x, 1));
3819 /* Return true if PATTERN is a PARALLEL suitable for a movem or fmovem
3820 instruction. STORE_P says whether the move is a load or store.
3822 If the instruction uses post-increment or pre-decrement addressing,
3823 AUTOMOD_BASE is the base register and AUTOMOD_OFFSET is the total
3824 adjustment. This adjustment will be made by the first element of
3825 PARALLEL, with the loads or stores starting at element 1. If the
3826 instruction does not use post-increment or pre-decrement addressing,
3827 AUTOMOD_BASE is null, AUTOMOD_OFFSET is 0, and the loads or stores
3828 start at element 0. */
3831 m68k_movem_pattern_p (rtx pattern, rtx automod_base,
3832 HOST_WIDE_INT automod_offset, bool store_p)
3834 rtx base, mem_base, set, mem, reg, last_reg;
3835 HOST_WIDE_INT offset, mem_offset;
3837 enum reg_class rclass;
3839 len = XVECLEN (pattern, 0);
3840 first = (automod_base != NULL);
3844 /* Stores must be pre-decrement and loads must be post-increment. */
3845 if (store_p != (automod_offset < 0))
3848 /* Work out the base and offset for lowest memory location. */
3849 base = automod_base;
3850 offset = (automod_offset < 0 ? automod_offset : 0);
3854 /* Allow any valid base and offset in the first access. */
3861 for (i = first; i < len; i++)
3863 /* We need a plain SET. */
3864 set = XVECEXP (pattern, 0, i);
3865 if (GET_CODE (set) != SET)
3868 /* Check that we have a memory location... */
3869 mem = XEXP (set, !store_p);
3870 if (!MEM_P (mem) || !memory_operand (mem, VOIDmode))
3873 /* ...with the right address. */
3876 m68k_split_offset (XEXP (mem, 0), &base, &offset);
3877 /* The ColdFire instruction only allows (An) and (d16,An) modes.
3878 There are no mode restrictions for 680x0 besides the
3879 automodification rules enforced above. */
3881 && !m68k_legitimate_base_reg_p (base, reload_completed))
3886 m68k_split_offset (XEXP (mem, 0), &mem_base, &mem_offset);
3887 if (!rtx_equal_p (base, mem_base) || offset != mem_offset)
3891 /* Check that we have a register of the required mode and class. */
3892 reg = XEXP (set, store_p);
3894 || !HARD_REGISTER_P (reg)
3895 || GET_MODE (reg) != reg_raw_mode[REGNO (reg)])
3900 /* The register must belong to RCLASS and have a higher number
3901 than the register in the previous SET. */
3902 if (!TEST_HARD_REG_BIT (reg_class_contents[rclass], REGNO (reg))
3903 || REGNO (last_reg) >= REGNO (reg))
3908 /* Work out which register class we need. */
3909 if (INT_REGNO_P (REGNO (reg)))
3910 rclass = GENERAL_REGS;
3911 else if (FP_REGNO_P (REGNO (reg)))
3918 offset += GET_MODE_SIZE (GET_MODE (reg));
3921 /* If we have an automodification, check whether the final offset is OK. */
3922 if (automod_base && offset != (automod_offset < 0 ? 0 : automod_offset))
3925 /* Reject unprofitable cases. */
3926 if (len < first + (rclass == FP_REGS ? MIN_FMOVEM_REGS : MIN_MOVEM_REGS))
3932 /* Return the assembly code template for a movem or fmovem instruction
3933 whose pattern is given by PATTERN. Store the template's operands
3936 If the instruction uses post-increment or pre-decrement addressing,
3937 AUTOMOD_OFFSET is the total adjustment, otherwise it is 0. STORE_P
3938 is true if this is a store instruction. */
3941 m68k_output_movem (rtx *operands, rtx pattern,
3942 HOST_WIDE_INT automod_offset, bool store_p)
3947 gcc_assert (GET_CODE (pattern) == PARALLEL);
3949 first = (automod_offset != 0);
3950 for (i = first; i < XVECLEN (pattern, 0); i++)
3952 /* When using movem with pre-decrement addressing, register X + D0_REG
3953 is controlled by bit 15 - X. For all other addressing modes,
3954 register X + D0_REG is controlled by bit X. Confusingly, the
3955 register mask for fmovem is in the opposite order to that for
3959 gcc_assert (MEM_P (XEXP (XVECEXP (pattern, 0, i), !store_p)));
3960 gcc_assert (REG_P (XEXP (XVECEXP (pattern, 0, i), store_p)));
3961 regno = REGNO (XEXP (XVECEXP (pattern, 0, i), store_p));
3962 if (automod_offset < 0)
3964 if (FP_REGNO_P (regno))
3965 mask |= 1 << (regno - FP0_REG);
3967 mask |= 1 << (15 - (regno - D0_REG));
3971 if (FP_REGNO_P (regno))
3972 mask |= 1 << (7 - (regno - FP0_REG));
3974 mask |= 1 << (regno - D0_REG);
3979 if (automod_offset == 0)
3980 operands[0] = XEXP (XEXP (XVECEXP (pattern, 0, first), !store_p), 0);
3981 else if (automod_offset < 0)
3982 operands[0] = gen_rtx_PRE_DEC (Pmode, SET_DEST (XVECEXP (pattern, 0, 0)));
3984 operands[0] = gen_rtx_POST_INC (Pmode, SET_DEST (XVECEXP (pattern, 0, 0)));
3985 operands[1] = GEN_INT (mask);
3986 if (FP_REGNO_P (REGNO (XEXP (XVECEXP (pattern, 0, first), store_p))))
3989 return "fmovem %1,%a0";
3991 return "fmovem %a0,%1";
3996 return "movem%.l %1,%a0";
3998 return "movem%.l %a0,%1";
4002 /* Return a REG that occurs in ADDR with coefficient 1.
4003 ADDR can be effectively incremented by incrementing REG. */
4006 find_addr_reg (rtx addr)
4008 while (GET_CODE (addr) == PLUS)
4010 if (GET_CODE (XEXP (addr, 0)) == REG)
4011 addr = XEXP (addr, 0);
4012 else if (GET_CODE (XEXP (addr, 1)) == REG)
4013 addr = XEXP (addr, 1);
4014 else if (CONSTANT_P (XEXP (addr, 0)))
4015 addr = XEXP (addr, 1);
4016 else if (CONSTANT_P (XEXP (addr, 1)))
4017 addr = XEXP (addr, 0);
4021 gcc_assert (GET_CODE (addr) == REG);
4025 /* Output assembler code to perform a 32-bit 3-operand add. */
4028 output_addsi3 (rtx *operands)
4030 if (! operands_match_p (operands[0], operands[1]))
4032 if (!ADDRESS_REG_P (operands[1]))
4034 rtx tmp = operands[1];
4036 operands[1] = operands[2];
4040 /* These insns can result from reloads to access
4041 stack slots over 64k from the frame pointer. */
4042 if (GET_CODE (operands[2]) == CONST_INT
4043 && (INTVAL (operands[2]) < -32768 || INTVAL (operands[2]) > 32767))
4044 return "move%.l %2,%0\n\tadd%.l %1,%0";
4045 if (GET_CODE (operands[2]) == REG)
4046 return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
4047 return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
4049 if (GET_CODE (operands[2]) == CONST_INT)
4051 if (INTVAL (operands[2]) > 0
4052 && INTVAL (operands[2]) <= 8)
4053 return "addq%.l %2,%0";
4054 if (INTVAL (operands[2]) < 0
4055 && INTVAL (operands[2]) >= -8)
4057 operands[2] = GEN_INT (- INTVAL (operands[2]));
4058 return "subq%.l %2,%0";
4060 /* On the CPU32 it is faster to use two addql instructions to
4061 add a small integer (8 < N <= 16) to a register.
4062 Likewise for subql. */
4063 if (TUNE_CPU32 && REG_P (operands[0]))
4065 if (INTVAL (operands[2]) > 8
4066 && INTVAL (operands[2]) <= 16)
4068 operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
4069 return "addq%.l #8,%0\n\taddq%.l %2,%0";
4071 if (INTVAL (operands[2]) < -8
4072 && INTVAL (operands[2]) >= -16)
4074 operands[2] = GEN_INT (- INTVAL (operands[2]) - 8);
4075 return "subq%.l #8,%0\n\tsubq%.l %2,%0";
4078 if (ADDRESS_REG_P (operands[0])
4079 && INTVAL (operands[2]) >= -0x8000
4080 && INTVAL (operands[2]) < 0x8000)
4083 return "add%.w %2,%0";
4085 return MOTOROLA ? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
4088 return "add%.l %2,%0";
4091 /* Store in cc_status the expressions that the condition codes will
4092 describe after execution of an instruction whose pattern is EXP.