OSDN Git Service

* config/rs6000/rs6000.c (rs6000_emit_prologue): Use 5 nops,
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / darwin.h
1 /* Target definitions for PowerPC running Darwin (Mac OS X).
2    Copyright (C) 1997, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
3    Contributed by Apple Computer Inc.
4
5    This file is part of GCC.
6
7    GCC is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published
9    by the Free Software Foundation; either version 2, or (at your
10    option) any later version.
11
12    GCC is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15    License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GCC; see the file COPYING.  If not, write to the
19    Free Software Foundation, 59 Temple Place - Suite 330, Boston,
20    MA 02111-1307, USA.  */
21
22 #undef  TARGET_VERSION
23 #define TARGET_VERSION fprintf (stderr, " (Darwin/PowerPC)");
24
25 /* The "Darwin ABI" is mostly like AIX, but with some key differences.  */
26
27 #define DEFAULT_ABI ABI_DARWIN
28
29 /* The object file format is Mach-O.  */
30
31 #define TARGET_OBJECT_FORMAT OBJECT_MACHO
32
33 /* We're not ever going to do TOCs.  */
34
35 #define TARGET_TOC 0
36 #define TARGET_NO_TOC 1
37
38 /* Override the default rs6000 definition.  */
39 #undef  PTRDIFF_TYPE
40 #define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
41
42 /* Darwin switches.  */
43 /* Use dynamic-no-pic codegen (no picbase reg; not suitable for shlibs.)  */
44 #define MASK_MACHO_DYNAMIC_NO_PIC 0x00800000
45
46 #define TARGET_DYNAMIC_NO_PIC   (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
47
48 /* Handle #pragma weak and #pragma pack.  */
49 #define HANDLE_SYSV_PRAGMA 1
50
51
52 #define TARGET_OS_CPP_BUILTINS()                \
53   do                                            \
54     {                                           \
55       if (!TARGET_64BIT) builtin_define ("__ppc__");   \
56       if (TARGET_64BIT) builtin_define ("__ppc64__");  \
57       builtin_define ("__POWERPC__");           \
58       builtin_define ("__NATURAL_ALIGNMENT__"); \
59       builtin_define ("__MACH__");              \
60       builtin_define ("__APPLE__");             \
61     }                                           \
62   while (0)
63
64
65 /*  */
66 #undef  SUBTARGET_SWITCHES
67 #define SUBTARGET_SWITCHES                                              \
68   { "64",     MASK_64BIT | MASK_POWERPC64, \
69         N_("Generate 64-bit code") }, \
70   { "32",     - (MASK_64BIT | MASK_POWERPC64), \
71         N_("Generate 32-bit code") }, \
72   {"dynamic-no-pic",    MASK_MACHO_DYNAMIC_NO_PIC,                      \
73       N_("Generate code suitable for executables (NOT shared libs)")},  \
74   {"no-dynamic-no-pic", -MASK_MACHO_DYNAMIC_NO_PIC, ""},
75
76
77 /* The Darwin ABI always includes AltiVec, can't be (validly) turned
78    off.  */
79
80 #define SUBTARGET_OVERRIDE_OPTIONS                                      \
81 do {                                                                    \
82   rs6000_altivec_abi = 1;                                               \
83   rs6000_altivec_vrsave = 1;                                            \
84   if (DEFAULT_ABI == ABI_DARWIN)                                        \
85   {                                                                     \
86     if (MACHO_DYNAMIC_NO_PIC_P)                                         \
87       {                                                                 \
88         if (flag_pic)                                                   \
89             warning ("-mdynamic-no-pic overrides -fpic or -fPIC");      \
90         flag_pic = 0;                                                   \
91       }                                                                 \
92     else if (flag_pic == 1)                                             \
93       {                                                                 \
94         /* Darwin doesn't support -fpic.  */                            \
95         warning ("-fpic is not supported; -fPIC assumed");              \
96         flag_pic = 2;                                                   \
97       }                                                                 \
98                                                                         \
99     /* Handle -mfix-and-continue.  */                                   \
100     if (darwin_fix_and_continue_switch)                                 \
101       {                                                                 \
102         const char *base = darwin_fix_and_continue_switch;              \
103         while (base[-1] != 'm') base--;                                 \
104                                                                         \
105         if (*darwin_fix_and_continue_switch != '\0')                    \
106           error ("invalid option %qs", base);                           \
107         darwin_fix_and_continue = (base[0] != 'n');                     \
108       }                                                                 \
109   }                                                                     \
110   if (TARGET_64BIT && ! TARGET_POWERPC64)                               \
111     {                                                                   \
112       target_flags |= MASK_POWERPC64;                                   \
113       warning ("-m64 requires PowerPC64 architecture, enabling");       \
114     }                                                                   \
115 } while(0)
116
117 /* Darwin has 128-bit long double support in libc in 10.4 and later.
118    Default to 128-bit long doubles even on earlier platforms for ABI
119    consistency; arithmetic will work even if libc and libm support is
120    not available.  */
121
122 #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 128
123
124
125 /* We want -fPIC by default, unless we're using -static to compile for
126    the kernel or some such.  */
127
128 #define CC1_SPEC "\
129 %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
130 %{static: %{Zdynamic: %e conflicting code gen style switches are used}}\
131 %{!static:%{!mdynamic-no-pic:-fPIC}}"
132
133 #define DARWIN_SUBARCH_SPEC "                   \
134  %{m64: ppc64}                                  \
135  %{!m64:                                        \
136  %{mcpu=601:ppc601;                             \
137    mcpu=603:ppc603;                             \
138    mcpu=603e:ppc603;                            \
139    mcpu=604:ppc604;                             \
140    mcpu=604e:ppc604e;                           \
141    mcpu=740:ppc750;                             \
142    mcpu=750:ppc750;                             \
143    mcpu=G3:ppc750;                              \
144    mcpu=7400:ppc7400;                           \
145    mcpu=G4:ppc7400;                             \
146    mcpu=7450:ppc7450;                           \
147    mcpu=970:ppc970;                             \
148    mcpu=power4:ppc970;                          \
149    mcpu=G5:ppc970;                              \
150    :ppc}}"
151
152 #undef SUBTARGET_EXTRA_SPECS
153 #define SUBTARGET_EXTRA_SPECS                   \
154   { "darwin_arch", "%{m64:ppc64;:ppc}" },       \
155   { "darwin_subarch", DARWIN_SUBARCH_SPEC },
156
157 /* Output a .machine directive.  */
158 #undef TARGET_ASM_FILE_START
159 #define TARGET_ASM_FILE_START rs6000_darwin_file_start
160
161 /* The "-faltivec" option should have been called "-maltivec" all
162    along.  -ffix-and-continue and -findirect-data is for compatibility
163    for old compilers.  */
164
165 #define SUBTARGET_OPTION_TRANSLATE_TABLE                                \
166   { "-ffix-and-continue", "-mfix-and-continue" },                       \
167   { "-findirect-data", "-mfix-and-continue" },                          \
168   { "-faltivec", "-maltivec -include altivec.h" },                      \
169   { "-fno-altivec", "-mno-altivec" },                                   \
170   { "-Waltivec-long-deprecated",        "-mwarn-altivec-long" },        \
171   { "-Wno-altivec-long-deprecated", "-mno-warn-altivec-long" }
172
173 /* Make both r2 and r13 available for allocation.  */
174 #define FIXED_R2 0
175 #define FIXED_R13 0
176
177 /* Base register for access to local variables of the function.  */
178
179 #undef  FRAME_POINTER_REGNUM
180 #define FRAME_POINTER_REGNUM 30
181
182 #undef  RS6000_PIC_OFFSET_TABLE_REGNUM
183 #define RS6000_PIC_OFFSET_TABLE_REGNUM 31
184
185 /* Pad the outgoing args area to 16 bytes instead of the usual 8.  */
186
187 #undef STARTING_FRAME_OFFSET
188 #define STARTING_FRAME_OFFSET                                           \
189   (RS6000_ALIGN (current_function_outgoing_args_size, 16)               \
190    + RS6000_VARARGS_AREA                                                \
191    + RS6000_SAVE_AREA)
192
193 #undef STACK_DYNAMIC_OFFSET
194 #define STACK_DYNAMIC_OFFSET(FUNDECL)                                   \
195   (RS6000_ALIGN (current_function_outgoing_args_size, 16)               \
196    + (STACK_POINTER_OFFSET))
197
198 /* These are used by -fbranch-probabilities */
199 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
200 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
201                               "__TEXT,__unlikely,regular,pure_instructions"
202
203 /* Define cutoff for using external functions to save floating point.
204    Currently on Darwin, always use inline stores.  */
205
206 #undef  FP_SAVE_INLINE
207 #define FP_SAVE_INLINE(FIRST_REG) ((FIRST_REG) < 64)
208
209 /* Darwin uses a function call if everything needs to be saved/restored.  */
210 #undef WORLD_SAVE_P
211 #define WORLD_SAVE_P(INFO) ((INFO)->world_save_p)
212
213 /* The assembler wants the alternate register names, but without
214    leading percent sign.  */
215 #undef REGISTER_NAMES
216 #define REGISTER_NAMES                                                  \
217 {                                                                       \
218      "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",             \
219      "r8",  "r9", "r10", "r11", "r12", "r13", "r14", "r15",             \
220     "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",             \
221     "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",             \
222      "f0",  "f1",  "f2",  "f3",  "f4",  "f5",  "f6",  "f7",             \
223      "f8",  "f9", "f10", "f11", "f12", "f13", "f14", "f15",             \
224     "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",             \
225     "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",             \
226      "mq",  "lr", "ctr",  "ap",                                         \
227     "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",             \
228     "xer",                                                              \
229      "v0",  "v1",  "v2",  "v3",  "v4",  "v5",  "v6",  "v7",             \
230      "v8",  "v9", "v10", "v11", "v12", "v13", "v14", "v15",             \
231     "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",             \
232     "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",             \
233     "vrsave", "vscr",                                                   \
234     "spe_acc", "spefscr"                                                \
235 }
236
237 /* This outputs NAME to FILE.  */
238
239 #undef  RS6000_OUTPUT_BASENAME
240 #define RS6000_OUTPUT_BASENAME(FILE, NAME)      \
241     assemble_name (FILE, NAME)
242
243 /* Globalizing directive for a label.  */
244 #undef GLOBAL_ASM_OP
245 #define GLOBAL_ASM_OP "\t.globl "
246 #undef TARGET_ASM_GLOBALIZE_LABEL
247
248 /* This is how to output an internal label prefix.  rs6000.c uses this
249    when generating traceback tables.  */
250 /* Not really used for Darwin?  */
251
252 #undef ASM_OUTPUT_INTERNAL_LABEL_PREFIX
253 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX)   \
254   fprintf (FILE, "%s", PREFIX)
255
256 /* This says how to output an assembler line to define a global common
257    symbol.  */
258 /* ? */
259 #undef  ASM_OUTPUT_ALIGNED_COMMON
260 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)                    \
261   do {                                                                  \
262     unsigned HOST_WIDE_INT _new_size = SIZE;                            \
263     fputs (".comm ", (FILE));                                           \
264     RS6000_OUTPUT_BASENAME ((FILE), (NAME));                            \
265     if (_new_size == 0) _new_size = 1;                                  \
266     fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n", _new_size);   \
267   } while (0)
268
269 /* Override the standard rs6000 definition.  */
270
271 #undef ASM_COMMENT_START
272 #define ASM_COMMENT_START ";"
273
274 /* FP save and restore routines.  */
275 #define SAVE_FP_PREFIX "._savef"
276 #define SAVE_FP_SUFFIX ""
277 #define RESTORE_FP_PREFIX "._restf"
278 #define RESTORE_FP_SUFFIX ""
279
280 /* This is how to output an assembler line that says to advance
281    the location counter to a multiple of 2**LOG bytes using the
282    "nop" instruction as padding.  */
283
284 #define ASM_OUTPUT_ALIGN_WITH_NOP(FILE,LOG)                   \
285   do                                                          \
286     {                                                         \
287       if ((LOG) < 3)                                          \
288         {                                                     \
289           ASM_OUTPUT_ALIGN (FILE,LOG);                        \
290         }                                                     \
291       else /* nop == ori r0,r0,0 */                           \
292         fprintf (FILE, "\t.align32 %d,0x60000000\n", (LOG));  \
293     } while (0)
294
295 /* Generate insns to call the profiler.  */
296
297 #define PROFILE_HOOK(LABEL)   output_profile_hook (LABEL)
298
299 /* Function name to call to do profiling.  */
300
301 #define RS6000_MCOUNT "*mcount"
302
303 /* Default processor: G4, and G5 for 64-bit.  */
304
305 #undef PROCESSOR_DEFAULT
306 #define PROCESSOR_DEFAULT  PROCESSOR_PPC7400
307 #undef PROCESSOR_DEFAULT64
308 #define PROCESSOR_DEFAULT64  PROCESSOR_POWER4
309
310 /* Default target flag settings.  Despite the fact that STMW/LMW
311    serializes, it's still a big code size win to use them.  Use FSEL by
312    default as well.  */
313
314 #undef  TARGET_DEFAULT
315 #define TARGET_DEFAULT (MASK_POWERPC | MASK_MULTIPLE | MASK_NEW_MNEMONICS \
316                       | MASK_PPC_GFXOPT)
317
318 /* Darwin only runs on PowerPC, so short-circuit POWER patterns.  */
319 #undef  TARGET_POWER
320 #define TARGET_POWER 0
321
322 /* Since Darwin doesn't do TOCs, stub this out.  */
323
324 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)  0
325
326 /* Unlike most other PowerPC targets, chars are signed, for
327    consistency with other Darwin architectures.  */
328
329 #undef DEFAULT_SIGNED_CHAR
330 #define DEFAULT_SIGNED_CHAR (1)
331
332 /* Given an rtx X being reloaded into a reg required to be      
333    in class CLASS, return the class of reg to actually use.     
334    In general this is just CLASS; but on some machines
335    in some cases it is preferable to use a more restrictive class.
336   
337    On the RS/6000, we have to return NO_REGS when we want to reload a
338    floating-point CONST_DOUBLE to force it to be copied to memory.
339
340    Don't allow R0 when loading the address of, or otherwise furtling with,
341    a SYMBOL_REF.  */
342
343 #undef PREFERRED_RELOAD_CLASS
344 #define PREFERRED_RELOAD_CLASS(X,CLASS)                         \
345   ((CONSTANT_P (X)                                              \
346     && reg_classes_intersect_p ((CLASS), FLOAT_REGS))           \
347    ? NO_REGS                                                    \
348    : ((GET_CODE (X) == SYMBOL_REF || GET_CODE (X) == HIGH)      \
349       && reg_class_subset_p (BASE_REGS, (CLASS)))               \
350    ? BASE_REGS                                                  \
351    : (GET_MODE_CLASS (GET_MODE (X)) == MODE_INT                 \
352       && (CLASS) == NON_SPECIAL_REGS)                           \
353    ? GENERAL_REGS                                               \
354    : (CLASS))
355
356 /* Fix for emit_group_load (): force large constants to be pushed via regs.  */
357 #define ALWAYS_PUSH_CONSTS_USING_REGS_P         1
358
359 /* This now supports a natural alignment mode */
360 /* Darwin word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
361 #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
362   (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
363   (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
364               ? get_inner_array_type (FIELD) \
365               : TREE_TYPE (FIELD)) == DFmode \
366    ? MIN ((COMPUTED), 32) : (COMPUTED)))
367
368 /* Darwin increases natural record alignment to doubleword if the first
369    field is an FP double while the FP fields remain word aligned.  */
370 #define ROUND_TYPE_ALIGN(STRUCT, COMPUTED, SPECIFIED)                   \
371   ((TREE_CODE (STRUCT) == RECORD_TYPE                                   \
372     || TREE_CODE (STRUCT) == UNION_TYPE                                 \
373     || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)                           \
374    && TARGET_ALIGN_NATURAL == 0                                         \
375    ? rs6000_special_round_type_align (STRUCT, COMPUTED, SPECIFIED)      \
376    : (TREE_CODE (STRUCT) == VECTOR_TYPE                                 \
377       && ALTIVEC_VECTOR_MODE (TYPE_MODE (STRUCT)))                      \
378    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 128)                            \
379    : MAX ((COMPUTED), (SPECIFIED)))
380
381 /* Specify padding for the last element of a block move between
382    registers and memory.  FIRST is nonzero if this is the only
383    element.  */
384 #define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
385   (!(FIRST) ? upward : FUNCTION_ARG_PADDING (MODE, TYPE))
386
387 /* XXX: Darwin supports neither .quad, or .llong, but it also doesn't
388    support 64 bit PowerPC either, so this just keeps things happy.  */
389 #define DOUBLE_INT_ASM_OP "\t.quad\t"
390
391 /* For binary compatibility with 2.95; Darwin C APIs use bool from
392    stdbool.h, which was an int-sized enum in 2.95.  Users can explicitly
393    choose to have sizeof(bool)==1 with the -mone-byte-bool switch. */
394 extern const char *darwin_one_byte_bool;
395 #define BOOL_TYPE_SIZE (darwin_one_byte_bool ? CHAR_TYPE_SIZE : INT_TYPE_SIZE)
396
397 #undef REGISTER_TARGET_PRAGMAS
398 #define REGISTER_TARGET_PRAGMAS DARWIN_REGISTER_TARGET_PRAGMAS
399
400 #ifdef IN_LIBGCC2
401 #include <stdbool.h>
402 #endif
403
404 #define MD_UNWIND_SUPPORT "config/rs6000/darwin-unwind.h"
405
406 #define HAS_MD_FALLBACK_FRAME_STATE_FOR 1
407
408 /* True, iff we're generating fast turn around debugging code.  When
409    true, we arrange for function prologues to start with 5 nops so
410    that gdb may insert code to redirect them, and for data to be
411    accessed indirectly.  The runtime uses this indirection to forward
412    references for data to the original instance of that data.  */
413
414 #define TARGET_FIX_AND_CONTINUE (darwin_fix_and_continue)