OSDN Git Service

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