OSDN Git Service

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