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, 2010
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"
31 #include "insn-config.h"
32 #include "conditions.h"
34 #include "insn-attr.h"
36 #include "diagnostic-core.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
;
156 static void m68k_trampoline_init (rtx
, tree
, rtx
);
157 static int m68k_return_pops_args (tree
, tree
, int);
158 static rtx
m68k_delegitimize_address (rtx
);
161 /* Specify the identification number of the library being built */
162 const char *m68k_library_id_string
= "_current_shared_library_a5_offset_";
164 /* Initialize the GCC target structure. */
166 #if INT_OP_GROUP == INT_OP_DOT_WORD
167 #undef TARGET_ASM_ALIGNED_HI_OP
168 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
171 #if INT_OP_GROUP == INT_OP_NO_DOT
172 #undef TARGET_ASM_BYTE_OP
173 #define TARGET_ASM_BYTE_OP "\tbyte\t"
174 #undef TARGET_ASM_ALIGNED_HI_OP
175 #define TARGET_ASM_ALIGNED_HI_OP "\tshort\t"
176 #undef TARGET_ASM_ALIGNED_SI_OP
177 #define TARGET_ASM_ALIGNED_SI_OP "\tlong\t"
180 #if INT_OP_GROUP == INT_OP_DC
181 #undef TARGET_ASM_BYTE_OP
182 #define TARGET_ASM_BYTE_OP "\tdc.b\t"
183 #undef TARGET_ASM_ALIGNED_HI_OP
184 #define TARGET_ASM_ALIGNED_HI_OP "\tdc.w\t"
185 #undef TARGET_ASM_ALIGNED_SI_OP
186 #define TARGET_ASM_ALIGNED_SI_OP "\tdc.l\t"
189 #undef TARGET_ASM_UNALIGNED_HI_OP
190 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
191 #undef TARGET_ASM_UNALIGNED_SI_OP
192 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
194 #undef TARGET_ASM_OUTPUT_MI_THUNK
195 #define TARGET_ASM_OUTPUT_MI_THUNK m68k_output_mi_thunk
196 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
197 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
199 #undef TARGET_ASM_FILE_START_APP_OFF
200 #define TARGET_ASM_FILE_START_APP_OFF true
202 #undef TARGET_LEGITIMIZE_ADDRESS
203 #define TARGET_LEGITIMIZE_ADDRESS m68k_legitimize_address
205 #undef TARGET_SCHED_ADJUST_COST
206 #define TARGET_SCHED_ADJUST_COST m68k_sched_adjust_cost
208 #undef TARGET_SCHED_ISSUE_RATE
209 #define TARGET_SCHED_ISSUE_RATE m68k_sched_issue_rate
211 #undef TARGET_SCHED_VARIABLE_ISSUE
212 #define TARGET_SCHED_VARIABLE_ISSUE m68k_sched_variable_issue
214 #undef TARGET_SCHED_INIT_GLOBAL
215 #define TARGET_SCHED_INIT_GLOBAL m68k_sched_md_init_global
217 #undef TARGET_SCHED_FINISH_GLOBAL
218 #define TARGET_SCHED_FINISH_GLOBAL m68k_sched_md_finish_global
220 #undef TARGET_SCHED_INIT
221 #define TARGET_SCHED_INIT m68k_sched_md_init
223 #undef TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE
224 #define TARGET_SCHED_DFA_PRE_ADVANCE_CYCLE m68k_sched_dfa_pre_advance_cycle
226 #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE
227 #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE m68k_sched_dfa_post_advance_cycle
229 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
230 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
231 m68k_sched_first_cycle_multipass_dfa_lookahead
233 #undef TARGET_HANDLE_OPTION
234 #define TARGET_HANDLE_OPTION m68k_handle_option
236 #undef TARGET_RTX_COSTS
237 #define TARGET_RTX_COSTS m68k_rtx_costs
239 #undef TARGET_ATTRIBUTE_TABLE
240 #define TARGET_ATTRIBUTE_TABLE m68k_attribute_table
242 #undef TARGET_PROMOTE_PROTOTYPES
243 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
245 #undef TARGET_STRUCT_VALUE_RTX
246 #define TARGET_STRUCT_VALUE_RTX m68k_struct_value_rtx
248 #undef TARGET_CANNOT_FORCE_CONST_MEM
249 #define TARGET_CANNOT_FORCE_CONST_MEM m68k_illegitimate_symbolic_constant_p
251 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
252 #define TARGET_FUNCTION_OK_FOR_SIBCALL m68k_ok_for_sibcall_p
254 #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
255 #undef TARGET_RETURN_IN_MEMORY
256 #define TARGET_RETURN_IN_MEMORY m68k_return_in_memory
260 #undef TARGET_HAVE_TLS
261 #define TARGET_HAVE_TLS (true)
263 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
264 #define TARGET_ASM_OUTPUT_DWARF_DTPREL m68k_output_dwarf_dtprel
267 #undef TARGET_LEGITIMATE_ADDRESS_P
268 #define TARGET_LEGITIMATE_ADDRESS_P m68k_legitimate_address_p
270 #undef TARGET_CAN_ELIMINATE
271 #define TARGET_CAN_ELIMINATE m68k_can_eliminate
273 #undef TARGET_TRAMPOLINE_INIT
274 #define TARGET_TRAMPOLINE_INIT m68k_trampoline_init
276 #undef TARGET_RETURN_POPS_ARGS
277 #define TARGET_RETURN_POPS_ARGS m68k_return_pops_args
279 #undef TARGET_DELEGITIMIZE_ADDRESS
280 #define TARGET_DELEGITIMIZE_ADDRESS m68k_delegitimize_address
282 static const struct attribute_spec m68k_attribute_table
[] =
284 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
285 { "interrupt", 0, 0, true, false, false, m68k_handle_fndecl_attribute
},
286 { "interrupt_handler", 0, 0, true, false, false, m68k_handle_fndecl_attribute
},
287 { "interrupt_thread", 0, 0, true, false, false, m68k_handle_fndecl_attribute
},
288 { NULL
, 0, 0, false, false, false, NULL
}
291 struct gcc_target targetm
= TARGET_INITIALIZER
;
293 /* Base flags for 68k ISAs. */
294 #define FL_FOR_isa_00 FL_ISA_68000
295 #define FL_FOR_isa_10 (FL_FOR_isa_00 | FL_ISA_68010)
296 /* FL_68881 controls the default setting of -m68881. gcc has traditionally
297 generated 68881 code for 68020 and 68030 targets unless explicitly told
299 #define FL_FOR_isa_20 (FL_FOR_isa_10 | FL_ISA_68020 \
300 | FL_BITFIELD | FL_68881)
301 #define FL_FOR_isa_40 (FL_FOR_isa_20 | FL_ISA_68040)
302 #define FL_FOR_isa_cpu32 (FL_FOR_isa_10 | FL_ISA_68020)
304 /* Base flags for ColdFire ISAs. */
305 #define FL_FOR_isa_a (FL_COLDFIRE | FL_ISA_A)
306 #define FL_FOR_isa_aplus (FL_FOR_isa_a | FL_ISA_APLUS | FL_CF_USP)
307 /* Note ISA_B doesn't necessarily include USP (user stack pointer) support. */
308 #define FL_FOR_isa_b (FL_FOR_isa_a | FL_ISA_B | FL_CF_HWDIV)
309 /* ISA_C is not upwardly compatible with ISA_B. */
310 #define FL_FOR_isa_c (FL_FOR_isa_a | FL_ISA_C | FL_CF_USP)
314 /* Traditional 68000 instruction sets. */
320 /* ColdFire instruction set variants. */
328 /* Information about one of the -march, -mcpu or -mtune arguments. */
329 struct m68k_target_selection
331 /* The argument being described. */
334 /* For -mcpu, this is the device selected by the option.
335 For -mtune and -march, it is a representative device
336 for the microarchitecture or ISA respectively. */
337 enum target_device device
;
339 /* The M68K_DEVICE fields associated with DEVICE. See the comment
340 in m68k-devices.def for details. FAMILY is only valid for -mcpu. */
342 enum uarch_type microarch
;
347 /* A list of all devices in m68k-devices.def. Used for -mcpu selection. */
348 static const struct m68k_target_selection all_devices
[] =
350 #define M68K_DEVICE(NAME,ENUM_VALUE,FAMILY,MULTILIB,MICROARCH,ISA,FLAGS) \
351 { NAME, ENUM_VALUE, FAMILY, u##MICROARCH, ISA, FLAGS | FL_FOR_##ISA },
352 #include "m68k-devices.def"
354 { NULL
, unk_device
, NULL
, unk_arch
, isa_max
, 0 }
357 /* A list of all ISAs, mapping each one to a representative device.
358 Used for -march selection. */
359 static const struct m68k_target_selection all_isas
[] =
361 { "68000", m68000
, NULL
, u68000
, isa_00
, FL_FOR_isa_00
},
362 { "68010", m68010
, NULL
, u68010
, isa_10
, FL_FOR_isa_10
},
363 { "68020", m68020
, NULL
, u68020
, isa_20
, FL_FOR_isa_20
},
364 { "68030", m68030
, NULL
, u68030
, isa_20
, FL_FOR_isa_20
},
365 { "68040", m68040
, NULL
, u68040
, isa_40
, FL_FOR_isa_40
},
366 { "68060", m68060
, NULL
, u68060
, isa_40
, FL_FOR_isa_40
},
367 { "cpu32", cpu32
, NULL
, ucpu32
, isa_20
, FL_FOR_isa_cpu32
},
368 { "isaa", mcf5206e
, NULL
, ucfv2
, isa_a
, (FL_FOR_isa_a
370 { "isaaplus", mcf5271
, NULL
, ucfv2
, isa_aplus
, (FL_FOR_isa_aplus
372 { "isab", mcf5407
, NULL
, ucfv4
, isa_b
, FL_FOR_isa_b
},
373 { "isac", unk_device
, NULL
, ucfv4
, isa_c
, (FL_FOR_isa_c
375 { NULL
, unk_device
, NULL
, unk_arch
, isa_max
, 0 }
378 /* A list of all microarchitectures, mapping each one to a representative
379 device. Used for -mtune selection. */
380 static const struct m68k_target_selection all_microarchs
[] =
382 { "68000", m68000
, NULL
, u68000
, isa_00
, FL_FOR_isa_00
},
383 { "68010", m68010
, NULL
, u68010
, isa_10
, FL_FOR_isa_10
},
384 { "68020", m68020
, NULL
, u68020
, isa_20
, FL_FOR_isa_20
},
385 { "68020-40", m68020
, NULL
, u68020_40
, isa_20
, FL_FOR_isa_20
},
386 { "68020-60", m68020
, NULL
, u68020_60
, isa_20
, FL_FOR_isa_20
},
387 { "68030", m68030
, NULL
, u68030
, isa_20
, FL_FOR_isa_20
},
388 { "68040", m68040
, NULL
, u68040
, isa_40
, FL_FOR_isa_40
},
389 { "68060", m68060
, NULL
, u68060
, isa_40
, FL_FOR_isa_40
},
390 { "cpu32", cpu32
, NULL
, ucpu32
, isa_20
, FL_FOR_isa_cpu32
},
391 { "cfv1", mcf51qe
, NULL
, ucfv1
, isa_c
, FL_FOR_isa_c
},
392 { "cfv2", mcf5206
, NULL
, ucfv2
, isa_a
, FL_FOR_isa_a
},
393 { "cfv3", mcf5307
, NULL
, ucfv3
, isa_a
, (FL_FOR_isa_a
395 { "cfv4", mcf5407
, NULL
, ucfv4
, isa_b
, FL_FOR_isa_b
},
396 { "cfv4e", mcf547x
, NULL
, ucfv4e
, isa_b
, (FL_FOR_isa_b
400 { NULL
, unk_device
, NULL
, unk_arch
, isa_max
, 0 }
403 /* The entries associated with the -mcpu, -march and -mtune settings,
404 or null for options that have not been used. */
405 const struct m68k_target_selection
*m68k_cpu_entry
;
406 const struct m68k_target_selection
*m68k_arch_entry
;
407 const struct m68k_target_selection
*m68k_tune_entry
;
409 /* Which CPU we are generating code for. */
410 enum target_device m68k_cpu
;
412 /* Which microarchitecture to tune for. */
413 enum uarch_type m68k_tune
;
415 /* Which FPU to use. */
416 enum fpu_type m68k_fpu
;
418 /* The set of FL_* flags that apply to the target processor. */
419 unsigned int m68k_cpu_flags
;
421 /* The set of FL_* flags that apply to the processor to be tuned for. */
422 unsigned int m68k_tune_flags
;
424 /* Asm templates for calling or jumping to an arbitrary symbolic address,
425 or NULL if such calls or jumps are not supported. The address is held
427 const char *m68k_symbolic_call
;
428 const char *m68k_symbolic_jump
;
430 /* Enum variable that corresponds to m68k_symbolic_call values. */
431 enum M68K_SYMBOLIC_CALL m68k_symbolic_call_var
;
434 /* See whether TABLE has an entry with name NAME. Return true and
435 store the entry in *ENTRY if so, otherwise return false and
436 leave *ENTRY alone. */
439 m68k_find_selection (const struct m68k_target_selection
**entry
,
440 const struct m68k_target_selection
*table
,
445 for (i
= 0; table
[i
].name
; i
++)
446 if (strcmp (table
[i
].name
, name
) == 0)
454 /* Implement TARGET_HANDLE_OPTION. */
457 m68k_handle_option (size_t code
, const char *arg
, int value
)
462 return m68k_find_selection (&m68k_arch_entry
, all_isas
, arg
);
465 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, arg
);
468 return m68k_find_selection (&m68k_tune_entry
, all_microarchs
, arg
);
471 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "5206");
474 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "5206e");
477 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "528x");
480 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "5307");
483 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "5407");
486 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "547x");
490 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68000");
493 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68010");
497 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68020");
500 return (m68k_find_selection (&m68k_tune_entry
, all_microarchs
,
502 && m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68020"));
505 return (m68k_find_selection (&m68k_tune_entry
, all_microarchs
,
507 && m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68020"));
510 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68030");
513 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68040");
516 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68060");
519 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68302");
523 return m68k_find_selection (&m68k_cpu_entry
, all_devices
, "68332");
525 case OPT_mshared_library_id_
:
526 if (value
> MAX_LIBRARY_ID
)
527 error ("-mshared-library-id=%s is not between 0 and %d",
528 arg
, MAX_LIBRARY_ID
);
532 asprintf (&tmp
, "%d", (value
* -4) - 4);
533 m68k_library_id_string
= tmp
;
542 /* Sometimes certain combinations of command options do not make
543 sense on a particular target machine. You can define a macro
544 `OVERRIDE_OPTIONS' to take account of this. This macro, if
545 defined, is executed once just after all the command options have
548 Don't use this macro to turn on various extra optimizations for
549 `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */
552 override_options (void)
554 const struct m68k_target_selection
*entry
;
555 unsigned long target_mask
;
563 -march=ARCH should generate code that runs any processor
564 implementing architecture ARCH. -mcpu=CPU should override -march
565 and should generate code that runs on processor CPU, making free
566 use of any instructions that CPU understands. -mtune=UARCH applies
567 on top of -mcpu or -march and optimizes the code for UARCH. It does
568 not change the target architecture. */
571 /* Complain if the -march setting is for a different microarchitecture,
572 or includes flags that the -mcpu setting doesn't. */
574 && (m68k_arch_entry
->microarch
!= m68k_cpu_entry
->microarch
575 || (m68k_arch_entry
->flags
& ~m68k_cpu_entry
->flags
) != 0))
576 warning (0, "-mcpu=%s conflicts with -march=%s",
577 m68k_cpu_entry
->name
, m68k_arch_entry
->name
);
579 entry
= m68k_cpu_entry
;
582 entry
= m68k_arch_entry
;
585 entry
= all_devices
+ TARGET_CPU_DEFAULT
;
587 m68k_cpu_flags
= entry
->flags
;
589 /* Use the architecture setting to derive default values for
593 /* ColdFire is lenient about alignment. */
594 if (!TARGET_COLDFIRE
)
595 target_mask
|= MASK_STRICT_ALIGNMENT
;
597 if ((m68k_cpu_flags
& FL_BITFIELD
) != 0)
598 target_mask
|= MASK_BITFIELD
;
599 if ((m68k_cpu_flags
& FL_CF_HWDIV
) != 0)
600 target_mask
|= MASK_CF_HWDIV
;
601 if ((m68k_cpu_flags
& (FL_68881
| FL_CF_FPU
)) != 0)
602 target_mask
|= MASK_HARD_FLOAT
;
603 target_flags
|= target_mask
& ~target_flags_explicit
;
605 /* Set the directly-usable versions of the -mcpu and -mtune settings. */
606 m68k_cpu
= entry
->device
;
609 m68k_tune
= m68k_tune_entry
->microarch
;
610 m68k_tune_flags
= m68k_tune_entry
->flags
;
612 #ifdef M68K_DEFAULT_TUNE
613 else if (!m68k_cpu_entry
&& !m68k_arch_entry
)
615 enum target_device dev
;
616 dev
= all_microarchs
[M68K_DEFAULT_TUNE
].device
;
617 m68k_tune_flags
= all_devices
[dev
]->flags
;
622 m68k_tune
= entry
->microarch
;
623 m68k_tune_flags
= entry
->flags
;
626 /* Set the type of FPU. */
627 m68k_fpu
= (!TARGET_HARD_FLOAT
? FPUTYPE_NONE
628 : (m68k_cpu_flags
& FL_COLDFIRE
) != 0 ? FPUTYPE_COLDFIRE
631 /* Sanity check to ensure that msep-data and mid-sahred-library are not
632 * both specified together. Doing so simply doesn't make sense.
634 if (TARGET_SEP_DATA
&& TARGET_ID_SHARED_LIBRARY
)
635 error ("cannot specify both -msep-data and -mid-shared-library");
637 /* If we're generating code for a separate A5 relative data segment,
638 * we've got to enable -fPIC as well. This might be relaxable to
639 * -fpic but it hasn't been tested properly.
641 if (TARGET_SEP_DATA
|| TARGET_ID_SHARED_LIBRARY
)
644 /* -mpcrel -fPIC uses 32-bit pc-relative displacements. Raise an
645 error if the target does not support them. */
646 if (TARGET_PCREL
&& !TARGET_68020
&& flag_pic
== 2)
647 error ("-mpcrel -fPIC is not currently supported on selected cpu");
649 /* ??? A historic way of turning on pic, or is this intended to
650 be an embedded thing that doesn't have the same name binding
651 significance that it does on hosted ELF systems? */
652 if (TARGET_PCREL
&& flag_pic
== 0)
657 m68k_symbolic_call_var
= M68K_SYMBOLIC_CALL_JSR
;
659 m68k_symbolic_jump
= "jra %a0";
661 else if (TARGET_ID_SHARED_LIBRARY
)
662 /* All addresses must be loaded from the GOT. */
664 else if (TARGET_68020
|| TARGET_ISAB
|| TARGET_ISAC
)
667 m68k_symbolic_call_var
= M68K_SYMBOLIC_CALL_BSR_C
;
669 m68k_symbolic_call_var
= M68K_SYMBOLIC_CALL_BSR_P
;
672 /* No unconditional long branch */;
673 else if (TARGET_PCREL
)
674 m68k_symbolic_jump
= "bra%.l %c0";
676 m68k_symbolic_jump
= "bra%.l %p0";
677 /* Turn off function cse if we are doing PIC. We always want
678 function call to be done as `bsr foo@PLTPC'. */
679 /* ??? It's traditional to do this for -mpcrel too, but it isn't
680 clear how intentional that is. */
681 flag_no_function_cse
= 1;
684 switch (m68k_symbolic_call_var
)
686 case M68K_SYMBOLIC_CALL_JSR
:
687 m68k_symbolic_call
= "jsr %a0";
690 case M68K_SYMBOLIC_CALL_BSR_C
:
691 m68k_symbolic_call
= "bsr%.l %c0";
694 case M68K_SYMBOLIC_CALL_BSR_P
:
695 m68k_symbolic_call
= "bsr%.l %p0";
698 case M68K_SYMBOLIC_CALL_NONE
:
699 gcc_assert (m68k_symbolic_call
== NULL
);
706 #ifndef ASM_OUTPUT_ALIGN_WITH_NOP
707 if (align_labels
> 2)
709 warning (0, "-falign-labels=%d is not supported", align_labels
);
714 warning (0, "-falign-loops=%d is not supported", align_loops
);
719 SUBTARGET_OVERRIDE_OPTIONS
;
721 /* Setup scheduling options. */
723 m68k_sched_cpu
= CPU_CFV1
;
725 m68k_sched_cpu
= CPU_CFV2
;
727 m68k_sched_cpu
= CPU_CFV3
;
729 m68k_sched_cpu
= CPU_CFV4
;
732 m68k_sched_cpu
= CPU_UNKNOWN
;
733 flag_schedule_insns
= 0;
734 flag_schedule_insns_after_reload
= 0;
735 flag_modulo_sched
= 0;
738 if (m68k_sched_cpu
!= CPU_UNKNOWN
)
740 if ((m68k_cpu_flags
& (FL_CF_EMAC
| FL_CF_EMAC_B
)) != 0)
741 m68k_sched_mac
= MAC_CF_EMAC
;
742 else if ((m68k_cpu_flags
& FL_CF_MAC
) != 0)
743 m68k_sched_mac
= MAC_CF_MAC
;
745 m68k_sched_mac
= MAC_NO
;
749 /* Generate a macro of the form __mPREFIX_cpu_NAME, where PREFIX is the
750 given argument and NAME is the argument passed to -mcpu. Return NULL
751 if -mcpu was not passed. */
754 m68k_cpp_cpu_ident (const char *prefix
)
758 return concat ("__m", prefix
, "_cpu_", m68k_cpu_entry
->name
, NULL
);
761 /* Generate a macro of the form __mPREFIX_family_NAME, where PREFIX is the
762 given argument and NAME is the name of the representative device for
763 the -mcpu argument's family. Return NULL if -mcpu was not passed. */
766 m68k_cpp_cpu_family (const char *prefix
)
770 return concat ("__m", prefix
, "_family_", m68k_cpu_entry
->family
, NULL
);
773 /* Return m68k_fk_interrupt_handler if FUNC has an "interrupt" or
774 "interrupt_handler" attribute and interrupt_thread if FUNC has an
775 "interrupt_thread" attribute. Otherwise, return
776 m68k_fk_normal_function. */
778 enum m68k_function_kind
779 m68k_get_function_kind (tree func
)
783 gcc_assert (TREE_CODE (func
) == FUNCTION_DECL
);
785 a
= lookup_attribute ("interrupt", DECL_ATTRIBUTES (func
));
787 return m68k_fk_interrupt_handler
;
789 a
= lookup_attribute ("interrupt_handler", DECL_ATTRIBUTES (func
));
791 return m68k_fk_interrupt_handler
;
793 a
= lookup_attribute ("interrupt_thread", DECL_ATTRIBUTES (func
));
795 return m68k_fk_interrupt_thread
;
797 return m68k_fk_normal_function
;
800 /* Handle an attribute requiring a FUNCTION_DECL; arguments as in
801 struct attribute_spec.handler. */
803 m68k_handle_fndecl_attribute (tree
*node
, tree name
,
804 tree args ATTRIBUTE_UNUSED
,
805 int flags ATTRIBUTE_UNUSED
,
808 if (TREE_CODE (*node
) != FUNCTION_DECL
)
810 warning (OPT_Wattributes
, "%qE attribute only applies to functions",
812 *no_add_attrs
= true;
815 if (m68k_get_function_kind (*node
) != m68k_fk_normal_function
)
817 error ("multiple interrupt attributes not allowed");
818 *no_add_attrs
= true;
822 && !strcmp (IDENTIFIER_POINTER (name
), "interrupt_thread"))
824 error ("interrupt_thread is available only on fido");
825 *no_add_attrs
= true;
832 m68k_compute_frame_layout (void)
836 enum m68k_function_kind func_kind
=
837 m68k_get_function_kind (current_function_decl
);
838 bool interrupt_handler
= func_kind
== m68k_fk_interrupt_handler
;
839 bool interrupt_thread
= func_kind
== m68k_fk_interrupt_thread
;
841 /* Only compute the frame once per function.
842 Don't cache information until reload has been completed. */
843 if (current_frame
.funcdef_no
== current_function_funcdef_no
847 current_frame
.size
= (get_frame_size () + 3) & -4;
851 /* Interrupt thread does not need to save any register. */
852 if (!interrupt_thread
)
853 for (regno
= 0; regno
< 16; regno
++)
854 if (m68k_save_reg (regno
, interrupt_handler
))
856 mask
|= 1 << (regno
- D0_REG
);
859 current_frame
.offset
= saved
* 4;
860 current_frame
.reg_no
= saved
;
861 current_frame
.reg_mask
= mask
;
863 current_frame
.foffset
= 0;
865 if (TARGET_HARD_FLOAT
)
867 /* Interrupt thread does not need to save any register. */
868 if (!interrupt_thread
)
869 for (regno
= 16; regno
< 24; regno
++)
870 if (m68k_save_reg (regno
, interrupt_handler
))
872 mask
|= 1 << (regno
- FP0_REG
);
875 current_frame
.foffset
= saved
* TARGET_FP_REG_SIZE
;
876 current_frame
.offset
+= current_frame
.foffset
;
878 current_frame
.fpu_no
= saved
;
879 current_frame
.fpu_mask
= mask
;
881 /* Remember what function this frame refers to. */
882 current_frame
.funcdef_no
= current_function_funcdef_no
;
885 /* Worker function for TARGET_CAN_ELIMINATE. */
888 m68k_can_eliminate (const int from ATTRIBUTE_UNUSED
, const int to
)
890 return (to
== STACK_POINTER_REGNUM
? ! frame_pointer_needed
: true);
894 m68k_initial_elimination_offset (int from
, int to
)
897 /* The arg pointer points 8 bytes before the start of the arguments,
898 as defined by FIRST_PARM_OFFSET. This makes it coincident with the
899 frame pointer in most frames. */
900 argptr_offset
= frame_pointer_needed
? 0 : UNITS_PER_WORD
;
901 if (from
== ARG_POINTER_REGNUM
&& to
== FRAME_POINTER_REGNUM
)
902 return argptr_offset
;
904 m68k_compute_frame_layout ();
906 gcc_assert (to
== STACK_POINTER_REGNUM
);
909 case ARG_POINTER_REGNUM
:
910 return current_frame
.offset
+ current_frame
.size
- argptr_offset
;
911 case FRAME_POINTER_REGNUM
:
912 return current_frame
.offset
+ current_frame
.size
;
918 /* Refer to the array `regs_ever_live' to determine which registers
919 to save; `regs_ever_live[I]' is nonzero if register number I
920 is ever used in the function. This function is responsible for
921 knowing which registers should not be saved even if used.
922 Return true if we need to save REGNO. */
925 m68k_save_reg (unsigned int regno
, bool interrupt_handler
)
927 if (flag_pic
&& regno
== PIC_REG
)
929 if (crtl
->saves_all_registers
)
931 if (crtl
->uses_pic_offset_table
)
933 /* Reload may introduce constant pool references into a function
934 that thitherto didn't need a PIC register. Note that the test
935 above will not catch that case because we will only set
936 crtl->uses_pic_offset_table when emitting
937 the address reloads. */
938 if (crtl
->uses_const_pool
)
942 if (crtl
->calls_eh_return
)
947 unsigned int test
= EH_RETURN_DATA_REGNO (i
);
948 if (test
== INVALID_REGNUM
)
955 /* Fixed regs we never touch. */
956 if (fixed_regs
[regno
])
959 /* The frame pointer (if it is such) is handled specially. */
960 if (regno
== FRAME_POINTER_REGNUM
&& frame_pointer_needed
)
963 /* Interrupt handlers must also save call_used_regs
964 if they are live or when calling nested functions. */
965 if (interrupt_handler
)
967 if (df_regs_ever_live_p (regno
))
970 if (!current_function_is_leaf
&& call_used_regs
[regno
])
974 /* Never need to save registers that aren't touched. */
975 if (!df_regs_ever_live_p (regno
))
978 /* Otherwise save everything that isn't call-clobbered. */
979 return !call_used_regs
[regno
];
982 /* Emit RTL for a MOVEM or FMOVEM instruction. BASE + OFFSET represents
983 the lowest memory address. COUNT is the number of registers to be
984 moved, with register REGNO + I being moved if bit I of MASK is set.
985 STORE_P specifies the direction of the move and ADJUST_STACK_P says
986 whether or not this is pre-decrement (if STORE_P) or post-increment
987 (if !STORE_P) operation. */
990 m68k_emit_movem (rtx base
, HOST_WIDE_INT offset
,
991 unsigned int count
, unsigned int regno
,
992 unsigned int mask
, bool store_p
, bool adjust_stack_p
)
995 rtx body
, addr
, src
, operands
[2];
996 enum machine_mode mode
;
998 body
= gen_rtx_PARALLEL (VOIDmode
, rtvec_alloc (adjust_stack_p
+ count
));
999 mode
= reg_raw_mode
[regno
];
1004 src
= plus_constant (base
, (count
1005 * GET_MODE_SIZE (mode
)
1006 * (HOST_WIDE_INT
) (store_p
? -1 : 1)));
1007 XVECEXP (body
, 0, i
++) = gen_rtx_SET (VOIDmode
, base
, src
);
1010 for (; mask
!= 0; mask
>>= 1, regno
++)
1013 addr
= plus_constant (base
, offset
);
1014 operands
[!store_p
] = gen_frame_mem (mode
, addr
);
1015 operands
[store_p
] = gen_rtx_REG (mode
, regno
);
1016 XVECEXP (body
, 0, i
++)
1017 = gen_rtx_SET (VOIDmode
, operands
[0], operands
[1]);
1018 offset
+= GET_MODE_SIZE (mode
);
1020 gcc_assert (i
== XVECLEN (body
, 0));
1022 return emit_insn (body
);
1025 /* Make INSN a frame-related instruction. */
1028 m68k_set_frame_related (rtx insn
)
1033 RTX_FRAME_RELATED_P (insn
) = 1;
1034 body
= PATTERN (insn
);
1035 if (GET_CODE (body
) == PARALLEL
)
1036 for (i
= 0; i
< XVECLEN (body
, 0); i
++)
1037 RTX_FRAME_RELATED_P (XVECEXP (body
, 0, i
)) = 1;
1040 /* Emit RTL for the "prologue" define_expand. */
1043 m68k_expand_prologue (void)
1045 HOST_WIDE_INT fsize_with_regs
;
1046 rtx limit
, src
, dest
;
1048 m68k_compute_frame_layout ();
1050 /* If the stack limit is a symbol, we can check it here,
1051 before actually allocating the space. */
1052 if (crtl
->limit_stack
1053 && GET_CODE (stack_limit_rtx
) == SYMBOL_REF
)
1055 limit
= plus_constant (stack_limit_rtx
, current_frame
.size
+ 4);
1056 if (!LEGITIMATE_CONSTANT_P (limit
))
1058 emit_move_insn (gen_rtx_REG (Pmode
, D0_REG
), limit
);
1059 limit
= gen_rtx_REG (Pmode
, D0_REG
);
1061 emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode
,
1062 stack_pointer_rtx
, limit
),
1063 stack_pointer_rtx
, limit
,
1067 fsize_with_regs
= current_frame
.size
;
1068 if (TARGET_COLDFIRE
)
1070 /* ColdFire's move multiple instructions do not allow pre-decrement
1071 addressing. Add the size of movem saves to the initial stack
1072 allocation instead. */
1073 if (current_frame
.reg_no
>= MIN_MOVEM_REGS
)
1074 fsize_with_regs
+= current_frame
.reg_no
* GET_MODE_SIZE (SImode
);
1075 if (current_frame
.fpu_no
>= MIN_FMOVEM_REGS
)
1076 fsize_with_regs
+= current_frame
.fpu_no
* GET_MODE_SIZE (DFmode
);
1079 if (frame_pointer_needed
)
1081 if (fsize_with_regs
== 0 && TUNE_68040
)
1083 /* On the 68040, two separate moves are faster than link.w 0. */
1084 dest
= gen_frame_mem (Pmode
,
1085 gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
));
1086 m68k_set_frame_related (emit_move_insn (dest
, frame_pointer_rtx
));
1087 m68k_set_frame_related (emit_move_insn (frame_pointer_rtx
,
1088 stack_pointer_rtx
));
1090 else if (fsize_with_regs
< 0x8000 || TARGET_68020
)
1091 m68k_set_frame_related
1092 (emit_insn (gen_link (frame_pointer_rtx
,
1093 GEN_INT (-4 - fsize_with_regs
))));
1096 m68k_set_frame_related
1097 (emit_insn (gen_link (frame_pointer_rtx
, GEN_INT (-4))));
1098 m68k_set_frame_related
1099 (emit_insn (gen_addsi3 (stack_pointer_rtx
,
1101 GEN_INT (-fsize_with_regs
))));
1104 /* If the frame pointer is needed, emit a special barrier that
1105 will prevent the scheduler from moving stores to the frame
1106 before the stack adjustment. */
1107 emit_insn (gen_stack_tie (stack_pointer_rtx
, frame_pointer_rtx
));
1109 else if (fsize_with_regs
!= 0)
1110 m68k_set_frame_related
1111 (emit_insn (gen_addsi3 (stack_pointer_rtx
,
1113 GEN_INT (-fsize_with_regs
))));
1115 if (current_frame
.fpu_mask
)
1117 gcc_assert (current_frame
.fpu_no
>= MIN_FMOVEM_REGS
);
1119 m68k_set_frame_related
1120 (m68k_emit_movem (stack_pointer_rtx
,
1121 current_frame
.fpu_no
* -GET_MODE_SIZE (XFmode
),
1122 current_frame
.fpu_no
, FP0_REG
,
1123 current_frame
.fpu_mask
, true, true));
1128 /* If we're using moveml to save the integer registers,
1129 the stack pointer will point to the bottom of the moveml
1130 save area. Find the stack offset of the first FP register. */
1131 if (current_frame
.reg_no
< MIN_MOVEM_REGS
)
1134 offset
= current_frame
.reg_no
* GET_MODE_SIZE (SImode
);
1135 m68k_set_frame_related
1136 (m68k_emit_movem (stack_pointer_rtx
, offset
,
1137 current_frame
.fpu_no
, FP0_REG
,
1138 current_frame
.fpu_mask
, true, false));
1142 /* If the stack limit is not a symbol, check it here.
1143 This has the disadvantage that it may be too late... */
1144 if (crtl
->limit_stack
)
1146 if (REG_P (stack_limit_rtx
))
1147 emit_insn (gen_ctrapsi4 (gen_rtx_LTU (VOIDmode
, stack_pointer_rtx
,
1149 stack_pointer_rtx
, stack_limit_rtx
,
1152 else if (GET_CODE (stack_limit_rtx
) != SYMBOL_REF
)
1153 warning (0, "stack limit expression is not supported");
1156 if (current_frame
.reg_no
< MIN_MOVEM_REGS
)
1158 /* Store each register separately in the same order moveml does. */
1161 for (i
= 16; i
-- > 0; )
1162 if (current_frame
.reg_mask
& (1 << i
))
1164 src
= gen_rtx_REG (SImode
, D0_REG
+ i
);
1165 dest
= gen_frame_mem (SImode
,
1166 gen_rtx_PRE_DEC (Pmode
, stack_pointer_rtx
));
1167 m68k_set_frame_related (emit_insn (gen_movsi (dest
, src
)));
1172 if (TARGET_COLDFIRE
)
1173 /* The required register save space has already been allocated.
1174 The first register should be stored at (%sp). */
1175 m68k_set_frame_related
1176 (m68k_emit_movem (stack_pointer_rtx
, 0,
1177 current_frame
.reg_no
, D0_REG
,
1178 current_frame
.reg_mask
, true, false));
1180 m68k_set_frame_related
1181 (m68k_emit_movem (stack_pointer_rtx
,
1182 current_frame
.reg_no
* -GET_MODE_SIZE (SImode
),
1183 current_frame
.reg_no
, D0_REG
,
1184 current_frame
.reg_mask
, true, true));
1187 if (!TARGET_SEP_DATA
1188 && crtl
->uses_pic_offset_table
)
1189 emit_insn (gen_load_got (pic_offset_table_rtx
));
1192 /* Return true if a simple (return) instruction is sufficient for this
1193 instruction (i.e. if no epilogue is needed). */
1196 m68k_use_return_insn (void)
1198 if (!reload_completed
|| frame_pointer_needed
|| get_frame_size () != 0)
1201 m68k_compute_frame_layout ();
1202 return current_frame
.offset
== 0;
1205 /* Emit RTL for the "epilogue" or "sibcall_epilogue" define_expand;
1206 SIBCALL_P says which.
1208 The function epilogue should not depend on the current stack pointer!
1209 It should use the frame pointer only, if there is a frame pointer.
1210 This is mandatory because of alloca; we also take advantage of it to
1211 omit stack adjustments before returning. */
1214 m68k_expand_epilogue (bool sibcall_p
)
1216 HOST_WIDE_INT fsize
, fsize_with_regs
;
1217 bool big
, restore_from_sp
;
1219 m68k_compute_frame_layout ();
1221 fsize
= current_frame
.size
;
1223 restore_from_sp
= false;
1225 /* FIXME : current_function_is_leaf below is too strong.
1226 What we really need to know there is if there could be pending
1227 stack adjustment needed at that point. */
1228 restore_from_sp
= (!frame_pointer_needed
1229 || (!cfun
->calls_alloca
1230 && current_function_is_leaf
));
1232 /* fsize_with_regs is the size we need to adjust the sp when
1233 popping the frame. */
1234 fsize_with_regs
= fsize
;
1235 if (TARGET_COLDFIRE
&& restore_from_sp
)
1237 /* ColdFire's move multiple instructions do not allow post-increment
1238 addressing. Add the size of movem loads to the final deallocation
1240 if (current_frame
.reg_no
>= MIN_MOVEM_REGS
)
1241 fsize_with_regs
+= current_frame
.reg_no
* GET_MODE_SIZE (SImode
);
1242 if (current_frame
.fpu_no
>= MIN_FMOVEM_REGS
)
1243 fsize_with_regs
+= current_frame
.fpu_no
* GET_MODE_SIZE (DFmode
);
1246 if (current_frame
.offset
+ fsize
>= 0x8000
1248 && (current_frame
.reg_mask
|| current_frame
.fpu_mask
))
1251 && (current_frame
.reg_no
>= MIN_MOVEM_REGS
1252 || current_frame
.fpu_no
>= MIN_FMOVEM_REGS
))
1254 /* ColdFire's move multiple instructions do not support the
1255 (d8,Ax,Xi) addressing mode, so we're as well using a normal
1256 stack-based restore. */
1257 emit_move_insn (gen_rtx_REG (Pmode
, A1_REG
),
1258 GEN_INT (-(current_frame
.offset
+ fsize
)));
1259 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1260 gen_rtx_REG (Pmode
, A1_REG
),
1261 frame_pointer_rtx
));
1262 restore_from_sp
= true;
1266 emit_move_insn (gen_rtx_REG (Pmode
, A1_REG
), GEN_INT (-fsize
));
1272 if (current_frame
.reg_no
< MIN_MOVEM_REGS
)
1274 /* Restore each register separately in the same order moveml does. */
1276 HOST_WIDE_INT offset
;
1278 offset
= current_frame
.offset
+ fsize
;
1279 for (i
= 0; i
< 16; i
++)
1280 if (current_frame
.reg_mask
& (1 << i
))
1286 /* Generate the address -OFFSET(%fp,%a1.l). */
1287 addr
= gen_rtx_REG (Pmode
, A1_REG
);
1288 addr
= gen_rtx_PLUS (Pmode
, addr
, frame_pointer_rtx
);
1289 addr
= plus_constant (addr
, -offset
);
1291 else if (restore_from_sp
)
1292 addr
= gen_rtx_POST_INC (Pmode
, stack_pointer_rtx
);
1294 addr
= plus_constant (frame_pointer_rtx
, -offset
);
1295 emit_move_insn (gen_rtx_REG (SImode
, D0_REG
+ i
),
1296 gen_frame_mem (SImode
, addr
));
1297 offset
-= GET_MODE_SIZE (SImode
);
1300 else if (current_frame
.reg_mask
)
1303 m68k_emit_movem (gen_rtx_PLUS (Pmode
,
1304 gen_rtx_REG (Pmode
, A1_REG
),
1306 -(current_frame
.offset
+ fsize
),
1307 current_frame
.reg_no
, D0_REG
,
1308 current_frame
.reg_mask
, false, false);
1309 else if (restore_from_sp
)
1310 m68k_emit_movem (stack_pointer_rtx
, 0,
1311 current_frame
.reg_no
, D0_REG
,
1312 current_frame
.reg_mask
, false,
1315 m68k_emit_movem (frame_pointer_rtx
,
1316 -(current_frame
.offset
+ fsize
),
1317 current_frame
.reg_no
, D0_REG
,
1318 current_frame
.reg_mask
, false, false);
1321 if (current_frame
.fpu_no
> 0)
1324 m68k_emit_movem (gen_rtx_PLUS (Pmode
,
1325 gen_rtx_REG (Pmode
, A1_REG
),
1327 -(current_frame
.foffset
+ fsize
),
1328 current_frame
.fpu_no
, FP0_REG
,
1329 current_frame
.fpu_mask
, false, false);
1330 else if (restore_from_sp
)
1332 if (TARGET_COLDFIRE
)
1336 /* If we used moveml to restore the integer registers, the
1337 stack pointer will still point to the bottom of the moveml
1338 save area. Find the stack offset of the first FP
1340 if (current_frame
.reg_no
< MIN_MOVEM_REGS
)
1343 offset
= current_frame
.reg_no
* GET_MODE_SIZE (SImode
);
1344 m68k_emit_movem (stack_pointer_rtx
, offset
,
1345 current_frame
.fpu_no
, FP0_REG
,
1346 current_frame
.fpu_mask
, false, false);
1349 m68k_emit_movem (stack_pointer_rtx
, 0,
1350 current_frame
.fpu_no
, FP0_REG
,
1351 current_frame
.fpu_mask
, false, true);
1354 m68k_emit_movem (frame_pointer_rtx
,
1355 -(current_frame
.foffset
+ fsize
),
1356 current_frame
.fpu_no
, FP0_REG
,
1357 current_frame
.fpu_mask
, false, false);
1360 if (frame_pointer_needed
)
1361 emit_insn (gen_unlink (frame_pointer_rtx
));
1362 else if (fsize_with_regs
)
1363 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1365 GEN_INT (fsize_with_regs
)));
1367 if (crtl
->calls_eh_return
)
1368 emit_insn (gen_addsi3 (stack_pointer_rtx
,
1370 EH_RETURN_STACKADJ_RTX
));
1373 emit_jump_insn (gen_rtx_RETURN (VOIDmode
));
1376 /* Return true if X is a valid comparison operator for the dbcc
1379 Note it rejects floating point comparison operators.
1380 (In the future we could use Fdbcc).
1382 It also rejects some comparisons when CC_NO_OVERFLOW is set. */
1385 valid_dbcc_comparison_p_2 (rtx x
, enum machine_mode mode ATTRIBUTE_UNUSED
)
1387 switch (GET_CODE (x
))
1389 case EQ
: case NE
: case GTU
: case LTU
:
1393 /* Reject some when CC_NO_OVERFLOW is set. This may be over
1395 case GT
: case LT
: case GE
: case LE
:
1396 return ! (cc_prev_status
.flags
& CC_NO_OVERFLOW
);
1402 /* Return nonzero if flags are currently in the 68881 flag register. */
1404 flags_in_68881 (void)
1406 /* We could add support for these in the future */
1407 return cc_status
.flags
& CC_IN_68881
;
1410 /* Return true if PARALLEL contains register REGNO. */
1412 m68k_reg_present_p (const_rtx parallel
, unsigned int regno
)
1416 if (REG_P (parallel
) && REGNO (parallel
) == regno
)
1419 if (GET_CODE (parallel
) != PARALLEL
)
1422 for (i
= 0; i
< XVECLEN (parallel
, 0); ++i
)
1426 x
= XEXP (XVECEXP (parallel
, 0, i
), 0);
1427 if (REG_P (x
) && REGNO (x
) == regno
)
1434 /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL_P. */
1437 m68k_ok_for_sibcall_p (tree decl
, tree exp
)
1439 enum m68k_function_kind kind
;
1441 /* We cannot use sibcalls for nested functions because we use the
1442 static chain register for indirect calls. */
1443 if (CALL_EXPR_STATIC_CHAIN (exp
))
1446 if (!VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun
->decl
))))
1448 /* Check that the return value locations are the same. For
1449 example that we aren't returning a value from the sibling in
1450 a D0 register but then need to transfer it to a A0 register. */
1454 cfun_value
= FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (cfun
->decl
)),
1456 call_value
= FUNCTION_VALUE (TREE_TYPE (exp
), decl
);
1458 /* Check that the values are equal or that the result the callee
1459 function returns is superset of what the current function returns. */
1460 if (!(rtx_equal_p (cfun_value
, call_value
)
1461 || (REG_P (cfun_value
)
1462 && m68k_reg_present_p (call_value
, REGNO (cfun_value
)))))
1466 kind
= m68k_get_function_kind (current_function_decl
);
1467 if (kind
== m68k_fk_normal_function
)
1468 /* We can always sibcall from a normal function, because it's
1469 undefined if it is calling an interrupt function. */
1472 /* Otherwise we can only sibcall if the function kind is known to be
1474 if (decl
&& m68k_get_function_kind (decl
) == kind
)
1480 /* Convert X to a legitimate function call memory reference and return the
1484 m68k_legitimize_call_address (rtx x
)
1486 gcc_assert (MEM_P (x
));
1487 if (call_operand (XEXP (x
, 0), VOIDmode
))
1489 return replace_equiv_address (x
, force_reg (Pmode
, XEXP (x
, 0)));
1492 /* Likewise for sibling calls. */
1495 m68k_legitimize_sibcall_address (rtx x
)
1497 gcc_assert (MEM_P (x
));
1498 if (sibcall_operand (XEXP (x
, 0), VOIDmode
))
1501 emit_move_insn (gen_rtx_REG (Pmode
, STATIC_CHAIN_REGNUM
), XEXP (x
, 0));
1502 return replace_equiv_address (x
, gen_rtx_REG (Pmode
, STATIC_CHAIN_REGNUM
));
1505 /* Convert X to a legitimate address and return it if successful. Otherwise
1508 For the 68000, we handle X+REG by loading X into a register R and
1509 using R+REG. R will go in an address reg and indexing will be used.
1510 However, if REG is a broken-out memory address or multiplication,
1511 nothing needs to be done because REG can certainly go in an address reg. */
1514 m68k_legitimize_address (rtx x
, rtx oldx
, enum machine_mode mode
)
1516 if (m68k_tls_symbol_p (x
))
1517 return m68k_legitimize_tls_address (x
);
1519 if (GET_CODE (x
) == PLUS
)
1521 int ch
= (x
) != (oldx
);
1524 #define COPY_ONCE(Y) if (!copied) { Y = copy_rtx (Y); copied = ch = 1; }
1526 if (GET_CODE (XEXP (x
, 0)) == MULT
)
1529 XEXP (x
, 0) = force_operand (XEXP (x
, 0), 0);
1531 if (GET_CODE (XEXP (x
, 1)) == MULT
)
1534 XEXP (x
, 1) = force_operand (XEXP (x
, 1), 0);
1538 if (GET_CODE (XEXP (x
, 1)) == REG
1539 && GET_CODE (XEXP (x
, 0)) == REG
)
1541 if (TARGET_COLDFIRE_FPU
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
)
1544 x
= force_operand (x
, 0);
1548 if (memory_address_p (mode
, x
))
1551 if (GET_CODE (XEXP (x
, 0)) == REG
1552 || (GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
1553 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == REG
1554 && GET_MODE (XEXP (XEXP (x
, 0), 0)) == HImode
))
1556 rtx temp
= gen_reg_rtx (Pmode
);
1557 rtx val
= force_operand (XEXP (x
, 1), 0);
1558 emit_move_insn (temp
, val
);
1561 if (TARGET_COLDFIRE_FPU
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
1562 && GET_CODE (XEXP (x
, 0)) == REG
)
1563 x
= force_operand (x
, 0);
1565 else if (GET_CODE (XEXP (x
, 1)) == REG
1566 || (GET_CODE (XEXP (x
, 1)) == SIGN_EXTEND
1567 && GET_CODE (XEXP (XEXP (x
, 1), 0)) == REG
1568 && GET_MODE (XEXP (XEXP (x
, 1), 0)) == HImode
))
1570 rtx temp
= gen_reg_rtx (Pmode
);
1571 rtx val
= force_operand (XEXP (x
, 0), 0);
1572 emit_move_insn (temp
, val
);
1575 if (TARGET_COLDFIRE_FPU
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
1576 && GET_CODE (XEXP (x
, 1)) == REG
)
1577 x
= force_operand (x
, 0);
1585 /* Output a dbCC; jCC sequence. Note we do not handle the
1586 floating point version of this sequence (Fdbcc). We also
1587 do not handle alternative conditions when CC_NO_OVERFLOW is
1588 set. It is assumed that valid_dbcc_comparison_p and flags_in_68881 will
1589 kick those out before we get here. */
1592 output_dbcc_and_branch (rtx
*operands
)
1594 switch (GET_CODE (operands
[3]))
1597 output_asm_insn ("dbeq %0,%l1\n\tjeq %l2", operands
);
1601 output_asm_insn ("dbne %0,%l1\n\tjne %l2", operands
);
1605 output_asm_insn ("dbgt %0,%l1\n\tjgt %l2", operands
);
1609 output_asm_insn ("dbhi %0,%l1\n\tjhi %l2", operands
);
1613 output_asm_insn ("dblt %0,%l1\n\tjlt %l2", operands
);
1617 output_asm_insn ("dbcs %0,%l1\n\tjcs %l2", operands
);
1621 output_asm_insn ("dbge %0,%l1\n\tjge %l2", operands
);
1625 output_asm_insn ("dbcc %0,%l1\n\tjcc %l2", operands
);
1629 output_asm_insn ("dble %0,%l1\n\tjle %l2", operands
);
1633 output_asm_insn ("dbls %0,%l1\n\tjls %l2", operands
);
1640 /* If the decrement is to be done in SImode, then we have
1641 to compensate for the fact that dbcc decrements in HImode. */
1642 switch (GET_MODE (operands
[0]))
1645 output_asm_insn ("clr%.w %0\n\tsubq%.l #1,%0\n\tjpl %l1", operands
);
1657 output_scc_di (rtx op
, rtx operand1
, rtx operand2
, rtx dest
)
1660 enum rtx_code op_code
= GET_CODE (op
);
1662 /* This does not produce a useful cc. */
1665 /* The m68k cmp.l instruction requires operand1 to be a reg as used
1666 below. Swap the operands and change the op if these requirements
1667 are not fulfilled. */
1668 if (GET_CODE (operand2
) == REG
&& GET_CODE (operand1
) != REG
)
1672 operand1
= operand2
;
1674 op_code
= swap_condition (op_code
);
1676 loperands
[0] = operand1
;
1677 if (GET_CODE (operand1
) == REG
)
1678 loperands
[1] = gen_rtx_REG (SImode
, REGNO (operand1
) + 1);
1680 loperands
[1] = adjust_address (operand1
, SImode
, 4);
1681 if (operand2
!= const0_rtx
)
1683 loperands
[2] = operand2
;
1684 if (GET_CODE (operand2
) == REG
)
1685 loperands
[3] = gen_rtx_REG (SImode
, REGNO (operand2
) + 1);
1687 loperands
[3] = adjust_address (operand2
, SImode
, 4);
1689 loperands
[4] = gen_label_rtx ();
1690 if (operand2
!= const0_rtx
)
1691 output_asm_insn ("cmp%.l %2,%0\n\tjne %l4\n\tcmp%.l %3,%1", loperands
);
1694 if (TARGET_68020
|| TARGET_COLDFIRE
|| ! ADDRESS_REG_P (loperands
[0]))
1695 output_asm_insn ("tst%.l %0", loperands
);
1697 output_asm_insn ("cmp%.w #0,%0", loperands
);
1699 output_asm_insn ("jne %l4", loperands
);
1701 if (TARGET_68020
|| TARGET_COLDFIRE
|| ! ADDRESS_REG_P (loperands
[1]))
1702 output_asm_insn ("tst%.l %1", loperands
);
1704 output_asm_insn ("cmp%.w #0,%1", loperands
);
1707 loperands
[5] = dest
;
1712 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1713 CODE_LABEL_NUMBER (loperands
[4]));
1714 output_asm_insn ("seq %5", loperands
);
1718 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1719 CODE_LABEL_NUMBER (loperands
[4]));
1720 output_asm_insn ("sne %5", loperands
);
1724 loperands
[6] = gen_label_rtx ();
1725 output_asm_insn ("shi %5\n\tjra %l6", loperands
);
1726 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1727 CODE_LABEL_NUMBER (loperands
[4]));
1728 output_asm_insn ("sgt %5", loperands
);
1729 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1730 CODE_LABEL_NUMBER (loperands
[6]));
1734 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1735 CODE_LABEL_NUMBER (loperands
[4]));
1736 output_asm_insn ("shi %5", loperands
);
1740 loperands
[6] = gen_label_rtx ();
1741 output_asm_insn ("scs %5\n\tjra %l6", loperands
);
1742 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1743 CODE_LABEL_NUMBER (loperands
[4]));
1744 output_asm_insn ("slt %5", loperands
);
1745 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1746 CODE_LABEL_NUMBER (loperands
[6]));
1750 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1751 CODE_LABEL_NUMBER (loperands
[4]));
1752 output_asm_insn ("scs %5", loperands
);
1756 loperands
[6] = gen_label_rtx ();
1757 output_asm_insn ("scc %5\n\tjra %l6", loperands
);
1758 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1759 CODE_LABEL_NUMBER (loperands
[4]));
1760 output_asm_insn ("sge %5", loperands
);
1761 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1762 CODE_LABEL_NUMBER (loperands
[6]));
1766 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1767 CODE_LABEL_NUMBER (loperands
[4]));
1768 output_asm_insn ("scc %5", loperands
);
1772 loperands
[6] = gen_label_rtx ();
1773 output_asm_insn ("sls %5\n\tjra %l6", loperands
);
1774 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1775 CODE_LABEL_NUMBER (loperands
[4]));
1776 output_asm_insn ("sle %5", loperands
);
1777 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1778 CODE_LABEL_NUMBER (loperands
[6]));
1782 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "L",
1783 CODE_LABEL_NUMBER (loperands
[4]));
1784 output_asm_insn ("sls %5", loperands
);
1794 output_btst (rtx
*operands
, rtx countop
, rtx dataop
, rtx insn
, int signpos
)
1796 operands
[0] = countop
;
1797 operands
[1] = dataop
;
1799 if (GET_CODE (countop
) == CONST_INT
)
1801 register int count
= INTVAL (countop
);
1802 /* If COUNT is bigger than size of storage unit in use,
1803 advance to the containing unit of same size. */
1804 if (count
> signpos
)
1806 int offset
= (count
& ~signpos
) / 8;
1807 count
= count
& signpos
;
1808 operands
[1] = dataop
= adjust_address (dataop
, QImode
, offset
);
1810 if (count
== signpos
)
1811 cc_status
.flags
= CC_NOT_POSITIVE
| CC_Z_IN_NOT_N
;
1813 cc_status
.flags
= CC_NOT_NEGATIVE
| CC_Z_IN_NOT_N
;
1815 /* These three statements used to use next_insns_test_no...
1816 but it appears that this should do the same job. */
1818 && next_insn_tests_no_inequality (insn
))
1821 && next_insn_tests_no_inequality (insn
))
1824 && next_insn_tests_no_inequality (insn
))
1826 /* Try to use `movew to ccr' followed by the appropriate branch insn.
1827 On some m68k variants unfortunately that's slower than btst.
1828 On 68000 and higher, that should also work for all HImode operands. */
1829 if (TUNE_CPU32
|| TARGET_COLDFIRE
|| optimize_size
)
1831 if (count
== 3 && DATA_REG_P (operands
[1])
1832 && next_insn_tests_no_inequality (insn
))
1834 cc_status
.flags
= CC_NOT_NEGATIVE
| CC_Z_IN_NOT_N
| CC_NO_OVERFLOW
;
1835 return "move%.w %1,%%ccr";
1837 if (count
== 2 && DATA_REG_P (operands
[1])
1838 && next_insn_tests_no_inequality (insn
))
1840 cc_status
.flags
= CC_NOT_NEGATIVE
| CC_INVERTED
| CC_NO_OVERFLOW
;
1841 return "move%.w %1,%%ccr";
1843 /* count == 1 followed by bvc/bvs and
1844 count == 0 followed by bcc/bcs are also possible, but need
1845 m68k-specific CC_Z_IN_NOT_V and CC_Z_IN_NOT_C flags. */
1848 cc_status
.flags
= CC_NOT_NEGATIVE
;
1850 return "btst %0,%1";
1853 /* Return true if X is a legitimate base register. STRICT_P says
1854 whether we need strict checking. */
1857 m68k_legitimate_base_reg_p (rtx x
, bool strict_p
)
1859 /* Allow SUBREG everywhere we allow REG. This results in better code. */
1860 if (!strict_p
&& GET_CODE (x
) == SUBREG
)
1865 ? REGNO_OK_FOR_BASE_P (REGNO (x
))
1866 : REGNO_OK_FOR_BASE_NONSTRICT_P (REGNO (x
))));
1869 /* Return true if X is a legitimate index register. STRICT_P says
1870 whether we need strict checking. */
1873 m68k_legitimate_index_reg_p (rtx x
, bool strict_p
)
1875 if (!strict_p
&& GET_CODE (x
) == SUBREG
)
1880 ? REGNO_OK_FOR_INDEX_P (REGNO (x
))
1881 : REGNO_OK_FOR_INDEX_NONSTRICT_P (REGNO (x
))));
1884 /* Return true if X is a legitimate index expression for a (d8,An,Xn) or
1885 (bd,An,Xn) addressing mode. Fill in the INDEX and SCALE fields of
1886 ADDRESS if so. STRICT_P says whether we need strict checking. */
1889 m68k_decompose_index (rtx x
, bool strict_p
, struct m68k_address
*address
)
1893 /* Check for a scale factor. */
1895 if ((TARGET_68020
|| TARGET_COLDFIRE
)
1896 && GET_CODE (x
) == MULT
1897 && GET_CODE (XEXP (x
, 1)) == CONST_INT
1898 && (INTVAL (XEXP (x
, 1)) == 2
1899 || INTVAL (XEXP (x
, 1)) == 4
1900 || (INTVAL (XEXP (x
, 1)) == 8
1901 && (TARGET_COLDFIRE_FPU
|| !TARGET_COLDFIRE
))))
1903 scale
= INTVAL (XEXP (x
, 1));
1907 /* Check for a word extension. */
1908 if (!TARGET_COLDFIRE
1909 && GET_CODE (x
) == SIGN_EXTEND
1910 && GET_MODE (XEXP (x
, 0)) == HImode
)
1913 if (m68k_legitimate_index_reg_p (x
, strict_p
))
1915 address
->scale
= scale
;
1923 /* Return true if X is an illegitimate symbolic constant. */
1926 m68k_illegitimate_symbolic_constant_p (rtx x
)
1930 if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P
)
1932 split_const (x
, &base
, &offset
);
1933 if (GET_CODE (base
) == SYMBOL_REF
1934 && !offset_within_block_p (base
, INTVAL (offset
)))
1937 return m68k_tls_reference_p (x
, false);
1940 /* Return true if X is a legitimate constant address that can reach
1941 bytes in the range [X, X + REACH). STRICT_P says whether we need
1945 m68k_legitimate_constant_address_p (rtx x
, unsigned int reach
, bool strict_p
)
1949 if (!CONSTANT_ADDRESS_P (x
))
1953 && !(strict_p
&& TARGET_PCREL
)
1954 && symbolic_operand (x
, VOIDmode
))
1957 if (M68K_OFFSETS_MUST_BE_WITHIN_SECTIONS_P
&& reach
> 1)
1959 split_const (x
, &base
, &offset
);
1960 if (GET_CODE (base
) == SYMBOL_REF
1961 && !offset_within_block_p (base
, INTVAL (offset
) + reach
- 1))
1965 return !m68k_tls_reference_p (x
, false);
1968 /* Return true if X is a LABEL_REF for a jump table. Assume that unplaced
1969 labels will become jump tables. */
1972 m68k_jump_table_ref_p (rtx x
)
1974 if (GET_CODE (x
) != LABEL_REF
)
1978 if (!NEXT_INSN (x
) && !PREV_INSN (x
))
1981 x
= next_nonnote_insn (x
);
1982 return x
&& JUMP_TABLE_DATA_P (x
);
1985 /* Return true if X is a legitimate address for values of mode MODE.
1986 STRICT_P says whether strict checking is needed. If the address
1987 is valid, describe its components in *ADDRESS. */
1990 m68k_decompose_address (enum machine_mode mode
, rtx x
,
1991 bool strict_p
, struct m68k_address
*address
)
1995 memset (address
, 0, sizeof (*address
));
1997 if (mode
== BLKmode
)
2000 reach
= GET_MODE_SIZE (mode
);
2002 /* Check for (An) (mode 2). */
2003 if (m68k_legitimate_base_reg_p (x
, strict_p
))
2009 /* Check for -(An) and (An)+ (modes 3 and 4). */
2010 if ((GET_CODE (x
) == PRE_DEC
|| GET_CODE (x
) == POST_INC
)
2011 && m68k_legitimate_base_reg_p (XEXP (x
, 0), strict_p
))
2013 address
->code
= GET_CODE (x
);
2014 address
->base
= XEXP (x
, 0);
2018 /* Check for (d16,An) (mode 5). */
2019 if (GET_CODE (x
) == PLUS
2020 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2021 && IN_RANGE (INTVAL (XEXP (x
, 1)), -0x8000, 0x8000 - reach
)
2022 && m68k_legitimate_base_reg_p (XEXP (x
, 0), strict_p
))
2024 address
->base
= XEXP (x
, 0);
2025 address
->offset
= XEXP (x
, 1);
2029 /* Check for GOT loads. These are (bd,An,Xn) addresses if
2030 TARGET_68020 && flag_pic == 2, otherwise they are (d16,An)
2032 if (GET_CODE (x
) == PLUS
2033 && XEXP (x
, 0) == pic_offset_table_rtx
)
2035 /* As we are processing a PLUS, do not unwrap RELOC32 symbols --
2036 they are invalid in this context. */
2037 if (m68k_unwrap_symbol (XEXP (x
, 1), false) != XEXP (x
, 1))
2039 address
->base
= XEXP (x
, 0);
2040 address
->offset
= XEXP (x
, 1);
2045 /* The ColdFire FPU only accepts addressing modes 2-5. */
2046 if (TARGET_COLDFIRE_FPU
&& GET_MODE_CLASS (mode
) == MODE_FLOAT
)
2049 /* Check for (xxx).w and (xxx).l. Also, in the TARGET_PCREL case,
2050 check for (d16,PC) or (bd,PC,Xn) with a suppressed index register.
2051 All these modes are variations of mode 7. */
2052 if (m68k_legitimate_constant_address_p (x
, reach
, strict_p
))
2054 address
->offset
= x
;
2058 /* Check for (d8,PC,Xn), a mode 7 form. This case is needed for
2061 ??? do_tablejump creates these addresses before placing the target
2062 label, so we have to assume that unplaced labels are jump table
2063 references. It seems unlikely that we would ever generate indexed
2064 accesses to unplaced labels in other cases. */
2065 if (GET_CODE (x
) == PLUS
2066 && m68k_jump_table_ref_p (XEXP (x
, 1))
2067 && m68k_decompose_index (XEXP (x
, 0), strict_p
, address
))
2069 address
->offset
= XEXP (x
, 1);
2073 /* Everything hereafter deals with (d8,An,Xn.SIZE*SCALE) or
2074 (bd,An,Xn.SIZE*SCALE) addresses. */
2078 /* Check for a nonzero base displacement. */
2079 if (GET_CODE (x
) == PLUS
2080 && m68k_legitimate_constant_address_p (XEXP (x
, 1), reach
, strict_p
))
2082 address
->offset
= XEXP (x
, 1);
2086 /* Check for a suppressed index register. */
2087 if (m68k_legitimate_base_reg_p (x
, strict_p
))
2093 /* Check for a suppressed base register. Do not allow this case
2094 for non-symbolic offsets as it effectively gives gcc freedom
2095 to treat data registers as base registers, which can generate
2098 && symbolic_operand (address
->offset
, VOIDmode
)
2099 && m68k_decompose_index (x
, strict_p
, address
))
2104 /* Check for a nonzero base displacement. */
2105 if (GET_CODE (x
) == PLUS
2106 && GET_CODE (XEXP (x
, 1)) == CONST_INT
2107 && IN_RANGE (INTVAL (XEXP (x
, 1)), -0x80, 0x80 - reach
))
2109 address
->offset
= XEXP (x
, 1);
2114 /* We now expect the sum of a base and an index. */
2115 if (GET_CODE (x
) == PLUS
)
2117 if (m68k_legitimate_base_reg_p (XEXP (x
, 0), strict_p
)
2118 && m68k_decompose_index (XEXP (x
, 1), strict_p
, address
))
2120 address
->base
= XEXP (x
, 0);
2124 if (m68k_legitimate_base_reg_p (XEXP (x
, 1), strict_p
)
2125 && m68k_decompose_index (XEXP (x
, 0), strict_p
, address
))
2127 address
->base
= XEXP (x
, 1);
2134 /* Return true if X is a legitimate address for values of mode MODE.
2135 STRICT_P says whether strict checking is needed. */
2138 m68k_legitimate_address_p (enum machine_mode mode
, rtx x
, bool strict_p
)
2140 struct m68k_address address
;
2142 return m68k_decompose_address (mode
, x
, strict_p
, &address
);
2145 /* Return true if X is a memory, describing its address in ADDRESS if so.
2146 Apply strict checking if called during or after reload. */
2149 m68k_legitimate_mem_p (rtx x
, struct m68k_address
*address
)
2152 && m68k_decompose_address (GET_MODE (x
), XEXP (x
, 0),
2153 reload_in_progress
|| reload_completed
,
2157 /* Return true if X matches the 'Q' constraint. It must be a memory
2158 with a base address and no constant offset or index. */
2161 m68k_matches_q_p (rtx x
)
2163 struct m68k_address address
;
2165 return (m68k_legitimate_mem_p (x
, &address
)
2166 && address
.code
== UNKNOWN
2172 /* Return true if X matches the 'U' constraint. It must be a base address
2173 with a constant offset and no index. */
2176 m68k_matches_u_p (rtx x
)
2178 struct m68k_address address
;
2180 return (m68k_legitimate_mem_p (x
, &address
)
2181 && address
.code
== UNKNOWN
2187 /* Return GOT pointer. */
2192 if (pic_offset_table_rtx
== NULL_RTX
)
2193 pic_offset_table_rtx
= gen_rtx_REG (Pmode
, PIC_REG
);
2195 crtl
->uses_pic_offset_table
= 1;
2197 return pic_offset_table_rtx
;
2200 /* M68K relocations, used to distinguish GOT and TLS relocations in UNSPEC
2202 enum m68k_reloc
{ RELOC_GOT
, RELOC_TLSGD
, RELOC_TLSLDM
, RELOC_TLSLDO
,
2203 RELOC_TLSIE
, RELOC_TLSLE
};
2205 #define TLS_RELOC_P(RELOC) ((RELOC) != RELOC_GOT)
2207 /* Wrap symbol X into unspec representing relocation RELOC.
2208 BASE_REG - register that should be added to the result.
2209 TEMP_REG - if non-null, temporary register. */
2212 m68k_wrap_symbol (rtx x
, enum m68k_reloc reloc
, rtx base_reg
, rtx temp_reg
)
2216 use_x_p
= (base_reg
== pic_offset_table_rtx
) ? TARGET_XGOT
: TARGET_XTLS
;
2218 if (TARGET_COLDFIRE
&& use_x_p
)
2219 /* When compiling with -mx{got, tls} switch the code will look like this:
2221 move.l <X>@<RELOC>,<TEMP_REG>
2222 add.l <BASE_REG>,<TEMP_REG> */
2224 /* Wrap X in UNSPEC_??? to tip m68k_output_addr_const_extra
2225 to put @RELOC after reference. */
2226 x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, x
, GEN_INT (reloc
)),
2228 x
= gen_rtx_CONST (Pmode
, x
);
2230 if (temp_reg
== NULL
)
2232 gcc_assert (can_create_pseudo_p ());
2233 temp_reg
= gen_reg_rtx (Pmode
);
2236 emit_move_insn (temp_reg
, x
);
2237 emit_insn (gen_addsi3 (temp_reg
, temp_reg
, base_reg
));
2242 x
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (2, x
, GEN_INT (reloc
)),
2244 x
= gen_rtx_CONST (Pmode
, x
);
2246 x
= gen_rtx_PLUS (Pmode
, base_reg
, x
);
2252 /* Helper for m68k_unwrap_symbol.
2253 Also, if unwrapping was successful (that is if (ORIG != <return value>)),
2254 sets *RELOC_PTR to relocation type for the symbol. */
2257 m68k_unwrap_symbol_1 (rtx orig
, bool unwrap_reloc32_p
,
2258 enum m68k_reloc
*reloc_ptr
)
2260 if (GET_CODE (orig
) == CONST
)
2263 enum m68k_reloc dummy
;
2267 if (reloc_ptr
== NULL
)
2270 /* Handle an addend. */
2271 if ((GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
)
2272 && CONST_INT_P (XEXP (x
, 1)))
2275 if (GET_CODE (x
) == UNSPEC
)
2277 switch (XINT (x
, 1))
2279 case UNSPEC_RELOC16
:
2280 orig
= XVECEXP (x
, 0, 0);
2281 *reloc_ptr
= (enum m68k_reloc
) INTVAL (XVECEXP (x
, 0, 1));
2284 case UNSPEC_RELOC32
:
2285 if (unwrap_reloc32_p
)
2287 orig
= XVECEXP (x
, 0, 0);
2288 *reloc_ptr
= (enum m68k_reloc
) INTVAL (XVECEXP (x
, 0, 1));
2301 /* Unwrap symbol from UNSPEC_RELOC16 and, if unwrap_reloc32_p,
2302 UNSPEC_RELOC32 wrappers. */
2305 m68k_unwrap_symbol (rtx orig
, bool unwrap_reloc32_p
)
2307 return m68k_unwrap_symbol_1 (orig
, unwrap_reloc32_p
, NULL
);
2310 /* Helper for m68k_final_prescan_insn. */
2313 m68k_final_prescan_insn_1 (rtx
*x_ptr
, void *data ATTRIBUTE_UNUSED
)
2317 if (m68k_unwrap_symbol (x
, true) != x
)
2318 /* For rationale of the below, see comment in m68k_final_prescan_insn. */
2322 gcc_assert (GET_CODE (x
) == CONST
);
2325 if (GET_CODE (plus
) == PLUS
|| GET_CODE (plus
) == MINUS
)
2330 unspec
= XEXP (plus
, 0);
2331 gcc_assert (GET_CODE (unspec
) == UNSPEC
);
2332 addend
= XEXP (plus
, 1);
2333 gcc_assert (CONST_INT_P (addend
));
2335 /* We now have all the pieces, rearrange them. */
2337 /* Move symbol to plus. */
2338 XEXP (plus
, 0) = XVECEXP (unspec
, 0, 0);
2340 /* Move plus inside unspec. */
2341 XVECEXP (unspec
, 0, 0) = plus
;
2343 /* Move unspec to top level of const. */
2344 XEXP (x
, 0) = unspec
;
2353 /* Prescan insn before outputing assembler for it. */
2356 m68k_final_prescan_insn (rtx insn ATTRIBUTE_UNUSED
,
2357 rtx
*operands
, int n_operands
)
2361 /* Combine and, possibly, other optimizations may do good job
2363 (const (unspec [(symbol)]))
2365 (const (plus (unspec [(symbol)])
2367 The problem with this is emitting @TLS or @GOT decorations.
2368 The decoration is emitted when processing (unspec), so the
2369 result would be "#symbol@TLSLE+N" instead of "#symbol+N@TLSLE".
2371 It seems that the easiest solution to this is to convert such
2373 (const (unspec [(plus (symbol)
2375 Note, that the top level of operand remains intact, so we don't have
2376 to patch up anything outside of the operand. */
2378 for (i
= 0; i
< n_operands
; ++i
)
2384 for_each_rtx (&op
, m68k_final_prescan_insn_1
, NULL
);
2388 /* Move X to a register and add REG_EQUAL note pointing to ORIG.
2389 If REG is non-null, use it; generate new pseudo otherwise. */
2392 m68k_move_to_reg (rtx x
, rtx orig
, rtx reg
)
2396 if (reg
== NULL_RTX
)
2398 gcc_assert (can_create_pseudo_p ());
2399 reg
= gen_reg_rtx (Pmode
);
2402 insn
= emit_move_insn (reg
, x
);
2403 /* Put a REG_EQUAL note on this insn, so that it can be optimized
2405 set_unique_reg_note (insn
, REG_EQUAL
, orig
);
2410 /* Does the same as m68k_wrap_symbol, but returns a memory reference to
2414 m68k_wrap_symbol_into_got_ref (rtx x
, enum m68k_reloc reloc
, rtx temp_reg
)
2416 x
= m68k_wrap_symbol (x
, reloc
, m68k_get_gp (), temp_reg
);
2418 x
= gen_rtx_MEM (Pmode
, x
);
2419 MEM_READONLY_P (x
) = 1;
2424 /* Legitimize PIC addresses. If the address is already
2425 position-independent, we return ORIG. Newly generated
2426 position-independent addresses go to REG. If we need more
2427 than one register, we lose.
2429 An address is legitimized by making an indirect reference
2430 through the Global Offset Table with the name of the symbol
2433 The assembler and linker are responsible for placing the
2434 address of the symbol in the GOT. The function prologue
2435 is responsible for initializing a5 to the starting address
2438 The assembler is also responsible for translating a symbol name
2439 into a constant displacement from the start of the GOT.
2441 A quick example may make things a little clearer:
2443 When not generating PIC code to store the value 12345 into _foo
2444 we would generate the following code:
2448 When generating PIC two transformations are made. First, the compiler
2449 loads the address of foo into a register. So the first transformation makes:
2454 The code in movsi will intercept the lea instruction and call this
2455 routine which will transform the instructions into:
2457 movel a5@(_foo:w), a0
2461 That (in a nutshell) is how *all* symbol and label references are
2465 legitimize_pic_address (rtx orig
, enum machine_mode mode ATTRIBUTE_UNUSED
,
2470 /* First handle a simple SYMBOL_REF or LABEL_REF */
2471 if (GET_CODE (orig
) == SYMBOL_REF
|| GET_CODE (orig
) == LABEL_REF
)
2475 pic_ref
= m68k_wrap_symbol_into_got_ref (orig
, RELOC_GOT
, reg
);
2476 pic_ref
= m68k_move_to_reg (pic_ref
, orig
, reg
);
2478 else if (GET_CODE (orig
) == CONST
)
2482 /* Make sure this has not already been legitimized. */
2483 if (m68k_unwrap_symbol (orig
, true) != orig
)
2488 /* legitimize both operands of the PLUS */
2489 gcc_assert (GET_CODE (XEXP (orig
, 0)) == PLUS
);
2491 base
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 0), Pmode
, reg
);
2492 orig
= legitimize_pic_address (XEXP (XEXP (orig
, 0), 1), Pmode
,
2493 base
== reg
? 0 : reg
);
2495 if (GET_CODE (orig
) == CONST_INT
)
2496 pic_ref
= plus_constant (base
, INTVAL (orig
));
2498 pic_ref
= gen_rtx_PLUS (Pmode
, base
, orig
);
2504 /* The __tls_get_addr symbol. */
2505 static GTY(()) rtx m68k_tls_get_addr
;
2507 /* Return SYMBOL_REF for __tls_get_addr. */
2510 m68k_get_tls_get_addr (void)
2512 if (m68k_tls_get_addr
== NULL_RTX
)
2513 m68k_tls_get_addr
= init_one_libfunc ("__tls_get_addr");
2515 return m68k_tls_get_addr
;
2518 /* Return libcall result in A0 instead of usual D0. */
2519 static bool m68k_libcall_value_in_a0_p
= false;
2521 /* Emit instruction sequence that calls __tls_get_addr. X is
2522 the TLS symbol we are referencing and RELOC is the symbol type to use
2523 (either TLSGD or TLSLDM). EQV is the REG_EQUAL note for the sequence
2524 emitted. A pseudo register with result of __tls_get_addr call is
2528 m68k_call_tls_get_addr (rtx x
, rtx eqv
, enum m68k_reloc reloc
)
2534 /* Emit the call sequence. */
2537 /* FIXME: Unfortunately, emit_library_call_value does not
2538 consider (plus (%a5) (const (unspec))) to be a good enough
2539 operand for push, so it forces it into a register. The bad
2540 thing about this is that combiner, due to copy propagation and other
2541 optimizations, sometimes can not later fix this. As a consequence,
2542 additional register may be allocated resulting in a spill.
2543 For reference, see args processing loops in
2544 calls.c:emit_library_call_value_1.
2545 For testcase, see gcc.target/m68k/tls-{gd, ld}.c */
2546 x
= m68k_wrap_symbol (x
, reloc
, m68k_get_gp (), NULL_RTX
);
2548 /* __tls_get_addr() is not a libcall, but emitting a libcall_value
2549 is the simpliest way of generating a call. The difference between
2550 __tls_get_addr() and libcall is that the result is returned in D0
2551 instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p
2552 which temporarily switches returning the result to A0. */
2554 m68k_libcall_value_in_a0_p
= true;
2555 a0
= emit_library_call_value (m68k_get_tls_get_addr (), NULL_RTX
, LCT_PURE
,
2556 Pmode
, 1, x
, Pmode
);
2557 m68k_libcall_value_in_a0_p
= false;
2559 insns
= get_insns ();
2562 gcc_assert (can_create_pseudo_p ());
2563 dest
= gen_reg_rtx (Pmode
);
2564 emit_libcall_block (insns
, dest
, a0
, eqv
);
2569 /* The __tls_get_addr symbol. */
2570 static GTY(()) rtx m68k_read_tp
;
2572 /* Return SYMBOL_REF for __m68k_read_tp. */
2575 m68k_get_m68k_read_tp (void)
2577 if (m68k_read_tp
== NULL_RTX
)
2578 m68k_read_tp
= init_one_libfunc ("__m68k_read_tp");
2580 return m68k_read_tp
;
2583 /* Emit instruction sequence that calls __m68k_read_tp.
2584 A pseudo register with result of __m68k_read_tp call is returned. */
2587 m68k_call_m68k_read_tp (void)
2596 /* __m68k_read_tp() is not a libcall, but emitting a libcall_value
2597 is the simpliest way of generating a call. The difference between
2598 __m68k_read_tp() and libcall is that the result is returned in D0
2599 instead of A0. To workaround this, we use m68k_libcall_value_in_a0_p
2600 which temporarily switches returning the result to A0. */
2602 /* Emit the call sequence. */
2603 m68k_libcall_value_in_a0_p
= true;
2604 a0
= emit_library_call_value (m68k_get_m68k_read_tp (), NULL_RTX
, LCT_PURE
,
2606 m68k_libcall_value_in_a0_p
= false;
2607 insns
= get_insns ();
2610 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2611 share the m68k_read_tp result with other IE/LE model accesses. */
2612 eqv
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const1_rtx
), UNSPEC_RELOC32
);
2614 gcc_assert (can_create_pseudo_p ());
2615 dest
= gen_reg_rtx (Pmode
);
2616 emit_libcall_block (insns
, dest
, a0
, eqv
);
2621 /* Return a legitimized address for accessing TLS SYMBOL_REF X.
2622 For explanations on instructions sequences see TLS/NPTL ABI for m68k and
2626 m68k_legitimize_tls_address (rtx orig
)
2628 switch (SYMBOL_REF_TLS_MODEL (orig
))
2630 case TLS_MODEL_GLOBAL_DYNAMIC
:
2631 orig
= m68k_call_tls_get_addr (orig
, orig
, RELOC_TLSGD
);
2634 case TLS_MODEL_LOCAL_DYNAMIC
:
2640 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2641 share the LDM result with other LD model accesses. */
2642 eqv
= gen_rtx_UNSPEC (Pmode
, gen_rtvec (1, const0_rtx
),
2645 a0
= m68k_call_tls_get_addr (orig
, eqv
, RELOC_TLSLDM
);
2647 x
= m68k_wrap_symbol (orig
, RELOC_TLSLDO
, a0
, NULL_RTX
);
2649 if (can_create_pseudo_p ())
2650 x
= m68k_move_to_reg (x
, orig
, NULL_RTX
);
2656 case TLS_MODEL_INITIAL_EXEC
:
2661 a0
= m68k_call_m68k_read_tp ();
2663 x
= m68k_wrap_symbol_into_got_ref (orig
, RELOC_TLSIE
, NULL_RTX
);
2664 x
= gen_rtx_PLUS (Pmode
, x
, a0
);
2666 if (can_create_pseudo_p ())
2667 x
= m68k_move_to_reg (x
, orig
, NULL_RTX
);
2673 case TLS_MODEL_LOCAL_EXEC
:
2678 a0
= m68k_call_m68k_read_tp ();
2680 x
= m68k_wrap_symbol (orig
, RELOC_TLSLE
, a0
, NULL_RTX
);
2682 if (can_create_pseudo_p ())
2683 x
= m68k_move_to_reg (x
, orig
, NULL_RTX
);
2696 /* Return true if X is a TLS symbol. */
2699 m68k_tls_symbol_p (rtx x
)
2701 if (!TARGET_HAVE_TLS
)
2704 if (GET_CODE (x
) != SYMBOL_REF
)
2707 return SYMBOL_REF_TLS_MODEL (x
) != 0;
2710 /* Helper for m68k_tls_referenced_p. */
2713 m68k_tls_reference_p_1 (rtx
*x_ptr
, void *data ATTRIBUTE_UNUSED
)
2715 /* Note: this is not the same as m68k_tls_symbol_p. */
2716 if (GET_CODE (*x_ptr
) == SYMBOL_REF
)
2717 return SYMBOL_REF_TLS_MODEL (*x_ptr
) != 0 ? 1 : 0;
2719 /* Don't recurse into legitimate TLS references. */
2720 if (m68k_tls_reference_p (*x_ptr
, true))
2726 /* If !LEGITIMATE_P, return true if X is a TLS symbol reference,
2727 though illegitimate one.
2728 If LEGITIMATE_P, return true if X is a legitimate TLS symbol reference. */
2731 m68k_tls_reference_p (rtx x
, bool legitimate_p
)
2733 if (!TARGET_HAVE_TLS
)
2737 return for_each_rtx (&x
, m68k_tls_reference_p_1
, NULL
) == 1 ? true : false;
2740 enum m68k_reloc reloc
= RELOC_GOT
;
2742 return (m68k_unwrap_symbol_1 (x
, true, &reloc
) != x
2743 && TLS_RELOC_P (reloc
));
2749 #define USE_MOVQ(i) ((unsigned) ((i) + 128) <= 255)
2751 /* Return the type of move that should be used for integer I. */
2754 m68k_const_method (HOST_WIDE_INT i
)
2761 /* The ColdFire doesn't have byte or word operations. */
2762 /* FIXME: This may not be useful for the m68060 either. */
2763 if (!TARGET_COLDFIRE
)
2765 /* if -256 < N < 256 but N is not in range for a moveq
2766 N^ff will be, so use moveq #N^ff, dreg; not.b dreg. */
2767 if (USE_MOVQ (i
^ 0xff))
2769 /* Likewise, try with not.w */
2770 if (USE_MOVQ (i
^ 0xffff))
2772 /* This is the only value where neg.w is useful */
2777 /* Try also with swap. */
2779 if (USE_MOVQ ((u
>> 16) | (u
<< 16)))
2784 /* Try using MVZ/MVS with an immediate value to load constants. */
2785 if (i
>= 0 && i
<= 65535)
2787 if (i
>= -32768 && i
<= 32767)
2791 /* Otherwise, use move.l */
2795 /* Return the cost of moving constant I into a data register. */
2798 const_int_cost (HOST_WIDE_INT i
)
2800 switch (m68k_const_method (i
))
2803 /* Constants between -128 and 127 are cheap due to moveq. */
2811 /* Constants easily generated by moveq + not.b/not.w/neg.w/swap. */
2821 m68k_rtx_costs (rtx x
, int code
, int outer_code
, int *total
,
2822 bool speed ATTRIBUTE_UNUSED
)
2827 /* Constant zero is super cheap due to clr instruction. */
2828 if (x
== const0_rtx
)
2831 *total
= const_int_cost (INTVAL (x
));
2841 /* Make 0.0 cheaper than other floating constants to
2842 encourage creating tstsf and tstdf insns. */
2843 if (outer_code
== COMPARE
2844 && (x
== CONST0_RTX (SFmode
) || x
== CONST0_RTX (DFmode
)))
2850 /* These are vaguely right for a 68020. */
2851 /* The costs for long multiply have been adjusted to work properly
2852 in synth_mult on the 68020, relative to an average of the time
2853 for add and the time for shift, taking away a little more because
2854 sometimes move insns are needed. */
2855 /* div?.w is relatively cheaper on 68000 counted in COSTS_N_INSNS
2860 : (TUNE_CFV2 && TUNE_EMAC) ? 3 \
2861 : (TUNE_CFV2 && TUNE_MAC) ? 4 \
2863 : TARGET_COLDFIRE ? 3 : 13)
2868 : TUNE_68000_10 ? 5 \
2869 : (TUNE_CFV2 && TUNE_EMAC) ? 3 \
2870 : (TUNE_CFV2 && TUNE_MAC) ? 2 \
2872 : TARGET_COLDFIRE ? 2 : 8)
2875 (TARGET_CF_HWDIV ? 11 \
2876 : TUNE_68000_10 || TARGET_COLDFIRE ? 12 : 27)
2879 /* An lea costs about three times as much as a simple add. */
2880 if (GET_MODE (x
) == SImode
2881 && GET_CODE (XEXP (x
, 1)) == REG
2882 && GET_CODE (XEXP (x
, 0)) == MULT
2883 && GET_CODE (XEXP (XEXP (x
, 0), 0)) == REG
2884 && GET_CODE (XEXP (XEXP (x
, 0), 1)) == CONST_INT
2885 && (INTVAL (XEXP (XEXP (x
, 0), 1)) == 2
2886 || INTVAL (XEXP (XEXP (x
, 0), 1)) == 4
2887 || INTVAL (XEXP (XEXP (x
, 0), 1)) == 8))
2889 /* lea an@(dx:l:i),am */
2890 *total
= COSTS_N_INSNS (TARGET_COLDFIRE
? 2 : 3);
2900 *total
= COSTS_N_INSNS(1);
2905 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
)
2907 if (INTVAL (XEXP (x
, 1)) < 16)
2908 *total
= COSTS_N_INSNS (2) + INTVAL (XEXP (x
, 1)) / 2;
2910 /* We're using clrw + swap for these cases. */
2911 *total
= COSTS_N_INSNS (4) + (INTVAL (XEXP (x
, 1)) - 16) / 2;
2914 *total
= COSTS_N_INSNS (10); /* Worst case. */
2917 /* A shift by a big integer takes an extra instruction. */
2918 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
2919 && (INTVAL (XEXP (x
, 1)) == 16))
2921 *total
= COSTS_N_INSNS (2); /* clrw;swap */
2924 if (GET_CODE (XEXP (x
, 1)) == CONST_INT
2925 && !(INTVAL (XEXP (x
, 1)) > 0
2926 && INTVAL (XEXP (x
, 1)) <= 8))
2928 *total
= COSTS_N_INSNS (TARGET_COLDFIRE
? 1 : 3); /* lsr #i,dn */
2934 if ((GET_CODE (XEXP (x
, 0)) == ZERO_EXTEND
2935 || GET_CODE (XEXP (x
, 0)) == SIGN_EXTEND
)
2936 && GET_MODE (x
) == SImode
)
2937 *total
= COSTS_N_INSNS (MULW_COST
);
2938 else if (GET_MODE (x
) == QImode
|| GET_MODE (x
) == HImode
)
2939 *total
= COSTS_N_INSNS (MULW_COST
);
2941 *total
= COSTS_N_INSNS (MULL_COST
);
2948 if (GET_MODE (x
) == QImode
|| GET_MODE (x
) == HImode
)
2949 *total
= COSTS_N_INSNS (DIVW_COST
); /* div.w */
2950 else if (TARGET_CF_HWDIV
)
2951 *total
= COSTS_N_INSNS (18);
2953 *total
= COSTS_N_INSNS (43); /* div.l */
2957 if (outer_code
== COMPARE
)
2966 /* Return an instruction to move CONST_INT OPERANDS[1] into data register
2970 output_move_const_into_data_reg (rtx
*operands
)
2974 i
= INTVAL (operands
[1]);
2975 switch (m68k_const_method (i
))
2978 return "mvzw %1,%0";
2980 return "mvsw %1,%0";
2982 return "moveq %1,%0";
2985 operands
[1] = GEN_INT (i
^ 0xff);
2986 return "moveq %1,%0\n\tnot%.b %0";
2989 operands
[1] = GEN_INT (i
^ 0xffff);
2990 return "moveq %1,%0\n\tnot%.w %0";
2993 return "moveq #-128,%0\n\tneg%.w %0";
2998 operands
[1] = GEN_INT ((u
<< 16) | (u
>> 16));
2999 return "moveq %1,%0\n\tswap %0";
3002 return "move%.l %1,%0";
3008 /* Return true if I can be handled by ISA B's mov3q instruction. */
3011 valid_mov3q_const (HOST_WIDE_INT i
)
3013 return TARGET_ISAB
&& (i
== -1 || IN_RANGE (i
, 1, 7));
3016 /* Return an instruction to move CONST_INT OPERANDS[1] into OPERANDS[0].
3017 I is the value of OPERANDS[1]. */
3020 output_move_simode_const (rtx
*operands
)
3026 src
= INTVAL (operands
[1]);
3028 && (DATA_REG_P (dest
) || MEM_P (dest
))
3029 /* clr insns on 68000 read before writing. */
3030 && ((TARGET_68010
|| TARGET_COLDFIRE
)
3031 || !(MEM_P (dest
) && MEM_VOLATILE_P (dest
))))
3033 else if (GET_MODE (dest
) == SImode
&& valid_mov3q_const (src
))
3034 return "mov3q%.l %1,%0";
3035 else if (src
== 0 && ADDRESS_REG_P (dest
))
3036 return "sub%.l %0,%0";
3037 else if (DATA_REG_P (dest
))
3038 return output_move_const_into_data_reg (operands
);
3039 else if (ADDRESS_REG_P (dest
) && IN_RANGE (src
, -0x8000, 0x7fff))
3041 if (valid_mov3q_const (src
))
3042 return "mov3q%.l %1,%0";
3043 return "move%.w %1,%0";
3045 else if (MEM_P (dest
)
3046 && GET_CODE (XEXP (dest
, 0)) == PRE_DEC
3047 && REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
3048 && IN_RANGE (src
, -0x8000, 0x7fff))
3050 if (valid_mov3q_const (src
))
3051 return "mov3q%.l %1,%-";
3054 return "move%.l %1,%0";
3058 output_move_simode (rtx
*operands
)
3060 if (GET_CODE (operands
[1]) == CONST_INT
)
3061 return output_move_simode_const (operands
);
3062 else if ((GET_CODE (operands
[1]) == SYMBOL_REF
3063 || GET_CODE (operands
[1]) == CONST
)
3064 && push_operand (operands
[0], SImode
))
3066 else if ((GET_CODE (operands
[1]) == SYMBOL_REF
3067 || GET_CODE (operands
[1]) == CONST
)
3068 && ADDRESS_REG_P (operands
[0]))
3069 return "lea %a1,%0";
3070 return "move%.l %1,%0";
3074 output_move_himode (rtx
*operands
)
3076 if (GET_CODE (operands
[1]) == CONST_INT
)
3078 if (operands
[1] == const0_rtx
3079 && (DATA_REG_P (operands
[0])
3080 || GET_CODE (operands
[0]) == MEM
)
3081 /* clr insns on 68000 read before writing. */
3082 && ((TARGET_68010
|| TARGET_COLDFIRE
)
3083 || !(GET_CODE (operands
[0]) == MEM
3084 && MEM_VOLATILE_P (operands
[0]))))
3086 else if (operands
[1] == const0_rtx
3087 && ADDRESS_REG_P (operands
[0]))
3088 return "sub%.l %0,%0";
3089 else if (DATA_REG_P (operands
[0])
3090 && INTVAL (operands
[1]) < 128
3091 && INTVAL (operands
[1]) >= -128)
3092 return "moveq %1,%0";
3093 else if (INTVAL (operands
[1]) < 0x8000
3094 && INTVAL (operands
[1]) >= -0x8000)
3095 return "move%.w %1,%0";
3097 else if (CONSTANT_P (operands
[1]))
3098 return "move%.l %1,%0";
3099 return "move%.w %1,%0";
3103 output_move_qimode (rtx
*operands
)
3105 /* 68k family always modifies the stack pointer by at least 2, even for
3106 byte pushes. The 5200 (ColdFire) does not do this. */
3108 /* This case is generated by pushqi1 pattern now. */
3109 gcc_assert (!(GET_CODE (operands
[0]) == MEM
3110 && GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
3111 && XEXP (XEXP (operands
[0], 0), 0) == stack_pointer_rtx
3112 && ! ADDRESS_REG_P (operands
[1])
3113 && ! TARGET_COLDFIRE
));
3115 /* clr and st insns on 68000 read before writing. */
3116 if (!ADDRESS_REG_P (operands
[0])
3117 && ((TARGET_68010
|| TARGET_COLDFIRE
)
3118 || !(GET_CODE (operands
[0]) == MEM
&& MEM_VOLATILE_P (operands
[0]))))
3120 if (operands
[1] == const0_rtx
)
3122 if ((!TARGET_COLDFIRE
|| DATA_REG_P (operands
[0]))
3123 && GET_CODE (operands
[1]) == CONST_INT
3124 && (INTVAL (operands
[1]) & 255) == 255)
3130 if (GET_CODE (operands
[1]) == CONST_INT
3131 && DATA_REG_P (operands
[0])
3132 && INTVAL (operands
[1]) < 128
3133 && INTVAL (operands
[1]) >= -128)
3134 return "moveq %1,%0";
3135 if (operands
[1] == const0_rtx
&& ADDRESS_REG_P (operands
[0]))
3136 return "sub%.l %0,%0";
3137 if (GET_CODE (operands
[1]) != CONST_INT
&& CONSTANT_P (operands
[1]))
3138 return "move%.l %1,%0";
3139 /* 68k family (including the 5200 ColdFire) does not support byte moves to
3140 from address registers. */
3141 if (ADDRESS_REG_P (operands
[0]) || ADDRESS_REG_P (operands
[1]))
3142 return "move%.w %1,%0";
3143 return "move%.b %1,%0";
3147 output_move_stricthi (rtx
*operands
)
3149 if (operands
[1] == const0_rtx
3150 /* clr insns on 68000 read before writing. */
3151 && ((TARGET_68010
|| TARGET_COLDFIRE
)
3152 || !(GET_CODE (operands
[0]) == MEM
&& MEM_VOLATILE_P (operands
[0]))))
3154 return "move%.w %1,%0";
3158 output_move_strictqi (rtx
*operands
)
3160 if (operands
[1] == const0_rtx
3161 /* clr insns on 68000 read before writing. */
3162 && ((TARGET_68010
|| TARGET_COLDFIRE
)
3163 || !(GET_CODE (operands
[0]) == MEM
&& MEM_VOLATILE_P (operands
[0]))))
3165 return "move%.b %1,%0";
3168 /* Return the best assembler insn template
3169 for moving operands[1] into operands[0] as a fullword. */
3172 singlemove_string (rtx
*operands
)
3174 if (GET_CODE (operands
[1]) == CONST_INT
)
3175 return output_move_simode_const (operands
);
3176 return "move%.l %1,%0";
3180 /* Output assembler or rtl code to perform a doubleword move insn
3181 with operands OPERANDS.
3182 Pointers to 3 helper functions should be specified:
3183 HANDLE_REG_ADJUST to adjust a register by a small value,
3184 HANDLE_COMPADR to compute an address and
3185 HANDLE_MOVSI to move 4 bytes. */
3188 handle_move_double (rtx operands
[2],
3189 void (*handle_reg_adjust
) (rtx
, int),
3190 void (*handle_compadr
) (rtx
[2]),
3191 void (*handle_movsi
) (rtx
[2]))
3195 REGOP
, OFFSOP
, MEMOP
, PUSHOP
, POPOP
, CNSTOP
, RNDOP
3200 rtx addreg0
= 0, addreg1
= 0;
3201 int dest_overlapped_low
= 0;
3202 int size
= GET_MODE_SIZE (GET_MODE (operands
[0]));
3207 /* First classify both operands. */
3209 if (REG_P (operands
[0]))
3211 else if (offsettable_memref_p (operands
[0]))
3213 else if (GET_CODE (XEXP (operands
[0], 0)) == POST_INC
)
3215 else if (GET_CODE (XEXP (operands
[0], 0)) == PRE_DEC
)
3217 else if (GET_CODE (operands
[0]) == MEM
)
3222 if (REG_P (operands
[1]))
3224 else if (CONSTANT_P (operands
[1]))
3226 else if (offsettable_memref_p (operands
[1]))
3228 else if (GET_CODE (XEXP (operands
[1], 0)) == POST_INC
)
3230 else if (GET_CODE (XEXP (operands
[1], 0)) == PRE_DEC
)
3232 else if (GET_CODE (operands
[1]) == MEM
)
3237 /* Check for the cases that the operand constraints are not supposed
3238 to allow to happen. Generating code for these cases is
3240 gcc_assert (optype0
!= RNDOP
&& optype1
!= RNDOP
);
3242 /* If one operand is decrementing and one is incrementing
3243 decrement the former register explicitly
3244 and change that operand into ordinary indexing. */
3246 if (optype0
== PUSHOP
&& optype1
== POPOP
)
3248 operands
[0] = XEXP (XEXP (operands
[0], 0), 0);
3250 handle_reg_adjust (operands
[0], -size
);
3252 if (GET_MODE (operands
[1]) == XFmode
)
3253 operands
[0] = gen_rtx_MEM (XFmode
, operands
[0]);
3254 else if (GET_MODE (operands
[0]) == DFmode
)
3255 operands
[0] = gen_rtx_MEM (DFmode
, operands
[0]);
3257 operands
[0] = gen_rtx_MEM (DImode
, operands
[0]);
3260 if (optype0
== POPOP
&& optype1
== PUSHOP
)
3262 operands
[1] = XEXP (XEXP (operands
[1], 0), 0);
3264 handle_reg_adjust (operands
[1], -size
);
3266 if (GET_MODE (operands
[1]) == XFmode
)
3267 operands
[1] = gen_rtx_MEM (XFmode
, operands
[1]);
3268 else if (GET_MODE (operands
[1]) == DFmode
)
3269 operands
[1] = gen_rtx_MEM (DFmode
, operands
[1]);
3271 operands
[1] = gen_rtx_MEM (DImode
, operands
[1]);
3275 /* If an operand is an unoffsettable memory ref, find a register
3276 we can increment temporarily to make it refer to the second word. */
3278 if (optype0
== MEMOP
)
3279 addreg0
= find_addr_reg (XEXP (operands
[0], 0));
3281 if (optype1
== MEMOP
)
3282 addreg1
= find_addr_reg (XEXP (operands
[1], 0));
3284 /* Ok, we can do one word at a time.
3285 Normally we do the low-numbered word first,
3286 but if either operand is autodecrementing then we
3287 do the high-numbered word first.
3289 In either case, set up in LATEHALF the operands to use
3290 for the high-numbered word and in some cases alter the
3291 operands in OPERANDS to be suitable for the low-numbered word. */
3295 if (optype0
== REGOP
)
3297 latehalf
[0] = gen_rtx_REG (SImode
, REGNO (operands
[0]) + 2);
3298 middlehalf
[0] = gen_rtx_REG (SImode
, REGNO (operands
[0]) + 1);
3300 else if (optype0
== OFFSOP
)
3302 middlehalf
[0] = adjust_address (operands
[0], SImode
, 4);
3303 latehalf
[0] = adjust_address (operands
[0], SImode
, size
- 4);
3307 middlehalf
[0] = adjust_address (operands
[0], SImode
, 0);
3308 latehalf
[0] = adjust_address (operands
[0], SImode
, 0);
3311 if (optype1
== REGOP
)
3313 latehalf
[1] = gen_rtx_REG (SImode
, REGNO (operands
[1]) + 2);
3314 middlehalf
[1] = gen_rtx_REG (SImode
, REGNO (operands
[1]) + 1);
3316 else if (optype1
== OFFSOP
)
3318 middlehalf
[1] = adjust_address (operands
[1], SImode
, 4);
3319 latehalf
[1] = adjust_address (operands
[1], SImode
, size
- 4);
3321 else if (optype1
== CNSTOP
)
3323 if (GET_CODE (operands
[1]) == CONST_DOUBLE
)
3328 REAL_VALUE_FROM_CONST_DOUBLE (r
, operands
[1]);
3329 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r
, l
);
3330 operands
[1] = GEN_INT (l
[0]);
3331 middlehalf
[1] = GEN_INT (l
[1]);
3332 latehalf
[1] = GEN_INT (l
[2]);
3336 /* No non-CONST_DOUBLE constant should ever appear
3338 gcc_assert (!CONSTANT_P (operands
[1]));
3343 middlehalf
[1] = adjust_address (operands
[1], SImode
, 0);
3344 latehalf
[1] = adjust_address (operands
[1], SImode
, 0);
3348 /* size is not 12: */
3350 if (optype0
== REGOP
)
3351 latehalf
[0] = gen_rtx_REG (SImode
, REGNO (operands
[0]) + 1);
3352 else if (optype0
== OFFSOP
)
3353 latehalf
[0] = adjust_address (operands
[0], SImode
, size
- 4);
3355 latehalf
[0] = adjust_address (operands
[0], SImode
, 0);
3357 if (optype1
== REGOP
)
3358 latehalf
[1] = gen_rtx_REG (SImode
, REGNO (operands
[1]) + 1);
3359 else if (optype1
== OFFSOP
)
3360 latehalf
[1] = adjust_address (operands
[1], SImode
, size
- 4);
3361 else if (optype1
== CNSTOP
)
3362 split_double (operands
[1], &operands
[1], &latehalf
[1]);
3364 latehalf
[1] = adjust_address (operands
[1], SImode
, 0);
3367 /* If insn is effectively movd N(sp),-(sp) then we will do the
3368 high word first. We should use the adjusted operand 1 (which is N+4(sp))
3369 for the low word as well, to compensate for the first decrement of sp. */
3370 if (optype0
== PUSHOP
3371 && REGNO (XEXP (XEXP (operands
[0], 0), 0)) == STACK_POINTER_REGNUM
3372 && reg_overlap_mentioned_p (stack_pointer_rtx
, operands
[1]))
3373 operands
[1] = middlehalf
[1] = latehalf
[1];
3375 /* For (set (reg:DI N) (mem:DI ... (reg:SI N) ...)),
3376 if the upper part of reg N does not appear in the MEM, arrange to
3377 emit the move late-half first. Otherwise, compute the MEM address
3378 into the upper part of N and use that as a pointer to the memory
3380 if (optype0
== REGOP
3381 && (optype1
== OFFSOP
|| optype1
== MEMOP
))
3383 rtx testlow
= gen_rtx_REG (SImode
, REGNO (operands
[0]));
3385 if (reg_overlap_mentioned_p (testlow
, XEXP (operands
[1], 0))
3386 && reg_overlap_mentioned_p (latehalf
[0], XEXP (operands
[1], 0)))
3388 /* If both halves of dest are used in the src memory address,
3389 compute the address into latehalf of dest.
3390 Note that this can't happen if the dest is two data regs. */
3392 xops
[0] = latehalf
[0];
3393 xops
[1] = XEXP (operands
[1], 0);
3395 handle_compadr (xops
);
3396 if (GET_MODE (operands
[1]) == XFmode
)
3398 operands
[1] = gen_rtx_MEM (XFmode
, latehalf
[0]);
3399 middlehalf
[1] = adjust_address (operands
[1], DImode
, size
- 8);
3400 latehalf
[1] = adjust_address (operands
[1], DImode
, size
- 4);
3404 operands
[1] = gen_rtx_MEM (DImode
, latehalf
[0]);
3405 latehalf
[1] = adjust_address (operands
[1], DImode
, size
- 4);
3409 && reg_overlap_mentioned_p (middlehalf
[0],
3410 XEXP (operands
[1], 0)))
3412 /* Check for two regs used by both source and dest.
3413 Note that this can't happen if the dest is all data regs.
3414 It can happen if the dest is d6, d7, a0.
3415 But in that case, latehalf is an addr reg, so
3416 the code at compadr does ok. */
3418 if (reg_overlap_mentioned_p (testlow
, XEXP (operands
[1], 0))
3419 || reg_overlap_mentioned_p (latehalf
[0], XEXP (operands
[1], 0)))
3422 /* JRV says this can't happen: */
3423 gcc_assert (!addreg0
&& !addreg1
);
3425 /* Only the middle reg conflicts; simply put it last. */
3426 handle_movsi (operands
);
3427 handle_movsi (latehalf
);
3428 handle_movsi (middlehalf
);
3432 else if (reg_overlap_mentioned_p (testlow
, XEXP (operands
[1], 0)))
3433 /* If the low half of dest is mentioned in the source memory
3434 address, the arrange to emit the move late half first. */
3435 dest_overlapped_low
= 1;
3438 /* If one or both operands autodecrementing,
3439 do the two words, high-numbered first. */
3441 /* Likewise, the first move would clobber the source of the second one,
3442 do them in the other order. This happens only for registers;
3443 such overlap can't happen in memory unless the user explicitly
3444 sets it up, and that is an undefined circumstance. */
3446 if (optype0
== PUSHOP
|| optype1
== PUSHOP
3447 || (optype0
== REGOP
&& optype1
== REGOP
3448 && ((middlehalf
[1] && REGNO (operands
[0]) == REGNO (middlehalf
[1]))
3449 || REGNO (operands
[0]) == REGNO (latehalf
[1])))
3450 || dest_overlapped_low
)
3452 /* Make any unoffsettable addresses point at high-numbered word. */
3454 handle_reg_adjust (addreg0
, size
- 4);
3456 handle_reg_adjust (addreg1
, size
- 4);
3459 handle_movsi (latehalf
);
3461 /* Undo the adds we just did. */
3463 handle_reg_adjust (addreg0
, -4);
3465 handle_reg_adjust (addreg1
, -4);
3469 handle_movsi (middlehalf
);
3472 handle_reg_adjust (addreg0
, -4);
3474 handle_reg_adjust (addreg1
, -4);
3477 /* Do low-numbered word. */
3479 handle_movsi (operands
);
3483 /* Normal case: do the two words, low-numbered first. */
3485 handle_movsi (operands
);
3487 /* Do the middle one of the three words for long double */
3491 handle_reg_adjust (addreg0
, 4);
3493 handle_reg_adjust (addreg1
, 4);
3495 handle_movsi (middlehalf
);
3498 /* Make any unoffsettable addresses point at high-numbered word. */
3500 handle_reg_adjust (addreg0
, 4);
3502 handle_reg_adjust (addreg1
, 4);
3505 handle_movsi (latehalf
);
3507 /* Undo the adds we just did. */
3509 handle_reg_adjust (addreg0
, -(size
- 4));
3511 handle_reg_adjust (addreg1
, -(size
- 4));
3516 /* Output assembler code to adjust REG by N. */
3518 output_reg_adjust (rtx reg
, int n
)
3522 gcc_assert (GET_MODE (reg
) == SImode
3523 && -12 <= n
&& n
!= 0 && n
<= 12);
3528 s
= "add%.l #12,%0";
3532 s
= "addq%.l #8,%0";
3536 s
= "addq%.l #4,%0";
3540 s
= "sub%.l #12,%0";
3544 s
= "subq%.l #8,%0";
3548 s
= "subq%.l #4,%0";
3556 output_asm_insn (s
, ®
);
3559 /* Emit rtl code to adjust REG by N. */
3561 emit_reg_adjust (rtx reg1
, int n
)
3565 gcc_assert (GET_MODE (reg1
) == SImode
3566 && -12 <= n
&& n
!= 0 && n
<= 12);
3568 reg1
= copy_rtx (reg1
);
3569 reg2
= copy_rtx (reg1
);
3572 emit_insn (gen_subsi3 (reg1
, reg2
, GEN_INT (-n
)));
3574 emit_insn (gen_addsi3 (reg1
, reg2
, GEN_INT (n
)));
3579 /* Output assembler to load address OPERANDS[0] to register OPERANDS[1]. */
3581 output_compadr (rtx operands
[2])
3583 output_asm_insn ("lea %a1,%0", operands
);
3586 /* Output the best assembler insn for moving operands[1] into operands[0]
3589 output_movsi (rtx operands
[2])
3591 output_asm_insn (singlemove_string (operands
), operands
);
3594 /* Copy OP and change its mode to MODE. */
3596 copy_operand (rtx op
, enum machine_mode mode
)
3598 /* ??? This looks really ugly. There must be a better way
3599 to change a mode on the operand. */
3600 if (GET_MODE (op
) != VOIDmode
)
3603 op
= gen_rtx_REG (mode
, REGNO (op
));
3607 PUT_MODE (op
, mode
);
3614 /* Emit rtl code for moving operands[1] into operands[0] as a fullword. */
3616 emit_movsi (rtx operands
[2])
3618 operands
[0] = copy_operand (operands
[0], SImode
);
3619 operands
[1] = copy_operand (operands
[1], SImode
);
3621 emit_insn (gen_movsi (operands
[0], operands
[1]));
3624 /* Output assembler code to perform a doubleword move insn
3625 with operands OPERANDS. */
3627 output_move_double (rtx
*operands
)
3629 handle_move_double (operands
,
3630 output_reg_adjust
, output_compadr
, output_movsi
);
3635 /* Output rtl code to perform a doubleword move insn
3636 with operands OPERANDS. */
3638 m68k_emit_move_double (rtx operands
[2])
3640 handle_move_double (operands
, emit_reg_adjust
, emit_movsi
, emit_movsi
);
3643 /* Ensure mode of ORIG, a REG rtx, is MODE. Returns either ORIG or a
3644 new rtx with the correct mode. */
3647 force_mode (enum machine_mode mode
, rtx orig
)
3649 if (mode
== GET_MODE (orig
))
3652 if (REGNO (orig
) >= FIRST_PSEUDO_REGISTER
)
3655 return gen_rtx_REG (mode
, REGNO (orig
));
3659 fp_reg_operand (rtx op
, enum machine_mode mode ATTRIBUTE_UNUSED
)
3661 return reg_renumber
&& FP_REG_P (op
);
3664 /* Emit insns to move operands[1] into operands[0].
3666 Return 1 if we have written out everything that needs to be done to
3667 do the move. Otherwise, return 0 and the caller will emit the move
3670 Note SCRATCH_REG may not be in the proper mode depending on how it
3671 will be used. This routine is responsible for creating a new copy
3672 of SCRATCH_REG in the proper mode. */
3675 emit_move_sequence (rtx
*operands
, enum machine_mode mode
, rtx scratch_reg
)
3677 register rtx operand0
= operands
[0];
3678 register rtx operand1
= operands
[1];
3682 && reload_in_progress
&& GET_CODE (operand0
) == REG
3683 && REGNO (operand0
) >= FIRST_PSEUDO_REGISTER
)
3684 operand0
= reg_equiv_mem
[REGNO (operand0
)];
3685 else if (scratch_reg
3686 && reload_in_progress
&& GET_CODE (operand0
) == SUBREG
3687 && GET_CODE (SUBREG_REG (operand0
)) == REG
3688 && REGNO (SUBREG_REG (operand0
)) >= FIRST_PSEUDO_REGISTER
)
3690 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
3691 the code which tracks sets/uses for delete_output_reload. */
3692 rtx temp
= gen_rtx_SUBREG (GET_MODE (operand0
),
3693 reg_equiv_mem
[REGNO (SUBREG_REG (operand0
))],
3694 SUBREG_BYTE (operand0
));
3695 operand0
= alter_subreg (&temp
);
3699 && reload_in_progress
&& GET_CODE (operand1
) == REG
3700 && REGNO (operand1
) >= FIRST_PSEUDO_REGISTER
)
3701 operand1
= reg_equiv_mem
[REGNO (operand1
)];
3702 else if (scratch_reg
3703 && reload_in_progress
&& GET_CODE (operand1
) == SUBREG
3704 && GET_CODE (SUBREG_REG (operand1
)) == REG
3705 && REGNO (SUBREG_REG (operand1
)) >= FIRST_PSEUDO_REGISTER
)
3707 /* We must not alter SUBREG_BYTE (operand0) since that would confuse
3708 the code which tracks sets/uses for delete_output_reload. */
3709 rtx temp
= gen_rtx_SUBREG (GET_MODE (operand1
),
3710 reg_equiv_mem
[REGNO (SUBREG_REG (operand1
))],
3711 SUBREG_BYTE (operand1
));
3712 operand1
= alter_subreg (&temp
);
3715 if (scratch_reg
&& reload_in_progress
&& GET_CODE (operand0
) == MEM
3716 && ((tem
= find_replacement (&XEXP (operand0
, 0)))
3717 != XEXP (operand0
, 0)))
3718 operand0
= gen_rtx_MEM (GET_MODE (operand0
), tem
);
3719 if (scratch_reg
&& reload_in_progress
&& GET_CODE (operand1
) == MEM
3720 && ((tem
= find_replacement (&XEXP (operand1
, 0)))
3721 != XEXP (operand1
, 0)))
3722 operand1
= gen_rtx_MEM (GET_MODE (operand1
), tem
);
3724 /* Handle secondary reloads for loads/stores of FP registers where
3725 the address is symbolic by using the scratch register */
3726 if (fp_reg_operand (operand0
, mode
)
3727 && ((GET_CODE (operand1
) == MEM
3728 && ! memory_address_p (DFmode
, XEXP (operand1
, 0)))
3729 || ((GET_CODE (operand1
) == SUBREG
3730 && GET_CODE (XEXP (operand1
, 0)) == MEM
3731 && !memory_address_p (DFmode
, XEXP (XEXP (operand1
, 0), 0)))))
3734 if (GET_CODE (operand1
) == SUBREG
)
3735 operand1
= XEXP (operand1
, 0);
3737 /* SCRATCH_REG will hold an address. We want
3738 it in SImode regardless of what mode it was originally given
3740 scratch_reg
= force_mode (SImode
, scratch_reg
);
3742 /* D might not fit in 14 bits either; for such cases load D into
3744 if (!memory_address_p (Pmode
, XEXP (operand1
, 0)))
3746 emit_move_insn (scratch_reg
, XEXP (XEXP (operand1
, 0), 1));
3747 emit_move_insn (scratch_reg
, gen_rtx_fmt_ee (GET_CODE (XEXP (operand1
, 0)),
3749 XEXP (XEXP (operand1
, 0), 0),
3753 emit_move_insn (scratch_reg
, XEXP (operand1
, 0));
3754 emit_insn (gen_rtx_SET (VOIDmode
, operand0
,
3755 gen_rtx_MEM (mode
, scratch_reg
)));
3758 else if (fp_reg_operand (operand1
, mode
)
3759 && ((GET_CODE (operand0
) == MEM
3760 && ! memory_address_p (DFmode
, XEXP (operand0
, 0)))
3761 || ((GET_CODE (operand0
) == SUBREG
)
3762 && GET_CODE (XEXP (operand0
, 0)) == MEM
3763 && !memory_address_p (DFmode
, XEXP (XEXP (operand0
, 0), 0))))
3766 if (GET_CODE (operand0
) == SUBREG
)
3767 operand0
= XEXP (operand0
, 0);
3769 /* SCRATCH_REG will hold an address and maybe the actual data. We want
3770 it in SIMODE regardless of what mode it was originally given
3772 scratch_reg
= force_mode (SImode
, scratch_reg
);
3774 /* D might not fit in 14 bits either; for such cases load D into
3776 if (!memory_address_p (Pmode
, XEXP (operand0
, 0)))
3778 emit_move_insn (scratch_reg
, XEXP (XEXP (operand0
, 0), 1));
3779 emit_move_insn (scratch_reg
, gen_rtx_fmt_ee (GET_CODE (XEXP (operand0
,
3782 XEXP (XEXP (operand0
, 0),
3787 emit_move_insn (scratch_reg
, XEXP (operand0
, 0));
3788 emit_insn (gen_rtx_SET (VOIDmode
, gen_rtx_MEM (mode
, scratch_reg
),
3792 /* Handle secondary reloads for loads of FP registers from constant
3793 expressions by forcing the constant into memory.
3795 use scratch_reg to hold the address of the memory location.
3797 The proper fix is to change PREFERRED_RELOAD_CLASS to return
3798 NO_REGS when presented with a const_int and an register class
3799 containing only FP registers. Doing so unfortunately creates
3800 more problems than it solves. Fix this for 2.5. */
3801 else if (fp_reg_operand (operand0
, mode
)
3802 && CONSTANT_P (operand1
)
3807 /* SCRATCH_REG will hold an address and maybe the actual data. We want
3808 it in SIMODE regardless of what mode it was originally given
3810 scratch_reg
= force_mode (SImode
, scratch_reg
);
3812 /* Force the constant into memory and put the address of the
3813 memory location into scratch_reg. */
3814 xoperands
[0] = scratch_reg
;
3815 xoperands
[1] = XEXP (force_const_mem (mode
, operand1
), 0);
3816 emit_insn (gen_rtx_SET (mode
, scratch_reg
, xoperands
[1]));
3818 /* Now load the destination register. */
3819 emit_insn (gen_rtx_SET (mode
, operand0
,
3820 gen_rtx_MEM (mode
, scratch_reg
)));
3824 /* Now have insn-emit do whatever it normally does. */
3828 /* Split one or more DImode RTL references into pairs of SImode
3829 references. The RTL can be REG, offsettable MEM, integer constant, or
3830 CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to
3831 split and "num" is its length. lo_half and hi_half are output arrays
3832 that parallel "operands". */
3835 split_di (rtx operands
[], int num
, rtx lo_half
[], rtx hi_half
[])
3839 rtx op
= operands
[num
];
3841 /* simplify_subreg refuses to split volatile memory addresses,
3842 but we still have to handle it. */
3843 if (GET_CODE (op
) == MEM
)
3845 lo_half
[num
] = adjust_address (op
, SImode
, 4);
3846 hi_half
[num
] = adjust_address (op
, SImode
, 0);
3850 lo_half
[num
] = simplify_gen_subreg (SImode
, op
,
3851 GET_MODE (op
) == VOIDmode
3852 ? DImode
: GET_MODE (op
), 4);
3853 hi_half
[num
] = simplify_gen_subreg (SImode
, op
,
3854 GET_MODE (op
) == VOIDmode
3855 ? DImode
: GET_MODE (op
), 0);
3860 /* Split X into a base and a constant offset, storing them in *BASE
3861 and *OFFSET respectively. */
3864 m68k_split_offset (rtx x
, rtx
*base
, HOST_WIDE_INT
*offset
)
3867 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3869 *offset
+= INTVAL (XEXP (x
, 1));
3875 /* Return true if PATTERN is a PARALLEL suitable for a movem or fmovem
3876 instruction. STORE_P says whether the move is a load or store.
3878 If the instruction uses post-increment or pre-decrement addressing,
3879 AUTOMOD_BASE is the base register and AUTOMOD_OFFSET is the total
3880 adjustment. This adjustment will be made by the first element of
3881 PARALLEL, with the loads or stores starting at element 1. If the
3882 instruction does not use post-increment or pre-decrement addressing,
3883 AUTOMOD_BASE is null, AUTOMOD_OFFSET is 0, and the loads or stores
3884 start at element 0. */
3887 m68k_movem_pattern_p (rtx pattern
, rtx automod_base
,
3888 HOST_WIDE_INT automod_offset
, bool store_p
)
3890 rtx base
, mem_base
, set
, mem
, reg
, last_reg
;
3891 HOST_WIDE_INT offset
, mem_offset
;
3893 enum reg_class rclass
;
3895 len
= XVECLEN (pattern
, 0);
3896 first
= (automod_base
!= NULL
);
3900 /* Stores must be pre-decrement and loads must be post-increment. */
3901 if (store_p
!= (automod_offset
< 0))
3904 /* Work out the base and offset for lowest memory location. */
3905 base
= automod_base
;
3906 offset
= (automod_offset
< 0 ? automod_offset
: 0);
3910 /* Allow any valid base and offset in the first access. */
3917 for (i
= first
; i
< len
; i
++)
3919 /* We need a plain SET. */
3920 set
= XVECEXP (pattern
, 0, i
);
3921 if (GET_CODE (set
) != SET
)
3924 /* Check that we have a memory location... */
3925 mem
= XEXP (set
, !store_p
);
3926 if (!MEM_P (mem
) || !memory_operand (mem
, VOIDmode
))
3929 /* ...with the right address. */
3932 m68k_split_offset (XEXP (mem
, 0), &base
, &offset
);
3933 /* The ColdFire instruction only allows (An) and (d16,An) modes.
3934 There are no mode restrictions for 680x0 besides the
3935 automodification rules enforced above. */
3937 && !m68k_legitimate_base_reg_p (base
, reload_completed
))
3942 m68k_split_offset (XEXP (mem
, 0), &mem_base
, &mem_offset
);
3943 if (!rtx_equal_p (base
, mem_base
) || offset
!= mem_offset
)
3947 /* Check that we have a register of the required mode and class. */
3948 reg
= XEXP (set
, store_p
);
3950 || !HARD_REGISTER_P (reg
)
3951 || GET_MODE (reg
) != reg_raw_mode
[REGNO (reg
)])
3956 /* The register must belong to RCLASS and have a higher number
3957 than the register in the previous SET. */
3958 if (!TEST_HARD_REG_BIT (reg_class_contents
[rclass
], REGNO (reg
))
3959 || REGNO (last_reg
) >= REGNO (reg
))
3964 /* Work out which register class we need. */
3965 if (INT_REGNO_P (REGNO (reg
)))
3966 rclass
= GENERAL_REGS
;
3967 else if (FP_REGNO_P (REGNO (reg
)))
3974 offset
+= GET_MODE_SIZE (GET_MODE (reg
));
3977 /* If we have an automodification, check whether the final offset is OK. */
3978 if (automod_base
&& offset
!= (automod_offset
< 0 ? 0 : automod_offset
))
3981 /* Reject unprofitable cases. */
3982 if (len
< first
+ (rclass
== FP_REGS
? MIN_FMOVEM_REGS
: MIN_MOVEM_REGS
))
3988 /* Return the assembly code template for a movem or fmovem instruction
3989 whose pattern is given by PATTERN. Store the template's operands
3992 If the instruction uses post-increment or pre-decrement addressing,
3993 AUTOMOD_OFFSET is the total adjustment, otherwise it is 0. STORE_P
3994 is true if this is a store instruction. */
3997 m68k_output_movem (rtx
*operands
, rtx pattern
,
3998 HOST_WIDE_INT automod_offset
, bool store_p
)
4003 gcc_assert (GET_CODE (pattern
) == PARALLEL
);
4005 first
= (automod_offset
!= 0);
4006 for (i
= first
; i
< XVECLEN (pattern
, 0); i
++)
4008 /* When using movem with pre-decrement addressing, register X + D0_REG
4009 is controlled by bit 15 - X. For all other addressing modes,
4010 register X + D0_REG is controlled by bit X. Confusingly, the
4011 register mask for fmovem is in the opposite order to that for
4015 gcc_assert (MEM_P (XEXP (XVECEXP (pattern
, 0, i
), !store_p
)));
4016 gcc_assert (REG_P (XEXP (XVECEXP (pattern
, 0, i
), store_p
)));
4017 regno
= REGNO (XEXP (XVECEXP (pattern
, 0, i
), store_p
));
4018 if (automod_offset
< 0)
4020 if (FP_REGNO_P (regno
))
4021 mask
|= 1 << (regno
- FP0_REG
);
4023 mask
|= 1 << (15 - (regno
- D0_REG
));
4027 if (FP_REGNO_P (regno
))
4028 mask
|= 1 << (7 - (regno
- FP0_REG
));
4030 mask
|= 1 << (regno
- D0_REG
);
4035 if (automod_offset
== 0)
4036 operands
[0] = XEXP (XEXP (XVECEXP (pattern
, 0, first
), !store_p
), 0);
4037 else if (automod_offset
< 0)
4038 operands
[0] = gen_rtx_PRE_DEC (Pmode
, SET_DEST (XVECEXP (pattern
, 0, 0)));
4040 operands
[0] = gen_rtx_POST_INC (Pmode
, SET_DEST (XVECEXP (pattern
, 0, 0)));
4041 operands
[1] = GEN_INT (mask
);
4042 if (FP_REGNO_P (REGNO (XEXP (XVECEXP (pattern
, 0, first
), store_p
))))
4045 return "fmovem %1,%a0";
4047 return "fmovem %a0,%1";
4052 return "movem%.l %1,%a0";
4054 return "movem%.l %a0,%1";
4058 /* Return a REG that occurs in ADDR with coefficient 1.
4059 ADDR can be effectively incremented by incrementing REG. */
4062 find_addr_reg (rtx addr
)
4064 while (GET_CODE (addr
) == PLUS
)
4066 if (GET_CODE (XEXP (addr
, 0)) == REG
)
4067 addr
= XEXP (addr
, 0);
4068 else if (GET_CODE (XEXP (addr
, 1)) == REG
)
4069 addr
= XEXP (addr
, 1);
4070 else if (CONSTANT_P (XEXP (addr
, 0)))
4071 addr
= XEXP (addr
, 1);
4072 else if (CONSTANT_P (XEXP (addr
, 1)))
4073 addr
= XEXP (addr
, 0);
4077 gcc_assert (GET_CODE (addr
) == REG
);
4081 /* Output assembler code to perform a 32-bit 3-operand add. */
4084 output_addsi3 (rtx
*operands
)
4086 if (! operands_match_p (operands
[0], operands
[1]))
4088 if (!ADDRESS_REG_P (operands
[1]))
4090 rtx tmp
= operands
[1];
4092 operands
[1] = operands
[2];
4096 /* These insns can result from reloads to access
4097 stack slots over 64k from the frame pointer. */
4098 if (GET_CODE (operands
[2]) == CONST_INT
4099 && (INTVAL (operands
[2]) < -32768 || INTVAL (operands
[2]) > 32767))
4100 return "move%.l %2,%0\n\tadd%.l %1,%0";
4101 if (GET_CODE (operands
[2]) == REG
)
4102 return MOTOROLA
? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
4103 return MOTOROLA
? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
4105 if (GET_CODE (operands
[2]) == CONST_INT
)
4107 if (INTVAL (operands
[2]) > 0
4108 && INTVAL (operands
[2]) <= 8)
4109 return "addq%.l %2,%0";
4110 if (INTVAL (operands
[2]) < 0
4111 && INTVAL (operands
[2]) >= -8)
4113 operands
[2] = GEN_INT (- INTVAL (operands
[2]));
4114 return "subq%.l %2,%0";
4116 /* On the CPU32 it is faster to use two addql instructions to
4117 add a small integer (8 < N <= 16) to a register.
4118 Likewise for subql. */
4119 if (TUNE_CPU32
&& REG_P (operands
[0]))
4121 if (INTVAL (operands
[2]) > 8
4122 && INTVAL (operands
[2]) <= 16)
4124 operands
[2] = GEN_INT (INTVAL (operands
[2]) - 8);
4125 return "addq%.l #8,%0\n\taddq%.l %2,%0";
4127 if (INTVAL (operands
[2]) < -8
4128 && INTVAL (operands
[2]) >= -16)
4130 operands
[2] = GEN_INT (- INTVAL (operands
[2]) - 8);
4131 return "subq%.l #8,%0\n\tsubq%.l %2,%0";
4134 if (ADDRESS_REG_P (operands
[0])
4135 && INTVAL (operands
[2]) >= -0x8000
4136 && INTVAL (operands
[2]) < 0x8000)
4139 return "add%.w %2,%0";
4141 return MOTOROLA
? "lea (%c2,%0),%0" : "lea %0@(%c2),%0";
4144 return "add%.l %2,%0";
4147 /* Store in cc_status the expressions that the condition codes will
4148 describe after execution of an instruction whose pattern is EXP.
4149 Do not alter them if the instruction would not alter the cc's. */
4151 /* On the 68000, all the insns to store in an address register fail to
4152 set the cc's. However, in some cases these instructions can make it
4153 possibly invalid to use the saved cc's. In those cases we clear out
4154 some or all of the saved cc's so they won't be used. */
4157 notice_update_cc (rtx exp
, rtx insn
)
4159 if (GET_CODE (exp
) == SET
)
4161 if (GET_CODE (SET_SRC (exp
)) == CALL
)
4163 else if (ADDRESS_REG_P (SET_DEST (exp
)))
4165 if (cc_status
.value1
&& modified_in_p (cc_status
.value1
, insn
))
4166 cc_status
.value1
= 0;
4167 if (cc_status
.value2
&& modified_in_p (cc_status
.value2
, insn
))
4168 cc_status
.value2
= 0;
4170 /* fmoves to memory or data registers do not set the condition
4171 codes. Normal moves _do_ set the condition codes, but not in
4172 a way that is appropriate for comparison with 0, because -0.0
4173 would be treated as a negative nonzero number. Note that it
4174 isn't appropriate to conditionalize this restriction on
4175 HONOR_SIGNED_ZEROS because that macro merely indicates whether
4176 we care about the difference between -0.0 and +0.0. */
4177 else if (!FP_REG_P (SET_DEST (exp
))
4178 && SET_DEST (exp
) != cc0_rtx
4179 && (FP_REG_P (SET_SRC (exp
))
4180 || GET_CODE (SET_SRC (exp
)) == FIX
4181 || FLOAT_MODE_P (GET_MODE (SET_DEST (exp
)))))
4183 /* A pair of move insns doesn't produce a useful overall cc. */
4184 else if (!FP_REG_P (SET_DEST (exp
))
4185 && !FP_REG_P (SET_SRC (exp
))
4186 && GET_MODE_SIZE (GET_MODE (SET_SRC (exp
))) > 4
4187 && (GET_CODE (SET_SRC (exp
)) == REG
4188 || GET_CODE (SET_SRC (exp
)) == MEM
4189 || GET_CODE (SET_SRC (exp
)) == CONST_DOUBLE
))
4191 else if (SET_DEST (exp
) != pc_rtx
)
4193 cc_status
.flags
= 0;
4194 cc_status
.value1
= SET_DEST (exp
);
4195 cc_status
.value2
= SET_SRC (exp
);
4198 else if (GET_CODE (exp
) == PARALLEL
4199 && GET_CODE (XVECEXP (exp
, 0, 0)) == SET
)
4201 rtx dest
= SET_DEST (XVECEXP (exp
, 0, 0));
4202 rtx src
= SET_SRC (XVECEXP (exp
, 0, 0));
4204 if (ADDRESS_REG_P (dest
))
4206 else if (dest
!= pc_rtx
)
4208 cc_status
.flags
= 0;
4209 cc_status
.value1
= dest
;
4210 cc_status
.value2
= src
;
4215 if (cc_status
.value2
!= 0
4216 && ADDRESS_REG_P (cc_status
.value2
)
4217 && GET_MODE (cc_status
.value2
) == QImode
)
4219 if (cc_status
.value2
!= 0)
4220 switch (GET_CODE (cc_status
.value2
))
4222 case ASHIFT
: case ASHIFTRT
: case LSHIFTRT
:
4223 case ROTATE
: case ROTATERT
:
4224 /* These instructions always clear the overflow bit, and set
4225 the carry to the bit shifted out. */
4226 cc_status
.flags
|= CC_OVERFLOW_UNUSABLE
| CC_NO_CARRY
;
4229 case PLUS
: case MINUS
: case MULT
:
4230 case DIV
: case UDIV
: case MOD
: case UMOD
: case NEG
:
4231 if (GET_MODE (cc_status
.value2
) != VOIDmode
)
4232 cc_status
.flags
|= CC_NO_OVERFLOW
;
4235 /* (SET r1 (ZERO_EXTEND r2)) on this machine
4236 ends with a move insn moving r2 in r2's mode.
4237 Thus, the cc's are set for r2.
4238 This can set N bit spuriously. */
4239 cc_status
.flags
|= CC_NOT_NEGATIVE
;
4244 if (cc_status
.value1
&& GET_CODE (cc_status
.value1
) == REG
4246 && reg_overlap_mentioned_p (cc_status
.value1
, cc_status
.value2
))
4247 cc_status
.value2
= 0;
4248 if (((cc_status
.value1
&& FP_REG_P (cc_status
.value1
))
4249 || (cc_status
.value2
&& FP_REG_P (cc_status
.value2
))))
4250 cc_status
.flags
= CC_IN_68881
;
4251 if (cc_status
.value2
&& GET_CODE (cc_status
.value2
) == COMPARE
4252 && GET_MODE_CLASS (GET_MODE (XEXP (cc_status
.value2
, 0))) == MODE_FLOAT
)
4254 cc_status
.flags
= CC_IN_68881
;
4255 if (!FP_REG_P (XEXP (cc_status
.value2
, 0)))
4256 cc_status
.flags
|= CC_REVERSED
;
4261 output_move_const_double (rtx
*operands
)
4263 int code
= standard_68881_constant_p (operands
[1]);
4267 static char buf
[40];
4269 sprintf (buf
, "fmovecr #0x%x,%%0", code
& 0xff);
4272 return "fmove%.d %1,%0";
4276 output_move_const_single (rtx
*operands
)
4278 int code
= standard_68881_constant_p (operands
[1]);
4282 static char buf
[40];
4284 sprintf (buf
, "fmovecr #0x%x,%%0", code
& 0xff);
4287 return "fmove%.s %f1,%0";
4290 /* Return nonzero if X, a CONST_DOUBLE, has a value that we can get
4291 from the "fmovecr" instruction.
4292 The value, anded with 0xff, gives the code to use in fmovecr
4293 to get the desired constant. */
4295 /* This code has been fixed for cross-compilation. */
4297 static int inited_68881_table
= 0;
4299 static const char *const strings_68881
[7] = {
4309 static const int codes_68881
[7] = {
4319 REAL_VALUE_TYPE values_68881
[7];
4321 /* Set up values_68881 array by converting the decimal values
4322 strings_68881 to binary. */
4325 init_68881_table (void)
4329 enum machine_mode mode
;
4332 for (i
= 0; i
< 7; i
++)
4336 r
= REAL_VALUE_ATOF (strings_68881
[i
], mode
);
4337 values_68881
[i
] = r
;
4339 inited_68881_table
= 1;
4343 standard_68881_constant_p (rtx x
)
4348 /* fmovecr must be emulated on the 68040 and 68060, so it shouldn't be
4349 used at all on those chips. */
4353 if (! inited_68881_table
)
4354 init_68881_table ();
4356 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
4358 /* Use REAL_VALUES_IDENTICAL instead of REAL_VALUES_EQUAL so that -0.0
4360 for (i
= 0; i
< 6; i
++)
4362 if (REAL_VALUES_IDENTICAL (r
, values_68881
[i
]))
4363 return (codes_68881
[i
]);
4366 if (GET_MODE (x
) == SFmode
)
4369 if (REAL_VALUES_EQUAL (r
, values_68881
[6]))
4370 return (codes_68881
[6]);
4372 /* larger powers of ten in the constants ram are not used
4373 because they are not equal to a `double' C constant. */
4377 /* If X is a floating-point constant, return the logarithm of X base 2,
4378 or 0 if X is not a power of 2. */
4381 floating_exact_log2 (rtx x
)
4383 REAL_VALUE_TYPE r
, r1
;
4386 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
4388 if (REAL_VALUES_LESS (r
, dconst1
))
4391 exp
= real_exponent (&r
);
4392 real_2expN (&r1
, exp
, DFmode
);
4393 if (REAL_VALUES_EQUAL (r1
, r
))
4399 /* A C compound statement to output to stdio stream STREAM the
4400 assembler syntax for an instruction operand X. X is an RTL
4403 CODE is a value that can be used to specify one of several ways
4404 of printing the operand. It is used when identical operands
4405 must be printed differently depending on the context. CODE
4406 comes from the `%' specification that was used to request
4407 printing of the operand. If the specification was just `%DIGIT'
4408 then CODE is 0; if the specification was `%LTR DIGIT' then CODE
4409 is the ASCII code for LTR.
4411 If X is a register, this macro should print the register's name.
4412 The names can be found in an array `reg_names' whose type is
4413 `char *[]'. `reg_names' is initialized from `REGISTER_NAMES'.
4415 When the machine description has a specification `%PUNCT' (a `%'
4416 followed by a punctuation character), this macro is called with
4417 a null pointer for X and the punctuation character for CODE.
4419 The m68k specific codes are:
4421 '.' for dot needed in Motorola-style opcode names.
4422 '-' for an operand pushing on the stack:
4423 sp@-, -(sp) or -(%sp) depending on the style of syntax.
4424 '+' for an operand pushing on the stack:
4425 sp@+, (sp)+ or (%sp)+ depending on the style of syntax.
4426 '@' for a reference to the top word on the stack:
4427 sp@, (sp) or (%sp) depending on the style of syntax.
4428 '#' for an immediate operand prefix (# in MIT and Motorola syntax
4429 but & in SGS syntax).
4430 '!' for the cc register (used in an `and to cc' insn).
4431 '$' for the letter `s' in an op code, but only on the 68040.
4432 '&' for the letter `d' in an op code, but only on the 68040.
4433 '/' for register prefix needed by longlong.h.
4434 '?' for m68k_library_id_string
4436 'b' for byte insn (no effect, on the Sun; this is for the ISI).
4437 'd' to force memory addressing to be absolute, not relative.
4438 'f' for float insn (print a CONST_DOUBLE as a float rather than in hex)
4439 'x' for float insn (print a CONST_DOUBLE as a float rather than in hex),
4440 or print pair of registers as rx:ry.
4441 'p' print an address with @PLTPC attached, but only if the operand
4442 is not locally-bound. */
4445 print_operand (FILE *file
, rtx op
, int letter
)
4450 fprintf (file
, ".");
4452 else if (letter
== '#')
4453 asm_fprintf (file
, "%I");
4454 else if (letter
== '-')
4455 asm_fprintf (file
, MOTOROLA
? "-(%Rsp)" : "%Rsp@-");
4456 else if (letter
== '+')
4457 asm_fprintf (file
, MOTOROLA
? "(%Rsp)+" : "%Rsp@+");
4458 else if (letter
== '@')
4459 asm_fprintf (file
, MOTOROLA
? "(%Rsp)" : "%Rsp@");
4460 else if (letter
== '!')
4461 asm_fprintf (file
, "%Rfpcr");
4462 else if (letter
== '$')
4465 fprintf (file
, "s");
4467 else if (letter
== '&')
4470 fprintf (file
, "d");
4472 else if (letter
== '/')
4473 asm_fprintf (file
, "%R");
4474 else if (letter
== '?')
4475 asm_fprintf (file
, m68k_library_id_string
);
4476 else if (letter
== 'p')
4478 output_addr_const (file
, op
);
4479 if (!(GET_CODE (op
) == SYMBOL_REF
&& SYMBOL_REF_LOCAL_P (op
)))
4480 fprintf (file
, "@PLTPC");
4482 else if (GET_CODE (op
) == REG
)
4485 /* Print out the second register name of a register pair.
4486 I.e., R (6) => 7. */
4487 fputs (M68K_REGNAME(REGNO (op
) + 1), file
);
4489 fputs (M68K_REGNAME(REGNO (op
)), file
);
4491 else if (GET_CODE (op
) == MEM
)
4493 output_address (XEXP (op
, 0));
4494 if (letter
== 'd' && ! TARGET_68020
4495 && CONSTANT_ADDRESS_P (XEXP (op
, 0))
4496 && !(GET_CODE (XEXP (op
, 0)) == CONST_INT
4497 && INTVAL (XEXP (op
, 0)) < 0x8000
4498 && INTVAL (XEXP (op
, 0)) >= -0x8000))
4499 fprintf (file
, MOTOROLA
? ".l" : ":l");
4501 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == SFmode
)
4505 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
4506 REAL_VALUE_TO_TARGET_SINGLE (r
, l
);
4507 asm_fprintf (file
, "%I0x%lx", l
& 0xFFFFFFFF);
4509 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == XFmode
)
4513 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
4514 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r
, l
);
4515 asm_fprintf (file
, "%I0x%lx%08lx%08lx", l
[0] & 0xFFFFFFFF,
4516 l
[1] & 0xFFFFFFFF, l
[2] & 0xFFFFFFFF);
4518 else if (GET_CODE (op
) == CONST_DOUBLE
&& GET_MODE (op
) == DFmode
)
4522 REAL_VALUE_FROM_CONST_DOUBLE (r
, op
);
4523 REAL_VALUE_TO_TARGET_DOUBLE (r
, l
);
4524 asm_fprintf (file
, "%I0x%lx%08lx", l
[0] & 0xFFFFFFFF, l
[1] & 0xFFFFFFFF);
4528 /* Use `print_operand_address' instead of `output_addr_const'
4529 to ensure that we print relevant PIC stuff. */
4530 asm_fprintf (file
, "%I");
4532 && (GET_CODE (op
) == SYMBOL_REF
|| GET_CODE (op
) == CONST
))
4533 print_operand_address (file
, op
);
4535 output_addr_const (file
, op
);
4539 /* Return string for TLS relocation RELOC. */
4542 m68k_get_reloc_decoration (enum m68k_reloc reloc
)
4544 /* To my knowledge, !MOTOROLA assemblers don't support TLS. */
4545 gcc_assert (MOTOROLA
|| reloc
== RELOC_GOT
);
4552 if (flag_pic
== 1 && TARGET_68020
)
4593 /* m68k implementation of OUTPUT_ADDR_CONST_EXTRA. */
4596 m68k_output_addr_const_extra (FILE *file
, rtx x
)
4598 if (GET_CODE (x
) == UNSPEC
)
4600 switch (XINT (x
, 1))
4602 case UNSPEC_RELOC16
:
4603 case UNSPEC_RELOC32
:
4604 output_addr_const (file
, XVECEXP (x
, 0, 0));
4605 fputs (m68k_get_reloc_decoration
4606 ((enum m68k_reloc
) INTVAL (XVECEXP (x
, 0, 1))), file
);
4617 /* M68K implementation of TARGET_ASM_OUTPUT_DWARF_DTPREL. */
4620 m68k_output_dwarf_dtprel (FILE *file
, int size
, rtx x
)
4622 gcc_assert (size
== 4);
4623 fputs ("\t.long\t", file
);
4624 output_addr_const (file
, x
);
4625 fputs ("@TLSLDO+0x8000", file
);
4628 /* In the name of slightly smaller debug output, and to cater to
4629 general assembler lossage, recognize various UNSPEC sequences
4630 and turn them back into a direct symbol reference. */
4633 m68k_delegitimize_address (rtx orig_x
)
4636 rtx addend
= NULL_RTX
;
4639 orig_x
= delegitimize_mem_from_attrs (orig_x
);
4640 if (! MEM_P (orig_x
))
4643 x
= XEXP (orig_x
, 0);
4645 if (GET_CODE (x
) == PLUS
4646 && GET_CODE (XEXP (x
, 1)) == CONST
4647 && REG_P (XEXP (x
, 0))
4648 && REGNO (XEXP (x
, 0)) == PIC_REG
)
4650 y
= x
= XEXP (XEXP (x
, 1), 0);
4652 /* Handle an addend. */
4653 if ((GET_CODE (x
) == PLUS
|| GET_CODE (x
) == MINUS
)
4654 && CONST_INT_P (XEXP (x
, 1)))
4656 addend
= XEXP (x
, 1);
4660 if (GET_CODE (x
) == UNSPEC
4661 && (XINT (x
, 1) == UNSPEC_RELOC16
4662 || XINT (x
, 1) == UNSPEC_RELOC32
))
4664 result
= XVECEXP (x
, 0, 0);
4667 if (GET_CODE (y
) == PLUS
)
4668 result
= gen_rtx_PLUS (Pmode
, result
, addend
);
4670 result
= gen_rtx_MINUS (Pmode
, result
, addend
);
4671 result
= gen_rtx_CONST (Pmode
, result
);
4681 /* A C compound statement to output to stdio stream STREAM the
4682 assembler syntax for an instruction operand that is a memory
4683 reference whose address is ADDR. ADDR is an RTL expression.
4685 Note that this contains a kludge that knows that the only reason
4686 we have an address (plus (label_ref...) (reg...)) when not generating
4687 PIC code is in the insn before a tablejump, and we know that m68k.md
4688 generates a label LInnn: on such an insn.
4690 It is possible for PIC to generate a (plus (label_ref...) (reg...))
4691 and we handle that just like we would a (plus (symbol_ref...) (reg...)).
4693 This routine is responsible for distinguishing between -fpic and -fPIC
4694 style relocations in an address. When generating -fpic code the
4695 offset is output in word mode (e.g. movel a5@(_foo:w), a0). When generating
4696 -fPIC code the offset is output in long mode (e.g. movel a5@(_foo:l), a0) */
4699 print_operand_address (FILE *file
, rtx addr
)
4701 struct m68k_address address
;
4703 if (!m68k_decompose_address (QImode
, addr
, true, &address
))
4706 if (address
.code
== PRE_DEC
)
4707 fprintf (file
, MOTOROLA
? "-(%s)" : "%s@-",
4708 M68K_REGNAME (REGNO (address
.base
)));
4709 else if (address
.code
== POST_INC
)
4710 fprintf (file
, MOTOROLA
? "(%s)+" : "%s@+",
4711 M68K_REGNAME (REGNO (address
.base
)));
4712 else if (!address
.base
&& !address
.index
)
4714 /* A constant address. */
4715 gcc_assert (address
.offset
== addr
);
4716 if (GET_CODE (addr
) == CONST_INT
)
4718 /* (xxx).w or (xxx).l. */
4719 if (IN_RANGE (INTVAL (addr
), -0x8000, 0x7fff))
4720 fprintf (file
, MOTOROLA
? "%d.w" : "%d:w", (int) INTVAL (addr
));
4722 fprintf (file
, HOST_WIDE_INT_PRINT_DEC
, INTVAL (addr
));
4724 else if (TARGET_PCREL
)
4726 /* (d16,PC) or (bd,PC,Xn) (with suppressed index register). */
4728 output_addr_const (file
, addr
);
4729 asm_fprintf (file
, flag_pic
== 1 ? ":w,%Rpc)" : ":l,%Rpc)");
4733 /* (xxx).l. We need a special case for SYMBOL_REF if the symbol
4734 name ends in `.<letter>', as the last 2 characters can be
4735 mistaken as a size suffix. Put the name in parentheses. */
4736 if (GET_CODE (addr
) == SYMBOL_REF
4737 && strlen (XSTR (addr
, 0)) > 2
4738 && XSTR (addr
, 0)[strlen (XSTR (addr
, 0)) - 2] == '.')
4741 output_addr_const (file
, addr
);
4745 output_addr_const (file
, addr
);
4752 /* If ADDR is a (d8,pc,Xn) address, this is the number of the
4753 label being accessed, otherwise it is -1. */
4754 labelno
= (address
.offset
4756 && GET_CODE (address
.offset
) == LABEL_REF
4757 ? CODE_LABEL_NUMBER (XEXP (address
.offset
, 0))
4761 /* Print the "offset(base" component. */
4763 asm_fprintf (file
, "%LL%d(%Rpc,", labelno
);
4767 output_addr_const (file
, address
.offset
);
4771 fputs (M68K_REGNAME (REGNO (address
.base
)), file
);
4773 /* Print the ",index" component, if any. */
4778 fprintf (file
, "%s.%c",
4779 M68K_REGNAME (REGNO (address
.index
)),
4780 GET_MODE (address
.index
) == HImode
? 'w' : 'l');
4781 if (address
.scale
!= 1)
4782 fprintf (file
, "*%d", address
.scale
);
4786 else /* !MOTOROLA */
4788 if (!address
.offset
&& !address
.index
)
4789 fprintf (file
, "%s@", M68K_REGNAME (REGNO (address
.base
)));
4792 /* Print the "base@(offset" component. */
4794 asm_fprintf (file
, "%Rpc@(%LL%d", labelno
);
4798 fputs (M68K_REGNAME (REGNO (address
.base
)), file
);
4799 fprintf (file
, "@(");
4801 output_addr_const (file
, address
.offset
);
4803 /* Print the ",index" component, if any. */
4806 fprintf (file
, ",%s:%c",
4807 M68K_REGNAME (REGNO (address
.index
)),
4808 GET_MODE (address
.index
) == HImode
? 'w' : 'l');
4809 if (address
.scale
!= 1)
4810 fprintf (file
, ":%d", address
.scale
);
4818 /* Check for cases where a clr insns can be omitted from code using
4819 strict_low_part sets. For example, the second clrl here is not needed:
4820 clrl d0; movw a0@+,d0; use d0; clrl d0; movw a0@+; use d0; ...
4822 MODE is the mode of this STRICT_LOW_PART set. FIRST_INSN is the clear
4823 insn we are checking for redundancy. TARGET is the register set by the
4827 strict_low_part_peephole_ok (enum machine_mode mode
, rtx first_insn
,
4832 while ((p
= PREV_INSN (p
)))
4834 if (NOTE_INSN_BASIC_BLOCK_P (p
))
4840 /* If it isn't an insn, then give up. */
4844 if (reg_set_p (target
, p
))
4846 rtx set
= single_set (p
);
4849 /* If it isn't an easy to recognize insn, then give up. */
4853 dest
= SET_DEST (set
);
4855 /* If this sets the entire target register to zero, then our
4856 first_insn is redundant. */
4857 if (rtx_equal_p (dest
, target
)
4858 && SET_SRC (set
) == const0_rtx
)
4860 else if (GET_CODE (dest
) == STRICT_LOW_PART
4861 && GET_CODE (XEXP (dest
, 0)) == REG
4862 && REGNO (XEXP (dest
, 0)) == REGNO (target
)
4863 && (GET_MODE_SIZE (GET_MODE (XEXP (dest
, 0)))
4864 <= GET_MODE_SIZE (mode
)))
4865 /* This is a strict low part set which modifies less than
4866 we are using, so it is safe. */
4876 /* Operand predicates for implementing asymmetric pc-relative addressing
4877 on m68k. The m68k supports pc-relative addressing (mode 7, register 2)
4878 when used as a source operand, but not as a destination operand.
4880 We model this by restricting the meaning of the basic predicates
4881 (general_operand, memory_operand, etc) to forbid the use of this
4882 addressing mode, and then define the following predicates that permit
4883 this addressing mode. These predicates can then be used for the
4884 source operands of the appropriate instructions.
4886 n.b. While it is theoretically possible to change all machine patterns
4887 to use this addressing more where permitted by the architecture,
4888 it has only been implemented for "common" cases: SImode, HImode, and
4889 QImode operands, and only for the principle operations that would
4890 require this addressing mode: data movement and simple integer operations.
4892 In parallel with these new predicates, two new constraint letters
4893 were defined: 'S' and 'T'. 'S' is the -mpcrel analog of 'm'.
4894 'T' replaces 's' in the non-pcrel case. It is a no-op in the pcrel case.
4895 In the pcrel case 's' is only valid in combination with 'a' registers.
4896 See addsi3, subsi3, cmpsi, and movsi patterns for a better understanding
4897 of how these constraints are used.
4899 The use of these predicates is strictly optional, though patterns that
4900 don't will cause an extra reload register to be allocated where one
4903 lea (abc:w,%pc),%a0 ; need to reload address
4904 moveq &1,%d1 ; since write to pc-relative space
4905 movel %d1,%a0@ ; is not allowed
4907 lea (abc:w,%pc),%a1 ; no need to reload address here
4908 movel %a1@,%d0 ; since "movel (abc:w,%pc),%d0" is ok
4910 For more info, consult tiemann@cygnus.com.
4913 All of the ugliness with predicates and constraints is due to the
4914 simple fact that the m68k does not allow a pc-relative addressing
4915 mode as a destination. gcc does not distinguish between source and
4916 destination addresses. Hence, if we claim that pc-relative address
4917 modes are valid, e.g. TARGET_LEGITIMATE_ADDRESS_P accepts them, then we
4918 end up with invalid code. To get around this problem, we left
4919 pc-relative modes as invalid addresses, and then added special
4920 predicates and constraints to accept them.
4922 A cleaner way to handle this is to modify gcc to distinguish
4923 between source and destination addresses. We can then say that
4924 pc-relative is a valid source address but not a valid destination
4925 address, and hopefully avoid a lot of the predicate and constraint
4926 hackery. Unfortunately, this would be a pretty big change. It would
4927 be a useful change for a number of ports, but there aren't any current
4928 plans to undertake this.
4930 ***************************************************************************/
4934 output_andsi3 (rtx
*operands
)
4937 if (GET_CODE (operands
[2]) == CONST_INT
4938 && (INTVAL (operands
[2]) | 0xffff) == -1
4939 && (DATA_REG_P (operands
[0])
4940 || offsettable_memref_p (operands
[0]))
4941 && !TARGET_COLDFIRE
)
4943 if (GET_CODE (operands
[0]) != REG
)
4944 operands
[0] = adjust_address (operands
[0], HImode
, 2);
4945 operands
[2] = GEN_INT (INTVAL (operands
[2]) & 0xffff);
4946 /* Do not delete a following tstl %0 insn; that would be incorrect. */
4948 if (operands
[2] == const0_rtx
)
4950 return "and%.w %2,%0";
4952 if (GET_CODE (operands
[2]) == CONST_INT
4953 && (logval
= exact_log2 (~ INTVAL (operands
[2]) & 0xffffffff)) >= 0
4954 && (DATA_REG_P (operands
[0])
4955 || offsettable_memref_p (operands
[0])))
4957 if (DATA_REG_P (operands
[0]))
4958 operands
[1] = GEN_INT (logval
);
4961 operands
[0] = adjust_address (operands
[0], SImode
, 3 - (logval
/ 8));
4962 operands
[1] = GEN_INT (logval
% 8);
4964 /* This does not set condition codes in a standard way. */
4966 return "bclr %1,%0";
4968 return "and%.l %2,%0";
4972 output_iorsi3 (rtx
*operands
)
4974 register int logval
;
4975 if (GET_CODE (operands
[2]) == CONST_INT
4976 && INTVAL (operands
[2]) >> 16 == 0
4977 && (DATA_REG_P (operands
[0])
4978 || offsettable_memref_p (operands
[0]))
4979 && !TARGET_COLDFIRE
)
4981 if (GET_CODE (operands
[0]) != REG
)
4982 operands
[0] = adjust_address (operands
[0], HImode
, 2);
4983 /* Do not delete a following tstl %0 insn; that would be incorrect. */
4985 if (INTVAL (operands
[2]) == 0xffff)
4986 return "mov%.w %2,%0";
4987 return "or%.w %2,%0";
4989 if (GET_CODE (operands
[2]) == CONST_INT
4990 && (logval
= exact_log2 (INTVAL (operands
[2]) & 0xffffffff)) >= 0
4991 && (DATA_REG_P (operands
[0])
4992 || offsettable_memref_p (operands
[0])))
4994 if (DATA_REG_P (operands
[0]))
4995 operands
[1] = GEN_INT (logval
);
4998 operands
[0] = adjust_address (operands
[0], SImode
, 3 - (logval
/ 8));
4999 operands
[1] = GEN_INT (logval
% 8);
5002 return "bset %1,%0";
5004 return "or%.l %2,%0";
5008 output_xorsi3 (rtx
*operands
)
5010 register int logval
;
5011 if (GET_CODE (operands
[2]) == CONST_INT
5012 && INTVAL (operands
[2]) >> 16 == 0
5013 && (offsettable_memref_p (operands
[0]) || DATA_REG_P (operands
[0]))
5014 && !TARGET_COLDFIRE
)
5016 if (! DATA_REG_P (operands
[0]))
5017 operands
[0] = adjust_address (operands
[0], HImode
, 2);
5018 /* Do not delete a following tstl %0 insn; that would be incorrect. */
5020 if (INTVAL (operands
[2]) == 0xffff)
5022 return "eor%.w %2,%0";
5024 if (GET_CODE (operands
[2]) == CONST_INT
5025 && (logval
= exact_log2 (INTVAL (operands
[2]) & 0xffffffff)) >= 0
5026 && (DATA_REG_P (operands
[0])
5027 || offsettable_memref_p (operands
[0])))
5029 if (DATA_REG_P (operands
[0]))
5030 operands
[1] = GEN_INT (logval
);
5033 operands
[0] = adjust_address (operands
[0], SImode
, 3 - (logval
/ 8));
5034 operands
[1] = GEN_INT (logval
% 8);
5037 return "bchg %1,%0";
5039 return "eor%.l %2,%0";
5042 /* Return the instruction that should be used for a call to address X,
5043 which is known to be in operand 0. */
5048 if (symbolic_operand (x
, VOIDmode
))
5049 return m68k_symbolic_call
;
5054 /* Likewise sibling calls. */
5057 output_sibcall (rtx x
)
5059 if (symbolic_operand (x
, VOIDmode
))
5060 return m68k_symbolic_jump
;
5066 m68k_output_mi_thunk (FILE *file
, tree thunk ATTRIBUTE_UNUSED
,
5067 HOST_WIDE_INT delta
, HOST_WIDE_INT vcall_offset
,
5070 rtx this_slot
, offset
, addr
, mem
, insn
, tmp
;
5072 /* Avoid clobbering the struct value reg by using the
5073 static chain reg as a temporary. */
5074 tmp
= gen_rtx_REG (Pmode
, STATIC_CHAIN_REGNUM
);
5076 /* Pretend to be a post-reload pass while generating rtl. */
5077 reload_completed
= 1;
5079 /* The "this" pointer is stored at 4(%sp). */
5080 this_slot
= gen_rtx_MEM (Pmode
, plus_constant (stack_pointer_rtx
, 4));
5082 /* Add DELTA to THIS. */
5085 /* Make the offset a legitimate operand for memory addition. */
5086 offset
= GEN_INT (delta
);
5087 if ((delta
< -8 || delta
> 8)
5088 && (TARGET_COLDFIRE
|| USE_MOVQ (delta
)))
5090 emit_move_insn (gen_rtx_REG (Pmode
, D0_REG
), offset
);
5091 offset
= gen_rtx_REG (Pmode
, D0_REG
);
5093 emit_insn (gen_add3_insn (copy_rtx (this_slot
),
5094 copy_rtx (this_slot
), offset
));
5097 /* If needed, add *(*THIS + VCALL_OFFSET) to THIS. */
5098 if (vcall_offset
!= 0)
5100 /* Set the static chain register to *THIS. */
5101 emit_move_insn (tmp
, this_slot
);
5102 emit_move_insn (tmp
, gen_rtx_MEM (Pmode
, tmp
));
5104 /* Set ADDR to a legitimate address for *THIS + VCALL_OFFSET. */
5105 addr
= plus_constant (tmp
, vcall_offset
);
5106 if (!m68k_legitimate_address_p (Pmode
, addr
, true))
5108 emit_insn (gen_rtx_SET (VOIDmode
, tmp
, addr
));
5112 /* Load the offset into %d0 and add it to THIS. */
5113 emit_move_insn (gen_rtx_REG (Pmode
, D0_REG
),
5114 gen_rtx_MEM (Pmode
, addr
));
5115 emit_insn (gen_add3_insn (copy_rtx (this_slot
),
5116 copy_rtx (this_slot
),
5117 gen_rtx_REG (Pmode
, D0_REG
)));
5120 /* Jump to the target function. Use a sibcall if direct jumps are
5121 allowed, otherwise load the address into a register first. */
5122 mem
= DECL_RTL (function
);
5123 if (!sibcall_operand (XEXP (mem
, 0), VOIDmode
))
5125 gcc_assert (flag_pic
);
5127 if (!TARGET_SEP_DATA
)
5129 /* Use the static chain register as a temporary (call-clobbered)
5130 GOT pointer for this function. We can use the static chain
5131 register because it isn't live on entry to the thunk. */
5132 SET_REGNO (pic_offset_table_rtx
, STATIC_CHAIN_REGNUM
);
5133 emit_insn (gen_load_got (pic_offset_table_rtx
));
5135 legitimize_pic_address (XEXP (mem
, 0), Pmode
, tmp
);
5136 mem
= replace_equiv_address (mem
, tmp
);
5138 insn
= emit_call_insn (gen_sibcall (mem
, const0_rtx
));
5139 SIBLING_CALL_P (insn
) = 1;
5141 /* Run just enough of rest_of_compilation. */
5142 insn
= get_insns ();
5143 split_all_insns_noflow ();
5144 final_start_function (insn
, file
, 1);
5145 final (insn
, file
, 1);
5146 final_end_function ();
5148 /* Clean up the vars set above. */
5149 reload_completed
= 0;
5151 /* Restore the original PIC register. */
5153 SET_REGNO (pic_offset_table_rtx
, PIC_REG
);
5156 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
5159 m68k_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED
,
5160 int incoming ATTRIBUTE_UNUSED
)
5162 return gen_rtx_REG (Pmode
, M68K_STRUCT_VALUE_REGNUM
);
5165 /* Return nonzero if register old_reg can be renamed to register new_reg. */
5167 m68k_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED
,
5168 unsigned int new_reg
)
5171 /* Interrupt functions can only use registers that have already been
5172 saved by the prologue, even if they would normally be
5175 if ((m68k_get_function_kind (current_function_decl
)
5176 == m68k_fk_interrupt_handler
)
5177 && !df_regs_ever_live_p (new_reg
))
5183 /* Value is true if hard register REGNO can hold a value of machine-mode
5184 MODE. On the 68000, we let the cpu registers can hold any mode, but
5185 restrict the 68881 registers to floating-point modes. */
5188 m68k_regno_mode_ok (int regno
, enum machine_mode mode
)
5190 if (DATA_REGNO_P (regno
))
5192 /* Data Registers, can hold aggregate if fits in. */
5193 if (regno
+ GET_MODE_SIZE (mode
) / 4 <= 8)
5196 else if (ADDRESS_REGNO_P (regno
))
5198 if (regno
+ GET_MODE_SIZE (mode
) / 4 <= 16)
5201 else if (FP_REGNO_P (regno
))
5203 /* FPU registers, hold float or complex float of long double or
5205 if ((GET_MODE_CLASS (mode
) == MODE_FLOAT
5206 || GET_MODE_CLASS (mode
) == MODE_COMPLEX_FLOAT
)
5207 && GET_MODE_UNIT_SIZE (mode
) <= TARGET_FP_REG_SIZE
)
5213 /* Implement SECONDARY_RELOAD_CLASS. */
5216 m68k_secondary_reload_class (enum reg_class rclass
,
5217 enum machine_mode mode
, rtx x
)
5221 regno
= true_regnum (x
);
5223 /* If one operand of a movqi is an address register, the other
5224 operand must be a general register or constant. Other types
5225 of operand must be reloaded through a data register. */
5226 if (GET_MODE_SIZE (mode
) == 1
5227 && reg_classes_intersect_p (rclass
, ADDR_REGS
)
5228 && !(INT_REGNO_P (regno
) || CONSTANT_P (x
)))
5231 /* PC-relative addresses must be loaded into an address register first. */
5233 && !reg_class_subset_p (rclass
, ADDR_REGS
)
5234 && symbolic_operand (x
, VOIDmode
))
5240 /* Implement PREFERRED_RELOAD_CLASS. */
5243 m68k_preferred_reload_class (rtx x
, enum reg_class rclass
)
5245 enum reg_class secondary_class
;
5247 /* If RCLASS might need a secondary reload, try restricting it to
5248 a class that doesn't. */
5249 secondary_class
= m68k_secondary_reload_class (rclass
, GET_MODE (x
), x
);
5250 if (secondary_class
!= NO_REGS
5251 && reg_class_subset_p (secondary_class
, rclass
))
5252 return secondary_class
;
5254 /* Prefer to use moveq for in-range constants. */
5255 if (GET_CODE (x
) == CONST_INT
5256 && reg_class_subset_p (DATA_REGS
, rclass
)
5257 && IN_RANGE (INTVAL (x
), -0x80, 0x7f))
5260 /* ??? Do we really need this now? */
5261 if (GET_CODE (x
) == CONST_DOUBLE
5262 && GET_MODE_CLASS (GET_MODE (x
)) == MODE_FLOAT
)
5264 if (TARGET_HARD_FLOAT
&& reg_class_subset_p (FP_REGS
, rclass
))
5273 /* Return floating point values in a 68881 register. This makes 68881 code
5274 a little bit faster. It also makes -msoft-float code incompatible with
5275 hard-float code, so people have to be careful not to mix the two.
5276 For ColdFire it was decided the ABI incompatibility is undesirable.
5277 If there is need for a hard-float ABI it is probably worth doing it
5278 properly and also passing function arguments in FP registers. */
5280 m68k_libcall_value (enum machine_mode mode
)
5287 return gen_rtx_REG (mode
, FP0_REG
);
5293 return gen_rtx_REG (mode
, m68k_libcall_value_in_a0_p
? A0_REG
: D0_REG
);
5296 /* Location in which function value is returned.
5297 NOTE: Due to differences in ABIs, don't call this function directly,
5298 use FUNCTION_VALUE instead. */
5300 m68k_function_value (const_tree valtype
, const_tree func ATTRIBUTE_UNUSED
)
5302 enum machine_mode mode
;
5304 mode
= TYPE_MODE (valtype
);
5310 return gen_rtx_REG (mode
, FP0_REG
);
5316 /* If the function returns a pointer, push that into %a0. */
5317 if (func
&& POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (func
))))
5318 /* For compatibility with the large body of existing code which
5319 does not always properly declare external functions returning
5320 pointer types, the m68k/SVR4 convention is to copy the value
5321 returned for pointer functions from a0 to d0 in the function
5322 epilogue, so that callers that have neglected to properly
5323 declare the callee can still find the correct return value in
5325 return gen_rtx_PARALLEL
5328 gen_rtx_EXPR_LIST (VOIDmode
,
5329 gen_rtx_REG (mode
, A0_REG
),
5331 gen_rtx_EXPR_LIST (VOIDmode
,
5332 gen_rtx_REG (mode
, D0_REG
),
5334 else if (POINTER_TYPE_P (valtype
))
5335 return gen_rtx_REG (mode
, A0_REG
);
5337 return gen_rtx_REG (mode
, D0_REG
);
5340 /* Worker function for TARGET_RETURN_IN_MEMORY. */
5341 #if M68K_HONOR_TARGET_STRICT_ALIGNMENT
5343 m68k_return_in_memory (const_tree type
, const_tree fntype ATTRIBUTE_UNUSED
)
5345 enum machine_mode mode
= TYPE_MODE (type
);
5347 if (mode
== BLKmode
)
5350 /* If TYPE's known alignment is less than the alignment of MODE that
5351 would contain the structure, then return in memory. We need to
5352 do so to maintain the compatibility between code compiled with
5353 -mstrict-align and that compiled with -mno-strict-align. */
5354 if (AGGREGATE_TYPE_P (type
)
5355 && TYPE_ALIGN (type
) < GET_MODE_ALIGNMENT (mode
))
5362 /* CPU to schedule the program for. */
5363 enum attr_cpu m68k_sched_cpu
;
5365 /* MAC to schedule the program for. */
5366 enum attr_mac m68k_sched_mac
;
5374 /* Integer register. */
5380 /* Implicit mem reference (e.g. stack). */
5383 /* Memory without offset or indexing. EA modes 2, 3 and 4. */
5386 /* Memory with offset but without indexing. EA mode 5. */
5389 /* Memory with indexing. EA mode 6. */
5392 /* Memory referenced by absolute address. EA mode 7. */
5395 /* Immediate operand that doesn't require extension word. */
5398 /* Immediate 16 bit operand. */
5401 /* Immediate 32 bit operand. */
5405 /* Return type of memory ADDR_RTX refers to. */
5406 static enum attr_op_type
5407 sched_address_type (enum machine_mode mode
, rtx addr_rtx
)
5409 struct m68k_address address
;
5411 if (symbolic_operand (addr_rtx
, VOIDmode
))
5412 return OP_TYPE_MEM7
;
5414 if (!m68k_decompose_address (mode
, addr_rtx
,
5415 reload_completed
, &address
))
5417 gcc_assert (!reload_completed
);
5418 /* Reload will likely fix the address to be in the register. */
5419 return OP_TYPE_MEM234
;
5422 if (address
.scale
!= 0)
5423 return OP_TYPE_MEM6
;
5425 if (address
.base
!= NULL_RTX
)
5427 if (address
.offset
== NULL_RTX
)
5428 return OP_TYPE_MEM234
;
5430 return OP_TYPE_MEM5
;
5433 gcc_assert (address
.offset
!= NULL_RTX
);
5435 return OP_TYPE_MEM7
;
5438 /* Return X or Y (depending on OPX_P) operand of INSN. */
5440 sched_get_operand (rtx insn
, bool opx_p
)
5444 if (recog_memoized (insn
) < 0)
5447 extract_constrain_insn_cached (insn
);
5450 i
= get_attr_opx (insn
);
5452 i
= get_attr_opy (insn
);
5454 if (i
>= recog_data
.n_operands
)
5457 return recog_data
.operand
[i
];
5460 /* Return type of INSN's operand X (if OPX_P) or operand Y (if !OPX_P).
5461 If ADDRESS_P is true, return type of memory location operand refers to. */
5462 static enum attr_op_type
5463 sched_attr_op_type (rtx insn
, bool opx_p
, bool address_p
)
5467 op
= sched_get_operand (insn
, opx_p
);
5471 gcc_assert (!reload_completed
);
5476 return sched_address_type (QImode
, op
);
5478 if (memory_operand (op
, VOIDmode
))
5479 return sched_address_type (GET_MODE (op
), XEXP (op
, 0));
5481 if (register_operand (op
, VOIDmode
))
5483 if ((!reload_completed
&& FLOAT_MODE_P (GET_MODE (op
)))
5484 || (reload_completed
&& FP_REG_P (op
)))
5490 if (GET_CODE (op
) == CONST_INT
)
5496 /* Check for quick constants. */
5497 switch (get_attr_type (insn
))
5500 if (IN_RANGE (ival
, 1, 8) || IN_RANGE (ival
, -8, -1))
5501 return OP_TYPE_IMM_Q
;
5503 gcc_assert (!reload_completed
);
5507 if (USE_MOVQ (ival
))
5508 return OP_TYPE_IMM_Q
;
5510 gcc_assert (!reload_completed
);
5514 if (valid_mov3q_const (ival
))
5515 return OP_TYPE_IMM_Q
;
5517 gcc_assert (!reload_completed
);
5524 if (IN_RANGE (ival
, -0x8000, 0x7fff))
5525 return OP_TYPE_IMM_W
;
5527 return OP_TYPE_IMM_L
;
5530 if (GET_CODE (op
) == CONST_DOUBLE
)
5532 switch (GET_MODE (op
))
5535 return OP_TYPE_IMM_W
;
5539 return OP_TYPE_IMM_L
;
5546 if (GET_CODE (op
) == CONST
5547 || symbolic_operand (op
, VOIDmode
)
5550 switch (GET_MODE (op
))
5553 return OP_TYPE_IMM_Q
;
5556 return OP_TYPE_IMM_W
;
5559 return OP_TYPE_IMM_L
;
5562 if (symbolic_operand (m68k_unwrap_symbol (op
, false), VOIDmode
))
5564 return OP_TYPE_IMM_W
;
5566 return OP_TYPE_IMM_L
;
5570 gcc_assert (!reload_completed
);
5572 if (FLOAT_MODE_P (GET_MODE (op
)))
5578 /* Implement opx_type attribute.
5579 Return type of INSN's operand X.
5580 If ADDRESS_P is true, return type of memory location operand refers to. */
5582 m68k_sched_attr_opx_type (rtx insn
, int address_p
)
5584 switch (sched_attr_op_type (insn
, true, address_p
!= 0))
5590 return OPX_TYPE_FPN
;
5593 return OPX_TYPE_MEM1
;
5595 case OP_TYPE_MEM234
:
5596 return OPX_TYPE_MEM234
;
5599 return OPX_TYPE_MEM5
;
5602 return OPX_TYPE_MEM6
;
5605 return OPX_TYPE_MEM7
;
5608 return OPX_TYPE_IMM_Q
;
5611 return OPX_TYPE_IMM_W
;
5614 return OPX_TYPE_IMM_L
;
5621 /* Implement opy_type attribute.
5622 Return type of INSN's operand Y.
5623 If ADDRESS_P is true, return type of memory location operand refers to. */
5625 m68k_sched_attr_opy_type (rtx insn
, int address_p
)
5627 switch (sched_attr_op_type (insn
, false, address_p
!= 0))
5633 return OPY_TYPE_FPN
;
5636 return OPY_TYPE_MEM1
;
5638 case OP_TYPE_MEM234
:
5639 return OPY_TYPE_MEM234
;
5642 return OPY_TYPE_MEM5
;
5645 return OPY_TYPE_MEM6
;
5648 return OPY_TYPE_MEM7
;
5651 return OPY_TYPE_IMM_Q
;
5654 return OPY_TYPE_IMM_W
;
5657 return OPY_TYPE_IMM_L
;
5664 /* Return size of INSN as int. */
5666 sched_get_attr_size_int (rtx insn
)
5670 switch (get_attr_type (insn
))
5673 /* There should be no references to m68k_sched_attr_size for 'ignore'
5687 switch (get_attr_opx_type (insn
))
5693 case OPX_TYPE_MEM234
:
5694 case OPY_TYPE_IMM_Q
:
5699 /* Here we assume that most absolute references are short. */
5701 case OPY_TYPE_IMM_W
:
5705 case OPY_TYPE_IMM_L
:
5713 switch (get_attr_opy_type (insn
))
5719 case OPY_TYPE_MEM234
:
5720 case OPY_TYPE_IMM_Q
:
5725 /* Here we assume that most absolute references are short. */
5727 case OPY_TYPE_IMM_W
:
5731 case OPY_TYPE_IMM_L
:
5741 gcc_assert (!reload_completed
);
5749 /* Return size of INSN as attribute enum value. */
5751 m68k_sched_attr_size (rtx insn
)
5753 switch (sched_get_attr_size_int (insn
))
5769 /* Return operand X or Y (depending on OPX_P) of INSN,
5770 if it is a MEM, or NULL overwise. */
5771 static enum attr_op_type
5772 sched_get_opxy_mem_type (rtx insn
, bool opx_p
)
5776 switch (get_attr_opx_type (insn
))
5781 case OPX_TYPE_IMM_Q
:
5782 case OPX_TYPE_IMM_W
:
5783 case OPX_TYPE_IMM_L
:
5787 case OPX_TYPE_MEM234
:
5790 return OP_TYPE_MEM1
;
5793 return OP_TYPE_MEM6
;
5801 switch (get_attr_opy_type (insn
))
5806 case OPY_TYPE_IMM_Q
:
5807 case OPY_TYPE_IMM_W
:
5808 case OPY_TYPE_IMM_L
:
5812 case OPY_TYPE_MEM234
:
5815 return OP_TYPE_MEM1
;
5818 return OP_TYPE_MEM6
;
5826 /* Implement op_mem attribute. */
5828 m68k_sched_attr_op_mem (rtx insn
)
5830 enum attr_op_type opx
;
5831 enum attr_op_type opy
;
5833 opx
= sched_get_opxy_mem_type (insn
, true);
5834 opy
= sched_get_opxy_mem_type (insn
, false);
5836 if (opy
== OP_TYPE_RN
&& opx
== OP_TYPE_RN
)
5839 if (opy
== OP_TYPE_RN
&& opx
== OP_TYPE_MEM1
)
5841 switch (get_attr_opx_access (insn
))
5857 if (opy
== OP_TYPE_RN
&& opx
== OP_TYPE_MEM6
)
5859 switch (get_attr_opx_access (insn
))
5875 if (opy
== OP_TYPE_MEM1
&& opx
== OP_TYPE_RN
)
5878 if (opy
== OP_TYPE_MEM1
&& opx
== OP_TYPE_MEM1
)
5880 switch (get_attr_opx_access (insn
))
5886 gcc_assert (!reload_completed
);
5891 if (opy
== OP_TYPE_MEM1
&& opx
== OP_TYPE_MEM6
)
5893 switch (get_attr_opx_access (insn
))
5899 gcc_assert (!reload_completed
);
5904 if (opy
== OP_TYPE_MEM6
&& opx
== OP_TYPE_RN
)
5907 if (opy
== OP_TYPE_MEM6
&& opx
== OP_TYPE_MEM1
)
5909 switch (get_attr_opx_access (insn
))
5915 gcc_assert (!reload_completed
);
5920 gcc_assert (opy
== OP_TYPE_MEM6
&& opx
== OP_TYPE_MEM6
);
5921 gcc_assert (!reload_completed
);
5925 /* Jump instructions types. Indexed by INSN_UID.
5926 The same rtl insn can be expanded into different asm instructions
5927 depending on the cc0_status. To properly determine type of jump
5928 instructions we scan instruction stream and map jumps types to this
5930 static enum attr_type
*sched_branch_type
;
5932 /* Return the type of the jump insn. */
5934 m68k_sched_branch_type (rtx insn
)
5936 enum attr_type type
;
5938 type
= sched_branch_type
[INSN_UID (insn
)];
5940 gcc_assert (type
!= 0);
5945 /* Data for ColdFire V4 index bypass.
5946 Producer modifies register that is used as index in consumer with
5950 /* Producer instruction. */
5953 /* Consumer instruction. */
5956 /* Scale of indexed memory access within consumer.
5957 Or zero if bypass should not be effective at the moment. */
5959 } sched_cfv4_bypass_data
;
5961 /* An empty state that is used in m68k_sched_adjust_cost. */
5962 static state_t sched_adjust_cost_state
;
5964 /* Implement adjust_cost scheduler hook.
5965 Return adjusted COST of dependency LINK between DEF_INSN and INSN. */
5967 m68k_sched_adjust_cost (rtx insn
, rtx link ATTRIBUTE_UNUSED
, rtx def_insn
,
5972 if (recog_memoized (def_insn
) < 0
5973 || recog_memoized (insn
) < 0)
5976 if (sched_cfv4_bypass_data
.scale
== 1)
5977 /* Handle ColdFire V4 bypass for indexed address with 1x scale. */
5979 /* haifa-sched.c: insn_cost () calls bypass_p () just before
5980 targetm.sched.adjust_cost (). Hence, we can be relatively sure
5981 that the data in sched_cfv4_bypass_data is up to date. */
5982 gcc_assert (sched_cfv4_bypass_data
.pro
== def_insn
5983 && sched_cfv4_bypass_data
.con
== insn
);
5988 sched_cfv4_bypass_data
.pro
= NULL
;
5989 sched_cfv4_bypass_data
.con
= NULL
;
5990 sched_cfv4_bypass_data
.scale
= 0;
5993 gcc_assert (sched_cfv4_bypass_data
.pro
== NULL
5994 && sched_cfv4_bypass_data
.con
== NULL
5995 && sched_cfv4_bypass_data
.scale
== 0);
5997 /* Don't try to issue INSN earlier than DFA permits.
5998 This is especially useful for instructions that write to memory,
5999 as their true dependence (default) latency is better to be set to 0
6000 to workaround alias analysis limitations.
6001 This is, in fact, a machine independent tweak, so, probably,
6002 it should be moved to haifa-sched.c: insn_cost (). */
6003 delay
= min_insn_conflict_delay (sched_adjust_cost_state
, def_insn
, insn
);
6010 /* Return maximal number of insns that can be scheduled on a single cycle. */
6012 m68k_sched_issue_rate (void)
6014 switch (m68k_sched_cpu
)
6030 /* Maximal length of instruction for current CPU.
6031 E.g. it is 3 for any ColdFire core. */
6032 static int max_insn_size
;
6034 /* Data to model instruction buffer of CPU. */
6037 /* True if instruction buffer model is modeled for current CPU. */
6040 /* Size of the instruction buffer in words. */
6043 /* Number of filled words in the instruction buffer. */
6046 /* Additional information about instruction buffer for CPUs that have
6047 a buffer of instruction records, rather then a plain buffer
6048 of instruction words. */
6049 struct _sched_ib_records
6051 /* Size of buffer in records. */
6054 /* Array to hold data on adjustements made to the size of the buffer. */
6057 /* Index of the above array. */
6061 /* An insn that reserves (marks empty) one word in the instruction buffer. */
6065 static struct _sched_ib sched_ib
;
6067 /* ID of memory unit. */
6068 static int sched_mem_unit_code
;
6070 /* Implementation of the targetm.sched.variable_issue () hook.
6071 It is called after INSN was issued. It returns the number of insns
6072 that can possibly get scheduled on the current cycle.
6073 It is used here to determine the effect of INSN on the instruction
6076 m68k_sched_variable_issue (FILE *sched_dump ATTRIBUTE_UNUSED
,
6077 int sched_verbose ATTRIBUTE_UNUSED
,
6078 rtx insn
, int can_issue_more
)
6082 if (recog_memoized (insn
) >= 0 && get_attr_type (insn
) != TYPE_IGNORE
)
6084 switch (m68k_sched_cpu
)
6088 insn_size
= sched_get_attr_size_int (insn
);
6092 insn_size
= sched_get_attr_size_int (insn
);
6094 /* ColdFire V3 and V4 cores have instruction buffers that can
6095 accumulate up to 8 instructions regardless of instructions'
6096 sizes. So we should take care not to "prefetch" 24 one-word
6097 or 12 two-words instructions.
6098 To model this behavior we temporarily decrease size of the
6099 buffer by (max_insn_size - insn_size) for next 7 instructions. */
6103 adjust
= max_insn_size
- insn_size
;
6104 sched_ib
.size
-= adjust
;
6106 if (sched_ib
.filled
> sched_ib
.size
)
6107 sched_ib
.filled
= sched_ib
.size
;
6109 sched_ib
.records
.adjust
[sched_ib
.records
.adjust_index
] = adjust
;
6112 ++sched_ib
.records
.adjust_index
;
6113 if (sched_ib
.records
.adjust_index
== sched_ib
.records
.n_insns
)
6114 sched_ib
.records
.adjust_index
= 0;
6116 /* Undo adjustement we did 7 instructions ago. */
6118 += sched_ib
.records
.adjust
[sched_ib
.records
.adjust_index
];
6123 gcc_assert (!sched_ib
.enabled_p
);
6131 gcc_assert (insn_size
<= sched_ib
.filled
);
6134 else if (GET_CODE (PATTERN (insn
)) == ASM_INPUT
6135 || asm_noperands (PATTERN (insn
)) >= 0)
6136 insn_size
= sched_ib
.filled
;
6140 sched_ib
.filled
-= insn_size
;
6142 return can_issue_more
;
6145 /* Return how many instructions should scheduler lookahead to choose the
6148 m68k_sched_first_cycle_multipass_dfa_lookahead (void)
6150 return m68k_sched_issue_rate () - 1;
6153 /* Implementation of targetm.sched.init_global () hook.
6154 It is invoked once per scheduling pass and is used here
6155 to initialize scheduler constants. */
6157 m68k_sched_md_init_global (FILE *sched_dump ATTRIBUTE_UNUSED
,
6158 int sched_verbose ATTRIBUTE_UNUSED
,
6159 int n_insns ATTRIBUTE_UNUSED
)
6161 /* Init branch types. */
6165 sched_branch_type
= XCNEWVEC (enum attr_type
, get_max_uid () + 1);
6167 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
6170 /* !!! FIXME: Implement real scan here. */
6171 sched_branch_type
[INSN_UID (insn
)] = TYPE_BCC
;
6175 #ifdef ENABLE_CHECKING
6176 /* Check that all instructions have DFA reservations and
6177 that all instructions can be issued from a clean state. */
6182 state
= alloca (state_size ());
6184 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
6186 if (INSN_P (insn
) && recog_memoized (insn
) >= 0)
6188 gcc_assert (insn_has_dfa_reservation_p (insn
));
6190 state_reset (state
);
6191 if (state_transition (state
, insn
) >= 0)
6198 /* Setup target cpu. */
6200 /* ColdFire V4 has a set of features to keep its instruction buffer full
6201 (e.g., a separate memory bus for instructions) and, hence, we do not model
6202 buffer for this CPU. */
6203 sched_ib
.enabled_p
= (m68k_sched_cpu
!= CPU_CFV4
);
6205 switch (m68k_sched_cpu
)
6208 sched_ib
.filled
= 0;
6215 sched_ib
.records
.n_insns
= 0;
6216 sched_ib
.records
.adjust
= NULL
;
6221 sched_ib
.records
.n_insns
= 8;
6222 sched_ib
.records
.adjust
= XNEWVEC (int, sched_ib
.records
.n_insns
);
6229 sched_mem_unit_code
= get_cpu_unit_code ("cf_mem1");
6231 sched_adjust_cost_state
= xmalloc (state_size ());
6232 state_reset (sched_adjust_cost_state
);
6235 emit_insn (gen_ib ());
6236 sched_ib
.insn
= get_insns ();
6240 /* Scheduling pass is now finished. Free/reset static variables. */
6242 m68k_sched_md_finish_global (FILE *dump ATTRIBUTE_UNUSED
,
6243 int verbose ATTRIBUTE_UNUSED
)
6245 sched_ib
.insn
= NULL
;
6247 free (sched_adjust_cost_state
);
6248 sched_adjust_cost_state
= NULL
;
6250 sched_mem_unit_code
= 0;
6252 free (sched_ib
.records
.adjust
);
6253 sched_ib
.records
.adjust
= NULL
;
6254 sched_ib
.records
.n_insns
= 0;
6257 free (sched_branch_type
);
6258 sched_branch_type
= NULL
;
6261 /* Implementation of targetm.sched.init () hook.
6262 It is invoked each time scheduler starts on the new block (basic block or
6263 extended basic block). */
6265 m68k_sched_md_init (FILE *sched_dump ATTRIBUTE_UNUSED
,
6266 int sched_verbose ATTRIBUTE_UNUSED
,
6267 int n_insns ATTRIBUTE_UNUSED
)
6269 switch (m68k_sched_cpu
)
6277 sched_ib
.size
= sched_ib
.records
.n_insns
* max_insn_size
;
6279 memset (sched_ib
.records
.adjust
, 0,
6280 sched_ib
.records
.n_insns
* sizeof (*sched_ib
.records
.adjust
));
6281 sched_ib
.records
.adjust_index
= 0;
6285 gcc_assert (!sched_ib
.enabled_p
);
6293 if (sched_ib
.enabled_p
)
6294 /* haifa-sched.c: schedule_block () calls advance_cycle () just before
6295 the first cycle. Workaround that. */
6296 sched_ib
.filled
= -2;
6299 /* Implementation of targetm.sched.dfa_pre_advance_cycle () hook.
6300 It is invoked just before current cycle finishes and is used here
6301 to track if instruction buffer got its two words this cycle. */
6303 m68k_sched_dfa_pre_advance_cycle (void)
6305 if (!sched_ib
.enabled_p
)
6308 if (!cpu_unit_reservation_p (curr_state
, sched_mem_unit_code
))
6310 sched_ib
.filled
+= 2;
6312 if (sched_ib
.filled
> sched_ib
.size
)
6313 sched_ib
.filled
= sched_ib
.size
;
6317 /* Implementation of targetm.sched.dfa_post_advance_cycle () hook.
6318 It is invoked just after new cycle begins and is used here
6319 to setup number of filled words in the instruction buffer so that
6320 instructions which won't have all their words prefetched would be
6321 stalled for a cycle. */
6323 m68k_sched_dfa_post_advance_cycle (void)
6327 if (!sched_ib
.enabled_p
)
6330 /* Setup number of prefetched instruction words in the instruction
6332 i
= max_insn_size
- sched_ib
.filled
;
6336 if (state_transition (curr_state
, sched_ib
.insn
) >= 0)
6341 /* Return X or Y (depending on OPX_P) operand of INSN,
6342 if it is an integer register, or NULL overwise. */
6344 sched_get_reg_operand (rtx insn
, bool opx_p
)
6350 if (get_attr_opx_type (insn
) == OPX_TYPE_RN
)
6352 op
= sched_get_operand (insn
, true);
6353 gcc_assert (op
!= NULL
);
6355 if (!reload_completed
&& !REG_P (op
))
6361 if (get_attr_opy_type (insn
) == OPY_TYPE_RN
)
6363 op
= sched_get_operand (insn
, false);
6364 gcc_assert (op
!= NULL
);
6366 if (!reload_completed
&& !REG_P (op
))
6374 /* Return true, if X or Y (depending on OPX_P) operand of INSN
6377 sched_mem_operand_p (rtx insn
, bool opx_p
)
6379 switch (sched_get_opxy_mem_type (insn
, opx_p
))
6390 /* Return X or Y (depending on OPX_P) operand of INSN,
6391 if it is a MEM, or NULL overwise. */
6393 sched_get_mem_operand (rtx insn
, bool must_read_p
, bool must_write_p
)
6413 if (opy_p
&& sched_mem_operand_p (insn
, false))
6414 return sched_get_operand (insn
, false);
6416 if (opx_p
&& sched_mem_operand_p (insn
, true))
6417 return sched_get_operand (insn
, true);
6423 /* Return non-zero if PRO modifies register used as part of
6426 m68k_sched_address_bypass_p (rtx pro
, rtx con
)
6431 pro_x
= sched_get_reg_operand (pro
, true);
6435 con_mem_read
= sched_get_mem_operand (con
, true, false);
6436 gcc_assert (con_mem_read
!= NULL
);
6438 if (reg_mentioned_p (pro_x
, con_mem_read
))
6444 /* Helper function for m68k_sched_indexed_address_bypass_p.
6445 if PRO modifies register used as index in CON,
6446 return scale of indexed memory access in CON. Return zero overwise. */
6448 sched_get_indexed_address_scale (rtx pro
, rtx con
)
6452 struct m68k_address address
;
6454 reg
= sched_get_reg_operand (pro
, true);
6458 mem
= sched_get_mem_operand (con
, true, false);
6459 gcc_assert (mem
!= NULL
&& MEM_P (mem
));
6461 if (!m68k_decompose_address (GET_MODE (mem
), XEXP (mem
, 0), reload_completed
,
6465 if (REGNO (reg
) == REGNO (address
.index
))
6467 gcc_assert (address
.scale
!= 0);
6468 return address
.scale
;
6474 /* Return non-zero if PRO modifies register used
6475 as index with scale 2 or 4 in CON. */
6477 m68k_sched_indexed_address_bypass_p (rtx pro
, rtx con
)
6479 gcc_assert (sched_cfv4_bypass_data
.pro
== NULL
6480 && sched_cfv4_bypass_data
.con
== NULL
6481 && sched_cfv4_bypass_data
.scale
== 0);
6483 switch (sched_get_indexed_address_scale (pro
, con
))
6486 /* We can't have a variable latency bypass, so
6487 remember to adjust the insn cost in adjust_cost hook. */
6488 sched_cfv4_bypass_data
.pro
= pro
;
6489 sched_cfv4_bypass_data
.con
= con
;
6490 sched_cfv4_bypass_data
.scale
= 1;
6502 /* We generate a two-instructions program at M_TRAMP :
6503 movea.l &CHAIN_VALUE,%a0
6505 where %a0 can be modified by changing STATIC_CHAIN_REGNUM. */
6508 m68k_trampoline_init (rtx m_tramp
, tree fndecl
, rtx chain_value
)
6510 rtx fnaddr
= XEXP (DECL_RTL (fndecl
), 0);
6513 gcc_assert (ADDRESS_REGNO_P (STATIC_CHAIN_REGNUM
));
6515 mem
= adjust_address (m_tramp
, HImode
, 0);
6516 emit_move_insn (mem
, GEN_INT(0x207C + ((STATIC_CHAIN_REGNUM
-8) << 9)));
6517 mem
= adjust_address (m_tramp
, SImode
, 2);
6518 emit_move_insn (mem
, chain_value
);
6520 mem
= adjust_address (m_tramp
, HImode
, 6);
6521 emit_move_insn (mem
, GEN_INT(0x4EF9));
6522 mem
= adjust_address (m_tramp
, SImode
, 8);
6523 emit_move_insn (mem
, fnaddr
);
6525 FINALIZE_TRAMPOLINE (XEXP (m_tramp
, 0));
6528 /* On the 68000, the RTS insn cannot pop anything.
6529 On the 68010, the RTD insn may be used to pop them if the number
6530 of args is fixed, but if the number is variable then the caller
6531 must pop them all. RTD can't be used for library calls now
6532 because the library is compiled with the Unix compiler.
6533 Use of RTD is a selectable option, since it is incompatible with
6534 standard Unix calling sequences. If the option is not selected,
6535 the caller must always pop the args. */
6538 m68k_return_pops_args (tree fundecl
, tree funtype
, int size
)
6542 || TREE_CODE (fundecl
) != IDENTIFIER_NODE
)
6543 && (!stdarg_p (funtype
)))
6547 #include "gt-m68k.h"