OSDN Git Service

2003-05-18 Kevin B. Hendricks <kevin.hendricks@sympatico.ca>
[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 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 /* Darwin switches.  */
39 /* Use dynamic-no-pic codegen (no picbase reg; not suitable for shlibs.)  */
40 #define MASK_MACHO_DYNAMIC_NO_PIC 0x00800000
41
42 #define TARGET_DYNAMIC_NO_PIC   (target_flags & MASK_MACHO_DYNAMIC_NO_PIC)
43
44 /* Handle #pragma weak and #pragma pack.  */
45 #define HANDLE_SYSV_PRAGMA 1
46
47
48 #define TARGET_OS_CPP_BUILTINS()                \
49   do                                            \
50     {                                           \
51       builtin_define ("__ppc__");               \
52       builtin_define ("__POWERPC__");           \
53       builtin_define ("__NATURAL_ALIGNMENT__"); \
54       builtin_define ("__MACH__");              \
55       builtin_define ("__APPLE__");             \
56     }                                           \
57   while (0)
58
59
60 /*  */
61 #undef  SUBTARGET_SWITCHES
62 #define SUBTARGET_SWITCHES                                              \
63   {"dynamic-no-pic",    MASK_MACHO_DYNAMIC_NO_PIC,                      \
64       N_("Generate code suitable for executables (NOT shared libs)")},  \
65   {"no-dynamic-no-pic", -MASK_MACHO_DYNAMIC_NO_PIC, ""},
66
67
68 /* The Darwin ABI always includes AltiVec, can't be (validly) turned
69    off.  */
70
71 #define SUBTARGET_OVERRIDE_OPTIONS                                      \
72 do {                                                                    \
73   rs6000_altivec_abi = 1;                                               \
74   if (DEFAULT_ABI == ABI_DARWIN)                                        \
75   {                                                                     \
76     if (MACHO_DYNAMIC_NO_PIC_P)                                         \
77       {                                                                 \
78         if (flag_pic)                                                   \
79             warning ("-mdynamic-no-pic overrides -fpic or -fPIC");      \
80         flag_pic = 0;                                                   \
81       }                                                                 \
82     else if (flag_pic == 1)                                             \
83       {                                                                 \
84         /* Darwin doesn't support -fpic.  */                            \
85         warning ("-fpic is not supported; -fPIC assumed");              \
86         flag_pic = 2;                                                   \
87       }                                                                 \
88   }                                                                     \
89 }while(0)
90
91 /* We want -fPIC by default, unless we're using -static to compile for
92    the kernel or some such.  */
93
94
95 #define CC1_SPEC "\
96 %{static: %{Zdynamic: %e conflicting code gen style switches are used}}\
97 %{!static:%{!mdynamic-no-pic:-fPIC}}"
98
99 /* Make both r2 and r3 available for allocation.  */
100 #define FIXED_R2 0
101 #define FIXED_R13 0
102
103 /* Base register for access to local variables of the function.  */
104
105 #undef  FRAME_POINTER_REGNUM
106 #define FRAME_POINTER_REGNUM 30
107
108 #undef  RS6000_PIC_OFFSET_TABLE_REGNUM
109 #define RS6000_PIC_OFFSET_TABLE_REGNUM 31
110
111 /* Pad the outgoing args area to 16 bytes instead of the usual 8.  */
112
113 #undef STARTING_FRAME_OFFSET
114 #define STARTING_FRAME_OFFSET                                           \
115   (RS6000_ALIGN (current_function_outgoing_args_size, 16)               \
116    + RS6000_VARARGS_AREA                                                \
117    + RS6000_SAVE_AREA)
118
119 #undef STACK_DYNAMIC_OFFSET
120 #define STACK_DYNAMIC_OFFSET(FUNDECL)                                   \
121   (RS6000_ALIGN (current_function_outgoing_args_size, 16)               \
122    + (STACK_POINTER_OFFSET))
123
124 /* These are used by -fbranch-probabilities */
125 #define HOT_TEXT_SECTION_NAME "__TEXT,__text,regular,pure_instructions"
126 #define UNLIKELY_EXECUTED_TEXT_SECTION_NAME \
127                               "__TEXT,__text2,regular,pure_instructions"
128
129 /* Define cutoff for using external functions to save floating point.
130    Currently on Darwin, always use inline stores.  */
131
132 #undef  FP_SAVE_INLINE
133 #define FP_SAVE_INLINE(FIRST_REG) ((FIRST_REG) < 64)
134
135 /* Always use the "debug" register names, they're what the assembler
136    wants to see.  */
137
138 #undef REGISTER_NAMES
139 #define REGISTER_NAMES DEBUG_REGISTER_NAMES
140
141 /* This outputs NAME to FILE.  */
142
143 #undef  RS6000_OUTPUT_BASENAME
144 #define RS6000_OUTPUT_BASENAME(FILE, NAME)      \
145     assemble_name (FILE, NAME);
146
147 /* Globalizing directive for a label.  */
148 #undef GLOBAL_ASM_OP
149 #define GLOBAL_ASM_OP "\t.globl "
150 #undef TARGET_ASM_GLOBALIZE_LABEL
151
152 /* This is how to output an internal label prefix.  rs6000.c uses this
153    when generating traceback tables.  */
154 /* Not really used for Darwin?  */
155
156 #undef ASM_OUTPUT_INTERNAL_LABEL_PREFIX
157 #define ASM_OUTPUT_INTERNAL_LABEL_PREFIX(FILE,PREFIX)   \
158   fprintf (FILE, "%s", PREFIX)
159
160 /* This says how to output an assembler line to define a global common
161    symbol.  */
162 /* ? */
163 #undef  ASM_OUTPUT_ALIGNED_COMMON
164 #define ASM_OUTPUT_COMMON(FILE, NAME, SIZE, ROUNDED)    \
165   do { fputs (".comm ", (FILE));                        \
166        RS6000_OUTPUT_BASENAME ((FILE), (NAME));         \
167        fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED"\n",\
168                 (SIZE)); } while (0)
169
170 /* Override the standard rs6000 definition.  */
171
172 #undef ASM_COMMENT_START
173 #define ASM_COMMENT_START ";"
174
175 /* FP save and restore routines.  */
176 #define SAVE_FP_PREFIX "._savef"
177 #define SAVE_FP_SUFFIX ""
178 #define RESTORE_FP_PREFIX "._restf"
179 #define RESTORE_FP_SUFFIX ""
180
181 /* This is how to output an assembler line that says to advance
182    the location counter to a multiple of 2**LOG bytes using the
183    "nop" instruction as padding.  */
184
185 #define ASM_OUTPUT_ALIGN_WITH_NOP(FILE,LOG)                   \
186   do                                                          \
187     {                                                         \
188       if ((LOG) < 3)                                          \
189         {                                                     \
190           ASM_OUTPUT_ALIGN (FILE,LOG);                        \
191         }                                                     \
192       else /* nop == ori r0,r0,0 */                           \
193         fprintf (FILE, "\t.align32 %d,0x60000000\n", (LOG));  \
194     } while (0)
195
196 /* Generate insns to call the profiler.  */
197
198 #define PROFILE_HOOK(LABEL)   output_profile_hook (LABEL)
199
200 /* Function name to call to do profiling.  */
201
202 #define RS6000_MCOUNT "*mcount"
203
204 /* Default processor: a G4.  */
205
206 #undef PROCESSOR_DEFAULT
207 #define PROCESSOR_DEFAULT  PROCESSOR_PPC7400
208
209 /* Default target flag settings.  Despite the fact that STMW/LMW
210    serializes, it's still a big codesize win to use them.  Use FSEL by
211    default as well.  */
212
213 #undef  TARGET_DEFAULT
214 #define TARGET_DEFAULT (MASK_POWERPC | MASK_MULTIPLE | MASK_NEW_MNEMONICS \
215                       | MASK_PPC_GFXOPT)
216
217 /* Since Darwin doesn't do TOCs, stub this out.  */
218
219 #define ASM_OUTPUT_SPECIAL_POOL_ENTRY_P(X, MODE)  0
220
221 /* Unlike most other PowerPC targets, chars are signed, for
222    consistency with other Darwin architectures.  */
223
224 #undef DEFAULT_SIGNED_CHAR
225 #define DEFAULT_SIGNED_CHAR (1)
226
227 /* Given an rtx X being reloaded into a reg required to be      
228    in class CLASS, return the class of reg to actually use.     
229    In general this is just CLASS; but on some machines
230    in some cases it is preferable to use a more restrictive class.
231   
232    On the RS/6000, we have to return NO_REGS when we want to reload a
233    floating-point CONST_DOUBLE to force it to be copied to memory.
234
235    Don't allow R0 when loading the address of, or otherwise furtling with,
236    a SYMBOL_REF.  */
237
238 #undef PREFERRED_RELOAD_CLASS
239 #define PREFERRED_RELOAD_CLASS(X,CLASS)                 \
240   (((GET_CODE (X) == CONST_DOUBLE                       \
241     && GET_MODE_CLASS (GET_MODE (X)) == MODE_FLOAT)     \
242    ? NO_REGS                                            \
243    : (GET_MODE_CLASS (GET_MODE (X)) == MODE_INT         \
244       && (CLASS) == NON_SPECIAL_REGS)                   \
245    ? GENERAL_REGS                                       \
246    : (GET_CODE (X) == SYMBOL_REF || GET_CODE (X) == HIGH)       \
247    ? BASE_REGS                                          \
248    : (CLASS)))
249
250 /* Fix for emit_group_load (): force large constants to be pushed via regs.  */
251 #define ALWAYS_PUSH_CONSTS_USING_REGS_P         1
252
253 /* This now supports a natural alignment mode */
254 /* Darwin word-aligns FP doubles but doubleword-aligns 64-bit ints.  */
255 #define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \
256   (TARGET_ALIGN_NATURAL ? (COMPUTED) : \
257   (TYPE_MODE (TREE_CODE (TREE_TYPE (FIELD)) == ARRAY_TYPE \
258               ? get_inner_array_type (FIELD) \
259               : TREE_TYPE (FIELD)) == DFmode \
260    ? MIN ((COMPUTED), 32) : (COMPUTED)))
261
262 /* Darwin increases natural record alignment to doubleword if the first
263    field is an FP double while the FP fields remain word aligned.  */
264 #define ROUND_TYPE_ALIGN(STRUCT, COMPUTED, SPECIFIED)   \
265   ((TREE_CODE (STRUCT) == RECORD_TYPE                   \
266     || TREE_CODE (STRUCT) == UNION_TYPE                 \
267     || TREE_CODE (STRUCT) == QUAL_UNION_TYPE)           \
268    && TYPE_FIELDS (STRUCT) != 0                         \
269    && TARGET_ALIGN_NATURAL == 0                         \
270    && DECL_MODE (TYPE_FIELDS (STRUCT)) == DFmode        \
271    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 64)            \
272    : (TARGET_ALTIVEC && TREE_CODE (STRUCT) == VECTOR_TYPE) \
273    ? MAX (MAX ((COMPUTED), (SPECIFIED)), 128)           \
274    : MAX ((COMPUTED), (SPECIFIED)))
275
276 /* XXX: Darwin supports neither .quad, or .llong, but it also doesn't
277    support 64 bit PowerPC either, so this just keeps things happy.  */
278 #define DOUBLE_INT_ASM_OP "\t.quad\t"
279
280 /* Get HOST_WIDE_INT and CONST_INT to be 32 bits, for compile time
281    space/speed.  */
282 #undef MAX_LONG_TYPE_SIZE
283 #define MAX_LONG_TYPE_SIZE 32
284
285 /* For binary compatibility with 2.95; Darwin C APIs use bool from
286    stdbool.h, which was an int-sized enum in 2.95.  */
287 #define BOOL_TYPE_SIZE INT_TYPE_SIZE
288
289 #undef REGISTER_TARGET_PRAGMAS
290 #define REGISTER_TARGET_PRAGMAS DARWIN_REGISTER_TARGET_PRAGMAS