]>
Commit | Line | Data |
---|---|---|
9878760c | 1 | /* Subroutines used for code generation on IBM RS/6000. |
9ebbca7d | 2 | Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
63b6e069 | 3 | 2000, 2001 Free Software Foundation, Inc. |
fab3bcc3 | 4 | Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu) |
9878760c RK |
5 | |
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
c15c9075 RK |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, |
21 | Boston, MA 02111-1307, USA. */ | |
9878760c | 22 | |
956d6950 | 23 | #include "config.h" |
c4d38ccb | 24 | #include "system.h" |
9878760c RK |
25 | #include "rtl.h" |
26 | #include "regs.h" | |
27 | #include "hard-reg-set.h" | |
28 | #include "real.h" | |
29 | #include "insn-config.h" | |
30 | #include "conditions.h" | |
9878760c RK |
31 | #include "insn-attr.h" |
32 | #include "flags.h" | |
33 | #include "recog.h" | |
9878760c | 34 | #include "obstack.h" |
9b30bae2 | 35 | #include "tree.h" |
dfafc897 | 36 | #include "expr.h" |
2fc1c679 | 37 | #include "optabs.h" |
2a430ec1 | 38 | #include "except.h" |
a7df97e6 | 39 | #include "function.h" |
296b8152 | 40 | #include "output.h" |
d5fa86ba | 41 | #include "basic-block.h" |
d0101753 | 42 | #include "integrate.h" |
296b8152 | 43 | #include "toplev.h" |
c8023011 | 44 | #include "ggc.h" |
9ebbca7d GK |
45 | #include "hashtab.h" |
46 | #include "tm_p.h" | |
672a6f42 NB |
47 | #include "target.h" |
48 | #include "target-def.h" | |
3ac88239 | 49 | #include "langhooks.h" |
9b30bae2 | 50 | |
7509c759 MM |
51 | #ifndef TARGET_NO_PROTOTYPE |
52 | #define TARGET_NO_PROTOTYPE 0 | |
53 | #endif | |
54 | ||
9878760c RK |
55 | #define min(A,B) ((A) < (B) ? (A) : (B)) |
56 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
57 | ||
5248c961 RK |
58 | /* Target cpu type */ |
59 | ||
60 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
61 | struct rs6000_cpu_select rs6000_select[3] = |
62 | { | |
815cdc52 MM |
63 | /* switch name, tune arch */ |
64 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
65 | { (const char *)0, "-mcpu=", 1, 1 }, | |
66 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 67 | }; |
5248c961 | 68 | |
6fa3f289 ZW |
69 | /* Size of long double */ |
70 | const char *rs6000_long_double_size_string; | |
71 | int rs6000_long_double_type_size; | |
72 | ||
73 | /* Whether -mabi=altivec has appeared */ | |
74 | int rs6000_altivec_abi; | |
75 | ||
c764f757 RK |
76 | /* Set to non-zero once AIX common-mode calls have been defined. */ |
77 | static int common_mode_defined; | |
c81bebd7 | 78 | |
9878760c RK |
79 | /* Save information from a "cmpxx" operation until the branch or scc is |
80 | emitted. */ | |
9878760c RK |
81 | rtx rs6000_compare_op0, rs6000_compare_op1; |
82 | int rs6000_compare_fp_p; | |
874a0744 | 83 | |
874a0744 MM |
84 | /* Label number of label created for -mrelocatable, to call to so we can |
85 | get the address of the GOT section */ | |
86 | int rs6000_pic_labelno; | |
c81bebd7 | 87 | |
b91da81f | 88 | #ifdef USING_ELFOS_H |
c81bebd7 | 89 | /* Which abi to adhere to */ |
815cdc52 | 90 | const char *rs6000_abi_name = RS6000_ABI_NAME; |
d9407988 MM |
91 | |
92 | /* Semantics of the small data area */ | |
93 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
94 | ||
95 | /* Which small data model to use */ | |
815cdc52 | 96 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
97 | |
98 | /* Counter for labels which are to be placed in .fixup. */ | |
99 | int fixuplabelno = 0; | |
874a0744 | 100 | #endif |
4697a36c | 101 | |
b6c9286a MM |
102 | /* ABI enumeration available for subtarget to use. */ |
103 | enum rs6000_abi rs6000_current_abi; | |
104 | ||
0ac081f6 AH |
105 | /* ABI string from -mabi= option. */ |
106 | const char *rs6000_abi_string; | |
107 | ||
38c1f2d7 | 108 | /* Debug flags */ |
815cdc52 | 109 | const char *rs6000_debug_name; |
38c1f2d7 MM |
110 | int rs6000_debug_stack; /* debug stack applications */ |
111 | int rs6000_debug_arg; /* debug argument handling */ | |
112 | ||
113 | /* Flag to say the TOC is initialized */ | |
114 | int toc_initialized; | |
9ebbca7d | 115 | char toc_label_name[10]; |
38c1f2d7 | 116 | |
9ebbca7d GK |
117 | /* Alias set for saves and restores from the rs6000 stack. */ |
118 | static int rs6000_sr_alias_set; | |
c8023011 | 119 | |
9ebbca7d GK |
120 | static void rs6000_add_gc_roots PARAMS ((void)); |
121 | static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT)); | |
122 | static rtx expand_block_move_mem PARAMS ((enum machine_mode, rtx, rtx)); | |
39a10a29 GK |
123 | static void validate_condition_mode |
124 | PARAMS ((enum rtx_code, enum machine_mode)); | |
125 | static rtx rs6000_generate_compare PARAMS ((enum rtx_code)); | |
e50f5f3d | 126 | static void rs6000_maybe_dead PARAMS ((rtx)); |
9ebbca7d GK |
127 | static void rs6000_emit_stack_tie PARAMS ((void)); |
128 | static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx)); | |
129 | static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int)); | |
130 | static unsigned rs6000_hash_constant PARAMS ((rtx)); | |
131 | static unsigned toc_hash_function PARAMS ((const void *)); | |
132 | static int toc_hash_eq PARAMS ((const void *, const void *)); | |
2eba1afa | 133 | static int toc_hash_mark_entry PARAMS ((void **, void *)); |
9ebbca7d GK |
134 | static void toc_hash_mark_table PARAMS ((void *)); |
135 | static int constant_pool_expr_1 PARAMS ((rtx, int *, int *)); | |
6fee9e99 NC |
136 | static void rs6000_free_machine_status PARAMS ((struct function *)); |
137 | static void rs6000_init_machine_status PARAMS ((struct function *)); | |
301d03af | 138 | static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int)); |
71f123ca | 139 | static int rs6000_ra_ever_killed PARAMS ((void)); |
91d231cb JM |
140 | static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *)); |
141 | const struct attribute_spec rs6000_attribute_table[]; | |
08c148a8 NB |
142 | static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT)); |
143 | static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT)); | |
2bfcf297 DB |
144 | static rtx rs6000_emit_set_long_const PARAMS ((rtx, |
145 | HOST_WIDE_INT, HOST_WIDE_INT)); | |
7c262518 RH |
146 | #if TARGET_ELF |
147 | static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *, | |
148 | int)); | |
d9f6800d RH |
149 | static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int)); |
150 | static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int)); | |
7c262518 RH |
151 | #endif |
152 | #ifdef OBJECT_FORMAT_COFF | |
715bdd29 | 153 | static void xcoff_asm_named_section PARAMS ((const char *, unsigned int)); |
7c262518 | 154 | #endif |
c237e94a ZW |
155 | static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int)); |
156 | static int rs6000_adjust_priority PARAMS ((rtx, int)); | |
157 | static int rs6000_issue_rate PARAMS ((void)); | |
158 | ||
6fa3f289 | 159 | static void rs6000_init_builtins PARAMS ((void)); |
0ac081f6 AH |
160 | static void altivec_init_builtins PARAMS ((void)); |
161 | static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int)); | |
00b960c7 | 162 | static rtx altivec_expand_builtin PARAMS ((tree, rtx)); |
2212663f | 163 | static rtx altivec_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx)); |
0ac081f6 | 164 | static rtx altivec_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx)); |
2212663f | 165 | static rtx altivec_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx)); |
0ac081f6 | 166 | static void rs6000_parse_abi_options PARAMS ((void)); |
00b960c7 AH |
167 | static int first_altivec_reg_to_save PARAMS ((void)); |
168 | static unsigned int compute_vrsave_mask PARAMS ((void)); | |
169 | static void is_altivec_return_reg PARAMS ((rtx, void *)); | |
170 | int vrsave_operation PARAMS ((rtx, enum machine_mode)); | |
171 | static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *)); | |
c81bebd7 MM |
172 | \f |
173 | /* Default register names. */ | |
174 | char rs6000_reg_names[][8] = | |
175 | { | |
802a0058 MM |
176 | "0", "1", "2", "3", "4", "5", "6", "7", |
177 | "8", "9", "10", "11", "12", "13", "14", "15", | |
178 | "16", "17", "18", "19", "20", "21", "22", "23", | |
179 | "24", "25", "26", "27", "28", "29", "30", "31", | |
180 | "0", "1", "2", "3", "4", "5", "6", "7", | |
181 | "8", "9", "10", "11", "12", "13", "14", "15", | |
182 | "16", "17", "18", "19", "20", "21", "22", "23", | |
183 | "24", "25", "26", "27", "28", "29", "30", "31", | |
184 | "mq", "lr", "ctr","ap", | |
185 | "0", "1", "2", "3", "4", "5", "6", "7", | |
0ac081f6 AH |
186 | "xer", |
187 | /* AltiVec registers. */ | |
0cd5e3a1 AH |
188 | "0", "1", "2", "3", "4", "5", "6", "7", |
189 | "8", "9", "10", "11", "12", "13", "14", "15", | |
190 | "16", "17", "18", "19", "20", "21", "22", "23", | |
191 | "24", "25", "26", "27", "28", "29", "30", "31", | |
0ac081f6 | 192 | "vrsave" |
c81bebd7 MM |
193 | }; |
194 | ||
195 | #ifdef TARGET_REGNAMES | |
8b60264b | 196 | static const char alt_reg_names[][8] = |
c81bebd7 | 197 | { |
802a0058 MM |
198 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
199 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
200 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
201 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
202 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
203 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
204 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
205 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
206 | "mq", "lr", "ctr", "ap", | |
207 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
0ac081f6 AH |
208 | "xer", |
209 | /* AltiVec registers. */ | |
210 | "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7", | |
211 | "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15", | |
212 | "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23", | |
213 | "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31", | |
214 | "%vrsave" | |
c81bebd7 MM |
215 | }; |
216 | #endif | |
9878760c | 217 | \f |
daf11973 MM |
218 | #ifndef MASK_STRICT_ALIGN |
219 | #define MASK_STRICT_ALIGN 0 | |
220 | #endif | |
672a6f42 NB |
221 | \f |
222 | /* Initialize the GCC target structure. */ | |
91d231cb JM |
223 | #undef TARGET_ATTRIBUTE_TABLE |
224 | #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table | |
daf11973 | 225 | |
301d03af RS |
226 | #undef TARGET_ASM_ALIGNED_DI_OP |
227 | #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP | |
228 | ||
229 | /* Default unaligned ops are only provided for ELF. Find the ops needed | |
230 | for non-ELF systems. */ | |
231 | #ifndef OBJECT_FORMAT_ELF | |
232 | #ifdef OBJECT_FORMAT_COFF | |
233 | /* For ECOFF. rs6000_assemble_integer will handle unaligned DIs on | |
234 | 64-bit targets. */ | |
235 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
236 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2," | |
237 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
238 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4," | |
239 | #undef TARGET_ASM_UNALIGNED_DI_OP | |
240 | #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8," | |
241 | #else | |
242 | /* For Darwin. */ | |
243 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
244 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" | |
245 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
246 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" | |
247 | #endif | |
248 | #endif | |
249 | ||
250 | /* This hook deals with fixups for relocatable code and DI-mode objects | |
251 | in 64-bit code. */ | |
252 | #undef TARGET_ASM_INTEGER | |
253 | #define TARGET_ASM_INTEGER rs6000_assemble_integer | |
254 | ||
08c148a8 NB |
255 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
256 | #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue | |
257 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
258 | #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue | |
259 | ||
7c262518 RH |
260 | #if TARGET_ELF |
261 | #undef TARGET_SECTION_TYPE_FLAGS | |
262 | #define TARGET_SECTION_TYPE_FLAGS rs6000_elf_section_type_flags | |
263 | #endif | |
264 | ||
c237e94a ZW |
265 | #undef TARGET_SCHED_ISSUE_RATE |
266 | #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate | |
267 | #undef TARGET_SCHED_ADJUST_COST | |
268 | #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost | |
269 | #undef TARGET_SCHED_ADJUST_PRIORITY | |
270 | #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority | |
271 | ||
0ac081f6 AH |
272 | #undef TARGET_INIT_BUILTINS |
273 | #define TARGET_INIT_BUILTINS rs6000_init_builtins | |
274 | ||
275 | #undef TARGET_EXPAND_BUILTIN | |
276 | #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin | |
277 | ||
00b960c7 AH |
278 | /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */ |
279 | #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO)) | |
280 | ||
f6897b10 | 281 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 282 | \f |
5248c961 RK |
283 | /* Override command line options. Mostly we process the processor |
284 | type and sometimes adjust other TARGET_ options. */ | |
285 | ||
286 | void | |
8e3f41e7 | 287 | rs6000_override_options (default_cpu) |
d330fd93 | 288 | const char *default_cpu; |
5248c961 | 289 | { |
c4d38ccb | 290 | size_t i, j; |
8e3f41e7 | 291 | struct rs6000_cpu_select *ptr; |
5248c961 | 292 | |
85638c0d RK |
293 | /* Simplify the entries below by making a mask for any POWER |
294 | variant and any PowerPC variant. */ | |
295 | ||
938937d8 | 296 | #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING) |
68c49ffa RK |
297 | #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \ |
298 | | MASK_PPC_GFXOPT | MASK_POWERPC64) | |
299 | #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT) | |
85638c0d | 300 | |
5248c961 RK |
301 | static struct ptt |
302 | { | |
8b60264b KG |
303 | const char *const name; /* Canonical processor name. */ |
304 | const enum processor_type processor; /* Processor type enum value. */ | |
305 | const int target_enable; /* Target flags to enable. */ | |
306 | const int target_disable; /* Target flags to disable. */ | |
307 | } const processor_target_table[] | |
cf27b467 MM |
308 | = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS, |
309 | POWER_MASKS | POWERPC_MASKS}, | |
db7f1e43 | 310 | {"power", PROCESSOR_POWER, |
938937d8 | 311 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 | 312 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
8e3f41e7 MM |
313 | {"power2", PROCESSOR_POWER, |
314 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
315 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, | |
c71791e0 DE |
316 | {"power3", PROCESSOR_PPC630, |
317 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
318 | POWER_MASKS | MASK_PPC_GPOPT}, | |
db7f1e43 RK |
319 | {"powerpc", PROCESSOR_POWERPC, |
320 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
68c49ffa | 321 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
3cb999d8 DE |
322 | {"powerpc64", PROCESSOR_POWERPC64, |
323 | MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS, | |
324 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
db7f1e43 | 325 | {"rios", PROCESSOR_RIOS1, |
938937d8 | 326 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
327 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
328 | {"rios1", PROCESSOR_RIOS1, | |
938937d8 | 329 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
330 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
331 | {"rsc", PROCESSOR_PPC601, | |
938937d8 | 332 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
333 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
334 | {"rsc1", PROCESSOR_PPC601, | |
938937d8 | 335 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
336 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
337 | {"rios2", PROCESSOR_RIOS2, | |
938937d8 | 338 | MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2, |
db7f1e43 | 339 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
3cb999d8 DE |
340 | {"rs64a", PROCESSOR_RS64A, |
341 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
342 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
a3a1dbf6 MM |
343 | {"401", PROCESSOR_PPC403, |
344 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
345 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
49a0b204 | 346 | {"403", PROCESSOR_PPC403, |
daf11973 | 347 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN, |
49a0b204 | 348 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
d7a5e253 DE |
349 | {"405", PROCESSOR_PPC405, |
350 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
351 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
352 | {"505", PROCESSOR_MPCCORE, |
353 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
354 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 355 | {"601", PROCESSOR_PPC601, |
938937d8 | 356 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING, |
68c49ffa | 357 | MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
1ec26da6 | 358 | {"602", PROCESSOR_PPC603, |
cf27b467 MM |
359 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
360 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
5248c961 | 361 | {"603", PROCESSOR_PPC603, |
68c49ffa RK |
362 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
363 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a MM |
364 | {"603e", PROCESSOR_PPC603, |
365 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
366 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b5370a88 | 367 | {"ec603e", PROCESSOR_PPC603, |
a3a1dbf6 MM |
368 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
369 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 370 | {"604", PROCESSOR_PPC604, |
b6c9286a MM |
371 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
372 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
cac8ce95 | 373 | {"604e", PROCESSOR_PPC604e, |
07e6159a MM |
374 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
375 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a | 376 | {"620", PROCESSOR_PPC620, |
68c49ffa | 377 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
a260abc9 | 378 | POWER_MASKS | MASK_PPC_GPOPT}, |
3cb999d8 DE |
379 | {"630", PROCESSOR_PPC630, |
380 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
381 | POWER_MASKS | MASK_PPC_GPOPT}, | |
bef84347 VM |
382 | {"740", PROCESSOR_PPC750, |
383 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
384 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
385 | {"750", PROCESSOR_PPC750, | |
386 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
387 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
a4f6c312 SS |
388 | {"7400", PROCESSOR_PPC7400, |
389 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
390 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
391 | {"7450", PROCESSOR_PPC7450, | |
392 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
393 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
07e6159a MM |
394 | {"801", PROCESSOR_MPCCORE, |
395 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
396 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
397 | {"821", PROCESSOR_MPCCORE, |
398 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
399 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
07e6159a MM |
400 | {"823", PROCESSOR_MPCCORE, |
401 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
402 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
403 | {"860", PROCESSOR_MPCCORE, |
404 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
405 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}}; | |
5248c961 | 406 | |
c4d38ccb | 407 | size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt); |
5248c961 | 408 | |
a4f6c312 SS |
409 | /* Save current -mmultiple/-mno-multiple status. */ |
410 | int multiple = TARGET_MULTIPLE; | |
411 | /* Save current -mstring/-mno-string status. */ | |
412 | int string = TARGET_STRING; | |
8a61d227 | 413 | |
a4f6c312 | 414 | /* Identify the processor type. */ |
8e3f41e7 | 415 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 416 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 417 | |
b6a1cbae | 418 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 419 | { |
8e3f41e7 MM |
420 | ptr = &rs6000_select[i]; |
421 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 422 | { |
8e3f41e7 MM |
423 | for (j = 0; j < ptt_size; j++) |
424 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
425 | { | |
426 | if (ptr->set_tune_p) | |
427 | rs6000_cpu = processor_target_table[j].processor; | |
428 | ||
429 | if (ptr->set_arch_p) | |
430 | { | |
431 | target_flags |= processor_target_table[j].target_enable; | |
432 | target_flags &= ~processor_target_table[j].target_disable; | |
433 | } | |
434 | break; | |
435 | } | |
436 | ||
4406229e | 437 | if (j == ptt_size) |
8e3f41e7 | 438 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
439 | } |
440 | } | |
8a61d227 | 441 | |
a4f6c312 SS |
442 | /* If we are optimizing big endian systems for space, use the store |
443 | multiple instructions. */ | |
ef792183 MM |
444 | if (BYTES_BIG_ENDIAN && optimize_size) |
445 | target_flags |= MASK_MULTIPLE; | |
446 | ||
8a61d227 MM |
447 | /* If -mmultiple or -mno-multiple was explicitly used, don't |
448 | override with the processor default */ | |
449 | if (TARGET_MULTIPLE_SET) | |
450 | target_flags = (target_flags & ~MASK_MULTIPLE) | multiple; | |
7e69e155 | 451 | |
a4f6c312 SS |
452 | /* If -mstring or -mno-string was explicitly used, don't override |
453 | with the processor default. */ | |
938937d8 | 454 | if (TARGET_STRING_SET) |
1f5515bf | 455 | target_flags = (target_flags & ~MASK_STRING) | string; |
938937d8 | 456 | |
a4f6c312 SS |
457 | /* Don't allow -mmultiple or -mstring on little endian systems |
458 | unless the cpu is a 750, because the hardware doesn't support the | |
459 | instructions used in little endian mode, and causes an alignment | |
460 | trap. The 750 does not cause an alignment trap (except when the | |
461 | target is unaligned). */ | |
bef84347 | 462 | |
bfc79d3b | 463 | if (! BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
464 | { |
465 | if (TARGET_MULTIPLE) | |
466 | { | |
467 | target_flags &= ~MASK_MULTIPLE; | |
468 | if (TARGET_MULTIPLE_SET) | |
469 | warning ("-mmultiple is not supported on little endian systems"); | |
470 | } | |
471 | ||
472 | if (TARGET_STRING) | |
473 | { | |
474 | target_flags &= ~MASK_STRING; | |
938937d8 MM |
475 | if (TARGET_STRING_SET) |
476 | warning ("-mstring is not supported on little endian systems"); | |
7e69e155 MM |
477 | } |
478 | } | |
3933e0e1 | 479 | |
2bfcf297 | 480 | if (flag_pic && DEFAULT_ABI == ABI_AIX) |
a260abc9 | 481 | { |
2bfcf297 | 482 | warning ("-f%s ignored (all code is position independent)", |
a260abc9 DE |
483 | (flag_pic > 1) ? "PIC" : "pic"); |
484 | flag_pic = 0; | |
485 | } | |
486 | ||
2bfcf297 | 487 | #ifdef XCOFF_DEBUGGING_INFO |
9861b0c9 | 488 | if (flag_function_sections && (write_symbols != NO_DEBUG) |
2bfcf297 | 489 | && DEFAULT_ABI == ABI_AIX) |
9861b0c9 DE |
490 | { |
491 | warning ("-ffunction-sections disabled on AIX when debugging"); | |
492 | flag_function_sections = 0; | |
493 | } | |
494 | ||
495 | if (flag_data_sections && (DEFAULT_ABI == ABI_AIX)) | |
496 | { | |
497 | warning ("-fdata-sections not supported on AIX"); | |
498 | flag_data_sections = 0; | |
499 | } | |
2bfcf297 | 500 | #endif |
9861b0c9 | 501 | |
38c1f2d7 MM |
502 | /* Set debug flags */ |
503 | if (rs6000_debug_name) | |
504 | { | |
bfc79d3b | 505 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 506 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 507 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 508 | rs6000_debug_stack = 1; |
bfc79d3b | 509 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
510 | rs6000_debug_arg = 1; |
511 | else | |
c725bd79 | 512 | error ("unknown -mdebug-%s switch", rs6000_debug_name); |
38c1f2d7 MM |
513 | } |
514 | ||
6fa3f289 ZW |
515 | /* Set size of long double */ |
516 | rs6000_long_double_type_size = 64; | |
517 | if (rs6000_long_double_size_string) | |
518 | { | |
519 | char *tail; | |
520 | int size = strtol (rs6000_long_double_size_string, &tail, 10); | |
521 | if (*tail != '\0' || (size != 64 && size != 128)) | |
522 | error ("Unknown switch -mlong-double-%s", | |
523 | rs6000_long_double_size_string); | |
524 | else | |
525 | rs6000_long_double_type_size = size; | |
526 | } | |
527 | ||
0ac081f6 AH |
528 | /* Handle -mabi= options. */ |
529 | rs6000_parse_abi_options (); | |
530 | ||
c81bebd7 | 531 | #ifdef TARGET_REGNAMES |
a4f6c312 SS |
532 | /* If the user desires alternate register names, copy in the |
533 | alternate names now. */ | |
c81bebd7 | 534 | if (TARGET_REGNAMES) |
4e135bdd | 535 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
536 | #endif |
537 | ||
3933e0e1 MM |
538 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
539 | SUBTARGET_OVERRIDE_OPTIONS; | |
540 | #endif | |
10baca6b AH |
541 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS |
542 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
543 | #endif | |
c8023011 | 544 | |
6fa3f289 ZW |
545 | /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined. |
546 | If -maix-struct-return or -msvr4-struct-return was explicitly | |
547 | used, don't override with the ABI default. */ | |
548 | if (!(target_flags & MASK_AIX_STRUCT_RET_SET)) | |
549 | { | |
550 | if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET) | |
551 | target_flags = (target_flags & ~MASK_AIX_STRUCT_RET); | |
552 | else | |
553 | target_flags |= MASK_AIX_STRUCT_RET; | |
554 | } | |
555 | ||
c8023011 MM |
556 | /* Register global variables with the garbage collector. */ |
557 | rs6000_add_gc_roots (); | |
9ebbca7d GK |
558 | |
559 | /* Allocate an alias set for register saves & restores from stack. */ | |
560 | rs6000_sr_alias_set = new_alias_set (); | |
561 | ||
562 | if (TARGET_TOC) | |
563 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); | |
71f123ca | 564 | |
301d03af RS |
565 | /* We can only guarantee the availability of DI pseudo-ops when |
566 | assembling for 64-bit targets. */ | |
567 | if (!TARGET_POWERPC64) | |
568 | { | |
569 | targetm.asm_out.aligned_op.di = NULL; | |
570 | targetm.asm_out.unaligned_op.di = NULL; | |
571 | } | |
572 | ||
71f123ca FS |
573 | /* Arrange to save and restore machine status around nested functions. */ |
574 | init_machine_status = rs6000_init_machine_status; | |
71f123ca | 575 | free_machine_status = rs6000_free_machine_status; |
5248c961 | 576 | } |
5accd822 | 577 | |
0ac081f6 | 578 | /* Handle -mabi= options. */ |
00b960c7 AH |
579 | static void |
580 | rs6000_parse_abi_options () | |
0ac081f6 AH |
581 | { |
582 | if (rs6000_abi_string == 0) | |
583 | return; | |
584 | else if (! strcmp (rs6000_abi_string, "altivec")) | |
6fa3f289 | 585 | rs6000_altivec_abi = 1; |
0ac081f6 | 586 | else |
c725bd79 | 587 | error ("unknown ABI specified: '%s'", rs6000_abi_string); |
0ac081f6 AH |
588 | } |
589 | ||
5accd822 DE |
590 | void |
591 | optimization_options (level, size) | |
e2c953b6 | 592 | int level ATTRIBUTE_UNUSED; |
5accd822 DE |
593 | int size ATTRIBUTE_UNUSED; |
594 | { | |
5accd822 | 595 | } |
3cfa4909 MM |
596 | \f |
597 | /* Do anything needed at the start of the asm file. */ | |
598 | ||
599 | void | |
600 | rs6000_file_start (file, default_cpu) | |
601 | FILE *file; | |
d330fd93 | 602 | const char *default_cpu; |
3cfa4909 | 603 | { |
c4d38ccb | 604 | size_t i; |
3cfa4909 | 605 | char buffer[80]; |
d330fd93 | 606 | const char *start = buffer; |
3cfa4909 MM |
607 | struct rs6000_cpu_select *ptr; |
608 | ||
609 | if (flag_verbose_asm) | |
610 | { | |
611 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
612 | rs6000_select[0].string = default_cpu; | |
613 | ||
b6a1cbae | 614 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
615 | { |
616 | ptr = &rs6000_select[i]; | |
617 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
618 | { | |
619 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
620 | start = ""; | |
621 | } | |
622 | } | |
623 | ||
b91da81f | 624 | #ifdef USING_ELFOS_H |
3cfa4909 MM |
625 | switch (rs6000_sdata) |
626 | { | |
627 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
628 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
629 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
630 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
631 | } | |
632 | ||
633 | if (rs6000_sdata && g_switch_value) | |
634 | { | |
635 | fprintf (file, "%s -G %d", start, g_switch_value); | |
636 | start = ""; | |
637 | } | |
638 | #endif | |
639 | ||
640 | if (*start == '\0') | |
949ea356 | 641 | putc ('\n', file); |
3cfa4909 MM |
642 | } |
643 | } | |
644 | ||
24d304eb RK |
645 | \f |
646 | /* Create a CONST_DOUBLE from a string. */ | |
647 | ||
648 | struct rtx_def * | |
649 | rs6000_float_const (string, mode) | |
d330fd93 | 650 | const char *string; |
24d304eb RK |
651 | enum machine_mode mode; |
652 | { | |
ca5adc63 GK |
653 | REAL_VALUE_TYPE value; |
654 | value = REAL_VALUE_ATOF (string, mode); | |
24d304eb RK |
655 | return immed_real_const_1 (value, mode); |
656 | } | |
5248c961 | 657 | \f |
9878760c RK |
658 | /* Return non-zero if this function is known to have a null epilogue. */ |
659 | ||
660 | int | |
661 | direct_return () | |
662 | { | |
4697a36c MM |
663 | if (reload_completed) |
664 | { | |
665 | rs6000_stack_t *info = rs6000_stack_info (); | |
666 | ||
667 | if (info->first_gp_reg_save == 32 | |
668 | && info->first_fp_reg_save == 64 | |
00b960c7 | 669 | && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1 |
c81fc13e DE |
670 | && ! info->lr_save_p |
671 | && ! info->cr_save_p | |
00b960c7 | 672 | && info->vrsave_mask == 0 |
c81fc13e | 673 | && ! info->push_p) |
4697a36c MM |
674 | return 1; |
675 | } | |
676 | ||
677 | return 0; | |
9878760c RK |
678 | } |
679 | ||
680 | /* Returns 1 always. */ | |
681 | ||
682 | int | |
683 | any_operand (op, mode) | |
592696dd | 684 | rtx op ATTRIBUTE_UNUSED; |
296b8152 | 685 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
686 | { |
687 | return 1; | |
688 | } | |
689 | ||
a4f6c312 | 690 | /* Returns 1 if op is the count register. */ |
38c1f2d7 | 691 | int |
a4f6c312 | 692 | count_register_operand (op, mode) |
592696dd | 693 | rtx op; |
296b8152 | 694 | enum machine_mode mode ATTRIBUTE_UNUSED; |
b6c9286a MM |
695 | { |
696 | if (GET_CODE (op) != REG) | |
697 | return 0; | |
698 | ||
699 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
700 | return 1; | |
701 | ||
702 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
703 | return 1; | |
704 | ||
705 | return 0; | |
706 | } | |
707 | ||
38c1f2d7 | 708 | int |
a4f6c312 | 709 | xer_operand (op, mode) |
592696dd | 710 | rtx op; |
296b8152 | 711 | enum machine_mode mode ATTRIBUTE_UNUSED; |
802a0058 MM |
712 | { |
713 | if (GET_CODE (op) != REG) | |
714 | return 0; | |
715 | ||
9ebbca7d | 716 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
717 | return 1; |
718 | ||
802a0058 MM |
719 | return 0; |
720 | } | |
721 | ||
c859cda6 DJ |
722 | /* Return 1 if OP is a signed 8-bit constant. Int multiplication |
723 | by such constants completes more quickly. */ | |
724 | ||
725 | int | |
726 | s8bit_cint_operand (op, mode) | |
727 | rtx op; | |
728 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
729 | { | |
730 | return ( GET_CODE (op) == CONST_INT | |
731 | && (INTVAL (op) >= -128 && INTVAL (op) <= 127)); | |
732 | } | |
733 | ||
9878760c RK |
734 | /* Return 1 if OP is a constant that can fit in a D field. */ |
735 | ||
736 | int | |
737 | short_cint_operand (op, mode) | |
592696dd | 738 | rtx op; |
296b8152 | 739 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 740 | { |
5f59ecb7 DE |
741 | return (GET_CODE (op) == CONST_INT |
742 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
743 | } |
744 | ||
5519a4f9 | 745 | /* Similar for an unsigned D field. */ |
9878760c RK |
746 | |
747 | int | |
748 | u_short_cint_operand (op, mode) | |
592696dd | 749 | rtx op; |
296b8152 | 750 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 751 | { |
19684119 | 752 | return (GET_CODE (op) == CONST_INT |
5f59ecb7 | 753 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')); |
9878760c RK |
754 | } |
755 | ||
dcfedcd0 RK |
756 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
757 | ||
758 | int | |
759 | non_short_cint_operand (op, mode) | |
592696dd | 760 | rtx op; |
296b8152 | 761 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
762 | { |
763 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 764 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
765 | } |
766 | ||
2bfcf297 DB |
767 | /* Returns 1 if OP is a CONST_INT that is a positive value |
768 | and an exact power of 2. */ | |
769 | ||
770 | int | |
771 | exact_log2_cint_operand (op, mode) | |
592696dd | 772 | rtx op; |
2bfcf297 DB |
773 | enum machine_mode mode ATTRIBUTE_UNUSED; |
774 | { | |
775 | return (GET_CODE (op) == CONST_INT | |
776 | && INTVAL (op) > 0 | |
777 | && exact_log2 (INTVAL (op)) >= 0); | |
778 | } | |
779 | ||
9878760c RK |
780 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
781 | ctr, or lr). */ | |
782 | ||
783 | int | |
cd2b37d9 | 784 | gpc_reg_operand (op, mode) |
592696dd | 785 | rtx op; |
9878760c RK |
786 | enum machine_mode mode; |
787 | { | |
788 | return (register_operand (op, mode) | |
802a0058 | 789 | && (GET_CODE (op) != REG |
9ebbca7d GK |
790 | || (REGNO (op) >= ARG_POINTER_REGNUM |
791 | && !XER_REGNO_P (REGNO (op))) | |
792 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
793 | } |
794 | ||
795 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
796 | CR field. */ | |
797 | ||
798 | int | |
799 | cc_reg_operand (op, mode) | |
592696dd | 800 | rtx op; |
9878760c RK |
801 | enum machine_mode mode; |
802 | { | |
803 | return (register_operand (op, mode) | |
804 | && (GET_CODE (op) != REG | |
805 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
806 | || CR_REGNO_P (REGNO (op)))); | |
807 | } | |
808 | ||
815cdc52 MM |
809 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
810 | CR field that isn't CR0. */ | |
811 | ||
812 | int | |
813 | cc_reg_not_cr0_operand (op, mode) | |
592696dd | 814 | rtx op; |
815cdc52 MM |
815 | enum machine_mode mode; |
816 | { | |
817 | return (register_operand (op, mode) | |
818 | && (GET_CODE (op) != REG | |
819 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
820 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
821 | } | |
822 | ||
a4f6c312 SS |
823 | /* Returns 1 if OP is either a constant integer valid for a D-field or |
824 | a non-special register. If a register, it must be in the proper | |
825 | mode unless MODE is VOIDmode. */ | |
9878760c RK |
826 | |
827 | int | |
828 | reg_or_short_operand (op, mode) | |
592696dd | 829 | rtx op; |
9878760c RK |
830 | enum machine_mode mode; |
831 | { | |
f5a28898 | 832 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
833 | } |
834 | ||
a4f6c312 SS |
835 | /* Similar, except check if the negation of the constant would be |
836 | valid for a D-field. */ | |
9878760c RK |
837 | |
838 | int | |
839 | reg_or_neg_short_operand (op, mode) | |
592696dd | 840 | rtx op; |
9878760c RK |
841 | enum machine_mode mode; |
842 | { | |
843 | if (GET_CODE (op) == CONST_INT) | |
844 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'); | |
845 | ||
cd2b37d9 | 846 | return gpc_reg_operand (op, mode); |
9878760c RK |
847 | } |
848 | ||
a4f6c312 SS |
849 | /* Return 1 if the operand is either a register or an integer whose |
850 | high-order 16 bits are zero. */ | |
9878760c RK |
851 | |
852 | int | |
853 | reg_or_u_short_operand (op, mode) | |
592696dd | 854 | rtx op; |
9878760c RK |
855 | enum machine_mode mode; |
856 | { | |
e675f625 | 857 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
858 | } |
859 | ||
860 | /* Return 1 is the operand is either a non-special register or ANY | |
861 | constant integer. */ | |
862 | ||
863 | int | |
864 | reg_or_cint_operand (op, mode) | |
592696dd | 865 | rtx op; |
9878760c RK |
866 | enum machine_mode mode; |
867 | { | |
a4f6c312 | 868 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
f6bf7de2 DE |
869 | } |
870 | ||
871 | /* Return 1 is the operand is either a non-special register or ANY | |
872 | 32-bit signed constant integer. */ | |
873 | ||
874 | int | |
875 | reg_or_arith_cint_operand (op, mode) | |
592696dd | 876 | rtx op; |
f6bf7de2 DE |
877 | enum machine_mode mode; |
878 | { | |
a4f6c312 SS |
879 | return (gpc_reg_operand (op, mode) |
880 | || (GET_CODE (op) == CONST_INT | |
f6bf7de2 | 881 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
882 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) |
883 | < (unsigned HOST_WIDE_INT) 0x100000000ll) | |
f6bf7de2 | 884 | #endif |
a4f6c312 | 885 | )); |
9878760c RK |
886 | } |
887 | ||
2bfcf297 DB |
888 | /* Return 1 is the operand is either a non-special register or a 32-bit |
889 | signed constant integer valid for 64-bit addition. */ | |
890 | ||
891 | int | |
892 | reg_or_add_cint64_operand (op, mode) | |
592696dd | 893 | rtx op; |
2bfcf297 DB |
894 | enum machine_mode mode; |
895 | { | |
a4f6c312 SS |
896 | return (gpc_reg_operand (op, mode) |
897 | || (GET_CODE (op) == CONST_INT | |
898 | && INTVAL (op) < 0x7fff8000 | |
2bfcf297 | 899 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
900 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) |
901 | < 0x100000000ll) | |
2bfcf297 | 902 | #endif |
a4f6c312 | 903 | )); |
2bfcf297 DB |
904 | } |
905 | ||
906 | /* Return 1 is the operand is either a non-special register or a 32-bit | |
907 | signed constant integer valid for 64-bit subtraction. */ | |
908 | ||
909 | int | |
910 | reg_or_sub_cint64_operand (op, mode) | |
592696dd | 911 | rtx op; |
2bfcf297 DB |
912 | enum machine_mode mode; |
913 | { | |
a4f6c312 SS |
914 | return (gpc_reg_operand (op, mode) |
915 | || (GET_CODE (op) == CONST_INT | |
916 | && (- INTVAL (op)) < 0x7fff8000 | |
2bfcf297 | 917 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
918 | && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000) |
919 | < 0x100000000ll) | |
2bfcf297 | 920 | #endif |
a4f6c312 | 921 | )); |
2bfcf297 DB |
922 | } |
923 | ||
9ebbca7d GK |
924 | /* Return 1 is the operand is either a non-special register or ANY |
925 | 32-bit unsigned constant integer. */ | |
926 | ||
927 | int | |
1d328b19 | 928 | reg_or_logical_cint_operand (op, mode) |
592696dd | 929 | rtx op; |
9ebbca7d GK |
930 | enum machine_mode mode; |
931 | { | |
1d328b19 GK |
932 | if (GET_CODE (op) == CONST_INT) |
933 | { | |
934 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
935 | { | |
936 | if (GET_MODE_BITSIZE (mode) <= 32) | |
a4f6c312 | 937 | abort (); |
1d328b19 GK |
938 | |
939 | if (INTVAL (op) < 0) | |
940 | return 0; | |
941 | } | |
942 | ||
943 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 944 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
945 | } |
946 | else if (GET_CODE (op) == CONST_DOUBLE) | |
947 | { | |
948 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
949 | || mode != DImode) | |
a4f6c312 | 950 | abort (); |
1d328b19 GK |
951 | |
952 | return CONST_DOUBLE_HIGH (op) == 0; | |
953 | } | |
954 | else | |
955 | return gpc_reg_operand (op, mode); | |
9ebbca7d GK |
956 | } |
957 | ||
51d3e7d6 | 958 | /* Return 1 if the operand is an operand that can be loaded via the GOT. */ |
766a866c MM |
959 | |
960 | int | |
961 | got_operand (op, mode) | |
592696dd | 962 | rtx op; |
296b8152 | 963 | enum machine_mode mode ATTRIBUTE_UNUSED; |
766a866c MM |
964 | { |
965 | return (GET_CODE (op) == SYMBOL_REF | |
966 | || GET_CODE (op) == CONST | |
967 | || GET_CODE (op) == LABEL_REF); | |
968 | } | |
969 | ||
38c1f2d7 MM |
970 | /* Return 1 if the operand is a simple references that can be loaded via |
971 | the GOT (labels involving addition aren't allowed). */ | |
972 | ||
973 | int | |
974 | got_no_const_operand (op, mode) | |
592696dd | 975 | rtx op; |
296b8152 | 976 | enum machine_mode mode ATTRIBUTE_UNUSED; |
38c1f2d7 MM |
977 | { |
978 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
979 | } | |
980 | ||
4e74d8ec MM |
981 | /* Return the number of instructions it takes to form a constant in an |
982 | integer register. */ | |
983 | ||
984 | static int | |
985 | num_insns_constant_wide (value) | |
986 | HOST_WIDE_INT value; | |
987 | { | |
988 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 989 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
990 | return 1; |
991 | ||
4e74d8ec | 992 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 993 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
994 | return 1; |
995 | ||
5f59ecb7 | 996 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 997 | else if (TARGET_POWERPC64) |
4e74d8ec | 998 | { |
0d30d435 | 999 | HOST_WIDE_INT low = value & 0xffffffff; |
4e74d8ec MM |
1000 | HOST_WIDE_INT high = value >> 32; |
1001 | ||
0d30d435 DE |
1002 | low = (low ^ 0x80000000) - 0x80000000; /* sign extend */ |
1003 | ||
0858c623 | 1004 | if (high == 0 && (low & 0x80000000) == 0) |
4e74d8ec MM |
1005 | return 2; |
1006 | ||
0858c623 | 1007 | else if (high == -1 && (low & 0x80000000) != 0) |
4e74d8ec MM |
1008 | return 2; |
1009 | ||
c81fc13e | 1010 | else if (! low) |
4e74d8ec MM |
1011 | return num_insns_constant_wide (high) + 1; |
1012 | ||
1013 | else | |
1014 | return (num_insns_constant_wide (high) | |
e396202a | 1015 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
1016 | } |
1017 | #endif | |
1018 | ||
1019 | else | |
1020 | return 2; | |
1021 | } | |
1022 | ||
1023 | int | |
1024 | num_insns_constant (op, mode) | |
1025 | rtx op; | |
1026 | enum machine_mode mode; | |
1027 | { | |
4e74d8ec | 1028 | if (GET_CODE (op) == CONST_INT) |
0d30d435 DE |
1029 | { |
1030 | #if HOST_BITS_PER_WIDE_INT == 64 | |
4e2c1c44 DE |
1031 | if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1 |
1032 | && mask64_operand (op, mode)) | |
0d30d435 DE |
1033 | return 2; |
1034 | else | |
1035 | #endif | |
1036 | return num_insns_constant_wide (INTVAL (op)); | |
1037 | } | |
4e74d8ec | 1038 | |
6fc48950 MM |
1039 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
1040 | { | |
1041 | long l; | |
1042 | REAL_VALUE_TYPE rv; | |
1043 | ||
1044 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1045 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
1046 | return num_insns_constant_wide ((HOST_WIDE_INT)l); | |
1047 | } | |
1048 | ||
47ad8c61 | 1049 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 1050 | { |
47ad8c61 MM |
1051 | HOST_WIDE_INT low; |
1052 | HOST_WIDE_INT high; | |
1053 | long l[2]; | |
1054 | REAL_VALUE_TYPE rv; | |
1055 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 1056 | |
47ad8c61 MM |
1057 | if (mode == VOIDmode || mode == DImode) |
1058 | { | |
1059 | high = CONST_DOUBLE_HIGH (op); | |
1060 | low = CONST_DOUBLE_LOW (op); | |
1061 | } | |
1062 | else | |
1063 | { | |
1064 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1065 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
1066 | high = l[endian]; | |
1067 | low = l[1 - endian]; | |
1068 | } | |
4e74d8ec | 1069 | |
47ad8c61 MM |
1070 | if (TARGET_32BIT) |
1071 | return (num_insns_constant_wide (low) | |
1072 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
1073 | |
1074 | else | |
47ad8c61 | 1075 | { |
0858c623 | 1076 | if (high == 0 && (low & 0x80000000) == 0) |
47ad8c61 MM |
1077 | return num_insns_constant_wide (low); |
1078 | ||
0858c623 | 1079 | else if (high == -1 && (low & 0x80000000) != 0) |
47ad8c61 MM |
1080 | return num_insns_constant_wide (low); |
1081 | ||
a260abc9 DE |
1082 | else if (mask64_operand (op, mode)) |
1083 | return 2; | |
1084 | ||
47ad8c61 MM |
1085 | else if (low == 0) |
1086 | return num_insns_constant_wide (high) + 1; | |
1087 | ||
1088 | else | |
1089 | return (num_insns_constant_wide (high) | |
1090 | + num_insns_constant_wide (low) + 1); | |
1091 | } | |
4e74d8ec MM |
1092 | } |
1093 | ||
1094 | else | |
1095 | abort (); | |
1096 | } | |
1097 | ||
a4f6c312 SS |
1098 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a |
1099 | register with one instruction per word. We only do this if we can | |
1100 | safely read CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
1101 | |
1102 | int | |
1103 | easy_fp_constant (op, mode) | |
592696dd SS |
1104 | rtx op; |
1105 | enum machine_mode mode; | |
9878760c | 1106 | { |
9878760c RK |
1107 | if (GET_CODE (op) != CONST_DOUBLE |
1108 | || GET_MODE (op) != mode | |
4e74d8ec | 1109 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
1110 | return 0; |
1111 | ||
a4f6c312 | 1112 | /* Consider all constants with -msoft-float to be easy. */ |
4e74d8ec | 1113 | if (TARGET_SOFT_FLOAT && mode != DImode) |
b6c9286a MM |
1114 | return 1; |
1115 | ||
a4f6c312 | 1116 | /* If we are using V.4 style PIC, consider all constants to be hard. */ |
f607bc57 | 1117 | if (flag_pic && DEFAULT_ABI == ABI_V4) |
a7273471 MM |
1118 | return 0; |
1119 | ||
5ae4759c | 1120 | #ifdef TARGET_RELOCATABLE |
a4f6c312 SS |
1121 | /* Similarly if we are using -mrelocatable, consider all constants |
1122 | to be hard. */ | |
5ae4759c MM |
1123 | if (TARGET_RELOCATABLE) |
1124 | return 0; | |
1125 | #endif | |
1126 | ||
042259f2 DE |
1127 | if (mode == DFmode) |
1128 | { | |
1129 | long k[2]; | |
1130 | REAL_VALUE_TYPE rv; | |
1131 | ||
1132 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1133 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 1134 | |
4e74d8ec MM |
1135 | return (num_insns_constant_wide ((HOST_WIDE_INT)k[0]) == 1 |
1136 | && num_insns_constant_wide ((HOST_WIDE_INT)k[1]) == 1); | |
042259f2 | 1137 | } |
4e74d8ec MM |
1138 | |
1139 | else if (mode == SFmode) | |
042259f2 DE |
1140 | { |
1141 | long l; | |
1142 | REAL_VALUE_TYPE rv; | |
1143 | ||
1144 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1145 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 1146 | |
4e74d8ec | 1147 | return num_insns_constant_wide (l) == 1; |
042259f2 | 1148 | } |
4e74d8ec | 1149 | |
a260abc9 | 1150 | else if (mode == DImode) |
c81fc13e | 1151 | return ((TARGET_POWERPC64 |
a260abc9 DE |
1152 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
1153 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 1154 | |
a9098fd0 GK |
1155 | else if (mode == SImode) |
1156 | return 1; | |
4e74d8ec MM |
1157 | else |
1158 | abort (); | |
9878760c | 1159 | } |
8f75773e | 1160 | |
50a0b056 GK |
1161 | /* Return 1 if the operand is 0.0. */ |
1162 | int | |
1163 | zero_fp_constant (op, mode) | |
592696dd SS |
1164 | rtx op; |
1165 | enum machine_mode mode; | |
50a0b056 GK |
1166 | { |
1167 | return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode); | |
1168 | } | |
1169 | ||
a4f6c312 SS |
1170 | /* Return 1 if the operand is in volatile memory. Note that during |
1171 | the RTL generation phase, memory_operand does not return TRUE for | |
b6c9286a MM |
1172 | volatile memory references. So this function allows us to |
1173 | recognize volatile references where its safe. */ | |
1174 | ||
1175 | int | |
1176 | volatile_mem_operand (op, mode) | |
592696dd | 1177 | rtx op; |
b6c9286a MM |
1178 | enum machine_mode mode; |
1179 | { | |
1180 | if (GET_CODE (op) != MEM) | |
1181 | return 0; | |
1182 | ||
1183 | if (!MEM_VOLATILE_P (op)) | |
1184 | return 0; | |
1185 | ||
1186 | if (mode != GET_MODE (op)) | |
1187 | return 0; | |
1188 | ||
1189 | if (reload_completed) | |
1190 | return memory_operand (op, mode); | |
1191 | ||
1192 | if (reload_in_progress) | |
1193 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
1194 | ||
1195 | return memory_address_p (mode, XEXP (op, 0)); | |
1196 | } | |
1197 | ||
97f6e72f | 1198 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
1199 | |
1200 | int | |
97f6e72f | 1201 | offsettable_mem_operand (op, mode) |
592696dd | 1202 | rtx op; |
914c2e77 RK |
1203 | enum machine_mode mode; |
1204 | { | |
97f6e72f | 1205 | return ((GET_CODE (op) == MEM) |
677a9668 | 1206 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 1207 | mode, XEXP (op, 0))); |
914c2e77 RK |
1208 | } |
1209 | ||
9878760c RK |
1210 | /* Return 1 if the operand is either an easy FP constant (see above) or |
1211 | memory. */ | |
1212 | ||
1213 | int | |
1214 | mem_or_easy_const_operand (op, mode) | |
592696dd | 1215 | rtx op; |
9878760c RK |
1216 | enum machine_mode mode; |
1217 | { | |
1218 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
1219 | } | |
1220 | ||
1221 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 1222 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
1223 | |
1224 | int | |
1225 | add_operand (op, mode) | |
592696dd | 1226 | rtx op; |
9878760c RK |
1227 | enum machine_mode mode; |
1228 | { | |
2bfcf297 DB |
1229 | if (GET_CODE (op) == CONST_INT) |
1230 | return (CONST_OK_FOR_LETTER_P (INTVAL(op), 'I') | |
1231 | || CONST_OK_FOR_LETTER_P (INTVAL(op), 'L')); | |
1232 | ||
1233 | return gpc_reg_operand (op, mode); | |
9878760c RK |
1234 | } |
1235 | ||
dcfedcd0 RK |
1236 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
1237 | ||
1238 | int | |
1239 | non_add_cint_operand (op, mode) | |
592696dd | 1240 | rtx op; |
296b8152 | 1241 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
1242 | { |
1243 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 1244 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000 |
38886f37 | 1245 | && ! CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); |
dcfedcd0 RK |
1246 | } |
1247 | ||
9878760c RK |
1248 | /* Return 1 if the operand is a non-special register or a constant that |
1249 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
1250 | ||
1251 | int | |
1252 | logical_operand (op, mode) | |
592696dd | 1253 | rtx op; |
9878760c RK |
1254 | enum machine_mode mode; |
1255 | { | |
40501e5f | 1256 | HOST_WIDE_INT opl, oph; |
1d328b19 | 1257 | |
dfbdccdb GK |
1258 | if (gpc_reg_operand (op, mode)) |
1259 | return 1; | |
1d328b19 | 1260 | |
dfbdccdb | 1261 | if (GET_CODE (op) == CONST_INT) |
40501e5f AM |
1262 | { |
1263 | opl = INTVAL (op) & GET_MODE_MASK (mode); | |
1264 | ||
1265 | #if HOST_BITS_PER_WIDE_INT <= 32 | |
1266 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0) | |
1267 | return 0; | |
1268 | #endif | |
1269 | } | |
dfbdccdb GK |
1270 | else if (GET_CODE (op) == CONST_DOUBLE) |
1271 | { | |
1d328b19 | 1272 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
40501e5f | 1273 | abort (); |
1d328b19 GK |
1274 | |
1275 | opl = CONST_DOUBLE_LOW (op); | |
1276 | oph = CONST_DOUBLE_HIGH (op); | |
40501e5f | 1277 | if (oph != 0) |
38886f37 | 1278 | return 0; |
dfbdccdb GK |
1279 | } |
1280 | else | |
1281 | return 0; | |
1d328b19 | 1282 | |
40501e5f AM |
1283 | return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 |
1284 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); | |
9878760c RK |
1285 | } |
1286 | ||
dcfedcd0 | 1287 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 1288 | above), but could be split into one. */ |
dcfedcd0 RK |
1289 | |
1290 | int | |
1291 | non_logical_cint_operand (op, mode) | |
592696dd | 1292 | rtx op; |
5f59ecb7 | 1293 | enum machine_mode mode; |
dcfedcd0 | 1294 | { |
dfbdccdb | 1295 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
1296 | && ! logical_operand (op, mode) |
1297 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
1298 | } |
1299 | ||
19ba8161 | 1300 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
1301 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
1302 | Reject all ones and all zeros, since these should have been optimized | |
1303 | away and confuse the making of MB and ME. */ | |
1304 | ||
1305 | int | |
19ba8161 | 1306 | mask_operand (op, mode) |
592696dd | 1307 | rtx op; |
19ba8161 | 1308 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 1309 | { |
02071907 | 1310 | HOST_WIDE_INT c, lsb; |
9878760c | 1311 | |
19ba8161 DE |
1312 | if (GET_CODE (op) != CONST_INT) |
1313 | return 0; | |
1314 | ||
1315 | c = INTVAL (op); | |
1316 | ||
c5059423 AM |
1317 | /* We don't change the number of transitions by inverting, |
1318 | so make sure we start with the LS bit zero. */ | |
1319 | if (c & 1) | |
1320 | c = ~c; | |
1321 | ||
1322 | /* Reject all zeros or all ones. */ | |
1323 | if (c == 0) | |
9878760c RK |
1324 | return 0; |
1325 | ||
c5059423 AM |
1326 | /* Find the first transition. */ |
1327 | lsb = c & -c; | |
1328 | ||
1329 | /* Invert to look for a second transition. */ | |
1330 | c = ~c; | |
9878760c | 1331 | |
c5059423 AM |
1332 | /* Erase first transition. */ |
1333 | c &= -lsb; | |
9878760c | 1334 | |
c5059423 AM |
1335 | /* Find the second transition (if any). */ |
1336 | lsb = c & -c; | |
1337 | ||
1338 | /* Match if all the bits above are 1's (or c is zero). */ | |
1339 | return c == -lsb; | |
9878760c RK |
1340 | } |
1341 | ||
a260abc9 DE |
1342 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
1343 | It is if there are no more than one 1->0 or 0->1 transitions. | |
1344 | Reject all ones and all zeros, since these should have been optimized | |
1345 | away and confuse the making of MB and ME. */ | |
9878760c RK |
1346 | |
1347 | int | |
a260abc9 | 1348 | mask64_operand (op, mode) |
592696dd | 1349 | rtx op; |
a260abc9 DE |
1350 | enum machine_mode mode; |
1351 | { | |
1352 | if (GET_CODE (op) == CONST_INT) | |
1353 | { | |
02071907 | 1354 | HOST_WIDE_INT c, lsb; |
a260abc9 | 1355 | |
c5059423 AM |
1356 | /* We don't change the number of transitions by inverting, |
1357 | so make sure we start with the LS bit zero. */ | |
1358 | c = INTVAL (op); | |
1359 | if (c & 1) | |
1360 | c = ~c; | |
a260abc9 | 1361 | |
c5059423 AM |
1362 | /* Reject all zeros or all ones. */ |
1363 | if (c == 0) | |
e2c953b6 DE |
1364 | return 0; |
1365 | ||
c5059423 AM |
1366 | /* Find the transition, and check that all bits above are 1's. */ |
1367 | lsb = c & -c; | |
1368 | return c == -lsb; | |
e2c953b6 | 1369 | } |
a260abc9 DE |
1370 | else if (GET_CODE (op) == CONST_DOUBLE |
1371 | && (mode == VOIDmode || mode == DImode)) | |
1372 | { | |
02071907 | 1373 | HOST_WIDE_INT low, high, lsb; |
a260abc9 | 1374 | |
c5059423 AM |
1375 | if (HOST_BITS_PER_WIDE_INT < 64) |
1376 | high = CONST_DOUBLE_HIGH (op); | |
a260abc9 | 1377 | |
c5059423 AM |
1378 | low = CONST_DOUBLE_LOW (op); |
1379 | if (low & 1) | |
1380 | { | |
1381 | if (HOST_BITS_PER_WIDE_INT < 64) | |
1382 | high = ~high; | |
1383 | low = ~low; | |
1384 | } | |
a260abc9 | 1385 | |
c5059423 AM |
1386 | if (low == 0) |
1387 | { | |
1388 | if (HOST_BITS_PER_WIDE_INT >= 64 || high == 0) | |
1389 | return 0; | |
a260abc9 | 1390 | |
c5059423 AM |
1391 | lsb = high & -high; |
1392 | return high == -lsb; | |
1393 | } | |
a260abc9 | 1394 | |
c5059423 AM |
1395 | lsb = low & -low; |
1396 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
a260abc9 DE |
1397 | } |
1398 | else | |
1399 | return 0; | |
1400 | } | |
1401 | ||
1402 | /* Return 1 if the operand is either a non-special register or a constant | |
1403 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
1404 | ||
1405 | int | |
1406 | and64_operand (op, mode) | |
592696dd | 1407 | rtx op; |
9878760c RK |
1408 | enum machine_mode mode; |
1409 | { | |
a4f6c312 | 1410 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
1411 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
1412 | ||
1413 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
1414 | } |
1415 | ||
a260abc9 DE |
1416 | /* Return 1 if the operand is either a non-special register or a |
1417 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
1418 | |
1419 | int | |
a260abc9 | 1420 | and_operand (op, mode) |
592696dd | 1421 | rtx op; |
a260abc9 | 1422 | enum machine_mode mode; |
dcfedcd0 | 1423 | { |
a4f6c312 | 1424 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
1425 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
1426 | ||
1427 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
1428 | } |
1429 | ||
9878760c RK |
1430 | /* Return 1 if the operand is a general register or memory operand. */ |
1431 | ||
1432 | int | |
1433 | reg_or_mem_operand (op, mode) | |
592696dd SS |
1434 | rtx op; |
1435 | enum machine_mode mode; | |
9878760c | 1436 | { |
b6c9286a MM |
1437 | return (gpc_reg_operand (op, mode) |
1438 | || memory_operand (op, mode) | |
1439 | || volatile_mem_operand (op, mode)); | |
9878760c RK |
1440 | } |
1441 | ||
a7a813f7 | 1442 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 1443 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
1444 | instruction. */ |
1445 | ||
1446 | int | |
1447 | lwa_operand (op, mode) | |
592696dd SS |
1448 | rtx op; |
1449 | enum machine_mode mode; | |
a7a813f7 RK |
1450 | { |
1451 | rtx inner = op; | |
1452 | ||
1453 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
1454 | inner = SUBREG_REG (inner); | |
1455 | ||
1456 | return gpc_reg_operand (inner, mode) | |
1457 | || (memory_operand (inner, mode) | |
1458 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
6a40a9d6 DE |
1459 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC |
1460 | && (GET_CODE (XEXP (inner, 0)) != PLUS | |
e903c96a DE |
1461 | || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT |
1462 | || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0)); | |
a7a813f7 RK |
1463 | } |
1464 | ||
9878760c RK |
1465 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
1466 | to CALL. This is a SYMBOL_REF or a pseudo-register, which will be | |
1467 | forced to lr. */ | |
1468 | ||
1469 | int | |
1470 | call_operand (op, mode) | |
592696dd | 1471 | rtx op; |
9878760c RK |
1472 | enum machine_mode mode; |
1473 | { | |
1474 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
1475 | return 0; | |
1476 | ||
1477 | return (GET_CODE (op) == SYMBOL_REF | |
1478 | || (GET_CODE (op) == REG && REGNO (op) >= FIRST_PSEUDO_REGISTER)); | |
1479 | } | |
1480 | ||
2af3d377 | 1481 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in |
a4f6c312 | 1482 | this file and the function is not weakly defined. */ |
2af3d377 RK |
1483 | |
1484 | int | |
1485 | current_file_function_operand (op, mode) | |
592696dd | 1486 | rtx op; |
296b8152 | 1487 | enum machine_mode mode ATTRIBUTE_UNUSED; |
2af3d377 RK |
1488 | { |
1489 | return (GET_CODE (op) == SYMBOL_REF | |
1490 | && (SYMBOL_REF_FLAG (op) | |
8f1b829e | 1491 | || (op == XEXP (DECL_RTL (current_function_decl), 0) |
c81fc13e | 1492 | && ! DECL_WEAK (current_function_decl)))); |
2af3d377 RK |
1493 | } |
1494 | ||
9878760c RK |
1495 | /* Return 1 if this operand is a valid input for a move insn. */ |
1496 | ||
1497 | int | |
1498 | input_operand (op, mode) | |
592696dd | 1499 | rtx op; |
9878760c RK |
1500 | enum machine_mode mode; |
1501 | { | |
eb4e8003 | 1502 | /* Memory is always valid. */ |
9878760c RK |
1503 | if (memory_operand (op, mode)) |
1504 | return 1; | |
1505 | ||
34792e82 | 1506 | /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */ |
01b4cf2b | 1507 | if (GET_CODE (op) == CONSTANT_P_RTX) |
34792e82 JL |
1508 | return 1; |
1509 | ||
eb4e8003 RK |
1510 | /* For floating-point, easy constants are valid. */ |
1511 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
1512 | && CONSTANT_P (op) | |
1513 | && easy_fp_constant (op, mode)) | |
1514 | return 1; | |
1515 | ||
4e74d8ec MM |
1516 | /* Allow any integer constant. */ |
1517 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 1518 | && (GET_CODE (op) == CONST_INT |
e675f625 | 1519 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
1520 | return 1; |
1521 | ||
eb4e8003 RK |
1522 | /* For floating-point or multi-word mode, the only remaining valid type |
1523 | is a register. */ | |
9878760c RK |
1524 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
1525 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 1526 | return register_operand (op, mode); |
9878760c | 1527 | |
88fe15a1 RK |
1528 | /* The only cases left are integral modes one word or smaller (we |
1529 | do not get called for MODE_CC values). These can be in any | |
1530 | register. */ | |
1531 | if (register_operand (op, mode)) | |
a8b3aeda | 1532 | return 1; |
88fe15a1 | 1533 | |
84cf9dda | 1534 | /* A SYMBOL_REF referring to the TOC is valid. */ |
7fec4abd | 1535 | if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op)) |
84cf9dda RK |
1536 | return 1; |
1537 | ||
9ebbca7d GK |
1538 | /* A constant pool expression (relative to the TOC) is valid */ |
1539 | if (TOC_RELATIVE_EXPR_P (op)) | |
b6c9286a MM |
1540 | return 1; |
1541 | ||
88228c4b MM |
1542 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
1543 | to be valid. */ | |
f607bc57 | 1544 | if (DEFAULT_ABI == ABI_V4 |
88228c4b MM |
1545 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
1546 | && small_data_operand (op, Pmode)) | |
1547 | return 1; | |
1548 | ||
042259f2 | 1549 | return 0; |
9878760c | 1550 | } |
7509c759 | 1551 | |
a4f6c312 | 1552 | /* Return 1 for an operand in small memory on V.4/eabi. */ |
7509c759 MM |
1553 | |
1554 | int | |
1555 | small_data_operand (op, mode) | |
296b8152 KG |
1556 | rtx op ATTRIBUTE_UNUSED; |
1557 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
7509c759 | 1558 | { |
38c1f2d7 | 1559 | #if TARGET_ELF |
5f59ecb7 | 1560 | rtx sym_ref; |
7509c759 | 1561 | |
d9407988 | 1562 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 1563 | return 0; |
a54d04b7 | 1564 | |
f607bc57 | 1565 | if (DEFAULT_ABI != ABI_V4) |
7509c759 MM |
1566 | return 0; |
1567 | ||
88228c4b MM |
1568 | if (GET_CODE (op) == SYMBOL_REF) |
1569 | sym_ref = op; | |
1570 | ||
1571 | else if (GET_CODE (op) != CONST | |
1572 | || GET_CODE (XEXP (op, 0)) != PLUS | |
1573 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
1574 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
1575 | return 0; |
1576 | ||
88228c4b | 1577 | else |
dbf55e53 MM |
1578 | { |
1579 | rtx sum = XEXP (op, 0); | |
1580 | HOST_WIDE_INT summand; | |
1581 | ||
1582 | /* We have to be careful here, because it is the referenced address | |
1583 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
1584 | summand = INTVAL (XEXP (sum, 1)); | |
1585 | if (summand < 0 || summand > g_switch_value) | |
1586 | return 0; | |
1587 | ||
1588 | sym_ref = XEXP (sum, 0); | |
1589 | } | |
88228c4b MM |
1590 | |
1591 | if (*XSTR (sym_ref, 0) != '@') | |
7509c759 MM |
1592 | return 0; |
1593 | ||
1594 | return 1; | |
d9407988 MM |
1595 | |
1596 | #else | |
1597 | return 0; | |
1598 | #endif | |
7509c759 | 1599 | } |
9ebbca7d GK |
1600 | \f |
1601 | static int | |
1602 | constant_pool_expr_1 (op, have_sym, have_toc) | |
1603 | rtx op; | |
1604 | int *have_sym; | |
1605 | int *have_toc; | |
1606 | { | |
1607 | switch (GET_CODE(op)) | |
1608 | { | |
1609 | case SYMBOL_REF: | |
a4f6c312 SS |
1610 | if (CONSTANT_POOL_ADDRESS_P (op)) |
1611 | { | |
1612 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) | |
1613 | { | |
1614 | *have_sym = 1; | |
1615 | return 1; | |
1616 | } | |
1617 | else | |
1618 | return 0; | |
1619 | } | |
1620 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
1621 | { | |
1622 | *have_toc = 1; | |
1623 | return 1; | |
1624 | } | |
1625 | else | |
1626 | return 0; | |
9ebbca7d GK |
1627 | case PLUS: |
1628 | case MINUS: | |
a4f6c312 SS |
1629 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) && |
1630 | constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc); | |
9ebbca7d | 1631 | case CONST: |
a4f6c312 | 1632 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); |
9ebbca7d | 1633 | case CONST_INT: |
a4f6c312 | 1634 | return 1; |
9ebbca7d | 1635 | default: |
a4f6c312 | 1636 | return 0; |
9ebbca7d GK |
1637 | } |
1638 | } | |
1639 | ||
1640 | int | |
1641 | constant_pool_expr_p (op) | |
1642 | rtx op; | |
1643 | { | |
1644 | int have_sym = 0; | |
1645 | int have_toc = 0; | |
1646 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
1647 | } | |
1648 | ||
1649 | int | |
1650 | toc_relative_expr_p (op) | |
1651 | rtx op; | |
1652 | { | |
1653 | int have_sym = 0; | |
1654 | int have_toc = 0; | |
1655 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
1656 | } | |
1657 | ||
1658 | /* Try machine-dependent ways of modifying an illegitimate address | |
1659 | to be legitimate. If we find one, return the new, valid address. | |
1660 | This is used from only one place: `memory_address' in explow.c. | |
1661 | ||
a4f6c312 SS |
1662 | OLDX is the address as it was before break_out_memory_refs was |
1663 | called. In some cases it is useful to look at this to decide what | |
1664 | needs to be done. | |
9ebbca7d | 1665 | |
a4f6c312 | 1666 | MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS. |
9ebbca7d | 1667 | |
a4f6c312 SS |
1668 | It is always safe for this function to do nothing. It exists to |
1669 | recognize opportunities to optimize the output. | |
9ebbca7d GK |
1670 | |
1671 | On RS/6000, first check for the sum of a register with a constant | |
1672 | integer that is out of range. If so, generate code to add the | |
1673 | constant with the low-order 16 bits masked to the register and force | |
1674 | this result into another register (this can be done with `cau'). | |
1675 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
1676 | possibility of bit 16 being a one. | |
1677 | ||
1678 | Then check for the sum of a register and something not constant, try to | |
1679 | load the other things into a register and return the sum. */ | |
1680 | rtx | |
1681 | rs6000_legitimize_address (x, oldx, mode) | |
1682 | rtx x; | |
1683 | rtx oldx ATTRIBUTE_UNUSED; | |
1684 | enum machine_mode mode; | |
0ac081f6 | 1685 | { |
9ebbca7d GK |
1686 | if (GET_CODE (x) == PLUS |
1687 | && GET_CODE (XEXP (x, 0)) == REG | |
1688 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
1689 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
1690 | { | |
1691 | HOST_WIDE_INT high_int, low_int; | |
1692 | rtx sum; | |
1693 | high_int = INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff); | |
1694 | low_int = INTVAL (XEXP (x, 1)) & 0xffff; | |
1695 | if (low_int & 0x8000) | |
1696 | high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16; | |
1697 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
1698 | GEN_INT (high_int)), 0); | |
1699 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
1700 | } | |
1701 | else if (GET_CODE (x) == PLUS | |
1702 | && GET_CODE (XEXP (x, 0)) == REG | |
1703 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
6ac7bf2c | 1704 | && GET_MODE_NUNITS (mode) == 1 |
9ebbca7d GK |
1705 | && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode) |
1706 | && (TARGET_POWERPC64 || mode != DImode) | |
1707 | && mode != TImode) | |
1708 | { | |
1709 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
1710 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
1711 | } | |
0ac081f6 AH |
1712 | else if (ALTIVEC_VECTOR_MODE (mode)) |
1713 | { | |
1714 | rtx reg; | |
1715 | ||
1716 | /* Make sure both operands are registers. */ | |
1717 | if (GET_CODE (x) == PLUS) | |
9f85ed45 | 1718 | return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)), |
0ac081f6 AH |
1719 | force_reg (Pmode, XEXP (x, 1))); |
1720 | ||
1721 | reg = force_reg (Pmode, x); | |
1722 | return reg; | |
1723 | } | |
9ebbca7d GK |
1724 | else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic |
1725 | && GET_CODE (x) != CONST_INT | |
1726 | && GET_CODE (x) != CONST_DOUBLE | |
1727 | && CONSTANT_P (x) | |
6ac7bf2c GK |
1728 | && GET_MODE_NUNITS (mode) == 1 |
1729 | && (GET_MODE_BITSIZE (mode) <= 32 | |
c3bb62b9 | 1730 | || (TARGET_HARD_FLOAT && mode == DFmode))) |
9ebbca7d GK |
1731 | { |
1732 | rtx reg = gen_reg_rtx (Pmode); | |
1733 | emit_insn (gen_elf_high (reg, (x))); | |
1734 | return gen_rtx_LO_SUM (Pmode, reg, (x)); | |
1735 | } | |
ee890fe2 SS |
1736 | else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC |
1737 | && ! flag_pic | |
1738 | && GET_CODE (x) != CONST_INT | |
1739 | && GET_CODE (x) != CONST_DOUBLE | |
1740 | && CONSTANT_P (x) | |
1741 | && (TARGET_HARD_FLOAT || mode != DFmode) | |
1742 | && mode != DImode | |
1743 | && mode != TImode) | |
1744 | { | |
1745 | rtx reg = gen_reg_rtx (Pmode); | |
1746 | emit_insn (gen_macho_high (reg, (x))); | |
1747 | return gen_rtx_LO_SUM (Pmode, reg, (x)); | |
1748 | } | |
9ebbca7d GK |
1749 | else if (TARGET_TOC |
1750 | && CONSTANT_POOL_EXPR_P (x) | |
a9098fd0 | 1751 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
1752 | { |
1753 | return create_TOC_reference (x); | |
1754 | } | |
1755 | else | |
1756 | return NULL_RTX; | |
1757 | } | |
258bfae2 FS |
1758 | |
1759 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression | |
1760 | that is a valid memory address for an instruction. | |
1761 | The MODE argument is the machine mode for the MEM expression | |
1762 | that wants to use this address. | |
1763 | ||
1764 | On the RS/6000, there are four valid address: a SYMBOL_REF that | |
1765 | refers to a constant pool entry of an address (or the sum of it | |
1766 | plus a constant), a short (16-bit signed) constant plus a register, | |
1767 | the sum of two registers, or a register indirect, possibly with an | |
1768 | auto-increment. For DFmode and DImode with an constant plus register, | |
1769 | we must ensure that both words are addressable or PowerPC64 with offset | |
1770 | word aligned. | |
1771 | ||
1772 | For modes spanning multiple registers (DFmode in 32-bit GPRs, | |
1773 | 32-bit DImode, TImode), indexed addressing cannot be used because | |
1774 | adjacent memory cells are accessed by adding word-sized offsets | |
1775 | during assembly output. */ | |
1776 | int | |
1777 | rs6000_legitimate_address (mode, x, reg_ok_strict) | |
1778 | enum machine_mode mode; | |
1779 | rtx x; | |
1780 | int reg_ok_strict; | |
1781 | { | |
1782 | if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict)) | |
1783 | return 1; | |
1784 | if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) | |
1785 | && TARGET_UPDATE | |
1786 | && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict)) | |
1787 | return 1; | |
1788 | if (LEGITIMATE_SMALL_DATA_P (mode, x)) | |
1789 | return 1; | |
1790 | if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x)) | |
1791 | return 1; | |
1792 | /* If not REG_OK_STRICT (before reload) let pass any stack offset. */ | |
1793 | if (! reg_ok_strict | |
1794 | && GET_CODE (x) == PLUS | |
1795 | && GET_CODE (XEXP (x, 0)) == REG | |
1796 | && XEXP (x, 0) == virtual_stack_vars_rtx | |
1797 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
1798 | return 1; | |
1799 | if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict)) | |
1800 | return 1; | |
1801 | if (mode != TImode | |
1802 | && (TARGET_HARD_FLOAT || TARGET_POWERPC64 || mode != DFmode) | |
1803 | && (TARGET_POWERPC64 || mode != DImode) | |
1804 | && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict)) | |
1805 | return 1; | |
1806 | if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict)) | |
1807 | return 1; | |
1808 | return 0; | |
1809 | } | |
fb4d4348 | 1810 | \f |
a4f6c312 SS |
1811 | /* Try to output insns to set TARGET equal to the constant C if it can |
1812 | be done in less than N insns. Do all computations in MODE. | |
1813 | Returns the place where the output has been placed if it can be | |
1814 | done and the insns have been emitted. If it would take more than N | |
1815 | insns, zero is returned and no insns and emitted. */ | |
2bfcf297 DB |
1816 | |
1817 | rtx | |
1818 | rs6000_emit_set_const (dest, mode, source, n) | |
1819 | rtx dest, source; | |
1820 | enum machine_mode mode; | |
1821 | int n ATTRIBUTE_UNUSED; | |
1822 | { | |
1823 | HOST_WIDE_INT c0, c1; | |
1824 | ||
1825 | if (mode == QImode || mode == HImode || mode == SImode) | |
1826 | { | |
1827 | if (dest == NULL) | |
1828 | dest = gen_reg_rtx (mode); | |
1829 | emit_insn (gen_rtx_SET (VOIDmode, dest, source)); | |
1830 | return dest; | |
1831 | } | |
1832 | ||
1833 | if (GET_CODE (source) == CONST_INT) | |
1834 | { | |
1835 | c0 = INTVAL (source); | |
1836 | c1 = -(c0 < 0); | |
1837 | } | |
1838 | else if (GET_CODE (source) == CONST_DOUBLE) | |
1839 | { | |
1840 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
1841 | c0 = CONST_DOUBLE_LOW (source); | |
1842 | c1 = -(c0 < 0); | |
1843 | #else | |
1844 | c0 = CONST_DOUBLE_LOW (source); | |
1845 | c1 = CONST_DOUBLE_HIGH (source); | |
1846 | #endif | |
1847 | } | |
1848 | else | |
a4f6c312 | 1849 | abort (); |
2bfcf297 DB |
1850 | |
1851 | return rs6000_emit_set_long_const (dest, c0, c1); | |
1852 | } | |
1853 | ||
1854 | /* Having failed to find a 3 insn sequence in rs6000_emit_set_const, | |
1855 | fall back to a straight forward decomposition. We do this to avoid | |
1856 | exponential run times encountered when looking for longer sequences | |
1857 | with rs6000_emit_set_const. */ | |
1858 | static rtx | |
1859 | rs6000_emit_set_long_const (dest, c1, c2) | |
1860 | rtx dest; | |
1861 | HOST_WIDE_INT c1, c2; | |
1862 | { | |
1863 | if (!TARGET_POWERPC64) | |
1864 | { | |
1865 | rtx operand1, operand2; | |
1866 | ||
1867 | operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0, | |
1868 | DImode); | |
1869 | operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, | |
1870 | DImode); | |
1871 | emit_move_insn (operand1, GEN_INT (c1)); | |
1872 | emit_move_insn (operand2, GEN_INT (c2)); | |
1873 | } | |
1874 | else | |
1875 | { | |
1876 | HOST_WIDE_INT d1, d2, d3, d4; | |
1877 | ||
1878 | /* Decompose the entire word */ | |
1879 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
1880 | if (c2 != -(c1 < 0)) | |
1881 | abort (); | |
1882 | d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000; | |
1883 | c1 -= d1; | |
1884 | d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
1885 | c1 = (c1 - d2) >> 32; | |
1886 | d3 = ((c1 & 0xffff) ^ 0x8000) - 0x8000; | |
1887 | c1 -= d3; | |
1888 | d4 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
1889 | if (c1 != d4) | |
1890 | abort (); | |
1891 | #else | |
1892 | d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000; | |
1893 | c1 -= d1; | |
1894 | d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
1895 | if (c1 != d2) | |
1896 | abort (); | |
1897 | c2 += (d2 < 0); | |
1898 | d3 = ((c2 & 0xffff) ^ 0x8000) - 0x8000; | |
1899 | c2 -= d3; | |
1900 | d4 = ((c2 & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
1901 | if (c2 != d4) | |
1902 | abort (); | |
1903 | #endif | |
1904 | ||
1905 | /* Construct the high word */ | |
40501e5f | 1906 | if (d4 != 0) |
2bfcf297 DB |
1907 | { |
1908 | emit_move_insn (dest, GEN_INT (d4)); | |
40501e5f | 1909 | if (d3 != 0) |
2bfcf297 DB |
1910 | emit_move_insn (dest, |
1911 | gen_rtx_PLUS (DImode, dest, GEN_INT (d3))); | |
1912 | } | |
1913 | else | |
1914 | emit_move_insn (dest, GEN_INT (d3)); | |
1915 | ||
1916 | /* Shift it into place */ | |
40501e5f AM |
1917 | if (d3 != 0 || d4 != 0) |
1918 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32))); | |
2bfcf297 DB |
1919 | |
1920 | /* Add in the low bits. */ | |
40501e5f | 1921 | if (d2 != 0) |
2bfcf297 | 1922 | emit_move_insn (dest, gen_rtx_PLUS (DImode, dest, GEN_INT (d2))); |
40501e5f | 1923 | if (d1 != 0) |
2bfcf297 DB |
1924 | emit_move_insn (dest, gen_rtx_PLUS (DImode, dest, GEN_INT (d1))); |
1925 | } | |
1926 | ||
1927 | return dest; | |
1928 | } | |
1929 | ||
fb4d4348 GK |
1930 | /* Emit a move from SOURCE to DEST in mode MODE. */ |
1931 | void | |
1932 | rs6000_emit_move (dest, source, mode) | |
1933 | rtx dest; | |
1934 | rtx source; | |
1935 | enum machine_mode mode; | |
1936 | { | |
1937 | rtx operands[2]; | |
1938 | operands[0] = dest; | |
1939 | operands[1] = source; | |
1940 | ||
1941 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ | |
1942 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
1943 | && ! FLOAT_MODE_P (mode) | |
1944 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
1945 | { | |
1946 | /* FIXME. This should never happen. */ | |
1947 | /* Since it seems that it does, do the safe thing and convert | |
1948 | to a CONST_INT. */ | |
1949 | operands[1] = | |
1950 | GEN_INT (trunc_int_for_mode (CONST_DOUBLE_LOW (operands[1]), mode)); | |
1951 | } | |
1952 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
1953 | && ! FLOAT_MODE_P (mode) | |
1954 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
1955 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
1956 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
1957 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
1958 | abort (); | |
c9e8cb32 DD |
1959 | |
1960 | /* Check if GCC is setting up a block move that will end up using FP | |
1961 | registers as temporaries. We must make sure this is acceptable. */ | |
1962 | if (GET_CODE (operands[0]) == MEM | |
1963 | && GET_CODE (operands[1]) == MEM | |
1964 | && mode == DImode | |
41543739 GK |
1965 | && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0])) |
1966 | || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1]))) | |
1967 | && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32 | |
1968 | ? 32 : MEM_ALIGN (operands[0]))) | |
1969 | || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32 | |
1970 | ? 32 | |
1971 | : MEM_ALIGN (operands[1])))) | |
1972 | && ! MEM_VOLATILE_P (operands [0]) | |
1973 | && ! MEM_VOLATILE_P (operands [1])) | |
c9e8cb32 | 1974 | { |
41543739 GK |
1975 | emit_move_insn (adjust_address (operands[0], SImode, 0), |
1976 | adjust_address (operands[1], SImode, 0)); | |
1977 | emit_move_insn (adjust_address (operands[0], SImode, 4), | |
1978 | adjust_address (operands[1], SImode, 4)); | |
c9e8cb32 DD |
1979 | return; |
1980 | } | |
fb4d4348 GK |
1981 | |
1982 | if (! no_new_pseudos && GET_CODE (operands[0]) != REG) | |
1983 | operands[1] = force_reg (mode, operands[1]); | |
a9098fd0 | 1984 | |
ffc14f31 GK |
1985 | if (mode == SFmode && ! TARGET_POWERPC && TARGET_HARD_FLOAT |
1986 | && GET_CODE (operands[0]) == MEM) | |
fb4d4348 | 1987 | { |
ffc14f31 GK |
1988 | int regnum; |
1989 | ||
1990 | if (reload_in_progress || reload_completed) | |
1991 | regnum = true_regnum (operands[1]); | |
1992 | else if (GET_CODE (operands[1]) == REG) | |
1993 | regnum = REGNO (operands[1]); | |
1994 | else | |
1995 | regnum = -1; | |
fb4d4348 GK |
1996 | |
1997 | /* If operands[1] is a register, on POWER it may have | |
1998 | double-precision data in it, so truncate it to single | |
1999 | precision. */ | |
2000 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
2001 | { | |
2002 | rtx newreg; | |
2003 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
2004 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
2005 | operands[1] = newreg; | |
2006 | } | |
2007 | } | |
2008 | ||
a9098fd0 GK |
2009 | /* Handle the case where reload calls us with an invalid address; |
2010 | and the case of CONSTANT_P_RTX. */ | |
2011 | if (! general_operand (operands[1], mode) | |
2012 | || ! nonimmediate_operand (operands[0], mode) | |
2013 | || GET_CODE (operands[1]) == CONSTANT_P_RTX) | |
fb4d4348 GK |
2014 | { |
2015 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
2016 | return; | |
2017 | } | |
a9098fd0 | 2018 | |
fb4d4348 GK |
2019 | /* FIXME: In the long term, this switch statement should go away |
2020 | and be replaced by a sequence of tests based on things like | |
2021 | mode == Pmode. */ | |
2022 | switch (mode) | |
2023 | { | |
2024 | case HImode: | |
2025 | case QImode: | |
2026 | if (CONSTANT_P (operands[1]) | |
2027 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 2028 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
2029 | break; |
2030 | ||
06f4e019 | 2031 | case TFmode: |
fb4d4348 GK |
2032 | case DFmode: |
2033 | case SFmode: | |
2034 | if (CONSTANT_P (operands[1]) | |
2035 | && ! easy_fp_constant (operands[1], mode)) | |
a9098fd0 | 2036 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
2037 | break; |
2038 | ||
0ac081f6 AH |
2039 | case V16QImode: |
2040 | case V8HImode: | |
2041 | case V4SFmode: | |
2042 | case V4SImode: | |
2043 | /* fixme: aldyh -- allow vector constants when they are implemented. */ | |
2044 | if (CONSTANT_P (operands[1])) | |
2045 | operands[1] = force_const_mem (mode, operands[1]); | |
2046 | break; | |
2047 | ||
fb4d4348 | 2048 | case SImode: |
a9098fd0 | 2049 | case DImode: |
fb4d4348 GK |
2050 | /* Use default pattern for address of ELF small data */ |
2051 | if (TARGET_ELF | |
a9098fd0 | 2052 | && mode == Pmode |
f607bc57 | 2053 | && DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
2054 | && (GET_CODE (operands[1]) == SYMBOL_REF |
2055 | || GET_CODE (operands[1]) == CONST) | |
2056 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
2057 | { |
2058 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
2059 | return; | |
2060 | } | |
2061 | ||
f607bc57 | 2062 | if (DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
2063 | && mode == Pmode && mode == SImode |
2064 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
2065 | { |
2066 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
2067 | return; | |
2068 | } | |
2069 | ||
ee890fe2 SS |
2070 | if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN) |
2071 | && TARGET_NO_TOC && ! flag_pic | |
a9098fd0 | 2072 | && mode == Pmode |
fb4d4348 GK |
2073 | && CONSTANT_P (operands[1]) |
2074 | && GET_CODE (operands[1]) != HIGH | |
2075 | && GET_CODE (operands[1]) != CONST_INT) | |
2076 | { | |
a9098fd0 | 2077 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
2078 | |
2079 | /* If this is a function address on -mcall-aixdesc, | |
2080 | convert it to the address of the descriptor. */ | |
2081 | if (DEFAULT_ABI == ABI_AIX | |
2082 | && GET_CODE (operands[1]) == SYMBOL_REF | |
2083 | && XSTR (operands[1], 0)[0] == '.') | |
2084 | { | |
2085 | const char *name = XSTR (operands[1], 0); | |
2086 | rtx new_ref; | |
2087 | while (*name == '.') | |
2088 | name++; | |
2089 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
2090 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
2091 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
2092 | SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]); | |
2093 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); | |
2094 | operands[1] = new_ref; | |
2095 | } | |
7509c759 | 2096 | |
ee890fe2 SS |
2097 | if (DEFAULT_ABI == ABI_DARWIN) |
2098 | { | |
2099 | emit_insn (gen_macho_high (target, operands[1])); | |
2100 | emit_insn (gen_macho_low (operands[0], target, operands[1])); | |
2101 | return; | |
2102 | } | |
2103 | ||
fb4d4348 GK |
2104 | emit_insn (gen_elf_high (target, operands[1])); |
2105 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
2106 | return; | |
2107 | } | |
2108 | ||
a9098fd0 GK |
2109 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
2110 | and we have put it in the TOC, we just need to make a TOC-relative | |
2111 | reference to it. */ | |
2112 | if (TARGET_TOC | |
2113 | && GET_CODE (operands[1]) == SYMBOL_REF | |
2114 | && CONSTANT_POOL_EXPR_P (operands[1]) | |
2115 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), | |
2116 | get_pool_mode (operands[1]))) | |
fb4d4348 | 2117 | { |
a9098fd0 | 2118 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 2119 | } |
a9098fd0 GK |
2120 | else if (mode == Pmode |
2121 | && CONSTANT_P (operands[1]) | |
38886f37 AO |
2122 | && ((GET_CODE (operands[1]) != CONST_INT |
2123 | && ! easy_fp_constant (operands[1], mode)) | |
2124 | || (GET_CODE (operands[1]) == CONST_INT | |
2125 | && num_insns_constant (operands[1], mode) > 2) | |
2126 | || (GET_CODE (operands[0]) == REG | |
2127 | && FP_REGNO_P (REGNO (operands[0])))) | |
a9098fd0 GK |
2128 | && GET_CODE (operands[1]) != HIGH |
2129 | && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]) | |
2130 | && ! TOC_RELATIVE_EXPR_P (operands[1])) | |
fb4d4348 GK |
2131 | { |
2132 | /* Emit a USE operation so that the constant isn't deleted if | |
2133 | expensive optimizations are turned on because nobody | |
2134 | references it. This should only be done for operands that | |
2135 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
2136 | This should not be done for operands that contain LABEL_REFs. | |
2137 | For now, we just handle the obvious case. */ | |
2138 | if (GET_CODE (operands[1]) != LABEL_REF) | |
2139 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
2140 | ||
c859cda6 | 2141 | #if TARGET_MACHO |
ee890fe2 SS |
2142 | /* Darwin uses a special PIC legitimizer. */ |
2143 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic) | |
2144 | { | |
ee890fe2 SS |
2145 | operands[1] = |
2146 | rs6000_machopic_legitimize_pic_address (operands[1], mode, | |
c859cda6 DJ |
2147 | operands[0]); |
2148 | if (operands[0] != operands[1]) | |
2149 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
ee890fe2 SS |
2150 | return; |
2151 | } | |
c859cda6 | 2152 | #endif |
ee890fe2 | 2153 | |
fb4d4348 GK |
2154 | /* If we are to limit the number of things we put in the TOC and |
2155 | this is a symbol plus a constant we can add in one insn, | |
2156 | just put the symbol in the TOC and add the constant. Don't do | |
2157 | this if reload is in progress. */ | |
2158 | if (GET_CODE (operands[1]) == CONST | |
2159 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
2160 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 2161 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
2162 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
2163 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
2164 | && ! side_effects_p (operands[0])) | |
2165 | { | |
a4f6c312 SS |
2166 | rtx sym = |
2167 | force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); | |
fb4d4348 GK |
2168 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
2169 | ||
a9098fd0 GK |
2170 | sym = force_reg (mode, sym); |
2171 | if (mode == SImode) | |
2172 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
2173 | else | |
2174 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
2175 | return; |
2176 | } | |
2177 | ||
a9098fd0 | 2178 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
2179 | |
2180 | if (TARGET_TOC | |
d34c5b80 DE |
2181 | && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0)) |
2182 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P ( | |
2183 | get_pool_constant (XEXP (operands[1], 0)), | |
2184 | get_pool_mode (XEXP (operands[1], 0)))) | |
a9098fd0 | 2185 | { |
ba4828e0 RK |
2186 | operands[1] |
2187 | = gen_rtx_MEM (mode, | |
2188 | create_TOC_reference (XEXP (operands[1], 0))); | |
2189 | set_mem_alias_set (operands[1], get_TOC_alias_set ()); | |
fb4d4348 | 2190 | RTX_UNCHANGING_P (operands[1]) = 1; |
a9098fd0 | 2191 | } |
fb4d4348 GK |
2192 | } |
2193 | break; | |
a9098fd0 | 2194 | |
fb4d4348 GK |
2195 | case TImode: |
2196 | if (GET_CODE (operands[0]) == MEM | |
2197 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
2198 | && ! reload_in_progress) | |
792760b9 RK |
2199 | operands[0] |
2200 | = replace_equiv_address (operands[0], | |
2201 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
fb4d4348 GK |
2202 | |
2203 | if (GET_CODE (operands[1]) == MEM | |
2204 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
2205 | && ! reload_in_progress) | |
792760b9 RK |
2206 | operands[1] |
2207 | = replace_equiv_address (operands[1], | |
2208 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
fb4d4348 GK |
2209 | break; |
2210 | ||
2211 | default: | |
2212 | abort (); | |
2213 | } | |
2214 | ||
a9098fd0 GK |
2215 | /* Above, we may have called force_const_mem which may have returned |
2216 | an invalid address. If we can, fix this up; otherwise, reload will | |
2217 | have to deal with it. */ | |
2218 | if (GET_CODE (operands[1]) == MEM | |
2219 | && ! memory_address_p (mode, XEXP (operands[1], 0)) | |
2220 | && ! reload_in_progress) | |
f4ef873c | 2221 | operands[1] = adjust_address (operands[1], mode, 0); |
a9098fd0 | 2222 | |
fb4d4348 | 2223 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
02a4ec28 | 2224 | return; |
fb4d4348 | 2225 | } |
4697a36c MM |
2226 | \f |
2227 | /* Initialize a variable CUM of type CUMULATIVE_ARGS | |
2228 | for a call to a function whose data type is FNTYPE. | |
2229 | For a library call, FNTYPE is 0. | |
2230 | ||
2231 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 2232 | so we never return a PARALLEL. */ |
4697a36c MM |
2233 | |
2234 | void | |
2235 | init_cumulative_args (cum, fntype, libname, incoming) | |
2236 | CUMULATIVE_ARGS *cum; | |
2237 | tree fntype; | |
296b8152 | 2238 | rtx libname ATTRIBUTE_UNUSED; |
4697a36c MM |
2239 | int incoming; |
2240 | { | |
2241 | static CUMULATIVE_ARGS zero_cumulative; | |
2242 | ||
2243 | *cum = zero_cumulative; | |
2244 | cum->words = 0; | |
2245 | cum->fregno = FP_ARG_MIN_REG; | |
0ac081f6 | 2246 | cum->vregno = ALTIVEC_ARG_MIN_REG; |
4697a36c | 2247 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); |
7509c759 | 2248 | cum->call_cookie = CALL_NORMAL; |
4cc833b7 | 2249 | cum->sysv_gregno = GP_ARG_MIN_REG; |
4697a36c MM |
2250 | |
2251 | if (incoming) | |
bd227acc | 2252 | cum->nargs_prototype = 1000; /* don't return a PARALLEL */ |
4697a36c MM |
2253 | |
2254 | else if (cum->prototype) | |
2255 | cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1 | |
2256 | + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode | |
2257 | || RETURN_IN_MEMORY (TREE_TYPE (fntype)))); | |
2258 | ||
2259 | else | |
2260 | cum->nargs_prototype = 0; | |
2261 | ||
2262 | cum->orig_nargs = cum->nargs_prototype; | |
7509c759 | 2263 | |
9ebbca7d GK |
2264 | /* Check for longcall's */ |
2265 | if (fntype && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
2266 | cum->call_cookie = CALL_LONG; |
2267 | ||
4697a36c MM |
2268 | if (TARGET_DEBUG_ARG) |
2269 | { | |
2270 | fprintf (stderr, "\ninit_cumulative_args:"); | |
2271 | if (fntype) | |
2272 | { | |
2273 | tree ret_type = TREE_TYPE (fntype); | |
2274 | fprintf (stderr, " ret code = %s,", | |
2275 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
2276 | } | |
2277 | ||
6a4cee5f MM |
2278 | if (cum->call_cookie & CALL_LONG) |
2279 | fprintf (stderr, " longcall,"); | |
2280 | ||
4697a36c MM |
2281 | fprintf (stderr, " proto = %d, nargs = %d\n", |
2282 | cum->prototype, cum->nargs_prototype); | |
2283 | } | |
2284 | } | |
2285 | \f | |
c229cba9 DE |
2286 | /* If defined, a C expression which determines whether, and in which |
2287 | direction, to pad out an argument with extra space. The value | |
2288 | should be of type `enum direction': either `upward' to pad above | |
2289 | the argument, `downward' to pad below, or `none' to inhibit | |
2290 | padding. | |
2291 | ||
2292 | For the AIX ABI structs are always stored left shifted in their | |
2293 | argument slot. */ | |
2294 | ||
9ebbca7d | 2295 | enum direction |
c229cba9 DE |
2296 | function_arg_padding (mode, type) |
2297 | enum machine_mode mode; | |
2298 | tree type; | |
2299 | { | |
c85f7c16 | 2300 | if (type != 0 && AGGREGATE_TYPE_P (type)) |
9ebbca7d | 2301 | return upward; |
c229cba9 DE |
2302 | |
2303 | /* This is the default definition. */ | |
2304 | return (! BYTES_BIG_ENDIAN | |
9ebbca7d | 2305 | ? upward |
c229cba9 DE |
2306 | : ((mode == BLKmode |
2307 | ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST | |
2308 | && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT)) | |
2309 | : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY) | |
9ebbca7d | 2310 | ? downward : upward)); |
c229cba9 DE |
2311 | } |
2312 | ||
b6c9286a MM |
2313 | /* If defined, a C expression that gives the alignment boundary, in bits, |
2314 | of an argument with the specified mode and type. If it is not defined, | |
2315 | PARM_BOUNDARY is used for all arguments. | |
2316 | ||
2310f99a | 2317 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
2318 | |
2319 | int | |
2320 | function_arg_boundary (mode, type) | |
2321 | enum machine_mode mode; | |
9ebbca7d | 2322 | tree type ATTRIBUTE_UNUSED; |
b6c9286a | 2323 | { |
f607bc57 | 2324 | if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode)) |
e1f83b4d | 2325 | return 64; |
0ac081f6 AH |
2326 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
2327 | return 128; | |
9ebbca7d | 2328 | else |
b6c9286a | 2329 | return PARM_BOUNDARY; |
b6c9286a MM |
2330 | } |
2331 | \f | |
4697a36c MM |
2332 | /* Update the data in CUM to advance over an argument |
2333 | of mode MODE and data type TYPE. | |
2334 | (TYPE is null for libcalls where that information may not be available.) */ | |
2335 | ||
2336 | void | |
2337 | function_arg_advance (cum, mode, type, named) | |
2338 | CUMULATIVE_ARGS *cum; | |
2339 | enum machine_mode mode; | |
2340 | tree type; | |
2341 | int named; | |
2342 | { | |
2343 | cum->nargs_prototype--; | |
2344 | ||
0ac081f6 AH |
2345 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
2346 | { | |
2347 | if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0) | |
2348 | cum->vregno++; | |
2349 | else | |
2350 | cum->words += RS6000_ARG_SIZE (mode, type); | |
2351 | } | |
f607bc57 | 2352 | else if (DEFAULT_ABI == ABI_V4) |
4697a36c | 2353 | { |
4cc833b7 RH |
2354 | if (TARGET_HARD_FLOAT |
2355 | && (mode == SFmode || mode == DFmode)) | |
4697a36c | 2356 | { |
4cc833b7 RH |
2357 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
2358 | cum->fregno++; | |
2359 | else | |
2360 | { | |
2361 | if (mode == DFmode) | |
2362 | cum->words += cum->words & 1; | |
d34c5b80 | 2363 | cum->words += RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 2364 | } |
4697a36c | 2365 | } |
4cc833b7 RH |
2366 | else |
2367 | { | |
2368 | int n_words; | |
2369 | int gregno = cum->sysv_gregno; | |
2370 | ||
2371 | /* Aggregates and IEEE quad get passed by reference. */ | |
2372 | if ((type && AGGREGATE_TYPE_P (type)) | |
2373 | || mode == TFmode) | |
2374 | n_words = 1; | |
2375 | else | |
d34c5b80 | 2376 | n_words = RS6000_ARG_SIZE (mode, type); |
4cc833b7 RH |
2377 | |
2378 | /* Long long is put in odd registers. */ | |
2379 | if (n_words == 2 && (gregno & 1) == 0) | |
2380 | gregno += 1; | |
2381 | ||
2382 | /* Long long is not split between registers and stack. */ | |
2383 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) | |
2384 | { | |
2385 | /* Long long is aligned on the stack. */ | |
2386 | if (n_words == 2) | |
2387 | cum->words += cum->words & 1; | |
2388 | cum->words += n_words; | |
2389 | } | |
4697a36c | 2390 | |
4cc833b7 RH |
2391 | /* Note: continuing to accumulate gregno past when we've started |
2392 | spilling to the stack indicates the fact that we've started | |
2393 | spilling to the stack to expand_builtin_saveregs. */ | |
2394 | cum->sysv_gregno = gregno + n_words; | |
2395 | } | |
4697a36c | 2396 | |
4cc833b7 RH |
2397 | if (TARGET_DEBUG_ARG) |
2398 | { | |
2399 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
2400 | cum->words, cum->fregno); | |
2401 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
2402 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
2403 | fprintf (stderr, "mode = %4s, named = %d\n", | |
2404 | GET_MODE_NAME (mode), named); | |
2405 | } | |
4697a36c MM |
2406 | } |
2407 | else | |
4cc833b7 RH |
2408 | { |
2409 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
2410 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
a4f6c312 | 2411 | |
d34c5b80 | 2412 | cum->words += align + RS6000_ARG_SIZE (mode, type); |
4697a36c | 2413 | |
d34c5b80 DE |
2414 | if (GET_MODE_CLASS (mode) == MODE_FLOAT && TARGET_HARD_FLOAT) |
2415 | cum->fregno++; | |
4cc833b7 RH |
2416 | |
2417 | if (TARGET_DEBUG_ARG) | |
2418 | { | |
2419 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
2420 | cum->words, cum->fregno); | |
2421 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
2422 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
2423 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
2424 | } | |
2425 | } | |
4697a36c MM |
2426 | } |
2427 | \f | |
2428 | /* Determine where to put an argument to a function. | |
2429 | Value is zero to push the argument on the stack, | |
2430 | or a hard register in which to store the argument. | |
2431 | ||
2432 | MODE is the argument's machine mode. | |
2433 | TYPE is the data type of the argument (as a tree). | |
2434 | This is null for libcalls where that information may | |
2435 | not be available. | |
2436 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
2437 | the preceding args and about the function being called. | |
2438 | NAMED is nonzero if this argument is a named parameter | |
2439 | (otherwise it is an extra parameter matching an ellipsis). | |
2440 | ||
2441 | On RS/6000 the first eight words of non-FP are normally in registers | |
2442 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
2443 | Under V.4, the first 8 FP args are in registers. | |
2444 | ||
2445 | If this is floating-point and no prototype is specified, we use | |
2446 | both an FP and integer register (or possibly FP reg and stack). Library | |
2447 | functions (when TYPE is zero) always have the proper types for args, | |
2448 | so we can pass the FP value just in one register. emit_library_function | |
1c20ae99 | 2449 | doesn't support PARALLEL anyway. */ |
4697a36c MM |
2450 | |
2451 | struct rtx_def * | |
2452 | function_arg (cum, mode, type, named) | |
2453 | CUMULATIVE_ARGS *cum; | |
2454 | enum machine_mode mode; | |
2455 | tree type; | |
20c29ebe | 2456 | int named; |
4697a36c | 2457 | { |
4cc833b7 | 2458 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 2459 | |
a4f6c312 SS |
2460 | /* Return a marker to indicate whether CR1 needs to set or clear the |
2461 | bit that V.4 uses to say fp args were passed in registers. | |
2462 | Assume that we don't need the marker for software floating point, | |
2463 | or compiler generated library calls. */ | |
4697a36c MM |
2464 | if (mode == VOIDmode) |
2465 | { | |
f607bc57 | 2466 | if (abi == ABI_V4 |
7509c759 MM |
2467 | && TARGET_HARD_FLOAT |
2468 | && cum->nargs_prototype < 0 | |
4697a36c | 2469 | && type && (cum->prototype || TARGET_NO_PROTOTYPE)) |
7509c759 | 2470 | { |
6a4cee5f MM |
2471 | return GEN_INT (cum->call_cookie |
2472 | | ((cum->fregno == FP_ARG_MIN_REG) | |
2473 | ? CALL_V4_SET_FP_ARGS | |
2474 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 2475 | } |
4697a36c | 2476 | |
7509c759 | 2477 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
2478 | } |
2479 | ||
0ac081f6 AH |
2480 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
2481 | { | |
20c29ebe | 2482 | if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG) |
0ac081f6 AH |
2483 | return gen_rtx_REG (mode, cum->vregno); |
2484 | else | |
2485 | return NULL; | |
2486 | } | |
f607bc57 | 2487 | else if (abi == ABI_V4) |
4697a36c | 2488 | { |
4cc833b7 RH |
2489 | if (TARGET_HARD_FLOAT |
2490 | && (mode == SFmode || mode == DFmode)) | |
2491 | { | |
2492 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
2493 | return gen_rtx_REG (mode, cum->fregno); | |
2494 | else | |
2495 | return NULL; | |
2496 | } | |
2497 | else | |
2498 | { | |
2499 | int n_words; | |
2500 | int gregno = cum->sysv_gregno; | |
2501 | ||
2502 | /* Aggregates and IEEE quad get passed by reference. */ | |
2503 | if ((type && AGGREGATE_TYPE_P (type)) | |
2504 | || mode == TFmode) | |
2505 | n_words = 1; | |
2506 | else | |
d34c5b80 | 2507 | n_words = RS6000_ARG_SIZE (mode, type); |
4cc833b7 RH |
2508 | |
2509 | /* Long long is put in odd registers. */ | |
2510 | if (n_words == 2 && (gregno & 1) == 0) | |
2511 | gregno += 1; | |
2512 | ||
2513 | /* Long long is not split between registers and stack. */ | |
2514 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
2515 | return gen_rtx_REG (mode, gregno); | |
2516 | else | |
2517 | return NULL; | |
2518 | } | |
4697a36c | 2519 | } |
4cc833b7 RH |
2520 | else |
2521 | { | |
2522 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
2523 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
2524 | int align_words = cum->words + align; | |
4697a36c | 2525 | |
4cc833b7 RH |
2526 | if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
2527 | return NULL_RTX; | |
2528 | ||
2529 | if (USE_FP_FOR_ARG_P (*cum, mode, type)) | |
2530 | { | |
2531 | if (! type | |
2532 | || ((cum->nargs_prototype > 0) | |
2533 | /* IBM AIX extended its linkage convention definition always | |
2534 | to require FP args after register save area hole on the | |
2535 | stack. */ | |
2536 | && (DEFAULT_ABI != ABI_AIX | |
2537 | || ! TARGET_XL_CALL | |
2538 | || (align_words < GP_ARG_NUM_REG)))) | |
2539 | return gen_rtx_REG (mode, cum->fregno); | |
2540 | ||
2541 | return gen_rtx_PARALLEL (mode, | |
2542 | gen_rtvec (2, | |
39403d82 | 2543 | gen_rtx_EXPR_LIST (VOIDmode, |
1c20ae99 JW |
2544 | ((align_words >= GP_ARG_NUM_REG) |
2545 | ? NULL_RTX | |
2546 | : (align_words | |
d34c5b80 | 2547 | + RS6000_ARG_SIZE (mode, type) |
1c20ae99 JW |
2548 | > GP_ARG_NUM_REG |
2549 | /* If this is partially on the stack, then | |
2550 | we only include the portion actually | |
2551 | in registers here. */ | |
39403d82 | 2552 | ? gen_rtx_REG (SImode, |
1c20ae99 | 2553 | GP_ARG_MIN_REG + align_words) |
39403d82 | 2554 | : gen_rtx_REG (mode, |
1c20ae99 JW |
2555 | GP_ARG_MIN_REG + align_words))), |
2556 | const0_rtx), | |
39403d82 DE |
2557 | gen_rtx_EXPR_LIST (VOIDmode, |
2558 | gen_rtx_REG (mode, cum->fregno), | |
1c20ae99 | 2559 | const0_rtx))); |
4cc833b7 RH |
2560 | } |
2561 | else if (align_words < GP_ARG_NUM_REG) | |
2562 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
2563 | else | |
2564 | return NULL_RTX; | |
4697a36c | 2565 | } |
4697a36c MM |
2566 | } |
2567 | \f | |
2568 | /* For an arg passed partly in registers and partly in memory, | |
2569 | this is the number of registers used. | |
2570 | For args passed entirely in registers or entirely in memory, zero. */ | |
2571 | ||
2572 | int | |
2573 | function_arg_partial_nregs (cum, mode, type, named) | |
2574 | CUMULATIVE_ARGS *cum; | |
2575 | enum machine_mode mode; | |
2576 | tree type; | |
d34c5b80 | 2577 | int named ATTRIBUTE_UNUSED; |
4697a36c | 2578 | { |
f607bc57 | 2579 | if (DEFAULT_ABI == ABI_V4) |
4697a36c | 2580 | return 0; |
4697a36c | 2581 | |
0ac081f6 AH |
2582 | if (USE_FP_FOR_ARG_P (*cum, mode, type) |
2583 | || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type)) | |
4697a36c MM |
2584 | { |
2585 | if (cum->nargs_prototype >= 0) | |
2586 | return 0; | |
2587 | } | |
2588 | ||
2589 | if (cum->words < GP_ARG_NUM_REG | |
d34c5b80 | 2590 | && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type))) |
4697a36c MM |
2591 | { |
2592 | int ret = GP_ARG_NUM_REG - cum->words; | |
2593 | if (ret && TARGET_DEBUG_ARG) | |
2594 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
2595 | ||
2596 | return ret; | |
2597 | } | |
2598 | ||
2599 | return 0; | |
2600 | } | |
2601 | \f | |
2602 | /* A C expression that indicates when an argument must be passed by | |
2603 | reference. If nonzero for an argument, a copy of that argument is | |
2604 | made in memory and a pointer to the argument is passed instead of | |
2605 | the argument itself. The pointer is passed in whatever way is | |
2606 | appropriate for passing a pointer to that type. | |
2607 | ||
2608 | Under V.4, structures and unions are passed by reference. */ | |
2609 | ||
2610 | int | |
2611 | function_arg_pass_by_reference (cum, mode, type, named) | |
296b8152 KG |
2612 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; |
2613 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4697a36c | 2614 | tree type; |
296b8152 | 2615 | int named ATTRIBUTE_UNUSED; |
4697a36c | 2616 | { |
f607bc57 | 2617 | if (DEFAULT_ABI == ABI_V4 |
4cc833b7 RH |
2618 | && ((type && AGGREGATE_TYPE_P (type)) |
2619 | || mode == TFmode)) | |
4697a36c MM |
2620 | { |
2621 | if (TARGET_DEBUG_ARG) | |
2622 | fprintf (stderr, "function_arg_pass_by_reference: aggregate\n"); | |
2623 | ||
2624 | return 1; | |
2625 | } | |
4697a36c MM |
2626 | |
2627 | return 0; | |
2628 | } | |
4697a36c MM |
2629 | \f |
2630 | /* Perform any needed actions needed for a function that is receiving a | |
2631 | variable number of arguments. | |
2632 | ||
2633 | CUM is as above. | |
2634 | ||
2635 | MODE and TYPE are the mode and type of the current parameter. | |
2636 | ||
2637 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
2638 | that must be pushed by the prolog to pretend that our caller pushed | |
2639 | it. | |
2640 | ||
2641 | Normally, this macro will push all remaining incoming registers on the | |
2642 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
2643 | ||
2644 | void | |
2645 | setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl) | |
2646 | CUMULATIVE_ARGS *cum; | |
2647 | enum machine_mode mode; | |
2648 | tree type; | |
2649 | int *pretend_size; | |
2650 | int no_rtl; | |
2651 | ||
2652 | { | |
4cc833b7 RH |
2653 | CUMULATIVE_ARGS next_cum; |
2654 | int reg_size = TARGET_32BIT ? 4 : 8; | |
ca5adc63 | 2655 | rtx save_area = NULL_RTX, mem; |
dfafc897 | 2656 | int first_reg_offset, set; |
d34c5b80 DE |
2657 | tree fntype; |
2658 | int stdarg_p; | |
4697a36c | 2659 | |
d34c5b80 DE |
2660 | fntype = TREE_TYPE (current_function_decl); |
2661 | stdarg_p = (TYPE_ARG_TYPES (fntype) != 0 | |
2662 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
2663 | != void_type_node)); | |
4cc833b7 | 2664 | |
d34c5b80 DE |
2665 | /* For varargs, we do not want to skip the dummy va_dcl argument. |
2666 | For stdargs, we do want to skip the last named argument. */ | |
2667 | next_cum = *cum; | |
2668 | if (stdarg_p) | |
2669 | function_arg_advance (&next_cum, mode, type, 1); | |
4cc833b7 | 2670 | |
f607bc57 | 2671 | if (DEFAULT_ABI == ABI_V4) |
d34c5b80 | 2672 | { |
4cc833b7 RH |
2673 | /* Indicate to allocate space on the stack for varargs save area. */ |
2674 | /* ??? Does this really have to be located at a magic spot on the | |
2675 | stack, or can we allocate this with assign_stack_local instead. */ | |
00dba523 | 2676 | cfun->machine->sysv_varargs_p = 1; |
60e2d0ca | 2677 | if (! no_rtl) |
2c4974b7 | 2678 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 2679 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
2680 | |
2681 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 2682 | } |
60e2d0ca | 2683 | else |
4697a36c | 2684 | { |
d34c5b80 | 2685 | first_reg_offset = next_cum.words; |
4cc833b7 | 2686 | save_area = virtual_incoming_args_rtx; |
00dba523 | 2687 | cfun->machine->sysv_varargs_p = 0; |
4697a36c MM |
2688 | |
2689 | if (MUST_PASS_IN_STACK (mode, type)) | |
d34c5b80 | 2690 | first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type); |
4cc833b7 | 2691 | } |
4697a36c | 2692 | |
dfafc897 | 2693 | set = get_varargs_alias_set (); |
c81fc13e | 2694 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 2695 | { |
dfafc897 FS |
2696 | mem = gen_rtx_MEM (BLKmode, |
2697 | plus_constant (save_area, | |
2698 | first_reg_offset * reg_size)), | |
ba4828e0 | 2699 | set_mem_alias_set (mem, set); |
8ac61af7 | 2700 | set_mem_align (mem, BITS_PER_WORD); |
dfafc897 | 2701 | |
4cc833b7 | 2702 | move_block_from_reg |
dfafc897 | 2703 | (GP_ARG_MIN_REG + first_reg_offset, mem, |
4cc833b7 RH |
2704 | GP_ARG_NUM_REG - first_reg_offset, |
2705 | (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD); | |
2706 | ||
2707 | /* ??? Does ABI_V4 need this at all? */ | |
4697a36c MM |
2708 | *pretend_size = (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD; |
2709 | } | |
2710 | ||
4697a36c | 2711 | /* Save FP registers if needed. */ |
f607bc57 | 2712 | if (DEFAULT_ABI == ABI_V4 |
c81fc13e | 2713 | && TARGET_HARD_FLOAT && ! no_rtl |
4cc833b7 | 2714 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 2715 | { |
4cc833b7 | 2716 | int fregno = next_cum.fregno; |
9ebbca7d | 2717 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
2718 | rtx lab = gen_label_rtx (); |
2719 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 2720 | |
4cc833b7 | 2721 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 2722 | pc_rtx, |
39403d82 | 2723 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
2724 | gen_rtx_NE (VOIDmode, cr1, |
2725 | const0_rtx), | |
39403d82 | 2726 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
2727 | pc_rtx))); |
2728 | ||
4cc833b7 RH |
2729 | while (fregno <= FP_ARG_V4_MAX_REG) |
2730 | { | |
dfafc897 | 2731 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
ba4828e0 | 2732 | set_mem_alias_set (mem, set); |
dfafc897 | 2733 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); |
4cc833b7 RH |
2734 | fregno++; |
2735 | off += 8; | |
4697a36c | 2736 | } |
4cc833b7 RH |
2737 | |
2738 | emit_label (lab); | |
4697a36c | 2739 | } |
4697a36c | 2740 | } |
4697a36c | 2741 | |
dfafc897 | 2742 | /* Create the va_list data type. */ |
2c4974b7 | 2743 | |
dfafc897 FS |
2744 | tree |
2745 | rs6000_build_va_list () | |
2746 | { | |
bab45a51 | 2747 | tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl; |
4697a36c | 2748 | |
9ebbca7d GK |
2749 | /* For AIX, prefer 'char *' because that's what the system |
2750 | header files like. */ | |
f607bc57 | 2751 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d | 2752 | return build_pointer_type (char_type_node); |
dfafc897 | 2753 | |
0f4fd75d | 2754 | record = make_lang_type (RECORD_TYPE); |
bab45a51 | 2755 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 2756 | |
9ebbca7d GK |
2757 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
2758 | unsigned_char_type_node); | |
2759 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), | |
2760 | unsigned_char_type_node); | |
dfafc897 FS |
2761 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
2762 | ptr_type_node); | |
2763 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
2764 | ptr_type_node); | |
2765 | ||
2766 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
2767 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
2768 | DECL_FIELD_CONTEXT (f_ovf) = record; | |
2769 | DECL_FIELD_CONTEXT (f_sav) = record; | |
2770 | ||
bab45a51 FS |
2771 | TREE_CHAIN (record) = type_decl; |
2772 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
2773 | TYPE_FIELDS (record) = f_gpr; |
2774 | TREE_CHAIN (f_gpr) = f_fpr; | |
2775 | TREE_CHAIN (f_fpr) = f_ovf; | |
2776 | TREE_CHAIN (f_ovf) = f_sav; | |
2777 | ||
2778 | layout_type (record); | |
2779 | ||
2780 | /* The correct type is an array type of one element. */ | |
2781 | return build_array_type (record, build_index_type (size_zero_node)); | |
2782 | } | |
2783 | ||
2784 | /* Implement va_start. */ | |
2785 | ||
2786 | void | |
2787 | rs6000_va_start (stdarg_p, valist, nextarg) | |
2788 | int stdarg_p; | |
2789 | tree valist; | |
2790 | rtx nextarg; | |
4697a36c | 2791 | { |
dfafc897 FS |
2792 | HOST_WIDE_INT words, n_gpr, n_fpr; |
2793 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
2794 | tree gpr, fpr, ovf, sav, t; | |
2c4974b7 | 2795 | |
dfafc897 | 2796 | /* Only SVR4 needs something special. */ |
f607bc57 | 2797 | if (DEFAULT_ABI != ABI_V4) |
dfafc897 FS |
2798 | { |
2799 | std_expand_builtin_va_start (stdarg_p, valist, nextarg); | |
2800 | return; | |
2801 | } | |
2802 | ||
973a648b | 2803 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 FS |
2804 | f_fpr = TREE_CHAIN (f_gpr); |
2805 | f_ovf = TREE_CHAIN (f_fpr); | |
2806 | f_sav = TREE_CHAIN (f_ovf); | |
2807 | ||
8ebecc3b | 2808 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
2809 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
2810 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
2811 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
2812 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
2813 | ||
2814 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 2815 | words = current_function_args_info.words; |
dfafc897 FS |
2816 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
2817 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
2818 | ||
2819 | if (TARGET_DEBUG_ARG) | |
78e1b90d DE |
2820 | { |
2821 | fputs ("va_start: words = ", stderr); | |
2822 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words); | |
2823 | fputs (", n_gpr = ", stderr); | |
2824 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr); | |
2825 | fputs (", n_fpr = ", stderr); | |
2826 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr); | |
2827 | putc ('\n', stderr); | |
2828 | } | |
dfafc897 FS |
2829 | |
2830 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
2831 | TREE_SIDE_EFFECTS (t) = 1; | |
2832 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2833 | ||
2834 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
2835 | TREE_SIDE_EFFECTS (t) = 1; | |
2836 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2837 | ||
2838 | /* Find the overflow area. */ | |
2839 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
2840 | if (words != 0) | |
2841 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
2842 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
2843 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
2844 | TREE_SIDE_EFFECTS (t) = 1; | |
2845 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2846 | ||
2847 | /* Find the register save area. */ | |
2848 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
2849 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
2850 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
2851 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
2852 | TREE_SIDE_EFFECTS (t) = 1; | |
2853 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2854 | } | |
2855 | ||
2856 | /* Implement va_arg. */ | |
2857 | ||
2858 | rtx | |
2859 | rs6000_va_arg (valist, type) | |
2860 | tree valist, type; | |
2861 | { | |
2862 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
2863 | tree gpr, fpr, ovf, sav, reg, t, u; | |
2864 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
2865 | rtx lab_false, lab_over, addr_rtx, r; | |
2866 | ||
9ebbca7d GK |
2867 | /* For AIX, the rule is that structures are passed left-aligned in |
2868 | their stack slot. However, GCC does not presently do this: | |
2869 | structures which are the same size as integer types are passed | |
2870 | right-aligned, as if they were in fact integers. This only | |
2871 | matters for structures of size 1 or 2, or 4 when TARGET_64BIT. */ | |
f607bc57 | 2872 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d GK |
2873 | { |
2874 | HOST_WIDE_INT align, rounded_size; | |
2875 | enum machine_mode mode; | |
2876 | tree addr_tree; | |
2877 | ||
2878 | /* Compute the rounded size of the type. */ | |
2879 | align = PARM_BOUNDARY / BITS_PER_UNIT; | |
2880 | rounded_size = (((int_size_in_bytes (type) + align - 1) / align) | |
2881 | * align); | |
2882 | ||
2883 | addr_tree = valist; | |
2884 | ||
2885 | mode = TYPE_MODE (type); | |
2886 | if (mode != BLKmode) | |
2887 | { | |
2888 | HOST_WIDE_INT adj; | |
2889 | adj = TREE_INT_CST_LOW (TYPE_SIZE (type)) / BITS_PER_UNIT; | |
2890 | if (rounded_size > align) | |
2891 | adj = rounded_size; | |
2892 | ||
2893 | addr_tree = build (PLUS_EXPR, TREE_TYPE (addr_tree), addr_tree, | |
2894 | build_int_2 (rounded_size - adj, 0)); | |
2895 | } | |
2896 | ||
2897 | addr_rtx = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL); | |
2898 | addr_rtx = copy_to_reg (addr_rtx); | |
2899 | ||
2900 | /* Compute new value for AP. */ | |
2901 | t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, | |
2902 | build (PLUS_EXPR, TREE_TYPE (valist), valist, | |
2903 | build_int_2 (rounded_size, 0))); | |
2904 | TREE_SIDE_EFFECTS (t) = 1; | |
2905 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2906 | ||
2907 | return addr_rtx; | |
2908 | } | |
dfafc897 | 2909 | |
973a648b | 2910 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 FS |
2911 | f_fpr = TREE_CHAIN (f_gpr); |
2912 | f_ovf = TREE_CHAIN (f_fpr); | |
2913 | f_sav = TREE_CHAIN (f_ovf); | |
2914 | ||
8ebecc3b | 2915 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
2916 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
2917 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
2918 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
2919 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
2920 | ||
2921 | size = int_size_in_bytes (type); | |
2922 | rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
4cc833b7 | 2923 | |
dfafc897 | 2924 | if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode) |
4cc833b7 | 2925 | { |
dfafc897 FS |
2926 | /* Aggregates and long doubles are passed by reference. */ |
2927 | indirect_p = 1; | |
2928 | reg = gpr; | |
2929 | n_reg = 1; | |
2930 | sav_ofs = 0; | |
2931 | sav_scale = 4; | |
2932 | size = rsize = UNITS_PER_WORD; | |
2933 | } | |
2934 | else if (FLOAT_TYPE_P (type) && ! TARGET_SOFT_FLOAT) | |
2935 | { | |
2936 | /* FP args go in FP registers, if present. */ | |
2937 | indirect_p = 0; | |
2938 | reg = fpr; | |
2939 | n_reg = 1; | |
2940 | sav_ofs = 8*4; | |
2941 | sav_scale = 8; | |
4cc833b7 | 2942 | } |
dfafc897 FS |
2943 | else |
2944 | { | |
2945 | /* Otherwise into GP registers. */ | |
2946 | indirect_p = 0; | |
2947 | reg = gpr; | |
2948 | n_reg = rsize; | |
2949 | sav_ofs = 0; | |
2950 | sav_scale = 4; | |
2951 | } | |
2952 | ||
a4f6c312 | 2953 | /* Pull the value out of the saved registers ... */ |
dfafc897 FS |
2954 | |
2955 | lab_false = gen_label_rtx (); | |
2956 | lab_over = gen_label_rtx (); | |
2957 | addr_rtx = gen_reg_rtx (Pmode); | |
2958 | ||
2959 | emit_cmp_and_jump_insns (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL), | |
a06ef755 RK |
2960 | GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1, |
2961 | lab_false); | |
2c4974b7 | 2962 | |
dfafc897 FS |
2963 | /* Long long is aligned in the registers. */ |
2964 | if (n_reg > 1) | |
2c4974b7 | 2965 | { |
dfafc897 FS |
2966 | u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg, |
2967 | build_int_2 (n_reg - 1, 0)); | |
2968 | u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u); | |
2969 | u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u); | |
2970 | TREE_SIDE_EFFECTS (u) = 1; | |
2971 | expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2c4974b7 | 2972 | } |
dfafc897 FS |
2973 | |
2974 | if (sav_ofs) | |
2975 | t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
2c4974b7 | 2976 | else |
dfafc897 | 2977 | t = sav; |
2c4974b7 | 2978 | |
dfafc897 FS |
2979 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, build_int_2 (n_reg, 0)); |
2980 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 2981 | |
dfafc897 FS |
2982 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
2983 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 2984 | |
dfafc897 FS |
2985 | u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); |
2986 | TREE_SIDE_EFFECTS (u) = 1; | |
2987 | ||
2988 | t = build (PLUS_EXPR, ptr_type_node, t, u); | |
2989 | TREE_SIDE_EFFECTS (t) = 1; | |
2990 | ||
2991 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
2992 | if (r != addr_rtx) | |
2993 | emit_move_insn (addr_rtx, r); | |
2994 | ||
2995 | emit_jump_insn (gen_jump (lab_over)); | |
2996 | emit_barrier (); | |
2997 | emit_label (lab_false); | |
2998 | ||
a4f6c312 | 2999 | /* ... otherwise out of the overflow area. */ |
dfafc897 FS |
3000 | |
3001 | /* Make sure we don't find reg 7 for the next int arg. */ | |
3002 | if (n_reg > 1) | |
3003 | { | |
3004 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
3005 | TREE_SIDE_EFFECTS (t) = 1; | |
3006 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3007 | } | |
3008 | ||
3009 | /* Care for on-stack alignment if needed. */ | |
3010 | if (rsize <= 1) | |
3011 | t = ovf; | |
3012 | else | |
3013 | { | |
3014 | t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (7, 0)); | |
3015 | t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-8, -1)); | |
3016 | } | |
3017 | t = save_expr (t); | |
3018 | ||
3019 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
3020 | if (r != addr_rtx) | |
3021 | emit_move_insn (addr_rtx, r); | |
3022 | ||
3023 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
3024 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
3025 | TREE_SIDE_EFFECTS (t) = 1; | |
3026 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3027 | ||
3028 | emit_label (lab_over); | |
3029 | ||
3030 | if (indirect_p) | |
3031 | { | |
3032 | r = gen_rtx_MEM (Pmode, addr_rtx); | |
ba4828e0 | 3033 | set_mem_alias_set (r, get_varargs_alias_set ()); |
dfafc897 FS |
3034 | emit_move_insn (addr_rtx, r); |
3035 | } | |
3036 | ||
3037 | return addr_rtx; | |
4697a36c | 3038 | } |
0ac081f6 AH |
3039 | |
3040 | /* Builtins. */ | |
3041 | ||
3042 | #define def_builtin(MASK, NAME, TYPE, CODE) \ | |
3043 | do { \ | |
3044 | if ((MASK) & target_flags) \ | |
3045 | builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL); \ | |
3046 | } while (0) | |
3047 | ||
3048 | struct builtin_description | |
3049 | { | |
3050 | const unsigned int mask; | |
3051 | const enum insn_code icode; | |
3052 | const char *const name; | |
3053 | const enum rs6000_builtins code; | |
3054 | }; | |
2212663f DB |
3055 | /* Simple ternary operations: VECd = foo (VECa, VECb, VECc) */ |
3056 | static const struct builtin_description bdesc_3arg[] = | |
3057 | { | |
3058 | { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP }, | |
3059 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS }, | |
3060 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS }, | |
3061 | { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM}, | |
3062 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM }, | |
3063 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM }, | |
3064 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM }, | |
3065 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM }, | |
3066 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS }, | |
3067 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS }, | |
617e0e1d | 3068 | { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP }, |
2212663f DB |
3069 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF }, |
3070 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI }, | |
3071 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI }, | |
3072 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI }, | |
617e0e1d DB |
3073 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF }, |
3074 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI }, | |
3075 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI }, | |
3076 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI }, | |
2212663f DB |
3077 | }; |
3078 | ||
3079 | /* Simple binary operations: VECc = foo (VECa, VECb). */ | |
0ac081f6 AH |
3080 | static const struct builtin_description bdesc_2arg[] = |
3081 | { | |
f18c054f DB |
3082 | { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM }, |
3083 | { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM }, | |
3084 | { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM }, | |
3085 | { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP }, | |
0ac081f6 AH |
3086 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW }, |
3087 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS }, | |
3088 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS }, | |
3089 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS }, | |
3090 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS }, | |
3091 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS }, | |
3092 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS }, | |
f18c054f | 3093 | { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND }, |
0ac081f6 AH |
3094 | { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC }, |
3095 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB }, | |
3096 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB }, | |
3097 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH }, | |
3098 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH }, | |
3099 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW }, | |
3100 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW }, | |
617e0e1d DB |
3101 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX }, |
3102 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX }, | |
0ac081f6 AH |
3103 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP }, |
3104 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB }, | |
3105 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH }, | |
3106 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW }, | |
3107 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP }, | |
3108 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP }, | |
3109 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB }, | |
3110 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB }, | |
3111 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH }, | |
3112 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH }, | |
3113 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW }, | |
3114 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW }, | |
3115 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP }, | |
617e0e1d DB |
3116 | { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS }, |
3117 | { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS }, | |
f18c054f DB |
3118 | { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB }, |
3119 | { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB }, | |
3120 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH }, | |
3121 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH }, | |
3122 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW }, | |
3123 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW }, | |
3124 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP }, | |
0ac081f6 AH |
3125 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB }, |
3126 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH }, | |
3127 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW }, | |
3128 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB }, | |
3129 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH }, | |
3130 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW }, | |
f18c054f DB |
3131 | { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB }, |
3132 | { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB }, | |
3133 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH }, | |
3134 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH }, | |
3135 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW }, | |
3136 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW }, | |
3137 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP }, | |
0ac081f6 AH |
3138 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB }, |
3139 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB }, | |
3140 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH }, | |
3141 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH }, | |
3142 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB }, | |
3143 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB }, | |
3144 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH }, | |
3145 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH }, | |
3146 | { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR }, | |
f18c054f | 3147 | { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR }, |
0ac081f6 AH |
3148 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM }, |
3149 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM }, | |
3150 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX }, | |
3151 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS }, | |
3152 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS }, | |
3153 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS }, | |
3154 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS }, | |
3155 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS }, | |
3156 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS }, | |
3157 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS }, | |
3158 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS }, | |
3159 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB }, | |
3160 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH }, | |
3161 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW }, | |
3162 | { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB }, | |
3163 | { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH }, | |
3164 | { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW }, | |
3165 | { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL }, | |
3166 | { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO }, | |
2212663f DB |
3167 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB }, |
3168 | { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH }, | |
3169 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW }, | |
0ac081f6 | 3170 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB }, |
f18c054f DB |
3171 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH }, |
3172 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW }, | |
0ac081f6 AH |
3173 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB }, |
3174 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH }, | |
3175 | { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW }, | |
3176 | { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR }, | |
3177 | { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO }, | |
f18c054f DB |
3178 | { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM }, |
3179 | { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM }, | |
3180 | { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM }, | |
3181 | { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP }, | |
0ac081f6 AH |
3182 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW }, |
3183 | { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS }, | |
3184 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS }, | |
3185 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS }, | |
3186 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS }, | |
3187 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS }, | |
3188 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS }, | |
3189 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS }, | |
3190 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS }, | |
3191 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS }, | |
3192 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS }, | |
3193 | { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS }, | |
f18c054f | 3194 | { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR }, |
0ac081f6 | 3195 | }; |
617e0e1d DB |
3196 | /* Simple unary operations: VECb = foo (unsigned literal) or VECb = |
3197 | foo (VECa). */ | |
2212663f DB |
3198 | static const struct builtin_description bdesc_1arg[] = |
3199 | { | |
617e0e1d DB |
3200 | { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP }, |
3201 | { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP }, | |
3202 | { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP }, | |
3203 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM }, | |
3204 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN }, | |
3205 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP }, | |
3206 | { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ }, | |
3207 | { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP }, | |
2212663f DB |
3208 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB }, |
3209 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH }, | |
3210 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW }, | |
3211 | }; | |
3212 | ||
3213 | static rtx | |
3214 | altivec_expand_unop_builtin (icode, arglist, target) | |
3215 | enum insn_code icode; | |
3216 | tree arglist; | |
3217 | rtx target; | |
3218 | { | |
3219 | rtx pat; | |
3220 | tree arg0 = TREE_VALUE (arglist); | |
3221 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3222 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
3223 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
3224 | ||
3225 | if (! target | |
3226 | || GET_MODE (target) != tmode | |
3227 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3228 | target = gen_reg_rtx (tmode); | |
3229 | ||
3230 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3231 | op0 = copy_to_mode_reg (mode0, op0); | |
3232 | ||
3233 | pat = GEN_FCN (icode) (target, op0); | |
3234 | if (! pat) | |
3235 | return 0; | |
3236 | emit_insn (pat); | |
0ac081f6 | 3237 | |
2212663f DB |
3238 | return target; |
3239 | } | |
0ac081f6 AH |
3240 | static rtx |
3241 | altivec_expand_binop_builtin (icode, arglist, target) | |
3242 | enum insn_code icode; | |
3243 | tree arglist; | |
3244 | rtx target; | |
3245 | { | |
3246 | rtx pat; | |
3247 | tree arg0 = TREE_VALUE (arglist); | |
3248 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
3249 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3250 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
3251 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
3252 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
3253 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
3254 | ||
3255 | if (! target | |
3256 | || GET_MODE (target) != tmode | |
3257 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3258 | target = gen_reg_rtx (tmode); | |
3259 | ||
3260 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3261 | op0 = copy_to_mode_reg (mode0, op0); | |
3262 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
3263 | op1 = copy_to_mode_reg (mode1, op1); | |
3264 | ||
3265 | pat = GEN_FCN (icode) (target, op0, op1); | |
3266 | if (! pat) | |
3267 | return 0; | |
3268 | emit_insn (pat); | |
3269 | ||
3270 | return target; | |
3271 | } | |
2212663f DB |
3272 | static rtx |
3273 | altivec_expand_ternop_builtin (icode, arglist, target) | |
3274 | enum insn_code icode; | |
3275 | tree arglist; | |
3276 | rtx target; | |
3277 | { | |
3278 | rtx pat; | |
3279 | tree arg0 = TREE_VALUE (arglist); | |
3280 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
3281 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
3282 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3283 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
3284 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
3285 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
3286 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
3287 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
3288 | enum machine_mode mode2 = insn_data[icode].operand[3].mode; | |
0ac081f6 | 3289 | |
2212663f DB |
3290 | if (! target |
3291 | || GET_MODE (target) != tmode | |
3292 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3293 | target = gen_reg_rtx (tmode); | |
3294 | ||
3295 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3296 | op0 = copy_to_mode_reg (mode0, op0); | |
3297 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
3298 | op1 = copy_to_mode_reg (mode1, op1); | |
3299 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
3300 | op2 = copy_to_mode_reg (mode2, op2); | |
3301 | ||
3302 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
3303 | if (! pat) | |
3304 | return 0; | |
3305 | emit_insn (pat); | |
3306 | ||
3307 | return target; | |
3308 | } | |
0ac081f6 | 3309 | static rtx |
00b960c7 | 3310 | altivec_expand_builtin (exp, target) |
0ac081f6 AH |
3311 | tree exp; |
3312 | rtx target; | |
0ac081f6 AH |
3313 | { |
3314 | struct builtin_description *d; | |
3315 | size_t i; | |
3316 | enum insn_code icode; | |
3317 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
3318 | tree arglist = TREE_OPERAND (exp, 1); | |
00b960c7 AH |
3319 | tree arg0, arg1; |
3320 | rtx op0, op1, pat; | |
3321 | enum machine_mode tmode, mode0, mode1; | |
0ac081f6 AH |
3322 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
3323 | ||
3324 | switch (fcode) | |
3325 | { | |
f18c054f DB |
3326 | case ALTIVEC_BUILTIN_LD_INTERNAL_16qi: |
3327 | icode = CODE_FOR_altivec_lvx_16qi; | |
0ac081f6 AH |
3328 | arg0 = TREE_VALUE (arglist); |
3329 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3330 | tmode = insn_data[icode].operand[0].mode; | |
3331 | mode0 = insn_data[icode].operand[1].mode; | |
3332 | ||
3333 | if (! target | |
3334 | || GET_MODE (target) != tmode | |
3335 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3336 | target = gen_reg_rtx (tmode); | |
3337 | ||
3338 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3339 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3340 | ||
3341 | pat = GEN_FCN (icode) (target, op0); | |
3342 | if (! pat) | |
3343 | return 0; | |
3344 | emit_insn (pat); | |
3345 | return target; | |
f18c054f DB |
3346 | case ALTIVEC_BUILTIN_LD_INTERNAL_8hi: |
3347 | icode = CODE_FOR_altivec_lvx_8hi; | |
3348 | arg0 = TREE_VALUE (arglist); | |
3349 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3350 | tmode = insn_data[icode].operand[0].mode; | |
3351 | mode0 = insn_data[icode].operand[1].mode; | |
0ac081f6 | 3352 | |
f18c054f DB |
3353 | if (! target |
3354 | || GET_MODE (target) != tmode | |
3355 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3356 | target = gen_reg_rtx (tmode); | |
3357 | ||
3358 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3359 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3360 | ||
3361 | pat = GEN_FCN (icode) (target, op0); | |
3362 | if (! pat) | |
3363 | return 0; | |
3364 | emit_insn (pat); | |
3365 | return target; | |
3366 | case ALTIVEC_BUILTIN_LD_INTERNAL_4si: | |
3367 | icode = CODE_FOR_altivec_lvx_4si; | |
3368 | arg0 = TREE_VALUE (arglist); | |
3369 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3370 | tmode = insn_data[icode].operand[0].mode; | |
3371 | mode0 = insn_data[icode].operand[1].mode; | |
3372 | ||
3373 | if (! target | |
3374 | || GET_MODE (target) != tmode | |
3375 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3376 | target = gen_reg_rtx (tmode); | |
3377 | ||
3378 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3379 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3380 | ||
3381 | pat = GEN_FCN (icode) (target, op0); | |
3382 | if (! pat) | |
3383 | return 0; | |
3384 | emit_insn (pat); | |
3385 | return target; | |
3386 | case ALTIVEC_BUILTIN_LD_INTERNAL_4sf: | |
3387 | icode = CODE_FOR_altivec_lvx_4sf; | |
3388 | arg0 = TREE_VALUE (arglist); | |
3389 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3390 | tmode = insn_data[icode].operand[0].mode; | |
3391 | mode0 = insn_data[icode].operand[1].mode; | |
3392 | ||
3393 | if (! target | |
3394 | || GET_MODE (target) != tmode | |
3395 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
3396 | target = gen_reg_rtx (tmode); | |
3397 | ||
3398 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
3399 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3400 | ||
3401 | pat = GEN_FCN (icode) (target, op0); | |
3402 | if (! pat) | |
3403 | return 0; | |
3404 | emit_insn (pat); | |
3405 | return target; | |
3406 | ||
3407 | case ALTIVEC_BUILTIN_ST_INTERNAL_16qi: | |
3408 | icode = CODE_FOR_altivec_stvx_16qi; | |
3409 | arg0 = TREE_VALUE (arglist); | |
3410 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
3411 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3412 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
3413 | mode0 = insn_data[icode].operand[0].mode; | |
3414 | mode1 = insn_data[icode].operand[1].mode; | |
3415 | ||
3416 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
3417 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3418 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
3419 | op1 = copy_to_mode_reg (mode1, op1); | |
3420 | ||
3421 | pat = GEN_FCN (icode) (op0, op1); | |
3422 | if (! pat) | |
3423 | return 0; | |
3424 | emit_insn (pat); | |
3425 | return NULL_RTX; | |
3426 | case ALTIVEC_BUILTIN_ST_INTERNAL_8hi: | |
3427 | icode = CODE_FOR_altivec_stvx_8hi; | |
3428 | arg0 = TREE_VALUE (arglist); | |
3429 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
3430 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3431 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
3432 | mode0 = insn_data[icode].operand[0].mode; | |
3433 | mode1 = insn_data[icode].operand[1].mode; | |
3434 | ||
3435 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
3436 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3437 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
3438 | op1 = copy_to_mode_reg (mode1, op1); | |
3439 | ||
3440 | pat = GEN_FCN (icode) (op0, op1); | |
3441 | if (! pat) | |
3442 | return 0; | |
3443 | emit_insn (pat); | |
3444 | return NULL_RTX; | |
3445 | case ALTIVEC_BUILTIN_ST_INTERNAL_4si: | |
3446 | icode = CODE_FOR_altivec_stvx_4si; | |
3447 | arg0 = TREE_VALUE (arglist); | |
3448 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
3449 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3450 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
3451 | mode0 = insn_data[icode].operand[0].mode; | |
3452 | mode1 = insn_data[icode].operand[1].mode; | |
3453 | ||
3454 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
3455 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3456 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
3457 | op1 = copy_to_mode_reg (mode1, op1); | |
3458 | ||
3459 | pat = GEN_FCN (icode) (op0, op1); | |
3460 | if (! pat) | |
3461 | return 0; | |
3462 | emit_insn (pat); | |
3463 | return NULL_RTX; | |
3464 | case ALTIVEC_BUILTIN_ST_INTERNAL_4sf: | |
3465 | icode = CODE_FOR_altivec_stvx_4sf; | |
0ac081f6 AH |
3466 | arg0 = TREE_VALUE (arglist); |
3467 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
3468 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
3469 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
3470 | mode0 = insn_data[icode].operand[0].mode; | |
3471 | mode1 = insn_data[icode].operand[1].mode; | |
3472 | ||
3473 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
3474 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
3475 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
3476 | op1 = copy_to_mode_reg (mode1, op1); | |
3477 | ||
3478 | pat = GEN_FCN (icode) (op0, op1); | |
3479 | if (! pat) | |
3480 | return 0; | |
3481 | emit_insn (pat); | |
3482 | return NULL_RTX; | |
3483 | } | |
2212663f DB |
3484 | /* Handle simple unary operations. */ |
3485 | d = (struct builtin_description *) bdesc_1arg; | |
3486 | for (i = 0; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++) | |
3487 | if (d->code == fcode) | |
3488 | return altivec_expand_unop_builtin (d->icode, arglist, target); | |
0ac081f6 AH |
3489 | |
3490 | /* Handle simple binary operations. */ | |
00b960c7 AH |
3491 | d = (struct builtin_description *) bdesc_2arg; |
3492 | for (i = 0; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++) | |
0ac081f6 AH |
3493 | if (d->code == fcode) |
3494 | return altivec_expand_binop_builtin (d->icode, arglist, target); | |
3495 | ||
2212663f DB |
3496 | /* Handle simple ternary operations. */ |
3497 | d = (struct builtin_description *) bdesc_3arg; | |
3498 | for (i = 0; i < sizeof (bdesc_3arg) / sizeof *d; i++, d++) | |
3499 | if (d->code == fcode) | |
3500 | return altivec_expand_ternop_builtin (d->icode, arglist, target); | |
3501 | ||
0ac081f6 AH |
3502 | abort (); |
3503 | return NULL_RTX; | |
3504 | } | |
3505 | ||
3506 | /* Expand an expression EXP that calls a built-in function, | |
3507 | with result going to TARGET if that's convenient | |
3508 | (and in mode MODE if that's convenient). | |
3509 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
3510 | IGNORE is nonzero if the value is to be ignored. */ | |
3511 | ||
3512 | static rtx | |
3513 | rs6000_expand_builtin (exp, target, subtarget, mode, ignore) | |
3514 | tree exp; | |
3515 | rtx target; | |
00b960c7 AH |
3516 | rtx subtarget ATTRIBUTE_UNUSED; |
3517 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3518 | int ignore ATTRIBUTE_UNUSED; | |
0ac081f6 AH |
3519 | { |
3520 | if (TARGET_ALTIVEC) | |
00b960c7 | 3521 | return altivec_expand_builtin (exp, target); |
0ac081f6 AH |
3522 | |
3523 | abort (); | |
3524 | } | |
3525 | ||
3526 | static void | |
6fa3f289 | 3527 | rs6000_init_builtins () |
0ac081f6 AH |
3528 | { |
3529 | if (TARGET_ALTIVEC) | |
3530 | altivec_init_builtins (); | |
3531 | } | |
3532 | ||
3533 | static void | |
3534 | altivec_init_builtins (void) | |
3535 | { | |
3536 | struct builtin_description * d; | |
3537 | size_t i; | |
3538 | ||
3539 | tree endlink = void_list_node; | |
3540 | ||
3541 | tree pint_type_node = build_pointer_type (integer_type_node); | |
f18c054f DB |
3542 | tree pshort_type_node = build_pointer_type (short_integer_type_node); |
3543 | tree pchar_type_node = build_pointer_type (char_type_node); | |
3544 | tree pfloat_type_node = build_pointer_type (float_type_node); | |
2212663f DB |
3545 | tree v4sf_ftype_v4sf_v4sf_v16qi |
3546 | = build_function_type (V4SF_type_node, | |
3547 | tree_cons (NULL_TREE, V4SF_type_node, | |
3548 | tree_cons (NULL_TREE, V4SF_type_node, | |
3549 | tree_cons (NULL_TREE, | |
3550 | V16QI_type_node, | |
3551 | endlink)))); | |
3552 | tree v4si_ftype_v4si_v4si_v16qi | |
3553 | = build_function_type (V4SI_type_node, | |
3554 | tree_cons (NULL_TREE, V4SI_type_node, | |
3555 | tree_cons (NULL_TREE, V4SI_type_node, | |
3556 | tree_cons (NULL_TREE, | |
3557 | V16QI_type_node, | |
3558 | endlink)))); | |
3559 | tree v8hi_ftype_v8hi_v8hi_v16qi | |
3560 | = build_function_type (V8HI_type_node, | |
3561 | tree_cons (NULL_TREE, V8HI_type_node, | |
3562 | tree_cons (NULL_TREE, V8HI_type_node, | |
3563 | tree_cons (NULL_TREE, | |
3564 | V16QI_type_node, | |
3565 | endlink)))); | |
3566 | tree v16qi_ftype_v16qi_v16qi_v16qi | |
3567 | = build_function_type (V16QI_type_node, | |
3568 | tree_cons (NULL_TREE, V16QI_type_node, | |
3569 | tree_cons (NULL_TREE, V16QI_type_node, | |
3570 | tree_cons (NULL_TREE, | |
3571 | V16QI_type_node, | |
3572 | endlink)))); | |
3573 | ||
3574 | /* V4SI foo (char) */ | |
3575 | tree v4si_ftype_char | |
3576 | = build_function_type (V4SI_type_node, | |
3577 | tree_cons (NULL_TREE, char_type_node, endlink)); | |
3578 | ||
3579 | /* V8HI foo (char) */ | |
3580 | tree v8hi_ftype_char | |
3581 | = build_function_type (V8HI_type_node, | |
3582 | tree_cons (NULL_TREE, char_type_node, endlink)); | |
3583 | ||
3584 | /* V16QI foo (char) */ | |
3585 | tree v16qi_ftype_char | |
3586 | = build_function_type (V16QI_type_node, | |
3587 | tree_cons (NULL_TREE, char_type_node, endlink)); | |
617e0e1d DB |
3588 | /* V4SF foo (V4SF) */ |
3589 | tree v4sf_ftype_v4sf | |
3590 | = build_function_type (V4SF_type_node, | |
3591 | tree_cons (NULL_TREE, V4SF_type_node, endlink)); | |
0ac081f6 AH |
3592 | |
3593 | /* V4SI foo (int *). */ | |
3594 | tree v4si_ftype_pint | |
3595 | = build_function_type (V4SI_type_node, | |
3596 | tree_cons (NULL_TREE, pint_type_node, endlink)); | |
f18c054f DB |
3597 | /* V8HI foo (short *). */ |
3598 | tree v8hi_ftype_pshort | |
3599 | = build_function_type (V8HI_type_node, | |
3600 | tree_cons (NULL_TREE, pshort_type_node, endlink)); | |
3601 | /* V16QI foo (char *). */ | |
3602 | tree v16qi_ftype_pchar | |
3603 | = build_function_type (V16QI_type_node, | |
3604 | tree_cons (NULL_TREE, pchar_type_node, endlink)); | |
3605 | /* V4SF foo (float *). */ | |
3606 | tree v4sf_ftype_pfloat | |
3607 | = build_function_type (V4SF_type_node, | |
3608 | tree_cons (NULL_TREE, pfloat_type_node, endlink)); | |
0ac081f6 AH |
3609 | |
3610 | /* void foo (int *, V4SI). */ | |
3611 | tree void_ftype_pint_v4si | |
3612 | = build_function_type (void_type_node, | |
3613 | tree_cons (NULL_TREE, pint_type_node, | |
3614 | tree_cons (NULL_TREE, V4SI_type_node, | |
3615 | endlink))); | |
f18c054f DB |
3616 | /* void foo (short *, V8HI). */ |
3617 | tree void_ftype_pshort_v8hi | |
3618 | = build_function_type (void_type_node, | |
3619 | tree_cons (NULL_TREE, pshort_type_node, | |
3620 | tree_cons (NULL_TREE, V8HI_type_node, | |
3621 | endlink))); | |
3622 | /* void foo (char *, V16QI). */ | |
3623 | tree void_ftype_pchar_v16qi | |
3624 | = build_function_type (void_type_node, | |
3625 | tree_cons (NULL_TREE, pchar_type_node, | |
3626 | tree_cons (NULL_TREE, V16QI_type_node, | |
3627 | endlink))); | |
3628 | /* void foo (float *, V4SF). */ | |
3629 | tree void_ftype_pfloat_v4sf | |
3630 | = build_function_type (void_type_node, | |
3631 | tree_cons (NULL_TREE, pfloat_type_node, | |
3632 | tree_cons (NULL_TREE, V4SF_type_node, | |
3633 | endlink))); | |
0ac081f6 AH |
3634 | |
3635 | tree v4si_ftype_v4si_v4si | |
3636 | = build_function_type (V4SI_type_node, | |
3637 | tree_cons (NULL_TREE, V4SI_type_node, | |
3638 | tree_cons (NULL_TREE, V4SI_type_node, | |
3639 | endlink))); | |
2212663f | 3640 | /* These are really for the unsigned 5 bit literals */ |
617e0e1d DB |
3641 | tree v4sf_ftype_v4si_char |
3642 | = build_function_type (V4SF_type_node, | |
3643 | tree_cons (NULL_TREE, V4SI_type_node, | |
3644 | tree_cons (NULL_TREE, char_type_node, | |
3645 | endlink))); | |
3646 | tree v4si_ftype_v4sf_char | |
3647 | = build_function_type (V4SI_type_node, | |
3648 | tree_cons (NULL_TREE, V4SF_type_node, | |
3649 | tree_cons (NULL_TREE, char_type_node, | |
3650 | endlink))); | |
2212663f DB |
3651 | tree v4si_ftype_v4si_char |
3652 | = build_function_type (V4SI_type_node, | |
3653 | tree_cons (NULL_TREE, V4SI_type_node, | |
3654 | tree_cons (NULL_TREE, char_type_node, | |
3655 | endlink))); | |
3656 | tree v8hi_ftype_v8hi_char | |
3657 | = build_function_type (V8HI_type_node, | |
3658 | tree_cons (NULL_TREE, V8HI_type_node, | |
3659 | tree_cons (NULL_TREE, char_type_node, | |
3660 | endlink))); | |
3661 | tree v16qi_ftype_v16qi_char | |
3662 | = build_function_type (V16QI_type_node, | |
3663 | tree_cons (NULL_TREE, V16QI_type_node, | |
3664 | tree_cons (NULL_TREE, char_type_node, | |
3665 | endlink))); | |
0ac081f6 AH |
3666 | |
3667 | tree v4sf_ftype_v4sf_v4sf | |
3668 | = build_function_type (V4SF_type_node, | |
3669 | tree_cons (NULL_TREE, V4SF_type_node, | |
3670 | tree_cons (NULL_TREE, V4SF_type_node, | |
3671 | endlink))); | |
617e0e1d DB |
3672 | tree v4sf_ftype_v4sf_v4sf_v4si |
3673 | = build_function_type (V4SF_type_node, | |
3674 | tree_cons (NULL_TREE, V4SF_type_node, | |
3675 | tree_cons (NULL_TREE, V4SF_type_node, | |
3676 | tree_cons (NULL_TREE, | |
3677 | V4SI_type_node, | |
3678 | endlink)))); | |
2212663f DB |
3679 | tree v4sf_ftype_v4sf_v4sf_v4sf |
3680 | = build_function_type (V4SF_type_node, | |
3681 | tree_cons (NULL_TREE, V4SF_type_node, | |
3682 | tree_cons (NULL_TREE, V4SF_type_node, | |
3683 | tree_cons (NULL_TREE, | |
3684 | V4SF_type_node, | |
3685 | endlink)))); | |
617e0e1d DB |
3686 | tree v4si_ftype_v4si_v4si_v4si |
3687 | = build_function_type (V4SI_type_node, | |
3688 | tree_cons (NULL_TREE, V4SI_type_node, | |
3689 | tree_cons (NULL_TREE, V4SI_type_node, | |
3690 | tree_cons (NULL_TREE, | |
3691 | V4SI_type_node, | |
3692 | endlink)))); | |
2212663f | 3693 | |
0ac081f6 AH |
3694 | tree v8hi_ftype_v8hi_v8hi |
3695 | = build_function_type (V8HI_type_node, | |
3696 | tree_cons (NULL_TREE, V8HI_type_node, | |
3697 | tree_cons (NULL_TREE, V8HI_type_node, | |
3698 | endlink))); | |
2212663f DB |
3699 | tree v8hi_ftype_v8hi_v8hi_v8hi |
3700 | = build_function_type (V8HI_type_node, | |
3701 | tree_cons (NULL_TREE, V8HI_type_node, | |
3702 | tree_cons (NULL_TREE, V8HI_type_node, | |
3703 | tree_cons (NULL_TREE, | |
3704 | V8HI_type_node, | |
3705 | endlink)))); | |
3706 | tree v4si_ftype_v8hi_v8hi_v4si | |
3707 | = build_function_type (V4SI_type_node, | |
3708 | tree_cons (NULL_TREE, V8HI_type_node, | |
3709 | tree_cons (NULL_TREE, V8HI_type_node, | |
3710 | tree_cons (NULL_TREE, | |
3711 | V4SI_type_node, | |
3712 | endlink)))); | |
3713 | tree v4si_ftype_v16qi_v16qi_v4si | |
3714 | = build_function_type (V4SI_type_node, | |
3715 | tree_cons (NULL_TREE, V16QI_type_node, | |
3716 | tree_cons (NULL_TREE, V16QI_type_node, | |
3717 | tree_cons (NULL_TREE, | |
3718 | V4SI_type_node, | |
3719 | endlink)))); | |
3720 | ||
0ac081f6 AH |
3721 | tree v16qi_ftype_v16qi_v16qi |
3722 | = build_function_type (V16QI_type_node, | |
3723 | tree_cons (NULL_TREE, V16QI_type_node, | |
3724 | tree_cons (NULL_TREE, V16QI_type_node, | |
3725 | endlink))); | |
2212663f | 3726 | |
0ac081f6 AH |
3727 | tree v4si_ftype_v4sf_v4sf |
3728 | = build_function_type (V4SI_type_node, | |
3729 | tree_cons (NULL_TREE, V4SF_type_node, | |
3730 | tree_cons (NULL_TREE, V4SF_type_node, | |
3731 | endlink))); | |
3732 | ||
3733 | tree v8hi_ftype_v16qi_v16qi | |
3734 | = build_function_type (V8HI_type_node, | |
3735 | tree_cons (NULL_TREE, V16QI_type_node, | |
3736 | tree_cons (NULL_TREE, V16QI_type_node, | |
3737 | endlink))); | |
3738 | ||
3739 | tree v4si_ftype_v8hi_v8hi | |
3740 | = build_function_type (V4SI_type_node, | |
3741 | tree_cons (NULL_TREE, V8HI_type_node, | |
3742 | tree_cons (NULL_TREE, V8HI_type_node, | |
3743 | endlink))); | |
3744 | ||
3745 | tree v8hi_ftype_v4si_v4si | |
3746 | = build_function_type (V8HI_type_node, | |
3747 | tree_cons (NULL_TREE, V4SI_type_node, | |
3748 | tree_cons (NULL_TREE, V4SI_type_node, | |
3749 | endlink))); | |
3750 | ||
3751 | tree v16qi_ftype_v8hi_v8hi | |
3752 | = build_function_type (V16QI_type_node, | |
3753 | tree_cons (NULL_TREE, V8HI_type_node, | |
3754 | tree_cons (NULL_TREE, V8HI_type_node, | |
3755 | endlink))); | |
3756 | ||
3757 | tree v4si_ftype_v16qi_v4si | |
3758 | = build_function_type (V4SI_type_node, | |
3759 | tree_cons (NULL_TREE, V16QI_type_node, | |
3760 | tree_cons (NULL_TREE, V4SI_type_node, | |
3761 | endlink))); | |
3762 | ||
3763 | tree v4si_ftype_v8hi_v4si | |
3764 | = build_function_type (V4SI_type_node, | |
3765 | tree_cons (NULL_TREE, V8HI_type_node, | |
3766 | tree_cons (NULL_TREE, V4SI_type_node, | |
3767 | endlink))); | |
3768 | ||
3769 | tree int_ftype_v4si_v4si | |
3770 | = build_function_type (integer_type_node, | |
3771 | tree_cons (NULL_TREE, V4SI_type_node, | |
3772 | tree_cons (NULL_TREE, V4SI_type_node, | |
3773 | endlink))); | |
3774 | ||
3775 | tree int_ftype_v4sf_v4sf | |
3776 | = build_function_type (integer_type_node, | |
3777 | tree_cons (NULL_TREE, V4SF_type_node, | |
3778 | tree_cons (NULL_TREE, V4SF_type_node, | |
3779 | endlink))); | |
3780 | ||
3781 | tree int_ftype_v16qi_v16qi | |
3782 | = build_function_type (integer_type_node, | |
3783 | tree_cons (NULL_TREE, V16QI_type_node, | |
3784 | tree_cons (NULL_TREE, V16QI_type_node, | |
3785 | endlink))); | |
3786 | ||
3787 | tree int_ftype_v8hi_v8hi | |
3788 | = build_function_type (integer_type_node, | |
3789 | tree_cons (NULL_TREE, V8HI_type_node, | |
3790 | tree_cons (NULL_TREE, V8HI_type_node, | |
3791 | endlink))); | |
3792 | ||
f18c054f DB |
3793 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pfloat, ALTIVEC_BUILTIN_LD_INTERNAL_4sf); |
3794 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, ALTIVEC_BUILTIN_ST_INTERNAL_4sf); | |
3795 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pint, ALTIVEC_BUILTIN_LD_INTERNAL_4si); | |
3796 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, ALTIVEC_BUILTIN_ST_INTERNAL_4si); | |
3797 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pshort, ALTIVEC_BUILTIN_LD_INTERNAL_8hi); | |
3798 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, ALTIVEC_BUILTIN_ST_INTERNAL_8hi); | |
3799 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pchar, ALTIVEC_BUILTIN_LD_INTERNAL_16qi); | |
3800 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, ALTIVEC_BUILTIN_ST_INTERNAL_16qi); | |
0ac081f6 | 3801 | |
2212663f DB |
3802 | /* Add the simple ternary operators. */ |
3803 | d = (struct builtin_description *) bdesc_3arg; | |
3804 | for (i = 0; i < sizeof (bdesc_3arg) / sizeof *d; i++, d++) | |
3805 | { | |
3806 | ||
3807 | enum machine_mode mode0, mode1, mode2, mode3; | |
3808 | tree type; | |
3809 | ||
3810 | if (d->name == 0) | |
3811 | continue; | |
3812 | ||
3813 | mode0 = insn_data[d->icode].operand[0].mode; | |
3814 | mode1 = insn_data[d->icode].operand[1].mode; | |
3815 | mode2 = insn_data[d->icode].operand[2].mode; | |
3816 | mode3 = insn_data[d->icode].operand[3].mode; | |
3817 | ||
3818 | /* When all four are of the same mode. */ | |
3819 | if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3) | |
3820 | { | |
3821 | switch (mode0) | |
3822 | { | |
617e0e1d DB |
3823 | case V4SImode: |
3824 | type = v4si_ftype_v4si_v4si_v4si; | |
3825 | break; | |
2212663f DB |
3826 | case V4SFmode: |
3827 | type = v4sf_ftype_v4sf_v4sf_v4sf; | |
3828 | break; | |
3829 | case V8HImode: | |
3830 | type = v8hi_ftype_v8hi_v8hi_v8hi; | |
3831 | break; | |
3832 | case V16QImode: | |
3833 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
3834 | break; | |
3835 | default: | |
3836 | abort(); | |
3837 | } | |
3838 | } | |
3839 | else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode) | |
3840 | { | |
3841 | switch (mode0) | |
3842 | { | |
3843 | case V4SImode: | |
3844 | type = v4si_ftype_v4si_v4si_v16qi; | |
3845 | break; | |
3846 | case V4SFmode: | |
3847 | type = v4sf_ftype_v4sf_v4sf_v16qi; | |
3848 | break; | |
3849 | case V8HImode: | |
3850 | type = v8hi_ftype_v8hi_v8hi_v16qi; | |
3851 | break; | |
3852 | case V16QImode: | |
3853 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
3854 | break; | |
3855 | default: | |
3856 | abort(); | |
3857 | } | |
3858 | } | |
3859 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode | |
3860 | && mode3 == V4SImode) | |
2212663f | 3861 | type = v4si_ftype_v16qi_v16qi_v4si; |
2212663f DB |
3862 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode |
3863 | && mode3 == V4SImode) | |
2212663f | 3864 | type = v4si_ftype_v8hi_v8hi_v4si; |
617e0e1d DB |
3865 | else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode |
3866 | && mode3 == V4SImode) | |
3867 | type = v4sf_ftype_v4sf_v4sf_v4si; | |
2212663f DB |
3868 | else |
3869 | abort (); | |
3870 | ||
3871 | def_builtin (d->mask, d->name, type, d->code); | |
3872 | } | |
3873 | ||
0ac081f6 | 3874 | /* Add the simple binary operators. */ |
00b960c7 AH |
3875 | d = (struct builtin_description *) bdesc_2arg; |
3876 | for (i = 0; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++) | |
0ac081f6 AH |
3877 | { |
3878 | enum machine_mode mode0, mode1, mode2; | |
3879 | tree type; | |
3880 | ||
3881 | if (d->name == 0) | |
3882 | continue; | |
3883 | ||
3884 | mode0 = insn_data[d->icode].operand[0].mode; | |
3885 | mode1 = insn_data[d->icode].operand[1].mode; | |
3886 | mode2 = insn_data[d->icode].operand[2].mode; | |
3887 | ||
3888 | /* When all three operands are of the same mode. */ | |
3889 | if (mode0 == mode1 && mode1 == mode2) | |
3890 | { | |
3891 | switch (mode0) | |
3892 | { | |
3893 | case V4SFmode: | |
3894 | type = v4sf_ftype_v4sf_v4sf; | |
3895 | break; | |
3896 | case V4SImode: | |
3897 | type = v4si_ftype_v4si_v4si; | |
3898 | break; | |
3899 | case V16QImode: | |
3900 | type = v16qi_ftype_v16qi_v16qi; | |
3901 | break; | |
3902 | case V8HImode: | |
3903 | type = v8hi_ftype_v8hi_v8hi; | |
3904 | break; | |
3905 | default: | |
3906 | abort (); | |
3907 | } | |
3908 | } | |
3909 | ||
3910 | /* A few other combos we really don't want to do manually. */ | |
3911 | ||
3912 | /* vint, vfloat, vfloat. */ | |
3913 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode) | |
3914 | type = v4si_ftype_v4sf_v4sf; | |
3915 | ||
3916 | /* vshort, vchar, vchar. */ | |
3917 | else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode) | |
3918 | type = v8hi_ftype_v16qi_v16qi; | |
3919 | ||
3920 | /* vint, vshort, vshort. */ | |
3921 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode) | |
3922 | type = v4si_ftype_v8hi_v8hi; | |
3923 | ||
3924 | /* vshort, vint, vint. */ | |
3925 | else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode) | |
3926 | type = v8hi_ftype_v4si_v4si; | |
3927 | ||
3928 | /* vchar, vshort, vshort. */ | |
3929 | else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode) | |
3930 | type = v16qi_ftype_v8hi_v8hi; | |
3931 | ||
3932 | /* vint, vchar, vint. */ | |
3933 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode) | |
3934 | type = v4si_ftype_v16qi_v4si; | |
3935 | ||
3936 | /* vint, vshort, vint. */ | |
3937 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode) | |
3938 | type = v4si_ftype_v8hi_v4si; | |
2212663f DB |
3939 | |
3940 | /* vint, vint, 5 bit literal. */ | |
3941 | else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode) | |
3942 | type = v4si_ftype_v4si_char; | |
3943 | ||
3944 | /* vshort, vshort, 5 bit literal. */ | |
3945 | else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode) | |
3946 | type = v8hi_ftype_v8hi_char; | |
3947 | ||
3948 | /* vchar, vchar, 5 bit literal. */ | |
3949 | else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode) | |
3950 | type = v16qi_ftype_v16qi_char; | |
0ac081f6 | 3951 | |
617e0e1d DB |
3952 | /* vfloat, vint, 5 bit literal. */ |
3953 | else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode) | |
3954 | type = v4sf_ftype_v4si_char; | |
3955 | ||
3956 | /* vint, vfloat, 5 bit literal. */ | |
3957 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode) | |
3958 | type = v4si_ftype_v4sf_char; | |
3959 | ||
0ac081f6 AH |
3960 | /* fixme: aldyh */ |
3961 | /* int, x, x. */ | |
3962 | else if (mode0 == SImode) | |
3963 | { | |
3964 | switch (mode1) | |
3965 | { | |
3966 | case V4SImode: | |
3967 | type = int_ftype_v4si_v4si; | |
3968 | break; | |
3969 | case V4SFmode: | |
3970 | type = int_ftype_v4sf_v4sf; | |
3971 | break; | |
3972 | case V16QImode: | |
3973 | type = int_ftype_v16qi_v16qi; | |
3974 | break; | |
3975 | case V8HImode: | |
3976 | type = int_ftype_v8hi_v8hi; | |
3977 | break; | |
3978 | default: | |
3979 | abort (); | |
3980 | } | |
3981 | } | |
3982 | ||
3983 | else | |
3984 | abort (); | |
3985 | ||
2212663f DB |
3986 | def_builtin (d->mask, d->name, type, d->code); |
3987 | } | |
3988 | /* Add the simple unary operators. */ | |
3989 | d = (struct builtin_description *) bdesc_1arg; | |
3990 | for (i = 0; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++) | |
3991 | { | |
3992 | enum machine_mode mode0, mode1; | |
3993 | tree type; | |
3994 | ||
3995 | if (d->name == 0) | |
3996 | continue; | |
3997 | ||
3998 | mode0 = insn_data[d->icode].operand[0].mode; | |
3999 | mode1 = insn_data[d->icode].operand[1].mode; | |
4000 | ||
4001 | if (mode0 == V4SImode && mode1 == QImode) | |
4002 | type = v4si_ftype_char; | |
4003 | else if (mode0 == V8HImode && mode1 == QImode) | |
4004 | type = v8hi_ftype_char; | |
4005 | else if (mode0 == V16QImode && mode1 == QImode) | |
4006 | type = v16qi_ftype_char; | |
617e0e1d DB |
4007 | else if (mode0 == V4SFmode && mode1 == V4SFmode) |
4008 | type = v4sf_ftype_v4sf; | |
2212663f DB |
4009 | else |
4010 | abort (); | |
4011 | ||
0ac081f6 AH |
4012 | def_builtin (d->mask, d->name, type, d->code); |
4013 | } | |
4014 | } | |
4015 | ||
5b5040b9 RK |
4016 | \f |
4017 | /* Generate a memory reference for expand_block_move, copying volatile, | |
4018 | and other bits from an original memory reference. */ | |
4019 | ||
4020 | static rtx | |
4021 | expand_block_move_mem (mode, addr, orig_mem) | |
4022 | enum machine_mode mode; | |
4023 | rtx addr; | |
4024 | rtx orig_mem; | |
4025 | { | |
39403d82 | 4026 | rtx mem = gen_rtx_MEM (mode, addr); |
b6c9286a | 4027 | |
c6df88cb | 4028 | MEM_COPY_ATTRIBUTES (mem, orig_mem); |
5b5040b9 RK |
4029 | return mem; |
4030 | } | |
4031 | ||
7e69e155 MM |
4032 | /* Expand a block move operation, and return 1 if successful. Return 0 |
4033 | if we should let the compiler generate normal code. | |
4034 | ||
4035 | operands[0] is the destination | |
4036 | operands[1] is the source | |
4037 | operands[2] is the length | |
4038 | operands[3] is the alignment */ | |
4039 | ||
3933e0e1 MM |
4040 | #define MAX_MOVE_REG 4 |
4041 | ||
7e69e155 MM |
4042 | int |
4043 | expand_block_move (operands) | |
4044 | rtx operands[]; | |
4045 | { | |
b6c9286a MM |
4046 | rtx orig_dest = operands[0]; |
4047 | rtx orig_src = operands[1]; | |
7e69e155 | 4048 | rtx bytes_rtx = operands[2]; |
7e69e155 | 4049 | rtx align_rtx = operands[3]; |
3933e0e1 | 4050 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 4051 | int align; |
3933e0e1 MM |
4052 | int bytes; |
4053 | int offset; | |
4054 | int num_reg; | |
4055 | int i; | |
7e69e155 MM |
4056 | rtx src_reg; |
4057 | rtx dest_reg; | |
3933e0e1 MM |
4058 | rtx src_addr; |
4059 | rtx dest_addr; | |
7e69e155 | 4060 | rtx tmp_reg; |
3933e0e1 | 4061 | rtx stores[MAX_MOVE_REG]; |
7e69e155 MM |
4062 | int move_bytes; |
4063 | ||
3933e0e1 | 4064 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 4065 | if (! constp) |
3933e0e1 MM |
4066 | return 0; |
4067 | ||
5ee95df6 FS |
4068 | /* If this is not a fixed size alignment, abort */ |
4069 | if (GET_CODE (align_rtx) != CONST_INT) | |
4070 | abort (); | |
4071 | align = INTVAL (align_rtx); | |
4072 | ||
7e69e155 | 4073 | /* Anything to move? */ |
3933e0e1 MM |
4074 | bytes = INTVAL (bytes_rtx); |
4075 | if (bytes <= 0) | |
7e69e155 MM |
4076 | return 1; |
4077 | ||
ea9982a8 TR |
4078 | /* store_one_arg depends on expand_block_move to handle at least the size of |
4079 | reg_parm_stack_space. */ | |
4080 | if (bytes > (TARGET_POWERPC64 ? 64 : 32)) | |
7e69e155 MM |
4081 | return 0; |
4082 | ||
4083 | /* Move the address into scratch registers. */ | |
b6c9286a MM |
4084 | dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0)); |
4085 | src_reg = copy_addr_to_reg (XEXP (orig_src, 0)); | |
7e69e155 | 4086 | |
3933e0e1 | 4087 | if (TARGET_STRING) /* string instructions are available */ |
7e69e155 | 4088 | { |
3933e0e1 | 4089 | for ( ; bytes > 0; bytes -= move_bytes) |
7e69e155 | 4090 | { |
3933e0e1 | 4091 | if (bytes > 24 /* move up to 32 bytes at a time */ |
cc0d9ba8 DE |
4092 | && ! fixed_regs[5] |
4093 | && ! fixed_regs[6] | |
4094 | && ! fixed_regs[7] | |
4095 | && ! fixed_regs[8] | |
4096 | && ! fixed_regs[9] | |
4097 | && ! fixed_regs[10] | |
4098 | && ! fixed_regs[11] | |
4099 | && ! fixed_regs[12]) | |
3933e0e1 MM |
4100 | { |
4101 | move_bytes = (bytes > 32) ? 32 : bytes; | |
cc0d9ba8 DE |
4102 | emit_insn (gen_movstrsi_8reg (expand_block_move_mem (BLKmode, |
4103 | dest_reg, | |
4104 | orig_dest), | |
4105 | expand_block_move_mem (BLKmode, | |
4106 | src_reg, | |
4107 | orig_src), | |
4108 | GEN_INT ((move_bytes == 32) | |
4109 | ? 0 : move_bytes), | |
4c64a852 | 4110 | align_rtx)); |
3933e0e1 MM |
4111 | } |
4112 | else if (bytes > 16 /* move up to 24 bytes at a time */ | |
f9562f27 DE |
4113 | && ! fixed_regs[5] |
4114 | && ! fixed_regs[6] | |
cc0d9ba8 DE |
4115 | && ! fixed_regs[7] |
4116 | && ! fixed_regs[8] | |
4117 | && ! fixed_regs[9] | |
f9562f27 | 4118 | && ! fixed_regs[10]) |
3933e0e1 MM |
4119 | { |
4120 | move_bytes = (bytes > 24) ? 24 : bytes; | |
cc0d9ba8 DE |
4121 | emit_insn (gen_movstrsi_6reg (expand_block_move_mem (BLKmode, |
4122 | dest_reg, | |
4123 | orig_dest), | |
4124 | expand_block_move_mem (BLKmode, | |
4125 | src_reg, | |
4126 | orig_src), | |
3933e0e1 | 4127 | GEN_INT (move_bytes), |
4c64a852 | 4128 | align_rtx)); |
3933e0e1 MM |
4129 | } |
4130 | else if (bytes > 8 /* move up to 16 bytes at a time */ | |
f9562f27 DE |
4131 | && ! fixed_regs[5] |
4132 | && ! fixed_regs[6] | |
4133 | && ! fixed_regs[7] | |
4134 | && ! fixed_regs[8]) | |
3933e0e1 MM |
4135 | { |
4136 | move_bytes = (bytes > 16) ? 16 : bytes; | |
cc0d9ba8 DE |
4137 | emit_insn (gen_movstrsi_4reg (expand_block_move_mem (BLKmode, |
4138 | dest_reg, | |
4139 | orig_dest), | |
4140 | expand_block_move_mem (BLKmode, | |
4141 | src_reg, | |
4142 | orig_src), | |
3933e0e1 | 4143 | GEN_INT (move_bytes), |
4c64a852 | 4144 | align_rtx)); |
3933e0e1 | 4145 | } |
acad7ed3 | 4146 | else if (bytes >= 8 && TARGET_POWERPC64 |
a4f6c312 | 4147 | /* 64-bit loads and stores require word-aligned |
82e41834 | 4148 | displacements. */ |
a4f6c312 | 4149 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) |
acad7ed3 DE |
4150 | { |
4151 | move_bytes = 8; | |
4152 | tmp_reg = gen_reg_rtx (DImode); | |
4153 | emit_move_insn (tmp_reg, | |
4154 | expand_block_move_mem (DImode, | |
2eba1afa | 4155 | src_reg, orig_src)); |
acad7ed3 | 4156 | emit_move_insn (expand_block_move_mem (DImode, |
2eba1afa | 4157 | dest_reg, orig_dest), |
acad7ed3 DE |
4158 | tmp_reg); |
4159 | } | |
09a625f7 | 4160 | else if (bytes > 4 && !TARGET_POWERPC64) |
3933e0e1 MM |
4161 | { /* move up to 8 bytes at a time */ |
4162 | move_bytes = (bytes > 8) ? 8 : bytes; | |
cc0d9ba8 DE |
4163 | emit_insn (gen_movstrsi_2reg (expand_block_move_mem (BLKmode, |
4164 | dest_reg, | |
4165 | orig_dest), | |
4166 | expand_block_move_mem (BLKmode, | |
4167 | src_reg, | |
4168 | orig_src), | |
3933e0e1 | 4169 | GEN_INT (move_bytes), |
4c64a852 | 4170 | align_rtx)); |
3933e0e1 | 4171 | } |
cc0d9ba8 | 4172 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
4173 | { /* move 4 bytes */ |
4174 | move_bytes = 4; | |
4175 | tmp_reg = gen_reg_rtx (SImode); | |
cc0d9ba8 DE |
4176 | emit_move_insn (tmp_reg, |
4177 | expand_block_move_mem (SImode, | |
4178 | src_reg, orig_src)); | |
4179 | emit_move_insn (expand_block_move_mem (SImode, | |
4180 | dest_reg, orig_dest), | |
4181 | tmp_reg); | |
3933e0e1 | 4182 | } |
cc0d9ba8 | 4183 | else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
4184 | { /* move 2 bytes */ |
4185 | move_bytes = 2; | |
4186 | tmp_reg = gen_reg_rtx (HImode); | |
cc0d9ba8 DE |
4187 | emit_move_insn (tmp_reg, |
4188 | expand_block_move_mem (HImode, | |
4189 | src_reg, orig_src)); | |
4190 | emit_move_insn (expand_block_move_mem (HImode, | |
4191 | dest_reg, orig_dest), | |
4192 | tmp_reg); | |
3933e0e1 MM |
4193 | } |
4194 | else if (bytes == 1) /* move 1 byte */ | |
4195 | { | |
4196 | move_bytes = 1; | |
4197 | tmp_reg = gen_reg_rtx (QImode); | |
cc0d9ba8 DE |
4198 | emit_move_insn (tmp_reg, |
4199 | expand_block_move_mem (QImode, | |
4200 | src_reg, orig_src)); | |
4201 | emit_move_insn (expand_block_move_mem (QImode, | |
4202 | dest_reg, orig_dest), | |
4203 | tmp_reg); | |
3933e0e1 MM |
4204 | } |
4205 | else | |
4206 | { /* move up to 4 bytes at a time */ | |
4207 | move_bytes = (bytes > 4) ? 4 : bytes; | |
cc0d9ba8 DE |
4208 | emit_insn (gen_movstrsi_1reg (expand_block_move_mem (BLKmode, |
4209 | dest_reg, | |
4210 | orig_dest), | |
4211 | expand_block_move_mem (BLKmode, | |
4212 | src_reg, | |
4213 | orig_src), | |
3933e0e1 | 4214 | GEN_INT (move_bytes), |
4c64a852 | 4215 | align_rtx)); |
3933e0e1 | 4216 | } |
4c64a852 | 4217 | |
015892ee RK |
4218 | if (bytes > move_bytes) |
4219 | { | |
cc0d9ba8 DE |
4220 | if (! TARGET_POWERPC64) |
4221 | { | |
4222 | emit_insn (gen_addsi3 (src_reg, src_reg, | |
4223 | GEN_INT (move_bytes))); | |
4224 | emit_insn (gen_addsi3 (dest_reg, dest_reg, | |
4225 | GEN_INT (move_bytes))); | |
4226 | } | |
4227 | else | |
4228 | { | |
4229 | emit_insn (gen_adddi3 (src_reg, src_reg, | |
4230 | GEN_INT (move_bytes))); | |
4231 | emit_insn (gen_adddi3 (dest_reg, dest_reg, | |
4232 | GEN_INT (move_bytes))); | |
4233 | } | |
015892ee | 4234 | } |
4c64a852 | 4235 | } |
3933e0e1 MM |
4236 | } |
4237 | ||
4238 | else /* string instructions not available */ | |
4239 | { | |
4240 | num_reg = offset = 0; | |
4241 | for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes)) | |
7e69e155 | 4242 | { |
3933e0e1 MM |
4243 | /* Calculate the correct offset for src/dest */ |
4244 | if (offset == 0) | |
7e69e155 | 4245 | { |
3933e0e1 MM |
4246 | src_addr = src_reg; |
4247 | dest_addr = dest_reg; | |
4248 | } | |
4249 | else | |
4250 | { | |
c5c76735 JL |
4251 | src_addr = plus_constant (src_reg, offset); |
4252 | dest_addr = plus_constant (dest_reg, offset); | |
3933e0e1 MM |
4253 | } |
4254 | ||
cc0d9ba8 DE |
4255 | /* Generate the appropriate load and store, saving the stores |
4256 | for later. */ | |
4257 | if (bytes >= 8 && TARGET_POWERPC64 | |
a4f6c312 SS |
4258 | /* 64-bit loads and stores require word-aligned |
4259 | displacements. */ | |
cc0d9ba8 | 4260 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) |
b6c9286a MM |
4261 | { |
4262 | move_bytes = 8; | |
4263 | tmp_reg = gen_reg_rtx (DImode); | |
cc0d9ba8 DE |
4264 | emit_insn (gen_movdi (tmp_reg, |
4265 | expand_block_move_mem (DImode, | |
4266 | src_addr, | |
4267 | orig_src))); | |
4268 | stores[num_reg++] = gen_movdi (expand_block_move_mem (DImode, | |
4269 | dest_addr, | |
4270 | orig_dest), | |
4271 | tmp_reg); | |
b6c9286a | 4272 | } |
cc0d9ba8 | 4273 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
4274 | { |
4275 | move_bytes = 4; | |
4276 | tmp_reg = gen_reg_rtx (SImode); | |
cc0d9ba8 DE |
4277 | emit_insn (gen_movsi (tmp_reg, |
4278 | expand_block_move_mem (SImode, | |
4279 | src_addr, | |
4280 | orig_src))); | |
4281 | stores[num_reg++] = gen_movsi (expand_block_move_mem (SImode, | |
4282 | dest_addr, | |
4283 | orig_dest), | |
4284 | tmp_reg); | |
3933e0e1 | 4285 | } |
cc0d9ba8 | 4286 | else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
4287 | { |
4288 | move_bytes = 2; | |
4289 | tmp_reg = gen_reg_rtx (HImode); | |
c81fc13e | 4290 | emit_insn (gen_movhi (tmp_reg, |
cc0d9ba8 DE |
4291 | expand_block_move_mem (HImode, |
4292 | src_addr, | |
4293 | orig_src))); | |
4294 | stores[num_reg++] = gen_movhi (expand_block_move_mem (HImode, | |
4295 | dest_addr, | |
4296 | orig_dest), | |
4297 | tmp_reg); | |
3933e0e1 MM |
4298 | } |
4299 | else | |
4300 | { | |
4301 | move_bytes = 1; | |
4302 | tmp_reg = gen_reg_rtx (QImode); | |
c81fc13e | 4303 | emit_insn (gen_movqi (tmp_reg, |
cc0d9ba8 DE |
4304 | expand_block_move_mem (QImode, |
4305 | src_addr, | |
4306 | orig_src))); | |
4307 | stores[num_reg++] = gen_movqi (expand_block_move_mem (QImode, | |
4308 | dest_addr, | |
4309 | orig_dest), | |
a4f6c312 | 4310 | tmp_reg); |
3933e0e1 MM |
4311 | } |
4312 | ||
4313 | if (num_reg >= MAX_MOVE_REG) | |
4314 | { | |
4315 | for (i = 0; i < num_reg; i++) | |
4316 | emit_insn (stores[i]); | |
4317 | num_reg = 0; | |
7e69e155 MM |
4318 | } |
4319 | } | |
3933e0e1 | 4320 | |
b6c9286a MM |
4321 | for (i = 0; i < num_reg; i++) |
4322 | emit_insn (stores[i]); | |
7e69e155 MM |
4323 | } |
4324 | ||
4325 | return 1; | |
4326 | } | |
4327 | ||
9878760c RK |
4328 | \f |
4329 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
4330 | PARALLEL and the first section will be tested. */ | |
4331 | ||
4332 | int | |
4333 | load_multiple_operation (op, mode) | |
4334 | rtx op; | |
296b8152 | 4335 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
4336 | { |
4337 | int count = XVECLEN (op, 0); | |
e2c953b6 | 4338 | unsigned int dest_regno; |
9878760c RK |
4339 | rtx src_addr; |
4340 | int i; | |
4341 | ||
4342 | /* Perform a quick check so we don't blow up below. */ | |
4343 | if (count <= 1 | |
4344 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
4345 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
4346 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
4347 | return 0; | |
4348 | ||
4349 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
4350 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
4351 | ||
4352 | for (i = 1; i < count; i++) | |
4353 | { | |
4354 | rtx elt = XVECEXP (op, 0, i); | |
4355 | ||
4356 | if (GET_CODE (elt) != SET | |
4357 | || GET_CODE (SET_DEST (elt)) != REG | |
4358 | || GET_MODE (SET_DEST (elt)) != SImode | |
4359 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
4360 | || GET_CODE (SET_SRC (elt)) != MEM | |
4361 | || GET_MODE (SET_SRC (elt)) != SImode | |
4362 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
4363 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
4364 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
4365 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
4366 | return 0; | |
4367 | } | |
4368 | ||
4369 | return 1; | |
4370 | } | |
4371 | ||
4372 | /* Similar, but tests for store multiple. Here, the second vector element | |
4373 | is a CLOBBER. It will be tested later. */ | |
4374 | ||
4375 | int | |
4376 | store_multiple_operation (op, mode) | |
4377 | rtx op; | |
296b8152 | 4378 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
4379 | { |
4380 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 4381 | unsigned int src_regno; |
9878760c RK |
4382 | rtx dest_addr; |
4383 | int i; | |
4384 | ||
4385 | /* Perform a quick check so we don't blow up below. */ | |
4386 | if (count <= 1 | |
4387 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
4388 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
4389 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
4390 | return 0; | |
4391 | ||
4392 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
4393 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
4394 | ||
4395 | for (i = 1; i < count; i++) | |
4396 | { | |
4397 | rtx elt = XVECEXP (op, 0, i + 1); | |
4398 | ||
4399 | if (GET_CODE (elt) != SET | |
4400 | || GET_CODE (SET_SRC (elt)) != REG | |
4401 | || GET_MODE (SET_SRC (elt)) != SImode | |
4402 | || REGNO (SET_SRC (elt)) != src_regno + i | |
4403 | || GET_CODE (SET_DEST (elt)) != MEM | |
4404 | || GET_MODE (SET_DEST (elt)) != SImode | |
4405 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
4406 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
4407 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
4408 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
4409 | return 0; | |
4410 | } | |
4411 | ||
4412 | return 1; | |
4413 | } | |
9ebbca7d | 4414 | |
00b960c7 AH |
4415 | /* Return 1 for a parallel vrsave operation. */ |
4416 | ||
4417 | int | |
4418 | vrsave_operation (op, mode) | |
4419 | rtx op; | |
4420 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4421 | { | |
4422 | int count = XVECLEN (op, 0); | |
4423 | unsigned int dest_regno, src_regno; | |
4424 | int i; | |
4425 | ||
4426 | if (count <= 1 | |
4427 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
4428 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
4429 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC) | |
4430 | return 0; | |
4431 | ||
4432 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
4433 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
4434 | ||
4435 | if (dest_regno != VRSAVE_REGNO | |
4436 | && src_regno != VRSAVE_REGNO) | |
4437 | return 0; | |
4438 | ||
4439 | for (i = 1; i < count; i++) | |
4440 | { | |
4441 | rtx elt = XVECEXP (op, 0, i); | |
4442 | ||
4443 | if (GET_CODE (elt) != CLOBBER) | |
4444 | return 0; | |
4445 | } | |
4446 | ||
4447 | return 1; | |
4448 | } | |
4449 | ||
a4f6c312 | 4450 | /* Return 1 for an PARALLEL suitable for mtcrf. */ |
9ebbca7d GK |
4451 | |
4452 | int | |
4453 | mtcrf_operation (op, mode) | |
4454 | rtx op; | |
4455 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4456 | { | |
4457 | int count = XVECLEN (op, 0); | |
4458 | int i; | |
9ebbca7d GK |
4459 | rtx src_reg; |
4460 | ||
4461 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
4462 | if (count < 1 |
4463 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
4464 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
4465 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 4466 | return 0; |
e35b9579 | 4467 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
9ebbca7d GK |
4468 | |
4469 | if (GET_CODE (src_reg) != REG | |
4470 | || GET_MODE (src_reg) != SImode | |
4471 | || ! INT_REGNO_P (REGNO (src_reg))) | |
4472 | return 0; | |
4473 | ||
e35b9579 | 4474 | for (i = 0; i < count; i++) |
9ebbca7d GK |
4475 | { |
4476 | rtx exp = XVECEXP (op, 0, i); | |
4477 | rtx unspec; | |
4478 | int maskval; | |
4479 | ||
4480 | if (GET_CODE (exp) != SET | |
4481 | || GET_CODE (SET_DEST (exp)) != REG | |
4482 | || GET_MODE (SET_DEST (exp)) != CCmode | |
4483 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
4484 | return 0; | |
4485 | unspec = SET_SRC (exp); | |
4486 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
9ebbca7d GK |
4487 | |
4488 | if (GET_CODE (unspec) != UNSPEC | |
4489 | || XINT (unspec, 1) != 20 | |
4490 | || XVECLEN (unspec, 0) != 2 | |
4491 | || XVECEXP (unspec, 0, 0) != src_reg | |
4492 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
4493 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
4494 | return 0; | |
4495 | } | |
e35b9579 | 4496 | return 1; |
9ebbca7d GK |
4497 | } |
4498 | ||
a4f6c312 | 4499 | /* Return 1 for an PARALLEL suitable for lmw. */ |
9ebbca7d GK |
4500 | |
4501 | int | |
4502 | lmw_operation (op, mode) | |
4503 | rtx op; | |
4504 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4505 | { | |
4506 | int count = XVECLEN (op, 0); | |
e2c953b6 | 4507 | unsigned int dest_regno; |
9ebbca7d | 4508 | rtx src_addr; |
e2c953b6 | 4509 | unsigned int base_regno; |
9ebbca7d GK |
4510 | HOST_WIDE_INT offset; |
4511 | int i; | |
4512 | ||
4513 | /* Perform a quick check so we don't blow up below. */ | |
4514 | if (count <= 1 | |
4515 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
4516 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
4517 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
4518 | return 0; | |
4519 | ||
4520 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
4521 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
4522 | ||
4523 | if (dest_regno > 31 | |
e2c953b6 | 4524 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
4525 | return 0; |
4526 | ||
258bfae2 | 4527 | if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0)) |
9ebbca7d GK |
4528 | { |
4529 | offset = 0; | |
4530 | base_regno = REGNO (src_addr); | |
4531 | if (base_regno == 0) | |
4532 | return 0; | |
4533 | } | |
258bfae2 | 4534 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0)) |
9ebbca7d GK |
4535 | { |
4536 | offset = INTVAL (XEXP (src_addr, 1)); | |
4537 | base_regno = REGNO (XEXP (src_addr, 0)); | |
4538 | } | |
4539 | else | |
4540 | return 0; | |
4541 | ||
4542 | for (i = 0; i < count; i++) | |
4543 | { | |
4544 | rtx elt = XVECEXP (op, 0, i); | |
4545 | rtx newaddr; | |
4546 | rtx addr_reg; | |
4547 | HOST_WIDE_INT newoffset; | |
4548 | ||
4549 | if (GET_CODE (elt) != SET | |
4550 | || GET_CODE (SET_DEST (elt)) != REG | |
4551 | || GET_MODE (SET_DEST (elt)) != SImode | |
4552 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
4553 | || GET_CODE (SET_SRC (elt)) != MEM | |
4554 | || GET_MODE (SET_SRC (elt)) != SImode) | |
4555 | return 0; | |
4556 | newaddr = XEXP (SET_SRC (elt), 0); | |
258bfae2 | 4557 | if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0)) |
9ebbca7d GK |
4558 | { |
4559 | newoffset = 0; | |
4560 | addr_reg = newaddr; | |
4561 | } | |
258bfae2 | 4562 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0)) |
9ebbca7d GK |
4563 | { |
4564 | addr_reg = XEXP (newaddr, 0); | |
4565 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
4566 | } | |
4567 | else | |
4568 | return 0; | |
4569 | if (REGNO (addr_reg) != base_regno | |
4570 | || newoffset != offset + 4 * i) | |
4571 | return 0; | |
4572 | } | |
4573 | ||
4574 | return 1; | |
4575 | } | |
4576 | ||
a4f6c312 | 4577 | /* Return 1 for an PARALLEL suitable for stmw. */ |
9ebbca7d GK |
4578 | |
4579 | int | |
4580 | stmw_operation (op, mode) | |
4581 | rtx op; | |
4582 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4583 | { | |
4584 | int count = XVECLEN (op, 0); | |
e2c953b6 | 4585 | unsigned int src_regno; |
9ebbca7d | 4586 | rtx dest_addr; |
e2c953b6 | 4587 | unsigned int base_regno; |
9ebbca7d GK |
4588 | HOST_WIDE_INT offset; |
4589 | int i; | |
4590 | ||
4591 | /* Perform a quick check so we don't blow up below. */ | |
4592 | if (count <= 1 | |
4593 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
4594 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
4595 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
4596 | return 0; | |
4597 | ||
4598 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
4599 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
4600 | ||
4601 | if (src_regno > 31 | |
e2c953b6 | 4602 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
4603 | return 0; |
4604 | ||
258bfae2 | 4605 | if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0)) |
9ebbca7d GK |
4606 | { |
4607 | offset = 0; | |
4608 | base_regno = REGNO (dest_addr); | |
4609 | if (base_regno == 0) | |
4610 | return 0; | |
4611 | } | |
258bfae2 | 4612 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0)) |
9ebbca7d GK |
4613 | { |
4614 | offset = INTVAL (XEXP (dest_addr, 1)); | |
4615 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
4616 | } | |
4617 | else | |
4618 | return 0; | |
4619 | ||
4620 | for (i = 0; i < count; i++) | |
4621 | { | |
4622 | rtx elt = XVECEXP (op, 0, i); | |
4623 | rtx newaddr; | |
4624 | rtx addr_reg; | |
4625 | HOST_WIDE_INT newoffset; | |
4626 | ||
4627 | if (GET_CODE (elt) != SET | |
4628 | || GET_CODE (SET_SRC (elt)) != REG | |
4629 | || GET_MODE (SET_SRC (elt)) != SImode | |
4630 | || REGNO (SET_SRC (elt)) != src_regno + i | |
4631 | || GET_CODE (SET_DEST (elt)) != MEM | |
4632 | || GET_MODE (SET_DEST (elt)) != SImode) | |
4633 | return 0; | |
4634 | newaddr = XEXP (SET_DEST (elt), 0); | |
258bfae2 | 4635 | if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0)) |
9ebbca7d GK |
4636 | { |
4637 | newoffset = 0; | |
4638 | addr_reg = newaddr; | |
4639 | } | |
258bfae2 | 4640 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0)) |
9ebbca7d GK |
4641 | { |
4642 | addr_reg = XEXP (newaddr, 0); | |
4643 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
4644 | } | |
4645 | else | |
4646 | return 0; | |
4647 | if (REGNO (addr_reg) != base_regno | |
4648 | || newoffset != offset + 4 * i) | |
4649 | return 0; | |
4650 | } | |
4651 | ||
4652 | return 1; | |
4653 | } | |
9878760c | 4654 | \f |
a4f6c312 SS |
4655 | /* A validation routine: say whether CODE, a condition code, and MODE |
4656 | match. The other alternatives either don't make sense or should | |
4657 | never be generated. */ | |
39a10a29 | 4658 | |
39a10a29 GK |
4659 | static void |
4660 | validate_condition_mode (code, mode) | |
4661 | enum rtx_code code; | |
4662 | enum machine_mode mode; | |
4663 | { | |
4664 | if (GET_RTX_CLASS (code) != '<' | |
4665 | || GET_MODE_CLASS (mode) != MODE_CC) | |
4666 | abort (); | |
4667 | ||
4668 | /* These don't make sense. */ | |
4669 | if ((code == GT || code == LT || code == GE || code == LE) | |
4670 | && mode == CCUNSmode) | |
4671 | abort (); | |
4672 | ||
4673 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
4674 | && mode != CCUNSmode) | |
4675 | abort (); | |
4676 | ||
4677 | if (mode != CCFPmode | |
4678 | && (code == ORDERED || code == UNORDERED | |
4679 | || code == UNEQ || code == LTGT | |
4680 | || code == UNGT || code == UNLT | |
4681 | || code == UNGE || code == UNLE)) | |
a4f6c312 | 4682 | abort (); |
39a10a29 | 4683 | |
de6c5979 BL |
4684 | /* These should never be generated except for |
4685 | flag_unsafe_math_optimizations. */ | |
39a10a29 | 4686 | if (mode == CCFPmode |
de6c5979 | 4687 | && ! flag_unsafe_math_optimizations |
39a10a29 GK |
4688 | && (code == LE || code == GE |
4689 | || code == UNEQ || code == LTGT | |
4690 | || code == UNGT || code == UNLT)) | |
4691 | abort (); | |
4692 | ||
4693 | /* These are invalid; the information is not there. */ | |
4694 | if (mode == CCEQmode | |
4695 | && code != EQ && code != NE) | |
4696 | abort (); | |
4697 | } | |
4698 | ||
9878760c RK |
4699 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
4700 | We only check the opcode against the mode of the CC value here. */ | |
4701 | ||
4702 | int | |
4703 | branch_comparison_operator (op, mode) | |
592696dd | 4704 | rtx op; |
296b8152 | 4705 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
4706 | { |
4707 | enum rtx_code code = GET_CODE (op); | |
4708 | enum machine_mode cc_mode; | |
4709 | ||
4710 | if (GET_RTX_CLASS (code) != '<') | |
4711 | return 0; | |
4712 | ||
4713 | cc_mode = GET_MODE (XEXP (op, 0)); | |
4714 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
4715 | return 0; | |
4716 | ||
39a10a29 | 4717 | validate_condition_mode (code, cc_mode); |
9878760c | 4718 | |
39a10a29 GK |
4719 | return 1; |
4720 | } | |
4721 | ||
4722 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
4723 | insn and which is true if the corresponding bit in the CC register | |
4724 | is set. */ | |
4725 | ||
4726 | int | |
4727 | branch_positive_comparison_operator (op, mode) | |
592696dd | 4728 | rtx op; |
39a10a29 GK |
4729 | enum machine_mode mode; |
4730 | { | |
4731 | enum rtx_code code; | |
4732 | ||
4733 | if (! branch_comparison_operator (op, mode)) | |
9878760c RK |
4734 | return 0; |
4735 | ||
39a10a29 GK |
4736 | code = GET_CODE (op); |
4737 | return (code == EQ || code == LT || code == GT | |
4738 | || code == LTU || code == GTU | |
4739 | || code == UNORDERED); | |
9878760c RK |
4740 | } |
4741 | ||
4742 | /* Return 1 if OP is a comparison operation that is valid for an scc insn. | |
4743 | We check the opcode against the mode of the CC value and disallow EQ or | |
4744 | NE comparisons for integers. */ | |
4745 | ||
4746 | int | |
4747 | scc_comparison_operator (op, mode) | |
592696dd | 4748 | rtx op; |
9878760c RK |
4749 | enum machine_mode mode; |
4750 | { | |
4751 | enum rtx_code code = GET_CODE (op); | |
4752 | enum machine_mode cc_mode; | |
4753 | ||
4754 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4755 | return 0; | |
4756 | ||
4757 | if (GET_RTX_CLASS (code) != '<') | |
4758 | return 0; | |
4759 | ||
4760 | cc_mode = GET_MODE (XEXP (op, 0)); | |
4761 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
4762 | return 0; | |
4763 | ||
39a10a29 | 4764 | validate_condition_mode (code, cc_mode); |
9878760c | 4765 | |
39a10a29 | 4766 | if (code == NE && cc_mode != CCFPmode) |
c5defebb RK |
4767 | return 0; |
4768 | ||
9878760c RK |
4769 | return 1; |
4770 | } | |
e0cd0770 JC |
4771 | |
4772 | int | |
4773 | trap_comparison_operator (op, mode) | |
4774 | rtx op; | |
4775 | enum machine_mode mode; | |
4776 | { | |
4777 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
4778 | return 0; | |
39a10a29 | 4779 | return GET_RTX_CLASS (GET_CODE (op)) == '<'; |
e0cd0770 | 4780 | } |
dfbdccdb GK |
4781 | |
4782 | int | |
4783 | boolean_operator (op, mode) | |
4784 | rtx op; | |
4785 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4786 | { | |
4787 | enum rtx_code code = GET_CODE (op); | |
4788 | return (code == AND || code == IOR || code == XOR); | |
4789 | } | |
1d328b19 GK |
4790 | |
4791 | int | |
4792 | boolean_or_operator (op, mode) | |
4793 | rtx op; | |
4794 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4795 | { | |
4796 | enum rtx_code code = GET_CODE (op); | |
4797 | return (code == IOR || code == XOR); | |
4798 | } | |
50a0b056 GK |
4799 | |
4800 | int | |
4801 | min_max_operator (op, mode) | |
4802 | rtx op; | |
4803 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4804 | { | |
4805 | enum rtx_code code = GET_CODE (op); | |
4806 | return (code == SMIN || code == SMAX || code == UMIN || code == UMAX); | |
4807 | } | |
9878760c RK |
4808 | \f |
4809 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
4810 | mask required to convert the result of a rotate insn into a shift | |
4811 | left insn of SHIFTOP bits. Both are known to be CONST_INT. */ | |
4812 | ||
4813 | int | |
4814 | includes_lshift_p (shiftop, andop) | |
592696dd SS |
4815 | rtx shiftop; |
4816 | rtx andop; | |
9878760c | 4817 | { |
e2c953b6 DE |
4818 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
4819 | ||
4820 | shift_mask <<= INTVAL (shiftop); | |
9878760c RK |
4821 | |
4822 | return (INTVAL (andop) & ~shift_mask) == 0; | |
4823 | } | |
4824 | ||
4825 | /* Similar, but for right shift. */ | |
4826 | ||
4827 | int | |
4828 | includes_rshift_p (shiftop, andop) | |
592696dd SS |
4829 | rtx shiftop; |
4830 | rtx andop; | |
9878760c | 4831 | { |
a7653a2c | 4832 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
4833 | |
4834 | shift_mask >>= INTVAL (shiftop); | |
4835 | ||
e2c953b6 DE |
4836 | return (INTVAL (andop) & ~shift_mask) == 0; |
4837 | } | |
4838 | ||
c5059423 AM |
4839 | /* Return 1 if ANDOP is a mask suitable for use with an rldic insn |
4840 | to perform a left shift. It must have exactly SHIFTOP least | |
4841 | signifigant 0's, then one or more 1's, then zero or more 0's. */ | |
e2c953b6 DE |
4842 | |
4843 | int | |
c5059423 | 4844 | includes_rldic_lshift_p (shiftop, andop) |
592696dd SS |
4845 | rtx shiftop; |
4846 | rtx andop; | |
e2c953b6 | 4847 | { |
c5059423 AM |
4848 | if (GET_CODE (andop) == CONST_INT) |
4849 | { | |
02071907 | 4850 | HOST_WIDE_INT c, lsb, shift_mask; |
e2c953b6 | 4851 | |
c5059423 | 4852 | c = INTVAL (andop); |
02071907 | 4853 | if (c == 0 || c == ~0) |
c5059423 | 4854 | return 0; |
e2c953b6 | 4855 | |
02071907 | 4856 | shift_mask = ~0; |
c5059423 AM |
4857 | shift_mask <<= INTVAL (shiftop); |
4858 | ||
4859 | /* Find the least signifigant one bit. */ | |
4860 | lsb = c & -c; | |
4861 | ||
4862 | /* It must coincide with the LSB of the shift mask. */ | |
4863 | if (-lsb != shift_mask) | |
4864 | return 0; | |
e2c953b6 | 4865 | |
c5059423 AM |
4866 | /* Invert to look for the next transition (if any). */ |
4867 | c = ~c; | |
4868 | ||
4869 | /* Remove the low group of ones (originally low group of zeros). */ | |
4870 | c &= -lsb; | |
4871 | ||
4872 | /* Again find the lsb, and check we have all 1's above. */ | |
4873 | lsb = c & -c; | |
4874 | return c == -lsb; | |
4875 | } | |
4876 | else if (GET_CODE (andop) == CONST_DOUBLE | |
4877 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
4878 | { | |
02071907 AM |
4879 | HOST_WIDE_INT low, high, lsb; |
4880 | HOST_WIDE_INT shift_mask_low, shift_mask_high; | |
c5059423 AM |
4881 | |
4882 | low = CONST_DOUBLE_LOW (andop); | |
4883 | if (HOST_BITS_PER_WIDE_INT < 64) | |
4884 | high = CONST_DOUBLE_HIGH (andop); | |
4885 | ||
4886 | if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)) | |
02071907 | 4887 | || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0))) |
c5059423 AM |
4888 | return 0; |
4889 | ||
4890 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
4891 | { | |
02071907 | 4892 | shift_mask_high = ~0; |
c5059423 AM |
4893 | if (INTVAL (shiftop) > 32) |
4894 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
4895 | ||
4896 | lsb = high & -high; | |
4897 | ||
4898 | if (-lsb != shift_mask_high || INTVAL (shiftop) < 32) | |
4899 | return 0; | |
4900 | ||
4901 | high = ~high; | |
4902 | high &= -lsb; | |
4903 | ||
4904 | lsb = high & -high; | |
4905 | return high == -lsb; | |
4906 | } | |
4907 | ||
02071907 | 4908 | shift_mask_low = ~0; |
c5059423 AM |
4909 | shift_mask_low <<= INTVAL (shiftop); |
4910 | ||
4911 | lsb = low & -low; | |
4912 | ||
4913 | if (-lsb != shift_mask_low) | |
4914 | return 0; | |
4915 | ||
4916 | if (HOST_BITS_PER_WIDE_INT < 64) | |
4917 | high = ~high; | |
4918 | low = ~low; | |
4919 | low &= -lsb; | |
4920 | ||
4921 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
4922 | { | |
4923 | lsb = high & -high; | |
4924 | return high == -lsb; | |
4925 | } | |
4926 | ||
4927 | lsb = low & -low; | |
4928 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
4929 | } | |
4930 | else | |
4931 | return 0; | |
4932 | } | |
e2c953b6 | 4933 | |
c5059423 AM |
4934 | /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn |
4935 | to perform a left shift. It must have SHIFTOP or more least | |
4936 | signifigant 0's, with the remainder of the word 1's. */ | |
e2c953b6 | 4937 | |
c5059423 AM |
4938 | int |
4939 | includes_rldicr_lshift_p (shiftop, andop) | |
592696dd SS |
4940 | rtx shiftop; |
4941 | rtx andop; | |
c5059423 | 4942 | { |
e2c953b6 | 4943 | if (GET_CODE (andop) == CONST_INT) |
c5059423 | 4944 | { |
02071907 | 4945 | HOST_WIDE_INT c, lsb, shift_mask; |
c5059423 | 4946 | |
02071907 | 4947 | shift_mask = ~0; |
c5059423 AM |
4948 | shift_mask <<= INTVAL (shiftop); |
4949 | c = INTVAL (andop); | |
4950 | ||
4951 | /* Find the least signifigant one bit. */ | |
4952 | lsb = c & -c; | |
4953 | ||
4954 | /* It must be covered by the shift mask. | |
a4f6c312 | 4955 | This test also rejects c == 0. */ |
c5059423 AM |
4956 | if ((lsb & shift_mask) == 0) |
4957 | return 0; | |
4958 | ||
4959 | /* Check we have all 1's above the transition, and reject all 1's. */ | |
4960 | return c == -lsb && lsb != 1; | |
4961 | } | |
4962 | else if (GET_CODE (andop) == CONST_DOUBLE | |
4963 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
4964 | { | |
02071907 | 4965 | HOST_WIDE_INT low, lsb, shift_mask_low; |
c5059423 AM |
4966 | |
4967 | low = CONST_DOUBLE_LOW (andop); | |
4968 | ||
4969 | if (HOST_BITS_PER_WIDE_INT < 64) | |
4970 | { | |
02071907 | 4971 | HOST_WIDE_INT high, shift_mask_high; |
c5059423 AM |
4972 | |
4973 | high = CONST_DOUBLE_HIGH (andop); | |
4974 | ||
4975 | if (low == 0) | |
4976 | { | |
02071907 | 4977 | shift_mask_high = ~0; |
c5059423 AM |
4978 | if (INTVAL (shiftop) > 32) |
4979 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
4980 | ||
4981 | lsb = high & -high; | |
4982 | ||
4983 | if ((lsb & shift_mask_high) == 0) | |
4984 | return 0; | |
4985 | ||
4986 | return high == -lsb; | |
4987 | } | |
4988 | if (high != ~0) | |
4989 | return 0; | |
4990 | } | |
4991 | ||
02071907 | 4992 | shift_mask_low = ~0; |
c5059423 AM |
4993 | shift_mask_low <<= INTVAL (shiftop); |
4994 | ||
4995 | lsb = low & -low; | |
4996 | ||
4997 | if ((lsb & shift_mask_low) == 0) | |
4998 | return 0; | |
4999 | ||
5000 | return low == -lsb && lsb != 1; | |
5001 | } | |
e2c953b6 | 5002 | else |
c5059423 | 5003 | return 0; |
9878760c | 5004 | } |
35068b43 RK |
5005 | |
5006 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates | |
5007 | for lfq and stfq insns. | |
5008 | ||
5009 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
5010 | abort if we are passed pseudo registers. */ | |
5011 | ||
5012 | int | |
5013 | registers_ok_for_quad_peep (reg1, reg2) | |
5014 | rtx reg1, reg2; | |
5015 | { | |
5016 | /* We might have been passed a SUBREG. */ | |
5017 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
5018 | return 0; | |
5019 | ||
5020 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
5021 | } | |
5022 | ||
a4f6c312 SS |
5023 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. |
5024 | addr1 and addr2 must be in consecutive memory locations | |
5025 | (addr2 == addr1 + 8). */ | |
35068b43 RK |
5026 | |
5027 | int | |
5028 | addrs_ok_for_quad_peep (addr1, addr2) | |
592696dd SS |
5029 | rtx addr1; |
5030 | rtx addr2; | |
35068b43 | 5031 | { |
e2c953b6 | 5032 | unsigned int reg1; |
35068b43 RK |
5033 | int offset1; |
5034 | ||
5035 | /* Extract an offset (if used) from the first addr. */ | |
5036 | if (GET_CODE (addr1) == PLUS) | |
5037 | { | |
5038 | /* If not a REG, return zero. */ | |
5039 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
5040 | return 0; | |
5041 | else | |
5042 | { | |
5043 | reg1 = REGNO (XEXP (addr1, 0)); | |
5044 | /* The offset must be constant! */ | |
5045 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
5046 | return 0; | |
5047 | offset1 = INTVAL (XEXP (addr1, 1)); | |
5048 | } | |
5049 | } | |
5050 | else if (GET_CODE (addr1) != REG) | |
5051 | return 0; | |
5052 | else | |
5053 | { | |
5054 | reg1 = REGNO (addr1); | |
5055 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
5056 | offset1 = 0; | |
5057 | } | |
5058 | ||
acad7ed3 | 5059 | /* Make sure the second address is a (mem (plus (reg) (const_int))). */ |
35068b43 RK |
5060 | if (GET_CODE (addr2) != PLUS) |
5061 | return 0; | |
5062 | ||
5063 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
5064 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
5065 | return 0; | |
5066 | ||
5067 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
5068 | return 0; | |
5069 | ||
5070 | /* The offset for the second addr must be 8 more than the first addr. */ | |
5071 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
5072 | return 0; | |
5073 | ||
5074 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
5075 | instructions. */ | |
5076 | return 1; | |
5077 | } | |
9878760c RK |
5078 | \f |
5079 | /* Return the register class of a scratch register needed to copy IN into | |
5080 | or out of a register in CLASS in MODE. If it can be done directly, | |
5081 | NO_REGS is returned. */ | |
5082 | ||
5083 | enum reg_class | |
5084 | secondary_reload_class (class, mode, in) | |
5085 | enum reg_class class; | |
296b8152 | 5086 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
5087 | rtx in; |
5088 | { | |
5accd822 | 5089 | int regno; |
9878760c | 5090 | |
46fad5b7 DJ |
5091 | if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN && flag_pic)) |
5092 | { | |
5093 | /* We cannot copy a symbolic operand directly into anything | |
5094 | other than BASE_REGS for TARGET_ELF. So indicate that a | |
5095 | register from BASE_REGS is needed as an intermediate | |
5096 | register. | |
5097 | ||
5098 | On Darwin, pic addresses require a load from memory, which | |
5099 | needs a base register. */ | |
5100 | if (class != BASE_REGS | |
5101 | && (GET_CODE (in) == SYMBOL_REF | |
5102 | || GET_CODE (in) == HIGH | |
5103 | || GET_CODE (in) == LABEL_REF | |
5104 | || GET_CODE (in) == CONST)) | |
5105 | return BASE_REGS; | |
5106 | } | |
e7b7998a | 5107 | |
5accd822 DE |
5108 | if (GET_CODE (in) == REG) |
5109 | { | |
5110 | regno = REGNO (in); | |
5111 | if (regno >= FIRST_PSEUDO_REGISTER) | |
5112 | { | |
5113 | regno = true_regnum (in); | |
5114 | if (regno >= FIRST_PSEUDO_REGISTER) | |
5115 | regno = -1; | |
5116 | } | |
5117 | } | |
5118 | else if (GET_CODE (in) == SUBREG) | |
5119 | { | |
5120 | regno = true_regnum (in); | |
5121 | if (regno >= FIRST_PSEUDO_REGISTER) | |
5122 | regno = -1; | |
5123 | } | |
5124 | else | |
5125 | regno = -1; | |
5126 | ||
9878760c RK |
5127 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
5128 | into anything. */ | |
5129 | if (class == GENERAL_REGS || class == BASE_REGS | |
5130 | || (regno >= 0 && INT_REGNO_P (regno))) | |
5131 | return NO_REGS; | |
5132 | ||
5133 | /* Constants, memory, and FP registers can go into FP registers. */ | |
5134 | if ((regno == -1 || FP_REGNO_P (regno)) | |
5135 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
5136 | return NO_REGS; | |
5137 | ||
0ac081f6 AH |
5138 | /* Memory, and AltiVec registers can go into AltiVec registers. */ |
5139 | if ((regno == -1 || ALTIVEC_REGNO_P (regno)) | |
5140 | && class == ALTIVEC_REGS) | |
5141 | return NO_REGS; | |
5142 | ||
9878760c RK |
5143 | /* We can copy among the CR registers. */ |
5144 | if ((class == CR_REGS || class == CR0_REGS) | |
5145 | && regno >= 0 && CR_REGNO_P (regno)) | |
5146 | return NO_REGS; | |
5147 | ||
5148 | /* Otherwise, we need GENERAL_REGS. */ | |
5149 | return GENERAL_REGS; | |
5150 | } | |
5151 | \f | |
5152 | /* Given a comparison operation, return the bit number in CCR to test. We | |
5153 | know this is a valid comparison. | |
5154 | ||
5155 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
5156 | used instead of %C, so the bits will be in different places. | |
5157 | ||
b4ac57ab | 5158 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
5159 | |
5160 | int | |
5161 | ccr_bit (op, scc_p) | |
592696dd | 5162 | rtx op; |
9878760c RK |
5163 | int scc_p; |
5164 | { | |
5165 | enum rtx_code code = GET_CODE (op); | |
5166 | enum machine_mode cc_mode; | |
5167 | int cc_regnum; | |
5168 | int base_bit; | |
9ebbca7d | 5169 | rtx reg; |
9878760c RK |
5170 | |
5171 | if (GET_RTX_CLASS (code) != '<') | |
5172 | return -1; | |
5173 | ||
9ebbca7d GK |
5174 | reg = XEXP (op, 0); |
5175 | ||
5176 | if (GET_CODE (reg) != REG | |
5177 | || ! CR_REGNO_P (REGNO (reg))) | |
5178 | abort (); | |
5179 | ||
5180 | cc_mode = GET_MODE (reg); | |
5181 | cc_regnum = REGNO (reg); | |
5182 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 5183 | |
39a10a29 | 5184 | validate_condition_mode (code, cc_mode); |
c5defebb | 5185 | |
9878760c RK |
5186 | switch (code) |
5187 | { | |
5188 | case NE: | |
5189 | return scc_p ? base_bit + 3 : base_bit + 2; | |
5190 | case EQ: | |
5191 | return base_bit + 2; | |
1c882ea4 | 5192 | case GT: case GTU: case UNLE: |
9878760c | 5193 | return base_bit + 1; |
1c882ea4 | 5194 | case LT: case LTU: case UNGE: |
9878760c | 5195 | return base_bit; |
1c882ea4 GK |
5196 | case ORDERED: case UNORDERED: |
5197 | return base_bit + 3; | |
9878760c RK |
5198 | |
5199 | case GE: case GEU: | |
39a10a29 | 5200 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
5201 | unordered position. So test that bit. For integer, this is ! LT |
5202 | unless this is an scc insn. */ | |
39a10a29 | 5203 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
5204 | |
5205 | case LE: case LEU: | |
39a10a29 | 5206 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 5207 | |
9878760c RK |
5208 | default: |
5209 | abort (); | |
5210 | } | |
5211 | } | |
1ff7789b | 5212 | \f |
8d30c4ee | 5213 | /* Return the GOT register. */ |
1ff7789b MM |
5214 | |
5215 | struct rtx_def * | |
5216 | rs6000_got_register (value) | |
5f59ecb7 | 5217 | rtx value ATTRIBUTE_UNUSED; |
1ff7789b | 5218 | { |
a4f6c312 SS |
5219 | /* The second flow pass currently (June 1999) can't update |
5220 | regs_ever_live without disturbing other parts of the compiler, so | |
5221 | update it here to make the prolog/epilogue code happy. */ | |
3cb999d8 | 5222 | if (no_new_pseudos && ! regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) |
8d30c4ee | 5223 | regs_ever_live[PIC_OFFSET_TABLE_REGNUM] = 1; |
1ff7789b | 5224 | |
8d30c4ee | 5225 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 5226 | |
1ff7789b MM |
5227 | return pic_offset_table_rtx; |
5228 | } | |
a7df97e6 | 5229 | \f |
71f123ca | 5230 | /* Functions to init, mark and free struct machine_function. |
a7df97e6 MM |
5231 | These will be called, via pointer variables, |
5232 | from push_function_context and pop_function_context. */ | |
5233 | ||
00dba523 NC |
5234 | static void |
5235 | rs6000_init_machine_status (p) | |
a7df97e6 MM |
5236 | struct function *p; |
5237 | { | |
71f123ca FS |
5238 | p->machine = (machine_function *) xcalloc (1, sizeof (machine_function)); |
5239 | } | |
a7df97e6 | 5240 | |
00dba523 NC |
5241 | static void |
5242 | rs6000_free_machine_status (p) | |
a7df97e6 MM |
5243 | struct function *p; |
5244 | { | |
00dba523 NC |
5245 | if (p->machine == NULL) |
5246 | return; | |
a7df97e6 | 5247 | |
00dba523 NC |
5248 | free (p->machine); |
5249 | p->machine = NULL; | |
a7df97e6 MM |
5250 | } |
5251 | ||
9878760c RK |
5252 | \f |
5253 | /* Print an operand. Recognize special options, documented below. */ | |
5254 | ||
38c1f2d7 | 5255 | #if TARGET_ELF |
d9407988 | 5256 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 5257 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
5258 | #else |
5259 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 5260 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
5261 | #endif |
5262 | ||
9878760c RK |
5263 | void |
5264 | print_operand (file, x, code) | |
5265 | FILE *file; | |
5266 | rtx x; | |
9ebbca7d | 5267 | int code; |
9878760c RK |
5268 | { |
5269 | int i; | |
a260abc9 | 5270 | HOST_WIDE_INT val; |
9878760c RK |
5271 | |
5272 | /* These macros test for integers and extract the low-order bits. */ | |
5273 | #define INT_P(X) \ | |
5274 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
5275 | && GET_MODE (X) == VOIDmode) | |
5276 | ||
5277 | #define INT_LOWPART(X) \ | |
5278 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
5279 | ||
5280 | switch (code) | |
5281 | { | |
a8b3aeda | 5282 | case '.': |
a85d226b RK |
5283 | /* Write out an instruction after the call which may be replaced |
5284 | with glue code by the loader. This depends on the AIX version. */ | |
5285 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
5286 | return; |
5287 | ||
81eace42 GK |
5288 | /* %a is output_address. */ |
5289 | ||
9854d9ed RK |
5290 | case 'A': |
5291 | /* If X is a constant integer whose low-order 5 bits are zero, | |
5292 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 5293 | in the AIX assembler where "sri" with a zero shift count |
9854d9ed RK |
5294 | write a trash instruction. */ |
5295 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) | |
76229ac8 | 5296 | putc ('l', file); |
9854d9ed | 5297 | else |
76229ac8 | 5298 | putc ('r', file); |
9854d9ed RK |
5299 | return; |
5300 | ||
5301 | case 'b': | |
e2c953b6 DE |
5302 | /* If constant, low-order 16 bits of constant, unsigned. |
5303 | Otherwise, write normally. */ | |
5304 | if (INT_P (x)) | |
5305 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
5306 | else | |
5307 | print_operand (file, x, 0); | |
cad12a8d RK |
5308 | return; |
5309 | ||
a260abc9 DE |
5310 | case 'B': |
5311 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
5312 | for 64-bit mask direction. */ | |
296b8152 | 5313 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 5314 | return; |
a260abc9 | 5315 | |
81eace42 GK |
5316 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
5317 | output_operand. */ | |
5318 | ||
9854d9ed | 5319 | case 'D': |
39a10a29 GK |
5320 | /* There used to be a comment for 'C' reading "This is an |
5321 | optional cror needed for certain floating-point | |
5322 | comparisons. Otherwise write nothing." */ | |
5323 | ||
9854d9ed RK |
5324 | /* Similar, except that this is for an scc, so we must be able to |
5325 | encode the test in a single bit that is one. We do the above | |
5326 | for any LE, GE, GEU, or LEU and invert the bit for NE. */ | |
5327 | if (GET_CODE (x) == LE || GET_CODE (x) == GE | |
5328 | || GET_CODE (x) == LEU || GET_CODE (x) == GEU) | |
5329 | { | |
9ebbca7d | 5330 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); |
9854d9ed RK |
5331 | |
5332 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
5333 | base_bit + 2, | |
5334 | base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU)); | |
5335 | } | |
5336 | ||
5337 | else if (GET_CODE (x) == NE) | |
5338 | { | |
9ebbca7d | 5339 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); |
9854d9ed RK |
5340 | |
5341 | fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3, | |
5342 | base_bit + 2, base_bit + 2); | |
5343 | } | |
5344 | return; | |
5345 | ||
5346 | case 'E': | |
39a10a29 | 5347 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
5348 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
5349 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 5350 | else |
39a10a29 | 5351 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 5352 | return; |
9854d9ed RK |
5353 | |
5354 | case 'f': | |
5355 | /* X is a CR register. Print the shift count needed to move it | |
5356 | to the high-order four bits. */ | |
5357 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
5358 | output_operand_lossage ("invalid %%f value"); | |
5359 | else | |
9ebbca7d | 5360 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
5361 | return; |
5362 | ||
5363 | case 'F': | |
5364 | /* Similar, but print the count for the rotate in the opposite | |
5365 | direction. */ | |
5366 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
5367 | output_operand_lossage ("invalid %%F value"); | |
5368 | else | |
9ebbca7d | 5369 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
5370 | return; |
5371 | ||
5372 | case 'G': | |
5373 | /* X is a constant integer. If it is negative, print "m", | |
5374 | otherwise print "z". This is to make a aze or ame insn. */ | |
5375 | if (GET_CODE (x) != CONST_INT) | |
5376 | output_operand_lossage ("invalid %%G value"); | |
5377 | else if (INTVAL (x) >= 0) | |
76229ac8 | 5378 | putc ('z', file); |
9854d9ed | 5379 | else |
76229ac8 | 5380 | putc ('m', file); |
9854d9ed | 5381 | return; |
e2c953b6 | 5382 | |
9878760c | 5383 | case 'h': |
a4f6c312 SS |
5384 | /* If constant, output low-order five bits. Otherwise, write |
5385 | normally. */ | |
9878760c | 5386 | if (INT_P (x)) |
5f59ecb7 | 5387 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
5388 | else |
5389 | print_operand (file, x, 0); | |
5390 | return; | |
5391 | ||
64305719 | 5392 | case 'H': |
a4f6c312 SS |
5393 | /* If constant, output low-order six bits. Otherwise, write |
5394 | normally. */ | |
64305719 | 5395 | if (INT_P (x)) |
5f59ecb7 | 5396 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
5397 | else |
5398 | print_operand (file, x, 0); | |
5399 | return; | |
5400 | ||
9854d9ed RK |
5401 | case 'I': |
5402 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 5403 | if (INT_P (x)) |
76229ac8 | 5404 | putc ('i', file); |
9878760c RK |
5405 | return; |
5406 | ||
9854d9ed RK |
5407 | case 'j': |
5408 | /* Write the bit number in CCR for jump. */ | |
5409 | i = ccr_bit (x, 0); | |
5410 | if (i == -1) | |
5411 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 5412 | else |
9854d9ed | 5413 | fprintf (file, "%d", i); |
9878760c RK |
5414 | return; |
5415 | ||
9854d9ed RK |
5416 | case 'J': |
5417 | /* Similar, but add one for shift count in rlinm for scc and pass | |
5418 | scc flag to `ccr_bit'. */ | |
5419 | i = ccr_bit (x, 1); | |
5420 | if (i == -1) | |
5421 | output_operand_lossage ("invalid %%J code"); | |
5422 | else | |
a0466a68 RK |
5423 | /* If we want bit 31, write a shift count of zero, not 32. */ |
5424 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
5425 | return; |
5426 | ||
9854d9ed RK |
5427 | case 'k': |
5428 | /* X must be a constant. Write the 1's complement of the | |
5429 | constant. */ | |
9878760c | 5430 | if (! INT_P (x)) |
9854d9ed | 5431 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
5432 | else |
5433 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
5434 | return; |
5435 | ||
81eace42 | 5436 | case 'K': |
9ebbca7d GK |
5437 | /* X must be a symbolic constant on ELF. Write an |
5438 | expression suitable for an 'addi' that adds in the low 16 | |
5439 | bits of the MEM. */ | |
5440 | if (GET_CODE (x) != CONST) | |
5441 | { | |
5442 | print_operand_address (file, x); | |
5443 | fputs ("@l", file); | |
5444 | } | |
5445 | else | |
5446 | { | |
5447 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
5448 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
5449 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
5450 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 5451 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
5452 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
5453 | fputs ("@l", file); | |
5454 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); | |
5455 | } | |
81eace42 GK |
5456 | return; |
5457 | ||
5458 | /* %l is output_asm_label. */ | |
9ebbca7d | 5459 | |
9854d9ed RK |
5460 | case 'L': |
5461 | /* Write second word of DImode or DFmode reference. Works on register | |
5462 | or non-indexed memory only. */ | |
5463 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 5464 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
5465 | else if (GET_CODE (x) == MEM) |
5466 | { | |
5467 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 5468 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
5469 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
5470 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
ed8908e7 RK |
5471 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), |
5472 | UNITS_PER_WORD)); | |
9854d9ed | 5473 | else |
d7624dc0 RK |
5474 | output_address (XEXP (adjust_address_nv (x, SImode, |
5475 | UNITS_PER_WORD), | |
5476 | 0)); | |
ed8908e7 | 5477 | |
ba5e43aa | 5478 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
5479 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
5480 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 5481 | } |
9878760c | 5482 | return; |
9854d9ed | 5483 | |
9878760c RK |
5484 | case 'm': |
5485 | /* MB value for a mask operand. */ | |
5486 | if (! mask_operand (x, VOIDmode)) | |
5487 | output_operand_lossage ("invalid %%m value"); | |
5488 | ||
5489 | val = INT_LOWPART (x); | |
5490 | ||
5491 | /* If the high bit is set and the low bit is not, the value is zero. | |
5492 | If the high bit is zero, the value is the first 1 bit we find from | |
5493 | the left. */ | |
0858c623 | 5494 | if ((val & 0x80000000) && ((val & 1) == 0)) |
9878760c | 5495 | { |
19d2d16f | 5496 | putc ('0', file); |
9878760c RK |
5497 | return; |
5498 | } | |
0858c623 | 5499 | else if ((val & 0x80000000) == 0) |
9878760c RK |
5500 | { |
5501 | for (i = 1; i < 32; i++) | |
0858c623 | 5502 | if ((val <<= 1) & 0x80000000) |
9878760c RK |
5503 | break; |
5504 | fprintf (file, "%d", i); | |
5505 | return; | |
5506 | } | |
5507 | ||
5508 | /* Otherwise, look for the first 0 bit from the right. The result is its | |
5509 | number plus 1. We know the low-order bit is one. */ | |
5510 | for (i = 0; i < 32; i++) | |
5511 | if (((val >>= 1) & 1) == 0) | |
5512 | break; | |
5513 | ||
a260abc9 | 5514 | /* If we ended in ...01, i would be 0. The correct value is 31, so |
9878760c RK |
5515 | we want 31 - i. */ |
5516 | fprintf (file, "%d", 31 - i); | |
5517 | return; | |
5518 | ||
5519 | case 'M': | |
5520 | /* ME value for a mask operand. */ | |
5521 | if (! mask_operand (x, VOIDmode)) | |
a260abc9 | 5522 | output_operand_lossage ("invalid %%M value"); |
9878760c RK |
5523 | |
5524 | val = INT_LOWPART (x); | |
5525 | ||
5526 | /* If the low bit is set and the high bit is not, the value is 31. | |
5527 | If the low bit is zero, the value is the first 1 bit we find from | |
5528 | the right. */ | |
0858c623 | 5529 | if ((val & 1) && ((val & 0x80000000) == 0)) |
9878760c | 5530 | { |
76229ac8 | 5531 | fputs ("31", file); |
9878760c RK |
5532 | return; |
5533 | } | |
5534 | else if ((val & 1) == 0) | |
5535 | { | |
5536 | for (i = 0; i < 32; i++) | |
5537 | if ((val >>= 1) & 1) | |
5538 | break; | |
5539 | ||
a260abc9 | 5540 | /* If we had ....10, i would be 0. The result should be |
9878760c RK |
5541 | 30, so we need 30 - i. */ |
5542 | fprintf (file, "%d", 30 - i); | |
5543 | return; | |
5544 | } | |
5545 | ||
5546 | /* Otherwise, look for the first 0 bit from the left. The result is its | |
5547 | number minus 1. We know the high-order bit is one. */ | |
5548 | for (i = 0; i < 32; i++) | |
0858c623 | 5549 | if (((val <<= 1) & 0x80000000) == 0) |
9878760c RK |
5550 | break; |
5551 | ||
5552 | fprintf (file, "%d", i); | |
5553 | return; | |
5554 | ||
81eace42 GK |
5555 | /* %n outputs the negative of its operand. */ |
5556 | ||
9878760c RK |
5557 | case 'N': |
5558 | /* Write the number of elements in the vector times 4. */ | |
5559 | if (GET_CODE (x) != PARALLEL) | |
5560 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
5561 | else |
5562 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
5563 | return; |
5564 | ||
5565 | case 'O': | |
5566 | /* Similar, but subtract 1 first. */ | |
5567 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 5568 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
5569 | else |
5570 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
5571 | return; |
5572 | ||
9854d9ed RK |
5573 | case 'p': |
5574 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
5575 | if (! INT_P (x) | |
2bfcf297 | 5576 | || INT_LOWPART (x) < 0 |
9854d9ed RK |
5577 | || (i = exact_log2 (INT_LOWPART (x))) < 0) |
5578 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
5579 | else |
5580 | fprintf (file, "%d", i); | |
9854d9ed RK |
5581 | return; |
5582 | ||
9878760c RK |
5583 | case 'P': |
5584 | /* The operand must be an indirect memory reference. The result | |
a4f6c312 | 5585 | is the register number. */ |
9878760c RK |
5586 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG |
5587 | || REGNO (XEXP (x, 0)) >= 32) | |
5588 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 DE |
5589 | else |
5590 | fprintf (file, "%d", REGNO (XEXP (x, 0))); | |
9878760c RK |
5591 | return; |
5592 | ||
dfbdccdb GK |
5593 | case 'q': |
5594 | /* This outputs the logical code corresponding to a boolean | |
5595 | expression. The expression may have one or both operands | |
39a10a29 GK |
5596 | negated (if one, only the first one). For condition register |
5597 | logical operations, it will also treat the negated | |
5598 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 5599 | { |
63bc1d05 | 5600 | const char *const *t = 0; |
dfbdccdb GK |
5601 | const char *s; |
5602 | enum rtx_code code = GET_CODE (x); | |
5603 | static const char * const tbl[3][3] = { | |
5604 | { "and", "andc", "nor" }, | |
5605 | { "or", "orc", "nand" }, | |
5606 | { "xor", "eqv", "xor" } }; | |
5607 | ||
5608 | if (code == AND) | |
5609 | t = tbl[0]; | |
5610 | else if (code == IOR) | |
5611 | t = tbl[1]; | |
5612 | else if (code == XOR) | |
5613 | t = tbl[2]; | |
5614 | else | |
5615 | output_operand_lossage ("invalid %%q value"); | |
5616 | ||
5617 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
5618 | s = t[0]; | |
5619 | else | |
5620 | { | |
5621 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
5622 | s = t[2]; | |
5623 | else | |
5624 | s = t[1]; | |
5625 | } | |
5626 | ||
5627 | fputs (s, file); | |
5628 | } | |
5629 | return; | |
5630 | ||
9854d9ed RK |
5631 | case 'R': |
5632 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
5633 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
5634 | output_operand_lossage ("invalid %%R value"); | |
5635 | else | |
9ebbca7d | 5636 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 5637 | return; |
9854d9ed RK |
5638 | |
5639 | case 's': | |
5640 | /* Low 5 bits of 32 - value */ | |
5641 | if (! INT_P (x)) | |
5642 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
5643 | else |
5644 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 5645 | return; |
9854d9ed | 5646 | |
a260abc9 DE |
5647 | case 'S': |
5648 | /* PowerPC64 mask position. All 0's and all 1's are excluded. | |
5649 | CONST_INT 32-bit mask is considered sign-extended so any | |
5650 | transition must occur within the CONST_INT, not on the boundary. */ | |
5651 | if (! mask64_operand (x, VOIDmode)) | |
5652 | output_operand_lossage ("invalid %%S value"); | |
5653 | ||
5654 | val = INT_LOWPART (x); | |
5655 | ||
5656 | if (val & 1) /* Clear Left */ | |
5657 | { | |
a238cd8b DE |
5658 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
5659 | if (!((val >>= 1) & 1)) | |
5660 | break; | |
a260abc9 | 5661 | |
a238cd8b DE |
5662 | #if HOST_BITS_PER_WIDE_INT == 32 |
5663 | if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
5664 | { | |
5665 | val = CONST_DOUBLE_HIGH (x); | |
5666 | ||
5667 | if (val == 0) | |
5668 | --i; | |
5669 | else | |
5670 | for (i = 32; i < 64; i++) | |
5671 | if (!((val >>= 1) & 1)) | |
5672 | break; | |
5673 | } | |
a260abc9 | 5674 | #endif |
a238cd8b DE |
5675 | /* i = index of last set bit from right |
5676 | mask begins at 63 - i from left */ | |
5677 | if (i > 63) | |
5678 | output_operand_lossage ("%%S computed all 1's mask"); | |
cccf3bdc | 5679 | |
a260abc9 DE |
5680 | fprintf (file, "%d", 63 - i); |
5681 | return; | |
5682 | } | |
5683 | else /* Clear Right */ | |
5684 | { | |
a238cd8b DE |
5685 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
5686 | if ((val >>= 1) & 1) | |
5687 | break; | |
a260abc9 | 5688 | |
a238cd8b | 5689 | #if HOST_BITS_PER_WIDE_INT == 32 |
a260abc9 DE |
5690 | if (GET_CODE (x) == CONST_DOUBLE && i == 32) |
5691 | { | |
a238cd8b | 5692 | val = CONST_DOUBLE_HIGH (x); |
a260abc9 | 5693 | |
a238cd8b | 5694 | if (val == (HOST_WIDE_INT) -1) |
a260abc9 | 5695 | --i; |
a260abc9 | 5696 | else |
a238cd8b DE |
5697 | for (i = 32; i < 64; i++) |
5698 | if ((val >>= 1) & 1) | |
a260abc9 DE |
5699 | break; |
5700 | } | |
5701 | #endif | |
a238cd8b DE |
5702 | /* i = index of last clear bit from right |
5703 | mask ends at 62 - i from left */ | |
5704 | if (i > 62) | |
5705 | output_operand_lossage ("%%S computed all 0's mask"); | |
cccf3bdc | 5706 | |
a238cd8b | 5707 | fprintf (file, "%d", 62 - i); |
a260abc9 DE |
5708 | return; |
5709 | } | |
5710 | ||
cccf3bdc DE |
5711 | case 'T': |
5712 | /* Print the symbolic name of a branch target register. */ | |
5713 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
5714 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
5715 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 5716 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
5717 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
5718 | else | |
5719 | fputs ("ctr", file); | |
5720 | return; | |
5721 | ||
9854d9ed | 5722 | case 'u': |
802a0058 | 5723 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
5724 | if (! INT_P (x)) |
5725 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 DE |
5726 | else |
5727 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, | |
5728 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
5729 | return; |
5730 | ||
802a0058 MM |
5731 | case 'v': |
5732 | /* High-order 16 bits of constant for use in signed operand. */ | |
5733 | if (! INT_P (x)) | |
5734 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 | 5735 | else |
134c32f6 DE |
5736 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
5737 | (INT_LOWPART (x) >> 16) & 0xffff); | |
5738 | return; | |
802a0058 | 5739 | |
9854d9ed RK |
5740 | case 'U': |
5741 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
5742 | if (GET_CODE (x) == MEM | |
5743 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
5744 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 5745 | putc ('u', file); |
9854d9ed | 5746 | return; |
9878760c | 5747 | |
e0cd0770 JC |
5748 | case 'V': |
5749 | /* Print the trap code for this operand. */ | |
5750 | switch (GET_CODE (x)) | |
5751 | { | |
5752 | case EQ: | |
5753 | fputs ("eq", file); /* 4 */ | |
5754 | break; | |
5755 | case NE: | |
5756 | fputs ("ne", file); /* 24 */ | |
5757 | break; | |
5758 | case LT: | |
5759 | fputs ("lt", file); /* 16 */ | |
5760 | break; | |
5761 | case LE: | |
5762 | fputs ("le", file); /* 20 */ | |
5763 | break; | |
5764 | case GT: | |
5765 | fputs ("gt", file); /* 8 */ | |
5766 | break; | |
5767 | case GE: | |
5768 | fputs ("ge", file); /* 12 */ | |
5769 | break; | |
5770 | case LTU: | |
5771 | fputs ("llt", file); /* 2 */ | |
5772 | break; | |
5773 | case LEU: | |
5774 | fputs ("lle", file); /* 6 */ | |
5775 | break; | |
5776 | case GTU: | |
5777 | fputs ("lgt", file); /* 1 */ | |
5778 | break; | |
5779 | case GEU: | |
5780 | fputs ("lge", file); /* 5 */ | |
5781 | break; | |
5782 | default: | |
5783 | abort (); | |
5784 | } | |
5785 | break; | |
5786 | ||
9854d9ed RK |
5787 | case 'w': |
5788 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
5789 | normally. */ | |
5790 | if (INT_P (x)) | |
5f59ecb7 DE |
5791 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
5792 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
5793 | else |
5794 | print_operand (file, x, 0); | |
9878760c RK |
5795 | return; |
5796 | ||
9854d9ed | 5797 | case 'W': |
e2c953b6 | 5798 | /* MB value for a PowerPC64 rldic operand. */ |
e2c953b6 DE |
5799 | val = (GET_CODE (x) == CONST_INT |
5800 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
5801 | ||
5802 | if (val < 0) | |
5803 | i = -1; | |
9854d9ed | 5804 | else |
e2c953b6 DE |
5805 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
5806 | if ((val <<= 1) < 0) | |
5807 | break; | |
5808 | ||
5809 | #if HOST_BITS_PER_WIDE_INT == 32 | |
5810 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
5811 | i += 32; /* zero-extend high-part was all 0's */ | |
5812 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
5813 | { | |
5814 | val = CONST_DOUBLE_LOW (x); | |
5815 | ||
5816 | if (val == 0) | |
a4f6c312 | 5817 | abort (); |
e2c953b6 DE |
5818 | else if (val < 0) |
5819 | --i; | |
5820 | else | |
5821 | for ( ; i < 64; i++) | |
5822 | if ((val <<= 1) < 0) | |
5823 | break; | |
5824 | } | |
5825 | #endif | |
5826 | ||
5827 | fprintf (file, "%d", i + 1); | |
9854d9ed | 5828 | return; |
9878760c | 5829 | |
9854d9ed RK |
5830 | case 'X': |
5831 | if (GET_CODE (x) == MEM | |
258bfae2 | 5832 | && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0)) |
76229ac8 | 5833 | putc ('x', file); |
9854d9ed | 5834 | return; |
9878760c | 5835 | |
9854d9ed RK |
5836 | case 'Y': |
5837 | /* Like 'L', for third word of TImode */ | |
5838 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 5839 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 5840 | else if (GET_CODE (x) == MEM) |
9878760c | 5841 | { |
9854d9ed RK |
5842 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
5843 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 5844 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 5845 | else |
d7624dc0 | 5846 | output_address (XEXP (adjust_address_nv (x, SImode, 8), 0)); |
ba5e43aa | 5847 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
5848 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
5849 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
5850 | } |
5851 | return; | |
9854d9ed | 5852 | |
9878760c | 5853 | case 'z': |
b4ac57ab RS |
5854 | /* X is a SYMBOL_REF. Write out the name preceded by a |
5855 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
5856 | names. If we are configured for System V (or the embedded ABI) on |
5857 | the PowerPC, do not emit the period, since those systems do not use | |
5858 | TOCs and the like. */ | |
9878760c RK |
5859 | if (GET_CODE (x) != SYMBOL_REF) |
5860 | abort (); | |
5861 | ||
b6c9286a MM |
5862 | if (XSTR (x, 0)[0] != '.') |
5863 | { | |
5864 | switch (DEFAULT_ABI) | |
5865 | { | |
5866 | default: | |
5867 | abort (); | |
5868 | ||
5869 | case ABI_AIX: | |
5870 | putc ('.', file); | |
5871 | break; | |
5872 | ||
5873 | case ABI_V4: | |
5874 | case ABI_AIX_NODESC: | |
ee890fe2 | 5875 | case ABI_DARWIN: |
b6c9286a | 5876 | break; |
b6c9286a MM |
5877 | } |
5878 | } | |
54ee9799 DE |
5879 | #if TARGET_AIX |
5880 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); | |
5881 | #else | |
9ebbca7d | 5882 | assemble_name (file, XSTR (x, 0)); |
54ee9799 | 5883 | #endif |
9878760c RK |
5884 | return; |
5885 | ||
9854d9ed RK |
5886 | case 'Z': |
5887 | /* Like 'L', for last word of TImode. */ | |
5888 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 5889 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
5890 | else if (GET_CODE (x) == MEM) |
5891 | { | |
5892 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
5893 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 5894 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 5895 | else |
d7624dc0 | 5896 | output_address (XEXP (adjust_address_nv (x, SImode, 12), 0)); |
ba5e43aa | 5897 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
5898 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
5899 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 5900 | } |
5c23c401 | 5901 | return; |
0ac081f6 AH |
5902 | |
5903 | /* Print AltiVec memory operand. */ | |
5904 | case 'y': | |
5905 | { | |
5906 | rtx tmp; | |
5907 | ||
5908 | if (GET_CODE (x) != MEM) | |
5909 | abort (); | |
5910 | ||
5911 | tmp = XEXP (x, 0); | |
5912 | ||
5913 | if (GET_CODE (tmp) == REG) | |
5914 | fprintf (file, "0, %s", reg_names[REGNO (tmp)]); | |
5915 | else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG) | |
5916 | { | |
5917 | if (REGNO (XEXP (tmp, 0)) == 0) | |
5918 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ], | |
5919 | reg_names[ REGNO (XEXP (tmp, 0)) ]); | |
5920 | else | |
5921 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ], | |
5922 | reg_names[ REGNO (XEXP (tmp, 1)) ]); | |
5923 | } | |
5924 | else | |
5925 | abort (); | |
5926 | break; | |
5927 | } | |
9854d9ed | 5928 | |
9878760c RK |
5929 | case 0: |
5930 | if (GET_CODE (x) == REG) | |
5931 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
5932 | else if (GET_CODE (x) == MEM) | |
5933 | { | |
5934 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
5935 | know the width from the mode. */ | |
5936 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
5937 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
5938 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 5939 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
5940 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
5941 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 5942 | else |
a54d04b7 | 5943 | output_address (XEXP (x, 0)); |
9878760c RK |
5944 | } |
5945 | else | |
a54d04b7 | 5946 | output_addr_const (file, x); |
a85d226b | 5947 | return; |
9878760c RK |
5948 | |
5949 | default: | |
5950 | output_operand_lossage ("invalid %%xn code"); | |
5951 | } | |
5952 | } | |
5953 | \f | |
5954 | /* Print the address of an operand. */ | |
5955 | ||
5956 | void | |
5957 | print_operand_address (file, x) | |
5958 | FILE *file; | |
592696dd | 5959 | rtx x; |
9878760c RK |
5960 | { |
5961 | if (GET_CODE (x) == REG) | |
4697a36c | 5962 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
5963 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
5964 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
5965 | { |
5966 | output_addr_const (file, x); | |
ba5e43aa | 5967 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
5968 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
5969 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d | 5970 | else if (TARGET_TOC) |
a4f6c312 | 5971 | abort (); |
9878760c RK |
5972 | } |
5973 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
5974 | { | |
5975 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
5976 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
5977 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 5978 | else |
4697a36c MM |
5979 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
5980 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
5981 | } |
5982 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
5f59ecb7 DE |
5983 | { |
5984 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1))); | |
5985 | fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
5986 | } | |
3cb999d8 DE |
5987 | #if TARGET_ELF |
5988 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
5989 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
5990 | { |
5991 | output_addr_const (file, XEXP (x, 1)); | |
5992 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
5993 | } | |
c859cda6 DJ |
5994 | #endif |
5995 | #if TARGET_MACHO | |
5996 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
5997 | && CONSTANT_P (XEXP (x, 1))) | |
5998 | { | |
5999 | fprintf (file, "lo16("); | |
6000 | output_addr_const (file, XEXP (x, 1)); | |
6001 | fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
6002 | } | |
3cb999d8 | 6003 | #endif |
9ebbca7d GK |
6004 | else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x)) |
6005 | { | |
2bfcf297 | 6006 | if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC)) |
9ebbca7d | 6007 | { |
2bfcf297 DB |
6008 | rtx contains_minus = XEXP (x, 1); |
6009 | rtx minus, symref; | |
6010 | const char *name; | |
9ebbca7d GK |
6011 | |
6012 | /* Find the (minus (sym) (toc)) buried in X, and temporarily | |
a4f6c312 | 6013 | turn it into (sym) for output_addr_const. */ |
9ebbca7d GK |
6014 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) |
6015 | contains_minus = XEXP (contains_minus, 0); | |
6016 | ||
2bfcf297 DB |
6017 | minus = XEXP (contains_minus, 0); |
6018 | symref = XEXP (minus, 0); | |
6019 | XEXP (contains_minus, 0) = symref; | |
6020 | if (TARGET_ELF) | |
6021 | { | |
6022 | char *newname; | |
6023 | ||
6024 | name = XSTR (symref, 0); | |
6025 | newname = alloca (strlen (name) + sizeof ("@toc")); | |
6026 | strcpy (newname, name); | |
6027 | strcat (newname, "@toc"); | |
6028 | XSTR (symref, 0) = newname; | |
6029 | } | |
6030 | output_addr_const (file, XEXP (x, 1)); | |
6031 | if (TARGET_ELF) | |
6032 | XSTR (symref, 0) = name; | |
9ebbca7d GK |
6033 | XEXP (contains_minus, 0) = minus; |
6034 | } | |
6035 | else | |
6036 | output_addr_const (file, XEXP (x, 1)); | |
6037 | ||
6038 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
6039 | } | |
9878760c RK |
6040 | else |
6041 | abort (); | |
6042 | } | |
6043 | \f | |
301d03af RS |
6044 | /* Target hook for assembling integer objects. The powerpc version has |
6045 | to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP | |
6046 | is defined. It also needs to handle DI-mode objects on 64-bit | |
6047 | targets. */ | |
6048 | ||
6049 | static bool | |
6050 | rs6000_assemble_integer (x, size, aligned_p) | |
6051 | rtx x; | |
6052 | unsigned int size; | |
6053 | int aligned_p; | |
6054 | { | |
6055 | #ifdef RELOCATABLE_NEEDS_FIXUP | |
6056 | /* Special handling for SI values. */ | |
6057 | if (size == 4 && aligned_p) | |
6058 | { | |
6059 | extern int in_toc_section PARAMS ((void)); | |
6060 | static int recurse = 0; | |
6061 | ||
6062 | /* For -mrelocatable, we mark all addresses that need to be fixed up | |
6063 | in the .fixup section. */ | |
6064 | if (TARGET_RELOCATABLE | |
6065 | && !in_toc_section () | |
6066 | && !in_text_section () | |
6067 | && !recurse | |
6068 | && GET_CODE (x) != CONST_INT | |
6069 | && GET_CODE (x) != CONST_DOUBLE | |
6070 | && CONSTANT_P (x)) | |
6071 | { | |
6072 | char buf[256]; | |
6073 | ||
6074 | recurse = 1; | |
6075 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno); | |
6076 | fixuplabelno++; | |
6077 | ASM_OUTPUT_LABEL (asm_out_file, buf); | |
6078 | fprintf (asm_out_file, "\t.long\t("); | |
6079 | output_addr_const (asm_out_file, x); | |
6080 | fprintf (asm_out_file, ")@fixup\n"); | |
6081 | fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n"); | |
6082 | ASM_OUTPUT_ALIGN (asm_out_file, 2); | |
6083 | fprintf (asm_out_file, "\t.long\t"); | |
6084 | assemble_name (asm_out_file, buf); | |
6085 | fprintf (asm_out_file, "\n\t.previous\n"); | |
6086 | recurse = 0; | |
6087 | return true; | |
6088 | } | |
6089 | /* Remove initial .'s to turn a -mcall-aixdesc function | |
6090 | address into the address of the descriptor, not the function | |
6091 | itself. */ | |
6092 | else if (GET_CODE (x) == SYMBOL_REF | |
6093 | && XSTR (x, 0)[0] == '.' | |
6094 | && DEFAULT_ABI == ABI_AIX) | |
6095 | { | |
6096 | const char *name = XSTR (x, 0); | |
6097 | while (*name == '.') | |
6098 | name++; | |
6099 | ||
6100 | fprintf (asm_out_file, "\t.long\t%s\n", name); | |
6101 | return true; | |
6102 | } | |
6103 | } | |
6104 | #endif /* RELOCATABLE_NEEDS_FIXUP */ | |
6105 | return default_assemble_integer (x, size, aligned_p); | |
6106 | } | |
6107 | \f | |
39a10a29 GK |
6108 | enum rtx_code |
6109 | rs6000_reverse_condition (mode, code) | |
6110 | enum machine_mode mode; | |
6111 | enum rtx_code code; | |
6112 | { | |
6113 | /* Reversal of FP compares takes care -- an ordered compare | |
6114 | becomes an unordered compare and vice versa. */ | |
6115 | if (mode == CCFPmode) | |
bab6226b | 6116 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 6117 | else |
bab6226b | 6118 | return reverse_condition (code); |
39a10a29 GK |
6119 | } |
6120 | ||
39a10a29 GK |
6121 | /* Generate a compare for CODE. Return a brand-new rtx that |
6122 | represents the result of the compare. */ | |
a4f6c312 | 6123 | |
39a10a29 GK |
6124 | static rtx |
6125 | rs6000_generate_compare (code) | |
6126 | enum rtx_code code; | |
6127 | { | |
6128 | enum machine_mode comp_mode; | |
6129 | rtx compare_result; | |
6130 | ||
6131 | if (rs6000_compare_fp_p) | |
6132 | comp_mode = CCFPmode; | |
6133 | else if (code == GTU || code == LTU | |
6134 | || code == GEU || code == LEU) | |
6135 | comp_mode = CCUNSmode; | |
6136 | else | |
6137 | comp_mode = CCmode; | |
6138 | ||
6139 | /* First, the compare. */ | |
6140 | compare_result = gen_reg_rtx (comp_mode); | |
6141 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
6142 | gen_rtx_COMPARE (comp_mode, | |
6143 | rs6000_compare_op0, | |
6144 | rs6000_compare_op1))); | |
6145 | ||
ca5adc63 | 6146 | /* Some kinds of FP comparisons need an OR operation; |
de6c5979 | 6147 | except for flag_unsafe_math_optimizations we don't bother. */ |
39a10a29 | 6148 | if (rs6000_compare_fp_p |
de6c5979 | 6149 | && ! flag_unsafe_math_optimizations |
39a10a29 GK |
6150 | && (code == LE || code == GE |
6151 | || code == UNEQ || code == LTGT | |
6152 | || code == UNGT || code == UNLT)) | |
6153 | { | |
6154 | enum rtx_code or1, or2; | |
6155 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
6156 | rtx or_result = gen_reg_rtx (CCEQmode); | |
6157 | ||
6158 | switch (code) | |
6159 | { | |
6160 | case LE: or1 = LT; or2 = EQ; break; | |
6161 | case GE: or1 = GT; or2 = EQ; break; | |
6162 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
6163 | case LTGT: or1 = LT; or2 = GT; break; | |
6164 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
6165 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
6166 | default: abort (); | |
6167 | } | |
6168 | validate_condition_mode (or1, comp_mode); | |
6169 | validate_condition_mode (or2, comp_mode); | |
6170 | or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx); | |
6171 | or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx); | |
6172 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, | |
6173 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
6174 | const_true_rtx); | |
6175 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
6176 | ||
6177 | compare_result = or_result; | |
6178 | code = EQ; | |
6179 | } | |
6180 | ||
6181 | validate_condition_mode (code, GET_MODE (compare_result)); | |
6182 | ||
6183 | return gen_rtx (code, VOIDmode, compare_result, const0_rtx); | |
6184 | } | |
6185 | ||
6186 | ||
6187 | /* Emit the RTL for an sCOND pattern. */ | |
6188 | ||
6189 | void | |
6190 | rs6000_emit_sCOND (code, result) | |
6191 | enum rtx_code code; | |
6192 | rtx result; | |
6193 | { | |
6194 | rtx condition_rtx; | |
6195 | enum machine_mode op_mode; | |
6196 | ||
6197 | condition_rtx = rs6000_generate_compare (code); | |
6198 | ||
6199 | op_mode = GET_MODE (rs6000_compare_op0); | |
6200 | if (op_mode == VOIDmode) | |
6201 | op_mode = GET_MODE (rs6000_compare_op1); | |
6202 | ||
6203 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
6204 | { | |
6205 | PUT_MODE (condition_rtx, DImode); | |
6206 | convert_move (result, condition_rtx, 0); | |
6207 | } | |
6208 | else | |
6209 | { | |
6210 | PUT_MODE (condition_rtx, SImode); | |
6211 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
6212 | } | |
6213 | } | |
6214 | ||
39a10a29 GK |
6215 | /* Emit a branch of kind CODE to location LOC. */ |
6216 | ||
6217 | void | |
6218 | rs6000_emit_cbranch (code, loc) | |
6219 | enum rtx_code code; | |
6220 | rtx loc; | |
6221 | { | |
6222 | rtx condition_rtx, loc_ref; | |
6223 | ||
6224 | condition_rtx = rs6000_generate_compare (code); | |
6225 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
6226 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
6227 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
6228 | loc_ref, pc_rtx))); | |
6229 | } | |
6230 | ||
12a4e8c5 GK |
6231 | /* Return the string to output a conditional branch to LABEL, which is |
6232 | the operand number of the label, or -1 if the branch is really a | |
6233 | conditional return. | |
6234 | ||
6235 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
6236 | condition code register and its mode specifies what kind of | |
6237 | comparison we made. | |
6238 | ||
6239 | REVERSED is non-zero if we should reverse the sense of the comparison. | |
6240 | ||
6241 | INSN is the insn. */ | |
6242 | ||
6243 | char * | |
6244 | output_cbranch (op, label, reversed, insn) | |
6245 | rtx op; | |
6246 | const char * label; | |
6247 | int reversed; | |
6248 | rtx insn; | |
6249 | { | |
6250 | static char string[64]; | |
6251 | enum rtx_code code = GET_CODE (op); | |
6252 | rtx cc_reg = XEXP (op, 0); | |
6253 | enum machine_mode mode = GET_MODE (cc_reg); | |
6254 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 6255 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
6256 | int really_reversed = reversed ^ need_longbranch; |
6257 | char *s = string; | |
6258 | const char *ccode; | |
6259 | const char *pred; | |
6260 | rtx note; | |
6261 | ||
39a10a29 GK |
6262 | validate_condition_mode (code, mode); |
6263 | ||
6264 | /* Work out which way this really branches. We could use | |
6265 | reverse_condition_maybe_unordered here always but this | |
6266 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 6267 | if (really_reversed) |
39a10a29 | 6268 | code = rs6000_reverse_condition (mode, code); |
12a4e8c5 | 6269 | |
39a10a29 | 6270 | switch (code) |
12a4e8c5 GK |
6271 | { |
6272 | /* Not all of these are actually distinct opcodes, but | |
6273 | we distinguish them for clarity of the resulting assembler. */ | |
50a0b056 GK |
6274 | case NE: case LTGT: |
6275 | ccode = "ne"; break; | |
6276 | case EQ: case UNEQ: | |
6277 | ccode = "eq"; break; | |
6278 | case GE: case GEU: | |
6279 | ccode = "ge"; break; | |
6280 | case GT: case GTU: case UNGT: | |
6281 | ccode = "gt"; break; | |
6282 | case LE: case LEU: | |
6283 | ccode = "le"; break; | |
6284 | case LT: case LTU: case UNLT: | |
6285 | ccode = "lt"; break; | |
12a4e8c5 GK |
6286 | case UNORDERED: ccode = "un"; break; |
6287 | case ORDERED: ccode = "nu"; break; | |
6288 | case UNGE: ccode = "nl"; break; | |
6289 | case UNLE: ccode = "ng"; break; | |
6290 | default: | |
a4f6c312 | 6291 | abort (); |
12a4e8c5 GK |
6292 | } |
6293 | ||
94a54f47 GK |
6294 | /* Maybe we have a guess as to how likely the branch is. |
6295 | The old mnemonics don't have a way to specify this information. */ | |
12a4e8c5 GK |
6296 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
6297 | if (note != NULL_RTX) | |
6298 | { | |
6299 | /* PROB is the difference from 50%. */ | |
6300 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
6301 | ||
6302 | /* For branches that are very close to 50%, assume not-taken. */ | |
6303 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
6304 | && ((prob > 0) ^ need_longbranch)) | |
6305 | pred = "+"; | |
6306 | else | |
6307 | pred = "-"; | |
6308 | } | |
6309 | else | |
6310 | pred = ""; | |
6311 | ||
6312 | if (label == NULL) | |
94a54f47 | 6313 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 6314 | else |
94a54f47 | 6315 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 6316 | |
37c67319 GK |
6317 | /* We need to escape any '%' characters in the reg_names string. |
6318 | Assume they'd only be the first character... */ | |
6319 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') | |
6320 | *s++ = '%'; | |
94a54f47 | 6321 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
6322 | |
6323 | if (label != NULL) | |
6324 | { | |
6325 | /* If the branch distance was too far, we may have to use an | |
6326 | unconditional branch to go the distance. */ | |
6327 | if (need_longbranch) | |
44518ddd | 6328 | s += sprintf (s, ",$+8\n\tb %s", label); |
12a4e8c5 GK |
6329 | else |
6330 | s += sprintf (s, ",%s", label); | |
6331 | } | |
6332 | ||
6333 | return string; | |
6334 | } | |
50a0b056 GK |
6335 | |
6336 | /* Emit a conditional move: move TRUE_COND to DEST if OP of the | |
6337 | operands of the last comparison is nonzero/true, FALSE_COND if it | |
6338 | is zero/false. Return 0 if the hardware has no such operation. */ | |
a4f6c312 | 6339 | |
50a0b056 GK |
6340 | int |
6341 | rs6000_emit_cmove (dest, op, true_cond, false_cond) | |
6342 | rtx dest; | |
6343 | rtx op; | |
6344 | rtx true_cond; | |
6345 | rtx false_cond; | |
6346 | { | |
6347 | enum rtx_code code = GET_CODE (op); | |
6348 | rtx op0 = rs6000_compare_op0; | |
6349 | rtx op1 = rs6000_compare_op1; | |
6350 | REAL_VALUE_TYPE c1; | |
6351 | enum machine_mode mode = GET_MODE (op0); | |
6352 | rtx temp; | |
6353 | ||
6354 | /* First, work out if the hardware can do this at all, or | |
6355 | if it's too slow... */ | |
6356 | /* If the comparison is an integer one, since we only have fsel | |
6357 | it'll be cheaper to use a branch. */ | |
6358 | if (! rs6000_compare_fp_p) | |
6359 | return 0; | |
6360 | ||
6361 | /* Eliminate half of the comparisons by switching operands, this | |
6362 | makes the remaining code simpler. */ | |
6363 | if (code == UNLT || code == UNGT || code == UNORDERED || code == NE | |
6364 | || code == LTGT || code == LT) | |
6365 | { | |
6366 | code = reverse_condition_maybe_unordered (code); | |
6367 | temp = true_cond; | |
6368 | true_cond = false_cond; | |
6369 | false_cond = temp; | |
6370 | } | |
6371 | ||
6372 | /* UNEQ and LTGT take four instructions for a comparison with zero, | |
6373 | it'll probably be faster to use a branch here too. */ | |
6374 | if (code == UNEQ) | |
6375 | return 0; | |
6376 | ||
6377 | if (GET_CODE (op1) == CONST_DOUBLE) | |
6378 | REAL_VALUE_FROM_CONST_DOUBLE (c1, op1); | |
6379 | ||
6380 | /* We're going to try to implement comparions by performing | |
6381 | a subtract, then comparing against zero. Unfortunately, | |
6382 | Inf - Inf is NaN which is not zero, and so if we don't | |
6383 | know that the the operand is finite and the comparison | |
6384 | would treat EQ different to UNORDERED, we can't do it. */ | |
6385 | if (! flag_unsafe_math_optimizations | |
6386 | && code != GT && code != UNGE | |
6387 | && (GET_CODE (op1) != CONST_DOUBLE || target_isinf (c1)) | |
6388 | /* Constructs of the form (a OP b ? a : b) are safe. */ | |
6389 | && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond)) | |
6390 | || (! rtx_equal_p (op0, true_cond) | |
6391 | && ! rtx_equal_p (op1, true_cond)))) | |
6392 | return 0; | |
6393 | /* At this point we know we can use fsel. */ | |
6394 | ||
6395 | /* Reduce the comparison to a comparison against zero. */ | |
6396 | temp = gen_reg_rtx (mode); | |
6397 | emit_insn (gen_rtx_SET (VOIDmode, temp, | |
6398 | gen_rtx_MINUS (mode, op0, op1))); | |
6399 | op0 = temp; | |
6400 | op1 = CONST0_RTX (mode); | |
6401 | ||
6402 | /* If we don't care about NaNs we can reduce some of the comparisons | |
6403 | down to faster ones. */ | |
6404 | if (flag_unsafe_math_optimizations) | |
6405 | switch (code) | |
6406 | { | |
6407 | case GT: | |
6408 | code = LE; | |
6409 | temp = true_cond; | |
6410 | true_cond = false_cond; | |
6411 | false_cond = temp; | |
6412 | break; | |
6413 | case UNGE: | |
6414 | code = GE; | |
6415 | break; | |
6416 | case UNEQ: | |
6417 | code = EQ; | |
6418 | break; | |
6419 | default: | |
6420 | break; | |
6421 | } | |
6422 | ||
6423 | /* Now, reduce everything down to a GE. */ | |
6424 | switch (code) | |
6425 | { | |
6426 | case GE: | |
6427 | break; | |
6428 | ||
6429 | case LE: | |
6430 | temp = gen_reg_rtx (mode); | |
6431 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (mode, op0))); | |
6432 | op0 = temp; | |
6433 | break; | |
6434 | ||
6435 | case ORDERED: | |
6436 | temp = gen_reg_rtx (mode); | |
6437 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (mode, op0))); | |
6438 | op0 = temp; | |
6439 | break; | |
6440 | ||
6441 | case EQ: | |
6442 | temp = gen_reg_rtx (mode); | |
6443 | emit_insn (gen_rtx_SET (VOIDmode, temp, | |
6444 | gen_rtx_NEG (mode, | |
6445 | gen_rtx_ABS (mode, op0)))); | |
6446 | op0 = temp; | |
6447 | break; | |
6448 | ||
6449 | case UNGE: | |
6450 | temp = gen_reg_rtx (mode); | |
6451 | emit_insn (gen_rtx_SET (VOIDmode, temp, | |
6452 | gen_rtx_IF_THEN_ELSE (mode, | |
6453 | gen_rtx_GE (VOIDmode, | |
6454 | op0, op1), | |
6455 | true_cond, false_cond))); | |
6456 | false_cond = temp; | |
6457 | true_cond = false_cond; | |
6458 | ||
6459 | temp = gen_reg_rtx (mode); | |
6460 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (mode, op0))); | |
6461 | op0 = temp; | |
6462 | break; | |
6463 | ||
6464 | case GT: | |
6465 | temp = gen_reg_rtx (mode); | |
6466 | emit_insn (gen_rtx_SET (VOIDmode, temp, | |
6467 | gen_rtx_IF_THEN_ELSE (mode, | |
6468 | gen_rtx_GE (VOIDmode, | |
6469 | op0, op1), | |
6470 | true_cond, false_cond))); | |
6471 | true_cond = temp; | |
6472 | false_cond = true_cond; | |
6473 | ||
6474 | temp = gen_reg_rtx (mode); | |
6475 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (mode, op0))); | |
6476 | op0 = temp; | |
6477 | break; | |
6478 | ||
6479 | default: | |
6480 | abort (); | |
6481 | } | |
6482 | ||
6483 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
9f1a9740 | 6484 | gen_rtx_IF_THEN_ELSE (GET_MODE (dest), |
50a0b056 GK |
6485 | gen_rtx_GE (VOIDmode, |
6486 | op0, op1), | |
6487 | true_cond, false_cond))); | |
6488 | return 1; | |
6489 | } | |
6490 | ||
6491 | void | |
6492 | rs6000_emit_minmax (dest, code, op0, op1) | |
6493 | rtx dest; | |
6494 | enum rtx_code code; | |
6495 | rtx op0; | |
6496 | rtx op1; | |
6497 | { | |
6498 | enum machine_mode mode = GET_MODE (op0); | |
6499 | rtx target; | |
6500 | if (code == SMAX || code == UMAX) | |
6501 | target = emit_conditional_move (dest, GE, op0, op1, mode, | |
6502 | op0, op1, mode, 0); | |
6503 | else | |
6504 | target = emit_conditional_move (dest, GE, op0, op1, mode, | |
6505 | op1, op0, mode, 0); | |
6506 | if (target == NULL_RTX) | |
6507 | abort (); | |
6508 | if (target != dest) | |
6509 | emit_move_insn (dest, target); | |
6510 | } | |
12a4e8c5 | 6511 | \f |
a4f6c312 SS |
6512 | /* This page contains routines that are used to determine what the |
6513 | function prologue and epilogue code will do and write them out. */ | |
9878760c | 6514 | |
a4f6c312 SS |
6515 | /* Return the first fixed-point register that is required to be |
6516 | saved. 32 if none. */ | |
9878760c RK |
6517 | |
6518 | int | |
6519 | first_reg_to_save () | |
6520 | { | |
6521 | int first_reg; | |
6522 | ||
6523 | /* Find lowest numbered live register. */ | |
6524 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
a38d360d GK |
6525 | if (regs_ever_live[first_reg] |
6526 | && (! call_used_regs[first_reg] | |
6527 | || (first_reg == PIC_OFFSET_TABLE_REGNUM | |
f607bc57 ZW |
6528 | && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
6529 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))) | |
9878760c RK |
6530 | break; |
6531 | ||
b5253831 DE |
6532 | if (profile_flag) |
6533 | { | |
6534 | /* AIX must save/restore every register that contains a parameter | |
6535 | before/after the .__mcount call plus an additional register | |
6536 | for the static chain, if needed; use registers from 30 down to 22 | |
6537 | to do this. */ | |
ee890fe2 | 6538 | if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) |
b5253831 DE |
6539 | { |
6540 | int last_parm_reg, profile_first_reg; | |
6541 | ||
6542 | /* Figure out last used parameter register. The proper thing | |
6543 | to do is to walk incoming args of the function. A function | |
6544 | might have live parameter registers even if it has no | |
6545 | incoming args. */ | |
6546 | for (last_parm_reg = 10; | |
6547 | last_parm_reg > 2 && ! regs_ever_live [last_parm_reg]; | |
6548 | last_parm_reg--) | |
6549 | ; | |
6550 | ||
6551 | /* Calculate first reg for saving parameter registers | |
6552 | and static chain. | |
6553 | Skip reg 31 which may contain the frame pointer. */ | |
6554 | profile_first_reg = (33 - last_parm_reg | |
6555 | - (current_function_needs_context ? 1 : 0)); | |
ee890fe2 SS |
6556 | #if TARGET_MACHO |
6557 | /* Need to skip another reg to account for R31 being PICBASE | |
6558 | (when flag_pic is set) or R30 being used as the frame | |
6559 | pointer (when flag_pic is not set). */ | |
6560 | --profile_first_reg; | |
6561 | #endif | |
b5253831 DE |
6562 | /* Do not save frame pointer if no parameters needs to be saved. */ |
6563 | if (profile_first_reg == 31) | |
6564 | profile_first_reg = 32; | |
6565 | ||
6566 | if (first_reg > profile_first_reg) | |
6567 | first_reg = profile_first_reg; | |
6568 | } | |
e165f3f0 | 6569 | |
b5253831 DE |
6570 | /* SVR4 may need one register to preserve the static chain. */ |
6571 | else if (current_function_needs_context) | |
6572 | { | |
6573 | /* Skip reg 31 which may contain the frame pointer. */ | |
6574 | if (first_reg > 30) | |
6575 | first_reg = 30; | |
6576 | } | |
6577 | } | |
e165f3f0 | 6578 | |
ee890fe2 SS |
6579 | #if TARGET_MACHO |
6580 | if (flag_pic && current_function_uses_pic_offset_table && | |
6581 | (first_reg > PIC_OFFSET_TABLE_REGNUM)) | |
6582 | return PIC_OFFSET_TABLE_REGNUM; | |
6583 | #endif | |
6584 | ||
9878760c RK |
6585 | return first_reg; |
6586 | } | |
6587 | ||
6588 | /* Similar, for FP regs. */ | |
6589 | ||
6590 | int | |
6591 | first_fp_reg_to_save () | |
6592 | { | |
6593 | int first_reg; | |
6594 | ||
6595 | /* Find lowest numbered live register. */ | |
6596 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
6597 | if (regs_ever_live[first_reg]) | |
6598 | break; | |
6599 | ||
6600 | return first_reg; | |
6601 | } | |
00b960c7 AH |
6602 | |
6603 | /* Similar, for AltiVec regs. */ | |
6604 | ||
6605 | static int | |
6606 | first_altivec_reg_to_save () | |
6607 | { | |
6608 | int i; | |
6609 | ||
6610 | /* Stack frame remains as is unless we are in AltiVec ABI. */ | |
6611 | if (! TARGET_ALTIVEC_ABI) | |
6612 | return LAST_ALTIVEC_REGNO + 1; | |
6613 | ||
6614 | /* Find lowest numbered live register. */ | |
6615 | for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i) | |
6616 | if (regs_ever_live[i]) | |
6617 | break; | |
6618 | ||
6619 | return i; | |
6620 | } | |
6621 | ||
6622 | /* Return a 32-bit mask of the AltiVec registers we need to set in | |
6623 | VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in | |
6624 | the 32-bit word is 0. */ | |
6625 | ||
6626 | static unsigned int | |
6627 | compute_vrsave_mask () | |
6628 | { | |
6629 | unsigned int i, mask = 0; | |
6630 | ||
6631 | /* First, find out if we use _any_ altivec registers. */ | |
6632 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
6633 | if (regs_ever_live[i]) | |
6634 | mask |= ALTIVEC_REG_BIT (i); | |
6635 | ||
6636 | if (mask == 0) | |
6637 | return mask; | |
6638 | ||
6639 | /* Next, add all registers that are call-clobbered. We do this | |
6640 | because post-reload register optimizers such as regrename_optimize | |
6641 | may choose to use them. They never change the register class | |
6642 | chosen by reload, so cannot create new uses of altivec registers | |
6643 | if there were none before, so the early exit above is safe. */ | |
6644 | /* ??? Alternately, we could define HARD_REGNO_RENAME_OK to disallow | |
6645 | altivec registers not saved in the mask, which might well make the | |
6646 | adjustments below more effective in eliding the save/restore of | |
6647 | VRSAVE in small functions. */ | |
6648 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
6649 | if (call_used_regs[i]) | |
6650 | mask |= ALTIVEC_REG_BIT (i); | |
6651 | ||
6652 | /* Next, remove the argument registers from the set. These must | |
6653 | be in the VRSAVE mask set by the caller, so we don't need to add | |
6654 | them in again. More importantly, the mask we compute here is | |
6655 | used to generate CLOBBERs in the set_vrsave insn, and we do not | |
6656 | wish the argument registers to die. */ | |
6657 | for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i) | |
6658 | mask &= ~ALTIVEC_REG_BIT (i); | |
6659 | ||
6660 | /* Similarly, remove the return value from the set. */ | |
6661 | { | |
6662 | bool yes = false; | |
6663 | diddle_return_value (is_altivec_return_reg, &yes); | |
6664 | if (yes) | |
6665 | mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN); | |
6666 | } | |
6667 | ||
6668 | return mask; | |
6669 | } | |
6670 | ||
6671 | static void | |
6672 | is_altivec_return_reg (reg, xyes) | |
6673 | rtx reg; | |
6674 | void *xyes; | |
6675 | { | |
6676 | bool *yes = (bool *) xyes; | |
6677 | if (REGNO (reg) == ALTIVEC_ARG_RETURN) | |
6678 | *yes = true; | |
6679 | } | |
6680 | ||
4697a36c MM |
6681 | \f |
6682 | /* Calculate the stack information for the current function. This is | |
6683 | complicated by having two separate calling sequences, the AIX calling | |
6684 | sequence and the V.4 calling sequence. | |
6685 | ||
592696dd | 6686 | AIX (and Darwin/Mac OS X) stack frames look like: |
a260abc9 | 6687 | 32-bit 64-bit |
4697a36c | 6688 | SP----> +---------------------------------------+ |
a260abc9 | 6689 | | back chain to caller | 0 0 |
4697a36c | 6690 | +---------------------------------------+ |
a260abc9 | 6691 | | saved CR | 4 8 (8-11) |
4697a36c | 6692 | +---------------------------------------+ |
a260abc9 | 6693 | | saved LR | 8 16 |
4697a36c | 6694 | +---------------------------------------+ |
a260abc9 | 6695 | | reserved for compilers | 12 24 |
4697a36c | 6696 | +---------------------------------------+ |
a260abc9 | 6697 | | reserved for binders | 16 32 |
4697a36c | 6698 | +---------------------------------------+ |
a260abc9 | 6699 | | saved TOC pointer | 20 40 |
4697a36c | 6700 | +---------------------------------------+ |
a260abc9 | 6701 | | Parameter save area (P) | 24 48 |
4697a36c | 6702 | +---------------------------------------+ |
a260abc9 | 6703 | | Alloca space (A) | 24+P etc. |
802a0058 | 6704 | +---------------------------------------+ |
a7df97e6 | 6705 | | Local variable space (L) | 24+P+A |
4697a36c | 6706 | +---------------------------------------+ |
a7df97e6 | 6707 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 6708 | +---------------------------------------+ |
00b960c7 AH |
6709 | | Save area for AltiVec registers (W) | 24+P+A+L+X |
6710 | +---------------------------------------+ | |
6711 | | AltiVec alignment padding (Y) | 24+P+A+L+X+W | |
6712 | +---------------------------------------+ | |
6713 | | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y | |
4697a36c | 6714 | +---------------------------------------+ |
00b960c7 AH |
6715 | | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z |
6716 | +---------------------------------------+ | |
6717 | | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G | |
4697a36c MM |
6718 | +---------------------------------------+ |
6719 | old SP->| back chain to caller's caller | | |
6720 | +---------------------------------------+ | |
6721 | ||
5376a30c KR |
6722 | The required alignment for AIX configurations is two words (i.e., 8 |
6723 | or 16 bytes). | |
6724 | ||
6725 | ||
4697a36c MM |
6726 | V.4 stack frames look like: |
6727 | ||
6728 | SP----> +---------------------------------------+ | |
6729 | | back chain to caller | 0 | |
6730 | +---------------------------------------+ | |
5eb387b8 | 6731 | | caller's saved LR | 4 |
4697a36c MM |
6732 | +---------------------------------------+ |
6733 | | Parameter save area (P) | 8 | |
6734 | +---------------------------------------+ | |
a7df97e6 MM |
6735 | | Alloca space (A) | 8+P |
6736 | +---------------------------------------+ | |
6737 | | Varargs save area (V) | 8+P+A | |
6738 | +---------------------------------------+ | |
6739 | | Local variable space (L) | 8+P+A+V | |
6740 | +---------------------------------------+ | |
6741 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 6742 | +---------------------------------------+ |
00b960c7 AH |
6743 | | Save area for AltiVec registers (W) | 8+P+A+V+L+X |
6744 | +---------------------------------------+ | |
6745 | | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W | |
6746 | +---------------------------------------+ | |
6747 | | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y | |
6748 | +---------------------------------------+ | |
6749 | | saved CR (C) | 8+P+A+V+L+X+W+Y+Z | |
a7df97e6 | 6750 | +---------------------------------------+ |
00b960c7 | 6751 | | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C |
a7df97e6 | 6752 | +---------------------------------------+ |
00b960c7 | 6753 | | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G |
4697a36c MM |
6754 | +---------------------------------------+ |
6755 | old SP->| back chain to caller's caller | | |
6756 | +---------------------------------------+ | |
b6c9286a | 6757 | |
5376a30c KR |
6758 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
6759 | given. (But note below and in sysv4.h that we require only 8 and | |
6760 | may round up the size of our stack frame anyways. The historical | |
6761 | reason is early versions of powerpc-linux which didn't properly | |
6762 | align the stack at program startup. A happy side-effect is that | |
6763 | -mno-eabi libraries can be used with -meabi programs.) | |
6764 | ||
5376a30c KR |
6765 | The EABI configuration defaults to the V.4 layout, unless |
6766 | -mcall-aix is used, in which case the AIX layout is used. However, | |
6767 | the stack alignment requirements may differ. If -mno-eabi is not | |
6768 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
6769 | given, the required alignment is 16 bytes. (But see V.4 comment | |
6770 | above.) */ | |
4697a36c | 6771 | |
61b2fbe7 MM |
6772 | #ifndef ABI_STACK_BOUNDARY |
6773 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
6774 | #endif | |
6775 | ||
4697a36c MM |
6776 | rs6000_stack_t * |
6777 | rs6000_stack_info () | |
6778 | { | |
6779 | static rs6000_stack_t info, zero_info; | |
6780 | rs6000_stack_t *info_ptr = &info; | |
9ebbca7d | 6781 | int reg_size = TARGET_POWERPC64 ? 8 : 4; |
24d304eb | 6782 | enum rs6000_abi abi; |
83720594 | 6783 | int ehrd_size; |
b6c9286a | 6784 | int total_raw_size; |
4697a36c | 6785 | |
a4f6c312 | 6786 | /* Zero all fields portably. */ |
4697a36c MM |
6787 | info = zero_info; |
6788 | ||
a4f6c312 | 6789 | /* Select which calling sequence. */ |
b6c9286a | 6790 | info_ptr->abi = abi = DEFAULT_ABI; |
9878760c | 6791 | |
a4f6c312 | 6792 | /* Calculate which registers need to be saved & save area size. */ |
4697a36c | 6793 | info_ptr->first_gp_reg_save = first_reg_to_save (); |
906fb125 GK |
6794 | /* Assume that we will have to save PIC_OFFSET_TABLE_REGNUM, |
6795 | even if it currently looks like we won't. */ | |
2bfcf297 | 6796 | if (((TARGET_TOC && TARGET_MINIMAL_TOC) |
f607bc57 ZW |
6797 | || (flag_pic == 1 && abi == ABI_V4) |
6798 | || (flag_pic && abi == ABI_DARWIN)) | |
906fb125 GK |
6799 | && info_ptr->first_gp_reg_save > PIC_OFFSET_TABLE_REGNUM) |
6800 | info_ptr->gp_size = reg_size * (32 - PIC_OFFSET_TABLE_REGNUM); | |
6801 | else | |
6802 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c MM |
6803 | |
6804 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); | |
6805 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
6806 | ||
00b960c7 AH |
6807 | info_ptr->first_altivec_reg_save = first_altivec_reg_to_save (); |
6808 | info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1 | |
6809 | - info_ptr->first_altivec_reg_save); | |
6810 | ||
592696dd | 6811 | /* Does this function call anything? */ |
71f123ca FS |
6812 | info_ptr->calls_p = (! current_function_is_leaf |
6813 | || cfun->machine->ra_needs_full_frame); | |
b6c9286a | 6814 | |
a4f6c312 | 6815 | /* Determine if we need to save the link register. */ |
71f123ca | 6816 | if (rs6000_ra_ever_killed () |
38c1f2d7 | 6817 | || (DEFAULT_ABI == ABI_AIX && profile_flag) |
4697a36c MM |
6818 | #ifdef TARGET_RELOCATABLE |
6819 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
6820 | #endif | |
6821 | || (info_ptr->first_fp_reg_save != 64 | |
6822 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
00b960c7 | 6823 | || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO |
24d304eb | 6824 | || (abi == ABI_V4 && current_function_calls_alloca) |
a4f6c312 SS |
6825 | || (DEFAULT_ABI == ABI_DARWIN |
6826 | && flag_pic | |
6827 | && current_function_uses_pic_offset_table) | |
4697a36c MM |
6828 | || info_ptr->calls_p) |
6829 | { | |
6830 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 6831 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
6832 | } |
6833 | ||
9ebbca7d GK |
6834 | /* Determine if we need to save the condition code registers. */ |
6835 | if (regs_ever_live[CR2_REGNO] | |
6836 | || regs_ever_live[CR3_REGNO] | |
6837 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
6838 | { |
6839 | info_ptr->cr_save_p = 1; | |
f607bc57 | 6840 | if (abi == ABI_V4) |
4697a36c MM |
6841 | info_ptr->cr_size = reg_size; |
6842 | } | |
6843 | ||
83720594 RH |
6844 | /* If the current function calls __builtin_eh_return, then we need |
6845 | to allocate stack space for registers that will hold data for | |
6846 | the exception handler. */ | |
6847 | if (current_function_calls_eh_return) | |
6848 | { | |
6849 | unsigned int i; | |
6850 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i) | |
6851 | continue; | |
6852 | ehrd_size = i * UNITS_PER_WORD; | |
6853 | } | |
6854 | else | |
6855 | ehrd_size = 0; | |
6856 | ||
592696dd | 6857 | /* Determine various sizes. */ |
4697a36c MM |
6858 | info_ptr->reg_size = reg_size; |
6859 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
6860 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 | 6861 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
a4f6c312 SS |
6862 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, |
6863 | 8); | |
00b960c7 AH |
6864 | |
6865 | if (TARGET_ALTIVEC_ABI) | |
6866 | { | |
6867 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
6868 | info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0; | |
6869 | } | |
6870 | else | |
6871 | { | |
6872 | info_ptr->vrsave_mask = 0; | |
6873 | info_ptr->vrsave_size = 0; | |
6874 | } | |
b6c9286a | 6875 | |
592696dd | 6876 | /* Calculate the offsets. */ |
24d304eb | 6877 | switch (abi) |
4697a36c | 6878 | { |
b6c9286a | 6879 | case ABI_NONE: |
24d304eb | 6880 | default: |
b6c9286a MM |
6881 | abort (); |
6882 | ||
6883 | case ABI_AIX: | |
6884 | case ABI_AIX_NODESC: | |
ee890fe2 | 6885 | case ABI_DARWIN: |
b6c9286a MM |
6886 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
6887 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
00b960c7 AH |
6888 | |
6889 | if (TARGET_ALTIVEC_ABI) | |
6890 | { | |
6891 | info_ptr->vrsave_save_offset | |
6892 | = info_ptr->gp_save_offset - info_ptr->vrsave_size; | |
6893 | ||
6894 | /* Align stack so vector save area is on a quadword boundary. */ | |
6895 | if (info_ptr->altivec_size != 0) | |
6896 | info_ptr->altivec_padding_size | |
6897 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
6898 | else | |
6899 | info_ptr->altivec_padding_size = 0; | |
6900 | ||
6901 | info_ptr->altivec_save_offset | |
6902 | = info_ptr->vrsave_save_offset | |
6903 | - info_ptr->altivec_padding_size | |
6904 | - info_ptr->altivec_size; | |
6905 | ||
6906 | /* Adjust for AltiVec case. */ | |
6907 | info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size; | |
6908 | } | |
6909 | else | |
6910 | info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size; | |
a260abc9 DE |
6911 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
6912 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
6913 | break; |
6914 | ||
6915 | case ABI_V4: | |
b6c9286a MM |
6916 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
6917 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 | 6918 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
00b960c7 AH |
6919 | |
6920 | if (TARGET_ALTIVEC_ABI) | |
6921 | { | |
6922 | info_ptr->vrsave_save_offset | |
6923 | = info_ptr->cr_save_offset - info_ptr->vrsave_size; | |
6924 | ||
6925 | /* Align stack so vector save area is on a quadword boundary. */ | |
6926 | if (info_ptr->altivec_size != 0) | |
6927 | info_ptr->altivec_padding_size | |
6928 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
6929 | else | |
6930 | info_ptr->altivec_padding_size = 0; | |
6931 | ||
6932 | info_ptr->altivec_save_offset | |
6933 | = info_ptr->vrsave_save_offset | |
6934 | - info_ptr->altivec_padding_size | |
6935 | - info_ptr->altivec_size; | |
6936 | ||
6937 | /* Adjust for AltiVec case. */ | |
6938 | info_ptr->toc_save_offset | |
6939 | = info_ptr->altivec_save_offset - info_ptr->toc_size; | |
6940 | } | |
6941 | else | |
6942 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
83720594 | 6943 | info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size; |
b6c9286a MM |
6944 | info_ptr->lr_save_offset = reg_size; |
6945 | break; | |
4697a36c MM |
6946 | } |
6947 | ||
00b960c7 AH |
6948 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
6949 | + info_ptr->gp_size | |
6950 | + info_ptr->altivec_size | |
6951 | + info_ptr->altivec_padding_size | |
6952 | + info_ptr->vrsave_size | |
6953 | + ehrd_size | |
6954 | + info_ptr->cr_size | |
6955 | + info_ptr->lr_size | |
6956 | + info_ptr->vrsave_size | |
6957 | + info_ptr->toc_size, | |
6958 | (TARGET_ALTIVEC_ABI || ABI_DARWIN) | |
6959 | ? 16 : 8); | |
6960 | ||
ff381587 MM |
6961 | total_raw_size = (info_ptr->vars_size |
6962 | + info_ptr->parm_size | |
ff381587 MM |
6963 | + info_ptr->save_size |
6964 | + info_ptr->varargs_size | |
6965 | + info_ptr->fixed_size); | |
6966 | ||
a4f6c312 SS |
6967 | info_ptr->total_size = |
6968 | RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
ff381587 MM |
6969 | |
6970 | /* Determine if we need to allocate any stack frame: | |
6971 | ||
a4f6c312 SS |
6972 | For AIX we need to push the stack if a frame pointer is needed |
6973 | (because the stack might be dynamically adjusted), if we are | |
6974 | debugging, if we make calls, or if the sum of fp_save, gp_save, | |
6975 | and local variables are more than the space needed to save all | |
6976 | non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 | |
6977 | + 18*8 = 288 (GPR13 reserved). | |
ff381587 | 6978 | |
a4f6c312 SS |
6979 | For V.4 we don't have the stack cushion that AIX uses, but assume |
6980 | that the debugger can handle stackless frames. */ | |
ff381587 MM |
6981 | |
6982 | if (info_ptr->calls_p) | |
6983 | info_ptr->push_p = 1; | |
6984 | ||
f607bc57 | 6985 | else if (abi == ABI_V4) |
ff381587 | 6986 | info_ptr->push_p = (total_raw_size > info_ptr->fixed_size |
9ebbca7d | 6987 | || info_ptr->calls_p); |
ff381587 MM |
6988 | |
6989 | else | |
6990 | info_ptr->push_p = (frame_pointer_needed | |
ee890fe2 | 6991 | || (abi != ABI_DARWIN && write_symbols != NO_DEBUG) |
ff381587 | 6992 | || ((total_raw_size - info_ptr->fixed_size) |
bfc79d3b | 6993 | > (TARGET_32BIT ? 220 : 288))); |
ff381587 | 6994 | |
a4f6c312 | 6995 | /* Zero offsets if we're not saving those registers. */ |
8dda1a21 | 6996 | if (info_ptr->fp_size == 0) |
4697a36c MM |
6997 | info_ptr->fp_save_offset = 0; |
6998 | ||
8dda1a21 | 6999 | if (info_ptr->gp_size == 0) |
4697a36c MM |
7000 | info_ptr->gp_save_offset = 0; |
7001 | ||
00b960c7 AH |
7002 | if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0) |
7003 | info_ptr->altivec_save_offset = 0; | |
7004 | ||
7005 | if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0) | |
7006 | info_ptr->vrsave_save_offset = 0; | |
7007 | ||
c81fc13e | 7008 | if (! info_ptr->lr_save_p) |
4697a36c MM |
7009 | info_ptr->lr_save_offset = 0; |
7010 | ||
c81fc13e | 7011 | if (! info_ptr->cr_save_p) |
4697a36c MM |
7012 | info_ptr->cr_save_offset = 0; |
7013 | ||
c81fc13e | 7014 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
7015 | info_ptr->toc_save_offset = 0; |
7016 | ||
4697a36c MM |
7017 | return info_ptr; |
7018 | } | |
7019 | ||
7020 | void | |
7021 | debug_stack_info (info) | |
7022 | rs6000_stack_t *info; | |
9878760c | 7023 | { |
d330fd93 | 7024 | const char *abi_string; |
24d304eb | 7025 | |
c81fc13e | 7026 | if (! info) |
4697a36c MM |
7027 | info = rs6000_stack_info (); |
7028 | ||
7029 | fprintf (stderr, "\nStack information for function %s:\n", | |
7030 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
7031 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
7032 | : "<unknown>")); | |
7033 | ||
24d304eb RK |
7034 | switch (info->abi) |
7035 | { | |
b6c9286a MM |
7036 | default: abi_string = "Unknown"; break; |
7037 | case ABI_NONE: abi_string = "NONE"; break; | |
f607bc57 | 7038 | case ABI_AIX: |
b6c9286a | 7039 | case ABI_AIX_NODESC: abi_string = "AIX"; break; |
ee890fe2 | 7040 | case ABI_DARWIN: abi_string = "Darwin"; break; |
b6c9286a | 7041 | case ABI_V4: abi_string = "V.4"; break; |
24d304eb RK |
7042 | } |
7043 | ||
7044 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
7045 | ||
00b960c7 AH |
7046 | if (TARGET_ALTIVEC_ABI) |
7047 | fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n"); | |
7048 | ||
4697a36c MM |
7049 | if (info->first_gp_reg_save != 32) |
7050 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
7051 | ||
7052 | if (info->first_fp_reg_save != 64) | |
7053 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 7054 | |
00b960c7 AH |
7055 | if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO) |
7056 | fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n", | |
7057 | info->first_altivec_reg_save); | |
7058 | ||
4697a36c MM |
7059 | if (info->lr_save_p) |
7060 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 7061 | |
4697a36c MM |
7062 | if (info->cr_save_p) |
7063 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
7064 | ||
b6c9286a MM |
7065 | if (info->toc_save_p) |
7066 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
7067 | ||
00b960c7 AH |
7068 | if (info->vrsave_mask) |
7069 | fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask); | |
7070 | ||
4697a36c MM |
7071 | if (info->push_p) |
7072 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
7073 | ||
7074 | if (info->calls_p) | |
7075 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
7076 | ||
4697a36c MM |
7077 | if (info->gp_save_offset) |
7078 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
7079 | ||
7080 | if (info->fp_save_offset) | |
7081 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
7082 | ||
00b960c7 AH |
7083 | if (info->altivec_save_offset) |
7084 | fprintf (stderr, "\taltivec_save_offset = %5d\n", | |
7085 | info->altivec_save_offset); | |
7086 | ||
7087 | if (info->vrsave_save_offset) | |
7088 | fprintf (stderr, "\tvrsave_save_offset = %5d\n", | |
7089 | info->vrsave_save_offset); | |
7090 | ||
4697a36c MM |
7091 | if (info->lr_save_offset) |
7092 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
7093 | ||
7094 | if (info->cr_save_offset) | |
7095 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
7096 | ||
b6c9286a MM |
7097 | if (info->toc_save_offset) |
7098 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
7099 | ||
4697a36c MM |
7100 | if (info->varargs_save_offset) |
7101 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
7102 | ||
7103 | if (info->total_size) | |
7104 | fprintf (stderr, "\ttotal_size = %5d\n", info->total_size); | |
7105 | ||
7106 | if (info->varargs_size) | |
7107 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
7108 | ||
7109 | if (info->vars_size) | |
7110 | fprintf (stderr, "\tvars_size = %5d\n", info->vars_size); | |
7111 | ||
7112 | if (info->parm_size) | |
7113 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
7114 | ||
7115 | if (info->fixed_size) | |
7116 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
7117 | ||
7118 | if (info->gp_size) | |
7119 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
7120 | ||
7121 | if (info->fp_size) | |
7122 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
7123 | ||
00b960c7 AH |
7124 | if (info->altivec_size) |
7125 | fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size); | |
7126 | ||
7127 | if (info->vrsave_size) | |
7128 | fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size); | |
7129 | ||
7130 | if (info->altivec_padding_size) | |
7131 | fprintf (stderr, "\taltivec_padding_size= %5d\n", | |
7132 | info->altivec_padding_size); | |
7133 | ||
a4f6c312 | 7134 | if (info->lr_size) |
ed947a96 | 7135 | fprintf (stderr, "\tlr_size = %5d\n", info->lr_size); |
b6c9286a | 7136 | |
4697a36c MM |
7137 | if (info->cr_size) |
7138 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
7139 | ||
a4f6c312 | 7140 | if (info->toc_size) |
b6c9286a MM |
7141 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); |
7142 | ||
4697a36c MM |
7143 | if (info->save_size) |
7144 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
7145 | ||
7146 | if (info->reg_size != 4) | |
7147 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
7148 | ||
7149 | fprintf (stderr, "\n"); | |
9878760c | 7150 | } |
71f123ca FS |
7151 | |
7152 | rtx | |
7153 | rs6000_return_addr (count, frame) | |
7154 | int count; | |
7155 | rtx frame; | |
7156 | { | |
a4f6c312 SS |
7157 | /* Currently we don't optimize very well between prolog and body |
7158 | code and for PIC code the code can be actually quite bad, so | |
7159 | don't try to be too clever here. */ | |
3418dd3a FS |
7160 | if (count != 0 |
7161 | || flag_pic != 0 | |
7162 | || DEFAULT_ABI == ABI_AIX | |
7163 | || DEFAULT_ABI == ABI_AIX_NODESC) | |
71f123ca FS |
7164 | { |
7165 | cfun->machine->ra_needs_full_frame = 1; | |
8ac61af7 RK |
7166 | |
7167 | return | |
7168 | gen_rtx_MEM | |
7169 | (Pmode, | |
7170 | memory_address | |
7171 | (Pmode, | |
7172 | plus_constant (copy_to_reg | |
7173 | (gen_rtx_MEM (Pmode, | |
7174 | memory_address (Pmode, frame))), | |
7175 | RETURN_ADDRESS_OFFSET))); | |
71f123ca FS |
7176 | } |
7177 | ||
9e2f7ec7 | 7178 | return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM); |
71f123ca FS |
7179 | } |
7180 | ||
7181 | static int | |
7182 | rs6000_ra_ever_killed () | |
7183 | { | |
7184 | rtx top; | |
7185 | ||
7186 | #ifdef ASM_OUTPUT_MI_THUNK | |
7187 | if (current_function_is_thunk) | |
7188 | return 0; | |
7189 | #endif | |
9e2f7ec7 DD |
7190 | if (!has_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM) |
7191 | || cfun->machine->ra_needs_full_frame) | |
71f123ca FS |
7192 | return regs_ever_live[LINK_REGISTER_REGNUM]; |
7193 | ||
7194 | push_topmost_sequence (); | |
7195 | top = get_insns (); | |
7196 | pop_topmost_sequence (); | |
7197 | ||
7198 | return reg_set_between_p (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), | |
7199 | top, NULL_RTX); | |
7200 | } | |
4697a36c | 7201 | \f |
8cd8f856 GK |
7202 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
7203 | static void | |
7204 | rs6000_maybe_dead (insn) | |
7205 | rtx insn; | |
7206 | { | |
7207 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
7208 | const0_rtx, | |
7209 | REG_NOTES (insn)); | |
7210 | } | |
7211 | ||
9ebbca7d | 7212 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 7213 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 7214 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
7215 | |
7216 | void | |
9ebbca7d GK |
7217 | rs6000_emit_load_toc_table (fromprolog) |
7218 | int fromprolog; | |
c7ca610e | 7219 | { |
9ebbca7d GK |
7220 | rtx dest; |
7221 | dest = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM); | |
c7ca610e | 7222 | |
2bfcf297 | 7223 | if (TARGET_ELF && DEFAULT_ABI != ABI_AIX) |
c7ca610e | 7224 | { |
f607bc57 | 7225 | if (DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
38c1f2d7 | 7226 | { |
9ebbca7d GK |
7227 | rtx temp = (fromprolog |
7228 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
7229 | : gen_reg_rtx (Pmode)); | |
2bfcf297 | 7230 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp))); |
8cd8f856 | 7231 | rs6000_maybe_dead (emit_move_insn (dest, temp)); |
38c1f2d7 | 7232 | } |
9ebbca7d GK |
7233 | else if (flag_pic == 2) |
7234 | { | |
7235 | char buf[30]; | |
7236 | rtx tempLR = (fromprolog | |
7237 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
7238 | : gen_reg_rtx (Pmode)); | |
7239 | rtx temp0 = (fromprolog | |
7240 | ? gen_rtx_REG (Pmode, 0) | |
7241 | : gen_reg_rtx (Pmode)); | |
7242 | rtx symF; | |
7243 | ||
7244 | /* possibly create the toc section */ | |
7245 | if (! toc_initialized) | |
7246 | { | |
7247 | toc_section (); | |
7248 | function_section (current_function_decl); | |
7249 | } | |
7250 | ||
7251 | if (fromprolog) | |
7252 | { | |
7253 | rtx symL; | |
7254 | ||
7255 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
a8a05998 | 7256 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); |
38c1f2d7 | 7257 | |
9ebbca7d | 7258 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
a8a05998 | 7259 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); |
38c1f2d7 | 7260 | |
8cd8f856 GK |
7261 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, |
7262 | symF))); | |
7263 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
7264 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
7265 | symL, | |
7266 | symF))); | |
9ebbca7d GK |
7267 | } |
7268 | else | |
7269 | { | |
7270 | rtx tocsym; | |
7271 | static int reload_toc_labelno = 0; | |
7272 | ||
b999aaeb | 7273 | tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); |
38c1f2d7 | 7274 | |
9ebbca7d | 7275 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); |
a8a05998 | 7276 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); |
9ebbca7d | 7277 | |
8cd8f856 GK |
7278 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR, |
7279 | symF, | |
7280 | tocsym))); | |
7281 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
7282 | rs6000_maybe_dead (emit_move_insn (temp0, | |
7283 | gen_rtx_MEM (Pmode, dest))); | |
9ebbca7d | 7284 | } |
8cd8f856 | 7285 | rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest))); |
9ebbca7d GK |
7286 | } |
7287 | else if (flag_pic == 0 && TARGET_MINIMAL_TOC) | |
7288 | { | |
7289 | /* This is for AIX code running in non-PIC ELF. */ | |
7290 | char buf[30]; | |
7291 | rtx realsym; | |
38c1f2d7 | 7292 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); |
a8a05998 | 7293 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); |
9ebbca7d | 7294 | |
8cd8f856 GK |
7295 | rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym))); |
7296 | rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym))); | |
9ebbca7d GK |
7297 | } |
7298 | else | |
a4f6c312 | 7299 | abort (); |
9ebbca7d GK |
7300 | } |
7301 | else | |
7302 | { | |
7303 | if (TARGET_32BIT) | |
8cd8f856 | 7304 | rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest))); |
9ebbca7d | 7305 | else |
8cd8f856 | 7306 | rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest))); |
9ebbca7d GK |
7307 | } |
7308 | } | |
7309 | ||
7310 | int | |
7311 | get_TOC_alias_set () | |
7312 | { | |
7313 | static int set = -1; | |
7314 | if (set == -1) | |
7315 | set = new_alias_set (); | |
7316 | return set; | |
7317 | } | |
7318 | ||
7319 | /* This retuns nonzero if the current function uses the TOC. This is | |
7320 | determined by the presence of (unspec ... 7), which is generated by | |
7321 | the various load_toc_* patterns. */ | |
a4f6c312 | 7322 | |
9ebbca7d GK |
7323 | int |
7324 | uses_TOC () | |
7325 | { | |
7326 | rtx insn; | |
38c1f2d7 | 7327 | |
9ebbca7d | 7328 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
2c3c49de | 7329 | if (INSN_P (insn)) |
9ebbca7d GK |
7330 | { |
7331 | rtx pat = PATTERN (insn); | |
7332 | int i; | |
7333 | ||
8cd8f856 | 7334 | if (GET_CODE (pat) == PARALLEL) |
9ebbca7d GK |
7335 | for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++) |
7336 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC | |
7337 | && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7) | |
7338 | return 1; | |
38c1f2d7 | 7339 | } |
9ebbca7d GK |
7340 | return 0; |
7341 | } | |
38c1f2d7 | 7342 | |
9ebbca7d | 7343 | rtx |
a4f6c312 | 7344 | create_TOC_reference (symbol) |
9ebbca7d GK |
7345 | rtx symbol; |
7346 | { | |
a8a05998 ZW |
7347 | return gen_rtx_PLUS (Pmode, |
7348 | gen_rtx_REG (Pmode, TOC_REGISTER), | |
7349 | gen_rtx_CONST (Pmode, | |
7350 | gen_rtx_MINUS (Pmode, symbol, | |
b999aaeb | 7351 | gen_rtx_SYMBOL_REF (Pmode, toc_label_name)))); |
9ebbca7d | 7352 | } |
38c1f2d7 | 7353 | |
9ebbca7d GK |
7354 | #if TARGET_AIX |
7355 | /* __throw will restore its own return address to be the same as the | |
7356 | return address of the function that the throw is being made to. | |
7357 | This is unfortunate, because we want to check the original | |
7358 | return address to see if we need to restore the TOC. | |
7359 | So we have to squirrel it away here. | |
7360 | This is used only in compiling __throw and __rethrow. | |
c7ca610e | 7361 | |
9ebbca7d GK |
7362 | Most of this code should be removed by CSE. */ |
7363 | static rtx insn_after_throw; | |
c7ca610e | 7364 | |
a4f6c312 | 7365 | /* This does the saving... */ |
9ebbca7d GK |
7366 | void |
7367 | rs6000_aix_emit_builtin_unwind_init () | |
7368 | { | |
7369 | rtx mem; | |
7370 | rtx stack_top = gen_reg_rtx (Pmode); | |
7371 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
7372 | ||
7373 | insn_after_throw = gen_reg_rtx (SImode); | |
7374 | ||
7375 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
7376 | emit_move_insn (stack_top, mem); | |
7377 | ||
7378 | mem = gen_rtx_MEM (Pmode, | |
7379 | gen_rtx_PLUS (Pmode, stack_top, | |
7380 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); | |
7381 | emit_move_insn (opcode_addr, mem); | |
7382 | emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr)); | |
c7ca610e RK |
7383 | } |
7384 | ||
a4f6c312 SS |
7385 | /* Emit insns to _restore_ the TOC register, at runtime (specifically |
7386 | in _eh.o). Only used on AIX. | |
9ebbca7d GK |
7387 | |
7388 | The idea is that on AIX, function calls look like this: | |
7389 | bl somefunction-trampoline | |
7390 | lwz r2,20(sp) | |
7391 | ||
a4f6c312 | 7392 | and later, |
9ebbca7d GK |
7393 | somefunction-trampoline: |
7394 | stw r2,20(sp) | |
7395 | ... load function address in the count register ... | |
7396 | bctr | |
7397 | or like this, if the linker determines that this is not a cross-module call | |
7398 | and so the TOC need not be restored: | |
7399 | bl somefunction | |
7400 | nop | |
7401 | or like this, if the compiler could determine that this is not a | |
7402 | cross-module call: | |
7403 | bl somefunction | |
7404 | now, the tricky bit here is that register 2 is saved and restored | |
7405 | by the _linker_, so we can't readily generate debugging information | |
7406 | for it. So we need to go back up the call chain looking at the | |
7407 | insns at return addresses to see which calls saved the TOC register | |
7408 | and so see where it gets restored from. | |
7409 | ||
7410 | Oh, and all this gets done in RTL inside the eh_epilogue pattern, | |
7411 | just before the actual epilogue. | |
7412 | ||
7413 | On the bright side, this incurs no space or time overhead unless an | |
7414 | exception is thrown, except for the extra code in libgcc.a. | |
7415 | ||
7416 | The parameter STACKSIZE is a register containing (at runtime) | |
7417 | the amount to be popped off the stack in addition to the stack frame | |
7418 | of this routine (which will be __throw or __rethrow, and so is | |
7419 | guaranteed to have a stack frame). */ | |
a4f6c312 | 7420 | |
9ebbca7d GK |
7421 | void |
7422 | rs6000_emit_eh_toc_restore (stacksize) | |
7423 | rtx stacksize; | |
7424 | { | |
7425 | rtx top_of_stack; | |
7426 | rtx bottom_of_stack = gen_reg_rtx (Pmode); | |
7427 | rtx tocompare = gen_reg_rtx (SImode); | |
7428 | rtx opcode = gen_reg_rtx (SImode); | |
7429 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
7430 | rtx mem; | |
7431 | rtx loop_start = gen_label_rtx (); | |
7432 | rtx no_toc_restore_needed = gen_label_rtx (); | |
7433 | rtx loop_exit = gen_label_rtx (); | |
7434 | ||
7435 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
ba4828e0 | 7436 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
7437 | emit_move_insn (bottom_of_stack, mem); |
7438 | ||
7439 | top_of_stack = expand_binop (Pmode, add_optab, | |
7440 | bottom_of_stack, stacksize, | |
7441 | NULL_RTX, 1, OPTAB_WIDEN); | |
7442 | ||
7443 | emit_move_insn (tocompare, | |
7444 | GEN_INT (trunc_int_for_mode (TARGET_32BIT | |
7445 | ? 0x80410014 | |
7446 | : 0xE8410028, SImode))); | |
7447 | ||
7448 | if (insn_after_throw == NULL_RTX) | |
a4f6c312 | 7449 | abort (); |
9ebbca7d GK |
7450 | emit_move_insn (opcode, insn_after_throw); |
7451 | ||
6496a589 | 7452 | emit_note (NULL, NOTE_INSN_LOOP_BEG); |
9ebbca7d GK |
7453 | emit_label (loop_start); |
7454 | ||
7455 | do_compare_rtx_and_jump (opcode, tocompare, NE, 1, | |
06f4e019 | 7456 | SImode, NULL_RTX, NULL_RTX, |
9ebbca7d GK |
7457 | no_toc_restore_needed); |
7458 | ||
7459 | mem = gen_rtx_MEM (Pmode, | |
7460 | gen_rtx_PLUS (Pmode, bottom_of_stack, | |
7461 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
7462 | emit_move_insn (gen_rtx_REG (Pmode, 2), mem); | |
7463 | ||
7464 | emit_label (no_toc_restore_needed); | |
7465 | do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1, | |
06f4e019 | 7466 | Pmode, NULL_RTX, NULL_RTX, |
9ebbca7d GK |
7467 | loop_exit); |
7468 | ||
7469 | mem = gen_rtx_MEM (Pmode, bottom_of_stack); | |
ba4828e0 | 7470 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
7471 | emit_move_insn (bottom_of_stack, mem); |
7472 | ||
7473 | mem = gen_rtx_MEM (Pmode, | |
7474 | gen_rtx_PLUS (Pmode, bottom_of_stack, | |
7475 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); | |
7476 | emit_move_insn (opcode_addr, mem); | |
7477 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); | |
7478 | ||
6496a589 | 7479 | emit_note (NULL, NOTE_INSN_LOOP_CONT); |
9ebbca7d | 7480 | emit_jump (loop_start); |
6496a589 | 7481 | emit_note (NULL, NOTE_INSN_LOOP_END); |
9ebbca7d GK |
7482 | emit_label (loop_exit); |
7483 | } | |
7484 | #endif /* TARGET_AIX */ | |
38c1f2d7 | 7485 | \f |
ba4828e0 RK |
7486 | /* This ties together stack memory (MEM with an alias set of |
7487 | rs6000_sr_alias_set) and the change to the stack pointer. */ | |
7488 | ||
9ebbca7d GK |
7489 | static void |
7490 | rs6000_emit_stack_tie () | |
7491 | { | |
ba4828e0 RK |
7492 | rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); |
7493 | ||
7494 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
7495 | emit_insn (gen_stack_tie (mem)); |
7496 | } | |
38c1f2d7 | 7497 | |
9ebbca7d GK |
7498 | /* Emit the correct code for allocating stack space, as insns. |
7499 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
7500 | The generated code may use hard register 0 as a temporary. */ | |
7501 | ||
7502 | static void | |
7503 | rs6000_emit_allocate_stack (size, copy_r12) | |
7504 | HOST_WIDE_INT size; | |
38c1f2d7 MM |
7505 | int copy_r12; |
7506 | { | |
9ebbca7d GK |
7507 | rtx insn; |
7508 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
7509 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
7510 | rtx todec = GEN_INT (-size); | |
a157febd GK |
7511 | |
7512 | if (current_function_limit_stack) | |
7513 | { | |
7514 | if (REG_P (stack_limit_rtx) | |
7515 | && REGNO (stack_limit_rtx) > 1 | |
7516 | && REGNO (stack_limit_rtx) <= 31) | |
7517 | { | |
9ebbca7d GK |
7518 | emit_insn (Pmode == SImode |
7519 | ? gen_addsi3 (tmp_reg, | |
7520 | stack_limit_rtx, | |
7521 | GEN_INT (size)) | |
7522 | : gen_adddi3 (tmp_reg, | |
7523 | stack_limit_rtx, | |
7524 | GEN_INT (size))); | |
7525 | ||
7526 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
7527 | const0_rtx)); | |
a157febd GK |
7528 | } |
7529 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 7530 | && TARGET_32BIT |
f607bc57 | 7531 | && DEFAULT_ABI == ABI_V4) |
a157febd | 7532 | { |
9ebbca7d GK |
7533 | rtx toload = gen_rtx_CONST (VOIDmode, |
7534 | gen_rtx_PLUS (Pmode, | |
7535 | stack_limit_rtx, | |
7536 | GEN_INT (size))); | |
7537 | ||
7538 | emit_insn (gen_elf_high (tmp_reg, toload)); | |
7539 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
7540 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
7541 | const0_rtx)); | |
a157febd GK |
7542 | } |
7543 | else | |
7544 | warning ("stack limit expression is not supported"); | |
7545 | } | |
7546 | ||
9ebbca7d GK |
7547 | if (copy_r12 || ! TARGET_UPDATE) |
7548 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
7549 | ||
38c1f2d7 MM |
7550 | if (TARGET_UPDATE) |
7551 | { | |
9ebbca7d | 7552 | if (size > 32767) |
38c1f2d7 | 7553 | { |
9ebbca7d GK |
7554 | /* Need a note here so that try_split doesn't get confused. */ |
7555 | if (get_last_insn() == NULL_RTX) | |
7556 | emit_note (0, NOTE_INSN_DELETED); | |
7557 | insn = emit_move_insn (tmp_reg, todec); | |
7558 | try_split (PATTERN (insn), insn, 0); | |
7559 | todec = tmp_reg; | |
38c1f2d7 | 7560 | } |
9ebbca7d GK |
7561 | |
7562 | if (Pmode == SImode) | |
7563 | insn = emit_insn (gen_movsi_update (stack_reg, stack_reg, | |
7564 | todec, stack_reg)); | |
7565 | else | |
7566 | insn = emit_insn (gen_movdi_update (stack_reg, stack_reg, | |
7567 | todec, stack_reg)); | |
38c1f2d7 MM |
7568 | } |
7569 | else | |
7570 | { | |
9ebbca7d GK |
7571 | if (Pmode == SImode) |
7572 | insn = emit_insn (gen_addsi3 (stack_reg, stack_reg, todec)); | |
38c1f2d7 | 7573 | else |
9ebbca7d GK |
7574 | insn = emit_insn (gen_adddi3 (stack_reg, stack_reg, todec)); |
7575 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), | |
7576 | gen_rtx_REG (Pmode, 12)); | |
7577 | } | |
7578 | ||
7579 | RTX_FRAME_RELATED_P (insn) = 1; | |
7580 | REG_NOTES (insn) = | |
7581 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
7582 | gen_rtx_SET (VOIDmode, stack_reg, | |
7583 | gen_rtx_PLUS (Pmode, stack_reg, | |
7584 | GEN_INT (-size))), | |
7585 | REG_NOTES (insn)); | |
7586 | } | |
7587 | ||
a4f6c312 SS |
7588 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced |
7589 | with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 | |
7590 | is not NULL. It would be nice if dwarf2out_frame_debug_expr could | |
7591 | deduce these equivalences by itself so it wasn't necessary to hold | |
7592 | its hand so much. */ | |
9ebbca7d GK |
7593 | |
7594 | static void | |
7595 | rs6000_frame_related (insn, reg, val, reg2, rreg) | |
7596 | rtx insn; | |
7597 | rtx reg; | |
7598 | HOST_WIDE_INT val; | |
7599 | rtx reg2; | |
7600 | rtx rreg; | |
7601 | { | |
7602 | rtx real, temp; | |
7603 | ||
7604 | real = copy_rtx (PATTERN (insn)); | |
7605 | ||
7606 | real = replace_rtx (real, reg, | |
7607 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, | |
7608 | STACK_POINTER_REGNUM), | |
7609 | GEN_INT (val))); | |
7610 | ||
7611 | /* We expect that 'real' is either a SET or a PARALLEL containing | |
7612 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
7613 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
7614 | ||
7615 | if (GET_CODE (real) == SET) | |
7616 | { | |
7617 | rtx set = real; | |
7618 | ||
7619 | temp = simplify_rtx (SET_SRC (set)); | |
7620 | if (temp) | |
7621 | SET_SRC (set) = temp; | |
7622 | temp = simplify_rtx (SET_DEST (set)); | |
7623 | if (temp) | |
7624 | SET_DEST (set) = temp; | |
7625 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 7626 | { |
9ebbca7d GK |
7627 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
7628 | if (temp) | |
7629 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 7630 | } |
38c1f2d7 | 7631 | } |
9ebbca7d GK |
7632 | else if (GET_CODE (real) == PARALLEL) |
7633 | { | |
7634 | int i; | |
7635 | for (i = 0; i < XVECLEN (real, 0); i++) | |
7636 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
7637 | { | |
7638 | rtx set = XVECEXP (real, 0, i); | |
7639 | ||
7640 | temp = simplify_rtx (SET_SRC (set)); | |
7641 | if (temp) | |
7642 | SET_SRC (set) = temp; | |
7643 | temp = simplify_rtx (SET_DEST (set)); | |
7644 | if (temp) | |
7645 | SET_DEST (set) = temp; | |
7646 | if (GET_CODE (SET_DEST (set)) == MEM) | |
7647 | { | |
7648 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
7649 | if (temp) | |
7650 | XEXP (SET_DEST (set), 0) = temp; | |
7651 | } | |
7652 | RTX_FRAME_RELATED_P (set) = 1; | |
7653 | } | |
7654 | } | |
7655 | else | |
a4f6c312 | 7656 | abort (); |
9ebbca7d GK |
7657 | |
7658 | if (reg2 != NULL_RTX) | |
7659 | real = replace_rtx (real, reg2, rreg); | |
7660 | ||
7661 | RTX_FRAME_RELATED_P (insn) = 1; | |
7662 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
7663 | real, | |
7664 | REG_NOTES (insn)); | |
38c1f2d7 MM |
7665 | } |
7666 | ||
00b960c7 AH |
7667 | /* Returns an insn that has a vrsave set operation with the |
7668 | appropriate CLOBBERs. */ | |
7669 | ||
7670 | static rtx | |
7671 | generate_set_vrsave (reg, info) | |
7672 | rtx reg; | |
7673 | rs6000_stack_t *info; | |
7674 | { | |
7675 | int nclobs, i; | |
7676 | rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1]; | |
7677 | ||
7678 | clobs[0] = gen_set_vrsave (reg); | |
7679 | ||
7680 | nclobs = 1; | |
7681 | ||
7682 | /* CLOBBER the registers in the mask. */ | |
7683 | ||
7684 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
7685 | if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0) | |
7686 | clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode, | |
7687 | gen_rtx_REG (V4SImode, i)); | |
7688 | ||
7689 | insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs)); | |
7690 | ||
7691 | for (i = 0; i < nclobs; ++i) | |
7692 | XVECEXP (insn, 0, i) = clobs[i]; | |
7693 | ||
7694 | return insn; | |
7695 | } | |
7696 | ||
9ebbca7d GK |
7697 | /* Emit function prologue as insns. */ |
7698 | ||
9878760c | 7699 | void |
83720594 | 7700 | rs6000_emit_prologue () |
9878760c | 7701 | { |
4697a36c | 7702 | rs6000_stack_t *info = rs6000_stack_info (); |
9ebbca7d GK |
7703 | enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode; |
7704 | int reg_size = TARGET_POWERPC64 ? 8 : 4; | |
7705 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
7706 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
7707 | rtx frame_reg_rtx = sp_reg_rtx; | |
7708 | rtx cr_save_rtx = NULL; | |
7709 | rtx insn; | |
7710 | int saving_FPRs_inline; | |
7711 | int using_store_multiple; | |
7712 | HOST_WIDE_INT sp_offset = 0; | |
7713 | ||
7714 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 | |
7715 | && info->first_gp_reg_save < 31); | |
7716 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
7717 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
7718 | ||
7719 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
f607bc57 | 7720 | if (info->push_p && DEFAULT_ABI == ABI_V4) |
9ebbca7d GK |
7721 | { |
7722 | if (info->total_size < 32767) | |
7723 | sp_offset = info->total_size; | |
7724 | else | |
7725 | frame_reg_rtx = frame_ptr_rtx; | |
7726 | rs6000_emit_allocate_stack (info->total_size, | |
7727 | (frame_reg_rtx != sp_reg_rtx | |
7728 | && (info->cr_save_p | |
7729 | || info->lr_save_p | |
7730 | || info->first_fp_reg_save < 64 | |
7731 | || info->first_gp_reg_save < 32 | |
7732 | ))); | |
7733 | if (frame_reg_rtx != sp_reg_rtx) | |
7734 | rs6000_emit_stack_tie (); | |
7735 | } | |
7736 | ||
7737 | /* If we use the link register, get it into r0. */ | |
7738 | if (info->lr_save_p) | |
71f123ca | 7739 | emit_move_insn (gen_rtx_REG (Pmode, 0), |
9ebbca7d GK |
7740 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); |
7741 | ||
7742 | /* If we need to save CR, put it into r12. */ | |
7743 | if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) | |
7744 | { | |
7745 | cr_save_rtx = gen_rtx_REG (SImode, 12); | |
7746 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
7747 | } | |
7748 | ||
a4f6c312 SS |
7749 | /* Do any required saving of fpr's. If only one or two to save, do |
7750 | it ourselves. Otherwise, call function. */ | |
9ebbca7d GK |
7751 | if (saving_FPRs_inline) |
7752 | { | |
7753 | int i; | |
7754 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
7755 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
7756 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
7757 | { | |
7758 | rtx addr, reg, mem; | |
7759 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
7760 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7761 | GEN_INT (info->fp_save_offset | |
7762 | + sp_offset | |
a4f6c312 | 7763 | + 8 * i)); |
9ebbca7d | 7764 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 7765 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
7766 | |
7767 | insn = emit_move_insn (mem, reg); | |
7768 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7769 | NULL_RTX, NULL_RTX); | |
7770 | } | |
7771 | } | |
7772 | else if (info->first_fp_reg_save != 64) | |
7773 | { | |
7774 | int i; | |
7775 | char rname[30]; | |
520a57c8 | 7776 | const char *alloc_rname; |
9ebbca7d GK |
7777 | rtvec p; |
7778 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
7779 | ||
7780 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
7781 | gen_rtx_REG (Pmode, | |
7782 | LINK_REGISTER_REGNUM)); | |
7783 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
7784 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
a8a05998 | 7785 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
7786 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
7787 | gen_rtx_SYMBOL_REF (Pmode, | |
7788 | alloc_rname)); | |
7789 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
7790 | { | |
7791 | rtx addr, reg, mem; | |
7792 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
7793 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7794 | GEN_INT (info->fp_save_offset | |
7795 | + sp_offset + 8*i)); | |
7796 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 7797 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
7798 | |
7799 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
7800 | } | |
7801 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
7802 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7803 | NULL_RTX, NULL_RTX); | |
7804 | } | |
b6c9286a | 7805 | |
9ebbca7d GK |
7806 | /* Save GPRs. This is done as a PARALLEL if we are using |
7807 | the store-multiple instructions. */ | |
7808 | if (using_store_multiple) | |
b6c9286a | 7809 | { |
9ebbca7d GK |
7810 | rtvec p, dwarfp; |
7811 | int i; | |
7812 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
7813 | dwarfp = rtvec_alloc (32 - info->first_gp_reg_save); | |
7814 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
7815 | { | |
7816 | rtx addr, reg, mem; | |
7817 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
7818 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7819 | GEN_INT (info->gp_save_offset | |
7820 | + sp_offset | |
7821 | + reg_size * i)); | |
7822 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 7823 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
7824 | |
7825 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
7826 | } | |
7827 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
7828 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7829 | NULL_RTX, NULL_RTX); | |
b6c9286a MM |
7830 | } |
7831 | else | |
7832 | { | |
9ebbca7d GK |
7833 | int i; |
7834 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
7835 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
7836 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
7837 | || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM | |
f607bc57 ZW |
7838 | && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
7839 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) | |
9ebbca7d GK |
7840 | { |
7841 | rtx addr, reg, mem; | |
7842 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
7843 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7844 | GEN_INT (info->gp_save_offset | |
7845 | + sp_offset | |
7846 | + reg_size * i)); | |
7847 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 7848 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
7849 | |
7850 | insn = emit_move_insn (mem, reg); | |
7851 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7852 | NULL_RTX, NULL_RTX); | |
7853 | } | |
7854 | } | |
7855 | ||
83720594 RH |
7856 | /* ??? There's no need to emit actual instructions here, but it's the |
7857 | easiest way to get the frame unwind information emitted. */ | |
7858 | if (current_function_calls_eh_return) | |
7859 | { | |
78e1b90d DE |
7860 | unsigned int i, regno; |
7861 | ||
83720594 RH |
7862 | for (i = 0; ; ++i) |
7863 | { | |
7864 | rtx addr, reg, mem; | |
7865 | ||
7866 | regno = EH_RETURN_DATA_REGNO (i); | |
7867 | if (regno == INVALID_REGNUM) | |
7868 | break; | |
7869 | ||
7870 | reg = gen_rtx_REG (reg_mode, regno); | |
7871 | addr = plus_constant (frame_reg_rtx, | |
78e1b90d DE |
7872 | info->ehrd_offset + sp_offset |
7873 | + reg_size * (int) i); | |
83720594 | 7874 | mem = gen_rtx_MEM (reg_mode, addr); |
ba4828e0 | 7875 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
7876 | |
7877 | insn = emit_move_insn (mem, reg); | |
7878 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7879 | NULL_RTX, NULL_RTX); | |
7880 | } | |
7881 | } | |
7882 | ||
9ebbca7d GK |
7883 | /* Save lr if we used it. */ |
7884 | if (info->lr_save_p) | |
7885 | { | |
7886 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7887 | GEN_INT (info->lr_save_offset + sp_offset)); | |
7888 | rtx reg = gen_rtx_REG (Pmode, 0); | |
7889 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
7890 | /* This should not be of rs6000_sr_alias_set, because of | |
7891 | __builtin_return_address. */ | |
7892 | ||
7893 | insn = emit_move_insn (mem, reg); | |
7894 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7895 | reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
7896 | } | |
7897 | ||
7898 | /* Save CR if we use any that must be preserved. */ | |
7899 | if (info->cr_save_p) | |
7900 | { | |
7901 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7902 | GEN_INT (info->cr_save_offset + sp_offset)); | |
7903 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
7904 | |
7905 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
7906 | |
7907 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
7908 | that it's free. */ | |
7909 | if (REGNO (frame_reg_rtx) == 12) | |
7910 | { | |
7911 | cr_save_rtx = gen_rtx_REG (SImode, 0); | |
7912 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
7913 | } | |
7914 | insn = emit_move_insn (mem, cr_save_rtx); | |
7915 | ||
7916 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
7917 | to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's | |
7918 | OK. All we have to do is specify that _one_ condition code | |
7919 | register is saved in this stack slot. The thrower's epilogue | |
a1dc9455 FS |
7920 | will then restore all the call-saved registers. |
7921 | We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */ | |
9ebbca7d | 7922 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
a1dc9455 | 7923 | cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO)); |
9ebbca7d GK |
7924 | } |
7925 | ||
7926 | /* Update stack and set back pointer unless this is V.4, | |
7927 | for which it was done previously. */ | |
f607bc57 | 7928 | if (info->push_p && DEFAULT_ABI != ABI_V4) |
9ebbca7d GK |
7929 | rs6000_emit_allocate_stack (info->total_size, FALSE); |
7930 | ||
00b960c7 AH |
7931 | /* Save AltiVec registers if needed. */ |
7932 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
7933 | { | |
7934 | int i; | |
7935 | ||
7936 | /* There should be a non inline version of this, for when we | |
7937 | are saving lots of vector registers. */ | |
7938 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
7939 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
7940 | { | |
7941 | rtx addr, areg, savereg, mem; | |
7942 | ||
7943 | savereg = gen_rtx_REG (V4SImode, i); | |
7944 | ||
7945 | areg = gen_rtx_REG (Pmode, 0); | |
7946 | emit_move_insn | |
7947 | (areg, GEN_INT (info->altivec_save_offset | |
7948 | + sp_offset | |
7949 | + 16 * (i - info->first_altivec_reg_save))); | |
7950 | ||
7951 | /* AltiVec addressing mode is [reg+reg]. */ | |
7952 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
7953 | mem = gen_rtx_MEM (V4SImode, addr); | |
7954 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
7955 | ||
7956 | insn = emit_move_insn (mem, savereg); | |
7957 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7958 | NULL_RTX, NULL_RTX); | |
7959 | } | |
7960 | } | |
7961 | ||
7962 | /* VRSAVE is a bit vector representing which AltiVec registers | |
7963 | are used. The OS uses this to determine which vector | |
7964 | registers to save on a context switch. We need to save | |
7965 | VRSAVE on the stack frame, add whatever AltiVec registers we | |
7966 | used in this function, and do the corresponding magic in the | |
7967 | epilogue. */ | |
7968 | ||
7969 | if (TARGET_ALTIVEC && info->vrsave_mask != 0) | |
7970 | { | |
7971 | rtx reg, addr, mem; | |
7972 | ||
7973 | /* Get VRSAVE onto a GPR. */ | |
7974 | reg = gen_rtx_REG (SImode, 12); | |
7975 | emit_insn (gen_get_vrsave (reg)); | |
7976 | ||
7977 | /* Save VRSAVE. */ | |
7978 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
7979 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
7980 | mem = gen_rtx_MEM (SImode, addr); | |
7981 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
7982 | insn = emit_move_insn (mem, reg); | |
7983 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7984 | NULL_RTX, NULL_RTX); | |
7985 | ||
7986 | /* Include the registers in the mask. */ | |
7987 | emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask))); | |
7988 | ||
7989 | insn = emit_insn (generate_set_vrsave (reg, info)); | |
7990 | ||
7991 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
7992 | NULL_RTX, NULL_RTX); | |
7993 | } | |
7994 | ||
9ebbca7d GK |
7995 | /* Set frame pointer, if needed. */ |
7996 | if (frame_pointer_needed) | |
7997 | { | |
7998 | insn = emit_move_insn (gen_rtx_REG (reg_mode, FRAME_POINTER_REGNUM), | |
7999 | sp_reg_rtx); | |
8000 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 8001 | } |
9878760c | 8002 | |
9ebbca7d GK |
8003 | /* If we are using PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
8004 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) | |
f607bc57 ZW |
8005 | || (DEFAULT_ABI == ABI_V4 && flag_pic == 1 |
8006 | && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])) | |
9ebbca7d GK |
8007 | { |
8008 | /* If emit_load_toc_table will use the link register, we need to save | |
8009 | it. We use R11 for this purpose because emit_load_toc_table | |
8010 | can use register 0. This allows us to use a plain 'blr' to return | |
8011 | from the procedure more often. */ | |
d5fa86ba GK |
8012 | int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0 |
8013 | && ! info->lr_save_p | |
8014 | && EXIT_BLOCK_PTR->pred != NULL); | |
9ebbca7d GK |
8015 | if (save_LR_around_toc_setup) |
8016 | emit_move_insn (gen_rtx_REG (Pmode, 11), | |
8017 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
8018 | ||
8019 | rs6000_emit_load_toc_table (TRUE); | |
8020 | ||
8021 | if (save_LR_around_toc_setup) | |
8022 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), | |
8023 | gen_rtx_REG (Pmode, 11)); | |
8024 | } | |
ee890fe2 SS |
8025 | |
8026 | if (DEFAULT_ABI == ABI_DARWIN | |
8027 | && flag_pic && current_function_uses_pic_offset_table) | |
8028 | { | |
8029 | rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
8030 | ||
8031 | rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest))); | |
8032 | ||
8033 | rs6000_maybe_dead ( | |
8034 | emit_move_insn (gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM), | |
8035 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM))); | |
8036 | } | |
9ebbca7d GK |
8037 | } |
8038 | ||
9ebbca7d | 8039 | /* Write function prologue. */ |
a4f6c312 | 8040 | |
08c148a8 NB |
8041 | static void |
8042 | rs6000_output_function_prologue (file, size) | |
9ebbca7d | 8043 | FILE *file; |
08c148a8 | 8044 | HOST_WIDE_INT size ATTRIBUTE_UNUSED; |
9ebbca7d GK |
8045 | { |
8046 | rs6000_stack_t *info = rs6000_stack_info (); | |
8047 | ||
4697a36c MM |
8048 | if (TARGET_DEBUG_STACK) |
8049 | debug_stack_info (info); | |
9878760c | 8050 | |
a4f6c312 SS |
8051 | /* Write .extern for any function we will call to save and restore |
8052 | fp values. */ | |
8053 | if (info->first_fp_reg_save < 64 | |
8054 | && !FP_SAVE_INLINE (info->first_fp_reg_save)) | |
4d30c363 | 8055 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c | 8056 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
a4f6c312 SS |
8057 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, |
8058 | RESTORE_FP_SUFFIX); | |
9878760c | 8059 | |
c764f757 RK |
8060 | /* Write .extern for AIX common mode routines, if needed. */ |
8061 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
8062 | { | |
f6709c70 JW |
8063 | fputs ("\t.extern __mulh\n", file); |
8064 | fputs ("\t.extern __mull\n", file); | |
8065 | fputs ("\t.extern __divss\n", file); | |
8066 | fputs ("\t.extern __divus\n", file); | |
8067 | fputs ("\t.extern __quoss\n", file); | |
8068 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
8069 | common_mode_defined = 1; |
8070 | } | |
9878760c | 8071 | |
9ebbca7d | 8072 | if (! HAVE_prologue) |
979721f8 | 8073 | { |
9ebbca7d GK |
8074 | start_sequence (); |
8075 | ||
a4f6c312 SS |
8076 | /* A NOTE_INSN_DELETED is supposed to be at the start and end of |
8077 | the "toplevel" insn chain. */ | |
9ebbca7d GK |
8078 | emit_note (0, NOTE_INSN_DELETED); |
8079 | rs6000_emit_prologue (); | |
8080 | emit_note (0, NOTE_INSN_DELETED); | |
8081 | ||
8082 | if (TARGET_DEBUG_STACK) | |
a4f6c312 SS |
8083 | debug_rtx_list (get_insns (), 100); |
8084 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 8085 | end_sequence (); |
979721f8 MM |
8086 | } |
8087 | ||
9ebbca7d GK |
8088 | rs6000_pic_labelno++; |
8089 | } | |
8090 | ||
8091 | /* Emit function epilogue as insns. | |
9878760c | 8092 | |
9ebbca7d GK |
8093 | At present, dwarf2out_frame_debug_expr doesn't understand |
8094 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
8095 | anywhere in the epilogue. Most of the insns below would in any case | |
8096 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 8097 | |
9ebbca7d | 8098 | void |
83720594 | 8099 | rs6000_emit_epilogue (sibcall) |
9ebbca7d GK |
8100 | int sibcall; |
8101 | { | |
8102 | rs6000_stack_t *info; | |
8103 | int restoring_FPRs_inline; | |
8104 | int using_load_multiple; | |
8105 | int using_mfcr_multiple; | |
8106 | int use_backchain_to_restore_sp; | |
8107 | int sp_offset = 0; | |
8108 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
8109 | rtx frame_reg_rtx = sp_reg_rtx; | |
8110 | enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode; | |
8111 | int reg_size = TARGET_POWERPC64 ? 8 : 4; | |
8112 | int i; | |
8113 | ||
8114 | info = rs6000_stack_info (); | |
8115 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 | |
8116 | && info->first_gp_reg_save < 31); | |
8117 | restoring_FPRs_inline = (sibcall | |
83720594 | 8118 | || current_function_calls_eh_return |
9ebbca7d GK |
8119 | || info->first_fp_reg_save == 64 |
8120 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
8121 | use_backchain_to_restore_sp = (frame_pointer_needed | |
8122 | || current_function_calls_alloca | |
8123 | || info->total_size > 32767); | |
8124 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
8125 | || rs6000_cpu == PROCESSOR_PPC603 | |
8126 | || rs6000_cpu == PROCESSOR_PPC750 | |
8127 | || optimize_size); | |
8128 | ||
8129 | /* If we have a frame pointer, a call to alloca, or a large stack | |
8130 | frame, restore the old stack pointer using the backchain. Otherwise, | |
8131 | we know what size to update it with. */ | |
8132 | if (use_backchain_to_restore_sp) | |
bacbde18 | 8133 | { |
9ebbca7d GK |
8134 | /* Under V.4, don't reset the stack pointer until after we're done |
8135 | loading the saved registers. */ | |
f607bc57 | 8136 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d | 8137 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); |
4697a36c | 8138 | |
9ebbca7d GK |
8139 | emit_move_insn (frame_reg_rtx, |
8140 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
8141 | ||
bacbde18 | 8142 | } |
9ebbca7d | 8143 | else if (info->push_p) |
85638c0d | 8144 | { |
f607bc57 | 8145 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d GK |
8146 | sp_offset = info->total_size; |
8147 | else | |
8148 | { | |
8149 | emit_insn (TARGET_32BIT | |
8150 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
8151 | GEN_INT (info->total_size)) | |
8152 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
8153 | GEN_INT (info->total_size))); | |
8154 | } | |
85638c0d | 8155 | } |
9ebbca7d GK |
8156 | |
8157 | /* Get the old lr if we saved it. */ | |
8158 | if (info->lr_save_p) | |
b6c9286a | 8159 | { |
9ebbca7d GK |
8160 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
8161 | GEN_INT (info->lr_save_offset + sp_offset)); | |
8162 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
ba4828e0 RK |
8163 | |
8164 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 8165 | |
9ebbca7d | 8166 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 8167 | } |
9ebbca7d GK |
8168 | |
8169 | /* Get the old cr if we saved it. */ | |
8170 | if (info->cr_save_p) | |
8171 | { | |
8172 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
8173 | GEN_INT (info->cr_save_offset + sp_offset)); | |
8174 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
8175 | |
8176 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 8177 | |
9ebbca7d GK |
8178 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
8179 | } | |
8180 | ||
8181 | /* Set LR here to try to overlap restores below. */ | |
4697a36c | 8182 | if (info->lr_save_p) |
9ebbca7d GK |
8183 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
8184 | gen_rtx_REG (Pmode, 0)); | |
8185 | ||
83720594 RH |
8186 | /* Load exception handler data registers, if needed. */ |
8187 | if (current_function_calls_eh_return) | |
8188 | { | |
78e1b90d DE |
8189 | unsigned int i, regno; |
8190 | ||
83720594 RH |
8191 | for (i = 0; ; ++i) |
8192 | { | |
8193 | rtx addr, mem; | |
8194 | ||
8195 | regno = EH_RETURN_DATA_REGNO (i); | |
8196 | if (regno == INVALID_REGNUM) | |
8197 | break; | |
8198 | ||
8199 | addr = plus_constant (frame_reg_rtx, | |
78e1b90d DE |
8200 | info->ehrd_offset + sp_offset |
8201 | + reg_size * (int) i); | |
83720594 | 8202 | mem = gen_rtx_MEM (reg_mode, addr); |
ba4828e0 | 8203 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
8204 | |
8205 | emit_move_insn (gen_rtx_REG (reg_mode, regno), mem); | |
8206 | } | |
8207 | } | |
9ebbca7d GK |
8208 | |
8209 | /* Restore GPRs. This is done as a PARALLEL if we are using | |
8210 | the load-multiple instructions. */ | |
8211 | if (using_load_multiple) | |
979721f8 | 8212 | { |
9ebbca7d GK |
8213 | rtvec p; |
8214 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
8215 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 8216 | { |
9ebbca7d GK |
8217 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
8218 | GEN_INT (info->gp_save_offset | |
8219 | + sp_offset | |
8220 | + reg_size * i)); | |
8221 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
8222 | |
8223 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
8224 | |
8225 | RTVEC_ELT (p, i) = | |
8226 | gen_rtx_SET (VOIDmode, | |
8227 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
8228 | mem); | |
979721f8 | 8229 | } |
9ebbca7d | 8230 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 8231 | } |
9ebbca7d GK |
8232 | else |
8233 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
8234 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
8235 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
8236 | || (i+info->first_gp_reg_save == PIC_OFFSET_TABLE_REGNUM | |
f607bc57 ZW |
8237 | && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
8238 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) | |
9ebbca7d GK |
8239 | { |
8240 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
8241 | GEN_INT (info->gp_save_offset | |
8242 | + sp_offset | |
8243 | + reg_size * i)); | |
8244 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
8245 | |
8246 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
8247 | |
8248 | emit_move_insn (gen_rtx_REG (reg_mode, | |
8249 | info->first_gp_reg_save + i), | |
8250 | mem); | |
8251 | } | |
9878760c | 8252 | |
9ebbca7d GK |
8253 | /* Restore fpr's if we need to do it without calling a function. */ |
8254 | if (restoring_FPRs_inline) | |
8255 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
8256 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
8257 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
8258 | { | |
8259 | rtx addr, mem; | |
8260 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
8261 | GEN_INT (info->fp_save_offset | |
8262 | + sp_offset | |
a4f6c312 | 8263 | + 8 * i)); |
9ebbca7d | 8264 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 8265 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
8266 | |
8267 | emit_move_insn (gen_rtx_REG (DFmode, | |
8268 | info->first_fp_reg_save + i), | |
8269 | mem); | |
8270 | } | |
8d30c4ee | 8271 | |
00b960c7 AH |
8272 | /* Restore AltiVec registers if needed. */ |
8273 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
8274 | { | |
8275 | int i; | |
8276 | ||
8277 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
8278 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
8279 | { | |
8280 | rtx addr, areg, mem; | |
8281 | ||
8282 | areg = gen_rtx_REG (Pmode, 0); | |
8283 | emit_move_insn | |
8284 | (areg, GEN_INT (info->altivec_save_offset | |
8285 | + sp_offset | |
8286 | + 16 * (i - info->first_altivec_reg_save))); | |
8287 | ||
8288 | /* AltiVec addressing mode is [reg+reg]. */ | |
8289 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
8290 | mem = gen_rtx_MEM (V4SImode, addr); | |
8291 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
8292 | ||
8293 | emit_move_insn (gen_rtx_REG (V4SImode, i), mem); | |
8294 | } | |
8295 | } | |
8296 | ||
8297 | /* Restore VRSAVE if needed. */ | |
8298 | if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0) | |
8299 | { | |
8300 | rtx addr, mem, reg; | |
8301 | ||
8302 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
8303 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
8304 | mem = gen_rtx_MEM (SImode, addr); | |
8305 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
8306 | reg = gen_rtx_REG (SImode, 12); | |
8307 | emit_move_insn (reg, mem); | |
8308 | ||
8309 | emit_insn (generate_set_vrsave (reg, info)); | |
8310 | } | |
8311 | ||
9ebbca7d GK |
8312 | /* If we saved cr, restore it here. Just those that were used. */ |
8313 | if (info->cr_save_p) | |
979721f8 | 8314 | { |
9ebbca7d | 8315 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 8316 | int count = 0; |
9ebbca7d GK |
8317 | |
8318 | if (using_mfcr_multiple) | |
979721f8 | 8319 | { |
9ebbca7d GK |
8320 | for (i = 0; i < 8; i++) |
8321 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 8322 | count++; |
9ebbca7d | 8323 | if (count == 0) |
e35b9579 GK |
8324 | abort (); |
8325 | } | |
8326 | ||
8327 | if (using_mfcr_multiple && count > 1) | |
8328 | { | |
8329 | rtvec p; | |
8330 | int ndx; | |
9ebbca7d | 8331 | |
e35b9579 | 8332 | p = rtvec_alloc (count); |
9ebbca7d | 8333 | |
e35b9579 | 8334 | ndx = 0; |
9ebbca7d GK |
8335 | for (i = 0; i < 8; i++) |
8336 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
8337 | { | |
8338 | rtvec r = rtvec_alloc (2); | |
8339 | RTVEC_ELT (r, 0) = r12_rtx; | |
8340 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 8341 | RTVEC_ELT (p, ndx) = |
9ebbca7d GK |
8342 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
8343 | gen_rtx_UNSPEC (CCmode, r, 20)); | |
e35b9579 | 8344 | ndx++; |
9ebbca7d GK |
8345 | } |
8346 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
8347 | if (ndx != count) |
8348 | abort (); | |
979721f8 MM |
8349 | } |
8350 | else | |
9ebbca7d GK |
8351 | for (i = 0; i < 8; i++) |
8352 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 8353 | { |
9ebbca7d GK |
8354 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
8355 | CR0_REGNO+i), | |
8356 | r12_rtx)); | |
979721f8 | 8357 | } |
979721f8 MM |
8358 | } |
8359 | ||
9ebbca7d GK |
8360 | /* If this is V.4, unwind the stack pointer after all of the loads |
8361 | have been done. We need to emit a block here so that sched | |
8362 | doesn't decide to move the sp change before the register restores | |
8363 | (which may not have any obvious dependency on the stack). This | |
8364 | doesn't hurt performance, because there is no scheduling that can | |
8365 | be done after this point. */ | |
f607bc57 | 8366 | if (DEFAULT_ABI == ABI_V4) |
b6c9286a | 8367 | { |
9ebbca7d GK |
8368 | if (frame_reg_rtx != sp_reg_rtx) |
8369 | rs6000_emit_stack_tie (); | |
b6c9286a | 8370 | |
9ebbca7d | 8371 | if (use_backchain_to_restore_sp) |
b6c9286a | 8372 | { |
9ebbca7d | 8373 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 8374 | } |
9ebbca7d | 8375 | else if (sp_offset != 0) |
13f1623b | 8376 | { |
9ebbca7d GK |
8377 | emit_insn (Pmode == SImode |
8378 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
8379 | GEN_INT (sp_offset)) | |
8380 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
8381 | GEN_INT (sp_offset))); | |
13f1623b | 8382 | } |
9ebbca7d | 8383 | } |
b6c9286a | 8384 | |
83720594 RH |
8385 | if (current_function_calls_eh_return) |
8386 | { | |
8387 | rtx sa = EH_RETURN_STACKADJ_RTX; | |
8388 | emit_insn (Pmode == SImode | |
8389 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa) | |
8390 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa)); | |
8391 | } | |
8392 | ||
9ebbca7d GK |
8393 | if (!sibcall) |
8394 | { | |
8395 | rtvec p; | |
8396 | if (! restoring_FPRs_inline) | |
8397 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
8398 | else | |
8399 | p = rtvec_alloc (2); | |
b6c9286a | 8400 | |
e35b9579 GK |
8401 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
8402 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
9ebbca7d GK |
8403 | gen_rtx_REG (Pmode, |
8404 | LINK_REGISTER_REGNUM)); | |
9ebbca7d GK |
8405 | |
8406 | /* If we have to restore more than two FP registers, branch to the | |
8407 | restore function. It will return to our caller. */ | |
8408 | if (! restoring_FPRs_inline) | |
8409 | { | |
8410 | int i; | |
8411 | char rname[30]; | |
520a57c8 | 8412 | const char *alloc_rname; |
979721f8 | 8413 | |
9ebbca7d GK |
8414 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
8415 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
a8a05998 | 8416 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
8417 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, |
8418 | gen_rtx_SYMBOL_REF (Pmode, | |
8419 | alloc_rname)); | |
b6c9286a | 8420 | |
9ebbca7d GK |
8421 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
8422 | { | |
8423 | rtx addr, mem; | |
8424 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
8425 | GEN_INT (info->fp_save_offset + 8*i)); | |
8426 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 8427 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
8428 | |
8429 | RTVEC_ELT (p, i+3) = | |
8430 | gen_rtx_SET (VOIDmode, | |
8431 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
8432 | mem); | |
b6c9286a MM |
8433 | } |
8434 | } | |
9ebbca7d GK |
8435 | |
8436 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
3daf36a4 | 8437 | } |
9878760c RK |
8438 | } |
8439 | ||
8440 | /* Write function epilogue. */ | |
8441 | ||
08c148a8 NB |
8442 | static void |
8443 | rs6000_output_function_epilogue (file, size) | |
9878760c | 8444 | FILE *file; |
08c148a8 | 8445 | HOST_WIDE_INT size ATTRIBUTE_UNUSED; |
9878760c | 8446 | { |
4697a36c | 8447 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 8448 | |
9ebbca7d | 8449 | if (! HAVE_epilogue) |
9878760c | 8450 | { |
9ebbca7d GK |
8451 | rtx insn = get_last_insn (); |
8452 | /* If the last insn was a BARRIER, we don't have to write anything except | |
8453 | the trace table. */ | |
8454 | if (GET_CODE (insn) == NOTE) | |
8455 | insn = prev_nonnote_insn (insn); | |
8456 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 8457 | { |
9ebbca7d GK |
8458 | /* This is slightly ugly, but at least we don't have two |
8459 | copies of the epilogue-emitting code. */ | |
8460 | start_sequence (); | |
8461 | ||
8462 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
8463 | and end of the "toplevel" insn chain. */ | |
8464 | emit_note (0, NOTE_INSN_DELETED); | |
8465 | rs6000_emit_epilogue (FALSE); | |
8466 | emit_note (0, NOTE_INSN_DELETED); | |
8467 | ||
8468 | if (TARGET_DEBUG_STACK) | |
a4f6c312 SS |
8469 | debug_rtx_list (get_insns (), 100); |
8470 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 8471 | end_sequence (); |
4697a36c | 8472 | } |
9878760c | 8473 | } |
b4ac57ab | 8474 | |
9b30bae2 | 8475 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
8476 | on its format. |
8477 | ||
8478 | We don't output a traceback table if -finhibit-size-directive was | |
8479 | used. The documentation for -finhibit-size-directive reads | |
8480 | ``don't output a @code{.size} assembler directive, or anything | |
8481 | else that would cause trouble if the function is split in the | |
8482 | middle, and the two halves are placed at locations far apart in | |
8483 | memory.'' The traceback table has this property, since it | |
8484 | includes the offset from the start of the function to the | |
4d30c363 MM |
8485 | traceback table itself. |
8486 | ||
8487 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a MM |
8488 | different traceback table. */ |
8489 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive) | |
9b30bae2 | 8490 | { |
3cce094d | 8491 | const char *fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); |
3ac88239 | 8492 | const char *language_string = lang_hooks.name; |
314fc5a9 ILT |
8493 | int fixed_parms, float_parms, parm_info; |
8494 | int i; | |
8495 | ||
b6c9286a MM |
8496 | while (*fname == '.') /* V.4 encodes . in the name */ |
8497 | fname++; | |
8498 | ||
314fc5a9 ILT |
8499 | /* Need label immediately before tbtab, so we can compute its offset |
8500 | from the function start. */ | |
8501 | if (*fname == '*') | |
8502 | ++fname; | |
8503 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
8504 | ASM_OUTPUT_LABEL (file, fname); | |
8505 | ||
8506 | /* The .tbtab pseudo-op can only be used for the first eight | |
8507 | expressions, since it can't handle the possibly variable | |
8508 | length fields that follow. However, if you omit the optional | |
8509 | fields, the assembler outputs zeros for all optional fields | |
8510 | anyways, giving each variable length field is minimum length | |
8511 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
8512 | pseudo-op at all. */ | |
8513 | ||
8514 | /* An all-zero word flags the start of the tbtab, for debuggers | |
8515 | that have to find it by searching forward from the entry | |
8516 | point or from the current pc. */ | |
19d2d16f | 8517 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
8518 | |
8519 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 8520 | fputs ("\t.byte 0,", file); |
314fc5a9 ILT |
8521 | |
8522 | /* Language type. Unfortunately, there doesn't seem to be any | |
8523 | official way to get this info, so we use language_string. C | |
8524 | is 0. C++ is 9. No number defined for Obj-C, so use the | |
9517ead8 | 8525 | value for C for now. There is no official value for Java, |
6f573ff9 | 8526 | although IBM appears to be using 13. There is no official value |
f710504c | 8527 | for Chill, so we've chosen 44 pseudo-randomly. */ |
314fc5a9 | 8528 | if (! strcmp (language_string, "GNU C") |
e2c953b6 | 8529 | || ! strcmp (language_string, "GNU Objective-C")) |
314fc5a9 ILT |
8530 | i = 0; |
8531 | else if (! strcmp (language_string, "GNU F77")) | |
8532 | i = 1; | |
8533 | else if (! strcmp (language_string, "GNU Ada")) | |
8534 | i = 3; | |
8b83775b | 8535 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 ILT |
8536 | i = 2; |
8537 | else if (! strcmp (language_string, "GNU C++")) | |
8538 | i = 9; | |
9517ead8 AG |
8539 | else if (! strcmp (language_string, "GNU Java")) |
8540 | i = 13; | |
6f573ff9 JL |
8541 | else if (! strcmp (language_string, "GNU CHILL")) |
8542 | i = 44; | |
314fc5a9 ILT |
8543 | else |
8544 | abort (); | |
8545 | fprintf (file, "%d,", i); | |
8546 | ||
8547 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
8548 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
8549 | from start of procedure stored in tbtab, internal function, function | |
8550 | has controlled storage, function has no toc, function uses fp, | |
8551 | function logs/aborts fp operations. */ | |
8552 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
4697a36c | 8553 | fprintf (file, "%d,", (1 << 5) | ((info->first_fp_reg_save != 64) << 1)); |
314fc5a9 ILT |
8554 | |
8555 | /* 6 bitfields: function is interrupt handler, name present in | |
8556 | proc table, function calls alloca, on condition directives | |
8557 | (controls stack walks, 3 bits), saves condition reg, saves | |
8558 | link reg. */ | |
8559 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
8560 | set up as a frame pointer, even when there is no alloca call. */ | |
8561 | fprintf (file, "%d,", | |
8562 | ((1 << 6) | (frame_pointer_needed << 5) | |
4697a36c | 8563 | | (info->cr_save_p << 1) | (info->lr_save_p))); |
314fc5a9 ILT |
8564 | |
8565 | /* 3 bitfields: saves backchain, spare bit, number of fpr saved | |
8566 | (6 bits). */ | |
8567 | fprintf (file, "%d,", | |
4697a36c | 8568 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
8569 | |
8570 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
8571 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
8572 | ||
8573 | { | |
8574 | /* Compute the parameter info from the function decl argument | |
8575 | list. */ | |
8576 | tree decl; | |
8577 | int next_parm_info_bit; | |
8578 | ||
8579 | next_parm_info_bit = 31; | |
8580 | parm_info = 0; | |
8581 | fixed_parms = 0; | |
8582 | float_parms = 0; | |
8583 | ||
8584 | for (decl = DECL_ARGUMENTS (current_function_decl); | |
8585 | decl; decl = TREE_CHAIN (decl)) | |
8586 | { | |
8587 | rtx parameter = DECL_INCOMING_RTL (decl); | |
8588 | enum machine_mode mode = GET_MODE (parameter); | |
8589 | ||
8590 | if (GET_CODE (parameter) == REG) | |
8591 | { | |
8592 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
8593 | { | |
8594 | int bits; | |
8595 | ||
8596 | float_parms++; | |
8597 | ||
8598 | if (mode == SFmode) | |
8599 | bits = 0x2; | |
8600 | else if (mode == DFmode) | |
8601 | bits = 0x3; | |
8602 | else | |
8603 | abort (); | |
8604 | ||
8605 | /* If only one bit will fit, don't or in this entry. */ | |
8606 | if (next_parm_info_bit > 0) | |
8607 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
8608 | next_parm_info_bit -= 2; | |
8609 | } | |
8610 | else | |
8611 | { | |
8612 | fixed_parms += ((GET_MODE_SIZE (mode) | |
8613 | + (UNITS_PER_WORD - 1)) | |
8614 | / UNITS_PER_WORD); | |
8615 | next_parm_info_bit -= 1; | |
8616 | } | |
8617 | } | |
8618 | } | |
8619 | } | |
8620 | ||
8621 | /* Number of fixed point parameters. */ | |
8622 | /* This is actually the number of words of fixed point parameters; thus | |
8623 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
8624 | fprintf (file, "%d,", fixed_parms); | |
8625 | ||
8626 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
8627 | all on stack. */ | |
8628 | /* This is actually the number of fp registers that hold parameters; | |
8629 | and thus the maximum value is 13. */ | |
8630 | /* Set parameters on stack bit if parameters are not in their original | |
8631 | registers, regardless of whether they are on the stack? Xlc | |
8632 | seems to set the bit when not optimizing. */ | |
8633 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
8634 | ||
8635 | /* Optional fields follow. Some are variable length. */ | |
8636 | ||
8637 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
8638 | 11 double float. */ | |
8639 | /* There is an entry for each parameter in a register, in the order that | |
8640 | they occur in the parameter list. Any intervening arguments on the | |
8641 | stack are ignored. If the list overflows a long (max possible length | |
8642 | 34 bits) then completely leave off all elements that don't fit. */ | |
8643 | /* Only emit this long if there was at least one parameter. */ | |
8644 | if (fixed_parms || float_parms) | |
8645 | fprintf (file, "\t.long %d\n", parm_info); | |
8646 | ||
8647 | /* Offset from start of code to tb table. */ | |
19d2d16f | 8648 | fputs ("\t.long ", file); |
314fc5a9 | 8649 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
54ee9799 DE |
8650 | #if TARGET_AIX |
8651 | RS6000_OUTPUT_BASENAME (file, fname); | |
8652 | #else | |
9ebbca7d | 8653 | assemble_name (file, fname); |
54ee9799 | 8654 | #endif |
19d2d16f | 8655 | fputs ("-.", file); |
54ee9799 DE |
8656 | #if TARGET_AIX |
8657 | RS6000_OUTPUT_BASENAME (file, fname); | |
8658 | #else | |
9ebbca7d | 8659 | assemble_name (file, fname); |
54ee9799 | 8660 | #endif |
19d2d16f | 8661 | putc ('\n', file); |
314fc5a9 ILT |
8662 | |
8663 | /* Interrupt handler mask. */ | |
8664 | /* Omit this long, since we never set the interrupt handler bit | |
8665 | above. */ | |
8666 | ||
8667 | /* Number of CTL (controlled storage) anchors. */ | |
8668 | /* Omit this long, since the has_ctl bit is never set above. */ | |
8669 | ||
8670 | /* Displacement into stack of each CTL anchor. */ | |
8671 | /* Omit this list of longs, because there are no CTL anchors. */ | |
8672 | ||
8673 | /* Length of function name. */ | |
296b8152 | 8674 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
8675 | |
8676 | /* Function name. */ | |
8677 | assemble_string (fname, strlen (fname)); | |
8678 | ||
8679 | /* Register for alloca automatic storage; this is always reg 31. | |
8680 | Only emit this if the alloca bit was set above. */ | |
8681 | if (frame_pointer_needed) | |
19d2d16f | 8682 | fputs ("\t.byte 31\n", file); |
9b30bae2 | 8683 | } |
9878760c | 8684 | } |
17167fd8 | 8685 | \f |
a4f6c312 SS |
8686 | /* A C compound statement that outputs the assembler code for a thunk |
8687 | function, used to implement C++ virtual function calls with | |
8688 | multiple inheritance. The thunk acts as a wrapper around a virtual | |
8689 | function, adjusting the implicit object parameter before handing | |
8690 | control off to the real function. | |
8691 | ||
8692 | First, emit code to add the integer DELTA to the location that | |
8693 | contains the incoming first argument. Assume that this argument | |
8694 | contains a pointer, and is the one used to pass the `this' pointer | |
8695 | in C++. This is the incoming argument *before* the function | |
8696 | prologue, e.g. `%o0' on a sparc. The addition must preserve the | |
8697 | values of all other incoming arguments. | |
17167fd8 MM |
8698 | |
8699 | After the addition, emit code to jump to FUNCTION, which is a | |
a4f6c312 SS |
8700 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does |
8701 | not touch the return address. Hence returning from FUNCTION will | |
8702 | return to whoever called the current `thunk'. | |
17167fd8 | 8703 | |
a4f6c312 SS |
8704 | The effect must be as if FUNCTION had been called directly with the |
8705 | adjusted first argument. This macro is responsible for emitting | |
8706 | all of the code for a thunk function; output_function_prologue() | |
8707 | and output_function_epilogue() are not invoked. | |
17167fd8 | 8708 | |
a4f6c312 SS |
8709 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already |
8710 | been extracted from it.) It might possibly be useful on some | |
8711 | targets, but probably not. | |
17167fd8 | 8712 | |
a4f6c312 SS |
8713 | If you do not define this macro, the target-independent code in the |
8714 | C++ frontend will generate a less efficient heavyweight thunk that | |
8715 | calls FUNCTION instead of jumping to it. The generic approach does | |
8716 | not support varargs. */ | |
17167fd8 MM |
8717 | |
8718 | void | |
8719 | output_mi_thunk (file, thunk_fndecl, delta, function) | |
8720 | FILE *file; | |
d330fd93 | 8721 | tree thunk_fndecl ATTRIBUTE_UNUSED; |
17167fd8 MM |
8722 | int delta; |
8723 | tree function; | |
8724 | { | |
a4f6c312 SS |
8725 | const char *this_reg = |
8726 | reg_names[ aggregate_value_p (TREE_TYPE (TREE_TYPE (function))) ? 4 : 3 ]; | |
d330fd93 | 8727 | const char *prefix; |
3cce094d | 8728 | const char *fname; |
d330fd93 | 8729 | const char *r0 = reg_names[0]; |
d330fd93 KG |
8730 | const char *toc = reg_names[2]; |
8731 | const char *schain = reg_names[11]; | |
8732 | const char *r12 = reg_names[12]; | |
17167fd8 MM |
8733 | char buf[512]; |
8734 | static int labelno = 0; | |
8735 | ||
a4f6c312 | 8736 | /* Small constants that can be done by one add instruction. */ |
17167fd8 MM |
8737 | if (delta >= -32768 && delta <= 32767) |
8738 | { | |
22b4a3b0 | 8739 | if (! TARGET_NEW_MNEMONICS) |
17167fd8 MM |
8740 | fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta, this_reg); |
8741 | else | |
8742 | fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta); | |
8743 | } | |
8744 | ||
a4f6c312 | 8745 | /* Large constants that can be done by one addis instruction. */ |
17167fd8 MM |
8746 | else if ((delta & 0xffff) == 0 && num_insns_constant_wide (delta) == 1) |
8747 | asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg, | |
8748 | delta >> 16); | |
8749 | ||
8750 | /* 32-bit constants that can be done by an add and addis instruction. */ | |
8751 | else if (TARGET_32BIT || num_insns_constant_wide (delta) == 1) | |
8752 | { | |
a4f6c312 SS |
8753 | /* Break into two pieces, propagating the sign bit from the low |
8754 | word to the upper word. */ | |
17167fd8 MM |
8755 | int delta_high = delta >> 16; |
8756 | int delta_low = delta & 0xffff; | |
8757 | if ((delta_low & 0x8000) != 0) | |
8758 | { | |
8759 | delta_high++; | |
8760 | delta_low = (delta_low ^ 0x8000) - 0x8000; /* sign extend */ | |
8761 | } | |
8762 | ||
8763 | asm_fprintf (file, "\t{cau|addis} %s,%s,%d\n", this_reg, this_reg, | |
8764 | delta_high); | |
8765 | ||
22b4a3b0 | 8766 | if (! TARGET_NEW_MNEMONICS) |
17167fd8 MM |
8767 | fprintf (file, "\tcal %s,%d(%s)\n", this_reg, delta_low, this_reg); |
8768 | else | |
8769 | fprintf (file, "\taddi %s,%s,%d\n", this_reg, this_reg, delta_low); | |
8770 | } | |
8771 | ||
8772 | /* 64-bit constants, fixme */ | |
8773 | else | |
8774 | abort (); | |
8775 | ||
8776 | /* Get the prefix in front of the names. */ | |
8777 | switch (DEFAULT_ABI) | |
8778 | { | |
8779 | default: | |
8780 | abort (); | |
8781 | ||
8782 | case ABI_AIX: | |
8783 | prefix = "."; | |
8784 | break; | |
8785 | ||
8786 | case ABI_V4: | |
8787 | case ABI_AIX_NODESC: | |
17167fd8 MM |
8788 | prefix = ""; |
8789 | break; | |
17167fd8 MM |
8790 | } |
8791 | ||
8792 | /* If the function is compiled in this module, jump to it directly. | |
8793 | Otherwise, load up its address and jump to it. */ | |
8794 | ||
8795 | fname = XSTR (XEXP (DECL_RTL (function), 0), 0); | |
42820a49 | 8796 | |
9ebbca7d | 8797 | if (current_file_function_operand (XEXP (DECL_RTL (function), 0), VOIDmode) |
22b4a3b0 FS |
8798 | && ! lookup_attribute ("longcall", |
8799 | TYPE_ATTRIBUTES (TREE_TYPE (function)))) | |
17167fd8 MM |
8800 | { |
8801 | fprintf (file, "\tb %s", prefix); | |
8802 | assemble_name (file, fname); | |
22b4a3b0 | 8803 | if (DEFAULT_ABI == ABI_V4 && flag_pic) fputs ("@local", file); |
949ea356 | 8804 | putc ('\n', file); |
17167fd8 MM |
8805 | } |
8806 | ||
8807 | else | |
8808 | { | |
8809 | switch (DEFAULT_ABI) | |
8810 | { | |
8811 | default: | |
17167fd8 MM |
8812 | abort (); |
8813 | ||
8814 | case ABI_AIX: | |
8815 | /* Set up a TOC entry for the function. */ | |
8816 | ASM_GENERATE_INTERNAL_LABEL (buf, "Lthunk", labelno); | |
8817 | toc_section (); | |
8818 | ASM_OUTPUT_INTERNAL_LABEL (file, "Lthunk", labelno); | |
8819 | labelno++; | |
8820 | ||
fa9b5c6b DE |
8821 | if (TARGET_MINIMAL_TOC) |
8822 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); | |
8823 | else | |
8824 | { | |
8825 | fputs ("\t.tc ", file); | |
8826 | assemble_name (file, fname); | |
8827 | fputs ("[TC],", file); | |
8828 | } | |
8829 | assemble_name (file, fname); | |
17167fd8 MM |
8830 | putc ('\n', file); |
8831 | text_section (); | |
468e8dba DE |
8832 | if (TARGET_MINIMAL_TOC) |
8833 | asm_fprintf (file, (TARGET_32BIT) | |
8834 | ? "\t{l|lwz} %s,%s(%s)\n" : "\tld %s,%s(%s)\n", r12, | |
8835 | TARGET_ELF ? ".LCTOC0@toc" : ".LCTOC..1", toc); | |
d2574c50 | 8836 | asm_fprintf (file, (TARGET_32BIT) ? "\t{l|lwz} %s," : "\tld %s,", r12); |
17167fd8 | 8837 | assemble_name (file, buf); |
468e8dba DE |
8838 | if (TARGET_ELF && TARGET_MINIMAL_TOC) |
8839 | fputs ("-(.LCTOC1)", file); | |
8840 | asm_fprintf (file, "(%s)\n", TARGET_MINIMAL_TOC ? r12 : toc); | |
17167fd8 MM |
8841 | asm_fprintf (file, |
8842 | (TARGET_32BIT) ? "\t{l|lwz} %s,0(%s)\n" : "\tld %s,0(%s)\n", | |
8843 | r0, r12); | |
8844 | ||
8845 | asm_fprintf (file, | |
8846 | (TARGET_32BIT) ? "\t{l|lwz} %s,4(%s)\n" : "\tld %s,8(%s)\n", | |
8847 | toc, r12); | |
8848 | ||
8849 | asm_fprintf (file, "\tmtctr %s\n", r0); | |
8850 | asm_fprintf (file, | |
8851 | (TARGET_32BIT) ? "\t{l|lwz} %s,8(%s)\n" : "\tld %s,16(%s)\n", | |
8852 | schain, r12); | |
8853 | ||
8854 | asm_fprintf (file, "\tbctr\n"); | |
8855 | break; | |
8856 | ||
9ebbca7d | 8857 | case ABI_AIX_NODESC: |
17167fd8 | 8858 | case ABI_V4: |
22b4a3b0 FS |
8859 | fprintf (file, "\tb %s", prefix); |
8860 | assemble_name (file, fname); | |
8861 | if (flag_pic) fputs ("@plt", file); | |
949ea356 | 8862 | putc ('\n', file); |
22b4a3b0 | 8863 | break; |
ee890fe2 SS |
8864 | |
8865 | #if TARGET_MACHO | |
8866 | case ABI_DARWIN: | |
8867 | fprintf (file, "\tb %s", prefix); | |
8868 | if (flag_pic && !machopic_name_defined_p (fname)) | |
8869 | assemble_name (file, machopic_stub_name (fname)); | |
8870 | else | |
8871 | assemble_name (file, fname); | |
8872 | putc ('\n', file); | |
8873 | break; | |
8874 | #endif | |
9ebbca7d GK |
8875 | } |
8876 | } | |
8877 | } | |
42820a49 | 8878 | |
9ebbca7d GK |
8879 | \f |
8880 | /* A quick summary of the various types of 'constant-pool tables' | |
8881 | under PowerPC: | |
8882 | ||
8883 | Target Flags Name One table per | |
8884 | AIX (none) AIX TOC object file | |
8885 | AIX -mfull-toc AIX TOC object file | |
8886 | AIX -mminimal-toc AIX minimal TOC translation unit | |
8887 | SVR4/EABI (none) SVR4 SDATA object file | |
8888 | SVR4/EABI -fpic SVR4 pic object file | |
8889 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
8890 | SVR4/EABI -mrelocatable EABI TOC function | |
8891 | SVR4/EABI -maix AIX TOC object file | |
8892 | SVR4/EABI -maix -mminimal-toc | |
8893 | AIX minimal TOC translation unit | |
8894 | ||
8895 | Name Reg. Set by entries contains: | |
8896 | made by addrs? fp? sum? | |
8897 | ||
8898 | AIX TOC 2 crt0 as Y option option | |
8899 | AIX minimal TOC 30 prolog gcc Y Y option | |
8900 | SVR4 SDATA 13 crt0 gcc N Y N | |
8901 | SVR4 pic 30 prolog ld Y not yet N | |
8902 | SVR4 PIC 30 prolog gcc Y option option | |
8903 | EABI TOC 30 prolog gcc Y option option | |
8904 | ||
8905 | */ | |
8906 | ||
8907 | /* Hash table stuff for keeping track of TOC entries. */ | |
8908 | ||
8909 | struct toc_hash_struct | |
8910 | { | |
8911 | /* `key' will satisfy CONSTANT_P; in fact, it will satisfy | |
8912 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */ | |
8913 | rtx key; | |
a9098fd0 | 8914 | enum machine_mode key_mode; |
9ebbca7d GK |
8915 | int labelno; |
8916 | }; | |
17167fd8 | 8917 | |
9ebbca7d GK |
8918 | static htab_t toc_hash_table; |
8919 | ||
8920 | /* Hash functions for the hash table. */ | |
8921 | ||
8922 | static unsigned | |
8923 | rs6000_hash_constant (k) | |
8924 | rtx k; | |
8925 | { | |
a9098fd0 | 8926 | unsigned result = (GET_CODE (k) << 3) ^ GET_MODE (k); |
9ebbca7d GK |
8927 | const char *format = GET_RTX_FORMAT (GET_CODE (k)); |
8928 | int flen = strlen (format); | |
8929 | int fidx; | |
8930 | ||
8931 | if (GET_CODE (k) == LABEL_REF) | |
832ea3b3 | 8932 | return result * 1231 + X0INT (XEXP (k, 0), 3); |
9ebbca7d GK |
8933 | |
8934 | if (GET_CODE (k) == CONST_DOUBLE) | |
592bf28c | 8935 | fidx = 1; |
9ebbca7d GK |
8936 | else if (GET_CODE (k) == CODE_LABEL) |
8937 | fidx = 3; | |
8938 | else | |
8939 | fidx = 0; | |
8940 | ||
8941 | for (; fidx < flen; fidx++) | |
8942 | switch (format[fidx]) | |
8943 | { | |
8944 | case 's': | |
8945 | { | |
8946 | unsigned i, len; | |
8947 | const char *str = XSTR (k, fidx); | |
8948 | len = strlen (str); | |
8949 | result = result * 613 + len; | |
8950 | for (i = 0; i < len; i++) | |
8951 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
8952 | break; |
8953 | } | |
9ebbca7d GK |
8954 | case 'u': |
8955 | case 'e': | |
8956 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
8957 | break; | |
8958 | case 'i': | |
8959 | case 'n': | |
8960 | result = result * 613 + (unsigned) XINT (k, fidx); | |
8961 | break; | |
8962 | case 'w': | |
8963 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
8964 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
8965 | else | |
8966 | { | |
8967 | size_t i; | |
8968 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
8969 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
8970 | >> CHAR_BIT * i); | |
8971 | } | |
8972 | break; | |
8973 | default: | |
a4f6c312 | 8974 | abort (); |
9ebbca7d GK |
8975 | } |
8976 | return result; | |
8977 | } | |
8978 | ||
8979 | static unsigned | |
8980 | toc_hash_function (hash_entry) | |
8981 | const void * hash_entry; | |
8982 | { | |
a9098fd0 GK |
8983 | const struct toc_hash_struct *thc = |
8984 | (const struct toc_hash_struct *) hash_entry; | |
8985 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
8986 | } |
8987 | ||
8988 | /* Compare H1 and H2 for equivalence. */ | |
8989 | ||
8990 | static int | |
8991 | toc_hash_eq (h1, h2) | |
8992 | const void * h1; | |
8993 | const void * h2; | |
8994 | { | |
8995 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
8996 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
8997 | ||
a9098fd0 GK |
8998 | if (((const struct toc_hash_struct *) h1)->key_mode |
8999 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
9000 | return 0; | |
9001 | ||
9ebbca7d GK |
9002 | /* Gotcha: One of these const_doubles will be in memory. |
9003 | The other may be on the constant-pool chain. | |
a4f6c312 | 9004 | So rtx_equal_p will think they are different... */ |
9ebbca7d GK |
9005 | if (r1 == r2) |
9006 | return 1; | |
9007 | if (GET_CODE (r1) != GET_CODE (r2) | |
9008 | || GET_MODE (r1) != GET_MODE (r2)) | |
9009 | return 0; | |
9010 | if (GET_CODE (r1) == CONST_DOUBLE) | |
9011 | { | |
9012 | int format_len = strlen (GET_RTX_FORMAT (CONST_DOUBLE)); | |
9013 | int i; | |
592bf28c | 9014 | for (i = 1; i < format_len; i++) |
9ebbca7d GK |
9015 | if (XWINT (r1, i) != XWINT (r2, i)) |
9016 | return 0; | |
9017 | ||
9018 | return 1; | |
17167fd8 | 9019 | } |
9ebbca7d | 9020 | else if (GET_CODE (r1) == LABEL_REF) |
e4a0656f GK |
9021 | return (CODE_LABEL_NUMBER (XEXP (r1, 0)) |
9022 | == CODE_LABEL_NUMBER (XEXP (r2, 0))); | |
9ebbca7d GK |
9023 | else |
9024 | return rtx_equal_p (r1, r2); | |
9025 | } | |
9026 | ||
9027 | /* Mark the hash table-entry HASH_ENTRY. */ | |
9028 | ||
9029 | static int | |
9030 | toc_hash_mark_entry (hash_slot, unused) | |
2eba1afa | 9031 | void ** hash_slot; |
9ebbca7d GK |
9032 | void * unused ATTRIBUTE_UNUSED; |
9033 | { | |
9034 | const struct toc_hash_struct * hash_entry = | |
9035 | *(const struct toc_hash_struct **) hash_slot; | |
9036 | rtx r = hash_entry->key; | |
9037 | ggc_set_mark (hash_entry); | |
a4f6c312 | 9038 | /* For CODE_LABELS, we don't want to drag in the whole insn chain... */ |
9ebbca7d GK |
9039 | if (GET_CODE (r) == LABEL_REF) |
9040 | { | |
9041 | ggc_set_mark (r); | |
9042 | ggc_set_mark (XEXP (r, 0)); | |
9043 | } | |
9044 | else | |
9045 | ggc_mark_rtx (r); | |
9046 | return 1; | |
9047 | } | |
9048 | ||
9049 | /* Mark all the elements of the TOC hash-table *HT. */ | |
9050 | ||
9051 | static void | |
9052 | toc_hash_mark_table (vht) | |
9053 | void *vht; | |
9054 | { | |
9055 | htab_t *ht = vht; | |
9056 | ||
9057 | htab_traverse (*ht, toc_hash_mark_entry, (void *)0); | |
17167fd8 MM |
9058 | } |
9059 | ||
28e510bd MM |
9060 | /* These are the names given by the C++ front-end to vtables, and |
9061 | vtable-like objects. Ideally, this logic should not be here; | |
9062 | instead, there should be some programmatic way of inquiring as | |
9063 | to whether or not an object is a vtable. */ | |
9064 | ||
9065 | #define VTABLE_NAME_P(NAME) \ | |
9066 | (strncmp ("_vt.", name, strlen("_vt.")) == 0 \ | |
9067 | || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \ | |
9068 | || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \ | |
9069 | || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0) | |
9070 | ||
9071 | void | |
9072 | rs6000_output_symbol_ref (file, x) | |
9073 | FILE *file; | |
9074 | rtx x; | |
9075 | { | |
9076 | /* Currently C++ toc references to vtables can be emitted before it | |
9077 | is decided whether the vtable is public or private. If this is | |
9078 | the case, then the linker will eventually complain that there is | |
9079 | a reference to an unknown section. Thus, for vtables only, | |
9080 | we emit the TOC reference to reference the symbol and not the | |
9081 | section. */ | |
9082 | const char *name = XSTR (x, 0); | |
54ee9799 DE |
9083 | |
9084 | if (VTABLE_NAME_P (name)) | |
9085 | { | |
9086 | RS6000_OUTPUT_BASENAME (file, name); | |
9087 | } | |
9088 | else | |
9089 | assemble_name (file, name); | |
28e510bd MM |
9090 | } |
9091 | ||
a4f6c312 SS |
9092 | /* Output a TOC entry. We derive the entry name from what is being |
9093 | written. */ | |
9878760c RK |
9094 | |
9095 | void | |
a9098fd0 | 9096 | output_toc (file, x, labelno, mode) |
9878760c RK |
9097 | FILE *file; |
9098 | rtx x; | |
9099 | int labelno; | |
a9098fd0 | 9100 | enum machine_mode mode; |
9878760c RK |
9101 | { |
9102 | char buf[256]; | |
3cce094d | 9103 | const char *name = buf; |
ec940faa | 9104 | const char *real_name; |
9878760c RK |
9105 | rtx base = x; |
9106 | int offset = 0; | |
9107 | ||
4697a36c MM |
9108 | if (TARGET_NO_TOC) |
9109 | abort (); | |
9110 | ||
9ebbca7d GK |
9111 | /* When the linker won't eliminate them, don't output duplicate |
9112 | TOC entries (this happens on AIX if there is any kind of TOC, | |
1f8f4a0b MM |
9113 | and on SVR4 under -fPIC or -mrelocatable). */ |
9114 | if (TARGET_TOC) | |
9ebbca7d GK |
9115 | { |
9116 | struct toc_hash_struct *h; | |
9117 | void * * found; | |
9118 | ||
9119 | h = ggc_alloc (sizeof (*h)); | |
9120 | h->key = x; | |
a9098fd0 | 9121 | h->key_mode = mode; |
9ebbca7d GK |
9122 | h->labelno = labelno; |
9123 | ||
9124 | found = htab_find_slot (toc_hash_table, h, 1); | |
9125 | if (*found == NULL) | |
9126 | *found = h; | |
9127 | else /* This is indeed a duplicate. | |
9128 | Set this label equal to that label. */ | |
9129 | { | |
9130 | fputs ("\t.set ", file); | |
9131 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
9132 | fprintf (file, "%d,", labelno); | |
9133 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
9134 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) | |
9135 | found)->labelno)); | |
9136 | return; | |
9137 | } | |
9138 | } | |
9139 | ||
9140 | /* If we're going to put a double constant in the TOC, make sure it's | |
9141 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
9142 | if (GET_CODE (x) == CONST_DOUBLE |
9143 | && STRICT_ALIGNMENT | |
a9098fd0 | 9144 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
9145 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
9146 | ASM_OUTPUT_ALIGN (file, 3); | |
9147 | } | |
9148 | ||
9ebbca7d | 9149 | ASM_OUTPUT_INTERNAL_LABEL (file, "LC", labelno); |
9878760c | 9150 | |
37c37a57 RK |
9151 | /* Handle FP constants specially. Note that if we have a minimal |
9152 | TOC, things we put here aren't actually in the TOC, so we can allow | |
9153 | FP constants. */ | |
a9098fd0 | 9154 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) |
9878760c | 9155 | { |
042259f2 DE |
9156 | REAL_VALUE_TYPE rv; |
9157 | long k[2]; | |
0adc764e | 9158 | |
042259f2 DE |
9159 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
9160 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 9161 | |
13ded975 DE |
9162 | if (TARGET_64BIT) |
9163 | { | |
9164 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9165 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 9166 | else |
2bfcf297 DB |
9167 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", k[0], k[1]); |
9168 | fprintf (file, "0x%lx%08lx\n", k[0], k[1]); | |
13ded975 DE |
9169 | return; |
9170 | } | |
1875cc88 | 9171 | else |
13ded975 DE |
9172 | { |
9173 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9174 | fputs ("\t.long ", file); |
13ded975 | 9175 | else |
2bfcf297 DB |
9176 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", k[0], k[1]); |
9177 | fprintf (file, "0x%lx,0x%lx\n", k[0], k[1]); | |
13ded975 DE |
9178 | return; |
9179 | } | |
9878760c | 9180 | } |
a9098fd0 | 9181 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 9182 | { |
042259f2 DE |
9183 | REAL_VALUE_TYPE rv; |
9184 | long l; | |
9878760c | 9185 | |
042259f2 DE |
9186 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
9187 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9188 | ||
31bfaa0b DE |
9189 | if (TARGET_64BIT) |
9190 | { | |
9191 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9192 | fputs (DOUBLE_INT_ASM_OP, file); |
31bfaa0b | 9193 | else |
2bfcf297 DB |
9194 | fprintf (file, "\t.tc FS_%lx[TC],", l); |
9195 | fprintf (file, "0x%lx00000000\n", l); | |
31bfaa0b DE |
9196 | return; |
9197 | } | |
042259f2 | 9198 | else |
31bfaa0b DE |
9199 | { |
9200 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9201 | fputs ("\t.long ", file); |
31bfaa0b | 9202 | else |
2bfcf297 DB |
9203 | fprintf (file, "\t.tc FS_%lx[TC],", l); |
9204 | fprintf (file, "0x%lx\n", l); | |
31bfaa0b DE |
9205 | return; |
9206 | } | |
042259f2 | 9207 | } |
f176e826 | 9208 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 9209 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 9210 | { |
e2c953b6 | 9211 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
9212 | HOST_WIDE_INT high; |
9213 | ||
9214 | if (GET_CODE (x) == CONST_DOUBLE) | |
9215 | { | |
9216 | low = CONST_DOUBLE_LOW (x); | |
9217 | high = CONST_DOUBLE_HIGH (x); | |
9218 | } | |
9219 | else | |
9220 | #if HOST_BITS_PER_WIDE_INT == 32 | |
9221 | { | |
9222 | low = INTVAL (x); | |
0858c623 | 9223 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
9224 | } |
9225 | #else | |
9226 | { | |
0858c623 | 9227 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
9228 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
9229 | } | |
9230 | #endif | |
9878760c | 9231 | |
a9098fd0 GK |
9232 | /* TOC entries are always Pmode-sized, but since this |
9233 | is a bigendian machine then if we're putting smaller | |
9234 | integer constants in the TOC we have to pad them. | |
9235 | (This is still a win over putting the constants in | |
9236 | a separate constant pool, because then we'd have | |
02a4ec28 FS |
9237 | to have both a TOC entry _and_ the actual constant.) |
9238 | ||
9239 | For a 32-bit target, CONST_INT values are loaded and shifted | |
9240 | entirely within `low' and can be stored in one TOC entry. */ | |
9241 | ||
9242 | if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
a9098fd0 | 9243 | abort ();/* It would be easy to make this work, but it doesn't now. */ |
02a4ec28 FS |
9244 | |
9245 | if (POINTER_SIZE > GET_MODE_BITSIZE (mode)) | |
a9098fd0 GK |
9246 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), |
9247 | POINTER_SIZE, &low, &high, 0); | |
9248 | ||
13ded975 DE |
9249 | if (TARGET_64BIT) |
9250 | { | |
9251 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9252 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 9253 | else |
2bfcf297 DB |
9254 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", (long)high, (long)low); |
9255 | fprintf (file, "0x%lx%08lx\n", (long) high, (long) low); | |
13ded975 DE |
9256 | return; |
9257 | } | |
1875cc88 | 9258 | else |
13ded975 | 9259 | { |
02a4ec28 FS |
9260 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) |
9261 | { | |
9262 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9263 | fputs ("\t.long ", file); |
02a4ec28 | 9264 | else |
2bfcf297 DB |
9265 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
9266 | (long)high, (long)low); | |
9267 | fprintf (file, "0x%lx,0x%lx\n", (long) high, (long) low); | |
02a4ec28 | 9268 | } |
13ded975 | 9269 | else |
02a4ec28 FS |
9270 | { |
9271 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 9272 | fputs ("\t.long ", file); |
02a4ec28 | 9273 | else |
2bfcf297 DB |
9274 | fprintf (file, "\t.tc IS_%lx[TC],", (long) low); |
9275 | fprintf (file, "0x%lx\n", (long) low); | |
02a4ec28 | 9276 | } |
13ded975 DE |
9277 | return; |
9278 | } | |
9878760c RK |
9279 | } |
9280 | ||
9281 | if (GET_CODE (x) == CONST) | |
9282 | { | |
2bfcf297 DB |
9283 | if (GET_CODE (XEXP (x, 0)) != PLUS) |
9284 | abort (); | |
9285 | ||
9878760c RK |
9286 | base = XEXP (XEXP (x, 0), 0); |
9287 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
9288 | } | |
9289 | ||
9290 | if (GET_CODE (base) == SYMBOL_REF) | |
9291 | name = XSTR (base, 0); | |
9292 | else if (GET_CODE (base) == LABEL_REF) | |
9293 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
9294 | else if (GET_CODE (base) == CODE_LABEL) | |
9295 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
9296 | else | |
9297 | abort (); | |
9298 | ||
2e4eb9b0 | 9299 | STRIP_NAME_ENCODING (real_name, name); |
1875cc88 | 9300 | if (TARGET_MINIMAL_TOC) |
2bfcf297 | 9301 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); |
1875cc88 JW |
9302 | else |
9303 | { | |
b6c9286a | 9304 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 9305 | |
1875cc88 JW |
9306 | if (offset < 0) |
9307 | fprintf (file, ".N%d", - offset); | |
9308 | else if (offset) | |
9309 | fprintf (file, ".P%d", offset); | |
9878760c | 9310 | |
19d2d16f | 9311 | fputs ("[TC],", file); |
1875cc88 | 9312 | } |
581bc4de MM |
9313 | |
9314 | /* Currently C++ toc references to vtables can be emitted before it | |
9315 | is decided whether the vtable is public or private. If this is | |
9316 | the case, then the linker will eventually complain that there is | |
9317 | a TOC reference to an unknown section. Thus, for vtables only, | |
9318 | we emit the TOC reference to reference the symbol and not the | |
9319 | section. */ | |
28e510bd | 9320 | if (VTABLE_NAME_P (name)) |
581bc4de | 9321 | { |
54ee9799 | 9322 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
9323 | if (offset < 0) |
9324 | fprintf (file, "%d", offset); | |
9325 | else if (offset > 0) | |
9326 | fprintf (file, "+%d", offset); | |
9327 | } | |
9328 | else | |
9329 | output_addr_const (file, x); | |
19d2d16f | 9330 | putc ('\n', file); |
9878760c RK |
9331 | } |
9332 | \f | |
9333 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
9334 | starting at P to FILE. | |
9335 | ||
9336 | On the RS/6000, we have to do this using the .byte operation and | |
9337 | write out special characters outside the quoted string. | |
9338 | Also, the assembler is broken; very long strings are truncated, | |
a4f6c312 | 9339 | so we must artificially break them up early. */ |
9878760c RK |
9340 | |
9341 | void | |
9342 | output_ascii (file, p, n) | |
9343 | FILE *file; | |
d330fd93 | 9344 | const char *p; |
9878760c RK |
9345 | int n; |
9346 | { | |
9347 | char c; | |
9348 | int i, count_string; | |
d330fd93 KG |
9349 | const char *for_string = "\t.byte \""; |
9350 | const char *for_decimal = "\t.byte "; | |
9351 | const char *to_close = NULL; | |
9878760c RK |
9352 | |
9353 | count_string = 0; | |
9354 | for (i = 0; i < n; i++) | |
9355 | { | |
9356 | c = *p++; | |
9357 | if (c >= ' ' && c < 0177) | |
9358 | { | |
9359 | if (for_string) | |
9360 | fputs (for_string, file); | |
9361 | putc (c, file); | |
9362 | ||
9363 | /* Write two quotes to get one. */ | |
9364 | if (c == '"') | |
9365 | { | |
9366 | putc (c, file); | |
9367 | ++count_string; | |
9368 | } | |
9369 | ||
9370 | for_string = NULL; | |
9371 | for_decimal = "\"\n\t.byte "; | |
9372 | to_close = "\"\n"; | |
9373 | ++count_string; | |
9374 | ||
9375 | if (count_string >= 512) | |
9376 | { | |
9377 | fputs (to_close, file); | |
9378 | ||
9379 | for_string = "\t.byte \""; | |
9380 | for_decimal = "\t.byte "; | |
9381 | to_close = NULL; | |
9382 | count_string = 0; | |
9383 | } | |
9384 | } | |
9385 | else | |
9386 | { | |
9387 | if (for_decimal) | |
9388 | fputs (for_decimal, file); | |
9389 | fprintf (file, "%d", c); | |
9390 | ||
9391 | for_string = "\n\t.byte \""; | |
9392 | for_decimal = ", "; | |
9393 | to_close = "\n"; | |
9394 | count_string = 0; | |
9395 | } | |
9396 | } | |
9397 | ||
9398 | /* Now close the string if we have written one. Then end the line. */ | |
9399 | if (to_close) | |
9ebbca7d | 9400 | fputs (to_close, file); |
9878760c RK |
9401 | } |
9402 | \f | |
9403 | /* Generate a unique section name for FILENAME for a section type | |
9404 | represented by SECTION_DESC. Output goes into BUF. | |
9405 | ||
9406 | SECTION_DESC can be any string, as long as it is different for each | |
9407 | possible section type. | |
9408 | ||
9409 | We name the section in the same manner as xlc. The name begins with an | |
9410 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
9411 | names) with the last period replaced by the string SECTION_DESC. If |
9412 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
9413 | the name. */ | |
9878760c RK |
9414 | |
9415 | void | |
9416 | rs6000_gen_section_name (buf, filename, section_desc) | |
9417 | char **buf; | |
9ebbca7d GK |
9418 | const char *filename; |
9419 | const char *section_desc; | |
9878760c | 9420 | { |
9ebbca7d | 9421 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
9422 | char *p; |
9423 | int len; | |
9878760c RK |
9424 | |
9425 | after_last_slash = filename; | |
9426 | for (q = filename; *q; q++) | |
11e5fe42 RK |
9427 | { |
9428 | if (*q == '/') | |
9429 | after_last_slash = q + 1; | |
9430 | else if (*q == '.') | |
9431 | last_period = q; | |
9432 | } | |
9878760c | 9433 | |
11e5fe42 | 9434 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
9878760c RK |
9435 | *buf = (char *) permalloc (len); |
9436 | ||
9437 | p = *buf; | |
9438 | *p++ = '_'; | |
9439 | ||
9440 | for (q = after_last_slash; *q; q++) | |
9441 | { | |
11e5fe42 | 9442 | if (q == last_period) |
9878760c RK |
9443 | { |
9444 | strcpy (p, section_desc); | |
9445 | p += strlen (section_desc); | |
9878760c RK |
9446 | } |
9447 | ||
e9a780ec | 9448 | else if (ISALNUM (*q)) |
9878760c RK |
9449 | *p++ = *q; |
9450 | } | |
9451 | ||
11e5fe42 | 9452 | if (last_period == 0) |
9878760c RK |
9453 | strcpy (p, section_desc); |
9454 | else | |
9455 | *p = '\0'; | |
9456 | } | |
e165f3f0 | 9457 | \f |
a4f6c312 | 9458 | /* Emit profile function. */ |
411707f4 | 9459 | |
411707f4 CC |
9460 | void |
9461 | output_profile_hook (labelno) | |
9462 | int labelno; | |
9463 | { | |
8480e480 CC |
9464 | if (DEFAULT_ABI == ABI_AIX) |
9465 | { | |
9466 | char buf[30]; | |
40501e5f | 9467 | const char *label_name; |
8480e480 | 9468 | rtx fun; |
411707f4 | 9469 | |
8480e480 | 9470 | labelno += 1; |
411707f4 | 9471 | |
8480e480 CC |
9472 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
9473 | STRIP_NAME_ENCODING (label_name, ggc_strdup (buf)); | |
9474 | fun = gen_rtx_SYMBOL_REF (Pmode, label_name); | |
411707f4 | 9475 | |
8480e480 CC |
9476 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1, |
9477 | fun, Pmode); | |
9478 | } | |
ee890fe2 SS |
9479 | else if (DEFAULT_ABI == ABI_DARWIN) |
9480 | { | |
d5fa86ba | 9481 | const char *mcount_name = RS6000_MCOUNT; |
ee890fe2 SS |
9482 | int caller_addr_regno = LINK_REGISTER_REGNUM; |
9483 | ||
9484 | /* Be conservative and always set this, at least for now. */ | |
9485 | current_function_uses_pic_offset_table = 1; | |
9486 | ||
9487 | #if TARGET_MACHO | |
9488 | /* For PIC code, set up a stub and collect the caller's address | |
9489 | from r0, which is where the prologue puts it. */ | |
9490 | if (flag_pic) | |
9491 | { | |
9492 | mcount_name = machopic_stub_name (mcount_name); | |
9493 | if (current_function_uses_pic_offset_table) | |
9494 | caller_addr_regno = 0; | |
9495 | } | |
9496 | #endif | |
9497 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name), | |
9498 | 0, VOIDmode, 1, | |
9499 | gen_rtx_REG (Pmode, caller_addr_regno), Pmode); | |
9500 | } | |
411707f4 CC |
9501 | } |
9502 | ||
a4f6c312 | 9503 | /* Write function profiler code. */ |
e165f3f0 RK |
9504 | |
9505 | void | |
9506 | output_function_profiler (file, labelno) | |
9507 | FILE *file; | |
9508 | int labelno; | |
9509 | { | |
3daf36a4 | 9510 | char buf[100]; |
e165f3f0 | 9511 | |
3daf36a4 | 9512 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 | 9513 | switch (DEFAULT_ABI) |
3daf36a4 | 9514 | { |
38c1f2d7 MM |
9515 | default: |
9516 | abort (); | |
9517 | ||
9518 | case ABI_V4: | |
38c1f2d7 MM |
9519 | case ABI_AIX_NODESC: |
9520 | fprintf (file, "\tmflr %s\n", reg_names[0]); | |
9521 | if (flag_pic == 1) | |
9522 | { | |
dfdfa60f DE |
9523 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
9524 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", | |
9525 | reg_names[0], reg_names[1]); | |
17167fd8 | 9526 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 9527 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 9528 | assemble_name (file, buf); |
17167fd8 | 9529 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 9530 | } |
9ebbca7d | 9531 | else if (flag_pic > 1) |
38c1f2d7 | 9532 | { |
dfdfa60f DE |
9533 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", |
9534 | reg_names[0], reg_names[1]); | |
9ebbca7d GK |
9535 | /* Now, we need to get the address of the label. */ |
9536 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 9537 | assemble_name (file, buf); |
9ebbca7d GK |
9538 | fputs ("-.\n1:", file); |
9539 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
9540 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", | |
9541 | reg_names[0], reg_names[11]); | |
9542 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
9543 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 9544 | } |
38c1f2d7 MM |
9545 | else |
9546 | { | |
17167fd8 | 9547 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 9548 | assemble_name (file, buf); |
dfdfa60f | 9549 | fputs ("@ha\n", file); |
b5253831 DE |
9550 | asm_fprintf (file, "\t{st|stw} %s,4(%s)\n", |
9551 | reg_names[0], reg_names[1]); | |
a260abc9 | 9552 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 9553 | assemble_name (file, buf); |
17167fd8 | 9554 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
9555 | } |
9556 | ||
b5253831 DE |
9557 | if (current_function_needs_context) |
9558 | asm_fprintf (file, "\tmr %s,%s\n", | |
9559 | reg_names[30], reg_names[STATIC_CHAIN_REGNUM]); | |
38c1f2d7 | 9560 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); |
b5253831 DE |
9561 | if (current_function_needs_context) |
9562 | asm_fprintf (file, "\tmr %s,%s\n", | |
9563 | reg_names[STATIC_CHAIN_REGNUM], reg_names[30]); | |
38c1f2d7 MM |
9564 | break; |
9565 | ||
9566 | case ABI_AIX: | |
ee890fe2 | 9567 | case ABI_DARWIN: |
a4f6c312 | 9568 | /* Don't do anything, done in output_profile_hook (). */ |
38c1f2d7 | 9569 | break; |
411707f4 | 9570 | |
38c1f2d7 | 9571 | } |
e165f3f0 | 9572 | } |
a251ffd0 TG |
9573 | |
9574 | /* Adjust the cost of a scheduling dependency. Return the new cost of | |
9575 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
9576 | ||
c237e94a | 9577 | static int |
a06faf84 | 9578 | rs6000_adjust_cost (insn, link, dep_insn, cost) |
a251ffd0 TG |
9579 | rtx insn; |
9580 | rtx link; | |
296b8152 | 9581 | rtx dep_insn ATTRIBUTE_UNUSED; |
a251ffd0 TG |
9582 | int cost; |
9583 | { | |
9584 | if (! recog_memoized (insn)) | |
9585 | return 0; | |
9586 | ||
9587 | if (REG_NOTE_KIND (link) != 0) | |
9588 | return 0; | |
9589 | ||
9590 | if (REG_NOTE_KIND (link) == 0) | |
9591 | { | |
ed947a96 DJ |
9592 | /* Data dependency; DEP_INSN writes a register that INSN reads |
9593 | some cycles later. */ | |
9594 | switch (get_attr_type (insn)) | |
9595 | { | |
9596 | case TYPE_JMPREG: | |
9597 | /* Tell the first scheduling pass about the latency between | |
9598 | a mtctr and bctr (and mtlr and br/blr). The first | |
9599 | scheduling pass will not know about this latency since | |
9600 | the mtctr instruction, which has the latency associated | |
9601 | to it, will be generated by reload. */ | |
9602 | return TARGET_POWER ? 5 : 4; | |
9603 | case TYPE_BRANCH: | |
9604 | /* Leave some extra cycles between a compare and its | |
9605 | dependent branch, to inhibit expensive mispredicts. */ | |
9606 | if ((rs6000_cpu_attr == CPU_PPC750 | |
9607 | || rs6000_cpu_attr == CPU_PPC7400 | |
9608 | || rs6000_cpu_attr == CPU_PPC7450) | |
9609 | && recog_memoized (dep_insn) | |
9610 | && (INSN_CODE (dep_insn) >= 0) | |
9611 | && (get_attr_type (dep_insn) == TYPE_COMPARE | |
9612 | || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE | |
9613 | || get_attr_type (dep_insn) == TYPE_FPCOMPARE | |
9614 | || get_attr_type (dep_insn) == TYPE_CR_LOGICAL)) | |
9615 | return cost + 2; | |
9616 | default: | |
9617 | break; | |
9618 | } | |
a251ffd0 TG |
9619 | /* Fall out to return default cost. */ |
9620 | } | |
9621 | ||
9622 | return cost; | |
9623 | } | |
b6c9286a | 9624 | |
a4f6c312 SS |
9625 | /* A C statement (sans semicolon) to update the integer scheduling |
9626 | priority INSN_PRIORITY (INSN). Reduce the priority to execute the | |
9627 | INSN earlier, increase the priority to execute INSN later. Do not | |
9628 | define this macro if you do not need to adjust the scheduling | |
9629 | priorities of insns. */ | |
bef84347 | 9630 | |
c237e94a | 9631 | static int |
bef84347 | 9632 | rs6000_adjust_priority (insn, priority) |
d330fd93 | 9633 | rtx insn ATTRIBUTE_UNUSED; |
bef84347 VM |
9634 | int priority; |
9635 | { | |
a4f6c312 SS |
9636 | /* On machines (like the 750) which have asymmetric integer units, |
9637 | where one integer unit can do multiply and divides and the other | |
9638 | can't, reduce the priority of multiply/divide so it is scheduled | |
9639 | before other integer operations. */ | |
bef84347 VM |
9640 | |
9641 | #if 0 | |
2c3c49de | 9642 | if (! INSN_P (insn)) |
bef84347 VM |
9643 | return priority; |
9644 | ||
9645 | if (GET_CODE (PATTERN (insn)) == USE) | |
9646 | return priority; | |
9647 | ||
9648 | switch (rs6000_cpu_attr) { | |
9649 | case CPU_PPC750: | |
9650 | switch (get_attr_type (insn)) | |
9651 | { | |
9652 | default: | |
9653 | break; | |
9654 | ||
9655 | case TYPE_IMUL: | |
9656 | case TYPE_IDIV: | |
3cb999d8 DE |
9657 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
9658 | priority, priority); | |
bef84347 VM |
9659 | if (priority >= 0 && priority < 0x01000000) |
9660 | priority >>= 3; | |
9661 | break; | |
9662 | } | |
9663 | } | |
9664 | #endif | |
9665 | ||
9666 | return priority; | |
9667 | } | |
9668 | ||
a4f6c312 SS |
9669 | /* Return how many instructions the machine can issue per cycle. */ |
9670 | ||
c237e94a ZW |
9671 | static int |
9672 | rs6000_issue_rate () | |
b6c9286a MM |
9673 | { |
9674 | switch (rs6000_cpu_attr) { | |
3cb999d8 DE |
9675 | case CPU_RIOS1: /* ? */ |
9676 | case CPU_RS64A: | |
9677 | case CPU_PPC601: /* ? */ | |
ed947a96 | 9678 | case CPU_PPC7450: |
3cb999d8 | 9679 | return 3; |
b6c9286a | 9680 | case CPU_PPC603: |
bef84347 | 9681 | case CPU_PPC750: |
ed947a96 | 9682 | case CPU_PPC7400: |
bef84347 | 9683 | return 2; |
3cb999d8 | 9684 | case CPU_RIOS2: |
b6c9286a | 9685 | case CPU_PPC604: |
19684119 | 9686 | case CPU_PPC604E: |
b6c9286a | 9687 | case CPU_PPC620: |
3cb999d8 | 9688 | case CPU_PPC630: |
b6c9286a MM |
9689 | return 4; |
9690 | default: | |
9691 | return 1; | |
9692 | } | |
9693 | } | |
9694 | ||
b6c9286a | 9695 | \f |
b6c9286a MM |
9696 | /* Length in units of the trampoline for entering a nested function. */ |
9697 | ||
9698 | int | |
9699 | rs6000_trampoline_size () | |
9700 | { | |
9701 | int ret = 0; | |
9702 | ||
9703 | switch (DEFAULT_ABI) | |
9704 | { | |
9705 | default: | |
9706 | abort (); | |
9707 | ||
9708 | case ABI_AIX: | |
8f802bfb | 9709 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
9710 | break; |
9711 | ||
4dabc42d | 9712 | case ABI_DARWIN: |
b6c9286a MM |
9713 | case ABI_V4: |
9714 | case ABI_AIX_NODESC: | |
03a7e1a5 | 9715 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 9716 | break; |
b6c9286a MM |
9717 | } |
9718 | ||
9719 | return ret; | |
9720 | } | |
9721 | ||
9722 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
9723 | FNADDR is an RTX for the address of the function's pure code. | |
9724 | CXT is an RTX for the static chain value for the function. */ | |
9725 | ||
9726 | void | |
9727 | rs6000_initialize_trampoline (addr, fnaddr, cxt) | |
9728 | rtx addr; | |
9729 | rtx fnaddr; | |
9730 | rtx cxt; | |
9731 | { | |
ac2a93a1 | 9732 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
9733 | int regsize = (TARGET_32BIT) ? 4 : 8; |
9734 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
9735 | |
9736 | switch (DEFAULT_ABI) | |
9737 | { | |
9738 | default: | |
9739 | abort (); | |
9740 | ||
8bd04c56 | 9741 | /* Macros to shorten the code expansions below. */ |
39403d82 | 9742 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
9743 | #define MEM_PLUS(addr,offset) \ |
9744 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 9745 | |
b6c9286a MM |
9746 | /* Under AIX, just build the 3 word function descriptor */ |
9747 | case ABI_AIX: | |
8bd04c56 MM |
9748 | { |
9749 | rtx fn_reg = gen_reg_rtx (pmode); | |
9750 | rtx toc_reg = gen_reg_rtx (pmode); | |
9751 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
1cb18e3c | 9752 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); |
8bd04c56 MM |
9753 | emit_move_insn (MEM_DEREF (addr), fn_reg); |
9754 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
9755 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
9756 | } | |
b6c9286a MM |
9757 | break; |
9758 | ||
4dabc42d TC |
9759 | /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */ |
9760 | case ABI_DARWIN: | |
b6c9286a MM |
9761 | case ABI_V4: |
9762 | case ABI_AIX_NODESC: | |
39403d82 | 9763 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
9764 | FALSE, VOIDmode, 4, |
9765 | addr, pmode, | |
9766 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
9767 | fnaddr, pmode, | |
9768 | ctx_reg, pmode); | |
b6c9286a | 9769 | break; |
b6c9286a MM |
9770 | } |
9771 | ||
9772 | return; | |
9773 | } | |
7509c759 MM |
9774 | |
9775 | \f | |
91d231cb | 9776 | /* Table of valid machine attributes. */ |
a4f6c312 | 9777 | |
91d231cb | 9778 | const struct attribute_spec rs6000_attribute_table[] = |
7509c759 | 9779 | { |
91d231cb JM |
9780 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
9781 | { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, | |
9782 | { NULL, 0, 0, false, false, false, NULL } | |
9783 | }; | |
7509c759 | 9784 | |
a4f6c312 SS |
9785 | /* Handle a "longcall" attribute; arguments as in struct |
9786 | attribute_spec.handler. */ | |
9787 | ||
91d231cb JM |
9788 | static tree |
9789 | rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs) | |
9790 | tree *node; | |
9791 | tree name; | |
9792 | tree args ATTRIBUTE_UNUSED; | |
9793 | int flags ATTRIBUTE_UNUSED; | |
9794 | bool *no_add_attrs; | |
9795 | { | |
9796 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
9797 | && TREE_CODE (*node) != FIELD_DECL | |
9798 | && TREE_CODE (*node) != TYPE_DECL) | |
9799 | { | |
9800 | warning ("`%s' attribute only applies to functions", | |
9801 | IDENTIFIER_POINTER (name)); | |
9802 | *no_add_attrs = true; | |
9803 | } | |
6a4cee5f | 9804 | |
91d231cb | 9805 | return NULL_TREE; |
7509c759 MM |
9806 | } |
9807 | ||
3cb999d8 DE |
9808 | /* Return a reference suitable for calling a function with the |
9809 | longcall attribute. */ | |
a4f6c312 | 9810 | |
6a4cee5f MM |
9811 | struct rtx_def * |
9812 | rs6000_longcall_ref (call_ref) | |
9813 | rtx call_ref; | |
9814 | { | |
d330fd93 | 9815 | const char *call_name; |
6a4cee5f MM |
9816 | tree node; |
9817 | ||
9818 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
9819 | return call_ref; | |
9820 | ||
9821 | /* System V adds '.' to the internal name, so skip them. */ | |
9822 | call_name = XSTR (call_ref, 0); | |
9823 | if (*call_name == '.') | |
9824 | { | |
9825 | while (*call_name == '.') | |
9826 | call_name++; | |
9827 | ||
9828 | node = get_identifier (call_name); | |
39403d82 | 9829 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
9830 | } |
9831 | ||
9832 | return force_reg (Pmode, call_ref); | |
9833 | } | |
9834 | ||
7509c759 MM |
9835 | \f |
9836 | /* A C statement or statements to switch to the appropriate section | |
9837 | for output of RTX in mode MODE. You can assume that RTX is some | |
9838 | kind of constant in RTL. The argument MODE is redundant except in | |
9839 | the case of a `const_int' rtx. Select the section by calling | |
9840 | `text_section' or one of the alternatives for other sections. | |
9841 | ||
9842 | Do not define this macro if you put all constants in the read-only | |
9843 | data section. */ | |
9844 | ||
b91da81f | 9845 | #ifdef USING_ELFOS_H |
7509c759 MM |
9846 | |
9847 | void | |
9848 | rs6000_select_rtx_section (mode, x) | |
a9098fd0 | 9849 | enum machine_mode mode; |
7509c759 MM |
9850 | rtx x; |
9851 | { | |
a9098fd0 | 9852 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 9853 | toc_section (); |
7509c759 MM |
9854 | else |
9855 | const_section (); | |
9856 | } | |
9857 | ||
9858 | /* A C statement or statements to switch to the appropriate | |
9859 | section for output of DECL. DECL is either a `VAR_DECL' node | |
9860 | or a constant of some sort. RELOC indicates whether forming | |
9861 | the initial value of DECL requires link-time relocations. */ | |
9862 | ||
9863 | void | |
9864 | rs6000_select_section (decl, reloc) | |
9865 | tree decl; | |
9866 | int reloc; | |
9867 | { | |
9868 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
63019373 GK |
9869 | int needs_sdata; |
9870 | int readonly; | |
9871 | static void (* const sec_funcs[4]) PARAMS ((void)) = { | |
9872 | &const_section, | |
9873 | &sdata2_section, | |
9874 | &data_section, | |
9875 | &sdata_section | |
9876 | }; | |
9877 | ||
9878 | needs_sdata = (size > 0 | |
9879 | && size <= g_switch_value | |
9880 | && rs6000_sdata != SDATA_NONE | |
9881 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))); | |
7509c759 MM |
9882 | |
9883 | if (TREE_CODE (decl) == STRING_CST) | |
63019373 | 9884 | readonly = ! flag_writable_strings; |
a9098fd0 | 9885 | else if (TREE_CODE (decl) == VAR_DECL) |
63019373 GK |
9886 | readonly = (! (flag_pic && reloc) |
9887 | && TREE_READONLY (decl) | |
9888 | && ! TREE_SIDE_EFFECTS (decl) | |
9889 | && DECL_INITIAL (decl) | |
9890 | && DECL_INITIAL (decl) != error_mark_node | |
9891 | && TREE_CONSTANT (DECL_INITIAL (decl))); | |
ac4f7ad9 GK |
9892 | else if (TREE_CODE (decl) == CONSTRUCTOR) |
9893 | readonly = (! (flag_pic && reloc) | |
ac4f7ad9 | 9894 | && ! TREE_SIDE_EFFECTS (decl) |
f3afc192 | 9895 | && TREE_CONSTANT (decl)); |
7509c759 | 9896 | else |
63019373 GK |
9897 | readonly = 1; |
9898 | if (needs_sdata && rs6000_sdata != SDATA_EABI) | |
9899 | readonly = 0; | |
9900 | ||
9901 | (*sec_funcs[(readonly ? 0 : 2) + (needs_sdata ? 1 : 0)])(); | |
9902 | } | |
9903 | ||
9904 | /* A C statement to build up a unique section name, expressed as a | |
9905 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
9906 | RELOC indicates whether the initial value of EXP requires | |
9907 | link-time relocations. If you do not define this macro, GCC will use | |
9908 | the symbol name prefixed by `.' as the section name. Note - this | |
f5143c46 | 9909 | macro can now be called for uninitialized data items as well as |
63019373 GK |
9910 | initialised data and functions. */ |
9911 | ||
9912 | void | |
9913 | rs6000_unique_section (decl, reloc) | |
9914 | tree decl; | |
9915 | int reloc; | |
9916 | { | |
63019373 GK |
9917 | int len; |
9918 | int sec; | |
9919 | const char *name; | |
9920 | char *string; | |
9921 | const char *prefix; | |
9922 | ||
9923 | static const char *const prefixes[7][2] = | |
9924 | { | |
63019373 GK |
9925 | { ".rodata.", ".gnu.linkonce.r." }, |
9926 | { ".sdata2.", ".gnu.linkonce.s2." }, | |
9927 | { ".data.", ".gnu.linkonce.d." }, | |
9928 | { ".sdata.", ".gnu.linkonce.s." }, | |
9929 | { ".bss.", ".gnu.linkonce.b." }, | |
5b8c2356 AM |
9930 | { ".sbss.", ".gnu.linkonce.sb." }, |
9931 | { ".text.", ".gnu.linkonce.t." } | |
63019373 | 9932 | }; |
63019373 | 9933 | |
5b8c2356 AM |
9934 | if (TREE_CODE (decl) == FUNCTION_DECL) |
9935 | sec = 6; | |
63019373 | 9936 | else |
5b8c2356 AM |
9937 | { |
9938 | int readonly; | |
9939 | int needs_sdata; | |
9940 | int size; | |
9941 | ||
9942 | readonly = 1; | |
9943 | if (TREE_CODE (decl) == STRING_CST) | |
9944 | readonly = ! flag_writable_strings; | |
9945 | else if (TREE_CODE (decl) == VAR_DECL) | |
9946 | readonly = (! (flag_pic && reloc) | |
9947 | && TREE_READONLY (decl) | |
9948 | && ! TREE_SIDE_EFFECTS (decl) | |
9949 | && TREE_CONSTANT (DECL_INITIAL (decl))); | |
9950 | ||
9951 | size = int_size_in_bytes (TREE_TYPE (decl)); | |
9952 | needs_sdata = (size > 0 | |
9953 | && size <= g_switch_value | |
9954 | && rs6000_sdata != SDATA_NONE | |
9955 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))); | |
9956 | ||
9957 | if (DECL_INITIAL (decl) == 0 | |
9958 | || DECL_INITIAL (decl) == error_mark_node) | |
9959 | sec = 4; | |
9960 | else if (! readonly) | |
9961 | sec = 2; | |
9962 | else | |
9963 | sec = 0; | |
63019373 | 9964 | |
5b8c2356 AM |
9965 | if (needs_sdata) |
9966 | { | |
9967 | /* .sdata2 is only for EABI. */ | |
9968 | if (sec == 0 && rs6000_sdata != SDATA_EABI) | |
9969 | sec = 2; | |
9970 | sec += 1; | |
9971 | } | |
9972 | } | |
63019373 | 9973 | |
e6978109 | 9974 | STRIP_NAME_ENCODING (name, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); |
63019373 GK |
9975 | prefix = prefixes[sec][DECL_ONE_ONLY (decl)]; |
9976 | len = strlen (name) + strlen (prefix); | |
9977 | string = alloca (len + 1); | |
9978 | ||
9979 | sprintf (string, "%s%s", prefix, name); | |
9980 | ||
9981 | DECL_SECTION_NAME (decl) = build_string (len, string); | |
7509c759 | 9982 | } |
d9407988 MM |
9983 | |
9984 | \f | |
d9407988 MM |
9985 | /* If we are referencing a function that is static or is known to be |
9986 | in this file, make the SYMBOL_REF special. We can use this to indicate | |
9987 | that we can branch to this function without emitting a no-op after the | |
9ebbca7d | 9988 | call. For real AIX calling sequences, we also replace the |
d9407988 MM |
9989 | function name with the real name (1 or 2 leading .'s), rather than |
9990 | the function descriptor name. This saves a lot of overriding code | |
a260abc9 | 9991 | to read the prefixes. */ |
d9407988 MM |
9992 | |
9993 | void | |
9994 | rs6000_encode_section_info (decl) | |
9995 | tree decl; | |
9996 | { | |
9997 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
9998 | { | |
9999 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
8f1b829e | 10000 | if ((TREE_ASM_WRITTEN (decl) || ! TREE_PUBLIC (decl)) |
c81fc13e | 10001 | && ! DECL_WEAK (decl)) |
d9407988 MM |
10002 | SYMBOL_REF_FLAG (sym_ref) = 1; |
10003 | ||
9ebbca7d | 10004 | if (DEFAULT_ABI == ABI_AIX) |
d9407988 | 10005 | { |
ff669a6c RH |
10006 | size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2; |
10007 | size_t len2 = strlen (XSTR (sym_ref, 0)); | |
520a57c8 | 10008 | char *str = alloca (len1 + len2 + 1); |
ff669a6c RH |
10009 | str[0] = '.'; |
10010 | str[1] = '.'; | |
10011 | memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1); | |
10012 | ||
520a57c8 | 10013 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2); |
d9407988 MM |
10014 | } |
10015 | } | |
10016 | else if (rs6000_sdata != SDATA_NONE | |
f607bc57 | 10017 | && DEFAULT_ABI == ABI_V4 |
d9407988 MM |
10018 | && TREE_CODE (decl) == VAR_DECL) |
10019 | { | |
10020 | int size = int_size_in_bytes (TREE_TYPE (decl)); | |
10021 | tree section_name = DECL_SECTION_NAME (decl); | |
d330fd93 | 10022 | const char *name = (char *)0; |
d9407988 MM |
10023 | int len = 0; |
10024 | ||
10025 | if (section_name) | |
10026 | { | |
10027 | if (TREE_CODE (section_name) == STRING_CST) | |
10028 | { | |
10029 | name = TREE_STRING_POINTER (section_name); | |
10030 | len = TREE_STRING_LENGTH (section_name); | |
10031 | } | |
10032 | else | |
10033 | abort (); | |
10034 | } | |
10035 | ||
10036 | if ((size > 0 && size <= g_switch_value) | |
10037 | || (name | |
5f59ecb7 | 10038 | && ((len == sizeof (".sdata") - 1 |
3cb999d8 | 10039 | && strcmp (name, ".sdata") == 0) |
5f59ecb7 | 10040 | || (len == sizeof (".sdata2") - 1 |
3cb999d8 | 10041 | && strcmp (name, ".sdata2") == 0) |
5f59ecb7 | 10042 | || (len == sizeof (".sbss") - 1 |
3cb999d8 | 10043 | && strcmp (name, ".sbss") == 0) |
5f59ecb7 | 10044 | || (len == sizeof (".sbss2") - 1 |
3cb999d8 | 10045 | && strcmp (name, ".sbss2") == 0) |
5f59ecb7 | 10046 | || (len == sizeof (".PPC.EMB.sdata0") - 1 |
3cb999d8 | 10047 | && strcmp (name, ".PPC.EMB.sdata0") == 0) |
5f59ecb7 | 10048 | || (len == sizeof (".PPC.EMB.sbss0") - 1 |
3cb999d8 | 10049 | && strcmp (name, ".PPC.EMB.sbss0") == 0)))) |
d9407988 MM |
10050 | { |
10051 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
ff669a6c | 10052 | size_t len = strlen (XSTR (sym_ref, 0)); |
88c1e412 | 10053 | char *str = alloca (len + 2); |
ff669a6c | 10054 | |
ff669a6c RH |
10055 | str[0] = '@'; |
10056 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
88c1e412 | 10057 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1); |
d9407988 MM |
10058 | } |
10059 | } | |
10060 | } | |
10061 | ||
b91da81f | 10062 | #endif /* USING_ELFOS_H */ |
000034eb | 10063 | |
a6c2a102 | 10064 | \f |
000034eb | 10065 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
10066 | ADDR can be effectively incremented by incrementing REG. |
10067 | ||
10068 | r0 is special and we must not select it as an address | |
10069 | register by this routine since our caller will try to | |
10070 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
10071 | |
10072 | struct rtx_def * | |
10073 | find_addr_reg (addr) | |
10074 | rtx addr; | |
10075 | { | |
10076 | while (GET_CODE (addr) == PLUS) | |
10077 | { | |
02441cd6 JL |
10078 | if (GET_CODE (XEXP (addr, 0)) == REG |
10079 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 10080 | addr = XEXP (addr, 0); |
02441cd6 JL |
10081 | else if (GET_CODE (XEXP (addr, 1)) == REG |
10082 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
10083 | addr = XEXP (addr, 1); |
10084 | else if (CONSTANT_P (XEXP (addr, 0))) | |
10085 | addr = XEXP (addr, 1); | |
10086 | else if (CONSTANT_P (XEXP (addr, 1))) | |
10087 | addr = XEXP (addr, 0); | |
10088 | else | |
10089 | abort (); | |
10090 | } | |
02441cd6 | 10091 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
10092 | return addr; |
10093 | abort (); | |
10094 | } | |
10095 | ||
a6c2a102 DE |
10096 | void |
10097 | rs6000_fatal_bad_address (op) | |
10098 | rtx op; | |
10099 | { | |
10100 | fatal_insn ("bad address", op); | |
10101 | } | |
c8023011 MM |
10102 | |
10103 | /* Called to register all of our global variables with the garbage | |
10104 | collector. */ | |
10105 | ||
10106 | static void | |
10107 | rs6000_add_gc_roots () | |
10108 | { | |
10109 | ggc_add_rtx_root (&rs6000_compare_op0, 1); | |
10110 | ggc_add_rtx_root (&rs6000_compare_op1, 1); | |
9ebbca7d GK |
10111 | |
10112 | toc_hash_table = htab_create (1021, toc_hash_function, toc_hash_eq, NULL); | |
10113 | ggc_add_root (&toc_hash_table, 1, sizeof (toc_hash_table), | |
10114 | toc_hash_mark_table); | |
ee890fe2 SS |
10115 | |
10116 | #if TARGET_MACHO | |
10117 | machopic_add_gc_roots (); | |
10118 | #endif | |
10119 | } | |
10120 | ||
10121 | #if TARGET_MACHO | |
10122 | ||
10123 | #if 0 | |
10124 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
10125 | reference and a constant. */ | |
10126 | ||
10127 | int | |
10128 | symbolic_operand (op) | |
592696dd | 10129 | rtx op; |
ee890fe2 SS |
10130 | { |
10131 | switch (GET_CODE (op)) | |
10132 | { | |
10133 | case SYMBOL_REF: | |
10134 | case LABEL_REF: | |
10135 | return 1; | |
10136 | case CONST: | |
10137 | op = XEXP (op, 0); | |
10138 | return (GET_CODE (op) == SYMBOL_REF || | |
10139 | (GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
10140 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
10141 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
10142 | default: | |
10143 | return 0; | |
10144 | } | |
c8023011 | 10145 | } |
ee890fe2 SS |
10146 | #endif |
10147 | ||
10148 | #ifdef RS6000_LONG_BRANCH | |
10149 | ||
10150 | static tree stub_list = 0; | |
10151 | ||
10152 | /* ADD_COMPILER_STUB adds the compiler generated stub for handling | |
10153 | procedure calls to the linked list. */ | |
10154 | ||
10155 | void | |
10156 | add_compiler_stub (label_name, function_name, line_number) | |
10157 | tree label_name; | |
10158 | tree function_name; | |
10159 | int line_number; | |
10160 | { | |
10161 | tree stub = build_tree_list (function_name, label_name); | |
10162 | TREE_TYPE (stub) = build_int_2 (line_number, 0); | |
10163 | TREE_CHAIN (stub) = stub_list; | |
10164 | stub_list = stub; | |
10165 | } | |
10166 | ||
10167 | #define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB) | |
10168 | #define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB) | |
10169 | #define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB)) | |
10170 | ||
a4f6c312 SS |
10171 | /* OUTPUT_COMPILER_STUB outputs the compiler generated stub for |
10172 | handling procedure calls from the linked list and initializes the | |
10173 | linked list. */ | |
ee890fe2 | 10174 | |
a4f6c312 SS |
10175 | void |
10176 | output_compiler_stub () | |
ee890fe2 SS |
10177 | { |
10178 | char tmp_buf[256]; | |
10179 | char label_buf[256]; | |
10180 | char *label; | |
10181 | tree tmp_stub, stub; | |
10182 | ||
10183 | if (!flag_pic) | |
10184 | for (stub = stub_list; stub; stub = TREE_CHAIN (stub)) | |
10185 | { | |
10186 | fprintf (asm_out_file, | |
10187 | "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub))); | |
10188 | ||
10189 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) | |
10190 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) | |
10191 | fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub)); | |
10192 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ | |
10193 | ||
10194 | if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*') | |
10195 | strcpy (label_buf, | |
10196 | IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1); | |
10197 | else | |
10198 | { | |
10199 | label_buf[0] = '_'; | |
10200 | strcpy (label_buf+1, | |
10201 | IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))); | |
10202 | } | |
10203 | ||
10204 | strcpy (tmp_buf, "lis r12,hi16("); | |
10205 | strcat (tmp_buf, label_buf); | |
10206 | strcat (tmp_buf, ")\n\tori r12,r12,lo16("); | |
10207 | strcat (tmp_buf, label_buf); | |
10208 | strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr"); | |
10209 | output_asm_insn (tmp_buf, 0); | |
10210 | ||
10211 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) | |
10212 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) | |
10213 | fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub)); | |
10214 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ | |
10215 | } | |
10216 | ||
10217 | stub_list = 0; | |
10218 | } | |
10219 | ||
10220 | /* NO_PREVIOUS_DEF checks in the link list whether the function name is | |
10221 | already there or not. */ | |
10222 | ||
a4f6c312 SS |
10223 | int |
10224 | no_previous_def (function_name) | |
ee890fe2 SS |
10225 | tree function_name; |
10226 | { | |
10227 | tree stub; | |
10228 | for (stub = stub_list; stub; stub = TREE_CHAIN (stub)) | |
10229 | if (function_name == STUB_FUNCTION_NAME (stub)) | |
10230 | return 0; | |
10231 | return 1; | |
10232 | } | |
10233 | ||
10234 | /* GET_PREV_LABEL gets the label name from the previous definition of | |
10235 | the function. */ | |
10236 | ||
a4f6c312 SS |
10237 | tree |
10238 | get_prev_label (function_name) | |
ee890fe2 SS |
10239 | tree function_name; |
10240 | { | |
10241 | tree stub; | |
10242 | for (stub = stub_list; stub; stub = TREE_CHAIN (stub)) | |
10243 | if (function_name == STUB_FUNCTION_NAME (stub)) | |
10244 | return STUB_LABEL_NAME (stub); | |
10245 | return 0; | |
10246 | } | |
10247 | ||
10248 | /* INSN is either a function call or a millicode call. It may have an | |
10249 | unconditional jump in its delay slot. | |
10250 | ||
10251 | CALL_DEST is the routine we are calling. */ | |
10252 | ||
10253 | char * | |
10254 | output_call (insn, call_dest, operand_number) | |
10255 | rtx insn; | |
10256 | rtx call_dest; | |
10257 | int operand_number; | |
10258 | { | |
10259 | static char buf[256]; | |
10260 | if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic) | |
10261 | { | |
10262 | tree labelname; | |
10263 | tree funname = get_identifier (XSTR (call_dest, 0)); | |
10264 | ||
10265 | if (no_previous_def (funname)) | |
10266 | { | |
10267 | int line_number; | |
10268 | rtx label_rtx = gen_label_rtx (); | |
10269 | char *label_buf, temp_buf[256]; | |
10270 | ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L", | |
10271 | CODE_LABEL_NUMBER (label_rtx)); | |
10272 | label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf; | |
10273 | labelname = get_identifier (label_buf); | |
10274 | for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn)); | |
10275 | if (insn) | |
10276 | line_number = NOTE_LINE_NUMBER (insn); | |
10277 | add_compiler_stub (labelname, funname, line_number); | |
10278 | } | |
10279 | else | |
10280 | labelname = get_prev_label (funname); | |
10281 | ||
10282 | sprintf (buf, "jbsr %%z%d,%.246s", | |
10283 | operand_number, IDENTIFIER_POINTER (labelname)); | |
10284 | return buf; | |
10285 | } | |
10286 | else | |
10287 | { | |
10288 | sprintf (buf, "bl %%z%d", operand_number); | |
10289 | return buf; | |
10290 | } | |
10291 | } | |
10292 | ||
10293 | #endif /* RS6000_LONG_BRANCH */ | |
10294 | ||
10295 | #define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \ | |
10296 | do { \ | |
83182544 | 10297 | const char *const symbol_ = (SYMBOL); \ |
ee890fe2 SS |
10298 | char *buffer_ = (BUF); \ |
10299 | if (symbol_[0] == '"') \ | |
10300 | { \ | |
10301 | sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \ | |
10302 | } \ | |
10303 | else if (name_needs_quotes(symbol_)) \ | |
10304 | { \ | |
10305 | sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \ | |
10306 | } \ | |
10307 | else \ | |
10308 | { \ | |
10309 | sprintf(buffer_, "L%d$%s", (N), symbol_); \ | |
10310 | } \ | |
10311 | } while (0) | |
10312 | ||
10313 | ||
10314 | /* Generate PIC and indirect symbol stubs. */ | |
10315 | ||
10316 | void | |
10317 | machopic_output_stub (file, symb, stub) | |
10318 | FILE *file; | |
10319 | const char *symb, *stub; | |
10320 | { | |
10321 | unsigned int length; | |
a4f6c312 SS |
10322 | char *symbol_name, *lazy_ptr_name; |
10323 | char *local_label_0; | |
ee890fe2 SS |
10324 | static int label = 0; |
10325 | ||
df56a27f SS |
10326 | /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
10327 | STRIP_NAME_ENCODING (symb, symb); | |
10328 | ||
ee890fe2 SS |
10329 | label += 1; |
10330 | ||
ee890fe2 SS |
10331 | length = strlen (symb); |
10332 | symbol_name = alloca (length + 32); | |
10333 | GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); | |
10334 | ||
10335 | lazy_ptr_name = alloca (length + 32); | |
10336 | GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length); | |
10337 | ||
10338 | local_label_0 = alloca (length + 32); | |
10339 | GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0); | |
10340 | ||
ee890fe2 SS |
10341 | if (flag_pic == 2) |
10342 | machopic_picsymbol_stub_section (); | |
10343 | else | |
10344 | machopic_symbol_stub_section (); | |
10345 | ||
10346 | fprintf (file, "%s:\n", stub); | |
10347 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
10348 | ||
10349 | if (flag_pic == 2) | |
10350 | { | |
10351 | fprintf (file, "\tmflr r0\n"); | |
10352 | fprintf (file, "\tbcl 20,31,%s\n", local_label_0); | |
10353 | fprintf (file, "%s:\n\tmflr r11\n", local_label_0); | |
10354 | fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n", | |
10355 | lazy_ptr_name, local_label_0); | |
10356 | fprintf (file, "\tmtlr r0\n"); | |
10357 | fprintf (file, "\tlwz r12,lo16(%s-%s)(r11)\n", | |
10358 | lazy_ptr_name, local_label_0); | |
10359 | fprintf (file, "\tmtctr r12\n"); | |
10360 | fprintf (file, "\taddi r11,r11,lo16(%s-%s)\n", | |
10361 | lazy_ptr_name, local_label_0); | |
10362 | fprintf (file, "\tbctr\n"); | |
10363 | } | |
10364 | else | |
10365 | fprintf (file, "non-pure not supported\n"); | |
10366 | ||
10367 | machopic_lazy_symbol_ptr_section (); | |
10368 | fprintf (file, "%s:\n", lazy_ptr_name); | |
10369 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
10370 | fprintf (file, "\t.long dyld_stub_binding_helper\n"); | |
10371 | } | |
10372 | ||
10373 | /* Legitimize PIC addresses. If the address is already | |
10374 | position-independent, we return ORIG. Newly generated | |
10375 | position-independent addresses go into a reg. This is REG if non | |
10376 | zero, otherwise we allocate register(s) as necessary. */ | |
10377 | ||
c859cda6 | 10378 | #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000) |
ee890fe2 SS |
10379 | |
10380 | rtx | |
10381 | rs6000_machopic_legitimize_pic_address (orig, mode, reg) | |
10382 | rtx orig; | |
10383 | enum machine_mode mode; | |
10384 | rtx reg; | |
10385 | { | |
10386 | rtx base, offset; | |
10387 | ||
10388 | if (reg == NULL && ! reload_in_progress && ! reload_completed) | |
10389 | reg = gen_reg_rtx (Pmode); | |
10390 | ||
10391 | if (GET_CODE (orig) == CONST) | |
10392 | { | |
10393 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
10394 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
10395 | return orig; | |
10396 | ||
10397 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
10398 | { | |
a4f6c312 SS |
10399 | base = |
10400 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), | |
10401 | Pmode, reg); | |
10402 | offset = | |
10403 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), | |
10404 | Pmode, reg); | |
ee890fe2 SS |
10405 | } |
10406 | else | |
10407 | abort (); | |
10408 | ||
10409 | if (GET_CODE (offset) == CONST_INT) | |
10410 | { | |
10411 | if (SMALL_INT (offset)) | |
ed8908e7 | 10412 | return plus_constant (base, INTVAL (offset)); |
ee890fe2 SS |
10413 | else if (! reload_in_progress && ! reload_completed) |
10414 | offset = force_reg (Pmode, offset); | |
10415 | else | |
c859cda6 DJ |
10416 | { |
10417 | rtx mem = force_const_mem (Pmode, orig); | |
10418 | return machopic_legitimize_pic_address (mem, Pmode, reg); | |
10419 | } | |
ee890fe2 SS |
10420 | } |
10421 | return gen_rtx (PLUS, Pmode, base, offset); | |
10422 | } | |
10423 | ||
10424 | /* Fall back on generic machopic code. */ | |
10425 | return machopic_legitimize_pic_address (orig, mode, reg); | |
10426 | } | |
10427 | ||
10428 | /* This is just a placeholder to make linking work without having to | |
10429 | add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is | |
10430 | ever needed for Darwin (not too likely!) this would have to get a | |
10431 | real definition. */ | |
10432 | ||
10433 | void | |
10434 | toc_section () | |
10435 | { | |
10436 | } | |
10437 | ||
10438 | #endif /* TARGET_MACHO */ | |
7c262518 RH |
10439 | |
10440 | #if TARGET_ELF | |
10441 | static unsigned int | |
10442 | rs6000_elf_section_type_flags (decl, name, reloc) | |
10443 | tree decl; | |
10444 | const char *name; | |
10445 | int reloc; | |
10446 | { | |
10447 | unsigned int flags = default_section_type_flags (decl, name, reloc); | |
10448 | ||
270fc29b RH |
10449 | if (TARGET_RELOCATABLE) |
10450 | flags |= SECTION_WRITE; | |
7c262518 | 10451 | |
d0101753 | 10452 | return flags; |
7c262518 | 10453 | } |
d9f6800d RH |
10454 | |
10455 | /* Record an element in the table of global constructors. SYMBOL is | |
10456 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
10457 | between 0 and MAX_INIT_PRIORITY. | |
10458 | ||
10459 | This differs from default_named_section_asm_out_constructor in | |
10460 | that we have special handling for -mrelocatable. */ | |
10461 | ||
10462 | static void | |
10463 | rs6000_elf_asm_out_constructor (symbol, priority) | |
10464 | rtx symbol; | |
10465 | int priority; | |
10466 | { | |
10467 | const char *section = ".ctors"; | |
10468 | char buf[16]; | |
10469 | ||
10470 | if (priority != DEFAULT_INIT_PRIORITY) | |
10471 | { | |
10472 | sprintf (buf, ".ctors.%.5u", | |
10473 | /* Invert the numbering so the linker puts us in the proper | |
10474 | order; constructors are run from right to left, and the | |
10475 | linker sorts in increasing order. */ | |
10476 | MAX_INIT_PRIORITY - priority); | |
10477 | section = buf; | |
10478 | } | |
10479 | ||
715bdd29 RH |
10480 | named_section_flags (section, SECTION_WRITE); |
10481 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
10482 | |
10483 | if (TARGET_RELOCATABLE) | |
10484 | { | |
10485 | fputs ("\t.long (", asm_out_file); | |
10486 | output_addr_const (asm_out_file, symbol); | |
10487 | fputs (")@fixup\n", asm_out_file); | |
10488 | } | |
10489 | else | |
c8af3574 | 10490 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d RH |
10491 | } |
10492 | ||
10493 | static void | |
10494 | rs6000_elf_asm_out_destructor (symbol, priority) | |
10495 | rtx symbol; | |
10496 | int priority; | |
10497 | { | |
10498 | const char *section = ".dtors"; | |
10499 | char buf[16]; | |
10500 | ||
10501 | if (priority != DEFAULT_INIT_PRIORITY) | |
10502 | { | |
10503 | sprintf (buf, ".dtors.%.5u", | |
10504 | /* Invert the numbering so the linker puts us in the proper | |
10505 | order; constructors are run from right to left, and the | |
10506 | linker sorts in increasing order. */ | |
10507 | MAX_INIT_PRIORITY - priority); | |
10508 | section = buf; | |
10509 | } | |
10510 | ||
715bdd29 RH |
10511 | named_section_flags (section, SECTION_WRITE); |
10512 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
10513 | |
10514 | if (TARGET_RELOCATABLE) | |
10515 | { | |
10516 | fputs ("\t.long (", asm_out_file); | |
10517 | output_addr_const (asm_out_file, symbol); | |
10518 | fputs (")@fixup\n", asm_out_file); | |
10519 | } | |
10520 | else | |
c8af3574 | 10521 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d | 10522 | } |
7c262518 RH |
10523 | #endif |
10524 | ||
10525 | #ifdef OBJECT_FORMAT_COFF | |
10526 | static void | |
715bdd29 | 10527 | xcoff_asm_named_section (name, flags) |
7c262518 RH |
10528 | const char *name; |
10529 | unsigned int flags ATTRIBUTE_UNUSED; | |
7c262518 RH |
10530 | { |
10531 | fprintf (asm_out_file, "\t.csect %s\n", name); | |
10532 | } | |
10533 | #endif |