]>
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 | 5 | |
5de601cf | 6 | This file is part of GCC. |
9878760c | 7 | |
5de601cf NC |
8 | GCC is free software; you can redistribute it and/or modify it |
9 | under the terms of the GNU General Public License as published | |
10 | by the Free Software Foundation; either version 2, or (at your | |
11 | option) any later version. | |
9878760c | 12 | |
5de601cf NC |
13 | GCC is distributed in the hope that it will be useful, but WITHOUT |
14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
15 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
16 | License for more details. | |
9878760c | 17 | |
5de601cf NC |
18 | You should have received a copy of the GNU General Public License |
19 | along with GCC; see the file COPYING. If not, write to the | |
20 | Free Software Foundation, 59 Temple Place - Suite 330, Boston, | |
21 | 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" |
117dca74 | 53 | #include "cfglayout.h" |
79ae11c4 | 54 | #include "sched-int.h" |
1bc7c5b6 ZW |
55 | #if TARGET_XCOFF |
56 | #include "xcoffout.h" /* get declarations of xcoff_*_section_name */ | |
57 | #endif | |
9b30bae2 | 58 | |
7509c759 MM |
59 | #ifndef TARGET_NO_PROTOTYPE |
60 | #define TARGET_NO_PROTOTYPE 0 | |
61 | #endif | |
62 | ||
d744e06e AH |
63 | #define EASY_VECTOR_15(n, x, y) ((n) >= -16 && (n) <= 15 \ |
64 | && easy_vector_same (x, y)) | |
65 | ||
66 | #define EASY_VECTOR_15_ADD_SELF(n, x, y) ((n) >= 0x10 && (n) <= 0x1e \ | |
67 | && !((n) & 1) \ | |
68 | && easy_vector_same (x, y)) | |
69 | ||
9878760c RK |
70 | #define min(A,B) ((A) < (B) ? (A) : (B)) |
71 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
72 | ||
d1d0c603 JJ |
73 | /* Structure used to define the rs6000 stack */ |
74 | typedef struct rs6000_stack { | |
75 | int first_gp_reg_save; /* first callee saved GP register used */ | |
76 | int first_fp_reg_save; /* first callee saved FP register used */ | |
77 | int first_altivec_reg_save; /* first callee saved AltiVec register used */ | |
78 | int lr_save_p; /* true if the link reg needs to be saved */ | |
79 | int cr_save_p; /* true if the CR reg needs to be saved */ | |
80 | unsigned int vrsave_mask; /* mask of vec registers to save */ | |
81 | int toc_save_p; /* true if the TOC needs to be saved */ | |
82 | int push_p; /* true if we need to allocate stack space */ | |
83 | int calls_p; /* true if the function makes any calls */ | |
84 | enum rs6000_abi abi; /* which ABI to use */ | |
85 | int gp_save_offset; /* offset to save GP regs from initial SP */ | |
86 | int fp_save_offset; /* offset to save FP regs from initial SP */ | |
87 | int altivec_save_offset; /* offset to save AltiVec regs from initial SP */ | |
88 | int lr_save_offset; /* offset to save LR from initial SP */ | |
89 | int cr_save_offset; /* offset to save CR from initial SP */ | |
90 | int vrsave_save_offset; /* offset to save VRSAVE from initial SP */ | |
91 | int spe_gp_save_offset; /* offset to save spe 64-bit gprs */ | |
92 | int toc_save_offset; /* offset to save the TOC pointer */ | |
93 | int varargs_save_offset; /* offset to save the varargs registers */ | |
94 | int ehrd_offset; /* offset to EH return data */ | |
95 | int reg_size; /* register size (4 or 8) */ | |
96 | int varargs_size; /* size to hold V.4 args passed in regs */ | |
97 | HOST_WIDE_INT vars_size; /* variable save area size */ | |
98 | int parm_size; /* outgoing parameter size */ | |
99 | int save_size; /* save area size */ | |
100 | int fixed_size; /* fixed size of stack frame */ | |
101 | int gp_size; /* size of saved GP registers */ | |
102 | int fp_size; /* size of saved FP registers */ | |
103 | int altivec_size; /* size of saved AltiVec registers */ | |
104 | int cr_size; /* size to hold CR if not in save_size */ | |
105 | int lr_size; /* size to hold LR if not in save_size */ | |
106 | int vrsave_size; /* size to hold VRSAVE if not in save_size */ | |
107 | int altivec_padding_size; /* size of altivec alignment padding if | |
108 | not in save_size */ | |
109 | int spe_gp_size; /* size of 64-bit GPR save size for SPE */ | |
110 | int spe_padding_size; | |
111 | int toc_size; /* size to hold TOC if not in save_size */ | |
112 | HOST_WIDE_INT total_size; /* total bytes allocated for stack */ | |
113 | int spe_64bit_regs_used; | |
114 | } rs6000_stack_t; | |
115 | ||
5248c961 RK |
116 | /* Target cpu type */ |
117 | ||
118 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
119 | struct rs6000_cpu_select rs6000_select[3] = |
120 | { | |
815cdc52 MM |
121 | /* switch name, tune arch */ |
122 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
123 | { (const char *)0, "-mcpu=", 1, 1 }, | |
124 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 125 | }; |
5248c961 | 126 | |
79ae11c4 DN |
127 | /* Support adjust_priority scheduler hook |
128 | and -mprioritize-restricted-insns= option. */ | |
129 | const char *rs6000_sched_restricted_insns_priority_str; | |
130 | int rs6000_sched_restricted_insns_priority; | |
131 | ||
569fa502 DN |
132 | /* Support for -msched-costly-dep option. */ |
133 | const char *rs6000_sched_costly_dep_str; | |
134 | enum rs6000_dependence_cost rs6000_sched_costly_dep; | |
135 | ||
cbe26ab8 DN |
136 | /* Support for -minsert-sched-nops option. */ |
137 | const char *rs6000_sched_insert_nops_str; | |
138 | enum rs6000_nop_insertion rs6000_sched_insert_nops; | |
139 | ||
6fa3f289 ZW |
140 | /* Size of long double */ |
141 | const char *rs6000_long_double_size_string; | |
142 | int rs6000_long_double_type_size; | |
143 | ||
144 | /* Whether -mabi=altivec has appeared */ | |
145 | int rs6000_altivec_abi; | |
146 | ||
08b57fb3 AH |
147 | /* Whether VRSAVE instructions should be generated. */ |
148 | int rs6000_altivec_vrsave; | |
149 | ||
150 | /* String from -mvrsave= option. */ | |
151 | const char *rs6000_altivec_vrsave_string; | |
152 | ||
a3170dc6 AH |
153 | /* Nonzero if we want SPE ABI extensions. */ |
154 | int rs6000_spe_abi; | |
155 | ||
156 | /* Whether isel instructions should be generated. */ | |
157 | int rs6000_isel; | |
158 | ||
993f19a8 AH |
159 | /* Whether SPE simd instructions should be generated. */ |
160 | int rs6000_spe; | |
161 | ||
5da702b1 AH |
162 | /* Nonzero if floating point operations are done in the GPRs. */ |
163 | int rs6000_float_gprs = 0; | |
164 | ||
165 | /* String from -mfloat-gprs=. */ | |
166 | const char *rs6000_float_gprs_string; | |
a3170dc6 AH |
167 | |
168 | /* String from -misel=. */ | |
169 | const char *rs6000_isel_string; | |
170 | ||
993f19a8 AH |
171 | /* String from -mspe=. */ |
172 | const char *rs6000_spe_string; | |
173 | ||
a0ab749a | 174 | /* Set to nonzero once AIX common-mode calls have been defined. */ |
bbfb86aa | 175 | static GTY(()) int common_mode_defined; |
c81bebd7 | 176 | |
9878760c RK |
177 | /* Save information from a "cmpxx" operation until the branch or scc is |
178 | emitted. */ | |
9878760c RK |
179 | rtx rs6000_compare_op0, rs6000_compare_op1; |
180 | int rs6000_compare_fp_p; | |
874a0744 | 181 | |
874a0744 MM |
182 | /* Label number of label created for -mrelocatable, to call to so we can |
183 | get the address of the GOT section */ | |
184 | int rs6000_pic_labelno; | |
c81bebd7 | 185 | |
b91da81f | 186 | #ifdef USING_ELFOS_H |
c81bebd7 | 187 | /* Which abi to adhere to */ |
9739c90c | 188 | const char *rs6000_abi_name; |
d9407988 MM |
189 | |
190 | /* Semantics of the small data area */ | |
191 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
192 | ||
193 | /* Which small data model to use */ | |
815cdc52 | 194 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
195 | |
196 | /* Counter for labels which are to be placed in .fixup. */ | |
197 | int fixuplabelno = 0; | |
874a0744 | 198 | #endif |
4697a36c | 199 | |
c4501e62 JJ |
200 | /* Bit size of immediate TLS offsets and string from which it is decoded. */ |
201 | int rs6000_tls_size = 32; | |
202 | const char *rs6000_tls_size_string; | |
203 | ||
b6c9286a MM |
204 | /* ABI enumeration available for subtarget to use. */ |
205 | enum rs6000_abi rs6000_current_abi; | |
206 | ||
0ac081f6 AH |
207 | /* ABI string from -mabi= option. */ |
208 | const char *rs6000_abi_string; | |
209 | ||
38c1f2d7 | 210 | /* Debug flags */ |
815cdc52 | 211 | const char *rs6000_debug_name; |
38c1f2d7 MM |
212 | int rs6000_debug_stack; /* debug stack applications */ |
213 | int rs6000_debug_arg; /* debug argument handling */ | |
214 | ||
6035d635 | 215 | /* Opaque types. */ |
2abe3e28 | 216 | static GTY(()) tree opaque_V2SI_type_node; |
2abe3e28 | 217 | static GTY(()) tree opaque_V2SF_type_node; |
6035d635 | 218 | static GTY(()) tree opaque_p_V2SI_type_node; |
2abe3e28 | 219 | |
57ac7be9 AM |
220 | const char *rs6000_traceback_name; |
221 | static enum { | |
222 | traceback_default = 0, | |
223 | traceback_none, | |
224 | traceback_part, | |
225 | traceback_full | |
226 | } rs6000_traceback; | |
227 | ||
38c1f2d7 MM |
228 | /* Flag to say the TOC is initialized */ |
229 | int toc_initialized; | |
9ebbca7d | 230 | char toc_label_name[10]; |
38c1f2d7 | 231 | |
9ebbca7d GK |
232 | /* Alias set for saves and restores from the rs6000 stack. */ |
233 | static int rs6000_sr_alias_set; | |
c8023011 | 234 | |
a5c76ee6 ZW |
235 | /* Call distance, overridden by -mlongcall and #pragma longcall(1). |
236 | The only place that looks at this is rs6000_set_default_type_attributes; | |
237 | everywhere else should rely on the presence or absence of a longcall | |
238 | attribute on the function declaration. */ | |
239 | int rs6000_default_long_calls; | |
240 | const char *rs6000_longcall_switch; | |
241 | ||
025d9908 KH |
242 | /* Control alignment for fields within structures. */ |
243 | /* String from -malign-XXXXX. */ | |
244 | const char *rs6000_alignment_string; | |
245 | int rs6000_alignment_flags; | |
246 | ||
a3170dc6 AH |
247 | struct builtin_description |
248 | { | |
249 | /* mask is not const because we're going to alter it below. This | |
250 | nonsense will go away when we rewrite the -march infrastructure | |
251 | to give us more target flag bits. */ | |
252 | unsigned int mask; | |
253 | const enum insn_code icode; | |
254 | const char *const name; | |
255 | const enum rs6000_builtins code; | |
256 | }; | |
257 | ||
a2369ed3 DJ |
258 | static bool rs6000_function_ok_for_sibcall (tree, tree); |
259 | static int num_insns_constant_wide (HOST_WIDE_INT); | |
260 | static void validate_condition_mode (enum rtx_code, enum machine_mode); | |
261 | static rtx rs6000_generate_compare (enum rtx_code); | |
262 | static void rs6000_maybe_dead (rtx); | |
263 | static void rs6000_emit_stack_tie (void); | |
264 | static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx); | |
265 | static rtx spe_synthesize_frame_save (rtx); | |
266 | static bool spe_func_has_64bit_regs_p (void); | |
b20a9cca | 267 | static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int, |
d1d0c603 | 268 | int, HOST_WIDE_INT); |
a2369ed3 DJ |
269 | static rtx gen_frame_mem_offset (enum machine_mode, rtx, int); |
270 | static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int); | |
271 | static unsigned rs6000_hash_constant (rtx); | |
272 | static unsigned toc_hash_function (const void *); | |
273 | static int toc_hash_eq (const void *, const void *); | |
274 | static int constant_pool_expr_1 (rtx, int *, int *); | |
275 | static bool constant_pool_expr_p (rtx); | |
276 | static bool toc_relative_expr_p (rtx); | |
277 | static bool legitimate_small_data_p (enum machine_mode, rtx); | |
278 | static bool legitimate_offset_address_p (enum machine_mode, rtx, int); | |
279 | static bool legitimate_indexed_address_p (rtx, int); | |
280 | static bool legitimate_indirect_address_p (rtx, int); | |
4c81e946 | 281 | static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode); |
a2369ed3 DJ |
282 | static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int); |
283 | static struct machine_function * rs6000_init_machine_status (void); | |
284 | static bool rs6000_assemble_integer (rtx, unsigned int, int); | |
5add3202 | 285 | #ifdef HAVE_GAS_HIDDEN |
a2369ed3 | 286 | static void rs6000_assemble_visibility (tree, int); |
5add3202 | 287 | #endif |
a2369ed3 DJ |
288 | static int rs6000_ra_ever_killed (void); |
289 | static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *); | |
b86fe7b4 | 290 | extern const struct attribute_spec rs6000_attribute_table[]; |
a2369ed3 DJ |
291 | static void rs6000_set_default_type_attributes (tree); |
292 | static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT); | |
293 | static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT); | |
b20a9cca AM |
294 | static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, |
295 | tree); | |
a2369ed3 | 296 | static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT); |
c6e8c921 | 297 | static bool rs6000_return_in_memory (tree, tree); |
a2369ed3 | 298 | static void rs6000_file_start (void); |
7c262518 | 299 | #if TARGET_ELF |
a2369ed3 DJ |
300 | static unsigned int rs6000_elf_section_type_flags (tree, const char *, int); |
301 | static void rs6000_elf_asm_out_constructor (rtx, int); | |
302 | static void rs6000_elf_asm_out_destructor (rtx, int); | |
303 | static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT); | |
304 | static void rs6000_elf_unique_section (tree, int); | |
305 | static void rs6000_elf_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 306 | unsigned HOST_WIDE_INT); |
a56d7372 | 307 | static void rs6000_elf_encode_section_info (tree, rtx, int) |
0e5dbd9b | 308 | ATTRIBUTE_UNUSED; |
a2369ed3 | 309 | static bool rs6000_elf_in_small_data_p (tree); |
7c262518 | 310 | #endif |
cbaaba19 | 311 | #if TARGET_XCOFF |
a2369ed3 DJ |
312 | static void rs6000_xcoff_asm_globalize_label (FILE *, const char *); |
313 | static void rs6000_xcoff_asm_named_section (const char *, unsigned int); | |
314 | static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT); | |
315 | static void rs6000_xcoff_unique_section (tree, int); | |
316 | static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 317 | unsigned HOST_WIDE_INT); |
a2369ed3 DJ |
318 | static const char * rs6000_xcoff_strip_name_encoding (const char *); |
319 | static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int); | |
320 | static void rs6000_xcoff_file_start (void); | |
321 | static void rs6000_xcoff_file_end (void); | |
f1384257 AM |
322 | #endif |
323 | #if TARGET_MACHO | |
a2369ed3 | 324 | static bool rs6000_binds_local_p (tree); |
f1384257 | 325 | #endif |
a2369ed3 DJ |
326 | static int rs6000_use_dfa_pipeline_interface (void); |
327 | static int rs6000_variable_issue (FILE *, int, rtx, int); | |
328 | static bool rs6000_rtx_costs (rtx, int, int, int *); | |
329 | static int rs6000_adjust_cost (rtx, rtx, rtx, int); | |
cbe26ab8 | 330 | static bool is_microcoded_insn (rtx); |
79ae11c4 | 331 | static int is_dispatch_slot_restricted (rtx); |
cbe26ab8 DN |
332 | static bool is_cracked_insn (rtx); |
333 | static bool is_branch_slot_insn (rtx); | |
a2369ed3 DJ |
334 | static int rs6000_adjust_priority (rtx, int); |
335 | static int rs6000_issue_rate (void); | |
569fa502 | 336 | static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int); |
cbe26ab8 DN |
337 | static rtx get_next_active_insn (rtx, rtx); |
338 | static bool insn_terminates_group_p (rtx , enum group_termination); | |
339 | static bool is_costly_group (rtx *, rtx); | |
340 | static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *); | |
341 | static int redefine_groups (FILE *, int, rtx, rtx); | |
342 | static int pad_groups (FILE *, int, rtx, rtx); | |
343 | static void rs6000_sched_finish (FILE *, int); | |
a2369ed3 DJ |
344 | static int rs6000_use_sched_lookahead (void); |
345 | ||
346 | static void rs6000_init_builtins (void); | |
347 | static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx); | |
348 | static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx); | |
349 | static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx); | |
350 | static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int); | |
351 | static void altivec_init_builtins (void); | |
352 | static void rs6000_common_init_builtins (void); | |
c15c90bb | 353 | static void rs6000_init_libfuncs (void); |
a2369ed3 | 354 | |
b20a9cca AM |
355 | static void enable_mask_for_builtins (struct builtin_description *, int, |
356 | enum rs6000_builtins, | |
357 | enum rs6000_builtins); | |
a2369ed3 DJ |
358 | static void spe_init_builtins (void); |
359 | static rtx spe_expand_builtin (tree, rtx, bool *); | |
360 | static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx); | |
361 | static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx); | |
362 | static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx); | |
d1d0c603 JJ |
363 | static rs6000_stack_t *rs6000_stack_info (void); |
364 | static void debug_stack_info (rs6000_stack_t *); | |
a2369ed3 DJ |
365 | |
366 | static rtx altivec_expand_builtin (tree, rtx, bool *); | |
367 | static rtx altivec_expand_ld_builtin (tree, rtx, bool *); | |
368 | static rtx altivec_expand_st_builtin (tree, rtx, bool *); | |
369 | static rtx altivec_expand_dst_builtin (tree, rtx, bool *); | |
370 | static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx); | |
371 | static rtx altivec_expand_predicate_builtin (enum insn_code, | |
372 | const char *, tree, rtx); | |
b4a62fa0 | 373 | static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx); |
a2369ed3 DJ |
374 | static rtx altivec_expand_stv_builtin (enum insn_code, tree); |
375 | static void rs6000_parse_abi_options (void); | |
376 | static void rs6000_parse_alignment_option (void); | |
377 | static void rs6000_parse_tls_size_option (void); | |
5da702b1 | 378 | static void rs6000_parse_yes_no_option (const char *, const char *, int *); |
a2369ed3 DJ |
379 | static int first_altivec_reg_to_save (void); |
380 | static unsigned int compute_vrsave_mask (void); | |
381 | static void is_altivec_return_reg (rtx, void *); | |
382 | static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int); | |
383 | int easy_vector_constant (rtx, enum machine_mode); | |
384 | static int easy_vector_same (rtx, enum machine_mode); | |
385 | static bool is_ev64_opaque_type (tree); | |
386 | static rtx rs6000_dwarf_register_span (rtx); | |
387 | static rtx rs6000_legitimize_tls_address (rtx, enum tls_model); | |
388 | static rtx rs6000_tls_get_addr (void); | |
389 | static rtx rs6000_got_sym (void); | |
390 | static inline int rs6000_tls_symbol_ref_1 (rtx *, void *); | |
391 | static const char *rs6000_get_some_local_dynamic_name (void); | |
392 | static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *); | |
ded9bf77 | 393 | static rtx rs6000_complex_function_value (enum machine_mode); |
b20a9cca | 394 | static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *, |
a2369ed3 | 395 | enum machine_mode, tree); |
b78d48dd FJ |
396 | static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *, |
397 | enum machine_mode, tree, int); | |
5985c7a6 | 398 | static void rs6000_move_block_from_reg(int regno, rtx x, int nregs); |
c6e8c921 GK |
399 | static void setup_incoming_varargs (CUMULATIVE_ARGS *, |
400 | enum machine_mode, tree, | |
401 | int *, int); | |
efdba735 SH |
402 | #if TARGET_MACHO |
403 | static void macho_branch_islands (void); | |
404 | static void add_compiler_branch_island (tree, tree, int); | |
405 | static int no_previous_def (tree function_name); | |
406 | static tree get_prev_label (tree function_name); | |
407 | #endif | |
408 | ||
c35d187f | 409 | static tree rs6000_build_builtin_va_list (void); |
17211ab5 GK |
410 | |
411 | /* Hash table stuff for keeping track of TOC entries. */ | |
412 | ||
413 | struct toc_hash_struct GTY(()) | |
414 | { | |
415 | /* `key' will satisfy CONSTANT_P; in fact, it will satisfy | |
416 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */ | |
417 | rtx key; | |
418 | enum machine_mode key_mode; | |
419 | int labelno; | |
420 | }; | |
421 | ||
422 | static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table; | |
c81bebd7 MM |
423 | \f |
424 | /* Default register names. */ | |
425 | char rs6000_reg_names[][8] = | |
426 | { | |
802a0058 MM |
427 | "0", "1", "2", "3", "4", "5", "6", "7", |
428 | "8", "9", "10", "11", "12", "13", "14", "15", | |
429 | "16", "17", "18", "19", "20", "21", "22", "23", | |
430 | "24", "25", "26", "27", "28", "29", "30", "31", | |
431 | "0", "1", "2", "3", "4", "5", "6", "7", | |
432 | "8", "9", "10", "11", "12", "13", "14", "15", | |
433 | "16", "17", "18", "19", "20", "21", "22", "23", | |
434 | "24", "25", "26", "27", "28", "29", "30", "31", | |
435 | "mq", "lr", "ctr","ap", | |
436 | "0", "1", "2", "3", "4", "5", "6", "7", | |
0ac081f6 AH |
437 | "xer", |
438 | /* AltiVec registers. */ | |
0cd5e3a1 AH |
439 | "0", "1", "2", "3", "4", "5", "6", "7", |
440 | "8", "9", "10", "11", "12", "13", "14", "15", | |
441 | "16", "17", "18", "19", "20", "21", "22", "23", | |
442 | "24", "25", "26", "27", "28", "29", "30", "31", | |
59a4c851 AH |
443 | "vrsave", "vscr", |
444 | /* SPE registers. */ | |
445 | "spe_acc", "spefscr" | |
c81bebd7 MM |
446 | }; |
447 | ||
448 | #ifdef TARGET_REGNAMES | |
8b60264b | 449 | static const char alt_reg_names[][8] = |
c81bebd7 | 450 | { |
802a0058 MM |
451 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
452 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
453 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
454 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
455 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
456 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
457 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
458 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
459 | "mq", "lr", "ctr", "ap", | |
460 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
0ac081f6 | 461 | "xer", |
59a4c851 | 462 | /* AltiVec registers. */ |
0ac081f6 | 463 | "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7", |
59a4c851 AH |
464 | "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15", |
465 | "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23", | |
466 | "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31", | |
467 | "vrsave", "vscr", | |
468 | /* SPE registers. */ | |
469 | "spe_acc", "spefscr" | |
c81bebd7 MM |
470 | }; |
471 | #endif | |
9878760c | 472 | \f |
daf11973 MM |
473 | #ifndef MASK_STRICT_ALIGN |
474 | #define MASK_STRICT_ALIGN 0 | |
475 | #endif | |
ffcfcb5f AM |
476 | #ifndef TARGET_PROFILE_KERNEL |
477 | #define TARGET_PROFILE_KERNEL 0 | |
478 | #endif | |
3961e8fe RH |
479 | |
480 | /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */ | |
481 | #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO)) | |
c4501e62 JJ |
482 | |
483 | /* Return 1 for a symbol ref for a thread-local storage symbol. */ | |
484 | #define RS6000_SYMBOL_REF_TLS_P(RTX) \ | |
485 | (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0) | |
672a6f42 NB |
486 | \f |
487 | /* Initialize the GCC target structure. */ | |
91d231cb JM |
488 | #undef TARGET_ATTRIBUTE_TABLE |
489 | #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table | |
a5c76ee6 ZW |
490 | #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
491 | #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes | |
daf11973 | 492 | |
301d03af RS |
493 | #undef TARGET_ASM_ALIGNED_DI_OP |
494 | #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP | |
495 | ||
496 | /* Default unaligned ops are only provided for ELF. Find the ops needed | |
497 | for non-ELF systems. */ | |
498 | #ifndef OBJECT_FORMAT_ELF | |
cbaaba19 | 499 | #if TARGET_XCOFF |
ae6c1efd | 500 | /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on |
301d03af RS |
501 | 64-bit targets. */ |
502 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
503 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2," | |
504 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
505 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4," | |
506 | #undef TARGET_ASM_UNALIGNED_DI_OP | |
507 | #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8," | |
508 | #else | |
509 | /* For Darwin. */ | |
510 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
511 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" | |
512 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
513 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" | |
514 | #endif | |
515 | #endif | |
516 | ||
517 | /* This hook deals with fixups for relocatable code and DI-mode objects | |
518 | in 64-bit code. */ | |
519 | #undef TARGET_ASM_INTEGER | |
520 | #define TARGET_ASM_INTEGER rs6000_assemble_integer | |
521 | ||
93638d7a AM |
522 | #ifdef HAVE_GAS_HIDDEN |
523 | #undef TARGET_ASM_ASSEMBLE_VISIBILITY | |
524 | #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility | |
525 | #endif | |
526 | ||
c4501e62 JJ |
527 | #undef TARGET_HAVE_TLS |
528 | #define TARGET_HAVE_TLS HAVE_AS_TLS | |
529 | ||
530 | #undef TARGET_CANNOT_FORCE_CONST_MEM | |
531 | #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p | |
532 | ||
08c148a8 NB |
533 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
534 | #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue | |
535 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
536 | #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue | |
537 | ||
b54cf83a DE |
538 | #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE |
539 | #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface | |
b54cf83a DE |
540 | #undef TARGET_SCHED_VARIABLE_ISSUE |
541 | #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue | |
542 | ||
c237e94a ZW |
543 | #undef TARGET_SCHED_ISSUE_RATE |
544 | #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate | |
545 | #undef TARGET_SCHED_ADJUST_COST | |
546 | #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost | |
547 | #undef TARGET_SCHED_ADJUST_PRIORITY | |
548 | #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority | |
569fa502 DN |
549 | #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE |
550 | #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence | |
cbe26ab8 DN |
551 | #undef TARGET_SCHED_FINISH |
552 | #define TARGET_SCHED_FINISH rs6000_sched_finish | |
c237e94a | 553 | |
be12c2b0 VM |
554 | #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD |
555 | #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead | |
556 | ||
0ac081f6 AH |
557 | #undef TARGET_INIT_BUILTINS |
558 | #define TARGET_INIT_BUILTINS rs6000_init_builtins | |
559 | ||
560 | #undef TARGET_EXPAND_BUILTIN | |
561 | #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin | |
562 | ||
c15c90bb ZW |
563 | #undef TARGET_INIT_LIBFUNCS |
564 | #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs | |
565 | ||
f1384257 | 566 | #if TARGET_MACHO |
0e5dbd9b DE |
567 | #undef TARGET_BINDS_LOCAL_P |
568 | #define TARGET_BINDS_LOCAL_P rs6000_binds_local_p | |
f1384257 | 569 | #endif |
0e5dbd9b | 570 | |
3961e8fe RH |
571 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
572 | #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk | |
573 | ||
3961e8fe | 574 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
5b71a4e7 | 575 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true |
00b960c7 | 576 | |
4977bab6 ZW |
577 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
578 | #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall | |
579 | ||
3c50106f RH |
580 | #undef TARGET_RTX_COSTS |
581 | #define TARGET_RTX_COSTS rs6000_rtx_costs | |
dcefdf67 RH |
582 | #undef TARGET_ADDRESS_COST |
583 | #define TARGET_ADDRESS_COST hook_int_rtx_0 | |
3c50106f | 584 | |
c8e4f0e9 AH |
585 | #undef TARGET_VECTOR_OPAQUE_P |
586 | #define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type | |
62e1dfcf | 587 | |
96714395 AH |
588 | #undef TARGET_DWARF_REGISTER_SPAN |
589 | #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span | |
590 | ||
c6e8c921 GK |
591 | /* On rs6000, function arguments are promoted, as are function return |
592 | values. */ | |
593 | #undef TARGET_PROMOTE_FUNCTION_ARGS | |
594 | #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true | |
595 | #undef TARGET_PROMOTE_FUNCTION_RETURN | |
596 | #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true | |
597 | ||
598 | /* Structure return values are passed as an extra parameter. */ | |
599 | #undef TARGET_STRUCT_VALUE_RTX | |
600 | #define TARGET_STRUCT_VALUE_RTX hook_rtx_tree_int_null | |
601 | ||
602 | #undef TARGET_RETURN_IN_MEMORY | |
603 | #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory | |
604 | ||
605 | #undef TARGET_SETUP_INCOMING_VARARGS | |
606 | #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs | |
607 | ||
608 | /* Always strict argument naming on rs6000. */ | |
609 | #undef TARGET_STRICT_ARGUMENT_NAMING | |
610 | #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true | |
611 | #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED | |
612 | #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true | |
613 | ||
c35d187f RH |
614 | #undef TARGET_BUILD_BUILTIN_VA_LIST |
615 | #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list | |
616 | ||
f6897b10 | 617 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 618 | \f |
5248c961 RK |
619 | /* Override command line options. Mostly we process the processor |
620 | type and sometimes adjust other TARGET_ options. */ | |
621 | ||
622 | void | |
d779d0dc | 623 | rs6000_override_options (const char *default_cpu) |
5248c961 | 624 | { |
c4d38ccb | 625 | size_t i, j; |
8e3f41e7 | 626 | struct rs6000_cpu_select *ptr; |
5248c961 | 627 | |
85638c0d RK |
628 | /* Simplify the entries below by making a mask for any POWER |
629 | variant and any PowerPC variant. */ | |
630 | ||
f05fd841 GK |
631 | #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING) |
632 | #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \ | |
633 | | MASK_PPC_GFXOPT | MASK_POWERPC64) | |
634 | #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT) | |
85638c0d | 635 | |
5248c961 RK |
636 | static struct ptt |
637 | { | |
8b60264b KG |
638 | const char *const name; /* Canonical processor name. */ |
639 | const enum processor_type processor; /* Processor type enum value. */ | |
640 | const int target_enable; /* Target flags to enable. */ | |
f05fd841 | 641 | const int target_disable; /* Target flags to disable. */ |
8b60264b | 642 | } const processor_target_table[] |
cf27b467 | 643 | = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS, |
f05fd841 | 644 | POWER_MASKS | POWERPC_MASKS}, |
db7f1e43 | 645 | {"power", PROCESSOR_POWER, |
938937d8 | 646 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
f05fd841 | 647 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
8e3f41e7 MM |
648 | {"power2", PROCESSOR_POWER, |
649 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
f05fd841 | 650 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
c71791e0 | 651 | {"power3", PROCESSOR_PPC630, |
f05fd841 GK |
652 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
653 | POWER_MASKS}, | |
309323c2 | 654 | {"power4", PROCESSOR_POWER4, |
ffa22984 | 655 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS | MASK_MFCRF, |
f05fd841 | 656 | POWER_MASKS}, |
db7f1e43 | 657 | {"powerpc", PROCESSOR_POWERPC, |
f05fd841 GK |
658 | MASK_POWERPC | MASK_NEW_MNEMONICS, |
659 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
3cb999d8 | 660 | {"powerpc64", PROCESSOR_POWERPC64, |
f05fd841 GK |
661 | MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS, |
662 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
db7f1e43 | 663 | {"rios", PROCESSOR_RIOS1, |
938937d8 | 664 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
f05fd841 | 665 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
db7f1e43 | 666 | {"rios1", PROCESSOR_RIOS1, |
938937d8 | 667 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
f05fd841 | 668 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
db7f1e43 | 669 | {"rsc", PROCESSOR_PPC601, |
938937d8 | 670 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
f05fd841 | 671 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
db7f1e43 | 672 | {"rsc1", PROCESSOR_PPC601, |
938937d8 | 673 | MASK_POWER | MASK_MULTIPLE | MASK_STRING, |
f05fd841 | 674 | MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
db7f1e43 | 675 | {"rios2", PROCESSOR_RIOS2, |
938937d8 | 676 | MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2, |
f05fd841 | 677 | POWERPC_MASKS | MASK_NEW_MNEMONICS}, |
3cb999d8 | 678 | {"rs64a", PROCESSOR_RS64A, |
f05fd841 GK |
679 | MASK_POWERPC | MASK_NEW_MNEMONICS, |
680 | POWER_MASKS | POWERPC_OPT_MASKS}, | |
a3a1dbf6 | 681 | {"401", PROCESSOR_PPC403, |
f05fd841 GK |
682 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
683 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
49a0b204 | 684 | {"403", PROCESSOR_PPC403, |
f05fd841 GK |
685 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN, |
686 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
d7a5e253 | 687 | {"405", PROCESSOR_PPC405, |
f05fd841 GK |
688 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
689 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
02ca7595 | 690 | {"405fp", PROCESSOR_PPC405, |
f05fd841 GK |
691 | MASK_POWERPC | MASK_NEW_MNEMONICS, |
692 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
02ca7595 | 693 | {"440", PROCESSOR_PPC440, |
f05fd841 GK |
694 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
695 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
02ca7595 | 696 | {"440fp", PROCESSOR_PPC440, |
f05fd841 GK |
697 | MASK_POWERPC | MASK_NEW_MNEMONICS, |
698 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 | 699 | {"505", PROCESSOR_MPCCORE, |
f05fd841 GK |
700 | MASK_POWERPC | MASK_NEW_MNEMONICS, |
701 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 702 | {"601", PROCESSOR_PPC601, |
f05fd841 GK |
703 | MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING, |
704 | MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
1ec26da6 | 705 | {"602", PROCESSOR_PPC603, |
f05fd841 GK |
706 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
707 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
5248c961 | 708 | {"603", PROCESSOR_PPC603, |
f05fd841 GK |
709 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
710 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a | 711 | {"603e", PROCESSOR_PPC603, |
f05fd841 GK |
712 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
713 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b5370a88 | 714 | {"ec603e", PROCESSOR_PPC603, |
f05fd841 GK |
715 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
716 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
5248c961 | 717 | {"604", PROCESSOR_PPC604, |
f05fd841 GK |
718 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
719 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
cac8ce95 | 720 | {"604e", PROCESSOR_PPC604e, |
f05fd841 GK |
721 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
722 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
b6c9286a | 723 | {"620", PROCESSOR_PPC620, |
f05fd841 GK |
724 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
725 | POWER_MASKS}, | |
3cb999d8 | 726 | {"630", PROCESSOR_PPC630, |
f05fd841 GK |
727 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
728 | POWER_MASKS}, | |
bef84347 | 729 | {"740", PROCESSOR_PPC750, |
f05fd841 GK |
730 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
731 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
bef84347 | 732 | {"750", PROCESSOR_PPC750, |
f05fd841 GK |
733 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
734 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
49ffe578 SP |
735 | {"G3", PROCESSOR_PPC750, |
736 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
737 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
a4f6c312 | 738 | {"7400", PROCESSOR_PPC7400, |
f05fd841 GK |
739 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
740 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
a4f6c312 | 741 | {"7450", PROCESSOR_PPC7450, |
f05fd841 GK |
742 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
743 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
49ffe578 SP |
744 | {"G4", PROCESSOR_PPC7450, |
745 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, | |
746 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
a3170dc6 | 747 | {"8540", PROCESSOR_PPC8540, |
f05fd841 GK |
748 | MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS, |
749 | POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64}, | |
07e6159a | 750 | {"801", PROCESSOR_MPCCORE, |
f05fd841 GK |
751 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
752 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 | 753 | {"821", PROCESSOR_MPCCORE, |
f05fd841 GK |
754 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
755 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
07e6159a | 756 | {"823", PROCESSOR_MPCCORE, |
f05fd841 GK |
757 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
758 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
cf27b467 | 759 | {"860", PROCESSOR_MPCCORE, |
f05fd841 GK |
760 | MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS, |
761 | POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}, | |
7177e720 | 762 | {"970", PROCESSOR_POWER4, |
ffa22984 | 763 | MASK_POWERPC | POWERPC_OPT_MASKS | MASK_NEW_MNEMONICS | MASK_MFCRF, |
49ffe578 SP |
764 | POWER_MASKS}, |
765 | {"G5", PROCESSOR_POWER4, | |
ffa22984 | 766 | MASK_POWERPC | POWERPC_OPT_MASKS | MASK_NEW_MNEMONICS | MASK_MFCRF, |
f05fd841 | 767 | POWER_MASKS}}; |
5248c961 | 768 | |
ca7558fc | 769 | const size_t ptt_size = ARRAY_SIZE (processor_target_table); |
5248c961 | 770 | |
a4f6c312 SS |
771 | /* Save current -mmultiple/-mno-multiple status. */ |
772 | int multiple = TARGET_MULTIPLE; | |
773 | /* Save current -mstring/-mno-string status. */ | |
774 | int string = TARGET_STRING; | |
8a61d227 | 775 | |
a4f6c312 | 776 | /* Identify the processor type. */ |
8e3f41e7 | 777 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 778 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 779 | |
b6a1cbae | 780 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 781 | { |
8e3f41e7 MM |
782 | ptr = &rs6000_select[i]; |
783 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 784 | { |
8e3f41e7 MM |
785 | for (j = 0; j < ptt_size; j++) |
786 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
787 | { | |
788 | if (ptr->set_tune_p) | |
789 | rs6000_cpu = processor_target_table[j].processor; | |
790 | ||
791 | if (ptr->set_arch_p) | |
792 | { | |
793 | target_flags |= processor_target_table[j].target_enable; | |
f05fd841 | 794 | target_flags &= ~processor_target_table[j].target_disable; |
8e3f41e7 MM |
795 | } |
796 | break; | |
797 | } | |
798 | ||
4406229e | 799 | if (j == ptt_size) |
8e3f41e7 | 800 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
801 | } |
802 | } | |
8a61d227 | 803 | |
993f19a8 | 804 | if (TARGET_E500) |
a3170dc6 AH |
805 | rs6000_isel = 1; |
806 | ||
dff9f1b6 DE |
807 | /* If we are optimizing big endian systems for space, use the load/store |
808 | multiple and string instructions. */ | |
ef792183 | 809 | if (BYTES_BIG_ENDIAN && optimize_size) |
dff9f1b6 | 810 | target_flags |= MASK_MULTIPLE | MASK_STRING; |
ef792183 | 811 | |
8a61d227 MM |
812 | /* If -mmultiple or -mno-multiple was explicitly used, don't |
813 | override with the processor default */ | |
b21fb038 | 814 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
8a61d227 | 815 | target_flags = (target_flags & ~MASK_MULTIPLE) | multiple; |
7e69e155 | 816 | |
a4f6c312 SS |
817 | /* If -mstring or -mno-string was explicitly used, don't override |
818 | with the processor default. */ | |
b21fb038 | 819 | if ((target_flags_explicit & MASK_STRING) != 0) |
1f5515bf | 820 | target_flags = (target_flags & ~MASK_STRING) | string; |
938937d8 | 821 | |
a4f6c312 SS |
822 | /* Don't allow -mmultiple or -mstring on little endian systems |
823 | unless the cpu is a 750, because the hardware doesn't support the | |
824 | instructions used in little endian mode, and causes an alignment | |
825 | trap. The 750 does not cause an alignment trap (except when the | |
826 | target is unaligned). */ | |
bef84347 | 827 | |
b21fb038 | 828 | if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
829 | { |
830 | if (TARGET_MULTIPLE) | |
831 | { | |
832 | target_flags &= ~MASK_MULTIPLE; | |
b21fb038 | 833 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
7e69e155 MM |
834 | warning ("-mmultiple is not supported on little endian systems"); |
835 | } | |
836 | ||
837 | if (TARGET_STRING) | |
838 | { | |
839 | target_flags &= ~MASK_STRING; | |
b21fb038 | 840 | if ((target_flags_explicit & MASK_STRING) != 0) |
938937d8 | 841 | warning ("-mstring is not supported on little endian systems"); |
7e69e155 MM |
842 | } |
843 | } | |
3933e0e1 | 844 | |
38c1f2d7 MM |
845 | /* Set debug flags */ |
846 | if (rs6000_debug_name) | |
847 | { | |
bfc79d3b | 848 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 849 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 850 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 851 | rs6000_debug_stack = 1; |
bfc79d3b | 852 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
853 | rs6000_debug_arg = 1; |
854 | else | |
c725bd79 | 855 | error ("unknown -mdebug-%s switch", rs6000_debug_name); |
38c1f2d7 MM |
856 | } |
857 | ||
57ac7be9 AM |
858 | if (rs6000_traceback_name) |
859 | { | |
860 | if (! strncmp (rs6000_traceback_name, "full", 4)) | |
861 | rs6000_traceback = traceback_full; | |
862 | else if (! strncmp (rs6000_traceback_name, "part", 4)) | |
863 | rs6000_traceback = traceback_part; | |
864 | else if (! strncmp (rs6000_traceback_name, "no", 2)) | |
865 | rs6000_traceback = traceback_none; | |
866 | else | |
867 | error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'", | |
868 | rs6000_traceback_name); | |
869 | } | |
870 | ||
6fa3f289 ZW |
871 | /* Set size of long double */ |
872 | rs6000_long_double_type_size = 64; | |
873 | if (rs6000_long_double_size_string) | |
874 | { | |
875 | char *tail; | |
876 | int size = strtol (rs6000_long_double_size_string, &tail, 10); | |
877 | if (*tail != '\0' || (size != 64 && size != 128)) | |
878 | error ("Unknown switch -mlong-double-%s", | |
879 | rs6000_long_double_size_string); | |
880 | else | |
881 | rs6000_long_double_type_size = size; | |
882 | } | |
883 | ||
0ac081f6 AH |
884 | /* Handle -mabi= options. */ |
885 | rs6000_parse_abi_options (); | |
886 | ||
025d9908 KH |
887 | /* Handle -malign-XXXXX option. */ |
888 | rs6000_parse_alignment_option (); | |
889 | ||
5da702b1 AH |
890 | /* Handle generic -mFOO=YES/NO options. */ |
891 | rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string, | |
892 | &rs6000_altivec_vrsave); | |
893 | rs6000_parse_yes_no_option ("isel", rs6000_isel_string, | |
894 | &rs6000_isel); | |
895 | rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe); | |
896 | rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string, | |
897 | &rs6000_float_gprs); | |
993f19a8 | 898 | |
c4501e62 JJ |
899 | /* Handle -mtls-size option. */ |
900 | rs6000_parse_tls_size_option (); | |
901 | ||
a7ae18e2 AH |
902 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
903 | SUBTARGET_OVERRIDE_OPTIONS; | |
904 | #endif | |
905 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS | |
906 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
907 | #endif | |
908 | ||
5da702b1 AH |
909 | if (TARGET_E500) |
910 | { | |
911 | /* The e500 does not have string instructions, and we set | |
912 | MASK_STRING above when optimizing for size. */ | |
913 | if ((target_flags & MASK_STRING) != 0) | |
914 | target_flags = target_flags & ~MASK_STRING; | |
b6e59a3a AH |
915 | |
916 | /* No SPE means 64-bit long doubles, even if an E500. */ | |
917 | if (rs6000_spe_string != 0 | |
918 | && !strcmp (rs6000_spe_string, "no")) | |
919 | rs6000_long_double_type_size = 64; | |
5da702b1 AH |
920 | } |
921 | else if (rs6000_select[1].string != NULL) | |
922 | { | |
923 | /* For the powerpc-eabispe configuration, we set all these by | |
924 | default, so let's unset them if we manually set another | |
925 | CPU that is not the E500. */ | |
926 | if (rs6000_abi_string == 0) | |
927 | rs6000_spe_abi = 0; | |
928 | if (rs6000_spe_string == 0) | |
929 | rs6000_spe = 0; | |
930 | if (rs6000_float_gprs_string == 0) | |
931 | rs6000_float_gprs = 0; | |
932 | if (rs6000_isel_string == 0) | |
933 | rs6000_isel = 0; | |
b6e59a3a AH |
934 | if (rs6000_long_double_size_string == 0) |
935 | rs6000_long_double_type_size = 64; | |
5da702b1 | 936 | } |
b5044283 | 937 | |
a5c76ee6 ZW |
938 | /* Handle -m(no-)longcall option. This is a bit of a cheap hack, |
939 | using TARGET_OPTIONS to handle a toggle switch, but we're out of | |
940 | bits in target_flags so TARGET_SWITCHES cannot be used. | |
941 | Assumption here is that rs6000_longcall_switch points into the | |
942 | text of the complete option, rather than being a copy, so we can | |
943 | scan back for the presence or absence of the no- modifier. */ | |
944 | if (rs6000_longcall_switch) | |
945 | { | |
946 | const char *base = rs6000_longcall_switch; | |
947 | while (base[-1] != 'm') base--; | |
948 | ||
949 | if (*rs6000_longcall_switch != '\0') | |
950 | error ("invalid option `%s'", base); | |
951 | rs6000_default_long_calls = (base[0] != 'n'); | |
952 | } | |
953 | ||
cbe26ab8 | 954 | /* Handle -mprioritize-restricted-insns option. */ |
79ae11c4 DN |
955 | rs6000_sched_restricted_insns_priority = DEFAULT_RESTRICTED_INSNS_PRIORITY; |
956 | if (rs6000_sched_restricted_insns_priority_str) | |
957 | rs6000_sched_restricted_insns_priority = | |
958 | atoi (rs6000_sched_restricted_insns_priority_str); | |
959 | ||
569fa502 DN |
960 | /* Handle -msched-costly-dep option. */ |
961 | rs6000_sched_costly_dep = DEFAULT_SCHED_COSTLY_DEP; | |
962 | if (rs6000_sched_costly_dep_str) | |
963 | { | |
964 | if (! strcmp (rs6000_sched_costly_dep_str, "no")) | |
965 | rs6000_sched_costly_dep = no_dep_costly; | |
966 | else if (! strcmp (rs6000_sched_costly_dep_str, "all")) | |
967 | rs6000_sched_costly_dep = all_deps_costly; | |
968 | else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load")) | |
969 | rs6000_sched_costly_dep = true_store_to_load_dep_costly; | |
970 | else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load")) | |
971 | rs6000_sched_costly_dep = store_to_load_dep_costly; | |
cbe26ab8 DN |
972 | else |
973 | rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str); | |
974 | } | |
975 | ||
976 | /* Handle -minsert-sched-nops option. */ | |
977 | rs6000_sched_insert_nops = DEFAULT_SCHED_FINISH_NOP_INSERTION_SCHEME; | |
978 | if (rs6000_sched_insert_nops_str) | |
979 | { | |
980 | if (! strcmp (rs6000_sched_insert_nops_str, "no")) | |
981 | rs6000_sched_insert_nops = sched_finish_none; | |
982 | else if (! strcmp (rs6000_sched_insert_nops_str, "pad")) | |
983 | rs6000_sched_insert_nops = sched_finish_pad_groups; | |
984 | else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact")) | |
985 | rs6000_sched_insert_nops = sched_finish_regroup_exact; | |
986 | else | |
987 | rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str); | |
569fa502 DN |
988 | } |
989 | ||
c81bebd7 | 990 | #ifdef TARGET_REGNAMES |
a4f6c312 SS |
991 | /* If the user desires alternate register names, copy in the |
992 | alternate names now. */ | |
c81bebd7 | 993 | if (TARGET_REGNAMES) |
4e135bdd | 994 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
995 | #endif |
996 | ||
6fa3f289 ZW |
997 | /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined. |
998 | If -maix-struct-return or -msvr4-struct-return was explicitly | |
999 | used, don't override with the ABI default. */ | |
b21fb038 | 1000 | if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0) |
6fa3f289 ZW |
1001 | { |
1002 | if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET) | |
1003 | target_flags = (target_flags & ~MASK_AIX_STRUCT_RET); | |
1004 | else | |
1005 | target_flags |= MASK_AIX_STRUCT_RET; | |
1006 | } | |
1007 | ||
fcce224d DE |
1008 | if (TARGET_LONG_DOUBLE_128 |
1009 | && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)) | |
70a01792 | 1010 | REAL_MODE_FORMAT (TFmode) = &ibm_extended_format; |
fcce224d | 1011 | |
9ebbca7d GK |
1012 | /* Allocate an alias set for register saves & restores from stack. */ |
1013 | rs6000_sr_alias_set = new_alias_set (); | |
1014 | ||
1015 | if (TARGET_TOC) | |
1016 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); | |
71f123ca | 1017 | |
301d03af RS |
1018 | /* We can only guarantee the availability of DI pseudo-ops when |
1019 | assembling for 64-bit targets. */ | |
ae6c1efd | 1020 | if (!TARGET_64BIT) |
301d03af RS |
1021 | { |
1022 | targetm.asm_out.aligned_op.di = NULL; | |
1023 | targetm.asm_out.unaligned_op.di = NULL; | |
1024 | } | |
1025 | ||
2792d578 DE |
1026 | /* Set maximum branch target alignment at two instructions, eight bytes. */ |
1027 | align_jumps_max_skip = 8; | |
1028 | align_loops_max_skip = 8; | |
1029 | ||
71f123ca FS |
1030 | /* Arrange to save and restore machine status around nested functions. */ |
1031 | init_machine_status = rs6000_init_machine_status; | |
5248c961 | 1032 | } |
5accd822 | 1033 | |
5da702b1 AH |
1034 | /* Handle generic options of the form -mfoo=yes/no. |
1035 | NAME is the option name. | |
1036 | VALUE is the option value. | |
1037 | FLAG is the pointer to the flag where to store a 1 or 0, depending on | |
1038 | whether the option value is 'yes' or 'no' respectively. */ | |
993f19a8 | 1039 | static void |
5da702b1 | 1040 | rs6000_parse_yes_no_option (const char *name, const char *value, int *flag) |
993f19a8 | 1041 | { |
5da702b1 | 1042 | if (value == 0) |
993f19a8 | 1043 | return; |
5da702b1 AH |
1044 | else if (!strcmp (value, "yes")) |
1045 | *flag = 1; | |
1046 | else if (!strcmp (value, "no")) | |
1047 | *flag = 0; | |
08b57fb3 | 1048 | else |
5da702b1 | 1049 | error ("unknown -m%s= option specified: '%s'", name, value); |
08b57fb3 AH |
1050 | } |
1051 | ||
0ac081f6 | 1052 | /* Handle -mabi= options. */ |
00b960c7 | 1053 | static void |
863d938c | 1054 | rs6000_parse_abi_options (void) |
0ac081f6 AH |
1055 | { |
1056 | if (rs6000_abi_string == 0) | |
1057 | return; | |
1058 | else if (! strcmp (rs6000_abi_string, "altivec")) | |
6fa3f289 | 1059 | rs6000_altivec_abi = 1; |
76a773f3 AH |
1060 | else if (! strcmp (rs6000_abi_string, "no-altivec")) |
1061 | rs6000_altivec_abi = 0; | |
a3170dc6 | 1062 | else if (! strcmp (rs6000_abi_string, "spe")) |
01f4962d NS |
1063 | { |
1064 | rs6000_spe_abi = 1; | |
1065 | if (!TARGET_SPE_ABI) | |
1066 | error ("not configured for ABI: '%s'", rs6000_abi_string); | |
1067 | } | |
1068 | ||
a3170dc6 AH |
1069 | else if (! strcmp (rs6000_abi_string, "no-spe")) |
1070 | rs6000_spe_abi = 0; | |
0ac081f6 | 1071 | else |
c725bd79 | 1072 | error ("unknown ABI specified: '%s'", rs6000_abi_string); |
0ac081f6 AH |
1073 | } |
1074 | ||
025d9908 KH |
1075 | /* Handle -malign-XXXXXX options. */ |
1076 | static void | |
863d938c | 1077 | rs6000_parse_alignment_option (void) |
025d9908 | 1078 | { |
b20a9cca AM |
1079 | if (rs6000_alignment_string == 0) |
1080 | return; | |
1081 | else if (! strcmp (rs6000_alignment_string, "power")) | |
025d9908 KH |
1082 | rs6000_alignment_flags = MASK_ALIGN_POWER; |
1083 | else if (! strcmp (rs6000_alignment_string, "natural")) | |
1084 | rs6000_alignment_flags = MASK_ALIGN_NATURAL; | |
1085 | else | |
1086 | error ("unknown -malign-XXXXX option specified: '%s'", | |
1087 | rs6000_alignment_string); | |
1088 | } | |
1089 | ||
c4501e62 JJ |
1090 | /* Validate and record the size specified with the -mtls-size option. */ |
1091 | ||
1092 | static void | |
863d938c | 1093 | rs6000_parse_tls_size_option (void) |
c4501e62 JJ |
1094 | { |
1095 | if (rs6000_tls_size_string == 0) | |
1096 | return; | |
1097 | else if (strcmp (rs6000_tls_size_string, "16") == 0) | |
1098 | rs6000_tls_size = 16; | |
1099 | else if (strcmp (rs6000_tls_size_string, "32") == 0) | |
1100 | rs6000_tls_size = 32; | |
1101 | else if (strcmp (rs6000_tls_size_string, "64") == 0) | |
1102 | rs6000_tls_size = 64; | |
1103 | else | |
1104 | error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string); | |
1105 | } | |
1106 | ||
5accd822 | 1107 | void |
a2369ed3 | 1108 | optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED) |
5accd822 | 1109 | { |
5accd822 | 1110 | } |
3cfa4909 MM |
1111 | \f |
1112 | /* Do anything needed at the start of the asm file. */ | |
1113 | ||
1bc7c5b6 | 1114 | static void |
863d938c | 1115 | rs6000_file_start (void) |
3cfa4909 | 1116 | { |
c4d38ccb | 1117 | size_t i; |
3cfa4909 | 1118 | char buffer[80]; |
d330fd93 | 1119 | const char *start = buffer; |
3cfa4909 | 1120 | struct rs6000_cpu_select *ptr; |
1bc7c5b6 ZW |
1121 | const char *default_cpu = TARGET_CPU_DEFAULT; |
1122 | FILE *file = asm_out_file; | |
1123 | ||
1124 | default_file_start (); | |
1125 | ||
1126 | #ifdef TARGET_BI_ARCH | |
1127 | if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT) | |
1128 | default_cpu = 0; | |
1129 | #endif | |
3cfa4909 MM |
1130 | |
1131 | if (flag_verbose_asm) | |
1132 | { | |
1133 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
1134 | rs6000_select[0].string = default_cpu; | |
1135 | ||
b6a1cbae | 1136 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
1137 | { |
1138 | ptr = &rs6000_select[i]; | |
1139 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
1140 | { | |
1141 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
1142 | start = ""; | |
1143 | } | |
1144 | } | |
1145 | ||
b91da81f | 1146 | #ifdef USING_ELFOS_H |
3cfa4909 MM |
1147 | switch (rs6000_sdata) |
1148 | { | |
1149 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
1150 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
1151 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
1152 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
1153 | } | |
1154 | ||
1155 | if (rs6000_sdata && g_switch_value) | |
1156 | { | |
307b599c MK |
1157 | fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start, |
1158 | g_switch_value); | |
3cfa4909 MM |
1159 | start = ""; |
1160 | } | |
1161 | #endif | |
1162 | ||
1163 | if (*start == '\0') | |
949ea356 | 1164 | putc ('\n', file); |
3cfa4909 MM |
1165 | } |
1166 | } | |
5248c961 | 1167 | \f |
a0ab749a | 1168 | /* Return nonzero if this function is known to have a null epilogue. */ |
9878760c RK |
1169 | |
1170 | int | |
863d938c | 1171 | direct_return (void) |
9878760c | 1172 | { |
4697a36c MM |
1173 | if (reload_completed) |
1174 | { | |
1175 | rs6000_stack_t *info = rs6000_stack_info (); | |
1176 | ||
1177 | if (info->first_gp_reg_save == 32 | |
1178 | && info->first_fp_reg_save == 64 | |
00b960c7 | 1179 | && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1 |
c81fc13e DE |
1180 | && ! info->lr_save_p |
1181 | && ! info->cr_save_p | |
00b960c7 | 1182 | && info->vrsave_mask == 0 |
c81fc13e | 1183 | && ! info->push_p) |
4697a36c MM |
1184 | return 1; |
1185 | } | |
1186 | ||
1187 | return 0; | |
9878760c RK |
1188 | } |
1189 | ||
1190 | /* Returns 1 always. */ | |
1191 | ||
1192 | int | |
a2369ed3 DJ |
1193 | any_operand (rtx op ATTRIBUTE_UNUSED, |
1194 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
9878760c RK |
1195 | { |
1196 | return 1; | |
1197 | } | |
1198 | ||
a4f6c312 | 1199 | /* Returns 1 if op is the count register. */ |
38c1f2d7 | 1200 | int |
a2369ed3 | 1201 | count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
b6c9286a MM |
1202 | { |
1203 | if (GET_CODE (op) != REG) | |
1204 | return 0; | |
1205 | ||
1206 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
1207 | return 1; | |
1208 | ||
1209 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
1210 | return 1; | |
1211 | ||
1212 | return 0; | |
1213 | } | |
1214 | ||
0ec4e2a8 AH |
1215 | /* Returns 1 if op is an altivec register. */ |
1216 | int | |
a2369ed3 | 1217 | altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ec4e2a8 AH |
1218 | { |
1219 | ||
1220 | return (register_operand (op, mode) | |
1221 | && (GET_CODE (op) != REG | |
1222 | || REGNO (op) > FIRST_PSEUDO_REGISTER | |
1223 | || ALTIVEC_REGNO_P (REGNO (op)))); | |
1224 | } | |
1225 | ||
38c1f2d7 | 1226 | int |
a2369ed3 | 1227 | xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
802a0058 MM |
1228 | { |
1229 | if (GET_CODE (op) != REG) | |
1230 | return 0; | |
1231 | ||
9ebbca7d | 1232 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
1233 | return 1; |
1234 | ||
802a0058 MM |
1235 | return 0; |
1236 | } | |
1237 | ||
c859cda6 | 1238 | /* Return 1 if OP is a signed 8-bit constant. Int multiplication |
6f317ef3 | 1239 | by such constants completes more quickly. */ |
c859cda6 DJ |
1240 | |
1241 | int | |
a2369ed3 | 1242 | s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
c859cda6 DJ |
1243 | { |
1244 | return ( GET_CODE (op) == CONST_INT | |
1245 | && (INTVAL (op) >= -128 && INTVAL (op) <= 127)); | |
1246 | } | |
1247 | ||
9878760c RK |
1248 | /* Return 1 if OP is a constant that can fit in a D field. */ |
1249 | ||
1250 | int | |
a2369ed3 | 1251 | short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1252 | { |
5f59ecb7 DE |
1253 | return (GET_CODE (op) == CONST_INT |
1254 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
1255 | } |
1256 | ||
5519a4f9 | 1257 | /* Similar for an unsigned D field. */ |
9878760c RK |
1258 | |
1259 | int | |
a2369ed3 | 1260 | u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1261 | { |
19684119 | 1262 | return (GET_CODE (op) == CONST_INT |
c1f11548 | 1263 | && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K')); |
9878760c RK |
1264 | } |
1265 | ||
dcfedcd0 RK |
1266 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
1267 | ||
1268 | int | |
a2369ed3 | 1269 | non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
1270 | { |
1271 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 1272 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
1273 | } |
1274 | ||
2bfcf297 DB |
1275 | /* Returns 1 if OP is a CONST_INT that is a positive value |
1276 | and an exact power of 2. */ | |
1277 | ||
1278 | int | |
a2369ed3 | 1279 | exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2bfcf297 DB |
1280 | { |
1281 | return (GET_CODE (op) == CONST_INT | |
1282 | && INTVAL (op) > 0 | |
1283 | && exact_log2 (INTVAL (op)) >= 0); | |
1284 | } | |
1285 | ||
9878760c RK |
1286 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
1287 | ctr, or lr). */ | |
1288 | ||
1289 | int | |
a2369ed3 | 1290 | gpc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1291 | { |
1292 | return (register_operand (op, mode) | |
802a0058 | 1293 | && (GET_CODE (op) != REG |
9ebbca7d GK |
1294 | || (REGNO (op) >= ARG_POINTER_REGNUM |
1295 | && !XER_REGNO_P (REGNO (op))) | |
1296 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
1297 | } |
1298 | ||
1299 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
1300 | CR field. */ | |
1301 | ||
1302 | int | |
a2369ed3 | 1303 | cc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1304 | { |
1305 | return (register_operand (op, mode) | |
1306 | && (GET_CODE (op) != REG | |
1307 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1308 | || CR_REGNO_P (REGNO (op)))); | |
1309 | } | |
1310 | ||
815cdc52 MM |
1311 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
1312 | CR field that isn't CR0. */ | |
1313 | ||
1314 | int | |
a2369ed3 | 1315 | cc_reg_not_cr0_operand (rtx op, enum machine_mode mode) |
815cdc52 MM |
1316 | { |
1317 | return (register_operand (op, mode) | |
1318 | && (GET_CODE (op) != REG | |
1319 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1320 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
1321 | } | |
1322 | ||
a4f6c312 SS |
1323 | /* Returns 1 if OP is either a constant integer valid for a D-field or |
1324 | a non-special register. If a register, it must be in the proper | |
1325 | mode unless MODE is VOIDmode. */ | |
9878760c RK |
1326 | |
1327 | int | |
a2369ed3 | 1328 | reg_or_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1329 | { |
f5a28898 | 1330 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1331 | } |
1332 | ||
a4f6c312 SS |
1333 | /* Similar, except check if the negation of the constant would be |
1334 | valid for a D-field. */ | |
9878760c RK |
1335 | |
1336 | int | |
a2369ed3 | 1337 | reg_or_neg_short_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1338 | { |
1339 | if (GET_CODE (op) == CONST_INT) | |
1340 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P'); | |
1341 | ||
cd2b37d9 | 1342 | return gpc_reg_operand (op, mode); |
9878760c RK |
1343 | } |
1344 | ||
768070a0 TR |
1345 | /* Returns 1 if OP is either a constant integer valid for a DS-field or |
1346 | a non-special register. If a register, it must be in the proper | |
1347 | mode unless MODE is VOIDmode. */ | |
1348 | ||
1349 | int | |
a2369ed3 | 1350 | reg_or_aligned_short_operand (rtx op, enum machine_mode mode) |
768070a0 TR |
1351 | { |
1352 | if (gpc_reg_operand (op, mode)) | |
1353 | return 1; | |
1354 | else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3)) | |
1355 | return 1; | |
1356 | ||
1357 | return 0; | |
1358 | } | |
1359 | ||
1360 | ||
a4f6c312 SS |
1361 | /* Return 1 if the operand is either a register or an integer whose |
1362 | high-order 16 bits are zero. */ | |
9878760c RK |
1363 | |
1364 | int | |
a2369ed3 | 1365 | reg_or_u_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1366 | { |
e675f625 | 1367 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1368 | } |
1369 | ||
1370 | /* Return 1 is the operand is either a non-special register or ANY | |
1371 | constant integer. */ | |
1372 | ||
1373 | int | |
a2369ed3 | 1374 | reg_or_cint_operand (rtx op, enum machine_mode mode) |
9878760c | 1375 | { |
a4f6c312 | 1376 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
f6bf7de2 DE |
1377 | } |
1378 | ||
1379 | /* Return 1 is the operand is either a non-special register or ANY | |
1380 | 32-bit signed constant integer. */ | |
1381 | ||
1382 | int | |
a2369ed3 | 1383 | reg_or_arith_cint_operand (rtx op, enum machine_mode mode) |
f6bf7de2 | 1384 | { |
a4f6c312 SS |
1385 | return (gpc_reg_operand (op, mode) |
1386 | || (GET_CODE (op) == CONST_INT | |
f6bf7de2 | 1387 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
1388 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) |
1389 | < (unsigned HOST_WIDE_INT) 0x100000000ll) | |
f6bf7de2 | 1390 | #endif |
a4f6c312 | 1391 | )); |
9878760c RK |
1392 | } |
1393 | ||
2bfcf297 DB |
1394 | /* Return 1 is the operand is either a non-special register or a 32-bit |
1395 | signed constant integer valid for 64-bit addition. */ | |
1396 | ||
1397 | int | |
a2369ed3 | 1398 | reg_or_add_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1399 | { |
a4f6c312 SS |
1400 | return (gpc_reg_operand (op, mode) |
1401 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1402 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1403 | && INTVAL (op) < 0x7fff8000 |
a65c591c | 1404 | #else |
a4f6c312 SS |
1405 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) |
1406 | < 0x100000000ll) | |
2bfcf297 | 1407 | #endif |
a4f6c312 | 1408 | )); |
2bfcf297 DB |
1409 | } |
1410 | ||
1411 | /* Return 1 is the operand is either a non-special register or a 32-bit | |
1412 | signed constant integer valid for 64-bit subtraction. */ | |
1413 | ||
1414 | int | |
a2369ed3 | 1415 | reg_or_sub_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1416 | { |
a4f6c312 SS |
1417 | return (gpc_reg_operand (op, mode) |
1418 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1419 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1420 | && (- INTVAL (op)) < 0x7fff8000 |
a65c591c | 1421 | #else |
a4f6c312 SS |
1422 | && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000) |
1423 | < 0x100000000ll) | |
2bfcf297 | 1424 | #endif |
a4f6c312 | 1425 | )); |
2bfcf297 DB |
1426 | } |
1427 | ||
9ebbca7d GK |
1428 | /* Return 1 is the operand is either a non-special register or ANY |
1429 | 32-bit unsigned constant integer. */ | |
1430 | ||
1431 | int | |
a2369ed3 | 1432 | reg_or_logical_cint_operand (rtx op, enum machine_mode mode) |
9ebbca7d | 1433 | { |
1d328b19 GK |
1434 | if (GET_CODE (op) == CONST_INT) |
1435 | { | |
1436 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
1437 | { | |
1438 | if (GET_MODE_BITSIZE (mode) <= 32) | |
a4f6c312 | 1439 | abort (); |
1d328b19 GK |
1440 | |
1441 | if (INTVAL (op) < 0) | |
1442 | return 0; | |
1443 | } | |
1444 | ||
1445 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 1446 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
1447 | } |
1448 | else if (GET_CODE (op) == CONST_DOUBLE) | |
1449 | { | |
1450 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
1451 | || mode != DImode) | |
a4f6c312 | 1452 | abort (); |
1d328b19 GK |
1453 | |
1454 | return CONST_DOUBLE_HIGH (op) == 0; | |
1455 | } | |
1456 | else | |
1457 | return gpc_reg_operand (op, mode); | |
9ebbca7d GK |
1458 | } |
1459 | ||
51d3e7d6 | 1460 | /* Return 1 if the operand is an operand that can be loaded via the GOT. */ |
766a866c MM |
1461 | |
1462 | int | |
a2369ed3 | 1463 | got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
766a866c MM |
1464 | { |
1465 | return (GET_CODE (op) == SYMBOL_REF | |
1466 | || GET_CODE (op) == CONST | |
1467 | || GET_CODE (op) == LABEL_REF); | |
1468 | } | |
1469 | ||
38c1f2d7 MM |
1470 | /* Return 1 if the operand is a simple references that can be loaded via |
1471 | the GOT (labels involving addition aren't allowed). */ | |
1472 | ||
1473 | int | |
a2369ed3 | 1474 | got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
38c1f2d7 MM |
1475 | { |
1476 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
1477 | } | |
1478 | ||
4e74d8ec MM |
1479 | /* Return the number of instructions it takes to form a constant in an |
1480 | integer register. */ | |
1481 | ||
1482 | static int | |
a2369ed3 | 1483 | num_insns_constant_wide (HOST_WIDE_INT value) |
4e74d8ec MM |
1484 | { |
1485 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 1486 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
1487 | return 1; |
1488 | ||
4e74d8ec | 1489 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 1490 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
1491 | return 1; |
1492 | ||
5f59ecb7 | 1493 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 1494 | else if (TARGET_POWERPC64) |
4e74d8ec | 1495 | { |
a65c591c DE |
1496 | HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000; |
1497 | HOST_WIDE_INT high = value >> 31; | |
4e74d8ec | 1498 | |
a65c591c | 1499 | if (high == 0 || high == -1) |
4e74d8ec MM |
1500 | return 2; |
1501 | ||
a65c591c | 1502 | high >>= 1; |
4e74d8ec | 1503 | |
a65c591c | 1504 | if (low == 0) |
4e74d8ec | 1505 | return num_insns_constant_wide (high) + 1; |
4e74d8ec MM |
1506 | else |
1507 | return (num_insns_constant_wide (high) | |
e396202a | 1508 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
1509 | } |
1510 | #endif | |
1511 | ||
1512 | else | |
1513 | return 2; | |
1514 | } | |
1515 | ||
1516 | int | |
a2369ed3 | 1517 | num_insns_constant (rtx op, enum machine_mode mode) |
4e74d8ec | 1518 | { |
4e74d8ec | 1519 | if (GET_CODE (op) == CONST_INT) |
0d30d435 DE |
1520 | { |
1521 | #if HOST_BITS_PER_WIDE_INT == 64 | |
4e2c1c44 DE |
1522 | if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1 |
1523 | && mask64_operand (op, mode)) | |
0d30d435 DE |
1524 | return 2; |
1525 | else | |
1526 | #endif | |
1527 | return num_insns_constant_wide (INTVAL (op)); | |
1528 | } | |
4e74d8ec | 1529 | |
6fc48950 MM |
1530 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
1531 | { | |
1532 | long l; | |
1533 | REAL_VALUE_TYPE rv; | |
1534 | ||
1535 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1536 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
e72247f4 | 1537 | return num_insns_constant_wide ((HOST_WIDE_INT) l); |
6fc48950 MM |
1538 | } |
1539 | ||
47ad8c61 | 1540 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 1541 | { |
47ad8c61 MM |
1542 | HOST_WIDE_INT low; |
1543 | HOST_WIDE_INT high; | |
1544 | long l[2]; | |
1545 | REAL_VALUE_TYPE rv; | |
1546 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 1547 | |
47ad8c61 MM |
1548 | if (mode == VOIDmode || mode == DImode) |
1549 | { | |
1550 | high = CONST_DOUBLE_HIGH (op); | |
1551 | low = CONST_DOUBLE_LOW (op); | |
1552 | } | |
1553 | else | |
1554 | { | |
1555 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1556 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
1557 | high = l[endian]; | |
1558 | low = l[1 - endian]; | |
1559 | } | |
4e74d8ec | 1560 | |
47ad8c61 MM |
1561 | if (TARGET_32BIT) |
1562 | return (num_insns_constant_wide (low) | |
1563 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
1564 | |
1565 | else | |
47ad8c61 | 1566 | { |
e72247f4 | 1567 | if (high == 0 && low >= 0) |
47ad8c61 MM |
1568 | return num_insns_constant_wide (low); |
1569 | ||
e72247f4 | 1570 | else if (high == -1 && low < 0) |
47ad8c61 MM |
1571 | return num_insns_constant_wide (low); |
1572 | ||
a260abc9 DE |
1573 | else if (mask64_operand (op, mode)) |
1574 | return 2; | |
1575 | ||
47ad8c61 MM |
1576 | else if (low == 0) |
1577 | return num_insns_constant_wide (high) + 1; | |
1578 | ||
1579 | else | |
1580 | return (num_insns_constant_wide (high) | |
1581 | + num_insns_constant_wide (low) + 1); | |
1582 | } | |
4e74d8ec MM |
1583 | } |
1584 | ||
1585 | else | |
1586 | abort (); | |
1587 | } | |
1588 | ||
a4f6c312 SS |
1589 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a |
1590 | register with one instruction per word. We only do this if we can | |
1591 | safely read CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
1592 | |
1593 | int | |
a2369ed3 | 1594 | easy_fp_constant (rtx op, enum machine_mode mode) |
9878760c | 1595 | { |
9878760c RK |
1596 | if (GET_CODE (op) != CONST_DOUBLE |
1597 | || GET_MODE (op) != mode | |
4e74d8ec | 1598 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
1599 | return 0; |
1600 | ||
a4f6c312 | 1601 | /* Consider all constants with -msoft-float to be easy. */ |
a3170dc6 AH |
1602 | if ((TARGET_SOFT_FLOAT || !TARGET_FPRS) |
1603 | && mode != DImode) | |
b6c9286a MM |
1604 | return 1; |
1605 | ||
a4f6c312 | 1606 | /* If we are using V.4 style PIC, consider all constants to be hard. */ |
f607bc57 | 1607 | if (flag_pic && DEFAULT_ABI == ABI_V4) |
a7273471 MM |
1608 | return 0; |
1609 | ||
5ae4759c | 1610 | #ifdef TARGET_RELOCATABLE |
a4f6c312 SS |
1611 | /* Similarly if we are using -mrelocatable, consider all constants |
1612 | to be hard. */ | |
5ae4759c MM |
1613 | if (TARGET_RELOCATABLE) |
1614 | return 0; | |
1615 | #endif | |
1616 | ||
fcce224d DE |
1617 | if (mode == TFmode) |
1618 | { | |
1619 | long k[4]; | |
1620 | REAL_VALUE_TYPE rv; | |
1621 | ||
1622 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1623 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
1624 | ||
1625 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 | |
1626 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1 | |
1627 | && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1 | |
1628 | && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1); | |
1629 | } | |
1630 | ||
1631 | else if (mode == DFmode) | |
042259f2 DE |
1632 | { |
1633 | long k[2]; | |
1634 | REAL_VALUE_TYPE rv; | |
1635 | ||
1636 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1637 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 1638 | |
a65c591c DE |
1639 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 |
1640 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1); | |
042259f2 | 1641 | } |
4e74d8ec MM |
1642 | |
1643 | else if (mode == SFmode) | |
042259f2 DE |
1644 | { |
1645 | long l; | |
1646 | REAL_VALUE_TYPE rv; | |
1647 | ||
1648 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1649 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 1650 | |
4e74d8ec | 1651 | return num_insns_constant_wide (l) == 1; |
042259f2 | 1652 | } |
4e74d8ec | 1653 | |
a260abc9 | 1654 | else if (mode == DImode) |
c81fc13e | 1655 | return ((TARGET_POWERPC64 |
a260abc9 DE |
1656 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
1657 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 1658 | |
a9098fd0 GK |
1659 | else if (mode == SImode) |
1660 | return 1; | |
4e74d8ec MM |
1661 | else |
1662 | abort (); | |
9878760c | 1663 | } |
8f75773e | 1664 | |
72ac76be | 1665 | /* Return nonzero if all elements of a vector have the same value. */ |
69ef87e2 AH |
1666 | |
1667 | static int | |
a2369ed3 | 1668 | easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
d744e06e AH |
1669 | { |
1670 | int units, i, cst; | |
1671 | ||
1672 | units = CONST_VECTOR_NUNITS (op); | |
1673 | ||
1674 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); | |
1675 | for (i = 1; i < units; ++i) | |
1676 | if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst) | |
1677 | break; | |
1678 | if (i == units) | |
1679 | return 1; | |
1680 | return 0; | |
1681 | } | |
1682 | ||
1683 | /* Return 1 if the operand is a CONST_INT and can be put into a | |
1684 | register without using memory. */ | |
1685 | ||
1686 | int | |
a2369ed3 | 1687 | easy_vector_constant (rtx op, enum machine_mode mode) |
69ef87e2 | 1688 | { |
d744e06e | 1689 | int cst, cst2; |
69ef87e2 | 1690 | |
d744e06e AH |
1691 | if (GET_CODE (op) != CONST_VECTOR |
1692 | || (!TARGET_ALTIVEC | |
1693 | && !TARGET_SPE)) | |
69ef87e2 AH |
1694 | return 0; |
1695 | ||
d744e06e AH |
1696 | if (zero_constant (op, mode) |
1697 | && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode)) | |
1698 | || (TARGET_SPE && SPE_VECTOR_MODE (mode)))) | |
1699 | return 1; | |
69ef87e2 | 1700 | |
d744e06e AH |
1701 | if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT) |
1702 | return 0; | |
1703 | ||
f5119d10 AH |
1704 | if (TARGET_SPE && mode == V1DImode) |
1705 | return 0; | |
1706 | ||
d744e06e AH |
1707 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); |
1708 | cst2 = INTVAL (CONST_VECTOR_ELT (op, 1)); | |
1709 | ||
1710 | /* Limit SPE vectors to 15 bits signed. These we can generate with: | |
1711 | li r0, CONSTANT1 | |
1712 | evmergelo r0, r0, r0 | |
1713 | li r0, CONSTANT2 | |
1714 | ||
1715 | I don't know how efficient it would be to allow bigger constants, | |
1716 | considering we'll have an extra 'ori' for every 'li'. I doubt 5 | |
1717 | instructions is better than a 64-bit memory load, but I don't | |
1718 | have the e500 timing specs. */ | |
1719 | if (TARGET_SPE && mode == V2SImode | |
1720 | && cst >= -0x7fff && cst <= 0x7fff | |
f5119d10 | 1721 | && cst2 >= -0x7fff && cst2 <= 0x7fff) |
d744e06e AH |
1722 | return 1; |
1723 | ||
1724 | if (TARGET_ALTIVEC && EASY_VECTOR_15 (cst, op, mode)) | |
1725 | return 1; | |
1726 | ||
1727 | if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode)) | |
1728 | return 1; | |
1729 | ||
1730 | return 0; | |
1731 | } | |
1732 | ||
1733 | /* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */ | |
1734 | ||
1735 | int | |
a2369ed3 | 1736 | easy_vector_constant_add_self (rtx op, enum machine_mode mode) |
d744e06e AH |
1737 | { |
1738 | int cst; | |
1739 | ||
1740 | if (!easy_vector_constant (op, mode)) | |
1741 | return 0; | |
1742 | ||
1743 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); | |
1744 | ||
1745 | return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode); | |
1746 | } | |
1747 | ||
1748 | const char * | |
a2369ed3 | 1749 | output_vec_const_move (rtx *operands) |
d744e06e AH |
1750 | { |
1751 | int cst, cst2; | |
1752 | enum machine_mode mode; | |
1753 | rtx dest, vec; | |
1754 | ||
1755 | dest = operands[0]; | |
1756 | vec = operands[1]; | |
69ef87e2 | 1757 | |
d744e06e AH |
1758 | cst = INTVAL (CONST_VECTOR_ELT (vec, 0)); |
1759 | cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1)); | |
1760 | mode = GET_MODE (dest); | |
69ef87e2 | 1761 | |
d744e06e AH |
1762 | if (TARGET_ALTIVEC) |
1763 | { | |
1764 | if (zero_constant (vec, mode)) | |
1765 | return "vxor %0,%0,%0"; | |
1766 | else if (EASY_VECTOR_15 (cst, vec, mode)) | |
98ef3137 | 1767 | { |
d744e06e AH |
1768 | operands[1] = GEN_INT (cst); |
1769 | switch (mode) | |
1770 | { | |
1771 | case V4SImode: | |
1772 | return "vspltisw %0,%1"; | |
1773 | case V8HImode: | |
1774 | return "vspltish %0,%1"; | |
1775 | case V16QImode: | |
1776 | return "vspltisb %0,%1"; | |
1777 | default: | |
1778 | abort (); | |
1779 | } | |
98ef3137 | 1780 | } |
d744e06e AH |
1781 | else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode)) |
1782 | return "#"; | |
1783 | else | |
1784 | abort (); | |
69ef87e2 AH |
1785 | } |
1786 | ||
d744e06e AH |
1787 | if (TARGET_SPE) |
1788 | { | |
1789 | /* Vector constant 0 is handled as a splitter of V2SI, and in the | |
1790 | pattern of V1DI, V4HI, and V2SF. | |
1791 | ||
c1207243 | 1792 | FIXME: We should probably return # and add post reload |
d744e06e AH |
1793 | splitters for these, but this way is so easy ;-). |
1794 | */ | |
1795 | operands[1] = GEN_INT (cst); | |
1796 | operands[2] = GEN_INT (cst2); | |
1797 | if (cst == cst2) | |
1798 | return "li %0,%1\n\tevmergelo %0,%0,%0"; | |
1799 | else | |
1800 | return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2"; | |
1801 | } | |
1802 | ||
1803 | abort (); | |
69ef87e2 AH |
1804 | } |
1805 | ||
1806 | /* Return 1 if the operand is the constant 0. This works for scalars | |
1807 | as well as vectors. */ | |
1808 | int | |
a2369ed3 | 1809 | zero_constant (rtx op, enum machine_mode mode) |
69ef87e2 AH |
1810 | { |
1811 | return op == CONST0_RTX (mode); | |
1812 | } | |
1813 | ||
50a0b056 GK |
1814 | /* Return 1 if the operand is 0.0. */ |
1815 | int | |
a2369ed3 | 1816 | zero_fp_constant (rtx op, enum machine_mode mode) |
50a0b056 GK |
1817 | { |
1818 | return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode); | |
1819 | } | |
1820 | ||
a4f6c312 SS |
1821 | /* Return 1 if the operand is in volatile memory. Note that during |
1822 | the RTL generation phase, memory_operand does not return TRUE for | |
b6c9286a MM |
1823 | volatile memory references. So this function allows us to |
1824 | recognize volatile references where its safe. */ | |
1825 | ||
1826 | int | |
a2369ed3 | 1827 | volatile_mem_operand (rtx op, enum machine_mode mode) |
b6c9286a MM |
1828 | { |
1829 | if (GET_CODE (op) != MEM) | |
1830 | return 0; | |
1831 | ||
1832 | if (!MEM_VOLATILE_P (op)) | |
1833 | return 0; | |
1834 | ||
1835 | if (mode != GET_MODE (op)) | |
1836 | return 0; | |
1837 | ||
1838 | if (reload_completed) | |
1839 | return memory_operand (op, mode); | |
1840 | ||
1841 | if (reload_in_progress) | |
1842 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
1843 | ||
1844 | return memory_address_p (mode, XEXP (op, 0)); | |
1845 | } | |
1846 | ||
97f6e72f | 1847 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
1848 | |
1849 | int | |
a2369ed3 | 1850 | offsettable_mem_operand (rtx op, enum machine_mode mode) |
914c2e77 | 1851 | { |
97f6e72f | 1852 | return ((GET_CODE (op) == MEM) |
677a9668 | 1853 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 1854 | mode, XEXP (op, 0))); |
914c2e77 RK |
1855 | } |
1856 | ||
9878760c RK |
1857 | /* Return 1 if the operand is either an easy FP constant (see above) or |
1858 | memory. */ | |
1859 | ||
1860 | int | |
a2369ed3 | 1861 | mem_or_easy_const_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1862 | { |
1863 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
1864 | } | |
1865 | ||
1866 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 1867 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
1868 | |
1869 | int | |
a2369ed3 | 1870 | add_operand (rtx op, enum machine_mode mode) |
9878760c | 1871 | { |
2bfcf297 | 1872 | if (GET_CODE (op) == CONST_INT) |
e72247f4 DE |
1873 | return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
1874 | || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
2bfcf297 DB |
1875 | |
1876 | return gpc_reg_operand (op, mode); | |
9878760c RK |
1877 | } |
1878 | ||
dcfedcd0 RK |
1879 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
1880 | ||
1881 | int | |
a2369ed3 | 1882 | non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
1883 | { |
1884 | return (GET_CODE (op) == CONST_INT | |
e72247f4 DE |
1885 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
1886 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
dcfedcd0 RK |
1887 | } |
1888 | ||
9878760c RK |
1889 | /* Return 1 if the operand is a non-special register or a constant that |
1890 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
1891 | ||
1892 | int | |
a2369ed3 | 1893 | logical_operand (rtx op, enum machine_mode mode) |
9878760c | 1894 | { |
40501e5f | 1895 | HOST_WIDE_INT opl, oph; |
1d328b19 | 1896 | |
dfbdccdb GK |
1897 | if (gpc_reg_operand (op, mode)) |
1898 | return 1; | |
1d328b19 | 1899 | |
dfbdccdb | 1900 | if (GET_CODE (op) == CONST_INT) |
40501e5f AM |
1901 | { |
1902 | opl = INTVAL (op) & GET_MODE_MASK (mode); | |
1903 | ||
1904 | #if HOST_BITS_PER_WIDE_INT <= 32 | |
1905 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0) | |
1906 | return 0; | |
1907 | #endif | |
1908 | } | |
dfbdccdb GK |
1909 | else if (GET_CODE (op) == CONST_DOUBLE) |
1910 | { | |
1d328b19 | 1911 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
40501e5f | 1912 | abort (); |
1d328b19 GK |
1913 | |
1914 | opl = CONST_DOUBLE_LOW (op); | |
1915 | oph = CONST_DOUBLE_HIGH (op); | |
40501e5f | 1916 | if (oph != 0) |
38886f37 | 1917 | return 0; |
dfbdccdb GK |
1918 | } |
1919 | else | |
1920 | return 0; | |
1d328b19 | 1921 | |
40501e5f AM |
1922 | return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 |
1923 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); | |
9878760c RK |
1924 | } |
1925 | ||
dcfedcd0 | 1926 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 1927 | above), but could be split into one. */ |
dcfedcd0 RK |
1928 | |
1929 | int | |
a2369ed3 | 1930 | non_logical_cint_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 1931 | { |
dfbdccdb | 1932 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
1933 | && ! logical_operand (op, mode) |
1934 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
1935 | } |
1936 | ||
19ba8161 | 1937 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
1938 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
1939 | Reject all ones and all zeros, since these should have been optimized | |
1940 | away and confuse the making of MB and ME. */ | |
1941 | ||
1942 | int | |
a2369ed3 | 1943 | mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1944 | { |
02071907 | 1945 | HOST_WIDE_INT c, lsb; |
9878760c | 1946 | |
19ba8161 DE |
1947 | if (GET_CODE (op) != CONST_INT) |
1948 | return 0; | |
1949 | ||
1950 | c = INTVAL (op); | |
1951 | ||
57deb3a1 AM |
1952 | /* Fail in 64-bit mode if the mask wraps around because the upper |
1953 | 32-bits of the mask will all be 1s, contrary to GCC's internal view. */ | |
1954 | if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001) | |
1955 | return 0; | |
1956 | ||
c5059423 AM |
1957 | /* We don't change the number of transitions by inverting, |
1958 | so make sure we start with the LS bit zero. */ | |
1959 | if (c & 1) | |
1960 | c = ~c; | |
1961 | ||
1962 | /* Reject all zeros or all ones. */ | |
1963 | if (c == 0) | |
9878760c RK |
1964 | return 0; |
1965 | ||
c5059423 AM |
1966 | /* Find the first transition. */ |
1967 | lsb = c & -c; | |
1968 | ||
1969 | /* Invert to look for a second transition. */ | |
1970 | c = ~c; | |
9878760c | 1971 | |
c5059423 AM |
1972 | /* Erase first transition. */ |
1973 | c &= -lsb; | |
9878760c | 1974 | |
c5059423 AM |
1975 | /* Find the second transition (if any). */ |
1976 | lsb = c & -c; | |
1977 | ||
1978 | /* Match if all the bits above are 1's (or c is zero). */ | |
1979 | return c == -lsb; | |
9878760c RK |
1980 | } |
1981 | ||
0ba1b2ff AM |
1982 | /* Return 1 for the PowerPC64 rlwinm corner case. */ |
1983 | ||
1984 | int | |
a2369ed3 | 1985 | mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
1986 | { |
1987 | HOST_WIDE_INT c, lsb; | |
1988 | ||
1989 | if (GET_CODE (op) != CONST_INT) | |
1990 | return 0; | |
1991 | ||
1992 | c = INTVAL (op); | |
1993 | ||
1994 | if ((c & 0x80000001) != 0x80000001) | |
1995 | return 0; | |
1996 | ||
1997 | c = ~c; | |
1998 | if (c == 0) | |
1999 | return 0; | |
2000 | ||
2001 | lsb = c & -c; | |
2002 | c = ~c; | |
2003 | c &= -lsb; | |
2004 | lsb = c & -c; | |
2005 | return c == -lsb; | |
2006 | } | |
2007 | ||
a260abc9 DE |
2008 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
2009 | It is if there are no more than one 1->0 or 0->1 transitions. | |
0ba1b2ff AM |
2010 | Reject all zeros, since zero should have been optimized away and |
2011 | confuses the making of MB and ME. */ | |
9878760c RK |
2012 | |
2013 | int | |
a2369ed3 | 2014 | mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
a260abc9 DE |
2015 | { |
2016 | if (GET_CODE (op) == CONST_INT) | |
2017 | { | |
02071907 | 2018 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2019 | |
c5059423 | 2020 | c = INTVAL (op); |
a260abc9 | 2021 | |
0ba1b2ff | 2022 | /* Reject all zeros. */ |
c5059423 | 2023 | if (c == 0) |
e2c953b6 DE |
2024 | return 0; |
2025 | ||
0ba1b2ff AM |
2026 | /* We don't change the number of transitions by inverting, |
2027 | so make sure we start with the LS bit zero. */ | |
2028 | if (c & 1) | |
2029 | c = ~c; | |
2030 | ||
c5059423 AM |
2031 | /* Find the transition, and check that all bits above are 1's. */ |
2032 | lsb = c & -c; | |
e3981aab DE |
2033 | |
2034 | /* Match if all the bits above are 1's (or c is zero). */ | |
c5059423 | 2035 | return c == -lsb; |
e2c953b6 | 2036 | } |
0ba1b2ff AM |
2037 | return 0; |
2038 | } | |
2039 | ||
2040 | /* Like mask64_operand, but allow up to three transitions. This | |
2041 | predicate is used by insn patterns that generate two rldicl or | |
2042 | rldicr machine insns. */ | |
2043 | ||
2044 | int | |
a2369ed3 | 2045 | mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2046 | { |
2047 | if (GET_CODE (op) == CONST_INT) | |
a260abc9 | 2048 | { |
0ba1b2ff | 2049 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2050 | |
0ba1b2ff | 2051 | c = INTVAL (op); |
a260abc9 | 2052 | |
0ba1b2ff AM |
2053 | /* Disallow all zeros. */ |
2054 | if (c == 0) | |
2055 | return 0; | |
a260abc9 | 2056 | |
0ba1b2ff AM |
2057 | /* We don't change the number of transitions by inverting, |
2058 | so make sure we start with the LS bit zero. */ | |
2059 | if (c & 1) | |
2060 | c = ~c; | |
a260abc9 | 2061 | |
0ba1b2ff AM |
2062 | /* Find the first transition. */ |
2063 | lsb = c & -c; | |
a260abc9 | 2064 | |
0ba1b2ff AM |
2065 | /* Invert to look for a second transition. */ |
2066 | c = ~c; | |
2067 | ||
2068 | /* Erase first transition. */ | |
2069 | c &= -lsb; | |
2070 | ||
2071 | /* Find the second transition. */ | |
2072 | lsb = c & -c; | |
2073 | ||
2074 | /* Invert to look for a third transition. */ | |
2075 | c = ~c; | |
2076 | ||
2077 | /* Erase second transition. */ | |
2078 | c &= -lsb; | |
2079 | ||
2080 | /* Find the third transition (if any). */ | |
2081 | lsb = c & -c; | |
2082 | ||
2083 | /* Match if all the bits above are 1's (or c is zero). */ | |
2084 | return c == -lsb; | |
2085 | } | |
2086 | return 0; | |
2087 | } | |
2088 | ||
2089 | /* Generates shifts and masks for a pair of rldicl or rldicr insns to | |
2090 | implement ANDing by the mask IN. */ | |
2091 | void | |
a2369ed3 | 2092 | build_mask64_2_operands (rtx in, rtx *out) |
0ba1b2ff AM |
2093 | { |
2094 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
2095 | unsigned HOST_WIDE_INT c, lsb, m1, m2; | |
2096 | int shift; | |
2097 | ||
2098 | if (GET_CODE (in) != CONST_INT) | |
2099 | abort (); | |
2100 | ||
2101 | c = INTVAL (in); | |
2102 | if (c & 1) | |
2103 | { | |
2104 | /* Assume c initially something like 0x00fff000000fffff. The idea | |
2105 | is to rotate the word so that the middle ^^^^^^ group of zeros | |
2106 | is at the MS end and can be cleared with an rldicl mask. We then | |
2107 | rotate back and clear off the MS ^^ group of zeros with a | |
2108 | second rldicl. */ | |
2109 | c = ~c; /* c == 0xff000ffffff00000 */ | |
2110 | lsb = c & -c; /* lsb == 0x0000000000100000 */ | |
2111 | m1 = -lsb; /* m1 == 0xfffffffffff00000 */ | |
2112 | c = ~c; /* c == 0x00fff000000fffff */ | |
2113 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2114 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2115 | c = ~c; /* c == 0xff000fffffffffff */ | |
2116 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2117 | shift = 0; | |
2118 | while ((lsb >>= 1) != 0) | |
2119 | shift++; /* shift == 44 on exit from loop */ | |
2120 | m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */ | |
2121 | m1 = ~m1; /* m1 == 0x000000ffffffffff */ | |
2122 | m2 = ~c; /* m2 == 0x00ffffffffffffff */ | |
a260abc9 DE |
2123 | } |
2124 | else | |
0ba1b2ff AM |
2125 | { |
2126 | /* Assume c initially something like 0xff000f0000000000. The idea | |
2127 | is to rotate the word so that the ^^^ middle group of zeros | |
2128 | is at the LS end and can be cleared with an rldicr mask. We then | |
2129 | rotate back and clear off the LS group of ^^^^^^^^^^ zeros with | |
2130 | a second rldicr. */ | |
2131 | lsb = c & -c; /* lsb == 0x0000010000000000 */ | |
2132 | m2 = -lsb; /* m2 == 0xffffff0000000000 */ | |
2133 | c = ~c; /* c == 0x00fff0ffffffffff */ | |
2134 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2135 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2136 | c = ~c; /* c == 0xff000fffffffffff */ | |
2137 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2138 | shift = 0; | |
2139 | while ((lsb >>= 1) != 0) | |
2140 | shift++; /* shift == 44 on exit from loop */ | |
2141 | m1 = ~c; /* m1 == 0x00ffffffffffffff */ | |
2142 | m1 >>= shift; /* m1 == 0x0000000000000fff */ | |
2143 | m1 = ~m1; /* m1 == 0xfffffffffffff000 */ | |
2144 | } | |
2145 | ||
2146 | /* Note that when we only have two 0->1 and 1->0 transitions, one of the | |
2147 | masks will be all 1's. We are guaranteed more than one transition. */ | |
2148 | out[0] = GEN_INT (64 - shift); | |
2149 | out[1] = GEN_INT (m1); | |
2150 | out[2] = GEN_INT (shift); | |
2151 | out[3] = GEN_INT (m2); | |
2152 | #else | |
045572c7 GK |
2153 | (void)in; |
2154 | (void)out; | |
0ba1b2ff AM |
2155 | abort (); |
2156 | #endif | |
a260abc9 DE |
2157 | } |
2158 | ||
2159 | /* Return 1 if the operand is either a non-special register or a constant | |
2160 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
2161 | ||
2162 | int | |
a2369ed3 | 2163 | and64_operand (rtx op, enum machine_mode mode) |
9878760c | 2164 | { |
a4f6c312 | 2165 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2166 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
2167 | ||
2168 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
2169 | } |
2170 | ||
0ba1b2ff AM |
2171 | /* Like the above, but also match constants that can be implemented |
2172 | with two rldicl or rldicr insns. */ | |
2173 | ||
2174 | int | |
a2369ed3 | 2175 | and64_2_operand (rtx op, enum machine_mode mode) |
0ba1b2ff AM |
2176 | { |
2177 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ | |
2178 | return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode); | |
2179 | ||
2180 | return logical_operand (op, mode) || mask64_2_operand (op, mode); | |
2181 | } | |
2182 | ||
a260abc9 DE |
2183 | /* Return 1 if the operand is either a non-special register or a |
2184 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
2185 | |
2186 | int | |
a2369ed3 | 2187 | and_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2188 | { |
a4f6c312 | 2189 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2190 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
2191 | ||
2192 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
2193 | } |
2194 | ||
9878760c RK |
2195 | /* Return 1 if the operand is a general register or memory operand. */ |
2196 | ||
2197 | int | |
a2369ed3 | 2198 | reg_or_mem_operand (rtx op, enum machine_mode mode) |
9878760c | 2199 | { |
b6c9286a MM |
2200 | return (gpc_reg_operand (op, mode) |
2201 | || memory_operand (op, mode) | |
4c81e946 | 2202 | || macho_lo_sum_memory_operand (op, mode) |
b6c9286a | 2203 | || volatile_mem_operand (op, mode)); |
9878760c RK |
2204 | } |
2205 | ||
a7a813f7 | 2206 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 2207 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
2208 | instruction. */ |
2209 | ||
2210 | int | |
a2369ed3 | 2211 | lwa_operand (rtx op, enum machine_mode mode) |
a7a813f7 RK |
2212 | { |
2213 | rtx inner = op; | |
2214 | ||
2215 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
2216 | inner = SUBREG_REG (inner); | |
2217 | ||
2218 | return gpc_reg_operand (inner, mode) | |
2219 | || (memory_operand (inner, mode) | |
2220 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
6a40a9d6 DE |
2221 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC |
2222 | && (GET_CODE (XEXP (inner, 0)) != PLUS | |
e903c96a DE |
2223 | || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT |
2224 | || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0)); | |
a7a813f7 RK |
2225 | } |
2226 | ||
cc4d5fec JH |
2227 | /* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */ |
2228 | ||
2229 | int | |
a2369ed3 | 2230 | symbol_ref_operand (rtx op, enum machine_mode mode) |
cc4d5fec JH |
2231 | { |
2232 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2233 | return 0; | |
2234 | ||
473f51b6 DE |
2235 | return (GET_CODE (op) == SYMBOL_REF |
2236 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))); | |
cc4d5fec JH |
2237 | } |
2238 | ||
9878760c | 2239 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
cc4d5fec | 2240 | to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */ |
9878760c RK |
2241 | |
2242 | int | |
a2369ed3 | 2243 | call_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2244 | { |
2245 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2246 | return 0; | |
2247 | ||
2248 | return (GET_CODE (op) == SYMBOL_REF | |
cc4d5fec JH |
2249 | || (GET_CODE (op) == REG |
2250 | && (REGNO (op) == LINK_REGISTER_REGNUM | |
2251 | || REGNO (op) == COUNT_REGISTER_REGNUM | |
2252 | || REGNO (op) >= FIRST_PSEUDO_REGISTER))); | |
9878760c RK |
2253 | } |
2254 | ||
2af3d377 | 2255 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in |
d1908feb | 2256 | this file. */ |
2af3d377 RK |
2257 | |
2258 | int | |
a2369ed3 DJ |
2259 | current_file_function_operand (rtx op, |
2260 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
2af3d377 | 2261 | { |
473f51b6 DE |
2262 | return (GET_CODE (op) == SYMBOL_REF |
2263 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)) | |
2264 | && (SYMBOL_REF_LOCAL_P (op) | |
2265 | || (op == XEXP (DECL_RTL (current_function_decl), 0)))); | |
2af3d377 RK |
2266 | } |
2267 | ||
9878760c RK |
2268 | /* Return 1 if this operand is a valid input for a move insn. */ |
2269 | ||
2270 | int | |
a2369ed3 | 2271 | input_operand (rtx op, enum machine_mode mode) |
9878760c | 2272 | { |
eb4e8003 | 2273 | /* Memory is always valid. */ |
9878760c RK |
2274 | if (memory_operand (op, mode)) |
2275 | return 1; | |
2276 | ||
34792e82 | 2277 | /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */ |
01b4cf2b | 2278 | if (GET_CODE (op) == CONSTANT_P_RTX) |
34792e82 JL |
2279 | return 1; |
2280 | ||
eb4e8003 RK |
2281 | /* For floating-point, easy constants are valid. */ |
2282 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
2283 | && CONSTANT_P (op) | |
2284 | && easy_fp_constant (op, mode)) | |
2285 | return 1; | |
2286 | ||
4e74d8ec MM |
2287 | /* Allow any integer constant. */ |
2288 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 2289 | && (GET_CODE (op) == CONST_INT |
e675f625 | 2290 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
2291 | return 1; |
2292 | ||
d744e06e AH |
2293 | /* Allow easy vector constants. */ |
2294 | if (GET_CODE (op) == CONST_VECTOR | |
2295 | && easy_vector_constant (op, mode)) | |
2296 | return 1; | |
2297 | ||
eb4e8003 RK |
2298 | /* For floating-point or multi-word mode, the only remaining valid type |
2299 | is a register. */ | |
9878760c RK |
2300 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
2301 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 2302 | return register_operand (op, mode); |
9878760c | 2303 | |
88fe15a1 RK |
2304 | /* The only cases left are integral modes one word or smaller (we |
2305 | do not get called for MODE_CC values). These can be in any | |
2306 | register. */ | |
2307 | if (register_operand (op, mode)) | |
a8b3aeda | 2308 | return 1; |
88fe15a1 | 2309 | |
84cf9dda | 2310 | /* A SYMBOL_REF referring to the TOC is valid. */ |
4d588c14 | 2311 | if (legitimate_constant_pool_address_p (op)) |
84cf9dda RK |
2312 | return 1; |
2313 | ||
9ebbca7d | 2314 | /* A constant pool expression (relative to the TOC) is valid */ |
4d588c14 | 2315 | if (toc_relative_expr_p (op)) |
b6c9286a MM |
2316 | return 1; |
2317 | ||
88228c4b MM |
2318 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
2319 | to be valid. */ | |
f607bc57 | 2320 | if (DEFAULT_ABI == ABI_V4 |
88228c4b MM |
2321 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
2322 | && small_data_operand (op, Pmode)) | |
2323 | return 1; | |
2324 | ||
042259f2 | 2325 | return 0; |
9878760c | 2326 | } |
7509c759 | 2327 | |
a4f6c312 | 2328 | /* Return 1 for an operand in small memory on V.4/eabi. */ |
7509c759 MM |
2329 | |
2330 | int | |
a2369ed3 DJ |
2331 | small_data_operand (rtx op ATTRIBUTE_UNUSED, |
2332 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
7509c759 | 2333 | { |
38c1f2d7 | 2334 | #if TARGET_ELF |
5f59ecb7 | 2335 | rtx sym_ref; |
7509c759 | 2336 | |
d9407988 | 2337 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 2338 | return 0; |
a54d04b7 | 2339 | |
f607bc57 | 2340 | if (DEFAULT_ABI != ABI_V4) |
7509c759 MM |
2341 | return 0; |
2342 | ||
88228c4b MM |
2343 | if (GET_CODE (op) == SYMBOL_REF) |
2344 | sym_ref = op; | |
2345 | ||
2346 | else if (GET_CODE (op) != CONST | |
2347 | || GET_CODE (XEXP (op, 0)) != PLUS | |
2348 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
2349 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
2350 | return 0; |
2351 | ||
88228c4b | 2352 | else |
dbf55e53 MM |
2353 | { |
2354 | rtx sum = XEXP (op, 0); | |
2355 | HOST_WIDE_INT summand; | |
2356 | ||
2357 | /* We have to be careful here, because it is the referenced address | |
2358 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
2359 | summand = INTVAL (XEXP (sum, 1)); | |
307b599c | 2360 | if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value) |
dbf55e53 MM |
2361 | return 0; |
2362 | ||
2363 | sym_ref = XEXP (sum, 0); | |
2364 | } | |
88228c4b | 2365 | |
20bfcd69 | 2366 | return SYMBOL_REF_SMALL_P (sym_ref); |
d9407988 MM |
2367 | #else |
2368 | return 0; | |
2369 | #endif | |
7509c759 | 2370 | } |
46c07df8 | 2371 | |
3a1f863f | 2372 | /* Return true if either operand is a general purpose register. */ |
46c07df8 | 2373 | |
3a1f863f DE |
2374 | bool |
2375 | gpr_or_gpr_p (rtx op0, rtx op1) | |
46c07df8 | 2376 | { |
3a1f863f DE |
2377 | return ((REG_P (op0) && INT_REGNO_P (REGNO (op0))) |
2378 | || (REG_P (op1) && INT_REGNO_P (REGNO (op1)))); | |
46c07df8 HP |
2379 | } |
2380 | ||
9ebbca7d | 2381 | \f |
4d588c14 RH |
2382 | /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */ |
2383 | ||
9ebbca7d | 2384 | static int |
a2369ed3 | 2385 | constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc) |
9ebbca7d GK |
2386 | { |
2387 | switch (GET_CODE(op)) | |
2388 | { | |
2389 | case SYMBOL_REF: | |
c4501e62 JJ |
2390 | if (RS6000_SYMBOL_REF_TLS_P (op)) |
2391 | return 0; | |
2392 | else if (CONSTANT_POOL_ADDRESS_P (op)) | |
a4f6c312 SS |
2393 | { |
2394 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) | |
2395 | { | |
2396 | *have_sym = 1; | |
2397 | return 1; | |
2398 | } | |
2399 | else | |
2400 | return 0; | |
2401 | } | |
2402 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
2403 | { | |
2404 | *have_toc = 1; | |
2405 | return 1; | |
2406 | } | |
2407 | else | |
2408 | return 0; | |
9ebbca7d GK |
2409 | case PLUS: |
2410 | case MINUS: | |
c1f11548 DE |
2411 | return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) |
2412 | && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc)); | |
9ebbca7d | 2413 | case CONST: |
a4f6c312 | 2414 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); |
9ebbca7d | 2415 | case CONST_INT: |
a4f6c312 | 2416 | return 1; |
9ebbca7d | 2417 | default: |
a4f6c312 | 2418 | return 0; |
9ebbca7d GK |
2419 | } |
2420 | } | |
2421 | ||
4d588c14 | 2422 | static bool |
a2369ed3 | 2423 | constant_pool_expr_p (rtx op) |
9ebbca7d GK |
2424 | { |
2425 | int have_sym = 0; | |
2426 | int have_toc = 0; | |
2427 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
2428 | } | |
2429 | ||
4d588c14 | 2430 | static bool |
a2369ed3 | 2431 | toc_relative_expr_p (rtx op) |
9ebbca7d | 2432 | { |
4d588c14 RH |
2433 | int have_sym = 0; |
2434 | int have_toc = 0; | |
2435 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
2436 | } | |
2437 | ||
2438 | /* SPE offset addressing is limited to 5-bits worth of double words. */ | |
2439 | #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0) | |
2440 | ||
2441 | bool | |
a2369ed3 | 2442 | legitimate_constant_pool_address_p (rtx x) |
4d588c14 RH |
2443 | { |
2444 | return (TARGET_TOC | |
2445 | && GET_CODE (x) == PLUS | |
2446 | && GET_CODE (XEXP (x, 0)) == REG | |
2447 | && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER) | |
2448 | && constant_pool_expr_p (XEXP (x, 1))); | |
2449 | } | |
2450 | ||
2451 | static bool | |
a2369ed3 | 2452 | legitimate_small_data_p (enum machine_mode mode, rtx x) |
4d588c14 RH |
2453 | { |
2454 | return (DEFAULT_ABI == ABI_V4 | |
2455 | && !flag_pic && !TARGET_TOC | |
2456 | && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST) | |
2457 | && small_data_operand (x, mode)); | |
2458 | } | |
2459 | ||
2460 | static bool | |
a2369ed3 | 2461 | legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict) |
4d588c14 RH |
2462 | { |
2463 | unsigned HOST_WIDE_INT offset, extra; | |
2464 | ||
2465 | if (GET_CODE (x) != PLUS) | |
2466 | return false; | |
2467 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2468 | return false; | |
2469 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
2470 | return false; | |
2471 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
2472 | return false; | |
2473 | ||
2474 | offset = INTVAL (XEXP (x, 1)); | |
2475 | extra = 0; | |
2476 | switch (mode) | |
2477 | { | |
2478 | case V16QImode: | |
2479 | case V8HImode: | |
2480 | case V4SFmode: | |
2481 | case V4SImode: | |
2482 | /* AltiVec vector modes. Only reg+reg addressing is valid here, | |
2483 | which leaves the only valid constant offset of zero, which by | |
2484 | canonicalization rules is also invalid. */ | |
2485 | return false; | |
2486 | ||
2487 | case V4HImode: | |
2488 | case V2SImode: | |
2489 | case V1DImode: | |
2490 | case V2SFmode: | |
2491 | /* SPE vector modes. */ | |
2492 | return SPE_CONST_OFFSET_OK (offset); | |
2493 | ||
2494 | case DFmode: | |
2495 | case DImode: | |
2496 | if (TARGET_32BIT) | |
2497 | extra = 4; | |
2498 | else if (offset & 3) | |
2499 | return false; | |
2500 | break; | |
2501 | ||
2502 | case TFmode: | |
2503 | case TImode: | |
2504 | if (TARGET_32BIT) | |
2505 | extra = 12; | |
2506 | else if (offset & 3) | |
2507 | return false; | |
2508 | else | |
2509 | extra = 8; | |
2510 | break; | |
2511 | ||
2512 | default: | |
2513 | break; | |
2514 | } | |
2515 | ||
2516 | return (offset + extra >= offset) && (offset + extra + 0x8000 < 0x10000); | |
2517 | } | |
2518 | ||
2519 | static bool | |
a2369ed3 | 2520 | legitimate_indexed_address_p (rtx x, int strict) |
4d588c14 RH |
2521 | { |
2522 | rtx op0, op1; | |
2523 | ||
2524 | if (GET_CODE (x) != PLUS) | |
2525 | return false; | |
2526 | op0 = XEXP (x, 0); | |
2527 | op1 = XEXP (x, 1); | |
2528 | ||
2529 | if (!REG_P (op0) || !REG_P (op1)) | |
2530 | return false; | |
2531 | ||
2532 | return ((INT_REG_OK_FOR_BASE_P (op0, strict) | |
2533 | && INT_REG_OK_FOR_INDEX_P (op1, strict)) | |
2534 | || (INT_REG_OK_FOR_BASE_P (op1, strict) | |
2535 | && INT_REG_OK_FOR_INDEX_P (op0, strict))); | |
9ebbca7d GK |
2536 | } |
2537 | ||
4d588c14 | 2538 | static inline bool |
a2369ed3 | 2539 | legitimate_indirect_address_p (rtx x, int strict) |
4d588c14 RH |
2540 | { |
2541 | return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict); | |
2542 | } | |
2543 | ||
4c81e946 FJ |
2544 | static bool |
2545 | macho_lo_sum_memory_operand (rtx x, enum machine_mode mode) | |
2546 | { | |
2547 | if (!TARGET_MACHO || !flag_pic | |
2548 | || mode != SImode || GET_CODE(x) != MEM) | |
2549 | return false; | |
2550 | x = XEXP (x, 0); | |
2551 | ||
2552 | if (GET_CODE (x) != LO_SUM) | |
2553 | return false; | |
2554 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2555 | return false; | |
2556 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0)) | |
2557 | return false; | |
2558 | x = XEXP (x, 1); | |
2559 | ||
2560 | return CONSTANT_P (x); | |
2561 | } | |
2562 | ||
4d588c14 | 2563 | static bool |
a2369ed3 | 2564 | legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict) |
4d588c14 RH |
2565 | { |
2566 | if (GET_CODE (x) != LO_SUM) | |
2567 | return false; | |
2568 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2569 | return false; | |
2570 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
2571 | return false; | |
2572 | x = XEXP (x, 1); | |
2573 | ||
2574 | if (TARGET_ELF) | |
2575 | { | |
2576 | if (DEFAULT_ABI != ABI_AIX && flag_pic) | |
2577 | return false; | |
2578 | if (TARGET_TOC) | |
2579 | return false; | |
2580 | if (GET_MODE_NUNITS (mode) != 1) | |
2581 | return false; | |
2582 | if (GET_MODE_BITSIZE (mode) > 32 | |
2583 | && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode)) | |
2584 | return false; | |
2585 | ||
2586 | return CONSTANT_P (x); | |
2587 | } | |
2588 | ||
2589 | return false; | |
2590 | } | |
2591 | ||
2592 | ||
9ebbca7d GK |
2593 | /* Try machine-dependent ways of modifying an illegitimate address |
2594 | to be legitimate. If we find one, return the new, valid address. | |
2595 | This is used from only one place: `memory_address' in explow.c. | |
2596 | ||
a4f6c312 SS |
2597 | OLDX is the address as it was before break_out_memory_refs was |
2598 | called. In some cases it is useful to look at this to decide what | |
2599 | needs to be done. | |
9ebbca7d | 2600 | |
a4f6c312 | 2601 | MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS. |
9ebbca7d | 2602 | |
a4f6c312 SS |
2603 | It is always safe for this function to do nothing. It exists to |
2604 | recognize opportunities to optimize the output. | |
9ebbca7d GK |
2605 | |
2606 | On RS/6000, first check for the sum of a register with a constant | |
2607 | integer that is out of range. If so, generate code to add the | |
2608 | constant with the low-order 16 bits masked to the register and force | |
2609 | this result into another register (this can be done with `cau'). | |
2610 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
2611 | possibility of bit 16 being a one. | |
2612 | ||
2613 | Then check for the sum of a register and something not constant, try to | |
2614 | load the other things into a register and return the sum. */ | |
4d588c14 | 2615 | |
9ebbca7d | 2616 | rtx |
a2369ed3 DJ |
2617 | rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, |
2618 | enum machine_mode mode) | |
0ac081f6 | 2619 | { |
c4501e62 JJ |
2620 | if (GET_CODE (x) == SYMBOL_REF) |
2621 | { | |
2622 | enum tls_model model = SYMBOL_REF_TLS_MODEL (x); | |
2623 | if (model != 0) | |
2624 | return rs6000_legitimize_tls_address (x, model); | |
2625 | } | |
2626 | ||
9ebbca7d GK |
2627 | if (GET_CODE (x) == PLUS |
2628 | && GET_CODE (XEXP (x, 0)) == REG | |
2629 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2630 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
2631 | { | |
2632 | HOST_WIDE_INT high_int, low_int; | |
2633 | rtx sum; | |
a65c591c DE |
2634 | low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000; |
2635 | high_int = INTVAL (XEXP (x, 1)) - low_int; | |
9ebbca7d GK |
2636 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), |
2637 | GEN_INT (high_int)), 0); | |
2638 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
2639 | } | |
2640 | else if (GET_CODE (x) == PLUS | |
2641 | && GET_CODE (XEXP (x, 0)) == REG | |
2642 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
6ac7bf2c | 2643 | && GET_MODE_NUNITS (mode) == 1 |
a3170dc6 AH |
2644 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
2645 | || TARGET_POWERPC64 | |
fcce224d | 2646 | || (mode != DFmode && mode != TFmode)) |
9ebbca7d GK |
2647 | && (TARGET_POWERPC64 || mode != DImode) |
2648 | && mode != TImode) | |
2649 | { | |
2650 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
2651 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
2652 | } | |
0ac081f6 AH |
2653 | else if (ALTIVEC_VECTOR_MODE (mode)) |
2654 | { | |
2655 | rtx reg; | |
2656 | ||
2657 | /* Make sure both operands are registers. */ | |
2658 | if (GET_CODE (x) == PLUS) | |
9f85ed45 | 2659 | return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)), |
0ac081f6 AH |
2660 | force_reg (Pmode, XEXP (x, 1))); |
2661 | ||
2662 | reg = force_reg (Pmode, x); | |
2663 | return reg; | |
2664 | } | |
a3170dc6 AH |
2665 | else if (SPE_VECTOR_MODE (mode)) |
2666 | { | |
2667 | /* We accept [reg + reg] and [reg + OFFSET]. */ | |
2668 | ||
2669 | if (GET_CODE (x) == PLUS) | |
2670 | { | |
2671 | rtx op1 = XEXP (x, 0); | |
2672 | rtx op2 = XEXP (x, 1); | |
2673 | ||
2674 | op1 = force_reg (Pmode, op1); | |
2675 | ||
2676 | if (GET_CODE (op2) != REG | |
2677 | && (GET_CODE (op2) != CONST_INT | |
2678 | || !SPE_CONST_OFFSET_OK (INTVAL (op2)))) | |
2679 | op2 = force_reg (Pmode, op2); | |
2680 | ||
2681 | return gen_rtx_PLUS (Pmode, op1, op2); | |
2682 | } | |
2683 | ||
2684 | return force_reg (Pmode, x); | |
2685 | } | |
f1384257 AM |
2686 | else if (TARGET_ELF |
2687 | && TARGET_32BIT | |
2688 | && TARGET_NO_TOC | |
2689 | && ! flag_pic | |
9ebbca7d GK |
2690 | && GET_CODE (x) != CONST_INT |
2691 | && GET_CODE (x) != CONST_DOUBLE | |
2692 | && CONSTANT_P (x) | |
6ac7bf2c GK |
2693 | && GET_MODE_NUNITS (mode) == 1 |
2694 | && (GET_MODE_BITSIZE (mode) <= 32 | |
a3170dc6 | 2695 | || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode))) |
9ebbca7d GK |
2696 | { |
2697 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
2698 | emit_insn (gen_elf_high (reg, x)); |
2699 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
9ebbca7d | 2700 | } |
ee890fe2 SS |
2701 | else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC |
2702 | && ! flag_pic | |
ab82a49f AP |
2703 | #if TARGET_MACHO |
2704 | && ! MACHO_DYNAMIC_NO_PIC_P | |
2705 | #endif | |
ee890fe2 SS |
2706 | && GET_CODE (x) != CONST_INT |
2707 | && GET_CODE (x) != CONST_DOUBLE | |
2708 | && CONSTANT_P (x) | |
a3170dc6 | 2709 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode) |
ee890fe2 SS |
2710 | && mode != DImode |
2711 | && mode != TImode) | |
2712 | { | |
2713 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
2714 | emit_insn (gen_macho_high (reg, x)); |
2715 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
ee890fe2 | 2716 | } |
9ebbca7d | 2717 | else if (TARGET_TOC |
4d588c14 | 2718 | && constant_pool_expr_p (x) |
a9098fd0 | 2719 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
2720 | { |
2721 | return create_TOC_reference (x); | |
2722 | } | |
2723 | else | |
2724 | return NULL_RTX; | |
2725 | } | |
258bfae2 | 2726 | |
c4501e62 JJ |
2727 | /* Construct the SYMBOL_REF for the tls_get_addr function. */ |
2728 | ||
2729 | static GTY(()) rtx rs6000_tls_symbol; | |
2730 | static rtx | |
863d938c | 2731 | rs6000_tls_get_addr (void) |
c4501e62 JJ |
2732 | { |
2733 | if (!rs6000_tls_symbol) | |
2734 | rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr"); | |
2735 | ||
2736 | return rs6000_tls_symbol; | |
2737 | } | |
2738 | ||
2739 | /* Construct the SYMBOL_REF for TLS GOT references. */ | |
2740 | ||
2741 | static GTY(()) rtx rs6000_got_symbol; | |
2742 | static rtx | |
863d938c | 2743 | rs6000_got_sym (void) |
c4501e62 JJ |
2744 | { |
2745 | if (!rs6000_got_symbol) | |
2746 | { | |
2747 | rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); | |
2748 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL; | |
2749 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL; | |
2750 | } | |
2751 | ||
2752 | return rs6000_got_symbol; | |
2753 | } | |
2754 | ||
2755 | /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute | |
2756 | this (thread-local) address. */ | |
2757 | ||
2758 | static rtx | |
a2369ed3 | 2759 | rs6000_legitimize_tls_address (rtx addr, enum tls_model model) |
c4501e62 JJ |
2760 | { |
2761 | rtx dest, insn; | |
2762 | ||
2763 | dest = gen_reg_rtx (Pmode); | |
2764 | if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16) | |
2765 | { | |
2766 | rtx tlsreg; | |
2767 | ||
2768 | if (TARGET_64BIT) | |
2769 | { | |
2770 | tlsreg = gen_rtx_REG (Pmode, 13); | |
2771 | insn = gen_tls_tprel_64 (dest, tlsreg, addr); | |
2772 | } | |
2773 | else | |
2774 | { | |
2775 | tlsreg = gen_rtx_REG (Pmode, 2); | |
2776 | insn = gen_tls_tprel_32 (dest, tlsreg, addr); | |
2777 | } | |
2778 | emit_insn (insn); | |
2779 | } | |
2780 | else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32) | |
2781 | { | |
2782 | rtx tlsreg, tmp; | |
2783 | ||
2784 | tmp = gen_reg_rtx (Pmode); | |
2785 | if (TARGET_64BIT) | |
2786 | { | |
2787 | tlsreg = gen_rtx_REG (Pmode, 13); | |
2788 | insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr); | |
2789 | } | |
2790 | else | |
2791 | { | |
2792 | tlsreg = gen_rtx_REG (Pmode, 2); | |
2793 | insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr); | |
2794 | } | |
2795 | emit_insn (insn); | |
2796 | if (TARGET_64BIT) | |
2797 | insn = gen_tls_tprel_lo_64 (dest, tmp, addr); | |
2798 | else | |
2799 | insn = gen_tls_tprel_lo_32 (dest, tmp, addr); | |
2800 | emit_insn (insn); | |
2801 | } | |
2802 | else | |
2803 | { | |
2804 | rtx r3, got, tga, tmp1, tmp2, eqv; | |
2805 | ||
2806 | if (TARGET_64BIT) | |
2807 | got = gen_rtx_REG (Pmode, TOC_REGISTER); | |
2808 | else | |
2809 | { | |
2810 | if (flag_pic == 1) | |
2811 | got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); | |
2812 | else | |
2813 | { | |
2814 | rtx gsym = rs6000_got_sym (); | |
2815 | got = gen_reg_rtx (Pmode); | |
2816 | if (flag_pic == 0) | |
2817 | rs6000_emit_move (got, gsym, Pmode); | |
2818 | else | |
2819 | { | |
2820 | char buf[30]; | |
2821 | static int tls_got_labelno = 0; | |
2822 | rtx tempLR, lab, tmp3, mem; | |
2823 | rtx first, last; | |
2824 | ||
2825 | ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++); | |
2826 | lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
2827 | tempLR = gen_reg_rtx (Pmode); | |
2828 | tmp1 = gen_reg_rtx (Pmode); | |
2829 | tmp2 = gen_reg_rtx (Pmode); | |
2830 | tmp3 = gen_reg_rtx (Pmode); | |
2831 | mem = gen_rtx_MEM (Pmode, tmp1); | |
2832 | RTX_UNCHANGING_P (mem) = 1; | |
2833 | ||
2834 | first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab, | |
2835 | gsym)); | |
2836 | emit_move_insn (tmp1, tempLR); | |
2837 | emit_move_insn (tmp2, mem); | |
2838 | emit_insn (gen_addsi3 (tmp3, tmp1, tmp2)); | |
2839 | last = emit_move_insn (got, tmp3); | |
2840 | REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym, | |
2841 | REG_NOTES (last)); | |
2842 | REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, | |
2843 | REG_NOTES (first)); | |
2844 | REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, | |
2845 | REG_NOTES (last)); | |
2846 | } | |
2847 | } | |
2848 | } | |
2849 | ||
2850 | if (model == TLS_MODEL_GLOBAL_DYNAMIC) | |
2851 | { | |
2852 | r3 = gen_rtx_REG (Pmode, 3); | |
2853 | if (TARGET_64BIT) | |
2854 | insn = gen_tls_gd_64 (r3, got, addr); | |
2855 | else | |
2856 | insn = gen_tls_gd_32 (r3, got, addr); | |
2857 | start_sequence (); | |
2858 | emit_insn (insn); | |
2859 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
2860 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
2861 | insn = emit_call_insn (insn); | |
2862 | CONST_OR_PURE_CALL_P (insn) = 1; | |
2863 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
2864 | insn = get_insns (); | |
2865 | end_sequence (); | |
2866 | emit_libcall_block (insn, dest, r3, addr); | |
2867 | } | |
2868 | else if (model == TLS_MODEL_LOCAL_DYNAMIC) | |
2869 | { | |
2870 | r3 = gen_rtx_REG (Pmode, 3); | |
2871 | if (TARGET_64BIT) | |
2872 | insn = gen_tls_ld_64 (r3, got); | |
2873 | else | |
2874 | insn = gen_tls_ld_32 (r3, got); | |
2875 | start_sequence (); | |
2876 | emit_insn (insn); | |
2877 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
2878 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
2879 | insn = emit_call_insn (insn); | |
2880 | CONST_OR_PURE_CALL_P (insn) = 1; | |
2881 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
2882 | insn = get_insns (); | |
2883 | end_sequence (); | |
2884 | tmp1 = gen_reg_rtx (Pmode); | |
2885 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), | |
2886 | UNSPEC_TLSLD); | |
2887 | emit_libcall_block (insn, tmp1, r3, eqv); | |
2888 | if (rs6000_tls_size == 16) | |
2889 | { | |
2890 | if (TARGET_64BIT) | |
2891 | insn = gen_tls_dtprel_64 (dest, tmp1, addr); | |
2892 | else | |
2893 | insn = gen_tls_dtprel_32 (dest, tmp1, addr); | |
2894 | } | |
2895 | else if (rs6000_tls_size == 32) | |
2896 | { | |
2897 | tmp2 = gen_reg_rtx (Pmode); | |
2898 | if (TARGET_64BIT) | |
2899 | insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr); | |
2900 | else | |
2901 | insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr); | |
2902 | emit_insn (insn); | |
2903 | if (TARGET_64BIT) | |
2904 | insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr); | |
2905 | else | |
2906 | insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr); | |
2907 | } | |
2908 | else | |
2909 | { | |
2910 | tmp2 = gen_reg_rtx (Pmode); | |
2911 | if (TARGET_64BIT) | |
2912 | insn = gen_tls_got_dtprel_64 (tmp2, got, addr); | |
2913 | else | |
2914 | insn = gen_tls_got_dtprel_32 (tmp2, got, addr); | |
2915 | emit_insn (insn); | |
2916 | insn = gen_rtx_SET (Pmode, dest, | |
2917 | gen_rtx_PLUS (Pmode, tmp2, tmp1)); | |
2918 | } | |
2919 | emit_insn (insn); | |
2920 | } | |
2921 | else | |
2922 | { | |
2923 | /* IE, or 64 bit offset LE. */ | |
2924 | tmp2 = gen_reg_rtx (Pmode); | |
2925 | if (TARGET_64BIT) | |
2926 | insn = gen_tls_got_tprel_64 (tmp2, got, addr); | |
2927 | else | |
2928 | insn = gen_tls_got_tprel_32 (tmp2, got, addr); | |
2929 | emit_insn (insn); | |
2930 | if (TARGET_64BIT) | |
2931 | insn = gen_tls_tls_64 (dest, tmp2, addr); | |
2932 | else | |
2933 | insn = gen_tls_tls_32 (dest, tmp2, addr); | |
2934 | emit_insn (insn); | |
2935 | } | |
2936 | } | |
2937 | ||
2938 | return dest; | |
2939 | } | |
2940 | ||
2941 | /* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in | |
2942 | instruction definitions. */ | |
2943 | ||
2944 | int | |
a2369ed3 | 2945 | rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED) |
c4501e62 JJ |
2946 | { |
2947 | return RS6000_SYMBOL_REF_TLS_P (x); | |
2948 | } | |
2949 | ||
2950 | /* Return 1 if X contains a thread-local symbol. */ | |
2951 | ||
2952 | bool | |
a2369ed3 | 2953 | rs6000_tls_referenced_p (rtx x) |
c4501e62 JJ |
2954 | { |
2955 | return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0); | |
2956 | } | |
2957 | ||
2958 | /* Return 1 if *X is a thread-local symbol. This is the same as | |
2959 | rs6000_tls_symbol_ref except for the type of the unused argument. */ | |
2960 | ||
2961 | static inline int | |
a2369ed3 | 2962 | rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
2963 | { |
2964 | return RS6000_SYMBOL_REF_TLS_P (*x); | |
2965 | } | |
2966 | ||
24ea750e DJ |
2967 | /* The convention appears to be to define this wherever it is used. |
2968 | With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P | |
2969 | is now used here. */ | |
2970 | #ifndef REG_MODE_OK_FOR_BASE_P | |
2971 | #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO) | |
2972 | #endif | |
2973 | ||
2974 | /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to | |
2975 | replace the input X, or the original X if no replacement is called for. | |
2976 | The output parameter *WIN is 1 if the calling macro should goto WIN, | |
2977 | 0 if it should not. | |
2978 | ||
2979 | For RS/6000, we wish to handle large displacements off a base | |
2980 | register by splitting the addend across an addiu/addis and the mem insn. | |
2981 | This cuts number of extra insns needed from 3 to 1. | |
2982 | ||
2983 | On Darwin, we use this to generate code for floating point constants. | |
2984 | A movsf_low is generated so we wind up with 2 instructions rather than 3. | |
2985 | The Darwin code is inside #if TARGET_MACHO because only then is | |
2986 | machopic_function_base_name() defined. */ | |
2987 | rtx | |
a2369ed3 DJ |
2988 | rs6000_legitimize_reload_address (rtx x, enum machine_mode mode, |
2989 | int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win) | |
24ea750e DJ |
2990 | { |
2991 | /* We must recognize output that we have already generated ourselves. */ | |
2992 | if (GET_CODE (x) == PLUS | |
2993 | && GET_CODE (XEXP (x, 0)) == PLUS | |
2994 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
2995 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
2996 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2997 | { | |
2998 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
2999 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3000 | opnum, (enum reload_type)type); | |
3001 | *win = 1; | |
3002 | return x; | |
3003 | } | |
3deb2758 | 3004 | |
24ea750e DJ |
3005 | #if TARGET_MACHO |
3006 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic | |
3007 | && GET_CODE (x) == LO_SUM | |
3008 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3009 | && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx | |
3010 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH | |
3011 | && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST | |
3012 | && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1) | |
3013 | && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS | |
3014 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF | |
3015 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF) | |
3016 | { | |
3017 | /* Result of previous invocation of this function on Darwin | |
6f317ef3 | 3018 | floating point constant. */ |
24ea750e DJ |
3019 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
3020 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
3021 | opnum, (enum reload_type)type); | |
3022 | *win = 1; | |
3023 | return x; | |
3024 | } | |
3025 | #endif | |
3026 | if (GET_CODE (x) == PLUS | |
3027 | && GET_CODE (XEXP (x, 0)) == REG | |
3028 | && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER | |
3029 | && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode) | |
78c875e8 | 3030 | && GET_CODE (XEXP (x, 1)) == CONST_INT |
93638d7a | 3031 | && !SPE_VECTOR_MODE (mode) |
78c875e8 | 3032 | && !ALTIVEC_VECTOR_MODE (mode)) |
24ea750e DJ |
3033 | { |
3034 | HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); | |
3035 | HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; | |
3036 | HOST_WIDE_INT high | |
3037 | = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
3038 | ||
3039 | /* Check for 32-bit overflow. */ | |
3040 | if (high + low != val) | |
3041 | { | |
3042 | *win = 0; | |
3043 | return x; | |
3044 | } | |
3045 | ||
3046 | /* Reload the high part into a base reg; leave the low part | |
3047 | in the mem directly. */ | |
3048 | ||
3049 | x = gen_rtx_PLUS (GET_MODE (x), | |
3050 | gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), | |
3051 | GEN_INT (high)), | |
3052 | GEN_INT (low)); | |
3053 | ||
3054 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3055 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3056 | opnum, (enum reload_type)type); | |
3057 | *win = 1; | |
3058 | return x; | |
3059 | } | |
3060 | #if TARGET_MACHO | |
3061 | if (GET_CODE (x) == SYMBOL_REF | |
3062 | && DEFAULT_ABI == ABI_DARWIN | |
69ef87e2 | 3063 | && !ALTIVEC_VECTOR_MODE (mode) |
24ea750e DJ |
3064 | && flag_pic) |
3065 | { | |
3066 | /* Darwin load of floating point constant. */ | |
3067 | rtx offset = gen_rtx (CONST, Pmode, | |
3068 | gen_rtx (MINUS, Pmode, x, | |
3069 | gen_rtx (SYMBOL_REF, Pmode, | |
3070 | machopic_function_base_name ()))); | |
3071 | x = gen_rtx (LO_SUM, GET_MODE (x), | |
3072 | gen_rtx (PLUS, Pmode, pic_offset_table_rtx, | |
3073 | gen_rtx (HIGH, Pmode, offset)), offset); | |
3074 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3075 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
3076 | opnum, (enum reload_type)type); | |
3077 | *win = 1; | |
3078 | return x; | |
3079 | } | |
ab82a49f AP |
3080 | if (GET_CODE (x) == SYMBOL_REF |
3081 | && DEFAULT_ABI == ABI_DARWIN | |
3082 | && !ALTIVEC_VECTOR_MODE (mode) | |
3083 | && MACHO_DYNAMIC_NO_PIC_P) | |
3084 | { | |
3085 | /* Darwin load of floating point constant. */ | |
3086 | x = gen_rtx (LO_SUM, GET_MODE (x), | |
3087 | gen_rtx (HIGH, Pmode, x), x); | |
3088 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3089 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
3090 | opnum, (enum reload_type)type); | |
3091 | *win = 1; | |
3092 | return x; | |
3093 | } | |
24ea750e DJ |
3094 | #endif |
3095 | if (TARGET_TOC | |
4d588c14 | 3096 | && constant_pool_expr_p (x) |
c1f11548 | 3097 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode)) |
24ea750e DJ |
3098 | { |
3099 | (x) = create_TOC_reference (x); | |
3100 | *win = 1; | |
3101 | return x; | |
3102 | } | |
3103 | *win = 0; | |
3104 | return x; | |
3105 | } | |
3106 | ||
258bfae2 FS |
3107 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression |
3108 | that is a valid memory address for an instruction. | |
3109 | The MODE argument is the machine mode for the MEM expression | |
3110 | that wants to use this address. | |
3111 | ||
3112 | On the RS/6000, there are four valid address: a SYMBOL_REF that | |
3113 | refers to a constant pool entry of an address (or the sum of it | |
3114 | plus a constant), a short (16-bit signed) constant plus a register, | |
3115 | the sum of two registers, or a register indirect, possibly with an | |
5bdc5878 | 3116 | auto-increment. For DFmode and DImode with a constant plus register, |
258bfae2 FS |
3117 | we must ensure that both words are addressable or PowerPC64 with offset |
3118 | word aligned. | |
3119 | ||
3120 | For modes spanning multiple registers (DFmode in 32-bit GPRs, | |
3121 | 32-bit DImode, TImode), indexed addressing cannot be used because | |
3122 | adjacent memory cells are accessed by adding word-sized offsets | |
3123 | during assembly output. */ | |
3124 | int | |
a2369ed3 | 3125 | rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict) |
258bfae2 | 3126 | { |
c4501e62 JJ |
3127 | if (RS6000_SYMBOL_REF_TLS_P (x)) |
3128 | return 0; | |
4d588c14 | 3129 | if (legitimate_indirect_address_p (x, reg_ok_strict)) |
258bfae2 FS |
3130 | return 1; |
3131 | if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) | |
0d6d6892 | 3132 | && !ALTIVEC_VECTOR_MODE (mode) |
a3170dc6 | 3133 | && !SPE_VECTOR_MODE (mode) |
258bfae2 | 3134 | && TARGET_UPDATE |
4d588c14 | 3135 | && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict)) |
258bfae2 | 3136 | return 1; |
4d588c14 | 3137 | if (legitimate_small_data_p (mode, x)) |
258bfae2 | 3138 | return 1; |
4d588c14 | 3139 | if (legitimate_constant_pool_address_p (x)) |
258bfae2 FS |
3140 | return 1; |
3141 | /* If not REG_OK_STRICT (before reload) let pass any stack offset. */ | |
3142 | if (! reg_ok_strict | |
3143 | && GET_CODE (x) == PLUS | |
3144 | && GET_CODE (XEXP (x, 0)) == REG | |
3145 | && XEXP (x, 0) == virtual_stack_vars_rtx | |
3146 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
3147 | return 1; | |
4d588c14 | 3148 | if (legitimate_offset_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3149 | return 1; |
3150 | if (mode != TImode | |
a3170dc6 AH |
3151 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
3152 | || TARGET_POWERPC64 | |
fcce224d | 3153 | || (mode != DFmode && mode != TFmode)) |
258bfae2 | 3154 | && (TARGET_POWERPC64 || mode != DImode) |
4d588c14 | 3155 | && legitimate_indexed_address_p (x, reg_ok_strict)) |
258bfae2 | 3156 | return 1; |
4d588c14 | 3157 | if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3158 | return 1; |
3159 | return 0; | |
3160 | } | |
4d588c14 RH |
3161 | |
3162 | /* Go to LABEL if ADDR (a legitimate address expression) | |
3163 | has an effect that depends on the machine mode it is used for. | |
3164 | ||
3165 | On the RS/6000 this is true of all integral offsets (since AltiVec | |
3166 | modes don't allow them) or is a pre-increment or decrement. | |
3167 | ||
3168 | ??? Except that due to conceptual problems in offsettable_address_p | |
3169 | we can't really report the problems of integral offsets. So leave | |
3170 | this assuming that the adjustable offset must be valid for the | |
3171 | sub-words of a TFmode operand, which is what we had before. */ | |
3172 | ||
3173 | bool | |
a2369ed3 | 3174 | rs6000_mode_dependent_address (rtx addr) |
4d588c14 RH |
3175 | { |
3176 | switch (GET_CODE (addr)) | |
3177 | { | |
3178 | case PLUS: | |
3179 | if (GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
3180 | { | |
3181 | unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1)); | |
3182 | return val + 12 + 0x8000 >= 0x10000; | |
3183 | } | |
3184 | break; | |
3185 | ||
3186 | case LO_SUM: | |
3187 | return true; | |
3188 | ||
3189 | case PRE_INC: | |
3190 | case PRE_DEC: | |
3191 | return TARGET_UPDATE; | |
3192 | ||
3193 | default: | |
3194 | break; | |
3195 | } | |
3196 | ||
3197 | return false; | |
3198 | } | |
fb4d4348 | 3199 | \f |
a4f6c312 SS |
3200 | /* Try to output insns to set TARGET equal to the constant C if it can |
3201 | be done in less than N insns. Do all computations in MODE. | |
3202 | Returns the place where the output has been placed if it can be | |
3203 | done and the insns have been emitted. If it would take more than N | |
3204 | insns, zero is returned and no insns and emitted. */ | |
2bfcf297 DB |
3205 | |
3206 | rtx | |
a2369ed3 DJ |
3207 | rs6000_emit_set_const (rtx dest, enum machine_mode mode, |
3208 | rtx source, int n ATTRIBUTE_UNUSED) | |
2bfcf297 | 3209 | { |
af8cb5c5 | 3210 | rtx result, insn, set; |
2bfcf297 DB |
3211 | HOST_WIDE_INT c0, c1; |
3212 | ||
af8cb5c5 | 3213 | if (mode == QImode || mode == HImode) |
2bfcf297 DB |
3214 | { |
3215 | if (dest == NULL) | |
3216 | dest = gen_reg_rtx (mode); | |
3217 | emit_insn (gen_rtx_SET (VOIDmode, dest, source)); | |
3218 | return dest; | |
3219 | } | |
af8cb5c5 | 3220 | else if (mode == SImode) |
2bfcf297 | 3221 | { |
af8cb5c5 DE |
3222 | result = no_new_pseudos ? dest : gen_reg_rtx (SImode); |
3223 | ||
3224 | emit_insn (gen_rtx_SET (VOIDmode, result, | |
3225 | GEN_INT (INTVAL (source) | |
3226 | & (~ (HOST_WIDE_INT) 0xffff)))); | |
3227 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3228 | gen_rtx_IOR (SImode, result, | |
3229 | GEN_INT (INTVAL (source) & 0xffff)))); | |
3230 | result = dest; | |
2bfcf297 | 3231 | } |
af8cb5c5 | 3232 | else if (mode == DImode) |
2bfcf297 | 3233 | { |
af8cb5c5 DE |
3234 | if (GET_CODE (source) == CONST_INT) |
3235 | { | |
3236 | c0 = INTVAL (source); | |
3237 | c1 = -(c0 < 0); | |
3238 | } | |
3239 | else if (GET_CODE (source) == CONST_DOUBLE) | |
3240 | { | |
2bfcf297 | 3241 | #if HOST_BITS_PER_WIDE_INT >= 64 |
af8cb5c5 DE |
3242 | c0 = CONST_DOUBLE_LOW (source); |
3243 | c1 = -(c0 < 0); | |
2bfcf297 | 3244 | #else |
af8cb5c5 DE |
3245 | c0 = CONST_DOUBLE_LOW (source); |
3246 | c1 = CONST_DOUBLE_HIGH (source); | |
2bfcf297 | 3247 | #endif |
af8cb5c5 DE |
3248 | } |
3249 | else | |
3250 | abort (); | |
3251 | ||
3252 | result = rs6000_emit_set_long_const (dest, c0, c1); | |
2bfcf297 DB |
3253 | } |
3254 | else | |
a4f6c312 | 3255 | abort (); |
2bfcf297 | 3256 | |
af8cb5c5 DE |
3257 | insn = get_last_insn (); |
3258 | set = single_set (insn); | |
3259 | if (! CONSTANT_P (SET_SRC (set))) | |
3260 | set_unique_reg_note (insn, REG_EQUAL, source); | |
3261 | ||
3262 | return result; | |
2bfcf297 DB |
3263 | } |
3264 | ||
3265 | /* Having failed to find a 3 insn sequence in rs6000_emit_set_const, | |
3266 | fall back to a straight forward decomposition. We do this to avoid | |
3267 | exponential run times encountered when looking for longer sequences | |
3268 | with rs6000_emit_set_const. */ | |
3269 | static rtx | |
a2369ed3 | 3270 | rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2) |
2bfcf297 DB |
3271 | { |
3272 | if (!TARGET_POWERPC64) | |
3273 | { | |
3274 | rtx operand1, operand2; | |
3275 | ||
3276 | operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0, | |
3277 | DImode); | |
3278 | operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, | |
3279 | DImode); | |
3280 | emit_move_insn (operand1, GEN_INT (c1)); | |
3281 | emit_move_insn (operand2, GEN_INT (c2)); | |
3282 | } | |
3283 | else | |
3284 | { | |
bc06712d | 3285 | HOST_WIDE_INT ud1, ud2, ud3, ud4; |
252b88f7 | 3286 | |
bc06712d | 3287 | ud1 = c1 & 0xffff; |
f921c9c9 | 3288 | ud2 = (c1 & 0xffff0000) >> 16; |
2bfcf297 | 3289 | #if HOST_BITS_PER_WIDE_INT >= 64 |
bc06712d | 3290 | c2 = c1 >> 32; |
2bfcf297 | 3291 | #endif |
bc06712d | 3292 | ud3 = c2 & 0xffff; |
f921c9c9 | 3293 | ud4 = (c2 & 0xffff0000) >> 16; |
2bfcf297 | 3294 | |
bc06712d TR |
3295 | if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) |
3296 | || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) | |
2bfcf297 | 3297 | { |
bc06712d | 3298 | if (ud1 & 0x8000) |
b78d48dd | 3299 | emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000))); |
bc06712d TR |
3300 | else |
3301 | emit_move_insn (dest, GEN_INT (ud1)); | |
2bfcf297 | 3302 | } |
2bfcf297 | 3303 | |
bc06712d TR |
3304 | else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000)) |
3305 | || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000))) | |
252b88f7 | 3306 | { |
bc06712d TR |
3307 | if (ud2 & 0x8000) |
3308 | emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000) | |
3309 | - 0x80000000)); | |
252b88f7 | 3310 | else |
bc06712d TR |
3311 | emit_move_insn (dest, GEN_INT (ud2 << 16)); |
3312 | if (ud1 != 0) | |
3313 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
252b88f7 | 3314 | } |
bc06712d TR |
3315 | else if ((ud4 == 0xffff && (ud3 & 0x8000)) |
3316 | || (ud4 == 0 && ! (ud3 & 0x8000))) | |
3317 | { | |
3318 | if (ud3 & 0x8000) | |
3319 | emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000) | |
3320 | - 0x80000000)); | |
3321 | else | |
3322 | emit_move_insn (dest, GEN_INT (ud3 << 16)); | |
3323 | ||
3324 | if (ud2 != 0) | |
3325 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2))); | |
3326 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16))); | |
3327 | if (ud1 != 0) | |
3328 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
3329 | } | |
3330 | else | |
3331 | { | |
3332 | if (ud4 & 0x8000) | |
3333 | emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000) | |
3334 | - 0x80000000)); | |
3335 | else | |
3336 | emit_move_insn (dest, GEN_INT (ud4 << 16)); | |
3337 | ||
3338 | if (ud3 != 0) | |
3339 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3))); | |
2bfcf297 | 3340 | |
bc06712d TR |
3341 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32))); |
3342 | if (ud2 != 0) | |
3343 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, | |
3344 | GEN_INT (ud2 << 16))); | |
3345 | if (ud1 != 0) | |
3346 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
3347 | } | |
3348 | } | |
2bfcf297 DB |
3349 | return dest; |
3350 | } | |
3351 | ||
fb4d4348 GK |
3352 | /* Emit a move from SOURCE to DEST in mode MODE. */ |
3353 | void | |
a2369ed3 | 3354 | rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode) |
fb4d4348 GK |
3355 | { |
3356 | rtx operands[2]; | |
3357 | operands[0] = dest; | |
3358 | operands[1] = source; | |
3359 | ||
3360 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ | |
3361 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
3362 | && ! FLOAT_MODE_P (mode) | |
3363 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
3364 | { | |
3365 | /* FIXME. This should never happen. */ | |
3366 | /* Since it seems that it does, do the safe thing and convert | |
3367 | to a CONST_INT. */ | |
2496c7bd | 3368 | operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode); |
fb4d4348 GK |
3369 | } |
3370 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
3371 | && ! FLOAT_MODE_P (mode) | |
3372 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
3373 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
3374 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
3375 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
3376 | abort (); | |
c9e8cb32 DD |
3377 | |
3378 | /* Check if GCC is setting up a block move that will end up using FP | |
3379 | registers as temporaries. We must make sure this is acceptable. */ | |
3380 | if (GET_CODE (operands[0]) == MEM | |
3381 | && GET_CODE (operands[1]) == MEM | |
3382 | && mode == DImode | |
41543739 GK |
3383 | && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0])) |
3384 | || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1]))) | |
3385 | && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32 | |
3386 | ? 32 : MEM_ALIGN (operands[0]))) | |
3387 | || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32 | |
3388 | ? 32 | |
3389 | : MEM_ALIGN (operands[1])))) | |
3390 | && ! MEM_VOLATILE_P (operands [0]) | |
3391 | && ! MEM_VOLATILE_P (operands [1])) | |
c9e8cb32 | 3392 | { |
41543739 GK |
3393 | emit_move_insn (adjust_address (operands[0], SImode, 0), |
3394 | adjust_address (operands[1], SImode, 0)); | |
3395 | emit_move_insn (adjust_address (operands[0], SImode, 4), | |
3396 | adjust_address (operands[1], SImode, 4)); | |
c9e8cb32 DD |
3397 | return; |
3398 | } | |
fb4d4348 | 3399 | |
67cef334 DE |
3400 | if (!no_new_pseudos) |
3401 | { | |
3402 | if (GET_CODE (operands[1]) == MEM && optimize > 0 | |
3403 | && (mode == QImode || mode == HImode || mode == SImode) | |
3404 | && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode)) | |
3405 | { | |
3406 | rtx reg = gen_reg_rtx (word_mode); | |
3407 | ||
3408 | emit_insn (gen_rtx_SET (word_mode, reg, | |
3409 | gen_rtx_ZERO_EXTEND (word_mode, | |
3410 | operands[1]))); | |
3411 | operands[1] = gen_lowpart (mode, reg); | |
3412 | } | |
3413 | if (GET_CODE (operands[0]) != REG) | |
3414 | operands[1] = force_reg (mode, operands[1]); | |
3415 | } | |
a9098fd0 | 3416 | |
a3170dc6 AH |
3417 | if (mode == SFmode && ! TARGET_POWERPC |
3418 | && TARGET_HARD_FLOAT && TARGET_FPRS | |
ffc14f31 | 3419 | && GET_CODE (operands[0]) == MEM) |
fb4d4348 | 3420 | { |
ffc14f31 GK |
3421 | int regnum; |
3422 | ||
3423 | if (reload_in_progress || reload_completed) | |
3424 | regnum = true_regnum (operands[1]); | |
3425 | else if (GET_CODE (operands[1]) == REG) | |
3426 | regnum = REGNO (operands[1]); | |
3427 | else | |
3428 | regnum = -1; | |
fb4d4348 GK |
3429 | |
3430 | /* If operands[1] is a register, on POWER it may have | |
3431 | double-precision data in it, so truncate it to single | |
3432 | precision. */ | |
3433 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
3434 | { | |
3435 | rtx newreg; | |
3436 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
3437 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
3438 | operands[1] = newreg; | |
3439 | } | |
3440 | } | |
3441 | ||
c4501e62 JJ |
3442 | /* Recognize the case where operand[1] is a reference to thread-local |
3443 | data and load its address to a register. */ | |
3444 | if (GET_CODE (operands[1]) == SYMBOL_REF) | |
3445 | { | |
3446 | enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]); | |
3447 | if (model != 0) | |
3448 | operands[1] = rs6000_legitimize_tls_address (operands[1], model); | |
3449 | } | |
3450 | ||
8f4e6caf RH |
3451 | /* Handle the case where reload calls us with an invalid address. */ |
3452 | if (reload_in_progress && mode == Pmode | |
69ef87e2 | 3453 | && (! general_operand (operands[1], mode) |
8f4e6caf RH |
3454 | || ! nonimmediate_operand (operands[0], mode))) |
3455 | goto emit_set; | |
3456 | ||
3457 | /* Handle the case of CONSTANT_P_RTX. */ | |
3458 | if (GET_CODE (operands[1]) == CONSTANT_P_RTX) | |
3459 | goto emit_set; | |
a9098fd0 | 3460 | |
fb4d4348 GK |
3461 | /* FIXME: In the long term, this switch statement should go away |
3462 | and be replaced by a sequence of tests based on things like | |
3463 | mode == Pmode. */ | |
3464 | switch (mode) | |
3465 | { | |
3466 | case HImode: | |
3467 | case QImode: | |
3468 | if (CONSTANT_P (operands[1]) | |
3469 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 3470 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3471 | break; |
3472 | ||
06f4e019 | 3473 | case TFmode: |
fb4d4348 GK |
3474 | case DFmode: |
3475 | case SFmode: | |
3476 | if (CONSTANT_P (operands[1]) | |
3477 | && ! easy_fp_constant (operands[1], mode)) | |
a9098fd0 | 3478 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3479 | break; |
3480 | ||
0ac081f6 AH |
3481 | case V16QImode: |
3482 | case V8HImode: | |
3483 | case V4SFmode: | |
3484 | case V4SImode: | |
a3170dc6 AH |
3485 | case V4HImode: |
3486 | case V2SFmode: | |
3487 | case V2SImode: | |
00a892b8 | 3488 | case V1DImode: |
69ef87e2 | 3489 | if (CONSTANT_P (operands[1]) |
d744e06e | 3490 | && !easy_vector_constant (operands[1], mode)) |
0ac081f6 AH |
3491 | operands[1] = force_const_mem (mode, operands[1]); |
3492 | break; | |
3493 | ||
fb4d4348 | 3494 | case SImode: |
a9098fd0 | 3495 | case DImode: |
fb4d4348 GK |
3496 | /* Use default pattern for address of ELF small data */ |
3497 | if (TARGET_ELF | |
a9098fd0 | 3498 | && mode == Pmode |
f607bc57 | 3499 | && DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
3500 | && (GET_CODE (operands[1]) == SYMBOL_REF |
3501 | || GET_CODE (operands[1]) == CONST) | |
3502 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
3503 | { |
3504 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
3505 | return; | |
3506 | } | |
3507 | ||
f607bc57 | 3508 | if (DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
3509 | && mode == Pmode && mode == SImode |
3510 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
3511 | { |
3512 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
3513 | return; | |
3514 | } | |
3515 | ||
ee890fe2 | 3516 | if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN) |
f1384257 AM |
3517 | && TARGET_NO_TOC |
3518 | && ! flag_pic | |
a9098fd0 | 3519 | && mode == Pmode |
fb4d4348 GK |
3520 | && CONSTANT_P (operands[1]) |
3521 | && GET_CODE (operands[1]) != HIGH | |
3522 | && GET_CODE (operands[1]) != CONST_INT) | |
3523 | { | |
a9098fd0 | 3524 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
3525 | |
3526 | /* If this is a function address on -mcall-aixdesc, | |
3527 | convert it to the address of the descriptor. */ | |
3528 | if (DEFAULT_ABI == ABI_AIX | |
3529 | && GET_CODE (operands[1]) == SYMBOL_REF | |
3530 | && XSTR (operands[1], 0)[0] == '.') | |
3531 | { | |
3532 | const char *name = XSTR (operands[1], 0); | |
3533 | rtx new_ref; | |
3534 | while (*name == '.') | |
3535 | name++; | |
3536 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
3537 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
3538 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
d1908feb | 3539 | SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]); |
fb4d4348 | 3540 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); |
d1908feb | 3541 | SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]); |
fb4d4348 GK |
3542 | operands[1] = new_ref; |
3543 | } | |
7509c759 | 3544 | |
ee890fe2 SS |
3545 | if (DEFAULT_ABI == ABI_DARWIN) |
3546 | { | |
ab82a49f AP |
3547 | #if TARGET_MACHO |
3548 | if (MACHO_DYNAMIC_NO_PIC_P) | |
3549 | { | |
3550 | /* Take care of any required data indirection. */ | |
3551 | operands[1] = rs6000_machopic_legitimize_pic_address ( | |
3552 | operands[1], mode, operands[0]); | |
3553 | if (operands[0] != operands[1]) | |
3554 | emit_insn (gen_rtx_SET (VOIDmode, | |
3555 | operands[0], operands[1])); | |
3556 | return; | |
3557 | } | |
3558 | #endif | |
ee890fe2 SS |
3559 | emit_insn (gen_macho_high (target, operands[1])); |
3560 | emit_insn (gen_macho_low (operands[0], target, operands[1])); | |
3561 | return; | |
3562 | } | |
3563 | ||
fb4d4348 GK |
3564 | emit_insn (gen_elf_high (target, operands[1])); |
3565 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
3566 | return; | |
3567 | } | |
3568 | ||
a9098fd0 GK |
3569 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
3570 | and we have put it in the TOC, we just need to make a TOC-relative | |
3571 | reference to it. */ | |
3572 | if (TARGET_TOC | |
3573 | && GET_CODE (operands[1]) == SYMBOL_REF | |
4d588c14 | 3574 | && constant_pool_expr_p (operands[1]) |
a9098fd0 GK |
3575 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), |
3576 | get_pool_mode (operands[1]))) | |
fb4d4348 | 3577 | { |
a9098fd0 | 3578 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 3579 | } |
a9098fd0 GK |
3580 | else if (mode == Pmode |
3581 | && CONSTANT_P (operands[1]) | |
38886f37 AO |
3582 | && ((GET_CODE (operands[1]) != CONST_INT |
3583 | && ! easy_fp_constant (operands[1], mode)) | |
3584 | || (GET_CODE (operands[1]) == CONST_INT | |
3585 | && num_insns_constant (operands[1], mode) > 2) | |
3586 | || (GET_CODE (operands[0]) == REG | |
3587 | && FP_REGNO_P (REGNO (operands[0])))) | |
a9098fd0 | 3588 | && GET_CODE (operands[1]) != HIGH |
4d588c14 RH |
3589 | && ! legitimate_constant_pool_address_p (operands[1]) |
3590 | && ! toc_relative_expr_p (operands[1])) | |
fb4d4348 GK |
3591 | { |
3592 | /* Emit a USE operation so that the constant isn't deleted if | |
3593 | expensive optimizations are turned on because nobody | |
3594 | references it. This should only be done for operands that | |
3595 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
3596 | This should not be done for operands that contain LABEL_REFs. | |
3597 | For now, we just handle the obvious case. */ | |
3598 | if (GET_CODE (operands[1]) != LABEL_REF) | |
3599 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
3600 | ||
c859cda6 | 3601 | #if TARGET_MACHO |
ee890fe2 | 3602 | /* Darwin uses a special PIC legitimizer. */ |
ab82a49f | 3603 | if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT) |
ee890fe2 | 3604 | { |
ee890fe2 SS |
3605 | operands[1] = |
3606 | rs6000_machopic_legitimize_pic_address (operands[1], mode, | |
c859cda6 DJ |
3607 | operands[0]); |
3608 | if (operands[0] != operands[1]) | |
3609 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
ee890fe2 SS |
3610 | return; |
3611 | } | |
c859cda6 | 3612 | #endif |
ee890fe2 | 3613 | |
fb4d4348 GK |
3614 | /* If we are to limit the number of things we put in the TOC and |
3615 | this is a symbol plus a constant we can add in one insn, | |
3616 | just put the symbol in the TOC and add the constant. Don't do | |
3617 | this if reload is in progress. */ | |
3618 | if (GET_CODE (operands[1]) == CONST | |
3619 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
3620 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 3621 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
3622 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
3623 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
3624 | && ! side_effects_p (operands[0])) | |
3625 | { | |
a4f6c312 SS |
3626 | rtx sym = |
3627 | force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); | |
fb4d4348 GK |
3628 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
3629 | ||
a9098fd0 GK |
3630 | sym = force_reg (mode, sym); |
3631 | if (mode == SImode) | |
3632 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
3633 | else | |
3634 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
3635 | return; |
3636 | } | |
3637 | ||
a9098fd0 | 3638 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3639 | |
3640 | if (TARGET_TOC | |
4d588c14 | 3641 | && constant_pool_expr_p (XEXP (operands[1], 0)) |
d34c5b80 DE |
3642 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P ( |
3643 | get_pool_constant (XEXP (operands[1], 0)), | |
3644 | get_pool_mode (XEXP (operands[1], 0)))) | |
a9098fd0 | 3645 | { |
ba4828e0 RK |
3646 | operands[1] |
3647 | = gen_rtx_MEM (mode, | |
3648 | create_TOC_reference (XEXP (operands[1], 0))); | |
3649 | set_mem_alias_set (operands[1], get_TOC_alias_set ()); | |
fb4d4348 | 3650 | RTX_UNCHANGING_P (operands[1]) = 1; |
a9098fd0 | 3651 | } |
fb4d4348 GK |
3652 | } |
3653 | break; | |
a9098fd0 | 3654 | |
fb4d4348 GK |
3655 | case TImode: |
3656 | if (GET_CODE (operands[0]) == MEM | |
3657 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
3658 | && ! reload_in_progress) | |
792760b9 RK |
3659 | operands[0] |
3660 | = replace_equiv_address (operands[0], | |
3661 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
fb4d4348 GK |
3662 | |
3663 | if (GET_CODE (operands[1]) == MEM | |
3664 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
3665 | && ! reload_in_progress) | |
792760b9 RK |
3666 | operands[1] |
3667 | = replace_equiv_address (operands[1], | |
3668 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
27dc0551 DE |
3669 | if (TARGET_POWER) |
3670 | { | |
3671 | emit_insn (gen_rtx_PARALLEL (VOIDmode, | |
3672 | gen_rtvec (2, | |
3673 | gen_rtx_SET (VOIDmode, | |
3674 | operands[0], operands[1]), | |
3675 | gen_rtx_CLOBBER (VOIDmode, | |
3676 | gen_rtx_SCRATCH (SImode))))); | |
3677 | return; | |
3678 | } | |
fb4d4348 GK |
3679 | break; |
3680 | ||
3681 | default: | |
3682 | abort (); | |
3683 | } | |
3684 | ||
a9098fd0 GK |
3685 | /* Above, we may have called force_const_mem which may have returned |
3686 | an invalid address. If we can, fix this up; otherwise, reload will | |
3687 | have to deal with it. */ | |
8f4e6caf RH |
3688 | if (GET_CODE (operands[1]) == MEM && ! reload_in_progress) |
3689 | operands[1] = validize_mem (operands[1]); | |
a9098fd0 | 3690 | |
8f4e6caf | 3691 | emit_set: |
fb4d4348 GK |
3692 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
3693 | } | |
4697a36c | 3694 | \f |
2858f73a GK |
3695 | /* Nonzero if we can use a floating-point register to pass this arg. */ |
3696 | #define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \ | |
3697 | (GET_MODE_CLASS (MODE) == MODE_FLOAT \ | |
3698 | && (CUM)->fregno <= FP_ARG_MAX_REG \ | |
3699 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
3700 | ||
3701 | /* Nonzero if we can use an AltiVec register to pass this arg. */ | |
3702 | #define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \ | |
3703 | (ALTIVEC_VECTOR_MODE (MODE) \ | |
3704 | && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \ | |
3705 | && TARGET_ALTIVEC_ABI \ | |
3706 | && (DEFAULT_ABI == ABI_V4 || (NAMED))) | |
3707 | ||
c6e8c921 GK |
3708 | /* Return a nonzero value to say to return the function value in |
3709 | memory, just as large structures are always returned. TYPE will be | |
3710 | the data type of the value, and FNTYPE will be the type of the | |
3711 | function doing the returning, or @code{NULL} for libcalls. | |
3712 | ||
3713 | The AIX ABI for the RS/6000 specifies that all structures are | |
3714 | returned in memory. The Darwin ABI does the same. The SVR4 ABI | |
3715 | specifies that structures <= 8 bytes are returned in r3/r4, but a | |
3716 | draft put them in memory, and GCC used to implement the draft | |
3717 | instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET | |
3718 | controls this instead of DEFAULT_ABI; V.4 targets needing backward | |
3719 | compatibility can change DRAFT_V4_STRUCT_RET to override the | |
3720 | default, and -m switches get the final word. See | |
3721 | rs6000_override_options for more details. | |
3722 | ||
3723 | The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit | |
3724 | long double support is enabled. These values are returned in memory. | |
3725 | ||
3726 | int_size_in_bytes returns -1 for variable size objects, which go in | |
3727 | memory always. The cast to unsigned makes -1 > 8. */ | |
3728 | ||
3729 | static bool | |
3730 | rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED) | |
3731 | { | |
3732 | if (AGGREGATE_TYPE_P (type) | |
3733 | && (TARGET_AIX_STRUCT_RET | |
3734 | || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8)) | |
3735 | return true; | |
3736 | if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode) | |
3737 | return true; | |
3738 | return false; | |
3739 | } | |
3740 | ||
4697a36c MM |
3741 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
3742 | for a call to a function whose data type is FNTYPE. | |
3743 | For a library call, FNTYPE is 0. | |
3744 | ||
3745 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 3746 | so we never return a PARALLEL. */ |
4697a36c MM |
3747 | |
3748 | void | |
a2369ed3 DJ |
3749 | init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, |
3750 | rtx libname ATTRIBUTE_UNUSED, int incoming, int libcall) | |
4697a36c MM |
3751 | { |
3752 | static CUMULATIVE_ARGS zero_cumulative; | |
3753 | ||
3754 | *cum = zero_cumulative; | |
3755 | cum->words = 0; | |
3756 | cum->fregno = FP_ARG_MIN_REG; | |
0ac081f6 | 3757 | cum->vregno = ALTIVEC_ARG_MIN_REG; |
4697a36c | 3758 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); |
ddcc8263 DE |
3759 | cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall) |
3760 | ? CALL_LIBCALL : CALL_NORMAL); | |
4cc833b7 | 3761 | cum->sysv_gregno = GP_ARG_MIN_REG; |
a6c9bed4 AH |
3762 | cum->stdarg = fntype |
3763 | && (TYPE_ARG_TYPES (fntype) != 0 | |
3764 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
3765 | != void_type_node)); | |
4697a36c MM |
3766 | |
3767 | if (incoming) | |
bd227acc | 3768 | cum->nargs_prototype = 1000; /* don't return a PARALLEL */ |
4697a36c MM |
3769 | |
3770 | else if (cum->prototype) | |
3771 | cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1 | |
3772 | + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode | |
c6e8c921 GK |
3773 | || rs6000_return_in_memory (TREE_TYPE (fntype), |
3774 | fntype))); | |
4697a36c MM |
3775 | |
3776 | else | |
3777 | cum->nargs_prototype = 0; | |
3778 | ||
a5c76ee6 ZW |
3779 | /* Check for a longcall attribute. */ |
3780 | if (fntype | |
3781 | && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) | |
3782 | && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
3783 | cum->call_cookie = CALL_LONG; |
3784 | ||
4697a36c MM |
3785 | if (TARGET_DEBUG_ARG) |
3786 | { | |
3787 | fprintf (stderr, "\ninit_cumulative_args:"); | |
3788 | if (fntype) | |
3789 | { | |
3790 | tree ret_type = TREE_TYPE (fntype); | |
3791 | fprintf (stderr, " ret code = %s,", | |
3792 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
3793 | } | |
3794 | ||
6a4cee5f MM |
3795 | if (cum->call_cookie & CALL_LONG) |
3796 | fprintf (stderr, " longcall,"); | |
3797 | ||
4697a36c MM |
3798 | fprintf (stderr, " proto = %d, nargs = %d\n", |
3799 | cum->prototype, cum->nargs_prototype); | |
3800 | } | |
3801 | } | |
3802 | \f | |
c229cba9 DE |
3803 | /* If defined, a C expression which determines whether, and in which |
3804 | direction, to pad out an argument with extra space. The value | |
3805 | should be of type `enum direction': either `upward' to pad above | |
3806 | the argument, `downward' to pad below, or `none' to inhibit | |
3807 | padding. | |
3808 | ||
3809 | For the AIX ABI structs are always stored left shifted in their | |
3810 | argument slot. */ | |
3811 | ||
9ebbca7d | 3812 | enum direction |
a2369ed3 | 3813 | function_arg_padding (enum machine_mode mode, tree type) |
c229cba9 | 3814 | { |
6e985040 AM |
3815 | #ifndef AGGREGATE_PADDING_FIXED |
3816 | #define AGGREGATE_PADDING_FIXED 0 | |
3817 | #endif | |
3818 | #ifndef AGGREGATES_PAD_UPWARD_ALWAYS | |
3819 | #define AGGREGATES_PAD_UPWARD_ALWAYS 0 | |
3820 | #endif | |
3821 | ||
3822 | if (!AGGREGATE_PADDING_FIXED) | |
3823 | { | |
3824 | /* GCC used to pass structures of the same size as integer types as | |
3825 | if they were in fact integers, ignoring FUNCTION_ARG_PADDING. | |
3826 | ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were | |
3827 | passed padded downward, except that -mstrict-align further | |
3828 | muddied the water in that multi-component structures of 2 and 4 | |
3829 | bytes in size were passed padded upward. | |
3830 | ||
3831 | The following arranges for best compatibility with previous | |
3832 | versions of gcc, but removes the -mstrict-align dependency. */ | |
3833 | if (BYTES_BIG_ENDIAN) | |
3834 | { | |
3835 | HOST_WIDE_INT size = 0; | |
3836 | ||
3837 | if (mode == BLKmode) | |
3838 | { | |
3839 | if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) | |
3840 | size = int_size_in_bytes (type); | |
3841 | } | |
3842 | else | |
3843 | size = GET_MODE_SIZE (mode); | |
3844 | ||
3845 | if (size == 1 || size == 2 || size == 4) | |
3846 | return downward; | |
3847 | } | |
3848 | return upward; | |
3849 | } | |
3850 | ||
3851 | if (AGGREGATES_PAD_UPWARD_ALWAYS) | |
3852 | { | |
3853 | if (type != 0 && AGGREGATE_TYPE_P (type)) | |
3854 | return upward; | |
3855 | } | |
c229cba9 | 3856 | |
d3704c46 KH |
3857 | /* Fall back to the default. */ |
3858 | return DEFAULT_FUNCTION_ARG_PADDING (mode, type); | |
c229cba9 DE |
3859 | } |
3860 | ||
b6c9286a MM |
3861 | /* If defined, a C expression that gives the alignment boundary, in bits, |
3862 | of an argument with the specified mode and type. If it is not defined, | |
3863 | PARM_BOUNDARY is used for all arguments. | |
3864 | ||
2310f99a | 3865 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
3866 | |
3867 | int | |
a2369ed3 | 3868 | function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED) |
b6c9286a | 3869 | { |
f607bc57 | 3870 | if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode)) |
e1f83b4d | 3871 | return 64; |
a3170dc6 AH |
3872 | else if (SPE_VECTOR_MODE (mode)) |
3873 | return 64; | |
0ac081f6 AH |
3874 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
3875 | return 128; | |
9ebbca7d | 3876 | else |
b6c9286a | 3877 | return PARM_BOUNDARY; |
b6c9286a MM |
3878 | } |
3879 | \f | |
4697a36c MM |
3880 | /* Update the data in CUM to advance over an argument |
3881 | of mode MODE and data type TYPE. | |
3882 | (TYPE is null for libcalls where that information may not be available.) */ | |
3883 | ||
3884 | void | |
a2369ed3 DJ |
3885 | function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
3886 | tree type, int named) | |
4697a36c MM |
3887 | { |
3888 | cum->nargs_prototype--; | |
3889 | ||
0ac081f6 AH |
3890 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
3891 | { | |
2858f73a | 3892 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
0ac081f6 | 3893 | cum->vregno++; |
2858f73a GK |
3894 | |
3895 | /* In variable-argument functions, vector arguments get GPRs allocated | |
3896 | even if they are going to be passed in a vector register. */ | |
3897 | if (cum->stdarg && DEFAULT_ABI != ABI_V4) | |
a594a19c GK |
3898 | { |
3899 | int align; | |
3900 | ||
2858f73a GK |
3901 | /* Vector parameters must be 16-byte aligned. This places |
3902 | them at 2 mod 4 in terms of words in 32-bit mode, since | |
3903 | the parameter save area starts at offset 24 from the | |
3904 | stack. In 64-bit mode, they just have to start on an | |
3905 | even word, since the parameter save area is 16-byte | |
3906 | aligned. Space for GPRs is reserved even if the argument | |
3907 | will be passed in memory. */ | |
3908 | if (TARGET_32BIT) | |
3909 | align = ((6 - (cum->words & 3)) & 3); | |
3910 | else | |
3911 | align = cum->words & 1; | |
a594a19c | 3912 | cum->words += align + RS6000_ARG_SIZE (mode, type); |
2858f73a | 3913 | |
a594a19c GK |
3914 | if (TARGET_DEBUG_ARG) |
3915 | { | |
3916 | fprintf (stderr, "function_adv: words = %2d, align=%d, ", | |
3917 | cum->words, align); | |
3918 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n", | |
2858f73a GK |
3919 | cum->nargs_prototype, cum->prototype, |
3920 | GET_MODE_NAME (mode)); | |
a594a19c GK |
3921 | } |
3922 | } | |
0ac081f6 | 3923 | } |
a4b0320c | 3924 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) |
a6c9bed4 AH |
3925 | && !cum->stdarg |
3926 | && cum->sysv_gregno <= GP_ARG_MAX_REG) | |
a4b0320c | 3927 | cum->sysv_gregno++; |
f607bc57 | 3928 | else if (DEFAULT_ABI == ABI_V4) |
4697a36c | 3929 | { |
a3170dc6 | 3930 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 | 3931 | && (mode == SFmode || mode == DFmode)) |
4697a36c | 3932 | { |
4cc833b7 RH |
3933 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
3934 | cum->fregno++; | |
3935 | else | |
3936 | { | |
3937 | if (mode == DFmode) | |
3938 | cum->words += cum->words & 1; | |
d34c5b80 | 3939 | cum->words += RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 3940 | } |
4697a36c | 3941 | } |
4cc833b7 RH |
3942 | else |
3943 | { | |
3944 | int n_words; | |
3945 | int gregno = cum->sysv_gregno; | |
3946 | ||
3947 | /* Aggregates and IEEE quad get passed by reference. */ | |
3948 | if ((type && AGGREGATE_TYPE_P (type)) | |
3949 | || mode == TFmode) | |
3950 | n_words = 1; | |
3951 | else | |
d34c5b80 | 3952 | n_words = RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 3953 | |
a4b0320c | 3954 | /* Long long and SPE vectors are put in odd registers. */ |
4cc833b7 RH |
3955 | if (n_words == 2 && (gregno & 1) == 0) |
3956 | gregno += 1; | |
3957 | ||
a4b0320c AH |
3958 | /* Long long and SPE vectors are not split between registers |
3959 | and stack. */ | |
4cc833b7 RH |
3960 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
3961 | { | |
3962 | /* Long long is aligned on the stack. */ | |
3963 | if (n_words == 2) | |
3964 | cum->words += cum->words & 1; | |
3965 | cum->words += n_words; | |
3966 | } | |
4697a36c | 3967 | |
4cc833b7 RH |
3968 | /* Note: continuing to accumulate gregno past when we've started |
3969 | spilling to the stack indicates the fact that we've started | |
3970 | spilling to the stack to expand_builtin_saveregs. */ | |
3971 | cum->sysv_gregno = gregno + n_words; | |
3972 | } | |
4697a36c | 3973 | |
4cc833b7 RH |
3974 | if (TARGET_DEBUG_ARG) |
3975 | { | |
3976 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
3977 | cum->words, cum->fregno); | |
3978 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
3979 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
3980 | fprintf (stderr, "mode = %4s, named = %d\n", | |
3981 | GET_MODE_NAME (mode), named); | |
3982 | } | |
4697a36c MM |
3983 | } |
3984 | else | |
4cc833b7 RH |
3985 | { |
3986 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
3987 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
a4f6c312 | 3988 | |
d34c5b80 | 3989 | cum->words += align + RS6000_ARG_SIZE (mode, type); |
4697a36c | 3990 | |
a3170dc6 AH |
3991 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
3992 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
fcce224d | 3993 | cum->fregno += (mode == TFmode ? 2 : 1); |
4cc833b7 RH |
3994 | |
3995 | if (TARGET_DEBUG_ARG) | |
3996 | { | |
3997 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
3998 | cum->words, cum->fregno); | |
3999 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
4000 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
4001 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
4002 | } | |
4003 | } | |
4697a36c | 4004 | } |
a6c9bed4 AH |
4005 | |
4006 | /* Determine where to put a SIMD argument on the SPE. */ | |
b78d48dd | 4007 | |
a6c9bed4 | 4008 | static rtx |
a2369ed3 DJ |
4009 | rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4010 | tree type) | |
a6c9bed4 AH |
4011 | { |
4012 | if (cum->stdarg) | |
4013 | { | |
4014 | int gregno = cum->sysv_gregno; | |
4015 | int n_words = RS6000_ARG_SIZE (mode, type); | |
4016 | ||
4017 | /* SPE vectors are put in odd registers. */ | |
4018 | if (n_words == 2 && (gregno & 1) == 0) | |
4019 | gregno += 1; | |
4020 | ||
4021 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
4022 | { | |
4023 | rtx r1, r2; | |
4024 | enum machine_mode m = SImode; | |
4025 | ||
4026 | r1 = gen_rtx_REG (m, gregno); | |
4027 | r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx); | |
4028 | r2 = gen_rtx_REG (m, gregno + 1); | |
4029 | r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4)); | |
4030 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); | |
4031 | } | |
4032 | else | |
b78d48dd | 4033 | return NULL_RTX; |
a6c9bed4 AH |
4034 | } |
4035 | else | |
4036 | { | |
4037 | if (cum->sysv_gregno <= GP_ARG_MAX_REG) | |
4038 | return gen_rtx_REG (mode, cum->sysv_gregno); | |
4039 | else | |
b78d48dd | 4040 | return NULL_RTX; |
a6c9bed4 AH |
4041 | } |
4042 | } | |
4043 | ||
b78d48dd FJ |
4044 | /* Determine where to place an argument in 64-bit mode with 32-bit ABI. */ |
4045 | ||
4046 | static rtx | |
4047 | rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, | |
4048 | tree type, int align_words) | |
4049 | { | |
4050 | if (mode == DFmode) | |
4051 | { | |
4052 | /* -mpowerpc64 with 32bit ABI splits up a DFmode argument | |
4053 | in vararg list into zero, one or two GPRs */ | |
4054 | if (align_words >= GP_ARG_NUM_REG) | |
4055 | return gen_rtx_PARALLEL (DFmode, | |
4056 | gen_rtvec (2, | |
4057 | gen_rtx_EXPR_LIST (VOIDmode, | |
4058 | NULL_RTX, const0_rtx), | |
4059 | gen_rtx_EXPR_LIST (VOIDmode, | |
4060 | gen_rtx_REG (mode, | |
4061 | cum->fregno), | |
4062 | const0_rtx))); | |
4063 | else if (align_words + RS6000_ARG_SIZE (mode, type) | |
4064 | > GP_ARG_NUM_REG) | |
4065 | /* If this is partially on the stack, then we only | |
4066 | include the portion actually in registers here. */ | |
4067 | return gen_rtx_PARALLEL (DFmode, | |
4068 | gen_rtvec (2, | |
4069 | gen_rtx_EXPR_LIST (VOIDmode, | |
4070 | gen_rtx_REG (SImode, | |
4071 | GP_ARG_MIN_REG | |
4072 | + align_words), | |
4073 | const0_rtx), | |
4074 | gen_rtx_EXPR_LIST (VOIDmode, | |
4075 | gen_rtx_REG (mode, | |
4076 | cum->fregno), | |
4077 | const0_rtx))); | |
4078 | ||
4079 | /* split a DFmode arg into two GPRs */ | |
4080 | return gen_rtx_PARALLEL (DFmode, | |
4081 | gen_rtvec (3, | |
4082 | gen_rtx_EXPR_LIST (VOIDmode, | |
4083 | gen_rtx_REG (SImode, | |
4084 | GP_ARG_MIN_REG | |
4085 | + align_words), | |
4086 | const0_rtx), | |
4087 | gen_rtx_EXPR_LIST (VOIDmode, | |
4088 | gen_rtx_REG (SImode, | |
4089 | GP_ARG_MIN_REG | |
4090 | + align_words + 1), | |
4091 | GEN_INT (4)), | |
4092 | gen_rtx_EXPR_LIST (VOIDmode, | |
4093 | gen_rtx_REG (mode, cum->fregno), | |
4094 | const0_rtx))); | |
4095 | } | |
4096 | /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one | |
4097 | or two GPRs */ | |
4098 | else if (mode == DImode) | |
4099 | { | |
4100 | if (align_words < GP_ARG_NUM_REG - 1) | |
4101 | return gen_rtx_PARALLEL (DImode, | |
4102 | gen_rtvec (2, | |
4103 | gen_rtx_EXPR_LIST (VOIDmode, | |
4104 | gen_rtx_REG (SImode, | |
4105 | GP_ARG_MIN_REG | |
4106 | + align_words), | |
4107 | const0_rtx), | |
4108 | gen_rtx_EXPR_LIST (VOIDmode, | |
4109 | gen_rtx_REG (SImode, | |
4110 | GP_ARG_MIN_REG | |
4111 | + align_words + 1), | |
4112 | GEN_INT (4)))); | |
4113 | else if (align_words == GP_ARG_NUM_REG - 1) | |
4114 | return gen_rtx_PARALLEL (DImode, | |
4115 | gen_rtvec (2, | |
4116 | gen_rtx_EXPR_LIST (VOIDmode, | |
4117 | NULL_RTX, const0_rtx), | |
4118 | gen_rtx_EXPR_LIST (VOIDmode, | |
4119 | gen_rtx_REG (SImode, | |
4120 | GP_ARG_MIN_REG | |
4121 | + align_words), | |
4122 | const0_rtx))); | |
4123 | } | |
4124 | else if (mode == BLKmode && align_words <= (GP_ARG_NUM_REG - 1)) | |
4125 | { | |
4126 | int k; | |
4127 | int size = int_size_in_bytes (type); | |
2f7b62ef | 4128 | int no_units = ((size - 1) / 4) + 1; |
b78d48dd FJ |
4129 | int max_no_words = GP_ARG_NUM_REG - align_words; |
4130 | int rtlvec_len = no_units < max_no_words ? no_units : max_no_words; | |
4131 | rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx)); | |
4132 | ||
4133 | memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx)); | |
4134 | ||
4135 | for (k=0; k < rtlvec_len; k++) | |
4136 | rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode, | |
4137 | gen_rtx_REG (SImode, | |
4138 | GP_ARG_MIN_REG | |
4139 | + align_words + k), | |
4140 | k == 0 ? const0_rtx : GEN_INT (k*4)); | |
4141 | ||
4142 | return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k, rtlvec)); | |
4143 | } | |
4144 | ||
4145 | return NULL_RTX; | |
4146 | } | |
4147 | ||
4697a36c MM |
4148 | /* Determine where to put an argument to a function. |
4149 | Value is zero to push the argument on the stack, | |
4150 | or a hard register in which to store the argument. | |
4151 | ||
4152 | MODE is the argument's machine mode. | |
4153 | TYPE is the data type of the argument (as a tree). | |
4154 | This is null for libcalls where that information may | |
4155 | not be available. | |
4156 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
4157 | the preceding args and about the function being called. | |
4158 | NAMED is nonzero if this argument is a named parameter | |
4159 | (otherwise it is an extra parameter matching an ellipsis). | |
4160 | ||
4161 | On RS/6000 the first eight words of non-FP are normally in registers | |
4162 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
4163 | Under V.4, the first 8 FP args are in registers. | |
4164 | ||
4165 | If this is floating-point and no prototype is specified, we use | |
4166 | both an FP and integer register (or possibly FP reg and stack). Library | |
b9599e46 | 4167 | functions (when CALL_LIBCALL is set) always have the proper types for args, |
4697a36c | 4168 | so we can pass the FP value just in one register. emit_library_function |
1c20ae99 | 4169 | doesn't support PARALLEL anyway. */ |
4697a36c MM |
4170 | |
4171 | struct rtx_def * | |
a2369ed3 DJ |
4172 | function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4173 | tree type, int named) | |
4697a36c | 4174 | { |
4cc833b7 | 4175 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 4176 | |
a4f6c312 SS |
4177 | /* Return a marker to indicate whether CR1 needs to set or clear the |
4178 | bit that V.4 uses to say fp args were passed in registers. | |
4179 | Assume that we don't need the marker for software floating point, | |
4180 | or compiler generated library calls. */ | |
4697a36c MM |
4181 | if (mode == VOIDmode) |
4182 | { | |
f607bc57 | 4183 | if (abi == ABI_V4 |
7509c759 | 4184 | && cum->nargs_prototype < 0 |
b9599e46 FS |
4185 | && (cum->call_cookie & CALL_LIBCALL) == 0 |
4186 | && (cum->prototype || TARGET_NO_PROTOTYPE)) | |
7509c759 | 4187 | { |
a3170dc6 AH |
4188 | /* For the SPE, we need to crxor CR6 always. */ |
4189 | if (TARGET_SPE_ABI) | |
4190 | return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS); | |
4191 | else if (TARGET_HARD_FLOAT && TARGET_FPRS) | |
4192 | return GEN_INT (cum->call_cookie | |
4193 | | ((cum->fregno == FP_ARG_MIN_REG) | |
4194 | ? CALL_V4_SET_FP_ARGS | |
4195 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 4196 | } |
4697a36c | 4197 | |
7509c759 | 4198 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
4199 | } |
4200 | ||
2858f73a GK |
4201 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
4202 | return gen_rtx_REG (mode, cum->vregno); | |
4203 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
0ac081f6 | 4204 | { |
2858f73a | 4205 | if (named || abi == ABI_V4) |
a594a19c | 4206 | return NULL_RTX; |
0ac081f6 | 4207 | else |
a594a19c GK |
4208 | { |
4209 | /* Vector parameters to varargs functions under AIX or Darwin | |
4210 | get passed in memory and possibly also in GPRs. */ | |
4211 | int align, align_words; | |
2858f73a | 4212 | enum machine_mode part_mode = mode; |
a594a19c GK |
4213 | |
4214 | /* Vector parameters must be 16-byte aligned. This places them at | |
2858f73a GK |
4215 | 2 mod 4 in terms of words in 32-bit mode, since the parameter |
4216 | save area starts at offset 24 from the stack. In 64-bit mode, | |
4217 | they just have to start on an even word, since the parameter | |
4218 | save area is 16-byte aligned. */ | |
4219 | if (TARGET_32BIT) | |
4220 | align = ((6 - (cum->words & 3)) & 3); | |
4221 | else | |
4222 | align = cum->words & 1; | |
a594a19c GK |
4223 | align_words = cum->words + align; |
4224 | ||
4225 | /* Out of registers? Memory, then. */ | |
4226 | if (align_words >= GP_ARG_NUM_REG) | |
4227 | return NULL_RTX; | |
4228 | ||
2858f73a GK |
4229 | /* The vector value goes in GPRs. Only the part of the |
4230 | value in GPRs is reported here. */ | |
4231 | if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS) | |
4232 | > GP_ARG_NUM_REG) | |
4233 | /* Fortunately, there are only two possibilites, the value | |
4234 | is either wholly in GPRs or half in GPRs and half not. */ | |
4235 | part_mode = DImode; | |
4236 | ||
4237 | return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words); | |
a594a19c | 4238 | } |
0ac081f6 | 4239 | } |
a6c9bed4 AH |
4240 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)) |
4241 | return rs6000_spe_function_arg (cum, mode, type); | |
f607bc57 | 4242 | else if (abi == ABI_V4) |
4697a36c | 4243 | { |
a3170dc6 | 4244 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 RH |
4245 | && (mode == SFmode || mode == DFmode)) |
4246 | { | |
4247 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
4248 | return gen_rtx_REG (mode, cum->fregno); | |
4249 | else | |
b78d48dd | 4250 | return NULL_RTX; |
4cc833b7 RH |
4251 | } |
4252 | else | |
4253 | { | |
4254 | int n_words; | |
4255 | int gregno = cum->sysv_gregno; | |
4256 | ||
4257 | /* Aggregates and IEEE quad get passed by reference. */ | |
4258 | if ((type && AGGREGATE_TYPE_P (type)) | |
4259 | || mode == TFmode) | |
4260 | n_words = 1; | |
4261 | else | |
d34c5b80 | 4262 | n_words = RS6000_ARG_SIZE (mode, type); |
4cc833b7 | 4263 | |
a4b0320c | 4264 | /* Long long and SPE vectors are put in odd registers. */ |
4cc833b7 RH |
4265 | if (n_words == 2 && (gregno & 1) == 0) |
4266 | gregno += 1; | |
4267 | ||
a6c9bed4 | 4268 | /* Long long do not split between registers and stack. */ |
4cc833b7 | 4269 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) |
a6c9bed4 | 4270 | return gen_rtx_REG (mode, gregno); |
4cc833b7 | 4271 | else |
b78d48dd | 4272 | return NULL_RTX; |
4cc833b7 | 4273 | } |
4697a36c | 4274 | } |
4cc833b7 RH |
4275 | else |
4276 | { | |
4277 | int align = (TARGET_32BIT && (cum->words & 1) != 0 | |
4278 | && function_arg_boundary (mode, type) == 64) ? 1 : 0; | |
4279 | int align_words = cum->words + align; | |
4697a36c | 4280 | |
4cc833b7 RH |
4281 | if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) |
4282 | return NULL_RTX; | |
4283 | ||
b78d48dd FJ |
4284 | if (TARGET_32BIT && TARGET_POWERPC64 |
4285 | && (mode == DFmode || mode == DImode || mode == BLKmode)) | |
4286 | return rs6000_mixed_function_arg (cum, mode, type, align_words); | |
4287 | ||
2858f73a | 4288 | if (USE_FP_FOR_ARG_P (cum, mode, type)) |
4cc833b7 RH |
4289 | { |
4290 | if (! type | |
4291 | || ((cum->nargs_prototype > 0) | |
4292 | /* IBM AIX extended its linkage convention definition always | |
4293 | to require FP args after register save area hole on the | |
4294 | stack. */ | |
4295 | && (DEFAULT_ABI != ABI_AIX | |
4296 | || ! TARGET_XL_CALL | |
4297 | || (align_words < GP_ARG_NUM_REG)))) | |
4298 | return gen_rtx_REG (mode, cum->fregno); | |
4299 | ||
4300 | return gen_rtx_PARALLEL (mode, | |
4301 | gen_rtvec (2, | |
39403d82 | 4302 | gen_rtx_EXPR_LIST (VOIDmode, |
1c20ae99 JW |
4303 | ((align_words >= GP_ARG_NUM_REG) |
4304 | ? NULL_RTX | |
4305 | : (align_words | |
d34c5b80 | 4306 | + RS6000_ARG_SIZE (mode, type) |
1c20ae99 JW |
4307 | > GP_ARG_NUM_REG |
4308 | /* If this is partially on the stack, then | |
4309 | we only include the portion actually | |
4310 | in registers here. */ | |
39403d82 | 4311 | ? gen_rtx_REG (SImode, |
1c20ae99 | 4312 | GP_ARG_MIN_REG + align_words) |
39403d82 | 4313 | : gen_rtx_REG (mode, |
1c20ae99 JW |
4314 | GP_ARG_MIN_REG + align_words))), |
4315 | const0_rtx), | |
39403d82 DE |
4316 | gen_rtx_EXPR_LIST (VOIDmode, |
4317 | gen_rtx_REG (mode, cum->fregno), | |
1c20ae99 | 4318 | const0_rtx))); |
4cc833b7 RH |
4319 | } |
4320 | else if (align_words < GP_ARG_NUM_REG) | |
4321 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4322 | else | |
4323 | return NULL_RTX; | |
4697a36c | 4324 | } |
4697a36c MM |
4325 | } |
4326 | \f | |
4327 | /* For an arg passed partly in registers and partly in memory, | |
4328 | this is the number of registers used. | |
4329 | For args passed entirely in registers or entirely in memory, zero. */ | |
4330 | ||
4331 | int | |
a2369ed3 | 4332 | function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
2858f73a | 4333 | tree type, int named) |
4697a36c | 4334 | { |
f607bc57 | 4335 | if (DEFAULT_ABI == ABI_V4) |
4697a36c | 4336 | return 0; |
4697a36c | 4337 | |
2858f73a GK |
4338 | if (USE_FP_FOR_ARG_P (cum, mode, type) |
4339 | || USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) | |
4697a36c MM |
4340 | { |
4341 | if (cum->nargs_prototype >= 0) | |
4342 | return 0; | |
4343 | } | |
4344 | ||
4345 | if (cum->words < GP_ARG_NUM_REG | |
d34c5b80 | 4346 | && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type))) |
4697a36c MM |
4347 | { |
4348 | int ret = GP_ARG_NUM_REG - cum->words; | |
4349 | if (ret && TARGET_DEBUG_ARG) | |
4350 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
4351 | ||
4352 | return ret; | |
4353 | } | |
4354 | ||
4355 | return 0; | |
4356 | } | |
4357 | \f | |
4358 | /* A C expression that indicates when an argument must be passed by | |
4359 | reference. If nonzero for an argument, a copy of that argument is | |
4360 | made in memory and a pointer to the argument is passed instead of | |
4361 | the argument itself. The pointer is passed in whatever way is | |
4362 | appropriate for passing a pointer to that type. | |
4363 | ||
c8c99a68 DE |
4364 | Under V.4, structures and unions are passed by reference. |
4365 | ||
4366 | As an extension to all ABIs, variable sized types are passed by | |
4367 | reference. */ | |
4697a36c MM |
4368 | |
4369 | int | |
a2369ed3 DJ |
4370 | function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED, |
4371 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
d779d0dc | 4372 | tree type, int named ATTRIBUTE_UNUSED) |
4697a36c | 4373 | { |
f607bc57 | 4374 | if (DEFAULT_ABI == ABI_V4 |
4cc833b7 RH |
4375 | && ((type && AGGREGATE_TYPE_P (type)) |
4376 | || mode == TFmode)) | |
4697a36c MM |
4377 | { |
4378 | if (TARGET_DEBUG_ARG) | |
4379 | fprintf (stderr, "function_arg_pass_by_reference: aggregate\n"); | |
4380 | ||
4381 | return 1; | |
4382 | } | |
fff2cb99 | 4383 | return type && int_size_in_bytes (type) < 0; |
4697a36c | 4384 | } |
5985c7a6 FJ |
4385 | |
4386 | static void | |
4387 | rs6000_move_block_from_reg(int regno, rtx x, int nregs) | |
4388 | { | |
4389 | int i; | |
4390 | enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode; | |
4391 | ||
4392 | if (nregs == 0) | |
4393 | return; | |
4394 | ||
4395 | for (i = 0; i < nregs; i++) | |
4396 | { | |
4397 | rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode)); | |
4398 | if (reload_completed) | |
4399 | { | |
4400 | if (! strict_memory_address_p (reg_mode, XEXP (tem, 0))) | |
4401 | tem = NULL_RTX; | |
4402 | else | |
4403 | tem = simplify_gen_subreg (reg_mode, x, BLKmode, | |
4404 | i * GET_MODE_SIZE(reg_mode)); | |
4405 | } | |
4406 | else | |
4407 | tem = replace_equiv_address (tem, XEXP (tem, 0)); | |
4408 | ||
4409 | if (tem == NULL_RTX) | |
4410 | abort (); | |
4411 | ||
4412 | emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i)); | |
4413 | } | |
4414 | } | |
4415 | ||
4697a36c MM |
4416 | \f |
4417 | /* Perform any needed actions needed for a function that is receiving a | |
4418 | variable number of arguments. | |
4419 | ||
4420 | CUM is as above. | |
4421 | ||
4422 | MODE and TYPE are the mode and type of the current parameter. | |
4423 | ||
4424 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
4425 | that must be pushed by the prolog to pretend that our caller pushed | |
4426 | it. | |
4427 | ||
4428 | Normally, this macro will push all remaining incoming registers on the | |
4429 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
4430 | ||
c6e8c921 | 4431 | static void |
a2369ed3 DJ |
4432 | setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4433 | tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl) | |
4697a36c | 4434 | { |
4cc833b7 RH |
4435 | CUMULATIVE_ARGS next_cum; |
4436 | int reg_size = TARGET_32BIT ? 4 : 8; | |
ca5adc63 | 4437 | rtx save_area = NULL_RTX, mem; |
dfafc897 | 4438 | int first_reg_offset, set; |
4697a36c | 4439 | |
f31bf321 | 4440 | /* Skip the last named argument. */ |
d34c5b80 | 4441 | next_cum = *cum; |
f31bf321 | 4442 | function_arg_advance (&next_cum, mode, type, 1); |
4cc833b7 | 4443 | |
f607bc57 | 4444 | if (DEFAULT_ABI == ABI_V4) |
d34c5b80 | 4445 | { |
4cc833b7 | 4446 | /* Indicate to allocate space on the stack for varargs save area. */ |
00dba523 | 4447 | cfun->machine->sysv_varargs_p = 1; |
60e2d0ca | 4448 | if (! no_rtl) |
2c4974b7 | 4449 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 4450 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
4451 | |
4452 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 4453 | } |
60e2d0ca | 4454 | else |
4697a36c | 4455 | { |
d34c5b80 | 4456 | first_reg_offset = next_cum.words; |
4cc833b7 | 4457 | save_area = virtual_incoming_args_rtx; |
00dba523 | 4458 | cfun->machine->sysv_varargs_p = 0; |
4697a36c MM |
4459 | |
4460 | if (MUST_PASS_IN_STACK (mode, type)) | |
d34c5b80 | 4461 | first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type); |
4cc833b7 | 4462 | } |
4697a36c | 4463 | |
dfafc897 | 4464 | set = get_varargs_alias_set (); |
c81fc13e | 4465 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 4466 | { |
dfafc897 FS |
4467 | mem = gen_rtx_MEM (BLKmode, |
4468 | plus_constant (save_area, | |
4469 | first_reg_offset * reg_size)), | |
ba4828e0 | 4470 | set_mem_alias_set (mem, set); |
8ac61af7 | 4471 | set_mem_align (mem, BITS_PER_WORD); |
dfafc897 | 4472 | |
5985c7a6 FJ |
4473 | rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem, |
4474 | GP_ARG_NUM_REG - first_reg_offset); | |
4697a36c MM |
4475 | } |
4476 | ||
4697a36c | 4477 | /* Save FP registers if needed. */ |
f607bc57 | 4478 | if (DEFAULT_ABI == ABI_V4 |
a3170dc6 AH |
4479 | && TARGET_HARD_FLOAT && TARGET_FPRS |
4480 | && ! no_rtl | |
4cc833b7 | 4481 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 4482 | { |
4cc833b7 | 4483 | int fregno = next_cum.fregno; |
9ebbca7d | 4484 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
4485 | rtx lab = gen_label_rtx (); |
4486 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 4487 | |
4cc833b7 | 4488 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 4489 | pc_rtx, |
39403d82 | 4490 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
4491 | gen_rtx_NE (VOIDmode, cr1, |
4492 | const0_rtx), | |
39403d82 | 4493 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
4494 | pc_rtx))); |
4495 | ||
4cc833b7 RH |
4496 | while (fregno <= FP_ARG_V4_MAX_REG) |
4497 | { | |
dfafc897 | 4498 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
ba4828e0 | 4499 | set_mem_alias_set (mem, set); |
dfafc897 | 4500 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); |
4cc833b7 RH |
4501 | fregno++; |
4502 | off += 8; | |
4697a36c | 4503 | } |
4cc833b7 RH |
4504 | |
4505 | emit_label (lab); | |
4697a36c | 4506 | } |
4697a36c | 4507 | } |
4697a36c | 4508 | |
dfafc897 | 4509 | /* Create the va_list data type. */ |
2c4974b7 | 4510 | |
c35d187f RH |
4511 | static tree |
4512 | rs6000_build_builtin_va_list (void) | |
dfafc897 | 4513 | { |
64c2816f | 4514 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl; |
4697a36c | 4515 | |
9ebbca7d GK |
4516 | /* For AIX, prefer 'char *' because that's what the system |
4517 | header files like. */ | |
f607bc57 | 4518 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d | 4519 | return build_pointer_type (char_type_node); |
dfafc897 | 4520 | |
f1e639b1 | 4521 | record = (*lang_hooks.types.make_type) (RECORD_TYPE); |
bab45a51 | 4522 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 4523 | |
9ebbca7d GK |
4524 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
4525 | unsigned_char_type_node); | |
4526 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), | |
4527 | unsigned_char_type_node); | |
64c2816f DT |
4528 | /* Give the two bytes of padding a name, so that -Wpadded won't warn on |
4529 | every user file. */ | |
4530 | f_res = build_decl (FIELD_DECL, get_identifier ("reserved"), | |
4531 | short_unsigned_type_node); | |
dfafc897 FS |
4532 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
4533 | ptr_type_node); | |
4534 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
4535 | ptr_type_node); | |
4536 | ||
4537 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
4538 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
64c2816f | 4539 | DECL_FIELD_CONTEXT (f_res) = record; |
dfafc897 FS |
4540 | DECL_FIELD_CONTEXT (f_ovf) = record; |
4541 | DECL_FIELD_CONTEXT (f_sav) = record; | |
4542 | ||
bab45a51 FS |
4543 | TREE_CHAIN (record) = type_decl; |
4544 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
4545 | TYPE_FIELDS (record) = f_gpr; |
4546 | TREE_CHAIN (f_gpr) = f_fpr; | |
64c2816f DT |
4547 | TREE_CHAIN (f_fpr) = f_res; |
4548 | TREE_CHAIN (f_res) = f_ovf; | |
dfafc897 FS |
4549 | TREE_CHAIN (f_ovf) = f_sav; |
4550 | ||
4551 | layout_type (record); | |
4552 | ||
4553 | /* The correct type is an array type of one element. */ | |
4554 | return build_array_type (record, build_index_type (size_zero_node)); | |
4555 | } | |
4556 | ||
4557 | /* Implement va_start. */ | |
4558 | ||
4559 | void | |
a2369ed3 | 4560 | rs6000_va_start (tree valist, rtx nextarg) |
4697a36c | 4561 | { |
dfafc897 | 4562 | HOST_WIDE_INT words, n_gpr, n_fpr; |
c566f9bd | 4563 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
dfafc897 | 4564 | tree gpr, fpr, ovf, sav, t; |
2c4974b7 | 4565 | |
dfafc897 | 4566 | /* Only SVR4 needs something special. */ |
f607bc57 | 4567 | if (DEFAULT_ABI != ABI_V4) |
dfafc897 | 4568 | { |
e5faf155 | 4569 | std_expand_builtin_va_start (valist, nextarg); |
dfafc897 FS |
4570 | return; |
4571 | } | |
4572 | ||
973a648b | 4573 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 | 4574 | f_fpr = TREE_CHAIN (f_gpr); |
c566f9bd DT |
4575 | f_res = TREE_CHAIN (f_fpr); |
4576 | f_ovf = TREE_CHAIN (f_res); | |
dfafc897 FS |
4577 | f_sav = TREE_CHAIN (f_ovf); |
4578 | ||
8ebecc3b | 4579 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
4580 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
4581 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
4582 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
4583 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
4584 | ||
4585 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 4586 | words = current_function_args_info.words; |
dfafc897 FS |
4587 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
4588 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
4589 | ||
4590 | if (TARGET_DEBUG_ARG) | |
4a0a75dd KG |
4591 | fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = " |
4592 | HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n", | |
4593 | words, n_gpr, n_fpr); | |
dfafc897 FS |
4594 | |
4595 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
4596 | TREE_SIDE_EFFECTS (t) = 1; | |
4597 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4598 | ||
4599 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
4600 | TREE_SIDE_EFFECTS (t) = 1; | |
4601 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4602 | ||
4603 | /* Find the overflow area. */ | |
4604 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
4605 | if (words != 0) | |
4606 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
4607 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
4608 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
4609 | TREE_SIDE_EFFECTS (t) = 1; | |
4610 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4611 | ||
4612 | /* Find the register save area. */ | |
4613 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
4614 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
4615 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
4616 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
4617 | TREE_SIDE_EFFECTS (t) = 1; | |
4618 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4619 | } | |
4620 | ||
4621 | /* Implement va_arg. */ | |
4622 | ||
4623 | rtx | |
a2369ed3 | 4624 | rs6000_va_arg (tree valist, tree type) |
dfafc897 | 4625 | { |
c566f9bd | 4626 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
dfafc897 FS |
4627 | tree gpr, fpr, ovf, sav, reg, t, u; |
4628 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
4629 | rtx lab_false, lab_over, addr_rtx, r; | |
4630 | ||
f607bc57 | 4631 | if (DEFAULT_ABI != ABI_V4) |
c8c99a68 DE |
4632 | { |
4633 | /* Variable sized types are passed by reference. */ | |
fff2cb99 | 4634 | if (int_size_in_bytes (type) < 0) |
c8c99a68 DE |
4635 | { |
4636 | u = build_pointer_type (type); | |
4637 | ||
4638 | /* Args grow upward. */ | |
4639 | t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist, | |
4640 | build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0)); | |
4641 | TREE_SIDE_EFFECTS (t) = 1; | |
4642 | ||
4643 | t = build1 (NOP_EXPR, build_pointer_type (u), t); | |
4644 | TREE_SIDE_EFFECTS (t) = 1; | |
4645 | ||
4646 | t = build1 (INDIRECT_REF, u, t); | |
4647 | TREE_SIDE_EFFECTS (t) = 1; | |
4648 | ||
4649 | return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL); | |
4650 | } | |
4651 | else | |
a594a19c GK |
4652 | { |
4653 | /* Altivec arguments must be aligned to a 128-bit boundary. */ | |
4aa4bf39 | 4654 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))) |
a594a19c GK |
4655 | { |
4656 | tree vtype = TREE_TYPE (valist); | |
4657 | tree new_valist, modify; | |
4658 | ||
4659 | /* Round address up to multiple of 16. Computes | |
4660 | (addr+15)&~0xf. */ | |
4661 | new_valist = fold (build (BIT_AND_EXPR, vtype, | |
4662 | fold (build (PLUS_EXPR, vtype, valist, | |
4663 | build_int_2 (15, 0))), | |
4664 | build_int_2 (~15, -1))); | |
4665 | ||
4666 | /* Update valist. */ | |
4667 | modify = build (MODIFY_EXPR, TREE_TYPE (valist), valist, | |
4668 | new_valist); | |
4669 | TREE_SIDE_EFFECTS (modify) = 1; | |
4670 | expand_expr (modify, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4671 | } | |
4672 | ||
4673 | return std_expand_builtin_va_arg (valist, type); | |
4674 | } | |
c8c99a68 | 4675 | } |
dfafc897 | 4676 | |
973a648b | 4677 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 | 4678 | f_fpr = TREE_CHAIN (f_gpr); |
c566f9bd DT |
4679 | f_res = TREE_CHAIN (f_fpr); |
4680 | f_ovf = TREE_CHAIN (f_res); | |
dfafc897 FS |
4681 | f_sav = TREE_CHAIN (f_ovf); |
4682 | ||
8ebecc3b | 4683 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
4684 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
4685 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
4686 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
4687 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
4688 | ||
4689 | size = int_size_in_bytes (type); | |
4690 | rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
4cc833b7 | 4691 | |
dfafc897 | 4692 | if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode) |
4cc833b7 | 4693 | { |
dfafc897 FS |
4694 | /* Aggregates and long doubles are passed by reference. */ |
4695 | indirect_p = 1; | |
4696 | reg = gpr; | |
4697 | n_reg = 1; | |
4698 | sav_ofs = 0; | |
4699 | sav_scale = 4; | |
d3294cd9 FS |
4700 | size = UNITS_PER_WORD; |
4701 | rsize = 1; | |
dfafc897 | 4702 | } |
a3170dc6 | 4703 | else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS) |
dfafc897 FS |
4704 | { |
4705 | /* FP args go in FP registers, if present. */ | |
4706 | indirect_p = 0; | |
4707 | reg = fpr; | |
4708 | n_reg = 1; | |
4709 | sav_ofs = 8*4; | |
4710 | sav_scale = 8; | |
4cc833b7 | 4711 | } |
dfafc897 FS |
4712 | else |
4713 | { | |
4714 | /* Otherwise into GP registers. */ | |
4715 | indirect_p = 0; | |
4716 | reg = gpr; | |
4717 | n_reg = rsize; | |
4718 | sav_ofs = 0; | |
4719 | sav_scale = 4; | |
4720 | } | |
4721 | ||
a4f6c312 | 4722 | /* Pull the value out of the saved registers ... */ |
dfafc897 FS |
4723 | |
4724 | lab_false = gen_label_rtx (); | |
4725 | lab_over = gen_label_rtx (); | |
4726 | addr_rtx = gen_reg_rtx (Pmode); | |
4727 | ||
16861f33 AH |
4728 | /* AltiVec vectors never go in registers. */ |
4729 | if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE) | |
2c4974b7 | 4730 | { |
41daaf0e AH |
4731 | TREE_THIS_VOLATILE (reg) = 1; |
4732 | emit_cmp_and_jump_insns | |
4733 | (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL), | |
4734 | GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1, | |
4735 | lab_false); | |
dfafc897 | 4736 | |
41daaf0e AH |
4737 | /* Long long is aligned in the registers. */ |
4738 | if (n_reg > 1) | |
4739 | { | |
4740 | u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg, | |
4741 | build_int_2 (n_reg - 1, 0)); | |
4742 | u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u); | |
4743 | u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u); | |
4744 | TREE_SIDE_EFFECTS (u) = 1; | |
4745 | expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4746 | } | |
2c4974b7 | 4747 | |
41daaf0e AH |
4748 | if (sav_ofs) |
4749 | t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
4750 | else | |
4751 | t = sav; | |
2c4974b7 | 4752 | |
41daaf0e AH |
4753 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, |
4754 | build_int_2 (n_reg, 0)); | |
4755 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 4756 | |
41daaf0e AH |
4757 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
4758 | TREE_SIDE_EFFECTS (u) = 1; | |
dfafc897 | 4759 | |
41daaf0e AH |
4760 | u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); |
4761 | TREE_SIDE_EFFECTS (u) = 1; | |
dfafc897 | 4762 | |
41daaf0e AH |
4763 | t = build (PLUS_EXPR, ptr_type_node, t, u); |
4764 | TREE_SIDE_EFFECTS (t) = 1; | |
4765 | ||
4766 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
4767 | if (r != addr_rtx) | |
4768 | emit_move_insn (addr_rtx, r); | |
4769 | ||
4770 | emit_jump_insn (gen_jump (lab_over)); | |
4771 | emit_barrier (); | |
4772 | } | |
dfafc897 | 4773 | |
dfafc897 FS |
4774 | emit_label (lab_false); |
4775 | ||
a4f6c312 | 4776 | /* ... otherwise out of the overflow area. */ |
dfafc897 | 4777 | |
41daaf0e AH |
4778 | /* Make sure we don't find reg 7 for the next int arg. |
4779 | ||
4780 | All AltiVec vectors go in the overflow area. So in the AltiVec | |
4781 | case we need to get the vectors from the overflow area, but | |
4782 | remember where the GPRs and FPRs are. */ | |
16861f33 AH |
4783 | if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE |
4784 | || !TARGET_ALTIVEC)) | |
dfafc897 FS |
4785 | { |
4786 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
4787 | TREE_SIDE_EFFECTS (t) = 1; | |
4788 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4789 | } | |
4790 | ||
4791 | /* Care for on-stack alignment if needed. */ | |
4792 | if (rsize <= 1) | |
4793 | t = ovf; | |
4794 | else | |
4795 | { | |
41daaf0e AH |
4796 | int align; |
4797 | ||
16861f33 AH |
4798 | /* AltiVec vectors are 16 byte aligned. */ |
4799 | if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE) | |
41daaf0e AH |
4800 | align = 15; |
4801 | else | |
4802 | align = 7; | |
4803 | ||
4804 | t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0)); | |
4805 | t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1)); | |
dfafc897 FS |
4806 | } |
4807 | t = save_expr (t); | |
4808 | ||
4809 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
4810 | if (r != addr_rtx) | |
4811 | emit_move_insn (addr_rtx, r); | |
4812 | ||
4813 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
4814 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
4815 | TREE_SIDE_EFFECTS (t) = 1; | |
4816 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
4817 | ||
4818 | emit_label (lab_over); | |
4819 | ||
4820 | if (indirect_p) | |
4821 | { | |
4822 | r = gen_rtx_MEM (Pmode, addr_rtx); | |
ba4828e0 | 4823 | set_mem_alias_set (r, get_varargs_alias_set ()); |
dfafc897 FS |
4824 | emit_move_insn (addr_rtx, r); |
4825 | } | |
4826 | ||
4827 | return addr_rtx; | |
4697a36c | 4828 | } |
0ac081f6 AH |
4829 | |
4830 | /* Builtins. */ | |
4831 | ||
6a2dd09a RS |
4832 | #define def_builtin(MASK, NAME, TYPE, CODE) \ |
4833 | do { \ | |
4834 | if ((MASK) & target_flags) \ | |
4835 | builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \ | |
4836 | NULL, NULL_TREE); \ | |
0ac081f6 AH |
4837 | } while (0) |
4838 | ||
24408032 AH |
4839 | /* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */ |
4840 | ||
2212663f | 4841 | static const struct builtin_description bdesc_3arg[] = |
24408032 AH |
4842 | { |
4843 | { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP }, | |
4844 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS }, | |
4845 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS }, | |
4846 | { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM}, | |
4847 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM }, | |
4848 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM }, | |
4849 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM }, | |
4850 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM }, | |
4851 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS }, | |
4852 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS }, | |
4853 | { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP }, | |
4854 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF }, | |
4855 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI }, | |
4856 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI }, | |
4857 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI }, | |
4858 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF }, | |
4859 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI }, | |
4860 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI }, | |
4861 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI }, | |
4862 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI }, | |
4863 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI }, | |
4864 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI }, | |
4865 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF }, | |
4866 | }; | |
2212663f | 4867 | |
95385cbb AH |
4868 | /* DST operations: void foo (void *, const int, const char). */ |
4869 | ||
4870 | static const struct builtin_description bdesc_dst[] = | |
4871 | { | |
4872 | { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST }, | |
4873 | { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT }, | |
4874 | { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST }, | |
4875 | { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT } | |
4876 | }; | |
4877 | ||
2212663f | 4878 | /* Simple binary operations: VECc = foo (VECa, VECb). */ |
24408032 | 4879 | |
a3170dc6 | 4880 | static struct builtin_description bdesc_2arg[] = |
0ac081f6 | 4881 | { |
f18c054f DB |
4882 | { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM }, |
4883 | { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM }, | |
4884 | { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM }, | |
4885 | { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP }, | |
0ac081f6 AH |
4886 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW }, |
4887 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS }, | |
4888 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS }, | |
4889 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS }, | |
4890 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS }, | |
4891 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS }, | |
4892 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS }, | |
f18c054f | 4893 | { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND }, |
0ac081f6 AH |
4894 | { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC }, |
4895 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB }, | |
4896 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB }, | |
4897 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH }, | |
4898 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH }, | |
4899 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW }, | |
4900 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW }, | |
617e0e1d DB |
4901 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX }, |
4902 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX }, | |
0ac081f6 AH |
4903 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP }, |
4904 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB }, | |
4905 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH }, | |
4906 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW }, | |
4907 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP }, | |
4908 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP }, | |
4909 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB }, | |
4910 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB }, | |
4911 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH }, | |
4912 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH }, | |
4913 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW }, | |
4914 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW }, | |
4915 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP }, | |
617e0e1d DB |
4916 | { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS }, |
4917 | { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS }, | |
f18c054f DB |
4918 | { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB }, |
4919 | { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB }, | |
df966bff AH |
4920 | { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH }, |
4921 | { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH }, | |
4922 | { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW }, | |
4923 | { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW }, | |
4924 | { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP }, | |
0ac081f6 AH |
4925 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB }, |
4926 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH }, | |
4927 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW }, | |
4928 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB }, | |
4929 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH }, | |
4930 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW }, | |
f18c054f DB |
4931 | { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB }, |
4932 | { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB }, | |
4933 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH }, | |
4934 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH }, | |
4935 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW }, | |
4936 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW }, | |
4937 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP }, | |
0ac081f6 AH |
4938 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB }, |
4939 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB }, | |
4940 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH }, | |
4941 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH }, | |
4942 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB }, | |
4943 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB }, | |
4944 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH }, | |
4945 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH }, | |
4946 | { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR }, | |
f18c054f | 4947 | { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR }, |
0ac081f6 AH |
4948 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM }, |
4949 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM }, | |
4950 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX }, | |
4951 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS }, | |
4952 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS }, | |
4953 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS }, | |
4954 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS }, | |
4955 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS }, | |
4956 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS }, | |
4957 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS }, | |
4958 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS }, | |
4959 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB }, | |
4960 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH }, | |
4961 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW }, | |
4962 | { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB }, | |
4963 | { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH }, | |
4964 | { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW }, | |
4965 | { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL }, | |
4966 | { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO }, | |
2212663f DB |
4967 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB }, |
4968 | { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH }, | |
4969 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW }, | |
0ac081f6 | 4970 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB }, |
f18c054f DB |
4971 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH }, |
4972 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW }, | |
0ac081f6 AH |
4973 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB }, |
4974 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH }, | |
4975 | { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW }, | |
4976 | { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR }, | |
4977 | { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO }, | |
f18c054f DB |
4978 | { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM }, |
4979 | { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM }, | |
4980 | { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM }, | |
4981 | { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP }, | |
0ac081f6 AH |
4982 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW }, |
4983 | { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS }, | |
4984 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS }, | |
4985 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS }, | |
4986 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS }, | |
4987 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS }, | |
4988 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS }, | |
4989 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS }, | |
4990 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS }, | |
4991 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS }, | |
4992 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS }, | |
4993 | { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS }, | |
f18c054f | 4994 | { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR }, |
a3170dc6 AH |
4995 | |
4996 | /* Place holder, leave as first spe builtin. */ | |
4997 | { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW }, | |
4998 | { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND }, | |
4999 | { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC }, | |
5000 | { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS }, | |
5001 | { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU }, | |
5002 | { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV }, | |
5003 | { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD }, | |
5004 | { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV }, | |
5005 | { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL }, | |
5006 | { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB }, | |
5007 | { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI }, | |
5008 | { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO }, | |
5009 | { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO }, | |
5010 | { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI }, | |
5011 | { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA }, | |
5012 | { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN }, | |
5013 | { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA }, | |
5014 | { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN }, | |
5015 | { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA }, | |
5016 | { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN }, | |
5017 | { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF }, | |
5018 | { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA }, | |
5019 | { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW }, | |
5020 | { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW }, | |
5021 | { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI }, | |
5022 | { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA }, | |
5023 | { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW }, | |
5024 | { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW }, | |
5025 | { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF }, | |
5026 | { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA }, | |
5027 | { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW }, | |
5028 | { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW }, | |
5029 | { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW }, | |
5030 | { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW }, | |
5031 | { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI }, | |
5032 | { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA }, | |
5033 | { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW }, | |
5034 | { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW }, | |
5035 | { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW }, | |
5036 | { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW }, | |
5037 | { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA }, | |
5038 | { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN }, | |
5039 | { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA }, | |
5040 | { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN }, | |
5041 | { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA }, | |
5042 | { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN }, | |
5043 | { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF }, | |
5044 | { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA }, | |
5045 | { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW }, | |
5046 | { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW }, | |
5047 | { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI }, | |
5048 | { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA }, | |
5049 | { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW }, | |
5050 | { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW }, | |
5051 | { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF }, | |
5052 | { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA }, | |
5053 | { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW }, | |
5054 | { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW }, | |
5055 | { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW }, | |
5056 | { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW }, | |
5057 | { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI }, | |
5058 | { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA }, | |
5059 | { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW }, | |
5060 | { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW }, | |
5061 | { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW }, | |
5062 | { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW }, | |
5063 | { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF }, | |
5064 | { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA }, | |
5065 | { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI }, | |
5066 | { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA }, | |
5067 | { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF }, | |
5068 | { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA }, | |
5069 | { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI }, | |
5070 | { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA }, | |
a3170dc6 AH |
5071 | { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW }, |
5072 | { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW }, | |
a3170dc6 AH |
5073 | { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW }, |
5074 | { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW }, | |
5075 | { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI }, | |
5076 | { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA }, | |
5077 | { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW }, | |
5078 | { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW }, | |
5079 | { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW }, | |
5080 | { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW }, | |
5081 | { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF }, | |
5082 | { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA }, | |
5083 | { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA }, | |
5084 | { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN }, | |
5085 | { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI }, | |
5086 | { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA }, | |
5087 | { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA }, | |
5088 | { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN }, | |
5089 | { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF }, | |
5090 | { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA }, | |
5091 | { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA }, | |
5092 | { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN }, | |
5093 | { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI }, | |
5094 | { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA }, | |
5095 | { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA }, | |
5096 | { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN }, | |
5097 | { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND }, | |
5098 | { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR }, | |
5099 | { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR }, | |
5100 | { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC }, | |
5101 | { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW }, | |
5102 | { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW }, | |
5103 | { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS }, | |
5104 | { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU }, | |
5105 | { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW }, | |
5106 | ||
5107 | /* SPE binary operations expecting a 5-bit unsigned literal. */ | |
5108 | { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW }, | |
5109 | ||
5110 | { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI }, | |
5111 | { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI }, | |
5112 | { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS }, | |
5113 | { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU }, | |
5114 | { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW }, | |
5115 | { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA }, | |
5116 | { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA }, | |
5117 | { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA }, | |
5118 | { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA }, | |
5119 | { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA }, | |
5120 | { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA }, | |
5121 | { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN }, | |
5122 | { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN }, | |
5123 | { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN }, | |
5124 | { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN }, | |
5125 | { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN }, | |
5126 | { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN }, | |
5127 | { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA }, | |
5128 | { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA }, | |
5129 | { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA }, | |
5130 | { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA }, | |
5131 | { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN }, | |
5132 | { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN }, | |
5133 | { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN }, | |
5134 | { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN }, | |
5135 | { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC }, | |
5136 | ||
5137 | /* Place-holder. Leave as last binary SPE builtin. */ | |
17edbda5 | 5138 | { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR }, |
ae4b4a02 AH |
5139 | }; |
5140 | ||
5141 | /* AltiVec predicates. */ | |
5142 | ||
5143 | struct builtin_description_predicates | |
5144 | { | |
5145 | const unsigned int mask; | |
5146 | const enum insn_code icode; | |
5147 | const char *opcode; | |
5148 | const char *const name; | |
5149 | const enum rs6000_builtins code; | |
5150 | }; | |
5151 | ||
5152 | static const struct builtin_description_predicates bdesc_altivec_preds[] = | |
5153 | { | |
5154 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P }, | |
5155 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P }, | |
5156 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P }, | |
5157 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P }, | |
5158 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P }, | |
5159 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P }, | |
5160 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P }, | |
5161 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P }, | |
5162 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P }, | |
5163 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P }, | |
5164 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P }, | |
5165 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P }, | |
5166 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P } | |
0ac081f6 | 5167 | }; |
24408032 | 5168 | |
a3170dc6 AH |
5169 | /* SPE predicates. */ |
5170 | static struct builtin_description bdesc_spe_predicates[] = | |
5171 | { | |
5172 | /* Place-holder. Leave as first. */ | |
5173 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ }, | |
5174 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS }, | |
5175 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU }, | |
5176 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS }, | |
5177 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU }, | |
5178 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ }, | |
5179 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT }, | |
5180 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT }, | |
5181 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ }, | |
5182 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT }, | |
5183 | /* Place-holder. Leave as last. */ | |
5184 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT }, | |
5185 | }; | |
5186 | ||
5187 | /* SPE evsel predicates. */ | |
5188 | static struct builtin_description bdesc_spe_evsel[] = | |
5189 | { | |
5190 | /* Place-holder. Leave as first. */ | |
5191 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS }, | |
5192 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU }, | |
5193 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS }, | |
5194 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU }, | |
5195 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ }, | |
5196 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT }, | |
5197 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT }, | |
5198 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ }, | |
5199 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT }, | |
5200 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT }, | |
5201 | /* Place-holder. Leave as last. */ | |
5202 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ }, | |
5203 | }; | |
5204 | ||
b6d08ca1 | 5205 | /* ABS* operations. */ |
100c4561 AH |
5206 | |
5207 | static const struct builtin_description bdesc_abs[] = | |
5208 | { | |
5209 | { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI }, | |
5210 | { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI }, | |
5211 | { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF }, | |
5212 | { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI }, | |
5213 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI }, | |
5214 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI }, | |
5215 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI } | |
5216 | }; | |
5217 | ||
617e0e1d DB |
5218 | /* Simple unary operations: VECb = foo (unsigned literal) or VECb = |
5219 | foo (VECa). */ | |
24408032 | 5220 | |
a3170dc6 | 5221 | static struct builtin_description bdesc_1arg[] = |
2212663f | 5222 | { |
617e0e1d DB |
5223 | { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP }, |
5224 | { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP }, | |
5225 | { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP }, | |
5226 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM }, | |
5227 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN }, | |
5228 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP }, | |
5229 | { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ }, | |
5230 | { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP }, | |
2212663f DB |
5231 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB }, |
5232 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH }, | |
5233 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW }, | |
20e26713 AH |
5234 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB }, |
5235 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX }, | |
5236 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH }, | |
5237 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB }, | |
5238 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX }, | |
5239 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH }, | |
a3170dc6 AH |
5240 | |
5241 | /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and | |
5242 | end with SPE_BUILTIN_EVSUBFUSIAAW. */ | |
5243 | { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS }, | |
5244 | { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW }, | |
5245 | { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW }, | |
5246 | { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW }, | |
5247 | { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW }, | |
5248 | { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW }, | |
5249 | { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW }, | |
5250 | { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB }, | |
5251 | { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH }, | |
5252 | { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS }, | |
5253 | { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF }, | |
5254 | { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI }, | |
5255 | { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF }, | |
5256 | { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI }, | |
5257 | { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF }, | |
5258 | { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI }, | |
5259 | { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ }, | |
5260 | { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF }, | |
5261 | { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI }, | |
5262 | { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ }, | |
5263 | { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS }, | |
5264 | { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG }, | |
5265 | { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA }, | |
5266 | { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG }, | |
5267 | { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW }, | |
5268 | { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW }, | |
5269 | { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW }, | |
5270 | { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW }, | |
a3170dc6 AH |
5271 | |
5272 | /* Place-holder. Leave as last unary SPE builtin. */ | |
5273 | { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW }, | |
2212663f DB |
5274 | }; |
5275 | ||
5276 | static rtx | |
a2369ed3 | 5277 | rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
5278 | { |
5279 | rtx pat; | |
5280 | tree arg0 = TREE_VALUE (arglist); | |
5281 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5282 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5283 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5284 | ||
0559cc77 DE |
5285 | if (icode == CODE_FOR_nothing) |
5286 | /* Builtin not supported on this processor. */ | |
5287 | return 0; | |
5288 | ||
20e26713 AH |
5289 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5290 | if (arg0 == error_mark_node) | |
9a171fcd | 5291 | return const0_rtx; |
20e26713 | 5292 | |
0559cc77 DE |
5293 | if (icode == CODE_FOR_altivec_vspltisb |
5294 | || icode == CODE_FOR_altivec_vspltish | |
5295 | || icode == CODE_FOR_altivec_vspltisw | |
5296 | || icode == CODE_FOR_spe_evsplatfi | |
5297 | || icode == CODE_FOR_spe_evsplati) | |
b44140e7 AH |
5298 | { |
5299 | /* Only allow 5-bit *signed* literals. */ | |
b44140e7 AH |
5300 | if (GET_CODE (op0) != CONST_INT |
5301 | || INTVAL (op0) > 0x1f | |
5302 | || INTVAL (op0) < -0x1f) | |
5303 | { | |
5304 | error ("argument 1 must be a 5-bit signed literal"); | |
9a171fcd | 5305 | return const0_rtx; |
b44140e7 | 5306 | } |
b44140e7 AH |
5307 | } |
5308 | ||
c62f2db5 | 5309 | if (target == 0 |
2212663f DB |
5310 | || GET_MODE (target) != tmode |
5311 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5312 | target = gen_reg_rtx (tmode); | |
5313 | ||
5314 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5315 | op0 = copy_to_mode_reg (mode0, op0); | |
5316 | ||
5317 | pat = GEN_FCN (icode) (target, op0); | |
5318 | if (! pat) | |
5319 | return 0; | |
5320 | emit_insn (pat); | |
0ac081f6 | 5321 | |
2212663f DB |
5322 | return target; |
5323 | } | |
ae4b4a02 | 5324 | |
100c4561 | 5325 | static rtx |
a2369ed3 | 5326 | altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target) |
100c4561 AH |
5327 | { |
5328 | rtx pat, scratch1, scratch2; | |
5329 | tree arg0 = TREE_VALUE (arglist); | |
5330 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5331 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5332 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5333 | ||
5334 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
5335 | if (arg0 == error_mark_node) | |
9a171fcd | 5336 | return const0_rtx; |
100c4561 AH |
5337 | |
5338 | if (target == 0 | |
5339 | || GET_MODE (target) != tmode | |
5340 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5341 | target = gen_reg_rtx (tmode); | |
5342 | ||
5343 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5344 | op0 = copy_to_mode_reg (mode0, op0); | |
5345 | ||
5346 | scratch1 = gen_reg_rtx (mode0); | |
5347 | scratch2 = gen_reg_rtx (mode0); | |
5348 | ||
5349 | pat = GEN_FCN (icode) (target, op0, scratch1, scratch2); | |
5350 | if (! pat) | |
5351 | return 0; | |
5352 | emit_insn (pat); | |
5353 | ||
5354 | return target; | |
5355 | } | |
5356 | ||
0ac081f6 | 5357 | static rtx |
a2369ed3 | 5358 | rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target) |
0ac081f6 AH |
5359 | { |
5360 | rtx pat; | |
5361 | tree arg0 = TREE_VALUE (arglist); | |
5362 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5363 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5364 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5365 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5366 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5367 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5368 | ||
0559cc77 DE |
5369 | if (icode == CODE_FOR_nothing) |
5370 | /* Builtin not supported on this processor. */ | |
5371 | return 0; | |
5372 | ||
20e26713 AH |
5373 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5374 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 5375 | return const0_rtx; |
20e26713 | 5376 | |
0559cc77 DE |
5377 | if (icode == CODE_FOR_altivec_vcfux |
5378 | || icode == CODE_FOR_altivec_vcfsx | |
5379 | || icode == CODE_FOR_altivec_vctsxs | |
5380 | || icode == CODE_FOR_altivec_vctuxs | |
5381 | || icode == CODE_FOR_altivec_vspltb | |
5382 | || icode == CODE_FOR_altivec_vsplth | |
5383 | || icode == CODE_FOR_altivec_vspltw | |
5384 | || icode == CODE_FOR_spe_evaddiw | |
5385 | || icode == CODE_FOR_spe_evldd | |
5386 | || icode == CODE_FOR_spe_evldh | |
5387 | || icode == CODE_FOR_spe_evldw | |
5388 | || icode == CODE_FOR_spe_evlhhesplat | |
5389 | || icode == CODE_FOR_spe_evlhhossplat | |
5390 | || icode == CODE_FOR_spe_evlhhousplat | |
5391 | || icode == CODE_FOR_spe_evlwhe | |
5392 | || icode == CODE_FOR_spe_evlwhos | |
5393 | || icode == CODE_FOR_spe_evlwhou | |
5394 | || icode == CODE_FOR_spe_evlwhsplat | |
5395 | || icode == CODE_FOR_spe_evlwwsplat | |
5396 | || icode == CODE_FOR_spe_evrlwi | |
5397 | || icode == CODE_FOR_spe_evslwi | |
5398 | || icode == CODE_FOR_spe_evsrwis | |
f5119d10 | 5399 | || icode == CODE_FOR_spe_evsubifw |
0559cc77 | 5400 | || icode == CODE_FOR_spe_evsrwiu) |
b44140e7 AH |
5401 | { |
5402 | /* Only allow 5-bit unsigned literals. */ | |
b44140e7 AH |
5403 | if (TREE_CODE (arg1) != INTEGER_CST |
5404 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
5405 | { | |
5406 | error ("argument 2 must be a 5-bit unsigned literal"); | |
9a171fcd | 5407 | return const0_rtx; |
b44140e7 | 5408 | } |
b44140e7 AH |
5409 | } |
5410 | ||
c62f2db5 | 5411 | if (target == 0 |
0ac081f6 AH |
5412 | || GET_MODE (target) != tmode |
5413 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5414 | target = gen_reg_rtx (tmode); | |
5415 | ||
5416 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5417 | op0 = copy_to_mode_reg (mode0, op0); | |
5418 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5419 | op1 = copy_to_mode_reg (mode1, op1); | |
5420 | ||
5421 | pat = GEN_FCN (icode) (target, op0, op1); | |
5422 | if (! pat) | |
5423 | return 0; | |
5424 | emit_insn (pat); | |
5425 | ||
5426 | return target; | |
5427 | } | |
6525c0e7 | 5428 | |
ae4b4a02 | 5429 | static rtx |
a2369ed3 DJ |
5430 | altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode, |
5431 | tree arglist, rtx target) | |
ae4b4a02 AH |
5432 | { |
5433 | rtx pat, scratch; | |
5434 | tree cr6_form = TREE_VALUE (arglist); | |
5435 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5436 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5437 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5438 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5439 | enum machine_mode tmode = SImode; | |
5440 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5441 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5442 | int cr6_form_int; | |
5443 | ||
5444 | if (TREE_CODE (cr6_form) != INTEGER_CST) | |
5445 | { | |
5446 | error ("argument 1 of __builtin_altivec_predicate must be a constant"); | |
9a171fcd | 5447 | return const0_rtx; |
ae4b4a02 AH |
5448 | } |
5449 | else | |
5450 | cr6_form_int = TREE_INT_CST_LOW (cr6_form); | |
5451 | ||
5452 | if (mode0 != mode1) | |
5453 | abort (); | |
5454 | ||
5455 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
5456 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 5457 | return const0_rtx; |
ae4b4a02 AH |
5458 | |
5459 | if (target == 0 | |
5460 | || GET_MODE (target) != tmode | |
5461 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5462 | target = gen_reg_rtx (tmode); | |
5463 | ||
5464 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5465 | op0 = copy_to_mode_reg (mode0, op0); | |
5466 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5467 | op1 = copy_to_mode_reg (mode1, op1); | |
5468 | ||
5469 | scratch = gen_reg_rtx (mode0); | |
5470 | ||
5471 | pat = GEN_FCN (icode) (scratch, op0, op1, | |
5472 | gen_rtx (SYMBOL_REF, Pmode, opcode)); | |
5473 | if (! pat) | |
5474 | return 0; | |
5475 | emit_insn (pat); | |
5476 | ||
5477 | /* The vec_any* and vec_all* predicates use the same opcodes for two | |
5478 | different operations, but the bits in CR6 will be different | |
5479 | depending on what information we want. So we have to play tricks | |
5480 | with CR6 to get the right bits out. | |
5481 | ||
5482 | If you think this is disgusting, look at the specs for the | |
5483 | AltiVec predicates. */ | |
5484 | ||
5485 | switch (cr6_form_int) | |
5486 | { | |
5487 | case 0: | |
5488 | emit_insn (gen_cr6_test_for_zero (target)); | |
5489 | break; | |
5490 | case 1: | |
5491 | emit_insn (gen_cr6_test_for_zero_reverse (target)); | |
5492 | break; | |
5493 | case 2: | |
5494 | emit_insn (gen_cr6_test_for_lt (target)); | |
5495 | break; | |
5496 | case 3: | |
5497 | emit_insn (gen_cr6_test_for_lt_reverse (target)); | |
5498 | break; | |
5499 | default: | |
5500 | error ("argument 1 of __builtin_altivec_predicate is out of range"); | |
5501 | break; | |
5502 | } | |
5503 | ||
5504 | return target; | |
5505 | } | |
5506 | ||
b4a62fa0 | 5507 | static rtx |
38f391a5 | 5508 | altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target) |
b4a62fa0 SB |
5509 | { |
5510 | rtx pat, addr; | |
5511 | tree arg0 = TREE_VALUE (arglist); | |
5512 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5513 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5514 | enum machine_mode mode0 = Pmode; | |
5515 | enum machine_mode mode1 = Pmode; | |
5516 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5517 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5518 | ||
5519 | if (icode == CODE_FOR_nothing) | |
5520 | /* Builtin not supported on this processor. */ | |
5521 | return 0; | |
5522 | ||
5523 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
5524 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
5525 | return const0_rtx; | |
5526 | ||
5527 | if (target == 0 | |
5528 | || GET_MODE (target) != tmode | |
5529 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5530 | target = gen_reg_rtx (tmode); | |
5531 | ||
5532 | op1 = copy_to_mode_reg (mode1, op1); | |
5533 | ||
5534 | if (op0 == const0_rtx) | |
5535 | { | |
5536 | addr = gen_rtx_MEM (tmode, op1); | |
5537 | } | |
5538 | else | |
5539 | { | |
5540 | op0 = copy_to_mode_reg (mode0, op0); | |
5541 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1)); | |
5542 | } | |
5543 | ||
5544 | pat = GEN_FCN (icode) (target, addr); | |
5545 | ||
5546 | if (! pat) | |
5547 | return 0; | |
5548 | emit_insn (pat); | |
5549 | ||
5550 | return target; | |
5551 | } | |
5552 | ||
6525c0e7 | 5553 | static rtx |
a2369ed3 | 5554 | altivec_expand_stv_builtin (enum insn_code icode, tree arglist) |
6525c0e7 AH |
5555 | { |
5556 | tree arg0 = TREE_VALUE (arglist); | |
5557 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5558 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5559 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5560 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5561 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
b4a62fa0 SB |
5562 | rtx pat, addr; |
5563 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5564 | enum machine_mode mode1 = Pmode; | |
5565 | enum machine_mode mode2 = Pmode; | |
6525c0e7 AH |
5566 | |
5567 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
5568 | if (arg0 == error_mark_node | |
5569 | || arg1 == error_mark_node | |
5570 | || arg2 == error_mark_node) | |
9a171fcd | 5571 | return const0_rtx; |
6525c0e7 | 5572 | |
b4a62fa0 SB |
5573 | if (! (*insn_data[icode].operand[1].predicate) (op0, tmode)) |
5574 | op0 = copy_to_mode_reg (tmode, op0); | |
5575 | ||
5576 | op2 = copy_to_mode_reg (mode2, op2); | |
5577 | ||
5578 | if (op1 == const0_rtx) | |
5579 | { | |
5580 | addr = gen_rtx_MEM (tmode, op2); | |
5581 | } | |
5582 | else | |
5583 | { | |
5584 | op1 = copy_to_mode_reg (mode1, op1); | |
5585 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2)); | |
5586 | } | |
6525c0e7 | 5587 | |
b4a62fa0 | 5588 | pat = GEN_FCN (icode) (addr, op0); |
6525c0e7 AH |
5589 | if (pat) |
5590 | emit_insn (pat); | |
5591 | return NULL_RTX; | |
5592 | } | |
5593 | ||
2212663f | 5594 | static rtx |
a2369ed3 | 5595 | rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
5596 | { |
5597 | rtx pat; | |
5598 | tree arg0 = TREE_VALUE (arglist); | |
5599 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5600 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5601 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5602 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5603 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
5604 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5605 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5606 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5607 | enum machine_mode mode2 = insn_data[icode].operand[3].mode; | |
0ac081f6 | 5608 | |
774b5662 DE |
5609 | if (icode == CODE_FOR_nothing) |
5610 | /* Builtin not supported on this processor. */ | |
5611 | return 0; | |
5612 | ||
20e26713 AH |
5613 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5614 | if (arg0 == error_mark_node | |
5615 | || arg1 == error_mark_node | |
5616 | || arg2 == error_mark_node) | |
9a171fcd | 5617 | return const0_rtx; |
20e26713 | 5618 | |
774b5662 DE |
5619 | if (icode == CODE_FOR_altivec_vsldoi_4sf |
5620 | || icode == CODE_FOR_altivec_vsldoi_4si | |
5621 | || icode == CODE_FOR_altivec_vsldoi_8hi | |
5622 | || icode == CODE_FOR_altivec_vsldoi_16qi) | |
b44140e7 AH |
5623 | { |
5624 | /* Only allow 4-bit unsigned literals. */ | |
b44140e7 AH |
5625 | if (TREE_CODE (arg2) != INTEGER_CST |
5626 | || TREE_INT_CST_LOW (arg2) & ~0xf) | |
5627 | { | |
5628 | error ("argument 3 must be a 4-bit unsigned literal"); | |
e3277ffb | 5629 | return const0_rtx; |
b44140e7 | 5630 | } |
b44140e7 AH |
5631 | } |
5632 | ||
c62f2db5 | 5633 | if (target == 0 |
2212663f DB |
5634 | || GET_MODE (target) != tmode |
5635 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5636 | target = gen_reg_rtx (tmode); | |
5637 | ||
5638 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5639 | op0 = copy_to_mode_reg (mode0, op0); | |
5640 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5641 | op1 = copy_to_mode_reg (mode1, op1); | |
5642 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
5643 | op2 = copy_to_mode_reg (mode2, op2); | |
5644 | ||
5645 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
5646 | if (! pat) | |
5647 | return 0; | |
5648 | emit_insn (pat); | |
5649 | ||
5650 | return target; | |
5651 | } | |
92898235 | 5652 | |
3a9b8c7e | 5653 | /* Expand the lvx builtins. */ |
0ac081f6 | 5654 | static rtx |
a2369ed3 | 5655 | altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp) |
0ac081f6 | 5656 | { |
0ac081f6 AH |
5657 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
5658 | tree arglist = TREE_OPERAND (exp, 1); | |
0ac081f6 | 5659 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
3a9b8c7e AH |
5660 | tree arg0; |
5661 | enum machine_mode tmode, mode0; | |
7c3abc73 | 5662 | rtx pat, op0; |
3a9b8c7e | 5663 | enum insn_code icode; |
92898235 | 5664 | |
0ac081f6 AH |
5665 | switch (fcode) |
5666 | { | |
f18c054f DB |
5667 | case ALTIVEC_BUILTIN_LD_INTERNAL_16qi: |
5668 | icode = CODE_FOR_altivec_lvx_16qi; | |
3a9b8c7e | 5669 | break; |
f18c054f DB |
5670 | case ALTIVEC_BUILTIN_LD_INTERNAL_8hi: |
5671 | icode = CODE_FOR_altivec_lvx_8hi; | |
3a9b8c7e AH |
5672 | break; |
5673 | case ALTIVEC_BUILTIN_LD_INTERNAL_4si: | |
5674 | icode = CODE_FOR_altivec_lvx_4si; | |
5675 | break; | |
5676 | case ALTIVEC_BUILTIN_LD_INTERNAL_4sf: | |
5677 | icode = CODE_FOR_altivec_lvx_4sf; | |
5678 | break; | |
5679 | default: | |
5680 | *expandedp = false; | |
5681 | return NULL_RTX; | |
5682 | } | |
0ac081f6 | 5683 | |
3a9b8c7e | 5684 | *expandedp = true; |
f18c054f | 5685 | |
3a9b8c7e AH |
5686 | arg0 = TREE_VALUE (arglist); |
5687 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5688 | tmode = insn_data[icode].operand[0].mode; | |
5689 | mode0 = insn_data[icode].operand[1].mode; | |
f18c054f | 5690 | |
3a9b8c7e AH |
5691 | if (target == 0 |
5692 | || GET_MODE (target) != tmode | |
5693 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5694 | target = gen_reg_rtx (tmode); | |
24408032 | 5695 | |
3a9b8c7e AH |
5696 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) |
5697 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
f18c054f | 5698 | |
3a9b8c7e AH |
5699 | pat = GEN_FCN (icode) (target, op0); |
5700 | if (! pat) | |
5701 | return 0; | |
5702 | emit_insn (pat); | |
5703 | return target; | |
5704 | } | |
f18c054f | 5705 | |
3a9b8c7e AH |
5706 | /* Expand the stvx builtins. */ |
5707 | static rtx | |
a2369ed3 DJ |
5708 | altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
5709 | bool *expandedp) | |
3a9b8c7e AH |
5710 | { |
5711 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
5712 | tree arglist = TREE_OPERAND (exp, 1); | |
5713 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
5714 | tree arg0, arg1; | |
5715 | enum machine_mode mode0, mode1; | |
7c3abc73 | 5716 | rtx pat, op0, op1; |
3a9b8c7e | 5717 | enum insn_code icode; |
f18c054f | 5718 | |
3a9b8c7e AH |
5719 | switch (fcode) |
5720 | { | |
5721 | case ALTIVEC_BUILTIN_ST_INTERNAL_16qi: | |
5722 | icode = CODE_FOR_altivec_stvx_16qi; | |
5723 | break; | |
5724 | case ALTIVEC_BUILTIN_ST_INTERNAL_8hi: | |
5725 | icode = CODE_FOR_altivec_stvx_8hi; | |
5726 | break; | |
5727 | case ALTIVEC_BUILTIN_ST_INTERNAL_4si: | |
5728 | icode = CODE_FOR_altivec_stvx_4si; | |
5729 | break; | |
5730 | case ALTIVEC_BUILTIN_ST_INTERNAL_4sf: | |
5731 | icode = CODE_FOR_altivec_stvx_4sf; | |
5732 | break; | |
5733 | default: | |
5734 | *expandedp = false; | |
5735 | return NULL_RTX; | |
5736 | } | |
24408032 | 5737 | |
3a9b8c7e AH |
5738 | arg0 = TREE_VALUE (arglist); |
5739 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5740 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5741 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5742 | mode0 = insn_data[icode].operand[0].mode; | |
5743 | mode1 = insn_data[icode].operand[1].mode; | |
f18c054f | 5744 | |
3a9b8c7e AH |
5745 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
5746 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
5747 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
5748 | op1 = copy_to_mode_reg (mode1, op1); | |
f18c054f | 5749 | |
3a9b8c7e AH |
5750 | pat = GEN_FCN (icode) (op0, op1); |
5751 | if (pat) | |
5752 | emit_insn (pat); | |
f18c054f | 5753 | |
3a9b8c7e AH |
5754 | *expandedp = true; |
5755 | return NULL_RTX; | |
5756 | } | |
f18c054f | 5757 | |
3a9b8c7e AH |
5758 | /* Expand the dst builtins. */ |
5759 | static rtx | |
a2369ed3 DJ |
5760 | altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
5761 | bool *expandedp) | |
3a9b8c7e AH |
5762 | { |
5763 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
5764 | tree arglist = TREE_OPERAND (exp, 1); | |
5765 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
5766 | tree arg0, arg1, arg2; | |
5767 | enum machine_mode mode0, mode1, mode2; | |
7c3abc73 | 5768 | rtx pat, op0, op1, op2; |
3a9b8c7e | 5769 | struct builtin_description *d; |
a3170dc6 | 5770 | size_t i; |
f18c054f | 5771 | |
3a9b8c7e | 5772 | *expandedp = false; |
f18c054f | 5773 | |
3a9b8c7e AH |
5774 | /* Handle DST variants. */ |
5775 | d = (struct builtin_description *) bdesc_dst; | |
5776 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
5777 | if (d->code == fcode) | |
5778 | { | |
5779 | arg0 = TREE_VALUE (arglist); | |
5780 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5781 | arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5782 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5783 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5784 | op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
5785 | mode0 = insn_data[d->icode].operand[0].mode; | |
5786 | mode1 = insn_data[d->icode].operand[1].mode; | |
5787 | mode2 = insn_data[d->icode].operand[2].mode; | |
24408032 | 5788 | |
3a9b8c7e AH |
5789 | /* Invalid arguments, bail out before generating bad rtl. */ |
5790 | if (arg0 == error_mark_node | |
5791 | || arg1 == error_mark_node | |
5792 | || arg2 == error_mark_node) | |
5793 | return const0_rtx; | |
f18c054f | 5794 | |
3a9b8c7e AH |
5795 | if (TREE_CODE (arg2) != INTEGER_CST |
5796 | || TREE_INT_CST_LOW (arg2) & ~0x3) | |
5797 | { | |
5798 | error ("argument to `%s' must be a 2-bit unsigned literal", d->name); | |
5799 | return const0_rtx; | |
5800 | } | |
f18c054f | 5801 | |
3a9b8c7e | 5802 | if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0)) |
b4a62fa0 | 5803 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); |
3a9b8c7e AH |
5804 | if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1)) |
5805 | op1 = copy_to_mode_reg (mode1, op1); | |
24408032 | 5806 | |
3a9b8c7e AH |
5807 | pat = GEN_FCN (d->icode) (op0, op1, op2); |
5808 | if (pat != 0) | |
5809 | emit_insn (pat); | |
f18c054f | 5810 | |
3a9b8c7e AH |
5811 | *expandedp = true; |
5812 | return NULL_RTX; | |
5813 | } | |
f18c054f | 5814 | |
3a9b8c7e AH |
5815 | return NULL_RTX; |
5816 | } | |
24408032 | 5817 | |
3a9b8c7e AH |
5818 | /* Expand the builtin in EXP and store the result in TARGET. Store |
5819 | true in *EXPANDEDP if we found a builtin to expand. */ | |
5820 | static rtx | |
a2369ed3 | 5821 | altivec_expand_builtin (tree exp, rtx target, bool *expandedp) |
3a9b8c7e AH |
5822 | { |
5823 | struct builtin_description *d; | |
5824 | struct builtin_description_predicates *dp; | |
5825 | size_t i; | |
5826 | enum insn_code icode; | |
5827 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
5828 | tree arglist = TREE_OPERAND (exp, 1); | |
7c3abc73 AH |
5829 | tree arg0; |
5830 | rtx op0, pat; | |
5831 | enum machine_mode tmode, mode0; | |
3a9b8c7e | 5832 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
0ac081f6 | 5833 | |
3a9b8c7e AH |
5834 | target = altivec_expand_ld_builtin (exp, target, expandedp); |
5835 | if (*expandedp) | |
5836 | return target; | |
0ac081f6 | 5837 | |
3a9b8c7e AH |
5838 | target = altivec_expand_st_builtin (exp, target, expandedp); |
5839 | if (*expandedp) | |
5840 | return target; | |
5841 | ||
5842 | target = altivec_expand_dst_builtin (exp, target, expandedp); | |
5843 | if (*expandedp) | |
5844 | return target; | |
5845 | ||
5846 | *expandedp = true; | |
95385cbb | 5847 | |
3a9b8c7e AH |
5848 | switch (fcode) |
5849 | { | |
6525c0e7 AH |
5850 | case ALTIVEC_BUILTIN_STVX: |
5851 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist); | |
5852 | case ALTIVEC_BUILTIN_STVEBX: | |
5853 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist); | |
5854 | case ALTIVEC_BUILTIN_STVEHX: | |
5855 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist); | |
5856 | case ALTIVEC_BUILTIN_STVEWX: | |
5857 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist); | |
5858 | case ALTIVEC_BUILTIN_STVXL: | |
5859 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist); | |
3a9b8c7e | 5860 | |
95385cbb AH |
5861 | case ALTIVEC_BUILTIN_MFVSCR: |
5862 | icode = CODE_FOR_altivec_mfvscr; | |
5863 | tmode = insn_data[icode].operand[0].mode; | |
5864 | ||
5865 | if (target == 0 | |
5866 | || GET_MODE (target) != tmode | |
5867 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5868 | target = gen_reg_rtx (tmode); | |
5869 | ||
5870 | pat = GEN_FCN (icode) (target); | |
0ac081f6 AH |
5871 | if (! pat) |
5872 | return 0; | |
5873 | emit_insn (pat); | |
95385cbb AH |
5874 | return target; |
5875 | ||
5876 | case ALTIVEC_BUILTIN_MTVSCR: | |
5877 | icode = CODE_FOR_altivec_mtvscr; | |
5878 | arg0 = TREE_VALUE (arglist); | |
5879 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5880 | mode0 = insn_data[icode].operand[0].mode; | |
5881 | ||
5882 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
5883 | if (arg0 == error_mark_node) | |
9a171fcd | 5884 | return const0_rtx; |
95385cbb AH |
5885 | |
5886 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
5887 | op0 = copy_to_mode_reg (mode0, op0); | |
5888 | ||
5889 | pat = GEN_FCN (icode) (op0); | |
5890 | if (pat) | |
5891 | emit_insn (pat); | |
5892 | return NULL_RTX; | |
3a9b8c7e | 5893 | |
95385cbb AH |
5894 | case ALTIVEC_BUILTIN_DSSALL: |
5895 | emit_insn (gen_altivec_dssall ()); | |
5896 | return NULL_RTX; | |
5897 | ||
5898 | case ALTIVEC_BUILTIN_DSS: | |
5899 | icode = CODE_FOR_altivec_dss; | |
5900 | arg0 = TREE_VALUE (arglist); | |
5901 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5902 | mode0 = insn_data[icode].operand[0].mode; | |
5903 | ||
5904 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
5905 | if (arg0 == error_mark_node) | |
9a171fcd | 5906 | return const0_rtx; |
95385cbb | 5907 | |
b44140e7 AH |
5908 | if (TREE_CODE (arg0) != INTEGER_CST |
5909 | || TREE_INT_CST_LOW (arg0) & ~0x3) | |
5910 | { | |
5911 | error ("argument to dss must be a 2-bit unsigned literal"); | |
9a171fcd | 5912 | return const0_rtx; |
b44140e7 AH |
5913 | } |
5914 | ||
95385cbb AH |
5915 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
5916 | op0 = copy_to_mode_reg (mode0, op0); | |
5917 | ||
5918 | emit_insn (gen_altivec_dss (op0)); | |
0ac081f6 AH |
5919 | return NULL_RTX; |
5920 | } | |
24408032 | 5921 | |
100c4561 AH |
5922 | /* Expand abs* operations. */ |
5923 | d = (struct builtin_description *) bdesc_abs; | |
ca7558fc | 5924 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) |
100c4561 AH |
5925 | if (d->code == fcode) |
5926 | return altivec_expand_abs_builtin (d->icode, arglist, target); | |
5927 | ||
ae4b4a02 AH |
5928 | /* Expand the AltiVec predicates. */ |
5929 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
ca7558fc | 5930 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) |
ae4b4a02 AH |
5931 | if (dp->code == fcode) |
5932 | return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target); | |
5933 | ||
6525c0e7 AH |
5934 | /* LV* are funky. We initialized them differently. */ |
5935 | switch (fcode) | |
5936 | { | |
5937 | case ALTIVEC_BUILTIN_LVSL: | |
b4a62fa0 | 5938 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl, |
6525c0e7 AH |
5939 | arglist, target); |
5940 | case ALTIVEC_BUILTIN_LVSR: | |
b4a62fa0 | 5941 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr, |
92898235 | 5942 | arglist, target); |
6525c0e7 | 5943 | case ALTIVEC_BUILTIN_LVEBX: |
b4a62fa0 | 5944 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx, |
92898235 | 5945 | arglist, target); |
6525c0e7 | 5946 | case ALTIVEC_BUILTIN_LVEHX: |
b4a62fa0 | 5947 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx, |
92898235 | 5948 | arglist, target); |
6525c0e7 | 5949 | case ALTIVEC_BUILTIN_LVEWX: |
b4a62fa0 | 5950 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx, |
92898235 | 5951 | arglist, target); |
6525c0e7 | 5952 | case ALTIVEC_BUILTIN_LVXL: |
b4a62fa0 | 5953 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl, |
92898235 | 5954 | arglist, target); |
6525c0e7 | 5955 | case ALTIVEC_BUILTIN_LVX: |
b4a62fa0 | 5956 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx, |
92898235 | 5957 | arglist, target); |
6525c0e7 AH |
5958 | default: |
5959 | break; | |
5960 | /* Fall through. */ | |
5961 | } | |
95385cbb | 5962 | |
92898235 | 5963 | *expandedp = false; |
0ac081f6 AH |
5964 | return NULL_RTX; |
5965 | } | |
5966 | ||
a3170dc6 AH |
5967 | /* Binops that need to be initialized manually, but can be expanded |
5968 | automagically by rs6000_expand_binop_builtin. */ | |
5969 | static struct builtin_description bdesc_2arg_spe[] = | |
5970 | { | |
5971 | { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX }, | |
5972 | { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX }, | |
5973 | { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX }, | |
5974 | { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX }, | |
5975 | { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX }, | |
5976 | { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX }, | |
5977 | { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX }, | |
5978 | { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX }, | |
5979 | { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX }, | |
5980 | { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX }, | |
5981 | { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX }, | |
5982 | { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD }, | |
5983 | { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW }, | |
5984 | { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH }, | |
5985 | { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE }, | |
5986 | { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU }, | |
5987 | { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS }, | |
5988 | { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT }, | |
5989 | { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT }, | |
5990 | { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT }, | |
5991 | { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT }, | |
5992 | { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT } | |
5993 | }; | |
5994 | ||
5995 | /* Expand the builtin in EXP and store the result in TARGET. Store | |
5996 | true in *EXPANDEDP if we found a builtin to expand. | |
5997 | ||
5998 | This expands the SPE builtins that are not simple unary and binary | |
5999 | operations. */ | |
6000 | static rtx | |
a2369ed3 | 6001 | spe_expand_builtin (tree exp, rtx target, bool *expandedp) |
a3170dc6 AH |
6002 | { |
6003 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6004 | tree arglist = TREE_OPERAND (exp, 1); | |
6005 | tree arg1, arg0; | |
6006 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6007 | enum insn_code icode; | |
6008 | enum machine_mode tmode, mode0; | |
6009 | rtx pat, op0; | |
6010 | struct builtin_description *d; | |
6011 | size_t i; | |
6012 | ||
6013 | *expandedp = true; | |
6014 | ||
6015 | /* Syntax check for a 5-bit unsigned immediate. */ | |
6016 | switch (fcode) | |
6017 | { | |
6018 | case SPE_BUILTIN_EVSTDD: | |
6019 | case SPE_BUILTIN_EVSTDH: | |
6020 | case SPE_BUILTIN_EVSTDW: | |
6021 | case SPE_BUILTIN_EVSTWHE: | |
6022 | case SPE_BUILTIN_EVSTWHO: | |
6023 | case SPE_BUILTIN_EVSTWWE: | |
6024 | case SPE_BUILTIN_EVSTWWO: | |
6025 | arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6026 | if (TREE_CODE (arg1) != INTEGER_CST | |
6027 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
6028 | { | |
6029 | error ("argument 2 must be a 5-bit unsigned literal"); | |
6030 | return const0_rtx; | |
6031 | } | |
6032 | break; | |
6033 | default: | |
6034 | break; | |
6035 | } | |
6036 | ||
00332c9f AH |
6037 | /* The evsplat*i instructions are not quite generic. */ |
6038 | switch (fcode) | |
6039 | { | |
6040 | case SPE_BUILTIN_EVSPLATFI: | |
6041 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi, | |
6042 | arglist, target); | |
6043 | case SPE_BUILTIN_EVSPLATI: | |
6044 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati, | |
6045 | arglist, target); | |
6046 | default: | |
6047 | break; | |
6048 | } | |
6049 | ||
a3170dc6 AH |
6050 | d = (struct builtin_description *) bdesc_2arg_spe; |
6051 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d) | |
6052 | if (d->code == fcode) | |
6053 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6054 | ||
6055 | d = (struct builtin_description *) bdesc_spe_predicates; | |
6056 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d) | |
6057 | if (d->code == fcode) | |
6058 | return spe_expand_predicate_builtin (d->icode, arglist, target); | |
6059 | ||
6060 | d = (struct builtin_description *) bdesc_spe_evsel; | |
6061 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d) | |
6062 | if (d->code == fcode) | |
6063 | return spe_expand_evsel_builtin (d->icode, arglist, target); | |
6064 | ||
6065 | switch (fcode) | |
6066 | { | |
6067 | case SPE_BUILTIN_EVSTDDX: | |
6068 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist); | |
6069 | case SPE_BUILTIN_EVSTDHX: | |
6070 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist); | |
6071 | case SPE_BUILTIN_EVSTDWX: | |
6072 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist); | |
6073 | case SPE_BUILTIN_EVSTWHEX: | |
6074 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist); | |
6075 | case SPE_BUILTIN_EVSTWHOX: | |
6076 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist); | |
6077 | case SPE_BUILTIN_EVSTWWEX: | |
6078 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist); | |
6079 | case SPE_BUILTIN_EVSTWWOX: | |
6080 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist); | |
6081 | case SPE_BUILTIN_EVSTDD: | |
6082 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist); | |
6083 | case SPE_BUILTIN_EVSTDH: | |
6084 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist); | |
6085 | case SPE_BUILTIN_EVSTDW: | |
6086 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist); | |
6087 | case SPE_BUILTIN_EVSTWHE: | |
6088 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist); | |
6089 | case SPE_BUILTIN_EVSTWHO: | |
6090 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist); | |
6091 | case SPE_BUILTIN_EVSTWWE: | |
6092 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist); | |
6093 | case SPE_BUILTIN_EVSTWWO: | |
6094 | return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist); | |
6095 | case SPE_BUILTIN_MFSPEFSCR: | |
6096 | icode = CODE_FOR_spe_mfspefscr; | |
6097 | tmode = insn_data[icode].operand[0].mode; | |
6098 | ||
6099 | if (target == 0 | |
6100 | || GET_MODE (target) != tmode | |
6101 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6102 | target = gen_reg_rtx (tmode); | |
6103 | ||
6104 | pat = GEN_FCN (icode) (target); | |
6105 | if (! pat) | |
6106 | return 0; | |
6107 | emit_insn (pat); | |
6108 | return target; | |
6109 | case SPE_BUILTIN_MTSPEFSCR: | |
6110 | icode = CODE_FOR_spe_mtspefscr; | |
6111 | arg0 = TREE_VALUE (arglist); | |
6112 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6113 | mode0 = insn_data[icode].operand[0].mode; | |
6114 | ||
6115 | if (arg0 == error_mark_node) | |
6116 | return const0_rtx; | |
6117 | ||
6118 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
6119 | op0 = copy_to_mode_reg (mode0, op0); | |
6120 | ||
6121 | pat = GEN_FCN (icode) (op0); | |
6122 | if (pat) | |
6123 | emit_insn (pat); | |
6124 | return NULL_RTX; | |
6125 | default: | |
6126 | break; | |
6127 | } | |
6128 | ||
6129 | *expandedp = false; | |
6130 | return NULL_RTX; | |
6131 | } | |
6132 | ||
6133 | static rtx | |
a2369ed3 | 6134 | spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
6135 | { |
6136 | rtx pat, scratch, tmp; | |
6137 | tree form = TREE_VALUE (arglist); | |
6138 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6139 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6140 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6141 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6142 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6143 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6144 | int form_int; | |
6145 | enum rtx_code code; | |
6146 | ||
6147 | if (TREE_CODE (form) != INTEGER_CST) | |
6148 | { | |
6149 | error ("argument 1 of __builtin_spe_predicate must be a constant"); | |
6150 | return const0_rtx; | |
6151 | } | |
6152 | else | |
6153 | form_int = TREE_INT_CST_LOW (form); | |
6154 | ||
6155 | if (mode0 != mode1) | |
6156 | abort (); | |
6157 | ||
6158 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
6159 | return const0_rtx; | |
6160 | ||
6161 | if (target == 0 | |
6162 | || GET_MODE (target) != SImode | |
6163 | || ! (*insn_data[icode].operand[0].predicate) (target, SImode)) | |
6164 | target = gen_reg_rtx (SImode); | |
6165 | ||
6166 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6167 | op0 = copy_to_mode_reg (mode0, op0); | |
6168 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6169 | op1 = copy_to_mode_reg (mode1, op1); | |
6170 | ||
6171 | scratch = gen_reg_rtx (CCmode); | |
6172 | ||
6173 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
6174 | if (! pat) | |
6175 | return const0_rtx; | |
6176 | emit_insn (pat); | |
6177 | ||
6178 | /* There are 4 variants for each predicate: _any_, _all_, _upper_, | |
6179 | _lower_. We use one compare, but look in different bits of the | |
6180 | CR for each variant. | |
6181 | ||
6182 | There are 2 elements in each SPE simd type (upper/lower). The CR | |
6183 | bits are set as follows: | |
6184 | ||
6185 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
6186 | U | L | (U | L) | (U & L) | |
6187 | ||
6188 | So, for an "all" relationship, BIT 3 would be set. | |
6189 | For an "any" relationship, BIT 2 would be set. Etc. | |
6190 | ||
6191 | Following traditional nomenclature, these bits map to: | |
6192 | ||
6193 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
6194 | LT | GT | EQ | OV | |
6195 | ||
6196 | Later, we will generate rtl to look in the LT/EQ/EQ/OV bits. | |
6197 | */ | |
6198 | ||
6199 | switch (form_int) | |
6200 | { | |
6201 | /* All variant. OV bit. */ | |
6202 | case 0: | |
6203 | /* We need to get to the OV bit, which is the ORDERED bit. We | |
6204 | could generate (ordered:SI (reg:CC xx) (const_int 0)), but | |
6205 | that's ugly and will trigger a validate_condition_mode abort. | |
6206 | So let's just use another pattern. */ | |
6207 | emit_insn (gen_move_from_CR_ov_bit (target, scratch)); | |
6208 | return target; | |
6209 | /* Any variant. EQ bit. */ | |
6210 | case 1: | |
6211 | code = EQ; | |
6212 | break; | |
6213 | /* Upper variant. LT bit. */ | |
6214 | case 2: | |
6215 | code = LT; | |
6216 | break; | |
6217 | /* Lower variant. GT bit. */ | |
6218 | case 3: | |
6219 | code = GT; | |
6220 | break; | |
6221 | default: | |
6222 | error ("argument 1 of __builtin_spe_predicate is out of range"); | |
6223 | return const0_rtx; | |
6224 | } | |
6225 | ||
6226 | tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx); | |
6227 | emit_move_insn (target, tmp); | |
6228 | ||
6229 | return target; | |
6230 | } | |
6231 | ||
6232 | /* The evsel builtins look like this: | |
6233 | ||
6234 | e = __builtin_spe_evsel_OP (a, b, c, d); | |
6235 | ||
6236 | and work like this: | |
6237 | ||
6238 | e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper]; | |
6239 | e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower]; | |
6240 | */ | |
6241 | ||
6242 | static rtx | |
a2369ed3 | 6243 | spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
6244 | { |
6245 | rtx pat, scratch; | |
6246 | tree arg0 = TREE_VALUE (arglist); | |
6247 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6248 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6249 | tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist)))); | |
6250 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6251 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6252 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6253 | rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0); | |
6254 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6255 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6256 | ||
6257 | if (mode0 != mode1) | |
6258 | abort (); | |
6259 | ||
6260 | if (arg0 == error_mark_node || arg1 == error_mark_node | |
6261 | || arg2 == error_mark_node || arg3 == error_mark_node) | |
6262 | return const0_rtx; | |
6263 | ||
6264 | if (target == 0 | |
6265 | || GET_MODE (target) != mode0 | |
6266 | || ! (*insn_data[icode].operand[0].predicate) (target, mode0)) | |
6267 | target = gen_reg_rtx (mode0); | |
6268 | ||
6269 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6270 | op0 = copy_to_mode_reg (mode0, op0); | |
6271 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
6272 | op1 = copy_to_mode_reg (mode0, op1); | |
6273 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
6274 | op2 = copy_to_mode_reg (mode0, op2); | |
6275 | if (! (*insn_data[icode].operand[1].predicate) (op3, mode1)) | |
6276 | op3 = copy_to_mode_reg (mode0, op3); | |
6277 | ||
6278 | /* Generate the compare. */ | |
6279 | scratch = gen_reg_rtx (CCmode); | |
6280 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
6281 | if (! pat) | |
6282 | return const0_rtx; | |
6283 | emit_insn (pat); | |
6284 | ||
6285 | if (mode0 == V2SImode) | |
6286 | emit_insn (gen_spe_evsel (target, op2, op3, scratch)); | |
6287 | else | |
6288 | emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch)); | |
6289 | ||
6290 | return target; | |
6291 | } | |
6292 | ||
0ac081f6 AH |
6293 | /* Expand an expression EXP that calls a built-in function, |
6294 | with result going to TARGET if that's convenient | |
6295 | (and in mode MODE if that's convenient). | |
6296 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
6297 | IGNORE is nonzero if the value is to be ignored. */ | |
6298 | ||
6299 | static rtx | |
a2369ed3 DJ |
6300 | rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, |
6301 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
6302 | int ignore ATTRIBUTE_UNUSED) | |
0ac081f6 | 6303 | { |
92898235 AH |
6304 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
6305 | tree arglist = TREE_OPERAND (exp, 1); | |
6306 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6307 | struct builtin_description *d; | |
6308 | size_t i; | |
6309 | rtx ret; | |
6310 | bool success; | |
6311 | ||
0ac081f6 | 6312 | if (TARGET_ALTIVEC) |
92898235 AH |
6313 | { |
6314 | ret = altivec_expand_builtin (exp, target, &success); | |
6315 | ||
a3170dc6 AH |
6316 | if (success) |
6317 | return ret; | |
6318 | } | |
6319 | if (TARGET_SPE) | |
6320 | { | |
6321 | ret = spe_expand_builtin (exp, target, &success); | |
6322 | ||
92898235 AH |
6323 | if (success) |
6324 | return ret; | |
6325 | } | |
6326 | ||
0559cc77 DE |
6327 | if (TARGET_ALTIVEC || TARGET_SPE) |
6328 | { | |
6329 | /* Handle simple unary operations. */ | |
6330 | d = (struct builtin_description *) bdesc_1arg; | |
6331 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) | |
6332 | if (d->code == fcode) | |
6333 | return rs6000_expand_unop_builtin (d->icode, arglist, target); | |
6334 | ||
6335 | /* Handle simple binary operations. */ | |
6336 | d = (struct builtin_description *) bdesc_2arg; | |
6337 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) | |
6338 | if (d->code == fcode) | |
6339 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6340 | ||
6341 | /* Handle simple ternary operations. */ | |
6342 | d = (struct builtin_description *) bdesc_3arg; | |
6343 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) | |
6344 | if (d->code == fcode) | |
6345 | return rs6000_expand_ternop_builtin (d->icode, arglist, target); | |
6346 | } | |
0ac081f6 AH |
6347 | |
6348 | abort (); | |
92898235 | 6349 | return NULL_RTX; |
0ac081f6 AH |
6350 | } |
6351 | ||
6352 | static void | |
863d938c | 6353 | rs6000_init_builtins (void) |
0ac081f6 | 6354 | { |
3fdaa45a AH |
6355 | opaque_V2SI_type_node = copy_node (V2SI_type_node); |
6356 | opaque_V2SF_type_node = copy_node (V2SF_type_node); | |
6035d635 | 6357 | opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node); |
3fdaa45a | 6358 | |
a3170dc6 | 6359 | if (TARGET_SPE) |
3fdaa45a | 6360 | spe_init_builtins (); |
0ac081f6 AH |
6361 | if (TARGET_ALTIVEC) |
6362 | altivec_init_builtins (); | |
0559cc77 DE |
6363 | if (TARGET_ALTIVEC || TARGET_SPE) |
6364 | rs6000_common_init_builtins (); | |
0ac081f6 AH |
6365 | } |
6366 | ||
a3170dc6 AH |
6367 | /* Search through a set of builtins and enable the mask bits. |
6368 | DESC is an array of builtins. | |
b6d08ca1 | 6369 | SIZE is the total number of builtins. |
a3170dc6 AH |
6370 | START is the builtin enum at which to start. |
6371 | END is the builtin enum at which to end. */ | |
0ac081f6 | 6372 | static void |
a2369ed3 DJ |
6373 | enable_mask_for_builtins (struct builtin_description *desc, int size, |
6374 | enum rs6000_builtins start, | |
6375 | enum rs6000_builtins end) | |
a3170dc6 AH |
6376 | { |
6377 | int i; | |
6378 | ||
6379 | for (i = 0; i < size; ++i) | |
6380 | if (desc[i].code == start) | |
6381 | break; | |
6382 | ||
6383 | if (i == size) | |
6384 | return; | |
6385 | ||
6386 | for (; i < size; ++i) | |
6387 | { | |
6388 | /* Flip all the bits on. */ | |
6389 | desc[i].mask = target_flags; | |
6390 | if (desc[i].code == end) | |
6391 | break; | |
6392 | } | |
6393 | } | |
6394 | ||
6395 | static void | |
863d938c | 6396 | spe_init_builtins (void) |
0ac081f6 | 6397 | { |
a3170dc6 AH |
6398 | tree endlink = void_list_node; |
6399 | tree puint_type_node = build_pointer_type (unsigned_type_node); | |
6400 | tree pushort_type_node = build_pointer_type (short_unsigned_type_node); | |
ae4b4a02 | 6401 | struct builtin_description *d; |
0ac081f6 AH |
6402 | size_t i; |
6403 | ||
a3170dc6 AH |
6404 | tree v2si_ftype_4_v2si |
6405 | = build_function_type | |
3fdaa45a AH |
6406 | (opaque_V2SI_type_node, |
6407 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
6408 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
6409 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
6410 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
6411 | endlink))))); |
6412 | ||
6413 | tree v2sf_ftype_4_v2sf | |
6414 | = build_function_type | |
3fdaa45a AH |
6415 | (opaque_V2SF_type_node, |
6416 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
6417 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
6418 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
6419 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
6420 | endlink))))); |
6421 | ||
6422 | tree int_ftype_int_v2si_v2si | |
6423 | = build_function_type | |
6424 | (integer_type_node, | |
6425 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
6426 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6427 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
6428 | endlink)))); |
6429 | ||
6430 | tree int_ftype_int_v2sf_v2sf | |
6431 | = build_function_type | |
6432 | (integer_type_node, | |
6433 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
6434 | tree_cons (NULL_TREE, opaque_V2SF_type_node, |
6435 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
6436 | endlink)))); |
6437 | ||
6438 | tree void_ftype_v2si_puint_int | |
6439 | = build_function_type (void_type_node, | |
3fdaa45a | 6440 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
6441 | tree_cons (NULL_TREE, puint_type_node, |
6442 | tree_cons (NULL_TREE, | |
6443 | integer_type_node, | |
6444 | endlink)))); | |
6445 | ||
6446 | tree void_ftype_v2si_puint_char | |
6447 | = build_function_type (void_type_node, | |
3fdaa45a | 6448 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
6449 | tree_cons (NULL_TREE, puint_type_node, |
6450 | tree_cons (NULL_TREE, | |
6451 | char_type_node, | |
6452 | endlink)))); | |
6453 | ||
6454 | tree void_ftype_v2si_pv2si_int | |
6455 | = build_function_type (void_type_node, | |
3fdaa45a | 6456 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 6457 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
6458 | tree_cons (NULL_TREE, |
6459 | integer_type_node, | |
6460 | endlink)))); | |
6461 | ||
6462 | tree void_ftype_v2si_pv2si_char | |
6463 | = build_function_type (void_type_node, | |
3fdaa45a | 6464 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 6465 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
6466 | tree_cons (NULL_TREE, |
6467 | char_type_node, | |
6468 | endlink)))); | |
6469 | ||
6470 | tree void_ftype_int | |
6471 | = build_function_type (void_type_node, | |
6472 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
6473 | ||
6474 | tree int_ftype_void | |
36e8d515 | 6475 | = build_function_type (integer_type_node, endlink); |
a3170dc6 AH |
6476 | |
6477 | tree v2si_ftype_pv2si_int | |
3fdaa45a | 6478 | = build_function_type (opaque_V2SI_type_node, |
6035d635 | 6479 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
6480 | tree_cons (NULL_TREE, integer_type_node, |
6481 | endlink))); | |
6482 | ||
6483 | tree v2si_ftype_puint_int | |
3fdaa45a | 6484 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
6485 | tree_cons (NULL_TREE, puint_type_node, |
6486 | tree_cons (NULL_TREE, integer_type_node, | |
6487 | endlink))); | |
6488 | ||
6489 | tree v2si_ftype_pushort_int | |
3fdaa45a | 6490 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
6491 | tree_cons (NULL_TREE, pushort_type_node, |
6492 | tree_cons (NULL_TREE, integer_type_node, | |
6493 | endlink))); | |
6494 | ||
00332c9f AH |
6495 | tree v2si_ftype_signed_char |
6496 | = build_function_type (opaque_V2SI_type_node, | |
6497 | tree_cons (NULL_TREE, signed_char_type_node, | |
6498 | endlink)); | |
6499 | ||
a3170dc6 AH |
6500 | /* The initialization of the simple binary and unary builtins is |
6501 | done in rs6000_common_init_builtins, but we have to enable the | |
6502 | mask bits here manually because we have run out of `target_flags' | |
6503 | bits. We really need to redesign this mask business. */ | |
6504 | ||
6505 | enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg, | |
6506 | ARRAY_SIZE (bdesc_2arg), | |
6507 | SPE_BUILTIN_EVADDW, | |
6508 | SPE_BUILTIN_EVXOR); | |
6509 | enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg, | |
6510 | ARRAY_SIZE (bdesc_1arg), | |
6511 | SPE_BUILTIN_EVABS, | |
6512 | SPE_BUILTIN_EVSUBFUSIAAW); | |
6513 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates, | |
6514 | ARRAY_SIZE (bdesc_spe_predicates), | |
6515 | SPE_BUILTIN_EVCMPEQ, | |
6516 | SPE_BUILTIN_EVFSTSTLT); | |
6517 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel, | |
6518 | ARRAY_SIZE (bdesc_spe_evsel), | |
6519 | SPE_BUILTIN_EVSEL_CMPGTS, | |
6520 | SPE_BUILTIN_EVSEL_FSTSTEQ); | |
6521 | ||
36252949 AH |
6522 | (*lang_hooks.decls.pushdecl) |
6523 | (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"), | |
6524 | opaque_V2SI_type_node)); | |
6525 | ||
a3170dc6 AH |
6526 | /* Initialize irregular SPE builtins. */ |
6527 | ||
6528 | def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR); | |
6529 | def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR); | |
6530 | def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX); | |
6531 | def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX); | |
6532 | def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX); | |
6533 | def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX); | |
6534 | def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX); | |
6535 | def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX); | |
6536 | def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX); | |
6537 | def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD); | |
6538 | def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH); | |
6539 | def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW); | |
6540 | def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE); | |
6541 | def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO); | |
6542 | def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE); | |
6543 | def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO); | |
00332c9f AH |
6544 | def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI); |
6545 | def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI); | |
a3170dc6 AH |
6546 | |
6547 | /* Loads. */ | |
6548 | def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX); | |
6549 | def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX); | |
6550 | def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX); | |
6551 | def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX); | |
6552 | def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX); | |
6553 | def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX); | |
6554 | def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX); | |
6555 | def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX); | |
6556 | def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX); | |
6557 | def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX); | |
6558 | def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX); | |
6559 | def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD); | |
6560 | def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW); | |
6561 | def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH); | |
6562 | def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT); | |
6563 | def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT); | |
6564 | def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT); | |
6565 | def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE); | |
6566 | def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS); | |
6567 | def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU); | |
6568 | def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT); | |
6569 | def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT); | |
6570 | ||
6571 | /* Predicates. */ | |
6572 | d = (struct builtin_description *) bdesc_spe_predicates; | |
6573 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++) | |
6574 | { | |
6575 | tree type; | |
6576 | ||
6577 | switch (insn_data[d->icode].operand[1].mode) | |
6578 | { | |
6579 | case V2SImode: | |
6580 | type = int_ftype_int_v2si_v2si; | |
6581 | break; | |
6582 | case V2SFmode: | |
6583 | type = int_ftype_int_v2sf_v2sf; | |
6584 | break; | |
6585 | default: | |
6586 | abort (); | |
6587 | } | |
6588 | ||
6589 | def_builtin (d->mask, d->name, type, d->code); | |
6590 | } | |
6591 | ||
6592 | /* Evsel predicates. */ | |
6593 | d = (struct builtin_description *) bdesc_spe_evsel; | |
6594 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++) | |
6595 | { | |
6596 | tree type; | |
6597 | ||
6598 | switch (insn_data[d->icode].operand[1].mode) | |
6599 | { | |
6600 | case V2SImode: | |
6601 | type = v2si_ftype_4_v2si; | |
6602 | break; | |
6603 | case V2SFmode: | |
6604 | type = v2sf_ftype_4_v2sf; | |
6605 | break; | |
6606 | default: | |
6607 | abort (); | |
6608 | } | |
6609 | ||
6610 | def_builtin (d->mask, d->name, type, d->code); | |
6611 | } | |
6612 | } | |
6613 | ||
6614 | static void | |
863d938c | 6615 | altivec_init_builtins (void) |
a3170dc6 AH |
6616 | { |
6617 | struct builtin_description *d; | |
6618 | struct builtin_description_predicates *dp; | |
6619 | size_t i; | |
6620 | tree pfloat_type_node = build_pointer_type (float_type_node); | |
6621 | tree pint_type_node = build_pointer_type (integer_type_node); | |
6622 | tree pshort_type_node = build_pointer_type (short_integer_type_node); | |
6623 | tree pchar_type_node = build_pointer_type (char_type_node); | |
6624 | ||
6625 | tree pvoid_type_node = build_pointer_type (void_type_node); | |
6626 | ||
0dbc3651 ZW |
6627 | tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST)); |
6628 | tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST)); | |
6629 | tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST)); | |
6630 | tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); | |
6631 | ||
6632 | tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST)); | |
6633 | ||
a3170dc6 AH |
6634 | tree int_ftype_int_v4si_v4si |
6635 | = build_function_type_list (integer_type_node, | |
6636 | integer_type_node, V4SI_type_node, | |
6637 | V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
6638 | tree v4sf_ftype_pcfloat |
6639 | = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE); | |
a3170dc6 | 6640 | tree void_ftype_pfloat_v4sf |
b4de2f7d | 6641 | = build_function_type_list (void_type_node, |
a3170dc6 | 6642 | pfloat_type_node, V4SF_type_node, NULL_TREE); |
0dbc3651 ZW |
6643 | tree v4si_ftype_pcint |
6644 | = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE); | |
6645 | tree void_ftype_pint_v4si | |
b4de2f7d AH |
6646 | = build_function_type_list (void_type_node, |
6647 | pint_type_node, V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
6648 | tree v8hi_ftype_pcshort |
6649 | = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE); | |
f18c054f | 6650 | tree void_ftype_pshort_v8hi |
b4de2f7d AH |
6651 | = build_function_type_list (void_type_node, |
6652 | pshort_type_node, V8HI_type_node, NULL_TREE); | |
0dbc3651 ZW |
6653 | tree v16qi_ftype_pcchar |
6654 | = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE); | |
f18c054f | 6655 | tree void_ftype_pchar_v16qi |
b4de2f7d AH |
6656 | = build_function_type_list (void_type_node, |
6657 | pchar_type_node, V16QI_type_node, NULL_TREE); | |
95385cbb | 6658 | tree void_ftype_v4si |
b4de2f7d | 6659 | = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE); |
a3170dc6 AH |
6660 | tree v8hi_ftype_void |
6661 | = build_function_type (V8HI_type_node, void_list_node); | |
6662 | tree void_ftype_void | |
6663 | = build_function_type (void_type_node, void_list_node); | |
6664 | tree void_ftype_qi | |
6665 | = build_function_type_list (void_type_node, char_type_node, NULL_TREE); | |
0dbc3651 | 6666 | |
b4a62fa0 | 6667 | tree v16qi_ftype_long_pcvoid |
a3170dc6 | 6668 | = build_function_type_list (V16QI_type_node, |
b4a62fa0 SB |
6669 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
6670 | tree v8hi_ftype_long_pcvoid | |
a3170dc6 | 6671 | = build_function_type_list (V8HI_type_node, |
b4a62fa0 SB |
6672 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
6673 | tree v4si_ftype_long_pcvoid | |
a3170dc6 | 6674 | = build_function_type_list (V4SI_type_node, |
b4a62fa0 | 6675 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
0dbc3651 | 6676 | |
b4a62fa0 | 6677 | tree void_ftype_v4si_long_pvoid |
b4de2f7d | 6678 | = build_function_type_list (void_type_node, |
b4a62fa0 | 6679 | V4SI_type_node, long_integer_type_node, |
b4de2f7d | 6680 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 6681 | tree void_ftype_v16qi_long_pvoid |
b4de2f7d | 6682 | = build_function_type_list (void_type_node, |
b4a62fa0 | 6683 | V16QI_type_node, long_integer_type_node, |
b4de2f7d | 6684 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 6685 | tree void_ftype_v8hi_long_pvoid |
b4de2f7d | 6686 | = build_function_type_list (void_type_node, |
b4a62fa0 | 6687 | V8HI_type_node, long_integer_type_node, |
b4de2f7d | 6688 | pvoid_type_node, NULL_TREE); |
a3170dc6 AH |
6689 | tree int_ftype_int_v8hi_v8hi |
6690 | = build_function_type_list (integer_type_node, | |
6691 | integer_type_node, V8HI_type_node, | |
6692 | V8HI_type_node, NULL_TREE); | |
6693 | tree int_ftype_int_v16qi_v16qi | |
6694 | = build_function_type_list (integer_type_node, | |
6695 | integer_type_node, V16QI_type_node, | |
6696 | V16QI_type_node, NULL_TREE); | |
6697 | tree int_ftype_int_v4sf_v4sf | |
6698 | = build_function_type_list (integer_type_node, | |
6699 | integer_type_node, V4SF_type_node, | |
6700 | V4SF_type_node, NULL_TREE); | |
6701 | tree v4si_ftype_v4si | |
6702 | = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE); | |
6703 | tree v8hi_ftype_v8hi | |
6704 | = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE); | |
6705 | tree v16qi_ftype_v16qi | |
6706 | = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE); | |
6707 | tree v4sf_ftype_v4sf | |
6708 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0dbc3651 | 6709 | tree void_ftype_pcvoid_int_char |
a3170dc6 | 6710 | = build_function_type_list (void_type_node, |
0dbc3651 | 6711 | pcvoid_type_node, integer_type_node, |
a3170dc6 | 6712 | char_type_node, NULL_TREE); |
0dbc3651 ZW |
6713 | |
6714 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat, | |
6715 | ALTIVEC_BUILTIN_LD_INTERNAL_4sf); | |
6716 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, | |
6717 | ALTIVEC_BUILTIN_ST_INTERNAL_4sf); | |
6718 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint, | |
6719 | ALTIVEC_BUILTIN_LD_INTERNAL_4si); | |
6720 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, | |
6721 | ALTIVEC_BUILTIN_ST_INTERNAL_4si); | |
6722 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort, | |
6723 | ALTIVEC_BUILTIN_LD_INTERNAL_8hi); | |
6724 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, | |
6725 | ALTIVEC_BUILTIN_ST_INTERNAL_8hi); | |
6726 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar, | |
6727 | ALTIVEC_BUILTIN_LD_INTERNAL_16qi); | |
6728 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, | |
6729 | ALTIVEC_BUILTIN_ST_INTERNAL_16qi); | |
a3170dc6 AH |
6730 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR); |
6731 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR); | |
6732 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL); | |
6733 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS); | |
b4a62fa0 SB |
6734 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL); |
6735 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR); | |
6736 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX); | |
6737 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX); | |
6738 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX); | |
6739 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL); | |
6740 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX); | |
6741 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX); | |
6742 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX); | |
6743 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL); | |
6744 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX); | |
6745 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX); | |
a3170dc6 AH |
6746 | |
6747 | /* Add the DST variants. */ | |
6748 | d = (struct builtin_description *) bdesc_dst; | |
6749 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
0dbc3651 | 6750 | def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code); |
a3170dc6 AH |
6751 | |
6752 | /* Initialize the predicates. */ | |
6753 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
6754 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) | |
6755 | { | |
6756 | enum machine_mode mode1; | |
6757 | tree type; | |
6758 | ||
6759 | mode1 = insn_data[dp->icode].operand[1].mode; | |
6760 | ||
6761 | switch (mode1) | |
6762 | { | |
6763 | case V4SImode: | |
6764 | type = int_ftype_int_v4si_v4si; | |
6765 | break; | |
6766 | case V8HImode: | |
6767 | type = int_ftype_int_v8hi_v8hi; | |
6768 | break; | |
6769 | case V16QImode: | |
6770 | type = int_ftype_int_v16qi_v16qi; | |
6771 | break; | |
6772 | case V4SFmode: | |
6773 | type = int_ftype_int_v4sf_v4sf; | |
6774 | break; | |
6775 | default: | |
6776 | abort (); | |
6777 | } | |
6778 | ||
6779 | def_builtin (dp->mask, dp->name, type, dp->code); | |
6780 | } | |
6781 | ||
6782 | /* Initialize the abs* operators. */ | |
6783 | d = (struct builtin_description *) bdesc_abs; | |
6784 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) | |
6785 | { | |
6786 | enum machine_mode mode0; | |
6787 | tree type; | |
6788 | ||
6789 | mode0 = insn_data[d->icode].operand[0].mode; | |
6790 | ||
6791 | switch (mode0) | |
6792 | { | |
6793 | case V4SImode: | |
6794 | type = v4si_ftype_v4si; | |
6795 | break; | |
6796 | case V8HImode: | |
6797 | type = v8hi_ftype_v8hi; | |
6798 | break; | |
6799 | case V16QImode: | |
6800 | type = v16qi_ftype_v16qi; | |
6801 | break; | |
6802 | case V4SFmode: | |
6803 | type = v4sf_ftype_v4sf; | |
6804 | break; | |
6805 | default: | |
6806 | abort (); | |
6807 | } | |
6808 | ||
6809 | def_builtin (d->mask, d->name, type, d->code); | |
6810 | } | |
6811 | } | |
6812 | ||
6813 | static void | |
863d938c | 6814 | rs6000_common_init_builtins (void) |
a3170dc6 AH |
6815 | { |
6816 | struct builtin_description *d; | |
6817 | size_t i; | |
6818 | ||
6819 | tree v4sf_ftype_v4sf_v4sf_v16qi | |
6820 | = build_function_type_list (V4SF_type_node, | |
6821 | V4SF_type_node, V4SF_type_node, | |
6822 | V16QI_type_node, NULL_TREE); | |
6823 | tree v4si_ftype_v4si_v4si_v16qi | |
6824 | = build_function_type_list (V4SI_type_node, | |
6825 | V4SI_type_node, V4SI_type_node, | |
6826 | V16QI_type_node, NULL_TREE); | |
6827 | tree v8hi_ftype_v8hi_v8hi_v16qi | |
6828 | = build_function_type_list (V8HI_type_node, | |
6829 | V8HI_type_node, V8HI_type_node, | |
6830 | V16QI_type_node, NULL_TREE); | |
6831 | tree v16qi_ftype_v16qi_v16qi_v16qi | |
6832 | = build_function_type_list (V16QI_type_node, | |
6833 | V16QI_type_node, V16QI_type_node, | |
6834 | V16QI_type_node, NULL_TREE); | |
6835 | tree v4si_ftype_char | |
6836 | = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE); | |
6837 | tree v8hi_ftype_char | |
6838 | = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE); | |
6839 | tree v16qi_ftype_char | |
6840 | = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE); | |
6841 | tree v8hi_ftype_v16qi | |
6842 | = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE); | |
6843 | tree v4sf_ftype_v4sf | |
6844 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
6845 | ||
6846 | tree v2si_ftype_v2si_v2si | |
2abe3e28 AH |
6847 | = build_function_type_list (opaque_V2SI_type_node, |
6848 | opaque_V2SI_type_node, | |
6849 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
6850 | |
6851 | tree v2sf_ftype_v2sf_v2sf | |
2abe3e28 AH |
6852 | = build_function_type_list (opaque_V2SF_type_node, |
6853 | opaque_V2SF_type_node, | |
6854 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
6855 | |
6856 | tree v2si_ftype_int_int | |
2abe3e28 | 6857 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
6858 | integer_type_node, integer_type_node, |
6859 | NULL_TREE); | |
6860 | ||
6861 | tree v2si_ftype_v2si | |
2abe3e28 AH |
6862 | = build_function_type_list (opaque_V2SI_type_node, |
6863 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
6864 | |
6865 | tree v2sf_ftype_v2sf | |
2abe3e28 AH |
6866 | = build_function_type_list (opaque_V2SF_type_node, |
6867 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
6868 | |
6869 | tree v2sf_ftype_v2si | |
2abe3e28 AH |
6870 | = build_function_type_list (opaque_V2SF_type_node, |
6871 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
6872 | |
6873 | tree v2si_ftype_v2sf | |
2abe3e28 AH |
6874 | = build_function_type_list (opaque_V2SI_type_node, |
6875 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
6876 | |
6877 | tree v2si_ftype_v2si_char | |
2abe3e28 AH |
6878 | = build_function_type_list (opaque_V2SI_type_node, |
6879 | opaque_V2SI_type_node, | |
6880 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
6881 | |
6882 | tree v2si_ftype_int_char | |
2abe3e28 | 6883 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
6884 | integer_type_node, char_type_node, NULL_TREE); |
6885 | ||
6886 | tree v2si_ftype_char | |
2abe3e28 AH |
6887 | = build_function_type_list (opaque_V2SI_type_node, |
6888 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
6889 | |
6890 | tree int_ftype_int_int | |
6891 | = build_function_type_list (integer_type_node, | |
6892 | integer_type_node, integer_type_node, | |
6893 | NULL_TREE); | |
95385cbb | 6894 | |
0ac081f6 | 6895 | tree v4si_ftype_v4si_v4si |
b4de2f7d AH |
6896 | = build_function_type_list (V4SI_type_node, |
6897 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
617e0e1d | 6898 | tree v4sf_ftype_v4si_char |
b4de2f7d AH |
6899 | = build_function_type_list (V4SF_type_node, |
6900 | V4SI_type_node, char_type_node, NULL_TREE); | |
617e0e1d | 6901 | tree v4si_ftype_v4sf_char |
b4de2f7d AH |
6902 | = build_function_type_list (V4SI_type_node, |
6903 | V4SF_type_node, char_type_node, NULL_TREE); | |
2212663f | 6904 | tree v4si_ftype_v4si_char |
b4de2f7d AH |
6905 | = build_function_type_list (V4SI_type_node, |
6906 | V4SI_type_node, char_type_node, NULL_TREE); | |
2212663f | 6907 | tree v8hi_ftype_v8hi_char |
b4de2f7d AH |
6908 | = build_function_type_list (V8HI_type_node, |
6909 | V8HI_type_node, char_type_node, NULL_TREE); | |
2212663f | 6910 | tree v16qi_ftype_v16qi_char |
b4de2f7d AH |
6911 | = build_function_type_list (V16QI_type_node, |
6912 | V16QI_type_node, char_type_node, NULL_TREE); | |
24408032 | 6913 | tree v16qi_ftype_v16qi_v16qi_char |
b4de2f7d AH |
6914 | = build_function_type_list (V16QI_type_node, |
6915 | V16QI_type_node, V16QI_type_node, | |
6916 | char_type_node, NULL_TREE); | |
24408032 | 6917 | tree v8hi_ftype_v8hi_v8hi_char |
b4de2f7d AH |
6918 | = build_function_type_list (V8HI_type_node, |
6919 | V8HI_type_node, V8HI_type_node, | |
6920 | char_type_node, NULL_TREE); | |
24408032 | 6921 | tree v4si_ftype_v4si_v4si_char |
b4de2f7d AH |
6922 | = build_function_type_list (V4SI_type_node, |
6923 | V4SI_type_node, V4SI_type_node, | |
6924 | char_type_node, NULL_TREE); | |
24408032 | 6925 | tree v4sf_ftype_v4sf_v4sf_char |
b4de2f7d AH |
6926 | = build_function_type_list (V4SF_type_node, |
6927 | V4SF_type_node, V4SF_type_node, | |
6928 | char_type_node, NULL_TREE); | |
0ac081f6 | 6929 | tree v4sf_ftype_v4sf_v4sf |
b4de2f7d AH |
6930 | = build_function_type_list (V4SF_type_node, |
6931 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
617e0e1d | 6932 | tree v4sf_ftype_v4sf_v4sf_v4si |
b4de2f7d AH |
6933 | = build_function_type_list (V4SF_type_node, |
6934 | V4SF_type_node, V4SF_type_node, | |
6935 | V4SI_type_node, NULL_TREE); | |
2212663f | 6936 | tree v4sf_ftype_v4sf_v4sf_v4sf |
b4de2f7d AH |
6937 | = build_function_type_list (V4SF_type_node, |
6938 | V4SF_type_node, V4SF_type_node, | |
6939 | V4SF_type_node, NULL_TREE); | |
617e0e1d | 6940 | tree v4si_ftype_v4si_v4si_v4si |
b4de2f7d AH |
6941 | = build_function_type_list (V4SI_type_node, |
6942 | V4SI_type_node, V4SI_type_node, | |
6943 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 6944 | tree v8hi_ftype_v8hi_v8hi |
b4de2f7d AH |
6945 | = build_function_type_list (V8HI_type_node, |
6946 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
2212663f | 6947 | tree v8hi_ftype_v8hi_v8hi_v8hi |
b4de2f7d AH |
6948 | = build_function_type_list (V8HI_type_node, |
6949 | V8HI_type_node, V8HI_type_node, | |
6950 | V8HI_type_node, NULL_TREE); | |
2212663f | 6951 | tree v4si_ftype_v8hi_v8hi_v4si |
b4de2f7d AH |
6952 | = build_function_type_list (V4SI_type_node, |
6953 | V8HI_type_node, V8HI_type_node, | |
6954 | V4SI_type_node, NULL_TREE); | |
2212663f | 6955 | tree v4si_ftype_v16qi_v16qi_v4si |
b4de2f7d AH |
6956 | = build_function_type_list (V4SI_type_node, |
6957 | V16QI_type_node, V16QI_type_node, | |
6958 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 6959 | tree v16qi_ftype_v16qi_v16qi |
b4de2f7d AH |
6960 | = build_function_type_list (V16QI_type_node, |
6961 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 6962 | tree v4si_ftype_v4sf_v4sf |
b4de2f7d AH |
6963 | = build_function_type_list (V4SI_type_node, |
6964 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0ac081f6 | 6965 | tree v8hi_ftype_v16qi_v16qi |
b4de2f7d AH |
6966 | = build_function_type_list (V8HI_type_node, |
6967 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 6968 | tree v4si_ftype_v8hi_v8hi |
b4de2f7d AH |
6969 | = build_function_type_list (V4SI_type_node, |
6970 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 6971 | tree v8hi_ftype_v4si_v4si |
b4de2f7d AH |
6972 | = build_function_type_list (V8HI_type_node, |
6973 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
0ac081f6 | 6974 | tree v16qi_ftype_v8hi_v8hi |
b4de2f7d AH |
6975 | = build_function_type_list (V16QI_type_node, |
6976 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 6977 | tree v4si_ftype_v16qi_v4si |
b4de2f7d AH |
6978 | = build_function_type_list (V4SI_type_node, |
6979 | V16QI_type_node, V4SI_type_node, NULL_TREE); | |
fa066a23 | 6980 | tree v4si_ftype_v16qi_v16qi |
b4de2f7d AH |
6981 | = build_function_type_list (V4SI_type_node, |
6982 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 6983 | tree v4si_ftype_v8hi_v4si |
b4de2f7d AH |
6984 | = build_function_type_list (V4SI_type_node, |
6985 | V8HI_type_node, V4SI_type_node, NULL_TREE); | |
a3170dc6 AH |
6986 | tree v4si_ftype_v8hi |
6987 | = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE); | |
6988 | tree int_ftype_v4si_v4si | |
6989 | = build_function_type_list (integer_type_node, | |
6990 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
6991 | tree int_ftype_v4sf_v4sf | |
6992 | = build_function_type_list (integer_type_node, | |
6993 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
6994 | tree int_ftype_v16qi_v16qi | |
6995 | = build_function_type_list (integer_type_node, | |
6996 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 6997 | tree int_ftype_v8hi_v8hi |
b4de2f7d AH |
6998 | = build_function_type_list (integer_type_node, |
6999 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7000 | |
6f317ef3 | 7001 | /* Add the simple ternary operators. */ |
2212663f | 7002 | d = (struct builtin_description *) bdesc_3arg; |
ca7558fc | 7003 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) |
2212663f DB |
7004 | { |
7005 | ||
7006 | enum machine_mode mode0, mode1, mode2, mode3; | |
7007 | tree type; | |
7008 | ||
0559cc77 | 7009 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
7010 | continue; |
7011 | ||
7012 | mode0 = insn_data[d->icode].operand[0].mode; | |
7013 | mode1 = insn_data[d->icode].operand[1].mode; | |
7014 | mode2 = insn_data[d->icode].operand[2].mode; | |
7015 | mode3 = insn_data[d->icode].operand[3].mode; | |
7016 | ||
7017 | /* When all four are of the same mode. */ | |
7018 | if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3) | |
7019 | { | |
7020 | switch (mode0) | |
7021 | { | |
617e0e1d DB |
7022 | case V4SImode: |
7023 | type = v4si_ftype_v4si_v4si_v4si; | |
7024 | break; | |
2212663f DB |
7025 | case V4SFmode: |
7026 | type = v4sf_ftype_v4sf_v4sf_v4sf; | |
7027 | break; | |
7028 | case V8HImode: | |
7029 | type = v8hi_ftype_v8hi_v8hi_v8hi; | |
7030 | break; | |
7031 | case V16QImode: | |
7032 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
7033 | break; | |
7034 | default: | |
7035 | abort(); | |
7036 | } | |
7037 | } | |
7038 | else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode) | |
7039 | { | |
7040 | switch (mode0) | |
7041 | { | |
7042 | case V4SImode: | |
7043 | type = v4si_ftype_v4si_v4si_v16qi; | |
7044 | break; | |
7045 | case V4SFmode: | |
7046 | type = v4sf_ftype_v4sf_v4sf_v16qi; | |
7047 | break; | |
7048 | case V8HImode: | |
7049 | type = v8hi_ftype_v8hi_v8hi_v16qi; | |
7050 | break; | |
7051 | case V16QImode: | |
7052 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
7053 | break; | |
7054 | default: | |
7055 | abort(); | |
7056 | } | |
7057 | } | |
7058 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode | |
7059 | && mode3 == V4SImode) | |
24408032 | 7060 | type = v4si_ftype_v16qi_v16qi_v4si; |
2212663f DB |
7061 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode |
7062 | && mode3 == V4SImode) | |
24408032 | 7063 | type = v4si_ftype_v8hi_v8hi_v4si; |
617e0e1d DB |
7064 | else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode |
7065 | && mode3 == V4SImode) | |
24408032 AH |
7066 | type = v4sf_ftype_v4sf_v4sf_v4si; |
7067 | ||
7068 | /* vchar, vchar, vchar, 4 bit literal. */ | |
7069 | else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0 | |
7070 | && mode3 == QImode) | |
7071 | type = v16qi_ftype_v16qi_v16qi_char; | |
7072 | ||
7073 | /* vshort, vshort, vshort, 4 bit literal. */ | |
7074 | else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0 | |
7075 | && mode3 == QImode) | |
7076 | type = v8hi_ftype_v8hi_v8hi_char; | |
7077 | ||
7078 | /* vint, vint, vint, 4 bit literal. */ | |
7079 | else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0 | |
7080 | && mode3 == QImode) | |
7081 | type = v4si_ftype_v4si_v4si_char; | |
7082 | ||
7083 | /* vfloat, vfloat, vfloat, 4 bit literal. */ | |
7084 | else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0 | |
7085 | && mode3 == QImode) | |
7086 | type = v4sf_ftype_v4sf_v4sf_char; | |
7087 | ||
2212663f DB |
7088 | else |
7089 | abort (); | |
7090 | ||
7091 | def_builtin (d->mask, d->name, type, d->code); | |
7092 | } | |
7093 | ||
0ac081f6 | 7094 | /* Add the simple binary operators. */ |
00b960c7 | 7095 | d = (struct builtin_description *) bdesc_2arg; |
ca7558fc | 7096 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
0ac081f6 AH |
7097 | { |
7098 | enum machine_mode mode0, mode1, mode2; | |
7099 | tree type; | |
7100 | ||
0559cc77 | 7101 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
0ac081f6 AH |
7102 | continue; |
7103 | ||
7104 | mode0 = insn_data[d->icode].operand[0].mode; | |
7105 | mode1 = insn_data[d->icode].operand[1].mode; | |
7106 | mode2 = insn_data[d->icode].operand[2].mode; | |
7107 | ||
7108 | /* When all three operands are of the same mode. */ | |
7109 | if (mode0 == mode1 && mode1 == mode2) | |
7110 | { | |
7111 | switch (mode0) | |
7112 | { | |
7113 | case V4SFmode: | |
7114 | type = v4sf_ftype_v4sf_v4sf; | |
7115 | break; | |
7116 | case V4SImode: | |
7117 | type = v4si_ftype_v4si_v4si; | |
7118 | break; | |
7119 | case V16QImode: | |
7120 | type = v16qi_ftype_v16qi_v16qi; | |
7121 | break; | |
7122 | case V8HImode: | |
7123 | type = v8hi_ftype_v8hi_v8hi; | |
7124 | break; | |
a3170dc6 AH |
7125 | case V2SImode: |
7126 | type = v2si_ftype_v2si_v2si; | |
7127 | break; | |
7128 | case V2SFmode: | |
7129 | type = v2sf_ftype_v2sf_v2sf; | |
7130 | break; | |
7131 | case SImode: | |
7132 | type = int_ftype_int_int; | |
7133 | break; | |
0ac081f6 AH |
7134 | default: |
7135 | abort (); | |
7136 | } | |
7137 | } | |
7138 | ||
7139 | /* A few other combos we really don't want to do manually. */ | |
7140 | ||
7141 | /* vint, vfloat, vfloat. */ | |
7142 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode) | |
7143 | type = v4si_ftype_v4sf_v4sf; | |
7144 | ||
7145 | /* vshort, vchar, vchar. */ | |
7146 | else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode) | |
7147 | type = v8hi_ftype_v16qi_v16qi; | |
7148 | ||
7149 | /* vint, vshort, vshort. */ | |
7150 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode) | |
7151 | type = v4si_ftype_v8hi_v8hi; | |
7152 | ||
7153 | /* vshort, vint, vint. */ | |
7154 | else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode) | |
7155 | type = v8hi_ftype_v4si_v4si; | |
7156 | ||
7157 | /* vchar, vshort, vshort. */ | |
7158 | else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode) | |
7159 | type = v16qi_ftype_v8hi_v8hi; | |
7160 | ||
7161 | /* vint, vchar, vint. */ | |
7162 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode) | |
7163 | type = v4si_ftype_v16qi_v4si; | |
7164 | ||
fa066a23 AH |
7165 | /* vint, vchar, vchar. */ |
7166 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode) | |
7167 | type = v4si_ftype_v16qi_v16qi; | |
7168 | ||
0ac081f6 AH |
7169 | /* vint, vshort, vint. */ |
7170 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode) | |
7171 | type = v4si_ftype_v8hi_v4si; | |
2212663f DB |
7172 | |
7173 | /* vint, vint, 5 bit literal. */ | |
7174 | else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode) | |
7175 | type = v4si_ftype_v4si_char; | |
7176 | ||
7177 | /* vshort, vshort, 5 bit literal. */ | |
7178 | else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode) | |
7179 | type = v8hi_ftype_v8hi_char; | |
7180 | ||
7181 | /* vchar, vchar, 5 bit literal. */ | |
7182 | else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode) | |
7183 | type = v16qi_ftype_v16qi_char; | |
0ac081f6 | 7184 | |
617e0e1d DB |
7185 | /* vfloat, vint, 5 bit literal. */ |
7186 | else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode) | |
7187 | type = v4sf_ftype_v4si_char; | |
7188 | ||
7189 | /* vint, vfloat, 5 bit literal. */ | |
7190 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode) | |
7191 | type = v4si_ftype_v4sf_char; | |
7192 | ||
a3170dc6 AH |
7193 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode) |
7194 | type = v2si_ftype_int_int; | |
7195 | ||
7196 | else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode) | |
7197 | type = v2si_ftype_v2si_char; | |
7198 | ||
7199 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode) | |
7200 | type = v2si_ftype_int_char; | |
7201 | ||
0ac081f6 AH |
7202 | /* int, x, x. */ |
7203 | else if (mode0 == SImode) | |
7204 | { | |
7205 | switch (mode1) | |
7206 | { | |
7207 | case V4SImode: | |
7208 | type = int_ftype_v4si_v4si; | |
7209 | break; | |
7210 | case V4SFmode: | |
7211 | type = int_ftype_v4sf_v4sf; | |
7212 | break; | |
7213 | case V16QImode: | |
7214 | type = int_ftype_v16qi_v16qi; | |
7215 | break; | |
7216 | case V8HImode: | |
7217 | type = int_ftype_v8hi_v8hi; | |
7218 | break; | |
7219 | default: | |
7220 | abort (); | |
7221 | } | |
7222 | } | |
7223 | ||
7224 | else | |
7225 | abort (); | |
7226 | ||
2212663f DB |
7227 | def_builtin (d->mask, d->name, type, d->code); |
7228 | } | |
24408032 | 7229 | |
2212663f DB |
7230 | /* Add the simple unary operators. */ |
7231 | d = (struct builtin_description *) bdesc_1arg; | |
ca7558fc | 7232 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
2212663f DB |
7233 | { |
7234 | enum machine_mode mode0, mode1; | |
7235 | tree type; | |
7236 | ||
0559cc77 | 7237 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
7238 | continue; |
7239 | ||
7240 | mode0 = insn_data[d->icode].operand[0].mode; | |
7241 | mode1 = insn_data[d->icode].operand[1].mode; | |
7242 | ||
7243 | if (mode0 == V4SImode && mode1 == QImode) | |
7244 | type = v4si_ftype_char; | |
7245 | else if (mode0 == V8HImode && mode1 == QImode) | |
7246 | type = v8hi_ftype_char; | |
7247 | else if (mode0 == V16QImode && mode1 == QImode) | |
7248 | type = v16qi_ftype_char; | |
617e0e1d DB |
7249 | else if (mode0 == V4SFmode && mode1 == V4SFmode) |
7250 | type = v4sf_ftype_v4sf; | |
20e26713 AH |
7251 | else if (mode0 == V8HImode && mode1 == V16QImode) |
7252 | type = v8hi_ftype_v16qi; | |
7253 | else if (mode0 == V4SImode && mode1 == V8HImode) | |
7254 | type = v4si_ftype_v8hi; | |
a3170dc6 AH |
7255 | else if (mode0 == V2SImode && mode1 == V2SImode) |
7256 | type = v2si_ftype_v2si; | |
7257 | else if (mode0 == V2SFmode && mode1 == V2SFmode) | |
7258 | type = v2sf_ftype_v2sf; | |
7259 | else if (mode0 == V2SFmode && mode1 == V2SImode) | |
7260 | type = v2sf_ftype_v2si; | |
7261 | else if (mode0 == V2SImode && mode1 == V2SFmode) | |
7262 | type = v2si_ftype_v2sf; | |
7263 | else if (mode0 == V2SImode && mode1 == QImode) | |
7264 | type = v2si_ftype_char; | |
2212663f DB |
7265 | else |
7266 | abort (); | |
7267 | ||
0ac081f6 AH |
7268 | def_builtin (d->mask, d->name, type, d->code); |
7269 | } | |
7270 | } | |
7271 | ||
c15c90bb ZW |
7272 | static void |
7273 | rs6000_init_libfuncs (void) | |
7274 | { | |
7275 | if (!TARGET_HARD_FLOAT) | |
7276 | return; | |
7277 | ||
c9034561 | 7278 | if (DEFAULT_ABI != ABI_V4) |
c15c90bb | 7279 | { |
c9034561 | 7280 | if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC) |
c15c90bb | 7281 | { |
c9034561 | 7282 | /* AIX library routines for float->int conversion. */ |
85363ca0 ZW |
7283 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc"); |
7284 | set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc"); | |
c15c90bb ZW |
7285 | } |
7286 | ||
c9034561 | 7287 | /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
7288 | set_optab_libfunc (add_optab, TFmode, "_xlqadd"); |
7289 | set_optab_libfunc (sub_optab, TFmode, "_xlqsub"); | |
7290 | set_optab_libfunc (smul_optab, TFmode, "_xlqmul"); | |
7291 | set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv"); | |
7292 | } | |
c9034561 | 7293 | else |
c15c90bb | 7294 | { |
c9034561 | 7295 | /* 32-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
7296 | |
7297 | set_optab_libfunc (add_optab, TFmode, "_q_add"); | |
7298 | set_optab_libfunc (sub_optab, TFmode, "_q_sub"); | |
7299 | set_optab_libfunc (neg_optab, TFmode, "_q_neg"); | |
7300 | set_optab_libfunc (smul_optab, TFmode, "_q_mul"); | |
7301 | set_optab_libfunc (sdiv_optab, TFmode, "_q_div"); | |
7302 | if (TARGET_PPC_GPOPT || TARGET_POWER2) | |
7303 | set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt"); | |
7304 | ||
c9034561 ZW |
7305 | set_optab_libfunc (eq_optab, TFmode, "_q_feq"); |
7306 | set_optab_libfunc (ne_optab, TFmode, "_q_fne"); | |
7307 | set_optab_libfunc (gt_optab, TFmode, "_q_fgt"); | |
7308 | set_optab_libfunc (ge_optab, TFmode, "_q_fge"); | |
7309 | set_optab_libfunc (lt_optab, TFmode, "_q_flt"); | |
7310 | set_optab_libfunc (le_optab, TFmode, "_q_fle"); | |
7311 | ||
85363ca0 ZW |
7312 | set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq"); |
7313 | set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq"); | |
7314 | set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos"); | |
7315 | set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod"); | |
7316 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi"); | |
7317 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou"); | |
7318 | set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq"); | |
c15c90bb ZW |
7319 | } |
7320 | } | |
35aff10b | 7321 | \f |
7e69e155 MM |
7322 | /* Expand a block move operation, and return 1 if successful. Return 0 |
7323 | if we should let the compiler generate normal code. | |
7324 | ||
7325 | operands[0] is the destination | |
7326 | operands[1] is the source | |
7327 | operands[2] is the length | |
7328 | operands[3] is the alignment */ | |
7329 | ||
3933e0e1 MM |
7330 | #define MAX_MOVE_REG 4 |
7331 | ||
7e69e155 | 7332 | int |
a2369ed3 | 7333 | expand_block_move (rtx operands[]) |
7e69e155 | 7334 | { |
b6c9286a MM |
7335 | rtx orig_dest = operands[0]; |
7336 | rtx orig_src = operands[1]; | |
7e69e155 | 7337 | rtx bytes_rtx = operands[2]; |
7e69e155 | 7338 | rtx align_rtx = operands[3]; |
3933e0e1 | 7339 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 7340 | int align; |
3933e0e1 MM |
7341 | int bytes; |
7342 | int offset; | |
7e69e155 | 7343 | int move_bytes; |
cabfd258 GK |
7344 | rtx stores[MAX_MOVE_REG]; |
7345 | int num_reg = 0; | |
7e69e155 | 7346 | |
3933e0e1 | 7347 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 7348 | if (! constp) |
3933e0e1 MM |
7349 | return 0; |
7350 | ||
5ee95df6 FS |
7351 | /* If this is not a fixed size alignment, abort */ |
7352 | if (GET_CODE (align_rtx) != CONST_INT) | |
7353 | abort (); | |
7354 | align = INTVAL (align_rtx); | |
7355 | ||
7e69e155 | 7356 | /* Anything to move? */ |
3933e0e1 MM |
7357 | bytes = INTVAL (bytes_rtx); |
7358 | if (bytes <= 0) | |
7e69e155 MM |
7359 | return 1; |
7360 | ||
ea9982a8 | 7361 | /* store_one_arg depends on expand_block_move to handle at least the size of |
6f317ef3 | 7362 | reg_parm_stack_space. */ |
ea9982a8 | 7363 | if (bytes > (TARGET_POWERPC64 ? 64 : 32)) |
7e69e155 MM |
7364 | return 0; |
7365 | ||
cabfd258 | 7366 | for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes) |
7e69e155 | 7367 | { |
cabfd258 | 7368 | union { |
a2369ed3 DJ |
7369 | rtx (*movstrsi) (rtx, rtx, rtx, rtx); |
7370 | rtx (*mov) (rtx, rtx); | |
cabfd258 GK |
7371 | } gen_func; |
7372 | enum machine_mode mode = BLKmode; | |
7373 | rtx src, dest; | |
7374 | ||
7375 | if (TARGET_STRING | |
7376 | && bytes > 24 /* move up to 32 bytes at a time */ | |
7377 | && ! fixed_regs[5] | |
7378 | && ! fixed_regs[6] | |
7379 | && ! fixed_regs[7] | |
7380 | && ! fixed_regs[8] | |
7381 | && ! fixed_regs[9] | |
7382 | && ! fixed_regs[10] | |
7383 | && ! fixed_regs[11] | |
7384 | && ! fixed_regs[12]) | |
7e69e155 | 7385 | { |
cabfd258 GK |
7386 | move_bytes = (bytes > 32) ? 32 : bytes; |
7387 | gen_func.movstrsi = gen_movstrsi_8reg; | |
7388 | } | |
7389 | else if (TARGET_STRING | |
7390 | && bytes > 16 /* move up to 24 bytes at a time */ | |
7391 | && ! fixed_regs[5] | |
7392 | && ! fixed_regs[6] | |
7393 | && ! fixed_regs[7] | |
7394 | && ! fixed_regs[8] | |
7395 | && ! fixed_regs[9] | |
7396 | && ! fixed_regs[10]) | |
7397 | { | |
7398 | move_bytes = (bytes > 24) ? 24 : bytes; | |
7399 | gen_func.movstrsi = gen_movstrsi_6reg; | |
7400 | } | |
7401 | else if (TARGET_STRING | |
7402 | && bytes > 8 /* move up to 16 bytes at a time */ | |
7403 | && ! fixed_regs[5] | |
7404 | && ! fixed_regs[6] | |
7405 | && ! fixed_regs[7] | |
7406 | && ! fixed_regs[8]) | |
7407 | { | |
7408 | move_bytes = (bytes > 16) ? 16 : bytes; | |
7409 | gen_func.movstrsi = gen_movstrsi_4reg; | |
7410 | } | |
7411 | else if (bytes >= 8 && TARGET_POWERPC64 | |
7412 | /* 64-bit loads and stores require word-aligned | |
7413 | displacements. */ | |
7414 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) | |
7415 | { | |
7416 | move_bytes = 8; | |
7417 | mode = DImode; | |
7418 | gen_func.mov = gen_movdi; | |
7419 | } | |
7420 | else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64) | |
7421 | { /* move up to 8 bytes at a time */ | |
7422 | move_bytes = (bytes > 8) ? 8 : bytes; | |
7423 | gen_func.movstrsi = gen_movstrsi_2reg; | |
7424 | } | |
7425 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) | |
7426 | { /* move 4 bytes */ | |
7427 | move_bytes = 4; | |
7428 | mode = SImode; | |
7429 | gen_func.mov = gen_movsi; | |
7430 | } | |
7431 | else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT)) | |
7432 | { /* move 2 bytes */ | |
7433 | move_bytes = 2; | |
7434 | mode = HImode; | |
7435 | gen_func.mov = gen_movhi; | |
7436 | } | |
7437 | else if (TARGET_STRING && bytes > 1) | |
7438 | { /* move up to 4 bytes at a time */ | |
7439 | move_bytes = (bytes > 4) ? 4 : bytes; | |
7440 | gen_func.movstrsi = gen_movstrsi_1reg; | |
7441 | } | |
7442 | else /* move 1 byte at a time */ | |
7443 | { | |
7444 | move_bytes = 1; | |
7445 | mode = QImode; | |
7446 | gen_func.mov = gen_movqi; | |
7447 | } | |
7448 | ||
7449 | src = adjust_address (orig_src, mode, offset); | |
7450 | dest = adjust_address (orig_dest, mode, offset); | |
7451 | ||
7452 | if (mode != BLKmode) | |
7453 | { | |
7454 | rtx tmp_reg = gen_reg_rtx (mode); | |
7455 | ||
7456 | emit_insn ((*gen_func.mov) (tmp_reg, src)); | |
7457 | stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg); | |
4c64a852 | 7458 | } |
3933e0e1 | 7459 | |
cabfd258 GK |
7460 | if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes) |
7461 | { | |
7462 | int i; | |
7463 | for (i = 0; i < num_reg; i++) | |
7464 | emit_insn (stores[i]); | |
7465 | num_reg = 0; | |
7466 | } | |
35aff10b | 7467 | |
cabfd258 | 7468 | if (mode == BLKmode) |
7e69e155 | 7469 | { |
cabfd258 GK |
7470 | /* Move the address into scratch registers. The movstrsi |
7471 | patterns require zero offset. */ | |
7472 | if (!REG_P (XEXP (src, 0))) | |
b6c9286a | 7473 | { |
cabfd258 GK |
7474 | rtx src_reg = copy_addr_to_reg (XEXP (src, 0)); |
7475 | src = replace_equiv_address (src, src_reg); | |
b6c9286a | 7476 | } |
cabfd258 GK |
7477 | set_mem_size (src, GEN_INT (move_bytes)); |
7478 | ||
7479 | if (!REG_P (XEXP (dest, 0))) | |
3933e0e1 | 7480 | { |
cabfd258 GK |
7481 | rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0)); |
7482 | dest = replace_equiv_address (dest, dest_reg); | |
7e69e155 | 7483 | } |
cabfd258 GK |
7484 | set_mem_size (dest, GEN_INT (move_bytes)); |
7485 | ||
7486 | emit_insn ((*gen_func.movstrsi) (dest, src, | |
7487 | GEN_INT (move_bytes & 31), | |
7488 | align_rtx)); | |
7e69e155 | 7489 | } |
7e69e155 MM |
7490 | } |
7491 | ||
7492 | return 1; | |
7493 | } | |
7494 | ||
9878760c RK |
7495 | \f |
7496 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
7497 | PARALLEL and the first section will be tested. */ | |
7498 | ||
7499 | int | |
a2369ed3 | 7500 | load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
7501 | { |
7502 | int count = XVECLEN (op, 0); | |
e2c953b6 | 7503 | unsigned int dest_regno; |
9878760c RK |
7504 | rtx src_addr; |
7505 | int i; | |
7506 | ||
7507 | /* Perform a quick check so we don't blow up below. */ | |
7508 | if (count <= 1 | |
7509 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7510 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
7511 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
7512 | return 0; | |
7513 | ||
7514 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
7515 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
7516 | ||
7517 | for (i = 1; i < count; i++) | |
7518 | { | |
7519 | rtx elt = XVECEXP (op, 0, i); | |
7520 | ||
7521 | if (GET_CODE (elt) != SET | |
7522 | || GET_CODE (SET_DEST (elt)) != REG | |
7523 | || GET_MODE (SET_DEST (elt)) != SImode | |
7524 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
7525 | || GET_CODE (SET_SRC (elt)) != MEM | |
7526 | || GET_MODE (SET_SRC (elt)) != SImode | |
7527 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
7528 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
7529 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
7530 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
7531 | return 0; | |
7532 | } | |
7533 | ||
7534 | return 1; | |
7535 | } | |
7536 | ||
7537 | /* Similar, but tests for store multiple. Here, the second vector element | |
7538 | is a CLOBBER. It will be tested later. */ | |
7539 | ||
7540 | int | |
a2369ed3 | 7541 | store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
7542 | { |
7543 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 7544 | unsigned int src_regno; |
9878760c RK |
7545 | rtx dest_addr; |
7546 | int i; | |
7547 | ||
7548 | /* Perform a quick check so we don't blow up below. */ | |
7549 | if (count <= 1 | |
7550 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7551 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
7552 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
7553 | return 0; | |
7554 | ||
7555 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
7556 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
7557 | ||
7558 | for (i = 1; i < count; i++) | |
7559 | { | |
7560 | rtx elt = XVECEXP (op, 0, i + 1); | |
7561 | ||
7562 | if (GET_CODE (elt) != SET | |
7563 | || GET_CODE (SET_SRC (elt)) != REG | |
7564 | || GET_MODE (SET_SRC (elt)) != SImode | |
7565 | || REGNO (SET_SRC (elt)) != src_regno + i | |
7566 | || GET_CODE (SET_DEST (elt)) != MEM | |
7567 | || GET_MODE (SET_DEST (elt)) != SImode | |
7568 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
7569 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
7570 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
7571 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
7572 | return 0; | |
7573 | } | |
7574 | ||
7575 | return 1; | |
7576 | } | |
9ebbca7d | 7577 | |
9caa3eb2 DE |
7578 | /* Return a string to perform a load_multiple operation. |
7579 | operands[0] is the vector. | |
7580 | operands[1] is the source address. | |
7581 | operands[2] is the first destination register. */ | |
7582 | ||
7583 | const char * | |
a2369ed3 | 7584 | rs6000_output_load_multiple (rtx operands[3]) |
9caa3eb2 DE |
7585 | { |
7586 | /* We have to handle the case where the pseudo used to contain the address | |
7587 | is assigned to one of the output registers. */ | |
7588 | int i, j; | |
7589 | int words = XVECLEN (operands[0], 0); | |
7590 | rtx xop[10]; | |
7591 | ||
7592 | if (XVECLEN (operands[0], 0) == 1) | |
7593 | return "{l|lwz} %2,0(%1)"; | |
7594 | ||
7595 | for (i = 0; i < words; i++) | |
7596 | if (refers_to_regno_p (REGNO (operands[2]) + i, | |
7597 | REGNO (operands[2]) + i + 1, operands[1], 0)) | |
7598 | { | |
7599 | if (i == words-1) | |
7600 | { | |
7601 | xop[0] = GEN_INT (4 * (words-1)); | |
7602 | xop[1] = operands[1]; | |
7603 | xop[2] = operands[2]; | |
7604 | output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop); | |
7605 | return ""; | |
7606 | } | |
7607 | else if (i == 0) | |
7608 | { | |
7609 | xop[0] = GEN_INT (4 * (words-1)); | |
7610 | xop[1] = operands[1]; | |
7611 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
7612 | 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); | |
7613 | return ""; | |
7614 | } | |
7615 | else | |
7616 | { | |
7617 | for (j = 0; j < words; j++) | |
7618 | if (j != i) | |
7619 | { | |
7620 | xop[0] = GEN_INT (j * 4); | |
7621 | xop[1] = operands[1]; | |
7622 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j); | |
7623 | output_asm_insn ("{l|lwz} %2,%0(%1)", xop); | |
7624 | } | |
7625 | xop[0] = GEN_INT (i * 4); | |
7626 | xop[1] = operands[1]; | |
7627 | output_asm_insn ("{l|lwz} %1,%0(%1)", xop); | |
7628 | return ""; | |
7629 | } | |
7630 | } | |
7631 | ||
7632 | return "{lsi|lswi} %2,%1,%N0"; | |
7633 | } | |
7634 | ||
00b960c7 AH |
7635 | /* Return 1 for a parallel vrsave operation. */ |
7636 | ||
7637 | int | |
a2369ed3 | 7638 | vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
00b960c7 AH |
7639 | { |
7640 | int count = XVECLEN (op, 0); | |
7641 | unsigned int dest_regno, src_regno; | |
7642 | int i; | |
7643 | ||
7644 | if (count <= 1 | |
7645 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7646 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
a004eb82 | 7647 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE) |
00b960c7 AH |
7648 | return 0; |
7649 | ||
7650 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
7651 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
7652 | ||
7653 | if (dest_regno != VRSAVE_REGNO | |
7654 | && src_regno != VRSAVE_REGNO) | |
7655 | return 0; | |
7656 | ||
7657 | for (i = 1; i < count; i++) | |
7658 | { | |
7659 | rtx elt = XVECEXP (op, 0, i); | |
7660 | ||
9aa86737 AH |
7661 | if (GET_CODE (elt) != CLOBBER |
7662 | && GET_CODE (elt) != SET) | |
00b960c7 AH |
7663 | return 0; |
7664 | } | |
7665 | ||
7666 | return 1; | |
7667 | } | |
7668 | ||
2c4a9cff DE |
7669 | /* Return 1 for an PARALLEL suitable for mfcr. */ |
7670 | ||
7671 | int | |
a2369ed3 | 7672 | mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2c4a9cff DE |
7673 | { |
7674 | int count = XVECLEN (op, 0); | |
7675 | int i; | |
7676 | ||
7677 | /* Perform a quick check so we don't blow up below. */ | |
7678 | if (count < 1 | |
7679 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7680 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
7681 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
7682 | return 0; | |
7683 | ||
7684 | for (i = 0; i < count; i++) | |
7685 | { | |
7686 | rtx exp = XVECEXP (op, 0, i); | |
7687 | rtx unspec; | |
7688 | int maskval; | |
7689 | rtx src_reg; | |
7690 | ||
7691 | src_reg = XVECEXP (SET_SRC (exp), 0, 0); | |
7692 | ||
7693 | if (GET_CODE (src_reg) != REG | |
7694 | || GET_MODE (src_reg) != CCmode | |
7695 | || ! CR_REGNO_P (REGNO (src_reg))) | |
7696 | return 0; | |
7697 | ||
7698 | if (GET_CODE (exp) != SET | |
7699 | || GET_CODE (SET_DEST (exp)) != REG | |
7700 | || GET_MODE (SET_DEST (exp)) != SImode | |
7701 | || ! INT_REGNO_P (REGNO (SET_DEST (exp)))) | |
7702 | return 0; | |
7703 | unspec = SET_SRC (exp); | |
7704 | maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg)); | |
7705 | ||
7706 | if (GET_CODE (unspec) != UNSPEC | |
7707 | || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR | |
7708 | || XVECLEN (unspec, 0) != 2 | |
7709 | || XVECEXP (unspec, 0, 0) != src_reg | |
7710 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
7711 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
7712 | return 0; | |
7713 | } | |
7714 | return 1; | |
7715 | } | |
7716 | ||
a4f6c312 | 7717 | /* Return 1 for an PARALLEL suitable for mtcrf. */ |
9ebbca7d GK |
7718 | |
7719 | int | |
a2369ed3 | 7720 | mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
7721 | { |
7722 | int count = XVECLEN (op, 0); | |
7723 | int i; | |
9ebbca7d GK |
7724 | rtx src_reg; |
7725 | ||
7726 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
7727 | if (count < 1 |
7728 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7729 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
7730 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 7731 | return 0; |
e35b9579 | 7732 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
9ebbca7d GK |
7733 | |
7734 | if (GET_CODE (src_reg) != REG | |
7735 | || GET_MODE (src_reg) != SImode | |
7736 | || ! INT_REGNO_P (REGNO (src_reg))) | |
7737 | return 0; | |
7738 | ||
e35b9579 | 7739 | for (i = 0; i < count; i++) |
9ebbca7d GK |
7740 | { |
7741 | rtx exp = XVECEXP (op, 0, i); | |
7742 | rtx unspec; | |
7743 | int maskval; | |
7744 | ||
7745 | if (GET_CODE (exp) != SET | |
7746 | || GET_CODE (SET_DEST (exp)) != REG | |
7747 | || GET_MODE (SET_DEST (exp)) != CCmode | |
7748 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
7749 | return 0; | |
7750 | unspec = SET_SRC (exp); | |
7751 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
9ebbca7d GK |
7752 | |
7753 | if (GET_CODE (unspec) != UNSPEC | |
615158e2 | 7754 | || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR |
9ebbca7d GK |
7755 | || XVECLEN (unspec, 0) != 2 |
7756 | || XVECEXP (unspec, 0, 0) != src_reg | |
7757 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
7758 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
7759 | return 0; | |
7760 | } | |
e35b9579 | 7761 | return 1; |
9ebbca7d GK |
7762 | } |
7763 | ||
a4f6c312 | 7764 | /* Return 1 for an PARALLEL suitable for lmw. */ |
9ebbca7d GK |
7765 | |
7766 | int | |
a2369ed3 | 7767 | lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
7768 | { |
7769 | int count = XVECLEN (op, 0); | |
e2c953b6 | 7770 | unsigned int dest_regno; |
9ebbca7d | 7771 | rtx src_addr; |
e2c953b6 | 7772 | unsigned int base_regno; |
9ebbca7d GK |
7773 | HOST_WIDE_INT offset; |
7774 | int i; | |
7775 | ||
7776 | /* Perform a quick check so we don't blow up below. */ | |
7777 | if (count <= 1 | |
7778 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7779 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
7780 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
7781 | return 0; | |
7782 | ||
7783 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
7784 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
7785 | ||
7786 | if (dest_regno > 31 | |
e2c953b6 | 7787 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
7788 | return 0; |
7789 | ||
4d588c14 | 7790 | if (legitimate_indirect_address_p (src_addr, 0)) |
9ebbca7d GK |
7791 | { |
7792 | offset = 0; | |
7793 | base_regno = REGNO (src_addr); | |
7794 | if (base_regno == 0) | |
7795 | return 0; | |
7796 | } | |
4d588c14 | 7797 | else if (legitimate_offset_address_p (SImode, src_addr, 0)) |
9ebbca7d GK |
7798 | { |
7799 | offset = INTVAL (XEXP (src_addr, 1)); | |
7800 | base_regno = REGNO (XEXP (src_addr, 0)); | |
7801 | } | |
7802 | else | |
7803 | return 0; | |
7804 | ||
7805 | for (i = 0; i < count; i++) | |
7806 | { | |
7807 | rtx elt = XVECEXP (op, 0, i); | |
7808 | rtx newaddr; | |
7809 | rtx addr_reg; | |
7810 | HOST_WIDE_INT newoffset; | |
7811 | ||
7812 | if (GET_CODE (elt) != SET | |
7813 | || GET_CODE (SET_DEST (elt)) != REG | |
7814 | || GET_MODE (SET_DEST (elt)) != SImode | |
7815 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
7816 | || GET_CODE (SET_SRC (elt)) != MEM | |
7817 | || GET_MODE (SET_SRC (elt)) != SImode) | |
7818 | return 0; | |
7819 | newaddr = XEXP (SET_SRC (elt), 0); | |
4d588c14 | 7820 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
7821 | { |
7822 | newoffset = 0; | |
7823 | addr_reg = newaddr; | |
7824 | } | |
4d588c14 | 7825 | else if (legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
7826 | { |
7827 | addr_reg = XEXP (newaddr, 0); | |
7828 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
7829 | } | |
7830 | else | |
7831 | return 0; | |
7832 | if (REGNO (addr_reg) != base_regno | |
7833 | || newoffset != offset + 4 * i) | |
7834 | return 0; | |
7835 | } | |
7836 | ||
7837 | return 1; | |
7838 | } | |
7839 | ||
a4f6c312 | 7840 | /* Return 1 for an PARALLEL suitable for stmw. */ |
9ebbca7d GK |
7841 | |
7842 | int | |
a2369ed3 | 7843 | stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
7844 | { |
7845 | int count = XVECLEN (op, 0); | |
e2c953b6 | 7846 | unsigned int src_regno; |
9ebbca7d | 7847 | rtx dest_addr; |
e2c953b6 | 7848 | unsigned int base_regno; |
9ebbca7d GK |
7849 | HOST_WIDE_INT offset; |
7850 | int i; | |
7851 | ||
7852 | /* Perform a quick check so we don't blow up below. */ | |
7853 | if (count <= 1 | |
7854 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
7855 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
7856 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
7857 | return 0; | |
7858 | ||
7859 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
7860 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
7861 | ||
7862 | if (src_regno > 31 | |
e2c953b6 | 7863 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
7864 | return 0; |
7865 | ||
4d588c14 | 7866 | if (legitimate_indirect_address_p (dest_addr, 0)) |
9ebbca7d GK |
7867 | { |
7868 | offset = 0; | |
7869 | base_regno = REGNO (dest_addr); | |
7870 | if (base_regno == 0) | |
7871 | return 0; | |
7872 | } | |
4d588c14 | 7873 | else if (legitimate_offset_address_p (SImode, dest_addr, 0)) |
9ebbca7d GK |
7874 | { |
7875 | offset = INTVAL (XEXP (dest_addr, 1)); | |
7876 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
7877 | } | |
7878 | else | |
7879 | return 0; | |
7880 | ||
7881 | for (i = 0; i < count; i++) | |
7882 | { | |
7883 | rtx elt = XVECEXP (op, 0, i); | |
7884 | rtx newaddr; | |
7885 | rtx addr_reg; | |
7886 | HOST_WIDE_INT newoffset; | |
7887 | ||
7888 | if (GET_CODE (elt) != SET | |
7889 | || GET_CODE (SET_SRC (elt)) != REG | |
7890 | || GET_MODE (SET_SRC (elt)) != SImode | |
7891 | || REGNO (SET_SRC (elt)) != src_regno + i | |
7892 | || GET_CODE (SET_DEST (elt)) != MEM | |
7893 | || GET_MODE (SET_DEST (elt)) != SImode) | |
7894 | return 0; | |
7895 | newaddr = XEXP (SET_DEST (elt), 0); | |
4d588c14 | 7896 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
7897 | { |
7898 | newoffset = 0; | |
7899 | addr_reg = newaddr; | |
7900 | } | |
4d588c14 | 7901 | else if (legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
7902 | { |
7903 | addr_reg = XEXP (newaddr, 0); | |
7904 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
7905 | } | |
7906 | else | |
7907 | return 0; | |
7908 | if (REGNO (addr_reg) != base_regno | |
7909 | || newoffset != offset + 4 * i) | |
7910 | return 0; | |
7911 | } | |
7912 | ||
7913 | return 1; | |
7914 | } | |
9878760c | 7915 | \f |
a4f6c312 SS |
7916 | /* A validation routine: say whether CODE, a condition code, and MODE |
7917 | match. The other alternatives either don't make sense or should | |
7918 | never be generated. */ | |
39a10a29 | 7919 | |
39a10a29 | 7920 | static void |
a2369ed3 | 7921 | validate_condition_mode (enum rtx_code code, enum machine_mode mode) |
39a10a29 GK |
7922 | { |
7923 | if (GET_RTX_CLASS (code) != '<' | |
7924 | || GET_MODE_CLASS (mode) != MODE_CC) | |
7925 | abort (); | |
7926 | ||
7927 | /* These don't make sense. */ | |
7928 | if ((code == GT || code == LT || code == GE || code == LE) | |
7929 | && mode == CCUNSmode) | |
7930 | abort (); | |
7931 | ||
7932 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
7933 | && mode != CCUNSmode) | |
7934 | abort (); | |
7935 | ||
7936 | if (mode != CCFPmode | |
7937 | && (code == ORDERED || code == UNORDERED | |
7938 | || code == UNEQ || code == LTGT | |
7939 | || code == UNGT || code == UNLT | |
7940 | || code == UNGE || code == UNLE)) | |
a4f6c312 | 7941 | abort (); |
39a10a29 | 7942 | |
de6c5979 | 7943 | /* These should never be generated except for |
bc9ec0e0 | 7944 | flag_finite_math_only. */ |
39a10a29 | 7945 | if (mode == CCFPmode |
ad72b533 | 7946 | && ! flag_finite_math_only |
39a10a29 GK |
7947 | && (code == LE || code == GE |
7948 | || code == UNEQ || code == LTGT | |
7949 | || code == UNGT || code == UNLT)) | |
7950 | abort (); | |
7951 | ||
7952 | /* These are invalid; the information is not there. */ | |
7953 | if (mode == CCEQmode | |
7954 | && code != EQ && code != NE) | |
7955 | abort (); | |
7956 | } | |
7957 | ||
9878760c RK |
7958 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
7959 | We only check the opcode against the mode of the CC value here. */ | |
7960 | ||
7961 | int | |
a2369ed3 | 7962 | branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
7963 | { |
7964 | enum rtx_code code = GET_CODE (op); | |
7965 | enum machine_mode cc_mode; | |
7966 | ||
7967 | if (GET_RTX_CLASS (code) != '<') | |
7968 | return 0; | |
7969 | ||
7970 | cc_mode = GET_MODE (XEXP (op, 0)); | |
7971 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
7972 | return 0; | |
7973 | ||
39a10a29 | 7974 | validate_condition_mode (code, cc_mode); |
9878760c | 7975 | |
39a10a29 GK |
7976 | return 1; |
7977 | } | |
7978 | ||
7979 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
7980 | insn and which is true if the corresponding bit in the CC register | |
7981 | is set. */ | |
7982 | ||
7983 | int | |
a2369ed3 | 7984 | branch_positive_comparison_operator (rtx op, enum machine_mode mode) |
39a10a29 GK |
7985 | { |
7986 | enum rtx_code code; | |
7987 | ||
8daf2e65 | 7988 | if (! branch_comparison_operator (op, mode)) |
9878760c RK |
7989 | return 0; |
7990 | ||
39a10a29 GK |
7991 | code = GET_CODE (op); |
7992 | return (code == EQ || code == LT || code == GT | |
993f19a8 | 7993 | || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE) |
39a10a29 GK |
7994 | || code == LTU || code == GTU |
7995 | || code == UNORDERED); | |
9878760c RK |
7996 | } |
7997 | ||
b7053a3f GK |
7998 | /* Return 1 if OP is a comparison operation that is valid for an scc |
7999 | insn: it must be a positive comparison. */ | |
9878760c RK |
8000 | |
8001 | int | |
a2369ed3 | 8002 | scc_comparison_operator (rtx op, enum machine_mode mode) |
9878760c | 8003 | { |
b7053a3f | 8004 | return branch_positive_comparison_operator (op, mode); |
9878760c | 8005 | } |
e0cd0770 JC |
8006 | |
8007 | int | |
a2369ed3 | 8008 | trap_comparison_operator (rtx op, enum machine_mode mode) |
e0cd0770 JC |
8009 | { |
8010 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
8011 | return 0; | |
39a10a29 | 8012 | return GET_RTX_CLASS (GET_CODE (op)) == '<'; |
e0cd0770 | 8013 | } |
dfbdccdb GK |
8014 | |
8015 | int | |
a2369ed3 | 8016 | boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dfbdccdb GK |
8017 | { |
8018 | enum rtx_code code = GET_CODE (op); | |
8019 | return (code == AND || code == IOR || code == XOR); | |
8020 | } | |
1d328b19 GK |
8021 | |
8022 | int | |
a2369ed3 | 8023 | boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
1d328b19 GK |
8024 | { |
8025 | enum rtx_code code = GET_CODE (op); | |
8026 | return (code == IOR || code == XOR); | |
8027 | } | |
50a0b056 GK |
8028 | |
8029 | int | |
a2369ed3 | 8030 | min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
50a0b056 GK |
8031 | { |
8032 | enum rtx_code code = GET_CODE (op); | |
8033 | return (code == SMIN || code == SMAX || code == UMIN || code == UMAX); | |
8034 | } | |
9878760c RK |
8035 | \f |
8036 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
8037 | mask required to convert the result of a rotate insn into a shift | |
b1765bde | 8038 | left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */ |
9878760c RK |
8039 | |
8040 | int | |
a2369ed3 | 8041 | includes_lshift_p (rtx shiftop, rtx andop) |
9878760c | 8042 | { |
e2c953b6 DE |
8043 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
8044 | ||
8045 | shift_mask <<= INTVAL (shiftop); | |
9878760c | 8046 | |
b1765bde | 8047 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
9878760c RK |
8048 | } |
8049 | ||
8050 | /* Similar, but for right shift. */ | |
8051 | ||
8052 | int | |
a2369ed3 | 8053 | includes_rshift_p (rtx shiftop, rtx andop) |
9878760c | 8054 | { |
a7653a2c | 8055 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
8056 | |
8057 | shift_mask >>= INTVAL (shiftop); | |
8058 | ||
b1765bde | 8059 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
e2c953b6 DE |
8060 | } |
8061 | ||
c5059423 AM |
8062 | /* Return 1 if ANDOP is a mask suitable for use with an rldic insn |
8063 | to perform a left shift. It must have exactly SHIFTOP least | |
b6d08ca1 | 8064 | significant 0's, then one or more 1's, then zero or more 0's. */ |
e2c953b6 DE |
8065 | |
8066 | int | |
a2369ed3 | 8067 | includes_rldic_lshift_p (rtx shiftop, rtx andop) |
e2c953b6 | 8068 | { |
c5059423 AM |
8069 | if (GET_CODE (andop) == CONST_INT) |
8070 | { | |
02071907 | 8071 | HOST_WIDE_INT c, lsb, shift_mask; |
e2c953b6 | 8072 | |
c5059423 | 8073 | c = INTVAL (andop); |
02071907 | 8074 | if (c == 0 || c == ~0) |
c5059423 | 8075 | return 0; |
e2c953b6 | 8076 | |
02071907 | 8077 | shift_mask = ~0; |
c5059423 AM |
8078 | shift_mask <<= INTVAL (shiftop); |
8079 | ||
b6d08ca1 | 8080 | /* Find the least significant one bit. */ |
c5059423 AM |
8081 | lsb = c & -c; |
8082 | ||
8083 | /* It must coincide with the LSB of the shift mask. */ | |
8084 | if (-lsb != shift_mask) | |
8085 | return 0; | |
e2c953b6 | 8086 | |
c5059423 AM |
8087 | /* Invert to look for the next transition (if any). */ |
8088 | c = ~c; | |
8089 | ||
8090 | /* Remove the low group of ones (originally low group of zeros). */ | |
8091 | c &= -lsb; | |
8092 | ||
8093 | /* Again find the lsb, and check we have all 1's above. */ | |
8094 | lsb = c & -c; | |
8095 | return c == -lsb; | |
8096 | } | |
8097 | else if (GET_CODE (andop) == CONST_DOUBLE | |
8098 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
8099 | { | |
02071907 AM |
8100 | HOST_WIDE_INT low, high, lsb; |
8101 | HOST_WIDE_INT shift_mask_low, shift_mask_high; | |
c5059423 AM |
8102 | |
8103 | low = CONST_DOUBLE_LOW (andop); | |
8104 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8105 | high = CONST_DOUBLE_HIGH (andop); | |
8106 | ||
8107 | if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)) | |
02071907 | 8108 | || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0))) |
c5059423 AM |
8109 | return 0; |
8110 | ||
8111 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
8112 | { | |
02071907 | 8113 | shift_mask_high = ~0; |
c5059423 AM |
8114 | if (INTVAL (shiftop) > 32) |
8115 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
8116 | ||
8117 | lsb = high & -high; | |
8118 | ||
8119 | if (-lsb != shift_mask_high || INTVAL (shiftop) < 32) | |
8120 | return 0; | |
8121 | ||
8122 | high = ~high; | |
8123 | high &= -lsb; | |
8124 | ||
8125 | lsb = high & -high; | |
8126 | return high == -lsb; | |
8127 | } | |
8128 | ||
02071907 | 8129 | shift_mask_low = ~0; |
c5059423 AM |
8130 | shift_mask_low <<= INTVAL (shiftop); |
8131 | ||
8132 | lsb = low & -low; | |
8133 | ||
8134 | if (-lsb != shift_mask_low) | |
8135 | return 0; | |
8136 | ||
8137 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8138 | high = ~high; | |
8139 | low = ~low; | |
8140 | low &= -lsb; | |
8141 | ||
8142 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
8143 | { | |
8144 | lsb = high & -high; | |
8145 | return high == -lsb; | |
8146 | } | |
8147 | ||
8148 | lsb = low & -low; | |
8149 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
8150 | } | |
8151 | else | |
8152 | return 0; | |
8153 | } | |
e2c953b6 | 8154 | |
c5059423 AM |
8155 | /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn |
8156 | to perform a left shift. It must have SHIFTOP or more least | |
c1207243 | 8157 | significant 0's, with the remainder of the word 1's. */ |
e2c953b6 | 8158 | |
c5059423 | 8159 | int |
a2369ed3 | 8160 | includes_rldicr_lshift_p (rtx shiftop, rtx andop) |
c5059423 | 8161 | { |
e2c953b6 | 8162 | if (GET_CODE (andop) == CONST_INT) |
c5059423 | 8163 | { |
02071907 | 8164 | HOST_WIDE_INT c, lsb, shift_mask; |
c5059423 | 8165 | |
02071907 | 8166 | shift_mask = ~0; |
c5059423 AM |
8167 | shift_mask <<= INTVAL (shiftop); |
8168 | c = INTVAL (andop); | |
8169 | ||
c1207243 | 8170 | /* Find the least significant one bit. */ |
c5059423 AM |
8171 | lsb = c & -c; |
8172 | ||
8173 | /* It must be covered by the shift mask. | |
a4f6c312 | 8174 | This test also rejects c == 0. */ |
c5059423 AM |
8175 | if ((lsb & shift_mask) == 0) |
8176 | return 0; | |
8177 | ||
8178 | /* Check we have all 1's above the transition, and reject all 1's. */ | |
8179 | return c == -lsb && lsb != 1; | |
8180 | } | |
8181 | else if (GET_CODE (andop) == CONST_DOUBLE | |
8182 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
8183 | { | |
02071907 | 8184 | HOST_WIDE_INT low, lsb, shift_mask_low; |
c5059423 AM |
8185 | |
8186 | low = CONST_DOUBLE_LOW (andop); | |
8187 | ||
8188 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8189 | { | |
02071907 | 8190 | HOST_WIDE_INT high, shift_mask_high; |
c5059423 AM |
8191 | |
8192 | high = CONST_DOUBLE_HIGH (andop); | |
8193 | ||
8194 | if (low == 0) | |
8195 | { | |
02071907 | 8196 | shift_mask_high = ~0; |
c5059423 AM |
8197 | if (INTVAL (shiftop) > 32) |
8198 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
8199 | ||
8200 | lsb = high & -high; | |
8201 | ||
8202 | if ((lsb & shift_mask_high) == 0) | |
8203 | return 0; | |
8204 | ||
8205 | return high == -lsb; | |
8206 | } | |
8207 | if (high != ~0) | |
8208 | return 0; | |
8209 | } | |
8210 | ||
02071907 | 8211 | shift_mask_low = ~0; |
c5059423 AM |
8212 | shift_mask_low <<= INTVAL (shiftop); |
8213 | ||
8214 | lsb = low & -low; | |
8215 | ||
8216 | if ((lsb & shift_mask_low) == 0) | |
8217 | return 0; | |
8218 | ||
8219 | return low == -lsb && lsb != 1; | |
8220 | } | |
e2c953b6 | 8221 | else |
c5059423 | 8222 | return 0; |
9878760c | 8223 | } |
35068b43 RK |
8224 | |
8225 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates | |
8226 | for lfq and stfq insns. | |
8227 | ||
8228 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
8229 | abort if we are passed pseudo registers. */ | |
8230 | ||
8231 | int | |
a2369ed3 | 8232 | registers_ok_for_quad_peep (rtx reg1, rtx reg2) |
35068b43 RK |
8233 | { |
8234 | /* We might have been passed a SUBREG. */ | |
8235 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
8236 | return 0; | |
8237 | ||
8238 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
8239 | } | |
8240 | ||
a4f6c312 SS |
8241 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. |
8242 | addr1 and addr2 must be in consecutive memory locations | |
8243 | (addr2 == addr1 + 8). */ | |
35068b43 RK |
8244 | |
8245 | int | |
a2369ed3 | 8246 | addrs_ok_for_quad_peep (rtx addr1, rtx addr2) |
35068b43 | 8247 | { |
e2c953b6 | 8248 | unsigned int reg1; |
35068b43 RK |
8249 | int offset1; |
8250 | ||
8251 | /* Extract an offset (if used) from the first addr. */ | |
8252 | if (GET_CODE (addr1) == PLUS) | |
8253 | { | |
8254 | /* If not a REG, return zero. */ | |
8255 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
8256 | return 0; | |
8257 | else | |
8258 | { | |
8259 | reg1 = REGNO (XEXP (addr1, 0)); | |
8260 | /* The offset must be constant! */ | |
8261 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
8262 | return 0; | |
8263 | offset1 = INTVAL (XEXP (addr1, 1)); | |
8264 | } | |
8265 | } | |
8266 | else if (GET_CODE (addr1) != REG) | |
8267 | return 0; | |
8268 | else | |
8269 | { | |
8270 | reg1 = REGNO (addr1); | |
8271 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
8272 | offset1 = 0; | |
8273 | } | |
8274 | ||
a2369ed3 DJ |
8275 | /* Make sure the second address is a (mem (plus (reg) (const_int))) |
8276 | or if it is (mem (reg)) then make sure that offset1 is -8 and the same | |
8277 | register as addr1. */ | |
984e25ac DE |
8278 | if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2)) |
8279 | return 1; | |
35068b43 RK |
8280 | if (GET_CODE (addr2) != PLUS) |
8281 | return 0; | |
8282 | ||
8283 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
8284 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
8285 | return 0; | |
8286 | ||
8287 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
8288 | return 0; | |
8289 | ||
8290 | /* The offset for the second addr must be 8 more than the first addr. */ | |
8291 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
8292 | return 0; | |
8293 | ||
8294 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
8295 | instructions. */ | |
8296 | return 1; | |
8297 | } | |
9878760c RK |
8298 | \f |
8299 | /* Return the register class of a scratch register needed to copy IN into | |
8300 | or out of a register in CLASS in MODE. If it can be done directly, | |
8301 | NO_REGS is returned. */ | |
8302 | ||
8303 | enum reg_class | |
a2369ed3 DJ |
8304 | secondary_reload_class (enum reg_class class, |
8305 | enum machine_mode mode ATTRIBUTE_UNUSED, rtx in) | |
9878760c | 8306 | { |
5accd822 | 8307 | int regno; |
9878760c | 8308 | |
ab82a49f AP |
8309 | if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN |
8310 | #if TARGET_MACHO | |
8311 | && MACHOPIC_INDIRECT | |
8312 | #endif | |
8313 | )) | |
46fad5b7 DJ |
8314 | { |
8315 | /* We cannot copy a symbolic operand directly into anything | |
8316 | other than BASE_REGS for TARGET_ELF. So indicate that a | |
8317 | register from BASE_REGS is needed as an intermediate | |
8318 | register. | |
8319 | ||
8320 | On Darwin, pic addresses require a load from memory, which | |
8321 | needs a base register. */ | |
8322 | if (class != BASE_REGS | |
8323 | && (GET_CODE (in) == SYMBOL_REF | |
8324 | || GET_CODE (in) == HIGH | |
8325 | || GET_CODE (in) == LABEL_REF | |
8326 | || GET_CODE (in) == CONST)) | |
8327 | return BASE_REGS; | |
8328 | } | |
e7b7998a | 8329 | |
5accd822 DE |
8330 | if (GET_CODE (in) == REG) |
8331 | { | |
8332 | regno = REGNO (in); | |
8333 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8334 | { | |
8335 | regno = true_regnum (in); | |
8336 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8337 | regno = -1; | |
8338 | } | |
8339 | } | |
8340 | else if (GET_CODE (in) == SUBREG) | |
8341 | { | |
8342 | regno = true_regnum (in); | |
8343 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8344 | regno = -1; | |
8345 | } | |
8346 | else | |
8347 | regno = -1; | |
8348 | ||
9878760c RK |
8349 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
8350 | into anything. */ | |
8351 | if (class == GENERAL_REGS || class == BASE_REGS | |
8352 | || (regno >= 0 && INT_REGNO_P (regno))) | |
8353 | return NO_REGS; | |
8354 | ||
8355 | /* Constants, memory, and FP registers can go into FP registers. */ | |
8356 | if ((regno == -1 || FP_REGNO_P (regno)) | |
8357 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
8358 | return NO_REGS; | |
8359 | ||
0ac081f6 AH |
8360 | /* Memory, and AltiVec registers can go into AltiVec registers. */ |
8361 | if ((regno == -1 || ALTIVEC_REGNO_P (regno)) | |
8362 | && class == ALTIVEC_REGS) | |
8363 | return NO_REGS; | |
8364 | ||
9878760c RK |
8365 | /* We can copy among the CR registers. */ |
8366 | if ((class == CR_REGS || class == CR0_REGS) | |
8367 | && regno >= 0 && CR_REGNO_P (regno)) | |
8368 | return NO_REGS; | |
8369 | ||
8370 | /* Otherwise, we need GENERAL_REGS. */ | |
8371 | return GENERAL_REGS; | |
8372 | } | |
8373 | \f | |
8374 | /* Given a comparison operation, return the bit number in CCR to test. We | |
8375 | know this is a valid comparison. | |
8376 | ||
8377 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
8378 | used instead of %C, so the bits will be in different places. | |
8379 | ||
b4ac57ab | 8380 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
8381 | |
8382 | int | |
a2369ed3 | 8383 | ccr_bit (rtx op, int scc_p) |
9878760c RK |
8384 | { |
8385 | enum rtx_code code = GET_CODE (op); | |
8386 | enum machine_mode cc_mode; | |
8387 | int cc_regnum; | |
8388 | int base_bit; | |
9ebbca7d | 8389 | rtx reg; |
9878760c RK |
8390 | |
8391 | if (GET_RTX_CLASS (code) != '<') | |
8392 | return -1; | |
8393 | ||
9ebbca7d GK |
8394 | reg = XEXP (op, 0); |
8395 | ||
8396 | if (GET_CODE (reg) != REG | |
8397 | || ! CR_REGNO_P (REGNO (reg))) | |
8398 | abort (); | |
8399 | ||
8400 | cc_mode = GET_MODE (reg); | |
8401 | cc_regnum = REGNO (reg); | |
8402 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 8403 | |
39a10a29 | 8404 | validate_condition_mode (code, cc_mode); |
c5defebb | 8405 | |
b7053a3f GK |
8406 | /* When generating a sCOND operation, only positive conditions are |
8407 | allowed. */ | |
8408 | if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED | |
8409 | && code != GTU && code != LTU) | |
8410 | abort (); | |
8411 | ||
9878760c RK |
8412 | switch (code) |
8413 | { | |
8414 | case NE: | |
993f19a8 AH |
8415 | if (TARGET_E500 && !TARGET_FPRS |
8416 | && TARGET_HARD_FLOAT && cc_mode == CCFPmode) | |
a3170dc6 | 8417 | return base_bit + 1; |
9878760c RK |
8418 | return scc_p ? base_bit + 3 : base_bit + 2; |
8419 | case EQ: | |
993f19a8 AH |
8420 | if (TARGET_E500 && !TARGET_FPRS |
8421 | && TARGET_HARD_FLOAT && cc_mode == CCFPmode) | |
a3170dc6 | 8422 | return base_bit + 1; |
9878760c | 8423 | return base_bit + 2; |
1c882ea4 | 8424 | case GT: case GTU: case UNLE: |
9878760c | 8425 | return base_bit + 1; |
1c882ea4 | 8426 | case LT: case LTU: case UNGE: |
9878760c | 8427 | return base_bit; |
1c882ea4 GK |
8428 | case ORDERED: case UNORDERED: |
8429 | return base_bit + 3; | |
9878760c RK |
8430 | |
8431 | case GE: case GEU: | |
39a10a29 | 8432 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
8433 | unordered position. So test that bit. For integer, this is ! LT |
8434 | unless this is an scc insn. */ | |
39a10a29 | 8435 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
8436 | |
8437 | case LE: case LEU: | |
39a10a29 | 8438 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 8439 | |
9878760c RK |
8440 | default: |
8441 | abort (); | |
8442 | } | |
8443 | } | |
1ff7789b | 8444 | \f |
8d30c4ee | 8445 | /* Return the GOT register. */ |
1ff7789b MM |
8446 | |
8447 | struct rtx_def * | |
a2369ed3 | 8448 | rs6000_got_register (rtx value ATTRIBUTE_UNUSED) |
1ff7789b | 8449 | { |
a4f6c312 SS |
8450 | /* The second flow pass currently (June 1999) can't update |
8451 | regs_ever_live without disturbing other parts of the compiler, so | |
8452 | update it here to make the prolog/epilogue code happy. */ | |
1db02437 FS |
8453 | if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]) |
8454 | regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
1ff7789b | 8455 | |
8d30c4ee | 8456 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 8457 | |
1ff7789b MM |
8458 | return pic_offset_table_rtx; |
8459 | } | |
a7df97e6 | 8460 | \f |
e2500fed GK |
8461 | /* Function to init struct machine_function. |
8462 | This will be called, via a pointer variable, | |
8463 | from push_function_context. */ | |
a7df97e6 | 8464 | |
e2500fed | 8465 | static struct machine_function * |
863d938c | 8466 | rs6000_init_machine_status (void) |
a7df97e6 | 8467 | { |
e2500fed | 8468 | return ggc_alloc_cleared (sizeof (machine_function)); |
a7df97e6 | 8469 | } |
9878760c | 8470 | \f |
0ba1b2ff AM |
8471 | /* These macros test for integers and extract the low-order bits. */ |
8472 | #define INT_P(X) \ | |
8473 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
8474 | && GET_MODE (X) == VOIDmode) | |
8475 | ||
8476 | #define INT_LOWPART(X) \ | |
8477 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
8478 | ||
8479 | int | |
a2369ed3 | 8480 | extract_MB (rtx op) |
0ba1b2ff AM |
8481 | { |
8482 | int i; | |
8483 | unsigned long val = INT_LOWPART (op); | |
8484 | ||
8485 | /* If the high bit is zero, the value is the first 1 bit we find | |
8486 | from the left. */ | |
8487 | if ((val & 0x80000000) == 0) | |
8488 | { | |
8489 | if ((val & 0xffffffff) == 0) | |
8490 | abort (); | |
8491 | ||
8492 | i = 1; | |
8493 | while (((val <<= 1) & 0x80000000) == 0) | |
8494 | ++i; | |
8495 | return i; | |
8496 | } | |
8497 | ||
8498 | /* If the high bit is set and the low bit is not, or the mask is all | |
8499 | 1's, the value is zero. */ | |
8500 | if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff) | |
8501 | return 0; | |
8502 | ||
8503 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
8504 | from the right. */ | |
8505 | i = 31; | |
8506 | while (((val >>= 1) & 1) != 0) | |
8507 | --i; | |
8508 | ||
8509 | return i; | |
8510 | } | |
8511 | ||
8512 | int | |
a2369ed3 | 8513 | extract_ME (rtx op) |
0ba1b2ff AM |
8514 | { |
8515 | int i; | |
8516 | unsigned long val = INT_LOWPART (op); | |
8517 | ||
8518 | /* If the low bit is zero, the value is the first 1 bit we find from | |
8519 | the right. */ | |
8520 | if ((val & 1) == 0) | |
8521 | { | |
8522 | if ((val & 0xffffffff) == 0) | |
8523 | abort (); | |
8524 | ||
8525 | i = 30; | |
8526 | while (((val >>= 1) & 1) == 0) | |
8527 | --i; | |
8528 | ||
8529 | return i; | |
8530 | } | |
8531 | ||
8532 | /* If the low bit is set and the high bit is not, or the mask is all | |
8533 | 1's, the value is 31. */ | |
8534 | if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff) | |
8535 | return 31; | |
8536 | ||
8537 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
8538 | from the left. */ | |
8539 | i = 0; | |
8540 | while (((val <<= 1) & 0x80000000) != 0) | |
8541 | ++i; | |
8542 | ||
8543 | return i; | |
8544 | } | |
8545 | ||
c4501e62 JJ |
8546 | /* Locate some local-dynamic symbol still in use by this function |
8547 | so that we can print its name in some tls_ld pattern. */ | |
8548 | ||
8549 | static const char * | |
863d938c | 8550 | rs6000_get_some_local_dynamic_name (void) |
c4501e62 JJ |
8551 | { |
8552 | rtx insn; | |
8553 | ||
8554 | if (cfun->machine->some_ld_name) | |
8555 | return cfun->machine->some_ld_name; | |
8556 | ||
8557 | for (insn = get_insns (); insn ; insn = NEXT_INSN (insn)) | |
8558 | if (INSN_P (insn) | |
8559 | && for_each_rtx (&PATTERN (insn), | |
8560 | rs6000_get_some_local_dynamic_name_1, 0)) | |
8561 | return cfun->machine->some_ld_name; | |
8562 | ||
8563 | abort (); | |
8564 | } | |
8565 | ||
8566 | /* Helper function for rs6000_get_some_local_dynamic_name. */ | |
8567 | ||
8568 | static int | |
a2369ed3 | 8569 | rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
8570 | { |
8571 | rtx x = *px; | |
8572 | ||
8573 | if (GET_CODE (x) == SYMBOL_REF) | |
8574 | { | |
8575 | const char *str = XSTR (x, 0); | |
8576 | if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC) | |
8577 | { | |
8578 | cfun->machine->some_ld_name = str; | |
8579 | return 1; | |
8580 | } | |
8581 | } | |
8582 | ||
8583 | return 0; | |
8584 | } | |
8585 | ||
9878760c RK |
8586 | /* Print an operand. Recognize special options, documented below. */ |
8587 | ||
38c1f2d7 | 8588 | #if TARGET_ELF |
d9407988 | 8589 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 8590 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
8591 | #else |
8592 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 8593 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
8594 | #endif |
8595 | ||
9878760c | 8596 | void |
a2369ed3 | 8597 | print_operand (FILE *file, rtx x, int code) |
9878760c RK |
8598 | { |
8599 | int i; | |
a260abc9 | 8600 | HOST_WIDE_INT val; |
0ba1b2ff | 8601 | unsigned HOST_WIDE_INT uval; |
9878760c RK |
8602 | |
8603 | switch (code) | |
8604 | { | |
a8b3aeda | 8605 | case '.': |
a85d226b RK |
8606 | /* Write out an instruction after the call which may be replaced |
8607 | with glue code by the loader. This depends on the AIX version. */ | |
8608 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
8609 | return; |
8610 | ||
81eace42 GK |
8611 | /* %a is output_address. */ |
8612 | ||
9854d9ed RK |
8613 | case 'A': |
8614 | /* If X is a constant integer whose low-order 5 bits are zero, | |
8615 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 8616 | in the AIX assembler where "sri" with a zero shift count |
20e26713 | 8617 | writes a trash instruction. */ |
9854d9ed | 8618 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) |
76229ac8 | 8619 | putc ('l', file); |
9854d9ed | 8620 | else |
76229ac8 | 8621 | putc ('r', file); |
9854d9ed RK |
8622 | return; |
8623 | ||
8624 | case 'b': | |
e2c953b6 DE |
8625 | /* If constant, low-order 16 bits of constant, unsigned. |
8626 | Otherwise, write normally. */ | |
8627 | if (INT_P (x)) | |
8628 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
8629 | else | |
8630 | print_operand (file, x, 0); | |
cad12a8d RK |
8631 | return; |
8632 | ||
a260abc9 DE |
8633 | case 'B': |
8634 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
8635 | for 64-bit mask direction. */ | |
296b8152 | 8636 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 8637 | return; |
a260abc9 | 8638 | |
81eace42 GK |
8639 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
8640 | output_operand. */ | |
8641 | ||
9854d9ed | 8642 | case 'E': |
39a10a29 | 8643 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
8644 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
8645 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 8646 | else |
39a10a29 | 8647 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 8648 | return; |
9854d9ed RK |
8649 | |
8650 | case 'f': | |
8651 | /* X is a CR register. Print the shift count needed to move it | |
8652 | to the high-order four bits. */ | |
8653 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
8654 | output_operand_lossage ("invalid %%f value"); | |
8655 | else | |
9ebbca7d | 8656 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
8657 | return; |
8658 | ||
8659 | case 'F': | |
8660 | /* Similar, but print the count for the rotate in the opposite | |
8661 | direction. */ | |
8662 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
8663 | output_operand_lossage ("invalid %%F value"); | |
8664 | else | |
9ebbca7d | 8665 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
8666 | return; |
8667 | ||
8668 | case 'G': | |
8669 | /* X is a constant integer. If it is negative, print "m", | |
43aa4e05 | 8670 | otherwise print "z". This is to make an aze or ame insn. */ |
9854d9ed RK |
8671 | if (GET_CODE (x) != CONST_INT) |
8672 | output_operand_lossage ("invalid %%G value"); | |
8673 | else if (INTVAL (x) >= 0) | |
76229ac8 | 8674 | putc ('z', file); |
9854d9ed | 8675 | else |
76229ac8 | 8676 | putc ('m', file); |
9854d9ed | 8677 | return; |
e2c953b6 | 8678 | |
9878760c | 8679 | case 'h': |
a4f6c312 SS |
8680 | /* If constant, output low-order five bits. Otherwise, write |
8681 | normally. */ | |
9878760c | 8682 | if (INT_P (x)) |
5f59ecb7 | 8683 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
8684 | else |
8685 | print_operand (file, x, 0); | |
8686 | return; | |
8687 | ||
64305719 | 8688 | case 'H': |
a4f6c312 SS |
8689 | /* If constant, output low-order six bits. Otherwise, write |
8690 | normally. */ | |
64305719 | 8691 | if (INT_P (x)) |
5f59ecb7 | 8692 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
8693 | else |
8694 | print_operand (file, x, 0); | |
8695 | return; | |
8696 | ||
9854d9ed RK |
8697 | case 'I': |
8698 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 8699 | if (INT_P (x)) |
76229ac8 | 8700 | putc ('i', file); |
9878760c RK |
8701 | return; |
8702 | ||
9854d9ed RK |
8703 | case 'j': |
8704 | /* Write the bit number in CCR for jump. */ | |
8705 | i = ccr_bit (x, 0); | |
8706 | if (i == -1) | |
8707 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 8708 | else |
9854d9ed | 8709 | fprintf (file, "%d", i); |
9878760c RK |
8710 | return; |
8711 | ||
9854d9ed RK |
8712 | case 'J': |
8713 | /* Similar, but add one for shift count in rlinm for scc and pass | |
8714 | scc flag to `ccr_bit'. */ | |
8715 | i = ccr_bit (x, 1); | |
8716 | if (i == -1) | |
8717 | output_operand_lossage ("invalid %%J code"); | |
8718 | else | |
a0466a68 RK |
8719 | /* If we want bit 31, write a shift count of zero, not 32. */ |
8720 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
8721 | return; |
8722 | ||
9854d9ed RK |
8723 | case 'k': |
8724 | /* X must be a constant. Write the 1's complement of the | |
8725 | constant. */ | |
9878760c | 8726 | if (! INT_P (x)) |
9854d9ed | 8727 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
8728 | else |
8729 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
8730 | return; |
8731 | ||
81eace42 | 8732 | case 'K': |
9ebbca7d GK |
8733 | /* X must be a symbolic constant on ELF. Write an |
8734 | expression suitable for an 'addi' that adds in the low 16 | |
8735 | bits of the MEM. */ | |
8736 | if (GET_CODE (x) != CONST) | |
8737 | { | |
8738 | print_operand_address (file, x); | |
8739 | fputs ("@l", file); | |
8740 | } | |
8741 | else | |
8742 | { | |
8743 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
8744 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
8745 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
8746 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 8747 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
8748 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
8749 | fputs ("@l", file); | |
ed8d2920 MM |
8750 | /* For GNU as, there must be a non-alphanumeric character |
8751 | between 'l' and the number. The '-' is added by | |
8752 | print_operand() already. */ | |
8753 | if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0) | |
8754 | fputs ("+", file); | |
9ebbca7d GK |
8755 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); |
8756 | } | |
81eace42 GK |
8757 | return; |
8758 | ||
8759 | /* %l is output_asm_label. */ | |
9ebbca7d | 8760 | |
9854d9ed RK |
8761 | case 'L': |
8762 | /* Write second word of DImode or DFmode reference. Works on register | |
8763 | or non-indexed memory only. */ | |
8764 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 8765 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
8766 | else if (GET_CODE (x) == MEM) |
8767 | { | |
8768 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 8769 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
8770 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
8771 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
ed8908e7 RK |
8772 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), |
8773 | UNITS_PER_WORD)); | |
9854d9ed | 8774 | else |
d7624dc0 RK |
8775 | output_address (XEXP (adjust_address_nv (x, SImode, |
8776 | UNITS_PER_WORD), | |
8777 | 0)); | |
ed8908e7 | 8778 | |
ba5e43aa | 8779 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
8780 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
8781 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 8782 | } |
9878760c | 8783 | return; |
9854d9ed | 8784 | |
9878760c RK |
8785 | case 'm': |
8786 | /* MB value for a mask operand. */ | |
b1765bde | 8787 | if (! mask_operand (x, SImode)) |
9878760c RK |
8788 | output_operand_lossage ("invalid %%m value"); |
8789 | ||
0ba1b2ff | 8790 | fprintf (file, "%d", extract_MB (x)); |
9878760c RK |
8791 | return; |
8792 | ||
8793 | case 'M': | |
8794 | /* ME value for a mask operand. */ | |
b1765bde | 8795 | if (! mask_operand (x, SImode)) |
a260abc9 | 8796 | output_operand_lossage ("invalid %%M value"); |
9878760c | 8797 | |
0ba1b2ff | 8798 | fprintf (file, "%d", extract_ME (x)); |
9878760c RK |
8799 | return; |
8800 | ||
81eace42 GK |
8801 | /* %n outputs the negative of its operand. */ |
8802 | ||
9878760c RK |
8803 | case 'N': |
8804 | /* Write the number of elements in the vector times 4. */ | |
8805 | if (GET_CODE (x) != PARALLEL) | |
8806 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
8807 | else |
8808 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
8809 | return; |
8810 | ||
8811 | case 'O': | |
8812 | /* Similar, but subtract 1 first. */ | |
8813 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 8814 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
8815 | else |
8816 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
8817 | return; |
8818 | ||
9854d9ed RK |
8819 | case 'p': |
8820 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
8821 | if (! INT_P (x) | |
2bfcf297 | 8822 | || INT_LOWPART (x) < 0 |
9854d9ed RK |
8823 | || (i = exact_log2 (INT_LOWPART (x))) < 0) |
8824 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
8825 | else |
8826 | fprintf (file, "%d", i); | |
9854d9ed RK |
8827 | return; |
8828 | ||
9878760c RK |
8829 | case 'P': |
8830 | /* The operand must be an indirect memory reference. The result | |
a4f6c312 | 8831 | is the register number. */ |
9878760c RK |
8832 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG |
8833 | || REGNO (XEXP (x, 0)) >= 32) | |
8834 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 DE |
8835 | else |
8836 | fprintf (file, "%d", REGNO (XEXP (x, 0))); | |
9878760c RK |
8837 | return; |
8838 | ||
dfbdccdb GK |
8839 | case 'q': |
8840 | /* This outputs the logical code corresponding to a boolean | |
8841 | expression. The expression may have one or both operands | |
39a10a29 GK |
8842 | negated (if one, only the first one). For condition register |
8843 | logical operations, it will also treat the negated | |
8844 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 8845 | { |
63bc1d05 | 8846 | const char *const *t = 0; |
dfbdccdb GK |
8847 | const char *s; |
8848 | enum rtx_code code = GET_CODE (x); | |
8849 | static const char * const tbl[3][3] = { | |
8850 | { "and", "andc", "nor" }, | |
8851 | { "or", "orc", "nand" }, | |
8852 | { "xor", "eqv", "xor" } }; | |
8853 | ||
8854 | if (code == AND) | |
8855 | t = tbl[0]; | |
8856 | else if (code == IOR) | |
8857 | t = tbl[1]; | |
8858 | else if (code == XOR) | |
8859 | t = tbl[2]; | |
8860 | else | |
8861 | output_operand_lossage ("invalid %%q value"); | |
8862 | ||
8863 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
8864 | s = t[0]; | |
8865 | else | |
8866 | { | |
8867 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
8868 | s = t[2]; | |
8869 | else | |
8870 | s = t[1]; | |
8871 | } | |
8872 | ||
8873 | fputs (s, file); | |
8874 | } | |
8875 | return; | |
8876 | ||
2c4a9cff DE |
8877 | case 'Q': |
8878 | if (TARGET_MFCRF) | |
8879 | fputc (',',file); | |
8880 | /* FALLTHRU */ | |
8881 | else | |
8882 | return; | |
8883 | ||
9854d9ed RK |
8884 | case 'R': |
8885 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
8886 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
8887 | output_operand_lossage ("invalid %%R value"); | |
8888 | else | |
9ebbca7d | 8889 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 8890 | return; |
9854d9ed RK |
8891 | |
8892 | case 's': | |
8893 | /* Low 5 bits of 32 - value */ | |
8894 | if (! INT_P (x)) | |
8895 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
8896 | else |
8897 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 8898 | return; |
9854d9ed | 8899 | |
a260abc9 | 8900 | case 'S': |
0ba1b2ff | 8901 | /* PowerPC64 mask position. All 0's is excluded. |
a260abc9 DE |
8902 | CONST_INT 32-bit mask is considered sign-extended so any |
8903 | transition must occur within the CONST_INT, not on the boundary. */ | |
b1765bde | 8904 | if (! mask64_operand (x, DImode)) |
a260abc9 DE |
8905 | output_operand_lossage ("invalid %%S value"); |
8906 | ||
0ba1b2ff | 8907 | uval = INT_LOWPART (x); |
a260abc9 | 8908 | |
0ba1b2ff | 8909 | if (uval & 1) /* Clear Left */ |
a260abc9 | 8910 | { |
f099d360 GK |
8911 | #if HOST_BITS_PER_WIDE_INT > 64 |
8912 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
8913 | #endif | |
0ba1b2ff | 8914 | i = 64; |
a260abc9 | 8915 | } |
0ba1b2ff | 8916 | else /* Clear Right */ |
a260abc9 | 8917 | { |
0ba1b2ff | 8918 | uval = ~uval; |
f099d360 GK |
8919 | #if HOST_BITS_PER_WIDE_INT > 64 |
8920 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
8921 | #endif | |
0ba1b2ff | 8922 | i = 63; |
a260abc9 | 8923 | } |
0ba1b2ff AM |
8924 | while (uval != 0) |
8925 | --i, uval >>= 1; | |
8926 | if (i < 0) | |
8927 | abort (); | |
8928 | fprintf (file, "%d", i); | |
8929 | return; | |
a260abc9 | 8930 | |
a3170dc6 AH |
8931 | case 't': |
8932 | /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */ | |
8933 | if (GET_CODE (x) != REG || GET_MODE (x) != CCmode) | |
8934 | abort (); | |
8935 | ||
8936 | /* Bit 3 is OV bit. */ | |
8937 | i = 4 * (REGNO (x) - CR0_REGNO) + 3; | |
8938 | ||
8939 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
8940 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
8941 | return; | |
8942 | ||
cccf3bdc DE |
8943 | case 'T': |
8944 | /* Print the symbolic name of a branch target register. */ | |
8945 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
8946 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
8947 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 8948 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
8949 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
8950 | else | |
8951 | fputs ("ctr", file); | |
8952 | return; | |
8953 | ||
9854d9ed | 8954 | case 'u': |
802a0058 | 8955 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
8956 | if (! INT_P (x)) |
8957 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 DE |
8958 | else |
8959 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, | |
8960 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
8961 | return; |
8962 | ||
802a0058 MM |
8963 | case 'v': |
8964 | /* High-order 16 bits of constant for use in signed operand. */ | |
8965 | if (! INT_P (x)) | |
8966 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 | 8967 | else |
134c32f6 DE |
8968 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
8969 | (INT_LOWPART (x) >> 16) & 0xffff); | |
8970 | return; | |
802a0058 | 8971 | |
9854d9ed RK |
8972 | case 'U': |
8973 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
8974 | if (GET_CODE (x) == MEM | |
8975 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
8976 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 8977 | putc ('u', file); |
9854d9ed | 8978 | return; |
9878760c | 8979 | |
e0cd0770 JC |
8980 | case 'V': |
8981 | /* Print the trap code for this operand. */ | |
8982 | switch (GET_CODE (x)) | |
8983 | { | |
8984 | case EQ: | |
8985 | fputs ("eq", file); /* 4 */ | |
8986 | break; | |
8987 | case NE: | |
8988 | fputs ("ne", file); /* 24 */ | |
8989 | break; | |
8990 | case LT: | |
8991 | fputs ("lt", file); /* 16 */ | |
8992 | break; | |
8993 | case LE: | |
8994 | fputs ("le", file); /* 20 */ | |
8995 | break; | |
8996 | case GT: | |
8997 | fputs ("gt", file); /* 8 */ | |
8998 | break; | |
8999 | case GE: | |
9000 | fputs ("ge", file); /* 12 */ | |
9001 | break; | |
9002 | case LTU: | |
9003 | fputs ("llt", file); /* 2 */ | |
9004 | break; | |
9005 | case LEU: | |
9006 | fputs ("lle", file); /* 6 */ | |
9007 | break; | |
9008 | case GTU: | |
9009 | fputs ("lgt", file); /* 1 */ | |
9010 | break; | |
9011 | case GEU: | |
9012 | fputs ("lge", file); /* 5 */ | |
9013 | break; | |
9014 | default: | |
9015 | abort (); | |
9016 | } | |
9017 | break; | |
9018 | ||
9854d9ed RK |
9019 | case 'w': |
9020 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
9021 | normally. */ | |
9022 | if (INT_P (x)) | |
5f59ecb7 DE |
9023 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
9024 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
9025 | else |
9026 | print_operand (file, x, 0); | |
9878760c RK |
9027 | return; |
9028 | ||
9854d9ed | 9029 | case 'W': |
e2c953b6 | 9030 | /* MB value for a PowerPC64 rldic operand. */ |
e2c953b6 DE |
9031 | val = (GET_CODE (x) == CONST_INT |
9032 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
9033 | ||
9034 | if (val < 0) | |
9035 | i = -1; | |
9854d9ed | 9036 | else |
e2c953b6 DE |
9037 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
9038 | if ((val <<= 1) < 0) | |
9039 | break; | |
9040 | ||
9041 | #if HOST_BITS_PER_WIDE_INT == 32 | |
9042 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
9043 | i += 32; /* zero-extend high-part was all 0's */ | |
9044 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
9045 | { | |
9046 | val = CONST_DOUBLE_LOW (x); | |
9047 | ||
9048 | if (val == 0) | |
a4f6c312 | 9049 | abort (); |
e2c953b6 DE |
9050 | else if (val < 0) |
9051 | --i; | |
9052 | else | |
9053 | for ( ; i < 64; i++) | |
9054 | if ((val <<= 1) < 0) | |
9055 | break; | |
9056 | } | |
9057 | #endif | |
9058 | ||
9059 | fprintf (file, "%d", i + 1); | |
9854d9ed | 9060 | return; |
9878760c | 9061 | |
9854d9ed RK |
9062 | case 'X': |
9063 | if (GET_CODE (x) == MEM | |
4d588c14 | 9064 | && legitimate_indexed_address_p (XEXP (x, 0), 0)) |
76229ac8 | 9065 | putc ('x', file); |
9854d9ed | 9066 | return; |
9878760c | 9067 | |
9854d9ed RK |
9068 | case 'Y': |
9069 | /* Like 'L', for third word of TImode */ | |
9070 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9071 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 9072 | else if (GET_CODE (x) == MEM) |
9878760c | 9073 | { |
9854d9ed RK |
9074 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
9075 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 9076 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 9077 | else |
d7624dc0 | 9078 | output_address (XEXP (adjust_address_nv (x, SImode, 8), 0)); |
ba5e43aa | 9079 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9080 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9081 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
9082 | } |
9083 | return; | |
9854d9ed | 9084 | |
9878760c | 9085 | case 'z': |
b4ac57ab RS |
9086 | /* X is a SYMBOL_REF. Write out the name preceded by a |
9087 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
9088 | names. If we are configured for System V (or the embedded ABI) on |
9089 | the PowerPC, do not emit the period, since those systems do not use | |
9090 | TOCs and the like. */ | |
9878760c RK |
9091 | if (GET_CODE (x) != SYMBOL_REF) |
9092 | abort (); | |
9093 | ||
b6c9286a MM |
9094 | if (XSTR (x, 0)[0] != '.') |
9095 | { | |
9096 | switch (DEFAULT_ABI) | |
9097 | { | |
9098 | default: | |
9099 | abort (); | |
9100 | ||
9101 | case ABI_AIX: | |
9102 | putc ('.', file); | |
9103 | break; | |
9104 | ||
9105 | case ABI_V4: | |
ee890fe2 | 9106 | case ABI_DARWIN: |
b6c9286a | 9107 | break; |
b6c9286a MM |
9108 | } |
9109 | } | |
9739c90c JJ |
9110 | if (TARGET_AIX) |
9111 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); | |
9112 | else | |
9113 | assemble_name (file, XSTR (x, 0)); | |
9878760c RK |
9114 | return; |
9115 | ||
9854d9ed RK |
9116 | case 'Z': |
9117 | /* Like 'L', for last word of TImode. */ | |
9118 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9119 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
9120 | else if (GET_CODE (x) == MEM) |
9121 | { | |
9122 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
9123 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 9124 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 9125 | else |
d7624dc0 | 9126 | output_address (XEXP (adjust_address_nv (x, SImode, 12), 0)); |
ba5e43aa | 9127 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9128 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9129 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 9130 | } |
5c23c401 | 9131 | return; |
0ac081f6 | 9132 | |
a3170dc6 | 9133 | /* Print AltiVec or SPE memory operand. */ |
0ac081f6 AH |
9134 | case 'y': |
9135 | { | |
9136 | rtx tmp; | |
9137 | ||
9138 | if (GET_CODE (x) != MEM) | |
9139 | abort (); | |
9140 | ||
9141 | tmp = XEXP (x, 0); | |
9142 | ||
993f19a8 | 9143 | if (TARGET_E500) |
a3170dc6 AH |
9144 | { |
9145 | /* Handle [reg]. */ | |
9146 | if (GET_CODE (tmp) == REG) | |
9147 | { | |
9148 | fprintf (file, "0(%s)", reg_names[REGNO (tmp)]); | |
9149 | break; | |
9150 | } | |
9151 | /* Handle [reg+UIMM]. */ | |
9152 | else if (GET_CODE (tmp) == PLUS && | |
9153 | GET_CODE (XEXP (tmp, 1)) == CONST_INT) | |
9154 | { | |
9155 | int x; | |
9156 | ||
9157 | if (GET_CODE (XEXP (tmp, 0)) != REG) | |
9158 | abort (); | |
9159 | ||
9160 | x = INTVAL (XEXP (tmp, 1)); | |
9161 | fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]); | |
9162 | break; | |
9163 | } | |
9164 | ||
9165 | /* Fall through. Must be [reg+reg]. */ | |
9166 | } | |
0ac081f6 | 9167 | if (GET_CODE (tmp) == REG) |
c62f2db5 | 9168 | fprintf (file, "0,%s", reg_names[REGNO (tmp)]); |
0ac081f6 AH |
9169 | else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG) |
9170 | { | |
9171 | if (REGNO (XEXP (tmp, 0)) == 0) | |
9172 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ], | |
9173 | reg_names[ REGNO (XEXP (tmp, 0)) ]); | |
9174 | else | |
9175 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ], | |
9176 | reg_names[ REGNO (XEXP (tmp, 1)) ]); | |
9177 | } | |
9178 | else | |
9179 | abort (); | |
9180 | break; | |
9181 | } | |
9854d9ed | 9182 | |
9878760c RK |
9183 | case 0: |
9184 | if (GET_CODE (x) == REG) | |
9185 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
9186 | else if (GET_CODE (x) == MEM) | |
9187 | { | |
9188 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
9189 | know the width from the mode. */ | |
9190 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
9191 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
9192 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 9193 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
9194 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
9195 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 9196 | else |
a54d04b7 | 9197 | output_address (XEXP (x, 0)); |
9878760c RK |
9198 | } |
9199 | else | |
a54d04b7 | 9200 | output_addr_const (file, x); |
a85d226b | 9201 | return; |
9878760c | 9202 | |
c4501e62 JJ |
9203 | case '&': |
9204 | assemble_name (file, rs6000_get_some_local_dynamic_name ()); | |
9205 | return; | |
9206 | ||
9878760c RK |
9207 | default: |
9208 | output_operand_lossage ("invalid %%xn code"); | |
9209 | } | |
9210 | } | |
9211 | \f | |
9212 | /* Print the address of an operand. */ | |
9213 | ||
9214 | void | |
a2369ed3 | 9215 | print_operand_address (FILE *file, rtx x) |
9878760c RK |
9216 | { |
9217 | if (GET_CODE (x) == REG) | |
4697a36c | 9218 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
9219 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
9220 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
9221 | { |
9222 | output_addr_const (file, x); | |
ba5e43aa | 9223 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9224 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9225 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d | 9226 | else if (TARGET_TOC) |
a4f6c312 | 9227 | abort (); |
9878760c RK |
9228 | } |
9229 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
9230 | { | |
9231 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
9232 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
9233 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 9234 | else |
4697a36c MM |
9235 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
9236 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
9237 | } |
9238 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
4a0a75dd KG |
9239 | fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)", |
9240 | INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]); | |
3cb999d8 DE |
9241 | #if TARGET_ELF |
9242 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
9243 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
9244 | { |
9245 | output_addr_const (file, XEXP (x, 1)); | |
9246 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
9247 | } | |
c859cda6 DJ |
9248 | #endif |
9249 | #if TARGET_MACHO | |
9250 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
9251 | && CONSTANT_P (XEXP (x, 1))) | |
9252 | { | |
9253 | fprintf (file, "lo16("); | |
9254 | output_addr_const (file, XEXP (x, 1)); | |
9255 | fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
9256 | } | |
3cb999d8 | 9257 | #endif |
4d588c14 | 9258 | else if (legitimate_constant_pool_address_p (x)) |
9ebbca7d | 9259 | { |
2bfcf297 | 9260 | if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC)) |
9ebbca7d | 9261 | { |
2bfcf297 DB |
9262 | rtx contains_minus = XEXP (x, 1); |
9263 | rtx minus, symref; | |
9264 | const char *name; | |
9ebbca7d GK |
9265 | |
9266 | /* Find the (minus (sym) (toc)) buried in X, and temporarily | |
a4f6c312 | 9267 | turn it into (sym) for output_addr_const. */ |
9ebbca7d GK |
9268 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) |
9269 | contains_minus = XEXP (contains_minus, 0); | |
9270 | ||
2bfcf297 DB |
9271 | minus = XEXP (contains_minus, 0); |
9272 | symref = XEXP (minus, 0); | |
9273 | XEXP (contains_minus, 0) = symref; | |
9274 | if (TARGET_ELF) | |
9275 | { | |
9276 | char *newname; | |
9277 | ||
9278 | name = XSTR (symref, 0); | |
9279 | newname = alloca (strlen (name) + sizeof ("@toc")); | |
9280 | strcpy (newname, name); | |
9281 | strcat (newname, "@toc"); | |
9282 | XSTR (symref, 0) = newname; | |
9283 | } | |
9284 | output_addr_const (file, XEXP (x, 1)); | |
9285 | if (TARGET_ELF) | |
9286 | XSTR (symref, 0) = name; | |
9ebbca7d GK |
9287 | XEXP (contains_minus, 0) = minus; |
9288 | } | |
9289 | else | |
9290 | output_addr_const (file, XEXP (x, 1)); | |
9291 | ||
9292 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
9293 | } | |
9878760c RK |
9294 | else |
9295 | abort (); | |
9296 | } | |
9297 | \f | |
88cad84b | 9298 | /* Target hook for assembling integer objects. The PowerPC version has |
301d03af RS |
9299 | to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP |
9300 | is defined. It also needs to handle DI-mode objects on 64-bit | |
9301 | targets. */ | |
9302 | ||
9303 | static bool | |
a2369ed3 | 9304 | rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p) |
301d03af RS |
9305 | { |
9306 | #ifdef RELOCATABLE_NEEDS_FIXUP | |
9307 | /* Special handling for SI values. */ | |
9308 | if (size == 4 && aligned_p) | |
9309 | { | |
a2369ed3 | 9310 | extern int in_toc_section (void); |
301d03af RS |
9311 | static int recurse = 0; |
9312 | ||
9313 | /* For -mrelocatable, we mark all addresses that need to be fixed up | |
9314 | in the .fixup section. */ | |
9315 | if (TARGET_RELOCATABLE | |
9316 | && !in_toc_section () | |
9317 | && !in_text_section () | |
9318 | && !recurse | |
9319 | && GET_CODE (x) != CONST_INT | |
9320 | && GET_CODE (x) != CONST_DOUBLE | |
9321 | && CONSTANT_P (x)) | |
9322 | { | |
9323 | char buf[256]; | |
9324 | ||
9325 | recurse = 1; | |
9326 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno); | |
9327 | fixuplabelno++; | |
9328 | ASM_OUTPUT_LABEL (asm_out_file, buf); | |
9329 | fprintf (asm_out_file, "\t.long\t("); | |
9330 | output_addr_const (asm_out_file, x); | |
9331 | fprintf (asm_out_file, ")@fixup\n"); | |
9332 | fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n"); | |
9333 | ASM_OUTPUT_ALIGN (asm_out_file, 2); | |
9334 | fprintf (asm_out_file, "\t.long\t"); | |
9335 | assemble_name (asm_out_file, buf); | |
9336 | fprintf (asm_out_file, "\n\t.previous\n"); | |
9337 | recurse = 0; | |
9338 | return true; | |
9339 | } | |
9340 | /* Remove initial .'s to turn a -mcall-aixdesc function | |
9341 | address into the address of the descriptor, not the function | |
9342 | itself. */ | |
9343 | else if (GET_CODE (x) == SYMBOL_REF | |
9344 | && XSTR (x, 0)[0] == '.' | |
9345 | && DEFAULT_ABI == ABI_AIX) | |
9346 | { | |
9347 | const char *name = XSTR (x, 0); | |
9348 | while (*name == '.') | |
9349 | name++; | |
9350 | ||
9351 | fprintf (asm_out_file, "\t.long\t%s\n", name); | |
9352 | return true; | |
9353 | } | |
9354 | } | |
9355 | #endif /* RELOCATABLE_NEEDS_FIXUP */ | |
9356 | return default_assemble_integer (x, size, aligned_p); | |
9357 | } | |
93638d7a AM |
9358 | |
9359 | #ifdef HAVE_GAS_HIDDEN | |
9360 | /* Emit an assembler directive to set symbol visibility for DECL to | |
9361 | VISIBILITY_TYPE. */ | |
9362 | ||
5add3202 | 9363 | static void |
a2369ed3 | 9364 | rs6000_assemble_visibility (tree decl, int vis) |
93638d7a | 9365 | { |
93638d7a AM |
9366 | /* Functions need to have their entry point symbol visibility set as |
9367 | well as their descriptor symbol visibility. */ | |
9368 | if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL) | |
9369 | { | |
25fdb4dc RH |
9370 | static const char * const visibility_types[] = { |
9371 | NULL, "internal", "hidden", "protected" | |
9372 | }; | |
9373 | ||
9374 | const char *name, *type; | |
93638d7a AM |
9375 | |
9376 | name = ((* targetm.strip_name_encoding) | |
9377 | (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)))); | |
25fdb4dc | 9378 | type = visibility_types[vis]; |
93638d7a | 9379 | |
25fdb4dc RH |
9380 | fprintf (asm_out_file, "\t.%s\t%s\n", type, name); |
9381 | fprintf (asm_out_file, "\t.%s\t.%s\n", type, name); | |
93638d7a | 9382 | } |
25fdb4dc RH |
9383 | else |
9384 | default_assemble_visibility (decl, vis); | |
93638d7a AM |
9385 | } |
9386 | #endif | |
301d03af | 9387 | \f |
39a10a29 | 9388 | enum rtx_code |
a2369ed3 | 9389 | rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code) |
39a10a29 GK |
9390 | { |
9391 | /* Reversal of FP compares takes care -- an ordered compare | |
9392 | becomes an unordered compare and vice versa. */ | |
bc9ec0e0 GK |
9393 | if (mode == CCFPmode |
9394 | && (!flag_finite_math_only | |
9395 | || code == UNLT || code == UNLE || code == UNGT || code == UNGE | |
9396 | || code == UNEQ || code == LTGT)) | |
bab6226b | 9397 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 9398 | else |
bab6226b | 9399 | return reverse_condition (code); |
39a10a29 GK |
9400 | } |
9401 | ||
39a10a29 GK |
9402 | /* Generate a compare for CODE. Return a brand-new rtx that |
9403 | represents the result of the compare. */ | |
a4f6c312 | 9404 | |
39a10a29 | 9405 | static rtx |
a2369ed3 | 9406 | rs6000_generate_compare (enum rtx_code code) |
39a10a29 GK |
9407 | { |
9408 | enum machine_mode comp_mode; | |
9409 | rtx compare_result; | |
9410 | ||
9411 | if (rs6000_compare_fp_p) | |
9412 | comp_mode = CCFPmode; | |
9413 | else if (code == GTU || code == LTU | |
9414 | || code == GEU || code == LEU) | |
9415 | comp_mode = CCUNSmode; | |
9416 | else | |
9417 | comp_mode = CCmode; | |
9418 | ||
9419 | /* First, the compare. */ | |
9420 | compare_result = gen_reg_rtx (comp_mode); | |
a3170dc6 AH |
9421 | |
9422 | /* SPE FP compare instructions on the GPRs. Yuck! */ | |
993f19a8 AH |
9423 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) |
9424 | && rs6000_compare_fp_p) | |
a3170dc6 AH |
9425 | { |
9426 | rtx cmp, or1, or2, or_result, compare_result2; | |
9427 | ||
9428 | switch (code) | |
9429 | { | |
9430 | case EQ: | |
9431 | case UNEQ: | |
9432 | case NE: | |
9433 | case LTGT: | |
bc9ec0e0 | 9434 | cmp = flag_finite_math_only |
a3170dc6 AH |
9435 | ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0, |
9436 | rs6000_compare_op1) | |
9437 | : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0, | |
9438 | rs6000_compare_op1); | |
9439 | break; | |
9440 | case GT: | |
9441 | case GTU: | |
9442 | case UNGT: | |
9443 | case UNGE: | |
9444 | case GE: | |
9445 | case GEU: | |
bc9ec0e0 | 9446 | cmp = flag_finite_math_only |
a3170dc6 AH |
9447 | ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0, |
9448 | rs6000_compare_op1) | |
9449 | : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0, | |
9450 | rs6000_compare_op1); | |
9451 | break; | |
9452 | case LT: | |
9453 | case LTU: | |
9454 | case UNLT: | |
9455 | case UNLE: | |
9456 | case LE: | |
9457 | case LEU: | |
bc9ec0e0 | 9458 | cmp = flag_finite_math_only |
a3170dc6 AH |
9459 | ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0, |
9460 | rs6000_compare_op1) | |
9461 | : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0, | |
9462 | rs6000_compare_op1); | |
9463 | break; | |
9464 | default: | |
9465 | abort (); | |
9466 | } | |
9467 | ||
9468 | /* Synthesize LE and GE from LT/GT || EQ. */ | |
9469 | if (code == LE || code == GE || code == LEU || code == GEU) | |
9470 | { | |
9471 | /* Synthesize GE/LE frome GT/LT || EQ. */ | |
9472 | ||
9473 | emit_insn (cmp); | |
9474 | ||
9475 | switch (code) | |
9476 | { | |
9477 | case LE: code = LT; break; | |
9478 | case GE: code = GT; break; | |
9479 | case LEU: code = LT; break; | |
9480 | case GEU: code = GT; break; | |
9481 | default: abort (); | |
9482 | } | |
9483 | ||
9484 | or1 = gen_reg_rtx (SImode); | |
9485 | or2 = gen_reg_rtx (SImode); | |
9486 | or_result = gen_reg_rtx (CCEQmode); | |
9487 | compare_result2 = gen_reg_rtx (CCFPmode); | |
9488 | ||
9489 | /* Do the EQ. */ | |
bc9ec0e0 | 9490 | cmp = flag_finite_math_only |
a3170dc6 AH |
9491 | ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0, |
9492 | rs6000_compare_op1) | |
9493 | : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0, | |
9494 | rs6000_compare_op1); | |
9495 | emit_insn (cmp); | |
9496 | ||
9497 | /* The MC8540 FP compare instructions set the CR bits | |
9498 | differently than other PPC compare instructions. For | |
9499 | that matter, there is no generic test instruction, but a | |
9500 | testgt, testlt, and testeq. For a true condition, bit 2 | |
9501 | is set (x1xx) in the CR. Following the traditional CR | |
9502 | values: | |
9503 | ||
9504 | LT GT EQ OV | |
9505 | bit3 bit2 bit1 bit0 | |
9506 | ||
9507 | ... bit 2 would be a GT CR alias, so later on we | |
b6d08ca1 | 9508 | look in the GT bits for the branch instructions. |
a3170dc6 AH |
9509 | However, we must be careful to emit correct RTL in |
9510 | the meantime, so optimizations don't get confused. */ | |
9511 | ||
9512 | or1 = gen_rtx (NE, SImode, compare_result, const0_rtx); | |
9513 | or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx); | |
9514 | ||
9515 | /* OR them together. */ | |
9516 | cmp = gen_rtx_SET (VOIDmode, or_result, | |
9517 | gen_rtx_COMPARE (CCEQmode, | |
9518 | gen_rtx_IOR (SImode, or1, or2), | |
9519 | const_true_rtx)); | |
9520 | compare_result = or_result; | |
9521 | code = EQ; | |
9522 | } | |
9523 | else | |
9524 | { | |
9525 | /* We only care about 1 bit (x1xx), so map everything to NE to | |
9526 | maintain rtl sanity. We'll get to the right bit (x1xx) at | |
9527 | code output time. */ | |
9528 | if (code == NE || code == LTGT) | |
9529 | /* Do the inverse here because we have no cmpne | |
9530 | instruction. We use the cmpeq instruction and expect | |
9531 | to get a 0 instead. */ | |
9532 | code = EQ; | |
9533 | else | |
9534 | code = NE; | |
9535 | } | |
9536 | ||
9537 | emit_insn (cmp); | |
9538 | } | |
9539 | else | |
9540 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
9541 | gen_rtx_COMPARE (comp_mode, | |
9542 | rs6000_compare_op0, | |
9543 | rs6000_compare_op1))); | |
39a10a29 | 9544 | |
ca5adc63 | 9545 | /* Some kinds of FP comparisons need an OR operation; |
bc9ec0e0 | 9546 | under flag_finite_math_only we don't bother. */ |
39a10a29 | 9547 | if (rs6000_compare_fp_p |
bc9ec0e0 | 9548 | && ! flag_finite_math_only |
993f19a8 | 9549 | && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS) |
39a10a29 GK |
9550 | && (code == LE || code == GE |
9551 | || code == UNEQ || code == LTGT | |
9552 | || code == UNGT || code == UNLT)) | |
9553 | { | |
9554 | enum rtx_code or1, or2; | |
9555 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
9556 | rtx or_result = gen_reg_rtx (CCEQmode); | |
9557 | ||
9558 | switch (code) | |
9559 | { | |
9560 | case LE: or1 = LT; or2 = EQ; break; | |
9561 | case GE: or1 = GT; or2 = EQ; break; | |
9562 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
9563 | case LTGT: or1 = LT; or2 = GT; break; | |
9564 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
9565 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
9566 | default: abort (); | |
9567 | } | |
9568 | validate_condition_mode (or1, comp_mode); | |
9569 | validate_condition_mode (or2, comp_mode); | |
9570 | or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx); | |
9571 | or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx); | |
9572 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, | |
9573 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
9574 | const_true_rtx); | |
9575 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
9576 | ||
9577 | compare_result = or_result; | |
9578 | code = EQ; | |
9579 | } | |
9580 | ||
9581 | validate_condition_mode (code, GET_MODE (compare_result)); | |
9582 | ||
9583 | return gen_rtx (code, VOIDmode, compare_result, const0_rtx); | |
9584 | } | |
9585 | ||
9586 | ||
9587 | /* Emit the RTL for an sCOND pattern. */ | |
9588 | ||
9589 | void | |
a2369ed3 | 9590 | rs6000_emit_sCOND (enum rtx_code code, rtx result) |
39a10a29 GK |
9591 | { |
9592 | rtx condition_rtx; | |
9593 | enum machine_mode op_mode; | |
b7053a3f | 9594 | enum rtx_code cond_code; |
39a10a29 GK |
9595 | |
9596 | condition_rtx = rs6000_generate_compare (code); | |
b7053a3f GK |
9597 | cond_code = GET_CODE (condition_rtx); |
9598 | ||
9599 | if (cond_code == NE | |
9600 | || cond_code == GE || cond_code == LE | |
9601 | || cond_code == GEU || cond_code == LEU | |
9602 | || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE) | |
9603 | { | |
9604 | rtx not_result = gen_reg_rtx (CCEQmode); | |
9605 | rtx not_op, rev_cond_rtx; | |
9606 | enum machine_mode cc_mode; | |
9607 | ||
9608 | cc_mode = GET_MODE (XEXP (condition_rtx, 0)); | |
9609 | ||
9610 | rev_cond_rtx = gen_rtx (rs6000_reverse_condition (cc_mode, cond_code), | |
9611 | SImode, XEXP (condition_rtx, 0), const0_rtx); | |
9612 | not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx); | |
9613 | emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op)); | |
9614 | condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx); | |
9615 | } | |
39a10a29 GK |
9616 | |
9617 | op_mode = GET_MODE (rs6000_compare_op0); | |
9618 | if (op_mode == VOIDmode) | |
9619 | op_mode = GET_MODE (rs6000_compare_op1); | |
9620 | ||
9621 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
9622 | { | |
9623 | PUT_MODE (condition_rtx, DImode); | |
9624 | convert_move (result, condition_rtx, 0); | |
9625 | } | |
9626 | else | |
9627 | { | |
9628 | PUT_MODE (condition_rtx, SImode); | |
9629 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
9630 | } | |
9631 | } | |
9632 | ||
39a10a29 GK |
9633 | /* Emit a branch of kind CODE to location LOC. */ |
9634 | ||
9635 | void | |
a2369ed3 | 9636 | rs6000_emit_cbranch (enum rtx_code code, rtx loc) |
39a10a29 GK |
9637 | { |
9638 | rtx condition_rtx, loc_ref; | |
9639 | ||
9640 | condition_rtx = rs6000_generate_compare (code); | |
9641 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
9642 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
9643 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
9644 | loc_ref, pc_rtx))); | |
9645 | } | |
9646 | ||
12a4e8c5 GK |
9647 | /* Return the string to output a conditional branch to LABEL, which is |
9648 | the operand number of the label, or -1 if the branch is really a | |
9649 | conditional return. | |
9650 | ||
9651 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
9652 | condition code register and its mode specifies what kind of | |
9653 | comparison we made. | |
9654 | ||
a0ab749a | 9655 | REVERSED is nonzero if we should reverse the sense of the comparison. |
12a4e8c5 GK |
9656 | |
9657 | INSN is the insn. */ | |
9658 | ||
9659 | char * | |
a2369ed3 | 9660 | output_cbranch (rtx op, const char *label, int reversed, rtx insn) |
12a4e8c5 GK |
9661 | { |
9662 | static char string[64]; | |
9663 | enum rtx_code code = GET_CODE (op); | |
9664 | rtx cc_reg = XEXP (op, 0); | |
9665 | enum machine_mode mode = GET_MODE (cc_reg); | |
9666 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 9667 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
9668 | int really_reversed = reversed ^ need_longbranch; |
9669 | char *s = string; | |
9670 | const char *ccode; | |
9671 | const char *pred; | |
9672 | rtx note; | |
9673 | ||
39a10a29 GK |
9674 | validate_condition_mode (code, mode); |
9675 | ||
9676 | /* Work out which way this really branches. We could use | |
9677 | reverse_condition_maybe_unordered here always but this | |
9678 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 9679 | if (really_reversed) |
de40e1df DJ |
9680 | { |
9681 | /* Reversal of FP compares takes care -- an ordered compare | |
9682 | becomes an unordered compare and vice versa. */ | |
9683 | if (mode == CCFPmode) | |
9684 | code = reverse_condition_maybe_unordered (code); | |
9685 | else | |
9686 | code = reverse_condition (code); | |
9687 | } | |
12a4e8c5 | 9688 | |
993f19a8 | 9689 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode) |
a3170dc6 AH |
9690 | { |
9691 | /* The efscmp/tst* instructions twiddle bit 2, which maps nicely | |
9692 | to the GT bit. */ | |
9693 | if (code == EQ) | |
9694 | /* Opposite of GT. */ | |
9695 | code = UNLE; | |
9696 | else if (code == NE) | |
9697 | code = GT; | |
9698 | else | |
9699 | abort (); | |
9700 | } | |
9701 | ||
39a10a29 | 9702 | switch (code) |
12a4e8c5 GK |
9703 | { |
9704 | /* Not all of these are actually distinct opcodes, but | |
9705 | we distinguish them for clarity of the resulting assembler. */ | |
50a0b056 GK |
9706 | case NE: case LTGT: |
9707 | ccode = "ne"; break; | |
9708 | case EQ: case UNEQ: | |
9709 | ccode = "eq"; break; | |
9710 | case GE: case GEU: | |
9711 | ccode = "ge"; break; | |
9712 | case GT: case GTU: case UNGT: | |
9713 | ccode = "gt"; break; | |
9714 | case LE: case LEU: | |
9715 | ccode = "le"; break; | |
9716 | case LT: case LTU: case UNLT: | |
9717 | ccode = "lt"; break; | |
12a4e8c5 GK |
9718 | case UNORDERED: ccode = "un"; break; |
9719 | case ORDERED: ccode = "nu"; break; | |
9720 | case UNGE: ccode = "nl"; break; | |
9721 | case UNLE: ccode = "ng"; break; | |
9722 | default: | |
a4f6c312 | 9723 | abort (); |
12a4e8c5 GK |
9724 | } |
9725 | ||
94a54f47 GK |
9726 | /* Maybe we have a guess as to how likely the branch is. |
9727 | The old mnemonics don't have a way to specify this information. */ | |
f4857b9b | 9728 | pred = ""; |
12a4e8c5 GK |
9729 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
9730 | if (note != NULL_RTX) | |
9731 | { | |
9732 | /* PROB is the difference from 50%. */ | |
9733 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
f4857b9b AM |
9734 | bool always_hint = rs6000_cpu != PROCESSOR_POWER4; |
9735 | ||
9736 | /* Only hint for highly probable/improbable branches on newer | |
9737 | cpus as static prediction overrides processor dynamic | |
9738 | prediction. For older cpus we may as well always hint, but | |
9739 | assume not taken for branches that are very close to 50% as a | |
9740 | mispredicted taken branch is more expensive than a | |
9741 | mispredicted not-taken branch. */ | |
9742 | if (always_hint | |
9743 | || abs (prob) > REG_BR_PROB_BASE / 100 * 48) | |
9744 | { | |
9745 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
9746 | && ((prob > 0) ^ need_longbranch)) | |
7f3d8013 | 9747 | pred = "+"; |
f4857b9b AM |
9748 | else |
9749 | pred = "-"; | |
9750 | } | |
12a4e8c5 | 9751 | } |
12a4e8c5 GK |
9752 | |
9753 | if (label == NULL) | |
94a54f47 | 9754 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 9755 | else |
94a54f47 | 9756 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 9757 | |
37c67319 GK |
9758 | /* We need to escape any '%' characters in the reg_names string. |
9759 | Assume they'd only be the first character... */ | |
9760 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') | |
9761 | *s++ = '%'; | |
94a54f47 | 9762 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
9763 | |
9764 | if (label != NULL) | |
9765 | { | |
9766 | /* If the branch distance was too far, we may have to use an | |
9767 | unconditional branch to go the distance. */ | |
9768 | if (need_longbranch) | |
44518ddd | 9769 | s += sprintf (s, ",$+8\n\tb %s", label); |
12a4e8c5 GK |
9770 | else |
9771 | s += sprintf (s, ",%s", label); | |
9772 | } | |
9773 | ||
9774 | return string; | |
9775 | } | |
50a0b056 GK |
9776 | |
9777 | /* Emit a conditional move: move TRUE_COND to DEST if OP of the | |
9778 | operands of the last comparison is nonzero/true, FALSE_COND if it | |
9779 | is zero/false. Return 0 if the hardware has no such operation. */ | |
a4f6c312 | 9780 | |
50a0b056 | 9781 | int |
a2369ed3 | 9782 | rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
50a0b056 GK |
9783 | { |
9784 | enum rtx_code code = GET_CODE (op); | |
9785 | rtx op0 = rs6000_compare_op0; | |
9786 | rtx op1 = rs6000_compare_op1; | |
9787 | REAL_VALUE_TYPE c1; | |
3148ad6d DJ |
9788 | enum machine_mode compare_mode = GET_MODE (op0); |
9789 | enum machine_mode result_mode = GET_MODE (dest); | |
50a0b056 GK |
9790 | rtx temp; |
9791 | ||
3148ad6d | 9792 | /* These modes should always match. */ |
a3170dc6 AH |
9793 | if (GET_MODE (op1) != compare_mode |
9794 | /* In the isel case however, we can use a compare immediate, so | |
9795 | op1 may be a small constant. */ | |
9796 | && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode))) | |
3148ad6d | 9797 | return 0; |
178c3eff | 9798 | if (GET_MODE (true_cond) != result_mode) |
3148ad6d | 9799 | return 0; |
178c3eff | 9800 | if (GET_MODE (false_cond) != result_mode) |
3148ad6d DJ |
9801 | return 0; |
9802 | ||
50a0b056 GK |
9803 | /* First, work out if the hardware can do this at all, or |
9804 | if it's too slow... */ | |
50a0b056 | 9805 | if (! rs6000_compare_fp_p) |
a3170dc6 AH |
9806 | { |
9807 | if (TARGET_ISEL) | |
9808 | return rs6000_emit_int_cmove (dest, op, true_cond, false_cond); | |
9809 | return 0; | |
9810 | } | |
50a0b056 GK |
9811 | |
9812 | /* Eliminate half of the comparisons by switching operands, this | |
9813 | makes the remaining code simpler. */ | |
9814 | if (code == UNLT || code == UNGT || code == UNORDERED || code == NE | |
bc9ec0e0 | 9815 | || code == LTGT || code == LT || code == UNLE) |
50a0b056 GK |
9816 | { |
9817 | code = reverse_condition_maybe_unordered (code); | |
9818 | temp = true_cond; | |
9819 | true_cond = false_cond; | |
9820 | false_cond = temp; | |
9821 | } | |
9822 | ||
9823 | /* UNEQ and LTGT take four instructions for a comparison with zero, | |
9824 | it'll probably be faster to use a branch here too. */ | |
bc9ec0e0 | 9825 | if (code == UNEQ && HONOR_NANS (compare_mode)) |
50a0b056 GK |
9826 | return 0; |
9827 | ||
9828 | if (GET_CODE (op1) == CONST_DOUBLE) | |
9829 | REAL_VALUE_FROM_CONST_DOUBLE (c1, op1); | |
9830 | ||
b6d08ca1 | 9831 | /* We're going to try to implement comparisons by performing |
50a0b056 GK |
9832 | a subtract, then comparing against zero. Unfortunately, |
9833 | Inf - Inf is NaN which is not zero, and so if we don't | |
27d30956 | 9834 | know that the operand is finite and the comparison |
50a0b056 | 9835 | would treat EQ different to UNORDERED, we can't do it. */ |
bc9ec0e0 | 9836 | if (HONOR_INFINITIES (compare_mode) |
50a0b056 | 9837 | && code != GT && code != UNGE |
045572c7 | 9838 | && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1)) |
50a0b056 GK |
9839 | /* Constructs of the form (a OP b ? a : b) are safe. */ |
9840 | && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond)) | |
9841 | || (! rtx_equal_p (op0, true_cond) | |
9842 | && ! rtx_equal_p (op1, true_cond)))) | |
9843 | return 0; | |
9844 | /* At this point we know we can use fsel. */ | |
9845 | ||
9846 | /* Reduce the comparison to a comparison against zero. */ | |
3148ad6d | 9847 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 9848 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 9849 | gen_rtx_MINUS (compare_mode, op0, op1))); |
50a0b056 | 9850 | op0 = temp; |
3148ad6d | 9851 | op1 = CONST0_RTX (compare_mode); |
50a0b056 GK |
9852 | |
9853 | /* If we don't care about NaNs we can reduce some of the comparisons | |
9854 | down to faster ones. */ | |
bc9ec0e0 | 9855 | if (! HONOR_NANS (compare_mode)) |
50a0b056 GK |
9856 | switch (code) |
9857 | { | |
9858 | case GT: | |
9859 | code = LE; | |
9860 | temp = true_cond; | |
9861 | true_cond = false_cond; | |
9862 | false_cond = temp; | |
9863 | break; | |
9864 | case UNGE: | |
9865 | code = GE; | |
9866 | break; | |
9867 | case UNEQ: | |
9868 | code = EQ; | |
9869 | break; | |
9870 | default: | |
9871 | break; | |
9872 | } | |
9873 | ||
9874 | /* Now, reduce everything down to a GE. */ | |
9875 | switch (code) | |
9876 | { | |
9877 | case GE: | |
9878 | break; | |
9879 | ||
9880 | case LE: | |
3148ad6d DJ |
9881 | temp = gen_reg_rtx (compare_mode); |
9882 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
9883 | op0 = temp; |
9884 | break; | |
9885 | ||
9886 | case ORDERED: | |
3148ad6d DJ |
9887 | temp = gen_reg_rtx (compare_mode); |
9888 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0))); | |
50a0b056 GK |
9889 | op0 = temp; |
9890 | break; | |
9891 | ||
9892 | case EQ: | |
3148ad6d | 9893 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 9894 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d DJ |
9895 | gen_rtx_NEG (compare_mode, |
9896 | gen_rtx_ABS (compare_mode, op0)))); | |
50a0b056 GK |
9897 | op0 = temp; |
9898 | break; | |
9899 | ||
9900 | case UNGE: | |
bc9ec0e0 | 9901 | /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */ |
3148ad6d | 9902 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 9903 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 9904 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
9905 | gen_rtx_GE (VOIDmode, |
9906 | op0, op1), | |
9907 | true_cond, false_cond))); | |
bc9ec0e0 GK |
9908 | false_cond = true_cond; |
9909 | true_cond = temp; | |
50a0b056 | 9910 | |
3148ad6d DJ |
9911 | temp = gen_reg_rtx (compare_mode); |
9912 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
9913 | op0 = temp; |
9914 | break; | |
9915 | ||
9916 | case GT: | |
bc9ec0e0 | 9917 | /* a GT 0 <-> (a GE 0 && -a UNLT 0) */ |
3148ad6d | 9918 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 9919 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 9920 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
9921 | gen_rtx_GE (VOIDmode, |
9922 | op0, op1), | |
9923 | true_cond, false_cond))); | |
bc9ec0e0 GK |
9924 | true_cond = false_cond; |
9925 | false_cond = temp; | |
50a0b056 | 9926 | |
3148ad6d DJ |
9927 | temp = gen_reg_rtx (compare_mode); |
9928 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
9929 | op0 = temp; |
9930 | break; | |
9931 | ||
9932 | default: | |
9933 | abort (); | |
9934 | } | |
9935 | ||
9936 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3148ad6d | 9937 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
9938 | gen_rtx_GE (VOIDmode, |
9939 | op0, op1), | |
9940 | true_cond, false_cond))); | |
9941 | return 1; | |
9942 | } | |
9943 | ||
a3170dc6 AH |
9944 | /* Same as above, but for ints (isel). */ |
9945 | ||
9946 | static int | |
a2369ed3 | 9947 | rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
a3170dc6 AH |
9948 | { |
9949 | rtx condition_rtx, cr; | |
9950 | ||
9951 | /* All isel implementations thus far are 32-bits. */ | |
9952 | if (GET_MODE (rs6000_compare_op0) != SImode) | |
9953 | return 0; | |
9954 | ||
9955 | /* We still have to do the compare, because isel doesn't do a | |
9956 | compare, it just looks at the CRx bits set by a previous compare | |
9957 | instruction. */ | |
9958 | condition_rtx = rs6000_generate_compare (GET_CODE (op)); | |
9959 | cr = XEXP (condition_rtx, 0); | |
9960 | ||
9961 | if (GET_MODE (cr) == CCmode) | |
9962 | emit_insn (gen_isel_signed (dest, condition_rtx, | |
9963 | true_cond, false_cond, cr)); | |
9964 | else | |
9965 | emit_insn (gen_isel_unsigned (dest, condition_rtx, | |
9966 | true_cond, false_cond, cr)); | |
9967 | ||
9968 | return 1; | |
9969 | } | |
9970 | ||
9971 | const char * | |
a2369ed3 | 9972 | output_isel (rtx *operands) |
a3170dc6 AH |
9973 | { |
9974 | enum rtx_code code; | |
9975 | ||
9976 | code = GET_CODE (operands[1]); | |
9977 | if (code == GE || code == GEU || code == LE || code == LEU || code == NE) | |
9978 | { | |
9979 | PUT_CODE (operands[1], reverse_condition (code)); | |
9980 | return "isel %0,%3,%2,%j1"; | |
9981 | } | |
9982 | else | |
9983 | return "isel %0,%2,%3,%j1"; | |
9984 | } | |
9985 | ||
50a0b056 | 9986 | void |
a2369ed3 | 9987 | rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1) |
50a0b056 GK |
9988 | { |
9989 | enum machine_mode mode = GET_MODE (op0); | |
5dc8d536 | 9990 | enum rtx_code c; |
50a0b056 | 9991 | rtx target; |
5dc8d536 AH |
9992 | |
9993 | if (code == SMAX || code == SMIN) | |
9994 | c = GE; | |
9995 | else | |
9996 | c = GEU; | |
9997 | ||
50a0b056 | 9998 | if (code == SMAX || code == UMAX) |
5dc8d536 | 9999 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
10000 | op0, op1, mode, 0); |
10001 | else | |
5dc8d536 | 10002 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
10003 | op1, op0, mode, 0); |
10004 | if (target == NULL_RTX) | |
10005 | abort (); | |
10006 | if (target != dest) | |
10007 | emit_move_insn (dest, target); | |
10008 | } | |
46c07df8 | 10009 | |
3a1f863f | 10010 | /* Called by splitter for multireg moves. |
46c07df8 HP |
10011 | Input: |
10012 | operands[0] : Destination of move | |
10013 | operands[1] : Source of move | |
3a1f863f | 10014 | |
46c07df8 | 10015 | Output: |
3a1f863f DE |
10016 | operands[2-n] : Destination slots |
10017 | operands[n-m] : Source slots | |
10018 | where n = 2 + HARD_REGNO_NREGS (reg, GET_MODE (operands[0])) | |
10019 | m = 2 + 2 * HARD_REGNO_NREGS (reg, GET_MODE (operands[0])) - 1 | |
46c07df8 HP |
10020 | |
10021 | Splits the move of operands[1] to operands[0]. | |
10022 | This is done, if GPRs are one of the operands. In this case | |
10023 | a sequence of simple move insns has to be issued. The sequence of these | |
10024 | move insns has to be done in correct order to avoid early clobber of the | |
10025 | base register or destructive overlap of registers. | |
10026 | */ | |
10027 | ||
10028 | void | |
3a1f863f | 10029 | rs6000_split_multireg_move (rtx *operands) |
46c07df8 | 10030 | { |
3a1f863f | 10031 | int nregs, reg, i, j, used_update = 0; |
46c07df8 | 10032 | enum machine_mode mode; |
3a1f863f DE |
10033 | rtx dst = operands[0]; |
10034 | rtx src = operands[1]; | |
10035 | rtx insn = 0; | |
46c07df8 HP |
10036 | |
10037 | /* Calculate number to move (2/4 for 32/64 bit mode). */ | |
10038 | ||
10039 | reg = REG_P (operands[0]) ? REGNO (operands[0]) : REGNO (operands[1]); | |
10040 | mode = GET_MODE (operands[0]); | |
10041 | nregs = HARD_REGNO_NREGS (reg, mode); | |
10042 | ||
10043 | if (REG_P (operands[1]) | |
10044 | && REG_P (operands[0]) | |
10045 | && (REGNO (operands[1]) < REGNO (operands[0]))) | |
10046 | { | |
10047 | /* Move register range backwards, if we have destructive overlap. */ | |
10048 | ||
10049 | j = nregs; | |
10050 | for (i = 0; i < nregs; i++) | |
10051 | { | |
10052 | j--; | |
3a1f863f DE |
10053 | operands[i+2] = operand_subword (operands[0], j, 0, mode); |
10054 | operands[i+2+nregs] = | |
46c07df8 HP |
10055 | operand_subword (operands[1], j, 0, mode); |
10056 | } | |
10057 | } | |
10058 | else | |
10059 | { | |
10060 | j = -1; | |
10061 | ||
10062 | if (GET_CODE (operands[1]) == MEM) | |
10063 | { | |
10064 | rtx breg; | |
3a1f863f DE |
10065 | |
10066 | if (GET_CODE (XEXP (operands[1], 0)) == PRE_INC | |
10067 | || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC) | |
10068 | { | |
10069 | rtx delta_rtx; | |
10070 | breg = XEXP (XEXP (operands[1], 0), 0); | |
10071 | delta_rtx = GET_CODE (XEXP (operands[1], 0)) == PRE_INC | |
10072 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (operands[1]))) | |
10073 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (operands[1]))); | |
10074 | insn = emit_insn (TARGET_32BIT | |
10075 | ? gen_addsi3 (breg, breg, delta_rtx) | |
10076 | : gen_adddi3 (breg, breg, delta_rtx)); | |
10077 | src = gen_rtx_MEM (mode, breg); | |
10078 | } | |
10079 | ||
10080 | /* We have now address involving an base register only. | |
10081 | If we use one of the registers to address memory, | |
10082 | we have change that register last. */ | |
10083 | ||
10084 | breg = (GET_CODE (XEXP (src, 0)) == PLUS | |
10085 | ? XEXP (XEXP (src, 0), 0) | |
10086 | : XEXP (src, 0)); | |
10087 | ||
10088 | if (!REG_P (breg)) | |
10089 | abort(); | |
10090 | ||
10091 | if (REGNO (breg) >= REGNO (dst) | |
10092 | && REGNO (breg) < REGNO (dst) + nregs) | |
10093 | j = REGNO (breg) - REGNO (dst); | |
46c07df8 HP |
10094 | } |
10095 | ||
3a1f863f DE |
10096 | if (GET_CODE (operands[0]) == MEM) |
10097 | { | |
10098 | rtx breg; | |
10099 | ||
10100 | if (GET_CODE (XEXP (operands[0], 0)) == PRE_INC | |
10101 | || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC) | |
10102 | { | |
10103 | rtx delta_rtx; | |
10104 | breg = XEXP (XEXP (operands[0], 0), 0); | |
10105 | delta_rtx = GET_CODE (XEXP (operands[0], 0)) == PRE_INC | |
10106 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (operands[0]))) | |
10107 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (operands[0]))); | |
10108 | ||
10109 | /* We have to update the breg before doing the store. | |
10110 | Use store with update, if available. */ | |
10111 | ||
10112 | if (TARGET_UPDATE) | |
10113 | { | |
10114 | insn = emit_insn (TARGET_32BIT | |
10115 | ? gen_movsi_update (breg, breg, delta_rtx, | |
10116 | operand_subword (src, 0, 0, mode)) | |
10117 | : gen_movdi_update (breg, breg, delta_rtx, | |
10118 | operand_subword (src, 0, 0, mode))); | |
10119 | used_update = 1; | |
10120 | } | |
10121 | else | |
10122 | insn = emit_insn (TARGET_32BIT | |
10123 | ? gen_addsi3 (breg, breg, delta_rtx) | |
10124 | : gen_adddi3 (breg, breg, delta_rtx)); | |
10125 | dst = gen_rtx_MEM (mode, breg); | |
10126 | } | |
10127 | } | |
10128 | ||
46c07df8 | 10129 | for (i = 0; i < nregs; i++) |
3a1f863f DE |
10130 | { |
10131 | /* Calculate index to next subword. */ | |
10132 | ++j; | |
10133 | if (j == nregs) | |
10134 | j = 0; | |
46c07df8 | 10135 | |
3a1f863f DE |
10136 | operands[i+2] = operand_subword (dst, j, 0, mode); |
10137 | operands[i+2+nregs] = operand_subword (src, j, 0, mode); | |
46c07df8 | 10138 | |
3a1f863f DE |
10139 | if (j == 0 && used_update) |
10140 | { | |
10141 | /* Already emited move of first word by | |
10142 | store with update -> emit dead insn instead (r := r). */ | |
10143 | operands[i+2] = operands[i+2+nregs]; | |
10144 | } | |
10145 | } | |
46c07df8 HP |
10146 | } |
10147 | } | |
10148 | ||
12a4e8c5 | 10149 | \f |
a4f6c312 SS |
10150 | /* This page contains routines that are used to determine what the |
10151 | function prologue and epilogue code will do and write them out. */ | |
9878760c | 10152 | |
a4f6c312 SS |
10153 | /* Return the first fixed-point register that is required to be |
10154 | saved. 32 if none. */ | |
9878760c RK |
10155 | |
10156 | int | |
863d938c | 10157 | first_reg_to_save (void) |
9878760c RK |
10158 | { |
10159 | int first_reg; | |
10160 | ||
10161 | /* Find lowest numbered live register. */ | |
10162 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
a38d360d GK |
10163 | if (regs_ever_live[first_reg] |
10164 | && (! call_used_regs[first_reg] | |
1db02437 | 10165 | || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 10166 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 10167 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))) |
9878760c RK |
10168 | break; |
10169 | ||
ee890fe2 | 10170 | #if TARGET_MACHO |
93638d7a AM |
10171 | if (flag_pic |
10172 | && current_function_uses_pic_offset_table | |
10173 | && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM) | |
1db02437 | 10174 | return RS6000_PIC_OFFSET_TABLE_REGNUM; |
ee890fe2 SS |
10175 | #endif |
10176 | ||
9878760c RK |
10177 | return first_reg; |
10178 | } | |
10179 | ||
10180 | /* Similar, for FP regs. */ | |
10181 | ||
10182 | int | |
863d938c | 10183 | first_fp_reg_to_save (void) |
9878760c RK |
10184 | { |
10185 | int first_reg; | |
10186 | ||
10187 | /* Find lowest numbered live register. */ | |
10188 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
10189 | if (regs_ever_live[first_reg]) | |
10190 | break; | |
10191 | ||
10192 | return first_reg; | |
10193 | } | |
00b960c7 AH |
10194 | |
10195 | /* Similar, for AltiVec regs. */ | |
10196 | ||
10197 | static int | |
863d938c | 10198 | first_altivec_reg_to_save (void) |
00b960c7 AH |
10199 | { |
10200 | int i; | |
10201 | ||
10202 | /* Stack frame remains as is unless we are in AltiVec ABI. */ | |
10203 | if (! TARGET_ALTIVEC_ABI) | |
10204 | return LAST_ALTIVEC_REGNO + 1; | |
10205 | ||
10206 | /* Find lowest numbered live register. */ | |
10207 | for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i) | |
10208 | if (regs_ever_live[i]) | |
10209 | break; | |
10210 | ||
10211 | return i; | |
10212 | } | |
10213 | ||
10214 | /* Return a 32-bit mask of the AltiVec registers we need to set in | |
10215 | VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in | |
10216 | the 32-bit word is 0. */ | |
10217 | ||
10218 | static unsigned int | |
863d938c | 10219 | compute_vrsave_mask (void) |
00b960c7 AH |
10220 | { |
10221 | unsigned int i, mask = 0; | |
10222 | ||
10223 | /* First, find out if we use _any_ altivec registers. */ | |
10224 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
10225 | if (regs_ever_live[i]) | |
10226 | mask |= ALTIVEC_REG_BIT (i); | |
10227 | ||
10228 | if (mask == 0) | |
10229 | return mask; | |
10230 | ||
00b960c7 AH |
10231 | /* Next, remove the argument registers from the set. These must |
10232 | be in the VRSAVE mask set by the caller, so we don't need to add | |
10233 | them in again. More importantly, the mask we compute here is | |
10234 | used to generate CLOBBERs in the set_vrsave insn, and we do not | |
10235 | wish the argument registers to die. */ | |
a6cf80f2 | 10236 | for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i) |
00b960c7 AH |
10237 | mask &= ~ALTIVEC_REG_BIT (i); |
10238 | ||
10239 | /* Similarly, remove the return value from the set. */ | |
10240 | { | |
10241 | bool yes = false; | |
10242 | diddle_return_value (is_altivec_return_reg, &yes); | |
10243 | if (yes) | |
10244 | mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN); | |
10245 | } | |
10246 | ||
10247 | return mask; | |
10248 | } | |
10249 | ||
10250 | static void | |
a2369ed3 | 10251 | is_altivec_return_reg (rtx reg, void *xyes) |
00b960c7 AH |
10252 | { |
10253 | bool *yes = (bool *) xyes; | |
10254 | if (REGNO (reg) == ALTIVEC_ARG_RETURN) | |
10255 | *yes = true; | |
10256 | } | |
10257 | ||
4697a36c MM |
10258 | \f |
10259 | /* Calculate the stack information for the current function. This is | |
10260 | complicated by having two separate calling sequences, the AIX calling | |
10261 | sequence and the V.4 calling sequence. | |
10262 | ||
592696dd | 10263 | AIX (and Darwin/Mac OS X) stack frames look like: |
a260abc9 | 10264 | 32-bit 64-bit |
4697a36c | 10265 | SP----> +---------------------------------------+ |
a260abc9 | 10266 | | back chain to caller | 0 0 |
4697a36c | 10267 | +---------------------------------------+ |
a260abc9 | 10268 | | saved CR | 4 8 (8-11) |
4697a36c | 10269 | +---------------------------------------+ |
a260abc9 | 10270 | | saved LR | 8 16 |
4697a36c | 10271 | +---------------------------------------+ |
a260abc9 | 10272 | | reserved for compilers | 12 24 |
4697a36c | 10273 | +---------------------------------------+ |
a260abc9 | 10274 | | reserved for binders | 16 32 |
4697a36c | 10275 | +---------------------------------------+ |
a260abc9 | 10276 | | saved TOC pointer | 20 40 |
4697a36c | 10277 | +---------------------------------------+ |
a260abc9 | 10278 | | Parameter save area (P) | 24 48 |
4697a36c | 10279 | +---------------------------------------+ |
a260abc9 | 10280 | | Alloca space (A) | 24+P etc. |
802a0058 | 10281 | +---------------------------------------+ |
a7df97e6 | 10282 | | Local variable space (L) | 24+P+A |
4697a36c | 10283 | +---------------------------------------+ |
a7df97e6 | 10284 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 10285 | +---------------------------------------+ |
00b960c7 AH |
10286 | | Save area for AltiVec registers (W) | 24+P+A+L+X |
10287 | +---------------------------------------+ | |
10288 | | AltiVec alignment padding (Y) | 24+P+A+L+X+W | |
10289 | +---------------------------------------+ | |
10290 | | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y | |
4697a36c | 10291 | +---------------------------------------+ |
00b960c7 AH |
10292 | | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z |
10293 | +---------------------------------------+ | |
10294 | | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G | |
4697a36c MM |
10295 | +---------------------------------------+ |
10296 | old SP->| back chain to caller's caller | | |
10297 | +---------------------------------------+ | |
10298 | ||
5376a30c KR |
10299 | The required alignment for AIX configurations is two words (i.e., 8 |
10300 | or 16 bytes). | |
10301 | ||
10302 | ||
4697a36c MM |
10303 | V.4 stack frames look like: |
10304 | ||
10305 | SP----> +---------------------------------------+ | |
10306 | | back chain to caller | 0 | |
10307 | +---------------------------------------+ | |
5eb387b8 | 10308 | | caller's saved LR | 4 |
4697a36c MM |
10309 | +---------------------------------------+ |
10310 | | Parameter save area (P) | 8 | |
10311 | +---------------------------------------+ | |
a7df97e6 MM |
10312 | | Alloca space (A) | 8+P |
10313 | +---------------------------------------+ | |
10314 | | Varargs save area (V) | 8+P+A | |
10315 | +---------------------------------------+ | |
10316 | | Local variable space (L) | 8+P+A+V | |
10317 | +---------------------------------------+ | |
10318 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 10319 | +---------------------------------------+ |
00b960c7 AH |
10320 | | Save area for AltiVec registers (W) | 8+P+A+V+L+X |
10321 | +---------------------------------------+ | |
10322 | | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W | |
10323 | +---------------------------------------+ | |
10324 | | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y | |
10325 | +---------------------------------------+ | |
a3170dc6 AH |
10326 | | SPE: area for 64-bit GP registers | |
10327 | +---------------------------------------+ | |
10328 | | SPE alignment padding | | |
10329 | +---------------------------------------+ | |
00b960c7 | 10330 | | saved CR (C) | 8+P+A+V+L+X+W+Y+Z |
a7df97e6 | 10331 | +---------------------------------------+ |
00b960c7 | 10332 | | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C |
a7df97e6 | 10333 | +---------------------------------------+ |
00b960c7 | 10334 | | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G |
4697a36c MM |
10335 | +---------------------------------------+ |
10336 | old SP->| back chain to caller's caller | | |
10337 | +---------------------------------------+ | |
b6c9286a | 10338 | |
5376a30c KR |
10339 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
10340 | given. (But note below and in sysv4.h that we require only 8 and | |
10341 | may round up the size of our stack frame anyways. The historical | |
10342 | reason is early versions of powerpc-linux which didn't properly | |
10343 | align the stack at program startup. A happy side-effect is that | |
10344 | -mno-eabi libraries can be used with -meabi programs.) | |
10345 | ||
50d440bc | 10346 | The EABI configuration defaults to the V.4 layout. However, |
5376a30c KR |
10347 | the stack alignment requirements may differ. If -mno-eabi is not |
10348 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
10349 | given, the required alignment is 16 bytes. (But see V.4 comment | |
10350 | above.) */ | |
4697a36c | 10351 | |
61b2fbe7 MM |
10352 | #ifndef ABI_STACK_BOUNDARY |
10353 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
10354 | #endif | |
10355 | ||
d1d0c603 | 10356 | static rs6000_stack_t * |
863d938c | 10357 | rs6000_stack_info (void) |
4697a36c MM |
10358 | { |
10359 | static rs6000_stack_t info, zero_info; | |
10360 | rs6000_stack_t *info_ptr = &info; | |
9ebbca7d | 10361 | int reg_size = TARGET_POWERPC64 ? 8 : 4; |
83720594 | 10362 | int ehrd_size; |
d1d0c603 | 10363 | HOST_WIDE_INT total_raw_size; |
4697a36c | 10364 | |
a4f6c312 | 10365 | /* Zero all fields portably. */ |
4697a36c MM |
10366 | info = zero_info; |
10367 | ||
c19de7aa AH |
10368 | if (TARGET_SPE) |
10369 | { | |
10370 | /* Cache value so we don't rescan instruction chain over and over. */ | |
9b7b447f AH |
10371 | if (cfun->machine->insn_chain_scanned_p == 0) |
10372 | { | |
10373 | cfun->machine->insn_chain_scanned_p = 1; | |
10374 | info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p (); | |
10375 | } | |
c19de7aa AH |
10376 | } |
10377 | ||
a4f6c312 | 10378 | /* Select which calling sequence. */ |
178274da | 10379 | info_ptr->abi = DEFAULT_ABI; |
9878760c | 10380 | |
a4f6c312 | 10381 | /* Calculate which registers need to be saved & save area size. */ |
4697a36c | 10382 | info_ptr->first_gp_reg_save = first_reg_to_save (); |
1db02437 | 10383 | /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM, |
906fb125 | 10384 | even if it currently looks like we won't. */ |
2bfcf297 | 10385 | if (((TARGET_TOC && TARGET_MINIMAL_TOC) |
178274da AM |
10386 | || (flag_pic == 1 && DEFAULT_ABI == ABI_V4) |
10387 | || (flag_pic && DEFAULT_ABI == ABI_DARWIN)) | |
1db02437 FS |
10388 | && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM) |
10389 | info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM); | |
906fb125 GK |
10390 | else |
10391 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c | 10392 | |
a3170dc6 AH |
10393 | /* For the SPE, we have an additional upper 32-bits on each GPR. |
10394 | Ideally we should save the entire 64-bits only when the upper | |
10395 | half is used in SIMD instructions. Since we only record | |
10396 | registers live (not the size they are used in), this proves | |
10397 | difficult because we'd have to traverse the instruction chain at | |
10398 | the right time, taking reload into account. This is a real pain, | |
c19de7aa AH |
10399 | so we opt to save the GPRs in 64-bits always if but one register |
10400 | gets used in 64-bits. Otherwise, all the registers in the frame | |
10401 | get saved in 32-bits. | |
a3170dc6 | 10402 | |
c19de7aa | 10403 | So... since when we save all GPRs (except the SP) in 64-bits, the |
a3170dc6 | 10404 | traditional GP save area will be empty. */ |
c19de7aa | 10405 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
10406 | info_ptr->gp_size = 0; |
10407 | ||
4697a36c MM |
10408 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); |
10409 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
10410 | ||
00b960c7 AH |
10411 | info_ptr->first_altivec_reg_save = first_altivec_reg_to_save (); |
10412 | info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1 | |
10413 | - info_ptr->first_altivec_reg_save); | |
10414 | ||
592696dd | 10415 | /* Does this function call anything? */ |
71f123ca FS |
10416 | info_ptr->calls_p = (! current_function_is_leaf |
10417 | || cfun->machine->ra_needs_full_frame); | |
b6c9286a | 10418 | |
a4f6c312 | 10419 | /* Determine if we need to save the link register. */ |
71f123ca | 10420 | if (rs6000_ra_ever_killed () |
ffcfcb5f AM |
10421 | || (DEFAULT_ABI == ABI_AIX |
10422 | && current_function_profile | |
10423 | && !TARGET_PROFILE_KERNEL) | |
4697a36c MM |
10424 | #ifdef TARGET_RELOCATABLE |
10425 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
10426 | #endif | |
10427 | || (info_ptr->first_fp_reg_save != 64 | |
10428 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
00b960c7 | 10429 | || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO |
178274da | 10430 | || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca) |
a4f6c312 SS |
10431 | || (DEFAULT_ABI == ABI_DARWIN |
10432 | && flag_pic | |
10433 | && current_function_uses_pic_offset_table) | |
4697a36c MM |
10434 | || info_ptr->calls_p) |
10435 | { | |
10436 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 10437 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
10438 | } |
10439 | ||
9ebbca7d GK |
10440 | /* Determine if we need to save the condition code registers. */ |
10441 | if (regs_ever_live[CR2_REGNO] | |
10442 | || regs_ever_live[CR3_REGNO] | |
10443 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
10444 | { |
10445 | info_ptr->cr_save_p = 1; | |
178274da | 10446 | if (DEFAULT_ABI == ABI_V4) |
4697a36c MM |
10447 | info_ptr->cr_size = reg_size; |
10448 | } | |
10449 | ||
83720594 RH |
10450 | /* If the current function calls __builtin_eh_return, then we need |
10451 | to allocate stack space for registers that will hold data for | |
10452 | the exception handler. */ | |
10453 | if (current_function_calls_eh_return) | |
10454 | { | |
10455 | unsigned int i; | |
10456 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i) | |
10457 | continue; | |
a3170dc6 AH |
10458 | |
10459 | /* SPE saves EH registers in 64-bits. */ | |
c19de7aa AH |
10460 | ehrd_size = i * (TARGET_SPE_ABI |
10461 | && info_ptr->spe_64bit_regs_used != 0 | |
10462 | ? UNITS_PER_SPE_WORD : UNITS_PER_WORD); | |
83720594 RH |
10463 | } |
10464 | else | |
10465 | ehrd_size = 0; | |
10466 | ||
592696dd | 10467 | /* Determine various sizes. */ |
4697a36c MM |
10468 | info_ptr->reg_size = reg_size; |
10469 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
10470 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 | 10471 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
a4f6c312 SS |
10472 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, |
10473 | 8); | |
00b960c7 | 10474 | |
c19de7aa | 10475 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
10476 | info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save); |
10477 | else | |
10478 | info_ptr->spe_gp_size = 0; | |
10479 | ||
08b57fb3 | 10480 | if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE) |
00b960c7 AH |
10481 | { |
10482 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
10483 | info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0; | |
10484 | } | |
10485 | else | |
10486 | { | |
10487 | info_ptr->vrsave_mask = 0; | |
10488 | info_ptr->vrsave_size = 0; | |
10489 | } | |
b6c9286a | 10490 | |
592696dd | 10491 | /* Calculate the offsets. */ |
178274da | 10492 | switch (DEFAULT_ABI) |
4697a36c | 10493 | { |
b6c9286a | 10494 | case ABI_NONE: |
24d304eb | 10495 | default: |
b6c9286a MM |
10496 | abort (); |
10497 | ||
10498 | case ABI_AIX: | |
ee890fe2 | 10499 | case ABI_DARWIN: |
b6c9286a MM |
10500 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
10501 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
00b960c7 AH |
10502 | |
10503 | if (TARGET_ALTIVEC_ABI) | |
10504 | { | |
10505 | info_ptr->vrsave_save_offset | |
10506 | = info_ptr->gp_save_offset - info_ptr->vrsave_size; | |
10507 | ||
10508 | /* Align stack so vector save area is on a quadword boundary. */ | |
10509 | if (info_ptr->altivec_size != 0) | |
10510 | info_ptr->altivec_padding_size | |
10511 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
10512 | else | |
10513 | info_ptr->altivec_padding_size = 0; | |
10514 | ||
10515 | info_ptr->altivec_save_offset | |
10516 | = info_ptr->vrsave_save_offset | |
10517 | - info_ptr->altivec_padding_size | |
10518 | - info_ptr->altivec_size; | |
10519 | ||
10520 | /* Adjust for AltiVec case. */ | |
10521 | info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size; | |
10522 | } | |
10523 | else | |
10524 | info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size; | |
a260abc9 DE |
10525 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
10526 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
10527 | break; |
10528 | ||
10529 | case ABI_V4: | |
b6c9286a MM |
10530 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
10531 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 | 10532 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
00b960c7 | 10533 | |
c19de7aa | 10534 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
10535 | { |
10536 | /* Align stack so SPE GPR save area is aligned on a | |
10537 | double-word boundary. */ | |
10538 | if (info_ptr->spe_gp_size != 0) | |
10539 | info_ptr->spe_padding_size | |
10540 | = 8 - (-info_ptr->cr_save_offset % 8); | |
10541 | else | |
10542 | info_ptr->spe_padding_size = 0; | |
10543 | ||
10544 | info_ptr->spe_gp_save_offset | |
10545 | = info_ptr->cr_save_offset | |
10546 | - info_ptr->spe_padding_size | |
10547 | - info_ptr->spe_gp_size; | |
10548 | ||
10549 | /* Adjust for SPE case. */ | |
10550 | info_ptr->toc_save_offset | |
10551 | = info_ptr->spe_gp_save_offset - info_ptr->toc_size; | |
10552 | } | |
10553 | else if (TARGET_ALTIVEC_ABI) | |
00b960c7 AH |
10554 | { |
10555 | info_ptr->vrsave_save_offset | |
10556 | = info_ptr->cr_save_offset - info_ptr->vrsave_size; | |
10557 | ||
10558 | /* Align stack so vector save area is on a quadword boundary. */ | |
10559 | if (info_ptr->altivec_size != 0) | |
10560 | info_ptr->altivec_padding_size | |
10561 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
10562 | else | |
10563 | info_ptr->altivec_padding_size = 0; | |
10564 | ||
10565 | info_ptr->altivec_save_offset | |
10566 | = info_ptr->vrsave_save_offset | |
10567 | - info_ptr->altivec_padding_size | |
10568 | - info_ptr->altivec_size; | |
10569 | ||
10570 | /* Adjust for AltiVec case. */ | |
10571 | info_ptr->toc_save_offset | |
10572 | = info_ptr->altivec_save_offset - info_ptr->toc_size; | |
10573 | } | |
10574 | else | |
10575 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
83720594 | 10576 | info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size; |
b6c9286a MM |
10577 | info_ptr->lr_save_offset = reg_size; |
10578 | break; | |
4697a36c MM |
10579 | } |
10580 | ||
00b960c7 AH |
10581 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
10582 | + info_ptr->gp_size | |
10583 | + info_ptr->altivec_size | |
10584 | + info_ptr->altivec_padding_size | |
a3170dc6 AH |
10585 | + info_ptr->spe_gp_size |
10586 | + info_ptr->spe_padding_size | |
00b960c7 AH |
10587 | + ehrd_size |
10588 | + info_ptr->cr_size | |
10589 | + info_ptr->lr_size | |
10590 | + info_ptr->vrsave_size | |
10591 | + info_ptr->toc_size, | |
10592 | (TARGET_ALTIVEC_ABI || ABI_DARWIN) | |
10593 | ? 16 : 8); | |
10594 | ||
ff381587 MM |
10595 | total_raw_size = (info_ptr->vars_size |
10596 | + info_ptr->parm_size | |
ff381587 MM |
10597 | + info_ptr->save_size |
10598 | + info_ptr->varargs_size | |
10599 | + info_ptr->fixed_size); | |
10600 | ||
a4f6c312 SS |
10601 | info_ptr->total_size = |
10602 | RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
ff381587 MM |
10603 | |
10604 | /* Determine if we need to allocate any stack frame: | |
10605 | ||
a4f6c312 SS |
10606 | For AIX we need to push the stack if a frame pointer is needed |
10607 | (because the stack might be dynamically adjusted), if we are | |
10608 | debugging, if we make calls, or if the sum of fp_save, gp_save, | |
10609 | and local variables are more than the space needed to save all | |
10610 | non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 | |
10611 | + 18*8 = 288 (GPR13 reserved). | |
ff381587 | 10612 | |
a4f6c312 SS |
10613 | For V.4 we don't have the stack cushion that AIX uses, but assume |
10614 | that the debugger can handle stackless frames. */ | |
ff381587 MM |
10615 | |
10616 | if (info_ptr->calls_p) | |
10617 | info_ptr->push_p = 1; | |
10618 | ||
178274da | 10619 | else if (DEFAULT_ABI == ABI_V4) |
e72247f4 | 10620 | info_ptr->push_p = total_raw_size > info_ptr->fixed_size; |
ff381587 | 10621 | |
178274da AM |
10622 | else if (frame_pointer_needed) |
10623 | info_ptr->push_p = 1; | |
10624 | ||
10625 | else if (TARGET_XCOFF && write_symbols != NO_DEBUG) | |
10626 | info_ptr->push_p = 1; | |
10627 | ||
ff381587 | 10628 | else |
178274da AM |
10629 | info_ptr->push_p |
10630 | = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288); | |
ff381587 | 10631 | |
a4f6c312 | 10632 | /* Zero offsets if we're not saving those registers. */ |
8dda1a21 | 10633 | if (info_ptr->fp_size == 0) |
4697a36c MM |
10634 | info_ptr->fp_save_offset = 0; |
10635 | ||
8dda1a21 | 10636 | if (info_ptr->gp_size == 0) |
4697a36c MM |
10637 | info_ptr->gp_save_offset = 0; |
10638 | ||
00b960c7 AH |
10639 | if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0) |
10640 | info_ptr->altivec_save_offset = 0; | |
10641 | ||
10642 | if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0) | |
10643 | info_ptr->vrsave_save_offset = 0; | |
10644 | ||
c19de7aa AH |
10645 | if (! TARGET_SPE_ABI |
10646 | || info_ptr->spe_64bit_regs_used == 0 | |
10647 | || info_ptr->spe_gp_size == 0) | |
a3170dc6 AH |
10648 | info_ptr->spe_gp_save_offset = 0; |
10649 | ||
c81fc13e | 10650 | if (! info_ptr->lr_save_p) |
4697a36c MM |
10651 | info_ptr->lr_save_offset = 0; |
10652 | ||
c81fc13e | 10653 | if (! info_ptr->cr_save_p) |
4697a36c MM |
10654 | info_ptr->cr_save_offset = 0; |
10655 | ||
c81fc13e | 10656 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
10657 | info_ptr->toc_save_offset = 0; |
10658 | ||
4697a36c MM |
10659 | return info_ptr; |
10660 | } | |
10661 | ||
c19de7aa AH |
10662 | /* Return true if the current function uses any GPRs in 64-bit SIMD |
10663 | mode. */ | |
10664 | ||
10665 | static bool | |
863d938c | 10666 | spe_func_has_64bit_regs_p (void) |
c19de7aa AH |
10667 | { |
10668 | rtx insns, insn; | |
10669 | ||
10670 | /* Functions that save and restore all the call-saved registers will | |
10671 | need to save/restore the registers in 64-bits. */ | |
10672 | if (current_function_calls_eh_return | |
10673 | || current_function_calls_setjmp | |
10674 | || current_function_has_nonlocal_goto) | |
10675 | return true; | |
10676 | ||
10677 | insns = get_insns (); | |
10678 | ||
10679 | for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn)) | |
10680 | { | |
10681 | if (INSN_P (insn)) | |
10682 | { | |
10683 | rtx i; | |
10684 | ||
10685 | i = PATTERN (insn); | |
10686 | if (GET_CODE (i) == SET | |
10687 | && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i)))) | |
10688 | return true; | |
10689 | } | |
10690 | } | |
10691 | ||
10692 | return false; | |
10693 | } | |
10694 | ||
d1d0c603 | 10695 | static void |
a2369ed3 | 10696 | debug_stack_info (rs6000_stack_t *info) |
9878760c | 10697 | { |
d330fd93 | 10698 | const char *abi_string; |
24d304eb | 10699 | |
c81fc13e | 10700 | if (! info) |
4697a36c MM |
10701 | info = rs6000_stack_info (); |
10702 | ||
10703 | fprintf (stderr, "\nStack information for function %s:\n", | |
10704 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
10705 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
10706 | : "<unknown>")); | |
10707 | ||
24d304eb RK |
10708 | switch (info->abi) |
10709 | { | |
b6c9286a MM |
10710 | default: abi_string = "Unknown"; break; |
10711 | case ABI_NONE: abi_string = "NONE"; break; | |
50d440bc | 10712 | case ABI_AIX: abi_string = "AIX"; break; |
ee890fe2 | 10713 | case ABI_DARWIN: abi_string = "Darwin"; break; |
b6c9286a | 10714 | case ABI_V4: abi_string = "V.4"; break; |
24d304eb RK |
10715 | } |
10716 | ||
10717 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
10718 | ||
00b960c7 AH |
10719 | if (TARGET_ALTIVEC_ABI) |
10720 | fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n"); | |
10721 | ||
a3170dc6 AH |
10722 | if (TARGET_SPE_ABI) |
10723 | fprintf (stderr, "\tSPE ABI extensions enabled.\n"); | |
10724 | ||
4697a36c MM |
10725 | if (info->first_gp_reg_save != 32) |
10726 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
10727 | ||
10728 | if (info->first_fp_reg_save != 64) | |
10729 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 10730 | |
00b960c7 AH |
10731 | if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO) |
10732 | fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n", | |
10733 | info->first_altivec_reg_save); | |
10734 | ||
4697a36c MM |
10735 | if (info->lr_save_p) |
10736 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 10737 | |
4697a36c MM |
10738 | if (info->cr_save_p) |
10739 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
10740 | ||
b6c9286a MM |
10741 | if (info->toc_save_p) |
10742 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
10743 | ||
00b960c7 AH |
10744 | if (info->vrsave_mask) |
10745 | fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask); | |
10746 | ||
4697a36c MM |
10747 | if (info->push_p) |
10748 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
10749 | ||
10750 | if (info->calls_p) | |
10751 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
10752 | ||
4697a36c MM |
10753 | if (info->gp_save_offset) |
10754 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
10755 | ||
10756 | if (info->fp_save_offset) | |
10757 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
10758 | ||
00b960c7 AH |
10759 | if (info->altivec_save_offset) |
10760 | fprintf (stderr, "\taltivec_save_offset = %5d\n", | |
10761 | info->altivec_save_offset); | |
10762 | ||
a3170dc6 AH |
10763 | if (info->spe_gp_save_offset) |
10764 | fprintf (stderr, "\tspe_gp_save_offset = %5d\n", | |
10765 | info->spe_gp_save_offset); | |
10766 | ||
00b960c7 AH |
10767 | if (info->vrsave_save_offset) |
10768 | fprintf (stderr, "\tvrsave_save_offset = %5d\n", | |
10769 | info->vrsave_save_offset); | |
10770 | ||
4697a36c MM |
10771 | if (info->lr_save_offset) |
10772 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
10773 | ||
10774 | if (info->cr_save_offset) | |
10775 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
10776 | ||
b6c9286a MM |
10777 | if (info->toc_save_offset) |
10778 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
10779 | ||
4697a36c MM |
10780 | if (info->varargs_save_offset) |
10781 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
10782 | ||
10783 | if (info->total_size) | |
d1d0c603 JJ |
10784 | fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
10785 | info->total_size); | |
4697a36c MM |
10786 | |
10787 | if (info->varargs_size) | |
10788 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
10789 | ||
10790 | if (info->vars_size) | |
d1d0c603 JJ |
10791 | fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
10792 | info->vars_size); | |
4697a36c MM |
10793 | |
10794 | if (info->parm_size) | |
10795 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
10796 | ||
10797 | if (info->fixed_size) | |
10798 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
10799 | ||
10800 | if (info->gp_size) | |
10801 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
10802 | ||
a3170dc6 AH |
10803 | if (info->spe_gp_size) |
10804 | fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size); | |
10805 | ||
4697a36c MM |
10806 | if (info->fp_size) |
10807 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
10808 | ||
00b960c7 AH |
10809 | if (info->altivec_size) |
10810 | fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size); | |
10811 | ||
10812 | if (info->vrsave_size) | |
10813 | fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size); | |
10814 | ||
10815 | if (info->altivec_padding_size) | |
10816 | fprintf (stderr, "\taltivec_padding_size= %5d\n", | |
10817 | info->altivec_padding_size); | |
10818 | ||
a3170dc6 AH |
10819 | if (info->spe_padding_size) |
10820 | fprintf (stderr, "\tspe_padding_size = %5d\n", | |
10821 | info->spe_padding_size); | |
10822 | ||
a4f6c312 | 10823 | if (info->lr_size) |
ed947a96 | 10824 | fprintf (stderr, "\tlr_size = %5d\n", info->lr_size); |
b6c9286a | 10825 | |
4697a36c MM |
10826 | if (info->cr_size) |
10827 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
10828 | ||
a4f6c312 | 10829 | if (info->toc_size) |
b6c9286a MM |
10830 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); |
10831 | ||
4697a36c MM |
10832 | if (info->save_size) |
10833 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
10834 | ||
10835 | if (info->reg_size != 4) | |
10836 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
10837 | ||
10838 | fprintf (stderr, "\n"); | |
9878760c | 10839 | } |
71f123ca FS |
10840 | |
10841 | rtx | |
a2369ed3 | 10842 | rs6000_return_addr (int count, rtx frame) |
71f123ca | 10843 | { |
a4f6c312 SS |
10844 | /* Currently we don't optimize very well between prolog and body |
10845 | code and for PIC code the code can be actually quite bad, so | |
10846 | don't try to be too clever here. */ | |
f1384257 | 10847 | if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic)) |
71f123ca FS |
10848 | { |
10849 | cfun->machine->ra_needs_full_frame = 1; | |
8ac61af7 RK |
10850 | |
10851 | return | |
10852 | gen_rtx_MEM | |
10853 | (Pmode, | |
10854 | memory_address | |
10855 | (Pmode, | |
10856 | plus_constant (copy_to_reg | |
10857 | (gen_rtx_MEM (Pmode, | |
10858 | memory_address (Pmode, frame))), | |
10859 | RETURN_ADDRESS_OFFSET))); | |
71f123ca FS |
10860 | } |
10861 | ||
8c29550d | 10862 | cfun->machine->ra_need_lr = 1; |
9e2f7ec7 | 10863 | return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM); |
71f123ca FS |
10864 | } |
10865 | ||
5e1bf043 DJ |
10866 | /* Say whether a function is a candidate for sibcall handling or not. |
10867 | We do not allow indirect calls to be optimized into sibling calls. | |
10868 | Also, we can't do it if there are any vector parameters; there's | |
10869 | nowhere to put the VRsave code so it works; note that functions with | |
10870 | vector parameters are required to have a prototype, so the argument | |
10871 | type info must be available here. (The tail recursion case can work | |
10872 | with vector parameters, but there's no way to distinguish here.) */ | |
4977bab6 | 10873 | static bool |
a2369ed3 | 10874 | rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) |
5e1bf043 DJ |
10875 | { |
10876 | tree type; | |
4977bab6 | 10877 | if (decl) |
5e1bf043 DJ |
10878 | { |
10879 | if (TARGET_ALTIVEC_VRSAVE) | |
10880 | { | |
4977bab6 | 10881 | for (type = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
5e1bf043 DJ |
10882 | type; type = TREE_CHAIN (type)) |
10883 | { | |
c15b529f | 10884 | if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE) |
4977bab6 | 10885 | return false; |
5e1bf043 DJ |
10886 | } |
10887 | } | |
10888 | if (DEFAULT_ABI == ABI_DARWIN | |
4977bab6 | 10889 | || (*targetm.binds_local_p) (decl)) |
2bcc50d0 | 10890 | { |
4977bab6 | 10891 | tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
2bcc50d0 AM |
10892 | |
10893 | if (!lookup_attribute ("longcall", attr_list) | |
10894 | || lookup_attribute ("shortcall", attr_list)) | |
4977bab6 | 10895 | return true; |
2bcc50d0 | 10896 | } |
5e1bf043 | 10897 | } |
4977bab6 | 10898 | return false; |
5e1bf043 DJ |
10899 | } |
10900 | ||
71f123ca | 10901 | static int |
863d938c | 10902 | rs6000_ra_ever_killed (void) |
71f123ca FS |
10903 | { |
10904 | rtx top; | |
5e1bf043 DJ |
10905 | rtx reg; |
10906 | rtx insn; | |
71f123ca | 10907 | |
3961e8fe RH |
10908 | /* Irritatingly, there are two kinds of thunks -- those created with |
10909 | TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go | |
10910 | through the regular part of the compiler. This is a very hacky | |
10911 | way to tell them apart. */ | |
10912 | if (current_function_is_thunk && !no_new_pseudos) | |
71f123ca | 10913 | return 0; |
eb0424da | 10914 | |
36f7e964 AH |
10915 | /* regs_ever_live has LR marked as used if any sibcalls are present, |
10916 | but this should not force saving and restoring in the | |
10917 | pro/epilogue. Likewise, reg_set_between_p thinks a sibcall | |
10918 | clobbers LR, so that is inappropriate. */ | |
10919 | ||
5e1bf043 DJ |
10920 | /* Also, the prologue can generate a store into LR that |
10921 | doesn't really count, like this: | |
36f7e964 | 10922 | |
5e1bf043 DJ |
10923 | move LR->R0 |
10924 | bcl to set PIC register | |
10925 | move LR->R31 | |
10926 | move R0->LR | |
36f7e964 AH |
10927 | |
10928 | When we're called from the epilogue, we need to avoid counting | |
10929 | this as a store. */ | |
5e1bf043 | 10930 | |
71f123ca FS |
10931 | push_topmost_sequence (); |
10932 | top = get_insns (); | |
10933 | pop_topmost_sequence (); | |
5e1bf043 | 10934 | reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); |
71f123ca | 10935 | |
5e1bf043 DJ |
10936 | for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn)) |
10937 | { | |
10938 | if (INSN_P (insn)) | |
10939 | { | |
10940 | if (FIND_REG_INC_NOTE (insn, reg)) | |
10941 | return 1; | |
10942 | else if (GET_CODE (insn) == CALL_INSN | |
c15b529f | 10943 | && !SIBLING_CALL_P (insn)) |
5e1bf043 | 10944 | return 1; |
36f7e964 AH |
10945 | else if (set_of (reg, insn) != NULL_RTX |
10946 | && !prologue_epilogue_contains (insn)) | |
5e1bf043 DJ |
10947 | return 1; |
10948 | } | |
10949 | } | |
10950 | return 0; | |
71f123ca | 10951 | } |
4697a36c | 10952 | \f |
8cd8f856 GK |
10953 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
10954 | static void | |
a2369ed3 | 10955 | rs6000_maybe_dead (rtx insn) |
8cd8f856 GK |
10956 | { |
10957 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
10958 | const0_rtx, | |
10959 | REG_NOTES (insn)); | |
10960 | } | |
10961 | ||
9ebbca7d | 10962 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 10963 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 10964 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
10965 | |
10966 | void | |
a2369ed3 | 10967 | rs6000_emit_load_toc_table (int fromprolog) |
c7ca610e | 10968 | { |
027fbf43 | 10969 | rtx dest, insn; |
1db02437 | 10970 | dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); |
c7ca610e | 10971 | |
20b71b17 AM |
10972 | if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
10973 | { | |
10974 | rtx temp = (fromprolog | |
10975 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
10976 | : gen_reg_rtx (Pmode)); | |
027fbf43 JJ |
10977 | insn = emit_insn (gen_load_toc_v4_pic_si (temp)); |
10978 | if (fromprolog) | |
10979 | rs6000_maybe_dead (insn); | |
10980 | insn = emit_move_insn (dest, temp); | |
10981 | if (fromprolog) | |
10982 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
10983 | } |
10984 | else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2) | |
10985 | { | |
10986 | char buf[30]; | |
10987 | rtx tempLR = (fromprolog | |
10988 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
10989 | : gen_reg_rtx (Pmode)); | |
10990 | rtx temp0 = (fromprolog | |
10991 | ? gen_rtx_REG (Pmode, 0) | |
10992 | : gen_reg_rtx (Pmode)); | |
10993 | rtx symF; | |
10994 | ||
10995 | /* possibly create the toc section */ | |
10996 | if (! toc_initialized) | |
38c1f2d7 | 10997 | { |
20b71b17 AM |
10998 | toc_section (); |
10999 | function_section (current_function_decl); | |
38c1f2d7 | 11000 | } |
9ebbca7d | 11001 | |
20b71b17 AM |
11002 | if (fromprolog) |
11003 | { | |
11004 | rtx symL; | |
38c1f2d7 | 11005 | |
20b71b17 AM |
11006 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); |
11007 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9ebbca7d | 11008 | |
20b71b17 AM |
11009 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
11010 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11011 | ||
11012 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, | |
11013 | symF))); | |
11014 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
11015 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
11016 | symL, | |
11017 | symF))); | |
9ebbca7d GK |
11018 | } |
11019 | else | |
20b71b17 AM |
11020 | { |
11021 | rtx tocsym; | |
11022 | static int reload_toc_labelno = 0; | |
11023 | ||
11024 | tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); | |
11025 | ||
11026 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); | |
11027 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11028 | ||
027fbf43 JJ |
11029 | emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym)); |
11030 | emit_move_insn (dest, tempLR); | |
11031 | emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest)); | |
20b71b17 | 11032 | } |
027fbf43 JJ |
11033 | insn = emit_insn (gen_addsi3 (dest, temp0, dest)); |
11034 | if (fromprolog) | |
11035 | rs6000_maybe_dead (insn); | |
9ebbca7d | 11036 | } |
20b71b17 AM |
11037 | else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC) |
11038 | { | |
11039 | /* This is for AIX code running in non-PIC ELF32. */ | |
11040 | char buf[30]; | |
11041 | rtx realsym; | |
11042 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
11043 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11044 | ||
027fbf43 JJ |
11045 | insn = emit_insn (gen_elf_high (dest, realsym)); |
11046 | if (fromprolog) | |
11047 | rs6000_maybe_dead (insn); | |
11048 | insn = emit_insn (gen_elf_low (dest, dest, realsym)); | |
11049 | if (fromprolog) | |
11050 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
11051 | } |
11052 | else if (DEFAULT_ABI == ABI_AIX) | |
9ebbca7d GK |
11053 | { |
11054 | if (TARGET_32BIT) | |
027fbf43 | 11055 | insn = emit_insn (gen_load_toc_aix_si (dest)); |
9ebbca7d | 11056 | else |
027fbf43 JJ |
11057 | insn = emit_insn (gen_load_toc_aix_di (dest)); |
11058 | if (fromprolog) | |
11059 | rs6000_maybe_dead (insn); | |
9ebbca7d | 11060 | } |
20b71b17 AM |
11061 | else |
11062 | abort (); | |
9ebbca7d GK |
11063 | } |
11064 | ||
d1d0c603 JJ |
11065 | /* Emit instructions to restore the link register after determining where |
11066 | its value has been stored. */ | |
11067 | ||
11068 | void | |
11069 | rs6000_emit_eh_reg_restore (rtx source, rtx scratch) | |
11070 | { | |
11071 | rs6000_stack_t *info = rs6000_stack_info (); | |
11072 | rtx operands[2]; | |
11073 | ||
11074 | operands[0] = source; | |
11075 | operands[1] = scratch; | |
11076 | ||
11077 | if (info->lr_save_p) | |
11078 | { | |
11079 | rtx frame_rtx = stack_pointer_rtx; | |
11080 | HOST_WIDE_INT sp_offset = 0; | |
11081 | rtx tmp; | |
11082 | ||
11083 | if (frame_pointer_needed | |
11084 | || current_function_calls_alloca | |
11085 | || info->total_size > 32767) | |
11086 | { | |
11087 | emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx)); | |
11088 | frame_rtx = operands[1]; | |
11089 | } | |
11090 | else if (info->push_p) | |
11091 | sp_offset = info->total_size; | |
11092 | ||
11093 | tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset); | |
11094 | tmp = gen_rtx_MEM (Pmode, tmp); | |
11095 | emit_move_insn (tmp, operands[0]); | |
11096 | } | |
11097 | else | |
11098 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]); | |
11099 | } | |
11100 | ||
9ebbca7d | 11101 | int |
863d938c | 11102 | get_TOC_alias_set (void) |
9ebbca7d GK |
11103 | { |
11104 | static int set = -1; | |
11105 | if (set == -1) | |
11106 | set = new_alias_set (); | |
11107 | return set; | |
11108 | } | |
11109 | ||
c1207243 | 11110 | /* This returns nonzero if the current function uses the TOC. This is |
c4501e62 JJ |
11111 | determined by the presence of (unspec ... UNSPEC_TOC) or |
11112 | use (unspec ... UNSPEC_TOC), which are generated by the various | |
11113 | load_toc_* patterns. */ | |
a4f6c312 | 11114 | |
9ebbca7d | 11115 | int |
38f391a5 | 11116 | uses_TOC (void) |
9ebbca7d | 11117 | { |
c4501e62 | 11118 | rtx insn; |
38c1f2d7 | 11119 | |
c4501e62 JJ |
11120 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
11121 | if (INSN_P (insn)) | |
11122 | { | |
11123 | rtx pat = PATTERN (insn); | |
11124 | int i; | |
9ebbca7d | 11125 | |
c4501e62 JJ |
11126 | if (GET_CODE (pat) == PARALLEL) |
11127 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
11128 | { | |
11129 | rtx sub = XVECEXP (pat, 0, i); | |
11130 | if (GET_CODE (sub) == USE) | |
11131 | { | |
11132 | sub = XEXP (sub, 0); | |
11133 | if (GET_CODE (sub) == UNSPEC | |
11134 | && XINT (sub, 1) == UNSPEC_TOC) | |
11135 | return 1; | |
11136 | } | |
11137 | } | |
11138 | } | |
11139 | return 0; | |
9ebbca7d | 11140 | } |
38c1f2d7 | 11141 | |
9ebbca7d | 11142 | rtx |
a2369ed3 | 11143 | create_TOC_reference (rtx symbol) |
9ebbca7d | 11144 | { |
a8a05998 ZW |
11145 | return gen_rtx_PLUS (Pmode, |
11146 | gen_rtx_REG (Pmode, TOC_REGISTER), | |
11147 | gen_rtx_CONST (Pmode, | |
11148 | gen_rtx_MINUS (Pmode, symbol, | |
b999aaeb | 11149 | gen_rtx_SYMBOL_REF (Pmode, toc_label_name)))); |
9ebbca7d | 11150 | } |
38c1f2d7 | 11151 | |
fc4767bb JJ |
11152 | /* If _Unwind_* has been called from within the same module, |
11153 | toc register is not guaranteed to be saved to 40(1) on function | |
11154 | entry. Save it there in that case. */ | |
c7ca610e | 11155 | |
9ebbca7d | 11156 | void |
863d938c | 11157 | rs6000_aix_emit_builtin_unwind_init (void) |
9ebbca7d GK |
11158 | { |
11159 | rtx mem; | |
11160 | rtx stack_top = gen_reg_rtx (Pmode); | |
11161 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
fc4767bb JJ |
11162 | rtx opcode = gen_reg_rtx (SImode); |
11163 | rtx tocompare = gen_reg_rtx (SImode); | |
11164 | rtx no_toc_save_needed = gen_label_rtx (); | |
9ebbca7d GK |
11165 | |
11166 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
11167 | emit_move_insn (stack_top, mem); | |
11168 | ||
fc4767bb JJ |
11169 | mem = gen_rtx_MEM (Pmode, |
11170 | gen_rtx_PLUS (Pmode, stack_top, | |
9ebbca7d GK |
11171 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); |
11172 | emit_move_insn (opcode_addr, mem); | |
fc4767bb JJ |
11173 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); |
11174 | emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014 | |
2496c7bd | 11175 | : 0xE8410028, SImode)); |
9ebbca7d | 11176 | |
fc4767bb | 11177 | do_compare_rtx_and_jump (opcode, tocompare, EQ, 1, |
06f4e019 | 11178 | SImode, NULL_RTX, NULL_RTX, |
fc4767bb | 11179 | no_toc_save_needed); |
9ebbca7d | 11180 | |
fc4767bb JJ |
11181 | mem = gen_rtx_MEM (Pmode, |
11182 | gen_rtx_PLUS (Pmode, stack_top, | |
11183 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
11184 | emit_move_insn (mem, gen_rtx_REG (Pmode, 2)); | |
11185 | emit_label (no_toc_save_needed); | |
9ebbca7d | 11186 | } |
38c1f2d7 | 11187 | \f |
ba4828e0 RK |
11188 | /* This ties together stack memory (MEM with an alias set of |
11189 | rs6000_sr_alias_set) and the change to the stack pointer. */ | |
11190 | ||
9ebbca7d | 11191 | static void |
863d938c | 11192 | rs6000_emit_stack_tie (void) |
9ebbca7d | 11193 | { |
ba4828e0 RK |
11194 | rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); |
11195 | ||
11196 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
11197 | emit_insn (gen_stack_tie (mem)); |
11198 | } | |
38c1f2d7 | 11199 | |
9ebbca7d GK |
11200 | /* Emit the correct code for allocating stack space, as insns. |
11201 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
11202 | The generated code may use hard register 0 as a temporary. */ | |
11203 | ||
11204 | static void | |
a2369ed3 | 11205 | rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12) |
38c1f2d7 | 11206 | { |
9ebbca7d GK |
11207 | rtx insn; |
11208 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
11209 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
11210 | rtx todec = GEN_INT (-size); | |
a157febd GK |
11211 | |
11212 | if (current_function_limit_stack) | |
11213 | { | |
11214 | if (REG_P (stack_limit_rtx) | |
11215 | && REGNO (stack_limit_rtx) > 1 | |
11216 | && REGNO (stack_limit_rtx) <= 31) | |
11217 | { | |
5b71a4e7 | 11218 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
11219 | ? gen_addsi3 (tmp_reg, |
11220 | stack_limit_rtx, | |
11221 | GEN_INT (size)) | |
11222 | : gen_adddi3 (tmp_reg, | |
11223 | stack_limit_rtx, | |
11224 | GEN_INT (size))); | |
5b71a4e7 | 11225 | |
9ebbca7d GK |
11226 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, |
11227 | const0_rtx)); | |
a157febd GK |
11228 | } |
11229 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 11230 | && TARGET_32BIT |
f607bc57 | 11231 | && DEFAULT_ABI == ABI_V4) |
a157febd | 11232 | { |
9ebbca7d GK |
11233 | rtx toload = gen_rtx_CONST (VOIDmode, |
11234 | gen_rtx_PLUS (Pmode, | |
11235 | stack_limit_rtx, | |
11236 | GEN_INT (size))); | |
5b71a4e7 | 11237 | |
9ebbca7d GK |
11238 | emit_insn (gen_elf_high (tmp_reg, toload)); |
11239 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
11240 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
11241 | const0_rtx)); | |
a157febd GK |
11242 | } |
11243 | else | |
11244 | warning ("stack limit expression is not supported"); | |
11245 | } | |
11246 | ||
9ebbca7d GK |
11247 | if (copy_r12 || ! TARGET_UPDATE) |
11248 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
11249 | ||
38c1f2d7 MM |
11250 | if (TARGET_UPDATE) |
11251 | { | |
9ebbca7d | 11252 | if (size > 32767) |
38c1f2d7 | 11253 | { |
9ebbca7d GK |
11254 | /* Need a note here so that try_split doesn't get confused. */ |
11255 | if (get_last_insn() == NULL_RTX) | |
2e040219 | 11256 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d GK |
11257 | insn = emit_move_insn (tmp_reg, todec); |
11258 | try_split (PATTERN (insn), insn, 0); | |
11259 | todec = tmp_reg; | |
38c1f2d7 | 11260 | } |
5b71a4e7 DE |
11261 | |
11262 | insn = emit_insn (TARGET_32BIT | |
11263 | ? gen_movsi_update (stack_reg, stack_reg, | |
11264 | todec, stack_reg) | |
11265 | : gen_movdi_update (stack_reg, stack_reg, | |
9ebbca7d | 11266 | todec, stack_reg)); |
38c1f2d7 MM |
11267 | } |
11268 | else | |
11269 | { | |
5b71a4e7 DE |
11270 | insn = emit_insn (TARGET_32BIT |
11271 | ? gen_addsi3 (stack_reg, stack_reg, todec) | |
11272 | : gen_adddi3 (stack_reg, stack_reg, todec)); | |
9ebbca7d GK |
11273 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), |
11274 | gen_rtx_REG (Pmode, 12)); | |
11275 | } | |
5b71a4e7 | 11276 | |
9ebbca7d GK |
11277 | RTX_FRAME_RELATED_P (insn) = 1; |
11278 | REG_NOTES (insn) = | |
11279 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
11280 | gen_rtx_SET (VOIDmode, stack_reg, | |
11281 | gen_rtx_PLUS (Pmode, stack_reg, | |
11282 | GEN_INT (-size))), | |
11283 | REG_NOTES (insn)); | |
11284 | } | |
11285 | ||
a4f6c312 SS |
11286 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced |
11287 | with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 | |
11288 | is not NULL. It would be nice if dwarf2out_frame_debug_expr could | |
11289 | deduce these equivalences by itself so it wasn't necessary to hold | |
11290 | its hand so much. */ | |
9ebbca7d GK |
11291 | |
11292 | static void | |
a2369ed3 DJ |
11293 | rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val, |
11294 | rtx reg2, rtx rreg) | |
9ebbca7d GK |
11295 | { |
11296 | rtx real, temp; | |
11297 | ||
e56c4463 JL |
11298 | /* copy_rtx will not make unique copies of registers, so we need to |
11299 | ensure we don't have unwanted sharing here. */ | |
11300 | if (reg == reg2) | |
11301 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
11302 | ||
11303 | if (reg == rreg) | |
11304 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
11305 | ||
9ebbca7d GK |
11306 | real = copy_rtx (PATTERN (insn)); |
11307 | ||
89e7058f AH |
11308 | if (reg2 != NULL_RTX) |
11309 | real = replace_rtx (real, reg2, rreg); | |
11310 | ||
9ebbca7d GK |
11311 | real = replace_rtx (real, reg, |
11312 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, | |
11313 | STACK_POINTER_REGNUM), | |
11314 | GEN_INT (val))); | |
11315 | ||
11316 | /* We expect that 'real' is either a SET or a PARALLEL containing | |
11317 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
11318 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
11319 | ||
11320 | if (GET_CODE (real) == SET) | |
11321 | { | |
11322 | rtx set = real; | |
11323 | ||
11324 | temp = simplify_rtx (SET_SRC (set)); | |
11325 | if (temp) | |
11326 | SET_SRC (set) = temp; | |
11327 | temp = simplify_rtx (SET_DEST (set)); | |
11328 | if (temp) | |
11329 | SET_DEST (set) = temp; | |
11330 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 11331 | { |
9ebbca7d GK |
11332 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
11333 | if (temp) | |
11334 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 11335 | } |
38c1f2d7 | 11336 | } |
9ebbca7d GK |
11337 | else if (GET_CODE (real) == PARALLEL) |
11338 | { | |
11339 | int i; | |
11340 | for (i = 0; i < XVECLEN (real, 0); i++) | |
11341 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
11342 | { | |
11343 | rtx set = XVECEXP (real, 0, i); | |
11344 | ||
11345 | temp = simplify_rtx (SET_SRC (set)); | |
11346 | if (temp) | |
11347 | SET_SRC (set) = temp; | |
11348 | temp = simplify_rtx (SET_DEST (set)); | |
11349 | if (temp) | |
11350 | SET_DEST (set) = temp; | |
11351 | if (GET_CODE (SET_DEST (set)) == MEM) | |
11352 | { | |
11353 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
11354 | if (temp) | |
11355 | XEXP (SET_DEST (set), 0) = temp; | |
11356 | } | |
11357 | RTX_FRAME_RELATED_P (set) = 1; | |
11358 | } | |
11359 | } | |
11360 | else | |
a4f6c312 | 11361 | abort (); |
c19de7aa AH |
11362 | |
11363 | if (TARGET_SPE) | |
11364 | real = spe_synthesize_frame_save (real); | |
11365 | ||
9ebbca7d GK |
11366 | RTX_FRAME_RELATED_P (insn) = 1; |
11367 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
11368 | real, | |
11369 | REG_NOTES (insn)); | |
38c1f2d7 MM |
11370 | } |
11371 | ||
c19de7aa AH |
11372 | /* Given an SPE frame note, return a PARALLEL of SETs with the |
11373 | original note, plus a synthetic register save. */ | |
11374 | ||
11375 | static rtx | |
a2369ed3 | 11376 | spe_synthesize_frame_save (rtx real) |
c19de7aa AH |
11377 | { |
11378 | rtx synth, offset, reg, real2; | |
11379 | ||
11380 | if (GET_CODE (real) != SET | |
11381 | || GET_MODE (SET_SRC (real)) != V2SImode) | |
11382 | return real; | |
11383 | ||
11384 | /* For the SPE, registers saved in 64-bits, get a PARALLEL for their | |
11385 | frame related note. The parallel contains a set of the register | |
41f3a930 | 11386 | being saved, and another set to a synthetic register (n+1200). |
c19de7aa AH |
11387 | This is so we can differentiate between 64-bit and 32-bit saves. |
11388 | Words cannot describe this nastiness. */ | |
11389 | ||
11390 | if (GET_CODE (SET_DEST (real)) != MEM | |
11391 | || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS | |
11392 | || GET_CODE (SET_SRC (real)) != REG) | |
11393 | abort (); | |
11394 | ||
11395 | /* Transform: | |
11396 | (set (mem (plus (reg x) (const y))) | |
11397 | (reg z)) | |
11398 | into: | |
11399 | (set (mem (plus (reg x) (const y+4))) | |
41f3a930 | 11400 | (reg z+1200)) |
c19de7aa AH |
11401 | */ |
11402 | ||
11403 | real2 = copy_rtx (real); | |
11404 | PUT_MODE (SET_DEST (real2), SImode); | |
11405 | reg = SET_SRC (real2); | |
11406 | real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg))); | |
11407 | synth = copy_rtx (real2); | |
11408 | ||
11409 | if (BYTES_BIG_ENDIAN) | |
11410 | { | |
11411 | offset = XEXP (XEXP (SET_DEST (real2), 0), 1); | |
11412 | real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4)); | |
11413 | } | |
11414 | ||
11415 | reg = SET_SRC (synth); | |
41f3a930 | 11416 | |
c19de7aa | 11417 | synth = replace_rtx (synth, reg, |
41f3a930 | 11418 | gen_rtx_REG (SImode, REGNO (reg) + 1200)); |
c19de7aa AH |
11419 | |
11420 | offset = XEXP (XEXP (SET_DEST (synth), 0), 1); | |
11421 | synth = replace_rtx (synth, offset, | |
11422 | GEN_INT (INTVAL (offset) | |
11423 | + (BYTES_BIG_ENDIAN ? 0 : 4))); | |
11424 | ||
11425 | RTX_FRAME_RELATED_P (synth) = 1; | |
11426 | RTX_FRAME_RELATED_P (real2) = 1; | |
11427 | if (BYTES_BIG_ENDIAN) | |
11428 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2)); | |
11429 | else | |
11430 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth)); | |
11431 | ||
11432 | return real; | |
11433 | } | |
11434 | ||
00b960c7 AH |
11435 | /* Returns an insn that has a vrsave set operation with the |
11436 | appropriate CLOBBERs. */ | |
11437 | ||
11438 | static rtx | |
a2369ed3 | 11439 | generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep) |
00b960c7 AH |
11440 | { |
11441 | int nclobs, i; | |
11442 | rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1]; | |
a004eb82 | 11443 | rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
00b960c7 | 11444 | |
a004eb82 AH |
11445 | clobs[0] |
11446 | = gen_rtx_SET (VOIDmode, | |
11447 | vrsave, | |
11448 | gen_rtx_UNSPEC_VOLATILE (SImode, | |
11449 | gen_rtvec (2, reg, vrsave), | |
11450 | 30)); | |
00b960c7 AH |
11451 | |
11452 | nclobs = 1; | |
11453 | ||
9aa86737 AH |
11454 | /* We need to clobber the registers in the mask so the scheduler |
11455 | does not move sets to VRSAVE before sets of AltiVec registers. | |
11456 | ||
11457 | However, if the function receives nonlocal gotos, reload will set | |
11458 | all call saved registers live. We will end up with: | |
11459 | ||
11460 | (set (reg 999) (mem)) | |
11461 | (parallel [ (set (reg vrsave) (unspec blah)) | |
11462 | (clobber (reg 999))]) | |
11463 | ||
11464 | The clobber will cause the store into reg 999 to be dead, and | |
11465 | flow will attempt to delete an epilogue insn. In this case, we | |
11466 | need an unspec use/set of the register. */ | |
00b960c7 AH |
11467 | |
11468 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
11469 | if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0) | |
9aa86737 AH |
11470 | { |
11471 | if (!epiloguep || call_used_regs [i]) | |
11472 | clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode, | |
11473 | gen_rtx_REG (V4SImode, i)); | |
11474 | else | |
11475 | { | |
11476 | rtx reg = gen_rtx_REG (V4SImode, i); | |
9aa86737 AH |
11477 | |
11478 | clobs[nclobs++] | |
a004eb82 AH |
11479 | = gen_rtx_SET (VOIDmode, |
11480 | reg, | |
11481 | gen_rtx_UNSPEC (V4SImode, | |
11482 | gen_rtvec (1, reg), 27)); | |
9aa86737 AH |
11483 | } |
11484 | } | |
00b960c7 AH |
11485 | |
11486 | insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs)); | |
11487 | ||
11488 | for (i = 0; i < nclobs; ++i) | |
11489 | XVECEXP (insn, 0, i) = clobs[i]; | |
11490 | ||
11491 | return insn; | |
11492 | } | |
11493 | ||
89e7058f AH |
11494 | /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes. |
11495 | Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */ | |
11496 | ||
11497 | static void | |
a2369ed3 | 11498 | emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode, |
d1d0c603 | 11499 | unsigned int regno, int offset, HOST_WIDE_INT total_size) |
89e7058f AH |
11500 | { |
11501 | rtx reg, offset_rtx, insn, mem, addr, int_rtx; | |
11502 | rtx replacea, replaceb; | |
11503 | ||
11504 | int_rtx = GEN_INT (offset); | |
11505 | ||
11506 | /* Some cases that need register indexed addressing. */ | |
11507 | if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
a3170dc6 AH |
11508 | || (TARGET_SPE_ABI |
11509 | && SPE_VECTOR_MODE (mode) | |
11510 | && !SPE_CONST_OFFSET_OK (offset))) | |
89e7058f AH |
11511 | { |
11512 | /* Whomever calls us must make sure r11 is available in the | |
11513 | flow path of instructions in the prologue. */ | |
11514 | offset_rtx = gen_rtx_REG (Pmode, 11); | |
11515 | emit_move_insn (offset_rtx, int_rtx); | |
11516 | ||
11517 | replacea = offset_rtx; | |
11518 | replaceb = int_rtx; | |
11519 | } | |
11520 | else | |
11521 | { | |
11522 | offset_rtx = int_rtx; | |
11523 | replacea = NULL_RTX; | |
11524 | replaceb = NULL_RTX; | |
11525 | } | |
11526 | ||
11527 | reg = gen_rtx_REG (mode, regno); | |
11528 | addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx); | |
11529 | mem = gen_rtx_MEM (mode, addr); | |
11530 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
11531 | ||
11532 | insn = emit_move_insn (mem, reg); | |
11533 | ||
11534 | rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb); | |
11535 | } | |
11536 | ||
a3170dc6 AH |
11537 | /* Emit an offset memory reference suitable for a frame store, while |
11538 | converting to a valid addressing mode. */ | |
11539 | ||
11540 | static rtx | |
a2369ed3 | 11541 | gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset) |
a3170dc6 AH |
11542 | { |
11543 | rtx int_rtx, offset_rtx; | |
11544 | ||
11545 | int_rtx = GEN_INT (offset); | |
11546 | ||
11547 | if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode)) | |
11548 | { | |
11549 | offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
11550 | emit_move_insn (offset_rtx, int_rtx); | |
11551 | } | |
11552 | else | |
11553 | offset_rtx = int_rtx; | |
11554 | ||
11555 | return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx)); | |
11556 | } | |
11557 | ||
9ebbca7d GK |
11558 | /* Emit function prologue as insns. */ |
11559 | ||
9878760c | 11560 | void |
863d938c | 11561 | rs6000_emit_prologue (void) |
9878760c | 11562 | { |
4697a36c | 11563 | rs6000_stack_t *info = rs6000_stack_info (); |
0e67400a FJ |
11564 | enum machine_mode reg_mode = Pmode; |
11565 | int reg_size = UNITS_PER_WORD; | |
9ebbca7d GK |
11566 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); |
11567 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
11568 | rtx frame_reg_rtx = sp_reg_rtx; | |
b78d48dd | 11569 | rtx cr_save_rtx = NULL_RTX; |
9ebbca7d GK |
11570 | rtx insn; |
11571 | int saving_FPRs_inline; | |
11572 | int using_store_multiple; | |
11573 | HOST_WIDE_INT sp_offset = 0; | |
11574 | ||
c19de7aa | 11575 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11576 | { |
11577 | reg_mode = V2SImode; | |
11578 | reg_size = 8; | |
11579 | } | |
11580 | ||
9ebbca7d | 11581 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
11582 | && (!TARGET_SPE_ABI |
11583 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
11584 | && info->first_gp_reg_save < 31); |
11585 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
8c29550d | 11586 | || FP_SAVE_INLINE (info->first_fp_reg_save) |
acd0b319 | 11587 | || current_function_calls_eh_return |
8c29550d | 11588 | || cfun->machine->ra_need_lr); |
9ebbca7d GK |
11589 | |
11590 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
fc4767bb | 11591 | if (info->push_p |
acd0b319 AM |
11592 | && (DEFAULT_ABI == ABI_V4 |
11593 | || current_function_calls_eh_return)) | |
9ebbca7d GK |
11594 | { |
11595 | if (info->total_size < 32767) | |
11596 | sp_offset = info->total_size; | |
11597 | else | |
11598 | frame_reg_rtx = frame_ptr_rtx; | |
11599 | rs6000_emit_allocate_stack (info->total_size, | |
11600 | (frame_reg_rtx != sp_reg_rtx | |
11601 | && (info->cr_save_p | |
11602 | || info->lr_save_p | |
11603 | || info->first_fp_reg_save < 64 | |
11604 | || info->first_gp_reg_save < 32 | |
11605 | ))); | |
11606 | if (frame_reg_rtx != sp_reg_rtx) | |
11607 | rs6000_emit_stack_tie (); | |
11608 | } | |
11609 | ||
9aa86737 AH |
11610 | /* Save AltiVec registers if needed. */ |
11611 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
11612 | { | |
11613 | int i; | |
11614 | ||
11615 | /* There should be a non inline version of this, for when we | |
11616 | are saving lots of vector registers. */ | |
11617 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
11618 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
11619 | { | |
11620 | rtx areg, savereg, mem; | |
11621 | int offset; | |
11622 | ||
11623 | offset = info->altivec_save_offset + sp_offset | |
11624 | + 16 * (i - info->first_altivec_reg_save); | |
11625 | ||
11626 | savereg = gen_rtx_REG (V4SImode, i); | |
11627 | ||
11628 | areg = gen_rtx_REG (Pmode, 0); | |
11629 | emit_move_insn (areg, GEN_INT (offset)); | |
11630 | ||
11631 | /* AltiVec addressing mode is [reg+reg]. */ | |
11632 | mem = gen_rtx_MEM (V4SImode, | |
11633 | gen_rtx_PLUS (Pmode, frame_reg_rtx, areg)); | |
11634 | ||
11635 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
11636 | ||
11637 | insn = emit_move_insn (mem, savereg); | |
11638 | ||
5c242421 SB |
11639 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
11640 | areg, GEN_INT (offset)); | |
9aa86737 AH |
11641 | } |
11642 | } | |
11643 | ||
11644 | /* VRSAVE is a bit vector representing which AltiVec registers | |
11645 | are used. The OS uses this to determine which vector | |
11646 | registers to save on a context switch. We need to save | |
11647 | VRSAVE on the stack frame, add whatever AltiVec registers we | |
11648 | used in this function, and do the corresponding magic in the | |
11649 | epilogue. */ | |
11650 | ||
11651 | if (TARGET_ALTIVEC && info->vrsave_mask != 0) | |
11652 | { | |
a004eb82 | 11653 | rtx reg, mem, vrsave; |
9aa86737 AH |
11654 | int offset; |
11655 | ||
11656 | /* Get VRSAVE onto a GPR. */ | |
11657 | reg = gen_rtx_REG (SImode, 12); | |
a004eb82 | 11658 | vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
b188f760 AH |
11659 | if (TARGET_MACHO) |
11660 | emit_insn (gen_get_vrsave_internal (reg)); | |
11661 | else | |
11662 | emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave)); | |
9aa86737 AH |
11663 | |
11664 | /* Save VRSAVE. */ | |
11665 | offset = info->vrsave_save_offset + sp_offset; | |
11666 | mem | |
11667 | = gen_rtx_MEM (SImode, | |
11668 | gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset))); | |
11669 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
11670 | insn = emit_move_insn (mem, reg); | |
11671 | ||
11672 | /* Include the registers in the mask. */ | |
11673 | emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask))); | |
11674 | ||
11675 | insn = emit_insn (generate_set_vrsave (reg, info, 0)); | |
11676 | } | |
11677 | ||
9ebbca7d GK |
11678 | /* If we use the link register, get it into r0. */ |
11679 | if (info->lr_save_p) | |
71f123ca | 11680 | emit_move_insn (gen_rtx_REG (Pmode, 0), |
9ebbca7d GK |
11681 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); |
11682 | ||
11683 | /* If we need to save CR, put it into r12. */ | |
11684 | if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) | |
11685 | { | |
11686 | cr_save_rtx = gen_rtx_REG (SImode, 12); | |
11687 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
11688 | } | |
11689 | ||
a4f6c312 SS |
11690 | /* Do any required saving of fpr's. If only one or two to save, do |
11691 | it ourselves. Otherwise, call function. */ | |
9ebbca7d GK |
11692 | if (saving_FPRs_inline) |
11693 | { | |
11694 | int i; | |
11695 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
11696 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
11697 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
89e7058f AH |
11698 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode, |
11699 | info->first_fp_reg_save + i, | |
11700 | info->fp_save_offset + sp_offset + 8 * i, | |
11701 | info->total_size); | |
9ebbca7d GK |
11702 | } |
11703 | else if (info->first_fp_reg_save != 64) | |
11704 | { | |
11705 | int i; | |
11706 | char rname[30]; | |
520a57c8 | 11707 | const char *alloc_rname; |
9ebbca7d GK |
11708 | rtvec p; |
11709 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
11710 | ||
11711 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
11712 | gen_rtx_REG (Pmode, | |
11713 | LINK_REGISTER_REGNUM)); | |
11714 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
11715 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
a8a05998 | 11716 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
11717 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
11718 | gen_rtx_SYMBOL_REF (Pmode, | |
11719 | alloc_rname)); | |
11720 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
11721 | { | |
11722 | rtx addr, reg, mem; | |
11723 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
11724 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
11725 | GEN_INT (info->fp_save_offset | |
11726 | + sp_offset + 8*i)); | |
11727 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 11728 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
11729 | |
11730 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
11731 | } | |
11732 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
11733 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11734 | NULL_RTX, NULL_RTX); | |
11735 | } | |
b6c9286a | 11736 | |
9ebbca7d GK |
11737 | /* Save GPRs. This is done as a PARALLEL if we are using |
11738 | the store-multiple instructions. */ | |
11739 | if (using_store_multiple) | |
b6c9286a | 11740 | { |
308c142a | 11741 | rtvec p; |
9ebbca7d GK |
11742 | int i; |
11743 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
9ebbca7d GK |
11744 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) |
11745 | { | |
11746 | rtx addr, reg, mem; | |
11747 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
11748 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
11749 | GEN_INT (info->gp_save_offset | |
11750 | + sp_offset | |
11751 | + reg_size * i)); | |
11752 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 11753 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
11754 | |
11755 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
11756 | } | |
11757 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
11758 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11759 | NULL_RTX, NULL_RTX); | |
b6c9286a MM |
11760 | } |
11761 | else | |
11762 | { | |
9ebbca7d GK |
11763 | int i; |
11764 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
11765 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
11766 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
1db02437 | 11767 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 11768 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 11769 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
a3170dc6 AH |
11770 | { |
11771 | rtx addr, reg, mem; | |
11772 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
11773 | ||
c19de7aa | 11774 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11775 | { |
11776 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
11777 | rtx b; | |
11778 | ||
11779 | if (!SPE_CONST_OFFSET_OK (offset)) | |
11780 | { | |
11781 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
11782 | emit_move_insn (b, GEN_INT (offset)); | |
11783 | } | |
11784 | else | |
11785 | b = GEN_INT (offset); | |
11786 | ||
11787 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
11788 | mem = gen_rtx_MEM (V2SImode, addr); | |
11789 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
11790 | insn = emit_move_insn (mem, reg); | |
11791 | ||
11792 | if (GET_CODE (b) == CONST_INT) | |
11793 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11794 | NULL_RTX, NULL_RTX); | |
11795 | else | |
11796 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11797 | b, GEN_INT (offset)); | |
11798 | } | |
11799 | else | |
11800 | { | |
11801 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
11802 | GEN_INT (info->gp_save_offset | |
11803 | + sp_offset | |
11804 | + reg_size * i)); | |
11805 | mem = gen_rtx_MEM (reg_mode, addr); | |
11806 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
11807 | ||
11808 | insn = emit_move_insn (mem, reg); | |
11809 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11810 | NULL_RTX, NULL_RTX); | |
11811 | } | |
11812 | } | |
9ebbca7d GK |
11813 | } |
11814 | ||
83720594 RH |
11815 | /* ??? There's no need to emit actual instructions here, but it's the |
11816 | easiest way to get the frame unwind information emitted. */ | |
11817 | if (current_function_calls_eh_return) | |
11818 | { | |
78e1b90d DE |
11819 | unsigned int i, regno; |
11820 | ||
fc4767bb JJ |
11821 | /* In AIX ABI we need to pretend we save r2 here. */ |
11822 | if (TARGET_AIX) | |
11823 | { | |
11824 | rtx addr, reg, mem; | |
11825 | ||
11826 | reg = gen_rtx_REG (reg_mode, 2); | |
11827 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
11828 | GEN_INT (sp_offset + 5 * reg_size)); | |
11829 | mem = gen_rtx_MEM (reg_mode, addr); | |
11830 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
11831 | ||
11832 | insn = emit_move_insn (mem, reg); | |
11833 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11834 | NULL_RTX, NULL_RTX); | |
11835 | PATTERN (insn) = gen_blockage (); | |
11836 | } | |
11837 | ||
83720594 RH |
11838 | for (i = 0; ; ++i) |
11839 | { | |
83720594 RH |
11840 | regno = EH_RETURN_DATA_REGNO (i); |
11841 | if (regno == INVALID_REGNUM) | |
11842 | break; | |
11843 | ||
89e7058f AH |
11844 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno, |
11845 | info->ehrd_offset + sp_offset | |
11846 | + reg_size * (int) i, | |
11847 | info->total_size); | |
83720594 RH |
11848 | } |
11849 | } | |
11850 | ||
9ebbca7d GK |
11851 | /* Save lr if we used it. */ |
11852 | if (info->lr_save_p) | |
11853 | { | |
11854 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
11855 | GEN_INT (info->lr_save_offset + sp_offset)); | |
11856 | rtx reg = gen_rtx_REG (Pmode, 0); | |
11857 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
11858 | /* This should not be of rs6000_sr_alias_set, because of | |
11859 | __builtin_return_address. */ | |
11860 | ||
11861 | insn = emit_move_insn (mem, reg); | |
11862 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
11863 | reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
11864 | } | |
11865 | ||
11866 | /* Save CR if we use any that must be preserved. */ | |
11867 | if (info->cr_save_p) | |
11868 | { | |
11869 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
11870 | GEN_INT (info->cr_save_offset + sp_offset)); | |
11871 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
11872 | |
11873 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
11874 | |
11875 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
11876 | that it's free. */ | |
11877 | if (REGNO (frame_reg_rtx) == 12) | |
11878 | { | |
11879 | cr_save_rtx = gen_rtx_REG (SImode, 0); | |
11880 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
11881 | } | |
11882 | insn = emit_move_insn (mem, cr_save_rtx); | |
11883 | ||
11884 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
615158e2 JJ |
11885 | to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'. |
11886 | But that's OK. All we have to do is specify that _one_ condition | |
11887 | code register is saved in this stack slot. The thrower's epilogue | |
a1dc9455 FS |
11888 | will then restore all the call-saved registers. |
11889 | We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */ | |
9ebbca7d | 11890 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
a1dc9455 | 11891 | cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO)); |
9ebbca7d GK |
11892 | } |
11893 | ||
11894 | /* Update stack and set back pointer unless this is V.4, | |
11895 | for which it was done previously. */ | |
fc4767bb JJ |
11896 | if (info->push_p |
11897 | && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return)) | |
9ebbca7d GK |
11898 | rs6000_emit_allocate_stack (info->total_size, FALSE); |
11899 | ||
11900 | /* Set frame pointer, if needed. */ | |
11901 | if (frame_pointer_needed) | |
11902 | { | |
a3170dc6 | 11903 | insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM), |
9ebbca7d GK |
11904 | sp_reg_rtx); |
11905 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 11906 | } |
9878760c | 11907 | |
1db02437 | 11908 | /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
9ebbca7d | 11909 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) |
f607bc57 | 11910 | || (DEFAULT_ABI == ABI_V4 && flag_pic == 1 |
1db02437 | 11911 | && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])) |
9ebbca7d GK |
11912 | { |
11913 | /* If emit_load_toc_table will use the link register, we need to save | |
c4501e62 | 11914 | it. We use R12 for this purpose because emit_load_toc_table |
9ebbca7d GK |
11915 | can use register 0. This allows us to use a plain 'blr' to return |
11916 | from the procedure more often. */ | |
f1384257 AM |
11917 | int save_LR_around_toc_setup = (TARGET_ELF |
11918 | && DEFAULT_ABI != ABI_AIX | |
11919 | && flag_pic | |
d5fa86ba GK |
11920 | && ! info->lr_save_p |
11921 | && EXIT_BLOCK_PTR->pred != NULL); | |
9ebbca7d | 11922 | if (save_LR_around_toc_setup) |
c4501e62 JJ |
11923 | { |
11924 | rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
11925 | rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr)); | |
11926 | rs6000_emit_load_toc_table (TRUE); | |
11927 | rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx)); | |
11928 | } | |
11929 | else | |
11930 | rs6000_emit_load_toc_table (TRUE); | |
9ebbca7d | 11931 | } |
ee890fe2 | 11932 | |
fcce224d | 11933 | #if TARGET_MACHO |
ee890fe2 SS |
11934 | if (DEFAULT_ABI == ABI_DARWIN |
11935 | && flag_pic && current_function_uses_pic_offset_table) | |
11936 | { | |
11937 | rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
f099d360 | 11938 | const char *picbase = machopic_function_base_name (); |
6788f5ca | 11939 | rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase); |
ee890fe2 | 11940 | |
f51eee6a | 11941 | rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src))); |
ee890fe2 SS |
11942 | |
11943 | rs6000_maybe_dead ( | |
1db02437 | 11944 | emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM), |
ee890fe2 SS |
11945 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM))); |
11946 | } | |
fcce224d | 11947 | #endif |
9ebbca7d GK |
11948 | } |
11949 | ||
9ebbca7d | 11950 | /* Write function prologue. */ |
a4f6c312 | 11951 | |
08c148a8 | 11952 | static void |
a2369ed3 DJ |
11953 | rs6000_output_function_prologue (FILE *file, |
11954 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) | |
9ebbca7d GK |
11955 | { |
11956 | rs6000_stack_t *info = rs6000_stack_info (); | |
11957 | ||
4697a36c MM |
11958 | if (TARGET_DEBUG_STACK) |
11959 | debug_stack_info (info); | |
9878760c | 11960 | |
a4f6c312 SS |
11961 | /* Write .extern for any function we will call to save and restore |
11962 | fp values. */ | |
11963 | if (info->first_fp_reg_save < 64 | |
11964 | && !FP_SAVE_INLINE (info->first_fp_reg_save)) | |
4d30c363 | 11965 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c | 11966 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
a4f6c312 SS |
11967 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, |
11968 | RESTORE_FP_SUFFIX); | |
9878760c | 11969 | |
c764f757 RK |
11970 | /* Write .extern for AIX common mode routines, if needed. */ |
11971 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
11972 | { | |
f6709c70 JW |
11973 | fputs ("\t.extern __mulh\n", file); |
11974 | fputs ("\t.extern __mull\n", file); | |
11975 | fputs ("\t.extern __divss\n", file); | |
11976 | fputs ("\t.extern __divus\n", file); | |
11977 | fputs ("\t.extern __quoss\n", file); | |
11978 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
11979 | common_mode_defined = 1; |
11980 | } | |
9878760c | 11981 | |
9ebbca7d | 11982 | if (! HAVE_prologue) |
979721f8 | 11983 | { |
9ebbca7d | 11984 | start_sequence (); |
9dda4cc8 | 11985 | |
a4f6c312 SS |
11986 | /* A NOTE_INSN_DELETED is supposed to be at the start and end of |
11987 | the "toplevel" insn chain. */ | |
2e040219 | 11988 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 11989 | rs6000_emit_prologue (); |
2e040219 | 11990 | emit_note (NOTE_INSN_DELETED); |
178c3eff DJ |
11991 | |
11992 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ | |
11993 | { | |
11994 | rtx insn; | |
11995 | unsigned addr = 0; | |
11996 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
11997 | { | |
11998 | INSN_ADDRESSES_NEW (insn, addr); | |
11999 | addr += 4; | |
12000 | } | |
12001 | } | |
9dda4cc8 | 12002 | |
9ebbca7d | 12003 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
12004 | debug_rtx_list (get_insns (), 100); |
12005 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 12006 | end_sequence (); |
979721f8 MM |
12007 | } |
12008 | ||
9ebbca7d GK |
12009 | rs6000_pic_labelno++; |
12010 | } | |
12011 | ||
12012 | /* Emit function epilogue as insns. | |
9878760c | 12013 | |
9ebbca7d GK |
12014 | At present, dwarf2out_frame_debug_expr doesn't understand |
12015 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
12016 | anywhere in the epilogue. Most of the insns below would in any case | |
12017 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 12018 | |
9ebbca7d | 12019 | void |
a2369ed3 | 12020 | rs6000_emit_epilogue (int sibcall) |
9ebbca7d GK |
12021 | { |
12022 | rs6000_stack_t *info; | |
12023 | int restoring_FPRs_inline; | |
12024 | int using_load_multiple; | |
12025 | int using_mfcr_multiple; | |
12026 | int use_backchain_to_restore_sp; | |
12027 | int sp_offset = 0; | |
12028 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
12029 | rtx frame_reg_rtx = sp_reg_rtx; | |
0e67400a FJ |
12030 | enum machine_mode reg_mode = Pmode; |
12031 | int reg_size = UNITS_PER_WORD; | |
9ebbca7d GK |
12032 | int i; |
12033 | ||
c19de7aa AH |
12034 | info = rs6000_stack_info (); |
12035 | ||
12036 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) | |
a3170dc6 AH |
12037 | { |
12038 | reg_mode = V2SImode; | |
12039 | reg_size = 8; | |
12040 | } | |
12041 | ||
9ebbca7d | 12042 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
12043 | && (!TARGET_SPE_ABI |
12044 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
12045 | && info->first_gp_reg_save < 31); |
12046 | restoring_FPRs_inline = (sibcall | |
83720594 | 12047 | || current_function_calls_eh_return |
9ebbca7d GK |
12048 | || info->first_fp_reg_save == 64 |
12049 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
12050 | use_backchain_to_restore_sp = (frame_pointer_needed | |
12051 | || current_function_calls_alloca | |
12052 | || info->total_size > 32767); | |
12053 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
12054 | || rs6000_cpu == PROCESSOR_PPC603 | |
12055 | || rs6000_cpu == PROCESSOR_PPC750 | |
12056 | || optimize_size); | |
12057 | ||
12058 | /* If we have a frame pointer, a call to alloca, or a large stack | |
12059 | frame, restore the old stack pointer using the backchain. Otherwise, | |
12060 | we know what size to update it with. */ | |
12061 | if (use_backchain_to_restore_sp) | |
bacbde18 | 12062 | { |
9ebbca7d GK |
12063 | /* Under V.4, don't reset the stack pointer until after we're done |
12064 | loading the saved registers. */ | |
f607bc57 | 12065 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d | 12066 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); |
4697a36c | 12067 | |
9ebbca7d GK |
12068 | emit_move_insn (frame_reg_rtx, |
12069 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
12070 | ||
bacbde18 | 12071 | } |
9ebbca7d | 12072 | else if (info->push_p) |
85638c0d | 12073 | { |
fc4767bb JJ |
12074 | if (DEFAULT_ABI == ABI_V4 |
12075 | || current_function_calls_eh_return) | |
9ebbca7d GK |
12076 | sp_offset = info->total_size; |
12077 | else | |
12078 | { | |
12079 | emit_insn (TARGET_32BIT | |
12080 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
12081 | GEN_INT (info->total_size)) | |
12082 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
12083 | GEN_INT (info->total_size))); | |
12084 | } | |
85638c0d | 12085 | } |
9ebbca7d | 12086 | |
9aa86737 AH |
12087 | /* Restore AltiVec registers if needed. */ |
12088 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
12089 | { | |
12090 | int i; | |
12091 | ||
12092 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
12093 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
12094 | { | |
12095 | rtx addr, areg, mem; | |
12096 | ||
12097 | areg = gen_rtx_REG (Pmode, 0); | |
12098 | emit_move_insn | |
12099 | (areg, GEN_INT (info->altivec_save_offset | |
12100 | + sp_offset | |
12101 | + 16 * (i - info->first_altivec_reg_save))); | |
12102 | ||
12103 | /* AltiVec addressing mode is [reg+reg]. */ | |
12104 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
12105 | mem = gen_rtx_MEM (V4SImode, addr); | |
12106 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12107 | ||
12108 | emit_move_insn (gen_rtx_REG (V4SImode, i), mem); | |
12109 | } | |
12110 | } | |
12111 | ||
12112 | /* Restore VRSAVE if needed. */ | |
12113 | if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0) | |
12114 | { | |
12115 | rtx addr, mem, reg; | |
12116 | ||
12117 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12118 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
12119 | mem = gen_rtx_MEM (SImode, addr); | |
12120 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12121 | reg = gen_rtx_REG (SImode, 12); | |
12122 | emit_move_insn (reg, mem); | |
12123 | ||
12124 | emit_insn (generate_set_vrsave (reg, info, 1)); | |
12125 | } | |
12126 | ||
9ebbca7d GK |
12127 | /* Get the old lr if we saved it. */ |
12128 | if (info->lr_save_p) | |
b6c9286a | 12129 | { |
a3170dc6 AH |
12130 | rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx, |
12131 | info->lr_save_offset + sp_offset); | |
ba4828e0 RK |
12132 | |
12133 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 12134 | |
9ebbca7d | 12135 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 12136 | } |
9ebbca7d GK |
12137 | |
12138 | /* Get the old cr if we saved it. */ | |
12139 | if (info->cr_save_p) | |
12140 | { | |
12141 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12142 | GEN_INT (info->cr_save_offset + sp_offset)); | |
12143 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
12144 | |
12145 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 12146 | |
9ebbca7d GK |
12147 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
12148 | } | |
12149 | ||
12150 | /* Set LR here to try to overlap restores below. */ | |
4697a36c | 12151 | if (info->lr_save_p) |
9ebbca7d GK |
12152 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
12153 | gen_rtx_REG (Pmode, 0)); | |
12154 | ||
83720594 RH |
12155 | /* Load exception handler data registers, if needed. */ |
12156 | if (current_function_calls_eh_return) | |
12157 | { | |
78e1b90d DE |
12158 | unsigned int i, regno; |
12159 | ||
fc4767bb JJ |
12160 | if (TARGET_AIX) |
12161 | { | |
12162 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12163 | GEN_INT (sp_offset + 5 * reg_size)); | |
12164 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
12165 | ||
12166 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12167 | ||
12168 | emit_move_insn (gen_rtx_REG (reg_mode, 2), mem); | |
12169 | } | |
12170 | ||
83720594 RH |
12171 | for (i = 0; ; ++i) |
12172 | { | |
a3170dc6 | 12173 | rtx mem; |
83720594 RH |
12174 | |
12175 | regno = EH_RETURN_DATA_REGNO (i); | |
12176 | if (regno == INVALID_REGNUM) | |
12177 | break; | |
12178 | ||
a3170dc6 AH |
12179 | mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx, |
12180 | info->ehrd_offset + sp_offset | |
12181 | + reg_size * (int) i); | |
ba4828e0 | 12182 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
12183 | |
12184 | emit_move_insn (gen_rtx_REG (reg_mode, regno), mem); | |
12185 | } | |
12186 | } | |
9ebbca7d GK |
12187 | |
12188 | /* Restore GPRs. This is done as a PARALLEL if we are using | |
12189 | the load-multiple instructions. */ | |
12190 | if (using_load_multiple) | |
979721f8 | 12191 | { |
9ebbca7d GK |
12192 | rtvec p; |
12193 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
12194 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 12195 | { |
9ebbca7d GK |
12196 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
12197 | GEN_INT (info->gp_save_offset | |
12198 | + sp_offset | |
12199 | + reg_size * i)); | |
12200 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
12201 | |
12202 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
12203 | |
12204 | RTVEC_ELT (p, i) = | |
12205 | gen_rtx_SET (VOIDmode, | |
12206 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
12207 | mem); | |
979721f8 | 12208 | } |
9ebbca7d | 12209 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 12210 | } |
9ebbca7d GK |
12211 | else |
12212 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
12213 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
12214 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
1db02437 | 12215 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 12216 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 12217 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
9ebbca7d GK |
12218 | { |
12219 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12220 | GEN_INT (info->gp_save_offset | |
12221 | + sp_offset | |
12222 | + reg_size * i)); | |
12223 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 12224 | |
a3170dc6 | 12225 | /* Restore 64-bit quantities for SPE. */ |
c19de7aa | 12226 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12227 | { |
12228 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
12229 | rtx b; | |
12230 | ||
12231 | if (!SPE_CONST_OFFSET_OK (offset)) | |
12232 | { | |
12233 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12234 | emit_move_insn (b, GEN_INT (offset)); | |
12235 | } | |
12236 | else | |
12237 | b = GEN_INT (offset); | |
12238 | ||
12239 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
12240 | mem = gen_rtx_MEM (V2SImode, addr); | |
12241 | } | |
12242 | ||
ba4828e0 | 12243 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12244 | |
12245 | emit_move_insn (gen_rtx_REG (reg_mode, | |
a3170dc6 | 12246 | info->first_gp_reg_save + i), mem); |
9ebbca7d | 12247 | } |
9878760c | 12248 | |
9ebbca7d GK |
12249 | /* Restore fpr's if we need to do it without calling a function. */ |
12250 | if (restoring_FPRs_inline) | |
12251 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12252 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
12253 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
12254 | { | |
12255 | rtx addr, mem; | |
12256 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12257 | GEN_INT (info->fp_save_offset | |
12258 | + sp_offset | |
a4f6c312 | 12259 | + 8 * i)); |
9ebbca7d | 12260 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 12261 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12262 | |
12263 | emit_move_insn (gen_rtx_REG (DFmode, | |
12264 | info->first_fp_reg_save + i), | |
12265 | mem); | |
12266 | } | |
8d30c4ee | 12267 | |
9ebbca7d GK |
12268 | /* If we saved cr, restore it here. Just those that were used. */ |
12269 | if (info->cr_save_p) | |
979721f8 | 12270 | { |
9ebbca7d | 12271 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 12272 | int count = 0; |
9ebbca7d GK |
12273 | |
12274 | if (using_mfcr_multiple) | |
979721f8 | 12275 | { |
9ebbca7d GK |
12276 | for (i = 0; i < 8; i++) |
12277 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 12278 | count++; |
9ebbca7d | 12279 | if (count == 0) |
e35b9579 GK |
12280 | abort (); |
12281 | } | |
12282 | ||
12283 | if (using_mfcr_multiple && count > 1) | |
12284 | { | |
12285 | rtvec p; | |
12286 | int ndx; | |
9ebbca7d | 12287 | |
e35b9579 | 12288 | p = rtvec_alloc (count); |
9ebbca7d | 12289 | |
e35b9579 | 12290 | ndx = 0; |
9ebbca7d GK |
12291 | for (i = 0; i < 8; i++) |
12292 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
12293 | { | |
12294 | rtvec r = rtvec_alloc (2); | |
12295 | RTVEC_ELT (r, 0) = r12_rtx; | |
12296 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 12297 | RTVEC_ELT (p, ndx) = |
9ebbca7d | 12298 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
615158e2 | 12299 | gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR)); |
e35b9579 | 12300 | ndx++; |
9ebbca7d GK |
12301 | } |
12302 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
12303 | if (ndx != count) |
12304 | abort (); | |
979721f8 MM |
12305 | } |
12306 | else | |
9ebbca7d GK |
12307 | for (i = 0; i < 8; i++) |
12308 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 12309 | { |
9ebbca7d GK |
12310 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
12311 | CR0_REGNO+i), | |
12312 | r12_rtx)); | |
979721f8 | 12313 | } |
979721f8 MM |
12314 | } |
12315 | ||
9ebbca7d GK |
12316 | /* If this is V.4, unwind the stack pointer after all of the loads |
12317 | have been done. We need to emit a block here so that sched | |
12318 | doesn't decide to move the sp change before the register restores | |
12319 | (which may not have any obvious dependency on the stack). This | |
12320 | doesn't hurt performance, because there is no scheduling that can | |
12321 | be done after this point. */ | |
fc4767bb JJ |
12322 | if (DEFAULT_ABI == ABI_V4 |
12323 | || current_function_calls_eh_return) | |
b6c9286a | 12324 | { |
9ebbca7d GK |
12325 | if (frame_reg_rtx != sp_reg_rtx) |
12326 | rs6000_emit_stack_tie (); | |
b6c9286a | 12327 | |
9ebbca7d | 12328 | if (use_backchain_to_restore_sp) |
b6c9286a | 12329 | { |
9ebbca7d | 12330 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 12331 | } |
9ebbca7d | 12332 | else if (sp_offset != 0) |
13f1623b | 12333 | { |
5b71a4e7 | 12334 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
12335 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, |
12336 | GEN_INT (sp_offset)) | |
12337 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
12338 | GEN_INT (sp_offset))); | |
13f1623b | 12339 | } |
9ebbca7d | 12340 | } |
b6c9286a | 12341 | |
83720594 RH |
12342 | if (current_function_calls_eh_return) |
12343 | { | |
12344 | rtx sa = EH_RETURN_STACKADJ_RTX; | |
5b71a4e7 | 12345 | emit_insn (TARGET_32BIT |
83720594 RH |
12346 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa) |
12347 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa)); | |
12348 | } | |
12349 | ||
9ebbca7d GK |
12350 | if (!sibcall) |
12351 | { | |
12352 | rtvec p; | |
12353 | if (! restoring_FPRs_inline) | |
12354 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
12355 | else | |
12356 | p = rtvec_alloc (2); | |
b6c9286a | 12357 | |
e35b9579 GK |
12358 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
12359 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
9ebbca7d GK |
12360 | gen_rtx_REG (Pmode, |
12361 | LINK_REGISTER_REGNUM)); | |
9ebbca7d GK |
12362 | |
12363 | /* If we have to restore more than two FP registers, branch to the | |
12364 | restore function. It will return to our caller. */ | |
12365 | if (! restoring_FPRs_inline) | |
12366 | { | |
12367 | int i; | |
12368 | char rname[30]; | |
520a57c8 | 12369 | const char *alloc_rname; |
979721f8 | 12370 | |
9ebbca7d GK |
12371 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
12372 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
a8a05998 | 12373 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
12374 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, |
12375 | gen_rtx_SYMBOL_REF (Pmode, | |
12376 | alloc_rname)); | |
b6c9286a | 12377 | |
9ebbca7d GK |
12378 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
12379 | { | |
12380 | rtx addr, mem; | |
12381 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
12382 | GEN_INT (info->fp_save_offset + 8*i)); | |
12383 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 12384 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12385 | |
12386 | RTVEC_ELT (p, i+3) = | |
12387 | gen_rtx_SET (VOIDmode, | |
12388 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
12389 | mem); | |
b6c9286a MM |
12390 | } |
12391 | } | |
9ebbca7d GK |
12392 | |
12393 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
3daf36a4 | 12394 | } |
9878760c RK |
12395 | } |
12396 | ||
12397 | /* Write function epilogue. */ | |
12398 | ||
08c148a8 | 12399 | static void |
a2369ed3 DJ |
12400 | rs6000_output_function_epilogue (FILE *file, |
12401 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) | |
9878760c | 12402 | { |
4697a36c | 12403 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 12404 | |
9ebbca7d | 12405 | if (! HAVE_epilogue) |
9878760c | 12406 | { |
9ebbca7d GK |
12407 | rtx insn = get_last_insn (); |
12408 | /* If the last insn was a BARRIER, we don't have to write anything except | |
12409 | the trace table. */ | |
12410 | if (GET_CODE (insn) == NOTE) | |
12411 | insn = prev_nonnote_insn (insn); | |
12412 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 12413 | { |
9ebbca7d GK |
12414 | /* This is slightly ugly, but at least we don't have two |
12415 | copies of the epilogue-emitting code. */ | |
12416 | start_sequence (); | |
12417 | ||
12418 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
12419 | and end of the "toplevel" insn chain. */ | |
2e040219 | 12420 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 12421 | rs6000_emit_epilogue (FALSE); |
2e040219 | 12422 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 12423 | |
178c3eff DJ |
12424 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
12425 | { | |
12426 | rtx insn; | |
12427 | unsigned addr = 0; | |
12428 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
12429 | { | |
12430 | INSN_ADDRESSES_NEW (insn, addr); | |
12431 | addr += 4; | |
12432 | } | |
12433 | } | |
12434 | ||
9ebbca7d | 12435 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
12436 | debug_rtx_list (get_insns (), 100); |
12437 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 12438 | end_sequence (); |
4697a36c | 12439 | } |
9878760c | 12440 | } |
b4ac57ab | 12441 | |
efdba735 SH |
12442 | #if TARGET_MACHO |
12443 | macho_branch_islands (); | |
0e5da0be GK |
12444 | /* Mach-O doesn't support labels at the end of objects, so if |
12445 | it looks like we might want one, insert a NOP. */ | |
12446 | { | |
12447 | rtx insn = get_last_insn (); | |
12448 | while (insn | |
12449 | && NOTE_P (insn) | |
12450 | && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL) | |
12451 | insn = PREV_INSN (insn); | |
12452 | if (insn | |
12453 | && (LABEL_P (insn) | |
12454 | || (NOTE_P (insn) | |
12455 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
12456 | fputs ("\tnop\n", file); | |
12457 | } | |
12458 | #endif | |
12459 | ||
9b30bae2 | 12460 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
12461 | on its format. |
12462 | ||
12463 | We don't output a traceback table if -finhibit-size-directive was | |
12464 | used. The documentation for -finhibit-size-directive reads | |
12465 | ``don't output a @code{.size} assembler directive, or anything | |
12466 | else that would cause trouble if the function is split in the | |
12467 | middle, and the two halves are placed at locations far apart in | |
12468 | memory.'' The traceback table has this property, since it | |
12469 | includes the offset from the start of the function to the | |
4d30c363 MM |
12470 | traceback table itself. |
12471 | ||
12472 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a | 12473 | different traceback table. */ |
57ac7be9 AM |
12474 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive |
12475 | && rs6000_traceback != traceback_none) | |
9b30bae2 | 12476 | { |
69c75916 | 12477 | const char *fname = NULL; |
3ac88239 | 12478 | const char *language_string = lang_hooks.name; |
6041bf2f | 12479 | int fixed_parms = 0, float_parms = 0, parm_info = 0; |
314fc5a9 | 12480 | int i; |
57ac7be9 AM |
12481 | int optional_tbtab; |
12482 | ||
12483 | if (rs6000_traceback == traceback_full) | |
12484 | optional_tbtab = 1; | |
12485 | else if (rs6000_traceback == traceback_part) | |
12486 | optional_tbtab = 0; | |
12487 | else | |
12488 | optional_tbtab = !optimize_size && !TARGET_ELF; | |
314fc5a9 | 12489 | |
69c75916 AM |
12490 | if (optional_tbtab) |
12491 | { | |
12492 | fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
12493 | while (*fname == '.') /* V.4 encodes . in the name */ | |
12494 | fname++; | |
12495 | ||
12496 | /* Need label immediately before tbtab, so we can compute | |
12497 | its offset from the function start. */ | |
12498 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
12499 | ASM_OUTPUT_LABEL (file, fname); | |
12500 | } | |
314fc5a9 ILT |
12501 | |
12502 | /* The .tbtab pseudo-op can only be used for the first eight | |
12503 | expressions, since it can't handle the possibly variable | |
12504 | length fields that follow. However, if you omit the optional | |
12505 | fields, the assembler outputs zeros for all optional fields | |
12506 | anyways, giving each variable length field is minimum length | |
12507 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
12508 | pseudo-op at all. */ | |
12509 | ||
12510 | /* An all-zero word flags the start of the tbtab, for debuggers | |
12511 | that have to find it by searching forward from the entry | |
12512 | point or from the current pc. */ | |
19d2d16f | 12513 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
12514 | |
12515 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 12516 | fputs ("\t.byte 0,", file); |
314fc5a9 ILT |
12517 | |
12518 | /* Language type. Unfortunately, there doesn't seem to be any | |
12519 | official way to get this info, so we use language_string. C | |
12520 | is 0. C++ is 9. No number defined for Obj-C, so use the | |
9517ead8 | 12521 | value for C for now. There is no official value for Java, |
6f573ff9 | 12522 | although IBM appears to be using 13. There is no official value |
f710504c | 12523 | for Chill, so we've chosen 44 pseudo-randomly. */ |
314fc5a9 | 12524 | if (! strcmp (language_string, "GNU C") |
e2c953b6 | 12525 | || ! strcmp (language_string, "GNU Objective-C")) |
314fc5a9 ILT |
12526 | i = 0; |
12527 | else if (! strcmp (language_string, "GNU F77")) | |
12528 | i = 1; | |
12529 | else if (! strcmp (language_string, "GNU Ada")) | |
12530 | i = 3; | |
8b83775b | 12531 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 ILT |
12532 | i = 2; |
12533 | else if (! strcmp (language_string, "GNU C++")) | |
12534 | i = 9; | |
9517ead8 AG |
12535 | else if (! strcmp (language_string, "GNU Java")) |
12536 | i = 13; | |
6f573ff9 JL |
12537 | else if (! strcmp (language_string, "GNU CHILL")) |
12538 | i = 44; | |
314fc5a9 ILT |
12539 | else |
12540 | abort (); | |
12541 | fprintf (file, "%d,", i); | |
12542 | ||
12543 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
12544 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
12545 | from start of procedure stored in tbtab, internal function, function | |
12546 | has controlled storage, function has no toc, function uses fp, | |
12547 | function logs/aborts fp operations. */ | |
12548 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
6041bf2f DE |
12549 | fprintf (file, "%d,", |
12550 | (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1)); | |
314fc5a9 ILT |
12551 | |
12552 | /* 6 bitfields: function is interrupt handler, name present in | |
12553 | proc table, function calls alloca, on condition directives | |
12554 | (controls stack walks, 3 bits), saves condition reg, saves | |
12555 | link reg. */ | |
12556 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
12557 | set up as a frame pointer, even when there is no alloca call. */ | |
12558 | fprintf (file, "%d,", | |
6041bf2f DE |
12559 | ((optional_tbtab << 6) |
12560 | | ((optional_tbtab & frame_pointer_needed) << 5) | |
12561 | | (info->cr_save_p << 1) | |
12562 | | (info->lr_save_p))); | |
314fc5a9 | 12563 | |
6041bf2f | 12564 | /* 3 bitfields: saves backchain, fixup code, number of fpr saved |
314fc5a9 ILT |
12565 | (6 bits). */ |
12566 | fprintf (file, "%d,", | |
4697a36c | 12567 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
12568 | |
12569 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
12570 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
12571 | ||
6041bf2f DE |
12572 | if (optional_tbtab) |
12573 | { | |
12574 | /* Compute the parameter info from the function decl argument | |
12575 | list. */ | |
12576 | tree decl; | |
12577 | int next_parm_info_bit = 31; | |
314fc5a9 | 12578 | |
6041bf2f DE |
12579 | for (decl = DECL_ARGUMENTS (current_function_decl); |
12580 | decl; decl = TREE_CHAIN (decl)) | |
12581 | { | |
12582 | rtx parameter = DECL_INCOMING_RTL (decl); | |
12583 | enum machine_mode mode = GET_MODE (parameter); | |
314fc5a9 | 12584 | |
6041bf2f DE |
12585 | if (GET_CODE (parameter) == REG) |
12586 | { | |
12587 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
12588 | { | |
12589 | int bits; | |
12590 | ||
12591 | float_parms++; | |
12592 | ||
12593 | if (mode == SFmode) | |
12594 | bits = 0x2; | |
fcce224d | 12595 | else if (mode == DFmode || mode == TFmode) |
6041bf2f DE |
12596 | bits = 0x3; |
12597 | else | |
12598 | abort (); | |
12599 | ||
12600 | /* If only one bit will fit, don't or in this entry. */ | |
12601 | if (next_parm_info_bit > 0) | |
12602 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
12603 | next_parm_info_bit -= 2; | |
12604 | } | |
12605 | else | |
12606 | { | |
12607 | fixed_parms += ((GET_MODE_SIZE (mode) | |
12608 | + (UNITS_PER_WORD - 1)) | |
12609 | / UNITS_PER_WORD); | |
12610 | next_parm_info_bit -= 1; | |
12611 | } | |
12612 | } | |
12613 | } | |
12614 | } | |
314fc5a9 ILT |
12615 | |
12616 | /* Number of fixed point parameters. */ | |
12617 | /* This is actually the number of words of fixed point parameters; thus | |
12618 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
12619 | fprintf (file, "%d,", fixed_parms); | |
12620 | ||
12621 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
12622 | all on stack. */ | |
12623 | /* This is actually the number of fp registers that hold parameters; | |
12624 | and thus the maximum value is 13. */ | |
12625 | /* Set parameters on stack bit if parameters are not in their original | |
12626 | registers, regardless of whether they are on the stack? Xlc | |
12627 | seems to set the bit when not optimizing. */ | |
12628 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
12629 | ||
6041bf2f DE |
12630 | if (! optional_tbtab) |
12631 | return; | |
12632 | ||
314fc5a9 ILT |
12633 | /* Optional fields follow. Some are variable length. */ |
12634 | ||
12635 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
12636 | 11 double float. */ | |
12637 | /* There is an entry for each parameter in a register, in the order that | |
12638 | they occur in the parameter list. Any intervening arguments on the | |
12639 | stack are ignored. If the list overflows a long (max possible length | |
12640 | 34 bits) then completely leave off all elements that don't fit. */ | |
12641 | /* Only emit this long if there was at least one parameter. */ | |
12642 | if (fixed_parms || float_parms) | |
12643 | fprintf (file, "\t.long %d\n", parm_info); | |
12644 | ||
12645 | /* Offset from start of code to tb table. */ | |
19d2d16f | 12646 | fputs ("\t.long ", file); |
314fc5a9 | 12647 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
54ee9799 DE |
12648 | #if TARGET_AIX |
12649 | RS6000_OUTPUT_BASENAME (file, fname); | |
12650 | #else | |
9ebbca7d | 12651 | assemble_name (file, fname); |
54ee9799 | 12652 | #endif |
19d2d16f | 12653 | fputs ("-.", file); |
54ee9799 DE |
12654 | #if TARGET_AIX |
12655 | RS6000_OUTPUT_BASENAME (file, fname); | |
12656 | #else | |
9ebbca7d | 12657 | assemble_name (file, fname); |
54ee9799 | 12658 | #endif |
19d2d16f | 12659 | putc ('\n', file); |
314fc5a9 ILT |
12660 | |
12661 | /* Interrupt handler mask. */ | |
12662 | /* Omit this long, since we never set the interrupt handler bit | |
12663 | above. */ | |
12664 | ||
12665 | /* Number of CTL (controlled storage) anchors. */ | |
12666 | /* Omit this long, since the has_ctl bit is never set above. */ | |
12667 | ||
12668 | /* Displacement into stack of each CTL anchor. */ | |
12669 | /* Omit this list of longs, because there are no CTL anchors. */ | |
12670 | ||
12671 | /* Length of function name. */ | |
69c75916 AM |
12672 | if (*fname == '*') |
12673 | ++fname; | |
296b8152 | 12674 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
12675 | |
12676 | /* Function name. */ | |
12677 | assemble_string (fname, strlen (fname)); | |
12678 | ||
12679 | /* Register for alloca automatic storage; this is always reg 31. | |
12680 | Only emit this if the alloca bit was set above. */ | |
12681 | if (frame_pointer_needed) | |
19d2d16f | 12682 | fputs ("\t.byte 31\n", file); |
b1765bde DE |
12683 | |
12684 | fputs ("\t.align 2\n", file); | |
9b30bae2 | 12685 | } |
9878760c | 12686 | } |
17167fd8 | 12687 | \f |
a4f6c312 SS |
12688 | /* A C compound statement that outputs the assembler code for a thunk |
12689 | function, used to implement C++ virtual function calls with | |
12690 | multiple inheritance. The thunk acts as a wrapper around a virtual | |
12691 | function, adjusting the implicit object parameter before handing | |
12692 | control off to the real function. | |
12693 | ||
12694 | First, emit code to add the integer DELTA to the location that | |
12695 | contains the incoming first argument. Assume that this argument | |
12696 | contains a pointer, and is the one used to pass the `this' pointer | |
12697 | in C++. This is the incoming argument *before* the function | |
12698 | prologue, e.g. `%o0' on a sparc. The addition must preserve the | |
12699 | values of all other incoming arguments. | |
17167fd8 MM |
12700 | |
12701 | After the addition, emit code to jump to FUNCTION, which is a | |
a4f6c312 SS |
12702 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does |
12703 | not touch the return address. Hence returning from FUNCTION will | |
12704 | return to whoever called the current `thunk'. | |
17167fd8 | 12705 | |
a4f6c312 SS |
12706 | The effect must be as if FUNCTION had been called directly with the |
12707 | adjusted first argument. This macro is responsible for emitting | |
12708 | all of the code for a thunk function; output_function_prologue() | |
12709 | and output_function_epilogue() are not invoked. | |
17167fd8 | 12710 | |
a4f6c312 SS |
12711 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already |
12712 | been extracted from it.) It might possibly be useful on some | |
12713 | targets, but probably not. | |
17167fd8 | 12714 | |
a4f6c312 SS |
12715 | If you do not define this macro, the target-independent code in the |
12716 | C++ frontend will generate a less efficient heavyweight thunk that | |
12717 | calls FUNCTION instead of jumping to it. The generic approach does | |
12718 | not support varargs. */ | |
17167fd8 | 12719 | |
3961e8fe | 12720 | static void |
a2369ed3 DJ |
12721 | rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, |
12722 | HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, | |
12723 | tree function) | |
17167fd8 | 12724 | { |
5b71a4e7 | 12725 | rtx this, insn, funexp; |
17167fd8 | 12726 | |
5b71a4e7 | 12727 | reload_completed = 1; |
fe3ad572 | 12728 | epilogue_completed = 1; |
5b71a4e7 | 12729 | no_new_pseudos = 1; |
56a7189a | 12730 | |
5b71a4e7 | 12731 | /* Mark the end of the (empty) prologue. */ |
2e040219 | 12732 | emit_note (NOTE_INSN_PROLOGUE_END); |
17167fd8 | 12733 | |
5b71a4e7 DE |
12734 | /* Find the "this" pointer. If the function returns a structure, |
12735 | the structure return pointer is in r3. */ | |
61f71b34 | 12736 | if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) |
5b71a4e7 | 12737 | this = gen_rtx_REG (Pmode, 4); |
56a7189a | 12738 | else |
5b71a4e7 | 12739 | this = gen_rtx_REG (Pmode, 3); |
17167fd8 | 12740 | |
5b71a4e7 DE |
12741 | /* Apply the constant offset, if required. */ |
12742 | if (delta) | |
12743 | { | |
12744 | rtx delta_rtx = GEN_INT (delta); | |
12745 | emit_insn (TARGET_32BIT | |
12746 | ? gen_addsi3 (this, this, delta_rtx) | |
12747 | : gen_adddi3 (this, this, delta_rtx)); | |
17167fd8 MM |
12748 | } |
12749 | ||
5b71a4e7 DE |
12750 | /* Apply the offset from the vtable, if required. */ |
12751 | if (vcall_offset) | |
17167fd8 | 12752 | { |
5b71a4e7 DE |
12753 | rtx vcall_offset_rtx = GEN_INT (vcall_offset); |
12754 | rtx tmp = gen_rtx_REG (Pmode, 12); | |
17167fd8 | 12755 | |
5b71a4e7 | 12756 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, this)); |
eeff9307 JJ |
12757 | if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000) |
12758 | { | |
12759 | emit_insn (TARGET_32BIT | |
12760 | ? gen_addsi3 (tmp, tmp, vcall_offset_rtx) | |
12761 | : gen_adddi3 (tmp, tmp, vcall_offset_rtx)); | |
12762 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
12763 | } | |
12764 | else | |
12765 | { | |
12766 | rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx); | |
12767 | ||
12768 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc)); | |
12769 | } | |
5b71a4e7 DE |
12770 | emit_insn (TARGET_32BIT |
12771 | ? gen_addsi3 (this, this, tmp) | |
12772 | : gen_adddi3 (this, this, tmp)); | |
17167fd8 MM |
12773 | } |
12774 | ||
5b71a4e7 DE |
12775 | /* Generate a tail call to the target function. */ |
12776 | if (!TREE_USED (function)) | |
12777 | { | |
12778 | assemble_external (function); | |
12779 | TREE_USED (function) = 1; | |
12780 | } | |
12781 | funexp = XEXP (DECL_RTL (function), 0); | |
5b71a4e7 | 12782 | funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); |
ee890fe2 SS |
12783 | |
12784 | #if TARGET_MACHO | |
ab82a49f | 12785 | if (MACHOPIC_INDIRECT) |
5b71a4e7 | 12786 | funexp = machopic_indirect_call_target (funexp); |
ee890fe2 | 12787 | #endif |
5b71a4e7 DE |
12788 | |
12789 | /* gen_sibcall expects reload to convert scratch pseudo to LR so we must | |
12790 | generate sibcall RTL explicitly to avoid constraint abort. */ | |
12791 | insn = emit_call_insn ( | |
12792 | gen_rtx_PARALLEL (VOIDmode, | |
12793 | gen_rtvec (4, | |
12794 | gen_rtx_CALL (VOIDmode, | |
12795 | funexp, const0_rtx), | |
12796 | gen_rtx_USE (VOIDmode, const0_rtx), | |
12797 | gen_rtx_USE (VOIDmode, | |
12798 | gen_rtx_REG (SImode, | |
12799 | LINK_REGISTER_REGNUM)), | |
12800 | gen_rtx_RETURN (VOIDmode)))); | |
12801 | SIBLING_CALL_P (insn) = 1; | |
12802 | emit_barrier (); | |
12803 | ||
12804 | /* Run just enough of rest_of_compilation to get the insns emitted. | |
12805 | There's not really enough bulk here to make other passes such as | |
12806 | instruction scheduling worth while. Note that use_thunk calls | |
12807 | assemble_start_function and assemble_end_function. */ | |
12808 | insn = get_insns (); | |
a2855205 | 12809 | insn_locators_initialize (); |
5b71a4e7 DE |
12810 | shorten_branches (insn); |
12811 | final_start_function (insn, file, 1); | |
12812 | final (insn, file, 1, 0); | |
12813 | final_end_function (); | |
12814 | ||
12815 | reload_completed = 0; | |
fe3ad572 | 12816 | epilogue_completed = 0; |
5b71a4e7 | 12817 | no_new_pseudos = 0; |
9ebbca7d | 12818 | } |
9ebbca7d GK |
12819 | \f |
12820 | /* A quick summary of the various types of 'constant-pool tables' | |
12821 | under PowerPC: | |
12822 | ||
12823 | Target Flags Name One table per | |
12824 | AIX (none) AIX TOC object file | |
12825 | AIX -mfull-toc AIX TOC object file | |
12826 | AIX -mminimal-toc AIX minimal TOC translation unit | |
12827 | SVR4/EABI (none) SVR4 SDATA object file | |
12828 | SVR4/EABI -fpic SVR4 pic object file | |
12829 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
12830 | SVR4/EABI -mrelocatable EABI TOC function | |
12831 | SVR4/EABI -maix AIX TOC object file | |
12832 | SVR4/EABI -maix -mminimal-toc | |
12833 | AIX minimal TOC translation unit | |
12834 | ||
12835 | Name Reg. Set by entries contains: | |
12836 | made by addrs? fp? sum? | |
12837 | ||
12838 | AIX TOC 2 crt0 as Y option option | |
12839 | AIX minimal TOC 30 prolog gcc Y Y option | |
12840 | SVR4 SDATA 13 crt0 gcc N Y N | |
12841 | SVR4 pic 30 prolog ld Y not yet N | |
12842 | SVR4 PIC 30 prolog gcc Y option option | |
12843 | EABI TOC 30 prolog gcc Y option option | |
12844 | ||
12845 | */ | |
12846 | ||
9ebbca7d GK |
12847 | /* Hash functions for the hash table. */ |
12848 | ||
12849 | static unsigned | |
a2369ed3 | 12850 | rs6000_hash_constant (rtx k) |
9ebbca7d | 12851 | { |
46b33600 RH |
12852 | enum rtx_code code = GET_CODE (k); |
12853 | enum machine_mode mode = GET_MODE (k); | |
12854 | unsigned result = (code << 3) ^ mode; | |
12855 | const char *format; | |
12856 | int flen, fidx; | |
9ebbca7d | 12857 | |
46b33600 RH |
12858 | format = GET_RTX_FORMAT (code); |
12859 | flen = strlen (format); | |
12860 | fidx = 0; | |
9ebbca7d | 12861 | |
46b33600 RH |
12862 | switch (code) |
12863 | { | |
12864 | case LABEL_REF: | |
12865 | return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0)); | |
12866 | ||
12867 | case CONST_DOUBLE: | |
12868 | if (mode != VOIDmode) | |
12869 | return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result; | |
12870 | flen = 2; | |
12871 | break; | |
12872 | ||
12873 | case CODE_LABEL: | |
12874 | fidx = 3; | |
12875 | break; | |
12876 | ||
12877 | default: | |
12878 | break; | |
12879 | } | |
9ebbca7d GK |
12880 | |
12881 | for (; fidx < flen; fidx++) | |
12882 | switch (format[fidx]) | |
12883 | { | |
12884 | case 's': | |
12885 | { | |
12886 | unsigned i, len; | |
12887 | const char *str = XSTR (k, fidx); | |
12888 | len = strlen (str); | |
12889 | result = result * 613 + len; | |
12890 | for (i = 0; i < len; i++) | |
12891 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
12892 | break; |
12893 | } | |
9ebbca7d GK |
12894 | case 'u': |
12895 | case 'e': | |
12896 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
12897 | break; | |
12898 | case 'i': | |
12899 | case 'n': | |
12900 | result = result * 613 + (unsigned) XINT (k, fidx); | |
12901 | break; | |
12902 | case 'w': | |
12903 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
12904 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
12905 | else | |
12906 | { | |
12907 | size_t i; | |
12908 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
12909 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
12910 | >> CHAR_BIT * i); | |
12911 | } | |
12912 | break; | |
09501938 DE |
12913 | case '0': |
12914 | break; | |
9ebbca7d | 12915 | default: |
a4f6c312 | 12916 | abort (); |
9ebbca7d | 12917 | } |
46b33600 | 12918 | |
9ebbca7d GK |
12919 | return result; |
12920 | } | |
12921 | ||
12922 | static unsigned | |
a2369ed3 | 12923 | toc_hash_function (const void *hash_entry) |
9ebbca7d | 12924 | { |
a9098fd0 GK |
12925 | const struct toc_hash_struct *thc = |
12926 | (const struct toc_hash_struct *) hash_entry; | |
12927 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
12928 | } |
12929 | ||
12930 | /* Compare H1 and H2 for equivalence. */ | |
12931 | ||
12932 | static int | |
a2369ed3 | 12933 | toc_hash_eq (const void *h1, const void *h2) |
9ebbca7d GK |
12934 | { |
12935 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
12936 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
12937 | ||
a9098fd0 GK |
12938 | if (((const struct toc_hash_struct *) h1)->key_mode |
12939 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
12940 | return 0; | |
12941 | ||
5692c7bc | 12942 | return rtx_equal_p (r1, r2); |
9ebbca7d GK |
12943 | } |
12944 | ||
28e510bd MM |
12945 | /* These are the names given by the C++ front-end to vtables, and |
12946 | vtable-like objects. Ideally, this logic should not be here; | |
12947 | instead, there should be some programmatic way of inquiring as | |
12948 | to whether or not an object is a vtable. */ | |
12949 | ||
12950 | #define VTABLE_NAME_P(NAME) \ | |
12951 | (strncmp ("_vt.", name, strlen("_vt.")) == 0 \ | |
12952 | || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \ | |
12953 | || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \ | |
12954 | || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0) | |
12955 | ||
12956 | void | |
a2369ed3 | 12957 | rs6000_output_symbol_ref (FILE *file, rtx x) |
28e510bd MM |
12958 | { |
12959 | /* Currently C++ toc references to vtables can be emitted before it | |
12960 | is decided whether the vtable is public or private. If this is | |
12961 | the case, then the linker will eventually complain that there is | |
12962 | a reference to an unknown section. Thus, for vtables only, | |
12963 | we emit the TOC reference to reference the symbol and not the | |
12964 | section. */ | |
12965 | const char *name = XSTR (x, 0); | |
54ee9799 DE |
12966 | |
12967 | if (VTABLE_NAME_P (name)) | |
12968 | { | |
12969 | RS6000_OUTPUT_BASENAME (file, name); | |
12970 | } | |
12971 | else | |
12972 | assemble_name (file, name); | |
28e510bd MM |
12973 | } |
12974 | ||
a4f6c312 SS |
12975 | /* Output a TOC entry. We derive the entry name from what is being |
12976 | written. */ | |
9878760c RK |
12977 | |
12978 | void | |
a2369ed3 | 12979 | output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode) |
9878760c RK |
12980 | { |
12981 | char buf[256]; | |
3cce094d | 12982 | const char *name = buf; |
ec940faa | 12983 | const char *real_name; |
9878760c RK |
12984 | rtx base = x; |
12985 | int offset = 0; | |
12986 | ||
4697a36c MM |
12987 | if (TARGET_NO_TOC) |
12988 | abort (); | |
12989 | ||
9ebbca7d GK |
12990 | /* When the linker won't eliminate them, don't output duplicate |
12991 | TOC entries (this happens on AIX if there is any kind of TOC, | |
17211ab5 GK |
12992 | and on SVR4 under -fPIC or -mrelocatable). Don't do this for |
12993 | CODE_LABELs. */ | |
12994 | if (TARGET_TOC && GET_CODE (x) != LABEL_REF) | |
9ebbca7d GK |
12995 | { |
12996 | struct toc_hash_struct *h; | |
12997 | void * * found; | |
12998 | ||
17211ab5 | 12999 | /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS |
39e3f58c | 13000 | time because GGC is not initialized at that point. */ |
17211ab5 GK |
13001 | if (toc_hash_table == NULL) |
13002 | toc_hash_table = htab_create_ggc (1021, toc_hash_function, | |
13003 | toc_hash_eq, NULL); | |
13004 | ||
9ebbca7d GK |
13005 | h = ggc_alloc (sizeof (*h)); |
13006 | h->key = x; | |
a9098fd0 | 13007 | h->key_mode = mode; |
9ebbca7d GK |
13008 | h->labelno = labelno; |
13009 | ||
13010 | found = htab_find_slot (toc_hash_table, h, 1); | |
13011 | if (*found == NULL) | |
13012 | *found = h; | |
13013 | else /* This is indeed a duplicate. | |
13014 | Set this label equal to that label. */ | |
13015 | { | |
13016 | fputs ("\t.set ", file); | |
13017 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
13018 | fprintf (file, "%d,", labelno); | |
13019 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
13020 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) | |
13021 | found)->labelno)); | |
13022 | return; | |
13023 | } | |
13024 | } | |
13025 | ||
13026 | /* If we're going to put a double constant in the TOC, make sure it's | |
13027 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
13028 | if (GET_CODE (x) == CONST_DOUBLE |
13029 | && STRICT_ALIGNMENT | |
a9098fd0 | 13030 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
13031 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
13032 | ASM_OUTPUT_ALIGN (file, 3); | |
13033 | } | |
13034 | ||
4977bab6 | 13035 | (*targetm.asm_out.internal_label) (file, "LC", labelno); |
9878760c | 13036 | |
37c37a57 RK |
13037 | /* Handle FP constants specially. Note that if we have a minimal |
13038 | TOC, things we put here aren't actually in the TOC, so we can allow | |
13039 | FP constants. */ | |
fcce224d DE |
13040 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode) |
13041 | { | |
13042 | REAL_VALUE_TYPE rv; | |
13043 | long k[4]; | |
13044 | ||
13045 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
13046 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
13047 | ||
13048 | if (TARGET_64BIT) | |
13049 | { | |
13050 | if (TARGET_MINIMAL_TOC) | |
13051 | fputs (DOUBLE_INT_ASM_OP, file); | |
13052 | else | |
13053 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
13054 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13055 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13056 | fprintf (file, "0x%lx%08lx,0x%lx%08lx\n", | |
13057 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13058 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13059 | return; | |
13060 | } | |
13061 | else | |
13062 | { | |
13063 | if (TARGET_MINIMAL_TOC) | |
13064 | fputs ("\t.long ", file); | |
13065 | else | |
13066 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
13067 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13068 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13069 | fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n", | |
13070 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13071 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13072 | return; | |
13073 | } | |
13074 | } | |
13075 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) | |
9878760c | 13076 | { |
042259f2 DE |
13077 | REAL_VALUE_TYPE rv; |
13078 | long k[2]; | |
0adc764e | 13079 | |
042259f2 DE |
13080 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
13081 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 13082 | |
13ded975 DE |
13083 | if (TARGET_64BIT) |
13084 | { | |
13085 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13086 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 13087 | else |
2f0552b6 AM |
13088 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
13089 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13090 | fprintf (file, "0x%lx%08lx\n", | |
13091 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
13092 | return; |
13093 | } | |
1875cc88 | 13094 | else |
13ded975 DE |
13095 | { |
13096 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13097 | fputs ("\t.long ", file); |
13ded975 | 13098 | else |
2f0552b6 AM |
13099 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
13100 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13101 | fprintf (file, "0x%lx,0x%lx\n", | |
13102 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
13103 | return; |
13104 | } | |
9878760c | 13105 | } |
a9098fd0 | 13106 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 13107 | { |
042259f2 DE |
13108 | REAL_VALUE_TYPE rv; |
13109 | long l; | |
9878760c | 13110 | |
042259f2 DE |
13111 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
13112 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
13113 | ||
31bfaa0b DE |
13114 | if (TARGET_64BIT) |
13115 | { | |
13116 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13117 | fputs (DOUBLE_INT_ASM_OP, file); |
31bfaa0b | 13118 | else |
2f0552b6 AM |
13119 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
13120 | fprintf (file, "0x%lx00000000\n", l & 0xffffffff); | |
31bfaa0b DE |
13121 | return; |
13122 | } | |
042259f2 | 13123 | else |
31bfaa0b DE |
13124 | { |
13125 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13126 | fputs ("\t.long ", file); |
31bfaa0b | 13127 | else |
2f0552b6 AM |
13128 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
13129 | fprintf (file, "0x%lx\n", l & 0xffffffff); | |
31bfaa0b DE |
13130 | return; |
13131 | } | |
042259f2 | 13132 | } |
f176e826 | 13133 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 13134 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 13135 | { |
e2c953b6 | 13136 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
13137 | HOST_WIDE_INT high; |
13138 | ||
13139 | if (GET_CODE (x) == CONST_DOUBLE) | |
13140 | { | |
13141 | low = CONST_DOUBLE_LOW (x); | |
13142 | high = CONST_DOUBLE_HIGH (x); | |
13143 | } | |
13144 | else | |
13145 | #if HOST_BITS_PER_WIDE_INT == 32 | |
13146 | { | |
13147 | low = INTVAL (x); | |
0858c623 | 13148 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
13149 | } |
13150 | #else | |
13151 | { | |
0858c623 | 13152 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
13153 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
13154 | } | |
13155 | #endif | |
9878760c | 13156 | |
a9098fd0 GK |
13157 | /* TOC entries are always Pmode-sized, but since this |
13158 | is a bigendian machine then if we're putting smaller | |
13159 | integer constants in the TOC we have to pad them. | |
13160 | (This is still a win over putting the constants in | |
13161 | a separate constant pool, because then we'd have | |
02a4ec28 FS |
13162 | to have both a TOC entry _and_ the actual constant.) |
13163 | ||
13164 | For a 32-bit target, CONST_INT values are loaded and shifted | |
13165 | entirely within `low' and can be stored in one TOC entry. */ | |
13166 | ||
13167 | if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
a9098fd0 | 13168 | abort ();/* It would be easy to make this work, but it doesn't now. */ |
02a4ec28 FS |
13169 | |
13170 | if (POINTER_SIZE > GET_MODE_BITSIZE (mode)) | |
fb52d8de AM |
13171 | { |
13172 | #if HOST_BITS_PER_WIDE_INT == 32 | |
13173 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), | |
13174 | POINTER_SIZE, &low, &high, 0); | |
13175 | #else | |
13176 | low |= high << 32; | |
13177 | low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode); | |
13178 | high = (HOST_WIDE_INT) low >> 32; | |
13179 | low &= 0xffffffff; | |
13180 | #endif | |
13181 | } | |
a9098fd0 | 13182 | |
13ded975 DE |
13183 | if (TARGET_64BIT) |
13184 | { | |
13185 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13186 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 13187 | else |
2f0552b6 AM |
13188 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
13189 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13190 | fprintf (file, "0x%lx%08lx\n", | |
13191 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13ded975 DE |
13192 | return; |
13193 | } | |
1875cc88 | 13194 | else |
13ded975 | 13195 | { |
02a4ec28 FS |
13196 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) |
13197 | { | |
13198 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13199 | fputs ("\t.long ", file); |
02a4ec28 | 13200 | else |
2bfcf297 | 13201 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
2f0552b6 AM |
13202 | (long) high & 0xffffffff, (long) low & 0xffffffff); |
13203 | fprintf (file, "0x%lx,0x%lx\n", | |
13204 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
02a4ec28 | 13205 | } |
13ded975 | 13206 | else |
02a4ec28 FS |
13207 | { |
13208 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13209 | fputs ("\t.long ", file); |
02a4ec28 | 13210 | else |
2f0552b6 AM |
13211 | fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff); |
13212 | fprintf (file, "0x%lx\n", (long) low & 0xffffffff); | |
02a4ec28 | 13213 | } |
13ded975 DE |
13214 | return; |
13215 | } | |
9878760c RK |
13216 | } |
13217 | ||
13218 | if (GET_CODE (x) == CONST) | |
13219 | { | |
2bfcf297 DB |
13220 | if (GET_CODE (XEXP (x, 0)) != PLUS) |
13221 | abort (); | |
13222 | ||
9878760c RK |
13223 | base = XEXP (XEXP (x, 0), 0); |
13224 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
13225 | } | |
13226 | ||
13227 | if (GET_CODE (base) == SYMBOL_REF) | |
13228 | name = XSTR (base, 0); | |
13229 | else if (GET_CODE (base) == LABEL_REF) | |
13230 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
13231 | else if (GET_CODE (base) == CODE_LABEL) | |
13232 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
13233 | else | |
13234 | abort (); | |
13235 | ||
772c5265 | 13236 | real_name = (*targetm.strip_name_encoding) (name); |
1875cc88 | 13237 | if (TARGET_MINIMAL_TOC) |
2bfcf297 | 13238 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); |
1875cc88 JW |
13239 | else |
13240 | { | |
b6c9286a | 13241 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 13242 | |
1875cc88 JW |
13243 | if (offset < 0) |
13244 | fprintf (file, ".N%d", - offset); | |
13245 | else if (offset) | |
13246 | fprintf (file, ".P%d", offset); | |
9878760c | 13247 | |
19d2d16f | 13248 | fputs ("[TC],", file); |
1875cc88 | 13249 | } |
581bc4de MM |
13250 | |
13251 | /* Currently C++ toc references to vtables can be emitted before it | |
13252 | is decided whether the vtable is public or private. If this is | |
13253 | the case, then the linker will eventually complain that there is | |
13254 | a TOC reference to an unknown section. Thus, for vtables only, | |
13255 | we emit the TOC reference to reference the symbol and not the | |
13256 | section. */ | |
28e510bd | 13257 | if (VTABLE_NAME_P (name)) |
581bc4de | 13258 | { |
54ee9799 | 13259 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
13260 | if (offset < 0) |
13261 | fprintf (file, "%d", offset); | |
13262 | else if (offset > 0) | |
13263 | fprintf (file, "+%d", offset); | |
13264 | } | |
13265 | else | |
13266 | output_addr_const (file, x); | |
19d2d16f | 13267 | putc ('\n', file); |
9878760c RK |
13268 | } |
13269 | \f | |
13270 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
13271 | starting at P to FILE. | |
13272 | ||
13273 | On the RS/6000, we have to do this using the .byte operation and | |
13274 | write out special characters outside the quoted string. | |
13275 | Also, the assembler is broken; very long strings are truncated, | |
a4f6c312 | 13276 | so we must artificially break them up early. */ |
9878760c RK |
13277 | |
13278 | void | |
a2369ed3 | 13279 | output_ascii (FILE *file, const char *p, int n) |
9878760c RK |
13280 | { |
13281 | char c; | |
13282 | int i, count_string; | |
d330fd93 KG |
13283 | const char *for_string = "\t.byte \""; |
13284 | const char *for_decimal = "\t.byte "; | |
13285 | const char *to_close = NULL; | |
9878760c RK |
13286 | |
13287 | count_string = 0; | |
13288 | for (i = 0; i < n; i++) | |
13289 | { | |
13290 | c = *p++; | |
13291 | if (c >= ' ' && c < 0177) | |
13292 | { | |
13293 | if (for_string) | |
13294 | fputs (for_string, file); | |
13295 | putc (c, file); | |
13296 | ||
13297 | /* Write two quotes to get one. */ | |
13298 | if (c == '"') | |
13299 | { | |
13300 | putc (c, file); | |
13301 | ++count_string; | |
13302 | } | |
13303 | ||
13304 | for_string = NULL; | |
13305 | for_decimal = "\"\n\t.byte "; | |
13306 | to_close = "\"\n"; | |
13307 | ++count_string; | |
13308 | ||
13309 | if (count_string >= 512) | |
13310 | { | |
13311 | fputs (to_close, file); | |
13312 | ||
13313 | for_string = "\t.byte \""; | |
13314 | for_decimal = "\t.byte "; | |
13315 | to_close = NULL; | |
13316 | count_string = 0; | |
13317 | } | |
13318 | } | |
13319 | else | |
13320 | { | |
13321 | if (for_decimal) | |
13322 | fputs (for_decimal, file); | |
13323 | fprintf (file, "%d", c); | |
13324 | ||
13325 | for_string = "\n\t.byte \""; | |
13326 | for_decimal = ", "; | |
13327 | to_close = "\n"; | |
13328 | count_string = 0; | |
13329 | } | |
13330 | } | |
13331 | ||
13332 | /* Now close the string if we have written one. Then end the line. */ | |
13333 | if (to_close) | |
9ebbca7d | 13334 | fputs (to_close, file); |
9878760c RK |
13335 | } |
13336 | \f | |
13337 | /* Generate a unique section name for FILENAME for a section type | |
13338 | represented by SECTION_DESC. Output goes into BUF. | |
13339 | ||
13340 | SECTION_DESC can be any string, as long as it is different for each | |
13341 | possible section type. | |
13342 | ||
13343 | We name the section in the same manner as xlc. The name begins with an | |
13344 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
13345 | names) with the last period replaced by the string SECTION_DESC. If |
13346 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
13347 | the name. */ | |
9878760c RK |
13348 | |
13349 | void | |
a2369ed3 DJ |
13350 | rs6000_gen_section_name (char **buf, const char *filename, |
13351 | const char *section_desc) | |
9878760c | 13352 | { |
9ebbca7d | 13353 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
13354 | char *p; |
13355 | int len; | |
9878760c RK |
13356 | |
13357 | after_last_slash = filename; | |
13358 | for (q = filename; *q; q++) | |
11e5fe42 RK |
13359 | { |
13360 | if (*q == '/') | |
13361 | after_last_slash = q + 1; | |
13362 | else if (*q == '.') | |
13363 | last_period = q; | |
13364 | } | |
9878760c | 13365 | |
11e5fe42 | 13366 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
6d9f628e | 13367 | *buf = (char *) xmalloc (len); |
9878760c RK |
13368 | |
13369 | p = *buf; | |
13370 | *p++ = '_'; | |
13371 | ||
13372 | for (q = after_last_slash; *q; q++) | |
13373 | { | |
11e5fe42 | 13374 | if (q == last_period) |
9878760c RK |
13375 | { |
13376 | strcpy (p, section_desc); | |
13377 | p += strlen (section_desc); | |
e3981aab | 13378 | break; |
9878760c RK |
13379 | } |
13380 | ||
e9a780ec | 13381 | else if (ISALNUM (*q)) |
9878760c RK |
13382 | *p++ = *q; |
13383 | } | |
13384 | ||
11e5fe42 | 13385 | if (last_period == 0) |
9878760c RK |
13386 | strcpy (p, section_desc); |
13387 | else | |
13388 | *p = '\0'; | |
13389 | } | |
e165f3f0 | 13390 | \f |
a4f6c312 | 13391 | /* Emit profile function. */ |
411707f4 | 13392 | |
411707f4 | 13393 | void |
a2369ed3 | 13394 | output_profile_hook (int labelno ATTRIBUTE_UNUSED) |
411707f4 | 13395 | { |
ffcfcb5f AM |
13396 | if (TARGET_PROFILE_KERNEL) |
13397 | return; | |
13398 | ||
8480e480 CC |
13399 | if (DEFAULT_ABI == ABI_AIX) |
13400 | { | |
9739c90c JJ |
13401 | #ifndef NO_PROFILE_COUNTERS |
13402 | # define NO_PROFILE_COUNTERS 0 | |
13403 | #endif | |
13404 | if (NO_PROFILE_COUNTERS) | |
13405 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0); | |
13406 | else | |
13407 | { | |
13408 | char buf[30]; | |
13409 | const char *label_name; | |
13410 | rtx fun; | |
411707f4 | 13411 | |
9739c90c JJ |
13412 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
13413 | label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf)); | |
13414 | fun = gen_rtx_SYMBOL_REF (Pmode, label_name); | |
411707f4 | 13415 | |
9739c90c JJ |
13416 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1, |
13417 | fun, Pmode); | |
13418 | } | |
8480e480 | 13419 | } |
ee890fe2 SS |
13420 | else if (DEFAULT_ABI == ABI_DARWIN) |
13421 | { | |
d5fa86ba | 13422 | const char *mcount_name = RS6000_MCOUNT; |
ee890fe2 SS |
13423 | int caller_addr_regno = LINK_REGISTER_REGNUM; |
13424 | ||
13425 | /* Be conservative and always set this, at least for now. */ | |
13426 | current_function_uses_pic_offset_table = 1; | |
13427 | ||
13428 | #if TARGET_MACHO | |
13429 | /* For PIC code, set up a stub and collect the caller's address | |
13430 | from r0, which is where the prologue puts it. */ | |
ab82a49f | 13431 | if (MACHOPIC_INDIRECT) |
ee890fe2 SS |
13432 | { |
13433 | mcount_name = machopic_stub_name (mcount_name); | |
13434 | if (current_function_uses_pic_offset_table) | |
13435 | caller_addr_regno = 0; | |
13436 | } | |
13437 | #endif | |
13438 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name), | |
13439 | 0, VOIDmode, 1, | |
13440 | gen_rtx_REG (Pmode, caller_addr_regno), Pmode); | |
13441 | } | |
411707f4 CC |
13442 | } |
13443 | ||
a4f6c312 | 13444 | /* Write function profiler code. */ |
e165f3f0 RK |
13445 | |
13446 | void | |
a2369ed3 | 13447 | output_function_profiler (FILE *file, int labelno) |
e165f3f0 | 13448 | { |
3daf36a4 | 13449 | char buf[100]; |
09eeeacb | 13450 | int save_lr = 8; |
e165f3f0 | 13451 | |
38c1f2d7 | 13452 | switch (DEFAULT_ABI) |
3daf36a4 | 13453 | { |
38c1f2d7 MM |
13454 | default: |
13455 | abort (); | |
13456 | ||
13457 | case ABI_V4: | |
09eeeacb | 13458 | save_lr = 4; |
09eeeacb AM |
13459 | if (!TARGET_32BIT) |
13460 | { | |
13461 | warning ("no profiling of 64-bit code for this ABI"); | |
13462 | return; | |
13463 | } | |
ffcfcb5f | 13464 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 MM |
13465 | fprintf (file, "\tmflr %s\n", reg_names[0]); |
13466 | if (flag_pic == 1) | |
13467 | { | |
dfdfa60f | 13468 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
09eeeacb AM |
13469 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
13470 | reg_names[0], save_lr, reg_names[1]); | |
17167fd8 | 13471 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 13472 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 13473 | assemble_name (file, buf); |
17167fd8 | 13474 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 13475 | } |
9ebbca7d | 13476 | else if (flag_pic > 1) |
38c1f2d7 | 13477 | { |
09eeeacb AM |
13478 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
13479 | reg_names[0], save_lr, reg_names[1]); | |
9ebbca7d GK |
13480 | /* Now, we need to get the address of the label. */ |
13481 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 13482 | assemble_name (file, buf); |
9ebbca7d GK |
13483 | fputs ("-.\n1:", file); |
13484 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
13485 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", | |
13486 | reg_names[0], reg_names[11]); | |
13487 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
13488 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 13489 | } |
38c1f2d7 MM |
13490 | else |
13491 | { | |
17167fd8 | 13492 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 13493 | assemble_name (file, buf); |
dfdfa60f | 13494 | fputs ("@ha\n", file); |
09eeeacb AM |
13495 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
13496 | reg_names[0], save_lr, reg_names[1]); | |
a260abc9 | 13497 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 13498 | assemble_name (file, buf); |
17167fd8 | 13499 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
13500 | } |
13501 | ||
50d440bc NC |
13502 | /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */ |
13503 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
38c1f2d7 MM |
13504 | break; |
13505 | ||
13506 | case ABI_AIX: | |
ee890fe2 | 13507 | case ABI_DARWIN: |
ffcfcb5f AM |
13508 | if (!TARGET_PROFILE_KERNEL) |
13509 | { | |
13510 | /* Don't do anything, done in output_profile_hook (). */ | |
13511 | } | |
13512 | else | |
13513 | { | |
13514 | if (TARGET_32BIT) | |
13515 | abort (); | |
13516 | ||
13517 | asm_fprintf (file, "\tmflr %s\n", reg_names[0]); | |
13518 | asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]); | |
13519 | ||
13520 | if (current_function_needs_context) | |
13521 | { | |
13522 | asm_fprintf (file, "\tstd %s,24(%s)\n", | |
13523 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
13524 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
13525 | asm_fprintf (file, "\tld %s,24(%s)\n", | |
13526 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
13527 | } | |
13528 | else | |
13529 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
13530 | } | |
38c1f2d7 MM |
13531 | break; |
13532 | } | |
e165f3f0 | 13533 | } |
a251ffd0 | 13534 | |
b54cf83a DE |
13535 | \f |
13536 | static int | |
863d938c | 13537 | rs6000_use_dfa_pipeline_interface (void) |
b54cf83a DE |
13538 | { |
13539 | return 1; | |
13540 | } | |
13541 | ||
b54cf83a DE |
13542 | /* Power4 load update and store update instructions are cracked into a |
13543 | load or store and an integer insn which are executed in the same cycle. | |
13544 | Branches have their own dispatch slot which does not count against the | |
13545 | GCC issue rate, but it changes the program flow so there are no other | |
13546 | instructions to issue in this cycle. */ | |
13547 | ||
13548 | static int | |
a2369ed3 DJ |
13549 | rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED, |
13550 | int verbose ATTRIBUTE_UNUSED, | |
13551 | rtx insn, int more) | |
b54cf83a DE |
13552 | { |
13553 | if (GET_CODE (PATTERN (insn)) == USE | |
13554 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
13555 | return more; | |
13556 | ||
13557 | if (rs6000_cpu == PROCESSOR_POWER4) | |
13558 | { | |
cbe26ab8 DN |
13559 | if (is_microcoded_insn (insn)) |
13560 | return 0; | |
13561 | else if (is_cracked_insn (insn)) | |
13562 | return more > 2 ? more - 2 : 0; | |
b54cf83a | 13563 | } |
165b263e DE |
13564 | |
13565 | return more - 1; | |
b54cf83a DE |
13566 | } |
13567 | ||
a251ffd0 TG |
13568 | /* Adjust the cost of a scheduling dependency. Return the new cost of |
13569 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
13570 | ||
c237e94a | 13571 | static int |
a2369ed3 DJ |
13572 | rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED, |
13573 | int cost) | |
a251ffd0 TG |
13574 | { |
13575 | if (! recog_memoized (insn)) | |
13576 | return 0; | |
13577 | ||
13578 | if (REG_NOTE_KIND (link) != 0) | |
13579 | return 0; | |
13580 | ||
13581 | if (REG_NOTE_KIND (link) == 0) | |
13582 | { | |
ed947a96 DJ |
13583 | /* Data dependency; DEP_INSN writes a register that INSN reads |
13584 | some cycles later. */ | |
13585 | switch (get_attr_type (insn)) | |
13586 | { | |
13587 | case TYPE_JMPREG: | |
309323c2 | 13588 | /* Tell the first scheduling pass about the latency between |
ed947a96 DJ |
13589 | a mtctr and bctr (and mtlr and br/blr). The first |
13590 | scheduling pass will not know about this latency since | |
13591 | the mtctr instruction, which has the latency associated | |
13592 | to it, will be generated by reload. */ | |
309323c2 | 13593 | return TARGET_POWER ? 5 : 4; |
ed947a96 DJ |
13594 | case TYPE_BRANCH: |
13595 | /* Leave some extra cycles between a compare and its | |
13596 | dependent branch, to inhibit expensive mispredicts. */ | |
309323c2 DE |
13597 | if ((rs6000_cpu_attr == CPU_PPC603 |
13598 | || rs6000_cpu_attr == CPU_PPC604 | |
13599 | || rs6000_cpu_attr == CPU_PPC604E | |
13600 | || rs6000_cpu_attr == CPU_PPC620 | |
13601 | || rs6000_cpu_attr == CPU_PPC630 | |
13602 | || rs6000_cpu_attr == CPU_PPC750 | |
13603 | || rs6000_cpu_attr == CPU_PPC7400 | |
13604 | || rs6000_cpu_attr == CPU_PPC7450 | |
13605 | || rs6000_cpu_attr == CPU_POWER4) | |
ed947a96 DJ |
13606 | && recog_memoized (dep_insn) |
13607 | && (INSN_CODE (dep_insn) >= 0) | |
b54cf83a DE |
13608 | && (get_attr_type (dep_insn) == TYPE_CMP |
13609 | || get_attr_type (dep_insn) == TYPE_COMPARE | |
ed947a96 | 13610 | || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE |
9259f3b0 DE |
13611 | || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE |
13612 | || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE | |
ed947a96 | 13613 | || get_attr_type (dep_insn) == TYPE_FPCOMPARE |
b54cf83a DE |
13614 | || get_attr_type (dep_insn) == TYPE_CR_LOGICAL |
13615 | || get_attr_type (dep_insn) == TYPE_DELAYED_CR)) | |
ed947a96 DJ |
13616 | return cost + 2; |
13617 | default: | |
13618 | break; | |
13619 | } | |
a251ffd0 TG |
13620 | /* Fall out to return default cost. */ |
13621 | } | |
13622 | ||
13623 | return cost; | |
13624 | } | |
b6c9286a | 13625 | |
cbe26ab8 DN |
13626 | /* The function returns a true if INSN is microcoded. |
13627 | Return false ptherwise. */ | |
13628 | ||
13629 | static bool | |
13630 | is_microcoded_insn (rtx insn) | |
13631 | { | |
13632 | if (!insn || !INSN_P (insn) | |
13633 | || GET_CODE (PATTERN (insn)) == USE | |
13634 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
13635 | return false; | |
13636 | ||
13637 | if (rs6000_cpu == PROCESSOR_POWER4) | |
13638 | { | |
13639 | enum attr_type type = get_attr_type (insn); | |
13640 | if (type == TYPE_LOAD_EXT_U | |
13641 | || type == TYPE_LOAD_EXT_UX | |
13642 | || type == TYPE_LOAD_UX | |
13643 | || type == TYPE_STORE_UX | |
13644 | || type == TYPE_MFCR) | |
13645 | return true; | |
13646 | } | |
13647 | ||
13648 | return false; | |
13649 | } | |
13650 | ||
79ae11c4 | 13651 | /* The function returns a non-zero value if INSN can be scheduled only |
cbe26ab8 DN |
13652 | as the first insn in a dispatch group ("dispatch-slot restricted"). |
13653 | In this case, the returned value indicates how many dispatch slots | |
13654 | the insn occupies (at the beginning of the group). | |
79ae11c4 DN |
13655 | Return 0 otherwise. */ |
13656 | ||
cbe26ab8 | 13657 | static int |
79ae11c4 DN |
13658 | is_dispatch_slot_restricted (rtx insn) |
13659 | { | |
13660 | enum attr_type type; | |
13661 | ||
13662 | if (rs6000_cpu != PROCESSOR_POWER4) | |
13663 | return 0; | |
13664 | ||
13665 | if (!insn | |
13666 | || insn == NULL_RTX | |
13667 | || GET_CODE (insn) == NOTE | |
13668 | || GET_CODE (PATTERN (insn)) == USE | |
13669 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
13670 | return 0; | |
13671 | ||
13672 | type = get_attr_type (insn); | |
13673 | ||
13674 | switch (type){ | |
13675 | case TYPE_MFCR: | |
13676 | case TYPE_MFCRF: | |
13677 | case TYPE_MTCR: | |
13678 | case TYPE_DELAYED_CR: | |
13679 | case TYPE_CR_LOGICAL: | |
13680 | case TYPE_MTJMPR: | |
13681 | case TYPE_MFJMPR: | |
13682 | return 1; | |
13683 | case TYPE_IDIV: | |
13684 | case TYPE_LDIV: | |
13685 | return 2; | |
13686 | default: | |
13687 | return 0; | |
13688 | } | |
13689 | } | |
13690 | ||
cbe26ab8 DN |
13691 | /* The function returns true if INSN is cracked into 2 instructions |
13692 | by the processor (and therefore occupies 2 issue slots). */ | |
13693 | ||
13694 | static bool | |
13695 | is_cracked_insn (rtx insn) | |
13696 | { | |
13697 | if (!insn || !INSN_P (insn) | |
13698 | || GET_CODE (PATTERN (insn)) == USE | |
13699 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
13700 | return false; | |
13701 | ||
13702 | if (rs6000_cpu == PROCESSOR_POWER4) | |
13703 | { | |
13704 | enum attr_type type = get_attr_type (insn); | |
13705 | if (type == TYPE_LOAD_U || type == TYPE_STORE_U | |
13706 | || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U | |
13707 | || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX | |
13708 | || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR | |
13709 | || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE | |
13710 | || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE | |
13711 | || type == TYPE_IDIV || type == TYPE_LDIV | |
13712 | || type == TYPE_INSERT_WORD) | |
13713 | return true; | |
13714 | } | |
13715 | ||
13716 | return false; | |
13717 | } | |
13718 | ||
13719 | /* The function returns true if INSN can be issued only from | |
13720 | the branch slot. */ | |
13721 | ||
13722 | static bool | |
13723 | is_branch_slot_insn (rtx insn) | |
13724 | { | |
13725 | if (!insn || !INSN_P (insn) | |
13726 | || GET_CODE (PATTERN (insn)) == USE | |
13727 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
13728 | return false; | |
13729 | ||
13730 | if (rs6000_cpu == PROCESSOR_POWER4) | |
13731 | { | |
13732 | enum attr_type type = get_attr_type (insn); | |
13733 | if (type == TYPE_BRANCH || type == TYPE_JMPREG) | |
13734 | return true; | |
13735 | return false; | |
13736 | } | |
13737 | ||
13738 | return false; | |
13739 | } | |
79ae11c4 | 13740 | |
a4f6c312 | 13741 | /* A C statement (sans semicolon) to update the integer scheduling |
79ae11c4 DN |
13742 | priority INSN_PRIORITY (INSN). Increase the priority to execute the |
13743 | INSN earlier, reduce the priority to execute INSN later. Do not | |
a4f6c312 SS |
13744 | define this macro if you do not need to adjust the scheduling |
13745 | priorities of insns. */ | |
bef84347 | 13746 | |
c237e94a | 13747 | static int |
a2369ed3 | 13748 | rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority) |
bef84347 | 13749 | { |
a4f6c312 SS |
13750 | /* On machines (like the 750) which have asymmetric integer units, |
13751 | where one integer unit can do multiply and divides and the other | |
13752 | can't, reduce the priority of multiply/divide so it is scheduled | |
13753 | before other integer operations. */ | |
bef84347 VM |
13754 | |
13755 | #if 0 | |
2c3c49de | 13756 | if (! INSN_P (insn)) |
bef84347 VM |
13757 | return priority; |
13758 | ||
13759 | if (GET_CODE (PATTERN (insn)) == USE) | |
13760 | return priority; | |
13761 | ||
13762 | switch (rs6000_cpu_attr) { | |
13763 | case CPU_PPC750: | |
13764 | switch (get_attr_type (insn)) | |
13765 | { | |
13766 | default: | |
13767 | break; | |
13768 | ||
13769 | case TYPE_IMUL: | |
13770 | case TYPE_IDIV: | |
3cb999d8 DE |
13771 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
13772 | priority, priority); | |
bef84347 VM |
13773 | if (priority >= 0 && priority < 0x01000000) |
13774 | priority >>= 3; | |
13775 | break; | |
13776 | } | |
13777 | } | |
13778 | #endif | |
13779 | ||
79ae11c4 DN |
13780 | if (is_dispatch_slot_restricted (insn) |
13781 | && reload_completed | |
13782 | && current_sched_info->sched_max_insns_priority | |
13783 | && rs6000_sched_restricted_insns_priority) | |
13784 | { | |
13785 | ||
13786 | /* Prioritize insns that can be dispatched only in the first dispatch slot. */ | |
13787 | if (rs6000_sched_restricted_insns_priority == 1) | |
13788 | /* Attach highest priority to insn. This means that in | |
13789 | haifa-sched.c:ready_sort(), dispatch-slot restriction considerations | |
13790 | precede 'priority' (critical path) considerations. */ | |
13791 | return current_sched_info->sched_max_insns_priority; | |
13792 | else if (rs6000_sched_restricted_insns_priority == 2) | |
13793 | /* Increase priority of insn by a minimal amount. This means that in | |
13794 | haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations | |
13795 | precede dispatch-slot restriction considerations. */ | |
13796 | return (priority + 1); | |
13797 | } | |
13798 | ||
bef84347 VM |
13799 | return priority; |
13800 | } | |
13801 | ||
a4f6c312 SS |
13802 | /* Return how many instructions the machine can issue per cycle. */ |
13803 | ||
c237e94a | 13804 | static int |
863d938c | 13805 | rs6000_issue_rate (void) |
b6c9286a | 13806 | { |
3317bab1 DE |
13807 | /* Use issue rate of 1 for first scheduling pass to decrease degradation. */ |
13808 | if (!reload_completed) | |
13809 | return 1; | |
13810 | ||
b6c9286a | 13811 | switch (rs6000_cpu_attr) { |
3cb999d8 DE |
13812 | case CPU_RIOS1: /* ? */ |
13813 | case CPU_RS64A: | |
13814 | case CPU_PPC601: /* ? */ | |
ed947a96 | 13815 | case CPU_PPC7450: |
3cb999d8 | 13816 | return 3; |
b54cf83a | 13817 | case CPU_PPC440: |
b6c9286a | 13818 | case CPU_PPC603: |
bef84347 | 13819 | case CPU_PPC750: |
ed947a96 | 13820 | case CPU_PPC7400: |
be12c2b0 | 13821 | case CPU_PPC8540: |
bef84347 | 13822 | return 2; |
3cb999d8 | 13823 | case CPU_RIOS2: |
b6c9286a | 13824 | case CPU_PPC604: |
19684119 | 13825 | case CPU_PPC604E: |
b6c9286a | 13826 | case CPU_PPC620: |
3cb999d8 | 13827 | case CPU_PPC630: |
b6c9286a | 13828 | return 4; |
cbe26ab8 DN |
13829 | case CPU_POWER4: |
13830 | return 5; | |
b6c9286a MM |
13831 | default: |
13832 | return 1; | |
13833 | } | |
13834 | } | |
13835 | ||
be12c2b0 VM |
13836 | /* Return how many instructions to look ahead for better insn |
13837 | scheduling. */ | |
13838 | ||
13839 | static int | |
863d938c | 13840 | rs6000_use_sched_lookahead (void) |
be12c2b0 VM |
13841 | { |
13842 | if (rs6000_cpu_attr == CPU_PPC8540) | |
13843 | return 4; | |
13844 | return 0; | |
13845 | } | |
13846 | ||
569fa502 DN |
13847 | /* Determine is PAT refers to memory. */ |
13848 | ||
13849 | static bool | |
13850 | is_mem_ref (rtx pat) | |
13851 | { | |
13852 | const char * fmt; | |
13853 | int i, j; | |
13854 | bool ret = false; | |
13855 | ||
13856 | if (GET_CODE (pat) == MEM) | |
13857 | return true; | |
13858 | ||
13859 | /* Recursively process the pattern. */ | |
13860 | fmt = GET_RTX_FORMAT (GET_CODE (pat)); | |
13861 | ||
13862 | for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--) | |
13863 | { | |
13864 | if (fmt[i] == 'e') | |
13865 | ret |= is_mem_ref (XEXP (pat, i)); | |
13866 | else if (fmt[i] == 'E') | |
13867 | for (j = XVECLEN (pat, i) - 1; j >= 0; j--) | |
13868 | ret |= is_mem_ref (XVECEXP (pat, i, j)); | |
13869 | } | |
13870 | ||
13871 | return ret; | |
13872 | } | |
13873 | ||
13874 | /* Determine if PAT is a PATTERN of a load insn. */ | |
13875 | ||
13876 | static bool | |
13877 | is_load_insn1 (rtx pat) | |
13878 | { | |
13879 | if (!pat || pat == NULL_RTX) | |
13880 | return false; | |
13881 | ||
13882 | if (GET_CODE (pat) == SET) | |
13883 | return is_mem_ref (SET_SRC (pat)); | |
13884 | ||
13885 | if (GET_CODE (pat) == PARALLEL) | |
13886 | { | |
13887 | int i; | |
13888 | ||
13889 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
13890 | if (is_load_insn1 (XVECEXP (pat, 0, i))) | |
13891 | return true; | |
13892 | } | |
13893 | ||
13894 | return false; | |
13895 | } | |
13896 | ||
13897 | /* Determine if INSN loads from memory. */ | |
13898 | ||
13899 | static bool | |
13900 | is_load_insn (rtx insn) | |
13901 | { | |
13902 | if (!insn || !INSN_P (insn)) | |
13903 | return false; | |
13904 | ||
13905 | if (GET_CODE (insn) == CALL_INSN) | |
13906 | return false; | |
13907 | ||
13908 | return is_load_insn1 (PATTERN (insn)); | |
13909 | } | |
13910 | ||
13911 | /* Determine if PAT is a PATTERN of a store insn. */ | |
13912 | ||
13913 | static bool | |
13914 | is_store_insn1 (rtx pat) | |
13915 | { | |
13916 | if (!pat || pat == NULL_RTX) | |
13917 | return false; | |
13918 | ||
13919 | if (GET_CODE (pat) == SET) | |
13920 | return is_mem_ref (SET_DEST (pat)); | |
13921 | ||
13922 | if (GET_CODE (pat) == PARALLEL) | |
13923 | { | |
13924 | int i; | |
13925 | ||
13926 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
13927 | if (is_store_insn1 (XVECEXP (pat, 0, i))) | |
13928 | return true; | |
13929 | } | |
13930 | ||
13931 | return false; | |
13932 | } | |
13933 | ||
13934 | /* Determine if INSN stores to memory. */ | |
13935 | ||
13936 | static bool | |
13937 | is_store_insn (rtx insn) | |
13938 | { | |
13939 | if (!insn || !INSN_P (insn)) | |
13940 | return false; | |
13941 | ||
13942 | return is_store_insn1 (PATTERN (insn)); | |
13943 | } | |
13944 | ||
13945 | /* Returns whether the dependence between INSN and NEXT is considered | |
13946 | costly by the given target. */ | |
13947 | ||
13948 | static bool | |
13949 | rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance) | |
13950 | { | |
13951 | /* If the flag is not enbled - no dependence is considered costly; | |
13952 | allow all dependent insns in the same group. | |
13953 | This is the most aggressive option. */ | |
13954 | if (rs6000_sched_costly_dep == no_dep_costly) | |
13955 | return false; | |
13956 | ||
13957 | /* If the flag is set to 1 - a dependence is always considered costly; | |
13958 | do not allow dependent instructions in the same group. | |
13959 | This is the most conservative option. */ | |
13960 | if (rs6000_sched_costly_dep == all_deps_costly) | |
13961 | return true; | |
13962 | ||
13963 | if (rs6000_sched_costly_dep == store_to_load_dep_costly | |
13964 | && is_load_insn (next) | |
13965 | && is_store_insn (insn)) | |
13966 | /* Prevent load after store in the same group. */ | |
13967 | return true; | |
13968 | ||
13969 | if (rs6000_sched_costly_dep == true_store_to_load_dep_costly | |
13970 | && is_load_insn (next) | |
13971 | && is_store_insn (insn) | |
13972 | && (!link || (int) REG_NOTE_KIND (link) == 0)) | |
13973 | /* Prevent load after store in the same group if it is a true dependence. */ | |
13974 | return true; | |
13975 | ||
13976 | /* The flag is set to X; dependences with latency >= X are considered costly, | |
13977 | and will not be scheduled in the same group. */ | |
13978 | if (rs6000_sched_costly_dep <= max_dep_latency | |
13979 | && ((cost - distance) >= (int)rs6000_sched_costly_dep)) | |
13980 | return true; | |
13981 | ||
13982 | return false; | |
13983 | } | |
13984 | ||
cbe26ab8 DN |
13985 | /* Return the next insn after INSN that is found before TAIL is reached, |
13986 | skipping any "non-active" insns - insns that will not actually occupy | |
13987 | an issue slot. Return NULL_RTX if such an insn is not found. */ | |
13988 | ||
13989 | static rtx | |
13990 | get_next_active_insn (rtx insn, rtx tail) | |
13991 | { | |
13992 | rtx next_insn; | |
13993 | ||
13994 | if (!insn || insn == tail) | |
13995 | return NULL_RTX; | |
13996 | ||
13997 | next_insn = NEXT_INSN (insn); | |
13998 | ||
13999 | while (next_insn | |
14000 | && next_insn != tail | |
14001 | && (GET_CODE(next_insn) == NOTE | |
14002 | || GET_CODE (PATTERN (next_insn)) == USE | |
14003 | || GET_CODE (PATTERN (next_insn)) == CLOBBER)) | |
14004 | { | |
14005 | next_insn = NEXT_INSN (next_insn); | |
14006 | } | |
14007 | ||
14008 | if (!next_insn || next_insn == tail) | |
14009 | return NULL_RTX; | |
14010 | ||
14011 | return next_insn; | |
14012 | } | |
14013 | ||
14014 | /* Return whether the presence of INSN causes a dispatch group terminatation | |
14015 | of group WHICH_GROUP. | |
14016 | ||
14017 | If WHICH_GROUP == current_group, this function will return true if INSN | |
14018 | causes the termination of the current group (i.e, the dispatch group to | |
14019 | which INSN belongs). This means that INSN will be the last insn in the | |
14020 | group it belongs to. | |
14021 | ||
14022 | If WHICH_GROUP == previous_group, this function will return true if INSN | |
14023 | causes the termination of the previous group (i.e, the dispatch group that | |
14024 | precedes the group to which INSN belongs). This means that INSN will be | |
14025 | the first insn in the group it belongs to). */ | |
14026 | ||
14027 | static bool | |
14028 | insn_terminates_group_p (rtx insn, enum group_termination which_group) | |
14029 | { | |
14030 | enum attr_type type; | |
14031 | ||
14032 | if (! insn) | |
14033 | return false; | |
569fa502 | 14034 | |
cbe26ab8 DN |
14035 | type = get_attr_type (insn); |
14036 | ||
14037 | if (is_microcoded_insn (insn)) | |
14038 | return true; | |
14039 | ||
14040 | if (which_group == current_group) | |
14041 | { | |
14042 | if (is_branch_slot_insn (insn)) | |
14043 | return true; | |
14044 | return false; | |
14045 | } | |
14046 | else if (which_group == previous_group) | |
14047 | { | |
14048 | if (is_dispatch_slot_restricted (insn)) | |
14049 | return true; | |
14050 | return false; | |
14051 | } | |
14052 | ||
14053 | return false; | |
14054 | } | |
14055 | ||
14056 | /* Return true if it is recommended to keep NEXT_INSN "far" (in a seperate | |
14057 | dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */ | |
14058 | ||
14059 | static bool | |
14060 | is_costly_group (rtx *group_insns, rtx next_insn) | |
14061 | { | |
14062 | int i; | |
14063 | rtx link; | |
14064 | int cost; | |
14065 | int issue_rate = rs6000_issue_rate (); | |
14066 | ||
14067 | for (i = 0; i < issue_rate; i++) | |
14068 | { | |
14069 | rtx insn = group_insns[i]; | |
14070 | if (!insn) | |
14071 | continue; | |
14072 | for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1)) | |
14073 | { | |
14074 | rtx next = XEXP (link, 0); | |
14075 | if (next == next_insn) | |
14076 | { | |
14077 | cost = insn_cost (insn, link, next_insn); | |
14078 | if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0)) | |
14079 | return true; | |
14080 | } | |
14081 | } | |
14082 | } | |
14083 | ||
14084 | return false; | |
14085 | } | |
14086 | ||
14087 | /* Utility of the function redefine_groups. | |
14088 | Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS | |
14089 | in the same dispatch group. If so, insert nops before NEXT_INSN, in order | |
14090 | to keep it "far" (in a separate group) from GROUP_INSNS, following | |
14091 | one of the following schemes, depending on the value of the flag | |
14092 | -minsert_sched_nops = X: | |
14093 | (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed | |
14094 | in order to force NEXT_INSN into a seperate group. | |
14095 | (2) X < sched_finish_regroup_exact: insert exactly X nops. | |
14096 | GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop | |
14097 | insertion (has a group just ended, how many vacant issue slots remain in the | |
14098 | last group, and how many dispatch groups were encountered so far). */ | |
14099 | ||
14100 | static int | |
14101 | force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn, | |
14102 | bool *group_end, int can_issue_more, int *group_count) | |
14103 | { | |
14104 | rtx nop; | |
14105 | bool force; | |
14106 | int issue_rate = rs6000_issue_rate (); | |
14107 | bool end = *group_end; | |
14108 | int i; | |
14109 | ||
14110 | if (next_insn == NULL_RTX) | |
14111 | return can_issue_more; | |
14112 | ||
14113 | if (rs6000_sched_insert_nops > sched_finish_regroup_exact) | |
14114 | return can_issue_more; | |
14115 | ||
14116 | force = is_costly_group (group_insns, next_insn); | |
14117 | if (!force) | |
14118 | return can_issue_more; | |
14119 | ||
14120 | if (sched_verbose > 6) | |
14121 | fprintf (dump,"force: group count = %d, can_issue_more = %d\n", | |
14122 | *group_count ,can_issue_more); | |
14123 | ||
14124 | if (rs6000_sched_insert_nops == sched_finish_regroup_exact) | |
14125 | { | |
14126 | if (*group_end) | |
14127 | can_issue_more = 0; | |
14128 | ||
14129 | /* Since only a branch can be issued in the last issue_slot, it is | |
14130 | sufficient to insert 'can_issue_more - 1' nops if next_insn is not | |
14131 | a branch. If next_insn is a branch, we insert 'can_issue_more' nops; | |
14132 | in this case the last nop will start a new group and the branch will be | |
14133 | forced to the new group. */ | |
14134 | if (can_issue_more && !is_branch_slot_insn (next_insn)) | |
14135 | can_issue_more--; | |
14136 | ||
14137 | while (can_issue_more > 0) | |
14138 | { | |
14139 | nop = gen_nop(); | |
14140 | emit_insn_before (nop, next_insn); | |
14141 | can_issue_more--; | |
14142 | } | |
14143 | ||
14144 | *group_end = true; | |
14145 | return 0; | |
14146 | } | |
14147 | ||
14148 | if (rs6000_sched_insert_nops < sched_finish_regroup_exact) | |
14149 | { | |
14150 | int n_nops = rs6000_sched_insert_nops; | |
14151 | ||
14152 | /* Nops can't be issued from the branch slot, so the effective | |
14153 | issue_rate for nops is 'issue_rate - 1'. */ | |
14154 | if (can_issue_more == 0) | |
14155 | can_issue_more = issue_rate; | |
14156 | can_issue_more--; | |
14157 | if (can_issue_more == 0) | |
14158 | { | |
14159 | can_issue_more = issue_rate - 1; | |
14160 | (*group_count)++; | |
14161 | end = true; | |
14162 | for (i = 0; i < issue_rate; i++) | |
14163 | { | |
14164 | group_insns[i] = 0; | |
14165 | } | |
14166 | } | |
14167 | ||
14168 | while (n_nops > 0) | |
14169 | { | |
14170 | nop = gen_nop (); | |
14171 | emit_insn_before (nop, next_insn); | |
14172 | if (can_issue_more == issue_rate - 1) /* new group begins */ | |
14173 | end = false; | |
14174 | can_issue_more--; | |
14175 | if (can_issue_more == 0) | |
14176 | { | |
14177 | can_issue_more = issue_rate - 1; | |
14178 | (*group_count)++; | |
14179 | end = true; | |
14180 | for (i = 0; i < issue_rate; i++) | |
14181 | { | |
14182 | group_insns[i] = 0; | |
14183 | } | |
14184 | } | |
14185 | n_nops--; | |
14186 | } | |
14187 | ||
14188 | /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */ | |
14189 | can_issue_more++; | |
14190 | ||
14191 | *group_end = /* Is next_insn going to start a new group? */ | |
14192 | (end | |
14193 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
14194 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
14195 | || (can_issue_more < issue_rate && | |
14196 | insn_terminates_group_p (next_insn, previous_group))); | |
14197 | if (*group_end && end) | |
14198 | (*group_count)--; | |
14199 | ||
14200 | if (sched_verbose > 6) | |
14201 | fprintf (dump, "done force: group count = %d, can_issue_more = %d\n", | |
14202 | *group_count, can_issue_more); | |
14203 | return can_issue_more; | |
14204 | } | |
14205 | ||
14206 | return can_issue_more; | |
14207 | } | |
14208 | ||
14209 | /* This function tries to synch the dispatch groups that the compiler "sees" | |
14210 | with the dispatch groups that the processor dispatcher is expected to | |
14211 | form in practice. It tries to achieve this synchronization by forcing the | |
14212 | estimated processor grouping on the compiler (as opposed to the function | |
14213 | 'pad_goups' which tries to force the scheduler's grouping on the processor). | |
14214 | ||
14215 | The function scans the insn sequence between PREV_HEAD_INSN and TAIL and | |
14216 | examines the (estimated) dispatch groups that will be formed by the processor | |
14217 | dispatcher. It marks these group boundaries to reflect the estimated | |
14218 | processor grouping, overriding the grouping that the scheduler had marked. | |
14219 | Depending on the value of the flag '-minsert-sched-nops' this function can | |
14220 | force certain insns into separate groups or force a certain distance between | |
14221 | them by inserting nops, for example, if there exists a "costly dependence" | |
14222 | between the insns. | |
14223 | ||
14224 | The function estimates the group boundaries that the processor will form as | |
14225 | folllows: It keeps track of how many vacant issue slots are available after | |
14226 | each insn. A subsequent insn will start a new group if one of the following | |
14227 | 4 cases applies: | |
14228 | - no more vacant issue slots remain in the current dispatch group. | |
14229 | - only the last issue slot, which is the branch slot, is vacant, but the next | |
14230 | insn is not a branch. | |
14231 | - only the last 2 or less issue slots, including the branch slot, are vacant, | |
14232 | which means that a cracked insn (which occupies two issue slots) can't be | |
14233 | issued in this group. | |
14234 | - less than 'issue_rate' slots are vacant, and the next insn always needs to | |
14235 | start a new group. */ | |
14236 | ||
14237 | static int | |
14238 | redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
14239 | { | |
14240 | rtx insn, next_insn; | |
14241 | int issue_rate; | |
14242 | int can_issue_more; | |
14243 | int slot, i; | |
14244 | bool group_end; | |
14245 | int group_count = 0; | |
14246 | rtx *group_insns; | |
14247 | ||
14248 | /* Initialize. */ | |
14249 | issue_rate = rs6000_issue_rate (); | |
14250 | group_insns = alloca (issue_rate * sizeof (rtx)); | |
14251 | for (i = 0; i < issue_rate; i++) | |
14252 | { | |
14253 | group_insns[i] = 0; | |
14254 | } | |
14255 | can_issue_more = issue_rate; | |
14256 | slot = 0; | |
14257 | insn = get_next_active_insn (prev_head_insn, tail); | |
14258 | group_end = false; | |
14259 | ||
14260 | while (insn != NULL_RTX) | |
14261 | { | |
14262 | slot = (issue_rate - can_issue_more); | |
14263 | group_insns[slot] = insn; | |
14264 | can_issue_more = | |
14265 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
14266 | if (insn_terminates_group_p (insn, current_group)) | |
14267 | can_issue_more = 0; | |
14268 | ||
14269 | next_insn = get_next_active_insn (insn, tail); | |
14270 | if (next_insn == NULL_RTX) | |
14271 | return group_count + 1; | |
14272 | ||
14273 | group_end = /* Is next_insn going to start a new group? */ | |
14274 | (can_issue_more == 0 | |
14275 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
14276 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
14277 | || (can_issue_more < issue_rate && | |
14278 | insn_terminates_group_p (next_insn, previous_group))); | |
14279 | ||
14280 | can_issue_more = force_new_group (sched_verbose, dump, group_insns, | |
14281 | next_insn, &group_end, can_issue_more, &group_count); | |
14282 | ||
14283 | if (group_end) | |
14284 | { | |
14285 | group_count++; | |
14286 | can_issue_more = 0; | |
14287 | for (i = 0; i < issue_rate; i++) | |
14288 | { | |
14289 | group_insns[i] = 0; | |
14290 | } | |
14291 | } | |
14292 | ||
14293 | if (GET_MODE (next_insn) == TImode && can_issue_more) | |
14294 | PUT_MODE(next_insn, VOIDmode); | |
14295 | else if (!can_issue_more && GET_MODE (next_insn) != TImode) | |
14296 | PUT_MODE (next_insn, TImode); | |
14297 | ||
14298 | insn = next_insn; | |
14299 | if (can_issue_more == 0) | |
14300 | can_issue_more = issue_rate; | |
14301 | } /* while */ | |
14302 | ||
14303 | return group_count; | |
14304 | } | |
14305 | ||
14306 | /* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the | |
14307 | dispatch group boundaries that the scheduler had marked. Pad with nops | |
14308 | any dispatch groups which have vacant issue slots, in order to force the | |
14309 | scheduler's grouping on the processor dispatcher. The function | |
14310 | returns the number of dispatch groups found. */ | |
14311 | ||
14312 | static int | |
14313 | pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
14314 | { | |
14315 | rtx insn, next_insn; | |
14316 | rtx nop; | |
14317 | int issue_rate; | |
14318 | int can_issue_more; | |
14319 | int group_end; | |
14320 | int group_count = 0; | |
14321 | ||
14322 | /* Initialize issue_rate. */ | |
14323 | issue_rate = rs6000_issue_rate (); | |
14324 | can_issue_more = issue_rate; | |
14325 | ||
14326 | insn = get_next_active_insn (prev_head_insn, tail); | |
14327 | next_insn = get_next_active_insn (insn, tail); | |
14328 | ||
14329 | while (insn != NULL_RTX) | |
14330 | { | |
14331 | can_issue_more = | |
14332 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
14333 | ||
14334 | group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode); | |
14335 | ||
14336 | if (next_insn == NULL_RTX) | |
14337 | break; | |
14338 | ||
14339 | if (group_end) | |
14340 | { | |
14341 | /* If the scheduler had marked group termination at this location | |
14342 | (between insn and next_indn), and neither insn nor next_insn will | |
14343 | force group termination, pad the group with nops to force group | |
14344 | termination. */ | |
14345 | if (can_issue_more | |
14346 | && (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
14347 | && !insn_terminates_group_p (insn, current_group) | |
14348 | && !insn_terminates_group_p (next_insn, previous_group)) | |
14349 | { | |
14350 | if (!is_branch_slot_insn(next_insn)) | |
14351 | can_issue_more--; | |
14352 | ||
14353 | while (can_issue_more) | |
14354 | { | |
14355 | nop = gen_nop (); | |
14356 | emit_insn_before (nop, next_insn); | |
14357 | can_issue_more--; | |
14358 | } | |
14359 | } | |
14360 | ||
14361 | can_issue_more = issue_rate; | |
14362 | group_count++; | |
14363 | } | |
14364 | ||
14365 | insn = next_insn; | |
14366 | next_insn = get_next_active_insn (insn, tail); | |
14367 | } | |
14368 | ||
14369 | return group_count; | |
14370 | } | |
14371 | ||
14372 | /* The following function is called at the end of scheduling BB. | |
14373 | After reload, it inserts nops at insn group bundling. */ | |
14374 | ||
14375 | static void | |
38f391a5 | 14376 | rs6000_sched_finish (FILE *dump, int sched_verbose) |
cbe26ab8 DN |
14377 | { |
14378 | int n_groups; | |
14379 | ||
14380 | if (sched_verbose) | |
14381 | fprintf (dump, "=== Finishing schedule.\n"); | |
14382 | ||
14383 | if (reload_completed && rs6000_cpu == PROCESSOR_POWER4) | |
14384 | { | |
14385 | if (rs6000_sched_insert_nops == sched_finish_none) | |
14386 | return; | |
14387 | ||
14388 | if (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
14389 | n_groups = pad_groups (dump, sched_verbose, | |
14390 | current_sched_info->prev_head, | |
14391 | current_sched_info->next_tail); | |
14392 | else | |
14393 | n_groups = redefine_groups (dump, sched_verbose, | |
14394 | current_sched_info->prev_head, | |
14395 | current_sched_info->next_tail); | |
14396 | ||
14397 | if (sched_verbose >= 6) | |
14398 | { | |
14399 | fprintf (dump, "ngroups = %d\n", n_groups); | |
14400 | print_rtl (dump, current_sched_info->prev_head); | |
14401 | fprintf (dump, "Done finish_sched\n"); | |
14402 | } | |
14403 | } | |
14404 | } | |
b6c9286a | 14405 | \f |
b6c9286a MM |
14406 | /* Length in units of the trampoline for entering a nested function. */ |
14407 | ||
14408 | int | |
863d938c | 14409 | rs6000_trampoline_size (void) |
b6c9286a MM |
14410 | { |
14411 | int ret = 0; | |
14412 | ||
14413 | switch (DEFAULT_ABI) | |
14414 | { | |
14415 | default: | |
14416 | abort (); | |
14417 | ||
14418 | case ABI_AIX: | |
8f802bfb | 14419 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
14420 | break; |
14421 | ||
4dabc42d | 14422 | case ABI_DARWIN: |
b6c9286a | 14423 | case ABI_V4: |
03a7e1a5 | 14424 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 14425 | break; |
b6c9286a MM |
14426 | } |
14427 | ||
14428 | return ret; | |
14429 | } | |
14430 | ||
14431 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
14432 | FNADDR is an RTX for the address of the function's pure code. | |
14433 | CXT is an RTX for the static chain value for the function. */ | |
14434 | ||
14435 | void | |
a2369ed3 | 14436 | rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt) |
b6c9286a | 14437 | { |
ac2a93a1 | 14438 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
14439 | int regsize = (TARGET_32BIT) ? 4 : 8; |
14440 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
14441 | |
14442 | switch (DEFAULT_ABI) | |
14443 | { | |
14444 | default: | |
14445 | abort (); | |
14446 | ||
8bd04c56 | 14447 | /* Macros to shorten the code expansions below. */ |
39403d82 | 14448 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
14449 | #define MEM_PLUS(addr,offset) \ |
14450 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 14451 | |
b6c9286a MM |
14452 | /* Under AIX, just build the 3 word function descriptor */ |
14453 | case ABI_AIX: | |
8bd04c56 MM |
14454 | { |
14455 | rtx fn_reg = gen_reg_rtx (pmode); | |
14456 | rtx toc_reg = gen_reg_rtx (pmode); | |
14457 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
1cb18e3c | 14458 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); |
8bd04c56 MM |
14459 | emit_move_insn (MEM_DEREF (addr), fn_reg); |
14460 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
14461 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
14462 | } | |
b6c9286a MM |
14463 | break; |
14464 | ||
4dabc42d TC |
14465 | /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */ |
14466 | case ABI_DARWIN: | |
b6c9286a | 14467 | case ABI_V4: |
39403d82 | 14468 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
14469 | FALSE, VOIDmode, 4, |
14470 | addr, pmode, | |
14471 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
14472 | fnaddr, pmode, | |
14473 | ctx_reg, pmode); | |
b6c9286a | 14474 | break; |
b6c9286a MM |
14475 | } |
14476 | ||
14477 | return; | |
14478 | } | |
7509c759 MM |
14479 | |
14480 | \f | |
91d231cb | 14481 | /* Table of valid machine attributes. */ |
a4f6c312 | 14482 | |
91d231cb | 14483 | const struct attribute_spec rs6000_attribute_table[] = |
7509c759 | 14484 | { |
91d231cb | 14485 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
a5c76ee6 ZW |
14486 | { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, |
14487 | { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, | |
14488 | { NULL, 0, 0, false, false, false, NULL } | |
91d231cb | 14489 | }; |
7509c759 | 14490 | |
a5c76ee6 ZW |
14491 | /* Handle a "longcall" or "shortcall" attribute; arguments as in |
14492 | struct attribute_spec.handler. */ | |
a4f6c312 | 14493 | |
91d231cb | 14494 | static tree |
a2369ed3 DJ |
14495 | rs6000_handle_longcall_attribute (tree *node, tree name, |
14496 | tree args ATTRIBUTE_UNUSED, | |
14497 | int flags ATTRIBUTE_UNUSED, | |
14498 | bool *no_add_attrs) | |
91d231cb JM |
14499 | { |
14500 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
14501 | && TREE_CODE (*node) != FIELD_DECL | |
14502 | && TREE_CODE (*node) != TYPE_DECL) | |
14503 | { | |
14504 | warning ("`%s' attribute only applies to functions", | |
14505 | IDENTIFIER_POINTER (name)); | |
14506 | *no_add_attrs = true; | |
14507 | } | |
6a4cee5f | 14508 | |
91d231cb | 14509 | return NULL_TREE; |
7509c759 MM |
14510 | } |
14511 | ||
a5c76ee6 ZW |
14512 | /* Set longcall attributes on all functions declared when |
14513 | rs6000_default_long_calls is true. */ | |
14514 | static void | |
a2369ed3 | 14515 | rs6000_set_default_type_attributes (tree type) |
a5c76ee6 ZW |
14516 | { |
14517 | if (rs6000_default_long_calls | |
14518 | && (TREE_CODE (type) == FUNCTION_TYPE | |
14519 | || TREE_CODE (type) == METHOD_TYPE)) | |
14520 | TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"), | |
14521 | NULL_TREE, | |
14522 | TYPE_ATTRIBUTES (type)); | |
14523 | } | |
14524 | ||
3cb999d8 DE |
14525 | /* Return a reference suitable for calling a function with the |
14526 | longcall attribute. */ | |
a4f6c312 | 14527 | |
6a4cee5f | 14528 | struct rtx_def * |
a2369ed3 | 14529 | rs6000_longcall_ref (rtx call_ref) |
6a4cee5f | 14530 | { |
d330fd93 | 14531 | const char *call_name; |
6a4cee5f MM |
14532 | tree node; |
14533 | ||
14534 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
14535 | return call_ref; | |
14536 | ||
14537 | /* System V adds '.' to the internal name, so skip them. */ | |
14538 | call_name = XSTR (call_ref, 0); | |
14539 | if (*call_name == '.') | |
14540 | { | |
14541 | while (*call_name == '.') | |
14542 | call_name++; | |
14543 | ||
14544 | node = get_identifier (call_name); | |
39403d82 | 14545 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
14546 | } |
14547 | ||
14548 | return force_reg (Pmode, call_ref); | |
14549 | } | |
7509c759 | 14550 | \f |
b64a1b53 RH |
14551 | #ifdef USING_ELFOS_H |
14552 | ||
7509c759 MM |
14553 | /* A C statement or statements to switch to the appropriate section |
14554 | for output of RTX in mode MODE. You can assume that RTX is some | |
14555 | kind of constant in RTL. The argument MODE is redundant except in | |
14556 | the case of a `const_int' rtx. Select the section by calling | |
14557 | `text_section' or one of the alternatives for other sections. | |
14558 | ||
14559 | Do not define this macro if you put all constants in the read-only | |
14560 | data section. */ | |
14561 | ||
b64a1b53 | 14562 | static void |
a2369ed3 DJ |
14563 | rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x, |
14564 | unsigned HOST_WIDE_INT align) | |
7509c759 | 14565 | { |
a9098fd0 | 14566 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 14567 | toc_section (); |
7509c759 | 14568 | else |
b64a1b53 | 14569 | default_elf_select_rtx_section (mode, x, align); |
7509c759 MM |
14570 | } |
14571 | ||
14572 | /* A C statement or statements to switch to the appropriate | |
14573 | section for output of DECL. DECL is either a `VAR_DECL' node | |
14574 | or a constant of some sort. RELOC indicates whether forming | |
14575 | the initial value of DECL requires link-time relocations. */ | |
14576 | ||
ae46c4e0 | 14577 | static void |
a2369ed3 DJ |
14578 | rs6000_elf_select_section (tree decl, int reloc, |
14579 | unsigned HOST_WIDE_INT align) | |
7509c759 | 14580 | { |
f1384257 AM |
14581 | /* Pretend that we're always building for a shared library when |
14582 | ABI_AIX, because otherwise we end up with dynamic relocations | |
14583 | in read-only sections. This happens for function pointers, | |
14584 | references to vtables in typeinfo, and probably other cases. */ | |
0e5dbd9b DE |
14585 | default_elf_select_section_1 (decl, reloc, align, |
14586 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
63019373 GK |
14587 | } |
14588 | ||
14589 | /* A C statement to build up a unique section name, expressed as a | |
14590 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
14591 | RELOC indicates whether the initial value of EXP requires | |
14592 | link-time relocations. If you do not define this macro, GCC will use | |
14593 | the symbol name prefixed by `.' as the section name. Note - this | |
f5143c46 | 14594 | macro can now be called for uninitialized data items as well as |
4912a07c | 14595 | initialized data and functions. */ |
63019373 | 14596 | |
ae46c4e0 | 14597 | static void |
a2369ed3 | 14598 | rs6000_elf_unique_section (tree decl, int reloc) |
63019373 | 14599 | { |
f1384257 AM |
14600 | /* As above, pretend that we're always building for a shared library |
14601 | when ABI_AIX, to avoid dynamic relocations in read-only sections. */ | |
0e5dbd9b DE |
14602 | default_unique_section_1 (decl, reloc, |
14603 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7509c759 | 14604 | } |
d9407988 | 14605 | \f |
d1908feb JJ |
14606 | /* For a SYMBOL_REF, set generic flags and then perform some |
14607 | target-specific processing. | |
14608 | ||
d1908feb JJ |
14609 | When the AIX ABI is requested on a non-AIX system, replace the |
14610 | function name with the real name (with a leading .) rather than the | |
14611 | function descriptor name. This saves a lot of overriding code to | |
14612 | read the prefixes. */ | |
d9407988 | 14613 | |
fb49053f | 14614 | static void |
a2369ed3 | 14615 | rs6000_elf_encode_section_info (tree decl, rtx rtl, int first) |
d9407988 | 14616 | { |
d1908feb | 14617 | default_encode_section_info (decl, rtl, first); |
b2003250 | 14618 | |
d1908feb JJ |
14619 | if (first |
14620 | && TREE_CODE (decl) == FUNCTION_DECL | |
14621 | && !TARGET_AIX | |
14622 | && DEFAULT_ABI == ABI_AIX) | |
d9407988 | 14623 | { |
c6a2438a | 14624 | rtx sym_ref = XEXP (rtl, 0); |
d1908feb JJ |
14625 | size_t len = strlen (XSTR (sym_ref, 0)); |
14626 | char *str = alloca (len + 2); | |
14627 | str[0] = '.'; | |
14628 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
14629 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1); | |
d9407988 | 14630 | } |
d9407988 MM |
14631 | } |
14632 | ||
0e5dbd9b | 14633 | static bool |
a2369ed3 | 14634 | rs6000_elf_in_small_data_p (tree decl) |
0e5dbd9b DE |
14635 | { |
14636 | if (rs6000_sdata == SDATA_NONE) | |
14637 | return false; | |
14638 | ||
14639 | if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl)) | |
14640 | { | |
14641 | const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
14642 | if (strcmp (section, ".sdata") == 0 | |
14643 | || strcmp (section, ".sdata2") == 0 | |
20bfcd69 GK |
14644 | || strcmp (section, ".sbss") == 0 |
14645 | || strcmp (section, ".sbss2") == 0 | |
14646 | || strcmp (section, ".PPC.EMB.sdata0") == 0 | |
14647 | || strcmp (section, ".PPC.EMB.sbss0") == 0) | |
0e5dbd9b DE |
14648 | return true; |
14649 | } | |
14650 | else | |
14651 | { | |
14652 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); | |
14653 | ||
14654 | if (size > 0 | |
307b599c | 14655 | && (unsigned HOST_WIDE_INT) size <= g_switch_value |
20bfcd69 GK |
14656 | /* If it's not public, and we're not going to reference it there, |
14657 | there's no need to put it in the small data section. */ | |
0e5dbd9b DE |
14658 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))) |
14659 | return true; | |
14660 | } | |
14661 | ||
14662 | return false; | |
14663 | } | |
14664 | ||
b91da81f | 14665 | #endif /* USING_ELFOS_H */ |
000034eb | 14666 | |
a6c2a102 | 14667 | \f |
000034eb | 14668 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
14669 | ADDR can be effectively incremented by incrementing REG. |
14670 | ||
14671 | r0 is special and we must not select it as an address | |
14672 | register by this routine since our caller will try to | |
14673 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
14674 | |
14675 | struct rtx_def * | |
a2369ed3 | 14676 | find_addr_reg (rtx addr) |
000034eb DE |
14677 | { |
14678 | while (GET_CODE (addr) == PLUS) | |
14679 | { | |
02441cd6 JL |
14680 | if (GET_CODE (XEXP (addr, 0)) == REG |
14681 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 14682 | addr = XEXP (addr, 0); |
02441cd6 JL |
14683 | else if (GET_CODE (XEXP (addr, 1)) == REG |
14684 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
14685 | addr = XEXP (addr, 1); |
14686 | else if (CONSTANT_P (XEXP (addr, 0))) | |
14687 | addr = XEXP (addr, 1); | |
14688 | else if (CONSTANT_P (XEXP (addr, 1))) | |
14689 | addr = XEXP (addr, 0); | |
14690 | else | |
14691 | abort (); | |
14692 | } | |
02441cd6 | 14693 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
14694 | return addr; |
14695 | abort (); | |
14696 | } | |
14697 | ||
a6c2a102 | 14698 | void |
a2369ed3 | 14699 | rs6000_fatal_bad_address (rtx op) |
a6c2a102 DE |
14700 | { |
14701 | fatal_insn ("bad address", op); | |
14702 | } | |
c8023011 | 14703 | |
ee890fe2 SS |
14704 | #if TARGET_MACHO |
14705 | ||
14706 | #if 0 | |
14707 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
14708 | reference and a constant. */ | |
14709 | ||
14710 | int | |
a2369ed3 | 14711 | symbolic_operand (rtx op) |
ee890fe2 SS |
14712 | { |
14713 | switch (GET_CODE (op)) | |
14714 | { | |
14715 | case SYMBOL_REF: | |
14716 | case LABEL_REF: | |
14717 | return 1; | |
14718 | case CONST: | |
14719 | op = XEXP (op, 0); | |
14720 | return (GET_CODE (op) == SYMBOL_REF || | |
14721 | (GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
14722 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
14723 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
14724 | default: | |
14725 | return 0; | |
14726 | } | |
c8023011 | 14727 | } |
ee890fe2 SS |
14728 | #endif |
14729 | ||
efdba735 | 14730 | #if TARGET_MACHO |
ee890fe2 | 14731 | |
efdba735 | 14732 | static tree branch_island_list = 0; |
ee890fe2 | 14733 | |
efdba735 SH |
14734 | /* Remember to generate a branch island for far calls to the given |
14735 | function. */ | |
ee890fe2 | 14736 | |
efdba735 SH |
14737 | static void |
14738 | add_compiler_branch_island (tree label_name, tree function_name, int line_number) | |
ee890fe2 | 14739 | { |
efdba735 SH |
14740 | tree branch_island = build_tree_list (function_name, label_name); |
14741 | TREE_TYPE (branch_island) = build_int_2 (line_number, 0); | |
14742 | TREE_CHAIN (branch_island) = branch_island_list; | |
14743 | branch_island_list = branch_island; | |
ee890fe2 SS |
14744 | } |
14745 | ||
efdba735 SH |
14746 | #define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND) |
14747 | #define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND) | |
14748 | #define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \ | |
14749 | TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND)) | |
ee890fe2 | 14750 | |
efdba735 SH |
14751 | /* Generate far-jump branch islands for everything on the |
14752 | branch_island_list. Invoked immediately after the last instruction | |
14753 | of the epilogue has been emitted; the branch-islands must be | |
14754 | appended to, and contiguous with, the function body. Mach-O stubs | |
14755 | are generated in machopic_output_stub(). */ | |
ee890fe2 | 14756 | |
efdba735 SH |
14757 | static void |
14758 | macho_branch_islands (void) | |
14759 | { | |
14760 | char tmp_buf[512]; | |
14761 | tree branch_island; | |
14762 | ||
14763 | for (branch_island = branch_island_list; | |
14764 | branch_island; | |
14765 | branch_island = TREE_CHAIN (branch_island)) | |
14766 | { | |
14767 | const char *label = | |
14768 | IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island)); | |
14769 | const char *name = | |
14770 | darwin_strip_name_encoding ( | |
14771 | IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island))); | |
14772 | char name_buf[512]; | |
14773 | /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */ | |
14774 | if (name[0] == '*' || name[0] == '&') | |
14775 | strcpy (name_buf, name+1); | |
14776 | else | |
14777 | { | |
14778 | name_buf[0] = '_'; | |
14779 | strcpy (name_buf+1, name); | |
14780 | } | |
14781 | strcpy (tmp_buf, "\n"); | |
14782 | strcat (tmp_buf, label); | |
ee890fe2 | 14783 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 14784 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 14785 | fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 14786 | BRANCH_ISLAND_LINE_NUMBER(branch_island)); |
ee890fe2 | 14787 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 SH |
14788 | if (flag_pic) |
14789 | { | |
14790 | strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,"); | |
14791 | strcat (tmp_buf, label); | |
14792 | strcat (tmp_buf, "_pic\n"); | |
14793 | strcat (tmp_buf, label); | |
14794 | strcat (tmp_buf, "_pic:\n\tmflr r11\n"); | |
14795 | ||
14796 | strcat (tmp_buf, "\taddis r11,r11,ha16("); | |
14797 | strcat (tmp_buf, name_buf); | |
14798 | strcat (tmp_buf, " - "); | |
14799 | strcat (tmp_buf, label); | |
14800 | strcat (tmp_buf, "_pic)\n"); | |
14801 | ||
14802 | strcat (tmp_buf, "\tmtlr r0\n"); | |
14803 | ||
14804 | strcat (tmp_buf, "\taddi r12,r11,lo16("); | |
14805 | strcat (tmp_buf, name_buf); | |
14806 | strcat (tmp_buf, " - "); | |
14807 | strcat (tmp_buf, label); | |
14808 | strcat (tmp_buf, "_pic)\n"); | |
14809 | ||
14810 | strcat (tmp_buf, "\tmtctr r12\n\tbctr\n"); | |
14811 | } | |
14812 | else | |
14813 | { | |
14814 | strcat (tmp_buf, ":\nlis r12,hi16("); | |
14815 | strcat (tmp_buf, name_buf); | |
14816 | strcat (tmp_buf, ")\n\tori r12,r12,lo16("); | |
14817 | strcat (tmp_buf, name_buf); | |
14818 | strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr"); | |
14819 | } | |
14820 | output_asm_insn (tmp_buf, 0); | |
ee890fe2 | 14821 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 14822 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 14823 | fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 14824 | BRANCH_ISLAND_LINE_NUMBER (branch_island)); |
ee890fe2 | 14825 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 | 14826 | } |
ee890fe2 | 14827 | |
efdba735 | 14828 | branch_island_list = 0; |
ee890fe2 SS |
14829 | } |
14830 | ||
14831 | /* NO_PREVIOUS_DEF checks in the link list whether the function name is | |
14832 | already there or not. */ | |
14833 | ||
efdba735 | 14834 | static int |
a2369ed3 | 14835 | no_previous_def (tree function_name) |
ee890fe2 | 14836 | { |
efdba735 SH |
14837 | tree branch_island; |
14838 | for (branch_island = branch_island_list; | |
14839 | branch_island; | |
14840 | branch_island = TREE_CHAIN (branch_island)) | |
14841 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
ee890fe2 SS |
14842 | return 0; |
14843 | return 1; | |
14844 | } | |
14845 | ||
14846 | /* GET_PREV_LABEL gets the label name from the previous definition of | |
14847 | the function. */ | |
14848 | ||
efdba735 | 14849 | static tree |
a2369ed3 | 14850 | get_prev_label (tree function_name) |
ee890fe2 | 14851 | { |
efdba735 SH |
14852 | tree branch_island; |
14853 | for (branch_island = branch_island_list; | |
14854 | branch_island; | |
14855 | branch_island = TREE_CHAIN (branch_island)) | |
14856 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
14857 | return BRANCH_ISLAND_LABEL_NAME (branch_island); | |
ee890fe2 SS |
14858 | return 0; |
14859 | } | |
14860 | ||
14861 | /* INSN is either a function call or a millicode call. It may have an | |
14862 | unconditional jump in its delay slot. | |
14863 | ||
14864 | CALL_DEST is the routine we are calling. */ | |
14865 | ||
14866 | char * | |
efdba735 | 14867 | output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number) |
ee890fe2 SS |
14868 | { |
14869 | static char buf[256]; | |
efdba735 SH |
14870 | if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF |
14871 | && (INTVAL (operands[cookie_operand_number]) & CALL_LONG)) | |
ee890fe2 SS |
14872 | { |
14873 | tree labelname; | |
efdba735 | 14874 | tree funname = get_identifier (XSTR (operands[dest_operand_number], 0)); |
ee890fe2 SS |
14875 | |
14876 | if (no_previous_def (funname)) | |
14877 | { | |
308c142a | 14878 | int line_number = 0; |
ee890fe2 SS |
14879 | rtx label_rtx = gen_label_rtx (); |
14880 | char *label_buf, temp_buf[256]; | |
14881 | ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L", | |
14882 | CODE_LABEL_NUMBER (label_rtx)); | |
14883 | label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf; | |
14884 | labelname = get_identifier (label_buf); | |
14885 | for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn)); | |
14886 | if (insn) | |
14887 | line_number = NOTE_LINE_NUMBER (insn); | |
efdba735 | 14888 | add_compiler_branch_island (labelname, funname, line_number); |
ee890fe2 SS |
14889 | } |
14890 | else | |
14891 | labelname = get_prev_label (funname); | |
14892 | ||
efdba735 SH |
14893 | /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl' |
14894 | instruction will reach 'foo', otherwise link as 'bl L42'". | |
14895 | "L42" should be a 'branch island', that will do a far jump to | |
14896 | 'foo'. Branch islands are generated in | |
14897 | macho_branch_islands(). */ | |
ee890fe2 | 14898 | sprintf (buf, "jbsr %%z%d,%.246s", |
efdba735 | 14899 | dest_operand_number, IDENTIFIER_POINTER (labelname)); |
ee890fe2 SS |
14900 | } |
14901 | else | |
efdba735 SH |
14902 | sprintf (buf, "bl %%z%d", dest_operand_number); |
14903 | return buf; | |
ee890fe2 SS |
14904 | } |
14905 | ||
efdba735 | 14906 | #endif /* TARGET_MACHO */ |
ee890fe2 | 14907 | |
ee890fe2 SS |
14908 | /* Generate PIC and indirect symbol stubs. */ |
14909 | ||
14910 | void | |
a2369ed3 | 14911 | machopic_output_stub (FILE *file, const char *symb, const char *stub) |
ee890fe2 SS |
14912 | { |
14913 | unsigned int length; | |
a4f6c312 SS |
14914 | char *symbol_name, *lazy_ptr_name; |
14915 | char *local_label_0; | |
ee890fe2 SS |
14916 | static int label = 0; |
14917 | ||
df56a27f | 14918 | /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
772c5265 | 14919 | symb = (*targetm.strip_name_encoding) (symb); |
df56a27f | 14920 | |
ee890fe2 | 14921 | |
ee890fe2 SS |
14922 | length = strlen (symb); |
14923 | symbol_name = alloca (length + 32); | |
14924 | GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); | |
14925 | ||
14926 | lazy_ptr_name = alloca (length + 32); | |
14927 | GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length); | |
14928 | ||
ee890fe2 | 14929 | if (flag_pic == 2) |
d3c300d2 | 14930 | machopic_picsymbol_stub1_section (); |
ee890fe2 | 14931 | else |
d3c300d2 DJ |
14932 | machopic_symbol_stub1_section (); |
14933 | fprintf (file, "\t.align 2\n"); | |
ee890fe2 SS |
14934 | |
14935 | fprintf (file, "%s:\n", stub); | |
14936 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
14937 | ||
14938 | if (flag_pic == 2) | |
14939 | { | |
876455fa AP |
14940 | label++; |
14941 | local_label_0 = alloca (sizeof("\"L0000000000$spb\"")); | |
14942 | sprintf (local_label_0, "\"L%011d$spb\"", label); | |
14943 | ||
ee890fe2 SS |
14944 | fprintf (file, "\tmflr r0\n"); |
14945 | fprintf (file, "\tbcl 20,31,%s\n", local_label_0); | |
14946 | fprintf (file, "%s:\n\tmflr r11\n", local_label_0); | |
14947 | fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n", | |
14948 | lazy_ptr_name, local_label_0); | |
14949 | fprintf (file, "\tmtlr r0\n"); | |
d3c300d2 | 14950 | fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n", |
ee890fe2 SS |
14951 | lazy_ptr_name, local_label_0); |
14952 | fprintf (file, "\tmtctr r12\n"); | |
ee890fe2 SS |
14953 | fprintf (file, "\tbctr\n"); |
14954 | } | |
14955 | else | |
ab82a49f AP |
14956 | { |
14957 | fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name); | |
14958 | fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name); | |
14959 | fprintf (file, "\tmtctr r12\n"); | |
14960 | fprintf (file, "\tbctr\n"); | |
14961 | } | |
ee890fe2 SS |
14962 | |
14963 | machopic_lazy_symbol_ptr_section (); | |
14964 | fprintf (file, "%s:\n", lazy_ptr_name); | |
14965 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
14966 | fprintf (file, "\t.long dyld_stub_binding_helper\n"); | |
14967 | } | |
14968 | ||
14969 | /* Legitimize PIC addresses. If the address is already | |
14970 | position-independent, we return ORIG. Newly generated | |
14971 | position-independent addresses go into a reg. This is REG if non | |
14972 | zero, otherwise we allocate register(s) as necessary. */ | |
14973 | ||
c859cda6 | 14974 | #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000) |
ee890fe2 SS |
14975 | |
14976 | rtx | |
a2369ed3 DJ |
14977 | rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, |
14978 | rtx reg) | |
ee890fe2 SS |
14979 | { |
14980 | rtx base, offset; | |
14981 | ||
14982 | if (reg == NULL && ! reload_in_progress && ! reload_completed) | |
14983 | reg = gen_reg_rtx (Pmode); | |
14984 | ||
14985 | if (GET_CODE (orig) == CONST) | |
14986 | { | |
14987 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
14988 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
14989 | return orig; | |
14990 | ||
14991 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
14992 | { | |
2cf520bf GK |
14993 | /* Use a different reg for the intermediate value, as |
14994 | it will be marked UNCHANGING. */ | |
14995 | rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode); | |
14996 | ||
a4f6c312 SS |
14997 | base = |
14998 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), | |
2cf520bf | 14999 | Pmode, reg_temp); |
a4f6c312 SS |
15000 | offset = |
15001 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), | |
15002 | Pmode, reg); | |
ee890fe2 SS |
15003 | } |
15004 | else | |
15005 | abort (); | |
15006 | ||
15007 | if (GET_CODE (offset) == CONST_INT) | |
15008 | { | |
15009 | if (SMALL_INT (offset)) | |
ed8908e7 | 15010 | return plus_constant (base, INTVAL (offset)); |
ee890fe2 SS |
15011 | else if (! reload_in_progress && ! reload_completed) |
15012 | offset = force_reg (Pmode, offset); | |
15013 | else | |
c859cda6 DJ |
15014 | { |
15015 | rtx mem = force_const_mem (Pmode, orig); | |
15016 | return machopic_legitimize_pic_address (mem, Pmode, reg); | |
15017 | } | |
ee890fe2 SS |
15018 | } |
15019 | return gen_rtx (PLUS, Pmode, base, offset); | |
15020 | } | |
15021 | ||
15022 | /* Fall back on generic machopic code. */ | |
15023 | return machopic_legitimize_pic_address (orig, mode, reg); | |
15024 | } | |
15025 | ||
15026 | /* This is just a placeholder to make linking work without having to | |
15027 | add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is | |
15028 | ever needed for Darwin (not too likely!) this would have to get a | |
15029 | real definition. */ | |
15030 | ||
15031 | void | |
863d938c | 15032 | toc_section (void) |
ee890fe2 SS |
15033 | { |
15034 | } | |
15035 | ||
15036 | #endif /* TARGET_MACHO */ | |
7c262518 RH |
15037 | |
15038 | #if TARGET_ELF | |
15039 | static unsigned int | |
a2369ed3 | 15040 | rs6000_elf_section_type_flags (tree decl, const char *name, int reloc) |
7c262518 | 15041 | { |
1ff8f81a AM |
15042 | return default_section_type_flags_1 (decl, name, reloc, |
15043 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7c262518 | 15044 | } |
d9f6800d RH |
15045 | |
15046 | /* Record an element in the table of global constructors. SYMBOL is | |
15047 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
15048 | between 0 and MAX_INIT_PRIORITY. | |
15049 | ||
15050 | This differs from default_named_section_asm_out_constructor in | |
15051 | that we have special handling for -mrelocatable. */ | |
15052 | ||
15053 | static void | |
a2369ed3 | 15054 | rs6000_elf_asm_out_constructor (rtx symbol, int priority) |
d9f6800d RH |
15055 | { |
15056 | const char *section = ".ctors"; | |
15057 | char buf[16]; | |
15058 | ||
15059 | if (priority != DEFAULT_INIT_PRIORITY) | |
15060 | { | |
15061 | sprintf (buf, ".ctors.%.5u", | |
15062 | /* Invert the numbering so the linker puts us in the proper | |
15063 | order; constructors are run from right to left, and the | |
15064 | linker sorts in increasing order. */ | |
15065 | MAX_INIT_PRIORITY - priority); | |
15066 | section = buf; | |
15067 | } | |
15068 | ||
715bdd29 RH |
15069 | named_section_flags (section, SECTION_WRITE); |
15070 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
15071 | |
15072 | if (TARGET_RELOCATABLE) | |
15073 | { | |
15074 | fputs ("\t.long (", asm_out_file); | |
15075 | output_addr_const (asm_out_file, symbol); | |
15076 | fputs (")@fixup\n", asm_out_file); | |
15077 | } | |
15078 | else | |
c8af3574 | 15079 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d RH |
15080 | } |
15081 | ||
15082 | static void | |
a2369ed3 | 15083 | rs6000_elf_asm_out_destructor (rtx symbol, int priority) |
d9f6800d RH |
15084 | { |
15085 | const char *section = ".dtors"; | |
15086 | char buf[16]; | |
15087 | ||
15088 | if (priority != DEFAULT_INIT_PRIORITY) | |
15089 | { | |
15090 | sprintf (buf, ".dtors.%.5u", | |
15091 | /* Invert the numbering so the linker puts us in the proper | |
15092 | order; constructors are run from right to left, and the | |
15093 | linker sorts in increasing order. */ | |
15094 | MAX_INIT_PRIORITY - priority); | |
15095 | section = buf; | |
15096 | } | |
15097 | ||
715bdd29 RH |
15098 | named_section_flags (section, SECTION_WRITE); |
15099 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
15100 | |
15101 | if (TARGET_RELOCATABLE) | |
15102 | { | |
15103 | fputs ("\t.long (", asm_out_file); | |
15104 | output_addr_const (asm_out_file, symbol); | |
15105 | fputs (")@fixup\n", asm_out_file); | |
15106 | } | |
15107 | else | |
c8af3574 | 15108 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d | 15109 | } |
9739c90c JJ |
15110 | |
15111 | void | |
a2369ed3 | 15112 | rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl) |
9739c90c JJ |
15113 | { |
15114 | if (TARGET_64BIT) | |
15115 | { | |
15116 | fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file); | |
15117 | ASM_OUTPUT_LABEL (file, name); | |
15118 | fputs (DOUBLE_INT_ASM_OP, file); | |
15119 | putc ('.', file); | |
15120 | assemble_name (file, name); | |
15121 | fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file); | |
15122 | assemble_name (file, name); | |
15123 | fputs (",24\n\t.type\t.", file); | |
15124 | assemble_name (file, name); | |
15125 | fputs (",@function\n", file); | |
15126 | if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl)) | |
15127 | { | |
15128 | fputs ("\t.globl\t.", file); | |
15129 | assemble_name (file, name); | |
15130 | putc ('\n', file); | |
15131 | } | |
15132 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
15133 | putc ('.', file); | |
15134 | ASM_OUTPUT_LABEL (file, name); | |
15135 | return; | |
15136 | } | |
15137 | ||
15138 | if (TARGET_RELOCATABLE | |
15139 | && (get_pool_size () != 0 || current_function_profile) | |
15140 | && uses_TOC()) | |
15141 | { | |
15142 | char buf[256]; | |
15143 | ||
15144 | (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno); | |
15145 | ||
15146 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
15147 | fprintf (file, "\t.long "); | |
15148 | assemble_name (file, buf); | |
15149 | putc ('-', file); | |
15150 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
15151 | assemble_name (file, buf); | |
15152 | putc ('\n', file); | |
15153 | } | |
15154 | ||
15155 | ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); | |
15156 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
15157 | ||
15158 | if (DEFAULT_ABI == ABI_AIX) | |
15159 | { | |
15160 | const char *desc_name, *orig_name; | |
15161 | ||
15162 | orig_name = (*targetm.strip_name_encoding) (name); | |
15163 | desc_name = orig_name; | |
15164 | while (*desc_name == '.') | |
15165 | desc_name++; | |
15166 | ||
15167 | if (TREE_PUBLIC (decl)) | |
15168 | fprintf (file, "\t.globl %s\n", desc_name); | |
15169 | ||
15170 | fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); | |
15171 | fprintf (file, "%s:\n", desc_name); | |
15172 | fprintf (file, "\t.long %s\n", orig_name); | |
15173 | fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file); | |
15174 | if (DEFAULT_ABI == ABI_AIX) | |
15175 | fputs ("\t.long 0\n", file); | |
15176 | fprintf (file, "\t.previous\n"); | |
15177 | } | |
15178 | ASM_OUTPUT_LABEL (file, name); | |
15179 | } | |
7c262518 RH |
15180 | #endif |
15181 | ||
cbaaba19 | 15182 | #if TARGET_XCOFF |
7c262518 | 15183 | static void |
a2369ed3 | 15184 | rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name) |
b275d088 DE |
15185 | { |
15186 | fputs (GLOBAL_ASM_OP, stream); | |
15187 | RS6000_OUTPUT_BASENAME (stream, name); | |
15188 | putc ('\n', stream); | |
15189 | } | |
15190 | ||
15191 | static void | |
a2369ed3 | 15192 | rs6000_xcoff_asm_named_section (const char *name, unsigned int flags) |
7c262518 | 15193 | { |
0e5dbd9b DE |
15194 | int smclass; |
15195 | static const char * const suffix[3] = { "PR", "RO", "RW" }; | |
15196 | ||
15197 | if (flags & SECTION_CODE) | |
15198 | smclass = 0; | |
15199 | else if (flags & SECTION_WRITE) | |
15200 | smclass = 2; | |
15201 | else | |
15202 | smclass = 1; | |
15203 | ||
5b5198f7 | 15204 | fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n", |
0e5dbd9b | 15205 | (flags & SECTION_CODE) ? "." : "", |
5b5198f7 | 15206 | name, suffix[smclass], flags & SECTION_ENTSIZE); |
7c262518 | 15207 | } |
ae46c4e0 RH |
15208 | |
15209 | static void | |
a2369ed3 DJ |
15210 | rs6000_xcoff_select_section (tree decl, int reloc, |
15211 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
ae46c4e0 | 15212 | { |
5add3202 | 15213 | if (decl_readonly_section_1 (decl, reloc, 1)) |
ae46c4e0 | 15214 | { |
0e5dbd9b | 15215 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
15216 | read_only_data_section (); |
15217 | else | |
15218 | read_only_private_data_section (); | |
15219 | } | |
15220 | else | |
15221 | { | |
0e5dbd9b | 15222 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
15223 | data_section (); |
15224 | else | |
15225 | private_data_section (); | |
15226 | } | |
15227 | } | |
15228 | ||
15229 | static void | |
a2369ed3 | 15230 | rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED) |
ae46c4e0 RH |
15231 | { |
15232 | const char *name; | |
ae46c4e0 | 15233 | |
5b5198f7 DE |
15234 | /* Use select_section for private and uninitialized data. */ |
15235 | if (!TREE_PUBLIC (decl) | |
15236 | || DECL_COMMON (decl) | |
0e5dbd9b DE |
15237 | || DECL_INITIAL (decl) == NULL_TREE |
15238 | || DECL_INITIAL (decl) == error_mark_node | |
15239 | || (flag_zero_initialized_in_bss | |
15240 | && initializer_zerop (DECL_INITIAL (decl)))) | |
15241 | return; | |
15242 | ||
15243 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
15244 | name = (*targetm.strip_name_encoding) (name); | |
15245 | DECL_SECTION_NAME (decl) = build_string (strlen (name), name); | |
ae46c4e0 | 15246 | } |
b64a1b53 | 15247 | |
fb49053f RH |
15248 | /* Select section for constant in constant pool. |
15249 | ||
15250 | On RS/6000, all constants are in the private read-only data area. | |
15251 | However, if this is being placed in the TOC it must be output as a | |
15252 | toc entry. */ | |
15253 | ||
b64a1b53 | 15254 | static void |
a2369ed3 DJ |
15255 | rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x, |
15256 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
b64a1b53 RH |
15257 | { |
15258 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) | |
15259 | toc_section (); | |
15260 | else | |
15261 | read_only_private_data_section (); | |
15262 | } | |
772c5265 RH |
15263 | |
15264 | /* Remove any trailing [DS] or the like from the symbol name. */ | |
15265 | ||
15266 | static const char * | |
a2369ed3 | 15267 | rs6000_xcoff_strip_name_encoding (const char *name) |
772c5265 RH |
15268 | { |
15269 | size_t len; | |
15270 | if (*name == '*') | |
15271 | name++; | |
15272 | len = strlen (name); | |
15273 | if (name[len - 1] == ']') | |
15274 | return ggc_alloc_string (name, len - 4); | |
15275 | else | |
15276 | return name; | |
15277 | } | |
15278 | ||
5add3202 DE |
15279 | /* Section attributes. AIX is always PIC. */ |
15280 | ||
15281 | static unsigned int | |
a2369ed3 | 15282 | rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc) |
5add3202 | 15283 | { |
5b5198f7 DE |
15284 | unsigned int align; |
15285 | unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1); | |
15286 | ||
15287 | /* Align to at least UNIT size. */ | |
15288 | if (flags & SECTION_CODE) | |
15289 | align = MIN_UNITS_PER_WORD; | |
15290 | else | |
15291 | /* Increase alignment of large objects if not already stricter. */ | |
15292 | align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT), | |
15293 | int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD | |
15294 | ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD); | |
15295 | ||
15296 | return flags | (exact_log2 (align) & SECTION_ENTSIZE); | |
5add3202 | 15297 | } |
a5fe455b | 15298 | |
1bc7c5b6 ZW |
15299 | /* Output at beginning of assembler file. |
15300 | ||
15301 | Initialize the section names for the RS/6000 at this point. | |
15302 | ||
15303 | Specify filename, including full path, to assembler. | |
15304 | ||
15305 | We want to go into the TOC section so at least one .toc will be emitted. | |
15306 | Also, in order to output proper .bs/.es pairs, we need at least one static | |
15307 | [RW] section emitted. | |
15308 | ||
15309 | Finally, declare mcount when profiling to make the assembler happy. */ | |
15310 | ||
15311 | static void | |
863d938c | 15312 | rs6000_xcoff_file_start (void) |
1bc7c5b6 ZW |
15313 | { |
15314 | rs6000_gen_section_name (&xcoff_bss_section_name, | |
15315 | main_input_filename, ".bss_"); | |
15316 | rs6000_gen_section_name (&xcoff_private_data_section_name, | |
15317 | main_input_filename, ".rw_"); | |
15318 | rs6000_gen_section_name (&xcoff_read_only_section_name, | |
15319 | main_input_filename, ".ro_"); | |
15320 | ||
15321 | fputs ("\t.file\t", asm_out_file); | |
15322 | output_quoted_string (asm_out_file, main_input_filename); | |
15323 | fputc ('\n', asm_out_file); | |
15324 | toc_section (); | |
15325 | if (write_symbols != NO_DEBUG) | |
15326 | private_data_section (); | |
15327 | text_section (); | |
15328 | if (profile_flag) | |
15329 | fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT); | |
15330 | rs6000_file_start (); | |
15331 | } | |
15332 | ||
a5fe455b ZW |
15333 | /* Output at end of assembler file. |
15334 | On the RS/6000, referencing data should automatically pull in text. */ | |
15335 | ||
15336 | static void | |
863d938c | 15337 | rs6000_xcoff_file_end (void) |
a5fe455b ZW |
15338 | { |
15339 | text_section (); | |
15340 | fputs ("_section_.text:\n", asm_out_file); | |
15341 | data_section (); | |
15342 | fputs (TARGET_32BIT | |
15343 | ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", | |
15344 | asm_out_file); | |
15345 | } | |
f1384257 | 15346 | #endif /* TARGET_XCOFF */ |
0e5dbd9b | 15347 | |
f1384257 AM |
15348 | #if TARGET_MACHO |
15349 | /* Cross-module name binding. Darwin does not support overriding | |
7f3d8013 | 15350 | functions at dynamic-link time. */ |
0e5dbd9b | 15351 | |
2bcc50d0 | 15352 | static bool |
a2369ed3 | 15353 | rs6000_binds_local_p (tree decl) |
0e5dbd9b | 15354 | { |
f1384257 | 15355 | return default_binds_local_p_1 (decl, 0); |
0e5dbd9b | 15356 | } |
f1384257 | 15357 | #endif |
34bb030a | 15358 | |
3c50106f RH |
15359 | /* Compute a (partial) cost for rtx X. Return true if the complete |
15360 | cost has been computed, and false if subexpressions should be | |
15361 | scanned. In either case, *TOTAL contains the cost result. */ | |
15362 | ||
15363 | static bool | |
a2369ed3 DJ |
15364 | rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, |
15365 | int *total) | |
3c50106f RH |
15366 | { |
15367 | switch (code) | |
15368 | { | |
15369 | /* On the RS/6000, if it is valid in the insn, it is free. | |
15370 | So this always returns 0. */ | |
15371 | case CONST_INT: | |
15372 | case CONST: | |
15373 | case LABEL_REF: | |
15374 | case SYMBOL_REF: | |
15375 | case CONST_DOUBLE: | |
15376 | case HIGH: | |
15377 | *total = 0; | |
15378 | return true; | |
15379 | ||
15380 | case PLUS: | |
15381 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
15382 | && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) | |
15383 | + 0x8000) >= 0x10000) | |
15384 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
15385 | ? COSTS_N_INSNS (2) | |
15386 | : COSTS_N_INSNS (1)); | |
15387 | return true; | |
15388 | ||
15389 | case AND: | |
15390 | case IOR: | |
15391 | case XOR: | |
15392 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
15393 | && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0 | |
15394 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
15395 | ? COSTS_N_INSNS (2) | |
15396 | : COSTS_N_INSNS (1)); | |
15397 | return true; | |
15398 | ||
15399 | case MULT: | |
15400 | if (optimize_size) | |
15401 | { | |
15402 | *total = COSTS_N_INSNS (2); | |
15403 | return true; | |
15404 | } | |
15405 | switch (rs6000_cpu) | |
15406 | { | |
15407 | case PROCESSOR_RIOS1: | |
15408 | case PROCESSOR_PPC405: | |
15409 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
15410 | ? COSTS_N_INSNS (5) | |
15411 | : (INTVAL (XEXP (x, 1)) >= -256 | |
15412 | && INTVAL (XEXP (x, 1)) <= 255) | |
15413 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
15414 | return true; | |
15415 | ||
02ca7595 DE |
15416 | case PROCESSOR_PPC440: |
15417 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
15418 | ? COSTS_N_INSNS (3) | |
15419 | : COSTS_N_INSNS (2)); | |
15420 | return true; | |
15421 | ||
3c50106f RH |
15422 | case PROCESSOR_RS64A: |
15423 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
15424 | ? GET_MODE (XEXP (x, 1)) != DImode | |
15425 | ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34) | |
15426 | : (INTVAL (XEXP (x, 1)) >= -256 | |
15427 | && INTVAL (XEXP (x, 1)) <= 255) | |
15428 | ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12)); | |
15429 | return true; | |
15430 | ||
15431 | case PROCESSOR_RIOS2: | |
15432 | case PROCESSOR_MPCCORE: | |
15433 | case PROCESSOR_PPC604e: | |
15434 | *total = COSTS_N_INSNS (2); | |
15435 | return true; | |
15436 | ||
15437 | case PROCESSOR_PPC601: | |
15438 | *total = COSTS_N_INSNS (5); | |
15439 | return true; | |
15440 | ||
15441 | case PROCESSOR_PPC603: | |
15442 | case PROCESSOR_PPC7400: | |
15443 | case PROCESSOR_PPC750: | |
15444 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
15445 | ? COSTS_N_INSNS (5) | |
15446 | : (INTVAL (XEXP (x, 1)) >= -256 | |
15447 | && INTVAL (XEXP (x, 1)) <= 255) | |
15448 | ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3)); | |
15449 | return true; | |
15450 | ||
15451 | case PROCESSOR_PPC7450: | |
15452 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
15453 | ? COSTS_N_INSNS (4) | |
15454 | : COSTS_N_INSNS (3)); | |
15455 | return true; | |
15456 | ||
15457 | case PROCESSOR_PPC403: | |
15458 | case PROCESSOR_PPC604: | |
15459 | case PROCESSOR_PPC8540: | |
15460 | *total = COSTS_N_INSNS (4); | |
15461 | return true; | |
15462 | ||
15463 | case PROCESSOR_PPC620: | |
15464 | case PROCESSOR_PPC630: | |
3c50106f RH |
15465 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT |
15466 | ? GET_MODE (XEXP (x, 1)) != DImode | |
15467 | ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7) | |
15468 | : (INTVAL (XEXP (x, 1)) >= -256 | |
15469 | && INTVAL (XEXP (x, 1)) <= 255) | |
15470 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
15471 | return true; | |
15472 | ||
9259f3b0 DE |
15473 | case PROCESSOR_POWER4: |
15474 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
15475 | ? GET_MODE (XEXP (x, 1)) != DImode | |
984e25ac DE |
15476 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4) |
15477 | : COSTS_N_INSNS (2)); | |
9259f3b0 DE |
15478 | return true; |
15479 | ||
3c50106f RH |
15480 | default: |
15481 | abort (); | |
15482 | } | |
15483 | ||
15484 | case DIV: | |
15485 | case MOD: | |
15486 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
15487 | && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) | |
15488 | { | |
15489 | *total = COSTS_N_INSNS (2); | |
15490 | return true; | |
15491 | } | |
15492 | /* FALLTHRU */ | |
15493 | ||
15494 | case UDIV: | |
15495 | case UMOD: | |
15496 | switch (rs6000_cpu) | |
15497 | { | |
15498 | case PROCESSOR_RIOS1: | |
15499 | *total = COSTS_N_INSNS (19); | |
15500 | return true; | |
15501 | ||
15502 | case PROCESSOR_RIOS2: | |
15503 | *total = COSTS_N_INSNS (13); | |
15504 | return true; | |
15505 | ||
15506 | case PROCESSOR_RS64A: | |
15507 | *total = (GET_MODE (XEXP (x, 1)) != DImode | |
15508 | ? COSTS_N_INSNS (65) | |
15509 | : COSTS_N_INSNS (67)); | |
15510 | return true; | |
15511 | ||
15512 | case PROCESSOR_MPCCORE: | |
15513 | *total = COSTS_N_INSNS (6); | |
15514 | return true; | |
15515 | ||
15516 | case PROCESSOR_PPC403: | |
15517 | *total = COSTS_N_INSNS (33); | |
15518 | return true; | |
15519 | ||
15520 | case PROCESSOR_PPC405: | |
15521 | *total = COSTS_N_INSNS (35); | |
15522 | return true; | |
15523 | ||
02ca7595 DE |
15524 | case PROCESSOR_PPC440: |
15525 | *total = COSTS_N_INSNS (34); | |
15526 | return true; | |
15527 | ||
3c50106f RH |
15528 | case PROCESSOR_PPC601: |
15529 | *total = COSTS_N_INSNS (36); | |
15530 | return true; | |
15531 | ||
15532 | case PROCESSOR_PPC603: | |
15533 | *total = COSTS_N_INSNS (37); | |
15534 | return true; | |
15535 | ||
15536 | case PROCESSOR_PPC604: | |
15537 | case PROCESSOR_PPC604e: | |
15538 | *total = COSTS_N_INSNS (20); | |
15539 | return true; | |
15540 | ||
15541 | case PROCESSOR_PPC620: | |
15542 | case PROCESSOR_PPC630: | |
3c50106f RH |
15543 | *total = (GET_MODE (XEXP (x, 1)) != DImode |
15544 | ? COSTS_N_INSNS (21) | |
15545 | : COSTS_N_INSNS (37)); | |
15546 | return true; | |
15547 | ||
15548 | case PROCESSOR_PPC750: | |
15549 | case PROCESSOR_PPC8540: | |
15550 | case PROCESSOR_PPC7400: | |
15551 | *total = COSTS_N_INSNS (19); | |
15552 | return true; | |
15553 | ||
15554 | case PROCESSOR_PPC7450: | |
15555 | *total = COSTS_N_INSNS (23); | |
15556 | return true; | |
984e25ac DE |
15557 | |
15558 | case PROCESSOR_POWER4: | |
15559 | *total = (GET_MODE (XEXP (x, 1)) != DImode | |
15560 | ? COSTS_N_INSNS (18) | |
15561 | : COSTS_N_INSNS (34)); | |
15562 | return true; | |
3c50106f RH |
15563 | |
15564 | default: | |
15565 | abort (); | |
15566 | } | |
15567 | ||
15568 | case FFS: | |
15569 | *total = COSTS_N_INSNS (4); | |
15570 | return true; | |
15571 | ||
15572 | case MEM: | |
15573 | /* MEM should be slightly more expensive than (plus (reg) (const)) */ | |
15574 | *total = 5; | |
15575 | return true; | |
15576 | ||
15577 | default: | |
15578 | return false; | |
15579 | } | |
15580 | } | |
15581 | ||
34bb030a DE |
15582 | /* A C expression returning the cost of moving data from a register of class |
15583 | CLASS1 to one of CLASS2. */ | |
15584 | ||
15585 | int | |
a2369ed3 DJ |
15586 | rs6000_register_move_cost (enum machine_mode mode, |
15587 | enum reg_class from, enum reg_class to) | |
34bb030a DE |
15588 | { |
15589 | /* Moves from/to GENERAL_REGS. */ | |
15590 | if (reg_classes_intersect_p (to, GENERAL_REGS) | |
15591 | || reg_classes_intersect_p (from, GENERAL_REGS)) | |
15592 | { | |
15593 | if (! reg_classes_intersect_p (to, GENERAL_REGS)) | |
15594 | from = to; | |
15595 | ||
15596 | if (from == FLOAT_REGS || from == ALTIVEC_REGS) | |
15597 | return (rs6000_memory_move_cost (mode, from, 0) | |
15598 | + rs6000_memory_move_cost (mode, GENERAL_REGS, 0)); | |
15599 | ||
15600 | /* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/ | |
15601 | else if (from == CR_REGS) | |
15602 | return 4; | |
15603 | ||
15604 | else | |
15605 | /* A move will cost one instruction per GPR moved. */ | |
15606 | return 2 * HARD_REGNO_NREGS (0, mode); | |
15607 | } | |
15608 | ||
15609 | /* Moving between two similar registers is just one instruction. */ | |
15610 | else if (reg_classes_intersect_p (to, from)) | |
15611 | return mode == TFmode ? 4 : 2; | |
15612 | ||
15613 | /* Everything else has to go through GENERAL_REGS. */ | |
15614 | else | |
15615 | return (rs6000_register_move_cost (mode, GENERAL_REGS, to) | |
15616 | + rs6000_register_move_cost (mode, from, GENERAL_REGS)); | |
15617 | } | |
15618 | ||
15619 | /* A C expressions returning the cost of moving data of MODE from a register to | |
15620 | or from memory. */ | |
15621 | ||
15622 | int | |
a2369ed3 DJ |
15623 | rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class, |
15624 | int in ATTRIBUTE_UNUSED) | |
34bb030a DE |
15625 | { |
15626 | if (reg_classes_intersect_p (class, GENERAL_REGS)) | |
15627 | return 4 * HARD_REGNO_NREGS (0, mode); | |
15628 | else if (reg_classes_intersect_p (class, FLOAT_REGS)) | |
15629 | return 4 * HARD_REGNO_NREGS (32, mode); | |
15630 | else if (reg_classes_intersect_p (class, ALTIVEC_REGS)) | |
15631 | return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode); | |
15632 | else | |
15633 | return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS); | |
15634 | } | |
15635 | ||
ded9bf77 AH |
15636 | /* Return an RTX representing where to find the function value of a |
15637 | function returning MODE. */ | |
15638 | static rtx | |
15639 | rs6000_complex_function_value (enum machine_mode mode) | |
15640 | { | |
15641 | unsigned int regno; | |
15642 | rtx r1, r2; | |
15643 | enum machine_mode inner = GET_MODE_INNER (mode); | |
15644 | ||
15645 | if (FLOAT_MODE_P (mode)) | |
15646 | regno = FP_ARG_RETURN; | |
15647 | else | |
15648 | { | |
15649 | regno = GP_ARG_RETURN; | |
15650 | ||
15651 | /* 32-bit is OK since it'll go in r3/r4. */ | |
165848da AH |
15652 | if (TARGET_32BIT |
15653 | && GET_MODE_BITSIZE (inner) >= 32) | |
ded9bf77 AH |
15654 | return gen_rtx_REG (mode, regno); |
15655 | } | |
15656 | ||
15657 | r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno), | |
15658 | const0_rtx); | |
15659 | r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1), | |
15660 | GEN_INT (GET_MODE_UNIT_SIZE (inner))); | |
15661 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); | |
15662 | } | |
15663 | ||
a6ebc39a AH |
15664 | /* Define how to find the value returned by a function. |
15665 | VALTYPE is the data type of the value (as a tree). | |
15666 | If the precise function being called is known, FUNC is its FUNCTION_DECL; | |
15667 | otherwise, FUNC is 0. | |
15668 | ||
15669 | On the SPE, both FPs and vectors are returned in r3. | |
15670 | ||
15671 | On RS/6000 an integer value is in r3 and a floating-point value is in | |
15672 | fp1, unless -msoft-float. */ | |
15673 | ||
15674 | rtx | |
15675 | rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED) | |
15676 | { | |
15677 | enum machine_mode mode; | |
2a8fa26c | 15678 | unsigned int regno; |
a6ebc39a | 15679 | |
0e67400a FJ |
15680 | if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode) |
15681 | { | |
15682 | /* Long long return value need be split in -mpowerpc64, 32bit ABI. */ | |
15683 | return gen_rtx_PARALLEL (DImode, | |
15684 | gen_rtvec (2, | |
15685 | gen_rtx_EXPR_LIST (VOIDmode, | |
15686 | gen_rtx_REG (SImode, GP_ARG_RETURN), | |
15687 | const0_rtx), | |
15688 | gen_rtx_EXPR_LIST (VOIDmode, | |
15689 | gen_rtx_REG (SImode, | |
15690 | GP_ARG_RETURN + 1), | |
15691 | GEN_INT (4)))); | |
15692 | } | |
15693 | ||
a6ebc39a AH |
15694 | if ((INTEGRAL_TYPE_P (valtype) |
15695 | && TYPE_PRECISION (valtype) < BITS_PER_WORD) | |
15696 | || POINTER_TYPE_P (valtype)) | |
b78d48dd | 15697 | mode = TARGET_32BIT ? SImode : DImode; |
a6ebc39a AH |
15698 | else |
15699 | mode = TYPE_MODE (valtype); | |
15700 | ||
2a8fa26c DE |
15701 | if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS) |
15702 | regno = FP_ARG_RETURN; | |
ded9bf77 AH |
15703 | else if (TREE_CODE (valtype) == COMPLEX_TYPE |
15704 | && TARGET_HARD_FLOAT | |
15705 | && SPLIT_COMPLEX_ARGS) | |
15706 | return rs6000_complex_function_value (mode); | |
2a8fa26c | 15707 | else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC) |
a6ebc39a AH |
15708 | regno = ALTIVEC_ARG_RETURN; |
15709 | else | |
15710 | regno = GP_ARG_RETURN; | |
15711 | ||
15712 | return gen_rtx_REG (mode, regno); | |
15713 | } | |
15714 | ||
ded9bf77 AH |
15715 | /* Define how to find the value returned by a library function |
15716 | assuming the value has mode MODE. */ | |
15717 | rtx | |
15718 | rs6000_libcall_value (enum machine_mode mode) | |
15719 | { | |
15720 | unsigned int regno; | |
15721 | ||
15722 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
15723 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
15724 | regno = FP_ARG_RETURN; | |
15725 | else if (ALTIVEC_VECTOR_MODE (mode)) | |
15726 | regno = ALTIVEC_ARG_RETURN; | |
15727 | else if (COMPLEX_MODE_P (mode) && SPLIT_COMPLEX_ARGS) | |
15728 | return rs6000_complex_function_value (mode); | |
15729 | else | |
15730 | regno = GP_ARG_RETURN; | |
15731 | ||
15732 | return gen_rtx_REG (mode, regno); | |
15733 | } | |
15734 | ||
d1d0c603 JJ |
15735 | /* Define the offset between two registers, FROM to be eliminated and its |
15736 | replacement TO, at the start of a routine. */ | |
15737 | HOST_WIDE_INT | |
15738 | rs6000_initial_elimination_offset (int from, int to) | |
15739 | { | |
15740 | rs6000_stack_t *info = rs6000_stack_info (); | |
15741 | HOST_WIDE_INT offset; | |
15742 | ||
15743 | if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
15744 | offset = info->push_p ? 0 : -info->total_size; | |
15745 | else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) | |
15746 | offset = info->total_size; | |
15747 | else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
15748 | offset = info->push_p ? info->total_size : 0; | |
15749 | else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM) | |
15750 | offset = 0; | |
15751 | else | |
15752 | abort (); | |
15753 | ||
15754 | return offset; | |
15755 | } | |
15756 | ||
62e1dfcf NC |
15757 | /* Return true if TYPE is of type __ev64_opaque__. */ |
15758 | ||
c8e4f0e9 | 15759 | static bool |
a2369ed3 | 15760 | is_ev64_opaque_type (tree type) |
62e1dfcf | 15761 | { |
c8e4f0e9 | 15762 | return (TARGET_SPE |
2abe3e28 AH |
15763 | && (type == opaque_V2SI_type_node |
15764 | || type == opaque_V2SF_type_node | |
36252949 | 15765 | || type == opaque_p_V2SI_type_node)); |
62e1dfcf NC |
15766 | } |
15767 | ||
96714395 | 15768 | static rtx |
a2369ed3 | 15769 | rs6000_dwarf_register_span (rtx reg) |
96714395 AH |
15770 | { |
15771 | unsigned regno; | |
15772 | ||
15773 | if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg))) | |
15774 | return NULL_RTX; | |
15775 | ||
15776 | regno = REGNO (reg); | |
15777 | ||
15778 | /* The duality of the SPE register size wreaks all kinds of havoc. | |
15779 | This is a way of distinguishing r0 in 32-bits from r0 in | |
15780 | 64-bits. */ | |
15781 | return | |
15782 | gen_rtx_PARALLEL (VOIDmode, | |
3bd104d1 AH |
15783 | BYTES_BIG_ENDIAN |
15784 | ? gen_rtvec (2, | |
15785 | gen_rtx_REG (SImode, regno + 1200), | |
15786 | gen_rtx_REG (SImode, regno)) | |
15787 | : gen_rtvec (2, | |
15788 | gen_rtx_REG (SImode, regno), | |
15789 | gen_rtx_REG (SImode, regno + 1200))); | |
96714395 AH |
15790 | } |
15791 | ||
17211ab5 | 15792 | #include "gt-rs6000.h" |