OSDN Git Service

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