OSDN Git Service

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