OSDN Git Service

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