OSDN Git Service

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