]>
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, |
d3c300d2 | 3 | 2000, 2001, 2002, 2003 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" |
4977bab6 ZW |
25 | #include "coretypes.h" |
26 | #include "tm.h" | |
9878760c RK |
27 | #include "rtl.h" |
28 | #include "regs.h" | |
29 | #include "hard-reg-set.h" | |
30 | #include "real.h" | |
31 | #include "insn-config.h" | |
32 | #include "conditions.h" | |
9878760c RK |
33 | #include "insn-attr.h" |
34 | #include "flags.h" | |
35 | #include "recog.h" | |
9878760c | 36 | #include "obstack.h" |
9b30bae2 | 37 | #include "tree.h" |
dfafc897 | 38 | #include "expr.h" |
2fc1c679 | 39 | #include "optabs.h" |
2a430ec1 | 40 | #include "except.h" |
a7df97e6 | 41 | #include "function.h" |
296b8152 | 42 | #include "output.h" |
d5fa86ba | 43 | #include "basic-block.h" |
d0101753 | 44 | #include "integrate.h" |
296b8152 | 45 | #include "toplev.h" |
c8023011 | 46 | #include "ggc.h" |
9ebbca7d GK |
47 | #include "hashtab.h" |
48 | #include "tm_p.h" | |
672a6f42 NB |
49 | #include "target.h" |
50 | #include "target-def.h" | |
3ac88239 | 51 | #include "langhooks.h" |
24ea750e | 52 | #include "reload.h" |
9b30bae2 | 53 | |
7509c759 MM |
54 | #ifndef TARGET_NO_PROTOTYPE |
55 | #define TARGET_NO_PROTOTYPE 0 | |
56 | #endif | |
57 | ||
9878760c RK |
58 | #define min(A,B) ((A) < (B) ? (A) : (B)) |
59 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
60 | ||
5248c961 RK |
61 | /* Target cpu type */ |
62 | ||
63 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
64 | struct rs6000_cpu_select rs6000_select[3] = |
65 | { | |
815cdc52 MM |
66 | /* switch name, tune arch */ |
67 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
68 | { (const char *)0, "-mcpu=", 1, 1 }, | |
69 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 70 | }; |
5248c961 | 71 | |
6fa3f289 ZW |
72 | /* Size of long double */ |
73 | const char *rs6000_long_double_size_string; | |
74 | int rs6000_long_double_type_size; | |
75 | ||
76 | /* Whether -mabi=altivec has appeared */ | |
77 | int rs6000_altivec_abi; | |
78 | ||
08b57fb3 AH |
79 | /* Whether VRSAVE instructions should be generated. */ |
80 | int rs6000_altivec_vrsave; | |
81 | ||
82 | /* String from -mvrsave= option. */ | |
83 | const char *rs6000_altivec_vrsave_string; | |
84 | ||
a3170dc6 AH |
85 | /* Nonzero if we want SPE ABI extensions. */ |
86 | int rs6000_spe_abi; | |
87 | ||
88 | /* Whether isel instructions should be generated. */ | |
89 | int rs6000_isel; | |
90 | ||
91 | /* Nonzero if we have FPRs. */ | |
92 | int rs6000_fprs = 1; | |
93 | ||
94 | /* String from -misel=. */ | |
95 | const char *rs6000_isel_string; | |
96 | ||
a0ab749a | 97 | /* Set to nonzero once AIX common-mode calls have been defined. */ |
bbfb86aa | 98 | static GTY(()) int common_mode_defined; |
c81bebd7 | 99 | |
0e5dbd9b DE |
100 | /* Private copy of original value of flag_pic for ABI_AIX. */ |
101 | static int rs6000_flag_pic; | |
102 | ||
9878760c RK |
103 | /* Save information from a "cmpxx" operation until the branch or scc is |
104 | emitted. */ | |
9878760c RK |
105 | rtx rs6000_compare_op0, rs6000_compare_op1; |
106 | int rs6000_compare_fp_p; | |
874a0744 | 107 | |
874a0744 MM |
108 | /* Label number of label created for -mrelocatable, to call to so we can |
109 | get the address of the GOT section */ | |
110 | int rs6000_pic_labelno; | |
c81bebd7 | 111 | |
b91da81f | 112 | #ifdef USING_ELFOS_H |
c81bebd7 | 113 | /* Which abi to adhere to */ |
815cdc52 | 114 | const char *rs6000_abi_name = RS6000_ABI_NAME; |
d9407988 MM |
115 | |
116 | /* Semantics of the small data area */ | |
117 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
118 | ||
119 | /* Which small data model to use */ | |
815cdc52 | 120 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
121 | |
122 | /* Counter for labels which are to be placed in .fixup. */ | |
123 | int fixuplabelno = 0; | |
874a0744 | 124 | #endif |
4697a36c | 125 | |
b6c9286a MM |
126 | /* ABI enumeration available for subtarget to use. */ |
127 | enum rs6000_abi rs6000_current_abi; | |
128 | ||
0ac081f6 AH |
129 | /* ABI string from -mabi= option. */ |
130 | const char *rs6000_abi_string; | |
131 | ||
38c1f2d7 | 132 | /* Debug flags */ |
815cdc52 | 133 | const char *rs6000_debug_name; |
38c1f2d7 MM |
134 | int rs6000_debug_stack; /* debug stack applications */ |
135 | int rs6000_debug_arg; /* debug argument handling */ | |
136 | ||
57ac7be9 AM |
137 | const char *rs6000_traceback_name; |
138 | static enum { | |
139 | traceback_default = 0, | |
140 | traceback_none, | |
141 | traceback_part, | |
142 | traceback_full | |
143 | } rs6000_traceback; | |
144 | ||
38c1f2d7 MM |
145 | /* Flag to say the TOC is initialized */ |
146 | int toc_initialized; | |
9ebbca7d | 147 | char toc_label_name[10]; |
38c1f2d7 | 148 | |
9ebbca7d GK |
149 | /* Alias set for saves and restores from the rs6000 stack. */ |
150 | static int rs6000_sr_alias_set; | |
c8023011 | 151 | |
a5c76ee6 ZW |
152 | /* Call distance, overridden by -mlongcall and #pragma longcall(1). |
153 | The only place that looks at this is rs6000_set_default_type_attributes; | |
154 | everywhere else should rely on the presence or absence of a longcall | |
155 | attribute on the function declaration. */ | |
156 | int rs6000_default_long_calls; | |
157 | const char *rs6000_longcall_switch; | |
158 | ||
a3170dc6 AH |
159 | struct builtin_description |
160 | { | |
161 | /* mask is not const because we're going to alter it below. This | |
162 | nonsense will go away when we rewrite the -march infrastructure | |
163 | to give us more target flag bits. */ | |
164 | unsigned int mask; | |
165 | const enum insn_code icode; | |
166 | const char *const name; | |
167 | const enum rs6000_builtins code; | |
168 | }; | |
169 | ||
4977bab6 | 170 | static bool rs6000_function_ok_for_sibcall PARAMS ((tree, tree)); |
9ebbca7d | 171 | static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT)); |
39a10a29 GK |
172 | static void validate_condition_mode |
173 | PARAMS ((enum rtx_code, enum machine_mode)); | |
174 | static rtx rs6000_generate_compare PARAMS ((enum rtx_code)); | |
e50f5f3d | 175 | static void rs6000_maybe_dead PARAMS ((rtx)); |
9ebbca7d GK |
176 | static void rs6000_emit_stack_tie PARAMS ((void)); |
177 | static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx)); | |
89e7058f AH |
178 | static void emit_frame_save PARAMS ((rtx, rtx, enum machine_mode, |
179 | unsigned int, int, int)); | |
a3170dc6 | 180 | static rtx gen_frame_mem_offset PARAMS ((enum machine_mode, rtx, int)); |
9ebbca7d GK |
181 | static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int)); |
182 | static unsigned rs6000_hash_constant PARAMS ((rtx)); | |
183 | static unsigned toc_hash_function PARAMS ((const void *)); | |
184 | static int toc_hash_eq PARAMS ((const void *, const void *)); | |
9ebbca7d | 185 | static int constant_pool_expr_1 PARAMS ((rtx, int *, int *)); |
e2500fed | 186 | static struct machine_function * rs6000_init_machine_status PARAMS ((void)); |
301d03af | 187 | static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int)); |
5add3202 | 188 | #ifdef HAVE_GAS_HIDDEN |
25fdb4dc | 189 | static void rs6000_assemble_visibility PARAMS ((tree, int)); |
5add3202 | 190 | #endif |
71f123ca | 191 | static int rs6000_ra_ever_killed PARAMS ((void)); |
91d231cb JM |
192 | static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *)); |
193 | const struct attribute_spec rs6000_attribute_table[]; | |
a5c76ee6 | 194 | static void rs6000_set_default_type_attributes PARAMS ((tree)); |
08c148a8 NB |
195 | static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT)); |
196 | static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT)); | |
3961e8fe RH |
197 | static void rs6000_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT, |
198 | HOST_WIDE_INT, tree)); | |
2bfcf297 DB |
199 | static rtx rs6000_emit_set_long_const PARAMS ((rtx, |
200 | HOST_WIDE_INT, HOST_WIDE_INT)); | |
7c262518 RH |
201 | #if TARGET_ELF |
202 | static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *, | |
203 | int)); | |
d9f6800d RH |
204 | static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int)); |
205 | static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int)); | |
ae46c4e0 | 206 | static void rs6000_elf_select_section PARAMS ((tree, int, |
5b71a4e7 | 207 | unsigned HOST_WIDE_INT)); |
ae46c4e0 | 208 | static void rs6000_elf_unique_section PARAMS ((tree, int)); |
b64a1b53 RH |
209 | static void rs6000_elf_select_rtx_section PARAMS ((enum machine_mode, rtx, |
210 | unsigned HOST_WIDE_INT)); | |
0e5dbd9b DE |
211 | static void rs6000_elf_encode_section_info PARAMS ((tree, int)) |
212 | ATTRIBUTE_UNUSED; | |
772c5265 | 213 | static const char *rs6000_elf_strip_name_encoding PARAMS ((const char *)); |
0e5dbd9b | 214 | static bool rs6000_elf_in_small_data_p PARAMS ((tree)); |
7c262518 | 215 | #endif |
cbaaba19 | 216 | #if TARGET_XCOFF |
b275d088 DE |
217 | static void rs6000_xcoff_asm_globalize_label PARAMS ((FILE *, const char *)); |
218 | static void rs6000_xcoff_asm_named_section PARAMS ((const char *, unsigned int)); | |
ae46c4e0 RH |
219 | static void rs6000_xcoff_select_section PARAMS ((tree, int, |
220 | unsigned HOST_WIDE_INT)); | |
221 | static void rs6000_xcoff_unique_section PARAMS ((tree, int)); | |
b64a1b53 RH |
222 | static void rs6000_xcoff_select_rtx_section PARAMS ((enum machine_mode, rtx, |
223 | unsigned HOST_WIDE_INT)); | |
772c5265 | 224 | static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *)); |
5add3202 | 225 | static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int)); |
7c262518 | 226 | #endif |
fb49053f RH |
227 | static void rs6000_xcoff_encode_section_info PARAMS ((tree, int)) |
228 | ATTRIBUTE_UNUSED; | |
2bcc50d0 | 229 | static bool rs6000_binds_local_p PARAMS ((tree)); |
3c50106f | 230 | static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *)); |
c237e94a ZW |
231 | static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int)); |
232 | static int rs6000_adjust_priority PARAMS ((rtx, int)); | |
233 | static int rs6000_issue_rate PARAMS ((void)); | |
234 | ||
6fa3f289 | 235 | static void rs6000_init_builtins PARAMS ((void)); |
92898235 AH |
236 | static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx)); |
237 | static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx)); | |
238 | static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx)); | |
0ac081f6 | 239 | static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int)); |
92898235 | 240 | static void altivec_init_builtins PARAMS ((void)); |
a3170dc6 AH |
241 | static void rs6000_common_init_builtins PARAMS ((void)); |
242 | ||
243 | static void enable_mask_for_builtins PARAMS ((struct builtin_description *, | |
244 | int, enum rs6000_builtins, | |
245 | enum rs6000_builtins)); | |
246 | static void spe_init_builtins PARAMS ((void)); | |
247 | static rtx spe_expand_builtin PARAMS ((tree, rtx, bool *)); | |
248 | static rtx spe_expand_predicate_builtin PARAMS ((enum insn_code, tree, rtx)); | |
249 | static rtx spe_expand_evsel_builtin PARAMS ((enum insn_code, tree, rtx)); | |
250 | static int rs6000_emit_int_cmove PARAMS ((rtx, rtx, rtx, rtx)); | |
251 | ||
92898235 | 252 | static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *)); |
3a9b8c7e AH |
253 | static rtx altivec_expand_ld_builtin PARAMS ((tree, rtx, bool *)); |
254 | static rtx altivec_expand_st_builtin PARAMS ((tree, rtx, bool *)); | |
255 | static rtx altivec_expand_dst_builtin PARAMS ((tree, rtx, bool *)); | |
100c4561 | 256 | static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx)); |
ae4b4a02 | 257 | static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx)); |
6525c0e7 | 258 | static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree)); |
0ac081f6 | 259 | static void rs6000_parse_abi_options PARAMS ((void)); |
08b57fb3 | 260 | static void rs6000_parse_vrsave_option PARAMS ((void)); |
a3170dc6 | 261 | static void rs6000_parse_isel_option PARAMS ((void)); |
00b960c7 AH |
262 | static int first_altivec_reg_to_save PARAMS ((void)); |
263 | static unsigned int compute_vrsave_mask PARAMS ((void)); | |
264 | static void is_altivec_return_reg PARAMS ((rtx, void *)); | |
9aa86737 AH |
265 | static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int)); |
266 | static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT)); | |
69ef87e2 | 267 | static int easy_vector_constant PARAMS ((rtx)); |
17211ab5 GK |
268 | |
269 | /* Hash table stuff for keeping track of TOC entries. */ | |
270 | ||
271 | struct toc_hash_struct GTY(()) | |
272 | { | |
273 | /* `key' will satisfy CONSTANT_P; in fact, it will satisfy | |
274 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */ | |
275 | rtx key; | |
276 | enum machine_mode key_mode; | |
277 | int labelno; | |
278 | }; | |
279 | ||
280 | static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table; | |
c81bebd7 MM |
281 | \f |
282 | /* Default register names. */ | |
283 | char rs6000_reg_names[][8] = | |
284 | { | |
802a0058 MM |
285 | "0", "1", "2", "3", "4", "5", "6", "7", |
286 | "8", "9", "10", "11", "12", "13", "14", "15", | |
287 | "16", "17", "18", "19", "20", "21", "22", "23", | |
288 | "24", "25", "26", "27", "28", "29", "30", "31", | |
289 | "0", "1", "2", "3", "4", "5", "6", "7", | |
290 | "8", "9", "10", "11", "12", "13", "14", "15", | |
291 | "16", "17", "18", "19", "20", "21", "22", "23", | |
292 | "24", "25", "26", "27", "28", "29", "30", "31", | |
293 | "mq", "lr", "ctr","ap", | |
294 | "0", "1", "2", "3", "4", "5", "6", "7", | |
0ac081f6 AH |
295 | "xer", |
296 | /* AltiVec registers. */ | |
0cd5e3a1 AH |
297 | "0", "1", "2", "3", "4", "5", "6", "7", |
298 | "8", "9", "10", "11", "12", "13", "14", "15", | |
299 | "16", "17", "18", "19", "20", "21", "22", "23", | |
300 | "24", "25", "26", "27", "28", "29", "30", "31", | |
59a4c851 AH |
301 | "vrsave", "vscr", |
302 | /* SPE registers. */ | |
303 | "spe_acc", "spefscr" | |
c81bebd7 MM |
304 | }; |
305 | ||
306 | #ifdef TARGET_REGNAMES | |
8b60264b | 307 | static const char alt_reg_names[][8] = |
c81bebd7 | 308 | { |
802a0058 MM |
309 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
310 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
311 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
312 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
313 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
314 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
315 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
316 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
317 | "mq", "lr", "ctr", "ap", | |
318 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
0ac081f6 | 319 | "xer", |
59a4c851 | 320 | /* AltiVec registers. */ |
0ac081f6 | 321 | "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7", |
59a4c851 AH |
322 | "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15", |
323 | "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23", | |
324 | "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31", | |
325 | "vrsave", "vscr", | |
326 | /* SPE registers. */ | |
327 | "spe_acc", "spefscr" | |
c81bebd7 MM |
328 | }; |
329 | #endif | |
9878760c | 330 | \f |
daf11973 MM |
331 | #ifndef MASK_STRICT_ALIGN |
332 | #define MASK_STRICT_ALIGN 0 | |
333 | #endif | |
3961e8fe RH |
334 | |
335 | /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */ | |
336 | #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO)) | |
672a6f42 NB |
337 | \f |
338 | /* Initialize the GCC target structure. */ | |
91d231cb JM |
339 | #undef TARGET_ATTRIBUTE_TABLE |
340 | #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table | |
a5c76ee6 ZW |
341 | #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
342 | #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes | |
daf11973 | 343 | |
301d03af RS |
344 | #undef TARGET_ASM_ALIGNED_DI_OP |
345 | #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP | |
346 | ||
347 | /* Default unaligned ops are only provided for ELF. Find the ops needed | |
348 | for non-ELF systems. */ | |
349 | #ifndef OBJECT_FORMAT_ELF | |
cbaaba19 | 350 | #if TARGET_XCOFF |
ae6c1efd | 351 | /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on |
301d03af RS |
352 | 64-bit targets. */ |
353 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
354 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2," | |
355 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
356 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4," | |
357 | #undef TARGET_ASM_UNALIGNED_DI_OP | |
358 | #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8," | |
359 | #else | |
360 | /* For Darwin. */ | |
361 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
362 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" | |
363 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
364 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" | |
365 | #endif | |
366 | #endif | |
367 | ||
368 | /* This hook deals with fixups for relocatable code and DI-mode objects | |
369 | in 64-bit code. */ | |
370 | #undef TARGET_ASM_INTEGER | |
371 | #define TARGET_ASM_INTEGER rs6000_assemble_integer | |
372 | ||
93638d7a AM |
373 | #ifdef HAVE_GAS_HIDDEN |
374 | #undef TARGET_ASM_ASSEMBLE_VISIBILITY | |
375 | #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility | |
376 | #endif | |
377 | ||
08c148a8 NB |
378 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
379 | #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue | |
380 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
381 | #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue | |
382 | ||
c237e94a ZW |
383 | #undef TARGET_SCHED_ISSUE_RATE |
384 | #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate | |
385 | #undef TARGET_SCHED_ADJUST_COST | |
386 | #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost | |
387 | #undef TARGET_SCHED_ADJUST_PRIORITY | |
388 | #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority | |
389 | ||
0ac081f6 AH |
390 | #undef TARGET_INIT_BUILTINS |
391 | #define TARGET_INIT_BUILTINS rs6000_init_builtins | |
392 | ||
393 | #undef TARGET_EXPAND_BUILTIN | |
394 | #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin | |
395 | ||
0e5dbd9b DE |
396 | #undef TARGET_BINDS_LOCAL_P |
397 | #define TARGET_BINDS_LOCAL_P rs6000_binds_local_p | |
398 | ||
3961e8fe RH |
399 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
400 | #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk | |
401 | ||
3961e8fe | 402 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
5b71a4e7 | 403 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true |
00b960c7 | 404 | |
4977bab6 ZW |
405 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
406 | #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall | |
407 | ||
3c50106f RH |
408 | #undef TARGET_RTX_COSTS |
409 | #define TARGET_RTX_COSTS rs6000_rtx_costs | |
dcefdf67 RH |
410 | #undef TARGET_ADDRESS_COST |
411 | #define TARGET_ADDRESS_COST hook_int_rtx_0 | |
3c50106f | 412 | |
f6897b10 | 413 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 414 | \f |
5248c961 RK |
415 | /* Override command line options. Mostly we process the processor |
416 | type and sometimes adjust other TARGET_ options. */ | |
417 | ||
418 | void | |
8e3f41e7 | 419 | rs6000_override_options (default_cpu) |
d330fd93 | 420 | const char *default_cpu; |
5248c961 | 421 | { |
c4d38ccb | 422 | size_t i, j; |
8e3f41e7 | 423 | struct rs6000_cpu_select *ptr; |
5248c961 | 424 | |
85638c0d RK |
425 | /* Simplify the entries below by making a mask for any POWER |
426 | variant and any PowerPC variant. */ | |
427 | ||
938937d8 | 428 | #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING) |
68c49ffa RK |
429 | #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \ |
430 | | MASK_PPC_GFXOPT | MASK_POWERPC64) | |
431 | #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT) | |
85638c0d | 432 | |
5248c961 RK |
433 | static struct ptt |
434 | { | |
8b60264b KG |
435 | const char *const name; /* Canonical processor name. */ |
436 | const enum processor_type processor; /* Processor type enum value. */ | |
437 | const int target_enable; /* Target flags to enable. */ | |
438 | const int target_disable; /* Target flags to disable. */ | |
439 | } const processor_target_table[] | |
cf27b467 MM |
440 | = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS, |
441 | POWER_MASKS | POWERPC_MASKS}, | |
db7f1e43 | 442 | {"power", PROCESSOR_POWER, |
938937d8 | 443 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 | 444 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
8e3f41e7 MM |
445 | {"power2", PROCESSOR_POWER, |
446 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
447 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, | |
c71791e0 DE |
448 | {"power3", PROCESSOR_PPC630, |
449 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
450 | POWER_MASKS | MASK_PPC_GPOPT}, | |
309323c2 DE |
451 | {"power4", PROCESSOR_POWER4, |
452 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
453 | POWER_MASKS | MASK_PPC_GPOPT}, | |
db7f1e43 RK |
454 | {"powerpc", PROCESSOR_POWERPC, |
455 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
68c49ffa | 456 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
3cb999d8 DE |
457 | {"powerpc64", PROCESSOR_POWERPC64, |
458 | MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS, | |
459 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
db7f1e43 | 460 | {"rios", PROCESSOR_RIOS1, |
938937d8 | 461 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
462 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
463 | {"rios1", PROCESSOR_RIOS1, | |
938937d8 | 464 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
465 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
466 | {"rsc", PROCESSOR_PPC601, | |
938937d8 | 467 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
468 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
469 | {"rsc1", PROCESSOR_PPC601, | |
938937d8 | 470 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
db7f1e43 RK |
471 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
472 | {"rios2", PROCESSOR_RIOS2, | |
938937d8 | 473 | MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2, |
db7f1e43 | 474 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
3cb999d8 DE |
475 | {"rs64a", PROCESSOR_RS64A, |
476 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
477 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
a3a1dbf6 MM |
478 | {"401", PROCESSOR_PPC403, |
479 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
480 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
49a0b204 | 481 | {"403", PROCESSOR_PPC403, |
daf11973 | 482 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN, |
49a0b204 | 483 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
d7a5e253 DE |
484 | {"405", PROCESSOR_PPC405, |
485 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
486 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
4977bab6 ZW |
487 | {"405f", PROCESSOR_PPC405, |
488 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
489 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
490 | {"505", PROCESSOR_MPCCORE, |
491 | MASK_POWERPC | MASK_NEW_MNEMONICS, | |
492 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 493 | {"601", PROCESSOR_PPC601, |
938937d8 | 494 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING, |
68c49ffa | 495 | MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64}, |
1ec26da6 | 496 | {"602", PROCESSOR_PPC603, |
cf27b467 MM |
497 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
498 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
5248c961 | 499 | {"603", PROCESSOR_PPC603, |
68c49ffa RK |
500 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
501 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a MM |
502 | {"603e", PROCESSOR_PPC603, |
503 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
504 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b5370a88 | 505 | {"ec603e", PROCESSOR_PPC603, |
a3a1dbf6 MM |
506 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
507 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 508 | {"604", PROCESSOR_PPC604, |
b6c9286a MM |
509 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
510 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
cac8ce95 | 511 | {"604e", PROCESSOR_PPC604e, |
07e6159a MM |
512 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
513 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a | 514 | {"620", PROCESSOR_PPC620, |
68c49ffa | 515 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
a260abc9 | 516 | POWER_MASKS | MASK_PPC_GPOPT}, |
3cb999d8 DE |
517 | {"630", PROCESSOR_PPC630, |
518 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
519 | POWER_MASKS | MASK_PPC_GPOPT}, | |
bef84347 VM |
520 | {"740", PROCESSOR_PPC750, |
521 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
522 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
523 | {"750", PROCESSOR_PPC750, | |
524 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
525 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
a4f6c312 SS |
526 | {"7400", PROCESSOR_PPC7400, |
527 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
528 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
529 | {"7450", PROCESSOR_PPC7450, | |
530 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
531 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
a3170dc6 AH |
532 | {"8540", PROCESSOR_PPC8540, |
533 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
534 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
07e6159a MM |
535 | {"801", PROCESSOR_MPCCORE, |
536 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
537 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
538 | {"821", PROCESSOR_MPCCORE, |
539 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
540 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
07e6159a MM |
541 | {"823", PROCESSOR_MPCCORE, |
542 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
543 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 MM |
544 | {"860", PROCESSOR_MPCCORE, |
545 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, | |
546 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}}; | |
5248c961 | 547 | |
ca7558fc | 548 | const size_t ptt_size = ARRAY_SIZE (processor_target_table); |
5248c961 | 549 | |
a4f6c312 SS |
550 | /* Save current -mmultiple/-mno-multiple status. */ |
551 | int multiple = TARGET_MULTIPLE; | |
552 | /* Save current -mstring/-mno-string status. */ | |
553 | int string = TARGET_STRING; | |
8a61d227 | 554 | |
a4f6c312 | 555 | /* Identify the processor type. */ |
8e3f41e7 | 556 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 557 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 558 | |
b6a1cbae | 559 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 560 | { |
8e3f41e7 MM |
561 | ptr = &rs6000_select[i]; |
562 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 563 | { |
8e3f41e7 MM |
564 | for (j = 0; j < ptt_size; j++) |
565 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
566 | { | |
567 | if (ptr->set_tune_p) | |
568 | rs6000_cpu = processor_target_table[j].processor; | |
569 | ||
570 | if (ptr->set_arch_p) | |
571 | { | |
572 | target_flags |= processor_target_table[j].target_enable; | |
573 | target_flags &= ~processor_target_table[j].target_disable; | |
574 | } | |
575 | break; | |
576 | } | |
577 | ||
4406229e | 578 | if (j == ptt_size) |
8e3f41e7 | 579 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
580 | } |
581 | } | |
8a61d227 | 582 | |
a3170dc6 AH |
583 | if (rs6000_cpu == PROCESSOR_PPC8540) |
584 | rs6000_isel = 1; | |
585 | ||
dff9f1b6 DE |
586 | /* If we are optimizing big endian systems for space, use the load/store |
587 | multiple and string instructions. */ | |
ef792183 | 588 | if (BYTES_BIG_ENDIAN && optimize_size) |
dff9f1b6 | 589 | target_flags |= MASK_MULTIPLE | MASK_STRING; |
ef792183 | 590 | |
8a61d227 MM |
591 | /* If -mmultiple or -mno-multiple was explicitly used, don't |
592 | override with the processor default */ | |
b21fb038 | 593 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
8a61d227 | 594 | target_flags = (target_flags & ~MASK_MULTIPLE) | multiple; |
7e69e155 | 595 | |
a4f6c312 SS |
596 | /* If -mstring or -mno-string was explicitly used, don't override |
597 | with the processor default. */ | |
b21fb038 | 598 | if ((target_flags_explicit & MASK_STRING) != 0) |
1f5515bf | 599 | target_flags = (target_flags & ~MASK_STRING) | string; |
938937d8 | 600 | |
a4f6c312 SS |
601 | /* Don't allow -mmultiple or -mstring on little endian systems |
602 | unless the cpu is a 750, because the hardware doesn't support the | |
603 | instructions used in little endian mode, and causes an alignment | |
604 | trap. The 750 does not cause an alignment trap (except when the | |
605 | target is unaligned). */ | |
bef84347 | 606 | |
b21fb038 | 607 | if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
608 | { |
609 | if (TARGET_MULTIPLE) | |
610 | { | |
611 | target_flags &= ~MASK_MULTIPLE; | |
b21fb038 | 612 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
7e69e155 MM |
613 | warning ("-mmultiple is not supported on little endian systems"); |
614 | } | |
615 | ||
616 | if (TARGET_STRING) | |
617 | { | |
618 | target_flags &= ~MASK_STRING; | |
b21fb038 | 619 | if ((target_flags_explicit & MASK_STRING) != 0) |
938937d8 | 620 | warning ("-mstring is not supported on little endian systems"); |
7e69e155 MM |
621 | } |
622 | } | |
3933e0e1 | 623 | |
ee2ca2a2 | 624 | if (flag_pic != 0 && DEFAULT_ABI == ABI_AIX) |
a260abc9 | 625 | { |
0e5dbd9b | 626 | rs6000_flag_pic = flag_pic; |
ee2ca2a2 | 627 | flag_pic = 0; |
a260abc9 DE |
628 | } |
629 | ||
c72bfda7 SS |
630 | /* For Darwin, always silently make -fpic and -fPIC identical. */ |
631 | if (flag_pic == 1 && DEFAULT_ABI == ABI_DARWIN) | |
632 | flag_pic = 2; | |
633 | ||
38c1f2d7 MM |
634 | /* Set debug flags */ |
635 | if (rs6000_debug_name) | |
636 | { | |
bfc79d3b | 637 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 638 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 639 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 640 | rs6000_debug_stack = 1; |
bfc79d3b | 641 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
642 | rs6000_debug_arg = 1; |
643 | else | |
c725bd79 | 644 | error ("unknown -mdebug-%s switch", rs6000_debug_name); |
38c1f2d7 MM |
645 | } |
646 | ||
57ac7be9 AM |
647 | if (rs6000_traceback_name) |
648 | { | |
649 | if (! strncmp (rs6000_traceback_name, "full", 4)) | |
650 | rs6000_traceback = traceback_full; | |
651 | else if (! strncmp (rs6000_traceback_name, "part", 4)) | |
652 | rs6000_traceback = traceback_part; | |
653 | else if (! strncmp (rs6000_traceback_name, "no", 2)) | |
654 | rs6000_traceback = traceback_none; | |
655 | else | |
656 | error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'", | |
657 | rs6000_traceback_name); | |
658 | } | |
659 | ||
6fa3f289 ZW |
660 | /* Set size of long double */ |
661 | rs6000_long_double_type_size = 64; | |
662 | if (rs6000_long_double_size_string) | |
663 | { | |
664 | char *tail; | |
665 | int size = strtol (rs6000_long_double_size_string, &tail, 10); | |
666 | if (*tail != '\0' || (size != 64 && size != 128)) | |
667 | error ("Unknown switch -mlong-double-%s", | |
668 | rs6000_long_double_size_string); | |
669 | else | |
670 | rs6000_long_double_type_size = size; | |
671 | } | |
672 | ||
0ac081f6 AH |
673 | /* Handle -mabi= options. */ |
674 | rs6000_parse_abi_options (); | |
675 | ||
08b57fb3 AH |
676 | /* Handle -mvrsave= option. */ |
677 | rs6000_parse_vrsave_option (); | |
678 | ||
a3170dc6 AH |
679 | /* Handle -misel= option. */ |
680 | rs6000_parse_isel_option (); | |
681 | ||
a7ae18e2 AH |
682 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
683 | SUBTARGET_OVERRIDE_OPTIONS; | |
684 | #endif | |
685 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS | |
686 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
687 | #endif | |
688 | ||
a5c76ee6 ZW |
689 | /* Handle -m(no-)longcall option. This is a bit of a cheap hack, |
690 | using TARGET_OPTIONS to handle a toggle switch, but we're out of | |
691 | bits in target_flags so TARGET_SWITCHES cannot be used. | |
692 | Assumption here is that rs6000_longcall_switch points into the | |
693 | text of the complete option, rather than being a copy, so we can | |
694 | scan back for the presence or absence of the no- modifier. */ | |
695 | if (rs6000_longcall_switch) | |
696 | { | |
697 | const char *base = rs6000_longcall_switch; | |
698 | while (base[-1] != 'm') base--; | |
699 | ||
700 | if (*rs6000_longcall_switch != '\0') | |
701 | error ("invalid option `%s'", base); | |
702 | rs6000_default_long_calls = (base[0] != 'n'); | |
703 | } | |
704 | ||
c81bebd7 | 705 | #ifdef TARGET_REGNAMES |
a4f6c312 SS |
706 | /* If the user desires alternate register names, copy in the |
707 | alternate names now. */ | |
c81bebd7 | 708 | if (TARGET_REGNAMES) |
4e135bdd | 709 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
710 | #endif |
711 | ||
6fa3f289 ZW |
712 | /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined. |
713 | If -maix-struct-return or -msvr4-struct-return was explicitly | |
714 | used, don't override with the ABI default. */ | |
b21fb038 | 715 | if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0) |
6fa3f289 ZW |
716 | { |
717 | if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET) | |
718 | target_flags = (target_flags & ~MASK_AIX_STRUCT_RET); | |
719 | else | |
720 | target_flags |= MASK_AIX_STRUCT_RET; | |
721 | } | |
722 | ||
fcce224d DE |
723 | if (TARGET_LONG_DOUBLE_128 |
724 | && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)) | |
725 | real_format_for_mode[TFmode - QFmode] = &ibm_extended_format; | |
726 | ||
9ebbca7d GK |
727 | /* Allocate an alias set for register saves & restores from stack. */ |
728 | rs6000_sr_alias_set = new_alias_set (); | |
729 | ||
730 | if (TARGET_TOC) | |
731 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); | |
71f123ca | 732 | |
301d03af RS |
733 | /* We can only guarantee the availability of DI pseudo-ops when |
734 | assembling for 64-bit targets. */ | |
ae6c1efd | 735 | if (!TARGET_64BIT) |
301d03af RS |
736 | { |
737 | targetm.asm_out.aligned_op.di = NULL; | |
738 | targetm.asm_out.unaligned_op.di = NULL; | |
739 | } | |
740 | ||
71f123ca FS |
741 | /* Arrange to save and restore machine status around nested functions. */ |
742 | init_machine_status = rs6000_init_machine_status; | |
5248c961 | 743 | } |
5accd822 | 744 | |
a3170dc6 AH |
745 | /* Handle -misel= option. */ |
746 | static void | |
747 | rs6000_parse_isel_option () | |
748 | { | |
749 | if (rs6000_isel_string == 0) | |
750 | return; | |
751 | else if (! strcmp (rs6000_isel_string, "yes")) | |
752 | rs6000_isel = 1; | |
753 | else if (! strcmp (rs6000_isel_string, "no")) | |
754 | rs6000_isel = 0; | |
755 | else | |
756 | error ("unknown -misel= option specified: '%s'", | |
757 | rs6000_isel_string); | |
758 | } | |
759 | ||
08b57fb3 AH |
760 | /* Handle -mvrsave= options. */ |
761 | static void | |
762 | rs6000_parse_vrsave_option () | |
763 | { | |
764 | /* Generate VRSAVE instructions by default. */ | |
765 | if (rs6000_altivec_vrsave_string == 0 | |
766 | || ! strcmp (rs6000_altivec_vrsave_string, "yes")) | |
767 | rs6000_altivec_vrsave = 1; | |
768 | else if (! strcmp (rs6000_altivec_vrsave_string, "no")) | |
769 | rs6000_altivec_vrsave = 0; | |
770 | else | |
771 | error ("unknown -mvrsave= option specified: '%s'", | |
772 | rs6000_altivec_vrsave_string); | |
773 | } | |
774 | ||
0ac081f6 | 775 | /* Handle -mabi= options. */ |
00b960c7 AH |
776 | static void |
777 | rs6000_parse_abi_options () | |
0ac081f6 AH |
778 | { |
779 | if (rs6000_abi_string == 0) | |
780 | return; | |
781 | else if (! strcmp (rs6000_abi_string, "altivec")) | |
6fa3f289 | 782 | rs6000_altivec_abi = 1; |
76a773f3 AH |
783 | else if (! strcmp (rs6000_abi_string, "no-altivec")) |
784 | rs6000_altivec_abi = 0; | |
a3170dc6 | 785 | else if (! strcmp (rs6000_abi_string, "spe")) |
01f4962d NS |
786 | { |
787 | rs6000_spe_abi = 1; | |
788 | if (!TARGET_SPE_ABI) | |
789 | error ("not configured for ABI: '%s'", rs6000_abi_string); | |
790 | } | |
791 | ||
a3170dc6 AH |
792 | else if (! strcmp (rs6000_abi_string, "no-spe")) |
793 | rs6000_spe_abi = 0; | |
0ac081f6 | 794 | else |
c725bd79 | 795 | error ("unknown ABI specified: '%s'", rs6000_abi_string); |
0ac081f6 AH |
796 | } |
797 | ||
5accd822 DE |
798 | void |
799 | optimization_options (level, size) | |
e2c953b6 | 800 | int level ATTRIBUTE_UNUSED; |
5accd822 DE |
801 | int size ATTRIBUTE_UNUSED; |
802 | { | |
5accd822 | 803 | } |
3cfa4909 MM |
804 | \f |
805 | /* Do anything needed at the start of the asm file. */ | |
806 | ||
807 | void | |
808 | rs6000_file_start (file, default_cpu) | |
809 | FILE *file; | |
d330fd93 | 810 | const char *default_cpu; |
3cfa4909 | 811 | { |
c4d38ccb | 812 | size_t i; |
3cfa4909 | 813 | char buffer[80]; |
d330fd93 | 814 | const char *start = buffer; |
3cfa4909 MM |
815 | struct rs6000_cpu_select *ptr; |
816 | ||
817 | if (flag_verbose_asm) | |
818 | { | |
819 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
820 | rs6000_select[0].string = default_cpu; | |
821 | ||
b6a1cbae | 822 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
823 | { |
824 | ptr = &rs6000_select[i]; | |
825 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
826 | { | |
827 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
828 | start = ""; | |
829 | } | |
830 | } | |
831 | ||
b91da81f | 832 | #ifdef USING_ELFOS_H |
3cfa4909 MM |
833 | switch (rs6000_sdata) |
834 | { | |
835 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
836 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
837 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
838 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
839 | } | |
840 | ||
841 | if (rs6000_sdata && g_switch_value) | |
842 | { | |
843 | fprintf (file, "%s -G %d", start, g_switch_value); | |
844 | start = ""; | |
845 | } | |
846 | #endif | |
847 | ||
848 | if (*start == '\0') | |
949ea356 | 849 | putc ('\n', file); |
3cfa4909 MM |
850 | } |
851 | } | |
5248c961 | 852 | \f |
a0ab749a | 853 | /* Return nonzero if this function is known to have a null epilogue. */ |
9878760c RK |
854 | |
855 | int | |
856 | direct_return () | |
857 | { | |
4697a36c MM |
858 | if (reload_completed) |
859 | { | |
860 | rs6000_stack_t *info = rs6000_stack_info (); | |
861 | ||
862 | if (info->first_gp_reg_save == 32 | |
863 | && info->first_fp_reg_save == 64 | |
00b960c7 | 864 | && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1 |
c81fc13e DE |
865 | && ! info->lr_save_p |
866 | && ! info->cr_save_p | |
00b960c7 | 867 | && info->vrsave_mask == 0 |
c81fc13e | 868 | && ! info->push_p) |
4697a36c MM |
869 | return 1; |
870 | } | |
871 | ||
872 | return 0; | |
9878760c RK |
873 | } |
874 | ||
875 | /* Returns 1 always. */ | |
876 | ||
877 | int | |
878 | any_operand (op, mode) | |
592696dd | 879 | rtx op ATTRIBUTE_UNUSED; |
296b8152 | 880 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
881 | { |
882 | return 1; | |
883 | } | |
884 | ||
a4f6c312 | 885 | /* Returns 1 if op is the count register. */ |
38c1f2d7 | 886 | int |
a4f6c312 | 887 | count_register_operand (op, mode) |
592696dd | 888 | rtx op; |
296b8152 | 889 | enum machine_mode mode ATTRIBUTE_UNUSED; |
b6c9286a MM |
890 | { |
891 | if (GET_CODE (op) != REG) | |
892 | return 0; | |
893 | ||
894 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
895 | return 1; | |
896 | ||
897 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
898 | return 1; | |
899 | ||
900 | return 0; | |
901 | } | |
902 | ||
0ec4e2a8 AH |
903 | /* Returns 1 if op is an altivec register. */ |
904 | int | |
905 | altivec_register_operand (op, mode) | |
906 | rtx op; | |
907 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
908 | { | |
909 | ||
910 | return (register_operand (op, mode) | |
911 | && (GET_CODE (op) != REG | |
912 | || REGNO (op) > FIRST_PSEUDO_REGISTER | |
913 | || ALTIVEC_REGNO_P (REGNO (op)))); | |
914 | } | |
915 | ||
38c1f2d7 | 916 | int |
a4f6c312 | 917 | xer_operand (op, mode) |
592696dd | 918 | rtx op; |
296b8152 | 919 | enum machine_mode mode ATTRIBUTE_UNUSED; |
802a0058 MM |
920 | { |
921 | if (GET_CODE (op) != REG) | |
922 | return 0; | |
923 | ||
9ebbca7d | 924 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
925 | return 1; |
926 | ||
802a0058 MM |
927 | return 0; |
928 | } | |
929 | ||
c859cda6 | 930 | /* Return 1 if OP is a signed 8-bit constant. Int multiplication |
6f317ef3 | 931 | by such constants completes more quickly. */ |
c859cda6 DJ |
932 | |
933 | int | |
934 | s8bit_cint_operand (op, mode) | |
935 | rtx op; | |
936 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
937 | { | |
938 | return ( GET_CODE (op) == CONST_INT | |
939 | && (INTVAL (op) >= -128 && INTVAL (op) <= 127)); | |
940 | } | |
941 | ||
9878760c RK |
942 | /* Return 1 if OP is a constant that can fit in a D field. */ |
943 | ||
944 | int | |
945 | short_cint_operand (op, mode) | |
592696dd | 946 | rtx op; |
296b8152 | 947 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 948 | { |
5f59ecb7 DE |
949 | return (GET_CODE (op) == CONST_INT |
950 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
951 | } |
952 | ||
5519a4f9 | 953 | /* Similar for an unsigned D field. */ |
9878760c RK |
954 | |
955 | int | |
956 | u_short_cint_operand (op, mode) | |
592696dd | 957 | rtx op; |
296b8152 | 958 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 959 | { |
19684119 | 960 | return (GET_CODE (op) == CONST_INT |
c1f11548 | 961 | && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K')); |
9878760c RK |
962 | } |
963 | ||
dcfedcd0 RK |
964 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
965 | ||
966 | int | |
967 | non_short_cint_operand (op, mode) | |
592696dd | 968 | rtx op; |
296b8152 | 969 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
970 | { |
971 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 972 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
973 | } |
974 | ||
2bfcf297 DB |
975 | /* Returns 1 if OP is a CONST_INT that is a positive value |
976 | and an exact power of 2. */ | |
977 | ||
978 | int | |
979 | exact_log2_cint_operand (op, mode) | |
592696dd | 980 | rtx op; |
2bfcf297 DB |
981 | enum machine_mode mode ATTRIBUTE_UNUSED; |
982 | { | |
983 | return (GET_CODE (op) == CONST_INT | |
984 | && INTVAL (op) > 0 | |
985 | && exact_log2 (INTVAL (op)) >= 0); | |
986 | } | |
987 | ||
9878760c RK |
988 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
989 | ctr, or lr). */ | |
990 | ||
991 | int | |
cd2b37d9 | 992 | gpc_reg_operand (op, mode) |
592696dd | 993 | rtx op; |
9878760c RK |
994 | enum machine_mode mode; |
995 | { | |
996 | return (register_operand (op, mode) | |
802a0058 | 997 | && (GET_CODE (op) != REG |
9ebbca7d GK |
998 | || (REGNO (op) >= ARG_POINTER_REGNUM |
999 | && !XER_REGNO_P (REGNO (op))) | |
1000 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
1001 | } |
1002 | ||
1003 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
1004 | CR field. */ | |
1005 | ||
1006 | int | |
1007 | cc_reg_operand (op, mode) | |
592696dd | 1008 | rtx op; |
9878760c RK |
1009 | enum machine_mode mode; |
1010 | { | |
1011 | return (register_operand (op, mode) | |
1012 | && (GET_CODE (op) != REG | |
1013 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1014 | || CR_REGNO_P (REGNO (op)))); | |
1015 | } | |
1016 | ||
815cdc52 MM |
1017 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
1018 | CR field that isn't CR0. */ | |
1019 | ||
1020 | int | |
1021 | cc_reg_not_cr0_operand (op, mode) | |
592696dd | 1022 | rtx op; |
815cdc52 MM |
1023 | enum machine_mode mode; |
1024 | { | |
1025 | return (register_operand (op, mode) | |
1026 | && (GET_CODE (op) != REG | |
1027 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1028 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
1029 | } | |
1030 | ||
a4f6c312 SS |
1031 | /* Returns 1 if OP is either a constant integer valid for a D-field or |
1032 | a non-special register. If a register, it must be in the proper | |
1033 | mode unless MODE is VOIDmode. */ | |
9878760c RK |
1034 | |
1035 | int | |
1036 | reg_or_short_operand (op, mode) | |
592696dd | 1037 | rtx op; |
9878760c RK |
1038 | enum machine_mode mode; |
1039 | { | |
f5a28898 | 1040 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1041 | } |
1042 | ||
a4f6c312 SS |
1043 | /* Similar, except check if the negation of the constant would be |
1044 | valid for a D-field. */ | |
9878760c RK |
1045 | |
1046 | int | |
1047 | reg_or_neg_short_operand (op, mode) | |
592696dd | 1048 | rtx op; |
9878760c RK |
1049 | enum machine_mode mode; |
1050 | { | |
1051 | if (GET_CODE (op) == CONST_INT) | |
1052 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'); | |
1053 | ||
cd2b37d9 | 1054 | return gpc_reg_operand (op, mode); |
9878760c RK |
1055 | } |
1056 | ||
768070a0 TR |
1057 | /* Returns 1 if OP is either a constant integer valid for a DS-field or |
1058 | a non-special register. If a register, it must be in the proper | |
1059 | mode unless MODE is VOIDmode. */ | |
1060 | ||
1061 | int | |
1062 | reg_or_aligned_short_operand (op, mode) | |
1063 | rtx op; | |
1064 | enum machine_mode mode; | |
1065 | { | |
1066 | if (gpc_reg_operand (op, mode)) | |
1067 | return 1; | |
1068 | else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3)) | |
1069 | return 1; | |
1070 | ||
1071 | return 0; | |
1072 | } | |
1073 | ||
1074 | ||
a4f6c312 SS |
1075 | /* Return 1 if the operand is either a register or an integer whose |
1076 | high-order 16 bits are zero. */ | |
9878760c RK |
1077 | |
1078 | int | |
1079 | reg_or_u_short_operand (op, mode) | |
592696dd | 1080 | rtx op; |
9878760c RK |
1081 | enum machine_mode mode; |
1082 | { | |
e675f625 | 1083 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1084 | } |
1085 | ||
1086 | /* Return 1 is the operand is either a non-special register or ANY | |
1087 | constant integer. */ | |
1088 | ||
1089 | int | |
1090 | reg_or_cint_operand (op, mode) | |
592696dd | 1091 | rtx op; |
9878760c RK |
1092 | enum machine_mode mode; |
1093 | { | |
a4f6c312 | 1094 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
f6bf7de2 DE |
1095 | } |
1096 | ||
1097 | /* Return 1 is the operand is either a non-special register or ANY | |
1098 | 32-bit signed constant integer. */ | |
1099 | ||
1100 | int | |
1101 | reg_or_arith_cint_operand (op, mode) | |
592696dd | 1102 | rtx op; |
f6bf7de2 DE |
1103 | enum machine_mode mode; |
1104 | { | |
a4f6c312 SS |
1105 | return (gpc_reg_operand (op, mode) |
1106 | || (GET_CODE (op) == CONST_INT | |
f6bf7de2 | 1107 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
1108 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) |
1109 | < (unsigned HOST_WIDE_INT) 0x100000000ll) | |
f6bf7de2 | 1110 | #endif |
a4f6c312 | 1111 | )); |
9878760c RK |
1112 | } |
1113 | ||
2bfcf297 DB |
1114 | /* Return 1 is the operand is either a non-special register or a 32-bit |
1115 | signed constant integer valid for 64-bit addition. */ | |
1116 | ||
1117 | int | |
1118 | reg_or_add_cint64_operand (op, mode) | |
592696dd | 1119 | rtx op; |
2bfcf297 DB |
1120 | enum machine_mode mode; |
1121 | { | |
a4f6c312 SS |
1122 | return (gpc_reg_operand (op, mode) |
1123 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1124 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1125 | && INTVAL (op) < 0x7fff8000 |
a65c591c | 1126 | #else |
a4f6c312 SS |
1127 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) |
1128 | < 0x100000000ll) | |
2bfcf297 | 1129 | #endif |
a4f6c312 | 1130 | )); |
2bfcf297 DB |
1131 | } |
1132 | ||
1133 | /* Return 1 is the operand is either a non-special register or a 32-bit | |
1134 | signed constant integer valid for 64-bit subtraction. */ | |
1135 | ||
1136 | int | |
1137 | reg_or_sub_cint64_operand (op, mode) | |
592696dd | 1138 | rtx op; |
2bfcf297 DB |
1139 | enum machine_mode mode; |
1140 | { | |
a4f6c312 SS |
1141 | return (gpc_reg_operand (op, mode) |
1142 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1143 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1144 | && (- INTVAL (op)) < 0x7fff8000 |
a65c591c | 1145 | #else |
a4f6c312 SS |
1146 | && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000) |
1147 | < 0x100000000ll) | |
2bfcf297 | 1148 | #endif |
a4f6c312 | 1149 | )); |
2bfcf297 DB |
1150 | } |
1151 | ||
9ebbca7d GK |
1152 | /* Return 1 is the operand is either a non-special register or ANY |
1153 | 32-bit unsigned constant integer. */ | |
1154 | ||
1155 | int | |
1d328b19 | 1156 | reg_or_logical_cint_operand (op, mode) |
592696dd | 1157 | rtx op; |
9ebbca7d GK |
1158 | enum machine_mode mode; |
1159 | { | |
1d328b19 GK |
1160 | if (GET_CODE (op) == CONST_INT) |
1161 | { | |
1162 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
1163 | { | |
1164 | if (GET_MODE_BITSIZE (mode) <= 32) | |
a4f6c312 | 1165 | abort (); |
1d328b19 GK |
1166 | |
1167 | if (INTVAL (op) < 0) | |
1168 | return 0; | |
1169 | } | |
1170 | ||
1171 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 1172 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
1173 | } |
1174 | else if (GET_CODE (op) == CONST_DOUBLE) | |
1175 | { | |
1176 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
1177 | || mode != DImode) | |
a4f6c312 | 1178 | abort (); |
1d328b19 GK |
1179 | |
1180 | return CONST_DOUBLE_HIGH (op) == 0; | |
1181 | } | |
1182 | else | |
1183 | return gpc_reg_operand (op, mode); | |
9ebbca7d GK |
1184 | } |
1185 | ||
51d3e7d6 | 1186 | /* Return 1 if the operand is an operand that can be loaded via the GOT. */ |
766a866c MM |
1187 | |
1188 | int | |
1189 | got_operand (op, mode) | |
592696dd | 1190 | rtx op; |
296b8152 | 1191 | enum machine_mode mode ATTRIBUTE_UNUSED; |
766a866c MM |
1192 | { |
1193 | return (GET_CODE (op) == SYMBOL_REF | |
1194 | || GET_CODE (op) == CONST | |
1195 | || GET_CODE (op) == LABEL_REF); | |
1196 | } | |
1197 | ||
38c1f2d7 MM |
1198 | /* Return 1 if the operand is a simple references that can be loaded via |
1199 | the GOT (labels involving addition aren't allowed). */ | |
1200 | ||
1201 | int | |
1202 | got_no_const_operand (op, mode) | |
592696dd | 1203 | rtx op; |
296b8152 | 1204 | enum machine_mode mode ATTRIBUTE_UNUSED; |
38c1f2d7 MM |
1205 | { |
1206 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
1207 | } | |
1208 | ||
4e74d8ec MM |
1209 | /* Return the number of instructions it takes to form a constant in an |
1210 | integer register. */ | |
1211 | ||
1212 | static int | |
1213 | num_insns_constant_wide (value) | |
1214 | HOST_WIDE_INT value; | |
1215 | { | |
1216 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 1217 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
1218 | return 1; |
1219 | ||
4e74d8ec | 1220 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 1221 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
1222 | return 1; |
1223 | ||
5f59ecb7 | 1224 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 1225 | else if (TARGET_POWERPC64) |
4e74d8ec | 1226 | { |
a65c591c DE |
1227 | HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000; |
1228 | HOST_WIDE_INT high = value >> 31; | |
4e74d8ec | 1229 | |
a65c591c | 1230 | if (high == 0 || high == -1) |
4e74d8ec MM |
1231 | return 2; |
1232 | ||
a65c591c | 1233 | high >>= 1; |
4e74d8ec | 1234 | |
a65c591c | 1235 | if (low == 0) |
4e74d8ec | 1236 | return num_insns_constant_wide (high) + 1; |
4e74d8ec MM |
1237 | else |
1238 | return (num_insns_constant_wide (high) | |
e396202a | 1239 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
1240 | } |
1241 | #endif | |
1242 | ||
1243 | else | |
1244 | return 2; | |
1245 | } | |
1246 | ||
1247 | int | |
1248 | num_insns_constant (op, mode) | |
1249 | rtx op; | |
1250 | enum machine_mode mode; | |
1251 | { | |
4e74d8ec | 1252 | if (GET_CODE (op) == CONST_INT) |
0d30d435 DE |
1253 | { |
1254 | #if HOST_BITS_PER_WIDE_INT == 64 | |
4e2c1c44 DE |
1255 | if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1 |
1256 | && mask64_operand (op, mode)) | |
0d30d435 DE |
1257 | return 2; |
1258 | else | |
1259 | #endif | |
1260 | return num_insns_constant_wide (INTVAL (op)); | |
1261 | } | |
4e74d8ec | 1262 | |
6fc48950 MM |
1263 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
1264 | { | |
1265 | long l; | |
1266 | REAL_VALUE_TYPE rv; | |
1267 | ||
1268 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1269 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
e72247f4 | 1270 | return num_insns_constant_wide ((HOST_WIDE_INT) l); |
6fc48950 MM |
1271 | } |
1272 | ||
47ad8c61 | 1273 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 1274 | { |
47ad8c61 MM |
1275 | HOST_WIDE_INT low; |
1276 | HOST_WIDE_INT high; | |
1277 | long l[2]; | |
1278 | REAL_VALUE_TYPE rv; | |
1279 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 1280 | |
47ad8c61 MM |
1281 | if (mode == VOIDmode || mode == DImode) |
1282 | { | |
1283 | high = CONST_DOUBLE_HIGH (op); | |
1284 | low = CONST_DOUBLE_LOW (op); | |
1285 | } | |
1286 | else | |
1287 | { | |
1288 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1289 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
1290 | high = l[endian]; | |
1291 | low = l[1 - endian]; | |
1292 | } | |
4e74d8ec | 1293 | |
47ad8c61 MM |
1294 | if (TARGET_32BIT) |
1295 | return (num_insns_constant_wide (low) | |
1296 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
1297 | |
1298 | else | |
47ad8c61 | 1299 | { |
e72247f4 | 1300 | if (high == 0 && low >= 0) |
47ad8c61 MM |
1301 | return num_insns_constant_wide (low); |
1302 | ||
e72247f4 | 1303 | else if (high == -1 && low < 0) |
47ad8c61 MM |
1304 | return num_insns_constant_wide (low); |
1305 | ||
a260abc9 DE |
1306 | else if (mask64_operand (op, mode)) |
1307 | return 2; | |
1308 | ||
47ad8c61 MM |
1309 | else if (low == 0) |
1310 | return num_insns_constant_wide (high) + 1; | |
1311 | ||
1312 | else | |
1313 | return (num_insns_constant_wide (high) | |
1314 | + num_insns_constant_wide (low) + 1); | |
1315 | } | |
4e74d8ec MM |
1316 | } |
1317 | ||
1318 | else | |
1319 | abort (); | |
1320 | } | |
1321 | ||
a4f6c312 SS |
1322 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a |
1323 | register with one instruction per word. We only do this if we can | |
1324 | safely read CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
1325 | |
1326 | int | |
1327 | easy_fp_constant (op, mode) | |
592696dd SS |
1328 | rtx op; |
1329 | enum machine_mode mode; | |
9878760c | 1330 | { |
9878760c RK |
1331 | if (GET_CODE (op) != CONST_DOUBLE |
1332 | || GET_MODE (op) != mode | |
4e74d8ec | 1333 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
1334 | return 0; |
1335 | ||
a4f6c312 | 1336 | /* Consider all constants with -msoft-float to be easy. */ |
a3170dc6 AH |
1337 | if ((TARGET_SOFT_FLOAT || !TARGET_FPRS) |
1338 | && mode != DImode) | |
b6c9286a MM |
1339 | return 1; |
1340 | ||
a4f6c312 | 1341 | /* If we are using V.4 style PIC, consider all constants to be hard. */ |
f607bc57 | 1342 | if (flag_pic && DEFAULT_ABI == ABI_V4) |
a7273471 MM |
1343 | return 0; |
1344 | ||
5ae4759c | 1345 | #ifdef TARGET_RELOCATABLE |
a4f6c312 SS |
1346 | /* Similarly if we are using -mrelocatable, consider all constants |
1347 | to be hard. */ | |
5ae4759c MM |
1348 | if (TARGET_RELOCATABLE) |
1349 | return 0; | |
1350 | #endif | |
1351 | ||
fcce224d DE |
1352 | if (mode == TFmode) |
1353 | { | |
1354 | long k[4]; | |
1355 | REAL_VALUE_TYPE rv; | |
1356 | ||
1357 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1358 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
1359 | ||
1360 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 | |
1361 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1 | |
1362 | && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1 | |
1363 | && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1); | |
1364 | } | |
1365 | ||
1366 | else if (mode == DFmode) | |
042259f2 DE |
1367 | { |
1368 | long k[2]; | |
1369 | REAL_VALUE_TYPE rv; | |
1370 | ||
1371 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1372 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 1373 | |
a65c591c DE |
1374 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 |
1375 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1); | |
042259f2 | 1376 | } |
4e74d8ec MM |
1377 | |
1378 | else if (mode == SFmode) | |
042259f2 DE |
1379 | { |
1380 | long l; | |
1381 | REAL_VALUE_TYPE rv; | |
1382 | ||
1383 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1384 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 1385 | |
4e74d8ec | 1386 | return num_insns_constant_wide (l) == 1; |
042259f2 | 1387 | } |
4e74d8ec | 1388 | |
a260abc9 | 1389 | else if (mode == DImode) |
c81fc13e | 1390 | return ((TARGET_POWERPC64 |
a260abc9 DE |
1391 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
1392 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 1393 | |
a9098fd0 GK |
1394 | else if (mode == SImode) |
1395 | return 1; | |
4e74d8ec MM |
1396 | else |
1397 | abort (); | |
9878760c | 1398 | } |
8f75773e | 1399 | |
69ef87e2 AH |
1400 | /* Return 1 if the operand is a CONST_INT and can be put into a |
1401 | register with one instruction. */ | |
1402 | ||
1403 | static int | |
1404 | easy_vector_constant (op) | |
1405 | rtx op; | |
1406 | { | |
1407 | rtx elt; | |
1408 | int units, i; | |
1409 | ||
1410 | if (GET_CODE (op) != CONST_VECTOR) | |
1411 | return 0; | |
1412 | ||
1413 | units = CONST_VECTOR_NUNITS (op); | |
1414 | ||
1415 | /* We can generate 0 easily. Look for that. */ | |
1416 | for (i = 0; i < units; ++i) | |
1417 | { | |
1418 | elt = CONST_VECTOR_ELT (op, i); | |
1419 | ||
1420 | /* We could probably simplify this by just checking for equality | |
1421 | with CONST0_RTX for the current mode, but let's be safe | |
1422 | instead. */ | |
1423 | ||
98ef3137 JJ |
1424 | switch (GET_CODE (elt)) |
1425 | { | |
1426 | case CONST_INT: | |
1427 | if (INTVAL (elt) != 0) | |
1428 | return 0; | |
1429 | break; | |
1430 | case CONST_DOUBLE: | |
1431 | if (CONST_DOUBLE_LOW (elt) != 0 || CONST_DOUBLE_HIGH (elt) != 0) | |
1432 | return 0; | |
1433 | break; | |
1434 | default: | |
1435 | return 0; | |
1436 | } | |
69ef87e2 AH |
1437 | } |
1438 | ||
1439 | /* We could probably generate a few other constants trivially, but | |
1440 | gcc doesn't generate them yet. FIXME later. */ | |
98ef3137 | 1441 | return 1; |
69ef87e2 AH |
1442 | } |
1443 | ||
1444 | /* Return 1 if the operand is the constant 0. This works for scalars | |
1445 | as well as vectors. */ | |
1446 | int | |
1447 | zero_constant (op, mode) | |
1448 | rtx op; | |
1449 | enum machine_mode mode; | |
1450 | { | |
1451 | return op == CONST0_RTX (mode); | |
1452 | } | |
1453 | ||
50a0b056 GK |
1454 | /* Return 1 if the operand is 0.0. */ |
1455 | int | |
1456 | zero_fp_constant (op, mode) | |
592696dd SS |
1457 | rtx op; |
1458 | enum machine_mode mode; | |
50a0b056 GK |
1459 | { |
1460 | return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode); | |
1461 | } | |
1462 | ||
a4f6c312 SS |
1463 | /* Return 1 if the operand is in volatile memory. Note that during |
1464 | the RTL generation phase, memory_operand does not return TRUE for | |
b6c9286a MM |
1465 | volatile memory references. So this function allows us to |
1466 | recognize volatile references where its safe. */ | |
1467 | ||
1468 | int | |
1469 | volatile_mem_operand (op, mode) | |
592696dd | 1470 | rtx op; |
b6c9286a MM |
1471 | enum machine_mode mode; |
1472 | { | |
1473 | if (GET_CODE (op) != MEM) | |
1474 | return 0; | |
1475 | ||
1476 | if (!MEM_VOLATILE_P (op)) | |
1477 | return 0; | |
1478 | ||
1479 | if (mode != GET_MODE (op)) | |
1480 | return 0; | |
1481 | ||
1482 | if (reload_completed) | |
1483 | return memory_operand (op, mode); | |
1484 | ||
1485 | if (reload_in_progress) | |
1486 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
1487 | ||
1488 | return memory_address_p (mode, XEXP (op, 0)); | |
1489 | } | |
1490 | ||
97f6e72f | 1491 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
1492 | |
1493 | int | |
97f6e72f | 1494 | offsettable_mem_operand (op, mode) |
592696dd | 1495 | rtx op; |
914c2e77 RK |
1496 | enum machine_mode mode; |
1497 | { | |
97f6e72f | 1498 | return ((GET_CODE (op) == MEM) |
677a9668 | 1499 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 1500 | mode, XEXP (op, 0))); |
914c2e77 RK |
1501 | } |
1502 | ||
9878760c RK |
1503 | /* Return 1 if the operand is either an easy FP constant (see above) or |
1504 | memory. */ | |
1505 | ||
1506 | int | |
1507 | mem_or_easy_const_operand (op, mode) | |
592696dd | 1508 | rtx op; |
9878760c RK |
1509 | enum machine_mode mode; |
1510 | { | |
1511 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
1512 | } | |
1513 | ||
1514 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 1515 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
1516 | |
1517 | int | |
1518 | add_operand (op, mode) | |
592696dd | 1519 | rtx op; |
9878760c RK |
1520 | enum machine_mode mode; |
1521 | { | |
2bfcf297 | 1522 | if (GET_CODE (op) == CONST_INT) |
e72247f4 DE |
1523 | return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
1524 | || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
2bfcf297 DB |
1525 | |
1526 | return gpc_reg_operand (op, mode); | |
9878760c RK |
1527 | } |
1528 | ||
dcfedcd0 RK |
1529 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
1530 | ||
1531 | int | |
1532 | non_add_cint_operand (op, mode) | |
592696dd | 1533 | rtx op; |
296b8152 | 1534 | enum machine_mode mode ATTRIBUTE_UNUSED; |
dcfedcd0 RK |
1535 | { |
1536 | return (GET_CODE (op) == CONST_INT | |
e72247f4 DE |
1537 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
1538 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
dcfedcd0 RK |
1539 | } |
1540 | ||
9878760c RK |
1541 | /* Return 1 if the operand is a non-special register or a constant that |
1542 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
1543 | ||
1544 | int | |
1545 | logical_operand (op, mode) | |
592696dd | 1546 | rtx op; |
9878760c RK |
1547 | enum machine_mode mode; |
1548 | { | |
40501e5f | 1549 | HOST_WIDE_INT opl, oph; |
1d328b19 | 1550 | |
dfbdccdb GK |
1551 | if (gpc_reg_operand (op, mode)) |
1552 | return 1; | |
1d328b19 | 1553 | |
dfbdccdb | 1554 | if (GET_CODE (op) == CONST_INT) |
40501e5f AM |
1555 | { |
1556 | opl = INTVAL (op) & GET_MODE_MASK (mode); | |
1557 | ||
1558 | #if HOST_BITS_PER_WIDE_INT <= 32 | |
1559 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0) | |
1560 | return 0; | |
1561 | #endif | |
1562 | } | |
dfbdccdb GK |
1563 | else if (GET_CODE (op) == CONST_DOUBLE) |
1564 | { | |
1d328b19 | 1565 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
40501e5f | 1566 | abort (); |
1d328b19 GK |
1567 | |
1568 | opl = CONST_DOUBLE_LOW (op); | |
1569 | oph = CONST_DOUBLE_HIGH (op); | |
40501e5f | 1570 | if (oph != 0) |
38886f37 | 1571 | return 0; |
dfbdccdb GK |
1572 | } |
1573 | else | |
1574 | return 0; | |
1d328b19 | 1575 | |
40501e5f AM |
1576 | return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 |
1577 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); | |
9878760c RK |
1578 | } |
1579 | ||
dcfedcd0 | 1580 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 1581 | above), but could be split into one. */ |
dcfedcd0 RK |
1582 | |
1583 | int | |
1584 | non_logical_cint_operand (op, mode) | |
592696dd | 1585 | rtx op; |
5f59ecb7 | 1586 | enum machine_mode mode; |
dcfedcd0 | 1587 | { |
dfbdccdb | 1588 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
1589 | && ! logical_operand (op, mode) |
1590 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
1591 | } |
1592 | ||
19ba8161 | 1593 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
1594 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
1595 | Reject all ones and all zeros, since these should have been optimized | |
1596 | away and confuse the making of MB and ME. */ | |
1597 | ||
1598 | int | |
19ba8161 | 1599 | mask_operand (op, mode) |
592696dd | 1600 | rtx op; |
19ba8161 | 1601 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c | 1602 | { |
02071907 | 1603 | HOST_WIDE_INT c, lsb; |
9878760c | 1604 | |
19ba8161 DE |
1605 | if (GET_CODE (op) != CONST_INT) |
1606 | return 0; | |
1607 | ||
1608 | c = INTVAL (op); | |
1609 | ||
57deb3a1 AM |
1610 | /* Fail in 64-bit mode if the mask wraps around because the upper |
1611 | 32-bits of the mask will all be 1s, contrary to GCC's internal view. */ | |
1612 | if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001) | |
1613 | return 0; | |
1614 | ||
c5059423 AM |
1615 | /* We don't change the number of transitions by inverting, |
1616 | so make sure we start with the LS bit zero. */ | |
1617 | if (c & 1) | |
1618 | c = ~c; | |
1619 | ||
1620 | /* Reject all zeros or all ones. */ | |
1621 | if (c == 0) | |
9878760c RK |
1622 | return 0; |
1623 | ||
c5059423 AM |
1624 | /* Find the first transition. */ |
1625 | lsb = c & -c; | |
1626 | ||
1627 | /* Invert to look for a second transition. */ | |
1628 | c = ~c; | |
9878760c | 1629 | |
c5059423 AM |
1630 | /* Erase first transition. */ |
1631 | c &= -lsb; | |
9878760c | 1632 | |
c5059423 AM |
1633 | /* Find the second transition (if any). */ |
1634 | lsb = c & -c; | |
1635 | ||
1636 | /* Match if all the bits above are 1's (or c is zero). */ | |
1637 | return c == -lsb; | |
9878760c RK |
1638 | } |
1639 | ||
0ba1b2ff AM |
1640 | /* Return 1 for the PowerPC64 rlwinm corner case. */ |
1641 | ||
1642 | int | |
1643 | mask_operand_wrap (op, mode) | |
1644 | rtx op; | |
1645 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1646 | { | |
1647 | HOST_WIDE_INT c, lsb; | |
1648 | ||
1649 | if (GET_CODE (op) != CONST_INT) | |
1650 | return 0; | |
1651 | ||
1652 | c = INTVAL (op); | |
1653 | ||
1654 | if ((c & 0x80000001) != 0x80000001) | |
1655 | return 0; | |
1656 | ||
1657 | c = ~c; | |
1658 | if (c == 0) | |
1659 | return 0; | |
1660 | ||
1661 | lsb = c & -c; | |
1662 | c = ~c; | |
1663 | c &= -lsb; | |
1664 | lsb = c & -c; | |
1665 | return c == -lsb; | |
1666 | } | |
1667 | ||
a260abc9 DE |
1668 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
1669 | It is if there are no more than one 1->0 or 0->1 transitions. | |
0ba1b2ff AM |
1670 | Reject all zeros, since zero should have been optimized away and |
1671 | confuses the making of MB and ME. */ | |
9878760c RK |
1672 | |
1673 | int | |
a260abc9 | 1674 | mask64_operand (op, mode) |
592696dd | 1675 | rtx op; |
0ba1b2ff | 1676 | enum machine_mode mode ATTRIBUTE_UNUSED; |
a260abc9 DE |
1677 | { |
1678 | if (GET_CODE (op) == CONST_INT) | |
1679 | { | |
02071907 | 1680 | HOST_WIDE_INT c, lsb; |
a260abc9 | 1681 | |
c5059423 | 1682 | c = INTVAL (op); |
a260abc9 | 1683 | |
0ba1b2ff | 1684 | /* Reject all zeros. */ |
c5059423 | 1685 | if (c == 0) |
e2c953b6 DE |
1686 | return 0; |
1687 | ||
0ba1b2ff AM |
1688 | /* We don't change the number of transitions by inverting, |
1689 | so make sure we start with the LS bit zero. */ | |
1690 | if (c & 1) | |
1691 | c = ~c; | |
1692 | ||
c5059423 AM |
1693 | /* Find the transition, and check that all bits above are 1's. */ |
1694 | lsb = c & -c; | |
e3981aab DE |
1695 | |
1696 | /* Match if all the bits above are 1's (or c is zero). */ | |
c5059423 | 1697 | return c == -lsb; |
e2c953b6 | 1698 | } |
0ba1b2ff AM |
1699 | return 0; |
1700 | } | |
1701 | ||
1702 | /* Like mask64_operand, but allow up to three transitions. This | |
1703 | predicate is used by insn patterns that generate two rldicl or | |
1704 | rldicr machine insns. */ | |
1705 | ||
1706 | int | |
1707 | mask64_2_operand (op, mode) | |
1708 | rtx op; | |
1709 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1710 | { | |
1711 | if (GET_CODE (op) == CONST_INT) | |
a260abc9 | 1712 | { |
0ba1b2ff | 1713 | HOST_WIDE_INT c, lsb; |
a260abc9 | 1714 | |
0ba1b2ff | 1715 | c = INTVAL (op); |
a260abc9 | 1716 | |
0ba1b2ff AM |
1717 | /* Disallow all zeros. */ |
1718 | if (c == 0) | |
1719 | return 0; | |
a260abc9 | 1720 | |
0ba1b2ff AM |
1721 | /* We don't change the number of transitions by inverting, |
1722 | so make sure we start with the LS bit zero. */ | |
1723 | if (c & 1) | |
1724 | c = ~c; | |
a260abc9 | 1725 | |
0ba1b2ff AM |
1726 | /* Find the first transition. */ |
1727 | lsb = c & -c; | |
a260abc9 | 1728 | |
0ba1b2ff AM |
1729 | /* Invert to look for a second transition. */ |
1730 | c = ~c; | |
1731 | ||
1732 | /* Erase first transition. */ | |
1733 | c &= -lsb; | |
1734 | ||
1735 | /* Find the second transition. */ | |
1736 | lsb = c & -c; | |
1737 | ||
1738 | /* Invert to look for a third transition. */ | |
1739 | c = ~c; | |
1740 | ||
1741 | /* Erase second transition. */ | |
1742 | c &= -lsb; | |
1743 | ||
1744 | /* Find the third transition (if any). */ | |
1745 | lsb = c & -c; | |
1746 | ||
1747 | /* Match if all the bits above are 1's (or c is zero). */ | |
1748 | return c == -lsb; | |
1749 | } | |
1750 | return 0; | |
1751 | } | |
1752 | ||
1753 | /* Generates shifts and masks for a pair of rldicl or rldicr insns to | |
1754 | implement ANDing by the mask IN. */ | |
1755 | void | |
1756 | build_mask64_2_operands (in, out) | |
1757 | rtx in; | |
1758 | rtx *out; | |
1759 | { | |
1760 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
1761 | unsigned HOST_WIDE_INT c, lsb, m1, m2; | |
1762 | int shift; | |
1763 | ||
1764 | if (GET_CODE (in) != CONST_INT) | |
1765 | abort (); | |
1766 | ||
1767 | c = INTVAL (in); | |
1768 | if (c & 1) | |
1769 | { | |
1770 | /* Assume c initially something like 0x00fff000000fffff. The idea | |
1771 | is to rotate the word so that the middle ^^^^^^ group of zeros | |
1772 | is at the MS end and can be cleared with an rldicl mask. We then | |
1773 | rotate back and clear off the MS ^^ group of zeros with a | |
1774 | second rldicl. */ | |
1775 | c = ~c; /* c == 0xff000ffffff00000 */ | |
1776 | lsb = c & -c; /* lsb == 0x0000000000100000 */ | |
1777 | m1 = -lsb; /* m1 == 0xfffffffffff00000 */ | |
1778 | c = ~c; /* c == 0x00fff000000fffff */ | |
1779 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
1780 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
1781 | c = ~c; /* c == 0xff000fffffffffff */ | |
1782 | c &= -lsb; /* c == 0xff00000000000000 */ | |
1783 | shift = 0; | |
1784 | while ((lsb >>= 1) != 0) | |
1785 | shift++; /* shift == 44 on exit from loop */ | |
1786 | m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */ | |
1787 | m1 = ~m1; /* m1 == 0x000000ffffffffff */ | |
1788 | m2 = ~c; /* m2 == 0x00ffffffffffffff */ | |
a260abc9 DE |
1789 | } |
1790 | else | |
0ba1b2ff AM |
1791 | { |
1792 | /* Assume c initially something like 0xff000f0000000000. The idea | |
1793 | is to rotate the word so that the ^^^ middle group of zeros | |
1794 | is at the LS end and can be cleared with an rldicr mask. We then | |
1795 | rotate back and clear off the LS group of ^^^^^^^^^^ zeros with | |
1796 | a second rldicr. */ | |
1797 | lsb = c & -c; /* lsb == 0x0000010000000000 */ | |
1798 | m2 = -lsb; /* m2 == 0xffffff0000000000 */ | |
1799 | c = ~c; /* c == 0x00fff0ffffffffff */ | |
1800 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
1801 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
1802 | c = ~c; /* c == 0xff000fffffffffff */ | |
1803 | c &= -lsb; /* c == 0xff00000000000000 */ | |
1804 | shift = 0; | |
1805 | while ((lsb >>= 1) != 0) | |
1806 | shift++; /* shift == 44 on exit from loop */ | |
1807 | m1 = ~c; /* m1 == 0x00ffffffffffffff */ | |
1808 | m1 >>= shift; /* m1 == 0x0000000000000fff */ | |
1809 | m1 = ~m1; /* m1 == 0xfffffffffffff000 */ | |
1810 | } | |
1811 | ||
1812 | /* Note that when we only have two 0->1 and 1->0 transitions, one of the | |
1813 | masks will be all 1's. We are guaranteed more than one transition. */ | |
1814 | out[0] = GEN_INT (64 - shift); | |
1815 | out[1] = GEN_INT (m1); | |
1816 | out[2] = GEN_INT (shift); | |
1817 | out[3] = GEN_INT (m2); | |
1818 | #else | |
045572c7 GK |
1819 | (void)in; |
1820 | (void)out; | |
0ba1b2ff AM |
1821 | abort (); |
1822 | #endif | |
a260abc9 DE |
1823 | } |
1824 | ||
1825 | /* Return 1 if the operand is either a non-special register or a constant | |
1826 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
1827 | ||
1828 | int | |
1829 | and64_operand (op, mode) | |
592696dd | 1830 | rtx op; |
9878760c RK |
1831 | enum machine_mode mode; |
1832 | { | |
a4f6c312 | 1833 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
1834 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
1835 | ||
1836 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
1837 | } |
1838 | ||
0ba1b2ff AM |
1839 | /* Like the above, but also match constants that can be implemented |
1840 | with two rldicl or rldicr insns. */ | |
1841 | ||
1842 | int | |
1843 | and64_2_operand (op, mode) | |
1844 | rtx op; | |
1845 | enum machine_mode mode; | |
1846 | { | |
1847 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ | |
1848 | return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode); | |
1849 | ||
1850 | return logical_operand (op, mode) || mask64_2_operand (op, mode); | |
1851 | } | |
1852 | ||
a260abc9 DE |
1853 | /* Return 1 if the operand is either a non-special register or a |
1854 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
1855 | |
1856 | int | |
a260abc9 | 1857 | and_operand (op, mode) |
592696dd | 1858 | rtx op; |
a260abc9 | 1859 | enum machine_mode mode; |
dcfedcd0 | 1860 | { |
a4f6c312 | 1861 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
1862 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
1863 | ||
1864 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
1865 | } |
1866 | ||
9878760c RK |
1867 | /* Return 1 if the operand is a general register or memory operand. */ |
1868 | ||
1869 | int | |
1870 | reg_or_mem_operand (op, mode) | |
592696dd SS |
1871 | rtx op; |
1872 | enum machine_mode mode; | |
9878760c | 1873 | { |
b6c9286a MM |
1874 | return (gpc_reg_operand (op, mode) |
1875 | || memory_operand (op, mode) | |
1876 | || volatile_mem_operand (op, mode)); | |
9878760c RK |
1877 | } |
1878 | ||
a7a813f7 | 1879 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 1880 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
1881 | instruction. */ |
1882 | ||
1883 | int | |
1884 | lwa_operand (op, mode) | |
592696dd SS |
1885 | rtx op; |
1886 | enum machine_mode mode; | |
a7a813f7 RK |
1887 | { |
1888 | rtx inner = op; | |
1889 | ||
1890 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
1891 | inner = SUBREG_REG (inner); | |
1892 | ||
1893 | return gpc_reg_operand (inner, mode) | |
1894 | || (memory_operand (inner, mode) | |
1895 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
6a40a9d6 DE |
1896 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC |
1897 | && (GET_CODE (XEXP (inner, 0)) != PLUS | |
e903c96a DE |
1898 | || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT |
1899 | || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0)); | |
a7a813f7 RK |
1900 | } |
1901 | ||
cc4d5fec JH |
1902 | /* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */ |
1903 | ||
1904 | int | |
1905 | symbol_ref_operand (op, mode) | |
1906 | rtx op; | |
1907 | enum machine_mode mode; | |
1908 | { | |
1909 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
1910 | return 0; | |
1911 | ||
1912 | return (GET_CODE (op) == SYMBOL_REF); | |
1913 | } | |
1914 | ||
9878760c | 1915 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
cc4d5fec | 1916 | to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */ |
9878760c RK |
1917 | |
1918 | int | |
1919 | call_operand (op, mode) | |
592696dd | 1920 | rtx op; |
9878760c RK |
1921 | enum machine_mode mode; |
1922 | { | |
1923 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
1924 | return 0; | |
1925 | ||
1926 | return (GET_CODE (op) == SYMBOL_REF | |
cc4d5fec JH |
1927 | || (GET_CODE (op) == REG |
1928 | && (REGNO (op) == LINK_REGISTER_REGNUM | |
1929 | || REGNO (op) == COUNT_REGISTER_REGNUM | |
1930 | || REGNO (op) >= FIRST_PSEUDO_REGISTER))); | |
9878760c RK |
1931 | } |
1932 | ||
2af3d377 | 1933 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in |
a4f6c312 | 1934 | this file and the function is not weakly defined. */ |
2af3d377 RK |
1935 | |
1936 | int | |
1937 | current_file_function_operand (op, mode) | |
592696dd | 1938 | rtx op; |
296b8152 | 1939 | enum machine_mode mode ATTRIBUTE_UNUSED; |
2af3d377 RK |
1940 | { |
1941 | return (GET_CODE (op) == SYMBOL_REF | |
1942 | && (SYMBOL_REF_FLAG (op) | |
8f1b829e | 1943 | || (op == XEXP (DECL_RTL (current_function_decl), 0) |
c81fc13e | 1944 | && ! DECL_WEAK (current_function_decl)))); |
2af3d377 RK |
1945 | } |
1946 | ||
9878760c RK |
1947 | /* Return 1 if this operand is a valid input for a move insn. */ |
1948 | ||
1949 | int | |
1950 | input_operand (op, mode) | |
592696dd | 1951 | rtx op; |
9878760c RK |
1952 | enum machine_mode mode; |
1953 | { | |
eb4e8003 | 1954 | /* Memory is always valid. */ |
9878760c RK |
1955 | if (memory_operand (op, mode)) |
1956 | return 1; | |
1957 | ||
34792e82 | 1958 | /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */ |
01b4cf2b | 1959 | if (GET_CODE (op) == CONSTANT_P_RTX) |
34792e82 JL |
1960 | return 1; |
1961 | ||
eb4e8003 RK |
1962 | /* For floating-point, easy constants are valid. */ |
1963 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
1964 | && CONSTANT_P (op) | |
1965 | && easy_fp_constant (op, mode)) | |
1966 | return 1; | |
1967 | ||
4e74d8ec MM |
1968 | /* Allow any integer constant. */ |
1969 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 1970 | && (GET_CODE (op) == CONST_INT |
e675f625 | 1971 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
1972 | return 1; |
1973 | ||
eb4e8003 RK |
1974 | /* For floating-point or multi-word mode, the only remaining valid type |
1975 | is a register. */ | |
9878760c RK |
1976 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
1977 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 1978 | return register_operand (op, mode); |
9878760c | 1979 | |
88fe15a1 RK |
1980 | /* The only cases left are integral modes one word or smaller (we |
1981 | do not get called for MODE_CC values). These can be in any | |
1982 | register. */ | |
1983 | if (register_operand (op, mode)) | |
a8b3aeda | 1984 | return 1; |
88fe15a1 | 1985 | |
84cf9dda | 1986 | /* A SYMBOL_REF referring to the TOC is valid. */ |
7fec4abd | 1987 | if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op)) |
84cf9dda RK |
1988 | return 1; |
1989 | ||
9ebbca7d GK |
1990 | /* A constant pool expression (relative to the TOC) is valid */ |
1991 | if (TOC_RELATIVE_EXPR_P (op)) | |
b6c9286a MM |
1992 | return 1; |
1993 | ||
88228c4b MM |
1994 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
1995 | to be valid. */ | |
f607bc57 | 1996 | if (DEFAULT_ABI == ABI_V4 |
88228c4b MM |
1997 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
1998 | && small_data_operand (op, Pmode)) | |
1999 | return 1; | |
2000 | ||
042259f2 | 2001 | return 0; |
9878760c | 2002 | } |
7509c759 | 2003 | |
a4f6c312 | 2004 | /* Return 1 for an operand in small memory on V.4/eabi. */ |
7509c759 MM |
2005 | |
2006 | int | |
2007 | small_data_operand (op, mode) | |
296b8152 KG |
2008 | rtx op ATTRIBUTE_UNUSED; |
2009 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
7509c759 | 2010 | { |
38c1f2d7 | 2011 | #if TARGET_ELF |
5f59ecb7 | 2012 | rtx sym_ref; |
7509c759 | 2013 | |
d9407988 | 2014 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 2015 | return 0; |
a54d04b7 | 2016 | |
f607bc57 | 2017 | if (DEFAULT_ABI != ABI_V4) |
7509c759 MM |
2018 | return 0; |
2019 | ||
88228c4b MM |
2020 | if (GET_CODE (op) == SYMBOL_REF) |
2021 | sym_ref = op; | |
2022 | ||
2023 | else if (GET_CODE (op) != CONST | |
2024 | || GET_CODE (XEXP (op, 0)) != PLUS | |
2025 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
2026 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
2027 | return 0; |
2028 | ||
88228c4b | 2029 | else |
dbf55e53 MM |
2030 | { |
2031 | rtx sum = XEXP (op, 0); | |
2032 | HOST_WIDE_INT summand; | |
2033 | ||
2034 | /* We have to be careful here, because it is the referenced address | |
2035 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
2036 | summand = INTVAL (XEXP (sum, 1)); | |
2037 | if (summand < 0 || summand > g_switch_value) | |
2038 | return 0; | |
2039 | ||
2040 | sym_ref = XEXP (sum, 0); | |
2041 | } | |
88228c4b MM |
2042 | |
2043 | if (*XSTR (sym_ref, 0) != '@') | |
7509c759 MM |
2044 | return 0; |
2045 | ||
2046 | return 1; | |
d9407988 MM |
2047 | |
2048 | #else | |
2049 | return 0; | |
2050 | #endif | |
7509c759 | 2051 | } |
9ebbca7d GK |
2052 | \f |
2053 | static int | |
2054 | constant_pool_expr_1 (op, have_sym, have_toc) | |
2055 | rtx op; | |
2056 | int *have_sym; | |
2057 | int *have_toc; | |
2058 | { | |
2059 | switch (GET_CODE(op)) | |
2060 | { | |
2061 | case SYMBOL_REF: | |
a4f6c312 SS |
2062 | if (CONSTANT_POOL_ADDRESS_P (op)) |
2063 | { | |
2064 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) | |
2065 | { | |
2066 | *have_sym = 1; | |
2067 | return 1; | |
2068 | } | |
2069 | else | |
2070 | return 0; | |
2071 | } | |
2072 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
2073 | { | |
2074 | *have_toc = 1; | |
2075 | return 1; | |
2076 | } | |
2077 | else | |
2078 | return 0; | |
9ebbca7d GK |
2079 | case PLUS: |
2080 | case MINUS: | |
c1f11548 DE |
2081 | return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) |
2082 | && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc)); | |
9ebbca7d | 2083 | case CONST: |
a4f6c312 | 2084 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); |
9ebbca7d | 2085 | case CONST_INT: |
a4f6c312 | 2086 | return 1; |
9ebbca7d | 2087 | default: |
a4f6c312 | 2088 | return 0; |
9ebbca7d GK |
2089 | } |
2090 | } | |
2091 | ||
2092 | int | |
2093 | constant_pool_expr_p (op) | |
2094 | rtx op; | |
2095 | { | |
2096 | int have_sym = 0; | |
2097 | int have_toc = 0; | |
2098 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
2099 | } | |
2100 | ||
2101 | int | |
2102 | toc_relative_expr_p (op) | |
2103 | rtx op; | |
2104 | { | |
2105 | int have_sym = 0; | |
2106 | int have_toc = 0; | |
2107 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
2108 | } | |
2109 | ||
2110 | /* Try machine-dependent ways of modifying an illegitimate address | |
2111 | to be legitimate. If we find one, return the new, valid address. | |
2112 | This is used from only one place: `memory_address' in explow.c. | |
2113 | ||
a4f6c312 SS |
2114 | OLDX is the address as it was before break_out_memory_refs was |
2115 | called. In some cases it is useful to look at this to decide what | |
2116 | needs to be done. | |
9ebbca7d | 2117 | |
a4f6c312 | 2118 | MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS. |
9ebbca7d | 2119 | |
a4f6c312 SS |
2120 | It is always safe for this function to do nothing. It exists to |
2121 | recognize opportunities to optimize the output. | |
9ebbca7d GK |
2122 | |
2123 | On RS/6000, first check for the sum of a register with a constant | |
2124 | integer that is out of range. If so, generate code to add the | |
2125 | constant with the low-order 16 bits masked to the register and force | |
2126 | this result into another register (this can be done with `cau'). | |
2127 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
2128 | possibility of bit 16 being a one. | |
2129 | ||
2130 | Then check for the sum of a register and something not constant, try to | |
2131 | load the other things into a register and return the sum. */ | |
2132 | rtx | |
2133 | rs6000_legitimize_address (x, oldx, mode) | |
2134 | rtx x; | |
2135 | rtx oldx ATTRIBUTE_UNUSED; | |
2136 | enum machine_mode mode; | |
0ac081f6 | 2137 | { |
9ebbca7d GK |
2138 | if (GET_CODE (x) == PLUS |
2139 | && GET_CODE (XEXP (x, 0)) == REG | |
2140 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2141 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
2142 | { | |
2143 | HOST_WIDE_INT high_int, low_int; | |
2144 | rtx sum; | |
a65c591c DE |
2145 | low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000; |
2146 | high_int = INTVAL (XEXP (x, 1)) - low_int; | |
9ebbca7d GK |
2147 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), |
2148 | GEN_INT (high_int)), 0); | |
2149 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
2150 | } | |
2151 | else if (GET_CODE (x) == PLUS | |
2152 | && GET_CODE (XEXP (x, 0)) == REG | |
2153 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
6ac7bf2c | 2154 | && GET_MODE_NUNITS (mode) == 1 |
a3170dc6 AH |
2155 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
2156 | || TARGET_POWERPC64 | |
fcce224d | 2157 | || (mode != DFmode && mode != TFmode)) |
9ebbca7d GK |
2158 | && (TARGET_POWERPC64 || mode != DImode) |
2159 | && mode != TImode) | |
2160 | { | |
2161 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
2162 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
2163 | } | |
0ac081f6 AH |
2164 | else if (ALTIVEC_VECTOR_MODE (mode)) |
2165 | { | |
2166 | rtx reg; | |
2167 | ||
2168 | /* Make sure both operands are registers. */ | |
2169 | if (GET_CODE (x) == PLUS) | |
9f85ed45 | 2170 | return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)), |
0ac081f6 AH |
2171 | force_reg (Pmode, XEXP (x, 1))); |
2172 | ||
2173 | reg = force_reg (Pmode, x); | |
2174 | return reg; | |
2175 | } | |
a3170dc6 AH |
2176 | else if (SPE_VECTOR_MODE (mode)) |
2177 | { | |
2178 | /* We accept [reg + reg] and [reg + OFFSET]. */ | |
2179 | ||
2180 | if (GET_CODE (x) == PLUS) | |
2181 | { | |
2182 | rtx op1 = XEXP (x, 0); | |
2183 | rtx op2 = XEXP (x, 1); | |
2184 | ||
2185 | op1 = force_reg (Pmode, op1); | |
2186 | ||
2187 | if (GET_CODE (op2) != REG | |
2188 | && (GET_CODE (op2) != CONST_INT | |
2189 | || !SPE_CONST_OFFSET_OK (INTVAL (op2)))) | |
2190 | op2 = force_reg (Pmode, op2); | |
2191 | ||
2192 | return gen_rtx_PLUS (Pmode, op1, op2); | |
2193 | } | |
2194 | ||
2195 | return force_reg (Pmode, x); | |
2196 | } | |
9ebbca7d GK |
2197 | else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic |
2198 | && GET_CODE (x) != CONST_INT | |
2199 | && GET_CODE (x) != CONST_DOUBLE | |
2200 | && CONSTANT_P (x) | |
6ac7bf2c GK |
2201 | && GET_MODE_NUNITS (mode) == 1 |
2202 | && (GET_MODE_BITSIZE (mode) <= 32 | |
a3170dc6 | 2203 | || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode))) |
9ebbca7d GK |
2204 | { |
2205 | rtx reg = gen_reg_rtx (Pmode); | |
2206 | emit_insn (gen_elf_high (reg, (x))); | |
2207 | return gen_rtx_LO_SUM (Pmode, reg, (x)); | |
2208 | } | |
ee890fe2 SS |
2209 | else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC |
2210 | && ! flag_pic | |
2211 | && GET_CODE (x) != CONST_INT | |
2212 | && GET_CODE (x) != CONST_DOUBLE | |
2213 | && CONSTANT_P (x) | |
a3170dc6 | 2214 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode) |
ee890fe2 SS |
2215 | && mode != DImode |
2216 | && mode != TImode) | |
2217 | { | |
2218 | rtx reg = gen_reg_rtx (Pmode); | |
2219 | emit_insn (gen_macho_high (reg, (x))); | |
2220 | return gen_rtx_LO_SUM (Pmode, reg, (x)); | |
2221 | } | |
9ebbca7d GK |
2222 | else if (TARGET_TOC |
2223 | && CONSTANT_POOL_EXPR_P (x) | |
a9098fd0 | 2224 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
2225 | { |
2226 | return create_TOC_reference (x); | |
2227 | } | |
2228 | else | |
2229 | return NULL_RTX; | |
2230 | } | |
258bfae2 | 2231 | |
24ea750e DJ |
2232 | /* The convention appears to be to define this wherever it is used. |
2233 | With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P | |
2234 | is now used here. */ | |
2235 | #ifndef REG_MODE_OK_FOR_BASE_P | |
2236 | #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO) | |
2237 | #endif | |
2238 | ||
2239 | /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to | |
2240 | replace the input X, or the original X if no replacement is called for. | |
2241 | The output parameter *WIN is 1 if the calling macro should goto WIN, | |
2242 | 0 if it should not. | |
2243 | ||
2244 | For RS/6000, we wish to handle large displacements off a base | |
2245 | register by splitting the addend across an addiu/addis and the mem insn. | |
2246 | This cuts number of extra insns needed from 3 to 1. | |
2247 | ||
2248 | On Darwin, we use this to generate code for floating point constants. | |
2249 | A movsf_low is generated so we wind up with 2 instructions rather than 3. | |
2250 | The Darwin code is inside #if TARGET_MACHO because only then is | |
2251 | machopic_function_base_name() defined. */ | |
2252 | rtx | |
2253 | rs6000_legitimize_reload_address (x, mode, opnum, type, ind_levels, win) | |
2254 | rtx x; | |
2255 | enum machine_mode mode; | |
2256 | int opnum; | |
2257 | int type; | |
2258 | int ind_levels ATTRIBUTE_UNUSED; | |
2259 | int *win; | |
2260 | { | |
2261 | /* We must recognize output that we have already generated ourselves. */ | |
2262 | if (GET_CODE (x) == PLUS | |
2263 | && GET_CODE (XEXP (x, 0)) == PLUS | |
2264 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
2265 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
2266 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2267 | { | |
2268 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
2269 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
2270 | opnum, (enum reload_type)type); | |
2271 | *win = 1; | |
2272 | return x; | |
2273 | } | |
3deb2758 | 2274 | |
24ea750e DJ |
2275 | #if TARGET_MACHO |
2276 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic | |
2277 | && GET_CODE (x) == LO_SUM | |
2278 | && GET_CODE (XEXP (x, 0)) == PLUS | |
2279 | && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx | |
2280 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH | |
2281 | && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST | |
2282 | && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1) | |
2283 | && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS | |
2284 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF | |
2285 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF) | |
2286 | { | |
2287 | /* Result of previous invocation of this function on Darwin | |
6f317ef3 | 2288 | floating point constant. */ |
24ea750e DJ |
2289 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
2290 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
2291 | opnum, (enum reload_type)type); | |
2292 | *win = 1; | |
2293 | return x; | |
2294 | } | |
2295 | #endif | |
2296 | if (GET_CODE (x) == PLUS | |
2297 | && GET_CODE (XEXP (x, 0)) == REG | |
2298 | && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER | |
2299 | && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode) | |
78c875e8 | 2300 | && GET_CODE (XEXP (x, 1)) == CONST_INT |
93638d7a | 2301 | && !SPE_VECTOR_MODE (mode) |
78c875e8 | 2302 | && !ALTIVEC_VECTOR_MODE (mode)) |
24ea750e DJ |
2303 | { |
2304 | HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); | |
2305 | HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; | |
2306 | HOST_WIDE_INT high | |
2307 | = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
2308 | ||
2309 | /* Check for 32-bit overflow. */ | |
2310 | if (high + low != val) | |
2311 | { | |
2312 | *win = 0; | |
2313 | return x; | |
2314 | } | |
2315 | ||
2316 | /* Reload the high part into a base reg; leave the low part | |
2317 | in the mem directly. */ | |
2318 | ||
2319 | x = gen_rtx_PLUS (GET_MODE (x), | |
2320 | gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), | |
2321 | GEN_INT (high)), | |
2322 | GEN_INT (low)); | |
2323 | ||
2324 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
2325 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
2326 | opnum, (enum reload_type)type); | |
2327 | *win = 1; | |
2328 | return x; | |
2329 | } | |
2330 | #if TARGET_MACHO | |
2331 | if (GET_CODE (x) == SYMBOL_REF | |
2332 | && DEFAULT_ABI == ABI_DARWIN | |
69ef87e2 | 2333 | && !ALTIVEC_VECTOR_MODE (mode) |
24ea750e DJ |
2334 | && flag_pic) |
2335 | { | |
2336 | /* Darwin load of floating point constant. */ | |
2337 | rtx offset = gen_rtx (CONST, Pmode, | |
2338 | gen_rtx (MINUS, Pmode, x, | |
2339 | gen_rtx (SYMBOL_REF, Pmode, | |
2340 | machopic_function_base_name ()))); | |
2341 | x = gen_rtx (LO_SUM, GET_MODE (x), | |
2342 | gen_rtx (PLUS, Pmode, pic_offset_table_rtx, | |
2343 | gen_rtx (HIGH, Pmode, offset)), offset); | |
2344 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
2345 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
2346 | opnum, (enum reload_type)type); | |
2347 | *win = 1; | |
2348 | return x; | |
2349 | } | |
2350 | #endif | |
2351 | if (TARGET_TOC | |
c1f11548 DE |
2352 | && CONSTANT_POOL_EXPR_P (x) |
2353 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode)) | |
24ea750e DJ |
2354 | { |
2355 | (x) = create_TOC_reference (x); | |
2356 | *win = 1; | |
2357 | return x; | |
2358 | } | |
2359 | *win = 0; | |
2360 | return x; | |
2361 | } | |
2362 | ||
258bfae2 FS |
2363 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression |
2364 | that is a valid memory address for an instruction. | |
2365 | The MODE argument is the machine mode for the MEM expression | |
2366 | that wants to use this address. | |
2367 | ||
2368 | On the RS/6000, there are four valid address: a SYMBOL_REF that | |
2369 | refers to a constant pool entry of an address (or the sum of it | |
2370 | plus a constant), a short (16-bit signed) constant plus a register, | |
2371 | the sum of two registers, or a register indirect, possibly with an | |
5bdc5878 | 2372 | auto-increment. For DFmode and DImode with a constant plus register, |
258bfae2 FS |
2373 | we must ensure that both words are addressable or PowerPC64 with offset |
2374 | word aligned. | |
2375 | ||
2376 | For modes spanning multiple registers (DFmode in 32-bit GPRs, | |
2377 | 32-bit DImode, TImode), indexed addressing cannot be used because | |
2378 | adjacent memory cells are accessed by adding word-sized offsets | |
2379 | during assembly output. */ | |
2380 | int | |
2381 | rs6000_legitimate_address (mode, x, reg_ok_strict) | |
2382 | enum machine_mode mode; | |
2383 | rtx x; | |
2384 | int reg_ok_strict; | |
2385 | { | |
2386 | if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict)) | |
2387 | return 1; | |
2388 | if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) | |
0d6d6892 | 2389 | && !ALTIVEC_VECTOR_MODE (mode) |
a3170dc6 | 2390 | && !SPE_VECTOR_MODE (mode) |
258bfae2 FS |
2391 | && TARGET_UPDATE |
2392 | && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict)) | |
2393 | return 1; | |
2394 | if (LEGITIMATE_SMALL_DATA_P (mode, x)) | |
2395 | return 1; | |
2396 | if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x)) | |
2397 | return 1; | |
2398 | /* If not REG_OK_STRICT (before reload) let pass any stack offset. */ | |
2399 | if (! reg_ok_strict | |
2400 | && GET_CODE (x) == PLUS | |
2401 | && GET_CODE (XEXP (x, 0)) == REG | |
2402 | && XEXP (x, 0) == virtual_stack_vars_rtx | |
2403 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2404 | return 1; | |
2405 | if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict)) | |
2406 | return 1; | |
2407 | if (mode != TImode | |
a3170dc6 AH |
2408 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
2409 | || TARGET_POWERPC64 | |
fcce224d | 2410 | || (mode != DFmode && mode != TFmode)) |
258bfae2 FS |
2411 | && (TARGET_POWERPC64 || mode != DImode) |
2412 | && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict)) | |
2413 | return 1; | |
2414 | if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict)) | |
2415 | return 1; | |
2416 | return 0; | |
2417 | } | |
fb4d4348 | 2418 | \f |
a4f6c312 SS |
2419 | /* Try to output insns to set TARGET equal to the constant C if it can |
2420 | be done in less than N insns. Do all computations in MODE. | |
2421 | Returns the place where the output has been placed if it can be | |
2422 | done and the insns have been emitted. If it would take more than N | |
2423 | insns, zero is returned and no insns and emitted. */ | |
2bfcf297 DB |
2424 | |
2425 | rtx | |
2426 | rs6000_emit_set_const (dest, mode, source, n) | |
2427 | rtx dest, source; | |
2428 | enum machine_mode mode; | |
2429 | int n ATTRIBUTE_UNUSED; | |
2430 | { | |
af8cb5c5 | 2431 | rtx result, insn, set; |
2bfcf297 DB |
2432 | HOST_WIDE_INT c0, c1; |
2433 | ||
af8cb5c5 | 2434 | if (mode == QImode || mode == HImode) |
2bfcf297 DB |
2435 | { |
2436 | if (dest == NULL) | |
2437 | dest = gen_reg_rtx (mode); | |
2438 | emit_insn (gen_rtx_SET (VOIDmode, dest, source)); | |
2439 | return dest; | |
2440 | } | |
af8cb5c5 | 2441 | else if (mode == SImode) |
2bfcf297 | 2442 | { |
af8cb5c5 DE |
2443 | result = no_new_pseudos ? dest : gen_reg_rtx (SImode); |
2444 | ||
2445 | emit_insn (gen_rtx_SET (VOIDmode, result, | |
2446 | GEN_INT (INTVAL (source) | |
2447 | & (~ (HOST_WIDE_INT) 0xffff)))); | |
2448 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
2449 | gen_rtx_IOR (SImode, result, | |
2450 | GEN_INT (INTVAL (source) & 0xffff)))); | |
2451 | result = dest; | |
2bfcf297 | 2452 | } |
af8cb5c5 | 2453 | else if (mode == DImode) |
2bfcf297 | 2454 | { |
af8cb5c5 DE |
2455 | if (GET_CODE (source) == CONST_INT) |
2456 | { | |
2457 | c0 = INTVAL (source); | |
2458 | c1 = -(c0 < 0); | |
2459 | } | |
2460 | else if (GET_CODE (source) == CONST_DOUBLE) | |
2461 | { | |
2bfcf297 | 2462 | #if HOST_BITS_PER_WIDE_INT >= 64 |
af8cb5c5 DE |
2463 | c0 = CONST_DOUBLE_LOW (source); |
2464 | c1 = -(c0 < 0); | |
2bfcf297 | 2465 | #else |
af8cb5c5 DE |
2466 | c0 = CONST_DOUBLE_LOW (source); |
2467 | c1 = CONST_DOUBLE_HIGH (source); | |
2bfcf297 | 2468 | #endif |
af8cb5c5 DE |
2469 | } |
2470 | else | |
2471 | abort (); | |
2472 | ||
2473 | result = rs6000_emit_set_long_const (dest, c0, c1); | |
2bfcf297 DB |
2474 | } |
2475 | else | |
a4f6c312 | 2476 | abort (); |
2bfcf297 | 2477 | |
af8cb5c5 DE |
2478 | insn = get_last_insn (); |
2479 | set = single_set (insn); | |
2480 | if (! CONSTANT_P (SET_SRC (set))) | |
2481 | set_unique_reg_note (insn, REG_EQUAL, source); | |
2482 | ||
2483 | return result; | |
2bfcf297 DB |
2484 | } |
2485 | ||
2486 | /* Having failed to find a 3 insn sequence in rs6000_emit_set_const, | |
2487 | fall back to a straight forward decomposition. We do this to avoid | |
2488 | exponential run times encountered when looking for longer sequences | |
2489 | with rs6000_emit_set_const. */ | |
2490 | static rtx | |
2491 | rs6000_emit_set_long_const (dest, c1, c2) | |
2492 | rtx dest; | |
2493 | HOST_WIDE_INT c1, c2; | |
2494 | { | |
2495 | if (!TARGET_POWERPC64) | |
2496 | { | |
2497 | rtx operand1, operand2; | |
2498 | ||
2499 | operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0, | |
2500 | DImode); | |
2501 | operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, | |
2502 | DImode); | |
2503 | emit_move_insn (operand1, GEN_INT (c1)); | |
2504 | emit_move_insn (operand2, GEN_INT (c2)); | |
2505 | } | |
2506 | else | |
2507 | { | |
bc06712d | 2508 | HOST_WIDE_INT ud1, ud2, ud3, ud4; |
252b88f7 | 2509 | |
bc06712d TR |
2510 | ud1 = c1 & 0xffff; |
2511 | ud2 = (c1 & 0xffff0000) >> 16; | |
2bfcf297 | 2512 | #if HOST_BITS_PER_WIDE_INT >= 64 |
bc06712d | 2513 | c2 = c1 >> 32; |
2bfcf297 | 2514 | #endif |
bc06712d TR |
2515 | ud3 = c2 & 0xffff; |
2516 | ud4 = (c2 & 0xffff0000) >> 16; | |
2bfcf297 | 2517 | |
bc06712d TR |
2518 | if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) |
2519 | || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) | |
2bfcf297 | 2520 | { |
bc06712d TR |
2521 | if (ud1 & 0x8000) |
2522 | emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000))); | |
2523 | else | |
2524 | emit_move_insn (dest, GEN_INT (ud1)); | |
2bfcf297 | 2525 | } |
2bfcf297 | 2526 | |
bc06712d TR |
2527 | else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000)) |
2528 | || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000))) | |
252b88f7 | 2529 | { |
bc06712d TR |
2530 | if (ud2 & 0x8000) |
2531 | emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000) | |
2532 | - 0x80000000)); | |
252b88f7 | 2533 | else |
bc06712d TR |
2534 | emit_move_insn (dest, GEN_INT (ud2 << 16)); |
2535 | if (ud1 != 0) | |
2536 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
252b88f7 | 2537 | } |
bc06712d TR |
2538 | else if ((ud4 == 0xffff && (ud3 & 0x8000)) |
2539 | || (ud4 == 0 && ! (ud3 & 0x8000))) | |
2540 | { | |
2541 | if (ud3 & 0x8000) | |
2542 | emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000) | |
2543 | - 0x80000000)); | |
2544 | else | |
2545 | emit_move_insn (dest, GEN_INT (ud3 << 16)); | |
2546 | ||
2547 | if (ud2 != 0) | |
2548 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2))); | |
2549 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16))); | |
2550 | if (ud1 != 0) | |
2551 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
2552 | } | |
2553 | else | |
2554 | { | |
2555 | if (ud4 & 0x8000) | |
2556 | emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000) | |
2557 | - 0x80000000)); | |
2558 | else | |
2559 | emit_move_insn (dest, GEN_INT (ud4 << 16)); | |
2560 | ||
2561 | if (ud3 != 0) | |
2562 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3))); | |
2bfcf297 | 2563 | |
bc06712d TR |
2564 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32))); |
2565 | if (ud2 != 0) | |
2566 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, | |
2567 | GEN_INT (ud2 << 16))); | |
2568 | if (ud1 != 0) | |
2569 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
2570 | } | |
2571 | } | |
2bfcf297 DB |
2572 | return dest; |
2573 | } | |
2574 | ||
fb4d4348 GK |
2575 | /* Emit a move from SOURCE to DEST in mode MODE. */ |
2576 | void | |
2577 | rs6000_emit_move (dest, source, mode) | |
2578 | rtx dest; | |
2579 | rtx source; | |
2580 | enum machine_mode mode; | |
2581 | { | |
2582 | rtx operands[2]; | |
2583 | operands[0] = dest; | |
2584 | operands[1] = source; | |
2585 | ||
2586 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ | |
2587 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
2588 | && ! FLOAT_MODE_P (mode) | |
2589 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
2590 | { | |
2591 | /* FIXME. This should never happen. */ | |
2592 | /* Since it seems that it does, do the safe thing and convert | |
2593 | to a CONST_INT. */ | |
2496c7bd | 2594 | operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode); |
fb4d4348 GK |
2595 | } |
2596 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
2597 | && ! FLOAT_MODE_P (mode) | |
2598 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
2599 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
2600 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
2601 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
2602 | abort (); | |
c9e8cb32 DD |
2603 | |
2604 | /* Check if GCC is setting up a block move that will end up using FP | |
2605 | registers as temporaries. We must make sure this is acceptable. */ | |
2606 | if (GET_CODE (operands[0]) == MEM | |
2607 | && GET_CODE (operands[1]) == MEM | |
2608 | && mode == DImode | |
41543739 GK |
2609 | && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0])) |
2610 | || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1]))) | |
2611 | && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32 | |
2612 | ? 32 : MEM_ALIGN (operands[0]))) | |
2613 | || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32 | |
2614 | ? 32 | |
2615 | : MEM_ALIGN (operands[1])))) | |
2616 | && ! MEM_VOLATILE_P (operands [0]) | |
2617 | && ! MEM_VOLATILE_P (operands [1])) | |
c9e8cb32 | 2618 | { |
41543739 GK |
2619 | emit_move_insn (adjust_address (operands[0], SImode, 0), |
2620 | adjust_address (operands[1], SImode, 0)); | |
2621 | emit_move_insn (adjust_address (operands[0], SImode, 4), | |
2622 | adjust_address (operands[1], SImode, 4)); | |
c9e8cb32 DD |
2623 | return; |
2624 | } | |
fb4d4348 | 2625 | |
67cef334 DE |
2626 | if (!no_new_pseudos) |
2627 | { | |
2628 | if (GET_CODE (operands[1]) == MEM && optimize > 0 | |
2629 | && (mode == QImode || mode == HImode || mode == SImode) | |
2630 | && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode)) | |
2631 | { | |
2632 | rtx reg = gen_reg_rtx (word_mode); | |
2633 | ||
2634 | emit_insn (gen_rtx_SET (word_mode, reg, | |
2635 | gen_rtx_ZERO_EXTEND (word_mode, | |
2636 | operands[1]))); | |
2637 | operands[1] = gen_lowpart (mode, reg); | |
2638 | } | |
2639 | if (GET_CODE (operands[0]) != REG) | |
2640 | operands[1] = force_reg (mode, operands[1]); | |
2641 | } | |
a9098fd0 | 2642 | |
a3170dc6 AH |
2643 | if (mode == SFmode && ! TARGET_POWERPC |
2644 | && TARGET_HARD_FLOAT && TARGET_FPRS | |
ffc14f31 | 2645 | && GET_CODE (operands[0]) == MEM) |
fb4d4348 | 2646 | { |
ffc14f31 GK |
2647 | int regnum; |
2648 | ||
2649 | if (reload_in_progress || reload_completed) | |
2650 | regnum = true_regnum (operands[1]); | |
2651 | else if (GET_CODE (operands[1]) == REG) | |
2652 | regnum = REGNO (operands[1]); | |
2653 | else | |
2654 | regnum = -1; | |
fb4d4348 GK |
2655 | |
2656 | /* If operands[1] is a register, on POWER it may have | |
2657 | double-precision data in it, so truncate it to single | |
2658 | precision. */ | |
2659 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
2660 | { | |
2661 | rtx newreg; | |
2662 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
2663 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
2664 | operands[1] = newreg; | |
2665 | } | |
2666 | } | |
2667 | ||
a9098fd0 GK |
2668 | /* Handle the case where reload calls us with an invalid address; |
2669 | and the case of CONSTANT_P_RTX. */ | |
16861f33 | 2670 | if (!ALTIVEC_VECTOR_MODE (mode) |
69ef87e2 AH |
2671 | && (! general_operand (operands[1], mode) |
2672 | || ! nonimmediate_operand (operands[0], mode) | |
2673 | || GET_CODE (operands[1]) == CONSTANT_P_RTX)) | |
fb4d4348 GK |
2674 | { |
2675 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
2676 | return; | |
2677 | } | |
a9098fd0 | 2678 | |
fb4d4348 GK |
2679 | /* FIXME: In the long term, this switch statement should go away |
2680 | and be replaced by a sequence of tests based on things like | |
2681 | mode == Pmode. */ | |
2682 | switch (mode) | |
2683 | { | |
2684 | case HImode: | |
2685 | case QImode: | |
2686 | if (CONSTANT_P (operands[1]) | |
2687 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 2688 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
2689 | break; |
2690 | ||
06f4e019 | 2691 | case TFmode: |
fb4d4348 GK |
2692 | case DFmode: |
2693 | case SFmode: | |
2694 | if (CONSTANT_P (operands[1]) | |
2695 | && ! easy_fp_constant (operands[1], mode)) | |
a9098fd0 | 2696 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
2697 | break; |
2698 | ||
0ac081f6 AH |
2699 | case V16QImode: |
2700 | case V8HImode: | |
2701 | case V4SFmode: | |
2702 | case V4SImode: | |
a3170dc6 AH |
2703 | case V4HImode: |
2704 | case V2SFmode: | |
2705 | case V2SImode: | |
00a892b8 | 2706 | case V1DImode: |
69ef87e2 AH |
2707 | if (CONSTANT_P (operands[1]) |
2708 | && !easy_vector_constant (operands[1])) | |
0ac081f6 AH |
2709 | operands[1] = force_const_mem (mode, operands[1]); |
2710 | break; | |
2711 | ||
fb4d4348 | 2712 | case SImode: |
a9098fd0 | 2713 | case DImode: |
fb4d4348 GK |
2714 | /* Use default pattern for address of ELF small data */ |
2715 | if (TARGET_ELF | |
a9098fd0 | 2716 | && mode == Pmode |
f607bc57 | 2717 | && DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
2718 | && (GET_CODE (operands[1]) == SYMBOL_REF |
2719 | || GET_CODE (operands[1]) == CONST) | |
2720 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
2721 | { |
2722 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
2723 | return; | |
2724 | } | |
2725 | ||
f607bc57 | 2726 | if (DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
2727 | && mode == Pmode && mode == SImode |
2728 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
2729 | { |
2730 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
2731 | return; | |
2732 | } | |
2733 | ||
ee890fe2 SS |
2734 | if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN) |
2735 | && TARGET_NO_TOC && ! flag_pic | |
a9098fd0 | 2736 | && mode == Pmode |
fb4d4348 GK |
2737 | && CONSTANT_P (operands[1]) |
2738 | && GET_CODE (operands[1]) != HIGH | |
2739 | && GET_CODE (operands[1]) != CONST_INT) | |
2740 | { | |
a9098fd0 | 2741 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
2742 | |
2743 | /* If this is a function address on -mcall-aixdesc, | |
2744 | convert it to the address of the descriptor. */ | |
2745 | if (DEFAULT_ABI == ABI_AIX | |
2746 | && GET_CODE (operands[1]) == SYMBOL_REF | |
2747 | && XSTR (operands[1], 0)[0] == '.') | |
2748 | { | |
2749 | const char *name = XSTR (operands[1], 0); | |
2750 | rtx new_ref; | |
2751 | while (*name == '.') | |
2752 | name++; | |
2753 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
2754 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
2755 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
2756 | SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]); | |
2757 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); | |
2758 | operands[1] = new_ref; | |
2759 | } | |
7509c759 | 2760 | |
ee890fe2 SS |
2761 | if (DEFAULT_ABI == ABI_DARWIN) |
2762 | { | |
2763 | emit_insn (gen_macho_high (target, operands[1])); | |
2764 | emit_insn (gen_macho_low (operands[0], target, operands[1])); | |
2765 | return; | |
2766 | } | |
2767 | ||
fb4d4348 GK |
2768 | emit_insn (gen_elf_high (target, operands[1])); |
2769 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
2770 | return; | |
2771 | } | |
2772 | ||
a9098fd0 GK |
2773 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
2774 | and we have put it in the TOC, we just need to make a TOC-relative | |
2775 | reference to it. */ | |
2776 | if (TARGET_TOC | |
2777 | && GET_CODE (operands[1]) == SYMBOL_REF | |
2778 | && CONSTANT_POOL_EXPR_P (operands[1]) | |
2779 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), | |
2780 | get_pool_mode (operands[1]))) | |
fb4d4348 | 2781 | { |
a9098fd0 | 2782 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 2783 | } |
a9098fd0 GK |
2784 | else if (mode == Pmode |
2785 | && CONSTANT_P (operands[1]) | |
38886f37 AO |
2786 | && ((GET_CODE (operands[1]) != CONST_INT |
2787 | && ! easy_fp_constant (operands[1], mode)) | |
2788 | || (GET_CODE (operands[1]) == CONST_INT | |
2789 | && num_insns_constant (operands[1], mode) > 2) | |
2790 | || (GET_CODE (operands[0]) == REG | |
2791 | && FP_REGNO_P (REGNO (operands[0])))) | |
a9098fd0 GK |
2792 | && GET_CODE (operands[1]) != HIGH |
2793 | && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]) | |
2794 | && ! TOC_RELATIVE_EXPR_P (operands[1])) | |
fb4d4348 GK |
2795 | { |
2796 | /* Emit a USE operation so that the constant isn't deleted if | |
2797 | expensive optimizations are turned on because nobody | |
2798 | references it. This should only be done for operands that | |
2799 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
2800 | This should not be done for operands that contain LABEL_REFs. | |
2801 | For now, we just handle the obvious case. */ | |
2802 | if (GET_CODE (operands[1]) != LABEL_REF) | |
2803 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
2804 | ||
c859cda6 | 2805 | #if TARGET_MACHO |
ee890fe2 SS |
2806 | /* Darwin uses a special PIC legitimizer. */ |
2807 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic) | |
2808 | { | |
ee890fe2 SS |
2809 | operands[1] = |
2810 | rs6000_machopic_legitimize_pic_address (operands[1], mode, | |
c859cda6 DJ |
2811 | operands[0]); |
2812 | if (operands[0] != operands[1]) | |
2813 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
ee890fe2 SS |
2814 | return; |
2815 | } | |
c859cda6 | 2816 | #endif |
ee890fe2 | 2817 | |
fb4d4348 GK |
2818 | /* If we are to limit the number of things we put in the TOC and |
2819 | this is a symbol plus a constant we can add in one insn, | |
2820 | just put the symbol in the TOC and add the constant. Don't do | |
2821 | this if reload is in progress. */ | |
2822 | if (GET_CODE (operands[1]) == CONST | |
2823 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
2824 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 2825 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
2826 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
2827 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
2828 | && ! side_effects_p (operands[0])) | |
2829 | { | |
a4f6c312 SS |
2830 | rtx sym = |
2831 | force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); | |
fb4d4348 GK |
2832 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
2833 | ||
a9098fd0 GK |
2834 | sym = force_reg (mode, sym); |
2835 | if (mode == SImode) | |
2836 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
2837 | else | |
2838 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
2839 | return; |
2840 | } | |
2841 | ||
a9098fd0 | 2842 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
2843 | |
2844 | if (TARGET_TOC | |
d34c5b80 DE |
2845 | && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0)) |
2846 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P ( | |
2847 | get_pool_constant (XEXP (operands[1], 0)), | |
2848 | get_pool_mode (XEXP (operands[1], 0)))) | |
a9098fd0 | 2849 | { |
ba4828e0 RK |
2850 | operands[1] |
2851 | = gen_rtx_MEM (mode, | |
2852 | create_TOC_reference (XEXP (operands[1], 0))); | |
2853 | set_mem_alias_set (operands[1], get_TOC_alias_set ()); | |
fb4d4348 | 2854 | RTX_UNCHANGING_P (operands[1]) = 1; |
a9098fd0 | 2855 | } |
fb4d4348 GK |
2856 | } |
2857 | break; | |
a9098fd0 | 2858 | |
fb4d4348 GK |
2859 | case TImode: |
2860 | if (GET_CODE (operands[0]) == MEM | |
2861 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
2862 | && ! reload_in_progress) | |
792760b9 RK |
2863 | operands[0] |
2864 | = replace_equiv_address (operands[0], | |
2865 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
fb4d4348 GK |
2866 | |
2867 | if (GET_CODE (operands[1]) == MEM | |
2868 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
2869 | && ! reload_in_progress) | |
792760b9 RK |
2870 | operands[1] |
2871 | = replace_equiv_address (operands[1], | |
2872 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
27dc0551 DE |
2873 | if (TARGET_POWER) |
2874 | { | |
2875 | emit_insn (gen_rtx_PARALLEL (VOIDmode, | |
2876 | gen_rtvec (2, | |
2877 | gen_rtx_SET (VOIDmode, | |
2878 | operands[0], operands[1]), | |
2879 | gen_rtx_CLOBBER (VOIDmode, | |
2880 | gen_rtx_SCRATCH (SImode))))); | |
2881 | return; | |
2882 | } | |
fb4d4348 GK |
2883 | break; |
2884 | ||
2885 | default: | |
2886 | abort (); | |
2887 | } | |
2888 | ||
a9098fd0 GK |
2889 | /* Above, we may have called force_const_mem which may have returned |
2890 | an invalid address. If we can, fix this up; otherwise, reload will | |
2891 | have to deal with it. */ | |
2892 | if (GET_CODE (operands[1]) == MEM | |
2893 | && ! memory_address_p (mode, XEXP (operands[1], 0)) | |
2894 | && ! reload_in_progress) | |
f4ef873c | 2895 | operands[1] = adjust_address (operands[1], mode, 0); |
a9098fd0 | 2896 | |
fb4d4348 | 2897 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
02a4ec28 | 2898 | return; |
fb4d4348 | 2899 | } |
4697a36c MM |
2900 | \f |
2901 | /* Initialize a variable CUM of type CUMULATIVE_ARGS | |
2902 | for a call to a function whose data type is FNTYPE. | |
2903 | For a library call, FNTYPE is 0. | |
2904 | ||
2905 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 2906 | so we never return a PARALLEL. */ |
4697a36c MM |
2907 | |
2908 | void | |
2909 | init_cumulative_args (cum, fntype, libname, incoming) | |
2910 | CUMULATIVE_ARGS *cum; | |
2911 | tree fntype; | |
296b8152 | 2912 | rtx libname ATTRIBUTE_UNUSED; |
4697a36c MM |
2913 | int incoming; |
2914 | { | |
2915 | static CUMULATIVE_ARGS zero_cumulative; | |
2916 | ||
2917 | *cum = zero_cumulative; | |
2918 | cum->words = 0; | |
2919 | cum->fregno = FP_ARG_MIN_REG; | |
0ac081f6 | 2920 | cum->vregno = ALTIVEC_ARG_MIN_REG; |
4697a36c | 2921 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); |
7509c759 | 2922 | cum->call_cookie = CALL_NORMAL; |
4cc833b7 | 2923 | cum->sysv_gregno = GP_ARG_MIN_REG; |
4697a36c MM |
2924 | |
2925 | if (incoming) | |
bd227acc | 2926 | cum->nargs_prototype = 1000; /* don't return a PARALLEL */ |
4697a36c MM |
2927 | |
2928 | else if (cum->prototype) | |
2929 | cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1 | |
2930 | + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode | |
2931 | || RETURN_IN_MEMORY (TREE_TYPE (fntype)))); | |
2932 | ||
2933 | else | |
2934 | cum->nargs_prototype = 0; | |
2935 | ||
2936 | cum->orig_nargs = cum->nargs_prototype; | |
7509c759 | 2937 | |
a5c76ee6 ZW |
2938 | /* Check for a longcall attribute. */ |
2939 | if (fntype | |
2940 | && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) | |
2941 | && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
2942 | cum->call_cookie = CALL_LONG; |
2943 | ||
4697a36c MM |
2944 | if (TARGET_DEBUG_ARG) |
2945 | { | |
2946 | fprintf (stderr, "\ninit_cumulative_args:"); | |
2947 | if (fntype) | |
2948 | { | |
2949 | tree ret_type = TREE_TYPE (fntype); | |
2950 | fprintf (stderr, " ret code = %s,", | |
2951 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
2952 | } | |
2953 | ||
6a4cee5f MM |
2954 | if (cum->call_cookie & CALL_LONG) |
2955 | fprintf (stderr, " longcall,"); | |
2956 | ||
4697a36c MM |
2957 | fprintf (stderr, " proto = %d, nargs = %d\n", |
2958 | cum->prototype, cum->nargs_prototype); | |
2959 | } | |
2960 | } | |
2961 | \f | |
c229cba9 DE |
2962 | /* If defined, a C expression which determines whether, and in which |
2963 | direction, to pad out an argument with extra space. The value | |
2964 | should be of type `enum direction': either `upward' to pad above | |
2965 | the argument, `downward' to pad below, or `none' to inhibit | |
2966 | padding. | |
2967 | ||
2968 | For the AIX ABI structs are always stored left shifted in their | |
2969 | argument slot. */ | |
2970 | ||
9ebbca7d | 2971 | enum direction |
c229cba9 DE |
2972 | function_arg_padding (mode, type) |
2973 | enum machine_mode mode; | |
2974 | tree type; | |
2975 | { | |
c85f7c16 | 2976 | if (type != 0 && AGGREGATE_TYPE_P (type)) |
9ebbca7d | 2977 | return upward; |
c229cba9 DE |
2978 | |
2979 | /* This is the default definition. */ | |
2980 | return (! BYTES_BIG_ENDIAN | |
9ebbca7d | 2981 | ? upward |
c229cba9 DE |
2982 | : ((mode == BLKmode |
2983 | ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST | |
2984 | && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT)) | |
2985 | : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY) | |
9ebbca7d | 2986 | ? downward : upward)); |
c229cba9 DE |
2987 | } |
2988 | ||
b6c9286a MM |
2989 | /* If defined, a C expression that gives the alignment boundary, in bits, |
2990 | of an argument with the specified mode and type. If it is not defined, | |
2991 | PARM_BOUNDARY is used for all arguments. | |
2992 | ||
2310f99a | 2993 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
2994 | |
2995 | int | |
2996 | function_arg_boundary (mode, type) | |
2997 | enum machine_mode mode; | |
9ebbca7d | 2998 | tree type ATTRIBUTE_UNUSED; |
b6c9286a | 2999 | { |
f607bc57 | 3000 | if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode)) |
e1f83b4d | 3001 | return 64; |
a3170dc6 AH |
3002 | else if (SPE_VECTOR_MODE (mode)) |
3003 | return 64; | |
0ac081f6 AH |
3004 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
3005 | return 128; | |
9ebbca7d | 3006 | else |
b6c9286a | 3007 | return PARM_BOUNDARY; |
b6c9286a MM |
3008 | } |
3009 | \f | |
4697a36c MM |
3010 | /* Update the data in CUM to advance over an argument |
3011 | of mode MODE and data type TYPE. | |
3012 | (TYPE is null for libcalls where that information may not be available.) */ | |
3013 | ||
3014 | void | |
3015 | function_arg_advance (cum, mode, type, named) | |
3016 | CUMULATIVE_ARGS *cum; | |
3017 | enum machine_mode mode; | |
3018 | tree type; | |
3019 | int named; | |
3020 | { | |
3021 | cum->nargs_prototype--; | |
3022 | ||
0ac081f6 AH |
3023 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
3024 | { | |
3025 | if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0) | |
3026 | cum->vregno++; | |
3027 | else | |
3028 | cum->words += RS6000_ARG_SIZE (mode, type); | |
3029 | } | |
a4b0320c AH |
3030 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) |
3031 | && named && cum->sysv_gregno <= GP_ARG_MAX_REG) | |
3032 | cum->sysv_gregno++; | |
f607bc57 | 3033 | else if (DEFAULT_ABI == ABI_V4) |
4697a36c | 3034 | { |
a3170dc6 | 3035 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 | 3036 | && (mode == SFmode || mode == DFmode)) |
4697a36c | 3037 | { |
4cc833b7 RH |
3038 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
3039 | cum->fregno++; | |
3040 | else | |
3041 | { | |
3042 | if (mode == DFmode) | |
3043 | cum->words += cum->words & 1; | |
d34c5b80 | 3044 | cum->words += RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 3045 | } |
4697a36c | 3046 | } |
4cc833b7 RH |
3047 | else |
3048 | { | |
3049 | int n_words; | |
3050 | int gregno = cum->sysv_gregno; | |
3051 | ||
3052 | /* Aggregates and IEEE quad get passed by reference. */ | |
3053 | if ((type && AGGREGATE_TYPE_P (type)) | |
3054 | || mode == TFmode) | |
3055 | n_words = 1; | |
3056 | else | |
d34c5b80 | 3057 | n_words = RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 3058 | |
a4b0320c | 3059 | /* Long long and SPE vectors are put in odd registers. */ |
4cc833b7 RH |
3060 | if (n_words == 2 && (gregno & 1) == 0) |
3061 | gregno += 1; | |
3062 | ||
a4b0320c AH |
3063 | /* Long long and SPE vectors are not split between registers |
3064 | and stack. */ | |
4cc833b7 RH |
3065 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
3066 | { | |
3067 | /* Long long is aligned on the stack. */ | |
3068 | if (n_words == 2) | |
3069 | cum->words += cum->words & 1; | |
3070 | cum->words += n_words; | |
3071 | } | |
4697a36c | 3072 | |
4cc833b7 RH |
3073 | /* Note: continuing to accumulate gregno past when we've started |
3074 | spilling to the stack indicates the fact that we've started | |
3075 | spilling to the stack to expand_builtin_saveregs. */ | |
3076 | cum->sysv_gregno = gregno + n_words; | |
3077 | } | |
4697a36c | 3078 | |
4cc833b7 RH |
3079 | if (TARGET_DEBUG_ARG) |
3080 | { | |
3081 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
3082 | cum->words, cum->fregno); | |
3083 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
3084 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
3085 | fprintf (stderr, "mode = %4s, named = %d\n", | |
3086 | GET_MODE_NAME (mode), named); | |
3087 | } | |
4697a36c MM |
3088 | } |
3089 | else | |
4cc833b7 RH |
3090 | { |
3091 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
3092 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
a4f6c312 | 3093 | |
d34c5b80 | 3094 | cum->words += align + RS6000_ARG_SIZE (mode, type); |
4697a36c | 3095 | |
a3170dc6 AH |
3096 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
3097 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
fcce224d | 3098 | cum->fregno += (mode == TFmode ? 2 : 1); |
4cc833b7 RH |
3099 | |
3100 | if (TARGET_DEBUG_ARG) | |
3101 | { | |
3102 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
3103 | cum->words, cum->fregno); | |
3104 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
3105 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
3106 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
3107 | } | |
3108 | } | |
4697a36c MM |
3109 | } |
3110 | \f | |
3111 | /* Determine where to put an argument to a function. | |
3112 | Value is zero to push the argument on the stack, | |
3113 | or a hard register in which to store the argument. | |
3114 | ||
3115 | MODE is the argument's machine mode. | |
3116 | TYPE is the data type of the argument (as a tree). | |
3117 | This is null for libcalls where that information may | |
3118 | not be available. | |
3119 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
3120 | the preceding args and about the function being called. | |
3121 | NAMED is nonzero if this argument is a named parameter | |
3122 | (otherwise it is an extra parameter matching an ellipsis). | |
3123 | ||
3124 | On RS/6000 the first eight words of non-FP are normally in registers | |
3125 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
3126 | Under V.4, the first 8 FP args are in registers. | |
3127 | ||
3128 | If this is floating-point and no prototype is specified, we use | |
3129 | both an FP and integer register (or possibly FP reg and stack). Library | |
3130 | functions (when TYPE is zero) always have the proper types for args, | |
3131 | so we can pass the FP value just in one register. emit_library_function | |
1c20ae99 | 3132 | doesn't support PARALLEL anyway. */ |
4697a36c MM |
3133 | |
3134 | struct rtx_def * | |
3135 | function_arg (cum, mode, type, named) | |
3136 | CUMULATIVE_ARGS *cum; | |
3137 | enum machine_mode mode; | |
3138 | tree type; | |
20c29ebe | 3139 | int named; |
4697a36c | 3140 | { |
4cc833b7 | 3141 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 3142 | |
a4f6c312 SS |
3143 | /* Return a marker to indicate whether CR1 needs to set or clear the |
3144 | bit that V.4 uses to say fp args were passed in registers. | |
3145 | Assume that we don't need the marker for software floating point, | |
3146 | or compiler generated library calls. */ | |
4697a36c MM |
3147 | if (mode == VOIDmode) |
3148 | { | |
f607bc57 | 3149 | if (abi == ABI_V4 |
7509c759 | 3150 | && cum->nargs_prototype < 0 |
4697a36c | 3151 | && type && (cum->prototype || TARGET_NO_PROTOTYPE)) |
7509c759 | 3152 | { |
a3170dc6 AH |
3153 | /* For the SPE, we need to crxor CR6 always. */ |
3154 | if (TARGET_SPE_ABI) | |
3155 | return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS); | |
3156 | else if (TARGET_HARD_FLOAT && TARGET_FPRS) | |
3157 | return GEN_INT (cum->call_cookie | |
3158 | | ((cum->fregno == FP_ARG_MIN_REG) | |
3159 | ? CALL_V4_SET_FP_ARGS | |
3160 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 3161 | } |
4697a36c | 3162 | |
7509c759 | 3163 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
3164 | } |
3165 | ||
0ac081f6 AH |
3166 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
3167 | { | |
20c29ebe | 3168 | if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG) |
0ac081f6 AH |
3169 | return gen_rtx_REG (mode, cum->vregno); |
3170 | else | |
3171 | return NULL; | |
3172 | } | |
a4b0320c | 3173 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) && named) |
a3170dc6 | 3174 | { |
a4b0320c | 3175 | if (cum->sysv_gregno <= GP_ARG_MAX_REG) |
a3170dc6 AH |
3176 | return gen_rtx_REG (mode, cum->sysv_gregno); |
3177 | else | |
3178 | return NULL; | |
3179 | } | |
f607bc57 | 3180 | else if (abi == ABI_V4) |
4697a36c | 3181 | { |
a3170dc6 | 3182 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 RH |
3183 | && (mode == SFmode || mode == DFmode)) |
3184 | { | |
3185 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
3186 | return gen_rtx_REG (mode, cum->fregno); | |
3187 | else | |
3188 | return NULL; | |
3189 | } | |
3190 | else | |
3191 | { | |
3192 | int n_words; | |
3193 | int gregno = cum->sysv_gregno; | |
3194 | ||
3195 | /* Aggregates and IEEE quad get passed by reference. */ | |
3196 | if ((type && AGGREGATE_TYPE_P (type)) | |
3197 | || mode == TFmode) | |
3198 | n_words = 1; | |
3199 | else | |
d34c5b80 | 3200 | n_words = RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 3201 | |
a4b0320c | 3202 | /* Long long and SPE vectors are put in odd registers. */ |
4cc833b7 RH |
3203 | if (n_words == 2 && (gregno & 1) == 0) |
3204 | gregno += 1; | |
3205 | ||
a4b0320c AH |
3206 | /* Long long and SPE vectors are not split between registers |
3207 | and stack. */ | |
4cc833b7 | 3208 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) |
a4b0320c AH |
3209 | { |
3210 | /* SPE vectors in ... get split into 2 registers. */ | |
3211 | if (TARGET_SPE && TARGET_SPE_ABI | |
3212 | && SPE_VECTOR_MODE (mode) && !named) | |
3213 | { | |
3214 | rtx r1, r2; | |
57de2c8f | 3215 | enum machine_mode m = SImode; |
f9dd72da | 3216 | |
a4b0320c AH |
3217 | r1 = gen_rtx_REG (m, gregno); |
3218 | r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx); | |
3219 | r2 = gen_rtx_REG (m, gregno + 1); | |
3220 | r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4)); | |
3221 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); | |
3222 | } | |
3223 | return gen_rtx_REG (mode, gregno); | |
3224 | } | |
4cc833b7 RH |
3225 | else |
3226 | return NULL; | |
3227 | } | |
4697a36c | 3228 | } |
4cc833b7 RH |
3229 | else |
3230 | { | |
3231 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
3232 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
3233 | int align_words = cum->words + align; | |
4697a36c | 3234 | |
4cc833b7 RH |
3235 | if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
3236 | return NULL_RTX; | |
3237 | ||
3238 | if (USE_FP_FOR_ARG_P (*cum, mode, type)) | |
3239 | { | |
3240 | if (! type | |
3241 | || ((cum->nargs_prototype > 0) | |
3242 | /* IBM AIX extended its linkage convention definition always | |
3243 | to require FP args after register save area hole on the | |
3244 | stack. */ | |
3245 | && (DEFAULT_ABI != ABI_AIX | |
3246 | || ! TARGET_XL_CALL | |
3247 | || (align_words < GP_ARG_NUM_REG)))) | |
3248 | return gen_rtx_REG (mode, cum->fregno); | |
3249 | ||
3250 | return gen_rtx_PARALLEL (mode, | |
3251 | gen_rtvec (2, | |
39403d82 | 3252 | gen_rtx_EXPR_LIST (VOIDmode, |
1c20ae99 JW |
3253 | ((align_words >= GP_ARG_NUM_REG) |
3254 | ? NULL_RTX | |
3255 | : (align_words | |
d34c5b80 | 3256 | + RS6000_ARG_SIZE (mode, type) |
1c20ae99 JW |
3257 | > GP_ARG_NUM_REG |
3258 | /* If this is partially on the stack, then | |
3259 | we only include the portion actually | |
3260 | in registers here. */ | |
39403d82 | 3261 | ? gen_rtx_REG (SImode, |
1c20ae99 | 3262 | GP_ARG_MIN_REG + align_words) |
39403d82 | 3263 | : gen_rtx_REG (mode, |
1c20ae99 JW |
3264 | GP_ARG_MIN_REG + align_words))), |
3265 | const0_rtx), | |
39403d82 DE |
3266 | gen_rtx_EXPR_LIST (VOIDmode, |
3267 | gen_rtx_REG (mode, cum->fregno), | |
1c20ae99 | 3268 | const0_rtx))); |
4cc833b7 RH |
3269 | } |
3270 | else if (align_words < GP_ARG_NUM_REG) | |
3271 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
3272 | else | |
3273 | return NULL_RTX; | |
4697a36c | 3274 | } |
4697a36c MM |
3275 | } |
3276 | \f | |
3277 | /* For an arg passed partly in registers and partly in memory, | |
3278 | this is the number of registers used. | |
3279 | For args passed entirely in registers or entirely in memory, zero. */ | |
3280 | ||
3281 | int | |
3282 | function_arg_partial_nregs (cum, mode, type, named) | |
3283 | CUMULATIVE_ARGS *cum; | |
3284 | enum machine_mode mode; | |
3285 | tree type; | |
d34c5b80 | 3286 | int named ATTRIBUTE_UNUSED; |
4697a36c | 3287 | { |
f607bc57 | 3288 | if (DEFAULT_ABI == ABI_V4) |
4697a36c | 3289 | return 0; |
4697a36c | 3290 | |
0ac081f6 AH |
3291 | if (USE_FP_FOR_ARG_P (*cum, mode, type) |
3292 | || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type)) | |
4697a36c MM |
3293 | { |
3294 | if (cum->nargs_prototype >= 0) | |
3295 | return 0; | |
3296 | } | |
3297 | ||
3298 | if (cum->words < GP_ARG_NUM_REG | |
d34c5b80 | 3299 | && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type))) |
4697a36c MM |
3300 | { |
3301 | int ret = GP_ARG_NUM_REG - cum->words; | |
3302 | if (ret && TARGET_DEBUG_ARG) | |
3303 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
3304 | ||
3305 | return ret; | |
3306 | } | |
3307 | ||
3308 | return 0; | |
3309 | } | |
3310 | \f | |
3311 | /* A C expression that indicates when an argument must be passed by | |
3312 | reference. If nonzero for an argument, a copy of that argument is | |
3313 | made in memory and a pointer to the argument is passed instead of | |
3314 | the argument itself. The pointer is passed in whatever way is | |
3315 | appropriate for passing a pointer to that type. | |
3316 | ||
c8c99a68 DE |
3317 | Under V.4, structures and unions are passed by reference. |
3318 | ||
3319 | As an extension to all ABIs, variable sized types are passed by | |
3320 | reference. */ | |
4697a36c MM |
3321 | |
3322 | int | |
3323 | function_arg_pass_by_reference (cum, mode, type, named) | |
296b8152 KG |
3324 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; |
3325 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4697a36c | 3326 | tree type; |
296b8152 | 3327 | int named ATTRIBUTE_UNUSED; |
4697a36c | 3328 | { |
f607bc57 | 3329 | if (DEFAULT_ABI == ABI_V4 |
4cc833b7 RH |
3330 | && ((type && AGGREGATE_TYPE_P (type)) |
3331 | || mode == TFmode)) | |
4697a36c MM |
3332 | { |
3333 | if (TARGET_DEBUG_ARG) | |
3334 | fprintf (stderr, "function_arg_pass_by_reference: aggregate\n"); | |
3335 | ||
3336 | return 1; | |
3337 | } | |
c8c99a68 | 3338 | return type && int_size_in_bytes (type) <= 0; |
4697a36c | 3339 | } |
4697a36c MM |
3340 | \f |
3341 | /* Perform any needed actions needed for a function that is receiving a | |
3342 | variable number of arguments. | |
3343 | ||
3344 | CUM is as above. | |
3345 | ||
3346 | MODE and TYPE are the mode and type of the current parameter. | |
3347 | ||
3348 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
3349 | that must be pushed by the prolog to pretend that our caller pushed | |
3350 | it. | |
3351 | ||
3352 | Normally, this macro will push all remaining incoming registers on the | |
3353 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
3354 | ||
3355 | void | |
3356 | setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl) | |
3357 | CUMULATIVE_ARGS *cum; | |
3358 | enum machine_mode mode; | |
3359 | tree type; | |
de62b72c | 3360 | int *pretend_size ATTRIBUTE_UNUSED; |
4697a36c MM |
3361 | int no_rtl; |
3362 | ||
3363 | { | |
4cc833b7 RH |
3364 | CUMULATIVE_ARGS next_cum; |
3365 | int reg_size = TARGET_32BIT ? 4 : 8; | |
ca5adc63 | 3366 | rtx save_area = NULL_RTX, mem; |
dfafc897 | 3367 | int first_reg_offset, set; |
d34c5b80 DE |
3368 | tree fntype; |
3369 | int stdarg_p; | |
4697a36c | 3370 | |
d34c5b80 DE |
3371 | fntype = TREE_TYPE (current_function_decl); |
3372 | stdarg_p = (TYPE_ARG_TYPES (fntype) != 0 | |
3373 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
3374 | != void_type_node)); | |
4cc833b7 | 3375 | |
d34c5b80 DE |
3376 | /* For varargs, we do not want to skip the dummy va_dcl argument. |
3377 | For stdargs, we do want to skip the last named argument. */ | |
3378 | next_cum = *cum; | |
3379 | if (stdarg_p) | |
3380 | function_arg_advance (&next_cum, mode, type, 1); | |
4cc833b7 | 3381 | |
f607bc57 | 3382 | if (DEFAULT_ABI == ABI_V4) |
d34c5b80 | 3383 | { |
4cc833b7 | 3384 | /* Indicate to allocate space on the stack for varargs save area. */ |
00dba523 | 3385 | cfun->machine->sysv_varargs_p = 1; |
60e2d0ca | 3386 | if (! no_rtl) |
2c4974b7 | 3387 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 3388 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
3389 | |
3390 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 3391 | } |
60e2d0ca | 3392 | else |
4697a36c | 3393 | { |
d34c5b80 | 3394 | first_reg_offset = next_cum.words; |
4cc833b7 | 3395 | save_area = virtual_incoming_args_rtx; |
00dba523 | 3396 | cfun->machine->sysv_varargs_p = 0; |
4697a36c MM |
3397 | |
3398 | if (MUST_PASS_IN_STACK (mode, type)) | |
d34c5b80 | 3399 | first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type); |
4cc833b7 | 3400 | } |
4697a36c | 3401 | |
dfafc897 | 3402 | set = get_varargs_alias_set (); |
c81fc13e | 3403 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 3404 | { |
dfafc897 FS |
3405 | mem = gen_rtx_MEM (BLKmode, |
3406 | plus_constant (save_area, | |
3407 | first_reg_offset * reg_size)), | |
ba4828e0 | 3408 | set_mem_alias_set (mem, set); |
8ac61af7 | 3409 | set_mem_align (mem, BITS_PER_WORD); |
dfafc897 | 3410 | |
4cc833b7 | 3411 | move_block_from_reg |
dfafc897 | 3412 | (GP_ARG_MIN_REG + first_reg_offset, mem, |
4cc833b7 RH |
3413 | GP_ARG_NUM_REG - first_reg_offset, |
3414 | (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD); | |
4697a36c MM |
3415 | } |
3416 | ||
4697a36c | 3417 | /* Save FP registers if needed. */ |
f607bc57 | 3418 | if (DEFAULT_ABI == ABI_V4 |
a3170dc6 AH |
3419 | && TARGET_HARD_FLOAT && TARGET_FPRS |
3420 | && ! no_rtl | |
4cc833b7 | 3421 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 3422 | { |
4cc833b7 | 3423 | int fregno = next_cum.fregno; |
9ebbca7d | 3424 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
3425 | rtx lab = gen_label_rtx (); |
3426 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 3427 | |
4cc833b7 | 3428 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 3429 | pc_rtx, |
39403d82 | 3430 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
3431 | gen_rtx_NE (VOIDmode, cr1, |
3432 | const0_rtx), | |
39403d82 | 3433 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
3434 | pc_rtx))); |
3435 | ||
4cc833b7 RH |
3436 | while (fregno <= FP_ARG_V4_MAX_REG) |
3437 | { | |
dfafc897 | 3438 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
ba4828e0 | 3439 | set_mem_alias_set (mem, set); |
dfafc897 | 3440 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); |
4cc833b7 RH |
3441 | fregno++; |
3442 | off += 8; | |
4697a36c | 3443 | } |
4cc833b7 RH |
3444 | |
3445 | emit_label (lab); | |
4697a36c | 3446 | } |
4697a36c | 3447 | } |
4697a36c | 3448 | |
dfafc897 | 3449 | /* Create the va_list data type. */ |
2c4974b7 | 3450 | |
dfafc897 FS |
3451 | tree |
3452 | rs6000_build_va_list () | |
3453 | { | |
bab45a51 | 3454 | tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl; |
4697a36c | 3455 | |
9ebbca7d GK |
3456 | /* For AIX, prefer 'char *' because that's what the system |
3457 | header files like. */ | |
f607bc57 | 3458 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d | 3459 | return build_pointer_type (char_type_node); |
dfafc897 | 3460 | |
f1e639b1 | 3461 | record = (*lang_hooks.types.make_type) (RECORD_TYPE); |
bab45a51 | 3462 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 3463 | |
9ebbca7d GK |
3464 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
3465 | unsigned_char_type_node); | |
3466 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), | |
3467 | unsigned_char_type_node); | |
dfafc897 FS |
3468 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
3469 | ptr_type_node); | |
3470 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
3471 | ptr_type_node); | |
3472 | ||
3473 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
3474 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
3475 | DECL_FIELD_CONTEXT (f_ovf) = record; | |
3476 | DECL_FIELD_CONTEXT (f_sav) = record; | |
3477 | ||
bab45a51 FS |
3478 | TREE_CHAIN (record) = type_decl; |
3479 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
3480 | TYPE_FIELDS (record) = f_gpr; |
3481 | TREE_CHAIN (f_gpr) = f_fpr; | |
3482 | TREE_CHAIN (f_fpr) = f_ovf; | |
3483 | TREE_CHAIN (f_ovf) = f_sav; | |
3484 | ||
3485 | layout_type (record); | |
3486 | ||
3487 | /* The correct type is an array type of one element. */ | |
3488 | return build_array_type (record, build_index_type (size_zero_node)); | |
3489 | } | |
3490 | ||
3491 | /* Implement va_start. */ | |
3492 | ||
3493 | void | |
e5faf155 | 3494 | rs6000_va_start (valist, nextarg) |
dfafc897 FS |
3495 | tree valist; |
3496 | rtx nextarg; | |
4697a36c | 3497 | { |
dfafc897 FS |
3498 | HOST_WIDE_INT words, n_gpr, n_fpr; |
3499 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
3500 | tree gpr, fpr, ovf, sav, t; | |
2c4974b7 | 3501 | |
dfafc897 | 3502 | /* Only SVR4 needs something special. */ |
f607bc57 | 3503 | if (DEFAULT_ABI != ABI_V4) |
dfafc897 | 3504 | { |
e5faf155 | 3505 | std_expand_builtin_va_start (valist, nextarg); |
dfafc897 FS |
3506 | return; |
3507 | } | |
3508 | ||
973a648b | 3509 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 FS |
3510 | f_fpr = TREE_CHAIN (f_gpr); |
3511 | f_ovf = TREE_CHAIN (f_fpr); | |
3512 | f_sav = TREE_CHAIN (f_ovf); | |
3513 | ||
8ebecc3b | 3514 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
3515 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
3516 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
3517 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
3518 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
3519 | ||
3520 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 3521 | words = current_function_args_info.words; |
dfafc897 FS |
3522 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
3523 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
3524 | ||
3525 | if (TARGET_DEBUG_ARG) | |
78e1b90d DE |
3526 | { |
3527 | fputs ("va_start: words = ", stderr); | |
3528 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words); | |
3529 | fputs (", n_gpr = ", stderr); | |
3530 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr); | |
3531 | fputs (", n_fpr = ", stderr); | |
3532 | fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr); | |
3533 | putc ('\n', stderr); | |
3534 | } | |
dfafc897 FS |
3535 | |
3536 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
3537 | TREE_SIDE_EFFECTS (t) = 1; | |
3538 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3539 | ||
3540 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
3541 | TREE_SIDE_EFFECTS (t) = 1; | |
3542 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3543 | ||
3544 | /* Find the overflow area. */ | |
3545 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
3546 | if (words != 0) | |
3547 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
3548 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
3549 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
3550 | TREE_SIDE_EFFECTS (t) = 1; | |
3551 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3552 | ||
3553 | /* Find the register save area. */ | |
3554 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
3555 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
3556 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
3557 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
3558 | TREE_SIDE_EFFECTS (t) = 1; | |
3559 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3560 | } | |
3561 | ||
3562 | /* Implement va_arg. */ | |
3563 | ||
3564 | rtx | |
3565 | rs6000_va_arg (valist, type) | |
3566 | tree valist, type; | |
3567 | { | |
3568 | tree f_gpr, f_fpr, f_ovf, f_sav; | |
3569 | tree gpr, fpr, ovf, sav, reg, t, u; | |
3570 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
3571 | rtx lab_false, lab_over, addr_rtx, r; | |
3572 | ||
f607bc57 | 3573 | if (DEFAULT_ABI != ABI_V4) |
c8c99a68 DE |
3574 | { |
3575 | /* Variable sized types are passed by reference. */ | |
3576 | if (int_size_in_bytes (type) <= 0) | |
3577 | { | |
3578 | u = build_pointer_type (type); | |
3579 | ||
3580 | /* Args grow upward. */ | |
3581 | t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist, | |
3582 | build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0)); | |
3583 | TREE_SIDE_EFFECTS (t) = 1; | |
3584 | ||
3585 | t = build1 (NOP_EXPR, build_pointer_type (u), t); | |
3586 | TREE_SIDE_EFFECTS (t) = 1; | |
3587 | ||
3588 | t = build1 (INDIRECT_REF, u, t); | |
3589 | TREE_SIDE_EFFECTS (t) = 1; | |
3590 | ||
3591 | return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL); | |
3592 | } | |
3593 | else | |
3594 | return std_expand_builtin_va_arg (valist, type); | |
3595 | } | |
dfafc897 | 3596 | |
973a648b | 3597 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 FS |
3598 | f_fpr = TREE_CHAIN (f_gpr); |
3599 | f_ovf = TREE_CHAIN (f_fpr); | |
3600 | f_sav = TREE_CHAIN (f_ovf); | |
3601 | ||
8ebecc3b | 3602 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
3603 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
3604 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
3605 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
3606 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
3607 | ||
3608 | size = int_size_in_bytes (type); | |
3609 | rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
4cc833b7 | 3610 | |
dfafc897 | 3611 | if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode) |
4cc833b7 | 3612 | { |
dfafc897 FS |
3613 | /* Aggregates and long doubles are passed by reference. */ |
3614 | indirect_p = 1; | |
3615 | reg = gpr; | |
3616 | n_reg = 1; | |
3617 | sav_ofs = 0; | |
3618 | sav_scale = 4; | |
d3294cd9 FS |
3619 | size = UNITS_PER_WORD; |
3620 | rsize = 1; | |
dfafc897 | 3621 | } |
a3170dc6 | 3622 | else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS) |
dfafc897 FS |
3623 | { |
3624 | /* FP args go in FP registers, if present. */ | |
3625 | indirect_p = 0; | |
3626 | reg = fpr; | |
3627 | n_reg = 1; | |
3628 | sav_ofs = 8*4; | |
3629 | sav_scale = 8; | |
4cc833b7 | 3630 | } |
dfafc897 FS |
3631 | else |
3632 | { | |
3633 | /* Otherwise into GP registers. */ | |
3634 | indirect_p = 0; | |
3635 | reg = gpr; | |
3636 | n_reg = rsize; | |
3637 | sav_ofs = 0; | |
3638 | sav_scale = 4; | |
3639 | } | |
3640 | ||
a4f6c312 | 3641 | /* Pull the value out of the saved registers ... */ |
dfafc897 FS |
3642 | |
3643 | lab_false = gen_label_rtx (); | |
3644 | lab_over = gen_label_rtx (); | |
3645 | addr_rtx = gen_reg_rtx (Pmode); | |
3646 | ||
16861f33 AH |
3647 | /* AltiVec vectors never go in registers. */ |
3648 | if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE) | |
2c4974b7 | 3649 | { |
41daaf0e AH |
3650 | TREE_THIS_VOLATILE (reg) = 1; |
3651 | emit_cmp_and_jump_insns | |
3652 | (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL), | |
3653 | GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1, | |
3654 | lab_false); | |
dfafc897 | 3655 | |
41daaf0e AH |
3656 | /* Long long is aligned in the registers. */ |
3657 | if (n_reg > 1) | |
3658 | { | |
3659 | u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg, | |
3660 | build_int_2 (n_reg - 1, 0)); | |
3661 | u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u); | |
3662 | u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u); | |
3663 | TREE_SIDE_EFFECTS (u) = 1; | |
3664 | expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3665 | } | |
2c4974b7 | 3666 | |
41daaf0e AH |
3667 | if (sav_ofs) |
3668 | t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
3669 | else | |
3670 | t = sav; | |
2c4974b7 | 3671 | |
41daaf0e AH |
3672 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, |
3673 | build_int_2 (n_reg, 0)); | |
3674 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 3675 | |
41daaf0e AH |
3676 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
3677 | TREE_SIDE_EFFECTS (u) = 1; | |
dfafc897 | 3678 | |
41daaf0e AH |
3679 | u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); |
3680 | TREE_SIDE_EFFECTS (u) = 1; | |
dfafc897 | 3681 | |
41daaf0e AH |
3682 | t = build (PLUS_EXPR, ptr_type_node, t, u); |
3683 | TREE_SIDE_EFFECTS (t) = 1; | |
3684 | ||
3685 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
3686 | if (r != addr_rtx) | |
3687 | emit_move_insn (addr_rtx, r); | |
3688 | ||
3689 | emit_jump_insn (gen_jump (lab_over)); | |
3690 | emit_barrier (); | |
3691 | } | |
dfafc897 | 3692 | |
dfafc897 FS |
3693 | emit_label (lab_false); |
3694 | ||
a4f6c312 | 3695 | /* ... otherwise out of the overflow area. */ |
dfafc897 | 3696 | |
41daaf0e AH |
3697 | /* Make sure we don't find reg 7 for the next int arg. |
3698 | ||
3699 | All AltiVec vectors go in the overflow area. So in the AltiVec | |
3700 | case we need to get the vectors from the overflow area, but | |
3701 | remember where the GPRs and FPRs are. */ | |
16861f33 AH |
3702 | if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE |
3703 | || !TARGET_ALTIVEC)) | |
dfafc897 FS |
3704 | { |
3705 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
3706 | TREE_SIDE_EFFECTS (t) = 1; | |
3707 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3708 | } | |
3709 | ||
3710 | /* Care for on-stack alignment if needed. */ | |
3711 | if (rsize <= 1) | |
3712 | t = ovf; | |
3713 | else | |
3714 | { | |
41daaf0e AH |
3715 | int align; |
3716 | ||
16861f33 AH |
3717 | /* AltiVec vectors are 16 byte aligned. */ |
3718 | if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE) | |
41daaf0e AH |
3719 | align = 15; |
3720 | else | |
3721 | align = 7; | |
3722 | ||
3723 | t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0)); | |
3724 | t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1)); | |
dfafc897 FS |
3725 | } |
3726 | t = save_expr (t); | |
3727 | ||
3728 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
3729 | if (r != addr_rtx) | |
3730 | emit_move_insn (addr_rtx, r); | |
3731 | ||
3732 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
3733 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
3734 | TREE_SIDE_EFFECTS (t) = 1; | |
3735 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
3736 | ||
3737 | emit_label (lab_over); | |
3738 | ||
3739 | if (indirect_p) | |
3740 | { | |
3741 | r = gen_rtx_MEM (Pmode, addr_rtx); | |
ba4828e0 | 3742 | set_mem_alias_set (r, get_varargs_alias_set ()); |
dfafc897 FS |
3743 | emit_move_insn (addr_rtx, r); |
3744 | } | |
3745 | ||
3746 | return addr_rtx; | |
4697a36c | 3747 | } |
0ac081f6 AH |
3748 | |
3749 | /* Builtins. */ | |
3750 | ||
6a2dd09a RS |
3751 | #define def_builtin(MASK, NAME, TYPE, CODE) \ |
3752 | do { \ | |
3753 | if ((MASK) & target_flags) \ | |
3754 | builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \ | |
3755 | NULL, NULL_TREE); \ | |
0ac081f6 AH |
3756 | } while (0) |
3757 | ||
24408032 AH |
3758 | /* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */ |
3759 | ||
2212663f | 3760 | static const struct builtin_description bdesc_3arg[] = |
24408032 AH |
3761 | { |
3762 | { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP }, | |
3763 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS }, | |
3764 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS }, | |
3765 | { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM}, | |
3766 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM }, | |
3767 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM }, | |
3768 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM }, | |
3769 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM }, | |
3770 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS }, | |
3771 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS }, | |
3772 | { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP }, | |
3773 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF }, | |
3774 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI }, | |
3775 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI }, | |
3776 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI }, | |
3777 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF }, | |
3778 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI }, | |
3779 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI }, | |
3780 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI }, | |
3781 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI }, | |
3782 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI }, | |
3783 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI }, | |
3784 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF }, | |
3785 | }; | |
2212663f | 3786 | |
95385cbb AH |
3787 | /* DST operations: void foo (void *, const int, const char). */ |
3788 | ||
3789 | static const struct builtin_description bdesc_dst[] = | |
3790 | { | |
3791 | { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST }, | |
3792 | { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT }, | |
3793 | { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST }, | |
3794 | { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT } | |
3795 | }; | |
3796 | ||
2212663f | 3797 | /* Simple binary operations: VECc = foo (VECa, VECb). */ |
24408032 | 3798 | |
a3170dc6 | 3799 | static struct builtin_description bdesc_2arg[] = |
0ac081f6 | 3800 | { |
f18c054f DB |
3801 | { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM }, |
3802 | { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM }, | |
3803 | { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM }, | |
3804 | { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP }, | |
0ac081f6 AH |
3805 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW }, |
3806 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS }, | |
3807 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS }, | |
3808 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS }, | |
3809 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS }, | |
3810 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS }, | |
3811 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS }, | |
f18c054f | 3812 | { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND }, |
0ac081f6 AH |
3813 | { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC }, |
3814 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB }, | |
3815 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB }, | |
3816 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH }, | |
3817 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH }, | |
3818 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW }, | |
3819 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW }, | |
617e0e1d DB |
3820 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX }, |
3821 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX }, | |
0ac081f6 AH |
3822 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP }, |
3823 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB }, | |
3824 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH }, | |
3825 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW }, | |
3826 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP }, | |
3827 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP }, | |
3828 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB }, | |
3829 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB }, | |
3830 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH }, | |
3831 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH }, | |
3832 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW }, | |
3833 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW }, | |
3834 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP }, | |
617e0e1d DB |
3835 | { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS }, |
3836 | { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS }, | |
f18c054f DB |
3837 | { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB }, |
3838 | { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB }, | |
df966bff AH |
3839 | { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH }, |
3840 | { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH }, | |
3841 | { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW }, | |
3842 | { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW }, | |
3843 | { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP }, | |
0ac081f6 AH |
3844 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB }, |
3845 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH }, | |
3846 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW }, | |
3847 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB }, | |
3848 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH }, | |
3849 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW }, | |
f18c054f DB |
3850 | { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB }, |
3851 | { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB }, | |
3852 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH }, | |
3853 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH }, | |
3854 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW }, | |
3855 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW }, | |
3856 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP }, | |
0ac081f6 AH |
3857 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB }, |
3858 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB }, | |
3859 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH }, | |
3860 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH }, | |
3861 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB }, | |
3862 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB }, | |
3863 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH }, | |
3864 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH }, | |
3865 | { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR }, | |
f18c054f | 3866 | { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR }, |
0ac081f6 AH |
3867 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM }, |
3868 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM }, | |
3869 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX }, | |
3870 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS }, | |
3871 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS }, | |
3872 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS }, | |
3873 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS }, | |
3874 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS }, | |
3875 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS }, | |
3876 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS }, | |
3877 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS }, | |
3878 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB }, | |
3879 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH }, | |
3880 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW }, | |
3881 | { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB }, | |
3882 | { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH }, | |
3883 | { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW }, | |
3884 | { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL }, | |
3885 | { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO }, | |
2212663f DB |
3886 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB }, |
3887 | { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH }, | |
3888 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW }, | |
0ac081f6 | 3889 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB }, |
f18c054f DB |
3890 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH }, |
3891 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW }, | |
0ac081f6 AH |
3892 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB }, |
3893 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH }, | |
3894 | { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW }, | |
3895 | { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR }, | |
3896 | { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO }, | |
f18c054f DB |
3897 | { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM }, |
3898 | { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM }, | |
3899 | { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM }, | |
3900 | { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP }, | |
0ac081f6 AH |
3901 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW }, |
3902 | { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS }, | |
3903 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS }, | |
3904 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS }, | |
3905 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS }, | |
3906 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS }, | |
3907 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS }, | |
3908 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS }, | |
3909 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS }, | |
3910 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS }, | |
3911 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS }, | |
3912 | { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS }, | |
f18c054f | 3913 | { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR }, |
a3170dc6 AH |
3914 | |
3915 | /* Place holder, leave as first spe builtin. */ | |
3916 | { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW }, | |
3917 | { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND }, | |
3918 | { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC }, | |
3919 | { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS }, | |
3920 | { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU }, | |
3921 | { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV }, | |
3922 | { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD }, | |
3923 | { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV }, | |
3924 | { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL }, | |
3925 | { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB }, | |
3926 | { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI }, | |
3927 | { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO }, | |
3928 | { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO }, | |
3929 | { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI }, | |
3930 | { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA }, | |
3931 | { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN }, | |
3932 | { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA }, | |
3933 | { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN }, | |
3934 | { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA }, | |
3935 | { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN }, | |
3936 | { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF }, | |
3937 | { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA }, | |
3938 | { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW }, | |
3939 | { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW }, | |
3940 | { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI }, | |
3941 | { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA }, | |
3942 | { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW }, | |
3943 | { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW }, | |
3944 | { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF }, | |
3945 | { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA }, | |
3946 | { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW }, | |
3947 | { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW }, | |
3948 | { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW }, | |
3949 | { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW }, | |
3950 | { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI }, | |
3951 | { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA }, | |
3952 | { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW }, | |
3953 | { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW }, | |
3954 | { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW }, | |
3955 | { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW }, | |
3956 | { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA }, | |
3957 | { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN }, | |
3958 | { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA }, | |
3959 | { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN }, | |
3960 | { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA }, | |
3961 | { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN }, | |
3962 | { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF }, | |
3963 | { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA }, | |
3964 | { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW }, | |
3965 | { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW }, | |
3966 | { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI }, | |
3967 | { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA }, | |
3968 | { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW }, | |
3969 | { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW }, | |
3970 | { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF }, | |
3971 | { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA }, | |
3972 | { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW }, | |
3973 | { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW }, | |
3974 | { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW }, | |
3975 | { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW }, | |
3976 | { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI }, | |
3977 | { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA }, | |
3978 | { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW }, | |
3979 | { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW }, | |
3980 | { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW }, | |
3981 | { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW }, | |
3982 | { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF }, | |
3983 | { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA }, | |
3984 | { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI }, | |
3985 | { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA }, | |
3986 | { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF }, | |
3987 | { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA }, | |
3988 | { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI }, | |
3989 | { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA }, | |
a3170dc6 AH |
3990 | { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW }, |
3991 | { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW }, | |
a3170dc6 AH |
3992 | { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW }, |
3993 | { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW }, | |
3994 | { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI }, | |
3995 | { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA }, | |
3996 | { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW }, | |
3997 | { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW }, | |
3998 | { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW }, | |
3999 | { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW }, | |
4000 | { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF }, | |
4001 | { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA }, | |
4002 | { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA }, | |
4003 | { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN }, | |
4004 | { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI }, | |
4005 | { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA }, | |
4006 | { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA }, | |
4007 | { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN }, | |
4008 | { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF }, | |
4009 | { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA }, | |
4010 | { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA }, | |
4011 | { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN }, | |
4012 | { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI }, | |
4013 | { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA }, | |
4014 | { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA }, | |
4015 | { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN }, | |
4016 | { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND }, | |
4017 | { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR }, | |
4018 | { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR }, | |
4019 | { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC }, | |
4020 | { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW }, | |
4021 | { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW }, | |
4022 | { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS }, | |
4023 | { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU }, | |
4024 | { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW }, | |
4025 | ||
4026 | /* SPE binary operations expecting a 5-bit unsigned literal. */ | |
4027 | { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW }, | |
4028 | ||
4029 | { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI }, | |
4030 | { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI }, | |
4031 | { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS }, | |
4032 | { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU }, | |
4033 | { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW }, | |
4034 | { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA }, | |
4035 | { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA }, | |
4036 | { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA }, | |
4037 | { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA }, | |
4038 | { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA }, | |
4039 | { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA }, | |
4040 | { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN }, | |
4041 | { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN }, | |
4042 | { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN }, | |
4043 | { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN }, | |
4044 | { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN }, | |
4045 | { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN }, | |
4046 | { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA }, | |
4047 | { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA }, | |
4048 | { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA }, | |
4049 | { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA }, | |
4050 | { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN }, | |
4051 | { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN }, | |
4052 | { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN }, | |
4053 | { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN }, | |
4054 | { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC }, | |
4055 | ||
4056 | /* Place-holder. Leave as last binary SPE builtin. */ | |
4057 | { 0, CODE_FOR_spe_evxor, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR }, | |
ae4b4a02 AH |
4058 | }; |
4059 | ||
4060 | /* AltiVec predicates. */ | |
4061 | ||
4062 | struct builtin_description_predicates | |
4063 | { | |
4064 | const unsigned int mask; | |
4065 | const enum insn_code icode; | |
4066 | const char *opcode; | |
4067 | const char *const name; | |
4068 | const enum rs6000_builtins code; | |
4069 | }; | |
4070 | ||
4071 | static const struct builtin_description_predicates bdesc_altivec_preds[] = | |
4072 | { | |
4073 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P }, | |
4074 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P }, | |
4075 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P }, | |
4076 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P }, | |
4077 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P }, | |
4078 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P }, | |
4079 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P }, | |
4080 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P }, | |
4081 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P }, | |
4082 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P }, | |
4083 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P }, | |
4084 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P }, | |
4085 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P } | |
0ac081f6 | 4086 | }; |
24408032 | 4087 | |
a3170dc6 AH |
4088 | /* SPE predicates. */ |
4089 | static struct builtin_description bdesc_spe_predicates[] = | |
4090 | { | |
4091 | /* Place-holder. Leave as first. */ | |
4092 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ }, | |
4093 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS }, | |
4094 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU }, | |
4095 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS }, | |
4096 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU }, | |
4097 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ }, | |
4098 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT }, | |
4099 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT }, | |
4100 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ }, | |
4101 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT }, | |
4102 | /* Place-holder. Leave as last. */ | |
4103 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT }, | |
4104 | }; | |
4105 | ||
4106 | /* SPE evsel predicates. */ | |
4107 | static struct builtin_description bdesc_spe_evsel[] = | |
4108 | { | |
4109 | /* Place-holder. Leave as first. */ | |
4110 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS }, | |
4111 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU }, | |
4112 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS }, | |
4113 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU }, | |
4114 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ }, | |
4115 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT }, | |
4116 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT }, | |
4117 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ }, | |
4118 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT }, | |
4119 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT }, | |
4120 | /* Place-holder. Leave as last. */ | |
4121 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ }, | |
4122 | }; | |
4123 | ||
b6d08ca1 | 4124 | /* ABS* operations. */ |
100c4561 AH |
4125 | |
4126 | static const struct builtin_description bdesc_abs[] = | |
4127 | { | |
4128 | { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI }, | |
4129 | { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI }, | |
4130 | { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF }, | |
4131 | { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI }, | |
4132 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI }, | |
4133 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI }, | |
4134 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI } | |
4135 | }; | |
4136 | ||
617e0e1d DB |
4137 | /* Simple unary operations: VECb = foo (unsigned literal) or VECb = |
4138 | foo (VECa). */ | |
24408032 | 4139 | |
a3170dc6 | 4140 | static struct builtin_description bdesc_1arg[] = |
2212663f | 4141 | { |
617e0e1d DB |
4142 | { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP }, |
4143 | { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP }, | |
4144 | { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP }, | |
4145 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM }, | |
4146 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN }, | |
4147 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP }, | |
4148 | { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ }, | |
4149 | { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP }, | |
2212663f DB |
4150 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB }, |
4151 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH }, | |
4152 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW }, | |
20e26713 AH |
4153 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB }, |
4154 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX }, | |
4155 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH }, | |
4156 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB }, | |
4157 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX }, | |
4158 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH }, | |
a3170dc6 AH |
4159 | |
4160 | /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and | |
4161 | end with SPE_BUILTIN_EVSUBFUSIAAW. */ | |
4162 | { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS }, | |
4163 | { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW }, | |
4164 | { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW }, | |
4165 | { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW }, | |
4166 | { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW }, | |
4167 | { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW }, | |
4168 | { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW }, | |
4169 | { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB }, | |
4170 | { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH }, | |
4171 | { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS }, | |
4172 | { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF }, | |
4173 | { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI }, | |
4174 | { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF }, | |
4175 | { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI }, | |
4176 | { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF }, | |
4177 | { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI }, | |
4178 | { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ }, | |
4179 | { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF }, | |
4180 | { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI }, | |
4181 | { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ }, | |
4182 | { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS }, | |
4183 | { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG }, | |
4184 | { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA }, | |
4185 | { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG }, | |
4186 | { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW }, | |
4187 | { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW }, | |
4188 | { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW }, | |
4189 | { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW }, | |
4190 | { 0, CODE_FOR_spe_evsplatfi, "__builtin_spe_evsplatfi", SPE_BUILTIN_EVSPLATFI }, | |
4191 | { 0, CODE_FOR_spe_evsplati, "__builtin_spe_evsplati", SPE_BUILTIN_EVSPLATI }, | |
4192 | ||
4193 | /* Place-holder. Leave as last unary SPE builtin. */ | |
4194 | { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW }, | |
2212663f DB |
4195 | }; |
4196 | ||
4197 | static rtx | |
92898235 | 4198 | rs6000_expand_unop_builtin (icode, arglist, target) |
2212663f DB |
4199 | enum insn_code icode; |
4200 | tree arglist; | |
4201 | rtx target; | |
4202 | { | |
4203 | rtx pat; | |
4204 | tree arg0 = TREE_VALUE (arglist); | |
4205 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4206 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
4207 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
4208 | ||
0559cc77 DE |
4209 | if (icode == CODE_FOR_nothing) |
4210 | /* Builtin not supported on this processor. */ | |
4211 | return 0; | |
4212 | ||
20e26713 AH |
4213 | /* If we got invalid arguments bail out before generating bad rtl. */ |
4214 | if (arg0 == error_mark_node) | |
9a171fcd | 4215 | return const0_rtx; |
20e26713 | 4216 | |
0559cc77 DE |
4217 | if (icode == CODE_FOR_altivec_vspltisb |
4218 | || icode == CODE_FOR_altivec_vspltish | |
4219 | || icode == CODE_FOR_altivec_vspltisw | |
4220 | || icode == CODE_FOR_spe_evsplatfi | |
4221 | || icode == CODE_FOR_spe_evsplati) | |
b44140e7 AH |
4222 | { |
4223 | /* Only allow 5-bit *signed* literals. */ | |
b44140e7 AH |
4224 | if (GET_CODE (op0) != CONST_INT |
4225 | || INTVAL (op0) > 0x1f | |
4226 | || INTVAL (op0) < -0x1f) | |
4227 | { | |
4228 | error ("argument 1 must be a 5-bit signed literal"); | |
9a171fcd | 4229 | return const0_rtx; |
b44140e7 | 4230 | } |
b44140e7 AH |
4231 | } |
4232 | ||
c62f2db5 | 4233 | if (target == 0 |
2212663f DB |
4234 | || GET_MODE (target) != tmode |
4235 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4236 | target = gen_reg_rtx (tmode); | |
4237 | ||
4238 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
4239 | op0 = copy_to_mode_reg (mode0, op0); | |
4240 | ||
4241 | pat = GEN_FCN (icode) (target, op0); | |
4242 | if (! pat) | |
4243 | return 0; | |
4244 | emit_insn (pat); | |
0ac081f6 | 4245 | |
2212663f DB |
4246 | return target; |
4247 | } | |
ae4b4a02 | 4248 | |
100c4561 AH |
4249 | static rtx |
4250 | altivec_expand_abs_builtin (icode, arglist, target) | |
4251 | enum insn_code icode; | |
4252 | tree arglist; | |
4253 | rtx target; | |
4254 | { | |
4255 | rtx pat, scratch1, scratch2; | |
4256 | tree arg0 = TREE_VALUE (arglist); | |
4257 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4258 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
4259 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
4260 | ||
4261 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
4262 | if (arg0 == error_mark_node) | |
9a171fcd | 4263 | return const0_rtx; |
100c4561 AH |
4264 | |
4265 | if (target == 0 | |
4266 | || GET_MODE (target) != tmode | |
4267 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4268 | target = gen_reg_rtx (tmode); | |
4269 | ||
4270 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
4271 | op0 = copy_to_mode_reg (mode0, op0); | |
4272 | ||
4273 | scratch1 = gen_reg_rtx (mode0); | |
4274 | scratch2 = gen_reg_rtx (mode0); | |
4275 | ||
4276 | pat = GEN_FCN (icode) (target, op0, scratch1, scratch2); | |
4277 | if (! pat) | |
4278 | return 0; | |
4279 | emit_insn (pat); | |
4280 | ||
4281 | return target; | |
4282 | } | |
4283 | ||
0ac081f6 | 4284 | static rtx |
92898235 | 4285 | rs6000_expand_binop_builtin (icode, arglist, target) |
0ac081f6 AH |
4286 | enum insn_code icode; |
4287 | tree arglist; | |
4288 | rtx target; | |
4289 | { | |
4290 | rtx pat; | |
4291 | tree arg0 = TREE_VALUE (arglist); | |
4292 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
4293 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4294 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
4295 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
4296 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
4297 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
4298 | ||
0559cc77 DE |
4299 | if (icode == CODE_FOR_nothing) |
4300 | /* Builtin not supported on this processor. */ | |
4301 | return 0; | |
4302 | ||
20e26713 AH |
4303 | /* If we got invalid arguments bail out before generating bad rtl. */ |
4304 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 4305 | return const0_rtx; |
20e26713 | 4306 | |
0559cc77 DE |
4307 | if (icode == CODE_FOR_altivec_vcfux |
4308 | || icode == CODE_FOR_altivec_vcfsx | |
4309 | || icode == CODE_FOR_altivec_vctsxs | |
4310 | || icode == CODE_FOR_altivec_vctuxs | |
4311 | || icode == CODE_FOR_altivec_vspltb | |
4312 | || icode == CODE_FOR_altivec_vsplth | |
4313 | || icode == CODE_FOR_altivec_vspltw | |
4314 | || icode == CODE_FOR_spe_evaddiw | |
4315 | || icode == CODE_FOR_spe_evldd | |
4316 | || icode == CODE_FOR_spe_evldh | |
4317 | || icode == CODE_FOR_spe_evldw | |
4318 | || icode == CODE_FOR_spe_evlhhesplat | |
4319 | || icode == CODE_FOR_spe_evlhhossplat | |
4320 | || icode == CODE_FOR_spe_evlhhousplat | |
4321 | || icode == CODE_FOR_spe_evlwhe | |
4322 | || icode == CODE_FOR_spe_evlwhos | |
4323 | || icode == CODE_FOR_spe_evlwhou | |
4324 | || icode == CODE_FOR_spe_evlwhsplat | |
4325 | || icode == CODE_FOR_spe_evlwwsplat | |
4326 | || icode == CODE_FOR_spe_evrlwi | |
4327 | || icode == CODE_FOR_spe_evslwi | |
4328 | || icode == CODE_FOR_spe_evsrwis | |
4329 | || icode == CODE_FOR_spe_evsrwiu) | |
b44140e7 AH |
4330 | { |
4331 | /* Only allow 5-bit unsigned literals. */ | |
b44140e7 AH |
4332 | if (TREE_CODE (arg1) != INTEGER_CST |
4333 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
4334 | { | |
4335 | error ("argument 2 must be a 5-bit unsigned literal"); | |
9a171fcd | 4336 | return const0_rtx; |
b44140e7 | 4337 | } |
b44140e7 AH |
4338 | } |
4339 | ||
c62f2db5 | 4340 | if (target == 0 |
0ac081f6 AH |
4341 | || GET_MODE (target) != tmode |
4342 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4343 | target = gen_reg_rtx (tmode); | |
4344 | ||
4345 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
4346 | op0 = copy_to_mode_reg (mode0, op0); | |
4347 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
4348 | op1 = copy_to_mode_reg (mode1, op1); | |
4349 | ||
4350 | pat = GEN_FCN (icode) (target, op0, op1); | |
4351 | if (! pat) | |
4352 | return 0; | |
4353 | emit_insn (pat); | |
4354 | ||
4355 | return target; | |
4356 | } | |
6525c0e7 | 4357 | |
ae4b4a02 AH |
4358 | static rtx |
4359 | altivec_expand_predicate_builtin (icode, opcode, arglist, target) | |
4360 | enum insn_code icode; | |
4361 | const char *opcode; | |
4362 | tree arglist; | |
4363 | rtx target; | |
4364 | { | |
4365 | rtx pat, scratch; | |
4366 | tree cr6_form = TREE_VALUE (arglist); | |
4367 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
4368 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
4369 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4370 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
4371 | enum machine_mode tmode = SImode; | |
4372 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
4373 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
4374 | int cr6_form_int; | |
4375 | ||
4376 | if (TREE_CODE (cr6_form) != INTEGER_CST) | |
4377 | { | |
4378 | error ("argument 1 of __builtin_altivec_predicate must be a constant"); | |
9a171fcd | 4379 | return const0_rtx; |
ae4b4a02 AH |
4380 | } |
4381 | else | |
4382 | cr6_form_int = TREE_INT_CST_LOW (cr6_form); | |
4383 | ||
4384 | if (mode0 != mode1) | |
4385 | abort (); | |
4386 | ||
4387 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
4388 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 4389 | return const0_rtx; |
ae4b4a02 AH |
4390 | |
4391 | if (target == 0 | |
4392 | || GET_MODE (target) != tmode | |
4393 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4394 | target = gen_reg_rtx (tmode); | |
4395 | ||
4396 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
4397 | op0 = copy_to_mode_reg (mode0, op0); | |
4398 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
4399 | op1 = copy_to_mode_reg (mode1, op1); | |
4400 | ||
4401 | scratch = gen_reg_rtx (mode0); | |
4402 | ||
4403 | pat = GEN_FCN (icode) (scratch, op0, op1, | |
4404 | gen_rtx (SYMBOL_REF, Pmode, opcode)); | |
4405 | if (! pat) | |
4406 | return 0; | |
4407 | emit_insn (pat); | |
4408 | ||
4409 | /* The vec_any* and vec_all* predicates use the same opcodes for two | |
4410 | different operations, but the bits in CR6 will be different | |
4411 | depending on what information we want. So we have to play tricks | |
4412 | with CR6 to get the right bits out. | |
4413 | ||
4414 | If you think this is disgusting, look at the specs for the | |
4415 | AltiVec predicates. */ | |
4416 | ||
4417 | switch (cr6_form_int) | |
4418 | { | |
4419 | case 0: | |
4420 | emit_insn (gen_cr6_test_for_zero (target)); | |
4421 | break; | |
4422 | case 1: | |
4423 | emit_insn (gen_cr6_test_for_zero_reverse (target)); | |
4424 | break; | |
4425 | case 2: | |
4426 | emit_insn (gen_cr6_test_for_lt (target)); | |
4427 | break; | |
4428 | case 3: | |
4429 | emit_insn (gen_cr6_test_for_lt_reverse (target)); | |
4430 | break; | |
4431 | default: | |
4432 | error ("argument 1 of __builtin_altivec_predicate is out of range"); | |
4433 | break; | |
4434 | } | |
4435 | ||
4436 | return target; | |
4437 | } | |
4438 | ||
6525c0e7 AH |
4439 | static rtx |
4440 | altivec_expand_stv_builtin (icode, arglist) | |
4441 | enum insn_code icode; | |
4442 | tree arglist; | |
4443 | { | |
4444 | tree arg0 = TREE_VALUE (arglist); | |
4445 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
4446 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
4447 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4448 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
4449 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
4450 | rtx pat; | |
4451 | enum machine_mode mode0 = insn_data[icode].operand[0].mode; | |
4452 | enum machine_mode mode1 = insn_data[icode].operand[1].mode; | |
4453 | enum machine_mode mode2 = insn_data[icode].operand[2].mode; | |
4454 | ||
4455 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
4456 | if (arg0 == error_mark_node | |
4457 | || arg1 == error_mark_node | |
4458 | || arg2 == error_mark_node) | |
9a171fcd | 4459 | return const0_rtx; |
6525c0e7 AH |
4460 | |
4461 | if (! (*insn_data[icode].operand[2].predicate) (op0, mode2)) | |
4462 | op0 = copy_to_mode_reg (mode2, op0); | |
4463 | if (! (*insn_data[icode].operand[0].predicate) (op1, mode0)) | |
4464 | op1 = copy_to_mode_reg (mode0, op1); | |
4465 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
4466 | op2 = copy_to_mode_reg (mode1, op2); | |
4467 | ||
4468 | pat = GEN_FCN (icode) (op1, op2, op0); | |
4469 | if (pat) | |
4470 | emit_insn (pat); | |
4471 | return NULL_RTX; | |
4472 | } | |
4473 | ||
2212663f | 4474 | static rtx |
92898235 | 4475 | rs6000_expand_ternop_builtin (icode, arglist, target) |
2212663f DB |
4476 | enum insn_code icode; |
4477 | tree arglist; | |
4478 | rtx target; | |
4479 | { | |
4480 | rtx pat; | |
4481 | tree arg0 = TREE_VALUE (arglist); | |
4482 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
4483 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
4484 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4485 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
4486 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
4487 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
4488 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
4489 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
4490 | enum machine_mode mode2 = insn_data[icode].operand[3].mode; | |
0ac081f6 | 4491 | |
774b5662 DE |
4492 | if (icode == CODE_FOR_nothing) |
4493 | /* Builtin not supported on this processor. */ | |
4494 | return 0; | |
4495 | ||
20e26713 AH |
4496 | /* If we got invalid arguments bail out before generating bad rtl. */ |
4497 | if (arg0 == error_mark_node | |
4498 | || arg1 == error_mark_node | |
4499 | || arg2 == error_mark_node) | |
9a171fcd | 4500 | return const0_rtx; |
20e26713 | 4501 | |
774b5662 DE |
4502 | if (icode == CODE_FOR_altivec_vsldoi_4sf |
4503 | || icode == CODE_FOR_altivec_vsldoi_4si | |
4504 | || icode == CODE_FOR_altivec_vsldoi_8hi | |
4505 | || icode == CODE_FOR_altivec_vsldoi_16qi) | |
b44140e7 AH |
4506 | { |
4507 | /* Only allow 4-bit unsigned literals. */ | |
b44140e7 AH |
4508 | if (TREE_CODE (arg2) != INTEGER_CST |
4509 | || TREE_INT_CST_LOW (arg2) & ~0xf) | |
4510 | { | |
4511 | error ("argument 3 must be a 4-bit unsigned literal"); | |
e3277ffb | 4512 | return const0_rtx; |
b44140e7 | 4513 | } |
b44140e7 AH |
4514 | } |
4515 | ||
c62f2db5 | 4516 | if (target == 0 |
2212663f DB |
4517 | || GET_MODE (target) != tmode |
4518 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4519 | target = gen_reg_rtx (tmode); | |
4520 | ||
4521 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
4522 | op0 = copy_to_mode_reg (mode0, op0); | |
4523 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
4524 | op1 = copy_to_mode_reg (mode1, op1); | |
4525 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
4526 | op2 = copy_to_mode_reg (mode2, op2); | |
4527 | ||
4528 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
4529 | if (! pat) | |
4530 | return 0; | |
4531 | emit_insn (pat); | |
4532 | ||
4533 | return target; | |
4534 | } | |
92898235 | 4535 | |
3a9b8c7e | 4536 | /* Expand the lvx builtins. */ |
0ac081f6 | 4537 | static rtx |
3a9b8c7e | 4538 | altivec_expand_ld_builtin (exp, target, expandedp) |
0ac081f6 AH |
4539 | tree exp; |
4540 | rtx target; | |
92898235 | 4541 | bool *expandedp; |
0ac081f6 | 4542 | { |
0ac081f6 AH |
4543 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
4544 | tree arglist = TREE_OPERAND (exp, 1); | |
0ac081f6 | 4545 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
3a9b8c7e AH |
4546 | tree arg0; |
4547 | enum machine_mode tmode, mode0; | |
7c3abc73 | 4548 | rtx pat, op0; |
3a9b8c7e | 4549 | enum insn_code icode; |
92898235 | 4550 | |
0ac081f6 AH |
4551 | switch (fcode) |
4552 | { | |
f18c054f DB |
4553 | case ALTIVEC_BUILTIN_LD_INTERNAL_16qi: |
4554 | icode = CODE_FOR_altivec_lvx_16qi; | |
3a9b8c7e | 4555 | break; |
f18c054f DB |
4556 | case ALTIVEC_BUILTIN_LD_INTERNAL_8hi: |
4557 | icode = CODE_FOR_altivec_lvx_8hi; | |
3a9b8c7e AH |
4558 | break; |
4559 | case ALTIVEC_BUILTIN_LD_INTERNAL_4si: | |
4560 | icode = CODE_FOR_altivec_lvx_4si; | |
4561 | break; | |
4562 | case ALTIVEC_BUILTIN_LD_INTERNAL_4sf: | |
4563 | icode = CODE_FOR_altivec_lvx_4sf; | |
4564 | break; | |
4565 | default: | |
4566 | *expandedp = false; | |
4567 | return NULL_RTX; | |
4568 | } | |
0ac081f6 | 4569 | |
3a9b8c7e | 4570 | *expandedp = true; |
f18c054f | 4571 | |
3a9b8c7e AH |
4572 | arg0 = TREE_VALUE (arglist); |
4573 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4574 | tmode = insn_data[icode].operand[0].mode; | |
4575 | mode0 = insn_data[icode].operand[1].mode; | |
f18c054f | 4576 | |
3a9b8c7e AH |
4577 | if (target == 0 |
4578 | || GET_MODE (target) != tmode | |
4579 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4580 | target = gen_reg_rtx (tmode); | |
24408032 | 4581 | |
3a9b8c7e AH |
4582 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) |
4583 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
f18c054f | 4584 | |
3a9b8c7e AH |
4585 | pat = GEN_FCN (icode) (target, op0); |
4586 | if (! pat) | |
4587 | return 0; | |
4588 | emit_insn (pat); | |
4589 | return target; | |
4590 | } | |
f18c054f | 4591 | |
3a9b8c7e AH |
4592 | /* Expand the stvx builtins. */ |
4593 | static rtx | |
4594 | altivec_expand_st_builtin (exp, target, expandedp) | |
4595 | tree exp; | |
7c3abc73 | 4596 | rtx target ATTRIBUTE_UNUSED; |
3a9b8c7e AH |
4597 | bool *expandedp; |
4598 | { | |
4599 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
4600 | tree arglist = TREE_OPERAND (exp, 1); | |
4601 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
4602 | tree arg0, arg1; | |
4603 | enum machine_mode mode0, mode1; | |
7c3abc73 | 4604 | rtx pat, op0, op1; |
3a9b8c7e | 4605 | enum insn_code icode; |
f18c054f | 4606 | |
3a9b8c7e AH |
4607 | switch (fcode) |
4608 | { | |
4609 | case ALTIVEC_BUILTIN_ST_INTERNAL_16qi: | |
4610 | icode = CODE_FOR_altivec_stvx_16qi; | |
4611 | break; | |
4612 | case ALTIVEC_BUILTIN_ST_INTERNAL_8hi: | |
4613 | icode = CODE_FOR_altivec_stvx_8hi; | |
4614 | break; | |
4615 | case ALTIVEC_BUILTIN_ST_INTERNAL_4si: | |
4616 | icode = CODE_FOR_altivec_stvx_4si; | |
4617 | break; | |
4618 | case ALTIVEC_BUILTIN_ST_INTERNAL_4sf: | |
4619 | icode = CODE_FOR_altivec_stvx_4sf; | |
4620 | break; | |
4621 | default: | |
4622 | *expandedp = false; | |
4623 | return NULL_RTX; | |
4624 | } | |
24408032 | 4625 | |
3a9b8c7e AH |
4626 | arg0 = TREE_VALUE (arglist); |
4627 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
4628 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4629 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
4630 | mode0 = insn_data[icode].operand[0].mode; | |
4631 | mode1 = insn_data[icode].operand[1].mode; | |
f18c054f | 4632 | |
3a9b8c7e AH |
4633 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
4634 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
4635 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
4636 | op1 = copy_to_mode_reg (mode1, op1); | |
f18c054f | 4637 | |
3a9b8c7e AH |
4638 | pat = GEN_FCN (icode) (op0, op1); |
4639 | if (pat) | |
4640 | emit_insn (pat); | |
f18c054f | 4641 | |
3a9b8c7e AH |
4642 | *expandedp = true; |
4643 | return NULL_RTX; | |
4644 | } | |
f18c054f | 4645 | |
3a9b8c7e AH |
4646 | /* Expand the dst builtins. */ |
4647 | static rtx | |
4648 | altivec_expand_dst_builtin (exp, target, expandedp) | |
4649 | tree exp; | |
7c3abc73 | 4650 | rtx target ATTRIBUTE_UNUSED; |
3a9b8c7e AH |
4651 | bool *expandedp; |
4652 | { | |
4653 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
4654 | tree arglist = TREE_OPERAND (exp, 1); | |
4655 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
4656 | tree arg0, arg1, arg2; | |
4657 | enum machine_mode mode0, mode1, mode2; | |
7c3abc73 | 4658 | rtx pat, op0, op1, op2; |
3a9b8c7e | 4659 | struct builtin_description *d; |
a3170dc6 | 4660 | size_t i; |
f18c054f | 4661 | |
3a9b8c7e | 4662 | *expandedp = false; |
f18c054f | 4663 | |
3a9b8c7e AH |
4664 | /* Handle DST variants. */ |
4665 | d = (struct builtin_description *) bdesc_dst; | |
4666 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
4667 | if (d->code == fcode) | |
4668 | { | |
4669 | arg0 = TREE_VALUE (arglist); | |
4670 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
4671 | arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
4672 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4673 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
4674 | op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
4675 | mode0 = insn_data[d->icode].operand[0].mode; | |
4676 | mode1 = insn_data[d->icode].operand[1].mode; | |
4677 | mode2 = insn_data[d->icode].operand[2].mode; | |
24408032 | 4678 | |
3a9b8c7e AH |
4679 | /* Invalid arguments, bail out before generating bad rtl. */ |
4680 | if (arg0 == error_mark_node | |
4681 | || arg1 == error_mark_node | |
4682 | || arg2 == error_mark_node) | |
4683 | return const0_rtx; | |
f18c054f | 4684 | |
3a9b8c7e AH |
4685 | if (TREE_CODE (arg2) != INTEGER_CST |
4686 | || TREE_INT_CST_LOW (arg2) & ~0x3) | |
4687 | { | |
4688 | error ("argument to `%s' must be a 2-bit unsigned literal", d->name); | |
4689 | return const0_rtx; | |
4690 | } | |
f18c054f | 4691 | |
3a9b8c7e AH |
4692 | if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0)) |
4693 | op0 = copy_to_mode_reg (mode0, op0); | |
4694 | if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1)) | |
4695 | op1 = copy_to_mode_reg (mode1, op1); | |
24408032 | 4696 | |
3a9b8c7e AH |
4697 | pat = GEN_FCN (d->icode) (op0, op1, op2); |
4698 | if (pat != 0) | |
4699 | emit_insn (pat); | |
f18c054f | 4700 | |
3a9b8c7e AH |
4701 | *expandedp = true; |
4702 | return NULL_RTX; | |
4703 | } | |
f18c054f | 4704 | |
3a9b8c7e AH |
4705 | return NULL_RTX; |
4706 | } | |
24408032 | 4707 | |
3a9b8c7e AH |
4708 | /* Expand the builtin in EXP and store the result in TARGET. Store |
4709 | true in *EXPANDEDP if we found a builtin to expand. */ | |
4710 | static rtx | |
4711 | altivec_expand_builtin (exp, target, expandedp) | |
4712 | tree exp; | |
4713 | rtx target; | |
4714 | bool *expandedp; | |
4715 | { | |
4716 | struct builtin_description *d; | |
4717 | struct builtin_description_predicates *dp; | |
4718 | size_t i; | |
4719 | enum insn_code icode; | |
4720 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
4721 | tree arglist = TREE_OPERAND (exp, 1); | |
7c3abc73 AH |
4722 | tree arg0; |
4723 | rtx op0, pat; | |
4724 | enum machine_mode tmode, mode0; | |
3a9b8c7e | 4725 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
0ac081f6 | 4726 | |
3a9b8c7e AH |
4727 | target = altivec_expand_ld_builtin (exp, target, expandedp); |
4728 | if (*expandedp) | |
4729 | return target; | |
0ac081f6 | 4730 | |
3a9b8c7e AH |
4731 | target = altivec_expand_st_builtin (exp, target, expandedp); |
4732 | if (*expandedp) | |
4733 | return target; | |
4734 | ||
4735 | target = altivec_expand_dst_builtin (exp, target, expandedp); | |
4736 | if (*expandedp) | |
4737 | return target; | |
4738 | ||
4739 | *expandedp = true; | |
95385cbb | 4740 | |
3a9b8c7e AH |
4741 | switch (fcode) |
4742 | { | |
6525c0e7 AH |
4743 | case ALTIVEC_BUILTIN_STVX: |
4744 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist); | |
4745 | case ALTIVEC_BUILTIN_STVEBX: | |
4746 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist); | |
4747 | case ALTIVEC_BUILTIN_STVEHX: | |
4748 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist); | |
4749 | case ALTIVEC_BUILTIN_STVEWX: | |
4750 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist); | |
4751 | case ALTIVEC_BUILTIN_STVXL: | |
4752 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist); | |
3a9b8c7e | 4753 | |
95385cbb AH |
4754 | case ALTIVEC_BUILTIN_MFVSCR: |
4755 | icode = CODE_FOR_altivec_mfvscr; | |
4756 | tmode = insn_data[icode].operand[0].mode; | |
4757 | ||
4758 | if (target == 0 | |
4759 | || GET_MODE (target) != tmode | |
4760 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4761 | target = gen_reg_rtx (tmode); | |
4762 | ||
4763 | pat = GEN_FCN (icode) (target); | |
0ac081f6 AH |
4764 | if (! pat) |
4765 | return 0; | |
4766 | emit_insn (pat); | |
95385cbb AH |
4767 | return target; |
4768 | ||
4769 | case ALTIVEC_BUILTIN_MTVSCR: | |
4770 | icode = CODE_FOR_altivec_mtvscr; | |
4771 | arg0 = TREE_VALUE (arglist); | |
4772 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4773 | mode0 = insn_data[icode].operand[0].mode; | |
4774 | ||
4775 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
4776 | if (arg0 == error_mark_node) | |
9a171fcd | 4777 | return const0_rtx; |
95385cbb AH |
4778 | |
4779 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
4780 | op0 = copy_to_mode_reg (mode0, op0); | |
4781 | ||
4782 | pat = GEN_FCN (icode) (op0); | |
4783 | if (pat) | |
4784 | emit_insn (pat); | |
4785 | return NULL_RTX; | |
3a9b8c7e | 4786 | |
95385cbb AH |
4787 | case ALTIVEC_BUILTIN_DSSALL: |
4788 | emit_insn (gen_altivec_dssall ()); | |
4789 | return NULL_RTX; | |
4790 | ||
4791 | case ALTIVEC_BUILTIN_DSS: | |
4792 | icode = CODE_FOR_altivec_dss; | |
4793 | arg0 = TREE_VALUE (arglist); | |
4794 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4795 | mode0 = insn_data[icode].operand[0].mode; | |
4796 | ||
4797 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
4798 | if (arg0 == error_mark_node) | |
9a171fcd | 4799 | return const0_rtx; |
95385cbb | 4800 | |
b44140e7 AH |
4801 | if (TREE_CODE (arg0) != INTEGER_CST |
4802 | || TREE_INT_CST_LOW (arg0) & ~0x3) | |
4803 | { | |
4804 | error ("argument to dss must be a 2-bit unsigned literal"); | |
9a171fcd | 4805 | return const0_rtx; |
b44140e7 AH |
4806 | } |
4807 | ||
95385cbb AH |
4808 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
4809 | op0 = copy_to_mode_reg (mode0, op0); | |
4810 | ||
4811 | emit_insn (gen_altivec_dss (op0)); | |
0ac081f6 AH |
4812 | return NULL_RTX; |
4813 | } | |
24408032 | 4814 | |
100c4561 AH |
4815 | /* Expand abs* operations. */ |
4816 | d = (struct builtin_description *) bdesc_abs; | |
ca7558fc | 4817 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) |
100c4561 AH |
4818 | if (d->code == fcode) |
4819 | return altivec_expand_abs_builtin (d->icode, arglist, target); | |
4820 | ||
ae4b4a02 AH |
4821 | /* Expand the AltiVec predicates. */ |
4822 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
ca7558fc | 4823 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) |
ae4b4a02 AH |
4824 | if (dp->code == fcode) |
4825 | return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target); | |
4826 | ||
6525c0e7 AH |
4827 | /* LV* are funky. We initialized them differently. */ |
4828 | switch (fcode) | |
4829 | { | |
4830 | case ALTIVEC_BUILTIN_LVSL: | |
92898235 | 4831 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl, |
6525c0e7 AH |
4832 | arglist, target); |
4833 | case ALTIVEC_BUILTIN_LVSR: | |
92898235 AH |
4834 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr, |
4835 | arglist, target); | |
6525c0e7 | 4836 | case ALTIVEC_BUILTIN_LVEBX: |
92898235 AH |
4837 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx, |
4838 | arglist, target); | |
6525c0e7 | 4839 | case ALTIVEC_BUILTIN_LVEHX: |
92898235 AH |
4840 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx, |
4841 | arglist, target); | |
6525c0e7 | 4842 | case ALTIVEC_BUILTIN_LVEWX: |
92898235 AH |
4843 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx, |
4844 | arglist, target); | |
6525c0e7 | 4845 | case ALTIVEC_BUILTIN_LVXL: |
92898235 AH |
4846 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl, |
4847 | arglist, target); | |
6525c0e7 | 4848 | case ALTIVEC_BUILTIN_LVX: |
92898235 AH |
4849 | return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx, |
4850 | arglist, target); | |
6525c0e7 AH |
4851 | default: |
4852 | break; | |
4853 | /* Fall through. */ | |
4854 | } | |
95385cbb | 4855 | |
92898235 | 4856 | *expandedp = false; |
0ac081f6 AH |
4857 | return NULL_RTX; |
4858 | } | |
4859 | ||
a3170dc6 AH |
4860 | /* Binops that need to be initialized manually, but can be expanded |
4861 | automagically by rs6000_expand_binop_builtin. */ | |
4862 | static struct builtin_description bdesc_2arg_spe[] = | |
4863 | { | |
4864 | { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX }, | |
4865 | { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX }, | |
4866 | { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX }, | |
4867 | { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX }, | |
4868 | { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX }, | |
4869 | { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX }, | |
4870 | { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX }, | |
4871 | { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX }, | |
4872 | { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX }, | |
4873 | { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX }, | |
4874 | { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX }, | |
4875 | { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD }, | |
4876 | { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW }, | |
4877 | { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH }, | |
4878 | { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE }, | |
4879 | { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU }, | |
4880 | { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS }, | |
4881 | { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT }, | |
4882 | { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT }, | |
4883 | { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT }, | |
4884 | { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT }, | |
4885 | { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT } | |
4886 | }; | |
4887 | ||
4888 | /* Expand the builtin in EXP and store the result in TARGET. Store | |
4889 | true in *EXPANDEDP if we found a builtin to expand. | |
4890 | ||
4891 | This expands the SPE builtins that are not simple unary and binary | |
4892 | operations. */ | |
4893 | static rtx | |
4894 | spe_expand_builtin (exp, target, expandedp) | |
4895 | tree exp; | |
4896 | rtx target; | |
4897 | bool *expandedp; | |
4898 | { | |
4899 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
4900 | tree arglist = TREE_OPERAND (exp, 1); | |
4901 | tree arg1, arg0; | |
4902 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
4903 | enum insn_code icode; | |
4904 | enum machine_mode tmode, mode0; | |
4905 | rtx pat, op0; | |
4906 | struct builtin_description *d; | |
4907 | size_t i; | |
4908 | ||
4909 | *expandedp = true; | |
4910 | ||
4911 | /* Syntax check for a 5-bit unsigned immediate. */ | |
4912 | switch (fcode) | |
4913 | { | |
4914 | case SPE_BUILTIN_EVSTDD: | |
4915 | case SPE_BUILTIN_EVSTDH: | |
4916 | case SPE_BUILTIN_EVSTDW: | |
4917 | case SPE_BUILTIN_EVSTWHE: | |
4918 | case SPE_BUILTIN_EVSTWHO: | |
4919 | case SPE_BUILTIN_EVSTWWE: | |
4920 | case SPE_BUILTIN_EVSTWWO: | |
4921 | arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
4922 | if (TREE_CODE (arg1) != INTEGER_CST | |
4923 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
4924 | { | |
4925 | error ("argument 2 must be a 5-bit unsigned literal"); | |
4926 | return const0_rtx; | |
4927 | } | |
4928 | break; | |
4929 | default: | |
4930 | break; | |
4931 | } | |
4932 | ||
4933 | d = (struct builtin_description *) bdesc_2arg_spe; | |
4934 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d) | |
4935 | if (d->code == fcode) | |
4936 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
4937 | ||
4938 | d = (struct builtin_description *) bdesc_spe_predicates; | |
4939 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d) | |
4940 | if (d->code == fcode) | |
4941 | return spe_expand_predicate_builtin (d->icode, arglist, target); | |
4942 | ||
4943 | d = (struct builtin_description *) bdesc_spe_evsel; | |
4944 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d) | |
4945 | if (d->code == fcode) | |
4946 | return spe_expand_evsel_builtin (d->icode, arglist, target); | |
4947 | ||
4948 | switch (fcode) | |
4949 | { | |
4950 | case SPE_BUILTIN_EVSTDDX: | |
4951 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist); | |
4952 | case SPE_BUILTIN_EVSTDHX: | |
4953 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist); | |
4954 | case SPE_BUILTIN_EVSTDWX: | |
4955 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist); | |
4956 | case SPE_BUILTIN_EVSTWHEX: | |
4957 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist); | |
4958 | case SPE_BUILTIN_EVSTWHOX: | |
4959 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist); | |
4960 | case SPE_BUILTIN_EVSTWWEX: | |
4961 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist); | |
4962 | case SPE_BUILTIN_EVSTWWOX: | |
4963 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist); | |
4964 | case SPE_BUILTIN_EVSTDD: | |
4965 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist); | |
4966 | case SPE_BUILTIN_EVSTDH: | |
4967 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist); | |
4968 | case SPE_BUILTIN_EVSTDW: | |
4969 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist); | |
4970 | case SPE_BUILTIN_EVSTWHE: | |
4971 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist); | |
4972 | case SPE_BUILTIN_EVSTWHO: | |
4973 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist); | |
4974 | case SPE_BUILTIN_EVSTWWE: | |
4975 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist); | |
4976 | case SPE_BUILTIN_EVSTWWO: | |
4977 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist); | |
4978 | case SPE_BUILTIN_MFSPEFSCR: | |
4979 | icode = CODE_FOR_spe_mfspefscr; | |
4980 | tmode = insn_data[icode].operand[0].mode; | |
4981 | ||
4982 | if (target == 0 | |
4983 | || GET_MODE (target) != tmode | |
4984 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
4985 | target = gen_reg_rtx (tmode); | |
4986 | ||
4987 | pat = GEN_FCN (icode) (target); | |
4988 | if (! pat) | |
4989 | return 0; | |
4990 | emit_insn (pat); | |
4991 | return target; | |
4992 | case SPE_BUILTIN_MTSPEFSCR: | |
4993 | icode = CODE_FOR_spe_mtspefscr; | |
4994 | arg0 = TREE_VALUE (arglist); | |
4995 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
4996 | mode0 = insn_data[icode].operand[0].mode; | |
4997 | ||
4998 | if (arg0 == error_mark_node) | |
4999 | return const0_rtx; | |
5000 | ||
5001 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
5002 | op0 = copy_to_mode_reg (mode0, op0); | |
5003 | ||
5004 | pat = GEN_FCN (icode) (op0); | |
5005 | if (pat) | |
5006 | emit_insn (pat); | |
5007 | return NULL_RTX; | |
5008 | default: | |
5009 | break; | |
5010 | } | |
5011 | ||
5012 | *expandedp = false; | |
5013 | return NULL_RTX; | |
5014 | } | |
5015 | ||
5016 | static rtx | |
5017 | spe_expand_predicate_builtin (icode, arglist, target) | |
5018 | enum insn_code icode; | |
5019 | tree arglist; | |
5020 | rtx target; | |
5021 | { | |
5022 | rtx pat, scratch, tmp; | |
5023 | tree form = TREE_VALUE (arglist); | |
5024 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5025 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5026 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5027 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5028 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5029 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5030 | int form_int; | |
5031 | enum rtx_code code; | |
5032 | ||
5033 | if (TREE_CODE (form) != INTEGER_CST) | |
5034 | { | |
5035 | error ("argument 1 of __builtin_spe_predicate must be a constant"); | |
5036 | return const0_rtx; | |
5037 | } | |
5038 | else | |
5039 | form_int = TREE_INT_CST_LOW (form); | |
5040 | ||
5041 | if (mode0 != mode1) | |
5042 | abort (); | |
5043 | ||
5044 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
5045 | return const0_rtx; | |
5046 | ||
5047 | if (target == 0 | |
5048 | || GET_MODE (target) != SImode | |
5049 | || ! (*insn_data[icode].operand[0].predicate) (target, SImode)) | |
5050 | target = gen_reg_rtx (SImode); | |
5051 | ||
5052 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5053 | op0 = copy_to_mode_reg (mode0, op0); | |
5054 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5055 | op1 = copy_to_mode_reg (mode1, op1); | |
5056 | ||
5057 | scratch = gen_reg_rtx (CCmode); | |
5058 | ||
5059 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
5060 | if (! pat) | |
5061 | return const0_rtx; | |
5062 | emit_insn (pat); | |
5063 | ||
5064 | /* There are 4 variants for each predicate: _any_, _all_, _upper_, | |
5065 | _lower_. We use one compare, but look in different bits of the | |
5066 | CR for each variant. | |
5067 | ||
5068 | There are 2 elements in each SPE simd type (upper/lower). The CR | |
5069 | bits are set as follows: | |
5070 | ||
5071 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
5072 | U | L | (U | L) | (U & L) | |
5073 | ||
5074 | So, for an "all" relationship, BIT 3 would be set. | |
5075 | For an "any" relationship, BIT 2 would be set. Etc. | |
5076 | ||
5077 | Following traditional nomenclature, these bits map to: | |
5078 | ||
5079 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
5080 | LT | GT | EQ | OV | |
5081 | ||
5082 | Later, we will generate rtl to look in the LT/EQ/EQ/OV bits. | |
5083 | */ | |
5084 | ||
5085 | switch (form_int) | |
5086 | { | |
5087 | /* All variant. OV bit. */ | |
5088 | case 0: | |
5089 | /* We need to get to the OV bit, which is the ORDERED bit. We | |
5090 | could generate (ordered:SI (reg:CC xx) (const_int 0)), but | |
5091 | that's ugly and will trigger a validate_condition_mode abort. | |
5092 | So let's just use another pattern. */ | |
5093 | emit_insn (gen_move_from_CR_ov_bit (target, scratch)); | |
5094 | return target; | |
5095 | /* Any variant. EQ bit. */ | |
5096 | case 1: | |
5097 | code = EQ; | |
5098 | break; | |
5099 | /* Upper variant. LT bit. */ | |
5100 | case 2: | |
5101 | code = LT; | |
5102 | break; | |
5103 | /* Lower variant. GT bit. */ | |
5104 | case 3: | |
5105 | code = GT; | |
5106 | break; | |
5107 | default: | |
5108 | error ("argument 1 of __builtin_spe_predicate is out of range"); | |
5109 | return const0_rtx; | |
5110 | } | |
5111 | ||
5112 | tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx); | |
5113 | emit_move_insn (target, tmp); | |
5114 | ||
5115 | return target; | |
5116 | } | |
5117 | ||
5118 | /* The evsel builtins look like this: | |
5119 | ||
5120 | e = __builtin_spe_evsel_OP (a, b, c, d); | |
5121 | ||
5122 | and work like this: | |
5123 | ||
5124 | e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper]; | |
5125 | e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower]; | |
5126 | */ | |
5127 | ||
5128 | static rtx | |
5129 | spe_expand_evsel_builtin (icode, arglist, target) | |
5130 | enum insn_code icode; | |
5131 | tree arglist; | |
5132 | rtx target; | |
5133 | { | |
5134 | rtx pat, scratch; | |
5135 | tree arg0 = TREE_VALUE (arglist); | |
5136 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5137 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5138 | tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist)))); | |
5139 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5140 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5141 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
5142 | rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0); | |
5143 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5144 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5145 | ||
5146 | if (mode0 != mode1) | |
5147 | abort (); | |
5148 | ||
5149 | if (arg0 == error_mark_node || arg1 == error_mark_node | |
5150 | || arg2 == error_mark_node || arg3 == error_mark_node) | |
5151 | return const0_rtx; | |
5152 | ||
5153 | if (target == 0 | |
5154 | || GET_MODE (target) != mode0 | |
5155 | || ! (*insn_data[icode].operand[0].predicate) (target, mode0)) | |
5156 | target = gen_reg_rtx (mode0); | |
5157 | ||
5158 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5159 | op0 = copy_to_mode_reg (mode0, op0); | |
5160 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
5161 | op1 = copy_to_mode_reg (mode0, op1); | |
5162 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
5163 | op2 = copy_to_mode_reg (mode0, op2); | |
5164 | if (! (*insn_data[icode].operand[1].predicate) (op3, mode1)) | |
5165 | op3 = copy_to_mode_reg (mode0, op3); | |
5166 | ||
5167 | /* Generate the compare. */ | |
5168 | scratch = gen_reg_rtx (CCmode); | |
5169 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
5170 | if (! pat) | |
5171 | return const0_rtx; | |
5172 | emit_insn (pat); | |
5173 | ||
5174 | if (mode0 == V2SImode) | |
5175 | emit_insn (gen_spe_evsel (target, op2, op3, scratch)); | |
5176 | else | |
5177 | emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch)); | |
5178 | ||
5179 | return target; | |
5180 | } | |
5181 | ||
0ac081f6 AH |
5182 | /* Expand an expression EXP that calls a built-in function, |
5183 | with result going to TARGET if that's convenient | |
5184 | (and in mode MODE if that's convenient). | |
5185 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
5186 | IGNORE is nonzero if the value is to be ignored. */ | |
5187 | ||
5188 | static rtx | |
5189 | rs6000_expand_builtin (exp, target, subtarget, mode, ignore) | |
5190 | tree exp; | |
5191 | rtx target; | |
00b960c7 AH |
5192 | rtx subtarget ATTRIBUTE_UNUSED; |
5193 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
5194 | int ignore ATTRIBUTE_UNUSED; | |
0ac081f6 | 5195 | { |
92898235 AH |
5196 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
5197 | tree arglist = TREE_OPERAND (exp, 1); | |
5198 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
5199 | struct builtin_description *d; | |
5200 | size_t i; | |
5201 | rtx ret; | |
5202 | bool success; | |
5203 | ||
0ac081f6 | 5204 | if (TARGET_ALTIVEC) |
92898235 AH |
5205 | { |
5206 | ret = altivec_expand_builtin (exp, target, &success); | |
5207 | ||
a3170dc6 AH |
5208 | if (success) |
5209 | return ret; | |
5210 | } | |
5211 | if (TARGET_SPE) | |
5212 | { | |
5213 | ret = spe_expand_builtin (exp, target, &success); | |
5214 | ||
92898235 AH |
5215 | if (success) |
5216 | return ret; | |
5217 | } | |
5218 | ||
0559cc77 DE |
5219 | if (TARGET_ALTIVEC || TARGET_SPE) |
5220 | { | |
5221 | /* Handle simple unary operations. */ | |
5222 | d = (struct builtin_description *) bdesc_1arg; | |
5223 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) | |
5224 | if (d->code == fcode) | |
5225 | return rs6000_expand_unop_builtin (d->icode, arglist, target); | |
5226 | ||
5227 | /* Handle simple binary operations. */ | |
5228 | d = (struct builtin_description *) bdesc_2arg; | |
5229 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) | |
5230 | if (d->code == fcode) | |
5231 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
5232 | ||
5233 | /* Handle simple ternary operations. */ | |
5234 | d = (struct builtin_description *) bdesc_3arg; | |
5235 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) | |
5236 | if (d->code == fcode) | |
5237 | return rs6000_expand_ternop_builtin (d->icode, arglist, target); | |
5238 | } | |
0ac081f6 AH |
5239 | |
5240 | abort (); | |
92898235 | 5241 | return NULL_RTX; |
0ac081f6 AH |
5242 | } |
5243 | ||
5244 | static void | |
6fa3f289 | 5245 | rs6000_init_builtins () |
0ac081f6 | 5246 | { |
a3170dc6 AH |
5247 | if (TARGET_SPE) |
5248 | spe_init_builtins (); | |
0ac081f6 AH |
5249 | if (TARGET_ALTIVEC) |
5250 | altivec_init_builtins (); | |
0559cc77 DE |
5251 | if (TARGET_ALTIVEC || TARGET_SPE) |
5252 | rs6000_common_init_builtins (); | |
0ac081f6 AH |
5253 | } |
5254 | ||
a3170dc6 AH |
5255 | /* Search through a set of builtins and enable the mask bits. |
5256 | DESC is an array of builtins. | |
b6d08ca1 | 5257 | SIZE is the total number of builtins. |
a3170dc6 AH |
5258 | START is the builtin enum at which to start. |
5259 | END is the builtin enum at which to end. */ | |
0ac081f6 | 5260 | static void |
a3170dc6 AH |
5261 | enable_mask_for_builtins (desc, size, start, end) |
5262 | struct builtin_description *desc; | |
5263 | int size; | |
5264 | enum rs6000_builtins start, end; | |
5265 | { | |
5266 | int i; | |
5267 | ||
5268 | for (i = 0; i < size; ++i) | |
5269 | if (desc[i].code == start) | |
5270 | break; | |
5271 | ||
5272 | if (i == size) | |
5273 | return; | |
5274 | ||
5275 | for (; i < size; ++i) | |
5276 | { | |
5277 | /* Flip all the bits on. */ | |
5278 | desc[i].mask = target_flags; | |
5279 | if (desc[i].code == end) | |
5280 | break; | |
5281 | } | |
5282 | } | |
5283 | ||
5284 | static void | |
b24c9d35 | 5285 | spe_init_builtins () |
0ac081f6 | 5286 | { |
a3170dc6 AH |
5287 | tree endlink = void_list_node; |
5288 | tree puint_type_node = build_pointer_type (unsigned_type_node); | |
5289 | tree pushort_type_node = build_pointer_type (short_unsigned_type_node); | |
5290 | tree pv2si_type_node = build_pointer_type (V2SI_type_node); | |
ae4b4a02 | 5291 | struct builtin_description *d; |
0ac081f6 AH |
5292 | size_t i; |
5293 | ||
a3170dc6 AH |
5294 | tree v2si_ftype_4_v2si |
5295 | = build_function_type | |
5296 | (V2SI_type_node, | |
5297 | tree_cons (NULL_TREE, V2SI_type_node, | |
5298 | tree_cons (NULL_TREE, V2SI_type_node, | |
5299 | tree_cons (NULL_TREE, V2SI_type_node, | |
5300 | tree_cons (NULL_TREE, V2SI_type_node, | |
5301 | endlink))))); | |
5302 | ||
5303 | tree v2sf_ftype_4_v2sf | |
5304 | = build_function_type | |
5305 | (V2SF_type_node, | |
5306 | tree_cons (NULL_TREE, V2SF_type_node, | |
5307 | tree_cons (NULL_TREE, V2SF_type_node, | |
5308 | tree_cons (NULL_TREE, V2SF_type_node, | |
5309 | tree_cons (NULL_TREE, V2SF_type_node, | |
5310 | endlink))))); | |
5311 | ||
5312 | tree int_ftype_int_v2si_v2si | |
5313 | = build_function_type | |
5314 | (integer_type_node, | |
5315 | tree_cons (NULL_TREE, integer_type_node, | |
5316 | tree_cons (NULL_TREE, V2SI_type_node, | |
5317 | tree_cons (NULL_TREE, V2SI_type_node, | |
5318 | endlink)))); | |
5319 | ||
5320 | tree int_ftype_int_v2sf_v2sf | |
5321 | = build_function_type | |
5322 | (integer_type_node, | |
5323 | tree_cons (NULL_TREE, integer_type_node, | |
5324 | tree_cons (NULL_TREE, V2SF_type_node, | |
5325 | tree_cons (NULL_TREE, V2SF_type_node, | |
5326 | endlink)))); | |
5327 | ||
5328 | tree void_ftype_v2si_puint_int | |
5329 | = build_function_type (void_type_node, | |
5330 | tree_cons (NULL_TREE, V2SI_type_node, | |
5331 | tree_cons (NULL_TREE, puint_type_node, | |
5332 | tree_cons (NULL_TREE, | |
5333 | integer_type_node, | |
5334 | endlink)))); | |
5335 | ||
5336 | tree void_ftype_v2si_puint_char | |
5337 | = build_function_type (void_type_node, | |
5338 | tree_cons (NULL_TREE, V2SI_type_node, | |
5339 | tree_cons (NULL_TREE, puint_type_node, | |
5340 | tree_cons (NULL_TREE, | |
5341 | char_type_node, | |
5342 | endlink)))); | |
5343 | ||
5344 | tree void_ftype_v2si_pv2si_int | |
5345 | = build_function_type (void_type_node, | |
5346 | tree_cons (NULL_TREE, V2SI_type_node, | |
5347 | tree_cons (NULL_TREE, pv2si_type_node, | |
5348 | tree_cons (NULL_TREE, | |
5349 | integer_type_node, | |
5350 | endlink)))); | |
5351 | ||
5352 | tree void_ftype_v2si_pv2si_char | |
5353 | = build_function_type (void_type_node, | |
5354 | tree_cons (NULL_TREE, V2SI_type_node, | |
5355 | tree_cons (NULL_TREE, pv2si_type_node, | |
5356 | tree_cons (NULL_TREE, | |
5357 | char_type_node, | |
5358 | endlink)))); | |
5359 | ||
5360 | tree void_ftype_int | |
5361 | = build_function_type (void_type_node, | |
5362 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
5363 | ||
5364 | tree int_ftype_void | |
5365 | = build_function_type (integer_type_node, | |
5366 | tree_cons (NULL_TREE, void_type_node, endlink)); | |
5367 | ||
5368 | tree v2si_ftype_pv2si_int | |
5369 | = build_function_type (V2SI_type_node, | |
5370 | tree_cons (NULL_TREE, pv2si_type_node, | |
5371 | tree_cons (NULL_TREE, integer_type_node, | |
5372 | endlink))); | |
5373 | ||
5374 | tree v2si_ftype_puint_int | |
5375 | = build_function_type (V2SI_type_node, | |
5376 | tree_cons (NULL_TREE, puint_type_node, | |
5377 | tree_cons (NULL_TREE, integer_type_node, | |
5378 | endlink))); | |
5379 | ||
5380 | tree v2si_ftype_pushort_int | |
5381 | = build_function_type (V2SI_type_node, | |
5382 | tree_cons (NULL_TREE, pushort_type_node, | |
5383 | tree_cons (NULL_TREE, integer_type_node, | |
5384 | endlink))); | |
5385 | ||
5386 | /* The initialization of the simple binary and unary builtins is | |
5387 | done in rs6000_common_init_builtins, but we have to enable the | |
5388 | mask bits here manually because we have run out of `target_flags' | |
5389 | bits. We really need to redesign this mask business. */ | |
5390 | ||
5391 | enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg, | |
5392 | ARRAY_SIZE (bdesc_2arg), | |
5393 | SPE_BUILTIN_EVADDW, | |
5394 | SPE_BUILTIN_EVXOR); | |
5395 | enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg, | |
5396 | ARRAY_SIZE (bdesc_1arg), | |
5397 | SPE_BUILTIN_EVABS, | |
5398 | SPE_BUILTIN_EVSUBFUSIAAW); | |
5399 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates, | |
5400 | ARRAY_SIZE (bdesc_spe_predicates), | |
5401 | SPE_BUILTIN_EVCMPEQ, | |
5402 | SPE_BUILTIN_EVFSTSTLT); | |
5403 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel, | |
5404 | ARRAY_SIZE (bdesc_spe_evsel), | |
5405 | SPE_BUILTIN_EVSEL_CMPGTS, | |
5406 | SPE_BUILTIN_EVSEL_FSTSTEQ); | |
5407 | ||
5408 | /* Initialize irregular SPE builtins. */ | |
5409 | ||
5410 | def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR); | |
5411 | def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR); | |
5412 | def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX); | |
5413 | def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX); | |
5414 | def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX); | |
5415 | def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX); | |
5416 | def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX); | |
5417 | def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX); | |
5418 | def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX); | |
5419 | def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD); | |
5420 | def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH); | |
5421 | def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW); | |
5422 | def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE); | |
5423 | def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO); | |
5424 | def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE); | |
5425 | def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO); | |
5426 | ||
5427 | /* Loads. */ | |
5428 | def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX); | |
5429 | def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX); | |
5430 | def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX); | |
5431 | def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX); | |
5432 | def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX); | |
5433 | def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX); | |
5434 | def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX); | |
5435 | def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX); | |
5436 | def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX); | |
5437 | def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX); | |
5438 | def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX); | |
5439 | def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD); | |
5440 | def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW); | |
5441 | def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH); | |
5442 | def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT); | |
5443 | def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT); | |
5444 | def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT); | |
5445 | def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE); | |
5446 | def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS); | |
5447 | def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU); | |
5448 | def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT); | |
5449 | def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT); | |
5450 | ||
5451 | /* Predicates. */ | |
5452 | d = (struct builtin_description *) bdesc_spe_predicates; | |
5453 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++) | |
5454 | { | |
5455 | tree type; | |
5456 | ||
5457 | switch (insn_data[d->icode].operand[1].mode) | |
5458 | { | |
5459 | case V2SImode: | |
5460 | type = int_ftype_int_v2si_v2si; | |
5461 | break; | |
5462 | case V2SFmode: | |
5463 | type = int_ftype_int_v2sf_v2sf; | |
5464 | break; | |
5465 | default: | |
5466 | abort (); | |
5467 | } | |
5468 | ||
5469 | def_builtin (d->mask, d->name, type, d->code); | |
5470 | } | |
5471 | ||
5472 | /* Evsel predicates. */ | |
5473 | d = (struct builtin_description *) bdesc_spe_evsel; | |
5474 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++) | |
5475 | { | |
5476 | tree type; | |
5477 | ||
5478 | switch (insn_data[d->icode].operand[1].mode) | |
5479 | { | |
5480 | case V2SImode: | |
5481 | type = v2si_ftype_4_v2si; | |
5482 | break; | |
5483 | case V2SFmode: | |
5484 | type = v2sf_ftype_4_v2sf; | |
5485 | break; | |
5486 | default: | |
5487 | abort (); | |
5488 | } | |
5489 | ||
5490 | def_builtin (d->mask, d->name, type, d->code); | |
5491 | } | |
5492 | } | |
5493 | ||
5494 | static void | |
b24c9d35 | 5495 | altivec_init_builtins () |
a3170dc6 AH |
5496 | { |
5497 | struct builtin_description *d; | |
5498 | struct builtin_description_predicates *dp; | |
5499 | size_t i; | |
5500 | tree pfloat_type_node = build_pointer_type (float_type_node); | |
5501 | tree pint_type_node = build_pointer_type (integer_type_node); | |
5502 | tree pshort_type_node = build_pointer_type (short_integer_type_node); | |
5503 | tree pchar_type_node = build_pointer_type (char_type_node); | |
5504 | ||
5505 | tree pvoid_type_node = build_pointer_type (void_type_node); | |
5506 | ||
0dbc3651 ZW |
5507 | tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST)); |
5508 | tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST)); | |
5509 | tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST)); | |
5510 | tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); | |
5511 | ||
5512 | tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST)); | |
5513 | ||
a3170dc6 AH |
5514 | tree int_ftype_int_v4si_v4si |
5515 | = build_function_type_list (integer_type_node, | |
5516 | integer_type_node, V4SI_type_node, | |
5517 | V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
5518 | tree v4sf_ftype_pcfloat |
5519 | = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE); | |
a3170dc6 | 5520 | tree void_ftype_pfloat_v4sf |
b4de2f7d | 5521 | = build_function_type_list (void_type_node, |
a3170dc6 | 5522 | pfloat_type_node, V4SF_type_node, NULL_TREE); |
0dbc3651 ZW |
5523 | tree v4si_ftype_pcint |
5524 | = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE); | |
5525 | tree void_ftype_pint_v4si | |
b4de2f7d AH |
5526 | = build_function_type_list (void_type_node, |
5527 | pint_type_node, V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
5528 | tree v8hi_ftype_pcshort |
5529 | = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE); | |
f18c054f | 5530 | tree void_ftype_pshort_v8hi |
b4de2f7d AH |
5531 | = build_function_type_list (void_type_node, |
5532 | pshort_type_node, V8HI_type_node, NULL_TREE); | |
0dbc3651 ZW |
5533 | tree v16qi_ftype_pcchar |
5534 | = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE); | |
f18c054f | 5535 | tree void_ftype_pchar_v16qi |
b4de2f7d AH |
5536 | = build_function_type_list (void_type_node, |
5537 | pchar_type_node, V16QI_type_node, NULL_TREE); | |
95385cbb | 5538 | tree void_ftype_v4si |
b4de2f7d | 5539 | = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE); |
a3170dc6 AH |
5540 | tree v8hi_ftype_void |
5541 | = build_function_type (V8HI_type_node, void_list_node); | |
5542 | tree void_ftype_void | |
5543 | = build_function_type (void_type_node, void_list_node); | |
5544 | tree void_ftype_qi | |
5545 | = build_function_type_list (void_type_node, char_type_node, NULL_TREE); | |
0dbc3651 ZW |
5546 | |
5547 | tree v16qi_ftype_int_pcvoid | |
a3170dc6 | 5548 | = build_function_type_list (V16QI_type_node, |
0dbc3651 ZW |
5549 | integer_type_node, pcvoid_type_node, NULL_TREE); |
5550 | tree v8hi_ftype_int_pcvoid | |
a3170dc6 | 5551 | = build_function_type_list (V8HI_type_node, |
0dbc3651 ZW |
5552 | integer_type_node, pcvoid_type_node, NULL_TREE); |
5553 | tree v4si_ftype_int_pcvoid | |
a3170dc6 | 5554 | = build_function_type_list (V4SI_type_node, |
0dbc3651 ZW |
5555 | integer_type_node, pcvoid_type_node, NULL_TREE); |
5556 | ||
14b32f4e | 5557 | tree void_ftype_v4si_int_pvoid |
b4de2f7d AH |
5558 | = build_function_type_list (void_type_node, |
5559 | V4SI_type_node, integer_type_node, | |
5560 | pvoid_type_node, NULL_TREE); | |
6525c0e7 | 5561 | tree void_ftype_v16qi_int_pvoid |
b4de2f7d AH |
5562 | = build_function_type_list (void_type_node, |
5563 | V16QI_type_node, integer_type_node, | |
5564 | pvoid_type_node, NULL_TREE); | |
6525c0e7 | 5565 | tree void_ftype_v8hi_int_pvoid |
b4de2f7d AH |
5566 | = build_function_type_list (void_type_node, |
5567 | V8HI_type_node, integer_type_node, | |
5568 | pvoid_type_node, NULL_TREE); | |
a3170dc6 AH |
5569 | tree int_ftype_int_v8hi_v8hi |
5570 | = build_function_type_list (integer_type_node, | |
5571 | integer_type_node, V8HI_type_node, | |
5572 | V8HI_type_node, NULL_TREE); | |
5573 | tree int_ftype_int_v16qi_v16qi | |
5574 | = build_function_type_list (integer_type_node, | |
5575 | integer_type_node, V16QI_type_node, | |
5576 | V16QI_type_node, NULL_TREE); | |
5577 | tree int_ftype_int_v4sf_v4sf | |
5578 | = build_function_type_list (integer_type_node, | |
5579 | integer_type_node, V4SF_type_node, | |
5580 | V4SF_type_node, NULL_TREE); | |
5581 | tree v4si_ftype_v4si | |
5582 | = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE); | |
5583 | tree v8hi_ftype_v8hi | |
5584 | = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE); | |
5585 | tree v16qi_ftype_v16qi | |
5586 | = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE); | |
5587 | tree v4sf_ftype_v4sf | |
5588 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0dbc3651 | 5589 | tree void_ftype_pcvoid_int_char |
a3170dc6 | 5590 | = build_function_type_list (void_type_node, |
0dbc3651 | 5591 | pcvoid_type_node, integer_type_node, |
a3170dc6 | 5592 | char_type_node, NULL_TREE); |
0dbc3651 ZW |
5593 | |
5594 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat, | |
5595 | ALTIVEC_BUILTIN_LD_INTERNAL_4sf); | |
5596 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, | |
5597 | ALTIVEC_BUILTIN_ST_INTERNAL_4sf); | |
5598 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint, | |
5599 | ALTIVEC_BUILTIN_LD_INTERNAL_4si); | |
5600 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, | |
5601 | ALTIVEC_BUILTIN_ST_INTERNAL_4si); | |
5602 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort, | |
5603 | ALTIVEC_BUILTIN_LD_INTERNAL_8hi); | |
5604 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, | |
5605 | ALTIVEC_BUILTIN_ST_INTERNAL_8hi); | |
5606 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar, | |
5607 | ALTIVEC_BUILTIN_LD_INTERNAL_16qi); | |
5608 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, | |
5609 | ALTIVEC_BUILTIN_ST_INTERNAL_16qi); | |
a3170dc6 AH |
5610 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR); |
5611 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR); | |
5612 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL); | |
5613 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS); | |
0dbc3651 ZW |
5614 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSL); |
5615 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSR); | |
5616 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEBX); | |
5617 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEHX); | |
5618 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEWX); | |
5619 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVXL); | |
5620 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVX); | |
a3170dc6 AH |
5621 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVX); |
5622 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVEWX); | |
5623 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVXL); | |
5624 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_int_pvoid, ALTIVEC_BUILTIN_STVEBX); | |
5625 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_int_pvoid, ALTIVEC_BUILTIN_STVEHX); | |
5626 | ||
5627 | /* Add the DST variants. */ | |
5628 | d = (struct builtin_description *) bdesc_dst; | |
5629 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
0dbc3651 | 5630 | def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code); |
a3170dc6 AH |
5631 | |
5632 | /* Initialize the predicates. */ | |
5633 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
5634 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) | |
5635 | { | |
5636 | enum machine_mode mode1; | |
5637 | tree type; | |
5638 | ||
5639 | mode1 = insn_data[dp->icode].operand[1].mode; | |
5640 | ||
5641 | switch (mode1) | |
5642 | { | |
5643 | case V4SImode: | |
5644 | type = int_ftype_int_v4si_v4si; | |
5645 | break; | |
5646 | case V8HImode: | |
5647 | type = int_ftype_int_v8hi_v8hi; | |
5648 | break; | |
5649 | case V16QImode: | |
5650 | type = int_ftype_int_v16qi_v16qi; | |
5651 | break; | |
5652 | case V4SFmode: | |
5653 | type = int_ftype_int_v4sf_v4sf; | |
5654 | break; | |
5655 | default: | |
5656 | abort (); | |
5657 | } | |
5658 | ||
5659 | def_builtin (dp->mask, dp->name, type, dp->code); | |
5660 | } | |
5661 | ||
5662 | /* Initialize the abs* operators. */ | |
5663 | d = (struct builtin_description *) bdesc_abs; | |
5664 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) | |
5665 | { | |
5666 | enum machine_mode mode0; | |
5667 | tree type; | |
5668 | ||
5669 | mode0 = insn_data[d->icode].operand[0].mode; | |
5670 | ||
5671 | switch (mode0) | |
5672 | { | |
5673 | case V4SImode: | |
5674 | type = v4si_ftype_v4si; | |
5675 | break; | |
5676 | case V8HImode: | |
5677 | type = v8hi_ftype_v8hi; | |
5678 | break; | |
5679 | case V16QImode: | |
5680 | type = v16qi_ftype_v16qi; | |
5681 | break; | |
5682 | case V4SFmode: | |
5683 | type = v4sf_ftype_v4sf; | |
5684 | break; | |
5685 | default: | |
5686 | abort (); | |
5687 | } | |
5688 | ||
5689 | def_builtin (d->mask, d->name, type, d->code); | |
5690 | } | |
5691 | } | |
5692 | ||
5693 | static void | |
b24c9d35 | 5694 | rs6000_common_init_builtins () |
a3170dc6 AH |
5695 | { |
5696 | struct builtin_description *d; | |
5697 | size_t i; | |
5698 | ||
5699 | tree v4sf_ftype_v4sf_v4sf_v16qi | |
5700 | = build_function_type_list (V4SF_type_node, | |
5701 | V4SF_type_node, V4SF_type_node, | |
5702 | V16QI_type_node, NULL_TREE); | |
5703 | tree v4si_ftype_v4si_v4si_v16qi | |
5704 | = build_function_type_list (V4SI_type_node, | |
5705 | V4SI_type_node, V4SI_type_node, | |
5706 | V16QI_type_node, NULL_TREE); | |
5707 | tree v8hi_ftype_v8hi_v8hi_v16qi | |
5708 | = build_function_type_list (V8HI_type_node, | |
5709 | V8HI_type_node, V8HI_type_node, | |
5710 | V16QI_type_node, NULL_TREE); | |
5711 | tree v16qi_ftype_v16qi_v16qi_v16qi | |
5712 | = build_function_type_list (V16QI_type_node, | |
5713 | V16QI_type_node, V16QI_type_node, | |
5714 | V16QI_type_node, NULL_TREE); | |
5715 | tree v4si_ftype_char | |
5716 | = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE); | |
5717 | tree v8hi_ftype_char | |
5718 | = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE); | |
5719 | tree v16qi_ftype_char | |
5720 | = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE); | |
5721 | tree v8hi_ftype_v16qi | |
5722 | = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE); | |
5723 | tree v4sf_ftype_v4sf | |
5724 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
5725 | ||
5726 | tree v2si_ftype_v2si_v2si | |
5727 | = build_function_type_list (V2SI_type_node, | |
5728 | V2SI_type_node, V2SI_type_node, NULL_TREE); | |
5729 | ||
5730 | tree v2sf_ftype_v2sf_v2sf | |
5731 | = build_function_type_list (V2SF_type_node, | |
5732 | V2SF_type_node, V2SF_type_node, NULL_TREE); | |
5733 | ||
5734 | tree v2si_ftype_int_int | |
5735 | = build_function_type_list (V2SI_type_node, | |
5736 | integer_type_node, integer_type_node, | |
5737 | NULL_TREE); | |
5738 | ||
5739 | tree v2si_ftype_v2si | |
5740 | = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE); | |
5741 | ||
5742 | tree v2sf_ftype_v2sf | |
5743 | = build_function_type_list (V2SF_type_node, | |
5744 | V2SF_type_node, NULL_TREE); | |
5745 | ||
5746 | tree v2sf_ftype_v2si | |
5747 | = build_function_type_list (V2SF_type_node, | |
5748 | V2SI_type_node, NULL_TREE); | |
5749 | ||
5750 | tree v2si_ftype_v2sf | |
5751 | = build_function_type_list (V2SI_type_node, | |
5752 | V2SF_type_node, NULL_TREE); | |
5753 | ||
5754 | tree v2si_ftype_v2si_char | |
5755 | = build_function_type_list (V2SI_type_node, | |
5756 | V2SI_type_node, char_type_node, NULL_TREE); | |
5757 | ||
5758 | tree v2si_ftype_int_char | |
5759 | = build_function_type_list (V2SI_type_node, | |
5760 | integer_type_node, char_type_node, NULL_TREE); | |
5761 | ||
5762 | tree v2si_ftype_char | |
5763 | = build_function_type_list (V2SI_type_node, char_type_node, NULL_TREE); | |
5764 | ||
5765 | tree int_ftype_int_int | |
5766 | = build_function_type_list (integer_type_node, | |
5767 | integer_type_node, integer_type_node, | |
5768 | NULL_TREE); | |
95385cbb | 5769 | |
0ac081f6 | 5770 | tree v4si_ftype_v4si_v4si |
b4de2f7d AH |
5771 | = build_function_type_list (V4SI_type_node, |
5772 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
617e0e1d | 5773 | tree v4sf_ftype_v4si_char |
b4de2f7d AH |
5774 | = build_function_type_list (V4SF_type_node, |
5775 | V4SI_type_node, char_type_node, NULL_TREE); | |
617e0e1d | 5776 | tree v4si_ftype_v4sf_char |
b4de2f7d AH |
5777 | = build_function_type_list (V4SI_type_node, |
5778 | V4SF_type_node, char_type_node, NULL_TREE); | |
2212663f | 5779 | tree v4si_ftype_v4si_char |
b4de2f7d AH |
5780 | = build_function_type_list (V4SI_type_node, |
5781 | V4SI_type_node, char_type_node, NULL_TREE); | |
2212663f | 5782 | tree v8hi_ftype_v8hi_char |
b4de2f7d AH |
5783 | = build_function_type_list (V8HI_type_node, |
5784 | V8HI_type_node, char_type_node, NULL_TREE); | |
2212663f | 5785 | tree v16qi_ftype_v16qi_char |
b4de2f7d AH |
5786 | = build_function_type_list (V16QI_type_node, |
5787 | V16QI_type_node, char_type_node, NULL_TREE); | |
24408032 | 5788 | tree v16qi_ftype_v16qi_v16qi_char |
b4de2f7d AH |
5789 | = build_function_type_list (V16QI_type_node, |
5790 | V16QI_type_node, V16QI_type_node, | |
5791 | char_type_node, NULL_TREE); | |
24408032 | 5792 | tree v8hi_ftype_v8hi_v8hi_char |
b4de2f7d AH |
5793 | = build_function_type_list (V8HI_type_node, |
5794 | V8HI_type_node, V8HI_type_node, | |
5795 | char_type_node, NULL_TREE); | |
24408032 | 5796 | tree v4si_ftype_v4si_v4si_char |
b4de2f7d AH |
5797 | = build_function_type_list (V4SI_type_node, |
5798 | V4SI_type_node, V4SI_type_node, | |
5799 | char_type_node, NULL_TREE); | |
24408032 | 5800 | tree v4sf_ftype_v4sf_v4sf_char |
b4de2f7d AH |
5801 | = build_function_type_list (V4SF_type_node, |
5802 | V4SF_type_node, V4SF_type_node, | |
5803 | char_type_node, NULL_TREE); | |
0ac081f6 | 5804 | tree v4sf_ftype_v4sf_v4sf |
b4de2f7d AH |
5805 | = build_function_type_list (V4SF_type_node, |
5806 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
617e0e1d | 5807 | tree v4sf_ftype_v4sf_v4sf_v4si |
b4de2f7d AH |
5808 | = build_function_type_list (V4SF_type_node, |
5809 | V4SF_type_node, V4SF_type_node, | |
5810 | V4SI_type_node, NULL_TREE); | |
2212663f | 5811 | tree v4sf_ftype_v4sf_v4sf_v4sf |
b4de2f7d AH |
5812 | = build_function_type_list (V4SF_type_node, |
5813 | V4SF_type_node, V4SF_type_node, | |
5814 | V4SF_type_node, NULL_TREE); | |
617e0e1d | 5815 | tree v4si_ftype_v4si_v4si_v4si |
b4de2f7d AH |
5816 | = build_function_type_list (V4SI_type_node, |
5817 | V4SI_type_node, V4SI_type_node, | |
5818 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 5819 | tree v8hi_ftype_v8hi_v8hi |
b4de2f7d AH |
5820 | = build_function_type_list (V8HI_type_node, |
5821 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
2212663f | 5822 | tree v8hi_ftype_v8hi_v8hi_v8hi |
b4de2f7d AH |
5823 | = build_function_type_list (V8HI_type_node, |
5824 | V8HI_type_node, V8HI_type_node, | |
5825 | V8HI_type_node, NULL_TREE); | |
2212663f | 5826 | tree v4si_ftype_v8hi_v8hi_v4si |
b4de2f7d AH |
5827 | = build_function_type_list (V4SI_type_node, |
5828 | V8HI_type_node, V8HI_type_node, | |
5829 | V4SI_type_node, NULL_TREE); | |
2212663f | 5830 | tree v4si_ftype_v16qi_v16qi_v4si |
b4de2f7d AH |
5831 | = build_function_type_list (V4SI_type_node, |
5832 | V16QI_type_node, V16QI_type_node, | |
5833 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 5834 | tree v16qi_ftype_v16qi_v16qi |
b4de2f7d AH |
5835 | = build_function_type_list (V16QI_type_node, |
5836 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 5837 | tree v4si_ftype_v4sf_v4sf |
b4de2f7d AH |
5838 | = build_function_type_list (V4SI_type_node, |
5839 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0ac081f6 | 5840 | tree v8hi_ftype_v16qi_v16qi |
b4de2f7d AH |
5841 | = build_function_type_list (V8HI_type_node, |
5842 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 5843 | tree v4si_ftype_v8hi_v8hi |
b4de2f7d AH |
5844 | = build_function_type_list (V4SI_type_node, |
5845 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 5846 | tree v8hi_ftype_v4si_v4si |
b4de2f7d AH |
5847 | = build_function_type_list (V8HI_type_node, |
5848 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
0ac081f6 | 5849 | tree v16qi_ftype_v8hi_v8hi |
b4de2f7d AH |
5850 | = build_function_type_list (V16QI_type_node, |
5851 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 5852 | tree v4si_ftype_v16qi_v4si |
b4de2f7d AH |
5853 | = build_function_type_list (V4SI_type_node, |
5854 | V16QI_type_node, V4SI_type_node, NULL_TREE); | |
fa066a23 | 5855 | tree v4si_ftype_v16qi_v16qi |
b4de2f7d AH |
5856 | = build_function_type_list (V4SI_type_node, |
5857 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 5858 | tree v4si_ftype_v8hi_v4si |
b4de2f7d AH |
5859 | = build_function_type_list (V4SI_type_node, |
5860 | V8HI_type_node, V4SI_type_node, NULL_TREE); | |
a3170dc6 AH |
5861 | tree v4si_ftype_v8hi |
5862 | = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE); | |
5863 | tree int_ftype_v4si_v4si | |
5864 | = build_function_type_list (integer_type_node, | |
5865 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
5866 | tree int_ftype_v4sf_v4sf | |
5867 | = build_function_type_list (integer_type_node, | |
5868 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
5869 | tree int_ftype_v16qi_v16qi | |
5870 | = build_function_type_list (integer_type_node, | |
5871 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 5872 | tree int_ftype_v8hi_v8hi |
b4de2f7d AH |
5873 | = build_function_type_list (integer_type_node, |
5874 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 5875 | |
6f317ef3 | 5876 | /* Add the simple ternary operators. */ |
2212663f | 5877 | d = (struct builtin_description *) bdesc_3arg; |
ca7558fc | 5878 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) |
2212663f DB |
5879 | { |
5880 | ||
5881 | enum machine_mode mode0, mode1, mode2, mode3; | |
5882 | tree type; | |
5883 | ||
0559cc77 | 5884 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
5885 | continue; |
5886 | ||
5887 | mode0 = insn_data[d->icode].operand[0].mode; | |
5888 | mode1 = insn_data[d->icode].operand[1].mode; | |
5889 | mode2 = insn_data[d->icode].operand[2].mode; | |
5890 | mode3 = insn_data[d->icode].operand[3].mode; | |
5891 | ||
5892 | /* When all four are of the same mode. */ | |
5893 | if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3) | |
5894 | { | |
5895 | switch (mode0) | |
5896 | { | |
617e0e1d DB |
5897 | case V4SImode: |
5898 | type = v4si_ftype_v4si_v4si_v4si; | |
5899 | break; | |
2212663f DB |
5900 | case V4SFmode: |
5901 | type = v4sf_ftype_v4sf_v4sf_v4sf; | |
5902 | break; | |
5903 | case V8HImode: | |
5904 | type = v8hi_ftype_v8hi_v8hi_v8hi; | |
5905 | break; | |
5906 | case V16QImode: | |
5907 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
5908 | break; | |
5909 | default: | |
5910 | abort(); | |
5911 | } | |
5912 | } | |
5913 | else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode) | |
5914 | { | |
5915 | switch (mode0) | |
5916 | { | |
5917 | case V4SImode: | |
5918 | type = v4si_ftype_v4si_v4si_v16qi; | |
5919 | break; | |
5920 | case V4SFmode: | |
5921 | type = v4sf_ftype_v4sf_v4sf_v16qi; | |
5922 | break; | |
5923 | case V8HImode: | |
5924 | type = v8hi_ftype_v8hi_v8hi_v16qi; | |
5925 | break; | |
5926 | case V16QImode: | |
5927 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
5928 | break; | |
5929 | default: | |
5930 | abort(); | |
5931 | } | |
5932 | } | |
5933 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode | |
5934 | && mode3 == V4SImode) | |
24408032 | 5935 | type = v4si_ftype_v16qi_v16qi_v4si; |
2212663f DB |
5936 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode |
5937 | && mode3 == V4SImode) | |
24408032 | 5938 | type = v4si_ftype_v8hi_v8hi_v4si; |
617e0e1d DB |
5939 | else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode |
5940 | && mode3 == V4SImode) | |
24408032 AH |
5941 | type = v4sf_ftype_v4sf_v4sf_v4si; |
5942 | ||
5943 | /* vchar, vchar, vchar, 4 bit literal. */ | |
5944 | else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0 | |
5945 | && mode3 == QImode) | |
5946 | type = v16qi_ftype_v16qi_v16qi_char; | |
5947 | ||
5948 | /* vshort, vshort, vshort, 4 bit literal. */ | |
5949 | else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0 | |
5950 | && mode3 == QImode) | |
5951 | type = v8hi_ftype_v8hi_v8hi_char; | |
5952 | ||
5953 | /* vint, vint, vint, 4 bit literal. */ | |
5954 | else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0 | |
5955 | && mode3 == QImode) | |
5956 | type = v4si_ftype_v4si_v4si_char; | |
5957 | ||
5958 | /* vfloat, vfloat, vfloat, 4 bit literal. */ | |
5959 | else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0 | |
5960 | && mode3 == QImode) | |
5961 | type = v4sf_ftype_v4sf_v4sf_char; | |
5962 | ||
2212663f DB |
5963 | else |
5964 | abort (); | |
5965 | ||
5966 | def_builtin (d->mask, d->name, type, d->code); | |
5967 | } | |
5968 | ||
0ac081f6 | 5969 | /* Add the simple binary operators. */ |
00b960c7 | 5970 | d = (struct builtin_description *) bdesc_2arg; |
ca7558fc | 5971 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
0ac081f6 AH |
5972 | { |
5973 | enum machine_mode mode0, mode1, mode2; | |
5974 | tree type; | |
5975 | ||
0559cc77 | 5976 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
0ac081f6 AH |
5977 | continue; |
5978 | ||
5979 | mode0 = insn_data[d->icode].operand[0].mode; | |
5980 | mode1 = insn_data[d->icode].operand[1].mode; | |
5981 | mode2 = insn_data[d->icode].operand[2].mode; | |
5982 | ||
5983 | /* When all three operands are of the same mode. */ | |
5984 | if (mode0 == mode1 && mode1 == mode2) | |
5985 | { | |
5986 | switch (mode0) | |
5987 | { | |
5988 | case V4SFmode: | |
5989 | type = v4sf_ftype_v4sf_v4sf; | |
5990 | break; | |
5991 | case V4SImode: | |
5992 | type = v4si_ftype_v4si_v4si; | |
5993 | break; | |
5994 | case V16QImode: | |
5995 | type = v16qi_ftype_v16qi_v16qi; | |
5996 | break; | |
5997 | case V8HImode: | |
5998 | type = v8hi_ftype_v8hi_v8hi; | |
5999 | break; | |
a3170dc6 AH |
6000 | case V2SImode: |
6001 | type = v2si_ftype_v2si_v2si; | |
6002 | break; | |
6003 | case V2SFmode: | |
6004 | type = v2sf_ftype_v2sf_v2sf; | |
6005 | break; | |
6006 | case SImode: | |
6007 | type = int_ftype_int_int; | |
6008 | break; | |
0ac081f6 AH |
6009 | default: |
6010 | abort (); | |
6011 | } | |
6012 | } | |
6013 | ||
6014 | /* A few other combos we really don't want to do manually. */ | |
6015 | ||
6016 | /* vint, vfloat, vfloat. */ | |
6017 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode) | |
6018 | type = v4si_ftype_v4sf_v4sf; | |
6019 | ||
6020 | /* vshort, vchar, vchar. */ | |
6021 | else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode) | |
6022 | type = v8hi_ftype_v16qi_v16qi; | |
6023 | ||
6024 | /* vint, vshort, vshort. */ | |
6025 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode) | |
6026 | type = v4si_ftype_v8hi_v8hi; | |
6027 | ||
6028 | /* vshort, vint, vint. */ | |
6029 | else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode) | |
6030 | type = v8hi_ftype_v4si_v4si; | |
6031 | ||
6032 | /* vchar, vshort, vshort. */ | |
6033 | else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode) | |
6034 | type = v16qi_ftype_v8hi_v8hi; | |
6035 | ||
6036 | /* vint, vchar, vint. */ | |
6037 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode) | |
6038 | type = v4si_ftype_v16qi_v4si; | |
6039 | ||
fa066a23 AH |
6040 | /* vint, vchar, vchar. */ |
6041 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode) | |
6042 | type = v4si_ftype_v16qi_v16qi; | |
6043 | ||
0ac081f6 AH |
6044 | /* vint, vshort, vint. */ |
6045 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode) | |
6046 | type = v4si_ftype_v8hi_v4si; | |
2212663f DB |
6047 | |
6048 | /* vint, vint, 5 bit literal. */ | |
6049 | else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode) | |
6050 | type = v4si_ftype_v4si_char; | |
6051 | ||
6052 | /* vshort, vshort, 5 bit literal. */ | |
6053 | else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode) | |
6054 | type = v8hi_ftype_v8hi_char; | |
6055 | ||
6056 | /* vchar, vchar, 5 bit literal. */ | |
6057 | else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode) | |
6058 | type = v16qi_ftype_v16qi_char; | |
0ac081f6 | 6059 | |
617e0e1d DB |
6060 | /* vfloat, vint, 5 bit literal. */ |
6061 | else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode) | |
6062 | type = v4sf_ftype_v4si_char; | |
6063 | ||
6064 | /* vint, vfloat, 5 bit literal. */ | |
6065 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode) | |
6066 | type = v4si_ftype_v4sf_char; | |
6067 | ||
a3170dc6 AH |
6068 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode) |
6069 | type = v2si_ftype_int_int; | |
6070 | ||
6071 | else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode) | |
6072 | type = v2si_ftype_v2si_char; | |
6073 | ||
6074 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode) | |
6075 | type = v2si_ftype_int_char; | |
6076 | ||
0ac081f6 AH |
6077 | /* int, x, x. */ |
6078 | else if (mode0 == SImode) | |
6079 | { | |
6080 | switch (mode1) | |
6081 | { | |
6082 | case V4SImode: | |
6083 | type = int_ftype_v4si_v4si; | |
6084 | break; | |
6085 | case V4SFmode: | |
6086 | type = int_ftype_v4sf_v4sf; | |
6087 | break; | |
6088 | case V16QImode: | |
6089 | type = int_ftype_v16qi_v16qi; | |
6090 | break; | |
6091 | case V8HImode: | |
6092 | type = int_ftype_v8hi_v8hi; | |
6093 | break; | |
6094 | default: | |
6095 | abort (); | |
6096 | } | |
6097 | } | |
6098 | ||
6099 | else | |
6100 | abort (); | |
6101 | ||
2212663f DB |
6102 | def_builtin (d->mask, d->name, type, d->code); |
6103 | } | |
24408032 | 6104 | |
2212663f DB |
6105 | /* Add the simple unary operators. */ |
6106 | d = (struct builtin_description *) bdesc_1arg; | |
ca7558fc | 6107 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
2212663f DB |
6108 | { |
6109 | enum machine_mode mode0, mode1; | |
6110 | tree type; | |
6111 | ||
0559cc77 | 6112 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
6113 | continue; |
6114 | ||
6115 | mode0 = insn_data[d->icode].operand[0].mode; | |
6116 | mode1 = insn_data[d->icode].operand[1].mode; | |
6117 | ||
6118 | if (mode0 == V4SImode && mode1 == QImode) | |
6119 | type = v4si_ftype_char; | |
6120 | else if (mode0 == V8HImode && mode1 == QImode) | |
6121 | type = v8hi_ftype_char; | |
6122 | else if (mode0 == V16QImode && mode1 == QImode) | |
6123 | type = v16qi_ftype_char; | |
617e0e1d DB |
6124 | else if (mode0 == V4SFmode && mode1 == V4SFmode) |
6125 | type = v4sf_ftype_v4sf; | |
20e26713 AH |
6126 | else if (mode0 == V8HImode && mode1 == V16QImode) |
6127 | type = v8hi_ftype_v16qi; | |
6128 | else if (mode0 == V4SImode && mode1 == V8HImode) | |
6129 | type = v4si_ftype_v8hi; | |
a3170dc6 AH |
6130 | else if (mode0 == V2SImode && mode1 == V2SImode) |
6131 | type = v2si_ftype_v2si; | |
6132 | else if (mode0 == V2SFmode && mode1 == V2SFmode) | |
6133 | type = v2sf_ftype_v2sf; | |
6134 | else if (mode0 == V2SFmode && mode1 == V2SImode) | |
6135 | type = v2sf_ftype_v2si; | |
6136 | else if (mode0 == V2SImode && mode1 == V2SFmode) | |
6137 | type = v2si_ftype_v2sf; | |
6138 | else if (mode0 == V2SImode && mode1 == QImode) | |
6139 | type = v2si_ftype_char; | |
2212663f DB |
6140 | else |
6141 | abort (); | |
6142 | ||
0ac081f6 AH |
6143 | def_builtin (d->mask, d->name, type, d->code); |
6144 | } | |
6145 | } | |
6146 | ||
35aff10b | 6147 | \f |
7e69e155 MM |
6148 | /* Expand a block move operation, and return 1 if successful. Return 0 |
6149 | if we should let the compiler generate normal code. | |
6150 | ||
6151 | operands[0] is the destination | |
6152 | operands[1] is the source | |
6153 | operands[2] is the length | |
6154 | operands[3] is the alignment */ | |
6155 | ||
3933e0e1 MM |
6156 | #define MAX_MOVE_REG 4 |
6157 | ||
7e69e155 MM |
6158 | int |
6159 | expand_block_move (operands) | |
6160 | rtx operands[]; | |
6161 | { | |
b6c9286a MM |
6162 | rtx orig_dest = operands[0]; |
6163 | rtx orig_src = operands[1]; | |
7e69e155 | 6164 | rtx bytes_rtx = operands[2]; |
7e69e155 | 6165 | rtx align_rtx = operands[3]; |
3933e0e1 | 6166 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 6167 | int align; |
3933e0e1 MM |
6168 | int bytes; |
6169 | int offset; | |
7e69e155 MM |
6170 | int move_bytes; |
6171 | ||
3933e0e1 | 6172 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 6173 | if (! constp) |
3933e0e1 MM |
6174 | return 0; |
6175 | ||
5ee95df6 FS |
6176 | /* If this is not a fixed size alignment, abort */ |
6177 | if (GET_CODE (align_rtx) != CONST_INT) | |
6178 | abort (); | |
6179 | align = INTVAL (align_rtx); | |
6180 | ||
7e69e155 | 6181 | /* Anything to move? */ |
3933e0e1 MM |
6182 | bytes = INTVAL (bytes_rtx); |
6183 | if (bytes <= 0) | |
7e69e155 MM |
6184 | return 1; |
6185 | ||
ea9982a8 | 6186 | /* store_one_arg depends on expand_block_move to handle at least the size of |
6f317ef3 | 6187 | reg_parm_stack_space. */ |
ea9982a8 | 6188 | if (bytes > (TARGET_POWERPC64 ? 64 : 32)) |
7e69e155 MM |
6189 | return 0; |
6190 | ||
3933e0e1 | 6191 | if (TARGET_STRING) /* string instructions are available */ |
7e69e155 | 6192 | { |
35aff10b | 6193 | for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes) |
7e69e155 | 6194 | { |
35aff10b AM |
6195 | union { |
6196 | rtx (*movstrsi) PARAMS ((rtx, rtx, rtx, rtx)); | |
6197 | rtx (*mov) PARAMS ((rtx, rtx)); | |
6198 | } gen_func; | |
6199 | enum machine_mode mode = BLKmode; | |
6200 | rtx src, dest; | |
6201 | ||
3933e0e1 | 6202 | if (bytes > 24 /* move up to 32 bytes at a time */ |
cc0d9ba8 DE |
6203 | && ! fixed_regs[5] |
6204 | && ! fixed_regs[6] | |
6205 | && ! fixed_regs[7] | |
6206 | && ! fixed_regs[8] | |
6207 | && ! fixed_regs[9] | |
6208 | && ! fixed_regs[10] | |
6209 | && ! fixed_regs[11] | |
6210 | && ! fixed_regs[12]) | |
3933e0e1 MM |
6211 | { |
6212 | move_bytes = (bytes > 32) ? 32 : bytes; | |
35aff10b | 6213 | gen_func.movstrsi = gen_movstrsi_8reg; |
3933e0e1 MM |
6214 | } |
6215 | else if (bytes > 16 /* move up to 24 bytes at a time */ | |
f9562f27 DE |
6216 | && ! fixed_regs[5] |
6217 | && ! fixed_regs[6] | |
cc0d9ba8 DE |
6218 | && ! fixed_regs[7] |
6219 | && ! fixed_regs[8] | |
6220 | && ! fixed_regs[9] | |
f9562f27 | 6221 | && ! fixed_regs[10]) |
3933e0e1 MM |
6222 | { |
6223 | move_bytes = (bytes > 24) ? 24 : bytes; | |
35aff10b | 6224 | gen_func.movstrsi = gen_movstrsi_6reg; |
3933e0e1 MM |
6225 | } |
6226 | else if (bytes > 8 /* move up to 16 bytes at a time */ | |
f9562f27 DE |
6227 | && ! fixed_regs[5] |
6228 | && ! fixed_regs[6] | |
6229 | && ! fixed_regs[7] | |
6230 | && ! fixed_regs[8]) | |
3933e0e1 MM |
6231 | { |
6232 | move_bytes = (bytes > 16) ? 16 : bytes; | |
35aff10b | 6233 | gen_func.movstrsi = gen_movstrsi_4reg; |
3933e0e1 | 6234 | } |
acad7ed3 | 6235 | else if (bytes >= 8 && TARGET_POWERPC64 |
a4f6c312 | 6236 | /* 64-bit loads and stores require word-aligned |
82e41834 | 6237 | displacements. */ |
a4f6c312 | 6238 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) |
acad7ed3 DE |
6239 | { |
6240 | move_bytes = 8; | |
35aff10b AM |
6241 | mode = DImode; |
6242 | gen_func.mov = gen_movdi; | |
acad7ed3 | 6243 | } |
09a625f7 | 6244 | else if (bytes > 4 && !TARGET_POWERPC64) |
3933e0e1 MM |
6245 | { /* move up to 8 bytes at a time */ |
6246 | move_bytes = (bytes > 8) ? 8 : bytes; | |
35aff10b | 6247 | gen_func.movstrsi = gen_movstrsi_2reg; |
3933e0e1 | 6248 | } |
cc0d9ba8 | 6249 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
6250 | { /* move 4 bytes */ |
6251 | move_bytes = 4; | |
35aff10b AM |
6252 | mode = SImode; |
6253 | gen_func.mov = gen_movsi; | |
3933e0e1 | 6254 | } |
cc0d9ba8 | 6255 | else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
6256 | { /* move 2 bytes */ |
6257 | move_bytes = 2; | |
35aff10b AM |
6258 | mode = HImode; |
6259 | gen_func.mov = gen_movhi; | |
3933e0e1 MM |
6260 | } |
6261 | else if (bytes == 1) /* move 1 byte */ | |
6262 | { | |
6263 | move_bytes = 1; | |
35aff10b AM |
6264 | mode = QImode; |
6265 | gen_func.mov = gen_movqi; | |
3933e0e1 MM |
6266 | } |
6267 | else | |
6268 | { /* move up to 4 bytes at a time */ | |
6269 | move_bytes = (bytes > 4) ? 4 : bytes; | |
35aff10b | 6270 | gen_func.movstrsi = gen_movstrsi_1reg; |
3933e0e1 | 6271 | } |
4c64a852 | 6272 | |
35aff10b AM |
6273 | src = adjust_address (orig_src, mode, offset); |
6274 | dest = adjust_address (orig_dest, mode, offset); | |
6275 | ||
6276 | if (mode == BLKmode) | |
015892ee | 6277 | { |
35aff10b AM |
6278 | /* Move the address into scratch registers. The movstrsi |
6279 | patterns require zero offset. */ | |
6280 | if (!REG_P (XEXP (src, 0))) | |
cc0d9ba8 | 6281 | { |
35aff10b AM |
6282 | rtx src_reg = copy_addr_to_reg (XEXP (src, 0)); |
6283 | src = replace_equiv_address (src, src_reg); | |
cc0d9ba8 | 6284 | } |
35aff10b AM |
6285 | set_mem_size (src, GEN_INT (move_bytes)); |
6286 | ||
6287 | if (!REG_P (XEXP (dest, 0))) | |
cc0d9ba8 | 6288 | { |
35aff10b AM |
6289 | rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0)); |
6290 | dest = replace_equiv_address (dest, dest_reg); | |
cc0d9ba8 | 6291 | } |
35aff10b AM |
6292 | set_mem_size (dest, GEN_INT (move_bytes)); |
6293 | ||
6294 | emit_insn ((*gen_func.movstrsi) (dest, src, | |
6295 | GEN_INT (move_bytes & 31), | |
6296 | align_rtx)); | |
6297 | } | |
6298 | else | |
6299 | { | |
6300 | rtx tmp_reg = gen_reg_rtx (mode); | |
6301 | ||
6302 | emit_insn ((*gen_func.mov) (tmp_reg, src)); | |
6303 | emit_insn ((*gen_func.mov) (dest, tmp_reg)); | |
015892ee | 6304 | } |
4c64a852 | 6305 | } |
3933e0e1 MM |
6306 | } |
6307 | ||
6308 | else /* string instructions not available */ | |
6309 | { | |
35aff10b AM |
6310 | rtx stores[MAX_MOVE_REG]; |
6311 | int num_reg = 0; | |
6312 | int i; | |
6313 | ||
6314 | for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes) | |
7e69e155 | 6315 | { |
35aff10b AM |
6316 | rtx (*gen_mov_func) PARAMS ((rtx, rtx)); |
6317 | enum machine_mode mode; | |
6318 | rtx src, dest, tmp_reg; | |
3933e0e1 | 6319 | |
cc0d9ba8 DE |
6320 | /* Generate the appropriate load and store, saving the stores |
6321 | for later. */ | |
6322 | if (bytes >= 8 && TARGET_POWERPC64 | |
a4f6c312 SS |
6323 | /* 64-bit loads and stores require word-aligned |
6324 | displacements. */ | |
cc0d9ba8 | 6325 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) |
b6c9286a MM |
6326 | { |
6327 | move_bytes = 8; | |
35aff10b AM |
6328 | mode = DImode; |
6329 | gen_mov_func = gen_movdi; | |
b6c9286a | 6330 | } |
cc0d9ba8 | 6331 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
6332 | { |
6333 | move_bytes = 4; | |
35aff10b AM |
6334 | mode = SImode; |
6335 | gen_mov_func = gen_movsi; | |
3933e0e1 | 6336 | } |
cc0d9ba8 | 6337 | else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT)) |
3933e0e1 MM |
6338 | { |
6339 | move_bytes = 2; | |
35aff10b AM |
6340 | mode = HImode; |
6341 | gen_mov_func = gen_movhi; | |
3933e0e1 MM |
6342 | } |
6343 | else | |
6344 | { | |
6345 | move_bytes = 1; | |
35aff10b AM |
6346 | mode = QImode; |
6347 | gen_mov_func = gen_movqi; | |
3933e0e1 MM |
6348 | } |
6349 | ||
35aff10b AM |
6350 | src = adjust_address (orig_src, mode, offset); |
6351 | dest = adjust_address (orig_dest, mode, offset); | |
6352 | tmp_reg = gen_reg_rtx (mode); | |
6353 | ||
6354 | emit_insn ((*gen_mov_func) (tmp_reg, src)); | |
6355 | stores[num_reg++] = (*gen_mov_func) (dest, tmp_reg); | |
6356 | ||
3933e0e1 MM |
6357 | if (num_reg >= MAX_MOVE_REG) |
6358 | { | |
6359 | for (i = 0; i < num_reg; i++) | |
6360 | emit_insn (stores[i]); | |
6361 | num_reg = 0; | |
7e69e155 MM |
6362 | } |
6363 | } | |
3933e0e1 | 6364 | |
b6c9286a MM |
6365 | for (i = 0; i < num_reg; i++) |
6366 | emit_insn (stores[i]); | |
7e69e155 MM |
6367 | } |
6368 | ||
6369 | return 1; | |
6370 | } | |
6371 | ||
9878760c RK |
6372 | \f |
6373 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
6374 | PARALLEL and the first section will be tested. */ | |
6375 | ||
6376 | int | |
6377 | load_multiple_operation (op, mode) | |
6378 | rtx op; | |
296b8152 | 6379 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
6380 | { |
6381 | int count = XVECLEN (op, 0); | |
e2c953b6 | 6382 | unsigned int dest_regno; |
9878760c RK |
6383 | rtx src_addr; |
6384 | int i; | |
6385 | ||
6386 | /* Perform a quick check so we don't blow up below. */ | |
6387 | if (count <= 1 | |
6388 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
6389 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
6390 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
6391 | return 0; | |
6392 | ||
6393 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
6394 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
6395 | ||
6396 | for (i = 1; i < count; i++) | |
6397 | { | |
6398 | rtx elt = XVECEXP (op, 0, i); | |
6399 | ||
6400 | if (GET_CODE (elt) != SET | |
6401 | || GET_CODE (SET_DEST (elt)) != REG | |
6402 | || GET_MODE (SET_DEST (elt)) != SImode | |
6403 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
6404 | || GET_CODE (SET_SRC (elt)) != MEM | |
6405 | || GET_MODE (SET_SRC (elt)) != SImode | |
6406 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
6407 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
6408 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
6409 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
6410 | return 0; | |
6411 | } | |
6412 | ||
6413 | return 1; | |
6414 | } | |
6415 | ||
6416 | /* Similar, but tests for store multiple. Here, the second vector element | |
6417 | is a CLOBBER. It will be tested later. */ | |
6418 | ||
6419 | int | |
6420 | store_multiple_operation (op, mode) | |
6421 | rtx op; | |
296b8152 | 6422 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
6423 | { |
6424 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 6425 | unsigned int src_regno; |
9878760c RK |
6426 | rtx dest_addr; |
6427 | int i; | |
6428 | ||
6429 | /* Perform a quick check so we don't blow up below. */ | |
6430 | if (count <= 1 | |
6431 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
6432 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
6433 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
6434 | return 0; | |
6435 | ||
6436 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
6437 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
6438 | ||
6439 | for (i = 1; i < count; i++) | |
6440 | { | |
6441 | rtx elt = XVECEXP (op, 0, i + 1); | |
6442 | ||
6443 | if (GET_CODE (elt) != SET | |
6444 | || GET_CODE (SET_SRC (elt)) != REG | |
6445 | || GET_MODE (SET_SRC (elt)) != SImode | |
6446 | || REGNO (SET_SRC (elt)) != src_regno + i | |
6447 | || GET_CODE (SET_DEST (elt)) != MEM | |
6448 | || GET_MODE (SET_DEST (elt)) != SImode | |
6449 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
6450 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
6451 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
6452 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
6453 | return 0; | |
6454 | } | |
6455 | ||
6456 | return 1; | |
6457 | } | |
9ebbca7d | 6458 | |
9caa3eb2 DE |
6459 | /* Return a string to perform a load_multiple operation. |
6460 | operands[0] is the vector. | |
6461 | operands[1] is the source address. | |
6462 | operands[2] is the first destination register. */ | |
6463 | ||
6464 | const char * | |
6465 | rs6000_output_load_multiple (operands) | |
ebe637e3 | 6466 | rtx operands[3]; |
9caa3eb2 DE |
6467 | { |
6468 | /* We have to handle the case where the pseudo used to contain the address | |
6469 | is assigned to one of the output registers. */ | |
6470 | int i, j; | |
6471 | int words = XVECLEN (operands[0], 0); | |
6472 | rtx xop[10]; | |
6473 | ||
6474 | if (XVECLEN (operands[0], 0) == 1) | |
6475 | return "{l|lwz} %2,0(%1)"; | |
6476 | ||
6477 | for (i = 0; i < words; i++) | |
6478 | if (refers_to_regno_p (REGNO (operands[2]) + i, | |
6479 | REGNO (operands[2]) + i + 1, operands[1], 0)) | |
6480 | { | |
6481 | if (i == words-1) | |
6482 | { | |
6483 | xop[0] = GEN_INT (4 * (words-1)); | |
6484 | xop[1] = operands[1]; | |
6485 | xop[2] = operands[2]; | |
6486 | output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop); | |
6487 | return ""; | |
6488 | } | |
6489 | else if (i == 0) | |
6490 | { | |
6491 | xop[0] = GEN_INT (4 * (words-1)); | |
6492 | xop[1] = operands[1]; | |
6493 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
6494 | output_asm_insn ("{cal %1,4(%1)|addi %1,%1,4}\n\t{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,-4(%1)", xop); | |
6495 | return ""; | |
6496 | } | |
6497 | else | |
6498 | { | |
6499 | for (j = 0; j < words; j++) | |
6500 | if (j != i) | |
6501 | { | |
6502 | xop[0] = GEN_INT (j * 4); | |
6503 | xop[1] = operands[1]; | |
6504 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j); | |
6505 | output_asm_insn ("{l|lwz} %2,%0(%1)", xop); | |
6506 | } | |
6507 | xop[0] = GEN_INT (i * 4); | |
6508 | xop[1] = operands[1]; | |
6509 | output_asm_insn ("{l|lwz} %1,%0(%1)", xop); | |
6510 | return ""; | |
6511 | } | |
6512 | } | |
6513 | ||
6514 | return "{lsi|lswi} %2,%1,%N0"; | |
6515 | } | |
6516 | ||
00b960c7 AH |
6517 | /* Return 1 for a parallel vrsave operation. */ |
6518 | ||
6519 | int | |
6520 | vrsave_operation (op, mode) | |
6521 | rtx op; | |
6522 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6523 | { | |
6524 | int count = XVECLEN (op, 0); | |
6525 | unsigned int dest_regno, src_regno; | |
6526 | int i; | |
6527 | ||
6528 | if (count <= 1 | |
6529 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
6530 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
a004eb82 | 6531 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE) |
00b960c7 AH |
6532 | return 0; |
6533 | ||
6534 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
6535 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
6536 | ||
6537 | if (dest_regno != VRSAVE_REGNO | |
6538 | && src_regno != VRSAVE_REGNO) | |
6539 | return 0; | |
6540 | ||
6541 | for (i = 1; i < count; i++) | |
6542 | { | |
6543 | rtx elt = XVECEXP (op, 0, i); | |
6544 | ||
9aa86737 AH |
6545 | if (GET_CODE (elt) != CLOBBER |
6546 | && GET_CODE (elt) != SET) | |
00b960c7 AH |
6547 | return 0; |
6548 | } | |
6549 | ||
6550 | return 1; | |
6551 | } | |
6552 | ||
a4f6c312 | 6553 | /* Return 1 for an PARALLEL suitable for mtcrf. */ |
9ebbca7d GK |
6554 | |
6555 | int | |
6556 | mtcrf_operation (op, mode) | |
6557 | rtx op; | |
6558 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6559 | { | |
6560 | int count = XVECLEN (op, 0); | |
6561 | int i; | |
9ebbca7d GK |
6562 | rtx src_reg; |
6563 | ||
6564 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
6565 | if (count < 1 |
6566 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
6567 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
6568 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 6569 | return 0; |
e35b9579 | 6570 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
9ebbca7d GK |
6571 | |
6572 | if (GET_CODE (src_reg) != REG | |
6573 | || GET_MODE (src_reg) != SImode | |
6574 | || ! INT_REGNO_P (REGNO (src_reg))) | |
6575 | return 0; | |
6576 | ||
e35b9579 | 6577 | for (i = 0; i < count; i++) |
9ebbca7d GK |
6578 | { |
6579 | rtx exp = XVECEXP (op, 0, i); | |
6580 | rtx unspec; | |
6581 | int maskval; | |
6582 | ||
6583 | if (GET_CODE (exp) != SET | |
6584 | || GET_CODE (SET_DEST (exp)) != REG | |
6585 | || GET_MODE (SET_DEST (exp)) != CCmode | |
6586 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
6587 | return 0; | |
6588 | unspec = SET_SRC (exp); | |
6589 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
9ebbca7d GK |
6590 | |
6591 | if (GET_CODE (unspec) != UNSPEC | |
6592 | || XINT (unspec, 1) != 20 | |
6593 | || XVECLEN (unspec, 0) != 2 | |
6594 | || XVECEXP (unspec, 0, 0) != src_reg | |
6595 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
6596 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
6597 | return 0; | |
6598 | } | |
e35b9579 | 6599 | return 1; |
9ebbca7d GK |
6600 | } |
6601 | ||
a4f6c312 | 6602 | /* Return 1 for an PARALLEL suitable for lmw. */ |
9ebbca7d GK |
6603 | |
6604 | int | |
6605 | lmw_operation (op, mode) | |
6606 | rtx op; | |
6607 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6608 | { | |
6609 | int count = XVECLEN (op, 0); | |
e2c953b6 | 6610 | unsigned int dest_regno; |
9ebbca7d | 6611 | rtx src_addr; |
e2c953b6 | 6612 | unsigned int base_regno; |
9ebbca7d GK |
6613 | HOST_WIDE_INT offset; |
6614 | int i; | |
6615 | ||
6616 | /* Perform a quick check so we don't blow up below. */ | |
6617 | if (count <= 1 | |
6618 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
6619 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
6620 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
6621 | return 0; | |
6622 | ||
6623 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
6624 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
6625 | ||
6626 | if (dest_regno > 31 | |
e2c953b6 | 6627 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
6628 | return 0; |
6629 | ||
258bfae2 | 6630 | if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0)) |
9ebbca7d GK |
6631 | { |
6632 | offset = 0; | |
6633 | base_regno = REGNO (src_addr); | |
6634 | if (base_regno == 0) | |
6635 | return 0; | |
6636 | } | |
258bfae2 | 6637 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0)) |
9ebbca7d GK |
6638 | { |
6639 | offset = INTVAL (XEXP (src_addr, 1)); | |
6640 | base_regno = REGNO (XEXP (src_addr, 0)); | |
6641 | } | |
6642 | else | |
6643 | return 0; | |
6644 | ||
6645 | for (i = 0; i < count; i++) | |
6646 | { | |
6647 | rtx elt = XVECEXP (op, 0, i); | |
6648 | rtx newaddr; | |
6649 | rtx addr_reg; | |
6650 | HOST_WIDE_INT newoffset; | |
6651 | ||
6652 | if (GET_CODE (elt) != SET | |
6653 | || GET_CODE (SET_DEST (elt)) != REG | |
6654 | || GET_MODE (SET_DEST (elt)) != SImode | |
6655 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
6656 | || GET_CODE (SET_SRC (elt)) != MEM | |
6657 | || GET_MODE (SET_SRC (elt)) != SImode) | |
6658 | return 0; | |
6659 | newaddr = XEXP (SET_SRC (elt), 0); | |
258bfae2 | 6660 | if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0)) |
9ebbca7d GK |
6661 | { |
6662 | newoffset = 0; | |
6663 | addr_reg = newaddr; | |
6664 | } | |
258bfae2 | 6665 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0)) |
9ebbca7d GK |
6666 | { |
6667 | addr_reg = XEXP (newaddr, 0); | |
6668 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
6669 | } | |
6670 | else | |
6671 | return 0; | |
6672 | if (REGNO (addr_reg) != base_regno | |
6673 | || newoffset != offset + 4 * i) | |
6674 | return 0; | |
6675 | } | |
6676 | ||
6677 | return 1; | |
6678 | } | |
6679 | ||
a4f6c312 | 6680 | /* Return 1 for an PARALLEL suitable for stmw. */ |
9ebbca7d GK |
6681 | |
6682 | int | |
6683 | stmw_operation (op, mode) | |
6684 | rtx op; | |
6685 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6686 | { | |
6687 | int count = XVECLEN (op, 0); | |
e2c953b6 | 6688 | unsigned int src_regno; |
9ebbca7d | 6689 | rtx dest_addr; |
e2c953b6 | 6690 | unsigned int base_regno; |
9ebbca7d GK |
6691 | HOST_WIDE_INT offset; |
6692 | int i; | |
6693 | ||
6694 | /* Perform a quick check so we don't blow up below. */ | |
6695 | if (count <= 1 | |
6696 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
6697 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
6698 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
6699 | return 0; | |
6700 | ||
6701 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
6702 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
6703 | ||
6704 | if (src_regno > 31 | |
e2c953b6 | 6705 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
6706 | return 0; |
6707 | ||
258bfae2 | 6708 | if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0)) |
9ebbca7d GK |
6709 | { |
6710 | offset = 0; | |
6711 | base_regno = REGNO (dest_addr); | |
6712 | if (base_regno == 0) | |
6713 | return 0; | |
6714 | } | |
258bfae2 | 6715 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0)) |
9ebbca7d GK |
6716 | { |
6717 | offset = INTVAL (XEXP (dest_addr, 1)); | |
6718 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
6719 | } | |
6720 | else | |
6721 | return 0; | |
6722 | ||
6723 | for (i = 0; i < count; i++) | |
6724 | { | |
6725 | rtx elt = XVECEXP (op, 0, i); | |
6726 | rtx newaddr; | |
6727 | rtx addr_reg; | |
6728 | HOST_WIDE_INT newoffset; | |
6729 | ||
6730 | if (GET_CODE (elt) != SET | |
6731 | || GET_CODE (SET_SRC (elt)) != REG | |
6732 | || GET_MODE (SET_SRC (elt)) != SImode | |
6733 | || REGNO (SET_SRC (elt)) != src_regno + i | |
6734 | || GET_CODE (SET_DEST (elt)) != MEM | |
6735 | || GET_MODE (SET_DEST (elt)) != SImode) | |
6736 | return 0; | |
6737 | newaddr = XEXP (SET_DEST (elt), 0); | |
258bfae2 | 6738 | if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0)) |
9ebbca7d GK |
6739 | { |
6740 | newoffset = 0; | |
6741 | addr_reg = newaddr; | |
6742 | } | |
258bfae2 | 6743 | else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0)) |
9ebbca7d GK |
6744 | { |
6745 | addr_reg = XEXP (newaddr, 0); | |
6746 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
6747 | } | |
6748 | else | |
6749 | return 0; | |
6750 | if (REGNO (addr_reg) != base_regno | |
6751 | || newoffset != offset + 4 * i) | |
6752 | return 0; | |
6753 | } | |
6754 | ||
6755 | return 1; | |
6756 | } | |
9878760c | 6757 | \f |
a4f6c312 SS |
6758 | /* A validation routine: say whether CODE, a condition code, and MODE |
6759 | match. The other alternatives either don't make sense or should | |
6760 | never be generated. */ | |
39a10a29 | 6761 | |
39a10a29 GK |
6762 | static void |
6763 | validate_condition_mode (code, mode) | |
6764 | enum rtx_code code; | |
6765 | enum machine_mode mode; | |
6766 | { | |
6767 | if (GET_RTX_CLASS (code) != '<' | |
6768 | || GET_MODE_CLASS (mode) != MODE_CC) | |
6769 | abort (); | |
6770 | ||
6771 | /* These don't make sense. */ | |
6772 | if ((code == GT || code == LT || code == GE || code == LE) | |
6773 | && mode == CCUNSmode) | |
6774 | abort (); | |
6775 | ||
6776 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
6777 | && mode != CCUNSmode) | |
6778 | abort (); | |
6779 | ||
6780 | if (mode != CCFPmode | |
6781 | && (code == ORDERED || code == UNORDERED | |
6782 | || code == UNEQ || code == LTGT | |
6783 | || code == UNGT || code == UNLT | |
6784 | || code == UNGE || code == UNLE)) | |
a4f6c312 | 6785 | abort (); |
39a10a29 | 6786 | |
de6c5979 | 6787 | /* These should never be generated except for |
ad72b533 | 6788 | flag_unsafe_math_optimizations and flag_finite_math_only. */ |
39a10a29 | 6789 | if (mode == CCFPmode |
de6c5979 | 6790 | && ! flag_unsafe_math_optimizations |
ad72b533 | 6791 | && ! flag_finite_math_only |
39a10a29 GK |
6792 | && (code == LE || code == GE |
6793 | || code == UNEQ || code == LTGT | |
6794 | || code == UNGT || code == UNLT)) | |
6795 | abort (); | |
6796 | ||
6797 | /* These are invalid; the information is not there. */ | |
6798 | if (mode == CCEQmode | |
6799 | && code != EQ && code != NE) | |
6800 | abort (); | |
6801 | } | |
6802 | ||
9878760c RK |
6803 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
6804 | We only check the opcode against the mode of the CC value here. */ | |
6805 | ||
6806 | int | |
6807 | branch_comparison_operator (op, mode) | |
592696dd | 6808 | rtx op; |
296b8152 | 6809 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
6810 | { |
6811 | enum rtx_code code = GET_CODE (op); | |
6812 | enum machine_mode cc_mode; | |
6813 | ||
6814 | if (GET_RTX_CLASS (code) != '<') | |
6815 | return 0; | |
6816 | ||
6817 | cc_mode = GET_MODE (XEXP (op, 0)); | |
6818 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
6819 | return 0; | |
6820 | ||
39a10a29 | 6821 | validate_condition_mode (code, cc_mode); |
9878760c | 6822 | |
39a10a29 GK |
6823 | return 1; |
6824 | } | |
6825 | ||
6826 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
6827 | insn and which is true if the corresponding bit in the CC register | |
6828 | is set. */ | |
6829 | ||
6830 | int | |
6831 | branch_positive_comparison_operator (op, mode) | |
592696dd | 6832 | rtx op; |
39a10a29 GK |
6833 | enum machine_mode mode; |
6834 | { | |
6835 | enum rtx_code code; | |
6836 | ||
6837 | if (! branch_comparison_operator (op, mode)) | |
9878760c RK |
6838 | return 0; |
6839 | ||
39a10a29 GK |
6840 | code = GET_CODE (op); |
6841 | return (code == EQ || code == LT || code == GT | |
a3170dc6 | 6842 | || (TARGET_SPE && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE) |
39a10a29 GK |
6843 | || code == LTU || code == GTU |
6844 | || code == UNORDERED); | |
9878760c RK |
6845 | } |
6846 | ||
6847 | /* Return 1 if OP is a comparison operation that is valid for an scc insn. | |
6848 | We check the opcode against the mode of the CC value and disallow EQ or | |
6849 | NE comparisons for integers. */ | |
6850 | ||
6851 | int | |
6852 | scc_comparison_operator (op, mode) | |
592696dd | 6853 | rtx op; |
9878760c RK |
6854 | enum machine_mode mode; |
6855 | { | |
6856 | enum rtx_code code = GET_CODE (op); | |
6857 | enum machine_mode cc_mode; | |
6858 | ||
6859 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
6860 | return 0; | |
6861 | ||
6862 | if (GET_RTX_CLASS (code) != '<') | |
6863 | return 0; | |
6864 | ||
6865 | cc_mode = GET_MODE (XEXP (op, 0)); | |
6866 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
6867 | return 0; | |
6868 | ||
39a10a29 | 6869 | validate_condition_mode (code, cc_mode); |
9878760c | 6870 | |
39a10a29 | 6871 | if (code == NE && cc_mode != CCFPmode) |
c5defebb RK |
6872 | return 0; |
6873 | ||
9878760c RK |
6874 | return 1; |
6875 | } | |
e0cd0770 JC |
6876 | |
6877 | int | |
6878 | trap_comparison_operator (op, mode) | |
6879 | rtx op; | |
6880 | enum machine_mode mode; | |
6881 | { | |
6882 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
6883 | return 0; | |
39a10a29 | 6884 | return GET_RTX_CLASS (GET_CODE (op)) == '<'; |
e0cd0770 | 6885 | } |
dfbdccdb GK |
6886 | |
6887 | int | |
6888 | boolean_operator (op, mode) | |
6889 | rtx op; | |
6890 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6891 | { | |
6892 | enum rtx_code code = GET_CODE (op); | |
6893 | return (code == AND || code == IOR || code == XOR); | |
6894 | } | |
1d328b19 GK |
6895 | |
6896 | int | |
6897 | boolean_or_operator (op, mode) | |
6898 | rtx op; | |
6899 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6900 | { | |
6901 | enum rtx_code code = GET_CODE (op); | |
6902 | return (code == IOR || code == XOR); | |
6903 | } | |
50a0b056 GK |
6904 | |
6905 | int | |
6906 | min_max_operator (op, mode) | |
6907 | rtx op; | |
6908 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
6909 | { | |
6910 | enum rtx_code code = GET_CODE (op); | |
6911 | return (code == SMIN || code == SMAX || code == UMIN || code == UMAX); | |
6912 | } | |
9878760c RK |
6913 | \f |
6914 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
6915 | mask required to convert the result of a rotate insn into a shift | |
b1765bde | 6916 | left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */ |
9878760c RK |
6917 | |
6918 | int | |
6919 | includes_lshift_p (shiftop, andop) | |
592696dd SS |
6920 | rtx shiftop; |
6921 | rtx andop; | |
9878760c | 6922 | { |
e2c953b6 DE |
6923 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
6924 | ||
6925 | shift_mask <<= INTVAL (shiftop); | |
9878760c | 6926 | |
b1765bde | 6927 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
9878760c RK |
6928 | } |
6929 | ||
6930 | /* Similar, but for right shift. */ | |
6931 | ||
6932 | int | |
6933 | includes_rshift_p (shiftop, andop) | |
592696dd SS |
6934 | rtx shiftop; |
6935 | rtx andop; | |
9878760c | 6936 | { |
a7653a2c | 6937 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
6938 | |
6939 | shift_mask >>= INTVAL (shiftop); | |
6940 | ||
b1765bde | 6941 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
e2c953b6 DE |
6942 | } |
6943 | ||
c5059423 AM |
6944 | /* Return 1 if ANDOP is a mask suitable for use with an rldic insn |
6945 | to perform a left shift. It must have exactly SHIFTOP least | |
b6d08ca1 | 6946 | significant 0's, then one or more 1's, then zero or more 0's. */ |
e2c953b6 DE |
6947 | |
6948 | int | |
c5059423 | 6949 | includes_rldic_lshift_p (shiftop, andop) |
592696dd SS |
6950 | rtx shiftop; |
6951 | rtx andop; | |
e2c953b6 | 6952 | { |
c5059423 AM |
6953 | if (GET_CODE (andop) == CONST_INT) |
6954 | { | |
02071907 | 6955 | HOST_WIDE_INT c, lsb, shift_mask; |
e2c953b6 | 6956 | |
c5059423 | 6957 | c = INTVAL (andop); |
02071907 | 6958 | if (c == 0 || c == ~0) |
c5059423 | 6959 | return 0; |
e2c953b6 | 6960 | |
02071907 | 6961 | shift_mask = ~0; |
c5059423 AM |
6962 | shift_mask <<= INTVAL (shiftop); |
6963 | ||
b6d08ca1 | 6964 | /* Find the least significant one bit. */ |
c5059423 AM |
6965 | lsb = c & -c; |
6966 | ||
6967 | /* It must coincide with the LSB of the shift mask. */ | |
6968 | if (-lsb != shift_mask) | |
6969 | return 0; | |
e2c953b6 | 6970 | |
c5059423 AM |
6971 | /* Invert to look for the next transition (if any). */ |
6972 | c = ~c; | |
6973 | ||
6974 | /* Remove the low group of ones (originally low group of zeros). */ | |
6975 | c &= -lsb; | |
6976 | ||
6977 | /* Again find the lsb, and check we have all 1's above. */ | |
6978 | lsb = c & -c; | |
6979 | return c == -lsb; | |
6980 | } | |
6981 | else if (GET_CODE (andop) == CONST_DOUBLE | |
6982 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
6983 | { | |
02071907 AM |
6984 | HOST_WIDE_INT low, high, lsb; |
6985 | HOST_WIDE_INT shift_mask_low, shift_mask_high; | |
c5059423 AM |
6986 | |
6987 | low = CONST_DOUBLE_LOW (andop); | |
6988 | if (HOST_BITS_PER_WIDE_INT < 64) | |
6989 | high = CONST_DOUBLE_HIGH (andop); | |
6990 | ||
6991 | if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)) | |
02071907 | 6992 | || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0))) |
c5059423 AM |
6993 | return 0; |
6994 | ||
6995 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
6996 | { | |
02071907 | 6997 | shift_mask_high = ~0; |
c5059423 AM |
6998 | if (INTVAL (shiftop) > 32) |
6999 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
7000 | ||
7001 | lsb = high & -high; | |
7002 | ||
7003 | if (-lsb != shift_mask_high || INTVAL (shiftop) < 32) | |
7004 | return 0; | |
7005 | ||
7006 | high = ~high; | |
7007 | high &= -lsb; | |
7008 | ||
7009 | lsb = high & -high; | |
7010 | return high == -lsb; | |
7011 | } | |
7012 | ||
02071907 | 7013 | shift_mask_low = ~0; |
c5059423 AM |
7014 | shift_mask_low <<= INTVAL (shiftop); |
7015 | ||
7016 | lsb = low & -low; | |
7017 | ||
7018 | if (-lsb != shift_mask_low) | |
7019 | return 0; | |
7020 | ||
7021 | if (HOST_BITS_PER_WIDE_INT < 64) | |
7022 | high = ~high; | |
7023 | low = ~low; | |
7024 | low &= -lsb; | |
7025 | ||
7026 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
7027 | { | |
7028 | lsb = high & -high; | |
7029 | return high == -lsb; | |
7030 | } | |
7031 | ||
7032 | lsb = low & -low; | |
7033 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
7034 | } | |
7035 | else | |
7036 | return 0; | |
7037 | } | |
e2c953b6 | 7038 | |
c5059423 AM |
7039 | /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn |
7040 | to perform a left shift. It must have SHIFTOP or more least | |
7041 | signifigant 0's, with the remainder of the word 1's. */ | |
e2c953b6 | 7042 | |
c5059423 AM |
7043 | int |
7044 | includes_rldicr_lshift_p (shiftop, andop) | |
592696dd SS |
7045 | rtx shiftop; |
7046 | rtx andop; | |
c5059423 | 7047 | { |
e2c953b6 | 7048 | if (GET_CODE (andop) == CONST_INT) |
c5059423 | 7049 | { |
02071907 | 7050 | HOST_WIDE_INT c, lsb, shift_mask; |
c5059423 | 7051 | |
02071907 | 7052 | shift_mask = ~0; |
c5059423 AM |
7053 | shift_mask <<= INTVAL (shiftop); |
7054 | c = INTVAL (andop); | |
7055 | ||
7056 | /* Find the least signifigant one bit. */ | |
7057 | lsb = c & -c; | |
7058 | ||
7059 | /* It must be covered by the shift mask. | |
a4f6c312 | 7060 | This test also rejects c == 0. */ |
c5059423 AM |
7061 | if ((lsb & shift_mask) == 0) |
7062 | return 0; | |
7063 | ||
7064 | /* Check we have all 1's above the transition, and reject all 1's. */ | |
7065 | return c == -lsb && lsb != 1; | |
7066 | } | |
7067 | else if (GET_CODE (andop) == CONST_DOUBLE | |
7068 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
7069 | { | |
02071907 | 7070 | HOST_WIDE_INT low, lsb, shift_mask_low; |
c5059423 AM |
7071 | |
7072 | low = CONST_DOUBLE_LOW (andop); | |
7073 | ||
7074 | if (HOST_BITS_PER_WIDE_INT < 64) | |
7075 | { | |
02071907 | 7076 | HOST_WIDE_INT high, shift_mask_high; |
c5059423 AM |
7077 | |
7078 | high = CONST_DOUBLE_HIGH (andop); | |
7079 | ||
7080 | if (low == 0) | |
7081 | { | |
02071907 | 7082 | shift_mask_high = ~0; |
c5059423 AM |
7083 | if (INTVAL (shiftop) > 32) |
7084 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
7085 | ||
7086 | lsb = high & -high; | |
7087 | ||
7088 | if ((lsb & shift_mask_high) == 0) | |
7089 | return 0; | |
7090 | ||
7091 | return high == -lsb; | |
7092 | } | |
7093 | if (high != ~0) | |
7094 | return 0; | |
7095 | } | |
7096 | ||
02071907 | 7097 | shift_mask_low = ~0; |
c5059423 AM |
7098 | shift_mask_low <<= INTVAL (shiftop); |
7099 | ||
7100 | lsb = low & -low; | |
7101 | ||
7102 | if ((lsb & shift_mask_low) == 0) | |
7103 | return 0; | |
7104 | ||
7105 | return low == -lsb && lsb != 1; | |
7106 | } | |
e2c953b6 | 7107 | else |
c5059423 | 7108 | return 0; |
9878760c | 7109 | } |
35068b43 RK |
7110 | |
7111 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates | |
7112 | for lfq and stfq insns. | |
7113 | ||
7114 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
7115 | abort if we are passed pseudo registers. */ | |
7116 | ||
7117 | int | |
7118 | registers_ok_for_quad_peep (reg1, reg2) | |
7119 | rtx reg1, reg2; | |
7120 | { | |
7121 | /* We might have been passed a SUBREG. */ | |
7122 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
7123 | return 0; | |
7124 | ||
7125 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
7126 | } | |
7127 | ||
a4f6c312 SS |
7128 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. |
7129 | addr1 and addr2 must be in consecutive memory locations | |
7130 | (addr2 == addr1 + 8). */ | |
35068b43 RK |
7131 | |
7132 | int | |
7133 | addrs_ok_for_quad_peep (addr1, addr2) | |
592696dd SS |
7134 | rtx addr1; |
7135 | rtx addr2; | |
35068b43 | 7136 | { |
e2c953b6 | 7137 | unsigned int reg1; |
35068b43 RK |
7138 | int offset1; |
7139 | ||
7140 | /* Extract an offset (if used) from the first addr. */ | |
7141 | if (GET_CODE (addr1) == PLUS) | |
7142 | { | |
7143 | /* If not a REG, return zero. */ | |
7144 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
7145 | return 0; | |
7146 | else | |
7147 | { | |
7148 | reg1 = REGNO (XEXP (addr1, 0)); | |
7149 | /* The offset must be constant! */ | |
7150 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
7151 | return 0; | |
7152 | offset1 = INTVAL (XEXP (addr1, 1)); | |
7153 | } | |
7154 | } | |
7155 | else if (GET_CODE (addr1) != REG) | |
7156 | return 0; | |
7157 | else | |
7158 | { | |
7159 | reg1 = REGNO (addr1); | |
7160 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
7161 | offset1 = 0; | |
7162 | } | |
7163 | ||
acad7ed3 | 7164 | /* Make sure the second address is a (mem (plus (reg) (const_int))). */ |
35068b43 RK |
7165 | if (GET_CODE (addr2) != PLUS) |
7166 | return 0; | |
7167 | ||
7168 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
7169 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
7170 | return 0; | |
7171 | ||
7172 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
7173 | return 0; | |
7174 | ||
7175 | /* The offset for the second addr must be 8 more than the first addr. */ | |
7176 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
7177 | return 0; | |
7178 | ||
7179 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
7180 | instructions. */ | |
7181 | return 1; | |
7182 | } | |
9878760c RK |
7183 | \f |
7184 | /* Return the register class of a scratch register needed to copy IN into | |
7185 | or out of a register in CLASS in MODE. If it can be done directly, | |
7186 | NO_REGS is returned. */ | |
7187 | ||
7188 | enum reg_class | |
7189 | secondary_reload_class (class, mode, in) | |
7190 | enum reg_class class; | |
296b8152 | 7191 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9878760c RK |
7192 | rtx in; |
7193 | { | |
5accd822 | 7194 | int regno; |
9878760c | 7195 | |
46fad5b7 DJ |
7196 | if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN && flag_pic)) |
7197 | { | |
7198 | /* We cannot copy a symbolic operand directly into anything | |
7199 | other than BASE_REGS for TARGET_ELF. So indicate that a | |
7200 | register from BASE_REGS is needed as an intermediate | |
7201 | register. | |
7202 | ||
7203 | On Darwin, pic addresses require a load from memory, which | |
7204 | needs a base register. */ | |
7205 | if (class != BASE_REGS | |
7206 | && (GET_CODE (in) == SYMBOL_REF | |
7207 | || GET_CODE (in) == HIGH | |
7208 | || GET_CODE (in) == LABEL_REF | |
7209 | || GET_CODE (in) == CONST)) | |
7210 | return BASE_REGS; | |
7211 | } | |
e7b7998a | 7212 | |
5accd822 DE |
7213 | if (GET_CODE (in) == REG) |
7214 | { | |
7215 | regno = REGNO (in); | |
7216 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7217 | { | |
7218 | regno = true_regnum (in); | |
7219 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7220 | regno = -1; | |
7221 | } | |
7222 | } | |
7223 | else if (GET_CODE (in) == SUBREG) | |
7224 | { | |
7225 | regno = true_regnum (in); | |
7226 | if (regno >= FIRST_PSEUDO_REGISTER) | |
7227 | regno = -1; | |
7228 | } | |
7229 | else | |
7230 | regno = -1; | |
7231 | ||
9878760c RK |
7232 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
7233 | into anything. */ | |
7234 | if (class == GENERAL_REGS || class == BASE_REGS | |
7235 | || (regno >= 0 && INT_REGNO_P (regno))) | |
7236 | return NO_REGS; | |
7237 | ||
7238 | /* Constants, memory, and FP registers can go into FP registers. */ | |
7239 | if ((regno == -1 || FP_REGNO_P (regno)) | |
7240 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
7241 | return NO_REGS; | |
7242 | ||
0ac081f6 AH |
7243 | /* Memory, and AltiVec registers can go into AltiVec registers. */ |
7244 | if ((regno == -1 || ALTIVEC_REGNO_P (regno)) | |
7245 | && class == ALTIVEC_REGS) | |
7246 | return NO_REGS; | |
7247 | ||
9878760c RK |
7248 | /* We can copy among the CR registers. */ |
7249 | if ((class == CR_REGS || class == CR0_REGS) | |
7250 | && regno >= 0 && CR_REGNO_P (regno)) | |
7251 | return NO_REGS; | |
7252 | ||
7253 | /* Otherwise, we need GENERAL_REGS. */ | |
7254 | return GENERAL_REGS; | |
7255 | } | |
7256 | \f | |
7257 | /* Given a comparison operation, return the bit number in CCR to test. We | |
7258 | know this is a valid comparison. | |
7259 | ||
7260 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
7261 | used instead of %C, so the bits will be in different places. | |
7262 | ||
b4ac57ab | 7263 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
7264 | |
7265 | int | |
7266 | ccr_bit (op, scc_p) | |
592696dd | 7267 | rtx op; |
9878760c RK |
7268 | int scc_p; |
7269 | { | |
7270 | enum rtx_code code = GET_CODE (op); | |
7271 | enum machine_mode cc_mode; | |
7272 | int cc_regnum; | |
7273 | int base_bit; | |
9ebbca7d | 7274 | rtx reg; |
9878760c RK |
7275 | |
7276 | if (GET_RTX_CLASS (code) != '<') | |
7277 | return -1; | |
7278 | ||
9ebbca7d GK |
7279 | reg = XEXP (op, 0); |
7280 | ||
7281 | if (GET_CODE (reg) != REG | |
7282 | || ! CR_REGNO_P (REGNO (reg))) | |
7283 | abort (); | |
7284 | ||
7285 | cc_mode = GET_MODE (reg); | |
7286 | cc_regnum = REGNO (reg); | |
7287 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 7288 | |
39a10a29 | 7289 | validate_condition_mode (code, cc_mode); |
c5defebb | 7290 | |
9878760c RK |
7291 | switch (code) |
7292 | { | |
7293 | case NE: | |
a3170dc6 AH |
7294 | if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode) |
7295 | return base_bit + 1; | |
9878760c RK |
7296 | return scc_p ? base_bit + 3 : base_bit + 2; |
7297 | case EQ: | |
a3170dc6 AH |
7298 | if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode) |
7299 | return base_bit + 1; | |
9878760c | 7300 | return base_bit + 2; |
1c882ea4 | 7301 | case GT: case GTU: case UNLE: |
9878760c | 7302 | return base_bit + 1; |
1c882ea4 | 7303 | case LT: case LTU: case UNGE: |
9878760c | 7304 | return base_bit; |
1c882ea4 GK |
7305 | case ORDERED: case UNORDERED: |
7306 | return base_bit + 3; | |
9878760c RK |
7307 | |
7308 | case GE: case GEU: | |
39a10a29 | 7309 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
7310 | unordered position. So test that bit. For integer, this is ! LT |
7311 | unless this is an scc insn. */ | |
39a10a29 | 7312 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
7313 | |
7314 | case LE: case LEU: | |
39a10a29 | 7315 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 7316 | |
9878760c RK |
7317 | default: |
7318 | abort (); | |
7319 | } | |
7320 | } | |
1ff7789b | 7321 | \f |
8d30c4ee | 7322 | /* Return the GOT register. */ |
1ff7789b MM |
7323 | |
7324 | struct rtx_def * | |
7325 | rs6000_got_register (value) | |
5f59ecb7 | 7326 | rtx value ATTRIBUTE_UNUSED; |
1ff7789b | 7327 | { |
a4f6c312 SS |
7328 | /* The second flow pass currently (June 1999) can't update |
7329 | regs_ever_live without disturbing other parts of the compiler, so | |
7330 | update it here to make the prolog/epilogue code happy. */ | |
1db02437 FS |
7331 | if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]) |
7332 | regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
1ff7789b | 7333 | |
8d30c4ee | 7334 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 7335 | |
1ff7789b MM |
7336 | return pic_offset_table_rtx; |
7337 | } | |
a7df97e6 | 7338 | \f |
e2500fed GK |
7339 | /* Function to init struct machine_function. |
7340 | This will be called, via a pointer variable, | |
7341 | from push_function_context. */ | |
a7df97e6 | 7342 | |
e2500fed GK |
7343 | static struct machine_function * |
7344 | rs6000_init_machine_status () | |
a7df97e6 | 7345 | { |
e2500fed | 7346 | return ggc_alloc_cleared (sizeof (machine_function)); |
a7df97e6 | 7347 | } |
9878760c | 7348 | \f |
0ba1b2ff AM |
7349 | /* These macros test for integers and extract the low-order bits. */ |
7350 | #define INT_P(X) \ | |
7351 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
7352 | && GET_MODE (X) == VOIDmode) | |
7353 | ||
7354 | #define INT_LOWPART(X) \ | |
7355 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
7356 | ||
7357 | int | |
7358 | extract_MB (op) | |
7359 | rtx op; | |
7360 | { | |
7361 | int i; | |
7362 | unsigned long val = INT_LOWPART (op); | |
7363 | ||
7364 | /* If the high bit is zero, the value is the first 1 bit we find | |
7365 | from the left. */ | |
7366 | if ((val & 0x80000000) == 0) | |
7367 | { | |
7368 | if ((val & 0xffffffff) == 0) | |
7369 | abort (); | |
7370 | ||
7371 | i = 1; | |
7372 | while (((val <<= 1) & 0x80000000) == 0) | |
7373 | ++i; | |
7374 | return i; | |
7375 | } | |
7376 | ||
7377 | /* If the high bit is set and the low bit is not, or the mask is all | |
7378 | 1's, the value is zero. */ | |
7379 | if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff) | |
7380 | return 0; | |
7381 | ||
7382 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
7383 | from the right. */ | |
7384 | i = 31; | |
7385 | while (((val >>= 1) & 1) != 0) | |
7386 | --i; | |
7387 | ||
7388 | return i; | |
7389 | } | |
7390 | ||
7391 | int | |
7392 | extract_ME (op) | |
7393 | rtx op; | |
7394 | { | |
7395 | int i; | |
7396 | unsigned long val = INT_LOWPART (op); | |
7397 | ||
7398 | /* If the low bit is zero, the value is the first 1 bit we find from | |
7399 | the right. */ | |
7400 | if ((val & 1) == 0) | |
7401 | { | |
7402 | if ((val & 0xffffffff) == 0) | |
7403 | abort (); | |
7404 | ||
7405 | i = 30; | |
7406 | while (((val >>= 1) & 1) == 0) | |
7407 | --i; | |
7408 | ||
7409 | return i; | |
7410 | } | |
7411 | ||
7412 | /* If the low bit is set and the high bit is not, or the mask is all | |
7413 | 1's, the value is 31. */ | |
7414 | if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff) | |
7415 | return 31; | |
7416 | ||
7417 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
7418 | from the left. */ | |
7419 | i = 0; | |
7420 | while (((val <<= 1) & 0x80000000) != 0) | |
7421 | ++i; | |
7422 | ||
7423 | return i; | |
7424 | } | |
7425 | ||
9878760c RK |
7426 | /* Print an operand. Recognize special options, documented below. */ |
7427 | ||
38c1f2d7 | 7428 | #if TARGET_ELF |
d9407988 | 7429 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 7430 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
7431 | #else |
7432 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 7433 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
7434 | #endif |
7435 | ||
9878760c RK |
7436 | void |
7437 | print_operand (file, x, code) | |
7438 | FILE *file; | |
7439 | rtx x; | |
9ebbca7d | 7440 | int code; |
9878760c RK |
7441 | { |
7442 | int i; | |
a260abc9 | 7443 | HOST_WIDE_INT val; |
0ba1b2ff | 7444 | unsigned HOST_WIDE_INT uval; |
9878760c RK |
7445 | |
7446 | switch (code) | |
7447 | { | |
a8b3aeda | 7448 | case '.': |
a85d226b RK |
7449 | /* Write out an instruction after the call which may be replaced |
7450 | with glue code by the loader. This depends on the AIX version. */ | |
7451 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
7452 | return; |
7453 | ||
81eace42 GK |
7454 | /* %a is output_address. */ |
7455 | ||
9854d9ed RK |
7456 | case 'A': |
7457 | /* If X is a constant integer whose low-order 5 bits are zero, | |
7458 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 7459 | in the AIX assembler where "sri" with a zero shift count |
20e26713 | 7460 | writes a trash instruction. */ |
9854d9ed | 7461 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) |
76229ac8 | 7462 | putc ('l', file); |
9854d9ed | 7463 | else |
76229ac8 | 7464 | putc ('r', file); |
9854d9ed RK |
7465 | return; |
7466 | ||
7467 | case 'b': | |
e2c953b6 DE |
7468 | /* If constant, low-order 16 bits of constant, unsigned. |
7469 | Otherwise, write normally. */ | |
7470 | if (INT_P (x)) | |
7471 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
7472 | else | |
7473 | print_operand (file, x, 0); | |
cad12a8d RK |
7474 | return; |
7475 | ||
a260abc9 DE |
7476 | case 'B': |
7477 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
7478 | for 64-bit mask direction. */ | |
296b8152 | 7479 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 7480 | return; |
a260abc9 | 7481 | |
81eace42 GK |
7482 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
7483 | output_operand. */ | |
7484 | ||
9854d9ed | 7485 | case 'D': |
39a10a29 GK |
7486 | /* There used to be a comment for 'C' reading "This is an |
7487 | optional cror needed for certain floating-point | |
7488 | comparisons. Otherwise write nothing." */ | |
7489 | ||
9854d9ed RK |
7490 | /* Similar, except that this is for an scc, so we must be able to |
7491 | encode the test in a single bit that is one. We do the above | |
7492 | for any LE, GE, GEU, or LEU and invert the bit for NE. */ | |
7493 | if (GET_CODE (x) == LE || GET_CODE (x) == GE | |
7494 | || GET_CODE (x) == LEU || GET_CODE (x) == GEU) | |
7495 | { | |
9ebbca7d | 7496 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); |
9854d9ed RK |
7497 | |
7498 | fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3, | |
7499 | base_bit + 2, | |
7500 | base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU)); | |
7501 | } | |
7502 | ||
7503 | else if (GET_CODE (x) == NE) | |
7504 | { | |
9ebbca7d | 7505 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); |
9854d9ed RK |
7506 | |
7507 | fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3, | |
7508 | base_bit + 2, base_bit + 2); | |
7509 | } | |
a3170dc6 AH |
7510 | else if (TARGET_SPE && TARGET_HARD_FLOAT |
7511 | && GET_CODE (x) == EQ | |
7512 | && GET_MODE (XEXP (x, 0)) == CCFPmode) | |
7513 | { | |
7514 | int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO); | |
7515 | ||
7516 | fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 1, | |
7517 | base_bit + 1, base_bit + 1); | |
7518 | } | |
9854d9ed RK |
7519 | return; |
7520 | ||
7521 | case 'E': | |
39a10a29 | 7522 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
7523 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
7524 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 7525 | else |
39a10a29 | 7526 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 7527 | return; |
9854d9ed RK |
7528 | |
7529 | case 'f': | |
7530 | /* X is a CR register. Print the shift count needed to move it | |
7531 | to the high-order four bits. */ | |
7532 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
7533 | output_operand_lossage ("invalid %%f value"); | |
7534 | else | |
9ebbca7d | 7535 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
7536 | return; |
7537 | ||
7538 | case 'F': | |
7539 | /* Similar, but print the count for the rotate in the opposite | |
7540 | direction. */ | |
7541 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
7542 | output_operand_lossage ("invalid %%F value"); | |
7543 | else | |
9ebbca7d | 7544 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
7545 | return; |
7546 | ||
7547 | case 'G': | |
7548 | /* X is a constant integer. If it is negative, print "m", | |
43aa4e05 | 7549 | otherwise print "z". This is to make an aze or ame insn. */ |
9854d9ed RK |
7550 | if (GET_CODE (x) != CONST_INT) |
7551 | output_operand_lossage ("invalid %%G value"); | |
7552 | else if (INTVAL (x) >= 0) | |
76229ac8 | 7553 | putc ('z', file); |
9854d9ed | 7554 | else |
76229ac8 | 7555 | putc ('m', file); |
9854d9ed | 7556 | return; |
e2c953b6 | 7557 | |
9878760c | 7558 | case 'h': |
a4f6c312 SS |
7559 | /* If constant, output low-order five bits. Otherwise, write |
7560 | normally. */ | |
9878760c | 7561 | if (INT_P (x)) |
5f59ecb7 | 7562 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
7563 | else |
7564 | print_operand (file, x, 0); | |
7565 | return; | |
7566 | ||
64305719 | 7567 | case 'H': |
a4f6c312 SS |
7568 | /* If constant, output low-order six bits. Otherwise, write |
7569 | normally. */ | |
64305719 | 7570 | if (INT_P (x)) |
5f59ecb7 | 7571 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
7572 | else |
7573 | print_operand (file, x, 0); | |
7574 | return; | |
7575 | ||
9854d9ed RK |
7576 | case 'I': |
7577 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 7578 | if (INT_P (x)) |
76229ac8 | 7579 | putc ('i', file); |
9878760c RK |
7580 | return; |
7581 | ||
9854d9ed RK |
7582 | case 'j': |
7583 | /* Write the bit number in CCR for jump. */ | |
7584 | i = ccr_bit (x, 0); | |
7585 | if (i == -1) | |
7586 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 7587 | else |
9854d9ed | 7588 | fprintf (file, "%d", i); |
9878760c RK |
7589 | return; |
7590 | ||
9854d9ed RK |
7591 | case 'J': |
7592 | /* Similar, but add one for shift count in rlinm for scc and pass | |
7593 | scc flag to `ccr_bit'. */ | |
7594 | i = ccr_bit (x, 1); | |
7595 | if (i == -1) | |
7596 | output_operand_lossage ("invalid %%J code"); | |
7597 | else | |
a0466a68 RK |
7598 | /* If we want bit 31, write a shift count of zero, not 32. */ |
7599 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
7600 | return; |
7601 | ||
9854d9ed RK |
7602 | case 'k': |
7603 | /* X must be a constant. Write the 1's complement of the | |
7604 | constant. */ | |
9878760c | 7605 | if (! INT_P (x)) |
9854d9ed | 7606 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
7607 | else |
7608 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
7609 | return; |
7610 | ||
81eace42 | 7611 | case 'K': |
9ebbca7d GK |
7612 | /* X must be a symbolic constant on ELF. Write an |
7613 | expression suitable for an 'addi' that adds in the low 16 | |
7614 | bits of the MEM. */ | |
7615 | if (GET_CODE (x) != CONST) | |
7616 | { | |
7617 | print_operand_address (file, x); | |
7618 | fputs ("@l", file); | |
7619 | } | |
7620 | else | |
7621 | { | |
7622 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
7623 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
7624 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
7625 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 7626 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
7627 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
7628 | fputs ("@l", file); | |
ed8d2920 MM |
7629 | /* For GNU as, there must be a non-alphanumeric character |
7630 | between 'l' and the number. The '-' is added by | |
7631 | print_operand() already. */ | |
7632 | if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0) | |
7633 | fputs ("+", file); | |
9ebbca7d GK |
7634 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); |
7635 | } | |
81eace42 GK |
7636 | return; |
7637 | ||
7638 | /* %l is output_asm_label. */ | |
9ebbca7d | 7639 | |
9854d9ed RK |
7640 | case 'L': |
7641 | /* Write second word of DImode or DFmode reference. Works on register | |
7642 | or non-indexed memory only. */ | |
7643 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 7644 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
7645 | else if (GET_CODE (x) == MEM) |
7646 | { | |
7647 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 7648 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
7649 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
7650 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
ed8908e7 RK |
7651 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), |
7652 | UNITS_PER_WORD)); | |
9854d9ed | 7653 | else |
d7624dc0 RK |
7654 | output_address (XEXP (adjust_address_nv (x, SImode, |
7655 | UNITS_PER_WORD), | |
7656 | 0)); | |
ed8908e7 | 7657 | |
ba5e43aa | 7658 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
7659 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
7660 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 7661 | } |
9878760c | 7662 | return; |
9854d9ed | 7663 | |
9878760c RK |
7664 | case 'm': |
7665 | /* MB value for a mask operand. */ | |
b1765bde | 7666 | if (! mask_operand (x, SImode)) |
9878760c RK |
7667 | output_operand_lossage ("invalid %%m value"); |
7668 | ||
0ba1b2ff | 7669 | fprintf (file, "%d", extract_MB (x)); |
9878760c RK |
7670 | return; |
7671 | ||
7672 | case 'M': | |
7673 | /* ME value for a mask operand. */ | |
b1765bde | 7674 | if (! mask_operand (x, SImode)) |
a260abc9 | 7675 | output_operand_lossage ("invalid %%M value"); |
9878760c | 7676 | |
0ba1b2ff | 7677 | fprintf (file, "%d", extract_ME (x)); |
9878760c RK |
7678 | return; |
7679 | ||
81eace42 GK |
7680 | /* %n outputs the negative of its operand. */ |
7681 | ||
9878760c RK |
7682 | case 'N': |
7683 | /* Write the number of elements in the vector times 4. */ | |
7684 | if (GET_CODE (x) != PARALLEL) | |
7685 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
7686 | else |
7687 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
7688 | return; |
7689 | ||
7690 | case 'O': | |
7691 | /* Similar, but subtract 1 first. */ | |
7692 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 7693 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
7694 | else |
7695 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
7696 | return; |
7697 | ||
9854d9ed RK |
7698 | case 'p': |
7699 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
7700 | if (! INT_P (x) | |
2bfcf297 | 7701 | || INT_LOWPART (x) < 0 |
9854d9ed RK |
7702 | || (i = exact_log2 (INT_LOWPART (x))) < 0) |
7703 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
7704 | else |
7705 | fprintf (file, "%d", i); | |
9854d9ed RK |
7706 | return; |
7707 | ||
9878760c RK |
7708 | case 'P': |
7709 | /* The operand must be an indirect memory reference. The result | |
a4f6c312 | 7710 | is the register number. */ |
9878760c RK |
7711 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG |
7712 | || REGNO (XEXP (x, 0)) >= 32) | |
7713 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 DE |
7714 | else |
7715 | fprintf (file, "%d", REGNO (XEXP (x, 0))); | |
9878760c RK |
7716 | return; |
7717 | ||
dfbdccdb GK |
7718 | case 'q': |
7719 | /* This outputs the logical code corresponding to a boolean | |
7720 | expression. The expression may have one or both operands | |
39a10a29 GK |
7721 | negated (if one, only the first one). For condition register |
7722 | logical operations, it will also treat the negated | |
7723 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 7724 | { |
63bc1d05 | 7725 | const char *const *t = 0; |
dfbdccdb GK |
7726 | const char *s; |
7727 | enum rtx_code code = GET_CODE (x); | |
7728 | static const char * const tbl[3][3] = { | |
7729 | { "and", "andc", "nor" }, | |
7730 | { "or", "orc", "nand" }, | |
7731 | { "xor", "eqv", "xor" } }; | |
7732 | ||
7733 | if (code == AND) | |
7734 | t = tbl[0]; | |
7735 | else if (code == IOR) | |
7736 | t = tbl[1]; | |
7737 | else if (code == XOR) | |
7738 | t = tbl[2]; | |
7739 | else | |
7740 | output_operand_lossage ("invalid %%q value"); | |
7741 | ||
7742 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
7743 | s = t[0]; | |
7744 | else | |
7745 | { | |
7746 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
7747 | s = t[2]; | |
7748 | else | |
7749 | s = t[1]; | |
7750 | } | |
7751 | ||
7752 | fputs (s, file); | |
7753 | } | |
7754 | return; | |
7755 | ||
9854d9ed RK |
7756 | case 'R': |
7757 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
7758 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
7759 | output_operand_lossage ("invalid %%R value"); | |
7760 | else | |
9ebbca7d | 7761 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 7762 | return; |
9854d9ed RK |
7763 | |
7764 | case 's': | |
7765 | /* Low 5 bits of 32 - value */ | |
7766 | if (! INT_P (x)) | |
7767 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
7768 | else |
7769 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 7770 | return; |
9854d9ed | 7771 | |
a260abc9 | 7772 | case 'S': |
0ba1b2ff | 7773 | /* PowerPC64 mask position. All 0's is excluded. |
a260abc9 DE |
7774 | CONST_INT 32-bit mask is considered sign-extended so any |
7775 | transition must occur within the CONST_INT, not on the boundary. */ | |
b1765bde | 7776 | if (! mask64_operand (x, DImode)) |
a260abc9 DE |
7777 | output_operand_lossage ("invalid %%S value"); |
7778 | ||
0ba1b2ff | 7779 | uval = INT_LOWPART (x); |
a260abc9 | 7780 | |
0ba1b2ff | 7781 | if (uval & 1) /* Clear Left */ |
a260abc9 | 7782 | { |
0ba1b2ff AM |
7783 | uval &= ((unsigned HOST_WIDE_INT) 1 << 63 << 1) - 1; |
7784 | i = 64; | |
a260abc9 | 7785 | } |
0ba1b2ff | 7786 | else /* Clear Right */ |
a260abc9 | 7787 | { |
0ba1b2ff AM |
7788 | uval = ~uval; |
7789 | uval &= ((unsigned HOST_WIDE_INT) 1 << 63 << 1) - 1; | |
7790 | i = 63; | |
a260abc9 | 7791 | } |
0ba1b2ff AM |
7792 | while (uval != 0) |
7793 | --i, uval >>= 1; | |
7794 | if (i < 0) | |
7795 | abort (); | |
7796 | fprintf (file, "%d", i); | |
7797 | return; | |
a260abc9 | 7798 | |
a3170dc6 AH |
7799 | case 't': |
7800 | /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */ | |
7801 | if (GET_CODE (x) != REG || GET_MODE (x) != CCmode) | |
7802 | abort (); | |
7803 | ||
7804 | /* Bit 3 is OV bit. */ | |
7805 | i = 4 * (REGNO (x) - CR0_REGNO) + 3; | |
7806 | ||
7807 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
7808 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
7809 | return; | |
7810 | ||
cccf3bdc DE |
7811 | case 'T': |
7812 | /* Print the symbolic name of a branch target register. */ | |
7813 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
7814 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
7815 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 7816 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
7817 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
7818 | else | |
7819 | fputs ("ctr", file); | |
7820 | return; | |
7821 | ||
9854d9ed | 7822 | case 'u': |
802a0058 | 7823 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
7824 | if (! INT_P (x)) |
7825 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 DE |
7826 | else |
7827 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, | |
7828 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
7829 | return; |
7830 | ||
802a0058 MM |
7831 | case 'v': |
7832 | /* High-order 16 bits of constant for use in signed operand. */ | |
7833 | if (! INT_P (x)) | |
7834 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 | 7835 | else |
134c32f6 DE |
7836 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
7837 | (INT_LOWPART (x) >> 16) & 0xffff); | |
7838 | return; | |
802a0058 | 7839 | |
9854d9ed RK |
7840 | case 'U': |
7841 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
7842 | if (GET_CODE (x) == MEM | |
7843 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
7844 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 7845 | putc ('u', file); |
9854d9ed | 7846 | return; |
9878760c | 7847 | |
e0cd0770 JC |
7848 | case 'V': |
7849 | /* Print the trap code for this operand. */ | |
7850 | switch (GET_CODE (x)) | |
7851 | { | |
7852 | case EQ: | |
7853 | fputs ("eq", file); /* 4 */ | |
7854 | break; | |
7855 | case NE: | |
7856 | fputs ("ne", file); /* 24 */ | |
7857 | break; | |
7858 | case LT: | |
7859 | fputs ("lt", file); /* 16 */ | |
7860 | break; | |
7861 | case LE: | |
7862 | fputs ("le", file); /* 20 */ | |
7863 | break; | |
7864 | case GT: | |
7865 | fputs ("gt", file); /* 8 */ | |
7866 | break; | |
7867 | case GE: | |
7868 | fputs ("ge", file); /* 12 */ | |
7869 | break; | |
7870 | case LTU: | |
7871 | fputs ("llt", file); /* 2 */ | |
7872 | break; | |
7873 | case LEU: | |
7874 | fputs ("lle", file); /* 6 */ | |
7875 | break; | |
7876 | case GTU: | |
7877 | fputs ("lgt", file); /* 1 */ | |
7878 | break; | |
7879 | case GEU: | |
7880 | fputs ("lge", file); /* 5 */ | |
7881 | break; | |
7882 | default: | |
7883 | abort (); | |
7884 | } | |
7885 | break; | |
7886 | ||
9854d9ed RK |
7887 | case 'w': |
7888 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
7889 | normally. */ | |
7890 | if (INT_P (x)) | |
5f59ecb7 DE |
7891 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
7892 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
7893 | else |
7894 | print_operand (file, x, 0); | |
9878760c RK |
7895 | return; |
7896 | ||
9854d9ed | 7897 | case 'W': |
e2c953b6 | 7898 | /* MB value for a PowerPC64 rldic operand. */ |
e2c953b6 DE |
7899 | val = (GET_CODE (x) == CONST_INT |
7900 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
7901 | ||
7902 | if (val < 0) | |
7903 | i = -1; | |
9854d9ed | 7904 | else |
e2c953b6 DE |
7905 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
7906 | if ((val <<= 1) < 0) | |
7907 | break; | |
7908 | ||
7909 | #if HOST_BITS_PER_WIDE_INT == 32 | |
7910 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
7911 | i += 32; /* zero-extend high-part was all 0's */ | |
7912 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
7913 | { | |
7914 | val = CONST_DOUBLE_LOW (x); | |
7915 | ||
7916 | if (val == 0) | |
a4f6c312 | 7917 | abort (); |
e2c953b6 DE |
7918 | else if (val < 0) |
7919 | --i; | |
7920 | else | |
7921 | for ( ; i < 64; i++) | |
7922 | if ((val <<= 1) < 0) | |
7923 | break; | |
7924 | } | |
7925 | #endif | |
7926 | ||
7927 | fprintf (file, "%d", i + 1); | |
9854d9ed | 7928 | return; |
9878760c | 7929 | |
9854d9ed RK |
7930 | case 'X': |
7931 | if (GET_CODE (x) == MEM | |
258bfae2 | 7932 | && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0)) |
76229ac8 | 7933 | putc ('x', file); |
9854d9ed | 7934 | return; |
9878760c | 7935 | |
9854d9ed RK |
7936 | case 'Y': |
7937 | /* Like 'L', for third word of TImode */ | |
7938 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 7939 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 7940 | else if (GET_CODE (x) == MEM) |
9878760c | 7941 | { |
9854d9ed RK |
7942 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
7943 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 7944 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 7945 | else |
d7624dc0 | 7946 | output_address (XEXP (adjust_address_nv (x, SImode, 8), 0)); |
ba5e43aa | 7947 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
7948 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
7949 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
7950 | } |
7951 | return; | |
9854d9ed | 7952 | |
9878760c | 7953 | case 'z': |
b4ac57ab RS |
7954 | /* X is a SYMBOL_REF. Write out the name preceded by a |
7955 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
7956 | names. If we are configured for System V (or the embedded ABI) on |
7957 | the PowerPC, do not emit the period, since those systems do not use | |
7958 | TOCs and the like. */ | |
9878760c RK |
7959 | if (GET_CODE (x) != SYMBOL_REF) |
7960 | abort (); | |
7961 | ||
b6c9286a MM |
7962 | if (XSTR (x, 0)[0] != '.') |
7963 | { | |
7964 | switch (DEFAULT_ABI) | |
7965 | { | |
7966 | default: | |
7967 | abort (); | |
7968 | ||
7969 | case ABI_AIX: | |
7970 | putc ('.', file); | |
7971 | break; | |
7972 | ||
7973 | case ABI_V4: | |
7974 | case ABI_AIX_NODESC: | |
ee890fe2 | 7975 | case ABI_DARWIN: |
b6c9286a | 7976 | break; |
b6c9286a MM |
7977 | } |
7978 | } | |
54ee9799 DE |
7979 | #if TARGET_AIX |
7980 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); | |
7981 | #else | |
9ebbca7d | 7982 | assemble_name (file, XSTR (x, 0)); |
54ee9799 | 7983 | #endif |
9878760c RK |
7984 | return; |
7985 | ||
9854d9ed RK |
7986 | case 'Z': |
7987 | /* Like 'L', for last word of TImode. */ | |
7988 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 7989 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
7990 | else if (GET_CODE (x) == MEM) |
7991 | { | |
7992 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
7993 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 7994 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 7995 | else |
d7624dc0 | 7996 | output_address (XEXP (adjust_address_nv (x, SImode, 12), 0)); |
ba5e43aa | 7997 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
7998 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
7999 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 8000 | } |
5c23c401 | 8001 | return; |
0ac081f6 | 8002 | |
a3170dc6 | 8003 | /* Print AltiVec or SPE memory operand. */ |
0ac081f6 AH |
8004 | case 'y': |
8005 | { | |
8006 | rtx tmp; | |
8007 | ||
8008 | if (GET_CODE (x) != MEM) | |
8009 | abort (); | |
8010 | ||
8011 | tmp = XEXP (x, 0); | |
8012 | ||
a3170dc6 AH |
8013 | if (TARGET_SPE) |
8014 | { | |
8015 | /* Handle [reg]. */ | |
8016 | if (GET_CODE (tmp) == REG) | |
8017 | { | |
8018 | fprintf (file, "0(%s)", reg_names[REGNO (tmp)]); | |
8019 | break; | |
8020 | } | |
8021 | /* Handle [reg+UIMM]. */ | |
8022 | else if (GET_CODE (tmp) == PLUS && | |
8023 | GET_CODE (XEXP (tmp, 1)) == CONST_INT) | |
8024 | { | |
8025 | int x; | |
8026 | ||
8027 | if (GET_CODE (XEXP (tmp, 0)) != REG) | |
8028 | abort (); | |
8029 | ||
8030 | x = INTVAL (XEXP (tmp, 1)); | |
8031 | fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]); | |
8032 | break; | |
8033 | } | |
8034 | ||
8035 | /* Fall through. Must be [reg+reg]. */ | |
8036 | } | |
0ac081f6 | 8037 | if (GET_CODE (tmp) == REG) |
c62f2db5 | 8038 | fprintf (file, "0,%s", reg_names[REGNO (tmp)]); |
0ac081f6 AH |
8039 | else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG) |
8040 | { | |
8041 | if (REGNO (XEXP (tmp, 0)) == 0) | |
8042 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ], | |
8043 | reg_names[ REGNO (XEXP (tmp, 0)) ]); | |
8044 | else | |
8045 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ], | |
8046 | reg_names[ REGNO (XEXP (tmp, 1)) ]); | |
8047 | } | |
8048 | else | |
8049 | abort (); | |
8050 | break; | |
8051 | } | |
9854d9ed | 8052 | |
9878760c RK |
8053 | case 0: |
8054 | if (GET_CODE (x) == REG) | |
8055 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
8056 | else if (GET_CODE (x) == MEM) | |
8057 | { | |
8058 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
8059 | know the width from the mode. */ | |
8060 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
8061 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
8062 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 8063 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
8064 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
8065 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 8066 | else |
a54d04b7 | 8067 | output_address (XEXP (x, 0)); |
9878760c RK |
8068 | } |
8069 | else | |
a54d04b7 | 8070 | output_addr_const (file, x); |
a85d226b | 8071 | return; |
9878760c RK |
8072 | |
8073 | default: | |
8074 | output_operand_lossage ("invalid %%xn code"); | |
8075 | } | |
8076 | } | |
8077 | \f | |
8078 | /* Print the address of an operand. */ | |
8079 | ||
8080 | void | |
8081 | print_operand_address (file, x) | |
8082 | FILE *file; | |
592696dd | 8083 | rtx x; |
9878760c RK |
8084 | { |
8085 | if (GET_CODE (x) == REG) | |
4697a36c | 8086 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
8087 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
8088 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
8089 | { |
8090 | output_addr_const (file, x); | |
ba5e43aa | 8091 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
8092 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
8093 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d | 8094 | else if (TARGET_TOC) |
a4f6c312 | 8095 | abort (); |
9878760c RK |
8096 | } |
8097 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
8098 | { | |
8099 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
8100 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
8101 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 8102 | else |
4697a36c MM |
8103 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
8104 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
8105 | } |
8106 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
5f59ecb7 DE |
8107 | { |
8108 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1))); | |
8109 | fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
8110 | } | |
3cb999d8 DE |
8111 | #if TARGET_ELF |
8112 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
8113 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
8114 | { |
8115 | output_addr_const (file, XEXP (x, 1)); | |
8116 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
8117 | } | |
c859cda6 DJ |
8118 | #endif |
8119 | #if TARGET_MACHO | |
8120 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
8121 | && CONSTANT_P (XEXP (x, 1))) | |
8122 | { | |
8123 | fprintf (file, "lo16("); | |
8124 | output_addr_const (file, XEXP (x, 1)); | |
8125 | fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
8126 | } | |
3cb999d8 | 8127 | #endif |
9ebbca7d GK |
8128 | else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x)) |
8129 | { | |
2bfcf297 | 8130 | if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC)) |
9ebbca7d | 8131 | { |
2bfcf297 DB |
8132 | rtx contains_minus = XEXP (x, 1); |
8133 | rtx minus, symref; | |
8134 | const char *name; | |
9ebbca7d GK |
8135 | |
8136 | /* Find the (minus (sym) (toc)) buried in X, and temporarily | |
a4f6c312 | 8137 | turn it into (sym) for output_addr_const. */ |
9ebbca7d GK |
8138 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) |
8139 | contains_minus = XEXP (contains_minus, 0); | |
8140 | ||
2bfcf297 DB |
8141 | minus = XEXP (contains_minus, 0); |
8142 | symref = XEXP (minus, 0); | |
8143 | XEXP (contains_minus, 0) = symref; | |
8144 | if (TARGET_ELF) | |
8145 | { | |
8146 | char *newname; | |
8147 | ||
8148 | name = XSTR (symref, 0); | |
8149 | newname = alloca (strlen (name) + sizeof ("@toc")); | |
8150 | strcpy (newname, name); | |
8151 | strcat (newname, "@toc"); | |
8152 | XSTR (symref, 0) = newname; | |
8153 | } | |
8154 | output_addr_const (file, XEXP (x, 1)); | |
8155 | if (TARGET_ELF) | |
8156 | XSTR (symref, 0) = name; | |
9ebbca7d GK |
8157 | XEXP (contains_minus, 0) = minus; |
8158 | } | |
8159 | else | |
8160 | output_addr_const (file, XEXP (x, 1)); | |
8161 | ||
8162 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
8163 | } | |
9878760c RK |
8164 | else |
8165 | abort (); | |
8166 | } | |
8167 | \f | |
88cad84b | 8168 | /* Target hook for assembling integer objects. The PowerPC version has |
301d03af RS |
8169 | to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP |
8170 | is defined. It also needs to handle DI-mode objects on 64-bit | |
8171 | targets. */ | |
8172 | ||
8173 | static bool | |
8174 | rs6000_assemble_integer (x, size, aligned_p) | |
8175 | rtx x; | |
8176 | unsigned int size; | |
8177 | int aligned_p; | |
8178 | { | |
8179 | #ifdef RELOCATABLE_NEEDS_FIXUP | |
8180 | /* Special handling for SI values. */ | |
8181 | if (size == 4 && aligned_p) | |
8182 | { | |
8183 | extern int in_toc_section PARAMS ((void)); | |
8184 | static int recurse = 0; | |
8185 | ||
8186 | /* For -mrelocatable, we mark all addresses that need to be fixed up | |
8187 | in the .fixup section. */ | |
8188 | if (TARGET_RELOCATABLE | |
8189 | && !in_toc_section () | |
8190 | && !in_text_section () | |
8191 | && !recurse | |
8192 | && GET_CODE (x) != CONST_INT | |
8193 | && GET_CODE (x) != CONST_DOUBLE | |
8194 | && CONSTANT_P (x)) | |
8195 | { | |
8196 | char buf[256]; | |
8197 | ||
8198 | recurse = 1; | |
8199 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno); | |
8200 | fixuplabelno++; | |
8201 | ASM_OUTPUT_LABEL (asm_out_file, buf); | |
8202 | fprintf (asm_out_file, "\t.long\t("); | |
8203 | output_addr_const (asm_out_file, x); | |
8204 | fprintf (asm_out_file, ")@fixup\n"); | |
8205 | fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n"); | |
8206 | ASM_OUTPUT_ALIGN (asm_out_file, 2); | |
8207 | fprintf (asm_out_file, "\t.long\t"); | |
8208 | assemble_name (asm_out_file, buf); | |
8209 | fprintf (asm_out_file, "\n\t.previous\n"); | |
8210 | recurse = 0; | |
8211 | return true; | |
8212 | } | |
8213 | /* Remove initial .'s to turn a -mcall-aixdesc function | |
8214 | address into the address of the descriptor, not the function | |
8215 | itself. */ | |
8216 | else if (GET_CODE (x) == SYMBOL_REF | |
8217 | && XSTR (x, 0)[0] == '.' | |
8218 | && DEFAULT_ABI == ABI_AIX) | |
8219 | { | |
8220 | const char *name = XSTR (x, 0); | |
8221 | while (*name == '.') | |
8222 | name++; | |
8223 | ||
8224 | fprintf (asm_out_file, "\t.long\t%s\n", name); | |
8225 | return true; | |
8226 | } | |
8227 | } | |
8228 | #endif /* RELOCATABLE_NEEDS_FIXUP */ | |
8229 | return default_assemble_integer (x, size, aligned_p); | |
8230 | } | |
93638d7a AM |
8231 | |
8232 | #ifdef HAVE_GAS_HIDDEN | |
8233 | /* Emit an assembler directive to set symbol visibility for DECL to | |
8234 | VISIBILITY_TYPE. */ | |
8235 | ||
5add3202 | 8236 | static void |
25fdb4dc | 8237 | rs6000_assemble_visibility (decl, vis) |
93638d7a | 8238 | tree decl; |
25fdb4dc | 8239 | int vis; |
93638d7a | 8240 | { |
93638d7a AM |
8241 | /* Functions need to have their entry point symbol visibility set as |
8242 | well as their descriptor symbol visibility. */ | |
8243 | if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL) | |
8244 | { | |
25fdb4dc RH |
8245 | static const char * const visibility_types[] = { |
8246 | NULL, "internal", "hidden", "protected" | |
8247 | }; | |
8248 | ||
8249 | const char *name, *type; | |
93638d7a AM |
8250 | |
8251 | name = ((* targetm.strip_name_encoding) | |
8252 | (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)))); | |
25fdb4dc | 8253 | type = visibility_types[vis]; |
93638d7a | 8254 | |
25fdb4dc RH |
8255 | fprintf (asm_out_file, "\t.%s\t%s\n", type, name); |
8256 | fprintf (asm_out_file, "\t.%s\t.%s\n", type, name); | |
93638d7a | 8257 | } |
25fdb4dc RH |
8258 | else |
8259 | default_assemble_visibility (decl, vis); | |
93638d7a AM |
8260 | } |
8261 | #endif | |
301d03af | 8262 | \f |
39a10a29 GK |
8263 | enum rtx_code |
8264 | rs6000_reverse_condition (mode, code) | |
8265 | enum machine_mode mode; | |
8266 | enum rtx_code code; | |
8267 | { | |
8268 | /* Reversal of FP compares takes care -- an ordered compare | |
8269 | becomes an unordered compare and vice versa. */ | |
de40e1df | 8270 | if (mode == CCFPmode && !flag_unsafe_math_optimizations) |
bab6226b | 8271 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 8272 | else |
bab6226b | 8273 | return reverse_condition (code); |
39a10a29 GK |
8274 | } |
8275 | ||
39a10a29 GK |
8276 | /* Generate a compare for CODE. Return a brand-new rtx that |
8277 | represents the result of the compare. */ | |
a4f6c312 | 8278 | |
39a10a29 GK |
8279 | static rtx |
8280 | rs6000_generate_compare (code) | |
8281 | enum rtx_code code; | |
8282 | { | |
8283 | enum machine_mode comp_mode; | |
8284 | rtx compare_result; | |
8285 | ||
8286 | if (rs6000_compare_fp_p) | |
8287 | comp_mode = CCFPmode; | |
8288 | else if (code == GTU || code == LTU | |
8289 | || code == GEU || code == LEU) | |
8290 | comp_mode = CCUNSmode; | |
8291 | else | |
8292 | comp_mode = CCmode; | |
8293 | ||
8294 | /* First, the compare. */ | |
8295 | compare_result = gen_reg_rtx (comp_mode); | |
a3170dc6 AH |
8296 | |
8297 | /* SPE FP compare instructions on the GPRs. Yuck! */ | |
8298 | if ((TARGET_SPE && TARGET_HARD_FLOAT) && rs6000_compare_fp_p) | |
8299 | { | |
8300 | rtx cmp, or1, or2, or_result, compare_result2; | |
8301 | ||
8302 | switch (code) | |
8303 | { | |
8304 | case EQ: | |
8305 | case UNEQ: | |
8306 | case NE: | |
8307 | case LTGT: | |
8308 | cmp = flag_unsafe_math_optimizations | |
8309 | ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0, | |
8310 | rs6000_compare_op1) | |
8311 | : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0, | |
8312 | rs6000_compare_op1); | |
8313 | break; | |
8314 | case GT: | |
8315 | case GTU: | |
8316 | case UNGT: | |
8317 | case UNGE: | |
8318 | case GE: | |
8319 | case GEU: | |
8320 | cmp = flag_unsafe_math_optimizations | |
8321 | ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0, | |
8322 | rs6000_compare_op1) | |
8323 | : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0, | |
8324 | rs6000_compare_op1); | |
8325 | break; | |
8326 | case LT: | |
8327 | case LTU: | |
8328 | case UNLT: | |
8329 | case UNLE: | |
8330 | case LE: | |
8331 | case LEU: | |
8332 | cmp = flag_unsafe_math_optimizations | |
8333 | ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0, | |
8334 | rs6000_compare_op1) | |
8335 | : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0, | |
8336 | rs6000_compare_op1); | |
8337 | break; | |
8338 | default: | |
8339 | abort (); | |
8340 | } | |
8341 | ||
8342 | /* Synthesize LE and GE from LT/GT || EQ. */ | |
8343 | if (code == LE || code == GE || code == LEU || code == GEU) | |
8344 | { | |
8345 | /* Synthesize GE/LE frome GT/LT || EQ. */ | |
8346 | ||
8347 | emit_insn (cmp); | |
8348 | ||
8349 | switch (code) | |
8350 | { | |
8351 | case LE: code = LT; break; | |
8352 | case GE: code = GT; break; | |
8353 | case LEU: code = LT; break; | |
8354 | case GEU: code = GT; break; | |
8355 | default: abort (); | |
8356 | } | |
8357 | ||
8358 | or1 = gen_reg_rtx (SImode); | |
8359 | or2 = gen_reg_rtx (SImode); | |
8360 | or_result = gen_reg_rtx (CCEQmode); | |
8361 | compare_result2 = gen_reg_rtx (CCFPmode); | |
8362 | ||
8363 | /* Do the EQ. */ | |
8364 | cmp = flag_unsafe_math_optimizations | |
8365 | ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0, | |
8366 | rs6000_compare_op1) | |
8367 | : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0, | |
8368 | rs6000_compare_op1); | |
8369 | emit_insn (cmp); | |
8370 | ||
8371 | /* The MC8540 FP compare instructions set the CR bits | |
8372 | differently than other PPC compare instructions. For | |
8373 | that matter, there is no generic test instruction, but a | |
8374 | testgt, testlt, and testeq. For a true condition, bit 2 | |
8375 | is set (x1xx) in the CR. Following the traditional CR | |
8376 | values: | |
8377 | ||
8378 | LT GT EQ OV | |
8379 | bit3 bit2 bit1 bit0 | |
8380 | ||
8381 | ... bit 2 would be a GT CR alias, so later on we | |
b6d08ca1 | 8382 | look in the GT bits for the branch instructions. |
a3170dc6 AH |
8383 | However, we must be careful to emit correct RTL in |
8384 | the meantime, so optimizations don't get confused. */ | |
8385 | ||
8386 | or1 = gen_rtx (NE, SImode, compare_result, const0_rtx); | |
8387 | or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx); | |
8388 | ||
8389 | /* OR them together. */ | |
8390 | cmp = gen_rtx_SET (VOIDmode, or_result, | |
8391 | gen_rtx_COMPARE (CCEQmode, | |
8392 | gen_rtx_IOR (SImode, or1, or2), | |
8393 | const_true_rtx)); | |
8394 | compare_result = or_result; | |
8395 | code = EQ; | |
8396 | } | |
8397 | else | |
8398 | { | |
8399 | /* We only care about 1 bit (x1xx), so map everything to NE to | |
8400 | maintain rtl sanity. We'll get to the right bit (x1xx) at | |
8401 | code output time. */ | |
8402 | if (code == NE || code == LTGT) | |
8403 | /* Do the inverse here because we have no cmpne | |
8404 | instruction. We use the cmpeq instruction and expect | |
8405 | to get a 0 instead. */ | |
8406 | code = EQ; | |
8407 | else | |
8408 | code = NE; | |
8409 | } | |
8410 | ||
8411 | emit_insn (cmp); | |
8412 | } | |
8413 | else | |
8414 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
8415 | gen_rtx_COMPARE (comp_mode, | |
8416 | rs6000_compare_op0, | |
8417 | rs6000_compare_op1))); | |
39a10a29 | 8418 | |
ca5adc63 | 8419 | /* Some kinds of FP comparisons need an OR operation; |
de6c5979 | 8420 | except for flag_unsafe_math_optimizations we don't bother. */ |
39a10a29 | 8421 | if (rs6000_compare_fp_p |
de6c5979 | 8422 | && ! flag_unsafe_math_optimizations |
a3170dc6 | 8423 | && ! (TARGET_HARD_FLOAT && TARGET_SPE) |
39a10a29 GK |
8424 | && (code == LE || code == GE |
8425 | || code == UNEQ || code == LTGT | |
8426 | || code == UNGT || code == UNLT)) | |
8427 | { | |
8428 | enum rtx_code or1, or2; | |
8429 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
8430 | rtx or_result = gen_reg_rtx (CCEQmode); | |
8431 | ||
8432 | switch (code) | |
8433 | { | |
8434 | case LE: or1 = LT; or2 = EQ; break; | |
8435 | case GE: or1 = GT; or2 = EQ; break; | |
8436 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
8437 | case LTGT: or1 = LT; or2 = GT; break; | |
8438 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
8439 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
8440 | default: abort (); | |
8441 | } | |
8442 | validate_condition_mode (or1, comp_mode); | |
8443 | validate_condition_mode (or2, comp_mode); | |
8444 | or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx); | |
8445 | or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx); | |
8446 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, | |
8447 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
8448 | const_true_rtx); | |
8449 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
8450 | ||
8451 | compare_result = or_result; | |
8452 | code = EQ; | |
8453 | } | |
8454 | ||
8455 | validate_condition_mode (code, GET_MODE (compare_result)); | |
8456 | ||
8457 | return gen_rtx (code, VOIDmode, compare_result, const0_rtx); | |
8458 | } | |
8459 | ||
8460 | ||
8461 | /* Emit the RTL for an sCOND pattern. */ | |
8462 | ||
8463 | void | |
8464 | rs6000_emit_sCOND (code, result) | |
8465 | enum rtx_code code; | |
8466 | rtx result; | |
8467 | { | |
8468 | rtx condition_rtx; | |
8469 | enum machine_mode op_mode; | |
8470 | ||
8471 | condition_rtx = rs6000_generate_compare (code); | |
8472 | ||
8473 | op_mode = GET_MODE (rs6000_compare_op0); | |
8474 | if (op_mode == VOIDmode) | |
8475 | op_mode = GET_MODE (rs6000_compare_op1); | |
8476 | ||
8477 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
8478 | { | |
8479 | PUT_MODE (condition_rtx, DImode); | |
8480 | convert_move (result, condition_rtx, 0); | |
8481 | } | |
8482 | else | |
8483 | { | |
8484 | PUT_MODE (condition_rtx, SImode); | |
8485 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
8486 | } | |
8487 | } | |
8488 | ||
39a10a29 GK |
8489 | /* Emit a branch of kind CODE to location LOC. */ |
8490 | ||
8491 | void | |
8492 | rs6000_emit_cbranch (code, loc) | |
8493 | enum rtx_code code; | |
8494 | rtx loc; | |
8495 | { | |
8496 | rtx condition_rtx, loc_ref; | |
8497 | ||
8498 | condition_rtx = rs6000_generate_compare (code); | |
8499 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
8500 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
8501 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
8502 | loc_ref, pc_rtx))); | |
8503 | } | |
8504 | ||
12a4e8c5 GK |
8505 | /* Return the string to output a conditional branch to LABEL, which is |
8506 | the operand number of the label, or -1 if the branch is really a | |
8507 | conditional return. | |
8508 | ||
8509 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
8510 | condition code register and its mode specifies what kind of | |
8511 | comparison we made. | |
8512 | ||
a0ab749a | 8513 | REVERSED is nonzero if we should reverse the sense of the comparison. |
12a4e8c5 GK |
8514 | |
8515 | INSN is the insn. */ | |
8516 | ||
8517 | char * | |
8518 | output_cbranch (op, label, reversed, insn) | |
8519 | rtx op; | |
8520 | const char * label; | |
8521 | int reversed; | |
8522 | rtx insn; | |
8523 | { | |
8524 | static char string[64]; | |
8525 | enum rtx_code code = GET_CODE (op); | |
8526 | rtx cc_reg = XEXP (op, 0); | |
8527 | enum machine_mode mode = GET_MODE (cc_reg); | |
8528 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 8529 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
8530 | int really_reversed = reversed ^ need_longbranch; |
8531 | char *s = string; | |
8532 | const char *ccode; | |
8533 | const char *pred; | |
8534 | rtx note; | |
8535 | ||
39a10a29 GK |
8536 | validate_condition_mode (code, mode); |
8537 | ||
8538 | /* Work out which way this really branches. We could use | |
8539 | reverse_condition_maybe_unordered here always but this | |
8540 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 8541 | if (really_reversed) |
de40e1df DJ |
8542 | { |
8543 | /* Reversal of FP compares takes care -- an ordered compare | |
8544 | becomes an unordered compare and vice versa. */ | |
8545 | if (mode == CCFPmode) | |
8546 | code = reverse_condition_maybe_unordered (code); | |
8547 | else | |
8548 | code = reverse_condition (code); | |
8549 | } | |
12a4e8c5 | 8550 | |
a3170dc6 AH |
8551 | if ((TARGET_SPE && TARGET_HARD_FLOAT) && mode == CCFPmode) |
8552 | { | |
8553 | /* The efscmp/tst* instructions twiddle bit 2, which maps nicely | |
8554 | to the GT bit. */ | |
8555 | if (code == EQ) | |
8556 | /* Opposite of GT. */ | |
8557 | code = UNLE; | |
8558 | else if (code == NE) | |
8559 | code = GT; | |
8560 | else | |
8561 | abort (); | |
8562 | } | |
8563 | ||
39a10a29 | 8564 | switch (code) |
12a4e8c5 GK |
8565 | { |
8566 | /* Not all of these are actually distinct opcodes, but | |
8567 | we distinguish them for clarity of the resulting assembler. */ | |
50a0b056 GK |
8568 | case NE: case LTGT: |
8569 | ccode = "ne"; break; | |
8570 | case EQ: case UNEQ: | |
8571 | ccode = "eq"; break; | |
8572 | case GE: case GEU: | |
8573 | ccode = "ge"; break; | |
8574 | case GT: case GTU: case UNGT: | |
8575 | ccode = "gt"; break; | |
8576 | case LE: case LEU: | |
8577 | ccode = "le"; break; | |
8578 | case LT: case LTU: case UNLT: | |
8579 | ccode = "lt"; break; | |
12a4e8c5 GK |
8580 | case UNORDERED: ccode = "un"; break; |
8581 | case ORDERED: ccode = "nu"; break; | |
8582 | case UNGE: ccode = "nl"; break; | |
8583 | case UNLE: ccode = "ng"; break; | |
8584 | default: | |
a4f6c312 | 8585 | abort (); |
12a4e8c5 GK |
8586 | } |
8587 | ||
94a54f47 GK |
8588 | /* Maybe we have a guess as to how likely the branch is. |
8589 | The old mnemonics don't have a way to specify this information. */ | |
f4857b9b | 8590 | pred = ""; |
12a4e8c5 GK |
8591 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
8592 | if (note != NULL_RTX) | |
8593 | { | |
8594 | /* PROB is the difference from 50%. */ | |
8595 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
f4857b9b AM |
8596 | bool always_hint = rs6000_cpu != PROCESSOR_POWER4; |
8597 | ||
8598 | /* Only hint for highly probable/improbable branches on newer | |
8599 | cpus as static prediction overrides processor dynamic | |
8600 | prediction. For older cpus we may as well always hint, but | |
8601 | assume not taken for branches that are very close to 50% as a | |
8602 | mispredicted taken branch is more expensive than a | |
8603 | mispredicted not-taken branch. */ | |
8604 | if (always_hint | |
8605 | || abs (prob) > REG_BR_PROB_BASE / 100 * 48) | |
8606 | { | |
8607 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
8608 | && ((prob > 0) ^ need_longbranch)) | |
8609 | pred = "+"; | |
8610 | else | |
8611 | pred = "-"; | |
8612 | } | |
12a4e8c5 | 8613 | } |
12a4e8c5 GK |
8614 | |
8615 | if (label == NULL) | |
94a54f47 | 8616 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 8617 | else |
94a54f47 | 8618 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 8619 | |
37c67319 GK |
8620 | /* We need to escape any '%' characters in the reg_names string. |
8621 | Assume they'd only be the first character... */ | |
8622 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') | |
8623 | *s++ = '%'; | |
94a54f47 | 8624 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
8625 | |
8626 | if (label != NULL) | |
8627 | { | |
8628 | /* If the branch distance was too far, we may have to use an | |
8629 | unconditional branch to go the distance. */ | |
8630 | if (need_longbranch) | |
44518ddd | 8631 | s += sprintf (s, ",$+8\n\tb %s", label); |
12a4e8c5 GK |
8632 | else |
8633 | s += sprintf (s, ",%s", label); | |
8634 | } | |
8635 | ||
8636 | return string; | |
8637 | } | |
50a0b056 GK |
8638 | |
8639 | /* Emit a conditional move: move TRUE_COND to DEST if OP of the | |
8640 | operands of the last comparison is nonzero/true, FALSE_COND if it | |
8641 | is zero/false. Return 0 if the hardware has no such operation. */ | |
a4f6c312 | 8642 | |
50a0b056 GK |
8643 | int |
8644 | rs6000_emit_cmove (dest, op, true_cond, false_cond) | |
8645 | rtx dest; | |
8646 | rtx op; | |
8647 | rtx true_cond; | |
8648 | rtx false_cond; | |
8649 | { | |
8650 | enum rtx_code code = GET_CODE (op); | |
8651 | rtx op0 = rs6000_compare_op0; | |
8652 | rtx op1 = rs6000_compare_op1; | |
8653 | REAL_VALUE_TYPE c1; | |
3148ad6d DJ |
8654 | enum machine_mode compare_mode = GET_MODE (op0); |
8655 | enum machine_mode result_mode = GET_MODE (dest); | |
50a0b056 GK |
8656 | rtx temp; |
8657 | ||
3148ad6d | 8658 | /* These modes should always match. */ |
a3170dc6 AH |
8659 | if (GET_MODE (op1) != compare_mode |
8660 | /* In the isel case however, we can use a compare immediate, so | |
8661 | op1 may be a small constant. */ | |
8662 | && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode))) | |
3148ad6d | 8663 | return 0; |
178c3eff | 8664 | if (GET_MODE (true_cond) != result_mode) |
3148ad6d | 8665 | return 0; |
178c3eff | 8666 | if (GET_MODE (false_cond) != result_mode) |
3148ad6d DJ |
8667 | return 0; |
8668 | ||
50a0b056 GK |
8669 | /* First, work out if the hardware can do this at all, or |
8670 | if it's too slow... */ | |
50a0b056 | 8671 | if (! rs6000_compare_fp_p) |
a3170dc6 AH |
8672 | { |
8673 | if (TARGET_ISEL) | |
8674 | return rs6000_emit_int_cmove (dest, op, true_cond, false_cond); | |
8675 | return 0; | |
8676 | } | |
50a0b056 GK |
8677 | |
8678 | /* Eliminate half of the comparisons by switching operands, this | |
8679 | makes the remaining code simpler. */ | |
8680 | if (code == UNLT || code == UNGT || code == UNORDERED || code == NE | |
8681 | || code == LTGT || code == LT) | |
8682 | { | |
8683 | code = reverse_condition_maybe_unordered (code); | |
8684 | temp = true_cond; | |
8685 | true_cond = false_cond; | |
8686 | false_cond = temp; | |
8687 | } | |
8688 | ||
8689 | /* UNEQ and LTGT take four instructions for a comparison with zero, | |
8690 | it'll probably be faster to use a branch here too. */ | |
8691 | if (code == UNEQ) | |
8692 | return 0; | |
8693 | ||
8694 | if (GET_CODE (op1) == CONST_DOUBLE) | |
8695 | REAL_VALUE_FROM_CONST_DOUBLE (c1, op1); | |
8696 | ||
b6d08ca1 | 8697 | /* We're going to try to implement comparisons by performing |
50a0b056 GK |
8698 | a subtract, then comparing against zero. Unfortunately, |
8699 | Inf - Inf is NaN which is not zero, and so if we don't | |
27d30956 | 8700 | know that the operand is finite and the comparison |
50a0b056 GK |
8701 | would treat EQ different to UNORDERED, we can't do it. */ |
8702 | if (! flag_unsafe_math_optimizations | |
8703 | && code != GT && code != UNGE | |
045572c7 | 8704 | && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1)) |
50a0b056 GK |
8705 | /* Constructs of the form (a OP b ? a : b) are safe. */ |
8706 | && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond)) | |
8707 | || (! rtx_equal_p (op0, true_cond) | |
8708 | && ! rtx_equal_p (op1, true_cond)))) | |
8709 | return 0; | |
8710 | /* At this point we know we can use fsel. */ | |
8711 | ||
8712 | /* Reduce the comparison to a comparison against zero. */ | |
3148ad6d | 8713 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 8714 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 8715 | gen_rtx_MINUS (compare_mode, op0, op1))); |
50a0b056 | 8716 | op0 = temp; |
3148ad6d | 8717 | op1 = CONST0_RTX (compare_mode); |
50a0b056 GK |
8718 | |
8719 | /* If we don't care about NaNs we can reduce some of the comparisons | |
8720 | down to faster ones. */ | |
8721 | if (flag_unsafe_math_optimizations) | |
8722 | switch (code) | |
8723 | { | |
8724 | case GT: | |
8725 | code = LE; | |
8726 | temp = true_cond; | |
8727 | true_cond = false_cond; | |
8728 | false_cond = temp; | |
8729 | break; | |
8730 | case UNGE: | |
8731 | code = GE; | |
8732 | break; | |
8733 | case UNEQ: | |
8734 | code = EQ; | |
8735 | break; | |
8736 | default: | |
8737 | break; | |
8738 | } | |
8739 | ||
8740 | /* Now, reduce everything down to a GE. */ | |
8741 | switch (code) | |
8742 | { | |
8743 | case GE: | |
8744 | break; | |
8745 | ||
8746 | case LE: | |
3148ad6d DJ |
8747 | temp = gen_reg_rtx (compare_mode); |
8748 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
8749 | op0 = temp; |
8750 | break; | |
8751 | ||
8752 | case ORDERED: | |
3148ad6d DJ |
8753 | temp = gen_reg_rtx (compare_mode); |
8754 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0))); | |
50a0b056 GK |
8755 | op0 = temp; |
8756 | break; | |
8757 | ||
8758 | case EQ: | |
3148ad6d | 8759 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 8760 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d DJ |
8761 | gen_rtx_NEG (compare_mode, |
8762 | gen_rtx_ABS (compare_mode, op0)))); | |
50a0b056 GK |
8763 | op0 = temp; |
8764 | break; | |
8765 | ||
8766 | case UNGE: | |
3148ad6d | 8767 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 8768 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 8769 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
8770 | gen_rtx_GE (VOIDmode, |
8771 | op0, op1), | |
8772 | true_cond, false_cond))); | |
8773 | false_cond = temp; | |
8774 | true_cond = false_cond; | |
8775 | ||
3148ad6d DJ |
8776 | temp = gen_reg_rtx (compare_mode); |
8777 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
8778 | op0 = temp; |
8779 | break; | |
8780 | ||
8781 | case GT: | |
3148ad6d | 8782 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 8783 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 8784 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
8785 | gen_rtx_GE (VOIDmode, |
8786 | op0, op1), | |
8787 | true_cond, false_cond))); | |
8788 | true_cond = temp; | |
8789 | false_cond = true_cond; | |
8790 | ||
3148ad6d DJ |
8791 | temp = gen_reg_rtx (compare_mode); |
8792 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
8793 | op0 = temp; |
8794 | break; | |
8795 | ||
8796 | default: | |
8797 | abort (); | |
8798 | } | |
8799 | ||
8800 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3148ad6d | 8801 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
8802 | gen_rtx_GE (VOIDmode, |
8803 | op0, op1), | |
8804 | true_cond, false_cond))); | |
8805 | return 1; | |
8806 | } | |
8807 | ||
a3170dc6 AH |
8808 | /* Same as above, but for ints (isel). */ |
8809 | ||
8810 | static int | |
8811 | rs6000_emit_int_cmove (dest, op, true_cond, false_cond) | |
8812 | rtx dest; | |
8813 | rtx op; | |
8814 | rtx true_cond; | |
8815 | rtx false_cond; | |
8816 | { | |
8817 | rtx condition_rtx, cr; | |
8818 | ||
8819 | /* All isel implementations thus far are 32-bits. */ | |
8820 | if (GET_MODE (rs6000_compare_op0) != SImode) | |
8821 | return 0; | |
8822 | ||
8823 | /* We still have to do the compare, because isel doesn't do a | |
8824 | compare, it just looks at the CRx bits set by a previous compare | |
8825 | instruction. */ | |
8826 | condition_rtx = rs6000_generate_compare (GET_CODE (op)); | |
8827 | cr = XEXP (condition_rtx, 0); | |
8828 | ||
8829 | if (GET_MODE (cr) == CCmode) | |
8830 | emit_insn (gen_isel_signed (dest, condition_rtx, | |
8831 | true_cond, false_cond, cr)); | |
8832 | else | |
8833 | emit_insn (gen_isel_unsigned (dest, condition_rtx, | |
8834 | true_cond, false_cond, cr)); | |
8835 | ||
8836 | return 1; | |
8837 | } | |
8838 | ||
8839 | const char * | |
8840 | output_isel (operands) | |
8841 | rtx *operands; | |
8842 | { | |
8843 | enum rtx_code code; | |
8844 | ||
8845 | code = GET_CODE (operands[1]); | |
8846 | if (code == GE || code == GEU || code == LE || code == LEU || code == NE) | |
8847 | { | |
8848 | PUT_CODE (operands[1], reverse_condition (code)); | |
8849 | return "isel %0,%3,%2,%j1"; | |
8850 | } | |
8851 | else | |
8852 | return "isel %0,%2,%3,%j1"; | |
8853 | } | |
8854 | ||
50a0b056 GK |
8855 | void |
8856 | rs6000_emit_minmax (dest, code, op0, op1) | |
8857 | rtx dest; | |
8858 | enum rtx_code code; | |
8859 | rtx op0; | |
8860 | rtx op1; | |
8861 | { | |
8862 | enum machine_mode mode = GET_MODE (op0); | |
5dc8d536 | 8863 | enum rtx_code c; |
50a0b056 | 8864 | rtx target; |
5dc8d536 AH |
8865 | |
8866 | if (code == SMAX || code == SMIN) | |
8867 | c = GE; | |
8868 | else | |
8869 | c = GEU; | |
8870 | ||
50a0b056 | 8871 | if (code == SMAX || code == UMAX) |
5dc8d536 | 8872 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
8873 | op0, op1, mode, 0); |
8874 | else | |
5dc8d536 | 8875 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
8876 | op1, op0, mode, 0); |
8877 | if (target == NULL_RTX) | |
8878 | abort (); | |
8879 | if (target != dest) | |
8880 | emit_move_insn (dest, target); | |
8881 | } | |
12a4e8c5 | 8882 | \f |
a4f6c312 SS |
8883 | /* This page contains routines that are used to determine what the |
8884 | function prologue and epilogue code will do and write them out. */ | |
9878760c | 8885 | |
a4f6c312 SS |
8886 | /* Return the first fixed-point register that is required to be |
8887 | saved. 32 if none. */ | |
9878760c RK |
8888 | |
8889 | int | |
8890 | first_reg_to_save () | |
8891 | { | |
8892 | int first_reg; | |
8893 | ||
8894 | /* Find lowest numbered live register. */ | |
8895 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
a38d360d GK |
8896 | if (regs_ever_live[first_reg] |
8897 | && (! call_used_regs[first_reg] | |
1db02437 | 8898 | || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM |
f607bc57 ZW |
8899 | && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
8900 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))) | |
9878760c RK |
8901 | break; |
8902 | ||
ee890fe2 | 8903 | #if TARGET_MACHO |
93638d7a AM |
8904 | if (flag_pic |
8905 | && current_function_uses_pic_offset_table | |
8906 | && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM) | |
1db02437 | 8907 | return RS6000_PIC_OFFSET_TABLE_REGNUM; |
ee890fe2 SS |
8908 | #endif |
8909 | ||
9878760c RK |
8910 | return first_reg; |
8911 | } | |
8912 | ||
8913 | /* Similar, for FP regs. */ | |
8914 | ||
8915 | int | |
8916 | first_fp_reg_to_save () | |
8917 | { | |
8918 | int first_reg; | |
8919 | ||
8920 | /* Find lowest numbered live register. */ | |
8921 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
8922 | if (regs_ever_live[first_reg]) | |
8923 | break; | |
8924 | ||
8925 | return first_reg; | |
8926 | } | |
00b960c7 AH |
8927 | |
8928 | /* Similar, for AltiVec regs. */ | |
8929 | ||
8930 | static int | |
8931 | first_altivec_reg_to_save () | |
8932 | { | |
8933 | int i; | |
8934 | ||
8935 | /* Stack frame remains as is unless we are in AltiVec ABI. */ | |
8936 | if (! TARGET_ALTIVEC_ABI) | |
8937 | return LAST_ALTIVEC_REGNO + 1; | |
8938 | ||
8939 | /* Find lowest numbered live register. */ | |
8940 | for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i) | |
8941 | if (regs_ever_live[i]) | |
8942 | break; | |
8943 | ||
8944 | return i; | |
8945 | } | |
8946 | ||
8947 | /* Return a 32-bit mask of the AltiVec registers we need to set in | |
8948 | VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in | |
8949 | the 32-bit word is 0. */ | |
8950 | ||
8951 | static unsigned int | |
8952 | compute_vrsave_mask () | |
8953 | { | |
8954 | unsigned int i, mask = 0; | |
8955 | ||
8956 | /* First, find out if we use _any_ altivec registers. */ | |
8957 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
8958 | if (regs_ever_live[i]) | |
8959 | mask |= ALTIVEC_REG_BIT (i); | |
8960 | ||
8961 | if (mask == 0) | |
8962 | return mask; | |
8963 | ||
8964 | /* Next, add all registers that are call-clobbered. We do this | |
8965 | because post-reload register optimizers such as regrename_optimize | |
8966 | may choose to use them. They never change the register class | |
8967 | chosen by reload, so cannot create new uses of altivec registers | |
8968 | if there were none before, so the early exit above is safe. */ | |
8969 | /* ??? Alternately, we could define HARD_REGNO_RENAME_OK to disallow | |
8970 | altivec registers not saved in the mask, which might well make the | |
8971 | adjustments below more effective in eliding the save/restore of | |
8972 | VRSAVE in small functions. */ | |
8973 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
8974 | if (call_used_regs[i]) | |
8975 | mask |= ALTIVEC_REG_BIT (i); | |
8976 | ||
8977 | /* Next, remove the argument registers from the set. These must | |
8978 | be in the VRSAVE mask set by the caller, so we don't need to add | |
8979 | them in again. More importantly, the mask we compute here is | |
8980 | used to generate CLOBBERs in the set_vrsave insn, and we do not | |
8981 | wish the argument registers to die. */ | |
8982 | for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i) | |
8983 | mask &= ~ALTIVEC_REG_BIT (i); | |
8984 | ||
8985 | /* Similarly, remove the return value from the set. */ | |
8986 | { | |
8987 | bool yes = false; | |
8988 | diddle_return_value (is_altivec_return_reg, &yes); | |
8989 | if (yes) | |
8990 | mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN); | |
8991 | } | |
8992 | ||
8993 | return mask; | |
8994 | } | |
8995 | ||
8996 | static void | |
8997 | is_altivec_return_reg (reg, xyes) | |
8998 | rtx reg; | |
8999 | void *xyes; | |
9000 | { | |
9001 | bool *yes = (bool *) xyes; | |
9002 | if (REGNO (reg) == ALTIVEC_ARG_RETURN) | |
9003 | *yes = true; | |
9004 | } | |
9005 | ||
4697a36c MM |
9006 | \f |
9007 | /* Calculate the stack information for the current function. This is | |
9008 | complicated by having two separate calling sequences, the AIX calling | |
9009 | sequence and the V.4 calling sequence. | |
9010 | ||
592696dd | 9011 | AIX (and Darwin/Mac OS X) stack frames look like: |
a260abc9 | 9012 | 32-bit 64-bit |
4697a36c | 9013 | SP----> +---------------------------------------+ |
a260abc9 | 9014 | | back chain to caller | 0 0 |
4697a36c | 9015 | +---------------------------------------+ |
a260abc9 | 9016 | | saved CR | 4 8 (8-11) |
4697a36c | 9017 | +---------------------------------------+ |
a260abc9 | 9018 | | saved LR | 8 16 |
4697a36c | 9019 | +---------------------------------------+ |
a260abc9 | 9020 | | reserved for compilers | 12 24 |
4697a36c | 9021 | +---------------------------------------+ |
a260abc9 | 9022 | | reserved for binders | 16 32 |
4697a36c | 9023 | +---------------------------------------+ |
a260abc9 | 9024 | | saved TOC pointer | 20 40 |
4697a36c | 9025 | +---------------------------------------+ |
a260abc9 | 9026 | | Parameter save area (P) | 24 48 |
4697a36c | 9027 | +---------------------------------------+ |
a260abc9 | 9028 | | Alloca space (A) | 24+P etc. |
802a0058 | 9029 | +---------------------------------------+ |
a7df97e6 | 9030 | | Local variable space (L) | 24+P+A |
4697a36c | 9031 | +---------------------------------------+ |
a7df97e6 | 9032 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 9033 | +---------------------------------------+ |
00b960c7 AH |
9034 | | Save area for AltiVec registers (W) | 24+P+A+L+X |
9035 | +---------------------------------------+ | |
9036 | | AltiVec alignment padding (Y) | 24+P+A+L+X+W | |
9037 | +---------------------------------------+ | |
9038 | | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y | |
4697a36c | 9039 | +---------------------------------------+ |
00b960c7 AH |
9040 | | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z |
9041 | +---------------------------------------+ | |
9042 | | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G | |
4697a36c MM |
9043 | +---------------------------------------+ |
9044 | old SP->| back chain to caller's caller | | |
9045 | +---------------------------------------+ | |
9046 | ||
5376a30c KR |
9047 | The required alignment for AIX configurations is two words (i.e., 8 |
9048 | or 16 bytes). | |
9049 | ||
9050 | ||
4697a36c MM |
9051 | V.4 stack frames look like: |
9052 | ||
9053 | SP----> +---------------------------------------+ | |
9054 | | back chain to caller | 0 | |
9055 | +---------------------------------------+ | |
5eb387b8 | 9056 | | caller's saved LR | 4 |
4697a36c MM |
9057 | +---------------------------------------+ |
9058 | | Parameter save area (P) | 8 | |
9059 | +---------------------------------------+ | |
a7df97e6 MM |
9060 | | Alloca space (A) | 8+P |
9061 | +---------------------------------------+ | |
9062 | | Varargs save area (V) | 8+P+A | |
9063 | +---------------------------------------+ | |
9064 | | Local variable space (L) | 8+P+A+V | |
9065 | +---------------------------------------+ | |
9066 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 9067 | +---------------------------------------+ |
00b960c7 AH |
9068 | | Save area for AltiVec registers (W) | 8+P+A+V+L+X |
9069 | +---------------------------------------+ | |
9070 | | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W | |
9071 | +---------------------------------------+ | |
9072 | | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y | |
9073 | +---------------------------------------+ | |
a3170dc6 AH |
9074 | | SPE: area for 64-bit GP registers | |
9075 | +---------------------------------------+ | |
9076 | | SPE alignment padding | | |
9077 | +---------------------------------------+ | |
00b960c7 | 9078 | | saved CR (C) | 8+P+A+V+L+X+W+Y+Z |
a7df97e6 | 9079 | +---------------------------------------+ |
00b960c7 | 9080 | | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C |
a7df97e6 | 9081 | +---------------------------------------+ |
00b960c7 | 9082 | | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G |
4697a36c MM |
9083 | +---------------------------------------+ |
9084 | old SP->| back chain to caller's caller | | |
9085 | +---------------------------------------+ | |
b6c9286a | 9086 | |
5376a30c KR |
9087 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
9088 | given. (But note below and in sysv4.h that we require only 8 and | |
9089 | may round up the size of our stack frame anyways. The historical | |
9090 | reason is early versions of powerpc-linux which didn't properly | |
9091 | align the stack at program startup. A happy side-effect is that | |
9092 | -mno-eabi libraries can be used with -meabi programs.) | |
9093 | ||
5376a30c KR |
9094 | The EABI configuration defaults to the V.4 layout, unless |
9095 | -mcall-aix is used, in which case the AIX layout is used. However, | |
9096 | the stack alignment requirements may differ. If -mno-eabi is not | |
9097 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
9098 | given, the required alignment is 16 bytes. (But see V.4 comment | |
9099 | above.) */ | |
4697a36c | 9100 | |
61b2fbe7 MM |
9101 | #ifndef ABI_STACK_BOUNDARY |
9102 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
9103 | #endif | |
9104 | ||
4697a36c MM |
9105 | rs6000_stack_t * |
9106 | rs6000_stack_info () | |
9107 | { | |
9108 | static rs6000_stack_t info, zero_info; | |
9109 | rs6000_stack_t *info_ptr = &info; | |
9ebbca7d | 9110 | int reg_size = TARGET_POWERPC64 ? 8 : 4; |
24d304eb | 9111 | enum rs6000_abi abi; |
83720594 | 9112 | int ehrd_size; |
b6c9286a | 9113 | int total_raw_size; |
4697a36c | 9114 | |
a4f6c312 | 9115 | /* Zero all fields portably. */ |
4697a36c MM |
9116 | info = zero_info; |
9117 | ||
a4f6c312 | 9118 | /* Select which calling sequence. */ |
b6c9286a | 9119 | info_ptr->abi = abi = DEFAULT_ABI; |
9878760c | 9120 | |
a4f6c312 | 9121 | /* Calculate which registers need to be saved & save area size. */ |
4697a36c | 9122 | info_ptr->first_gp_reg_save = first_reg_to_save (); |
1db02437 | 9123 | /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM, |
906fb125 | 9124 | even if it currently looks like we won't. */ |
2bfcf297 | 9125 | if (((TARGET_TOC && TARGET_MINIMAL_TOC) |
f607bc57 ZW |
9126 | || (flag_pic == 1 && abi == ABI_V4) |
9127 | || (flag_pic && abi == ABI_DARWIN)) | |
1db02437 FS |
9128 | && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM) |
9129 | info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM); | |
906fb125 GK |
9130 | else |
9131 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c | 9132 | |
a3170dc6 AH |
9133 | /* For the SPE, we have an additional upper 32-bits on each GPR. |
9134 | Ideally we should save the entire 64-bits only when the upper | |
9135 | half is used in SIMD instructions. Since we only record | |
9136 | registers live (not the size they are used in), this proves | |
9137 | difficult because we'd have to traverse the instruction chain at | |
9138 | the right time, taking reload into account. This is a real pain, | |
9139 | so we opt to save the GPRs in 64-bits always. Anyone overly | |
9140 | concerned with frame size can fix this. ;-). | |
9141 | ||
9142 | So... since we save all GPRs (except the SP) in 64-bits, the | |
9143 | traditional GP save area will be empty. */ | |
9144 | if (TARGET_SPE_ABI) | |
9145 | info_ptr->gp_size = 0; | |
9146 | ||
4697a36c MM |
9147 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); |
9148 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
9149 | ||
00b960c7 AH |
9150 | info_ptr->first_altivec_reg_save = first_altivec_reg_to_save (); |
9151 | info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1 | |
9152 | - info_ptr->first_altivec_reg_save); | |
9153 | ||
592696dd | 9154 | /* Does this function call anything? */ |
71f123ca FS |
9155 | info_ptr->calls_p = (! current_function_is_leaf |
9156 | || cfun->machine->ra_needs_full_frame); | |
b6c9286a | 9157 | |
a4f6c312 | 9158 | /* Determine if we need to save the link register. */ |
71f123ca | 9159 | if (rs6000_ra_ever_killed () |
70f4f91c | 9160 | || (DEFAULT_ABI == ABI_AIX && current_function_profile) |
4697a36c MM |
9161 | #ifdef TARGET_RELOCATABLE |
9162 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
9163 | #endif | |
9164 | || (info_ptr->first_fp_reg_save != 64 | |
9165 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
00b960c7 | 9166 | || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO |
24d304eb | 9167 | || (abi == ABI_V4 && current_function_calls_alloca) |
a4f6c312 SS |
9168 | || (DEFAULT_ABI == ABI_DARWIN |
9169 | && flag_pic | |
9170 | && current_function_uses_pic_offset_table) | |
4697a36c MM |
9171 | || info_ptr->calls_p) |
9172 | { | |
9173 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 9174 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
9175 | } |
9176 | ||
9ebbca7d GK |
9177 | /* Determine if we need to save the condition code registers. */ |
9178 | if (regs_ever_live[CR2_REGNO] | |
9179 | || regs_ever_live[CR3_REGNO] | |
9180 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
9181 | { |
9182 | info_ptr->cr_save_p = 1; | |
f607bc57 | 9183 | if (abi == ABI_V4) |
4697a36c MM |
9184 | info_ptr->cr_size = reg_size; |
9185 | } | |
9186 | ||
83720594 RH |
9187 | /* If the current function calls __builtin_eh_return, then we need |
9188 | to allocate stack space for registers that will hold data for | |
9189 | the exception handler. */ | |
9190 | if (current_function_calls_eh_return) | |
9191 | { | |
9192 | unsigned int i; | |
9193 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i) | |
9194 | continue; | |
a3170dc6 AH |
9195 | |
9196 | /* SPE saves EH registers in 64-bits. */ | |
9197 | ehrd_size = i * (TARGET_SPE_ABI ? UNITS_PER_SPE_WORD : UNITS_PER_WORD); | |
83720594 RH |
9198 | } |
9199 | else | |
9200 | ehrd_size = 0; | |
9201 | ||
592696dd | 9202 | /* Determine various sizes. */ |
4697a36c MM |
9203 | info_ptr->reg_size = reg_size; |
9204 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
9205 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 | 9206 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
a4f6c312 SS |
9207 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, |
9208 | 8); | |
00b960c7 | 9209 | |
a3170dc6 AH |
9210 | if (TARGET_SPE_ABI) |
9211 | info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save); | |
9212 | else | |
9213 | info_ptr->spe_gp_size = 0; | |
9214 | ||
08b57fb3 | 9215 | if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE) |
00b960c7 AH |
9216 | { |
9217 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
9218 | info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0; | |
9219 | } | |
9220 | else | |
9221 | { | |
9222 | info_ptr->vrsave_mask = 0; | |
9223 | info_ptr->vrsave_size = 0; | |
9224 | } | |
b6c9286a | 9225 | |
592696dd | 9226 | /* Calculate the offsets. */ |
24d304eb | 9227 | switch (abi) |
4697a36c | 9228 | { |
b6c9286a | 9229 | case ABI_NONE: |
24d304eb | 9230 | default: |
b6c9286a MM |
9231 | abort (); |
9232 | ||
9233 | case ABI_AIX: | |
9234 | case ABI_AIX_NODESC: | |
ee890fe2 | 9235 | case ABI_DARWIN: |
b6c9286a MM |
9236 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
9237 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
00b960c7 AH |
9238 | |
9239 | if (TARGET_ALTIVEC_ABI) | |
9240 | { | |
9241 | info_ptr->vrsave_save_offset | |
9242 | = info_ptr->gp_save_offset - info_ptr->vrsave_size; | |
9243 | ||
9244 | /* Align stack so vector save area is on a quadword boundary. */ | |
9245 | if (info_ptr->altivec_size != 0) | |
9246 | info_ptr->altivec_padding_size | |
9247 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
9248 | else | |
9249 | info_ptr->altivec_padding_size = 0; | |
9250 | ||
9251 | info_ptr->altivec_save_offset | |
9252 | = info_ptr->vrsave_save_offset | |
9253 | - info_ptr->altivec_padding_size | |
9254 | - info_ptr->altivec_size; | |
9255 | ||
9256 | /* Adjust for AltiVec case. */ | |
9257 | info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size; | |
9258 | } | |
9259 | else | |
9260 | info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size; | |
a260abc9 DE |
9261 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
9262 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
9263 | break; |
9264 | ||
9265 | case ABI_V4: | |
b6c9286a MM |
9266 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
9267 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 | 9268 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
00b960c7 | 9269 | |
a3170dc6 AH |
9270 | if (TARGET_SPE_ABI) |
9271 | { | |
9272 | /* Align stack so SPE GPR save area is aligned on a | |
9273 | double-word boundary. */ | |
9274 | if (info_ptr->spe_gp_size != 0) | |
9275 | info_ptr->spe_padding_size | |
9276 | = 8 - (-info_ptr->cr_save_offset % 8); | |
9277 | else | |
9278 | info_ptr->spe_padding_size = 0; | |
9279 | ||
9280 | info_ptr->spe_gp_save_offset | |
9281 | = info_ptr->cr_save_offset | |
9282 | - info_ptr->spe_padding_size | |
9283 | - info_ptr->spe_gp_size; | |
9284 | ||
9285 | /* Adjust for SPE case. */ | |
9286 | info_ptr->toc_save_offset | |
9287 | = info_ptr->spe_gp_save_offset - info_ptr->toc_size; | |
9288 | } | |
9289 | else if (TARGET_ALTIVEC_ABI) | |
00b960c7 AH |
9290 | { |
9291 | info_ptr->vrsave_save_offset | |
9292 | = info_ptr->cr_save_offset - info_ptr->vrsave_size; | |
9293 | ||
9294 | /* Align stack so vector save area is on a quadword boundary. */ | |
9295 | if (info_ptr->altivec_size != 0) | |
9296 | info_ptr->altivec_padding_size | |
9297 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
9298 | else | |
9299 | info_ptr->altivec_padding_size = 0; | |
9300 | ||
9301 | info_ptr->altivec_save_offset | |
9302 | = info_ptr->vrsave_save_offset | |
9303 | - info_ptr->altivec_padding_size | |
9304 | - info_ptr->altivec_size; | |
9305 | ||
9306 | /* Adjust for AltiVec case. */ | |
9307 | info_ptr->toc_save_offset | |
9308 | = info_ptr->altivec_save_offset - info_ptr->toc_size; | |
9309 | } | |
9310 | else | |
9311 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
83720594 | 9312 | info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size; |
b6c9286a MM |
9313 | info_ptr->lr_save_offset = reg_size; |
9314 | break; | |
4697a36c MM |
9315 | } |
9316 | ||
00b960c7 AH |
9317 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
9318 | + info_ptr->gp_size | |
9319 | + info_ptr->altivec_size | |
9320 | + info_ptr->altivec_padding_size | |
9321 | + info_ptr->vrsave_size | |
a3170dc6 AH |
9322 | + info_ptr->spe_gp_size |
9323 | + info_ptr->spe_padding_size | |
00b960c7 AH |
9324 | + ehrd_size |
9325 | + info_ptr->cr_size | |
9326 | + info_ptr->lr_size | |
9327 | + info_ptr->vrsave_size | |
9328 | + info_ptr->toc_size, | |
9329 | (TARGET_ALTIVEC_ABI || ABI_DARWIN) | |
9330 | ? 16 : 8); | |
9331 | ||
ff381587 MM |
9332 | total_raw_size = (info_ptr->vars_size |
9333 | + info_ptr->parm_size | |
ff381587 MM |
9334 | + info_ptr->save_size |
9335 | + info_ptr->varargs_size | |
9336 | + info_ptr->fixed_size); | |
9337 | ||
a4f6c312 SS |
9338 | info_ptr->total_size = |
9339 | RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
ff381587 MM |
9340 | |
9341 | /* Determine if we need to allocate any stack frame: | |
9342 | ||
a4f6c312 SS |
9343 | For AIX we need to push the stack if a frame pointer is needed |
9344 | (because the stack might be dynamically adjusted), if we are | |
9345 | debugging, if we make calls, or if the sum of fp_save, gp_save, | |
9346 | and local variables are more than the space needed to save all | |
9347 | non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 | |
9348 | + 18*8 = 288 (GPR13 reserved). | |
ff381587 | 9349 | |
a4f6c312 SS |
9350 | For V.4 we don't have the stack cushion that AIX uses, but assume |
9351 | that the debugger can handle stackless frames. */ | |
ff381587 MM |
9352 | |
9353 | if (info_ptr->calls_p) | |
9354 | info_ptr->push_p = 1; | |
9355 | ||
f607bc57 | 9356 | else if (abi == ABI_V4) |
e72247f4 | 9357 | info_ptr->push_p = total_raw_size > info_ptr->fixed_size; |
ff381587 MM |
9358 | |
9359 | else | |
9360 | info_ptr->push_p = (frame_pointer_needed | |
ee890fe2 | 9361 | || (abi != ABI_DARWIN && write_symbols != NO_DEBUG) |
ff381587 | 9362 | || ((total_raw_size - info_ptr->fixed_size) |
bfc79d3b | 9363 | > (TARGET_32BIT ? 220 : 288))); |
ff381587 | 9364 | |
a4f6c312 | 9365 | /* Zero offsets if we're not saving those registers. */ |
8dda1a21 | 9366 | if (info_ptr->fp_size == 0) |
4697a36c MM |
9367 | info_ptr->fp_save_offset = 0; |
9368 | ||
8dda1a21 | 9369 | if (info_ptr->gp_size == 0) |
4697a36c MM |
9370 | info_ptr->gp_save_offset = 0; |
9371 | ||
00b960c7 AH |
9372 | if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0) |
9373 | info_ptr->altivec_save_offset = 0; | |
9374 | ||
9375 | if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0) | |
9376 | info_ptr->vrsave_save_offset = 0; | |
9377 | ||
a3170dc6 AH |
9378 | if (! TARGET_SPE_ABI || info_ptr->spe_gp_size == 0) |
9379 | info_ptr->spe_gp_save_offset = 0; | |
9380 | ||
c81fc13e | 9381 | if (! info_ptr->lr_save_p) |
4697a36c MM |
9382 | info_ptr->lr_save_offset = 0; |
9383 | ||
c81fc13e | 9384 | if (! info_ptr->cr_save_p) |
4697a36c MM |
9385 | info_ptr->cr_save_offset = 0; |
9386 | ||
c81fc13e | 9387 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
9388 | info_ptr->toc_save_offset = 0; |
9389 | ||
4697a36c MM |
9390 | return info_ptr; |
9391 | } | |
9392 | ||
9393 | void | |
9394 | debug_stack_info (info) | |
9395 | rs6000_stack_t *info; | |
9878760c | 9396 | { |
d330fd93 | 9397 | const char *abi_string; |
24d304eb | 9398 | |
c81fc13e | 9399 | if (! info) |
4697a36c MM |
9400 | info = rs6000_stack_info (); |
9401 | ||
9402 | fprintf (stderr, "\nStack information for function %s:\n", | |
9403 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
9404 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
9405 | : "<unknown>")); | |
9406 | ||
24d304eb RK |
9407 | switch (info->abi) |
9408 | { | |
b6c9286a MM |
9409 | default: abi_string = "Unknown"; break; |
9410 | case ABI_NONE: abi_string = "NONE"; break; | |
f607bc57 | 9411 | case ABI_AIX: |
b6c9286a | 9412 | case ABI_AIX_NODESC: abi_string = "AIX"; break; |
ee890fe2 | 9413 | case ABI_DARWIN: abi_string = "Darwin"; break; |
b6c9286a | 9414 | case ABI_V4: abi_string = "V.4"; break; |
24d304eb RK |
9415 | } |
9416 | ||
9417 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
9418 | ||
00b960c7 AH |
9419 | if (TARGET_ALTIVEC_ABI) |
9420 | fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n"); | |
9421 | ||
a3170dc6 AH |
9422 | if (TARGET_SPE_ABI) |
9423 | fprintf (stderr, "\tSPE ABI extensions enabled.\n"); | |
9424 | ||
4697a36c MM |
9425 | if (info->first_gp_reg_save != 32) |
9426 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
9427 | ||
9428 | if (info->first_fp_reg_save != 64) | |
9429 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 9430 | |
00b960c7 AH |
9431 | if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO) |
9432 | fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n", | |
9433 | info->first_altivec_reg_save); | |
9434 | ||
4697a36c MM |
9435 | if (info->lr_save_p) |
9436 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 9437 | |
4697a36c MM |
9438 | if (info->cr_save_p) |
9439 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
9440 | ||
b6c9286a MM |
9441 | if (info->toc_save_p) |
9442 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
9443 | ||
00b960c7 AH |
9444 | if (info->vrsave_mask) |
9445 | fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask); | |
9446 | ||
4697a36c MM |
9447 | if (info->push_p) |
9448 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
9449 | ||
9450 | if (info->calls_p) | |
9451 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
9452 | ||
4697a36c MM |
9453 | if (info->gp_save_offset) |
9454 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
9455 | ||
9456 | if (info->fp_save_offset) | |
9457 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
9458 | ||
00b960c7 AH |
9459 | if (info->altivec_save_offset) |
9460 | fprintf (stderr, "\taltivec_save_offset = %5d\n", | |
9461 | info->altivec_save_offset); | |
9462 | ||
a3170dc6 AH |
9463 | if (info->spe_gp_save_offset) |
9464 | fprintf (stderr, "\tspe_gp_save_offset = %5d\n", | |
9465 | info->spe_gp_save_offset); | |
9466 | ||
00b960c7 AH |
9467 | if (info->vrsave_save_offset) |
9468 | fprintf (stderr, "\tvrsave_save_offset = %5d\n", | |
9469 | info->vrsave_save_offset); | |
9470 | ||
4697a36c MM |
9471 | if (info->lr_save_offset) |
9472 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
9473 | ||
9474 | if (info->cr_save_offset) | |
9475 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
9476 | ||
b6c9286a MM |
9477 | if (info->toc_save_offset) |
9478 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
9479 | ||
4697a36c MM |
9480 | if (info->varargs_save_offset) |
9481 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
9482 | ||
9483 | if (info->total_size) | |
9484 | fprintf (stderr, "\ttotal_size = %5d\n", info->total_size); | |
9485 | ||
9486 | if (info->varargs_size) | |
9487 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
9488 | ||
9489 | if (info->vars_size) | |
9490 | fprintf (stderr, "\tvars_size = %5d\n", info->vars_size); | |
9491 | ||
9492 | if (info->parm_size) | |
9493 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
9494 | ||
9495 | if (info->fixed_size) | |
9496 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
9497 | ||
9498 | if (info->gp_size) | |
9499 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
9500 | ||
a3170dc6 AH |
9501 | if (info->spe_gp_size) |
9502 | fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size); | |
9503 | ||
4697a36c MM |
9504 | if (info->fp_size) |
9505 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
9506 | ||
00b960c7 AH |
9507 | if (info->altivec_size) |
9508 | fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size); | |
9509 | ||
9510 | if (info->vrsave_size) | |
9511 | fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size); | |
9512 | ||
9513 | if (info->altivec_padding_size) | |
9514 | fprintf (stderr, "\taltivec_padding_size= %5d\n", | |
9515 | info->altivec_padding_size); | |
9516 | ||
a3170dc6 AH |
9517 | if (info->spe_padding_size) |
9518 | fprintf (stderr, "\tspe_padding_size = %5d\n", | |
9519 | info->spe_padding_size); | |
9520 | ||
a4f6c312 | 9521 | if (info->lr_size) |
ed947a96 | 9522 | fprintf (stderr, "\tlr_size = %5d\n", info->lr_size); |
b6c9286a | 9523 | |
4697a36c MM |
9524 | if (info->cr_size) |
9525 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
9526 | ||
a4f6c312 | 9527 | if (info->toc_size) |
b6c9286a MM |
9528 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); |
9529 | ||
4697a36c MM |
9530 | if (info->save_size) |
9531 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
9532 | ||
9533 | if (info->reg_size != 4) | |
9534 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
9535 | ||
9536 | fprintf (stderr, "\n"); | |
9878760c | 9537 | } |
71f123ca FS |
9538 | |
9539 | rtx | |
9540 | rs6000_return_addr (count, frame) | |
9541 | int count; | |
9542 | rtx frame; | |
9543 | { | |
a4f6c312 SS |
9544 | /* Currently we don't optimize very well between prolog and body |
9545 | code and for PIC code the code can be actually quite bad, so | |
9546 | don't try to be too clever here. */ | |
f585a356 | 9547 | if (count != 0 || flag_pic != 0) |
71f123ca FS |
9548 | { |
9549 | cfun->machine->ra_needs_full_frame = 1; | |
8ac61af7 RK |
9550 | |
9551 | return | |
9552 | gen_rtx_MEM | |
9553 | (Pmode, | |
9554 | memory_address | |
9555 | (Pmode, | |
9556 | plus_constant (copy_to_reg | |
9557 | (gen_rtx_MEM (Pmode, | |
9558 | memory_address (Pmode, frame))), | |
9559 | RETURN_ADDRESS_OFFSET))); | |
71f123ca FS |
9560 | } |
9561 | ||
9e2f7ec7 | 9562 | return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM); |
71f123ca FS |
9563 | } |
9564 | ||
5e1bf043 DJ |
9565 | /* Say whether a function is a candidate for sibcall handling or not. |
9566 | We do not allow indirect calls to be optimized into sibling calls. | |
9567 | Also, we can't do it if there are any vector parameters; there's | |
9568 | nowhere to put the VRsave code so it works; note that functions with | |
9569 | vector parameters are required to have a prototype, so the argument | |
9570 | type info must be available here. (The tail recursion case can work | |
9571 | with vector parameters, but there's no way to distinguish here.) */ | |
4977bab6 ZW |
9572 | static bool |
9573 | rs6000_function_ok_for_sibcall (decl, exp) | |
9574 | tree decl; | |
9575 | tree exp ATTRIBUTE_UNUSED; | |
5e1bf043 DJ |
9576 | { |
9577 | tree type; | |
4977bab6 | 9578 | if (decl) |
5e1bf043 DJ |
9579 | { |
9580 | if (TARGET_ALTIVEC_VRSAVE) | |
9581 | { | |
4977bab6 | 9582 | for (type = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
5e1bf043 DJ |
9583 | type; type = TREE_CHAIN (type)) |
9584 | { | |
c15b529f | 9585 | if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE) |
4977bab6 | 9586 | return false; |
5e1bf043 DJ |
9587 | } |
9588 | } | |
9589 | if (DEFAULT_ABI == ABI_DARWIN | |
4977bab6 | 9590 | || (*targetm.binds_local_p) (decl)) |
2bcc50d0 | 9591 | { |
4977bab6 | 9592 | tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
2bcc50d0 AM |
9593 | |
9594 | if (!lookup_attribute ("longcall", attr_list) | |
9595 | || lookup_attribute ("shortcall", attr_list)) | |
4977bab6 | 9596 | return true; |
2bcc50d0 | 9597 | } |
5e1bf043 | 9598 | } |
4977bab6 | 9599 | return false; |
5e1bf043 DJ |
9600 | } |
9601 | ||
71f123ca FS |
9602 | static int |
9603 | rs6000_ra_ever_killed () | |
9604 | { | |
9605 | rtx top; | |
5e1bf043 DJ |
9606 | rtx reg; |
9607 | rtx insn; | |
71f123ca | 9608 | |
3961e8fe RH |
9609 | /* Irritatingly, there are two kinds of thunks -- those created with |
9610 | TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go | |
9611 | through the regular part of the compiler. This is a very hacky | |
9612 | way to tell them apart. */ | |
9613 | if (current_function_is_thunk && !no_new_pseudos) | |
71f123ca | 9614 | return 0; |
eb0424da | 9615 | |
36f7e964 AH |
9616 | /* regs_ever_live has LR marked as used if any sibcalls are present, |
9617 | but this should not force saving and restoring in the | |
9618 | pro/epilogue. Likewise, reg_set_between_p thinks a sibcall | |
9619 | clobbers LR, so that is inappropriate. */ | |
9620 | ||
5e1bf043 DJ |
9621 | /* Also, the prologue can generate a store into LR that |
9622 | doesn't really count, like this: | |
36f7e964 | 9623 | |
5e1bf043 DJ |
9624 | move LR->R0 |
9625 | bcl to set PIC register | |
9626 | move LR->R31 | |
9627 | move R0->LR | |
36f7e964 AH |
9628 | |
9629 | When we're called from the epilogue, we need to avoid counting | |
9630 | this as a store. */ | |
5e1bf043 | 9631 | |
71f123ca FS |
9632 | push_topmost_sequence (); |
9633 | top = get_insns (); | |
9634 | pop_topmost_sequence (); | |
5e1bf043 | 9635 | reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); |
71f123ca | 9636 | |
5e1bf043 DJ |
9637 | for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn)) |
9638 | { | |
9639 | if (INSN_P (insn)) | |
9640 | { | |
9641 | if (FIND_REG_INC_NOTE (insn, reg)) | |
9642 | return 1; | |
9643 | else if (GET_CODE (insn) == CALL_INSN | |
c15b529f | 9644 | && !SIBLING_CALL_P (insn)) |
5e1bf043 | 9645 | return 1; |
36f7e964 AH |
9646 | else if (set_of (reg, insn) != NULL_RTX |
9647 | && !prologue_epilogue_contains (insn)) | |
5e1bf043 DJ |
9648 | return 1; |
9649 | } | |
9650 | } | |
9651 | return 0; | |
71f123ca | 9652 | } |
4697a36c | 9653 | \f |
8cd8f856 GK |
9654 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
9655 | static void | |
9656 | rs6000_maybe_dead (insn) | |
9657 | rtx insn; | |
9658 | { | |
9659 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
9660 | const0_rtx, | |
9661 | REG_NOTES (insn)); | |
9662 | } | |
9663 | ||
9ebbca7d | 9664 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 9665 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 9666 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
9667 | |
9668 | void | |
9ebbca7d GK |
9669 | rs6000_emit_load_toc_table (fromprolog) |
9670 | int fromprolog; | |
c7ca610e | 9671 | { |
9ebbca7d | 9672 | rtx dest; |
1db02437 | 9673 | dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); |
c7ca610e | 9674 | |
20b71b17 AM |
9675 | if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
9676 | { | |
9677 | rtx temp = (fromprolog | |
9678 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
9679 | : gen_reg_rtx (Pmode)); | |
9680 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp))); | |
9681 | rs6000_maybe_dead (emit_move_insn (dest, temp)); | |
9682 | } | |
9683 | else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2) | |
9684 | { | |
9685 | char buf[30]; | |
9686 | rtx tempLR = (fromprolog | |
9687 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
9688 | : gen_reg_rtx (Pmode)); | |
9689 | rtx temp0 = (fromprolog | |
9690 | ? gen_rtx_REG (Pmode, 0) | |
9691 | : gen_reg_rtx (Pmode)); | |
9692 | rtx symF; | |
9693 | ||
9694 | /* possibly create the toc section */ | |
9695 | if (! toc_initialized) | |
38c1f2d7 | 9696 | { |
20b71b17 AM |
9697 | toc_section (); |
9698 | function_section (current_function_decl); | |
38c1f2d7 | 9699 | } |
9ebbca7d | 9700 | |
20b71b17 AM |
9701 | if (fromprolog) |
9702 | { | |
9703 | rtx symL; | |
38c1f2d7 | 9704 | |
20b71b17 AM |
9705 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); |
9706 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9ebbca7d | 9707 | |
20b71b17 AM |
9708 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
9709 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9710 | ||
9711 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, | |
9712 | symF))); | |
9713 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
9714 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
9715 | symL, | |
9716 | symF))); | |
9ebbca7d GK |
9717 | } |
9718 | else | |
20b71b17 AM |
9719 | { |
9720 | rtx tocsym; | |
9721 | static int reload_toc_labelno = 0; | |
9722 | ||
9723 | tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); | |
9724 | ||
9725 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); | |
9726 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9727 | ||
9728 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR, | |
9729 | symF, | |
9730 | tocsym))); | |
9731 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
9732 | rs6000_maybe_dead (emit_move_insn (temp0, | |
9733 | gen_rtx_MEM (Pmode, dest))); | |
9734 | } | |
9735 | rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest))); | |
9ebbca7d | 9736 | } |
20b71b17 AM |
9737 | else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC) |
9738 | { | |
9739 | /* This is for AIX code running in non-PIC ELF32. */ | |
9740 | char buf[30]; | |
9741 | rtx realsym; | |
9742 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
9743 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9744 | ||
9745 | rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym))); | |
9746 | rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym))); | |
9747 | } | |
9748 | else if (DEFAULT_ABI == ABI_AIX) | |
9ebbca7d GK |
9749 | { |
9750 | if (TARGET_32BIT) | |
20b71b17 | 9751 | rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest))); |
9ebbca7d | 9752 | else |
20b71b17 | 9753 | rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest))); |
9ebbca7d | 9754 | } |
20b71b17 AM |
9755 | else |
9756 | abort (); | |
9ebbca7d GK |
9757 | } |
9758 | ||
9759 | int | |
9760 | get_TOC_alias_set () | |
9761 | { | |
9762 | static int set = -1; | |
9763 | if (set == -1) | |
9764 | set = new_alias_set (); | |
9765 | return set; | |
9766 | } | |
9767 | ||
9768 | /* This retuns nonzero if the current function uses the TOC. This is | |
9769 | determined by the presence of (unspec ... 7), which is generated by | |
9770 | the various load_toc_* patterns. */ | |
a4f6c312 | 9771 | |
9ebbca7d GK |
9772 | int |
9773 | uses_TOC () | |
9774 | { | |
9775 | rtx insn; | |
38c1f2d7 | 9776 | |
9ebbca7d | 9777 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
2c3c49de | 9778 | if (INSN_P (insn)) |
9ebbca7d GK |
9779 | { |
9780 | rtx pat = PATTERN (insn); | |
9781 | int i; | |
9782 | ||
8cd8f856 | 9783 | if (GET_CODE (pat) == PARALLEL) |
9ebbca7d GK |
9784 | for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++) |
9785 | if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC | |
9786 | && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7) | |
9787 | return 1; | |
38c1f2d7 | 9788 | } |
9ebbca7d GK |
9789 | return 0; |
9790 | } | |
38c1f2d7 | 9791 | |
9ebbca7d | 9792 | rtx |
a4f6c312 | 9793 | create_TOC_reference (symbol) |
9ebbca7d GK |
9794 | rtx symbol; |
9795 | { | |
a8a05998 ZW |
9796 | return gen_rtx_PLUS (Pmode, |
9797 | gen_rtx_REG (Pmode, TOC_REGISTER), | |
9798 | gen_rtx_CONST (Pmode, | |
9799 | gen_rtx_MINUS (Pmode, symbol, | |
b999aaeb | 9800 | gen_rtx_SYMBOL_REF (Pmode, toc_label_name)))); |
9ebbca7d | 9801 | } |
38c1f2d7 | 9802 | |
9ebbca7d GK |
9803 | #if TARGET_AIX |
9804 | /* __throw will restore its own return address to be the same as the | |
9805 | return address of the function that the throw is being made to. | |
9806 | This is unfortunate, because we want to check the original | |
9807 | return address to see if we need to restore the TOC. | |
9808 | So we have to squirrel it away here. | |
9809 | This is used only in compiling __throw and __rethrow. | |
c7ca610e | 9810 | |
9ebbca7d GK |
9811 | Most of this code should be removed by CSE. */ |
9812 | static rtx insn_after_throw; | |
c7ca610e | 9813 | |
a4f6c312 | 9814 | /* This does the saving... */ |
9ebbca7d GK |
9815 | void |
9816 | rs6000_aix_emit_builtin_unwind_init () | |
9817 | { | |
9818 | rtx mem; | |
9819 | rtx stack_top = gen_reg_rtx (Pmode); | |
9820 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
9821 | ||
9822 | insn_after_throw = gen_reg_rtx (SImode); | |
9823 | ||
9824 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
9825 | emit_move_insn (stack_top, mem); | |
9826 | ||
9827 | mem = gen_rtx_MEM (Pmode, | |
9828 | gen_rtx_PLUS (Pmode, stack_top, | |
9829 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); | |
9830 | emit_move_insn (opcode_addr, mem); | |
9831 | emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr)); | |
c7ca610e RK |
9832 | } |
9833 | ||
a4f6c312 SS |
9834 | /* Emit insns to _restore_ the TOC register, at runtime (specifically |
9835 | in _eh.o). Only used on AIX. | |
9ebbca7d GK |
9836 | |
9837 | The idea is that on AIX, function calls look like this: | |
9838 | bl somefunction-trampoline | |
9839 | lwz r2,20(sp) | |
9840 | ||
a4f6c312 | 9841 | and later, |
9ebbca7d GK |
9842 | somefunction-trampoline: |
9843 | stw r2,20(sp) | |
9844 | ... load function address in the count register ... | |
9845 | bctr | |
9846 | or like this, if the linker determines that this is not a cross-module call | |
9847 | and so the TOC need not be restored: | |
9848 | bl somefunction | |
9849 | nop | |
9850 | or like this, if the compiler could determine that this is not a | |
9851 | cross-module call: | |
9852 | bl somefunction | |
9853 | now, the tricky bit here is that register 2 is saved and restored | |
9854 | by the _linker_, so we can't readily generate debugging information | |
9855 | for it. So we need to go back up the call chain looking at the | |
9856 | insns at return addresses to see which calls saved the TOC register | |
9857 | and so see where it gets restored from. | |
9858 | ||
9859 | Oh, and all this gets done in RTL inside the eh_epilogue pattern, | |
9860 | just before the actual epilogue. | |
9861 | ||
9862 | On the bright side, this incurs no space or time overhead unless an | |
9863 | exception is thrown, except for the extra code in libgcc.a. | |
9864 | ||
9865 | The parameter STACKSIZE is a register containing (at runtime) | |
9866 | the amount to be popped off the stack in addition to the stack frame | |
9867 | of this routine (which will be __throw or __rethrow, and so is | |
9868 | guaranteed to have a stack frame). */ | |
a4f6c312 | 9869 | |
9ebbca7d GK |
9870 | void |
9871 | rs6000_emit_eh_toc_restore (stacksize) | |
9872 | rtx stacksize; | |
9873 | { | |
9874 | rtx top_of_stack; | |
9875 | rtx bottom_of_stack = gen_reg_rtx (Pmode); | |
9876 | rtx tocompare = gen_reg_rtx (SImode); | |
9877 | rtx opcode = gen_reg_rtx (SImode); | |
9878 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
9879 | rtx mem; | |
9880 | rtx loop_start = gen_label_rtx (); | |
9881 | rtx no_toc_restore_needed = gen_label_rtx (); | |
9882 | rtx loop_exit = gen_label_rtx (); | |
9883 | ||
9884 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
ba4828e0 | 9885 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
9886 | emit_move_insn (bottom_of_stack, mem); |
9887 | ||
9888 | top_of_stack = expand_binop (Pmode, add_optab, | |
9889 | bottom_of_stack, stacksize, | |
9890 | NULL_RTX, 1, OPTAB_WIDEN); | |
9891 | ||
2496c7bd LB |
9892 | emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014 |
9893 | : 0xE8410028, SImode)); | |
9ebbca7d GK |
9894 | |
9895 | if (insn_after_throw == NULL_RTX) | |
a4f6c312 | 9896 | abort (); |
9ebbca7d GK |
9897 | emit_move_insn (opcode, insn_after_throw); |
9898 | ||
6496a589 | 9899 | emit_note (NULL, NOTE_INSN_LOOP_BEG); |
9ebbca7d GK |
9900 | emit_label (loop_start); |
9901 | ||
9902 | do_compare_rtx_and_jump (opcode, tocompare, NE, 1, | |
06f4e019 | 9903 | SImode, NULL_RTX, NULL_RTX, |
9ebbca7d GK |
9904 | no_toc_restore_needed); |
9905 | ||
9906 | mem = gen_rtx_MEM (Pmode, | |
9907 | gen_rtx_PLUS (Pmode, bottom_of_stack, | |
9908 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
9909 | emit_move_insn (gen_rtx_REG (Pmode, 2), mem); | |
9910 | ||
9911 | emit_label (no_toc_restore_needed); | |
9912 | do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1, | |
06f4e019 | 9913 | Pmode, NULL_RTX, NULL_RTX, |
9ebbca7d GK |
9914 | loop_exit); |
9915 | ||
9916 | mem = gen_rtx_MEM (Pmode, bottom_of_stack); | |
ba4828e0 | 9917 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
9918 | emit_move_insn (bottom_of_stack, mem); |
9919 | ||
9920 | mem = gen_rtx_MEM (Pmode, | |
9921 | gen_rtx_PLUS (Pmode, bottom_of_stack, | |
9922 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); | |
9923 | emit_move_insn (opcode_addr, mem); | |
9924 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); | |
9925 | ||
6496a589 | 9926 | emit_note (NULL, NOTE_INSN_LOOP_CONT); |
9ebbca7d | 9927 | emit_jump (loop_start); |
6496a589 | 9928 | emit_note (NULL, NOTE_INSN_LOOP_END); |
9ebbca7d GK |
9929 | emit_label (loop_exit); |
9930 | } | |
9931 | #endif /* TARGET_AIX */ | |
38c1f2d7 | 9932 | \f |
ba4828e0 RK |
9933 | /* This ties together stack memory (MEM with an alias set of |
9934 | rs6000_sr_alias_set) and the change to the stack pointer. */ | |
9935 | ||
9ebbca7d GK |
9936 | static void |
9937 | rs6000_emit_stack_tie () | |
9938 | { | |
ba4828e0 RK |
9939 | rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); |
9940 | ||
9941 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
9942 | emit_insn (gen_stack_tie (mem)); |
9943 | } | |
38c1f2d7 | 9944 | |
9ebbca7d GK |
9945 | /* Emit the correct code for allocating stack space, as insns. |
9946 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
9947 | The generated code may use hard register 0 as a temporary. */ | |
9948 | ||
9949 | static void | |
9950 | rs6000_emit_allocate_stack (size, copy_r12) | |
9951 | HOST_WIDE_INT size; | |
38c1f2d7 MM |
9952 | int copy_r12; |
9953 | { | |
9ebbca7d GK |
9954 | rtx insn; |
9955 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
9956 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
9957 | rtx todec = GEN_INT (-size); | |
a157febd GK |
9958 | |
9959 | if (current_function_limit_stack) | |
9960 | { | |
9961 | if (REG_P (stack_limit_rtx) | |
9962 | && REGNO (stack_limit_rtx) > 1 | |
9963 | && REGNO (stack_limit_rtx) <= 31) | |
9964 | { | |
5b71a4e7 | 9965 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
9966 | ? gen_addsi3 (tmp_reg, |
9967 | stack_limit_rtx, | |
9968 | GEN_INT (size)) | |
9969 | : gen_adddi3 (tmp_reg, | |
9970 | stack_limit_rtx, | |
9971 | GEN_INT (size))); | |
5b71a4e7 | 9972 | |
9ebbca7d GK |
9973 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, |
9974 | const0_rtx)); | |
a157febd GK |
9975 | } |
9976 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 9977 | && TARGET_32BIT |
f607bc57 | 9978 | && DEFAULT_ABI == ABI_V4) |
a157febd | 9979 | { |
9ebbca7d GK |
9980 | rtx toload = gen_rtx_CONST (VOIDmode, |
9981 | gen_rtx_PLUS (Pmode, | |
9982 | stack_limit_rtx, | |
9983 | GEN_INT (size))); | |
5b71a4e7 | 9984 | |
9ebbca7d GK |
9985 | emit_insn (gen_elf_high (tmp_reg, toload)); |
9986 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
9987 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
9988 | const0_rtx)); | |
a157febd GK |
9989 | } |
9990 | else | |
9991 | warning ("stack limit expression is not supported"); | |
9992 | } | |
9993 | ||
9ebbca7d GK |
9994 | if (copy_r12 || ! TARGET_UPDATE) |
9995 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
9996 | ||
38c1f2d7 MM |
9997 | if (TARGET_UPDATE) |
9998 | { | |
9ebbca7d | 9999 | if (size > 32767) |
38c1f2d7 | 10000 | { |
9ebbca7d GK |
10001 | /* Need a note here so that try_split doesn't get confused. */ |
10002 | if (get_last_insn() == NULL_RTX) | |
10003 | emit_note (0, NOTE_INSN_DELETED); | |
10004 | insn = emit_move_insn (tmp_reg, todec); | |
10005 | try_split (PATTERN (insn), insn, 0); | |
10006 | todec = tmp_reg; | |
38c1f2d7 | 10007 | } |
5b71a4e7 DE |
10008 | |
10009 | insn = emit_insn (TARGET_32BIT | |
10010 | ? gen_movsi_update (stack_reg, stack_reg, | |
10011 | todec, stack_reg) | |
10012 | : gen_movdi_update (stack_reg, stack_reg, | |
9ebbca7d | 10013 | todec, stack_reg)); |
38c1f2d7 MM |
10014 | } |
10015 | else | |
10016 | { | |
5b71a4e7 DE |
10017 | insn = emit_insn (TARGET_32BIT |
10018 | ? gen_addsi3 (stack_reg, stack_reg, todec) | |
10019 | : gen_adddi3 (stack_reg, stack_reg, todec)); | |
9ebbca7d GK |
10020 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), |
10021 | gen_rtx_REG (Pmode, 12)); | |
10022 | } | |
5b71a4e7 | 10023 | |
9ebbca7d GK |
10024 | RTX_FRAME_RELATED_P (insn) = 1; |
10025 | REG_NOTES (insn) = | |
10026 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
10027 | gen_rtx_SET (VOIDmode, stack_reg, | |
10028 | gen_rtx_PLUS (Pmode, stack_reg, | |
10029 | GEN_INT (-size))), | |
10030 | REG_NOTES (insn)); | |
10031 | } | |
10032 | ||
9aa86737 AH |
10033 | /* Add a RTX_FRAME_RELATED note so that dwarf2out_frame_debug_expr |
10034 | knows that: | |
10035 | ||
10036 | (mem (plus (blah) (regXX))) | |
10037 | ||
10038 | is really: | |
10039 | ||
10040 | (mem (plus (blah) (const VALUE_OF_REGXX))). */ | |
10041 | ||
10042 | static void | |
10043 | altivec_frame_fixup (insn, reg, val) | |
10044 | rtx insn, reg; | |
10045 | HOST_WIDE_INT val; | |
10046 | { | |
10047 | rtx real; | |
10048 | ||
10049 | real = copy_rtx (PATTERN (insn)); | |
10050 | ||
10051 | real = replace_rtx (real, reg, GEN_INT (val)); | |
10052 | ||
10053 | RTX_FRAME_RELATED_P (insn) = 1; | |
10054 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
10055 | real, | |
10056 | REG_NOTES (insn)); | |
10057 | } | |
10058 | ||
a4f6c312 SS |
10059 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced |
10060 | with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 | |
10061 | is not NULL. It would be nice if dwarf2out_frame_debug_expr could | |
10062 | deduce these equivalences by itself so it wasn't necessary to hold | |
10063 | its hand so much. */ | |
9ebbca7d GK |
10064 | |
10065 | static void | |
10066 | rs6000_frame_related (insn, reg, val, reg2, rreg) | |
10067 | rtx insn; | |
10068 | rtx reg; | |
10069 | HOST_WIDE_INT val; | |
10070 | rtx reg2; | |
10071 | rtx rreg; | |
10072 | { | |
10073 | rtx real, temp; | |
10074 | ||
e56c4463 JL |
10075 | /* copy_rtx will not make unique copies of registers, so we need to |
10076 | ensure we don't have unwanted sharing here. */ | |
10077 | if (reg == reg2) | |
10078 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
10079 | ||
10080 | if (reg == rreg) | |
10081 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
10082 | ||
9ebbca7d GK |
10083 | real = copy_rtx (PATTERN (insn)); |
10084 | ||
89e7058f AH |
10085 | if (reg2 != NULL_RTX) |
10086 | real = replace_rtx (real, reg2, rreg); | |
10087 | ||
9ebbca7d GK |
10088 | real = replace_rtx (real, reg, |
10089 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, | |
10090 | STACK_POINTER_REGNUM), | |
10091 | GEN_INT (val))); | |
10092 | ||
10093 | /* We expect that 'real' is either a SET or a PARALLEL containing | |
10094 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
10095 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
10096 | ||
10097 | if (GET_CODE (real) == SET) | |
10098 | { | |
10099 | rtx set = real; | |
10100 | ||
10101 | temp = simplify_rtx (SET_SRC (set)); | |
10102 | if (temp) | |
10103 | SET_SRC (set) = temp; | |
10104 | temp = simplify_rtx (SET_DEST (set)); | |
10105 | if (temp) | |
10106 | SET_DEST (set) = temp; | |
10107 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 10108 | { |
9ebbca7d GK |
10109 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
10110 | if (temp) | |
10111 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 10112 | } |
38c1f2d7 | 10113 | } |
9ebbca7d GK |
10114 | else if (GET_CODE (real) == PARALLEL) |
10115 | { | |
10116 | int i; | |
10117 | for (i = 0; i < XVECLEN (real, 0); i++) | |
10118 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
10119 | { | |
10120 | rtx set = XVECEXP (real, 0, i); | |
10121 | ||
10122 | temp = simplify_rtx (SET_SRC (set)); | |
10123 | if (temp) | |
10124 | SET_SRC (set) = temp; | |
10125 | temp = simplify_rtx (SET_DEST (set)); | |
10126 | if (temp) | |
10127 | SET_DEST (set) = temp; | |
10128 | if (GET_CODE (SET_DEST (set)) == MEM) | |
10129 | { | |
10130 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
10131 | if (temp) | |
10132 | XEXP (SET_DEST (set), 0) = temp; | |
10133 | } | |
10134 | RTX_FRAME_RELATED_P (set) = 1; | |
10135 | } | |
10136 | } | |
10137 | else | |
a4f6c312 | 10138 | abort (); |
9ebbca7d | 10139 | |
9ebbca7d GK |
10140 | RTX_FRAME_RELATED_P (insn) = 1; |
10141 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
10142 | real, | |
10143 | REG_NOTES (insn)); | |
38c1f2d7 MM |
10144 | } |
10145 | ||
00b960c7 AH |
10146 | /* Returns an insn that has a vrsave set operation with the |
10147 | appropriate CLOBBERs. */ | |
10148 | ||
10149 | static rtx | |
9aa86737 | 10150 | generate_set_vrsave (reg, info, epiloguep) |
00b960c7 AH |
10151 | rtx reg; |
10152 | rs6000_stack_t *info; | |
9aa86737 | 10153 | int epiloguep; |
00b960c7 AH |
10154 | { |
10155 | int nclobs, i; | |
10156 | rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1]; | |
a004eb82 | 10157 | rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
00b960c7 | 10158 | |
a004eb82 AH |
10159 | clobs[0] |
10160 | = gen_rtx_SET (VOIDmode, | |
10161 | vrsave, | |
10162 | gen_rtx_UNSPEC_VOLATILE (SImode, | |
10163 | gen_rtvec (2, reg, vrsave), | |
10164 | 30)); | |
00b960c7 AH |
10165 | |
10166 | nclobs = 1; | |
10167 | ||
9aa86737 AH |
10168 | /* We need to clobber the registers in the mask so the scheduler |
10169 | does not move sets to VRSAVE before sets of AltiVec registers. | |
10170 | ||
10171 | However, if the function receives nonlocal gotos, reload will set | |
10172 | all call saved registers live. We will end up with: | |
10173 | ||
10174 | (set (reg 999) (mem)) | |
10175 | (parallel [ (set (reg vrsave) (unspec blah)) | |
10176 | (clobber (reg 999))]) | |
10177 | ||
10178 | The clobber will cause the store into reg 999 to be dead, and | |
10179 | flow will attempt to delete an epilogue insn. In this case, we | |
10180 | need an unspec use/set of the register. */ | |
00b960c7 AH |
10181 | |
10182 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
10183 | if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0) | |
9aa86737 AH |
10184 | { |
10185 | if (!epiloguep || call_used_regs [i]) | |
10186 | clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode, | |
10187 | gen_rtx_REG (V4SImode, i)); | |
10188 | else | |
10189 | { | |
10190 | rtx reg = gen_rtx_REG (V4SImode, i); | |
9aa86737 AH |
10191 | |
10192 | clobs[nclobs++] | |
a004eb82 AH |
10193 | = gen_rtx_SET (VOIDmode, |
10194 | reg, | |
10195 | gen_rtx_UNSPEC (V4SImode, | |
10196 | gen_rtvec (1, reg), 27)); | |
9aa86737 AH |
10197 | } |
10198 | } | |
00b960c7 AH |
10199 | |
10200 | insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs)); | |
10201 | ||
10202 | for (i = 0; i < nclobs; ++i) | |
10203 | XVECEXP (insn, 0, i) = clobs[i]; | |
10204 | ||
10205 | return insn; | |
10206 | } | |
10207 | ||
89e7058f AH |
10208 | /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes. |
10209 | Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */ | |
10210 | ||
10211 | static void | |
10212 | emit_frame_save (frame_reg, frame_ptr, mode, regno, offset, total_size) | |
10213 | rtx frame_reg; | |
10214 | rtx frame_ptr; | |
10215 | enum machine_mode mode; | |
10216 | unsigned int regno; | |
10217 | int offset; | |
10218 | int total_size; | |
10219 | { | |
10220 | rtx reg, offset_rtx, insn, mem, addr, int_rtx; | |
10221 | rtx replacea, replaceb; | |
10222 | ||
10223 | int_rtx = GEN_INT (offset); | |
10224 | ||
10225 | /* Some cases that need register indexed addressing. */ | |
10226 | if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
a3170dc6 AH |
10227 | || (TARGET_SPE_ABI |
10228 | && SPE_VECTOR_MODE (mode) | |
10229 | && !SPE_CONST_OFFSET_OK (offset))) | |
89e7058f AH |
10230 | { |
10231 | /* Whomever calls us must make sure r11 is available in the | |
10232 | flow path of instructions in the prologue. */ | |
10233 | offset_rtx = gen_rtx_REG (Pmode, 11); | |
10234 | emit_move_insn (offset_rtx, int_rtx); | |
10235 | ||
10236 | replacea = offset_rtx; | |
10237 | replaceb = int_rtx; | |
10238 | } | |
10239 | else | |
10240 | { | |
10241 | offset_rtx = int_rtx; | |
10242 | replacea = NULL_RTX; | |
10243 | replaceb = NULL_RTX; | |
10244 | } | |
10245 | ||
10246 | reg = gen_rtx_REG (mode, regno); | |
10247 | addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx); | |
10248 | mem = gen_rtx_MEM (mode, addr); | |
10249 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10250 | ||
10251 | insn = emit_move_insn (mem, reg); | |
10252 | ||
10253 | rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb); | |
10254 | } | |
10255 | ||
a3170dc6 AH |
10256 | /* Emit an offset memory reference suitable for a frame store, while |
10257 | converting to a valid addressing mode. */ | |
10258 | ||
10259 | static rtx | |
10260 | gen_frame_mem_offset (mode, reg, offset) | |
10261 | enum machine_mode mode; | |
10262 | rtx reg; | |
10263 | int offset; | |
10264 | { | |
10265 | rtx int_rtx, offset_rtx; | |
10266 | ||
10267 | int_rtx = GEN_INT (offset); | |
10268 | ||
10269 | if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode)) | |
10270 | { | |
10271 | offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
10272 | emit_move_insn (offset_rtx, int_rtx); | |
10273 | } | |
10274 | else | |
10275 | offset_rtx = int_rtx; | |
10276 | ||
10277 | return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx)); | |
10278 | } | |
10279 | ||
9ebbca7d GK |
10280 | /* Emit function prologue as insns. */ |
10281 | ||
9878760c | 10282 | void |
83720594 | 10283 | rs6000_emit_prologue () |
9878760c | 10284 | { |
4697a36c | 10285 | rs6000_stack_t *info = rs6000_stack_info (); |
9ebbca7d GK |
10286 | enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode; |
10287 | int reg_size = TARGET_POWERPC64 ? 8 : 4; | |
10288 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
10289 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
10290 | rtx frame_reg_rtx = sp_reg_rtx; | |
10291 | rtx cr_save_rtx = NULL; | |
10292 | rtx insn; | |
10293 | int saving_FPRs_inline; | |
10294 | int using_store_multiple; | |
10295 | HOST_WIDE_INT sp_offset = 0; | |
10296 | ||
a3170dc6 AH |
10297 | if (TARGET_SPE_ABI) |
10298 | { | |
10299 | reg_mode = V2SImode; | |
10300 | reg_size = 8; | |
10301 | } | |
10302 | ||
9ebbca7d | 10303 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
a3170dc6 | 10304 | && !TARGET_SPE_ABI |
9ebbca7d GK |
10305 | && info->first_gp_reg_save < 31); |
10306 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
10307 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
10308 | ||
10309 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
f607bc57 | 10310 | if (info->push_p && DEFAULT_ABI == ABI_V4) |
9ebbca7d GK |
10311 | { |
10312 | if (info->total_size < 32767) | |
10313 | sp_offset = info->total_size; | |
10314 | else | |
10315 | frame_reg_rtx = frame_ptr_rtx; | |
10316 | rs6000_emit_allocate_stack (info->total_size, | |
10317 | (frame_reg_rtx != sp_reg_rtx | |
10318 | && (info->cr_save_p | |
10319 | || info->lr_save_p | |
10320 | || info->first_fp_reg_save < 64 | |
10321 | || info->first_gp_reg_save < 32 | |
10322 | ))); | |
10323 | if (frame_reg_rtx != sp_reg_rtx) | |
10324 | rs6000_emit_stack_tie (); | |
10325 | } | |
10326 | ||
9aa86737 AH |
10327 | /* Save AltiVec registers if needed. */ |
10328 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
10329 | { | |
10330 | int i; | |
10331 | ||
10332 | /* There should be a non inline version of this, for when we | |
10333 | are saving lots of vector registers. */ | |
10334 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
10335 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
10336 | { | |
10337 | rtx areg, savereg, mem; | |
10338 | int offset; | |
10339 | ||
10340 | offset = info->altivec_save_offset + sp_offset | |
10341 | + 16 * (i - info->first_altivec_reg_save); | |
10342 | ||
10343 | savereg = gen_rtx_REG (V4SImode, i); | |
10344 | ||
10345 | areg = gen_rtx_REG (Pmode, 0); | |
10346 | emit_move_insn (areg, GEN_INT (offset)); | |
10347 | ||
10348 | /* AltiVec addressing mode is [reg+reg]. */ | |
10349 | mem = gen_rtx_MEM (V4SImode, | |
10350 | gen_rtx_PLUS (Pmode, frame_reg_rtx, areg)); | |
10351 | ||
10352 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10353 | ||
10354 | insn = emit_move_insn (mem, savereg); | |
10355 | ||
10356 | altivec_frame_fixup (insn, areg, offset); | |
10357 | } | |
10358 | } | |
10359 | ||
10360 | /* VRSAVE is a bit vector representing which AltiVec registers | |
10361 | are used. The OS uses this to determine which vector | |
10362 | registers to save on a context switch. We need to save | |
10363 | VRSAVE on the stack frame, add whatever AltiVec registers we | |
10364 | used in this function, and do the corresponding magic in the | |
10365 | epilogue. */ | |
10366 | ||
10367 | if (TARGET_ALTIVEC && info->vrsave_mask != 0) | |
10368 | { | |
a004eb82 | 10369 | rtx reg, mem, vrsave; |
9aa86737 AH |
10370 | int offset; |
10371 | ||
10372 | /* Get VRSAVE onto a GPR. */ | |
10373 | reg = gen_rtx_REG (SImode, 12); | |
a004eb82 | 10374 | vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
b188f760 AH |
10375 | if (TARGET_MACHO) |
10376 | emit_insn (gen_get_vrsave_internal (reg)); | |
10377 | else | |
10378 | emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave)); | |
9aa86737 AH |
10379 | |
10380 | /* Save VRSAVE. */ | |
10381 | offset = info->vrsave_save_offset + sp_offset; | |
10382 | mem | |
10383 | = gen_rtx_MEM (SImode, | |
10384 | gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset))); | |
10385 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10386 | insn = emit_move_insn (mem, reg); | |
10387 | ||
10388 | /* Include the registers in the mask. */ | |
10389 | emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask))); | |
10390 | ||
10391 | insn = emit_insn (generate_set_vrsave (reg, info, 0)); | |
10392 | } | |
10393 | ||
9ebbca7d GK |
10394 | /* If we use the link register, get it into r0. */ |
10395 | if (info->lr_save_p) | |
71f123ca | 10396 | emit_move_insn (gen_rtx_REG (Pmode, 0), |
9ebbca7d GK |
10397 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); |
10398 | ||
10399 | /* If we need to save CR, put it into r12. */ | |
10400 | if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) | |
10401 | { | |
10402 | cr_save_rtx = gen_rtx_REG (SImode, 12); | |
10403 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
10404 | } | |
10405 | ||
a4f6c312 SS |
10406 | /* Do any required saving of fpr's. If only one or two to save, do |
10407 | it ourselves. Otherwise, call function. */ | |
9ebbca7d GK |
10408 | if (saving_FPRs_inline) |
10409 | { | |
10410 | int i; | |
10411 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
10412 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
10413 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
89e7058f AH |
10414 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode, |
10415 | info->first_fp_reg_save + i, | |
10416 | info->fp_save_offset + sp_offset + 8 * i, | |
10417 | info->total_size); | |
9ebbca7d GK |
10418 | } |
10419 | else if (info->first_fp_reg_save != 64) | |
10420 | { | |
10421 | int i; | |
10422 | char rname[30]; | |
520a57c8 | 10423 | const char *alloc_rname; |
9ebbca7d GK |
10424 | rtvec p; |
10425 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
10426 | ||
10427 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
10428 | gen_rtx_REG (Pmode, | |
10429 | LINK_REGISTER_REGNUM)); | |
10430 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
10431 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
a8a05998 | 10432 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
10433 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
10434 | gen_rtx_SYMBOL_REF (Pmode, | |
10435 | alloc_rname)); | |
10436 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
10437 | { | |
10438 | rtx addr, reg, mem; | |
10439 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
10440 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10441 | GEN_INT (info->fp_save_offset | |
10442 | + sp_offset + 8*i)); | |
10443 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 10444 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
10445 | |
10446 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
10447 | } | |
10448 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
10449 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
10450 | NULL_RTX, NULL_RTX); | |
10451 | } | |
b6c9286a | 10452 | |
9ebbca7d GK |
10453 | /* Save GPRs. This is done as a PARALLEL if we are using |
10454 | the store-multiple instructions. */ | |
10455 | if (using_store_multiple) | |
b6c9286a | 10456 | { |
308c142a | 10457 | rtvec p; |
9ebbca7d GK |
10458 | int i; |
10459 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
9ebbca7d GK |
10460 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) |
10461 | { | |
10462 | rtx addr, reg, mem; | |
10463 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
10464 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10465 | GEN_INT (info->gp_save_offset | |
10466 | + sp_offset | |
10467 | + reg_size * i)); | |
10468 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 10469 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
10470 | |
10471 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
10472 | } | |
10473 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
10474 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
10475 | NULL_RTX, NULL_RTX); | |
b6c9286a MM |
10476 | } |
10477 | else | |
10478 | { | |
9ebbca7d GK |
10479 | int i; |
10480 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
10481 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
10482 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
1db02437 | 10483 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
f607bc57 ZW |
10484 | && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
10485 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) | |
a3170dc6 AH |
10486 | { |
10487 | rtx addr, reg, mem; | |
10488 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
10489 | ||
10490 | if (TARGET_SPE_ABI) | |
10491 | { | |
10492 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
10493 | rtx b; | |
10494 | ||
10495 | if (!SPE_CONST_OFFSET_OK (offset)) | |
10496 | { | |
10497 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
10498 | emit_move_insn (b, GEN_INT (offset)); | |
10499 | } | |
10500 | else | |
10501 | b = GEN_INT (offset); | |
10502 | ||
10503 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
10504 | mem = gen_rtx_MEM (V2SImode, addr); | |
10505 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10506 | insn = emit_move_insn (mem, reg); | |
10507 | ||
10508 | if (GET_CODE (b) == CONST_INT) | |
10509 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
10510 | NULL_RTX, NULL_RTX); | |
10511 | else | |
10512 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
10513 | b, GEN_INT (offset)); | |
10514 | } | |
10515 | else | |
10516 | { | |
10517 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10518 | GEN_INT (info->gp_save_offset | |
10519 | + sp_offset | |
10520 | + reg_size * i)); | |
10521 | mem = gen_rtx_MEM (reg_mode, addr); | |
10522 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10523 | ||
10524 | insn = emit_move_insn (mem, reg); | |
10525 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
10526 | NULL_RTX, NULL_RTX); | |
10527 | } | |
10528 | } | |
9ebbca7d GK |
10529 | } |
10530 | ||
83720594 RH |
10531 | /* ??? There's no need to emit actual instructions here, but it's the |
10532 | easiest way to get the frame unwind information emitted. */ | |
10533 | if (current_function_calls_eh_return) | |
10534 | { | |
78e1b90d DE |
10535 | unsigned int i, regno; |
10536 | ||
83720594 RH |
10537 | for (i = 0; ; ++i) |
10538 | { | |
83720594 RH |
10539 | regno = EH_RETURN_DATA_REGNO (i); |
10540 | if (regno == INVALID_REGNUM) | |
10541 | break; | |
10542 | ||
89e7058f AH |
10543 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno, |
10544 | info->ehrd_offset + sp_offset | |
10545 | + reg_size * (int) i, | |
10546 | info->total_size); | |
83720594 RH |
10547 | } |
10548 | } | |
10549 | ||
9ebbca7d GK |
10550 | /* Save lr if we used it. */ |
10551 | if (info->lr_save_p) | |
10552 | { | |
10553 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10554 | GEN_INT (info->lr_save_offset + sp_offset)); | |
10555 | rtx reg = gen_rtx_REG (Pmode, 0); | |
10556 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
10557 | /* This should not be of rs6000_sr_alias_set, because of | |
10558 | __builtin_return_address. */ | |
10559 | ||
10560 | insn = emit_move_insn (mem, reg); | |
10561 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
10562 | reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
10563 | } | |
10564 | ||
10565 | /* Save CR if we use any that must be preserved. */ | |
10566 | if (info->cr_save_p) | |
10567 | { | |
10568 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10569 | GEN_INT (info->cr_save_offset + sp_offset)); | |
10570 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
10571 | |
10572 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
10573 | |
10574 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
10575 | that it's free. */ | |
10576 | if (REGNO (frame_reg_rtx) == 12) | |
10577 | { | |
10578 | cr_save_rtx = gen_rtx_REG (SImode, 0); | |
10579 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
10580 | } | |
10581 | insn = emit_move_insn (mem, cr_save_rtx); | |
10582 | ||
10583 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
10584 | to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's | |
10585 | OK. All we have to do is specify that _one_ condition code | |
10586 | register is saved in this stack slot. The thrower's epilogue | |
a1dc9455 FS |
10587 | will then restore all the call-saved registers. |
10588 | We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */ | |
9ebbca7d | 10589 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
a1dc9455 | 10590 | cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO)); |
9ebbca7d GK |
10591 | } |
10592 | ||
10593 | /* Update stack and set back pointer unless this is V.4, | |
10594 | for which it was done previously. */ | |
f607bc57 | 10595 | if (info->push_p && DEFAULT_ABI != ABI_V4) |
9ebbca7d GK |
10596 | rs6000_emit_allocate_stack (info->total_size, FALSE); |
10597 | ||
10598 | /* Set frame pointer, if needed. */ | |
10599 | if (frame_pointer_needed) | |
10600 | { | |
a3170dc6 | 10601 | insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM), |
9ebbca7d GK |
10602 | sp_reg_rtx); |
10603 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 10604 | } |
9878760c | 10605 | |
1db02437 | 10606 | /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
9ebbca7d | 10607 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) |
f607bc57 | 10608 | || (DEFAULT_ABI == ABI_V4 && flag_pic == 1 |
1db02437 | 10609 | && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])) |
9ebbca7d GK |
10610 | { |
10611 | /* If emit_load_toc_table will use the link register, we need to save | |
10612 | it. We use R11 for this purpose because emit_load_toc_table | |
10613 | can use register 0. This allows us to use a plain 'blr' to return | |
10614 | from the procedure more often. */ | |
d5fa86ba GK |
10615 | int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0 |
10616 | && ! info->lr_save_p | |
10617 | && EXIT_BLOCK_PTR->pred != NULL); | |
9ebbca7d GK |
10618 | if (save_LR_around_toc_setup) |
10619 | emit_move_insn (gen_rtx_REG (Pmode, 11), | |
10620 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
10621 | ||
10622 | rs6000_emit_load_toc_table (TRUE); | |
10623 | ||
10624 | if (save_LR_around_toc_setup) | |
10625 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), | |
10626 | gen_rtx_REG (Pmode, 11)); | |
10627 | } | |
ee890fe2 | 10628 | |
fcce224d | 10629 | #if TARGET_MACHO |
ee890fe2 SS |
10630 | if (DEFAULT_ABI == ABI_DARWIN |
10631 | && flag_pic && current_function_uses_pic_offset_table) | |
10632 | { | |
10633 | rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
f51eee6a GK |
10634 | char *picbase = machopic_function_base_name (); |
10635 | rtx src = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1)); | |
ee890fe2 | 10636 | |
f51eee6a | 10637 | rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src))); |
ee890fe2 SS |
10638 | |
10639 | rs6000_maybe_dead ( | |
1db02437 | 10640 | emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM), |
ee890fe2 SS |
10641 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM))); |
10642 | } | |
fcce224d | 10643 | #endif |
9ebbca7d GK |
10644 | } |
10645 | ||
9ebbca7d | 10646 | /* Write function prologue. */ |
a4f6c312 | 10647 | |
08c148a8 NB |
10648 | static void |
10649 | rs6000_output_function_prologue (file, size) | |
9ebbca7d | 10650 | FILE *file; |
08c148a8 | 10651 | HOST_WIDE_INT size ATTRIBUTE_UNUSED; |
9ebbca7d GK |
10652 | { |
10653 | rs6000_stack_t *info = rs6000_stack_info (); | |
10654 | ||
4697a36c MM |
10655 | if (TARGET_DEBUG_STACK) |
10656 | debug_stack_info (info); | |
9878760c | 10657 | |
a4f6c312 SS |
10658 | /* Write .extern for any function we will call to save and restore |
10659 | fp values. */ | |
10660 | if (info->first_fp_reg_save < 64 | |
10661 | && !FP_SAVE_INLINE (info->first_fp_reg_save)) | |
4d30c363 | 10662 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c | 10663 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
a4f6c312 SS |
10664 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, |
10665 | RESTORE_FP_SUFFIX); | |
9878760c | 10666 | |
c764f757 RK |
10667 | /* Write .extern for AIX common mode routines, if needed. */ |
10668 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
10669 | { | |
f6709c70 JW |
10670 | fputs ("\t.extern __mulh\n", file); |
10671 | fputs ("\t.extern __mull\n", file); | |
10672 | fputs ("\t.extern __divss\n", file); | |
10673 | fputs ("\t.extern __divus\n", file); | |
10674 | fputs ("\t.extern __quoss\n", file); | |
10675 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
10676 | common_mode_defined = 1; |
10677 | } | |
9878760c | 10678 | |
9ebbca7d | 10679 | if (! HAVE_prologue) |
979721f8 | 10680 | { |
9ebbca7d | 10681 | start_sequence (); |
9dda4cc8 | 10682 | |
a4f6c312 SS |
10683 | /* A NOTE_INSN_DELETED is supposed to be at the start and end of |
10684 | the "toplevel" insn chain. */ | |
9ebbca7d GK |
10685 | emit_note (0, NOTE_INSN_DELETED); |
10686 | rs6000_emit_prologue (); | |
10687 | emit_note (0, NOTE_INSN_DELETED); | |
178c3eff DJ |
10688 | |
10689 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ | |
10690 | { | |
10691 | rtx insn; | |
10692 | unsigned addr = 0; | |
10693 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
10694 | { | |
10695 | INSN_ADDRESSES_NEW (insn, addr); | |
10696 | addr += 4; | |
10697 | } | |
10698 | } | |
9dda4cc8 | 10699 | |
9ebbca7d | 10700 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
10701 | debug_rtx_list (get_insns (), 100); |
10702 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 10703 | end_sequence (); |
979721f8 MM |
10704 | } |
10705 | ||
9ebbca7d GK |
10706 | rs6000_pic_labelno++; |
10707 | } | |
10708 | ||
10709 | /* Emit function epilogue as insns. | |
9878760c | 10710 | |
9ebbca7d GK |
10711 | At present, dwarf2out_frame_debug_expr doesn't understand |
10712 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
10713 | anywhere in the epilogue. Most of the insns below would in any case | |
10714 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 10715 | |
9ebbca7d | 10716 | void |
83720594 | 10717 | rs6000_emit_epilogue (sibcall) |
9ebbca7d GK |
10718 | int sibcall; |
10719 | { | |
10720 | rs6000_stack_t *info; | |
10721 | int restoring_FPRs_inline; | |
10722 | int using_load_multiple; | |
10723 | int using_mfcr_multiple; | |
10724 | int use_backchain_to_restore_sp; | |
10725 | int sp_offset = 0; | |
10726 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
10727 | rtx frame_reg_rtx = sp_reg_rtx; | |
10728 | enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode; | |
10729 | int reg_size = TARGET_POWERPC64 ? 8 : 4; | |
10730 | int i; | |
10731 | ||
a3170dc6 AH |
10732 | if (TARGET_SPE_ABI) |
10733 | { | |
10734 | reg_mode = V2SImode; | |
10735 | reg_size = 8; | |
10736 | } | |
10737 | ||
9ebbca7d GK |
10738 | info = rs6000_stack_info (); |
10739 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 | |
a3170dc6 | 10740 | && !TARGET_SPE_ABI |
9ebbca7d GK |
10741 | && info->first_gp_reg_save < 31); |
10742 | restoring_FPRs_inline = (sibcall | |
83720594 | 10743 | || current_function_calls_eh_return |
9ebbca7d GK |
10744 | || info->first_fp_reg_save == 64 |
10745 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
10746 | use_backchain_to_restore_sp = (frame_pointer_needed | |
10747 | || current_function_calls_alloca | |
10748 | || info->total_size > 32767); | |
10749 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
10750 | || rs6000_cpu == PROCESSOR_PPC603 | |
10751 | || rs6000_cpu == PROCESSOR_PPC750 | |
10752 | || optimize_size); | |
10753 | ||
10754 | /* If we have a frame pointer, a call to alloca, or a large stack | |
10755 | frame, restore the old stack pointer using the backchain. Otherwise, | |
10756 | we know what size to update it with. */ | |
10757 | if (use_backchain_to_restore_sp) | |
bacbde18 | 10758 | { |
9ebbca7d GK |
10759 | /* Under V.4, don't reset the stack pointer until after we're done |
10760 | loading the saved registers. */ | |
f607bc57 | 10761 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d | 10762 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); |
4697a36c | 10763 | |
9ebbca7d GK |
10764 | emit_move_insn (frame_reg_rtx, |
10765 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
10766 | ||
bacbde18 | 10767 | } |
9ebbca7d | 10768 | else if (info->push_p) |
85638c0d | 10769 | { |
f607bc57 | 10770 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d GK |
10771 | sp_offset = info->total_size; |
10772 | else | |
10773 | { | |
10774 | emit_insn (TARGET_32BIT | |
10775 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
10776 | GEN_INT (info->total_size)) | |
10777 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
10778 | GEN_INT (info->total_size))); | |
10779 | } | |
85638c0d | 10780 | } |
9ebbca7d | 10781 | |
9aa86737 AH |
10782 | /* Restore AltiVec registers if needed. */ |
10783 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
10784 | { | |
10785 | int i; | |
10786 | ||
10787 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
10788 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
10789 | { | |
10790 | rtx addr, areg, mem; | |
10791 | ||
10792 | areg = gen_rtx_REG (Pmode, 0); | |
10793 | emit_move_insn | |
10794 | (areg, GEN_INT (info->altivec_save_offset | |
10795 | + sp_offset | |
10796 | + 16 * (i - info->first_altivec_reg_save))); | |
10797 | ||
10798 | /* AltiVec addressing mode is [reg+reg]. */ | |
10799 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
10800 | mem = gen_rtx_MEM (V4SImode, addr); | |
10801 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10802 | ||
10803 | emit_move_insn (gen_rtx_REG (V4SImode, i), mem); | |
10804 | } | |
10805 | } | |
10806 | ||
10807 | /* Restore VRSAVE if needed. */ | |
10808 | if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0) | |
10809 | { | |
10810 | rtx addr, mem, reg; | |
10811 | ||
10812 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10813 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
10814 | mem = gen_rtx_MEM (SImode, addr); | |
10815 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
10816 | reg = gen_rtx_REG (SImode, 12); | |
10817 | emit_move_insn (reg, mem); | |
10818 | ||
10819 | emit_insn (generate_set_vrsave (reg, info, 1)); | |
10820 | } | |
10821 | ||
9ebbca7d GK |
10822 | /* Get the old lr if we saved it. */ |
10823 | if (info->lr_save_p) | |
b6c9286a | 10824 | { |
a3170dc6 AH |
10825 | rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx, |
10826 | info->lr_save_offset + sp_offset); | |
ba4828e0 RK |
10827 | |
10828 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 10829 | |
9ebbca7d | 10830 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 10831 | } |
9ebbca7d GK |
10832 | |
10833 | /* Get the old cr if we saved it. */ | |
10834 | if (info->cr_save_p) | |
10835 | { | |
10836 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10837 | GEN_INT (info->cr_save_offset + sp_offset)); | |
10838 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
10839 | |
10840 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 10841 | |
9ebbca7d GK |
10842 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
10843 | } | |
10844 | ||
10845 | /* Set LR here to try to overlap restores below. */ | |
4697a36c | 10846 | if (info->lr_save_p) |
9ebbca7d GK |
10847 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
10848 | gen_rtx_REG (Pmode, 0)); | |
10849 | ||
83720594 RH |
10850 | /* Load exception handler data registers, if needed. */ |
10851 | if (current_function_calls_eh_return) | |
10852 | { | |
78e1b90d DE |
10853 | unsigned int i, regno; |
10854 | ||
83720594 RH |
10855 | for (i = 0; ; ++i) |
10856 | { | |
a3170dc6 | 10857 | rtx mem; |
83720594 RH |
10858 | |
10859 | regno = EH_RETURN_DATA_REGNO (i); | |
10860 | if (regno == INVALID_REGNUM) | |
10861 | break; | |
10862 | ||
a3170dc6 AH |
10863 | mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx, |
10864 | info->ehrd_offset + sp_offset | |
10865 | + reg_size * (int) i); | |
ba4828e0 | 10866 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
10867 | |
10868 | emit_move_insn (gen_rtx_REG (reg_mode, regno), mem); | |
10869 | } | |
10870 | } | |
9ebbca7d GK |
10871 | |
10872 | /* Restore GPRs. This is done as a PARALLEL if we are using | |
10873 | the load-multiple instructions. */ | |
10874 | if (using_load_multiple) | |
979721f8 | 10875 | { |
9ebbca7d GK |
10876 | rtvec p; |
10877 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
10878 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 10879 | { |
9ebbca7d GK |
10880 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
10881 | GEN_INT (info->gp_save_offset | |
10882 | + sp_offset | |
10883 | + reg_size * i)); | |
10884 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
10885 | |
10886 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
10887 | |
10888 | RTVEC_ELT (p, i) = | |
10889 | gen_rtx_SET (VOIDmode, | |
10890 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
10891 | mem); | |
979721f8 | 10892 | } |
9ebbca7d | 10893 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 10894 | } |
9ebbca7d GK |
10895 | else |
10896 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
10897 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
10898 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
1db02437 | 10899 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
f607bc57 ZW |
10900 | && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
10901 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) | |
9ebbca7d GK |
10902 | { |
10903 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10904 | GEN_INT (info->gp_save_offset | |
10905 | + sp_offset | |
10906 | + reg_size * i)); | |
10907 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 10908 | |
a3170dc6 AH |
10909 | /* Restore 64-bit quantities for SPE. */ |
10910 | if (TARGET_SPE_ABI) | |
10911 | { | |
10912 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
10913 | rtx b; | |
10914 | ||
10915 | if (!SPE_CONST_OFFSET_OK (offset)) | |
10916 | { | |
10917 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
10918 | emit_move_insn (b, GEN_INT (offset)); | |
10919 | } | |
10920 | else | |
10921 | b = GEN_INT (offset); | |
10922 | ||
10923 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
10924 | mem = gen_rtx_MEM (V2SImode, addr); | |
10925 | } | |
10926 | ||
ba4828e0 | 10927 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
10928 | |
10929 | emit_move_insn (gen_rtx_REG (reg_mode, | |
a3170dc6 | 10930 | info->first_gp_reg_save + i), mem); |
9ebbca7d | 10931 | } |
9878760c | 10932 | |
9ebbca7d GK |
10933 | /* Restore fpr's if we need to do it without calling a function. */ |
10934 | if (restoring_FPRs_inline) | |
10935 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
10936 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
10937 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
10938 | { | |
10939 | rtx addr, mem; | |
10940 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
10941 | GEN_INT (info->fp_save_offset | |
10942 | + sp_offset | |
a4f6c312 | 10943 | + 8 * i)); |
9ebbca7d | 10944 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 10945 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
10946 | |
10947 | emit_move_insn (gen_rtx_REG (DFmode, | |
10948 | info->first_fp_reg_save + i), | |
10949 | mem); | |
10950 | } | |
8d30c4ee | 10951 | |
9ebbca7d GK |
10952 | /* If we saved cr, restore it here. Just those that were used. */ |
10953 | if (info->cr_save_p) | |
979721f8 | 10954 | { |
9ebbca7d | 10955 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 10956 | int count = 0; |
9ebbca7d GK |
10957 | |
10958 | if (using_mfcr_multiple) | |
979721f8 | 10959 | { |
9ebbca7d GK |
10960 | for (i = 0; i < 8; i++) |
10961 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 10962 | count++; |
9ebbca7d | 10963 | if (count == 0) |
e35b9579 GK |
10964 | abort (); |
10965 | } | |
10966 | ||
10967 | if (using_mfcr_multiple && count > 1) | |
10968 | { | |
10969 | rtvec p; | |
10970 | int ndx; | |
9ebbca7d | 10971 | |
e35b9579 | 10972 | p = rtvec_alloc (count); |
9ebbca7d | 10973 | |
e35b9579 | 10974 | ndx = 0; |
9ebbca7d GK |
10975 | for (i = 0; i < 8; i++) |
10976 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
10977 | { | |
10978 | rtvec r = rtvec_alloc (2); | |
10979 | RTVEC_ELT (r, 0) = r12_rtx; | |
10980 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 10981 | RTVEC_ELT (p, ndx) = |
9ebbca7d GK |
10982 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
10983 | gen_rtx_UNSPEC (CCmode, r, 20)); | |
e35b9579 | 10984 | ndx++; |
9ebbca7d GK |
10985 | } |
10986 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
10987 | if (ndx != count) |
10988 | abort (); | |
979721f8 MM |
10989 | } |
10990 | else | |
9ebbca7d GK |
10991 | for (i = 0; i < 8; i++) |
10992 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 10993 | { |
9ebbca7d GK |
10994 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
10995 | CR0_REGNO+i), | |
10996 | r12_rtx)); | |
979721f8 | 10997 | } |
979721f8 MM |
10998 | } |
10999 | ||
9ebbca7d GK |
11000 | /* If this is V.4, unwind the stack pointer after all of the loads |
11001 | have been done. We need to emit a block here so that sched | |
11002 | doesn't decide to move the sp change before the register restores | |
11003 | (which may not have any obvious dependency on the stack). This | |
11004 | doesn't hurt performance, because there is no scheduling that can | |
11005 | be done after this point. */ | |
f607bc57 | 11006 | if (DEFAULT_ABI == ABI_V4) |
b6c9286a | 11007 | { |
9ebbca7d GK |
11008 | if (frame_reg_rtx != sp_reg_rtx) |
11009 | rs6000_emit_stack_tie (); | |
b6c9286a | 11010 | |
9ebbca7d | 11011 | if (use_backchain_to_restore_sp) |
b6c9286a | 11012 | { |
9ebbca7d | 11013 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 11014 | } |
9ebbca7d | 11015 | else if (sp_offset != 0) |
13f1623b | 11016 | { |
5b71a4e7 | 11017 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
11018 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, |
11019 | GEN_INT (sp_offset)) | |
11020 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
11021 | GEN_INT (sp_offset))); | |
13f1623b | 11022 | } |
9ebbca7d | 11023 | } |
b6c9286a | 11024 | |
83720594 RH |
11025 | if (current_function_calls_eh_return) |
11026 | { | |
11027 | rtx sa = EH_RETURN_STACKADJ_RTX; | |
5b71a4e7 | 11028 | emit_insn (TARGET_32BIT |
83720594 RH |
11029 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa) |
11030 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa)); | |
11031 | } | |
11032 | ||
9ebbca7d GK |
11033 | if (!sibcall) |
11034 | { | |
11035 | rtvec p; | |
11036 | if (! restoring_FPRs_inline) | |
11037 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
11038 | else | |
11039 | p = rtvec_alloc (2); | |
b6c9286a | 11040 | |
e35b9579 GK |
11041 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
11042 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
9ebbca7d GK |
11043 | gen_rtx_REG (Pmode, |
11044 | LINK_REGISTER_REGNUM)); | |
9ebbca7d GK |
11045 | |
11046 | /* If we have to restore more than two FP registers, branch to the | |
11047 | restore function. It will return to our caller. */ | |
11048 | if (! restoring_FPRs_inline) | |
11049 | { | |
11050 | int i; | |
11051 | char rname[30]; | |
520a57c8 | 11052 | const char *alloc_rname; |
979721f8 | 11053 | |
9ebbca7d GK |
11054 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
11055 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
a8a05998 | 11056 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
11057 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, |
11058 | gen_rtx_SYMBOL_REF (Pmode, | |
11059 | alloc_rname)); | |
b6c9286a | 11060 | |
9ebbca7d GK |
11061 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
11062 | { | |
11063 | rtx addr, mem; | |
11064 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
11065 | GEN_INT (info->fp_save_offset + 8*i)); | |
11066 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 11067 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
11068 | |
11069 | RTVEC_ELT (p, i+3) = | |
11070 | gen_rtx_SET (VOIDmode, | |
11071 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
11072 | mem); | |
b6c9286a MM |
11073 | } |
11074 | } | |
9ebbca7d GK |
11075 | |
11076 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
3daf36a4 | 11077 | } |
9878760c RK |
11078 | } |
11079 | ||
11080 | /* Write function epilogue. */ | |
11081 | ||
08c148a8 NB |
11082 | static void |
11083 | rs6000_output_function_epilogue (file, size) | |
9878760c | 11084 | FILE *file; |
08c148a8 | 11085 | HOST_WIDE_INT size ATTRIBUTE_UNUSED; |
9878760c | 11086 | { |
4697a36c | 11087 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 11088 | |
9ebbca7d | 11089 | if (! HAVE_epilogue) |
9878760c | 11090 | { |
9ebbca7d GK |
11091 | rtx insn = get_last_insn (); |
11092 | /* If the last insn was a BARRIER, we don't have to write anything except | |
11093 | the trace table. */ | |
11094 | if (GET_CODE (insn) == NOTE) | |
11095 | insn = prev_nonnote_insn (insn); | |
11096 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 11097 | { |
9ebbca7d GK |
11098 | /* This is slightly ugly, but at least we don't have two |
11099 | copies of the epilogue-emitting code. */ | |
11100 | start_sequence (); | |
11101 | ||
11102 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
11103 | and end of the "toplevel" insn chain. */ | |
11104 | emit_note (0, NOTE_INSN_DELETED); | |
11105 | rs6000_emit_epilogue (FALSE); | |
11106 | emit_note (0, NOTE_INSN_DELETED); | |
11107 | ||
178c3eff DJ |
11108 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
11109 | { | |
11110 | rtx insn; | |
11111 | unsigned addr = 0; | |
11112 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
11113 | { | |
11114 | INSN_ADDRESSES_NEW (insn, addr); | |
11115 | addr += 4; | |
11116 | } | |
11117 | } | |
11118 | ||
9ebbca7d | 11119 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
11120 | debug_rtx_list (get_insns (), 100); |
11121 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 11122 | end_sequence (); |
4697a36c | 11123 | } |
9878760c | 11124 | } |
b4ac57ab | 11125 | |
9b30bae2 | 11126 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
11127 | on its format. |
11128 | ||
11129 | We don't output a traceback table if -finhibit-size-directive was | |
11130 | used. The documentation for -finhibit-size-directive reads | |
11131 | ``don't output a @code{.size} assembler directive, or anything | |
11132 | else that would cause trouble if the function is split in the | |
11133 | middle, and the two halves are placed at locations far apart in | |
11134 | memory.'' The traceback table has this property, since it | |
11135 | includes the offset from the start of the function to the | |
4d30c363 MM |
11136 | traceback table itself. |
11137 | ||
11138 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a | 11139 | different traceback table. */ |
57ac7be9 AM |
11140 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive |
11141 | && rs6000_traceback != traceback_none) | |
9b30bae2 | 11142 | { |
69c75916 | 11143 | const char *fname = NULL; |
3ac88239 | 11144 | const char *language_string = lang_hooks.name; |
6041bf2f | 11145 | int fixed_parms = 0, float_parms = 0, parm_info = 0; |
314fc5a9 | 11146 | int i; |
57ac7be9 AM |
11147 | int optional_tbtab; |
11148 | ||
11149 | if (rs6000_traceback == traceback_full) | |
11150 | optional_tbtab = 1; | |
11151 | else if (rs6000_traceback == traceback_part) | |
11152 | optional_tbtab = 0; | |
11153 | else | |
11154 | optional_tbtab = !optimize_size && !TARGET_ELF; | |
314fc5a9 | 11155 | |
69c75916 AM |
11156 | if (optional_tbtab) |
11157 | { | |
11158 | fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
11159 | while (*fname == '.') /* V.4 encodes . in the name */ | |
11160 | fname++; | |
11161 | ||
11162 | /* Need label immediately before tbtab, so we can compute | |
11163 | its offset from the function start. */ | |
11164 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
11165 | ASM_OUTPUT_LABEL (file, fname); | |
11166 | } | |
314fc5a9 ILT |
11167 | |
11168 | /* The .tbtab pseudo-op can only be used for the first eight | |
11169 | expressions, since it can't handle the possibly variable | |
11170 | length fields that follow. However, if you omit the optional | |
11171 | fields, the assembler outputs zeros for all optional fields | |
11172 | anyways, giving each variable length field is minimum length | |
11173 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
11174 | pseudo-op at all. */ | |
11175 | ||
11176 | /* An all-zero word flags the start of the tbtab, for debuggers | |
11177 | that have to find it by searching forward from the entry | |
11178 | point or from the current pc. */ | |
19d2d16f | 11179 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
11180 | |
11181 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 11182 | fputs ("\t.byte 0,", file); |
314fc5a9 ILT |
11183 | |
11184 | /* Language type. Unfortunately, there doesn't seem to be any | |
11185 | official way to get this info, so we use language_string. C | |
11186 | is 0. C++ is 9. No number defined for Obj-C, so use the | |
9517ead8 | 11187 | value for C for now. There is no official value for Java, |
6f573ff9 | 11188 | although IBM appears to be using 13. There is no official value |
f710504c | 11189 | for Chill, so we've chosen 44 pseudo-randomly. */ |
314fc5a9 | 11190 | if (! strcmp (language_string, "GNU C") |
e2c953b6 | 11191 | || ! strcmp (language_string, "GNU Objective-C")) |
314fc5a9 ILT |
11192 | i = 0; |
11193 | else if (! strcmp (language_string, "GNU F77")) | |
11194 | i = 1; | |
11195 | else if (! strcmp (language_string, "GNU Ada")) | |
11196 | i = 3; | |
8b83775b | 11197 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 ILT |
11198 | i = 2; |
11199 | else if (! strcmp (language_string, "GNU C++")) | |
11200 | i = 9; | |
9517ead8 AG |
11201 | else if (! strcmp (language_string, "GNU Java")) |
11202 | i = 13; | |
6f573ff9 JL |
11203 | else if (! strcmp (language_string, "GNU CHILL")) |
11204 | i = 44; | |
314fc5a9 ILT |
11205 | else |
11206 | abort (); | |
11207 | fprintf (file, "%d,", i); | |
11208 | ||
11209 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
11210 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
11211 | from start of procedure stored in tbtab, internal function, function | |
11212 | has controlled storage, function has no toc, function uses fp, | |
11213 | function logs/aborts fp operations. */ | |
11214 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
6041bf2f DE |
11215 | fprintf (file, "%d,", |
11216 | (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1)); | |
314fc5a9 ILT |
11217 | |
11218 | /* 6 bitfields: function is interrupt handler, name present in | |
11219 | proc table, function calls alloca, on condition directives | |
11220 | (controls stack walks, 3 bits), saves condition reg, saves | |
11221 | link reg. */ | |
11222 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
11223 | set up as a frame pointer, even when there is no alloca call. */ | |
11224 | fprintf (file, "%d,", | |
6041bf2f DE |
11225 | ((optional_tbtab << 6) |
11226 | | ((optional_tbtab & frame_pointer_needed) << 5) | |
11227 | | (info->cr_save_p << 1) | |
11228 | | (info->lr_save_p))); | |
314fc5a9 | 11229 | |
6041bf2f | 11230 | /* 3 bitfields: saves backchain, fixup code, number of fpr saved |
314fc5a9 ILT |
11231 | (6 bits). */ |
11232 | fprintf (file, "%d,", | |
4697a36c | 11233 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
11234 | |
11235 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
11236 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
11237 | ||
6041bf2f DE |
11238 | if (optional_tbtab) |
11239 | { | |
11240 | /* Compute the parameter info from the function decl argument | |
11241 | list. */ | |
11242 | tree decl; | |
11243 | int next_parm_info_bit = 31; | |
314fc5a9 | 11244 | |
6041bf2f DE |
11245 | for (decl = DECL_ARGUMENTS (current_function_decl); |
11246 | decl; decl = TREE_CHAIN (decl)) | |
11247 | { | |
11248 | rtx parameter = DECL_INCOMING_RTL (decl); | |
11249 | enum machine_mode mode = GET_MODE (parameter); | |
314fc5a9 | 11250 | |
6041bf2f DE |
11251 | if (GET_CODE (parameter) == REG) |
11252 | { | |
11253 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
11254 | { | |
11255 | int bits; | |
11256 | ||
11257 | float_parms++; | |
11258 | ||
11259 | if (mode == SFmode) | |
11260 | bits = 0x2; | |
fcce224d | 11261 | else if (mode == DFmode || mode == TFmode) |
6041bf2f DE |
11262 | bits = 0x3; |
11263 | else | |
11264 | abort (); | |
11265 | ||
11266 | /* If only one bit will fit, don't or in this entry. */ | |
11267 | if (next_parm_info_bit > 0) | |
11268 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
11269 | next_parm_info_bit -= 2; | |
11270 | } | |
11271 | else | |
11272 | { | |
11273 | fixed_parms += ((GET_MODE_SIZE (mode) | |
11274 | + (UNITS_PER_WORD - 1)) | |
11275 | / UNITS_PER_WORD); | |
11276 | next_parm_info_bit -= 1; | |
11277 | } | |
11278 | } | |
11279 | } | |
11280 | } | |
314fc5a9 ILT |
11281 | |
11282 | /* Number of fixed point parameters. */ | |
11283 | /* This is actually the number of words of fixed point parameters; thus | |
11284 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
11285 | fprintf (file, "%d,", fixed_parms); | |
11286 | ||
11287 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
11288 | all on stack. */ | |
11289 | /* This is actually the number of fp registers that hold parameters; | |
11290 | and thus the maximum value is 13. */ | |
11291 | /* Set parameters on stack bit if parameters are not in their original | |
11292 | registers, regardless of whether they are on the stack? Xlc | |
11293 | seems to set the bit when not optimizing. */ | |
11294 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
11295 | ||
6041bf2f DE |
11296 | if (! optional_tbtab) |
11297 | return; | |
11298 | ||
314fc5a9 ILT |
11299 | /* Optional fields follow. Some are variable length. */ |
11300 | ||
11301 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
11302 | 11 double float. */ | |
11303 | /* There is an entry for each parameter in a register, in the order that | |
11304 | they occur in the parameter list. Any intervening arguments on the | |
11305 | stack are ignored. If the list overflows a long (max possible length | |
11306 | 34 bits) then completely leave off all elements that don't fit. */ | |
11307 | /* Only emit this long if there was at least one parameter. */ | |
11308 | if (fixed_parms || float_parms) | |
11309 | fprintf (file, "\t.long %d\n", parm_info); | |
11310 | ||
11311 | /* Offset from start of code to tb table. */ | |
19d2d16f | 11312 | fputs ("\t.long ", file); |
314fc5a9 | 11313 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
54ee9799 DE |
11314 | #if TARGET_AIX |
11315 | RS6000_OUTPUT_BASENAME (file, fname); | |
11316 | #else | |
9ebbca7d | 11317 | assemble_name (file, fname); |
54ee9799 | 11318 | #endif |
19d2d16f | 11319 | fputs ("-.", file); |
54ee9799 DE |
11320 | #if TARGET_AIX |
11321 | RS6000_OUTPUT_BASENAME (file, fname); | |
11322 | #else | |
9ebbca7d | 11323 | assemble_name (file, fname); |
54ee9799 | 11324 | #endif |
19d2d16f | 11325 | putc ('\n', file); |
314fc5a9 ILT |
11326 | |
11327 | /* Interrupt handler mask. */ | |
11328 | /* Omit this long, since we never set the interrupt handler bit | |
11329 | above. */ | |
11330 | ||
11331 | /* Number of CTL (controlled storage) anchors. */ | |
11332 | /* Omit this long, since the has_ctl bit is never set above. */ | |
11333 | ||
11334 | /* Displacement into stack of each CTL anchor. */ | |
11335 | /* Omit this list of longs, because there are no CTL anchors. */ | |
11336 | ||
11337 | /* Length of function name. */ | |
69c75916 AM |
11338 | if (*fname == '*') |
11339 | ++fname; | |
296b8152 | 11340 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
11341 | |
11342 | /* Function name. */ | |
11343 | assemble_string (fname, strlen (fname)); | |
11344 | ||
11345 | /* Register for alloca automatic storage; this is always reg 31. | |
11346 | Only emit this if the alloca bit was set above. */ | |
11347 | if (frame_pointer_needed) | |
19d2d16f | 11348 | fputs ("\t.byte 31\n", file); |
b1765bde DE |
11349 | |
11350 | fputs ("\t.align 2\n", file); | |
9b30bae2 | 11351 | } |
9878760c | 11352 | } |
17167fd8 | 11353 | \f |
a4f6c312 SS |
11354 | /* A C compound statement that outputs the assembler code for a thunk |
11355 | function, used to implement C++ virtual function calls with | |
11356 | multiple inheritance. The thunk acts as a wrapper around a virtual | |
11357 | function, adjusting the implicit object parameter before handing | |
11358 | control off to the real function. | |
11359 | ||
11360 | First, emit code to add the integer DELTA to the location that | |
11361 | contains the incoming first argument. Assume that this argument | |
11362 | contains a pointer, and is the one used to pass the `this' pointer | |
11363 | in C++. This is the incoming argument *before* the function | |
11364 | prologue, e.g. `%o0' on a sparc. The addition must preserve the | |
11365 | values of all other incoming arguments. | |
17167fd8 MM |
11366 | |
11367 | After the addition, emit code to jump to FUNCTION, which is a | |
a4f6c312 SS |
11368 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does |
11369 | not touch the return address. Hence returning from FUNCTION will | |
11370 | return to whoever called the current `thunk'. | |
17167fd8 | 11371 | |
a4f6c312 SS |
11372 | The effect must be as if FUNCTION had been called directly with the |
11373 | adjusted first argument. This macro is responsible for emitting | |
11374 | all of the code for a thunk function; output_function_prologue() | |
11375 | and output_function_epilogue() are not invoked. | |
17167fd8 | 11376 | |
a4f6c312 SS |
11377 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already |
11378 | been extracted from it.) It might possibly be useful on some | |
11379 | targets, but probably not. | |
17167fd8 | 11380 | |
a4f6c312 SS |
11381 | If you do not define this macro, the target-independent code in the |
11382 | C++ frontend will generate a less efficient heavyweight thunk that | |
11383 | calls FUNCTION instead of jumping to it. The generic approach does | |
11384 | not support varargs. */ | |
17167fd8 | 11385 | |
3961e8fe RH |
11386 | static void |
11387 | rs6000_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function) | |
17167fd8 | 11388 | FILE *file; |
d330fd93 | 11389 | tree thunk_fndecl ATTRIBUTE_UNUSED; |
eb0424da | 11390 | HOST_WIDE_INT delta; |
5b71a4e7 | 11391 | HOST_WIDE_INT vcall_offset; |
17167fd8 MM |
11392 | tree function; |
11393 | { | |
5b71a4e7 | 11394 | rtx this, insn, funexp; |
17167fd8 | 11395 | |
5b71a4e7 DE |
11396 | reload_completed = 1; |
11397 | no_new_pseudos = 1; | |
56a7189a | 11398 | |
5b71a4e7 DE |
11399 | /* Mark the end of the (empty) prologue. */ |
11400 | emit_note (NULL, NOTE_INSN_PROLOGUE_END); | |
17167fd8 | 11401 | |
5b71a4e7 DE |
11402 | /* Find the "this" pointer. If the function returns a structure, |
11403 | the structure return pointer is in r3. */ | |
11404 | if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)))) | |
11405 | this = gen_rtx_REG (Pmode, 4); | |
56a7189a | 11406 | else |
5b71a4e7 | 11407 | this = gen_rtx_REG (Pmode, 3); |
17167fd8 | 11408 | |
5b71a4e7 DE |
11409 | /* Apply the constant offset, if required. */ |
11410 | if (delta) | |
11411 | { | |
11412 | rtx delta_rtx = GEN_INT (delta); | |
11413 | emit_insn (TARGET_32BIT | |
11414 | ? gen_addsi3 (this, this, delta_rtx) | |
11415 | : gen_adddi3 (this, this, delta_rtx)); | |
17167fd8 MM |
11416 | } |
11417 | ||
5b71a4e7 DE |
11418 | /* Apply the offset from the vtable, if required. */ |
11419 | if (vcall_offset) | |
17167fd8 | 11420 | { |
5b71a4e7 DE |
11421 | rtx vcall_offset_rtx = GEN_INT (vcall_offset); |
11422 | rtx tmp = gen_rtx_REG (Pmode, 12); | |
17167fd8 | 11423 | |
5b71a4e7 DE |
11424 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, this)); |
11425 | emit_insn (TARGET_32BIT | |
11426 | ? gen_addsi3 (tmp, tmp, vcall_offset_rtx) | |
11427 | : gen_adddi3 (tmp, tmp, vcall_offset_rtx)); | |
11428 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
11429 | emit_insn (TARGET_32BIT | |
11430 | ? gen_addsi3 (this, this, tmp) | |
11431 | : gen_adddi3 (this, this, tmp)); | |
17167fd8 MM |
11432 | } |
11433 | ||
5b71a4e7 DE |
11434 | /* Generate a tail call to the target function. */ |
11435 | if (!TREE_USED (function)) | |
11436 | { | |
11437 | assemble_external (function); | |
11438 | TREE_USED (function) = 1; | |
11439 | } | |
11440 | funexp = XEXP (DECL_RTL (function), 0); | |
42820a49 | 11441 | |
5b71a4e7 DE |
11442 | SYMBOL_REF_FLAG (funexp) = 0; |
11443 | if (current_file_function_operand (funexp, VOIDmode) | |
a5c76ee6 ZW |
11444 | && (! lookup_attribute ("longcall", |
11445 | TYPE_ATTRIBUTES (TREE_TYPE (function))) | |
11446 | || lookup_attribute ("shortcall", | |
11447 | TYPE_ATTRIBUTES (TREE_TYPE (function))))) | |
5b71a4e7 | 11448 | SYMBOL_REF_FLAG (funexp) = 1; |
17167fd8 | 11449 | |
5b71a4e7 | 11450 | funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); |
ee890fe2 SS |
11451 | |
11452 | #if TARGET_MACHO | |
5b71a4e7 DE |
11453 | if (flag_pic) |
11454 | funexp = machopic_indirect_call_target (funexp); | |
ee890fe2 | 11455 | #endif |
5b71a4e7 DE |
11456 | |
11457 | /* gen_sibcall expects reload to convert scratch pseudo to LR so we must | |
11458 | generate sibcall RTL explicitly to avoid constraint abort. */ | |
11459 | insn = emit_call_insn ( | |
11460 | gen_rtx_PARALLEL (VOIDmode, | |
11461 | gen_rtvec (4, | |
11462 | gen_rtx_CALL (VOIDmode, | |
11463 | funexp, const0_rtx), | |
11464 | gen_rtx_USE (VOIDmode, const0_rtx), | |
11465 | gen_rtx_USE (VOIDmode, | |
11466 | gen_rtx_REG (SImode, | |
11467 | LINK_REGISTER_REGNUM)), | |
11468 | gen_rtx_RETURN (VOIDmode)))); | |
11469 | SIBLING_CALL_P (insn) = 1; | |
11470 | emit_barrier (); | |
11471 | ||
11472 | /* Run just enough of rest_of_compilation to get the insns emitted. | |
11473 | There's not really enough bulk here to make other passes such as | |
11474 | instruction scheduling worth while. Note that use_thunk calls | |
11475 | assemble_start_function and assemble_end_function. */ | |
11476 | insn = get_insns (); | |
11477 | shorten_branches (insn); | |
11478 | final_start_function (insn, file, 1); | |
11479 | final (insn, file, 1, 0); | |
11480 | final_end_function (); | |
11481 | ||
11482 | reload_completed = 0; | |
11483 | no_new_pseudos = 0; | |
9ebbca7d | 11484 | } |
9ebbca7d GK |
11485 | \f |
11486 | /* A quick summary of the various types of 'constant-pool tables' | |
11487 | under PowerPC: | |
11488 | ||
11489 | Target Flags Name One table per | |
11490 | AIX (none) AIX TOC object file | |
11491 | AIX -mfull-toc AIX TOC object file | |
11492 | AIX -mminimal-toc AIX minimal TOC translation unit | |
11493 | SVR4/EABI (none) SVR4 SDATA object file | |
11494 | SVR4/EABI -fpic SVR4 pic object file | |
11495 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
11496 | SVR4/EABI -mrelocatable EABI TOC function | |
11497 | SVR4/EABI -maix AIX TOC object file | |
11498 | SVR4/EABI -maix -mminimal-toc | |
11499 | AIX minimal TOC translation unit | |
11500 | ||
11501 | Name Reg. Set by entries contains: | |
11502 | made by addrs? fp? sum? | |
11503 | ||
11504 | AIX TOC 2 crt0 as Y option option | |
11505 | AIX minimal TOC 30 prolog gcc Y Y option | |
11506 | SVR4 SDATA 13 crt0 gcc N Y N | |
11507 | SVR4 pic 30 prolog ld Y not yet N | |
11508 | SVR4 PIC 30 prolog gcc Y option option | |
11509 | EABI TOC 30 prolog gcc Y option option | |
11510 | ||
11511 | */ | |
11512 | ||
9ebbca7d GK |
11513 | /* Hash functions for the hash table. */ |
11514 | ||
11515 | static unsigned | |
11516 | rs6000_hash_constant (k) | |
11517 | rtx k; | |
11518 | { | |
46b33600 RH |
11519 | enum rtx_code code = GET_CODE (k); |
11520 | enum machine_mode mode = GET_MODE (k); | |
11521 | unsigned result = (code << 3) ^ mode; | |
11522 | const char *format; | |
11523 | int flen, fidx; | |
9ebbca7d | 11524 | |
46b33600 RH |
11525 | format = GET_RTX_FORMAT (code); |
11526 | flen = strlen (format); | |
11527 | fidx = 0; | |
9ebbca7d | 11528 | |
46b33600 RH |
11529 | switch (code) |
11530 | { | |
11531 | case LABEL_REF: | |
11532 | return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0)); | |
11533 | ||
11534 | case CONST_DOUBLE: | |
11535 | if (mode != VOIDmode) | |
11536 | return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result; | |
11537 | flen = 2; | |
11538 | break; | |
11539 | ||
11540 | case CODE_LABEL: | |
11541 | fidx = 3; | |
11542 | break; | |
11543 | ||
11544 | default: | |
11545 | break; | |
11546 | } | |
9ebbca7d GK |
11547 | |
11548 | for (; fidx < flen; fidx++) | |
11549 | switch (format[fidx]) | |
11550 | { | |
11551 | case 's': | |
11552 | { | |
11553 | unsigned i, len; | |
11554 | const char *str = XSTR (k, fidx); | |
11555 | len = strlen (str); | |
11556 | result = result * 613 + len; | |
11557 | for (i = 0; i < len; i++) | |
11558 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
11559 | break; |
11560 | } | |
9ebbca7d GK |
11561 | case 'u': |
11562 | case 'e': | |
11563 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
11564 | break; | |
11565 | case 'i': | |
11566 | case 'n': | |
11567 | result = result * 613 + (unsigned) XINT (k, fidx); | |
11568 | break; | |
11569 | case 'w': | |
11570 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
11571 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
11572 | else | |
11573 | { | |
11574 | size_t i; | |
11575 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
11576 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
11577 | >> CHAR_BIT * i); | |
11578 | } | |
11579 | break; | |
11580 | default: | |
a4f6c312 | 11581 | abort (); |
9ebbca7d | 11582 | } |
46b33600 | 11583 | |
9ebbca7d GK |
11584 | return result; |
11585 | } | |
11586 | ||
11587 | static unsigned | |
11588 | toc_hash_function (hash_entry) | |
11589 | const void * hash_entry; | |
11590 | { | |
a9098fd0 GK |
11591 | const struct toc_hash_struct *thc = |
11592 | (const struct toc_hash_struct *) hash_entry; | |
11593 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
11594 | } |
11595 | ||
11596 | /* Compare H1 and H2 for equivalence. */ | |
11597 | ||
11598 | static int | |
11599 | toc_hash_eq (h1, h2) | |
11600 | const void * h1; | |
11601 | const void * h2; | |
11602 | { | |
11603 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
11604 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
11605 | ||
a9098fd0 GK |
11606 | if (((const struct toc_hash_struct *) h1)->key_mode |
11607 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
11608 | return 0; | |
11609 | ||
5692c7bc | 11610 | return rtx_equal_p (r1, r2); |
9ebbca7d GK |
11611 | } |
11612 | ||
28e510bd MM |
11613 | /* These are the names given by the C++ front-end to vtables, and |
11614 | vtable-like objects. Ideally, this logic should not be here; | |
11615 | instead, there should be some programmatic way of inquiring as | |
11616 | to whether or not an object is a vtable. */ | |
11617 | ||
11618 | #define VTABLE_NAME_P(NAME) \ | |
11619 | (strncmp ("_vt.", name, strlen("_vt.")) == 0 \ | |
11620 | || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \ | |
11621 | || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \ | |
11622 | || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0) | |
11623 | ||
11624 | void | |
11625 | rs6000_output_symbol_ref (file, x) | |
11626 | FILE *file; | |
11627 | rtx x; | |
11628 | { | |
11629 | /* Currently C++ toc references to vtables can be emitted before it | |
11630 | is decided whether the vtable is public or private. If this is | |
11631 | the case, then the linker will eventually complain that there is | |
11632 | a reference to an unknown section. Thus, for vtables only, | |
11633 | we emit the TOC reference to reference the symbol and not the | |
11634 | section. */ | |
11635 | const char *name = XSTR (x, 0); | |
54ee9799 DE |
11636 | |
11637 | if (VTABLE_NAME_P (name)) | |
11638 | { | |
11639 | RS6000_OUTPUT_BASENAME (file, name); | |
11640 | } | |
11641 | else | |
11642 | assemble_name (file, name); | |
28e510bd MM |
11643 | } |
11644 | ||
a4f6c312 SS |
11645 | /* Output a TOC entry. We derive the entry name from what is being |
11646 | written. */ | |
9878760c RK |
11647 | |
11648 | void | |
a9098fd0 | 11649 | output_toc (file, x, labelno, mode) |
9878760c RK |
11650 | FILE *file; |
11651 | rtx x; | |
11652 | int labelno; | |
a9098fd0 | 11653 | enum machine_mode mode; |
9878760c RK |
11654 | { |
11655 | char buf[256]; | |
3cce094d | 11656 | const char *name = buf; |
ec940faa | 11657 | const char *real_name; |
9878760c RK |
11658 | rtx base = x; |
11659 | int offset = 0; | |
11660 | ||
4697a36c MM |
11661 | if (TARGET_NO_TOC) |
11662 | abort (); | |
11663 | ||
9ebbca7d GK |
11664 | /* When the linker won't eliminate them, don't output duplicate |
11665 | TOC entries (this happens on AIX if there is any kind of TOC, | |
17211ab5 GK |
11666 | and on SVR4 under -fPIC or -mrelocatable). Don't do this for |
11667 | CODE_LABELs. */ | |
11668 | if (TARGET_TOC && GET_CODE (x) != LABEL_REF) | |
9ebbca7d GK |
11669 | { |
11670 | struct toc_hash_struct *h; | |
11671 | void * * found; | |
11672 | ||
17211ab5 GK |
11673 | /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS |
11674 | time because GGC is not initialised at that point. */ | |
11675 | if (toc_hash_table == NULL) | |
11676 | toc_hash_table = htab_create_ggc (1021, toc_hash_function, | |
11677 | toc_hash_eq, NULL); | |
11678 | ||
9ebbca7d GK |
11679 | h = ggc_alloc (sizeof (*h)); |
11680 | h->key = x; | |
a9098fd0 | 11681 | h->key_mode = mode; |
9ebbca7d GK |
11682 | h->labelno = labelno; |
11683 | ||
11684 | found = htab_find_slot (toc_hash_table, h, 1); | |
11685 | if (*found == NULL) | |
11686 | *found = h; | |
11687 | else /* This is indeed a duplicate. | |
11688 | Set this label equal to that label. */ | |
11689 | { | |
11690 | fputs ("\t.set ", file); | |
11691 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
11692 | fprintf (file, "%d,", labelno); | |
11693 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
11694 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) | |
11695 | found)->labelno)); | |
11696 | return; | |
11697 | } | |
11698 | } | |
11699 | ||
11700 | /* If we're going to put a double constant in the TOC, make sure it's | |
11701 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
11702 | if (GET_CODE (x) == CONST_DOUBLE |
11703 | && STRICT_ALIGNMENT | |
a9098fd0 | 11704 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
11705 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
11706 | ASM_OUTPUT_ALIGN (file, 3); | |
11707 | } | |
11708 | ||
4977bab6 | 11709 | (*targetm.asm_out.internal_label) (file, "LC", labelno); |
9878760c | 11710 | |
37c37a57 RK |
11711 | /* Handle FP constants specially. Note that if we have a minimal |
11712 | TOC, things we put here aren't actually in the TOC, so we can allow | |
11713 | FP constants. */ | |
fcce224d DE |
11714 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode) |
11715 | { | |
11716 | REAL_VALUE_TYPE rv; | |
11717 | long k[4]; | |
11718 | ||
11719 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
11720 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
11721 | ||
11722 | if (TARGET_64BIT) | |
11723 | { | |
11724 | if (TARGET_MINIMAL_TOC) | |
11725 | fputs (DOUBLE_INT_ASM_OP, file); | |
11726 | else | |
11727 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
11728 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
11729 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
11730 | fprintf (file, "0x%lx%08lx,0x%lx%08lx\n", | |
11731 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
11732 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
11733 | return; | |
11734 | } | |
11735 | else | |
11736 | { | |
11737 | if (TARGET_MINIMAL_TOC) | |
11738 | fputs ("\t.long ", file); | |
11739 | else | |
11740 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
11741 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
11742 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
11743 | fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n", | |
11744 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
11745 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
11746 | return; | |
11747 | } | |
11748 | } | |
11749 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) | |
9878760c | 11750 | { |
042259f2 DE |
11751 | REAL_VALUE_TYPE rv; |
11752 | long k[2]; | |
0adc764e | 11753 | |
042259f2 DE |
11754 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
11755 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 11756 | |
13ded975 DE |
11757 | if (TARGET_64BIT) |
11758 | { | |
11759 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11760 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 11761 | else |
2f0552b6 AM |
11762 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
11763 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
11764 | fprintf (file, "0x%lx%08lx\n", | |
11765 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
11766 | return; |
11767 | } | |
1875cc88 | 11768 | else |
13ded975 DE |
11769 | { |
11770 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11771 | fputs ("\t.long ", file); |
13ded975 | 11772 | else |
2f0552b6 AM |
11773 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
11774 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
11775 | fprintf (file, "0x%lx,0x%lx\n", | |
11776 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
11777 | return; |
11778 | } | |
9878760c | 11779 | } |
a9098fd0 | 11780 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 11781 | { |
042259f2 DE |
11782 | REAL_VALUE_TYPE rv; |
11783 | long l; | |
9878760c | 11784 | |
042259f2 DE |
11785 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
11786 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
11787 | ||
31bfaa0b DE |
11788 | if (TARGET_64BIT) |
11789 | { | |
11790 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11791 | fputs (DOUBLE_INT_ASM_OP, file); |
31bfaa0b | 11792 | else |
2f0552b6 AM |
11793 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
11794 | fprintf (file, "0x%lx00000000\n", l & 0xffffffff); | |
31bfaa0b DE |
11795 | return; |
11796 | } | |
042259f2 | 11797 | else |
31bfaa0b DE |
11798 | { |
11799 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11800 | fputs ("\t.long ", file); |
31bfaa0b | 11801 | else |
2f0552b6 AM |
11802 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
11803 | fprintf (file, "0x%lx\n", l & 0xffffffff); | |
31bfaa0b DE |
11804 | return; |
11805 | } | |
042259f2 | 11806 | } |
f176e826 | 11807 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 11808 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 11809 | { |
e2c953b6 | 11810 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
11811 | HOST_WIDE_INT high; |
11812 | ||
11813 | if (GET_CODE (x) == CONST_DOUBLE) | |
11814 | { | |
11815 | low = CONST_DOUBLE_LOW (x); | |
11816 | high = CONST_DOUBLE_HIGH (x); | |
11817 | } | |
11818 | else | |
11819 | #if HOST_BITS_PER_WIDE_INT == 32 | |
11820 | { | |
11821 | low = INTVAL (x); | |
0858c623 | 11822 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
11823 | } |
11824 | #else | |
11825 | { | |
0858c623 | 11826 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
11827 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
11828 | } | |
11829 | #endif | |
9878760c | 11830 | |
a9098fd0 GK |
11831 | /* TOC entries are always Pmode-sized, but since this |
11832 | is a bigendian machine then if we're putting smaller | |
11833 | integer constants in the TOC we have to pad them. | |
11834 | (This is still a win over putting the constants in | |
11835 | a separate constant pool, because then we'd have | |
02a4ec28 FS |
11836 | to have both a TOC entry _and_ the actual constant.) |
11837 | ||
11838 | For a 32-bit target, CONST_INT values are loaded and shifted | |
11839 | entirely within `low' and can be stored in one TOC entry. */ | |
11840 | ||
11841 | if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
a9098fd0 | 11842 | abort ();/* It would be easy to make this work, but it doesn't now. */ |
02a4ec28 FS |
11843 | |
11844 | if (POINTER_SIZE > GET_MODE_BITSIZE (mode)) | |
fb52d8de AM |
11845 | { |
11846 | #if HOST_BITS_PER_WIDE_INT == 32 | |
11847 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), | |
11848 | POINTER_SIZE, &low, &high, 0); | |
11849 | #else | |
11850 | low |= high << 32; | |
11851 | low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode); | |
11852 | high = (HOST_WIDE_INT) low >> 32; | |
11853 | low &= 0xffffffff; | |
11854 | #endif | |
11855 | } | |
a9098fd0 | 11856 | |
13ded975 DE |
11857 | if (TARGET_64BIT) |
11858 | { | |
11859 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11860 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 11861 | else |
2f0552b6 AM |
11862 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
11863 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
11864 | fprintf (file, "0x%lx%08lx\n", | |
11865 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13ded975 DE |
11866 | return; |
11867 | } | |
1875cc88 | 11868 | else |
13ded975 | 11869 | { |
02a4ec28 FS |
11870 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) |
11871 | { | |
11872 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11873 | fputs ("\t.long ", file); |
02a4ec28 | 11874 | else |
2bfcf297 | 11875 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
2f0552b6 AM |
11876 | (long) high & 0xffffffff, (long) low & 0xffffffff); |
11877 | fprintf (file, "0x%lx,0x%lx\n", | |
11878 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
02a4ec28 | 11879 | } |
13ded975 | 11880 | else |
02a4ec28 FS |
11881 | { |
11882 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 11883 | fputs ("\t.long ", file); |
02a4ec28 | 11884 | else |
2f0552b6 AM |
11885 | fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff); |
11886 | fprintf (file, "0x%lx\n", (long) low & 0xffffffff); | |
02a4ec28 | 11887 | } |
13ded975 DE |
11888 | return; |
11889 | } | |
9878760c RK |
11890 | } |
11891 | ||
11892 | if (GET_CODE (x) == CONST) | |
11893 | { | |
2bfcf297 DB |
11894 | if (GET_CODE (XEXP (x, 0)) != PLUS) |
11895 | abort (); | |
11896 | ||
9878760c RK |
11897 | base = XEXP (XEXP (x, 0), 0); |
11898 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
11899 | } | |
11900 | ||
11901 | if (GET_CODE (base) == SYMBOL_REF) | |
11902 | name = XSTR (base, 0); | |
11903 | else if (GET_CODE (base) == LABEL_REF) | |
11904 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
11905 | else if (GET_CODE (base) == CODE_LABEL) | |
11906 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
11907 | else | |
11908 | abort (); | |
11909 | ||
772c5265 | 11910 | real_name = (*targetm.strip_name_encoding) (name); |
1875cc88 | 11911 | if (TARGET_MINIMAL_TOC) |
2bfcf297 | 11912 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); |
1875cc88 JW |
11913 | else |
11914 | { | |
b6c9286a | 11915 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 11916 | |
1875cc88 JW |
11917 | if (offset < 0) |
11918 | fprintf (file, ".N%d", - offset); | |
11919 | else if (offset) | |
11920 | fprintf (file, ".P%d", offset); | |
9878760c | 11921 | |
19d2d16f | 11922 | fputs ("[TC],", file); |
1875cc88 | 11923 | } |
581bc4de MM |
11924 | |
11925 | /* Currently C++ toc references to vtables can be emitted before it | |
11926 | is decided whether the vtable is public or private. If this is | |
11927 | the case, then the linker will eventually complain that there is | |
11928 | a TOC reference to an unknown section. Thus, for vtables only, | |
11929 | we emit the TOC reference to reference the symbol and not the | |
11930 | section. */ | |
28e510bd | 11931 | if (VTABLE_NAME_P (name)) |
581bc4de | 11932 | { |
54ee9799 | 11933 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
11934 | if (offset < 0) |
11935 | fprintf (file, "%d", offset); | |
11936 | else if (offset > 0) | |
11937 | fprintf (file, "+%d", offset); | |
11938 | } | |
11939 | else | |
11940 | output_addr_const (file, x); | |
19d2d16f | 11941 | putc ('\n', file); |
9878760c RK |
11942 | } |
11943 | \f | |
11944 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
11945 | starting at P to FILE. | |
11946 | ||
11947 | On the RS/6000, we have to do this using the .byte operation and | |
11948 | write out special characters outside the quoted string. | |
11949 | Also, the assembler is broken; very long strings are truncated, | |
a4f6c312 | 11950 | so we must artificially break them up early. */ |
9878760c RK |
11951 | |
11952 | void | |
11953 | output_ascii (file, p, n) | |
11954 | FILE *file; | |
d330fd93 | 11955 | const char *p; |
9878760c RK |
11956 | int n; |
11957 | { | |
11958 | char c; | |
11959 | int i, count_string; | |
d330fd93 KG |
11960 | const char *for_string = "\t.byte \""; |
11961 | const char *for_decimal = "\t.byte "; | |
11962 | const char *to_close = NULL; | |
9878760c RK |
11963 | |
11964 | count_string = 0; | |
11965 | for (i = 0; i < n; i++) | |
11966 | { | |
11967 | c = *p++; | |
11968 | if (c >= ' ' && c < 0177) | |
11969 | { | |
11970 | if (for_string) | |
11971 | fputs (for_string, file); | |
11972 | putc (c, file); | |
11973 | ||
11974 | /* Write two quotes to get one. */ | |
11975 | if (c == '"') | |
11976 | { | |
11977 | putc (c, file); | |
11978 | ++count_string; | |
11979 | } | |
11980 | ||
11981 | for_string = NULL; | |
11982 | for_decimal = "\"\n\t.byte "; | |
11983 | to_close = "\"\n"; | |
11984 | ++count_string; | |
11985 | ||
11986 | if (count_string >= 512) | |
11987 | { | |
11988 | fputs (to_close, file); | |
11989 | ||
11990 | for_string = "\t.byte \""; | |
11991 | for_decimal = "\t.byte "; | |
11992 | to_close = NULL; | |
11993 | count_string = 0; | |
11994 | } | |
11995 | } | |
11996 | else | |
11997 | { | |
11998 | if (for_decimal) | |
11999 | fputs (for_decimal, file); | |
12000 | fprintf (file, "%d", c); | |
12001 | ||
12002 | for_string = "\n\t.byte \""; | |
12003 | for_decimal = ", "; | |
12004 | to_close = "\n"; | |
12005 | count_string = 0; | |
12006 | } | |
12007 | } | |
12008 | ||
12009 | /* Now close the string if we have written one. Then end the line. */ | |
12010 | if (to_close) | |
9ebbca7d | 12011 | fputs (to_close, file); |
9878760c RK |
12012 | } |
12013 | \f | |
12014 | /* Generate a unique section name for FILENAME for a section type | |
12015 | represented by SECTION_DESC. Output goes into BUF. | |
12016 | ||
12017 | SECTION_DESC can be any string, as long as it is different for each | |
12018 | possible section type. | |
12019 | ||
12020 | We name the section in the same manner as xlc. The name begins with an | |
12021 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
12022 | names) with the last period replaced by the string SECTION_DESC. If |
12023 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
12024 | the name. */ | |
9878760c RK |
12025 | |
12026 | void | |
12027 | rs6000_gen_section_name (buf, filename, section_desc) | |
12028 | char **buf; | |
9ebbca7d GK |
12029 | const char *filename; |
12030 | const char *section_desc; | |
9878760c | 12031 | { |
9ebbca7d | 12032 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
12033 | char *p; |
12034 | int len; | |
9878760c RK |
12035 | |
12036 | after_last_slash = filename; | |
12037 | for (q = filename; *q; q++) | |
11e5fe42 RK |
12038 | { |
12039 | if (*q == '/') | |
12040 | after_last_slash = q + 1; | |
12041 | else if (*q == '.') | |
12042 | last_period = q; | |
12043 | } | |
9878760c | 12044 | |
11e5fe42 | 12045 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
6d9f628e | 12046 | *buf = (char *) xmalloc (len); |
9878760c RK |
12047 | |
12048 | p = *buf; | |
12049 | *p++ = '_'; | |
12050 | ||
12051 | for (q = after_last_slash; *q; q++) | |
12052 | { | |
11e5fe42 | 12053 | if (q == last_period) |
9878760c RK |
12054 | { |
12055 | strcpy (p, section_desc); | |
12056 | p += strlen (section_desc); | |
e3981aab | 12057 | break; |
9878760c RK |
12058 | } |
12059 | ||
e9a780ec | 12060 | else if (ISALNUM (*q)) |
9878760c RK |
12061 | *p++ = *q; |
12062 | } | |
12063 | ||
11e5fe42 | 12064 | if (last_period == 0) |
9878760c RK |
12065 | strcpy (p, section_desc); |
12066 | else | |
12067 | *p = '\0'; | |
12068 | } | |
e165f3f0 | 12069 | \f |
a4f6c312 | 12070 | /* Emit profile function. */ |
411707f4 | 12071 | |
411707f4 CC |
12072 | void |
12073 | output_profile_hook (labelno) | |
57ac7be9 | 12074 | int labelno ATTRIBUTE_UNUSED; |
411707f4 | 12075 | { |
8480e480 CC |
12076 | if (DEFAULT_ABI == ABI_AIX) |
12077 | { | |
57ac7be9 AM |
12078 | #ifdef NO_PROFILE_COUNTERS |
12079 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0); | |
12080 | #else | |
8480e480 | 12081 | char buf[30]; |
40501e5f | 12082 | const char *label_name; |
8480e480 | 12083 | rtx fun; |
411707f4 | 12084 | |
8480e480 | 12085 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
772c5265 | 12086 | label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf)); |
8480e480 | 12087 | fun = gen_rtx_SYMBOL_REF (Pmode, label_name); |
411707f4 | 12088 | |
8480e480 CC |
12089 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1, |
12090 | fun, Pmode); | |
57ac7be9 | 12091 | #endif |
8480e480 | 12092 | } |
ee890fe2 SS |
12093 | else if (DEFAULT_ABI == ABI_DARWIN) |
12094 | { | |
d5fa86ba | 12095 | const char *mcount_name = RS6000_MCOUNT; |
ee890fe2 SS |
12096 | int caller_addr_regno = LINK_REGISTER_REGNUM; |
12097 | ||
12098 | /* Be conservative and always set this, at least for now. */ | |
12099 | current_function_uses_pic_offset_table = 1; | |
12100 | ||
12101 | #if TARGET_MACHO | |
12102 | /* For PIC code, set up a stub and collect the caller's address | |
12103 | from r0, which is where the prologue puts it. */ | |
12104 | if (flag_pic) | |
12105 | { | |
12106 | mcount_name = machopic_stub_name (mcount_name); | |
12107 | if (current_function_uses_pic_offset_table) | |
12108 | caller_addr_regno = 0; | |
12109 | } | |
12110 | #endif | |
12111 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name), | |
12112 | 0, VOIDmode, 1, | |
12113 | gen_rtx_REG (Pmode, caller_addr_regno), Pmode); | |
12114 | } | |
411707f4 CC |
12115 | } |
12116 | ||
a4f6c312 | 12117 | /* Write function profiler code. */ |
e165f3f0 RK |
12118 | |
12119 | void | |
12120 | output_function_profiler (file, labelno) | |
12121 | FILE *file; | |
12122 | int labelno; | |
12123 | { | |
3daf36a4 | 12124 | char buf[100]; |
09eeeacb | 12125 | int save_lr = 8; |
e165f3f0 | 12126 | |
3daf36a4 | 12127 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 | 12128 | switch (DEFAULT_ABI) |
3daf36a4 | 12129 | { |
38c1f2d7 MM |
12130 | default: |
12131 | abort (); | |
12132 | ||
12133 | case ABI_V4: | |
09eeeacb AM |
12134 | save_lr = 4; |
12135 | /* Fall through. */ | |
12136 | ||
38c1f2d7 | 12137 | case ABI_AIX_NODESC: |
09eeeacb AM |
12138 | if (!TARGET_32BIT) |
12139 | { | |
12140 | warning ("no profiling of 64-bit code for this ABI"); | |
12141 | return; | |
12142 | } | |
38c1f2d7 MM |
12143 | fprintf (file, "\tmflr %s\n", reg_names[0]); |
12144 | if (flag_pic == 1) | |
12145 | { | |
dfdfa60f | 12146 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
09eeeacb AM |
12147 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
12148 | reg_names[0], save_lr, reg_names[1]); | |
17167fd8 | 12149 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 12150 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 12151 | assemble_name (file, buf); |
17167fd8 | 12152 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 12153 | } |
9ebbca7d | 12154 | else if (flag_pic > 1) |
38c1f2d7 | 12155 | { |
09eeeacb AM |
12156 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
12157 | reg_names[0], save_lr, reg_names[1]); | |
9ebbca7d GK |
12158 | /* Now, we need to get the address of the label. */ |
12159 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 12160 | assemble_name (file, buf); |
9ebbca7d GK |
12161 | fputs ("-.\n1:", file); |
12162 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
12163 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", | |
12164 | reg_names[0], reg_names[11]); | |
12165 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
12166 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 12167 | } |
38c1f2d7 MM |
12168 | else |
12169 | { | |
17167fd8 | 12170 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 12171 | assemble_name (file, buf); |
dfdfa60f | 12172 | fputs ("@ha\n", file); |
09eeeacb AM |
12173 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
12174 | reg_names[0], save_lr, reg_names[1]); | |
a260abc9 | 12175 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 12176 | assemble_name (file, buf); |
17167fd8 | 12177 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
12178 | } |
12179 | ||
09eeeacb AM |
12180 | if (current_function_needs_context && DEFAULT_ABI == ABI_AIX_NODESC) |
12181 | { | |
12182 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", | |
12183 | reg_names[STATIC_CHAIN_REGNUM], | |
12184 | 12, reg_names[1]); | |
12185 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
12186 | asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n", | |
12187 | reg_names[STATIC_CHAIN_REGNUM], | |
12188 | 12, reg_names[1]); | |
12189 | } | |
12190 | else | |
12191 | /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */ | |
12192 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
38c1f2d7 MM |
12193 | break; |
12194 | ||
12195 | case ABI_AIX: | |
ee890fe2 | 12196 | case ABI_DARWIN: |
a4f6c312 | 12197 | /* Don't do anything, done in output_profile_hook (). */ |
38c1f2d7 MM |
12198 | break; |
12199 | } | |
e165f3f0 | 12200 | } |
a251ffd0 TG |
12201 | |
12202 | /* Adjust the cost of a scheduling dependency. Return the new cost of | |
12203 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
12204 | ||
c237e94a | 12205 | static int |
a06faf84 | 12206 | rs6000_adjust_cost (insn, link, dep_insn, cost) |
a251ffd0 TG |
12207 | rtx insn; |
12208 | rtx link; | |
296b8152 | 12209 | rtx dep_insn ATTRIBUTE_UNUSED; |
a251ffd0 TG |
12210 | int cost; |
12211 | { | |
12212 | if (! recog_memoized (insn)) | |
12213 | return 0; | |
12214 | ||
12215 | if (REG_NOTE_KIND (link) != 0) | |
12216 | return 0; | |
12217 | ||
12218 | if (REG_NOTE_KIND (link) == 0) | |
12219 | { | |
ed947a96 DJ |
12220 | /* Data dependency; DEP_INSN writes a register that INSN reads |
12221 | some cycles later. */ | |
12222 | switch (get_attr_type (insn)) | |
12223 | { | |
12224 | case TYPE_JMPREG: | |
309323c2 | 12225 | /* Tell the first scheduling pass about the latency between |
ed947a96 DJ |
12226 | a mtctr and bctr (and mtlr and br/blr). The first |
12227 | scheduling pass will not know about this latency since | |
12228 | the mtctr instruction, which has the latency associated | |
12229 | to it, will be generated by reload. */ | |
309323c2 | 12230 | return TARGET_POWER ? 5 : 4; |
ed947a96 DJ |
12231 | case TYPE_BRANCH: |
12232 | /* Leave some extra cycles between a compare and its | |
12233 | dependent branch, to inhibit expensive mispredicts. */ | |
309323c2 DE |
12234 | if ((rs6000_cpu_attr == CPU_PPC603 |
12235 | || rs6000_cpu_attr == CPU_PPC604 | |
12236 | || rs6000_cpu_attr == CPU_PPC604E | |
12237 | || rs6000_cpu_attr == CPU_PPC620 | |
12238 | || rs6000_cpu_attr == CPU_PPC630 | |
12239 | || rs6000_cpu_attr == CPU_PPC750 | |
12240 | || rs6000_cpu_attr == CPU_PPC7400 | |
12241 | || rs6000_cpu_attr == CPU_PPC7450 | |
12242 | || rs6000_cpu_attr == CPU_POWER4) | |
ed947a96 DJ |
12243 | && recog_memoized (dep_insn) |
12244 | && (INSN_CODE (dep_insn) >= 0) | |
12245 | && (get_attr_type (dep_insn) == TYPE_COMPARE | |
12246 | || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE | |
12247 | || get_attr_type (dep_insn) == TYPE_FPCOMPARE | |
12248 | || get_attr_type (dep_insn) == TYPE_CR_LOGICAL)) | |
12249 | return cost + 2; | |
12250 | default: | |
12251 | break; | |
12252 | } | |
a251ffd0 TG |
12253 | /* Fall out to return default cost. */ |
12254 | } | |
12255 | ||
12256 | return cost; | |
12257 | } | |
b6c9286a | 12258 | |
a4f6c312 SS |
12259 | /* A C statement (sans semicolon) to update the integer scheduling |
12260 | priority INSN_PRIORITY (INSN). Reduce the priority to execute the | |
12261 | INSN earlier, increase the priority to execute INSN later. Do not | |
12262 | define this macro if you do not need to adjust the scheduling | |
12263 | priorities of insns. */ | |
bef84347 | 12264 | |
c237e94a | 12265 | static int |
bef84347 | 12266 | rs6000_adjust_priority (insn, priority) |
d330fd93 | 12267 | rtx insn ATTRIBUTE_UNUSED; |
bef84347 VM |
12268 | int priority; |
12269 | { | |
a4f6c312 SS |
12270 | /* On machines (like the 750) which have asymmetric integer units, |
12271 | where one integer unit can do multiply and divides and the other | |
12272 | can't, reduce the priority of multiply/divide so it is scheduled | |
12273 | before other integer operations. */ | |
bef84347 VM |
12274 | |
12275 | #if 0 | |
2c3c49de | 12276 | if (! INSN_P (insn)) |
bef84347 VM |
12277 | return priority; |
12278 | ||
12279 | if (GET_CODE (PATTERN (insn)) == USE) | |
12280 | return priority; | |
12281 | ||
12282 | switch (rs6000_cpu_attr) { | |
12283 | case CPU_PPC750: | |
12284 | switch (get_attr_type (insn)) | |
12285 | { | |
12286 | default: | |
12287 | break; | |
12288 | ||
12289 | case TYPE_IMUL: | |
12290 | case TYPE_IDIV: | |
3cb999d8 DE |
12291 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
12292 | priority, priority); | |
bef84347 VM |
12293 | if (priority >= 0 && priority < 0x01000000) |
12294 | priority >>= 3; | |
12295 | break; | |
12296 | } | |
12297 | } | |
12298 | #endif | |
12299 | ||
12300 | return priority; | |
12301 | } | |
12302 | ||
a4f6c312 SS |
12303 | /* Return how many instructions the machine can issue per cycle. */ |
12304 | ||
c237e94a ZW |
12305 | static int |
12306 | rs6000_issue_rate () | |
b6c9286a MM |
12307 | { |
12308 | switch (rs6000_cpu_attr) { | |
3cb999d8 DE |
12309 | case CPU_RIOS1: /* ? */ |
12310 | case CPU_RS64A: | |
12311 | case CPU_PPC601: /* ? */ | |
ed947a96 | 12312 | case CPU_PPC7450: |
3cb999d8 | 12313 | return 3; |
b6c9286a | 12314 | case CPU_PPC603: |
bef84347 | 12315 | case CPU_PPC750: |
ed947a96 | 12316 | case CPU_PPC7400: |
bef84347 | 12317 | return 2; |
3cb999d8 | 12318 | case CPU_RIOS2: |
b6c9286a | 12319 | case CPU_PPC604: |
19684119 | 12320 | case CPU_PPC604E: |
b6c9286a | 12321 | case CPU_PPC620: |
3cb999d8 | 12322 | case CPU_PPC630: |
309323c2 | 12323 | case CPU_POWER4: |
b6c9286a MM |
12324 | return 4; |
12325 | default: | |
12326 | return 1; | |
12327 | } | |
12328 | } | |
12329 | ||
b6c9286a | 12330 | \f |
b6c9286a MM |
12331 | /* Length in units of the trampoline for entering a nested function. */ |
12332 | ||
12333 | int | |
12334 | rs6000_trampoline_size () | |
12335 | { | |
12336 | int ret = 0; | |
12337 | ||
12338 | switch (DEFAULT_ABI) | |
12339 | { | |
12340 | default: | |
12341 | abort (); | |
12342 | ||
12343 | case ABI_AIX: | |
8f802bfb | 12344 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
12345 | break; |
12346 | ||
4dabc42d | 12347 | case ABI_DARWIN: |
b6c9286a MM |
12348 | case ABI_V4: |
12349 | case ABI_AIX_NODESC: | |
03a7e1a5 | 12350 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 12351 | break; |
b6c9286a MM |
12352 | } |
12353 | ||
12354 | return ret; | |
12355 | } | |
12356 | ||
12357 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
12358 | FNADDR is an RTX for the address of the function's pure code. | |
12359 | CXT is an RTX for the static chain value for the function. */ | |
12360 | ||
12361 | void | |
12362 | rs6000_initialize_trampoline (addr, fnaddr, cxt) | |
12363 | rtx addr; | |
12364 | rtx fnaddr; | |
12365 | rtx cxt; | |
12366 | { | |
ac2a93a1 | 12367 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
12368 | int regsize = (TARGET_32BIT) ? 4 : 8; |
12369 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
12370 | |
12371 | switch (DEFAULT_ABI) | |
12372 | { | |
12373 | default: | |
12374 | abort (); | |
12375 | ||
8bd04c56 | 12376 | /* Macros to shorten the code expansions below. */ |
39403d82 | 12377 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
12378 | #define MEM_PLUS(addr,offset) \ |
12379 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 12380 | |
b6c9286a MM |
12381 | /* Under AIX, just build the 3 word function descriptor */ |
12382 | case ABI_AIX: | |
8bd04c56 MM |
12383 | { |
12384 | rtx fn_reg = gen_reg_rtx (pmode); | |
12385 | rtx toc_reg = gen_reg_rtx (pmode); | |
12386 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
1cb18e3c | 12387 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); |
8bd04c56 MM |
12388 | emit_move_insn (MEM_DEREF (addr), fn_reg); |
12389 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
12390 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
12391 | } | |
b6c9286a MM |
12392 | break; |
12393 | ||
4dabc42d TC |
12394 | /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */ |
12395 | case ABI_DARWIN: | |
b6c9286a MM |
12396 | case ABI_V4: |
12397 | case ABI_AIX_NODESC: | |
39403d82 | 12398 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
12399 | FALSE, VOIDmode, 4, |
12400 | addr, pmode, | |
12401 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
12402 | fnaddr, pmode, | |
12403 | ctx_reg, pmode); | |
b6c9286a | 12404 | break; |
b6c9286a MM |
12405 | } |
12406 | ||
12407 | return; | |
12408 | } | |
7509c759 MM |
12409 | |
12410 | \f | |
91d231cb | 12411 | /* Table of valid machine attributes. */ |
a4f6c312 | 12412 | |
91d231cb | 12413 | const struct attribute_spec rs6000_attribute_table[] = |
7509c759 | 12414 | { |
91d231cb | 12415 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
a5c76ee6 ZW |
12416 | { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, |
12417 | { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, | |
12418 | { NULL, 0, 0, false, false, false, NULL } | |
91d231cb | 12419 | }; |
7509c759 | 12420 | |
a5c76ee6 ZW |
12421 | /* Handle a "longcall" or "shortcall" attribute; arguments as in |
12422 | struct attribute_spec.handler. */ | |
a4f6c312 | 12423 | |
91d231cb JM |
12424 | static tree |
12425 | rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs) | |
12426 | tree *node; | |
12427 | tree name; | |
12428 | tree args ATTRIBUTE_UNUSED; | |
12429 | int flags ATTRIBUTE_UNUSED; | |
12430 | bool *no_add_attrs; | |
12431 | { | |
12432 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
12433 | && TREE_CODE (*node) != FIELD_DECL | |
12434 | && TREE_CODE (*node) != TYPE_DECL) | |
12435 | { | |
12436 | warning ("`%s' attribute only applies to functions", | |
12437 | IDENTIFIER_POINTER (name)); | |
12438 | *no_add_attrs = true; | |
12439 | } | |
6a4cee5f | 12440 | |
91d231cb | 12441 | return NULL_TREE; |
7509c759 MM |
12442 | } |
12443 | ||
a5c76ee6 ZW |
12444 | /* Set longcall attributes on all functions declared when |
12445 | rs6000_default_long_calls is true. */ | |
12446 | static void | |
12447 | rs6000_set_default_type_attributes (type) | |
12448 | tree type; | |
12449 | { | |
12450 | if (rs6000_default_long_calls | |
12451 | && (TREE_CODE (type) == FUNCTION_TYPE | |
12452 | || TREE_CODE (type) == METHOD_TYPE)) | |
12453 | TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"), | |
12454 | NULL_TREE, | |
12455 | TYPE_ATTRIBUTES (type)); | |
12456 | } | |
12457 | ||
3cb999d8 DE |
12458 | /* Return a reference suitable for calling a function with the |
12459 | longcall attribute. */ | |
a4f6c312 | 12460 | |
6a4cee5f MM |
12461 | struct rtx_def * |
12462 | rs6000_longcall_ref (call_ref) | |
12463 | rtx call_ref; | |
12464 | { | |
d330fd93 | 12465 | const char *call_name; |
6a4cee5f MM |
12466 | tree node; |
12467 | ||
12468 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
12469 | return call_ref; | |
12470 | ||
12471 | /* System V adds '.' to the internal name, so skip them. */ | |
12472 | call_name = XSTR (call_ref, 0); | |
12473 | if (*call_name == '.') | |
12474 | { | |
12475 | while (*call_name == '.') | |
12476 | call_name++; | |
12477 | ||
12478 | node = get_identifier (call_name); | |
39403d82 | 12479 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
12480 | } |
12481 | ||
12482 | return force_reg (Pmode, call_ref); | |
12483 | } | |
12484 | ||
7509c759 | 12485 | \f |
b64a1b53 RH |
12486 | #ifdef USING_ELFOS_H |
12487 | ||
7509c759 MM |
12488 | /* A C statement or statements to switch to the appropriate section |
12489 | for output of RTX in mode MODE. You can assume that RTX is some | |
12490 | kind of constant in RTL. The argument MODE is redundant except in | |
12491 | the case of a `const_int' rtx. Select the section by calling | |
12492 | `text_section' or one of the alternatives for other sections. | |
12493 | ||
12494 | Do not define this macro if you put all constants in the read-only | |
12495 | data section. */ | |
12496 | ||
b64a1b53 RH |
12497 | static void |
12498 | rs6000_elf_select_rtx_section (mode, x, align) | |
a9098fd0 | 12499 | enum machine_mode mode; |
7509c759 | 12500 | rtx x; |
b64a1b53 | 12501 | unsigned HOST_WIDE_INT align; |
7509c759 | 12502 | { |
a9098fd0 | 12503 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 12504 | toc_section (); |
7509c759 | 12505 | else |
b64a1b53 | 12506 | default_elf_select_rtx_section (mode, x, align); |
7509c759 MM |
12507 | } |
12508 | ||
12509 | /* A C statement or statements to switch to the appropriate | |
12510 | section for output of DECL. DECL is either a `VAR_DECL' node | |
12511 | or a constant of some sort. RELOC indicates whether forming | |
12512 | the initial value of DECL requires link-time relocations. */ | |
12513 | ||
ae46c4e0 RH |
12514 | static void |
12515 | rs6000_elf_select_section (decl, reloc, align) | |
7509c759 MM |
12516 | tree decl; |
12517 | int reloc; | |
0e5dbd9b | 12518 | unsigned HOST_WIDE_INT align; |
7509c759 | 12519 | { |
0e5dbd9b DE |
12520 | default_elf_select_section_1 (decl, reloc, align, |
12521 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
63019373 GK |
12522 | } |
12523 | ||
12524 | /* A C statement to build up a unique section name, expressed as a | |
12525 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
12526 | RELOC indicates whether the initial value of EXP requires | |
12527 | link-time relocations. If you do not define this macro, GCC will use | |
12528 | the symbol name prefixed by `.' as the section name. Note - this | |
f5143c46 | 12529 | macro can now be called for uninitialized data items as well as |
4912a07c | 12530 | initialized data and functions. */ |
63019373 | 12531 | |
ae46c4e0 RH |
12532 | static void |
12533 | rs6000_elf_unique_section (decl, reloc) | |
63019373 GK |
12534 | tree decl; |
12535 | int reloc; | |
12536 | { | |
0e5dbd9b DE |
12537 | default_unique_section_1 (decl, reloc, |
12538 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7509c759 | 12539 | } |
d9407988 MM |
12540 | |
12541 | \f | |
d9407988 MM |
12542 | /* If we are referencing a function that is static or is known to be |
12543 | in this file, make the SYMBOL_REF special. We can use this to indicate | |
12544 | that we can branch to this function without emitting a no-op after the | |
9ebbca7d | 12545 | call. For real AIX calling sequences, we also replace the |
d9407988 MM |
12546 | function name with the real name (1 or 2 leading .'s), rather than |
12547 | the function descriptor name. This saves a lot of overriding code | |
a260abc9 | 12548 | to read the prefixes. */ |
d9407988 | 12549 | |
fb49053f RH |
12550 | static void |
12551 | rs6000_elf_encode_section_info (decl, first) | |
d9407988 | 12552 | tree decl; |
b2003250 | 12553 | int first; |
d9407988 | 12554 | { |
b2003250 RH |
12555 | if (!first) |
12556 | return; | |
12557 | ||
d9407988 MM |
12558 | if (TREE_CODE (decl) == FUNCTION_DECL) |
12559 | { | |
12560 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); | |
b629ba0c | 12561 | if ((*targetm.binds_local_p) (decl)) |
d9407988 MM |
12562 | SYMBOL_REF_FLAG (sym_ref) = 1; |
12563 | ||
9ebbca7d | 12564 | if (DEFAULT_ABI == ABI_AIX) |
d9407988 | 12565 | { |
ff669a6c RH |
12566 | size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2; |
12567 | size_t len2 = strlen (XSTR (sym_ref, 0)); | |
520a57c8 | 12568 | char *str = alloca (len1 + len2 + 1); |
ff669a6c RH |
12569 | str[0] = '.'; |
12570 | str[1] = '.'; | |
12571 | memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1); | |
12572 | ||
520a57c8 | 12573 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2); |
d9407988 MM |
12574 | } |
12575 | } | |
12576 | else if (rs6000_sdata != SDATA_NONE | |
f607bc57 | 12577 | && DEFAULT_ABI == ABI_V4 |
d9407988 MM |
12578 | && TREE_CODE (decl) == VAR_DECL) |
12579 | { | |
c40e5172 | 12580 | rtx sym_ref = XEXP (DECL_RTL (decl), 0); |
d9407988 MM |
12581 | int size = int_size_in_bytes (TREE_TYPE (decl)); |
12582 | tree section_name = DECL_SECTION_NAME (decl); | |
d330fd93 | 12583 | const char *name = (char *)0; |
d9407988 MM |
12584 | int len = 0; |
12585 | ||
c40e5172 JS |
12586 | if ((*targetm.binds_local_p) (decl)) |
12587 | SYMBOL_REF_FLAG (sym_ref) = 1; | |
12588 | ||
d9407988 MM |
12589 | if (section_name) |
12590 | { | |
12591 | if (TREE_CODE (section_name) == STRING_CST) | |
12592 | { | |
12593 | name = TREE_STRING_POINTER (section_name); | |
12594 | len = TREE_STRING_LENGTH (section_name); | |
12595 | } | |
12596 | else | |
12597 | abort (); | |
12598 | } | |
12599 | ||
12600 | if ((size > 0 && size <= g_switch_value) | |
12601 | || (name | |
5f59ecb7 | 12602 | && ((len == sizeof (".sdata") - 1 |
3cb999d8 | 12603 | && strcmp (name, ".sdata") == 0) |
5f59ecb7 | 12604 | || (len == sizeof (".sdata2") - 1 |
3cb999d8 | 12605 | && strcmp (name, ".sdata2") == 0) |
5f59ecb7 | 12606 | || (len == sizeof (".sbss") - 1 |
3cb999d8 | 12607 | && strcmp (name, ".sbss") == 0) |
5f59ecb7 | 12608 | || (len == sizeof (".sbss2") - 1 |
3cb999d8 | 12609 | && strcmp (name, ".sbss2") == 0) |
5f59ecb7 | 12610 | || (len == sizeof (".PPC.EMB.sdata0") - 1 |
3cb999d8 | 12611 | && strcmp (name, ".PPC.EMB.sdata0") == 0) |
5f59ecb7 | 12612 | || (len == sizeof (".PPC.EMB.sbss0") - 1 |
3cb999d8 | 12613 | && strcmp (name, ".PPC.EMB.sbss0") == 0)))) |
d9407988 | 12614 | { |
ff669a6c | 12615 | size_t len = strlen (XSTR (sym_ref, 0)); |
88c1e412 | 12616 | char *str = alloca (len + 2); |
ff669a6c | 12617 | |
ff669a6c RH |
12618 | str[0] = '@'; |
12619 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
88c1e412 | 12620 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1); |
d9407988 MM |
12621 | } |
12622 | } | |
12623 | } | |
12624 | ||
772c5265 RH |
12625 | static const char * |
12626 | rs6000_elf_strip_name_encoding (str) | |
12627 | const char *str; | |
12628 | { | |
12629 | while (*str == '*' || *str == '@') | |
12630 | str++; | |
12631 | return str; | |
12632 | } | |
12633 | ||
0e5dbd9b DE |
12634 | static bool |
12635 | rs6000_elf_in_small_data_p (decl) | |
12636 | tree decl; | |
12637 | { | |
12638 | if (rs6000_sdata == SDATA_NONE) | |
12639 | return false; | |
12640 | ||
12641 | if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl)) | |
12642 | { | |
12643 | const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
12644 | if (strcmp (section, ".sdata") == 0 | |
12645 | || strcmp (section, ".sdata2") == 0 | |
12646 | || strcmp (section, ".sbss") == 0) | |
12647 | return true; | |
12648 | } | |
12649 | else | |
12650 | { | |
12651 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); | |
12652 | ||
12653 | if (size > 0 | |
12654 | && size <= g_switch_value | |
12655 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))) | |
12656 | return true; | |
12657 | } | |
12658 | ||
12659 | return false; | |
12660 | } | |
12661 | ||
b91da81f | 12662 | #endif /* USING_ELFOS_H */ |
000034eb | 12663 | |
a6c2a102 | 12664 | \f |
000034eb | 12665 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
12666 | ADDR can be effectively incremented by incrementing REG. |
12667 | ||
12668 | r0 is special and we must not select it as an address | |
12669 | register by this routine since our caller will try to | |
12670 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
12671 | |
12672 | struct rtx_def * | |
12673 | find_addr_reg (addr) | |
12674 | rtx addr; | |
12675 | { | |
12676 | while (GET_CODE (addr) == PLUS) | |
12677 | { | |
02441cd6 JL |
12678 | if (GET_CODE (XEXP (addr, 0)) == REG |
12679 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 12680 | addr = XEXP (addr, 0); |
02441cd6 JL |
12681 | else if (GET_CODE (XEXP (addr, 1)) == REG |
12682 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
12683 | addr = XEXP (addr, 1); |
12684 | else if (CONSTANT_P (XEXP (addr, 0))) | |
12685 | addr = XEXP (addr, 1); | |
12686 | else if (CONSTANT_P (XEXP (addr, 1))) | |
12687 | addr = XEXP (addr, 0); | |
12688 | else | |
12689 | abort (); | |
12690 | } | |
02441cd6 | 12691 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
12692 | return addr; |
12693 | abort (); | |
12694 | } | |
12695 | ||
a6c2a102 DE |
12696 | void |
12697 | rs6000_fatal_bad_address (op) | |
12698 | rtx op; | |
12699 | { | |
12700 | fatal_insn ("bad address", op); | |
12701 | } | |
c8023011 | 12702 | |
ee890fe2 SS |
12703 | #if TARGET_MACHO |
12704 | ||
12705 | #if 0 | |
12706 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
12707 | reference and a constant. */ | |
12708 | ||
12709 | int | |
12710 | symbolic_operand (op) | |
592696dd | 12711 | rtx op; |
ee890fe2 SS |
12712 | { |
12713 | switch (GET_CODE (op)) | |
12714 | { | |
12715 | case SYMBOL_REF: | |
12716 | case LABEL_REF: | |
12717 | return 1; | |
12718 | case CONST: | |
12719 | op = XEXP (op, 0); | |
12720 | return (GET_CODE (op) == SYMBOL_REF || | |
12721 | (GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
12722 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
12723 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
12724 | default: | |
12725 | return 0; | |
12726 | } | |
c8023011 | 12727 | } |
ee890fe2 SS |
12728 | #endif |
12729 | ||
12730 | #ifdef RS6000_LONG_BRANCH | |
12731 | ||
12732 | static tree stub_list = 0; | |
12733 | ||
12734 | /* ADD_COMPILER_STUB adds the compiler generated stub for handling | |
12735 | procedure calls to the linked list. */ | |
12736 | ||
12737 | void | |
12738 | add_compiler_stub (label_name, function_name, line_number) | |
12739 | tree label_name; | |
12740 | tree function_name; | |
12741 | int line_number; | |
12742 | { | |
12743 | tree stub = build_tree_list (function_name, label_name); | |
12744 | TREE_TYPE (stub) = build_int_2 (line_number, 0); | |
12745 | TREE_CHAIN (stub) = stub_list; | |
12746 | stub_list = stub; | |
12747 | } | |
12748 | ||
12749 | #define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB) | |
12750 | #define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB) | |
12751 | #define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB)) | |
12752 | ||
a4f6c312 SS |
12753 | /* OUTPUT_COMPILER_STUB outputs the compiler generated stub for |
12754 | handling procedure calls from the linked list and initializes the | |
12755 | linked list. */ | |
ee890fe2 | 12756 | |
a4f6c312 SS |
12757 | void |
12758 | output_compiler_stub () | |
ee890fe2 SS |
12759 | { |
12760 | char tmp_buf[256]; | |
12761 | char label_buf[256]; | |
308c142a | 12762 | tree stub; |
ee890fe2 SS |
12763 | |
12764 | if (!flag_pic) | |
12765 | for (stub = stub_list; stub; stub = TREE_CHAIN (stub)) | |
12766 | { | |
12767 | fprintf (asm_out_file, | |
12768 | "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub))); | |
12769 | ||
12770 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) | |
12771 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) | |
12772 | fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub)); | |
12773 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ | |
12774 | ||
12775 | if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*') | |
12776 | strcpy (label_buf, | |
12777 | IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1); | |
12778 | else | |
12779 | { | |
12780 | label_buf[0] = '_'; | |
12781 | strcpy (label_buf+1, | |
12782 | IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))); | |
12783 | } | |
12784 | ||
12785 | strcpy (tmp_buf, "lis r12,hi16("); | |
12786 | strcat (tmp_buf, label_buf); | |
12787 | strcat (tmp_buf, ")\n\tori r12,r12,lo16("); | |
12788 | strcat (tmp_buf, label_buf); | |
12789 | strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr"); | |
12790 | output_asm_insn (tmp_buf, 0); | |
12791 | ||
12792 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) | |
12793 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) | |
12794 | fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub)); | |
12795 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ | |
12796 | } | |
12797 | ||
12798 | stub_list = 0; | |
12799 | } | |
12800 | ||
12801 | /* NO_PREVIOUS_DEF checks in the link list whether the function name is | |
12802 | already there or not. */ | |
12803 | ||
a4f6c312 SS |
12804 | int |
12805 | no_previous_def (function_name) | |
ee890fe2 SS |
12806 | tree function_name; |
12807 | { | |
12808 | tree stub; | |
12809 | for (stub = stub_list; stub; stub = TREE_CHAIN (stub)) | |
12810 | if (function_name == STUB_FUNCTION_NAME (stub)) | |
12811 | return 0; | |
12812 | return 1; | |
12813 | } | |
12814 | ||
12815 | /* GET_PREV_LABEL gets the label name from the previous definition of | |
12816 | the function. */ | |
12817 | ||
a4f6c312 SS |
12818 | tree |
12819 | get_prev_label (function_name) | |
ee890fe2 SS |
12820 | tree function_name; |
12821 | { | |
12822 | tree stub; | |
12823 | for (stub = stub_list; stub; stub = TREE_CHAIN (stub)) | |
12824 | if (function_name == STUB_FUNCTION_NAME (stub)) | |
12825 | return STUB_LABEL_NAME (stub); | |
12826 | return 0; | |
12827 | } | |
12828 | ||
12829 | /* INSN is either a function call or a millicode call. It may have an | |
12830 | unconditional jump in its delay slot. | |
12831 | ||
12832 | CALL_DEST is the routine we are calling. */ | |
12833 | ||
12834 | char * | |
12835 | output_call (insn, call_dest, operand_number) | |
12836 | rtx insn; | |
12837 | rtx call_dest; | |
12838 | int operand_number; | |
12839 | { | |
12840 | static char buf[256]; | |
12841 | if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic) | |
12842 | { | |
12843 | tree labelname; | |
12844 | tree funname = get_identifier (XSTR (call_dest, 0)); | |
12845 | ||
12846 | if (no_previous_def (funname)) | |
12847 | { | |
308c142a | 12848 | int line_number = 0; |
ee890fe2 SS |
12849 | rtx label_rtx = gen_label_rtx (); |
12850 | char *label_buf, temp_buf[256]; | |
12851 | ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L", | |
12852 | CODE_LABEL_NUMBER (label_rtx)); | |
12853 | label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf; | |
12854 | labelname = get_identifier (label_buf); | |
12855 | for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn)); | |
12856 | if (insn) | |
12857 | line_number = NOTE_LINE_NUMBER (insn); | |
12858 | add_compiler_stub (labelname, funname, line_number); | |
12859 | } | |
12860 | else | |
12861 | labelname = get_prev_label (funname); | |
12862 | ||
12863 | sprintf (buf, "jbsr %%z%d,%.246s", | |
12864 | operand_number, IDENTIFIER_POINTER (labelname)); | |
12865 | return buf; | |
12866 | } | |
12867 | else | |
12868 | { | |
12869 | sprintf (buf, "bl %%z%d", operand_number); | |
12870 | return buf; | |
12871 | } | |
12872 | } | |
12873 | ||
12874 | #endif /* RS6000_LONG_BRANCH */ | |
12875 | ||
12876 | #define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \ | |
12877 | do { \ | |
83182544 | 12878 | const char *const symbol_ = (SYMBOL); \ |
ee890fe2 SS |
12879 | char *buffer_ = (BUF); \ |
12880 | if (symbol_[0] == '"') \ | |
12881 | { \ | |
12882 | sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \ | |
12883 | } \ | |
12884 | else if (name_needs_quotes(symbol_)) \ | |
12885 | { \ | |
12886 | sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \ | |
12887 | } \ | |
12888 | else \ | |
12889 | { \ | |
12890 | sprintf(buffer_, "L%d$%s", (N), symbol_); \ | |
12891 | } \ | |
12892 | } while (0) | |
12893 | ||
12894 | ||
12895 | /* Generate PIC and indirect symbol stubs. */ | |
12896 | ||
12897 | void | |
12898 | machopic_output_stub (file, symb, stub) | |
12899 | FILE *file; | |
12900 | const char *symb, *stub; | |
12901 | { | |
12902 | unsigned int length; | |
a4f6c312 SS |
12903 | char *symbol_name, *lazy_ptr_name; |
12904 | char *local_label_0; | |
ee890fe2 SS |
12905 | static int label = 0; |
12906 | ||
df56a27f | 12907 | /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
772c5265 | 12908 | symb = (*targetm.strip_name_encoding) (symb); |
df56a27f | 12909 | |
ee890fe2 SS |
12910 | label += 1; |
12911 | ||
ee890fe2 SS |
12912 | length = strlen (symb); |
12913 | symbol_name = alloca (length + 32); | |
12914 | GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); | |
12915 | ||
12916 | lazy_ptr_name = alloca (length + 32); | |
12917 | GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length); | |
12918 | ||
12919 | local_label_0 = alloca (length + 32); | |
12920 | GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0); | |
12921 | ||
ee890fe2 | 12922 | if (flag_pic == 2) |
d3c300d2 | 12923 | machopic_picsymbol_stub1_section (); |
ee890fe2 | 12924 | else |
d3c300d2 DJ |
12925 | machopic_symbol_stub1_section (); |
12926 | fprintf (file, "\t.align 2\n"); | |
ee890fe2 SS |
12927 | |
12928 | fprintf (file, "%s:\n", stub); | |
12929 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
12930 | ||
12931 | if (flag_pic == 2) | |
12932 | { | |
12933 | fprintf (file, "\tmflr r0\n"); | |
12934 | fprintf (file, "\tbcl 20,31,%s\n", local_label_0); | |
12935 | fprintf (file, "%s:\n\tmflr r11\n", local_label_0); | |
12936 | fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n", | |
12937 | lazy_ptr_name, local_label_0); | |
12938 | fprintf (file, "\tmtlr r0\n"); | |
d3c300d2 | 12939 | fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n", |
ee890fe2 SS |
12940 | lazy_ptr_name, local_label_0); |
12941 | fprintf (file, "\tmtctr r12\n"); | |
ee890fe2 SS |
12942 | fprintf (file, "\tbctr\n"); |
12943 | } | |
12944 | else | |
12945 | fprintf (file, "non-pure not supported\n"); | |
12946 | ||
12947 | machopic_lazy_symbol_ptr_section (); | |
12948 | fprintf (file, "%s:\n", lazy_ptr_name); | |
12949 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
12950 | fprintf (file, "\t.long dyld_stub_binding_helper\n"); | |
12951 | } | |
12952 | ||
12953 | /* Legitimize PIC addresses. If the address is already | |
12954 | position-independent, we return ORIG. Newly generated | |
12955 | position-independent addresses go into a reg. This is REG if non | |
12956 | zero, otherwise we allocate register(s) as necessary. */ | |
12957 | ||
c859cda6 | 12958 | #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000) |
ee890fe2 SS |
12959 | |
12960 | rtx | |
12961 | rs6000_machopic_legitimize_pic_address (orig, mode, reg) | |
12962 | rtx orig; | |
12963 | enum machine_mode mode; | |
12964 | rtx reg; | |
12965 | { | |
12966 | rtx base, offset; | |
12967 | ||
12968 | if (reg == NULL && ! reload_in_progress && ! reload_completed) | |
12969 | reg = gen_reg_rtx (Pmode); | |
12970 | ||
12971 | if (GET_CODE (orig) == CONST) | |
12972 | { | |
12973 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
12974 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
12975 | return orig; | |
12976 | ||
12977 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
12978 | { | |
a4f6c312 SS |
12979 | base = |
12980 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), | |
12981 | Pmode, reg); | |
12982 | offset = | |
12983 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), | |
12984 | Pmode, reg); | |
ee890fe2 SS |
12985 | } |
12986 | else | |
12987 | abort (); | |
12988 | ||
12989 | if (GET_CODE (offset) == CONST_INT) | |
12990 | { | |
12991 | if (SMALL_INT (offset)) | |
ed8908e7 | 12992 | return plus_constant (base, INTVAL (offset)); |
ee890fe2 SS |
12993 | else if (! reload_in_progress && ! reload_completed) |
12994 | offset = force_reg (Pmode, offset); | |
12995 | else | |
c859cda6 DJ |
12996 | { |
12997 | rtx mem = force_const_mem (Pmode, orig); | |
12998 | return machopic_legitimize_pic_address (mem, Pmode, reg); | |
12999 | } | |
ee890fe2 SS |
13000 | } |
13001 | return gen_rtx (PLUS, Pmode, base, offset); | |
13002 | } | |
13003 | ||
13004 | /* Fall back on generic machopic code. */ | |
13005 | return machopic_legitimize_pic_address (orig, mode, reg); | |
13006 | } | |
13007 | ||
13008 | /* This is just a placeholder to make linking work without having to | |
13009 | add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is | |
13010 | ever needed for Darwin (not too likely!) this would have to get a | |
13011 | real definition. */ | |
13012 | ||
13013 | void | |
13014 | toc_section () | |
13015 | { | |
13016 | } | |
13017 | ||
13018 | #endif /* TARGET_MACHO */ | |
7c262518 RH |
13019 | |
13020 | #if TARGET_ELF | |
13021 | static unsigned int | |
13022 | rs6000_elf_section_type_flags (decl, name, reloc) | |
13023 | tree decl; | |
13024 | const char *name; | |
13025 | int reloc; | |
13026 | { | |
5add3202 DE |
13027 | unsigned int flags |
13028 | = default_section_type_flags_1 (decl, name, reloc, | |
13029 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7c262518 | 13030 | |
270fc29b RH |
13031 | if (TARGET_RELOCATABLE) |
13032 | flags |= SECTION_WRITE; | |
7c262518 | 13033 | |
d0101753 | 13034 | return flags; |
7c262518 | 13035 | } |
d9f6800d RH |
13036 | |
13037 | /* Record an element in the table of global constructors. SYMBOL is | |
13038 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
13039 | between 0 and MAX_INIT_PRIORITY. | |
13040 | ||
13041 | This differs from default_named_section_asm_out_constructor in | |
13042 | that we have special handling for -mrelocatable. */ | |
13043 | ||
13044 | static void | |
13045 | rs6000_elf_asm_out_constructor (symbol, priority) | |
13046 | rtx symbol; | |
13047 | int priority; | |
13048 | { | |
13049 | const char *section = ".ctors"; | |
13050 | char buf[16]; | |
13051 | ||
13052 | if (priority != DEFAULT_INIT_PRIORITY) | |
13053 | { | |
13054 | sprintf (buf, ".ctors.%.5u", | |
13055 | /* Invert the numbering so the linker puts us in the proper | |
13056 | order; constructors are run from right to left, and the | |
13057 | linker sorts in increasing order. */ | |
13058 | MAX_INIT_PRIORITY - priority); | |
13059 | section = buf; | |
13060 | } | |
13061 | ||
715bdd29 RH |
13062 | named_section_flags (section, SECTION_WRITE); |
13063 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
13064 | |
13065 | if (TARGET_RELOCATABLE) | |
13066 | { | |
13067 | fputs ("\t.long (", asm_out_file); | |
13068 | output_addr_const (asm_out_file, symbol); | |
13069 | fputs (")@fixup\n", asm_out_file); | |
13070 | } | |
13071 | else | |
c8af3574 | 13072 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d RH |
13073 | } |
13074 | ||
13075 | static void | |
13076 | rs6000_elf_asm_out_destructor (symbol, priority) | |
13077 | rtx symbol; | |
13078 | int priority; | |
13079 | { | |
13080 | const char *section = ".dtors"; | |
13081 | char buf[16]; | |
13082 | ||
13083 | if (priority != DEFAULT_INIT_PRIORITY) | |
13084 | { | |
13085 | sprintf (buf, ".dtors.%.5u", | |
13086 | /* Invert the numbering so the linker puts us in the proper | |
13087 | order; constructors are run from right to left, and the | |
13088 | linker sorts in increasing order. */ | |
13089 | MAX_INIT_PRIORITY - priority); | |
13090 | section = buf; | |
13091 | } | |
13092 | ||
715bdd29 RH |
13093 | named_section_flags (section, SECTION_WRITE); |
13094 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
13095 | |
13096 | if (TARGET_RELOCATABLE) | |
13097 | { | |
13098 | fputs ("\t.long (", asm_out_file); | |
13099 | output_addr_const (asm_out_file, symbol); | |
13100 | fputs (")@fixup\n", asm_out_file); | |
13101 | } | |
13102 | else | |
c8af3574 | 13103 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d | 13104 | } |
7c262518 RH |
13105 | #endif |
13106 | ||
cbaaba19 | 13107 | #if TARGET_XCOFF |
7c262518 | 13108 | static void |
b275d088 DE |
13109 | rs6000_xcoff_asm_globalize_label (stream, name) |
13110 | FILE *stream; | |
13111 | const char *name; | |
13112 | { | |
13113 | fputs (GLOBAL_ASM_OP, stream); | |
13114 | RS6000_OUTPUT_BASENAME (stream, name); | |
13115 | putc ('\n', stream); | |
13116 | } | |
13117 | ||
13118 | static void | |
13119 | rs6000_xcoff_asm_named_section (name, flags) | |
7c262518 | 13120 | const char *name; |
0e5dbd9b | 13121 | unsigned int flags; |
7c262518 | 13122 | { |
0e5dbd9b DE |
13123 | int smclass; |
13124 | static const char * const suffix[3] = { "PR", "RO", "RW" }; | |
13125 | ||
13126 | if (flags & SECTION_CODE) | |
13127 | smclass = 0; | |
13128 | else if (flags & SECTION_WRITE) | |
13129 | smclass = 2; | |
13130 | else | |
13131 | smclass = 1; | |
13132 | ||
5b5198f7 | 13133 | fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n", |
0e5dbd9b | 13134 | (flags & SECTION_CODE) ? "." : "", |
5b5198f7 | 13135 | name, suffix[smclass], flags & SECTION_ENTSIZE); |
7c262518 | 13136 | } |
ae46c4e0 RH |
13137 | |
13138 | static void | |
0e5dbd9b DE |
13139 | rs6000_xcoff_select_section (decl, reloc, align) |
13140 | tree decl; | |
ae46c4e0 RH |
13141 | int reloc; |
13142 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED; | |
13143 | { | |
5add3202 | 13144 | if (decl_readonly_section_1 (decl, reloc, 1)) |
ae46c4e0 | 13145 | { |
0e5dbd9b | 13146 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
13147 | read_only_data_section (); |
13148 | else | |
13149 | read_only_private_data_section (); | |
13150 | } | |
13151 | else | |
13152 | { | |
0e5dbd9b | 13153 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
13154 | data_section (); |
13155 | else | |
13156 | private_data_section (); | |
13157 | } | |
13158 | } | |
13159 | ||
13160 | static void | |
13161 | rs6000_xcoff_unique_section (decl, reloc) | |
13162 | tree decl; | |
772c5265 | 13163 | int reloc ATTRIBUTE_UNUSED; |
ae46c4e0 RH |
13164 | { |
13165 | const char *name; | |
ae46c4e0 | 13166 | |
5b5198f7 DE |
13167 | /* Use select_section for private and uninitialized data. */ |
13168 | if (!TREE_PUBLIC (decl) | |
13169 | || DECL_COMMON (decl) | |
0e5dbd9b DE |
13170 | || DECL_INITIAL (decl) == NULL_TREE |
13171 | || DECL_INITIAL (decl) == error_mark_node | |
13172 | || (flag_zero_initialized_in_bss | |
13173 | && initializer_zerop (DECL_INITIAL (decl)))) | |
13174 | return; | |
13175 | ||
13176 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
13177 | name = (*targetm.strip_name_encoding) (name); | |
13178 | DECL_SECTION_NAME (decl) = build_string (strlen (name), name); | |
ae46c4e0 | 13179 | } |
b64a1b53 | 13180 | |
fb49053f RH |
13181 | /* Select section for constant in constant pool. |
13182 | ||
13183 | On RS/6000, all constants are in the private read-only data area. | |
13184 | However, if this is being placed in the TOC it must be output as a | |
13185 | toc entry. */ | |
13186 | ||
b64a1b53 RH |
13187 | static void |
13188 | rs6000_xcoff_select_rtx_section (mode, x, align) | |
13189 | enum machine_mode mode; | |
13190 | rtx x; | |
13191 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED; | |
13192 | { | |
13193 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) | |
13194 | toc_section (); | |
13195 | else | |
13196 | read_only_private_data_section (); | |
13197 | } | |
772c5265 RH |
13198 | |
13199 | /* Remove any trailing [DS] or the like from the symbol name. */ | |
13200 | ||
13201 | static const char * | |
13202 | rs6000_xcoff_strip_name_encoding (name) | |
13203 | const char *name; | |
13204 | { | |
13205 | size_t len; | |
13206 | if (*name == '*') | |
13207 | name++; | |
13208 | len = strlen (name); | |
13209 | if (name[len - 1] == ']') | |
13210 | return ggc_alloc_string (name, len - 4); | |
13211 | else | |
13212 | return name; | |
13213 | } | |
13214 | ||
5add3202 DE |
13215 | /* Section attributes. AIX is always PIC. */ |
13216 | ||
13217 | static unsigned int | |
13218 | rs6000_xcoff_section_type_flags (decl, name, reloc) | |
13219 | tree decl; | |
13220 | const char *name; | |
13221 | int reloc; | |
13222 | { | |
5b5198f7 DE |
13223 | unsigned int align; |
13224 | unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1); | |
13225 | ||
13226 | /* Align to at least UNIT size. */ | |
13227 | if (flags & SECTION_CODE) | |
13228 | align = MIN_UNITS_PER_WORD; | |
13229 | else | |
13230 | /* Increase alignment of large objects if not already stricter. */ | |
13231 | align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT), | |
13232 | int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD | |
13233 | ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD); | |
13234 | ||
13235 | return flags | (exact_log2 (align) & SECTION_ENTSIZE); | |
5add3202 DE |
13236 | } |
13237 | ||
cbaaba19 | 13238 | #endif /* TARGET_XCOFF */ |
fb49053f | 13239 | |
0e5dbd9b | 13240 | /* Note that this is also used for PPC64 Linux. */ |
fb49053f RH |
13241 | |
13242 | static void | |
13243 | rs6000_xcoff_encode_section_info (decl, first) | |
13244 | tree decl; | |
13245 | int first ATTRIBUTE_UNUSED; | |
13246 | { | |
13247 | if (TREE_CODE (decl) == FUNCTION_DECL | |
b629ba0c | 13248 | && (*targetm.binds_local_p) (decl)) |
fb49053f RH |
13249 | SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1; |
13250 | } | |
0e5dbd9b DE |
13251 | |
13252 | /* Cross-module name binding. For AIX and PPC64 Linux, which always are | |
13253 | PIC, use private copy of flag_pic. */ | |
13254 | ||
2bcc50d0 | 13255 | static bool |
0e5dbd9b DE |
13256 | rs6000_binds_local_p (decl) |
13257 | tree decl; | |
13258 | { | |
5add3202 | 13259 | return default_binds_local_p_1 (decl, flag_pic || rs6000_flag_pic); |
0e5dbd9b | 13260 | } |
34bb030a | 13261 | |
3c50106f RH |
13262 | /* Compute a (partial) cost for rtx X. Return true if the complete |
13263 | cost has been computed, and false if subexpressions should be | |
13264 | scanned. In either case, *TOTAL contains the cost result. */ | |
13265 | ||
13266 | static bool | |
13267 | rs6000_rtx_costs (x, code, outer_code, total) | |
13268 | rtx x; | |
13269 | int code, outer_code ATTRIBUTE_UNUSED; | |
13270 | int *total; | |
13271 | { | |
13272 | switch (code) | |
13273 | { | |
13274 | /* On the RS/6000, if it is valid in the insn, it is free. | |
13275 | So this always returns 0. */ | |
13276 | case CONST_INT: | |
13277 | case CONST: | |
13278 | case LABEL_REF: | |
13279 | case SYMBOL_REF: | |
13280 | case CONST_DOUBLE: | |
13281 | case HIGH: | |
13282 | *total = 0; | |
13283 | return true; | |
13284 | ||
13285 | case PLUS: | |
13286 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
13287 | && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) | |
13288 | + 0x8000) >= 0x10000) | |
13289 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
13290 | ? COSTS_N_INSNS (2) | |
13291 | : COSTS_N_INSNS (1)); | |
13292 | return true; | |
13293 | ||
13294 | case AND: | |
13295 | case IOR: | |
13296 | case XOR: | |
13297 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
13298 | && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0 | |
13299 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
13300 | ? COSTS_N_INSNS (2) | |
13301 | : COSTS_N_INSNS (1)); | |
13302 | return true; | |
13303 | ||
13304 | case MULT: | |
13305 | if (optimize_size) | |
13306 | { | |
13307 | *total = COSTS_N_INSNS (2); | |
13308 | return true; | |
13309 | } | |
13310 | switch (rs6000_cpu) | |
13311 | { | |
13312 | case PROCESSOR_RIOS1: | |
13313 | case PROCESSOR_PPC405: | |
13314 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
13315 | ? COSTS_N_INSNS (5) | |
13316 | : (INTVAL (XEXP (x, 1)) >= -256 | |
13317 | && INTVAL (XEXP (x, 1)) <= 255) | |
13318 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
13319 | return true; | |
13320 | ||
13321 | case PROCESSOR_RS64A: | |
13322 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
13323 | ? GET_MODE (XEXP (x, 1)) != DImode | |
13324 | ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34) | |
13325 | : (INTVAL (XEXP (x, 1)) >= -256 | |
13326 | && INTVAL (XEXP (x, 1)) <= 255) | |
13327 | ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12)); | |
13328 | return true; | |
13329 | ||
13330 | case PROCESSOR_RIOS2: | |
13331 | case PROCESSOR_MPCCORE: | |
13332 | case PROCESSOR_PPC604e: | |
13333 | *total = COSTS_N_INSNS (2); | |
13334 | return true; | |
13335 | ||
13336 | case PROCESSOR_PPC601: | |
13337 | *total = COSTS_N_INSNS (5); | |
13338 | return true; | |
13339 | ||
13340 | case PROCESSOR_PPC603: | |
13341 | case PROCESSOR_PPC7400: | |
13342 | case PROCESSOR_PPC750: | |
13343 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
13344 | ? COSTS_N_INSNS (5) | |
13345 | : (INTVAL (XEXP (x, 1)) >= -256 | |
13346 | && INTVAL (XEXP (x, 1)) <= 255) | |
13347 | ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3)); | |
13348 | return true; | |
13349 | ||
13350 | case PROCESSOR_PPC7450: | |
13351 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
13352 | ? COSTS_N_INSNS (4) | |
13353 | : COSTS_N_INSNS (3)); | |
13354 | return true; | |
13355 | ||
13356 | case PROCESSOR_PPC403: | |
13357 | case PROCESSOR_PPC604: | |
13358 | case PROCESSOR_PPC8540: | |
13359 | *total = COSTS_N_INSNS (4); | |
13360 | return true; | |
13361 | ||
13362 | case PROCESSOR_PPC620: | |
13363 | case PROCESSOR_PPC630: | |
13364 | case PROCESSOR_POWER4: | |
13365 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
13366 | ? GET_MODE (XEXP (x, 1)) != DImode | |
13367 | ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7) | |
13368 | : (INTVAL (XEXP (x, 1)) >= -256 | |
13369 | && INTVAL (XEXP (x, 1)) <= 255) | |
13370 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
13371 | return true; | |
13372 | ||
13373 | default: | |
13374 | abort (); | |
13375 | } | |
13376 | ||
13377 | case DIV: | |
13378 | case MOD: | |
13379 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
13380 | && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) | |
13381 | { | |
13382 | *total = COSTS_N_INSNS (2); | |
13383 | return true; | |
13384 | } | |
13385 | /* FALLTHRU */ | |
13386 | ||
13387 | case UDIV: | |
13388 | case UMOD: | |
13389 | switch (rs6000_cpu) | |
13390 | { | |
13391 | case PROCESSOR_RIOS1: | |
13392 | *total = COSTS_N_INSNS (19); | |
13393 | return true; | |
13394 | ||
13395 | case PROCESSOR_RIOS2: | |
13396 | *total = COSTS_N_INSNS (13); | |
13397 | return true; | |
13398 | ||
13399 | case PROCESSOR_RS64A: | |
13400 | *total = (GET_MODE (XEXP (x, 1)) != DImode | |
13401 | ? COSTS_N_INSNS (65) | |
13402 | : COSTS_N_INSNS (67)); | |
13403 | return true; | |
13404 | ||
13405 | case PROCESSOR_MPCCORE: | |
13406 | *total = COSTS_N_INSNS (6); | |
13407 | return true; | |
13408 | ||
13409 | case PROCESSOR_PPC403: | |
13410 | *total = COSTS_N_INSNS (33); | |
13411 | return true; | |
13412 | ||
13413 | case PROCESSOR_PPC405: | |
13414 | *total = COSTS_N_INSNS (35); | |
13415 | return true; | |
13416 | ||
13417 | case PROCESSOR_PPC601: | |
13418 | *total = COSTS_N_INSNS (36); | |
13419 | return true; | |
13420 | ||
13421 | case PROCESSOR_PPC603: | |
13422 | *total = COSTS_N_INSNS (37); | |
13423 | return true; | |
13424 | ||
13425 | case PROCESSOR_PPC604: | |
13426 | case PROCESSOR_PPC604e: | |
13427 | *total = COSTS_N_INSNS (20); | |
13428 | return true; | |
13429 | ||
13430 | case PROCESSOR_PPC620: | |
13431 | case PROCESSOR_PPC630: | |
13432 | case PROCESSOR_POWER4: | |
13433 | *total = (GET_MODE (XEXP (x, 1)) != DImode | |
13434 | ? COSTS_N_INSNS (21) | |
13435 | : COSTS_N_INSNS (37)); | |
13436 | return true; | |
13437 | ||
13438 | case PROCESSOR_PPC750: | |
13439 | case PROCESSOR_PPC8540: | |
13440 | case PROCESSOR_PPC7400: | |
13441 | *total = COSTS_N_INSNS (19); | |
13442 | return true; | |
13443 | ||
13444 | case PROCESSOR_PPC7450: | |
13445 | *total = COSTS_N_INSNS (23); | |
13446 | return true; | |
13447 | ||
13448 | default: | |
13449 | abort (); | |
13450 | } | |
13451 | ||
13452 | case FFS: | |
13453 | *total = COSTS_N_INSNS (4); | |
13454 | return true; | |
13455 | ||
13456 | case MEM: | |
13457 | /* MEM should be slightly more expensive than (plus (reg) (const)) */ | |
13458 | *total = 5; | |
13459 | return true; | |
13460 | ||
13461 | default: | |
13462 | return false; | |
13463 | } | |
13464 | } | |
13465 | ||
34bb030a DE |
13466 | /* A C expression returning the cost of moving data from a register of class |
13467 | CLASS1 to one of CLASS2. */ | |
13468 | ||
13469 | int | |
13470 | rs6000_register_move_cost (mode, from, to) | |
13471 | enum machine_mode mode; | |
13472 | enum reg_class from, to; | |
13473 | { | |
13474 | /* Moves from/to GENERAL_REGS. */ | |
13475 | if (reg_classes_intersect_p (to, GENERAL_REGS) | |
13476 | || reg_classes_intersect_p (from, GENERAL_REGS)) | |
13477 | { | |
13478 | if (! reg_classes_intersect_p (to, GENERAL_REGS)) | |
13479 | from = to; | |
13480 | ||
13481 | if (from == FLOAT_REGS || from == ALTIVEC_REGS) | |
13482 | return (rs6000_memory_move_cost (mode, from, 0) | |
13483 | + rs6000_memory_move_cost (mode, GENERAL_REGS, 0)); | |
13484 | ||
13485 | /* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/ | |
13486 | else if (from == CR_REGS) | |
13487 | return 4; | |
13488 | ||
13489 | else | |
13490 | /* A move will cost one instruction per GPR moved. */ | |
13491 | return 2 * HARD_REGNO_NREGS (0, mode); | |
13492 | } | |
13493 | ||
13494 | /* Moving between two similar registers is just one instruction. */ | |
13495 | else if (reg_classes_intersect_p (to, from)) | |
13496 | return mode == TFmode ? 4 : 2; | |
13497 | ||
13498 | /* Everything else has to go through GENERAL_REGS. */ | |
13499 | else | |
13500 | return (rs6000_register_move_cost (mode, GENERAL_REGS, to) | |
13501 | + rs6000_register_move_cost (mode, from, GENERAL_REGS)); | |
13502 | } | |
13503 | ||
13504 | /* A C expressions returning the cost of moving data of MODE from a register to | |
13505 | or from memory. */ | |
13506 | ||
13507 | int | |
13508 | rs6000_memory_move_cost (mode, class, in) | |
13509 | enum machine_mode mode; | |
13510 | enum reg_class class; | |
13511 | int in ATTRIBUTE_UNUSED; | |
13512 | { | |
13513 | if (reg_classes_intersect_p (class, GENERAL_REGS)) | |
13514 | return 4 * HARD_REGNO_NREGS (0, mode); | |
13515 | else if (reg_classes_intersect_p (class, FLOAT_REGS)) | |
13516 | return 4 * HARD_REGNO_NREGS (32, mode); | |
13517 | else if (reg_classes_intersect_p (class, ALTIVEC_REGS)) | |
13518 | return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode); | |
13519 | else | |
13520 | return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS); | |
13521 | } | |
13522 | ||
17211ab5 | 13523 | #include "gt-rs6000.h" |