OSDN Git Service

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