OSDN Git Service

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