OSDN Git Service

* hooks.h (hook_bool_const_int_const_int_true): Declare.
[pf3gnuchains/gcc-fork.git] / gcc / config / s390 / s390.h
1 /* Definitions of target machine for GNU compiler, for IBM S/390
2    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3    2007, 2008, 2009 Free Software Foundation, Inc.
4    Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5                   Ulrich Weigand (uweigand@de.ibm.com).
6                   Andreas Krebbel (Andreas.Krebbel@de.ibm.com)
7
8 This file is part of GCC.
9
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
13 version.
14
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18 for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3.  If not see
22 <http://www.gnu.org/licenses/>.  */
23
24 #ifndef _S390_H
25 #define _S390_H
26
27 /* Override the __fixdfdi etc. routines when building libgcc2.
28    ??? This should be done in a cleaner way ...  */
29 #if defined (IN_LIBGCC2) && !defined (__s390x__)
30 #include <config/s390/fixdfdi.h>
31 #endif
32
33 /* Which processor to generate code or schedule for. The cpu attribute
34    defines a list that mirrors this list, so changes to s390.md must be
35    made at the same time.  */
36
37 enum processor_type
38 {
39   PROCESSOR_9672_G5,
40   PROCESSOR_9672_G6,
41   PROCESSOR_2064_Z900,
42   PROCESSOR_2084_Z990,
43   PROCESSOR_2094_Z9_109,
44   PROCESSOR_2097_Z10,
45   PROCESSOR_max
46 };
47
48 /* Optional architectural facilities supported by the processor.  */
49
50 enum processor_flags
51 {
52   PF_IEEE_FLOAT = 1,
53   PF_ZARCH = 2,
54   PF_LONG_DISPLACEMENT = 4,
55   PF_EXTIMM = 8,
56   PF_DFP = 16,
57   PF_Z10 = 32
58 };
59
60 extern enum processor_type s390_tune;
61 extern int s390_tune_flags;
62
63 /* This is necessary to avoid a warning about comparing different enum
64    types.  */
65 #define s390_tune_attr ((enum attr_cpu)s390_tune)
66
67 extern enum processor_type s390_arch;
68 extern int s390_arch_flags;
69
70 /* These flags indicate that the generated code should run on a cpu
71    providing the respective hardware facility regardless of the
72    current cpu mode (ESA or z/Architecture).  */
73
74 #define TARGET_CPU_IEEE_FLOAT \
75         (s390_arch_flags & PF_IEEE_FLOAT)
76 #define TARGET_CPU_ZARCH \
77         (s390_arch_flags & PF_ZARCH)
78 #define TARGET_CPU_LONG_DISPLACEMENT \
79         (s390_arch_flags & PF_LONG_DISPLACEMENT)
80 #define TARGET_CPU_EXTIMM \
81         (s390_arch_flags & PF_EXTIMM)
82 #define TARGET_CPU_DFP \
83         (s390_arch_flags & PF_DFP)
84 #define TARGET_CPU_Z10 \
85         (s390_arch_flags & PF_Z10)
86
87 /* These flags indicate that the generated code should run on a cpu
88    providing the respective hardware facility when run in
89    z/Architecture mode.  */
90
91 #define TARGET_LONG_DISPLACEMENT \
92        (TARGET_ZARCH && TARGET_CPU_LONG_DISPLACEMENT)
93 #define TARGET_EXTIMM \
94        (TARGET_ZARCH && TARGET_CPU_EXTIMM)
95 #define TARGET_DFP \
96        (TARGET_ZARCH && TARGET_CPU_DFP && TARGET_HARD_FLOAT)
97 #define TARGET_Z10 \
98        (TARGET_ZARCH && TARGET_CPU_Z10)
99
100 /* Run-time target specification.  */
101
102 /* Defaults for option flags defined only on some subtargets.  */
103 #ifndef TARGET_TPF_PROFILING
104 #define TARGET_TPF_PROFILING 0
105 #endif
106
107 /* This will be overridden by OS headers.  */
108 #define TARGET_TPF 0
109
110 /* Target CPU builtins.  */
111 #define TARGET_CPU_CPP_BUILTINS()                       \
112   do                                                    \
113     {                                                   \
114       builtin_assert ("cpu=s390");                      \
115       builtin_assert ("machine=s390");                  \
116       builtin_define ("__s390__");                      \
117       if (TARGET_64BIT)                                 \
118         builtin_define ("__s390x__");                   \
119       if (TARGET_LONG_DOUBLE_128)                       \
120         builtin_define ("__LONG_DOUBLE_128__");         \
121     }                                                   \
122   while (0)
123
124 #ifdef DEFAULT_TARGET_64BIT
125 #define TARGET_DEFAULT             (MASK_64BIT | MASK_ZARCH | MASK_HARD_DFP)
126 #else
127 #define TARGET_DEFAULT             0
128 #endif
129
130 /* Support for configure-time defaults.  */
131 #define OPTION_DEFAULT_SPECS                                    \
132   { "mode", "%{!mesa:%{!mzarch:-m%(VALUE)}}" },                 \
133   { "arch", "%{!march=*:-march=%(VALUE)}" },                    \
134   { "tune", "%{!mtune=*:-mtune=%(VALUE)}" }
135
136 /* Defaulting rules.  */
137 #ifdef DEFAULT_TARGET_64BIT
138 #define DRIVER_SELF_SPECS                                       \
139   "%{!m31:%{!m64:-m64}}",                                       \
140   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",             \
141   "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
142 #else
143 #define DRIVER_SELF_SPECS                                       \
144   "%{!m31:%{!m64:-m31}}",                                       \
145   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",             \
146   "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
147 #endif
148
149 /* Target version string.  Overridden by the OS header.  */
150 #ifdef DEFAULT_TARGET_64BIT
151 #define TARGET_VERSION fprintf (stderr, " (zSeries)");
152 #else
153 #define TARGET_VERSION fprintf (stderr, " (S/390)");
154 #endif
155
156 /* Hooks to override options.  */
157 #define OPTIMIZATION_OPTIONS(LEVEL, SIZE) optimization_options(LEVEL, SIZE)
158 #define OVERRIDE_OPTIONS override_options ()
159
160 /* Frame pointer is not used for debugging.  */
161 #define CAN_DEBUG_WITHOUT_FP
162
163 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
164 #define S390_TDC_POSITIVE_ZERO                     (1 << 11)
165 #define S390_TDC_NEGATIVE_ZERO                     (1 << 10)
166 #define S390_TDC_POSITIVE_NORMALIZED_BFP_NUMBER    (1 << 9)
167 #define S390_TDC_NEGATIVE_NORMALIZED_BFP_NUMBER    (1 << 8)
168 #define S390_TDC_POSITIVE_DENORMALIZED_BFP_NUMBER  (1 << 7)
169 #define S390_TDC_NEGATIVE_DENORMALIZED_BFP_NUMBER  (1 << 6)
170 #define S390_TDC_POSITIVE_INFINITY                 (1 << 5)
171 #define S390_TDC_NEGATIVE_INFINITY                 (1 << 4)
172 #define S390_TDC_POSITIVE_QUIET_NAN                (1 << 3)
173 #define S390_TDC_NEGATIVE_QUIET_NAN                (1 << 2)
174 #define S390_TDC_POSITIVE_SIGNALING_NAN            (1 << 1)
175 #define S390_TDC_NEGATIVE_SIGNALING_NAN            (1 << 0)
176
177 /* The following values are different for DFP.  */
178 #define S390_TDC_POSITIVE_DENORMALIZED_DFP_NUMBER (1 << 9)
179 #define S390_TDC_NEGATIVE_DENORMALIZED_DFP_NUMBER (1 << 8)
180 #define S390_TDC_POSITIVE_NORMALIZED_DFP_NUMBER   (1 << 7)
181 #define S390_TDC_NEGATIVE_NORMALIZED_DFP_NUMBER   (1 << 6)
182
183 /* For signbit, the BFP-DFP-difference makes no difference. */
184 #define S390_TDC_SIGNBIT_SET (S390_TDC_NEGATIVE_ZERO \
185                           | S390_TDC_NEGATIVE_NORMALIZED_BFP_NUMBER \
186                           | S390_TDC_NEGATIVE_DENORMALIZED_BFP_NUMBER\
187                           | S390_TDC_NEGATIVE_INFINITY \
188                           | S390_TDC_NEGATIVE_QUIET_NAN \
189                           | S390_TDC_NEGATIVE_SIGNALING_NAN )
190
191 #define S390_TDC_INFINITY (S390_TDC_POSITIVE_INFINITY \
192                           | S390_TDC_NEGATIVE_INFINITY )
193
194 /* In libgcc2, determine target settings as compile-time constants.  */
195 #ifdef IN_LIBGCC2
196 #undef TARGET_64BIT
197 #ifdef __s390x__
198 #define TARGET_64BIT 1
199 #else
200 #define TARGET_64BIT 0
201 #endif
202 #endif
203
204
205 /* Target machine storage layout.  */
206
207 /* Everything is big-endian.  */
208 #define BITS_BIG_ENDIAN 1
209 #define BYTES_BIG_ENDIAN 1
210 #define WORDS_BIG_ENDIAN 1
211
212 /* Width of a word, in units (bytes).  */
213 #define UNITS_PER_WORD (TARGET_64BIT ? 8 : 4)
214 #ifndef IN_LIBGCC2
215 #define MIN_UNITS_PER_WORD 4
216 #endif
217 #define MAX_BITS_PER_WORD 64
218
219 /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
220 #define PARM_BOUNDARY (TARGET_64BIT ? 64 : 32)
221
222 /* Boundary (in *bits*) on which stack pointer should be aligned.  */
223 #define STACK_BOUNDARY 64
224
225 /* Allocation boundary (in *bits*) for the code of a function.  */
226 #define FUNCTION_BOUNDARY 32
227
228 /* There is no point aligning anything to a rounder boundary than this.  */
229 #define BIGGEST_ALIGNMENT 64
230
231 /* Alignment of field after `int : 0' in a structure.  */
232 #define EMPTY_FIELD_BOUNDARY 32
233
234 /* Alignment on even addresses for LARL instruction.  */
235 #define CONSTANT_ALIGNMENT(EXP, ALIGN) (ALIGN) < 16 ? 16 : (ALIGN)
236 #define DATA_ALIGNMENT(TYPE, ALIGN) (ALIGN) < 16 ? 16 : (ALIGN)
237
238 /* Alignment is not required by the hardware.  */
239 #define STRICT_ALIGNMENT 0
240
241 /* Mode of stack savearea.
242    FUNCTION is VOIDmode because calling convention maintains SP.
243    BLOCK needs Pmode for SP.
244    NONLOCAL needs twice Pmode to maintain both backchain and SP.  */
245 #define STACK_SAVEAREA_MODE(LEVEL)      \
246   (LEVEL == SAVE_FUNCTION ? VOIDmode    \
247   : LEVEL == SAVE_NONLOCAL ? (TARGET_64BIT ? OImode : TImode) : Pmode)
248
249
250 /* Type layout.  */
251
252 /* Sizes in bits of the source language data types.  */
253 #define SHORT_TYPE_SIZE 16
254 #define INT_TYPE_SIZE 32
255 #define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32)
256 #define LONG_LONG_TYPE_SIZE 64
257 #define FLOAT_TYPE_SIZE 32
258 #define DOUBLE_TYPE_SIZE 64
259 #define LONG_DOUBLE_TYPE_SIZE (TARGET_LONG_DOUBLE_128 ? 128 : 64)
260
261 /* Define this to set long double type size to use in libgcc2.c, which can
262    not depend on target_flags.  */
263 #ifdef __LONG_DOUBLE_128__
264 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE 128
265 #else
266 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE 64
267 #endif
268
269 /* Work around target_flags dependency in ada/targtyps.c.  */
270 #define WIDEST_HARDWARE_FP_SIZE 64
271
272 /* We use "unsigned char" as default.  */
273 #define DEFAULT_SIGNED_CHAR 0
274
275
276 /* Register usage.  */
277
278 /* We have 16 general purpose registers (registers 0-15),
279    and 16 floating point registers (registers 16-31).
280    (On non-IEEE machines, we have only 4 fp registers.)
281
282    Amongst the general purpose registers, some are used
283    for specific purposes:
284    GPR 11: Hard frame pointer (if needed)
285    GPR 12: Global offset table pointer (if needed)
286    GPR 13: Literal pool base register
287    GPR 14: Return address register
288    GPR 15: Stack pointer
289
290    Registers 32-35 are 'fake' hard registers that do not
291    correspond to actual hardware:
292    Reg 32: Argument pointer
293    Reg 33: Condition code
294    Reg 34: Frame pointer
295    Reg 35: Return address pointer
296
297    Registers 36 and 37 are mapped to access registers
298    0 and 1, used to implement thread-local storage.  */
299
300 #define FIRST_PSEUDO_REGISTER 38
301
302 /* Standard register usage.  */
303 #define GENERAL_REGNO_P(N)      ((int)(N) >= 0 && (N) < 16)
304 #define ADDR_REGNO_P(N)         ((N) >= 1 && (N) < 16)
305 #define FP_REGNO_P(N)           ((N) >= 16 && (N) < 32)
306 #define CC_REGNO_P(N)           ((N) == 33)
307 #define FRAME_REGNO_P(N)        ((N) == 32 || (N) == 34 || (N) == 35)
308 #define ACCESS_REGNO_P(N)       ((N) == 36 || (N) == 37)
309
310 #define GENERAL_REG_P(X)        (REG_P (X) && GENERAL_REGNO_P (REGNO (X)))
311 #define ADDR_REG_P(X)           (REG_P (X) && ADDR_REGNO_P (REGNO (X)))
312 #define FP_REG_P(X)             (REG_P (X) && FP_REGNO_P (REGNO (X)))
313 #define CC_REG_P(X)             (REG_P (X) && CC_REGNO_P (REGNO (X)))
314 #define FRAME_REG_P(X)          (REG_P (X) && FRAME_REGNO_P (REGNO (X)))
315 #define ACCESS_REG_P(X)         (REG_P (X) && ACCESS_REGNO_P (REGNO (X)))
316
317 /* Set up fixed registers and calling convention:
318
319    GPRs 0-5 are always call-clobbered,
320    GPRs 6-15 are always call-saved.
321    GPR 12 is fixed if used as GOT pointer.
322    GPR 13 is always fixed (as literal pool pointer).
323    GPR 14 is always fixed on S/390 machines (as return address).
324    GPR 15 is always fixed (as stack pointer).
325    The 'fake' hard registers are call-clobbered and fixed.
326    The access registers are call-saved and fixed.
327
328    On 31-bit, FPRs 18-19 are call-clobbered;
329    on 64-bit, FPRs 24-31 are call-clobbered.
330    The remaining FPRs are call-saved.  */
331
332 #define FIXED_REGISTERS                         \
333 { 0, 0, 0, 0,                                   \
334   0, 0, 0, 0,                                   \
335   0, 0, 0, 0,                                   \
336   0, 1, 1, 1,                                   \
337   0, 0, 0, 0,                                   \
338   0, 0, 0, 0,                                   \
339   0, 0, 0, 0,                                   \
340   0, 0, 0, 0,                                   \
341   1, 1, 1, 1,                                   \
342   1, 1 }
343
344 #define CALL_USED_REGISTERS                     \
345 { 1, 1, 1, 1,                                   \
346   1, 1, 0, 0,                                   \
347   0, 0, 0, 0,                                   \
348   0, 1, 1, 1,                                   \
349   1, 1, 1, 1,                                   \
350   1, 1, 1, 1,                                   \
351   1, 1, 1, 1,                                   \
352   1, 1, 1, 1,                                   \
353   1, 1, 1, 1,                                   \
354   1, 1 }
355
356 #define CALL_REALLY_USED_REGISTERS              \
357 { 1, 1, 1, 1,                                   \
358   1, 1, 0, 0,                                   \
359   0, 0, 0, 0,                                   \
360   0, 0, 0, 0,                                   \
361   1, 1, 1, 1,                                   \
362   1, 1, 1, 1,                                   \
363   1, 1, 1, 1,                                   \
364   1, 1, 1, 1,                                   \
365   1, 1, 1, 1,                                   \
366   0, 0 }
367
368 #define CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage ()
369
370 /* Preferred register allocation order.  */
371 #define REG_ALLOC_ORDER                                         \
372 {  1, 2, 3, 4, 5, 0, 12, 11, 10, 9, 8, 7, 6, 14, 13,            \
373    16, 17, 18, 19, 20, 21, 22, 23,                              \
374    24, 25, 26, 27, 28, 29, 30, 31,                              \
375    15, 32, 33, 34, 35, 36, 37 }
376
377
378 /* Fitting values into registers.  */
379
380 /* Integer modes <= word size fit into any GPR.
381    Integer modes > word size fit into successive GPRs, starting with
382    an even-numbered register.
383    SImode and DImode fit into FPRs as well.
384
385    Floating point modes <= word size fit into any FPR or GPR.
386    Floating point modes > word size (i.e. DFmode on 32-bit) fit
387    into any FPR, or an even-odd GPR pair.
388    TFmode fits only into an even-odd FPR pair.
389
390    Complex floating point modes fit either into two FPRs, or into
391    successive GPRs (again starting with an even number).
392    TCmode fits only into two successive even-odd FPR pairs.
393
394    Condition code modes fit only into the CC register.  */
395
396 /* Because all registers in a class have the same size HARD_REGNO_NREGS
397    is equivalent to CLASS_MAX_NREGS.  */
398 #define HARD_REGNO_NREGS(REGNO, MODE)                           \
399   s390_class_max_nregs (REGNO_REG_CLASS (REGNO), (MODE))
400
401 #define HARD_REGNO_MODE_OK(REGNO, MODE)         \
402   s390_hard_regno_mode_ok ((REGNO), (MODE))
403
404 #define HARD_REGNO_RENAME_OK(FROM, TO)          \
405   s390_hard_regno_rename_ok (FROM, TO)
406
407 #define MODES_TIEABLE_P(MODE1, MODE2)           \
408    (((MODE1) == SFmode || (MODE1) == DFmode)    \
409    == ((MODE2) == SFmode || (MODE2) == DFmode))
410
411 /* Maximum number of registers to represent a value of mode MODE
412    in a register of class CLASS.  */
413 #define CLASS_MAX_NREGS(CLASS, MODE)                                    \
414   s390_class_max_nregs ((CLASS), (MODE))
415
416 /* If a 4-byte value is loaded into a FPR, it is placed into the
417    *upper* half of the register, not the lower.  Therefore, we
418    cannot use SUBREGs to switch between modes in FP registers.
419    Likewise for access registers, since they have only half the
420    word size on 64-bit.  */
421 #define CANNOT_CHANGE_MODE_CLASS(FROM, TO, CLASS)                       \
422   (GET_MODE_SIZE (FROM) != GET_MODE_SIZE (TO)                           \
423    ? ((reg_classes_intersect_p (FP_REGS, CLASS)                         \
424        && (GET_MODE_SIZE (FROM) < 8 || GET_MODE_SIZE (TO) < 8))         \
425       || reg_classes_intersect_p (ACCESS_REGS, CLASS)) : 0)
426
427 /* Register classes.  */
428
429 /* We use the following register classes:
430    GENERAL_REGS     All general purpose registers
431    ADDR_REGS        All general purpose registers except %r0
432                     (These registers can be used in address generation)
433    FP_REGS          All floating point registers
434    CC_REGS          The condition code register
435    ACCESS_REGS      The access registers
436
437    GENERAL_FP_REGS  Union of GENERAL_REGS and FP_REGS
438    ADDR_FP_REGS     Union of ADDR_REGS and FP_REGS
439    GENERAL_CC_REGS  Union of GENERAL_REGS and CC_REGS
440    ADDR_CC_REGS     Union of ADDR_REGS and CC_REGS
441
442    NO_REGS          No registers
443    ALL_REGS         All registers
444
445    Note that the 'fake' frame pointer and argument pointer registers
446    are included amongst the address registers here.  */
447
448 enum reg_class
449 {
450   NO_REGS, CC_REGS, ADDR_REGS, GENERAL_REGS, ACCESS_REGS,
451   ADDR_CC_REGS, GENERAL_CC_REGS,
452   FP_REGS, ADDR_FP_REGS, GENERAL_FP_REGS,
453   ALL_REGS, LIM_REG_CLASSES
454 };
455 #define N_REG_CLASSES (int) LIM_REG_CLASSES
456
457 #define REG_CLASS_NAMES                                                 \
458 { "NO_REGS", "CC_REGS", "ADDR_REGS", "GENERAL_REGS", "ACCESS_REGS",     \
459   "ADDR_CC_REGS", "GENERAL_CC_REGS",                                    \
460   "FP_REGS", "ADDR_FP_REGS", "GENERAL_FP_REGS", "ALL_REGS" }
461
462 /* Class -> register mapping.  */
463 #define REG_CLASS_CONTENTS \
464 {                                                       \
465   { 0x00000000, 0x00000000 },   /* NO_REGS */           \
466   { 0x00000000, 0x00000002 },   /* CC_REGS */           \
467   { 0x0000fffe, 0x0000000d },   /* ADDR_REGS */         \
468   { 0x0000ffff, 0x0000000d },   /* GENERAL_REGS */      \
469   { 0x00000000, 0x00000030 },   /* ACCESS_REGS */       \
470   { 0x0000fffe, 0x0000000f },   /* ADDR_CC_REGS */      \
471   { 0x0000ffff, 0x0000000f },   /* GENERAL_CC_REGS */   \
472   { 0xffff0000, 0x00000000 },   /* FP_REGS */           \
473   { 0xfffffffe, 0x0000000d },   /* ADDR_FP_REGS */      \
474   { 0xffffffff, 0x0000000d },   /* GENERAL_FP_REGS */   \
475   { 0xffffffff, 0x0000003f },   /* ALL_REGS */          \
476 }
477
478 /* The following macro defines cover classes for Integrated Register
479    Allocator.  Cover classes is a set of non-intersected register
480    classes covering all hard registers used for register allocation
481    purpose.  Any move between two registers of a cover class should be
482    cheaper than load or store of the registers.  The macro value is
483    array of register classes with LIM_REG_CLASSES used as the end
484    marker.  */
485
486 #define IRA_COVER_CLASSES                                                    \
487 {                                                                            \
488   GENERAL_REGS, FP_REGS, CC_REGS, ACCESS_REGS, LIM_REG_CLASSES               \
489 }
490
491 /* In some case register allocation order is not enough for IRA to
492    generate a good code.  The following macro (if defined) increases
493    cost of REGNO for a pseudo approximately by pseudo usage frequency
494    multiplied by the macro value.
495
496    We avoid usage of BASE_REGNUM by nonzero macro value because the
497    reload can decide not to use the hard register because some
498    constant was forced to be in memory.  */
499 #define IRA_HARD_REGNO_ADD_COST_MULTIPLIER(regno)       \
500   (regno == BASE_REGNUM ? 0.0 : 0.5)
501
502 /* Register -> class mapping.  */
503 extern const enum reg_class regclass_map[FIRST_PSEUDO_REGISTER];
504 #define REGNO_REG_CLASS(REGNO) (regclass_map[REGNO])
505
506 /* ADDR_REGS can be used as base or index register.  */
507 #define INDEX_REG_CLASS ADDR_REGS
508 #define BASE_REG_CLASS ADDR_REGS
509
510 /* Check whether REGNO is a hard register of the suitable class
511    or a pseudo register currently allocated to one such.  */
512 #define REGNO_OK_FOR_INDEX_P(REGNO)                                     \
513     (((REGNO) < FIRST_PSEUDO_REGISTER                                   \
514       && REGNO_REG_CLASS ((REGNO)) == ADDR_REGS)                        \
515      || ADDR_REGNO_P (reg_renumber[REGNO]))
516 #define REGNO_OK_FOR_BASE_P(REGNO) REGNO_OK_FOR_INDEX_P (REGNO)
517
518
519 /* Given an rtx X being reloaded into a reg required to be in class CLASS,
520    return the class of reg to actually use.  */
521 #define PREFERRED_RELOAD_CLASS(X, CLASS)        \
522   s390_preferred_reload_class ((X), (CLASS))
523
524 /* We need secondary memory to move data between GPRs and FPRs.  With
525    DFP the ldgr lgdr instructions are available.  But these
526    instructions do not handle GPR pairs so it is not possible for 31
527    bit.  */
528 #define SECONDARY_MEMORY_NEEDED(CLASS1, CLASS2, MODE) \
529  ((CLASS1) != (CLASS2)                                \
530   && ((CLASS1) == FP_REGS || (CLASS2) == FP_REGS)     \
531   && (!TARGET_DFP || !TARGET_64BIT || GET_MODE_SIZE (MODE) != 8))
532
533 /* Get_secondary_mem widens its argument to BITS_PER_WORD which loses on 64bit
534    because the movsi and movsf patterns don't handle r/f moves.  */
535 #define SECONDARY_MEMORY_NEEDED_MODE(MODE)              \
536  (GET_MODE_BITSIZE (MODE) < 32                          \
537   ? mode_for_size (32, GET_MODE_CLASS (MODE), 0)        \
538   : MODE)
539
540
541 /* Stack layout and calling conventions.  */
542
543 /* Our stack grows from higher to lower addresses.  However, local variables
544    are accessed by positive offsets, and function arguments are stored at
545    increasing addresses.  */
546 #define STACK_GROWS_DOWNWARD
547 #define FRAME_GROWS_DOWNWARD 1
548 /* #undef ARGS_GROW_DOWNWARD */
549
550 /* The basic stack layout looks like this: the stack pointer points
551    to the register save area for called functions.  Above that area
552    is the location to place outgoing arguments.  Above those follow
553    dynamic allocations (alloca), and finally the local variables.  */
554
555 /* Offset from stack-pointer to first location of outgoing args.  */
556 #define STACK_POINTER_OFFSET (TARGET_64BIT ? 160 : 96)
557
558 /* Offset within stack frame to start allocating local variables at.  */
559 #define STARTING_FRAME_OFFSET 0
560
561 /* Offset from the stack pointer register to an item dynamically
562    allocated on the stack, e.g., by `alloca'.  */
563 #define STACK_DYNAMIC_OFFSET(FUNDECL) \
564   (STACK_POINTER_OFFSET + crtl->outgoing_args_size)
565
566 /* Offset of first parameter from the argument pointer register value.
567    We have a fake argument pointer register that points directly to
568    the argument area.  */
569 #define FIRST_PARM_OFFSET(FNDECL) 0
570
571 /* Defining this macro makes __builtin_frame_address(0) and
572    __builtin_return_address(0) work with -fomit-frame-pointer.  */
573 #define INITIAL_FRAME_ADDRESS_RTX                                             \
574   (plus_constant (arg_pointer_rtx, -STACK_POINTER_OFFSET))
575
576 /* The return address of the current frame is retrieved
577    from the initial value of register RETURN_REGNUM.
578    For frames farther back, we use the stack slot where
579    the corresponding RETURN_REGNUM register was saved.  */
580 #define DYNAMIC_CHAIN_ADDRESS(FRAME)                                          \
581   (TARGET_PACKED_STACK ?                                                      \
582    plus_constant ((FRAME), STACK_POINTER_OFFSET - UNITS_PER_WORD) : (FRAME))
583
584 /* For -mpacked-stack this adds 160 - 8 (96 - 4) to the output of
585    builtin_frame_address.  Otherwise arg pointer -
586    STACK_POINTER_OFFSET would be returned for
587    __builtin_frame_address(0) what might result in an address pointing
588    somewhere into the middle of the local variables since the packed
589    stack layout generally does not need all the bytes in the register
590    save area.  */
591 #define FRAME_ADDR_RTX(FRAME)                   \
592   DYNAMIC_CHAIN_ADDRESS ((FRAME))
593
594 #define RETURN_ADDR_RTX(COUNT, FRAME)                                         \
595   s390_return_addr_rtx ((COUNT), DYNAMIC_CHAIN_ADDRESS ((FRAME)))
596
597 /* In 31-bit mode, we need to mask off the high bit of return addresses.  */
598 #define MASK_RETURN_ADDR (TARGET_64BIT ? constm1_rtx : GEN_INT (0x7fffffff))
599
600
601 /* Exception handling.  */
602
603 /* Describe calling conventions for DWARF-2 exception handling.  */
604 #define INCOMING_RETURN_ADDR_RTX  gen_rtx_REG (Pmode, RETURN_REGNUM)
605 #define INCOMING_FRAME_SP_OFFSET STACK_POINTER_OFFSET
606 #define DWARF_FRAME_RETURN_COLUMN  14
607
608 /* Describe how we implement __builtin_eh_return.  */
609 #define EH_RETURN_DATA_REGNO(N) ((N) < 4 ? (N) + 6 : INVALID_REGNUM)
610 #define EH_RETURN_HANDLER_RTX gen_rtx_MEM (Pmode, return_address_pointer_rtx)
611
612 /* Select a format to encode pointers in exception handling data.  */
613 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL)                          \
614   (flag_pic                                                                 \
615     ? ((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4 \
616    : DW_EH_PE_absptr)
617
618
619 /* Frame registers.  */
620
621 #define STACK_POINTER_REGNUM 15
622 #define FRAME_POINTER_REGNUM 34
623 #define HARD_FRAME_POINTER_REGNUM 11
624 #define ARG_POINTER_REGNUM 32
625 #define RETURN_ADDRESS_POINTER_REGNUM 35
626
627 /* The static chain must be call-clobbered, but not used for
628    function argument passing.  As register 1 is clobbered by
629    the trampoline code, we only have one option.  */
630 #define STATIC_CHAIN_REGNUM 0
631
632 /* Number of hardware registers that go into the DWARF-2 unwind info.
633    To avoid ABI incompatibility, this number must not change even as
634    'fake' hard registers are added or removed.  */
635 #define DWARF_FRAME_REGISTERS 34
636
637
638 /* Frame pointer and argument pointer elimination.  */
639
640 #define ELIMINABLE_REGS                                         \
641 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM },                \
642  { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },           \
643  { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM },                  \
644  { ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },             \
645  { RETURN_ADDRESS_POINTER_REGNUM, STACK_POINTER_REGNUM },       \
646  { RETURN_ADDRESS_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },  \
647  { BASE_REGNUM, BASE_REGNUM }}
648
649 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
650   (OFFSET) = s390_initial_elimination_offset ((FROM), (TO))
651
652
653 /* Stack arguments.  */
654
655 /* We need current_function_outgoing_args to be valid.  */
656 #define ACCUMULATE_OUTGOING_ARGS 1
657
658 /* Return doesn't modify the stack.  */
659 #define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, SIZE) 0
660
661
662 /* Register arguments.  */
663
664 typedef struct s390_arg_structure
665 {
666   int gprs;                     /* gpr so far */
667   int fprs;                     /* fpr so far */
668 }
669 CUMULATIVE_ARGS;
670
671 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, NN, N_NAMED_ARGS) \
672   ((CUM).gprs=0, (CUM).fprs=0)
673
674 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)                    \
675   s390_function_arg_advance (&CUM, MODE, TYPE, NAMED)
676
677 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED)   \
678   s390_function_arg (&CUM, MODE, TYPE, NAMED)
679
680 /* Arguments can be placed in general registers 2 to 6, or in floating
681    point registers 0 and 2 for 31 bit and fprs 0, 2, 4 and 6 for 64
682    bit.  */
683 #define FUNCTION_ARG_REGNO_P(N) (((N) >=2 && (N) <7) || \
684   (N) == 16 || (N) == 17 || (TARGET_64BIT && ((N) == 18 || (N) == 19)))
685
686
687 /* Scalar return values.  */
688
689 #define FUNCTION_VALUE(VALTYPE, FUNC) \
690   s390_function_value ((VALTYPE), (FUNC), VOIDmode)
691
692 #define LIBCALL_VALUE(MODE) \
693   s390_function_value (NULL, NULL, (MODE))
694
695 /* Only gpr 2 and fpr 0 are ever used as return registers.  */
696 #define FUNCTION_VALUE_REGNO_P(N) ((N) == 2 || (N) == 16)
697
698
699 /* Function entry and exit.  */
700
701 /* When returning from a function, the stack pointer does not matter.  */
702 #define EXIT_IGNORE_STACK       1
703
704
705 /* Profiling.  */
706
707 #define FUNCTION_PROFILER(FILE, LABELNO)                        \
708   s390_function_profiler ((FILE), ((LABELNO)))
709
710 #define PROFILE_BEFORE_PROLOGUE 1
711
712
713 /* Trampolines for nested functions.  */
714
715 #define TRAMPOLINE_SIZE (TARGET_64BIT ? 32 : 16)
716
717 #define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, CXT)                       \
718    s390_initialize_trampoline ((ADDR), (FNADDR), (CXT))
719
720 #define TRAMPOLINE_TEMPLATE(FILE)                                       \
721    s390_trampoline_template (FILE)
722
723
724 /* Addressing modes, and classification of registers for them.  */
725
726 /* Recognize any constant value that is a valid address.  */
727 #define CONSTANT_ADDRESS_P(X) 0
728
729 /* Maximum number of registers that can appear in a valid memory address.  */
730 #define MAX_REGS_PER_ADDRESS 2
731
732 /* This definition replaces the formerly used 'm' constraint with a
733    different constraint letter in order to avoid changing semantics of
734    the 'm' constraint when accepting new address formats in
735    TARGET_LEGITIMATE_ADDRESS_P.  The constraint letter defined here
736    must not be used in insn definitions or inline assemblies.  */
737 #define TARGET_MEM_CONSTRAINT 'e'
738
739 /* Try a machine-dependent way of reloading an illegitimate address
740    operand.  If we find one, push the reload and jump to WIN.  This
741    macro is used in only one place: `find_reloads_address' in reload.c.  */
742 #define LEGITIMIZE_RELOAD_ADDRESS(AD, MODE, OPNUM, TYPE, IND, WIN)      \
743 do {                                                                    \
744   rtx new_rtx = legitimize_reload_address (AD, MODE, OPNUM, (int)(TYPE));       \
745   if (new_rtx)                                                          \
746     {                                                                   \
747       (AD) = new_rtx;                                                   \
748       goto WIN;                                                         \
749     }                                                                   \
750 } while (0)
751
752 /* Nonzero if the constant value X is a legitimate general operand.
753    It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
754 #define LEGITIMATE_CONSTANT_P(X) \
755      legitimate_constant_p (X)
756
757 /* Helper macro for s390.c and s390.md to check for symbolic constants.  */
758 #define SYMBOLIC_CONST(X)       \
759 (GET_CODE (X) == SYMBOL_REF                                             \
760  || GET_CODE (X) == LABEL_REF                                           \
761  || (GET_CODE (X) == CONST && symbolic_reference_mentioned_p (X)))
762
763 #define TLS_SYMBOLIC_CONST(X)   \
764 ((GET_CODE (X) == SYMBOL_REF && tls_symbolic_operand (X))       \
765  || (GET_CODE (X) == CONST && tls_symbolic_reference_mentioned_p (X)))
766
767
768 /* Condition codes.  */
769
770 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
771    return the mode to be used for the comparison.  */
772 #define SELECT_CC_MODE(OP, X, Y) s390_select_ccmode ((OP), (X), (Y))
773
774 /* Canonicalize a comparison from one we don't have to one we do have.  */
775 #define CANONICALIZE_COMPARISON(CODE, OP0, OP1) \
776   s390_canonicalize_comparison (&(CODE), &(OP0), &(OP1))
777
778 /* Relative costs of operations.  */
779
780 /* On s390, copy between fprs and gprs is expensive.  */
781 #define REGISTER_MOVE_COST(MODE, CLASS1, CLASS2)                        \
782   ((   (   reg_classes_intersect_p ((CLASS1), GENERAL_REGS)             \
783         && reg_classes_intersect_p ((CLASS2), FP_REGS))                 \
784     || (   reg_classes_intersect_p ((CLASS1), FP_REGS)                  \
785         && reg_classes_intersect_p ((CLASS2), GENERAL_REGS))) ? 10 : 1)
786
787 /* A C expression for the cost of moving data of mode M between a
788    register and memory.  A value of 2 is the default; this cost is
789    relative to those in `REGISTER_MOVE_COST'.  */
790 #define MEMORY_MOVE_COST(M, C, I) 1
791
792 /* A C expression for the cost of a branch instruction.  A value of 1
793    is the default; other values are interpreted relative to that.  */
794 #define BRANCH_COST(speed_p, predictable_p) 1
795
796 /* Nonzero if access to memory by bytes is slow and undesirable.  */
797 #define SLOW_BYTE_ACCESS 1
798
799 /* An integer expression for the size in bits of the largest integer machine
800    mode that should actually be used.  We allow pairs of registers.  */
801 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (TARGET_64BIT ? TImode : DImode)
802
803 /* The maximum number of bytes that a single instruction can move quickly
804    between memory and registers or between two memory locations.  */
805 #define MOVE_MAX (TARGET_64BIT ? 16 : 8)
806 #define MOVE_MAX_PIECES (TARGET_64BIT ? 8 : 4)
807 #define MAX_MOVE_MAX 16
808
809 /* Determine whether to use move_by_pieces or block move insn.  */
810 #define MOVE_BY_PIECES_P(SIZE, ALIGN)           \
811   ( (SIZE) == 1 || (SIZE) == 2 || (SIZE) == 4   \
812     || (TARGET_64BIT && (SIZE) == 8) )
813
814 /* Determine whether to use clear_by_pieces or block clear insn.  */
815 #define CLEAR_BY_PIECES_P(SIZE, ALIGN)          \
816   ( (SIZE) == 1 || (SIZE) == 2 || (SIZE) == 4   \
817     || (TARGET_64BIT && (SIZE) == 8) )
818
819 /* This macro is used to determine whether store_by_pieces should be
820    called to "memcpy" storage when the source is a constant string.  */
821 #define STORE_BY_PIECES_P(SIZE, ALIGN) MOVE_BY_PIECES_P (SIZE, ALIGN)
822
823 /* Likewise to decide whether to "memset" storage with byte values
824    other than zero.  */
825 #define SET_BY_PIECES_P(SIZE, ALIGN) STORE_BY_PIECES_P (SIZE, ALIGN)
826
827 /* Don't perform CSE on function addresses.  */
828 #define NO_FUNCTION_CSE
829
830 /* This value is used in tree-sra to decide whether it might benefical
831    to split a struct move into several word-size moves.  For S/390
832    only small values make sense here since struct moves are relatively
833    cheap thanks to mvc so the small default value choosen for archs
834    with memmove patterns should be ok.  But this value is multiplied
835    in tree-sra with UNITS_PER_WORD to make a decision so we adjust it
836    here to compensate for that factor since mvc costs exactly the same
837    on 31 and 64 bit.  */
838 #define MOVE_RATIO(speed) (TARGET_64BIT? 2 : 4)
839
840
841 /* Sections.  */
842
843 /* Output before read-only data.  */
844 #define TEXT_SECTION_ASM_OP ".text"
845
846 /* Output before writable (initialized) data.  */
847 #define DATA_SECTION_ASM_OP ".data"
848
849 /* Output before writable (uninitialized) data.  */
850 #define BSS_SECTION_ASM_OP ".bss"
851
852 /* S/390 constant pool breaks the devices in crtstuff.c to control section
853    in where code resides.  We have to write it as asm code.  */
854 #ifndef __s390x__
855 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
856     asm (SECTION_OP "\n\
857         bras\t%r2,1f\n\
858 0:      .long\t" USER_LABEL_PREFIX #FUNC " - 0b\n\
859 1:      l\t%r3,0(%r2)\n\
860         bas\t%r14,0(%r3,%r2)\n\
861         .previous");
862 #endif
863
864
865 /* Position independent code.  */
866
867 extern int flag_pic;
868
869 #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? 12 : INVALID_REGNUM)
870
871 #define LEGITIMATE_PIC_OPERAND_P(X)  legitimate_pic_operand_p (X)
872
873
874 /* Assembler file format.  */
875
876 /* Character to start a comment.  */
877 #define ASM_COMMENT_START "#"
878
879 /* Declare an uninitialized external linkage data object.  */
880 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
881   asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
882
883 /* Globalizing directive for a label.  */
884 #define GLOBAL_ASM_OP ".globl "
885
886 /* Advance the location counter to a multiple of 2**LOG bytes.  */
887 #define ASM_OUTPUT_ALIGN(FILE, LOG) \
888   if ((LOG)) fprintf ((FILE), "\t.align\t%d\n", 1 << (LOG))
889
890 /* Advance the location counter by SIZE bytes.  */
891 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
892   fprintf ((FILE), "\t.set\t.,.+"HOST_WIDE_INT_PRINT_UNSIGNED"\n", (SIZE))
893
894 /* The LOCAL_LABEL_PREFIX variable is used by dbxelf.h.  */
895 #define LOCAL_LABEL_PREFIX "."
896
897 /* How to refer to registers in assembler output.  This sequence is
898    indexed by compiler's hard-register-number (see above).  */
899 #define REGISTER_NAMES                                                  \
900 { "%r0",  "%r1",  "%r2",  "%r3",  "%r4",  "%r5",  "%r6",  "%r7",        \
901   "%r8",  "%r9",  "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",       \
902   "%f0",  "%f2",  "%f4",  "%f6",  "%f1",  "%f3",  "%f5",  "%f7",        \
903   "%f8",  "%f10", "%f12", "%f14", "%f9",  "%f11", "%f13", "%f15",       \
904   "%ap",  "%cc",  "%fp",  "%rp",  "%a0",  "%a1"                         \
905 }
906
907 /* Print operand X (an rtx) in assembler syntax to file FILE.  */
908 #define PRINT_OPERAND(FILE, X, CODE) print_operand (FILE, X, CODE)
909 #define PRINT_OPERAND_ADDRESS(FILE, ADDR) print_operand_address (FILE, ADDR)
910
911 /* Output machine-dependent UNSPECs in address constants.  */
912 #define OUTPUT_ADDR_CONST_EXTRA(FILE, X, FAIL)          \
913 do {                                                    \
914   if (!s390_output_addr_const_extra (FILE, (X)))        \
915     goto FAIL;                                          \
916 } while (0);
917
918 /* Output an element of a case-vector that is absolute.  */
919 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE)                            \
920 do {                                                                    \
921   char buf[32];                                                         \
922   fputs (integer_asm_op (UNITS_PER_WORD, TRUE), (FILE));                \
923   ASM_GENERATE_INTERNAL_LABEL (buf, "L", (VALUE));                      \
924   assemble_name ((FILE), buf);                                          \
925   fputc ('\n', (FILE));                                                 \
926 } while (0)
927
928 /* Output an element of a case-vector that is relative.  */
929 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)                \
930 do {                                                                    \
931   char buf[32];                                                         \
932   fputs (integer_asm_op (UNITS_PER_WORD, TRUE), (FILE));                \
933   ASM_GENERATE_INTERNAL_LABEL (buf, "L", (VALUE));                      \
934   assemble_name ((FILE), buf);                                          \
935   fputc ('-', (FILE));                                                  \
936   ASM_GENERATE_INTERNAL_LABEL (buf, "L", (REL));                        \
937   assemble_name ((FILE), buf);                                          \
938   fputc ('\n', (FILE));                                                 \
939 } while (0)
940
941
942 /* Miscellaneous parameters.  */
943
944 /* Specify the machine mode that this machine uses for the index in the
945    tablejump instruction.  */
946 #define CASE_VECTOR_MODE (TARGET_64BIT ? DImode : SImode)
947
948 /* Value is 1 if truncating an integer of INPREC bits to OUTPREC bits
949    is done just by pretending it is already truncated.  */
950 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC)  1
951
952 /* Specify the machine mode that pointers have.
953    After generation of rtl, the compiler makes no further distinction
954    between pointers and any other objects of this machine mode.  */
955 #define Pmode ((enum machine_mode) (TARGET_64BIT ? DImode : SImode))
956
957 /* This is -1 for "pointer mode" extend.  See ptr_extend in s390.md.  */
958 #define POINTERS_EXTEND_UNSIGNED -1
959
960 /* A function address in a call instruction is a byte address (for
961    indexing purposes) so give the MEM rtx a byte's mode.  */
962 #define FUNCTION_MODE QImode
963
964 /* Specify the value which is used when clz operand is zero.  */
965 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = 64, 1)
966
967 /* Machine-specific symbol_ref flags.  */
968 #define SYMBOL_FLAG_ALIGN1                (SYMBOL_FLAG_MACH_DEP << 0)
969 #define SYMBOL_REF_ALIGN1_P(X)          \
970   ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_ALIGN1))
971 #define SYMBOL_FLAG_NOT_NATURALLY_ALIGNED (SYMBOL_FLAG_MACH_DEP << 1)
972 #define SYMBOL_REF_NOT_NATURALLY_ALIGNED_P(X) \
973   ((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_NOT_NATURALLY_ALIGNED))
974
975 /* Check whether integer displacement is in range.  */
976 #define DISP_IN_RANGE(d) \
977   (TARGET_LONG_DISPLACEMENT? ((d) >= -524288 && (d) <= 524287) \
978                            : ((d) >= 0 && (d) <= 4095))
979
980 #endif