* Makefile.in (cse.o): Depend on TARGET_H.
[official-gcc.git] / gcc / config / sh / sh.h
blob7213933ad367316e35acb6b3ea991b7961d50c0f
1 /* Definitions of target machine for GNU compiler for Hitachi / SuperH SH.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003 Free Software Foundation, Inc.
4 Contributed by Steve Chamberlain (sac@cygnus.com).
5 Improved by Jim Wilson (wilson@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 #ifndef GCC_SH_H
25 #define GCC_SH_H
27 #define TARGET_VERSION \
28 fputs (" (Hitachi SH)", stderr);
30 /* Unfortunately, insn-attrtab.c doesn't include insn-codes.h. We can't
31 include it here, because bconfig.h is also included by gencodes.c . */
32 /* ??? No longer true. */
33 extern int code_for_indirect_jump_scratch;
35 #define TARGET_CPU_CPP_BUILTINS() \
36 do { \
37 builtin_define ("__sh__"); \
38 builtin_assert ("cpu=sh"); \
39 builtin_assert ("machine=sh"); \
40 switch ((int) sh_cpu) \
41 { \
42 case PROCESSOR_SH1: \
43 builtin_define ("__sh1__"); \
44 break; \
45 case PROCESSOR_SH2: \
46 builtin_define ("__sh2__"); \
47 break; \
48 case PROCESSOR_SH2E: \
49 builtin_define ("__SH2E__"); \
50 break; \
51 case PROCESSOR_SH3: \
52 builtin_define ("__sh3__"); \
53 builtin_define ("__SH3__"); \
54 if (TARGET_HARD_SH4) \
55 builtin_define ("__SH4_NOFPU__"); \
56 break; \
57 case PROCESSOR_SH3E: \
58 builtin_define (TARGET_HARD_SH4 ? "__SH4_SINGLE_ONLY__" : "__SH3E__"); \
59 break; \
60 case PROCESSOR_SH4: \
61 builtin_define (TARGET_FPU_SINGLE ? "__SH4_SINGLE__" : "__SH4__"); \
62 break; \
63 case PROCESSOR_SH5: \
64 { \
65 builtin_define_with_value ("__SH5__", \
66 TARGET_SHMEDIA64 ? "64" : "32", 0); \
67 builtin_define_with_value ("__SHMEDIA__", \
68 TARGET_SHMEDIA ? "1" : "0", 0); \
69 if (! TARGET_FPU_DOUBLE) \
70 builtin_define ("__SH4_NOFPU__"); \
71 } \
72 } \
73 if (TARGET_HITACHI) \
74 builtin_define ("__HITACHI__"); \
75 builtin_define (TARGET_LITTLE_ENDIAN \
76 ? "__LITTLE_ENDIAN__" : "__BIG_ENDIAN__"); \
77 if (flag_pic) \
78 { \
79 builtin_define ("__pic__"); \
80 builtin_define ("__PIC__"); \
81 } \
82 TARGET_OBJFMT_CPP_BUILTINS (); \
83 } while (0)
85 /* We can not debug without a frame pointer. */
86 /* #define CAN_DEBUG_WITHOUT_FP */
88 #define CONDITIONAL_REGISTER_USAGE do \
89 { \
90 int regno; \
91 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++) \
92 if (! VALID_REGISTER_P (regno)) \
93 fixed_regs[regno] = call_used_regs[regno] = 1; \
94 /* R8 and R9 are call-clobbered on SH5, but not on earlier SH ABIs. */ \
95 if (TARGET_SH5) \
96 call_used_regs[FIRST_GENERAL_REG + 8] \
97 = call_used_regs[FIRST_GENERAL_REG + 9] = 1; \
98 if (TARGET_SHMEDIA) \
99 { \
100 regno_reg_class[FIRST_GENERAL_REG] = GENERAL_REGS; \
101 CLEAR_HARD_REG_SET (reg_class_contents[FP0_REGS]); \
102 regno_reg_class[FIRST_FP_REG] = FP_REGS; \
104 if (flag_pic) \
105 fixed_regs[PIC_OFFSET_TABLE_REGNUM] = 1; \
106 /* Hitachi saves and restores mac registers on call. */ \
107 if (TARGET_HITACHI && ! TARGET_NOMACSAVE) \
109 call_used_regs[MACH_REG] = 0; \
110 call_used_regs[MACL_REG] = 0; \
112 for (regno = FIRST_FP_REG + (TARGET_LITTLE_ENDIAN != 0); \
113 regno <= LAST_FP_REG; regno += 2) \
114 SET_HARD_REG_BIT (reg_class_contents[DF_HI_REGS], regno); \
115 if (TARGET_SHMEDIA) \
117 for (regno = FIRST_TARGET_REG; regno <= LAST_TARGET_REG; regno ++)\
118 if (! fixed_regs[regno] && call_used_regs[regno]) \
119 SET_HARD_REG_BIT (reg_class_contents[SIBCALL_REGS], regno); \
121 else \
122 for (regno = FIRST_GENERAL_REG; regno <= LAST_GENERAL_REG; regno++) \
123 if (! fixed_regs[regno] && call_used_regs[regno]) \
124 SET_HARD_REG_BIT (reg_class_contents[SIBCALL_REGS], regno); \
125 } while (0)
127 /* ??? Need to write documentation for all SH options and add it to the
128 invoke.texi file. */
130 /* Run-time compilation parameters selecting different hardware subsets. */
132 extern int target_flags;
133 #define ISIZE_BIT (1<<1)
134 #define DALIGN_BIT (1<<6)
135 #define SH1_BIT (1<<8)
136 #define SH2_BIT (1<<9)
137 #define SH3_BIT (1<<10)
138 #define SH_E_BIT (1<<11)
139 #define HARD_SH4_BIT (1<<5)
140 #define FPU_SINGLE_BIT (1<<7)
141 #define SH4_BIT (1<<12)
142 #define FMOVD_BIT (1<<4)
143 #define SH5_BIT (1<<0)
144 #define SPACE_BIT (1<<13)
145 #define BIGTABLE_BIT (1<<14)
146 #define RELAX_BIT (1<<15)
147 #define USERMODE_BIT (1<<16)
148 #define HITACHI_BIT (1<<22)
149 #define NOMACSAVE_BIT (1<<23)
150 #define PREFERGOT_BIT (1<<24)
151 #define PADSTRUCT_BIT (1<<28)
152 #define LITTLE_ENDIAN_BIT (1<<29)
153 #define IEEE_BIT (1<<30)
155 /* Nonzero if we should dump out instruction size info. */
156 #define TARGET_DUMPISIZE (target_flags & ISIZE_BIT)
158 /* Nonzero to align doubles on 64 bit boundaries. */
159 #define TARGET_ALIGN_DOUBLE (target_flags & DALIGN_BIT)
161 /* Nonzero if we should generate code using type 1 insns. */
162 #define TARGET_SH1 (target_flags & SH1_BIT)
164 /* Nonzero if we should generate code using type 2 insns. */
165 #define TARGET_SH2 (target_flags & SH2_BIT)
167 /* Nonzero if we should generate code using type 2E insns. */
168 #define TARGET_SH2E ((target_flags & SH_E_BIT) && TARGET_SH2)
170 /* Nonzero if we should generate code using type 3 insns. */
171 #define TARGET_SH3 (target_flags & SH3_BIT)
173 /* Nonzero if we should generate code using type 3E insns. */
174 #define TARGET_SH3E ((target_flags & SH_E_BIT) && TARGET_SH3)
176 /* Nonzero if the cache line size is 32. */
177 #define TARGET_CACHE32 (target_flags & HARD_SH4_BIT || TARGET_SH5)
179 /* Nonzero if we schedule for a superscalar implementation. */
180 #define TARGET_SUPERSCALAR (target_flags & HARD_SH4_BIT)
182 /* Nonzero if the target has separate instruction and data caches. */
183 #define TARGET_HARVARD (target_flags & HARD_SH4_BIT)
185 /* Nonzero if compiling for SH4 hardware (to be used for insn costs etc.) */
186 #define TARGET_HARD_SH4 (target_flags & HARD_SH4_BIT)
188 /* Nonzero if the default precision of th FPU is single */
189 #define TARGET_FPU_SINGLE (target_flags & FPU_SINGLE_BIT)
191 /* Nonzero if a double-precision FPU is available. */
192 #define TARGET_FPU_DOUBLE (target_flags & SH4_BIT)
194 /* Nonzero if an FPU is available. */
195 #define TARGET_FPU_ANY (TARGET_SH2E || TARGET_FPU_DOUBLE)
197 /* Nonzero if we should generate code using type 4 insns. */
198 #define TARGET_SH4 ((target_flags & SH4_BIT) && (target_flags & SH1_BIT))
200 /* Nonzero if we should generate code for a SH5 CPU (either ISA). */
201 #define TARGET_SH5 (target_flags & SH5_BIT)
203 /* Nonzero if we should generate code using the SHcompact instruction
204 set and 32-bit ABI. */
205 #define TARGET_SHCOMPACT (TARGET_SH5 && TARGET_SH1)
207 /* Nonzero if we should generate code using the SHmedia instruction
208 set and ABI. */
209 #define TARGET_SHMEDIA (TARGET_SH5 && ! TARGET_SH1)
211 /* Nonzero if we should generate code using the SHmedia ISA and 32-bit
212 ABI. */
213 #define TARGET_SHMEDIA32 (TARGET_SH5 && ! TARGET_SH1 \
214 && (target_flags & SH_E_BIT))
216 /* Nonzero if we should generate code using the SHmedia ISA and 64-bit
217 ABI. */
218 #define TARGET_SHMEDIA64 (TARGET_SH5 && ! TARGET_SH1 \
219 && ! (target_flags & SH_E_BIT))
221 /* Nonzero if we should generate code using SHmedia FPU instructions. */
222 #define TARGET_SHMEDIA_FPU (TARGET_SHMEDIA && TARGET_FPU_DOUBLE)
223 /* Nonzero if we should generate fmovd. */
224 #define TARGET_FMOVD (target_flags & FMOVD_BIT)
226 /* Nonzero if we respect NANs. */
227 #define TARGET_IEEE (target_flags & IEEE_BIT)
229 /* Nonzero if we should generate smaller code rather than faster code. */
230 #define TARGET_SMALLCODE (target_flags & SPACE_BIT)
232 /* Nonzero to use long jump tables. */
233 #define TARGET_BIGTABLE (target_flags & BIGTABLE_BIT)
235 /* Nonzero to generate pseudo-ops needed by the assembler and linker
236 to do function call relaxing. */
237 #define TARGET_RELAX (target_flags & RELAX_BIT)
239 /* Nonzero if using Hitachi's calling convention. */
240 #define TARGET_HITACHI (target_flags & HITACHI_BIT)
242 /* Nonzero if not saving macl/mach when using -mhitachi */
243 #define TARGET_NOMACSAVE (target_flags & NOMACSAVE_BIT)
245 /* Nonzero if padding structures to a multiple of 4 bytes. This is
246 incompatible with Hitachi's compiler, and gives unusual structure layouts
247 which confuse programmers.
248 ??? This option is not useful, but is retained in case there are people
249 who are still relying on it. It may be deleted in the future. */
250 #define TARGET_PADSTRUCT (target_flags & PADSTRUCT_BIT)
252 /* Nonzero if generating code for a little endian SH. */
253 #define TARGET_LITTLE_ENDIAN (target_flags & LITTLE_ENDIAN_BIT)
255 /* Nonzero if we should do everything in userland. */
256 #define TARGET_USERMODE (target_flags & USERMODE_BIT)
258 /* Nonzero if we should prefer @GOT calls when generating PIC. */
259 #define TARGET_PREFERGOT (target_flags & PREFERGOT_BIT)
261 #define SELECT_SH1 (SH1_BIT)
262 #define SELECT_SH2 (SH2_BIT | SELECT_SH1)
263 #define SELECT_SH2E (SH_E_BIT | SH2_BIT | SH1_BIT | FPU_SINGLE_BIT)
264 #define SELECT_SH3 (SH3_BIT | SELECT_SH2)
265 #define SELECT_SH3E (SH_E_BIT | FPU_SINGLE_BIT | SELECT_SH3)
266 #define SELECT_SH4_NOFPU (HARD_SH4_BIT | SELECT_SH3)
267 #define SELECT_SH4_SINGLE_ONLY (HARD_SH4_BIT | SELECT_SH3E)
268 #define SELECT_SH4 (SH4_BIT | SH_E_BIT | HARD_SH4_BIT | SELECT_SH3)
269 #define SELECT_SH4_SINGLE (FPU_SINGLE_BIT | SELECT_SH4)
270 #define SELECT_SH5_64 (SH5_BIT | SH4_BIT)
271 #define SELECT_SH5_64_NOFPU (SH5_BIT)
272 #define SELECT_SH5_32 (SH5_BIT | SH4_BIT | SH_E_BIT)
273 #define SELECT_SH5_32_NOFPU (SH5_BIT | SH_E_BIT)
274 #define SELECT_SH5_COMPACT (SH5_BIT | SH4_BIT | SELECT_SH3E)
275 #define SELECT_SH5_COMPACT_NOFPU (SH5_BIT | SELECT_SH3)
277 /* Reset all target-selection flags. */
278 #define TARGET_NONE -(SH1_BIT | SH2_BIT | SH3_BIT | SH_E_BIT | SH4_BIT \
279 | HARD_SH4_BIT | FPU_SINGLE_BIT | SH5_BIT)
281 #define TARGET_SWITCHES \
282 { {"1", TARGET_NONE, "" }, \
283 {"1", SELECT_SH1, "" }, \
284 {"2", TARGET_NONE, "" }, \
285 {"2", SELECT_SH2, "" }, \
286 {"2e", TARGET_NONE, "" }, \
287 {"2e", SELECT_SH2E, "" }, \
288 {"3", TARGET_NONE, "" }, \
289 {"3", SELECT_SH3, "" }, \
290 {"3e", TARGET_NONE, "" }, \
291 {"3e", SELECT_SH3E, "" }, \
292 {"4-single-only", TARGET_NONE, "" }, \
293 {"4-single-only", SELECT_SH4_SINGLE_ONLY, "" }, \
294 {"4-single", TARGET_NONE, "" }, \
295 {"4-single", SELECT_SH4_SINGLE, "" }, \
296 {"4-nofpu", TARGET_NONE, "" }, \
297 {"4-nofpu", SELECT_SH4_NOFPU, "" }, \
298 {"4", TARGET_NONE, "" }, \
299 {"4", SELECT_SH4, "" }, \
300 {"5-64media", TARGET_NONE, "" }, \
301 {"5-64media", SELECT_SH5_64, "Generate 64-bit SHmedia code" }, \
302 {"5-64media-nofpu", TARGET_NONE, "" }, \
303 {"5-64media-nofpu", SELECT_SH5_64_NOFPU, "Generate 64-bit FPU-less SHmedia code" }, \
304 {"5-32media", TARGET_NONE, "" }, \
305 {"5-32media", SELECT_SH5_32, "Generate 32-bit SHmedia code" }, \
306 {"5-32media-nofpu", TARGET_NONE, "" }, \
307 {"5-32media-nofpu", SELECT_SH5_32_NOFPU, "Generate 32-bit FPU-less SHmedia code" }, \
308 {"5-compact", TARGET_NONE, "" }, \
309 {"5-compact", SELECT_SH5_COMPACT, "Generate SHcompact code" }, \
310 {"5-compact-nofpu", TARGET_NONE, "" }, \
311 {"5-compact-nofpu", SELECT_SH5_COMPACT_NOFPU, "Generate FPU-less SHcompact code" }, \
312 {"b", -LITTLE_ENDIAN_BIT, "" }, \
313 {"bigtable", BIGTABLE_BIT, "" }, \
314 {"dalign", DALIGN_BIT, "" }, \
315 {"fmovd", FMOVD_BIT, "" }, \
316 {"hitachi", HITACHI_BIT, "" }, \
317 {"nomacsave", NOMACSAVE_BIT, "" }, \
318 {"ieee", IEEE_BIT, "" }, \
319 {"isize", ISIZE_BIT, "" }, \
320 {"l", LITTLE_ENDIAN_BIT, "" }, \
321 {"no-ieee", -IEEE_BIT, "" }, \
322 {"padstruct", PADSTRUCT_BIT, "" }, \
323 {"prefergot", PREFERGOT_BIT, "" }, \
324 {"relax", RELAX_BIT, "" }, \
325 {"space", SPACE_BIT, "" }, \
326 {"usermode", USERMODE_BIT, "" }, \
327 SUBTARGET_SWITCHES \
328 {"", TARGET_DEFAULT, "" } \
331 /* This are meant to be redefined in the host dependent files */
332 #define SUBTARGET_SWITCHES
334 /* This defaults us to big-endian. */
335 #ifndef TARGET_ENDIAN_DEFAULT
336 #define TARGET_ENDIAN_DEFAULT 0
337 #endif
339 #ifndef TARGET_CPU_DEFAULT
340 #define TARGET_CPU_DEFAULT SELECT_SH1
341 #endif
343 #define TARGET_DEFAULT (TARGET_CPU_DEFAULT|TARGET_ENDIAN_DEFAULT)
345 #define CPP_SPEC " %(subtarget_cpp_spec) "
347 #ifndef SUBTARGET_CPP_SPEC
348 #define SUBTARGET_CPP_SPEC ""
349 #endif
351 #ifndef SUBTARGET_EXTRA_SPECS
352 #define SUBTARGET_EXTRA_SPECS
353 #endif
355 #define EXTRA_SPECS \
356 { "subtarget_cpp_spec", SUBTARGET_CPP_SPEC }, \
357 { "link_emul_prefix", LINK_EMUL_PREFIX }, \
358 { "link_default_cpu_emul", LINK_DEFAULT_CPU_EMUL }, \
359 { "subtarget_link_emul_suffix", SUBTARGET_LINK_EMUL_SUFFIX }, \
360 { "subtarget_link_spec", SUBTARGET_LINK_SPEC }, \
361 { "subtarget_asm_endian_spec", SUBTARGET_ASM_ENDIAN_SPEC }, \
362 SUBTARGET_EXTRA_SPECS
364 #define ASM_SPEC "%(subtarget_asm_endian_spec) %{mrelax:-relax}"
366 #ifndef SUBTARGET_ASM_ENDIAN_SPEC
367 #if TARGET_ENDIAN_DEFAULT == LITTLE_ENDIAN_BIT
368 #define SUBTARGET_ASM_ENDIAN_SPEC "%{mb:-big} %{!mb:-little}"
369 #else
370 #define SUBTARGET_ASM_ENDIAN_SPEC "%{ml:-little} %{!ml:-big}"
371 #endif
372 #endif
374 #define LINK_EMUL_PREFIX "sh%{ml:l}"
376 #if TARGET_CPU_DEFAULT & SH5_BIT
377 #if TARGET_CPU_DEFAULT & SH_E_BIT
378 #define LINK_DEFAULT_CPU_EMUL "32"
379 #else
380 #define LINK_DEFAULT_CPU_EMUL "64"
381 #endif /* SH_E_BIT */
382 #else
383 #define LINK_DEFAULT_CPU_EMUL ""
384 #endif /* SH5_BIT */
386 #define SUBTARGET_LINK_EMUL_SUFFIX ""
387 #define SUBTARGET_LINK_SPEC ""
389 /* svr4.h redefines LINK_SPEC inappropriately, so go via SH_LINK_SPEC,
390 so that we can undo the damage without code replication. */
391 #define LINK_SPEC SH_LINK_SPEC
393 #define SH_LINK_SPEC "\
394 -m %(link_emul_prefix)\
395 %{m5-compact*|m5-32media*:32}\
396 %{m5-64media*:64}\
397 %{!m1:%{!m2:%{!m3*:%{!m4*:%{!m5*:%(link_default_cpu_emul)}}}}}\
398 %(subtarget_link_emul_suffix) \
399 %{mrelax:-relax} %(subtarget_link_spec)"
401 #define OPTIMIZATION_OPTIONS(LEVEL,SIZE) \
402 do { \
403 if (LEVEL) \
404 flag_omit_frame_pointer = -1; \
405 if (SIZE) \
406 target_flags |= SPACE_BIT; \
407 } while (0)
409 #define ASSEMBLER_DIALECT assembler_dialect
411 extern int assembler_dialect;
413 #define OVERRIDE_OPTIONS \
414 do { \
415 int regno; \
417 sh_cpu = CPU_SH1; \
418 assembler_dialect = 0; \
419 if (TARGET_SH2) \
420 sh_cpu = CPU_SH2; \
421 if (TARGET_SH2E) \
422 sh_cpu = CPU_SH2E; \
423 if (TARGET_SH3) \
424 sh_cpu = CPU_SH3; \
425 if (TARGET_SH3E) \
426 sh_cpu = CPU_SH3E; \
427 if (TARGET_SH4) \
429 assembler_dialect = 1; \
430 sh_cpu = CPU_SH4; \
432 if (TARGET_SH5) \
434 sh_cpu = CPU_SH5; \
435 target_flags |= DALIGN_BIT; \
436 if (TARGET_FPU_ANY \
437 && ! (TARGET_SHCOMPACT && TARGET_LITTLE_ENDIAN)) \
438 target_flags |= FMOVD_BIT; \
439 if (TARGET_SHMEDIA) \
441 /* There are no delay slots on SHmedia. */ \
442 flag_delayed_branch = 0; \
443 /* Relaxation isn't yet supported for SHmedia */ \
444 target_flags &= ~RELAX_BIT; \
446 if (profile_flag || profile_arc_flag) \
448 warning ("Profiling is not supported on this target."); \
449 profile_flag = profile_arc_flag = 0; \
452 else \
454 /* Only the sh64-elf assembler fully supports .quad properly. */\
455 targetm.asm_out.aligned_op.di = NULL; \
456 targetm.asm_out.unaligned_op.di = NULL; \
458 if (TARGET_FMOVD) \
459 reg_class_from_letter['e'] = NO_REGS; \
461 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) \
462 if (! VALID_REGISTER_P (regno)) \
463 sh_register_names[regno][0] = '\0'; \
465 for (regno = 0; regno < ADDREGNAMES_SIZE; regno++) \
466 if (! VALID_REGISTER_P (ADDREGNAMES_REGNO (regno))) \
467 sh_additional_register_names[regno][0] = '\0'; \
469 if (flag_omit_frame_pointer < 0) \
471 /* The debugging information is sufficient, \
472 but gdb doesn't implement this yet */ \
473 if (0) \
474 flag_omit_frame_pointer \
475 = (PREFERRED_DEBUGGING_TYPE == DWARF_DEBUG \
476 || PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG); \
477 else \
478 flag_omit_frame_pointer = 0; \
481 if (flag_pic && ! TARGET_PREFERGOT) \
482 flag_no_function_cse = 1; \
484 if (SMALL_REGISTER_CLASSES) \
486 /* Never run scheduling before reload, since that can \
487 break global alloc, and generates slower code anyway due \
488 to the pressure on R0. */ \
489 flag_schedule_insns = 0; \
492 /* Allocation boundary (in *bytes*) for the code of a function. \
493 SH1: 32 bit alignment is faster, because instructions are always \
494 fetched as a pair from a longword boundary. \
495 SH2 .. SH5 : align to cache line start. */ \
496 if (align_functions == 0) \
497 align_functions \
498 = TARGET_SMALLCODE ? FUNCTION_BOUNDARY/8 : (1 << CACHE_LOG); \
499 } while (0)
501 /* Target machine storage layout. */
503 /* Define this if most significant bit is lowest numbered
504 in instructions that operate on numbered bit-fields. */
506 #define BITS_BIG_ENDIAN 0
508 /* Define this if most significant byte of a word is the lowest numbered. */
509 #define BYTES_BIG_ENDIAN (TARGET_LITTLE_ENDIAN == 0)
511 /* Define this if most significant word of a multiword number is the lowest
512 numbered. */
513 #define WORDS_BIG_ENDIAN (TARGET_LITTLE_ENDIAN == 0)
515 /* Define this to set the endianness to use in libgcc2.c, which can
516 not depend on target_flags. */
517 #if defined(__LITTLE_ENDIAN__)
518 #define LIBGCC2_WORDS_BIG_ENDIAN 0
519 #else
520 #define LIBGCC2_WORDS_BIG_ENDIAN 1
521 #endif
523 #define MAX_BITS_PER_WORD 64
525 #define MAX_LONG_TYPE_SIZE MAX_BITS_PER_WORD
527 /* Width in bits of an `int'. We want just 32-bits, even if words are
528 longer. */
529 #define INT_TYPE_SIZE 32
531 /* Width in bits of a `long'. */
532 #define LONG_TYPE_SIZE (TARGET_SHMEDIA64 ? 64 : 32)
534 /* Width in bits of a `long long'. */
535 #define LONG_LONG_TYPE_SIZE 64
537 /* Width in bits of a `long double'. */
538 #define LONG_DOUBLE_TYPE_SIZE 64
540 /* Width of a word, in units (bytes). */
541 #define UNITS_PER_WORD (TARGET_SHMEDIA ? 8 : 4)
542 #define MIN_UNITS_PER_WORD 4
544 /* Width in bits of a pointer.
545 See also the macro `Pmode' defined below. */
546 #define POINTER_SIZE (TARGET_SHMEDIA64 ? 64 : 32)
548 /* Allocation boundary (in *bits*) for storing arguments in argument list. */
549 #define PARM_BOUNDARY (TARGET_SH5 ? 64 : 32)
551 /* Boundary (in *bits*) on which stack pointer should be aligned. */
552 #define STACK_BOUNDARY BIGGEST_ALIGNMENT
554 /* The log (base 2) of the cache line size, in bytes. Processors prior to
555 SH2 have no actual cache, but they fetch code in chunks of 4 bytes.
556 The SH2/3 have 16 byte cache lines, and the SH4 has a 32 byte cache line */
557 #define CACHE_LOG (TARGET_CACHE32 ? 5 : TARGET_SH2 ? 4 : 2)
559 /* ABI given & required minimum allocation boundary (in *bits*) for the
560 code of a function. */
561 #define FUNCTION_BOUNDARY (16 << TARGET_SHMEDIA)
563 /* On SH5, the lowest bit is used to indicate SHmedia functions, so
564 the vbit must go into the delta field of
565 pointers-to-member-functions. */
566 #define TARGET_PTRMEMFUNC_VBIT_LOCATION \
567 (TARGET_SH5 ? ptrmemfunc_vbit_in_delta : ptrmemfunc_vbit_in_pfn)
569 /* Alignment of field after `int : 0' in a structure. */
570 #define EMPTY_FIELD_BOUNDARY 32
572 /* No data type wants to be aligned rounder than this. */
573 #define BIGGEST_ALIGNMENT (TARGET_ALIGN_DOUBLE ? 64 : 32)
575 /* The best alignment to use in cases where we have a choice. */
576 #define FASTEST_ALIGNMENT (TARGET_SH5 ? 64 : 32)
578 /* Make strings word-aligned so strcpy from constants will be faster. */
579 #define CONSTANT_ALIGNMENT(EXP, ALIGN) \
580 ((TREE_CODE (EXP) == STRING_CST \
581 && (ALIGN) < FASTEST_ALIGNMENT) \
582 ? FASTEST_ALIGNMENT : (ALIGN))
584 /* Make arrays of chars word-aligned for the same reasons. */
585 #define DATA_ALIGNMENT(TYPE, ALIGN) \
586 (TREE_CODE (TYPE) == ARRAY_TYPE \
587 && TYPE_MODE (TREE_TYPE (TYPE)) == QImode \
588 && (ALIGN) < FASTEST_ALIGNMENT ? FASTEST_ALIGNMENT : (ALIGN))
590 /* Number of bits which any structure or union's size must be a
591 multiple of. Each structure or union's size is rounded up to a
592 multiple of this. */
593 #define STRUCTURE_SIZE_BOUNDARY (TARGET_PADSTRUCT ? 32 : 8)
595 /* Set this nonzero if move instructions will actually fail to work
596 when given unaligned data. */
597 #define STRICT_ALIGNMENT 1
599 /* If LABEL_AFTER_BARRIER demands an alignment, return its base 2 logarithm. */
600 #define LABEL_ALIGN_AFTER_BARRIER(LABEL_AFTER_BARRIER) \
601 barrier_align (LABEL_AFTER_BARRIER)
603 #define LOOP_ALIGN(A_LABEL) \
604 ((! optimize || TARGET_HARVARD || TARGET_SMALLCODE) \
605 ? 0 : sh_loop_align (A_LABEL))
607 #define LABEL_ALIGN(A_LABEL) \
609 (PREV_INSN (A_LABEL) \
610 && GET_CODE (PREV_INSN (A_LABEL)) == INSN \
611 && GET_CODE (PATTERN (PREV_INSN (A_LABEL))) == UNSPEC_VOLATILE \
612 && XINT (PATTERN (PREV_INSN (A_LABEL)), 1) == UNSPECV_ALIGN) \
613 /* explicit alignment insn in constant tables. */ \
614 ? INTVAL (XVECEXP (PATTERN (PREV_INSN (A_LABEL)), 0, 0)) \
615 : 0)
617 /* Jump tables must be 32 bit aligned, no matter the size of the element. */
618 #define ADDR_VEC_ALIGN(ADDR_VEC) 2
620 /* The base two logarithm of the known minimum alignment of an insn length. */
621 #define INSN_LENGTH_ALIGNMENT(A_INSN) \
622 (GET_CODE (A_INSN) == INSN \
623 ? 1 << TARGET_SHMEDIA \
624 : GET_CODE (A_INSN) == JUMP_INSN || GET_CODE (A_INSN) == CALL_INSN \
625 ? 1 << TARGET_SHMEDIA \
626 : CACHE_LOG)
628 /* Standard register usage. */
630 /* Register allocation for the Hitachi calling convention:
632 r0 arg return
633 r1..r3 scratch
634 r4..r7 args in
635 r8..r13 call saved
636 r14 frame pointer/call saved
637 r15 stack pointer
638 ap arg pointer (doesn't really exist, always eliminated)
639 pr subroutine return address
640 t t bit
641 mach multiply/accumulate result, high part
642 macl multiply/accumulate result, low part.
643 fpul fp/int communication register
644 rap return address pointer register
645 fr0 fp arg return
646 fr1..fr3 scratch floating point registers
647 fr4..fr11 fp args in
648 fr12..fr15 call saved floating point registers */
650 #define MAX_REGISTER_NAME_LENGTH 5
651 extern char sh_register_names[][MAX_REGISTER_NAME_LENGTH + 1];
653 #define SH_REGISTER_NAMES_INITIALIZER \
655 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", \
656 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", \
657 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", \
658 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", \
659 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", \
660 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", \
661 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", \
662 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63", \
663 "fr0", "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", \
664 "fr8", "fr9", "fr10", "fr11", "fr12", "fr13", "fr14", "fr15", \
665 "fr16", "fr17", "fr18", "fr19", "fr20", "fr21", "fr22", "fr23", \
666 "fr24", "fr25", "fr26", "fr27", "fr28", "fr29", "fr30", "fr31", \
667 "fr32", "fr33", "fr34", "fr35", "fr36", "fr37", "fr38", "fr39", \
668 "fr40", "fr41", "fr42", "fr43", "fr44", "fr45", "fr46", "fr47", \
669 "fr48", "fr49", "fr50", "fr51", "fr52", "fr53", "fr54", "fr55", \
670 "fr56", "fr57", "fr58", "fr59", "fr60", "fr61", "fr62", "fr63", \
671 "tr0", "tr1", "tr2", "tr3", "tr4", "tr5", "tr6", "tr7", \
672 "xd0", "xd2", "xd4", "xd6", "xd8", "xd10", "xd12", "xd14", \
673 "gbr", "ap", "pr", "t", "mach", "macl", "fpul", "fpscr", \
674 "rap" \
677 #define DEBUG_REGISTER_NAMES SH_REGISTER_NAMES_INITIALIZER
679 #define REGNAMES_ARR_INDEX_1(index) \
680 (sh_register_names[index])
681 #define REGNAMES_ARR_INDEX_2(index) \
682 REGNAMES_ARR_INDEX_1 ((index)), REGNAMES_ARR_INDEX_1 ((index)+1)
683 #define REGNAMES_ARR_INDEX_4(index) \
684 REGNAMES_ARR_INDEX_2 ((index)), REGNAMES_ARR_INDEX_2 ((index)+2)
685 #define REGNAMES_ARR_INDEX_8(index) \
686 REGNAMES_ARR_INDEX_4 ((index)), REGNAMES_ARR_INDEX_4 ((index)+4)
687 #define REGNAMES_ARR_INDEX_16(index) \
688 REGNAMES_ARR_INDEX_8 ((index)), REGNAMES_ARR_INDEX_8 ((index)+8)
689 #define REGNAMES_ARR_INDEX_32(index) \
690 REGNAMES_ARR_INDEX_16 ((index)), REGNAMES_ARR_INDEX_16 ((index)+16)
691 #define REGNAMES_ARR_INDEX_64(index) \
692 REGNAMES_ARR_INDEX_32 ((index)), REGNAMES_ARR_INDEX_32 ((index)+32)
694 #define REGISTER_NAMES \
696 REGNAMES_ARR_INDEX_64 (0), \
697 REGNAMES_ARR_INDEX_64 (64), \
698 REGNAMES_ARR_INDEX_8 (128), \
699 REGNAMES_ARR_INDEX_8 (136), \
700 REGNAMES_ARR_INDEX_8 (144), \
701 REGNAMES_ARR_INDEX_1 (152) \
704 #define ADDREGNAMES_SIZE 32
705 #define MAX_ADDITIONAL_REGISTER_NAME_LENGTH 4
706 extern char sh_additional_register_names[ADDREGNAMES_SIZE] \
707 [MAX_ADDITIONAL_REGISTER_NAME_LENGTH + 1];
709 #define SH_ADDITIONAL_REGISTER_NAMES_INITIALIZER \
711 "dr0", "dr2", "dr4", "dr6", "dr8", "dr10", "dr12", "dr14", \
712 "dr16", "dr18", "dr20", "dr22", "dr24", "dr26", "dr28", "dr30", \
713 "dr32", "dr34", "dr36", "dr38", "dr40", "dr42", "dr44", "dr46", \
714 "dr48", "dr50", "dr52", "dr54", "dr56", "dr58", "dr60", "dr62" \
717 #define ADDREGNAMES_REGNO(index) \
718 ((index < 32) ? (FIRST_FP_REG + (index) * 2) \
719 : (-1))
721 #define ADDREGNAMES_ARR_INDEX_1(index) \
722 { (sh_additional_register_names[index]), ADDREGNAMES_REGNO (index) }
723 #define ADDREGNAMES_ARR_INDEX_2(index) \
724 ADDREGNAMES_ARR_INDEX_1 ((index)), ADDREGNAMES_ARR_INDEX_1 ((index)+1)
725 #define ADDREGNAMES_ARR_INDEX_4(index) \
726 ADDREGNAMES_ARR_INDEX_2 ((index)), ADDREGNAMES_ARR_INDEX_2 ((index)+2)
727 #define ADDREGNAMES_ARR_INDEX_8(index) \
728 ADDREGNAMES_ARR_INDEX_4 ((index)), ADDREGNAMES_ARR_INDEX_4 ((index)+4)
729 #define ADDREGNAMES_ARR_INDEX_16(index) \
730 ADDREGNAMES_ARR_INDEX_8 ((index)), ADDREGNAMES_ARR_INDEX_8 ((index)+8)
731 #define ADDREGNAMES_ARR_INDEX_32(index) \
732 ADDREGNAMES_ARR_INDEX_16 ((index)), ADDREGNAMES_ARR_INDEX_16 ((index)+16)
734 #define ADDITIONAL_REGISTER_NAMES \
736 ADDREGNAMES_ARR_INDEX_32 (0) \
739 /* Number of actual hardware registers.
740 The hardware registers are assigned numbers for the compiler
741 from 0 to just below FIRST_PSEUDO_REGISTER.
742 All registers that the compiler knows about must be given numbers,
743 even those that are not normally considered general registers. */
745 /* There are many other relevant definitions in sh.md's md_constants. */
747 #define FIRST_GENERAL_REG R0_REG
748 #define LAST_GENERAL_REG (FIRST_GENERAL_REG + (TARGET_SHMEDIA ? 63 : 15))
749 #define FIRST_FP_REG DR0_REG
750 #define LAST_FP_REG (FIRST_FP_REG + \
751 (TARGET_SHMEDIA_FPU ? 63 : TARGET_SH2E ? 15 : -1))
752 #define FIRST_XD_REG XD0_REG
753 #define LAST_XD_REG (FIRST_XD_REG + ((TARGET_SH4 && TARGET_FMOVD) ? 7 : -1))
754 #define FIRST_TARGET_REG TR0_REG
755 #define LAST_TARGET_REG (FIRST_TARGET_REG + (TARGET_SHMEDIA ? 7 : -1))
757 #define GENERAL_REGISTER_P(REGNO) \
758 IN_RANGE ((REGNO), FIRST_GENERAL_REG, LAST_GENERAL_REG)
760 #define GENERAL_OR_AP_REGISTER_P(REGNO) \
761 (GENERAL_REGISTER_P (REGNO) || ((REGNO) == AP_REG))
763 #define FP_REGISTER_P(REGNO) \
764 ((REGNO) >= FIRST_FP_REG && (REGNO) <= LAST_FP_REG)
766 #define XD_REGISTER_P(REGNO) \
767 ((REGNO) >= FIRST_XD_REG && (REGNO) <= LAST_XD_REG)
769 #define FP_OR_XD_REGISTER_P(REGNO) \
770 (FP_REGISTER_P (REGNO) || XD_REGISTER_P (REGNO))
772 #define FP_ANY_REGISTER_P(REGNO) \
773 (FP_REGISTER_P (REGNO) || XD_REGISTER_P (REGNO) || (REGNO) == FPUL_REG)
775 #define SPECIAL_REGISTER_P(REGNO) \
776 ((REGNO) == GBR_REG || (REGNO) == T_REG \
777 || (REGNO) == MACH_REG || (REGNO) == MACL_REG)
779 #define TARGET_REGISTER_P(REGNO) \
780 ((REGNO) >= FIRST_TARGET_REG && (REGNO) <= LAST_TARGET_REG)
782 #define SHMEDIA_REGISTER_P(REGNO) \
783 (GENERAL_REGISTER_P (REGNO) || FP_REGISTER_P (REGNO) \
784 || TARGET_REGISTER_P (REGNO))
786 /* This is to be used in CONDITIONAL_REGISTER_USAGE, to mark registers
787 that should be fixed. */
788 #define VALID_REGISTER_P(REGNO) \
789 (SHMEDIA_REGISTER_P (REGNO) || XD_REGISTER_P (REGNO) \
790 || (REGNO) == AP_REG || (REGNO) == RAP_REG \
791 || (TARGET_SH1 && (SPECIAL_REGISTER_P (REGNO) || (REGNO) == PR_REG)) \
792 || (TARGET_SH2E && (REGNO) == FPUL_REG))
794 /* The mode that should be generally used to store a register by
795 itself in the stack, or to load it back. */
796 #define REGISTER_NATURAL_MODE(REGNO) \
797 (FP_REGISTER_P (REGNO) ? SFmode \
798 : XD_REGISTER_P (REGNO) ? DFmode \
799 : TARGET_SHMEDIA && ! HARD_REGNO_CALL_PART_CLOBBERED ((REGNO), DImode) \
800 ? DImode \
801 : SImode)
803 #define FIRST_PSEUDO_REGISTER 153
805 /* 1 for registers that have pervasive standard uses
806 and are not available for the register allocator.
808 Mach register is fixed 'cause it's only 10 bits wide for SH1.
809 It is 32 bits wide for SH2. */
811 #define FIXED_REGISTERS \
813 /* Regular registers. */ \
814 0, 0, 0, 0, 0, 0, 0, 0, \
815 0, 0, 0, 0, 0, 0, 0, 1, \
816 /* r16 is reserved, r18 is the former pr. */ \
817 1, 0, 0, 0, 0, 0, 0, 0, \
818 /* r24 is reserved for the OS; r25, for the assembler or linker. */ \
819 /* r26 is a global variable data pointer; r27 is for constants. */ \
820 1, 1, 1, 1, 0, 0, 0, 0, \
821 0, 0, 0, 0, 0, 0, 0, 0, \
822 0, 0, 0, 0, 0, 0, 0, 0, \
823 0, 0, 0, 0, 0, 0, 0, 0, \
824 0, 0, 0, 0, 0, 0, 0, 1, \
825 /* FP registers. */ \
826 0, 0, 0, 0, 0, 0, 0, 0, \
827 0, 0, 0, 0, 0, 0, 0, 0, \
828 0, 0, 0, 0, 0, 0, 0, 0, \
829 0, 0, 0, 0, 0, 0, 0, 0, \
830 0, 0, 0, 0, 0, 0, 0, 0, \
831 0, 0, 0, 0, 0, 0, 0, 0, \
832 0, 0, 0, 0, 0, 0, 0, 0, \
833 0, 0, 0, 0, 0, 0, 0, 0, \
834 /* Branch target registers. */ \
835 0, 0, 0, 0, 0, 0, 0, 0, \
836 /* XD registers. */ \
837 0, 0, 0, 0, 0, 0, 0, 0, \
838 /*"gbr", "ap", "pr", "t", "mach", "macl", "fpul", "fpscr", */ \
839 1, 1, 1, 1, 1, 1, 0, 1, \
840 /*"rap" */ \
841 1, \
844 /* 1 for registers not available across function calls.
845 These must include the FIXED_REGISTERS and also any
846 registers that can be used without being saved.
847 The latter must include the registers where values are returned
848 and the register where structure-value addresses are passed.
849 Aside from that, you can include as many other registers as you like. */
851 #define CALL_USED_REGISTERS \
853 /* Regular registers. */ \
854 1, 1, 1, 1, 1, 1, 1, 1, \
855 /* R8 and R9 are call-clobbered on SH5, but not on earlier SH ABIs. \
856 Only the lower 32bits of R10-R14 are guaranteed to be preserved \
857 across SH5 function calls. */ \
858 0, 0, 0, 0, 0, 0, 0, 1, \
859 1, 1, 0, 1, 1, 1, 1, 1, \
860 1, 1, 1, 1, 0, 0, 0, 0, \
861 0, 0, 0, 0, 1, 1, 1, 1, \
862 1, 1, 1, 1, 0, 0, 0, 0, \
863 0, 0, 0, 0, 0, 0, 0, 0, \
864 0, 0, 0, 0, 1, 1, 1, 1, \
865 /* FP registers. */ \
866 1, 1, 1, 1, 1, 1, 1, 1, \
867 1, 1, 1, 1, 0, 0, 0, 0, \
868 1, 1, 1, 1, 1, 1, 1, 1, \
869 1, 1, 1, 1, 1, 1, 1, 1, \
870 1, 1, 1, 1, 0, 0, 0, 0, \
871 0, 0, 0, 0, 0, 0, 0, 0, \
872 0, 0, 0, 0, 0, 0, 0, 0, \
873 0, 0, 0, 0, 0, 0, 0, 0, \
874 /* Branch target registers. */ \
875 1, 1, 1, 1, 1, 0, 0, 0, \
876 /* XD registers. */ \
877 1, 1, 1, 1, 1, 1, 0, 0, \
878 /*"gbr", "ap", "pr", "t", "mach", "macl", "fpul", "fpscr", */ \
879 1, 1, 0, 1, 1, 1, 1, 1, \
880 /*"rap" */ \
881 1, \
884 /* Only the lower 32-bits of R10-R14 are guaranteed to be preserved
885 across SHcompact function calls. We can't tell whether a called
886 function is SHmedia or SHcompact, so we assume it may be when
887 compiling SHmedia code with the 32-bit ABI, since that's the only
888 ABI that can be linked with SHcompact code. */
889 #define HARD_REGNO_CALL_PART_CLOBBERED(REGNO,MODE) \
890 (TARGET_SHMEDIA32 \
891 && GET_MODE_SIZE (MODE) > 4 \
892 && (((REGNO) >= FIRST_GENERAL_REG + 10 \
893 && (REGNO) <= FIRST_GENERAL_REG + 14) \
894 || (REGNO) == PR_MEDIA_REG))
896 /* Return number of consecutive hard regs needed starting at reg REGNO
897 to hold something of mode MODE.
898 This is ordinarily the length in words of a value of mode MODE
899 but can be less for certain modes in special long registers.
901 On the SH all but the XD regs are UNITS_PER_WORD bits wide. */
903 #define HARD_REGNO_NREGS(REGNO, MODE) \
904 (XD_REGISTER_P (REGNO) \
905 ? (GET_MODE_SIZE (MODE) / (2 * UNITS_PER_WORD)) \
906 : (TARGET_SHMEDIA && FP_REGISTER_P (REGNO)) \
907 ? ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD/2 - 1) / (UNITS_PER_WORD/2)) \
908 : ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)) \
910 /* Value is 1 if hard register REGNO can hold a value of machine-mode MODE.
911 We can allow any mode in any general register. The special registers
912 only allow SImode. Don't allow any mode in the PR. */
914 /* We cannot hold DCmode values in the XD registers because alter_reg
915 handles subregs of them incorrectly. We could work around this by
916 spacing the XD registers like the DR registers, but this would require
917 additional memory in every compilation to hold larger register vectors.
918 We could hold SFmode / SCmode values in XD registers, but that
919 would require a tertiary reload when reloading from / to memory,
920 and a secondary reload to reload from / to general regs; that
921 seems to be a loosing proposition. */
922 /* We want to allow TImode FP regs so that when V4SFmode is loaded as TImode,
923 it won't be ferried through GP registers first. */
924 #define HARD_REGNO_MODE_OK(REGNO, MODE) \
925 (SPECIAL_REGISTER_P (REGNO) ? (MODE) == SImode \
926 : (REGNO) == FPUL_REG ? (MODE) == SImode || (MODE) == SFmode \
927 : FP_REGISTER_P (REGNO) && (MODE) == SFmode \
928 ? 1 \
929 : (MODE) == V2SFmode \
930 ? ((FP_REGISTER_P (REGNO) && ((REGNO) - FIRST_FP_REG) % 2 == 0) \
931 || GENERAL_REGISTER_P (REGNO)) \
932 : (MODE) == V4SFmode \
933 ? ((FP_REGISTER_P (REGNO) && ((REGNO) - FIRST_FP_REG) % 4 == 0) \
934 || (! TARGET_SHMEDIA && GENERAL_REGISTER_P (REGNO))) \
935 : (MODE) == V16SFmode \
936 ? (TARGET_SHMEDIA \
937 ? (FP_REGISTER_P (REGNO) && ((REGNO) - FIRST_FP_REG) % 16 == 0) \
938 : (REGNO) == FIRST_XD_REG) \
939 : FP_REGISTER_P (REGNO) \
940 ? ((MODE) == SFmode || (MODE) == SImode \
941 || ((TARGET_SH2E || TARGET_SHMEDIA) && (MODE) == SCmode) \
942 || (((TARGET_SH4 && (MODE) == DFmode) || (MODE) == DCmode \
943 || (TARGET_SHMEDIA && ((MODE) == DFmode || (MODE) == DImode \
944 || (MODE) == V2SFmode || (MODE) == TImode))) \
945 && (((REGNO) - FIRST_FP_REG) & 1) == 0)) \
946 : XD_REGISTER_P (REGNO) \
947 ? (MODE) == DFmode \
948 : TARGET_REGISTER_P (REGNO) \
949 ? ((MODE) == DImode || (MODE) == SImode) \
950 : (REGNO) == PR_REG ? 0 \
951 : (REGNO) == FPSCR_REG ? (MODE) == PSImode \
952 : 1)
954 /* Value is 1 if MODE is a supported vector mode. */
955 #define VECTOR_MODE_SUPPORTED_P(MODE) \
956 ((TARGET_FPU_ANY \
957 && ((MODE) == V2SFmode || (MODE) == V4SFmode || (MODE) == V16SFmode)) \
958 || (TARGET_SHMEDIA \
959 && ((MODE) == V8QImode || (MODE) == V2HImode || (MODE) == V4HImode \
960 || (MODE) == V2SImode)))
962 /* Value is 1 if it is a good idea to tie two pseudo registers
963 when one has mode MODE1 and one has mode MODE2.
964 If HARD_REGNO_MODE_OK could produce different values for MODE1 and MODE2,
965 for any hard reg, then this must be 0 for correct output.
966 That's the case for xd registers: we don't hold SFmode values in
967 them, so we can't tie an SFmode pseudos with one in another
968 floating-point mode. */
970 #define MODES_TIEABLE_P(MODE1, MODE2) \
971 ((MODE1) == (MODE2) \
972 || (GET_MODE_CLASS (MODE1) == GET_MODE_CLASS (MODE2) \
973 && (TARGET_SHMEDIA ? ((GET_MODE_SIZE (MODE1) <= 4) \
974 && (GET_MODE_SIZE (MODE2) <= 4)) \
975 : ((MODE1) != SFmode && (MODE2) != SFmode))))
977 /* A C expression that is nonzero if hard register NEW_REG can be
978 considered for use as a rename register for OLD_REG register */
980 #define HARD_REGNO_RENAME_OK(OLD_REG, NEW_REG) \
981 sh_hard_regno_rename_ok (OLD_REG, NEW_REG)
983 /* Specify the registers used for certain standard purposes.
984 The values of these macros are register numbers. */
986 /* Define this if the program counter is overloaded on a register. */
987 /* #define PC_REGNUM 15*/
989 /* Register to use for pushing function arguments. */
990 #define STACK_POINTER_REGNUM SP_REG
992 /* Base register for access to local variables of the function. */
993 #define FRAME_POINTER_REGNUM FP_REG
995 /* Fake register that holds the address on the stack of the
996 current function's return address. */
997 #define RETURN_ADDRESS_POINTER_REGNUM RAP_REG
999 /* Register to hold the addressing base for position independent
1000 code access to data items. */
1001 #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? PIC_REG : INVALID_REGNUM)
1003 #define GOT_SYMBOL_NAME "*_GLOBAL_OFFSET_TABLE_"
1005 /* Value should be nonzero if functions must have frame pointers.
1006 Zero means the frame pointer need not be set up (and parms may be accessed
1007 via the stack pointer) in functions that seem suitable. */
1009 #define FRAME_POINTER_REQUIRED 0
1011 /* Definitions for register eliminations.
1013 We have three registers that can be eliminated on the SH. First, the
1014 frame pointer register can often be eliminated in favor of the stack
1015 pointer register. Secondly, the argument pointer register can always be
1016 eliminated; it is replaced with either the stack or frame pointer.
1017 Third, there is the return address pointer, which can also be replaced
1018 with either the stack or the frame pointer. */
1020 /* This is an array of structures. Each structure initializes one pair
1021 of eliminable registers. The "from" register number is given first,
1022 followed by "to". Eliminations of the same "from" register are listed
1023 in order of preference. */
1025 /* If you add any registers here that are not actually hard registers,
1026 and that have any alternative of elimination that doesn't always
1027 apply, you need to amend calc_live_regs to exclude it, because
1028 reload spills all eliminable registers where it sees an
1029 can_eliminate == 0 entry, thus making them 'live' .
1030 If you add any hard registers that can be eliminated in different
1031 ways, you have to patch reload to spill them only when all alternatives
1032 of elimination fail. */
1034 #define ELIMINABLE_REGS \
1035 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
1036 { RETURN_ADDRESS_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
1037 { RETURN_ADDRESS_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
1038 { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
1039 { ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM},}
1041 /* Given FROM and TO register numbers, say whether this elimination
1042 is allowed. */
1043 #define CAN_ELIMINATE(FROM, TO) \
1044 (!((FROM) == FRAME_POINTER_REGNUM && FRAME_POINTER_REQUIRED))
1046 /* Define the offset between two registers, one to be eliminated, and the other
1047 its replacement, at the start of a routine. */
1049 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
1050 OFFSET = initial_elimination_offset ((FROM), (TO))
1052 /* Base register for access to arguments of the function. */
1053 #define ARG_POINTER_REGNUM AP_REG
1055 /* Register in which the static-chain is passed to a function. */
1056 #define STATIC_CHAIN_REGNUM (TARGET_SH5 ? 1 : 3)
1058 /* The register in which a struct value address is passed. */
1060 #define STRUCT_VALUE_REGNUM 2
1062 /* If the structure value address is not passed in a register, define
1063 `STRUCT_VALUE' as an expression returning an RTX for the place
1064 where the address is passed. If it returns 0, the address is
1065 passed as an "invisible" first argument. */
1067 /* The Hitachi calling convention doesn't quite fit into this scheme since
1068 the address is passed like an invisible argument, but one that is always
1069 passed in memory. */
1070 #define STRUCT_VALUE \
1071 (TARGET_HITACHI ? 0 : gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM))
1073 #define RETURN_IN_MEMORY(TYPE) \
1074 (TARGET_SH5 \
1075 ? ((TYPE_MODE (TYPE) == BLKmode \
1076 ? (unsigned HOST_WIDE_INT) int_size_in_bytes (TYPE) \
1077 : GET_MODE_SIZE (TYPE_MODE (TYPE))) > 8) \
1078 : (TYPE_MODE (TYPE) == BLKmode \
1079 || TARGET_HITACHI && TREE_CODE (TYPE) == RECORD_TYPE))
1081 /* Don't default to pcc-struct-return, because we have already specified
1082 exactly how to return structures in the RETURN_IN_MEMORY macro. */
1084 #define DEFAULT_PCC_STRUCT_RETURN 0
1086 #define SHMEDIA_REGS_STACK_ADJUST() \
1087 (TARGET_SHCOMPACT && current_function_has_nonlocal_label \
1088 ? (8 * (/* r28-r35 */ 8 + /* r44-r59 */ 16 + /* tr5-tr7 */ 3) \
1089 + (TARGET_FPU_ANY ? 4 * (/* fr36 - fr63 */ 28) : 0)) \
1090 : 0)
1093 /* Define the classes of registers for register constraints in the
1094 machine description. Also define ranges of constants.
1096 One of the classes must always be named ALL_REGS and include all hard regs.
1097 If there is more than one class, another class must be named NO_REGS
1098 and contain no registers.
1100 The name GENERAL_REGS must be the name of a class (or an alias for
1101 another name such as ALL_REGS). This is the class of registers
1102 that is allowed by "g" or "r" in a register constraint.
1103 Also, registers outside this class are allocated only when
1104 instructions express preferences for them.
1106 The classes must be numbered in nondecreasing order; that is,
1107 a larger-numbered class must never be contained completely
1108 in a smaller-numbered class.
1110 For any two classes, it is very desirable that there be another
1111 class that represents their union. */
1113 /* The SH has two sorts of general registers, R0 and the rest. R0 can
1114 be used as the destination of some of the arithmetic ops. There are
1115 also some special purpose registers; the T bit register, the
1116 Procedure Return Register and the Multiply Accumulate Registers. */
1117 /* Place GENERAL_REGS after FPUL_REGS so that it will be preferred by
1118 reg_class_subunion. We don't want to have an actual union class
1119 of these, because it would only be used when both classes are calculated
1120 to give the same cost, but there is only one FPUL register.
1121 Besides, regclass fails to notice the different REGISTER_MOVE_COSTS
1122 applying to the actual instruction alternative considered. E.g., the
1123 y/r alternative of movsi_ie is considered to have no more cost that
1124 the r/r alternative, which is patently untrue. */
1126 enum reg_class
1128 NO_REGS,
1129 R0_REGS,
1130 PR_REGS,
1131 T_REGS,
1132 MAC_REGS,
1133 FPUL_REGS,
1134 SIBCALL_REGS,
1135 GENERAL_REGS,
1136 FP0_REGS,
1137 FP_REGS,
1138 DF_HI_REGS,
1139 DF_REGS,
1140 FPSCR_REGS,
1141 GENERAL_FP_REGS,
1142 TARGET_REGS,
1143 ALL_REGS,
1144 LIM_REG_CLASSES
1147 #define N_REG_CLASSES (int) LIM_REG_CLASSES
1149 /* Give names of register classes as strings for dump file. */
1150 #define REG_CLASS_NAMES \
1152 "NO_REGS", \
1153 "R0_REGS", \
1154 "PR_REGS", \
1155 "T_REGS", \
1156 "MAC_REGS", \
1157 "FPUL_REGS", \
1158 "SIBCALL_REGS", \
1159 "GENERAL_REGS", \
1160 "FP0_REGS", \
1161 "FP_REGS", \
1162 "DF_HI_REGS", \
1163 "DF_REGS", \
1164 "FPSCR_REGS", \
1165 "GENERAL_FP_REGS", \
1166 "TARGET_REGS", \
1167 "ALL_REGS", \
1170 /* Define which registers fit in which classes.
1171 This is an initializer for a vector of HARD_REG_SET
1172 of length N_REG_CLASSES. */
1174 #define REG_CLASS_CONTENTS \
1176 /* NO_REGS: */ \
1177 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, \
1178 /* R0_REGS: */ \
1179 { 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, \
1180 /* PR_REGS: */ \
1181 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00040000 }, \
1182 /* T_REGS: */ \
1183 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00080000 }, \
1184 /* MAC_REGS: */ \
1185 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00300000 }, \
1186 /* FPUL_REGS: */ \
1187 { 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00400000 }, \
1188 /* SIBCALL_REGS: Initialized in CONDITIONAL_REGISTER_USAGE. */ \
1189 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, \
1190 /* GENERAL_REGS: */ \
1191 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x01020000 }, \
1192 /* FP0_REGS: */ \
1193 { 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000 }, \
1194 /* FP_REGS: */ \
1195 { 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0x00000000 }, \
1196 /* DF_HI_REGS: Initialized in CONDITIONAL_REGISTER_USAGE. */ \
1197 { 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0x0000ff00 }, \
1198 /* DF_REGS: */ \
1199 { 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0x0000ff00 }, \
1200 /* FPSCR_REGS: */ \
1201 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00800000 }, \
1202 /* GENERAL_FP_REGS: */ \
1203 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x0102ff00 }, \
1204 /* TARGET_REGS: */ \
1205 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x000000ff }, \
1206 /* ALL_REGS: */ \
1207 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x01ffffff }, \
1210 /* The same information, inverted:
1211 Return the class number of the smallest class containing
1212 reg number REGNO. This could be a conditional expression
1213 or could index an array. */
1215 extern int regno_reg_class[FIRST_PSEUDO_REGISTER];
1216 #define REGNO_REG_CLASS(REGNO) regno_reg_class[(REGNO)]
1218 /* When defined, the compiler allows registers explicitly used in the
1219 rtl to be used as spill registers but prevents the compiler from
1220 extending the lifetime of these registers. */
1222 #define SMALL_REGISTER_CLASSES (! TARGET_SHMEDIA)
1224 /* The order in which register should be allocated. */
1225 /* Sometimes FP0_REGS becomes the preferred class of a floating point pseudo,
1226 and GENERAL_FP_REGS the alternate class. Since FP0 is likely to be
1227 spilled or used otherwise, we better have the FP_REGS allocated first. */
1228 #define REG_ALLOC_ORDER \
1229 { 65, 66, 67, 68, 69, 70, 71, 64, \
1230 72, 73, 74, 75, 76, 77, 78, 79, \
1231 136,137,138,139,140,141,142,143, \
1232 80, 81, 82, 83, 84, 85, 86, 87, \
1233 88, 89, 90, 91, 92, 93, 94, 95, \
1234 96, 97, 98, 99,100,101,102,103, \
1235 104,105,106,107,108,109,110,111, \
1236 112,113,114,115,116,117,118,119, \
1237 120,121,122,123,124,125,126,127, \
1238 151, 1, 2, 3, 7, 6, 5, 4, \
1239 0, 8, 9, 10, 11, 12, 13, 14, \
1240 16, 17, 18, 19, 20, 21, 22, 23, \
1241 24, 25, 26, 27, 28, 29, 30, 31, \
1242 32, 33, 34, 35, 36, 37, 38, 39, \
1243 40, 41, 42, 43, 44, 45, 46, 47, \
1244 48, 49, 50, 51, 52, 53, 54, 55, \
1245 56, 57, 58, 59, 60, 61, 62, 63, \
1246 150, 15,145,146,147,144,148,149, \
1247 128,129,130,131,132,133,134,135, \
1248 152 }
1250 /* The class value for index registers, and the one for base regs. */
1251 #define INDEX_REG_CLASS (TARGET_SHMEDIA ? GENERAL_REGS : R0_REGS)
1252 #define BASE_REG_CLASS GENERAL_REGS
1254 /* Get reg_class from a letter such as appears in the machine
1255 description. */
1256 extern enum reg_class reg_class_from_letter[];
1258 #define REG_CLASS_FROM_LETTER(C) \
1259 ( ISLOWER (C) ? reg_class_from_letter[(C)-'a'] : NO_REGS )
1261 /* The letters I, J, K, L and M in a register constraint string
1262 can be used to stand for particular ranges of immediate operands.
1263 This macro defines what the ranges are.
1264 C is the letter, and VALUE is a constant value.
1265 Return 1 if VALUE is in the range specified by C.
1266 I: arithmetic operand -127..128, as used in add, sub, etc
1267 J: arithmetic operand -32768..32767, as used in SHmedia movi and shori
1268 K: shift operand 1,2,8 or 16
1269 L: logical operand 0..255, as used in and, or, etc.
1270 M: constant 1
1271 N: constant 0
1272 O: arithmetic operand -32..31, as used in SHmedia beqi, bnei and xori
1273 P: arithmetic operand -512..511, as used in SHmedia andi, ori
1276 #define CONST_OK_FOR_I(VALUE) (((HOST_WIDE_INT)(VALUE))>= -128 \
1277 && ((HOST_WIDE_INT)(VALUE)) <= 127)
1278 #define CONST_OK_FOR_J(VALUE) (((HOST_WIDE_INT)(VALUE)) >= -32768 \
1279 && ((HOST_WIDE_INT)(VALUE)) <= 32767)
1280 #define CONST_OK_FOR_K(VALUE) ((VALUE)==1||(VALUE)==2||(VALUE)==8||(VALUE)==16)
1281 #define CONST_OK_FOR_L(VALUE) (((HOST_WIDE_INT)(VALUE))>= 0 \
1282 && ((HOST_WIDE_INT)(VALUE)) <= 255)
1283 #define CONST_OK_FOR_M(VALUE) ((VALUE)==1)
1284 #define CONST_OK_FOR_N(VALUE) ((VALUE)==0)
1285 #define CONST_OK_FOR_O(VALUE) (((HOST_WIDE_INT)(VALUE)) >= -32 \
1286 && ((HOST_WIDE_INT)(VALUE)) <= 31)
1287 #define CONST_OK_FOR_P(VALUE) (((HOST_WIDE_INT)(VALUE)) >= -512 \
1288 && ((HOST_WIDE_INT)(VALUE)) <= 511)
1289 #define CONST_OK_FOR_LETTER_P(VALUE, C) \
1290 ((C) == 'I' ? CONST_OK_FOR_I (VALUE) \
1291 : (C) == 'J' ? CONST_OK_FOR_J (VALUE) \
1292 : (C) == 'K' ? CONST_OK_FOR_K (VALUE) \
1293 : (C) == 'L' ? CONST_OK_FOR_L (VALUE) \
1294 : (C) == 'M' ? CONST_OK_FOR_M (VALUE) \
1295 : (C) == 'N' ? CONST_OK_FOR_N (VALUE) \
1296 : (C) == 'O' ? CONST_OK_FOR_O (VALUE) \
1297 : (C) == 'P' ? CONST_OK_FOR_P (VALUE) \
1298 : 0)
1300 /* Similar, but for floating constants, and defining letters G and H.
1301 Here VALUE is the CONST_DOUBLE rtx itself. */
1303 #define CONST_DOUBLE_OK_FOR_LETTER_P(VALUE, C) \
1304 ((C) == 'G' ? (fp_zero_operand (VALUE) && fldi_ok ()) \
1305 : (C) == 'H' ? (fp_one_operand (VALUE) && fldi_ok ()) \
1306 : (C) == 'F')
1308 /* Given an rtx X being reloaded into a reg required to be
1309 in class CLASS, return the class of reg to actually use.
1310 In general this is just CLASS; but on some machines
1311 in some cases it is preferable to use a more restrictive class. */
1313 #define PREFERRED_RELOAD_CLASS(X, CLASS) \
1314 ((CLASS) == NO_REGS && TARGET_SHMEDIA \
1315 && (GET_CODE (X) == CONST_DOUBLE \
1316 || GET_CODE (X) == SYMBOL_REF) \
1317 ? GENERAL_REGS \
1318 : (CLASS)) \
1320 #define SECONDARY_OUTPUT_RELOAD_CLASS(CLASS,MODE,X) \
1321 ((((REGCLASS_HAS_FP_REG (CLASS) \
1322 && (GET_CODE (X) == REG \
1323 && (GENERAL_OR_AP_REGISTER_P (REGNO (X)) \
1324 || (FP_REGISTER_P (REGNO (X)) && (MODE) == SImode \
1325 && TARGET_FMOVD)))) \
1326 || (REGCLASS_HAS_GENERAL_REG (CLASS) \
1327 && GET_CODE (X) == REG \
1328 && FP_REGISTER_P (REGNO (X)))) \
1329 && ! TARGET_SHMEDIA \
1330 && ((MODE) == SFmode || (MODE) == SImode)) \
1331 ? FPUL_REGS \
1332 : (((CLASS) == FPUL_REGS \
1333 || (REGCLASS_HAS_FP_REG (CLASS) \
1334 && ! TARGET_SHMEDIA && MODE == SImode)) \
1335 && (GET_CODE (X) == MEM \
1336 || (GET_CODE (X) == REG \
1337 && (REGNO (X) >= FIRST_PSEUDO_REGISTER \
1338 || REGNO (X) == T_REG \
1339 || system_reg_operand (X, VOIDmode))))) \
1340 ? GENERAL_REGS \
1341 : ((CLASS) == TARGET_REGS \
1342 || (TARGET_SHMEDIA && (CLASS) == SIBCALL_REGS)) \
1343 ? ((target_operand ((X), (MODE)) \
1344 && ! target_reg_operand ((X), (MODE))) \
1345 ? NO_REGS : GENERAL_REGS) \
1346 : (((CLASS) == MAC_REGS || (CLASS) == PR_REGS) \
1347 && GET_CODE (X) == REG && ! GENERAL_REGISTER_P (REGNO (X)) \
1348 && (CLASS) != REGNO_REG_CLASS (REGNO (X))) \
1349 ? GENERAL_REGS \
1350 : ((CLASS) != GENERAL_REGS && GET_CODE (X) == REG \
1351 && TARGET_REGISTER_P (REGNO (X))) \
1352 ? GENERAL_REGS : NO_REGS)
1354 #define SECONDARY_INPUT_RELOAD_CLASS(CLASS,MODE,X) \
1355 ((REGCLASS_HAS_FP_REG (CLASS) \
1356 && ! TARGET_SHMEDIA \
1357 && immediate_operand ((X), (MODE)) \
1358 && ! ((fp_zero_operand (X) || fp_one_operand (X)) \
1359 && (MODE) == SFmode && fldi_ok ())) \
1360 ? R0_REGS \
1361 : (CLASS == FPUL_REGS \
1362 && ((GET_CODE (X) == REG \
1363 && (REGNO (X) == MACL_REG || REGNO (X) == MACH_REG \
1364 || REGNO (X) == T_REG)))) \
1365 ? GENERAL_REGS \
1366 : CLASS == FPUL_REGS && immediate_operand ((X), (MODE)) \
1367 ? (GET_CODE (X) == CONST_INT && CONST_OK_FOR_I (INTVAL (X)) \
1368 ? GENERAL_REGS \
1369 : R0_REGS) \
1370 : (CLASS == FPSCR_REGS \
1371 && ((GET_CODE (X) == REG && REGNO (X) >= FIRST_PSEUDO_REGISTER) \
1372 || (GET_CODE (X) == MEM && GET_CODE (XEXP ((X), 0)) == PLUS)))\
1373 ? GENERAL_REGS \
1374 : (REGCLASS_HAS_FP_REG (CLASS) \
1375 && TARGET_SHMEDIA \
1376 && immediate_operand ((X), (MODE)) \
1377 && (X) != CONST0_RTX (GET_MODE (X)) \
1378 && GET_MODE (X) != V4SFmode) \
1379 ? GENERAL_REGS \
1380 : SECONDARY_OUTPUT_RELOAD_CLASS((CLASS),(MODE),(X)))
1382 /* Return the maximum number of consecutive registers
1383 needed to represent mode MODE in a register of class CLASS.
1385 On SH this is the size of MODE in words. */
1386 #define CLASS_MAX_NREGS(CLASS, MODE) \
1387 ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1389 /* If defined, gives a class of registers that cannot be used as the
1390 operand of a SUBREG that changes the mode of the object illegally. */
1391 /* ??? We need to renumber the internal numbers for the frnn registers
1392 when in little endian in order to allow mode size changes. */
1394 #define CANNOT_CHANGE_MODE_CLASS(FROM, TO) \
1395 sh_cannot_change_mode_class (FROM, TO)
1397 /* Stack layout; function entry, exit and calling. */
1399 /* Define the number of registers that can hold parameters.
1400 These macros are used only in other macro definitions below. */
1402 #define NPARM_REGS(MODE) \
1403 (TARGET_FPU_ANY && (MODE) == SFmode \
1404 ? (TARGET_SH5 ? 12 : 8) \
1405 : TARGET_SH4 && (GET_MODE_CLASS (MODE) == MODE_FLOAT \
1406 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT) \
1407 ? (TARGET_SH5 ? 12 : 8) \
1408 : (TARGET_SH5 ? 8 : 4))
1410 #define FIRST_PARM_REG (FIRST_GENERAL_REG + (TARGET_SH5 ? 2 : 4))
1411 #define FIRST_RET_REG (FIRST_GENERAL_REG + (TARGET_SH5 ? 2 : 0))
1413 #define FIRST_FP_PARM_REG (FIRST_FP_REG + (TARGET_SH5 ? 0 : 4))
1414 #define FIRST_FP_RET_REG FIRST_FP_REG
1416 /* Define this if pushing a word on the stack
1417 makes the stack pointer a smaller address. */
1418 #define STACK_GROWS_DOWNWARD
1420 /* Define this macro if the addresses of local variable slots are at
1421 negative offsets from the frame pointer.
1423 The SH only has positive indexes, so grow the frame up. */
1424 /* #define FRAME_GROWS_DOWNWARD */
1426 /* Offset from the frame pointer to the first local variable slot to
1427 be allocated. */
1428 #define STARTING_FRAME_OFFSET 0
1430 /* If we generate an insn to push BYTES bytes,
1431 this says how many the stack pointer really advances by. */
1432 /* Don't define PUSH_ROUNDING, since the hardware doesn't do this.
1433 When PUSH_ROUNDING is not defined, PARM_BOUNDARY will cause gcc to
1434 do correct alignment. */
1435 #if 0
1436 #define PUSH_ROUNDING(NPUSHED) (((NPUSHED) + 3) & ~3)
1437 #endif
1439 /* Offset of first parameter from the argument pointer register value. */
1440 #define FIRST_PARM_OFFSET(FNDECL) 0
1442 /* Value is the number of byte of arguments automatically
1443 popped when returning from a subroutine call.
1444 FUNDECL is the declaration node of the function (as a tree),
1445 FUNTYPE is the data type of the function (as a tree),
1446 or for a library call it is an identifier node for the subroutine name.
1447 SIZE is the number of bytes of arguments passed on the stack.
1449 On the SH, the caller does not pop any of its arguments that were passed
1450 on the stack. */
1451 #define RETURN_POPS_ARGS(FUNDECL,FUNTYPE,SIZE) 0
1453 /* Value is the number of bytes of arguments automatically popped when
1454 calling a subroutine.
1455 CUM is the accumulated argument list.
1457 On SHcompact, the call trampoline pops arguments off the stack. */
1458 #define CALL_POPS_ARGS(CUM) (TARGET_SHCOMPACT ? (CUM).stack_regs * 8 : 0)
1460 /* Nonzero if we do not know how to pass TYPE solely in registers.
1461 Values that come in registers with inconvenient padding are stored
1462 to memory at the function start. */
1464 #define MUST_PASS_IN_STACK(MODE,TYPE) \
1465 ((TYPE) != 0 \
1466 && (TREE_CODE (TYPE_SIZE (TYPE)) != INTEGER_CST \
1467 || TREE_ADDRESSABLE (TYPE)))
1468 /* Some subroutine macros specific to this machine. */
1470 #define BASE_RETURN_VALUE_REG(MODE) \
1471 ((TARGET_FPU_ANY && ((MODE) == SFmode)) \
1472 ? FIRST_FP_RET_REG \
1473 : TARGET_FPU_ANY && (MODE) == SCmode \
1474 ? FIRST_FP_RET_REG \
1475 : (TARGET_FPU_DOUBLE \
1476 && ((MODE) == DFmode || (MODE) == SFmode \
1477 || (MODE) == DCmode || (MODE) == SCmode )) \
1478 ? FIRST_FP_RET_REG \
1479 : FIRST_RET_REG)
1481 #define BASE_ARG_REG(MODE) \
1482 ((TARGET_SH2E && ((MODE) == SFmode)) \
1483 ? FIRST_FP_PARM_REG \
1484 : TARGET_SH4 && (GET_MODE_CLASS (MODE) == MODE_FLOAT \
1485 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)\
1486 ? FIRST_FP_PARM_REG \
1487 : FIRST_PARM_REG)
1489 /* Define how to find the value returned by a function.
1490 VALTYPE is the data type of the value (as a tree).
1491 If the precise function being called is known, FUNC is its FUNCTION_DECL;
1492 otherwise, FUNC is 0.
1493 For the SH, this is like LIBCALL_VALUE, except that we must change the
1494 mode like PROMOTE_MODE does.
1495 ??? PROMOTE_MODE is ignored for non-scalar types. The set of types
1496 tested here has to be kept in sync with the one in explow.c:promote_mode. */
1498 #define FUNCTION_VALUE(VALTYPE, FUNC) \
1499 gen_rtx (REG, \
1500 ((GET_MODE_CLASS (TYPE_MODE (VALTYPE)) == MODE_INT \
1501 && GET_MODE_SIZE (TYPE_MODE (VALTYPE)) < UNITS_PER_WORD \
1502 && (TREE_CODE (VALTYPE) == INTEGER_TYPE \
1503 || TREE_CODE (VALTYPE) == ENUMERAL_TYPE \
1504 || TREE_CODE (VALTYPE) == BOOLEAN_TYPE \
1505 || TREE_CODE (VALTYPE) == CHAR_TYPE \
1506 || TREE_CODE (VALTYPE) == REAL_TYPE \
1507 || TREE_CODE (VALTYPE) == OFFSET_TYPE)) \
1508 ? (TARGET_SHMEDIA ? DImode : SImode) : TYPE_MODE (VALTYPE)), \
1509 BASE_RETURN_VALUE_REG (TYPE_MODE (VALTYPE)))
1511 /* Define how to find the value returned by a library function
1512 assuming the value has mode MODE. */
1513 #define LIBCALL_VALUE(MODE) \
1514 gen_rtx_REG ((MODE), BASE_RETURN_VALUE_REG (MODE));
1516 /* 1 if N is a possible register number for a function value. */
1517 #define FUNCTION_VALUE_REGNO_P(REGNO) \
1518 ((REGNO) == FIRST_RET_REG || (TARGET_SH2E && (REGNO) == FIRST_FP_RET_REG) \
1519 || (TARGET_SHMEDIA_FPU && (REGNO) == FIRST_FP_RET_REG))
1521 /* 1 if N is a possible register number for function argument passing. */
1522 #define FUNCTION_ARG_REGNO_P(REGNO) \
1523 (((REGNO) >= FIRST_PARM_REG && (REGNO) < (FIRST_PARM_REG \
1524 + NPARM_REGS (SImode))) \
1525 || (TARGET_FPU_ANY \
1526 && (REGNO) >= FIRST_FP_PARM_REG && (REGNO) < (FIRST_FP_PARM_REG \
1527 + NPARM_REGS (SFmode))))
1529 /* Define a data type for recording info about an argument list
1530 during the scan of that argument list. This data type should
1531 hold all necessary information about the function itself
1532 and about the args processed so far, enough to enable macros
1533 such as FUNCTION_ARG to determine where the next arg should go.
1535 On SH, this is a single integer, which is a number of words
1536 of arguments scanned so far (including the invisible argument,
1537 if any, which holds the structure-value-address).
1538 Thus NARGREGS or more means all following args should go on the stack. */
1540 enum sh_arg_class { SH_ARG_INT = 0, SH_ARG_FLOAT = 1 };
1541 struct sh_args {
1542 int arg_count[2];
1543 int force_mem;
1544 /* Nonzero if a prototype is available for the function. */
1545 int prototype_p;
1546 /* The number of an odd floating-point register, that should be used
1547 for the next argument of type float. */
1548 int free_single_fp_reg;
1549 /* Whether we're processing an outgoing function call. */
1550 int outgoing;
1551 /* The number of general-purpose registers that should have been
1552 used to pass partial arguments, that are passed totally on the
1553 stack. On SHcompact, a call trampoline will pop them off the
1554 stack before calling the actual function, and, if the called
1555 function is implemented in SHcompact mode, the incoming arguments
1556 decoder will push such arguments back onto the stack. For
1557 incoming arguments, STACK_REGS also takes into account other
1558 arguments passed by reference, that the decoder will also push
1559 onto the stack. */
1560 int stack_regs;
1561 /* The number of general-purpose registers that should have been
1562 used to pass arguments, if the arguments didn't have to be passed
1563 by reference. */
1564 int byref_regs;
1565 /* Set by SHCOMPACT_BYREF if the current argument is to be passed by
1566 reference. */
1567 int byref;
1569 /* call_cookie is a bitmask used by call expanders, as well as
1570 function prologue and epilogues, to allow SHcompact to comply
1571 with the SH5 32-bit ABI, that requires 64-bit registers to be
1572 used even though only the lower 32-bit half is visible in
1573 SHcompact mode. The strategy is to call SHmedia trampolines.
1575 The alternatives for each of the argument-passing registers are
1576 (a) leave it unchanged; (b) pop it off the stack; (c) load its
1577 contents from the address in it; (d) add 8 to it, storing the
1578 result in the next register, then (c); (e) copy it from some
1579 floating-point register,
1581 Regarding copies from floating-point registers, r2 may only be
1582 copied from dr0. r3 may be copied from dr0 or dr2. r4 maybe
1583 copied from dr0, dr2 or dr4. r5 maybe copied from dr0, dr2,
1584 dr4 or dr6. r6 may be copied from dr0, dr2, dr4, dr6 or dr8.
1585 r7 through to r9 may be copied from dr0, dr2, dr4, dr8, dr8 or
1586 dr10.
1588 The bit mask is structured as follows:
1590 - 1 bit to tell whether to set up a return trampoline.
1592 - 3 bits to count the number consecutive registers to pop off the
1593 stack.
1595 - 4 bits for each of r9, r8, r7 and r6.
1597 - 3 bits for each of r5, r4, r3 and r2.
1599 - 3 bits set to 0 (the most significant ones)
1601 3 2 1 0
1602 1098 7654 3210 9876 5432 1098 7654 3210
1603 FLPF LPFL PFLP FFLP FFLP FFLP FFLP SSST
1604 2223 3344 4555 6666 7777 8888 9999 SSS-
1606 - If F is set, the register must be copied from an FP register,
1607 whose number is encoded in the remaining bits.
1609 - Else, if L is set, the register must be loaded from the address
1610 contained in it. If the P bit is *not* set, the address of the
1611 following dword should be computed first, and stored in the
1612 following register.
1614 - Else, if P is set, the register alone should be popped off the
1615 stack.
1617 - After all this processing, the number of registers represented
1618 in SSS will be popped off the stack. This is an optimization
1619 for pushing/popping consecutive registers, typically used for
1620 varargs and large arguments partially passed in registers.
1622 - If T is set, a return trampoline will be set up for 64-bit
1623 return values to be split into 2 32-bit registers. */
1624 #define CALL_COOKIE_RET_TRAMP_SHIFT 0
1625 #define CALL_COOKIE_RET_TRAMP(VAL) ((VAL) << CALL_COOKIE_RET_TRAMP_SHIFT)
1626 #define CALL_COOKIE_STACKSEQ_SHIFT 1
1627 #define CALL_COOKIE_STACKSEQ(VAL) ((VAL) << CALL_COOKIE_STACKSEQ_SHIFT)
1628 #define CALL_COOKIE_STACKSEQ_GET(COOKIE) \
1629 (((COOKIE) >> CALL_COOKIE_STACKSEQ_SHIFT) & 7)
1630 #define CALL_COOKIE_INT_REG_SHIFT(REG) \
1631 (4 * (7 - (REG)) + (((REG) <= 2) ? ((REG) - 2) : 1) + 3)
1632 #define CALL_COOKIE_INT_REG(REG, VAL) \
1633 ((VAL) << CALL_COOKIE_INT_REG_SHIFT (REG))
1634 #define CALL_COOKIE_INT_REG_GET(COOKIE, REG) \
1635 (((COOKIE) >> CALL_COOKIE_INT_REG_SHIFT (REG)) & ((REG) < 4 ? 7 : 15))
1636 long call_cookie;
1639 #define CUMULATIVE_ARGS struct sh_args
1641 #define GET_SH_ARG_CLASS(MODE) \
1642 ((TARGET_FPU_ANY && (MODE) == SFmode) \
1643 ? SH_ARG_FLOAT \
1644 /* There's no mention of complex float types in the SH5 ABI, so we
1645 should presumably handle them as aggregate types. */ \
1646 : TARGET_SH5 && GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
1647 ? SH_ARG_INT \
1648 : TARGET_FPU_DOUBLE && (GET_MODE_CLASS (MODE) == MODE_FLOAT \
1649 || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT) \
1650 ? SH_ARG_FLOAT : SH_ARG_INT)
1652 #define ROUND_ADVANCE(SIZE) \
1653 (((SIZE) + UNITS_PER_WORD - 1) / UNITS_PER_WORD)
1655 /* Round a register number up to a proper boundary for an arg of mode
1656 MODE.
1658 The SH doesn't care about double alignment, so we only
1659 round doubles to even regs when asked to explicitly. */
1661 #define ROUND_REG(CUM, MODE) \
1662 (((TARGET_ALIGN_DOUBLE \
1663 || (TARGET_SH4 && ((MODE) == DFmode || (MODE) == DCmode) \
1664 && (CUM).arg_count[(int) SH_ARG_FLOAT] < NPARM_REGS (MODE)))\
1665 && GET_MODE_UNIT_SIZE ((MODE)) > UNITS_PER_WORD) \
1666 ? ((CUM).arg_count[(int) GET_SH_ARG_CLASS (MODE)] \
1667 + ((CUM).arg_count[(int) GET_SH_ARG_CLASS (MODE)] & 1)) \
1668 : (CUM).arg_count[(int) GET_SH_ARG_CLASS (MODE)])
1670 /* Initialize a variable CUM of type CUMULATIVE_ARGS
1671 for a call to a function whose data type is FNTYPE.
1672 For a library call, FNTYPE is 0.
1674 On SH, the offset always starts at 0: the first parm reg is always
1675 the same reg for a given argument class.
1677 For TARGET_HITACHI, the structure value pointer is passed in memory. */
1679 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, INDIRECT) \
1680 do { \
1681 (CUM).arg_count[(int) SH_ARG_INT] = 0; \
1682 (CUM).arg_count[(int) SH_ARG_FLOAT] = 0; \
1683 (CUM).force_mem \
1684 = (TARGET_HITACHI && FNTYPE \
1685 && aggregate_value_p (TREE_TYPE (FNTYPE))); \
1686 (CUM).prototype_p = (FNTYPE) && TYPE_ARG_TYPES (FNTYPE); \
1687 (CUM).arg_count[(int) SH_ARG_INT] \
1688 = (TARGET_SH5 && (FNTYPE) \
1689 && aggregate_value_p (TREE_TYPE (FNTYPE))); \
1690 (CUM).free_single_fp_reg = 0; \
1691 (CUM).outgoing = 1; \
1692 (CUM).stack_regs = 0; \
1693 (CUM).byref_regs = 0; \
1694 (CUM).byref = 0; \
1695 (CUM).call_cookie \
1696 = (CALL_COOKIE_RET_TRAMP \
1697 (TARGET_SHCOMPACT && (FNTYPE) \
1698 && (CUM).arg_count[(int) SH_ARG_INT] == 0 \
1699 && (TYPE_MODE (TREE_TYPE (FNTYPE)) == BLKmode \
1700 ? int_size_in_bytes (TREE_TYPE (FNTYPE)) \
1701 : GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (FNTYPE)))) > 4 \
1702 && (BASE_RETURN_VALUE_REG (TYPE_MODE (TREE_TYPE \
1703 (FNTYPE))) \
1704 == FIRST_RET_REG))); \
1705 } while (0)
1707 #define INIT_CUMULATIVE_LIBCALL_ARGS(CUM, MODE, LIBNAME) \
1708 do { \
1709 INIT_CUMULATIVE_ARGS ((CUM), NULL_TREE, (LIBNAME), 0); \
1710 (CUM).call_cookie \
1711 = (CALL_COOKIE_RET_TRAMP \
1712 (TARGET_SHCOMPACT && GET_MODE_SIZE (MODE) > 4 \
1713 && BASE_RETURN_VALUE_REG (MODE) == FIRST_RET_REG)); \
1714 } while (0)
1716 #define INIT_CUMULATIVE_INCOMING_ARGS(CUM, FNTYPE, LIBNAME) \
1717 do { \
1718 INIT_CUMULATIVE_ARGS ((CUM), (FNTYPE), (LIBNAME), 0); \
1719 (CUM).outgoing = 0; \
1720 } while (0)
1722 /* Update the data in CUM to advance over an argument
1723 of mode MODE and data type TYPE.
1724 (TYPE is null for libcalls where that information may not be
1725 available.) */
1727 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED) \
1728 if ((CUM).force_mem) \
1729 (CUM).force_mem = 0; \
1730 else if (TARGET_SH5) \
1732 tree TYPE_ = ((CUM).byref && (TYPE) \
1733 ? TREE_TYPE (TYPE) \
1734 : (TYPE)); \
1735 enum machine_mode MODE_ = ((CUM).byref && (TYPE) \
1736 ? TYPE_MODE (TYPE_) \
1737 : (MODE)); \
1738 int dwords = (((CUM).byref \
1739 ? (CUM).byref \
1740 : (MODE_) == BLKmode \
1741 ? int_size_in_bytes (TYPE_) \
1742 : GET_MODE_SIZE (MODE_)) + 7) / 8; \
1743 int numregs = MIN (dwords, NPARM_REGS (SImode) \
1744 - (CUM).arg_count[(int) SH_ARG_INT]); \
1746 if (numregs) \
1748 (CUM).arg_count[(int) SH_ARG_INT] += numregs; \
1749 if (TARGET_SHCOMPACT \
1750 && SHCOMPACT_FORCE_ON_STACK (MODE_, TYPE_)) \
1752 (CUM).call_cookie \
1753 |= CALL_COOKIE_INT_REG (((CUM).arg_count[(int) SH_ARG_INT] \
1754 - numregs), 1); \
1755 /* N.B. We want this also for outgoing. */\
1756 (CUM).stack_regs += numregs; \
1758 else if ((CUM).byref) \
1760 if (! (CUM).outgoing) \
1761 (CUM).stack_regs += numregs; \
1762 (CUM).byref_regs += numregs; \
1763 (CUM).byref = 0; \
1764 do \
1765 (CUM).call_cookie \
1766 |= CALL_COOKIE_INT_REG (((CUM).arg_count[(int) SH_ARG_INT] \
1767 - numregs), 2); \
1768 while (--numregs); \
1769 (CUM).call_cookie \
1770 |= CALL_COOKIE_INT_REG (((CUM).arg_count[(int) SH_ARG_INT] \
1771 - 1), 1); \
1773 else if (dwords > numregs) \
1775 int pushregs = numregs; \
1777 if (TARGET_SHCOMPACT) \
1778 (CUM).stack_regs += numregs; \
1779 while (pushregs < NPARM_REGS (SImode) - 1 \
1780 && (CALL_COOKIE_INT_REG_GET \
1781 ((CUM).call_cookie, \
1782 NPARM_REGS (SImode) - pushregs) \
1783 == 1)) \
1785 (CUM).call_cookie \
1786 &= ~ CALL_COOKIE_INT_REG (NPARM_REGS (SImode) \
1787 - pushregs, 1); \
1788 pushregs++; \
1790 if (numregs == NPARM_REGS (SImode)) \
1791 (CUM).call_cookie \
1792 |= CALL_COOKIE_INT_REG (0, 1) \
1793 | CALL_COOKIE_STACKSEQ (numregs - 1); \
1794 else \
1795 (CUM).call_cookie \
1796 |= CALL_COOKIE_STACKSEQ (numregs); \
1799 if (GET_SH_ARG_CLASS (MODE_) == SH_ARG_FLOAT \
1800 && ((NAMED) || ! (CUM).prototype_p)) \
1802 if ((MODE_) == SFmode && (CUM).free_single_fp_reg) \
1803 (CUM).free_single_fp_reg = 0; \
1804 else if ((CUM).arg_count[(int) SH_ARG_FLOAT] \
1805 < NPARM_REGS (SFmode)) \
1807 int numfpregs \
1808 = MIN ((GET_MODE_SIZE (MODE_) + 7) / 8 * 2, \
1809 NPARM_REGS (SFmode) \
1810 - (CUM).arg_count[(int) SH_ARG_FLOAT]); \
1812 (CUM).arg_count[(int) SH_ARG_FLOAT] += numfpregs; \
1814 if (TARGET_SHCOMPACT && ! (CUM).prototype_p) \
1816 if ((CUM).outgoing && numregs > 0) \
1817 do \
1819 (CUM).call_cookie \
1820 |= (CALL_COOKIE_INT_REG \
1821 ((CUM).arg_count[(int) SH_ARG_INT] \
1822 - numregs + ((numfpregs - 2) / 2), \
1823 4 + ((CUM).arg_count[(int) SH_ARG_FLOAT] \
1824 - numfpregs) / 2)); \
1826 while (numfpregs -= 2); \
1828 else if ((MODE_) == SFmode && (NAMED) \
1829 && ((CUM).arg_count[(int) SH_ARG_FLOAT] \
1830 < NPARM_REGS (SFmode))) \
1831 (CUM).free_single_fp_reg \
1832 = FIRST_FP_PARM_REG - numfpregs \
1833 + (CUM).arg_count[(int) SH_ARG_FLOAT] + 1; \
1837 else if (! TARGET_SH4 || PASS_IN_REG_P ((CUM), (MODE), (TYPE))) \
1838 ((CUM).arg_count[(int) GET_SH_ARG_CLASS (MODE)] \
1839 = (ROUND_REG ((CUM), (MODE)) \
1840 + ((MODE) == BLKmode \
1841 ? ROUND_ADVANCE (int_size_in_bytes (TYPE)) \
1842 : ROUND_ADVANCE (GET_MODE_SIZE (MODE)))))
1844 /* Return boolean indicating arg of mode MODE will be passed in a reg.
1845 This macro is only used in this file. */
1847 #define PASS_IN_REG_P(CUM, MODE, TYPE) \
1848 (((TYPE) == 0 \
1849 || (! TREE_ADDRESSABLE ((tree)(TYPE)) \
1850 && (! TARGET_HITACHI || ! AGGREGATE_TYPE_P (TYPE)))) \
1851 && ! (CUM).force_mem \
1852 && (TARGET_SH2E \
1853 ? ((MODE) == BLKmode \
1854 ? (((CUM).arg_count[(int) SH_ARG_INT] * UNITS_PER_WORD \
1855 + int_size_in_bytes (TYPE)) \
1856 <= NPARM_REGS (SImode) * UNITS_PER_WORD) \
1857 : ((ROUND_REG((CUM), (MODE)) \
1858 + HARD_REGNO_NREGS (BASE_ARG_REG (MODE), (MODE))) \
1859 <= NPARM_REGS (MODE))) \
1860 : ROUND_REG ((CUM), (MODE)) < NPARM_REGS (MODE)))
1862 /* Define where to put the arguments to a function.
1863 Value is zero to push the argument on the stack,
1864 or a hard register in which to store the argument.
1866 MODE is the argument's machine mode.
1867 TYPE is the data type of the argument (as a tree).
1868 This is null for libcalls where that information may
1869 not be available.
1870 CUM is a variable of type CUMULATIVE_ARGS which gives info about
1871 the preceding args and about the function being called.
1872 NAMED is nonzero if this argument is a named parameter
1873 (otherwise it is an extra parameter matching an ellipsis).
1875 On SH the first args are normally in registers
1876 and the rest are pushed. Any arg that starts within the first
1877 NPARM_REGS words is at least partially passed in a register unless
1878 its data type forbids. */
1880 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
1881 ((! TARGET_SH5 \
1882 && PASS_IN_REG_P ((CUM), (MODE), (TYPE)) \
1883 && ((NAMED) || !TARGET_HITACHI)) \
1884 ? gen_rtx_REG ((MODE), \
1885 ((BASE_ARG_REG (MODE) + ROUND_REG ((CUM), (MODE))) \
1886 ^ ((MODE) == SFmode && TARGET_SH4 \
1887 && TARGET_LITTLE_ENDIAN != 0))) \
1888 : TARGET_SH5 \
1889 ? ((MODE) == VOIDmode && TARGET_SHCOMPACT \
1890 ? GEN_INT ((CUM).call_cookie) \
1891 /* The following test assumes unnamed arguments are promoted to \
1892 DFmode. */ \
1893 : (MODE) == SFmode && (CUM).free_single_fp_reg \
1894 ? SH5_PROTOTYPED_FLOAT_ARG ((CUM), (MODE), (CUM).free_single_fp_reg) \
1895 : (GET_SH_ARG_CLASS (MODE) == SH_ARG_FLOAT \
1896 && ((NAMED) || ! (CUM).prototype_p) \
1897 && (CUM).arg_count[(int) SH_ARG_FLOAT] < NPARM_REGS (SFmode)) \
1898 ? ((! (CUM).prototype_p && TARGET_SHMEDIA) \
1899 ? SH5_PROTOTYPELESS_FLOAT_ARG ((CUM), (MODE)) \
1900 : SH5_PROTOTYPED_FLOAT_ARG ((CUM), (MODE), \
1901 FIRST_FP_PARM_REG \
1902 + (CUM).arg_count[(int) SH_ARG_FLOAT])) \
1903 : ((CUM).arg_count[(int) SH_ARG_INT] < NPARM_REGS (SImode) \
1904 && (! TARGET_SHCOMPACT \
1905 || (! SHCOMPACT_FORCE_ON_STACK ((MODE), (TYPE)) \
1906 && ! SH5_WOULD_BE_PARTIAL_NREGS ((CUM), (MODE), \
1907 (TYPE), (NAMED))))) \
1908 ? gen_rtx_REG ((MODE), (FIRST_PARM_REG \
1909 + (CUM).arg_count[(int) SH_ARG_INT])) \
1910 : 0) \
1911 : 0)
1913 /* Whether an argument must be passed by reference. On SHcompact, we
1914 pretend arguments wider than 32-bits that would have been passed in
1915 registers are passed by reference, so that an SHmedia trampoline
1916 loads them into the full 64-bits registers. */
1917 #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM,MODE,TYPE,NAMED) \
1918 (MUST_PASS_IN_STACK ((MODE), (TYPE)) \
1919 || SHCOMPACT_BYREF ((CUM), (MODE), (TYPE), (NAMED)))
1921 #define SHCOMPACT_BYREF(CUM, MODE, TYPE, NAMED) \
1922 ((CUM).byref \
1923 = (TARGET_SHCOMPACT \
1924 && (CUM).arg_count[(int) SH_ARG_INT] < NPARM_REGS (SImode) \
1925 && (! (NAMED) || GET_SH_ARG_CLASS (MODE) == SH_ARG_INT \
1926 || (GET_SH_ARG_CLASS (MODE) == SH_ARG_FLOAT \
1927 && ((CUM).arg_count[(int) SH_ARG_FLOAT] \
1928 >= NPARM_REGS (SFmode)))) \
1929 && ((MODE) == BLKmode ? int_size_in_bytes (TYPE) \
1930 : GET_MODE_SIZE (MODE)) > 4 \
1931 && ! SHCOMPACT_FORCE_ON_STACK ((MODE), (TYPE)) \
1932 && ! SH5_WOULD_BE_PARTIAL_NREGS ((CUM), (MODE), \
1933 (TYPE), (NAMED))) \
1934 ? ((MODE) == BLKmode ? int_size_in_bytes (TYPE) \
1935 : GET_MODE_SIZE (MODE)) \
1936 : 0)
1938 /* If an argument of size 5, 6 or 7 bytes is to be passed in a 64-bit
1939 register in SHcompact mode, it must be padded in the most
1940 significant end. This means that passing it by reference wouldn't
1941 pad properly on a big-endian machine. In this particular case, we
1942 pass this argument on the stack, in a way that the call trampoline
1943 will load its value into the appropriate register. */
1944 #define SHCOMPACT_FORCE_ON_STACK(MODE,TYPE) \
1945 ((MODE) == BLKmode \
1946 && TARGET_SHCOMPACT \
1947 && ! TARGET_LITTLE_ENDIAN \
1948 && int_size_in_bytes (TYPE) > 4 \
1949 && int_size_in_bytes (TYPE) < 8)
1951 /* Minimum alignment for an argument to be passed by callee-copy
1952 reference. We need such arguments to be aligned to 8 byte
1953 boundaries, because they'll be loaded using quad loads. */
1954 #define SH_MIN_ALIGN_FOR_CALLEE_COPY (8 * BITS_PER_UNIT)
1956 #define FUNCTION_ARG_CALLEE_COPIES(CUM,MODE,TYPE,NAMED) \
1957 ((CUM).outgoing \
1958 && (((MODE) == BLKmode ? TYPE_ALIGN (TYPE) \
1959 : GET_MODE_ALIGNMENT (MODE)) \
1960 % SH_MIN_ALIGN_FOR_CALLEE_COPY == 0))
1962 /* The SH5 ABI requires floating-point arguments to be passed to
1963 functions without a prototype in both an FP register and a regular
1964 register or the stack. When passing the argument in both FP and
1965 general-purpose registers, list the FP register first. */
1966 #define SH5_PROTOTYPELESS_FLOAT_ARG(CUM,MODE) \
1967 (gen_rtx_PARALLEL \
1968 ((MODE), \
1969 gen_rtvec (2, \
1970 gen_rtx_EXPR_LIST \
1971 (VOIDmode, \
1972 ((CUM).arg_count[(int) SH_ARG_INT] < NPARM_REGS (SImode) \
1973 ? gen_rtx_REG ((MODE), FIRST_FP_PARM_REG \
1974 + (CUM).arg_count[(int) SH_ARG_FLOAT]) \
1975 : NULL_RTX), \
1976 const0_rtx), \
1977 gen_rtx_EXPR_LIST \
1978 (VOIDmode, \
1979 ((CUM).arg_count[(int) SH_ARG_INT] < NPARM_REGS (SImode) \
1980 ? gen_rtx_REG ((MODE), FIRST_PARM_REG \
1981 + (CUM).arg_count[(int) SH_ARG_INT]) \
1982 : gen_rtx_REG ((MODE), FIRST_FP_PARM_REG \
1983 + (CUM).arg_count[(int) SH_ARG_FLOAT])), \
1984 const0_rtx))))
1986 /* The SH5 ABI requires regular registers or stack slots to be
1987 reserved for floating-point arguments. Registers are taken care of
1988 in FUNCTION_ARG_ADVANCE, but stack slots must be reserved here.
1989 Unfortunately, there's no way to just reserve a stack slot, so
1990 we'll end up needlessly storing a copy of the argument in the
1991 stack. For incoming arguments, however, the PARALLEL will be
1992 optimized to the register-only form, and the value in the stack
1993 slot won't be used at all. */
1994 #define SH5_PROTOTYPED_FLOAT_ARG(CUM,MODE,REG) \
1995 ((CUM).arg_count[(int) SH_ARG_INT] < NPARM_REGS (SImode) \
1996 ? gen_rtx_REG ((MODE), (REG)) \
1997 : gen_rtx_PARALLEL ((MODE), \
1998 gen_rtvec (2, \
1999 gen_rtx_EXPR_LIST \
2000 (VOIDmode, NULL_RTX, \
2001 const0_rtx), \
2002 gen_rtx_EXPR_LIST \
2003 (VOIDmode, gen_rtx_REG ((MODE), \
2004 (REG)), \
2005 const0_rtx))))
2007 #define STRICT_ARGUMENT_NAMING TARGET_SH5
2009 #define PRETEND_OUTGOING_VARARGS_NAMED (! TARGET_HITACHI && ! TARGET_SH5)
2011 /* For an arg passed partly in registers and partly in memory,
2012 this is the number of registers used.
2013 For args passed entirely in registers or entirely in memory, zero.
2015 We sometimes split args. */
2017 #define FUNCTION_ARG_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED) \
2018 ((! TARGET_SH5 \
2019 && PASS_IN_REG_P ((CUM), (MODE), (TYPE)) \
2020 && ! TARGET_SH4 \
2021 && (ROUND_REG ((CUM), (MODE)) \
2022 + ((MODE) != BLKmode \
2023 ? ROUND_ADVANCE (GET_MODE_SIZE (MODE)) \
2024 : ROUND_ADVANCE (int_size_in_bytes (TYPE))) \
2025 > NPARM_REGS (MODE))) \
2026 ? NPARM_REGS (MODE) - ROUND_REG ((CUM), (MODE)) \
2027 : (SH5_WOULD_BE_PARTIAL_NREGS ((CUM), (MODE), (TYPE), (NAMED)) \
2028 && ! TARGET_SHCOMPACT) \
2029 ? NPARM_REGS (SImode) - (CUM).arg_count[(int) SH_ARG_INT] \
2030 : 0)
2032 #define SH5_WOULD_BE_PARTIAL_NREGS(CUM, MODE, TYPE, NAMED) \
2033 (TARGET_SH5 && ((MODE) == BLKmode || (MODE) == TImode) \
2034 && ((CUM).arg_count[(int) SH_ARG_INT] \
2035 + (int_size_in_bytes (TYPE) + 7) / 8) > NPARM_REGS (SImode))
2037 /* Perform any needed actions needed for a function that is receiving a
2038 variable number of arguments. */
2040 /* We actually emit the code in sh_expand_prologue. We used to use
2041 a static variable to flag that we need to emit this code, but that
2042 doesn't when inlining, when functions are deferred and then emitted
2043 later. Fortunately, we already have two flags that are part of struct
2044 function that tell if a function uses varargs or stdarg. */
2045 #define SETUP_INCOMING_VARARGS(ASF, MODE, TYPE, PAS, ST) do \
2046 if (! current_function_stdarg) \
2047 abort (); \
2048 while (0)
2050 /* Define the `__builtin_va_list' type for the ABI. */
2051 #define BUILD_VA_LIST_TYPE(VALIST) \
2052 (VALIST) = sh_build_va_list ()
2054 /* Implement `va_start' for varargs and stdarg. */
2055 #define EXPAND_BUILTIN_VA_START(valist, nextarg) \
2056 sh_va_start (valist, nextarg)
2058 /* Implement `va_arg'. */
2059 #define EXPAND_BUILTIN_VA_ARG(valist, type) \
2060 sh_va_arg (valist, type)
2062 /* Call the function profiler with a given profile label.
2063 We use two .aligns, so as to make sure that both the .long is aligned
2064 on a 4 byte boundary, and that the .long is a fixed distance (2 bytes)
2065 from the trapa instruction. */
2067 #define FUNCTION_PROFILER(STREAM,LABELNO) \
2069 fprintf((STREAM), "\t.align\t2\n"); \
2070 fprintf((STREAM), "\ttrapa\t#33\n"); \
2071 fprintf((STREAM), "\t.align\t2\n"); \
2072 asm_fprintf((STREAM), "\t.long\t%LLP%d\n", (LABELNO)); \
2075 /* Define this macro if the code for function profiling should come
2076 before the function prologue. Normally, the profiling code comes
2077 after. */
2079 #define PROFILE_BEFORE_PROLOGUE
2081 /* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
2082 the stack pointer does not matter. The value is tested only in
2083 functions that have frame pointers.
2084 No definition is equivalent to always zero. */
2086 #define EXIT_IGNORE_STACK 1
2089 On the SH, the trampoline looks like
2090 2 0002 D202 mov.l l2,r2
2091 1 0000 D301 mov.l l1,r3
2092 3 0004 422B jmp @r2
2093 4 0006 0009 nop
2094 5 0008 00000000 l1: .long area
2095 6 000c 00000000 l2: .long function */
2097 /* Length in units of the trampoline for entering a nested function. */
2098 #define TRAMPOLINE_SIZE (TARGET_SHMEDIA64 ? 40 : TARGET_SH5 ? 24 : 16)
2100 /* Alignment required for a trampoline in bits . */
2101 #define TRAMPOLINE_ALIGNMENT \
2102 ((CACHE_LOG < 3 || (TARGET_SMALLCODE && ! TARGET_HARVARD)) ? 32 \
2103 : TARGET_SHMEDIA ? 256 : 64)
2105 /* Emit RTL insns to initialize the variable parts of a trampoline.
2106 FNADDR is an RTX for the address of the function's pure code.
2107 CXT is an RTX for the static chain value for the function. */
2109 #define INITIALIZE_TRAMPOLINE(TRAMP, FNADDR, CXT) \
2110 sh_initialize_trampoline ((TRAMP), (FNADDR), (CXT))
2112 /* On SH5, trampolines are SHmedia code, so add 1 to the address. */
2114 #define TRAMPOLINE_ADJUST_ADDRESS(TRAMP) do \
2116 if (TARGET_SHMEDIA) \
2117 (TRAMP) = expand_simple_binop (Pmode, PLUS, (TRAMP), GEN_INT (1), \
2118 gen_reg_rtx (Pmode), 0, \
2119 OPTAB_LIB_WIDEN); \
2120 } while (0)
2122 /* A C expression whose value is RTL representing the value of the return
2123 address for the frame COUNT steps up from the current frame.
2124 FRAMEADDR is already the frame pointer of the COUNT frame, so we
2125 can ignore COUNT. */
2127 #define RETURN_ADDR_RTX(COUNT, FRAME) \
2128 (((COUNT) == 0) \
2129 ? get_hard_reg_initial_val (Pmode, TARGET_SHMEDIA ? PR_MEDIA_REG : PR_REG) \
2130 : (rtx) 0)
2132 /* A C expression whose value is RTL representing the location of the
2133 incoming return address at the beginning of any function, before the
2134 prologue. This RTL is either a REG, indicating that the return
2135 value is saved in REG, or a MEM representing a location in
2136 the stack. */
2137 #define INCOMING_RETURN_ADDR_RTX \
2138 gen_rtx_REG (Pmode, TARGET_SHMEDIA ? PR_MEDIA_REG : PR_REG)
2140 /* Generate necessary RTL for __builtin_saveregs(). */
2141 #define EXPAND_BUILTIN_SAVEREGS() sh_builtin_saveregs ()
2143 /* Addressing modes, and classification of registers for them. */
2144 #define HAVE_POST_INCREMENT TARGET_SH1
2145 #define HAVE_PRE_DECREMENT TARGET_SH1
2147 #define USE_LOAD_POST_INCREMENT(mode) ((mode == SImode || mode == DImode) \
2148 ? 0 : TARGET_SH1)
2149 #define USE_LOAD_PRE_DECREMENT(mode) 0
2150 #define USE_STORE_POST_INCREMENT(mode) 0
2151 #define USE_STORE_PRE_DECREMENT(mode) ((mode == SImode || mode == DImode) \
2152 ? 0 : TARGET_SH1)
2154 #define MOVE_BY_PIECES_P(SIZE, ALIGN) (move_by_pieces_ninsns (SIZE, ALIGN) \
2155 < (TARGET_SMALLCODE ? 2 : \
2156 ((ALIGN >= 32) ? 16 : 2)))
2158 /* Macros to check register numbers against specific register classes. */
2160 /* These assume that REGNO is a hard or pseudo reg number.
2161 They give nonzero only if REGNO is a hard reg of the suitable class
2162 or a pseudo reg currently allocated to a suitable hard reg.
2163 Since they use reg_renumber, they are safe only once reg_renumber
2164 has been allocated, which happens in local-alloc.c. */
2166 #define REGNO_OK_FOR_BASE_P(REGNO) \
2167 (GENERAL_OR_AP_REGISTER_P (REGNO) \
2168 || GENERAL_OR_AP_REGISTER_P (reg_renumber[(REGNO)]))
2169 #define REGNO_OK_FOR_INDEX_P(REGNO) \
2170 (TARGET_SHMEDIA \
2171 ? (GENERAL_REGISTER_P (REGNO) \
2172 || GENERAL_REGISTER_P ((unsigned) reg_renumber[(REGNO)])) \
2173 : (REGNO) == R0_REG || (unsigned) reg_renumber[(REGNO)] == R0_REG)
2175 /* Maximum number of registers that can appear in a valid memory
2176 address. */
2178 #define MAX_REGS_PER_ADDRESS 2
2180 /* Recognize any constant value that is a valid address. */
2182 #define CONSTANT_ADDRESS_P(X) (GET_CODE (X) == LABEL_REF)
2184 /* Nonzero if the constant value X is a legitimate general operand. */
2186 #define LEGITIMATE_CONSTANT_P(X) \
2187 (TARGET_SHMEDIA \
2188 ? ((GET_MODE (X) != DFmode \
2189 && GET_MODE_CLASS (GET_MODE (X)) != MODE_VECTOR_FLOAT) \
2190 || (X) == CONST0_RTX (GET_MODE (X)) \
2191 || ! TARGET_SHMEDIA_FPU \
2192 || TARGET_SHMEDIA64) \
2193 : (GET_CODE (X) != CONST_DOUBLE \
2194 || GET_MODE (X) == DFmode || GET_MODE (X) == SFmode \
2195 || (TARGET_SH2E && (fp_zero_operand (X) || fp_one_operand (X)))))
2197 /* The macros REG_OK_FOR..._P assume that the arg is a REG rtx
2198 and check its validity for a certain class.
2199 We have two alternate definitions for each of them.
2200 The usual definition accepts all pseudo regs; the other rejects
2201 them unless they have been allocated suitable hard regs.
2202 The symbol REG_OK_STRICT causes the latter definition to be used. */
2204 #ifndef REG_OK_STRICT
2206 /* Nonzero if X is a hard reg that can be used as a base reg
2207 or if it is a pseudo reg. */
2208 #define REG_OK_FOR_BASE_P(X) \
2209 (GENERAL_OR_AP_REGISTER_P (REGNO (X)) || REGNO (X) >= FIRST_PSEUDO_REGISTER)
2211 /* Nonzero if X is a hard reg that can be used as an index
2212 or if it is a pseudo reg. */
2213 #define REG_OK_FOR_INDEX_P(X) \
2214 ((TARGET_SHMEDIA ? GENERAL_REGISTER_P (REGNO (X)) \
2215 : REGNO (X) == R0_REG) || REGNO (X) >= FIRST_PSEUDO_REGISTER)
2217 /* Nonzero if X/OFFSET is a hard reg that can be used as an index
2218 or if X is a pseudo reg. */
2219 #define SUBREG_OK_FOR_INDEX_P(X, OFFSET) \
2220 ((TARGET_SHMEDIA ? GENERAL_REGISTER_P (REGNO (X)) \
2221 : REGNO (X) == R0_REG && OFFSET == 0) || REGNO (X) >= FIRST_PSEUDO_REGISTER)
2223 #else
2225 /* Nonzero if X is a hard reg that can be used as a base reg. */
2226 #define REG_OK_FOR_BASE_P(X) \
2227 REGNO_OK_FOR_BASE_P (REGNO (X))
2229 /* Nonzero if X is a hard reg that can be used as an index. */
2230 #define REG_OK_FOR_INDEX_P(X) \
2231 REGNO_OK_FOR_INDEX_P (REGNO (X))
2233 /* Nonzero if X/OFFSET is a hard reg that can be used as an index. */
2234 #define SUBREG_OK_FOR_INDEX_P(X, OFFSET) \
2235 (REGNO_OK_FOR_INDEX_P (REGNO (X)) && (OFFSET) == 0)
2237 #endif
2239 /* The 'Q' constraint is a pc relative load operand. */
2240 #define EXTRA_CONSTRAINT_Q(OP) \
2241 (GET_CODE (OP) == MEM \
2242 && ((GET_CODE (XEXP ((OP), 0)) == LABEL_REF) \
2243 || (GET_CODE (XEXP ((OP), 0)) == CONST \
2244 && GET_CODE (XEXP (XEXP ((OP), 0), 0)) == PLUS \
2245 && GET_CODE (XEXP (XEXP (XEXP ((OP), 0), 0), 0)) == LABEL_REF \
2246 && GET_CODE (XEXP (XEXP (XEXP ((OP), 0), 0), 1)) == CONST_INT)))
2248 /* The `S' constraint is a 16-bit constant, literal or symbolic. */
2249 #define EXTRA_CONSTRAINT_S(OP) \
2250 (GET_CODE (OP) == CONST \
2251 && GET_CODE (XEXP ((OP), 0)) == SIGN_EXTEND \
2252 && GET_MODE (XEXP ((OP), 0)) == DImode \
2253 && GET_CODE (XEXP (XEXP ((OP), 0), 0)) == TRUNCATE \
2254 && GET_MODE (XEXP (XEXP ((OP), 0), 0)) == HImode \
2255 && (MOVI_SHORI_BASE_OPERAND_P (XEXP (XEXP (XEXP ((OP), 0), 0), 0)) \
2256 || (GET_CODE (XEXP (XEXP (XEXP ((OP), 0), 0), 0)) == ASHIFTRT \
2257 && (MOVI_SHORI_BASE_OPERAND_P \
2258 (XEXP (XEXP (XEXP (XEXP ((OP), 0), 0), 0), 0))) \
2259 && GET_CODE (XEXP (XEXP (XEXP (XEXP ((OP), 0), 0), 0), \
2260 1)) == CONST_INT)))
2262 /* Check whether OP is a datalabel unspec. */
2263 #define DATALABEL_REF_NO_CONST_P(OP) \
2264 (GET_CODE (OP) == UNSPEC \
2265 && XINT ((OP), 1) == UNSPEC_DATALABEL \
2266 && XVECLEN ((OP), 0) == 1 \
2267 && (GET_CODE (XVECEXP ((OP), 0, 0)) == SYMBOL_REF \
2268 || GET_CODE (XVECEXP ((OP), 0, 0)) == LABEL_REF))
2270 /* Check whether OP is a datalabel unspec, possibly enclosed within a
2271 CONST. */
2272 #define DATALABEL_REF_P(OP) \
2273 ((GET_CODE (OP) == CONST && DATALABEL_REF_NO_CONST_P (XEXP ((OP), 0))) \
2274 || DATALABEL_REF_NO_CONST_P (OP))
2276 #define GOT_ENTRY_P(OP) \
2277 (GET_CODE (OP) == CONST && GET_CODE (XEXP ((OP), 0)) == UNSPEC \
2278 && XINT (XEXP ((OP), 0), 1) == UNSPEC_GOT)
2280 #define GOTPLT_ENTRY_P(OP) \
2281 (GET_CODE (OP) == CONST && GET_CODE (XEXP ((OP), 0)) == UNSPEC \
2282 && XINT (XEXP ((OP), 0), 1) == UNSPEC_GOTPLT)
2284 #define UNSPEC_GOTOFF_P(OP) \
2285 (GET_CODE (OP) == UNSPEC && XINT ((OP), 1) == UNSPEC_GOTOFF)
2287 #define GOTOFF_P(OP) \
2288 (GET_CODE (OP) == CONST \
2289 && (UNSPEC_GOTOFF_P (XEXP ((OP), 0)) \
2290 || (GET_CODE (XEXP ((OP), 0)) == PLUS \
2291 && UNSPEC_GOTOFF_P (XEXP (XEXP ((OP), 0), 0)) \
2292 && GET_CODE (XEXP (XEXP ((OP), 0), 1)) == CONST_INT)))
2294 #define PIC_ADDR_P(OP) \
2295 (GET_CODE (OP) == CONST && GET_CODE (XEXP ((OP), 0)) == UNSPEC \
2296 && XINT (XEXP ((OP), 0), 1) == UNSPEC_PIC)
2298 #define NON_PIC_REFERENCE_P(OP) \
2299 (GET_CODE (OP) == LABEL_REF || GET_CODE (OP) == SYMBOL_REF \
2300 || DATALABEL_REF_P (OP) \
2301 || (GET_CODE (OP) == CONST && GET_CODE (XEXP ((OP), 0)) == PLUS \
2302 && (GET_CODE (XEXP (XEXP ((OP), 0), 0)) == SYMBOL_REF \
2303 || DATALABEL_REF_P (XEXP (XEXP ((OP), 0), 0))) \
2304 && GET_CODE (XEXP (XEXP ((OP), 0), 1)) == CONST_INT))
2306 #define PIC_REFERENCE_P(OP) \
2307 (GOT_ENTRY_P (OP) || GOTPLT_ENTRY_P (OP) \
2308 || GOTOFF_P (OP) || PIC_ADDR_P (OP))
2310 #define MOVI_SHORI_BASE_OPERAND_P(OP) \
2311 (flag_pic ? PIC_REFERENCE_P (OP) : NON_PIC_REFERENCE_P (OP))
2313 /* The `T' constraint is a label or a symbol. */
2314 #define EXTRA_CONSTRAINT_T(OP) \
2315 (NON_PIC_REFERENCE_P (OP))
2317 /* A zero in any shape or form. */
2318 #define EXTRA_CONSTRAINT_U(OP) \
2319 ((OP) == CONST0_RTX (GET_MODE (OP)))
2321 /* Any vector constant we can handle. */
2322 #define EXTRA_CONSTRAINT_W(OP) \
2323 (GET_CODE (OP) == CONST_VECTOR \
2324 && (sh_rep_vec ((OP), VOIDmode) \
2325 || (HOST_BITS_PER_WIDE_INT >= 64 \
2326 ? sh_const_vec ((OP), VOIDmode) \
2327 : sh_1el_vec ((OP), VOIDmode))))
2329 #define EXTRA_CONSTRAINT_Z(OP) \
2330 (GET_CODE (OP) == CONST_INT \
2331 && (INTVAL (OP) == (unsigned) 0xffffffff \
2332 || INTVAL (OP) == (HOST_WIDE_INT) -1 << 32))
2334 #define EXTRA_CONSTRAINT(OP, C) \
2335 ((C) == 'Q' ? EXTRA_CONSTRAINT_Q (OP) \
2336 : (C) == 'S' ? EXTRA_CONSTRAINT_S (OP) \
2337 : (C) == 'T' ? EXTRA_CONSTRAINT_T (OP) \
2338 : (C) == 'U' ? EXTRA_CONSTRAINT_U (OP) \
2339 : (C) == 'W' ? EXTRA_CONSTRAINT_W (OP) \
2340 : (C) == 'Z' ? EXTRA_CONSTRAINT_Z (OP) \
2341 : 0)
2343 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2344 that is a valid memory address for an instruction.
2345 The MODE argument is the machine mode for the MEM expression
2346 that wants to use this address. */
2348 #define MODE_DISP_OK_4(X,MODE) \
2349 (GET_MODE_SIZE (MODE) == 4 && (unsigned) INTVAL (X) < 64 \
2350 && ! (INTVAL (X) & 3) && ! (TARGET_SH2E && (MODE) == SFmode))
2352 #define MODE_DISP_OK_8(X,MODE) \
2353 ((GET_MODE_SIZE(MODE)==8) && ((unsigned)INTVAL(X)<60) \
2354 && ! (INTVAL(X) & 3) && ! (TARGET_SH4 && (MODE) == DFmode))
2356 #define BASE_REGISTER_RTX_P(X) \
2357 ((GET_CODE (X) == REG && REG_OK_FOR_BASE_P (X)) \
2358 || (GET_CODE (X) == SUBREG \
2359 && GET_CODE (SUBREG_REG (X)) == REG \
2360 && REG_OK_FOR_BASE_P (SUBREG_REG (X))))
2362 /* Since this must be r0, which is a single register class, we must check
2363 SUBREGs more carefully, to be sure that we don't accept one that extends
2364 outside the class. */
2365 #define INDEX_REGISTER_RTX_P(X) \
2366 ((GET_CODE (X) == REG && REG_OK_FOR_INDEX_P (X)) \
2367 || (GET_CODE (X) == SUBREG \
2368 && GET_CODE (SUBREG_REG (X)) == REG \
2369 && SUBREG_OK_FOR_INDEX_P (SUBREG_REG (X), SUBREG_BYTE (X))))
2371 /* Jump to LABEL if X is a valid address RTX. This must also take
2372 REG_OK_STRICT into account when deciding about valid registers, but it uses
2373 the above macros so we are in luck.
2375 Allow REG
2376 REG+disp
2377 REG+r0
2378 REG++
2379 --REG */
2381 /* ??? The SH2e does not have the REG+disp addressing mode when loading values
2382 into the FRx registers. We implement this by setting the maximum offset
2383 to zero when the value is SFmode. This also restricts loading of SFmode
2384 values into the integer registers, but that can't be helped. */
2386 /* The SH allows a displacement in a QI or HI amode, but only when the
2387 other operand is R0. GCC doesn't handle this very well, so we forgo
2388 all of that.
2390 A legitimate index for a QI or HI is 0, SI can be any number 0..63,
2391 DI can be any number 0..60. */
2393 #define GO_IF_LEGITIMATE_INDEX(MODE, OP, LABEL) \
2394 do { \
2395 if (GET_CODE (OP) == CONST_INT) \
2397 if (TARGET_SHMEDIA) \
2399 int MODE_SIZE = GET_MODE_SIZE (MODE); \
2400 if (! (INTVAL (OP) & (MODE_SIZE - 1)) \
2401 && INTVAL (OP) >= -512 * MODE_SIZE \
2402 && INTVAL (OP) < 512 * MODE_SIZE) \
2403 goto LABEL; \
2404 else \
2405 break; \
2407 if (MODE_DISP_OK_4 ((OP), (MODE))) goto LABEL; \
2408 if (MODE_DISP_OK_8 ((OP), (MODE))) goto LABEL; \
2410 } while(0)
2412 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, LABEL) \
2414 if (BASE_REGISTER_RTX_P (X)) \
2415 goto LABEL; \
2416 else if ((GET_CODE (X) == POST_INC || GET_CODE (X) == PRE_DEC) \
2417 && ! TARGET_SHMEDIA \
2418 && BASE_REGISTER_RTX_P (XEXP ((X), 0))) \
2419 goto LABEL; \
2420 else if (GET_CODE (X) == PLUS \
2421 && ((MODE) != PSImode || reload_completed)) \
2423 rtx xop0 = XEXP ((X), 0); \
2424 rtx xop1 = XEXP ((X), 1); \
2425 if (GET_MODE_SIZE (MODE) <= 8 && BASE_REGISTER_RTX_P (xop0)) \
2426 GO_IF_LEGITIMATE_INDEX ((MODE), xop1, LABEL); \
2427 if (GET_MODE_SIZE (MODE) <= 4 \
2428 || (TARGET_SHMEDIA && GET_MODE_SIZE (MODE) <= 8) \
2429 || (TARGET_SH4 && TARGET_FMOVD && MODE == DFmode)) \
2431 if (BASE_REGISTER_RTX_P (xop1) && INDEX_REGISTER_RTX_P (xop0))\
2432 goto LABEL; \
2433 if (INDEX_REGISTER_RTX_P (xop1) && BASE_REGISTER_RTX_P (xop0))\
2434 goto LABEL; \
2439 /* Try machine-dependent ways of modifying an illegitimate address
2440 to be legitimate. If we find one, return the new, valid address.
2441 This macro is used in only one place: `memory_address' in explow.c.
2443 OLDX is the address as it was before break_out_memory_refs was called.
2444 In some cases it is useful to look at this to decide what needs to be done.
2446 MODE and WIN are passed so that this macro can use
2447 GO_IF_LEGITIMATE_ADDRESS.
2449 It is always safe for this macro to do nothing. It exists to recognize
2450 opportunities to optimize the output.
2452 For the SH, if X is almost suitable for indexing, but the offset is
2453 out of range, convert it into a normal form so that cse has a chance
2454 of reducing the number of address registers used. */
2456 #define LEGITIMIZE_ADDRESS(X,OLDX,MODE,WIN) \
2458 if (flag_pic) \
2459 (X) = legitimize_pic_address (OLDX, MODE, NULL_RTX); \
2460 if (GET_CODE (X) == PLUS \
2461 && (GET_MODE_SIZE (MODE) == 4 \
2462 || GET_MODE_SIZE (MODE) == 8) \
2463 && GET_CODE (XEXP ((X), 1)) == CONST_INT \
2464 && BASE_REGISTER_RTX_P (XEXP ((X), 0)) \
2465 && ! TARGET_SHMEDIA \
2466 && ! (TARGET_SH4 && (MODE) == DFmode) \
2467 && ! (TARGET_SH2E && (MODE) == SFmode)) \
2469 rtx index_rtx = XEXP ((X), 1); \
2470 HOST_WIDE_INT offset = INTVAL (index_rtx), offset_base; \
2471 rtx sum; \
2473 GO_IF_LEGITIMATE_INDEX ((MODE), index_rtx, WIN); \
2474 /* On rare occasions, we might get an unaligned pointer \
2475 that is indexed in a way to give an aligned address. \
2476 Therefore, keep the lower two bits in offset_base. */ \
2477 /* Instead of offset_base 128..131 use 124..127, so that \
2478 simple add suffices. */ \
2479 if (offset > 127) \
2481 offset_base = ((offset + 4) & ~60) - 4; \
2483 else \
2484 offset_base = offset & ~60; \
2485 /* Sometimes the normal form does not suit DImode. We \
2486 could avoid that by using smaller ranges, but that \
2487 would give less optimized code when SImode is \
2488 prevalent. */ \
2489 if (GET_MODE_SIZE (MODE) + offset - offset_base <= 64) \
2491 sum = expand_binop (Pmode, add_optab, XEXP ((X), 0), \
2492 GEN_INT (offset_base), NULL_RTX, 0, \
2493 OPTAB_LIB_WIDEN); \
2495 (X) = gen_rtx_PLUS (Pmode, sum, GEN_INT (offset - offset_base)); \
2496 goto WIN; \
2501 /* A C compound statement that attempts to replace X, which is an address
2502 that needs reloading, with a valid memory address for an operand of
2503 mode MODE. WIN is a C statement label elsewhere in the code.
2505 Like for LEGITIMIZE_ADDRESS, for the SH we try to get a normal form
2506 of the address. That will allow inheritance of the address reloads. */
2508 #define LEGITIMIZE_RELOAD_ADDRESS(X,MODE,OPNUM,TYPE,IND_LEVELS,WIN) \
2510 if (GET_CODE (X) == PLUS \
2511 && (GET_MODE_SIZE (MODE) == 4 || GET_MODE_SIZE (MODE) == 8) \
2512 && GET_CODE (XEXP (X, 1)) == CONST_INT \
2513 && BASE_REGISTER_RTX_P (XEXP (X, 0)) \
2514 && ! TARGET_SHMEDIA \
2515 && ! (TARGET_SH4 && (MODE) == DFmode) \
2516 && ! ((MODE) == PSImode && (TYPE) == RELOAD_FOR_INPUT_ADDRESS)) \
2518 rtx index_rtx = XEXP (X, 1); \
2519 HOST_WIDE_INT offset = INTVAL (index_rtx), offset_base; \
2520 rtx sum; \
2522 if (TARGET_SH2E && MODE == SFmode) \
2524 X = copy_rtx (X); \
2525 push_reload (index_rtx, NULL_RTX, &XEXP (X, 1), NULL, \
2526 INDEX_REG_CLASS, Pmode, VOIDmode, 0, 0, (OPNUM), \
2527 (TYPE)); \
2528 goto WIN; \
2530 /* Instead of offset_base 128..131 use 124..127, so that \
2531 simple add suffices. */ \
2532 if (offset > 127) \
2534 offset_base = ((offset + 4) & ~60) - 4; \
2536 else \
2537 offset_base = offset & ~60; \
2538 /* Sometimes the normal form does not suit DImode. We \
2539 could avoid that by using smaller ranges, but that \
2540 would give less optimized code when SImode is \
2541 prevalent. */ \
2542 if (GET_MODE_SIZE (MODE) + offset - offset_base <= 64) \
2544 sum = gen_rtx (PLUS, Pmode, XEXP (X, 0), \
2545 GEN_INT (offset_base)); \
2546 X = gen_rtx (PLUS, Pmode, sum, GEN_INT (offset - offset_base));\
2547 push_reload (sum, NULL_RTX, &XEXP (X, 0), NULL, \
2548 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, (OPNUM), \
2549 (TYPE)); \
2550 goto WIN; \
2553 /* We must re-recognize what we created before. */ \
2554 else if (GET_CODE (X) == PLUS \
2555 && (GET_MODE_SIZE (MODE) == 4 || GET_MODE_SIZE (MODE) == 8) \
2556 && GET_CODE (XEXP (X, 0)) == PLUS \
2557 && GET_CODE (XEXP (XEXP (X, 0), 1)) == CONST_INT \
2558 && BASE_REGISTER_RTX_P (XEXP (XEXP (X, 0), 0)) \
2559 && GET_CODE (XEXP (X, 1)) == CONST_INT \
2560 && ! TARGET_SHMEDIA \
2561 && ! (TARGET_SH2E && MODE == SFmode)) \
2563 /* Because this address is so complex, we know it must have \
2564 been created by LEGITIMIZE_RELOAD_ADDRESS before; thus, \
2565 it is already unshared, and needs no further unsharing. */ \
2566 push_reload (XEXP ((X), 0), NULL_RTX, &XEXP ((X), 0), NULL, \
2567 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, (OPNUM), (TYPE));\
2568 goto WIN; \
2572 /* Go to LABEL if ADDR (a legitimate address expression)
2573 has an effect that depends on the machine mode it is used for.
2575 ??? Strictly speaking, we should also include all indexed addressing,
2576 because the index scale factor is the length of the operand.
2577 However, the impact of GO_IF_MODE_DEPENDENT_ADDRESS would be to
2578 high if we did that. So we rely on reload to fix things up. */
2580 #define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR,LABEL) \
2582 if (GET_CODE(ADDR) == PRE_DEC || GET_CODE(ADDR) == POST_INC) \
2583 goto LABEL; \
2586 /* Specify the machine mode that this machine uses
2587 for the index in the tablejump instruction. */
2588 #define CASE_VECTOR_MODE ((! optimize || TARGET_BIGTABLE) ? SImode : HImode)
2590 #define CASE_VECTOR_SHORTEN_MODE(MIN_OFFSET, MAX_OFFSET, BODY) \
2591 ((MIN_OFFSET) >= 0 && (MAX_OFFSET) <= 127 \
2592 ? (ADDR_DIFF_VEC_FLAGS (BODY).offset_unsigned = 0, QImode) \
2593 : (MIN_OFFSET) >= 0 && (MAX_OFFSET) <= 255 \
2594 ? (ADDR_DIFF_VEC_FLAGS (BODY).offset_unsigned = 1, QImode) \
2595 : (MIN_OFFSET) >= -32768 && (MAX_OFFSET) <= 32767 ? HImode \
2596 : SImode)
2598 /* Define as C expression which evaluates to nonzero if the tablejump
2599 instruction expects the table to contain offsets from the address of the
2600 table.
2601 Do not define this if the table should contain absolute addresses. */
2602 #define CASE_VECTOR_PC_RELATIVE 1
2604 /* Define it here, so that it doesn't get bumped to 64-bits on SHmedia. */
2605 #define FLOAT_TYPE_SIZE 32
2607 /* Since the SH2e has only `float' support, it is desirable to make all
2608 floating point types equivalent to `float'. */
2609 #define DOUBLE_TYPE_SIZE ((TARGET_SH2E && ! TARGET_SH4) ? 32 : 64)
2611 /* 'char' is signed by default. */
2612 #define DEFAULT_SIGNED_CHAR 1
2614 /* The type of size_t unsigned int. */
2615 #define SIZE_TYPE (TARGET_SH5 ? "long unsigned int" : "unsigned int")
2617 #undef PTRDIFF_TYPE
2618 #define PTRDIFF_TYPE (TARGET_SH5 ? "long int" : "int")
2620 #define WCHAR_TYPE "short unsigned int"
2621 #define WCHAR_TYPE_SIZE 16
2623 #define SH_ELF_WCHAR_TYPE "long int"
2625 /* Don't cse the address of the function being compiled. */
2626 /*#define NO_RECURSIVE_FUNCTION_CSE 1*/
2628 /* Max number of bytes we can move from memory to memory
2629 in one reasonably fast instruction. */
2630 #define MOVE_MAX (TARGET_SHMEDIA ? 8 : 4)
2632 /* Maximum value possibly taken by MOVE_MAX. Must be defined whenever
2633 MOVE_MAX is not a compile-time constant. */
2634 #define MAX_MOVE_MAX 8
2636 /* Max number of bytes we want move_by_pieces to be able to copy
2637 efficiently. */
2638 #define MOVE_MAX_PIECES (TARGET_SH4 || TARGET_SHMEDIA ? 8 : 4)
2640 /* Define if operations between registers always perform the operation
2641 on the full register even if a narrower mode is specified. */
2642 #define WORD_REGISTER_OPERATIONS
2644 /* Define if loading in MODE, an integral mode narrower than BITS_PER_WORD
2645 will either zero-extend or sign-extend. The value of this macro should
2646 be the code that says which one of the two operations is implicitly
2647 done, NIL if none. */
2648 /* For SHmedia, we can truncate to QImode easier using zero extension. */
2649 /* FP registers can load SImode values, but don't implicitly sign-extend
2650 them to DImode. */
2651 #define LOAD_EXTEND_OP(MODE) \
2652 (((MODE) == QImode && TARGET_SHMEDIA) ? ZERO_EXTEND \
2653 : (MODE) != SImode ? SIGN_EXTEND : NIL)
2655 /* Define if loading short immediate values into registers sign extends. */
2656 #define SHORT_IMMEDIATES_SIGN_EXTEND
2658 /* Nonzero if access to memory by bytes is no faster than for words. */
2659 #define SLOW_BYTE_ACCESS 1
2661 /* We assume that the store-condition-codes instructions store 0 for false
2662 and some other value for true. This is the value stored for true. */
2664 #define STORE_FLAG_VALUE 1
2666 /* Immediate shift counts are truncated by the output routines (or was it
2667 the assembler?). Shift counts in a register are truncated by SH. Note
2668 that the native compiler puts too large (> 32) immediate shift counts
2669 into a register and shifts by the register, letting the SH decide what
2670 to do instead of doing that itself. */
2671 /* ??? The library routines in lib1funcs.asm truncate the shift count.
2672 However, the SH3 has hardware shifts that do not truncate exactly as gcc
2673 expects - the sign bit is significant - so it appears that we need to
2674 leave this zero for correct SH3 code. */
2675 #define SHIFT_COUNT_TRUNCATED (! TARGET_SH3)
2677 /* All integers have the same format so truncation is easy. */
2678 #define TRULY_NOOP_TRUNCATION(OUTPREC,INPREC) 1
2680 /* Define this if addresses of constant functions
2681 shouldn't be put through pseudo regs where they can be cse'd.
2682 Desirable on machines where ordinary constants are expensive
2683 but a CALL with constant address is cheap. */
2684 /*#define NO_FUNCTION_CSE 1*/
2686 /* Chars and shorts should be passed as ints. */
2687 #define PROMOTE_PROTOTYPES 1
2689 /* The machine modes of pointers and functions. */
2690 #define Pmode (TARGET_SHMEDIA64 ? DImode : SImode)
2691 #define FUNCTION_MODE Pmode
2693 /* The multiply insn on the SH1 and the divide insns on the SH1 and SH2
2694 are actually function calls with some special constraints on arguments
2695 and register usage.
2697 These macros tell reorg that the references to arguments and
2698 register clobbers for insns of type sfunc do not appear to happen
2699 until after the millicode call. This allows reorg to put insns
2700 which set the argument registers into the delay slot of the millicode
2701 call -- thus they act more like traditional CALL_INSNs.
2703 get_attr_is_sfunc will try to recognize the given insn, so make sure to
2704 filter out things it will not accept -- SEQUENCE, USE and CLOBBER insns
2705 in particular. */
2707 #define INSN_SETS_ARE_DELAYED(X) \
2708 ((GET_CODE (X) == INSN \
2709 && GET_CODE (PATTERN (X)) != SEQUENCE \
2710 && GET_CODE (PATTERN (X)) != USE \
2711 && GET_CODE (PATTERN (X)) != CLOBBER \
2712 && get_attr_is_sfunc (X)))
2714 #define INSN_REFERENCES_ARE_DELAYED(X) \
2715 ((GET_CODE (X) == INSN \
2716 && GET_CODE (PATTERN (X)) != SEQUENCE \
2717 && GET_CODE (PATTERN (X)) != USE \
2718 && GET_CODE (PATTERN (X)) != CLOBBER \
2719 && get_attr_is_sfunc (X)))
2722 /* Position Independent Code. */
2724 /* The prefix used to mark SYMBOL_REFs that refer to data symbols. */
2725 #define SH_DATALABEL_ENCODING "#"
2727 /* Return true if SYM_NAME starts with SH_DATALABEL_ENCODING. */
2728 #define DATALABEL_SYMNAME_P(SYM_NAME) \
2729 (SH_DATALABEL_ENCODING[1] ? (abort (), 0) : \
2730 (SYM_NAME)[0] == SH_DATALABEL_ENCODING[0])
2732 /* Skip an optional SH_DATALABEL_ENCODING in the beginning of
2733 SYM_NAME. Then, remove a leading *, like the default definition in
2734 output.h. */
2735 #define STRIP_DATALABEL_ENCODING(VAR, SYM_NAME) \
2736 (VAR) = (SYM_NAME) + (DATALABEL_SYMNAME_P (SYM_NAME) \
2737 ? strlen (SH_DATALABEL_ENCODING) : 0)
2739 /* We can't directly access anything that contains a symbol,
2740 nor can we indirect via the constant pool. */
2741 #define LEGITIMATE_PIC_OPERAND_P(X) \
2742 (! nonpic_symbol_mentioned_p (X) \
2743 && (GET_CODE (X) != SYMBOL_REF \
2744 || ! CONSTANT_POOL_ADDRESS_P (X) \
2745 || ! nonpic_symbol_mentioned_p (get_pool_constant (X))))
2747 #define SYMBOLIC_CONST_P(X) \
2748 ((GET_CODE (X) == SYMBOL_REF || GET_CODE (X) == LABEL_REF) \
2749 && nonpic_symbol_mentioned_p (X))
2751 /* Compute the cost of an address. For the SH, all valid addresses are
2752 the same cost. Use a slightly higher cost for reg + reg addressing,
2753 since it increases pressure on r0. */
2755 #define ADDRESS_COST(X) (GET_CODE (X) == PLUS && ! CONSTANT_P (XEXP (X, 1)) \
2756 && ! TARGET_SHMEDIA \
2757 ? 1 : 0)
2759 /* Compute extra cost of moving data between one register class
2760 and another. */
2762 /* If SECONDARY*_RELOAD_CLASS says something about the src/dst pair, regclass
2763 uses this information. Hence, the general register <-> floating point
2764 register information here is not used for SFmode. */
2766 #define REGCLASS_HAS_GENERAL_REG(CLASS) \
2767 ((CLASS) == GENERAL_REGS || (CLASS) == R0_REGS \
2768 || (! TARGET_SHMEDIA && (CLASS) == SIBCALL_REGS))
2770 #define REGCLASS_HAS_FP_REG(CLASS) \
2771 ((CLASS) == FP0_REGS || (CLASS) == FP_REGS \
2772 || (CLASS) == DF_REGS || (CLASS) == DF_HI_REGS)
2774 #define REGISTER_MOVE_COST(MODE, SRCCLASS, DSTCLASS) \
2775 sh_register_move_cost ((MODE), (SRCCLASS), (DSTCLASS))
2777 /* ??? Perhaps make MEMORY_MOVE_COST depend on compiler option? This
2778 would be so that people with slow memory systems could generate
2779 different code that does fewer memory accesses. */
2781 /* A C expression for the cost of a branch instruction. A value of 1
2782 is the default; other values are interpreted relative to that.
2783 The SH1 does not have delay slots, hence we get a pipeline stall
2784 at every branch. The SH4 is superscalar, so the single delay slot
2785 is not sufficient to keep both pipelines filled. */
2786 #define BRANCH_COST (TARGET_SH5 ? 1 : ! TARGET_SH2 || TARGET_HARD_SH4 ? 2 : 1)
2788 /* Assembler output control. */
2790 /* A C string constant describing how to begin a comment in the target
2791 assembler language. The compiler assumes that the comment will end at
2792 the end of the line. */
2793 #define ASM_COMMENT_START "!"
2795 /* The text to go at the start of the assembler file. */
2796 #define ASM_FILE_START(STREAM) \
2797 output_file_start (STREAM)
2799 #define ASM_APP_ON ""
2800 #define ASM_APP_OFF ""
2801 #define FILE_ASM_OP "\t.file\n"
2802 #define SET_ASM_OP "\t.set\t"
2804 /* How to change between sections. */
2806 #define TEXT_SECTION_ASM_OP (TARGET_SHMEDIA32 ? "\t.section\t.text..SHmedia32,\"ax\"" : "\t.text")
2807 #define DATA_SECTION_ASM_OP "\t.data"
2809 #if defined CRT_BEGIN || defined CRT_END
2810 /* Arrange for TEXT_SECTION_ASM_OP to be a compile-time constant. */
2811 # undef TEXT_SECTION_ASM_OP
2812 # if __SHMEDIA__ == 1 && __SH5__ == 32
2813 # define TEXT_SECTION_ASM_OP "\t.section\t.text..SHmedia32,\"ax\""
2814 # else
2815 # define TEXT_SECTION_ASM_OP "\t.text"
2816 # endif
2817 #endif
2820 /* If defined, a C expression whose value is a string containing the
2821 assembler operation to identify the following data as
2822 uninitialized global data. If not defined, and neither
2823 `ASM_OUTPUT_BSS' nor `ASM_OUTPUT_ALIGNED_BSS' are defined,
2824 uninitialized global data will be output in the data section if
2825 `-fno-common' is passed, otherwise `ASM_OUTPUT_COMMON' will be
2826 used. */
2827 #ifndef BSS_SECTION_ASM_OP
2828 #define BSS_SECTION_ASM_OP "\t.section\t.bss"
2829 #endif
2831 /* Like `ASM_OUTPUT_BSS' except takes the required alignment as a
2832 separate, explicit argument. If you define this macro, it is used
2833 in place of `ASM_OUTPUT_BSS', and gives you more flexibility in
2834 handling the required alignment of the variable. The alignment is
2835 specified as the number of bits.
2837 Try to use function `asm_output_aligned_bss' defined in file
2838 `varasm.c' when defining this macro. */
2839 #ifndef ASM_OUTPUT_ALIGNED_BSS
2840 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
2841 asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
2842 #endif
2844 /* Define this so that jump tables go in same section as the current function,
2845 which could be text or it could be a user defined section. */
2846 #define JUMP_TABLES_IN_TEXT_SECTION 1
2848 #undef DO_GLOBAL_CTORS_BODY
2849 #define DO_GLOBAL_CTORS_BODY \
2851 typedef (*pfunc)(); \
2852 extern pfunc __ctors[]; \
2853 extern pfunc __ctors_end[]; \
2854 pfunc *p; \
2855 for (p = __ctors_end; p > __ctors; ) \
2857 (*--p)(); \
2861 #undef DO_GLOBAL_DTORS_BODY
2862 #define DO_GLOBAL_DTORS_BODY \
2864 typedef (*pfunc)(); \
2865 extern pfunc __dtors[]; \
2866 extern pfunc __dtors_end[]; \
2867 pfunc *p; \
2868 for (p = __dtors; p < __dtors_end; p++) \
2870 (*p)(); \
2874 #define ASM_OUTPUT_REG_PUSH(file, v) \
2875 fprintf ((file), "\tmov.l\tr%d,@-r15\n", (v));
2877 #define ASM_OUTPUT_REG_POP(file, v) \
2878 fprintf ((file), "\tmov.l\t@r15+,r%d\n", (v));
2880 /* DBX register number for a given compiler register number. */
2881 /* GDB has FPUL at 23 and FP0 at 25, so we must add one to all FP registers
2882 to match gdb. */
2883 /* svr4.h undefines this macro, yet we really want to use the same numbers
2884 for coff as for elf, so we go via another macro: SH_DBX_REGISTER_NUMBER. */
2885 /* expand_builtin_init_dwarf_reg_sizes uses this to test if a
2886 register exists, so we should return -1 for invalid register numbers. */
2887 #define DBX_REGISTER_NUMBER(REGNO) SH_DBX_REGISTER_NUMBER (REGNO)
2889 #define SH_DBX_REGISTER_NUMBER(REGNO) \
2890 (GENERAL_REGISTER_P (REGNO) \
2891 ? ((REGNO) - FIRST_GENERAL_REG) \
2892 : FP_REGISTER_P (REGNO) \
2893 ? ((REGNO) - FIRST_FP_REG + (TARGET_SH5 ? (TARGET_SHCOMPACT ? 245 \
2894 : 77) : 25)) \
2895 : XD_REGISTER_P (REGNO) \
2896 ? ((REGNO) - FIRST_XD_REG + (TARGET_SH5 ? 289 : 87)) \
2897 : TARGET_REGISTER_P (REGNO) \
2898 ? ((REGNO) - FIRST_TARGET_REG + 68) \
2899 : (REGNO) == PR_REG \
2900 ? (TARGET_SH5 ? 241 : 17) \
2901 : (REGNO) == PR_MEDIA_REG \
2902 ? (TARGET_SH5 ? 18 : -1) \
2903 : (REGNO) == T_REG \
2904 ? (TARGET_SH5 ? 242 : 18) \
2905 : (REGNO) == GBR_REG \
2906 ? (TARGET_SH5 ? 238 : 19) \
2907 : (REGNO) == MACH_REG \
2908 ? (TARGET_SH5 ? 239 : 20) \
2909 : (REGNO) == MACL_REG \
2910 ? (TARGET_SH5 ? 240 : 21) \
2911 : (REGNO) == FPUL_REG \
2912 ? (TARGET_SH5 ? 244 : 23) \
2913 : -1)
2915 /* This is how to output a reference to a user-level label named NAME. */
2916 #define ASM_OUTPUT_LABELREF(FILE, NAME) \
2917 do \
2919 const char * lname; \
2921 STRIP_DATALABEL_ENCODING (lname, (NAME)); \
2922 if (lname[0] == '*') \
2923 fputs (lname + 1, (FILE)); \
2924 else \
2925 asm_fprintf ((FILE), "%U%s", lname); \
2927 while (0)
2929 /* This is how to output a reference to a symbol_ref. On SH5,
2930 references to non-code symbols must be preceded by `datalabel'. */
2931 #define ASM_OUTPUT_SYMBOL_REF(FILE,SYM) \
2932 do \
2934 if (TARGET_SH5 \
2935 && (DATALABEL_SYMNAME_P (XSTR ((SYM), 0)) \
2936 || CONSTANT_POOL_ADDRESS_P (SYM))) \
2937 fputs ("datalabel ", (FILE)); \
2938 assemble_name ((FILE), XSTR ((SYM), 0)); \
2940 while (0)
2942 /* This is how to output an assembler line
2943 that says to advance the location counter
2944 to a multiple of 2**LOG bytes. */
2946 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
2947 if ((LOG) != 0) \
2948 fprintf ((FILE), "\t.align %d\n", (LOG))
2950 /* Globalizing directive for a label. */
2951 #define GLOBAL_ASM_OP "\t.global\t"
2953 /* #define ASM_OUTPUT_CASE_END(STREAM,NUM,TABLE) */
2955 /* Output a relative address table. */
2957 #define ASM_OUTPUT_ADDR_DIFF_ELT(STREAM,BODY,VALUE,REL) \
2958 switch (GET_MODE (BODY)) \
2960 case SImode: \
2961 if (TARGET_SH5) \
2963 asm_fprintf ((STREAM), "\t.long\t%LL%d-datalabel %LL%d\n", \
2964 (VALUE), (REL)); \
2965 break; \
2967 asm_fprintf ((STREAM), "\t.long\t%LL%d-%LL%d\n", (VALUE),(REL)); \
2968 break; \
2969 case HImode: \
2970 if (TARGET_SH5) \
2972 asm_fprintf ((STREAM), "\t.word\t%LL%d-datalabel %LL%d\n", \
2973 (VALUE), (REL)); \
2974 break; \
2976 asm_fprintf ((STREAM), "\t.word\t%LL%d-%LL%d\n", (VALUE),(REL)); \
2977 break; \
2978 case QImode: \
2979 if (TARGET_SH5) \
2981 asm_fprintf ((STREAM), "\t.byte\t%LL%d-datalabel %LL%d\n", \
2982 (VALUE), (REL)); \
2983 break; \
2985 asm_fprintf ((STREAM), "\t.byte\t%LL%d-%LL%d\n", (VALUE),(REL)); \
2986 break; \
2987 default: \
2988 break; \
2991 /* Output an absolute table element. */
2993 #define ASM_OUTPUT_ADDR_VEC_ELT(STREAM,VALUE) \
2994 if (! optimize || TARGET_BIGTABLE) \
2995 asm_fprintf ((STREAM), "\t.long\t%LL%d\n", (VALUE)); \
2996 else \
2997 asm_fprintf ((STREAM), "\t.word\t%LL%d\n", (VALUE));
3000 /* A C statement to be executed just prior to the output of
3001 assembler code for INSN, to modify the extracted operands so
3002 they will be output differently.
3004 Here the argument OPVEC is the vector containing the operands
3005 extracted from INSN, and NOPERANDS is the number of elements of
3006 the vector which contain meaningful data for this insn.
3007 The contents of this vector are what will be used to convert the insn
3008 template into assembler code, so you can change the assembler output
3009 by changing the contents of the vector. */
3011 #define FINAL_PRESCAN_INSN(INSN, OPVEC, NOPERANDS) \
3012 final_prescan_insn ((INSN), (OPVEC), (NOPERANDS))
3014 /* Print operand X (an rtx) in assembler syntax to file FILE.
3015 CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified.
3016 For `%' followed by punctuation, CODE is the punctuation and X is null. */
3018 #define PRINT_OPERAND(STREAM, X, CODE) print_operand ((STREAM), (X), (CODE))
3020 /* Print a memory address as an operand to reference that memory location. */
3022 #define PRINT_OPERAND_ADDRESS(STREAM,X) print_operand_address ((STREAM), (X))
3024 #define PRINT_OPERAND_PUNCT_VALID_P(CHAR) \
3025 ((CHAR) == '.' || (CHAR) == '#' || (CHAR) == '@' || (CHAR) == ',' \
3026 || (CHAR) == '$'|| (CHAR) == '\'')
3028 /* Recognize machine-specific patterns that may appear within
3029 constants. Used for PIC-specific UNSPECs. */
3030 #define OUTPUT_ADDR_CONST_EXTRA(STREAM, X, FAIL) \
3031 do \
3032 if (GET_CODE (X) == UNSPEC && XVECLEN ((X), 0) == 1) \
3034 switch (XINT ((X), 1)) \
3036 case UNSPEC_DATALABEL: \
3037 fputs ("datalabel ", (STREAM)); \
3038 output_addr_const ((STREAM), XVECEXP ((X), 0, 0)); \
3039 break; \
3040 case UNSPEC_PIC: \
3041 /* GLOBAL_OFFSET_TABLE or local symbols, no suffix. */ \
3042 output_addr_const ((STREAM), XVECEXP ((X), 0, 0)); \
3043 break; \
3044 case UNSPEC_GOT: \
3045 output_addr_const ((STREAM), XVECEXP ((X), 0, 0)); \
3046 fputs ("@GOT", (STREAM)); \
3047 break; \
3048 case UNSPEC_GOTOFF: \
3049 output_addr_const ((STREAM), XVECEXP ((X), 0, 0)); \
3050 fputs ("@GOTOFF", (STREAM)); \
3051 break; \
3052 case UNSPEC_PLT: \
3053 output_addr_const ((STREAM), XVECEXP ((X), 0, 0)); \
3054 fputs ("@PLT", (STREAM)); \
3055 break; \
3056 case UNSPEC_GOTPLT: \
3057 output_addr_const ((STREAM), XVECEXP ((X), 0, 0)); \
3058 fputs ("@GOTPLT", (STREAM)); \
3059 break; \
3060 case UNSPEC_CALLER: \
3062 char name[32]; \
3063 /* LPCS stands for Label for PIC Call Site. */ \
3064 ASM_GENERATE_INTERNAL_LABEL \
3065 (name, "LPCS", INTVAL (XVECEXP ((X), 0, 0))); \
3066 assemble_name ((STREAM), name); \
3068 break; \
3069 default: \
3070 goto FAIL; \
3072 break; \
3074 else \
3075 goto FAIL; \
3076 while (0)
3079 extern struct rtx_def *sh_compare_op0;
3080 extern struct rtx_def *sh_compare_op1;
3082 /* Which processor to schedule for. The elements of the enumeration must
3083 match exactly the cpu attribute in the sh.md file. */
3085 enum processor_type {
3086 PROCESSOR_SH1,
3087 PROCESSOR_SH2,
3088 PROCESSOR_SH2E,
3089 PROCESSOR_SH3,
3090 PROCESSOR_SH3E,
3091 PROCESSOR_SH4,
3092 PROCESSOR_SH5
3095 #define sh_cpu_attr ((enum attr_cpu)sh_cpu)
3096 extern enum processor_type sh_cpu;
3098 extern int optimize; /* needed for gen_casesi. */
3100 enum mdep_reorg_phase_e
3102 SH_BEFORE_MDEP_REORG,
3103 SH_INSERT_USES_LABELS,
3104 SH_SHORTEN_BRANCHES0,
3105 SH_FIXUP_PCLOAD,
3106 SH_SHORTEN_BRANCHES1,
3107 SH_AFTER_MDEP_REORG
3110 extern enum mdep_reorg_phase_e mdep_reorg_phase;
3112 #define MACHINE_DEPENDENT_REORG(X) machine_dependent_reorg(X)
3114 /* Generate calls to memcpy, memcmp and memset. */
3116 #define TARGET_MEM_FUNCTIONS
3118 /* Handle Hitachi compiler's pragmas. */
3119 #define REGISTER_TARGET_PRAGMAS() do { \
3120 c_register_pragma (0, "interrupt", sh_pr_interrupt); \
3121 c_register_pragma (0, "trapa", sh_pr_trapa); \
3122 c_register_pragma (0, "nosave_low_regs", sh_pr_nosave_low_regs); \
3123 } while (0)
3125 /* Set when processing a function with pragma interrupt turned on. */
3127 extern int pragma_interrupt;
3129 /* Set when processing a function with interrupt attribute. */
3131 extern int current_function_interrupt;
3133 /* Set to an RTX containing the address of the stack to switch to
3134 for interrupt functions. */
3135 extern struct rtx_def *sp_switch;
3137 extern int rtx_equal_function_value_matters;
3140 /* Instructions with unfilled delay slots take up an
3141 extra two bytes for the nop in the delay slot.
3142 sh-dsp parallel processing insns are four bytes long. */
3144 #define ADJUST_INSN_LENGTH(X, LENGTH) \
3145 (LENGTH) += sh_insn_length_adjustment (X);
3147 /* Define the codes that are matched by predicates in sh.c. */
3148 #define PREDICATE_CODES \
3149 {"and_operand", {SUBREG, REG, CONST_INT}}, \
3150 {"any_register_operand", {SUBREG, REG}}, \
3151 {"arith_operand", {SUBREG, REG, CONST_INT}}, \
3152 {"arith_reg_dest", {SUBREG, REG}}, \
3153 {"arith_reg_operand", {SUBREG, REG}}, \
3154 {"arith_reg_or_0_operand", {SUBREG, REG, CONST_INT, CONST_VECTOR}}, \
3155 {"binary_float_operator", {PLUS, MINUS, MULT, DIV}}, \
3156 {"binary_logical_operator", {AND, IOR, XOR}}, \
3157 {"commutative_float_operator", {PLUS, MULT}}, \
3158 {"equality_comparison_operator", {EQ,NE}}, \
3159 {"extend_reg_operand", {SUBREG, REG, TRUNCATE}}, \
3160 {"extend_reg_or_0_operand", {SUBREG, REG, TRUNCATE, CONST_INT}}, \
3161 {"fp_arith_reg_operand", {SUBREG, REG}}, \
3162 {"fpscr_operand", {REG}}, \
3163 {"fpul_operand", {REG}}, \
3164 {"general_extend_operand", {SUBREG, REG, MEM, TRUNCATE}}, \
3165 {"general_movsrc_operand", {SUBREG, REG, CONST_INT, CONST_DOUBLE, MEM}}, \
3166 {"general_movdst_operand", {SUBREG, REG, MEM}}, \
3167 {"greater_comparison_operator", {GT,GE,GTU,GEU}}, \
3168 {"int_gpr_dest", {SUBREG, REG}}, \
3169 {"inqhi_operand", {TRUNCATE}}, \
3170 {"less_comparison_operator", {LT,LE,LTU,LEU}}, \
3171 {"logical_operand", {SUBREG, REG, CONST_INT}}, \
3172 {"mextr_bit_offset", {CONST_INT}}, \
3173 {"noncommutative_float_operator", {MINUS, DIV}}, \
3174 {"shmedia_6bit_operand", {SUBREG, REG, CONST_INT}}, \
3175 {"sh_register_operand", {REG, SUBREG, CONST_INT}}, \
3176 {"target_reg_operand", {SUBREG, REG}}, \
3177 {"target_operand", {SUBREG, REG, LABEL_REF, SYMBOL_REF, CONST, UNSPEC}},\
3178 {"trunc_hi_operand", {SUBREG, REG, TRUNCATE}}, \
3179 {"register_operand", {SUBREG, REG}}, \
3180 {"sh_const_vec", {CONST_VECTOR}}, \
3181 {"sh_1el_vec", {CONST_VECTOR, PARALLEL}}, \
3182 {"sh_rep_vec", {CONST_VECTOR, PARALLEL}}, \
3183 {"symbol_ref_operand", {SYMBOL_REF}}, \
3184 {"unary_float_operator", {ABS, NEG, SQRT}}, \
3186 #define SPECIAL_MODE_PREDICATES \
3187 "any_register_operand", \
3188 "int_gpr_dest", \
3189 "trunc_hi_operand", \
3190 /* This line intentionally left blank. */
3192 #define any_register_operand register_operand
3194 /* Define this macro if it is advisable to hold scalars in registers
3195 in a wider mode than that declared by the program. In such cases,
3196 the value is constrained to be within the bounds of the declared
3197 type, but kept valid in the wider mode. The signedness of the
3198 extension may differ from that of the type.
3200 Leaving the unsignedp unchanged gives better code than always setting it
3201 to 0. This is despite the fact that we have only signed char and short
3202 load instructions. */
3203 #define PROMOTE_MODE(MODE, UNSIGNEDP, TYPE) \
3204 if (GET_MODE_CLASS (MODE) == MODE_INT \
3205 && GET_MODE_SIZE (MODE) < UNITS_PER_WORD) \
3206 (UNSIGNEDP) = ((MODE) == SImode ? 0 : (UNSIGNEDP)), \
3207 (MODE) = (TARGET_SH1 ? SImode : DImode);
3209 /* Defining PROMOTE_FUNCTION_ARGS eliminates some unnecessary zero/sign
3210 extensions applied to char/short functions arguments. Defining
3211 PROMOTE_FUNCTION_RETURN does the same for function returns. */
3213 #define PROMOTE_FUNCTION_ARGS
3214 #define PROMOTE_FUNCTION_RETURN
3216 #define MAX_FIXED_MODE_SIZE (TARGET_SH5 ? 128 : 64)
3218 /* ??? Define ACCUMULATE_OUTGOING_ARGS? This is more efficient than pushing
3219 and poping arguments. However, we do have push/pop instructions, and
3220 rather limited offsets (4 bits) in load/store instructions, so it isn't
3221 clear if this would give better code. If implemented, should check for
3222 compatibility problems. */
3224 #define SH_DYNAMIC_SHIFT_COST \
3225 (TARGET_HARD_SH4 ? 1 : TARGET_SH3 ? (TARGET_SMALLCODE ? 1 : 2) : 20)
3228 #define NUM_MODES_FOR_MODE_SWITCHING { FP_MODE_NONE }
3230 #define OPTIMIZE_MODE_SWITCHING(ENTITY) TARGET_SH4
3232 #define NORMAL_MODE(ENTITY) \
3233 (sh_cfun_interrupt_handler_p () ? FP_MODE_NONE \
3234 : TARGET_FPU_SINGLE ? FP_MODE_SINGLE \
3235 : FP_MODE_DOUBLE)
3237 #define EPILOGUE_USES(REGNO) ((TARGET_SH2E || TARGET_SH4) \
3238 && (REGNO) == FPSCR_REG)
3240 #define MODE_NEEDED(ENTITY, INSN) \
3241 (recog_memoized (INSN) >= 0 \
3242 ? get_attr_fp_mode (INSN) \
3243 : FP_MODE_NONE)
3245 #define MODE_PRIORITY_TO_MODE(ENTITY, N) \
3246 ((TARGET_FPU_SINGLE != 0) ^ (N) ? FP_MODE_SINGLE : FP_MODE_DOUBLE)
3248 #define EMIT_MODE_SET(ENTITY, MODE, HARD_REGS_LIVE) \
3249 fpscr_set_from_mem ((MODE), (HARD_REGS_LIVE))
3251 #define MD_CAN_REDIRECT_BRANCH(INSN, SEQ) \
3252 sh_can_redirect_branch ((INSN), (SEQ))
3254 #define DWARF_FRAME_RETURN_COLUMN \
3255 (TARGET_SH5 ? DWARF_FRAME_REGNUM (PR_MEDIA_REG) : DWARF_FRAME_REGNUM (PR_REG))
3257 #define EH_RETURN_DATA_REGNO(N) \
3258 ((N) < 4 ? (N) + (TARGET_SH5 ? 2 : 4) : INVALID_REGNUM)
3260 #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM)
3262 #if (defined CRT_BEGIN || defined CRT_END) && ! __SHMEDIA__
3263 /* SH constant pool breaks the devices in crtstuff.c to control section
3264 in where code resides. We have to write it as asm code. */
3265 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
3266 asm (SECTION_OP "\n\
3267 mov.l 1f,r1\n\
3268 mova 2f,r0\n\
3269 braf r1\n\
3270 lds r0,pr\n\
3271 0: .p2align 2\n\
3272 1: .long " USER_LABEL_PREFIX #FUNC " - 0b\n\
3273 2:\n" TEXT_SECTION_ASM_OP);
3274 #endif /* (defined CRT_BEGIN || defined CRT_END) && ! __SHMEDIA__ */
3276 #define ALLOCATE_INITIAL_VALUE(hard_reg) \
3277 (REGNO (hard_reg) == (TARGET_SH5 ? PR_MEDIA_REG : PR_REG) \
3278 ? (current_function_is_leaf && ! sh_pr_n_sets () \
3279 ? (hard_reg) \
3280 : gen_rtx_MEM (Pmode, TARGET_SH5 \
3281 ? (plus_constant (arg_pointer_rtx, \
3282 TARGET_SHMEDIA64 ? -8 : -4)) \
3283 : frame_pointer_rtx)) \
3284 : NULL_RTX)
3286 #endif /* ! GCC_SH_H */