]>
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, |
93c9d1ba | 3 | 2000, 2001, 2002, 2003, 2004 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 | ||
452a7d36 HP |
63 | #define EASY_VECTOR_15(n) ((n) >= -16 && (n) <= 15) |
64 | #define EASY_VECTOR_15_ADD_SELF(n) ((n) >= 0x10 && (n) <= 0x1e \ | |
65 | && !((n) & 1)) | |
d744e06e | 66 | |
9878760c RK |
67 | #define min(A,B) ((A) < (B) ? (A) : (B)) |
68 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
69 | ||
d1d0c603 JJ |
70 | /* Structure used to define the rs6000 stack */ |
71 | typedef struct rs6000_stack { | |
72 | int first_gp_reg_save; /* first callee saved GP register used */ | |
73 | int first_fp_reg_save; /* first callee saved FP register used */ | |
74 | int first_altivec_reg_save; /* first callee saved AltiVec register used */ | |
75 | int lr_save_p; /* true if the link reg needs to be saved */ | |
76 | int cr_save_p; /* true if the CR reg needs to be saved */ | |
77 | unsigned int vrsave_mask; /* mask of vec registers to save */ | |
78 | int toc_save_p; /* true if the TOC needs to be saved */ | |
79 | int push_p; /* true if we need to allocate stack space */ | |
80 | int calls_p; /* true if the function makes any calls */ | |
81 | enum rs6000_abi abi; /* which ABI to use */ | |
82 | int gp_save_offset; /* offset to save GP regs from initial SP */ | |
83 | int fp_save_offset; /* offset to save FP regs from initial SP */ | |
84 | int altivec_save_offset; /* offset to save AltiVec regs from initial SP */ | |
85 | int lr_save_offset; /* offset to save LR from initial SP */ | |
86 | int cr_save_offset; /* offset to save CR from initial SP */ | |
87 | int vrsave_save_offset; /* offset to save VRSAVE from initial SP */ | |
88 | int spe_gp_save_offset; /* offset to save spe 64-bit gprs */ | |
89 | int toc_save_offset; /* offset to save the TOC pointer */ | |
90 | int varargs_save_offset; /* offset to save the varargs registers */ | |
91 | int ehrd_offset; /* offset to EH return data */ | |
92 | int reg_size; /* register size (4 or 8) */ | |
93 | int varargs_size; /* size to hold V.4 args passed in regs */ | |
94 | HOST_WIDE_INT vars_size; /* variable save area size */ | |
95 | int parm_size; /* outgoing parameter size */ | |
96 | int save_size; /* save area size */ | |
97 | int fixed_size; /* fixed size of stack frame */ | |
98 | int gp_size; /* size of saved GP registers */ | |
99 | int fp_size; /* size of saved FP registers */ | |
100 | int altivec_size; /* size of saved AltiVec registers */ | |
101 | int cr_size; /* size to hold CR if not in save_size */ | |
102 | int lr_size; /* size to hold LR if not in save_size */ | |
103 | int vrsave_size; /* size to hold VRSAVE if not in save_size */ | |
104 | int altivec_padding_size; /* size of altivec alignment padding if | |
105 | not in save_size */ | |
106 | int spe_gp_size; /* size of 64-bit GPR save size for SPE */ | |
107 | int spe_padding_size; | |
108 | int toc_size; /* size to hold TOC if not in save_size */ | |
109 | HOST_WIDE_INT total_size; /* total bytes allocated for stack */ | |
110 | int spe_64bit_regs_used; | |
111 | } rs6000_stack_t; | |
112 | ||
5248c961 RK |
113 | /* Target cpu type */ |
114 | ||
115 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
116 | struct rs6000_cpu_select rs6000_select[3] = |
117 | { | |
815cdc52 MM |
118 | /* switch name, tune arch */ |
119 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
120 | { (const char *)0, "-mcpu=", 1, 1 }, | |
121 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 122 | }; |
5248c961 | 123 | |
ec507f2d DE |
124 | /* Always emit branch hint bits. */ |
125 | static GTY(()) bool rs6000_always_hint; | |
126 | ||
127 | /* Schedule instructions for group formation. */ | |
128 | static GTY(()) bool rs6000_sched_groups; | |
129 | ||
79ae11c4 DN |
130 | /* Support adjust_priority scheduler hook |
131 | and -mprioritize-restricted-insns= option. */ | |
132 | const char *rs6000_sched_restricted_insns_priority_str; | |
133 | int rs6000_sched_restricted_insns_priority; | |
134 | ||
569fa502 DN |
135 | /* Support for -msched-costly-dep option. */ |
136 | const char *rs6000_sched_costly_dep_str; | |
137 | enum rs6000_dependence_cost rs6000_sched_costly_dep; | |
138 | ||
cbe26ab8 DN |
139 | /* Support for -minsert-sched-nops option. */ |
140 | const char *rs6000_sched_insert_nops_str; | |
141 | enum rs6000_nop_insertion rs6000_sched_insert_nops; | |
142 | ||
6fa3f289 ZW |
143 | /* Size of long double */ |
144 | const char *rs6000_long_double_size_string; | |
145 | int rs6000_long_double_type_size; | |
146 | ||
147 | /* Whether -mabi=altivec has appeared */ | |
148 | int rs6000_altivec_abi; | |
149 | ||
08b57fb3 AH |
150 | /* Whether VRSAVE instructions should be generated. */ |
151 | int rs6000_altivec_vrsave; | |
152 | ||
153 | /* String from -mvrsave= option. */ | |
154 | const char *rs6000_altivec_vrsave_string; | |
155 | ||
a3170dc6 AH |
156 | /* Nonzero if we want SPE ABI extensions. */ |
157 | int rs6000_spe_abi; | |
158 | ||
159 | /* Whether isel instructions should be generated. */ | |
160 | int rs6000_isel; | |
161 | ||
993f19a8 AH |
162 | /* Whether SPE simd instructions should be generated. */ |
163 | int rs6000_spe; | |
164 | ||
5da702b1 AH |
165 | /* Nonzero if floating point operations are done in the GPRs. */ |
166 | int rs6000_float_gprs = 0; | |
167 | ||
168 | /* String from -mfloat-gprs=. */ | |
169 | const char *rs6000_float_gprs_string; | |
a3170dc6 AH |
170 | |
171 | /* String from -misel=. */ | |
172 | const char *rs6000_isel_string; | |
173 | ||
993f19a8 AH |
174 | /* String from -mspe=. */ |
175 | const char *rs6000_spe_string; | |
176 | ||
a0ab749a | 177 | /* Set to nonzero once AIX common-mode calls have been defined. */ |
bbfb86aa | 178 | static GTY(()) int common_mode_defined; |
c81bebd7 | 179 | |
9878760c RK |
180 | /* Save information from a "cmpxx" operation until the branch or scc is |
181 | emitted. */ | |
9878760c RK |
182 | rtx rs6000_compare_op0, rs6000_compare_op1; |
183 | int rs6000_compare_fp_p; | |
874a0744 | 184 | |
874a0744 MM |
185 | /* Label number of label created for -mrelocatable, to call to so we can |
186 | get the address of the GOT section */ | |
187 | int rs6000_pic_labelno; | |
c81bebd7 | 188 | |
b91da81f | 189 | #ifdef USING_ELFOS_H |
c81bebd7 | 190 | /* Which abi to adhere to */ |
9739c90c | 191 | const char *rs6000_abi_name; |
d9407988 MM |
192 | |
193 | /* Semantics of the small data area */ | |
194 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
195 | ||
196 | /* Which small data model to use */ | |
815cdc52 | 197 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
198 | |
199 | /* Counter for labels which are to be placed in .fixup. */ | |
200 | int fixuplabelno = 0; | |
874a0744 | 201 | #endif |
4697a36c | 202 | |
c4501e62 JJ |
203 | /* Bit size of immediate TLS offsets and string from which it is decoded. */ |
204 | int rs6000_tls_size = 32; | |
205 | const char *rs6000_tls_size_string; | |
206 | ||
b6c9286a MM |
207 | /* ABI enumeration available for subtarget to use. */ |
208 | enum rs6000_abi rs6000_current_abi; | |
209 | ||
0ac081f6 AH |
210 | /* ABI string from -mabi= option. */ |
211 | const char *rs6000_abi_string; | |
212 | ||
38c1f2d7 | 213 | /* Debug flags */ |
815cdc52 | 214 | const char *rs6000_debug_name; |
38c1f2d7 MM |
215 | int rs6000_debug_stack; /* debug stack applications */ |
216 | int rs6000_debug_arg; /* debug argument handling */ | |
217 | ||
0d1fbc8c AH |
218 | /* Value is TRUE if register/mode pair is accepatable. */ |
219 | bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER]; | |
220 | ||
6035d635 | 221 | /* Opaque types. */ |
2abe3e28 | 222 | static GTY(()) tree opaque_V2SI_type_node; |
2abe3e28 | 223 | static GTY(()) tree opaque_V2SF_type_node; |
6035d635 | 224 | static GTY(()) tree opaque_p_V2SI_type_node; |
4a5eab38 PB |
225 | static GTY(()) tree V16QI_type_node; |
226 | static GTY(()) tree V2SI_type_node; | |
227 | static GTY(()) tree V2SF_type_node; | |
228 | static GTY(()) tree V4HI_type_node; | |
229 | static GTY(()) tree V4SI_type_node; | |
230 | static GTY(()) tree V4SF_type_node; | |
231 | static GTY(()) tree V8HI_type_node; | |
232 | static GTY(()) tree unsigned_V16QI_type_node; | |
233 | static GTY(()) tree unsigned_V8HI_type_node; | |
234 | static GTY(()) tree unsigned_V4SI_type_node; | |
8bb418a3 ZL |
235 | static GTY(()) tree bool_char_type_node; /* __bool char */ |
236 | static GTY(()) tree bool_short_type_node; /* __bool short */ | |
237 | static GTY(()) tree bool_int_type_node; /* __bool int */ | |
238 | static GTY(()) tree pixel_type_node; /* __pixel */ | |
239 | static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */ | |
240 | static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */ | |
241 | static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */ | |
242 | static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */ | |
243 | ||
244 | int rs6000_warn_altivec_long = 1; /* On by default. */ | |
245 | const char *rs6000_warn_altivec_long_switch; | |
246 | ||
57ac7be9 AM |
247 | const char *rs6000_traceback_name; |
248 | static enum { | |
249 | traceback_default = 0, | |
250 | traceback_none, | |
251 | traceback_part, | |
252 | traceback_full | |
253 | } rs6000_traceback; | |
254 | ||
38c1f2d7 MM |
255 | /* Flag to say the TOC is initialized */ |
256 | int toc_initialized; | |
9ebbca7d | 257 | char toc_label_name[10]; |
38c1f2d7 | 258 | |
9ebbca7d | 259 | /* Alias set for saves and restores from the rs6000 stack. */ |
f103e34d | 260 | static GTY(()) int rs6000_sr_alias_set; |
c8023011 | 261 | |
a5c76ee6 ZW |
262 | /* Call distance, overridden by -mlongcall and #pragma longcall(1). |
263 | The only place that looks at this is rs6000_set_default_type_attributes; | |
264 | everywhere else should rely on the presence or absence of a longcall | |
265 | attribute on the function declaration. */ | |
266 | int rs6000_default_long_calls; | |
267 | const char *rs6000_longcall_switch; | |
268 | ||
a3c9585f KH |
269 | /* Control alignment for fields within structures. */ |
270 | /* String from -malign-XXXXX. */ | |
025d9908 KH |
271 | const char *rs6000_alignment_string; |
272 | int rs6000_alignment_flags; | |
273 | ||
a3170dc6 AH |
274 | struct builtin_description |
275 | { | |
276 | /* mask is not const because we're going to alter it below. This | |
277 | nonsense will go away when we rewrite the -march infrastructure | |
278 | to give us more target flag bits. */ | |
279 | unsigned int mask; | |
280 | const enum insn_code icode; | |
281 | const char *const name; | |
282 | const enum rs6000_builtins code; | |
283 | }; | |
284 | ||
a2369ed3 DJ |
285 | static bool rs6000_function_ok_for_sibcall (tree, tree); |
286 | static int num_insns_constant_wide (HOST_WIDE_INT); | |
287 | static void validate_condition_mode (enum rtx_code, enum machine_mode); | |
288 | static rtx rs6000_generate_compare (enum rtx_code); | |
289 | static void rs6000_maybe_dead (rtx); | |
290 | static void rs6000_emit_stack_tie (void); | |
291 | static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx); | |
292 | static rtx spe_synthesize_frame_save (rtx); | |
293 | static bool spe_func_has_64bit_regs_p (void); | |
b20a9cca | 294 | static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int, |
d1d0c603 | 295 | int, HOST_WIDE_INT); |
a2369ed3 DJ |
296 | static rtx gen_frame_mem_offset (enum machine_mode, rtx, int); |
297 | static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int); | |
298 | static unsigned rs6000_hash_constant (rtx); | |
299 | static unsigned toc_hash_function (const void *); | |
300 | static int toc_hash_eq (const void *, const void *); | |
301 | static int constant_pool_expr_1 (rtx, int *, int *); | |
302 | static bool constant_pool_expr_p (rtx); | |
303 | static bool toc_relative_expr_p (rtx); | |
304 | static bool legitimate_small_data_p (enum machine_mode, rtx); | |
305 | static bool legitimate_offset_address_p (enum machine_mode, rtx, int); | |
306 | static bool legitimate_indexed_address_p (rtx, int); | |
307 | static bool legitimate_indirect_address_p (rtx, int); | |
4c81e946 | 308 | static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode); |
a2369ed3 DJ |
309 | static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int); |
310 | static struct machine_function * rs6000_init_machine_status (void); | |
311 | static bool rs6000_assemble_integer (rtx, unsigned int, int); | |
5add3202 | 312 | #ifdef HAVE_GAS_HIDDEN |
a2369ed3 | 313 | static void rs6000_assemble_visibility (tree, int); |
5add3202 | 314 | #endif |
a2369ed3 DJ |
315 | static int rs6000_ra_ever_killed (void); |
316 | static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *); | |
8bb418a3 | 317 | static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *); |
f18eca82 | 318 | static const char *rs6000_mangle_fundamental_type (tree); |
b86fe7b4 | 319 | extern const struct attribute_spec rs6000_attribute_table[]; |
a2369ed3 DJ |
320 | static void rs6000_set_default_type_attributes (tree); |
321 | static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT); | |
322 | static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT); | |
b20a9cca AM |
323 | static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, |
324 | tree); | |
a2369ed3 | 325 | static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT); |
c6e8c921 | 326 | static bool rs6000_return_in_memory (tree, tree); |
a2369ed3 | 327 | static void rs6000_file_start (void); |
7c262518 | 328 | #if TARGET_ELF |
a2369ed3 DJ |
329 | static unsigned int rs6000_elf_section_type_flags (tree, const char *, int); |
330 | static void rs6000_elf_asm_out_constructor (rtx, int); | |
331 | static void rs6000_elf_asm_out_destructor (rtx, int); | |
332 | static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT); | |
333 | static void rs6000_elf_unique_section (tree, int); | |
334 | static void rs6000_elf_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 335 | unsigned HOST_WIDE_INT); |
a56d7372 | 336 | static void rs6000_elf_encode_section_info (tree, rtx, int) |
0e5dbd9b | 337 | ATTRIBUTE_UNUSED; |
a2369ed3 | 338 | static bool rs6000_elf_in_small_data_p (tree); |
7c262518 | 339 | #endif |
cbaaba19 | 340 | #if TARGET_XCOFF |
a2369ed3 DJ |
341 | static void rs6000_xcoff_asm_globalize_label (FILE *, const char *); |
342 | static void rs6000_xcoff_asm_named_section (const char *, unsigned int); | |
343 | static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT); | |
344 | static void rs6000_xcoff_unique_section (tree, int); | |
345 | static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 346 | unsigned HOST_WIDE_INT); |
a2369ed3 DJ |
347 | static const char * rs6000_xcoff_strip_name_encoding (const char *); |
348 | static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int); | |
349 | static void rs6000_xcoff_file_start (void); | |
350 | static void rs6000_xcoff_file_end (void); | |
f1384257 AM |
351 | #endif |
352 | #if TARGET_MACHO | |
a2369ed3 | 353 | static bool rs6000_binds_local_p (tree); |
f1384257 | 354 | #endif |
a2369ed3 DJ |
355 | static int rs6000_use_dfa_pipeline_interface (void); |
356 | static int rs6000_variable_issue (FILE *, int, rtx, int); | |
357 | static bool rs6000_rtx_costs (rtx, int, int, int *); | |
358 | static int rs6000_adjust_cost (rtx, rtx, rtx, int); | |
cbe26ab8 | 359 | static bool is_microcoded_insn (rtx); |
79ae11c4 | 360 | static int is_dispatch_slot_restricted (rtx); |
cbe26ab8 DN |
361 | static bool is_cracked_insn (rtx); |
362 | static bool is_branch_slot_insn (rtx); | |
a2369ed3 DJ |
363 | static int rs6000_adjust_priority (rtx, int); |
364 | static int rs6000_issue_rate (void); | |
569fa502 | 365 | static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int); |
cbe26ab8 DN |
366 | static rtx get_next_active_insn (rtx, rtx); |
367 | static bool insn_terminates_group_p (rtx , enum group_termination); | |
368 | static bool is_costly_group (rtx *, rtx); | |
369 | static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *); | |
370 | static int redefine_groups (FILE *, int, rtx, rtx); | |
371 | static int pad_groups (FILE *, int, rtx, rtx); | |
372 | static void rs6000_sched_finish (FILE *, int); | |
a2369ed3 DJ |
373 | static int rs6000_use_sched_lookahead (void); |
374 | ||
375 | static void rs6000_init_builtins (void); | |
376 | static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx); | |
377 | static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx); | |
378 | static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx); | |
379 | static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int); | |
380 | static void altivec_init_builtins (void); | |
381 | static void rs6000_common_init_builtins (void); | |
c15c90bb | 382 | static void rs6000_init_libfuncs (void); |
a2369ed3 | 383 | |
b20a9cca AM |
384 | static void enable_mask_for_builtins (struct builtin_description *, int, |
385 | enum rs6000_builtins, | |
386 | enum rs6000_builtins); | |
7c62e993 | 387 | static tree build_opaque_vector_type (tree, int); |
a2369ed3 DJ |
388 | static void spe_init_builtins (void); |
389 | static rtx spe_expand_builtin (tree, rtx, bool *); | |
61bea3b0 | 390 | static rtx spe_expand_stv_builtin (enum insn_code, tree); |
a2369ed3 DJ |
391 | static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx); |
392 | static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx); | |
393 | static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx); | |
d1d0c603 JJ |
394 | static rs6000_stack_t *rs6000_stack_info (void); |
395 | static void debug_stack_info (rs6000_stack_t *); | |
a2369ed3 DJ |
396 | |
397 | static rtx altivec_expand_builtin (tree, rtx, bool *); | |
398 | static rtx altivec_expand_ld_builtin (tree, rtx, bool *); | |
399 | static rtx altivec_expand_st_builtin (tree, rtx, bool *); | |
400 | static rtx altivec_expand_dst_builtin (tree, rtx, bool *); | |
401 | static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx); | |
402 | static rtx altivec_expand_predicate_builtin (enum insn_code, | |
403 | const char *, tree, rtx); | |
b4a62fa0 | 404 | static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx); |
a2369ed3 DJ |
405 | static rtx altivec_expand_stv_builtin (enum insn_code, tree); |
406 | static void rs6000_parse_abi_options (void); | |
407 | static void rs6000_parse_alignment_option (void); | |
408 | static void rs6000_parse_tls_size_option (void); | |
5da702b1 | 409 | static void rs6000_parse_yes_no_option (const char *, const char *, int *); |
a2369ed3 DJ |
410 | static int first_altivec_reg_to_save (void); |
411 | static unsigned int compute_vrsave_mask (void); | |
412 | static void is_altivec_return_reg (rtx, void *); | |
413 | static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int); | |
414 | int easy_vector_constant (rtx, enum machine_mode); | |
415 | static int easy_vector_same (rtx, enum machine_mode); | |
452a7d36 | 416 | static int easy_vector_splat_const (int, enum machine_mode); |
a2369ed3 DJ |
417 | static bool is_ev64_opaque_type (tree); |
418 | static rtx rs6000_dwarf_register_span (rtx); | |
419 | static rtx rs6000_legitimize_tls_address (rtx, enum tls_model); | |
420 | static rtx rs6000_tls_get_addr (void); | |
421 | static rtx rs6000_got_sym (void); | |
422 | static inline int rs6000_tls_symbol_ref_1 (rtx *, void *); | |
423 | static const char *rs6000_get_some_local_dynamic_name (void); | |
424 | static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *); | |
ded9bf77 | 425 | static rtx rs6000_complex_function_value (enum machine_mode); |
b20a9cca | 426 | static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *, |
a2369ed3 | 427 | enum machine_mode, tree); |
b78d48dd FJ |
428 | static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *, |
429 | enum machine_mode, tree, int); | |
b1917422 | 430 | static void rs6000_move_block_from_reg (int regno, rtx x, int nregs); |
c6e8c921 GK |
431 | static void setup_incoming_varargs (CUMULATIVE_ARGS *, |
432 | enum machine_mode, tree, | |
433 | int *, int); | |
efdba735 SH |
434 | #if TARGET_MACHO |
435 | static void macho_branch_islands (void); | |
436 | static void add_compiler_branch_island (tree, tree, int); | |
437 | static int no_previous_def (tree function_name); | |
438 | static tree get_prev_label (tree function_name); | |
439 | #endif | |
440 | ||
c35d187f | 441 | static tree rs6000_build_builtin_va_list (void); |
17211ab5 GK |
442 | |
443 | /* Hash table stuff for keeping track of TOC entries. */ | |
444 | ||
445 | struct toc_hash_struct GTY(()) | |
446 | { | |
447 | /* `key' will satisfy CONSTANT_P; in fact, it will satisfy | |
448 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */ | |
449 | rtx key; | |
450 | enum machine_mode key_mode; | |
451 | int labelno; | |
452 | }; | |
453 | ||
454 | static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table; | |
c81bebd7 MM |
455 | \f |
456 | /* Default register names. */ | |
457 | char rs6000_reg_names[][8] = | |
458 | { | |
802a0058 MM |
459 | "0", "1", "2", "3", "4", "5", "6", "7", |
460 | "8", "9", "10", "11", "12", "13", "14", "15", | |
461 | "16", "17", "18", "19", "20", "21", "22", "23", | |
462 | "24", "25", "26", "27", "28", "29", "30", "31", | |
463 | "0", "1", "2", "3", "4", "5", "6", "7", | |
464 | "8", "9", "10", "11", "12", "13", "14", "15", | |
465 | "16", "17", "18", "19", "20", "21", "22", "23", | |
466 | "24", "25", "26", "27", "28", "29", "30", "31", | |
467 | "mq", "lr", "ctr","ap", | |
468 | "0", "1", "2", "3", "4", "5", "6", "7", | |
0ac081f6 AH |
469 | "xer", |
470 | /* AltiVec registers. */ | |
0cd5e3a1 AH |
471 | "0", "1", "2", "3", "4", "5", "6", "7", |
472 | "8", "9", "10", "11", "12", "13", "14", "15", | |
473 | "16", "17", "18", "19", "20", "21", "22", "23", | |
474 | "24", "25", "26", "27", "28", "29", "30", "31", | |
59a4c851 AH |
475 | "vrsave", "vscr", |
476 | /* SPE registers. */ | |
477 | "spe_acc", "spefscr" | |
c81bebd7 MM |
478 | }; |
479 | ||
480 | #ifdef TARGET_REGNAMES | |
8b60264b | 481 | static const char alt_reg_names[][8] = |
c81bebd7 | 482 | { |
802a0058 MM |
483 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
484 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
485 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
486 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
487 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
488 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
489 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
490 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
491 | "mq", "lr", "ctr", "ap", | |
492 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
0ac081f6 | 493 | "xer", |
59a4c851 | 494 | /* AltiVec registers. */ |
0ac081f6 | 495 | "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7", |
59a4c851 AH |
496 | "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15", |
497 | "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23", | |
498 | "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31", | |
499 | "vrsave", "vscr", | |
500 | /* SPE registers. */ | |
501 | "spe_acc", "spefscr" | |
c81bebd7 MM |
502 | }; |
503 | #endif | |
9878760c | 504 | \f |
daf11973 MM |
505 | #ifndef MASK_STRICT_ALIGN |
506 | #define MASK_STRICT_ALIGN 0 | |
507 | #endif | |
ffcfcb5f AM |
508 | #ifndef TARGET_PROFILE_KERNEL |
509 | #define TARGET_PROFILE_KERNEL 0 | |
510 | #endif | |
3961e8fe RH |
511 | |
512 | /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */ | |
513 | #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO)) | |
c4501e62 JJ |
514 | |
515 | /* Return 1 for a symbol ref for a thread-local storage symbol. */ | |
516 | #define RS6000_SYMBOL_REF_TLS_P(RTX) \ | |
517 | (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0) | |
672a6f42 NB |
518 | \f |
519 | /* Initialize the GCC target structure. */ | |
91d231cb JM |
520 | #undef TARGET_ATTRIBUTE_TABLE |
521 | #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table | |
a5c76ee6 ZW |
522 | #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
523 | #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes | |
daf11973 | 524 | |
301d03af RS |
525 | #undef TARGET_ASM_ALIGNED_DI_OP |
526 | #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP | |
527 | ||
528 | /* Default unaligned ops are only provided for ELF. Find the ops needed | |
529 | for non-ELF systems. */ | |
530 | #ifndef OBJECT_FORMAT_ELF | |
cbaaba19 | 531 | #if TARGET_XCOFF |
ae6c1efd | 532 | /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on |
301d03af RS |
533 | 64-bit targets. */ |
534 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
535 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2," | |
536 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
537 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4," | |
538 | #undef TARGET_ASM_UNALIGNED_DI_OP | |
539 | #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8," | |
540 | #else | |
541 | /* For Darwin. */ | |
542 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
543 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" | |
544 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
545 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" | |
546 | #endif | |
547 | #endif | |
548 | ||
549 | /* This hook deals with fixups for relocatable code and DI-mode objects | |
550 | in 64-bit code. */ | |
551 | #undef TARGET_ASM_INTEGER | |
552 | #define TARGET_ASM_INTEGER rs6000_assemble_integer | |
553 | ||
93638d7a AM |
554 | #ifdef HAVE_GAS_HIDDEN |
555 | #undef TARGET_ASM_ASSEMBLE_VISIBILITY | |
556 | #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility | |
557 | #endif | |
558 | ||
c4501e62 JJ |
559 | #undef TARGET_HAVE_TLS |
560 | #define TARGET_HAVE_TLS HAVE_AS_TLS | |
561 | ||
562 | #undef TARGET_CANNOT_FORCE_CONST_MEM | |
563 | #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p | |
564 | ||
08c148a8 NB |
565 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
566 | #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue | |
567 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
568 | #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue | |
569 | ||
b54cf83a DE |
570 | #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE |
571 | #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface | |
b54cf83a DE |
572 | #undef TARGET_SCHED_VARIABLE_ISSUE |
573 | #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue | |
574 | ||
c237e94a ZW |
575 | #undef TARGET_SCHED_ISSUE_RATE |
576 | #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate | |
577 | #undef TARGET_SCHED_ADJUST_COST | |
578 | #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost | |
579 | #undef TARGET_SCHED_ADJUST_PRIORITY | |
580 | #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority | |
569fa502 DN |
581 | #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE |
582 | #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence | |
cbe26ab8 DN |
583 | #undef TARGET_SCHED_FINISH |
584 | #define TARGET_SCHED_FINISH rs6000_sched_finish | |
c237e94a | 585 | |
be12c2b0 VM |
586 | #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD |
587 | #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead | |
588 | ||
0ac081f6 AH |
589 | #undef TARGET_INIT_BUILTINS |
590 | #define TARGET_INIT_BUILTINS rs6000_init_builtins | |
591 | ||
592 | #undef TARGET_EXPAND_BUILTIN | |
593 | #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin | |
594 | ||
f18eca82 ZL |
595 | #undef TARGET_MANGLE_FUNDAMENTAL_TYPE |
596 | #define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type | |
597 | ||
c15c90bb ZW |
598 | #undef TARGET_INIT_LIBFUNCS |
599 | #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs | |
600 | ||
f1384257 | 601 | #if TARGET_MACHO |
0e5dbd9b DE |
602 | #undef TARGET_BINDS_LOCAL_P |
603 | #define TARGET_BINDS_LOCAL_P rs6000_binds_local_p | |
f1384257 | 604 | #endif |
0e5dbd9b | 605 | |
3961e8fe RH |
606 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
607 | #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk | |
608 | ||
3961e8fe | 609 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
5b71a4e7 | 610 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true |
00b960c7 | 611 | |
4977bab6 ZW |
612 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
613 | #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall | |
614 | ||
3c50106f RH |
615 | #undef TARGET_RTX_COSTS |
616 | #define TARGET_RTX_COSTS rs6000_rtx_costs | |
dcefdf67 RH |
617 | #undef TARGET_ADDRESS_COST |
618 | #define TARGET_ADDRESS_COST hook_int_rtx_0 | |
3c50106f | 619 | |
c8e4f0e9 AH |
620 | #undef TARGET_VECTOR_OPAQUE_P |
621 | #define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type | |
62e1dfcf | 622 | |
96714395 AH |
623 | #undef TARGET_DWARF_REGISTER_SPAN |
624 | #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span | |
625 | ||
c6e8c921 GK |
626 | /* On rs6000, function arguments are promoted, as are function return |
627 | values. */ | |
628 | #undef TARGET_PROMOTE_FUNCTION_ARGS | |
629 | #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true | |
630 | #undef TARGET_PROMOTE_FUNCTION_RETURN | |
631 | #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true | |
632 | ||
c6e8c921 GK |
633 | #undef TARGET_RETURN_IN_MEMORY |
634 | #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory | |
635 | ||
636 | #undef TARGET_SETUP_INCOMING_VARARGS | |
637 | #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs | |
638 | ||
639 | /* Always strict argument naming on rs6000. */ | |
640 | #undef TARGET_STRICT_ARGUMENT_NAMING | |
641 | #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true | |
642 | #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED | |
643 | #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true | |
42ba5130 RH |
644 | #undef TARGET_SPLIT_COMPLEX_ARG |
645 | #define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true | |
c6e8c921 | 646 | |
c35d187f RH |
647 | #undef TARGET_BUILD_BUILTIN_VA_LIST |
648 | #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list | |
649 | ||
f6897b10 | 650 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 651 | \f |
0d1fbc8c AH |
652 | |
653 | /* Value is 1 if hard register REGNO can hold a value of machine-mode | |
654 | MODE. */ | |
655 | static int | |
656 | rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode) | |
657 | { | |
658 | /* The GPRs can hold any mode, but values bigger than one register | |
659 | cannot go past R31. */ | |
660 | if (INT_REGNO_P (regno)) | |
661 | return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1); | |
662 | ||
663 | /* The float registers can only hold floating modes and DImode. */ | |
664 | if (FP_REGNO_P (regno)) | |
665 | return | |
666 | (GET_MODE_CLASS (mode) == MODE_FLOAT | |
667 | && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1)) | |
668 | || (GET_MODE_CLASS (mode) == MODE_INT | |
669 | && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD); | |
670 | ||
671 | /* The CR register can only hold CC modes. */ | |
672 | if (CR_REGNO_P (regno)) | |
673 | return GET_MODE_CLASS (mode) == MODE_CC; | |
674 | ||
675 | if (XER_REGNO_P (regno)) | |
676 | return mode == PSImode; | |
677 | ||
678 | /* AltiVec only in AldyVec registers. */ | |
679 | if (ALTIVEC_REGNO_P (regno)) | |
680 | return ALTIVEC_VECTOR_MODE (mode); | |
681 | ||
682 | /* ...but GPRs can hold SIMD data on the SPE in one register. */ | |
683 | if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
684 | return 1; | |
685 | ||
686 | /* We cannot put TImode anywhere except general register and it must be | |
687 | able to fit within the register set. */ | |
688 | ||
689 | return GET_MODE_SIZE (mode) <= UNITS_PER_WORD; | |
690 | } | |
691 | ||
692 | /* Initialize rs6000_hard_regno_mode_ok_p table. */ | |
693 | static void | |
694 | rs6000_init_hard_regno_mode_ok (void) | |
695 | { | |
696 | int r, m; | |
697 | ||
698 | for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r) | |
699 | for (m = 0; m < NUM_MACHINE_MODES; ++m) | |
700 | if (rs6000_hard_regno_mode_ok (r, m)) | |
701 | rs6000_hard_regno_mode_ok_p[m][r] = true; | |
702 | } | |
703 | ||
5248c961 RK |
704 | /* Override command line options. Mostly we process the processor |
705 | type and sometimes adjust other TARGET_ options. */ | |
706 | ||
707 | void | |
d779d0dc | 708 | rs6000_override_options (const char *default_cpu) |
5248c961 | 709 | { |
c4d38ccb | 710 | size_t i, j; |
8e3f41e7 | 711 | struct rs6000_cpu_select *ptr; |
66188a7e | 712 | int set_masks; |
5248c961 | 713 | |
66188a7e | 714 | /* Simplifications for entries below. */ |
85638c0d | 715 | |
66188a7e GK |
716 | enum { |
717 | POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS, | |
718 | POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC | |
719 | }; | |
85638c0d | 720 | |
66188a7e GK |
721 | /* This table occasionally claims that a processor does not support |
722 | a particular feature even though it does, but the feature is slower | |
723 | than the alternative. Thus, it shouldn't be relied on as a | |
724 | complete description of the processor's support. | |
725 | ||
726 | Please keep this list in order, and don't forget to update the | |
727 | documentation in invoke.texi when adding a new processor or | |
728 | flag. */ | |
5248c961 RK |
729 | static struct ptt |
730 | { | |
8b60264b KG |
731 | const char *const name; /* Canonical processor name. */ |
732 | const enum processor_type processor; /* Processor type enum value. */ | |
733 | const int target_enable; /* Target flags to enable. */ | |
8b60264b | 734 | } const processor_target_table[] |
66188a7e | 735 | = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, |
49a0b204 | 736 | {"403", PROCESSOR_PPC403, |
66188a7e GK |
737 | POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN}, |
738 | {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
739 | {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK}, | |
740 | {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
741 | {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK}, | |
742 | {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK}, | |
5248c961 | 743 | {"601", PROCESSOR_PPC601, |
66188a7e GK |
744 | MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING}, |
745 | {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
746 | {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
747 | {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
748 | {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
749 | {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
7ddb6568 AM |
750 | {"620", PROCESSOR_PPC620, |
751 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
752 | {"630", PROCESSOR_PPC630, | |
753 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
66188a7e GK |
754 | {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, |
755 | {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK}, | |
756 | {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK}, | |
757 | {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
758 | {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
759 | {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
760 | {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
761 | {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
762 | {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
7177e720 | 763 | {"970", PROCESSOR_POWER4, |
66188a7e GK |
764 | POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64}, |
765 | {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS}, | |
766 | {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
767 | {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
768 | {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK}, | |
49ffe578 | 769 | {"G5", PROCESSOR_POWER4, |
66188a7e GK |
770 | POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64}, |
771 | {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
772 | {"power2", PROCESSOR_POWER, | |
773 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING}, | |
7ddb6568 AM |
774 | {"power3", PROCESSOR_PPC630, |
775 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
776 | {"power4", PROCESSOR_POWER4, | |
fc091c8e | 777 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64}, |
ec507f2d | 778 | {"power5", PROCESSOR_POWER5, |
fc091c8e | 779 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64}, |
66188a7e GK |
780 | {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK}, |
781 | {"powerpc64", PROCESSOR_POWERPC64, | |
782 | POWERPC_BASE_MASK | MASK_POWERPC64}, | |
783 | {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
784 | {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
785 | {"rios2", PROCESSOR_RIOS2, | |
786 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING}, | |
787 | {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
788 | {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
7ddb6568 | 789 | {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64}, |
66188a7e | 790 | }; |
5248c961 | 791 | |
ca7558fc | 792 | const size_t ptt_size = ARRAY_SIZE (processor_target_table); |
5248c961 | 793 | |
66188a7e GK |
794 | /* Some OSs don't support saving the high part of 64-bit registers on |
795 | context switch. Other OSs don't support saving Altivec registers. | |
796 | On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC | |
797 | settings; if the user wants either, the user must explicitly specify | |
798 | them and we won't interfere with the user's specification. */ | |
799 | ||
800 | enum { | |
801 | POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
802 | POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT | |
803 | | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC | |
804 | | MASK_MFCRF) | |
805 | }; | |
0d1fbc8c AH |
806 | |
807 | rs6000_init_hard_regno_mode_ok (); | |
808 | ||
66188a7e GK |
809 | set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT; |
810 | #ifdef OS_MISSING_POWERPC64 | |
811 | if (OS_MISSING_POWERPC64) | |
812 | set_masks &= ~MASK_POWERPC64; | |
813 | #endif | |
814 | #ifdef OS_MISSING_ALTIVEC | |
815 | if (OS_MISSING_ALTIVEC) | |
816 | set_masks &= ~MASK_ALTIVEC; | |
817 | #endif | |
818 | ||
957211c3 AM |
819 | /* Don't override these by the processor default if given explicitly. */ |
820 | set_masks &= ~(target_flags_explicit | |
821 | & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT)); | |
822 | ||
a4f6c312 | 823 | /* Identify the processor type. */ |
8e3f41e7 | 824 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 825 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 826 | |
b6a1cbae | 827 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 828 | { |
8e3f41e7 MM |
829 | ptr = &rs6000_select[i]; |
830 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 831 | { |
8e3f41e7 MM |
832 | for (j = 0; j < ptt_size; j++) |
833 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
834 | { | |
835 | if (ptr->set_tune_p) | |
836 | rs6000_cpu = processor_target_table[j].processor; | |
837 | ||
838 | if (ptr->set_arch_p) | |
839 | { | |
66188a7e GK |
840 | target_flags &= ~set_masks; |
841 | target_flags |= (processor_target_table[j].target_enable | |
842 | & set_masks); | |
8e3f41e7 MM |
843 | } |
844 | break; | |
845 | } | |
846 | ||
4406229e | 847 | if (j == ptt_size) |
8e3f41e7 | 848 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
849 | } |
850 | } | |
8a61d227 | 851 | |
993f19a8 | 852 | if (TARGET_E500) |
a3170dc6 AH |
853 | rs6000_isel = 1; |
854 | ||
dff9f1b6 DE |
855 | /* If we are optimizing big endian systems for space, use the load/store |
856 | multiple and string instructions. */ | |
ef792183 | 857 | if (BYTES_BIG_ENDIAN && optimize_size) |
957211c3 | 858 | target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING); |
938937d8 | 859 | |
a4f6c312 SS |
860 | /* Don't allow -mmultiple or -mstring on little endian systems |
861 | unless the cpu is a 750, because the hardware doesn't support the | |
862 | instructions used in little endian mode, and causes an alignment | |
863 | trap. The 750 does not cause an alignment trap (except when the | |
864 | target is unaligned). */ | |
bef84347 | 865 | |
b21fb038 | 866 | if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
867 | { |
868 | if (TARGET_MULTIPLE) | |
869 | { | |
870 | target_flags &= ~MASK_MULTIPLE; | |
b21fb038 | 871 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
7e69e155 MM |
872 | warning ("-mmultiple is not supported on little endian systems"); |
873 | } | |
874 | ||
875 | if (TARGET_STRING) | |
876 | { | |
877 | target_flags &= ~MASK_STRING; | |
b21fb038 | 878 | if ((target_flags_explicit & MASK_STRING) != 0) |
938937d8 | 879 | warning ("-mstring is not supported on little endian systems"); |
7e69e155 MM |
880 | } |
881 | } | |
3933e0e1 | 882 | |
38c1f2d7 MM |
883 | /* Set debug flags */ |
884 | if (rs6000_debug_name) | |
885 | { | |
bfc79d3b | 886 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 887 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 888 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 889 | rs6000_debug_stack = 1; |
bfc79d3b | 890 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
891 | rs6000_debug_arg = 1; |
892 | else | |
c725bd79 | 893 | error ("unknown -mdebug-%s switch", rs6000_debug_name); |
38c1f2d7 MM |
894 | } |
895 | ||
57ac7be9 AM |
896 | if (rs6000_traceback_name) |
897 | { | |
898 | if (! strncmp (rs6000_traceback_name, "full", 4)) | |
899 | rs6000_traceback = traceback_full; | |
900 | else if (! strncmp (rs6000_traceback_name, "part", 4)) | |
901 | rs6000_traceback = traceback_part; | |
902 | else if (! strncmp (rs6000_traceback_name, "no", 2)) | |
903 | rs6000_traceback = traceback_none; | |
904 | else | |
905 | error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'", | |
906 | rs6000_traceback_name); | |
907 | } | |
908 | ||
6fa3f289 ZW |
909 | /* Set size of long double */ |
910 | rs6000_long_double_type_size = 64; | |
911 | if (rs6000_long_double_size_string) | |
912 | { | |
913 | char *tail; | |
914 | int size = strtol (rs6000_long_double_size_string, &tail, 10); | |
915 | if (*tail != '\0' || (size != 64 && size != 128)) | |
916 | error ("Unknown switch -mlong-double-%s", | |
917 | rs6000_long_double_size_string); | |
918 | else | |
919 | rs6000_long_double_type_size = size; | |
920 | } | |
921 | ||
6d0ef01e HP |
922 | /* Set Altivec ABI as default for powerpc64 linux. */ |
923 | if (TARGET_ELF && TARGET_64BIT) | |
924 | { | |
925 | rs6000_altivec_abi = 1; | |
926 | rs6000_altivec_vrsave = 1; | |
927 | } | |
928 | ||
0ac081f6 AH |
929 | /* Handle -mabi= options. */ |
930 | rs6000_parse_abi_options (); | |
931 | ||
025d9908 KH |
932 | /* Handle -malign-XXXXX option. */ |
933 | rs6000_parse_alignment_option (); | |
934 | ||
5da702b1 AH |
935 | /* Handle generic -mFOO=YES/NO options. */ |
936 | rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string, | |
937 | &rs6000_altivec_vrsave); | |
938 | rs6000_parse_yes_no_option ("isel", rs6000_isel_string, | |
939 | &rs6000_isel); | |
940 | rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe); | |
941 | rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string, | |
942 | &rs6000_float_gprs); | |
993f19a8 | 943 | |
c4501e62 JJ |
944 | /* Handle -mtls-size option. */ |
945 | rs6000_parse_tls_size_option (); | |
946 | ||
a7ae18e2 AH |
947 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
948 | SUBTARGET_OVERRIDE_OPTIONS; | |
949 | #endif | |
950 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS | |
951 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
952 | #endif | |
953 | ||
5da702b1 AH |
954 | if (TARGET_E500) |
955 | { | |
e4463bf1 AH |
956 | if (TARGET_ALTIVEC) |
957 | error ("AltiVec and E500 instructions cannot coexist"); | |
958 | ||
5da702b1 AH |
959 | /* The e500 does not have string instructions, and we set |
960 | MASK_STRING above when optimizing for size. */ | |
961 | if ((target_flags & MASK_STRING) != 0) | |
962 | target_flags = target_flags & ~MASK_STRING; | |
b6e59a3a AH |
963 | |
964 | /* No SPE means 64-bit long doubles, even if an E500. */ | |
965 | if (rs6000_spe_string != 0 | |
966 | && !strcmp (rs6000_spe_string, "no")) | |
967 | rs6000_long_double_type_size = 64; | |
5da702b1 AH |
968 | } |
969 | else if (rs6000_select[1].string != NULL) | |
970 | { | |
971 | /* For the powerpc-eabispe configuration, we set all these by | |
972 | default, so let's unset them if we manually set another | |
973 | CPU that is not the E500. */ | |
974 | if (rs6000_abi_string == 0) | |
975 | rs6000_spe_abi = 0; | |
976 | if (rs6000_spe_string == 0) | |
977 | rs6000_spe = 0; | |
978 | if (rs6000_float_gprs_string == 0) | |
979 | rs6000_float_gprs = 0; | |
980 | if (rs6000_isel_string == 0) | |
981 | rs6000_isel = 0; | |
b6e59a3a AH |
982 | if (rs6000_long_double_size_string == 0) |
983 | rs6000_long_double_type_size = 64; | |
5da702b1 | 984 | } |
b5044283 | 985 | |
ec507f2d DE |
986 | rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4 |
987 | && rs6000_cpu != PROCESSOR_POWER5); | |
988 | rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4 | |
989 | || rs6000_cpu == PROCESSOR_POWER5); | |
990 | ||
a5c76ee6 ZW |
991 | /* Handle -m(no-)longcall option. This is a bit of a cheap hack, |
992 | using TARGET_OPTIONS to handle a toggle switch, but we're out of | |
993 | bits in target_flags so TARGET_SWITCHES cannot be used. | |
994 | Assumption here is that rs6000_longcall_switch points into the | |
995 | text of the complete option, rather than being a copy, so we can | |
996 | scan back for the presence or absence of the no- modifier. */ | |
997 | if (rs6000_longcall_switch) | |
998 | { | |
999 | const char *base = rs6000_longcall_switch; | |
1000 | while (base[-1] != 'm') base--; | |
1001 | ||
1002 | if (*rs6000_longcall_switch != '\0') | |
1003 | error ("invalid option `%s'", base); | |
1004 | rs6000_default_long_calls = (base[0] != 'n'); | |
1005 | } | |
1006 | ||
8bb418a3 ZL |
1007 | /* Handle -m(no-)warn-altivec-long similarly. */ |
1008 | if (rs6000_warn_altivec_long_switch) | |
1009 | { | |
1010 | const char *base = rs6000_warn_altivec_long_switch; | |
1011 | while (base[-1] != 'm') base--; | |
1012 | ||
1013 | if (*rs6000_warn_altivec_long_switch != '\0') | |
1014 | error ("invalid option `%s'", base); | |
1015 | rs6000_warn_altivec_long = (base[0] != 'n'); | |
1016 | } | |
1017 | ||
cbe26ab8 | 1018 | /* Handle -mprioritize-restricted-insns option. */ |
ec507f2d DE |
1019 | rs6000_sched_restricted_insns_priority |
1020 | = (rs6000_sched_groups ? 1 : 0); | |
79ae11c4 DN |
1021 | if (rs6000_sched_restricted_insns_priority_str) |
1022 | rs6000_sched_restricted_insns_priority = | |
1023 | atoi (rs6000_sched_restricted_insns_priority_str); | |
1024 | ||
569fa502 | 1025 | /* Handle -msched-costly-dep option. */ |
ec507f2d DE |
1026 | rs6000_sched_costly_dep |
1027 | = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly); | |
569fa502 DN |
1028 | if (rs6000_sched_costly_dep_str) |
1029 | { | |
1030 | if (! strcmp (rs6000_sched_costly_dep_str, "no")) | |
1031 | rs6000_sched_costly_dep = no_dep_costly; | |
1032 | else if (! strcmp (rs6000_sched_costly_dep_str, "all")) | |
1033 | rs6000_sched_costly_dep = all_deps_costly; | |
1034 | else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load")) | |
1035 | rs6000_sched_costly_dep = true_store_to_load_dep_costly; | |
1036 | else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load")) | |
1037 | rs6000_sched_costly_dep = store_to_load_dep_costly; | |
cbe26ab8 DN |
1038 | else |
1039 | rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str); | |
1040 | } | |
1041 | ||
1042 | /* Handle -minsert-sched-nops option. */ | |
ec507f2d DE |
1043 | rs6000_sched_insert_nops |
1044 | = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none); | |
cbe26ab8 DN |
1045 | if (rs6000_sched_insert_nops_str) |
1046 | { | |
1047 | if (! strcmp (rs6000_sched_insert_nops_str, "no")) | |
1048 | rs6000_sched_insert_nops = sched_finish_none; | |
1049 | else if (! strcmp (rs6000_sched_insert_nops_str, "pad")) | |
1050 | rs6000_sched_insert_nops = sched_finish_pad_groups; | |
1051 | else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact")) | |
1052 | rs6000_sched_insert_nops = sched_finish_regroup_exact; | |
1053 | else | |
1054 | rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str); | |
569fa502 DN |
1055 | } |
1056 | ||
c81bebd7 | 1057 | #ifdef TARGET_REGNAMES |
a4f6c312 SS |
1058 | /* If the user desires alternate register names, copy in the |
1059 | alternate names now. */ | |
c81bebd7 | 1060 | if (TARGET_REGNAMES) |
4e135bdd | 1061 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
1062 | #endif |
1063 | ||
6fa3f289 ZW |
1064 | /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined. |
1065 | If -maix-struct-return or -msvr4-struct-return was explicitly | |
1066 | used, don't override with the ABI default. */ | |
b21fb038 | 1067 | if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0) |
6fa3f289 ZW |
1068 | { |
1069 | if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET) | |
1070 | target_flags = (target_flags & ~MASK_AIX_STRUCT_RET); | |
1071 | else | |
1072 | target_flags |= MASK_AIX_STRUCT_RET; | |
1073 | } | |
1074 | ||
fcce224d DE |
1075 | if (TARGET_LONG_DOUBLE_128 |
1076 | && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)) | |
70a01792 | 1077 | REAL_MODE_FORMAT (TFmode) = &ibm_extended_format; |
fcce224d | 1078 | |
9ebbca7d GK |
1079 | /* Allocate an alias set for register saves & restores from stack. */ |
1080 | rs6000_sr_alias_set = new_alias_set (); | |
1081 | ||
1082 | if (TARGET_TOC) | |
1083 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); | |
71f123ca | 1084 | |
301d03af RS |
1085 | /* We can only guarantee the availability of DI pseudo-ops when |
1086 | assembling for 64-bit targets. */ | |
ae6c1efd | 1087 | if (!TARGET_64BIT) |
301d03af RS |
1088 | { |
1089 | targetm.asm_out.aligned_op.di = NULL; | |
1090 | targetm.asm_out.unaligned_op.di = NULL; | |
1091 | } | |
1092 | ||
2792d578 DE |
1093 | /* Set maximum branch target alignment at two instructions, eight bytes. */ |
1094 | align_jumps_max_skip = 8; | |
1095 | align_loops_max_skip = 8; | |
1096 | ||
71f123ca FS |
1097 | /* Arrange to save and restore machine status around nested functions. */ |
1098 | init_machine_status = rs6000_init_machine_status; | |
42ba5130 RH |
1099 | |
1100 | /* We should always be splitting complex arguments, but we can't break | |
1101 | Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */ | |
1102 | if (DEFAULT_ABI != ABI_AIX) | |
1103 | targetm.calls.split_complex_arg = NULL; | |
5248c961 | 1104 | } |
5accd822 | 1105 | |
5da702b1 AH |
1106 | /* Handle generic options of the form -mfoo=yes/no. |
1107 | NAME is the option name. | |
1108 | VALUE is the option value. | |
1109 | FLAG is the pointer to the flag where to store a 1 or 0, depending on | |
1110 | whether the option value is 'yes' or 'no' respectively. */ | |
993f19a8 | 1111 | static void |
5da702b1 | 1112 | rs6000_parse_yes_no_option (const char *name, const char *value, int *flag) |
993f19a8 | 1113 | { |
5da702b1 | 1114 | if (value == 0) |
993f19a8 | 1115 | return; |
5da702b1 AH |
1116 | else if (!strcmp (value, "yes")) |
1117 | *flag = 1; | |
1118 | else if (!strcmp (value, "no")) | |
1119 | *flag = 0; | |
08b57fb3 | 1120 | else |
5da702b1 | 1121 | error ("unknown -m%s= option specified: '%s'", name, value); |
08b57fb3 AH |
1122 | } |
1123 | ||
0ac081f6 | 1124 | /* Handle -mabi= options. */ |
00b960c7 | 1125 | static void |
863d938c | 1126 | rs6000_parse_abi_options (void) |
0ac081f6 AH |
1127 | { |
1128 | if (rs6000_abi_string == 0) | |
1129 | return; | |
1130 | else if (! strcmp (rs6000_abi_string, "altivec")) | |
5cc73f91 AH |
1131 | { |
1132 | rs6000_altivec_abi = 1; | |
1133 | rs6000_spe_abi = 0; | |
1134 | } | |
76a773f3 AH |
1135 | else if (! strcmp (rs6000_abi_string, "no-altivec")) |
1136 | rs6000_altivec_abi = 0; | |
a3170dc6 | 1137 | else if (! strcmp (rs6000_abi_string, "spe")) |
01f4962d NS |
1138 | { |
1139 | rs6000_spe_abi = 1; | |
5cc73f91 | 1140 | rs6000_altivec_abi = 0; |
01f4962d NS |
1141 | if (!TARGET_SPE_ABI) |
1142 | error ("not configured for ABI: '%s'", rs6000_abi_string); | |
1143 | } | |
1144 | ||
a3170dc6 AH |
1145 | else if (! strcmp (rs6000_abi_string, "no-spe")) |
1146 | rs6000_spe_abi = 0; | |
0ac081f6 | 1147 | else |
c725bd79 | 1148 | error ("unknown ABI specified: '%s'", rs6000_abi_string); |
0ac081f6 AH |
1149 | } |
1150 | ||
025d9908 KH |
1151 | /* Handle -malign-XXXXXX options. */ |
1152 | static void | |
863d938c | 1153 | rs6000_parse_alignment_option (void) |
025d9908 | 1154 | { |
b20a9cca AM |
1155 | if (rs6000_alignment_string == 0) |
1156 | return; | |
1157 | else if (! strcmp (rs6000_alignment_string, "power")) | |
025d9908 KH |
1158 | rs6000_alignment_flags = MASK_ALIGN_POWER; |
1159 | else if (! strcmp (rs6000_alignment_string, "natural")) | |
1160 | rs6000_alignment_flags = MASK_ALIGN_NATURAL; | |
1161 | else | |
1162 | error ("unknown -malign-XXXXX option specified: '%s'", | |
1163 | rs6000_alignment_string); | |
1164 | } | |
1165 | ||
c4501e62 JJ |
1166 | /* Validate and record the size specified with the -mtls-size option. */ |
1167 | ||
1168 | static void | |
863d938c | 1169 | rs6000_parse_tls_size_option (void) |
c4501e62 JJ |
1170 | { |
1171 | if (rs6000_tls_size_string == 0) | |
1172 | return; | |
1173 | else if (strcmp (rs6000_tls_size_string, "16") == 0) | |
1174 | rs6000_tls_size = 16; | |
1175 | else if (strcmp (rs6000_tls_size_string, "32") == 0) | |
1176 | rs6000_tls_size = 32; | |
1177 | else if (strcmp (rs6000_tls_size_string, "64") == 0) | |
1178 | rs6000_tls_size = 64; | |
1179 | else | |
1180 | error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string); | |
1181 | } | |
1182 | ||
5accd822 | 1183 | void |
a2369ed3 | 1184 | optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED) |
5accd822 | 1185 | { |
5accd822 | 1186 | } |
3cfa4909 MM |
1187 | \f |
1188 | /* Do anything needed at the start of the asm file. */ | |
1189 | ||
1bc7c5b6 | 1190 | static void |
863d938c | 1191 | rs6000_file_start (void) |
3cfa4909 | 1192 | { |
c4d38ccb | 1193 | size_t i; |
3cfa4909 | 1194 | char buffer[80]; |
d330fd93 | 1195 | const char *start = buffer; |
3cfa4909 | 1196 | struct rs6000_cpu_select *ptr; |
1bc7c5b6 ZW |
1197 | const char *default_cpu = TARGET_CPU_DEFAULT; |
1198 | FILE *file = asm_out_file; | |
1199 | ||
1200 | default_file_start (); | |
1201 | ||
1202 | #ifdef TARGET_BI_ARCH | |
1203 | if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT) | |
1204 | default_cpu = 0; | |
1205 | #endif | |
3cfa4909 MM |
1206 | |
1207 | if (flag_verbose_asm) | |
1208 | { | |
1209 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
1210 | rs6000_select[0].string = default_cpu; | |
1211 | ||
b6a1cbae | 1212 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
1213 | { |
1214 | ptr = &rs6000_select[i]; | |
1215 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
1216 | { | |
1217 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
1218 | start = ""; | |
1219 | } | |
1220 | } | |
1221 | ||
b91da81f | 1222 | #ifdef USING_ELFOS_H |
3cfa4909 MM |
1223 | switch (rs6000_sdata) |
1224 | { | |
1225 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
1226 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
1227 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
1228 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
1229 | } | |
1230 | ||
1231 | if (rs6000_sdata && g_switch_value) | |
1232 | { | |
307b599c MK |
1233 | fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start, |
1234 | g_switch_value); | |
3cfa4909 MM |
1235 | start = ""; |
1236 | } | |
1237 | #endif | |
1238 | ||
1239 | if (*start == '\0') | |
949ea356 | 1240 | putc ('\n', file); |
3cfa4909 MM |
1241 | } |
1242 | } | |
5248c961 | 1243 | \f |
a0ab749a | 1244 | /* Return nonzero if this function is known to have a null epilogue. */ |
9878760c RK |
1245 | |
1246 | int | |
863d938c | 1247 | direct_return (void) |
9878760c | 1248 | { |
4697a36c MM |
1249 | if (reload_completed) |
1250 | { | |
1251 | rs6000_stack_t *info = rs6000_stack_info (); | |
1252 | ||
1253 | if (info->first_gp_reg_save == 32 | |
1254 | && info->first_fp_reg_save == 64 | |
00b960c7 | 1255 | && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1 |
c81fc13e DE |
1256 | && ! info->lr_save_p |
1257 | && ! info->cr_save_p | |
00b960c7 | 1258 | && info->vrsave_mask == 0 |
c81fc13e | 1259 | && ! info->push_p) |
4697a36c MM |
1260 | return 1; |
1261 | } | |
1262 | ||
1263 | return 0; | |
9878760c RK |
1264 | } |
1265 | ||
1266 | /* Returns 1 always. */ | |
1267 | ||
1268 | int | |
a2369ed3 DJ |
1269 | any_operand (rtx op ATTRIBUTE_UNUSED, |
1270 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
9878760c RK |
1271 | { |
1272 | return 1; | |
1273 | } | |
1274 | ||
a4f6c312 | 1275 | /* Returns 1 if op is the count register. */ |
38c1f2d7 | 1276 | int |
a2369ed3 | 1277 | count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
b6c9286a MM |
1278 | { |
1279 | if (GET_CODE (op) != REG) | |
1280 | return 0; | |
1281 | ||
1282 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
1283 | return 1; | |
1284 | ||
1285 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
1286 | return 1; | |
1287 | ||
1288 | return 0; | |
1289 | } | |
1290 | ||
0ec4e2a8 AH |
1291 | /* Returns 1 if op is an altivec register. */ |
1292 | int | |
a2369ed3 | 1293 | altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ec4e2a8 AH |
1294 | { |
1295 | ||
1296 | return (register_operand (op, mode) | |
1297 | && (GET_CODE (op) != REG | |
1298 | || REGNO (op) > FIRST_PSEUDO_REGISTER | |
1299 | || ALTIVEC_REGNO_P (REGNO (op)))); | |
1300 | } | |
1301 | ||
38c1f2d7 | 1302 | int |
a2369ed3 | 1303 | xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
802a0058 MM |
1304 | { |
1305 | if (GET_CODE (op) != REG) | |
1306 | return 0; | |
1307 | ||
9ebbca7d | 1308 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
1309 | return 1; |
1310 | ||
802a0058 MM |
1311 | return 0; |
1312 | } | |
1313 | ||
c859cda6 | 1314 | /* Return 1 if OP is a signed 8-bit constant. Int multiplication |
6f317ef3 | 1315 | by such constants completes more quickly. */ |
c859cda6 DJ |
1316 | |
1317 | int | |
a2369ed3 | 1318 | s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
c859cda6 DJ |
1319 | { |
1320 | return ( GET_CODE (op) == CONST_INT | |
1321 | && (INTVAL (op) >= -128 && INTVAL (op) <= 127)); | |
1322 | } | |
1323 | ||
9878760c RK |
1324 | /* Return 1 if OP is a constant that can fit in a D field. */ |
1325 | ||
1326 | int | |
a2369ed3 | 1327 | short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1328 | { |
5f59ecb7 DE |
1329 | return (GET_CODE (op) == CONST_INT |
1330 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
1331 | } |
1332 | ||
5519a4f9 | 1333 | /* Similar for an unsigned D field. */ |
9878760c RK |
1334 | |
1335 | int | |
a2369ed3 | 1336 | u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1337 | { |
19684119 | 1338 | return (GET_CODE (op) == CONST_INT |
c1f11548 | 1339 | && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K')); |
9878760c RK |
1340 | } |
1341 | ||
dcfedcd0 RK |
1342 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
1343 | ||
1344 | int | |
a2369ed3 | 1345 | non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
1346 | { |
1347 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 1348 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
1349 | } |
1350 | ||
2bfcf297 DB |
1351 | /* Returns 1 if OP is a CONST_INT that is a positive value |
1352 | and an exact power of 2. */ | |
1353 | ||
1354 | int | |
a2369ed3 | 1355 | exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2bfcf297 DB |
1356 | { |
1357 | return (GET_CODE (op) == CONST_INT | |
1358 | && INTVAL (op) > 0 | |
1359 | && exact_log2 (INTVAL (op)) >= 0); | |
1360 | } | |
1361 | ||
9878760c RK |
1362 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
1363 | ctr, or lr). */ | |
1364 | ||
1365 | int | |
a2369ed3 | 1366 | gpc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1367 | { |
1368 | return (register_operand (op, mode) | |
802a0058 | 1369 | && (GET_CODE (op) != REG |
9ebbca7d GK |
1370 | || (REGNO (op) >= ARG_POINTER_REGNUM |
1371 | && !XER_REGNO_P (REGNO (op))) | |
1372 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
1373 | } |
1374 | ||
1375 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
1376 | CR field. */ | |
1377 | ||
1378 | int | |
a2369ed3 | 1379 | cc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1380 | { |
1381 | return (register_operand (op, mode) | |
1382 | && (GET_CODE (op) != REG | |
1383 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1384 | || CR_REGNO_P (REGNO (op)))); | |
1385 | } | |
1386 | ||
815cdc52 MM |
1387 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
1388 | CR field that isn't CR0. */ | |
1389 | ||
1390 | int | |
a2369ed3 | 1391 | cc_reg_not_cr0_operand (rtx op, enum machine_mode mode) |
815cdc52 MM |
1392 | { |
1393 | return (register_operand (op, mode) | |
1394 | && (GET_CODE (op) != REG | |
1395 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1396 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
1397 | } | |
1398 | ||
a4f6c312 SS |
1399 | /* Returns 1 if OP is either a constant integer valid for a D-field or |
1400 | a non-special register. If a register, it must be in the proper | |
1401 | mode unless MODE is VOIDmode. */ | |
9878760c RK |
1402 | |
1403 | int | |
a2369ed3 | 1404 | reg_or_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1405 | { |
f5a28898 | 1406 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1407 | } |
1408 | ||
a4f6c312 | 1409 | /* Similar, except check if the negation of the constant would be |
42f806e5 AM |
1410 | valid for a D-field. Don't allow a constant zero, since all the |
1411 | patterns that call this predicate use "addic r1,r2,-constant" on | |
1412 | a constant value to set a carry when r2 is greater or equal to | |
1413 | "constant". That doesn't work for zero. */ | |
9878760c RK |
1414 | |
1415 | int | |
a2369ed3 | 1416 | reg_or_neg_short_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1417 | { |
1418 | if (GET_CODE (op) == CONST_INT) | |
42f806e5 | 1419 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0; |
9878760c | 1420 | |
cd2b37d9 | 1421 | return gpc_reg_operand (op, mode); |
9878760c RK |
1422 | } |
1423 | ||
768070a0 TR |
1424 | /* Returns 1 if OP is either a constant integer valid for a DS-field or |
1425 | a non-special register. If a register, it must be in the proper | |
1426 | mode unless MODE is VOIDmode. */ | |
1427 | ||
1428 | int | |
a2369ed3 | 1429 | reg_or_aligned_short_operand (rtx op, enum machine_mode mode) |
768070a0 TR |
1430 | { |
1431 | if (gpc_reg_operand (op, mode)) | |
1432 | return 1; | |
1433 | else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3)) | |
1434 | return 1; | |
1435 | ||
1436 | return 0; | |
1437 | } | |
1438 | ||
1439 | ||
a4f6c312 SS |
1440 | /* Return 1 if the operand is either a register or an integer whose |
1441 | high-order 16 bits are zero. */ | |
9878760c RK |
1442 | |
1443 | int | |
a2369ed3 | 1444 | reg_or_u_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1445 | { |
e675f625 | 1446 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1447 | } |
1448 | ||
1449 | /* Return 1 is the operand is either a non-special register or ANY | |
1450 | constant integer. */ | |
1451 | ||
1452 | int | |
a2369ed3 | 1453 | reg_or_cint_operand (rtx op, enum machine_mode mode) |
9878760c | 1454 | { |
a4f6c312 | 1455 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
f6bf7de2 DE |
1456 | } |
1457 | ||
1458 | /* Return 1 is the operand is either a non-special register or ANY | |
1459 | 32-bit signed constant integer. */ | |
1460 | ||
1461 | int | |
a2369ed3 | 1462 | reg_or_arith_cint_operand (rtx op, enum machine_mode mode) |
f6bf7de2 | 1463 | { |
a4f6c312 SS |
1464 | return (gpc_reg_operand (op, mode) |
1465 | || (GET_CODE (op) == CONST_INT | |
f6bf7de2 | 1466 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
1467 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) |
1468 | < (unsigned HOST_WIDE_INT) 0x100000000ll) | |
f6bf7de2 | 1469 | #endif |
a4f6c312 | 1470 | )); |
9878760c RK |
1471 | } |
1472 | ||
2bfcf297 DB |
1473 | /* Return 1 is the operand is either a non-special register or a 32-bit |
1474 | signed constant integer valid for 64-bit addition. */ | |
1475 | ||
1476 | int | |
a2369ed3 | 1477 | reg_or_add_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1478 | { |
a4f6c312 SS |
1479 | return (gpc_reg_operand (op, mode) |
1480 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1481 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1482 | && INTVAL (op) < 0x7fff8000 |
a65c591c | 1483 | #else |
a4f6c312 SS |
1484 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) |
1485 | < 0x100000000ll) | |
2bfcf297 | 1486 | #endif |
a4f6c312 | 1487 | )); |
2bfcf297 DB |
1488 | } |
1489 | ||
1490 | /* Return 1 is the operand is either a non-special register or a 32-bit | |
1491 | signed constant integer valid for 64-bit subtraction. */ | |
1492 | ||
1493 | int | |
a2369ed3 | 1494 | reg_or_sub_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1495 | { |
a4f6c312 SS |
1496 | return (gpc_reg_operand (op, mode) |
1497 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1498 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1499 | && (- INTVAL (op)) < 0x7fff8000 |
a65c591c | 1500 | #else |
a4f6c312 SS |
1501 | && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000) |
1502 | < 0x100000000ll) | |
2bfcf297 | 1503 | #endif |
a4f6c312 | 1504 | )); |
2bfcf297 DB |
1505 | } |
1506 | ||
9ebbca7d GK |
1507 | /* Return 1 is the operand is either a non-special register or ANY |
1508 | 32-bit unsigned constant integer. */ | |
1509 | ||
1510 | int | |
a2369ed3 | 1511 | reg_or_logical_cint_operand (rtx op, enum machine_mode mode) |
9ebbca7d | 1512 | { |
1d328b19 GK |
1513 | if (GET_CODE (op) == CONST_INT) |
1514 | { | |
1515 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
1516 | { | |
1517 | if (GET_MODE_BITSIZE (mode) <= 32) | |
a4f6c312 | 1518 | abort (); |
1d328b19 GK |
1519 | |
1520 | if (INTVAL (op) < 0) | |
1521 | return 0; | |
1522 | } | |
1523 | ||
1524 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 1525 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
1526 | } |
1527 | else if (GET_CODE (op) == CONST_DOUBLE) | |
1528 | { | |
1529 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
1530 | || mode != DImode) | |
a4f6c312 | 1531 | abort (); |
1d328b19 GK |
1532 | |
1533 | return CONST_DOUBLE_HIGH (op) == 0; | |
1534 | } | |
1535 | else | |
1536 | return gpc_reg_operand (op, mode); | |
9ebbca7d GK |
1537 | } |
1538 | ||
51d3e7d6 | 1539 | /* Return 1 if the operand is an operand that can be loaded via the GOT. */ |
766a866c MM |
1540 | |
1541 | int | |
a2369ed3 | 1542 | got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
766a866c MM |
1543 | { |
1544 | return (GET_CODE (op) == SYMBOL_REF | |
1545 | || GET_CODE (op) == CONST | |
1546 | || GET_CODE (op) == LABEL_REF); | |
1547 | } | |
1548 | ||
38c1f2d7 MM |
1549 | /* Return 1 if the operand is a simple references that can be loaded via |
1550 | the GOT (labels involving addition aren't allowed). */ | |
1551 | ||
1552 | int | |
a2369ed3 | 1553 | got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
38c1f2d7 MM |
1554 | { |
1555 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
1556 | } | |
1557 | ||
4e74d8ec MM |
1558 | /* Return the number of instructions it takes to form a constant in an |
1559 | integer register. */ | |
1560 | ||
1561 | static int | |
a2369ed3 | 1562 | num_insns_constant_wide (HOST_WIDE_INT value) |
4e74d8ec MM |
1563 | { |
1564 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 1565 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
1566 | return 1; |
1567 | ||
4e74d8ec | 1568 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 1569 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
1570 | return 1; |
1571 | ||
5f59ecb7 | 1572 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 1573 | else if (TARGET_POWERPC64) |
4e74d8ec | 1574 | { |
a65c591c DE |
1575 | HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000; |
1576 | HOST_WIDE_INT high = value >> 31; | |
4e74d8ec | 1577 | |
a65c591c | 1578 | if (high == 0 || high == -1) |
4e74d8ec MM |
1579 | return 2; |
1580 | ||
a65c591c | 1581 | high >>= 1; |
4e74d8ec | 1582 | |
a65c591c | 1583 | if (low == 0) |
4e74d8ec | 1584 | return num_insns_constant_wide (high) + 1; |
4e74d8ec MM |
1585 | else |
1586 | return (num_insns_constant_wide (high) | |
e396202a | 1587 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
1588 | } |
1589 | #endif | |
1590 | ||
1591 | else | |
1592 | return 2; | |
1593 | } | |
1594 | ||
1595 | int | |
a2369ed3 | 1596 | num_insns_constant (rtx op, enum machine_mode mode) |
4e74d8ec | 1597 | { |
4e74d8ec | 1598 | if (GET_CODE (op) == CONST_INT) |
0d30d435 DE |
1599 | { |
1600 | #if HOST_BITS_PER_WIDE_INT == 64 | |
4e2c1c44 DE |
1601 | if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1 |
1602 | && mask64_operand (op, mode)) | |
0d30d435 DE |
1603 | return 2; |
1604 | else | |
1605 | #endif | |
1606 | return num_insns_constant_wide (INTVAL (op)); | |
1607 | } | |
4e74d8ec | 1608 | |
6fc48950 MM |
1609 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
1610 | { | |
1611 | long l; | |
1612 | REAL_VALUE_TYPE rv; | |
1613 | ||
1614 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1615 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
e72247f4 | 1616 | return num_insns_constant_wide ((HOST_WIDE_INT) l); |
6fc48950 MM |
1617 | } |
1618 | ||
47ad8c61 | 1619 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 1620 | { |
47ad8c61 MM |
1621 | HOST_WIDE_INT low; |
1622 | HOST_WIDE_INT high; | |
1623 | long l[2]; | |
1624 | REAL_VALUE_TYPE rv; | |
1625 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 1626 | |
47ad8c61 MM |
1627 | if (mode == VOIDmode || mode == DImode) |
1628 | { | |
1629 | high = CONST_DOUBLE_HIGH (op); | |
1630 | low = CONST_DOUBLE_LOW (op); | |
1631 | } | |
1632 | else | |
1633 | { | |
1634 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1635 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
1636 | high = l[endian]; | |
1637 | low = l[1 - endian]; | |
1638 | } | |
4e74d8ec | 1639 | |
47ad8c61 MM |
1640 | if (TARGET_32BIT) |
1641 | return (num_insns_constant_wide (low) | |
1642 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
1643 | |
1644 | else | |
47ad8c61 | 1645 | { |
e72247f4 | 1646 | if (high == 0 && low >= 0) |
47ad8c61 MM |
1647 | return num_insns_constant_wide (low); |
1648 | ||
e72247f4 | 1649 | else if (high == -1 && low < 0) |
47ad8c61 MM |
1650 | return num_insns_constant_wide (low); |
1651 | ||
a260abc9 DE |
1652 | else if (mask64_operand (op, mode)) |
1653 | return 2; | |
1654 | ||
47ad8c61 MM |
1655 | else if (low == 0) |
1656 | return num_insns_constant_wide (high) + 1; | |
1657 | ||
1658 | else | |
1659 | return (num_insns_constant_wide (high) | |
1660 | + num_insns_constant_wide (low) + 1); | |
1661 | } | |
4e74d8ec MM |
1662 | } |
1663 | ||
1664 | else | |
1665 | abort (); | |
1666 | } | |
1667 | ||
a4f6c312 SS |
1668 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a |
1669 | register with one instruction per word. We only do this if we can | |
1670 | safely read CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
1671 | |
1672 | int | |
a2369ed3 | 1673 | easy_fp_constant (rtx op, enum machine_mode mode) |
9878760c | 1674 | { |
9878760c RK |
1675 | if (GET_CODE (op) != CONST_DOUBLE |
1676 | || GET_MODE (op) != mode | |
4e74d8ec | 1677 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
1678 | return 0; |
1679 | ||
a4f6c312 | 1680 | /* Consider all constants with -msoft-float to be easy. */ |
a3170dc6 AH |
1681 | if ((TARGET_SOFT_FLOAT || !TARGET_FPRS) |
1682 | && mode != DImode) | |
b6c9286a MM |
1683 | return 1; |
1684 | ||
a4f6c312 | 1685 | /* If we are using V.4 style PIC, consider all constants to be hard. */ |
f607bc57 | 1686 | if (flag_pic && DEFAULT_ABI == ABI_V4) |
a7273471 MM |
1687 | return 0; |
1688 | ||
5ae4759c | 1689 | #ifdef TARGET_RELOCATABLE |
a4f6c312 SS |
1690 | /* Similarly if we are using -mrelocatable, consider all constants |
1691 | to be hard. */ | |
5ae4759c MM |
1692 | if (TARGET_RELOCATABLE) |
1693 | return 0; | |
1694 | #endif | |
1695 | ||
fcce224d DE |
1696 | if (mode == TFmode) |
1697 | { | |
1698 | long k[4]; | |
1699 | REAL_VALUE_TYPE rv; | |
1700 | ||
1701 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1702 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
1703 | ||
1704 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 | |
1705 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1 | |
1706 | && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1 | |
1707 | && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1); | |
1708 | } | |
1709 | ||
1710 | else if (mode == DFmode) | |
042259f2 DE |
1711 | { |
1712 | long k[2]; | |
1713 | REAL_VALUE_TYPE rv; | |
1714 | ||
1715 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1716 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 1717 | |
a65c591c DE |
1718 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 |
1719 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1); | |
042259f2 | 1720 | } |
4e74d8ec MM |
1721 | |
1722 | else if (mode == SFmode) | |
042259f2 DE |
1723 | { |
1724 | long l; | |
1725 | REAL_VALUE_TYPE rv; | |
1726 | ||
1727 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1728 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 1729 | |
4e74d8ec | 1730 | return num_insns_constant_wide (l) == 1; |
042259f2 | 1731 | } |
4e74d8ec | 1732 | |
a260abc9 | 1733 | else if (mode == DImode) |
c81fc13e | 1734 | return ((TARGET_POWERPC64 |
a260abc9 DE |
1735 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
1736 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 1737 | |
a9098fd0 GK |
1738 | else if (mode == SImode) |
1739 | return 1; | |
4e74d8ec MM |
1740 | else |
1741 | abort (); | |
9878760c | 1742 | } |
8f75773e | 1743 | |
effa5d5d | 1744 | /* Returns the constant for the splat instruction, if exists. */ |
452a7d36 HP |
1745 | |
1746 | static int | |
1747 | easy_vector_splat_const (int cst, enum machine_mode mode) | |
1748 | { | |
1749 | switch (mode) | |
1750 | { | |
1751 | case V4SImode: | |
1752 | if (EASY_VECTOR_15 (cst) | |
1753 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
1754 | return cst; | |
1755 | if ((cst & 0xffff) != ((cst >> 16) & 0xffff)) | |
1756 | break; | |
1757 | cst = cst >> 16; | |
1758 | case V8HImode: | |
1759 | if (EASY_VECTOR_15 (cst) | |
1760 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
1761 | return cst; | |
1762 | if ((cst & 0xff) != ((cst >> 8) & 0xff)) | |
1763 | break; | |
1764 | cst = cst >> 8; | |
1765 | case V16QImode: | |
1766 | if (EASY_VECTOR_15 (cst) | |
1767 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
1768 | return cst; | |
1769 | default: | |
1770 | break; | |
1771 | } | |
1772 | return 0; | |
1773 | } | |
1774 | ||
1775 | ||
72ac76be | 1776 | /* Return nonzero if all elements of a vector have the same value. */ |
69ef87e2 AH |
1777 | |
1778 | static int | |
a2369ed3 | 1779 | easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
d744e06e AH |
1780 | { |
1781 | int units, i, cst; | |
1782 | ||
1783 | units = CONST_VECTOR_NUNITS (op); | |
1784 | ||
1785 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); | |
1786 | for (i = 1; i < units; ++i) | |
1787 | if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst) | |
1788 | break; | |
452a7d36 | 1789 | if (i == units && easy_vector_splat_const (cst, mode)) |
d744e06e AH |
1790 | return 1; |
1791 | return 0; | |
1792 | } | |
1793 | ||
1794 | /* Return 1 if the operand is a CONST_INT and can be put into a | |
1795 | register without using memory. */ | |
1796 | ||
1797 | int | |
a2369ed3 | 1798 | easy_vector_constant (rtx op, enum machine_mode mode) |
69ef87e2 | 1799 | { |
d744e06e | 1800 | int cst, cst2; |
69ef87e2 | 1801 | |
d744e06e AH |
1802 | if (GET_CODE (op) != CONST_VECTOR |
1803 | || (!TARGET_ALTIVEC | |
1804 | && !TARGET_SPE)) | |
69ef87e2 AH |
1805 | return 0; |
1806 | ||
d744e06e AH |
1807 | if (zero_constant (op, mode) |
1808 | && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode)) | |
1809 | || (TARGET_SPE && SPE_VECTOR_MODE (mode)))) | |
1810 | return 1; | |
69ef87e2 | 1811 | |
d744e06e AH |
1812 | if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT) |
1813 | return 0; | |
1814 | ||
f5119d10 AH |
1815 | if (TARGET_SPE && mode == V1DImode) |
1816 | return 0; | |
1817 | ||
d744e06e AH |
1818 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); |
1819 | cst2 = INTVAL (CONST_VECTOR_ELT (op, 1)); | |
1820 | ||
1821 | /* Limit SPE vectors to 15 bits signed. These we can generate with: | |
1822 | li r0, CONSTANT1 | |
1823 | evmergelo r0, r0, r0 | |
1824 | li r0, CONSTANT2 | |
1825 | ||
1826 | I don't know how efficient it would be to allow bigger constants, | |
1827 | considering we'll have an extra 'ori' for every 'li'. I doubt 5 | |
1828 | instructions is better than a 64-bit memory load, but I don't | |
1829 | have the e500 timing specs. */ | |
1830 | if (TARGET_SPE && mode == V2SImode | |
1831 | && cst >= -0x7fff && cst <= 0x7fff | |
f5119d10 | 1832 | && cst2 >= -0x7fff && cst2 <= 0x7fff) |
d744e06e AH |
1833 | return 1; |
1834 | ||
452a7d36 HP |
1835 | if (TARGET_ALTIVEC |
1836 | && easy_vector_same (op, mode)) | |
1837 | { | |
1838 | cst = easy_vector_splat_const (cst, mode); | |
1839 | if (EASY_VECTOR_15_ADD_SELF (cst) | |
1840 | || EASY_VECTOR_15 (cst)) | |
1841 | return 1; | |
1842 | } | |
d744e06e AH |
1843 | return 0; |
1844 | } | |
1845 | ||
1846 | /* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */ | |
1847 | ||
1848 | int | |
a2369ed3 | 1849 | easy_vector_constant_add_self (rtx op, enum machine_mode mode) |
d744e06e AH |
1850 | { |
1851 | int cst; | |
452a7d36 HP |
1852 | if (TARGET_ALTIVEC |
1853 | && GET_CODE (op) == CONST_VECTOR | |
1854 | && easy_vector_same (op, mode)) | |
1855 | { | |
1856 | cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode); | |
1857 | if (EASY_VECTOR_15_ADD_SELF (cst)) | |
1858 | return 1; | |
1859 | } | |
1860 | return 0; | |
1861 | } | |
d744e06e | 1862 | |
452a7d36 | 1863 | /* Generate easy_vector_constant out of a easy_vector_constant_add_self. */ |
d744e06e | 1864 | |
452a7d36 HP |
1865 | rtx |
1866 | gen_easy_vector_constant_add_self (rtx op) | |
1867 | { | |
1868 | int i, units; | |
1869 | rtvec v; | |
1870 | units = GET_MODE_NUNITS (GET_MODE (op)); | |
1871 | v = rtvec_alloc (units); | |
1872 | ||
1873 | for (i = 0; i < units; i++) | |
1874 | RTVEC_ELT (v, i) = | |
1875 | GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1); | |
1876 | return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v); | |
d744e06e AH |
1877 | } |
1878 | ||
1879 | const char * | |
a2369ed3 | 1880 | output_vec_const_move (rtx *operands) |
d744e06e AH |
1881 | { |
1882 | int cst, cst2; | |
1883 | enum machine_mode mode; | |
1884 | rtx dest, vec; | |
1885 | ||
1886 | dest = operands[0]; | |
1887 | vec = operands[1]; | |
69ef87e2 | 1888 | |
d744e06e AH |
1889 | cst = INTVAL (CONST_VECTOR_ELT (vec, 0)); |
1890 | cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1)); | |
1891 | mode = GET_MODE (dest); | |
69ef87e2 | 1892 | |
d744e06e AH |
1893 | if (TARGET_ALTIVEC) |
1894 | { | |
1895 | if (zero_constant (vec, mode)) | |
1896 | return "vxor %0,%0,%0"; | |
ce1f50b2 | 1897 | else if (easy_vector_constant (vec, mode)) |
98ef3137 | 1898 | { |
d744e06e AH |
1899 | operands[1] = GEN_INT (cst); |
1900 | switch (mode) | |
1901 | { | |
1902 | case V4SImode: | |
452a7d36 | 1903 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
1904 | { |
1905 | operands[1] = GEN_INT (cst); | |
1906 | return "vspltisw %0,%1"; | |
1907 | } | |
452a7d36 HP |
1908 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
1909 | return "#"; | |
ce1f50b2 | 1910 | cst = cst >> 16; |
d744e06e | 1911 | case V8HImode: |
452a7d36 | 1912 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
1913 | { |
1914 | operands[1] = GEN_INT (cst); | |
1915 | return "vspltish %0,%1"; | |
1916 | } | |
452a7d36 HP |
1917 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
1918 | return "#"; | |
ce1f50b2 | 1919 | cst = cst >> 8; |
d744e06e | 1920 | case V16QImode: |
452a7d36 | 1921 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
1922 | { |
1923 | operands[1] = GEN_INT (cst); | |
1924 | return "vspltisb %0,%1"; | |
1925 | } | |
452a7d36 HP |
1926 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
1927 | return "#"; | |
d744e06e AH |
1928 | default: |
1929 | abort (); | |
1930 | } | |
98ef3137 | 1931 | } |
d744e06e AH |
1932 | else |
1933 | abort (); | |
69ef87e2 AH |
1934 | } |
1935 | ||
d744e06e AH |
1936 | if (TARGET_SPE) |
1937 | { | |
1938 | /* Vector constant 0 is handled as a splitter of V2SI, and in the | |
1939 | pattern of V1DI, V4HI, and V2SF. | |
1940 | ||
c1207243 | 1941 | FIXME: We should probably return # and add post reload |
d744e06e AH |
1942 | splitters for these, but this way is so easy ;-). |
1943 | */ | |
1944 | operands[1] = GEN_INT (cst); | |
1945 | operands[2] = GEN_INT (cst2); | |
1946 | if (cst == cst2) | |
1947 | return "li %0,%1\n\tevmergelo %0,%0,%0"; | |
1948 | else | |
1949 | return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2"; | |
1950 | } | |
1951 | ||
1952 | abort (); | |
69ef87e2 AH |
1953 | } |
1954 | ||
1955 | /* Return 1 if the operand is the constant 0. This works for scalars | |
1956 | as well as vectors. */ | |
1957 | int | |
a2369ed3 | 1958 | zero_constant (rtx op, enum machine_mode mode) |
69ef87e2 AH |
1959 | { |
1960 | return op == CONST0_RTX (mode); | |
1961 | } | |
1962 | ||
50a0b056 GK |
1963 | /* Return 1 if the operand is 0.0. */ |
1964 | int | |
a2369ed3 | 1965 | zero_fp_constant (rtx op, enum machine_mode mode) |
50a0b056 GK |
1966 | { |
1967 | return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode); | |
1968 | } | |
1969 | ||
a4f6c312 SS |
1970 | /* Return 1 if the operand is in volatile memory. Note that during |
1971 | the RTL generation phase, memory_operand does not return TRUE for | |
b6c9286a MM |
1972 | volatile memory references. So this function allows us to |
1973 | recognize volatile references where its safe. */ | |
1974 | ||
1975 | int | |
a2369ed3 | 1976 | volatile_mem_operand (rtx op, enum machine_mode mode) |
b6c9286a MM |
1977 | { |
1978 | if (GET_CODE (op) != MEM) | |
1979 | return 0; | |
1980 | ||
1981 | if (!MEM_VOLATILE_P (op)) | |
1982 | return 0; | |
1983 | ||
1984 | if (mode != GET_MODE (op)) | |
1985 | return 0; | |
1986 | ||
1987 | if (reload_completed) | |
1988 | return memory_operand (op, mode); | |
1989 | ||
1990 | if (reload_in_progress) | |
1991 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
1992 | ||
1993 | return memory_address_p (mode, XEXP (op, 0)); | |
1994 | } | |
1995 | ||
97f6e72f | 1996 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
1997 | |
1998 | int | |
a2369ed3 | 1999 | offsettable_mem_operand (rtx op, enum machine_mode mode) |
914c2e77 | 2000 | { |
97f6e72f | 2001 | return ((GET_CODE (op) == MEM) |
677a9668 | 2002 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 2003 | mode, XEXP (op, 0))); |
914c2e77 RK |
2004 | } |
2005 | ||
9878760c RK |
2006 | /* Return 1 if the operand is either an easy FP constant (see above) or |
2007 | memory. */ | |
2008 | ||
2009 | int | |
a2369ed3 | 2010 | mem_or_easy_const_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2011 | { |
2012 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
2013 | } | |
2014 | ||
2015 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 2016 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
2017 | |
2018 | int | |
a2369ed3 | 2019 | add_operand (rtx op, enum machine_mode mode) |
9878760c | 2020 | { |
2bfcf297 | 2021 | if (GET_CODE (op) == CONST_INT) |
e72247f4 DE |
2022 | return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
2023 | || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
2bfcf297 DB |
2024 | |
2025 | return gpc_reg_operand (op, mode); | |
9878760c RK |
2026 | } |
2027 | ||
dcfedcd0 RK |
2028 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
2029 | ||
2030 | int | |
a2369ed3 | 2031 | non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
2032 | { |
2033 | return (GET_CODE (op) == CONST_INT | |
e72247f4 DE |
2034 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
2035 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
dcfedcd0 RK |
2036 | } |
2037 | ||
9878760c RK |
2038 | /* Return 1 if the operand is a non-special register or a constant that |
2039 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
2040 | ||
2041 | int | |
a2369ed3 | 2042 | logical_operand (rtx op, enum machine_mode mode) |
9878760c | 2043 | { |
40501e5f | 2044 | HOST_WIDE_INT opl, oph; |
1d328b19 | 2045 | |
dfbdccdb GK |
2046 | if (gpc_reg_operand (op, mode)) |
2047 | return 1; | |
1d328b19 | 2048 | |
dfbdccdb | 2049 | if (GET_CODE (op) == CONST_INT) |
40501e5f AM |
2050 | { |
2051 | opl = INTVAL (op) & GET_MODE_MASK (mode); | |
2052 | ||
2053 | #if HOST_BITS_PER_WIDE_INT <= 32 | |
2054 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0) | |
2055 | return 0; | |
2056 | #endif | |
2057 | } | |
dfbdccdb GK |
2058 | else if (GET_CODE (op) == CONST_DOUBLE) |
2059 | { | |
1d328b19 | 2060 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
40501e5f | 2061 | abort (); |
1d328b19 GK |
2062 | |
2063 | opl = CONST_DOUBLE_LOW (op); | |
2064 | oph = CONST_DOUBLE_HIGH (op); | |
40501e5f | 2065 | if (oph != 0) |
38886f37 | 2066 | return 0; |
dfbdccdb GK |
2067 | } |
2068 | else | |
2069 | return 0; | |
1d328b19 | 2070 | |
40501e5f AM |
2071 | return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 |
2072 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); | |
9878760c RK |
2073 | } |
2074 | ||
dcfedcd0 | 2075 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 2076 | above), but could be split into one. */ |
dcfedcd0 RK |
2077 | |
2078 | int | |
a2369ed3 | 2079 | non_logical_cint_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2080 | { |
dfbdccdb | 2081 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
2082 | && ! logical_operand (op, mode) |
2083 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
2084 | } |
2085 | ||
19ba8161 | 2086 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
2087 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
2088 | Reject all ones and all zeros, since these should have been optimized | |
2089 | away and confuse the making of MB and ME. */ | |
2090 | ||
2091 | int | |
a2369ed3 | 2092 | mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 2093 | { |
02071907 | 2094 | HOST_WIDE_INT c, lsb; |
9878760c | 2095 | |
19ba8161 DE |
2096 | if (GET_CODE (op) != CONST_INT) |
2097 | return 0; | |
2098 | ||
2099 | c = INTVAL (op); | |
2100 | ||
57deb3a1 AM |
2101 | /* Fail in 64-bit mode if the mask wraps around because the upper |
2102 | 32-bits of the mask will all be 1s, contrary to GCC's internal view. */ | |
2103 | if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001) | |
2104 | return 0; | |
2105 | ||
c5059423 AM |
2106 | /* We don't change the number of transitions by inverting, |
2107 | so make sure we start with the LS bit zero. */ | |
2108 | if (c & 1) | |
2109 | c = ~c; | |
2110 | ||
2111 | /* Reject all zeros or all ones. */ | |
2112 | if (c == 0) | |
9878760c RK |
2113 | return 0; |
2114 | ||
c5059423 AM |
2115 | /* Find the first transition. */ |
2116 | lsb = c & -c; | |
2117 | ||
2118 | /* Invert to look for a second transition. */ | |
2119 | c = ~c; | |
9878760c | 2120 | |
c5059423 AM |
2121 | /* Erase first transition. */ |
2122 | c &= -lsb; | |
9878760c | 2123 | |
c5059423 AM |
2124 | /* Find the second transition (if any). */ |
2125 | lsb = c & -c; | |
2126 | ||
2127 | /* Match if all the bits above are 1's (or c is zero). */ | |
2128 | return c == -lsb; | |
9878760c RK |
2129 | } |
2130 | ||
0ba1b2ff AM |
2131 | /* Return 1 for the PowerPC64 rlwinm corner case. */ |
2132 | ||
2133 | int | |
a2369ed3 | 2134 | mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2135 | { |
2136 | HOST_WIDE_INT c, lsb; | |
2137 | ||
2138 | if (GET_CODE (op) != CONST_INT) | |
2139 | return 0; | |
2140 | ||
2141 | c = INTVAL (op); | |
2142 | ||
2143 | if ((c & 0x80000001) != 0x80000001) | |
2144 | return 0; | |
2145 | ||
2146 | c = ~c; | |
2147 | if (c == 0) | |
2148 | return 0; | |
2149 | ||
2150 | lsb = c & -c; | |
2151 | c = ~c; | |
2152 | c &= -lsb; | |
2153 | lsb = c & -c; | |
2154 | return c == -lsb; | |
2155 | } | |
2156 | ||
a260abc9 DE |
2157 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
2158 | It is if there are no more than one 1->0 or 0->1 transitions. | |
0ba1b2ff AM |
2159 | Reject all zeros, since zero should have been optimized away and |
2160 | confuses the making of MB and ME. */ | |
9878760c RK |
2161 | |
2162 | int | |
a2369ed3 | 2163 | mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
a260abc9 DE |
2164 | { |
2165 | if (GET_CODE (op) == CONST_INT) | |
2166 | { | |
02071907 | 2167 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2168 | |
c5059423 | 2169 | c = INTVAL (op); |
a260abc9 | 2170 | |
0ba1b2ff | 2171 | /* Reject all zeros. */ |
c5059423 | 2172 | if (c == 0) |
e2c953b6 DE |
2173 | return 0; |
2174 | ||
0ba1b2ff AM |
2175 | /* We don't change the number of transitions by inverting, |
2176 | so make sure we start with the LS bit zero. */ | |
2177 | if (c & 1) | |
2178 | c = ~c; | |
2179 | ||
c5059423 AM |
2180 | /* Find the transition, and check that all bits above are 1's. */ |
2181 | lsb = c & -c; | |
e3981aab DE |
2182 | |
2183 | /* Match if all the bits above are 1's (or c is zero). */ | |
c5059423 | 2184 | return c == -lsb; |
e2c953b6 | 2185 | } |
0ba1b2ff AM |
2186 | return 0; |
2187 | } | |
2188 | ||
2189 | /* Like mask64_operand, but allow up to three transitions. This | |
2190 | predicate is used by insn patterns that generate two rldicl or | |
2191 | rldicr machine insns. */ | |
2192 | ||
2193 | int | |
a2369ed3 | 2194 | mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2195 | { |
2196 | if (GET_CODE (op) == CONST_INT) | |
a260abc9 | 2197 | { |
0ba1b2ff | 2198 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2199 | |
0ba1b2ff | 2200 | c = INTVAL (op); |
a260abc9 | 2201 | |
0ba1b2ff AM |
2202 | /* Disallow all zeros. */ |
2203 | if (c == 0) | |
2204 | return 0; | |
a260abc9 | 2205 | |
0ba1b2ff AM |
2206 | /* We don't change the number of transitions by inverting, |
2207 | so make sure we start with the LS bit zero. */ | |
2208 | if (c & 1) | |
2209 | c = ~c; | |
a260abc9 | 2210 | |
0ba1b2ff AM |
2211 | /* Find the first transition. */ |
2212 | lsb = c & -c; | |
a260abc9 | 2213 | |
0ba1b2ff AM |
2214 | /* Invert to look for a second transition. */ |
2215 | c = ~c; | |
2216 | ||
2217 | /* Erase first transition. */ | |
2218 | c &= -lsb; | |
2219 | ||
2220 | /* Find the second transition. */ | |
2221 | lsb = c & -c; | |
2222 | ||
2223 | /* Invert to look for a third transition. */ | |
2224 | c = ~c; | |
2225 | ||
2226 | /* Erase second transition. */ | |
2227 | c &= -lsb; | |
2228 | ||
2229 | /* Find the third transition (if any). */ | |
2230 | lsb = c & -c; | |
2231 | ||
2232 | /* Match if all the bits above are 1's (or c is zero). */ | |
2233 | return c == -lsb; | |
2234 | } | |
2235 | return 0; | |
2236 | } | |
2237 | ||
2238 | /* Generates shifts and masks for a pair of rldicl or rldicr insns to | |
2239 | implement ANDing by the mask IN. */ | |
2240 | void | |
a2369ed3 | 2241 | build_mask64_2_operands (rtx in, rtx *out) |
0ba1b2ff AM |
2242 | { |
2243 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
2244 | unsigned HOST_WIDE_INT c, lsb, m1, m2; | |
2245 | int shift; | |
2246 | ||
2247 | if (GET_CODE (in) != CONST_INT) | |
2248 | abort (); | |
2249 | ||
2250 | c = INTVAL (in); | |
2251 | if (c & 1) | |
2252 | { | |
2253 | /* Assume c initially something like 0x00fff000000fffff. The idea | |
2254 | is to rotate the word so that the middle ^^^^^^ group of zeros | |
2255 | is at the MS end and can be cleared with an rldicl mask. We then | |
2256 | rotate back and clear off the MS ^^ group of zeros with a | |
2257 | second rldicl. */ | |
2258 | c = ~c; /* c == 0xff000ffffff00000 */ | |
2259 | lsb = c & -c; /* lsb == 0x0000000000100000 */ | |
2260 | m1 = -lsb; /* m1 == 0xfffffffffff00000 */ | |
2261 | c = ~c; /* c == 0x00fff000000fffff */ | |
2262 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2263 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2264 | c = ~c; /* c == 0xff000fffffffffff */ | |
2265 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2266 | shift = 0; | |
2267 | while ((lsb >>= 1) != 0) | |
2268 | shift++; /* shift == 44 on exit from loop */ | |
2269 | m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */ | |
2270 | m1 = ~m1; /* m1 == 0x000000ffffffffff */ | |
2271 | m2 = ~c; /* m2 == 0x00ffffffffffffff */ | |
a260abc9 DE |
2272 | } |
2273 | else | |
0ba1b2ff AM |
2274 | { |
2275 | /* Assume c initially something like 0xff000f0000000000. The idea | |
2276 | is to rotate the word so that the ^^^ middle group of zeros | |
2277 | is at the LS end and can be cleared with an rldicr mask. We then | |
2278 | rotate back and clear off the LS group of ^^^^^^^^^^ zeros with | |
2279 | a second rldicr. */ | |
2280 | lsb = c & -c; /* lsb == 0x0000010000000000 */ | |
2281 | m2 = -lsb; /* m2 == 0xffffff0000000000 */ | |
2282 | c = ~c; /* c == 0x00fff0ffffffffff */ | |
2283 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2284 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2285 | c = ~c; /* c == 0xff000fffffffffff */ | |
2286 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2287 | shift = 0; | |
2288 | while ((lsb >>= 1) != 0) | |
2289 | shift++; /* shift == 44 on exit from loop */ | |
2290 | m1 = ~c; /* m1 == 0x00ffffffffffffff */ | |
2291 | m1 >>= shift; /* m1 == 0x0000000000000fff */ | |
2292 | m1 = ~m1; /* m1 == 0xfffffffffffff000 */ | |
2293 | } | |
2294 | ||
2295 | /* Note that when we only have two 0->1 and 1->0 transitions, one of the | |
2296 | masks will be all 1's. We are guaranteed more than one transition. */ | |
2297 | out[0] = GEN_INT (64 - shift); | |
2298 | out[1] = GEN_INT (m1); | |
2299 | out[2] = GEN_INT (shift); | |
2300 | out[3] = GEN_INT (m2); | |
2301 | #else | |
045572c7 GK |
2302 | (void)in; |
2303 | (void)out; | |
0ba1b2ff AM |
2304 | abort (); |
2305 | #endif | |
a260abc9 DE |
2306 | } |
2307 | ||
2308 | /* Return 1 if the operand is either a non-special register or a constant | |
2309 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
2310 | ||
2311 | int | |
a2369ed3 | 2312 | and64_operand (rtx op, enum machine_mode mode) |
9878760c | 2313 | { |
a4f6c312 | 2314 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2315 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
2316 | ||
2317 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
2318 | } |
2319 | ||
0ba1b2ff AM |
2320 | /* Like the above, but also match constants that can be implemented |
2321 | with two rldicl or rldicr insns. */ | |
2322 | ||
2323 | int | |
a2369ed3 | 2324 | and64_2_operand (rtx op, enum machine_mode mode) |
0ba1b2ff | 2325 | { |
a3c9585f | 2326 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
0ba1b2ff AM |
2327 | return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode); |
2328 | ||
2329 | return logical_operand (op, mode) || mask64_2_operand (op, mode); | |
2330 | } | |
2331 | ||
a260abc9 DE |
2332 | /* Return 1 if the operand is either a non-special register or a |
2333 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
2334 | |
2335 | int | |
a2369ed3 | 2336 | and_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2337 | { |
a4f6c312 | 2338 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2339 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
2340 | ||
2341 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
2342 | } |
2343 | ||
9878760c RK |
2344 | /* Return 1 if the operand is a general register or memory operand. */ |
2345 | ||
2346 | int | |
a2369ed3 | 2347 | reg_or_mem_operand (rtx op, enum machine_mode mode) |
9878760c | 2348 | { |
b6c9286a MM |
2349 | return (gpc_reg_operand (op, mode) |
2350 | || memory_operand (op, mode) | |
4c81e946 | 2351 | || macho_lo_sum_memory_operand (op, mode) |
b6c9286a | 2352 | || volatile_mem_operand (op, mode)); |
9878760c RK |
2353 | } |
2354 | ||
a7a813f7 | 2355 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 2356 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
2357 | instruction. */ |
2358 | ||
2359 | int | |
a2369ed3 | 2360 | lwa_operand (rtx op, enum machine_mode mode) |
a7a813f7 RK |
2361 | { |
2362 | rtx inner = op; | |
2363 | ||
2364 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
2365 | inner = SUBREG_REG (inner); | |
2366 | ||
2367 | return gpc_reg_operand (inner, mode) | |
2368 | || (memory_operand (inner, mode) | |
2369 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
6a40a9d6 DE |
2370 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC |
2371 | && (GET_CODE (XEXP (inner, 0)) != PLUS | |
e903c96a DE |
2372 | || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT |
2373 | || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0)); | |
a7a813f7 RK |
2374 | } |
2375 | ||
cc4d5fec JH |
2376 | /* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */ |
2377 | ||
2378 | int | |
a2369ed3 | 2379 | symbol_ref_operand (rtx op, enum machine_mode mode) |
cc4d5fec JH |
2380 | { |
2381 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2382 | return 0; | |
2383 | ||
473f51b6 DE |
2384 | return (GET_CODE (op) == SYMBOL_REF |
2385 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))); | |
cc4d5fec JH |
2386 | } |
2387 | ||
9878760c | 2388 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
cc4d5fec | 2389 | to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */ |
9878760c RK |
2390 | |
2391 | int | |
a2369ed3 | 2392 | call_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2393 | { |
2394 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2395 | return 0; | |
2396 | ||
2397 | return (GET_CODE (op) == SYMBOL_REF | |
cc4d5fec JH |
2398 | || (GET_CODE (op) == REG |
2399 | && (REGNO (op) == LINK_REGISTER_REGNUM | |
2400 | || REGNO (op) == COUNT_REGISTER_REGNUM | |
2401 | || REGNO (op) >= FIRST_PSEUDO_REGISTER))); | |
9878760c RK |
2402 | } |
2403 | ||
2af3d377 | 2404 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in |
d1908feb | 2405 | this file. */ |
2af3d377 RK |
2406 | |
2407 | int | |
a2369ed3 DJ |
2408 | current_file_function_operand (rtx op, |
2409 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
2af3d377 | 2410 | { |
473f51b6 DE |
2411 | return (GET_CODE (op) == SYMBOL_REF |
2412 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)) | |
2413 | && (SYMBOL_REF_LOCAL_P (op) | |
2414 | || (op == XEXP (DECL_RTL (current_function_decl), 0)))); | |
2af3d377 RK |
2415 | } |
2416 | ||
9878760c RK |
2417 | /* Return 1 if this operand is a valid input for a move insn. */ |
2418 | ||
2419 | int | |
a2369ed3 | 2420 | input_operand (rtx op, enum machine_mode mode) |
9878760c | 2421 | { |
eb4e8003 | 2422 | /* Memory is always valid. */ |
9878760c RK |
2423 | if (memory_operand (op, mode)) |
2424 | return 1; | |
2425 | ||
eb4e8003 RK |
2426 | /* For floating-point, easy constants are valid. */ |
2427 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
2428 | && CONSTANT_P (op) | |
2429 | && easy_fp_constant (op, mode)) | |
2430 | return 1; | |
2431 | ||
4e74d8ec MM |
2432 | /* Allow any integer constant. */ |
2433 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 2434 | && (GET_CODE (op) == CONST_INT |
e675f625 | 2435 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
2436 | return 1; |
2437 | ||
d744e06e AH |
2438 | /* Allow easy vector constants. */ |
2439 | if (GET_CODE (op) == CONST_VECTOR | |
2440 | && easy_vector_constant (op, mode)) | |
2441 | return 1; | |
2442 | ||
eb4e8003 RK |
2443 | /* For floating-point or multi-word mode, the only remaining valid type |
2444 | is a register. */ | |
9878760c RK |
2445 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
2446 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 2447 | return register_operand (op, mode); |
9878760c | 2448 | |
88fe15a1 RK |
2449 | /* The only cases left are integral modes one word or smaller (we |
2450 | do not get called for MODE_CC values). These can be in any | |
2451 | register. */ | |
2452 | if (register_operand (op, mode)) | |
a8b3aeda | 2453 | return 1; |
88fe15a1 | 2454 | |
84cf9dda | 2455 | /* A SYMBOL_REF referring to the TOC is valid. */ |
4d588c14 | 2456 | if (legitimate_constant_pool_address_p (op)) |
84cf9dda RK |
2457 | return 1; |
2458 | ||
9ebbca7d | 2459 | /* A constant pool expression (relative to the TOC) is valid */ |
4d588c14 | 2460 | if (toc_relative_expr_p (op)) |
b6c9286a MM |
2461 | return 1; |
2462 | ||
88228c4b MM |
2463 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
2464 | to be valid. */ | |
f607bc57 | 2465 | if (DEFAULT_ABI == ABI_V4 |
88228c4b MM |
2466 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
2467 | && small_data_operand (op, Pmode)) | |
2468 | return 1; | |
2469 | ||
042259f2 | 2470 | return 0; |
9878760c | 2471 | } |
7509c759 | 2472 | |
95727fb8 AP |
2473 | |
2474 | /* Darwin, AIX increases natural record alignment to doubleword if the first | |
2475 | field is an FP double while the FP fields remain word aligned. */ | |
2476 | ||
19d66194 | 2477 | unsigned int |
95727fb8 AP |
2478 | rs6000_special_round_type_align (tree type, int computed, int specified) |
2479 | { | |
2480 | tree field = TYPE_FIELDS (type); | |
95727fb8 AP |
2481 | |
2482 | /* Skip all the static variables only if ABI is greater than | |
71cc389b | 2483 | 1 or equal to 0. */ |
3ce5437a | 2484 | while (field != NULL && TREE_CODE (field) == VAR_DECL) |
95727fb8 AP |
2485 | field = TREE_CHAIN (field); |
2486 | ||
3ce5437a | 2487 | if (field == NULL || field == type || DECL_MODE (field) != DFmode) |
95727fb8 AP |
2488 | return MAX (computed, specified); |
2489 | ||
2490 | return MAX (MAX (computed, specified), 64); | |
2491 | } | |
2492 | ||
a4f6c312 | 2493 | /* Return 1 for an operand in small memory on V.4/eabi. */ |
7509c759 MM |
2494 | |
2495 | int | |
a2369ed3 DJ |
2496 | small_data_operand (rtx op ATTRIBUTE_UNUSED, |
2497 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
7509c759 | 2498 | { |
38c1f2d7 | 2499 | #if TARGET_ELF |
5f59ecb7 | 2500 | rtx sym_ref; |
7509c759 | 2501 | |
d9407988 | 2502 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 2503 | return 0; |
a54d04b7 | 2504 | |
f607bc57 | 2505 | if (DEFAULT_ABI != ABI_V4) |
7509c759 MM |
2506 | return 0; |
2507 | ||
88228c4b MM |
2508 | if (GET_CODE (op) == SYMBOL_REF) |
2509 | sym_ref = op; | |
2510 | ||
2511 | else if (GET_CODE (op) != CONST | |
2512 | || GET_CODE (XEXP (op, 0)) != PLUS | |
2513 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
2514 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
2515 | return 0; |
2516 | ||
88228c4b | 2517 | else |
dbf55e53 MM |
2518 | { |
2519 | rtx sum = XEXP (op, 0); | |
2520 | HOST_WIDE_INT summand; | |
2521 | ||
2522 | /* We have to be careful here, because it is the referenced address | |
2523 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
2524 | summand = INTVAL (XEXP (sum, 1)); | |
307b599c | 2525 | if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value) |
dbf55e53 MM |
2526 | return 0; |
2527 | ||
2528 | sym_ref = XEXP (sum, 0); | |
2529 | } | |
88228c4b | 2530 | |
20bfcd69 | 2531 | return SYMBOL_REF_SMALL_P (sym_ref); |
d9407988 MM |
2532 | #else |
2533 | return 0; | |
2534 | #endif | |
7509c759 | 2535 | } |
46c07df8 | 2536 | |
d2288d5d HP |
2537 | /* Return true, if operand is a memory operand and has a |
2538 | displacement divisible by 4. */ | |
2539 | ||
2540 | int | |
2541 | word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) | |
2542 | { | |
2543 | rtx addr; | |
2544 | int off = 0; | |
2545 | ||
2546 | if (!memory_operand (op, mode)) | |
2547 | return 0; | |
2548 | ||
2549 | addr = XEXP (op, 0); | |
2550 | if (GET_CODE (addr) == PLUS | |
2551 | && GET_CODE (XEXP (addr, 0)) == REG | |
2552 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
2553 | off = INTVAL (XEXP (addr, 1)); | |
2554 | ||
2555 | return (off % 4) == 0; | |
2556 | } | |
2557 | ||
3a1f863f | 2558 | /* Return true if either operand is a general purpose register. */ |
46c07df8 | 2559 | |
3a1f863f DE |
2560 | bool |
2561 | gpr_or_gpr_p (rtx op0, rtx op1) | |
46c07df8 | 2562 | { |
3a1f863f DE |
2563 | return ((REG_P (op0) && INT_REGNO_P (REGNO (op0))) |
2564 | || (REG_P (op1) && INT_REGNO_P (REGNO (op1)))); | |
46c07df8 HP |
2565 | } |
2566 | ||
9ebbca7d | 2567 | \f |
4d588c14 RH |
2568 | /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */ |
2569 | ||
9ebbca7d | 2570 | static int |
a2369ed3 | 2571 | constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc) |
9ebbca7d GK |
2572 | { |
2573 | switch (GET_CODE(op)) | |
2574 | { | |
2575 | case SYMBOL_REF: | |
c4501e62 JJ |
2576 | if (RS6000_SYMBOL_REF_TLS_P (op)) |
2577 | return 0; | |
2578 | else if (CONSTANT_POOL_ADDRESS_P (op)) | |
a4f6c312 SS |
2579 | { |
2580 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) | |
2581 | { | |
2582 | *have_sym = 1; | |
2583 | return 1; | |
2584 | } | |
2585 | else | |
2586 | return 0; | |
2587 | } | |
2588 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
2589 | { | |
2590 | *have_toc = 1; | |
2591 | return 1; | |
2592 | } | |
2593 | else | |
2594 | return 0; | |
9ebbca7d GK |
2595 | case PLUS: |
2596 | case MINUS: | |
c1f11548 DE |
2597 | return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) |
2598 | && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc)); | |
9ebbca7d | 2599 | case CONST: |
a4f6c312 | 2600 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); |
9ebbca7d | 2601 | case CONST_INT: |
a4f6c312 | 2602 | return 1; |
9ebbca7d | 2603 | default: |
a4f6c312 | 2604 | return 0; |
9ebbca7d GK |
2605 | } |
2606 | } | |
2607 | ||
4d588c14 | 2608 | static bool |
a2369ed3 | 2609 | constant_pool_expr_p (rtx op) |
9ebbca7d GK |
2610 | { |
2611 | int have_sym = 0; | |
2612 | int have_toc = 0; | |
2613 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
2614 | } | |
2615 | ||
4d588c14 | 2616 | static bool |
a2369ed3 | 2617 | toc_relative_expr_p (rtx op) |
9ebbca7d | 2618 | { |
4d588c14 RH |
2619 | int have_sym = 0; |
2620 | int have_toc = 0; | |
2621 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
2622 | } | |
2623 | ||
2624 | /* SPE offset addressing is limited to 5-bits worth of double words. */ | |
2625 | #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0) | |
2626 | ||
2627 | bool | |
a2369ed3 | 2628 | legitimate_constant_pool_address_p (rtx x) |
4d588c14 RH |
2629 | { |
2630 | return (TARGET_TOC | |
2631 | && GET_CODE (x) == PLUS | |
2632 | && GET_CODE (XEXP (x, 0)) == REG | |
2633 | && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER) | |
2634 | && constant_pool_expr_p (XEXP (x, 1))); | |
2635 | } | |
2636 | ||
2637 | static bool | |
a2369ed3 | 2638 | legitimate_small_data_p (enum machine_mode mode, rtx x) |
4d588c14 RH |
2639 | { |
2640 | return (DEFAULT_ABI == ABI_V4 | |
2641 | && !flag_pic && !TARGET_TOC | |
2642 | && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST) | |
2643 | && small_data_operand (x, mode)); | |
2644 | } | |
2645 | ||
2646 | static bool | |
a2369ed3 | 2647 | legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict) |
4d588c14 RH |
2648 | { |
2649 | unsigned HOST_WIDE_INT offset, extra; | |
2650 | ||
2651 | if (GET_CODE (x) != PLUS) | |
2652 | return false; | |
2653 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2654 | return false; | |
2655 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
2656 | return false; | |
2657 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) | |
2658 | return false; | |
2659 | ||
2660 | offset = INTVAL (XEXP (x, 1)); | |
2661 | extra = 0; | |
2662 | switch (mode) | |
2663 | { | |
2664 | case V16QImode: | |
2665 | case V8HImode: | |
2666 | case V4SFmode: | |
2667 | case V4SImode: | |
2668 | /* AltiVec vector modes. Only reg+reg addressing is valid here, | |
2669 | which leaves the only valid constant offset of zero, which by | |
2670 | canonicalization rules is also invalid. */ | |
2671 | return false; | |
2672 | ||
2673 | case V4HImode: | |
2674 | case V2SImode: | |
2675 | case V1DImode: | |
2676 | case V2SFmode: | |
2677 | /* SPE vector modes. */ | |
2678 | return SPE_CONST_OFFSET_OK (offset); | |
2679 | ||
2680 | case DFmode: | |
2681 | case DImode: | |
3364872d | 2682 | if (mode == DFmode || !TARGET_POWERPC64) |
4d588c14 RH |
2683 | extra = 4; |
2684 | else if (offset & 3) | |
2685 | return false; | |
2686 | break; | |
2687 | ||
2688 | case TFmode: | |
2689 | case TImode: | |
3364872d | 2690 | if (mode == TFmode || !TARGET_POWERPC64) |
4d588c14 RH |
2691 | extra = 12; |
2692 | else if (offset & 3) | |
2693 | return false; | |
2694 | else | |
2695 | extra = 8; | |
2696 | break; | |
2697 | ||
2698 | default: | |
2699 | break; | |
2700 | } | |
2701 | ||
b1917422 AM |
2702 | offset += 0x8000; |
2703 | return (offset < 0x10000) && (offset + extra < 0x10000); | |
4d588c14 RH |
2704 | } |
2705 | ||
2706 | static bool | |
a2369ed3 | 2707 | legitimate_indexed_address_p (rtx x, int strict) |
4d588c14 RH |
2708 | { |
2709 | rtx op0, op1; | |
2710 | ||
2711 | if (GET_CODE (x) != PLUS) | |
2712 | return false; | |
2713 | op0 = XEXP (x, 0); | |
2714 | op1 = XEXP (x, 1); | |
2715 | ||
2716 | if (!REG_P (op0) || !REG_P (op1)) | |
2717 | return false; | |
2718 | ||
2719 | return ((INT_REG_OK_FOR_BASE_P (op0, strict) | |
2720 | && INT_REG_OK_FOR_INDEX_P (op1, strict)) | |
2721 | || (INT_REG_OK_FOR_BASE_P (op1, strict) | |
2722 | && INT_REG_OK_FOR_INDEX_P (op0, strict))); | |
9ebbca7d GK |
2723 | } |
2724 | ||
4d588c14 | 2725 | static inline bool |
a2369ed3 | 2726 | legitimate_indirect_address_p (rtx x, int strict) |
4d588c14 RH |
2727 | { |
2728 | return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict); | |
2729 | } | |
2730 | ||
4c81e946 FJ |
2731 | static bool |
2732 | macho_lo_sum_memory_operand (rtx x, enum machine_mode mode) | |
2733 | { | |
2734 | if (!TARGET_MACHO || !flag_pic | |
2735 | || mode != SImode || GET_CODE(x) != MEM) | |
2736 | return false; | |
2737 | x = XEXP (x, 0); | |
2738 | ||
2739 | if (GET_CODE (x) != LO_SUM) | |
2740 | return false; | |
2741 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2742 | return false; | |
2743 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0)) | |
2744 | return false; | |
2745 | x = XEXP (x, 1); | |
2746 | ||
2747 | return CONSTANT_P (x); | |
2748 | } | |
2749 | ||
4d588c14 | 2750 | static bool |
a2369ed3 | 2751 | legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict) |
4d588c14 RH |
2752 | { |
2753 | if (GET_CODE (x) != LO_SUM) | |
2754 | return false; | |
2755 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2756 | return false; | |
2757 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
2758 | return false; | |
2759 | x = XEXP (x, 1); | |
2760 | ||
8622e235 | 2761 | if (TARGET_ELF || TARGET_MACHO) |
4d588c14 | 2762 | { |
a29077da | 2763 | if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic) |
4d588c14 RH |
2764 | return false; |
2765 | if (TARGET_TOC) | |
2766 | return false; | |
2767 | if (GET_MODE_NUNITS (mode) != 1) | |
2768 | return false; | |
2769 | if (GET_MODE_BITSIZE (mode) > 32 | |
2770 | && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode)) | |
2771 | return false; | |
2772 | ||
2773 | return CONSTANT_P (x); | |
2774 | } | |
2775 | ||
2776 | return false; | |
2777 | } | |
2778 | ||
2779 | ||
9ebbca7d GK |
2780 | /* Try machine-dependent ways of modifying an illegitimate address |
2781 | to be legitimate. If we find one, return the new, valid address. | |
2782 | This is used from only one place: `memory_address' in explow.c. | |
2783 | ||
a4f6c312 SS |
2784 | OLDX is the address as it was before break_out_memory_refs was |
2785 | called. In some cases it is useful to look at this to decide what | |
2786 | needs to be done. | |
9ebbca7d | 2787 | |
a4f6c312 | 2788 | MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS. |
9ebbca7d | 2789 | |
a4f6c312 SS |
2790 | It is always safe for this function to do nothing. It exists to |
2791 | recognize opportunities to optimize the output. | |
9ebbca7d GK |
2792 | |
2793 | On RS/6000, first check for the sum of a register with a constant | |
2794 | integer that is out of range. If so, generate code to add the | |
2795 | constant with the low-order 16 bits masked to the register and force | |
2796 | this result into another register (this can be done with `cau'). | |
2797 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
2798 | possibility of bit 16 being a one. | |
2799 | ||
2800 | Then check for the sum of a register and something not constant, try to | |
2801 | load the other things into a register and return the sum. */ | |
4d588c14 | 2802 | |
9ebbca7d | 2803 | rtx |
a2369ed3 DJ |
2804 | rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, |
2805 | enum machine_mode mode) | |
0ac081f6 | 2806 | { |
c4501e62 JJ |
2807 | if (GET_CODE (x) == SYMBOL_REF) |
2808 | { | |
2809 | enum tls_model model = SYMBOL_REF_TLS_MODEL (x); | |
2810 | if (model != 0) | |
2811 | return rs6000_legitimize_tls_address (x, model); | |
2812 | } | |
2813 | ||
9ebbca7d GK |
2814 | if (GET_CODE (x) == PLUS |
2815 | && GET_CODE (XEXP (x, 0)) == REG | |
2816 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2817 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
2818 | { | |
2819 | HOST_WIDE_INT high_int, low_int; | |
2820 | rtx sum; | |
a65c591c DE |
2821 | low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000; |
2822 | high_int = INTVAL (XEXP (x, 1)) - low_int; | |
9ebbca7d GK |
2823 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), |
2824 | GEN_INT (high_int)), 0); | |
2825 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
2826 | } | |
2827 | else if (GET_CODE (x) == PLUS | |
2828 | && GET_CODE (XEXP (x, 0)) == REG | |
2829 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
6ac7bf2c | 2830 | && GET_MODE_NUNITS (mode) == 1 |
a3170dc6 AH |
2831 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
2832 | || TARGET_POWERPC64 | |
fcce224d | 2833 | || (mode != DFmode && mode != TFmode)) |
9ebbca7d GK |
2834 | && (TARGET_POWERPC64 || mode != DImode) |
2835 | && mode != TImode) | |
2836 | { | |
2837 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
2838 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
2839 | } | |
0ac081f6 AH |
2840 | else if (ALTIVEC_VECTOR_MODE (mode)) |
2841 | { | |
2842 | rtx reg; | |
2843 | ||
2844 | /* Make sure both operands are registers. */ | |
2845 | if (GET_CODE (x) == PLUS) | |
9f85ed45 | 2846 | return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)), |
0ac081f6 AH |
2847 | force_reg (Pmode, XEXP (x, 1))); |
2848 | ||
2849 | reg = force_reg (Pmode, x); | |
2850 | return reg; | |
2851 | } | |
a3170dc6 AH |
2852 | else if (SPE_VECTOR_MODE (mode)) |
2853 | { | |
2854 | /* We accept [reg + reg] and [reg + OFFSET]. */ | |
2855 | ||
2856 | if (GET_CODE (x) == PLUS) | |
2857 | { | |
2858 | rtx op1 = XEXP (x, 0); | |
2859 | rtx op2 = XEXP (x, 1); | |
2860 | ||
2861 | op1 = force_reg (Pmode, op1); | |
2862 | ||
2863 | if (GET_CODE (op2) != REG | |
2864 | && (GET_CODE (op2) != CONST_INT | |
2865 | || !SPE_CONST_OFFSET_OK (INTVAL (op2)))) | |
2866 | op2 = force_reg (Pmode, op2); | |
2867 | ||
2868 | return gen_rtx_PLUS (Pmode, op1, op2); | |
2869 | } | |
2870 | ||
2871 | return force_reg (Pmode, x); | |
2872 | } | |
f1384257 AM |
2873 | else if (TARGET_ELF |
2874 | && TARGET_32BIT | |
2875 | && TARGET_NO_TOC | |
2876 | && ! flag_pic | |
9ebbca7d GK |
2877 | && GET_CODE (x) != CONST_INT |
2878 | && GET_CODE (x) != CONST_DOUBLE | |
2879 | && CONSTANT_P (x) | |
6ac7bf2c GK |
2880 | && GET_MODE_NUNITS (mode) == 1 |
2881 | && (GET_MODE_BITSIZE (mode) <= 32 | |
a3170dc6 | 2882 | || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode))) |
9ebbca7d GK |
2883 | { |
2884 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
2885 | emit_insn (gen_elf_high (reg, x)); |
2886 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
9ebbca7d | 2887 | } |
ee890fe2 SS |
2888 | else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC |
2889 | && ! flag_pic | |
ab82a49f AP |
2890 | #if TARGET_MACHO |
2891 | && ! MACHO_DYNAMIC_NO_PIC_P | |
2892 | #endif | |
ee890fe2 SS |
2893 | && GET_CODE (x) != CONST_INT |
2894 | && GET_CODE (x) != CONST_DOUBLE | |
2895 | && CONSTANT_P (x) | |
a3170dc6 | 2896 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode) |
ee890fe2 SS |
2897 | && mode != DImode |
2898 | && mode != TImode) | |
2899 | { | |
2900 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
2901 | emit_insn (gen_macho_high (reg, x)); |
2902 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
ee890fe2 | 2903 | } |
9ebbca7d | 2904 | else if (TARGET_TOC |
4d588c14 | 2905 | && constant_pool_expr_p (x) |
a9098fd0 | 2906 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
2907 | { |
2908 | return create_TOC_reference (x); | |
2909 | } | |
2910 | else | |
2911 | return NULL_RTX; | |
2912 | } | |
258bfae2 | 2913 | |
c973d557 JJ |
2914 | /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL. |
2915 | We need to emit DTP-relative relocations. */ | |
2916 | ||
2917 | void | |
2918 | rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x) | |
2919 | { | |
2920 | switch (size) | |
2921 | { | |
2922 | case 4: | |
2923 | fputs ("\t.long\t", file); | |
2924 | break; | |
2925 | case 8: | |
2926 | fputs (DOUBLE_INT_ASM_OP, file); | |
2927 | break; | |
2928 | default: | |
2929 | abort (); | |
2930 | } | |
2931 | output_addr_const (file, x); | |
2932 | fputs ("@dtprel+0x8000", file); | |
2933 | } | |
2934 | ||
c4501e62 JJ |
2935 | /* Construct the SYMBOL_REF for the tls_get_addr function. */ |
2936 | ||
2937 | static GTY(()) rtx rs6000_tls_symbol; | |
2938 | static rtx | |
863d938c | 2939 | rs6000_tls_get_addr (void) |
c4501e62 JJ |
2940 | { |
2941 | if (!rs6000_tls_symbol) | |
2942 | rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr"); | |
2943 | ||
2944 | return rs6000_tls_symbol; | |
2945 | } | |
2946 | ||
2947 | /* Construct the SYMBOL_REF for TLS GOT references. */ | |
2948 | ||
2949 | static GTY(()) rtx rs6000_got_symbol; | |
2950 | static rtx | |
863d938c | 2951 | rs6000_got_sym (void) |
c4501e62 JJ |
2952 | { |
2953 | if (!rs6000_got_symbol) | |
2954 | { | |
2955 | rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); | |
2956 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL; | |
2957 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL; | |
2958 | } | |
2959 | ||
2960 | return rs6000_got_symbol; | |
2961 | } | |
2962 | ||
2963 | /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute | |
2964 | this (thread-local) address. */ | |
2965 | ||
2966 | static rtx | |
a2369ed3 | 2967 | rs6000_legitimize_tls_address (rtx addr, enum tls_model model) |
c4501e62 JJ |
2968 | { |
2969 | rtx dest, insn; | |
2970 | ||
2971 | dest = gen_reg_rtx (Pmode); | |
2972 | if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16) | |
2973 | { | |
2974 | rtx tlsreg; | |
2975 | ||
2976 | if (TARGET_64BIT) | |
2977 | { | |
2978 | tlsreg = gen_rtx_REG (Pmode, 13); | |
2979 | insn = gen_tls_tprel_64 (dest, tlsreg, addr); | |
2980 | } | |
2981 | else | |
2982 | { | |
2983 | tlsreg = gen_rtx_REG (Pmode, 2); | |
2984 | insn = gen_tls_tprel_32 (dest, tlsreg, addr); | |
2985 | } | |
2986 | emit_insn (insn); | |
2987 | } | |
2988 | else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32) | |
2989 | { | |
2990 | rtx tlsreg, tmp; | |
2991 | ||
2992 | tmp = gen_reg_rtx (Pmode); | |
2993 | if (TARGET_64BIT) | |
2994 | { | |
2995 | tlsreg = gen_rtx_REG (Pmode, 13); | |
2996 | insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr); | |
2997 | } | |
2998 | else | |
2999 | { | |
3000 | tlsreg = gen_rtx_REG (Pmode, 2); | |
3001 | insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr); | |
3002 | } | |
3003 | emit_insn (insn); | |
3004 | if (TARGET_64BIT) | |
3005 | insn = gen_tls_tprel_lo_64 (dest, tmp, addr); | |
3006 | else | |
3007 | insn = gen_tls_tprel_lo_32 (dest, tmp, addr); | |
3008 | emit_insn (insn); | |
3009 | } | |
3010 | else | |
3011 | { | |
3012 | rtx r3, got, tga, tmp1, tmp2, eqv; | |
3013 | ||
3014 | if (TARGET_64BIT) | |
3015 | got = gen_rtx_REG (Pmode, TOC_REGISTER); | |
3016 | else | |
3017 | { | |
3018 | if (flag_pic == 1) | |
3019 | got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); | |
3020 | else | |
3021 | { | |
3022 | rtx gsym = rs6000_got_sym (); | |
3023 | got = gen_reg_rtx (Pmode); | |
3024 | if (flag_pic == 0) | |
3025 | rs6000_emit_move (got, gsym, Pmode); | |
3026 | else | |
3027 | { | |
3028 | char buf[30]; | |
3029 | static int tls_got_labelno = 0; | |
3030 | rtx tempLR, lab, tmp3, mem; | |
3031 | rtx first, last; | |
3032 | ||
3033 | ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++); | |
3034 | lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
3035 | tempLR = gen_reg_rtx (Pmode); | |
3036 | tmp1 = gen_reg_rtx (Pmode); | |
3037 | tmp2 = gen_reg_rtx (Pmode); | |
3038 | tmp3 = gen_reg_rtx (Pmode); | |
3039 | mem = gen_rtx_MEM (Pmode, tmp1); | |
3040 | RTX_UNCHANGING_P (mem) = 1; | |
3041 | ||
3042 | first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab, | |
3043 | gsym)); | |
3044 | emit_move_insn (tmp1, tempLR); | |
3045 | emit_move_insn (tmp2, mem); | |
3046 | emit_insn (gen_addsi3 (tmp3, tmp1, tmp2)); | |
3047 | last = emit_move_insn (got, tmp3); | |
3048 | REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym, | |
3049 | REG_NOTES (last)); | |
3050 | REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, | |
3051 | REG_NOTES (first)); | |
3052 | REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, | |
3053 | REG_NOTES (last)); | |
3054 | } | |
3055 | } | |
3056 | } | |
3057 | ||
3058 | if (model == TLS_MODEL_GLOBAL_DYNAMIC) | |
3059 | { | |
3060 | r3 = gen_rtx_REG (Pmode, 3); | |
3061 | if (TARGET_64BIT) | |
3062 | insn = gen_tls_gd_64 (r3, got, addr); | |
3063 | else | |
3064 | insn = gen_tls_gd_32 (r3, got, addr); | |
3065 | start_sequence (); | |
3066 | emit_insn (insn); | |
3067 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
3068 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
3069 | insn = emit_call_insn (insn); | |
3070 | CONST_OR_PURE_CALL_P (insn) = 1; | |
3071 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
3072 | insn = get_insns (); | |
3073 | end_sequence (); | |
3074 | emit_libcall_block (insn, dest, r3, addr); | |
3075 | } | |
3076 | else if (model == TLS_MODEL_LOCAL_DYNAMIC) | |
3077 | { | |
3078 | r3 = gen_rtx_REG (Pmode, 3); | |
3079 | if (TARGET_64BIT) | |
3080 | insn = gen_tls_ld_64 (r3, got); | |
3081 | else | |
3082 | insn = gen_tls_ld_32 (r3, got); | |
3083 | start_sequence (); | |
3084 | emit_insn (insn); | |
3085 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
3086 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
3087 | insn = emit_call_insn (insn); | |
3088 | CONST_OR_PURE_CALL_P (insn) = 1; | |
3089 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
3090 | insn = get_insns (); | |
3091 | end_sequence (); | |
3092 | tmp1 = gen_reg_rtx (Pmode); | |
3093 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), | |
3094 | UNSPEC_TLSLD); | |
3095 | emit_libcall_block (insn, tmp1, r3, eqv); | |
3096 | if (rs6000_tls_size == 16) | |
3097 | { | |
3098 | if (TARGET_64BIT) | |
3099 | insn = gen_tls_dtprel_64 (dest, tmp1, addr); | |
3100 | else | |
3101 | insn = gen_tls_dtprel_32 (dest, tmp1, addr); | |
3102 | } | |
3103 | else if (rs6000_tls_size == 32) | |
3104 | { | |
3105 | tmp2 = gen_reg_rtx (Pmode); | |
3106 | if (TARGET_64BIT) | |
3107 | insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr); | |
3108 | else | |
3109 | insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr); | |
3110 | emit_insn (insn); | |
3111 | if (TARGET_64BIT) | |
3112 | insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr); | |
3113 | else | |
3114 | insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr); | |
3115 | } | |
3116 | else | |
3117 | { | |
3118 | tmp2 = gen_reg_rtx (Pmode); | |
3119 | if (TARGET_64BIT) | |
3120 | insn = gen_tls_got_dtprel_64 (tmp2, got, addr); | |
3121 | else | |
3122 | insn = gen_tls_got_dtprel_32 (tmp2, got, addr); | |
3123 | emit_insn (insn); | |
3124 | insn = gen_rtx_SET (Pmode, dest, | |
3125 | gen_rtx_PLUS (Pmode, tmp2, tmp1)); | |
3126 | } | |
3127 | emit_insn (insn); | |
3128 | } | |
3129 | else | |
3130 | { | |
3131 | /* IE, or 64 bit offset LE. */ | |
3132 | tmp2 = gen_reg_rtx (Pmode); | |
3133 | if (TARGET_64BIT) | |
3134 | insn = gen_tls_got_tprel_64 (tmp2, got, addr); | |
3135 | else | |
3136 | insn = gen_tls_got_tprel_32 (tmp2, got, addr); | |
3137 | emit_insn (insn); | |
3138 | if (TARGET_64BIT) | |
3139 | insn = gen_tls_tls_64 (dest, tmp2, addr); | |
3140 | else | |
3141 | insn = gen_tls_tls_32 (dest, tmp2, addr); | |
3142 | emit_insn (insn); | |
3143 | } | |
3144 | } | |
3145 | ||
3146 | return dest; | |
3147 | } | |
3148 | ||
3149 | /* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in | |
3150 | instruction definitions. */ | |
3151 | ||
3152 | int | |
a2369ed3 | 3153 | rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED) |
c4501e62 JJ |
3154 | { |
3155 | return RS6000_SYMBOL_REF_TLS_P (x); | |
3156 | } | |
3157 | ||
3158 | /* Return 1 if X contains a thread-local symbol. */ | |
3159 | ||
3160 | bool | |
a2369ed3 | 3161 | rs6000_tls_referenced_p (rtx x) |
c4501e62 | 3162 | { |
cd413cab AP |
3163 | if (! TARGET_HAVE_TLS) |
3164 | return false; | |
3165 | ||
c4501e62 JJ |
3166 | return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0); |
3167 | } | |
3168 | ||
3169 | /* Return 1 if *X is a thread-local symbol. This is the same as | |
3170 | rs6000_tls_symbol_ref except for the type of the unused argument. */ | |
3171 | ||
3172 | static inline int | |
a2369ed3 | 3173 | rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
3174 | { |
3175 | return RS6000_SYMBOL_REF_TLS_P (*x); | |
3176 | } | |
3177 | ||
24ea750e DJ |
3178 | /* The convention appears to be to define this wherever it is used. |
3179 | With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P | |
3180 | is now used here. */ | |
3181 | #ifndef REG_MODE_OK_FOR_BASE_P | |
3182 | #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO) | |
3183 | #endif | |
3184 | ||
3185 | /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to | |
3186 | replace the input X, or the original X if no replacement is called for. | |
3187 | The output parameter *WIN is 1 if the calling macro should goto WIN, | |
3188 | 0 if it should not. | |
3189 | ||
3190 | For RS/6000, we wish to handle large displacements off a base | |
3191 | register by splitting the addend across an addiu/addis and the mem insn. | |
3192 | This cuts number of extra insns needed from 3 to 1. | |
3193 | ||
3194 | On Darwin, we use this to generate code for floating point constants. | |
3195 | A movsf_low is generated so we wind up with 2 instructions rather than 3. | |
3196 | The Darwin code is inside #if TARGET_MACHO because only then is | |
3197 | machopic_function_base_name() defined. */ | |
3198 | rtx | |
a2369ed3 DJ |
3199 | rs6000_legitimize_reload_address (rtx x, enum machine_mode mode, |
3200 | int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win) | |
24ea750e DJ |
3201 | { |
3202 | /* We must recognize output that we have already generated ourselves. */ | |
3203 | if (GET_CODE (x) == PLUS | |
3204 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3205 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
3206 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
3207 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
3208 | { | |
3209 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3210 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3211 | opnum, (enum reload_type)type); | |
3212 | *win = 1; | |
3213 | return x; | |
3214 | } | |
3deb2758 | 3215 | |
24ea750e DJ |
3216 | #if TARGET_MACHO |
3217 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic | |
3218 | && GET_CODE (x) == LO_SUM | |
3219 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3220 | && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx | |
3221 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH | |
3222 | && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST | |
3223 | && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1) | |
3224 | && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS | |
3225 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF | |
3226 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF) | |
3227 | { | |
3228 | /* Result of previous invocation of this function on Darwin | |
6f317ef3 | 3229 | floating point constant. */ |
24ea750e DJ |
3230 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
3231 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
3232 | opnum, (enum reload_type)type); | |
3233 | *win = 1; | |
3234 | return x; | |
3235 | } | |
3236 | #endif | |
3237 | if (GET_CODE (x) == PLUS | |
3238 | && GET_CODE (XEXP (x, 0)) == REG | |
3239 | && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER | |
3240 | && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode) | |
78c875e8 | 3241 | && GET_CODE (XEXP (x, 1)) == CONST_INT |
93638d7a | 3242 | && !SPE_VECTOR_MODE (mode) |
78c875e8 | 3243 | && !ALTIVEC_VECTOR_MODE (mode)) |
24ea750e DJ |
3244 | { |
3245 | HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); | |
3246 | HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; | |
3247 | HOST_WIDE_INT high | |
3248 | = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
3249 | ||
3250 | /* Check for 32-bit overflow. */ | |
3251 | if (high + low != val) | |
3252 | { | |
3253 | *win = 0; | |
3254 | return x; | |
3255 | } | |
3256 | ||
3257 | /* Reload the high part into a base reg; leave the low part | |
3258 | in the mem directly. */ | |
3259 | ||
3260 | x = gen_rtx_PLUS (GET_MODE (x), | |
3261 | gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), | |
3262 | GEN_INT (high)), | |
3263 | GEN_INT (low)); | |
3264 | ||
3265 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3266 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3267 | opnum, (enum reload_type)type); | |
3268 | *win = 1; | |
3269 | return x; | |
3270 | } | |
3271 | #if TARGET_MACHO | |
3272 | if (GET_CODE (x) == SYMBOL_REF | |
3273 | && DEFAULT_ABI == ABI_DARWIN | |
69ef87e2 | 3274 | && !ALTIVEC_VECTOR_MODE (mode) |
a29077da GK |
3275 | && (flag_pic || MACHO_DYNAMIC_NO_PIC_P) |
3276 | /* Don't do this for TFmode, since the result isn't offsettable. */ | |
3277 | && mode != TFmode) | |
24ea750e | 3278 | { |
a29077da GK |
3279 | if (flag_pic) |
3280 | { | |
3281 | rtx offset = gen_rtx_CONST (Pmode, | |
3282 | gen_rtx_MINUS (Pmode, x, | |
3283 | gen_rtx_SYMBOL_REF (Pmode, | |
3284 | machopic_function_base_name ()))); | |
3285 | x = gen_rtx_LO_SUM (GET_MODE (x), | |
3286 | gen_rtx_PLUS (Pmode, pic_offset_table_rtx, | |
3287 | gen_rtx_HIGH (Pmode, offset)), offset); | |
3288 | } | |
3289 | else | |
3290 | x = gen_rtx_LO_SUM (GET_MODE (x), | |
3291 | gen_rtx_HIGH (Pmode, x), x); | |
3292 | ||
24ea750e | 3293 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
a29077da GK |
3294 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, |
3295 | opnum, (enum reload_type)type); | |
24ea750e DJ |
3296 | *win = 1; |
3297 | return x; | |
3298 | } | |
3299 | #endif | |
3300 | if (TARGET_TOC | |
4d588c14 | 3301 | && constant_pool_expr_p (x) |
c1f11548 | 3302 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode)) |
24ea750e DJ |
3303 | { |
3304 | (x) = create_TOC_reference (x); | |
3305 | *win = 1; | |
3306 | return x; | |
3307 | } | |
3308 | *win = 0; | |
3309 | return x; | |
3310 | } | |
3311 | ||
258bfae2 FS |
3312 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression |
3313 | that is a valid memory address for an instruction. | |
3314 | The MODE argument is the machine mode for the MEM expression | |
3315 | that wants to use this address. | |
3316 | ||
3317 | On the RS/6000, there are four valid address: a SYMBOL_REF that | |
3318 | refers to a constant pool entry of an address (or the sum of it | |
3319 | plus a constant), a short (16-bit signed) constant plus a register, | |
3320 | the sum of two registers, or a register indirect, possibly with an | |
5bdc5878 | 3321 | auto-increment. For DFmode and DImode with a constant plus register, |
258bfae2 FS |
3322 | we must ensure that both words are addressable or PowerPC64 with offset |
3323 | word aligned. | |
3324 | ||
3325 | For modes spanning multiple registers (DFmode in 32-bit GPRs, | |
3326 | 32-bit DImode, TImode), indexed addressing cannot be used because | |
3327 | adjacent memory cells are accessed by adding word-sized offsets | |
3328 | during assembly output. */ | |
3329 | int | |
a2369ed3 | 3330 | rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict) |
258bfae2 | 3331 | { |
c4501e62 JJ |
3332 | if (RS6000_SYMBOL_REF_TLS_P (x)) |
3333 | return 0; | |
4d588c14 | 3334 | if (legitimate_indirect_address_p (x, reg_ok_strict)) |
258bfae2 FS |
3335 | return 1; |
3336 | if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) | |
0d6d6892 | 3337 | && !ALTIVEC_VECTOR_MODE (mode) |
a3170dc6 | 3338 | && !SPE_VECTOR_MODE (mode) |
258bfae2 | 3339 | && TARGET_UPDATE |
4d588c14 | 3340 | && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict)) |
258bfae2 | 3341 | return 1; |
4d588c14 | 3342 | if (legitimate_small_data_p (mode, x)) |
258bfae2 | 3343 | return 1; |
4d588c14 | 3344 | if (legitimate_constant_pool_address_p (x)) |
258bfae2 FS |
3345 | return 1; |
3346 | /* If not REG_OK_STRICT (before reload) let pass any stack offset. */ | |
3347 | if (! reg_ok_strict | |
3348 | && GET_CODE (x) == PLUS | |
3349 | && GET_CODE (XEXP (x, 0)) == REG | |
708d2456 HP |
3350 | && (XEXP (x, 0) == virtual_stack_vars_rtx |
3351 | || XEXP (x, 0) == arg_pointer_rtx) | |
258bfae2 FS |
3352 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
3353 | return 1; | |
4d588c14 | 3354 | if (legitimate_offset_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3355 | return 1; |
3356 | if (mode != TImode | |
a3170dc6 AH |
3357 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
3358 | || TARGET_POWERPC64 | |
fcce224d | 3359 | || (mode != DFmode && mode != TFmode)) |
258bfae2 | 3360 | && (TARGET_POWERPC64 || mode != DImode) |
4d588c14 | 3361 | && legitimate_indexed_address_p (x, reg_ok_strict)) |
258bfae2 | 3362 | return 1; |
4d588c14 | 3363 | if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3364 | return 1; |
3365 | return 0; | |
3366 | } | |
4d588c14 RH |
3367 | |
3368 | /* Go to LABEL if ADDR (a legitimate address expression) | |
3369 | has an effect that depends on the machine mode it is used for. | |
3370 | ||
3371 | On the RS/6000 this is true of all integral offsets (since AltiVec | |
3372 | modes don't allow them) or is a pre-increment or decrement. | |
3373 | ||
3374 | ??? Except that due to conceptual problems in offsettable_address_p | |
3375 | we can't really report the problems of integral offsets. So leave | |
3376 | this assuming that the adjustable offset must be valid for the | |
3377 | sub-words of a TFmode operand, which is what we had before. */ | |
3378 | ||
3379 | bool | |
a2369ed3 | 3380 | rs6000_mode_dependent_address (rtx addr) |
4d588c14 RH |
3381 | { |
3382 | switch (GET_CODE (addr)) | |
3383 | { | |
3384 | case PLUS: | |
3385 | if (GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
3386 | { | |
3387 | unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1)); | |
3388 | return val + 12 + 0x8000 >= 0x10000; | |
3389 | } | |
3390 | break; | |
3391 | ||
3392 | case LO_SUM: | |
3393 | return true; | |
3394 | ||
3395 | case PRE_INC: | |
3396 | case PRE_DEC: | |
3397 | return TARGET_UPDATE; | |
3398 | ||
3399 | default: | |
3400 | break; | |
3401 | } | |
3402 | ||
3403 | return false; | |
3404 | } | |
d8ecbcdb AH |
3405 | |
3406 | /* Return number of consecutive hard regs needed starting at reg REGNO | |
3407 | to hold something of mode MODE. | |
3408 | This is ordinarily the length in words of a value of mode MODE | |
3409 | but can be less for certain modes in special long registers. | |
3410 | ||
3411 | For the SPE, GPRs are 64 bits but only 32 bits are visible in | |
3412 | scalar instructions. The upper 32 bits are only available to the | |
3413 | SIMD instructions. | |
3414 | ||
3415 | POWER and PowerPC GPRs hold 32 bits worth; | |
3416 | PowerPC64 GPRs and FPRs point register holds 64 bits worth. */ | |
3417 | ||
3418 | int | |
3419 | rs6000_hard_regno_nregs (int regno, enum machine_mode mode) | |
3420 | { | |
3421 | if (FP_REGNO_P (regno)) | |
3422 | return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD; | |
3423 | ||
3424 | if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
3425 | return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD; | |
3426 | ||
3427 | if (ALTIVEC_REGNO_P (regno)) | |
3428 | return | |
3429 | (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD; | |
3430 | ||
3431 | return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
3432 | } | |
2aa4498c AH |
3433 | |
3434 | /* Change register usage conditional on target flags. */ | |
3435 | void | |
3436 | rs6000_conditional_register_usage (void) | |
3437 | { | |
3438 | int i; | |
3439 | ||
3440 | /* Set MQ register fixed (already call_used) if not POWER | |
3441 | architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not | |
3442 | be allocated. */ | |
3443 | if (! TARGET_POWER) | |
3444 | fixed_regs[64] = 1; | |
3445 | ||
3446 | /* 64-bit AIX reserves GPR13 for thread-private data. */ | |
3447 | if (TARGET_64BIT) | |
3448 | fixed_regs[13] = call_used_regs[13] | |
3449 | = call_really_used_regs[13] = 1; | |
3450 | ||
3451 | /* Conditionally disable FPRs. */ | |
3452 | if (TARGET_SOFT_FLOAT || !TARGET_FPRS) | |
3453 | for (i = 32; i < 64; i++) | |
3454 | fixed_regs[i] = call_used_regs[i] | |
3455 | = call_really_used_regs[i] = 1; | |
3456 | ||
3457 | if (DEFAULT_ABI == ABI_V4 | |
3458 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM | |
3459 | && flag_pic == 2) | |
3460 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3461 | ||
3462 | if (DEFAULT_ABI == ABI_V4 | |
3463 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM | |
3464 | && flag_pic == 1) | |
3465 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3466 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3467 | = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3468 | ||
3469 | if (DEFAULT_ABI == ABI_DARWIN | |
3470 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) | |
3471 | global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3472 | = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3473 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3474 | = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3475 | ||
3476 | if (TARGET_ALTIVEC) | |
3477 | global_regs[VSCR_REGNO] = 1; | |
3478 | ||
3479 | if (TARGET_SPE) | |
3480 | { | |
3481 | global_regs[SPEFSCR_REGNO] = 1; | |
3482 | fixed_regs[FIXED_SCRATCH] | |
3483 | = call_used_regs[FIXED_SCRATCH] | |
3484 | = call_really_used_regs[FIXED_SCRATCH] = 1; | |
3485 | } | |
3486 | ||
3487 | if (! TARGET_ALTIVEC) | |
3488 | { | |
3489 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
3490 | fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1; | |
3491 | call_really_used_regs[VRSAVE_REGNO] = 1; | |
3492 | } | |
3493 | ||
3494 | if (TARGET_ALTIVEC_ABI) | |
3495 | for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i) | |
3496 | call_used_regs[i] = call_really_used_regs[i] = 1; | |
3497 | } | |
fb4d4348 | 3498 | \f |
a4f6c312 SS |
3499 | /* Try to output insns to set TARGET equal to the constant C if it can |
3500 | be done in less than N insns. Do all computations in MODE. | |
3501 | Returns the place where the output has been placed if it can be | |
3502 | done and the insns have been emitted. If it would take more than N | |
3503 | insns, zero is returned and no insns and emitted. */ | |
2bfcf297 DB |
3504 | |
3505 | rtx | |
a2369ed3 DJ |
3506 | rs6000_emit_set_const (rtx dest, enum machine_mode mode, |
3507 | rtx source, int n ATTRIBUTE_UNUSED) | |
2bfcf297 | 3508 | { |
af8cb5c5 | 3509 | rtx result, insn, set; |
2bfcf297 DB |
3510 | HOST_WIDE_INT c0, c1; |
3511 | ||
af8cb5c5 | 3512 | if (mode == QImode || mode == HImode) |
2bfcf297 DB |
3513 | { |
3514 | if (dest == NULL) | |
3515 | dest = gen_reg_rtx (mode); | |
3516 | emit_insn (gen_rtx_SET (VOIDmode, dest, source)); | |
3517 | return dest; | |
3518 | } | |
af8cb5c5 | 3519 | else if (mode == SImode) |
2bfcf297 | 3520 | { |
af8cb5c5 DE |
3521 | result = no_new_pseudos ? dest : gen_reg_rtx (SImode); |
3522 | ||
3523 | emit_insn (gen_rtx_SET (VOIDmode, result, | |
3524 | GEN_INT (INTVAL (source) | |
3525 | & (~ (HOST_WIDE_INT) 0xffff)))); | |
3526 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3527 | gen_rtx_IOR (SImode, result, | |
3528 | GEN_INT (INTVAL (source) & 0xffff)))); | |
3529 | result = dest; | |
2bfcf297 | 3530 | } |
af8cb5c5 | 3531 | else if (mode == DImode) |
2bfcf297 | 3532 | { |
af8cb5c5 DE |
3533 | if (GET_CODE (source) == CONST_INT) |
3534 | { | |
3535 | c0 = INTVAL (source); | |
3536 | c1 = -(c0 < 0); | |
3537 | } | |
3538 | else if (GET_CODE (source) == CONST_DOUBLE) | |
3539 | { | |
2bfcf297 | 3540 | #if HOST_BITS_PER_WIDE_INT >= 64 |
af8cb5c5 DE |
3541 | c0 = CONST_DOUBLE_LOW (source); |
3542 | c1 = -(c0 < 0); | |
2bfcf297 | 3543 | #else |
af8cb5c5 DE |
3544 | c0 = CONST_DOUBLE_LOW (source); |
3545 | c1 = CONST_DOUBLE_HIGH (source); | |
2bfcf297 | 3546 | #endif |
af8cb5c5 DE |
3547 | } |
3548 | else | |
3549 | abort (); | |
3550 | ||
3551 | result = rs6000_emit_set_long_const (dest, c0, c1); | |
2bfcf297 DB |
3552 | } |
3553 | else | |
a4f6c312 | 3554 | abort (); |
2bfcf297 | 3555 | |
af8cb5c5 DE |
3556 | insn = get_last_insn (); |
3557 | set = single_set (insn); | |
3558 | if (! CONSTANT_P (SET_SRC (set))) | |
3559 | set_unique_reg_note (insn, REG_EQUAL, source); | |
3560 | ||
3561 | return result; | |
2bfcf297 DB |
3562 | } |
3563 | ||
3564 | /* Having failed to find a 3 insn sequence in rs6000_emit_set_const, | |
3565 | fall back to a straight forward decomposition. We do this to avoid | |
3566 | exponential run times encountered when looking for longer sequences | |
3567 | with rs6000_emit_set_const. */ | |
3568 | static rtx | |
a2369ed3 | 3569 | rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2) |
2bfcf297 DB |
3570 | { |
3571 | if (!TARGET_POWERPC64) | |
3572 | { | |
3573 | rtx operand1, operand2; | |
3574 | ||
3575 | operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0, | |
3576 | DImode); | |
3577 | operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, | |
3578 | DImode); | |
3579 | emit_move_insn (operand1, GEN_INT (c1)); | |
3580 | emit_move_insn (operand2, GEN_INT (c2)); | |
3581 | } | |
3582 | else | |
3583 | { | |
bc06712d | 3584 | HOST_WIDE_INT ud1, ud2, ud3, ud4; |
252b88f7 | 3585 | |
bc06712d | 3586 | ud1 = c1 & 0xffff; |
f921c9c9 | 3587 | ud2 = (c1 & 0xffff0000) >> 16; |
2bfcf297 | 3588 | #if HOST_BITS_PER_WIDE_INT >= 64 |
bc06712d | 3589 | c2 = c1 >> 32; |
2bfcf297 | 3590 | #endif |
bc06712d | 3591 | ud3 = c2 & 0xffff; |
f921c9c9 | 3592 | ud4 = (c2 & 0xffff0000) >> 16; |
2bfcf297 | 3593 | |
bc06712d TR |
3594 | if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) |
3595 | || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) | |
2bfcf297 | 3596 | { |
bc06712d | 3597 | if (ud1 & 0x8000) |
b78d48dd | 3598 | emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000))); |
bc06712d TR |
3599 | else |
3600 | emit_move_insn (dest, GEN_INT (ud1)); | |
2bfcf297 | 3601 | } |
2bfcf297 | 3602 | |
bc06712d TR |
3603 | else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000)) |
3604 | || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000))) | |
252b88f7 | 3605 | { |
bc06712d TR |
3606 | if (ud2 & 0x8000) |
3607 | emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000) | |
3608 | - 0x80000000)); | |
252b88f7 | 3609 | else |
bc06712d TR |
3610 | emit_move_insn (dest, GEN_INT (ud2 << 16)); |
3611 | if (ud1 != 0) | |
3612 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
252b88f7 | 3613 | } |
bc06712d TR |
3614 | else if ((ud4 == 0xffff && (ud3 & 0x8000)) |
3615 | || (ud4 == 0 && ! (ud3 & 0x8000))) | |
3616 | { | |
3617 | if (ud3 & 0x8000) | |
3618 | emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000) | |
3619 | - 0x80000000)); | |
3620 | else | |
3621 | emit_move_insn (dest, GEN_INT (ud3 << 16)); | |
3622 | ||
3623 | if (ud2 != 0) | |
3624 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2))); | |
3625 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16))); | |
3626 | if (ud1 != 0) | |
3627 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
3628 | } | |
3629 | else | |
3630 | { | |
3631 | if (ud4 & 0x8000) | |
3632 | emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000) | |
3633 | - 0x80000000)); | |
3634 | else | |
3635 | emit_move_insn (dest, GEN_INT (ud4 << 16)); | |
3636 | ||
3637 | if (ud3 != 0) | |
3638 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3))); | |
2bfcf297 | 3639 | |
bc06712d TR |
3640 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32))); |
3641 | if (ud2 != 0) | |
3642 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, | |
3643 | GEN_INT (ud2 << 16))); | |
3644 | if (ud1 != 0) | |
3645 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
3646 | } | |
3647 | } | |
2bfcf297 DB |
3648 | return dest; |
3649 | } | |
3650 | ||
fb4d4348 GK |
3651 | /* Emit a move from SOURCE to DEST in mode MODE. */ |
3652 | void | |
a2369ed3 | 3653 | rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode) |
fb4d4348 GK |
3654 | { |
3655 | rtx operands[2]; | |
3656 | operands[0] = dest; | |
3657 | operands[1] = source; | |
3658 | ||
3659 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ | |
3660 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
3661 | && ! FLOAT_MODE_P (mode) | |
3662 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
3663 | { | |
3664 | /* FIXME. This should never happen. */ | |
3665 | /* Since it seems that it does, do the safe thing and convert | |
3666 | to a CONST_INT. */ | |
2496c7bd | 3667 | operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode); |
fb4d4348 GK |
3668 | } |
3669 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
3670 | && ! FLOAT_MODE_P (mode) | |
3671 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
3672 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
3673 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
3674 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
3675 | abort (); | |
c9e8cb32 DD |
3676 | |
3677 | /* Check if GCC is setting up a block move that will end up using FP | |
3678 | registers as temporaries. We must make sure this is acceptable. */ | |
3679 | if (GET_CODE (operands[0]) == MEM | |
3680 | && GET_CODE (operands[1]) == MEM | |
3681 | && mode == DImode | |
41543739 GK |
3682 | && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0])) |
3683 | || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1]))) | |
3684 | && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32 | |
3685 | ? 32 : MEM_ALIGN (operands[0]))) | |
3686 | || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32 | |
3687 | ? 32 | |
3688 | : MEM_ALIGN (operands[1])))) | |
3689 | && ! MEM_VOLATILE_P (operands [0]) | |
3690 | && ! MEM_VOLATILE_P (operands [1])) | |
c9e8cb32 | 3691 | { |
41543739 GK |
3692 | emit_move_insn (adjust_address (operands[0], SImode, 0), |
3693 | adjust_address (operands[1], SImode, 0)); | |
3694 | emit_move_insn (adjust_address (operands[0], SImode, 4), | |
3695 | adjust_address (operands[1], SImode, 4)); | |
c9e8cb32 DD |
3696 | return; |
3697 | } | |
630d42a0 | 3698 | |
67cef334 DE |
3699 | if (!no_new_pseudos) |
3700 | { | |
3701 | if (GET_CODE (operands[1]) == MEM && optimize > 0 | |
3702 | && (mode == QImode || mode == HImode || mode == SImode) | |
3703 | && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode)) | |
3704 | { | |
3705 | rtx reg = gen_reg_rtx (word_mode); | |
3706 | ||
3707 | emit_insn (gen_rtx_SET (word_mode, reg, | |
3708 | gen_rtx_ZERO_EXTEND (word_mode, | |
3709 | operands[1]))); | |
3710 | operands[1] = gen_lowpart (mode, reg); | |
3711 | } | |
3712 | if (GET_CODE (operands[0]) != REG) | |
3713 | operands[1] = force_reg (mode, operands[1]); | |
3714 | } | |
a9098fd0 | 3715 | |
a3170dc6 AH |
3716 | if (mode == SFmode && ! TARGET_POWERPC |
3717 | && TARGET_HARD_FLOAT && TARGET_FPRS | |
ffc14f31 | 3718 | && GET_CODE (operands[0]) == MEM) |
fb4d4348 | 3719 | { |
ffc14f31 GK |
3720 | int regnum; |
3721 | ||
3722 | if (reload_in_progress || reload_completed) | |
3723 | regnum = true_regnum (operands[1]); | |
3724 | else if (GET_CODE (operands[1]) == REG) | |
3725 | regnum = REGNO (operands[1]); | |
3726 | else | |
3727 | regnum = -1; | |
fb4d4348 GK |
3728 | |
3729 | /* If operands[1] is a register, on POWER it may have | |
3730 | double-precision data in it, so truncate it to single | |
3731 | precision. */ | |
3732 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
3733 | { | |
3734 | rtx newreg; | |
3735 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
3736 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
3737 | operands[1] = newreg; | |
3738 | } | |
3739 | } | |
3740 | ||
c4501e62 JJ |
3741 | /* Recognize the case where operand[1] is a reference to thread-local |
3742 | data and load its address to a register. */ | |
3743 | if (GET_CODE (operands[1]) == SYMBOL_REF) | |
3744 | { | |
3745 | enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]); | |
3746 | if (model != 0) | |
3747 | operands[1] = rs6000_legitimize_tls_address (operands[1], model); | |
3748 | } | |
3749 | ||
8f4e6caf RH |
3750 | /* Handle the case where reload calls us with an invalid address. */ |
3751 | if (reload_in_progress && mode == Pmode | |
69ef87e2 | 3752 | && (! general_operand (operands[1], mode) |
8f4e6caf RH |
3753 | || ! nonimmediate_operand (operands[0], mode))) |
3754 | goto emit_set; | |
3755 | ||
a9baceb1 GK |
3756 | /* 128-bit constant floating-point values on Darwin should really be |
3757 | loaded as two parts. */ | |
3758 | if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) | |
3759 | && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128 | |
3760 | && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE) | |
3761 | { | |
3762 | /* DImode is used, not DFmode, because simplify_gen_subreg doesn't | |
3763 | know how to get a DFmode SUBREG of a TFmode. */ | |
3764 | rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0), | |
3765 | simplify_gen_subreg (DImode, operands[1], mode, 0), | |
3766 | DImode); | |
3767 | rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, | |
3768 | GET_MODE_SIZE (DImode)), | |
3769 | simplify_gen_subreg (DImode, operands[1], mode, | |
3770 | GET_MODE_SIZE (DImode)), | |
3771 | DImode); | |
3772 | return; | |
3773 | } | |
3774 | ||
fb4d4348 GK |
3775 | /* FIXME: In the long term, this switch statement should go away |
3776 | and be replaced by a sequence of tests based on things like | |
3777 | mode == Pmode. */ | |
3778 | switch (mode) | |
3779 | { | |
3780 | case HImode: | |
3781 | case QImode: | |
3782 | if (CONSTANT_P (operands[1]) | |
3783 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 3784 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3785 | break; |
3786 | ||
06f4e019 | 3787 | case TFmode: |
fb4d4348 GK |
3788 | case DFmode: |
3789 | case SFmode: | |
3790 | if (CONSTANT_P (operands[1]) | |
3791 | && ! easy_fp_constant (operands[1], mode)) | |
a9098fd0 | 3792 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3793 | break; |
3794 | ||
0ac081f6 AH |
3795 | case V16QImode: |
3796 | case V8HImode: | |
3797 | case V4SFmode: | |
3798 | case V4SImode: | |
a3170dc6 AH |
3799 | case V4HImode: |
3800 | case V2SFmode: | |
3801 | case V2SImode: | |
00a892b8 | 3802 | case V1DImode: |
69ef87e2 | 3803 | if (CONSTANT_P (operands[1]) |
d744e06e | 3804 | && !easy_vector_constant (operands[1], mode)) |
0ac081f6 AH |
3805 | operands[1] = force_const_mem (mode, operands[1]); |
3806 | break; | |
3807 | ||
fb4d4348 | 3808 | case SImode: |
a9098fd0 | 3809 | case DImode: |
fb4d4348 GK |
3810 | /* Use default pattern for address of ELF small data */ |
3811 | if (TARGET_ELF | |
a9098fd0 | 3812 | && mode == Pmode |
f607bc57 | 3813 | && DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
3814 | && (GET_CODE (operands[1]) == SYMBOL_REF |
3815 | || GET_CODE (operands[1]) == CONST) | |
3816 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
3817 | { |
3818 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
3819 | return; | |
3820 | } | |
3821 | ||
f607bc57 | 3822 | if (DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
3823 | && mode == Pmode && mode == SImode |
3824 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
3825 | { |
3826 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
3827 | return; | |
3828 | } | |
3829 | ||
ee890fe2 | 3830 | if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN) |
f1384257 AM |
3831 | && TARGET_NO_TOC |
3832 | && ! flag_pic | |
a9098fd0 | 3833 | && mode == Pmode |
fb4d4348 GK |
3834 | && CONSTANT_P (operands[1]) |
3835 | && GET_CODE (operands[1]) != HIGH | |
3836 | && GET_CODE (operands[1]) != CONST_INT) | |
3837 | { | |
a9098fd0 | 3838 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
3839 | |
3840 | /* If this is a function address on -mcall-aixdesc, | |
3841 | convert it to the address of the descriptor. */ | |
3842 | if (DEFAULT_ABI == ABI_AIX | |
3843 | && GET_CODE (operands[1]) == SYMBOL_REF | |
3844 | && XSTR (operands[1], 0)[0] == '.') | |
3845 | { | |
3846 | const char *name = XSTR (operands[1], 0); | |
3847 | rtx new_ref; | |
3848 | while (*name == '.') | |
3849 | name++; | |
3850 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
3851 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
3852 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
d1908feb | 3853 | SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]); |
fb4d4348 | 3854 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); |
d1908feb | 3855 | SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]); |
fb4d4348 GK |
3856 | operands[1] = new_ref; |
3857 | } | |
7509c759 | 3858 | |
ee890fe2 SS |
3859 | if (DEFAULT_ABI == ABI_DARWIN) |
3860 | { | |
ab82a49f AP |
3861 | #if TARGET_MACHO |
3862 | if (MACHO_DYNAMIC_NO_PIC_P) | |
3863 | { | |
3864 | /* Take care of any required data indirection. */ | |
3865 | operands[1] = rs6000_machopic_legitimize_pic_address ( | |
3866 | operands[1], mode, operands[0]); | |
3867 | if (operands[0] != operands[1]) | |
3868 | emit_insn (gen_rtx_SET (VOIDmode, | |
3869 | operands[0], operands[1])); | |
3870 | return; | |
3871 | } | |
3872 | #endif | |
ee890fe2 SS |
3873 | emit_insn (gen_macho_high (target, operands[1])); |
3874 | emit_insn (gen_macho_low (operands[0], target, operands[1])); | |
3875 | return; | |
3876 | } | |
3877 | ||
fb4d4348 GK |
3878 | emit_insn (gen_elf_high (target, operands[1])); |
3879 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
3880 | return; | |
3881 | } | |
3882 | ||
a9098fd0 GK |
3883 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
3884 | and we have put it in the TOC, we just need to make a TOC-relative | |
3885 | reference to it. */ | |
3886 | if (TARGET_TOC | |
3887 | && GET_CODE (operands[1]) == SYMBOL_REF | |
4d588c14 | 3888 | && constant_pool_expr_p (operands[1]) |
a9098fd0 GK |
3889 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), |
3890 | get_pool_mode (operands[1]))) | |
fb4d4348 | 3891 | { |
a9098fd0 | 3892 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 3893 | } |
a9098fd0 GK |
3894 | else if (mode == Pmode |
3895 | && CONSTANT_P (operands[1]) | |
38886f37 AO |
3896 | && ((GET_CODE (operands[1]) != CONST_INT |
3897 | && ! easy_fp_constant (operands[1], mode)) | |
3898 | || (GET_CODE (operands[1]) == CONST_INT | |
3899 | && num_insns_constant (operands[1], mode) > 2) | |
3900 | || (GET_CODE (operands[0]) == REG | |
3901 | && FP_REGNO_P (REGNO (operands[0])))) | |
a9098fd0 | 3902 | && GET_CODE (operands[1]) != HIGH |
4d588c14 RH |
3903 | && ! legitimate_constant_pool_address_p (operands[1]) |
3904 | && ! toc_relative_expr_p (operands[1])) | |
fb4d4348 GK |
3905 | { |
3906 | /* Emit a USE operation so that the constant isn't deleted if | |
3907 | expensive optimizations are turned on because nobody | |
3908 | references it. This should only be done for operands that | |
3909 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
3910 | This should not be done for operands that contain LABEL_REFs. | |
3911 | For now, we just handle the obvious case. */ | |
3912 | if (GET_CODE (operands[1]) != LABEL_REF) | |
3913 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
3914 | ||
c859cda6 | 3915 | #if TARGET_MACHO |
ee890fe2 | 3916 | /* Darwin uses a special PIC legitimizer. */ |
ab82a49f | 3917 | if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT) |
ee890fe2 | 3918 | { |
ee890fe2 SS |
3919 | operands[1] = |
3920 | rs6000_machopic_legitimize_pic_address (operands[1], mode, | |
c859cda6 DJ |
3921 | operands[0]); |
3922 | if (operands[0] != operands[1]) | |
3923 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
ee890fe2 SS |
3924 | return; |
3925 | } | |
c859cda6 | 3926 | #endif |
ee890fe2 | 3927 | |
fb4d4348 GK |
3928 | /* If we are to limit the number of things we put in the TOC and |
3929 | this is a symbol plus a constant we can add in one insn, | |
3930 | just put the symbol in the TOC and add the constant. Don't do | |
3931 | this if reload is in progress. */ | |
3932 | if (GET_CODE (operands[1]) == CONST | |
3933 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
3934 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 3935 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
3936 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
3937 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
3938 | && ! side_effects_p (operands[0])) | |
3939 | { | |
a4f6c312 SS |
3940 | rtx sym = |
3941 | force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); | |
fb4d4348 GK |
3942 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
3943 | ||
a9098fd0 GK |
3944 | sym = force_reg (mode, sym); |
3945 | if (mode == SImode) | |
3946 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
3947 | else | |
3948 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
3949 | return; |
3950 | } | |
3951 | ||
a9098fd0 | 3952 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3953 | |
3954 | if (TARGET_TOC | |
4d588c14 | 3955 | && constant_pool_expr_p (XEXP (operands[1], 0)) |
d34c5b80 DE |
3956 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P ( |
3957 | get_pool_constant (XEXP (operands[1], 0)), | |
3958 | get_pool_mode (XEXP (operands[1], 0)))) | |
a9098fd0 | 3959 | { |
ba4828e0 RK |
3960 | operands[1] |
3961 | = gen_rtx_MEM (mode, | |
3962 | create_TOC_reference (XEXP (operands[1], 0))); | |
3963 | set_mem_alias_set (operands[1], get_TOC_alias_set ()); | |
fb4d4348 | 3964 | RTX_UNCHANGING_P (operands[1]) = 1; |
a9098fd0 | 3965 | } |
fb4d4348 GK |
3966 | } |
3967 | break; | |
a9098fd0 | 3968 | |
fb4d4348 GK |
3969 | case TImode: |
3970 | if (GET_CODE (operands[0]) == MEM | |
3971 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
3972 | && ! reload_in_progress) | |
792760b9 RK |
3973 | operands[0] |
3974 | = replace_equiv_address (operands[0], | |
3975 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
fb4d4348 GK |
3976 | |
3977 | if (GET_CODE (operands[1]) == MEM | |
3978 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
3979 | && ! reload_in_progress) | |
792760b9 RK |
3980 | operands[1] |
3981 | = replace_equiv_address (operands[1], | |
3982 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
27dc0551 DE |
3983 | if (TARGET_POWER) |
3984 | { | |
3985 | emit_insn (gen_rtx_PARALLEL (VOIDmode, | |
3986 | gen_rtvec (2, | |
3987 | gen_rtx_SET (VOIDmode, | |
3988 | operands[0], operands[1]), | |
3989 | gen_rtx_CLOBBER (VOIDmode, | |
3990 | gen_rtx_SCRATCH (SImode))))); | |
3991 | return; | |
3992 | } | |
fb4d4348 GK |
3993 | break; |
3994 | ||
3995 | default: | |
3996 | abort (); | |
3997 | } | |
3998 | ||
a9098fd0 GK |
3999 | /* Above, we may have called force_const_mem which may have returned |
4000 | an invalid address. If we can, fix this up; otherwise, reload will | |
4001 | have to deal with it. */ | |
8f4e6caf RH |
4002 | if (GET_CODE (operands[1]) == MEM && ! reload_in_progress) |
4003 | operands[1] = validize_mem (operands[1]); | |
a9098fd0 | 4004 | |
8f4e6caf | 4005 | emit_set: |
fb4d4348 GK |
4006 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
4007 | } | |
4697a36c | 4008 | \f |
2858f73a GK |
4009 | /* Nonzero if we can use a floating-point register to pass this arg. */ |
4010 | #define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \ | |
4011 | (GET_MODE_CLASS (MODE) == MODE_FLOAT \ | |
4012 | && (CUM)->fregno <= FP_ARG_MAX_REG \ | |
4013 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
4014 | ||
4015 | /* Nonzero if we can use an AltiVec register to pass this arg. */ | |
4016 | #define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \ | |
4017 | (ALTIVEC_VECTOR_MODE (MODE) \ | |
4018 | && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \ | |
4019 | && TARGET_ALTIVEC_ABI \ | |
83953138 | 4020 | && (NAMED)) |
2858f73a | 4021 | |
c6e8c921 GK |
4022 | /* Return a nonzero value to say to return the function value in |
4023 | memory, just as large structures are always returned. TYPE will be | |
4024 | the data type of the value, and FNTYPE will be the type of the | |
4025 | function doing the returning, or @code{NULL} for libcalls. | |
4026 | ||
4027 | The AIX ABI for the RS/6000 specifies that all structures are | |
4028 | returned in memory. The Darwin ABI does the same. The SVR4 ABI | |
4029 | specifies that structures <= 8 bytes are returned in r3/r4, but a | |
4030 | draft put them in memory, and GCC used to implement the draft | |
4031 | instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET | |
4032 | controls this instead of DEFAULT_ABI; V.4 targets needing backward | |
4033 | compatibility can change DRAFT_V4_STRUCT_RET to override the | |
4034 | default, and -m switches get the final word. See | |
4035 | rs6000_override_options for more details. | |
4036 | ||
4037 | The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit | |
4038 | long double support is enabled. These values are returned in memory. | |
4039 | ||
4040 | int_size_in_bytes returns -1 for variable size objects, which go in | |
4041 | memory always. The cast to unsigned makes -1 > 8. */ | |
4042 | ||
4043 | static bool | |
4044 | rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED) | |
4045 | { | |
4046 | if (AGGREGATE_TYPE_P (type) | |
4047 | && (TARGET_AIX_STRUCT_RET | |
4048 | || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8)) | |
4049 | return true; | |
4050 | if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode) | |
4051 | return true; | |
4052 | return false; | |
4053 | } | |
4054 | ||
4697a36c MM |
4055 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
4056 | for a call to a function whose data type is FNTYPE. | |
4057 | For a library call, FNTYPE is 0. | |
4058 | ||
4059 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 4060 | so we never return a PARALLEL. */ |
4697a36c MM |
4061 | |
4062 | void | |
a2369ed3 | 4063 | init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, |
0f6937fe AM |
4064 | rtx libname ATTRIBUTE_UNUSED, int incoming, |
4065 | int libcall, int n_named_args) | |
4697a36c MM |
4066 | { |
4067 | static CUMULATIVE_ARGS zero_cumulative; | |
4068 | ||
4069 | *cum = zero_cumulative; | |
4070 | cum->words = 0; | |
4071 | cum->fregno = FP_ARG_MIN_REG; | |
0ac081f6 | 4072 | cum->vregno = ALTIVEC_ARG_MIN_REG; |
4697a36c | 4073 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); |
ddcc8263 DE |
4074 | cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall) |
4075 | ? CALL_LIBCALL : CALL_NORMAL); | |
4cc833b7 | 4076 | cum->sysv_gregno = GP_ARG_MIN_REG; |
a6c9bed4 AH |
4077 | cum->stdarg = fntype |
4078 | && (TYPE_ARG_TYPES (fntype) != 0 | |
4079 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
4080 | != void_type_node)); | |
4697a36c | 4081 | |
0f6937fe AM |
4082 | cum->nargs_prototype = 0; |
4083 | if (incoming || cum->prototype) | |
4084 | cum->nargs_prototype = n_named_args; | |
4697a36c | 4085 | |
a5c76ee6 ZW |
4086 | /* Check for a longcall attribute. */ |
4087 | if (fntype | |
4088 | && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) | |
4089 | && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
4090 | cum->call_cookie = CALL_LONG; |
4091 | ||
4697a36c MM |
4092 | if (TARGET_DEBUG_ARG) |
4093 | { | |
4094 | fprintf (stderr, "\ninit_cumulative_args:"); | |
4095 | if (fntype) | |
4096 | { | |
4097 | tree ret_type = TREE_TYPE (fntype); | |
4098 | fprintf (stderr, " ret code = %s,", | |
4099 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
4100 | } | |
4101 | ||
6a4cee5f MM |
4102 | if (cum->call_cookie & CALL_LONG) |
4103 | fprintf (stderr, " longcall,"); | |
4104 | ||
4697a36c MM |
4105 | fprintf (stderr, " proto = %d, nargs = %d\n", |
4106 | cum->prototype, cum->nargs_prototype); | |
4107 | } | |
6d0ef01e HP |
4108 | |
4109 | if (fntype | |
4110 | && !TARGET_ALTIVEC | |
4111 | && TARGET_ALTIVEC_ABI | |
4112 | && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype)))) | |
4113 | { | |
4114 | error ("Cannot return value in vector register because" | |
4115 | " altivec instructions are disabled, use -maltivec" | |
4116 | " to enable them."); | |
4117 | } | |
4697a36c MM |
4118 | } |
4119 | \f | |
c229cba9 DE |
4120 | /* If defined, a C expression which determines whether, and in which |
4121 | direction, to pad out an argument with extra space. The value | |
4122 | should be of type `enum direction': either `upward' to pad above | |
4123 | the argument, `downward' to pad below, or `none' to inhibit | |
4124 | padding. | |
4125 | ||
4126 | For the AIX ABI structs are always stored left shifted in their | |
4127 | argument slot. */ | |
4128 | ||
9ebbca7d | 4129 | enum direction |
a2369ed3 | 4130 | function_arg_padding (enum machine_mode mode, tree type) |
c229cba9 | 4131 | { |
6e985040 AM |
4132 | #ifndef AGGREGATE_PADDING_FIXED |
4133 | #define AGGREGATE_PADDING_FIXED 0 | |
4134 | #endif | |
4135 | #ifndef AGGREGATES_PAD_UPWARD_ALWAYS | |
4136 | #define AGGREGATES_PAD_UPWARD_ALWAYS 0 | |
4137 | #endif | |
4138 | ||
4139 | if (!AGGREGATE_PADDING_FIXED) | |
4140 | { | |
4141 | /* GCC used to pass structures of the same size as integer types as | |
4142 | if they were in fact integers, ignoring FUNCTION_ARG_PADDING. | |
4143 | ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were | |
4144 | passed padded downward, except that -mstrict-align further | |
4145 | muddied the water in that multi-component structures of 2 and 4 | |
4146 | bytes in size were passed padded upward. | |
4147 | ||
4148 | The following arranges for best compatibility with previous | |
4149 | versions of gcc, but removes the -mstrict-align dependency. */ | |
4150 | if (BYTES_BIG_ENDIAN) | |
4151 | { | |
4152 | HOST_WIDE_INT size = 0; | |
4153 | ||
4154 | if (mode == BLKmode) | |
4155 | { | |
4156 | if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) | |
4157 | size = int_size_in_bytes (type); | |
4158 | } | |
4159 | else | |
4160 | size = GET_MODE_SIZE (mode); | |
4161 | ||
4162 | if (size == 1 || size == 2 || size == 4) | |
4163 | return downward; | |
4164 | } | |
4165 | return upward; | |
4166 | } | |
4167 | ||
4168 | if (AGGREGATES_PAD_UPWARD_ALWAYS) | |
4169 | { | |
4170 | if (type != 0 && AGGREGATE_TYPE_P (type)) | |
4171 | return upward; | |
4172 | } | |
c229cba9 | 4173 | |
d3704c46 KH |
4174 | /* Fall back to the default. */ |
4175 | return DEFAULT_FUNCTION_ARG_PADDING (mode, type); | |
c229cba9 DE |
4176 | } |
4177 | ||
b6c9286a MM |
4178 | /* If defined, a C expression that gives the alignment boundary, in bits, |
4179 | of an argument with the specified mode and type. If it is not defined, | |
4180 | PARM_BOUNDARY is used for all arguments. | |
4181 | ||
2310f99a | 4182 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
4183 | |
4184 | int | |
a2369ed3 | 4185 | function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED) |
b6c9286a | 4186 | { |
4ed78545 AM |
4187 | if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8) |
4188 | return 64; | |
4189 | else if (SPE_VECTOR_MODE (mode)) | |
e1f83b4d | 4190 | return 64; |
b2d04ecf | 4191 | else if (ALTIVEC_VECTOR_MODE (mode)) |
0ac081f6 | 4192 | return 128; |
9ebbca7d | 4193 | else |
b6c9286a | 4194 | return PARM_BOUNDARY; |
b6c9286a | 4195 | } |
c53bdcf5 AM |
4196 | |
4197 | /* Compute the size (in words) of a function argument. */ | |
4198 | ||
4199 | static unsigned long | |
4200 | rs6000_arg_size (enum machine_mode mode, tree type) | |
4201 | { | |
4202 | unsigned long size; | |
4203 | ||
4204 | if (mode != BLKmode) | |
4205 | size = GET_MODE_SIZE (mode); | |
4206 | else | |
4207 | size = int_size_in_bytes (type); | |
4208 | ||
4209 | if (TARGET_32BIT) | |
4210 | return (size + 3) >> 2; | |
4211 | else | |
4212 | return (size + 7) >> 3; | |
4213 | } | |
b6c9286a | 4214 | \f |
4697a36c MM |
4215 | /* Update the data in CUM to advance over an argument |
4216 | of mode MODE and data type TYPE. | |
b2d04ecf AM |
4217 | (TYPE is null for libcalls where that information may not be available.) |
4218 | ||
4219 | Note that for args passed by reference, function_arg will be called | |
4220 | with MODE and TYPE set to that of the pointer to the arg, not the arg | |
4221 | itself. */ | |
4697a36c MM |
4222 | |
4223 | void | |
a2369ed3 DJ |
4224 | function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4225 | tree type, int named) | |
4697a36c MM |
4226 | { |
4227 | cum->nargs_prototype--; | |
4228 | ||
0ac081f6 AH |
4229 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
4230 | { | |
4ed78545 AM |
4231 | bool stack = false; |
4232 | ||
2858f73a | 4233 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
6d0ef01e HP |
4234 | { |
4235 | cum->vregno++; | |
4236 | if (!TARGET_ALTIVEC) | |
4237 | error ("Cannot pass argument in vector register because" | |
4238 | " altivec instructions are disabled, use -maltivec" | |
4239 | " to enable them."); | |
4ed78545 AM |
4240 | |
4241 | /* PowerPC64 Linux and AIX allocate GPRs for a vector argument | |
4242 | even if it is going to be passed in a vector register. | |
4243 | Darwin does the same for variable-argument functions. */ | |
4244 | if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT) | |
4245 | || (cum->stdarg && DEFAULT_ABI != ABI_V4)) | |
4246 | stack = true; | |
6d0ef01e | 4247 | } |
4ed78545 AM |
4248 | else |
4249 | stack = true; | |
4250 | ||
4251 | if (stack) | |
c72d6c26 | 4252 | { |
a594a19c GK |
4253 | int align; |
4254 | ||
2858f73a GK |
4255 | /* Vector parameters must be 16-byte aligned. This places |
4256 | them at 2 mod 4 in terms of words in 32-bit mode, since | |
4257 | the parameter save area starts at offset 24 from the | |
4258 | stack. In 64-bit mode, they just have to start on an | |
4259 | even word, since the parameter save area is 16-byte | |
4260 | aligned. Space for GPRs is reserved even if the argument | |
4261 | will be passed in memory. */ | |
4262 | if (TARGET_32BIT) | |
4ed78545 | 4263 | align = (2 - cum->words) & 3; |
2858f73a GK |
4264 | else |
4265 | align = cum->words & 1; | |
c53bdcf5 | 4266 | cum->words += align + rs6000_arg_size (mode, type); |
2858f73a | 4267 | |
a594a19c GK |
4268 | if (TARGET_DEBUG_ARG) |
4269 | { | |
4270 | fprintf (stderr, "function_adv: words = %2d, align=%d, ", | |
4271 | cum->words, align); | |
4272 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n", | |
2858f73a GK |
4273 | cum->nargs_prototype, cum->prototype, |
4274 | GET_MODE_NAME (mode)); | |
a594a19c GK |
4275 | } |
4276 | } | |
0ac081f6 | 4277 | } |
a4b0320c | 4278 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) |
a6c9bed4 AH |
4279 | && !cum->stdarg |
4280 | && cum->sysv_gregno <= GP_ARG_MAX_REG) | |
a4b0320c | 4281 | cum->sysv_gregno++; |
f607bc57 | 4282 | else if (DEFAULT_ABI == ABI_V4) |
4697a36c | 4283 | { |
a3170dc6 | 4284 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 | 4285 | && (mode == SFmode || mode == DFmode)) |
4697a36c | 4286 | { |
4cc833b7 RH |
4287 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
4288 | cum->fregno++; | |
4289 | else | |
4290 | { | |
4291 | if (mode == DFmode) | |
4292 | cum->words += cum->words & 1; | |
c53bdcf5 | 4293 | cum->words += rs6000_arg_size (mode, type); |
4cc833b7 | 4294 | } |
4697a36c | 4295 | } |
4cc833b7 RH |
4296 | else |
4297 | { | |
b2d04ecf | 4298 | int n_words = rs6000_arg_size (mode, type); |
4cc833b7 RH |
4299 | int gregno = cum->sysv_gregno; |
4300 | ||
4ed78545 AM |
4301 | /* Long long and SPE vectors are put in (r3,r4), (r5,r6), |
4302 | (r7,r8) or (r9,r10). As does any other 2 word item such | |
4303 | as complex int due to a historical mistake. */ | |
4304 | if (n_words == 2) | |
4305 | gregno += (1 - gregno) & 1; | |
4cc833b7 | 4306 | |
4ed78545 | 4307 | /* Multi-reg args are not split between registers and stack. */ |
4cc833b7 RH |
4308 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
4309 | { | |
4ed78545 AM |
4310 | /* Long long and SPE vectors are aligned on the stack. |
4311 | So are other 2 word items such as complex int due to | |
4312 | a historical mistake. */ | |
4cc833b7 RH |
4313 | if (n_words == 2) |
4314 | cum->words += cum->words & 1; | |
4315 | cum->words += n_words; | |
4316 | } | |
4697a36c | 4317 | |
4cc833b7 RH |
4318 | /* Note: continuing to accumulate gregno past when we've started |
4319 | spilling to the stack indicates the fact that we've started | |
4320 | spilling to the stack to expand_builtin_saveregs. */ | |
4321 | cum->sysv_gregno = gregno + n_words; | |
4322 | } | |
4697a36c | 4323 | |
4cc833b7 RH |
4324 | if (TARGET_DEBUG_ARG) |
4325 | { | |
4326 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
4327 | cum->words, cum->fregno); | |
4328 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
4329 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
4330 | fprintf (stderr, "mode = %4s, named = %d\n", | |
4331 | GET_MODE_NAME (mode), named); | |
4332 | } | |
4697a36c MM |
4333 | } |
4334 | else | |
4cc833b7 | 4335 | { |
b2d04ecf AM |
4336 | int n_words = rs6000_arg_size (mode, type); |
4337 | int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; | |
a4f6c312 | 4338 | |
b2d04ecf AM |
4339 | /* The simple alignment calculation here works because |
4340 | function_arg_boundary / PARM_BOUNDARY will only be 1 or 2. | |
4341 | If we ever want to handle alignments larger than 8 bytes for | |
4342 | 32-bit or 16 bytes for 64-bit, then we'll need to take into | |
4343 | account the offset to the start of the parm save area. */ | |
4344 | align &= cum->words; | |
4345 | cum->words += align + n_words; | |
4697a36c | 4346 | |
a3170dc6 AH |
4347 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
4348 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
c53bdcf5 | 4349 | cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3; |
4cc833b7 RH |
4350 | |
4351 | if (TARGET_DEBUG_ARG) | |
4352 | { | |
4353 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
4354 | cum->words, cum->fregno); | |
4355 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
4356 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
4357 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
4358 | } | |
4359 | } | |
4697a36c | 4360 | } |
a6c9bed4 AH |
4361 | |
4362 | /* Determine where to put a SIMD argument on the SPE. */ | |
b78d48dd | 4363 | |
a6c9bed4 | 4364 | static rtx |
a2369ed3 DJ |
4365 | rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4366 | tree type) | |
a6c9bed4 AH |
4367 | { |
4368 | if (cum->stdarg) | |
4369 | { | |
4370 | int gregno = cum->sysv_gregno; | |
c53bdcf5 | 4371 | int n_words = rs6000_arg_size (mode, type); |
a6c9bed4 AH |
4372 | |
4373 | /* SPE vectors are put in odd registers. */ | |
4374 | if (n_words == 2 && (gregno & 1) == 0) | |
4375 | gregno += 1; | |
4376 | ||
4377 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
4378 | { | |
4379 | rtx r1, r2; | |
4380 | enum machine_mode m = SImode; | |
4381 | ||
4382 | r1 = gen_rtx_REG (m, gregno); | |
4383 | r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx); | |
4384 | r2 = gen_rtx_REG (m, gregno + 1); | |
4385 | r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4)); | |
4386 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); | |
4387 | } | |
4388 | else | |
b78d48dd | 4389 | return NULL_RTX; |
a6c9bed4 AH |
4390 | } |
4391 | else | |
4392 | { | |
4393 | if (cum->sysv_gregno <= GP_ARG_MAX_REG) | |
4394 | return gen_rtx_REG (mode, cum->sysv_gregno); | |
4395 | else | |
b78d48dd | 4396 | return NULL_RTX; |
a6c9bed4 AH |
4397 | } |
4398 | } | |
4399 | ||
b78d48dd FJ |
4400 | /* Determine where to place an argument in 64-bit mode with 32-bit ABI. */ |
4401 | ||
4402 | static rtx | |
4403 | rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, | |
4404 | tree type, int align_words) | |
4405 | { | |
4406 | if (mode == DFmode) | |
4407 | { | |
4408 | /* -mpowerpc64 with 32bit ABI splits up a DFmode argument | |
4409 | in vararg list into zero, one or two GPRs */ | |
4410 | if (align_words >= GP_ARG_NUM_REG) | |
4411 | return gen_rtx_PARALLEL (DFmode, | |
4412 | gen_rtvec (2, | |
4413 | gen_rtx_EXPR_LIST (VOIDmode, | |
4414 | NULL_RTX, const0_rtx), | |
4415 | gen_rtx_EXPR_LIST (VOIDmode, | |
4416 | gen_rtx_REG (mode, | |
4417 | cum->fregno), | |
4418 | const0_rtx))); | |
c53bdcf5 | 4419 | else if (align_words + rs6000_arg_size (mode, type) |
b78d48dd FJ |
4420 | > GP_ARG_NUM_REG) |
4421 | /* If this is partially on the stack, then we only | |
a3c9585f | 4422 | include the portion actually in registers here. */ |
b78d48dd FJ |
4423 | return gen_rtx_PARALLEL (DFmode, |
4424 | gen_rtvec (2, | |
4425 | gen_rtx_EXPR_LIST (VOIDmode, | |
4426 | gen_rtx_REG (SImode, | |
4427 | GP_ARG_MIN_REG | |
4428 | + align_words), | |
4429 | const0_rtx), | |
4430 | gen_rtx_EXPR_LIST (VOIDmode, | |
4431 | gen_rtx_REG (mode, | |
4432 | cum->fregno), | |
4433 | const0_rtx))); | |
4434 | ||
4435 | /* split a DFmode arg into two GPRs */ | |
4436 | return gen_rtx_PARALLEL (DFmode, | |
4437 | gen_rtvec (3, | |
4438 | gen_rtx_EXPR_LIST (VOIDmode, | |
4439 | gen_rtx_REG (SImode, | |
4440 | GP_ARG_MIN_REG | |
4441 | + align_words), | |
4442 | const0_rtx), | |
4443 | gen_rtx_EXPR_LIST (VOIDmode, | |
4444 | gen_rtx_REG (SImode, | |
4445 | GP_ARG_MIN_REG | |
4446 | + align_words + 1), | |
4447 | GEN_INT (4)), | |
4448 | gen_rtx_EXPR_LIST (VOIDmode, | |
4449 | gen_rtx_REG (mode, cum->fregno), | |
4450 | const0_rtx))); | |
4451 | } | |
4452 | /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one | |
4453 | or two GPRs */ | |
4454 | else if (mode == DImode) | |
4455 | { | |
4456 | if (align_words < GP_ARG_NUM_REG - 1) | |
4457 | return gen_rtx_PARALLEL (DImode, | |
4458 | gen_rtvec (2, | |
4459 | gen_rtx_EXPR_LIST (VOIDmode, | |
4460 | gen_rtx_REG (SImode, | |
4461 | GP_ARG_MIN_REG | |
4462 | + align_words), | |
4463 | const0_rtx), | |
4464 | gen_rtx_EXPR_LIST (VOIDmode, | |
4465 | gen_rtx_REG (SImode, | |
4466 | GP_ARG_MIN_REG | |
4467 | + align_words + 1), | |
4468 | GEN_INT (4)))); | |
4469 | else if (align_words == GP_ARG_NUM_REG - 1) | |
4470 | return gen_rtx_PARALLEL (DImode, | |
4471 | gen_rtvec (2, | |
4472 | gen_rtx_EXPR_LIST (VOIDmode, | |
4473 | NULL_RTX, const0_rtx), | |
4474 | gen_rtx_EXPR_LIST (VOIDmode, | |
4475 | gen_rtx_REG (SImode, | |
4476 | GP_ARG_MIN_REG | |
4477 | + align_words), | |
4478 | const0_rtx))); | |
4479 | } | |
36a454e1 | 4480 | else if (ALTIVEC_VECTOR_MODE (mode) && align_words == GP_ARG_NUM_REG - 2) |
b78d48dd | 4481 | { |
36a454e1 FJ |
4482 | /* Varargs vector regs must be saved in R9-R10. */ |
4483 | return gen_rtx_PARALLEL (mode, | |
4484 | gen_rtvec (3, | |
4485 | gen_rtx_EXPR_LIST (VOIDmode, | |
4486 | NULL_RTX, const0_rtx), | |
4487 | gen_rtx_EXPR_LIST (VOIDmode, | |
4488 | gen_rtx_REG (SImode, | |
4489 | GP_ARG_MIN_REG | |
4490 | + align_words), | |
4491 | const0_rtx), | |
4492 | gen_rtx_EXPR_LIST (VOIDmode, | |
4493 | gen_rtx_REG (SImode, | |
4494 | GP_ARG_MIN_REG | |
4495 | + align_words + 1), | |
4496 | GEN_INT (4)))); | |
4497 | } | |
4498 | else if ((mode == BLKmode || ALTIVEC_VECTOR_MODE (mode)) | |
4499 | && align_words <= (GP_ARG_NUM_REG - 1)) | |
4500 | { | |
4501 | /* AltiVec vector regs are saved in R5-R8. */ | |
b78d48dd FJ |
4502 | int k; |
4503 | int size = int_size_in_bytes (type); | |
2f7b62ef | 4504 | int no_units = ((size - 1) / 4) + 1; |
b78d48dd FJ |
4505 | int max_no_words = GP_ARG_NUM_REG - align_words; |
4506 | int rtlvec_len = no_units < max_no_words ? no_units : max_no_words; | |
4507 | rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx)); | |
4508 | ||
4509 | memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx)); | |
4510 | ||
4511 | for (k=0; k < rtlvec_len; k++) | |
4512 | rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode, | |
4513 | gen_rtx_REG (SImode, | |
4514 | GP_ARG_MIN_REG | |
4515 | + align_words + k), | |
4516 | k == 0 ? const0_rtx : GEN_INT (k*4)); | |
4517 | ||
36a454e1 FJ |
4518 | return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rtlvec)); |
4519 | } | |
b78d48dd FJ |
4520 | return NULL_RTX; |
4521 | } | |
4522 | ||
4697a36c MM |
4523 | /* Determine where to put an argument to a function. |
4524 | Value is zero to push the argument on the stack, | |
4525 | or a hard register in which to store the argument. | |
4526 | ||
4527 | MODE is the argument's machine mode. | |
4528 | TYPE is the data type of the argument (as a tree). | |
4529 | This is null for libcalls where that information may | |
4530 | not be available. | |
4531 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
4532 | the preceding args and about the function being called. | |
4533 | NAMED is nonzero if this argument is a named parameter | |
4534 | (otherwise it is an extra parameter matching an ellipsis). | |
4535 | ||
4536 | On RS/6000 the first eight words of non-FP are normally in registers | |
4537 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
4538 | Under V.4, the first 8 FP args are in registers. | |
4539 | ||
4540 | If this is floating-point and no prototype is specified, we use | |
4541 | both an FP and integer register (or possibly FP reg and stack). Library | |
b9599e46 | 4542 | functions (when CALL_LIBCALL is set) always have the proper types for args, |
4697a36c | 4543 | so we can pass the FP value just in one register. emit_library_function |
b2d04ecf AM |
4544 | doesn't support PARALLEL anyway. |
4545 | ||
4546 | Note that for args passed by reference, function_arg will be called | |
4547 | with MODE and TYPE set to that of the pointer to the arg, not the arg | |
4548 | itself. */ | |
4697a36c MM |
4549 | |
4550 | struct rtx_def * | |
a2369ed3 DJ |
4551 | function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4552 | tree type, int named) | |
4697a36c | 4553 | { |
4cc833b7 | 4554 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 4555 | |
a4f6c312 SS |
4556 | /* Return a marker to indicate whether CR1 needs to set or clear the |
4557 | bit that V.4 uses to say fp args were passed in registers. | |
4558 | Assume that we don't need the marker for software floating point, | |
4559 | or compiler generated library calls. */ | |
4697a36c MM |
4560 | if (mode == VOIDmode) |
4561 | { | |
f607bc57 | 4562 | if (abi == ABI_V4 |
7509c759 | 4563 | && cum->nargs_prototype < 0 |
b9599e46 FS |
4564 | && (cum->call_cookie & CALL_LIBCALL) == 0 |
4565 | && (cum->prototype || TARGET_NO_PROTOTYPE)) | |
7509c759 | 4566 | { |
a3170dc6 AH |
4567 | /* For the SPE, we need to crxor CR6 always. */ |
4568 | if (TARGET_SPE_ABI) | |
4569 | return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS); | |
4570 | else if (TARGET_HARD_FLOAT && TARGET_FPRS) | |
4571 | return GEN_INT (cum->call_cookie | |
4572 | | ((cum->fregno == FP_ARG_MIN_REG) | |
4573 | ? CALL_V4_SET_FP_ARGS | |
4574 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 4575 | } |
4697a36c | 4576 | |
7509c759 | 4577 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
4578 | } |
4579 | ||
2858f73a | 4580 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
c72d6c26 HP |
4581 | if (TARGET_64BIT && ! cum->prototype) |
4582 | { | |
4583 | /* Vector parameters get passed in vector register | |
4584 | and also in GPRs or memory, in absence of prototype. */ | |
4585 | int align_words; | |
4586 | rtx slot; | |
4587 | align_words = (cum->words + 1) & ~1; | |
4588 | ||
4589 | if (align_words >= GP_ARG_NUM_REG) | |
4590 | { | |
4591 | slot = NULL_RTX; | |
4592 | } | |
4593 | else | |
4594 | { | |
4595 | slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4596 | } | |
4597 | return gen_rtx_PARALLEL (mode, | |
4598 | gen_rtvec (2, | |
4599 | gen_rtx_EXPR_LIST (VOIDmode, | |
4600 | slot, const0_rtx), | |
4601 | gen_rtx_EXPR_LIST (VOIDmode, | |
4602 | gen_rtx_REG (mode, cum->vregno), | |
4603 | const0_rtx))); | |
4604 | } | |
4605 | else | |
4606 | return gen_rtx_REG (mode, cum->vregno); | |
2858f73a | 4607 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
0ac081f6 | 4608 | { |
2858f73a | 4609 | if (named || abi == ABI_V4) |
a594a19c | 4610 | return NULL_RTX; |
0ac081f6 | 4611 | else |
a594a19c GK |
4612 | { |
4613 | /* Vector parameters to varargs functions under AIX or Darwin | |
4614 | get passed in memory and possibly also in GPRs. */ | |
4615 | int align, align_words; | |
2858f73a | 4616 | enum machine_mode part_mode = mode; |
a594a19c GK |
4617 | |
4618 | /* Vector parameters must be 16-byte aligned. This places them at | |
2858f73a GK |
4619 | 2 mod 4 in terms of words in 32-bit mode, since the parameter |
4620 | save area starts at offset 24 from the stack. In 64-bit mode, | |
4621 | they just have to start on an even word, since the parameter | |
4622 | save area is 16-byte aligned. */ | |
4623 | if (TARGET_32BIT) | |
4ed78545 | 4624 | align = (2 - cum->words) & 3; |
2858f73a GK |
4625 | else |
4626 | align = cum->words & 1; | |
a594a19c GK |
4627 | align_words = cum->words + align; |
4628 | ||
4629 | /* Out of registers? Memory, then. */ | |
4630 | if (align_words >= GP_ARG_NUM_REG) | |
4631 | return NULL_RTX; | |
4632 | ||
2858f73a GK |
4633 | /* The vector value goes in GPRs. Only the part of the |
4634 | value in GPRs is reported here. */ | |
4635 | if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS) | |
4636 | > GP_ARG_NUM_REG) | |
839a4992 | 4637 | /* Fortunately, there are only two possibilities, the value |
2858f73a GK |
4638 | is either wholly in GPRs or half in GPRs and half not. */ |
4639 | part_mode = DImode; | |
4640 | ||
36a454e1 FJ |
4641 | if (TARGET_32BIT |
4642 | && (TARGET_POWERPC64 || (align_words == GP_ARG_NUM_REG - 2))) | |
4643 | return rs6000_mixed_function_arg (cum, part_mode, type, align_words); | |
4644 | else | |
4645 | return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words); | |
a594a19c | 4646 | } |
0ac081f6 | 4647 | } |
a6c9bed4 AH |
4648 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)) |
4649 | return rs6000_spe_function_arg (cum, mode, type); | |
f607bc57 | 4650 | else if (abi == ABI_V4) |
4697a36c | 4651 | { |
a3170dc6 | 4652 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 RH |
4653 | && (mode == SFmode || mode == DFmode)) |
4654 | { | |
4655 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
4656 | return gen_rtx_REG (mode, cum->fregno); | |
4657 | else | |
b78d48dd | 4658 | return NULL_RTX; |
4cc833b7 RH |
4659 | } |
4660 | else | |
4661 | { | |
b2d04ecf | 4662 | int n_words = rs6000_arg_size (mode, type); |
4cc833b7 RH |
4663 | int gregno = cum->sysv_gregno; |
4664 | ||
4ed78545 AM |
4665 | /* Long long and SPE vectors are put in (r3,r4), (r5,r6), |
4666 | (r7,r8) or (r9,r10). As does any other 2 word item such | |
4667 | as complex int due to a historical mistake. */ | |
4668 | if (n_words == 2) | |
4669 | gregno += (1 - gregno) & 1; | |
4cc833b7 | 4670 | |
4ed78545 | 4671 | /* Multi-reg args are not split between registers and stack. */ |
4cc833b7 | 4672 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) |
a6c9bed4 | 4673 | return gen_rtx_REG (mode, gregno); |
4cc833b7 | 4674 | else |
b78d48dd | 4675 | return NULL_RTX; |
4cc833b7 | 4676 | } |
4697a36c | 4677 | } |
4cc833b7 RH |
4678 | else |
4679 | { | |
b2d04ecf AM |
4680 | int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; |
4681 | int align_words = cum->words + (cum->words & align); | |
b78d48dd | 4682 | |
2858f73a | 4683 | if (USE_FP_FOR_ARG_P (cum, mode, type)) |
4cc833b7 | 4684 | { |
c53bdcf5 AM |
4685 | rtx fpr[2]; |
4686 | rtx *r; | |
4687 | bool needs_psave; | |
4688 | enum machine_mode fmode = mode; | |
4689 | int n; | |
4690 | unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3; | |
4691 | ||
4692 | if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1) | |
4693 | { | |
4694 | /* Long double split over regs and memory. */ | |
4695 | if (fmode == TFmode) | |
4696 | fmode = DFmode; | |
4697 | ||
4698 | /* Currently, we only ever need one reg here because complex | |
4699 | doubles are split. */ | |
4700 | if (cum->fregno != FP_ARG_MAX_REG - 1) | |
4701 | abort (); | |
4702 | } | |
4703 | fpr[1] = gen_rtx_REG (fmode, cum->fregno); | |
4704 | ||
4705 | /* Do we also need to pass this arg in the parameter save | |
4706 | area? */ | |
4707 | needs_psave = (type | |
4708 | && (cum->nargs_prototype <= 0 | |
4709 | || (DEFAULT_ABI == ABI_AIX | |
4710 | && TARGET_XL_CALL | |
4711 | && align_words >= GP_ARG_NUM_REG))); | |
4712 | ||
4713 | if (!needs_psave && mode == fmode) | |
4714 | return fpr[1]; | |
4cc833b7 | 4715 | |
e91fa876 FJ |
4716 | if (TARGET_32BIT && TARGET_POWERPC64 |
4717 | && mode == DFmode && cum->stdarg) | |
4718 | return rs6000_mixed_function_arg (cum, mode, type, align_words); | |
4719 | ||
c53bdcf5 AM |
4720 | /* Describe where this piece goes. */ |
4721 | r = fpr + 1; | |
4722 | *r = gen_rtx_EXPR_LIST (VOIDmode, *r, const0_rtx); | |
4723 | n = 1; | |
4724 | ||
4725 | if (needs_psave) | |
4726 | { | |
4727 | /* Now describe the part that goes in gprs or the stack. | |
4728 | This piece must come first, before the fprs. */ | |
4729 | rtx reg = NULL_RTX; | |
4730 | if (align_words < GP_ARG_NUM_REG) | |
4731 | { | |
4732 | unsigned long n_words = rs6000_arg_size (mode, type); | |
4733 | enum machine_mode rmode = mode; | |
4734 | ||
4735 | if (align_words + n_words > GP_ARG_NUM_REG) | |
4736 | /* If this is partially on the stack, then we only | |
4737 | include the portion actually in registers here. | |
4738 | We know this can only be one register because | |
4739 | complex doubles are splt. */ | |
4740 | rmode = Pmode; | |
4741 | reg = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words); | |
4742 | } | |
4743 | *--r = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx); | |
4744 | ++n; | |
4745 | } | |
4746 | ||
4747 | return gen_rtx_PARALLEL (mode, gen_rtvec_v (n, r)); | |
4cc833b7 RH |
4748 | } |
4749 | else if (align_words < GP_ARG_NUM_REG) | |
b2d04ecf AM |
4750 | { |
4751 | if (TARGET_32BIT && TARGET_POWERPC64 | |
4752 | && (mode == DImode || mode == BLKmode)) | |
4753 | return rs6000_mixed_function_arg (cum, mode, type, align_words); | |
4754 | ||
4755 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4756 | } | |
4cc833b7 RH |
4757 | else |
4758 | return NULL_RTX; | |
4697a36c | 4759 | } |
4697a36c MM |
4760 | } |
4761 | \f | |
4762 | /* For an arg passed partly in registers and partly in memory, | |
4763 | this is the number of registers used. | |
4764 | For args passed entirely in registers or entirely in memory, zero. */ | |
4765 | ||
4766 | int | |
a2369ed3 | 4767 | function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
2858f73a | 4768 | tree type, int named) |
4697a36c | 4769 | { |
c53bdcf5 AM |
4770 | int ret = 0; |
4771 | ||
f607bc57 | 4772 | if (DEFAULT_ABI == ABI_V4) |
4697a36c | 4773 | return 0; |
4697a36c | 4774 | |
c53bdcf5 AM |
4775 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named) |
4776 | && cum->nargs_prototype >= 0) | |
4777 | return 0; | |
4778 | ||
4779 | if (USE_FP_FOR_ARG_P (cum, mode, type)) | |
4697a36c | 4780 | { |
c53bdcf5 AM |
4781 | if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1) |
4782 | ret = FP_ARG_MAX_REG - cum->fregno; | |
4783 | else if (cum->nargs_prototype >= 0) | |
4697a36c MM |
4784 | return 0; |
4785 | } | |
4786 | ||
4787 | if (cum->words < GP_ARG_NUM_REG | |
c53bdcf5 AM |
4788 | && GP_ARG_NUM_REG < cum->words + rs6000_arg_size (mode, type)) |
4789 | ret = GP_ARG_NUM_REG - cum->words; | |
4697a36c | 4790 | |
c53bdcf5 AM |
4791 | if (ret != 0 && TARGET_DEBUG_ARG) |
4792 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
4697a36c | 4793 | |
c53bdcf5 | 4794 | return ret; |
4697a36c MM |
4795 | } |
4796 | \f | |
4797 | /* A C expression that indicates when an argument must be passed by | |
4798 | reference. If nonzero for an argument, a copy of that argument is | |
4799 | made in memory and a pointer to the argument is passed instead of | |
4800 | the argument itself. The pointer is passed in whatever way is | |
4801 | appropriate for passing a pointer to that type. | |
4802 | ||
b2d04ecf AM |
4803 | Under V.4, aggregates and long double are passed by reference. |
4804 | ||
4805 | As an extension to all 32-bit ABIs, AltiVec vectors are passed by | |
4806 | reference unless the AltiVec vector extension ABI is in force. | |
c8c99a68 DE |
4807 | |
4808 | As an extension to all ABIs, variable sized types are passed by | |
4809 | reference. */ | |
4697a36c MM |
4810 | |
4811 | int | |
a2369ed3 DJ |
4812 | function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED, |
4813 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
d779d0dc | 4814 | tree type, int named ATTRIBUTE_UNUSED) |
4697a36c | 4815 | { |
b2d04ecf AM |
4816 | if ((DEFAULT_ABI == ABI_V4 |
4817 | && ((type && AGGREGATE_TYPE_P (type)) | |
4818 | || mode == TFmode)) | |
4819 | || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
4820 | || (type && int_size_in_bytes (type) < 0)) | |
4697a36c MM |
4821 | { |
4822 | if (TARGET_DEBUG_ARG) | |
b2d04ecf | 4823 | fprintf (stderr, "function_arg_pass_by_reference\n"); |
4697a36c MM |
4824 | |
4825 | return 1; | |
4826 | } | |
b2d04ecf | 4827 | return 0; |
4697a36c | 4828 | } |
5985c7a6 FJ |
4829 | |
4830 | static void | |
2d9db8eb | 4831 | rs6000_move_block_from_reg (int regno, rtx x, int nregs) |
5985c7a6 FJ |
4832 | { |
4833 | int i; | |
4834 | enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode; | |
4835 | ||
4836 | if (nregs == 0) | |
4837 | return; | |
4838 | ||
4839 | for (i = 0; i < nregs; i++) | |
4840 | { | |
4841 | rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode)); | |
4842 | if (reload_completed) | |
4843 | { | |
4844 | if (! strict_memory_address_p (reg_mode, XEXP (tem, 0))) | |
4845 | tem = NULL_RTX; | |
4846 | else | |
4847 | tem = simplify_gen_subreg (reg_mode, x, BLKmode, | |
4848 | i * GET_MODE_SIZE(reg_mode)); | |
4849 | } | |
4850 | else | |
4851 | tem = replace_equiv_address (tem, XEXP (tem, 0)); | |
4852 | ||
4853 | if (tem == NULL_RTX) | |
4854 | abort (); | |
4855 | ||
4856 | emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i)); | |
4857 | } | |
4858 | } | |
4859 | ||
4697a36c MM |
4860 | \f |
4861 | /* Perform any needed actions needed for a function that is receiving a | |
4862 | variable number of arguments. | |
4863 | ||
4864 | CUM is as above. | |
4865 | ||
4866 | MODE and TYPE are the mode and type of the current parameter. | |
4867 | ||
4868 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
4869 | that must be pushed by the prolog to pretend that our caller pushed | |
4870 | it. | |
4871 | ||
4872 | Normally, this macro will push all remaining incoming registers on the | |
4873 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
4874 | ||
c6e8c921 | 4875 | static void |
a2369ed3 DJ |
4876 | setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4877 | tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl) | |
4697a36c | 4878 | { |
4cc833b7 RH |
4879 | CUMULATIVE_ARGS next_cum; |
4880 | int reg_size = TARGET_32BIT ? 4 : 8; | |
ca5adc63 | 4881 | rtx save_area = NULL_RTX, mem; |
dfafc897 | 4882 | int first_reg_offset, set; |
4697a36c | 4883 | |
f31bf321 | 4884 | /* Skip the last named argument. */ |
d34c5b80 | 4885 | next_cum = *cum; |
f31bf321 | 4886 | function_arg_advance (&next_cum, mode, type, 1); |
4cc833b7 | 4887 | |
f607bc57 | 4888 | if (DEFAULT_ABI == ABI_V4) |
d34c5b80 | 4889 | { |
4cc833b7 | 4890 | /* Indicate to allocate space on the stack for varargs save area. */ |
00dba523 | 4891 | cfun->machine->sysv_varargs_p = 1; |
60e2d0ca | 4892 | if (! no_rtl) |
2c4974b7 | 4893 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 4894 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
4895 | |
4896 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 4897 | } |
60e2d0ca | 4898 | else |
4697a36c | 4899 | { |
d34c5b80 | 4900 | first_reg_offset = next_cum.words; |
4cc833b7 | 4901 | save_area = virtual_incoming_args_rtx; |
00dba523 | 4902 | cfun->machine->sysv_varargs_p = 0; |
4697a36c MM |
4903 | |
4904 | if (MUST_PASS_IN_STACK (mode, type)) | |
c53bdcf5 | 4905 | first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type); |
4cc833b7 | 4906 | } |
4697a36c | 4907 | |
dfafc897 | 4908 | set = get_varargs_alias_set (); |
c81fc13e | 4909 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 4910 | { |
dfafc897 FS |
4911 | mem = gen_rtx_MEM (BLKmode, |
4912 | plus_constant (save_area, | |
4913 | first_reg_offset * reg_size)), | |
ba4828e0 | 4914 | set_mem_alias_set (mem, set); |
8ac61af7 | 4915 | set_mem_align (mem, BITS_PER_WORD); |
dfafc897 | 4916 | |
5985c7a6 FJ |
4917 | rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem, |
4918 | GP_ARG_NUM_REG - first_reg_offset); | |
4697a36c MM |
4919 | } |
4920 | ||
4697a36c | 4921 | /* Save FP registers if needed. */ |
f607bc57 | 4922 | if (DEFAULT_ABI == ABI_V4 |
a3170dc6 AH |
4923 | && TARGET_HARD_FLOAT && TARGET_FPRS |
4924 | && ! no_rtl | |
4cc833b7 | 4925 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 4926 | { |
4cc833b7 | 4927 | int fregno = next_cum.fregno; |
9ebbca7d | 4928 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
4929 | rtx lab = gen_label_rtx (); |
4930 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 4931 | |
4cc833b7 | 4932 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 4933 | pc_rtx, |
39403d82 | 4934 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
4935 | gen_rtx_NE (VOIDmode, cr1, |
4936 | const0_rtx), | |
39403d82 | 4937 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
4938 | pc_rtx))); |
4939 | ||
4cc833b7 RH |
4940 | while (fregno <= FP_ARG_V4_MAX_REG) |
4941 | { | |
dfafc897 | 4942 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
ba4828e0 | 4943 | set_mem_alias_set (mem, set); |
dfafc897 | 4944 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); |
4cc833b7 RH |
4945 | fregno++; |
4946 | off += 8; | |
4697a36c | 4947 | } |
4cc833b7 RH |
4948 | |
4949 | emit_label (lab); | |
4697a36c | 4950 | } |
4697a36c | 4951 | } |
4697a36c | 4952 | |
dfafc897 | 4953 | /* Create the va_list data type. */ |
2c4974b7 | 4954 | |
c35d187f RH |
4955 | static tree |
4956 | rs6000_build_builtin_va_list (void) | |
dfafc897 | 4957 | { |
64c2816f | 4958 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl; |
4697a36c | 4959 | |
9ebbca7d GK |
4960 | /* For AIX, prefer 'char *' because that's what the system |
4961 | header files like. */ | |
f607bc57 | 4962 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d | 4963 | return build_pointer_type (char_type_node); |
dfafc897 | 4964 | |
f1e639b1 | 4965 | record = (*lang_hooks.types.make_type) (RECORD_TYPE); |
bab45a51 | 4966 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 4967 | |
9ebbca7d GK |
4968 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
4969 | unsigned_char_type_node); | |
4970 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), | |
4971 | unsigned_char_type_node); | |
64c2816f DT |
4972 | /* Give the two bytes of padding a name, so that -Wpadded won't warn on |
4973 | every user file. */ | |
4974 | f_res = build_decl (FIELD_DECL, get_identifier ("reserved"), | |
4975 | short_unsigned_type_node); | |
dfafc897 FS |
4976 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
4977 | ptr_type_node); | |
4978 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
4979 | ptr_type_node); | |
4980 | ||
4981 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
4982 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
64c2816f | 4983 | DECL_FIELD_CONTEXT (f_res) = record; |
dfafc897 FS |
4984 | DECL_FIELD_CONTEXT (f_ovf) = record; |
4985 | DECL_FIELD_CONTEXT (f_sav) = record; | |
4986 | ||
bab45a51 FS |
4987 | TREE_CHAIN (record) = type_decl; |
4988 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
4989 | TYPE_FIELDS (record) = f_gpr; |
4990 | TREE_CHAIN (f_gpr) = f_fpr; | |
64c2816f DT |
4991 | TREE_CHAIN (f_fpr) = f_res; |
4992 | TREE_CHAIN (f_res) = f_ovf; | |
dfafc897 FS |
4993 | TREE_CHAIN (f_ovf) = f_sav; |
4994 | ||
4995 | layout_type (record); | |
4996 | ||
4997 | /* The correct type is an array type of one element. */ | |
4998 | return build_array_type (record, build_index_type (size_zero_node)); | |
4999 | } | |
5000 | ||
5001 | /* Implement va_start. */ | |
5002 | ||
5003 | void | |
a2369ed3 | 5004 | rs6000_va_start (tree valist, rtx nextarg) |
4697a36c | 5005 | { |
dfafc897 | 5006 | HOST_WIDE_INT words, n_gpr, n_fpr; |
c566f9bd | 5007 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
dfafc897 | 5008 | tree gpr, fpr, ovf, sav, t; |
2c4974b7 | 5009 | |
dfafc897 | 5010 | /* Only SVR4 needs something special. */ |
f607bc57 | 5011 | if (DEFAULT_ABI != ABI_V4) |
dfafc897 | 5012 | { |
e5faf155 | 5013 | std_expand_builtin_va_start (valist, nextarg); |
dfafc897 FS |
5014 | return; |
5015 | } | |
5016 | ||
973a648b | 5017 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 | 5018 | f_fpr = TREE_CHAIN (f_gpr); |
c566f9bd DT |
5019 | f_res = TREE_CHAIN (f_fpr); |
5020 | f_ovf = TREE_CHAIN (f_res); | |
dfafc897 FS |
5021 | f_sav = TREE_CHAIN (f_ovf); |
5022 | ||
8ebecc3b | 5023 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
5024 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
5025 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
5026 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
5027 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
5028 | ||
5029 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 5030 | words = current_function_args_info.words; |
dfafc897 FS |
5031 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
5032 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
5033 | ||
5034 | if (TARGET_DEBUG_ARG) | |
4a0a75dd KG |
5035 | fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = " |
5036 | HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n", | |
5037 | words, n_gpr, n_fpr); | |
dfafc897 FS |
5038 | |
5039 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
5040 | TREE_SIDE_EFFECTS (t) = 1; | |
5041 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5042 | ||
5043 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
5044 | TREE_SIDE_EFFECTS (t) = 1; | |
5045 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5046 | ||
5047 | /* Find the overflow area. */ | |
5048 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
5049 | if (words != 0) | |
5050 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
5051 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
5052 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
5053 | TREE_SIDE_EFFECTS (t) = 1; | |
5054 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5055 | ||
5056 | /* Find the register save area. */ | |
5057 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
5058 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
5059 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
5060 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
5061 | TREE_SIDE_EFFECTS (t) = 1; | |
5062 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5063 | } | |
5064 | ||
5065 | /* Implement va_arg. */ | |
5066 | ||
5067 | rtx | |
a2369ed3 | 5068 | rs6000_va_arg (tree valist, tree type) |
dfafc897 | 5069 | { |
c566f9bd | 5070 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
dfafc897 FS |
5071 | tree gpr, fpr, ovf, sav, reg, t, u; |
5072 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
5073 | rtx lab_false, lab_over, addr_rtx, r; | |
4ed78545 | 5074 | int align; |
dfafc897 | 5075 | |
f607bc57 | 5076 | if (DEFAULT_ABI != ABI_V4) |
c8c99a68 | 5077 | { |
b2d04ecf AM |
5078 | /* Variable sized types are passed by reference, as are AltiVec |
5079 | vectors when 32-bit and not using the AltiVec ABI extension. */ | |
5080 | if (int_size_in_bytes (type) < 0 | |
5081 | || (TARGET_32BIT | |
5082 | && !TARGET_ALTIVEC_ABI | |
5083 | && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))) | |
c8c99a68 DE |
5084 | { |
5085 | u = build_pointer_type (type); | |
5086 | ||
5087 | /* Args grow upward. */ | |
5088 | t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist, | |
5089 | build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0)); | |
5090 | TREE_SIDE_EFFECTS (t) = 1; | |
5091 | ||
5092 | t = build1 (NOP_EXPR, build_pointer_type (u), t); | |
5093 | TREE_SIDE_EFFECTS (t) = 1; | |
5094 | ||
5095 | t = build1 (INDIRECT_REF, u, t); | |
5096 | TREE_SIDE_EFFECTS (t) = 1; | |
5097 | ||
5098 | return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL); | |
5099 | } | |
fa78dbea | 5100 | if (targetm.calls.split_complex_arg |
c53bdcf5 AM |
5101 | && TREE_CODE (type) == COMPLEX_TYPE) |
5102 | { | |
5103 | tree elem_type = TREE_TYPE (type); | |
5104 | enum machine_mode elem_mode = TYPE_MODE (elem_type); | |
5105 | int elem_size = GET_MODE_SIZE (elem_mode); | |
5106 | ||
5107 | if (elem_size < UNITS_PER_WORD) | |
5108 | { | |
5109 | rtx real_part, imag_part, dest_real, rr; | |
5110 | ||
5111 | real_part = rs6000_va_arg (valist, elem_type); | |
5112 | imag_part = rs6000_va_arg (valist, elem_type); | |
5113 | ||
5114 | /* We're not returning the value here, but the address. | |
5115 | real_part and imag_part are not contiguous, and we know | |
5116 | there is space available to pack real_part next to | |
5117 | imag_part. float _Complex is not promoted to | |
5118 | double _Complex by the default promotion rules that | |
5119 | promote float to double. */ | |
5120 | if (2 * elem_size > UNITS_PER_WORD) | |
5121 | abort (); | |
5122 | ||
5123 | real_part = gen_rtx_MEM (elem_mode, real_part); | |
5124 | imag_part = gen_rtx_MEM (elem_mode, imag_part); | |
5125 | ||
5126 | dest_real = adjust_address (imag_part, elem_mode, -elem_size); | |
5127 | rr = gen_reg_rtx (elem_mode); | |
5128 | emit_move_insn (rr, real_part); | |
5129 | emit_move_insn (dest_real, rr); | |
5130 | ||
5131 | return XEXP (dest_real, 0); | |
5132 | } | |
5133 | } | |
5134 | ||
5135 | return std_expand_builtin_va_arg (valist, type); | |
c8c99a68 | 5136 | } |
dfafc897 | 5137 | |
973a648b | 5138 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 | 5139 | f_fpr = TREE_CHAIN (f_gpr); |
c566f9bd DT |
5140 | f_res = TREE_CHAIN (f_fpr); |
5141 | f_ovf = TREE_CHAIN (f_res); | |
dfafc897 FS |
5142 | f_sav = TREE_CHAIN (f_ovf); |
5143 | ||
8ebecc3b | 5144 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
dfafc897 FS |
5145 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr); |
5146 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr); | |
5147 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf); | |
5148 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav); | |
5149 | ||
5150 | size = int_size_in_bytes (type); | |
11c01dcc | 5151 | rsize = (size + 3) / 4; |
4ed78545 | 5152 | align = 1; |
4cc833b7 | 5153 | |
4ed78545 AM |
5154 | if (AGGREGATE_TYPE_P (type) |
5155 | || TYPE_MODE (type) == TFmode | |
5156 | || (!TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))) | |
4cc833b7 | 5157 | { |
4ed78545 AM |
5158 | /* Aggregates, long doubles, and AltiVec vectors are passed by |
5159 | reference. */ | |
dfafc897 FS |
5160 | indirect_p = 1; |
5161 | reg = gpr; | |
5162 | n_reg = 1; | |
5163 | sav_ofs = 0; | |
5164 | sav_scale = 4; | |
11c01dcc | 5165 | size = 4; |
d3294cd9 | 5166 | rsize = 1; |
dfafc897 | 5167 | } |
4ed78545 AM |
5168 | else if (TARGET_HARD_FLOAT && TARGET_FPRS |
5169 | && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode)) | |
dfafc897 FS |
5170 | { |
5171 | /* FP args go in FP registers, if present. */ | |
5172 | indirect_p = 0; | |
5173 | reg = fpr; | |
5174 | n_reg = 1; | |
5175 | sav_ofs = 8*4; | |
5176 | sav_scale = 8; | |
4ed78545 AM |
5177 | if (TYPE_MODE (type) == DFmode) |
5178 | align = 8; | |
4cc833b7 | 5179 | } |
dfafc897 FS |
5180 | else |
5181 | { | |
5182 | /* Otherwise into GP registers. */ | |
5183 | indirect_p = 0; | |
5184 | reg = gpr; | |
5185 | n_reg = rsize; | |
5186 | sav_ofs = 0; | |
5187 | sav_scale = 4; | |
4ed78545 AM |
5188 | if (n_reg == 2) |
5189 | align = 8; | |
dfafc897 FS |
5190 | } |
5191 | ||
a3c9585f | 5192 | /* Pull the value out of the saved registers.... */ |
dfafc897 | 5193 | |
4ed78545 | 5194 | lab_over = NULL_RTX; |
dfafc897 FS |
5195 | addr_rtx = gen_reg_rtx (Pmode); |
5196 | ||
4ed78545 AM |
5197 | /* AltiVec vectors never go in registers when -mabi=altivec. */ |
5198 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))) | |
5199 | align = 16; | |
5200 | else | |
2c4974b7 | 5201 | { |
4ed78545 AM |
5202 | lab_false = gen_label_rtx (); |
5203 | lab_over = gen_label_rtx (); | |
dfafc897 | 5204 | |
4ed78545 AM |
5205 | /* Long long and SPE vectors are aligned in the registers. |
5206 | As are any other 2 gpr item such as complex int due to a | |
5207 | historical mistake. */ | |
5208 | u = reg; | |
5209 | if (n_reg == 2) | |
41daaf0e AH |
5210 | { |
5211 | u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg, | |
5212 | build_int_2 (n_reg - 1, 0)); | |
4ed78545 | 5213 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u); |
41daaf0e | 5214 | TREE_SIDE_EFFECTS (u) = 1; |
41daaf0e | 5215 | } |
2c4974b7 | 5216 | |
4ed78545 AM |
5217 | emit_cmp_and_jump_insns |
5218 | (expand_expr (u, NULL_RTX, QImode, EXPAND_NORMAL), | |
5219 | GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1, | |
5220 | lab_false); | |
5221 | ||
5222 | t = sav; | |
41daaf0e AH |
5223 | if (sav_ofs) |
5224 | t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
2c4974b7 | 5225 | |
41daaf0e AH |
5226 | u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, |
5227 | build_int_2 (n_reg, 0)); | |
5228 | TREE_SIDE_EFFECTS (u) = 1; | |
2c4974b7 | 5229 | |
41daaf0e AH |
5230 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
5231 | TREE_SIDE_EFFECTS (u) = 1; | |
dfafc897 | 5232 | |
41daaf0e AH |
5233 | u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); |
5234 | TREE_SIDE_EFFECTS (u) = 1; | |
dfafc897 | 5235 | |
41daaf0e AH |
5236 | t = build (PLUS_EXPR, ptr_type_node, t, u); |
5237 | TREE_SIDE_EFFECTS (t) = 1; | |
5238 | ||
5239 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
5240 | if (r != addr_rtx) | |
5241 | emit_move_insn (addr_rtx, r); | |
5242 | ||
5243 | emit_jump_insn (gen_jump (lab_over)); | |
5244 | emit_barrier (); | |
dfafc897 | 5245 | |
4ed78545 | 5246 | emit_label (lab_false); |
11c01dcc AM |
5247 | if (n_reg > 2) |
5248 | { | |
5249 | /* Ensure that we don't find any more args in regs. | |
5250 | Alignment has taken care of the n_reg == 2 case. */ | |
5251 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
5252 | TREE_SIDE_EFFECTS (t) = 1; | |
5253 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5254 | } | |
4ed78545 | 5255 | } |
dfafc897 | 5256 | |
a4f6c312 | 5257 | /* ... otherwise out of the overflow area. */ |
dfafc897 | 5258 | |
dfafc897 | 5259 | /* Care for on-stack alignment if needed. */ |
4ed78545 AM |
5260 | t = ovf; |
5261 | if (align != 1) | |
dfafc897 | 5262 | { |
4ed78545 AM |
5263 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (align - 1, 0)); |
5264 | t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align, -1)); | |
dfafc897 FS |
5265 | } |
5266 | t = save_expr (t); | |
5267 | ||
5268 | r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL); | |
5269 | if (r != addr_rtx) | |
5270 | emit_move_insn (addr_rtx, r); | |
5271 | ||
5272 | t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
5273 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
5274 | TREE_SIDE_EFFECTS (t) = 1; | |
5275 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5276 | ||
4ed78545 AM |
5277 | if (lab_over) |
5278 | emit_label (lab_over); | |
dfafc897 FS |
5279 | |
5280 | if (indirect_p) | |
5281 | { | |
5282 | r = gen_rtx_MEM (Pmode, addr_rtx); | |
ba4828e0 | 5283 | set_mem_alias_set (r, get_varargs_alias_set ()); |
dfafc897 FS |
5284 | emit_move_insn (addr_rtx, r); |
5285 | } | |
5286 | ||
5287 | return addr_rtx; | |
4697a36c | 5288 | } |
0ac081f6 AH |
5289 | |
5290 | /* Builtins. */ | |
5291 | ||
6a2dd09a RS |
5292 | #define def_builtin(MASK, NAME, TYPE, CODE) \ |
5293 | do { \ | |
5294 | if ((MASK) & target_flags) \ | |
5295 | builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \ | |
5296 | NULL, NULL_TREE); \ | |
0ac081f6 AH |
5297 | } while (0) |
5298 | ||
24408032 AH |
5299 | /* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */ |
5300 | ||
2212663f | 5301 | static const struct builtin_description bdesc_3arg[] = |
24408032 AH |
5302 | { |
5303 | { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP }, | |
5304 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS }, | |
5305 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS }, | |
5306 | { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM}, | |
5307 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM }, | |
5308 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM }, | |
5309 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM }, | |
5310 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM }, | |
5311 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS }, | |
5312 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS }, | |
5313 | { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP }, | |
5314 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF }, | |
5315 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI }, | |
5316 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI }, | |
5317 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI }, | |
5318 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF }, | |
5319 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI }, | |
5320 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI }, | |
5321 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI }, | |
5322 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI }, | |
5323 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI }, | |
5324 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI }, | |
5325 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF }, | |
5326 | }; | |
2212663f | 5327 | |
95385cbb AH |
5328 | /* DST operations: void foo (void *, const int, const char). */ |
5329 | ||
5330 | static const struct builtin_description bdesc_dst[] = | |
5331 | { | |
5332 | { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST }, | |
5333 | { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT }, | |
5334 | { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST }, | |
5335 | { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT } | |
5336 | }; | |
5337 | ||
2212663f | 5338 | /* Simple binary operations: VECc = foo (VECa, VECb). */ |
24408032 | 5339 | |
a3170dc6 | 5340 | static struct builtin_description bdesc_2arg[] = |
0ac081f6 | 5341 | { |
f18c054f DB |
5342 | { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM }, |
5343 | { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM }, | |
5344 | { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM }, | |
5345 | { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP }, | |
0ac081f6 AH |
5346 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW }, |
5347 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS }, | |
5348 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS }, | |
5349 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS }, | |
5350 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS }, | |
5351 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS }, | |
5352 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS }, | |
f18c054f | 5353 | { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND }, |
0ac081f6 AH |
5354 | { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC }, |
5355 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB }, | |
5356 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB }, | |
5357 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH }, | |
5358 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH }, | |
5359 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW }, | |
5360 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW }, | |
617e0e1d DB |
5361 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX }, |
5362 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX }, | |
0ac081f6 AH |
5363 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP }, |
5364 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB }, | |
5365 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH }, | |
5366 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW }, | |
5367 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP }, | |
5368 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP }, | |
5369 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB }, | |
5370 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB }, | |
5371 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH }, | |
5372 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH }, | |
5373 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW }, | |
5374 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW }, | |
5375 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP }, | |
617e0e1d DB |
5376 | { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS }, |
5377 | { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS }, | |
f18c054f DB |
5378 | { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB }, |
5379 | { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB }, | |
df966bff AH |
5380 | { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH }, |
5381 | { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH }, | |
5382 | { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW }, | |
5383 | { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW }, | |
5384 | { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP }, | |
0ac081f6 AH |
5385 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB }, |
5386 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH }, | |
5387 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW }, | |
5388 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB }, | |
5389 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH }, | |
5390 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW }, | |
f18c054f DB |
5391 | { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB }, |
5392 | { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB }, | |
5393 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH }, | |
5394 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH }, | |
5395 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW }, | |
5396 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW }, | |
5397 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP }, | |
0ac081f6 AH |
5398 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB }, |
5399 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB }, | |
5400 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH }, | |
5401 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH }, | |
5402 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB }, | |
5403 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB }, | |
5404 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH }, | |
5405 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH }, | |
5406 | { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR }, | |
f18c054f | 5407 | { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR }, |
0ac081f6 AH |
5408 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM }, |
5409 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM }, | |
5410 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX }, | |
5411 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS }, | |
5412 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS }, | |
5413 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS }, | |
5414 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS }, | |
5415 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS }, | |
5416 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS }, | |
5417 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS }, | |
5418 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS }, | |
5419 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB }, | |
5420 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH }, | |
5421 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW }, | |
5422 | { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB }, | |
5423 | { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH }, | |
5424 | { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW }, | |
5425 | { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL }, | |
5426 | { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO }, | |
2212663f DB |
5427 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB }, |
5428 | { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH }, | |
5429 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW }, | |
0ac081f6 | 5430 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB }, |
f18c054f DB |
5431 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH }, |
5432 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW }, | |
0ac081f6 AH |
5433 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB }, |
5434 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH }, | |
5435 | { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW }, | |
5436 | { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR }, | |
5437 | { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO }, | |
f18c054f DB |
5438 | { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM }, |
5439 | { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM }, | |
5440 | { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM }, | |
5441 | { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP }, | |
0ac081f6 AH |
5442 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW }, |
5443 | { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS }, | |
5444 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS }, | |
5445 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS }, | |
5446 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS }, | |
5447 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS }, | |
5448 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS }, | |
5449 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS }, | |
5450 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS }, | |
5451 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS }, | |
5452 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS }, | |
5453 | { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS }, | |
f18c054f | 5454 | { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR }, |
a3170dc6 AH |
5455 | |
5456 | /* Place holder, leave as first spe builtin. */ | |
5457 | { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW }, | |
5458 | { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND }, | |
5459 | { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC }, | |
5460 | { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS }, | |
5461 | { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU }, | |
5462 | { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV }, | |
5463 | { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD }, | |
5464 | { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV }, | |
5465 | { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL }, | |
5466 | { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB }, | |
5467 | { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI }, | |
5468 | { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO }, | |
5469 | { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO }, | |
5470 | { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI }, | |
5471 | { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA }, | |
5472 | { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN }, | |
5473 | { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA }, | |
5474 | { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN }, | |
5475 | { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA }, | |
5476 | { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN }, | |
5477 | { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF }, | |
5478 | { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA }, | |
5479 | { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW }, | |
5480 | { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW }, | |
5481 | { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI }, | |
5482 | { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA }, | |
5483 | { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW }, | |
5484 | { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW }, | |
5485 | { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF }, | |
5486 | { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA }, | |
5487 | { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW }, | |
5488 | { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW }, | |
5489 | { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW }, | |
5490 | { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW }, | |
5491 | { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI }, | |
5492 | { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA }, | |
5493 | { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW }, | |
5494 | { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW }, | |
5495 | { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW }, | |
5496 | { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW }, | |
5497 | { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA }, | |
5498 | { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN }, | |
5499 | { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA }, | |
5500 | { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN }, | |
5501 | { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA }, | |
5502 | { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN }, | |
5503 | { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF }, | |
5504 | { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA }, | |
5505 | { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW }, | |
5506 | { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW }, | |
5507 | { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI }, | |
5508 | { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA }, | |
5509 | { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW }, | |
5510 | { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW }, | |
5511 | { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF }, | |
5512 | { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA }, | |
5513 | { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW }, | |
5514 | { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW }, | |
5515 | { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW }, | |
5516 | { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW }, | |
5517 | { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI }, | |
5518 | { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA }, | |
5519 | { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW }, | |
5520 | { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW }, | |
5521 | { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW }, | |
5522 | { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW }, | |
5523 | { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF }, | |
5524 | { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA }, | |
5525 | { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI }, | |
5526 | { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA }, | |
5527 | { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF }, | |
5528 | { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA }, | |
5529 | { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI }, | |
5530 | { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA }, | |
a3170dc6 AH |
5531 | { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW }, |
5532 | { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW }, | |
a3170dc6 AH |
5533 | { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW }, |
5534 | { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW }, | |
5535 | { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI }, | |
5536 | { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA }, | |
5537 | { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW }, | |
5538 | { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW }, | |
5539 | { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW }, | |
5540 | { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW }, | |
5541 | { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF }, | |
5542 | { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA }, | |
5543 | { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA }, | |
5544 | { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN }, | |
5545 | { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI }, | |
5546 | { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA }, | |
5547 | { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA }, | |
5548 | { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN }, | |
5549 | { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF }, | |
5550 | { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA }, | |
5551 | { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA }, | |
5552 | { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN }, | |
5553 | { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI }, | |
5554 | { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA }, | |
5555 | { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA }, | |
5556 | { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN }, | |
5557 | { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND }, | |
5558 | { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR }, | |
5559 | { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR }, | |
5560 | { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC }, | |
5561 | { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW }, | |
5562 | { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW }, | |
5563 | { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS }, | |
5564 | { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU }, | |
5565 | { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW }, | |
5566 | ||
5567 | /* SPE binary operations expecting a 5-bit unsigned literal. */ | |
5568 | { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW }, | |
5569 | ||
5570 | { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI }, | |
5571 | { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI }, | |
5572 | { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS }, | |
5573 | { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU }, | |
5574 | { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW }, | |
5575 | { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA }, | |
5576 | { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA }, | |
5577 | { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA }, | |
5578 | { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA }, | |
5579 | { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA }, | |
5580 | { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA }, | |
5581 | { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN }, | |
5582 | { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN }, | |
5583 | { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN }, | |
5584 | { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN }, | |
5585 | { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN }, | |
5586 | { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN }, | |
5587 | { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA }, | |
5588 | { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA }, | |
5589 | { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA }, | |
5590 | { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA }, | |
5591 | { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN }, | |
5592 | { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN }, | |
5593 | { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN }, | |
5594 | { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN }, | |
5595 | { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC }, | |
5596 | ||
5597 | /* Place-holder. Leave as last binary SPE builtin. */ | |
17edbda5 | 5598 | { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR }, |
ae4b4a02 AH |
5599 | }; |
5600 | ||
5601 | /* AltiVec predicates. */ | |
5602 | ||
5603 | struct builtin_description_predicates | |
5604 | { | |
5605 | const unsigned int mask; | |
5606 | const enum insn_code icode; | |
5607 | const char *opcode; | |
5608 | const char *const name; | |
5609 | const enum rs6000_builtins code; | |
5610 | }; | |
5611 | ||
5612 | static const struct builtin_description_predicates bdesc_altivec_preds[] = | |
5613 | { | |
5614 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P }, | |
5615 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P }, | |
5616 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P }, | |
5617 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P }, | |
5618 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P }, | |
5619 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P }, | |
5620 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P }, | |
5621 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P }, | |
5622 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P }, | |
5623 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P }, | |
5624 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P }, | |
5625 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P }, | |
5626 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P } | |
0ac081f6 | 5627 | }; |
24408032 | 5628 | |
a3170dc6 AH |
5629 | /* SPE predicates. */ |
5630 | static struct builtin_description bdesc_spe_predicates[] = | |
5631 | { | |
5632 | /* Place-holder. Leave as first. */ | |
5633 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ }, | |
5634 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS }, | |
5635 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU }, | |
5636 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS }, | |
5637 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU }, | |
5638 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ }, | |
5639 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT }, | |
5640 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT }, | |
5641 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ }, | |
5642 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT }, | |
5643 | /* Place-holder. Leave as last. */ | |
5644 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT }, | |
5645 | }; | |
5646 | ||
5647 | /* SPE evsel predicates. */ | |
5648 | static struct builtin_description bdesc_spe_evsel[] = | |
5649 | { | |
5650 | /* Place-holder. Leave as first. */ | |
5651 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS }, | |
5652 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU }, | |
5653 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS }, | |
5654 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU }, | |
5655 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ }, | |
5656 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT }, | |
5657 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT }, | |
5658 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ }, | |
5659 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT }, | |
5660 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT }, | |
5661 | /* Place-holder. Leave as last. */ | |
5662 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ }, | |
5663 | }; | |
5664 | ||
b6d08ca1 | 5665 | /* ABS* operations. */ |
100c4561 AH |
5666 | |
5667 | static const struct builtin_description bdesc_abs[] = | |
5668 | { | |
5669 | { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI }, | |
5670 | { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI }, | |
5671 | { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF }, | |
5672 | { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI }, | |
5673 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI }, | |
5674 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI }, | |
5675 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI } | |
5676 | }; | |
5677 | ||
617e0e1d DB |
5678 | /* Simple unary operations: VECb = foo (unsigned literal) or VECb = |
5679 | foo (VECa). */ | |
24408032 | 5680 | |
a3170dc6 | 5681 | static struct builtin_description bdesc_1arg[] = |
2212663f | 5682 | { |
617e0e1d DB |
5683 | { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP }, |
5684 | { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP }, | |
5685 | { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP }, | |
5686 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM }, | |
5687 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN }, | |
5688 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP }, | |
5689 | { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ }, | |
5690 | { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP }, | |
2212663f DB |
5691 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB }, |
5692 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH }, | |
5693 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW }, | |
20e26713 AH |
5694 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB }, |
5695 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX }, | |
5696 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH }, | |
5697 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB }, | |
5698 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX }, | |
5699 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH }, | |
a3170dc6 AH |
5700 | |
5701 | /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and | |
5702 | end with SPE_BUILTIN_EVSUBFUSIAAW. */ | |
5703 | { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS }, | |
5704 | { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW }, | |
5705 | { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW }, | |
5706 | { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW }, | |
5707 | { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW }, | |
5708 | { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW }, | |
5709 | { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW }, | |
5710 | { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB }, | |
5711 | { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH }, | |
5712 | { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS }, | |
5713 | { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF }, | |
5714 | { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI }, | |
5715 | { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF }, | |
5716 | { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI }, | |
5717 | { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF }, | |
5718 | { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI }, | |
5719 | { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ }, | |
5720 | { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF }, | |
5721 | { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI }, | |
5722 | { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ }, | |
5723 | { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS }, | |
5724 | { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG }, | |
5725 | { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA }, | |
6a599451 | 5726 | { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG }, |
a3170dc6 AH |
5727 | { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW }, |
5728 | { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW }, | |
5729 | { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW }, | |
5730 | { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW }, | |
a3170dc6 AH |
5731 | |
5732 | /* Place-holder. Leave as last unary SPE builtin. */ | |
5733 | { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW }, | |
2212663f DB |
5734 | }; |
5735 | ||
5736 | static rtx | |
a2369ed3 | 5737 | rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
5738 | { |
5739 | rtx pat; | |
5740 | tree arg0 = TREE_VALUE (arglist); | |
5741 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5742 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5743 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5744 | ||
0559cc77 DE |
5745 | if (icode == CODE_FOR_nothing) |
5746 | /* Builtin not supported on this processor. */ | |
5747 | return 0; | |
5748 | ||
20e26713 AH |
5749 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5750 | if (arg0 == error_mark_node) | |
9a171fcd | 5751 | return const0_rtx; |
20e26713 | 5752 | |
0559cc77 DE |
5753 | if (icode == CODE_FOR_altivec_vspltisb |
5754 | || icode == CODE_FOR_altivec_vspltish | |
5755 | || icode == CODE_FOR_altivec_vspltisw | |
5756 | || icode == CODE_FOR_spe_evsplatfi | |
5757 | || icode == CODE_FOR_spe_evsplati) | |
b44140e7 AH |
5758 | { |
5759 | /* Only allow 5-bit *signed* literals. */ | |
b44140e7 AH |
5760 | if (GET_CODE (op0) != CONST_INT |
5761 | || INTVAL (op0) > 0x1f | |
5762 | || INTVAL (op0) < -0x1f) | |
5763 | { | |
5764 | error ("argument 1 must be a 5-bit signed literal"); | |
9a171fcd | 5765 | return const0_rtx; |
b44140e7 | 5766 | } |
b44140e7 AH |
5767 | } |
5768 | ||
c62f2db5 | 5769 | if (target == 0 |
2212663f DB |
5770 | || GET_MODE (target) != tmode |
5771 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5772 | target = gen_reg_rtx (tmode); | |
5773 | ||
5774 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5775 | op0 = copy_to_mode_reg (mode0, op0); | |
5776 | ||
5777 | pat = GEN_FCN (icode) (target, op0); | |
5778 | if (! pat) | |
5779 | return 0; | |
5780 | emit_insn (pat); | |
0ac081f6 | 5781 | |
2212663f DB |
5782 | return target; |
5783 | } | |
ae4b4a02 | 5784 | |
100c4561 | 5785 | static rtx |
a2369ed3 | 5786 | altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target) |
100c4561 AH |
5787 | { |
5788 | rtx pat, scratch1, scratch2; | |
5789 | tree arg0 = TREE_VALUE (arglist); | |
5790 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5791 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5792 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5793 | ||
5794 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
5795 | if (arg0 == error_mark_node) | |
9a171fcd | 5796 | return const0_rtx; |
100c4561 AH |
5797 | |
5798 | if (target == 0 | |
5799 | || GET_MODE (target) != tmode | |
5800 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5801 | target = gen_reg_rtx (tmode); | |
5802 | ||
5803 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5804 | op0 = copy_to_mode_reg (mode0, op0); | |
5805 | ||
5806 | scratch1 = gen_reg_rtx (mode0); | |
5807 | scratch2 = gen_reg_rtx (mode0); | |
5808 | ||
5809 | pat = GEN_FCN (icode) (target, op0, scratch1, scratch2); | |
5810 | if (! pat) | |
5811 | return 0; | |
5812 | emit_insn (pat); | |
5813 | ||
5814 | return target; | |
5815 | } | |
5816 | ||
0ac081f6 | 5817 | static rtx |
a2369ed3 | 5818 | rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target) |
0ac081f6 AH |
5819 | { |
5820 | rtx pat; | |
5821 | tree arg0 = TREE_VALUE (arglist); | |
5822 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5823 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5824 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5825 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5826 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5827 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5828 | ||
0559cc77 DE |
5829 | if (icode == CODE_FOR_nothing) |
5830 | /* Builtin not supported on this processor. */ | |
5831 | return 0; | |
5832 | ||
20e26713 AH |
5833 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5834 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 5835 | return const0_rtx; |
20e26713 | 5836 | |
0559cc77 DE |
5837 | if (icode == CODE_FOR_altivec_vcfux |
5838 | || icode == CODE_FOR_altivec_vcfsx | |
5839 | || icode == CODE_FOR_altivec_vctsxs | |
5840 | || icode == CODE_FOR_altivec_vctuxs | |
5841 | || icode == CODE_FOR_altivec_vspltb | |
5842 | || icode == CODE_FOR_altivec_vsplth | |
5843 | || icode == CODE_FOR_altivec_vspltw | |
5844 | || icode == CODE_FOR_spe_evaddiw | |
5845 | || icode == CODE_FOR_spe_evldd | |
5846 | || icode == CODE_FOR_spe_evldh | |
5847 | || icode == CODE_FOR_spe_evldw | |
5848 | || icode == CODE_FOR_spe_evlhhesplat | |
5849 | || icode == CODE_FOR_spe_evlhhossplat | |
5850 | || icode == CODE_FOR_spe_evlhhousplat | |
5851 | || icode == CODE_FOR_spe_evlwhe | |
5852 | || icode == CODE_FOR_spe_evlwhos | |
5853 | || icode == CODE_FOR_spe_evlwhou | |
5854 | || icode == CODE_FOR_spe_evlwhsplat | |
5855 | || icode == CODE_FOR_spe_evlwwsplat | |
5856 | || icode == CODE_FOR_spe_evrlwi | |
5857 | || icode == CODE_FOR_spe_evslwi | |
5858 | || icode == CODE_FOR_spe_evsrwis | |
f5119d10 | 5859 | || icode == CODE_FOR_spe_evsubifw |
0559cc77 | 5860 | || icode == CODE_FOR_spe_evsrwiu) |
b44140e7 AH |
5861 | { |
5862 | /* Only allow 5-bit unsigned literals. */ | |
8bb418a3 | 5863 | STRIP_NOPS (arg1); |
b44140e7 AH |
5864 | if (TREE_CODE (arg1) != INTEGER_CST |
5865 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
5866 | { | |
5867 | error ("argument 2 must be a 5-bit unsigned literal"); | |
9a171fcd | 5868 | return const0_rtx; |
b44140e7 | 5869 | } |
b44140e7 AH |
5870 | } |
5871 | ||
c62f2db5 | 5872 | if (target == 0 |
0ac081f6 AH |
5873 | || GET_MODE (target) != tmode |
5874 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5875 | target = gen_reg_rtx (tmode); | |
5876 | ||
5877 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5878 | op0 = copy_to_mode_reg (mode0, op0); | |
5879 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5880 | op1 = copy_to_mode_reg (mode1, op1); | |
5881 | ||
5882 | pat = GEN_FCN (icode) (target, op0, op1); | |
5883 | if (! pat) | |
5884 | return 0; | |
5885 | emit_insn (pat); | |
5886 | ||
5887 | return target; | |
5888 | } | |
6525c0e7 | 5889 | |
ae4b4a02 | 5890 | static rtx |
a2369ed3 DJ |
5891 | altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode, |
5892 | tree arglist, rtx target) | |
ae4b4a02 AH |
5893 | { |
5894 | rtx pat, scratch; | |
5895 | tree cr6_form = TREE_VALUE (arglist); | |
5896 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5897 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5898 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5899 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5900 | enum machine_mode tmode = SImode; | |
5901 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5902 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5903 | int cr6_form_int; | |
5904 | ||
5905 | if (TREE_CODE (cr6_form) != INTEGER_CST) | |
5906 | { | |
5907 | error ("argument 1 of __builtin_altivec_predicate must be a constant"); | |
9a171fcd | 5908 | return const0_rtx; |
ae4b4a02 AH |
5909 | } |
5910 | else | |
5911 | cr6_form_int = TREE_INT_CST_LOW (cr6_form); | |
5912 | ||
5913 | if (mode0 != mode1) | |
5914 | abort (); | |
5915 | ||
5916 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
5917 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 5918 | return const0_rtx; |
ae4b4a02 AH |
5919 | |
5920 | if (target == 0 | |
5921 | || GET_MODE (target) != tmode | |
5922 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5923 | target = gen_reg_rtx (tmode); | |
5924 | ||
5925 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5926 | op0 = copy_to_mode_reg (mode0, op0); | |
5927 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5928 | op1 = copy_to_mode_reg (mode1, op1); | |
5929 | ||
5930 | scratch = gen_reg_rtx (mode0); | |
5931 | ||
5932 | pat = GEN_FCN (icode) (scratch, op0, op1, | |
f1c25d3b | 5933 | gen_rtx_SYMBOL_REF (Pmode, opcode)); |
ae4b4a02 AH |
5934 | if (! pat) |
5935 | return 0; | |
5936 | emit_insn (pat); | |
5937 | ||
5938 | /* The vec_any* and vec_all* predicates use the same opcodes for two | |
5939 | different operations, but the bits in CR6 will be different | |
5940 | depending on what information we want. So we have to play tricks | |
5941 | with CR6 to get the right bits out. | |
5942 | ||
5943 | If you think this is disgusting, look at the specs for the | |
5944 | AltiVec predicates. */ | |
5945 | ||
5946 | switch (cr6_form_int) | |
5947 | { | |
5948 | case 0: | |
5949 | emit_insn (gen_cr6_test_for_zero (target)); | |
5950 | break; | |
5951 | case 1: | |
5952 | emit_insn (gen_cr6_test_for_zero_reverse (target)); | |
5953 | break; | |
5954 | case 2: | |
5955 | emit_insn (gen_cr6_test_for_lt (target)); | |
5956 | break; | |
5957 | case 3: | |
5958 | emit_insn (gen_cr6_test_for_lt_reverse (target)); | |
5959 | break; | |
5960 | default: | |
5961 | error ("argument 1 of __builtin_altivec_predicate is out of range"); | |
5962 | break; | |
5963 | } | |
5964 | ||
5965 | return target; | |
5966 | } | |
5967 | ||
b4a62fa0 | 5968 | static rtx |
38f391a5 | 5969 | altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target) |
b4a62fa0 SB |
5970 | { |
5971 | rtx pat, addr; | |
5972 | tree arg0 = TREE_VALUE (arglist); | |
5973 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5974 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5975 | enum machine_mode mode0 = Pmode; | |
5976 | enum machine_mode mode1 = Pmode; | |
5977 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5978 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5979 | ||
5980 | if (icode == CODE_FOR_nothing) | |
5981 | /* Builtin not supported on this processor. */ | |
5982 | return 0; | |
5983 | ||
5984 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
5985 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
5986 | return const0_rtx; | |
5987 | ||
5988 | if (target == 0 | |
5989 | || GET_MODE (target) != tmode | |
5990 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5991 | target = gen_reg_rtx (tmode); | |
5992 | ||
5993 | op1 = copy_to_mode_reg (mode1, op1); | |
5994 | ||
5995 | if (op0 == const0_rtx) | |
5996 | { | |
5997 | addr = gen_rtx_MEM (tmode, op1); | |
5998 | } | |
5999 | else | |
6000 | { | |
6001 | op0 = copy_to_mode_reg (mode0, op0); | |
6002 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1)); | |
6003 | } | |
6004 | ||
6005 | pat = GEN_FCN (icode) (target, addr); | |
6006 | ||
6007 | if (! pat) | |
6008 | return 0; | |
6009 | emit_insn (pat); | |
6010 | ||
6011 | return target; | |
6012 | } | |
6013 | ||
61bea3b0 AH |
6014 | static rtx |
6015 | spe_expand_stv_builtin (enum insn_code icode, tree arglist) | |
6016 | { | |
6017 | tree arg0 = TREE_VALUE (arglist); | |
6018 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6019 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6020 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6021 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6022 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6023 | rtx pat; | |
6024 | enum machine_mode mode0 = insn_data[icode].operand[0].mode; | |
6025 | enum machine_mode mode1 = insn_data[icode].operand[1].mode; | |
6026 | enum machine_mode mode2 = insn_data[icode].operand[2].mode; | |
6027 | ||
6028 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
6029 | if (arg0 == error_mark_node | |
6030 | || arg1 == error_mark_node | |
6031 | || arg2 == error_mark_node) | |
6032 | return const0_rtx; | |
6033 | ||
6034 | if (! (*insn_data[icode].operand[2].predicate) (op0, mode2)) | |
6035 | op0 = copy_to_mode_reg (mode2, op0); | |
6036 | if (! (*insn_data[icode].operand[0].predicate) (op1, mode0)) | |
6037 | op1 = copy_to_mode_reg (mode0, op1); | |
6038 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
6039 | op2 = copy_to_mode_reg (mode1, op2); | |
6040 | ||
6041 | pat = GEN_FCN (icode) (op1, op2, op0); | |
6042 | if (pat) | |
6043 | emit_insn (pat); | |
6044 | return NULL_RTX; | |
6045 | } | |
6046 | ||
6525c0e7 | 6047 | static rtx |
a2369ed3 | 6048 | altivec_expand_stv_builtin (enum insn_code icode, tree arglist) |
6525c0e7 AH |
6049 | { |
6050 | tree arg0 = TREE_VALUE (arglist); | |
6051 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6052 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6053 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6054 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6055 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
b4a62fa0 SB |
6056 | rtx pat, addr; |
6057 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6058 | enum machine_mode mode1 = Pmode; | |
6059 | enum machine_mode mode2 = Pmode; | |
6525c0e7 AH |
6060 | |
6061 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
6062 | if (arg0 == error_mark_node | |
6063 | || arg1 == error_mark_node | |
6064 | || arg2 == error_mark_node) | |
9a171fcd | 6065 | return const0_rtx; |
6525c0e7 | 6066 | |
b4a62fa0 SB |
6067 | if (! (*insn_data[icode].operand[1].predicate) (op0, tmode)) |
6068 | op0 = copy_to_mode_reg (tmode, op0); | |
6069 | ||
6070 | op2 = copy_to_mode_reg (mode2, op2); | |
6071 | ||
6072 | if (op1 == const0_rtx) | |
6073 | { | |
6074 | addr = gen_rtx_MEM (tmode, op2); | |
6075 | } | |
6076 | else | |
6077 | { | |
6078 | op1 = copy_to_mode_reg (mode1, op1); | |
6079 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2)); | |
6080 | } | |
6525c0e7 | 6081 | |
b4a62fa0 | 6082 | pat = GEN_FCN (icode) (addr, op0); |
6525c0e7 AH |
6083 | if (pat) |
6084 | emit_insn (pat); | |
6085 | return NULL_RTX; | |
6086 | } | |
6087 | ||
2212663f | 6088 | static rtx |
a2369ed3 | 6089 | rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
6090 | { |
6091 | rtx pat; | |
6092 | tree arg0 = TREE_VALUE (arglist); | |
6093 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6094 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6095 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6096 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6097 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6098 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6099 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6100 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6101 | enum machine_mode mode2 = insn_data[icode].operand[3].mode; | |
0ac081f6 | 6102 | |
774b5662 DE |
6103 | if (icode == CODE_FOR_nothing) |
6104 | /* Builtin not supported on this processor. */ | |
6105 | return 0; | |
6106 | ||
20e26713 AH |
6107 | /* If we got invalid arguments bail out before generating bad rtl. */ |
6108 | if (arg0 == error_mark_node | |
6109 | || arg1 == error_mark_node | |
6110 | || arg2 == error_mark_node) | |
9a171fcd | 6111 | return const0_rtx; |
20e26713 | 6112 | |
774b5662 DE |
6113 | if (icode == CODE_FOR_altivec_vsldoi_4sf |
6114 | || icode == CODE_FOR_altivec_vsldoi_4si | |
6115 | || icode == CODE_FOR_altivec_vsldoi_8hi | |
6116 | || icode == CODE_FOR_altivec_vsldoi_16qi) | |
b44140e7 AH |
6117 | { |
6118 | /* Only allow 4-bit unsigned literals. */ | |
8bb418a3 | 6119 | STRIP_NOPS (arg2); |
b44140e7 AH |
6120 | if (TREE_CODE (arg2) != INTEGER_CST |
6121 | || TREE_INT_CST_LOW (arg2) & ~0xf) | |
6122 | { | |
6123 | error ("argument 3 must be a 4-bit unsigned literal"); | |
e3277ffb | 6124 | return const0_rtx; |
b44140e7 | 6125 | } |
b44140e7 AH |
6126 | } |
6127 | ||
c62f2db5 | 6128 | if (target == 0 |
2212663f DB |
6129 | || GET_MODE (target) != tmode |
6130 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6131 | target = gen_reg_rtx (tmode); | |
6132 | ||
6133 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6134 | op0 = copy_to_mode_reg (mode0, op0); | |
6135 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6136 | op1 = copy_to_mode_reg (mode1, op1); | |
6137 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
6138 | op2 = copy_to_mode_reg (mode2, op2); | |
6139 | ||
6140 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
6141 | if (! pat) | |
6142 | return 0; | |
6143 | emit_insn (pat); | |
6144 | ||
6145 | return target; | |
6146 | } | |
92898235 | 6147 | |
3a9b8c7e | 6148 | /* Expand the lvx builtins. */ |
0ac081f6 | 6149 | static rtx |
a2369ed3 | 6150 | altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp) |
0ac081f6 | 6151 | { |
0ac081f6 AH |
6152 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
6153 | tree arglist = TREE_OPERAND (exp, 1); | |
0ac081f6 | 6154 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
3a9b8c7e AH |
6155 | tree arg0; |
6156 | enum machine_mode tmode, mode0; | |
7c3abc73 | 6157 | rtx pat, op0; |
3a9b8c7e | 6158 | enum insn_code icode; |
92898235 | 6159 | |
0ac081f6 AH |
6160 | switch (fcode) |
6161 | { | |
f18c054f DB |
6162 | case ALTIVEC_BUILTIN_LD_INTERNAL_16qi: |
6163 | icode = CODE_FOR_altivec_lvx_16qi; | |
3a9b8c7e | 6164 | break; |
f18c054f DB |
6165 | case ALTIVEC_BUILTIN_LD_INTERNAL_8hi: |
6166 | icode = CODE_FOR_altivec_lvx_8hi; | |
3a9b8c7e AH |
6167 | break; |
6168 | case ALTIVEC_BUILTIN_LD_INTERNAL_4si: | |
6169 | icode = CODE_FOR_altivec_lvx_4si; | |
6170 | break; | |
6171 | case ALTIVEC_BUILTIN_LD_INTERNAL_4sf: | |
6172 | icode = CODE_FOR_altivec_lvx_4sf; | |
6173 | break; | |
6174 | default: | |
6175 | *expandedp = false; | |
6176 | return NULL_RTX; | |
6177 | } | |
0ac081f6 | 6178 | |
3a9b8c7e | 6179 | *expandedp = true; |
f18c054f | 6180 | |
3a9b8c7e AH |
6181 | arg0 = TREE_VALUE (arglist); |
6182 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6183 | tmode = insn_data[icode].operand[0].mode; | |
6184 | mode0 = insn_data[icode].operand[1].mode; | |
f18c054f | 6185 | |
3a9b8c7e AH |
6186 | if (target == 0 |
6187 | || GET_MODE (target) != tmode | |
6188 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6189 | target = gen_reg_rtx (tmode); | |
24408032 | 6190 | |
3a9b8c7e AH |
6191 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) |
6192 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
f18c054f | 6193 | |
3a9b8c7e AH |
6194 | pat = GEN_FCN (icode) (target, op0); |
6195 | if (! pat) | |
6196 | return 0; | |
6197 | emit_insn (pat); | |
6198 | return target; | |
6199 | } | |
f18c054f | 6200 | |
3a9b8c7e AH |
6201 | /* Expand the stvx builtins. */ |
6202 | static rtx | |
a2369ed3 DJ |
6203 | altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
6204 | bool *expandedp) | |
3a9b8c7e AH |
6205 | { |
6206 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6207 | tree arglist = TREE_OPERAND (exp, 1); | |
6208 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6209 | tree arg0, arg1; | |
6210 | enum machine_mode mode0, mode1; | |
7c3abc73 | 6211 | rtx pat, op0, op1; |
3a9b8c7e | 6212 | enum insn_code icode; |
f18c054f | 6213 | |
3a9b8c7e AH |
6214 | switch (fcode) |
6215 | { | |
6216 | case ALTIVEC_BUILTIN_ST_INTERNAL_16qi: | |
6217 | icode = CODE_FOR_altivec_stvx_16qi; | |
6218 | break; | |
6219 | case ALTIVEC_BUILTIN_ST_INTERNAL_8hi: | |
6220 | icode = CODE_FOR_altivec_stvx_8hi; | |
6221 | break; | |
6222 | case ALTIVEC_BUILTIN_ST_INTERNAL_4si: | |
6223 | icode = CODE_FOR_altivec_stvx_4si; | |
6224 | break; | |
6225 | case ALTIVEC_BUILTIN_ST_INTERNAL_4sf: | |
6226 | icode = CODE_FOR_altivec_stvx_4sf; | |
6227 | break; | |
6228 | default: | |
6229 | *expandedp = false; | |
6230 | return NULL_RTX; | |
6231 | } | |
24408032 | 6232 | |
3a9b8c7e AH |
6233 | arg0 = TREE_VALUE (arglist); |
6234 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6235 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6236 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6237 | mode0 = insn_data[icode].operand[0].mode; | |
6238 | mode1 = insn_data[icode].operand[1].mode; | |
f18c054f | 6239 | |
3a9b8c7e AH |
6240 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
6241 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
6242 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
6243 | op1 = copy_to_mode_reg (mode1, op1); | |
f18c054f | 6244 | |
3a9b8c7e AH |
6245 | pat = GEN_FCN (icode) (op0, op1); |
6246 | if (pat) | |
6247 | emit_insn (pat); | |
f18c054f | 6248 | |
3a9b8c7e AH |
6249 | *expandedp = true; |
6250 | return NULL_RTX; | |
6251 | } | |
f18c054f | 6252 | |
3a9b8c7e AH |
6253 | /* Expand the dst builtins. */ |
6254 | static rtx | |
a2369ed3 DJ |
6255 | altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
6256 | bool *expandedp) | |
3a9b8c7e AH |
6257 | { |
6258 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6259 | tree arglist = TREE_OPERAND (exp, 1); | |
6260 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6261 | tree arg0, arg1, arg2; | |
6262 | enum machine_mode mode0, mode1, mode2; | |
7c3abc73 | 6263 | rtx pat, op0, op1, op2; |
3a9b8c7e | 6264 | struct builtin_description *d; |
a3170dc6 | 6265 | size_t i; |
f18c054f | 6266 | |
3a9b8c7e | 6267 | *expandedp = false; |
f18c054f | 6268 | |
3a9b8c7e AH |
6269 | /* Handle DST variants. */ |
6270 | d = (struct builtin_description *) bdesc_dst; | |
6271 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
6272 | if (d->code == fcode) | |
6273 | { | |
6274 | arg0 = TREE_VALUE (arglist); | |
6275 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6276 | arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6277 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6278 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6279 | op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6280 | mode0 = insn_data[d->icode].operand[0].mode; | |
6281 | mode1 = insn_data[d->icode].operand[1].mode; | |
6282 | mode2 = insn_data[d->icode].operand[2].mode; | |
24408032 | 6283 | |
3a9b8c7e AH |
6284 | /* Invalid arguments, bail out before generating bad rtl. */ |
6285 | if (arg0 == error_mark_node | |
6286 | || arg1 == error_mark_node | |
6287 | || arg2 == error_mark_node) | |
6288 | return const0_rtx; | |
f18c054f | 6289 | |
86e7df90 | 6290 | *expandedp = true; |
8bb418a3 | 6291 | STRIP_NOPS (arg2); |
3a9b8c7e AH |
6292 | if (TREE_CODE (arg2) != INTEGER_CST |
6293 | || TREE_INT_CST_LOW (arg2) & ~0x3) | |
6294 | { | |
6295 | error ("argument to `%s' must be a 2-bit unsigned literal", d->name); | |
6296 | return const0_rtx; | |
6297 | } | |
f18c054f | 6298 | |
3a9b8c7e | 6299 | if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0)) |
b4a62fa0 | 6300 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); |
3a9b8c7e AH |
6301 | if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1)) |
6302 | op1 = copy_to_mode_reg (mode1, op1); | |
24408032 | 6303 | |
3a9b8c7e AH |
6304 | pat = GEN_FCN (d->icode) (op0, op1, op2); |
6305 | if (pat != 0) | |
6306 | emit_insn (pat); | |
f18c054f | 6307 | |
3a9b8c7e AH |
6308 | return NULL_RTX; |
6309 | } | |
f18c054f | 6310 | |
3a9b8c7e AH |
6311 | return NULL_RTX; |
6312 | } | |
24408032 | 6313 | |
3a9b8c7e AH |
6314 | /* Expand the builtin in EXP and store the result in TARGET. Store |
6315 | true in *EXPANDEDP if we found a builtin to expand. */ | |
6316 | static rtx | |
a2369ed3 | 6317 | altivec_expand_builtin (tree exp, rtx target, bool *expandedp) |
3a9b8c7e AH |
6318 | { |
6319 | struct builtin_description *d; | |
6320 | struct builtin_description_predicates *dp; | |
6321 | size_t i; | |
6322 | enum insn_code icode; | |
6323 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6324 | tree arglist = TREE_OPERAND (exp, 1); | |
7c3abc73 AH |
6325 | tree arg0; |
6326 | rtx op0, pat; | |
6327 | enum machine_mode tmode, mode0; | |
3a9b8c7e | 6328 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
0ac081f6 | 6329 | |
3a9b8c7e AH |
6330 | target = altivec_expand_ld_builtin (exp, target, expandedp); |
6331 | if (*expandedp) | |
6332 | return target; | |
0ac081f6 | 6333 | |
3a9b8c7e AH |
6334 | target = altivec_expand_st_builtin (exp, target, expandedp); |
6335 | if (*expandedp) | |
6336 | return target; | |
6337 | ||
6338 | target = altivec_expand_dst_builtin (exp, target, expandedp); | |
6339 | if (*expandedp) | |
6340 | return target; | |
6341 | ||
6342 | *expandedp = true; | |
95385cbb | 6343 | |
3a9b8c7e AH |
6344 | switch (fcode) |
6345 | { | |
6525c0e7 AH |
6346 | case ALTIVEC_BUILTIN_STVX: |
6347 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist); | |
6348 | case ALTIVEC_BUILTIN_STVEBX: | |
6349 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist); | |
6350 | case ALTIVEC_BUILTIN_STVEHX: | |
6351 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist); | |
6352 | case ALTIVEC_BUILTIN_STVEWX: | |
6353 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist); | |
6354 | case ALTIVEC_BUILTIN_STVXL: | |
6355 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist); | |
3a9b8c7e | 6356 | |
95385cbb AH |
6357 | case ALTIVEC_BUILTIN_MFVSCR: |
6358 | icode = CODE_FOR_altivec_mfvscr; | |
6359 | tmode = insn_data[icode].operand[0].mode; | |
6360 | ||
6361 | if (target == 0 | |
6362 | || GET_MODE (target) != tmode | |
6363 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6364 | target = gen_reg_rtx (tmode); | |
6365 | ||
6366 | pat = GEN_FCN (icode) (target); | |
0ac081f6 AH |
6367 | if (! pat) |
6368 | return 0; | |
6369 | emit_insn (pat); | |
95385cbb AH |
6370 | return target; |
6371 | ||
6372 | case ALTIVEC_BUILTIN_MTVSCR: | |
6373 | icode = CODE_FOR_altivec_mtvscr; | |
6374 | arg0 = TREE_VALUE (arglist); | |
6375 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6376 | mode0 = insn_data[icode].operand[0].mode; | |
6377 | ||
6378 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6379 | if (arg0 == error_mark_node) | |
9a171fcd | 6380 | return const0_rtx; |
95385cbb AH |
6381 | |
6382 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
6383 | op0 = copy_to_mode_reg (mode0, op0); | |
6384 | ||
6385 | pat = GEN_FCN (icode) (op0); | |
6386 | if (pat) | |
6387 | emit_insn (pat); | |
6388 | return NULL_RTX; | |
3a9b8c7e | 6389 | |
95385cbb AH |
6390 | case ALTIVEC_BUILTIN_DSSALL: |
6391 | emit_insn (gen_altivec_dssall ()); | |
6392 | return NULL_RTX; | |
6393 | ||
6394 | case ALTIVEC_BUILTIN_DSS: | |
6395 | icode = CODE_FOR_altivec_dss; | |
6396 | arg0 = TREE_VALUE (arglist); | |
8bb418a3 | 6397 | STRIP_NOPS (arg0); |
95385cbb AH |
6398 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); |
6399 | mode0 = insn_data[icode].operand[0].mode; | |
6400 | ||
6401 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6402 | if (arg0 == error_mark_node) | |
9a171fcd | 6403 | return const0_rtx; |
95385cbb | 6404 | |
b44140e7 AH |
6405 | if (TREE_CODE (arg0) != INTEGER_CST |
6406 | || TREE_INT_CST_LOW (arg0) & ~0x3) | |
6407 | { | |
6408 | error ("argument to dss must be a 2-bit unsigned literal"); | |
9a171fcd | 6409 | return const0_rtx; |
b44140e7 AH |
6410 | } |
6411 | ||
95385cbb AH |
6412 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
6413 | op0 = copy_to_mode_reg (mode0, op0); | |
6414 | ||
6415 | emit_insn (gen_altivec_dss (op0)); | |
0ac081f6 | 6416 | return NULL_RTX; |
8bb418a3 ZL |
6417 | |
6418 | case ALTIVEC_BUILTIN_COMPILETIME_ERROR: | |
6419 | arg0 = TREE_VALUE (arglist); | |
6420 | while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR) | |
6421 | arg0 = TREE_OPERAND (arg0, 0); | |
6422 | error ("invalid parameter combination for `%s' AltiVec intrinsic", | |
6423 | TREE_STRING_POINTER (arg0)); | |
6424 | ||
6425 | return const0_rtx; | |
0ac081f6 | 6426 | } |
24408032 | 6427 | |
100c4561 AH |
6428 | /* Expand abs* operations. */ |
6429 | d = (struct builtin_description *) bdesc_abs; | |
ca7558fc | 6430 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) |
100c4561 AH |
6431 | if (d->code == fcode) |
6432 | return altivec_expand_abs_builtin (d->icode, arglist, target); | |
6433 | ||
ae4b4a02 AH |
6434 | /* Expand the AltiVec predicates. */ |
6435 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
ca7558fc | 6436 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) |
ae4b4a02 AH |
6437 | if (dp->code == fcode) |
6438 | return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target); | |
6439 | ||
6525c0e7 AH |
6440 | /* LV* are funky. We initialized them differently. */ |
6441 | switch (fcode) | |
6442 | { | |
6443 | case ALTIVEC_BUILTIN_LVSL: | |
b4a62fa0 | 6444 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl, |
6525c0e7 AH |
6445 | arglist, target); |
6446 | case ALTIVEC_BUILTIN_LVSR: | |
b4a62fa0 | 6447 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr, |
92898235 | 6448 | arglist, target); |
6525c0e7 | 6449 | case ALTIVEC_BUILTIN_LVEBX: |
b4a62fa0 | 6450 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx, |
92898235 | 6451 | arglist, target); |
6525c0e7 | 6452 | case ALTIVEC_BUILTIN_LVEHX: |
b4a62fa0 | 6453 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx, |
92898235 | 6454 | arglist, target); |
6525c0e7 | 6455 | case ALTIVEC_BUILTIN_LVEWX: |
b4a62fa0 | 6456 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx, |
92898235 | 6457 | arglist, target); |
6525c0e7 | 6458 | case ALTIVEC_BUILTIN_LVXL: |
b4a62fa0 | 6459 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl, |
92898235 | 6460 | arglist, target); |
6525c0e7 | 6461 | case ALTIVEC_BUILTIN_LVX: |
b4a62fa0 | 6462 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx, |
92898235 | 6463 | arglist, target); |
6525c0e7 AH |
6464 | default: |
6465 | break; | |
6466 | /* Fall through. */ | |
6467 | } | |
95385cbb | 6468 | |
92898235 | 6469 | *expandedp = false; |
0ac081f6 AH |
6470 | return NULL_RTX; |
6471 | } | |
6472 | ||
a3170dc6 AH |
6473 | /* Binops that need to be initialized manually, but can be expanded |
6474 | automagically by rs6000_expand_binop_builtin. */ | |
6475 | static struct builtin_description bdesc_2arg_spe[] = | |
6476 | { | |
6477 | { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX }, | |
6478 | { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX }, | |
6479 | { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX }, | |
6480 | { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX }, | |
6481 | { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX }, | |
6482 | { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX }, | |
6483 | { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX }, | |
6484 | { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX }, | |
6485 | { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX }, | |
6486 | { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX }, | |
6487 | { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX }, | |
6488 | { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD }, | |
6489 | { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW }, | |
6490 | { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH }, | |
6491 | { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE }, | |
6492 | { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU }, | |
6493 | { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS }, | |
6494 | { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT }, | |
6495 | { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT }, | |
6496 | { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT }, | |
6497 | { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT }, | |
6498 | { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT } | |
6499 | }; | |
6500 | ||
6501 | /* Expand the builtin in EXP and store the result in TARGET. Store | |
6502 | true in *EXPANDEDP if we found a builtin to expand. | |
6503 | ||
6504 | This expands the SPE builtins that are not simple unary and binary | |
6505 | operations. */ | |
6506 | static rtx | |
a2369ed3 | 6507 | spe_expand_builtin (tree exp, rtx target, bool *expandedp) |
a3170dc6 AH |
6508 | { |
6509 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6510 | tree arglist = TREE_OPERAND (exp, 1); | |
6511 | tree arg1, arg0; | |
6512 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6513 | enum insn_code icode; | |
6514 | enum machine_mode tmode, mode0; | |
6515 | rtx pat, op0; | |
6516 | struct builtin_description *d; | |
6517 | size_t i; | |
6518 | ||
6519 | *expandedp = true; | |
6520 | ||
6521 | /* Syntax check for a 5-bit unsigned immediate. */ | |
6522 | switch (fcode) | |
6523 | { | |
6524 | case SPE_BUILTIN_EVSTDD: | |
6525 | case SPE_BUILTIN_EVSTDH: | |
6526 | case SPE_BUILTIN_EVSTDW: | |
6527 | case SPE_BUILTIN_EVSTWHE: | |
6528 | case SPE_BUILTIN_EVSTWHO: | |
6529 | case SPE_BUILTIN_EVSTWWE: | |
6530 | case SPE_BUILTIN_EVSTWWO: | |
6531 | arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6532 | if (TREE_CODE (arg1) != INTEGER_CST | |
6533 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
6534 | { | |
6535 | error ("argument 2 must be a 5-bit unsigned literal"); | |
6536 | return const0_rtx; | |
6537 | } | |
6538 | break; | |
6539 | default: | |
6540 | break; | |
6541 | } | |
6542 | ||
00332c9f AH |
6543 | /* The evsplat*i instructions are not quite generic. */ |
6544 | switch (fcode) | |
6545 | { | |
6546 | case SPE_BUILTIN_EVSPLATFI: | |
6547 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi, | |
6548 | arglist, target); | |
6549 | case SPE_BUILTIN_EVSPLATI: | |
6550 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati, | |
6551 | arglist, target); | |
6552 | default: | |
6553 | break; | |
6554 | } | |
6555 | ||
a3170dc6 AH |
6556 | d = (struct builtin_description *) bdesc_2arg_spe; |
6557 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d) | |
6558 | if (d->code == fcode) | |
6559 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6560 | ||
6561 | d = (struct builtin_description *) bdesc_spe_predicates; | |
6562 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d) | |
6563 | if (d->code == fcode) | |
6564 | return spe_expand_predicate_builtin (d->icode, arglist, target); | |
6565 | ||
6566 | d = (struct builtin_description *) bdesc_spe_evsel; | |
6567 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d) | |
6568 | if (d->code == fcode) | |
6569 | return spe_expand_evsel_builtin (d->icode, arglist, target); | |
6570 | ||
6571 | switch (fcode) | |
6572 | { | |
6573 | case SPE_BUILTIN_EVSTDDX: | |
61bea3b0 | 6574 | return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist); |
a3170dc6 | 6575 | case SPE_BUILTIN_EVSTDHX: |
61bea3b0 | 6576 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist); |
a3170dc6 | 6577 | case SPE_BUILTIN_EVSTDWX: |
61bea3b0 | 6578 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist); |
a3170dc6 | 6579 | case SPE_BUILTIN_EVSTWHEX: |
61bea3b0 | 6580 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist); |
a3170dc6 | 6581 | case SPE_BUILTIN_EVSTWHOX: |
61bea3b0 | 6582 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist); |
a3170dc6 | 6583 | case SPE_BUILTIN_EVSTWWEX: |
61bea3b0 | 6584 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist); |
a3170dc6 | 6585 | case SPE_BUILTIN_EVSTWWOX: |
61bea3b0 | 6586 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist); |
a3170dc6 | 6587 | case SPE_BUILTIN_EVSTDD: |
61bea3b0 | 6588 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist); |
a3170dc6 | 6589 | case SPE_BUILTIN_EVSTDH: |
61bea3b0 | 6590 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist); |
a3170dc6 | 6591 | case SPE_BUILTIN_EVSTDW: |
61bea3b0 | 6592 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist); |
a3170dc6 | 6593 | case SPE_BUILTIN_EVSTWHE: |
61bea3b0 | 6594 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist); |
a3170dc6 | 6595 | case SPE_BUILTIN_EVSTWHO: |
61bea3b0 | 6596 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist); |
a3170dc6 | 6597 | case SPE_BUILTIN_EVSTWWE: |
61bea3b0 | 6598 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist); |
a3170dc6 | 6599 | case SPE_BUILTIN_EVSTWWO: |
61bea3b0 | 6600 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist); |
a3170dc6 AH |
6601 | case SPE_BUILTIN_MFSPEFSCR: |
6602 | icode = CODE_FOR_spe_mfspefscr; | |
6603 | tmode = insn_data[icode].operand[0].mode; | |
6604 | ||
6605 | if (target == 0 | |
6606 | || GET_MODE (target) != tmode | |
6607 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6608 | target = gen_reg_rtx (tmode); | |
6609 | ||
6610 | pat = GEN_FCN (icode) (target); | |
6611 | if (! pat) | |
6612 | return 0; | |
6613 | emit_insn (pat); | |
6614 | return target; | |
6615 | case SPE_BUILTIN_MTSPEFSCR: | |
6616 | icode = CODE_FOR_spe_mtspefscr; | |
6617 | arg0 = TREE_VALUE (arglist); | |
6618 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6619 | mode0 = insn_data[icode].operand[0].mode; | |
6620 | ||
6621 | if (arg0 == error_mark_node) | |
6622 | return const0_rtx; | |
6623 | ||
6624 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
6625 | op0 = copy_to_mode_reg (mode0, op0); | |
6626 | ||
6627 | pat = GEN_FCN (icode) (op0); | |
6628 | if (pat) | |
6629 | emit_insn (pat); | |
6630 | return NULL_RTX; | |
6631 | default: | |
6632 | break; | |
6633 | } | |
6634 | ||
6635 | *expandedp = false; | |
6636 | return NULL_RTX; | |
6637 | } | |
6638 | ||
6639 | static rtx | |
a2369ed3 | 6640 | spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
6641 | { |
6642 | rtx pat, scratch, tmp; | |
6643 | tree form = TREE_VALUE (arglist); | |
6644 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6645 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6646 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6647 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6648 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6649 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6650 | int form_int; | |
6651 | enum rtx_code code; | |
6652 | ||
6653 | if (TREE_CODE (form) != INTEGER_CST) | |
6654 | { | |
6655 | error ("argument 1 of __builtin_spe_predicate must be a constant"); | |
6656 | return const0_rtx; | |
6657 | } | |
6658 | else | |
6659 | form_int = TREE_INT_CST_LOW (form); | |
6660 | ||
6661 | if (mode0 != mode1) | |
6662 | abort (); | |
6663 | ||
6664 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
6665 | return const0_rtx; | |
6666 | ||
6667 | if (target == 0 | |
6668 | || GET_MODE (target) != SImode | |
6669 | || ! (*insn_data[icode].operand[0].predicate) (target, SImode)) | |
6670 | target = gen_reg_rtx (SImode); | |
6671 | ||
6672 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6673 | op0 = copy_to_mode_reg (mode0, op0); | |
6674 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6675 | op1 = copy_to_mode_reg (mode1, op1); | |
6676 | ||
6677 | scratch = gen_reg_rtx (CCmode); | |
6678 | ||
6679 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
6680 | if (! pat) | |
6681 | return const0_rtx; | |
6682 | emit_insn (pat); | |
6683 | ||
6684 | /* There are 4 variants for each predicate: _any_, _all_, _upper_, | |
6685 | _lower_. We use one compare, but look in different bits of the | |
6686 | CR for each variant. | |
6687 | ||
6688 | There are 2 elements in each SPE simd type (upper/lower). The CR | |
6689 | bits are set as follows: | |
6690 | ||
6691 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
6692 | U | L | (U | L) | (U & L) | |
6693 | ||
6694 | So, for an "all" relationship, BIT 3 would be set. | |
6695 | For an "any" relationship, BIT 2 would be set. Etc. | |
6696 | ||
6697 | Following traditional nomenclature, these bits map to: | |
6698 | ||
6699 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
6700 | LT | GT | EQ | OV | |
6701 | ||
6702 | Later, we will generate rtl to look in the LT/EQ/EQ/OV bits. | |
6703 | */ | |
6704 | ||
6705 | switch (form_int) | |
6706 | { | |
6707 | /* All variant. OV bit. */ | |
6708 | case 0: | |
6709 | /* We need to get to the OV bit, which is the ORDERED bit. We | |
6710 | could generate (ordered:SI (reg:CC xx) (const_int 0)), but | |
6711 | that's ugly and will trigger a validate_condition_mode abort. | |
6712 | So let's just use another pattern. */ | |
6713 | emit_insn (gen_move_from_CR_ov_bit (target, scratch)); | |
6714 | return target; | |
6715 | /* Any variant. EQ bit. */ | |
6716 | case 1: | |
6717 | code = EQ; | |
6718 | break; | |
6719 | /* Upper variant. LT bit. */ | |
6720 | case 2: | |
6721 | code = LT; | |
6722 | break; | |
6723 | /* Lower variant. GT bit. */ | |
6724 | case 3: | |
6725 | code = GT; | |
6726 | break; | |
6727 | default: | |
6728 | error ("argument 1 of __builtin_spe_predicate is out of range"); | |
6729 | return const0_rtx; | |
6730 | } | |
6731 | ||
6732 | tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx); | |
6733 | emit_move_insn (target, tmp); | |
6734 | ||
6735 | return target; | |
6736 | } | |
6737 | ||
6738 | /* The evsel builtins look like this: | |
6739 | ||
6740 | e = __builtin_spe_evsel_OP (a, b, c, d); | |
6741 | ||
6742 | and work like this: | |
6743 | ||
6744 | e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper]; | |
6745 | e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower]; | |
6746 | */ | |
6747 | ||
6748 | static rtx | |
a2369ed3 | 6749 | spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
6750 | { |
6751 | rtx pat, scratch; | |
6752 | tree arg0 = TREE_VALUE (arglist); | |
6753 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6754 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6755 | tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist)))); | |
6756 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6757 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6758 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6759 | rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0); | |
6760 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6761 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6762 | ||
6763 | if (mode0 != mode1) | |
6764 | abort (); | |
6765 | ||
6766 | if (arg0 == error_mark_node || arg1 == error_mark_node | |
6767 | || arg2 == error_mark_node || arg3 == error_mark_node) | |
6768 | return const0_rtx; | |
6769 | ||
6770 | if (target == 0 | |
6771 | || GET_MODE (target) != mode0 | |
6772 | || ! (*insn_data[icode].operand[0].predicate) (target, mode0)) | |
6773 | target = gen_reg_rtx (mode0); | |
6774 | ||
6775 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6776 | op0 = copy_to_mode_reg (mode0, op0); | |
6777 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
6778 | op1 = copy_to_mode_reg (mode0, op1); | |
6779 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
6780 | op2 = copy_to_mode_reg (mode0, op2); | |
6781 | if (! (*insn_data[icode].operand[1].predicate) (op3, mode1)) | |
6782 | op3 = copy_to_mode_reg (mode0, op3); | |
6783 | ||
6784 | /* Generate the compare. */ | |
6785 | scratch = gen_reg_rtx (CCmode); | |
6786 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
6787 | if (! pat) | |
6788 | return const0_rtx; | |
6789 | emit_insn (pat); | |
6790 | ||
6791 | if (mode0 == V2SImode) | |
6792 | emit_insn (gen_spe_evsel (target, op2, op3, scratch)); | |
6793 | else | |
6794 | emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch)); | |
6795 | ||
6796 | return target; | |
6797 | } | |
6798 | ||
0ac081f6 AH |
6799 | /* Expand an expression EXP that calls a built-in function, |
6800 | with result going to TARGET if that's convenient | |
6801 | (and in mode MODE if that's convenient). | |
6802 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
6803 | IGNORE is nonzero if the value is to be ignored. */ | |
6804 | ||
6805 | static rtx | |
a2369ed3 DJ |
6806 | rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, |
6807 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
6808 | int ignore ATTRIBUTE_UNUSED) | |
0ac081f6 | 6809 | { |
92898235 AH |
6810 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
6811 | tree arglist = TREE_OPERAND (exp, 1); | |
6812 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6813 | struct builtin_description *d; | |
6814 | size_t i; | |
6815 | rtx ret; | |
6816 | bool success; | |
6817 | ||
0ac081f6 | 6818 | if (TARGET_ALTIVEC) |
92898235 AH |
6819 | { |
6820 | ret = altivec_expand_builtin (exp, target, &success); | |
6821 | ||
a3170dc6 AH |
6822 | if (success) |
6823 | return ret; | |
6824 | } | |
6825 | if (TARGET_SPE) | |
6826 | { | |
6827 | ret = spe_expand_builtin (exp, target, &success); | |
6828 | ||
92898235 AH |
6829 | if (success) |
6830 | return ret; | |
6831 | } | |
6832 | ||
0559cc77 DE |
6833 | if (TARGET_ALTIVEC || TARGET_SPE) |
6834 | { | |
6835 | /* Handle simple unary operations. */ | |
6836 | d = (struct builtin_description *) bdesc_1arg; | |
6837 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) | |
6838 | if (d->code == fcode) | |
6839 | return rs6000_expand_unop_builtin (d->icode, arglist, target); | |
6840 | ||
6841 | /* Handle simple binary operations. */ | |
6842 | d = (struct builtin_description *) bdesc_2arg; | |
6843 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) | |
6844 | if (d->code == fcode) | |
6845 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6846 | ||
6847 | /* Handle simple ternary operations. */ | |
6848 | d = (struct builtin_description *) bdesc_3arg; | |
6849 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) | |
6850 | if (d->code == fcode) | |
6851 | return rs6000_expand_ternop_builtin (d->icode, arglist, target); | |
6852 | } | |
0ac081f6 AH |
6853 | |
6854 | abort (); | |
92898235 | 6855 | return NULL_RTX; |
0ac081f6 AH |
6856 | } |
6857 | ||
7c62e993 PB |
6858 | static tree |
6859 | build_opaque_vector_type (tree node, int nunits) | |
6860 | { | |
6861 | node = copy_node (node); | |
6862 | TYPE_MAIN_VARIANT (node) = node; | |
6863 | return build_vector_type (node, nunits); | |
6864 | } | |
6865 | ||
0ac081f6 | 6866 | static void |
863d938c | 6867 | rs6000_init_builtins (void) |
0ac081f6 | 6868 | { |
4a5eab38 PB |
6869 | V2SI_type_node = build_vector_type (intSI_type_node, 2); |
6870 | V2SF_type_node = build_vector_type (float_type_node, 2); | |
6871 | V4HI_type_node = build_vector_type (intHI_type_node, 4); | |
6872 | V4SI_type_node = build_vector_type (intSI_type_node, 4); | |
6873 | V4SF_type_node = build_vector_type (float_type_node, 4); | |
7e463bda | 6874 | V8HI_type_node = build_vector_type (intHI_type_node, 8); |
4a5eab38 PB |
6875 | V16QI_type_node = build_vector_type (intQI_type_node, 16); |
6876 | ||
6877 | unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16); | |
6878 | unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8); | |
6879 | unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4); | |
6880 | ||
7c62e993 PB |
6881 | opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2); |
6882 | opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2); | |
6035d635 | 6883 | opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node); |
3fdaa45a | 6884 | |
8bb418a3 ZL |
6885 | /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...' |
6886 | types, especially in C++ land. Similarly, 'vector pixel' is distinct from | |
6887 | 'vector unsigned short'. */ | |
6888 | ||
6889 | bool_char_type_node = copy_node (unsigned_intQI_type_node); | |
6890 | TYPE_MAIN_VARIANT (bool_char_type_node) = bool_char_type_node; | |
6891 | bool_short_type_node = copy_node (unsigned_intHI_type_node); | |
6892 | TYPE_MAIN_VARIANT (bool_short_type_node) = bool_short_type_node; | |
6893 | bool_int_type_node = copy_node (unsigned_intSI_type_node); | |
6894 | TYPE_MAIN_VARIANT (bool_int_type_node) = bool_int_type_node; | |
6895 | pixel_type_node = copy_node (unsigned_intHI_type_node); | |
6896 | TYPE_MAIN_VARIANT (pixel_type_node) = pixel_type_node; | |
6897 | ||
6898 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6899 | get_identifier ("__bool char"), | |
6900 | bool_char_type_node)); | |
6901 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6902 | get_identifier ("__bool short"), | |
6903 | bool_short_type_node)); | |
6904 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6905 | get_identifier ("__bool int"), | |
6906 | bool_int_type_node)); | |
6907 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6908 | get_identifier ("__pixel"), | |
6909 | pixel_type_node)); | |
6910 | ||
4a5eab38 PB |
6911 | bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16); |
6912 | bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8); | |
6913 | bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4); | |
6914 | pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8); | |
8bb418a3 ZL |
6915 | |
6916 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6917 | get_identifier ("__vector unsigned char"), | |
6918 | unsigned_V16QI_type_node)); | |
6919 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6920 | get_identifier ("__vector signed char"), | |
6921 | V16QI_type_node)); | |
6922 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6923 | get_identifier ("__vector __bool char"), | |
6924 | bool_V16QI_type_node)); | |
6925 | ||
6926 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6927 | get_identifier ("__vector unsigned short"), | |
6928 | unsigned_V8HI_type_node)); | |
6929 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6930 | get_identifier ("__vector signed short"), | |
6931 | V8HI_type_node)); | |
6932 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6933 | get_identifier ("__vector __bool short"), | |
6934 | bool_V8HI_type_node)); | |
6935 | ||
6936 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6937 | get_identifier ("__vector unsigned int"), | |
6938 | unsigned_V4SI_type_node)); | |
6939 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6940 | get_identifier ("__vector signed int"), | |
6941 | V4SI_type_node)); | |
6942 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6943 | get_identifier ("__vector __bool int"), | |
6944 | bool_V4SI_type_node)); | |
6945 | ||
6946 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6947 | get_identifier ("__vector float"), | |
6948 | V4SF_type_node)); | |
6949 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6950 | get_identifier ("__vector __pixel"), | |
6951 | pixel_V8HI_type_node)); | |
6952 | ||
a3170dc6 | 6953 | if (TARGET_SPE) |
3fdaa45a | 6954 | spe_init_builtins (); |
0ac081f6 AH |
6955 | if (TARGET_ALTIVEC) |
6956 | altivec_init_builtins (); | |
0559cc77 DE |
6957 | if (TARGET_ALTIVEC || TARGET_SPE) |
6958 | rs6000_common_init_builtins (); | |
0ac081f6 AH |
6959 | } |
6960 | ||
a3170dc6 AH |
6961 | /* Search through a set of builtins and enable the mask bits. |
6962 | DESC is an array of builtins. | |
b6d08ca1 | 6963 | SIZE is the total number of builtins. |
a3170dc6 AH |
6964 | START is the builtin enum at which to start. |
6965 | END is the builtin enum at which to end. */ | |
0ac081f6 | 6966 | static void |
a2369ed3 DJ |
6967 | enable_mask_for_builtins (struct builtin_description *desc, int size, |
6968 | enum rs6000_builtins start, | |
6969 | enum rs6000_builtins end) | |
a3170dc6 AH |
6970 | { |
6971 | int i; | |
6972 | ||
6973 | for (i = 0; i < size; ++i) | |
6974 | if (desc[i].code == start) | |
6975 | break; | |
6976 | ||
6977 | if (i == size) | |
6978 | return; | |
6979 | ||
6980 | for (; i < size; ++i) | |
6981 | { | |
6982 | /* Flip all the bits on. */ | |
6983 | desc[i].mask = target_flags; | |
6984 | if (desc[i].code == end) | |
6985 | break; | |
6986 | } | |
6987 | } | |
6988 | ||
6989 | static void | |
863d938c | 6990 | spe_init_builtins (void) |
0ac081f6 | 6991 | { |
a3170dc6 AH |
6992 | tree endlink = void_list_node; |
6993 | tree puint_type_node = build_pointer_type (unsigned_type_node); | |
6994 | tree pushort_type_node = build_pointer_type (short_unsigned_type_node); | |
ae4b4a02 | 6995 | struct builtin_description *d; |
0ac081f6 AH |
6996 | size_t i; |
6997 | ||
a3170dc6 AH |
6998 | tree v2si_ftype_4_v2si |
6999 | = build_function_type | |
3fdaa45a AH |
7000 | (opaque_V2SI_type_node, |
7001 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
7002 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
7003 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
7004 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
7005 | endlink))))); |
7006 | ||
7007 | tree v2sf_ftype_4_v2sf | |
7008 | = build_function_type | |
3fdaa45a AH |
7009 | (opaque_V2SF_type_node, |
7010 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
7011 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
7012 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
7013 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
7014 | endlink))))); |
7015 | ||
7016 | tree int_ftype_int_v2si_v2si | |
7017 | = build_function_type | |
7018 | (integer_type_node, | |
7019 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
7020 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
7021 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
7022 | endlink)))); |
7023 | ||
7024 | tree int_ftype_int_v2sf_v2sf | |
7025 | = build_function_type | |
7026 | (integer_type_node, | |
7027 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
7028 | tree_cons (NULL_TREE, opaque_V2SF_type_node, |
7029 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
7030 | endlink)))); |
7031 | ||
7032 | tree void_ftype_v2si_puint_int | |
7033 | = build_function_type (void_type_node, | |
3fdaa45a | 7034 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
7035 | tree_cons (NULL_TREE, puint_type_node, |
7036 | tree_cons (NULL_TREE, | |
7037 | integer_type_node, | |
7038 | endlink)))); | |
7039 | ||
7040 | tree void_ftype_v2si_puint_char | |
7041 | = build_function_type (void_type_node, | |
3fdaa45a | 7042 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
7043 | tree_cons (NULL_TREE, puint_type_node, |
7044 | tree_cons (NULL_TREE, | |
7045 | char_type_node, | |
7046 | endlink)))); | |
7047 | ||
7048 | tree void_ftype_v2si_pv2si_int | |
7049 | = build_function_type (void_type_node, | |
3fdaa45a | 7050 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 7051 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7052 | tree_cons (NULL_TREE, |
7053 | integer_type_node, | |
7054 | endlink)))); | |
7055 | ||
7056 | tree void_ftype_v2si_pv2si_char | |
7057 | = build_function_type (void_type_node, | |
3fdaa45a | 7058 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 7059 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7060 | tree_cons (NULL_TREE, |
7061 | char_type_node, | |
7062 | endlink)))); | |
7063 | ||
7064 | tree void_ftype_int | |
7065 | = build_function_type (void_type_node, | |
7066 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
7067 | ||
7068 | tree int_ftype_void | |
36e8d515 | 7069 | = build_function_type (integer_type_node, endlink); |
a3170dc6 AH |
7070 | |
7071 | tree v2si_ftype_pv2si_int | |
3fdaa45a | 7072 | = build_function_type (opaque_V2SI_type_node, |
6035d635 | 7073 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7074 | tree_cons (NULL_TREE, integer_type_node, |
7075 | endlink))); | |
7076 | ||
7077 | tree v2si_ftype_puint_int | |
3fdaa45a | 7078 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
7079 | tree_cons (NULL_TREE, puint_type_node, |
7080 | tree_cons (NULL_TREE, integer_type_node, | |
7081 | endlink))); | |
7082 | ||
7083 | tree v2si_ftype_pushort_int | |
3fdaa45a | 7084 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
7085 | tree_cons (NULL_TREE, pushort_type_node, |
7086 | tree_cons (NULL_TREE, integer_type_node, | |
7087 | endlink))); | |
7088 | ||
00332c9f AH |
7089 | tree v2si_ftype_signed_char |
7090 | = build_function_type (opaque_V2SI_type_node, | |
7091 | tree_cons (NULL_TREE, signed_char_type_node, | |
7092 | endlink)); | |
7093 | ||
a3170dc6 AH |
7094 | /* The initialization of the simple binary and unary builtins is |
7095 | done in rs6000_common_init_builtins, but we have to enable the | |
7096 | mask bits here manually because we have run out of `target_flags' | |
7097 | bits. We really need to redesign this mask business. */ | |
7098 | ||
7099 | enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg, | |
7100 | ARRAY_SIZE (bdesc_2arg), | |
7101 | SPE_BUILTIN_EVADDW, | |
7102 | SPE_BUILTIN_EVXOR); | |
7103 | enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg, | |
7104 | ARRAY_SIZE (bdesc_1arg), | |
7105 | SPE_BUILTIN_EVABS, | |
7106 | SPE_BUILTIN_EVSUBFUSIAAW); | |
7107 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates, | |
7108 | ARRAY_SIZE (bdesc_spe_predicates), | |
7109 | SPE_BUILTIN_EVCMPEQ, | |
7110 | SPE_BUILTIN_EVFSTSTLT); | |
7111 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel, | |
7112 | ARRAY_SIZE (bdesc_spe_evsel), | |
7113 | SPE_BUILTIN_EVSEL_CMPGTS, | |
7114 | SPE_BUILTIN_EVSEL_FSTSTEQ); | |
7115 | ||
36252949 AH |
7116 | (*lang_hooks.decls.pushdecl) |
7117 | (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"), | |
7118 | opaque_V2SI_type_node)); | |
7119 | ||
a3170dc6 AH |
7120 | /* Initialize irregular SPE builtins. */ |
7121 | ||
7122 | def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR); | |
7123 | def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR); | |
7124 | def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX); | |
7125 | def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX); | |
7126 | def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX); | |
7127 | def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX); | |
7128 | def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX); | |
7129 | def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX); | |
7130 | def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX); | |
7131 | def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD); | |
7132 | def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH); | |
7133 | def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW); | |
7134 | def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE); | |
7135 | def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO); | |
7136 | def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE); | |
7137 | def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO); | |
00332c9f AH |
7138 | def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI); |
7139 | def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI); | |
a3170dc6 AH |
7140 | |
7141 | /* Loads. */ | |
7142 | def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX); | |
7143 | def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX); | |
7144 | def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX); | |
7145 | def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX); | |
7146 | def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX); | |
7147 | def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX); | |
7148 | def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX); | |
7149 | def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX); | |
7150 | def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX); | |
7151 | def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX); | |
7152 | def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX); | |
7153 | def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD); | |
7154 | def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW); | |
7155 | def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH); | |
7156 | def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT); | |
7157 | def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT); | |
7158 | def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT); | |
7159 | def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE); | |
7160 | def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS); | |
7161 | def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU); | |
7162 | def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT); | |
7163 | def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT); | |
7164 | ||
7165 | /* Predicates. */ | |
7166 | d = (struct builtin_description *) bdesc_spe_predicates; | |
7167 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++) | |
7168 | { | |
7169 | tree type; | |
7170 | ||
7171 | switch (insn_data[d->icode].operand[1].mode) | |
7172 | { | |
7173 | case V2SImode: | |
7174 | type = int_ftype_int_v2si_v2si; | |
7175 | break; | |
7176 | case V2SFmode: | |
7177 | type = int_ftype_int_v2sf_v2sf; | |
7178 | break; | |
7179 | default: | |
7180 | abort (); | |
7181 | } | |
7182 | ||
7183 | def_builtin (d->mask, d->name, type, d->code); | |
7184 | } | |
7185 | ||
7186 | /* Evsel predicates. */ | |
7187 | d = (struct builtin_description *) bdesc_spe_evsel; | |
7188 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++) | |
7189 | { | |
7190 | tree type; | |
7191 | ||
7192 | switch (insn_data[d->icode].operand[1].mode) | |
7193 | { | |
7194 | case V2SImode: | |
7195 | type = v2si_ftype_4_v2si; | |
7196 | break; | |
7197 | case V2SFmode: | |
7198 | type = v2sf_ftype_4_v2sf; | |
7199 | break; | |
7200 | default: | |
7201 | abort (); | |
7202 | } | |
7203 | ||
7204 | def_builtin (d->mask, d->name, type, d->code); | |
7205 | } | |
7206 | } | |
7207 | ||
7208 | static void | |
863d938c | 7209 | altivec_init_builtins (void) |
a3170dc6 AH |
7210 | { |
7211 | struct builtin_description *d; | |
7212 | struct builtin_description_predicates *dp; | |
7213 | size_t i; | |
7214 | tree pfloat_type_node = build_pointer_type (float_type_node); | |
7215 | tree pint_type_node = build_pointer_type (integer_type_node); | |
7216 | tree pshort_type_node = build_pointer_type (short_integer_type_node); | |
7217 | tree pchar_type_node = build_pointer_type (char_type_node); | |
7218 | ||
7219 | tree pvoid_type_node = build_pointer_type (void_type_node); | |
7220 | ||
0dbc3651 ZW |
7221 | tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST)); |
7222 | tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST)); | |
7223 | tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST)); | |
7224 | tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); | |
7225 | ||
7226 | tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST)); | |
7227 | ||
a3170dc6 AH |
7228 | tree int_ftype_int_v4si_v4si |
7229 | = build_function_type_list (integer_type_node, | |
7230 | integer_type_node, V4SI_type_node, | |
7231 | V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7232 | tree v4sf_ftype_pcfloat |
7233 | = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE); | |
a3170dc6 | 7234 | tree void_ftype_pfloat_v4sf |
b4de2f7d | 7235 | = build_function_type_list (void_type_node, |
a3170dc6 | 7236 | pfloat_type_node, V4SF_type_node, NULL_TREE); |
0dbc3651 ZW |
7237 | tree v4si_ftype_pcint |
7238 | = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE); | |
7239 | tree void_ftype_pint_v4si | |
b4de2f7d AH |
7240 | = build_function_type_list (void_type_node, |
7241 | pint_type_node, V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7242 | tree v8hi_ftype_pcshort |
7243 | = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE); | |
f18c054f | 7244 | tree void_ftype_pshort_v8hi |
b4de2f7d AH |
7245 | = build_function_type_list (void_type_node, |
7246 | pshort_type_node, V8HI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7247 | tree v16qi_ftype_pcchar |
7248 | = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE); | |
f18c054f | 7249 | tree void_ftype_pchar_v16qi |
b4de2f7d AH |
7250 | = build_function_type_list (void_type_node, |
7251 | pchar_type_node, V16QI_type_node, NULL_TREE); | |
95385cbb | 7252 | tree void_ftype_v4si |
b4de2f7d | 7253 | = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE); |
a3170dc6 AH |
7254 | tree v8hi_ftype_void |
7255 | = build_function_type (V8HI_type_node, void_list_node); | |
7256 | tree void_ftype_void | |
7257 | = build_function_type (void_type_node, void_list_node); | |
7258 | tree void_ftype_qi | |
7259 | = build_function_type_list (void_type_node, char_type_node, NULL_TREE); | |
0dbc3651 | 7260 | |
b4a62fa0 | 7261 | tree v16qi_ftype_long_pcvoid |
a3170dc6 | 7262 | = build_function_type_list (V16QI_type_node, |
b4a62fa0 SB |
7263 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
7264 | tree v8hi_ftype_long_pcvoid | |
a3170dc6 | 7265 | = build_function_type_list (V8HI_type_node, |
b4a62fa0 SB |
7266 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
7267 | tree v4si_ftype_long_pcvoid | |
a3170dc6 | 7268 | = build_function_type_list (V4SI_type_node, |
b4a62fa0 | 7269 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
0dbc3651 | 7270 | |
b4a62fa0 | 7271 | tree void_ftype_v4si_long_pvoid |
b4de2f7d | 7272 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7273 | V4SI_type_node, long_integer_type_node, |
b4de2f7d | 7274 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 7275 | tree void_ftype_v16qi_long_pvoid |
b4de2f7d | 7276 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7277 | V16QI_type_node, long_integer_type_node, |
b4de2f7d | 7278 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 7279 | tree void_ftype_v8hi_long_pvoid |
b4de2f7d | 7280 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7281 | V8HI_type_node, long_integer_type_node, |
b4de2f7d | 7282 | pvoid_type_node, NULL_TREE); |
a3170dc6 AH |
7283 | tree int_ftype_int_v8hi_v8hi |
7284 | = build_function_type_list (integer_type_node, | |
7285 | integer_type_node, V8HI_type_node, | |
7286 | V8HI_type_node, NULL_TREE); | |
7287 | tree int_ftype_int_v16qi_v16qi | |
7288 | = build_function_type_list (integer_type_node, | |
7289 | integer_type_node, V16QI_type_node, | |
7290 | V16QI_type_node, NULL_TREE); | |
7291 | tree int_ftype_int_v4sf_v4sf | |
7292 | = build_function_type_list (integer_type_node, | |
7293 | integer_type_node, V4SF_type_node, | |
7294 | V4SF_type_node, NULL_TREE); | |
7295 | tree v4si_ftype_v4si | |
7296 | = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE); | |
7297 | tree v8hi_ftype_v8hi | |
7298 | = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE); | |
7299 | tree v16qi_ftype_v16qi | |
7300 | = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE); | |
7301 | tree v4sf_ftype_v4sf | |
7302 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
8bb418a3 | 7303 | tree void_ftype_pcvoid_int_int |
a3170dc6 | 7304 | = build_function_type_list (void_type_node, |
0dbc3651 | 7305 | pcvoid_type_node, integer_type_node, |
8bb418a3 ZL |
7306 | integer_type_node, NULL_TREE); |
7307 | tree int_ftype_pcchar | |
7308 | = build_function_type_list (integer_type_node, | |
7309 | pcchar_type_node, NULL_TREE); | |
7310 | ||
0dbc3651 ZW |
7311 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat, |
7312 | ALTIVEC_BUILTIN_LD_INTERNAL_4sf); | |
7313 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, | |
7314 | ALTIVEC_BUILTIN_ST_INTERNAL_4sf); | |
7315 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint, | |
7316 | ALTIVEC_BUILTIN_LD_INTERNAL_4si); | |
7317 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, | |
7318 | ALTIVEC_BUILTIN_ST_INTERNAL_4si); | |
7319 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort, | |
7320 | ALTIVEC_BUILTIN_LD_INTERNAL_8hi); | |
7321 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, | |
7322 | ALTIVEC_BUILTIN_ST_INTERNAL_8hi); | |
7323 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar, | |
7324 | ALTIVEC_BUILTIN_LD_INTERNAL_16qi); | |
7325 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, | |
7326 | ALTIVEC_BUILTIN_ST_INTERNAL_16qi); | |
a3170dc6 AH |
7327 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR); |
7328 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR); | |
7329 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL); | |
7330 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS); | |
b4a62fa0 SB |
7331 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL); |
7332 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR); | |
7333 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX); | |
7334 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX); | |
7335 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX); | |
7336 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL); | |
7337 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX); | |
7338 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX); | |
7339 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX); | |
7340 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL); | |
7341 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX); | |
7342 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX); | |
a3170dc6 | 7343 | |
8bb418a3 ZL |
7344 | /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */ |
7345 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar, | |
7346 | ALTIVEC_BUILTIN_COMPILETIME_ERROR); | |
7347 | ||
a3170dc6 AH |
7348 | /* Add the DST variants. */ |
7349 | d = (struct builtin_description *) bdesc_dst; | |
7350 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
8bb418a3 | 7351 | def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code); |
a3170dc6 AH |
7352 | |
7353 | /* Initialize the predicates. */ | |
7354 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
7355 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) | |
7356 | { | |
7357 | enum machine_mode mode1; | |
7358 | tree type; | |
7359 | ||
7360 | mode1 = insn_data[dp->icode].operand[1].mode; | |
7361 | ||
7362 | switch (mode1) | |
7363 | { | |
7364 | case V4SImode: | |
7365 | type = int_ftype_int_v4si_v4si; | |
7366 | break; | |
7367 | case V8HImode: | |
7368 | type = int_ftype_int_v8hi_v8hi; | |
7369 | break; | |
7370 | case V16QImode: | |
7371 | type = int_ftype_int_v16qi_v16qi; | |
7372 | break; | |
7373 | case V4SFmode: | |
7374 | type = int_ftype_int_v4sf_v4sf; | |
7375 | break; | |
7376 | default: | |
7377 | abort (); | |
7378 | } | |
7379 | ||
7380 | def_builtin (dp->mask, dp->name, type, dp->code); | |
7381 | } | |
7382 | ||
7383 | /* Initialize the abs* operators. */ | |
7384 | d = (struct builtin_description *) bdesc_abs; | |
7385 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) | |
7386 | { | |
7387 | enum machine_mode mode0; | |
7388 | tree type; | |
7389 | ||
7390 | mode0 = insn_data[d->icode].operand[0].mode; | |
7391 | ||
7392 | switch (mode0) | |
7393 | { | |
7394 | case V4SImode: | |
7395 | type = v4si_ftype_v4si; | |
7396 | break; | |
7397 | case V8HImode: | |
7398 | type = v8hi_ftype_v8hi; | |
7399 | break; | |
7400 | case V16QImode: | |
7401 | type = v16qi_ftype_v16qi; | |
7402 | break; | |
7403 | case V4SFmode: | |
7404 | type = v4sf_ftype_v4sf; | |
7405 | break; | |
7406 | default: | |
7407 | abort (); | |
7408 | } | |
7409 | ||
7410 | def_builtin (d->mask, d->name, type, d->code); | |
7411 | } | |
7412 | } | |
7413 | ||
7414 | static void | |
863d938c | 7415 | rs6000_common_init_builtins (void) |
a3170dc6 AH |
7416 | { |
7417 | struct builtin_description *d; | |
7418 | size_t i; | |
7419 | ||
7420 | tree v4sf_ftype_v4sf_v4sf_v16qi | |
7421 | = build_function_type_list (V4SF_type_node, | |
7422 | V4SF_type_node, V4SF_type_node, | |
7423 | V16QI_type_node, NULL_TREE); | |
7424 | tree v4si_ftype_v4si_v4si_v16qi | |
7425 | = build_function_type_list (V4SI_type_node, | |
7426 | V4SI_type_node, V4SI_type_node, | |
7427 | V16QI_type_node, NULL_TREE); | |
7428 | tree v8hi_ftype_v8hi_v8hi_v16qi | |
7429 | = build_function_type_list (V8HI_type_node, | |
7430 | V8HI_type_node, V8HI_type_node, | |
7431 | V16QI_type_node, NULL_TREE); | |
7432 | tree v16qi_ftype_v16qi_v16qi_v16qi | |
7433 | = build_function_type_list (V16QI_type_node, | |
7434 | V16QI_type_node, V16QI_type_node, | |
7435 | V16QI_type_node, NULL_TREE); | |
b9e4e5d1 ZL |
7436 | tree v4si_ftype_int |
7437 | = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE); | |
7438 | tree v8hi_ftype_int | |
7439 | = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE); | |
7440 | tree v16qi_ftype_int | |
7441 | = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE); | |
a3170dc6 AH |
7442 | tree v8hi_ftype_v16qi |
7443 | = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE); | |
7444 | tree v4sf_ftype_v4sf | |
7445 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
7446 | ||
7447 | tree v2si_ftype_v2si_v2si | |
2abe3e28 AH |
7448 | = build_function_type_list (opaque_V2SI_type_node, |
7449 | opaque_V2SI_type_node, | |
7450 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7451 | |
7452 | tree v2sf_ftype_v2sf_v2sf | |
2abe3e28 AH |
7453 | = build_function_type_list (opaque_V2SF_type_node, |
7454 | opaque_V2SF_type_node, | |
7455 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7456 | |
7457 | tree v2si_ftype_int_int | |
2abe3e28 | 7458 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
7459 | integer_type_node, integer_type_node, |
7460 | NULL_TREE); | |
7461 | ||
7462 | tree v2si_ftype_v2si | |
2abe3e28 AH |
7463 | = build_function_type_list (opaque_V2SI_type_node, |
7464 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7465 | |
7466 | tree v2sf_ftype_v2sf | |
2abe3e28 AH |
7467 | = build_function_type_list (opaque_V2SF_type_node, |
7468 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7469 | |
7470 | tree v2sf_ftype_v2si | |
2abe3e28 AH |
7471 | = build_function_type_list (opaque_V2SF_type_node, |
7472 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7473 | |
7474 | tree v2si_ftype_v2sf | |
2abe3e28 AH |
7475 | = build_function_type_list (opaque_V2SI_type_node, |
7476 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7477 | |
7478 | tree v2si_ftype_v2si_char | |
2abe3e28 AH |
7479 | = build_function_type_list (opaque_V2SI_type_node, |
7480 | opaque_V2SI_type_node, | |
7481 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
7482 | |
7483 | tree v2si_ftype_int_char | |
2abe3e28 | 7484 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
7485 | integer_type_node, char_type_node, NULL_TREE); |
7486 | ||
7487 | tree v2si_ftype_char | |
2abe3e28 AH |
7488 | = build_function_type_list (opaque_V2SI_type_node, |
7489 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
7490 | |
7491 | tree int_ftype_int_int | |
7492 | = build_function_type_list (integer_type_node, | |
7493 | integer_type_node, integer_type_node, | |
7494 | NULL_TREE); | |
95385cbb | 7495 | |
0ac081f6 | 7496 | tree v4si_ftype_v4si_v4si |
b4de2f7d AH |
7497 | = build_function_type_list (V4SI_type_node, |
7498 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
b9e4e5d1 | 7499 | tree v4sf_ftype_v4si_int |
b4de2f7d | 7500 | = build_function_type_list (V4SF_type_node, |
b9e4e5d1 ZL |
7501 | V4SI_type_node, integer_type_node, NULL_TREE); |
7502 | tree v4si_ftype_v4sf_int | |
b4de2f7d | 7503 | = build_function_type_list (V4SI_type_node, |
b9e4e5d1 ZL |
7504 | V4SF_type_node, integer_type_node, NULL_TREE); |
7505 | tree v4si_ftype_v4si_int | |
b4de2f7d | 7506 | = build_function_type_list (V4SI_type_node, |
b9e4e5d1 ZL |
7507 | V4SI_type_node, integer_type_node, NULL_TREE); |
7508 | tree v8hi_ftype_v8hi_int | |
b4de2f7d | 7509 | = build_function_type_list (V8HI_type_node, |
b9e4e5d1 ZL |
7510 | V8HI_type_node, integer_type_node, NULL_TREE); |
7511 | tree v16qi_ftype_v16qi_int | |
b4de2f7d | 7512 | = build_function_type_list (V16QI_type_node, |
b9e4e5d1 ZL |
7513 | V16QI_type_node, integer_type_node, NULL_TREE); |
7514 | tree v16qi_ftype_v16qi_v16qi_int | |
b4de2f7d AH |
7515 | = build_function_type_list (V16QI_type_node, |
7516 | V16QI_type_node, V16QI_type_node, | |
b9e4e5d1 ZL |
7517 | integer_type_node, NULL_TREE); |
7518 | tree v8hi_ftype_v8hi_v8hi_int | |
b4de2f7d AH |
7519 | = build_function_type_list (V8HI_type_node, |
7520 | V8HI_type_node, V8HI_type_node, | |
b9e4e5d1 ZL |
7521 | integer_type_node, NULL_TREE); |
7522 | tree v4si_ftype_v4si_v4si_int | |
b4de2f7d AH |
7523 | = build_function_type_list (V4SI_type_node, |
7524 | V4SI_type_node, V4SI_type_node, | |
b9e4e5d1 ZL |
7525 | integer_type_node, NULL_TREE); |
7526 | tree v4sf_ftype_v4sf_v4sf_int | |
b4de2f7d AH |
7527 | = build_function_type_list (V4SF_type_node, |
7528 | V4SF_type_node, V4SF_type_node, | |
b9e4e5d1 | 7529 | integer_type_node, NULL_TREE); |
0ac081f6 | 7530 | tree v4sf_ftype_v4sf_v4sf |
b4de2f7d AH |
7531 | = build_function_type_list (V4SF_type_node, |
7532 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
617e0e1d | 7533 | tree v4sf_ftype_v4sf_v4sf_v4si |
b4de2f7d AH |
7534 | = build_function_type_list (V4SF_type_node, |
7535 | V4SF_type_node, V4SF_type_node, | |
7536 | V4SI_type_node, NULL_TREE); | |
2212663f | 7537 | tree v4sf_ftype_v4sf_v4sf_v4sf |
b4de2f7d AH |
7538 | = build_function_type_list (V4SF_type_node, |
7539 | V4SF_type_node, V4SF_type_node, | |
7540 | V4SF_type_node, NULL_TREE); | |
617e0e1d | 7541 | tree v4si_ftype_v4si_v4si_v4si |
b4de2f7d AH |
7542 | = build_function_type_list (V4SI_type_node, |
7543 | V4SI_type_node, V4SI_type_node, | |
7544 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 7545 | tree v8hi_ftype_v8hi_v8hi |
b4de2f7d AH |
7546 | = build_function_type_list (V8HI_type_node, |
7547 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
2212663f | 7548 | tree v8hi_ftype_v8hi_v8hi_v8hi |
b4de2f7d AH |
7549 | = build_function_type_list (V8HI_type_node, |
7550 | V8HI_type_node, V8HI_type_node, | |
7551 | V8HI_type_node, NULL_TREE); | |
2212663f | 7552 | tree v4si_ftype_v8hi_v8hi_v4si |
b4de2f7d AH |
7553 | = build_function_type_list (V4SI_type_node, |
7554 | V8HI_type_node, V8HI_type_node, | |
7555 | V4SI_type_node, NULL_TREE); | |
2212663f | 7556 | tree v4si_ftype_v16qi_v16qi_v4si |
b4de2f7d AH |
7557 | = build_function_type_list (V4SI_type_node, |
7558 | V16QI_type_node, V16QI_type_node, | |
7559 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 7560 | tree v16qi_ftype_v16qi_v16qi |
b4de2f7d AH |
7561 | = build_function_type_list (V16QI_type_node, |
7562 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7563 | tree v4si_ftype_v4sf_v4sf |
b4de2f7d AH |
7564 | = build_function_type_list (V4SI_type_node, |
7565 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0ac081f6 | 7566 | tree v8hi_ftype_v16qi_v16qi |
b4de2f7d AH |
7567 | = build_function_type_list (V8HI_type_node, |
7568 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7569 | tree v4si_ftype_v8hi_v8hi |
b4de2f7d AH |
7570 | = build_function_type_list (V4SI_type_node, |
7571 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7572 | tree v8hi_ftype_v4si_v4si |
b4de2f7d AH |
7573 | = build_function_type_list (V8HI_type_node, |
7574 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
0ac081f6 | 7575 | tree v16qi_ftype_v8hi_v8hi |
b4de2f7d AH |
7576 | = build_function_type_list (V16QI_type_node, |
7577 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7578 | tree v4si_ftype_v16qi_v4si |
b4de2f7d AH |
7579 | = build_function_type_list (V4SI_type_node, |
7580 | V16QI_type_node, V4SI_type_node, NULL_TREE); | |
fa066a23 | 7581 | tree v4si_ftype_v16qi_v16qi |
b4de2f7d AH |
7582 | = build_function_type_list (V4SI_type_node, |
7583 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7584 | tree v4si_ftype_v8hi_v4si |
b4de2f7d AH |
7585 | = build_function_type_list (V4SI_type_node, |
7586 | V8HI_type_node, V4SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7587 | tree v4si_ftype_v8hi |
7588 | = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE); | |
7589 | tree int_ftype_v4si_v4si | |
7590 | = build_function_type_list (integer_type_node, | |
7591 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
7592 | tree int_ftype_v4sf_v4sf | |
7593 | = build_function_type_list (integer_type_node, | |
7594 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
7595 | tree int_ftype_v16qi_v16qi | |
7596 | = build_function_type_list (integer_type_node, | |
7597 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7598 | tree int_ftype_v8hi_v8hi |
b4de2f7d AH |
7599 | = build_function_type_list (integer_type_node, |
7600 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7601 | |
6f317ef3 | 7602 | /* Add the simple ternary operators. */ |
2212663f | 7603 | d = (struct builtin_description *) bdesc_3arg; |
ca7558fc | 7604 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) |
2212663f DB |
7605 | { |
7606 | ||
7607 | enum machine_mode mode0, mode1, mode2, mode3; | |
7608 | tree type; | |
7609 | ||
0559cc77 | 7610 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
7611 | continue; |
7612 | ||
7613 | mode0 = insn_data[d->icode].operand[0].mode; | |
7614 | mode1 = insn_data[d->icode].operand[1].mode; | |
7615 | mode2 = insn_data[d->icode].operand[2].mode; | |
7616 | mode3 = insn_data[d->icode].operand[3].mode; | |
7617 | ||
7618 | /* When all four are of the same mode. */ | |
7619 | if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3) | |
7620 | { | |
7621 | switch (mode0) | |
7622 | { | |
617e0e1d DB |
7623 | case V4SImode: |
7624 | type = v4si_ftype_v4si_v4si_v4si; | |
7625 | break; | |
2212663f DB |
7626 | case V4SFmode: |
7627 | type = v4sf_ftype_v4sf_v4sf_v4sf; | |
7628 | break; | |
7629 | case V8HImode: | |
7630 | type = v8hi_ftype_v8hi_v8hi_v8hi; | |
7631 | break; | |
7632 | case V16QImode: | |
7633 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
7634 | break; | |
7635 | default: | |
7636 | abort(); | |
7637 | } | |
7638 | } | |
7639 | else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode) | |
7640 | { | |
7641 | switch (mode0) | |
7642 | { | |
7643 | case V4SImode: | |
7644 | type = v4si_ftype_v4si_v4si_v16qi; | |
7645 | break; | |
7646 | case V4SFmode: | |
7647 | type = v4sf_ftype_v4sf_v4sf_v16qi; | |
7648 | break; | |
7649 | case V8HImode: | |
7650 | type = v8hi_ftype_v8hi_v8hi_v16qi; | |
7651 | break; | |
7652 | case V16QImode: | |
7653 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
7654 | break; | |
7655 | default: | |
7656 | abort(); | |
7657 | } | |
7658 | } | |
7659 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode | |
7660 | && mode3 == V4SImode) | |
24408032 | 7661 | type = v4si_ftype_v16qi_v16qi_v4si; |
2212663f DB |
7662 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode |
7663 | && mode3 == V4SImode) | |
24408032 | 7664 | type = v4si_ftype_v8hi_v8hi_v4si; |
617e0e1d DB |
7665 | else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode |
7666 | && mode3 == V4SImode) | |
24408032 AH |
7667 | type = v4sf_ftype_v4sf_v4sf_v4si; |
7668 | ||
7669 | /* vchar, vchar, vchar, 4 bit literal. */ | |
7670 | else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0 | |
7671 | && mode3 == QImode) | |
b9e4e5d1 | 7672 | type = v16qi_ftype_v16qi_v16qi_int; |
24408032 AH |
7673 | |
7674 | /* vshort, vshort, vshort, 4 bit literal. */ | |
7675 | else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0 | |
7676 | && mode3 == QImode) | |
b9e4e5d1 | 7677 | type = v8hi_ftype_v8hi_v8hi_int; |
24408032 AH |
7678 | |
7679 | /* vint, vint, vint, 4 bit literal. */ | |
7680 | else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0 | |
7681 | && mode3 == QImode) | |
b9e4e5d1 | 7682 | type = v4si_ftype_v4si_v4si_int; |
24408032 AH |
7683 | |
7684 | /* vfloat, vfloat, vfloat, 4 bit literal. */ | |
7685 | else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0 | |
7686 | && mode3 == QImode) | |
b9e4e5d1 | 7687 | type = v4sf_ftype_v4sf_v4sf_int; |
24408032 | 7688 | |
2212663f DB |
7689 | else |
7690 | abort (); | |
7691 | ||
7692 | def_builtin (d->mask, d->name, type, d->code); | |
7693 | } | |
7694 | ||
0ac081f6 | 7695 | /* Add the simple binary operators. */ |
00b960c7 | 7696 | d = (struct builtin_description *) bdesc_2arg; |
ca7558fc | 7697 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
0ac081f6 AH |
7698 | { |
7699 | enum machine_mode mode0, mode1, mode2; | |
7700 | tree type; | |
7701 | ||
0559cc77 | 7702 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
0ac081f6 AH |
7703 | continue; |
7704 | ||
7705 | mode0 = insn_data[d->icode].operand[0].mode; | |
7706 | mode1 = insn_data[d->icode].operand[1].mode; | |
7707 | mode2 = insn_data[d->icode].operand[2].mode; | |
7708 | ||
7709 | /* When all three operands are of the same mode. */ | |
7710 | if (mode0 == mode1 && mode1 == mode2) | |
7711 | { | |
7712 | switch (mode0) | |
7713 | { | |
7714 | case V4SFmode: | |
7715 | type = v4sf_ftype_v4sf_v4sf; | |
7716 | break; | |
7717 | case V4SImode: | |
7718 | type = v4si_ftype_v4si_v4si; | |
7719 | break; | |
7720 | case V16QImode: | |
7721 | type = v16qi_ftype_v16qi_v16qi; | |
7722 | break; | |
7723 | case V8HImode: | |
7724 | type = v8hi_ftype_v8hi_v8hi; | |
7725 | break; | |
a3170dc6 AH |
7726 | case V2SImode: |
7727 | type = v2si_ftype_v2si_v2si; | |
7728 | break; | |
7729 | case V2SFmode: | |
7730 | type = v2sf_ftype_v2sf_v2sf; | |
7731 | break; | |
7732 | case SImode: | |
7733 | type = int_ftype_int_int; | |
7734 | break; | |
0ac081f6 AH |
7735 | default: |
7736 | abort (); | |
7737 | } | |
7738 | } | |
7739 | ||
7740 | /* A few other combos we really don't want to do manually. */ | |
7741 | ||
7742 | /* vint, vfloat, vfloat. */ | |
7743 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode) | |
7744 | type = v4si_ftype_v4sf_v4sf; | |
7745 | ||
7746 | /* vshort, vchar, vchar. */ | |
7747 | else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode) | |
7748 | type = v8hi_ftype_v16qi_v16qi; | |
7749 | ||
7750 | /* vint, vshort, vshort. */ | |
7751 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode) | |
7752 | type = v4si_ftype_v8hi_v8hi; | |
7753 | ||
7754 | /* vshort, vint, vint. */ | |
7755 | else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode) | |
7756 | type = v8hi_ftype_v4si_v4si; | |
7757 | ||
7758 | /* vchar, vshort, vshort. */ | |
7759 | else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode) | |
7760 | type = v16qi_ftype_v8hi_v8hi; | |
7761 | ||
7762 | /* vint, vchar, vint. */ | |
7763 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode) | |
7764 | type = v4si_ftype_v16qi_v4si; | |
7765 | ||
fa066a23 AH |
7766 | /* vint, vchar, vchar. */ |
7767 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode) | |
7768 | type = v4si_ftype_v16qi_v16qi; | |
7769 | ||
0ac081f6 AH |
7770 | /* vint, vshort, vint. */ |
7771 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode) | |
7772 | type = v4si_ftype_v8hi_v4si; | |
2212663f DB |
7773 | |
7774 | /* vint, vint, 5 bit literal. */ | |
7775 | else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode) | |
b9e4e5d1 | 7776 | type = v4si_ftype_v4si_int; |
2212663f DB |
7777 | |
7778 | /* vshort, vshort, 5 bit literal. */ | |
7779 | else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode) | |
b9e4e5d1 | 7780 | type = v8hi_ftype_v8hi_int; |
2212663f DB |
7781 | |
7782 | /* vchar, vchar, 5 bit literal. */ | |
7783 | else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode) | |
b9e4e5d1 | 7784 | type = v16qi_ftype_v16qi_int; |
0ac081f6 | 7785 | |
617e0e1d DB |
7786 | /* vfloat, vint, 5 bit literal. */ |
7787 | else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode) | |
b9e4e5d1 | 7788 | type = v4sf_ftype_v4si_int; |
617e0e1d DB |
7789 | |
7790 | /* vint, vfloat, 5 bit literal. */ | |
7791 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode) | |
b9e4e5d1 | 7792 | type = v4si_ftype_v4sf_int; |
617e0e1d | 7793 | |
a3170dc6 AH |
7794 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode) |
7795 | type = v2si_ftype_int_int; | |
7796 | ||
7797 | else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode) | |
7798 | type = v2si_ftype_v2si_char; | |
7799 | ||
7800 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode) | |
7801 | type = v2si_ftype_int_char; | |
7802 | ||
0ac081f6 AH |
7803 | /* int, x, x. */ |
7804 | else if (mode0 == SImode) | |
7805 | { | |
7806 | switch (mode1) | |
7807 | { | |
7808 | case V4SImode: | |
7809 | type = int_ftype_v4si_v4si; | |
7810 | break; | |
7811 | case V4SFmode: | |
7812 | type = int_ftype_v4sf_v4sf; | |
7813 | break; | |
7814 | case V16QImode: | |
7815 | type = int_ftype_v16qi_v16qi; | |
7816 | break; | |
7817 | case V8HImode: | |
7818 | type = int_ftype_v8hi_v8hi; | |
7819 | break; | |
7820 | default: | |
7821 | abort (); | |
7822 | } | |
7823 | } | |
7824 | ||
7825 | else | |
7826 | abort (); | |
7827 | ||
2212663f DB |
7828 | def_builtin (d->mask, d->name, type, d->code); |
7829 | } | |
24408032 | 7830 | |
2212663f DB |
7831 | /* Add the simple unary operators. */ |
7832 | d = (struct builtin_description *) bdesc_1arg; | |
ca7558fc | 7833 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
2212663f DB |
7834 | { |
7835 | enum machine_mode mode0, mode1; | |
7836 | tree type; | |
7837 | ||
0559cc77 | 7838 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
7839 | continue; |
7840 | ||
7841 | mode0 = insn_data[d->icode].operand[0].mode; | |
7842 | mode1 = insn_data[d->icode].operand[1].mode; | |
7843 | ||
7844 | if (mode0 == V4SImode && mode1 == QImode) | |
b9e4e5d1 | 7845 | type = v4si_ftype_int; |
2212663f | 7846 | else if (mode0 == V8HImode && mode1 == QImode) |
b9e4e5d1 | 7847 | type = v8hi_ftype_int; |
2212663f | 7848 | else if (mode0 == V16QImode && mode1 == QImode) |
b9e4e5d1 | 7849 | type = v16qi_ftype_int; |
617e0e1d DB |
7850 | else if (mode0 == V4SFmode && mode1 == V4SFmode) |
7851 | type = v4sf_ftype_v4sf; | |
20e26713 AH |
7852 | else if (mode0 == V8HImode && mode1 == V16QImode) |
7853 | type = v8hi_ftype_v16qi; | |
7854 | else if (mode0 == V4SImode && mode1 == V8HImode) | |
7855 | type = v4si_ftype_v8hi; | |
a3170dc6 AH |
7856 | else if (mode0 == V2SImode && mode1 == V2SImode) |
7857 | type = v2si_ftype_v2si; | |
7858 | else if (mode0 == V2SFmode && mode1 == V2SFmode) | |
7859 | type = v2sf_ftype_v2sf; | |
7860 | else if (mode0 == V2SFmode && mode1 == V2SImode) | |
7861 | type = v2sf_ftype_v2si; | |
7862 | else if (mode0 == V2SImode && mode1 == V2SFmode) | |
7863 | type = v2si_ftype_v2sf; | |
7864 | else if (mode0 == V2SImode && mode1 == QImode) | |
7865 | type = v2si_ftype_char; | |
2212663f DB |
7866 | else |
7867 | abort (); | |
7868 | ||
0ac081f6 AH |
7869 | def_builtin (d->mask, d->name, type, d->code); |
7870 | } | |
7871 | } | |
7872 | ||
c15c90bb ZW |
7873 | static void |
7874 | rs6000_init_libfuncs (void) | |
7875 | { | |
7876 | if (!TARGET_HARD_FLOAT) | |
7877 | return; | |
7878 | ||
c9034561 | 7879 | if (DEFAULT_ABI != ABI_V4) |
c15c90bb | 7880 | { |
c9034561 | 7881 | if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC) |
c15c90bb | 7882 | { |
c9034561 | 7883 | /* AIX library routines for float->int conversion. */ |
85363ca0 ZW |
7884 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc"); |
7885 | set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc"); | |
4274207b DE |
7886 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc"); |
7887 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc"); | |
c15c90bb ZW |
7888 | } |
7889 | ||
c9034561 | 7890 | /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
7891 | set_optab_libfunc (add_optab, TFmode, "_xlqadd"); |
7892 | set_optab_libfunc (sub_optab, TFmode, "_xlqsub"); | |
7893 | set_optab_libfunc (smul_optab, TFmode, "_xlqmul"); | |
7894 | set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv"); | |
7895 | } | |
c9034561 | 7896 | else |
c15c90bb | 7897 | { |
c9034561 | 7898 | /* 32-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
7899 | |
7900 | set_optab_libfunc (add_optab, TFmode, "_q_add"); | |
7901 | set_optab_libfunc (sub_optab, TFmode, "_q_sub"); | |
7902 | set_optab_libfunc (neg_optab, TFmode, "_q_neg"); | |
7903 | set_optab_libfunc (smul_optab, TFmode, "_q_mul"); | |
7904 | set_optab_libfunc (sdiv_optab, TFmode, "_q_div"); | |
7905 | if (TARGET_PPC_GPOPT || TARGET_POWER2) | |
7906 | set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt"); | |
7907 | ||
c9034561 ZW |
7908 | set_optab_libfunc (eq_optab, TFmode, "_q_feq"); |
7909 | set_optab_libfunc (ne_optab, TFmode, "_q_fne"); | |
7910 | set_optab_libfunc (gt_optab, TFmode, "_q_fgt"); | |
7911 | set_optab_libfunc (ge_optab, TFmode, "_q_fge"); | |
7912 | set_optab_libfunc (lt_optab, TFmode, "_q_flt"); | |
7913 | set_optab_libfunc (le_optab, TFmode, "_q_fle"); | |
7914 | ||
85363ca0 ZW |
7915 | set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq"); |
7916 | set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq"); | |
7917 | set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos"); | |
7918 | set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod"); | |
7919 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi"); | |
7920 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou"); | |
7921 | set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq"); | |
c15c90bb ZW |
7922 | } |
7923 | } | |
35aff10b | 7924 | \f |
7e69e155 MM |
7925 | /* Expand a block move operation, and return 1 if successful. Return 0 |
7926 | if we should let the compiler generate normal code. | |
7927 | ||
7928 | operands[0] is the destination | |
7929 | operands[1] is the source | |
7930 | operands[2] is the length | |
7931 | operands[3] is the alignment */ | |
7932 | ||
3933e0e1 MM |
7933 | #define MAX_MOVE_REG 4 |
7934 | ||
7e69e155 | 7935 | int |
a2369ed3 | 7936 | expand_block_move (rtx operands[]) |
7e69e155 | 7937 | { |
b6c9286a MM |
7938 | rtx orig_dest = operands[0]; |
7939 | rtx orig_src = operands[1]; | |
7e69e155 | 7940 | rtx bytes_rtx = operands[2]; |
7e69e155 | 7941 | rtx align_rtx = operands[3]; |
3933e0e1 | 7942 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 7943 | int align; |
3933e0e1 MM |
7944 | int bytes; |
7945 | int offset; | |
7e69e155 | 7946 | int move_bytes; |
cabfd258 GK |
7947 | rtx stores[MAX_MOVE_REG]; |
7948 | int num_reg = 0; | |
7e69e155 | 7949 | |
3933e0e1 | 7950 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 7951 | if (! constp) |
3933e0e1 MM |
7952 | return 0; |
7953 | ||
5ee95df6 FS |
7954 | /* If this is not a fixed size alignment, abort */ |
7955 | if (GET_CODE (align_rtx) != CONST_INT) | |
7956 | abort (); | |
7957 | align = INTVAL (align_rtx); | |
7958 | ||
7e69e155 | 7959 | /* Anything to move? */ |
3933e0e1 MM |
7960 | bytes = INTVAL (bytes_rtx); |
7961 | if (bytes <= 0) | |
7e69e155 MM |
7962 | return 1; |
7963 | ||
ea9982a8 | 7964 | /* store_one_arg depends on expand_block_move to handle at least the size of |
6f317ef3 | 7965 | reg_parm_stack_space. */ |
ea9982a8 | 7966 | if (bytes > (TARGET_POWERPC64 ? 64 : 32)) |
7e69e155 MM |
7967 | return 0; |
7968 | ||
cabfd258 | 7969 | for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes) |
7e69e155 | 7970 | { |
cabfd258 | 7971 | union { |
a2369ed3 DJ |
7972 | rtx (*movstrsi) (rtx, rtx, rtx, rtx); |
7973 | rtx (*mov) (rtx, rtx); | |
cabfd258 GK |
7974 | } gen_func; |
7975 | enum machine_mode mode = BLKmode; | |
7976 | rtx src, dest; | |
7977 | ||
7978 | if (TARGET_STRING | |
7979 | && bytes > 24 /* move up to 32 bytes at a time */ | |
7980 | && ! fixed_regs[5] | |
7981 | && ! fixed_regs[6] | |
7982 | && ! fixed_regs[7] | |
7983 | && ! fixed_regs[8] | |
7984 | && ! fixed_regs[9] | |
7985 | && ! fixed_regs[10] | |
7986 | && ! fixed_regs[11] | |
7987 | && ! fixed_regs[12]) | |
7e69e155 | 7988 | { |
cabfd258 GK |
7989 | move_bytes = (bytes > 32) ? 32 : bytes; |
7990 | gen_func.movstrsi = gen_movstrsi_8reg; | |
7991 | } | |
7992 | else if (TARGET_STRING | |
7993 | && bytes > 16 /* move up to 24 bytes at a time */ | |
7994 | && ! fixed_regs[5] | |
7995 | && ! fixed_regs[6] | |
7996 | && ! fixed_regs[7] | |
7997 | && ! fixed_regs[8] | |
7998 | && ! fixed_regs[9] | |
7999 | && ! fixed_regs[10]) | |
8000 | { | |
8001 | move_bytes = (bytes > 24) ? 24 : bytes; | |
8002 | gen_func.movstrsi = gen_movstrsi_6reg; | |
8003 | } | |
8004 | else if (TARGET_STRING | |
8005 | && bytes > 8 /* move up to 16 bytes at a time */ | |
8006 | && ! fixed_regs[5] | |
8007 | && ! fixed_regs[6] | |
8008 | && ! fixed_regs[7] | |
8009 | && ! fixed_regs[8]) | |
8010 | { | |
8011 | move_bytes = (bytes > 16) ? 16 : bytes; | |
8012 | gen_func.movstrsi = gen_movstrsi_4reg; | |
8013 | } | |
8014 | else if (bytes >= 8 && TARGET_POWERPC64 | |
8015 | /* 64-bit loads and stores require word-aligned | |
8016 | displacements. */ | |
8017 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) | |
8018 | { | |
8019 | move_bytes = 8; | |
8020 | mode = DImode; | |
8021 | gen_func.mov = gen_movdi; | |
8022 | } | |
8023 | else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64) | |
8024 | { /* move up to 8 bytes at a time */ | |
8025 | move_bytes = (bytes > 8) ? 8 : bytes; | |
8026 | gen_func.movstrsi = gen_movstrsi_2reg; | |
8027 | } | |
8028 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) | |
8029 | { /* move 4 bytes */ | |
8030 | move_bytes = 4; | |
8031 | mode = SImode; | |
8032 | gen_func.mov = gen_movsi; | |
8033 | } | |
8034 | else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT)) | |
8035 | { /* move 2 bytes */ | |
8036 | move_bytes = 2; | |
8037 | mode = HImode; | |
8038 | gen_func.mov = gen_movhi; | |
8039 | } | |
8040 | else if (TARGET_STRING && bytes > 1) | |
8041 | { /* move up to 4 bytes at a time */ | |
8042 | move_bytes = (bytes > 4) ? 4 : bytes; | |
8043 | gen_func.movstrsi = gen_movstrsi_1reg; | |
8044 | } | |
8045 | else /* move 1 byte at a time */ | |
8046 | { | |
8047 | move_bytes = 1; | |
8048 | mode = QImode; | |
8049 | gen_func.mov = gen_movqi; | |
8050 | } | |
8051 | ||
8052 | src = adjust_address (orig_src, mode, offset); | |
8053 | dest = adjust_address (orig_dest, mode, offset); | |
8054 | ||
8055 | if (mode != BLKmode) | |
8056 | { | |
8057 | rtx tmp_reg = gen_reg_rtx (mode); | |
8058 | ||
8059 | emit_insn ((*gen_func.mov) (tmp_reg, src)); | |
8060 | stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg); | |
4c64a852 | 8061 | } |
3933e0e1 | 8062 | |
cabfd258 GK |
8063 | if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes) |
8064 | { | |
8065 | int i; | |
8066 | for (i = 0; i < num_reg; i++) | |
8067 | emit_insn (stores[i]); | |
8068 | num_reg = 0; | |
8069 | } | |
35aff10b | 8070 | |
cabfd258 | 8071 | if (mode == BLKmode) |
7e69e155 | 8072 | { |
cabfd258 GK |
8073 | /* Move the address into scratch registers. The movstrsi |
8074 | patterns require zero offset. */ | |
8075 | if (!REG_P (XEXP (src, 0))) | |
b6c9286a | 8076 | { |
cabfd258 GK |
8077 | rtx src_reg = copy_addr_to_reg (XEXP (src, 0)); |
8078 | src = replace_equiv_address (src, src_reg); | |
b6c9286a | 8079 | } |
cabfd258 GK |
8080 | set_mem_size (src, GEN_INT (move_bytes)); |
8081 | ||
8082 | if (!REG_P (XEXP (dest, 0))) | |
3933e0e1 | 8083 | { |
cabfd258 GK |
8084 | rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0)); |
8085 | dest = replace_equiv_address (dest, dest_reg); | |
7e69e155 | 8086 | } |
cabfd258 GK |
8087 | set_mem_size (dest, GEN_INT (move_bytes)); |
8088 | ||
8089 | emit_insn ((*gen_func.movstrsi) (dest, src, | |
8090 | GEN_INT (move_bytes & 31), | |
8091 | align_rtx)); | |
7e69e155 | 8092 | } |
7e69e155 MM |
8093 | } |
8094 | ||
8095 | return 1; | |
8096 | } | |
8097 | ||
9878760c RK |
8098 | \f |
8099 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
8100 | PARALLEL and the first section will be tested. */ | |
8101 | ||
8102 | int | |
a2369ed3 | 8103 | load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8104 | { |
8105 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8106 | unsigned int dest_regno; |
9878760c RK |
8107 | rtx src_addr; |
8108 | int i; | |
8109 | ||
8110 | /* Perform a quick check so we don't blow up below. */ | |
8111 | if (count <= 1 | |
8112 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8113 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
8114 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
8115 | return 0; | |
8116 | ||
8117 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8118 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
8119 | ||
8120 | for (i = 1; i < count; i++) | |
8121 | { | |
8122 | rtx elt = XVECEXP (op, 0, i); | |
8123 | ||
8124 | if (GET_CODE (elt) != SET | |
8125 | || GET_CODE (SET_DEST (elt)) != REG | |
8126 | || GET_MODE (SET_DEST (elt)) != SImode | |
8127 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
8128 | || GET_CODE (SET_SRC (elt)) != MEM | |
8129 | || GET_MODE (SET_SRC (elt)) != SImode | |
8130 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
8131 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
8132 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
8133 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
8134 | return 0; | |
8135 | } | |
8136 | ||
8137 | return 1; | |
8138 | } | |
8139 | ||
8140 | /* Similar, but tests for store multiple. Here, the second vector element | |
8141 | is a CLOBBER. It will be tested later. */ | |
8142 | ||
8143 | int | |
a2369ed3 | 8144 | store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8145 | { |
8146 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 8147 | unsigned int src_regno; |
9878760c RK |
8148 | rtx dest_addr; |
8149 | int i; | |
8150 | ||
8151 | /* Perform a quick check so we don't blow up below. */ | |
8152 | if (count <= 1 | |
8153 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8154 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
8155 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
8156 | return 0; | |
8157 | ||
8158 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8159 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
8160 | ||
8161 | for (i = 1; i < count; i++) | |
8162 | { | |
8163 | rtx elt = XVECEXP (op, 0, i + 1); | |
8164 | ||
8165 | if (GET_CODE (elt) != SET | |
8166 | || GET_CODE (SET_SRC (elt)) != REG | |
8167 | || GET_MODE (SET_SRC (elt)) != SImode | |
8168 | || REGNO (SET_SRC (elt)) != src_regno + i | |
8169 | || GET_CODE (SET_DEST (elt)) != MEM | |
8170 | || GET_MODE (SET_DEST (elt)) != SImode | |
8171 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
8172 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
8173 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
8174 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
8175 | return 0; | |
8176 | } | |
8177 | ||
8178 | return 1; | |
8179 | } | |
9ebbca7d | 8180 | |
9caa3eb2 DE |
8181 | /* Return a string to perform a load_multiple operation. |
8182 | operands[0] is the vector. | |
8183 | operands[1] is the source address. | |
8184 | operands[2] is the first destination register. */ | |
8185 | ||
8186 | const char * | |
a2369ed3 | 8187 | rs6000_output_load_multiple (rtx operands[3]) |
9caa3eb2 DE |
8188 | { |
8189 | /* We have to handle the case where the pseudo used to contain the address | |
8190 | is assigned to one of the output registers. */ | |
8191 | int i, j; | |
8192 | int words = XVECLEN (operands[0], 0); | |
8193 | rtx xop[10]; | |
8194 | ||
8195 | if (XVECLEN (operands[0], 0) == 1) | |
8196 | return "{l|lwz} %2,0(%1)"; | |
8197 | ||
8198 | for (i = 0; i < words; i++) | |
8199 | if (refers_to_regno_p (REGNO (operands[2]) + i, | |
8200 | REGNO (operands[2]) + i + 1, operands[1], 0)) | |
8201 | { | |
8202 | if (i == words-1) | |
8203 | { | |
8204 | xop[0] = GEN_INT (4 * (words-1)); | |
8205 | xop[1] = operands[1]; | |
8206 | xop[2] = operands[2]; | |
8207 | output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop); | |
8208 | return ""; | |
8209 | } | |
8210 | else if (i == 0) | |
8211 | { | |
8212 | xop[0] = GEN_INT (4 * (words-1)); | |
8213 | xop[1] = operands[1]; | |
8214 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
8215 | 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); | |
8216 | return ""; | |
8217 | } | |
8218 | else | |
8219 | { | |
8220 | for (j = 0; j < words; j++) | |
8221 | if (j != i) | |
8222 | { | |
8223 | xop[0] = GEN_INT (j * 4); | |
8224 | xop[1] = operands[1]; | |
8225 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j); | |
8226 | output_asm_insn ("{l|lwz} %2,%0(%1)", xop); | |
8227 | } | |
8228 | xop[0] = GEN_INT (i * 4); | |
8229 | xop[1] = operands[1]; | |
8230 | output_asm_insn ("{l|lwz} %1,%0(%1)", xop); | |
8231 | return ""; | |
8232 | } | |
8233 | } | |
8234 | ||
8235 | return "{lsi|lswi} %2,%1,%N0"; | |
8236 | } | |
8237 | ||
00b960c7 AH |
8238 | /* Return 1 for a parallel vrsave operation. */ |
8239 | ||
8240 | int | |
a2369ed3 | 8241 | vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
00b960c7 AH |
8242 | { |
8243 | int count = XVECLEN (op, 0); | |
8244 | unsigned int dest_regno, src_regno; | |
8245 | int i; | |
8246 | ||
8247 | if (count <= 1 | |
8248 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8249 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
a004eb82 | 8250 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE) |
00b960c7 AH |
8251 | return 0; |
8252 | ||
8253 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8254 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8255 | ||
8256 | if (dest_regno != VRSAVE_REGNO | |
8257 | && src_regno != VRSAVE_REGNO) | |
8258 | return 0; | |
8259 | ||
8260 | for (i = 1; i < count; i++) | |
8261 | { | |
8262 | rtx elt = XVECEXP (op, 0, i); | |
8263 | ||
9aa86737 AH |
8264 | if (GET_CODE (elt) != CLOBBER |
8265 | && GET_CODE (elt) != SET) | |
00b960c7 AH |
8266 | return 0; |
8267 | } | |
8268 | ||
8269 | return 1; | |
8270 | } | |
8271 | ||
2c4a9cff DE |
8272 | /* Return 1 for an PARALLEL suitable for mfcr. */ |
8273 | ||
8274 | int | |
a2369ed3 | 8275 | mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2c4a9cff DE |
8276 | { |
8277 | int count = XVECLEN (op, 0); | |
8278 | int i; | |
8279 | ||
8280 | /* Perform a quick check so we don't blow up below. */ | |
8281 | if (count < 1 | |
8282 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8283 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
8284 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
8285 | return 0; | |
8286 | ||
8287 | for (i = 0; i < count; i++) | |
8288 | { | |
8289 | rtx exp = XVECEXP (op, 0, i); | |
8290 | rtx unspec; | |
8291 | int maskval; | |
8292 | rtx src_reg; | |
8293 | ||
8294 | src_reg = XVECEXP (SET_SRC (exp), 0, 0); | |
8295 | ||
8296 | if (GET_CODE (src_reg) != REG | |
8297 | || GET_MODE (src_reg) != CCmode | |
8298 | || ! CR_REGNO_P (REGNO (src_reg))) | |
8299 | return 0; | |
8300 | ||
8301 | if (GET_CODE (exp) != SET | |
8302 | || GET_CODE (SET_DEST (exp)) != REG | |
8303 | || GET_MODE (SET_DEST (exp)) != SImode | |
8304 | || ! INT_REGNO_P (REGNO (SET_DEST (exp)))) | |
8305 | return 0; | |
8306 | unspec = SET_SRC (exp); | |
8307 | maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg)); | |
8308 | ||
8309 | if (GET_CODE (unspec) != UNSPEC | |
8310 | || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR | |
8311 | || XVECLEN (unspec, 0) != 2 | |
8312 | || XVECEXP (unspec, 0, 0) != src_reg | |
8313 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
8314 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
8315 | return 0; | |
8316 | } | |
8317 | return 1; | |
8318 | } | |
8319 | ||
a4f6c312 | 8320 | /* Return 1 for an PARALLEL suitable for mtcrf. */ |
9ebbca7d GK |
8321 | |
8322 | int | |
a2369ed3 | 8323 | mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
8324 | { |
8325 | int count = XVECLEN (op, 0); | |
8326 | int i; | |
9ebbca7d GK |
8327 | rtx src_reg; |
8328 | ||
8329 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
8330 | if (count < 1 |
8331 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8332 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
8333 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 8334 | return 0; |
e35b9579 | 8335 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
9ebbca7d GK |
8336 | |
8337 | if (GET_CODE (src_reg) != REG | |
8338 | || GET_MODE (src_reg) != SImode | |
8339 | || ! INT_REGNO_P (REGNO (src_reg))) | |
8340 | return 0; | |
8341 | ||
e35b9579 | 8342 | for (i = 0; i < count; i++) |
9ebbca7d GK |
8343 | { |
8344 | rtx exp = XVECEXP (op, 0, i); | |
8345 | rtx unspec; | |
8346 | int maskval; | |
8347 | ||
8348 | if (GET_CODE (exp) != SET | |
8349 | || GET_CODE (SET_DEST (exp)) != REG | |
8350 | || GET_MODE (SET_DEST (exp)) != CCmode | |
8351 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
8352 | return 0; | |
8353 | unspec = SET_SRC (exp); | |
8354 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
9ebbca7d GK |
8355 | |
8356 | if (GET_CODE (unspec) != UNSPEC | |
615158e2 | 8357 | || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR |
9ebbca7d GK |
8358 | || XVECLEN (unspec, 0) != 2 |
8359 | || XVECEXP (unspec, 0, 0) != src_reg | |
8360 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
8361 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
8362 | return 0; | |
8363 | } | |
e35b9579 | 8364 | return 1; |
9ebbca7d GK |
8365 | } |
8366 | ||
a4f6c312 | 8367 | /* Return 1 for an PARALLEL suitable for lmw. */ |
9ebbca7d GK |
8368 | |
8369 | int | |
a2369ed3 | 8370 | lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
8371 | { |
8372 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8373 | unsigned int dest_regno; |
9ebbca7d | 8374 | rtx src_addr; |
e2c953b6 | 8375 | unsigned int base_regno; |
9ebbca7d GK |
8376 | HOST_WIDE_INT offset; |
8377 | int i; | |
8378 | ||
8379 | /* Perform a quick check so we don't blow up below. */ | |
8380 | if (count <= 1 | |
8381 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8382 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
8383 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
8384 | return 0; | |
8385 | ||
8386 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8387 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
8388 | ||
8389 | if (dest_regno > 31 | |
e2c953b6 | 8390 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
8391 | return 0; |
8392 | ||
4d588c14 | 8393 | if (legitimate_indirect_address_p (src_addr, 0)) |
9ebbca7d GK |
8394 | { |
8395 | offset = 0; | |
8396 | base_regno = REGNO (src_addr); | |
8397 | if (base_regno == 0) | |
8398 | return 0; | |
8399 | } | |
4d588c14 | 8400 | else if (legitimate_offset_address_p (SImode, src_addr, 0)) |
9ebbca7d GK |
8401 | { |
8402 | offset = INTVAL (XEXP (src_addr, 1)); | |
8403 | base_regno = REGNO (XEXP (src_addr, 0)); | |
8404 | } | |
8405 | else | |
8406 | return 0; | |
8407 | ||
8408 | for (i = 0; i < count; i++) | |
8409 | { | |
8410 | rtx elt = XVECEXP (op, 0, i); | |
8411 | rtx newaddr; | |
8412 | rtx addr_reg; | |
8413 | HOST_WIDE_INT newoffset; | |
8414 | ||
8415 | if (GET_CODE (elt) != SET | |
8416 | || GET_CODE (SET_DEST (elt)) != REG | |
8417 | || GET_MODE (SET_DEST (elt)) != SImode | |
8418 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
8419 | || GET_CODE (SET_SRC (elt)) != MEM | |
8420 | || GET_MODE (SET_SRC (elt)) != SImode) | |
8421 | return 0; | |
8422 | newaddr = XEXP (SET_SRC (elt), 0); | |
4d588c14 | 8423 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
8424 | { |
8425 | newoffset = 0; | |
8426 | addr_reg = newaddr; | |
8427 | } | |
4d588c14 | 8428 | else if (legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
8429 | { |
8430 | addr_reg = XEXP (newaddr, 0); | |
8431 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
8432 | } | |
8433 | else | |
8434 | return 0; | |
8435 | if (REGNO (addr_reg) != base_regno | |
8436 | || newoffset != offset + 4 * i) | |
8437 | return 0; | |
8438 | } | |
8439 | ||
8440 | return 1; | |
8441 | } | |
8442 | ||
a4f6c312 | 8443 | /* Return 1 for an PARALLEL suitable for stmw. */ |
9ebbca7d GK |
8444 | |
8445 | int | |
a2369ed3 | 8446 | stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
8447 | { |
8448 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8449 | unsigned int src_regno; |
9ebbca7d | 8450 | rtx dest_addr; |
e2c953b6 | 8451 | unsigned int base_regno; |
9ebbca7d GK |
8452 | HOST_WIDE_INT offset; |
8453 | int i; | |
8454 | ||
8455 | /* Perform a quick check so we don't blow up below. */ | |
8456 | if (count <= 1 | |
8457 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8458 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
8459 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
8460 | return 0; | |
8461 | ||
8462 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8463 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
8464 | ||
8465 | if (src_regno > 31 | |
e2c953b6 | 8466 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
8467 | return 0; |
8468 | ||
4d588c14 | 8469 | if (legitimate_indirect_address_p (dest_addr, 0)) |
9ebbca7d GK |
8470 | { |
8471 | offset = 0; | |
8472 | base_regno = REGNO (dest_addr); | |
8473 | if (base_regno == 0) | |
8474 | return 0; | |
8475 | } | |
4d588c14 | 8476 | else if (legitimate_offset_address_p (SImode, dest_addr, 0)) |
9ebbca7d GK |
8477 | { |
8478 | offset = INTVAL (XEXP (dest_addr, 1)); | |
8479 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
8480 | } | |
8481 | else | |
8482 | return 0; | |
8483 | ||
8484 | for (i = 0; i < count; i++) | |
8485 | { | |
8486 | rtx elt = XVECEXP (op, 0, i); | |
8487 | rtx newaddr; | |
8488 | rtx addr_reg; | |
8489 | HOST_WIDE_INT newoffset; | |
8490 | ||
8491 | if (GET_CODE (elt) != SET | |
8492 | || GET_CODE (SET_SRC (elt)) != REG | |
8493 | || GET_MODE (SET_SRC (elt)) != SImode | |
8494 | || REGNO (SET_SRC (elt)) != src_regno + i | |
8495 | || GET_CODE (SET_DEST (elt)) != MEM | |
8496 | || GET_MODE (SET_DEST (elt)) != SImode) | |
8497 | return 0; | |
8498 | newaddr = XEXP (SET_DEST (elt), 0); | |
4d588c14 | 8499 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
8500 | { |
8501 | newoffset = 0; | |
8502 | addr_reg = newaddr; | |
8503 | } | |
4d588c14 | 8504 | else if (legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
8505 | { |
8506 | addr_reg = XEXP (newaddr, 0); | |
8507 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
8508 | } | |
8509 | else | |
8510 | return 0; | |
8511 | if (REGNO (addr_reg) != base_regno | |
8512 | || newoffset != offset + 4 * i) | |
8513 | return 0; | |
8514 | } | |
8515 | ||
8516 | return 1; | |
8517 | } | |
9878760c | 8518 | \f |
a4f6c312 SS |
8519 | /* A validation routine: say whether CODE, a condition code, and MODE |
8520 | match. The other alternatives either don't make sense or should | |
8521 | never be generated. */ | |
39a10a29 | 8522 | |
39a10a29 | 8523 | static void |
a2369ed3 | 8524 | validate_condition_mode (enum rtx_code code, enum machine_mode mode) |
39a10a29 | 8525 | { |
ec8e098d PB |
8526 | if ((GET_RTX_CLASS (code) != RTX_COMPARE |
8527 | && GET_RTX_CLASS (code) != RTX_COMM_COMPARE) | |
39a10a29 GK |
8528 | || GET_MODE_CLASS (mode) != MODE_CC) |
8529 | abort (); | |
8530 | ||
8531 | /* These don't make sense. */ | |
8532 | if ((code == GT || code == LT || code == GE || code == LE) | |
8533 | && mode == CCUNSmode) | |
8534 | abort (); | |
8535 | ||
8536 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
8537 | && mode != CCUNSmode) | |
8538 | abort (); | |
8539 | ||
8540 | if (mode != CCFPmode | |
8541 | && (code == ORDERED || code == UNORDERED | |
8542 | || code == UNEQ || code == LTGT | |
8543 | || code == UNGT || code == UNLT | |
8544 | || code == UNGE || code == UNLE)) | |
a4f6c312 | 8545 | abort (); |
39a10a29 | 8546 | |
de6c5979 | 8547 | /* These should never be generated except for |
bc9ec0e0 | 8548 | flag_finite_math_only. */ |
39a10a29 | 8549 | if (mode == CCFPmode |
ad72b533 | 8550 | && ! flag_finite_math_only |
39a10a29 GK |
8551 | && (code == LE || code == GE |
8552 | || code == UNEQ || code == LTGT | |
8553 | || code == UNGT || code == UNLT)) | |
8554 | abort (); | |
8555 | ||
8556 | /* These are invalid; the information is not there. */ | |
8557 | if (mode == CCEQmode | |
8558 | && code != EQ && code != NE) | |
8559 | abort (); | |
8560 | } | |
8561 | ||
9878760c RK |
8562 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
8563 | We only check the opcode against the mode of the CC value here. */ | |
8564 | ||
8565 | int | |
a2369ed3 | 8566 | branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8567 | { |
8568 | enum rtx_code code = GET_CODE (op); | |
8569 | enum machine_mode cc_mode; | |
8570 | ||
ec8e098d | 8571 | if (!COMPARISON_P (op)) |
9878760c RK |
8572 | return 0; |
8573 | ||
8574 | cc_mode = GET_MODE (XEXP (op, 0)); | |
8575 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
8576 | return 0; | |
8577 | ||
39a10a29 | 8578 | validate_condition_mode (code, cc_mode); |
9878760c | 8579 | |
39a10a29 GK |
8580 | return 1; |
8581 | } | |
8582 | ||
8583 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
8584 | insn and which is true if the corresponding bit in the CC register | |
8585 | is set. */ | |
8586 | ||
8587 | int | |
a2369ed3 | 8588 | branch_positive_comparison_operator (rtx op, enum machine_mode mode) |
39a10a29 GK |
8589 | { |
8590 | enum rtx_code code; | |
8591 | ||
8daf2e65 | 8592 | if (! branch_comparison_operator (op, mode)) |
9878760c RK |
8593 | return 0; |
8594 | ||
39a10a29 GK |
8595 | code = GET_CODE (op); |
8596 | return (code == EQ || code == LT || code == GT | |
8597 | || code == LTU || code == GTU | |
8598 | || code == UNORDERED); | |
9878760c RK |
8599 | } |
8600 | ||
b7053a3f GK |
8601 | /* Return 1 if OP is a comparison operation that is valid for an scc |
8602 | insn: it must be a positive comparison. */ | |
9878760c RK |
8603 | |
8604 | int | |
a2369ed3 | 8605 | scc_comparison_operator (rtx op, enum machine_mode mode) |
9878760c | 8606 | { |
b7053a3f | 8607 | return branch_positive_comparison_operator (op, mode); |
9878760c | 8608 | } |
e0cd0770 JC |
8609 | |
8610 | int | |
a2369ed3 | 8611 | trap_comparison_operator (rtx op, enum machine_mode mode) |
e0cd0770 JC |
8612 | { |
8613 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
8614 | return 0; | |
ec8e098d | 8615 | return COMPARISON_P (op); |
e0cd0770 | 8616 | } |
dfbdccdb GK |
8617 | |
8618 | int | |
a2369ed3 | 8619 | boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dfbdccdb GK |
8620 | { |
8621 | enum rtx_code code = GET_CODE (op); | |
8622 | return (code == AND || code == IOR || code == XOR); | |
8623 | } | |
1d328b19 GK |
8624 | |
8625 | int | |
a2369ed3 | 8626 | boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
1d328b19 GK |
8627 | { |
8628 | enum rtx_code code = GET_CODE (op); | |
8629 | return (code == IOR || code == XOR); | |
8630 | } | |
50a0b056 GK |
8631 | |
8632 | int | |
a2369ed3 | 8633 | min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
50a0b056 GK |
8634 | { |
8635 | enum rtx_code code = GET_CODE (op); | |
8636 | return (code == SMIN || code == SMAX || code == UMIN || code == UMAX); | |
8637 | } | |
9878760c RK |
8638 | \f |
8639 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
8640 | mask required to convert the result of a rotate insn into a shift | |
b1765bde | 8641 | left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */ |
9878760c RK |
8642 | |
8643 | int | |
a2369ed3 | 8644 | includes_lshift_p (rtx shiftop, rtx andop) |
9878760c | 8645 | { |
e2c953b6 DE |
8646 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
8647 | ||
8648 | shift_mask <<= INTVAL (shiftop); | |
9878760c | 8649 | |
b1765bde | 8650 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
9878760c RK |
8651 | } |
8652 | ||
8653 | /* Similar, but for right shift. */ | |
8654 | ||
8655 | int | |
a2369ed3 | 8656 | includes_rshift_p (rtx shiftop, rtx andop) |
9878760c | 8657 | { |
a7653a2c | 8658 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
8659 | |
8660 | shift_mask >>= INTVAL (shiftop); | |
8661 | ||
b1765bde | 8662 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
e2c953b6 DE |
8663 | } |
8664 | ||
c5059423 AM |
8665 | /* Return 1 if ANDOP is a mask suitable for use with an rldic insn |
8666 | to perform a left shift. It must have exactly SHIFTOP least | |
b6d08ca1 | 8667 | significant 0's, then one or more 1's, then zero or more 0's. */ |
e2c953b6 DE |
8668 | |
8669 | int | |
a2369ed3 | 8670 | includes_rldic_lshift_p (rtx shiftop, rtx andop) |
e2c953b6 | 8671 | { |
c5059423 AM |
8672 | if (GET_CODE (andop) == CONST_INT) |
8673 | { | |
02071907 | 8674 | HOST_WIDE_INT c, lsb, shift_mask; |
e2c953b6 | 8675 | |
c5059423 | 8676 | c = INTVAL (andop); |
02071907 | 8677 | if (c == 0 || c == ~0) |
c5059423 | 8678 | return 0; |
e2c953b6 | 8679 | |
02071907 | 8680 | shift_mask = ~0; |
c5059423 AM |
8681 | shift_mask <<= INTVAL (shiftop); |
8682 | ||
b6d08ca1 | 8683 | /* Find the least significant one bit. */ |
c5059423 AM |
8684 | lsb = c & -c; |
8685 | ||
8686 | /* It must coincide with the LSB of the shift mask. */ | |
8687 | if (-lsb != shift_mask) | |
8688 | return 0; | |
e2c953b6 | 8689 | |
c5059423 AM |
8690 | /* Invert to look for the next transition (if any). */ |
8691 | c = ~c; | |
8692 | ||
8693 | /* Remove the low group of ones (originally low group of zeros). */ | |
8694 | c &= -lsb; | |
8695 | ||
8696 | /* Again find the lsb, and check we have all 1's above. */ | |
8697 | lsb = c & -c; | |
8698 | return c == -lsb; | |
8699 | } | |
8700 | else if (GET_CODE (andop) == CONST_DOUBLE | |
8701 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
8702 | { | |
02071907 AM |
8703 | HOST_WIDE_INT low, high, lsb; |
8704 | HOST_WIDE_INT shift_mask_low, shift_mask_high; | |
c5059423 AM |
8705 | |
8706 | low = CONST_DOUBLE_LOW (andop); | |
8707 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8708 | high = CONST_DOUBLE_HIGH (andop); | |
8709 | ||
8710 | if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)) | |
02071907 | 8711 | || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0))) |
c5059423 AM |
8712 | return 0; |
8713 | ||
8714 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
8715 | { | |
02071907 | 8716 | shift_mask_high = ~0; |
c5059423 AM |
8717 | if (INTVAL (shiftop) > 32) |
8718 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
8719 | ||
8720 | lsb = high & -high; | |
8721 | ||
8722 | if (-lsb != shift_mask_high || INTVAL (shiftop) < 32) | |
8723 | return 0; | |
8724 | ||
8725 | high = ~high; | |
8726 | high &= -lsb; | |
8727 | ||
8728 | lsb = high & -high; | |
8729 | return high == -lsb; | |
8730 | } | |
8731 | ||
02071907 | 8732 | shift_mask_low = ~0; |
c5059423 AM |
8733 | shift_mask_low <<= INTVAL (shiftop); |
8734 | ||
8735 | lsb = low & -low; | |
8736 | ||
8737 | if (-lsb != shift_mask_low) | |
8738 | return 0; | |
8739 | ||
8740 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8741 | high = ~high; | |
8742 | low = ~low; | |
8743 | low &= -lsb; | |
8744 | ||
8745 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
8746 | { | |
8747 | lsb = high & -high; | |
8748 | return high == -lsb; | |
8749 | } | |
8750 | ||
8751 | lsb = low & -low; | |
8752 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
8753 | } | |
8754 | else | |
8755 | return 0; | |
8756 | } | |
e2c953b6 | 8757 | |
c5059423 AM |
8758 | /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn |
8759 | to perform a left shift. It must have SHIFTOP or more least | |
c1207243 | 8760 | significant 0's, with the remainder of the word 1's. */ |
e2c953b6 | 8761 | |
c5059423 | 8762 | int |
a2369ed3 | 8763 | includes_rldicr_lshift_p (rtx shiftop, rtx andop) |
c5059423 | 8764 | { |
e2c953b6 | 8765 | if (GET_CODE (andop) == CONST_INT) |
c5059423 | 8766 | { |
02071907 | 8767 | HOST_WIDE_INT c, lsb, shift_mask; |
c5059423 | 8768 | |
02071907 | 8769 | shift_mask = ~0; |
c5059423 AM |
8770 | shift_mask <<= INTVAL (shiftop); |
8771 | c = INTVAL (andop); | |
8772 | ||
c1207243 | 8773 | /* Find the least significant one bit. */ |
c5059423 AM |
8774 | lsb = c & -c; |
8775 | ||
8776 | /* It must be covered by the shift mask. | |
a4f6c312 | 8777 | This test also rejects c == 0. */ |
c5059423 AM |
8778 | if ((lsb & shift_mask) == 0) |
8779 | return 0; | |
8780 | ||
8781 | /* Check we have all 1's above the transition, and reject all 1's. */ | |
8782 | return c == -lsb && lsb != 1; | |
8783 | } | |
8784 | else if (GET_CODE (andop) == CONST_DOUBLE | |
8785 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
8786 | { | |
02071907 | 8787 | HOST_WIDE_INT low, lsb, shift_mask_low; |
c5059423 AM |
8788 | |
8789 | low = CONST_DOUBLE_LOW (andop); | |
8790 | ||
8791 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8792 | { | |
02071907 | 8793 | HOST_WIDE_INT high, shift_mask_high; |
c5059423 AM |
8794 | |
8795 | high = CONST_DOUBLE_HIGH (andop); | |
8796 | ||
8797 | if (low == 0) | |
8798 | { | |
02071907 | 8799 | shift_mask_high = ~0; |
c5059423 AM |
8800 | if (INTVAL (shiftop) > 32) |
8801 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
8802 | ||
8803 | lsb = high & -high; | |
8804 | ||
8805 | if ((lsb & shift_mask_high) == 0) | |
8806 | return 0; | |
8807 | ||
8808 | return high == -lsb; | |
8809 | } | |
8810 | if (high != ~0) | |
8811 | return 0; | |
8812 | } | |
8813 | ||
02071907 | 8814 | shift_mask_low = ~0; |
c5059423 AM |
8815 | shift_mask_low <<= INTVAL (shiftop); |
8816 | ||
8817 | lsb = low & -low; | |
8818 | ||
8819 | if ((lsb & shift_mask_low) == 0) | |
8820 | return 0; | |
8821 | ||
8822 | return low == -lsb && lsb != 1; | |
8823 | } | |
e2c953b6 | 8824 | else |
c5059423 | 8825 | return 0; |
9878760c | 8826 | } |
35068b43 RK |
8827 | |
8828 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates | |
90f81f99 | 8829 | for lfq and stfq insns iff the registers are hard registers. */ |
35068b43 RK |
8830 | |
8831 | int | |
a2369ed3 | 8832 | registers_ok_for_quad_peep (rtx reg1, rtx reg2) |
35068b43 RK |
8833 | { |
8834 | /* We might have been passed a SUBREG. */ | |
8835 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
8836 | return 0; | |
90f81f99 AP |
8837 | |
8838 | /* We might have been passed non floating point registers. */ | |
8839 | if (!FP_REGNO_P (REGNO (reg1)) | |
8840 | || !FP_REGNO_P (REGNO (reg2))) | |
8841 | return 0; | |
35068b43 RK |
8842 | |
8843 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
8844 | } | |
8845 | ||
a4f6c312 SS |
8846 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. |
8847 | addr1 and addr2 must be in consecutive memory locations | |
8848 | (addr2 == addr1 + 8). */ | |
35068b43 RK |
8849 | |
8850 | int | |
90f81f99 | 8851 | mems_ok_for_quad_peep (rtx mem1, rtx mem2) |
35068b43 | 8852 | { |
90f81f99 | 8853 | rtx addr1, addr2; |
e2c953b6 | 8854 | unsigned int reg1; |
35068b43 RK |
8855 | int offset1; |
8856 | ||
90f81f99 AP |
8857 | /* The mems cannot be volatile. */ |
8858 | if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2)) | |
8859 | return 0; | |
8860 | ||
8861 | addr1 = XEXP (mem1, 0); | |
8862 | addr2 = XEXP (mem2, 0); | |
8863 | ||
35068b43 RK |
8864 | /* Extract an offset (if used) from the first addr. */ |
8865 | if (GET_CODE (addr1) == PLUS) | |
8866 | { | |
8867 | /* If not a REG, return zero. */ | |
8868 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
8869 | return 0; | |
8870 | else | |
8871 | { | |
8872 | reg1 = REGNO (XEXP (addr1, 0)); | |
8873 | /* The offset must be constant! */ | |
8874 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
8875 | return 0; | |
8876 | offset1 = INTVAL (XEXP (addr1, 1)); | |
8877 | } | |
8878 | } | |
8879 | else if (GET_CODE (addr1) != REG) | |
8880 | return 0; | |
8881 | else | |
8882 | { | |
8883 | reg1 = REGNO (addr1); | |
8884 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
8885 | offset1 = 0; | |
8886 | } | |
8887 | ||
a2369ed3 | 8888 | /* Make sure the second address is a (mem (plus (reg) (const_int))) |
0f6937fe AM |
8889 | or if it is (mem (reg)) then make sure that offset1 is -8 and the same |
8890 | register as addr1. */ | |
984e25ac | 8891 | if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2)) |
0f6937fe | 8892 | return 1; |
35068b43 RK |
8893 | if (GET_CODE (addr2) != PLUS) |
8894 | return 0; | |
8895 | ||
8896 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
8897 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
8898 | return 0; | |
8899 | ||
8900 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
8901 | return 0; | |
8902 | ||
8903 | /* The offset for the second addr must be 8 more than the first addr. */ | |
8904 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
8905 | return 0; | |
8906 | ||
8907 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
8908 | instructions. */ | |
8909 | return 1; | |
8910 | } | |
9878760c RK |
8911 | \f |
8912 | /* Return the register class of a scratch register needed to copy IN into | |
8913 | or out of a register in CLASS in MODE. If it can be done directly, | |
8914 | NO_REGS is returned. */ | |
8915 | ||
8916 | enum reg_class | |
a2369ed3 | 8917 | secondary_reload_class (enum reg_class class, |
a9baceb1 GK |
8918 | enum machine_mode mode ATTRIBUTE_UNUSED, |
8919 | rtx in) | |
9878760c | 8920 | { |
5accd822 | 8921 | int regno; |
9878760c | 8922 | |
ab82a49f AP |
8923 | if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN |
8924 | #if TARGET_MACHO | |
8925 | && MACHOPIC_INDIRECT | |
8926 | #endif | |
8927 | )) | |
46fad5b7 DJ |
8928 | { |
8929 | /* We cannot copy a symbolic operand directly into anything | |
8930 | other than BASE_REGS for TARGET_ELF. So indicate that a | |
8931 | register from BASE_REGS is needed as an intermediate | |
8932 | register. | |
8933 | ||
8934 | On Darwin, pic addresses require a load from memory, which | |
8935 | needs a base register. */ | |
8936 | if (class != BASE_REGS | |
8937 | && (GET_CODE (in) == SYMBOL_REF | |
8938 | || GET_CODE (in) == HIGH | |
8939 | || GET_CODE (in) == LABEL_REF | |
8940 | || GET_CODE (in) == CONST)) | |
8941 | return BASE_REGS; | |
8942 | } | |
e7b7998a | 8943 | |
5accd822 DE |
8944 | if (GET_CODE (in) == REG) |
8945 | { | |
8946 | regno = REGNO (in); | |
8947 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8948 | { | |
8949 | regno = true_regnum (in); | |
8950 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8951 | regno = -1; | |
8952 | } | |
8953 | } | |
8954 | else if (GET_CODE (in) == SUBREG) | |
8955 | { | |
8956 | regno = true_regnum (in); | |
8957 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8958 | regno = -1; | |
8959 | } | |
8960 | else | |
8961 | regno = -1; | |
8962 | ||
9878760c RK |
8963 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
8964 | into anything. */ | |
8965 | if (class == GENERAL_REGS || class == BASE_REGS | |
8966 | || (regno >= 0 && INT_REGNO_P (regno))) | |
8967 | return NO_REGS; | |
8968 | ||
8969 | /* Constants, memory, and FP registers can go into FP registers. */ | |
8970 | if ((regno == -1 || FP_REGNO_P (regno)) | |
8971 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
8972 | return NO_REGS; | |
8973 | ||
0ac081f6 AH |
8974 | /* Memory, and AltiVec registers can go into AltiVec registers. */ |
8975 | if ((regno == -1 || ALTIVEC_REGNO_P (regno)) | |
8976 | && class == ALTIVEC_REGS) | |
8977 | return NO_REGS; | |
8978 | ||
9878760c RK |
8979 | /* We can copy among the CR registers. */ |
8980 | if ((class == CR_REGS || class == CR0_REGS) | |
8981 | && regno >= 0 && CR_REGNO_P (regno)) | |
8982 | return NO_REGS; | |
8983 | ||
8984 | /* Otherwise, we need GENERAL_REGS. */ | |
8985 | return GENERAL_REGS; | |
8986 | } | |
8987 | \f | |
8988 | /* Given a comparison operation, return the bit number in CCR to test. We | |
8989 | know this is a valid comparison. | |
8990 | ||
8991 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
8992 | used instead of %C, so the bits will be in different places. | |
8993 | ||
b4ac57ab | 8994 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
8995 | |
8996 | int | |
a2369ed3 | 8997 | ccr_bit (rtx op, int scc_p) |
9878760c RK |
8998 | { |
8999 | enum rtx_code code = GET_CODE (op); | |
9000 | enum machine_mode cc_mode; | |
9001 | int cc_regnum; | |
9002 | int base_bit; | |
9ebbca7d | 9003 | rtx reg; |
9878760c | 9004 | |
ec8e098d | 9005 | if (!COMPARISON_P (op)) |
9878760c RK |
9006 | return -1; |
9007 | ||
9ebbca7d GK |
9008 | reg = XEXP (op, 0); |
9009 | ||
9010 | if (GET_CODE (reg) != REG | |
9011 | || ! CR_REGNO_P (REGNO (reg))) | |
9012 | abort (); | |
9013 | ||
9014 | cc_mode = GET_MODE (reg); | |
9015 | cc_regnum = REGNO (reg); | |
9016 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 9017 | |
39a10a29 | 9018 | validate_condition_mode (code, cc_mode); |
c5defebb | 9019 | |
b7053a3f GK |
9020 | /* When generating a sCOND operation, only positive conditions are |
9021 | allowed. */ | |
9022 | if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED | |
9023 | && code != GTU && code != LTU) | |
9024 | abort (); | |
9025 | ||
9878760c RK |
9026 | switch (code) |
9027 | { | |
9028 | case NE: | |
9029 | return scc_p ? base_bit + 3 : base_bit + 2; | |
9030 | case EQ: | |
9031 | return base_bit + 2; | |
1c882ea4 | 9032 | case GT: case GTU: case UNLE: |
9878760c | 9033 | return base_bit + 1; |
1c882ea4 | 9034 | case LT: case LTU: case UNGE: |
9878760c | 9035 | return base_bit; |
1c882ea4 GK |
9036 | case ORDERED: case UNORDERED: |
9037 | return base_bit + 3; | |
9878760c RK |
9038 | |
9039 | case GE: case GEU: | |
39a10a29 | 9040 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
9041 | unordered position. So test that bit. For integer, this is ! LT |
9042 | unless this is an scc insn. */ | |
39a10a29 | 9043 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
9044 | |
9045 | case LE: case LEU: | |
39a10a29 | 9046 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 9047 | |
9878760c RK |
9048 | default: |
9049 | abort (); | |
9050 | } | |
9051 | } | |
1ff7789b | 9052 | \f |
8d30c4ee | 9053 | /* Return the GOT register. */ |
1ff7789b MM |
9054 | |
9055 | struct rtx_def * | |
a2369ed3 | 9056 | rs6000_got_register (rtx value ATTRIBUTE_UNUSED) |
1ff7789b | 9057 | { |
a4f6c312 SS |
9058 | /* The second flow pass currently (June 1999) can't update |
9059 | regs_ever_live without disturbing other parts of the compiler, so | |
9060 | update it here to make the prolog/epilogue code happy. */ | |
1db02437 FS |
9061 | if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]) |
9062 | regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
1ff7789b | 9063 | |
8d30c4ee | 9064 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 9065 | |
1ff7789b MM |
9066 | return pic_offset_table_rtx; |
9067 | } | |
a7df97e6 | 9068 | \f |
e2500fed GK |
9069 | /* Function to init struct machine_function. |
9070 | This will be called, via a pointer variable, | |
9071 | from push_function_context. */ | |
a7df97e6 | 9072 | |
e2500fed | 9073 | static struct machine_function * |
863d938c | 9074 | rs6000_init_machine_status (void) |
a7df97e6 | 9075 | { |
e2500fed | 9076 | return ggc_alloc_cleared (sizeof (machine_function)); |
a7df97e6 | 9077 | } |
9878760c | 9078 | \f |
0ba1b2ff AM |
9079 | /* These macros test for integers and extract the low-order bits. */ |
9080 | #define INT_P(X) \ | |
9081 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
9082 | && GET_MODE (X) == VOIDmode) | |
9083 | ||
9084 | #define INT_LOWPART(X) \ | |
9085 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
9086 | ||
9087 | int | |
a2369ed3 | 9088 | extract_MB (rtx op) |
0ba1b2ff AM |
9089 | { |
9090 | int i; | |
9091 | unsigned long val = INT_LOWPART (op); | |
9092 | ||
9093 | /* If the high bit is zero, the value is the first 1 bit we find | |
9094 | from the left. */ | |
9095 | if ((val & 0x80000000) == 0) | |
9096 | { | |
9097 | if ((val & 0xffffffff) == 0) | |
9098 | abort (); | |
9099 | ||
9100 | i = 1; | |
9101 | while (((val <<= 1) & 0x80000000) == 0) | |
9102 | ++i; | |
9103 | return i; | |
9104 | } | |
9105 | ||
9106 | /* If the high bit is set and the low bit is not, or the mask is all | |
9107 | 1's, the value is zero. */ | |
9108 | if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff) | |
9109 | return 0; | |
9110 | ||
9111 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
9112 | from the right. */ | |
9113 | i = 31; | |
9114 | while (((val >>= 1) & 1) != 0) | |
9115 | --i; | |
9116 | ||
9117 | return i; | |
9118 | } | |
9119 | ||
9120 | int | |
a2369ed3 | 9121 | extract_ME (rtx op) |
0ba1b2ff AM |
9122 | { |
9123 | int i; | |
9124 | unsigned long val = INT_LOWPART (op); | |
9125 | ||
9126 | /* If the low bit is zero, the value is the first 1 bit we find from | |
9127 | the right. */ | |
9128 | if ((val & 1) == 0) | |
9129 | { | |
9130 | if ((val & 0xffffffff) == 0) | |
9131 | abort (); | |
9132 | ||
9133 | i = 30; | |
9134 | while (((val >>= 1) & 1) == 0) | |
9135 | --i; | |
9136 | ||
9137 | return i; | |
9138 | } | |
9139 | ||
9140 | /* If the low bit is set and the high bit is not, or the mask is all | |
9141 | 1's, the value is 31. */ | |
9142 | if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff) | |
9143 | return 31; | |
9144 | ||
9145 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
9146 | from the left. */ | |
9147 | i = 0; | |
9148 | while (((val <<= 1) & 0x80000000) != 0) | |
9149 | ++i; | |
9150 | ||
9151 | return i; | |
9152 | } | |
9153 | ||
c4501e62 JJ |
9154 | /* Locate some local-dynamic symbol still in use by this function |
9155 | so that we can print its name in some tls_ld pattern. */ | |
9156 | ||
9157 | static const char * | |
863d938c | 9158 | rs6000_get_some_local_dynamic_name (void) |
c4501e62 JJ |
9159 | { |
9160 | rtx insn; | |
9161 | ||
9162 | if (cfun->machine->some_ld_name) | |
9163 | return cfun->machine->some_ld_name; | |
9164 | ||
9165 | for (insn = get_insns (); insn ; insn = NEXT_INSN (insn)) | |
9166 | if (INSN_P (insn) | |
9167 | && for_each_rtx (&PATTERN (insn), | |
9168 | rs6000_get_some_local_dynamic_name_1, 0)) | |
9169 | return cfun->machine->some_ld_name; | |
9170 | ||
9171 | abort (); | |
9172 | } | |
9173 | ||
9174 | /* Helper function for rs6000_get_some_local_dynamic_name. */ | |
9175 | ||
9176 | static int | |
a2369ed3 | 9177 | rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
9178 | { |
9179 | rtx x = *px; | |
9180 | ||
9181 | if (GET_CODE (x) == SYMBOL_REF) | |
9182 | { | |
9183 | const char *str = XSTR (x, 0); | |
9184 | if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC) | |
9185 | { | |
9186 | cfun->machine->some_ld_name = str; | |
9187 | return 1; | |
9188 | } | |
9189 | } | |
9190 | ||
9191 | return 0; | |
9192 | } | |
9193 | ||
9878760c RK |
9194 | /* Print an operand. Recognize special options, documented below. */ |
9195 | ||
38c1f2d7 | 9196 | #if TARGET_ELF |
d9407988 | 9197 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 9198 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
9199 | #else |
9200 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 9201 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
9202 | #endif |
9203 | ||
9878760c | 9204 | void |
a2369ed3 | 9205 | print_operand (FILE *file, rtx x, int code) |
9878760c RK |
9206 | { |
9207 | int i; | |
a260abc9 | 9208 | HOST_WIDE_INT val; |
0ba1b2ff | 9209 | unsigned HOST_WIDE_INT uval; |
9878760c RK |
9210 | |
9211 | switch (code) | |
9212 | { | |
a8b3aeda | 9213 | case '.': |
a85d226b RK |
9214 | /* Write out an instruction after the call which may be replaced |
9215 | with glue code by the loader. This depends on the AIX version. */ | |
9216 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
9217 | return; |
9218 | ||
81eace42 GK |
9219 | /* %a is output_address. */ |
9220 | ||
9854d9ed RK |
9221 | case 'A': |
9222 | /* If X is a constant integer whose low-order 5 bits are zero, | |
9223 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 9224 | in the AIX assembler where "sri" with a zero shift count |
20e26713 | 9225 | writes a trash instruction. */ |
9854d9ed | 9226 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) |
76229ac8 | 9227 | putc ('l', file); |
9854d9ed | 9228 | else |
76229ac8 | 9229 | putc ('r', file); |
9854d9ed RK |
9230 | return; |
9231 | ||
9232 | case 'b': | |
e2c953b6 DE |
9233 | /* If constant, low-order 16 bits of constant, unsigned. |
9234 | Otherwise, write normally. */ | |
9235 | if (INT_P (x)) | |
9236 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
9237 | else | |
9238 | print_operand (file, x, 0); | |
cad12a8d RK |
9239 | return; |
9240 | ||
a260abc9 DE |
9241 | case 'B': |
9242 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
9243 | for 64-bit mask direction. */ | |
296b8152 | 9244 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 9245 | return; |
a260abc9 | 9246 | |
81eace42 GK |
9247 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
9248 | output_operand. */ | |
9249 | ||
423c1189 AH |
9250 | case 'c': |
9251 | /* X is a CR register. Print the number of the GT bit of the CR. */ | |
9252 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9253 | output_operand_lossage ("invalid %%E value"); | |
9254 | else | |
9255 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1); | |
9256 | return; | |
9257 | ||
9258 | case 'D': | |
9259 | /* Like 'J' but get to the GT bit. */ | |
9260 | if (GET_CODE (x) != REG) | |
9261 | abort (); | |
9262 | ||
9263 | /* Bit 1 is GT bit. */ | |
9264 | i = 4 * (REGNO (x) - CR0_REGNO) + 1; | |
9265 | ||
9266 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
9267 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9268 | return; | |
9269 | ||
9854d9ed | 9270 | case 'E': |
39a10a29 | 9271 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
9272 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
9273 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 9274 | else |
39a10a29 | 9275 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 9276 | return; |
9854d9ed RK |
9277 | |
9278 | case 'f': | |
9279 | /* X is a CR register. Print the shift count needed to move it | |
9280 | to the high-order four bits. */ | |
9281 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9282 | output_operand_lossage ("invalid %%f value"); | |
9283 | else | |
9ebbca7d | 9284 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
9285 | return; |
9286 | ||
9287 | case 'F': | |
9288 | /* Similar, but print the count for the rotate in the opposite | |
9289 | direction. */ | |
9290 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9291 | output_operand_lossage ("invalid %%F value"); | |
9292 | else | |
9ebbca7d | 9293 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
9294 | return; |
9295 | ||
9296 | case 'G': | |
9297 | /* X is a constant integer. If it is negative, print "m", | |
43aa4e05 | 9298 | otherwise print "z". This is to make an aze or ame insn. */ |
9854d9ed RK |
9299 | if (GET_CODE (x) != CONST_INT) |
9300 | output_operand_lossage ("invalid %%G value"); | |
9301 | else if (INTVAL (x) >= 0) | |
76229ac8 | 9302 | putc ('z', file); |
9854d9ed | 9303 | else |
76229ac8 | 9304 | putc ('m', file); |
9854d9ed | 9305 | return; |
e2c953b6 | 9306 | |
9878760c | 9307 | case 'h': |
a4f6c312 SS |
9308 | /* If constant, output low-order five bits. Otherwise, write |
9309 | normally. */ | |
9878760c | 9310 | if (INT_P (x)) |
5f59ecb7 | 9311 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
9312 | else |
9313 | print_operand (file, x, 0); | |
9314 | return; | |
9315 | ||
64305719 | 9316 | case 'H': |
a4f6c312 SS |
9317 | /* If constant, output low-order six bits. Otherwise, write |
9318 | normally. */ | |
64305719 | 9319 | if (INT_P (x)) |
5f59ecb7 | 9320 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
9321 | else |
9322 | print_operand (file, x, 0); | |
9323 | return; | |
9324 | ||
9854d9ed RK |
9325 | case 'I': |
9326 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 9327 | if (INT_P (x)) |
76229ac8 | 9328 | putc ('i', file); |
9878760c RK |
9329 | return; |
9330 | ||
9854d9ed RK |
9331 | case 'j': |
9332 | /* Write the bit number in CCR for jump. */ | |
9333 | i = ccr_bit (x, 0); | |
9334 | if (i == -1) | |
9335 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 9336 | else |
9854d9ed | 9337 | fprintf (file, "%d", i); |
9878760c RK |
9338 | return; |
9339 | ||
9854d9ed RK |
9340 | case 'J': |
9341 | /* Similar, but add one for shift count in rlinm for scc and pass | |
9342 | scc flag to `ccr_bit'. */ | |
9343 | i = ccr_bit (x, 1); | |
9344 | if (i == -1) | |
9345 | output_operand_lossage ("invalid %%J code"); | |
9346 | else | |
a0466a68 RK |
9347 | /* If we want bit 31, write a shift count of zero, not 32. */ |
9348 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
9349 | return; |
9350 | ||
9854d9ed RK |
9351 | case 'k': |
9352 | /* X must be a constant. Write the 1's complement of the | |
9353 | constant. */ | |
9878760c | 9354 | if (! INT_P (x)) |
9854d9ed | 9355 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
9356 | else |
9357 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
9358 | return; |
9359 | ||
81eace42 | 9360 | case 'K': |
9ebbca7d GK |
9361 | /* X must be a symbolic constant on ELF. Write an |
9362 | expression suitable for an 'addi' that adds in the low 16 | |
9363 | bits of the MEM. */ | |
9364 | if (GET_CODE (x) != CONST) | |
9365 | { | |
9366 | print_operand_address (file, x); | |
9367 | fputs ("@l", file); | |
9368 | } | |
9369 | else | |
9370 | { | |
9371 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
9372 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
9373 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
9374 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 9375 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
9376 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
9377 | fputs ("@l", file); | |
ed8d2920 MM |
9378 | /* For GNU as, there must be a non-alphanumeric character |
9379 | between 'l' and the number. The '-' is added by | |
9380 | print_operand() already. */ | |
9381 | if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0) | |
9382 | fputs ("+", file); | |
9ebbca7d GK |
9383 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); |
9384 | } | |
81eace42 GK |
9385 | return; |
9386 | ||
9387 | /* %l is output_asm_label. */ | |
9ebbca7d | 9388 | |
9854d9ed RK |
9389 | case 'L': |
9390 | /* Write second word of DImode or DFmode reference. Works on register | |
9391 | or non-indexed memory only. */ | |
9392 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9393 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
9394 | else if (GET_CODE (x) == MEM) |
9395 | { | |
9396 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 9397 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
9398 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
9399 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
ed8908e7 RK |
9400 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), |
9401 | UNITS_PER_WORD)); | |
9854d9ed | 9402 | else |
d7624dc0 RK |
9403 | output_address (XEXP (adjust_address_nv (x, SImode, |
9404 | UNITS_PER_WORD), | |
9405 | 0)); | |
ed8908e7 | 9406 | |
ba5e43aa | 9407 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9408 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9409 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 9410 | } |
9878760c | 9411 | return; |
9854d9ed | 9412 | |
9878760c RK |
9413 | case 'm': |
9414 | /* MB value for a mask operand. */ | |
b1765bde | 9415 | if (! mask_operand (x, SImode)) |
9878760c RK |
9416 | output_operand_lossage ("invalid %%m value"); |
9417 | ||
0ba1b2ff | 9418 | fprintf (file, "%d", extract_MB (x)); |
9878760c RK |
9419 | return; |
9420 | ||
9421 | case 'M': | |
9422 | /* ME value for a mask operand. */ | |
b1765bde | 9423 | if (! mask_operand (x, SImode)) |
a260abc9 | 9424 | output_operand_lossage ("invalid %%M value"); |
9878760c | 9425 | |
0ba1b2ff | 9426 | fprintf (file, "%d", extract_ME (x)); |
9878760c RK |
9427 | return; |
9428 | ||
81eace42 GK |
9429 | /* %n outputs the negative of its operand. */ |
9430 | ||
9878760c RK |
9431 | case 'N': |
9432 | /* Write the number of elements in the vector times 4. */ | |
9433 | if (GET_CODE (x) != PARALLEL) | |
9434 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
9435 | else |
9436 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
9437 | return; |
9438 | ||
9439 | case 'O': | |
9440 | /* Similar, but subtract 1 first. */ | |
9441 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 9442 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
9443 | else |
9444 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
9445 | return; |
9446 | ||
9854d9ed RK |
9447 | case 'p': |
9448 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
9449 | if (! INT_P (x) | |
2bfcf297 | 9450 | || INT_LOWPART (x) < 0 |
9854d9ed RK |
9451 | || (i = exact_log2 (INT_LOWPART (x))) < 0) |
9452 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
9453 | else |
9454 | fprintf (file, "%d", i); | |
9854d9ed RK |
9455 | return; |
9456 | ||
9878760c RK |
9457 | case 'P': |
9458 | /* The operand must be an indirect memory reference. The result | |
8bb418a3 | 9459 | is the register name. */ |
9878760c RK |
9460 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG |
9461 | || REGNO (XEXP (x, 0)) >= 32) | |
9462 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 | 9463 | else |
8bb418a3 | 9464 | fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]); |
9878760c RK |
9465 | return; |
9466 | ||
dfbdccdb GK |
9467 | case 'q': |
9468 | /* This outputs the logical code corresponding to a boolean | |
9469 | expression. The expression may have one or both operands | |
39a10a29 GK |
9470 | negated (if one, only the first one). For condition register |
9471 | logical operations, it will also treat the negated | |
9472 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 9473 | { |
63bc1d05 | 9474 | const char *const *t = 0; |
dfbdccdb GK |
9475 | const char *s; |
9476 | enum rtx_code code = GET_CODE (x); | |
9477 | static const char * const tbl[3][3] = { | |
9478 | { "and", "andc", "nor" }, | |
9479 | { "or", "orc", "nand" }, | |
9480 | { "xor", "eqv", "xor" } }; | |
9481 | ||
9482 | if (code == AND) | |
9483 | t = tbl[0]; | |
9484 | else if (code == IOR) | |
9485 | t = tbl[1]; | |
9486 | else if (code == XOR) | |
9487 | t = tbl[2]; | |
9488 | else | |
9489 | output_operand_lossage ("invalid %%q value"); | |
9490 | ||
9491 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
9492 | s = t[0]; | |
9493 | else | |
9494 | { | |
9495 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
9496 | s = t[2]; | |
9497 | else | |
9498 | s = t[1]; | |
9499 | } | |
9500 | ||
9501 | fputs (s, file); | |
9502 | } | |
9503 | return; | |
9504 | ||
2c4a9cff DE |
9505 | case 'Q': |
9506 | if (TARGET_MFCRF) | |
3b6ce0af | 9507 | fputc (',', file); |
5efb1046 | 9508 | /* FALLTHRU */ |
2c4a9cff DE |
9509 | else |
9510 | return; | |
9511 | ||
9854d9ed RK |
9512 | case 'R': |
9513 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
9514 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9515 | output_operand_lossage ("invalid %%R value"); | |
9516 | else | |
9ebbca7d | 9517 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 9518 | return; |
9854d9ed RK |
9519 | |
9520 | case 's': | |
9521 | /* Low 5 bits of 32 - value */ | |
9522 | if (! INT_P (x)) | |
9523 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
9524 | else |
9525 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 9526 | return; |
9854d9ed | 9527 | |
a260abc9 | 9528 | case 'S': |
0ba1b2ff | 9529 | /* PowerPC64 mask position. All 0's is excluded. |
a260abc9 DE |
9530 | CONST_INT 32-bit mask is considered sign-extended so any |
9531 | transition must occur within the CONST_INT, not on the boundary. */ | |
b1765bde | 9532 | if (! mask64_operand (x, DImode)) |
a260abc9 DE |
9533 | output_operand_lossage ("invalid %%S value"); |
9534 | ||
0ba1b2ff | 9535 | uval = INT_LOWPART (x); |
a260abc9 | 9536 | |
0ba1b2ff | 9537 | if (uval & 1) /* Clear Left */ |
a260abc9 | 9538 | { |
f099d360 GK |
9539 | #if HOST_BITS_PER_WIDE_INT > 64 |
9540 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
9541 | #endif | |
0ba1b2ff | 9542 | i = 64; |
a260abc9 | 9543 | } |
0ba1b2ff | 9544 | else /* Clear Right */ |
a260abc9 | 9545 | { |
0ba1b2ff | 9546 | uval = ~uval; |
f099d360 GK |
9547 | #if HOST_BITS_PER_WIDE_INT > 64 |
9548 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
9549 | #endif | |
0ba1b2ff | 9550 | i = 63; |
a260abc9 | 9551 | } |
0ba1b2ff AM |
9552 | while (uval != 0) |
9553 | --i, uval >>= 1; | |
9554 | if (i < 0) | |
9555 | abort (); | |
9556 | fprintf (file, "%d", i); | |
9557 | return; | |
a260abc9 | 9558 | |
a3170dc6 AH |
9559 | case 't': |
9560 | /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */ | |
9561 | if (GET_CODE (x) != REG || GET_MODE (x) != CCmode) | |
9562 | abort (); | |
9563 | ||
9564 | /* Bit 3 is OV bit. */ | |
9565 | i = 4 * (REGNO (x) - CR0_REGNO) + 3; | |
9566 | ||
9567 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
9568 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9569 | return; | |
9570 | ||
cccf3bdc DE |
9571 | case 'T': |
9572 | /* Print the symbolic name of a branch target register. */ | |
9573 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
9574 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
9575 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 9576 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
9577 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
9578 | else | |
9579 | fputs ("ctr", file); | |
9580 | return; | |
9581 | ||
9854d9ed | 9582 | case 'u': |
802a0058 | 9583 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
9584 | if (! INT_P (x)) |
9585 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 DE |
9586 | else |
9587 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, | |
9588 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
9589 | return; |
9590 | ||
802a0058 MM |
9591 | case 'v': |
9592 | /* High-order 16 bits of constant for use in signed operand. */ | |
9593 | if (! INT_P (x)) | |
9594 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 | 9595 | else |
134c32f6 DE |
9596 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
9597 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9598 | return; | |
802a0058 | 9599 | |
9854d9ed RK |
9600 | case 'U': |
9601 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
9602 | if (GET_CODE (x) == MEM | |
9603 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
9604 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 9605 | putc ('u', file); |
9854d9ed | 9606 | return; |
9878760c | 9607 | |
e0cd0770 JC |
9608 | case 'V': |
9609 | /* Print the trap code for this operand. */ | |
9610 | switch (GET_CODE (x)) | |
9611 | { | |
9612 | case EQ: | |
9613 | fputs ("eq", file); /* 4 */ | |
9614 | break; | |
9615 | case NE: | |
9616 | fputs ("ne", file); /* 24 */ | |
9617 | break; | |
9618 | case LT: | |
9619 | fputs ("lt", file); /* 16 */ | |
9620 | break; | |
9621 | case LE: | |
9622 | fputs ("le", file); /* 20 */ | |
9623 | break; | |
9624 | case GT: | |
9625 | fputs ("gt", file); /* 8 */ | |
9626 | break; | |
9627 | case GE: | |
9628 | fputs ("ge", file); /* 12 */ | |
9629 | break; | |
9630 | case LTU: | |
9631 | fputs ("llt", file); /* 2 */ | |
9632 | break; | |
9633 | case LEU: | |
9634 | fputs ("lle", file); /* 6 */ | |
9635 | break; | |
9636 | case GTU: | |
9637 | fputs ("lgt", file); /* 1 */ | |
9638 | break; | |
9639 | case GEU: | |
9640 | fputs ("lge", file); /* 5 */ | |
9641 | break; | |
9642 | default: | |
9643 | abort (); | |
9644 | } | |
9645 | break; | |
9646 | ||
9854d9ed RK |
9647 | case 'w': |
9648 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
9649 | normally. */ | |
9650 | if (INT_P (x)) | |
5f59ecb7 DE |
9651 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
9652 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
9653 | else |
9654 | print_operand (file, x, 0); | |
9878760c RK |
9655 | return; |
9656 | ||
9854d9ed | 9657 | case 'W': |
e2c953b6 | 9658 | /* MB value for a PowerPC64 rldic operand. */ |
e2c953b6 DE |
9659 | val = (GET_CODE (x) == CONST_INT |
9660 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
9661 | ||
9662 | if (val < 0) | |
9663 | i = -1; | |
9854d9ed | 9664 | else |
e2c953b6 DE |
9665 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
9666 | if ((val <<= 1) < 0) | |
9667 | break; | |
9668 | ||
9669 | #if HOST_BITS_PER_WIDE_INT == 32 | |
9670 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
9671 | i += 32; /* zero-extend high-part was all 0's */ | |
9672 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
9673 | { | |
9674 | val = CONST_DOUBLE_LOW (x); | |
9675 | ||
9676 | if (val == 0) | |
a4f6c312 | 9677 | abort (); |
e2c953b6 DE |
9678 | else if (val < 0) |
9679 | --i; | |
9680 | else | |
9681 | for ( ; i < 64; i++) | |
9682 | if ((val <<= 1) < 0) | |
9683 | break; | |
9684 | } | |
9685 | #endif | |
9686 | ||
9687 | fprintf (file, "%d", i + 1); | |
9854d9ed | 9688 | return; |
9878760c | 9689 | |
9854d9ed RK |
9690 | case 'X': |
9691 | if (GET_CODE (x) == MEM | |
4d588c14 | 9692 | && legitimate_indexed_address_p (XEXP (x, 0), 0)) |
76229ac8 | 9693 | putc ('x', file); |
9854d9ed | 9694 | return; |
9878760c | 9695 | |
9854d9ed RK |
9696 | case 'Y': |
9697 | /* Like 'L', for third word of TImode */ | |
9698 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9699 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 9700 | else if (GET_CODE (x) == MEM) |
9878760c | 9701 | { |
9854d9ed RK |
9702 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
9703 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 9704 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 9705 | else |
d7624dc0 | 9706 | output_address (XEXP (adjust_address_nv (x, SImode, 8), 0)); |
ba5e43aa | 9707 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9708 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9709 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
9710 | } |
9711 | return; | |
9854d9ed | 9712 | |
9878760c | 9713 | case 'z': |
b4ac57ab RS |
9714 | /* X is a SYMBOL_REF. Write out the name preceded by a |
9715 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
9716 | names. If we are configured for System V (or the embedded ABI) on |
9717 | the PowerPC, do not emit the period, since those systems do not use | |
9718 | TOCs and the like. */ | |
9878760c RK |
9719 | if (GET_CODE (x) != SYMBOL_REF) |
9720 | abort (); | |
9721 | ||
9bf6462a AP |
9722 | /* Mark the decl as referenced so that cgraph will output the function. */ |
9723 | if (SYMBOL_REF_DECL (x)) | |
9724 | mark_decl_referenced (SYMBOL_REF_DECL (x)); | |
9725 | ||
b6c9286a MM |
9726 | if (XSTR (x, 0)[0] != '.') |
9727 | { | |
9728 | switch (DEFAULT_ABI) | |
9729 | { | |
9730 | default: | |
9731 | abort (); | |
9732 | ||
9733 | case ABI_AIX: | |
9734 | putc ('.', file); | |
9735 | break; | |
9736 | ||
9737 | case ABI_V4: | |
ee890fe2 | 9738 | case ABI_DARWIN: |
b6c9286a | 9739 | break; |
b6c9286a MM |
9740 | } |
9741 | } | |
f9da97f0 AP |
9742 | /* For macho, we need to check it see if we need a stub. */ |
9743 | if (TARGET_MACHO) | |
9744 | { | |
9745 | const char *name = XSTR (x, 0); | |
a031e781 | 9746 | #if TARGET_MACHO |
f9da97f0 AP |
9747 | if (machopic_classify_name (name) == MACHOPIC_UNDEFINED_FUNCTION) |
9748 | name = machopic_stub_name (name); | |
9749 | #endif | |
9750 | assemble_name (file, name); | |
9751 | } | |
9752 | else if (TARGET_AIX) | |
9739c90c JJ |
9753 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); |
9754 | else | |
9755 | assemble_name (file, XSTR (x, 0)); | |
9878760c RK |
9756 | return; |
9757 | ||
9854d9ed RK |
9758 | case 'Z': |
9759 | /* Like 'L', for last word of TImode. */ | |
9760 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9761 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
9762 | else if (GET_CODE (x) == MEM) |
9763 | { | |
9764 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
9765 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 9766 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 9767 | else |
d7624dc0 | 9768 | output_address (XEXP (adjust_address_nv (x, SImode, 12), 0)); |
ba5e43aa | 9769 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9770 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9771 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 9772 | } |
5c23c401 | 9773 | return; |
0ac081f6 | 9774 | |
a3170dc6 | 9775 | /* Print AltiVec or SPE memory operand. */ |
0ac081f6 AH |
9776 | case 'y': |
9777 | { | |
9778 | rtx tmp; | |
9779 | ||
9780 | if (GET_CODE (x) != MEM) | |
9781 | abort (); | |
9782 | ||
9783 | tmp = XEXP (x, 0); | |
9784 | ||
993f19a8 | 9785 | if (TARGET_E500) |
a3170dc6 AH |
9786 | { |
9787 | /* Handle [reg]. */ | |
9788 | if (GET_CODE (tmp) == REG) | |
9789 | { | |
9790 | fprintf (file, "0(%s)", reg_names[REGNO (tmp)]); | |
9791 | break; | |
9792 | } | |
9793 | /* Handle [reg+UIMM]. */ | |
9794 | else if (GET_CODE (tmp) == PLUS && | |
9795 | GET_CODE (XEXP (tmp, 1)) == CONST_INT) | |
9796 | { | |
9797 | int x; | |
9798 | ||
9799 | if (GET_CODE (XEXP (tmp, 0)) != REG) | |
9800 | abort (); | |
9801 | ||
9802 | x = INTVAL (XEXP (tmp, 1)); | |
9803 | fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]); | |
9804 | break; | |
9805 | } | |
9806 | ||
9807 | /* Fall through. Must be [reg+reg]. */ | |
9808 | } | |
0ac081f6 | 9809 | if (GET_CODE (tmp) == REG) |
c62f2db5 | 9810 | fprintf (file, "0,%s", reg_names[REGNO (tmp)]); |
0ac081f6 AH |
9811 | else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG) |
9812 | { | |
9813 | if (REGNO (XEXP (tmp, 0)) == 0) | |
9814 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ], | |
9815 | reg_names[ REGNO (XEXP (tmp, 0)) ]); | |
9816 | else | |
9817 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ], | |
9818 | reg_names[ REGNO (XEXP (tmp, 1)) ]); | |
9819 | } | |
9820 | else | |
9821 | abort (); | |
9822 | break; | |
9823 | } | |
9854d9ed | 9824 | |
9878760c RK |
9825 | case 0: |
9826 | if (GET_CODE (x) == REG) | |
9827 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
9828 | else if (GET_CODE (x) == MEM) | |
9829 | { | |
9830 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
9831 | know the width from the mode. */ | |
9832 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
9833 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
9834 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 9835 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
9836 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
9837 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 9838 | else |
a54d04b7 | 9839 | output_address (XEXP (x, 0)); |
9878760c RK |
9840 | } |
9841 | else | |
a54d04b7 | 9842 | output_addr_const (file, x); |
a85d226b | 9843 | return; |
9878760c | 9844 | |
c4501e62 JJ |
9845 | case '&': |
9846 | assemble_name (file, rs6000_get_some_local_dynamic_name ()); | |
9847 | return; | |
9848 | ||
9878760c RK |
9849 | default: |
9850 | output_operand_lossage ("invalid %%xn code"); | |
9851 | } | |
9852 | } | |
9853 | \f | |
9854 | /* Print the address of an operand. */ | |
9855 | ||
9856 | void | |
a2369ed3 | 9857 | print_operand_address (FILE *file, rtx x) |
9878760c RK |
9858 | { |
9859 | if (GET_CODE (x) == REG) | |
4697a36c | 9860 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
9861 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
9862 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
9863 | { |
9864 | output_addr_const (file, x); | |
ba5e43aa | 9865 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9866 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9867 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d | 9868 | else if (TARGET_TOC) |
a4f6c312 | 9869 | abort (); |
9878760c RK |
9870 | } |
9871 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
9872 | { | |
9873 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
9874 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
9875 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 9876 | else |
4697a36c MM |
9877 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
9878 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
9879 | } |
9880 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
4a0a75dd KG |
9881 | fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)", |
9882 | INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]); | |
3cb999d8 DE |
9883 | #if TARGET_ELF |
9884 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
9885 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
9886 | { |
9887 | output_addr_const (file, XEXP (x, 1)); | |
9888 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
9889 | } | |
c859cda6 DJ |
9890 | #endif |
9891 | #if TARGET_MACHO | |
9892 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
9893 | && CONSTANT_P (XEXP (x, 1))) | |
9894 | { | |
9895 | fprintf (file, "lo16("); | |
9896 | output_addr_const (file, XEXP (x, 1)); | |
9897 | fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
9898 | } | |
3cb999d8 | 9899 | #endif |
4d588c14 | 9900 | else if (legitimate_constant_pool_address_p (x)) |
9ebbca7d | 9901 | { |
2bfcf297 | 9902 | if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC)) |
9ebbca7d | 9903 | { |
2bfcf297 DB |
9904 | rtx contains_minus = XEXP (x, 1); |
9905 | rtx minus, symref; | |
9906 | const char *name; | |
9ebbca7d GK |
9907 | |
9908 | /* Find the (minus (sym) (toc)) buried in X, and temporarily | |
a4f6c312 | 9909 | turn it into (sym) for output_addr_const. */ |
9ebbca7d GK |
9910 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) |
9911 | contains_minus = XEXP (contains_minus, 0); | |
9912 | ||
2bfcf297 DB |
9913 | minus = XEXP (contains_minus, 0); |
9914 | symref = XEXP (minus, 0); | |
9915 | XEXP (contains_minus, 0) = symref; | |
9916 | if (TARGET_ELF) | |
9917 | { | |
9918 | char *newname; | |
9919 | ||
9920 | name = XSTR (symref, 0); | |
9921 | newname = alloca (strlen (name) + sizeof ("@toc")); | |
9922 | strcpy (newname, name); | |
9923 | strcat (newname, "@toc"); | |
9924 | XSTR (symref, 0) = newname; | |
9925 | } | |
9926 | output_addr_const (file, XEXP (x, 1)); | |
9927 | if (TARGET_ELF) | |
9928 | XSTR (symref, 0) = name; | |
9ebbca7d GK |
9929 | XEXP (contains_minus, 0) = minus; |
9930 | } | |
9931 | else | |
9932 | output_addr_const (file, XEXP (x, 1)); | |
9933 | ||
9934 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
9935 | } | |
9878760c RK |
9936 | else |
9937 | abort (); | |
9938 | } | |
9939 | \f | |
88cad84b | 9940 | /* Target hook for assembling integer objects. The PowerPC version has |
301d03af RS |
9941 | to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP |
9942 | is defined. It also needs to handle DI-mode objects on 64-bit | |
9943 | targets. */ | |
9944 | ||
9945 | static bool | |
a2369ed3 | 9946 | rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p) |
301d03af RS |
9947 | { |
9948 | #ifdef RELOCATABLE_NEEDS_FIXUP | |
9949 | /* Special handling for SI values. */ | |
9950 | if (size == 4 && aligned_p) | |
9951 | { | |
a2369ed3 | 9952 | extern int in_toc_section (void); |
301d03af RS |
9953 | static int recurse = 0; |
9954 | ||
9955 | /* For -mrelocatable, we mark all addresses that need to be fixed up | |
9956 | in the .fixup section. */ | |
9957 | if (TARGET_RELOCATABLE | |
9958 | && !in_toc_section () | |
9959 | && !in_text_section () | |
642af3be | 9960 | && !in_unlikely_text_section () |
301d03af RS |
9961 | && !recurse |
9962 | && GET_CODE (x) != CONST_INT | |
9963 | && GET_CODE (x) != CONST_DOUBLE | |
9964 | && CONSTANT_P (x)) | |
9965 | { | |
9966 | char buf[256]; | |
9967 | ||
9968 | recurse = 1; | |
9969 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno); | |
9970 | fixuplabelno++; | |
9971 | ASM_OUTPUT_LABEL (asm_out_file, buf); | |
9972 | fprintf (asm_out_file, "\t.long\t("); | |
9973 | output_addr_const (asm_out_file, x); | |
9974 | fprintf (asm_out_file, ")@fixup\n"); | |
9975 | fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n"); | |
9976 | ASM_OUTPUT_ALIGN (asm_out_file, 2); | |
9977 | fprintf (asm_out_file, "\t.long\t"); | |
9978 | assemble_name (asm_out_file, buf); | |
9979 | fprintf (asm_out_file, "\n\t.previous\n"); | |
9980 | recurse = 0; | |
9981 | return true; | |
9982 | } | |
9983 | /* Remove initial .'s to turn a -mcall-aixdesc function | |
9984 | address into the address of the descriptor, not the function | |
9985 | itself. */ | |
9986 | else if (GET_CODE (x) == SYMBOL_REF | |
9987 | && XSTR (x, 0)[0] == '.' | |
9988 | && DEFAULT_ABI == ABI_AIX) | |
9989 | { | |
9990 | const char *name = XSTR (x, 0); | |
9991 | while (*name == '.') | |
9992 | name++; | |
9993 | ||
9994 | fprintf (asm_out_file, "\t.long\t%s\n", name); | |
9995 | return true; | |
9996 | } | |
9997 | } | |
9998 | #endif /* RELOCATABLE_NEEDS_FIXUP */ | |
9999 | return default_assemble_integer (x, size, aligned_p); | |
10000 | } | |
93638d7a AM |
10001 | |
10002 | #ifdef HAVE_GAS_HIDDEN | |
10003 | /* Emit an assembler directive to set symbol visibility for DECL to | |
10004 | VISIBILITY_TYPE. */ | |
10005 | ||
5add3202 | 10006 | static void |
a2369ed3 | 10007 | rs6000_assemble_visibility (tree decl, int vis) |
93638d7a | 10008 | { |
93638d7a AM |
10009 | /* Functions need to have their entry point symbol visibility set as |
10010 | well as their descriptor symbol visibility. */ | |
10011 | if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL) | |
10012 | { | |
25fdb4dc RH |
10013 | static const char * const visibility_types[] = { |
10014 | NULL, "internal", "hidden", "protected" | |
10015 | }; | |
10016 | ||
10017 | const char *name, *type; | |
93638d7a AM |
10018 | |
10019 | name = ((* targetm.strip_name_encoding) | |
10020 | (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)))); | |
25fdb4dc | 10021 | type = visibility_types[vis]; |
93638d7a | 10022 | |
25fdb4dc RH |
10023 | fprintf (asm_out_file, "\t.%s\t%s\n", type, name); |
10024 | fprintf (asm_out_file, "\t.%s\t.%s\n", type, name); | |
93638d7a | 10025 | } |
25fdb4dc RH |
10026 | else |
10027 | default_assemble_visibility (decl, vis); | |
93638d7a AM |
10028 | } |
10029 | #endif | |
301d03af | 10030 | \f |
39a10a29 | 10031 | enum rtx_code |
a2369ed3 | 10032 | rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code) |
39a10a29 GK |
10033 | { |
10034 | /* Reversal of FP compares takes care -- an ordered compare | |
10035 | becomes an unordered compare and vice versa. */ | |
bc9ec0e0 GK |
10036 | if (mode == CCFPmode |
10037 | && (!flag_finite_math_only | |
10038 | || code == UNLT || code == UNLE || code == UNGT || code == UNGE | |
10039 | || code == UNEQ || code == LTGT)) | |
bab6226b | 10040 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 10041 | else |
bab6226b | 10042 | return reverse_condition (code); |
39a10a29 GK |
10043 | } |
10044 | ||
39a10a29 GK |
10045 | /* Generate a compare for CODE. Return a brand-new rtx that |
10046 | represents the result of the compare. */ | |
a4f6c312 | 10047 | |
39a10a29 | 10048 | static rtx |
a2369ed3 | 10049 | rs6000_generate_compare (enum rtx_code code) |
39a10a29 GK |
10050 | { |
10051 | enum machine_mode comp_mode; | |
10052 | rtx compare_result; | |
10053 | ||
10054 | if (rs6000_compare_fp_p) | |
10055 | comp_mode = CCFPmode; | |
10056 | else if (code == GTU || code == LTU | |
10057 | || code == GEU || code == LEU) | |
10058 | comp_mode = CCUNSmode; | |
10059 | else | |
10060 | comp_mode = CCmode; | |
10061 | ||
10062 | /* First, the compare. */ | |
10063 | compare_result = gen_reg_rtx (comp_mode); | |
a3170dc6 AH |
10064 | |
10065 | /* SPE FP compare instructions on the GPRs. Yuck! */ | |
993f19a8 AH |
10066 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) |
10067 | && rs6000_compare_fp_p) | |
a3170dc6 AH |
10068 | { |
10069 | rtx cmp, or1, or2, or_result, compare_result2; | |
10070 | ||
423c1189 AH |
10071 | /* Note: The E500 comparison instructions set the GT bit (x + |
10072 | 1), on success. This explains the mess. */ | |
10073 | ||
a3170dc6 AH |
10074 | switch (code) |
10075 | { | |
423c1189 | 10076 | case EQ: case UNEQ: case NE: case LTGT: |
bc9ec0e0 | 10077 | cmp = flag_finite_math_only |
a3170dc6 AH |
10078 | ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0, |
10079 | rs6000_compare_op1) | |
10080 | : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0, | |
10081 | rs6000_compare_op1); | |
10082 | break; | |
423c1189 | 10083 | case GT: case GTU: case UNGT: case UNGE: case GE: case GEU: |
bc9ec0e0 | 10084 | cmp = flag_finite_math_only |
a3170dc6 AH |
10085 | ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0, |
10086 | rs6000_compare_op1) | |
10087 | : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0, | |
10088 | rs6000_compare_op1); | |
10089 | break; | |
423c1189 | 10090 | case LT: case LTU: case UNLT: case UNLE: case LE: case LEU: |
bc9ec0e0 | 10091 | cmp = flag_finite_math_only |
a3170dc6 AH |
10092 | ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0, |
10093 | rs6000_compare_op1) | |
10094 | : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0, | |
10095 | rs6000_compare_op1); | |
10096 | break; | |
10097 | default: | |
10098 | abort (); | |
10099 | } | |
10100 | ||
10101 | /* Synthesize LE and GE from LT/GT || EQ. */ | |
10102 | if (code == LE || code == GE || code == LEU || code == GEU) | |
10103 | { | |
a3170dc6 AH |
10104 | emit_insn (cmp); |
10105 | ||
10106 | switch (code) | |
10107 | { | |
10108 | case LE: code = LT; break; | |
10109 | case GE: code = GT; break; | |
10110 | case LEU: code = LT; break; | |
10111 | case GEU: code = GT; break; | |
10112 | default: abort (); | |
10113 | } | |
10114 | ||
10115 | or1 = gen_reg_rtx (SImode); | |
10116 | or2 = gen_reg_rtx (SImode); | |
10117 | or_result = gen_reg_rtx (CCEQmode); | |
10118 | compare_result2 = gen_reg_rtx (CCFPmode); | |
10119 | ||
10120 | /* Do the EQ. */ | |
bc9ec0e0 | 10121 | cmp = flag_finite_math_only |
a3170dc6 AH |
10122 | ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0, |
10123 | rs6000_compare_op1) | |
10124 | : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0, | |
10125 | rs6000_compare_op1); | |
10126 | emit_insn (cmp); | |
10127 | ||
423c1189 AH |
10128 | or1 = gen_rtx_GT (SImode, compare_result, const0_rtx); |
10129 | or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx); | |
a3170dc6 AH |
10130 | |
10131 | /* OR them together. */ | |
10132 | cmp = gen_rtx_SET (VOIDmode, or_result, | |
10133 | gen_rtx_COMPARE (CCEQmode, | |
10134 | gen_rtx_IOR (SImode, or1, or2), | |
10135 | const_true_rtx)); | |
10136 | compare_result = or_result; | |
10137 | code = EQ; | |
10138 | } | |
10139 | else | |
10140 | { | |
a3170dc6 | 10141 | if (code == NE || code == LTGT) |
a3170dc6 | 10142 | code = NE; |
423c1189 AH |
10143 | else |
10144 | code = EQ; | |
a3170dc6 AH |
10145 | } |
10146 | ||
10147 | emit_insn (cmp); | |
10148 | } | |
10149 | else | |
10150 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
10151 | gen_rtx_COMPARE (comp_mode, | |
10152 | rs6000_compare_op0, | |
10153 | rs6000_compare_op1))); | |
39a10a29 | 10154 | |
ca5adc63 | 10155 | /* Some kinds of FP comparisons need an OR operation; |
bc9ec0e0 | 10156 | under flag_finite_math_only we don't bother. */ |
39a10a29 | 10157 | if (rs6000_compare_fp_p |
bc9ec0e0 | 10158 | && ! flag_finite_math_only |
993f19a8 | 10159 | && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS) |
39a10a29 GK |
10160 | && (code == LE || code == GE |
10161 | || code == UNEQ || code == LTGT | |
10162 | || code == UNGT || code == UNLT)) | |
10163 | { | |
10164 | enum rtx_code or1, or2; | |
10165 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
10166 | rtx or_result = gen_reg_rtx (CCEQmode); | |
10167 | ||
10168 | switch (code) | |
10169 | { | |
10170 | case LE: or1 = LT; or2 = EQ; break; | |
10171 | case GE: or1 = GT; or2 = EQ; break; | |
10172 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
10173 | case LTGT: or1 = LT; or2 = GT; break; | |
10174 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
10175 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
10176 | default: abort (); | |
10177 | } | |
10178 | validate_condition_mode (or1, comp_mode); | |
10179 | validate_condition_mode (or2, comp_mode); | |
1c563bed KH |
10180 | or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx); |
10181 | or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx); | |
39a10a29 GK |
10182 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, |
10183 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
10184 | const_true_rtx); | |
10185 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
10186 | ||
10187 | compare_result = or_result; | |
10188 | code = EQ; | |
10189 | } | |
10190 | ||
10191 | validate_condition_mode (code, GET_MODE (compare_result)); | |
10192 | ||
1c563bed | 10193 | return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx); |
39a10a29 GK |
10194 | } |
10195 | ||
10196 | ||
10197 | /* Emit the RTL for an sCOND pattern. */ | |
10198 | ||
10199 | void | |
a2369ed3 | 10200 | rs6000_emit_sCOND (enum rtx_code code, rtx result) |
39a10a29 GK |
10201 | { |
10202 | rtx condition_rtx; | |
10203 | enum machine_mode op_mode; | |
b7053a3f | 10204 | enum rtx_code cond_code; |
39a10a29 GK |
10205 | |
10206 | condition_rtx = rs6000_generate_compare (code); | |
b7053a3f GK |
10207 | cond_code = GET_CODE (condition_rtx); |
10208 | ||
423c1189 AH |
10209 | if (TARGET_E500 && rs6000_compare_fp_p |
10210 | && !TARGET_FPRS && TARGET_HARD_FLOAT) | |
10211 | { | |
10212 | rtx t; | |
10213 | ||
10214 | PUT_MODE (condition_rtx, SImode); | |
10215 | t = XEXP (condition_rtx, 0); | |
10216 | ||
10217 | if (cond_code != NE && cond_code != EQ) | |
10218 | abort (); | |
10219 | ||
10220 | if (cond_code == NE) | |
10221 | emit_insn (gen_e500_flip_gt_bit (t, t)); | |
10222 | ||
10223 | emit_insn (gen_move_from_CR_gt_bit (result, t)); | |
10224 | return; | |
10225 | } | |
10226 | ||
b7053a3f GK |
10227 | if (cond_code == NE |
10228 | || cond_code == GE || cond_code == LE | |
10229 | || cond_code == GEU || cond_code == LEU | |
10230 | || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE) | |
10231 | { | |
10232 | rtx not_result = gen_reg_rtx (CCEQmode); | |
10233 | rtx not_op, rev_cond_rtx; | |
10234 | enum machine_mode cc_mode; | |
10235 | ||
10236 | cc_mode = GET_MODE (XEXP (condition_rtx, 0)); | |
10237 | ||
1c563bed | 10238 | rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code), |
0f4c242b | 10239 | SImode, XEXP (condition_rtx, 0), const0_rtx); |
b7053a3f GK |
10240 | not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx); |
10241 | emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op)); | |
10242 | condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx); | |
10243 | } | |
39a10a29 GK |
10244 | |
10245 | op_mode = GET_MODE (rs6000_compare_op0); | |
10246 | if (op_mode == VOIDmode) | |
10247 | op_mode = GET_MODE (rs6000_compare_op1); | |
10248 | ||
10249 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
10250 | { | |
10251 | PUT_MODE (condition_rtx, DImode); | |
10252 | convert_move (result, condition_rtx, 0); | |
10253 | } | |
10254 | else | |
10255 | { | |
10256 | PUT_MODE (condition_rtx, SImode); | |
10257 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
10258 | } | |
10259 | } | |
10260 | ||
39a10a29 GK |
10261 | /* Emit a branch of kind CODE to location LOC. */ |
10262 | ||
10263 | void | |
a2369ed3 | 10264 | rs6000_emit_cbranch (enum rtx_code code, rtx loc) |
39a10a29 GK |
10265 | { |
10266 | rtx condition_rtx, loc_ref; | |
10267 | ||
10268 | condition_rtx = rs6000_generate_compare (code); | |
10269 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
10270 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
10271 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
10272 | loc_ref, pc_rtx))); | |
10273 | } | |
10274 | ||
12a4e8c5 GK |
10275 | /* Return the string to output a conditional branch to LABEL, which is |
10276 | the operand number of the label, or -1 if the branch is really a | |
10277 | conditional return. | |
10278 | ||
10279 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
10280 | condition code register and its mode specifies what kind of | |
10281 | comparison we made. | |
10282 | ||
a0ab749a | 10283 | REVERSED is nonzero if we should reverse the sense of the comparison. |
12a4e8c5 GK |
10284 | |
10285 | INSN is the insn. */ | |
10286 | ||
10287 | char * | |
a2369ed3 | 10288 | output_cbranch (rtx op, const char *label, int reversed, rtx insn) |
12a4e8c5 GK |
10289 | { |
10290 | static char string[64]; | |
10291 | enum rtx_code code = GET_CODE (op); | |
10292 | rtx cc_reg = XEXP (op, 0); | |
10293 | enum machine_mode mode = GET_MODE (cc_reg); | |
10294 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 10295 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
10296 | int really_reversed = reversed ^ need_longbranch; |
10297 | char *s = string; | |
10298 | const char *ccode; | |
10299 | const char *pred; | |
10300 | rtx note; | |
10301 | ||
39a10a29 GK |
10302 | validate_condition_mode (code, mode); |
10303 | ||
10304 | /* Work out which way this really branches. We could use | |
10305 | reverse_condition_maybe_unordered here always but this | |
10306 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 10307 | if (really_reversed) |
de40e1df DJ |
10308 | { |
10309 | /* Reversal of FP compares takes care -- an ordered compare | |
10310 | becomes an unordered compare and vice versa. */ | |
10311 | if (mode == CCFPmode) | |
10312 | code = reverse_condition_maybe_unordered (code); | |
10313 | else | |
10314 | code = reverse_condition (code); | |
10315 | } | |
12a4e8c5 | 10316 | |
993f19a8 | 10317 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode) |
a3170dc6 AH |
10318 | { |
10319 | /* The efscmp/tst* instructions twiddle bit 2, which maps nicely | |
10320 | to the GT bit. */ | |
10321 | if (code == EQ) | |
10322 | /* Opposite of GT. */ | |
a3170dc6 | 10323 | code = GT; |
423c1189 AH |
10324 | else if (code == NE) |
10325 | code = UNLE; | |
a3170dc6 AH |
10326 | else |
10327 | abort (); | |
10328 | } | |
10329 | ||
39a10a29 | 10330 | switch (code) |
12a4e8c5 GK |
10331 | { |
10332 | /* Not all of these are actually distinct opcodes, but | |
10333 | we distinguish them for clarity of the resulting assembler. */ | |
50a0b056 GK |
10334 | case NE: case LTGT: |
10335 | ccode = "ne"; break; | |
10336 | case EQ: case UNEQ: | |
10337 | ccode = "eq"; break; | |
10338 | case GE: case GEU: | |
10339 | ccode = "ge"; break; | |
10340 | case GT: case GTU: case UNGT: | |
10341 | ccode = "gt"; break; | |
10342 | case LE: case LEU: | |
10343 | ccode = "le"; break; | |
10344 | case LT: case LTU: case UNLT: | |
10345 | ccode = "lt"; break; | |
12a4e8c5 GK |
10346 | case UNORDERED: ccode = "un"; break; |
10347 | case ORDERED: ccode = "nu"; break; | |
10348 | case UNGE: ccode = "nl"; break; | |
10349 | case UNLE: ccode = "ng"; break; | |
10350 | default: | |
a4f6c312 | 10351 | abort (); |
12a4e8c5 GK |
10352 | } |
10353 | ||
94a54f47 GK |
10354 | /* Maybe we have a guess as to how likely the branch is. |
10355 | The old mnemonics don't have a way to specify this information. */ | |
f4857b9b | 10356 | pred = ""; |
12a4e8c5 GK |
10357 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
10358 | if (note != NULL_RTX) | |
10359 | { | |
10360 | /* PROB is the difference from 50%. */ | |
10361 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
f4857b9b AM |
10362 | |
10363 | /* Only hint for highly probable/improbable branches on newer | |
10364 | cpus as static prediction overrides processor dynamic | |
10365 | prediction. For older cpus we may as well always hint, but | |
10366 | assume not taken for branches that are very close to 50% as a | |
10367 | mispredicted taken branch is more expensive than a | |
10368 | mispredicted not-taken branch. */ | |
ec507f2d | 10369 | if (rs6000_always_hint |
f4857b9b AM |
10370 | || abs (prob) > REG_BR_PROB_BASE / 100 * 48) |
10371 | { | |
10372 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
10373 | && ((prob > 0) ^ need_longbranch)) | |
7f3d8013 | 10374 | pred = "+"; |
f4857b9b AM |
10375 | else |
10376 | pred = "-"; | |
10377 | } | |
12a4e8c5 | 10378 | } |
12a4e8c5 GK |
10379 | |
10380 | if (label == NULL) | |
94a54f47 | 10381 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 10382 | else |
94a54f47 | 10383 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 10384 | |
37c67319 | 10385 | /* We need to escape any '%' characters in the reg_names string. |
a3c9585f | 10386 | Assume they'd only be the first character.... */ |
37c67319 GK |
10387 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') |
10388 | *s++ = '%'; | |
94a54f47 | 10389 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
10390 | |
10391 | if (label != NULL) | |
10392 | { | |
10393 | /* If the branch distance was too far, we may have to use an | |
10394 | unconditional branch to go the distance. */ | |
10395 | if (need_longbranch) | |
44518ddd | 10396 | s += sprintf (s, ",$+8\n\tb %s", label); |
12a4e8c5 GK |
10397 | else |
10398 | s += sprintf (s, ",%s", label); | |
10399 | } | |
10400 | ||
10401 | return string; | |
10402 | } | |
50a0b056 | 10403 | |
423c1189 AH |
10404 | /* Return the string to flip the GT bit on a CR. */ |
10405 | char * | |
10406 | output_e500_flip_gt_bit (rtx dst, rtx src) | |
10407 | { | |
10408 | static char string[64]; | |
10409 | int a, b; | |
10410 | ||
10411 | if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst)) | |
10412 | || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src))) | |
10413 | abort (); | |
10414 | ||
10415 | /* GT bit. */ | |
10416 | a = 4 * (REGNO (dst) - CR0_REGNO) + 1; | |
10417 | b = 4 * (REGNO (src) - CR0_REGNO) + 1; | |
10418 | ||
10419 | sprintf (string, "crnot %d,%d", a, b); | |
10420 | return string; | |
10421 | } | |
10422 | ||
50a0b056 GK |
10423 | /* Emit a conditional move: move TRUE_COND to DEST if OP of the |
10424 | operands of the last comparison is nonzero/true, FALSE_COND if it | |
10425 | is zero/false. Return 0 if the hardware has no such operation. */ | |
a4f6c312 | 10426 | |
50a0b056 | 10427 | int |
a2369ed3 | 10428 | rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
50a0b056 GK |
10429 | { |
10430 | enum rtx_code code = GET_CODE (op); | |
10431 | rtx op0 = rs6000_compare_op0; | |
10432 | rtx op1 = rs6000_compare_op1; | |
10433 | REAL_VALUE_TYPE c1; | |
3148ad6d DJ |
10434 | enum machine_mode compare_mode = GET_MODE (op0); |
10435 | enum machine_mode result_mode = GET_MODE (dest); | |
50a0b056 GK |
10436 | rtx temp; |
10437 | ||
a3c9585f | 10438 | /* These modes should always match. */ |
a3170dc6 AH |
10439 | if (GET_MODE (op1) != compare_mode |
10440 | /* In the isel case however, we can use a compare immediate, so | |
10441 | op1 may be a small constant. */ | |
10442 | && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode))) | |
3148ad6d | 10443 | return 0; |
178c3eff | 10444 | if (GET_MODE (true_cond) != result_mode) |
3148ad6d | 10445 | return 0; |
178c3eff | 10446 | if (GET_MODE (false_cond) != result_mode) |
3148ad6d DJ |
10447 | return 0; |
10448 | ||
50a0b056 | 10449 | /* First, work out if the hardware can do this at all, or |
a3c9585f | 10450 | if it's too slow.... */ |
50a0b056 | 10451 | if (! rs6000_compare_fp_p) |
a3170dc6 AH |
10452 | { |
10453 | if (TARGET_ISEL) | |
10454 | return rs6000_emit_int_cmove (dest, op, true_cond, false_cond); | |
10455 | return 0; | |
10456 | } | |
fef98bf2 AH |
10457 | else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS |
10458 | && GET_MODE_CLASS (compare_mode) == MODE_FLOAT) | |
10459 | return 0; | |
50a0b056 GK |
10460 | |
10461 | /* Eliminate half of the comparisons by switching operands, this | |
10462 | makes the remaining code simpler. */ | |
10463 | if (code == UNLT || code == UNGT || code == UNORDERED || code == NE | |
bc9ec0e0 | 10464 | || code == LTGT || code == LT || code == UNLE) |
50a0b056 GK |
10465 | { |
10466 | code = reverse_condition_maybe_unordered (code); | |
10467 | temp = true_cond; | |
10468 | true_cond = false_cond; | |
10469 | false_cond = temp; | |
10470 | } | |
10471 | ||
10472 | /* UNEQ and LTGT take four instructions for a comparison with zero, | |
10473 | it'll probably be faster to use a branch here too. */ | |
bc9ec0e0 | 10474 | if (code == UNEQ && HONOR_NANS (compare_mode)) |
50a0b056 GK |
10475 | return 0; |
10476 | ||
10477 | if (GET_CODE (op1) == CONST_DOUBLE) | |
10478 | REAL_VALUE_FROM_CONST_DOUBLE (c1, op1); | |
10479 | ||
b6d08ca1 | 10480 | /* We're going to try to implement comparisons by performing |
50a0b056 GK |
10481 | a subtract, then comparing against zero. Unfortunately, |
10482 | Inf - Inf is NaN which is not zero, and so if we don't | |
27d30956 | 10483 | know that the operand is finite and the comparison |
50a0b056 | 10484 | would treat EQ different to UNORDERED, we can't do it. */ |
bc9ec0e0 | 10485 | if (HONOR_INFINITIES (compare_mode) |
50a0b056 | 10486 | && code != GT && code != UNGE |
045572c7 | 10487 | && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1)) |
50a0b056 GK |
10488 | /* Constructs of the form (a OP b ? a : b) are safe. */ |
10489 | && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond)) | |
10490 | || (! rtx_equal_p (op0, true_cond) | |
10491 | && ! rtx_equal_p (op1, true_cond)))) | |
10492 | return 0; | |
10493 | /* At this point we know we can use fsel. */ | |
10494 | ||
10495 | /* Reduce the comparison to a comparison against zero. */ | |
3148ad6d | 10496 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 10497 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 10498 | gen_rtx_MINUS (compare_mode, op0, op1))); |
50a0b056 | 10499 | op0 = temp; |
3148ad6d | 10500 | op1 = CONST0_RTX (compare_mode); |
50a0b056 GK |
10501 | |
10502 | /* If we don't care about NaNs we can reduce some of the comparisons | |
10503 | down to faster ones. */ | |
bc9ec0e0 | 10504 | if (! HONOR_NANS (compare_mode)) |
50a0b056 GK |
10505 | switch (code) |
10506 | { | |
10507 | case GT: | |
10508 | code = LE; | |
10509 | temp = true_cond; | |
10510 | true_cond = false_cond; | |
10511 | false_cond = temp; | |
10512 | break; | |
10513 | case UNGE: | |
10514 | code = GE; | |
10515 | break; | |
10516 | case UNEQ: | |
10517 | code = EQ; | |
10518 | break; | |
10519 | default: | |
10520 | break; | |
10521 | } | |
10522 | ||
10523 | /* Now, reduce everything down to a GE. */ | |
10524 | switch (code) | |
10525 | { | |
10526 | case GE: | |
10527 | break; | |
10528 | ||
10529 | case LE: | |
3148ad6d DJ |
10530 | temp = gen_reg_rtx (compare_mode); |
10531 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
10532 | op0 = temp; |
10533 | break; | |
10534 | ||
10535 | case ORDERED: | |
3148ad6d DJ |
10536 | temp = gen_reg_rtx (compare_mode); |
10537 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0))); | |
50a0b056 GK |
10538 | op0 = temp; |
10539 | break; | |
10540 | ||
10541 | case EQ: | |
3148ad6d | 10542 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 10543 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d DJ |
10544 | gen_rtx_NEG (compare_mode, |
10545 | gen_rtx_ABS (compare_mode, op0)))); | |
50a0b056 GK |
10546 | op0 = temp; |
10547 | break; | |
10548 | ||
10549 | case UNGE: | |
bc9ec0e0 | 10550 | /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */ |
3148ad6d | 10551 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 10552 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 10553 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
10554 | gen_rtx_GE (VOIDmode, |
10555 | op0, op1), | |
10556 | true_cond, false_cond))); | |
bc9ec0e0 GK |
10557 | false_cond = true_cond; |
10558 | true_cond = temp; | |
50a0b056 | 10559 | |
3148ad6d DJ |
10560 | temp = gen_reg_rtx (compare_mode); |
10561 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
10562 | op0 = temp; |
10563 | break; | |
10564 | ||
10565 | case GT: | |
bc9ec0e0 | 10566 | /* a GT 0 <-> (a GE 0 && -a UNLT 0) */ |
3148ad6d | 10567 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 10568 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 10569 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
10570 | gen_rtx_GE (VOIDmode, |
10571 | op0, op1), | |
10572 | true_cond, false_cond))); | |
bc9ec0e0 GK |
10573 | true_cond = false_cond; |
10574 | false_cond = temp; | |
50a0b056 | 10575 | |
3148ad6d DJ |
10576 | temp = gen_reg_rtx (compare_mode); |
10577 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
10578 | op0 = temp; |
10579 | break; | |
10580 | ||
10581 | default: | |
10582 | abort (); | |
10583 | } | |
10584 | ||
10585 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3148ad6d | 10586 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
10587 | gen_rtx_GE (VOIDmode, |
10588 | op0, op1), | |
10589 | true_cond, false_cond))); | |
10590 | return 1; | |
10591 | } | |
10592 | ||
a3170dc6 AH |
10593 | /* Same as above, but for ints (isel). */ |
10594 | ||
10595 | static int | |
a2369ed3 | 10596 | rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
a3170dc6 AH |
10597 | { |
10598 | rtx condition_rtx, cr; | |
10599 | ||
10600 | /* All isel implementations thus far are 32-bits. */ | |
10601 | if (GET_MODE (rs6000_compare_op0) != SImode) | |
10602 | return 0; | |
10603 | ||
10604 | /* We still have to do the compare, because isel doesn't do a | |
10605 | compare, it just looks at the CRx bits set by a previous compare | |
10606 | instruction. */ | |
10607 | condition_rtx = rs6000_generate_compare (GET_CODE (op)); | |
10608 | cr = XEXP (condition_rtx, 0); | |
10609 | ||
10610 | if (GET_MODE (cr) == CCmode) | |
10611 | emit_insn (gen_isel_signed (dest, condition_rtx, | |
10612 | true_cond, false_cond, cr)); | |
10613 | else | |
10614 | emit_insn (gen_isel_unsigned (dest, condition_rtx, | |
10615 | true_cond, false_cond, cr)); | |
10616 | ||
10617 | return 1; | |
10618 | } | |
10619 | ||
10620 | const char * | |
a2369ed3 | 10621 | output_isel (rtx *operands) |
a3170dc6 AH |
10622 | { |
10623 | enum rtx_code code; | |
10624 | ||
10625 | code = GET_CODE (operands[1]); | |
10626 | if (code == GE || code == GEU || code == LE || code == LEU || code == NE) | |
10627 | { | |
10628 | PUT_CODE (operands[1], reverse_condition (code)); | |
10629 | return "isel %0,%3,%2,%j1"; | |
10630 | } | |
10631 | else | |
10632 | return "isel %0,%2,%3,%j1"; | |
10633 | } | |
10634 | ||
50a0b056 | 10635 | void |
a2369ed3 | 10636 | rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1) |
50a0b056 GK |
10637 | { |
10638 | enum machine_mode mode = GET_MODE (op0); | |
5dc8d536 | 10639 | enum rtx_code c; |
50a0b056 | 10640 | rtx target; |
5dc8d536 AH |
10641 | |
10642 | if (code == SMAX || code == SMIN) | |
10643 | c = GE; | |
10644 | else | |
10645 | c = GEU; | |
10646 | ||
50a0b056 | 10647 | if (code == SMAX || code == UMAX) |
5dc8d536 | 10648 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
10649 | op0, op1, mode, 0); |
10650 | else | |
5dc8d536 | 10651 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
10652 | op1, op0, mode, 0); |
10653 | if (target == NULL_RTX) | |
10654 | abort (); | |
10655 | if (target != dest) | |
10656 | emit_move_insn (dest, target); | |
10657 | } | |
46c07df8 | 10658 | |
a9baceb1 GK |
10659 | /* Emit instructions to move SRC to DST. Called by splitters for |
10660 | multi-register moves. It will emit at most one instruction for | |
10661 | each register that is accessed; that is, it won't emit li/lis pairs | |
10662 | (or equivalent for 64-bit code). One of SRC or DST must be a hard | |
10663 | register. */ | |
46c07df8 | 10664 | |
46c07df8 | 10665 | void |
a9baceb1 | 10666 | rs6000_split_multireg_move (rtx dst, rtx src) |
46c07df8 | 10667 | { |
a9baceb1 GK |
10668 | /* The register number of the first register being moved. */ |
10669 | int reg; | |
10670 | /* The mode that is to be moved. */ | |
10671 | enum machine_mode mode; | |
10672 | /* The mode that the move is being done in, and its size. */ | |
10673 | enum machine_mode reg_mode; | |
10674 | int reg_mode_size; | |
10675 | /* The number of registers that will be moved. */ | |
10676 | int nregs; | |
10677 | ||
10678 | reg = REG_P (dst) ? REGNO (dst) : REGNO (src); | |
10679 | mode = GET_MODE (dst); | |
10680 | nregs = HARD_REGNO_NREGS (reg, mode); | |
10681 | if (FP_REGNO_P (reg)) | |
10682 | reg_mode = DFmode; | |
10683 | else if (ALTIVEC_REGNO_P (reg)) | |
10684 | reg_mode = V16QImode; | |
10685 | else | |
10686 | reg_mode = word_mode; | |
10687 | reg_mode_size = GET_MODE_SIZE (reg_mode); | |
46c07df8 | 10688 | |
a9baceb1 GK |
10689 | if (reg_mode_size * nregs != GET_MODE_SIZE (mode)) |
10690 | abort (); | |
10691 | ||
10692 | if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst))) | |
10693 | { | |
10694 | /* Move register range backwards, if we might have destructive | |
10695 | overlap. */ | |
10696 | int i; | |
10697 | for (i = nregs - 1; i >= 0; i--) | |
10698 | emit_insn (gen_rtx_SET (VOIDmode, | |
10699 | simplify_gen_subreg (reg_mode, dst, mode, | |
10700 | i * reg_mode_size), | |
10701 | simplify_gen_subreg (reg_mode, src, mode, | |
10702 | i * reg_mode_size))); | |
10703 | } | |
46c07df8 HP |
10704 | else |
10705 | { | |
a9baceb1 GK |
10706 | int i; |
10707 | int j = -1; | |
10708 | bool used_update = false; | |
46c07df8 | 10709 | |
a9baceb1 | 10710 | if (GET_CODE (src) == MEM && INT_REGNO_P (reg)) |
46c07df8 HP |
10711 | { |
10712 | rtx breg; | |
3a1f863f | 10713 | |
a9baceb1 GK |
10714 | if (GET_CODE (XEXP (src, 0)) == PRE_INC |
10715 | || GET_CODE (XEXP (src, 0)) == PRE_DEC) | |
3a1f863f DE |
10716 | { |
10717 | rtx delta_rtx; | |
a9baceb1 GK |
10718 | breg = XEXP (XEXP (src, 0), 0); |
10719 | delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC | |
10720 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (src))) | |
10721 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))); | |
10722 | emit_insn (TARGET_32BIT | |
10723 | ? gen_addsi3 (breg, breg, delta_rtx) | |
10724 | : gen_adddi3 (breg, breg, delta_rtx)); | |
3a1f863f DE |
10725 | src = gen_rtx_MEM (mode, breg); |
10726 | } | |
10727 | ||
10728 | /* We have now address involving an base register only. | |
10729 | If we use one of the registers to address memory, | |
10730 | we have change that register last. */ | |
10731 | ||
10732 | breg = (GET_CODE (XEXP (src, 0)) == PLUS | |
10733 | ? XEXP (XEXP (src, 0), 0) | |
10734 | : XEXP (src, 0)); | |
10735 | ||
10736 | if (!REG_P (breg)) | |
10737 | abort(); | |
10738 | ||
10739 | if (REGNO (breg) >= REGNO (dst) | |
10740 | && REGNO (breg) < REGNO (dst) + nregs) | |
10741 | j = REGNO (breg) - REGNO (dst); | |
46c07df8 HP |
10742 | } |
10743 | ||
a9baceb1 | 10744 | if (GET_CODE (dst) == MEM && INT_REGNO_P (reg)) |
3a1f863f DE |
10745 | { |
10746 | rtx breg; | |
10747 | ||
a9baceb1 GK |
10748 | if (GET_CODE (XEXP (dst, 0)) == PRE_INC |
10749 | || GET_CODE (XEXP (dst, 0)) == PRE_DEC) | |
3a1f863f DE |
10750 | { |
10751 | rtx delta_rtx; | |
a9baceb1 GK |
10752 | breg = XEXP (XEXP (dst, 0), 0); |
10753 | delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC | |
10754 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst))) | |
10755 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))); | |
3a1f863f DE |
10756 | |
10757 | /* We have to update the breg before doing the store. | |
10758 | Use store with update, if available. */ | |
10759 | ||
10760 | if (TARGET_UPDATE) | |
10761 | { | |
a9baceb1 GK |
10762 | rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0); |
10763 | emit_insn (TARGET_32BIT | |
10764 | ? gen_movsi_update (breg, breg, delta_rtx, nsrc) | |
10765 | : gen_movdi_update (breg, breg, delta_rtx, nsrc)); | |
10766 | used_update = true; | |
3a1f863f DE |
10767 | } |
10768 | else | |
a9baceb1 GK |
10769 | emit_insn (TARGET_32BIT |
10770 | ? gen_addsi3 (breg, breg, delta_rtx) | |
10771 | : gen_adddi3 (breg, breg, delta_rtx)); | |
3a1f863f DE |
10772 | dst = gen_rtx_MEM (mode, breg); |
10773 | } | |
10774 | } | |
10775 | ||
46c07df8 | 10776 | for (i = 0; i < nregs; i++) |
3a1f863f DE |
10777 | { |
10778 | /* Calculate index to next subword. */ | |
10779 | ++j; | |
10780 | if (j == nregs) | |
10781 | j = 0; | |
46c07df8 | 10782 | |
a9baceb1 GK |
10783 | /* If compiler already emited move of first word by |
10784 | store with update, no need to do anything. */ | |
3a1f863f | 10785 | if (j == 0 && used_update) |
a9baceb1 GK |
10786 | continue; |
10787 | ||
10788 | emit_insn (gen_rtx_SET (VOIDmode, | |
10789 | simplify_gen_subreg (reg_mode, dst, mode, | |
10790 | j * reg_mode_size), | |
10791 | simplify_gen_subreg (reg_mode, src, mode, | |
10792 | j * reg_mode_size))); | |
3a1f863f | 10793 | } |
46c07df8 HP |
10794 | } |
10795 | } | |
10796 | ||
12a4e8c5 | 10797 | \f |
a4f6c312 SS |
10798 | /* This page contains routines that are used to determine what the |
10799 | function prologue and epilogue code will do and write them out. */ | |
9878760c | 10800 | |
a4f6c312 SS |
10801 | /* Return the first fixed-point register that is required to be |
10802 | saved. 32 if none. */ | |
9878760c RK |
10803 | |
10804 | int | |
863d938c | 10805 | first_reg_to_save (void) |
9878760c RK |
10806 | { |
10807 | int first_reg; | |
10808 | ||
10809 | /* Find lowest numbered live register. */ | |
10810 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
a38d360d GK |
10811 | if (regs_ever_live[first_reg] |
10812 | && (! call_used_regs[first_reg] | |
1db02437 | 10813 | || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 10814 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 10815 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))) |
9878760c RK |
10816 | break; |
10817 | ||
ee890fe2 | 10818 | #if TARGET_MACHO |
93638d7a AM |
10819 | if (flag_pic |
10820 | && current_function_uses_pic_offset_table | |
10821 | && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM) | |
1db02437 | 10822 | return RS6000_PIC_OFFSET_TABLE_REGNUM; |
ee890fe2 SS |
10823 | #endif |
10824 | ||
9878760c RK |
10825 | return first_reg; |
10826 | } | |
10827 | ||
10828 | /* Similar, for FP regs. */ | |
10829 | ||
10830 | int | |
863d938c | 10831 | first_fp_reg_to_save (void) |
9878760c RK |
10832 | { |
10833 | int first_reg; | |
10834 | ||
10835 | /* Find lowest numbered live register. */ | |
10836 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
10837 | if (regs_ever_live[first_reg]) | |
10838 | break; | |
10839 | ||
10840 | return first_reg; | |
10841 | } | |
00b960c7 AH |
10842 | |
10843 | /* Similar, for AltiVec regs. */ | |
10844 | ||
10845 | static int | |
863d938c | 10846 | first_altivec_reg_to_save (void) |
00b960c7 AH |
10847 | { |
10848 | int i; | |
10849 | ||
10850 | /* Stack frame remains as is unless we are in AltiVec ABI. */ | |
10851 | if (! TARGET_ALTIVEC_ABI) | |
10852 | return LAST_ALTIVEC_REGNO + 1; | |
10853 | ||
10854 | /* Find lowest numbered live register. */ | |
10855 | for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i) | |
10856 | if (regs_ever_live[i]) | |
10857 | break; | |
10858 | ||
10859 | return i; | |
10860 | } | |
10861 | ||
10862 | /* Return a 32-bit mask of the AltiVec registers we need to set in | |
10863 | VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in | |
10864 | the 32-bit word is 0. */ | |
10865 | ||
10866 | static unsigned int | |
863d938c | 10867 | compute_vrsave_mask (void) |
00b960c7 AH |
10868 | { |
10869 | unsigned int i, mask = 0; | |
10870 | ||
10871 | /* First, find out if we use _any_ altivec registers. */ | |
10872 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
10873 | if (regs_ever_live[i]) | |
10874 | mask |= ALTIVEC_REG_BIT (i); | |
10875 | ||
10876 | if (mask == 0) | |
10877 | return mask; | |
10878 | ||
00b960c7 AH |
10879 | /* Next, remove the argument registers from the set. These must |
10880 | be in the VRSAVE mask set by the caller, so we don't need to add | |
10881 | them in again. More importantly, the mask we compute here is | |
10882 | used to generate CLOBBERs in the set_vrsave insn, and we do not | |
10883 | wish the argument registers to die. */ | |
a6cf80f2 | 10884 | for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i) |
00b960c7 AH |
10885 | mask &= ~ALTIVEC_REG_BIT (i); |
10886 | ||
10887 | /* Similarly, remove the return value from the set. */ | |
10888 | { | |
10889 | bool yes = false; | |
10890 | diddle_return_value (is_altivec_return_reg, &yes); | |
10891 | if (yes) | |
10892 | mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN); | |
10893 | } | |
10894 | ||
10895 | return mask; | |
10896 | } | |
10897 | ||
10898 | static void | |
a2369ed3 | 10899 | is_altivec_return_reg (rtx reg, void *xyes) |
00b960c7 AH |
10900 | { |
10901 | bool *yes = (bool *) xyes; | |
10902 | if (REGNO (reg) == ALTIVEC_ARG_RETURN) | |
10903 | *yes = true; | |
10904 | } | |
10905 | ||
4697a36c MM |
10906 | \f |
10907 | /* Calculate the stack information for the current function. This is | |
10908 | complicated by having two separate calling sequences, the AIX calling | |
10909 | sequence and the V.4 calling sequence. | |
10910 | ||
592696dd | 10911 | AIX (and Darwin/Mac OS X) stack frames look like: |
a260abc9 | 10912 | 32-bit 64-bit |
4697a36c | 10913 | SP----> +---------------------------------------+ |
a260abc9 | 10914 | | back chain to caller | 0 0 |
4697a36c | 10915 | +---------------------------------------+ |
a260abc9 | 10916 | | saved CR | 4 8 (8-11) |
4697a36c | 10917 | +---------------------------------------+ |
a260abc9 | 10918 | | saved LR | 8 16 |
4697a36c | 10919 | +---------------------------------------+ |
a260abc9 | 10920 | | reserved for compilers | 12 24 |
4697a36c | 10921 | +---------------------------------------+ |
a260abc9 | 10922 | | reserved for binders | 16 32 |
4697a36c | 10923 | +---------------------------------------+ |
a260abc9 | 10924 | | saved TOC pointer | 20 40 |
4697a36c | 10925 | +---------------------------------------+ |
a260abc9 | 10926 | | Parameter save area (P) | 24 48 |
4697a36c | 10927 | +---------------------------------------+ |
a260abc9 | 10928 | | Alloca space (A) | 24+P etc. |
802a0058 | 10929 | +---------------------------------------+ |
a7df97e6 | 10930 | | Local variable space (L) | 24+P+A |
4697a36c | 10931 | +---------------------------------------+ |
a7df97e6 | 10932 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 10933 | +---------------------------------------+ |
00b960c7 AH |
10934 | | Save area for AltiVec registers (W) | 24+P+A+L+X |
10935 | +---------------------------------------+ | |
10936 | | AltiVec alignment padding (Y) | 24+P+A+L+X+W | |
10937 | +---------------------------------------+ | |
10938 | | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y | |
4697a36c | 10939 | +---------------------------------------+ |
00b960c7 AH |
10940 | | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z |
10941 | +---------------------------------------+ | |
10942 | | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G | |
4697a36c MM |
10943 | +---------------------------------------+ |
10944 | old SP->| back chain to caller's caller | | |
10945 | +---------------------------------------+ | |
10946 | ||
5376a30c KR |
10947 | The required alignment for AIX configurations is two words (i.e., 8 |
10948 | or 16 bytes). | |
10949 | ||
10950 | ||
4697a36c MM |
10951 | V.4 stack frames look like: |
10952 | ||
10953 | SP----> +---------------------------------------+ | |
10954 | | back chain to caller | 0 | |
10955 | +---------------------------------------+ | |
5eb387b8 | 10956 | | caller's saved LR | 4 |
4697a36c MM |
10957 | +---------------------------------------+ |
10958 | | Parameter save area (P) | 8 | |
10959 | +---------------------------------------+ | |
a7df97e6 MM |
10960 | | Alloca space (A) | 8+P |
10961 | +---------------------------------------+ | |
10962 | | Varargs save area (V) | 8+P+A | |
10963 | +---------------------------------------+ | |
10964 | | Local variable space (L) | 8+P+A+V | |
10965 | +---------------------------------------+ | |
10966 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 10967 | +---------------------------------------+ |
00b960c7 AH |
10968 | | Save area for AltiVec registers (W) | 8+P+A+V+L+X |
10969 | +---------------------------------------+ | |
10970 | | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W | |
10971 | +---------------------------------------+ | |
10972 | | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y | |
10973 | +---------------------------------------+ | |
a3170dc6 AH |
10974 | | SPE: area for 64-bit GP registers | |
10975 | +---------------------------------------+ | |
10976 | | SPE alignment padding | | |
10977 | +---------------------------------------+ | |
00b960c7 | 10978 | | saved CR (C) | 8+P+A+V+L+X+W+Y+Z |
a7df97e6 | 10979 | +---------------------------------------+ |
00b960c7 | 10980 | | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C |
a7df97e6 | 10981 | +---------------------------------------+ |
00b960c7 | 10982 | | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G |
4697a36c MM |
10983 | +---------------------------------------+ |
10984 | old SP->| back chain to caller's caller | | |
10985 | +---------------------------------------+ | |
b6c9286a | 10986 | |
5376a30c KR |
10987 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
10988 | given. (But note below and in sysv4.h that we require only 8 and | |
10989 | may round up the size of our stack frame anyways. The historical | |
10990 | reason is early versions of powerpc-linux which didn't properly | |
10991 | align the stack at program startup. A happy side-effect is that | |
10992 | -mno-eabi libraries can be used with -meabi programs.) | |
10993 | ||
50d440bc | 10994 | The EABI configuration defaults to the V.4 layout. However, |
5376a30c KR |
10995 | the stack alignment requirements may differ. If -mno-eabi is not |
10996 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
10997 | given, the required alignment is 16 bytes. (But see V.4 comment | |
10998 | above.) */ | |
4697a36c | 10999 | |
61b2fbe7 MM |
11000 | #ifndef ABI_STACK_BOUNDARY |
11001 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
11002 | #endif | |
11003 | ||
d1d0c603 | 11004 | static rs6000_stack_t * |
863d938c | 11005 | rs6000_stack_info (void) |
4697a36c MM |
11006 | { |
11007 | static rs6000_stack_t info, zero_info; | |
11008 | rs6000_stack_t *info_ptr = &info; | |
327e5343 | 11009 | int reg_size = TARGET_32BIT ? 4 : 8; |
83720594 | 11010 | int ehrd_size; |
44688022 | 11011 | HOST_WIDE_INT non_fixed_size; |
4697a36c | 11012 | |
a4f6c312 | 11013 | /* Zero all fields portably. */ |
4697a36c MM |
11014 | info = zero_info; |
11015 | ||
c19de7aa AH |
11016 | if (TARGET_SPE) |
11017 | { | |
11018 | /* Cache value so we don't rescan instruction chain over and over. */ | |
9b7b447f AH |
11019 | if (cfun->machine->insn_chain_scanned_p == 0) |
11020 | { | |
11021 | cfun->machine->insn_chain_scanned_p = 1; | |
11022 | info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p (); | |
11023 | } | |
c19de7aa AH |
11024 | } |
11025 | ||
a4f6c312 | 11026 | /* Select which calling sequence. */ |
178274da | 11027 | info_ptr->abi = DEFAULT_ABI; |
9878760c | 11028 | |
a4f6c312 | 11029 | /* Calculate which registers need to be saved & save area size. */ |
4697a36c | 11030 | info_ptr->first_gp_reg_save = first_reg_to_save (); |
1db02437 | 11031 | /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM, |
906fb125 | 11032 | even if it currently looks like we won't. */ |
2bfcf297 | 11033 | if (((TARGET_TOC && TARGET_MINIMAL_TOC) |
178274da AM |
11034 | || (flag_pic == 1 && DEFAULT_ABI == ABI_V4) |
11035 | || (flag_pic && DEFAULT_ABI == ABI_DARWIN)) | |
1db02437 FS |
11036 | && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM) |
11037 | info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM); | |
906fb125 GK |
11038 | else |
11039 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c | 11040 | |
a3170dc6 AH |
11041 | /* For the SPE, we have an additional upper 32-bits on each GPR. |
11042 | Ideally we should save the entire 64-bits only when the upper | |
11043 | half is used in SIMD instructions. Since we only record | |
11044 | registers live (not the size they are used in), this proves | |
11045 | difficult because we'd have to traverse the instruction chain at | |
11046 | the right time, taking reload into account. This is a real pain, | |
c19de7aa AH |
11047 | so we opt to save the GPRs in 64-bits always if but one register |
11048 | gets used in 64-bits. Otherwise, all the registers in the frame | |
11049 | get saved in 32-bits. | |
a3170dc6 | 11050 | |
c19de7aa | 11051 | So... since when we save all GPRs (except the SP) in 64-bits, the |
a3170dc6 | 11052 | traditional GP save area will be empty. */ |
c19de7aa | 11053 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11054 | info_ptr->gp_size = 0; |
11055 | ||
4697a36c MM |
11056 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); |
11057 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
11058 | ||
00b960c7 AH |
11059 | info_ptr->first_altivec_reg_save = first_altivec_reg_to_save (); |
11060 | info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1 | |
11061 | - info_ptr->first_altivec_reg_save); | |
11062 | ||
592696dd | 11063 | /* Does this function call anything? */ |
71f123ca FS |
11064 | info_ptr->calls_p = (! current_function_is_leaf |
11065 | || cfun->machine->ra_needs_full_frame); | |
b6c9286a | 11066 | |
a4f6c312 | 11067 | /* Determine if we need to save the link register. */ |
71f123ca | 11068 | if (rs6000_ra_ever_killed () |
ffcfcb5f AM |
11069 | || (DEFAULT_ABI == ABI_AIX |
11070 | && current_function_profile | |
11071 | && !TARGET_PROFILE_KERNEL) | |
4697a36c MM |
11072 | #ifdef TARGET_RELOCATABLE |
11073 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
11074 | #endif | |
11075 | || (info_ptr->first_fp_reg_save != 64 | |
11076 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
00b960c7 | 11077 | || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO |
178274da | 11078 | || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca) |
a4f6c312 SS |
11079 | || (DEFAULT_ABI == ABI_DARWIN |
11080 | && flag_pic | |
11081 | && current_function_uses_pic_offset_table) | |
4697a36c MM |
11082 | || info_ptr->calls_p) |
11083 | { | |
11084 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 11085 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
11086 | } |
11087 | ||
9ebbca7d GK |
11088 | /* Determine if we need to save the condition code registers. */ |
11089 | if (regs_ever_live[CR2_REGNO] | |
11090 | || regs_ever_live[CR3_REGNO] | |
11091 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
11092 | { |
11093 | info_ptr->cr_save_p = 1; | |
178274da | 11094 | if (DEFAULT_ABI == ABI_V4) |
4697a36c MM |
11095 | info_ptr->cr_size = reg_size; |
11096 | } | |
11097 | ||
83720594 RH |
11098 | /* If the current function calls __builtin_eh_return, then we need |
11099 | to allocate stack space for registers that will hold data for | |
11100 | the exception handler. */ | |
11101 | if (current_function_calls_eh_return) | |
11102 | { | |
11103 | unsigned int i; | |
11104 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i) | |
11105 | continue; | |
a3170dc6 AH |
11106 | |
11107 | /* SPE saves EH registers in 64-bits. */ | |
c19de7aa AH |
11108 | ehrd_size = i * (TARGET_SPE_ABI |
11109 | && info_ptr->spe_64bit_regs_used != 0 | |
11110 | ? UNITS_PER_SPE_WORD : UNITS_PER_WORD); | |
83720594 RH |
11111 | } |
11112 | else | |
11113 | ehrd_size = 0; | |
11114 | ||
592696dd | 11115 | /* Determine various sizes. */ |
4697a36c MM |
11116 | info_ptr->reg_size = reg_size; |
11117 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
11118 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 | 11119 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
a4f6c312 | 11120 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, |
03e007d7 | 11121 | TARGET_ALTIVEC ? 16 : 8); |
00b960c7 | 11122 | |
c19de7aa | 11123 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11124 | info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save); |
11125 | else | |
11126 | info_ptr->spe_gp_size = 0; | |
11127 | ||
4d774ff8 HP |
11128 | if (TARGET_ALTIVEC_ABI) |
11129 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
00b960c7 | 11130 | else |
4d774ff8 HP |
11131 | info_ptr->vrsave_mask = 0; |
11132 | ||
11133 | if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask) | |
11134 | info_ptr->vrsave_size = 4; | |
11135 | else | |
11136 | info_ptr->vrsave_size = 0; | |
b6c9286a | 11137 | |
592696dd | 11138 | /* Calculate the offsets. */ |
178274da | 11139 | switch (DEFAULT_ABI) |
4697a36c | 11140 | { |
b6c9286a | 11141 | case ABI_NONE: |
24d304eb | 11142 | default: |
b6c9286a MM |
11143 | abort (); |
11144 | ||
11145 | case ABI_AIX: | |
ee890fe2 | 11146 | case ABI_DARWIN: |
b6c9286a MM |
11147 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
11148 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
00b960c7 AH |
11149 | |
11150 | if (TARGET_ALTIVEC_ABI) | |
11151 | { | |
11152 | info_ptr->vrsave_save_offset | |
11153 | = info_ptr->gp_save_offset - info_ptr->vrsave_size; | |
11154 | ||
11155 | /* Align stack so vector save area is on a quadword boundary. */ | |
11156 | if (info_ptr->altivec_size != 0) | |
11157 | info_ptr->altivec_padding_size | |
11158 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
11159 | else | |
11160 | info_ptr->altivec_padding_size = 0; | |
11161 | ||
11162 | info_ptr->altivec_save_offset | |
11163 | = info_ptr->vrsave_save_offset | |
11164 | - info_ptr->altivec_padding_size | |
11165 | - info_ptr->altivec_size; | |
11166 | ||
11167 | /* Adjust for AltiVec case. */ | |
11168 | info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size; | |
11169 | } | |
11170 | else | |
11171 | info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size; | |
a260abc9 DE |
11172 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
11173 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
11174 | break; |
11175 | ||
11176 | case ABI_V4: | |
b6c9286a MM |
11177 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
11178 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 | 11179 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
00b960c7 | 11180 | |
c19de7aa | 11181 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11182 | { |
11183 | /* Align stack so SPE GPR save area is aligned on a | |
11184 | double-word boundary. */ | |
11185 | if (info_ptr->spe_gp_size != 0) | |
11186 | info_ptr->spe_padding_size | |
11187 | = 8 - (-info_ptr->cr_save_offset % 8); | |
11188 | else | |
11189 | info_ptr->spe_padding_size = 0; | |
11190 | ||
11191 | info_ptr->spe_gp_save_offset | |
11192 | = info_ptr->cr_save_offset | |
11193 | - info_ptr->spe_padding_size | |
11194 | - info_ptr->spe_gp_size; | |
11195 | ||
11196 | /* Adjust for SPE case. */ | |
11197 | info_ptr->toc_save_offset | |
11198 | = info_ptr->spe_gp_save_offset - info_ptr->toc_size; | |
11199 | } | |
11200 | else if (TARGET_ALTIVEC_ABI) | |
00b960c7 AH |
11201 | { |
11202 | info_ptr->vrsave_save_offset | |
11203 | = info_ptr->cr_save_offset - info_ptr->vrsave_size; | |
11204 | ||
11205 | /* Align stack so vector save area is on a quadword boundary. */ | |
11206 | if (info_ptr->altivec_size != 0) | |
11207 | info_ptr->altivec_padding_size | |
11208 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
11209 | else | |
11210 | info_ptr->altivec_padding_size = 0; | |
11211 | ||
11212 | info_ptr->altivec_save_offset | |
11213 | = info_ptr->vrsave_save_offset | |
11214 | - info_ptr->altivec_padding_size | |
11215 | - info_ptr->altivec_size; | |
11216 | ||
11217 | /* Adjust for AltiVec case. */ | |
11218 | info_ptr->toc_save_offset | |
11219 | = info_ptr->altivec_save_offset - info_ptr->toc_size; | |
11220 | } | |
11221 | else | |
11222 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
83720594 | 11223 | info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size; |
b6c9286a MM |
11224 | info_ptr->lr_save_offset = reg_size; |
11225 | break; | |
4697a36c MM |
11226 | } |
11227 | ||
00b960c7 AH |
11228 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
11229 | + info_ptr->gp_size | |
11230 | + info_ptr->altivec_size | |
11231 | + info_ptr->altivec_padding_size | |
a3170dc6 AH |
11232 | + info_ptr->spe_gp_size |
11233 | + info_ptr->spe_padding_size | |
00b960c7 AH |
11234 | + ehrd_size |
11235 | + info_ptr->cr_size | |
11236 | + info_ptr->lr_size | |
11237 | + info_ptr->vrsave_size | |
11238 | + info_ptr->toc_size, | |
11239 | (TARGET_ALTIVEC_ABI || ABI_DARWIN) | |
11240 | ? 16 : 8); | |
11241 | ||
44688022 | 11242 | non_fixed_size = (info_ptr->vars_size |
ff381587 | 11243 | + info_ptr->parm_size |
ff381587 | 11244 | + info_ptr->save_size |
44688022 | 11245 | + info_ptr->varargs_size); |
ff381587 | 11246 | |
44688022 AM |
11247 | info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size, |
11248 | ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
ff381587 MM |
11249 | |
11250 | /* Determine if we need to allocate any stack frame: | |
11251 | ||
a4f6c312 SS |
11252 | For AIX we need to push the stack if a frame pointer is needed |
11253 | (because the stack might be dynamically adjusted), if we are | |
11254 | debugging, if we make calls, or if the sum of fp_save, gp_save, | |
11255 | and local variables are more than the space needed to save all | |
11256 | non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 | |
11257 | + 18*8 = 288 (GPR13 reserved). | |
ff381587 | 11258 | |
a4f6c312 SS |
11259 | For V.4 we don't have the stack cushion that AIX uses, but assume |
11260 | that the debugger can handle stackless frames. */ | |
ff381587 MM |
11261 | |
11262 | if (info_ptr->calls_p) | |
11263 | info_ptr->push_p = 1; | |
11264 | ||
178274da | 11265 | else if (DEFAULT_ABI == ABI_V4) |
44688022 | 11266 | info_ptr->push_p = non_fixed_size != 0; |
ff381587 | 11267 | |
178274da AM |
11268 | else if (frame_pointer_needed) |
11269 | info_ptr->push_p = 1; | |
11270 | ||
11271 | else if (TARGET_XCOFF && write_symbols != NO_DEBUG) | |
11272 | info_ptr->push_p = 1; | |
11273 | ||
ff381587 | 11274 | else |
44688022 | 11275 | info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288); |
ff381587 | 11276 | |
a4f6c312 | 11277 | /* Zero offsets if we're not saving those registers. */ |
8dda1a21 | 11278 | if (info_ptr->fp_size == 0) |
4697a36c MM |
11279 | info_ptr->fp_save_offset = 0; |
11280 | ||
8dda1a21 | 11281 | if (info_ptr->gp_size == 0) |
4697a36c MM |
11282 | info_ptr->gp_save_offset = 0; |
11283 | ||
00b960c7 AH |
11284 | if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0) |
11285 | info_ptr->altivec_save_offset = 0; | |
11286 | ||
11287 | if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0) | |
11288 | info_ptr->vrsave_save_offset = 0; | |
11289 | ||
c19de7aa AH |
11290 | if (! TARGET_SPE_ABI |
11291 | || info_ptr->spe_64bit_regs_used == 0 | |
11292 | || info_ptr->spe_gp_size == 0) | |
a3170dc6 AH |
11293 | info_ptr->spe_gp_save_offset = 0; |
11294 | ||
c81fc13e | 11295 | if (! info_ptr->lr_save_p) |
4697a36c MM |
11296 | info_ptr->lr_save_offset = 0; |
11297 | ||
c81fc13e | 11298 | if (! info_ptr->cr_save_p) |
4697a36c MM |
11299 | info_ptr->cr_save_offset = 0; |
11300 | ||
c81fc13e | 11301 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
11302 | info_ptr->toc_save_offset = 0; |
11303 | ||
4697a36c MM |
11304 | return info_ptr; |
11305 | } | |
11306 | ||
c19de7aa AH |
11307 | /* Return true if the current function uses any GPRs in 64-bit SIMD |
11308 | mode. */ | |
11309 | ||
11310 | static bool | |
863d938c | 11311 | spe_func_has_64bit_regs_p (void) |
c19de7aa AH |
11312 | { |
11313 | rtx insns, insn; | |
11314 | ||
11315 | /* Functions that save and restore all the call-saved registers will | |
11316 | need to save/restore the registers in 64-bits. */ | |
11317 | if (current_function_calls_eh_return | |
11318 | || current_function_calls_setjmp | |
11319 | || current_function_has_nonlocal_goto) | |
11320 | return true; | |
11321 | ||
11322 | insns = get_insns (); | |
11323 | ||
11324 | for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn)) | |
11325 | { | |
11326 | if (INSN_P (insn)) | |
11327 | { | |
11328 | rtx i; | |
11329 | ||
11330 | i = PATTERN (insn); | |
11331 | if (GET_CODE (i) == SET | |
11332 | && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i)))) | |
11333 | return true; | |
11334 | } | |
11335 | } | |
11336 | ||
11337 | return false; | |
11338 | } | |
11339 | ||
d1d0c603 | 11340 | static void |
a2369ed3 | 11341 | debug_stack_info (rs6000_stack_t *info) |
9878760c | 11342 | { |
d330fd93 | 11343 | const char *abi_string; |
24d304eb | 11344 | |
c81fc13e | 11345 | if (! info) |
4697a36c MM |
11346 | info = rs6000_stack_info (); |
11347 | ||
11348 | fprintf (stderr, "\nStack information for function %s:\n", | |
11349 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
11350 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
11351 | : "<unknown>")); | |
11352 | ||
24d304eb RK |
11353 | switch (info->abi) |
11354 | { | |
b6c9286a MM |
11355 | default: abi_string = "Unknown"; break; |
11356 | case ABI_NONE: abi_string = "NONE"; break; | |
50d440bc | 11357 | case ABI_AIX: abi_string = "AIX"; break; |
ee890fe2 | 11358 | case ABI_DARWIN: abi_string = "Darwin"; break; |
b6c9286a | 11359 | case ABI_V4: abi_string = "V.4"; break; |
24d304eb RK |
11360 | } |
11361 | ||
11362 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
11363 | ||
00b960c7 AH |
11364 | if (TARGET_ALTIVEC_ABI) |
11365 | fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n"); | |
11366 | ||
a3170dc6 AH |
11367 | if (TARGET_SPE_ABI) |
11368 | fprintf (stderr, "\tSPE ABI extensions enabled.\n"); | |
11369 | ||
4697a36c MM |
11370 | if (info->first_gp_reg_save != 32) |
11371 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
11372 | ||
11373 | if (info->first_fp_reg_save != 64) | |
11374 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 11375 | |
00b960c7 AH |
11376 | if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO) |
11377 | fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n", | |
11378 | info->first_altivec_reg_save); | |
11379 | ||
4697a36c MM |
11380 | if (info->lr_save_p) |
11381 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 11382 | |
4697a36c MM |
11383 | if (info->cr_save_p) |
11384 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
11385 | ||
b6c9286a MM |
11386 | if (info->toc_save_p) |
11387 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
11388 | ||
00b960c7 AH |
11389 | if (info->vrsave_mask) |
11390 | fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask); | |
11391 | ||
4697a36c MM |
11392 | if (info->push_p) |
11393 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
11394 | ||
11395 | if (info->calls_p) | |
11396 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
11397 | ||
4697a36c MM |
11398 | if (info->gp_save_offset) |
11399 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
11400 | ||
11401 | if (info->fp_save_offset) | |
11402 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
11403 | ||
00b960c7 AH |
11404 | if (info->altivec_save_offset) |
11405 | fprintf (stderr, "\taltivec_save_offset = %5d\n", | |
11406 | info->altivec_save_offset); | |
11407 | ||
a3170dc6 AH |
11408 | if (info->spe_gp_save_offset) |
11409 | fprintf (stderr, "\tspe_gp_save_offset = %5d\n", | |
11410 | info->spe_gp_save_offset); | |
11411 | ||
00b960c7 AH |
11412 | if (info->vrsave_save_offset) |
11413 | fprintf (stderr, "\tvrsave_save_offset = %5d\n", | |
11414 | info->vrsave_save_offset); | |
11415 | ||
4697a36c MM |
11416 | if (info->lr_save_offset) |
11417 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
11418 | ||
11419 | if (info->cr_save_offset) | |
11420 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
11421 | ||
b6c9286a MM |
11422 | if (info->toc_save_offset) |
11423 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
11424 | ||
4697a36c MM |
11425 | if (info->varargs_save_offset) |
11426 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
11427 | ||
11428 | if (info->total_size) | |
d1d0c603 JJ |
11429 | fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
11430 | info->total_size); | |
4697a36c MM |
11431 | |
11432 | if (info->varargs_size) | |
11433 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
11434 | ||
11435 | if (info->vars_size) | |
d1d0c603 JJ |
11436 | fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
11437 | info->vars_size); | |
4697a36c MM |
11438 | |
11439 | if (info->parm_size) | |
11440 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
11441 | ||
11442 | if (info->fixed_size) | |
11443 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
11444 | ||
11445 | if (info->gp_size) | |
11446 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
11447 | ||
a3170dc6 AH |
11448 | if (info->spe_gp_size) |
11449 | fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size); | |
11450 | ||
4697a36c MM |
11451 | if (info->fp_size) |
11452 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
11453 | ||
00b960c7 AH |
11454 | if (info->altivec_size) |
11455 | fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size); | |
11456 | ||
11457 | if (info->vrsave_size) | |
11458 | fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size); | |
11459 | ||
11460 | if (info->altivec_padding_size) | |
11461 | fprintf (stderr, "\taltivec_padding_size= %5d\n", | |
11462 | info->altivec_padding_size); | |
11463 | ||
a3170dc6 AH |
11464 | if (info->spe_padding_size) |
11465 | fprintf (stderr, "\tspe_padding_size = %5d\n", | |
11466 | info->spe_padding_size); | |
11467 | ||
a4f6c312 | 11468 | if (info->lr_size) |
ed947a96 | 11469 | fprintf (stderr, "\tlr_size = %5d\n", info->lr_size); |
b6c9286a | 11470 | |
4697a36c MM |
11471 | if (info->cr_size) |
11472 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
11473 | ||
a4f6c312 | 11474 | if (info->toc_size) |
b6c9286a MM |
11475 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); |
11476 | ||
4697a36c MM |
11477 | if (info->save_size) |
11478 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
11479 | ||
11480 | if (info->reg_size != 4) | |
11481 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
11482 | ||
11483 | fprintf (stderr, "\n"); | |
9878760c | 11484 | } |
71f123ca FS |
11485 | |
11486 | rtx | |
a2369ed3 | 11487 | rs6000_return_addr (int count, rtx frame) |
71f123ca | 11488 | { |
a4f6c312 SS |
11489 | /* Currently we don't optimize very well between prolog and body |
11490 | code and for PIC code the code can be actually quite bad, so | |
11491 | don't try to be too clever here. */ | |
f1384257 | 11492 | if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic)) |
71f123ca FS |
11493 | { |
11494 | cfun->machine->ra_needs_full_frame = 1; | |
8ac61af7 RK |
11495 | |
11496 | return | |
11497 | gen_rtx_MEM | |
11498 | (Pmode, | |
11499 | memory_address | |
11500 | (Pmode, | |
11501 | plus_constant (copy_to_reg | |
11502 | (gen_rtx_MEM (Pmode, | |
11503 | memory_address (Pmode, frame))), | |
11504 | RETURN_ADDRESS_OFFSET))); | |
71f123ca FS |
11505 | } |
11506 | ||
8c29550d | 11507 | cfun->machine->ra_need_lr = 1; |
9e2f7ec7 | 11508 | return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM); |
71f123ca FS |
11509 | } |
11510 | ||
5e1bf043 DJ |
11511 | /* Say whether a function is a candidate for sibcall handling or not. |
11512 | We do not allow indirect calls to be optimized into sibling calls. | |
11513 | Also, we can't do it if there are any vector parameters; there's | |
11514 | nowhere to put the VRsave code so it works; note that functions with | |
11515 | vector parameters are required to have a prototype, so the argument | |
11516 | type info must be available here. (The tail recursion case can work | |
11517 | with vector parameters, but there's no way to distinguish here.) */ | |
4977bab6 | 11518 | static bool |
a2369ed3 | 11519 | rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) |
5e1bf043 DJ |
11520 | { |
11521 | tree type; | |
4977bab6 | 11522 | if (decl) |
5e1bf043 DJ |
11523 | { |
11524 | if (TARGET_ALTIVEC_VRSAVE) | |
11525 | { | |
4977bab6 | 11526 | for (type = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
5e1bf043 DJ |
11527 | type; type = TREE_CHAIN (type)) |
11528 | { | |
c15b529f | 11529 | if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE) |
4977bab6 | 11530 | return false; |
5e1bf043 DJ |
11531 | } |
11532 | } | |
11533 | if (DEFAULT_ABI == ABI_DARWIN | |
4977bab6 | 11534 | || (*targetm.binds_local_p) (decl)) |
2bcc50d0 | 11535 | { |
4977bab6 | 11536 | tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
2bcc50d0 AM |
11537 | |
11538 | if (!lookup_attribute ("longcall", attr_list) | |
11539 | || lookup_attribute ("shortcall", attr_list)) | |
4977bab6 | 11540 | return true; |
2bcc50d0 | 11541 | } |
5e1bf043 | 11542 | } |
4977bab6 | 11543 | return false; |
5e1bf043 DJ |
11544 | } |
11545 | ||
71f123ca | 11546 | static int |
863d938c | 11547 | rs6000_ra_ever_killed (void) |
71f123ca FS |
11548 | { |
11549 | rtx top; | |
5e1bf043 DJ |
11550 | rtx reg; |
11551 | rtx insn; | |
71f123ca | 11552 | |
dd292d0a | 11553 | if (current_function_is_thunk) |
71f123ca | 11554 | return 0; |
eb0424da | 11555 | |
36f7e964 AH |
11556 | /* regs_ever_live has LR marked as used if any sibcalls are present, |
11557 | but this should not force saving and restoring in the | |
11558 | pro/epilogue. Likewise, reg_set_between_p thinks a sibcall | |
a3c9585f | 11559 | clobbers LR, so that is inappropriate. */ |
36f7e964 | 11560 | |
5e1bf043 DJ |
11561 | /* Also, the prologue can generate a store into LR that |
11562 | doesn't really count, like this: | |
36f7e964 | 11563 | |
5e1bf043 DJ |
11564 | move LR->R0 |
11565 | bcl to set PIC register | |
11566 | move LR->R31 | |
11567 | move R0->LR | |
36f7e964 AH |
11568 | |
11569 | When we're called from the epilogue, we need to avoid counting | |
11570 | this as a store. */ | |
5e1bf043 | 11571 | |
71f123ca FS |
11572 | push_topmost_sequence (); |
11573 | top = get_insns (); | |
11574 | pop_topmost_sequence (); | |
5e1bf043 | 11575 | reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); |
71f123ca | 11576 | |
5e1bf043 DJ |
11577 | for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn)) |
11578 | { | |
11579 | if (INSN_P (insn)) | |
11580 | { | |
11581 | if (FIND_REG_INC_NOTE (insn, reg)) | |
11582 | return 1; | |
11583 | else if (GET_CODE (insn) == CALL_INSN | |
c15b529f | 11584 | && !SIBLING_CALL_P (insn)) |
5e1bf043 | 11585 | return 1; |
36f7e964 AH |
11586 | else if (set_of (reg, insn) != NULL_RTX |
11587 | && !prologue_epilogue_contains (insn)) | |
5e1bf043 DJ |
11588 | return 1; |
11589 | } | |
11590 | } | |
11591 | return 0; | |
71f123ca | 11592 | } |
4697a36c | 11593 | \f |
8cd8f856 GK |
11594 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
11595 | static void | |
a2369ed3 | 11596 | rs6000_maybe_dead (rtx insn) |
8cd8f856 GK |
11597 | { |
11598 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
11599 | const0_rtx, | |
11600 | REG_NOTES (insn)); | |
11601 | } | |
11602 | ||
9ebbca7d | 11603 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 11604 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 11605 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
11606 | |
11607 | void | |
a2369ed3 | 11608 | rs6000_emit_load_toc_table (int fromprolog) |
c7ca610e | 11609 | { |
027fbf43 | 11610 | rtx dest, insn; |
1db02437 | 11611 | dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); |
c7ca610e | 11612 | |
20b71b17 AM |
11613 | if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
11614 | { | |
11615 | rtx temp = (fromprolog | |
11616 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
11617 | : gen_reg_rtx (Pmode)); | |
027fbf43 JJ |
11618 | insn = emit_insn (gen_load_toc_v4_pic_si (temp)); |
11619 | if (fromprolog) | |
11620 | rs6000_maybe_dead (insn); | |
11621 | insn = emit_move_insn (dest, temp); | |
11622 | if (fromprolog) | |
11623 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
11624 | } |
11625 | else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2) | |
11626 | { | |
11627 | char buf[30]; | |
11628 | rtx tempLR = (fromprolog | |
11629 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
11630 | : gen_reg_rtx (Pmode)); | |
11631 | rtx temp0 = (fromprolog | |
11632 | ? gen_rtx_REG (Pmode, 0) | |
11633 | : gen_reg_rtx (Pmode)); | |
11634 | rtx symF; | |
11635 | ||
11636 | /* possibly create the toc section */ | |
11637 | if (! toc_initialized) | |
38c1f2d7 | 11638 | { |
20b71b17 AM |
11639 | toc_section (); |
11640 | function_section (current_function_decl); | |
38c1f2d7 | 11641 | } |
9ebbca7d | 11642 | |
20b71b17 AM |
11643 | if (fromprolog) |
11644 | { | |
11645 | rtx symL; | |
38c1f2d7 | 11646 | |
20b71b17 AM |
11647 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); |
11648 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9ebbca7d | 11649 | |
20b71b17 AM |
11650 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
11651 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11652 | ||
11653 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, | |
11654 | symF))); | |
11655 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
11656 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
11657 | symL, | |
11658 | symF))); | |
9ebbca7d GK |
11659 | } |
11660 | else | |
20b71b17 AM |
11661 | { |
11662 | rtx tocsym; | |
11663 | static int reload_toc_labelno = 0; | |
11664 | ||
11665 | tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); | |
11666 | ||
11667 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); | |
11668 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11669 | ||
027fbf43 JJ |
11670 | emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym)); |
11671 | emit_move_insn (dest, tempLR); | |
11672 | emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest)); | |
20b71b17 | 11673 | } |
027fbf43 JJ |
11674 | insn = emit_insn (gen_addsi3 (dest, temp0, dest)); |
11675 | if (fromprolog) | |
11676 | rs6000_maybe_dead (insn); | |
9ebbca7d | 11677 | } |
20b71b17 AM |
11678 | else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC) |
11679 | { | |
11680 | /* This is for AIX code running in non-PIC ELF32. */ | |
11681 | char buf[30]; | |
11682 | rtx realsym; | |
11683 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
11684 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11685 | ||
027fbf43 JJ |
11686 | insn = emit_insn (gen_elf_high (dest, realsym)); |
11687 | if (fromprolog) | |
11688 | rs6000_maybe_dead (insn); | |
11689 | insn = emit_insn (gen_elf_low (dest, dest, realsym)); | |
11690 | if (fromprolog) | |
11691 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
11692 | } |
11693 | else if (DEFAULT_ABI == ABI_AIX) | |
9ebbca7d GK |
11694 | { |
11695 | if (TARGET_32BIT) | |
027fbf43 | 11696 | insn = emit_insn (gen_load_toc_aix_si (dest)); |
9ebbca7d | 11697 | else |
027fbf43 JJ |
11698 | insn = emit_insn (gen_load_toc_aix_di (dest)); |
11699 | if (fromprolog) | |
11700 | rs6000_maybe_dead (insn); | |
9ebbca7d | 11701 | } |
20b71b17 AM |
11702 | else |
11703 | abort (); | |
9ebbca7d GK |
11704 | } |
11705 | ||
d1d0c603 JJ |
11706 | /* Emit instructions to restore the link register after determining where |
11707 | its value has been stored. */ | |
11708 | ||
11709 | void | |
11710 | rs6000_emit_eh_reg_restore (rtx source, rtx scratch) | |
11711 | { | |
11712 | rs6000_stack_t *info = rs6000_stack_info (); | |
11713 | rtx operands[2]; | |
11714 | ||
11715 | operands[0] = source; | |
11716 | operands[1] = scratch; | |
11717 | ||
11718 | if (info->lr_save_p) | |
11719 | { | |
11720 | rtx frame_rtx = stack_pointer_rtx; | |
11721 | HOST_WIDE_INT sp_offset = 0; | |
11722 | rtx tmp; | |
11723 | ||
11724 | if (frame_pointer_needed | |
11725 | || current_function_calls_alloca | |
11726 | || info->total_size > 32767) | |
11727 | { | |
11728 | emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx)); | |
11729 | frame_rtx = operands[1]; | |
11730 | } | |
11731 | else if (info->push_p) | |
11732 | sp_offset = info->total_size; | |
11733 | ||
11734 | tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset); | |
11735 | tmp = gen_rtx_MEM (Pmode, tmp); | |
11736 | emit_move_insn (tmp, operands[0]); | |
11737 | } | |
11738 | else | |
11739 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]); | |
11740 | } | |
11741 | ||
f103e34d GK |
11742 | static GTY(()) int set = -1; |
11743 | ||
9ebbca7d | 11744 | int |
863d938c | 11745 | get_TOC_alias_set (void) |
9ebbca7d | 11746 | { |
f103e34d GK |
11747 | if (set == -1) |
11748 | set = new_alias_set (); | |
11749 | return set; | |
9ebbca7d GK |
11750 | } |
11751 | ||
c1207243 | 11752 | /* This returns nonzero if the current function uses the TOC. This is |
3c9eb5f4 AM |
11753 | determined by the presence of (use (unspec ... UNSPEC_TOC)), which |
11754 | is generated by the ABI_V4 load_toc_* patterns. */ | |
c954844a | 11755 | #if TARGET_ELF |
3c9eb5f4 | 11756 | static int |
38f391a5 | 11757 | uses_TOC (void) |
9ebbca7d | 11758 | { |
c4501e62 | 11759 | rtx insn; |
38c1f2d7 | 11760 | |
c4501e62 JJ |
11761 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
11762 | if (INSN_P (insn)) | |
11763 | { | |
11764 | rtx pat = PATTERN (insn); | |
11765 | int i; | |
9ebbca7d | 11766 | |
c4501e62 JJ |
11767 | if (GET_CODE (pat) == PARALLEL) |
11768 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
11769 | { | |
11770 | rtx sub = XVECEXP (pat, 0, i); | |
11771 | if (GET_CODE (sub) == USE) | |
11772 | { | |
11773 | sub = XEXP (sub, 0); | |
11774 | if (GET_CODE (sub) == UNSPEC | |
11775 | && XINT (sub, 1) == UNSPEC_TOC) | |
11776 | return 1; | |
11777 | } | |
11778 | } | |
11779 | } | |
11780 | return 0; | |
9ebbca7d | 11781 | } |
c954844a | 11782 | #endif |
38c1f2d7 | 11783 | |
9ebbca7d | 11784 | rtx |
a2369ed3 | 11785 | create_TOC_reference (rtx symbol) |
9ebbca7d | 11786 | { |
a8a05998 ZW |
11787 | return gen_rtx_PLUS (Pmode, |
11788 | gen_rtx_REG (Pmode, TOC_REGISTER), | |
11789 | gen_rtx_CONST (Pmode, | |
11790 | gen_rtx_MINUS (Pmode, symbol, | |
b999aaeb | 11791 | gen_rtx_SYMBOL_REF (Pmode, toc_label_name)))); |
9ebbca7d | 11792 | } |
38c1f2d7 | 11793 | |
fc4767bb JJ |
11794 | /* If _Unwind_* has been called from within the same module, |
11795 | toc register is not guaranteed to be saved to 40(1) on function | |
11796 | entry. Save it there in that case. */ | |
c7ca610e | 11797 | |
9ebbca7d | 11798 | void |
863d938c | 11799 | rs6000_aix_emit_builtin_unwind_init (void) |
9ebbca7d GK |
11800 | { |
11801 | rtx mem; | |
11802 | rtx stack_top = gen_reg_rtx (Pmode); | |
11803 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
fc4767bb JJ |
11804 | rtx opcode = gen_reg_rtx (SImode); |
11805 | rtx tocompare = gen_reg_rtx (SImode); | |
11806 | rtx no_toc_save_needed = gen_label_rtx (); | |
9ebbca7d GK |
11807 | |
11808 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
11809 | emit_move_insn (stack_top, mem); | |
11810 | ||
fc4767bb JJ |
11811 | mem = gen_rtx_MEM (Pmode, |
11812 | gen_rtx_PLUS (Pmode, stack_top, | |
9ebbca7d GK |
11813 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); |
11814 | emit_move_insn (opcode_addr, mem); | |
fc4767bb JJ |
11815 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); |
11816 | emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014 | |
2496c7bd | 11817 | : 0xE8410028, SImode)); |
9ebbca7d | 11818 | |
fc4767bb | 11819 | do_compare_rtx_and_jump (opcode, tocompare, EQ, 1, |
06f4e019 | 11820 | SImode, NULL_RTX, NULL_RTX, |
fc4767bb | 11821 | no_toc_save_needed); |
9ebbca7d | 11822 | |
fc4767bb JJ |
11823 | mem = gen_rtx_MEM (Pmode, |
11824 | gen_rtx_PLUS (Pmode, stack_top, | |
11825 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
11826 | emit_move_insn (mem, gen_rtx_REG (Pmode, 2)); | |
11827 | emit_label (no_toc_save_needed); | |
9ebbca7d | 11828 | } |
38c1f2d7 | 11829 | \f |
ba4828e0 RK |
11830 | /* This ties together stack memory (MEM with an alias set of |
11831 | rs6000_sr_alias_set) and the change to the stack pointer. */ | |
11832 | ||
9ebbca7d | 11833 | static void |
863d938c | 11834 | rs6000_emit_stack_tie (void) |
9ebbca7d | 11835 | { |
ba4828e0 RK |
11836 | rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); |
11837 | ||
11838 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
11839 | emit_insn (gen_stack_tie (mem)); |
11840 | } | |
38c1f2d7 | 11841 | |
9ebbca7d GK |
11842 | /* Emit the correct code for allocating stack space, as insns. |
11843 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
11844 | The generated code may use hard register 0 as a temporary. */ | |
11845 | ||
11846 | static void | |
a2369ed3 | 11847 | rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12) |
38c1f2d7 | 11848 | { |
9ebbca7d GK |
11849 | rtx insn; |
11850 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
11851 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
11852 | rtx todec = GEN_INT (-size); | |
a157febd GK |
11853 | |
11854 | if (current_function_limit_stack) | |
11855 | { | |
11856 | if (REG_P (stack_limit_rtx) | |
11857 | && REGNO (stack_limit_rtx) > 1 | |
11858 | && REGNO (stack_limit_rtx) <= 31) | |
11859 | { | |
5b71a4e7 | 11860 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
11861 | ? gen_addsi3 (tmp_reg, |
11862 | stack_limit_rtx, | |
11863 | GEN_INT (size)) | |
11864 | : gen_adddi3 (tmp_reg, | |
11865 | stack_limit_rtx, | |
11866 | GEN_INT (size))); | |
5b71a4e7 | 11867 | |
9ebbca7d GK |
11868 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, |
11869 | const0_rtx)); | |
a157febd GK |
11870 | } |
11871 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 11872 | && TARGET_32BIT |
f607bc57 | 11873 | && DEFAULT_ABI == ABI_V4) |
a157febd | 11874 | { |
9ebbca7d GK |
11875 | rtx toload = gen_rtx_CONST (VOIDmode, |
11876 | gen_rtx_PLUS (Pmode, | |
11877 | stack_limit_rtx, | |
11878 | GEN_INT (size))); | |
5b71a4e7 | 11879 | |
9ebbca7d GK |
11880 | emit_insn (gen_elf_high (tmp_reg, toload)); |
11881 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
11882 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
11883 | const0_rtx)); | |
a157febd GK |
11884 | } |
11885 | else | |
11886 | warning ("stack limit expression is not supported"); | |
11887 | } | |
11888 | ||
9ebbca7d GK |
11889 | if (copy_r12 || ! TARGET_UPDATE) |
11890 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
11891 | ||
38c1f2d7 MM |
11892 | if (TARGET_UPDATE) |
11893 | { | |
9ebbca7d | 11894 | if (size > 32767) |
38c1f2d7 | 11895 | { |
9ebbca7d GK |
11896 | /* Need a note here so that try_split doesn't get confused. */ |
11897 | if (get_last_insn() == NULL_RTX) | |
2e040219 | 11898 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d GK |
11899 | insn = emit_move_insn (tmp_reg, todec); |
11900 | try_split (PATTERN (insn), insn, 0); | |
11901 | todec = tmp_reg; | |
38c1f2d7 | 11902 | } |
5b71a4e7 DE |
11903 | |
11904 | insn = emit_insn (TARGET_32BIT | |
11905 | ? gen_movsi_update (stack_reg, stack_reg, | |
11906 | todec, stack_reg) | |
11907 | : gen_movdi_update (stack_reg, stack_reg, | |
9ebbca7d | 11908 | todec, stack_reg)); |
38c1f2d7 MM |
11909 | } |
11910 | else | |
11911 | { | |
5b71a4e7 DE |
11912 | insn = emit_insn (TARGET_32BIT |
11913 | ? gen_addsi3 (stack_reg, stack_reg, todec) | |
11914 | : gen_adddi3 (stack_reg, stack_reg, todec)); | |
9ebbca7d GK |
11915 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), |
11916 | gen_rtx_REG (Pmode, 12)); | |
11917 | } | |
5b71a4e7 | 11918 | |
9ebbca7d GK |
11919 | RTX_FRAME_RELATED_P (insn) = 1; |
11920 | REG_NOTES (insn) = | |
11921 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
11922 | gen_rtx_SET (VOIDmode, stack_reg, | |
11923 | gen_rtx_PLUS (Pmode, stack_reg, | |
11924 | GEN_INT (-size))), | |
11925 | REG_NOTES (insn)); | |
11926 | } | |
11927 | ||
a4f6c312 SS |
11928 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced |
11929 | with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 | |
11930 | is not NULL. It would be nice if dwarf2out_frame_debug_expr could | |
11931 | deduce these equivalences by itself so it wasn't necessary to hold | |
11932 | its hand so much. */ | |
9ebbca7d GK |
11933 | |
11934 | static void | |
a2369ed3 DJ |
11935 | rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val, |
11936 | rtx reg2, rtx rreg) | |
9ebbca7d GK |
11937 | { |
11938 | rtx real, temp; | |
11939 | ||
e56c4463 JL |
11940 | /* copy_rtx will not make unique copies of registers, so we need to |
11941 | ensure we don't have unwanted sharing here. */ | |
11942 | if (reg == reg2) | |
11943 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
11944 | ||
11945 | if (reg == rreg) | |
11946 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
11947 | ||
9ebbca7d GK |
11948 | real = copy_rtx (PATTERN (insn)); |
11949 | ||
89e7058f AH |
11950 | if (reg2 != NULL_RTX) |
11951 | real = replace_rtx (real, reg2, rreg); | |
11952 | ||
9ebbca7d GK |
11953 | real = replace_rtx (real, reg, |
11954 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, | |
11955 | STACK_POINTER_REGNUM), | |
11956 | GEN_INT (val))); | |
11957 | ||
11958 | /* We expect that 'real' is either a SET or a PARALLEL containing | |
11959 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
11960 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
11961 | ||
11962 | if (GET_CODE (real) == SET) | |
11963 | { | |
11964 | rtx set = real; | |
11965 | ||
11966 | temp = simplify_rtx (SET_SRC (set)); | |
11967 | if (temp) | |
11968 | SET_SRC (set) = temp; | |
11969 | temp = simplify_rtx (SET_DEST (set)); | |
11970 | if (temp) | |
11971 | SET_DEST (set) = temp; | |
11972 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 11973 | { |
9ebbca7d GK |
11974 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
11975 | if (temp) | |
11976 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 11977 | } |
38c1f2d7 | 11978 | } |
9ebbca7d GK |
11979 | else if (GET_CODE (real) == PARALLEL) |
11980 | { | |
11981 | int i; | |
11982 | for (i = 0; i < XVECLEN (real, 0); i++) | |
11983 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
11984 | { | |
11985 | rtx set = XVECEXP (real, 0, i); | |
11986 | ||
11987 | temp = simplify_rtx (SET_SRC (set)); | |
11988 | if (temp) | |
11989 | SET_SRC (set) = temp; | |
11990 | temp = simplify_rtx (SET_DEST (set)); | |
11991 | if (temp) | |
11992 | SET_DEST (set) = temp; | |
11993 | if (GET_CODE (SET_DEST (set)) == MEM) | |
11994 | { | |
11995 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
11996 | if (temp) | |
11997 | XEXP (SET_DEST (set), 0) = temp; | |
11998 | } | |
11999 | RTX_FRAME_RELATED_P (set) = 1; | |
12000 | } | |
12001 | } | |
12002 | else | |
a4f6c312 | 12003 | abort (); |
c19de7aa AH |
12004 | |
12005 | if (TARGET_SPE) | |
12006 | real = spe_synthesize_frame_save (real); | |
12007 | ||
9ebbca7d GK |
12008 | RTX_FRAME_RELATED_P (insn) = 1; |
12009 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
12010 | real, | |
12011 | REG_NOTES (insn)); | |
38c1f2d7 MM |
12012 | } |
12013 | ||
c19de7aa AH |
12014 | /* Given an SPE frame note, return a PARALLEL of SETs with the |
12015 | original note, plus a synthetic register save. */ | |
12016 | ||
12017 | static rtx | |
a2369ed3 | 12018 | spe_synthesize_frame_save (rtx real) |
c19de7aa AH |
12019 | { |
12020 | rtx synth, offset, reg, real2; | |
12021 | ||
12022 | if (GET_CODE (real) != SET | |
12023 | || GET_MODE (SET_SRC (real)) != V2SImode) | |
12024 | return real; | |
12025 | ||
12026 | /* For the SPE, registers saved in 64-bits, get a PARALLEL for their | |
12027 | frame related note. The parallel contains a set of the register | |
41f3a930 | 12028 | being saved, and another set to a synthetic register (n+1200). |
c19de7aa AH |
12029 | This is so we can differentiate between 64-bit and 32-bit saves. |
12030 | Words cannot describe this nastiness. */ | |
12031 | ||
12032 | if (GET_CODE (SET_DEST (real)) != MEM | |
12033 | || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS | |
12034 | || GET_CODE (SET_SRC (real)) != REG) | |
12035 | abort (); | |
12036 | ||
12037 | /* Transform: | |
12038 | (set (mem (plus (reg x) (const y))) | |
12039 | (reg z)) | |
12040 | into: | |
12041 | (set (mem (plus (reg x) (const y+4))) | |
41f3a930 | 12042 | (reg z+1200)) |
c19de7aa AH |
12043 | */ |
12044 | ||
12045 | real2 = copy_rtx (real); | |
12046 | PUT_MODE (SET_DEST (real2), SImode); | |
12047 | reg = SET_SRC (real2); | |
12048 | real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg))); | |
12049 | synth = copy_rtx (real2); | |
12050 | ||
12051 | if (BYTES_BIG_ENDIAN) | |
12052 | { | |
12053 | offset = XEXP (XEXP (SET_DEST (real2), 0), 1); | |
12054 | real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4)); | |
12055 | } | |
12056 | ||
12057 | reg = SET_SRC (synth); | |
41f3a930 | 12058 | |
c19de7aa | 12059 | synth = replace_rtx (synth, reg, |
41f3a930 | 12060 | gen_rtx_REG (SImode, REGNO (reg) + 1200)); |
c19de7aa AH |
12061 | |
12062 | offset = XEXP (XEXP (SET_DEST (synth), 0), 1); | |
12063 | synth = replace_rtx (synth, offset, | |
12064 | GEN_INT (INTVAL (offset) | |
12065 | + (BYTES_BIG_ENDIAN ? 0 : 4))); | |
12066 | ||
12067 | RTX_FRAME_RELATED_P (synth) = 1; | |
12068 | RTX_FRAME_RELATED_P (real2) = 1; | |
12069 | if (BYTES_BIG_ENDIAN) | |
12070 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2)); | |
12071 | else | |
12072 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth)); | |
12073 | ||
12074 | return real; | |
12075 | } | |
12076 | ||
00b960c7 AH |
12077 | /* Returns an insn that has a vrsave set operation with the |
12078 | appropriate CLOBBERs. */ | |
12079 | ||
12080 | static rtx | |
a2369ed3 | 12081 | generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep) |
00b960c7 AH |
12082 | { |
12083 | int nclobs, i; | |
12084 | rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1]; | |
a004eb82 | 12085 | rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
00b960c7 | 12086 | |
a004eb82 AH |
12087 | clobs[0] |
12088 | = gen_rtx_SET (VOIDmode, | |
12089 | vrsave, | |
12090 | gen_rtx_UNSPEC_VOLATILE (SImode, | |
12091 | gen_rtvec (2, reg, vrsave), | |
12092 | 30)); | |
00b960c7 AH |
12093 | |
12094 | nclobs = 1; | |
12095 | ||
9aa86737 AH |
12096 | /* We need to clobber the registers in the mask so the scheduler |
12097 | does not move sets to VRSAVE before sets of AltiVec registers. | |
12098 | ||
12099 | However, if the function receives nonlocal gotos, reload will set | |
12100 | all call saved registers live. We will end up with: | |
12101 | ||
12102 | (set (reg 999) (mem)) | |
12103 | (parallel [ (set (reg vrsave) (unspec blah)) | |
12104 | (clobber (reg 999))]) | |
12105 | ||
12106 | The clobber will cause the store into reg 999 to be dead, and | |
12107 | flow will attempt to delete an epilogue insn. In this case, we | |
12108 | need an unspec use/set of the register. */ | |
00b960c7 AH |
12109 | |
12110 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
44688022 | 12111 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) |
9aa86737 AH |
12112 | { |
12113 | if (!epiloguep || call_used_regs [i]) | |
12114 | clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode, | |
12115 | gen_rtx_REG (V4SImode, i)); | |
12116 | else | |
12117 | { | |
12118 | rtx reg = gen_rtx_REG (V4SImode, i); | |
9aa86737 AH |
12119 | |
12120 | clobs[nclobs++] | |
a004eb82 AH |
12121 | = gen_rtx_SET (VOIDmode, |
12122 | reg, | |
12123 | gen_rtx_UNSPEC (V4SImode, | |
12124 | gen_rtvec (1, reg), 27)); | |
9aa86737 AH |
12125 | } |
12126 | } | |
00b960c7 AH |
12127 | |
12128 | insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs)); | |
12129 | ||
12130 | for (i = 0; i < nclobs; ++i) | |
12131 | XVECEXP (insn, 0, i) = clobs[i]; | |
12132 | ||
12133 | return insn; | |
12134 | } | |
12135 | ||
89e7058f AH |
12136 | /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes. |
12137 | Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */ | |
12138 | ||
12139 | static void | |
a2369ed3 | 12140 | emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode, |
d1d0c603 | 12141 | unsigned int regno, int offset, HOST_WIDE_INT total_size) |
89e7058f AH |
12142 | { |
12143 | rtx reg, offset_rtx, insn, mem, addr, int_rtx; | |
12144 | rtx replacea, replaceb; | |
12145 | ||
12146 | int_rtx = GEN_INT (offset); | |
12147 | ||
12148 | /* Some cases that need register indexed addressing. */ | |
12149 | if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
a3170dc6 AH |
12150 | || (TARGET_SPE_ABI |
12151 | && SPE_VECTOR_MODE (mode) | |
12152 | && !SPE_CONST_OFFSET_OK (offset))) | |
89e7058f AH |
12153 | { |
12154 | /* Whomever calls us must make sure r11 is available in the | |
12155 | flow path of instructions in the prologue. */ | |
12156 | offset_rtx = gen_rtx_REG (Pmode, 11); | |
12157 | emit_move_insn (offset_rtx, int_rtx); | |
12158 | ||
12159 | replacea = offset_rtx; | |
12160 | replaceb = int_rtx; | |
12161 | } | |
12162 | else | |
12163 | { | |
12164 | offset_rtx = int_rtx; | |
12165 | replacea = NULL_RTX; | |
12166 | replaceb = NULL_RTX; | |
12167 | } | |
12168 | ||
12169 | reg = gen_rtx_REG (mode, regno); | |
12170 | addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx); | |
12171 | mem = gen_rtx_MEM (mode, addr); | |
12172 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12173 | ||
12174 | insn = emit_move_insn (mem, reg); | |
12175 | ||
12176 | rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb); | |
12177 | } | |
12178 | ||
a3170dc6 AH |
12179 | /* Emit an offset memory reference suitable for a frame store, while |
12180 | converting to a valid addressing mode. */ | |
12181 | ||
12182 | static rtx | |
a2369ed3 | 12183 | gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset) |
a3170dc6 AH |
12184 | { |
12185 | rtx int_rtx, offset_rtx; | |
12186 | ||
12187 | int_rtx = GEN_INT (offset); | |
12188 | ||
12189 | if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode)) | |
12190 | { | |
12191 | offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12192 | emit_move_insn (offset_rtx, int_rtx); | |
12193 | } | |
12194 | else | |
12195 | offset_rtx = int_rtx; | |
12196 | ||
12197 | return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx)); | |
12198 | } | |
12199 | ||
9ebbca7d GK |
12200 | /* Emit function prologue as insns. */ |
12201 | ||
9878760c | 12202 | void |
863d938c | 12203 | rs6000_emit_prologue (void) |
9878760c | 12204 | { |
4697a36c | 12205 | rs6000_stack_t *info = rs6000_stack_info (); |
0e67400a | 12206 | enum machine_mode reg_mode = Pmode; |
327e5343 | 12207 | int reg_size = TARGET_32BIT ? 4 : 8; |
9ebbca7d GK |
12208 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); |
12209 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
12210 | rtx frame_reg_rtx = sp_reg_rtx; | |
b78d48dd | 12211 | rtx cr_save_rtx = NULL_RTX; |
9ebbca7d GK |
12212 | rtx insn; |
12213 | int saving_FPRs_inline; | |
12214 | int using_store_multiple; | |
12215 | HOST_WIDE_INT sp_offset = 0; | |
12216 | ||
c19de7aa | 12217 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12218 | { |
12219 | reg_mode = V2SImode; | |
12220 | reg_size = 8; | |
12221 | } | |
12222 | ||
9ebbca7d | 12223 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
12224 | && (!TARGET_SPE_ABI |
12225 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
12226 | && info->first_gp_reg_save < 31); |
12227 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
8c29550d | 12228 | || FP_SAVE_INLINE (info->first_fp_reg_save) |
acd0b319 | 12229 | || current_function_calls_eh_return |
8c29550d | 12230 | || cfun->machine->ra_need_lr); |
9ebbca7d GK |
12231 | |
12232 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
fc4767bb | 12233 | if (info->push_p |
acd0b319 AM |
12234 | && (DEFAULT_ABI == ABI_V4 |
12235 | || current_function_calls_eh_return)) | |
9ebbca7d GK |
12236 | { |
12237 | if (info->total_size < 32767) | |
12238 | sp_offset = info->total_size; | |
12239 | else | |
12240 | frame_reg_rtx = frame_ptr_rtx; | |
12241 | rs6000_emit_allocate_stack (info->total_size, | |
12242 | (frame_reg_rtx != sp_reg_rtx | |
12243 | && (info->cr_save_p | |
12244 | || info->lr_save_p | |
12245 | || info->first_fp_reg_save < 64 | |
12246 | || info->first_gp_reg_save < 32 | |
12247 | ))); | |
12248 | if (frame_reg_rtx != sp_reg_rtx) | |
12249 | rs6000_emit_stack_tie (); | |
12250 | } | |
12251 | ||
9aa86737 AH |
12252 | /* Save AltiVec registers if needed. */ |
12253 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
12254 | { | |
12255 | int i; | |
12256 | ||
12257 | /* There should be a non inline version of this, for when we | |
12258 | are saving lots of vector registers. */ | |
12259 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
12260 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
12261 | { | |
12262 | rtx areg, savereg, mem; | |
12263 | int offset; | |
12264 | ||
12265 | offset = info->altivec_save_offset + sp_offset | |
12266 | + 16 * (i - info->first_altivec_reg_save); | |
12267 | ||
12268 | savereg = gen_rtx_REG (V4SImode, i); | |
12269 | ||
12270 | areg = gen_rtx_REG (Pmode, 0); | |
12271 | emit_move_insn (areg, GEN_INT (offset)); | |
12272 | ||
12273 | /* AltiVec addressing mode is [reg+reg]. */ | |
12274 | mem = gen_rtx_MEM (V4SImode, | |
12275 | gen_rtx_PLUS (Pmode, frame_reg_rtx, areg)); | |
12276 | ||
12277 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12278 | ||
12279 | insn = emit_move_insn (mem, savereg); | |
12280 | ||
5c242421 SB |
12281 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
12282 | areg, GEN_INT (offset)); | |
9aa86737 AH |
12283 | } |
12284 | } | |
12285 | ||
12286 | /* VRSAVE is a bit vector representing which AltiVec registers | |
12287 | are used. The OS uses this to determine which vector | |
12288 | registers to save on a context switch. We need to save | |
12289 | VRSAVE on the stack frame, add whatever AltiVec registers we | |
12290 | used in this function, and do the corresponding magic in the | |
12291 | epilogue. */ | |
12292 | ||
4d774ff8 HP |
12293 | if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE |
12294 | && info->vrsave_mask != 0) | |
9aa86737 | 12295 | { |
a004eb82 | 12296 | rtx reg, mem, vrsave; |
9aa86737 AH |
12297 | int offset; |
12298 | ||
12299 | /* Get VRSAVE onto a GPR. */ | |
12300 | reg = gen_rtx_REG (SImode, 12); | |
a004eb82 | 12301 | vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
b188f760 AH |
12302 | if (TARGET_MACHO) |
12303 | emit_insn (gen_get_vrsave_internal (reg)); | |
12304 | else | |
12305 | emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave)); | |
9aa86737 AH |
12306 | |
12307 | /* Save VRSAVE. */ | |
12308 | offset = info->vrsave_save_offset + sp_offset; | |
12309 | mem | |
12310 | = gen_rtx_MEM (SImode, | |
12311 | gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset))); | |
12312 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12313 | insn = emit_move_insn (mem, reg); | |
12314 | ||
12315 | /* Include the registers in the mask. */ | |
12316 | emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask))); | |
12317 | ||
12318 | insn = emit_insn (generate_set_vrsave (reg, info, 0)); | |
12319 | } | |
12320 | ||
9ebbca7d GK |
12321 | /* If we use the link register, get it into r0. */ |
12322 | if (info->lr_save_p) | |
71f123ca | 12323 | emit_move_insn (gen_rtx_REG (Pmode, 0), |
9ebbca7d GK |
12324 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); |
12325 | ||
12326 | /* If we need to save CR, put it into r12. */ | |
12327 | if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) | |
12328 | { | |
12329 | cr_save_rtx = gen_rtx_REG (SImode, 12); | |
12330 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
12331 | } | |
12332 | ||
a4f6c312 SS |
12333 | /* Do any required saving of fpr's. If only one or two to save, do |
12334 | it ourselves. Otherwise, call function. */ | |
9ebbca7d GK |
12335 | if (saving_FPRs_inline) |
12336 | { | |
12337 | int i; | |
12338 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12339 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
12340 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
89e7058f AH |
12341 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode, |
12342 | info->first_fp_reg_save + i, | |
12343 | info->fp_save_offset + sp_offset + 8 * i, | |
12344 | info->total_size); | |
9ebbca7d GK |
12345 | } |
12346 | else if (info->first_fp_reg_save != 64) | |
12347 | { | |
12348 | int i; | |
12349 | char rname[30]; | |
520a57c8 | 12350 | const char *alloc_rname; |
9ebbca7d GK |
12351 | rtvec p; |
12352 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
12353 | ||
12354 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
12355 | gen_rtx_REG (Pmode, | |
12356 | LINK_REGISTER_REGNUM)); | |
12357 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
12358 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
a8a05998 | 12359 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
12360 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
12361 | gen_rtx_SYMBOL_REF (Pmode, | |
12362 | alloc_rname)); | |
12363 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12364 | { | |
12365 | rtx addr, reg, mem; | |
12366 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
12367 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12368 | GEN_INT (info->fp_save_offset | |
12369 | + sp_offset + 8*i)); | |
12370 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 12371 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12372 | |
12373 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
12374 | } | |
12375 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
12376 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12377 | NULL_RTX, NULL_RTX); | |
12378 | } | |
b6c9286a | 12379 | |
9ebbca7d GK |
12380 | /* Save GPRs. This is done as a PARALLEL if we are using |
12381 | the store-multiple instructions. */ | |
12382 | if (using_store_multiple) | |
b6c9286a | 12383 | { |
308c142a | 12384 | rtvec p; |
9ebbca7d GK |
12385 | int i; |
12386 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
9ebbca7d GK |
12387 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) |
12388 | { | |
12389 | rtx addr, reg, mem; | |
12390 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
12391 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12392 | GEN_INT (info->gp_save_offset | |
12393 | + sp_offset | |
12394 | + reg_size * i)); | |
12395 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 12396 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12397 | |
12398 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
12399 | } | |
12400 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
12401 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12402 | NULL_RTX, NULL_RTX); | |
b6c9286a MM |
12403 | } |
12404 | else | |
12405 | { | |
9ebbca7d GK |
12406 | int i; |
12407 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
12408 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
12409 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
1db02437 | 12410 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 12411 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 12412 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
a3170dc6 AH |
12413 | { |
12414 | rtx addr, reg, mem; | |
12415 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
12416 | ||
c19de7aa | 12417 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12418 | { |
12419 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
12420 | rtx b; | |
12421 | ||
12422 | if (!SPE_CONST_OFFSET_OK (offset)) | |
12423 | { | |
12424 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12425 | emit_move_insn (b, GEN_INT (offset)); | |
12426 | } | |
12427 | else | |
12428 | b = GEN_INT (offset); | |
12429 | ||
12430 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
12431 | mem = gen_rtx_MEM (V2SImode, addr); | |
12432 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12433 | insn = emit_move_insn (mem, reg); | |
12434 | ||
12435 | if (GET_CODE (b) == CONST_INT) | |
12436 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12437 | NULL_RTX, NULL_RTX); | |
12438 | else | |
12439 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12440 | b, GEN_INT (offset)); | |
12441 | } | |
12442 | else | |
12443 | { | |
12444 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12445 | GEN_INT (info->gp_save_offset | |
12446 | + sp_offset | |
12447 | + reg_size * i)); | |
12448 | mem = gen_rtx_MEM (reg_mode, addr); | |
12449 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12450 | ||
12451 | insn = emit_move_insn (mem, reg); | |
12452 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12453 | NULL_RTX, NULL_RTX); | |
12454 | } | |
12455 | } | |
9ebbca7d GK |
12456 | } |
12457 | ||
83720594 RH |
12458 | /* ??? There's no need to emit actual instructions here, but it's the |
12459 | easiest way to get the frame unwind information emitted. */ | |
12460 | if (current_function_calls_eh_return) | |
12461 | { | |
78e1b90d DE |
12462 | unsigned int i, regno; |
12463 | ||
fc4767bb JJ |
12464 | /* In AIX ABI we need to pretend we save r2 here. */ |
12465 | if (TARGET_AIX) | |
12466 | { | |
12467 | rtx addr, reg, mem; | |
12468 | ||
12469 | reg = gen_rtx_REG (reg_mode, 2); | |
12470 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12471 | GEN_INT (sp_offset + 5 * reg_size)); | |
12472 | mem = gen_rtx_MEM (reg_mode, addr); | |
12473 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12474 | ||
12475 | insn = emit_move_insn (mem, reg); | |
12476 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12477 | NULL_RTX, NULL_RTX); | |
12478 | PATTERN (insn) = gen_blockage (); | |
12479 | } | |
12480 | ||
83720594 RH |
12481 | for (i = 0; ; ++i) |
12482 | { | |
83720594 RH |
12483 | regno = EH_RETURN_DATA_REGNO (i); |
12484 | if (regno == INVALID_REGNUM) | |
12485 | break; | |
12486 | ||
89e7058f AH |
12487 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno, |
12488 | info->ehrd_offset + sp_offset | |
12489 | + reg_size * (int) i, | |
12490 | info->total_size); | |
83720594 RH |
12491 | } |
12492 | } | |
12493 | ||
9ebbca7d GK |
12494 | /* Save lr if we used it. */ |
12495 | if (info->lr_save_p) | |
12496 | { | |
12497 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12498 | GEN_INT (info->lr_save_offset + sp_offset)); | |
12499 | rtx reg = gen_rtx_REG (Pmode, 0); | |
12500 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
12501 | /* This should not be of rs6000_sr_alias_set, because of | |
12502 | __builtin_return_address. */ | |
12503 | ||
12504 | insn = emit_move_insn (mem, reg); | |
12505 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12506 | reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
12507 | } | |
12508 | ||
12509 | /* Save CR if we use any that must be preserved. */ | |
12510 | if (info->cr_save_p) | |
12511 | { | |
12512 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12513 | GEN_INT (info->cr_save_offset + sp_offset)); | |
12514 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
12515 | |
12516 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
12517 | |
12518 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
12519 | that it's free. */ | |
12520 | if (REGNO (frame_reg_rtx) == 12) | |
12521 | { | |
12522 | cr_save_rtx = gen_rtx_REG (SImode, 0); | |
12523 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
12524 | } | |
12525 | insn = emit_move_insn (mem, cr_save_rtx); | |
12526 | ||
12527 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
615158e2 JJ |
12528 | to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'. |
12529 | But that's OK. All we have to do is specify that _one_ condition | |
12530 | code register is saved in this stack slot. The thrower's epilogue | |
a1dc9455 FS |
12531 | will then restore all the call-saved registers. |
12532 | We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */ | |
9ebbca7d | 12533 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
a1dc9455 | 12534 | cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO)); |
9ebbca7d GK |
12535 | } |
12536 | ||
12537 | /* Update stack and set back pointer unless this is V.4, | |
12538 | for which it was done previously. */ | |
fc4767bb JJ |
12539 | if (info->push_p |
12540 | && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return)) | |
9ebbca7d GK |
12541 | rs6000_emit_allocate_stack (info->total_size, FALSE); |
12542 | ||
12543 | /* Set frame pointer, if needed. */ | |
12544 | if (frame_pointer_needed) | |
12545 | { | |
a3170dc6 | 12546 | insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM), |
9ebbca7d GK |
12547 | sp_reg_rtx); |
12548 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 12549 | } |
9878760c | 12550 | |
1db02437 | 12551 | /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
9ebbca7d | 12552 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) |
f607bc57 | 12553 | || (DEFAULT_ABI == ABI_V4 && flag_pic == 1 |
1db02437 | 12554 | && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])) |
9ebbca7d GK |
12555 | { |
12556 | /* If emit_load_toc_table will use the link register, we need to save | |
c4501e62 | 12557 | it. We use R12 for this purpose because emit_load_toc_table |
9ebbca7d GK |
12558 | can use register 0. This allows us to use a plain 'blr' to return |
12559 | from the procedure more often. */ | |
f1384257 AM |
12560 | int save_LR_around_toc_setup = (TARGET_ELF |
12561 | && DEFAULT_ABI != ABI_AIX | |
12562 | && flag_pic | |
d5fa86ba GK |
12563 | && ! info->lr_save_p |
12564 | && EXIT_BLOCK_PTR->pred != NULL); | |
9ebbca7d | 12565 | if (save_LR_around_toc_setup) |
c4501e62 JJ |
12566 | { |
12567 | rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
12568 | rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr)); | |
12569 | rs6000_emit_load_toc_table (TRUE); | |
12570 | rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx)); | |
12571 | } | |
12572 | else | |
12573 | rs6000_emit_load_toc_table (TRUE); | |
9ebbca7d | 12574 | } |
ee890fe2 | 12575 | |
fcce224d | 12576 | #if TARGET_MACHO |
ee890fe2 SS |
12577 | if (DEFAULT_ABI == ABI_DARWIN |
12578 | && flag_pic && current_function_uses_pic_offset_table) | |
12579 | { | |
12580 | rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
f099d360 | 12581 | const char *picbase = machopic_function_base_name (); |
6788f5ca | 12582 | rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase); |
ee890fe2 | 12583 | |
f51eee6a | 12584 | rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src))); |
ee890fe2 SS |
12585 | |
12586 | rs6000_maybe_dead ( | |
1db02437 | 12587 | emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM), |
ee890fe2 SS |
12588 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM))); |
12589 | } | |
fcce224d | 12590 | #endif |
9ebbca7d GK |
12591 | } |
12592 | ||
9ebbca7d | 12593 | /* Write function prologue. */ |
a4f6c312 | 12594 | |
08c148a8 | 12595 | static void |
a2369ed3 DJ |
12596 | rs6000_output_function_prologue (FILE *file, |
12597 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) | |
9ebbca7d GK |
12598 | { |
12599 | rs6000_stack_t *info = rs6000_stack_info (); | |
12600 | ||
4697a36c MM |
12601 | if (TARGET_DEBUG_STACK) |
12602 | debug_stack_info (info); | |
9878760c | 12603 | |
a4f6c312 SS |
12604 | /* Write .extern for any function we will call to save and restore |
12605 | fp values. */ | |
12606 | if (info->first_fp_reg_save < 64 | |
12607 | && !FP_SAVE_INLINE (info->first_fp_reg_save)) | |
4d30c363 | 12608 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c | 12609 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
a4f6c312 SS |
12610 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, |
12611 | RESTORE_FP_SUFFIX); | |
9878760c | 12612 | |
c764f757 RK |
12613 | /* Write .extern for AIX common mode routines, if needed. */ |
12614 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
12615 | { | |
f6709c70 JW |
12616 | fputs ("\t.extern __mulh\n", file); |
12617 | fputs ("\t.extern __mull\n", file); | |
12618 | fputs ("\t.extern __divss\n", file); | |
12619 | fputs ("\t.extern __divus\n", file); | |
12620 | fputs ("\t.extern __quoss\n", file); | |
12621 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
12622 | common_mode_defined = 1; |
12623 | } | |
9878760c | 12624 | |
9ebbca7d | 12625 | if (! HAVE_prologue) |
979721f8 | 12626 | { |
9ebbca7d | 12627 | start_sequence (); |
9dda4cc8 | 12628 | |
a4f6c312 SS |
12629 | /* A NOTE_INSN_DELETED is supposed to be at the start and end of |
12630 | the "toplevel" insn chain. */ | |
2e040219 | 12631 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 12632 | rs6000_emit_prologue (); |
2e040219 | 12633 | emit_note (NOTE_INSN_DELETED); |
178c3eff | 12634 | |
a3c9585f | 12635 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
178c3eff DJ |
12636 | { |
12637 | rtx insn; | |
12638 | unsigned addr = 0; | |
12639 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
12640 | { | |
12641 | INSN_ADDRESSES_NEW (insn, addr); | |
12642 | addr += 4; | |
12643 | } | |
12644 | } | |
9dda4cc8 | 12645 | |
9ebbca7d | 12646 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
12647 | debug_rtx_list (get_insns (), 100); |
12648 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 12649 | end_sequence (); |
979721f8 MM |
12650 | } |
12651 | ||
9ebbca7d GK |
12652 | rs6000_pic_labelno++; |
12653 | } | |
12654 | ||
12655 | /* Emit function epilogue as insns. | |
9878760c | 12656 | |
9ebbca7d GK |
12657 | At present, dwarf2out_frame_debug_expr doesn't understand |
12658 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
12659 | anywhere in the epilogue. Most of the insns below would in any case | |
12660 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 12661 | |
9ebbca7d | 12662 | void |
a2369ed3 | 12663 | rs6000_emit_epilogue (int sibcall) |
9ebbca7d GK |
12664 | { |
12665 | rs6000_stack_t *info; | |
12666 | int restoring_FPRs_inline; | |
12667 | int using_load_multiple; | |
12668 | int using_mfcr_multiple; | |
12669 | int use_backchain_to_restore_sp; | |
12670 | int sp_offset = 0; | |
12671 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
12672 | rtx frame_reg_rtx = sp_reg_rtx; | |
0e67400a | 12673 | enum machine_mode reg_mode = Pmode; |
327e5343 | 12674 | int reg_size = TARGET_32BIT ? 4 : 8; |
9ebbca7d GK |
12675 | int i; |
12676 | ||
c19de7aa AH |
12677 | info = rs6000_stack_info (); |
12678 | ||
12679 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) | |
a3170dc6 AH |
12680 | { |
12681 | reg_mode = V2SImode; | |
12682 | reg_size = 8; | |
12683 | } | |
12684 | ||
9ebbca7d | 12685 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
12686 | && (!TARGET_SPE_ABI |
12687 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
12688 | && info->first_gp_reg_save < 31); |
12689 | restoring_FPRs_inline = (sibcall | |
83720594 | 12690 | || current_function_calls_eh_return |
9ebbca7d GK |
12691 | || info->first_fp_reg_save == 64 |
12692 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
12693 | use_backchain_to_restore_sp = (frame_pointer_needed | |
12694 | || current_function_calls_alloca | |
12695 | || info->total_size > 32767); | |
12696 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
12697 | || rs6000_cpu == PROCESSOR_PPC603 | |
12698 | || rs6000_cpu == PROCESSOR_PPC750 | |
12699 | || optimize_size); | |
12700 | ||
12701 | /* If we have a frame pointer, a call to alloca, or a large stack | |
12702 | frame, restore the old stack pointer using the backchain. Otherwise, | |
12703 | we know what size to update it with. */ | |
12704 | if (use_backchain_to_restore_sp) | |
bacbde18 | 12705 | { |
9ebbca7d GK |
12706 | /* Under V.4, don't reset the stack pointer until after we're done |
12707 | loading the saved registers. */ | |
f607bc57 | 12708 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d | 12709 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); |
4697a36c | 12710 | |
9ebbca7d GK |
12711 | emit_move_insn (frame_reg_rtx, |
12712 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
12713 | ||
bacbde18 | 12714 | } |
9ebbca7d | 12715 | else if (info->push_p) |
85638c0d | 12716 | { |
fc4767bb JJ |
12717 | if (DEFAULT_ABI == ABI_V4 |
12718 | || current_function_calls_eh_return) | |
9ebbca7d GK |
12719 | sp_offset = info->total_size; |
12720 | else | |
12721 | { | |
12722 | emit_insn (TARGET_32BIT | |
12723 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
12724 | GEN_INT (info->total_size)) | |
12725 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
12726 | GEN_INT (info->total_size))); | |
12727 | } | |
85638c0d | 12728 | } |
9ebbca7d | 12729 | |
9aa86737 AH |
12730 | /* Restore AltiVec registers if needed. */ |
12731 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
12732 | { | |
12733 | int i; | |
12734 | ||
12735 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
12736 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
12737 | { | |
12738 | rtx addr, areg, mem; | |
12739 | ||
12740 | areg = gen_rtx_REG (Pmode, 0); | |
12741 | emit_move_insn | |
12742 | (areg, GEN_INT (info->altivec_save_offset | |
12743 | + sp_offset | |
12744 | + 16 * (i - info->first_altivec_reg_save))); | |
12745 | ||
12746 | /* AltiVec addressing mode is [reg+reg]. */ | |
12747 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
12748 | mem = gen_rtx_MEM (V4SImode, addr); | |
12749 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12750 | ||
12751 | emit_move_insn (gen_rtx_REG (V4SImode, i), mem); | |
12752 | } | |
12753 | } | |
12754 | ||
12755 | /* Restore VRSAVE if needed. */ | |
44688022 | 12756 | if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE |
4d774ff8 | 12757 | && info->vrsave_mask != 0) |
9aa86737 AH |
12758 | { |
12759 | rtx addr, mem, reg; | |
12760 | ||
12761 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12762 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
12763 | mem = gen_rtx_MEM (SImode, addr); | |
12764 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12765 | reg = gen_rtx_REG (SImode, 12); | |
12766 | emit_move_insn (reg, mem); | |
12767 | ||
12768 | emit_insn (generate_set_vrsave (reg, info, 1)); | |
12769 | } | |
12770 | ||
9ebbca7d GK |
12771 | /* Get the old lr if we saved it. */ |
12772 | if (info->lr_save_p) | |
b6c9286a | 12773 | { |
a3170dc6 AH |
12774 | rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx, |
12775 | info->lr_save_offset + sp_offset); | |
ba4828e0 RK |
12776 | |
12777 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 12778 | |
9ebbca7d | 12779 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 12780 | } |
9ebbca7d GK |
12781 | |
12782 | /* Get the old cr if we saved it. */ | |
12783 | if (info->cr_save_p) | |
12784 | { | |
12785 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12786 | GEN_INT (info->cr_save_offset + sp_offset)); | |
12787 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
12788 | |
12789 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 12790 | |
9ebbca7d GK |
12791 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
12792 | } | |
12793 | ||
12794 | /* Set LR here to try to overlap restores below. */ | |
4697a36c | 12795 | if (info->lr_save_p) |
9ebbca7d GK |
12796 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
12797 | gen_rtx_REG (Pmode, 0)); | |
12798 | ||
83720594 RH |
12799 | /* Load exception handler data registers, if needed. */ |
12800 | if (current_function_calls_eh_return) | |
12801 | { | |
78e1b90d DE |
12802 | unsigned int i, regno; |
12803 | ||
fc4767bb JJ |
12804 | if (TARGET_AIX) |
12805 | { | |
12806 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12807 | GEN_INT (sp_offset + 5 * reg_size)); | |
12808 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
12809 | ||
12810 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12811 | ||
12812 | emit_move_insn (gen_rtx_REG (reg_mode, 2), mem); | |
12813 | } | |
12814 | ||
83720594 RH |
12815 | for (i = 0; ; ++i) |
12816 | { | |
a3170dc6 | 12817 | rtx mem; |
83720594 RH |
12818 | |
12819 | regno = EH_RETURN_DATA_REGNO (i); | |
12820 | if (regno == INVALID_REGNUM) | |
12821 | break; | |
12822 | ||
a3170dc6 AH |
12823 | mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx, |
12824 | info->ehrd_offset + sp_offset | |
12825 | + reg_size * (int) i); | |
ba4828e0 | 12826 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
12827 | |
12828 | emit_move_insn (gen_rtx_REG (reg_mode, regno), mem); | |
12829 | } | |
12830 | } | |
9ebbca7d GK |
12831 | |
12832 | /* Restore GPRs. This is done as a PARALLEL if we are using | |
12833 | the load-multiple instructions. */ | |
12834 | if (using_load_multiple) | |
979721f8 | 12835 | { |
9ebbca7d GK |
12836 | rtvec p; |
12837 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
12838 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 12839 | { |
9ebbca7d GK |
12840 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
12841 | GEN_INT (info->gp_save_offset | |
12842 | + sp_offset | |
12843 | + reg_size * i)); | |
12844 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
12845 | |
12846 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
12847 | |
12848 | RTVEC_ELT (p, i) = | |
12849 | gen_rtx_SET (VOIDmode, | |
12850 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
12851 | mem); | |
979721f8 | 12852 | } |
9ebbca7d | 12853 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 12854 | } |
9ebbca7d GK |
12855 | else |
12856 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
12857 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
12858 | && ! call_used_regs[info->first_gp_reg_save+i]) | |
1db02437 | 12859 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 12860 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 12861 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
9ebbca7d GK |
12862 | { |
12863 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12864 | GEN_INT (info->gp_save_offset | |
12865 | + sp_offset | |
12866 | + reg_size * i)); | |
12867 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 12868 | |
a3170dc6 | 12869 | /* Restore 64-bit quantities for SPE. */ |
c19de7aa | 12870 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12871 | { |
12872 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
12873 | rtx b; | |
12874 | ||
12875 | if (!SPE_CONST_OFFSET_OK (offset)) | |
12876 | { | |
12877 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12878 | emit_move_insn (b, GEN_INT (offset)); | |
12879 | } | |
12880 | else | |
12881 | b = GEN_INT (offset); | |
12882 | ||
12883 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
12884 | mem = gen_rtx_MEM (V2SImode, addr); | |
12885 | } | |
12886 | ||
ba4828e0 | 12887 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12888 | |
12889 | emit_move_insn (gen_rtx_REG (reg_mode, | |
a3170dc6 | 12890 | info->first_gp_reg_save + i), mem); |
9ebbca7d | 12891 | } |
9878760c | 12892 | |
9ebbca7d GK |
12893 | /* Restore fpr's if we need to do it without calling a function. */ |
12894 | if (restoring_FPRs_inline) | |
12895 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12896 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
12897 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
12898 | { | |
12899 | rtx addr, mem; | |
12900 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12901 | GEN_INT (info->fp_save_offset | |
12902 | + sp_offset | |
a4f6c312 | 12903 | + 8 * i)); |
9ebbca7d | 12904 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 12905 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12906 | |
12907 | emit_move_insn (gen_rtx_REG (DFmode, | |
12908 | info->first_fp_reg_save + i), | |
12909 | mem); | |
12910 | } | |
8d30c4ee | 12911 | |
9ebbca7d GK |
12912 | /* If we saved cr, restore it here. Just those that were used. */ |
12913 | if (info->cr_save_p) | |
979721f8 | 12914 | { |
9ebbca7d | 12915 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 12916 | int count = 0; |
9ebbca7d GK |
12917 | |
12918 | if (using_mfcr_multiple) | |
979721f8 | 12919 | { |
9ebbca7d GK |
12920 | for (i = 0; i < 8; i++) |
12921 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 12922 | count++; |
9ebbca7d | 12923 | if (count == 0) |
e35b9579 GK |
12924 | abort (); |
12925 | } | |
12926 | ||
12927 | if (using_mfcr_multiple && count > 1) | |
12928 | { | |
12929 | rtvec p; | |
12930 | int ndx; | |
9ebbca7d | 12931 | |
e35b9579 | 12932 | p = rtvec_alloc (count); |
9ebbca7d | 12933 | |
e35b9579 | 12934 | ndx = 0; |
9ebbca7d GK |
12935 | for (i = 0; i < 8; i++) |
12936 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
12937 | { | |
12938 | rtvec r = rtvec_alloc (2); | |
12939 | RTVEC_ELT (r, 0) = r12_rtx; | |
12940 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 12941 | RTVEC_ELT (p, ndx) = |
9ebbca7d | 12942 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
615158e2 | 12943 | gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR)); |
e35b9579 | 12944 | ndx++; |
9ebbca7d GK |
12945 | } |
12946 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
12947 | if (ndx != count) |
12948 | abort (); | |
979721f8 MM |
12949 | } |
12950 | else | |
9ebbca7d GK |
12951 | for (i = 0; i < 8; i++) |
12952 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 12953 | { |
9ebbca7d GK |
12954 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
12955 | CR0_REGNO+i), | |
12956 | r12_rtx)); | |
979721f8 | 12957 | } |
979721f8 MM |
12958 | } |
12959 | ||
9ebbca7d GK |
12960 | /* If this is V.4, unwind the stack pointer after all of the loads |
12961 | have been done. We need to emit a block here so that sched | |
12962 | doesn't decide to move the sp change before the register restores | |
12963 | (which may not have any obvious dependency on the stack). This | |
12964 | doesn't hurt performance, because there is no scheduling that can | |
12965 | be done after this point. */ | |
fc4767bb JJ |
12966 | if (DEFAULT_ABI == ABI_V4 |
12967 | || current_function_calls_eh_return) | |
b6c9286a | 12968 | { |
9ebbca7d GK |
12969 | if (frame_reg_rtx != sp_reg_rtx) |
12970 | rs6000_emit_stack_tie (); | |
b6c9286a | 12971 | |
9ebbca7d | 12972 | if (use_backchain_to_restore_sp) |
b6c9286a | 12973 | { |
9ebbca7d | 12974 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 12975 | } |
9ebbca7d | 12976 | else if (sp_offset != 0) |
13f1623b | 12977 | { |
5b71a4e7 | 12978 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
12979 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, |
12980 | GEN_INT (sp_offset)) | |
12981 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
12982 | GEN_INT (sp_offset))); | |
13f1623b | 12983 | } |
9ebbca7d | 12984 | } |
b6c9286a | 12985 | |
83720594 RH |
12986 | if (current_function_calls_eh_return) |
12987 | { | |
12988 | rtx sa = EH_RETURN_STACKADJ_RTX; | |
5b71a4e7 | 12989 | emit_insn (TARGET_32BIT |
83720594 RH |
12990 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa) |
12991 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa)); | |
12992 | } | |
12993 | ||
9ebbca7d GK |
12994 | if (!sibcall) |
12995 | { | |
12996 | rtvec p; | |
12997 | if (! restoring_FPRs_inline) | |
12998 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
12999 | else | |
13000 | p = rtvec_alloc (2); | |
b6c9286a | 13001 | |
e35b9579 GK |
13002 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
13003 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
9ebbca7d GK |
13004 | gen_rtx_REG (Pmode, |
13005 | LINK_REGISTER_REGNUM)); | |
9ebbca7d GK |
13006 | |
13007 | /* If we have to restore more than two FP registers, branch to the | |
13008 | restore function. It will return to our caller. */ | |
13009 | if (! restoring_FPRs_inline) | |
13010 | { | |
13011 | int i; | |
13012 | char rname[30]; | |
520a57c8 | 13013 | const char *alloc_rname; |
979721f8 | 13014 | |
9ebbca7d GK |
13015 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
13016 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
a8a05998 | 13017 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
13018 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, |
13019 | gen_rtx_SYMBOL_REF (Pmode, | |
13020 | alloc_rname)); | |
b6c9286a | 13021 | |
9ebbca7d GK |
13022 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
13023 | { | |
13024 | rtx addr, mem; | |
13025 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
13026 | GEN_INT (info->fp_save_offset + 8*i)); | |
13027 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 13028 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
13029 | |
13030 | RTVEC_ELT (p, i+3) = | |
13031 | gen_rtx_SET (VOIDmode, | |
13032 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
13033 | mem); | |
b6c9286a MM |
13034 | } |
13035 | } | |
9ebbca7d GK |
13036 | |
13037 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
3daf36a4 | 13038 | } |
9878760c RK |
13039 | } |
13040 | ||
13041 | /* Write function epilogue. */ | |
13042 | ||
08c148a8 | 13043 | static void |
a2369ed3 DJ |
13044 | rs6000_output_function_epilogue (FILE *file, |
13045 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) | |
9878760c | 13046 | { |
4697a36c | 13047 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 13048 | |
9ebbca7d | 13049 | if (! HAVE_epilogue) |
9878760c | 13050 | { |
9ebbca7d GK |
13051 | rtx insn = get_last_insn (); |
13052 | /* If the last insn was a BARRIER, we don't have to write anything except | |
13053 | the trace table. */ | |
13054 | if (GET_CODE (insn) == NOTE) | |
13055 | insn = prev_nonnote_insn (insn); | |
13056 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 13057 | { |
9ebbca7d GK |
13058 | /* This is slightly ugly, but at least we don't have two |
13059 | copies of the epilogue-emitting code. */ | |
13060 | start_sequence (); | |
13061 | ||
13062 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
13063 | and end of the "toplevel" insn chain. */ | |
2e040219 | 13064 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 13065 | rs6000_emit_epilogue (FALSE); |
2e040219 | 13066 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 13067 | |
a3c9585f | 13068 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
178c3eff DJ |
13069 | { |
13070 | rtx insn; | |
13071 | unsigned addr = 0; | |
13072 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
13073 | { | |
13074 | INSN_ADDRESSES_NEW (insn, addr); | |
13075 | addr += 4; | |
13076 | } | |
13077 | } | |
13078 | ||
9ebbca7d | 13079 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
13080 | debug_rtx_list (get_insns (), 100); |
13081 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 13082 | end_sequence (); |
4697a36c | 13083 | } |
9878760c | 13084 | } |
b4ac57ab | 13085 | |
efdba735 SH |
13086 | #if TARGET_MACHO |
13087 | macho_branch_islands (); | |
0e5da0be GK |
13088 | /* Mach-O doesn't support labels at the end of objects, so if |
13089 | it looks like we might want one, insert a NOP. */ | |
13090 | { | |
13091 | rtx insn = get_last_insn (); | |
13092 | while (insn | |
13093 | && NOTE_P (insn) | |
13094 | && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL) | |
13095 | insn = PREV_INSN (insn); | |
13096 | if (insn | |
13097 | && (LABEL_P (insn) | |
13098 | || (NOTE_P (insn) | |
13099 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
13100 | fputs ("\tnop\n", file); | |
13101 | } | |
13102 | #endif | |
13103 | ||
9b30bae2 | 13104 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
13105 | on its format. |
13106 | ||
13107 | We don't output a traceback table if -finhibit-size-directive was | |
13108 | used. The documentation for -finhibit-size-directive reads | |
13109 | ``don't output a @code{.size} assembler directive, or anything | |
13110 | else that would cause trouble if the function is split in the | |
13111 | middle, and the two halves are placed at locations far apart in | |
13112 | memory.'' The traceback table has this property, since it | |
13113 | includes the offset from the start of the function to the | |
4d30c363 MM |
13114 | traceback table itself. |
13115 | ||
13116 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a | 13117 | different traceback table. */ |
57ac7be9 AM |
13118 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive |
13119 | && rs6000_traceback != traceback_none) | |
9b30bae2 | 13120 | { |
69c75916 | 13121 | const char *fname = NULL; |
3ac88239 | 13122 | const char *language_string = lang_hooks.name; |
6041bf2f | 13123 | int fixed_parms = 0, float_parms = 0, parm_info = 0; |
314fc5a9 | 13124 | int i; |
57ac7be9 AM |
13125 | int optional_tbtab; |
13126 | ||
13127 | if (rs6000_traceback == traceback_full) | |
13128 | optional_tbtab = 1; | |
13129 | else if (rs6000_traceback == traceback_part) | |
13130 | optional_tbtab = 0; | |
13131 | else | |
13132 | optional_tbtab = !optimize_size && !TARGET_ELF; | |
314fc5a9 | 13133 | |
69c75916 AM |
13134 | if (optional_tbtab) |
13135 | { | |
13136 | fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
13137 | while (*fname == '.') /* V.4 encodes . in the name */ | |
13138 | fname++; | |
13139 | ||
13140 | /* Need label immediately before tbtab, so we can compute | |
13141 | its offset from the function start. */ | |
13142 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
13143 | ASM_OUTPUT_LABEL (file, fname); | |
13144 | } | |
314fc5a9 ILT |
13145 | |
13146 | /* The .tbtab pseudo-op can only be used for the first eight | |
13147 | expressions, since it can't handle the possibly variable | |
13148 | length fields that follow. However, if you omit the optional | |
13149 | fields, the assembler outputs zeros for all optional fields | |
13150 | anyways, giving each variable length field is minimum length | |
13151 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
13152 | pseudo-op at all. */ | |
13153 | ||
13154 | /* An all-zero word flags the start of the tbtab, for debuggers | |
13155 | that have to find it by searching forward from the entry | |
13156 | point or from the current pc. */ | |
19d2d16f | 13157 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
13158 | |
13159 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 13160 | fputs ("\t.byte 0,", file); |
314fc5a9 | 13161 | |
5fc921c1 DE |
13162 | /* Language type. Unfortunately, there does not seem to be any |
13163 | official way to discover the language being compiled, so we | |
13164 | use language_string. | |
13165 | C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9. | |
13166 | Java is 13. Objective-C is 14. */ | |
13167 | if (! strcmp (language_string, "GNU C")) | |
314fc5a9 | 13168 | i = 0; |
6de9cd9a DN |
13169 | else if (! strcmp (language_string, "GNU F77") |
13170 | || ! strcmp (language_string, "GNU F95")) | |
314fc5a9 | 13171 | i = 1; |
8b83775b | 13172 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 | 13173 | i = 2; |
5fc921c1 DE |
13174 | else if (! strcmp (language_string, "GNU Ada")) |
13175 | i = 3; | |
314fc5a9 ILT |
13176 | else if (! strcmp (language_string, "GNU C++")) |
13177 | i = 9; | |
9517ead8 AG |
13178 | else if (! strcmp (language_string, "GNU Java")) |
13179 | i = 13; | |
5fc921c1 DE |
13180 | else if (! strcmp (language_string, "GNU Objective-C")) |
13181 | i = 14; | |
314fc5a9 ILT |
13182 | else |
13183 | abort (); | |
13184 | fprintf (file, "%d,", i); | |
13185 | ||
13186 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
13187 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
13188 | from start of procedure stored in tbtab, internal function, function | |
13189 | has controlled storage, function has no toc, function uses fp, | |
13190 | function logs/aborts fp operations. */ | |
13191 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
6041bf2f DE |
13192 | fprintf (file, "%d,", |
13193 | (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1)); | |
314fc5a9 ILT |
13194 | |
13195 | /* 6 bitfields: function is interrupt handler, name present in | |
13196 | proc table, function calls alloca, on condition directives | |
13197 | (controls stack walks, 3 bits), saves condition reg, saves | |
13198 | link reg. */ | |
13199 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
13200 | set up as a frame pointer, even when there is no alloca call. */ | |
13201 | fprintf (file, "%d,", | |
6041bf2f DE |
13202 | ((optional_tbtab << 6) |
13203 | | ((optional_tbtab & frame_pointer_needed) << 5) | |
13204 | | (info->cr_save_p << 1) | |
13205 | | (info->lr_save_p))); | |
314fc5a9 | 13206 | |
6041bf2f | 13207 | /* 3 bitfields: saves backchain, fixup code, number of fpr saved |
314fc5a9 ILT |
13208 | (6 bits). */ |
13209 | fprintf (file, "%d,", | |
4697a36c | 13210 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
13211 | |
13212 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
13213 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
13214 | ||
6041bf2f DE |
13215 | if (optional_tbtab) |
13216 | { | |
13217 | /* Compute the parameter info from the function decl argument | |
13218 | list. */ | |
13219 | tree decl; | |
13220 | int next_parm_info_bit = 31; | |
314fc5a9 | 13221 | |
6041bf2f DE |
13222 | for (decl = DECL_ARGUMENTS (current_function_decl); |
13223 | decl; decl = TREE_CHAIN (decl)) | |
13224 | { | |
13225 | rtx parameter = DECL_INCOMING_RTL (decl); | |
13226 | enum machine_mode mode = GET_MODE (parameter); | |
314fc5a9 | 13227 | |
6041bf2f DE |
13228 | if (GET_CODE (parameter) == REG) |
13229 | { | |
13230 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
13231 | { | |
13232 | int bits; | |
13233 | ||
13234 | float_parms++; | |
13235 | ||
13236 | if (mode == SFmode) | |
13237 | bits = 0x2; | |
fcce224d | 13238 | else if (mode == DFmode || mode == TFmode) |
6041bf2f DE |
13239 | bits = 0x3; |
13240 | else | |
13241 | abort (); | |
13242 | ||
13243 | /* If only one bit will fit, don't or in this entry. */ | |
13244 | if (next_parm_info_bit > 0) | |
13245 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
13246 | next_parm_info_bit -= 2; | |
13247 | } | |
13248 | else | |
13249 | { | |
13250 | fixed_parms += ((GET_MODE_SIZE (mode) | |
13251 | + (UNITS_PER_WORD - 1)) | |
13252 | / UNITS_PER_WORD); | |
13253 | next_parm_info_bit -= 1; | |
13254 | } | |
13255 | } | |
13256 | } | |
13257 | } | |
314fc5a9 ILT |
13258 | |
13259 | /* Number of fixed point parameters. */ | |
13260 | /* This is actually the number of words of fixed point parameters; thus | |
13261 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
13262 | fprintf (file, "%d,", fixed_parms); | |
13263 | ||
13264 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
13265 | all on stack. */ | |
13266 | /* This is actually the number of fp registers that hold parameters; | |
13267 | and thus the maximum value is 13. */ | |
13268 | /* Set parameters on stack bit if parameters are not in their original | |
13269 | registers, regardless of whether they are on the stack? Xlc | |
13270 | seems to set the bit when not optimizing. */ | |
13271 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
13272 | ||
6041bf2f DE |
13273 | if (! optional_tbtab) |
13274 | return; | |
13275 | ||
314fc5a9 ILT |
13276 | /* Optional fields follow. Some are variable length. */ |
13277 | ||
13278 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
13279 | 11 double float. */ | |
13280 | /* There is an entry for each parameter in a register, in the order that | |
13281 | they occur in the parameter list. Any intervening arguments on the | |
13282 | stack are ignored. If the list overflows a long (max possible length | |
13283 | 34 bits) then completely leave off all elements that don't fit. */ | |
13284 | /* Only emit this long if there was at least one parameter. */ | |
13285 | if (fixed_parms || float_parms) | |
13286 | fprintf (file, "\t.long %d\n", parm_info); | |
13287 | ||
13288 | /* Offset from start of code to tb table. */ | |
19d2d16f | 13289 | fputs ("\t.long ", file); |
314fc5a9 | 13290 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
54ee9799 DE |
13291 | #if TARGET_AIX |
13292 | RS6000_OUTPUT_BASENAME (file, fname); | |
13293 | #else | |
9ebbca7d | 13294 | assemble_name (file, fname); |
54ee9799 | 13295 | #endif |
19d2d16f | 13296 | fputs ("-.", file); |
54ee9799 DE |
13297 | #if TARGET_AIX |
13298 | RS6000_OUTPUT_BASENAME (file, fname); | |
13299 | #else | |
9ebbca7d | 13300 | assemble_name (file, fname); |
54ee9799 | 13301 | #endif |
19d2d16f | 13302 | putc ('\n', file); |
314fc5a9 ILT |
13303 | |
13304 | /* Interrupt handler mask. */ | |
13305 | /* Omit this long, since we never set the interrupt handler bit | |
13306 | above. */ | |
13307 | ||
13308 | /* Number of CTL (controlled storage) anchors. */ | |
13309 | /* Omit this long, since the has_ctl bit is never set above. */ | |
13310 | ||
13311 | /* Displacement into stack of each CTL anchor. */ | |
13312 | /* Omit this list of longs, because there are no CTL anchors. */ | |
13313 | ||
13314 | /* Length of function name. */ | |
69c75916 AM |
13315 | if (*fname == '*') |
13316 | ++fname; | |
296b8152 | 13317 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
13318 | |
13319 | /* Function name. */ | |
13320 | assemble_string (fname, strlen (fname)); | |
13321 | ||
13322 | /* Register for alloca automatic storage; this is always reg 31. | |
13323 | Only emit this if the alloca bit was set above. */ | |
13324 | if (frame_pointer_needed) | |
19d2d16f | 13325 | fputs ("\t.byte 31\n", file); |
b1765bde DE |
13326 | |
13327 | fputs ("\t.align 2\n", file); | |
9b30bae2 | 13328 | } |
9878760c | 13329 | } |
17167fd8 | 13330 | \f |
a4f6c312 SS |
13331 | /* A C compound statement that outputs the assembler code for a thunk |
13332 | function, used to implement C++ virtual function calls with | |
13333 | multiple inheritance. The thunk acts as a wrapper around a virtual | |
13334 | function, adjusting the implicit object parameter before handing | |
13335 | control off to the real function. | |
13336 | ||
13337 | First, emit code to add the integer DELTA to the location that | |
13338 | contains the incoming first argument. Assume that this argument | |
13339 | contains a pointer, and is the one used to pass the `this' pointer | |
13340 | in C++. This is the incoming argument *before* the function | |
13341 | prologue, e.g. `%o0' on a sparc. The addition must preserve the | |
13342 | values of all other incoming arguments. | |
17167fd8 MM |
13343 | |
13344 | After the addition, emit code to jump to FUNCTION, which is a | |
a4f6c312 SS |
13345 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does |
13346 | not touch the return address. Hence returning from FUNCTION will | |
13347 | return to whoever called the current `thunk'. | |
17167fd8 | 13348 | |
a4f6c312 SS |
13349 | The effect must be as if FUNCTION had been called directly with the |
13350 | adjusted first argument. This macro is responsible for emitting | |
13351 | all of the code for a thunk function; output_function_prologue() | |
13352 | and output_function_epilogue() are not invoked. | |
17167fd8 | 13353 | |
a4f6c312 SS |
13354 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already |
13355 | been extracted from it.) It might possibly be useful on some | |
13356 | targets, but probably not. | |
17167fd8 | 13357 | |
a4f6c312 SS |
13358 | If you do not define this macro, the target-independent code in the |
13359 | C++ frontend will generate a less efficient heavyweight thunk that | |
13360 | calls FUNCTION instead of jumping to it. The generic approach does | |
13361 | not support varargs. */ | |
17167fd8 | 13362 | |
3961e8fe | 13363 | static void |
a2369ed3 DJ |
13364 | rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, |
13365 | HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, | |
13366 | tree function) | |
17167fd8 | 13367 | { |
5b71a4e7 | 13368 | rtx this, insn, funexp; |
17167fd8 | 13369 | |
5b71a4e7 | 13370 | reload_completed = 1; |
fe3ad572 | 13371 | epilogue_completed = 1; |
5b71a4e7 | 13372 | no_new_pseudos = 1; |
56a7189a | 13373 | |
5b71a4e7 | 13374 | /* Mark the end of the (empty) prologue. */ |
2e040219 | 13375 | emit_note (NOTE_INSN_PROLOGUE_END); |
17167fd8 | 13376 | |
5b71a4e7 DE |
13377 | /* Find the "this" pointer. If the function returns a structure, |
13378 | the structure return pointer is in r3. */ | |
61f71b34 | 13379 | if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) |
5b71a4e7 | 13380 | this = gen_rtx_REG (Pmode, 4); |
56a7189a | 13381 | else |
5b71a4e7 | 13382 | this = gen_rtx_REG (Pmode, 3); |
17167fd8 | 13383 | |
5b71a4e7 DE |
13384 | /* Apply the constant offset, if required. */ |
13385 | if (delta) | |
13386 | { | |
13387 | rtx delta_rtx = GEN_INT (delta); | |
13388 | emit_insn (TARGET_32BIT | |
13389 | ? gen_addsi3 (this, this, delta_rtx) | |
13390 | : gen_adddi3 (this, this, delta_rtx)); | |
17167fd8 MM |
13391 | } |
13392 | ||
5b71a4e7 DE |
13393 | /* Apply the offset from the vtable, if required. */ |
13394 | if (vcall_offset) | |
17167fd8 | 13395 | { |
5b71a4e7 DE |
13396 | rtx vcall_offset_rtx = GEN_INT (vcall_offset); |
13397 | rtx tmp = gen_rtx_REG (Pmode, 12); | |
17167fd8 | 13398 | |
5b71a4e7 | 13399 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, this)); |
eeff9307 JJ |
13400 | if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000) |
13401 | { | |
13402 | emit_insn (TARGET_32BIT | |
13403 | ? gen_addsi3 (tmp, tmp, vcall_offset_rtx) | |
13404 | : gen_adddi3 (tmp, tmp, vcall_offset_rtx)); | |
13405 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
13406 | } | |
13407 | else | |
13408 | { | |
13409 | rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx); | |
13410 | ||
13411 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc)); | |
13412 | } | |
5b71a4e7 DE |
13413 | emit_insn (TARGET_32BIT |
13414 | ? gen_addsi3 (this, this, tmp) | |
13415 | : gen_adddi3 (this, this, tmp)); | |
17167fd8 MM |
13416 | } |
13417 | ||
5b71a4e7 DE |
13418 | /* Generate a tail call to the target function. */ |
13419 | if (!TREE_USED (function)) | |
13420 | { | |
13421 | assemble_external (function); | |
13422 | TREE_USED (function) = 1; | |
13423 | } | |
13424 | funexp = XEXP (DECL_RTL (function), 0); | |
5b71a4e7 | 13425 | funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); |
ee890fe2 SS |
13426 | |
13427 | #if TARGET_MACHO | |
ab82a49f | 13428 | if (MACHOPIC_INDIRECT) |
5b71a4e7 | 13429 | funexp = machopic_indirect_call_target (funexp); |
ee890fe2 | 13430 | #endif |
5b71a4e7 DE |
13431 | |
13432 | /* gen_sibcall expects reload to convert scratch pseudo to LR so we must | |
13433 | generate sibcall RTL explicitly to avoid constraint abort. */ | |
13434 | insn = emit_call_insn ( | |
13435 | gen_rtx_PARALLEL (VOIDmode, | |
13436 | gen_rtvec (4, | |
13437 | gen_rtx_CALL (VOIDmode, | |
13438 | funexp, const0_rtx), | |
13439 | gen_rtx_USE (VOIDmode, const0_rtx), | |
13440 | gen_rtx_USE (VOIDmode, | |
13441 | gen_rtx_REG (SImode, | |
13442 | LINK_REGISTER_REGNUM)), | |
13443 | gen_rtx_RETURN (VOIDmode)))); | |
13444 | SIBLING_CALL_P (insn) = 1; | |
13445 | emit_barrier (); | |
13446 | ||
13447 | /* Run just enough of rest_of_compilation to get the insns emitted. | |
13448 | There's not really enough bulk here to make other passes such as | |
13449 | instruction scheduling worth while. Note that use_thunk calls | |
13450 | assemble_start_function and assemble_end_function. */ | |
13451 | insn = get_insns (); | |
a2855205 | 13452 | insn_locators_initialize (); |
5b71a4e7 DE |
13453 | shorten_branches (insn); |
13454 | final_start_function (insn, file, 1); | |
13455 | final (insn, file, 1, 0); | |
13456 | final_end_function (); | |
13457 | ||
13458 | reload_completed = 0; | |
fe3ad572 | 13459 | epilogue_completed = 0; |
5b71a4e7 | 13460 | no_new_pseudos = 0; |
9ebbca7d | 13461 | } |
9ebbca7d GK |
13462 | \f |
13463 | /* A quick summary of the various types of 'constant-pool tables' | |
13464 | under PowerPC: | |
13465 | ||
13466 | Target Flags Name One table per | |
13467 | AIX (none) AIX TOC object file | |
13468 | AIX -mfull-toc AIX TOC object file | |
13469 | AIX -mminimal-toc AIX minimal TOC translation unit | |
13470 | SVR4/EABI (none) SVR4 SDATA object file | |
13471 | SVR4/EABI -fpic SVR4 pic object file | |
13472 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
13473 | SVR4/EABI -mrelocatable EABI TOC function | |
13474 | SVR4/EABI -maix AIX TOC object file | |
13475 | SVR4/EABI -maix -mminimal-toc | |
13476 | AIX minimal TOC translation unit | |
13477 | ||
13478 | Name Reg. Set by entries contains: | |
13479 | made by addrs? fp? sum? | |
13480 | ||
13481 | AIX TOC 2 crt0 as Y option option | |
13482 | AIX minimal TOC 30 prolog gcc Y Y option | |
13483 | SVR4 SDATA 13 crt0 gcc N Y N | |
13484 | SVR4 pic 30 prolog ld Y not yet N | |
13485 | SVR4 PIC 30 prolog gcc Y option option | |
13486 | EABI TOC 30 prolog gcc Y option option | |
13487 | ||
13488 | */ | |
13489 | ||
9ebbca7d GK |
13490 | /* Hash functions for the hash table. */ |
13491 | ||
13492 | static unsigned | |
a2369ed3 | 13493 | rs6000_hash_constant (rtx k) |
9ebbca7d | 13494 | { |
46b33600 RH |
13495 | enum rtx_code code = GET_CODE (k); |
13496 | enum machine_mode mode = GET_MODE (k); | |
13497 | unsigned result = (code << 3) ^ mode; | |
13498 | const char *format; | |
13499 | int flen, fidx; | |
9ebbca7d | 13500 | |
46b33600 RH |
13501 | format = GET_RTX_FORMAT (code); |
13502 | flen = strlen (format); | |
13503 | fidx = 0; | |
9ebbca7d | 13504 | |
46b33600 RH |
13505 | switch (code) |
13506 | { | |
13507 | case LABEL_REF: | |
13508 | return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0)); | |
13509 | ||
13510 | case CONST_DOUBLE: | |
13511 | if (mode != VOIDmode) | |
13512 | return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result; | |
13513 | flen = 2; | |
13514 | break; | |
13515 | ||
13516 | case CODE_LABEL: | |
13517 | fidx = 3; | |
13518 | break; | |
13519 | ||
13520 | default: | |
13521 | break; | |
13522 | } | |
9ebbca7d GK |
13523 | |
13524 | for (; fidx < flen; fidx++) | |
13525 | switch (format[fidx]) | |
13526 | { | |
13527 | case 's': | |
13528 | { | |
13529 | unsigned i, len; | |
13530 | const char *str = XSTR (k, fidx); | |
13531 | len = strlen (str); | |
13532 | result = result * 613 + len; | |
13533 | for (i = 0; i < len; i++) | |
13534 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
13535 | break; |
13536 | } | |
9ebbca7d GK |
13537 | case 'u': |
13538 | case 'e': | |
13539 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
13540 | break; | |
13541 | case 'i': | |
13542 | case 'n': | |
13543 | result = result * 613 + (unsigned) XINT (k, fidx); | |
13544 | break; | |
13545 | case 'w': | |
13546 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
13547 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
13548 | else | |
13549 | { | |
13550 | size_t i; | |
13551 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
13552 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
13553 | >> CHAR_BIT * i); | |
13554 | } | |
13555 | break; | |
09501938 DE |
13556 | case '0': |
13557 | break; | |
9ebbca7d | 13558 | default: |
a4f6c312 | 13559 | abort (); |
9ebbca7d | 13560 | } |
46b33600 | 13561 | |
9ebbca7d GK |
13562 | return result; |
13563 | } | |
13564 | ||
13565 | static unsigned | |
a2369ed3 | 13566 | toc_hash_function (const void *hash_entry) |
9ebbca7d | 13567 | { |
a9098fd0 GK |
13568 | const struct toc_hash_struct *thc = |
13569 | (const struct toc_hash_struct *) hash_entry; | |
13570 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
13571 | } |
13572 | ||
13573 | /* Compare H1 and H2 for equivalence. */ | |
13574 | ||
13575 | static int | |
a2369ed3 | 13576 | toc_hash_eq (const void *h1, const void *h2) |
9ebbca7d GK |
13577 | { |
13578 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
13579 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
13580 | ||
a9098fd0 GK |
13581 | if (((const struct toc_hash_struct *) h1)->key_mode |
13582 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
13583 | return 0; | |
13584 | ||
5692c7bc | 13585 | return rtx_equal_p (r1, r2); |
9ebbca7d GK |
13586 | } |
13587 | ||
28e510bd MM |
13588 | /* These are the names given by the C++ front-end to vtables, and |
13589 | vtable-like objects. Ideally, this logic should not be here; | |
13590 | instead, there should be some programmatic way of inquiring as | |
13591 | to whether or not an object is a vtable. */ | |
13592 | ||
13593 | #define VTABLE_NAME_P(NAME) \ | |
13594 | (strncmp ("_vt.", name, strlen("_vt.")) == 0 \ | |
13595 | || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \ | |
13596 | || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \ | |
26be75db | 13597 | || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \ |
28e510bd MM |
13598 | || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0) |
13599 | ||
13600 | void | |
a2369ed3 | 13601 | rs6000_output_symbol_ref (FILE *file, rtx x) |
28e510bd MM |
13602 | { |
13603 | /* Currently C++ toc references to vtables can be emitted before it | |
13604 | is decided whether the vtable is public or private. If this is | |
13605 | the case, then the linker will eventually complain that there is | |
13606 | a reference to an unknown section. Thus, for vtables only, | |
13607 | we emit the TOC reference to reference the symbol and not the | |
13608 | section. */ | |
13609 | const char *name = XSTR (x, 0); | |
54ee9799 DE |
13610 | |
13611 | if (VTABLE_NAME_P (name)) | |
13612 | { | |
13613 | RS6000_OUTPUT_BASENAME (file, name); | |
13614 | } | |
13615 | else | |
13616 | assemble_name (file, name); | |
28e510bd MM |
13617 | } |
13618 | ||
a4f6c312 SS |
13619 | /* Output a TOC entry. We derive the entry name from what is being |
13620 | written. */ | |
9878760c RK |
13621 | |
13622 | void | |
a2369ed3 | 13623 | output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode) |
9878760c RK |
13624 | { |
13625 | char buf[256]; | |
3cce094d | 13626 | const char *name = buf; |
ec940faa | 13627 | const char *real_name; |
9878760c RK |
13628 | rtx base = x; |
13629 | int offset = 0; | |
13630 | ||
4697a36c MM |
13631 | if (TARGET_NO_TOC) |
13632 | abort (); | |
13633 | ||
9ebbca7d GK |
13634 | /* When the linker won't eliminate them, don't output duplicate |
13635 | TOC entries (this happens on AIX if there is any kind of TOC, | |
17211ab5 GK |
13636 | and on SVR4 under -fPIC or -mrelocatable). Don't do this for |
13637 | CODE_LABELs. */ | |
13638 | if (TARGET_TOC && GET_CODE (x) != LABEL_REF) | |
9ebbca7d GK |
13639 | { |
13640 | struct toc_hash_struct *h; | |
13641 | void * * found; | |
13642 | ||
17211ab5 | 13643 | /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS |
39e3f58c | 13644 | time because GGC is not initialized at that point. */ |
17211ab5 GK |
13645 | if (toc_hash_table == NULL) |
13646 | toc_hash_table = htab_create_ggc (1021, toc_hash_function, | |
13647 | toc_hash_eq, NULL); | |
13648 | ||
9ebbca7d GK |
13649 | h = ggc_alloc (sizeof (*h)); |
13650 | h->key = x; | |
a9098fd0 | 13651 | h->key_mode = mode; |
9ebbca7d GK |
13652 | h->labelno = labelno; |
13653 | ||
13654 | found = htab_find_slot (toc_hash_table, h, 1); | |
13655 | if (*found == NULL) | |
13656 | *found = h; | |
13657 | else /* This is indeed a duplicate. | |
13658 | Set this label equal to that label. */ | |
13659 | { | |
13660 | fputs ("\t.set ", file); | |
13661 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
13662 | fprintf (file, "%d,", labelno); | |
13663 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
13664 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) | |
13665 | found)->labelno)); | |
13666 | return; | |
13667 | } | |
13668 | } | |
13669 | ||
13670 | /* If we're going to put a double constant in the TOC, make sure it's | |
13671 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
13672 | if (GET_CODE (x) == CONST_DOUBLE |
13673 | && STRICT_ALIGNMENT | |
a9098fd0 | 13674 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
13675 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
13676 | ASM_OUTPUT_ALIGN (file, 3); | |
13677 | } | |
13678 | ||
4977bab6 | 13679 | (*targetm.asm_out.internal_label) (file, "LC", labelno); |
9878760c | 13680 | |
37c37a57 RK |
13681 | /* Handle FP constants specially. Note that if we have a minimal |
13682 | TOC, things we put here aren't actually in the TOC, so we can allow | |
13683 | FP constants. */ | |
fcce224d DE |
13684 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode) |
13685 | { | |
13686 | REAL_VALUE_TYPE rv; | |
13687 | long k[4]; | |
13688 | ||
13689 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
13690 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
13691 | ||
13692 | if (TARGET_64BIT) | |
13693 | { | |
13694 | if (TARGET_MINIMAL_TOC) | |
13695 | fputs (DOUBLE_INT_ASM_OP, file); | |
13696 | else | |
13697 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
13698 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13699 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13700 | fprintf (file, "0x%lx%08lx,0x%lx%08lx\n", | |
13701 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13702 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13703 | return; | |
13704 | } | |
13705 | else | |
13706 | { | |
13707 | if (TARGET_MINIMAL_TOC) | |
13708 | fputs ("\t.long ", file); | |
13709 | else | |
13710 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
13711 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13712 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13713 | fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n", | |
13714 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13715 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13716 | return; | |
13717 | } | |
13718 | } | |
13719 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) | |
9878760c | 13720 | { |
042259f2 DE |
13721 | REAL_VALUE_TYPE rv; |
13722 | long k[2]; | |
0adc764e | 13723 | |
042259f2 DE |
13724 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
13725 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 13726 | |
13ded975 DE |
13727 | if (TARGET_64BIT) |
13728 | { | |
13729 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13730 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 13731 | else |
2f0552b6 AM |
13732 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
13733 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13734 | fprintf (file, "0x%lx%08lx\n", | |
13735 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
13736 | return; |
13737 | } | |
1875cc88 | 13738 | else |
13ded975 DE |
13739 | { |
13740 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13741 | fputs ("\t.long ", file); |
13ded975 | 13742 | else |
2f0552b6 AM |
13743 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
13744 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13745 | fprintf (file, "0x%lx,0x%lx\n", | |
13746 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
13747 | return; |
13748 | } | |
9878760c | 13749 | } |
a9098fd0 | 13750 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 13751 | { |
042259f2 DE |
13752 | REAL_VALUE_TYPE rv; |
13753 | long l; | |
9878760c | 13754 | |
042259f2 DE |
13755 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
13756 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
13757 | ||
31bfaa0b DE |
13758 | if (TARGET_64BIT) |
13759 | { | |
13760 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13761 | fputs (DOUBLE_INT_ASM_OP, file); |
31bfaa0b | 13762 | else |
2f0552b6 AM |
13763 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
13764 | fprintf (file, "0x%lx00000000\n", l & 0xffffffff); | |
31bfaa0b DE |
13765 | return; |
13766 | } | |
042259f2 | 13767 | else |
31bfaa0b DE |
13768 | { |
13769 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13770 | fputs ("\t.long ", file); |
31bfaa0b | 13771 | else |
2f0552b6 AM |
13772 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
13773 | fprintf (file, "0x%lx\n", l & 0xffffffff); | |
31bfaa0b DE |
13774 | return; |
13775 | } | |
042259f2 | 13776 | } |
f176e826 | 13777 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 13778 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 13779 | { |
e2c953b6 | 13780 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
13781 | HOST_WIDE_INT high; |
13782 | ||
13783 | if (GET_CODE (x) == CONST_DOUBLE) | |
13784 | { | |
13785 | low = CONST_DOUBLE_LOW (x); | |
13786 | high = CONST_DOUBLE_HIGH (x); | |
13787 | } | |
13788 | else | |
13789 | #if HOST_BITS_PER_WIDE_INT == 32 | |
13790 | { | |
13791 | low = INTVAL (x); | |
0858c623 | 13792 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
13793 | } |
13794 | #else | |
13795 | { | |
0858c623 | 13796 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
13797 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
13798 | } | |
13799 | #endif | |
9878760c | 13800 | |
a9098fd0 GK |
13801 | /* TOC entries are always Pmode-sized, but since this |
13802 | is a bigendian machine then if we're putting smaller | |
13803 | integer constants in the TOC we have to pad them. | |
13804 | (This is still a win over putting the constants in | |
13805 | a separate constant pool, because then we'd have | |
02a4ec28 FS |
13806 | to have both a TOC entry _and_ the actual constant.) |
13807 | ||
13808 | For a 32-bit target, CONST_INT values are loaded and shifted | |
13809 | entirely within `low' and can be stored in one TOC entry. */ | |
13810 | ||
13811 | if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
a9098fd0 | 13812 | abort ();/* It would be easy to make this work, but it doesn't now. */ |
02a4ec28 FS |
13813 | |
13814 | if (POINTER_SIZE > GET_MODE_BITSIZE (mode)) | |
fb52d8de AM |
13815 | { |
13816 | #if HOST_BITS_PER_WIDE_INT == 32 | |
13817 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), | |
13818 | POINTER_SIZE, &low, &high, 0); | |
13819 | #else | |
13820 | low |= high << 32; | |
13821 | low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode); | |
13822 | high = (HOST_WIDE_INT) low >> 32; | |
13823 | low &= 0xffffffff; | |
13824 | #endif | |
13825 | } | |
a9098fd0 | 13826 | |
13ded975 DE |
13827 | if (TARGET_64BIT) |
13828 | { | |
13829 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13830 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 13831 | else |
2f0552b6 AM |
13832 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
13833 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13834 | fprintf (file, "0x%lx%08lx\n", | |
13835 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13ded975 DE |
13836 | return; |
13837 | } | |
1875cc88 | 13838 | else |
13ded975 | 13839 | { |
02a4ec28 FS |
13840 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) |
13841 | { | |
13842 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13843 | fputs ("\t.long ", file); |
02a4ec28 | 13844 | else |
2bfcf297 | 13845 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
2f0552b6 AM |
13846 | (long) high & 0xffffffff, (long) low & 0xffffffff); |
13847 | fprintf (file, "0x%lx,0x%lx\n", | |
13848 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
02a4ec28 | 13849 | } |
13ded975 | 13850 | else |
02a4ec28 FS |
13851 | { |
13852 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13853 | fputs ("\t.long ", file); |
02a4ec28 | 13854 | else |
2f0552b6 AM |
13855 | fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff); |
13856 | fprintf (file, "0x%lx\n", (long) low & 0xffffffff); | |
02a4ec28 | 13857 | } |
13ded975 DE |
13858 | return; |
13859 | } | |
9878760c RK |
13860 | } |
13861 | ||
13862 | if (GET_CODE (x) == CONST) | |
13863 | { | |
2bfcf297 DB |
13864 | if (GET_CODE (XEXP (x, 0)) != PLUS) |
13865 | abort (); | |
13866 | ||
9878760c RK |
13867 | base = XEXP (XEXP (x, 0), 0); |
13868 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
13869 | } | |
13870 | ||
13871 | if (GET_CODE (base) == SYMBOL_REF) | |
13872 | name = XSTR (base, 0); | |
13873 | else if (GET_CODE (base) == LABEL_REF) | |
13874 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
13875 | else if (GET_CODE (base) == CODE_LABEL) | |
13876 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
13877 | else | |
13878 | abort (); | |
13879 | ||
772c5265 | 13880 | real_name = (*targetm.strip_name_encoding) (name); |
1875cc88 | 13881 | if (TARGET_MINIMAL_TOC) |
2bfcf297 | 13882 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); |
1875cc88 JW |
13883 | else |
13884 | { | |
b6c9286a | 13885 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 13886 | |
1875cc88 JW |
13887 | if (offset < 0) |
13888 | fprintf (file, ".N%d", - offset); | |
13889 | else if (offset) | |
13890 | fprintf (file, ".P%d", offset); | |
9878760c | 13891 | |
19d2d16f | 13892 | fputs ("[TC],", file); |
1875cc88 | 13893 | } |
581bc4de MM |
13894 | |
13895 | /* Currently C++ toc references to vtables can be emitted before it | |
13896 | is decided whether the vtable is public or private. If this is | |
13897 | the case, then the linker will eventually complain that there is | |
13898 | a TOC reference to an unknown section. Thus, for vtables only, | |
13899 | we emit the TOC reference to reference the symbol and not the | |
13900 | section. */ | |
28e510bd | 13901 | if (VTABLE_NAME_P (name)) |
581bc4de | 13902 | { |
54ee9799 | 13903 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
13904 | if (offset < 0) |
13905 | fprintf (file, "%d", offset); | |
13906 | else if (offset > 0) | |
13907 | fprintf (file, "+%d", offset); | |
13908 | } | |
13909 | else | |
13910 | output_addr_const (file, x); | |
19d2d16f | 13911 | putc ('\n', file); |
9878760c RK |
13912 | } |
13913 | \f | |
13914 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
13915 | starting at P to FILE. | |
13916 | ||
13917 | On the RS/6000, we have to do this using the .byte operation and | |
13918 | write out special characters outside the quoted string. | |
13919 | Also, the assembler is broken; very long strings are truncated, | |
a4f6c312 | 13920 | so we must artificially break them up early. */ |
9878760c RK |
13921 | |
13922 | void | |
a2369ed3 | 13923 | output_ascii (FILE *file, const char *p, int n) |
9878760c RK |
13924 | { |
13925 | char c; | |
13926 | int i, count_string; | |
d330fd93 KG |
13927 | const char *for_string = "\t.byte \""; |
13928 | const char *for_decimal = "\t.byte "; | |
13929 | const char *to_close = NULL; | |
9878760c RK |
13930 | |
13931 | count_string = 0; | |
13932 | for (i = 0; i < n; i++) | |
13933 | { | |
13934 | c = *p++; | |
13935 | if (c >= ' ' && c < 0177) | |
13936 | { | |
13937 | if (for_string) | |
13938 | fputs (for_string, file); | |
13939 | putc (c, file); | |
13940 | ||
13941 | /* Write two quotes to get one. */ | |
13942 | if (c == '"') | |
13943 | { | |
13944 | putc (c, file); | |
13945 | ++count_string; | |
13946 | } | |
13947 | ||
13948 | for_string = NULL; | |
13949 | for_decimal = "\"\n\t.byte "; | |
13950 | to_close = "\"\n"; | |
13951 | ++count_string; | |
13952 | ||
13953 | if (count_string >= 512) | |
13954 | { | |
13955 | fputs (to_close, file); | |
13956 | ||
13957 | for_string = "\t.byte \""; | |
13958 | for_decimal = "\t.byte "; | |
13959 | to_close = NULL; | |
13960 | count_string = 0; | |
13961 | } | |
13962 | } | |
13963 | else | |
13964 | { | |
13965 | if (for_decimal) | |
13966 | fputs (for_decimal, file); | |
13967 | fprintf (file, "%d", c); | |
13968 | ||
13969 | for_string = "\n\t.byte \""; | |
13970 | for_decimal = ", "; | |
13971 | to_close = "\n"; | |
13972 | count_string = 0; | |
13973 | } | |
13974 | } | |
13975 | ||
13976 | /* Now close the string if we have written one. Then end the line. */ | |
13977 | if (to_close) | |
9ebbca7d | 13978 | fputs (to_close, file); |
9878760c RK |
13979 | } |
13980 | \f | |
13981 | /* Generate a unique section name for FILENAME for a section type | |
13982 | represented by SECTION_DESC. Output goes into BUF. | |
13983 | ||
13984 | SECTION_DESC can be any string, as long as it is different for each | |
13985 | possible section type. | |
13986 | ||
13987 | We name the section in the same manner as xlc. The name begins with an | |
13988 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
13989 | names) with the last period replaced by the string SECTION_DESC. If |
13990 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
13991 | the name. */ | |
9878760c RK |
13992 | |
13993 | void | |
a2369ed3 DJ |
13994 | rs6000_gen_section_name (char **buf, const char *filename, |
13995 | const char *section_desc) | |
9878760c | 13996 | { |
9ebbca7d | 13997 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
13998 | char *p; |
13999 | int len; | |
9878760c RK |
14000 | |
14001 | after_last_slash = filename; | |
14002 | for (q = filename; *q; q++) | |
11e5fe42 RK |
14003 | { |
14004 | if (*q == '/') | |
14005 | after_last_slash = q + 1; | |
14006 | else if (*q == '.') | |
14007 | last_period = q; | |
14008 | } | |
9878760c | 14009 | |
11e5fe42 | 14010 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
6d9f628e | 14011 | *buf = (char *) xmalloc (len); |
9878760c RK |
14012 | |
14013 | p = *buf; | |
14014 | *p++ = '_'; | |
14015 | ||
14016 | for (q = after_last_slash; *q; q++) | |
14017 | { | |
11e5fe42 | 14018 | if (q == last_period) |
9878760c RK |
14019 | { |
14020 | strcpy (p, section_desc); | |
14021 | p += strlen (section_desc); | |
e3981aab | 14022 | break; |
9878760c RK |
14023 | } |
14024 | ||
e9a780ec | 14025 | else if (ISALNUM (*q)) |
9878760c RK |
14026 | *p++ = *q; |
14027 | } | |
14028 | ||
11e5fe42 | 14029 | if (last_period == 0) |
9878760c RK |
14030 | strcpy (p, section_desc); |
14031 | else | |
14032 | *p = '\0'; | |
14033 | } | |
e165f3f0 | 14034 | \f |
a4f6c312 | 14035 | /* Emit profile function. */ |
411707f4 | 14036 | |
411707f4 | 14037 | void |
a2369ed3 | 14038 | output_profile_hook (int labelno ATTRIBUTE_UNUSED) |
411707f4 | 14039 | { |
ffcfcb5f AM |
14040 | if (TARGET_PROFILE_KERNEL) |
14041 | return; | |
14042 | ||
8480e480 CC |
14043 | if (DEFAULT_ABI == ABI_AIX) |
14044 | { | |
9739c90c JJ |
14045 | #ifndef NO_PROFILE_COUNTERS |
14046 | # define NO_PROFILE_COUNTERS 0 | |
14047 | #endif | |
14048 | if (NO_PROFILE_COUNTERS) | |
14049 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0); | |
14050 | else | |
14051 | { | |
14052 | char buf[30]; | |
14053 | const char *label_name; | |
14054 | rtx fun; | |
411707f4 | 14055 | |
9739c90c JJ |
14056 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
14057 | label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf)); | |
14058 | fun = gen_rtx_SYMBOL_REF (Pmode, label_name); | |
411707f4 | 14059 | |
9739c90c JJ |
14060 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1, |
14061 | fun, Pmode); | |
14062 | } | |
8480e480 | 14063 | } |
ee890fe2 SS |
14064 | else if (DEFAULT_ABI == ABI_DARWIN) |
14065 | { | |
d5fa86ba | 14066 | const char *mcount_name = RS6000_MCOUNT; |
ee890fe2 SS |
14067 | int caller_addr_regno = LINK_REGISTER_REGNUM; |
14068 | ||
14069 | /* Be conservative and always set this, at least for now. */ | |
14070 | current_function_uses_pic_offset_table = 1; | |
14071 | ||
14072 | #if TARGET_MACHO | |
14073 | /* For PIC code, set up a stub and collect the caller's address | |
14074 | from r0, which is where the prologue puts it. */ | |
ab82a49f | 14075 | if (MACHOPIC_INDIRECT) |
ee890fe2 SS |
14076 | { |
14077 | mcount_name = machopic_stub_name (mcount_name); | |
14078 | if (current_function_uses_pic_offset_table) | |
14079 | caller_addr_regno = 0; | |
14080 | } | |
14081 | #endif | |
14082 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name), | |
14083 | 0, VOIDmode, 1, | |
14084 | gen_rtx_REG (Pmode, caller_addr_regno), Pmode); | |
14085 | } | |
411707f4 CC |
14086 | } |
14087 | ||
a4f6c312 | 14088 | /* Write function profiler code. */ |
e165f3f0 RK |
14089 | |
14090 | void | |
a2369ed3 | 14091 | output_function_profiler (FILE *file, int labelno) |
e165f3f0 | 14092 | { |
3daf36a4 | 14093 | char buf[100]; |
09eeeacb | 14094 | int save_lr = 8; |
e165f3f0 | 14095 | |
38c1f2d7 | 14096 | switch (DEFAULT_ABI) |
3daf36a4 | 14097 | { |
38c1f2d7 MM |
14098 | default: |
14099 | abort (); | |
14100 | ||
14101 | case ABI_V4: | |
09eeeacb | 14102 | save_lr = 4; |
09eeeacb AM |
14103 | if (!TARGET_32BIT) |
14104 | { | |
14105 | warning ("no profiling of 64-bit code for this ABI"); | |
14106 | return; | |
14107 | } | |
ffcfcb5f | 14108 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 MM |
14109 | fprintf (file, "\tmflr %s\n", reg_names[0]); |
14110 | if (flag_pic == 1) | |
14111 | { | |
dfdfa60f | 14112 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
09eeeacb AM |
14113 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
14114 | reg_names[0], save_lr, reg_names[1]); | |
17167fd8 | 14115 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 14116 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 14117 | assemble_name (file, buf); |
17167fd8 | 14118 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 14119 | } |
9ebbca7d | 14120 | else if (flag_pic > 1) |
38c1f2d7 | 14121 | { |
09eeeacb AM |
14122 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
14123 | reg_names[0], save_lr, reg_names[1]); | |
9ebbca7d GK |
14124 | /* Now, we need to get the address of the label. */ |
14125 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 14126 | assemble_name (file, buf); |
9ebbca7d GK |
14127 | fputs ("-.\n1:", file); |
14128 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
14129 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", | |
14130 | reg_names[0], reg_names[11]); | |
14131 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
14132 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 14133 | } |
38c1f2d7 MM |
14134 | else |
14135 | { | |
17167fd8 | 14136 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 14137 | assemble_name (file, buf); |
dfdfa60f | 14138 | fputs ("@ha\n", file); |
09eeeacb AM |
14139 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
14140 | reg_names[0], save_lr, reg_names[1]); | |
a260abc9 | 14141 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 14142 | assemble_name (file, buf); |
17167fd8 | 14143 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
14144 | } |
14145 | ||
50d440bc | 14146 | /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */ |
3b6ce0af DE |
14147 | fprintf (file, "\tbl %s%s\n", |
14148 | RS6000_MCOUNT, flag_pic ? "@plt" : ""); | |
38c1f2d7 MM |
14149 | break; |
14150 | ||
14151 | case ABI_AIX: | |
ee890fe2 | 14152 | case ABI_DARWIN: |
ffcfcb5f AM |
14153 | if (!TARGET_PROFILE_KERNEL) |
14154 | { | |
a3c9585f | 14155 | /* Don't do anything, done in output_profile_hook (). */ |
ffcfcb5f AM |
14156 | } |
14157 | else | |
14158 | { | |
14159 | if (TARGET_32BIT) | |
14160 | abort (); | |
14161 | ||
14162 | asm_fprintf (file, "\tmflr %s\n", reg_names[0]); | |
14163 | asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]); | |
14164 | ||
6de9cd9a | 14165 | if (cfun->static_chain_decl != NULL) |
ffcfcb5f AM |
14166 | { |
14167 | asm_fprintf (file, "\tstd %s,24(%s)\n", | |
14168 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
14169 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
14170 | asm_fprintf (file, "\tld %s,24(%s)\n", | |
14171 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
14172 | } | |
14173 | else | |
14174 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
14175 | } | |
38c1f2d7 MM |
14176 | break; |
14177 | } | |
e165f3f0 | 14178 | } |
a251ffd0 | 14179 | |
b54cf83a DE |
14180 | \f |
14181 | static int | |
863d938c | 14182 | rs6000_use_dfa_pipeline_interface (void) |
b54cf83a DE |
14183 | { |
14184 | return 1; | |
14185 | } | |
14186 | ||
b54cf83a DE |
14187 | /* Power4 load update and store update instructions are cracked into a |
14188 | load or store and an integer insn which are executed in the same cycle. | |
14189 | Branches have their own dispatch slot which does not count against the | |
14190 | GCC issue rate, but it changes the program flow so there are no other | |
14191 | instructions to issue in this cycle. */ | |
14192 | ||
14193 | static int | |
a2369ed3 DJ |
14194 | rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED, |
14195 | int verbose ATTRIBUTE_UNUSED, | |
14196 | rtx insn, int more) | |
b54cf83a DE |
14197 | { |
14198 | if (GET_CODE (PATTERN (insn)) == USE | |
14199 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14200 | return more; | |
14201 | ||
ec507f2d | 14202 | if (rs6000_sched_groups) |
b54cf83a | 14203 | { |
cbe26ab8 DN |
14204 | if (is_microcoded_insn (insn)) |
14205 | return 0; | |
14206 | else if (is_cracked_insn (insn)) | |
14207 | return more > 2 ? more - 2 : 0; | |
b54cf83a | 14208 | } |
165b263e DE |
14209 | |
14210 | return more - 1; | |
b54cf83a DE |
14211 | } |
14212 | ||
a251ffd0 TG |
14213 | /* Adjust the cost of a scheduling dependency. Return the new cost of |
14214 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
14215 | ||
c237e94a | 14216 | static int |
a2369ed3 DJ |
14217 | rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED, |
14218 | int cost) | |
a251ffd0 TG |
14219 | { |
14220 | if (! recog_memoized (insn)) | |
14221 | return 0; | |
14222 | ||
14223 | if (REG_NOTE_KIND (link) != 0) | |
14224 | return 0; | |
14225 | ||
14226 | if (REG_NOTE_KIND (link) == 0) | |
14227 | { | |
ed947a96 DJ |
14228 | /* Data dependency; DEP_INSN writes a register that INSN reads |
14229 | some cycles later. */ | |
14230 | switch (get_attr_type (insn)) | |
14231 | { | |
14232 | case TYPE_JMPREG: | |
309323c2 | 14233 | /* Tell the first scheduling pass about the latency between |
ed947a96 DJ |
14234 | a mtctr and bctr (and mtlr and br/blr). The first |
14235 | scheduling pass will not know about this latency since | |
14236 | the mtctr instruction, which has the latency associated | |
14237 | to it, will be generated by reload. */ | |
309323c2 | 14238 | return TARGET_POWER ? 5 : 4; |
ed947a96 DJ |
14239 | case TYPE_BRANCH: |
14240 | /* Leave some extra cycles between a compare and its | |
14241 | dependent branch, to inhibit expensive mispredicts. */ | |
309323c2 DE |
14242 | if ((rs6000_cpu_attr == CPU_PPC603 |
14243 | || rs6000_cpu_attr == CPU_PPC604 | |
14244 | || rs6000_cpu_attr == CPU_PPC604E | |
14245 | || rs6000_cpu_attr == CPU_PPC620 | |
14246 | || rs6000_cpu_attr == CPU_PPC630 | |
14247 | || rs6000_cpu_attr == CPU_PPC750 | |
14248 | || rs6000_cpu_attr == CPU_PPC7400 | |
14249 | || rs6000_cpu_attr == CPU_PPC7450 | |
ec507f2d DE |
14250 | || rs6000_cpu_attr == CPU_POWER4 |
14251 | || rs6000_cpu_attr == CPU_POWER5) | |
ed947a96 DJ |
14252 | && recog_memoized (dep_insn) |
14253 | && (INSN_CODE (dep_insn) >= 0) | |
b54cf83a DE |
14254 | && (get_attr_type (dep_insn) == TYPE_CMP |
14255 | || get_attr_type (dep_insn) == TYPE_COMPARE | |
ed947a96 | 14256 | || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE |
9259f3b0 DE |
14257 | || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE |
14258 | || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE | |
ed947a96 | 14259 | || get_attr_type (dep_insn) == TYPE_FPCOMPARE |
b54cf83a DE |
14260 | || get_attr_type (dep_insn) == TYPE_CR_LOGICAL |
14261 | || get_attr_type (dep_insn) == TYPE_DELAYED_CR)) | |
ed947a96 DJ |
14262 | return cost + 2; |
14263 | default: | |
14264 | break; | |
14265 | } | |
a251ffd0 TG |
14266 | /* Fall out to return default cost. */ |
14267 | } | |
14268 | ||
14269 | return cost; | |
14270 | } | |
b6c9286a | 14271 | |
cbe26ab8 | 14272 | /* The function returns a true if INSN is microcoded. |
839a4992 | 14273 | Return false otherwise. */ |
cbe26ab8 DN |
14274 | |
14275 | static bool | |
14276 | is_microcoded_insn (rtx insn) | |
14277 | { | |
14278 | if (!insn || !INSN_P (insn) | |
14279 | || GET_CODE (PATTERN (insn)) == USE | |
14280 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14281 | return false; | |
14282 | ||
ec507f2d | 14283 | if (rs6000_sched_groups) |
cbe26ab8 DN |
14284 | { |
14285 | enum attr_type type = get_attr_type (insn); | |
14286 | if (type == TYPE_LOAD_EXT_U | |
14287 | || type == TYPE_LOAD_EXT_UX | |
14288 | || type == TYPE_LOAD_UX | |
14289 | || type == TYPE_STORE_UX | |
14290 | || type == TYPE_MFCR) | |
14291 | return true; | |
14292 | } | |
14293 | ||
14294 | return false; | |
14295 | } | |
14296 | ||
5c425df5 | 14297 | /* The function returns a nonzero value if INSN can be scheduled only |
cbe26ab8 DN |
14298 | as the first insn in a dispatch group ("dispatch-slot restricted"). |
14299 | In this case, the returned value indicates how many dispatch slots | |
14300 | the insn occupies (at the beginning of the group). | |
79ae11c4 DN |
14301 | Return 0 otherwise. */ |
14302 | ||
cbe26ab8 | 14303 | static int |
79ae11c4 DN |
14304 | is_dispatch_slot_restricted (rtx insn) |
14305 | { | |
14306 | enum attr_type type; | |
14307 | ||
ec507f2d | 14308 | if (!rs6000_sched_groups) |
79ae11c4 DN |
14309 | return 0; |
14310 | ||
14311 | if (!insn | |
14312 | || insn == NULL_RTX | |
14313 | || GET_CODE (insn) == NOTE | |
14314 | || GET_CODE (PATTERN (insn)) == USE | |
14315 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14316 | return 0; | |
14317 | ||
14318 | type = get_attr_type (insn); | |
14319 | ||
ec507f2d DE |
14320 | switch (type) |
14321 | { | |
14322 | case TYPE_MFCR: | |
14323 | case TYPE_MFCRF: | |
14324 | case TYPE_MTCR: | |
14325 | case TYPE_DELAYED_CR: | |
14326 | case TYPE_CR_LOGICAL: | |
14327 | case TYPE_MTJMPR: | |
14328 | case TYPE_MFJMPR: | |
14329 | return 1; | |
14330 | case TYPE_IDIV: | |
14331 | case TYPE_LDIV: | |
14332 | return 2; | |
14333 | default: | |
14334 | if (rs6000_cpu == PROCESSOR_POWER5 | |
14335 | && is_cracked_insn (insn)) | |
14336 | return 2; | |
14337 | return 0; | |
14338 | } | |
79ae11c4 DN |
14339 | } |
14340 | ||
cbe26ab8 DN |
14341 | /* The function returns true if INSN is cracked into 2 instructions |
14342 | by the processor (and therefore occupies 2 issue slots). */ | |
14343 | ||
14344 | static bool | |
14345 | is_cracked_insn (rtx insn) | |
14346 | { | |
14347 | if (!insn || !INSN_P (insn) | |
14348 | || GET_CODE (PATTERN (insn)) == USE | |
14349 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14350 | return false; | |
14351 | ||
ec507f2d | 14352 | if (rs6000_sched_groups) |
cbe26ab8 DN |
14353 | { |
14354 | enum attr_type type = get_attr_type (insn); | |
14355 | if (type == TYPE_LOAD_U || type == TYPE_STORE_U | |
14356 | || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U | |
14357 | || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX | |
14358 | || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR | |
14359 | || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE | |
14360 | || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE | |
14361 | || type == TYPE_IDIV || type == TYPE_LDIV | |
14362 | || type == TYPE_INSERT_WORD) | |
14363 | return true; | |
14364 | } | |
14365 | ||
14366 | return false; | |
14367 | } | |
14368 | ||
14369 | /* The function returns true if INSN can be issued only from | |
a3c9585f | 14370 | the branch slot. */ |
cbe26ab8 DN |
14371 | |
14372 | static bool | |
14373 | is_branch_slot_insn (rtx insn) | |
14374 | { | |
14375 | if (!insn || !INSN_P (insn) | |
14376 | || GET_CODE (PATTERN (insn)) == USE | |
14377 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14378 | return false; | |
14379 | ||
ec507f2d | 14380 | if (rs6000_sched_groups) |
cbe26ab8 DN |
14381 | { |
14382 | enum attr_type type = get_attr_type (insn); | |
14383 | if (type == TYPE_BRANCH || type == TYPE_JMPREG) | |
14384 | return true; | |
14385 | return false; | |
14386 | } | |
14387 | ||
14388 | return false; | |
14389 | } | |
79ae11c4 | 14390 | |
a4f6c312 | 14391 | /* A C statement (sans semicolon) to update the integer scheduling |
79ae11c4 DN |
14392 | priority INSN_PRIORITY (INSN). Increase the priority to execute the |
14393 | INSN earlier, reduce the priority to execute INSN later. Do not | |
a4f6c312 SS |
14394 | define this macro if you do not need to adjust the scheduling |
14395 | priorities of insns. */ | |
bef84347 | 14396 | |
c237e94a | 14397 | static int |
a2369ed3 | 14398 | rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority) |
bef84347 | 14399 | { |
a4f6c312 SS |
14400 | /* On machines (like the 750) which have asymmetric integer units, |
14401 | where one integer unit can do multiply and divides and the other | |
14402 | can't, reduce the priority of multiply/divide so it is scheduled | |
14403 | before other integer operations. */ | |
bef84347 VM |
14404 | |
14405 | #if 0 | |
2c3c49de | 14406 | if (! INSN_P (insn)) |
bef84347 VM |
14407 | return priority; |
14408 | ||
14409 | if (GET_CODE (PATTERN (insn)) == USE) | |
14410 | return priority; | |
14411 | ||
14412 | switch (rs6000_cpu_attr) { | |
14413 | case CPU_PPC750: | |
14414 | switch (get_attr_type (insn)) | |
14415 | { | |
14416 | default: | |
14417 | break; | |
14418 | ||
14419 | case TYPE_IMUL: | |
14420 | case TYPE_IDIV: | |
3cb999d8 DE |
14421 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
14422 | priority, priority); | |
bef84347 VM |
14423 | if (priority >= 0 && priority < 0x01000000) |
14424 | priority >>= 3; | |
14425 | break; | |
14426 | } | |
14427 | } | |
14428 | #endif | |
14429 | ||
79ae11c4 DN |
14430 | if (is_dispatch_slot_restricted (insn) |
14431 | && reload_completed | |
14432 | && current_sched_info->sched_max_insns_priority | |
14433 | && rs6000_sched_restricted_insns_priority) | |
14434 | { | |
14435 | ||
14436 | /* Prioritize insns that can be dispatched only in the first dispatch slot. */ | |
14437 | if (rs6000_sched_restricted_insns_priority == 1) | |
14438 | /* Attach highest priority to insn. This means that in | |
14439 | haifa-sched.c:ready_sort(), dispatch-slot restriction considerations | |
14440 | precede 'priority' (critical path) considerations. */ | |
14441 | return current_sched_info->sched_max_insns_priority; | |
14442 | else if (rs6000_sched_restricted_insns_priority == 2) | |
14443 | /* Increase priority of insn by a minimal amount. This means that in | |
14444 | haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations | |
14445 | precede dispatch-slot restriction considerations. */ | |
14446 | return (priority + 1); | |
14447 | } | |
14448 | ||
bef84347 VM |
14449 | return priority; |
14450 | } | |
14451 | ||
a4f6c312 SS |
14452 | /* Return how many instructions the machine can issue per cycle. */ |
14453 | ||
c237e94a | 14454 | static int |
863d938c | 14455 | rs6000_issue_rate (void) |
b6c9286a | 14456 | { |
3317bab1 DE |
14457 | /* Use issue rate of 1 for first scheduling pass to decrease degradation. */ |
14458 | if (!reload_completed) | |
14459 | return 1; | |
14460 | ||
b6c9286a | 14461 | switch (rs6000_cpu_attr) { |
3cb999d8 DE |
14462 | case CPU_RIOS1: /* ? */ |
14463 | case CPU_RS64A: | |
14464 | case CPU_PPC601: /* ? */ | |
ed947a96 | 14465 | case CPU_PPC7450: |
3cb999d8 | 14466 | return 3; |
b54cf83a | 14467 | case CPU_PPC440: |
b6c9286a | 14468 | case CPU_PPC603: |
bef84347 | 14469 | case CPU_PPC750: |
ed947a96 | 14470 | case CPU_PPC7400: |
be12c2b0 | 14471 | case CPU_PPC8540: |
bef84347 | 14472 | return 2; |
3cb999d8 | 14473 | case CPU_RIOS2: |
b6c9286a | 14474 | case CPU_PPC604: |
19684119 | 14475 | case CPU_PPC604E: |
b6c9286a | 14476 | case CPU_PPC620: |
3cb999d8 | 14477 | case CPU_PPC630: |
b6c9286a | 14478 | return 4; |
cbe26ab8 | 14479 | case CPU_POWER4: |
ec507f2d | 14480 | case CPU_POWER5: |
cbe26ab8 | 14481 | return 5; |
b6c9286a MM |
14482 | default: |
14483 | return 1; | |
14484 | } | |
14485 | } | |
14486 | ||
be12c2b0 VM |
14487 | /* Return how many instructions to look ahead for better insn |
14488 | scheduling. */ | |
14489 | ||
14490 | static int | |
863d938c | 14491 | rs6000_use_sched_lookahead (void) |
be12c2b0 VM |
14492 | { |
14493 | if (rs6000_cpu_attr == CPU_PPC8540) | |
14494 | return 4; | |
14495 | return 0; | |
14496 | } | |
14497 | ||
569fa502 DN |
14498 | /* Determine is PAT refers to memory. */ |
14499 | ||
14500 | static bool | |
14501 | is_mem_ref (rtx pat) | |
14502 | { | |
14503 | const char * fmt; | |
14504 | int i, j; | |
14505 | bool ret = false; | |
14506 | ||
14507 | if (GET_CODE (pat) == MEM) | |
14508 | return true; | |
14509 | ||
14510 | /* Recursively process the pattern. */ | |
14511 | fmt = GET_RTX_FORMAT (GET_CODE (pat)); | |
14512 | ||
14513 | for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--) | |
14514 | { | |
14515 | if (fmt[i] == 'e') | |
14516 | ret |= is_mem_ref (XEXP (pat, i)); | |
14517 | else if (fmt[i] == 'E') | |
14518 | for (j = XVECLEN (pat, i) - 1; j >= 0; j--) | |
14519 | ret |= is_mem_ref (XVECEXP (pat, i, j)); | |
14520 | } | |
14521 | ||
14522 | return ret; | |
14523 | } | |
14524 | ||
14525 | /* Determine if PAT is a PATTERN of a load insn. */ | |
14526 | ||
14527 | static bool | |
14528 | is_load_insn1 (rtx pat) | |
14529 | { | |
14530 | if (!pat || pat == NULL_RTX) | |
14531 | return false; | |
14532 | ||
14533 | if (GET_CODE (pat) == SET) | |
14534 | return is_mem_ref (SET_SRC (pat)); | |
14535 | ||
14536 | if (GET_CODE (pat) == PARALLEL) | |
14537 | { | |
14538 | int i; | |
14539 | ||
14540 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
14541 | if (is_load_insn1 (XVECEXP (pat, 0, i))) | |
14542 | return true; | |
14543 | } | |
14544 | ||
14545 | return false; | |
14546 | } | |
14547 | ||
14548 | /* Determine if INSN loads from memory. */ | |
14549 | ||
14550 | static bool | |
14551 | is_load_insn (rtx insn) | |
14552 | { | |
14553 | if (!insn || !INSN_P (insn)) | |
14554 | return false; | |
14555 | ||
14556 | if (GET_CODE (insn) == CALL_INSN) | |
14557 | return false; | |
14558 | ||
14559 | return is_load_insn1 (PATTERN (insn)); | |
14560 | } | |
14561 | ||
14562 | /* Determine if PAT is a PATTERN of a store insn. */ | |
14563 | ||
14564 | static bool | |
14565 | is_store_insn1 (rtx pat) | |
14566 | { | |
14567 | if (!pat || pat == NULL_RTX) | |
14568 | return false; | |
14569 | ||
14570 | if (GET_CODE (pat) == SET) | |
14571 | return is_mem_ref (SET_DEST (pat)); | |
14572 | ||
14573 | if (GET_CODE (pat) == PARALLEL) | |
14574 | { | |
14575 | int i; | |
14576 | ||
14577 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
14578 | if (is_store_insn1 (XVECEXP (pat, 0, i))) | |
14579 | return true; | |
14580 | } | |
14581 | ||
14582 | return false; | |
14583 | } | |
14584 | ||
14585 | /* Determine if INSN stores to memory. */ | |
14586 | ||
14587 | static bool | |
14588 | is_store_insn (rtx insn) | |
14589 | { | |
14590 | if (!insn || !INSN_P (insn)) | |
14591 | return false; | |
14592 | ||
14593 | return is_store_insn1 (PATTERN (insn)); | |
14594 | } | |
14595 | ||
14596 | /* Returns whether the dependence between INSN and NEXT is considered | |
14597 | costly by the given target. */ | |
14598 | ||
14599 | static bool | |
14600 | rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance) | |
14601 | { | |
14602 | /* If the flag is not enbled - no dependence is considered costly; | |
14603 | allow all dependent insns in the same group. | |
14604 | This is the most aggressive option. */ | |
14605 | if (rs6000_sched_costly_dep == no_dep_costly) | |
14606 | return false; | |
14607 | ||
14608 | /* If the flag is set to 1 - a dependence is always considered costly; | |
14609 | do not allow dependent instructions in the same group. | |
14610 | This is the most conservative option. */ | |
14611 | if (rs6000_sched_costly_dep == all_deps_costly) | |
14612 | return true; | |
14613 | ||
14614 | if (rs6000_sched_costly_dep == store_to_load_dep_costly | |
14615 | && is_load_insn (next) | |
14616 | && is_store_insn (insn)) | |
14617 | /* Prevent load after store in the same group. */ | |
14618 | return true; | |
14619 | ||
14620 | if (rs6000_sched_costly_dep == true_store_to_load_dep_costly | |
14621 | && is_load_insn (next) | |
14622 | && is_store_insn (insn) | |
14623 | && (!link || (int) REG_NOTE_KIND (link) == 0)) | |
14624 | /* Prevent load after store in the same group if it is a true dependence. */ | |
14625 | return true; | |
14626 | ||
14627 | /* The flag is set to X; dependences with latency >= X are considered costly, | |
14628 | and will not be scheduled in the same group. */ | |
14629 | if (rs6000_sched_costly_dep <= max_dep_latency | |
14630 | && ((cost - distance) >= (int)rs6000_sched_costly_dep)) | |
14631 | return true; | |
14632 | ||
14633 | return false; | |
14634 | } | |
14635 | ||
cbe26ab8 DN |
14636 | /* Return the next insn after INSN that is found before TAIL is reached, |
14637 | skipping any "non-active" insns - insns that will not actually occupy | |
14638 | an issue slot. Return NULL_RTX if such an insn is not found. */ | |
14639 | ||
14640 | static rtx | |
14641 | get_next_active_insn (rtx insn, rtx tail) | |
14642 | { | |
14643 | rtx next_insn; | |
14644 | ||
14645 | if (!insn || insn == tail) | |
14646 | return NULL_RTX; | |
14647 | ||
14648 | next_insn = NEXT_INSN (insn); | |
14649 | ||
14650 | while (next_insn | |
14651 | && next_insn != tail | |
14652 | && (GET_CODE(next_insn) == NOTE | |
14653 | || GET_CODE (PATTERN (next_insn)) == USE | |
14654 | || GET_CODE (PATTERN (next_insn)) == CLOBBER)) | |
14655 | { | |
14656 | next_insn = NEXT_INSN (next_insn); | |
14657 | } | |
14658 | ||
14659 | if (!next_insn || next_insn == tail) | |
14660 | return NULL_RTX; | |
14661 | ||
14662 | return next_insn; | |
14663 | } | |
14664 | ||
839a4992 | 14665 | /* Return whether the presence of INSN causes a dispatch group termination |
cbe26ab8 DN |
14666 | of group WHICH_GROUP. |
14667 | ||
14668 | If WHICH_GROUP == current_group, this function will return true if INSN | |
14669 | causes the termination of the current group (i.e, the dispatch group to | |
14670 | which INSN belongs). This means that INSN will be the last insn in the | |
14671 | group it belongs to. | |
14672 | ||
14673 | If WHICH_GROUP == previous_group, this function will return true if INSN | |
14674 | causes the termination of the previous group (i.e, the dispatch group that | |
14675 | precedes the group to which INSN belongs). This means that INSN will be | |
14676 | the first insn in the group it belongs to). */ | |
14677 | ||
14678 | static bool | |
14679 | insn_terminates_group_p (rtx insn, enum group_termination which_group) | |
14680 | { | |
14681 | enum attr_type type; | |
14682 | ||
14683 | if (! insn) | |
14684 | return false; | |
569fa502 | 14685 | |
cbe26ab8 DN |
14686 | type = get_attr_type (insn); |
14687 | ||
14688 | if (is_microcoded_insn (insn)) | |
14689 | return true; | |
14690 | ||
14691 | if (which_group == current_group) | |
14692 | { | |
14693 | if (is_branch_slot_insn (insn)) | |
14694 | return true; | |
14695 | return false; | |
14696 | } | |
14697 | else if (which_group == previous_group) | |
14698 | { | |
14699 | if (is_dispatch_slot_restricted (insn)) | |
14700 | return true; | |
14701 | return false; | |
14702 | } | |
14703 | ||
14704 | return false; | |
14705 | } | |
14706 | ||
839a4992 | 14707 | /* Return true if it is recommended to keep NEXT_INSN "far" (in a separate |
cbe26ab8 DN |
14708 | dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */ |
14709 | ||
14710 | static bool | |
14711 | is_costly_group (rtx *group_insns, rtx next_insn) | |
14712 | { | |
14713 | int i; | |
14714 | rtx link; | |
14715 | int cost; | |
14716 | int issue_rate = rs6000_issue_rate (); | |
14717 | ||
14718 | for (i = 0; i < issue_rate; i++) | |
14719 | { | |
14720 | rtx insn = group_insns[i]; | |
14721 | if (!insn) | |
14722 | continue; | |
14723 | for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1)) | |
14724 | { | |
14725 | rtx next = XEXP (link, 0); | |
14726 | if (next == next_insn) | |
14727 | { | |
14728 | cost = insn_cost (insn, link, next_insn); | |
14729 | if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0)) | |
14730 | return true; | |
14731 | } | |
14732 | } | |
14733 | } | |
14734 | ||
14735 | return false; | |
14736 | } | |
14737 | ||
14738 | /* Utility of the function redefine_groups. | |
14739 | Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS | |
14740 | in the same dispatch group. If so, insert nops before NEXT_INSN, in order | |
14741 | to keep it "far" (in a separate group) from GROUP_INSNS, following | |
14742 | one of the following schemes, depending on the value of the flag | |
14743 | -minsert_sched_nops = X: | |
14744 | (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed | |
839a4992 | 14745 | in order to force NEXT_INSN into a separate group. |
cbe26ab8 DN |
14746 | (2) X < sched_finish_regroup_exact: insert exactly X nops. |
14747 | GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop | |
14748 | insertion (has a group just ended, how many vacant issue slots remain in the | |
14749 | last group, and how many dispatch groups were encountered so far). */ | |
14750 | ||
14751 | static int | |
14752 | force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn, | |
14753 | bool *group_end, int can_issue_more, int *group_count) | |
14754 | { | |
14755 | rtx nop; | |
14756 | bool force; | |
14757 | int issue_rate = rs6000_issue_rate (); | |
14758 | bool end = *group_end; | |
14759 | int i; | |
14760 | ||
14761 | if (next_insn == NULL_RTX) | |
14762 | return can_issue_more; | |
14763 | ||
14764 | if (rs6000_sched_insert_nops > sched_finish_regroup_exact) | |
14765 | return can_issue_more; | |
14766 | ||
14767 | force = is_costly_group (group_insns, next_insn); | |
14768 | if (!force) | |
14769 | return can_issue_more; | |
14770 | ||
14771 | if (sched_verbose > 6) | |
14772 | fprintf (dump,"force: group count = %d, can_issue_more = %d\n", | |
14773 | *group_count ,can_issue_more); | |
14774 | ||
14775 | if (rs6000_sched_insert_nops == sched_finish_regroup_exact) | |
14776 | { | |
14777 | if (*group_end) | |
14778 | can_issue_more = 0; | |
14779 | ||
14780 | /* Since only a branch can be issued in the last issue_slot, it is | |
14781 | sufficient to insert 'can_issue_more - 1' nops if next_insn is not | |
14782 | a branch. If next_insn is a branch, we insert 'can_issue_more' nops; | |
14783 | in this case the last nop will start a new group and the branch will be | |
14784 | forced to the new group. */ | |
14785 | if (can_issue_more && !is_branch_slot_insn (next_insn)) | |
14786 | can_issue_more--; | |
14787 | ||
14788 | while (can_issue_more > 0) | |
14789 | { | |
14790 | nop = gen_nop(); | |
14791 | emit_insn_before (nop, next_insn); | |
14792 | can_issue_more--; | |
14793 | } | |
14794 | ||
14795 | *group_end = true; | |
14796 | return 0; | |
14797 | } | |
14798 | ||
14799 | if (rs6000_sched_insert_nops < sched_finish_regroup_exact) | |
14800 | { | |
14801 | int n_nops = rs6000_sched_insert_nops; | |
14802 | ||
14803 | /* Nops can't be issued from the branch slot, so the effective | |
14804 | issue_rate for nops is 'issue_rate - 1'. */ | |
14805 | if (can_issue_more == 0) | |
14806 | can_issue_more = issue_rate; | |
14807 | can_issue_more--; | |
14808 | if (can_issue_more == 0) | |
14809 | { | |
14810 | can_issue_more = issue_rate - 1; | |
14811 | (*group_count)++; | |
14812 | end = true; | |
14813 | for (i = 0; i < issue_rate; i++) | |
14814 | { | |
14815 | group_insns[i] = 0; | |
14816 | } | |
14817 | } | |
14818 | ||
14819 | while (n_nops > 0) | |
14820 | { | |
14821 | nop = gen_nop (); | |
14822 | emit_insn_before (nop, next_insn); | |
14823 | if (can_issue_more == issue_rate - 1) /* new group begins */ | |
14824 | end = false; | |
14825 | can_issue_more--; | |
14826 | if (can_issue_more == 0) | |
14827 | { | |
14828 | can_issue_more = issue_rate - 1; | |
14829 | (*group_count)++; | |
14830 | end = true; | |
14831 | for (i = 0; i < issue_rate; i++) | |
14832 | { | |
14833 | group_insns[i] = 0; | |
14834 | } | |
14835 | } | |
14836 | n_nops--; | |
14837 | } | |
14838 | ||
14839 | /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */ | |
14840 | can_issue_more++; | |
14841 | ||
14842 | *group_end = /* Is next_insn going to start a new group? */ | |
14843 | (end | |
14844 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
14845 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
14846 | || (can_issue_more < issue_rate && | |
14847 | insn_terminates_group_p (next_insn, previous_group))); | |
14848 | if (*group_end && end) | |
14849 | (*group_count)--; | |
14850 | ||
14851 | if (sched_verbose > 6) | |
14852 | fprintf (dump, "done force: group count = %d, can_issue_more = %d\n", | |
14853 | *group_count, can_issue_more); | |
14854 | return can_issue_more; | |
14855 | } | |
14856 | ||
14857 | return can_issue_more; | |
14858 | } | |
14859 | ||
14860 | /* This function tries to synch the dispatch groups that the compiler "sees" | |
14861 | with the dispatch groups that the processor dispatcher is expected to | |
14862 | form in practice. It tries to achieve this synchronization by forcing the | |
14863 | estimated processor grouping on the compiler (as opposed to the function | |
14864 | 'pad_goups' which tries to force the scheduler's grouping on the processor). | |
14865 | ||
14866 | The function scans the insn sequence between PREV_HEAD_INSN and TAIL and | |
14867 | examines the (estimated) dispatch groups that will be formed by the processor | |
14868 | dispatcher. It marks these group boundaries to reflect the estimated | |
14869 | processor grouping, overriding the grouping that the scheduler had marked. | |
14870 | Depending on the value of the flag '-minsert-sched-nops' this function can | |
14871 | force certain insns into separate groups or force a certain distance between | |
14872 | them by inserting nops, for example, if there exists a "costly dependence" | |
14873 | between the insns. | |
14874 | ||
14875 | The function estimates the group boundaries that the processor will form as | |
14876 | folllows: It keeps track of how many vacant issue slots are available after | |
14877 | each insn. A subsequent insn will start a new group if one of the following | |
14878 | 4 cases applies: | |
14879 | - no more vacant issue slots remain in the current dispatch group. | |
14880 | - only the last issue slot, which is the branch slot, is vacant, but the next | |
14881 | insn is not a branch. | |
14882 | - only the last 2 or less issue slots, including the branch slot, are vacant, | |
14883 | which means that a cracked insn (which occupies two issue slots) can't be | |
14884 | issued in this group. | |
14885 | - less than 'issue_rate' slots are vacant, and the next insn always needs to | |
14886 | start a new group. */ | |
14887 | ||
14888 | static int | |
14889 | redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
14890 | { | |
14891 | rtx insn, next_insn; | |
14892 | int issue_rate; | |
14893 | int can_issue_more; | |
14894 | int slot, i; | |
14895 | bool group_end; | |
14896 | int group_count = 0; | |
14897 | rtx *group_insns; | |
14898 | ||
14899 | /* Initialize. */ | |
14900 | issue_rate = rs6000_issue_rate (); | |
14901 | group_insns = alloca (issue_rate * sizeof (rtx)); | |
14902 | for (i = 0; i < issue_rate; i++) | |
14903 | { | |
14904 | group_insns[i] = 0; | |
14905 | } | |
14906 | can_issue_more = issue_rate; | |
14907 | slot = 0; | |
14908 | insn = get_next_active_insn (prev_head_insn, tail); | |
14909 | group_end = false; | |
14910 | ||
14911 | while (insn != NULL_RTX) | |
14912 | { | |
14913 | slot = (issue_rate - can_issue_more); | |
14914 | group_insns[slot] = insn; | |
14915 | can_issue_more = | |
14916 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
14917 | if (insn_terminates_group_p (insn, current_group)) | |
14918 | can_issue_more = 0; | |
14919 | ||
14920 | next_insn = get_next_active_insn (insn, tail); | |
14921 | if (next_insn == NULL_RTX) | |
14922 | return group_count + 1; | |
14923 | ||
14924 | group_end = /* Is next_insn going to start a new group? */ | |
14925 | (can_issue_more == 0 | |
14926 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
14927 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
14928 | || (can_issue_more < issue_rate && | |
14929 | insn_terminates_group_p (next_insn, previous_group))); | |
14930 | ||
14931 | can_issue_more = force_new_group (sched_verbose, dump, group_insns, | |
14932 | next_insn, &group_end, can_issue_more, &group_count); | |
14933 | ||
14934 | if (group_end) | |
14935 | { | |
14936 | group_count++; | |
14937 | can_issue_more = 0; | |
14938 | for (i = 0; i < issue_rate; i++) | |
14939 | { | |
14940 | group_insns[i] = 0; | |
14941 | } | |
14942 | } | |
14943 | ||
14944 | if (GET_MODE (next_insn) == TImode && can_issue_more) | |
14945 | PUT_MODE(next_insn, VOIDmode); | |
14946 | else if (!can_issue_more && GET_MODE (next_insn) != TImode) | |
14947 | PUT_MODE (next_insn, TImode); | |
14948 | ||
14949 | insn = next_insn; | |
14950 | if (can_issue_more == 0) | |
14951 | can_issue_more = issue_rate; | |
14952 | } /* while */ | |
14953 | ||
14954 | return group_count; | |
14955 | } | |
14956 | ||
14957 | /* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the | |
14958 | dispatch group boundaries that the scheduler had marked. Pad with nops | |
14959 | any dispatch groups which have vacant issue slots, in order to force the | |
14960 | scheduler's grouping on the processor dispatcher. The function | |
14961 | returns the number of dispatch groups found. */ | |
14962 | ||
14963 | static int | |
14964 | pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
14965 | { | |
14966 | rtx insn, next_insn; | |
14967 | rtx nop; | |
14968 | int issue_rate; | |
14969 | int can_issue_more; | |
14970 | int group_end; | |
14971 | int group_count = 0; | |
14972 | ||
14973 | /* Initialize issue_rate. */ | |
14974 | issue_rate = rs6000_issue_rate (); | |
14975 | can_issue_more = issue_rate; | |
14976 | ||
14977 | insn = get_next_active_insn (prev_head_insn, tail); | |
14978 | next_insn = get_next_active_insn (insn, tail); | |
14979 | ||
14980 | while (insn != NULL_RTX) | |
14981 | { | |
14982 | can_issue_more = | |
14983 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
14984 | ||
14985 | group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode); | |
14986 | ||
14987 | if (next_insn == NULL_RTX) | |
14988 | break; | |
14989 | ||
14990 | if (group_end) | |
14991 | { | |
14992 | /* If the scheduler had marked group termination at this location | |
14993 | (between insn and next_indn), and neither insn nor next_insn will | |
14994 | force group termination, pad the group with nops to force group | |
14995 | termination. */ | |
14996 | if (can_issue_more | |
14997 | && (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
14998 | && !insn_terminates_group_p (insn, current_group) | |
14999 | && !insn_terminates_group_p (next_insn, previous_group)) | |
15000 | { | |
15001 | if (!is_branch_slot_insn(next_insn)) | |
15002 | can_issue_more--; | |
15003 | ||
15004 | while (can_issue_more) | |
15005 | { | |
15006 | nop = gen_nop (); | |
15007 | emit_insn_before (nop, next_insn); | |
15008 | can_issue_more--; | |
15009 | } | |
15010 | } | |
15011 | ||
15012 | can_issue_more = issue_rate; | |
15013 | group_count++; | |
15014 | } | |
15015 | ||
15016 | insn = next_insn; | |
15017 | next_insn = get_next_active_insn (insn, tail); | |
15018 | } | |
15019 | ||
15020 | return group_count; | |
15021 | } | |
15022 | ||
15023 | /* The following function is called at the end of scheduling BB. | |
15024 | After reload, it inserts nops at insn group bundling. */ | |
15025 | ||
15026 | static void | |
38f391a5 | 15027 | rs6000_sched_finish (FILE *dump, int sched_verbose) |
cbe26ab8 DN |
15028 | { |
15029 | int n_groups; | |
15030 | ||
15031 | if (sched_verbose) | |
15032 | fprintf (dump, "=== Finishing schedule.\n"); | |
15033 | ||
ec507f2d | 15034 | if (reload_completed && rs6000_sched_groups) |
cbe26ab8 DN |
15035 | { |
15036 | if (rs6000_sched_insert_nops == sched_finish_none) | |
15037 | return; | |
15038 | ||
15039 | if (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
15040 | n_groups = pad_groups (dump, sched_verbose, | |
15041 | current_sched_info->prev_head, | |
15042 | current_sched_info->next_tail); | |
15043 | else | |
15044 | n_groups = redefine_groups (dump, sched_verbose, | |
15045 | current_sched_info->prev_head, | |
15046 | current_sched_info->next_tail); | |
15047 | ||
15048 | if (sched_verbose >= 6) | |
15049 | { | |
15050 | fprintf (dump, "ngroups = %d\n", n_groups); | |
15051 | print_rtl (dump, current_sched_info->prev_head); | |
15052 | fprintf (dump, "Done finish_sched\n"); | |
15053 | } | |
15054 | } | |
15055 | } | |
b6c9286a | 15056 | \f |
b6c9286a MM |
15057 | /* Length in units of the trampoline for entering a nested function. */ |
15058 | ||
15059 | int | |
863d938c | 15060 | rs6000_trampoline_size (void) |
b6c9286a MM |
15061 | { |
15062 | int ret = 0; | |
15063 | ||
15064 | switch (DEFAULT_ABI) | |
15065 | { | |
15066 | default: | |
15067 | abort (); | |
15068 | ||
15069 | case ABI_AIX: | |
8f802bfb | 15070 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
15071 | break; |
15072 | ||
4dabc42d | 15073 | case ABI_DARWIN: |
b6c9286a | 15074 | case ABI_V4: |
03a7e1a5 | 15075 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 15076 | break; |
b6c9286a MM |
15077 | } |
15078 | ||
15079 | return ret; | |
15080 | } | |
15081 | ||
15082 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
15083 | FNADDR is an RTX for the address of the function's pure code. | |
15084 | CXT is an RTX for the static chain value for the function. */ | |
15085 | ||
15086 | void | |
a2369ed3 | 15087 | rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt) |
b6c9286a | 15088 | { |
ac2a93a1 | 15089 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
15090 | int regsize = (TARGET_32BIT) ? 4 : 8; |
15091 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
15092 | |
15093 | switch (DEFAULT_ABI) | |
15094 | { | |
15095 | default: | |
15096 | abort (); | |
15097 | ||
8bd04c56 | 15098 | /* Macros to shorten the code expansions below. */ |
39403d82 | 15099 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
15100 | #define MEM_PLUS(addr,offset) \ |
15101 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 15102 | |
b6c9286a MM |
15103 | /* Under AIX, just build the 3 word function descriptor */ |
15104 | case ABI_AIX: | |
8bd04c56 MM |
15105 | { |
15106 | rtx fn_reg = gen_reg_rtx (pmode); | |
15107 | rtx toc_reg = gen_reg_rtx (pmode); | |
15108 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
1cb18e3c | 15109 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); |
8bd04c56 MM |
15110 | emit_move_insn (MEM_DEREF (addr), fn_reg); |
15111 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
15112 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
15113 | } | |
b6c9286a MM |
15114 | break; |
15115 | ||
4dabc42d TC |
15116 | /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */ |
15117 | case ABI_DARWIN: | |
b6c9286a | 15118 | case ABI_V4: |
39403d82 | 15119 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
15120 | FALSE, VOIDmode, 4, |
15121 | addr, pmode, | |
15122 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
15123 | fnaddr, pmode, | |
15124 | ctx_reg, pmode); | |
b6c9286a | 15125 | break; |
b6c9286a MM |
15126 | } |
15127 | ||
15128 | return; | |
15129 | } | |
7509c759 MM |
15130 | |
15131 | \f | |
91d231cb | 15132 | /* Table of valid machine attributes. */ |
a4f6c312 | 15133 | |
91d231cb | 15134 | const struct attribute_spec rs6000_attribute_table[] = |
7509c759 | 15135 | { |
91d231cb | 15136 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
8bb418a3 | 15137 | { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute }, |
a5c76ee6 ZW |
15138 | { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, |
15139 | { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, | |
15140 | { NULL, 0, 0, false, false, false, NULL } | |
91d231cb | 15141 | }; |
7509c759 | 15142 | |
8bb418a3 ZL |
15143 | /* Handle the "altivec" attribute. The attribute may have |
15144 | arguments as follows: | |
15145 | ||
15146 | __attribute__((altivec(vector__))) | |
15147 | __attribute__((altivec(pixel__))) (always followed by 'unsigned short') | |
15148 | __attribute__((altivec(bool__))) (always followed by 'unsigned') | |
15149 | ||
15150 | and may appear more than once (e.g., 'vector bool char') in a | |
15151 | given declaration. */ | |
15152 | ||
15153 | static tree | |
15154 | rs6000_handle_altivec_attribute (tree *node, tree name, tree args, | |
15155 | int flags ATTRIBUTE_UNUSED, | |
15156 | bool *no_add_attrs) | |
15157 | { | |
15158 | tree type = *node, result = NULL_TREE; | |
15159 | enum machine_mode mode; | |
15160 | int unsigned_p; | |
15161 | char altivec_type | |
15162 | = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args) | |
15163 | && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE) | |
15164 | ? *IDENTIFIER_POINTER (TREE_VALUE (args)) | |
15165 | : '?'); | |
15166 | ||
15167 | while (POINTER_TYPE_P (type) | |
15168 | || TREE_CODE (type) == FUNCTION_TYPE | |
15169 | || TREE_CODE (type) == METHOD_TYPE | |
15170 | || TREE_CODE (type) == ARRAY_TYPE) | |
15171 | type = TREE_TYPE (type); | |
15172 | ||
15173 | mode = TYPE_MODE (type); | |
15174 | ||
15175 | if (rs6000_warn_altivec_long | |
15176 | && (type == long_unsigned_type_node || type == long_integer_type_node)) | |
15177 | warning ("use of 'long' in AltiVec types is deprecated; use 'int'"); | |
15178 | ||
15179 | switch (altivec_type) | |
15180 | { | |
15181 | case 'v': | |
8df83eae | 15182 | unsigned_p = TYPE_UNSIGNED (type); |
8bb418a3 ZL |
15183 | switch (mode) |
15184 | { | |
15185 | case SImode: | |
15186 | result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node); | |
15187 | break; | |
15188 | case HImode: | |
15189 | result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node); | |
15190 | break; | |
15191 | case QImode: | |
15192 | result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node); | |
15193 | break; | |
15194 | case SFmode: result = V4SF_type_node; break; | |
15195 | /* If the user says 'vector int bool', we may be handed the 'bool' | |
15196 | attribute _before_ the 'vector' attribute, and so select the proper | |
15197 | type in the 'b' case below. */ | |
15198 | case V4SImode: case V8HImode: case V16QImode: result = type; | |
15199 | default: break; | |
15200 | } | |
15201 | break; | |
15202 | case 'b': | |
15203 | switch (mode) | |
15204 | { | |
15205 | case SImode: case V4SImode: result = bool_V4SI_type_node; break; | |
15206 | case HImode: case V8HImode: result = bool_V8HI_type_node; break; | |
15207 | case QImode: case V16QImode: result = bool_V16QI_type_node; | |
15208 | default: break; | |
15209 | } | |
15210 | break; | |
15211 | case 'p': | |
15212 | switch (mode) | |
15213 | { | |
15214 | case V8HImode: result = pixel_V8HI_type_node; | |
15215 | default: break; | |
15216 | } | |
15217 | default: break; | |
15218 | } | |
15219 | ||
7958a2a6 FJ |
15220 | if (result && result != type && TYPE_READONLY (type)) |
15221 | result = build_qualified_type (result, TYPE_QUAL_CONST); | |
15222 | ||
8bb418a3 ZL |
15223 | *no_add_attrs = true; /* No need to hang on to the attribute. */ |
15224 | ||
15225 | if (!result) | |
15226 | warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); | |
15227 | else | |
15228 | *node = reconstruct_complex_type (*node, result); | |
15229 | ||
15230 | return NULL_TREE; | |
15231 | } | |
15232 | ||
f18eca82 ZL |
15233 | /* AltiVec defines four built-in scalar types that serve as vector |
15234 | elements; we must teach the compiler how to mangle them. */ | |
15235 | ||
15236 | static const char * | |
15237 | rs6000_mangle_fundamental_type (tree type) | |
15238 | { | |
15239 | if (type == bool_char_type_node) return "U6__boolc"; | |
15240 | if (type == bool_short_type_node) return "U6__bools"; | |
15241 | if (type == pixel_type_node) return "u7__pixel"; | |
15242 | if (type == bool_int_type_node) return "U6__booli"; | |
15243 | ||
15244 | /* For all other types, use normal C++ mangling. */ | |
15245 | return NULL; | |
15246 | } | |
15247 | ||
a5c76ee6 ZW |
15248 | /* Handle a "longcall" or "shortcall" attribute; arguments as in |
15249 | struct attribute_spec.handler. */ | |
a4f6c312 | 15250 | |
91d231cb | 15251 | static tree |
a2369ed3 DJ |
15252 | rs6000_handle_longcall_attribute (tree *node, tree name, |
15253 | tree args ATTRIBUTE_UNUSED, | |
15254 | int flags ATTRIBUTE_UNUSED, | |
15255 | bool *no_add_attrs) | |
91d231cb JM |
15256 | { |
15257 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
15258 | && TREE_CODE (*node) != FIELD_DECL | |
15259 | && TREE_CODE (*node) != TYPE_DECL) | |
15260 | { | |
15261 | warning ("`%s' attribute only applies to functions", | |
15262 | IDENTIFIER_POINTER (name)); | |
15263 | *no_add_attrs = true; | |
15264 | } | |
6a4cee5f | 15265 | |
91d231cb | 15266 | return NULL_TREE; |
7509c759 MM |
15267 | } |
15268 | ||
a5c76ee6 ZW |
15269 | /* Set longcall attributes on all functions declared when |
15270 | rs6000_default_long_calls is true. */ | |
15271 | static void | |
a2369ed3 | 15272 | rs6000_set_default_type_attributes (tree type) |
a5c76ee6 ZW |
15273 | { |
15274 | if (rs6000_default_long_calls | |
15275 | && (TREE_CODE (type) == FUNCTION_TYPE | |
15276 | || TREE_CODE (type) == METHOD_TYPE)) | |
15277 | TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"), | |
15278 | NULL_TREE, | |
15279 | TYPE_ATTRIBUTES (type)); | |
15280 | } | |
15281 | ||
3cb999d8 DE |
15282 | /* Return a reference suitable for calling a function with the |
15283 | longcall attribute. */ | |
a4f6c312 | 15284 | |
6a4cee5f | 15285 | struct rtx_def * |
a2369ed3 | 15286 | rs6000_longcall_ref (rtx call_ref) |
6a4cee5f | 15287 | { |
d330fd93 | 15288 | const char *call_name; |
6a4cee5f MM |
15289 | tree node; |
15290 | ||
15291 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
15292 | return call_ref; | |
15293 | ||
15294 | /* System V adds '.' to the internal name, so skip them. */ | |
15295 | call_name = XSTR (call_ref, 0); | |
15296 | if (*call_name == '.') | |
15297 | { | |
15298 | while (*call_name == '.') | |
15299 | call_name++; | |
15300 | ||
15301 | node = get_identifier (call_name); | |
39403d82 | 15302 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
15303 | } |
15304 | ||
15305 | return force_reg (Pmode, call_ref); | |
15306 | } | |
7509c759 | 15307 | \f |
b64a1b53 RH |
15308 | #ifdef USING_ELFOS_H |
15309 | ||
7509c759 MM |
15310 | /* A C statement or statements to switch to the appropriate section |
15311 | for output of RTX in mode MODE. You can assume that RTX is some | |
15312 | kind of constant in RTL. The argument MODE is redundant except in | |
15313 | the case of a `const_int' rtx. Select the section by calling | |
15314 | `text_section' or one of the alternatives for other sections. | |
15315 | ||
15316 | Do not define this macro if you put all constants in the read-only | |
15317 | data section. */ | |
15318 | ||
b64a1b53 | 15319 | static void |
a2369ed3 DJ |
15320 | rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x, |
15321 | unsigned HOST_WIDE_INT align) | |
7509c759 | 15322 | { |
a9098fd0 | 15323 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 15324 | toc_section (); |
7509c759 | 15325 | else |
b64a1b53 | 15326 | default_elf_select_rtx_section (mode, x, align); |
7509c759 MM |
15327 | } |
15328 | ||
15329 | /* A C statement or statements to switch to the appropriate | |
15330 | section for output of DECL. DECL is either a `VAR_DECL' node | |
15331 | or a constant of some sort. RELOC indicates whether forming | |
15332 | the initial value of DECL requires link-time relocations. */ | |
15333 | ||
ae46c4e0 | 15334 | static void |
a2369ed3 DJ |
15335 | rs6000_elf_select_section (tree decl, int reloc, |
15336 | unsigned HOST_WIDE_INT align) | |
7509c759 | 15337 | { |
f1384257 AM |
15338 | /* Pretend that we're always building for a shared library when |
15339 | ABI_AIX, because otherwise we end up with dynamic relocations | |
15340 | in read-only sections. This happens for function pointers, | |
15341 | references to vtables in typeinfo, and probably other cases. */ | |
0e5dbd9b DE |
15342 | default_elf_select_section_1 (decl, reloc, align, |
15343 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
63019373 GK |
15344 | } |
15345 | ||
15346 | /* A C statement to build up a unique section name, expressed as a | |
15347 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
15348 | RELOC indicates whether the initial value of EXP requires | |
15349 | link-time relocations. If you do not define this macro, GCC will use | |
15350 | the symbol name prefixed by `.' as the section name. Note - this | |
f5143c46 | 15351 | macro can now be called for uninitialized data items as well as |
4912a07c | 15352 | initialized data and functions. */ |
63019373 | 15353 | |
ae46c4e0 | 15354 | static void |
a2369ed3 | 15355 | rs6000_elf_unique_section (tree decl, int reloc) |
63019373 | 15356 | { |
f1384257 AM |
15357 | /* As above, pretend that we're always building for a shared library |
15358 | when ABI_AIX, to avoid dynamic relocations in read-only sections. */ | |
0e5dbd9b DE |
15359 | default_unique_section_1 (decl, reloc, |
15360 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7509c759 | 15361 | } |
d9407988 | 15362 | \f |
d1908feb JJ |
15363 | /* For a SYMBOL_REF, set generic flags and then perform some |
15364 | target-specific processing. | |
15365 | ||
d1908feb JJ |
15366 | When the AIX ABI is requested on a non-AIX system, replace the |
15367 | function name with the real name (with a leading .) rather than the | |
15368 | function descriptor name. This saves a lot of overriding code to | |
15369 | read the prefixes. */ | |
d9407988 | 15370 | |
fb49053f | 15371 | static void |
a2369ed3 | 15372 | rs6000_elf_encode_section_info (tree decl, rtx rtl, int first) |
d9407988 | 15373 | { |
d1908feb | 15374 | default_encode_section_info (decl, rtl, first); |
b2003250 | 15375 | |
d1908feb JJ |
15376 | if (first |
15377 | && TREE_CODE (decl) == FUNCTION_DECL | |
15378 | && !TARGET_AIX | |
15379 | && DEFAULT_ABI == ABI_AIX) | |
d9407988 | 15380 | { |
c6a2438a | 15381 | rtx sym_ref = XEXP (rtl, 0); |
d1908feb JJ |
15382 | size_t len = strlen (XSTR (sym_ref, 0)); |
15383 | char *str = alloca (len + 2); | |
15384 | str[0] = '.'; | |
15385 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
15386 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1); | |
d9407988 | 15387 | } |
d9407988 MM |
15388 | } |
15389 | ||
0e5dbd9b | 15390 | static bool |
a2369ed3 | 15391 | rs6000_elf_in_small_data_p (tree decl) |
0e5dbd9b DE |
15392 | { |
15393 | if (rs6000_sdata == SDATA_NONE) | |
15394 | return false; | |
15395 | ||
15396 | if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl)) | |
15397 | { | |
15398 | const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
15399 | if (strcmp (section, ".sdata") == 0 | |
15400 | || strcmp (section, ".sdata2") == 0 | |
20bfcd69 GK |
15401 | || strcmp (section, ".sbss") == 0 |
15402 | || strcmp (section, ".sbss2") == 0 | |
15403 | || strcmp (section, ".PPC.EMB.sdata0") == 0 | |
15404 | || strcmp (section, ".PPC.EMB.sbss0") == 0) | |
0e5dbd9b DE |
15405 | return true; |
15406 | } | |
15407 | else | |
15408 | { | |
15409 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); | |
15410 | ||
15411 | if (size > 0 | |
307b599c | 15412 | && (unsigned HOST_WIDE_INT) size <= g_switch_value |
20bfcd69 GK |
15413 | /* If it's not public, and we're not going to reference it there, |
15414 | there's no need to put it in the small data section. */ | |
0e5dbd9b DE |
15415 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))) |
15416 | return true; | |
15417 | } | |
15418 | ||
15419 | return false; | |
15420 | } | |
15421 | ||
b91da81f | 15422 | #endif /* USING_ELFOS_H */ |
000034eb | 15423 | |
a6c2a102 | 15424 | \f |
000034eb | 15425 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
15426 | ADDR can be effectively incremented by incrementing REG. |
15427 | ||
15428 | r0 is special and we must not select it as an address | |
15429 | register by this routine since our caller will try to | |
15430 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
15431 | |
15432 | struct rtx_def * | |
a2369ed3 | 15433 | find_addr_reg (rtx addr) |
000034eb DE |
15434 | { |
15435 | while (GET_CODE (addr) == PLUS) | |
15436 | { | |
02441cd6 JL |
15437 | if (GET_CODE (XEXP (addr, 0)) == REG |
15438 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 15439 | addr = XEXP (addr, 0); |
02441cd6 JL |
15440 | else if (GET_CODE (XEXP (addr, 1)) == REG |
15441 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
15442 | addr = XEXP (addr, 1); |
15443 | else if (CONSTANT_P (XEXP (addr, 0))) | |
15444 | addr = XEXP (addr, 1); | |
15445 | else if (CONSTANT_P (XEXP (addr, 1))) | |
15446 | addr = XEXP (addr, 0); | |
15447 | else | |
15448 | abort (); | |
15449 | } | |
02441cd6 | 15450 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
15451 | return addr; |
15452 | abort (); | |
15453 | } | |
15454 | ||
a6c2a102 | 15455 | void |
a2369ed3 | 15456 | rs6000_fatal_bad_address (rtx op) |
a6c2a102 DE |
15457 | { |
15458 | fatal_insn ("bad address", op); | |
15459 | } | |
c8023011 | 15460 | |
ee890fe2 SS |
15461 | #if TARGET_MACHO |
15462 | ||
15463 | #if 0 | |
15464 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
15465 | reference and a constant. */ | |
15466 | ||
15467 | int | |
a2369ed3 | 15468 | symbolic_operand (rtx op) |
ee890fe2 SS |
15469 | { |
15470 | switch (GET_CODE (op)) | |
15471 | { | |
15472 | case SYMBOL_REF: | |
15473 | case LABEL_REF: | |
15474 | return 1; | |
15475 | case CONST: | |
15476 | op = XEXP (op, 0); | |
15477 | return (GET_CODE (op) == SYMBOL_REF || | |
15478 | (GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
15479 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
15480 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
15481 | default: | |
15482 | return 0; | |
15483 | } | |
c8023011 | 15484 | } |
ee890fe2 SS |
15485 | #endif |
15486 | ||
efdba735 | 15487 | #if TARGET_MACHO |
ee890fe2 | 15488 | |
efdba735 | 15489 | static tree branch_island_list = 0; |
ee890fe2 | 15490 | |
efdba735 SH |
15491 | /* Remember to generate a branch island for far calls to the given |
15492 | function. */ | |
ee890fe2 | 15493 | |
efdba735 SH |
15494 | static void |
15495 | add_compiler_branch_island (tree label_name, tree function_name, int line_number) | |
ee890fe2 | 15496 | { |
efdba735 SH |
15497 | tree branch_island = build_tree_list (function_name, label_name); |
15498 | TREE_TYPE (branch_island) = build_int_2 (line_number, 0); | |
15499 | TREE_CHAIN (branch_island) = branch_island_list; | |
15500 | branch_island_list = branch_island; | |
ee890fe2 SS |
15501 | } |
15502 | ||
efdba735 SH |
15503 | #define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND) |
15504 | #define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND) | |
15505 | #define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \ | |
15506 | TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND)) | |
ee890fe2 | 15507 | |
efdba735 SH |
15508 | /* Generate far-jump branch islands for everything on the |
15509 | branch_island_list. Invoked immediately after the last instruction | |
15510 | of the epilogue has been emitted; the branch-islands must be | |
15511 | appended to, and contiguous with, the function body. Mach-O stubs | |
15512 | are generated in machopic_output_stub(). */ | |
ee890fe2 | 15513 | |
efdba735 SH |
15514 | static void |
15515 | macho_branch_islands (void) | |
15516 | { | |
15517 | char tmp_buf[512]; | |
15518 | tree branch_island; | |
15519 | ||
15520 | for (branch_island = branch_island_list; | |
15521 | branch_island; | |
15522 | branch_island = TREE_CHAIN (branch_island)) | |
15523 | { | |
15524 | const char *label = | |
15525 | IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island)); | |
15526 | const char *name = | |
15527 | darwin_strip_name_encoding ( | |
15528 | IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island))); | |
15529 | char name_buf[512]; | |
15530 | /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */ | |
15531 | if (name[0] == '*' || name[0] == '&') | |
15532 | strcpy (name_buf, name+1); | |
15533 | else | |
15534 | { | |
15535 | name_buf[0] = '_'; | |
15536 | strcpy (name_buf+1, name); | |
15537 | } | |
15538 | strcpy (tmp_buf, "\n"); | |
15539 | strcat (tmp_buf, label); | |
ee890fe2 | 15540 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 15541 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 15542 | fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 15543 | BRANCH_ISLAND_LINE_NUMBER(branch_island)); |
ee890fe2 | 15544 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 SH |
15545 | if (flag_pic) |
15546 | { | |
15547 | strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,"); | |
15548 | strcat (tmp_buf, label); | |
15549 | strcat (tmp_buf, "_pic\n"); | |
15550 | strcat (tmp_buf, label); | |
15551 | strcat (tmp_buf, "_pic:\n\tmflr r11\n"); | |
15552 | ||
15553 | strcat (tmp_buf, "\taddis r11,r11,ha16("); | |
15554 | strcat (tmp_buf, name_buf); | |
15555 | strcat (tmp_buf, " - "); | |
15556 | strcat (tmp_buf, label); | |
15557 | strcat (tmp_buf, "_pic)\n"); | |
15558 | ||
15559 | strcat (tmp_buf, "\tmtlr r0\n"); | |
15560 | ||
15561 | strcat (tmp_buf, "\taddi r12,r11,lo16("); | |
15562 | strcat (tmp_buf, name_buf); | |
15563 | strcat (tmp_buf, " - "); | |
15564 | strcat (tmp_buf, label); | |
15565 | strcat (tmp_buf, "_pic)\n"); | |
15566 | ||
15567 | strcat (tmp_buf, "\tmtctr r12\n\tbctr\n"); | |
15568 | } | |
15569 | else | |
15570 | { | |
15571 | strcat (tmp_buf, ":\nlis r12,hi16("); | |
15572 | strcat (tmp_buf, name_buf); | |
15573 | strcat (tmp_buf, ")\n\tori r12,r12,lo16("); | |
15574 | strcat (tmp_buf, name_buf); | |
15575 | strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr"); | |
15576 | } | |
15577 | output_asm_insn (tmp_buf, 0); | |
ee890fe2 | 15578 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 15579 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 15580 | fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 15581 | BRANCH_ISLAND_LINE_NUMBER (branch_island)); |
ee890fe2 | 15582 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 | 15583 | } |
ee890fe2 | 15584 | |
efdba735 | 15585 | branch_island_list = 0; |
ee890fe2 SS |
15586 | } |
15587 | ||
15588 | /* NO_PREVIOUS_DEF checks in the link list whether the function name is | |
15589 | already there or not. */ | |
15590 | ||
efdba735 | 15591 | static int |
a2369ed3 | 15592 | no_previous_def (tree function_name) |
ee890fe2 | 15593 | { |
efdba735 SH |
15594 | tree branch_island; |
15595 | for (branch_island = branch_island_list; | |
15596 | branch_island; | |
15597 | branch_island = TREE_CHAIN (branch_island)) | |
15598 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
ee890fe2 SS |
15599 | return 0; |
15600 | return 1; | |
15601 | } | |
15602 | ||
15603 | /* GET_PREV_LABEL gets the label name from the previous definition of | |
15604 | the function. */ | |
15605 | ||
efdba735 | 15606 | static tree |
a2369ed3 | 15607 | get_prev_label (tree function_name) |
ee890fe2 | 15608 | { |
efdba735 SH |
15609 | tree branch_island; |
15610 | for (branch_island = branch_island_list; | |
15611 | branch_island; | |
15612 | branch_island = TREE_CHAIN (branch_island)) | |
15613 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
15614 | return BRANCH_ISLAND_LABEL_NAME (branch_island); | |
ee890fe2 SS |
15615 | return 0; |
15616 | } | |
15617 | ||
15618 | /* INSN is either a function call or a millicode call. It may have an | |
15619 | unconditional jump in its delay slot. | |
15620 | ||
15621 | CALL_DEST is the routine we are calling. */ | |
15622 | ||
15623 | char * | |
efdba735 | 15624 | output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number) |
ee890fe2 SS |
15625 | { |
15626 | static char buf[256]; | |
efdba735 SH |
15627 | if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF |
15628 | && (INTVAL (operands[cookie_operand_number]) & CALL_LONG)) | |
ee890fe2 SS |
15629 | { |
15630 | tree labelname; | |
efdba735 | 15631 | tree funname = get_identifier (XSTR (operands[dest_operand_number], 0)); |
ee890fe2 SS |
15632 | |
15633 | if (no_previous_def (funname)) | |
15634 | { | |
308c142a | 15635 | int line_number = 0; |
ee890fe2 SS |
15636 | rtx label_rtx = gen_label_rtx (); |
15637 | char *label_buf, temp_buf[256]; | |
15638 | ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L", | |
15639 | CODE_LABEL_NUMBER (label_rtx)); | |
15640 | label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf; | |
15641 | labelname = get_identifier (label_buf); | |
15642 | for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn)); | |
15643 | if (insn) | |
15644 | line_number = NOTE_LINE_NUMBER (insn); | |
efdba735 | 15645 | add_compiler_branch_island (labelname, funname, line_number); |
ee890fe2 SS |
15646 | } |
15647 | else | |
15648 | labelname = get_prev_label (funname); | |
15649 | ||
efdba735 SH |
15650 | /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl' |
15651 | instruction will reach 'foo', otherwise link as 'bl L42'". | |
15652 | "L42" should be a 'branch island', that will do a far jump to | |
15653 | 'foo'. Branch islands are generated in | |
15654 | macho_branch_islands(). */ | |
ee890fe2 | 15655 | sprintf (buf, "jbsr %%z%d,%.246s", |
efdba735 | 15656 | dest_operand_number, IDENTIFIER_POINTER (labelname)); |
ee890fe2 SS |
15657 | } |
15658 | else | |
efdba735 SH |
15659 | sprintf (buf, "bl %%z%d", dest_operand_number); |
15660 | return buf; | |
ee890fe2 SS |
15661 | } |
15662 | ||
efdba735 | 15663 | #endif /* TARGET_MACHO */ |
ee890fe2 | 15664 | |
ee890fe2 SS |
15665 | /* Generate PIC and indirect symbol stubs. */ |
15666 | ||
15667 | void | |
a2369ed3 | 15668 | machopic_output_stub (FILE *file, const char *symb, const char *stub) |
ee890fe2 SS |
15669 | { |
15670 | unsigned int length; | |
a4f6c312 SS |
15671 | char *symbol_name, *lazy_ptr_name; |
15672 | char *local_label_0; | |
ee890fe2 SS |
15673 | static int label = 0; |
15674 | ||
df56a27f | 15675 | /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
772c5265 | 15676 | symb = (*targetm.strip_name_encoding) (symb); |
df56a27f | 15677 | |
ee890fe2 | 15678 | |
ee890fe2 SS |
15679 | length = strlen (symb); |
15680 | symbol_name = alloca (length + 32); | |
15681 | GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); | |
15682 | ||
15683 | lazy_ptr_name = alloca (length + 32); | |
15684 | GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length); | |
15685 | ||
ee890fe2 | 15686 | if (flag_pic == 2) |
d3c300d2 | 15687 | machopic_picsymbol_stub1_section (); |
ee890fe2 | 15688 | else |
d3c300d2 DJ |
15689 | machopic_symbol_stub1_section (); |
15690 | fprintf (file, "\t.align 2\n"); | |
ee890fe2 SS |
15691 | |
15692 | fprintf (file, "%s:\n", stub); | |
15693 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
15694 | ||
15695 | if (flag_pic == 2) | |
15696 | { | |
876455fa AP |
15697 | label++; |
15698 | local_label_0 = alloca (sizeof("\"L0000000000$spb\"")); | |
15699 | sprintf (local_label_0, "\"L%011d$spb\"", label); | |
15700 | ||
ee890fe2 SS |
15701 | fprintf (file, "\tmflr r0\n"); |
15702 | fprintf (file, "\tbcl 20,31,%s\n", local_label_0); | |
15703 | fprintf (file, "%s:\n\tmflr r11\n", local_label_0); | |
15704 | fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n", | |
15705 | lazy_ptr_name, local_label_0); | |
15706 | fprintf (file, "\tmtlr r0\n"); | |
d3c300d2 | 15707 | fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n", |
ee890fe2 SS |
15708 | lazy_ptr_name, local_label_0); |
15709 | fprintf (file, "\tmtctr r12\n"); | |
ee890fe2 SS |
15710 | fprintf (file, "\tbctr\n"); |
15711 | } | |
15712 | else | |
ab82a49f AP |
15713 | { |
15714 | fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name); | |
15715 | fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name); | |
15716 | fprintf (file, "\tmtctr r12\n"); | |
15717 | fprintf (file, "\tbctr\n"); | |
15718 | } | |
ee890fe2 SS |
15719 | |
15720 | machopic_lazy_symbol_ptr_section (); | |
15721 | fprintf (file, "%s:\n", lazy_ptr_name); | |
15722 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
15723 | fprintf (file, "\t.long dyld_stub_binding_helper\n"); | |
15724 | } | |
15725 | ||
15726 | /* Legitimize PIC addresses. If the address is already | |
15727 | position-independent, we return ORIG. Newly generated | |
15728 | position-independent addresses go into a reg. This is REG if non | |
15729 | zero, otherwise we allocate register(s) as necessary. */ | |
15730 | ||
c859cda6 | 15731 | #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000) |
ee890fe2 SS |
15732 | |
15733 | rtx | |
a2369ed3 DJ |
15734 | rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, |
15735 | rtx reg) | |
ee890fe2 SS |
15736 | { |
15737 | rtx base, offset; | |
15738 | ||
15739 | if (reg == NULL && ! reload_in_progress && ! reload_completed) | |
15740 | reg = gen_reg_rtx (Pmode); | |
15741 | ||
15742 | if (GET_CODE (orig) == CONST) | |
15743 | { | |
15744 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
15745 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
15746 | return orig; | |
15747 | ||
15748 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
15749 | { | |
2cf520bf | 15750 | /* Use a different reg for the intermediate value, as |
a3c9585f | 15751 | it will be marked UNCHANGING. */ |
2cf520bf GK |
15752 | rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode); |
15753 | ||
a4f6c312 SS |
15754 | base = |
15755 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), | |
2cf520bf | 15756 | Pmode, reg_temp); |
a4f6c312 SS |
15757 | offset = |
15758 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), | |
15759 | Pmode, reg); | |
ee890fe2 SS |
15760 | } |
15761 | else | |
15762 | abort (); | |
15763 | ||
15764 | if (GET_CODE (offset) == CONST_INT) | |
15765 | { | |
15766 | if (SMALL_INT (offset)) | |
ed8908e7 | 15767 | return plus_constant (base, INTVAL (offset)); |
ee890fe2 SS |
15768 | else if (! reload_in_progress && ! reload_completed) |
15769 | offset = force_reg (Pmode, offset); | |
15770 | else | |
c859cda6 DJ |
15771 | { |
15772 | rtx mem = force_const_mem (Pmode, orig); | |
15773 | return machopic_legitimize_pic_address (mem, Pmode, reg); | |
15774 | } | |
ee890fe2 | 15775 | } |
f1c25d3b | 15776 | return gen_rtx_PLUS (Pmode, base, offset); |
ee890fe2 SS |
15777 | } |
15778 | ||
15779 | /* Fall back on generic machopic code. */ | |
15780 | return machopic_legitimize_pic_address (orig, mode, reg); | |
15781 | } | |
15782 | ||
15783 | /* This is just a placeholder to make linking work without having to | |
15784 | add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is | |
15785 | ever needed for Darwin (not too likely!) this would have to get a | |
15786 | real definition. */ | |
15787 | ||
15788 | void | |
863d938c | 15789 | toc_section (void) |
ee890fe2 SS |
15790 | { |
15791 | } | |
15792 | ||
15793 | #endif /* TARGET_MACHO */ | |
7c262518 RH |
15794 | |
15795 | #if TARGET_ELF | |
15796 | static unsigned int | |
a2369ed3 | 15797 | rs6000_elf_section_type_flags (tree decl, const char *name, int reloc) |
7c262518 | 15798 | { |
1ff8f81a AM |
15799 | return default_section_type_flags_1 (decl, name, reloc, |
15800 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7c262518 | 15801 | } |
d9f6800d RH |
15802 | |
15803 | /* Record an element in the table of global constructors. SYMBOL is | |
15804 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
15805 | between 0 and MAX_INIT_PRIORITY. | |
15806 | ||
15807 | This differs from default_named_section_asm_out_constructor in | |
15808 | that we have special handling for -mrelocatable. */ | |
15809 | ||
15810 | static void | |
a2369ed3 | 15811 | rs6000_elf_asm_out_constructor (rtx symbol, int priority) |
d9f6800d RH |
15812 | { |
15813 | const char *section = ".ctors"; | |
15814 | char buf[16]; | |
15815 | ||
15816 | if (priority != DEFAULT_INIT_PRIORITY) | |
15817 | { | |
15818 | sprintf (buf, ".ctors.%.5u", | |
15819 | /* Invert the numbering so the linker puts us in the proper | |
15820 | order; constructors are run from right to left, and the | |
15821 | linker sorts in increasing order. */ | |
15822 | MAX_INIT_PRIORITY - priority); | |
15823 | section = buf; | |
15824 | } | |
15825 | ||
715bdd29 RH |
15826 | named_section_flags (section, SECTION_WRITE); |
15827 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
15828 | |
15829 | if (TARGET_RELOCATABLE) | |
15830 | { | |
15831 | fputs ("\t.long (", asm_out_file); | |
15832 | output_addr_const (asm_out_file, symbol); | |
15833 | fputs (")@fixup\n", asm_out_file); | |
15834 | } | |
15835 | else | |
c8af3574 | 15836 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d RH |
15837 | } |
15838 | ||
15839 | static void | |
a2369ed3 | 15840 | rs6000_elf_asm_out_destructor (rtx symbol, int priority) |
d9f6800d RH |
15841 | { |
15842 | const char *section = ".dtors"; | |
15843 | char buf[16]; | |
15844 | ||
15845 | if (priority != DEFAULT_INIT_PRIORITY) | |
15846 | { | |
15847 | sprintf (buf, ".dtors.%.5u", | |
15848 | /* Invert the numbering so the linker puts us in the proper | |
15849 | order; constructors are run from right to left, and the | |
15850 | linker sorts in increasing order. */ | |
15851 | MAX_INIT_PRIORITY - priority); | |
15852 | section = buf; | |
15853 | } | |
15854 | ||
715bdd29 RH |
15855 | named_section_flags (section, SECTION_WRITE); |
15856 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
15857 | |
15858 | if (TARGET_RELOCATABLE) | |
15859 | { | |
15860 | fputs ("\t.long (", asm_out_file); | |
15861 | output_addr_const (asm_out_file, symbol); | |
15862 | fputs (")@fixup\n", asm_out_file); | |
15863 | } | |
15864 | else | |
c8af3574 | 15865 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d | 15866 | } |
9739c90c JJ |
15867 | |
15868 | void | |
a2369ed3 | 15869 | rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl) |
9739c90c JJ |
15870 | { |
15871 | if (TARGET_64BIT) | |
15872 | { | |
15873 | fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file); | |
15874 | ASM_OUTPUT_LABEL (file, name); | |
15875 | fputs (DOUBLE_INT_ASM_OP, file); | |
15876 | putc ('.', file); | |
15877 | assemble_name (file, name); | |
15878 | fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file); | |
15879 | assemble_name (file, name); | |
15880 | fputs (",24\n\t.type\t.", file); | |
15881 | assemble_name (file, name); | |
15882 | fputs (",@function\n", file); | |
15883 | if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl)) | |
15884 | { | |
15885 | fputs ("\t.globl\t.", file); | |
15886 | assemble_name (file, name); | |
15887 | putc ('\n', file); | |
15888 | } | |
15889 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
15890 | putc ('.', file); | |
15891 | ASM_OUTPUT_LABEL (file, name); | |
15892 | return; | |
15893 | } | |
15894 | ||
15895 | if (TARGET_RELOCATABLE | |
15896 | && (get_pool_size () != 0 || current_function_profile) | |
3c9eb5f4 | 15897 | && uses_TOC ()) |
9739c90c JJ |
15898 | { |
15899 | char buf[256]; | |
15900 | ||
15901 | (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno); | |
15902 | ||
15903 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
15904 | fprintf (file, "\t.long "); | |
15905 | assemble_name (file, buf); | |
15906 | putc ('-', file); | |
15907 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
15908 | assemble_name (file, buf); | |
15909 | putc ('\n', file); | |
15910 | } | |
15911 | ||
15912 | ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); | |
15913 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
15914 | ||
15915 | if (DEFAULT_ABI == ABI_AIX) | |
15916 | { | |
15917 | const char *desc_name, *orig_name; | |
15918 | ||
15919 | orig_name = (*targetm.strip_name_encoding) (name); | |
15920 | desc_name = orig_name; | |
15921 | while (*desc_name == '.') | |
15922 | desc_name++; | |
15923 | ||
15924 | if (TREE_PUBLIC (decl)) | |
15925 | fprintf (file, "\t.globl %s\n", desc_name); | |
15926 | ||
15927 | fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); | |
15928 | fprintf (file, "%s:\n", desc_name); | |
15929 | fprintf (file, "\t.long %s\n", orig_name); | |
15930 | fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file); | |
15931 | if (DEFAULT_ABI == ABI_AIX) | |
15932 | fputs ("\t.long 0\n", file); | |
15933 | fprintf (file, "\t.previous\n"); | |
15934 | } | |
15935 | ASM_OUTPUT_LABEL (file, name); | |
15936 | } | |
7c262518 RH |
15937 | #endif |
15938 | ||
cbaaba19 | 15939 | #if TARGET_XCOFF |
7c262518 | 15940 | static void |
a2369ed3 | 15941 | rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name) |
b275d088 DE |
15942 | { |
15943 | fputs (GLOBAL_ASM_OP, stream); | |
15944 | RS6000_OUTPUT_BASENAME (stream, name); | |
15945 | putc ('\n', stream); | |
15946 | } | |
15947 | ||
15948 | static void | |
a2369ed3 | 15949 | rs6000_xcoff_asm_named_section (const char *name, unsigned int flags) |
7c262518 | 15950 | { |
0e5dbd9b DE |
15951 | int smclass; |
15952 | static const char * const suffix[3] = { "PR", "RO", "RW" }; | |
15953 | ||
15954 | if (flags & SECTION_CODE) | |
15955 | smclass = 0; | |
15956 | else if (flags & SECTION_WRITE) | |
15957 | smclass = 2; | |
15958 | else | |
15959 | smclass = 1; | |
15960 | ||
5b5198f7 | 15961 | fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n", |
0e5dbd9b | 15962 | (flags & SECTION_CODE) ? "." : "", |
5b5198f7 | 15963 | name, suffix[smclass], flags & SECTION_ENTSIZE); |
7c262518 | 15964 | } |
ae46c4e0 RH |
15965 | |
15966 | static void | |
a2369ed3 DJ |
15967 | rs6000_xcoff_select_section (tree decl, int reloc, |
15968 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
ae46c4e0 | 15969 | { |
5add3202 | 15970 | if (decl_readonly_section_1 (decl, reloc, 1)) |
ae46c4e0 | 15971 | { |
0e5dbd9b | 15972 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
15973 | read_only_data_section (); |
15974 | else | |
15975 | read_only_private_data_section (); | |
15976 | } | |
15977 | else | |
15978 | { | |
0e5dbd9b | 15979 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
15980 | data_section (); |
15981 | else | |
15982 | private_data_section (); | |
15983 | } | |
15984 | } | |
15985 | ||
15986 | static void | |
a2369ed3 | 15987 | rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED) |
ae46c4e0 RH |
15988 | { |
15989 | const char *name; | |
ae46c4e0 | 15990 | |
5b5198f7 DE |
15991 | /* Use select_section for private and uninitialized data. */ |
15992 | if (!TREE_PUBLIC (decl) | |
15993 | || DECL_COMMON (decl) | |
0e5dbd9b DE |
15994 | || DECL_INITIAL (decl) == NULL_TREE |
15995 | || DECL_INITIAL (decl) == error_mark_node | |
15996 | || (flag_zero_initialized_in_bss | |
15997 | && initializer_zerop (DECL_INITIAL (decl)))) | |
15998 | return; | |
15999 | ||
16000 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
16001 | name = (*targetm.strip_name_encoding) (name); | |
16002 | DECL_SECTION_NAME (decl) = build_string (strlen (name), name); | |
ae46c4e0 | 16003 | } |
b64a1b53 | 16004 | |
fb49053f RH |
16005 | /* Select section for constant in constant pool. |
16006 | ||
16007 | On RS/6000, all constants are in the private read-only data area. | |
16008 | However, if this is being placed in the TOC it must be output as a | |
16009 | toc entry. */ | |
16010 | ||
b64a1b53 | 16011 | static void |
a2369ed3 DJ |
16012 | rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x, |
16013 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
b64a1b53 RH |
16014 | { |
16015 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) | |
16016 | toc_section (); | |
16017 | else | |
16018 | read_only_private_data_section (); | |
16019 | } | |
772c5265 RH |
16020 | |
16021 | /* Remove any trailing [DS] or the like from the symbol name. */ | |
16022 | ||
16023 | static const char * | |
a2369ed3 | 16024 | rs6000_xcoff_strip_name_encoding (const char *name) |
772c5265 RH |
16025 | { |
16026 | size_t len; | |
16027 | if (*name == '*') | |
16028 | name++; | |
16029 | len = strlen (name); | |
16030 | if (name[len - 1] == ']') | |
16031 | return ggc_alloc_string (name, len - 4); | |
16032 | else | |
16033 | return name; | |
16034 | } | |
16035 | ||
5add3202 DE |
16036 | /* Section attributes. AIX is always PIC. */ |
16037 | ||
16038 | static unsigned int | |
a2369ed3 | 16039 | rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc) |
5add3202 | 16040 | { |
5b5198f7 DE |
16041 | unsigned int align; |
16042 | unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1); | |
16043 | ||
16044 | /* Align to at least UNIT size. */ | |
16045 | if (flags & SECTION_CODE) | |
16046 | align = MIN_UNITS_PER_WORD; | |
16047 | else | |
16048 | /* Increase alignment of large objects if not already stricter. */ | |
16049 | align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT), | |
16050 | int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD | |
16051 | ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD); | |
16052 | ||
16053 | return flags | (exact_log2 (align) & SECTION_ENTSIZE); | |
5add3202 | 16054 | } |
a5fe455b | 16055 | |
1bc7c5b6 ZW |
16056 | /* Output at beginning of assembler file. |
16057 | ||
16058 | Initialize the section names for the RS/6000 at this point. | |
16059 | ||
16060 | Specify filename, including full path, to assembler. | |
16061 | ||
16062 | We want to go into the TOC section so at least one .toc will be emitted. | |
16063 | Also, in order to output proper .bs/.es pairs, we need at least one static | |
16064 | [RW] section emitted. | |
16065 | ||
16066 | Finally, declare mcount when profiling to make the assembler happy. */ | |
16067 | ||
16068 | static void | |
863d938c | 16069 | rs6000_xcoff_file_start (void) |
1bc7c5b6 ZW |
16070 | { |
16071 | rs6000_gen_section_name (&xcoff_bss_section_name, | |
16072 | main_input_filename, ".bss_"); | |
16073 | rs6000_gen_section_name (&xcoff_private_data_section_name, | |
16074 | main_input_filename, ".rw_"); | |
16075 | rs6000_gen_section_name (&xcoff_read_only_section_name, | |
16076 | main_input_filename, ".ro_"); | |
16077 | ||
16078 | fputs ("\t.file\t", asm_out_file); | |
16079 | output_quoted_string (asm_out_file, main_input_filename); | |
16080 | fputc ('\n', asm_out_file); | |
16081 | toc_section (); | |
16082 | if (write_symbols != NO_DEBUG) | |
16083 | private_data_section (); | |
16084 | text_section (); | |
16085 | if (profile_flag) | |
16086 | fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT); | |
16087 | rs6000_file_start (); | |
16088 | } | |
16089 | ||
a5fe455b ZW |
16090 | /* Output at end of assembler file. |
16091 | On the RS/6000, referencing data should automatically pull in text. */ | |
16092 | ||
16093 | static void | |
863d938c | 16094 | rs6000_xcoff_file_end (void) |
a5fe455b ZW |
16095 | { |
16096 | text_section (); | |
16097 | fputs ("_section_.text:\n", asm_out_file); | |
16098 | data_section (); | |
16099 | fputs (TARGET_32BIT | |
16100 | ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", | |
16101 | asm_out_file); | |
16102 | } | |
f1384257 | 16103 | #endif /* TARGET_XCOFF */ |
0e5dbd9b | 16104 | |
f1384257 AM |
16105 | #if TARGET_MACHO |
16106 | /* Cross-module name binding. Darwin does not support overriding | |
7f3d8013 | 16107 | functions at dynamic-link time. */ |
0e5dbd9b | 16108 | |
2bcc50d0 | 16109 | static bool |
a2369ed3 | 16110 | rs6000_binds_local_p (tree decl) |
0e5dbd9b | 16111 | { |
f1384257 | 16112 | return default_binds_local_p_1 (decl, 0); |
0e5dbd9b | 16113 | } |
f1384257 | 16114 | #endif |
34bb030a | 16115 | |
3c50106f RH |
16116 | /* Compute a (partial) cost for rtx X. Return true if the complete |
16117 | cost has been computed, and false if subexpressions should be | |
16118 | scanned. In either case, *TOTAL contains the cost result. */ | |
16119 | ||
16120 | static bool | |
a2369ed3 DJ |
16121 | rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, |
16122 | int *total) | |
3c50106f RH |
16123 | { |
16124 | switch (code) | |
16125 | { | |
16126 | /* On the RS/6000, if it is valid in the insn, it is free. | |
16127 | So this always returns 0. */ | |
16128 | case CONST_INT: | |
16129 | case CONST: | |
16130 | case LABEL_REF: | |
16131 | case SYMBOL_REF: | |
16132 | case CONST_DOUBLE: | |
16133 | case HIGH: | |
16134 | *total = 0; | |
16135 | return true; | |
16136 | ||
16137 | case PLUS: | |
16138 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
16139 | && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) | |
16140 | + 0x8000) >= 0x10000) | |
16141 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
16142 | ? COSTS_N_INSNS (2) | |
16143 | : COSTS_N_INSNS (1)); | |
16144 | return true; | |
16145 | ||
16146 | case AND: | |
16147 | case IOR: | |
16148 | case XOR: | |
16149 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
16150 | && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0 | |
16151 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
16152 | ? COSTS_N_INSNS (2) | |
16153 | : COSTS_N_INSNS (1)); | |
16154 | return true; | |
16155 | ||
16156 | case MULT: | |
16157 | if (optimize_size) | |
16158 | { | |
16159 | *total = COSTS_N_INSNS (2); | |
16160 | return true; | |
16161 | } | |
16162 | switch (rs6000_cpu) | |
16163 | { | |
16164 | case PROCESSOR_RIOS1: | |
16165 | case PROCESSOR_PPC405: | |
16166 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16167 | ? COSTS_N_INSNS (5) | |
16168 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16169 | && INTVAL (XEXP (x, 1)) <= 255) | |
16170 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
16171 | return true; | |
16172 | ||
02ca7595 DE |
16173 | case PROCESSOR_PPC440: |
16174 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16175 | ? COSTS_N_INSNS (3) | |
16176 | : COSTS_N_INSNS (2)); | |
16177 | return true; | |
16178 | ||
3c50106f RH |
16179 | case PROCESSOR_RS64A: |
16180 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16181 | ? GET_MODE (XEXP (x, 1)) != DImode | |
16182 | ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34) | |
16183 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16184 | && INTVAL (XEXP (x, 1)) <= 255) | |
16185 | ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12)); | |
16186 | return true; | |
16187 | ||
16188 | case PROCESSOR_RIOS2: | |
16189 | case PROCESSOR_MPCCORE: | |
16190 | case PROCESSOR_PPC604e: | |
16191 | *total = COSTS_N_INSNS (2); | |
16192 | return true; | |
16193 | ||
16194 | case PROCESSOR_PPC601: | |
16195 | *total = COSTS_N_INSNS (5); | |
16196 | return true; | |
16197 | ||
16198 | case PROCESSOR_PPC603: | |
16199 | case PROCESSOR_PPC7400: | |
16200 | case PROCESSOR_PPC750: | |
16201 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16202 | ? COSTS_N_INSNS (5) | |
16203 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16204 | && INTVAL (XEXP (x, 1)) <= 255) | |
16205 | ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3)); | |
16206 | return true; | |
16207 | ||
16208 | case PROCESSOR_PPC7450: | |
16209 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16210 | ? COSTS_N_INSNS (4) | |
16211 | : COSTS_N_INSNS (3)); | |
16212 | return true; | |
16213 | ||
16214 | case PROCESSOR_PPC403: | |
16215 | case PROCESSOR_PPC604: | |
16216 | case PROCESSOR_PPC8540: | |
16217 | *total = COSTS_N_INSNS (4); | |
16218 | return true; | |
16219 | ||
16220 | case PROCESSOR_PPC620: | |
16221 | case PROCESSOR_PPC630: | |
3c50106f RH |
16222 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT |
16223 | ? GET_MODE (XEXP (x, 1)) != DImode | |
16224 | ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7) | |
16225 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16226 | && INTVAL (XEXP (x, 1)) <= 255) | |
16227 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
16228 | return true; | |
16229 | ||
9259f3b0 | 16230 | case PROCESSOR_POWER4: |
ec507f2d | 16231 | case PROCESSOR_POWER5: |
9259f3b0 DE |
16232 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT |
16233 | ? GET_MODE (XEXP (x, 1)) != DImode | |
984e25ac DE |
16234 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4) |
16235 | : COSTS_N_INSNS (2)); | |
9259f3b0 DE |
16236 | return true; |
16237 | ||
3c50106f RH |
16238 | default: |
16239 | abort (); | |
16240 | } | |
16241 | ||
16242 | case DIV: | |
16243 | case MOD: | |
16244 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
16245 | && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) | |
16246 | { | |
16247 | *total = COSTS_N_INSNS (2); | |
16248 | return true; | |
16249 | } | |
5efb1046 | 16250 | /* FALLTHRU */ |
3c50106f RH |
16251 | |
16252 | case UDIV: | |
16253 | case UMOD: | |
16254 | switch (rs6000_cpu) | |
16255 | { | |
16256 | case PROCESSOR_RIOS1: | |
16257 | *total = COSTS_N_INSNS (19); | |
16258 | return true; | |
16259 | ||
16260 | case PROCESSOR_RIOS2: | |
16261 | *total = COSTS_N_INSNS (13); | |
16262 | return true; | |
16263 | ||
16264 | case PROCESSOR_RS64A: | |
16265 | *total = (GET_MODE (XEXP (x, 1)) != DImode | |
16266 | ? COSTS_N_INSNS (65) | |
16267 | : COSTS_N_INSNS (67)); | |
16268 | return true; | |
16269 | ||
16270 | case PROCESSOR_MPCCORE: | |
16271 | *total = COSTS_N_INSNS (6); | |
16272 | return true; | |
16273 | ||
16274 | case PROCESSOR_PPC403: | |
16275 | *total = COSTS_N_INSNS (33); | |
16276 | return true; | |
16277 | ||
16278 | case PROCESSOR_PPC405: | |
16279 | *total = COSTS_N_INSNS (35); | |
16280 | return true; | |
16281 | ||
02ca7595 DE |
16282 | case PROCESSOR_PPC440: |
16283 | *total = COSTS_N_INSNS (34); | |
16284 | return true; | |
16285 | ||
3c50106f RH |
16286 | case PROCESSOR_PPC601: |
16287 | *total = COSTS_N_INSNS (36); | |
16288 | return true; | |
16289 | ||
16290 | case PROCESSOR_PPC603: | |
16291 | *total = COSTS_N_INSNS (37); | |
16292 | return true; | |
16293 | ||
16294 | case PROCESSOR_PPC604: | |
16295 | case PROCESSOR_PPC604e: | |
16296 | *total = COSTS_N_INSNS (20); | |
16297 | return true; | |
16298 | ||
16299 | case PROCESSOR_PPC620: | |
16300 | case PROCESSOR_PPC630: | |
3c50106f RH |
16301 | *total = (GET_MODE (XEXP (x, 1)) != DImode |
16302 | ? COSTS_N_INSNS (21) | |
16303 | : COSTS_N_INSNS (37)); | |
16304 | return true; | |
16305 | ||
16306 | case PROCESSOR_PPC750: | |
16307 | case PROCESSOR_PPC8540: | |
16308 | case PROCESSOR_PPC7400: | |
16309 | *total = COSTS_N_INSNS (19); | |
16310 | return true; | |
16311 | ||
16312 | case PROCESSOR_PPC7450: | |
16313 | *total = COSTS_N_INSNS (23); | |
16314 | return true; | |
984e25ac DE |
16315 | |
16316 | case PROCESSOR_POWER4: | |
ec507f2d | 16317 | case PROCESSOR_POWER5: |
984e25ac DE |
16318 | *total = (GET_MODE (XEXP (x, 1)) != DImode |
16319 | ? COSTS_N_INSNS (18) | |
16320 | : COSTS_N_INSNS (34)); | |
16321 | return true; | |
3c50106f RH |
16322 | |
16323 | default: | |
16324 | abort (); | |
16325 | } | |
16326 | ||
16327 | case FFS: | |
16328 | *total = COSTS_N_INSNS (4); | |
16329 | return true; | |
16330 | ||
16331 | case MEM: | |
a3c9585f | 16332 | /* MEM should be slightly more expensive than (plus (reg) (const)). */ |
3c50106f RH |
16333 | *total = 5; |
16334 | return true; | |
16335 | ||
16336 | default: | |
16337 | return false; | |
16338 | } | |
16339 | } | |
16340 | ||
34bb030a DE |
16341 | /* A C expression returning the cost of moving data from a register of class |
16342 | CLASS1 to one of CLASS2. */ | |
16343 | ||
16344 | int | |
a2369ed3 DJ |
16345 | rs6000_register_move_cost (enum machine_mode mode, |
16346 | enum reg_class from, enum reg_class to) | |
34bb030a DE |
16347 | { |
16348 | /* Moves from/to GENERAL_REGS. */ | |
16349 | if (reg_classes_intersect_p (to, GENERAL_REGS) | |
16350 | || reg_classes_intersect_p (from, GENERAL_REGS)) | |
16351 | { | |
16352 | if (! reg_classes_intersect_p (to, GENERAL_REGS)) | |
16353 | from = to; | |
16354 | ||
16355 | if (from == FLOAT_REGS || from == ALTIVEC_REGS) | |
16356 | return (rs6000_memory_move_cost (mode, from, 0) | |
16357 | + rs6000_memory_move_cost (mode, GENERAL_REGS, 0)); | |
16358 | ||
a3c9585f | 16359 | /* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */ |
34bb030a DE |
16360 | else if (from == CR_REGS) |
16361 | return 4; | |
16362 | ||
16363 | else | |
16364 | /* A move will cost one instruction per GPR moved. */ | |
16365 | return 2 * HARD_REGNO_NREGS (0, mode); | |
16366 | } | |
16367 | ||
16368 | /* Moving between two similar registers is just one instruction. */ | |
16369 | else if (reg_classes_intersect_p (to, from)) | |
16370 | return mode == TFmode ? 4 : 2; | |
16371 | ||
16372 | /* Everything else has to go through GENERAL_REGS. */ | |
16373 | else | |
16374 | return (rs6000_register_move_cost (mode, GENERAL_REGS, to) | |
16375 | + rs6000_register_move_cost (mode, from, GENERAL_REGS)); | |
16376 | } | |
16377 | ||
16378 | /* A C expressions returning the cost of moving data of MODE from a register to | |
16379 | or from memory. */ | |
16380 | ||
16381 | int | |
a2369ed3 DJ |
16382 | rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class, |
16383 | int in ATTRIBUTE_UNUSED) | |
34bb030a DE |
16384 | { |
16385 | if (reg_classes_intersect_p (class, GENERAL_REGS)) | |
16386 | return 4 * HARD_REGNO_NREGS (0, mode); | |
16387 | else if (reg_classes_intersect_p (class, FLOAT_REGS)) | |
16388 | return 4 * HARD_REGNO_NREGS (32, mode); | |
16389 | else if (reg_classes_intersect_p (class, ALTIVEC_REGS)) | |
16390 | return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode); | |
16391 | else | |
16392 | return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS); | |
16393 | } | |
16394 | ||
ded9bf77 AH |
16395 | /* Return an RTX representing where to find the function value of a |
16396 | function returning MODE. */ | |
16397 | static rtx | |
16398 | rs6000_complex_function_value (enum machine_mode mode) | |
16399 | { | |
16400 | unsigned int regno; | |
16401 | rtx r1, r2; | |
16402 | enum machine_mode inner = GET_MODE_INNER (mode); | |
fb7e4164 | 16403 | unsigned int inner_bytes = GET_MODE_SIZE (inner); |
ded9bf77 | 16404 | |
4ed78545 | 16405 | if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS) |
ded9bf77 AH |
16406 | regno = FP_ARG_RETURN; |
16407 | else | |
16408 | { | |
16409 | regno = GP_ARG_RETURN; | |
16410 | ||
16411 | /* 32-bit is OK since it'll go in r3/r4. */ | |
fb7e4164 | 16412 | if (TARGET_32BIT && inner_bytes >= 4) |
ded9bf77 AH |
16413 | return gen_rtx_REG (mode, regno); |
16414 | } | |
16415 | ||
fb7e4164 AM |
16416 | if (inner_bytes >= 8) |
16417 | return gen_rtx_REG (mode, regno); | |
16418 | ||
ded9bf77 AH |
16419 | r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno), |
16420 | const0_rtx); | |
16421 | r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1), | |
fb7e4164 | 16422 | GEN_INT (inner_bytes)); |
ded9bf77 AH |
16423 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); |
16424 | } | |
16425 | ||
a6ebc39a AH |
16426 | /* Define how to find the value returned by a function. |
16427 | VALTYPE is the data type of the value (as a tree). | |
16428 | If the precise function being called is known, FUNC is its FUNCTION_DECL; | |
16429 | otherwise, FUNC is 0. | |
16430 | ||
16431 | On the SPE, both FPs and vectors are returned in r3. | |
16432 | ||
16433 | On RS/6000 an integer value is in r3 and a floating-point value is in | |
16434 | fp1, unless -msoft-float. */ | |
16435 | ||
16436 | rtx | |
16437 | rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED) | |
16438 | { | |
16439 | enum machine_mode mode; | |
2a8fa26c | 16440 | unsigned int regno; |
a6ebc39a | 16441 | |
0e67400a FJ |
16442 | if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode) |
16443 | { | |
16444 | /* Long long return value need be split in -mpowerpc64, 32bit ABI. */ | |
16445 | return gen_rtx_PARALLEL (DImode, | |
16446 | gen_rtvec (2, | |
16447 | gen_rtx_EXPR_LIST (VOIDmode, | |
16448 | gen_rtx_REG (SImode, GP_ARG_RETURN), | |
16449 | const0_rtx), | |
16450 | gen_rtx_EXPR_LIST (VOIDmode, | |
16451 | gen_rtx_REG (SImode, | |
16452 | GP_ARG_RETURN + 1), | |
16453 | GEN_INT (4)))); | |
16454 | } | |
16455 | ||
a6ebc39a AH |
16456 | if ((INTEGRAL_TYPE_P (valtype) |
16457 | && TYPE_PRECISION (valtype) < BITS_PER_WORD) | |
16458 | || POINTER_TYPE_P (valtype)) | |
b78d48dd | 16459 | mode = TARGET_32BIT ? SImode : DImode; |
a6ebc39a AH |
16460 | else |
16461 | mode = TYPE_MODE (valtype); | |
16462 | ||
4ed78545 | 16463 | if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS) |
2a8fa26c | 16464 | regno = FP_ARG_RETURN; |
ded9bf77 | 16465 | else if (TREE_CODE (valtype) == COMPLEX_TYPE |
42ba5130 | 16466 | && targetm.calls.split_complex_arg) |
ded9bf77 | 16467 | return rs6000_complex_function_value (mode); |
44688022 AM |
16468 | else if (TREE_CODE (valtype) == VECTOR_TYPE |
16469 | && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI) | |
a6ebc39a AH |
16470 | regno = ALTIVEC_ARG_RETURN; |
16471 | else | |
16472 | regno = GP_ARG_RETURN; | |
16473 | ||
16474 | return gen_rtx_REG (mode, regno); | |
16475 | } | |
16476 | ||
ded9bf77 AH |
16477 | /* Define how to find the value returned by a library function |
16478 | assuming the value has mode MODE. */ | |
16479 | rtx | |
16480 | rs6000_libcall_value (enum machine_mode mode) | |
16481 | { | |
16482 | unsigned int regno; | |
16483 | ||
16484 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
16485 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
16486 | regno = FP_ARG_RETURN; | |
44688022 AM |
16487 | else if (ALTIVEC_VECTOR_MODE (mode) |
16488 | && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI) | |
ded9bf77 | 16489 | regno = ALTIVEC_ARG_RETURN; |
42ba5130 | 16490 | else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg) |
ded9bf77 AH |
16491 | return rs6000_complex_function_value (mode); |
16492 | else | |
16493 | regno = GP_ARG_RETURN; | |
16494 | ||
16495 | return gen_rtx_REG (mode, regno); | |
16496 | } | |
16497 | ||
d1d0c603 JJ |
16498 | /* Define the offset between two registers, FROM to be eliminated and its |
16499 | replacement TO, at the start of a routine. */ | |
16500 | HOST_WIDE_INT | |
16501 | rs6000_initial_elimination_offset (int from, int to) | |
16502 | { | |
16503 | rs6000_stack_t *info = rs6000_stack_info (); | |
16504 | HOST_WIDE_INT offset; | |
16505 | ||
16506 | if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
16507 | offset = info->push_p ? 0 : -info->total_size; | |
16508 | else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) | |
16509 | offset = info->total_size; | |
16510 | else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
16511 | offset = info->push_p ? info->total_size : 0; | |
16512 | else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM) | |
16513 | offset = 0; | |
16514 | else | |
16515 | abort (); | |
16516 | ||
16517 | return offset; | |
16518 | } | |
16519 | ||
62e1dfcf NC |
16520 | /* Return true if TYPE is of type __ev64_opaque__. */ |
16521 | ||
c8e4f0e9 | 16522 | static bool |
a2369ed3 | 16523 | is_ev64_opaque_type (tree type) |
62e1dfcf | 16524 | { |
c8e4f0e9 | 16525 | return (TARGET_SPE |
2abe3e28 AH |
16526 | && (type == opaque_V2SI_type_node |
16527 | || type == opaque_V2SF_type_node | |
36252949 | 16528 | || type == opaque_p_V2SI_type_node)); |
62e1dfcf NC |
16529 | } |
16530 | ||
96714395 | 16531 | static rtx |
a2369ed3 | 16532 | rs6000_dwarf_register_span (rtx reg) |
96714395 AH |
16533 | { |
16534 | unsigned regno; | |
16535 | ||
16536 | if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg))) | |
16537 | return NULL_RTX; | |
16538 | ||
16539 | regno = REGNO (reg); | |
16540 | ||
16541 | /* The duality of the SPE register size wreaks all kinds of havoc. | |
16542 | This is a way of distinguishing r0 in 32-bits from r0 in | |
16543 | 64-bits. */ | |
16544 | return | |
16545 | gen_rtx_PARALLEL (VOIDmode, | |
3bd104d1 AH |
16546 | BYTES_BIG_ENDIAN |
16547 | ? gen_rtvec (2, | |
16548 | gen_rtx_REG (SImode, regno + 1200), | |
16549 | gen_rtx_REG (SImode, regno)) | |
16550 | : gen_rtvec (2, | |
16551 | gen_rtx_REG (SImode, regno), | |
16552 | gen_rtx_REG (SImode, regno + 1200))); | |
96714395 AH |
16553 | } |
16554 | ||
93c9d1ba AM |
16555 | /* Map internal gcc register numbers to DWARF2 register numbers. */ |
16556 | ||
16557 | unsigned int | |
16558 | rs6000_dbx_register_number (unsigned int regno) | |
16559 | { | |
16560 | if (regno <= 63 || write_symbols != DWARF2_DEBUG) | |
16561 | return regno; | |
16562 | if (regno == MQ_REGNO) | |
16563 | return 100; | |
16564 | if (regno == LINK_REGISTER_REGNUM) | |
16565 | return 108; | |
16566 | if (regno == COUNT_REGISTER_REGNUM) | |
16567 | return 109; | |
16568 | if (CR_REGNO_P (regno)) | |
16569 | return regno - CR0_REGNO + 86; | |
16570 | if (regno == XER_REGNO) | |
16571 | return 101; | |
16572 | if (ALTIVEC_REGNO_P (regno)) | |
16573 | return regno - FIRST_ALTIVEC_REGNO + 1124; | |
16574 | if (regno == VRSAVE_REGNO) | |
16575 | return 356; | |
16576 | if (regno == VSCR_REGNO) | |
16577 | return 67; | |
16578 | if (regno == SPE_ACC_REGNO) | |
16579 | return 99; | |
16580 | if (regno == SPEFSCR_REGNO) | |
16581 | return 612; | |
16582 | /* SPE high reg number. We get these values of regno from | |
16583 | rs6000_dwarf_register_span. */ | |
16584 | if (regno >= 1200 && regno < 1232) | |
16585 | return regno; | |
16586 | ||
16587 | abort (); | |
16588 | } | |
16589 | ||
17211ab5 | 16590 | #include "gt-rs6000.h" |