]>
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" |
cd3ce9b4 | 55 | #include "tree-gimple.h" |
1bc7c5b6 ZW |
56 | #if TARGET_XCOFF |
57 | #include "xcoffout.h" /* get declarations of xcoff_*_section_name */ | |
58 | #endif | |
9b30bae2 | 59 | |
7509c759 MM |
60 | #ifndef TARGET_NO_PROTOTYPE |
61 | #define TARGET_NO_PROTOTYPE 0 | |
62 | #endif | |
63 | ||
452a7d36 HP |
64 | #define EASY_VECTOR_15(n) ((n) >= -16 && (n) <= 15) |
65 | #define EASY_VECTOR_15_ADD_SELF(n) ((n) >= 0x10 && (n) <= 0x1e \ | |
66 | && !((n) & 1)) | |
d744e06e | 67 | |
9878760c RK |
68 | #define min(A,B) ((A) < (B) ? (A) : (B)) |
69 | #define max(A,B) ((A) > (B) ? (A) : (B)) | |
70 | ||
d1d0c603 JJ |
71 | /* Structure used to define the rs6000 stack */ |
72 | typedef struct rs6000_stack { | |
73 | int first_gp_reg_save; /* first callee saved GP register used */ | |
74 | int first_fp_reg_save; /* first callee saved FP register used */ | |
75 | int first_altivec_reg_save; /* first callee saved AltiVec register used */ | |
76 | int lr_save_p; /* true if the link reg needs to be saved */ | |
77 | int cr_save_p; /* true if the CR reg needs to be saved */ | |
78 | unsigned int vrsave_mask; /* mask of vec registers to save */ | |
79 | int toc_save_p; /* true if the TOC needs to be saved */ | |
80 | int push_p; /* true if we need to allocate stack space */ | |
81 | int calls_p; /* true if the function makes any calls */ | |
82 | enum rs6000_abi abi; /* which ABI to use */ | |
83 | int gp_save_offset; /* offset to save GP regs from initial SP */ | |
84 | int fp_save_offset; /* offset to save FP regs from initial SP */ | |
85 | int altivec_save_offset; /* offset to save AltiVec regs from initial SP */ | |
86 | int lr_save_offset; /* offset to save LR from initial SP */ | |
87 | int cr_save_offset; /* offset to save CR from initial SP */ | |
88 | int vrsave_save_offset; /* offset to save VRSAVE from initial SP */ | |
89 | int spe_gp_save_offset; /* offset to save spe 64-bit gprs */ | |
90 | int toc_save_offset; /* offset to save the TOC pointer */ | |
91 | int varargs_save_offset; /* offset to save the varargs registers */ | |
92 | int ehrd_offset; /* offset to EH return data */ | |
93 | int reg_size; /* register size (4 or 8) */ | |
94 | int varargs_size; /* size to hold V.4 args passed in regs */ | |
95 | HOST_WIDE_INT vars_size; /* variable save area size */ | |
96 | int parm_size; /* outgoing parameter size */ | |
97 | int save_size; /* save area size */ | |
98 | int fixed_size; /* fixed size of stack frame */ | |
99 | int gp_size; /* size of saved GP registers */ | |
100 | int fp_size; /* size of saved FP registers */ | |
101 | int altivec_size; /* size of saved AltiVec registers */ | |
102 | int cr_size; /* size to hold CR if not in save_size */ | |
103 | int lr_size; /* size to hold LR if not in save_size */ | |
104 | int vrsave_size; /* size to hold VRSAVE if not in save_size */ | |
105 | int altivec_padding_size; /* size of altivec alignment padding if | |
106 | not in save_size */ | |
107 | int spe_gp_size; /* size of 64-bit GPR save size for SPE */ | |
108 | int spe_padding_size; | |
109 | int toc_size; /* size to hold TOC if not in save_size */ | |
110 | HOST_WIDE_INT total_size; /* total bytes allocated for stack */ | |
111 | int spe_64bit_regs_used; | |
112 | } rs6000_stack_t; | |
113 | ||
5248c961 RK |
114 | /* Target cpu type */ |
115 | ||
116 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
117 | struct rs6000_cpu_select rs6000_select[3] = |
118 | { | |
815cdc52 MM |
119 | /* switch name, tune arch */ |
120 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
121 | { (const char *)0, "-mcpu=", 1, 1 }, | |
122 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 123 | }; |
5248c961 | 124 | |
ec507f2d DE |
125 | /* Always emit branch hint bits. */ |
126 | static GTY(()) bool rs6000_always_hint; | |
127 | ||
128 | /* Schedule instructions for group formation. */ | |
129 | static GTY(()) bool rs6000_sched_groups; | |
130 | ||
79ae11c4 DN |
131 | /* Support adjust_priority scheduler hook |
132 | and -mprioritize-restricted-insns= option. */ | |
133 | const char *rs6000_sched_restricted_insns_priority_str; | |
134 | int rs6000_sched_restricted_insns_priority; | |
135 | ||
569fa502 DN |
136 | /* Support for -msched-costly-dep option. */ |
137 | const char *rs6000_sched_costly_dep_str; | |
138 | enum rs6000_dependence_cost rs6000_sched_costly_dep; | |
139 | ||
cbe26ab8 DN |
140 | /* Support for -minsert-sched-nops option. */ |
141 | const char *rs6000_sched_insert_nops_str; | |
142 | enum rs6000_nop_insertion rs6000_sched_insert_nops; | |
143 | ||
6fa3f289 ZW |
144 | /* Size of long double */ |
145 | const char *rs6000_long_double_size_string; | |
146 | int rs6000_long_double_type_size; | |
147 | ||
148 | /* Whether -mabi=altivec has appeared */ | |
149 | int rs6000_altivec_abi; | |
150 | ||
08b57fb3 AH |
151 | /* Whether VRSAVE instructions should be generated. */ |
152 | int rs6000_altivec_vrsave; | |
153 | ||
154 | /* String from -mvrsave= option. */ | |
155 | const char *rs6000_altivec_vrsave_string; | |
156 | ||
a3170dc6 AH |
157 | /* Nonzero if we want SPE ABI extensions. */ |
158 | int rs6000_spe_abi; | |
159 | ||
160 | /* Whether isel instructions should be generated. */ | |
161 | int rs6000_isel; | |
162 | ||
993f19a8 AH |
163 | /* Whether SPE simd instructions should be generated. */ |
164 | int rs6000_spe; | |
165 | ||
5da702b1 AH |
166 | /* Nonzero if floating point operations are done in the GPRs. */ |
167 | int rs6000_float_gprs = 0; | |
168 | ||
169 | /* String from -mfloat-gprs=. */ | |
170 | const char *rs6000_float_gprs_string; | |
a3170dc6 AH |
171 | |
172 | /* String from -misel=. */ | |
173 | const char *rs6000_isel_string; | |
174 | ||
993f19a8 AH |
175 | /* String from -mspe=. */ |
176 | const char *rs6000_spe_string; | |
177 | ||
a0ab749a | 178 | /* Set to nonzero once AIX common-mode calls have been defined. */ |
bbfb86aa | 179 | static GTY(()) int common_mode_defined; |
c81bebd7 | 180 | |
9878760c RK |
181 | /* Save information from a "cmpxx" operation until the branch or scc is |
182 | emitted. */ | |
9878760c RK |
183 | rtx rs6000_compare_op0, rs6000_compare_op1; |
184 | int rs6000_compare_fp_p; | |
874a0744 | 185 | |
874a0744 MM |
186 | /* Label number of label created for -mrelocatable, to call to so we can |
187 | get the address of the GOT section */ | |
188 | int rs6000_pic_labelno; | |
c81bebd7 | 189 | |
b91da81f | 190 | #ifdef USING_ELFOS_H |
c81bebd7 | 191 | /* Which abi to adhere to */ |
9739c90c | 192 | const char *rs6000_abi_name; |
d9407988 MM |
193 | |
194 | /* Semantics of the small data area */ | |
195 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
196 | ||
197 | /* Which small data model to use */ | |
815cdc52 | 198 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
199 | |
200 | /* Counter for labels which are to be placed in .fixup. */ | |
201 | int fixuplabelno = 0; | |
874a0744 | 202 | #endif |
4697a36c | 203 | |
c4501e62 JJ |
204 | /* Bit size of immediate TLS offsets and string from which it is decoded. */ |
205 | int rs6000_tls_size = 32; | |
206 | const char *rs6000_tls_size_string; | |
207 | ||
b6c9286a MM |
208 | /* ABI enumeration available for subtarget to use. */ |
209 | enum rs6000_abi rs6000_current_abi; | |
210 | ||
0ac081f6 AH |
211 | /* ABI string from -mabi= option. */ |
212 | const char *rs6000_abi_string; | |
213 | ||
38c1f2d7 | 214 | /* Debug flags */ |
815cdc52 | 215 | const char *rs6000_debug_name; |
38c1f2d7 MM |
216 | int rs6000_debug_stack; /* debug stack applications */ |
217 | int rs6000_debug_arg; /* debug argument handling */ | |
218 | ||
0d1fbc8c AH |
219 | /* Value is TRUE if register/mode pair is accepatable. */ |
220 | bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER]; | |
221 | ||
6035d635 | 222 | /* Opaque types. */ |
2abe3e28 | 223 | static GTY(()) tree opaque_V2SI_type_node; |
2abe3e28 | 224 | static GTY(()) tree opaque_V2SF_type_node; |
6035d635 | 225 | static GTY(()) tree opaque_p_V2SI_type_node; |
4a5eab38 PB |
226 | static GTY(()) tree V16QI_type_node; |
227 | static GTY(()) tree V2SI_type_node; | |
228 | static GTY(()) tree V2SF_type_node; | |
229 | static GTY(()) tree V4HI_type_node; | |
230 | static GTY(()) tree V4SI_type_node; | |
231 | static GTY(()) tree V4SF_type_node; | |
232 | static GTY(()) tree V8HI_type_node; | |
233 | static GTY(()) tree unsigned_V16QI_type_node; | |
234 | static GTY(()) tree unsigned_V8HI_type_node; | |
235 | static GTY(()) tree unsigned_V4SI_type_node; | |
8bb418a3 ZL |
236 | static GTY(()) tree bool_char_type_node; /* __bool char */ |
237 | static GTY(()) tree bool_short_type_node; /* __bool short */ | |
238 | static GTY(()) tree bool_int_type_node; /* __bool int */ | |
239 | static GTY(()) tree pixel_type_node; /* __pixel */ | |
240 | static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */ | |
241 | static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */ | |
242 | static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */ | |
243 | static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */ | |
244 | ||
245 | int rs6000_warn_altivec_long = 1; /* On by default. */ | |
246 | const char *rs6000_warn_altivec_long_switch; | |
247 | ||
57ac7be9 AM |
248 | const char *rs6000_traceback_name; |
249 | static enum { | |
250 | traceback_default = 0, | |
251 | traceback_none, | |
252 | traceback_part, | |
253 | traceback_full | |
254 | } rs6000_traceback; | |
255 | ||
38c1f2d7 MM |
256 | /* Flag to say the TOC is initialized */ |
257 | int toc_initialized; | |
9ebbca7d | 258 | char toc_label_name[10]; |
38c1f2d7 | 259 | |
9ebbca7d | 260 | /* Alias set for saves and restores from the rs6000 stack. */ |
f103e34d | 261 | static GTY(()) int rs6000_sr_alias_set; |
c8023011 | 262 | |
a5c76ee6 ZW |
263 | /* Call distance, overridden by -mlongcall and #pragma longcall(1). |
264 | The only place that looks at this is rs6000_set_default_type_attributes; | |
265 | everywhere else should rely on the presence or absence of a longcall | |
266 | attribute on the function declaration. */ | |
267 | int rs6000_default_long_calls; | |
268 | const char *rs6000_longcall_switch; | |
269 | ||
a3c9585f KH |
270 | /* Control alignment for fields within structures. */ |
271 | /* String from -malign-XXXXX. */ | |
025d9908 KH |
272 | const char *rs6000_alignment_string; |
273 | int rs6000_alignment_flags; | |
274 | ||
a3170dc6 AH |
275 | struct builtin_description |
276 | { | |
277 | /* mask is not const because we're going to alter it below. This | |
278 | nonsense will go away when we rewrite the -march infrastructure | |
279 | to give us more target flag bits. */ | |
280 | unsigned int mask; | |
281 | const enum insn_code icode; | |
282 | const char *const name; | |
283 | const enum rs6000_builtins code; | |
284 | }; | |
285 | ||
a2369ed3 DJ |
286 | static bool rs6000_function_ok_for_sibcall (tree, tree); |
287 | static int num_insns_constant_wide (HOST_WIDE_INT); | |
288 | static void validate_condition_mode (enum rtx_code, enum machine_mode); | |
289 | static rtx rs6000_generate_compare (enum rtx_code); | |
290 | static void rs6000_maybe_dead (rtx); | |
291 | static void rs6000_emit_stack_tie (void); | |
292 | static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx); | |
293 | static rtx spe_synthesize_frame_save (rtx); | |
294 | static bool spe_func_has_64bit_regs_p (void); | |
b20a9cca | 295 | static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int, |
d1d0c603 | 296 | int, HOST_WIDE_INT); |
a2369ed3 DJ |
297 | static rtx gen_frame_mem_offset (enum machine_mode, rtx, int); |
298 | static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int); | |
299 | static unsigned rs6000_hash_constant (rtx); | |
300 | static unsigned toc_hash_function (const void *); | |
301 | static int toc_hash_eq (const void *, const void *); | |
302 | static int constant_pool_expr_1 (rtx, int *, int *); | |
303 | static bool constant_pool_expr_p (rtx); | |
304 | static bool toc_relative_expr_p (rtx); | |
305 | static bool legitimate_small_data_p (enum machine_mode, rtx); | |
a2369ed3 DJ |
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 *); |
76d2b81d | 318 | static void rs6000_eliminate_indexed_memrefs (rtx operands[2]); |
f18eca82 | 319 | static const char *rs6000_mangle_fundamental_type (tree); |
b86fe7b4 | 320 | extern const struct attribute_spec rs6000_attribute_table[]; |
a2369ed3 DJ |
321 | static void rs6000_set_default_type_attributes (tree); |
322 | static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT); | |
323 | static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT); | |
b20a9cca AM |
324 | static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, |
325 | tree); | |
a2369ed3 | 326 | static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT); |
c6e8c921 | 327 | static bool rs6000_return_in_memory (tree, tree); |
a2369ed3 | 328 | static void rs6000_file_start (void); |
7c262518 | 329 | #if TARGET_ELF |
a2369ed3 DJ |
330 | static unsigned int rs6000_elf_section_type_flags (tree, const char *, int); |
331 | static void rs6000_elf_asm_out_constructor (rtx, int); | |
332 | static void rs6000_elf_asm_out_destructor (rtx, int); | |
333 | static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT); | |
334 | static void rs6000_elf_unique_section (tree, int); | |
335 | static void rs6000_elf_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 336 | unsigned HOST_WIDE_INT); |
a56d7372 | 337 | static void rs6000_elf_encode_section_info (tree, rtx, int) |
0e5dbd9b | 338 | ATTRIBUTE_UNUSED; |
a2369ed3 | 339 | static bool rs6000_elf_in_small_data_p (tree); |
7c262518 | 340 | #endif |
cbaaba19 | 341 | #if TARGET_XCOFF |
a2369ed3 DJ |
342 | static void rs6000_xcoff_asm_globalize_label (FILE *, const char *); |
343 | static void rs6000_xcoff_asm_named_section (const char *, unsigned int); | |
344 | static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT); | |
345 | static void rs6000_xcoff_unique_section (tree, int); | |
346 | static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 347 | unsigned HOST_WIDE_INT); |
a2369ed3 DJ |
348 | static const char * rs6000_xcoff_strip_name_encoding (const char *); |
349 | static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int); | |
350 | static void rs6000_xcoff_file_start (void); | |
351 | static void rs6000_xcoff_file_end (void); | |
f1384257 AM |
352 | #endif |
353 | #if TARGET_MACHO | |
a2369ed3 | 354 | static bool rs6000_binds_local_p (tree); |
f1384257 | 355 | #endif |
a2369ed3 DJ |
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); |
ec6376ab | 428 | static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int); |
b1917422 | 429 | static void rs6000_move_block_from_reg (int regno, rtx x, int nregs); |
c6e8c921 GK |
430 | static void setup_incoming_varargs (CUMULATIVE_ARGS *, |
431 | enum machine_mode, tree, | |
432 | int *, int); | |
efdba735 SH |
433 | #if TARGET_MACHO |
434 | static void macho_branch_islands (void); | |
435 | static void add_compiler_branch_island (tree, tree, int); | |
436 | static int no_previous_def (tree function_name); | |
437 | static tree get_prev_label (tree function_name); | |
438 | #endif | |
439 | ||
c35d187f | 440 | static tree rs6000_build_builtin_va_list (void); |
23a60a04 | 441 | static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *); |
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 | 570 | #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE |
11ac38b2 | 571 | #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE hook_int_void_1 |
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 | ||
cd3ce9b4 JM |
650 | #undef TARGET_GIMPLIFY_VA_ARG_EXPR |
651 | #define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg | |
652 | ||
f6897b10 | 653 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 654 | \f |
0d1fbc8c AH |
655 | |
656 | /* Value is 1 if hard register REGNO can hold a value of machine-mode | |
657 | MODE. */ | |
658 | static int | |
659 | rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode) | |
660 | { | |
661 | /* The GPRs can hold any mode, but values bigger than one register | |
662 | cannot go past R31. */ | |
663 | if (INT_REGNO_P (regno)) | |
664 | return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1); | |
665 | ||
666 | /* The float registers can only hold floating modes and DImode. */ | |
667 | if (FP_REGNO_P (regno)) | |
668 | return | |
669 | (GET_MODE_CLASS (mode) == MODE_FLOAT | |
670 | && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1)) | |
671 | || (GET_MODE_CLASS (mode) == MODE_INT | |
672 | && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD); | |
673 | ||
674 | /* The CR register can only hold CC modes. */ | |
675 | if (CR_REGNO_P (regno)) | |
676 | return GET_MODE_CLASS (mode) == MODE_CC; | |
677 | ||
678 | if (XER_REGNO_P (regno)) | |
679 | return mode == PSImode; | |
680 | ||
681 | /* AltiVec only in AldyVec registers. */ | |
682 | if (ALTIVEC_REGNO_P (regno)) | |
683 | return ALTIVEC_VECTOR_MODE (mode); | |
684 | ||
685 | /* ...but GPRs can hold SIMD data on the SPE in one register. */ | |
686 | if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
687 | return 1; | |
688 | ||
689 | /* We cannot put TImode anywhere except general register and it must be | |
690 | able to fit within the register set. */ | |
691 | ||
692 | return GET_MODE_SIZE (mode) <= UNITS_PER_WORD; | |
693 | } | |
694 | ||
695 | /* Initialize rs6000_hard_regno_mode_ok_p table. */ | |
696 | static void | |
697 | rs6000_init_hard_regno_mode_ok (void) | |
698 | { | |
699 | int r, m; | |
700 | ||
701 | for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r) | |
702 | for (m = 0; m < NUM_MACHINE_MODES; ++m) | |
703 | if (rs6000_hard_regno_mode_ok (r, m)) | |
704 | rs6000_hard_regno_mode_ok_p[m][r] = true; | |
705 | } | |
706 | ||
5248c961 RK |
707 | /* Override command line options. Mostly we process the processor |
708 | type and sometimes adjust other TARGET_ options. */ | |
709 | ||
710 | void | |
d779d0dc | 711 | rs6000_override_options (const char *default_cpu) |
5248c961 | 712 | { |
c4d38ccb | 713 | size_t i, j; |
8e3f41e7 | 714 | struct rs6000_cpu_select *ptr; |
66188a7e | 715 | int set_masks; |
5248c961 | 716 | |
66188a7e | 717 | /* Simplifications for entries below. */ |
85638c0d | 718 | |
66188a7e GK |
719 | enum { |
720 | POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS, | |
721 | POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC | |
722 | }; | |
85638c0d | 723 | |
66188a7e GK |
724 | /* This table occasionally claims that a processor does not support |
725 | a particular feature even though it does, but the feature is slower | |
726 | than the alternative. Thus, it shouldn't be relied on as a | |
727 | complete description of the processor's support. | |
728 | ||
729 | Please keep this list in order, and don't forget to update the | |
730 | documentation in invoke.texi when adding a new processor or | |
731 | flag. */ | |
5248c961 RK |
732 | static struct ptt |
733 | { | |
8b60264b KG |
734 | const char *const name; /* Canonical processor name. */ |
735 | const enum processor_type processor; /* Processor type enum value. */ | |
736 | const int target_enable; /* Target flags to enable. */ | |
8b60264b | 737 | } const processor_target_table[] |
66188a7e | 738 | = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, |
49a0b204 | 739 | {"403", PROCESSOR_PPC403, |
66188a7e GK |
740 | POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN}, |
741 | {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
742 | {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK}, | |
743 | {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
744 | {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK}, | |
745 | {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK}, | |
5248c961 | 746 | {"601", PROCESSOR_PPC601, |
66188a7e GK |
747 | MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING}, |
748 | {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
749 | {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
750 | {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
751 | {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
752 | {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
7ddb6568 AM |
753 | {"620", PROCESSOR_PPC620, |
754 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
755 | {"630", PROCESSOR_PPC630, | |
756 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
66188a7e GK |
757 | {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, |
758 | {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK}, | |
759 | {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK}, | |
760 | {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
761 | {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
762 | {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
763 | {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
764 | {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
765 | {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
7177e720 | 766 | {"970", PROCESSOR_POWER4, |
66188a7e GK |
767 | POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64}, |
768 | {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS}, | |
769 | {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
770 | {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
771 | {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK}, | |
49ffe578 | 772 | {"G5", PROCESSOR_POWER4, |
66188a7e GK |
773 | POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64}, |
774 | {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
775 | {"power2", PROCESSOR_POWER, | |
776 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING}, | |
7ddb6568 AM |
777 | {"power3", PROCESSOR_PPC630, |
778 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
779 | {"power4", PROCESSOR_POWER4, | |
fc091c8e | 780 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64}, |
ec507f2d | 781 | {"power5", PROCESSOR_POWER5, |
fc091c8e | 782 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64}, |
66188a7e GK |
783 | {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK}, |
784 | {"powerpc64", PROCESSOR_POWERPC64, | |
785 | POWERPC_BASE_MASK | MASK_POWERPC64}, | |
786 | {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
787 | {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
788 | {"rios2", PROCESSOR_RIOS2, | |
789 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING}, | |
790 | {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
791 | {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
7ddb6568 | 792 | {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64}, |
66188a7e | 793 | }; |
5248c961 | 794 | |
ca7558fc | 795 | const size_t ptt_size = ARRAY_SIZE (processor_target_table); |
5248c961 | 796 | |
66188a7e GK |
797 | /* Some OSs don't support saving the high part of 64-bit registers on |
798 | context switch. Other OSs don't support saving Altivec registers. | |
799 | On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC | |
800 | settings; if the user wants either, the user must explicitly specify | |
801 | them and we won't interfere with the user's specification. */ | |
802 | ||
803 | enum { | |
804 | POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
805 | POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT | |
806 | | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC | |
807 | | MASK_MFCRF) | |
808 | }; | |
0d1fbc8c AH |
809 | |
810 | rs6000_init_hard_regno_mode_ok (); | |
811 | ||
66188a7e GK |
812 | set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT; |
813 | #ifdef OS_MISSING_POWERPC64 | |
814 | if (OS_MISSING_POWERPC64) | |
815 | set_masks &= ~MASK_POWERPC64; | |
816 | #endif | |
817 | #ifdef OS_MISSING_ALTIVEC | |
818 | if (OS_MISSING_ALTIVEC) | |
819 | set_masks &= ~MASK_ALTIVEC; | |
820 | #endif | |
821 | ||
957211c3 AM |
822 | /* Don't override these by the processor default if given explicitly. */ |
823 | set_masks &= ~(target_flags_explicit | |
824 | & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT)); | |
825 | ||
a4f6c312 | 826 | /* Identify the processor type. */ |
8e3f41e7 | 827 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 828 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 829 | |
b6a1cbae | 830 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 831 | { |
8e3f41e7 MM |
832 | ptr = &rs6000_select[i]; |
833 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 834 | { |
8e3f41e7 MM |
835 | for (j = 0; j < ptt_size; j++) |
836 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
837 | { | |
838 | if (ptr->set_tune_p) | |
839 | rs6000_cpu = processor_target_table[j].processor; | |
840 | ||
841 | if (ptr->set_arch_p) | |
842 | { | |
66188a7e GK |
843 | target_flags &= ~set_masks; |
844 | target_flags |= (processor_target_table[j].target_enable | |
845 | & set_masks); | |
8e3f41e7 MM |
846 | } |
847 | break; | |
848 | } | |
849 | ||
4406229e | 850 | if (j == ptt_size) |
8e3f41e7 | 851 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
852 | } |
853 | } | |
8a61d227 | 854 | |
993f19a8 | 855 | if (TARGET_E500) |
a3170dc6 AH |
856 | rs6000_isel = 1; |
857 | ||
dff9f1b6 DE |
858 | /* If we are optimizing big endian systems for space, use the load/store |
859 | multiple and string instructions. */ | |
ef792183 | 860 | if (BYTES_BIG_ENDIAN && optimize_size) |
957211c3 | 861 | target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING); |
938937d8 | 862 | |
a4f6c312 SS |
863 | /* Don't allow -mmultiple or -mstring on little endian systems |
864 | unless the cpu is a 750, because the hardware doesn't support the | |
865 | instructions used in little endian mode, and causes an alignment | |
866 | trap. The 750 does not cause an alignment trap (except when the | |
867 | target is unaligned). */ | |
bef84347 | 868 | |
b21fb038 | 869 | if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
870 | { |
871 | if (TARGET_MULTIPLE) | |
872 | { | |
873 | target_flags &= ~MASK_MULTIPLE; | |
b21fb038 | 874 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
7e69e155 MM |
875 | warning ("-mmultiple is not supported on little endian systems"); |
876 | } | |
877 | ||
878 | if (TARGET_STRING) | |
879 | { | |
880 | target_flags &= ~MASK_STRING; | |
b21fb038 | 881 | if ((target_flags_explicit & MASK_STRING) != 0) |
938937d8 | 882 | warning ("-mstring is not supported on little endian systems"); |
7e69e155 MM |
883 | } |
884 | } | |
3933e0e1 | 885 | |
38c1f2d7 MM |
886 | /* Set debug flags */ |
887 | if (rs6000_debug_name) | |
888 | { | |
bfc79d3b | 889 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 890 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 891 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 892 | rs6000_debug_stack = 1; |
bfc79d3b | 893 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
894 | rs6000_debug_arg = 1; |
895 | else | |
c725bd79 | 896 | error ("unknown -mdebug-%s switch", rs6000_debug_name); |
38c1f2d7 MM |
897 | } |
898 | ||
57ac7be9 AM |
899 | if (rs6000_traceback_name) |
900 | { | |
901 | if (! strncmp (rs6000_traceback_name, "full", 4)) | |
902 | rs6000_traceback = traceback_full; | |
903 | else if (! strncmp (rs6000_traceback_name, "part", 4)) | |
904 | rs6000_traceback = traceback_part; | |
905 | else if (! strncmp (rs6000_traceback_name, "no", 2)) | |
906 | rs6000_traceback = traceback_none; | |
907 | else | |
908 | error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'", | |
909 | rs6000_traceback_name); | |
910 | } | |
911 | ||
6fa3f289 ZW |
912 | /* Set size of long double */ |
913 | rs6000_long_double_type_size = 64; | |
914 | if (rs6000_long_double_size_string) | |
915 | { | |
916 | char *tail; | |
917 | int size = strtol (rs6000_long_double_size_string, &tail, 10); | |
918 | if (*tail != '\0' || (size != 64 && size != 128)) | |
919 | error ("Unknown switch -mlong-double-%s", | |
920 | rs6000_long_double_size_string); | |
921 | else | |
922 | rs6000_long_double_type_size = size; | |
923 | } | |
924 | ||
6d0ef01e HP |
925 | /* Set Altivec ABI as default for powerpc64 linux. */ |
926 | if (TARGET_ELF && TARGET_64BIT) | |
927 | { | |
928 | rs6000_altivec_abi = 1; | |
929 | rs6000_altivec_vrsave = 1; | |
930 | } | |
931 | ||
0ac081f6 AH |
932 | /* Handle -mabi= options. */ |
933 | rs6000_parse_abi_options (); | |
934 | ||
025d9908 KH |
935 | /* Handle -malign-XXXXX option. */ |
936 | rs6000_parse_alignment_option (); | |
937 | ||
5da702b1 AH |
938 | /* Handle generic -mFOO=YES/NO options. */ |
939 | rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string, | |
940 | &rs6000_altivec_vrsave); | |
941 | rs6000_parse_yes_no_option ("isel", rs6000_isel_string, | |
942 | &rs6000_isel); | |
943 | rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe); | |
944 | rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string, | |
945 | &rs6000_float_gprs); | |
993f19a8 | 946 | |
c4501e62 JJ |
947 | /* Handle -mtls-size option. */ |
948 | rs6000_parse_tls_size_option (); | |
949 | ||
a7ae18e2 AH |
950 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
951 | SUBTARGET_OVERRIDE_OPTIONS; | |
952 | #endif | |
953 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS | |
954 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
955 | #endif | |
956 | ||
5da702b1 AH |
957 | if (TARGET_E500) |
958 | { | |
e4463bf1 AH |
959 | if (TARGET_ALTIVEC) |
960 | error ("AltiVec and E500 instructions cannot coexist"); | |
961 | ||
5da702b1 AH |
962 | /* The e500 does not have string instructions, and we set |
963 | MASK_STRING above when optimizing for size. */ | |
964 | if ((target_flags & MASK_STRING) != 0) | |
965 | target_flags = target_flags & ~MASK_STRING; | |
b6e59a3a AH |
966 | |
967 | /* No SPE means 64-bit long doubles, even if an E500. */ | |
968 | if (rs6000_spe_string != 0 | |
969 | && !strcmp (rs6000_spe_string, "no")) | |
970 | rs6000_long_double_type_size = 64; | |
5da702b1 AH |
971 | } |
972 | else if (rs6000_select[1].string != NULL) | |
973 | { | |
974 | /* For the powerpc-eabispe configuration, we set all these by | |
975 | default, so let's unset them if we manually set another | |
976 | CPU that is not the E500. */ | |
977 | if (rs6000_abi_string == 0) | |
978 | rs6000_spe_abi = 0; | |
979 | if (rs6000_spe_string == 0) | |
980 | rs6000_spe = 0; | |
981 | if (rs6000_float_gprs_string == 0) | |
982 | rs6000_float_gprs = 0; | |
983 | if (rs6000_isel_string == 0) | |
984 | rs6000_isel = 0; | |
b6e59a3a AH |
985 | if (rs6000_long_double_size_string == 0) |
986 | rs6000_long_double_type_size = 64; | |
5da702b1 | 987 | } |
b5044283 | 988 | |
ec507f2d DE |
989 | rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4 |
990 | && rs6000_cpu != PROCESSOR_POWER5); | |
991 | rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4 | |
992 | || rs6000_cpu == PROCESSOR_POWER5); | |
993 | ||
a5c76ee6 ZW |
994 | /* Handle -m(no-)longcall option. This is a bit of a cheap hack, |
995 | using TARGET_OPTIONS to handle a toggle switch, but we're out of | |
996 | bits in target_flags so TARGET_SWITCHES cannot be used. | |
997 | Assumption here is that rs6000_longcall_switch points into the | |
998 | text of the complete option, rather than being a copy, so we can | |
999 | scan back for the presence or absence of the no- modifier. */ | |
1000 | if (rs6000_longcall_switch) | |
1001 | { | |
1002 | const char *base = rs6000_longcall_switch; | |
1003 | while (base[-1] != 'm') base--; | |
1004 | ||
1005 | if (*rs6000_longcall_switch != '\0') | |
1006 | error ("invalid option `%s'", base); | |
1007 | rs6000_default_long_calls = (base[0] != 'n'); | |
1008 | } | |
1009 | ||
8bb418a3 ZL |
1010 | /* Handle -m(no-)warn-altivec-long similarly. */ |
1011 | if (rs6000_warn_altivec_long_switch) | |
1012 | { | |
1013 | const char *base = rs6000_warn_altivec_long_switch; | |
1014 | while (base[-1] != 'm') base--; | |
1015 | ||
1016 | if (*rs6000_warn_altivec_long_switch != '\0') | |
1017 | error ("invalid option `%s'", base); | |
1018 | rs6000_warn_altivec_long = (base[0] != 'n'); | |
1019 | } | |
1020 | ||
cbe26ab8 | 1021 | /* Handle -mprioritize-restricted-insns option. */ |
ec507f2d DE |
1022 | rs6000_sched_restricted_insns_priority |
1023 | = (rs6000_sched_groups ? 1 : 0); | |
79ae11c4 DN |
1024 | if (rs6000_sched_restricted_insns_priority_str) |
1025 | rs6000_sched_restricted_insns_priority = | |
1026 | atoi (rs6000_sched_restricted_insns_priority_str); | |
1027 | ||
569fa502 | 1028 | /* Handle -msched-costly-dep option. */ |
ec507f2d DE |
1029 | rs6000_sched_costly_dep |
1030 | = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly); | |
569fa502 DN |
1031 | if (rs6000_sched_costly_dep_str) |
1032 | { | |
1033 | if (! strcmp (rs6000_sched_costly_dep_str, "no")) | |
1034 | rs6000_sched_costly_dep = no_dep_costly; | |
1035 | else if (! strcmp (rs6000_sched_costly_dep_str, "all")) | |
1036 | rs6000_sched_costly_dep = all_deps_costly; | |
1037 | else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load")) | |
1038 | rs6000_sched_costly_dep = true_store_to_load_dep_costly; | |
1039 | else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load")) | |
1040 | rs6000_sched_costly_dep = store_to_load_dep_costly; | |
cbe26ab8 DN |
1041 | else |
1042 | rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str); | |
1043 | } | |
1044 | ||
1045 | /* Handle -minsert-sched-nops option. */ | |
ec507f2d DE |
1046 | rs6000_sched_insert_nops |
1047 | = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none); | |
cbe26ab8 DN |
1048 | if (rs6000_sched_insert_nops_str) |
1049 | { | |
1050 | if (! strcmp (rs6000_sched_insert_nops_str, "no")) | |
1051 | rs6000_sched_insert_nops = sched_finish_none; | |
1052 | else if (! strcmp (rs6000_sched_insert_nops_str, "pad")) | |
1053 | rs6000_sched_insert_nops = sched_finish_pad_groups; | |
1054 | else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact")) | |
1055 | rs6000_sched_insert_nops = sched_finish_regroup_exact; | |
1056 | else | |
1057 | rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str); | |
569fa502 DN |
1058 | } |
1059 | ||
c81bebd7 | 1060 | #ifdef TARGET_REGNAMES |
a4f6c312 SS |
1061 | /* If the user desires alternate register names, copy in the |
1062 | alternate names now. */ | |
c81bebd7 | 1063 | if (TARGET_REGNAMES) |
4e135bdd | 1064 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
1065 | #endif |
1066 | ||
6fa3f289 ZW |
1067 | /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined. |
1068 | If -maix-struct-return or -msvr4-struct-return was explicitly | |
1069 | used, don't override with the ABI default. */ | |
b21fb038 | 1070 | if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0) |
6fa3f289 ZW |
1071 | { |
1072 | if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET) | |
1073 | target_flags = (target_flags & ~MASK_AIX_STRUCT_RET); | |
1074 | else | |
1075 | target_flags |= MASK_AIX_STRUCT_RET; | |
1076 | } | |
1077 | ||
fcce224d DE |
1078 | if (TARGET_LONG_DOUBLE_128 |
1079 | && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)) | |
70a01792 | 1080 | REAL_MODE_FORMAT (TFmode) = &ibm_extended_format; |
fcce224d | 1081 | |
9ebbca7d GK |
1082 | /* Allocate an alias set for register saves & restores from stack. */ |
1083 | rs6000_sr_alias_set = new_alias_set (); | |
1084 | ||
1085 | if (TARGET_TOC) | |
1086 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); | |
71f123ca | 1087 | |
301d03af RS |
1088 | /* We can only guarantee the availability of DI pseudo-ops when |
1089 | assembling for 64-bit targets. */ | |
ae6c1efd | 1090 | if (!TARGET_64BIT) |
301d03af RS |
1091 | { |
1092 | targetm.asm_out.aligned_op.di = NULL; | |
1093 | targetm.asm_out.unaligned_op.di = NULL; | |
1094 | } | |
1095 | ||
2792d578 DE |
1096 | /* Set maximum branch target alignment at two instructions, eight bytes. */ |
1097 | align_jumps_max_skip = 8; | |
1098 | align_loops_max_skip = 8; | |
1099 | ||
71f123ca FS |
1100 | /* Arrange to save and restore machine status around nested functions. */ |
1101 | init_machine_status = rs6000_init_machine_status; | |
42ba5130 RH |
1102 | |
1103 | /* We should always be splitting complex arguments, but we can't break | |
1104 | Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */ | |
1105 | if (DEFAULT_ABI != ABI_AIX) | |
1106 | targetm.calls.split_complex_arg = NULL; | |
5248c961 | 1107 | } |
5accd822 | 1108 | |
5da702b1 AH |
1109 | /* Handle generic options of the form -mfoo=yes/no. |
1110 | NAME is the option name. | |
1111 | VALUE is the option value. | |
1112 | FLAG is the pointer to the flag where to store a 1 or 0, depending on | |
1113 | whether the option value is 'yes' or 'no' respectively. */ | |
993f19a8 | 1114 | static void |
5da702b1 | 1115 | rs6000_parse_yes_no_option (const char *name, const char *value, int *flag) |
993f19a8 | 1116 | { |
5da702b1 | 1117 | if (value == 0) |
993f19a8 | 1118 | return; |
5da702b1 AH |
1119 | else if (!strcmp (value, "yes")) |
1120 | *flag = 1; | |
1121 | else if (!strcmp (value, "no")) | |
1122 | *flag = 0; | |
08b57fb3 | 1123 | else |
5da702b1 | 1124 | error ("unknown -m%s= option specified: '%s'", name, value); |
08b57fb3 AH |
1125 | } |
1126 | ||
0ac081f6 | 1127 | /* Handle -mabi= options. */ |
00b960c7 | 1128 | static void |
863d938c | 1129 | rs6000_parse_abi_options (void) |
0ac081f6 AH |
1130 | { |
1131 | if (rs6000_abi_string == 0) | |
1132 | return; | |
1133 | else if (! strcmp (rs6000_abi_string, "altivec")) | |
5cc73f91 AH |
1134 | { |
1135 | rs6000_altivec_abi = 1; | |
1136 | rs6000_spe_abi = 0; | |
1137 | } | |
76a773f3 AH |
1138 | else if (! strcmp (rs6000_abi_string, "no-altivec")) |
1139 | rs6000_altivec_abi = 0; | |
a3170dc6 | 1140 | else if (! strcmp (rs6000_abi_string, "spe")) |
01f4962d NS |
1141 | { |
1142 | rs6000_spe_abi = 1; | |
5cc73f91 | 1143 | rs6000_altivec_abi = 0; |
01f4962d NS |
1144 | if (!TARGET_SPE_ABI) |
1145 | error ("not configured for ABI: '%s'", rs6000_abi_string); | |
1146 | } | |
1147 | ||
a3170dc6 AH |
1148 | else if (! strcmp (rs6000_abi_string, "no-spe")) |
1149 | rs6000_spe_abi = 0; | |
0ac081f6 | 1150 | else |
c725bd79 | 1151 | error ("unknown ABI specified: '%s'", rs6000_abi_string); |
0ac081f6 AH |
1152 | } |
1153 | ||
025d9908 KH |
1154 | /* Handle -malign-XXXXXX options. */ |
1155 | static void | |
863d938c | 1156 | rs6000_parse_alignment_option (void) |
025d9908 | 1157 | { |
b20a9cca AM |
1158 | if (rs6000_alignment_string == 0) |
1159 | return; | |
1160 | else if (! strcmp (rs6000_alignment_string, "power")) | |
025d9908 KH |
1161 | rs6000_alignment_flags = MASK_ALIGN_POWER; |
1162 | else if (! strcmp (rs6000_alignment_string, "natural")) | |
1163 | rs6000_alignment_flags = MASK_ALIGN_NATURAL; | |
1164 | else | |
1165 | error ("unknown -malign-XXXXX option specified: '%s'", | |
1166 | rs6000_alignment_string); | |
1167 | } | |
1168 | ||
c4501e62 JJ |
1169 | /* Validate and record the size specified with the -mtls-size option. */ |
1170 | ||
1171 | static void | |
863d938c | 1172 | rs6000_parse_tls_size_option (void) |
c4501e62 JJ |
1173 | { |
1174 | if (rs6000_tls_size_string == 0) | |
1175 | return; | |
1176 | else if (strcmp (rs6000_tls_size_string, "16") == 0) | |
1177 | rs6000_tls_size = 16; | |
1178 | else if (strcmp (rs6000_tls_size_string, "32") == 0) | |
1179 | rs6000_tls_size = 32; | |
1180 | else if (strcmp (rs6000_tls_size_string, "64") == 0) | |
1181 | rs6000_tls_size = 64; | |
1182 | else | |
1183 | error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string); | |
1184 | } | |
1185 | ||
5accd822 | 1186 | void |
a2369ed3 | 1187 | optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED) |
5accd822 | 1188 | { |
5accd822 | 1189 | } |
3cfa4909 MM |
1190 | \f |
1191 | /* Do anything needed at the start of the asm file. */ | |
1192 | ||
1bc7c5b6 | 1193 | static void |
863d938c | 1194 | rs6000_file_start (void) |
3cfa4909 | 1195 | { |
c4d38ccb | 1196 | size_t i; |
3cfa4909 | 1197 | char buffer[80]; |
d330fd93 | 1198 | const char *start = buffer; |
3cfa4909 | 1199 | struct rs6000_cpu_select *ptr; |
1bc7c5b6 ZW |
1200 | const char *default_cpu = TARGET_CPU_DEFAULT; |
1201 | FILE *file = asm_out_file; | |
1202 | ||
1203 | default_file_start (); | |
1204 | ||
1205 | #ifdef TARGET_BI_ARCH | |
1206 | if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT) | |
1207 | default_cpu = 0; | |
1208 | #endif | |
3cfa4909 MM |
1209 | |
1210 | if (flag_verbose_asm) | |
1211 | { | |
1212 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
1213 | rs6000_select[0].string = default_cpu; | |
1214 | ||
b6a1cbae | 1215 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
1216 | { |
1217 | ptr = &rs6000_select[i]; | |
1218 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
1219 | { | |
1220 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
1221 | start = ""; | |
1222 | } | |
1223 | } | |
1224 | ||
b91da81f | 1225 | #ifdef USING_ELFOS_H |
3cfa4909 MM |
1226 | switch (rs6000_sdata) |
1227 | { | |
1228 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
1229 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
1230 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
1231 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
1232 | } | |
1233 | ||
1234 | if (rs6000_sdata && g_switch_value) | |
1235 | { | |
307b599c MK |
1236 | fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start, |
1237 | g_switch_value); | |
3cfa4909 MM |
1238 | start = ""; |
1239 | } | |
1240 | #endif | |
1241 | ||
1242 | if (*start == '\0') | |
949ea356 | 1243 | putc ('\n', file); |
3cfa4909 MM |
1244 | } |
1245 | } | |
5248c961 | 1246 | \f |
a0ab749a | 1247 | /* Return nonzero if this function is known to have a null epilogue. */ |
9878760c RK |
1248 | |
1249 | int | |
863d938c | 1250 | direct_return (void) |
9878760c | 1251 | { |
4697a36c MM |
1252 | if (reload_completed) |
1253 | { | |
1254 | rs6000_stack_t *info = rs6000_stack_info (); | |
1255 | ||
1256 | if (info->first_gp_reg_save == 32 | |
1257 | && info->first_fp_reg_save == 64 | |
00b960c7 | 1258 | && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1 |
c81fc13e DE |
1259 | && ! info->lr_save_p |
1260 | && ! info->cr_save_p | |
00b960c7 | 1261 | && info->vrsave_mask == 0 |
c81fc13e | 1262 | && ! info->push_p) |
4697a36c MM |
1263 | return 1; |
1264 | } | |
1265 | ||
1266 | return 0; | |
9878760c RK |
1267 | } |
1268 | ||
1269 | /* Returns 1 always. */ | |
1270 | ||
1271 | int | |
a2369ed3 DJ |
1272 | any_operand (rtx op ATTRIBUTE_UNUSED, |
1273 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
9878760c RK |
1274 | { |
1275 | return 1; | |
1276 | } | |
1277 | ||
a4f6c312 | 1278 | /* Returns 1 if op is the count register. */ |
38c1f2d7 | 1279 | int |
a2369ed3 | 1280 | count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
b6c9286a MM |
1281 | { |
1282 | if (GET_CODE (op) != REG) | |
1283 | return 0; | |
1284 | ||
1285 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
1286 | return 1; | |
1287 | ||
1288 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
1289 | return 1; | |
1290 | ||
1291 | return 0; | |
1292 | } | |
1293 | ||
0ec4e2a8 AH |
1294 | /* Returns 1 if op is an altivec register. */ |
1295 | int | |
a2369ed3 | 1296 | altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ec4e2a8 AH |
1297 | { |
1298 | ||
1299 | return (register_operand (op, mode) | |
1300 | && (GET_CODE (op) != REG | |
1301 | || REGNO (op) > FIRST_PSEUDO_REGISTER | |
1302 | || ALTIVEC_REGNO_P (REGNO (op)))); | |
1303 | } | |
1304 | ||
38c1f2d7 | 1305 | int |
a2369ed3 | 1306 | xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
802a0058 MM |
1307 | { |
1308 | if (GET_CODE (op) != REG) | |
1309 | return 0; | |
1310 | ||
9ebbca7d | 1311 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
1312 | return 1; |
1313 | ||
802a0058 MM |
1314 | return 0; |
1315 | } | |
1316 | ||
c859cda6 | 1317 | /* Return 1 if OP is a signed 8-bit constant. Int multiplication |
6f317ef3 | 1318 | by such constants completes more quickly. */ |
c859cda6 DJ |
1319 | |
1320 | int | |
a2369ed3 | 1321 | s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
c859cda6 DJ |
1322 | { |
1323 | return ( GET_CODE (op) == CONST_INT | |
1324 | && (INTVAL (op) >= -128 && INTVAL (op) <= 127)); | |
1325 | } | |
1326 | ||
9878760c RK |
1327 | /* Return 1 if OP is a constant that can fit in a D field. */ |
1328 | ||
1329 | int | |
a2369ed3 | 1330 | short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1331 | { |
5f59ecb7 DE |
1332 | return (GET_CODE (op) == CONST_INT |
1333 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
1334 | } |
1335 | ||
5519a4f9 | 1336 | /* Similar for an unsigned D field. */ |
9878760c RK |
1337 | |
1338 | int | |
a2369ed3 | 1339 | u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1340 | { |
19684119 | 1341 | return (GET_CODE (op) == CONST_INT |
c1f11548 | 1342 | && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K')); |
9878760c RK |
1343 | } |
1344 | ||
dcfedcd0 RK |
1345 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
1346 | ||
1347 | int | |
a2369ed3 | 1348 | non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
1349 | { |
1350 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 1351 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
1352 | } |
1353 | ||
2bfcf297 DB |
1354 | /* Returns 1 if OP is a CONST_INT that is a positive value |
1355 | and an exact power of 2. */ | |
1356 | ||
1357 | int | |
a2369ed3 | 1358 | exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2bfcf297 DB |
1359 | { |
1360 | return (GET_CODE (op) == CONST_INT | |
1361 | && INTVAL (op) > 0 | |
1362 | && exact_log2 (INTVAL (op)) >= 0); | |
1363 | } | |
1364 | ||
9878760c RK |
1365 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
1366 | ctr, or lr). */ | |
1367 | ||
1368 | int | |
a2369ed3 | 1369 | gpc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1370 | { |
1371 | return (register_operand (op, mode) | |
802a0058 | 1372 | && (GET_CODE (op) != REG |
9ebbca7d GK |
1373 | || (REGNO (op) >= ARG_POINTER_REGNUM |
1374 | && !XER_REGNO_P (REGNO (op))) | |
1375 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
1376 | } |
1377 | ||
1378 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
1379 | CR field. */ | |
1380 | ||
1381 | int | |
a2369ed3 | 1382 | cc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1383 | { |
1384 | return (register_operand (op, mode) | |
1385 | && (GET_CODE (op) != REG | |
1386 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1387 | || CR_REGNO_P (REGNO (op)))); | |
1388 | } | |
1389 | ||
815cdc52 MM |
1390 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
1391 | CR field that isn't CR0. */ | |
1392 | ||
1393 | int | |
a2369ed3 | 1394 | cc_reg_not_cr0_operand (rtx op, enum machine_mode mode) |
815cdc52 MM |
1395 | { |
1396 | return (register_operand (op, mode) | |
1397 | && (GET_CODE (op) != REG | |
1398 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1399 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
1400 | } | |
1401 | ||
a4f6c312 SS |
1402 | /* Returns 1 if OP is either a constant integer valid for a D-field or |
1403 | a non-special register. If a register, it must be in the proper | |
1404 | mode unless MODE is VOIDmode. */ | |
9878760c RK |
1405 | |
1406 | int | |
a2369ed3 | 1407 | reg_or_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1408 | { |
f5a28898 | 1409 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1410 | } |
1411 | ||
a4f6c312 | 1412 | /* Similar, except check if the negation of the constant would be |
42f806e5 AM |
1413 | valid for a D-field. Don't allow a constant zero, since all the |
1414 | patterns that call this predicate use "addic r1,r2,-constant" on | |
1415 | a constant value to set a carry when r2 is greater or equal to | |
1416 | "constant". That doesn't work for zero. */ | |
9878760c RK |
1417 | |
1418 | int | |
a2369ed3 | 1419 | reg_or_neg_short_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1420 | { |
1421 | if (GET_CODE (op) == CONST_INT) | |
42f806e5 | 1422 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0; |
9878760c | 1423 | |
cd2b37d9 | 1424 | return gpc_reg_operand (op, mode); |
9878760c RK |
1425 | } |
1426 | ||
768070a0 TR |
1427 | /* Returns 1 if OP is either a constant integer valid for a DS-field or |
1428 | a non-special register. If a register, it must be in the proper | |
1429 | mode unless MODE is VOIDmode. */ | |
1430 | ||
1431 | int | |
a2369ed3 | 1432 | reg_or_aligned_short_operand (rtx op, enum machine_mode mode) |
768070a0 TR |
1433 | { |
1434 | if (gpc_reg_operand (op, mode)) | |
1435 | return 1; | |
1436 | else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3)) | |
1437 | return 1; | |
1438 | ||
1439 | return 0; | |
1440 | } | |
1441 | ||
1442 | ||
a4f6c312 SS |
1443 | /* Return 1 if the operand is either a register or an integer whose |
1444 | high-order 16 bits are zero. */ | |
9878760c RK |
1445 | |
1446 | int | |
a2369ed3 | 1447 | reg_or_u_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1448 | { |
e675f625 | 1449 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1450 | } |
1451 | ||
1452 | /* Return 1 is the operand is either a non-special register or ANY | |
1453 | constant integer. */ | |
1454 | ||
1455 | int | |
a2369ed3 | 1456 | reg_or_cint_operand (rtx op, enum machine_mode mode) |
9878760c | 1457 | { |
a4f6c312 | 1458 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
f6bf7de2 DE |
1459 | } |
1460 | ||
1461 | /* Return 1 is the operand is either a non-special register or ANY | |
1462 | 32-bit signed constant integer. */ | |
1463 | ||
1464 | int | |
a2369ed3 | 1465 | reg_or_arith_cint_operand (rtx op, enum machine_mode mode) |
f6bf7de2 | 1466 | { |
a4f6c312 SS |
1467 | return (gpc_reg_operand (op, mode) |
1468 | || (GET_CODE (op) == CONST_INT | |
f6bf7de2 | 1469 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
1470 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) |
1471 | < (unsigned HOST_WIDE_INT) 0x100000000ll) | |
f6bf7de2 | 1472 | #endif |
a4f6c312 | 1473 | )); |
9878760c RK |
1474 | } |
1475 | ||
2bfcf297 DB |
1476 | /* Return 1 is the operand is either a non-special register or a 32-bit |
1477 | signed constant integer valid for 64-bit addition. */ | |
1478 | ||
1479 | int | |
a2369ed3 | 1480 | reg_or_add_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1481 | { |
a4f6c312 SS |
1482 | return (gpc_reg_operand (op, mode) |
1483 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1484 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1485 | && INTVAL (op) < 0x7fff8000 |
a65c591c | 1486 | #else |
a4f6c312 SS |
1487 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) |
1488 | < 0x100000000ll) | |
2bfcf297 | 1489 | #endif |
a4f6c312 | 1490 | )); |
2bfcf297 DB |
1491 | } |
1492 | ||
1493 | /* Return 1 is the operand is either a non-special register or a 32-bit | |
1494 | signed constant integer valid for 64-bit subtraction. */ | |
1495 | ||
1496 | int | |
a2369ed3 | 1497 | reg_or_sub_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1498 | { |
a4f6c312 SS |
1499 | return (gpc_reg_operand (op, mode) |
1500 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1501 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1502 | && (- INTVAL (op)) < 0x7fff8000 |
a65c591c | 1503 | #else |
a4f6c312 SS |
1504 | && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000) |
1505 | < 0x100000000ll) | |
2bfcf297 | 1506 | #endif |
a4f6c312 | 1507 | )); |
2bfcf297 DB |
1508 | } |
1509 | ||
9ebbca7d GK |
1510 | /* Return 1 is the operand is either a non-special register or ANY |
1511 | 32-bit unsigned constant integer. */ | |
1512 | ||
1513 | int | |
a2369ed3 | 1514 | reg_or_logical_cint_operand (rtx op, enum machine_mode mode) |
9ebbca7d | 1515 | { |
1d328b19 GK |
1516 | if (GET_CODE (op) == CONST_INT) |
1517 | { | |
1518 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
1519 | { | |
1520 | if (GET_MODE_BITSIZE (mode) <= 32) | |
a4f6c312 | 1521 | abort (); |
1d328b19 GK |
1522 | |
1523 | if (INTVAL (op) < 0) | |
1524 | return 0; | |
1525 | } | |
1526 | ||
1527 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 1528 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
1529 | } |
1530 | else if (GET_CODE (op) == CONST_DOUBLE) | |
1531 | { | |
1532 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
1533 | || mode != DImode) | |
a4f6c312 | 1534 | abort (); |
1d328b19 GK |
1535 | |
1536 | return CONST_DOUBLE_HIGH (op) == 0; | |
1537 | } | |
1538 | else | |
1539 | return gpc_reg_operand (op, mode); | |
9ebbca7d GK |
1540 | } |
1541 | ||
51d3e7d6 | 1542 | /* Return 1 if the operand is an operand that can be loaded via the GOT. */ |
766a866c MM |
1543 | |
1544 | int | |
a2369ed3 | 1545 | got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
766a866c MM |
1546 | { |
1547 | return (GET_CODE (op) == SYMBOL_REF | |
1548 | || GET_CODE (op) == CONST | |
1549 | || GET_CODE (op) == LABEL_REF); | |
1550 | } | |
1551 | ||
38c1f2d7 MM |
1552 | /* Return 1 if the operand is a simple references that can be loaded via |
1553 | the GOT (labels involving addition aren't allowed). */ | |
1554 | ||
1555 | int | |
a2369ed3 | 1556 | got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
38c1f2d7 MM |
1557 | { |
1558 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
1559 | } | |
1560 | ||
4e74d8ec MM |
1561 | /* Return the number of instructions it takes to form a constant in an |
1562 | integer register. */ | |
1563 | ||
1564 | static int | |
a2369ed3 | 1565 | num_insns_constant_wide (HOST_WIDE_INT value) |
4e74d8ec MM |
1566 | { |
1567 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 1568 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
1569 | return 1; |
1570 | ||
4e74d8ec | 1571 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 1572 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
1573 | return 1; |
1574 | ||
5f59ecb7 | 1575 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 1576 | else if (TARGET_POWERPC64) |
4e74d8ec | 1577 | { |
a65c591c DE |
1578 | HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000; |
1579 | HOST_WIDE_INT high = value >> 31; | |
4e74d8ec | 1580 | |
a65c591c | 1581 | if (high == 0 || high == -1) |
4e74d8ec MM |
1582 | return 2; |
1583 | ||
a65c591c | 1584 | high >>= 1; |
4e74d8ec | 1585 | |
a65c591c | 1586 | if (low == 0) |
4e74d8ec | 1587 | return num_insns_constant_wide (high) + 1; |
4e74d8ec MM |
1588 | else |
1589 | return (num_insns_constant_wide (high) | |
e396202a | 1590 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
1591 | } |
1592 | #endif | |
1593 | ||
1594 | else | |
1595 | return 2; | |
1596 | } | |
1597 | ||
1598 | int | |
a2369ed3 | 1599 | num_insns_constant (rtx op, enum machine_mode mode) |
4e74d8ec | 1600 | { |
4e74d8ec | 1601 | if (GET_CODE (op) == CONST_INT) |
0d30d435 DE |
1602 | { |
1603 | #if HOST_BITS_PER_WIDE_INT == 64 | |
4e2c1c44 DE |
1604 | if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1 |
1605 | && mask64_operand (op, mode)) | |
0d30d435 DE |
1606 | return 2; |
1607 | else | |
1608 | #endif | |
1609 | return num_insns_constant_wide (INTVAL (op)); | |
1610 | } | |
4e74d8ec | 1611 | |
6fc48950 MM |
1612 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
1613 | { | |
1614 | long l; | |
1615 | REAL_VALUE_TYPE rv; | |
1616 | ||
1617 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1618 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
e72247f4 | 1619 | return num_insns_constant_wide ((HOST_WIDE_INT) l); |
6fc48950 MM |
1620 | } |
1621 | ||
47ad8c61 | 1622 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 1623 | { |
47ad8c61 MM |
1624 | HOST_WIDE_INT low; |
1625 | HOST_WIDE_INT high; | |
1626 | long l[2]; | |
1627 | REAL_VALUE_TYPE rv; | |
1628 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 1629 | |
47ad8c61 MM |
1630 | if (mode == VOIDmode || mode == DImode) |
1631 | { | |
1632 | high = CONST_DOUBLE_HIGH (op); | |
1633 | low = CONST_DOUBLE_LOW (op); | |
1634 | } | |
1635 | else | |
1636 | { | |
1637 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1638 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
1639 | high = l[endian]; | |
1640 | low = l[1 - endian]; | |
1641 | } | |
4e74d8ec | 1642 | |
47ad8c61 MM |
1643 | if (TARGET_32BIT) |
1644 | return (num_insns_constant_wide (low) | |
1645 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
1646 | |
1647 | else | |
47ad8c61 | 1648 | { |
e72247f4 | 1649 | if (high == 0 && low >= 0) |
47ad8c61 MM |
1650 | return num_insns_constant_wide (low); |
1651 | ||
e72247f4 | 1652 | else if (high == -1 && low < 0) |
47ad8c61 MM |
1653 | return num_insns_constant_wide (low); |
1654 | ||
a260abc9 DE |
1655 | else if (mask64_operand (op, mode)) |
1656 | return 2; | |
1657 | ||
47ad8c61 MM |
1658 | else if (low == 0) |
1659 | return num_insns_constant_wide (high) + 1; | |
1660 | ||
1661 | else | |
1662 | return (num_insns_constant_wide (high) | |
1663 | + num_insns_constant_wide (low) + 1); | |
1664 | } | |
4e74d8ec MM |
1665 | } |
1666 | ||
1667 | else | |
1668 | abort (); | |
1669 | } | |
1670 | ||
a4f6c312 SS |
1671 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a |
1672 | register with one instruction per word. We only do this if we can | |
1673 | safely read CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
1674 | |
1675 | int | |
a2369ed3 | 1676 | easy_fp_constant (rtx op, enum machine_mode mode) |
9878760c | 1677 | { |
9878760c RK |
1678 | if (GET_CODE (op) != CONST_DOUBLE |
1679 | || GET_MODE (op) != mode | |
4e74d8ec | 1680 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
1681 | return 0; |
1682 | ||
a4f6c312 | 1683 | /* Consider all constants with -msoft-float to be easy. */ |
a3170dc6 AH |
1684 | if ((TARGET_SOFT_FLOAT || !TARGET_FPRS) |
1685 | && mode != DImode) | |
b6c9286a MM |
1686 | return 1; |
1687 | ||
a4f6c312 | 1688 | /* If we are using V.4 style PIC, consider all constants to be hard. */ |
f607bc57 | 1689 | if (flag_pic && DEFAULT_ABI == ABI_V4) |
a7273471 MM |
1690 | return 0; |
1691 | ||
5ae4759c | 1692 | #ifdef TARGET_RELOCATABLE |
a4f6c312 SS |
1693 | /* Similarly if we are using -mrelocatable, consider all constants |
1694 | to be hard. */ | |
5ae4759c MM |
1695 | if (TARGET_RELOCATABLE) |
1696 | return 0; | |
1697 | #endif | |
1698 | ||
fcce224d DE |
1699 | if (mode == TFmode) |
1700 | { | |
1701 | long k[4]; | |
1702 | REAL_VALUE_TYPE rv; | |
1703 | ||
1704 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1705 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
1706 | ||
1707 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 | |
1708 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1 | |
1709 | && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1 | |
1710 | && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1); | |
1711 | } | |
1712 | ||
1713 | else if (mode == DFmode) | |
042259f2 DE |
1714 | { |
1715 | long k[2]; | |
1716 | REAL_VALUE_TYPE rv; | |
1717 | ||
1718 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1719 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 1720 | |
a65c591c DE |
1721 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 |
1722 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1); | |
042259f2 | 1723 | } |
4e74d8ec MM |
1724 | |
1725 | else if (mode == SFmode) | |
042259f2 DE |
1726 | { |
1727 | long l; | |
1728 | REAL_VALUE_TYPE rv; | |
1729 | ||
1730 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
1731 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 1732 | |
4e74d8ec | 1733 | return num_insns_constant_wide (l) == 1; |
042259f2 | 1734 | } |
4e74d8ec | 1735 | |
a260abc9 | 1736 | else if (mode == DImode) |
c81fc13e | 1737 | return ((TARGET_POWERPC64 |
a260abc9 DE |
1738 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
1739 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 1740 | |
a9098fd0 GK |
1741 | else if (mode == SImode) |
1742 | return 1; | |
4e74d8ec MM |
1743 | else |
1744 | abort (); | |
9878760c | 1745 | } |
8f75773e | 1746 | |
effa5d5d | 1747 | /* Returns the constant for the splat instruction, if exists. */ |
452a7d36 HP |
1748 | |
1749 | static int | |
1750 | easy_vector_splat_const (int cst, enum machine_mode mode) | |
1751 | { | |
1752 | switch (mode) | |
1753 | { | |
1754 | case V4SImode: | |
1755 | if (EASY_VECTOR_15 (cst) | |
1756 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
1757 | return cst; | |
1758 | if ((cst & 0xffff) != ((cst >> 16) & 0xffff)) | |
1759 | break; | |
1760 | cst = cst >> 16; | |
1761 | case V8HImode: | |
1762 | if (EASY_VECTOR_15 (cst) | |
1763 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
1764 | return cst; | |
1765 | if ((cst & 0xff) != ((cst >> 8) & 0xff)) | |
1766 | break; | |
1767 | cst = cst >> 8; | |
1768 | case V16QImode: | |
1769 | if (EASY_VECTOR_15 (cst) | |
1770 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
1771 | return cst; | |
1772 | default: | |
1773 | break; | |
1774 | } | |
1775 | return 0; | |
1776 | } | |
1777 | ||
1778 | ||
72ac76be | 1779 | /* Return nonzero if all elements of a vector have the same value. */ |
69ef87e2 AH |
1780 | |
1781 | static int | |
a2369ed3 | 1782 | easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
d744e06e AH |
1783 | { |
1784 | int units, i, cst; | |
1785 | ||
1786 | units = CONST_VECTOR_NUNITS (op); | |
1787 | ||
1788 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); | |
1789 | for (i = 1; i < units; ++i) | |
1790 | if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst) | |
1791 | break; | |
452a7d36 | 1792 | if (i == units && easy_vector_splat_const (cst, mode)) |
d744e06e AH |
1793 | return 1; |
1794 | return 0; | |
1795 | } | |
1796 | ||
1797 | /* Return 1 if the operand is a CONST_INT and can be put into a | |
1798 | register without using memory. */ | |
1799 | ||
1800 | int | |
a2369ed3 | 1801 | easy_vector_constant (rtx op, enum machine_mode mode) |
69ef87e2 | 1802 | { |
d744e06e | 1803 | int cst, cst2; |
69ef87e2 | 1804 | |
d744e06e AH |
1805 | if (GET_CODE (op) != CONST_VECTOR |
1806 | || (!TARGET_ALTIVEC | |
1807 | && !TARGET_SPE)) | |
69ef87e2 AH |
1808 | return 0; |
1809 | ||
d744e06e AH |
1810 | if (zero_constant (op, mode) |
1811 | && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode)) | |
1812 | || (TARGET_SPE && SPE_VECTOR_MODE (mode)))) | |
1813 | return 1; | |
69ef87e2 | 1814 | |
d744e06e AH |
1815 | if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT) |
1816 | return 0; | |
1817 | ||
f5119d10 AH |
1818 | if (TARGET_SPE && mode == V1DImode) |
1819 | return 0; | |
1820 | ||
d744e06e AH |
1821 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); |
1822 | cst2 = INTVAL (CONST_VECTOR_ELT (op, 1)); | |
1823 | ||
1824 | /* Limit SPE vectors to 15 bits signed. These we can generate with: | |
1825 | li r0, CONSTANT1 | |
1826 | evmergelo r0, r0, r0 | |
1827 | li r0, CONSTANT2 | |
1828 | ||
1829 | I don't know how efficient it would be to allow bigger constants, | |
1830 | considering we'll have an extra 'ori' for every 'li'. I doubt 5 | |
1831 | instructions is better than a 64-bit memory load, but I don't | |
1832 | have the e500 timing specs. */ | |
1833 | if (TARGET_SPE && mode == V2SImode | |
1834 | && cst >= -0x7fff && cst <= 0x7fff | |
f5119d10 | 1835 | && cst2 >= -0x7fff && cst2 <= 0x7fff) |
d744e06e AH |
1836 | return 1; |
1837 | ||
452a7d36 HP |
1838 | if (TARGET_ALTIVEC |
1839 | && easy_vector_same (op, mode)) | |
1840 | { | |
1841 | cst = easy_vector_splat_const (cst, mode); | |
1842 | if (EASY_VECTOR_15_ADD_SELF (cst) | |
1843 | || EASY_VECTOR_15 (cst)) | |
1844 | return 1; | |
1845 | } | |
d744e06e AH |
1846 | return 0; |
1847 | } | |
1848 | ||
1849 | /* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */ | |
1850 | ||
1851 | int | |
a2369ed3 | 1852 | easy_vector_constant_add_self (rtx op, enum machine_mode mode) |
d744e06e AH |
1853 | { |
1854 | int cst; | |
452a7d36 HP |
1855 | if (TARGET_ALTIVEC |
1856 | && GET_CODE (op) == CONST_VECTOR | |
1857 | && easy_vector_same (op, mode)) | |
1858 | { | |
1859 | cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode); | |
1860 | if (EASY_VECTOR_15_ADD_SELF (cst)) | |
1861 | return 1; | |
1862 | } | |
1863 | return 0; | |
1864 | } | |
d744e06e | 1865 | |
452a7d36 | 1866 | /* Generate easy_vector_constant out of a easy_vector_constant_add_self. */ |
d744e06e | 1867 | |
452a7d36 HP |
1868 | rtx |
1869 | gen_easy_vector_constant_add_self (rtx op) | |
1870 | { | |
1871 | int i, units; | |
1872 | rtvec v; | |
1873 | units = GET_MODE_NUNITS (GET_MODE (op)); | |
1874 | v = rtvec_alloc (units); | |
1875 | ||
1876 | for (i = 0; i < units; i++) | |
1877 | RTVEC_ELT (v, i) = | |
1878 | GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1); | |
1879 | return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v); | |
d744e06e AH |
1880 | } |
1881 | ||
1882 | const char * | |
a2369ed3 | 1883 | output_vec_const_move (rtx *operands) |
d744e06e AH |
1884 | { |
1885 | int cst, cst2; | |
1886 | enum machine_mode mode; | |
1887 | rtx dest, vec; | |
1888 | ||
1889 | dest = operands[0]; | |
1890 | vec = operands[1]; | |
69ef87e2 | 1891 | |
d744e06e AH |
1892 | cst = INTVAL (CONST_VECTOR_ELT (vec, 0)); |
1893 | cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1)); | |
1894 | mode = GET_MODE (dest); | |
69ef87e2 | 1895 | |
d744e06e AH |
1896 | if (TARGET_ALTIVEC) |
1897 | { | |
1898 | if (zero_constant (vec, mode)) | |
1899 | return "vxor %0,%0,%0"; | |
ce1f50b2 | 1900 | else if (easy_vector_constant (vec, mode)) |
98ef3137 | 1901 | { |
d744e06e AH |
1902 | operands[1] = GEN_INT (cst); |
1903 | switch (mode) | |
1904 | { | |
1905 | case V4SImode: | |
452a7d36 | 1906 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
1907 | { |
1908 | operands[1] = GEN_INT (cst); | |
1909 | return "vspltisw %0,%1"; | |
1910 | } | |
452a7d36 HP |
1911 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
1912 | return "#"; | |
ce1f50b2 | 1913 | cst = cst >> 16; |
d744e06e | 1914 | case V8HImode: |
452a7d36 | 1915 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
1916 | { |
1917 | operands[1] = GEN_INT (cst); | |
1918 | return "vspltish %0,%1"; | |
1919 | } | |
452a7d36 HP |
1920 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
1921 | return "#"; | |
ce1f50b2 | 1922 | cst = cst >> 8; |
d744e06e | 1923 | case V16QImode: |
452a7d36 | 1924 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
1925 | { |
1926 | operands[1] = GEN_INT (cst); | |
1927 | return "vspltisb %0,%1"; | |
1928 | } | |
452a7d36 HP |
1929 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
1930 | return "#"; | |
d744e06e AH |
1931 | default: |
1932 | abort (); | |
1933 | } | |
98ef3137 | 1934 | } |
d744e06e AH |
1935 | else |
1936 | abort (); | |
69ef87e2 AH |
1937 | } |
1938 | ||
d744e06e AH |
1939 | if (TARGET_SPE) |
1940 | { | |
1941 | /* Vector constant 0 is handled as a splitter of V2SI, and in the | |
1942 | pattern of V1DI, V4HI, and V2SF. | |
1943 | ||
c1207243 | 1944 | FIXME: We should probably return # and add post reload |
d744e06e AH |
1945 | splitters for these, but this way is so easy ;-). |
1946 | */ | |
1947 | operands[1] = GEN_INT (cst); | |
1948 | operands[2] = GEN_INT (cst2); | |
1949 | if (cst == cst2) | |
1950 | return "li %0,%1\n\tevmergelo %0,%0,%0"; | |
1951 | else | |
1952 | return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2"; | |
1953 | } | |
1954 | ||
1955 | abort (); | |
69ef87e2 AH |
1956 | } |
1957 | ||
1958 | /* Return 1 if the operand is the constant 0. This works for scalars | |
1959 | as well as vectors. */ | |
1960 | int | |
a2369ed3 | 1961 | zero_constant (rtx op, enum machine_mode mode) |
69ef87e2 AH |
1962 | { |
1963 | return op == CONST0_RTX (mode); | |
1964 | } | |
1965 | ||
50a0b056 GK |
1966 | /* Return 1 if the operand is 0.0. */ |
1967 | int | |
a2369ed3 | 1968 | zero_fp_constant (rtx op, enum machine_mode mode) |
50a0b056 GK |
1969 | { |
1970 | return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode); | |
1971 | } | |
1972 | ||
a4f6c312 SS |
1973 | /* Return 1 if the operand is in volatile memory. Note that during |
1974 | the RTL generation phase, memory_operand does not return TRUE for | |
b6c9286a MM |
1975 | volatile memory references. So this function allows us to |
1976 | recognize volatile references where its safe. */ | |
1977 | ||
1978 | int | |
a2369ed3 | 1979 | volatile_mem_operand (rtx op, enum machine_mode mode) |
b6c9286a MM |
1980 | { |
1981 | if (GET_CODE (op) != MEM) | |
1982 | return 0; | |
1983 | ||
1984 | if (!MEM_VOLATILE_P (op)) | |
1985 | return 0; | |
1986 | ||
1987 | if (mode != GET_MODE (op)) | |
1988 | return 0; | |
1989 | ||
1990 | if (reload_completed) | |
1991 | return memory_operand (op, mode); | |
1992 | ||
1993 | if (reload_in_progress) | |
1994 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
1995 | ||
1996 | return memory_address_p (mode, XEXP (op, 0)); | |
1997 | } | |
1998 | ||
97f6e72f | 1999 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
2000 | |
2001 | int | |
a2369ed3 | 2002 | offsettable_mem_operand (rtx op, enum machine_mode mode) |
914c2e77 | 2003 | { |
97f6e72f | 2004 | return ((GET_CODE (op) == MEM) |
677a9668 | 2005 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 2006 | mode, XEXP (op, 0))); |
914c2e77 RK |
2007 | } |
2008 | ||
9878760c RK |
2009 | /* Return 1 if the operand is either an easy FP constant (see above) or |
2010 | memory. */ | |
2011 | ||
2012 | int | |
a2369ed3 | 2013 | mem_or_easy_const_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2014 | { |
2015 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
2016 | } | |
2017 | ||
2018 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 2019 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
2020 | |
2021 | int | |
a2369ed3 | 2022 | add_operand (rtx op, enum machine_mode mode) |
9878760c | 2023 | { |
2bfcf297 | 2024 | if (GET_CODE (op) == CONST_INT) |
e72247f4 DE |
2025 | return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
2026 | || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
2bfcf297 DB |
2027 | |
2028 | return gpc_reg_operand (op, mode); | |
9878760c RK |
2029 | } |
2030 | ||
dcfedcd0 RK |
2031 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
2032 | ||
2033 | int | |
a2369ed3 | 2034 | non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
2035 | { |
2036 | return (GET_CODE (op) == CONST_INT | |
e72247f4 DE |
2037 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
2038 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
dcfedcd0 RK |
2039 | } |
2040 | ||
9878760c RK |
2041 | /* Return 1 if the operand is a non-special register or a constant that |
2042 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
2043 | ||
2044 | int | |
a2369ed3 | 2045 | logical_operand (rtx op, enum machine_mode mode) |
9878760c | 2046 | { |
40501e5f | 2047 | HOST_WIDE_INT opl, oph; |
1d328b19 | 2048 | |
dfbdccdb GK |
2049 | if (gpc_reg_operand (op, mode)) |
2050 | return 1; | |
1d328b19 | 2051 | |
dfbdccdb | 2052 | if (GET_CODE (op) == CONST_INT) |
40501e5f AM |
2053 | { |
2054 | opl = INTVAL (op) & GET_MODE_MASK (mode); | |
2055 | ||
2056 | #if HOST_BITS_PER_WIDE_INT <= 32 | |
2057 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0) | |
2058 | return 0; | |
2059 | #endif | |
2060 | } | |
dfbdccdb GK |
2061 | else if (GET_CODE (op) == CONST_DOUBLE) |
2062 | { | |
1d328b19 | 2063 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
40501e5f | 2064 | abort (); |
1d328b19 GK |
2065 | |
2066 | opl = CONST_DOUBLE_LOW (op); | |
2067 | oph = CONST_DOUBLE_HIGH (op); | |
40501e5f | 2068 | if (oph != 0) |
38886f37 | 2069 | return 0; |
dfbdccdb GK |
2070 | } |
2071 | else | |
2072 | return 0; | |
1d328b19 | 2073 | |
40501e5f AM |
2074 | return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 |
2075 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); | |
9878760c RK |
2076 | } |
2077 | ||
dcfedcd0 | 2078 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 2079 | above), but could be split into one. */ |
dcfedcd0 RK |
2080 | |
2081 | int | |
a2369ed3 | 2082 | non_logical_cint_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2083 | { |
dfbdccdb | 2084 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
2085 | && ! logical_operand (op, mode) |
2086 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
2087 | } |
2088 | ||
19ba8161 | 2089 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
2090 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
2091 | Reject all ones and all zeros, since these should have been optimized | |
2092 | away and confuse the making of MB and ME. */ | |
2093 | ||
2094 | int | |
a2369ed3 | 2095 | mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 2096 | { |
02071907 | 2097 | HOST_WIDE_INT c, lsb; |
9878760c | 2098 | |
19ba8161 DE |
2099 | if (GET_CODE (op) != CONST_INT) |
2100 | return 0; | |
2101 | ||
2102 | c = INTVAL (op); | |
2103 | ||
57deb3a1 AM |
2104 | /* Fail in 64-bit mode if the mask wraps around because the upper |
2105 | 32-bits of the mask will all be 1s, contrary to GCC's internal view. */ | |
2106 | if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001) | |
2107 | return 0; | |
2108 | ||
c5059423 AM |
2109 | /* We don't change the number of transitions by inverting, |
2110 | so make sure we start with the LS bit zero. */ | |
2111 | if (c & 1) | |
2112 | c = ~c; | |
2113 | ||
2114 | /* Reject all zeros or all ones. */ | |
2115 | if (c == 0) | |
9878760c RK |
2116 | return 0; |
2117 | ||
c5059423 AM |
2118 | /* Find the first transition. */ |
2119 | lsb = c & -c; | |
2120 | ||
2121 | /* Invert to look for a second transition. */ | |
2122 | c = ~c; | |
9878760c | 2123 | |
c5059423 AM |
2124 | /* Erase first transition. */ |
2125 | c &= -lsb; | |
9878760c | 2126 | |
c5059423 AM |
2127 | /* Find the second transition (if any). */ |
2128 | lsb = c & -c; | |
2129 | ||
2130 | /* Match if all the bits above are 1's (or c is zero). */ | |
2131 | return c == -lsb; | |
9878760c RK |
2132 | } |
2133 | ||
0ba1b2ff AM |
2134 | /* Return 1 for the PowerPC64 rlwinm corner case. */ |
2135 | ||
2136 | int | |
a2369ed3 | 2137 | mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2138 | { |
2139 | HOST_WIDE_INT c, lsb; | |
2140 | ||
2141 | if (GET_CODE (op) != CONST_INT) | |
2142 | return 0; | |
2143 | ||
2144 | c = INTVAL (op); | |
2145 | ||
2146 | if ((c & 0x80000001) != 0x80000001) | |
2147 | return 0; | |
2148 | ||
2149 | c = ~c; | |
2150 | if (c == 0) | |
2151 | return 0; | |
2152 | ||
2153 | lsb = c & -c; | |
2154 | c = ~c; | |
2155 | c &= -lsb; | |
2156 | lsb = c & -c; | |
2157 | return c == -lsb; | |
2158 | } | |
2159 | ||
a260abc9 DE |
2160 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
2161 | It is if there are no more than one 1->0 or 0->1 transitions. | |
0ba1b2ff AM |
2162 | Reject all zeros, since zero should have been optimized away and |
2163 | confuses the making of MB and ME. */ | |
9878760c RK |
2164 | |
2165 | int | |
a2369ed3 | 2166 | mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
a260abc9 DE |
2167 | { |
2168 | if (GET_CODE (op) == CONST_INT) | |
2169 | { | |
02071907 | 2170 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2171 | |
c5059423 | 2172 | c = INTVAL (op); |
a260abc9 | 2173 | |
0ba1b2ff | 2174 | /* Reject all zeros. */ |
c5059423 | 2175 | if (c == 0) |
e2c953b6 DE |
2176 | return 0; |
2177 | ||
0ba1b2ff AM |
2178 | /* We don't change the number of transitions by inverting, |
2179 | so make sure we start with the LS bit zero. */ | |
2180 | if (c & 1) | |
2181 | c = ~c; | |
2182 | ||
c5059423 AM |
2183 | /* Find the transition, and check that all bits above are 1's. */ |
2184 | lsb = c & -c; | |
e3981aab DE |
2185 | |
2186 | /* Match if all the bits above are 1's (or c is zero). */ | |
c5059423 | 2187 | return c == -lsb; |
e2c953b6 | 2188 | } |
0ba1b2ff AM |
2189 | return 0; |
2190 | } | |
2191 | ||
2192 | /* Like mask64_operand, but allow up to three transitions. This | |
2193 | predicate is used by insn patterns that generate two rldicl or | |
2194 | rldicr machine insns. */ | |
2195 | ||
2196 | int | |
a2369ed3 | 2197 | mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2198 | { |
2199 | if (GET_CODE (op) == CONST_INT) | |
a260abc9 | 2200 | { |
0ba1b2ff | 2201 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2202 | |
0ba1b2ff | 2203 | c = INTVAL (op); |
a260abc9 | 2204 | |
0ba1b2ff AM |
2205 | /* Disallow all zeros. */ |
2206 | if (c == 0) | |
2207 | return 0; | |
a260abc9 | 2208 | |
0ba1b2ff AM |
2209 | /* We don't change the number of transitions by inverting, |
2210 | so make sure we start with the LS bit zero. */ | |
2211 | if (c & 1) | |
2212 | c = ~c; | |
a260abc9 | 2213 | |
0ba1b2ff AM |
2214 | /* Find the first transition. */ |
2215 | lsb = c & -c; | |
a260abc9 | 2216 | |
0ba1b2ff AM |
2217 | /* Invert to look for a second transition. */ |
2218 | c = ~c; | |
2219 | ||
2220 | /* Erase first transition. */ | |
2221 | c &= -lsb; | |
2222 | ||
2223 | /* Find the second transition. */ | |
2224 | lsb = c & -c; | |
2225 | ||
2226 | /* Invert to look for a third transition. */ | |
2227 | c = ~c; | |
2228 | ||
2229 | /* Erase second transition. */ | |
2230 | c &= -lsb; | |
2231 | ||
2232 | /* Find the third transition (if any). */ | |
2233 | lsb = c & -c; | |
2234 | ||
2235 | /* Match if all the bits above are 1's (or c is zero). */ | |
2236 | return c == -lsb; | |
2237 | } | |
2238 | return 0; | |
2239 | } | |
2240 | ||
2241 | /* Generates shifts and masks for a pair of rldicl or rldicr insns to | |
2242 | implement ANDing by the mask IN. */ | |
2243 | void | |
a2369ed3 | 2244 | build_mask64_2_operands (rtx in, rtx *out) |
0ba1b2ff AM |
2245 | { |
2246 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
2247 | unsigned HOST_WIDE_INT c, lsb, m1, m2; | |
2248 | int shift; | |
2249 | ||
2250 | if (GET_CODE (in) != CONST_INT) | |
2251 | abort (); | |
2252 | ||
2253 | c = INTVAL (in); | |
2254 | if (c & 1) | |
2255 | { | |
2256 | /* Assume c initially something like 0x00fff000000fffff. The idea | |
2257 | is to rotate the word so that the middle ^^^^^^ group of zeros | |
2258 | is at the MS end and can be cleared with an rldicl mask. We then | |
2259 | rotate back and clear off the MS ^^ group of zeros with a | |
2260 | second rldicl. */ | |
2261 | c = ~c; /* c == 0xff000ffffff00000 */ | |
2262 | lsb = c & -c; /* lsb == 0x0000000000100000 */ | |
2263 | m1 = -lsb; /* m1 == 0xfffffffffff00000 */ | |
2264 | c = ~c; /* c == 0x00fff000000fffff */ | |
2265 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2266 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2267 | c = ~c; /* c == 0xff000fffffffffff */ | |
2268 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2269 | shift = 0; | |
2270 | while ((lsb >>= 1) != 0) | |
2271 | shift++; /* shift == 44 on exit from loop */ | |
2272 | m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */ | |
2273 | m1 = ~m1; /* m1 == 0x000000ffffffffff */ | |
2274 | m2 = ~c; /* m2 == 0x00ffffffffffffff */ | |
a260abc9 DE |
2275 | } |
2276 | else | |
0ba1b2ff AM |
2277 | { |
2278 | /* Assume c initially something like 0xff000f0000000000. The idea | |
2279 | is to rotate the word so that the ^^^ middle group of zeros | |
2280 | is at the LS end and can be cleared with an rldicr mask. We then | |
2281 | rotate back and clear off the LS group of ^^^^^^^^^^ zeros with | |
2282 | a second rldicr. */ | |
2283 | lsb = c & -c; /* lsb == 0x0000010000000000 */ | |
2284 | m2 = -lsb; /* m2 == 0xffffff0000000000 */ | |
2285 | c = ~c; /* c == 0x00fff0ffffffffff */ | |
2286 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2287 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2288 | c = ~c; /* c == 0xff000fffffffffff */ | |
2289 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2290 | shift = 0; | |
2291 | while ((lsb >>= 1) != 0) | |
2292 | shift++; /* shift == 44 on exit from loop */ | |
2293 | m1 = ~c; /* m1 == 0x00ffffffffffffff */ | |
2294 | m1 >>= shift; /* m1 == 0x0000000000000fff */ | |
2295 | m1 = ~m1; /* m1 == 0xfffffffffffff000 */ | |
2296 | } | |
2297 | ||
2298 | /* Note that when we only have two 0->1 and 1->0 transitions, one of the | |
2299 | masks will be all 1's. We are guaranteed more than one transition. */ | |
2300 | out[0] = GEN_INT (64 - shift); | |
2301 | out[1] = GEN_INT (m1); | |
2302 | out[2] = GEN_INT (shift); | |
2303 | out[3] = GEN_INT (m2); | |
2304 | #else | |
045572c7 GK |
2305 | (void)in; |
2306 | (void)out; | |
0ba1b2ff AM |
2307 | abort (); |
2308 | #endif | |
a260abc9 DE |
2309 | } |
2310 | ||
2311 | /* Return 1 if the operand is either a non-special register or a constant | |
2312 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
2313 | ||
2314 | int | |
a2369ed3 | 2315 | and64_operand (rtx op, enum machine_mode mode) |
9878760c | 2316 | { |
a4f6c312 | 2317 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2318 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
2319 | ||
2320 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
2321 | } |
2322 | ||
0ba1b2ff AM |
2323 | /* Like the above, but also match constants that can be implemented |
2324 | with two rldicl or rldicr insns. */ | |
2325 | ||
2326 | int | |
a2369ed3 | 2327 | and64_2_operand (rtx op, enum machine_mode mode) |
0ba1b2ff | 2328 | { |
a3c9585f | 2329 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
0ba1b2ff AM |
2330 | return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode); |
2331 | ||
2332 | return logical_operand (op, mode) || mask64_2_operand (op, mode); | |
2333 | } | |
2334 | ||
a260abc9 DE |
2335 | /* Return 1 if the operand is either a non-special register or a |
2336 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
2337 | |
2338 | int | |
a2369ed3 | 2339 | and_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2340 | { |
a4f6c312 | 2341 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2342 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
2343 | ||
2344 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
2345 | } |
2346 | ||
9878760c RK |
2347 | /* Return 1 if the operand is a general register or memory operand. */ |
2348 | ||
2349 | int | |
a2369ed3 | 2350 | reg_or_mem_operand (rtx op, enum machine_mode mode) |
9878760c | 2351 | { |
b6c9286a MM |
2352 | return (gpc_reg_operand (op, mode) |
2353 | || memory_operand (op, mode) | |
4c81e946 | 2354 | || macho_lo_sum_memory_operand (op, mode) |
b6c9286a | 2355 | || volatile_mem_operand (op, mode)); |
9878760c RK |
2356 | } |
2357 | ||
a7a813f7 | 2358 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 2359 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
2360 | instruction. */ |
2361 | ||
2362 | int | |
a2369ed3 | 2363 | lwa_operand (rtx op, enum machine_mode mode) |
a7a813f7 RK |
2364 | { |
2365 | rtx inner = op; | |
2366 | ||
2367 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
2368 | inner = SUBREG_REG (inner); | |
2369 | ||
2370 | return gpc_reg_operand (inner, mode) | |
2371 | || (memory_operand (inner, mode) | |
2372 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
6a40a9d6 DE |
2373 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC |
2374 | && (GET_CODE (XEXP (inner, 0)) != PLUS | |
e903c96a DE |
2375 | || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT |
2376 | || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0)); | |
a7a813f7 RK |
2377 | } |
2378 | ||
cc4d5fec JH |
2379 | /* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */ |
2380 | ||
2381 | int | |
a2369ed3 | 2382 | symbol_ref_operand (rtx op, enum machine_mode mode) |
cc4d5fec JH |
2383 | { |
2384 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2385 | return 0; | |
2386 | ||
473f51b6 DE |
2387 | return (GET_CODE (op) == SYMBOL_REF |
2388 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))); | |
cc4d5fec JH |
2389 | } |
2390 | ||
9878760c | 2391 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
cc4d5fec | 2392 | to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */ |
9878760c RK |
2393 | |
2394 | int | |
a2369ed3 | 2395 | call_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2396 | { |
2397 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2398 | return 0; | |
2399 | ||
2400 | return (GET_CODE (op) == SYMBOL_REF | |
cc4d5fec JH |
2401 | || (GET_CODE (op) == REG |
2402 | && (REGNO (op) == LINK_REGISTER_REGNUM | |
2403 | || REGNO (op) == COUNT_REGISTER_REGNUM | |
2404 | || REGNO (op) >= FIRST_PSEUDO_REGISTER))); | |
9878760c RK |
2405 | } |
2406 | ||
2af3d377 | 2407 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in |
d1908feb | 2408 | this file. */ |
2af3d377 RK |
2409 | |
2410 | int | |
a2369ed3 DJ |
2411 | current_file_function_operand (rtx op, |
2412 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
2af3d377 | 2413 | { |
473f51b6 DE |
2414 | return (GET_CODE (op) == SYMBOL_REF |
2415 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)) | |
2416 | && (SYMBOL_REF_LOCAL_P (op) | |
2417 | || (op == XEXP (DECL_RTL (current_function_decl), 0)))); | |
2af3d377 RK |
2418 | } |
2419 | ||
9878760c RK |
2420 | /* Return 1 if this operand is a valid input for a move insn. */ |
2421 | ||
2422 | int | |
a2369ed3 | 2423 | input_operand (rtx op, enum machine_mode mode) |
9878760c | 2424 | { |
eb4e8003 | 2425 | /* Memory is always valid. */ |
9878760c RK |
2426 | if (memory_operand (op, mode)) |
2427 | return 1; | |
2428 | ||
eb4e8003 RK |
2429 | /* For floating-point, easy constants are valid. */ |
2430 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
2431 | && CONSTANT_P (op) | |
2432 | && easy_fp_constant (op, mode)) | |
2433 | return 1; | |
2434 | ||
4e74d8ec MM |
2435 | /* Allow any integer constant. */ |
2436 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 2437 | && (GET_CODE (op) == CONST_INT |
e675f625 | 2438 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
2439 | return 1; |
2440 | ||
d744e06e AH |
2441 | /* Allow easy vector constants. */ |
2442 | if (GET_CODE (op) == CONST_VECTOR | |
2443 | && easy_vector_constant (op, mode)) | |
2444 | return 1; | |
2445 | ||
eb4e8003 RK |
2446 | /* For floating-point or multi-word mode, the only remaining valid type |
2447 | is a register. */ | |
9878760c RK |
2448 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
2449 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 2450 | return register_operand (op, mode); |
9878760c | 2451 | |
88fe15a1 RK |
2452 | /* The only cases left are integral modes one word or smaller (we |
2453 | do not get called for MODE_CC values). These can be in any | |
2454 | register. */ | |
2455 | if (register_operand (op, mode)) | |
a8b3aeda | 2456 | return 1; |
88fe15a1 | 2457 | |
84cf9dda | 2458 | /* A SYMBOL_REF referring to the TOC is valid. */ |
4d588c14 | 2459 | if (legitimate_constant_pool_address_p (op)) |
84cf9dda RK |
2460 | return 1; |
2461 | ||
9ebbca7d | 2462 | /* A constant pool expression (relative to the TOC) is valid */ |
4d588c14 | 2463 | if (toc_relative_expr_p (op)) |
b6c9286a MM |
2464 | return 1; |
2465 | ||
88228c4b MM |
2466 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
2467 | to be valid. */ | |
f607bc57 | 2468 | if (DEFAULT_ABI == ABI_V4 |
88228c4b MM |
2469 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
2470 | && small_data_operand (op, Pmode)) | |
2471 | return 1; | |
2472 | ||
042259f2 | 2473 | return 0; |
9878760c | 2474 | } |
7509c759 | 2475 | |
95727fb8 AP |
2476 | |
2477 | /* Darwin, AIX increases natural record alignment to doubleword if the first | |
2478 | field is an FP double while the FP fields remain word aligned. */ | |
2479 | ||
19d66194 | 2480 | unsigned int |
95727fb8 AP |
2481 | rs6000_special_round_type_align (tree type, int computed, int specified) |
2482 | { | |
2483 | tree field = TYPE_FIELDS (type); | |
95727fb8 AP |
2484 | |
2485 | /* Skip all the static variables only if ABI is greater than | |
71cc389b | 2486 | 1 or equal to 0. */ |
3ce5437a | 2487 | while (field != NULL && TREE_CODE (field) == VAR_DECL) |
95727fb8 AP |
2488 | field = TREE_CHAIN (field); |
2489 | ||
3ce5437a | 2490 | if (field == NULL || field == type || DECL_MODE (field) != DFmode) |
95727fb8 AP |
2491 | return MAX (computed, specified); |
2492 | ||
2493 | return MAX (MAX (computed, specified), 64); | |
2494 | } | |
2495 | ||
a4f6c312 | 2496 | /* Return 1 for an operand in small memory on V.4/eabi. */ |
7509c759 MM |
2497 | |
2498 | int | |
a2369ed3 DJ |
2499 | small_data_operand (rtx op ATTRIBUTE_UNUSED, |
2500 | enum machine_mode mode ATTRIBUTE_UNUSED) | |
7509c759 | 2501 | { |
38c1f2d7 | 2502 | #if TARGET_ELF |
5f59ecb7 | 2503 | rtx sym_ref; |
7509c759 | 2504 | |
d9407988 | 2505 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 2506 | return 0; |
a54d04b7 | 2507 | |
f607bc57 | 2508 | if (DEFAULT_ABI != ABI_V4) |
7509c759 MM |
2509 | return 0; |
2510 | ||
88228c4b MM |
2511 | if (GET_CODE (op) == SYMBOL_REF) |
2512 | sym_ref = op; | |
2513 | ||
2514 | else if (GET_CODE (op) != CONST | |
2515 | || GET_CODE (XEXP (op, 0)) != PLUS | |
2516 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
2517 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
2518 | return 0; |
2519 | ||
88228c4b | 2520 | else |
dbf55e53 MM |
2521 | { |
2522 | rtx sum = XEXP (op, 0); | |
2523 | HOST_WIDE_INT summand; | |
2524 | ||
2525 | /* We have to be careful here, because it is the referenced address | |
2526 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
2527 | summand = INTVAL (XEXP (sum, 1)); | |
307b599c | 2528 | if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value) |
dbf55e53 MM |
2529 | return 0; |
2530 | ||
2531 | sym_ref = XEXP (sum, 0); | |
2532 | } | |
88228c4b | 2533 | |
20bfcd69 | 2534 | return SYMBOL_REF_SMALL_P (sym_ref); |
d9407988 MM |
2535 | #else |
2536 | return 0; | |
2537 | #endif | |
7509c759 | 2538 | } |
46c07df8 | 2539 | |
d2288d5d HP |
2540 | /* Return true, if operand is a memory operand and has a |
2541 | displacement divisible by 4. */ | |
2542 | ||
2543 | int | |
2544 | word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) | |
2545 | { | |
2546 | rtx addr; | |
2547 | int off = 0; | |
2548 | ||
2549 | if (!memory_operand (op, mode)) | |
2550 | return 0; | |
2551 | ||
2552 | addr = XEXP (op, 0); | |
2553 | if (GET_CODE (addr) == PLUS | |
2554 | && GET_CODE (XEXP (addr, 0)) == REG | |
2555 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
2556 | off = INTVAL (XEXP (addr, 1)); | |
2557 | ||
2558 | return (off % 4) == 0; | |
2559 | } | |
2560 | ||
3a1f863f | 2561 | /* Return true if either operand is a general purpose register. */ |
46c07df8 | 2562 | |
3a1f863f DE |
2563 | bool |
2564 | gpr_or_gpr_p (rtx op0, rtx op1) | |
46c07df8 | 2565 | { |
3a1f863f DE |
2566 | return ((REG_P (op0) && INT_REGNO_P (REGNO (op0))) |
2567 | || (REG_P (op1) && INT_REGNO_P (REGNO (op1)))); | |
46c07df8 HP |
2568 | } |
2569 | ||
9ebbca7d | 2570 | \f |
4d588c14 RH |
2571 | /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */ |
2572 | ||
9ebbca7d | 2573 | static int |
a2369ed3 | 2574 | constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc) |
9ebbca7d GK |
2575 | { |
2576 | switch (GET_CODE(op)) | |
2577 | { | |
2578 | case SYMBOL_REF: | |
c4501e62 JJ |
2579 | if (RS6000_SYMBOL_REF_TLS_P (op)) |
2580 | return 0; | |
2581 | else if (CONSTANT_POOL_ADDRESS_P (op)) | |
a4f6c312 SS |
2582 | { |
2583 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) | |
2584 | { | |
2585 | *have_sym = 1; | |
2586 | return 1; | |
2587 | } | |
2588 | else | |
2589 | return 0; | |
2590 | } | |
2591 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
2592 | { | |
2593 | *have_toc = 1; | |
2594 | return 1; | |
2595 | } | |
2596 | else | |
2597 | return 0; | |
9ebbca7d GK |
2598 | case PLUS: |
2599 | case MINUS: | |
c1f11548 DE |
2600 | return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) |
2601 | && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc)); | |
9ebbca7d | 2602 | case CONST: |
a4f6c312 | 2603 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); |
9ebbca7d | 2604 | case CONST_INT: |
a4f6c312 | 2605 | return 1; |
9ebbca7d | 2606 | default: |
a4f6c312 | 2607 | return 0; |
9ebbca7d GK |
2608 | } |
2609 | } | |
2610 | ||
4d588c14 | 2611 | static bool |
a2369ed3 | 2612 | constant_pool_expr_p (rtx op) |
9ebbca7d GK |
2613 | { |
2614 | int have_sym = 0; | |
2615 | int have_toc = 0; | |
2616 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
2617 | } | |
2618 | ||
4d588c14 | 2619 | static bool |
a2369ed3 | 2620 | toc_relative_expr_p (rtx op) |
9ebbca7d | 2621 | { |
4d588c14 RH |
2622 | int have_sym = 0; |
2623 | int have_toc = 0; | |
2624 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
2625 | } | |
2626 | ||
4d588c14 | 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 | ||
60cdabab DE |
2646 | /* SPE offset addressing is limited to 5-bits worth of double words. */ |
2647 | #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0) | |
2648 | ||
76d2b81d DJ |
2649 | bool |
2650 | rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict) | |
4d588c14 RH |
2651 | { |
2652 | unsigned HOST_WIDE_INT offset, extra; | |
2653 | ||
2654 | if (GET_CODE (x) != PLUS) | |
2655 | return false; | |
2656 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2657 | return false; | |
2658 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
2659 | return false; | |
60cdabab DE |
2660 | if (legitimate_constant_pool_address_p (x)) |
2661 | return true; | |
4d588c14 RH |
2662 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) |
2663 | return false; | |
2664 | ||
2665 | offset = INTVAL (XEXP (x, 1)); | |
2666 | extra = 0; | |
2667 | switch (mode) | |
2668 | { | |
2669 | case V16QImode: | |
2670 | case V8HImode: | |
2671 | case V4SFmode: | |
2672 | case V4SImode: | |
2673 | /* AltiVec vector modes. Only reg+reg addressing is valid here, | |
2674 | which leaves the only valid constant offset of zero, which by | |
2675 | canonicalization rules is also invalid. */ | |
2676 | return false; | |
2677 | ||
2678 | case V4HImode: | |
2679 | case V2SImode: | |
2680 | case V1DImode: | |
2681 | case V2SFmode: | |
2682 | /* SPE vector modes. */ | |
2683 | return SPE_CONST_OFFSET_OK (offset); | |
2684 | ||
2685 | case DFmode: | |
2686 | case DImode: | |
3364872d | 2687 | if (mode == DFmode || !TARGET_POWERPC64) |
4d588c14 RH |
2688 | extra = 4; |
2689 | else if (offset & 3) | |
2690 | return false; | |
2691 | break; | |
2692 | ||
2693 | case TFmode: | |
2694 | case TImode: | |
3364872d | 2695 | if (mode == TFmode || !TARGET_POWERPC64) |
4d588c14 RH |
2696 | extra = 12; |
2697 | else if (offset & 3) | |
2698 | return false; | |
2699 | else | |
2700 | extra = 8; | |
2701 | break; | |
2702 | ||
2703 | default: | |
2704 | break; | |
2705 | } | |
2706 | ||
b1917422 AM |
2707 | offset += 0x8000; |
2708 | return (offset < 0x10000) && (offset + extra < 0x10000); | |
4d588c14 RH |
2709 | } |
2710 | ||
2711 | static bool | |
a2369ed3 | 2712 | legitimate_indexed_address_p (rtx x, int strict) |
4d588c14 RH |
2713 | { |
2714 | rtx op0, op1; | |
2715 | ||
2716 | if (GET_CODE (x) != PLUS) | |
2717 | return false; | |
2718 | op0 = XEXP (x, 0); | |
2719 | op1 = XEXP (x, 1); | |
2720 | ||
2721 | if (!REG_P (op0) || !REG_P (op1)) | |
2722 | return false; | |
2723 | ||
2724 | return ((INT_REG_OK_FOR_BASE_P (op0, strict) | |
2725 | && INT_REG_OK_FOR_INDEX_P (op1, strict)) | |
2726 | || (INT_REG_OK_FOR_BASE_P (op1, strict) | |
2727 | && INT_REG_OK_FOR_INDEX_P (op0, strict))); | |
9ebbca7d GK |
2728 | } |
2729 | ||
4d588c14 | 2730 | static inline bool |
a2369ed3 | 2731 | legitimate_indirect_address_p (rtx x, int strict) |
4d588c14 RH |
2732 | { |
2733 | return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict); | |
2734 | } | |
2735 | ||
4c81e946 FJ |
2736 | static bool |
2737 | macho_lo_sum_memory_operand (rtx x, enum machine_mode mode) | |
2738 | { | |
2739 | if (!TARGET_MACHO || !flag_pic | |
2740 | || mode != SImode || GET_CODE(x) != MEM) | |
2741 | return false; | |
2742 | x = XEXP (x, 0); | |
2743 | ||
2744 | if (GET_CODE (x) != LO_SUM) | |
2745 | return false; | |
2746 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2747 | return false; | |
2748 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0)) | |
2749 | return false; | |
2750 | x = XEXP (x, 1); | |
2751 | ||
2752 | return CONSTANT_P (x); | |
2753 | } | |
2754 | ||
4d588c14 | 2755 | static bool |
a2369ed3 | 2756 | legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict) |
4d588c14 RH |
2757 | { |
2758 | if (GET_CODE (x) != LO_SUM) | |
2759 | return false; | |
2760 | if (GET_CODE (XEXP (x, 0)) != REG) | |
2761 | return false; | |
2762 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
2763 | return false; | |
2764 | x = XEXP (x, 1); | |
2765 | ||
8622e235 | 2766 | if (TARGET_ELF || TARGET_MACHO) |
4d588c14 | 2767 | { |
a29077da | 2768 | if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic) |
4d588c14 RH |
2769 | return false; |
2770 | if (TARGET_TOC) | |
2771 | return false; | |
2772 | if (GET_MODE_NUNITS (mode) != 1) | |
2773 | return false; | |
2774 | if (GET_MODE_BITSIZE (mode) > 32 | |
2775 | && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode)) | |
2776 | return false; | |
2777 | ||
2778 | return CONSTANT_P (x); | |
2779 | } | |
2780 | ||
2781 | return false; | |
2782 | } | |
2783 | ||
2784 | ||
9ebbca7d GK |
2785 | /* Try machine-dependent ways of modifying an illegitimate address |
2786 | to be legitimate. If we find one, return the new, valid address. | |
2787 | This is used from only one place: `memory_address' in explow.c. | |
2788 | ||
a4f6c312 SS |
2789 | OLDX is the address as it was before break_out_memory_refs was |
2790 | called. In some cases it is useful to look at this to decide what | |
2791 | needs to be done. | |
9ebbca7d | 2792 | |
a4f6c312 | 2793 | MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS. |
9ebbca7d | 2794 | |
a4f6c312 SS |
2795 | It is always safe for this function to do nothing. It exists to |
2796 | recognize opportunities to optimize the output. | |
9ebbca7d GK |
2797 | |
2798 | On RS/6000, first check for the sum of a register with a constant | |
2799 | integer that is out of range. If so, generate code to add the | |
2800 | constant with the low-order 16 bits masked to the register and force | |
2801 | this result into another register (this can be done with `cau'). | |
2802 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
2803 | possibility of bit 16 being a one. | |
2804 | ||
2805 | Then check for the sum of a register and something not constant, try to | |
2806 | load the other things into a register and return the sum. */ | |
4d588c14 | 2807 | |
9ebbca7d | 2808 | rtx |
a2369ed3 DJ |
2809 | rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, |
2810 | enum machine_mode mode) | |
0ac081f6 | 2811 | { |
c4501e62 JJ |
2812 | if (GET_CODE (x) == SYMBOL_REF) |
2813 | { | |
2814 | enum tls_model model = SYMBOL_REF_TLS_MODEL (x); | |
2815 | if (model != 0) | |
2816 | return rs6000_legitimize_tls_address (x, model); | |
2817 | } | |
2818 | ||
9ebbca7d GK |
2819 | if (GET_CODE (x) == PLUS |
2820 | && GET_CODE (XEXP (x, 0)) == REG | |
2821 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2822 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
2823 | { | |
2824 | HOST_WIDE_INT high_int, low_int; | |
2825 | rtx sum; | |
a65c591c DE |
2826 | low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000; |
2827 | high_int = INTVAL (XEXP (x, 1)) - low_int; | |
9ebbca7d GK |
2828 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), |
2829 | GEN_INT (high_int)), 0); | |
2830 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
2831 | } | |
2832 | else if (GET_CODE (x) == PLUS | |
2833 | && GET_CODE (XEXP (x, 0)) == REG | |
2834 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
6ac7bf2c | 2835 | && GET_MODE_NUNITS (mode) == 1 |
a3170dc6 AH |
2836 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
2837 | || TARGET_POWERPC64 | |
fcce224d | 2838 | || (mode != DFmode && mode != TFmode)) |
9ebbca7d GK |
2839 | && (TARGET_POWERPC64 || mode != DImode) |
2840 | && mode != TImode) | |
2841 | { | |
2842 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
2843 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
2844 | } | |
0ac081f6 AH |
2845 | else if (ALTIVEC_VECTOR_MODE (mode)) |
2846 | { | |
2847 | rtx reg; | |
2848 | ||
2849 | /* Make sure both operands are registers. */ | |
2850 | if (GET_CODE (x) == PLUS) | |
9f85ed45 | 2851 | return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)), |
0ac081f6 AH |
2852 | force_reg (Pmode, XEXP (x, 1))); |
2853 | ||
2854 | reg = force_reg (Pmode, x); | |
2855 | return reg; | |
2856 | } | |
a3170dc6 AH |
2857 | else if (SPE_VECTOR_MODE (mode)) |
2858 | { | |
2859 | /* We accept [reg + reg] and [reg + OFFSET]. */ | |
2860 | ||
2861 | if (GET_CODE (x) == PLUS) | |
2862 | { | |
2863 | rtx op1 = XEXP (x, 0); | |
2864 | rtx op2 = XEXP (x, 1); | |
2865 | ||
2866 | op1 = force_reg (Pmode, op1); | |
2867 | ||
2868 | if (GET_CODE (op2) != REG | |
2869 | && (GET_CODE (op2) != CONST_INT | |
2870 | || !SPE_CONST_OFFSET_OK (INTVAL (op2)))) | |
2871 | op2 = force_reg (Pmode, op2); | |
2872 | ||
2873 | return gen_rtx_PLUS (Pmode, op1, op2); | |
2874 | } | |
2875 | ||
2876 | return force_reg (Pmode, x); | |
2877 | } | |
f1384257 AM |
2878 | else if (TARGET_ELF |
2879 | && TARGET_32BIT | |
2880 | && TARGET_NO_TOC | |
2881 | && ! flag_pic | |
9ebbca7d GK |
2882 | && GET_CODE (x) != CONST_INT |
2883 | && GET_CODE (x) != CONST_DOUBLE | |
2884 | && CONSTANT_P (x) | |
6ac7bf2c GK |
2885 | && GET_MODE_NUNITS (mode) == 1 |
2886 | && (GET_MODE_BITSIZE (mode) <= 32 | |
a3170dc6 | 2887 | || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode))) |
9ebbca7d GK |
2888 | { |
2889 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
2890 | emit_insn (gen_elf_high (reg, x)); |
2891 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
9ebbca7d | 2892 | } |
ee890fe2 SS |
2893 | else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC |
2894 | && ! flag_pic | |
ab82a49f AP |
2895 | #if TARGET_MACHO |
2896 | && ! MACHO_DYNAMIC_NO_PIC_P | |
2897 | #endif | |
ee890fe2 SS |
2898 | && GET_CODE (x) != CONST_INT |
2899 | && GET_CODE (x) != CONST_DOUBLE | |
2900 | && CONSTANT_P (x) | |
a3170dc6 | 2901 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode) |
ee890fe2 SS |
2902 | && mode != DImode |
2903 | && mode != TImode) | |
2904 | { | |
2905 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
2906 | emit_insn (gen_macho_high (reg, x)); |
2907 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
ee890fe2 | 2908 | } |
9ebbca7d | 2909 | else if (TARGET_TOC |
4d588c14 | 2910 | && constant_pool_expr_p (x) |
a9098fd0 | 2911 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
2912 | { |
2913 | return create_TOC_reference (x); | |
2914 | } | |
2915 | else | |
2916 | return NULL_RTX; | |
2917 | } | |
258bfae2 | 2918 | |
c973d557 JJ |
2919 | /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL. |
2920 | We need to emit DTP-relative relocations. */ | |
2921 | ||
2922 | void | |
2923 | rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x) | |
2924 | { | |
2925 | switch (size) | |
2926 | { | |
2927 | case 4: | |
2928 | fputs ("\t.long\t", file); | |
2929 | break; | |
2930 | case 8: | |
2931 | fputs (DOUBLE_INT_ASM_OP, file); | |
2932 | break; | |
2933 | default: | |
2934 | abort (); | |
2935 | } | |
2936 | output_addr_const (file, x); | |
2937 | fputs ("@dtprel+0x8000", file); | |
2938 | } | |
2939 | ||
c4501e62 JJ |
2940 | /* Construct the SYMBOL_REF for the tls_get_addr function. */ |
2941 | ||
2942 | static GTY(()) rtx rs6000_tls_symbol; | |
2943 | static rtx | |
863d938c | 2944 | rs6000_tls_get_addr (void) |
c4501e62 JJ |
2945 | { |
2946 | if (!rs6000_tls_symbol) | |
2947 | rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr"); | |
2948 | ||
2949 | return rs6000_tls_symbol; | |
2950 | } | |
2951 | ||
2952 | /* Construct the SYMBOL_REF for TLS GOT references. */ | |
2953 | ||
2954 | static GTY(()) rtx rs6000_got_symbol; | |
2955 | static rtx | |
863d938c | 2956 | rs6000_got_sym (void) |
c4501e62 JJ |
2957 | { |
2958 | if (!rs6000_got_symbol) | |
2959 | { | |
2960 | rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); | |
2961 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL; | |
2962 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL; | |
2963 | } | |
2964 | ||
2965 | return rs6000_got_symbol; | |
2966 | } | |
2967 | ||
2968 | /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute | |
2969 | this (thread-local) address. */ | |
2970 | ||
2971 | static rtx | |
a2369ed3 | 2972 | rs6000_legitimize_tls_address (rtx addr, enum tls_model model) |
c4501e62 JJ |
2973 | { |
2974 | rtx dest, insn; | |
2975 | ||
2976 | dest = gen_reg_rtx (Pmode); | |
2977 | if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16) | |
2978 | { | |
2979 | rtx tlsreg; | |
2980 | ||
2981 | if (TARGET_64BIT) | |
2982 | { | |
2983 | tlsreg = gen_rtx_REG (Pmode, 13); | |
2984 | insn = gen_tls_tprel_64 (dest, tlsreg, addr); | |
2985 | } | |
2986 | else | |
2987 | { | |
2988 | tlsreg = gen_rtx_REG (Pmode, 2); | |
2989 | insn = gen_tls_tprel_32 (dest, tlsreg, addr); | |
2990 | } | |
2991 | emit_insn (insn); | |
2992 | } | |
2993 | else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32) | |
2994 | { | |
2995 | rtx tlsreg, tmp; | |
2996 | ||
2997 | tmp = gen_reg_rtx (Pmode); | |
2998 | if (TARGET_64BIT) | |
2999 | { | |
3000 | tlsreg = gen_rtx_REG (Pmode, 13); | |
3001 | insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr); | |
3002 | } | |
3003 | else | |
3004 | { | |
3005 | tlsreg = gen_rtx_REG (Pmode, 2); | |
3006 | insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr); | |
3007 | } | |
3008 | emit_insn (insn); | |
3009 | if (TARGET_64BIT) | |
3010 | insn = gen_tls_tprel_lo_64 (dest, tmp, addr); | |
3011 | else | |
3012 | insn = gen_tls_tprel_lo_32 (dest, tmp, addr); | |
3013 | emit_insn (insn); | |
3014 | } | |
3015 | else | |
3016 | { | |
3017 | rtx r3, got, tga, tmp1, tmp2, eqv; | |
3018 | ||
3019 | if (TARGET_64BIT) | |
3020 | got = gen_rtx_REG (Pmode, TOC_REGISTER); | |
3021 | else | |
3022 | { | |
3023 | if (flag_pic == 1) | |
3024 | got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); | |
3025 | else | |
3026 | { | |
3027 | rtx gsym = rs6000_got_sym (); | |
3028 | got = gen_reg_rtx (Pmode); | |
3029 | if (flag_pic == 0) | |
3030 | rs6000_emit_move (got, gsym, Pmode); | |
3031 | else | |
3032 | { | |
3033 | char buf[30]; | |
3034 | static int tls_got_labelno = 0; | |
3035 | rtx tempLR, lab, tmp3, mem; | |
3036 | rtx first, last; | |
3037 | ||
3038 | ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++); | |
3039 | lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
3040 | tempLR = gen_reg_rtx (Pmode); | |
3041 | tmp1 = gen_reg_rtx (Pmode); | |
3042 | tmp2 = gen_reg_rtx (Pmode); | |
3043 | tmp3 = gen_reg_rtx (Pmode); | |
3044 | mem = gen_rtx_MEM (Pmode, tmp1); | |
3045 | RTX_UNCHANGING_P (mem) = 1; | |
3046 | ||
3047 | first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab, | |
3048 | gsym)); | |
3049 | emit_move_insn (tmp1, tempLR); | |
3050 | emit_move_insn (tmp2, mem); | |
3051 | emit_insn (gen_addsi3 (tmp3, tmp1, tmp2)); | |
3052 | last = emit_move_insn (got, tmp3); | |
3053 | REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym, | |
3054 | REG_NOTES (last)); | |
3055 | REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, | |
3056 | REG_NOTES (first)); | |
3057 | REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, | |
3058 | REG_NOTES (last)); | |
3059 | } | |
3060 | } | |
3061 | } | |
3062 | ||
3063 | if (model == TLS_MODEL_GLOBAL_DYNAMIC) | |
3064 | { | |
3065 | r3 = gen_rtx_REG (Pmode, 3); | |
3066 | if (TARGET_64BIT) | |
3067 | insn = gen_tls_gd_64 (r3, got, addr); | |
3068 | else | |
3069 | insn = gen_tls_gd_32 (r3, got, addr); | |
3070 | start_sequence (); | |
3071 | emit_insn (insn); | |
3072 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
3073 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
3074 | insn = emit_call_insn (insn); | |
3075 | CONST_OR_PURE_CALL_P (insn) = 1; | |
3076 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
3077 | insn = get_insns (); | |
3078 | end_sequence (); | |
3079 | emit_libcall_block (insn, dest, r3, addr); | |
3080 | } | |
3081 | else if (model == TLS_MODEL_LOCAL_DYNAMIC) | |
3082 | { | |
3083 | r3 = gen_rtx_REG (Pmode, 3); | |
3084 | if (TARGET_64BIT) | |
3085 | insn = gen_tls_ld_64 (r3, got); | |
3086 | else | |
3087 | insn = gen_tls_ld_32 (r3, got); | |
3088 | start_sequence (); | |
3089 | emit_insn (insn); | |
3090 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
3091 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
3092 | insn = emit_call_insn (insn); | |
3093 | CONST_OR_PURE_CALL_P (insn) = 1; | |
3094 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
3095 | insn = get_insns (); | |
3096 | end_sequence (); | |
3097 | tmp1 = gen_reg_rtx (Pmode); | |
3098 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), | |
3099 | UNSPEC_TLSLD); | |
3100 | emit_libcall_block (insn, tmp1, r3, eqv); | |
3101 | if (rs6000_tls_size == 16) | |
3102 | { | |
3103 | if (TARGET_64BIT) | |
3104 | insn = gen_tls_dtprel_64 (dest, tmp1, addr); | |
3105 | else | |
3106 | insn = gen_tls_dtprel_32 (dest, tmp1, addr); | |
3107 | } | |
3108 | else if (rs6000_tls_size == 32) | |
3109 | { | |
3110 | tmp2 = gen_reg_rtx (Pmode); | |
3111 | if (TARGET_64BIT) | |
3112 | insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr); | |
3113 | else | |
3114 | insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr); | |
3115 | emit_insn (insn); | |
3116 | if (TARGET_64BIT) | |
3117 | insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr); | |
3118 | else | |
3119 | insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr); | |
3120 | } | |
3121 | else | |
3122 | { | |
3123 | tmp2 = gen_reg_rtx (Pmode); | |
3124 | if (TARGET_64BIT) | |
3125 | insn = gen_tls_got_dtprel_64 (tmp2, got, addr); | |
3126 | else | |
3127 | insn = gen_tls_got_dtprel_32 (tmp2, got, addr); | |
3128 | emit_insn (insn); | |
3129 | insn = gen_rtx_SET (Pmode, dest, | |
3130 | gen_rtx_PLUS (Pmode, tmp2, tmp1)); | |
3131 | } | |
3132 | emit_insn (insn); | |
3133 | } | |
3134 | else | |
3135 | { | |
3136 | /* IE, or 64 bit offset LE. */ | |
3137 | tmp2 = gen_reg_rtx (Pmode); | |
3138 | if (TARGET_64BIT) | |
3139 | insn = gen_tls_got_tprel_64 (tmp2, got, addr); | |
3140 | else | |
3141 | insn = gen_tls_got_tprel_32 (tmp2, got, addr); | |
3142 | emit_insn (insn); | |
3143 | if (TARGET_64BIT) | |
3144 | insn = gen_tls_tls_64 (dest, tmp2, addr); | |
3145 | else | |
3146 | insn = gen_tls_tls_32 (dest, tmp2, addr); | |
3147 | emit_insn (insn); | |
3148 | } | |
3149 | } | |
3150 | ||
3151 | return dest; | |
3152 | } | |
3153 | ||
3154 | /* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in | |
3155 | instruction definitions. */ | |
3156 | ||
3157 | int | |
a2369ed3 | 3158 | rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED) |
c4501e62 JJ |
3159 | { |
3160 | return RS6000_SYMBOL_REF_TLS_P (x); | |
3161 | } | |
3162 | ||
3163 | /* Return 1 if X contains a thread-local symbol. */ | |
3164 | ||
3165 | bool | |
a2369ed3 | 3166 | rs6000_tls_referenced_p (rtx x) |
c4501e62 | 3167 | { |
cd413cab AP |
3168 | if (! TARGET_HAVE_TLS) |
3169 | return false; | |
3170 | ||
c4501e62 JJ |
3171 | return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0); |
3172 | } | |
3173 | ||
3174 | /* Return 1 if *X is a thread-local symbol. This is the same as | |
3175 | rs6000_tls_symbol_ref except for the type of the unused argument. */ | |
3176 | ||
3177 | static inline int | |
a2369ed3 | 3178 | rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
3179 | { |
3180 | return RS6000_SYMBOL_REF_TLS_P (*x); | |
3181 | } | |
3182 | ||
24ea750e DJ |
3183 | /* The convention appears to be to define this wherever it is used. |
3184 | With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P | |
3185 | is now used here. */ | |
3186 | #ifndef REG_MODE_OK_FOR_BASE_P | |
3187 | #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO) | |
3188 | #endif | |
3189 | ||
3190 | /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to | |
3191 | replace the input X, or the original X if no replacement is called for. | |
3192 | The output parameter *WIN is 1 if the calling macro should goto WIN, | |
3193 | 0 if it should not. | |
3194 | ||
3195 | For RS/6000, we wish to handle large displacements off a base | |
3196 | register by splitting the addend across an addiu/addis and the mem insn. | |
3197 | This cuts number of extra insns needed from 3 to 1. | |
3198 | ||
3199 | On Darwin, we use this to generate code for floating point constants. | |
3200 | A movsf_low is generated so we wind up with 2 instructions rather than 3. | |
3201 | The Darwin code is inside #if TARGET_MACHO because only then is | |
3202 | machopic_function_base_name() defined. */ | |
3203 | rtx | |
a2369ed3 DJ |
3204 | rs6000_legitimize_reload_address (rtx x, enum machine_mode mode, |
3205 | int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win) | |
24ea750e DJ |
3206 | { |
3207 | /* We must recognize output that we have already generated ourselves. */ | |
3208 | if (GET_CODE (x) == PLUS | |
3209 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3210 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
3211 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
3212 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
3213 | { | |
3214 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3215 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3216 | opnum, (enum reload_type)type); | |
3217 | *win = 1; | |
3218 | return x; | |
3219 | } | |
3deb2758 | 3220 | |
24ea750e DJ |
3221 | #if TARGET_MACHO |
3222 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic | |
3223 | && GET_CODE (x) == LO_SUM | |
3224 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3225 | && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx | |
3226 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH | |
3227 | && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST | |
3228 | && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1) | |
3229 | && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS | |
3230 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF | |
3231 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF) | |
3232 | { | |
3233 | /* Result of previous invocation of this function on Darwin | |
6f317ef3 | 3234 | floating point constant. */ |
24ea750e DJ |
3235 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
3236 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
3237 | opnum, (enum reload_type)type); | |
3238 | *win = 1; | |
3239 | return x; | |
3240 | } | |
3241 | #endif | |
3242 | if (GET_CODE (x) == PLUS | |
3243 | && GET_CODE (XEXP (x, 0)) == REG | |
3244 | && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER | |
3245 | && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode) | |
78c875e8 | 3246 | && GET_CODE (XEXP (x, 1)) == CONST_INT |
93638d7a | 3247 | && !SPE_VECTOR_MODE (mode) |
78c875e8 | 3248 | && !ALTIVEC_VECTOR_MODE (mode)) |
24ea750e DJ |
3249 | { |
3250 | HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); | |
3251 | HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; | |
3252 | HOST_WIDE_INT high | |
3253 | = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
3254 | ||
3255 | /* Check for 32-bit overflow. */ | |
3256 | if (high + low != val) | |
3257 | { | |
3258 | *win = 0; | |
3259 | return x; | |
3260 | } | |
3261 | ||
3262 | /* Reload the high part into a base reg; leave the low part | |
3263 | in the mem directly. */ | |
3264 | ||
3265 | x = gen_rtx_PLUS (GET_MODE (x), | |
3266 | gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), | |
3267 | GEN_INT (high)), | |
3268 | GEN_INT (low)); | |
3269 | ||
3270 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3271 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3272 | opnum, (enum reload_type)type); | |
3273 | *win = 1; | |
3274 | return x; | |
3275 | } | |
3276 | #if TARGET_MACHO | |
3277 | if (GET_CODE (x) == SYMBOL_REF | |
3278 | && DEFAULT_ABI == ABI_DARWIN | |
69ef87e2 | 3279 | && !ALTIVEC_VECTOR_MODE (mode) |
a29077da GK |
3280 | && (flag_pic || MACHO_DYNAMIC_NO_PIC_P) |
3281 | /* Don't do this for TFmode, since the result isn't offsettable. */ | |
3282 | && mode != TFmode) | |
24ea750e | 3283 | { |
a29077da GK |
3284 | if (flag_pic) |
3285 | { | |
3286 | rtx offset = gen_rtx_CONST (Pmode, | |
3287 | gen_rtx_MINUS (Pmode, x, | |
3288 | gen_rtx_SYMBOL_REF (Pmode, | |
3289 | machopic_function_base_name ()))); | |
3290 | x = gen_rtx_LO_SUM (GET_MODE (x), | |
3291 | gen_rtx_PLUS (Pmode, pic_offset_table_rtx, | |
3292 | gen_rtx_HIGH (Pmode, offset)), offset); | |
3293 | } | |
3294 | else | |
3295 | x = gen_rtx_LO_SUM (GET_MODE (x), | |
3296 | gen_rtx_HIGH (Pmode, x), x); | |
3297 | ||
24ea750e | 3298 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
a29077da GK |
3299 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, |
3300 | opnum, (enum reload_type)type); | |
24ea750e DJ |
3301 | *win = 1; |
3302 | return x; | |
3303 | } | |
3304 | #endif | |
3305 | if (TARGET_TOC | |
4d588c14 | 3306 | && constant_pool_expr_p (x) |
c1f11548 | 3307 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode)) |
24ea750e DJ |
3308 | { |
3309 | (x) = create_TOC_reference (x); | |
3310 | *win = 1; | |
3311 | return x; | |
3312 | } | |
3313 | *win = 0; | |
3314 | return x; | |
3315 | } | |
3316 | ||
258bfae2 FS |
3317 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression |
3318 | that is a valid memory address for an instruction. | |
3319 | The MODE argument is the machine mode for the MEM expression | |
3320 | that wants to use this address. | |
3321 | ||
3322 | On the RS/6000, there are four valid address: a SYMBOL_REF that | |
3323 | refers to a constant pool entry of an address (or the sum of it | |
3324 | plus a constant), a short (16-bit signed) constant plus a register, | |
3325 | the sum of two registers, or a register indirect, possibly with an | |
5bdc5878 | 3326 | auto-increment. For DFmode and DImode with a constant plus register, |
258bfae2 FS |
3327 | we must ensure that both words are addressable or PowerPC64 with offset |
3328 | word aligned. | |
3329 | ||
3330 | For modes spanning multiple registers (DFmode in 32-bit GPRs, | |
76d2b81d | 3331 | 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because |
258bfae2 FS |
3332 | adjacent memory cells are accessed by adding word-sized offsets |
3333 | during assembly output. */ | |
3334 | int | |
a2369ed3 | 3335 | rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict) |
258bfae2 | 3336 | { |
c4501e62 JJ |
3337 | if (RS6000_SYMBOL_REF_TLS_P (x)) |
3338 | return 0; | |
4d588c14 | 3339 | if (legitimate_indirect_address_p (x, reg_ok_strict)) |
258bfae2 FS |
3340 | return 1; |
3341 | if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) | |
0d6d6892 | 3342 | && !ALTIVEC_VECTOR_MODE (mode) |
a3170dc6 | 3343 | && !SPE_VECTOR_MODE (mode) |
258bfae2 | 3344 | && TARGET_UPDATE |
4d588c14 | 3345 | && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict)) |
258bfae2 | 3346 | return 1; |
4d588c14 | 3347 | if (legitimate_small_data_p (mode, x)) |
258bfae2 | 3348 | return 1; |
4d588c14 | 3349 | if (legitimate_constant_pool_address_p (x)) |
258bfae2 FS |
3350 | return 1; |
3351 | /* If not REG_OK_STRICT (before reload) let pass any stack offset. */ | |
3352 | if (! reg_ok_strict | |
3353 | && GET_CODE (x) == PLUS | |
3354 | && GET_CODE (XEXP (x, 0)) == REG | |
708d2456 HP |
3355 | && (XEXP (x, 0) == virtual_stack_vars_rtx |
3356 | || XEXP (x, 0) == arg_pointer_rtx) | |
258bfae2 FS |
3357 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
3358 | return 1; | |
76d2b81d | 3359 | if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3360 | return 1; |
3361 | if (mode != TImode | |
76d2b81d | 3362 | && mode != TFmode |
a3170dc6 AH |
3363 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
3364 | || TARGET_POWERPC64 | |
fcce224d | 3365 | || (mode != DFmode && mode != TFmode)) |
258bfae2 | 3366 | && (TARGET_POWERPC64 || mode != DImode) |
4d588c14 | 3367 | && legitimate_indexed_address_p (x, reg_ok_strict)) |
258bfae2 | 3368 | return 1; |
4d588c14 | 3369 | if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3370 | return 1; |
3371 | return 0; | |
3372 | } | |
4d588c14 RH |
3373 | |
3374 | /* Go to LABEL if ADDR (a legitimate address expression) | |
3375 | has an effect that depends on the machine mode it is used for. | |
3376 | ||
3377 | On the RS/6000 this is true of all integral offsets (since AltiVec | |
3378 | modes don't allow them) or is a pre-increment or decrement. | |
3379 | ||
3380 | ??? Except that due to conceptual problems in offsettable_address_p | |
3381 | we can't really report the problems of integral offsets. So leave | |
3382 | this assuming that the adjustable offset must be valid for the | |
3383 | sub-words of a TFmode operand, which is what we had before. */ | |
3384 | ||
3385 | bool | |
a2369ed3 | 3386 | rs6000_mode_dependent_address (rtx addr) |
4d588c14 RH |
3387 | { |
3388 | switch (GET_CODE (addr)) | |
3389 | { | |
3390 | case PLUS: | |
3391 | if (GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
3392 | { | |
3393 | unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1)); | |
3394 | return val + 12 + 0x8000 >= 0x10000; | |
3395 | } | |
3396 | break; | |
3397 | ||
3398 | case LO_SUM: | |
3399 | return true; | |
3400 | ||
3401 | case PRE_INC: | |
3402 | case PRE_DEC: | |
3403 | return TARGET_UPDATE; | |
3404 | ||
3405 | default: | |
3406 | break; | |
3407 | } | |
3408 | ||
3409 | return false; | |
3410 | } | |
d8ecbcdb AH |
3411 | |
3412 | /* Return number of consecutive hard regs needed starting at reg REGNO | |
3413 | to hold something of mode MODE. | |
3414 | This is ordinarily the length in words of a value of mode MODE | |
3415 | but can be less for certain modes in special long registers. | |
3416 | ||
3417 | For the SPE, GPRs are 64 bits but only 32 bits are visible in | |
3418 | scalar instructions. The upper 32 bits are only available to the | |
3419 | SIMD instructions. | |
3420 | ||
3421 | POWER and PowerPC GPRs hold 32 bits worth; | |
3422 | PowerPC64 GPRs and FPRs point register holds 64 bits worth. */ | |
3423 | ||
3424 | int | |
3425 | rs6000_hard_regno_nregs (int regno, enum machine_mode mode) | |
3426 | { | |
3427 | if (FP_REGNO_P (regno)) | |
3428 | return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD; | |
3429 | ||
3430 | if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
3431 | return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD; | |
3432 | ||
3433 | if (ALTIVEC_REGNO_P (regno)) | |
3434 | return | |
3435 | (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD; | |
3436 | ||
3437 | return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
3438 | } | |
2aa4498c AH |
3439 | |
3440 | /* Change register usage conditional on target flags. */ | |
3441 | void | |
3442 | rs6000_conditional_register_usage (void) | |
3443 | { | |
3444 | int i; | |
3445 | ||
3446 | /* Set MQ register fixed (already call_used) if not POWER | |
3447 | architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not | |
3448 | be allocated. */ | |
3449 | if (! TARGET_POWER) | |
3450 | fixed_regs[64] = 1; | |
3451 | ||
3452 | /* 64-bit AIX reserves GPR13 for thread-private data. */ | |
3453 | if (TARGET_64BIT) | |
3454 | fixed_regs[13] = call_used_regs[13] | |
3455 | = call_really_used_regs[13] = 1; | |
3456 | ||
3457 | /* Conditionally disable FPRs. */ | |
3458 | if (TARGET_SOFT_FLOAT || !TARGET_FPRS) | |
3459 | for (i = 32; i < 64; i++) | |
3460 | fixed_regs[i] = call_used_regs[i] | |
3461 | = call_really_used_regs[i] = 1; | |
3462 | ||
3463 | if (DEFAULT_ABI == ABI_V4 | |
3464 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM | |
3465 | && flag_pic == 2) | |
3466 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3467 | ||
3468 | if (DEFAULT_ABI == ABI_V4 | |
3469 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM | |
3470 | && flag_pic == 1) | |
3471 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3472 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3473 | = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3474 | ||
3475 | if (DEFAULT_ABI == ABI_DARWIN | |
3476 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) | |
3477 | global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3478 | = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3479 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3480 | = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3481 | ||
b4db40bf JJ |
3482 | if (TARGET_TOC && TARGET_MINIMAL_TOC) |
3483 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3484 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3485 | ||
2aa4498c AH |
3486 | if (TARGET_ALTIVEC) |
3487 | global_regs[VSCR_REGNO] = 1; | |
3488 | ||
3489 | if (TARGET_SPE) | |
3490 | { | |
3491 | global_regs[SPEFSCR_REGNO] = 1; | |
3492 | fixed_regs[FIXED_SCRATCH] | |
3493 | = call_used_regs[FIXED_SCRATCH] | |
3494 | = call_really_used_regs[FIXED_SCRATCH] = 1; | |
3495 | } | |
3496 | ||
3497 | if (! TARGET_ALTIVEC) | |
3498 | { | |
3499 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
3500 | fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1; | |
3501 | call_really_used_regs[VRSAVE_REGNO] = 1; | |
3502 | } | |
3503 | ||
3504 | if (TARGET_ALTIVEC_ABI) | |
3505 | for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i) | |
3506 | call_used_regs[i] = call_really_used_regs[i] = 1; | |
3507 | } | |
fb4d4348 | 3508 | \f |
a4f6c312 SS |
3509 | /* Try to output insns to set TARGET equal to the constant C if it can |
3510 | be done in less than N insns. Do all computations in MODE. | |
3511 | Returns the place where the output has been placed if it can be | |
3512 | done and the insns have been emitted. If it would take more than N | |
3513 | insns, zero is returned and no insns and emitted. */ | |
2bfcf297 DB |
3514 | |
3515 | rtx | |
a2369ed3 DJ |
3516 | rs6000_emit_set_const (rtx dest, enum machine_mode mode, |
3517 | rtx source, int n ATTRIBUTE_UNUSED) | |
2bfcf297 | 3518 | { |
af8cb5c5 | 3519 | rtx result, insn, set; |
2bfcf297 DB |
3520 | HOST_WIDE_INT c0, c1; |
3521 | ||
af8cb5c5 | 3522 | if (mode == QImode || mode == HImode) |
2bfcf297 DB |
3523 | { |
3524 | if (dest == NULL) | |
3525 | dest = gen_reg_rtx (mode); | |
3526 | emit_insn (gen_rtx_SET (VOIDmode, dest, source)); | |
3527 | return dest; | |
3528 | } | |
af8cb5c5 | 3529 | else if (mode == SImode) |
2bfcf297 | 3530 | { |
af8cb5c5 DE |
3531 | result = no_new_pseudos ? dest : gen_reg_rtx (SImode); |
3532 | ||
3533 | emit_insn (gen_rtx_SET (VOIDmode, result, | |
3534 | GEN_INT (INTVAL (source) | |
3535 | & (~ (HOST_WIDE_INT) 0xffff)))); | |
3536 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3537 | gen_rtx_IOR (SImode, result, | |
3538 | GEN_INT (INTVAL (source) & 0xffff)))); | |
3539 | result = dest; | |
2bfcf297 | 3540 | } |
af8cb5c5 | 3541 | else if (mode == DImode) |
2bfcf297 | 3542 | { |
af8cb5c5 DE |
3543 | if (GET_CODE (source) == CONST_INT) |
3544 | { | |
3545 | c0 = INTVAL (source); | |
3546 | c1 = -(c0 < 0); | |
3547 | } | |
3548 | else if (GET_CODE (source) == CONST_DOUBLE) | |
3549 | { | |
2bfcf297 | 3550 | #if HOST_BITS_PER_WIDE_INT >= 64 |
af8cb5c5 DE |
3551 | c0 = CONST_DOUBLE_LOW (source); |
3552 | c1 = -(c0 < 0); | |
2bfcf297 | 3553 | #else |
af8cb5c5 DE |
3554 | c0 = CONST_DOUBLE_LOW (source); |
3555 | c1 = CONST_DOUBLE_HIGH (source); | |
2bfcf297 | 3556 | #endif |
af8cb5c5 DE |
3557 | } |
3558 | else | |
3559 | abort (); | |
3560 | ||
3561 | result = rs6000_emit_set_long_const (dest, c0, c1); | |
2bfcf297 DB |
3562 | } |
3563 | else | |
a4f6c312 | 3564 | abort (); |
2bfcf297 | 3565 | |
af8cb5c5 DE |
3566 | insn = get_last_insn (); |
3567 | set = single_set (insn); | |
3568 | if (! CONSTANT_P (SET_SRC (set))) | |
3569 | set_unique_reg_note (insn, REG_EQUAL, source); | |
3570 | ||
3571 | return result; | |
2bfcf297 DB |
3572 | } |
3573 | ||
3574 | /* Having failed to find a 3 insn sequence in rs6000_emit_set_const, | |
3575 | fall back to a straight forward decomposition. We do this to avoid | |
3576 | exponential run times encountered when looking for longer sequences | |
3577 | with rs6000_emit_set_const. */ | |
3578 | static rtx | |
a2369ed3 | 3579 | rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2) |
2bfcf297 DB |
3580 | { |
3581 | if (!TARGET_POWERPC64) | |
3582 | { | |
3583 | rtx operand1, operand2; | |
3584 | ||
3585 | operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0, | |
3586 | DImode); | |
3587 | operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, | |
3588 | DImode); | |
3589 | emit_move_insn (operand1, GEN_INT (c1)); | |
3590 | emit_move_insn (operand2, GEN_INT (c2)); | |
3591 | } | |
3592 | else | |
3593 | { | |
bc06712d | 3594 | HOST_WIDE_INT ud1, ud2, ud3, ud4; |
252b88f7 | 3595 | |
bc06712d | 3596 | ud1 = c1 & 0xffff; |
f921c9c9 | 3597 | ud2 = (c1 & 0xffff0000) >> 16; |
2bfcf297 | 3598 | #if HOST_BITS_PER_WIDE_INT >= 64 |
bc06712d | 3599 | c2 = c1 >> 32; |
2bfcf297 | 3600 | #endif |
bc06712d | 3601 | ud3 = c2 & 0xffff; |
f921c9c9 | 3602 | ud4 = (c2 & 0xffff0000) >> 16; |
2bfcf297 | 3603 | |
bc06712d TR |
3604 | if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) |
3605 | || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) | |
2bfcf297 | 3606 | { |
bc06712d | 3607 | if (ud1 & 0x8000) |
b78d48dd | 3608 | emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000))); |
bc06712d TR |
3609 | else |
3610 | emit_move_insn (dest, GEN_INT (ud1)); | |
2bfcf297 | 3611 | } |
2bfcf297 | 3612 | |
bc06712d TR |
3613 | else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000)) |
3614 | || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000))) | |
252b88f7 | 3615 | { |
bc06712d TR |
3616 | if (ud2 & 0x8000) |
3617 | emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000) | |
3618 | - 0x80000000)); | |
252b88f7 | 3619 | else |
bc06712d TR |
3620 | emit_move_insn (dest, GEN_INT (ud2 << 16)); |
3621 | if (ud1 != 0) | |
3622 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
252b88f7 | 3623 | } |
bc06712d TR |
3624 | else if ((ud4 == 0xffff && (ud3 & 0x8000)) |
3625 | || (ud4 == 0 && ! (ud3 & 0x8000))) | |
3626 | { | |
3627 | if (ud3 & 0x8000) | |
3628 | emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000) | |
3629 | - 0x80000000)); | |
3630 | else | |
3631 | emit_move_insn (dest, GEN_INT (ud3 << 16)); | |
3632 | ||
3633 | if (ud2 != 0) | |
3634 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2))); | |
3635 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16))); | |
3636 | if (ud1 != 0) | |
3637 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
3638 | } | |
3639 | else | |
3640 | { | |
3641 | if (ud4 & 0x8000) | |
3642 | emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000) | |
3643 | - 0x80000000)); | |
3644 | else | |
3645 | emit_move_insn (dest, GEN_INT (ud4 << 16)); | |
3646 | ||
3647 | if (ud3 != 0) | |
3648 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3))); | |
2bfcf297 | 3649 | |
bc06712d TR |
3650 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32))); |
3651 | if (ud2 != 0) | |
3652 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, | |
3653 | GEN_INT (ud2 << 16))); | |
3654 | if (ud1 != 0) | |
3655 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
3656 | } | |
3657 | } | |
2bfcf297 DB |
3658 | return dest; |
3659 | } | |
3660 | ||
76d2b81d DJ |
3661 | /* Helper for the following. Get rid of [r+r] memory refs |
3662 | in cases where it won't work (TImode, TFmode). */ | |
3663 | ||
3664 | static void | |
3665 | rs6000_eliminate_indexed_memrefs (rtx operands[2]) | |
3666 | { | |
3667 | if (GET_CODE (operands[0]) == MEM | |
3668 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
3669 | && ! reload_in_progress) | |
3670 | operands[0] | |
3671 | = replace_equiv_address (operands[0], | |
3672 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
3673 | ||
3674 | if (GET_CODE (operands[1]) == MEM | |
3675 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
3676 | && ! reload_in_progress) | |
3677 | operands[1] | |
3678 | = replace_equiv_address (operands[1], | |
3679 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
3680 | } | |
3681 | ||
fb4d4348 GK |
3682 | /* Emit a move from SOURCE to DEST in mode MODE. */ |
3683 | void | |
a2369ed3 | 3684 | rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode) |
fb4d4348 GK |
3685 | { |
3686 | rtx operands[2]; | |
3687 | operands[0] = dest; | |
3688 | operands[1] = source; | |
3689 | ||
3690 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ | |
3691 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
3692 | && ! FLOAT_MODE_P (mode) | |
3693 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
3694 | { | |
3695 | /* FIXME. This should never happen. */ | |
3696 | /* Since it seems that it does, do the safe thing and convert | |
3697 | to a CONST_INT. */ | |
2496c7bd | 3698 | operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode); |
fb4d4348 GK |
3699 | } |
3700 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
3701 | && ! FLOAT_MODE_P (mode) | |
3702 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
3703 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
3704 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
3705 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
3706 | abort (); | |
c9e8cb32 DD |
3707 | |
3708 | /* Check if GCC is setting up a block move that will end up using FP | |
3709 | registers as temporaries. We must make sure this is acceptable. */ | |
3710 | if (GET_CODE (operands[0]) == MEM | |
3711 | && GET_CODE (operands[1]) == MEM | |
3712 | && mode == DImode | |
41543739 GK |
3713 | && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0])) |
3714 | || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1]))) | |
3715 | && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32 | |
3716 | ? 32 : MEM_ALIGN (operands[0]))) | |
3717 | || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32 | |
3718 | ? 32 | |
3719 | : MEM_ALIGN (operands[1])))) | |
3720 | && ! MEM_VOLATILE_P (operands [0]) | |
3721 | && ! MEM_VOLATILE_P (operands [1])) | |
c9e8cb32 | 3722 | { |
41543739 GK |
3723 | emit_move_insn (adjust_address (operands[0], SImode, 0), |
3724 | adjust_address (operands[1], SImode, 0)); | |
3725 | emit_move_insn (adjust_address (operands[0], SImode, 4), | |
3726 | adjust_address (operands[1], SImode, 4)); | |
c9e8cb32 DD |
3727 | return; |
3728 | } | |
630d42a0 | 3729 | |
67cef334 DE |
3730 | if (!no_new_pseudos) |
3731 | { | |
3732 | if (GET_CODE (operands[1]) == MEM && optimize > 0 | |
3733 | && (mode == QImode || mode == HImode || mode == SImode) | |
3734 | && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode)) | |
3735 | { | |
3736 | rtx reg = gen_reg_rtx (word_mode); | |
3737 | ||
3738 | emit_insn (gen_rtx_SET (word_mode, reg, | |
3739 | gen_rtx_ZERO_EXTEND (word_mode, | |
3740 | operands[1]))); | |
3741 | operands[1] = gen_lowpart (mode, reg); | |
3742 | } | |
3743 | if (GET_CODE (operands[0]) != REG) | |
3744 | operands[1] = force_reg (mode, operands[1]); | |
3745 | } | |
a9098fd0 | 3746 | |
a3170dc6 AH |
3747 | if (mode == SFmode && ! TARGET_POWERPC |
3748 | && TARGET_HARD_FLOAT && TARGET_FPRS | |
ffc14f31 | 3749 | && GET_CODE (operands[0]) == MEM) |
fb4d4348 | 3750 | { |
ffc14f31 GK |
3751 | int regnum; |
3752 | ||
3753 | if (reload_in_progress || reload_completed) | |
3754 | regnum = true_regnum (operands[1]); | |
3755 | else if (GET_CODE (operands[1]) == REG) | |
3756 | regnum = REGNO (operands[1]); | |
3757 | else | |
3758 | regnum = -1; | |
fb4d4348 GK |
3759 | |
3760 | /* If operands[1] is a register, on POWER it may have | |
3761 | double-precision data in it, so truncate it to single | |
3762 | precision. */ | |
3763 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
3764 | { | |
3765 | rtx newreg; | |
3766 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
3767 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
3768 | operands[1] = newreg; | |
3769 | } | |
3770 | } | |
3771 | ||
c4501e62 JJ |
3772 | /* Recognize the case where operand[1] is a reference to thread-local |
3773 | data and load its address to a register. */ | |
3774 | if (GET_CODE (operands[1]) == SYMBOL_REF) | |
3775 | { | |
3776 | enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]); | |
3777 | if (model != 0) | |
3778 | operands[1] = rs6000_legitimize_tls_address (operands[1], model); | |
3779 | } | |
3780 | ||
8f4e6caf RH |
3781 | /* Handle the case where reload calls us with an invalid address. */ |
3782 | if (reload_in_progress && mode == Pmode | |
69ef87e2 | 3783 | && (! general_operand (operands[1], mode) |
8f4e6caf RH |
3784 | || ! nonimmediate_operand (operands[0], mode))) |
3785 | goto emit_set; | |
3786 | ||
a9baceb1 GK |
3787 | /* 128-bit constant floating-point values on Darwin should really be |
3788 | loaded as two parts. */ | |
3789 | if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) | |
3790 | && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128 | |
3791 | && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE) | |
3792 | { | |
3793 | /* DImode is used, not DFmode, because simplify_gen_subreg doesn't | |
3794 | know how to get a DFmode SUBREG of a TFmode. */ | |
3795 | rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0), | |
3796 | simplify_gen_subreg (DImode, operands[1], mode, 0), | |
3797 | DImode); | |
3798 | rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, | |
3799 | GET_MODE_SIZE (DImode)), | |
3800 | simplify_gen_subreg (DImode, operands[1], mode, | |
3801 | GET_MODE_SIZE (DImode)), | |
3802 | DImode); | |
3803 | return; | |
3804 | } | |
3805 | ||
fb4d4348 GK |
3806 | /* FIXME: In the long term, this switch statement should go away |
3807 | and be replaced by a sequence of tests based on things like | |
3808 | mode == Pmode. */ | |
3809 | switch (mode) | |
3810 | { | |
3811 | case HImode: | |
3812 | case QImode: | |
3813 | if (CONSTANT_P (operands[1]) | |
3814 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 3815 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3816 | break; |
3817 | ||
06f4e019 | 3818 | case TFmode: |
76d2b81d DJ |
3819 | rs6000_eliminate_indexed_memrefs (operands); |
3820 | /* fall through */ | |
3821 | ||
fb4d4348 GK |
3822 | case DFmode: |
3823 | case SFmode: | |
3824 | if (CONSTANT_P (operands[1]) | |
3825 | && ! easy_fp_constant (operands[1], mode)) | |
a9098fd0 | 3826 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3827 | break; |
3828 | ||
0ac081f6 AH |
3829 | case V16QImode: |
3830 | case V8HImode: | |
3831 | case V4SFmode: | |
3832 | case V4SImode: | |
a3170dc6 AH |
3833 | case V4HImode: |
3834 | case V2SFmode: | |
3835 | case V2SImode: | |
00a892b8 | 3836 | case V1DImode: |
69ef87e2 | 3837 | if (CONSTANT_P (operands[1]) |
d744e06e | 3838 | && !easy_vector_constant (operands[1], mode)) |
0ac081f6 AH |
3839 | operands[1] = force_const_mem (mode, operands[1]); |
3840 | break; | |
3841 | ||
fb4d4348 | 3842 | case SImode: |
a9098fd0 | 3843 | case DImode: |
fb4d4348 GK |
3844 | /* Use default pattern for address of ELF small data */ |
3845 | if (TARGET_ELF | |
a9098fd0 | 3846 | && mode == Pmode |
f607bc57 | 3847 | && DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
3848 | && (GET_CODE (operands[1]) == SYMBOL_REF |
3849 | || GET_CODE (operands[1]) == CONST) | |
3850 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
3851 | { |
3852 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
3853 | return; | |
3854 | } | |
3855 | ||
f607bc57 | 3856 | if (DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
3857 | && mode == Pmode && mode == SImode |
3858 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
3859 | { |
3860 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
3861 | return; | |
3862 | } | |
3863 | ||
ee890fe2 | 3864 | if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN) |
f1384257 AM |
3865 | && TARGET_NO_TOC |
3866 | && ! flag_pic | |
a9098fd0 | 3867 | && mode == Pmode |
fb4d4348 GK |
3868 | && CONSTANT_P (operands[1]) |
3869 | && GET_CODE (operands[1]) != HIGH | |
3870 | && GET_CODE (operands[1]) != CONST_INT) | |
3871 | { | |
a9098fd0 | 3872 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
3873 | |
3874 | /* If this is a function address on -mcall-aixdesc, | |
3875 | convert it to the address of the descriptor. */ | |
3876 | if (DEFAULT_ABI == ABI_AIX | |
3877 | && GET_CODE (operands[1]) == SYMBOL_REF | |
3878 | && XSTR (operands[1], 0)[0] == '.') | |
3879 | { | |
3880 | const char *name = XSTR (operands[1], 0); | |
3881 | rtx new_ref; | |
3882 | while (*name == '.') | |
3883 | name++; | |
3884 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
3885 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
3886 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
d1908feb | 3887 | SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]); |
fb4d4348 | 3888 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); |
d1908feb | 3889 | SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]); |
fb4d4348 GK |
3890 | operands[1] = new_ref; |
3891 | } | |
7509c759 | 3892 | |
ee890fe2 SS |
3893 | if (DEFAULT_ABI == ABI_DARWIN) |
3894 | { | |
ab82a49f AP |
3895 | #if TARGET_MACHO |
3896 | if (MACHO_DYNAMIC_NO_PIC_P) | |
3897 | { | |
3898 | /* Take care of any required data indirection. */ | |
3899 | operands[1] = rs6000_machopic_legitimize_pic_address ( | |
3900 | operands[1], mode, operands[0]); | |
3901 | if (operands[0] != operands[1]) | |
3902 | emit_insn (gen_rtx_SET (VOIDmode, | |
3903 | operands[0], operands[1])); | |
3904 | return; | |
3905 | } | |
3906 | #endif | |
ee890fe2 SS |
3907 | emit_insn (gen_macho_high (target, operands[1])); |
3908 | emit_insn (gen_macho_low (operands[0], target, operands[1])); | |
3909 | return; | |
3910 | } | |
3911 | ||
fb4d4348 GK |
3912 | emit_insn (gen_elf_high (target, operands[1])); |
3913 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
3914 | return; | |
3915 | } | |
3916 | ||
a9098fd0 GK |
3917 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
3918 | and we have put it in the TOC, we just need to make a TOC-relative | |
3919 | reference to it. */ | |
3920 | if (TARGET_TOC | |
3921 | && GET_CODE (operands[1]) == SYMBOL_REF | |
4d588c14 | 3922 | && constant_pool_expr_p (operands[1]) |
a9098fd0 GK |
3923 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), |
3924 | get_pool_mode (operands[1]))) | |
fb4d4348 | 3925 | { |
a9098fd0 | 3926 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 3927 | } |
a9098fd0 GK |
3928 | else if (mode == Pmode |
3929 | && CONSTANT_P (operands[1]) | |
38886f37 AO |
3930 | && ((GET_CODE (operands[1]) != CONST_INT |
3931 | && ! easy_fp_constant (operands[1], mode)) | |
3932 | || (GET_CODE (operands[1]) == CONST_INT | |
3933 | && num_insns_constant (operands[1], mode) > 2) | |
3934 | || (GET_CODE (operands[0]) == REG | |
3935 | && FP_REGNO_P (REGNO (operands[0])))) | |
a9098fd0 | 3936 | && GET_CODE (operands[1]) != HIGH |
4d588c14 RH |
3937 | && ! legitimate_constant_pool_address_p (operands[1]) |
3938 | && ! toc_relative_expr_p (operands[1])) | |
fb4d4348 GK |
3939 | { |
3940 | /* Emit a USE operation so that the constant isn't deleted if | |
3941 | expensive optimizations are turned on because nobody | |
3942 | references it. This should only be done for operands that | |
3943 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
3944 | This should not be done for operands that contain LABEL_REFs. | |
3945 | For now, we just handle the obvious case. */ | |
3946 | if (GET_CODE (operands[1]) != LABEL_REF) | |
3947 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
3948 | ||
c859cda6 | 3949 | #if TARGET_MACHO |
ee890fe2 | 3950 | /* Darwin uses a special PIC legitimizer. */ |
ab82a49f | 3951 | if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT) |
ee890fe2 | 3952 | { |
ee890fe2 SS |
3953 | operands[1] = |
3954 | rs6000_machopic_legitimize_pic_address (operands[1], mode, | |
c859cda6 DJ |
3955 | operands[0]); |
3956 | if (operands[0] != operands[1]) | |
3957 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
ee890fe2 SS |
3958 | return; |
3959 | } | |
c859cda6 | 3960 | #endif |
ee890fe2 | 3961 | |
fb4d4348 GK |
3962 | /* If we are to limit the number of things we put in the TOC and |
3963 | this is a symbol plus a constant we can add in one insn, | |
3964 | just put the symbol in the TOC and add the constant. Don't do | |
3965 | this if reload is in progress. */ | |
3966 | if (GET_CODE (operands[1]) == CONST | |
3967 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
3968 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 3969 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
3970 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
3971 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
3972 | && ! side_effects_p (operands[0])) | |
3973 | { | |
a4f6c312 SS |
3974 | rtx sym = |
3975 | force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); | |
fb4d4348 GK |
3976 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
3977 | ||
a9098fd0 GK |
3978 | sym = force_reg (mode, sym); |
3979 | if (mode == SImode) | |
3980 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
3981 | else | |
3982 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
3983 | return; |
3984 | } | |
3985 | ||
a9098fd0 | 3986 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
3987 | |
3988 | if (TARGET_TOC | |
4d588c14 | 3989 | && constant_pool_expr_p (XEXP (operands[1], 0)) |
d34c5b80 DE |
3990 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P ( |
3991 | get_pool_constant (XEXP (operands[1], 0)), | |
3992 | get_pool_mode (XEXP (operands[1], 0)))) | |
a9098fd0 | 3993 | { |
ba4828e0 RK |
3994 | operands[1] |
3995 | = gen_rtx_MEM (mode, | |
3996 | create_TOC_reference (XEXP (operands[1], 0))); | |
3997 | set_mem_alias_set (operands[1], get_TOC_alias_set ()); | |
fb4d4348 | 3998 | RTX_UNCHANGING_P (operands[1]) = 1; |
a9098fd0 | 3999 | } |
fb4d4348 GK |
4000 | } |
4001 | break; | |
a9098fd0 | 4002 | |
fb4d4348 | 4003 | case TImode: |
76d2b81d DJ |
4004 | rs6000_eliminate_indexed_memrefs (operands); |
4005 | ||
27dc0551 DE |
4006 | if (TARGET_POWER) |
4007 | { | |
4008 | emit_insn (gen_rtx_PARALLEL (VOIDmode, | |
4009 | gen_rtvec (2, | |
4010 | gen_rtx_SET (VOIDmode, | |
4011 | operands[0], operands[1]), | |
4012 | gen_rtx_CLOBBER (VOIDmode, | |
4013 | gen_rtx_SCRATCH (SImode))))); | |
4014 | return; | |
4015 | } | |
fb4d4348 GK |
4016 | break; |
4017 | ||
4018 | default: | |
4019 | abort (); | |
4020 | } | |
4021 | ||
a9098fd0 GK |
4022 | /* Above, we may have called force_const_mem which may have returned |
4023 | an invalid address. If we can, fix this up; otherwise, reload will | |
4024 | have to deal with it. */ | |
8f4e6caf RH |
4025 | if (GET_CODE (operands[1]) == MEM && ! reload_in_progress) |
4026 | operands[1] = validize_mem (operands[1]); | |
a9098fd0 | 4027 | |
8f4e6caf | 4028 | emit_set: |
fb4d4348 GK |
4029 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
4030 | } | |
4697a36c | 4031 | \f |
2858f73a GK |
4032 | /* Nonzero if we can use a floating-point register to pass this arg. */ |
4033 | #define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \ | |
4034 | (GET_MODE_CLASS (MODE) == MODE_FLOAT \ | |
4035 | && (CUM)->fregno <= FP_ARG_MAX_REG \ | |
4036 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
4037 | ||
4038 | /* Nonzero if we can use an AltiVec register to pass this arg. */ | |
4039 | #define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \ | |
4040 | (ALTIVEC_VECTOR_MODE (MODE) \ | |
4041 | && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \ | |
4042 | && TARGET_ALTIVEC_ABI \ | |
83953138 | 4043 | && (NAMED)) |
2858f73a | 4044 | |
c6e8c921 GK |
4045 | /* Return a nonzero value to say to return the function value in |
4046 | memory, just as large structures are always returned. TYPE will be | |
4047 | the data type of the value, and FNTYPE will be the type of the | |
4048 | function doing the returning, or @code{NULL} for libcalls. | |
4049 | ||
4050 | The AIX ABI for the RS/6000 specifies that all structures are | |
4051 | returned in memory. The Darwin ABI does the same. The SVR4 ABI | |
4052 | specifies that structures <= 8 bytes are returned in r3/r4, but a | |
4053 | draft put them in memory, and GCC used to implement the draft | |
4054 | instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET | |
4055 | controls this instead of DEFAULT_ABI; V.4 targets needing backward | |
4056 | compatibility can change DRAFT_V4_STRUCT_RET to override the | |
4057 | default, and -m switches get the final word. See | |
4058 | rs6000_override_options for more details. | |
4059 | ||
4060 | The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit | |
4061 | long double support is enabled. These values are returned in memory. | |
4062 | ||
4063 | int_size_in_bytes returns -1 for variable size objects, which go in | |
4064 | memory always. The cast to unsigned makes -1 > 8. */ | |
4065 | ||
4066 | static bool | |
4067 | rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED) | |
4068 | { | |
4069 | if (AGGREGATE_TYPE_P (type) | |
4070 | && (TARGET_AIX_STRUCT_RET | |
4071 | || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8)) | |
4072 | return true; | |
4073 | if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode) | |
4074 | return true; | |
4075 | return false; | |
4076 | } | |
4077 | ||
4697a36c MM |
4078 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
4079 | for a call to a function whose data type is FNTYPE. | |
4080 | For a library call, FNTYPE is 0. | |
4081 | ||
4082 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 4083 | so we never return a PARALLEL. */ |
4697a36c MM |
4084 | |
4085 | void | |
a2369ed3 | 4086 | init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, |
0f6937fe AM |
4087 | rtx libname ATTRIBUTE_UNUSED, int incoming, |
4088 | int libcall, int n_named_args) | |
4697a36c MM |
4089 | { |
4090 | static CUMULATIVE_ARGS zero_cumulative; | |
4091 | ||
4092 | *cum = zero_cumulative; | |
4093 | cum->words = 0; | |
4094 | cum->fregno = FP_ARG_MIN_REG; | |
0ac081f6 | 4095 | cum->vregno = ALTIVEC_ARG_MIN_REG; |
4697a36c | 4096 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); |
ddcc8263 DE |
4097 | cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall) |
4098 | ? CALL_LIBCALL : CALL_NORMAL); | |
4cc833b7 | 4099 | cum->sysv_gregno = GP_ARG_MIN_REG; |
a6c9bed4 AH |
4100 | cum->stdarg = fntype |
4101 | && (TYPE_ARG_TYPES (fntype) != 0 | |
4102 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
4103 | != void_type_node)); | |
4697a36c | 4104 | |
0f6937fe AM |
4105 | cum->nargs_prototype = 0; |
4106 | if (incoming || cum->prototype) | |
4107 | cum->nargs_prototype = n_named_args; | |
4697a36c | 4108 | |
a5c76ee6 ZW |
4109 | /* Check for a longcall attribute. */ |
4110 | if (fntype | |
4111 | && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) | |
4112 | && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
4113 | cum->call_cookie = CALL_LONG; |
4114 | ||
4697a36c MM |
4115 | if (TARGET_DEBUG_ARG) |
4116 | { | |
4117 | fprintf (stderr, "\ninit_cumulative_args:"); | |
4118 | if (fntype) | |
4119 | { | |
4120 | tree ret_type = TREE_TYPE (fntype); | |
4121 | fprintf (stderr, " ret code = %s,", | |
4122 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
4123 | } | |
4124 | ||
6a4cee5f MM |
4125 | if (cum->call_cookie & CALL_LONG) |
4126 | fprintf (stderr, " longcall,"); | |
4127 | ||
4697a36c MM |
4128 | fprintf (stderr, " proto = %d, nargs = %d\n", |
4129 | cum->prototype, cum->nargs_prototype); | |
4130 | } | |
6d0ef01e HP |
4131 | |
4132 | if (fntype | |
4133 | && !TARGET_ALTIVEC | |
4134 | && TARGET_ALTIVEC_ABI | |
4135 | && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype)))) | |
4136 | { | |
4137 | error ("Cannot return value in vector register because" | |
4138 | " altivec instructions are disabled, use -maltivec" | |
4139 | " to enable them."); | |
4140 | } | |
4697a36c MM |
4141 | } |
4142 | \f | |
c229cba9 DE |
4143 | /* If defined, a C expression which determines whether, and in which |
4144 | direction, to pad out an argument with extra space. The value | |
4145 | should be of type `enum direction': either `upward' to pad above | |
4146 | the argument, `downward' to pad below, or `none' to inhibit | |
4147 | padding. | |
4148 | ||
4149 | For the AIX ABI structs are always stored left shifted in their | |
4150 | argument slot. */ | |
4151 | ||
9ebbca7d | 4152 | enum direction |
a2369ed3 | 4153 | function_arg_padding (enum machine_mode mode, tree type) |
c229cba9 | 4154 | { |
6e985040 AM |
4155 | #ifndef AGGREGATE_PADDING_FIXED |
4156 | #define AGGREGATE_PADDING_FIXED 0 | |
4157 | #endif | |
4158 | #ifndef AGGREGATES_PAD_UPWARD_ALWAYS | |
4159 | #define AGGREGATES_PAD_UPWARD_ALWAYS 0 | |
4160 | #endif | |
4161 | ||
4162 | if (!AGGREGATE_PADDING_FIXED) | |
4163 | { | |
4164 | /* GCC used to pass structures of the same size as integer types as | |
4165 | if they were in fact integers, ignoring FUNCTION_ARG_PADDING. | |
4166 | ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were | |
4167 | passed padded downward, except that -mstrict-align further | |
4168 | muddied the water in that multi-component structures of 2 and 4 | |
4169 | bytes in size were passed padded upward. | |
4170 | ||
4171 | The following arranges for best compatibility with previous | |
4172 | versions of gcc, but removes the -mstrict-align dependency. */ | |
4173 | if (BYTES_BIG_ENDIAN) | |
4174 | { | |
4175 | HOST_WIDE_INT size = 0; | |
4176 | ||
4177 | if (mode == BLKmode) | |
4178 | { | |
4179 | if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) | |
4180 | size = int_size_in_bytes (type); | |
4181 | } | |
4182 | else | |
4183 | size = GET_MODE_SIZE (mode); | |
4184 | ||
4185 | if (size == 1 || size == 2 || size == 4) | |
4186 | return downward; | |
4187 | } | |
4188 | return upward; | |
4189 | } | |
4190 | ||
4191 | if (AGGREGATES_PAD_UPWARD_ALWAYS) | |
4192 | { | |
4193 | if (type != 0 && AGGREGATE_TYPE_P (type)) | |
4194 | return upward; | |
4195 | } | |
c229cba9 | 4196 | |
d3704c46 KH |
4197 | /* Fall back to the default. */ |
4198 | return DEFAULT_FUNCTION_ARG_PADDING (mode, type); | |
c229cba9 DE |
4199 | } |
4200 | ||
b6c9286a MM |
4201 | /* If defined, a C expression that gives the alignment boundary, in bits, |
4202 | of an argument with the specified mode and type. If it is not defined, | |
4203 | PARM_BOUNDARY is used for all arguments. | |
4204 | ||
2310f99a | 4205 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
4206 | |
4207 | int | |
a2369ed3 | 4208 | function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED) |
b6c9286a | 4209 | { |
4ed78545 AM |
4210 | if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8) |
4211 | return 64; | |
4212 | else if (SPE_VECTOR_MODE (mode)) | |
e1f83b4d | 4213 | return 64; |
b2d04ecf | 4214 | else if (ALTIVEC_VECTOR_MODE (mode)) |
0ac081f6 | 4215 | return 128; |
9ebbca7d | 4216 | else |
b6c9286a | 4217 | return PARM_BOUNDARY; |
b6c9286a | 4218 | } |
c53bdcf5 AM |
4219 | |
4220 | /* Compute the size (in words) of a function argument. */ | |
4221 | ||
4222 | static unsigned long | |
4223 | rs6000_arg_size (enum machine_mode mode, tree type) | |
4224 | { | |
4225 | unsigned long size; | |
4226 | ||
4227 | if (mode != BLKmode) | |
4228 | size = GET_MODE_SIZE (mode); | |
4229 | else | |
4230 | size = int_size_in_bytes (type); | |
4231 | ||
4232 | if (TARGET_32BIT) | |
4233 | return (size + 3) >> 2; | |
4234 | else | |
4235 | return (size + 7) >> 3; | |
4236 | } | |
b6c9286a | 4237 | \f |
4697a36c MM |
4238 | /* Update the data in CUM to advance over an argument |
4239 | of mode MODE and data type TYPE. | |
b2d04ecf AM |
4240 | (TYPE is null for libcalls where that information may not be available.) |
4241 | ||
4242 | Note that for args passed by reference, function_arg will be called | |
4243 | with MODE and TYPE set to that of the pointer to the arg, not the arg | |
4244 | itself. */ | |
4697a36c MM |
4245 | |
4246 | void | |
a2369ed3 DJ |
4247 | function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4248 | tree type, int named) | |
4697a36c MM |
4249 | { |
4250 | cum->nargs_prototype--; | |
4251 | ||
0ac081f6 AH |
4252 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
4253 | { | |
4ed78545 AM |
4254 | bool stack = false; |
4255 | ||
2858f73a | 4256 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
6d0ef01e HP |
4257 | { |
4258 | cum->vregno++; | |
4259 | if (!TARGET_ALTIVEC) | |
4260 | error ("Cannot pass argument in vector register because" | |
4261 | " altivec instructions are disabled, use -maltivec" | |
4262 | " to enable them."); | |
4ed78545 AM |
4263 | |
4264 | /* PowerPC64 Linux and AIX allocate GPRs for a vector argument | |
4265 | even if it is going to be passed in a vector register. | |
4266 | Darwin does the same for variable-argument functions. */ | |
4267 | if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT) | |
4268 | || (cum->stdarg && DEFAULT_ABI != ABI_V4)) | |
4269 | stack = true; | |
6d0ef01e | 4270 | } |
4ed78545 AM |
4271 | else |
4272 | stack = true; | |
4273 | ||
4274 | if (stack) | |
c72d6c26 | 4275 | { |
a594a19c GK |
4276 | int align; |
4277 | ||
2858f73a GK |
4278 | /* Vector parameters must be 16-byte aligned. This places |
4279 | them at 2 mod 4 in terms of words in 32-bit mode, since | |
4280 | the parameter save area starts at offset 24 from the | |
4281 | stack. In 64-bit mode, they just have to start on an | |
4282 | even word, since the parameter save area is 16-byte | |
4283 | aligned. Space for GPRs is reserved even if the argument | |
4284 | will be passed in memory. */ | |
4285 | if (TARGET_32BIT) | |
4ed78545 | 4286 | align = (2 - cum->words) & 3; |
2858f73a GK |
4287 | else |
4288 | align = cum->words & 1; | |
c53bdcf5 | 4289 | cum->words += align + rs6000_arg_size (mode, type); |
2858f73a | 4290 | |
a594a19c GK |
4291 | if (TARGET_DEBUG_ARG) |
4292 | { | |
4293 | fprintf (stderr, "function_adv: words = %2d, align=%d, ", | |
4294 | cum->words, align); | |
4295 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n", | |
2858f73a GK |
4296 | cum->nargs_prototype, cum->prototype, |
4297 | GET_MODE_NAME (mode)); | |
a594a19c GK |
4298 | } |
4299 | } | |
0ac081f6 | 4300 | } |
a4b0320c | 4301 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) |
a6c9bed4 AH |
4302 | && !cum->stdarg |
4303 | && cum->sysv_gregno <= GP_ARG_MAX_REG) | |
a4b0320c | 4304 | cum->sysv_gregno++; |
f607bc57 | 4305 | else if (DEFAULT_ABI == ABI_V4) |
4697a36c | 4306 | { |
a3170dc6 | 4307 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 | 4308 | && (mode == SFmode || mode == DFmode)) |
4697a36c | 4309 | { |
4cc833b7 RH |
4310 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
4311 | cum->fregno++; | |
4312 | else | |
4313 | { | |
4314 | if (mode == DFmode) | |
4315 | cum->words += cum->words & 1; | |
c53bdcf5 | 4316 | cum->words += rs6000_arg_size (mode, type); |
4cc833b7 | 4317 | } |
4697a36c | 4318 | } |
4cc833b7 RH |
4319 | else |
4320 | { | |
b2d04ecf | 4321 | int n_words = rs6000_arg_size (mode, type); |
4cc833b7 RH |
4322 | int gregno = cum->sysv_gregno; |
4323 | ||
4ed78545 AM |
4324 | /* Long long and SPE vectors are put in (r3,r4), (r5,r6), |
4325 | (r7,r8) or (r9,r10). As does any other 2 word item such | |
4326 | as complex int due to a historical mistake. */ | |
4327 | if (n_words == 2) | |
4328 | gregno += (1 - gregno) & 1; | |
4cc833b7 | 4329 | |
4ed78545 | 4330 | /* Multi-reg args are not split between registers and stack. */ |
4cc833b7 RH |
4331 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
4332 | { | |
4ed78545 AM |
4333 | /* Long long and SPE vectors are aligned on the stack. |
4334 | So are other 2 word items such as complex int due to | |
4335 | a historical mistake. */ | |
4cc833b7 RH |
4336 | if (n_words == 2) |
4337 | cum->words += cum->words & 1; | |
4338 | cum->words += n_words; | |
4339 | } | |
4697a36c | 4340 | |
4cc833b7 RH |
4341 | /* Note: continuing to accumulate gregno past when we've started |
4342 | spilling to the stack indicates the fact that we've started | |
4343 | spilling to the stack to expand_builtin_saveregs. */ | |
4344 | cum->sysv_gregno = gregno + n_words; | |
4345 | } | |
4697a36c | 4346 | |
4cc833b7 RH |
4347 | if (TARGET_DEBUG_ARG) |
4348 | { | |
4349 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
4350 | cum->words, cum->fregno); | |
4351 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
4352 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
4353 | fprintf (stderr, "mode = %4s, named = %d\n", | |
4354 | GET_MODE_NAME (mode), named); | |
4355 | } | |
4697a36c MM |
4356 | } |
4357 | else | |
4cc833b7 | 4358 | { |
b2d04ecf AM |
4359 | int n_words = rs6000_arg_size (mode, type); |
4360 | int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; | |
a4f6c312 | 4361 | |
b2d04ecf AM |
4362 | /* The simple alignment calculation here works because |
4363 | function_arg_boundary / PARM_BOUNDARY will only be 1 or 2. | |
4364 | If we ever want to handle alignments larger than 8 bytes for | |
4365 | 32-bit or 16 bytes for 64-bit, then we'll need to take into | |
4366 | account the offset to the start of the parm save area. */ | |
4367 | align &= cum->words; | |
4368 | cum->words += align + n_words; | |
4697a36c | 4369 | |
a3170dc6 AH |
4370 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
4371 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
c53bdcf5 | 4372 | cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3; |
4cc833b7 RH |
4373 | |
4374 | if (TARGET_DEBUG_ARG) | |
4375 | { | |
4376 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
4377 | cum->words, cum->fregno); | |
4378 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
4379 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
4380 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
4381 | } | |
4382 | } | |
4697a36c | 4383 | } |
a6c9bed4 AH |
4384 | |
4385 | /* Determine where to put a SIMD argument on the SPE. */ | |
b78d48dd | 4386 | |
a6c9bed4 | 4387 | static rtx |
a2369ed3 DJ |
4388 | rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4389 | tree type) | |
a6c9bed4 AH |
4390 | { |
4391 | if (cum->stdarg) | |
4392 | { | |
4393 | int gregno = cum->sysv_gregno; | |
c53bdcf5 | 4394 | int n_words = rs6000_arg_size (mode, type); |
a6c9bed4 AH |
4395 | |
4396 | /* SPE vectors are put in odd registers. */ | |
4397 | if (n_words == 2 && (gregno & 1) == 0) | |
4398 | gregno += 1; | |
4399 | ||
4400 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
4401 | { | |
4402 | rtx r1, r2; | |
4403 | enum machine_mode m = SImode; | |
4404 | ||
4405 | r1 = gen_rtx_REG (m, gregno); | |
4406 | r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx); | |
4407 | r2 = gen_rtx_REG (m, gregno + 1); | |
4408 | r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4)); | |
4409 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); | |
4410 | } | |
4411 | else | |
b78d48dd | 4412 | return NULL_RTX; |
a6c9bed4 AH |
4413 | } |
4414 | else | |
4415 | { | |
4416 | if (cum->sysv_gregno <= GP_ARG_MAX_REG) | |
4417 | return gen_rtx_REG (mode, cum->sysv_gregno); | |
4418 | else | |
b78d48dd | 4419 | return NULL_RTX; |
a6c9bed4 AH |
4420 | } |
4421 | } | |
4422 | ||
b78d48dd FJ |
4423 | /* Determine where to place an argument in 64-bit mode with 32-bit ABI. */ |
4424 | ||
4425 | static rtx | |
ec6376ab | 4426 | rs6000_mixed_function_arg (enum machine_mode mode, tree type, int align_words) |
b78d48dd | 4427 | { |
ec6376ab AM |
4428 | int n_units; |
4429 | int i, k; | |
4430 | rtx rvec[GP_ARG_NUM_REG + 1]; | |
4431 | ||
4432 | if (align_words >= GP_ARG_NUM_REG) | |
4433 | return NULL_RTX; | |
4434 | ||
4435 | n_units = rs6000_arg_size (mode, type); | |
4436 | ||
4437 | /* Optimize the simple case where the arg fits in one gpr, except in | |
4438 | the case of BLKmode due to assign_parms assuming that registers are | |
4439 | BITS_PER_WORD wide. */ | |
4440 | if (n_units == 0 | |
4441 | || (n_units == 1 && mode != BLKmode)) | |
4442 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4443 | ||
4444 | k = 0; | |
4445 | if (align_words + n_units > GP_ARG_NUM_REG) | |
4446 | /* Not all of the arg fits in gprs. Say that it goes in memory too, | |
4447 | using a magic NULL_RTX component. | |
4448 | FIXME: This is not strictly correct. Only some of the arg | |
4449 | belongs in memory, not all of it. However, there isn't any way | |
4450 | to do this currently, apart from building rtx descriptions for | |
4451 | the pieces of memory we want stored. Due to bugs in the generic | |
4452 | code we can't use the normal function_arg_partial_nregs scheme | |
4453 | with the PARALLEL arg description we emit here. | |
4454 | In any case, the code to store the whole arg to memory is often | |
4455 | more efficient than code to store pieces, and we know that space | |
4456 | is available in the right place for the whole arg. */ | |
4457 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx); | |
4458 | ||
4459 | i = 0; | |
4460 | do | |
36a454e1 | 4461 | { |
ec6376ab AM |
4462 | rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words); |
4463 | rtx off = GEN_INT (i++ * 4); | |
4464 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off); | |
36a454e1 | 4465 | } |
ec6376ab AM |
4466 | while (++align_words < GP_ARG_NUM_REG && --n_units != 0); |
4467 | ||
4468 | return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec)); | |
b78d48dd FJ |
4469 | } |
4470 | ||
4697a36c MM |
4471 | /* Determine where to put an argument to a function. |
4472 | Value is zero to push the argument on the stack, | |
4473 | or a hard register in which to store the argument. | |
4474 | ||
4475 | MODE is the argument's machine mode. | |
4476 | TYPE is the data type of the argument (as a tree). | |
4477 | This is null for libcalls where that information may | |
4478 | not be available. | |
4479 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
4480 | the preceding args and about the function being called. | |
4481 | NAMED is nonzero if this argument is a named parameter | |
4482 | (otherwise it is an extra parameter matching an ellipsis). | |
4483 | ||
4484 | On RS/6000 the first eight words of non-FP are normally in registers | |
4485 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
4486 | Under V.4, the first 8 FP args are in registers. | |
4487 | ||
4488 | If this is floating-point and no prototype is specified, we use | |
4489 | both an FP and integer register (or possibly FP reg and stack). Library | |
b9599e46 | 4490 | functions (when CALL_LIBCALL is set) always have the proper types for args, |
4697a36c | 4491 | so we can pass the FP value just in one register. emit_library_function |
b2d04ecf AM |
4492 | doesn't support PARALLEL anyway. |
4493 | ||
4494 | Note that for args passed by reference, function_arg will be called | |
4495 | with MODE and TYPE set to that of the pointer to the arg, not the arg | |
4496 | itself. */ | |
4697a36c MM |
4497 | |
4498 | struct rtx_def * | |
a2369ed3 DJ |
4499 | function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4500 | tree type, int named) | |
4697a36c | 4501 | { |
4cc833b7 | 4502 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 4503 | |
a4f6c312 SS |
4504 | /* Return a marker to indicate whether CR1 needs to set or clear the |
4505 | bit that V.4 uses to say fp args were passed in registers. | |
4506 | Assume that we don't need the marker for software floating point, | |
4507 | or compiler generated library calls. */ | |
4697a36c MM |
4508 | if (mode == VOIDmode) |
4509 | { | |
f607bc57 | 4510 | if (abi == ABI_V4 |
7509c759 | 4511 | && cum->nargs_prototype < 0 |
b9599e46 FS |
4512 | && (cum->call_cookie & CALL_LIBCALL) == 0 |
4513 | && (cum->prototype || TARGET_NO_PROTOTYPE)) | |
7509c759 | 4514 | { |
a3170dc6 AH |
4515 | /* For the SPE, we need to crxor CR6 always. */ |
4516 | if (TARGET_SPE_ABI) | |
4517 | return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS); | |
4518 | else if (TARGET_HARD_FLOAT && TARGET_FPRS) | |
4519 | return GEN_INT (cum->call_cookie | |
4520 | | ((cum->fregno == FP_ARG_MIN_REG) | |
4521 | ? CALL_V4_SET_FP_ARGS | |
4522 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 4523 | } |
4697a36c | 4524 | |
7509c759 | 4525 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
4526 | } |
4527 | ||
2858f73a | 4528 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
c72d6c26 HP |
4529 | if (TARGET_64BIT && ! cum->prototype) |
4530 | { | |
4531 | /* Vector parameters get passed in vector register | |
4532 | and also in GPRs or memory, in absence of prototype. */ | |
4533 | int align_words; | |
4534 | rtx slot; | |
4535 | align_words = (cum->words + 1) & ~1; | |
4536 | ||
4537 | if (align_words >= GP_ARG_NUM_REG) | |
4538 | { | |
4539 | slot = NULL_RTX; | |
4540 | } | |
4541 | else | |
4542 | { | |
4543 | slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4544 | } | |
4545 | return gen_rtx_PARALLEL (mode, | |
4546 | gen_rtvec (2, | |
4547 | gen_rtx_EXPR_LIST (VOIDmode, | |
4548 | slot, const0_rtx), | |
4549 | gen_rtx_EXPR_LIST (VOIDmode, | |
4550 | gen_rtx_REG (mode, cum->vregno), | |
4551 | const0_rtx))); | |
4552 | } | |
4553 | else | |
4554 | return gen_rtx_REG (mode, cum->vregno); | |
2858f73a | 4555 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
0ac081f6 | 4556 | { |
2858f73a | 4557 | if (named || abi == ABI_V4) |
a594a19c | 4558 | return NULL_RTX; |
0ac081f6 | 4559 | else |
a594a19c GK |
4560 | { |
4561 | /* Vector parameters to varargs functions under AIX or Darwin | |
4562 | get passed in memory and possibly also in GPRs. */ | |
ec6376ab AM |
4563 | int align, align_words, n_words; |
4564 | enum machine_mode part_mode; | |
a594a19c GK |
4565 | |
4566 | /* Vector parameters must be 16-byte aligned. This places them at | |
2858f73a GK |
4567 | 2 mod 4 in terms of words in 32-bit mode, since the parameter |
4568 | save area starts at offset 24 from the stack. In 64-bit mode, | |
4569 | they just have to start on an even word, since the parameter | |
4570 | save area is 16-byte aligned. */ | |
4571 | if (TARGET_32BIT) | |
4ed78545 | 4572 | align = (2 - cum->words) & 3; |
2858f73a GK |
4573 | else |
4574 | align = cum->words & 1; | |
a594a19c GK |
4575 | align_words = cum->words + align; |
4576 | ||
4577 | /* Out of registers? Memory, then. */ | |
4578 | if (align_words >= GP_ARG_NUM_REG) | |
4579 | return NULL_RTX; | |
ec6376ab AM |
4580 | |
4581 | if (TARGET_32BIT && TARGET_POWERPC64) | |
4582 | return rs6000_mixed_function_arg (mode, type, align_words); | |
4583 | ||
2858f73a GK |
4584 | /* The vector value goes in GPRs. Only the part of the |
4585 | value in GPRs is reported here. */ | |
ec6376ab AM |
4586 | part_mode = mode; |
4587 | n_words = rs6000_arg_size (mode, type); | |
4588 | if (align_words + n_words > GP_ARG_NUM_REG) | |
839a4992 | 4589 | /* Fortunately, there are only two possibilities, the value |
2858f73a GK |
4590 | is either wholly in GPRs or half in GPRs and half not. */ |
4591 | part_mode = DImode; | |
ec6376ab AM |
4592 | |
4593 | return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words); | |
a594a19c | 4594 | } |
0ac081f6 | 4595 | } |
a6c9bed4 AH |
4596 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)) |
4597 | return rs6000_spe_function_arg (cum, mode, type); | |
f607bc57 | 4598 | else if (abi == ABI_V4) |
4697a36c | 4599 | { |
a3170dc6 | 4600 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 RH |
4601 | && (mode == SFmode || mode == DFmode)) |
4602 | { | |
4603 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
4604 | return gen_rtx_REG (mode, cum->fregno); | |
4605 | else | |
b78d48dd | 4606 | return NULL_RTX; |
4cc833b7 RH |
4607 | } |
4608 | else | |
4609 | { | |
b2d04ecf | 4610 | int n_words = rs6000_arg_size (mode, type); |
4cc833b7 RH |
4611 | int gregno = cum->sysv_gregno; |
4612 | ||
4ed78545 AM |
4613 | /* Long long and SPE vectors are put in (r3,r4), (r5,r6), |
4614 | (r7,r8) or (r9,r10). As does any other 2 word item such | |
4615 | as complex int due to a historical mistake. */ | |
4616 | if (n_words == 2) | |
4617 | gregno += (1 - gregno) & 1; | |
4cc833b7 | 4618 | |
4ed78545 | 4619 | /* Multi-reg args are not split between registers and stack. */ |
ec6376ab | 4620 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
b78d48dd | 4621 | return NULL_RTX; |
ec6376ab AM |
4622 | |
4623 | if (TARGET_32BIT && TARGET_POWERPC64) | |
4624 | return rs6000_mixed_function_arg (mode, type, | |
4625 | gregno - GP_ARG_MIN_REG); | |
4626 | return gen_rtx_REG (mode, gregno); | |
4cc833b7 | 4627 | } |
4697a36c | 4628 | } |
4cc833b7 RH |
4629 | else |
4630 | { | |
b2d04ecf AM |
4631 | int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; |
4632 | int align_words = cum->words + (cum->words & align); | |
b78d48dd | 4633 | |
2858f73a | 4634 | if (USE_FP_FOR_ARG_P (cum, mode, type)) |
4cc833b7 | 4635 | { |
ec6376ab AM |
4636 | rtx rvec[GP_ARG_NUM_REG + 1]; |
4637 | rtx r; | |
4638 | int k; | |
c53bdcf5 AM |
4639 | bool needs_psave; |
4640 | enum machine_mode fmode = mode; | |
c53bdcf5 AM |
4641 | unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3; |
4642 | ||
4643 | if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1) | |
4644 | { | |
c53bdcf5 AM |
4645 | /* Currently, we only ever need one reg here because complex |
4646 | doubles are split. */ | |
ec6376ab | 4647 | if (cum->fregno != FP_ARG_MAX_REG || fmode != TFmode) |
c53bdcf5 | 4648 | abort (); |
ec6376ab AM |
4649 | |
4650 | /* Long double split over regs and memory. */ | |
4651 | fmode = DFmode; | |
c53bdcf5 | 4652 | } |
c53bdcf5 AM |
4653 | |
4654 | /* Do we also need to pass this arg in the parameter save | |
4655 | area? */ | |
4656 | needs_psave = (type | |
4657 | && (cum->nargs_prototype <= 0 | |
4658 | || (DEFAULT_ABI == ABI_AIX | |
4659 | && TARGET_XL_CALL | |
4660 | && align_words >= GP_ARG_NUM_REG))); | |
4661 | ||
4662 | if (!needs_psave && mode == fmode) | |
ec6376ab | 4663 | return gen_rtx_REG (fmode, cum->fregno); |
c53bdcf5 | 4664 | |
ec6376ab | 4665 | k = 0; |
c53bdcf5 AM |
4666 | if (needs_psave) |
4667 | { | |
ec6376ab | 4668 | /* Describe the part that goes in gprs or the stack. |
c53bdcf5 | 4669 | This piece must come first, before the fprs. */ |
c53bdcf5 AM |
4670 | if (align_words < GP_ARG_NUM_REG) |
4671 | { | |
4672 | unsigned long n_words = rs6000_arg_size (mode, type); | |
ec6376ab AM |
4673 | |
4674 | if (align_words + n_words > GP_ARG_NUM_REG | |
4675 | || (TARGET_32BIT && TARGET_POWERPC64)) | |
4676 | { | |
4677 | /* If this is partially on the stack, then we only | |
4678 | include the portion actually in registers here. */ | |
4679 | enum machine_mode rmode = TARGET_32BIT ? SImode : DImode; | |
4680 | rtx off; | |
4681 | do | |
4682 | { | |
4683 | r = gen_rtx_REG (rmode, | |
4684 | GP_ARG_MIN_REG + align_words); | |
4685 | off = GEN_INT (k * GET_MODE_SIZE (rmode)); | |
4686 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off); | |
4687 | } | |
4688 | while (++align_words < GP_ARG_NUM_REG && --n_words != 0); | |
4689 | } | |
4690 | else | |
4691 | { | |
4692 | /* The whole arg fits in gprs. */ | |
4693 | r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4694 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx); | |
4695 | } | |
c53bdcf5 | 4696 | } |
ec6376ab AM |
4697 | else |
4698 | /* It's entirely in memory. */ | |
4699 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx); | |
c53bdcf5 AM |
4700 | } |
4701 | ||
ec6376ab AM |
4702 | /* Describe where this piece goes in the fprs. */ |
4703 | r = gen_rtx_REG (fmode, cum->fregno); | |
4704 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx); | |
4705 | ||
4706 | return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec)); | |
4cc833b7 RH |
4707 | } |
4708 | else if (align_words < GP_ARG_NUM_REG) | |
b2d04ecf | 4709 | { |
ec6376ab AM |
4710 | if (TARGET_32BIT && TARGET_POWERPC64) |
4711 | return rs6000_mixed_function_arg (mode, type, align_words); | |
b2d04ecf AM |
4712 | |
4713 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4714 | } | |
4cc833b7 RH |
4715 | else |
4716 | return NULL_RTX; | |
4697a36c | 4717 | } |
4697a36c MM |
4718 | } |
4719 | \f | |
ec6376ab AM |
4720 | /* For an arg passed partly in registers and partly in memory, this is |
4721 | the number of registers used. For args passed entirely in registers | |
4722 | or entirely in memory, zero. When an arg is described by a PARALLEL, | |
4723 | perhaps using more than one register type, this function returns the | |
4724 | number of registers used by the first element of the PARALLEL. */ | |
4697a36c MM |
4725 | |
4726 | int | |
a2369ed3 | 4727 | function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
2858f73a | 4728 | tree type, int named) |
4697a36c | 4729 | { |
c53bdcf5 | 4730 | int ret = 0; |
ec6376ab AM |
4731 | int align; |
4732 | int parm_offset; | |
4733 | int align_words; | |
c53bdcf5 | 4734 | |
f607bc57 | 4735 | if (DEFAULT_ABI == ABI_V4) |
4697a36c | 4736 | return 0; |
4697a36c | 4737 | |
c53bdcf5 AM |
4738 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named) |
4739 | && cum->nargs_prototype >= 0) | |
4740 | return 0; | |
4741 | ||
ec6376ab AM |
4742 | align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; |
4743 | parm_offset = TARGET_32BIT ? 2 : 0; | |
4744 | align_words = cum->words + ((parm_offset - cum->words) & align); | |
4745 | ||
4746 | if (USE_FP_FOR_ARG_P (cum, mode, type) | |
4747 | /* If we are passing this arg in gprs as well, then this function | |
4748 | should return the number of gprs (or memory) partially passed, | |
4749 | *not* the number of fprs. */ | |
4750 | && !(type | |
4751 | && (cum->nargs_prototype <= 0 | |
4752 | || (DEFAULT_ABI == ABI_AIX | |
4753 | && TARGET_XL_CALL | |
4754 | && align_words >= GP_ARG_NUM_REG)))) | |
4697a36c | 4755 | { |
c53bdcf5 | 4756 | if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1) |
ec6376ab | 4757 | ret = FP_ARG_MAX_REG + 1 - cum->fregno; |
c53bdcf5 | 4758 | else if (cum->nargs_prototype >= 0) |
4697a36c MM |
4759 | return 0; |
4760 | } | |
4761 | ||
ec6376ab AM |
4762 | if (align_words < GP_ARG_NUM_REG |
4763 | && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type)) | |
4764 | ret = GP_ARG_NUM_REG - align_words; | |
4697a36c | 4765 | |
c53bdcf5 AM |
4766 | if (ret != 0 && TARGET_DEBUG_ARG) |
4767 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
4697a36c | 4768 | |
c53bdcf5 | 4769 | return ret; |
4697a36c MM |
4770 | } |
4771 | \f | |
4772 | /* A C expression that indicates when an argument must be passed by | |
4773 | reference. If nonzero for an argument, a copy of that argument is | |
4774 | made in memory and a pointer to the argument is passed instead of | |
4775 | the argument itself. The pointer is passed in whatever way is | |
4776 | appropriate for passing a pointer to that type. | |
4777 | ||
b2d04ecf AM |
4778 | Under V.4, aggregates and long double are passed by reference. |
4779 | ||
4780 | As an extension to all 32-bit ABIs, AltiVec vectors are passed by | |
4781 | reference unless the AltiVec vector extension ABI is in force. | |
c8c99a68 DE |
4782 | |
4783 | As an extension to all ABIs, variable sized types are passed by | |
4784 | reference. */ | |
4697a36c MM |
4785 | |
4786 | int | |
a2369ed3 DJ |
4787 | function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED, |
4788 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
d779d0dc | 4789 | tree type, int named ATTRIBUTE_UNUSED) |
4697a36c | 4790 | { |
b2d04ecf AM |
4791 | if ((DEFAULT_ABI == ABI_V4 |
4792 | && ((type && AGGREGATE_TYPE_P (type)) | |
4793 | || mode == TFmode)) | |
4794 | || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
4795 | || (type && int_size_in_bytes (type) < 0)) | |
4697a36c MM |
4796 | { |
4797 | if (TARGET_DEBUG_ARG) | |
b2d04ecf | 4798 | fprintf (stderr, "function_arg_pass_by_reference\n"); |
4697a36c MM |
4799 | |
4800 | return 1; | |
4801 | } | |
b2d04ecf | 4802 | return 0; |
4697a36c | 4803 | } |
5985c7a6 FJ |
4804 | |
4805 | static void | |
2d9db8eb | 4806 | rs6000_move_block_from_reg (int regno, rtx x, int nregs) |
5985c7a6 FJ |
4807 | { |
4808 | int i; | |
4809 | enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode; | |
4810 | ||
4811 | if (nregs == 0) | |
4812 | return; | |
4813 | ||
4814 | for (i = 0; i < nregs; i++) | |
4815 | { | |
4816 | rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode)); | |
4817 | if (reload_completed) | |
4818 | { | |
4819 | if (! strict_memory_address_p (reg_mode, XEXP (tem, 0))) | |
4820 | tem = NULL_RTX; | |
4821 | else | |
4822 | tem = simplify_gen_subreg (reg_mode, x, BLKmode, | |
4823 | i * GET_MODE_SIZE(reg_mode)); | |
4824 | } | |
4825 | else | |
4826 | tem = replace_equiv_address (tem, XEXP (tem, 0)); | |
4827 | ||
4828 | if (tem == NULL_RTX) | |
4829 | abort (); | |
4830 | ||
4831 | emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i)); | |
4832 | } | |
4833 | } | |
4834 | ||
4697a36c MM |
4835 | \f |
4836 | /* Perform any needed actions needed for a function that is receiving a | |
4837 | variable number of arguments. | |
4838 | ||
4839 | CUM is as above. | |
4840 | ||
4841 | MODE and TYPE are the mode and type of the current parameter. | |
4842 | ||
4843 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
4844 | that must be pushed by the prolog to pretend that our caller pushed | |
4845 | it. | |
4846 | ||
4847 | Normally, this macro will push all remaining incoming registers on the | |
4848 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
4849 | ||
c6e8c921 | 4850 | static void |
a2369ed3 DJ |
4851 | setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
4852 | tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl) | |
4697a36c | 4853 | { |
4cc833b7 RH |
4854 | CUMULATIVE_ARGS next_cum; |
4855 | int reg_size = TARGET_32BIT ? 4 : 8; | |
ca5adc63 | 4856 | rtx save_area = NULL_RTX, mem; |
dfafc897 | 4857 | int first_reg_offset, set; |
4697a36c | 4858 | |
f31bf321 | 4859 | /* Skip the last named argument. */ |
d34c5b80 | 4860 | next_cum = *cum; |
f31bf321 | 4861 | function_arg_advance (&next_cum, mode, type, 1); |
4cc833b7 | 4862 | |
f607bc57 | 4863 | if (DEFAULT_ABI == ABI_V4) |
d34c5b80 | 4864 | { |
4cc833b7 | 4865 | /* Indicate to allocate space on the stack for varargs save area. */ |
00dba523 | 4866 | cfun->machine->sysv_varargs_p = 1; |
60e2d0ca | 4867 | if (! no_rtl) |
2c4974b7 | 4868 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 4869 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
4870 | |
4871 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 4872 | } |
60e2d0ca | 4873 | else |
4697a36c | 4874 | { |
d34c5b80 | 4875 | first_reg_offset = next_cum.words; |
4cc833b7 | 4876 | save_area = virtual_incoming_args_rtx; |
00dba523 | 4877 | cfun->machine->sysv_varargs_p = 0; |
4697a36c MM |
4878 | |
4879 | if (MUST_PASS_IN_STACK (mode, type)) | |
c53bdcf5 | 4880 | first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type); |
4cc833b7 | 4881 | } |
4697a36c | 4882 | |
dfafc897 | 4883 | set = get_varargs_alias_set (); |
c81fc13e | 4884 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 4885 | { |
dfafc897 FS |
4886 | mem = gen_rtx_MEM (BLKmode, |
4887 | plus_constant (save_area, | |
4888 | first_reg_offset * reg_size)), | |
ba4828e0 | 4889 | set_mem_alias_set (mem, set); |
8ac61af7 | 4890 | set_mem_align (mem, BITS_PER_WORD); |
dfafc897 | 4891 | |
5985c7a6 FJ |
4892 | rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem, |
4893 | GP_ARG_NUM_REG - first_reg_offset); | |
4697a36c MM |
4894 | } |
4895 | ||
4697a36c | 4896 | /* Save FP registers if needed. */ |
f607bc57 | 4897 | if (DEFAULT_ABI == ABI_V4 |
a3170dc6 AH |
4898 | && TARGET_HARD_FLOAT && TARGET_FPRS |
4899 | && ! no_rtl | |
4cc833b7 | 4900 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 4901 | { |
4cc833b7 | 4902 | int fregno = next_cum.fregno; |
9ebbca7d | 4903 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
4904 | rtx lab = gen_label_rtx (); |
4905 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 4906 | |
4cc833b7 | 4907 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 4908 | pc_rtx, |
39403d82 | 4909 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
4910 | gen_rtx_NE (VOIDmode, cr1, |
4911 | const0_rtx), | |
39403d82 | 4912 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
4913 | pc_rtx))); |
4914 | ||
4cc833b7 RH |
4915 | while (fregno <= FP_ARG_V4_MAX_REG) |
4916 | { | |
dfafc897 | 4917 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
ba4828e0 | 4918 | set_mem_alias_set (mem, set); |
dfafc897 | 4919 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); |
4cc833b7 RH |
4920 | fregno++; |
4921 | off += 8; | |
4697a36c | 4922 | } |
4cc833b7 RH |
4923 | |
4924 | emit_label (lab); | |
4697a36c | 4925 | } |
4697a36c | 4926 | } |
4697a36c | 4927 | |
dfafc897 | 4928 | /* Create the va_list data type. */ |
2c4974b7 | 4929 | |
c35d187f RH |
4930 | static tree |
4931 | rs6000_build_builtin_va_list (void) | |
dfafc897 | 4932 | { |
64c2816f | 4933 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl; |
4697a36c | 4934 | |
9ebbca7d GK |
4935 | /* For AIX, prefer 'char *' because that's what the system |
4936 | header files like. */ | |
f607bc57 | 4937 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d | 4938 | return build_pointer_type (char_type_node); |
dfafc897 | 4939 | |
f1e639b1 | 4940 | record = (*lang_hooks.types.make_type) (RECORD_TYPE); |
bab45a51 | 4941 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 4942 | |
9ebbca7d GK |
4943 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
4944 | unsigned_char_type_node); | |
4945 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), | |
4946 | unsigned_char_type_node); | |
64c2816f DT |
4947 | /* Give the two bytes of padding a name, so that -Wpadded won't warn on |
4948 | every user file. */ | |
4949 | f_res = build_decl (FIELD_DECL, get_identifier ("reserved"), | |
4950 | short_unsigned_type_node); | |
dfafc897 FS |
4951 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
4952 | ptr_type_node); | |
4953 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
4954 | ptr_type_node); | |
4955 | ||
4956 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
4957 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
64c2816f | 4958 | DECL_FIELD_CONTEXT (f_res) = record; |
dfafc897 FS |
4959 | DECL_FIELD_CONTEXT (f_ovf) = record; |
4960 | DECL_FIELD_CONTEXT (f_sav) = record; | |
4961 | ||
bab45a51 FS |
4962 | TREE_CHAIN (record) = type_decl; |
4963 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
4964 | TYPE_FIELDS (record) = f_gpr; |
4965 | TREE_CHAIN (f_gpr) = f_fpr; | |
64c2816f DT |
4966 | TREE_CHAIN (f_fpr) = f_res; |
4967 | TREE_CHAIN (f_res) = f_ovf; | |
dfafc897 FS |
4968 | TREE_CHAIN (f_ovf) = f_sav; |
4969 | ||
4970 | layout_type (record); | |
4971 | ||
4972 | /* The correct type is an array type of one element. */ | |
4973 | return build_array_type (record, build_index_type (size_zero_node)); | |
4974 | } | |
4975 | ||
4976 | /* Implement va_start. */ | |
4977 | ||
4978 | void | |
a2369ed3 | 4979 | rs6000_va_start (tree valist, rtx nextarg) |
4697a36c | 4980 | { |
dfafc897 | 4981 | HOST_WIDE_INT words, n_gpr, n_fpr; |
c566f9bd | 4982 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
dfafc897 | 4983 | tree gpr, fpr, ovf, sav, t; |
2c4974b7 | 4984 | |
dfafc897 | 4985 | /* Only SVR4 needs something special. */ |
f607bc57 | 4986 | if (DEFAULT_ABI != ABI_V4) |
dfafc897 | 4987 | { |
e5faf155 | 4988 | std_expand_builtin_va_start (valist, nextarg); |
dfafc897 FS |
4989 | return; |
4990 | } | |
4991 | ||
973a648b | 4992 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 | 4993 | f_fpr = TREE_CHAIN (f_gpr); |
c566f9bd DT |
4994 | f_res = TREE_CHAIN (f_fpr); |
4995 | f_ovf = TREE_CHAIN (f_res); | |
dfafc897 FS |
4996 | f_sav = TREE_CHAIN (f_ovf); |
4997 | ||
8ebecc3b | 4998 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
44de5aeb RK |
4999 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE); |
5000 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE); | |
5001 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE); | |
5002 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE); | |
dfafc897 FS |
5003 | |
5004 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 5005 | words = current_function_args_info.words; |
dfafc897 FS |
5006 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
5007 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
5008 | ||
5009 | if (TARGET_DEBUG_ARG) | |
4a0a75dd KG |
5010 | fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = " |
5011 | HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n", | |
5012 | words, n_gpr, n_fpr); | |
dfafc897 FS |
5013 | |
5014 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0)); | |
5015 | TREE_SIDE_EFFECTS (t) = 1; | |
5016 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5017 | ||
5018 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0)); | |
5019 | TREE_SIDE_EFFECTS (t) = 1; | |
5020 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5021 | ||
5022 | /* Find the overflow area. */ | |
5023 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
5024 | if (words != 0) | |
5025 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
5026 | build_int_2 (words * UNITS_PER_WORD, 0)); | |
5027 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
5028 | TREE_SIDE_EFFECTS (t) = 1; | |
5029 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5030 | ||
5031 | /* Find the register save area. */ | |
5032 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
5033 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
5034 | build_int_2 (-RS6000_VARARGS_SIZE, -1)); | |
5035 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); | |
5036 | TREE_SIDE_EFFECTS (t) = 1; | |
5037 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5038 | } | |
5039 | ||
5040 | /* Implement va_arg. */ | |
5041 | ||
23a60a04 JM |
5042 | tree |
5043 | rs6000_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p) | |
cd3ce9b4 | 5044 | { |
cd3ce9b4 JM |
5045 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
5046 | tree gpr, fpr, ovf, sav, reg, t, u; | |
5047 | int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale; | |
5048 | tree lab_false, lab_over, addr; | |
5049 | int align; | |
5050 | tree ptrtype = build_pointer_type (type); | |
5051 | ||
5052 | if (DEFAULT_ABI != ABI_V4) | |
5053 | { | |
5054 | /* Variable sized types are passed by reference, as are AltiVec | |
5055 | vectors when 32-bit and not using the AltiVec ABI extension. */ | |
5056 | if (int_size_in_bytes (type) < 0 | |
5057 | || (TARGET_32BIT | |
5058 | && !TARGET_ALTIVEC_ABI | |
5059 | && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))) | |
5060 | { | |
5061 | /* Args grow upward. */ | |
5062 | t = build2 (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist, | |
5063 | build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0)); | |
5064 | t = build1 (NOP_EXPR, build_pointer_type (ptrtype), t); | |
5065 | t = build_fold_indirect_ref (t); | |
23a60a04 | 5066 | return build_fold_indirect_ref (t); |
cd3ce9b4 JM |
5067 | } |
5068 | if (targetm.calls.split_complex_arg | |
5069 | && TREE_CODE (type) == COMPLEX_TYPE) | |
5070 | { | |
5071 | tree elem_type = TREE_TYPE (type); | |
5072 | enum machine_mode elem_mode = TYPE_MODE (elem_type); | |
5073 | int elem_size = GET_MODE_SIZE (elem_mode); | |
5074 | ||
5075 | if (elem_size < UNITS_PER_WORD) | |
5076 | { | |
23a60a04 | 5077 | tree real_part, imag_part; |
cd3ce9b4 JM |
5078 | tree post = NULL_TREE; |
5079 | ||
23a60a04 JM |
5080 | real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p, |
5081 | &post); | |
5082 | /* Copy the value into a temporary, lest the formal temporary | |
5083 | be reused out from under us. */ | |
5084 | real_part = get_initialized_tmp_var (real_part, pre_p, &post); | |
cd3ce9b4 JM |
5085 | append_to_statement_list (post, pre_p); |
5086 | ||
23a60a04 JM |
5087 | imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p, |
5088 | post_p); | |
cd3ce9b4 | 5089 | |
23a60a04 | 5090 | return build (COMPLEX_EXPR, type, real_part, imag_part); |
cd3ce9b4 JM |
5091 | } |
5092 | } | |
5093 | ||
23a60a04 | 5094 | return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); |
cd3ce9b4 JM |
5095 | } |
5096 | ||
5097 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); | |
5098 | f_fpr = TREE_CHAIN (f_gpr); | |
5099 | f_res = TREE_CHAIN (f_fpr); | |
5100 | f_ovf = TREE_CHAIN (f_res); | |
5101 | f_sav = TREE_CHAIN (f_ovf); | |
5102 | ||
5103 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); | |
44de5aeb RK |
5104 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE); |
5105 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE); | |
5106 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE); | |
5107 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE); | |
cd3ce9b4 JM |
5108 | |
5109 | size = int_size_in_bytes (type); | |
5110 | rsize = (size + 3) / 4; | |
5111 | align = 1; | |
5112 | ||
5113 | if (AGGREGATE_TYPE_P (type) | |
5114 | || TYPE_MODE (type) == TFmode | |
5115 | || (!TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))) | |
5116 | { | |
5117 | /* Aggregates, long doubles, and AltiVec vectors are passed by | |
5118 | reference. */ | |
5119 | indirect_p = 1; | |
5120 | reg = gpr; | |
5121 | n_reg = 1; | |
5122 | sav_ofs = 0; | |
5123 | sav_scale = 4; | |
5124 | size = 4; | |
5125 | rsize = 1; | |
5126 | } | |
5127 | else if (TARGET_HARD_FLOAT && TARGET_FPRS | |
5128 | && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode)) | |
5129 | { | |
5130 | /* FP args go in FP registers, if present. */ | |
5131 | indirect_p = 0; | |
5132 | reg = fpr; | |
5133 | n_reg = 1; | |
5134 | sav_ofs = 8*4; | |
5135 | sav_scale = 8; | |
5136 | if (TYPE_MODE (type) == DFmode) | |
5137 | align = 8; | |
5138 | } | |
5139 | else | |
5140 | { | |
5141 | /* Otherwise into GP registers. */ | |
5142 | indirect_p = 0; | |
5143 | reg = gpr; | |
5144 | n_reg = rsize; | |
5145 | sav_ofs = 0; | |
5146 | sav_scale = 4; | |
5147 | if (n_reg == 2) | |
5148 | align = 8; | |
5149 | } | |
5150 | ||
5151 | /* Pull the value out of the saved registers.... */ | |
5152 | ||
5153 | lab_over = NULL; | |
5154 | addr = create_tmp_var (ptr_type_node, "addr"); | |
5155 | DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set (); | |
5156 | ||
5157 | /* AltiVec vectors never go in registers when -mabi=altivec. */ | |
5158 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))) | |
5159 | align = 16; | |
5160 | else | |
5161 | { | |
5162 | lab_false = create_artificial_label (); | |
5163 | lab_over = create_artificial_label (); | |
5164 | ||
5165 | /* Long long and SPE vectors are aligned in the registers. | |
5166 | As are any other 2 gpr item such as complex int due to a | |
5167 | historical mistake. */ | |
5168 | u = reg; | |
5169 | if (n_reg == 2) | |
5170 | { | |
5171 | u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), reg, | |
5172 | build_int_2 (n_reg - 1, 0)); | |
5173 | u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u); | |
5174 | } | |
5175 | ||
5176 | t = build_int_2 (8 - n_reg + 1, 0); | |
5177 | TREE_TYPE (t) = TREE_TYPE (reg); | |
5178 | t = build2 (GE_EXPR, boolean_type_node, u, t); | |
5179 | u = build1 (GOTO_EXPR, void_type_node, lab_false); | |
5180 | t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE); | |
5181 | gimplify_and_add (t, pre_p); | |
5182 | ||
5183 | t = sav; | |
5184 | if (sav_ofs) | |
5185 | t = build2 (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0)); | |
5186 | ||
5187 | u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, | |
5188 | build_int_2 (n_reg, 0)); | |
5189 | u = build1 (CONVERT_EXPR, integer_type_node, u); | |
5190 | u = build2 (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0)); | |
5191 | t = build2 (PLUS_EXPR, ptr_type_node, t, u); | |
5192 | ||
5193 | t = build2 (MODIFY_EXPR, void_type_node, addr, t); | |
5194 | gimplify_and_add (t, pre_p); | |
5195 | ||
5196 | t = build1 (GOTO_EXPR, void_type_node, lab_over); | |
5197 | gimplify_and_add (t, pre_p); | |
5198 | ||
5199 | t = build1 (LABEL_EXPR, void_type_node, lab_false); | |
5200 | append_to_statement_list (t, pre_p); | |
5201 | ||
5202 | if (n_reg > 2) | |
5203 | { | |
5204 | /* Ensure that we don't find any more args in regs. | |
5205 | Alignment has taken care of the n_reg == 2 case. */ | |
5206 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0)); | |
5207 | gimplify_and_add (t, pre_p); | |
5208 | } | |
5209 | } | |
5210 | ||
5211 | /* ... otherwise out of the overflow area. */ | |
5212 | ||
5213 | /* Care for on-stack alignment if needed. */ | |
5214 | t = ovf; | |
5215 | if (align != 1) | |
5216 | { | |
5217 | t = build2 (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (align - 1, 0)); | |
5218 | t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align, -1)); | |
5219 | } | |
5220 | gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue); | |
5221 | ||
5222 | u = build2 (MODIFY_EXPR, void_type_node, addr, t); | |
5223 | gimplify_and_add (u, pre_p); | |
5224 | ||
5225 | t = build2 (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0)); | |
5226 | t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); | |
5227 | gimplify_and_add (t, pre_p); | |
5228 | ||
5229 | if (lab_over) | |
5230 | { | |
5231 | t = build1 (LABEL_EXPR, void_type_node, lab_over); | |
5232 | append_to_statement_list (t, pre_p); | |
5233 | } | |
5234 | ||
5235 | if (indirect_p) | |
5236 | { | |
23a60a04 | 5237 | addr = fold_convert (build_pointer_type (ptrtype), addr); |
cd3ce9b4 JM |
5238 | addr = build_fold_indirect_ref (addr); |
5239 | } | |
5240 | else | |
23a60a04 | 5241 | addr = fold_convert (ptrtype, addr); |
cd3ce9b4 | 5242 | |
23a60a04 | 5243 | return build_fold_indirect_ref (addr); |
cd3ce9b4 JM |
5244 | } |
5245 | ||
0ac081f6 AH |
5246 | /* Builtins. */ |
5247 | ||
6a2dd09a RS |
5248 | #define def_builtin(MASK, NAME, TYPE, CODE) \ |
5249 | do { \ | |
5250 | if ((MASK) & target_flags) \ | |
5251 | builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \ | |
5252 | NULL, NULL_TREE); \ | |
0ac081f6 AH |
5253 | } while (0) |
5254 | ||
24408032 AH |
5255 | /* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */ |
5256 | ||
2212663f | 5257 | static const struct builtin_description bdesc_3arg[] = |
24408032 AH |
5258 | { |
5259 | { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP }, | |
5260 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS }, | |
5261 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS }, | |
5262 | { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM}, | |
5263 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM }, | |
5264 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM }, | |
5265 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM }, | |
5266 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM }, | |
5267 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS }, | |
5268 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS }, | |
5269 | { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP }, | |
5270 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF }, | |
5271 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI }, | |
5272 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI }, | |
5273 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI }, | |
5274 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF }, | |
5275 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI }, | |
5276 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI }, | |
5277 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI }, | |
5278 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI }, | |
5279 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI }, | |
5280 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI }, | |
5281 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF }, | |
5282 | }; | |
2212663f | 5283 | |
95385cbb AH |
5284 | /* DST operations: void foo (void *, const int, const char). */ |
5285 | ||
5286 | static const struct builtin_description bdesc_dst[] = | |
5287 | { | |
5288 | { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST }, | |
5289 | { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT }, | |
5290 | { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST }, | |
5291 | { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT } | |
5292 | }; | |
5293 | ||
2212663f | 5294 | /* Simple binary operations: VECc = foo (VECa, VECb). */ |
24408032 | 5295 | |
a3170dc6 | 5296 | static struct builtin_description bdesc_2arg[] = |
0ac081f6 | 5297 | { |
f18c054f DB |
5298 | { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM }, |
5299 | { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM }, | |
5300 | { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM }, | |
5301 | { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP }, | |
0ac081f6 AH |
5302 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW }, |
5303 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS }, | |
5304 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS }, | |
5305 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS }, | |
5306 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS }, | |
5307 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS }, | |
5308 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS }, | |
f18c054f | 5309 | { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND }, |
0ac081f6 AH |
5310 | { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC }, |
5311 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB }, | |
5312 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB }, | |
5313 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH }, | |
5314 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH }, | |
5315 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW }, | |
5316 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW }, | |
617e0e1d DB |
5317 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX }, |
5318 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX }, | |
0ac081f6 AH |
5319 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP }, |
5320 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB }, | |
5321 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH }, | |
5322 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW }, | |
5323 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP }, | |
5324 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP }, | |
5325 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB }, | |
5326 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB }, | |
5327 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH }, | |
5328 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH }, | |
5329 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW }, | |
5330 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW }, | |
5331 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP }, | |
617e0e1d DB |
5332 | { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS }, |
5333 | { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS }, | |
f18c054f DB |
5334 | { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB }, |
5335 | { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB }, | |
df966bff AH |
5336 | { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH }, |
5337 | { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH }, | |
5338 | { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW }, | |
5339 | { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW }, | |
5340 | { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP }, | |
0ac081f6 AH |
5341 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB }, |
5342 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH }, | |
5343 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW }, | |
5344 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB }, | |
5345 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH }, | |
5346 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW }, | |
f18c054f DB |
5347 | { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB }, |
5348 | { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB }, | |
5349 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH }, | |
5350 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH }, | |
5351 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW }, | |
5352 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW }, | |
5353 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP }, | |
0ac081f6 AH |
5354 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB }, |
5355 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB }, | |
5356 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH }, | |
5357 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH }, | |
5358 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB }, | |
5359 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB }, | |
5360 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH }, | |
5361 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH }, | |
5362 | { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR }, | |
f18c054f | 5363 | { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR }, |
0ac081f6 AH |
5364 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM }, |
5365 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM }, | |
5366 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX }, | |
5367 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS }, | |
5368 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS }, | |
5369 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS }, | |
5370 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS }, | |
5371 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS }, | |
5372 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS }, | |
5373 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS }, | |
5374 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS }, | |
5375 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB }, | |
5376 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH }, | |
5377 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW }, | |
5378 | { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB }, | |
5379 | { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH }, | |
5380 | { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW }, | |
5381 | { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL }, | |
5382 | { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO }, | |
2212663f DB |
5383 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB }, |
5384 | { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH }, | |
5385 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW }, | |
0ac081f6 | 5386 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB }, |
f18c054f DB |
5387 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH }, |
5388 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW }, | |
0ac081f6 AH |
5389 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB }, |
5390 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH }, | |
5391 | { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW }, | |
5392 | { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR }, | |
5393 | { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO }, | |
f18c054f DB |
5394 | { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM }, |
5395 | { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM }, | |
5396 | { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM }, | |
5397 | { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP }, | |
0ac081f6 AH |
5398 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW }, |
5399 | { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS }, | |
5400 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS }, | |
5401 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS }, | |
5402 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS }, | |
5403 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS }, | |
5404 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS }, | |
5405 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS }, | |
5406 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS }, | |
5407 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS }, | |
5408 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS }, | |
5409 | { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS }, | |
f18c054f | 5410 | { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR }, |
a3170dc6 AH |
5411 | |
5412 | /* Place holder, leave as first spe builtin. */ | |
5413 | { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW }, | |
5414 | { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND }, | |
5415 | { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC }, | |
5416 | { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS }, | |
5417 | { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU }, | |
5418 | { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV }, | |
5419 | { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD }, | |
5420 | { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV }, | |
5421 | { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL }, | |
5422 | { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB }, | |
5423 | { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI }, | |
5424 | { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO }, | |
5425 | { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO }, | |
5426 | { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI }, | |
5427 | { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA }, | |
5428 | { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN }, | |
5429 | { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA }, | |
5430 | { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN }, | |
5431 | { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA }, | |
5432 | { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN }, | |
5433 | { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF }, | |
5434 | { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA }, | |
5435 | { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW }, | |
5436 | { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW }, | |
5437 | { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI }, | |
5438 | { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA }, | |
5439 | { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW }, | |
5440 | { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW }, | |
5441 | { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF }, | |
5442 | { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA }, | |
5443 | { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW }, | |
5444 | { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW }, | |
5445 | { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW }, | |
5446 | { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW }, | |
5447 | { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI }, | |
5448 | { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA }, | |
5449 | { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW }, | |
5450 | { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW }, | |
5451 | { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW }, | |
5452 | { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW }, | |
5453 | { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA }, | |
5454 | { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN }, | |
5455 | { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA }, | |
5456 | { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN }, | |
5457 | { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA }, | |
5458 | { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN }, | |
5459 | { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF }, | |
5460 | { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA }, | |
5461 | { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW }, | |
5462 | { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW }, | |
5463 | { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI }, | |
5464 | { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA }, | |
5465 | { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW }, | |
5466 | { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW }, | |
5467 | { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF }, | |
5468 | { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA }, | |
5469 | { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW }, | |
5470 | { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW }, | |
5471 | { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW }, | |
5472 | { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW }, | |
5473 | { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI }, | |
5474 | { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA }, | |
5475 | { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW }, | |
5476 | { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW }, | |
5477 | { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW }, | |
5478 | { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW }, | |
5479 | { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF }, | |
5480 | { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA }, | |
5481 | { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI }, | |
5482 | { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA }, | |
5483 | { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF }, | |
5484 | { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA }, | |
5485 | { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI }, | |
5486 | { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA }, | |
a3170dc6 AH |
5487 | { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW }, |
5488 | { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW }, | |
a3170dc6 AH |
5489 | { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW }, |
5490 | { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW }, | |
5491 | { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI }, | |
5492 | { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA }, | |
5493 | { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW }, | |
5494 | { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW }, | |
5495 | { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW }, | |
5496 | { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW }, | |
5497 | { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF }, | |
5498 | { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA }, | |
5499 | { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA }, | |
5500 | { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN }, | |
5501 | { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI }, | |
5502 | { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA }, | |
5503 | { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA }, | |
5504 | { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN }, | |
5505 | { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF }, | |
5506 | { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA }, | |
5507 | { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA }, | |
5508 | { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN }, | |
5509 | { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI }, | |
5510 | { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA }, | |
5511 | { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA }, | |
5512 | { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN }, | |
5513 | { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND }, | |
5514 | { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR }, | |
5515 | { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR }, | |
5516 | { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC }, | |
5517 | { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW }, | |
5518 | { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW }, | |
5519 | { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS }, | |
5520 | { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU }, | |
5521 | { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW }, | |
5522 | ||
5523 | /* SPE binary operations expecting a 5-bit unsigned literal. */ | |
5524 | { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW }, | |
5525 | ||
5526 | { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI }, | |
5527 | { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI }, | |
5528 | { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS }, | |
5529 | { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU }, | |
5530 | { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW }, | |
5531 | { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA }, | |
5532 | { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA }, | |
5533 | { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA }, | |
5534 | { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA }, | |
5535 | { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA }, | |
5536 | { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA }, | |
5537 | { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN }, | |
5538 | { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN }, | |
5539 | { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN }, | |
5540 | { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN }, | |
5541 | { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN }, | |
5542 | { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN }, | |
5543 | { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA }, | |
5544 | { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA }, | |
5545 | { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA }, | |
5546 | { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA }, | |
5547 | { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN }, | |
5548 | { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN }, | |
5549 | { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN }, | |
5550 | { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN }, | |
5551 | { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC }, | |
5552 | ||
5553 | /* Place-holder. Leave as last binary SPE builtin. */ | |
17edbda5 | 5554 | { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR }, |
ae4b4a02 AH |
5555 | }; |
5556 | ||
5557 | /* AltiVec predicates. */ | |
5558 | ||
5559 | struct builtin_description_predicates | |
5560 | { | |
5561 | const unsigned int mask; | |
5562 | const enum insn_code icode; | |
5563 | const char *opcode; | |
5564 | const char *const name; | |
5565 | const enum rs6000_builtins code; | |
5566 | }; | |
5567 | ||
5568 | static const struct builtin_description_predicates bdesc_altivec_preds[] = | |
5569 | { | |
5570 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P }, | |
5571 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P }, | |
5572 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P }, | |
5573 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P }, | |
5574 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P }, | |
5575 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P }, | |
5576 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P }, | |
5577 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P }, | |
5578 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P }, | |
5579 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P }, | |
5580 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P }, | |
5581 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P }, | |
5582 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P } | |
0ac081f6 | 5583 | }; |
24408032 | 5584 | |
a3170dc6 AH |
5585 | /* SPE predicates. */ |
5586 | static struct builtin_description bdesc_spe_predicates[] = | |
5587 | { | |
5588 | /* Place-holder. Leave as first. */ | |
5589 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ }, | |
5590 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS }, | |
5591 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU }, | |
5592 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS }, | |
5593 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU }, | |
5594 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ }, | |
5595 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT }, | |
5596 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT }, | |
5597 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ }, | |
5598 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT }, | |
5599 | /* Place-holder. Leave as last. */ | |
5600 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT }, | |
5601 | }; | |
5602 | ||
5603 | /* SPE evsel predicates. */ | |
5604 | static struct builtin_description bdesc_spe_evsel[] = | |
5605 | { | |
5606 | /* Place-holder. Leave as first. */ | |
5607 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS }, | |
5608 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU }, | |
5609 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS }, | |
5610 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU }, | |
5611 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ }, | |
5612 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT }, | |
5613 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT }, | |
5614 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ }, | |
5615 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT }, | |
5616 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT }, | |
5617 | /* Place-holder. Leave as last. */ | |
5618 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ }, | |
5619 | }; | |
5620 | ||
b6d08ca1 | 5621 | /* ABS* operations. */ |
100c4561 AH |
5622 | |
5623 | static const struct builtin_description bdesc_abs[] = | |
5624 | { | |
5625 | { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI }, | |
5626 | { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI }, | |
5627 | { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF }, | |
5628 | { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI }, | |
5629 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI }, | |
5630 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI }, | |
5631 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI } | |
5632 | }; | |
5633 | ||
617e0e1d DB |
5634 | /* Simple unary operations: VECb = foo (unsigned literal) or VECb = |
5635 | foo (VECa). */ | |
24408032 | 5636 | |
a3170dc6 | 5637 | static struct builtin_description bdesc_1arg[] = |
2212663f | 5638 | { |
617e0e1d DB |
5639 | { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP }, |
5640 | { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP }, | |
5641 | { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP }, | |
5642 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM }, | |
5643 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN }, | |
5644 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP }, | |
5645 | { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ }, | |
5646 | { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP }, | |
2212663f DB |
5647 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB }, |
5648 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH }, | |
5649 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW }, | |
20e26713 AH |
5650 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB }, |
5651 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX }, | |
5652 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH }, | |
5653 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB }, | |
5654 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX }, | |
5655 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH }, | |
a3170dc6 AH |
5656 | |
5657 | /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and | |
5658 | end with SPE_BUILTIN_EVSUBFUSIAAW. */ | |
5659 | { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS }, | |
5660 | { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW }, | |
5661 | { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW }, | |
5662 | { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW }, | |
5663 | { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW }, | |
5664 | { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW }, | |
5665 | { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW }, | |
5666 | { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB }, | |
5667 | { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH }, | |
5668 | { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS }, | |
5669 | { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF }, | |
5670 | { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI }, | |
5671 | { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF }, | |
5672 | { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI }, | |
5673 | { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF }, | |
5674 | { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI }, | |
5675 | { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ }, | |
5676 | { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF }, | |
5677 | { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI }, | |
5678 | { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ }, | |
5679 | { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS }, | |
5680 | { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG }, | |
5681 | { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA }, | |
6a599451 | 5682 | { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG }, |
a3170dc6 AH |
5683 | { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW }, |
5684 | { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW }, | |
5685 | { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW }, | |
5686 | { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW }, | |
a3170dc6 AH |
5687 | |
5688 | /* Place-holder. Leave as last unary SPE builtin. */ | |
5689 | { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW }, | |
2212663f DB |
5690 | }; |
5691 | ||
5692 | static rtx | |
a2369ed3 | 5693 | rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
5694 | { |
5695 | rtx pat; | |
5696 | tree arg0 = TREE_VALUE (arglist); | |
5697 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5698 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5699 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5700 | ||
0559cc77 DE |
5701 | if (icode == CODE_FOR_nothing) |
5702 | /* Builtin not supported on this processor. */ | |
5703 | return 0; | |
5704 | ||
20e26713 AH |
5705 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5706 | if (arg0 == error_mark_node) | |
9a171fcd | 5707 | return const0_rtx; |
20e26713 | 5708 | |
0559cc77 DE |
5709 | if (icode == CODE_FOR_altivec_vspltisb |
5710 | || icode == CODE_FOR_altivec_vspltish | |
5711 | || icode == CODE_FOR_altivec_vspltisw | |
5712 | || icode == CODE_FOR_spe_evsplatfi | |
5713 | || icode == CODE_FOR_spe_evsplati) | |
b44140e7 AH |
5714 | { |
5715 | /* Only allow 5-bit *signed* literals. */ | |
b44140e7 AH |
5716 | if (GET_CODE (op0) != CONST_INT |
5717 | || INTVAL (op0) > 0x1f | |
5718 | || INTVAL (op0) < -0x1f) | |
5719 | { | |
5720 | error ("argument 1 must be a 5-bit signed literal"); | |
9a171fcd | 5721 | return const0_rtx; |
b44140e7 | 5722 | } |
b44140e7 AH |
5723 | } |
5724 | ||
c62f2db5 | 5725 | if (target == 0 |
2212663f DB |
5726 | || GET_MODE (target) != tmode |
5727 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5728 | target = gen_reg_rtx (tmode); | |
5729 | ||
5730 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5731 | op0 = copy_to_mode_reg (mode0, op0); | |
5732 | ||
5733 | pat = GEN_FCN (icode) (target, op0); | |
5734 | if (! pat) | |
5735 | return 0; | |
5736 | emit_insn (pat); | |
0ac081f6 | 5737 | |
2212663f DB |
5738 | return target; |
5739 | } | |
ae4b4a02 | 5740 | |
100c4561 | 5741 | static rtx |
a2369ed3 | 5742 | altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target) |
100c4561 AH |
5743 | { |
5744 | rtx pat, scratch1, scratch2; | |
5745 | tree arg0 = TREE_VALUE (arglist); | |
5746 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5747 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5748 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5749 | ||
5750 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
5751 | if (arg0 == error_mark_node) | |
9a171fcd | 5752 | return const0_rtx; |
100c4561 AH |
5753 | |
5754 | if (target == 0 | |
5755 | || GET_MODE (target) != tmode | |
5756 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5757 | target = gen_reg_rtx (tmode); | |
5758 | ||
5759 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5760 | op0 = copy_to_mode_reg (mode0, op0); | |
5761 | ||
5762 | scratch1 = gen_reg_rtx (mode0); | |
5763 | scratch2 = gen_reg_rtx (mode0); | |
5764 | ||
5765 | pat = GEN_FCN (icode) (target, op0, scratch1, scratch2); | |
5766 | if (! pat) | |
5767 | return 0; | |
5768 | emit_insn (pat); | |
5769 | ||
5770 | return target; | |
5771 | } | |
5772 | ||
0ac081f6 | 5773 | static rtx |
a2369ed3 | 5774 | rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target) |
0ac081f6 AH |
5775 | { |
5776 | rtx pat; | |
5777 | tree arg0 = TREE_VALUE (arglist); | |
5778 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5779 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5780 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5781 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5782 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5783 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5784 | ||
0559cc77 DE |
5785 | if (icode == CODE_FOR_nothing) |
5786 | /* Builtin not supported on this processor. */ | |
5787 | return 0; | |
5788 | ||
20e26713 AH |
5789 | /* If we got invalid arguments bail out before generating bad rtl. */ |
5790 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 5791 | return const0_rtx; |
20e26713 | 5792 | |
0559cc77 DE |
5793 | if (icode == CODE_FOR_altivec_vcfux |
5794 | || icode == CODE_FOR_altivec_vcfsx | |
5795 | || icode == CODE_FOR_altivec_vctsxs | |
5796 | || icode == CODE_FOR_altivec_vctuxs | |
5797 | || icode == CODE_FOR_altivec_vspltb | |
5798 | || icode == CODE_FOR_altivec_vsplth | |
5799 | || icode == CODE_FOR_altivec_vspltw | |
5800 | || icode == CODE_FOR_spe_evaddiw | |
5801 | || icode == CODE_FOR_spe_evldd | |
5802 | || icode == CODE_FOR_spe_evldh | |
5803 | || icode == CODE_FOR_spe_evldw | |
5804 | || icode == CODE_FOR_spe_evlhhesplat | |
5805 | || icode == CODE_FOR_spe_evlhhossplat | |
5806 | || icode == CODE_FOR_spe_evlhhousplat | |
5807 | || icode == CODE_FOR_spe_evlwhe | |
5808 | || icode == CODE_FOR_spe_evlwhos | |
5809 | || icode == CODE_FOR_spe_evlwhou | |
5810 | || icode == CODE_FOR_spe_evlwhsplat | |
5811 | || icode == CODE_FOR_spe_evlwwsplat | |
5812 | || icode == CODE_FOR_spe_evrlwi | |
5813 | || icode == CODE_FOR_spe_evslwi | |
5814 | || icode == CODE_FOR_spe_evsrwis | |
f5119d10 | 5815 | || icode == CODE_FOR_spe_evsubifw |
0559cc77 | 5816 | || icode == CODE_FOR_spe_evsrwiu) |
b44140e7 AH |
5817 | { |
5818 | /* Only allow 5-bit unsigned literals. */ | |
8bb418a3 | 5819 | STRIP_NOPS (arg1); |
b44140e7 AH |
5820 | if (TREE_CODE (arg1) != INTEGER_CST |
5821 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
5822 | { | |
5823 | error ("argument 2 must be a 5-bit unsigned literal"); | |
9a171fcd | 5824 | return const0_rtx; |
b44140e7 | 5825 | } |
b44140e7 AH |
5826 | } |
5827 | ||
c62f2db5 | 5828 | if (target == 0 |
0ac081f6 AH |
5829 | || GET_MODE (target) != tmode |
5830 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5831 | target = gen_reg_rtx (tmode); | |
5832 | ||
5833 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5834 | op0 = copy_to_mode_reg (mode0, op0); | |
5835 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5836 | op1 = copy_to_mode_reg (mode1, op1); | |
5837 | ||
5838 | pat = GEN_FCN (icode) (target, op0, op1); | |
5839 | if (! pat) | |
5840 | return 0; | |
5841 | emit_insn (pat); | |
5842 | ||
5843 | return target; | |
5844 | } | |
6525c0e7 | 5845 | |
ae4b4a02 | 5846 | static rtx |
a2369ed3 DJ |
5847 | altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode, |
5848 | tree arglist, rtx target) | |
ae4b4a02 AH |
5849 | { |
5850 | rtx pat, scratch; | |
5851 | tree cr6_form = TREE_VALUE (arglist); | |
5852 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5853 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5854 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5855 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5856 | enum machine_mode tmode = SImode; | |
5857 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
5858 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
5859 | int cr6_form_int; | |
5860 | ||
5861 | if (TREE_CODE (cr6_form) != INTEGER_CST) | |
5862 | { | |
5863 | error ("argument 1 of __builtin_altivec_predicate must be a constant"); | |
9a171fcd | 5864 | return const0_rtx; |
ae4b4a02 AH |
5865 | } |
5866 | else | |
5867 | cr6_form_int = TREE_INT_CST_LOW (cr6_form); | |
5868 | ||
5869 | if (mode0 != mode1) | |
5870 | abort (); | |
5871 | ||
5872 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
5873 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 5874 | return const0_rtx; |
ae4b4a02 AH |
5875 | |
5876 | if (target == 0 | |
5877 | || GET_MODE (target) != tmode | |
5878 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5879 | target = gen_reg_rtx (tmode); | |
5880 | ||
5881 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
5882 | op0 = copy_to_mode_reg (mode0, op0); | |
5883 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
5884 | op1 = copy_to_mode_reg (mode1, op1); | |
5885 | ||
5886 | scratch = gen_reg_rtx (mode0); | |
5887 | ||
5888 | pat = GEN_FCN (icode) (scratch, op0, op1, | |
f1c25d3b | 5889 | gen_rtx_SYMBOL_REF (Pmode, opcode)); |
ae4b4a02 AH |
5890 | if (! pat) |
5891 | return 0; | |
5892 | emit_insn (pat); | |
5893 | ||
5894 | /* The vec_any* and vec_all* predicates use the same opcodes for two | |
5895 | different operations, but the bits in CR6 will be different | |
5896 | depending on what information we want. So we have to play tricks | |
5897 | with CR6 to get the right bits out. | |
5898 | ||
5899 | If you think this is disgusting, look at the specs for the | |
5900 | AltiVec predicates. */ | |
5901 | ||
5902 | switch (cr6_form_int) | |
5903 | { | |
5904 | case 0: | |
5905 | emit_insn (gen_cr6_test_for_zero (target)); | |
5906 | break; | |
5907 | case 1: | |
5908 | emit_insn (gen_cr6_test_for_zero_reverse (target)); | |
5909 | break; | |
5910 | case 2: | |
5911 | emit_insn (gen_cr6_test_for_lt (target)); | |
5912 | break; | |
5913 | case 3: | |
5914 | emit_insn (gen_cr6_test_for_lt_reverse (target)); | |
5915 | break; | |
5916 | default: | |
5917 | error ("argument 1 of __builtin_altivec_predicate is out of range"); | |
5918 | break; | |
5919 | } | |
5920 | ||
5921 | return target; | |
5922 | } | |
5923 | ||
b4a62fa0 | 5924 | static rtx |
38f391a5 | 5925 | altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target) |
b4a62fa0 SB |
5926 | { |
5927 | rtx pat, addr; | |
5928 | tree arg0 = TREE_VALUE (arglist); | |
5929 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5930 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
5931 | enum machine_mode mode0 = Pmode; | |
5932 | enum machine_mode mode1 = Pmode; | |
5933 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5934 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5935 | ||
5936 | if (icode == CODE_FOR_nothing) | |
5937 | /* Builtin not supported on this processor. */ | |
5938 | return 0; | |
5939 | ||
5940 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
5941 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
5942 | return const0_rtx; | |
5943 | ||
5944 | if (target == 0 | |
5945 | || GET_MODE (target) != tmode | |
5946 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
5947 | target = gen_reg_rtx (tmode); | |
5948 | ||
5949 | op1 = copy_to_mode_reg (mode1, op1); | |
5950 | ||
5951 | if (op0 == const0_rtx) | |
5952 | { | |
5953 | addr = gen_rtx_MEM (tmode, op1); | |
5954 | } | |
5955 | else | |
5956 | { | |
5957 | op0 = copy_to_mode_reg (mode0, op0); | |
5958 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1)); | |
5959 | } | |
5960 | ||
5961 | pat = GEN_FCN (icode) (target, addr); | |
5962 | ||
5963 | if (! pat) | |
5964 | return 0; | |
5965 | emit_insn (pat); | |
5966 | ||
5967 | return target; | |
5968 | } | |
5969 | ||
61bea3b0 AH |
5970 | static rtx |
5971 | spe_expand_stv_builtin (enum insn_code icode, tree arglist) | |
5972 | { | |
5973 | tree arg0 = TREE_VALUE (arglist); | |
5974 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
5975 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
5976 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
5977 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
5978 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
5979 | rtx pat; | |
5980 | enum machine_mode mode0 = insn_data[icode].operand[0].mode; | |
5981 | enum machine_mode mode1 = insn_data[icode].operand[1].mode; | |
5982 | enum machine_mode mode2 = insn_data[icode].operand[2].mode; | |
5983 | ||
5984 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
5985 | if (arg0 == error_mark_node | |
5986 | || arg1 == error_mark_node | |
5987 | || arg2 == error_mark_node) | |
5988 | return const0_rtx; | |
5989 | ||
5990 | if (! (*insn_data[icode].operand[2].predicate) (op0, mode2)) | |
5991 | op0 = copy_to_mode_reg (mode2, op0); | |
5992 | if (! (*insn_data[icode].operand[0].predicate) (op1, mode0)) | |
5993 | op1 = copy_to_mode_reg (mode0, op1); | |
5994 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
5995 | op2 = copy_to_mode_reg (mode1, op2); | |
5996 | ||
5997 | pat = GEN_FCN (icode) (op1, op2, op0); | |
5998 | if (pat) | |
5999 | emit_insn (pat); | |
6000 | return NULL_RTX; | |
6001 | } | |
6002 | ||
6525c0e7 | 6003 | static rtx |
a2369ed3 | 6004 | altivec_expand_stv_builtin (enum insn_code icode, tree arglist) |
6525c0e7 AH |
6005 | { |
6006 | tree arg0 = TREE_VALUE (arglist); | |
6007 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6008 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6009 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6010 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6011 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
b4a62fa0 SB |
6012 | rtx pat, addr; |
6013 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6014 | enum machine_mode mode1 = Pmode; | |
6015 | enum machine_mode mode2 = Pmode; | |
6525c0e7 AH |
6016 | |
6017 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
6018 | if (arg0 == error_mark_node | |
6019 | || arg1 == error_mark_node | |
6020 | || arg2 == error_mark_node) | |
9a171fcd | 6021 | return const0_rtx; |
6525c0e7 | 6022 | |
b4a62fa0 SB |
6023 | if (! (*insn_data[icode].operand[1].predicate) (op0, tmode)) |
6024 | op0 = copy_to_mode_reg (tmode, op0); | |
6025 | ||
6026 | op2 = copy_to_mode_reg (mode2, op2); | |
6027 | ||
6028 | if (op1 == const0_rtx) | |
6029 | { | |
6030 | addr = gen_rtx_MEM (tmode, op2); | |
6031 | } | |
6032 | else | |
6033 | { | |
6034 | op1 = copy_to_mode_reg (mode1, op1); | |
6035 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2)); | |
6036 | } | |
6525c0e7 | 6037 | |
b4a62fa0 | 6038 | pat = GEN_FCN (icode) (addr, op0); |
6525c0e7 AH |
6039 | if (pat) |
6040 | emit_insn (pat); | |
6041 | return NULL_RTX; | |
6042 | } | |
6043 | ||
2212663f | 6044 | static rtx |
a2369ed3 | 6045 | rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
6046 | { |
6047 | rtx pat; | |
6048 | tree arg0 = TREE_VALUE (arglist); | |
6049 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6050 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6051 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6052 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6053 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6054 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6055 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6056 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6057 | enum machine_mode mode2 = insn_data[icode].operand[3].mode; | |
0ac081f6 | 6058 | |
774b5662 DE |
6059 | if (icode == CODE_FOR_nothing) |
6060 | /* Builtin not supported on this processor. */ | |
6061 | return 0; | |
6062 | ||
20e26713 AH |
6063 | /* If we got invalid arguments bail out before generating bad rtl. */ |
6064 | if (arg0 == error_mark_node | |
6065 | || arg1 == error_mark_node | |
6066 | || arg2 == error_mark_node) | |
9a171fcd | 6067 | return const0_rtx; |
20e26713 | 6068 | |
774b5662 DE |
6069 | if (icode == CODE_FOR_altivec_vsldoi_4sf |
6070 | || icode == CODE_FOR_altivec_vsldoi_4si | |
6071 | || icode == CODE_FOR_altivec_vsldoi_8hi | |
6072 | || icode == CODE_FOR_altivec_vsldoi_16qi) | |
b44140e7 AH |
6073 | { |
6074 | /* Only allow 4-bit unsigned literals. */ | |
8bb418a3 | 6075 | STRIP_NOPS (arg2); |
b44140e7 AH |
6076 | if (TREE_CODE (arg2) != INTEGER_CST |
6077 | || TREE_INT_CST_LOW (arg2) & ~0xf) | |
6078 | { | |
6079 | error ("argument 3 must be a 4-bit unsigned literal"); | |
e3277ffb | 6080 | return const0_rtx; |
b44140e7 | 6081 | } |
b44140e7 AH |
6082 | } |
6083 | ||
c62f2db5 | 6084 | if (target == 0 |
2212663f DB |
6085 | || GET_MODE (target) != tmode |
6086 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6087 | target = gen_reg_rtx (tmode); | |
6088 | ||
6089 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6090 | op0 = copy_to_mode_reg (mode0, op0); | |
6091 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6092 | op1 = copy_to_mode_reg (mode1, op1); | |
6093 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
6094 | op2 = copy_to_mode_reg (mode2, op2); | |
6095 | ||
6096 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
6097 | if (! pat) | |
6098 | return 0; | |
6099 | emit_insn (pat); | |
6100 | ||
6101 | return target; | |
6102 | } | |
92898235 | 6103 | |
3a9b8c7e | 6104 | /* Expand the lvx builtins. */ |
0ac081f6 | 6105 | static rtx |
a2369ed3 | 6106 | altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp) |
0ac081f6 | 6107 | { |
0ac081f6 AH |
6108 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
6109 | tree arglist = TREE_OPERAND (exp, 1); | |
0ac081f6 | 6110 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
3a9b8c7e AH |
6111 | tree arg0; |
6112 | enum machine_mode tmode, mode0; | |
7c3abc73 | 6113 | rtx pat, op0; |
3a9b8c7e | 6114 | enum insn_code icode; |
92898235 | 6115 | |
0ac081f6 AH |
6116 | switch (fcode) |
6117 | { | |
f18c054f DB |
6118 | case ALTIVEC_BUILTIN_LD_INTERNAL_16qi: |
6119 | icode = CODE_FOR_altivec_lvx_16qi; | |
3a9b8c7e | 6120 | break; |
f18c054f DB |
6121 | case ALTIVEC_BUILTIN_LD_INTERNAL_8hi: |
6122 | icode = CODE_FOR_altivec_lvx_8hi; | |
3a9b8c7e AH |
6123 | break; |
6124 | case ALTIVEC_BUILTIN_LD_INTERNAL_4si: | |
6125 | icode = CODE_FOR_altivec_lvx_4si; | |
6126 | break; | |
6127 | case ALTIVEC_BUILTIN_LD_INTERNAL_4sf: | |
6128 | icode = CODE_FOR_altivec_lvx_4sf; | |
6129 | break; | |
6130 | default: | |
6131 | *expandedp = false; | |
6132 | return NULL_RTX; | |
6133 | } | |
0ac081f6 | 6134 | |
3a9b8c7e | 6135 | *expandedp = true; |
f18c054f | 6136 | |
3a9b8c7e AH |
6137 | arg0 = TREE_VALUE (arglist); |
6138 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6139 | tmode = insn_data[icode].operand[0].mode; | |
6140 | mode0 = insn_data[icode].operand[1].mode; | |
f18c054f | 6141 | |
3a9b8c7e AH |
6142 | if (target == 0 |
6143 | || GET_MODE (target) != tmode | |
6144 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6145 | target = gen_reg_rtx (tmode); | |
24408032 | 6146 | |
3a9b8c7e AH |
6147 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) |
6148 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
f18c054f | 6149 | |
3a9b8c7e AH |
6150 | pat = GEN_FCN (icode) (target, op0); |
6151 | if (! pat) | |
6152 | return 0; | |
6153 | emit_insn (pat); | |
6154 | return target; | |
6155 | } | |
f18c054f | 6156 | |
3a9b8c7e AH |
6157 | /* Expand the stvx builtins. */ |
6158 | static rtx | |
a2369ed3 DJ |
6159 | altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
6160 | bool *expandedp) | |
3a9b8c7e AH |
6161 | { |
6162 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6163 | tree arglist = TREE_OPERAND (exp, 1); | |
6164 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6165 | tree arg0, arg1; | |
6166 | enum machine_mode mode0, mode1; | |
7c3abc73 | 6167 | rtx pat, op0, op1; |
3a9b8c7e | 6168 | enum insn_code icode; |
f18c054f | 6169 | |
3a9b8c7e AH |
6170 | switch (fcode) |
6171 | { | |
6172 | case ALTIVEC_BUILTIN_ST_INTERNAL_16qi: | |
6173 | icode = CODE_FOR_altivec_stvx_16qi; | |
6174 | break; | |
6175 | case ALTIVEC_BUILTIN_ST_INTERNAL_8hi: | |
6176 | icode = CODE_FOR_altivec_stvx_8hi; | |
6177 | break; | |
6178 | case ALTIVEC_BUILTIN_ST_INTERNAL_4si: | |
6179 | icode = CODE_FOR_altivec_stvx_4si; | |
6180 | break; | |
6181 | case ALTIVEC_BUILTIN_ST_INTERNAL_4sf: | |
6182 | icode = CODE_FOR_altivec_stvx_4sf; | |
6183 | break; | |
6184 | default: | |
6185 | *expandedp = false; | |
6186 | return NULL_RTX; | |
6187 | } | |
24408032 | 6188 | |
3a9b8c7e AH |
6189 | arg0 = TREE_VALUE (arglist); |
6190 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6191 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6192 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6193 | mode0 = insn_data[icode].operand[0].mode; | |
6194 | mode1 = insn_data[icode].operand[1].mode; | |
f18c054f | 6195 | |
3a9b8c7e AH |
6196 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
6197 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
6198 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
6199 | op1 = copy_to_mode_reg (mode1, op1); | |
f18c054f | 6200 | |
3a9b8c7e AH |
6201 | pat = GEN_FCN (icode) (op0, op1); |
6202 | if (pat) | |
6203 | emit_insn (pat); | |
f18c054f | 6204 | |
3a9b8c7e AH |
6205 | *expandedp = true; |
6206 | return NULL_RTX; | |
6207 | } | |
f18c054f | 6208 | |
3a9b8c7e AH |
6209 | /* Expand the dst builtins. */ |
6210 | static rtx | |
a2369ed3 DJ |
6211 | altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
6212 | bool *expandedp) | |
3a9b8c7e AH |
6213 | { |
6214 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6215 | tree arglist = TREE_OPERAND (exp, 1); | |
6216 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6217 | tree arg0, arg1, arg2; | |
6218 | enum machine_mode mode0, mode1, mode2; | |
7c3abc73 | 6219 | rtx pat, op0, op1, op2; |
3a9b8c7e | 6220 | struct builtin_description *d; |
a3170dc6 | 6221 | size_t i; |
f18c054f | 6222 | |
3a9b8c7e | 6223 | *expandedp = false; |
f18c054f | 6224 | |
3a9b8c7e AH |
6225 | /* Handle DST variants. */ |
6226 | d = (struct builtin_description *) bdesc_dst; | |
6227 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
6228 | if (d->code == fcode) | |
6229 | { | |
6230 | arg0 = TREE_VALUE (arglist); | |
6231 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6232 | arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6233 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6234 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6235 | op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6236 | mode0 = insn_data[d->icode].operand[0].mode; | |
6237 | mode1 = insn_data[d->icode].operand[1].mode; | |
6238 | mode2 = insn_data[d->icode].operand[2].mode; | |
24408032 | 6239 | |
3a9b8c7e AH |
6240 | /* Invalid arguments, bail out before generating bad rtl. */ |
6241 | if (arg0 == error_mark_node | |
6242 | || arg1 == error_mark_node | |
6243 | || arg2 == error_mark_node) | |
6244 | return const0_rtx; | |
f18c054f | 6245 | |
86e7df90 | 6246 | *expandedp = true; |
8bb418a3 | 6247 | STRIP_NOPS (arg2); |
3a9b8c7e AH |
6248 | if (TREE_CODE (arg2) != INTEGER_CST |
6249 | || TREE_INT_CST_LOW (arg2) & ~0x3) | |
6250 | { | |
6251 | error ("argument to `%s' must be a 2-bit unsigned literal", d->name); | |
6252 | return const0_rtx; | |
6253 | } | |
f18c054f | 6254 | |
3a9b8c7e | 6255 | if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0)) |
b4a62fa0 | 6256 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); |
3a9b8c7e AH |
6257 | if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1)) |
6258 | op1 = copy_to_mode_reg (mode1, op1); | |
24408032 | 6259 | |
3a9b8c7e AH |
6260 | pat = GEN_FCN (d->icode) (op0, op1, op2); |
6261 | if (pat != 0) | |
6262 | emit_insn (pat); | |
f18c054f | 6263 | |
3a9b8c7e AH |
6264 | return NULL_RTX; |
6265 | } | |
f18c054f | 6266 | |
3a9b8c7e AH |
6267 | return NULL_RTX; |
6268 | } | |
24408032 | 6269 | |
3a9b8c7e AH |
6270 | /* Expand the builtin in EXP and store the result in TARGET. Store |
6271 | true in *EXPANDEDP if we found a builtin to expand. */ | |
6272 | static rtx | |
a2369ed3 | 6273 | altivec_expand_builtin (tree exp, rtx target, bool *expandedp) |
3a9b8c7e AH |
6274 | { |
6275 | struct builtin_description *d; | |
6276 | struct builtin_description_predicates *dp; | |
6277 | size_t i; | |
6278 | enum insn_code icode; | |
6279 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6280 | tree arglist = TREE_OPERAND (exp, 1); | |
7c3abc73 AH |
6281 | tree arg0; |
6282 | rtx op0, pat; | |
6283 | enum machine_mode tmode, mode0; | |
3a9b8c7e | 6284 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
0ac081f6 | 6285 | |
3a9b8c7e AH |
6286 | target = altivec_expand_ld_builtin (exp, target, expandedp); |
6287 | if (*expandedp) | |
6288 | return target; | |
0ac081f6 | 6289 | |
3a9b8c7e AH |
6290 | target = altivec_expand_st_builtin (exp, target, expandedp); |
6291 | if (*expandedp) | |
6292 | return target; | |
6293 | ||
6294 | target = altivec_expand_dst_builtin (exp, target, expandedp); | |
6295 | if (*expandedp) | |
6296 | return target; | |
6297 | ||
6298 | *expandedp = true; | |
95385cbb | 6299 | |
3a9b8c7e AH |
6300 | switch (fcode) |
6301 | { | |
6525c0e7 AH |
6302 | case ALTIVEC_BUILTIN_STVX: |
6303 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist); | |
6304 | case ALTIVEC_BUILTIN_STVEBX: | |
6305 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist); | |
6306 | case ALTIVEC_BUILTIN_STVEHX: | |
6307 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist); | |
6308 | case ALTIVEC_BUILTIN_STVEWX: | |
6309 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist); | |
6310 | case ALTIVEC_BUILTIN_STVXL: | |
6311 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist); | |
3a9b8c7e | 6312 | |
95385cbb AH |
6313 | case ALTIVEC_BUILTIN_MFVSCR: |
6314 | icode = CODE_FOR_altivec_mfvscr; | |
6315 | tmode = insn_data[icode].operand[0].mode; | |
6316 | ||
6317 | if (target == 0 | |
6318 | || GET_MODE (target) != tmode | |
6319 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6320 | target = gen_reg_rtx (tmode); | |
6321 | ||
6322 | pat = GEN_FCN (icode) (target); | |
0ac081f6 AH |
6323 | if (! pat) |
6324 | return 0; | |
6325 | emit_insn (pat); | |
95385cbb AH |
6326 | return target; |
6327 | ||
6328 | case ALTIVEC_BUILTIN_MTVSCR: | |
6329 | icode = CODE_FOR_altivec_mtvscr; | |
6330 | arg0 = TREE_VALUE (arglist); | |
6331 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6332 | mode0 = insn_data[icode].operand[0].mode; | |
6333 | ||
6334 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6335 | if (arg0 == error_mark_node) | |
9a171fcd | 6336 | return const0_rtx; |
95385cbb AH |
6337 | |
6338 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
6339 | op0 = copy_to_mode_reg (mode0, op0); | |
6340 | ||
6341 | pat = GEN_FCN (icode) (op0); | |
6342 | if (pat) | |
6343 | emit_insn (pat); | |
6344 | return NULL_RTX; | |
3a9b8c7e | 6345 | |
95385cbb AH |
6346 | case ALTIVEC_BUILTIN_DSSALL: |
6347 | emit_insn (gen_altivec_dssall ()); | |
6348 | return NULL_RTX; | |
6349 | ||
6350 | case ALTIVEC_BUILTIN_DSS: | |
6351 | icode = CODE_FOR_altivec_dss; | |
6352 | arg0 = TREE_VALUE (arglist); | |
8bb418a3 | 6353 | STRIP_NOPS (arg0); |
95385cbb AH |
6354 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); |
6355 | mode0 = insn_data[icode].operand[0].mode; | |
6356 | ||
6357 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6358 | if (arg0 == error_mark_node) | |
9a171fcd | 6359 | return const0_rtx; |
95385cbb | 6360 | |
b44140e7 AH |
6361 | if (TREE_CODE (arg0) != INTEGER_CST |
6362 | || TREE_INT_CST_LOW (arg0) & ~0x3) | |
6363 | { | |
6364 | error ("argument to dss must be a 2-bit unsigned literal"); | |
9a171fcd | 6365 | return const0_rtx; |
b44140e7 AH |
6366 | } |
6367 | ||
95385cbb AH |
6368 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
6369 | op0 = copy_to_mode_reg (mode0, op0); | |
6370 | ||
6371 | emit_insn (gen_altivec_dss (op0)); | |
0ac081f6 | 6372 | return NULL_RTX; |
8bb418a3 ZL |
6373 | |
6374 | case ALTIVEC_BUILTIN_COMPILETIME_ERROR: | |
6375 | arg0 = TREE_VALUE (arglist); | |
6376 | while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR) | |
6377 | arg0 = TREE_OPERAND (arg0, 0); | |
6378 | error ("invalid parameter combination for `%s' AltiVec intrinsic", | |
6379 | TREE_STRING_POINTER (arg0)); | |
6380 | ||
6381 | return const0_rtx; | |
0ac081f6 | 6382 | } |
24408032 | 6383 | |
100c4561 AH |
6384 | /* Expand abs* operations. */ |
6385 | d = (struct builtin_description *) bdesc_abs; | |
ca7558fc | 6386 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) |
100c4561 AH |
6387 | if (d->code == fcode) |
6388 | return altivec_expand_abs_builtin (d->icode, arglist, target); | |
6389 | ||
ae4b4a02 AH |
6390 | /* Expand the AltiVec predicates. */ |
6391 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
ca7558fc | 6392 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) |
ae4b4a02 AH |
6393 | if (dp->code == fcode) |
6394 | return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target); | |
6395 | ||
6525c0e7 AH |
6396 | /* LV* are funky. We initialized them differently. */ |
6397 | switch (fcode) | |
6398 | { | |
6399 | case ALTIVEC_BUILTIN_LVSL: | |
b4a62fa0 | 6400 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl, |
6525c0e7 AH |
6401 | arglist, target); |
6402 | case ALTIVEC_BUILTIN_LVSR: | |
b4a62fa0 | 6403 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr, |
92898235 | 6404 | arglist, target); |
6525c0e7 | 6405 | case ALTIVEC_BUILTIN_LVEBX: |
b4a62fa0 | 6406 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx, |
92898235 | 6407 | arglist, target); |
6525c0e7 | 6408 | case ALTIVEC_BUILTIN_LVEHX: |
b4a62fa0 | 6409 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx, |
92898235 | 6410 | arglist, target); |
6525c0e7 | 6411 | case ALTIVEC_BUILTIN_LVEWX: |
b4a62fa0 | 6412 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx, |
92898235 | 6413 | arglist, target); |
6525c0e7 | 6414 | case ALTIVEC_BUILTIN_LVXL: |
b4a62fa0 | 6415 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl, |
92898235 | 6416 | arglist, target); |
6525c0e7 | 6417 | case ALTIVEC_BUILTIN_LVX: |
b4a62fa0 | 6418 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx, |
92898235 | 6419 | arglist, target); |
6525c0e7 AH |
6420 | default: |
6421 | break; | |
6422 | /* Fall through. */ | |
6423 | } | |
95385cbb | 6424 | |
92898235 | 6425 | *expandedp = false; |
0ac081f6 AH |
6426 | return NULL_RTX; |
6427 | } | |
6428 | ||
a3170dc6 AH |
6429 | /* Binops that need to be initialized manually, but can be expanded |
6430 | automagically by rs6000_expand_binop_builtin. */ | |
6431 | static struct builtin_description bdesc_2arg_spe[] = | |
6432 | { | |
6433 | { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX }, | |
6434 | { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX }, | |
6435 | { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX }, | |
6436 | { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX }, | |
6437 | { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX }, | |
6438 | { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX }, | |
6439 | { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX }, | |
6440 | { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX }, | |
6441 | { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX }, | |
6442 | { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX }, | |
6443 | { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX }, | |
6444 | { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD }, | |
6445 | { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW }, | |
6446 | { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH }, | |
6447 | { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE }, | |
6448 | { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU }, | |
6449 | { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS }, | |
6450 | { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT }, | |
6451 | { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT }, | |
6452 | { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT }, | |
6453 | { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT }, | |
6454 | { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT } | |
6455 | }; | |
6456 | ||
6457 | /* Expand the builtin in EXP and store the result in TARGET. Store | |
6458 | true in *EXPANDEDP if we found a builtin to expand. | |
6459 | ||
6460 | This expands the SPE builtins that are not simple unary and binary | |
6461 | operations. */ | |
6462 | static rtx | |
a2369ed3 | 6463 | spe_expand_builtin (tree exp, rtx target, bool *expandedp) |
a3170dc6 AH |
6464 | { |
6465 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6466 | tree arglist = TREE_OPERAND (exp, 1); | |
6467 | tree arg1, arg0; | |
6468 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6469 | enum insn_code icode; | |
6470 | enum machine_mode tmode, mode0; | |
6471 | rtx pat, op0; | |
6472 | struct builtin_description *d; | |
6473 | size_t i; | |
6474 | ||
6475 | *expandedp = true; | |
6476 | ||
6477 | /* Syntax check for a 5-bit unsigned immediate. */ | |
6478 | switch (fcode) | |
6479 | { | |
6480 | case SPE_BUILTIN_EVSTDD: | |
6481 | case SPE_BUILTIN_EVSTDH: | |
6482 | case SPE_BUILTIN_EVSTDW: | |
6483 | case SPE_BUILTIN_EVSTWHE: | |
6484 | case SPE_BUILTIN_EVSTWHO: | |
6485 | case SPE_BUILTIN_EVSTWWE: | |
6486 | case SPE_BUILTIN_EVSTWWO: | |
6487 | arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6488 | if (TREE_CODE (arg1) != INTEGER_CST | |
6489 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
6490 | { | |
6491 | error ("argument 2 must be a 5-bit unsigned literal"); | |
6492 | return const0_rtx; | |
6493 | } | |
6494 | break; | |
6495 | default: | |
6496 | break; | |
6497 | } | |
6498 | ||
00332c9f AH |
6499 | /* The evsplat*i instructions are not quite generic. */ |
6500 | switch (fcode) | |
6501 | { | |
6502 | case SPE_BUILTIN_EVSPLATFI: | |
6503 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi, | |
6504 | arglist, target); | |
6505 | case SPE_BUILTIN_EVSPLATI: | |
6506 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati, | |
6507 | arglist, target); | |
6508 | default: | |
6509 | break; | |
6510 | } | |
6511 | ||
a3170dc6 AH |
6512 | d = (struct builtin_description *) bdesc_2arg_spe; |
6513 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d) | |
6514 | if (d->code == fcode) | |
6515 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6516 | ||
6517 | d = (struct builtin_description *) bdesc_spe_predicates; | |
6518 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d) | |
6519 | if (d->code == fcode) | |
6520 | return spe_expand_predicate_builtin (d->icode, arglist, target); | |
6521 | ||
6522 | d = (struct builtin_description *) bdesc_spe_evsel; | |
6523 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d) | |
6524 | if (d->code == fcode) | |
6525 | return spe_expand_evsel_builtin (d->icode, arglist, target); | |
6526 | ||
6527 | switch (fcode) | |
6528 | { | |
6529 | case SPE_BUILTIN_EVSTDDX: | |
61bea3b0 | 6530 | return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist); |
a3170dc6 | 6531 | case SPE_BUILTIN_EVSTDHX: |
61bea3b0 | 6532 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist); |
a3170dc6 | 6533 | case SPE_BUILTIN_EVSTDWX: |
61bea3b0 | 6534 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist); |
a3170dc6 | 6535 | case SPE_BUILTIN_EVSTWHEX: |
61bea3b0 | 6536 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist); |
a3170dc6 | 6537 | case SPE_BUILTIN_EVSTWHOX: |
61bea3b0 | 6538 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist); |
a3170dc6 | 6539 | case SPE_BUILTIN_EVSTWWEX: |
61bea3b0 | 6540 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist); |
a3170dc6 | 6541 | case SPE_BUILTIN_EVSTWWOX: |
61bea3b0 | 6542 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist); |
a3170dc6 | 6543 | case SPE_BUILTIN_EVSTDD: |
61bea3b0 | 6544 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist); |
a3170dc6 | 6545 | case SPE_BUILTIN_EVSTDH: |
61bea3b0 | 6546 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist); |
a3170dc6 | 6547 | case SPE_BUILTIN_EVSTDW: |
61bea3b0 | 6548 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist); |
a3170dc6 | 6549 | case SPE_BUILTIN_EVSTWHE: |
61bea3b0 | 6550 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist); |
a3170dc6 | 6551 | case SPE_BUILTIN_EVSTWHO: |
61bea3b0 | 6552 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist); |
a3170dc6 | 6553 | case SPE_BUILTIN_EVSTWWE: |
61bea3b0 | 6554 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist); |
a3170dc6 | 6555 | case SPE_BUILTIN_EVSTWWO: |
61bea3b0 | 6556 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist); |
a3170dc6 AH |
6557 | case SPE_BUILTIN_MFSPEFSCR: |
6558 | icode = CODE_FOR_spe_mfspefscr; | |
6559 | tmode = insn_data[icode].operand[0].mode; | |
6560 | ||
6561 | if (target == 0 | |
6562 | || GET_MODE (target) != tmode | |
6563 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6564 | target = gen_reg_rtx (tmode); | |
6565 | ||
6566 | pat = GEN_FCN (icode) (target); | |
6567 | if (! pat) | |
6568 | return 0; | |
6569 | emit_insn (pat); | |
6570 | return target; | |
6571 | case SPE_BUILTIN_MTSPEFSCR: | |
6572 | icode = CODE_FOR_spe_mtspefscr; | |
6573 | arg0 = TREE_VALUE (arglist); | |
6574 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6575 | mode0 = insn_data[icode].operand[0].mode; | |
6576 | ||
6577 | if (arg0 == error_mark_node) | |
6578 | return const0_rtx; | |
6579 | ||
6580 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
6581 | op0 = copy_to_mode_reg (mode0, op0); | |
6582 | ||
6583 | pat = GEN_FCN (icode) (op0); | |
6584 | if (pat) | |
6585 | emit_insn (pat); | |
6586 | return NULL_RTX; | |
6587 | default: | |
6588 | break; | |
6589 | } | |
6590 | ||
6591 | *expandedp = false; | |
6592 | return NULL_RTX; | |
6593 | } | |
6594 | ||
6595 | static rtx | |
a2369ed3 | 6596 | spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
6597 | { |
6598 | rtx pat, scratch, tmp; | |
6599 | tree form = TREE_VALUE (arglist); | |
6600 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6601 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6602 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6603 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6604 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6605 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6606 | int form_int; | |
6607 | enum rtx_code code; | |
6608 | ||
6609 | if (TREE_CODE (form) != INTEGER_CST) | |
6610 | { | |
6611 | error ("argument 1 of __builtin_spe_predicate must be a constant"); | |
6612 | return const0_rtx; | |
6613 | } | |
6614 | else | |
6615 | form_int = TREE_INT_CST_LOW (form); | |
6616 | ||
6617 | if (mode0 != mode1) | |
6618 | abort (); | |
6619 | ||
6620 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
6621 | return const0_rtx; | |
6622 | ||
6623 | if (target == 0 | |
6624 | || GET_MODE (target) != SImode | |
6625 | || ! (*insn_data[icode].operand[0].predicate) (target, SImode)) | |
6626 | target = gen_reg_rtx (SImode); | |
6627 | ||
6628 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6629 | op0 = copy_to_mode_reg (mode0, op0); | |
6630 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6631 | op1 = copy_to_mode_reg (mode1, op1); | |
6632 | ||
6633 | scratch = gen_reg_rtx (CCmode); | |
6634 | ||
6635 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
6636 | if (! pat) | |
6637 | return const0_rtx; | |
6638 | emit_insn (pat); | |
6639 | ||
6640 | /* There are 4 variants for each predicate: _any_, _all_, _upper_, | |
6641 | _lower_. We use one compare, but look in different bits of the | |
6642 | CR for each variant. | |
6643 | ||
6644 | There are 2 elements in each SPE simd type (upper/lower). The CR | |
6645 | bits are set as follows: | |
6646 | ||
6647 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
6648 | U | L | (U | L) | (U & L) | |
6649 | ||
6650 | So, for an "all" relationship, BIT 3 would be set. | |
6651 | For an "any" relationship, BIT 2 would be set. Etc. | |
6652 | ||
6653 | Following traditional nomenclature, these bits map to: | |
6654 | ||
6655 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
6656 | LT | GT | EQ | OV | |
6657 | ||
6658 | Later, we will generate rtl to look in the LT/EQ/EQ/OV bits. | |
6659 | */ | |
6660 | ||
6661 | switch (form_int) | |
6662 | { | |
6663 | /* All variant. OV bit. */ | |
6664 | case 0: | |
6665 | /* We need to get to the OV bit, which is the ORDERED bit. We | |
6666 | could generate (ordered:SI (reg:CC xx) (const_int 0)), but | |
6667 | that's ugly and will trigger a validate_condition_mode abort. | |
6668 | So let's just use another pattern. */ | |
6669 | emit_insn (gen_move_from_CR_ov_bit (target, scratch)); | |
6670 | return target; | |
6671 | /* Any variant. EQ bit. */ | |
6672 | case 1: | |
6673 | code = EQ; | |
6674 | break; | |
6675 | /* Upper variant. LT bit. */ | |
6676 | case 2: | |
6677 | code = LT; | |
6678 | break; | |
6679 | /* Lower variant. GT bit. */ | |
6680 | case 3: | |
6681 | code = GT; | |
6682 | break; | |
6683 | default: | |
6684 | error ("argument 1 of __builtin_spe_predicate is out of range"); | |
6685 | return const0_rtx; | |
6686 | } | |
6687 | ||
6688 | tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx); | |
6689 | emit_move_insn (target, tmp); | |
6690 | ||
6691 | return target; | |
6692 | } | |
6693 | ||
6694 | /* The evsel builtins look like this: | |
6695 | ||
6696 | e = __builtin_spe_evsel_OP (a, b, c, d); | |
6697 | ||
6698 | and work like this: | |
6699 | ||
6700 | e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper]; | |
6701 | e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower]; | |
6702 | */ | |
6703 | ||
6704 | static rtx | |
a2369ed3 | 6705 | spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
6706 | { |
6707 | rtx pat, scratch; | |
6708 | tree arg0 = TREE_VALUE (arglist); | |
6709 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6710 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6711 | tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist)))); | |
6712 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6713 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6714 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6715 | rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0); | |
6716 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6717 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6718 | ||
6719 | if (mode0 != mode1) | |
6720 | abort (); | |
6721 | ||
6722 | if (arg0 == error_mark_node || arg1 == error_mark_node | |
6723 | || arg2 == error_mark_node || arg3 == error_mark_node) | |
6724 | return const0_rtx; | |
6725 | ||
6726 | if (target == 0 | |
6727 | || GET_MODE (target) != mode0 | |
6728 | || ! (*insn_data[icode].operand[0].predicate) (target, mode0)) | |
6729 | target = gen_reg_rtx (mode0); | |
6730 | ||
6731 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6732 | op0 = copy_to_mode_reg (mode0, op0); | |
6733 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
6734 | op1 = copy_to_mode_reg (mode0, op1); | |
6735 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
6736 | op2 = copy_to_mode_reg (mode0, op2); | |
6737 | if (! (*insn_data[icode].operand[1].predicate) (op3, mode1)) | |
6738 | op3 = copy_to_mode_reg (mode0, op3); | |
6739 | ||
6740 | /* Generate the compare. */ | |
6741 | scratch = gen_reg_rtx (CCmode); | |
6742 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
6743 | if (! pat) | |
6744 | return const0_rtx; | |
6745 | emit_insn (pat); | |
6746 | ||
6747 | if (mode0 == V2SImode) | |
6748 | emit_insn (gen_spe_evsel (target, op2, op3, scratch)); | |
6749 | else | |
6750 | emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch)); | |
6751 | ||
6752 | return target; | |
6753 | } | |
6754 | ||
0ac081f6 AH |
6755 | /* Expand an expression EXP that calls a built-in function, |
6756 | with result going to TARGET if that's convenient | |
6757 | (and in mode MODE if that's convenient). | |
6758 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
6759 | IGNORE is nonzero if the value is to be ignored. */ | |
6760 | ||
6761 | static rtx | |
a2369ed3 DJ |
6762 | rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, |
6763 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
6764 | int ignore ATTRIBUTE_UNUSED) | |
0ac081f6 | 6765 | { |
92898235 AH |
6766 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
6767 | tree arglist = TREE_OPERAND (exp, 1); | |
6768 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6769 | struct builtin_description *d; | |
6770 | size_t i; | |
6771 | rtx ret; | |
6772 | bool success; | |
6773 | ||
0ac081f6 | 6774 | if (TARGET_ALTIVEC) |
92898235 AH |
6775 | { |
6776 | ret = altivec_expand_builtin (exp, target, &success); | |
6777 | ||
a3170dc6 AH |
6778 | if (success) |
6779 | return ret; | |
6780 | } | |
6781 | if (TARGET_SPE) | |
6782 | { | |
6783 | ret = spe_expand_builtin (exp, target, &success); | |
6784 | ||
92898235 AH |
6785 | if (success) |
6786 | return ret; | |
6787 | } | |
6788 | ||
0559cc77 DE |
6789 | if (TARGET_ALTIVEC || TARGET_SPE) |
6790 | { | |
6791 | /* Handle simple unary operations. */ | |
6792 | d = (struct builtin_description *) bdesc_1arg; | |
6793 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) | |
6794 | if (d->code == fcode) | |
6795 | return rs6000_expand_unop_builtin (d->icode, arglist, target); | |
6796 | ||
6797 | /* Handle simple binary operations. */ | |
6798 | d = (struct builtin_description *) bdesc_2arg; | |
6799 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) | |
6800 | if (d->code == fcode) | |
6801 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6802 | ||
6803 | /* Handle simple ternary operations. */ | |
6804 | d = (struct builtin_description *) bdesc_3arg; | |
6805 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) | |
6806 | if (d->code == fcode) | |
6807 | return rs6000_expand_ternop_builtin (d->icode, arglist, target); | |
6808 | } | |
0ac081f6 AH |
6809 | |
6810 | abort (); | |
92898235 | 6811 | return NULL_RTX; |
0ac081f6 AH |
6812 | } |
6813 | ||
7c62e993 PB |
6814 | static tree |
6815 | build_opaque_vector_type (tree node, int nunits) | |
6816 | { | |
6817 | node = copy_node (node); | |
6818 | TYPE_MAIN_VARIANT (node) = node; | |
6819 | return build_vector_type (node, nunits); | |
6820 | } | |
6821 | ||
0ac081f6 | 6822 | static void |
863d938c | 6823 | rs6000_init_builtins (void) |
0ac081f6 | 6824 | { |
4a5eab38 PB |
6825 | V2SI_type_node = build_vector_type (intSI_type_node, 2); |
6826 | V2SF_type_node = build_vector_type (float_type_node, 2); | |
6827 | V4HI_type_node = build_vector_type (intHI_type_node, 4); | |
6828 | V4SI_type_node = build_vector_type (intSI_type_node, 4); | |
6829 | V4SF_type_node = build_vector_type (float_type_node, 4); | |
7e463bda | 6830 | V8HI_type_node = build_vector_type (intHI_type_node, 8); |
4a5eab38 PB |
6831 | V16QI_type_node = build_vector_type (intQI_type_node, 16); |
6832 | ||
6833 | unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16); | |
6834 | unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8); | |
6835 | unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4); | |
6836 | ||
7c62e993 PB |
6837 | opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2); |
6838 | opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2); | |
6035d635 | 6839 | opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node); |
3fdaa45a | 6840 | |
8bb418a3 ZL |
6841 | /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...' |
6842 | types, especially in C++ land. Similarly, 'vector pixel' is distinct from | |
6843 | 'vector unsigned short'. */ | |
6844 | ||
6845 | bool_char_type_node = copy_node (unsigned_intQI_type_node); | |
6846 | TYPE_MAIN_VARIANT (bool_char_type_node) = bool_char_type_node; | |
6847 | bool_short_type_node = copy_node (unsigned_intHI_type_node); | |
6848 | TYPE_MAIN_VARIANT (bool_short_type_node) = bool_short_type_node; | |
6849 | bool_int_type_node = copy_node (unsigned_intSI_type_node); | |
6850 | TYPE_MAIN_VARIANT (bool_int_type_node) = bool_int_type_node; | |
6851 | pixel_type_node = copy_node (unsigned_intHI_type_node); | |
6852 | TYPE_MAIN_VARIANT (pixel_type_node) = pixel_type_node; | |
6853 | ||
6854 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6855 | get_identifier ("__bool char"), | |
6856 | bool_char_type_node)); | |
6857 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6858 | get_identifier ("__bool short"), | |
6859 | bool_short_type_node)); | |
6860 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6861 | get_identifier ("__bool int"), | |
6862 | bool_int_type_node)); | |
6863 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6864 | get_identifier ("__pixel"), | |
6865 | pixel_type_node)); | |
6866 | ||
4a5eab38 PB |
6867 | bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16); |
6868 | bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8); | |
6869 | bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4); | |
6870 | pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8); | |
8bb418a3 ZL |
6871 | |
6872 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6873 | get_identifier ("__vector unsigned char"), | |
6874 | unsigned_V16QI_type_node)); | |
6875 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6876 | get_identifier ("__vector signed char"), | |
6877 | V16QI_type_node)); | |
6878 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6879 | get_identifier ("__vector __bool char"), | |
6880 | bool_V16QI_type_node)); | |
6881 | ||
6882 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6883 | get_identifier ("__vector unsigned short"), | |
6884 | unsigned_V8HI_type_node)); | |
6885 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6886 | get_identifier ("__vector signed short"), | |
6887 | V8HI_type_node)); | |
6888 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6889 | get_identifier ("__vector __bool short"), | |
6890 | bool_V8HI_type_node)); | |
6891 | ||
6892 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6893 | get_identifier ("__vector unsigned int"), | |
6894 | unsigned_V4SI_type_node)); | |
6895 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6896 | get_identifier ("__vector signed int"), | |
6897 | V4SI_type_node)); | |
6898 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6899 | get_identifier ("__vector __bool int"), | |
6900 | bool_V4SI_type_node)); | |
6901 | ||
6902 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6903 | get_identifier ("__vector float"), | |
6904 | V4SF_type_node)); | |
6905 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
6906 | get_identifier ("__vector __pixel"), | |
6907 | pixel_V8HI_type_node)); | |
6908 | ||
a3170dc6 | 6909 | if (TARGET_SPE) |
3fdaa45a | 6910 | spe_init_builtins (); |
0ac081f6 AH |
6911 | if (TARGET_ALTIVEC) |
6912 | altivec_init_builtins (); | |
0559cc77 DE |
6913 | if (TARGET_ALTIVEC || TARGET_SPE) |
6914 | rs6000_common_init_builtins (); | |
0ac081f6 AH |
6915 | } |
6916 | ||
a3170dc6 AH |
6917 | /* Search through a set of builtins and enable the mask bits. |
6918 | DESC is an array of builtins. | |
b6d08ca1 | 6919 | SIZE is the total number of builtins. |
a3170dc6 AH |
6920 | START is the builtin enum at which to start. |
6921 | END is the builtin enum at which to end. */ | |
0ac081f6 | 6922 | static void |
a2369ed3 DJ |
6923 | enable_mask_for_builtins (struct builtin_description *desc, int size, |
6924 | enum rs6000_builtins start, | |
6925 | enum rs6000_builtins end) | |
a3170dc6 AH |
6926 | { |
6927 | int i; | |
6928 | ||
6929 | for (i = 0; i < size; ++i) | |
6930 | if (desc[i].code == start) | |
6931 | break; | |
6932 | ||
6933 | if (i == size) | |
6934 | return; | |
6935 | ||
6936 | for (; i < size; ++i) | |
6937 | { | |
6938 | /* Flip all the bits on. */ | |
6939 | desc[i].mask = target_flags; | |
6940 | if (desc[i].code == end) | |
6941 | break; | |
6942 | } | |
6943 | } | |
6944 | ||
6945 | static void | |
863d938c | 6946 | spe_init_builtins (void) |
0ac081f6 | 6947 | { |
a3170dc6 AH |
6948 | tree endlink = void_list_node; |
6949 | tree puint_type_node = build_pointer_type (unsigned_type_node); | |
6950 | tree pushort_type_node = build_pointer_type (short_unsigned_type_node); | |
ae4b4a02 | 6951 | struct builtin_description *d; |
0ac081f6 AH |
6952 | size_t i; |
6953 | ||
a3170dc6 AH |
6954 | tree v2si_ftype_4_v2si |
6955 | = build_function_type | |
3fdaa45a AH |
6956 | (opaque_V2SI_type_node, |
6957 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
6958 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
6959 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
6960 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
6961 | endlink))))); |
6962 | ||
6963 | tree v2sf_ftype_4_v2sf | |
6964 | = build_function_type | |
3fdaa45a AH |
6965 | (opaque_V2SF_type_node, |
6966 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
6967 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
6968 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
6969 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
6970 | endlink))))); |
6971 | ||
6972 | tree int_ftype_int_v2si_v2si | |
6973 | = build_function_type | |
6974 | (integer_type_node, | |
6975 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
6976 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6977 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
6978 | endlink)))); |
6979 | ||
6980 | tree int_ftype_int_v2sf_v2sf | |
6981 | = build_function_type | |
6982 | (integer_type_node, | |
6983 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
6984 | tree_cons (NULL_TREE, opaque_V2SF_type_node, |
6985 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
6986 | endlink)))); |
6987 | ||
6988 | tree void_ftype_v2si_puint_int | |
6989 | = build_function_type (void_type_node, | |
3fdaa45a | 6990 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
6991 | tree_cons (NULL_TREE, puint_type_node, |
6992 | tree_cons (NULL_TREE, | |
6993 | integer_type_node, | |
6994 | endlink)))); | |
6995 | ||
6996 | tree void_ftype_v2si_puint_char | |
6997 | = build_function_type (void_type_node, | |
3fdaa45a | 6998 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
6999 | tree_cons (NULL_TREE, puint_type_node, |
7000 | tree_cons (NULL_TREE, | |
7001 | char_type_node, | |
7002 | endlink)))); | |
7003 | ||
7004 | tree void_ftype_v2si_pv2si_int | |
7005 | = build_function_type (void_type_node, | |
3fdaa45a | 7006 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 7007 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7008 | tree_cons (NULL_TREE, |
7009 | integer_type_node, | |
7010 | endlink)))); | |
7011 | ||
7012 | tree void_ftype_v2si_pv2si_char | |
7013 | = build_function_type (void_type_node, | |
3fdaa45a | 7014 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 7015 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7016 | tree_cons (NULL_TREE, |
7017 | char_type_node, | |
7018 | endlink)))); | |
7019 | ||
7020 | tree void_ftype_int | |
7021 | = build_function_type (void_type_node, | |
7022 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
7023 | ||
7024 | tree int_ftype_void | |
36e8d515 | 7025 | = build_function_type (integer_type_node, endlink); |
a3170dc6 AH |
7026 | |
7027 | tree v2si_ftype_pv2si_int | |
3fdaa45a | 7028 | = build_function_type (opaque_V2SI_type_node, |
6035d635 | 7029 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7030 | tree_cons (NULL_TREE, integer_type_node, |
7031 | endlink))); | |
7032 | ||
7033 | tree v2si_ftype_puint_int | |
3fdaa45a | 7034 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
7035 | tree_cons (NULL_TREE, puint_type_node, |
7036 | tree_cons (NULL_TREE, integer_type_node, | |
7037 | endlink))); | |
7038 | ||
7039 | tree v2si_ftype_pushort_int | |
3fdaa45a | 7040 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
7041 | tree_cons (NULL_TREE, pushort_type_node, |
7042 | tree_cons (NULL_TREE, integer_type_node, | |
7043 | endlink))); | |
7044 | ||
00332c9f AH |
7045 | tree v2si_ftype_signed_char |
7046 | = build_function_type (opaque_V2SI_type_node, | |
7047 | tree_cons (NULL_TREE, signed_char_type_node, | |
7048 | endlink)); | |
7049 | ||
a3170dc6 AH |
7050 | /* The initialization of the simple binary and unary builtins is |
7051 | done in rs6000_common_init_builtins, but we have to enable the | |
7052 | mask bits here manually because we have run out of `target_flags' | |
7053 | bits. We really need to redesign this mask business. */ | |
7054 | ||
7055 | enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg, | |
7056 | ARRAY_SIZE (bdesc_2arg), | |
7057 | SPE_BUILTIN_EVADDW, | |
7058 | SPE_BUILTIN_EVXOR); | |
7059 | enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg, | |
7060 | ARRAY_SIZE (bdesc_1arg), | |
7061 | SPE_BUILTIN_EVABS, | |
7062 | SPE_BUILTIN_EVSUBFUSIAAW); | |
7063 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates, | |
7064 | ARRAY_SIZE (bdesc_spe_predicates), | |
7065 | SPE_BUILTIN_EVCMPEQ, | |
7066 | SPE_BUILTIN_EVFSTSTLT); | |
7067 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel, | |
7068 | ARRAY_SIZE (bdesc_spe_evsel), | |
7069 | SPE_BUILTIN_EVSEL_CMPGTS, | |
7070 | SPE_BUILTIN_EVSEL_FSTSTEQ); | |
7071 | ||
36252949 AH |
7072 | (*lang_hooks.decls.pushdecl) |
7073 | (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"), | |
7074 | opaque_V2SI_type_node)); | |
7075 | ||
a3170dc6 AH |
7076 | /* Initialize irregular SPE builtins. */ |
7077 | ||
7078 | def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR); | |
7079 | def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR); | |
7080 | def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX); | |
7081 | def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX); | |
7082 | def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX); | |
7083 | def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX); | |
7084 | def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX); | |
7085 | def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX); | |
7086 | def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX); | |
7087 | def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD); | |
7088 | def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH); | |
7089 | def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW); | |
7090 | def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE); | |
7091 | def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO); | |
7092 | def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE); | |
7093 | def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO); | |
00332c9f AH |
7094 | def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI); |
7095 | def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI); | |
a3170dc6 AH |
7096 | |
7097 | /* Loads. */ | |
7098 | def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX); | |
7099 | def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX); | |
7100 | def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX); | |
7101 | def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX); | |
7102 | def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX); | |
7103 | def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX); | |
7104 | def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX); | |
7105 | def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX); | |
7106 | def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX); | |
7107 | def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX); | |
7108 | def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX); | |
7109 | def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD); | |
7110 | def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW); | |
7111 | def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH); | |
7112 | def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT); | |
7113 | def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT); | |
7114 | def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT); | |
7115 | def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE); | |
7116 | def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS); | |
7117 | def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU); | |
7118 | def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT); | |
7119 | def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT); | |
7120 | ||
7121 | /* Predicates. */ | |
7122 | d = (struct builtin_description *) bdesc_spe_predicates; | |
7123 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++) | |
7124 | { | |
7125 | tree type; | |
7126 | ||
7127 | switch (insn_data[d->icode].operand[1].mode) | |
7128 | { | |
7129 | case V2SImode: | |
7130 | type = int_ftype_int_v2si_v2si; | |
7131 | break; | |
7132 | case V2SFmode: | |
7133 | type = int_ftype_int_v2sf_v2sf; | |
7134 | break; | |
7135 | default: | |
7136 | abort (); | |
7137 | } | |
7138 | ||
7139 | def_builtin (d->mask, d->name, type, d->code); | |
7140 | } | |
7141 | ||
7142 | /* Evsel predicates. */ | |
7143 | d = (struct builtin_description *) bdesc_spe_evsel; | |
7144 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++) | |
7145 | { | |
7146 | tree type; | |
7147 | ||
7148 | switch (insn_data[d->icode].operand[1].mode) | |
7149 | { | |
7150 | case V2SImode: | |
7151 | type = v2si_ftype_4_v2si; | |
7152 | break; | |
7153 | case V2SFmode: | |
7154 | type = v2sf_ftype_4_v2sf; | |
7155 | break; | |
7156 | default: | |
7157 | abort (); | |
7158 | } | |
7159 | ||
7160 | def_builtin (d->mask, d->name, type, d->code); | |
7161 | } | |
7162 | } | |
7163 | ||
7164 | static void | |
863d938c | 7165 | altivec_init_builtins (void) |
a3170dc6 AH |
7166 | { |
7167 | struct builtin_description *d; | |
7168 | struct builtin_description_predicates *dp; | |
7169 | size_t i; | |
7170 | tree pfloat_type_node = build_pointer_type (float_type_node); | |
7171 | tree pint_type_node = build_pointer_type (integer_type_node); | |
7172 | tree pshort_type_node = build_pointer_type (short_integer_type_node); | |
7173 | tree pchar_type_node = build_pointer_type (char_type_node); | |
7174 | ||
7175 | tree pvoid_type_node = build_pointer_type (void_type_node); | |
7176 | ||
0dbc3651 ZW |
7177 | tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST)); |
7178 | tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST)); | |
7179 | tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST)); | |
7180 | tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); | |
7181 | ||
7182 | tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST)); | |
7183 | ||
a3170dc6 AH |
7184 | tree int_ftype_int_v4si_v4si |
7185 | = build_function_type_list (integer_type_node, | |
7186 | integer_type_node, V4SI_type_node, | |
7187 | V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7188 | tree v4sf_ftype_pcfloat |
7189 | = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE); | |
a3170dc6 | 7190 | tree void_ftype_pfloat_v4sf |
b4de2f7d | 7191 | = build_function_type_list (void_type_node, |
a3170dc6 | 7192 | pfloat_type_node, V4SF_type_node, NULL_TREE); |
0dbc3651 ZW |
7193 | tree v4si_ftype_pcint |
7194 | = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE); | |
7195 | tree void_ftype_pint_v4si | |
b4de2f7d AH |
7196 | = build_function_type_list (void_type_node, |
7197 | pint_type_node, V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7198 | tree v8hi_ftype_pcshort |
7199 | = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE); | |
f18c054f | 7200 | tree void_ftype_pshort_v8hi |
b4de2f7d AH |
7201 | = build_function_type_list (void_type_node, |
7202 | pshort_type_node, V8HI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7203 | tree v16qi_ftype_pcchar |
7204 | = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE); | |
f18c054f | 7205 | tree void_ftype_pchar_v16qi |
b4de2f7d AH |
7206 | = build_function_type_list (void_type_node, |
7207 | pchar_type_node, V16QI_type_node, NULL_TREE); | |
95385cbb | 7208 | tree void_ftype_v4si |
b4de2f7d | 7209 | = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE); |
a3170dc6 AH |
7210 | tree v8hi_ftype_void |
7211 | = build_function_type (V8HI_type_node, void_list_node); | |
7212 | tree void_ftype_void | |
7213 | = build_function_type (void_type_node, void_list_node); | |
7214 | tree void_ftype_qi | |
7215 | = build_function_type_list (void_type_node, char_type_node, NULL_TREE); | |
0dbc3651 | 7216 | |
b4a62fa0 | 7217 | tree v16qi_ftype_long_pcvoid |
a3170dc6 | 7218 | = build_function_type_list (V16QI_type_node, |
b4a62fa0 SB |
7219 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
7220 | tree v8hi_ftype_long_pcvoid | |
a3170dc6 | 7221 | = build_function_type_list (V8HI_type_node, |
b4a62fa0 SB |
7222 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
7223 | tree v4si_ftype_long_pcvoid | |
a3170dc6 | 7224 | = build_function_type_list (V4SI_type_node, |
b4a62fa0 | 7225 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
0dbc3651 | 7226 | |
b4a62fa0 | 7227 | tree void_ftype_v4si_long_pvoid |
b4de2f7d | 7228 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7229 | V4SI_type_node, long_integer_type_node, |
b4de2f7d | 7230 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 7231 | tree void_ftype_v16qi_long_pvoid |
b4de2f7d | 7232 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7233 | V16QI_type_node, long_integer_type_node, |
b4de2f7d | 7234 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 7235 | tree void_ftype_v8hi_long_pvoid |
b4de2f7d | 7236 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7237 | V8HI_type_node, long_integer_type_node, |
b4de2f7d | 7238 | pvoid_type_node, NULL_TREE); |
a3170dc6 AH |
7239 | tree int_ftype_int_v8hi_v8hi |
7240 | = build_function_type_list (integer_type_node, | |
7241 | integer_type_node, V8HI_type_node, | |
7242 | V8HI_type_node, NULL_TREE); | |
7243 | tree int_ftype_int_v16qi_v16qi | |
7244 | = build_function_type_list (integer_type_node, | |
7245 | integer_type_node, V16QI_type_node, | |
7246 | V16QI_type_node, NULL_TREE); | |
7247 | tree int_ftype_int_v4sf_v4sf | |
7248 | = build_function_type_list (integer_type_node, | |
7249 | integer_type_node, V4SF_type_node, | |
7250 | V4SF_type_node, NULL_TREE); | |
7251 | tree v4si_ftype_v4si | |
7252 | = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE); | |
7253 | tree v8hi_ftype_v8hi | |
7254 | = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE); | |
7255 | tree v16qi_ftype_v16qi | |
7256 | = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE); | |
7257 | tree v4sf_ftype_v4sf | |
7258 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
8bb418a3 | 7259 | tree void_ftype_pcvoid_int_int |
a3170dc6 | 7260 | = build_function_type_list (void_type_node, |
0dbc3651 | 7261 | pcvoid_type_node, integer_type_node, |
8bb418a3 ZL |
7262 | integer_type_node, NULL_TREE); |
7263 | tree int_ftype_pcchar | |
7264 | = build_function_type_list (integer_type_node, | |
7265 | pcchar_type_node, NULL_TREE); | |
7266 | ||
0dbc3651 ZW |
7267 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat, |
7268 | ALTIVEC_BUILTIN_LD_INTERNAL_4sf); | |
7269 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, | |
7270 | ALTIVEC_BUILTIN_ST_INTERNAL_4sf); | |
7271 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint, | |
7272 | ALTIVEC_BUILTIN_LD_INTERNAL_4si); | |
7273 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, | |
7274 | ALTIVEC_BUILTIN_ST_INTERNAL_4si); | |
7275 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort, | |
7276 | ALTIVEC_BUILTIN_LD_INTERNAL_8hi); | |
7277 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, | |
7278 | ALTIVEC_BUILTIN_ST_INTERNAL_8hi); | |
7279 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar, | |
7280 | ALTIVEC_BUILTIN_LD_INTERNAL_16qi); | |
7281 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, | |
7282 | ALTIVEC_BUILTIN_ST_INTERNAL_16qi); | |
a3170dc6 AH |
7283 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR); |
7284 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR); | |
7285 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL); | |
7286 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS); | |
b4a62fa0 SB |
7287 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL); |
7288 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR); | |
7289 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX); | |
7290 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX); | |
7291 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX); | |
7292 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL); | |
7293 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX); | |
7294 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX); | |
7295 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX); | |
7296 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL); | |
7297 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX); | |
7298 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX); | |
a3170dc6 | 7299 | |
8bb418a3 ZL |
7300 | /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */ |
7301 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar, | |
7302 | ALTIVEC_BUILTIN_COMPILETIME_ERROR); | |
7303 | ||
a3170dc6 AH |
7304 | /* Add the DST variants. */ |
7305 | d = (struct builtin_description *) bdesc_dst; | |
7306 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
8bb418a3 | 7307 | def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code); |
a3170dc6 AH |
7308 | |
7309 | /* Initialize the predicates. */ | |
7310 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
7311 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) | |
7312 | { | |
7313 | enum machine_mode mode1; | |
7314 | tree type; | |
7315 | ||
7316 | mode1 = insn_data[dp->icode].operand[1].mode; | |
7317 | ||
7318 | switch (mode1) | |
7319 | { | |
7320 | case V4SImode: | |
7321 | type = int_ftype_int_v4si_v4si; | |
7322 | break; | |
7323 | case V8HImode: | |
7324 | type = int_ftype_int_v8hi_v8hi; | |
7325 | break; | |
7326 | case V16QImode: | |
7327 | type = int_ftype_int_v16qi_v16qi; | |
7328 | break; | |
7329 | case V4SFmode: | |
7330 | type = int_ftype_int_v4sf_v4sf; | |
7331 | break; | |
7332 | default: | |
7333 | abort (); | |
7334 | } | |
7335 | ||
7336 | def_builtin (dp->mask, dp->name, type, dp->code); | |
7337 | } | |
7338 | ||
7339 | /* Initialize the abs* operators. */ | |
7340 | d = (struct builtin_description *) bdesc_abs; | |
7341 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) | |
7342 | { | |
7343 | enum machine_mode mode0; | |
7344 | tree type; | |
7345 | ||
7346 | mode0 = insn_data[d->icode].operand[0].mode; | |
7347 | ||
7348 | switch (mode0) | |
7349 | { | |
7350 | case V4SImode: | |
7351 | type = v4si_ftype_v4si; | |
7352 | break; | |
7353 | case V8HImode: | |
7354 | type = v8hi_ftype_v8hi; | |
7355 | break; | |
7356 | case V16QImode: | |
7357 | type = v16qi_ftype_v16qi; | |
7358 | break; | |
7359 | case V4SFmode: | |
7360 | type = v4sf_ftype_v4sf; | |
7361 | break; | |
7362 | default: | |
7363 | abort (); | |
7364 | } | |
7365 | ||
7366 | def_builtin (d->mask, d->name, type, d->code); | |
7367 | } | |
7368 | } | |
7369 | ||
7370 | static void | |
863d938c | 7371 | rs6000_common_init_builtins (void) |
a3170dc6 AH |
7372 | { |
7373 | struct builtin_description *d; | |
7374 | size_t i; | |
7375 | ||
7376 | tree v4sf_ftype_v4sf_v4sf_v16qi | |
7377 | = build_function_type_list (V4SF_type_node, | |
7378 | V4SF_type_node, V4SF_type_node, | |
7379 | V16QI_type_node, NULL_TREE); | |
7380 | tree v4si_ftype_v4si_v4si_v16qi | |
7381 | = build_function_type_list (V4SI_type_node, | |
7382 | V4SI_type_node, V4SI_type_node, | |
7383 | V16QI_type_node, NULL_TREE); | |
7384 | tree v8hi_ftype_v8hi_v8hi_v16qi | |
7385 | = build_function_type_list (V8HI_type_node, | |
7386 | V8HI_type_node, V8HI_type_node, | |
7387 | V16QI_type_node, NULL_TREE); | |
7388 | tree v16qi_ftype_v16qi_v16qi_v16qi | |
7389 | = build_function_type_list (V16QI_type_node, | |
7390 | V16QI_type_node, V16QI_type_node, | |
7391 | V16QI_type_node, NULL_TREE); | |
b9e4e5d1 ZL |
7392 | tree v4si_ftype_int |
7393 | = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE); | |
7394 | tree v8hi_ftype_int | |
7395 | = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE); | |
7396 | tree v16qi_ftype_int | |
7397 | = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE); | |
a3170dc6 AH |
7398 | tree v8hi_ftype_v16qi |
7399 | = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE); | |
7400 | tree v4sf_ftype_v4sf | |
7401 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
7402 | ||
7403 | tree v2si_ftype_v2si_v2si | |
2abe3e28 AH |
7404 | = build_function_type_list (opaque_V2SI_type_node, |
7405 | opaque_V2SI_type_node, | |
7406 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7407 | |
7408 | tree v2sf_ftype_v2sf_v2sf | |
2abe3e28 AH |
7409 | = build_function_type_list (opaque_V2SF_type_node, |
7410 | opaque_V2SF_type_node, | |
7411 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7412 | |
7413 | tree v2si_ftype_int_int | |
2abe3e28 | 7414 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
7415 | integer_type_node, integer_type_node, |
7416 | NULL_TREE); | |
7417 | ||
7418 | tree v2si_ftype_v2si | |
2abe3e28 AH |
7419 | = build_function_type_list (opaque_V2SI_type_node, |
7420 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7421 | |
7422 | tree v2sf_ftype_v2sf | |
2abe3e28 AH |
7423 | = build_function_type_list (opaque_V2SF_type_node, |
7424 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7425 | |
7426 | tree v2sf_ftype_v2si | |
2abe3e28 AH |
7427 | = build_function_type_list (opaque_V2SF_type_node, |
7428 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7429 | |
7430 | tree v2si_ftype_v2sf | |
2abe3e28 AH |
7431 | = build_function_type_list (opaque_V2SI_type_node, |
7432 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7433 | |
7434 | tree v2si_ftype_v2si_char | |
2abe3e28 AH |
7435 | = build_function_type_list (opaque_V2SI_type_node, |
7436 | opaque_V2SI_type_node, | |
7437 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
7438 | |
7439 | tree v2si_ftype_int_char | |
2abe3e28 | 7440 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
7441 | integer_type_node, char_type_node, NULL_TREE); |
7442 | ||
7443 | tree v2si_ftype_char | |
2abe3e28 AH |
7444 | = build_function_type_list (opaque_V2SI_type_node, |
7445 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
7446 | |
7447 | tree int_ftype_int_int | |
7448 | = build_function_type_list (integer_type_node, | |
7449 | integer_type_node, integer_type_node, | |
7450 | NULL_TREE); | |
95385cbb | 7451 | |
0ac081f6 | 7452 | tree v4si_ftype_v4si_v4si |
b4de2f7d AH |
7453 | = build_function_type_list (V4SI_type_node, |
7454 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
b9e4e5d1 | 7455 | tree v4sf_ftype_v4si_int |
b4de2f7d | 7456 | = build_function_type_list (V4SF_type_node, |
b9e4e5d1 ZL |
7457 | V4SI_type_node, integer_type_node, NULL_TREE); |
7458 | tree v4si_ftype_v4sf_int | |
b4de2f7d | 7459 | = build_function_type_list (V4SI_type_node, |
b9e4e5d1 ZL |
7460 | V4SF_type_node, integer_type_node, NULL_TREE); |
7461 | tree v4si_ftype_v4si_int | |
b4de2f7d | 7462 | = build_function_type_list (V4SI_type_node, |
b9e4e5d1 ZL |
7463 | V4SI_type_node, integer_type_node, NULL_TREE); |
7464 | tree v8hi_ftype_v8hi_int | |
b4de2f7d | 7465 | = build_function_type_list (V8HI_type_node, |
b9e4e5d1 ZL |
7466 | V8HI_type_node, integer_type_node, NULL_TREE); |
7467 | tree v16qi_ftype_v16qi_int | |
b4de2f7d | 7468 | = build_function_type_list (V16QI_type_node, |
b9e4e5d1 ZL |
7469 | V16QI_type_node, integer_type_node, NULL_TREE); |
7470 | tree v16qi_ftype_v16qi_v16qi_int | |
b4de2f7d AH |
7471 | = build_function_type_list (V16QI_type_node, |
7472 | V16QI_type_node, V16QI_type_node, | |
b9e4e5d1 ZL |
7473 | integer_type_node, NULL_TREE); |
7474 | tree v8hi_ftype_v8hi_v8hi_int | |
b4de2f7d AH |
7475 | = build_function_type_list (V8HI_type_node, |
7476 | V8HI_type_node, V8HI_type_node, | |
b9e4e5d1 ZL |
7477 | integer_type_node, NULL_TREE); |
7478 | tree v4si_ftype_v4si_v4si_int | |
b4de2f7d AH |
7479 | = build_function_type_list (V4SI_type_node, |
7480 | V4SI_type_node, V4SI_type_node, | |
b9e4e5d1 ZL |
7481 | integer_type_node, NULL_TREE); |
7482 | tree v4sf_ftype_v4sf_v4sf_int | |
b4de2f7d AH |
7483 | = build_function_type_list (V4SF_type_node, |
7484 | V4SF_type_node, V4SF_type_node, | |
b9e4e5d1 | 7485 | integer_type_node, NULL_TREE); |
0ac081f6 | 7486 | tree v4sf_ftype_v4sf_v4sf |
b4de2f7d AH |
7487 | = build_function_type_list (V4SF_type_node, |
7488 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
617e0e1d | 7489 | tree v4sf_ftype_v4sf_v4sf_v4si |
b4de2f7d AH |
7490 | = build_function_type_list (V4SF_type_node, |
7491 | V4SF_type_node, V4SF_type_node, | |
7492 | V4SI_type_node, NULL_TREE); | |
2212663f | 7493 | tree v4sf_ftype_v4sf_v4sf_v4sf |
b4de2f7d AH |
7494 | = build_function_type_list (V4SF_type_node, |
7495 | V4SF_type_node, V4SF_type_node, | |
7496 | V4SF_type_node, NULL_TREE); | |
617e0e1d | 7497 | tree v4si_ftype_v4si_v4si_v4si |
b4de2f7d AH |
7498 | = build_function_type_list (V4SI_type_node, |
7499 | V4SI_type_node, V4SI_type_node, | |
7500 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 7501 | tree v8hi_ftype_v8hi_v8hi |
b4de2f7d AH |
7502 | = build_function_type_list (V8HI_type_node, |
7503 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
2212663f | 7504 | tree v8hi_ftype_v8hi_v8hi_v8hi |
b4de2f7d AH |
7505 | = build_function_type_list (V8HI_type_node, |
7506 | V8HI_type_node, V8HI_type_node, | |
7507 | V8HI_type_node, NULL_TREE); | |
2212663f | 7508 | tree v4si_ftype_v8hi_v8hi_v4si |
b4de2f7d AH |
7509 | = build_function_type_list (V4SI_type_node, |
7510 | V8HI_type_node, V8HI_type_node, | |
7511 | V4SI_type_node, NULL_TREE); | |
2212663f | 7512 | tree v4si_ftype_v16qi_v16qi_v4si |
b4de2f7d AH |
7513 | = build_function_type_list (V4SI_type_node, |
7514 | V16QI_type_node, V16QI_type_node, | |
7515 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 7516 | tree v16qi_ftype_v16qi_v16qi |
b4de2f7d AH |
7517 | = build_function_type_list (V16QI_type_node, |
7518 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7519 | tree v4si_ftype_v4sf_v4sf |
b4de2f7d AH |
7520 | = build_function_type_list (V4SI_type_node, |
7521 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0ac081f6 | 7522 | tree v8hi_ftype_v16qi_v16qi |
b4de2f7d AH |
7523 | = build_function_type_list (V8HI_type_node, |
7524 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7525 | tree v4si_ftype_v8hi_v8hi |
b4de2f7d AH |
7526 | = build_function_type_list (V4SI_type_node, |
7527 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7528 | tree v8hi_ftype_v4si_v4si |
b4de2f7d AH |
7529 | = build_function_type_list (V8HI_type_node, |
7530 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
0ac081f6 | 7531 | tree v16qi_ftype_v8hi_v8hi |
b4de2f7d AH |
7532 | = build_function_type_list (V16QI_type_node, |
7533 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7534 | tree v4si_ftype_v16qi_v4si |
b4de2f7d AH |
7535 | = build_function_type_list (V4SI_type_node, |
7536 | V16QI_type_node, V4SI_type_node, NULL_TREE); | |
fa066a23 | 7537 | tree v4si_ftype_v16qi_v16qi |
b4de2f7d AH |
7538 | = build_function_type_list (V4SI_type_node, |
7539 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7540 | tree v4si_ftype_v8hi_v4si |
b4de2f7d AH |
7541 | = build_function_type_list (V4SI_type_node, |
7542 | V8HI_type_node, V4SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7543 | tree v4si_ftype_v8hi |
7544 | = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE); | |
7545 | tree int_ftype_v4si_v4si | |
7546 | = build_function_type_list (integer_type_node, | |
7547 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
7548 | tree int_ftype_v4sf_v4sf | |
7549 | = build_function_type_list (integer_type_node, | |
7550 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
7551 | tree int_ftype_v16qi_v16qi | |
7552 | = build_function_type_list (integer_type_node, | |
7553 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 7554 | tree int_ftype_v8hi_v8hi |
b4de2f7d AH |
7555 | = build_function_type_list (integer_type_node, |
7556 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 7557 | |
6f317ef3 | 7558 | /* Add the simple ternary operators. */ |
2212663f | 7559 | d = (struct builtin_description *) bdesc_3arg; |
ca7558fc | 7560 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) |
2212663f DB |
7561 | { |
7562 | ||
7563 | enum machine_mode mode0, mode1, mode2, mode3; | |
7564 | tree type; | |
7565 | ||
0559cc77 | 7566 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
7567 | continue; |
7568 | ||
7569 | mode0 = insn_data[d->icode].operand[0].mode; | |
7570 | mode1 = insn_data[d->icode].operand[1].mode; | |
7571 | mode2 = insn_data[d->icode].operand[2].mode; | |
7572 | mode3 = insn_data[d->icode].operand[3].mode; | |
7573 | ||
7574 | /* When all four are of the same mode. */ | |
7575 | if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3) | |
7576 | { | |
7577 | switch (mode0) | |
7578 | { | |
617e0e1d DB |
7579 | case V4SImode: |
7580 | type = v4si_ftype_v4si_v4si_v4si; | |
7581 | break; | |
2212663f DB |
7582 | case V4SFmode: |
7583 | type = v4sf_ftype_v4sf_v4sf_v4sf; | |
7584 | break; | |
7585 | case V8HImode: | |
7586 | type = v8hi_ftype_v8hi_v8hi_v8hi; | |
7587 | break; | |
7588 | case V16QImode: | |
7589 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
7590 | break; | |
7591 | default: | |
7592 | abort(); | |
7593 | } | |
7594 | } | |
7595 | else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode) | |
7596 | { | |
7597 | switch (mode0) | |
7598 | { | |
7599 | case V4SImode: | |
7600 | type = v4si_ftype_v4si_v4si_v16qi; | |
7601 | break; | |
7602 | case V4SFmode: | |
7603 | type = v4sf_ftype_v4sf_v4sf_v16qi; | |
7604 | break; | |
7605 | case V8HImode: | |
7606 | type = v8hi_ftype_v8hi_v8hi_v16qi; | |
7607 | break; | |
7608 | case V16QImode: | |
7609 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
7610 | break; | |
7611 | default: | |
7612 | abort(); | |
7613 | } | |
7614 | } | |
7615 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode | |
7616 | && mode3 == V4SImode) | |
24408032 | 7617 | type = v4si_ftype_v16qi_v16qi_v4si; |
2212663f DB |
7618 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode |
7619 | && mode3 == V4SImode) | |
24408032 | 7620 | type = v4si_ftype_v8hi_v8hi_v4si; |
617e0e1d DB |
7621 | else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode |
7622 | && mode3 == V4SImode) | |
24408032 AH |
7623 | type = v4sf_ftype_v4sf_v4sf_v4si; |
7624 | ||
7625 | /* vchar, vchar, vchar, 4 bit literal. */ | |
7626 | else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0 | |
7627 | && mode3 == QImode) | |
b9e4e5d1 | 7628 | type = v16qi_ftype_v16qi_v16qi_int; |
24408032 AH |
7629 | |
7630 | /* vshort, vshort, vshort, 4 bit literal. */ | |
7631 | else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0 | |
7632 | && mode3 == QImode) | |
b9e4e5d1 | 7633 | type = v8hi_ftype_v8hi_v8hi_int; |
24408032 AH |
7634 | |
7635 | /* vint, vint, vint, 4 bit literal. */ | |
7636 | else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0 | |
7637 | && mode3 == QImode) | |
b9e4e5d1 | 7638 | type = v4si_ftype_v4si_v4si_int; |
24408032 AH |
7639 | |
7640 | /* vfloat, vfloat, vfloat, 4 bit literal. */ | |
7641 | else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0 | |
7642 | && mode3 == QImode) | |
b9e4e5d1 | 7643 | type = v4sf_ftype_v4sf_v4sf_int; |
24408032 | 7644 | |
2212663f DB |
7645 | else |
7646 | abort (); | |
7647 | ||
7648 | def_builtin (d->mask, d->name, type, d->code); | |
7649 | } | |
7650 | ||
0ac081f6 | 7651 | /* Add the simple binary operators. */ |
00b960c7 | 7652 | d = (struct builtin_description *) bdesc_2arg; |
ca7558fc | 7653 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
0ac081f6 AH |
7654 | { |
7655 | enum machine_mode mode0, mode1, mode2; | |
7656 | tree type; | |
7657 | ||
0559cc77 | 7658 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
0ac081f6 AH |
7659 | continue; |
7660 | ||
7661 | mode0 = insn_data[d->icode].operand[0].mode; | |
7662 | mode1 = insn_data[d->icode].operand[1].mode; | |
7663 | mode2 = insn_data[d->icode].operand[2].mode; | |
7664 | ||
7665 | /* When all three operands are of the same mode. */ | |
7666 | if (mode0 == mode1 && mode1 == mode2) | |
7667 | { | |
7668 | switch (mode0) | |
7669 | { | |
7670 | case V4SFmode: | |
7671 | type = v4sf_ftype_v4sf_v4sf; | |
7672 | break; | |
7673 | case V4SImode: | |
7674 | type = v4si_ftype_v4si_v4si; | |
7675 | break; | |
7676 | case V16QImode: | |
7677 | type = v16qi_ftype_v16qi_v16qi; | |
7678 | break; | |
7679 | case V8HImode: | |
7680 | type = v8hi_ftype_v8hi_v8hi; | |
7681 | break; | |
a3170dc6 AH |
7682 | case V2SImode: |
7683 | type = v2si_ftype_v2si_v2si; | |
7684 | break; | |
7685 | case V2SFmode: | |
7686 | type = v2sf_ftype_v2sf_v2sf; | |
7687 | break; | |
7688 | case SImode: | |
7689 | type = int_ftype_int_int; | |
7690 | break; | |
0ac081f6 AH |
7691 | default: |
7692 | abort (); | |
7693 | } | |
7694 | } | |
7695 | ||
7696 | /* A few other combos we really don't want to do manually. */ | |
7697 | ||
7698 | /* vint, vfloat, vfloat. */ | |
7699 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode) | |
7700 | type = v4si_ftype_v4sf_v4sf; | |
7701 | ||
7702 | /* vshort, vchar, vchar. */ | |
7703 | else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode) | |
7704 | type = v8hi_ftype_v16qi_v16qi; | |
7705 | ||
7706 | /* vint, vshort, vshort. */ | |
7707 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode) | |
7708 | type = v4si_ftype_v8hi_v8hi; | |
7709 | ||
7710 | /* vshort, vint, vint. */ | |
7711 | else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode) | |
7712 | type = v8hi_ftype_v4si_v4si; | |
7713 | ||
7714 | /* vchar, vshort, vshort. */ | |
7715 | else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode) | |
7716 | type = v16qi_ftype_v8hi_v8hi; | |
7717 | ||
7718 | /* vint, vchar, vint. */ | |
7719 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode) | |
7720 | type = v4si_ftype_v16qi_v4si; | |
7721 | ||
fa066a23 AH |
7722 | /* vint, vchar, vchar. */ |
7723 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode) | |
7724 | type = v4si_ftype_v16qi_v16qi; | |
7725 | ||
0ac081f6 AH |
7726 | /* vint, vshort, vint. */ |
7727 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode) | |
7728 | type = v4si_ftype_v8hi_v4si; | |
2212663f DB |
7729 | |
7730 | /* vint, vint, 5 bit literal. */ | |
7731 | else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode) | |
b9e4e5d1 | 7732 | type = v4si_ftype_v4si_int; |
2212663f DB |
7733 | |
7734 | /* vshort, vshort, 5 bit literal. */ | |
7735 | else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode) | |
b9e4e5d1 | 7736 | type = v8hi_ftype_v8hi_int; |
2212663f DB |
7737 | |
7738 | /* vchar, vchar, 5 bit literal. */ | |
7739 | else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode) | |
b9e4e5d1 | 7740 | type = v16qi_ftype_v16qi_int; |
0ac081f6 | 7741 | |
617e0e1d DB |
7742 | /* vfloat, vint, 5 bit literal. */ |
7743 | else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode) | |
b9e4e5d1 | 7744 | type = v4sf_ftype_v4si_int; |
617e0e1d DB |
7745 | |
7746 | /* vint, vfloat, 5 bit literal. */ | |
7747 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode) | |
b9e4e5d1 | 7748 | type = v4si_ftype_v4sf_int; |
617e0e1d | 7749 | |
a3170dc6 AH |
7750 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode) |
7751 | type = v2si_ftype_int_int; | |
7752 | ||
7753 | else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode) | |
7754 | type = v2si_ftype_v2si_char; | |
7755 | ||
7756 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode) | |
7757 | type = v2si_ftype_int_char; | |
7758 | ||
0ac081f6 AH |
7759 | /* int, x, x. */ |
7760 | else if (mode0 == SImode) | |
7761 | { | |
7762 | switch (mode1) | |
7763 | { | |
7764 | case V4SImode: | |
7765 | type = int_ftype_v4si_v4si; | |
7766 | break; | |
7767 | case V4SFmode: | |
7768 | type = int_ftype_v4sf_v4sf; | |
7769 | break; | |
7770 | case V16QImode: | |
7771 | type = int_ftype_v16qi_v16qi; | |
7772 | break; | |
7773 | case V8HImode: | |
7774 | type = int_ftype_v8hi_v8hi; | |
7775 | break; | |
7776 | default: | |
7777 | abort (); | |
7778 | } | |
7779 | } | |
7780 | ||
7781 | else | |
7782 | abort (); | |
7783 | ||
2212663f DB |
7784 | def_builtin (d->mask, d->name, type, d->code); |
7785 | } | |
24408032 | 7786 | |
2212663f DB |
7787 | /* Add the simple unary operators. */ |
7788 | d = (struct builtin_description *) bdesc_1arg; | |
ca7558fc | 7789 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
2212663f DB |
7790 | { |
7791 | enum machine_mode mode0, mode1; | |
7792 | tree type; | |
7793 | ||
0559cc77 | 7794 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f DB |
7795 | continue; |
7796 | ||
7797 | mode0 = insn_data[d->icode].operand[0].mode; | |
7798 | mode1 = insn_data[d->icode].operand[1].mode; | |
7799 | ||
7800 | if (mode0 == V4SImode && mode1 == QImode) | |
b9e4e5d1 | 7801 | type = v4si_ftype_int; |
2212663f | 7802 | else if (mode0 == V8HImode && mode1 == QImode) |
b9e4e5d1 | 7803 | type = v8hi_ftype_int; |
2212663f | 7804 | else if (mode0 == V16QImode && mode1 == QImode) |
b9e4e5d1 | 7805 | type = v16qi_ftype_int; |
617e0e1d DB |
7806 | else if (mode0 == V4SFmode && mode1 == V4SFmode) |
7807 | type = v4sf_ftype_v4sf; | |
20e26713 AH |
7808 | else if (mode0 == V8HImode && mode1 == V16QImode) |
7809 | type = v8hi_ftype_v16qi; | |
7810 | else if (mode0 == V4SImode && mode1 == V8HImode) | |
7811 | type = v4si_ftype_v8hi; | |
a3170dc6 AH |
7812 | else if (mode0 == V2SImode && mode1 == V2SImode) |
7813 | type = v2si_ftype_v2si; | |
7814 | else if (mode0 == V2SFmode && mode1 == V2SFmode) | |
7815 | type = v2sf_ftype_v2sf; | |
7816 | else if (mode0 == V2SFmode && mode1 == V2SImode) | |
7817 | type = v2sf_ftype_v2si; | |
7818 | else if (mode0 == V2SImode && mode1 == V2SFmode) | |
7819 | type = v2si_ftype_v2sf; | |
7820 | else if (mode0 == V2SImode && mode1 == QImode) | |
7821 | type = v2si_ftype_char; | |
2212663f DB |
7822 | else |
7823 | abort (); | |
7824 | ||
0ac081f6 AH |
7825 | def_builtin (d->mask, d->name, type, d->code); |
7826 | } | |
7827 | } | |
7828 | ||
c15c90bb ZW |
7829 | static void |
7830 | rs6000_init_libfuncs (void) | |
7831 | { | |
7832 | if (!TARGET_HARD_FLOAT) | |
7833 | return; | |
7834 | ||
c9034561 | 7835 | if (DEFAULT_ABI != ABI_V4) |
c15c90bb | 7836 | { |
c9034561 | 7837 | if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC) |
c15c90bb | 7838 | { |
c9034561 | 7839 | /* AIX library routines for float->int conversion. */ |
85363ca0 ZW |
7840 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc"); |
7841 | set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc"); | |
4274207b DE |
7842 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc"); |
7843 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc"); | |
c15c90bb ZW |
7844 | } |
7845 | ||
c9034561 | 7846 | /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
7847 | set_optab_libfunc (add_optab, TFmode, "_xlqadd"); |
7848 | set_optab_libfunc (sub_optab, TFmode, "_xlqsub"); | |
7849 | set_optab_libfunc (smul_optab, TFmode, "_xlqmul"); | |
7850 | set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv"); | |
7851 | } | |
c9034561 | 7852 | else |
c15c90bb | 7853 | { |
c9034561 | 7854 | /* 32-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
7855 | |
7856 | set_optab_libfunc (add_optab, TFmode, "_q_add"); | |
7857 | set_optab_libfunc (sub_optab, TFmode, "_q_sub"); | |
7858 | set_optab_libfunc (neg_optab, TFmode, "_q_neg"); | |
7859 | set_optab_libfunc (smul_optab, TFmode, "_q_mul"); | |
7860 | set_optab_libfunc (sdiv_optab, TFmode, "_q_div"); | |
7861 | if (TARGET_PPC_GPOPT || TARGET_POWER2) | |
7862 | set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt"); | |
7863 | ||
c9034561 ZW |
7864 | set_optab_libfunc (eq_optab, TFmode, "_q_feq"); |
7865 | set_optab_libfunc (ne_optab, TFmode, "_q_fne"); | |
7866 | set_optab_libfunc (gt_optab, TFmode, "_q_fgt"); | |
7867 | set_optab_libfunc (ge_optab, TFmode, "_q_fge"); | |
7868 | set_optab_libfunc (lt_optab, TFmode, "_q_flt"); | |
7869 | set_optab_libfunc (le_optab, TFmode, "_q_fle"); | |
7870 | ||
85363ca0 ZW |
7871 | set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq"); |
7872 | set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq"); | |
7873 | set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos"); | |
7874 | set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod"); | |
7875 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi"); | |
7876 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou"); | |
7877 | set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq"); | |
c15c90bb ZW |
7878 | } |
7879 | } | |
35aff10b | 7880 | \f |
7e69e155 MM |
7881 | /* Expand a block move operation, and return 1 if successful. Return 0 |
7882 | if we should let the compiler generate normal code. | |
7883 | ||
7884 | operands[0] is the destination | |
7885 | operands[1] is the source | |
7886 | operands[2] is the length | |
7887 | operands[3] is the alignment */ | |
7888 | ||
3933e0e1 MM |
7889 | #define MAX_MOVE_REG 4 |
7890 | ||
7e69e155 | 7891 | int |
a2369ed3 | 7892 | expand_block_move (rtx operands[]) |
7e69e155 | 7893 | { |
b6c9286a MM |
7894 | rtx orig_dest = operands[0]; |
7895 | rtx orig_src = operands[1]; | |
7e69e155 | 7896 | rtx bytes_rtx = operands[2]; |
7e69e155 | 7897 | rtx align_rtx = operands[3]; |
3933e0e1 | 7898 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 7899 | int align; |
3933e0e1 MM |
7900 | int bytes; |
7901 | int offset; | |
7e69e155 | 7902 | int move_bytes; |
cabfd258 GK |
7903 | rtx stores[MAX_MOVE_REG]; |
7904 | int num_reg = 0; | |
7e69e155 | 7905 | |
3933e0e1 | 7906 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 7907 | if (! constp) |
3933e0e1 MM |
7908 | return 0; |
7909 | ||
5ee95df6 FS |
7910 | /* If this is not a fixed size alignment, abort */ |
7911 | if (GET_CODE (align_rtx) != CONST_INT) | |
7912 | abort (); | |
7913 | align = INTVAL (align_rtx); | |
7914 | ||
7e69e155 | 7915 | /* Anything to move? */ |
3933e0e1 MM |
7916 | bytes = INTVAL (bytes_rtx); |
7917 | if (bytes <= 0) | |
7e69e155 MM |
7918 | return 1; |
7919 | ||
ea9982a8 | 7920 | /* store_one_arg depends on expand_block_move to handle at least the size of |
6f317ef3 | 7921 | reg_parm_stack_space. */ |
ea9982a8 | 7922 | if (bytes > (TARGET_POWERPC64 ? 64 : 32)) |
7e69e155 MM |
7923 | return 0; |
7924 | ||
cabfd258 | 7925 | for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes) |
7e69e155 | 7926 | { |
cabfd258 | 7927 | union { |
a2369ed3 DJ |
7928 | rtx (*movstrsi) (rtx, rtx, rtx, rtx); |
7929 | rtx (*mov) (rtx, rtx); | |
cabfd258 GK |
7930 | } gen_func; |
7931 | enum machine_mode mode = BLKmode; | |
7932 | rtx src, dest; | |
7933 | ||
7934 | if (TARGET_STRING | |
7935 | && bytes > 24 /* move up to 32 bytes at a time */ | |
7936 | && ! fixed_regs[5] | |
7937 | && ! fixed_regs[6] | |
7938 | && ! fixed_regs[7] | |
7939 | && ! fixed_regs[8] | |
7940 | && ! fixed_regs[9] | |
7941 | && ! fixed_regs[10] | |
7942 | && ! fixed_regs[11] | |
7943 | && ! fixed_regs[12]) | |
7e69e155 | 7944 | { |
cabfd258 GK |
7945 | move_bytes = (bytes > 32) ? 32 : bytes; |
7946 | gen_func.movstrsi = gen_movstrsi_8reg; | |
7947 | } | |
7948 | else if (TARGET_STRING | |
7949 | && bytes > 16 /* move up to 24 bytes at a time */ | |
7950 | && ! fixed_regs[5] | |
7951 | && ! fixed_regs[6] | |
7952 | && ! fixed_regs[7] | |
7953 | && ! fixed_regs[8] | |
7954 | && ! fixed_regs[9] | |
7955 | && ! fixed_regs[10]) | |
7956 | { | |
7957 | move_bytes = (bytes > 24) ? 24 : bytes; | |
7958 | gen_func.movstrsi = gen_movstrsi_6reg; | |
7959 | } | |
7960 | else if (TARGET_STRING | |
7961 | && bytes > 8 /* move up to 16 bytes at a time */ | |
7962 | && ! fixed_regs[5] | |
7963 | && ! fixed_regs[6] | |
7964 | && ! fixed_regs[7] | |
7965 | && ! fixed_regs[8]) | |
7966 | { | |
7967 | move_bytes = (bytes > 16) ? 16 : bytes; | |
7968 | gen_func.movstrsi = gen_movstrsi_4reg; | |
7969 | } | |
7970 | else if (bytes >= 8 && TARGET_POWERPC64 | |
7971 | /* 64-bit loads and stores require word-aligned | |
7972 | displacements. */ | |
7973 | && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4))) | |
7974 | { | |
7975 | move_bytes = 8; | |
7976 | mode = DImode; | |
7977 | gen_func.mov = gen_movdi; | |
7978 | } | |
7979 | else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64) | |
7980 | { /* move up to 8 bytes at a time */ | |
7981 | move_bytes = (bytes > 8) ? 8 : bytes; | |
7982 | gen_func.movstrsi = gen_movstrsi_2reg; | |
7983 | } | |
7984 | else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT)) | |
7985 | { /* move 4 bytes */ | |
7986 | move_bytes = 4; | |
7987 | mode = SImode; | |
7988 | gen_func.mov = gen_movsi; | |
7989 | } | |
7990 | else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT)) | |
7991 | { /* move 2 bytes */ | |
7992 | move_bytes = 2; | |
7993 | mode = HImode; | |
7994 | gen_func.mov = gen_movhi; | |
7995 | } | |
7996 | else if (TARGET_STRING && bytes > 1) | |
7997 | { /* move up to 4 bytes at a time */ | |
7998 | move_bytes = (bytes > 4) ? 4 : bytes; | |
7999 | gen_func.movstrsi = gen_movstrsi_1reg; | |
8000 | } | |
8001 | else /* move 1 byte at a time */ | |
8002 | { | |
8003 | move_bytes = 1; | |
8004 | mode = QImode; | |
8005 | gen_func.mov = gen_movqi; | |
8006 | } | |
8007 | ||
8008 | src = adjust_address (orig_src, mode, offset); | |
8009 | dest = adjust_address (orig_dest, mode, offset); | |
8010 | ||
8011 | if (mode != BLKmode) | |
8012 | { | |
8013 | rtx tmp_reg = gen_reg_rtx (mode); | |
8014 | ||
8015 | emit_insn ((*gen_func.mov) (tmp_reg, src)); | |
8016 | stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg); | |
4c64a852 | 8017 | } |
3933e0e1 | 8018 | |
cabfd258 GK |
8019 | if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes) |
8020 | { | |
8021 | int i; | |
8022 | for (i = 0; i < num_reg; i++) | |
8023 | emit_insn (stores[i]); | |
8024 | num_reg = 0; | |
8025 | } | |
35aff10b | 8026 | |
cabfd258 | 8027 | if (mode == BLKmode) |
7e69e155 | 8028 | { |
cabfd258 GK |
8029 | /* Move the address into scratch registers. The movstrsi |
8030 | patterns require zero offset. */ | |
8031 | if (!REG_P (XEXP (src, 0))) | |
b6c9286a | 8032 | { |
cabfd258 GK |
8033 | rtx src_reg = copy_addr_to_reg (XEXP (src, 0)); |
8034 | src = replace_equiv_address (src, src_reg); | |
b6c9286a | 8035 | } |
cabfd258 GK |
8036 | set_mem_size (src, GEN_INT (move_bytes)); |
8037 | ||
8038 | if (!REG_P (XEXP (dest, 0))) | |
3933e0e1 | 8039 | { |
cabfd258 GK |
8040 | rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0)); |
8041 | dest = replace_equiv_address (dest, dest_reg); | |
7e69e155 | 8042 | } |
cabfd258 GK |
8043 | set_mem_size (dest, GEN_INT (move_bytes)); |
8044 | ||
8045 | emit_insn ((*gen_func.movstrsi) (dest, src, | |
8046 | GEN_INT (move_bytes & 31), | |
8047 | align_rtx)); | |
7e69e155 | 8048 | } |
7e69e155 MM |
8049 | } |
8050 | ||
8051 | return 1; | |
8052 | } | |
8053 | ||
9878760c RK |
8054 | \f |
8055 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
8056 | PARALLEL and the first section will be tested. */ | |
8057 | ||
8058 | int | |
a2369ed3 | 8059 | load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8060 | { |
8061 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8062 | unsigned int dest_regno; |
9878760c RK |
8063 | rtx src_addr; |
8064 | int i; | |
8065 | ||
8066 | /* Perform a quick check so we don't blow up below. */ | |
8067 | if (count <= 1 | |
8068 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8069 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
8070 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
8071 | return 0; | |
8072 | ||
8073 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8074 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
8075 | ||
8076 | for (i = 1; i < count; i++) | |
8077 | { | |
8078 | rtx elt = XVECEXP (op, 0, i); | |
8079 | ||
8080 | if (GET_CODE (elt) != SET | |
8081 | || GET_CODE (SET_DEST (elt)) != REG | |
8082 | || GET_MODE (SET_DEST (elt)) != SImode | |
8083 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
8084 | || GET_CODE (SET_SRC (elt)) != MEM | |
8085 | || GET_MODE (SET_SRC (elt)) != SImode | |
8086 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
8087 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
8088 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
8089 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
8090 | return 0; | |
8091 | } | |
8092 | ||
8093 | return 1; | |
8094 | } | |
8095 | ||
8096 | /* Similar, but tests for store multiple. Here, the second vector element | |
8097 | is a CLOBBER. It will be tested later. */ | |
8098 | ||
8099 | int | |
a2369ed3 | 8100 | store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8101 | { |
8102 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 8103 | unsigned int src_regno; |
9878760c RK |
8104 | rtx dest_addr; |
8105 | int i; | |
8106 | ||
8107 | /* Perform a quick check so we don't blow up below. */ | |
8108 | if (count <= 1 | |
8109 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8110 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
8111 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
8112 | return 0; | |
8113 | ||
8114 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8115 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
8116 | ||
8117 | for (i = 1; i < count; i++) | |
8118 | { | |
8119 | rtx elt = XVECEXP (op, 0, i + 1); | |
8120 | ||
8121 | if (GET_CODE (elt) != SET | |
8122 | || GET_CODE (SET_SRC (elt)) != REG | |
8123 | || GET_MODE (SET_SRC (elt)) != SImode | |
8124 | || REGNO (SET_SRC (elt)) != src_regno + i | |
8125 | || GET_CODE (SET_DEST (elt)) != MEM | |
8126 | || GET_MODE (SET_DEST (elt)) != SImode | |
8127 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
8128 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
8129 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
8130 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
8131 | return 0; | |
8132 | } | |
8133 | ||
8134 | return 1; | |
8135 | } | |
9ebbca7d | 8136 | |
9caa3eb2 DE |
8137 | /* Return a string to perform a load_multiple operation. |
8138 | operands[0] is the vector. | |
8139 | operands[1] is the source address. | |
8140 | operands[2] is the first destination register. */ | |
8141 | ||
8142 | const char * | |
a2369ed3 | 8143 | rs6000_output_load_multiple (rtx operands[3]) |
9caa3eb2 DE |
8144 | { |
8145 | /* We have to handle the case where the pseudo used to contain the address | |
8146 | is assigned to one of the output registers. */ | |
8147 | int i, j; | |
8148 | int words = XVECLEN (operands[0], 0); | |
8149 | rtx xop[10]; | |
8150 | ||
8151 | if (XVECLEN (operands[0], 0) == 1) | |
8152 | return "{l|lwz} %2,0(%1)"; | |
8153 | ||
8154 | for (i = 0; i < words; i++) | |
8155 | if (refers_to_regno_p (REGNO (operands[2]) + i, | |
8156 | REGNO (operands[2]) + i + 1, operands[1], 0)) | |
8157 | { | |
8158 | if (i == words-1) | |
8159 | { | |
8160 | xop[0] = GEN_INT (4 * (words-1)); | |
8161 | xop[1] = operands[1]; | |
8162 | xop[2] = operands[2]; | |
8163 | output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop); | |
8164 | return ""; | |
8165 | } | |
8166 | else if (i == 0) | |
8167 | { | |
8168 | xop[0] = GEN_INT (4 * (words-1)); | |
8169 | xop[1] = operands[1]; | |
8170 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
8171 | 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); | |
8172 | return ""; | |
8173 | } | |
8174 | else | |
8175 | { | |
8176 | for (j = 0; j < words; j++) | |
8177 | if (j != i) | |
8178 | { | |
8179 | xop[0] = GEN_INT (j * 4); | |
8180 | xop[1] = operands[1]; | |
8181 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j); | |
8182 | output_asm_insn ("{l|lwz} %2,%0(%1)", xop); | |
8183 | } | |
8184 | xop[0] = GEN_INT (i * 4); | |
8185 | xop[1] = operands[1]; | |
8186 | output_asm_insn ("{l|lwz} %1,%0(%1)", xop); | |
8187 | return ""; | |
8188 | } | |
8189 | } | |
8190 | ||
8191 | return "{lsi|lswi} %2,%1,%N0"; | |
8192 | } | |
8193 | ||
00b960c7 AH |
8194 | /* Return 1 for a parallel vrsave operation. */ |
8195 | ||
8196 | int | |
a2369ed3 | 8197 | vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
00b960c7 AH |
8198 | { |
8199 | int count = XVECLEN (op, 0); | |
8200 | unsigned int dest_regno, src_regno; | |
8201 | int i; | |
8202 | ||
8203 | if (count <= 1 | |
8204 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8205 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
a004eb82 | 8206 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE) |
00b960c7 AH |
8207 | return 0; |
8208 | ||
8209 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8210 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8211 | ||
8212 | if (dest_regno != VRSAVE_REGNO | |
8213 | && src_regno != VRSAVE_REGNO) | |
8214 | return 0; | |
8215 | ||
8216 | for (i = 1; i < count; i++) | |
8217 | { | |
8218 | rtx elt = XVECEXP (op, 0, i); | |
8219 | ||
9aa86737 AH |
8220 | if (GET_CODE (elt) != CLOBBER |
8221 | && GET_CODE (elt) != SET) | |
00b960c7 AH |
8222 | return 0; |
8223 | } | |
8224 | ||
8225 | return 1; | |
8226 | } | |
8227 | ||
2c4a9cff DE |
8228 | /* Return 1 for an PARALLEL suitable for mfcr. */ |
8229 | ||
8230 | int | |
a2369ed3 | 8231 | mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2c4a9cff DE |
8232 | { |
8233 | int count = XVECLEN (op, 0); | |
8234 | int i; | |
8235 | ||
8236 | /* Perform a quick check so we don't blow up below. */ | |
8237 | if (count < 1 | |
8238 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8239 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
8240 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
8241 | return 0; | |
8242 | ||
8243 | for (i = 0; i < count; i++) | |
8244 | { | |
8245 | rtx exp = XVECEXP (op, 0, i); | |
8246 | rtx unspec; | |
8247 | int maskval; | |
8248 | rtx src_reg; | |
8249 | ||
8250 | src_reg = XVECEXP (SET_SRC (exp), 0, 0); | |
8251 | ||
8252 | if (GET_CODE (src_reg) != REG | |
8253 | || GET_MODE (src_reg) != CCmode | |
8254 | || ! CR_REGNO_P (REGNO (src_reg))) | |
8255 | return 0; | |
8256 | ||
8257 | if (GET_CODE (exp) != SET | |
8258 | || GET_CODE (SET_DEST (exp)) != REG | |
8259 | || GET_MODE (SET_DEST (exp)) != SImode | |
8260 | || ! INT_REGNO_P (REGNO (SET_DEST (exp)))) | |
8261 | return 0; | |
8262 | unspec = SET_SRC (exp); | |
8263 | maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg)); | |
8264 | ||
8265 | if (GET_CODE (unspec) != UNSPEC | |
8266 | || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR | |
8267 | || XVECLEN (unspec, 0) != 2 | |
8268 | || XVECEXP (unspec, 0, 0) != src_reg | |
8269 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
8270 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
8271 | return 0; | |
8272 | } | |
8273 | return 1; | |
8274 | } | |
8275 | ||
a4f6c312 | 8276 | /* Return 1 for an PARALLEL suitable for mtcrf. */ |
9ebbca7d GK |
8277 | |
8278 | int | |
a2369ed3 | 8279 | mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
8280 | { |
8281 | int count = XVECLEN (op, 0); | |
8282 | int i; | |
9ebbca7d GK |
8283 | rtx src_reg; |
8284 | ||
8285 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
8286 | if (count < 1 |
8287 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8288 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
8289 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 8290 | return 0; |
e35b9579 | 8291 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
9ebbca7d GK |
8292 | |
8293 | if (GET_CODE (src_reg) != REG | |
8294 | || GET_MODE (src_reg) != SImode | |
8295 | || ! INT_REGNO_P (REGNO (src_reg))) | |
8296 | return 0; | |
8297 | ||
e35b9579 | 8298 | for (i = 0; i < count; i++) |
9ebbca7d GK |
8299 | { |
8300 | rtx exp = XVECEXP (op, 0, i); | |
8301 | rtx unspec; | |
8302 | int maskval; | |
8303 | ||
8304 | if (GET_CODE (exp) != SET | |
8305 | || GET_CODE (SET_DEST (exp)) != REG | |
8306 | || GET_MODE (SET_DEST (exp)) != CCmode | |
8307 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
8308 | return 0; | |
8309 | unspec = SET_SRC (exp); | |
8310 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
9ebbca7d GK |
8311 | |
8312 | if (GET_CODE (unspec) != UNSPEC | |
615158e2 | 8313 | || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR |
9ebbca7d GK |
8314 | || XVECLEN (unspec, 0) != 2 |
8315 | || XVECEXP (unspec, 0, 0) != src_reg | |
8316 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
8317 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
8318 | return 0; | |
8319 | } | |
e35b9579 | 8320 | return 1; |
9ebbca7d GK |
8321 | } |
8322 | ||
a4f6c312 | 8323 | /* Return 1 for an PARALLEL suitable for lmw. */ |
9ebbca7d GK |
8324 | |
8325 | int | |
a2369ed3 | 8326 | lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
8327 | { |
8328 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8329 | unsigned int dest_regno; |
9ebbca7d | 8330 | rtx src_addr; |
e2c953b6 | 8331 | unsigned int base_regno; |
9ebbca7d GK |
8332 | HOST_WIDE_INT offset; |
8333 | int i; | |
8334 | ||
8335 | /* Perform a quick check so we don't blow up below. */ | |
8336 | if (count <= 1 | |
8337 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8338 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
8339 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
8340 | return 0; | |
8341 | ||
8342 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8343 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
8344 | ||
8345 | if (dest_regno > 31 | |
e2c953b6 | 8346 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
8347 | return 0; |
8348 | ||
4d588c14 | 8349 | if (legitimate_indirect_address_p (src_addr, 0)) |
9ebbca7d GK |
8350 | { |
8351 | offset = 0; | |
8352 | base_regno = REGNO (src_addr); | |
8353 | if (base_regno == 0) | |
8354 | return 0; | |
8355 | } | |
76d2b81d | 8356 | else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0)) |
9ebbca7d GK |
8357 | { |
8358 | offset = INTVAL (XEXP (src_addr, 1)); | |
8359 | base_regno = REGNO (XEXP (src_addr, 0)); | |
8360 | } | |
8361 | else | |
8362 | return 0; | |
8363 | ||
8364 | for (i = 0; i < count; i++) | |
8365 | { | |
8366 | rtx elt = XVECEXP (op, 0, i); | |
8367 | rtx newaddr; | |
8368 | rtx addr_reg; | |
8369 | HOST_WIDE_INT newoffset; | |
8370 | ||
8371 | if (GET_CODE (elt) != SET | |
8372 | || GET_CODE (SET_DEST (elt)) != REG | |
8373 | || GET_MODE (SET_DEST (elt)) != SImode | |
8374 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
8375 | || GET_CODE (SET_SRC (elt)) != MEM | |
8376 | || GET_MODE (SET_SRC (elt)) != SImode) | |
8377 | return 0; | |
8378 | newaddr = XEXP (SET_SRC (elt), 0); | |
4d588c14 | 8379 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
8380 | { |
8381 | newoffset = 0; | |
8382 | addr_reg = newaddr; | |
8383 | } | |
76d2b81d | 8384 | else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
8385 | { |
8386 | addr_reg = XEXP (newaddr, 0); | |
8387 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
8388 | } | |
8389 | else | |
8390 | return 0; | |
8391 | if (REGNO (addr_reg) != base_regno | |
8392 | || newoffset != offset + 4 * i) | |
8393 | return 0; | |
8394 | } | |
8395 | ||
8396 | return 1; | |
8397 | } | |
8398 | ||
a4f6c312 | 8399 | /* Return 1 for an PARALLEL suitable for stmw. */ |
9ebbca7d GK |
8400 | |
8401 | int | |
a2369ed3 | 8402 | stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
8403 | { |
8404 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8405 | unsigned int src_regno; |
9ebbca7d | 8406 | rtx dest_addr; |
e2c953b6 | 8407 | unsigned int base_regno; |
9ebbca7d GK |
8408 | HOST_WIDE_INT offset; |
8409 | int i; | |
8410 | ||
8411 | /* Perform a quick check so we don't blow up below. */ | |
8412 | if (count <= 1 | |
8413 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8414 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
8415 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
8416 | return 0; | |
8417 | ||
8418 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8419 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
8420 | ||
8421 | if (src_regno > 31 | |
e2c953b6 | 8422 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
8423 | return 0; |
8424 | ||
4d588c14 | 8425 | if (legitimate_indirect_address_p (dest_addr, 0)) |
9ebbca7d GK |
8426 | { |
8427 | offset = 0; | |
8428 | base_regno = REGNO (dest_addr); | |
8429 | if (base_regno == 0) | |
8430 | return 0; | |
8431 | } | |
76d2b81d | 8432 | else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0)) |
9ebbca7d GK |
8433 | { |
8434 | offset = INTVAL (XEXP (dest_addr, 1)); | |
8435 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
8436 | } | |
8437 | else | |
8438 | return 0; | |
8439 | ||
8440 | for (i = 0; i < count; i++) | |
8441 | { | |
8442 | rtx elt = XVECEXP (op, 0, i); | |
8443 | rtx newaddr; | |
8444 | rtx addr_reg; | |
8445 | HOST_WIDE_INT newoffset; | |
8446 | ||
8447 | if (GET_CODE (elt) != SET | |
8448 | || GET_CODE (SET_SRC (elt)) != REG | |
8449 | || GET_MODE (SET_SRC (elt)) != SImode | |
8450 | || REGNO (SET_SRC (elt)) != src_regno + i | |
8451 | || GET_CODE (SET_DEST (elt)) != MEM | |
8452 | || GET_MODE (SET_DEST (elt)) != SImode) | |
8453 | return 0; | |
8454 | newaddr = XEXP (SET_DEST (elt), 0); | |
4d588c14 | 8455 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
8456 | { |
8457 | newoffset = 0; | |
8458 | addr_reg = newaddr; | |
8459 | } | |
76d2b81d | 8460 | else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
8461 | { |
8462 | addr_reg = XEXP (newaddr, 0); | |
8463 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
8464 | } | |
8465 | else | |
8466 | return 0; | |
8467 | if (REGNO (addr_reg) != base_regno | |
8468 | || newoffset != offset + 4 * i) | |
8469 | return 0; | |
8470 | } | |
8471 | ||
8472 | return 1; | |
8473 | } | |
9878760c | 8474 | \f |
a4f6c312 SS |
8475 | /* A validation routine: say whether CODE, a condition code, and MODE |
8476 | match. The other alternatives either don't make sense or should | |
8477 | never be generated. */ | |
39a10a29 | 8478 | |
39a10a29 | 8479 | static void |
a2369ed3 | 8480 | validate_condition_mode (enum rtx_code code, enum machine_mode mode) |
39a10a29 | 8481 | { |
ec8e098d PB |
8482 | if ((GET_RTX_CLASS (code) != RTX_COMPARE |
8483 | && GET_RTX_CLASS (code) != RTX_COMM_COMPARE) | |
39a10a29 GK |
8484 | || GET_MODE_CLASS (mode) != MODE_CC) |
8485 | abort (); | |
8486 | ||
8487 | /* These don't make sense. */ | |
8488 | if ((code == GT || code == LT || code == GE || code == LE) | |
8489 | && mode == CCUNSmode) | |
8490 | abort (); | |
8491 | ||
8492 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
8493 | && mode != CCUNSmode) | |
8494 | abort (); | |
8495 | ||
8496 | if (mode != CCFPmode | |
8497 | && (code == ORDERED || code == UNORDERED | |
8498 | || code == UNEQ || code == LTGT | |
8499 | || code == UNGT || code == UNLT | |
8500 | || code == UNGE || code == UNLE)) | |
a4f6c312 | 8501 | abort (); |
39a10a29 | 8502 | |
de6c5979 | 8503 | /* These should never be generated except for |
bc9ec0e0 | 8504 | flag_finite_math_only. */ |
39a10a29 | 8505 | if (mode == CCFPmode |
ad72b533 | 8506 | && ! flag_finite_math_only |
39a10a29 GK |
8507 | && (code == LE || code == GE |
8508 | || code == UNEQ || code == LTGT | |
8509 | || code == UNGT || code == UNLT)) | |
8510 | abort (); | |
8511 | ||
8512 | /* These are invalid; the information is not there. */ | |
8513 | if (mode == CCEQmode | |
8514 | && code != EQ && code != NE) | |
8515 | abort (); | |
8516 | } | |
8517 | ||
9878760c RK |
8518 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
8519 | We only check the opcode against the mode of the CC value here. */ | |
8520 | ||
8521 | int | |
a2369ed3 | 8522 | branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8523 | { |
8524 | enum rtx_code code = GET_CODE (op); | |
8525 | enum machine_mode cc_mode; | |
8526 | ||
ec8e098d | 8527 | if (!COMPARISON_P (op)) |
9878760c RK |
8528 | return 0; |
8529 | ||
8530 | cc_mode = GET_MODE (XEXP (op, 0)); | |
8531 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
8532 | return 0; | |
8533 | ||
39a10a29 | 8534 | validate_condition_mode (code, cc_mode); |
9878760c | 8535 | |
39a10a29 GK |
8536 | return 1; |
8537 | } | |
8538 | ||
8539 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
8540 | insn and which is true if the corresponding bit in the CC register | |
8541 | is set. */ | |
8542 | ||
8543 | int | |
a2369ed3 | 8544 | branch_positive_comparison_operator (rtx op, enum machine_mode mode) |
39a10a29 GK |
8545 | { |
8546 | enum rtx_code code; | |
8547 | ||
8daf2e65 | 8548 | if (! branch_comparison_operator (op, mode)) |
9878760c RK |
8549 | return 0; |
8550 | ||
39a10a29 GK |
8551 | code = GET_CODE (op); |
8552 | return (code == EQ || code == LT || code == GT | |
8553 | || code == LTU || code == GTU | |
8554 | || code == UNORDERED); | |
9878760c RK |
8555 | } |
8556 | ||
b7053a3f GK |
8557 | /* Return 1 if OP is a comparison operation that is valid for an scc |
8558 | insn: it must be a positive comparison. */ | |
9878760c RK |
8559 | |
8560 | int | |
a2369ed3 | 8561 | scc_comparison_operator (rtx op, enum machine_mode mode) |
9878760c | 8562 | { |
b7053a3f | 8563 | return branch_positive_comparison_operator (op, mode); |
9878760c | 8564 | } |
e0cd0770 JC |
8565 | |
8566 | int | |
a2369ed3 | 8567 | trap_comparison_operator (rtx op, enum machine_mode mode) |
e0cd0770 JC |
8568 | { |
8569 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
8570 | return 0; | |
ec8e098d | 8571 | return COMPARISON_P (op); |
e0cd0770 | 8572 | } |
dfbdccdb GK |
8573 | |
8574 | int | |
a2369ed3 | 8575 | boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dfbdccdb GK |
8576 | { |
8577 | enum rtx_code code = GET_CODE (op); | |
8578 | return (code == AND || code == IOR || code == XOR); | |
8579 | } | |
1d328b19 GK |
8580 | |
8581 | int | |
a2369ed3 | 8582 | boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
1d328b19 GK |
8583 | { |
8584 | enum rtx_code code = GET_CODE (op); | |
8585 | return (code == IOR || code == XOR); | |
8586 | } | |
50a0b056 GK |
8587 | |
8588 | int | |
a2369ed3 | 8589 | min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
50a0b056 GK |
8590 | { |
8591 | enum rtx_code code = GET_CODE (op); | |
8592 | return (code == SMIN || code == SMAX || code == UMIN || code == UMAX); | |
8593 | } | |
9878760c RK |
8594 | \f |
8595 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
8596 | mask required to convert the result of a rotate insn into a shift | |
b1765bde | 8597 | left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */ |
9878760c RK |
8598 | |
8599 | int | |
a2369ed3 | 8600 | includes_lshift_p (rtx shiftop, rtx andop) |
9878760c | 8601 | { |
e2c953b6 DE |
8602 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
8603 | ||
8604 | shift_mask <<= INTVAL (shiftop); | |
9878760c | 8605 | |
b1765bde | 8606 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
9878760c RK |
8607 | } |
8608 | ||
8609 | /* Similar, but for right shift. */ | |
8610 | ||
8611 | int | |
a2369ed3 | 8612 | includes_rshift_p (rtx shiftop, rtx andop) |
9878760c | 8613 | { |
a7653a2c | 8614 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
8615 | |
8616 | shift_mask >>= INTVAL (shiftop); | |
8617 | ||
b1765bde | 8618 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
e2c953b6 DE |
8619 | } |
8620 | ||
c5059423 AM |
8621 | /* Return 1 if ANDOP is a mask suitable for use with an rldic insn |
8622 | to perform a left shift. It must have exactly SHIFTOP least | |
b6d08ca1 | 8623 | significant 0's, then one or more 1's, then zero or more 0's. */ |
e2c953b6 DE |
8624 | |
8625 | int | |
a2369ed3 | 8626 | includes_rldic_lshift_p (rtx shiftop, rtx andop) |
e2c953b6 | 8627 | { |
c5059423 AM |
8628 | if (GET_CODE (andop) == CONST_INT) |
8629 | { | |
02071907 | 8630 | HOST_WIDE_INT c, lsb, shift_mask; |
e2c953b6 | 8631 | |
c5059423 | 8632 | c = INTVAL (andop); |
02071907 | 8633 | if (c == 0 || c == ~0) |
c5059423 | 8634 | return 0; |
e2c953b6 | 8635 | |
02071907 | 8636 | shift_mask = ~0; |
c5059423 AM |
8637 | shift_mask <<= INTVAL (shiftop); |
8638 | ||
b6d08ca1 | 8639 | /* Find the least significant one bit. */ |
c5059423 AM |
8640 | lsb = c & -c; |
8641 | ||
8642 | /* It must coincide with the LSB of the shift mask. */ | |
8643 | if (-lsb != shift_mask) | |
8644 | return 0; | |
e2c953b6 | 8645 | |
c5059423 AM |
8646 | /* Invert to look for the next transition (if any). */ |
8647 | c = ~c; | |
8648 | ||
8649 | /* Remove the low group of ones (originally low group of zeros). */ | |
8650 | c &= -lsb; | |
8651 | ||
8652 | /* Again find the lsb, and check we have all 1's above. */ | |
8653 | lsb = c & -c; | |
8654 | return c == -lsb; | |
8655 | } | |
8656 | else if (GET_CODE (andop) == CONST_DOUBLE | |
8657 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
8658 | { | |
02071907 AM |
8659 | HOST_WIDE_INT low, high, lsb; |
8660 | HOST_WIDE_INT shift_mask_low, shift_mask_high; | |
c5059423 AM |
8661 | |
8662 | low = CONST_DOUBLE_LOW (andop); | |
8663 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8664 | high = CONST_DOUBLE_HIGH (andop); | |
8665 | ||
8666 | if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)) | |
02071907 | 8667 | || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0))) |
c5059423 AM |
8668 | return 0; |
8669 | ||
8670 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
8671 | { | |
02071907 | 8672 | shift_mask_high = ~0; |
c5059423 AM |
8673 | if (INTVAL (shiftop) > 32) |
8674 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
8675 | ||
8676 | lsb = high & -high; | |
8677 | ||
8678 | if (-lsb != shift_mask_high || INTVAL (shiftop) < 32) | |
8679 | return 0; | |
8680 | ||
8681 | high = ~high; | |
8682 | high &= -lsb; | |
8683 | ||
8684 | lsb = high & -high; | |
8685 | return high == -lsb; | |
8686 | } | |
8687 | ||
02071907 | 8688 | shift_mask_low = ~0; |
c5059423 AM |
8689 | shift_mask_low <<= INTVAL (shiftop); |
8690 | ||
8691 | lsb = low & -low; | |
8692 | ||
8693 | if (-lsb != shift_mask_low) | |
8694 | return 0; | |
8695 | ||
8696 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8697 | high = ~high; | |
8698 | low = ~low; | |
8699 | low &= -lsb; | |
8700 | ||
8701 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
8702 | { | |
8703 | lsb = high & -high; | |
8704 | return high == -lsb; | |
8705 | } | |
8706 | ||
8707 | lsb = low & -low; | |
8708 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
8709 | } | |
8710 | else | |
8711 | return 0; | |
8712 | } | |
e2c953b6 | 8713 | |
c5059423 AM |
8714 | /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn |
8715 | to perform a left shift. It must have SHIFTOP or more least | |
c1207243 | 8716 | significant 0's, with the remainder of the word 1's. */ |
e2c953b6 | 8717 | |
c5059423 | 8718 | int |
a2369ed3 | 8719 | includes_rldicr_lshift_p (rtx shiftop, rtx andop) |
c5059423 | 8720 | { |
e2c953b6 | 8721 | if (GET_CODE (andop) == CONST_INT) |
c5059423 | 8722 | { |
02071907 | 8723 | HOST_WIDE_INT c, lsb, shift_mask; |
c5059423 | 8724 | |
02071907 | 8725 | shift_mask = ~0; |
c5059423 AM |
8726 | shift_mask <<= INTVAL (shiftop); |
8727 | c = INTVAL (andop); | |
8728 | ||
c1207243 | 8729 | /* Find the least significant one bit. */ |
c5059423 AM |
8730 | lsb = c & -c; |
8731 | ||
8732 | /* It must be covered by the shift mask. | |
a4f6c312 | 8733 | This test also rejects c == 0. */ |
c5059423 AM |
8734 | if ((lsb & shift_mask) == 0) |
8735 | return 0; | |
8736 | ||
8737 | /* Check we have all 1's above the transition, and reject all 1's. */ | |
8738 | return c == -lsb && lsb != 1; | |
8739 | } | |
8740 | else if (GET_CODE (andop) == CONST_DOUBLE | |
8741 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
8742 | { | |
02071907 | 8743 | HOST_WIDE_INT low, lsb, shift_mask_low; |
c5059423 AM |
8744 | |
8745 | low = CONST_DOUBLE_LOW (andop); | |
8746 | ||
8747 | if (HOST_BITS_PER_WIDE_INT < 64) | |
8748 | { | |
02071907 | 8749 | HOST_WIDE_INT high, shift_mask_high; |
c5059423 AM |
8750 | |
8751 | high = CONST_DOUBLE_HIGH (andop); | |
8752 | ||
8753 | if (low == 0) | |
8754 | { | |
02071907 | 8755 | shift_mask_high = ~0; |
c5059423 AM |
8756 | if (INTVAL (shiftop) > 32) |
8757 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
8758 | ||
8759 | lsb = high & -high; | |
8760 | ||
8761 | if ((lsb & shift_mask_high) == 0) | |
8762 | return 0; | |
8763 | ||
8764 | return high == -lsb; | |
8765 | } | |
8766 | if (high != ~0) | |
8767 | return 0; | |
8768 | } | |
8769 | ||
02071907 | 8770 | shift_mask_low = ~0; |
c5059423 AM |
8771 | shift_mask_low <<= INTVAL (shiftop); |
8772 | ||
8773 | lsb = low & -low; | |
8774 | ||
8775 | if ((lsb & shift_mask_low) == 0) | |
8776 | return 0; | |
8777 | ||
8778 | return low == -lsb && lsb != 1; | |
8779 | } | |
e2c953b6 | 8780 | else |
c5059423 | 8781 | return 0; |
9878760c | 8782 | } |
35068b43 | 8783 | |
11ac38b2 DE |
8784 | /* Return 1 if operands will generate a valid arguments to rlwimi |
8785 | instruction for insert with right shift in 64-bit mode. The mask may | |
8786 | not start on the first bit or stop on the last bit because wrap-around | |
8787 | effects of instruction do not correspond to semantics of RTL insn. */ | |
8788 | ||
8789 | int | |
8790 | insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop) | |
8791 | { | |
8792 | if (INTVAL (startop) < 64 | |
8793 | && INTVAL (startop) > 32 | |
8794 | && (INTVAL (sizeop) + INTVAL (startop) < 64) | |
8795 | && (INTVAL (sizeop) + INTVAL (startop) > 33) | |
8796 | && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96) | |
8797 | && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64) | |
8798 | && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop)) | |
8799 | return 1; | |
8800 | ||
8801 | return 0; | |
8802 | } | |
8803 | ||
35068b43 | 8804 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates |
90f81f99 | 8805 | for lfq and stfq insns iff the registers are hard registers. */ |
35068b43 RK |
8806 | |
8807 | int | |
a2369ed3 | 8808 | registers_ok_for_quad_peep (rtx reg1, rtx reg2) |
35068b43 RK |
8809 | { |
8810 | /* We might have been passed a SUBREG. */ | |
8811 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
8812 | return 0; | |
90f81f99 AP |
8813 | |
8814 | /* We might have been passed non floating point registers. */ | |
8815 | if (!FP_REGNO_P (REGNO (reg1)) | |
8816 | || !FP_REGNO_P (REGNO (reg2))) | |
8817 | return 0; | |
35068b43 RK |
8818 | |
8819 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
8820 | } | |
8821 | ||
a4f6c312 SS |
8822 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. |
8823 | addr1 and addr2 must be in consecutive memory locations | |
8824 | (addr2 == addr1 + 8). */ | |
35068b43 RK |
8825 | |
8826 | int | |
90f81f99 | 8827 | mems_ok_for_quad_peep (rtx mem1, rtx mem2) |
35068b43 | 8828 | { |
90f81f99 | 8829 | rtx addr1, addr2; |
e2c953b6 | 8830 | unsigned int reg1; |
35068b43 RK |
8831 | int offset1; |
8832 | ||
90f81f99 AP |
8833 | /* The mems cannot be volatile. */ |
8834 | if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2)) | |
8835 | return 0; | |
8836 | ||
8837 | addr1 = XEXP (mem1, 0); | |
8838 | addr2 = XEXP (mem2, 0); | |
8839 | ||
35068b43 RK |
8840 | /* Extract an offset (if used) from the first addr. */ |
8841 | if (GET_CODE (addr1) == PLUS) | |
8842 | { | |
8843 | /* If not a REG, return zero. */ | |
8844 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
8845 | return 0; | |
8846 | else | |
8847 | { | |
8848 | reg1 = REGNO (XEXP (addr1, 0)); | |
8849 | /* The offset must be constant! */ | |
8850 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
8851 | return 0; | |
8852 | offset1 = INTVAL (XEXP (addr1, 1)); | |
8853 | } | |
8854 | } | |
8855 | else if (GET_CODE (addr1) != REG) | |
8856 | return 0; | |
8857 | else | |
8858 | { | |
8859 | reg1 = REGNO (addr1); | |
8860 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
8861 | offset1 = 0; | |
8862 | } | |
8863 | ||
a2369ed3 | 8864 | /* Make sure the second address is a (mem (plus (reg) (const_int))) |
0f6937fe AM |
8865 | or if it is (mem (reg)) then make sure that offset1 is -8 and the same |
8866 | register as addr1. */ | |
984e25ac | 8867 | if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2)) |
0f6937fe | 8868 | return 1; |
35068b43 RK |
8869 | if (GET_CODE (addr2) != PLUS) |
8870 | return 0; | |
8871 | ||
8872 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
8873 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
8874 | return 0; | |
8875 | ||
8876 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
8877 | return 0; | |
8878 | ||
8879 | /* The offset for the second addr must be 8 more than the first addr. */ | |
8880 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
8881 | return 0; | |
8882 | ||
8883 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
8884 | instructions. */ | |
8885 | return 1; | |
8886 | } | |
9878760c RK |
8887 | \f |
8888 | /* Return the register class of a scratch register needed to copy IN into | |
8889 | or out of a register in CLASS in MODE. If it can be done directly, | |
8890 | NO_REGS is returned. */ | |
8891 | ||
8892 | enum reg_class | |
a2369ed3 | 8893 | secondary_reload_class (enum reg_class class, |
a9baceb1 GK |
8894 | enum machine_mode mode ATTRIBUTE_UNUSED, |
8895 | rtx in) | |
9878760c | 8896 | { |
5accd822 | 8897 | int regno; |
9878760c | 8898 | |
ab82a49f AP |
8899 | if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN |
8900 | #if TARGET_MACHO | |
8901 | && MACHOPIC_INDIRECT | |
8902 | #endif | |
8903 | )) | |
46fad5b7 DJ |
8904 | { |
8905 | /* We cannot copy a symbolic operand directly into anything | |
8906 | other than BASE_REGS for TARGET_ELF. So indicate that a | |
8907 | register from BASE_REGS is needed as an intermediate | |
8908 | register. | |
8909 | ||
8910 | On Darwin, pic addresses require a load from memory, which | |
8911 | needs a base register. */ | |
8912 | if (class != BASE_REGS | |
8913 | && (GET_CODE (in) == SYMBOL_REF | |
8914 | || GET_CODE (in) == HIGH | |
8915 | || GET_CODE (in) == LABEL_REF | |
8916 | || GET_CODE (in) == CONST)) | |
8917 | return BASE_REGS; | |
8918 | } | |
e7b7998a | 8919 | |
5accd822 DE |
8920 | if (GET_CODE (in) == REG) |
8921 | { | |
8922 | regno = REGNO (in); | |
8923 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8924 | { | |
8925 | regno = true_regnum (in); | |
8926 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8927 | regno = -1; | |
8928 | } | |
8929 | } | |
8930 | else if (GET_CODE (in) == SUBREG) | |
8931 | { | |
8932 | regno = true_regnum (in); | |
8933 | if (regno >= FIRST_PSEUDO_REGISTER) | |
8934 | regno = -1; | |
8935 | } | |
8936 | else | |
8937 | regno = -1; | |
8938 | ||
9878760c RK |
8939 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
8940 | into anything. */ | |
8941 | if (class == GENERAL_REGS || class == BASE_REGS | |
8942 | || (regno >= 0 && INT_REGNO_P (regno))) | |
8943 | return NO_REGS; | |
8944 | ||
8945 | /* Constants, memory, and FP registers can go into FP registers. */ | |
8946 | if ((regno == -1 || FP_REGNO_P (regno)) | |
8947 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
8948 | return NO_REGS; | |
8949 | ||
0ac081f6 AH |
8950 | /* Memory, and AltiVec registers can go into AltiVec registers. */ |
8951 | if ((regno == -1 || ALTIVEC_REGNO_P (regno)) | |
8952 | && class == ALTIVEC_REGS) | |
8953 | return NO_REGS; | |
8954 | ||
9878760c RK |
8955 | /* We can copy among the CR registers. */ |
8956 | if ((class == CR_REGS || class == CR0_REGS) | |
8957 | && regno >= 0 && CR_REGNO_P (regno)) | |
8958 | return NO_REGS; | |
8959 | ||
8960 | /* Otherwise, we need GENERAL_REGS. */ | |
8961 | return GENERAL_REGS; | |
8962 | } | |
8963 | \f | |
8964 | /* Given a comparison operation, return the bit number in CCR to test. We | |
8965 | know this is a valid comparison. | |
8966 | ||
8967 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
8968 | used instead of %C, so the bits will be in different places. | |
8969 | ||
b4ac57ab | 8970 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
8971 | |
8972 | int | |
a2369ed3 | 8973 | ccr_bit (rtx op, int scc_p) |
9878760c RK |
8974 | { |
8975 | enum rtx_code code = GET_CODE (op); | |
8976 | enum machine_mode cc_mode; | |
8977 | int cc_regnum; | |
8978 | int base_bit; | |
9ebbca7d | 8979 | rtx reg; |
9878760c | 8980 | |
ec8e098d | 8981 | if (!COMPARISON_P (op)) |
9878760c RK |
8982 | return -1; |
8983 | ||
9ebbca7d GK |
8984 | reg = XEXP (op, 0); |
8985 | ||
8986 | if (GET_CODE (reg) != REG | |
8987 | || ! CR_REGNO_P (REGNO (reg))) | |
8988 | abort (); | |
8989 | ||
8990 | cc_mode = GET_MODE (reg); | |
8991 | cc_regnum = REGNO (reg); | |
8992 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 8993 | |
39a10a29 | 8994 | validate_condition_mode (code, cc_mode); |
c5defebb | 8995 | |
b7053a3f GK |
8996 | /* When generating a sCOND operation, only positive conditions are |
8997 | allowed. */ | |
8998 | if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED | |
8999 | && code != GTU && code != LTU) | |
9000 | abort (); | |
9001 | ||
9878760c RK |
9002 | switch (code) |
9003 | { | |
9004 | case NE: | |
9005 | return scc_p ? base_bit + 3 : base_bit + 2; | |
9006 | case EQ: | |
9007 | return base_bit + 2; | |
1c882ea4 | 9008 | case GT: case GTU: case UNLE: |
9878760c | 9009 | return base_bit + 1; |
1c882ea4 | 9010 | case LT: case LTU: case UNGE: |
9878760c | 9011 | return base_bit; |
1c882ea4 GK |
9012 | case ORDERED: case UNORDERED: |
9013 | return base_bit + 3; | |
9878760c RK |
9014 | |
9015 | case GE: case GEU: | |
39a10a29 | 9016 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
9017 | unordered position. So test that bit. For integer, this is ! LT |
9018 | unless this is an scc insn. */ | |
39a10a29 | 9019 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
9020 | |
9021 | case LE: case LEU: | |
39a10a29 | 9022 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 9023 | |
9878760c RK |
9024 | default: |
9025 | abort (); | |
9026 | } | |
9027 | } | |
1ff7789b | 9028 | \f |
8d30c4ee | 9029 | /* Return the GOT register. */ |
1ff7789b MM |
9030 | |
9031 | struct rtx_def * | |
a2369ed3 | 9032 | rs6000_got_register (rtx value ATTRIBUTE_UNUSED) |
1ff7789b | 9033 | { |
a4f6c312 SS |
9034 | /* The second flow pass currently (June 1999) can't update |
9035 | regs_ever_live without disturbing other parts of the compiler, so | |
9036 | update it here to make the prolog/epilogue code happy. */ | |
1db02437 FS |
9037 | if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]) |
9038 | regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
1ff7789b | 9039 | |
8d30c4ee | 9040 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 9041 | |
1ff7789b MM |
9042 | return pic_offset_table_rtx; |
9043 | } | |
a7df97e6 | 9044 | \f |
e2500fed GK |
9045 | /* Function to init struct machine_function. |
9046 | This will be called, via a pointer variable, | |
9047 | from push_function_context. */ | |
a7df97e6 | 9048 | |
e2500fed | 9049 | static struct machine_function * |
863d938c | 9050 | rs6000_init_machine_status (void) |
a7df97e6 | 9051 | { |
e2500fed | 9052 | return ggc_alloc_cleared (sizeof (machine_function)); |
a7df97e6 | 9053 | } |
9878760c | 9054 | \f |
0ba1b2ff AM |
9055 | /* These macros test for integers and extract the low-order bits. */ |
9056 | #define INT_P(X) \ | |
9057 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
9058 | && GET_MODE (X) == VOIDmode) | |
9059 | ||
9060 | #define INT_LOWPART(X) \ | |
9061 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
9062 | ||
9063 | int | |
a2369ed3 | 9064 | extract_MB (rtx op) |
0ba1b2ff AM |
9065 | { |
9066 | int i; | |
9067 | unsigned long val = INT_LOWPART (op); | |
9068 | ||
9069 | /* If the high bit is zero, the value is the first 1 bit we find | |
9070 | from the left. */ | |
9071 | if ((val & 0x80000000) == 0) | |
9072 | { | |
9073 | if ((val & 0xffffffff) == 0) | |
9074 | abort (); | |
9075 | ||
9076 | i = 1; | |
9077 | while (((val <<= 1) & 0x80000000) == 0) | |
9078 | ++i; | |
9079 | return i; | |
9080 | } | |
9081 | ||
9082 | /* If the high bit is set and the low bit is not, or the mask is all | |
9083 | 1's, the value is zero. */ | |
9084 | if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff) | |
9085 | return 0; | |
9086 | ||
9087 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
9088 | from the right. */ | |
9089 | i = 31; | |
9090 | while (((val >>= 1) & 1) != 0) | |
9091 | --i; | |
9092 | ||
9093 | return i; | |
9094 | } | |
9095 | ||
9096 | int | |
a2369ed3 | 9097 | extract_ME (rtx op) |
0ba1b2ff AM |
9098 | { |
9099 | int i; | |
9100 | unsigned long val = INT_LOWPART (op); | |
9101 | ||
9102 | /* If the low bit is zero, the value is the first 1 bit we find from | |
9103 | the right. */ | |
9104 | if ((val & 1) == 0) | |
9105 | { | |
9106 | if ((val & 0xffffffff) == 0) | |
9107 | abort (); | |
9108 | ||
9109 | i = 30; | |
9110 | while (((val >>= 1) & 1) == 0) | |
9111 | --i; | |
9112 | ||
9113 | return i; | |
9114 | } | |
9115 | ||
9116 | /* If the low bit is set and the high bit is not, or the mask is all | |
9117 | 1's, the value is 31. */ | |
9118 | if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff) | |
9119 | return 31; | |
9120 | ||
9121 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
9122 | from the left. */ | |
9123 | i = 0; | |
9124 | while (((val <<= 1) & 0x80000000) != 0) | |
9125 | ++i; | |
9126 | ||
9127 | return i; | |
9128 | } | |
9129 | ||
c4501e62 JJ |
9130 | /* Locate some local-dynamic symbol still in use by this function |
9131 | so that we can print its name in some tls_ld pattern. */ | |
9132 | ||
9133 | static const char * | |
863d938c | 9134 | rs6000_get_some_local_dynamic_name (void) |
c4501e62 JJ |
9135 | { |
9136 | rtx insn; | |
9137 | ||
9138 | if (cfun->machine->some_ld_name) | |
9139 | return cfun->machine->some_ld_name; | |
9140 | ||
9141 | for (insn = get_insns (); insn ; insn = NEXT_INSN (insn)) | |
9142 | if (INSN_P (insn) | |
9143 | && for_each_rtx (&PATTERN (insn), | |
9144 | rs6000_get_some_local_dynamic_name_1, 0)) | |
9145 | return cfun->machine->some_ld_name; | |
9146 | ||
9147 | abort (); | |
9148 | } | |
9149 | ||
9150 | /* Helper function for rs6000_get_some_local_dynamic_name. */ | |
9151 | ||
9152 | static int | |
a2369ed3 | 9153 | rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
9154 | { |
9155 | rtx x = *px; | |
9156 | ||
9157 | if (GET_CODE (x) == SYMBOL_REF) | |
9158 | { | |
9159 | const char *str = XSTR (x, 0); | |
9160 | if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC) | |
9161 | { | |
9162 | cfun->machine->some_ld_name = str; | |
9163 | return 1; | |
9164 | } | |
9165 | } | |
9166 | ||
9167 | return 0; | |
9168 | } | |
9169 | ||
9878760c RK |
9170 | /* Print an operand. Recognize special options, documented below. */ |
9171 | ||
38c1f2d7 | 9172 | #if TARGET_ELF |
d9407988 | 9173 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 9174 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
9175 | #else |
9176 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 9177 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
9178 | #endif |
9179 | ||
9878760c | 9180 | void |
a2369ed3 | 9181 | print_operand (FILE *file, rtx x, int code) |
9878760c RK |
9182 | { |
9183 | int i; | |
a260abc9 | 9184 | HOST_WIDE_INT val; |
0ba1b2ff | 9185 | unsigned HOST_WIDE_INT uval; |
9878760c RK |
9186 | |
9187 | switch (code) | |
9188 | { | |
a8b3aeda | 9189 | case '.': |
a85d226b RK |
9190 | /* Write out an instruction after the call which may be replaced |
9191 | with glue code by the loader. This depends on the AIX version. */ | |
9192 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
9193 | return; |
9194 | ||
81eace42 GK |
9195 | /* %a is output_address. */ |
9196 | ||
9854d9ed RK |
9197 | case 'A': |
9198 | /* If X is a constant integer whose low-order 5 bits are zero, | |
9199 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 9200 | in the AIX assembler where "sri" with a zero shift count |
20e26713 | 9201 | writes a trash instruction. */ |
9854d9ed | 9202 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) |
76229ac8 | 9203 | putc ('l', file); |
9854d9ed | 9204 | else |
76229ac8 | 9205 | putc ('r', file); |
9854d9ed RK |
9206 | return; |
9207 | ||
9208 | case 'b': | |
e2c953b6 DE |
9209 | /* If constant, low-order 16 bits of constant, unsigned. |
9210 | Otherwise, write normally. */ | |
9211 | if (INT_P (x)) | |
9212 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
9213 | else | |
9214 | print_operand (file, x, 0); | |
cad12a8d RK |
9215 | return; |
9216 | ||
a260abc9 DE |
9217 | case 'B': |
9218 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
9219 | for 64-bit mask direction. */ | |
296b8152 | 9220 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 9221 | return; |
a260abc9 | 9222 | |
81eace42 GK |
9223 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
9224 | output_operand. */ | |
9225 | ||
423c1189 AH |
9226 | case 'c': |
9227 | /* X is a CR register. Print the number of the GT bit of the CR. */ | |
9228 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9229 | output_operand_lossage ("invalid %%E value"); | |
9230 | else | |
9231 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1); | |
9232 | return; | |
9233 | ||
9234 | case 'D': | |
9235 | /* Like 'J' but get to the GT bit. */ | |
9236 | if (GET_CODE (x) != REG) | |
9237 | abort (); | |
9238 | ||
9239 | /* Bit 1 is GT bit. */ | |
9240 | i = 4 * (REGNO (x) - CR0_REGNO) + 1; | |
9241 | ||
9242 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
9243 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9244 | return; | |
9245 | ||
9854d9ed | 9246 | case 'E': |
39a10a29 | 9247 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
9248 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
9249 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 9250 | else |
39a10a29 | 9251 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 9252 | return; |
9854d9ed RK |
9253 | |
9254 | case 'f': | |
9255 | /* X is a CR register. Print the shift count needed to move it | |
9256 | to the high-order four bits. */ | |
9257 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9258 | output_operand_lossage ("invalid %%f value"); | |
9259 | else | |
9ebbca7d | 9260 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
9261 | return; |
9262 | ||
9263 | case 'F': | |
9264 | /* Similar, but print the count for the rotate in the opposite | |
9265 | direction. */ | |
9266 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9267 | output_operand_lossage ("invalid %%F value"); | |
9268 | else | |
9ebbca7d | 9269 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
9270 | return; |
9271 | ||
9272 | case 'G': | |
9273 | /* X is a constant integer. If it is negative, print "m", | |
43aa4e05 | 9274 | otherwise print "z". This is to make an aze or ame insn. */ |
9854d9ed RK |
9275 | if (GET_CODE (x) != CONST_INT) |
9276 | output_operand_lossage ("invalid %%G value"); | |
9277 | else if (INTVAL (x) >= 0) | |
76229ac8 | 9278 | putc ('z', file); |
9854d9ed | 9279 | else |
76229ac8 | 9280 | putc ('m', file); |
9854d9ed | 9281 | return; |
e2c953b6 | 9282 | |
9878760c | 9283 | case 'h': |
a4f6c312 SS |
9284 | /* If constant, output low-order five bits. Otherwise, write |
9285 | normally. */ | |
9878760c | 9286 | if (INT_P (x)) |
5f59ecb7 | 9287 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
9288 | else |
9289 | print_operand (file, x, 0); | |
9290 | return; | |
9291 | ||
64305719 | 9292 | case 'H': |
a4f6c312 SS |
9293 | /* If constant, output low-order six bits. Otherwise, write |
9294 | normally. */ | |
64305719 | 9295 | if (INT_P (x)) |
5f59ecb7 | 9296 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
9297 | else |
9298 | print_operand (file, x, 0); | |
9299 | return; | |
9300 | ||
9854d9ed RK |
9301 | case 'I': |
9302 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 9303 | if (INT_P (x)) |
76229ac8 | 9304 | putc ('i', file); |
9878760c RK |
9305 | return; |
9306 | ||
9854d9ed RK |
9307 | case 'j': |
9308 | /* Write the bit number in CCR for jump. */ | |
9309 | i = ccr_bit (x, 0); | |
9310 | if (i == -1) | |
9311 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 9312 | else |
9854d9ed | 9313 | fprintf (file, "%d", i); |
9878760c RK |
9314 | return; |
9315 | ||
9854d9ed RK |
9316 | case 'J': |
9317 | /* Similar, but add one for shift count in rlinm for scc and pass | |
9318 | scc flag to `ccr_bit'. */ | |
9319 | i = ccr_bit (x, 1); | |
9320 | if (i == -1) | |
9321 | output_operand_lossage ("invalid %%J code"); | |
9322 | else | |
a0466a68 RK |
9323 | /* If we want bit 31, write a shift count of zero, not 32. */ |
9324 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
9325 | return; |
9326 | ||
9854d9ed RK |
9327 | case 'k': |
9328 | /* X must be a constant. Write the 1's complement of the | |
9329 | constant. */ | |
9878760c | 9330 | if (! INT_P (x)) |
9854d9ed | 9331 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
9332 | else |
9333 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
9334 | return; |
9335 | ||
81eace42 | 9336 | case 'K': |
9ebbca7d GK |
9337 | /* X must be a symbolic constant on ELF. Write an |
9338 | expression suitable for an 'addi' that adds in the low 16 | |
9339 | bits of the MEM. */ | |
9340 | if (GET_CODE (x) != CONST) | |
9341 | { | |
9342 | print_operand_address (file, x); | |
9343 | fputs ("@l", file); | |
9344 | } | |
9345 | else | |
9346 | { | |
9347 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
9348 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
9349 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
9350 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 9351 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
9352 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
9353 | fputs ("@l", file); | |
ed8d2920 MM |
9354 | /* For GNU as, there must be a non-alphanumeric character |
9355 | between 'l' and the number. The '-' is added by | |
9356 | print_operand() already. */ | |
9357 | if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0) | |
9358 | fputs ("+", file); | |
9ebbca7d GK |
9359 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); |
9360 | } | |
81eace42 GK |
9361 | return; |
9362 | ||
9363 | /* %l is output_asm_label. */ | |
9ebbca7d | 9364 | |
9854d9ed RK |
9365 | case 'L': |
9366 | /* Write second word of DImode or DFmode reference. Works on register | |
9367 | or non-indexed memory only. */ | |
9368 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9369 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); |
9854d9ed RK |
9370 | else if (GET_CODE (x) == MEM) |
9371 | { | |
9372 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 9373 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
9374 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
9375 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
ed8908e7 RK |
9376 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), |
9377 | UNITS_PER_WORD)); | |
9854d9ed | 9378 | else |
d7624dc0 RK |
9379 | output_address (XEXP (adjust_address_nv (x, SImode, |
9380 | UNITS_PER_WORD), | |
9381 | 0)); | |
ed8908e7 | 9382 | |
ba5e43aa | 9383 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9384 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9385 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 9386 | } |
9878760c | 9387 | return; |
9854d9ed | 9388 | |
9878760c RK |
9389 | case 'm': |
9390 | /* MB value for a mask operand. */ | |
b1765bde | 9391 | if (! mask_operand (x, SImode)) |
9878760c RK |
9392 | output_operand_lossage ("invalid %%m value"); |
9393 | ||
0ba1b2ff | 9394 | fprintf (file, "%d", extract_MB (x)); |
9878760c RK |
9395 | return; |
9396 | ||
9397 | case 'M': | |
9398 | /* ME value for a mask operand. */ | |
b1765bde | 9399 | if (! mask_operand (x, SImode)) |
a260abc9 | 9400 | output_operand_lossage ("invalid %%M value"); |
9878760c | 9401 | |
0ba1b2ff | 9402 | fprintf (file, "%d", extract_ME (x)); |
9878760c RK |
9403 | return; |
9404 | ||
81eace42 GK |
9405 | /* %n outputs the negative of its operand. */ |
9406 | ||
9878760c RK |
9407 | case 'N': |
9408 | /* Write the number of elements in the vector times 4. */ | |
9409 | if (GET_CODE (x) != PARALLEL) | |
9410 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
9411 | else |
9412 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
9413 | return; |
9414 | ||
9415 | case 'O': | |
9416 | /* Similar, but subtract 1 first. */ | |
9417 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 9418 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
9419 | else |
9420 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
9421 | return; |
9422 | ||
9854d9ed RK |
9423 | case 'p': |
9424 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
9425 | if (! INT_P (x) | |
2bfcf297 | 9426 | || INT_LOWPART (x) < 0 |
9854d9ed RK |
9427 | || (i = exact_log2 (INT_LOWPART (x))) < 0) |
9428 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
9429 | else |
9430 | fprintf (file, "%d", i); | |
9854d9ed RK |
9431 | return; |
9432 | ||
9878760c RK |
9433 | case 'P': |
9434 | /* The operand must be an indirect memory reference. The result | |
8bb418a3 | 9435 | is the register name. */ |
9878760c RK |
9436 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG |
9437 | || REGNO (XEXP (x, 0)) >= 32) | |
9438 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 | 9439 | else |
8bb418a3 | 9440 | fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]); |
9878760c RK |
9441 | return; |
9442 | ||
dfbdccdb GK |
9443 | case 'q': |
9444 | /* This outputs the logical code corresponding to a boolean | |
9445 | expression. The expression may have one or both operands | |
39a10a29 GK |
9446 | negated (if one, only the first one). For condition register |
9447 | logical operations, it will also treat the negated | |
9448 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 9449 | { |
63bc1d05 | 9450 | const char *const *t = 0; |
dfbdccdb GK |
9451 | const char *s; |
9452 | enum rtx_code code = GET_CODE (x); | |
9453 | static const char * const tbl[3][3] = { | |
9454 | { "and", "andc", "nor" }, | |
9455 | { "or", "orc", "nand" }, | |
9456 | { "xor", "eqv", "xor" } }; | |
9457 | ||
9458 | if (code == AND) | |
9459 | t = tbl[0]; | |
9460 | else if (code == IOR) | |
9461 | t = tbl[1]; | |
9462 | else if (code == XOR) | |
9463 | t = tbl[2]; | |
9464 | else | |
9465 | output_operand_lossage ("invalid %%q value"); | |
9466 | ||
9467 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
9468 | s = t[0]; | |
9469 | else | |
9470 | { | |
9471 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
9472 | s = t[2]; | |
9473 | else | |
9474 | s = t[1]; | |
9475 | } | |
9476 | ||
9477 | fputs (s, file); | |
9478 | } | |
9479 | return; | |
9480 | ||
2c4a9cff DE |
9481 | case 'Q': |
9482 | if (TARGET_MFCRF) | |
3b6ce0af | 9483 | fputc (',', file); |
5efb1046 | 9484 | /* FALLTHRU */ |
2c4a9cff DE |
9485 | else |
9486 | return; | |
9487 | ||
9854d9ed RK |
9488 | case 'R': |
9489 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
9490 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
9491 | output_operand_lossage ("invalid %%R value"); | |
9492 | else | |
9ebbca7d | 9493 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 9494 | return; |
9854d9ed RK |
9495 | |
9496 | case 's': | |
9497 | /* Low 5 bits of 32 - value */ | |
9498 | if (! INT_P (x)) | |
9499 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
9500 | else |
9501 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 9502 | return; |
9854d9ed | 9503 | |
a260abc9 | 9504 | case 'S': |
0ba1b2ff | 9505 | /* PowerPC64 mask position. All 0's is excluded. |
a260abc9 DE |
9506 | CONST_INT 32-bit mask is considered sign-extended so any |
9507 | transition must occur within the CONST_INT, not on the boundary. */ | |
b1765bde | 9508 | if (! mask64_operand (x, DImode)) |
a260abc9 DE |
9509 | output_operand_lossage ("invalid %%S value"); |
9510 | ||
0ba1b2ff | 9511 | uval = INT_LOWPART (x); |
a260abc9 | 9512 | |
0ba1b2ff | 9513 | if (uval & 1) /* Clear Left */ |
a260abc9 | 9514 | { |
f099d360 GK |
9515 | #if HOST_BITS_PER_WIDE_INT > 64 |
9516 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
9517 | #endif | |
0ba1b2ff | 9518 | i = 64; |
a260abc9 | 9519 | } |
0ba1b2ff | 9520 | else /* Clear Right */ |
a260abc9 | 9521 | { |
0ba1b2ff | 9522 | uval = ~uval; |
f099d360 GK |
9523 | #if HOST_BITS_PER_WIDE_INT > 64 |
9524 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
9525 | #endif | |
0ba1b2ff | 9526 | i = 63; |
a260abc9 | 9527 | } |
0ba1b2ff AM |
9528 | while (uval != 0) |
9529 | --i, uval >>= 1; | |
9530 | if (i < 0) | |
9531 | abort (); | |
9532 | fprintf (file, "%d", i); | |
9533 | return; | |
a260abc9 | 9534 | |
a3170dc6 AH |
9535 | case 't': |
9536 | /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */ | |
9537 | if (GET_CODE (x) != REG || GET_MODE (x) != CCmode) | |
9538 | abort (); | |
9539 | ||
9540 | /* Bit 3 is OV bit. */ | |
9541 | i = 4 * (REGNO (x) - CR0_REGNO) + 3; | |
9542 | ||
9543 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
9544 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9545 | return; | |
9546 | ||
cccf3bdc DE |
9547 | case 'T': |
9548 | /* Print the symbolic name of a branch target register. */ | |
9549 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
9550 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
9551 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 9552 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
9553 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
9554 | else | |
9555 | fputs ("ctr", file); | |
9556 | return; | |
9557 | ||
9854d9ed | 9558 | case 'u': |
802a0058 | 9559 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
9560 | if (! INT_P (x)) |
9561 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 DE |
9562 | else |
9563 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, | |
9564 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9878760c RK |
9565 | return; |
9566 | ||
802a0058 MM |
9567 | case 'v': |
9568 | /* High-order 16 bits of constant for use in signed operand. */ | |
9569 | if (! INT_P (x)) | |
9570 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 | 9571 | else |
134c32f6 DE |
9572 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
9573 | (INT_LOWPART (x) >> 16) & 0xffff); | |
9574 | return; | |
802a0058 | 9575 | |
9854d9ed RK |
9576 | case 'U': |
9577 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
9578 | if (GET_CODE (x) == MEM | |
9579 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
9580 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 9581 | putc ('u', file); |
9854d9ed | 9582 | return; |
9878760c | 9583 | |
e0cd0770 JC |
9584 | case 'V': |
9585 | /* Print the trap code for this operand. */ | |
9586 | switch (GET_CODE (x)) | |
9587 | { | |
9588 | case EQ: | |
9589 | fputs ("eq", file); /* 4 */ | |
9590 | break; | |
9591 | case NE: | |
9592 | fputs ("ne", file); /* 24 */ | |
9593 | break; | |
9594 | case LT: | |
9595 | fputs ("lt", file); /* 16 */ | |
9596 | break; | |
9597 | case LE: | |
9598 | fputs ("le", file); /* 20 */ | |
9599 | break; | |
9600 | case GT: | |
9601 | fputs ("gt", file); /* 8 */ | |
9602 | break; | |
9603 | case GE: | |
9604 | fputs ("ge", file); /* 12 */ | |
9605 | break; | |
9606 | case LTU: | |
9607 | fputs ("llt", file); /* 2 */ | |
9608 | break; | |
9609 | case LEU: | |
9610 | fputs ("lle", file); /* 6 */ | |
9611 | break; | |
9612 | case GTU: | |
9613 | fputs ("lgt", file); /* 1 */ | |
9614 | break; | |
9615 | case GEU: | |
9616 | fputs ("lge", file); /* 5 */ | |
9617 | break; | |
9618 | default: | |
9619 | abort (); | |
9620 | } | |
9621 | break; | |
9622 | ||
9854d9ed RK |
9623 | case 'w': |
9624 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
9625 | normally. */ | |
9626 | if (INT_P (x)) | |
5f59ecb7 DE |
9627 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
9628 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); | |
9854d9ed RK |
9629 | else |
9630 | print_operand (file, x, 0); | |
9878760c RK |
9631 | return; |
9632 | ||
9854d9ed | 9633 | case 'W': |
e2c953b6 | 9634 | /* MB value for a PowerPC64 rldic operand. */ |
e2c953b6 DE |
9635 | val = (GET_CODE (x) == CONST_INT |
9636 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
9637 | ||
9638 | if (val < 0) | |
9639 | i = -1; | |
9854d9ed | 9640 | else |
e2c953b6 DE |
9641 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
9642 | if ((val <<= 1) < 0) | |
9643 | break; | |
9644 | ||
9645 | #if HOST_BITS_PER_WIDE_INT == 32 | |
9646 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
9647 | i += 32; /* zero-extend high-part was all 0's */ | |
9648 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
9649 | { | |
9650 | val = CONST_DOUBLE_LOW (x); | |
9651 | ||
9652 | if (val == 0) | |
a4f6c312 | 9653 | abort (); |
e2c953b6 DE |
9654 | else if (val < 0) |
9655 | --i; | |
9656 | else | |
9657 | for ( ; i < 64; i++) | |
9658 | if ((val <<= 1) < 0) | |
9659 | break; | |
9660 | } | |
9661 | #endif | |
9662 | ||
9663 | fprintf (file, "%d", i + 1); | |
9854d9ed | 9664 | return; |
9878760c | 9665 | |
9854d9ed RK |
9666 | case 'X': |
9667 | if (GET_CODE (x) == MEM | |
4d588c14 | 9668 | && legitimate_indexed_address_p (XEXP (x, 0), 0)) |
76229ac8 | 9669 | putc ('x', file); |
9854d9ed | 9670 | return; |
9878760c | 9671 | |
9854d9ed RK |
9672 | case 'Y': |
9673 | /* Like 'L', for third word of TImode */ | |
9674 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9675 | fprintf (file, "%s", reg_names[REGNO (x) + 2]); |
9854d9ed | 9676 | else if (GET_CODE (x) == MEM) |
9878760c | 9677 | { |
9854d9ed RK |
9678 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
9679 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 9680 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 9681 | else |
d7624dc0 | 9682 | output_address (XEXP (adjust_address_nv (x, SImode, 8), 0)); |
ba5e43aa | 9683 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9684 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9685 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
9686 | } |
9687 | return; | |
9854d9ed | 9688 | |
9878760c | 9689 | case 'z': |
b4ac57ab RS |
9690 | /* X is a SYMBOL_REF. Write out the name preceded by a |
9691 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
9692 | names. If we are configured for System V (or the embedded ABI) on |
9693 | the PowerPC, do not emit the period, since those systems do not use | |
9694 | TOCs and the like. */ | |
9878760c RK |
9695 | if (GET_CODE (x) != SYMBOL_REF) |
9696 | abort (); | |
9697 | ||
9bf6462a AP |
9698 | /* Mark the decl as referenced so that cgraph will output the function. */ |
9699 | if (SYMBOL_REF_DECL (x)) | |
9700 | mark_decl_referenced (SYMBOL_REF_DECL (x)); | |
9701 | ||
b6c9286a MM |
9702 | if (XSTR (x, 0)[0] != '.') |
9703 | { | |
9704 | switch (DEFAULT_ABI) | |
9705 | { | |
9706 | default: | |
9707 | abort (); | |
9708 | ||
9709 | case ABI_AIX: | |
9710 | putc ('.', file); | |
9711 | break; | |
9712 | ||
9713 | case ABI_V4: | |
ee890fe2 | 9714 | case ABI_DARWIN: |
b6c9286a | 9715 | break; |
b6c9286a MM |
9716 | } |
9717 | } | |
f9da97f0 AP |
9718 | /* For macho, we need to check it see if we need a stub. */ |
9719 | if (TARGET_MACHO) | |
9720 | { | |
9721 | const char *name = XSTR (x, 0); | |
a031e781 | 9722 | #if TARGET_MACHO |
3b48085e AP |
9723 | if (MACHOPIC_INDIRECT |
9724 | && machopic_classify_name (name) == MACHOPIC_UNDEFINED_FUNCTION) | |
f9da97f0 AP |
9725 | name = machopic_stub_name (name); |
9726 | #endif | |
9727 | assemble_name (file, name); | |
9728 | } | |
9729 | else if (TARGET_AIX) | |
9739c90c JJ |
9730 | RS6000_OUTPUT_BASENAME (file, XSTR (x, 0)); |
9731 | else | |
9732 | assemble_name (file, XSTR (x, 0)); | |
9878760c RK |
9733 | return; |
9734 | ||
9854d9ed RK |
9735 | case 'Z': |
9736 | /* Like 'L', for last word of TImode. */ | |
9737 | if (GET_CODE (x) == REG) | |
5ebfb2ba | 9738 | fprintf (file, "%s", reg_names[REGNO (x) + 3]); |
9854d9ed RK |
9739 | else if (GET_CODE (x) == MEM) |
9740 | { | |
9741 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
9742 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 9743 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 9744 | else |
d7624dc0 | 9745 | output_address (XEXP (adjust_address_nv (x, SImode, 12), 0)); |
ba5e43aa | 9746 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9747 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9748 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 9749 | } |
5c23c401 | 9750 | return; |
0ac081f6 | 9751 | |
a3170dc6 | 9752 | /* Print AltiVec or SPE memory operand. */ |
0ac081f6 AH |
9753 | case 'y': |
9754 | { | |
9755 | rtx tmp; | |
9756 | ||
9757 | if (GET_CODE (x) != MEM) | |
9758 | abort (); | |
9759 | ||
9760 | tmp = XEXP (x, 0); | |
9761 | ||
993f19a8 | 9762 | if (TARGET_E500) |
a3170dc6 AH |
9763 | { |
9764 | /* Handle [reg]. */ | |
9765 | if (GET_CODE (tmp) == REG) | |
9766 | { | |
9767 | fprintf (file, "0(%s)", reg_names[REGNO (tmp)]); | |
9768 | break; | |
9769 | } | |
9770 | /* Handle [reg+UIMM]. */ | |
9771 | else if (GET_CODE (tmp) == PLUS && | |
9772 | GET_CODE (XEXP (tmp, 1)) == CONST_INT) | |
9773 | { | |
9774 | int x; | |
9775 | ||
9776 | if (GET_CODE (XEXP (tmp, 0)) != REG) | |
9777 | abort (); | |
9778 | ||
9779 | x = INTVAL (XEXP (tmp, 1)); | |
9780 | fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]); | |
9781 | break; | |
9782 | } | |
9783 | ||
9784 | /* Fall through. Must be [reg+reg]. */ | |
9785 | } | |
0ac081f6 | 9786 | if (GET_CODE (tmp) == REG) |
c62f2db5 | 9787 | fprintf (file, "0,%s", reg_names[REGNO (tmp)]); |
0ac081f6 AH |
9788 | else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG) |
9789 | { | |
9790 | if (REGNO (XEXP (tmp, 0)) == 0) | |
9791 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ], | |
9792 | reg_names[ REGNO (XEXP (tmp, 0)) ]); | |
9793 | else | |
9794 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ], | |
9795 | reg_names[ REGNO (XEXP (tmp, 1)) ]); | |
9796 | } | |
9797 | else | |
9798 | abort (); | |
9799 | break; | |
9800 | } | |
9854d9ed | 9801 | |
9878760c RK |
9802 | case 0: |
9803 | if (GET_CODE (x) == REG) | |
9804 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
9805 | else if (GET_CODE (x) == MEM) | |
9806 | { | |
9807 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
9808 | know the width from the mode. */ | |
9809 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
9810 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
9811 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 9812 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
9813 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
9814 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 9815 | else |
a54d04b7 | 9816 | output_address (XEXP (x, 0)); |
9878760c RK |
9817 | } |
9818 | else | |
a54d04b7 | 9819 | output_addr_const (file, x); |
a85d226b | 9820 | return; |
9878760c | 9821 | |
c4501e62 JJ |
9822 | case '&': |
9823 | assemble_name (file, rs6000_get_some_local_dynamic_name ()); | |
9824 | return; | |
9825 | ||
9878760c RK |
9826 | default: |
9827 | output_operand_lossage ("invalid %%xn code"); | |
9828 | } | |
9829 | } | |
9830 | \f | |
9831 | /* Print the address of an operand. */ | |
9832 | ||
9833 | void | |
a2369ed3 | 9834 | print_operand_address (FILE *file, rtx x) |
9878760c RK |
9835 | { |
9836 | if (GET_CODE (x) == REG) | |
4697a36c | 9837 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
9838 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
9839 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
9840 | { |
9841 | output_addr_const (file, x); | |
ba5e43aa | 9842 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
9843 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
9844 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d | 9845 | else if (TARGET_TOC) |
a4f6c312 | 9846 | abort (); |
9878760c RK |
9847 | } |
9848 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
9849 | { | |
9850 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
9851 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
9852 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 9853 | else |
4697a36c MM |
9854 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
9855 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
9856 | } |
9857 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
4a0a75dd KG |
9858 | fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)", |
9859 | INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]); | |
3cb999d8 DE |
9860 | #if TARGET_ELF |
9861 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
9862 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
9863 | { |
9864 | output_addr_const (file, XEXP (x, 1)); | |
9865 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
9866 | } | |
c859cda6 DJ |
9867 | #endif |
9868 | #if TARGET_MACHO | |
9869 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
9870 | && CONSTANT_P (XEXP (x, 1))) | |
9871 | { | |
9872 | fprintf (file, "lo16("); | |
9873 | output_addr_const (file, XEXP (x, 1)); | |
9874 | fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
9875 | } | |
3cb999d8 | 9876 | #endif |
4d588c14 | 9877 | else if (legitimate_constant_pool_address_p (x)) |
9ebbca7d | 9878 | { |
2bfcf297 | 9879 | if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC)) |
9ebbca7d | 9880 | { |
2bfcf297 DB |
9881 | rtx contains_minus = XEXP (x, 1); |
9882 | rtx minus, symref; | |
9883 | const char *name; | |
9ebbca7d GK |
9884 | |
9885 | /* Find the (minus (sym) (toc)) buried in X, and temporarily | |
a4f6c312 | 9886 | turn it into (sym) for output_addr_const. */ |
9ebbca7d GK |
9887 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) |
9888 | contains_minus = XEXP (contains_minus, 0); | |
9889 | ||
2bfcf297 DB |
9890 | minus = XEXP (contains_minus, 0); |
9891 | symref = XEXP (minus, 0); | |
9892 | XEXP (contains_minus, 0) = symref; | |
9893 | if (TARGET_ELF) | |
9894 | { | |
9895 | char *newname; | |
9896 | ||
9897 | name = XSTR (symref, 0); | |
9898 | newname = alloca (strlen (name) + sizeof ("@toc")); | |
9899 | strcpy (newname, name); | |
9900 | strcat (newname, "@toc"); | |
9901 | XSTR (symref, 0) = newname; | |
9902 | } | |
9903 | output_addr_const (file, XEXP (x, 1)); | |
9904 | if (TARGET_ELF) | |
9905 | XSTR (symref, 0) = name; | |
9ebbca7d GK |
9906 | XEXP (contains_minus, 0) = minus; |
9907 | } | |
9908 | else | |
9909 | output_addr_const (file, XEXP (x, 1)); | |
9910 | ||
9911 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
9912 | } | |
9878760c RK |
9913 | else |
9914 | abort (); | |
9915 | } | |
9916 | \f | |
88cad84b | 9917 | /* Target hook for assembling integer objects. The PowerPC version has |
301d03af RS |
9918 | to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP |
9919 | is defined. It also needs to handle DI-mode objects on 64-bit | |
9920 | targets. */ | |
9921 | ||
9922 | static bool | |
a2369ed3 | 9923 | rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p) |
301d03af RS |
9924 | { |
9925 | #ifdef RELOCATABLE_NEEDS_FIXUP | |
9926 | /* Special handling for SI values. */ | |
9927 | if (size == 4 && aligned_p) | |
9928 | { | |
a2369ed3 | 9929 | extern int in_toc_section (void); |
301d03af RS |
9930 | static int recurse = 0; |
9931 | ||
9932 | /* For -mrelocatable, we mark all addresses that need to be fixed up | |
9933 | in the .fixup section. */ | |
9934 | if (TARGET_RELOCATABLE | |
9935 | && !in_toc_section () | |
9936 | && !in_text_section () | |
642af3be | 9937 | && !in_unlikely_text_section () |
301d03af RS |
9938 | && !recurse |
9939 | && GET_CODE (x) != CONST_INT | |
9940 | && GET_CODE (x) != CONST_DOUBLE | |
9941 | && CONSTANT_P (x)) | |
9942 | { | |
9943 | char buf[256]; | |
9944 | ||
9945 | recurse = 1; | |
9946 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno); | |
9947 | fixuplabelno++; | |
9948 | ASM_OUTPUT_LABEL (asm_out_file, buf); | |
9949 | fprintf (asm_out_file, "\t.long\t("); | |
9950 | output_addr_const (asm_out_file, x); | |
9951 | fprintf (asm_out_file, ")@fixup\n"); | |
9952 | fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n"); | |
9953 | ASM_OUTPUT_ALIGN (asm_out_file, 2); | |
9954 | fprintf (asm_out_file, "\t.long\t"); | |
9955 | assemble_name (asm_out_file, buf); | |
9956 | fprintf (asm_out_file, "\n\t.previous\n"); | |
9957 | recurse = 0; | |
9958 | return true; | |
9959 | } | |
9960 | /* Remove initial .'s to turn a -mcall-aixdesc function | |
9961 | address into the address of the descriptor, not the function | |
9962 | itself. */ | |
9963 | else if (GET_CODE (x) == SYMBOL_REF | |
9964 | && XSTR (x, 0)[0] == '.' | |
9965 | && DEFAULT_ABI == ABI_AIX) | |
9966 | { | |
9967 | const char *name = XSTR (x, 0); | |
9968 | while (*name == '.') | |
9969 | name++; | |
9970 | ||
9971 | fprintf (asm_out_file, "\t.long\t%s\n", name); | |
9972 | return true; | |
9973 | } | |
9974 | } | |
9975 | #endif /* RELOCATABLE_NEEDS_FIXUP */ | |
9976 | return default_assemble_integer (x, size, aligned_p); | |
9977 | } | |
93638d7a AM |
9978 | |
9979 | #ifdef HAVE_GAS_HIDDEN | |
9980 | /* Emit an assembler directive to set symbol visibility for DECL to | |
9981 | VISIBILITY_TYPE. */ | |
9982 | ||
5add3202 | 9983 | static void |
a2369ed3 | 9984 | rs6000_assemble_visibility (tree decl, int vis) |
93638d7a | 9985 | { |
93638d7a AM |
9986 | /* Functions need to have their entry point symbol visibility set as |
9987 | well as their descriptor symbol visibility. */ | |
9988 | if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL) | |
9989 | { | |
25fdb4dc RH |
9990 | static const char * const visibility_types[] = { |
9991 | NULL, "internal", "hidden", "protected" | |
9992 | }; | |
9993 | ||
9994 | const char *name, *type; | |
93638d7a AM |
9995 | |
9996 | name = ((* targetm.strip_name_encoding) | |
9997 | (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)))); | |
25fdb4dc | 9998 | type = visibility_types[vis]; |
93638d7a | 9999 | |
25fdb4dc RH |
10000 | fprintf (asm_out_file, "\t.%s\t%s\n", type, name); |
10001 | fprintf (asm_out_file, "\t.%s\t.%s\n", type, name); | |
93638d7a | 10002 | } |
25fdb4dc RH |
10003 | else |
10004 | default_assemble_visibility (decl, vis); | |
93638d7a AM |
10005 | } |
10006 | #endif | |
301d03af | 10007 | \f |
39a10a29 | 10008 | enum rtx_code |
a2369ed3 | 10009 | rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code) |
39a10a29 GK |
10010 | { |
10011 | /* Reversal of FP compares takes care -- an ordered compare | |
10012 | becomes an unordered compare and vice versa. */ | |
bc9ec0e0 GK |
10013 | if (mode == CCFPmode |
10014 | && (!flag_finite_math_only | |
10015 | || code == UNLT || code == UNLE || code == UNGT || code == UNGE | |
10016 | || code == UNEQ || code == LTGT)) | |
bab6226b | 10017 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 10018 | else |
bab6226b | 10019 | return reverse_condition (code); |
39a10a29 GK |
10020 | } |
10021 | ||
39a10a29 GK |
10022 | /* Generate a compare for CODE. Return a brand-new rtx that |
10023 | represents the result of the compare. */ | |
a4f6c312 | 10024 | |
39a10a29 | 10025 | static rtx |
a2369ed3 | 10026 | rs6000_generate_compare (enum rtx_code code) |
39a10a29 GK |
10027 | { |
10028 | enum machine_mode comp_mode; | |
10029 | rtx compare_result; | |
10030 | ||
10031 | if (rs6000_compare_fp_p) | |
10032 | comp_mode = CCFPmode; | |
10033 | else if (code == GTU || code == LTU | |
10034 | || code == GEU || code == LEU) | |
10035 | comp_mode = CCUNSmode; | |
10036 | else | |
10037 | comp_mode = CCmode; | |
10038 | ||
10039 | /* First, the compare. */ | |
10040 | compare_result = gen_reg_rtx (comp_mode); | |
a3170dc6 AH |
10041 | |
10042 | /* SPE FP compare instructions on the GPRs. Yuck! */ | |
993f19a8 AH |
10043 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) |
10044 | && rs6000_compare_fp_p) | |
a3170dc6 AH |
10045 | { |
10046 | rtx cmp, or1, or2, or_result, compare_result2; | |
10047 | ||
423c1189 AH |
10048 | /* Note: The E500 comparison instructions set the GT bit (x + |
10049 | 1), on success. This explains the mess. */ | |
10050 | ||
a3170dc6 AH |
10051 | switch (code) |
10052 | { | |
423c1189 | 10053 | case EQ: case UNEQ: case NE: case LTGT: |
bc9ec0e0 | 10054 | cmp = flag_finite_math_only |
a3170dc6 AH |
10055 | ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0, |
10056 | rs6000_compare_op1) | |
10057 | : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0, | |
10058 | rs6000_compare_op1); | |
10059 | break; | |
423c1189 | 10060 | case GT: case GTU: case UNGT: case UNGE: case GE: case GEU: |
bc9ec0e0 | 10061 | cmp = flag_finite_math_only |
a3170dc6 AH |
10062 | ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0, |
10063 | rs6000_compare_op1) | |
10064 | : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0, | |
10065 | rs6000_compare_op1); | |
10066 | break; | |
423c1189 | 10067 | case LT: case LTU: case UNLT: case UNLE: case LE: case LEU: |
bc9ec0e0 | 10068 | cmp = flag_finite_math_only |
a3170dc6 AH |
10069 | ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0, |
10070 | rs6000_compare_op1) | |
10071 | : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0, | |
10072 | rs6000_compare_op1); | |
10073 | break; | |
10074 | default: | |
10075 | abort (); | |
10076 | } | |
10077 | ||
10078 | /* Synthesize LE and GE from LT/GT || EQ. */ | |
10079 | if (code == LE || code == GE || code == LEU || code == GEU) | |
10080 | { | |
a3170dc6 AH |
10081 | emit_insn (cmp); |
10082 | ||
10083 | switch (code) | |
10084 | { | |
10085 | case LE: code = LT; break; | |
10086 | case GE: code = GT; break; | |
10087 | case LEU: code = LT; break; | |
10088 | case GEU: code = GT; break; | |
10089 | default: abort (); | |
10090 | } | |
10091 | ||
10092 | or1 = gen_reg_rtx (SImode); | |
10093 | or2 = gen_reg_rtx (SImode); | |
10094 | or_result = gen_reg_rtx (CCEQmode); | |
10095 | compare_result2 = gen_reg_rtx (CCFPmode); | |
10096 | ||
10097 | /* Do the EQ. */ | |
bc9ec0e0 | 10098 | cmp = flag_finite_math_only |
a3170dc6 AH |
10099 | ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0, |
10100 | rs6000_compare_op1) | |
10101 | : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0, | |
10102 | rs6000_compare_op1); | |
10103 | emit_insn (cmp); | |
10104 | ||
423c1189 AH |
10105 | or1 = gen_rtx_GT (SImode, compare_result, const0_rtx); |
10106 | or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx); | |
a3170dc6 AH |
10107 | |
10108 | /* OR them together. */ | |
10109 | cmp = gen_rtx_SET (VOIDmode, or_result, | |
10110 | gen_rtx_COMPARE (CCEQmode, | |
10111 | gen_rtx_IOR (SImode, or1, or2), | |
10112 | const_true_rtx)); | |
10113 | compare_result = or_result; | |
10114 | code = EQ; | |
10115 | } | |
10116 | else | |
10117 | { | |
a3170dc6 | 10118 | if (code == NE || code == LTGT) |
a3170dc6 | 10119 | code = NE; |
423c1189 AH |
10120 | else |
10121 | code = EQ; | |
a3170dc6 AH |
10122 | } |
10123 | ||
10124 | emit_insn (cmp); | |
10125 | } | |
10126 | else | |
10127 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
10128 | gen_rtx_COMPARE (comp_mode, | |
10129 | rs6000_compare_op0, | |
10130 | rs6000_compare_op1))); | |
39a10a29 | 10131 | |
ca5adc63 | 10132 | /* Some kinds of FP comparisons need an OR operation; |
bc9ec0e0 | 10133 | under flag_finite_math_only we don't bother. */ |
39a10a29 | 10134 | if (rs6000_compare_fp_p |
bc9ec0e0 | 10135 | && ! flag_finite_math_only |
993f19a8 | 10136 | && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS) |
39a10a29 GK |
10137 | && (code == LE || code == GE |
10138 | || code == UNEQ || code == LTGT | |
10139 | || code == UNGT || code == UNLT)) | |
10140 | { | |
10141 | enum rtx_code or1, or2; | |
10142 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
10143 | rtx or_result = gen_reg_rtx (CCEQmode); | |
10144 | ||
10145 | switch (code) | |
10146 | { | |
10147 | case LE: or1 = LT; or2 = EQ; break; | |
10148 | case GE: or1 = GT; or2 = EQ; break; | |
10149 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
10150 | case LTGT: or1 = LT; or2 = GT; break; | |
10151 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
10152 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
10153 | default: abort (); | |
10154 | } | |
10155 | validate_condition_mode (or1, comp_mode); | |
10156 | validate_condition_mode (or2, comp_mode); | |
1c563bed KH |
10157 | or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx); |
10158 | or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx); | |
39a10a29 GK |
10159 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, |
10160 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
10161 | const_true_rtx); | |
10162 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
10163 | ||
10164 | compare_result = or_result; | |
10165 | code = EQ; | |
10166 | } | |
10167 | ||
10168 | validate_condition_mode (code, GET_MODE (compare_result)); | |
10169 | ||
1c563bed | 10170 | return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx); |
39a10a29 GK |
10171 | } |
10172 | ||
10173 | ||
10174 | /* Emit the RTL for an sCOND pattern. */ | |
10175 | ||
10176 | void | |
a2369ed3 | 10177 | rs6000_emit_sCOND (enum rtx_code code, rtx result) |
39a10a29 GK |
10178 | { |
10179 | rtx condition_rtx; | |
10180 | enum machine_mode op_mode; | |
b7053a3f | 10181 | enum rtx_code cond_code; |
39a10a29 GK |
10182 | |
10183 | condition_rtx = rs6000_generate_compare (code); | |
b7053a3f GK |
10184 | cond_code = GET_CODE (condition_rtx); |
10185 | ||
423c1189 AH |
10186 | if (TARGET_E500 && rs6000_compare_fp_p |
10187 | && !TARGET_FPRS && TARGET_HARD_FLOAT) | |
10188 | { | |
10189 | rtx t; | |
10190 | ||
10191 | PUT_MODE (condition_rtx, SImode); | |
10192 | t = XEXP (condition_rtx, 0); | |
10193 | ||
10194 | if (cond_code != NE && cond_code != EQ) | |
10195 | abort (); | |
10196 | ||
10197 | if (cond_code == NE) | |
10198 | emit_insn (gen_e500_flip_gt_bit (t, t)); | |
10199 | ||
10200 | emit_insn (gen_move_from_CR_gt_bit (result, t)); | |
10201 | return; | |
10202 | } | |
10203 | ||
b7053a3f GK |
10204 | if (cond_code == NE |
10205 | || cond_code == GE || cond_code == LE | |
10206 | || cond_code == GEU || cond_code == LEU | |
10207 | || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE) | |
10208 | { | |
10209 | rtx not_result = gen_reg_rtx (CCEQmode); | |
10210 | rtx not_op, rev_cond_rtx; | |
10211 | enum machine_mode cc_mode; | |
10212 | ||
10213 | cc_mode = GET_MODE (XEXP (condition_rtx, 0)); | |
10214 | ||
1c563bed | 10215 | rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code), |
0f4c242b | 10216 | SImode, XEXP (condition_rtx, 0), const0_rtx); |
b7053a3f GK |
10217 | not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx); |
10218 | emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op)); | |
10219 | condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx); | |
10220 | } | |
39a10a29 GK |
10221 | |
10222 | op_mode = GET_MODE (rs6000_compare_op0); | |
10223 | if (op_mode == VOIDmode) | |
10224 | op_mode = GET_MODE (rs6000_compare_op1); | |
10225 | ||
10226 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
10227 | { | |
10228 | PUT_MODE (condition_rtx, DImode); | |
10229 | convert_move (result, condition_rtx, 0); | |
10230 | } | |
10231 | else | |
10232 | { | |
10233 | PUT_MODE (condition_rtx, SImode); | |
10234 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
10235 | } | |
10236 | } | |
10237 | ||
39a10a29 GK |
10238 | /* Emit a branch of kind CODE to location LOC. */ |
10239 | ||
10240 | void | |
a2369ed3 | 10241 | rs6000_emit_cbranch (enum rtx_code code, rtx loc) |
39a10a29 GK |
10242 | { |
10243 | rtx condition_rtx, loc_ref; | |
10244 | ||
10245 | condition_rtx = rs6000_generate_compare (code); | |
10246 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
10247 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
10248 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
10249 | loc_ref, pc_rtx))); | |
10250 | } | |
10251 | ||
12a4e8c5 GK |
10252 | /* Return the string to output a conditional branch to LABEL, which is |
10253 | the operand number of the label, or -1 if the branch is really a | |
10254 | conditional return. | |
10255 | ||
10256 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
10257 | condition code register and its mode specifies what kind of | |
10258 | comparison we made. | |
10259 | ||
a0ab749a | 10260 | REVERSED is nonzero if we should reverse the sense of the comparison. |
12a4e8c5 GK |
10261 | |
10262 | INSN is the insn. */ | |
10263 | ||
10264 | char * | |
a2369ed3 | 10265 | output_cbranch (rtx op, const char *label, int reversed, rtx insn) |
12a4e8c5 GK |
10266 | { |
10267 | static char string[64]; | |
10268 | enum rtx_code code = GET_CODE (op); | |
10269 | rtx cc_reg = XEXP (op, 0); | |
10270 | enum machine_mode mode = GET_MODE (cc_reg); | |
10271 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 10272 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
10273 | int really_reversed = reversed ^ need_longbranch; |
10274 | char *s = string; | |
10275 | const char *ccode; | |
10276 | const char *pred; | |
10277 | rtx note; | |
10278 | ||
39a10a29 GK |
10279 | validate_condition_mode (code, mode); |
10280 | ||
10281 | /* Work out which way this really branches. We could use | |
10282 | reverse_condition_maybe_unordered here always but this | |
10283 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 10284 | if (really_reversed) |
de40e1df DJ |
10285 | { |
10286 | /* Reversal of FP compares takes care -- an ordered compare | |
10287 | becomes an unordered compare and vice versa. */ | |
10288 | if (mode == CCFPmode) | |
10289 | code = reverse_condition_maybe_unordered (code); | |
10290 | else | |
10291 | code = reverse_condition (code); | |
10292 | } | |
12a4e8c5 | 10293 | |
993f19a8 | 10294 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode) |
a3170dc6 AH |
10295 | { |
10296 | /* The efscmp/tst* instructions twiddle bit 2, which maps nicely | |
10297 | to the GT bit. */ | |
10298 | if (code == EQ) | |
10299 | /* Opposite of GT. */ | |
a3170dc6 | 10300 | code = GT; |
423c1189 AH |
10301 | else if (code == NE) |
10302 | code = UNLE; | |
a3170dc6 AH |
10303 | else |
10304 | abort (); | |
10305 | } | |
10306 | ||
39a10a29 | 10307 | switch (code) |
12a4e8c5 GK |
10308 | { |
10309 | /* Not all of these are actually distinct opcodes, but | |
10310 | we distinguish them for clarity of the resulting assembler. */ | |
50a0b056 GK |
10311 | case NE: case LTGT: |
10312 | ccode = "ne"; break; | |
10313 | case EQ: case UNEQ: | |
10314 | ccode = "eq"; break; | |
10315 | case GE: case GEU: | |
10316 | ccode = "ge"; break; | |
10317 | case GT: case GTU: case UNGT: | |
10318 | ccode = "gt"; break; | |
10319 | case LE: case LEU: | |
10320 | ccode = "le"; break; | |
10321 | case LT: case LTU: case UNLT: | |
10322 | ccode = "lt"; break; | |
12a4e8c5 GK |
10323 | case UNORDERED: ccode = "un"; break; |
10324 | case ORDERED: ccode = "nu"; break; | |
10325 | case UNGE: ccode = "nl"; break; | |
10326 | case UNLE: ccode = "ng"; break; | |
10327 | default: | |
a4f6c312 | 10328 | abort (); |
12a4e8c5 GK |
10329 | } |
10330 | ||
94a54f47 GK |
10331 | /* Maybe we have a guess as to how likely the branch is. |
10332 | The old mnemonics don't have a way to specify this information. */ | |
f4857b9b | 10333 | pred = ""; |
12a4e8c5 GK |
10334 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
10335 | if (note != NULL_RTX) | |
10336 | { | |
10337 | /* PROB is the difference from 50%. */ | |
10338 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
f4857b9b AM |
10339 | |
10340 | /* Only hint for highly probable/improbable branches on newer | |
10341 | cpus as static prediction overrides processor dynamic | |
10342 | prediction. For older cpus we may as well always hint, but | |
10343 | assume not taken for branches that are very close to 50% as a | |
10344 | mispredicted taken branch is more expensive than a | |
10345 | mispredicted not-taken branch. */ | |
ec507f2d | 10346 | if (rs6000_always_hint |
f4857b9b AM |
10347 | || abs (prob) > REG_BR_PROB_BASE / 100 * 48) |
10348 | { | |
10349 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
10350 | && ((prob > 0) ^ need_longbranch)) | |
7f3d8013 | 10351 | pred = "+"; |
f4857b9b AM |
10352 | else |
10353 | pred = "-"; | |
10354 | } | |
12a4e8c5 | 10355 | } |
12a4e8c5 GK |
10356 | |
10357 | if (label == NULL) | |
94a54f47 | 10358 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 10359 | else |
94a54f47 | 10360 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 10361 | |
37c67319 | 10362 | /* We need to escape any '%' characters in the reg_names string. |
a3c9585f | 10363 | Assume they'd only be the first character.... */ |
37c67319 GK |
10364 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') |
10365 | *s++ = '%'; | |
94a54f47 | 10366 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
10367 | |
10368 | if (label != NULL) | |
10369 | { | |
10370 | /* If the branch distance was too far, we may have to use an | |
10371 | unconditional branch to go the distance. */ | |
10372 | if (need_longbranch) | |
44518ddd | 10373 | s += sprintf (s, ",$+8\n\tb %s", label); |
12a4e8c5 GK |
10374 | else |
10375 | s += sprintf (s, ",%s", label); | |
10376 | } | |
10377 | ||
10378 | return string; | |
10379 | } | |
50a0b056 | 10380 | |
423c1189 AH |
10381 | /* Return the string to flip the GT bit on a CR. */ |
10382 | char * | |
10383 | output_e500_flip_gt_bit (rtx dst, rtx src) | |
10384 | { | |
10385 | static char string[64]; | |
10386 | int a, b; | |
10387 | ||
10388 | if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst)) | |
10389 | || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src))) | |
10390 | abort (); | |
10391 | ||
10392 | /* GT bit. */ | |
10393 | a = 4 * (REGNO (dst) - CR0_REGNO) + 1; | |
10394 | b = 4 * (REGNO (src) - CR0_REGNO) + 1; | |
10395 | ||
10396 | sprintf (string, "crnot %d,%d", a, b); | |
10397 | return string; | |
10398 | } | |
10399 | ||
50a0b056 GK |
10400 | /* Emit a conditional move: move TRUE_COND to DEST if OP of the |
10401 | operands of the last comparison is nonzero/true, FALSE_COND if it | |
10402 | is zero/false. Return 0 if the hardware has no such operation. */ | |
a4f6c312 | 10403 | |
50a0b056 | 10404 | int |
a2369ed3 | 10405 | rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
50a0b056 GK |
10406 | { |
10407 | enum rtx_code code = GET_CODE (op); | |
10408 | rtx op0 = rs6000_compare_op0; | |
10409 | rtx op1 = rs6000_compare_op1; | |
10410 | REAL_VALUE_TYPE c1; | |
3148ad6d DJ |
10411 | enum machine_mode compare_mode = GET_MODE (op0); |
10412 | enum machine_mode result_mode = GET_MODE (dest); | |
50a0b056 GK |
10413 | rtx temp; |
10414 | ||
a3c9585f | 10415 | /* These modes should always match. */ |
a3170dc6 AH |
10416 | if (GET_MODE (op1) != compare_mode |
10417 | /* In the isel case however, we can use a compare immediate, so | |
10418 | op1 may be a small constant. */ | |
10419 | && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode))) | |
3148ad6d | 10420 | return 0; |
178c3eff | 10421 | if (GET_MODE (true_cond) != result_mode) |
3148ad6d | 10422 | return 0; |
178c3eff | 10423 | if (GET_MODE (false_cond) != result_mode) |
3148ad6d DJ |
10424 | return 0; |
10425 | ||
50a0b056 | 10426 | /* First, work out if the hardware can do this at all, or |
a3c9585f | 10427 | if it's too slow.... */ |
50a0b056 | 10428 | if (! rs6000_compare_fp_p) |
a3170dc6 AH |
10429 | { |
10430 | if (TARGET_ISEL) | |
10431 | return rs6000_emit_int_cmove (dest, op, true_cond, false_cond); | |
10432 | return 0; | |
10433 | } | |
fef98bf2 AH |
10434 | else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS |
10435 | && GET_MODE_CLASS (compare_mode) == MODE_FLOAT) | |
10436 | return 0; | |
50a0b056 GK |
10437 | |
10438 | /* Eliminate half of the comparisons by switching operands, this | |
10439 | makes the remaining code simpler. */ | |
10440 | if (code == UNLT || code == UNGT || code == UNORDERED || code == NE | |
bc9ec0e0 | 10441 | || code == LTGT || code == LT || code == UNLE) |
50a0b056 GK |
10442 | { |
10443 | code = reverse_condition_maybe_unordered (code); | |
10444 | temp = true_cond; | |
10445 | true_cond = false_cond; | |
10446 | false_cond = temp; | |
10447 | } | |
10448 | ||
10449 | /* UNEQ and LTGT take four instructions for a comparison with zero, | |
10450 | it'll probably be faster to use a branch here too. */ | |
bc9ec0e0 | 10451 | if (code == UNEQ && HONOR_NANS (compare_mode)) |
50a0b056 GK |
10452 | return 0; |
10453 | ||
10454 | if (GET_CODE (op1) == CONST_DOUBLE) | |
10455 | REAL_VALUE_FROM_CONST_DOUBLE (c1, op1); | |
10456 | ||
b6d08ca1 | 10457 | /* We're going to try to implement comparisons by performing |
50a0b056 GK |
10458 | a subtract, then comparing against zero. Unfortunately, |
10459 | Inf - Inf is NaN which is not zero, and so if we don't | |
27d30956 | 10460 | know that the operand is finite and the comparison |
50a0b056 | 10461 | would treat EQ different to UNORDERED, we can't do it. */ |
bc9ec0e0 | 10462 | if (HONOR_INFINITIES (compare_mode) |
50a0b056 | 10463 | && code != GT && code != UNGE |
045572c7 | 10464 | && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1)) |
50a0b056 GK |
10465 | /* Constructs of the form (a OP b ? a : b) are safe. */ |
10466 | && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond)) | |
10467 | || (! rtx_equal_p (op0, true_cond) | |
10468 | && ! rtx_equal_p (op1, true_cond)))) | |
10469 | return 0; | |
10470 | /* At this point we know we can use fsel. */ | |
10471 | ||
10472 | /* Reduce the comparison to a comparison against zero. */ | |
3148ad6d | 10473 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 10474 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 10475 | gen_rtx_MINUS (compare_mode, op0, op1))); |
50a0b056 | 10476 | op0 = temp; |
3148ad6d | 10477 | op1 = CONST0_RTX (compare_mode); |
50a0b056 GK |
10478 | |
10479 | /* If we don't care about NaNs we can reduce some of the comparisons | |
10480 | down to faster ones. */ | |
bc9ec0e0 | 10481 | if (! HONOR_NANS (compare_mode)) |
50a0b056 GK |
10482 | switch (code) |
10483 | { | |
10484 | case GT: | |
10485 | code = LE; | |
10486 | temp = true_cond; | |
10487 | true_cond = false_cond; | |
10488 | false_cond = temp; | |
10489 | break; | |
10490 | case UNGE: | |
10491 | code = GE; | |
10492 | break; | |
10493 | case UNEQ: | |
10494 | code = EQ; | |
10495 | break; | |
10496 | default: | |
10497 | break; | |
10498 | } | |
10499 | ||
10500 | /* Now, reduce everything down to a GE. */ | |
10501 | switch (code) | |
10502 | { | |
10503 | case GE: | |
10504 | break; | |
10505 | ||
10506 | case LE: | |
3148ad6d DJ |
10507 | temp = gen_reg_rtx (compare_mode); |
10508 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
10509 | op0 = temp; |
10510 | break; | |
10511 | ||
10512 | case ORDERED: | |
3148ad6d DJ |
10513 | temp = gen_reg_rtx (compare_mode); |
10514 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0))); | |
50a0b056 GK |
10515 | op0 = temp; |
10516 | break; | |
10517 | ||
10518 | case EQ: | |
3148ad6d | 10519 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 10520 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d DJ |
10521 | gen_rtx_NEG (compare_mode, |
10522 | gen_rtx_ABS (compare_mode, op0)))); | |
50a0b056 GK |
10523 | op0 = temp; |
10524 | break; | |
10525 | ||
10526 | case UNGE: | |
bc9ec0e0 | 10527 | /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */ |
3148ad6d | 10528 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 10529 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 10530 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
10531 | gen_rtx_GE (VOIDmode, |
10532 | op0, op1), | |
10533 | true_cond, false_cond))); | |
bc9ec0e0 GK |
10534 | false_cond = true_cond; |
10535 | true_cond = temp; | |
50a0b056 | 10536 | |
3148ad6d DJ |
10537 | temp = gen_reg_rtx (compare_mode); |
10538 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
10539 | op0 = temp; |
10540 | break; | |
10541 | ||
10542 | case GT: | |
bc9ec0e0 | 10543 | /* a GT 0 <-> (a GE 0 && -a UNLT 0) */ |
3148ad6d | 10544 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 10545 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 10546 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
10547 | gen_rtx_GE (VOIDmode, |
10548 | op0, op1), | |
10549 | true_cond, false_cond))); | |
bc9ec0e0 GK |
10550 | true_cond = false_cond; |
10551 | false_cond = temp; | |
50a0b056 | 10552 | |
3148ad6d DJ |
10553 | temp = gen_reg_rtx (compare_mode); |
10554 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
10555 | op0 = temp; |
10556 | break; | |
10557 | ||
10558 | default: | |
10559 | abort (); | |
10560 | } | |
10561 | ||
10562 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3148ad6d | 10563 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
10564 | gen_rtx_GE (VOIDmode, |
10565 | op0, op1), | |
10566 | true_cond, false_cond))); | |
10567 | return 1; | |
10568 | } | |
10569 | ||
a3170dc6 AH |
10570 | /* Same as above, but for ints (isel). */ |
10571 | ||
10572 | static int | |
a2369ed3 | 10573 | rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
a3170dc6 AH |
10574 | { |
10575 | rtx condition_rtx, cr; | |
10576 | ||
10577 | /* All isel implementations thus far are 32-bits. */ | |
10578 | if (GET_MODE (rs6000_compare_op0) != SImode) | |
10579 | return 0; | |
10580 | ||
10581 | /* We still have to do the compare, because isel doesn't do a | |
10582 | compare, it just looks at the CRx bits set by a previous compare | |
10583 | instruction. */ | |
10584 | condition_rtx = rs6000_generate_compare (GET_CODE (op)); | |
10585 | cr = XEXP (condition_rtx, 0); | |
10586 | ||
10587 | if (GET_MODE (cr) == CCmode) | |
10588 | emit_insn (gen_isel_signed (dest, condition_rtx, | |
10589 | true_cond, false_cond, cr)); | |
10590 | else | |
10591 | emit_insn (gen_isel_unsigned (dest, condition_rtx, | |
10592 | true_cond, false_cond, cr)); | |
10593 | ||
10594 | return 1; | |
10595 | } | |
10596 | ||
10597 | const char * | |
a2369ed3 | 10598 | output_isel (rtx *operands) |
a3170dc6 AH |
10599 | { |
10600 | enum rtx_code code; | |
10601 | ||
10602 | code = GET_CODE (operands[1]); | |
10603 | if (code == GE || code == GEU || code == LE || code == LEU || code == NE) | |
10604 | { | |
10605 | PUT_CODE (operands[1], reverse_condition (code)); | |
10606 | return "isel %0,%3,%2,%j1"; | |
10607 | } | |
10608 | else | |
10609 | return "isel %0,%2,%3,%j1"; | |
10610 | } | |
10611 | ||
50a0b056 | 10612 | void |
a2369ed3 | 10613 | rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1) |
50a0b056 GK |
10614 | { |
10615 | enum machine_mode mode = GET_MODE (op0); | |
5dc8d536 | 10616 | enum rtx_code c; |
50a0b056 | 10617 | rtx target; |
5dc8d536 AH |
10618 | |
10619 | if (code == SMAX || code == SMIN) | |
10620 | c = GE; | |
10621 | else | |
10622 | c = GEU; | |
10623 | ||
50a0b056 | 10624 | if (code == SMAX || code == UMAX) |
5dc8d536 | 10625 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
10626 | op0, op1, mode, 0); |
10627 | else | |
5dc8d536 | 10628 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
10629 | op1, op0, mode, 0); |
10630 | if (target == NULL_RTX) | |
10631 | abort (); | |
10632 | if (target != dest) | |
10633 | emit_move_insn (dest, target); | |
10634 | } | |
46c07df8 | 10635 | |
a9baceb1 GK |
10636 | /* Emit instructions to move SRC to DST. Called by splitters for |
10637 | multi-register moves. It will emit at most one instruction for | |
10638 | each register that is accessed; that is, it won't emit li/lis pairs | |
10639 | (or equivalent for 64-bit code). One of SRC or DST must be a hard | |
10640 | register. */ | |
46c07df8 | 10641 | |
46c07df8 | 10642 | void |
a9baceb1 | 10643 | rs6000_split_multireg_move (rtx dst, rtx src) |
46c07df8 | 10644 | { |
a9baceb1 GK |
10645 | /* The register number of the first register being moved. */ |
10646 | int reg; | |
10647 | /* The mode that is to be moved. */ | |
10648 | enum machine_mode mode; | |
10649 | /* The mode that the move is being done in, and its size. */ | |
10650 | enum machine_mode reg_mode; | |
10651 | int reg_mode_size; | |
10652 | /* The number of registers that will be moved. */ | |
10653 | int nregs; | |
10654 | ||
10655 | reg = REG_P (dst) ? REGNO (dst) : REGNO (src); | |
10656 | mode = GET_MODE (dst); | |
10657 | nregs = HARD_REGNO_NREGS (reg, mode); | |
10658 | if (FP_REGNO_P (reg)) | |
10659 | reg_mode = DFmode; | |
10660 | else if (ALTIVEC_REGNO_P (reg)) | |
10661 | reg_mode = V16QImode; | |
10662 | else | |
10663 | reg_mode = word_mode; | |
10664 | reg_mode_size = GET_MODE_SIZE (reg_mode); | |
46c07df8 | 10665 | |
a9baceb1 GK |
10666 | if (reg_mode_size * nregs != GET_MODE_SIZE (mode)) |
10667 | abort (); | |
10668 | ||
10669 | if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst))) | |
10670 | { | |
10671 | /* Move register range backwards, if we might have destructive | |
10672 | overlap. */ | |
10673 | int i; | |
10674 | for (i = nregs - 1; i >= 0; i--) | |
10675 | emit_insn (gen_rtx_SET (VOIDmode, | |
10676 | simplify_gen_subreg (reg_mode, dst, mode, | |
10677 | i * reg_mode_size), | |
10678 | simplify_gen_subreg (reg_mode, src, mode, | |
10679 | i * reg_mode_size))); | |
10680 | } | |
46c07df8 HP |
10681 | else |
10682 | { | |
a9baceb1 GK |
10683 | int i; |
10684 | int j = -1; | |
10685 | bool used_update = false; | |
46c07df8 | 10686 | |
a9baceb1 | 10687 | if (GET_CODE (src) == MEM && INT_REGNO_P (reg)) |
46c07df8 HP |
10688 | { |
10689 | rtx breg; | |
3a1f863f | 10690 | |
a9baceb1 GK |
10691 | if (GET_CODE (XEXP (src, 0)) == PRE_INC |
10692 | || GET_CODE (XEXP (src, 0)) == PRE_DEC) | |
3a1f863f DE |
10693 | { |
10694 | rtx delta_rtx; | |
a9baceb1 GK |
10695 | breg = XEXP (XEXP (src, 0), 0); |
10696 | delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC | |
10697 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (src))) | |
10698 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))); | |
10699 | emit_insn (TARGET_32BIT | |
10700 | ? gen_addsi3 (breg, breg, delta_rtx) | |
10701 | : gen_adddi3 (breg, breg, delta_rtx)); | |
3a1f863f DE |
10702 | src = gen_rtx_MEM (mode, breg); |
10703 | } | |
10704 | ||
10705 | /* We have now address involving an base register only. | |
10706 | If we use one of the registers to address memory, | |
10707 | we have change that register last. */ | |
10708 | ||
10709 | breg = (GET_CODE (XEXP (src, 0)) == PLUS | |
10710 | ? XEXP (XEXP (src, 0), 0) | |
10711 | : XEXP (src, 0)); | |
10712 | ||
10713 | if (!REG_P (breg)) | |
10714 | abort(); | |
10715 | ||
10716 | if (REGNO (breg) >= REGNO (dst) | |
10717 | && REGNO (breg) < REGNO (dst) + nregs) | |
10718 | j = REGNO (breg) - REGNO (dst); | |
46c07df8 HP |
10719 | } |
10720 | ||
a9baceb1 | 10721 | if (GET_CODE (dst) == MEM && INT_REGNO_P (reg)) |
3a1f863f DE |
10722 | { |
10723 | rtx breg; | |
10724 | ||
a9baceb1 GK |
10725 | if (GET_CODE (XEXP (dst, 0)) == PRE_INC |
10726 | || GET_CODE (XEXP (dst, 0)) == PRE_DEC) | |
3a1f863f DE |
10727 | { |
10728 | rtx delta_rtx; | |
a9baceb1 GK |
10729 | breg = XEXP (XEXP (dst, 0), 0); |
10730 | delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC | |
10731 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst))) | |
10732 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))); | |
3a1f863f DE |
10733 | |
10734 | /* We have to update the breg before doing the store. | |
10735 | Use store with update, if available. */ | |
10736 | ||
10737 | if (TARGET_UPDATE) | |
10738 | { | |
a9baceb1 GK |
10739 | rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0); |
10740 | emit_insn (TARGET_32BIT | |
10741 | ? gen_movsi_update (breg, breg, delta_rtx, nsrc) | |
10742 | : gen_movdi_update (breg, breg, delta_rtx, nsrc)); | |
10743 | used_update = true; | |
3a1f863f DE |
10744 | } |
10745 | else | |
a9baceb1 GK |
10746 | emit_insn (TARGET_32BIT |
10747 | ? gen_addsi3 (breg, breg, delta_rtx) | |
10748 | : gen_adddi3 (breg, breg, delta_rtx)); | |
3a1f863f DE |
10749 | dst = gen_rtx_MEM (mode, breg); |
10750 | } | |
10751 | } | |
10752 | ||
46c07df8 | 10753 | for (i = 0; i < nregs; i++) |
3a1f863f DE |
10754 | { |
10755 | /* Calculate index to next subword. */ | |
10756 | ++j; | |
10757 | if (j == nregs) | |
10758 | j = 0; | |
46c07df8 | 10759 | |
a9baceb1 GK |
10760 | /* If compiler already emited move of first word by |
10761 | store with update, no need to do anything. */ | |
3a1f863f | 10762 | if (j == 0 && used_update) |
a9baceb1 GK |
10763 | continue; |
10764 | ||
10765 | emit_insn (gen_rtx_SET (VOIDmode, | |
10766 | simplify_gen_subreg (reg_mode, dst, mode, | |
10767 | j * reg_mode_size), | |
10768 | simplify_gen_subreg (reg_mode, src, mode, | |
10769 | j * reg_mode_size))); | |
3a1f863f | 10770 | } |
46c07df8 HP |
10771 | } |
10772 | } | |
10773 | ||
12a4e8c5 | 10774 | \f |
a4f6c312 SS |
10775 | /* This page contains routines that are used to determine what the |
10776 | function prologue and epilogue code will do and write them out. */ | |
9878760c | 10777 | |
a4f6c312 SS |
10778 | /* Return the first fixed-point register that is required to be |
10779 | saved. 32 if none. */ | |
9878760c RK |
10780 | |
10781 | int | |
863d938c | 10782 | first_reg_to_save (void) |
9878760c RK |
10783 | { |
10784 | int first_reg; | |
10785 | ||
10786 | /* Find lowest numbered live register. */ | |
10787 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
a38d360d GK |
10788 | if (regs_ever_live[first_reg] |
10789 | && (! call_used_regs[first_reg] | |
1db02437 | 10790 | || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 10791 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
b4db40bf JJ |
10792 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic) |
10793 | || (TARGET_TOC && TARGET_MINIMAL_TOC))))) | |
9878760c RK |
10794 | break; |
10795 | ||
ee890fe2 | 10796 | #if TARGET_MACHO |
93638d7a AM |
10797 | if (flag_pic |
10798 | && current_function_uses_pic_offset_table | |
10799 | && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM) | |
1db02437 | 10800 | return RS6000_PIC_OFFSET_TABLE_REGNUM; |
ee890fe2 SS |
10801 | #endif |
10802 | ||
9878760c RK |
10803 | return first_reg; |
10804 | } | |
10805 | ||
10806 | /* Similar, for FP regs. */ | |
10807 | ||
10808 | int | |
863d938c | 10809 | first_fp_reg_to_save (void) |
9878760c RK |
10810 | { |
10811 | int first_reg; | |
10812 | ||
10813 | /* Find lowest numbered live register. */ | |
10814 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
10815 | if (regs_ever_live[first_reg]) | |
10816 | break; | |
10817 | ||
10818 | return first_reg; | |
10819 | } | |
00b960c7 AH |
10820 | |
10821 | /* Similar, for AltiVec regs. */ | |
10822 | ||
10823 | static int | |
863d938c | 10824 | first_altivec_reg_to_save (void) |
00b960c7 AH |
10825 | { |
10826 | int i; | |
10827 | ||
10828 | /* Stack frame remains as is unless we are in AltiVec ABI. */ | |
10829 | if (! TARGET_ALTIVEC_ABI) | |
10830 | return LAST_ALTIVEC_REGNO + 1; | |
10831 | ||
10832 | /* Find lowest numbered live register. */ | |
10833 | for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i) | |
10834 | if (regs_ever_live[i]) | |
10835 | break; | |
10836 | ||
10837 | return i; | |
10838 | } | |
10839 | ||
10840 | /* Return a 32-bit mask of the AltiVec registers we need to set in | |
10841 | VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in | |
10842 | the 32-bit word is 0. */ | |
10843 | ||
10844 | static unsigned int | |
863d938c | 10845 | compute_vrsave_mask (void) |
00b960c7 AH |
10846 | { |
10847 | unsigned int i, mask = 0; | |
10848 | ||
10849 | /* First, find out if we use _any_ altivec registers. */ | |
10850 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
10851 | if (regs_ever_live[i]) | |
10852 | mask |= ALTIVEC_REG_BIT (i); | |
10853 | ||
10854 | if (mask == 0) | |
10855 | return mask; | |
10856 | ||
00b960c7 AH |
10857 | /* Next, remove the argument registers from the set. These must |
10858 | be in the VRSAVE mask set by the caller, so we don't need to add | |
10859 | them in again. More importantly, the mask we compute here is | |
10860 | used to generate CLOBBERs in the set_vrsave insn, and we do not | |
10861 | wish the argument registers to die. */ | |
a6cf80f2 | 10862 | for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i) |
00b960c7 AH |
10863 | mask &= ~ALTIVEC_REG_BIT (i); |
10864 | ||
10865 | /* Similarly, remove the return value from the set. */ | |
10866 | { | |
10867 | bool yes = false; | |
10868 | diddle_return_value (is_altivec_return_reg, &yes); | |
10869 | if (yes) | |
10870 | mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN); | |
10871 | } | |
10872 | ||
10873 | return mask; | |
10874 | } | |
10875 | ||
10876 | static void | |
a2369ed3 | 10877 | is_altivec_return_reg (rtx reg, void *xyes) |
00b960c7 AH |
10878 | { |
10879 | bool *yes = (bool *) xyes; | |
10880 | if (REGNO (reg) == ALTIVEC_ARG_RETURN) | |
10881 | *yes = true; | |
10882 | } | |
10883 | ||
4697a36c MM |
10884 | \f |
10885 | /* Calculate the stack information for the current function. This is | |
10886 | complicated by having two separate calling sequences, the AIX calling | |
10887 | sequence and the V.4 calling sequence. | |
10888 | ||
592696dd | 10889 | AIX (and Darwin/Mac OS X) stack frames look like: |
a260abc9 | 10890 | 32-bit 64-bit |
4697a36c | 10891 | SP----> +---------------------------------------+ |
a260abc9 | 10892 | | back chain to caller | 0 0 |
4697a36c | 10893 | +---------------------------------------+ |
a260abc9 | 10894 | | saved CR | 4 8 (8-11) |
4697a36c | 10895 | +---------------------------------------+ |
a260abc9 | 10896 | | saved LR | 8 16 |
4697a36c | 10897 | +---------------------------------------+ |
a260abc9 | 10898 | | reserved for compilers | 12 24 |
4697a36c | 10899 | +---------------------------------------+ |
a260abc9 | 10900 | | reserved for binders | 16 32 |
4697a36c | 10901 | +---------------------------------------+ |
a260abc9 | 10902 | | saved TOC pointer | 20 40 |
4697a36c | 10903 | +---------------------------------------+ |
a260abc9 | 10904 | | Parameter save area (P) | 24 48 |
4697a36c | 10905 | +---------------------------------------+ |
a260abc9 | 10906 | | Alloca space (A) | 24+P etc. |
802a0058 | 10907 | +---------------------------------------+ |
a7df97e6 | 10908 | | Local variable space (L) | 24+P+A |
4697a36c | 10909 | +---------------------------------------+ |
a7df97e6 | 10910 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 10911 | +---------------------------------------+ |
00b960c7 AH |
10912 | | Save area for AltiVec registers (W) | 24+P+A+L+X |
10913 | +---------------------------------------+ | |
10914 | | AltiVec alignment padding (Y) | 24+P+A+L+X+W | |
10915 | +---------------------------------------+ | |
10916 | | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y | |
4697a36c | 10917 | +---------------------------------------+ |
00b960c7 AH |
10918 | | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z |
10919 | +---------------------------------------+ | |
10920 | | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G | |
4697a36c MM |
10921 | +---------------------------------------+ |
10922 | old SP->| back chain to caller's caller | | |
10923 | +---------------------------------------+ | |
10924 | ||
5376a30c KR |
10925 | The required alignment for AIX configurations is two words (i.e., 8 |
10926 | or 16 bytes). | |
10927 | ||
10928 | ||
4697a36c MM |
10929 | V.4 stack frames look like: |
10930 | ||
10931 | SP----> +---------------------------------------+ | |
10932 | | back chain to caller | 0 | |
10933 | +---------------------------------------+ | |
5eb387b8 | 10934 | | caller's saved LR | 4 |
4697a36c MM |
10935 | +---------------------------------------+ |
10936 | | Parameter save area (P) | 8 | |
10937 | +---------------------------------------+ | |
a7df97e6 MM |
10938 | | Alloca space (A) | 8+P |
10939 | +---------------------------------------+ | |
10940 | | Varargs save area (V) | 8+P+A | |
10941 | +---------------------------------------+ | |
10942 | | Local variable space (L) | 8+P+A+V | |
10943 | +---------------------------------------+ | |
10944 | | Float/int conversion temporary (X) | 8+P+A+V+L | |
4697a36c | 10945 | +---------------------------------------+ |
00b960c7 AH |
10946 | | Save area for AltiVec registers (W) | 8+P+A+V+L+X |
10947 | +---------------------------------------+ | |
10948 | | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W | |
10949 | +---------------------------------------+ | |
10950 | | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y | |
10951 | +---------------------------------------+ | |
a3170dc6 AH |
10952 | | SPE: area for 64-bit GP registers | |
10953 | +---------------------------------------+ | |
10954 | | SPE alignment padding | | |
10955 | +---------------------------------------+ | |
00b960c7 | 10956 | | saved CR (C) | 8+P+A+V+L+X+W+Y+Z |
a7df97e6 | 10957 | +---------------------------------------+ |
00b960c7 | 10958 | | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C |
a7df97e6 | 10959 | +---------------------------------------+ |
00b960c7 | 10960 | | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G |
4697a36c MM |
10961 | +---------------------------------------+ |
10962 | old SP->| back chain to caller's caller | | |
10963 | +---------------------------------------+ | |
b6c9286a | 10964 | |
5376a30c KR |
10965 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
10966 | given. (But note below and in sysv4.h that we require only 8 and | |
10967 | may round up the size of our stack frame anyways. The historical | |
10968 | reason is early versions of powerpc-linux which didn't properly | |
10969 | align the stack at program startup. A happy side-effect is that | |
10970 | -mno-eabi libraries can be used with -meabi programs.) | |
10971 | ||
50d440bc | 10972 | The EABI configuration defaults to the V.4 layout. However, |
5376a30c KR |
10973 | the stack alignment requirements may differ. If -mno-eabi is not |
10974 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
10975 | given, the required alignment is 16 bytes. (But see V.4 comment | |
10976 | above.) */ | |
4697a36c | 10977 | |
61b2fbe7 MM |
10978 | #ifndef ABI_STACK_BOUNDARY |
10979 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
10980 | #endif | |
10981 | ||
d1d0c603 | 10982 | static rs6000_stack_t * |
863d938c | 10983 | rs6000_stack_info (void) |
4697a36c MM |
10984 | { |
10985 | static rs6000_stack_t info, zero_info; | |
10986 | rs6000_stack_t *info_ptr = &info; | |
327e5343 | 10987 | int reg_size = TARGET_32BIT ? 4 : 8; |
83720594 | 10988 | int ehrd_size; |
44688022 | 10989 | HOST_WIDE_INT non_fixed_size; |
4697a36c | 10990 | |
a4f6c312 | 10991 | /* Zero all fields portably. */ |
4697a36c MM |
10992 | info = zero_info; |
10993 | ||
c19de7aa AH |
10994 | if (TARGET_SPE) |
10995 | { | |
10996 | /* Cache value so we don't rescan instruction chain over and over. */ | |
9b7b447f AH |
10997 | if (cfun->machine->insn_chain_scanned_p == 0) |
10998 | { | |
10999 | cfun->machine->insn_chain_scanned_p = 1; | |
11000 | info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p (); | |
11001 | } | |
c19de7aa AH |
11002 | } |
11003 | ||
a4f6c312 | 11004 | /* Select which calling sequence. */ |
178274da | 11005 | info_ptr->abi = DEFAULT_ABI; |
9878760c | 11006 | |
a4f6c312 | 11007 | /* Calculate which registers need to be saved & save area size. */ |
4697a36c | 11008 | info_ptr->first_gp_reg_save = first_reg_to_save (); |
1db02437 | 11009 | /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM, |
906fb125 | 11010 | even if it currently looks like we won't. */ |
2bfcf297 | 11011 | if (((TARGET_TOC && TARGET_MINIMAL_TOC) |
178274da AM |
11012 | || (flag_pic == 1 && DEFAULT_ABI == ABI_V4) |
11013 | || (flag_pic && DEFAULT_ABI == ABI_DARWIN)) | |
1db02437 FS |
11014 | && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM) |
11015 | info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM); | |
906fb125 GK |
11016 | else |
11017 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c | 11018 | |
a3170dc6 AH |
11019 | /* For the SPE, we have an additional upper 32-bits on each GPR. |
11020 | Ideally we should save the entire 64-bits only when the upper | |
11021 | half is used in SIMD instructions. Since we only record | |
11022 | registers live (not the size they are used in), this proves | |
11023 | difficult because we'd have to traverse the instruction chain at | |
11024 | the right time, taking reload into account. This is a real pain, | |
c19de7aa AH |
11025 | so we opt to save the GPRs in 64-bits always if but one register |
11026 | gets used in 64-bits. Otherwise, all the registers in the frame | |
11027 | get saved in 32-bits. | |
a3170dc6 | 11028 | |
c19de7aa | 11029 | So... since when we save all GPRs (except the SP) in 64-bits, the |
a3170dc6 | 11030 | traditional GP save area will be empty. */ |
c19de7aa | 11031 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11032 | info_ptr->gp_size = 0; |
11033 | ||
4697a36c MM |
11034 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); |
11035 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
11036 | ||
00b960c7 AH |
11037 | info_ptr->first_altivec_reg_save = first_altivec_reg_to_save (); |
11038 | info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1 | |
11039 | - info_ptr->first_altivec_reg_save); | |
11040 | ||
592696dd | 11041 | /* Does this function call anything? */ |
71f123ca FS |
11042 | info_ptr->calls_p = (! current_function_is_leaf |
11043 | || cfun->machine->ra_needs_full_frame); | |
b6c9286a | 11044 | |
a4f6c312 | 11045 | /* Determine if we need to save the link register. */ |
71f123ca | 11046 | if (rs6000_ra_ever_killed () |
ffcfcb5f AM |
11047 | || (DEFAULT_ABI == ABI_AIX |
11048 | && current_function_profile | |
11049 | && !TARGET_PROFILE_KERNEL) | |
4697a36c MM |
11050 | #ifdef TARGET_RELOCATABLE |
11051 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
11052 | #endif | |
11053 | || (info_ptr->first_fp_reg_save != 64 | |
11054 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
00b960c7 | 11055 | || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO |
178274da | 11056 | || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca) |
a4f6c312 SS |
11057 | || (DEFAULT_ABI == ABI_DARWIN |
11058 | && flag_pic | |
11059 | && current_function_uses_pic_offset_table) | |
4697a36c MM |
11060 | || info_ptr->calls_p) |
11061 | { | |
11062 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 11063 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
11064 | } |
11065 | ||
9ebbca7d GK |
11066 | /* Determine if we need to save the condition code registers. */ |
11067 | if (regs_ever_live[CR2_REGNO] | |
11068 | || regs_ever_live[CR3_REGNO] | |
11069 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
11070 | { |
11071 | info_ptr->cr_save_p = 1; | |
178274da | 11072 | if (DEFAULT_ABI == ABI_V4) |
4697a36c MM |
11073 | info_ptr->cr_size = reg_size; |
11074 | } | |
11075 | ||
83720594 RH |
11076 | /* If the current function calls __builtin_eh_return, then we need |
11077 | to allocate stack space for registers that will hold data for | |
11078 | the exception handler. */ | |
11079 | if (current_function_calls_eh_return) | |
11080 | { | |
11081 | unsigned int i; | |
11082 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i) | |
11083 | continue; | |
a3170dc6 AH |
11084 | |
11085 | /* SPE saves EH registers in 64-bits. */ | |
c19de7aa AH |
11086 | ehrd_size = i * (TARGET_SPE_ABI |
11087 | && info_ptr->spe_64bit_regs_used != 0 | |
11088 | ? UNITS_PER_SPE_WORD : UNITS_PER_WORD); | |
83720594 RH |
11089 | } |
11090 | else | |
11091 | ehrd_size = 0; | |
11092 | ||
592696dd | 11093 | /* Determine various sizes. */ |
4697a36c MM |
11094 | info_ptr->reg_size = reg_size; |
11095 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
11096 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 | 11097 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
a4f6c312 | 11098 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, |
03e007d7 | 11099 | TARGET_ALTIVEC ? 16 : 8); |
00b960c7 | 11100 | |
c19de7aa | 11101 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11102 | info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save); |
11103 | else | |
11104 | info_ptr->spe_gp_size = 0; | |
11105 | ||
4d774ff8 HP |
11106 | if (TARGET_ALTIVEC_ABI) |
11107 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
00b960c7 | 11108 | else |
4d774ff8 HP |
11109 | info_ptr->vrsave_mask = 0; |
11110 | ||
11111 | if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask) | |
11112 | info_ptr->vrsave_size = 4; | |
11113 | else | |
11114 | info_ptr->vrsave_size = 0; | |
b6c9286a | 11115 | |
592696dd | 11116 | /* Calculate the offsets. */ |
178274da | 11117 | switch (DEFAULT_ABI) |
4697a36c | 11118 | { |
b6c9286a | 11119 | case ABI_NONE: |
24d304eb | 11120 | default: |
b6c9286a MM |
11121 | abort (); |
11122 | ||
11123 | case ABI_AIX: | |
ee890fe2 | 11124 | case ABI_DARWIN: |
b6c9286a MM |
11125 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
11126 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
00b960c7 AH |
11127 | |
11128 | if (TARGET_ALTIVEC_ABI) | |
11129 | { | |
11130 | info_ptr->vrsave_save_offset | |
11131 | = info_ptr->gp_save_offset - info_ptr->vrsave_size; | |
11132 | ||
11133 | /* Align stack so vector save area is on a quadword boundary. */ | |
11134 | if (info_ptr->altivec_size != 0) | |
11135 | info_ptr->altivec_padding_size | |
11136 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
11137 | else | |
11138 | info_ptr->altivec_padding_size = 0; | |
11139 | ||
11140 | info_ptr->altivec_save_offset | |
11141 | = info_ptr->vrsave_save_offset | |
11142 | - info_ptr->altivec_padding_size | |
11143 | - info_ptr->altivec_size; | |
11144 | ||
11145 | /* Adjust for AltiVec case. */ | |
11146 | info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size; | |
11147 | } | |
11148 | else | |
11149 | info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size; | |
a260abc9 DE |
11150 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
11151 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
11152 | break; |
11153 | ||
11154 | case ABI_V4: | |
b6c9286a MM |
11155 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
11156 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 | 11157 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
00b960c7 | 11158 | |
c19de7aa | 11159 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11160 | { |
11161 | /* Align stack so SPE GPR save area is aligned on a | |
11162 | double-word boundary. */ | |
11163 | if (info_ptr->spe_gp_size != 0) | |
11164 | info_ptr->spe_padding_size | |
11165 | = 8 - (-info_ptr->cr_save_offset % 8); | |
11166 | else | |
11167 | info_ptr->spe_padding_size = 0; | |
11168 | ||
11169 | info_ptr->spe_gp_save_offset | |
11170 | = info_ptr->cr_save_offset | |
11171 | - info_ptr->spe_padding_size | |
11172 | - info_ptr->spe_gp_size; | |
11173 | ||
11174 | /* Adjust for SPE case. */ | |
11175 | info_ptr->toc_save_offset | |
11176 | = info_ptr->spe_gp_save_offset - info_ptr->toc_size; | |
11177 | } | |
11178 | else if (TARGET_ALTIVEC_ABI) | |
00b960c7 AH |
11179 | { |
11180 | info_ptr->vrsave_save_offset | |
11181 | = info_ptr->cr_save_offset - info_ptr->vrsave_size; | |
11182 | ||
11183 | /* Align stack so vector save area is on a quadword boundary. */ | |
11184 | if (info_ptr->altivec_size != 0) | |
11185 | info_ptr->altivec_padding_size | |
11186 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
11187 | else | |
11188 | info_ptr->altivec_padding_size = 0; | |
11189 | ||
11190 | info_ptr->altivec_save_offset | |
11191 | = info_ptr->vrsave_save_offset | |
11192 | - info_ptr->altivec_padding_size | |
11193 | - info_ptr->altivec_size; | |
11194 | ||
11195 | /* Adjust for AltiVec case. */ | |
11196 | info_ptr->toc_save_offset | |
11197 | = info_ptr->altivec_save_offset - info_ptr->toc_size; | |
11198 | } | |
11199 | else | |
11200 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
83720594 | 11201 | info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size; |
b6c9286a MM |
11202 | info_ptr->lr_save_offset = reg_size; |
11203 | break; | |
4697a36c MM |
11204 | } |
11205 | ||
00b960c7 AH |
11206 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
11207 | + info_ptr->gp_size | |
11208 | + info_ptr->altivec_size | |
11209 | + info_ptr->altivec_padding_size | |
a3170dc6 AH |
11210 | + info_ptr->spe_gp_size |
11211 | + info_ptr->spe_padding_size | |
00b960c7 AH |
11212 | + ehrd_size |
11213 | + info_ptr->cr_size | |
11214 | + info_ptr->lr_size | |
11215 | + info_ptr->vrsave_size | |
11216 | + info_ptr->toc_size, | |
11217 | (TARGET_ALTIVEC_ABI || ABI_DARWIN) | |
11218 | ? 16 : 8); | |
11219 | ||
44688022 | 11220 | non_fixed_size = (info_ptr->vars_size |
ff381587 | 11221 | + info_ptr->parm_size |
ff381587 | 11222 | + info_ptr->save_size |
44688022 | 11223 | + info_ptr->varargs_size); |
ff381587 | 11224 | |
44688022 AM |
11225 | info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size, |
11226 | ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
ff381587 MM |
11227 | |
11228 | /* Determine if we need to allocate any stack frame: | |
11229 | ||
a4f6c312 SS |
11230 | For AIX we need to push the stack if a frame pointer is needed |
11231 | (because the stack might be dynamically adjusted), if we are | |
11232 | debugging, if we make calls, or if the sum of fp_save, gp_save, | |
11233 | and local variables are more than the space needed to save all | |
11234 | non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 | |
11235 | + 18*8 = 288 (GPR13 reserved). | |
ff381587 | 11236 | |
a4f6c312 SS |
11237 | For V.4 we don't have the stack cushion that AIX uses, but assume |
11238 | that the debugger can handle stackless frames. */ | |
ff381587 MM |
11239 | |
11240 | if (info_ptr->calls_p) | |
11241 | info_ptr->push_p = 1; | |
11242 | ||
178274da | 11243 | else if (DEFAULT_ABI == ABI_V4) |
44688022 | 11244 | info_ptr->push_p = non_fixed_size != 0; |
ff381587 | 11245 | |
178274da AM |
11246 | else if (frame_pointer_needed) |
11247 | info_ptr->push_p = 1; | |
11248 | ||
11249 | else if (TARGET_XCOFF && write_symbols != NO_DEBUG) | |
11250 | info_ptr->push_p = 1; | |
11251 | ||
ff381587 | 11252 | else |
44688022 | 11253 | info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288); |
ff381587 | 11254 | |
a4f6c312 | 11255 | /* Zero offsets if we're not saving those registers. */ |
8dda1a21 | 11256 | if (info_ptr->fp_size == 0) |
4697a36c MM |
11257 | info_ptr->fp_save_offset = 0; |
11258 | ||
8dda1a21 | 11259 | if (info_ptr->gp_size == 0) |
4697a36c MM |
11260 | info_ptr->gp_save_offset = 0; |
11261 | ||
00b960c7 AH |
11262 | if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0) |
11263 | info_ptr->altivec_save_offset = 0; | |
11264 | ||
11265 | if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0) | |
11266 | info_ptr->vrsave_save_offset = 0; | |
11267 | ||
c19de7aa AH |
11268 | if (! TARGET_SPE_ABI |
11269 | || info_ptr->spe_64bit_regs_used == 0 | |
11270 | || info_ptr->spe_gp_size == 0) | |
a3170dc6 AH |
11271 | info_ptr->spe_gp_save_offset = 0; |
11272 | ||
c81fc13e | 11273 | if (! info_ptr->lr_save_p) |
4697a36c MM |
11274 | info_ptr->lr_save_offset = 0; |
11275 | ||
c81fc13e | 11276 | if (! info_ptr->cr_save_p) |
4697a36c MM |
11277 | info_ptr->cr_save_offset = 0; |
11278 | ||
c81fc13e | 11279 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
11280 | info_ptr->toc_save_offset = 0; |
11281 | ||
4697a36c MM |
11282 | return info_ptr; |
11283 | } | |
11284 | ||
c19de7aa AH |
11285 | /* Return true if the current function uses any GPRs in 64-bit SIMD |
11286 | mode. */ | |
11287 | ||
11288 | static bool | |
863d938c | 11289 | spe_func_has_64bit_regs_p (void) |
c19de7aa AH |
11290 | { |
11291 | rtx insns, insn; | |
11292 | ||
11293 | /* Functions that save and restore all the call-saved registers will | |
11294 | need to save/restore the registers in 64-bits. */ | |
11295 | if (current_function_calls_eh_return | |
11296 | || current_function_calls_setjmp | |
11297 | || current_function_has_nonlocal_goto) | |
11298 | return true; | |
11299 | ||
11300 | insns = get_insns (); | |
11301 | ||
11302 | for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn)) | |
11303 | { | |
11304 | if (INSN_P (insn)) | |
11305 | { | |
11306 | rtx i; | |
11307 | ||
11308 | i = PATTERN (insn); | |
11309 | if (GET_CODE (i) == SET | |
11310 | && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i)))) | |
11311 | return true; | |
11312 | } | |
11313 | } | |
11314 | ||
11315 | return false; | |
11316 | } | |
11317 | ||
d1d0c603 | 11318 | static void |
a2369ed3 | 11319 | debug_stack_info (rs6000_stack_t *info) |
9878760c | 11320 | { |
d330fd93 | 11321 | const char *abi_string; |
24d304eb | 11322 | |
c81fc13e | 11323 | if (! info) |
4697a36c MM |
11324 | info = rs6000_stack_info (); |
11325 | ||
11326 | fprintf (stderr, "\nStack information for function %s:\n", | |
11327 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
11328 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
11329 | : "<unknown>")); | |
11330 | ||
24d304eb RK |
11331 | switch (info->abi) |
11332 | { | |
b6c9286a MM |
11333 | default: abi_string = "Unknown"; break; |
11334 | case ABI_NONE: abi_string = "NONE"; break; | |
50d440bc | 11335 | case ABI_AIX: abi_string = "AIX"; break; |
ee890fe2 | 11336 | case ABI_DARWIN: abi_string = "Darwin"; break; |
b6c9286a | 11337 | case ABI_V4: abi_string = "V.4"; break; |
24d304eb RK |
11338 | } |
11339 | ||
11340 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
11341 | ||
00b960c7 AH |
11342 | if (TARGET_ALTIVEC_ABI) |
11343 | fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n"); | |
11344 | ||
a3170dc6 AH |
11345 | if (TARGET_SPE_ABI) |
11346 | fprintf (stderr, "\tSPE ABI extensions enabled.\n"); | |
11347 | ||
4697a36c MM |
11348 | if (info->first_gp_reg_save != 32) |
11349 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
11350 | ||
11351 | if (info->first_fp_reg_save != 64) | |
11352 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 11353 | |
00b960c7 AH |
11354 | if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO) |
11355 | fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n", | |
11356 | info->first_altivec_reg_save); | |
11357 | ||
4697a36c MM |
11358 | if (info->lr_save_p) |
11359 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 11360 | |
4697a36c MM |
11361 | if (info->cr_save_p) |
11362 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
11363 | ||
b6c9286a MM |
11364 | if (info->toc_save_p) |
11365 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
11366 | ||
00b960c7 AH |
11367 | if (info->vrsave_mask) |
11368 | fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask); | |
11369 | ||
4697a36c MM |
11370 | if (info->push_p) |
11371 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
11372 | ||
11373 | if (info->calls_p) | |
11374 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
11375 | ||
4697a36c MM |
11376 | if (info->gp_save_offset) |
11377 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
11378 | ||
11379 | if (info->fp_save_offset) | |
11380 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
11381 | ||
00b960c7 AH |
11382 | if (info->altivec_save_offset) |
11383 | fprintf (stderr, "\taltivec_save_offset = %5d\n", | |
11384 | info->altivec_save_offset); | |
11385 | ||
a3170dc6 AH |
11386 | if (info->spe_gp_save_offset) |
11387 | fprintf (stderr, "\tspe_gp_save_offset = %5d\n", | |
11388 | info->spe_gp_save_offset); | |
11389 | ||
00b960c7 AH |
11390 | if (info->vrsave_save_offset) |
11391 | fprintf (stderr, "\tvrsave_save_offset = %5d\n", | |
11392 | info->vrsave_save_offset); | |
11393 | ||
4697a36c MM |
11394 | if (info->lr_save_offset) |
11395 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
11396 | ||
11397 | if (info->cr_save_offset) | |
11398 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
11399 | ||
b6c9286a MM |
11400 | if (info->toc_save_offset) |
11401 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
11402 | ||
4697a36c MM |
11403 | if (info->varargs_save_offset) |
11404 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
11405 | ||
11406 | if (info->total_size) | |
d1d0c603 JJ |
11407 | fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
11408 | info->total_size); | |
4697a36c MM |
11409 | |
11410 | if (info->varargs_size) | |
11411 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
11412 | ||
11413 | if (info->vars_size) | |
d1d0c603 JJ |
11414 | fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
11415 | info->vars_size); | |
4697a36c MM |
11416 | |
11417 | if (info->parm_size) | |
11418 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
11419 | ||
11420 | if (info->fixed_size) | |
11421 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
11422 | ||
11423 | if (info->gp_size) | |
11424 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
11425 | ||
a3170dc6 AH |
11426 | if (info->spe_gp_size) |
11427 | fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size); | |
11428 | ||
4697a36c MM |
11429 | if (info->fp_size) |
11430 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
11431 | ||
00b960c7 AH |
11432 | if (info->altivec_size) |
11433 | fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size); | |
11434 | ||
11435 | if (info->vrsave_size) | |
11436 | fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size); | |
11437 | ||
11438 | if (info->altivec_padding_size) | |
11439 | fprintf (stderr, "\taltivec_padding_size= %5d\n", | |
11440 | info->altivec_padding_size); | |
11441 | ||
a3170dc6 AH |
11442 | if (info->spe_padding_size) |
11443 | fprintf (stderr, "\tspe_padding_size = %5d\n", | |
11444 | info->spe_padding_size); | |
11445 | ||
a4f6c312 | 11446 | if (info->lr_size) |
ed947a96 | 11447 | fprintf (stderr, "\tlr_size = %5d\n", info->lr_size); |
b6c9286a | 11448 | |
4697a36c MM |
11449 | if (info->cr_size) |
11450 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
11451 | ||
a4f6c312 | 11452 | if (info->toc_size) |
b6c9286a MM |
11453 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); |
11454 | ||
4697a36c MM |
11455 | if (info->save_size) |
11456 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
11457 | ||
11458 | if (info->reg_size != 4) | |
11459 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
11460 | ||
11461 | fprintf (stderr, "\n"); | |
9878760c | 11462 | } |
71f123ca FS |
11463 | |
11464 | rtx | |
a2369ed3 | 11465 | rs6000_return_addr (int count, rtx frame) |
71f123ca | 11466 | { |
a4f6c312 SS |
11467 | /* Currently we don't optimize very well between prolog and body |
11468 | code and for PIC code the code can be actually quite bad, so | |
11469 | don't try to be too clever here. */ | |
f1384257 | 11470 | if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic)) |
71f123ca FS |
11471 | { |
11472 | cfun->machine->ra_needs_full_frame = 1; | |
8ac61af7 RK |
11473 | |
11474 | return | |
11475 | gen_rtx_MEM | |
11476 | (Pmode, | |
11477 | memory_address | |
11478 | (Pmode, | |
11479 | plus_constant (copy_to_reg | |
11480 | (gen_rtx_MEM (Pmode, | |
11481 | memory_address (Pmode, frame))), | |
11482 | RETURN_ADDRESS_OFFSET))); | |
71f123ca FS |
11483 | } |
11484 | ||
8c29550d | 11485 | cfun->machine->ra_need_lr = 1; |
9e2f7ec7 | 11486 | return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM); |
71f123ca FS |
11487 | } |
11488 | ||
5e1bf043 DJ |
11489 | /* Say whether a function is a candidate for sibcall handling or not. |
11490 | We do not allow indirect calls to be optimized into sibling calls. | |
11491 | Also, we can't do it if there are any vector parameters; there's | |
11492 | nowhere to put the VRsave code so it works; note that functions with | |
11493 | vector parameters are required to have a prototype, so the argument | |
11494 | type info must be available here. (The tail recursion case can work | |
11495 | with vector parameters, but there's no way to distinguish here.) */ | |
4977bab6 | 11496 | static bool |
a2369ed3 | 11497 | rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) |
5e1bf043 DJ |
11498 | { |
11499 | tree type; | |
4977bab6 | 11500 | if (decl) |
5e1bf043 DJ |
11501 | { |
11502 | if (TARGET_ALTIVEC_VRSAVE) | |
11503 | { | |
4977bab6 | 11504 | for (type = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
5e1bf043 DJ |
11505 | type; type = TREE_CHAIN (type)) |
11506 | { | |
c15b529f | 11507 | if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE) |
4977bab6 | 11508 | return false; |
5e1bf043 DJ |
11509 | } |
11510 | } | |
11511 | if (DEFAULT_ABI == ABI_DARWIN | |
4977bab6 | 11512 | || (*targetm.binds_local_p) (decl)) |
2bcc50d0 | 11513 | { |
4977bab6 | 11514 | tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
2bcc50d0 AM |
11515 | |
11516 | if (!lookup_attribute ("longcall", attr_list) | |
11517 | || lookup_attribute ("shortcall", attr_list)) | |
4977bab6 | 11518 | return true; |
2bcc50d0 | 11519 | } |
5e1bf043 | 11520 | } |
4977bab6 | 11521 | return false; |
5e1bf043 DJ |
11522 | } |
11523 | ||
71f123ca | 11524 | static int |
863d938c | 11525 | rs6000_ra_ever_killed (void) |
71f123ca FS |
11526 | { |
11527 | rtx top; | |
5e1bf043 DJ |
11528 | rtx reg; |
11529 | rtx insn; | |
71f123ca | 11530 | |
dd292d0a | 11531 | if (current_function_is_thunk) |
71f123ca | 11532 | return 0; |
eb0424da | 11533 | |
36f7e964 AH |
11534 | /* regs_ever_live has LR marked as used if any sibcalls are present, |
11535 | but this should not force saving and restoring in the | |
11536 | pro/epilogue. Likewise, reg_set_between_p thinks a sibcall | |
a3c9585f | 11537 | clobbers LR, so that is inappropriate. */ |
36f7e964 | 11538 | |
5e1bf043 DJ |
11539 | /* Also, the prologue can generate a store into LR that |
11540 | doesn't really count, like this: | |
36f7e964 | 11541 | |
5e1bf043 DJ |
11542 | move LR->R0 |
11543 | bcl to set PIC register | |
11544 | move LR->R31 | |
11545 | move R0->LR | |
36f7e964 AH |
11546 | |
11547 | When we're called from the epilogue, we need to avoid counting | |
11548 | this as a store. */ | |
5e1bf043 | 11549 | |
71f123ca FS |
11550 | push_topmost_sequence (); |
11551 | top = get_insns (); | |
11552 | pop_topmost_sequence (); | |
5e1bf043 | 11553 | reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); |
71f123ca | 11554 | |
5e1bf043 DJ |
11555 | for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn)) |
11556 | { | |
11557 | if (INSN_P (insn)) | |
11558 | { | |
11559 | if (FIND_REG_INC_NOTE (insn, reg)) | |
11560 | return 1; | |
11561 | else if (GET_CODE (insn) == CALL_INSN | |
c15b529f | 11562 | && !SIBLING_CALL_P (insn)) |
5e1bf043 | 11563 | return 1; |
36f7e964 AH |
11564 | else if (set_of (reg, insn) != NULL_RTX |
11565 | && !prologue_epilogue_contains (insn)) | |
5e1bf043 DJ |
11566 | return 1; |
11567 | } | |
11568 | } | |
11569 | return 0; | |
71f123ca | 11570 | } |
4697a36c | 11571 | \f |
8cd8f856 GK |
11572 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
11573 | static void | |
a2369ed3 | 11574 | rs6000_maybe_dead (rtx insn) |
8cd8f856 GK |
11575 | { |
11576 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
11577 | const0_rtx, | |
11578 | REG_NOTES (insn)); | |
11579 | } | |
11580 | ||
9ebbca7d | 11581 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 11582 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 11583 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
11584 | |
11585 | void | |
a2369ed3 | 11586 | rs6000_emit_load_toc_table (int fromprolog) |
c7ca610e | 11587 | { |
027fbf43 | 11588 | rtx dest, insn; |
1db02437 | 11589 | dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); |
c7ca610e | 11590 | |
20b71b17 AM |
11591 | if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
11592 | { | |
11593 | rtx temp = (fromprolog | |
11594 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
11595 | : gen_reg_rtx (Pmode)); | |
027fbf43 JJ |
11596 | insn = emit_insn (gen_load_toc_v4_pic_si (temp)); |
11597 | if (fromprolog) | |
11598 | rs6000_maybe_dead (insn); | |
11599 | insn = emit_move_insn (dest, temp); | |
11600 | if (fromprolog) | |
11601 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
11602 | } |
11603 | else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2) | |
11604 | { | |
11605 | char buf[30]; | |
11606 | rtx tempLR = (fromprolog | |
11607 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
11608 | : gen_reg_rtx (Pmode)); | |
11609 | rtx temp0 = (fromprolog | |
11610 | ? gen_rtx_REG (Pmode, 0) | |
11611 | : gen_reg_rtx (Pmode)); | |
11612 | rtx symF; | |
11613 | ||
11614 | /* possibly create the toc section */ | |
11615 | if (! toc_initialized) | |
38c1f2d7 | 11616 | { |
20b71b17 AM |
11617 | toc_section (); |
11618 | function_section (current_function_decl); | |
38c1f2d7 | 11619 | } |
9ebbca7d | 11620 | |
20b71b17 AM |
11621 | if (fromprolog) |
11622 | { | |
11623 | rtx symL; | |
38c1f2d7 | 11624 | |
20b71b17 AM |
11625 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); |
11626 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9ebbca7d | 11627 | |
20b71b17 AM |
11628 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
11629 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11630 | ||
11631 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, | |
11632 | symF))); | |
11633 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
11634 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
11635 | symL, | |
11636 | symF))); | |
9ebbca7d GK |
11637 | } |
11638 | else | |
20b71b17 AM |
11639 | { |
11640 | rtx tocsym; | |
11641 | static int reload_toc_labelno = 0; | |
11642 | ||
11643 | tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); | |
11644 | ||
11645 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); | |
11646 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11647 | ||
027fbf43 JJ |
11648 | emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym)); |
11649 | emit_move_insn (dest, tempLR); | |
11650 | emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest)); | |
20b71b17 | 11651 | } |
027fbf43 JJ |
11652 | insn = emit_insn (gen_addsi3 (dest, temp0, dest)); |
11653 | if (fromprolog) | |
11654 | rs6000_maybe_dead (insn); | |
9ebbca7d | 11655 | } |
20b71b17 AM |
11656 | else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC) |
11657 | { | |
11658 | /* This is for AIX code running in non-PIC ELF32. */ | |
11659 | char buf[30]; | |
11660 | rtx realsym; | |
11661 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
11662 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
11663 | ||
027fbf43 JJ |
11664 | insn = emit_insn (gen_elf_high (dest, realsym)); |
11665 | if (fromprolog) | |
11666 | rs6000_maybe_dead (insn); | |
11667 | insn = emit_insn (gen_elf_low (dest, dest, realsym)); | |
11668 | if (fromprolog) | |
11669 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
11670 | } |
11671 | else if (DEFAULT_ABI == ABI_AIX) | |
9ebbca7d GK |
11672 | { |
11673 | if (TARGET_32BIT) | |
027fbf43 | 11674 | insn = emit_insn (gen_load_toc_aix_si (dest)); |
9ebbca7d | 11675 | else |
027fbf43 JJ |
11676 | insn = emit_insn (gen_load_toc_aix_di (dest)); |
11677 | if (fromprolog) | |
11678 | rs6000_maybe_dead (insn); | |
9ebbca7d | 11679 | } |
20b71b17 AM |
11680 | else |
11681 | abort (); | |
9ebbca7d GK |
11682 | } |
11683 | ||
d1d0c603 JJ |
11684 | /* Emit instructions to restore the link register after determining where |
11685 | its value has been stored. */ | |
11686 | ||
11687 | void | |
11688 | rs6000_emit_eh_reg_restore (rtx source, rtx scratch) | |
11689 | { | |
11690 | rs6000_stack_t *info = rs6000_stack_info (); | |
11691 | rtx operands[2]; | |
11692 | ||
11693 | operands[0] = source; | |
11694 | operands[1] = scratch; | |
11695 | ||
11696 | if (info->lr_save_p) | |
11697 | { | |
11698 | rtx frame_rtx = stack_pointer_rtx; | |
11699 | HOST_WIDE_INT sp_offset = 0; | |
11700 | rtx tmp; | |
11701 | ||
11702 | if (frame_pointer_needed | |
11703 | || current_function_calls_alloca | |
11704 | || info->total_size > 32767) | |
11705 | { | |
11706 | emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx)); | |
11707 | frame_rtx = operands[1]; | |
11708 | } | |
11709 | else if (info->push_p) | |
11710 | sp_offset = info->total_size; | |
11711 | ||
11712 | tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset); | |
11713 | tmp = gen_rtx_MEM (Pmode, tmp); | |
11714 | emit_move_insn (tmp, operands[0]); | |
11715 | } | |
11716 | else | |
11717 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]); | |
11718 | } | |
11719 | ||
f103e34d GK |
11720 | static GTY(()) int set = -1; |
11721 | ||
9ebbca7d | 11722 | int |
863d938c | 11723 | get_TOC_alias_set (void) |
9ebbca7d | 11724 | { |
f103e34d GK |
11725 | if (set == -1) |
11726 | set = new_alias_set (); | |
11727 | return set; | |
9ebbca7d GK |
11728 | } |
11729 | ||
c1207243 | 11730 | /* This returns nonzero if the current function uses the TOC. This is |
3c9eb5f4 AM |
11731 | determined by the presence of (use (unspec ... UNSPEC_TOC)), which |
11732 | is generated by the ABI_V4 load_toc_* patterns. */ | |
c954844a | 11733 | #if TARGET_ELF |
3c9eb5f4 | 11734 | static int |
38f391a5 | 11735 | uses_TOC (void) |
9ebbca7d | 11736 | { |
c4501e62 | 11737 | rtx insn; |
38c1f2d7 | 11738 | |
c4501e62 JJ |
11739 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
11740 | if (INSN_P (insn)) | |
11741 | { | |
11742 | rtx pat = PATTERN (insn); | |
11743 | int i; | |
9ebbca7d | 11744 | |
c4501e62 JJ |
11745 | if (GET_CODE (pat) == PARALLEL) |
11746 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
11747 | { | |
11748 | rtx sub = XVECEXP (pat, 0, i); | |
11749 | if (GET_CODE (sub) == USE) | |
11750 | { | |
11751 | sub = XEXP (sub, 0); | |
11752 | if (GET_CODE (sub) == UNSPEC | |
11753 | && XINT (sub, 1) == UNSPEC_TOC) | |
11754 | return 1; | |
11755 | } | |
11756 | } | |
11757 | } | |
11758 | return 0; | |
9ebbca7d | 11759 | } |
c954844a | 11760 | #endif |
38c1f2d7 | 11761 | |
9ebbca7d | 11762 | rtx |
a2369ed3 | 11763 | create_TOC_reference (rtx symbol) |
9ebbca7d | 11764 | { |
a8a05998 ZW |
11765 | return gen_rtx_PLUS (Pmode, |
11766 | gen_rtx_REG (Pmode, TOC_REGISTER), | |
11767 | gen_rtx_CONST (Pmode, | |
11768 | gen_rtx_MINUS (Pmode, symbol, | |
b999aaeb | 11769 | gen_rtx_SYMBOL_REF (Pmode, toc_label_name)))); |
9ebbca7d | 11770 | } |
38c1f2d7 | 11771 | |
fc4767bb JJ |
11772 | /* If _Unwind_* has been called from within the same module, |
11773 | toc register is not guaranteed to be saved to 40(1) on function | |
11774 | entry. Save it there in that case. */ | |
c7ca610e | 11775 | |
9ebbca7d | 11776 | void |
863d938c | 11777 | rs6000_aix_emit_builtin_unwind_init (void) |
9ebbca7d GK |
11778 | { |
11779 | rtx mem; | |
11780 | rtx stack_top = gen_reg_rtx (Pmode); | |
11781 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
fc4767bb JJ |
11782 | rtx opcode = gen_reg_rtx (SImode); |
11783 | rtx tocompare = gen_reg_rtx (SImode); | |
11784 | rtx no_toc_save_needed = gen_label_rtx (); | |
9ebbca7d GK |
11785 | |
11786 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
11787 | emit_move_insn (stack_top, mem); | |
11788 | ||
fc4767bb JJ |
11789 | mem = gen_rtx_MEM (Pmode, |
11790 | gen_rtx_PLUS (Pmode, stack_top, | |
9ebbca7d GK |
11791 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); |
11792 | emit_move_insn (opcode_addr, mem); | |
fc4767bb JJ |
11793 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); |
11794 | emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014 | |
2496c7bd | 11795 | : 0xE8410028, SImode)); |
9ebbca7d | 11796 | |
fc4767bb | 11797 | do_compare_rtx_and_jump (opcode, tocompare, EQ, 1, |
06f4e019 | 11798 | SImode, NULL_RTX, NULL_RTX, |
fc4767bb | 11799 | no_toc_save_needed); |
9ebbca7d | 11800 | |
fc4767bb JJ |
11801 | mem = gen_rtx_MEM (Pmode, |
11802 | gen_rtx_PLUS (Pmode, stack_top, | |
11803 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
11804 | emit_move_insn (mem, gen_rtx_REG (Pmode, 2)); | |
11805 | emit_label (no_toc_save_needed); | |
9ebbca7d | 11806 | } |
38c1f2d7 | 11807 | \f |
ba4828e0 RK |
11808 | /* This ties together stack memory (MEM with an alias set of |
11809 | rs6000_sr_alias_set) and the change to the stack pointer. */ | |
11810 | ||
9ebbca7d | 11811 | static void |
863d938c | 11812 | rs6000_emit_stack_tie (void) |
9ebbca7d | 11813 | { |
ba4828e0 RK |
11814 | rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); |
11815 | ||
11816 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
11817 | emit_insn (gen_stack_tie (mem)); |
11818 | } | |
38c1f2d7 | 11819 | |
9ebbca7d GK |
11820 | /* Emit the correct code for allocating stack space, as insns. |
11821 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
11822 | The generated code may use hard register 0 as a temporary. */ | |
11823 | ||
11824 | static void | |
a2369ed3 | 11825 | rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12) |
38c1f2d7 | 11826 | { |
9ebbca7d GK |
11827 | rtx insn; |
11828 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
11829 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
11830 | rtx todec = GEN_INT (-size); | |
a157febd GK |
11831 | |
11832 | if (current_function_limit_stack) | |
11833 | { | |
11834 | if (REG_P (stack_limit_rtx) | |
11835 | && REGNO (stack_limit_rtx) > 1 | |
11836 | && REGNO (stack_limit_rtx) <= 31) | |
11837 | { | |
5b71a4e7 | 11838 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
11839 | ? gen_addsi3 (tmp_reg, |
11840 | stack_limit_rtx, | |
11841 | GEN_INT (size)) | |
11842 | : gen_adddi3 (tmp_reg, | |
11843 | stack_limit_rtx, | |
11844 | GEN_INT (size))); | |
5b71a4e7 | 11845 | |
9ebbca7d GK |
11846 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, |
11847 | const0_rtx)); | |
a157febd GK |
11848 | } |
11849 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 11850 | && TARGET_32BIT |
f607bc57 | 11851 | && DEFAULT_ABI == ABI_V4) |
a157febd | 11852 | { |
9ebbca7d GK |
11853 | rtx toload = gen_rtx_CONST (VOIDmode, |
11854 | gen_rtx_PLUS (Pmode, | |
11855 | stack_limit_rtx, | |
11856 | GEN_INT (size))); | |
5b71a4e7 | 11857 | |
9ebbca7d GK |
11858 | emit_insn (gen_elf_high (tmp_reg, toload)); |
11859 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
11860 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
11861 | const0_rtx)); | |
a157febd GK |
11862 | } |
11863 | else | |
11864 | warning ("stack limit expression is not supported"); | |
11865 | } | |
11866 | ||
9ebbca7d GK |
11867 | if (copy_r12 || ! TARGET_UPDATE) |
11868 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
11869 | ||
38c1f2d7 MM |
11870 | if (TARGET_UPDATE) |
11871 | { | |
9ebbca7d | 11872 | if (size > 32767) |
38c1f2d7 | 11873 | { |
9ebbca7d GK |
11874 | /* Need a note here so that try_split doesn't get confused. */ |
11875 | if (get_last_insn() == NULL_RTX) | |
2e040219 | 11876 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d GK |
11877 | insn = emit_move_insn (tmp_reg, todec); |
11878 | try_split (PATTERN (insn), insn, 0); | |
11879 | todec = tmp_reg; | |
38c1f2d7 | 11880 | } |
5b71a4e7 DE |
11881 | |
11882 | insn = emit_insn (TARGET_32BIT | |
11883 | ? gen_movsi_update (stack_reg, stack_reg, | |
11884 | todec, stack_reg) | |
11885 | : gen_movdi_update (stack_reg, stack_reg, | |
9ebbca7d | 11886 | todec, stack_reg)); |
38c1f2d7 MM |
11887 | } |
11888 | else | |
11889 | { | |
5b71a4e7 DE |
11890 | insn = emit_insn (TARGET_32BIT |
11891 | ? gen_addsi3 (stack_reg, stack_reg, todec) | |
11892 | : gen_adddi3 (stack_reg, stack_reg, todec)); | |
9ebbca7d GK |
11893 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), |
11894 | gen_rtx_REG (Pmode, 12)); | |
11895 | } | |
5b71a4e7 | 11896 | |
9ebbca7d GK |
11897 | RTX_FRAME_RELATED_P (insn) = 1; |
11898 | REG_NOTES (insn) = | |
11899 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
11900 | gen_rtx_SET (VOIDmode, stack_reg, | |
11901 | gen_rtx_PLUS (Pmode, stack_reg, | |
11902 | GEN_INT (-size))), | |
11903 | REG_NOTES (insn)); | |
11904 | } | |
11905 | ||
a4f6c312 SS |
11906 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced |
11907 | with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 | |
11908 | is not NULL. It would be nice if dwarf2out_frame_debug_expr could | |
11909 | deduce these equivalences by itself so it wasn't necessary to hold | |
11910 | its hand so much. */ | |
9ebbca7d GK |
11911 | |
11912 | static void | |
a2369ed3 DJ |
11913 | rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val, |
11914 | rtx reg2, rtx rreg) | |
9ebbca7d GK |
11915 | { |
11916 | rtx real, temp; | |
11917 | ||
e56c4463 JL |
11918 | /* copy_rtx will not make unique copies of registers, so we need to |
11919 | ensure we don't have unwanted sharing here. */ | |
11920 | if (reg == reg2) | |
11921 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
11922 | ||
11923 | if (reg == rreg) | |
11924 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
11925 | ||
9ebbca7d GK |
11926 | real = copy_rtx (PATTERN (insn)); |
11927 | ||
89e7058f AH |
11928 | if (reg2 != NULL_RTX) |
11929 | real = replace_rtx (real, reg2, rreg); | |
11930 | ||
9ebbca7d GK |
11931 | real = replace_rtx (real, reg, |
11932 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, | |
11933 | STACK_POINTER_REGNUM), | |
11934 | GEN_INT (val))); | |
11935 | ||
11936 | /* We expect that 'real' is either a SET or a PARALLEL containing | |
11937 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
11938 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
11939 | ||
11940 | if (GET_CODE (real) == SET) | |
11941 | { | |
11942 | rtx set = real; | |
11943 | ||
11944 | temp = simplify_rtx (SET_SRC (set)); | |
11945 | if (temp) | |
11946 | SET_SRC (set) = temp; | |
11947 | temp = simplify_rtx (SET_DEST (set)); | |
11948 | if (temp) | |
11949 | SET_DEST (set) = temp; | |
11950 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 11951 | { |
9ebbca7d GK |
11952 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
11953 | if (temp) | |
11954 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 11955 | } |
38c1f2d7 | 11956 | } |
9ebbca7d GK |
11957 | else if (GET_CODE (real) == PARALLEL) |
11958 | { | |
11959 | int i; | |
11960 | for (i = 0; i < XVECLEN (real, 0); i++) | |
11961 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
11962 | { | |
11963 | rtx set = XVECEXP (real, 0, i); | |
11964 | ||
11965 | temp = simplify_rtx (SET_SRC (set)); | |
11966 | if (temp) | |
11967 | SET_SRC (set) = temp; | |
11968 | temp = simplify_rtx (SET_DEST (set)); | |
11969 | if (temp) | |
11970 | SET_DEST (set) = temp; | |
11971 | if (GET_CODE (SET_DEST (set)) == MEM) | |
11972 | { | |
11973 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
11974 | if (temp) | |
11975 | XEXP (SET_DEST (set), 0) = temp; | |
11976 | } | |
11977 | RTX_FRAME_RELATED_P (set) = 1; | |
11978 | } | |
11979 | } | |
11980 | else | |
a4f6c312 | 11981 | abort (); |
c19de7aa AH |
11982 | |
11983 | if (TARGET_SPE) | |
11984 | real = spe_synthesize_frame_save (real); | |
11985 | ||
9ebbca7d GK |
11986 | RTX_FRAME_RELATED_P (insn) = 1; |
11987 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
11988 | real, | |
11989 | REG_NOTES (insn)); | |
38c1f2d7 MM |
11990 | } |
11991 | ||
c19de7aa AH |
11992 | /* Given an SPE frame note, return a PARALLEL of SETs with the |
11993 | original note, plus a synthetic register save. */ | |
11994 | ||
11995 | static rtx | |
a2369ed3 | 11996 | spe_synthesize_frame_save (rtx real) |
c19de7aa AH |
11997 | { |
11998 | rtx synth, offset, reg, real2; | |
11999 | ||
12000 | if (GET_CODE (real) != SET | |
12001 | || GET_MODE (SET_SRC (real)) != V2SImode) | |
12002 | return real; | |
12003 | ||
12004 | /* For the SPE, registers saved in 64-bits, get a PARALLEL for their | |
12005 | frame related note. The parallel contains a set of the register | |
41f3a930 | 12006 | being saved, and another set to a synthetic register (n+1200). |
c19de7aa AH |
12007 | This is so we can differentiate between 64-bit and 32-bit saves. |
12008 | Words cannot describe this nastiness. */ | |
12009 | ||
12010 | if (GET_CODE (SET_DEST (real)) != MEM | |
12011 | || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS | |
12012 | || GET_CODE (SET_SRC (real)) != REG) | |
12013 | abort (); | |
12014 | ||
12015 | /* Transform: | |
12016 | (set (mem (plus (reg x) (const y))) | |
12017 | (reg z)) | |
12018 | into: | |
12019 | (set (mem (plus (reg x) (const y+4))) | |
41f3a930 | 12020 | (reg z+1200)) |
c19de7aa AH |
12021 | */ |
12022 | ||
12023 | real2 = copy_rtx (real); | |
12024 | PUT_MODE (SET_DEST (real2), SImode); | |
12025 | reg = SET_SRC (real2); | |
12026 | real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg))); | |
12027 | synth = copy_rtx (real2); | |
12028 | ||
12029 | if (BYTES_BIG_ENDIAN) | |
12030 | { | |
12031 | offset = XEXP (XEXP (SET_DEST (real2), 0), 1); | |
12032 | real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4)); | |
12033 | } | |
12034 | ||
12035 | reg = SET_SRC (synth); | |
41f3a930 | 12036 | |
c19de7aa | 12037 | synth = replace_rtx (synth, reg, |
41f3a930 | 12038 | gen_rtx_REG (SImode, REGNO (reg) + 1200)); |
c19de7aa AH |
12039 | |
12040 | offset = XEXP (XEXP (SET_DEST (synth), 0), 1); | |
12041 | synth = replace_rtx (synth, offset, | |
12042 | GEN_INT (INTVAL (offset) | |
12043 | + (BYTES_BIG_ENDIAN ? 0 : 4))); | |
12044 | ||
12045 | RTX_FRAME_RELATED_P (synth) = 1; | |
12046 | RTX_FRAME_RELATED_P (real2) = 1; | |
12047 | if (BYTES_BIG_ENDIAN) | |
12048 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2)); | |
12049 | else | |
12050 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth)); | |
12051 | ||
12052 | return real; | |
12053 | } | |
12054 | ||
00b960c7 AH |
12055 | /* Returns an insn that has a vrsave set operation with the |
12056 | appropriate CLOBBERs. */ | |
12057 | ||
12058 | static rtx | |
a2369ed3 | 12059 | generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep) |
00b960c7 AH |
12060 | { |
12061 | int nclobs, i; | |
12062 | rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1]; | |
a004eb82 | 12063 | rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
00b960c7 | 12064 | |
a004eb82 AH |
12065 | clobs[0] |
12066 | = gen_rtx_SET (VOIDmode, | |
12067 | vrsave, | |
12068 | gen_rtx_UNSPEC_VOLATILE (SImode, | |
12069 | gen_rtvec (2, reg, vrsave), | |
12070 | 30)); | |
00b960c7 AH |
12071 | |
12072 | nclobs = 1; | |
12073 | ||
9aa86737 AH |
12074 | /* We need to clobber the registers in the mask so the scheduler |
12075 | does not move sets to VRSAVE before sets of AltiVec registers. | |
12076 | ||
12077 | However, if the function receives nonlocal gotos, reload will set | |
12078 | all call saved registers live. We will end up with: | |
12079 | ||
12080 | (set (reg 999) (mem)) | |
12081 | (parallel [ (set (reg vrsave) (unspec blah)) | |
12082 | (clobber (reg 999))]) | |
12083 | ||
12084 | The clobber will cause the store into reg 999 to be dead, and | |
12085 | flow will attempt to delete an epilogue insn. In this case, we | |
12086 | need an unspec use/set of the register. */ | |
00b960c7 AH |
12087 | |
12088 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
44688022 | 12089 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) |
9aa86737 AH |
12090 | { |
12091 | if (!epiloguep || call_used_regs [i]) | |
12092 | clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode, | |
12093 | gen_rtx_REG (V4SImode, i)); | |
12094 | else | |
12095 | { | |
12096 | rtx reg = gen_rtx_REG (V4SImode, i); | |
9aa86737 AH |
12097 | |
12098 | clobs[nclobs++] | |
a004eb82 AH |
12099 | = gen_rtx_SET (VOIDmode, |
12100 | reg, | |
12101 | gen_rtx_UNSPEC (V4SImode, | |
12102 | gen_rtvec (1, reg), 27)); | |
9aa86737 AH |
12103 | } |
12104 | } | |
00b960c7 AH |
12105 | |
12106 | insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs)); | |
12107 | ||
12108 | for (i = 0; i < nclobs; ++i) | |
12109 | XVECEXP (insn, 0, i) = clobs[i]; | |
12110 | ||
12111 | return insn; | |
12112 | } | |
12113 | ||
89e7058f AH |
12114 | /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes. |
12115 | Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */ | |
12116 | ||
12117 | static void | |
a2369ed3 | 12118 | emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode, |
d1d0c603 | 12119 | unsigned int regno, int offset, HOST_WIDE_INT total_size) |
89e7058f AH |
12120 | { |
12121 | rtx reg, offset_rtx, insn, mem, addr, int_rtx; | |
12122 | rtx replacea, replaceb; | |
12123 | ||
12124 | int_rtx = GEN_INT (offset); | |
12125 | ||
12126 | /* Some cases that need register indexed addressing. */ | |
12127 | if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
a3170dc6 AH |
12128 | || (TARGET_SPE_ABI |
12129 | && SPE_VECTOR_MODE (mode) | |
12130 | && !SPE_CONST_OFFSET_OK (offset))) | |
89e7058f AH |
12131 | { |
12132 | /* Whomever calls us must make sure r11 is available in the | |
12133 | flow path of instructions in the prologue. */ | |
12134 | offset_rtx = gen_rtx_REG (Pmode, 11); | |
12135 | emit_move_insn (offset_rtx, int_rtx); | |
12136 | ||
12137 | replacea = offset_rtx; | |
12138 | replaceb = int_rtx; | |
12139 | } | |
12140 | else | |
12141 | { | |
12142 | offset_rtx = int_rtx; | |
12143 | replacea = NULL_RTX; | |
12144 | replaceb = NULL_RTX; | |
12145 | } | |
12146 | ||
12147 | reg = gen_rtx_REG (mode, regno); | |
12148 | addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx); | |
12149 | mem = gen_rtx_MEM (mode, addr); | |
12150 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12151 | ||
12152 | insn = emit_move_insn (mem, reg); | |
12153 | ||
12154 | rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb); | |
12155 | } | |
12156 | ||
a3170dc6 AH |
12157 | /* Emit an offset memory reference suitable for a frame store, while |
12158 | converting to a valid addressing mode. */ | |
12159 | ||
12160 | static rtx | |
a2369ed3 | 12161 | gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset) |
a3170dc6 AH |
12162 | { |
12163 | rtx int_rtx, offset_rtx; | |
12164 | ||
12165 | int_rtx = GEN_INT (offset); | |
12166 | ||
12167 | if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode)) | |
12168 | { | |
12169 | offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12170 | emit_move_insn (offset_rtx, int_rtx); | |
12171 | } | |
12172 | else | |
12173 | offset_rtx = int_rtx; | |
12174 | ||
12175 | return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx)); | |
12176 | } | |
12177 | ||
9ebbca7d GK |
12178 | /* Emit function prologue as insns. */ |
12179 | ||
9878760c | 12180 | void |
863d938c | 12181 | rs6000_emit_prologue (void) |
9878760c | 12182 | { |
4697a36c | 12183 | rs6000_stack_t *info = rs6000_stack_info (); |
0e67400a | 12184 | enum machine_mode reg_mode = Pmode; |
327e5343 | 12185 | int reg_size = TARGET_32BIT ? 4 : 8; |
9ebbca7d GK |
12186 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); |
12187 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
12188 | rtx frame_reg_rtx = sp_reg_rtx; | |
b78d48dd | 12189 | rtx cr_save_rtx = NULL_RTX; |
9ebbca7d GK |
12190 | rtx insn; |
12191 | int saving_FPRs_inline; | |
12192 | int using_store_multiple; | |
12193 | HOST_WIDE_INT sp_offset = 0; | |
12194 | ||
c19de7aa | 12195 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12196 | { |
12197 | reg_mode = V2SImode; | |
12198 | reg_size = 8; | |
12199 | } | |
12200 | ||
9ebbca7d | 12201 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
12202 | && (!TARGET_SPE_ABI |
12203 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
12204 | && info->first_gp_reg_save < 31); |
12205 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
8c29550d | 12206 | || FP_SAVE_INLINE (info->first_fp_reg_save) |
acd0b319 | 12207 | || current_function_calls_eh_return |
8c29550d | 12208 | || cfun->machine->ra_need_lr); |
9ebbca7d GK |
12209 | |
12210 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
fc4767bb | 12211 | if (info->push_p |
acd0b319 AM |
12212 | && (DEFAULT_ABI == ABI_V4 |
12213 | || current_function_calls_eh_return)) | |
9ebbca7d GK |
12214 | { |
12215 | if (info->total_size < 32767) | |
12216 | sp_offset = info->total_size; | |
12217 | else | |
12218 | frame_reg_rtx = frame_ptr_rtx; | |
12219 | rs6000_emit_allocate_stack (info->total_size, | |
12220 | (frame_reg_rtx != sp_reg_rtx | |
12221 | && (info->cr_save_p | |
12222 | || info->lr_save_p | |
12223 | || info->first_fp_reg_save < 64 | |
12224 | || info->first_gp_reg_save < 32 | |
12225 | ))); | |
12226 | if (frame_reg_rtx != sp_reg_rtx) | |
12227 | rs6000_emit_stack_tie (); | |
12228 | } | |
12229 | ||
9aa86737 AH |
12230 | /* Save AltiVec registers if needed. */ |
12231 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
12232 | { | |
12233 | int i; | |
12234 | ||
12235 | /* There should be a non inline version of this, for when we | |
12236 | are saving lots of vector registers. */ | |
12237 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
12238 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
12239 | { | |
12240 | rtx areg, savereg, mem; | |
12241 | int offset; | |
12242 | ||
12243 | offset = info->altivec_save_offset + sp_offset | |
12244 | + 16 * (i - info->first_altivec_reg_save); | |
12245 | ||
12246 | savereg = gen_rtx_REG (V4SImode, i); | |
12247 | ||
12248 | areg = gen_rtx_REG (Pmode, 0); | |
12249 | emit_move_insn (areg, GEN_INT (offset)); | |
12250 | ||
12251 | /* AltiVec addressing mode is [reg+reg]. */ | |
12252 | mem = gen_rtx_MEM (V4SImode, | |
12253 | gen_rtx_PLUS (Pmode, frame_reg_rtx, areg)); | |
12254 | ||
12255 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12256 | ||
12257 | insn = emit_move_insn (mem, savereg); | |
12258 | ||
5c242421 SB |
12259 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
12260 | areg, GEN_INT (offset)); | |
9aa86737 AH |
12261 | } |
12262 | } | |
12263 | ||
12264 | /* VRSAVE is a bit vector representing which AltiVec registers | |
12265 | are used. The OS uses this to determine which vector | |
12266 | registers to save on a context switch. We need to save | |
12267 | VRSAVE on the stack frame, add whatever AltiVec registers we | |
12268 | used in this function, and do the corresponding magic in the | |
12269 | epilogue. */ | |
12270 | ||
4d774ff8 HP |
12271 | if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE |
12272 | && info->vrsave_mask != 0) | |
9aa86737 | 12273 | { |
a004eb82 | 12274 | rtx reg, mem, vrsave; |
9aa86737 AH |
12275 | int offset; |
12276 | ||
12277 | /* Get VRSAVE onto a GPR. */ | |
12278 | reg = gen_rtx_REG (SImode, 12); | |
a004eb82 | 12279 | vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
b188f760 AH |
12280 | if (TARGET_MACHO) |
12281 | emit_insn (gen_get_vrsave_internal (reg)); | |
12282 | else | |
12283 | emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave)); | |
9aa86737 AH |
12284 | |
12285 | /* Save VRSAVE. */ | |
12286 | offset = info->vrsave_save_offset + sp_offset; | |
12287 | mem | |
12288 | = gen_rtx_MEM (SImode, | |
12289 | gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset))); | |
12290 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12291 | insn = emit_move_insn (mem, reg); | |
12292 | ||
12293 | /* Include the registers in the mask. */ | |
12294 | emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask))); | |
12295 | ||
12296 | insn = emit_insn (generate_set_vrsave (reg, info, 0)); | |
12297 | } | |
12298 | ||
9ebbca7d GK |
12299 | /* If we use the link register, get it into r0. */ |
12300 | if (info->lr_save_p) | |
71f123ca | 12301 | emit_move_insn (gen_rtx_REG (Pmode, 0), |
9ebbca7d GK |
12302 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); |
12303 | ||
12304 | /* If we need to save CR, put it into r12. */ | |
12305 | if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) | |
12306 | { | |
12307 | cr_save_rtx = gen_rtx_REG (SImode, 12); | |
12308 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
12309 | } | |
12310 | ||
a4f6c312 SS |
12311 | /* Do any required saving of fpr's. If only one or two to save, do |
12312 | it ourselves. Otherwise, call function. */ | |
9ebbca7d GK |
12313 | if (saving_FPRs_inline) |
12314 | { | |
12315 | int i; | |
12316 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12317 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
12318 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
89e7058f AH |
12319 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode, |
12320 | info->first_fp_reg_save + i, | |
12321 | info->fp_save_offset + sp_offset + 8 * i, | |
12322 | info->total_size); | |
9ebbca7d GK |
12323 | } |
12324 | else if (info->first_fp_reg_save != 64) | |
12325 | { | |
12326 | int i; | |
12327 | char rname[30]; | |
520a57c8 | 12328 | const char *alloc_rname; |
9ebbca7d GK |
12329 | rtvec p; |
12330 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
12331 | ||
12332 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
12333 | gen_rtx_REG (Pmode, | |
12334 | LINK_REGISTER_REGNUM)); | |
12335 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
12336 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
a8a05998 | 12337 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
12338 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
12339 | gen_rtx_SYMBOL_REF (Pmode, | |
12340 | alloc_rname)); | |
12341 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12342 | { | |
12343 | rtx addr, reg, mem; | |
12344 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
12345 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12346 | GEN_INT (info->fp_save_offset | |
12347 | + sp_offset + 8*i)); | |
12348 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 12349 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12350 | |
12351 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
12352 | } | |
12353 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
12354 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12355 | NULL_RTX, NULL_RTX); | |
12356 | } | |
b6c9286a | 12357 | |
9ebbca7d GK |
12358 | /* Save GPRs. This is done as a PARALLEL if we are using |
12359 | the store-multiple instructions. */ | |
12360 | if (using_store_multiple) | |
b6c9286a | 12361 | { |
308c142a | 12362 | rtvec p; |
9ebbca7d GK |
12363 | int i; |
12364 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
9ebbca7d GK |
12365 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) |
12366 | { | |
12367 | rtx addr, reg, mem; | |
12368 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
12369 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12370 | GEN_INT (info->gp_save_offset | |
12371 | + sp_offset | |
12372 | + reg_size * i)); | |
12373 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 12374 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12375 | |
12376 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
12377 | } | |
12378 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
12379 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12380 | NULL_RTX, NULL_RTX); | |
b6c9286a MM |
12381 | } |
12382 | else | |
12383 | { | |
9ebbca7d GK |
12384 | int i; |
12385 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
12386 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
b4db40bf JJ |
12387 | && (! call_used_regs[info->first_gp_reg_save+i] |
12388 | || (i+info->first_gp_reg_save | |
12389 | == RS6000_PIC_OFFSET_TABLE_REGNUM | |
12390 | && TARGET_TOC && TARGET_MINIMAL_TOC))) | |
1db02437 | 12391 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 12392 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 12393 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
a3170dc6 AH |
12394 | { |
12395 | rtx addr, reg, mem; | |
12396 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
12397 | ||
c19de7aa | 12398 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12399 | { |
12400 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
12401 | rtx b; | |
12402 | ||
12403 | if (!SPE_CONST_OFFSET_OK (offset)) | |
12404 | { | |
12405 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12406 | emit_move_insn (b, GEN_INT (offset)); | |
12407 | } | |
12408 | else | |
12409 | b = GEN_INT (offset); | |
12410 | ||
12411 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
12412 | mem = gen_rtx_MEM (V2SImode, addr); | |
12413 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12414 | insn = emit_move_insn (mem, reg); | |
12415 | ||
12416 | if (GET_CODE (b) == CONST_INT) | |
12417 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12418 | NULL_RTX, NULL_RTX); | |
12419 | else | |
12420 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12421 | b, GEN_INT (offset)); | |
12422 | } | |
12423 | else | |
12424 | { | |
12425 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12426 | GEN_INT (info->gp_save_offset | |
12427 | + sp_offset | |
12428 | + reg_size * i)); | |
12429 | mem = gen_rtx_MEM (reg_mode, addr); | |
12430 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12431 | ||
12432 | insn = emit_move_insn (mem, reg); | |
12433 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12434 | NULL_RTX, NULL_RTX); | |
12435 | } | |
12436 | } | |
9ebbca7d GK |
12437 | } |
12438 | ||
83720594 RH |
12439 | /* ??? There's no need to emit actual instructions here, but it's the |
12440 | easiest way to get the frame unwind information emitted. */ | |
12441 | if (current_function_calls_eh_return) | |
12442 | { | |
78e1b90d DE |
12443 | unsigned int i, regno; |
12444 | ||
fc4767bb JJ |
12445 | /* In AIX ABI we need to pretend we save r2 here. */ |
12446 | if (TARGET_AIX) | |
12447 | { | |
12448 | rtx addr, reg, mem; | |
12449 | ||
12450 | reg = gen_rtx_REG (reg_mode, 2); | |
12451 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12452 | GEN_INT (sp_offset + 5 * reg_size)); | |
12453 | mem = gen_rtx_MEM (reg_mode, addr); | |
12454 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12455 | ||
12456 | insn = emit_move_insn (mem, reg); | |
12457 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12458 | NULL_RTX, NULL_RTX); | |
12459 | PATTERN (insn) = gen_blockage (); | |
12460 | } | |
12461 | ||
83720594 RH |
12462 | for (i = 0; ; ++i) |
12463 | { | |
83720594 RH |
12464 | regno = EH_RETURN_DATA_REGNO (i); |
12465 | if (regno == INVALID_REGNUM) | |
12466 | break; | |
12467 | ||
89e7058f AH |
12468 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno, |
12469 | info->ehrd_offset + sp_offset | |
12470 | + reg_size * (int) i, | |
12471 | info->total_size); | |
83720594 RH |
12472 | } |
12473 | } | |
12474 | ||
9ebbca7d GK |
12475 | /* Save lr if we used it. */ |
12476 | if (info->lr_save_p) | |
12477 | { | |
12478 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12479 | GEN_INT (info->lr_save_offset + sp_offset)); | |
12480 | rtx reg = gen_rtx_REG (Pmode, 0); | |
12481 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
12482 | /* This should not be of rs6000_sr_alias_set, because of | |
12483 | __builtin_return_address. */ | |
12484 | ||
12485 | insn = emit_move_insn (mem, reg); | |
12486 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
12487 | reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
12488 | } | |
12489 | ||
12490 | /* Save CR if we use any that must be preserved. */ | |
12491 | if (info->cr_save_p) | |
12492 | { | |
12493 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12494 | GEN_INT (info->cr_save_offset + sp_offset)); | |
12495 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
12496 | |
12497 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
12498 | |
12499 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
12500 | that it's free. */ | |
12501 | if (REGNO (frame_reg_rtx) == 12) | |
12502 | { | |
12503 | cr_save_rtx = gen_rtx_REG (SImode, 0); | |
12504 | emit_insn (gen_movesi_from_cr (cr_save_rtx)); | |
12505 | } | |
12506 | insn = emit_move_insn (mem, cr_save_rtx); | |
12507 | ||
12508 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
615158e2 JJ |
12509 | to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'. |
12510 | But that's OK. All we have to do is specify that _one_ condition | |
12511 | code register is saved in this stack slot. The thrower's epilogue | |
a1dc9455 FS |
12512 | will then restore all the call-saved registers. |
12513 | We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */ | |
9ebbca7d | 12514 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
a1dc9455 | 12515 | cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO)); |
9ebbca7d GK |
12516 | } |
12517 | ||
12518 | /* Update stack and set back pointer unless this is V.4, | |
12519 | for which it was done previously. */ | |
fc4767bb JJ |
12520 | if (info->push_p |
12521 | && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return)) | |
9ebbca7d GK |
12522 | rs6000_emit_allocate_stack (info->total_size, FALSE); |
12523 | ||
12524 | /* Set frame pointer, if needed. */ | |
12525 | if (frame_pointer_needed) | |
12526 | { | |
a3170dc6 | 12527 | insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM), |
9ebbca7d GK |
12528 | sp_reg_rtx); |
12529 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 12530 | } |
9878760c | 12531 | |
1db02437 | 12532 | /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
9ebbca7d | 12533 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) |
f607bc57 | 12534 | || (DEFAULT_ABI == ABI_V4 && flag_pic == 1 |
1db02437 | 12535 | && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])) |
9ebbca7d GK |
12536 | { |
12537 | /* If emit_load_toc_table will use the link register, we need to save | |
c4501e62 | 12538 | it. We use R12 for this purpose because emit_load_toc_table |
9ebbca7d GK |
12539 | can use register 0. This allows us to use a plain 'blr' to return |
12540 | from the procedure more often. */ | |
f1384257 AM |
12541 | int save_LR_around_toc_setup = (TARGET_ELF |
12542 | && DEFAULT_ABI != ABI_AIX | |
12543 | && flag_pic | |
d5fa86ba GK |
12544 | && ! info->lr_save_p |
12545 | && EXIT_BLOCK_PTR->pred != NULL); | |
9ebbca7d | 12546 | if (save_LR_around_toc_setup) |
c4501e62 JJ |
12547 | { |
12548 | rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
12549 | rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr)); | |
12550 | rs6000_emit_load_toc_table (TRUE); | |
12551 | rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx)); | |
12552 | } | |
12553 | else | |
12554 | rs6000_emit_load_toc_table (TRUE); | |
9ebbca7d | 12555 | } |
ee890fe2 | 12556 | |
fcce224d | 12557 | #if TARGET_MACHO |
ee890fe2 SS |
12558 | if (DEFAULT_ABI == ABI_DARWIN |
12559 | && flag_pic && current_function_uses_pic_offset_table) | |
12560 | { | |
12561 | rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
f099d360 | 12562 | const char *picbase = machopic_function_base_name (); |
6788f5ca | 12563 | rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase); |
ee890fe2 | 12564 | |
f51eee6a | 12565 | rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src))); |
ee890fe2 SS |
12566 | |
12567 | rs6000_maybe_dead ( | |
1db02437 | 12568 | emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM), |
ee890fe2 SS |
12569 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM))); |
12570 | } | |
fcce224d | 12571 | #endif |
9ebbca7d GK |
12572 | } |
12573 | ||
9ebbca7d | 12574 | /* Write function prologue. */ |
a4f6c312 | 12575 | |
08c148a8 | 12576 | static void |
a2369ed3 DJ |
12577 | rs6000_output_function_prologue (FILE *file, |
12578 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) | |
9ebbca7d GK |
12579 | { |
12580 | rs6000_stack_t *info = rs6000_stack_info (); | |
12581 | ||
4697a36c MM |
12582 | if (TARGET_DEBUG_STACK) |
12583 | debug_stack_info (info); | |
9878760c | 12584 | |
a4f6c312 SS |
12585 | /* Write .extern for any function we will call to save and restore |
12586 | fp values. */ | |
12587 | if (info->first_fp_reg_save < 64 | |
12588 | && !FP_SAVE_INLINE (info->first_fp_reg_save)) | |
4d30c363 | 12589 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c | 12590 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
a4f6c312 SS |
12591 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, |
12592 | RESTORE_FP_SUFFIX); | |
9878760c | 12593 | |
c764f757 RK |
12594 | /* Write .extern for AIX common mode routines, if needed. */ |
12595 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
12596 | { | |
f6709c70 JW |
12597 | fputs ("\t.extern __mulh\n", file); |
12598 | fputs ("\t.extern __mull\n", file); | |
12599 | fputs ("\t.extern __divss\n", file); | |
12600 | fputs ("\t.extern __divus\n", file); | |
12601 | fputs ("\t.extern __quoss\n", file); | |
12602 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
12603 | common_mode_defined = 1; |
12604 | } | |
9878760c | 12605 | |
9ebbca7d | 12606 | if (! HAVE_prologue) |
979721f8 | 12607 | { |
9ebbca7d | 12608 | start_sequence (); |
9dda4cc8 | 12609 | |
a4f6c312 SS |
12610 | /* A NOTE_INSN_DELETED is supposed to be at the start and end of |
12611 | the "toplevel" insn chain. */ | |
2e040219 | 12612 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 12613 | rs6000_emit_prologue (); |
2e040219 | 12614 | emit_note (NOTE_INSN_DELETED); |
178c3eff | 12615 | |
a3c9585f | 12616 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
178c3eff DJ |
12617 | { |
12618 | rtx insn; | |
12619 | unsigned addr = 0; | |
12620 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
12621 | { | |
12622 | INSN_ADDRESSES_NEW (insn, addr); | |
12623 | addr += 4; | |
12624 | } | |
12625 | } | |
9dda4cc8 | 12626 | |
9ebbca7d | 12627 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
12628 | debug_rtx_list (get_insns (), 100); |
12629 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 12630 | end_sequence (); |
979721f8 MM |
12631 | } |
12632 | ||
9ebbca7d GK |
12633 | rs6000_pic_labelno++; |
12634 | } | |
12635 | ||
12636 | /* Emit function epilogue as insns. | |
9878760c | 12637 | |
9ebbca7d GK |
12638 | At present, dwarf2out_frame_debug_expr doesn't understand |
12639 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
12640 | anywhere in the epilogue. Most of the insns below would in any case | |
12641 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 12642 | |
9ebbca7d | 12643 | void |
a2369ed3 | 12644 | rs6000_emit_epilogue (int sibcall) |
9ebbca7d GK |
12645 | { |
12646 | rs6000_stack_t *info; | |
12647 | int restoring_FPRs_inline; | |
12648 | int using_load_multiple; | |
12649 | int using_mfcr_multiple; | |
12650 | int use_backchain_to_restore_sp; | |
12651 | int sp_offset = 0; | |
12652 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
12653 | rtx frame_reg_rtx = sp_reg_rtx; | |
0e67400a | 12654 | enum machine_mode reg_mode = Pmode; |
327e5343 | 12655 | int reg_size = TARGET_32BIT ? 4 : 8; |
9ebbca7d GK |
12656 | int i; |
12657 | ||
c19de7aa AH |
12658 | info = rs6000_stack_info (); |
12659 | ||
12660 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) | |
a3170dc6 AH |
12661 | { |
12662 | reg_mode = V2SImode; | |
12663 | reg_size = 8; | |
12664 | } | |
12665 | ||
9ebbca7d | 12666 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
12667 | && (!TARGET_SPE_ABI |
12668 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
12669 | && info->first_gp_reg_save < 31); |
12670 | restoring_FPRs_inline = (sibcall | |
83720594 | 12671 | || current_function_calls_eh_return |
9ebbca7d GK |
12672 | || info->first_fp_reg_save == 64 |
12673 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
12674 | use_backchain_to_restore_sp = (frame_pointer_needed | |
12675 | || current_function_calls_alloca | |
12676 | || info->total_size > 32767); | |
12677 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
12678 | || rs6000_cpu == PROCESSOR_PPC603 | |
12679 | || rs6000_cpu == PROCESSOR_PPC750 | |
12680 | || optimize_size); | |
12681 | ||
12682 | /* If we have a frame pointer, a call to alloca, or a large stack | |
12683 | frame, restore the old stack pointer using the backchain. Otherwise, | |
12684 | we know what size to update it with. */ | |
12685 | if (use_backchain_to_restore_sp) | |
bacbde18 | 12686 | { |
9ebbca7d GK |
12687 | /* Under V.4, don't reset the stack pointer until after we're done |
12688 | loading the saved registers. */ | |
f607bc57 | 12689 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d | 12690 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); |
4697a36c | 12691 | |
9ebbca7d GK |
12692 | emit_move_insn (frame_reg_rtx, |
12693 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
12694 | ||
bacbde18 | 12695 | } |
9ebbca7d | 12696 | else if (info->push_p) |
85638c0d | 12697 | { |
fc4767bb JJ |
12698 | if (DEFAULT_ABI == ABI_V4 |
12699 | || current_function_calls_eh_return) | |
9ebbca7d GK |
12700 | sp_offset = info->total_size; |
12701 | else | |
12702 | { | |
12703 | emit_insn (TARGET_32BIT | |
12704 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
12705 | GEN_INT (info->total_size)) | |
12706 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
12707 | GEN_INT (info->total_size))); | |
12708 | } | |
85638c0d | 12709 | } |
9ebbca7d | 12710 | |
9aa86737 AH |
12711 | /* Restore AltiVec registers if needed. */ |
12712 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
12713 | { | |
12714 | int i; | |
12715 | ||
12716 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
12717 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
12718 | { | |
12719 | rtx addr, areg, mem; | |
12720 | ||
12721 | areg = gen_rtx_REG (Pmode, 0); | |
12722 | emit_move_insn | |
12723 | (areg, GEN_INT (info->altivec_save_offset | |
12724 | + sp_offset | |
12725 | + 16 * (i - info->first_altivec_reg_save))); | |
12726 | ||
12727 | /* AltiVec addressing mode is [reg+reg]. */ | |
12728 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
12729 | mem = gen_rtx_MEM (V4SImode, addr); | |
12730 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12731 | ||
12732 | emit_move_insn (gen_rtx_REG (V4SImode, i), mem); | |
12733 | } | |
12734 | } | |
12735 | ||
12736 | /* Restore VRSAVE if needed. */ | |
44688022 | 12737 | if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE |
4d774ff8 | 12738 | && info->vrsave_mask != 0) |
9aa86737 AH |
12739 | { |
12740 | rtx addr, mem, reg; | |
12741 | ||
12742 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12743 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
12744 | mem = gen_rtx_MEM (SImode, addr); | |
12745 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12746 | reg = gen_rtx_REG (SImode, 12); | |
12747 | emit_move_insn (reg, mem); | |
12748 | ||
12749 | emit_insn (generate_set_vrsave (reg, info, 1)); | |
12750 | } | |
12751 | ||
9ebbca7d GK |
12752 | /* Get the old lr if we saved it. */ |
12753 | if (info->lr_save_p) | |
b6c9286a | 12754 | { |
a3170dc6 AH |
12755 | rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx, |
12756 | info->lr_save_offset + sp_offset); | |
ba4828e0 RK |
12757 | |
12758 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 12759 | |
9ebbca7d | 12760 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 12761 | } |
9ebbca7d GK |
12762 | |
12763 | /* Get the old cr if we saved it. */ | |
12764 | if (info->cr_save_p) | |
12765 | { | |
12766 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12767 | GEN_INT (info->cr_save_offset + sp_offset)); | |
12768 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
12769 | |
12770 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 12771 | |
9ebbca7d GK |
12772 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
12773 | } | |
12774 | ||
12775 | /* Set LR here to try to overlap restores below. */ | |
4697a36c | 12776 | if (info->lr_save_p) |
9ebbca7d GK |
12777 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
12778 | gen_rtx_REG (Pmode, 0)); | |
12779 | ||
83720594 RH |
12780 | /* Load exception handler data registers, if needed. */ |
12781 | if (current_function_calls_eh_return) | |
12782 | { | |
78e1b90d DE |
12783 | unsigned int i, regno; |
12784 | ||
fc4767bb JJ |
12785 | if (TARGET_AIX) |
12786 | { | |
12787 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12788 | GEN_INT (sp_offset + 5 * reg_size)); | |
12789 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
12790 | ||
12791 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12792 | ||
12793 | emit_move_insn (gen_rtx_REG (reg_mode, 2), mem); | |
12794 | } | |
12795 | ||
83720594 RH |
12796 | for (i = 0; ; ++i) |
12797 | { | |
a3170dc6 | 12798 | rtx mem; |
83720594 RH |
12799 | |
12800 | regno = EH_RETURN_DATA_REGNO (i); | |
12801 | if (regno == INVALID_REGNUM) | |
12802 | break; | |
12803 | ||
a3170dc6 AH |
12804 | mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx, |
12805 | info->ehrd_offset + sp_offset | |
12806 | + reg_size * (int) i); | |
ba4828e0 | 12807 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
12808 | |
12809 | emit_move_insn (gen_rtx_REG (reg_mode, regno), mem); | |
12810 | } | |
12811 | } | |
9ebbca7d GK |
12812 | |
12813 | /* Restore GPRs. This is done as a PARALLEL if we are using | |
12814 | the load-multiple instructions. */ | |
12815 | if (using_load_multiple) | |
979721f8 | 12816 | { |
9ebbca7d GK |
12817 | rtvec p; |
12818 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
12819 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 12820 | { |
9ebbca7d GK |
12821 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
12822 | GEN_INT (info->gp_save_offset | |
12823 | + sp_offset | |
12824 | + reg_size * i)); | |
12825 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
12826 | |
12827 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
12828 | |
12829 | RTVEC_ELT (p, i) = | |
12830 | gen_rtx_SET (VOIDmode, | |
12831 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
12832 | mem); | |
979721f8 | 12833 | } |
9ebbca7d | 12834 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 12835 | } |
9ebbca7d GK |
12836 | else |
12837 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
12838 | if ((regs_ever_live[info->first_gp_reg_save+i] | |
b4db40bf JJ |
12839 | && (! call_used_regs[info->first_gp_reg_save+i] |
12840 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM | |
12841 | && TARGET_TOC && TARGET_MINIMAL_TOC))) | |
1db02437 | 12842 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 12843 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 12844 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
9ebbca7d GK |
12845 | { |
12846 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12847 | GEN_INT (info->gp_save_offset | |
12848 | + sp_offset | |
12849 | + reg_size * i)); | |
12850 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 12851 | |
a3170dc6 | 12852 | /* Restore 64-bit quantities for SPE. */ |
c19de7aa | 12853 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12854 | { |
12855 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
12856 | rtx b; | |
12857 | ||
12858 | if (!SPE_CONST_OFFSET_OK (offset)) | |
12859 | { | |
12860 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
12861 | emit_move_insn (b, GEN_INT (offset)); | |
12862 | } | |
12863 | else | |
12864 | b = GEN_INT (offset); | |
12865 | ||
12866 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
12867 | mem = gen_rtx_MEM (V2SImode, addr); | |
12868 | } | |
12869 | ||
ba4828e0 | 12870 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12871 | |
12872 | emit_move_insn (gen_rtx_REG (reg_mode, | |
a3170dc6 | 12873 | info->first_gp_reg_save + i), mem); |
9ebbca7d | 12874 | } |
9878760c | 12875 | |
9ebbca7d GK |
12876 | /* Restore fpr's if we need to do it without calling a function. */ |
12877 | if (restoring_FPRs_inline) | |
12878 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
12879 | if ((regs_ever_live[info->first_fp_reg_save+i] | |
12880 | && ! call_used_regs[info->first_fp_reg_save+i])) | |
12881 | { | |
12882 | rtx addr, mem; | |
12883 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
12884 | GEN_INT (info->fp_save_offset | |
12885 | + sp_offset | |
a4f6c312 | 12886 | + 8 * i)); |
9ebbca7d | 12887 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 12888 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
12889 | |
12890 | emit_move_insn (gen_rtx_REG (DFmode, | |
12891 | info->first_fp_reg_save + i), | |
12892 | mem); | |
12893 | } | |
8d30c4ee | 12894 | |
9ebbca7d GK |
12895 | /* If we saved cr, restore it here. Just those that were used. */ |
12896 | if (info->cr_save_p) | |
979721f8 | 12897 | { |
9ebbca7d | 12898 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 12899 | int count = 0; |
9ebbca7d GK |
12900 | |
12901 | if (using_mfcr_multiple) | |
979721f8 | 12902 | { |
9ebbca7d GK |
12903 | for (i = 0; i < 8; i++) |
12904 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 12905 | count++; |
9ebbca7d | 12906 | if (count == 0) |
e35b9579 GK |
12907 | abort (); |
12908 | } | |
12909 | ||
12910 | if (using_mfcr_multiple && count > 1) | |
12911 | { | |
12912 | rtvec p; | |
12913 | int ndx; | |
9ebbca7d | 12914 | |
e35b9579 | 12915 | p = rtvec_alloc (count); |
9ebbca7d | 12916 | |
e35b9579 | 12917 | ndx = 0; |
9ebbca7d GK |
12918 | for (i = 0; i < 8; i++) |
12919 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
12920 | { | |
12921 | rtvec r = rtvec_alloc (2); | |
12922 | RTVEC_ELT (r, 0) = r12_rtx; | |
12923 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 12924 | RTVEC_ELT (p, ndx) = |
9ebbca7d | 12925 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
615158e2 | 12926 | gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR)); |
e35b9579 | 12927 | ndx++; |
9ebbca7d GK |
12928 | } |
12929 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
12930 | if (ndx != count) |
12931 | abort (); | |
979721f8 MM |
12932 | } |
12933 | else | |
9ebbca7d GK |
12934 | for (i = 0; i < 8; i++) |
12935 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 12936 | { |
9ebbca7d GK |
12937 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
12938 | CR0_REGNO+i), | |
12939 | r12_rtx)); | |
979721f8 | 12940 | } |
979721f8 MM |
12941 | } |
12942 | ||
9ebbca7d GK |
12943 | /* If this is V.4, unwind the stack pointer after all of the loads |
12944 | have been done. We need to emit a block here so that sched | |
12945 | doesn't decide to move the sp change before the register restores | |
12946 | (which may not have any obvious dependency on the stack). This | |
12947 | doesn't hurt performance, because there is no scheduling that can | |
12948 | be done after this point. */ | |
fc4767bb JJ |
12949 | if (DEFAULT_ABI == ABI_V4 |
12950 | || current_function_calls_eh_return) | |
b6c9286a | 12951 | { |
9ebbca7d GK |
12952 | if (frame_reg_rtx != sp_reg_rtx) |
12953 | rs6000_emit_stack_tie (); | |
b6c9286a | 12954 | |
9ebbca7d | 12955 | if (use_backchain_to_restore_sp) |
b6c9286a | 12956 | { |
9ebbca7d | 12957 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 12958 | } |
9ebbca7d | 12959 | else if (sp_offset != 0) |
13f1623b | 12960 | { |
5b71a4e7 | 12961 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
12962 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, |
12963 | GEN_INT (sp_offset)) | |
12964 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
12965 | GEN_INT (sp_offset))); | |
13f1623b | 12966 | } |
9ebbca7d | 12967 | } |
b6c9286a | 12968 | |
83720594 RH |
12969 | if (current_function_calls_eh_return) |
12970 | { | |
12971 | rtx sa = EH_RETURN_STACKADJ_RTX; | |
5b71a4e7 | 12972 | emit_insn (TARGET_32BIT |
83720594 RH |
12973 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa) |
12974 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa)); | |
12975 | } | |
12976 | ||
9ebbca7d GK |
12977 | if (!sibcall) |
12978 | { | |
12979 | rtvec p; | |
12980 | if (! restoring_FPRs_inline) | |
12981 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
12982 | else | |
12983 | p = rtvec_alloc (2); | |
b6c9286a | 12984 | |
e35b9579 GK |
12985 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
12986 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, | |
9ebbca7d GK |
12987 | gen_rtx_REG (Pmode, |
12988 | LINK_REGISTER_REGNUM)); | |
9ebbca7d GK |
12989 | |
12990 | /* If we have to restore more than two FP registers, branch to the | |
12991 | restore function. It will return to our caller. */ | |
12992 | if (! restoring_FPRs_inline) | |
12993 | { | |
12994 | int i; | |
12995 | char rname[30]; | |
520a57c8 | 12996 | const char *alloc_rname; |
979721f8 | 12997 | |
9ebbca7d GK |
12998 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
12999 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); | |
a8a05998 | 13000 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
13001 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, |
13002 | gen_rtx_SYMBOL_REF (Pmode, | |
13003 | alloc_rname)); | |
b6c9286a | 13004 | |
9ebbca7d GK |
13005 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
13006 | { | |
13007 | rtx addr, mem; | |
13008 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
13009 | GEN_INT (info->fp_save_offset + 8*i)); | |
13010 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 13011 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
13012 | |
13013 | RTVEC_ELT (p, i+3) = | |
13014 | gen_rtx_SET (VOIDmode, | |
13015 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
13016 | mem); | |
b6c9286a MM |
13017 | } |
13018 | } | |
9ebbca7d GK |
13019 | |
13020 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
3daf36a4 | 13021 | } |
9878760c RK |
13022 | } |
13023 | ||
13024 | /* Write function epilogue. */ | |
13025 | ||
08c148a8 | 13026 | static void |
a2369ed3 DJ |
13027 | rs6000_output_function_epilogue (FILE *file, |
13028 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) | |
9878760c | 13029 | { |
4697a36c | 13030 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 13031 | |
9ebbca7d | 13032 | if (! HAVE_epilogue) |
9878760c | 13033 | { |
9ebbca7d GK |
13034 | rtx insn = get_last_insn (); |
13035 | /* If the last insn was a BARRIER, we don't have to write anything except | |
13036 | the trace table. */ | |
13037 | if (GET_CODE (insn) == NOTE) | |
13038 | insn = prev_nonnote_insn (insn); | |
13039 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 13040 | { |
9ebbca7d GK |
13041 | /* This is slightly ugly, but at least we don't have two |
13042 | copies of the epilogue-emitting code. */ | |
13043 | start_sequence (); | |
13044 | ||
13045 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
13046 | and end of the "toplevel" insn chain. */ | |
2e040219 | 13047 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 13048 | rs6000_emit_epilogue (FALSE); |
2e040219 | 13049 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 13050 | |
a3c9585f | 13051 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
178c3eff DJ |
13052 | { |
13053 | rtx insn; | |
13054 | unsigned addr = 0; | |
13055 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
13056 | { | |
13057 | INSN_ADDRESSES_NEW (insn, addr); | |
13058 | addr += 4; | |
13059 | } | |
13060 | } | |
13061 | ||
9ebbca7d | 13062 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
13063 | debug_rtx_list (get_insns (), 100); |
13064 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 13065 | end_sequence (); |
4697a36c | 13066 | } |
9878760c | 13067 | } |
b4ac57ab | 13068 | |
efdba735 SH |
13069 | #if TARGET_MACHO |
13070 | macho_branch_islands (); | |
0e5da0be GK |
13071 | /* Mach-O doesn't support labels at the end of objects, so if |
13072 | it looks like we might want one, insert a NOP. */ | |
13073 | { | |
13074 | rtx insn = get_last_insn (); | |
13075 | while (insn | |
13076 | && NOTE_P (insn) | |
13077 | && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL) | |
13078 | insn = PREV_INSN (insn); | |
13079 | if (insn | |
13080 | && (LABEL_P (insn) | |
13081 | || (NOTE_P (insn) | |
13082 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
13083 | fputs ("\tnop\n", file); | |
13084 | } | |
13085 | #endif | |
13086 | ||
9b30bae2 | 13087 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
13088 | on its format. |
13089 | ||
13090 | We don't output a traceback table if -finhibit-size-directive was | |
13091 | used. The documentation for -finhibit-size-directive reads | |
13092 | ``don't output a @code{.size} assembler directive, or anything | |
13093 | else that would cause trouble if the function is split in the | |
13094 | middle, and the two halves are placed at locations far apart in | |
13095 | memory.'' The traceback table has this property, since it | |
13096 | includes the offset from the start of the function to the | |
4d30c363 MM |
13097 | traceback table itself. |
13098 | ||
13099 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a | 13100 | different traceback table. */ |
57ac7be9 AM |
13101 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive |
13102 | && rs6000_traceback != traceback_none) | |
9b30bae2 | 13103 | { |
69c75916 | 13104 | const char *fname = NULL; |
3ac88239 | 13105 | const char *language_string = lang_hooks.name; |
6041bf2f | 13106 | int fixed_parms = 0, float_parms = 0, parm_info = 0; |
314fc5a9 | 13107 | int i; |
57ac7be9 AM |
13108 | int optional_tbtab; |
13109 | ||
13110 | if (rs6000_traceback == traceback_full) | |
13111 | optional_tbtab = 1; | |
13112 | else if (rs6000_traceback == traceback_part) | |
13113 | optional_tbtab = 0; | |
13114 | else | |
13115 | optional_tbtab = !optimize_size && !TARGET_ELF; | |
314fc5a9 | 13116 | |
69c75916 AM |
13117 | if (optional_tbtab) |
13118 | { | |
13119 | fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
13120 | while (*fname == '.') /* V.4 encodes . in the name */ | |
13121 | fname++; | |
13122 | ||
13123 | /* Need label immediately before tbtab, so we can compute | |
13124 | its offset from the function start. */ | |
13125 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
13126 | ASM_OUTPUT_LABEL (file, fname); | |
13127 | } | |
314fc5a9 ILT |
13128 | |
13129 | /* The .tbtab pseudo-op can only be used for the first eight | |
13130 | expressions, since it can't handle the possibly variable | |
13131 | length fields that follow. However, if you omit the optional | |
13132 | fields, the assembler outputs zeros for all optional fields | |
13133 | anyways, giving each variable length field is minimum length | |
13134 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
13135 | pseudo-op at all. */ | |
13136 | ||
13137 | /* An all-zero word flags the start of the tbtab, for debuggers | |
13138 | that have to find it by searching forward from the entry | |
13139 | point or from the current pc. */ | |
19d2d16f | 13140 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
13141 | |
13142 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 13143 | fputs ("\t.byte 0,", file); |
314fc5a9 | 13144 | |
5fc921c1 DE |
13145 | /* Language type. Unfortunately, there does not seem to be any |
13146 | official way to discover the language being compiled, so we | |
13147 | use language_string. | |
13148 | C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9. | |
13149 | Java is 13. Objective-C is 14. */ | |
13150 | if (! strcmp (language_string, "GNU C")) | |
314fc5a9 | 13151 | i = 0; |
6de9cd9a DN |
13152 | else if (! strcmp (language_string, "GNU F77") |
13153 | || ! strcmp (language_string, "GNU F95")) | |
314fc5a9 | 13154 | i = 1; |
8b83775b | 13155 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 | 13156 | i = 2; |
5fc921c1 DE |
13157 | else if (! strcmp (language_string, "GNU Ada")) |
13158 | i = 3; | |
314fc5a9 ILT |
13159 | else if (! strcmp (language_string, "GNU C++")) |
13160 | i = 9; | |
9517ead8 AG |
13161 | else if (! strcmp (language_string, "GNU Java")) |
13162 | i = 13; | |
5fc921c1 DE |
13163 | else if (! strcmp (language_string, "GNU Objective-C")) |
13164 | i = 14; | |
314fc5a9 ILT |
13165 | else |
13166 | abort (); | |
13167 | fprintf (file, "%d,", i); | |
13168 | ||
13169 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
13170 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
13171 | from start of procedure stored in tbtab, internal function, function | |
13172 | has controlled storage, function has no toc, function uses fp, | |
13173 | function logs/aborts fp operations. */ | |
13174 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
6041bf2f DE |
13175 | fprintf (file, "%d,", |
13176 | (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1)); | |
314fc5a9 ILT |
13177 | |
13178 | /* 6 bitfields: function is interrupt handler, name present in | |
13179 | proc table, function calls alloca, on condition directives | |
13180 | (controls stack walks, 3 bits), saves condition reg, saves | |
13181 | link reg. */ | |
13182 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
13183 | set up as a frame pointer, even when there is no alloca call. */ | |
13184 | fprintf (file, "%d,", | |
6041bf2f DE |
13185 | ((optional_tbtab << 6) |
13186 | | ((optional_tbtab & frame_pointer_needed) << 5) | |
13187 | | (info->cr_save_p << 1) | |
13188 | | (info->lr_save_p))); | |
314fc5a9 | 13189 | |
6041bf2f | 13190 | /* 3 bitfields: saves backchain, fixup code, number of fpr saved |
314fc5a9 ILT |
13191 | (6 bits). */ |
13192 | fprintf (file, "%d,", | |
4697a36c | 13193 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
13194 | |
13195 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
13196 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
13197 | ||
6041bf2f DE |
13198 | if (optional_tbtab) |
13199 | { | |
13200 | /* Compute the parameter info from the function decl argument | |
13201 | list. */ | |
13202 | tree decl; | |
13203 | int next_parm_info_bit = 31; | |
314fc5a9 | 13204 | |
6041bf2f DE |
13205 | for (decl = DECL_ARGUMENTS (current_function_decl); |
13206 | decl; decl = TREE_CHAIN (decl)) | |
13207 | { | |
13208 | rtx parameter = DECL_INCOMING_RTL (decl); | |
13209 | enum machine_mode mode = GET_MODE (parameter); | |
314fc5a9 | 13210 | |
6041bf2f DE |
13211 | if (GET_CODE (parameter) == REG) |
13212 | { | |
13213 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
13214 | { | |
13215 | int bits; | |
13216 | ||
13217 | float_parms++; | |
13218 | ||
13219 | if (mode == SFmode) | |
13220 | bits = 0x2; | |
fcce224d | 13221 | else if (mode == DFmode || mode == TFmode) |
6041bf2f DE |
13222 | bits = 0x3; |
13223 | else | |
13224 | abort (); | |
13225 | ||
13226 | /* If only one bit will fit, don't or in this entry. */ | |
13227 | if (next_parm_info_bit > 0) | |
13228 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
13229 | next_parm_info_bit -= 2; | |
13230 | } | |
13231 | else | |
13232 | { | |
13233 | fixed_parms += ((GET_MODE_SIZE (mode) | |
13234 | + (UNITS_PER_WORD - 1)) | |
13235 | / UNITS_PER_WORD); | |
13236 | next_parm_info_bit -= 1; | |
13237 | } | |
13238 | } | |
13239 | } | |
13240 | } | |
314fc5a9 ILT |
13241 | |
13242 | /* Number of fixed point parameters. */ | |
13243 | /* This is actually the number of words of fixed point parameters; thus | |
13244 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
13245 | fprintf (file, "%d,", fixed_parms); | |
13246 | ||
13247 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
13248 | all on stack. */ | |
13249 | /* This is actually the number of fp registers that hold parameters; | |
13250 | and thus the maximum value is 13. */ | |
13251 | /* Set parameters on stack bit if parameters are not in their original | |
13252 | registers, regardless of whether they are on the stack? Xlc | |
13253 | seems to set the bit when not optimizing. */ | |
13254 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
13255 | ||
6041bf2f DE |
13256 | if (! optional_tbtab) |
13257 | return; | |
13258 | ||
314fc5a9 ILT |
13259 | /* Optional fields follow. Some are variable length. */ |
13260 | ||
13261 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
13262 | 11 double float. */ | |
13263 | /* There is an entry for each parameter in a register, in the order that | |
13264 | they occur in the parameter list. Any intervening arguments on the | |
13265 | stack are ignored. If the list overflows a long (max possible length | |
13266 | 34 bits) then completely leave off all elements that don't fit. */ | |
13267 | /* Only emit this long if there was at least one parameter. */ | |
13268 | if (fixed_parms || float_parms) | |
13269 | fprintf (file, "\t.long %d\n", parm_info); | |
13270 | ||
13271 | /* Offset from start of code to tb table. */ | |
19d2d16f | 13272 | fputs ("\t.long ", file); |
314fc5a9 | 13273 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
54ee9799 DE |
13274 | #if TARGET_AIX |
13275 | RS6000_OUTPUT_BASENAME (file, fname); | |
13276 | #else | |
9ebbca7d | 13277 | assemble_name (file, fname); |
54ee9799 | 13278 | #endif |
19d2d16f | 13279 | fputs ("-.", file); |
54ee9799 DE |
13280 | #if TARGET_AIX |
13281 | RS6000_OUTPUT_BASENAME (file, fname); | |
13282 | #else | |
9ebbca7d | 13283 | assemble_name (file, fname); |
54ee9799 | 13284 | #endif |
19d2d16f | 13285 | putc ('\n', file); |
314fc5a9 ILT |
13286 | |
13287 | /* Interrupt handler mask. */ | |
13288 | /* Omit this long, since we never set the interrupt handler bit | |
13289 | above. */ | |
13290 | ||
13291 | /* Number of CTL (controlled storage) anchors. */ | |
13292 | /* Omit this long, since the has_ctl bit is never set above. */ | |
13293 | ||
13294 | /* Displacement into stack of each CTL anchor. */ | |
13295 | /* Omit this list of longs, because there are no CTL anchors. */ | |
13296 | ||
13297 | /* Length of function name. */ | |
69c75916 AM |
13298 | if (*fname == '*') |
13299 | ++fname; | |
296b8152 | 13300 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
13301 | |
13302 | /* Function name. */ | |
13303 | assemble_string (fname, strlen (fname)); | |
13304 | ||
13305 | /* Register for alloca automatic storage; this is always reg 31. | |
13306 | Only emit this if the alloca bit was set above. */ | |
13307 | if (frame_pointer_needed) | |
19d2d16f | 13308 | fputs ("\t.byte 31\n", file); |
b1765bde DE |
13309 | |
13310 | fputs ("\t.align 2\n", file); | |
9b30bae2 | 13311 | } |
9878760c | 13312 | } |
17167fd8 | 13313 | \f |
a4f6c312 SS |
13314 | /* A C compound statement that outputs the assembler code for a thunk |
13315 | function, used to implement C++ virtual function calls with | |
13316 | multiple inheritance. The thunk acts as a wrapper around a virtual | |
13317 | function, adjusting the implicit object parameter before handing | |
13318 | control off to the real function. | |
13319 | ||
13320 | First, emit code to add the integer DELTA to the location that | |
13321 | contains the incoming first argument. Assume that this argument | |
13322 | contains a pointer, and is the one used to pass the `this' pointer | |
13323 | in C++. This is the incoming argument *before* the function | |
13324 | prologue, e.g. `%o0' on a sparc. The addition must preserve the | |
13325 | values of all other incoming arguments. | |
17167fd8 MM |
13326 | |
13327 | After the addition, emit code to jump to FUNCTION, which is a | |
a4f6c312 SS |
13328 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does |
13329 | not touch the return address. Hence returning from FUNCTION will | |
13330 | return to whoever called the current `thunk'. | |
17167fd8 | 13331 | |
a4f6c312 SS |
13332 | The effect must be as if FUNCTION had been called directly with the |
13333 | adjusted first argument. This macro is responsible for emitting | |
13334 | all of the code for a thunk function; output_function_prologue() | |
13335 | and output_function_epilogue() are not invoked. | |
17167fd8 | 13336 | |
a4f6c312 SS |
13337 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already |
13338 | been extracted from it.) It might possibly be useful on some | |
13339 | targets, but probably not. | |
17167fd8 | 13340 | |
a4f6c312 SS |
13341 | If you do not define this macro, the target-independent code in the |
13342 | C++ frontend will generate a less efficient heavyweight thunk that | |
13343 | calls FUNCTION instead of jumping to it. The generic approach does | |
13344 | not support varargs. */ | |
17167fd8 | 13345 | |
3961e8fe | 13346 | static void |
a2369ed3 DJ |
13347 | rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, |
13348 | HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, | |
13349 | tree function) | |
17167fd8 | 13350 | { |
5b71a4e7 | 13351 | rtx this, insn, funexp; |
17167fd8 | 13352 | |
5b71a4e7 | 13353 | reload_completed = 1; |
fe3ad572 | 13354 | epilogue_completed = 1; |
5b71a4e7 | 13355 | no_new_pseudos = 1; |
56a7189a | 13356 | |
5b71a4e7 | 13357 | /* Mark the end of the (empty) prologue. */ |
2e040219 | 13358 | emit_note (NOTE_INSN_PROLOGUE_END); |
17167fd8 | 13359 | |
5b71a4e7 DE |
13360 | /* Find the "this" pointer. If the function returns a structure, |
13361 | the structure return pointer is in r3. */ | |
61f71b34 | 13362 | if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) |
5b71a4e7 | 13363 | this = gen_rtx_REG (Pmode, 4); |
56a7189a | 13364 | else |
5b71a4e7 | 13365 | this = gen_rtx_REG (Pmode, 3); |
17167fd8 | 13366 | |
5b71a4e7 DE |
13367 | /* Apply the constant offset, if required. */ |
13368 | if (delta) | |
13369 | { | |
13370 | rtx delta_rtx = GEN_INT (delta); | |
13371 | emit_insn (TARGET_32BIT | |
13372 | ? gen_addsi3 (this, this, delta_rtx) | |
13373 | : gen_adddi3 (this, this, delta_rtx)); | |
17167fd8 MM |
13374 | } |
13375 | ||
5b71a4e7 DE |
13376 | /* Apply the offset from the vtable, if required. */ |
13377 | if (vcall_offset) | |
17167fd8 | 13378 | { |
5b71a4e7 DE |
13379 | rtx vcall_offset_rtx = GEN_INT (vcall_offset); |
13380 | rtx tmp = gen_rtx_REG (Pmode, 12); | |
17167fd8 | 13381 | |
5b71a4e7 | 13382 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, this)); |
eeff9307 JJ |
13383 | if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000) |
13384 | { | |
13385 | emit_insn (TARGET_32BIT | |
13386 | ? gen_addsi3 (tmp, tmp, vcall_offset_rtx) | |
13387 | : gen_adddi3 (tmp, tmp, vcall_offset_rtx)); | |
13388 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
13389 | } | |
13390 | else | |
13391 | { | |
13392 | rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx); | |
13393 | ||
13394 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc)); | |
13395 | } | |
5b71a4e7 DE |
13396 | emit_insn (TARGET_32BIT |
13397 | ? gen_addsi3 (this, this, tmp) | |
13398 | : gen_adddi3 (this, this, tmp)); | |
17167fd8 MM |
13399 | } |
13400 | ||
5b71a4e7 DE |
13401 | /* Generate a tail call to the target function. */ |
13402 | if (!TREE_USED (function)) | |
13403 | { | |
13404 | assemble_external (function); | |
13405 | TREE_USED (function) = 1; | |
13406 | } | |
13407 | funexp = XEXP (DECL_RTL (function), 0); | |
5b71a4e7 | 13408 | funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); |
ee890fe2 SS |
13409 | |
13410 | #if TARGET_MACHO | |
ab82a49f | 13411 | if (MACHOPIC_INDIRECT) |
5b71a4e7 | 13412 | funexp = machopic_indirect_call_target (funexp); |
ee890fe2 | 13413 | #endif |
5b71a4e7 DE |
13414 | |
13415 | /* gen_sibcall expects reload to convert scratch pseudo to LR so we must | |
13416 | generate sibcall RTL explicitly to avoid constraint abort. */ | |
13417 | insn = emit_call_insn ( | |
13418 | gen_rtx_PARALLEL (VOIDmode, | |
13419 | gen_rtvec (4, | |
13420 | gen_rtx_CALL (VOIDmode, | |
13421 | funexp, const0_rtx), | |
13422 | gen_rtx_USE (VOIDmode, const0_rtx), | |
13423 | gen_rtx_USE (VOIDmode, | |
13424 | gen_rtx_REG (SImode, | |
13425 | LINK_REGISTER_REGNUM)), | |
13426 | gen_rtx_RETURN (VOIDmode)))); | |
13427 | SIBLING_CALL_P (insn) = 1; | |
13428 | emit_barrier (); | |
13429 | ||
13430 | /* Run just enough of rest_of_compilation to get the insns emitted. | |
13431 | There's not really enough bulk here to make other passes such as | |
13432 | instruction scheduling worth while. Note that use_thunk calls | |
13433 | assemble_start_function and assemble_end_function. */ | |
13434 | insn = get_insns (); | |
a2855205 | 13435 | insn_locators_initialize (); |
5b71a4e7 DE |
13436 | shorten_branches (insn); |
13437 | final_start_function (insn, file, 1); | |
13438 | final (insn, file, 1, 0); | |
13439 | final_end_function (); | |
13440 | ||
13441 | reload_completed = 0; | |
fe3ad572 | 13442 | epilogue_completed = 0; |
5b71a4e7 | 13443 | no_new_pseudos = 0; |
9ebbca7d | 13444 | } |
9ebbca7d GK |
13445 | \f |
13446 | /* A quick summary of the various types of 'constant-pool tables' | |
13447 | under PowerPC: | |
13448 | ||
13449 | Target Flags Name One table per | |
13450 | AIX (none) AIX TOC object file | |
13451 | AIX -mfull-toc AIX TOC object file | |
13452 | AIX -mminimal-toc AIX minimal TOC translation unit | |
13453 | SVR4/EABI (none) SVR4 SDATA object file | |
13454 | SVR4/EABI -fpic SVR4 pic object file | |
13455 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
13456 | SVR4/EABI -mrelocatable EABI TOC function | |
13457 | SVR4/EABI -maix AIX TOC object file | |
13458 | SVR4/EABI -maix -mminimal-toc | |
13459 | AIX minimal TOC translation unit | |
13460 | ||
13461 | Name Reg. Set by entries contains: | |
13462 | made by addrs? fp? sum? | |
13463 | ||
13464 | AIX TOC 2 crt0 as Y option option | |
13465 | AIX minimal TOC 30 prolog gcc Y Y option | |
13466 | SVR4 SDATA 13 crt0 gcc N Y N | |
13467 | SVR4 pic 30 prolog ld Y not yet N | |
13468 | SVR4 PIC 30 prolog gcc Y option option | |
13469 | EABI TOC 30 prolog gcc Y option option | |
13470 | ||
13471 | */ | |
13472 | ||
9ebbca7d GK |
13473 | /* Hash functions for the hash table. */ |
13474 | ||
13475 | static unsigned | |
a2369ed3 | 13476 | rs6000_hash_constant (rtx k) |
9ebbca7d | 13477 | { |
46b33600 RH |
13478 | enum rtx_code code = GET_CODE (k); |
13479 | enum machine_mode mode = GET_MODE (k); | |
13480 | unsigned result = (code << 3) ^ mode; | |
13481 | const char *format; | |
13482 | int flen, fidx; | |
9ebbca7d | 13483 | |
46b33600 RH |
13484 | format = GET_RTX_FORMAT (code); |
13485 | flen = strlen (format); | |
13486 | fidx = 0; | |
9ebbca7d | 13487 | |
46b33600 RH |
13488 | switch (code) |
13489 | { | |
13490 | case LABEL_REF: | |
13491 | return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0)); | |
13492 | ||
13493 | case CONST_DOUBLE: | |
13494 | if (mode != VOIDmode) | |
13495 | return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result; | |
13496 | flen = 2; | |
13497 | break; | |
13498 | ||
13499 | case CODE_LABEL: | |
13500 | fidx = 3; | |
13501 | break; | |
13502 | ||
13503 | default: | |
13504 | break; | |
13505 | } | |
9ebbca7d GK |
13506 | |
13507 | for (; fidx < flen; fidx++) | |
13508 | switch (format[fidx]) | |
13509 | { | |
13510 | case 's': | |
13511 | { | |
13512 | unsigned i, len; | |
13513 | const char *str = XSTR (k, fidx); | |
13514 | len = strlen (str); | |
13515 | result = result * 613 + len; | |
13516 | for (i = 0; i < len; i++) | |
13517 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
13518 | break; |
13519 | } | |
9ebbca7d GK |
13520 | case 'u': |
13521 | case 'e': | |
13522 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
13523 | break; | |
13524 | case 'i': | |
13525 | case 'n': | |
13526 | result = result * 613 + (unsigned) XINT (k, fidx); | |
13527 | break; | |
13528 | case 'w': | |
13529 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
13530 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
13531 | else | |
13532 | { | |
13533 | size_t i; | |
13534 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
13535 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
13536 | >> CHAR_BIT * i); | |
13537 | } | |
13538 | break; | |
09501938 DE |
13539 | case '0': |
13540 | break; | |
9ebbca7d | 13541 | default: |
a4f6c312 | 13542 | abort (); |
9ebbca7d | 13543 | } |
46b33600 | 13544 | |
9ebbca7d GK |
13545 | return result; |
13546 | } | |
13547 | ||
13548 | static unsigned | |
a2369ed3 | 13549 | toc_hash_function (const void *hash_entry) |
9ebbca7d | 13550 | { |
a9098fd0 GK |
13551 | const struct toc_hash_struct *thc = |
13552 | (const struct toc_hash_struct *) hash_entry; | |
13553 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
13554 | } |
13555 | ||
13556 | /* Compare H1 and H2 for equivalence. */ | |
13557 | ||
13558 | static int | |
a2369ed3 | 13559 | toc_hash_eq (const void *h1, const void *h2) |
9ebbca7d GK |
13560 | { |
13561 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
13562 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
13563 | ||
a9098fd0 GK |
13564 | if (((const struct toc_hash_struct *) h1)->key_mode |
13565 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
13566 | return 0; | |
13567 | ||
5692c7bc | 13568 | return rtx_equal_p (r1, r2); |
9ebbca7d GK |
13569 | } |
13570 | ||
28e510bd MM |
13571 | /* These are the names given by the C++ front-end to vtables, and |
13572 | vtable-like objects. Ideally, this logic should not be here; | |
13573 | instead, there should be some programmatic way of inquiring as | |
13574 | to whether or not an object is a vtable. */ | |
13575 | ||
13576 | #define VTABLE_NAME_P(NAME) \ | |
13577 | (strncmp ("_vt.", name, strlen("_vt.")) == 0 \ | |
13578 | || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \ | |
13579 | || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \ | |
26be75db | 13580 | || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \ |
28e510bd MM |
13581 | || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0) |
13582 | ||
13583 | void | |
a2369ed3 | 13584 | rs6000_output_symbol_ref (FILE *file, rtx x) |
28e510bd MM |
13585 | { |
13586 | /* Currently C++ toc references to vtables can be emitted before it | |
13587 | is decided whether the vtable is public or private. If this is | |
13588 | the case, then the linker will eventually complain that there is | |
13589 | a reference to an unknown section. Thus, for vtables only, | |
13590 | we emit the TOC reference to reference the symbol and not the | |
13591 | section. */ | |
13592 | const char *name = XSTR (x, 0); | |
54ee9799 DE |
13593 | |
13594 | if (VTABLE_NAME_P (name)) | |
13595 | { | |
13596 | RS6000_OUTPUT_BASENAME (file, name); | |
13597 | } | |
13598 | else | |
13599 | assemble_name (file, name); | |
28e510bd MM |
13600 | } |
13601 | ||
a4f6c312 SS |
13602 | /* Output a TOC entry. We derive the entry name from what is being |
13603 | written. */ | |
9878760c RK |
13604 | |
13605 | void | |
a2369ed3 | 13606 | output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode) |
9878760c RK |
13607 | { |
13608 | char buf[256]; | |
3cce094d | 13609 | const char *name = buf; |
ec940faa | 13610 | const char *real_name; |
9878760c RK |
13611 | rtx base = x; |
13612 | int offset = 0; | |
13613 | ||
4697a36c MM |
13614 | if (TARGET_NO_TOC) |
13615 | abort (); | |
13616 | ||
9ebbca7d GK |
13617 | /* When the linker won't eliminate them, don't output duplicate |
13618 | TOC entries (this happens on AIX if there is any kind of TOC, | |
17211ab5 GK |
13619 | and on SVR4 under -fPIC or -mrelocatable). Don't do this for |
13620 | CODE_LABELs. */ | |
13621 | if (TARGET_TOC && GET_CODE (x) != LABEL_REF) | |
9ebbca7d GK |
13622 | { |
13623 | struct toc_hash_struct *h; | |
13624 | void * * found; | |
13625 | ||
17211ab5 | 13626 | /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS |
39e3f58c | 13627 | time because GGC is not initialized at that point. */ |
17211ab5 GK |
13628 | if (toc_hash_table == NULL) |
13629 | toc_hash_table = htab_create_ggc (1021, toc_hash_function, | |
13630 | toc_hash_eq, NULL); | |
13631 | ||
9ebbca7d GK |
13632 | h = ggc_alloc (sizeof (*h)); |
13633 | h->key = x; | |
a9098fd0 | 13634 | h->key_mode = mode; |
9ebbca7d GK |
13635 | h->labelno = labelno; |
13636 | ||
13637 | found = htab_find_slot (toc_hash_table, h, 1); | |
13638 | if (*found == NULL) | |
13639 | *found = h; | |
13640 | else /* This is indeed a duplicate. | |
13641 | Set this label equal to that label. */ | |
13642 | { | |
13643 | fputs ("\t.set ", file); | |
13644 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
13645 | fprintf (file, "%d,", labelno); | |
13646 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
13647 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) | |
13648 | found)->labelno)); | |
13649 | return; | |
13650 | } | |
13651 | } | |
13652 | ||
13653 | /* If we're going to put a double constant in the TOC, make sure it's | |
13654 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
13655 | if (GET_CODE (x) == CONST_DOUBLE |
13656 | && STRICT_ALIGNMENT | |
a9098fd0 | 13657 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
13658 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
13659 | ASM_OUTPUT_ALIGN (file, 3); | |
13660 | } | |
13661 | ||
4977bab6 | 13662 | (*targetm.asm_out.internal_label) (file, "LC", labelno); |
9878760c | 13663 | |
37c37a57 RK |
13664 | /* Handle FP constants specially. Note that if we have a minimal |
13665 | TOC, things we put here aren't actually in the TOC, so we can allow | |
13666 | FP constants. */ | |
fcce224d DE |
13667 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode) |
13668 | { | |
13669 | REAL_VALUE_TYPE rv; | |
13670 | long k[4]; | |
13671 | ||
13672 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
13673 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
13674 | ||
13675 | if (TARGET_64BIT) | |
13676 | { | |
13677 | if (TARGET_MINIMAL_TOC) | |
13678 | fputs (DOUBLE_INT_ASM_OP, file); | |
13679 | else | |
13680 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
13681 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13682 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13683 | fprintf (file, "0x%lx%08lx,0x%lx%08lx\n", | |
13684 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13685 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13686 | return; | |
13687 | } | |
13688 | else | |
13689 | { | |
13690 | if (TARGET_MINIMAL_TOC) | |
13691 | fputs ("\t.long ", file); | |
13692 | else | |
13693 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
13694 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13695 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13696 | fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n", | |
13697 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
13698 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
13699 | return; | |
13700 | } | |
13701 | } | |
13702 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) | |
9878760c | 13703 | { |
042259f2 DE |
13704 | REAL_VALUE_TYPE rv; |
13705 | long k[2]; | |
0adc764e | 13706 | |
042259f2 DE |
13707 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
13708 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 13709 | |
13ded975 DE |
13710 | if (TARGET_64BIT) |
13711 | { | |
13712 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13713 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 13714 | else |
2f0552b6 AM |
13715 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
13716 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13717 | fprintf (file, "0x%lx%08lx\n", | |
13718 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
13719 | return; |
13720 | } | |
1875cc88 | 13721 | else |
13ded975 DE |
13722 | { |
13723 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13724 | fputs ("\t.long ", file); |
13ded975 | 13725 | else |
2f0552b6 AM |
13726 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
13727 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13728 | fprintf (file, "0x%lx,0x%lx\n", | |
13729 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
13730 | return; |
13731 | } | |
9878760c | 13732 | } |
a9098fd0 | 13733 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 13734 | { |
042259f2 DE |
13735 | REAL_VALUE_TYPE rv; |
13736 | long l; | |
9878760c | 13737 | |
042259f2 DE |
13738 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
13739 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
13740 | ||
31bfaa0b DE |
13741 | if (TARGET_64BIT) |
13742 | { | |
13743 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13744 | fputs (DOUBLE_INT_ASM_OP, file); |
31bfaa0b | 13745 | else |
2f0552b6 AM |
13746 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
13747 | fprintf (file, "0x%lx00000000\n", l & 0xffffffff); | |
31bfaa0b DE |
13748 | return; |
13749 | } | |
042259f2 | 13750 | else |
31bfaa0b DE |
13751 | { |
13752 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13753 | fputs ("\t.long ", file); |
31bfaa0b | 13754 | else |
2f0552b6 AM |
13755 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
13756 | fprintf (file, "0x%lx\n", l & 0xffffffff); | |
31bfaa0b DE |
13757 | return; |
13758 | } | |
042259f2 | 13759 | } |
f176e826 | 13760 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 13761 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 13762 | { |
e2c953b6 | 13763 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
13764 | HOST_WIDE_INT high; |
13765 | ||
13766 | if (GET_CODE (x) == CONST_DOUBLE) | |
13767 | { | |
13768 | low = CONST_DOUBLE_LOW (x); | |
13769 | high = CONST_DOUBLE_HIGH (x); | |
13770 | } | |
13771 | else | |
13772 | #if HOST_BITS_PER_WIDE_INT == 32 | |
13773 | { | |
13774 | low = INTVAL (x); | |
0858c623 | 13775 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
13776 | } |
13777 | #else | |
13778 | { | |
0858c623 | 13779 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
13780 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
13781 | } | |
13782 | #endif | |
9878760c | 13783 | |
a9098fd0 GK |
13784 | /* TOC entries are always Pmode-sized, but since this |
13785 | is a bigendian machine then if we're putting smaller | |
13786 | integer constants in the TOC we have to pad them. | |
13787 | (This is still a win over putting the constants in | |
13788 | a separate constant pool, because then we'd have | |
02a4ec28 FS |
13789 | to have both a TOC entry _and_ the actual constant.) |
13790 | ||
13791 | For a 32-bit target, CONST_INT values are loaded and shifted | |
13792 | entirely within `low' and can be stored in one TOC entry. */ | |
13793 | ||
13794 | if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
a9098fd0 | 13795 | abort ();/* It would be easy to make this work, but it doesn't now. */ |
02a4ec28 FS |
13796 | |
13797 | if (POINTER_SIZE > GET_MODE_BITSIZE (mode)) | |
fb52d8de AM |
13798 | { |
13799 | #if HOST_BITS_PER_WIDE_INT == 32 | |
13800 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), | |
13801 | POINTER_SIZE, &low, &high, 0); | |
13802 | #else | |
13803 | low |= high << 32; | |
13804 | low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode); | |
13805 | high = (HOST_WIDE_INT) low >> 32; | |
13806 | low &= 0xffffffff; | |
13807 | #endif | |
13808 | } | |
a9098fd0 | 13809 | |
13ded975 DE |
13810 | if (TARGET_64BIT) |
13811 | { | |
13812 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13813 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 13814 | else |
2f0552b6 AM |
13815 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
13816 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13817 | fprintf (file, "0x%lx%08lx\n", | |
13818 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13ded975 DE |
13819 | return; |
13820 | } | |
1875cc88 | 13821 | else |
13ded975 | 13822 | { |
02a4ec28 FS |
13823 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) |
13824 | { | |
13825 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13826 | fputs ("\t.long ", file); |
02a4ec28 | 13827 | else |
2bfcf297 | 13828 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
2f0552b6 AM |
13829 | (long) high & 0xffffffff, (long) low & 0xffffffff); |
13830 | fprintf (file, "0x%lx,0x%lx\n", | |
13831 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
02a4ec28 | 13832 | } |
13ded975 | 13833 | else |
02a4ec28 FS |
13834 | { |
13835 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 13836 | fputs ("\t.long ", file); |
02a4ec28 | 13837 | else |
2f0552b6 AM |
13838 | fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff); |
13839 | fprintf (file, "0x%lx\n", (long) low & 0xffffffff); | |
02a4ec28 | 13840 | } |
13ded975 DE |
13841 | return; |
13842 | } | |
9878760c RK |
13843 | } |
13844 | ||
13845 | if (GET_CODE (x) == CONST) | |
13846 | { | |
2bfcf297 DB |
13847 | if (GET_CODE (XEXP (x, 0)) != PLUS) |
13848 | abort (); | |
13849 | ||
9878760c RK |
13850 | base = XEXP (XEXP (x, 0), 0); |
13851 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
13852 | } | |
13853 | ||
13854 | if (GET_CODE (base) == SYMBOL_REF) | |
13855 | name = XSTR (base, 0); | |
13856 | else if (GET_CODE (base) == LABEL_REF) | |
13857 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
13858 | else if (GET_CODE (base) == CODE_LABEL) | |
13859 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
13860 | else | |
13861 | abort (); | |
13862 | ||
772c5265 | 13863 | real_name = (*targetm.strip_name_encoding) (name); |
1875cc88 | 13864 | if (TARGET_MINIMAL_TOC) |
2bfcf297 | 13865 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); |
1875cc88 JW |
13866 | else |
13867 | { | |
b6c9286a | 13868 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 13869 | |
1875cc88 JW |
13870 | if (offset < 0) |
13871 | fprintf (file, ".N%d", - offset); | |
13872 | else if (offset) | |
13873 | fprintf (file, ".P%d", offset); | |
9878760c | 13874 | |
19d2d16f | 13875 | fputs ("[TC],", file); |
1875cc88 | 13876 | } |
581bc4de MM |
13877 | |
13878 | /* Currently C++ toc references to vtables can be emitted before it | |
13879 | is decided whether the vtable is public or private. If this is | |
13880 | the case, then the linker will eventually complain that there is | |
13881 | a TOC reference to an unknown section. Thus, for vtables only, | |
13882 | we emit the TOC reference to reference the symbol and not the | |
13883 | section. */ | |
28e510bd | 13884 | if (VTABLE_NAME_P (name)) |
581bc4de | 13885 | { |
54ee9799 | 13886 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
13887 | if (offset < 0) |
13888 | fprintf (file, "%d", offset); | |
13889 | else if (offset > 0) | |
13890 | fprintf (file, "+%d", offset); | |
13891 | } | |
13892 | else | |
13893 | output_addr_const (file, x); | |
19d2d16f | 13894 | putc ('\n', file); |
9878760c RK |
13895 | } |
13896 | \f | |
13897 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
13898 | starting at P to FILE. | |
13899 | ||
13900 | On the RS/6000, we have to do this using the .byte operation and | |
13901 | write out special characters outside the quoted string. | |
13902 | Also, the assembler is broken; very long strings are truncated, | |
a4f6c312 | 13903 | so we must artificially break them up early. */ |
9878760c RK |
13904 | |
13905 | void | |
a2369ed3 | 13906 | output_ascii (FILE *file, const char *p, int n) |
9878760c RK |
13907 | { |
13908 | char c; | |
13909 | int i, count_string; | |
d330fd93 KG |
13910 | const char *for_string = "\t.byte \""; |
13911 | const char *for_decimal = "\t.byte "; | |
13912 | const char *to_close = NULL; | |
9878760c RK |
13913 | |
13914 | count_string = 0; | |
13915 | for (i = 0; i < n; i++) | |
13916 | { | |
13917 | c = *p++; | |
13918 | if (c >= ' ' && c < 0177) | |
13919 | { | |
13920 | if (for_string) | |
13921 | fputs (for_string, file); | |
13922 | putc (c, file); | |
13923 | ||
13924 | /* Write two quotes to get one. */ | |
13925 | if (c == '"') | |
13926 | { | |
13927 | putc (c, file); | |
13928 | ++count_string; | |
13929 | } | |
13930 | ||
13931 | for_string = NULL; | |
13932 | for_decimal = "\"\n\t.byte "; | |
13933 | to_close = "\"\n"; | |
13934 | ++count_string; | |
13935 | ||
13936 | if (count_string >= 512) | |
13937 | { | |
13938 | fputs (to_close, file); | |
13939 | ||
13940 | for_string = "\t.byte \""; | |
13941 | for_decimal = "\t.byte "; | |
13942 | to_close = NULL; | |
13943 | count_string = 0; | |
13944 | } | |
13945 | } | |
13946 | else | |
13947 | { | |
13948 | if (for_decimal) | |
13949 | fputs (for_decimal, file); | |
13950 | fprintf (file, "%d", c); | |
13951 | ||
13952 | for_string = "\n\t.byte \""; | |
13953 | for_decimal = ", "; | |
13954 | to_close = "\n"; | |
13955 | count_string = 0; | |
13956 | } | |
13957 | } | |
13958 | ||
13959 | /* Now close the string if we have written one. Then end the line. */ | |
13960 | if (to_close) | |
9ebbca7d | 13961 | fputs (to_close, file); |
9878760c RK |
13962 | } |
13963 | \f | |
13964 | /* Generate a unique section name for FILENAME for a section type | |
13965 | represented by SECTION_DESC. Output goes into BUF. | |
13966 | ||
13967 | SECTION_DESC can be any string, as long as it is different for each | |
13968 | possible section type. | |
13969 | ||
13970 | We name the section in the same manner as xlc. The name begins with an | |
13971 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
13972 | names) with the last period replaced by the string SECTION_DESC. If |
13973 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
13974 | the name. */ | |
9878760c RK |
13975 | |
13976 | void | |
a2369ed3 DJ |
13977 | rs6000_gen_section_name (char **buf, const char *filename, |
13978 | const char *section_desc) | |
9878760c | 13979 | { |
9ebbca7d | 13980 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
13981 | char *p; |
13982 | int len; | |
9878760c RK |
13983 | |
13984 | after_last_slash = filename; | |
13985 | for (q = filename; *q; q++) | |
11e5fe42 RK |
13986 | { |
13987 | if (*q == '/') | |
13988 | after_last_slash = q + 1; | |
13989 | else if (*q == '.') | |
13990 | last_period = q; | |
13991 | } | |
9878760c | 13992 | |
11e5fe42 | 13993 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
6d9f628e | 13994 | *buf = (char *) xmalloc (len); |
9878760c RK |
13995 | |
13996 | p = *buf; | |
13997 | *p++ = '_'; | |
13998 | ||
13999 | for (q = after_last_slash; *q; q++) | |
14000 | { | |
11e5fe42 | 14001 | if (q == last_period) |
9878760c RK |
14002 | { |
14003 | strcpy (p, section_desc); | |
14004 | p += strlen (section_desc); | |
e3981aab | 14005 | break; |
9878760c RK |
14006 | } |
14007 | ||
e9a780ec | 14008 | else if (ISALNUM (*q)) |
9878760c RK |
14009 | *p++ = *q; |
14010 | } | |
14011 | ||
11e5fe42 | 14012 | if (last_period == 0) |
9878760c RK |
14013 | strcpy (p, section_desc); |
14014 | else | |
14015 | *p = '\0'; | |
14016 | } | |
e165f3f0 | 14017 | \f |
a4f6c312 | 14018 | /* Emit profile function. */ |
411707f4 | 14019 | |
411707f4 | 14020 | void |
a2369ed3 | 14021 | output_profile_hook (int labelno ATTRIBUTE_UNUSED) |
411707f4 | 14022 | { |
ffcfcb5f AM |
14023 | if (TARGET_PROFILE_KERNEL) |
14024 | return; | |
14025 | ||
8480e480 CC |
14026 | if (DEFAULT_ABI == ABI_AIX) |
14027 | { | |
9739c90c JJ |
14028 | #ifndef NO_PROFILE_COUNTERS |
14029 | # define NO_PROFILE_COUNTERS 0 | |
14030 | #endif | |
14031 | if (NO_PROFILE_COUNTERS) | |
14032 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0); | |
14033 | else | |
14034 | { | |
14035 | char buf[30]; | |
14036 | const char *label_name; | |
14037 | rtx fun; | |
411707f4 | 14038 | |
9739c90c JJ |
14039 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
14040 | label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf)); | |
14041 | fun = gen_rtx_SYMBOL_REF (Pmode, label_name); | |
411707f4 | 14042 | |
9739c90c JJ |
14043 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1, |
14044 | fun, Pmode); | |
14045 | } | |
8480e480 | 14046 | } |
ee890fe2 SS |
14047 | else if (DEFAULT_ABI == ABI_DARWIN) |
14048 | { | |
d5fa86ba | 14049 | const char *mcount_name = RS6000_MCOUNT; |
ee890fe2 SS |
14050 | int caller_addr_regno = LINK_REGISTER_REGNUM; |
14051 | ||
14052 | /* Be conservative and always set this, at least for now. */ | |
14053 | current_function_uses_pic_offset_table = 1; | |
14054 | ||
14055 | #if TARGET_MACHO | |
14056 | /* For PIC code, set up a stub and collect the caller's address | |
14057 | from r0, which is where the prologue puts it. */ | |
ab82a49f | 14058 | if (MACHOPIC_INDIRECT) |
ee890fe2 SS |
14059 | { |
14060 | mcount_name = machopic_stub_name (mcount_name); | |
14061 | if (current_function_uses_pic_offset_table) | |
14062 | caller_addr_regno = 0; | |
14063 | } | |
14064 | #endif | |
14065 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name), | |
14066 | 0, VOIDmode, 1, | |
14067 | gen_rtx_REG (Pmode, caller_addr_regno), Pmode); | |
14068 | } | |
411707f4 CC |
14069 | } |
14070 | ||
a4f6c312 | 14071 | /* Write function profiler code. */ |
e165f3f0 RK |
14072 | |
14073 | void | |
a2369ed3 | 14074 | output_function_profiler (FILE *file, int labelno) |
e165f3f0 | 14075 | { |
3daf36a4 | 14076 | char buf[100]; |
09eeeacb | 14077 | int save_lr = 8; |
e165f3f0 | 14078 | |
38c1f2d7 | 14079 | switch (DEFAULT_ABI) |
3daf36a4 | 14080 | { |
38c1f2d7 MM |
14081 | default: |
14082 | abort (); | |
14083 | ||
14084 | case ABI_V4: | |
09eeeacb | 14085 | save_lr = 4; |
09eeeacb AM |
14086 | if (!TARGET_32BIT) |
14087 | { | |
14088 | warning ("no profiling of 64-bit code for this ABI"); | |
14089 | return; | |
14090 | } | |
ffcfcb5f | 14091 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 MM |
14092 | fprintf (file, "\tmflr %s\n", reg_names[0]); |
14093 | if (flag_pic == 1) | |
14094 | { | |
dfdfa60f | 14095 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
09eeeacb AM |
14096 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
14097 | reg_names[0], save_lr, reg_names[1]); | |
17167fd8 | 14098 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 14099 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 14100 | assemble_name (file, buf); |
17167fd8 | 14101 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 14102 | } |
9ebbca7d | 14103 | else if (flag_pic > 1) |
38c1f2d7 | 14104 | { |
09eeeacb AM |
14105 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
14106 | reg_names[0], save_lr, reg_names[1]); | |
9ebbca7d GK |
14107 | /* Now, we need to get the address of the label. */ |
14108 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 14109 | assemble_name (file, buf); |
9ebbca7d GK |
14110 | fputs ("-.\n1:", file); |
14111 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
14112 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", | |
14113 | reg_names[0], reg_names[11]); | |
14114 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
14115 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 14116 | } |
38c1f2d7 MM |
14117 | else |
14118 | { | |
17167fd8 | 14119 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 14120 | assemble_name (file, buf); |
dfdfa60f | 14121 | fputs ("@ha\n", file); |
09eeeacb AM |
14122 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
14123 | reg_names[0], save_lr, reg_names[1]); | |
a260abc9 | 14124 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 14125 | assemble_name (file, buf); |
17167fd8 | 14126 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
14127 | } |
14128 | ||
50d440bc | 14129 | /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */ |
3b6ce0af DE |
14130 | fprintf (file, "\tbl %s%s\n", |
14131 | RS6000_MCOUNT, flag_pic ? "@plt" : ""); | |
38c1f2d7 MM |
14132 | break; |
14133 | ||
14134 | case ABI_AIX: | |
ee890fe2 | 14135 | case ABI_DARWIN: |
ffcfcb5f AM |
14136 | if (!TARGET_PROFILE_KERNEL) |
14137 | { | |
a3c9585f | 14138 | /* Don't do anything, done in output_profile_hook (). */ |
ffcfcb5f AM |
14139 | } |
14140 | else | |
14141 | { | |
14142 | if (TARGET_32BIT) | |
14143 | abort (); | |
14144 | ||
14145 | asm_fprintf (file, "\tmflr %s\n", reg_names[0]); | |
14146 | asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]); | |
14147 | ||
6de9cd9a | 14148 | if (cfun->static_chain_decl != NULL) |
ffcfcb5f AM |
14149 | { |
14150 | asm_fprintf (file, "\tstd %s,24(%s)\n", | |
14151 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
14152 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
14153 | asm_fprintf (file, "\tld %s,24(%s)\n", | |
14154 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
14155 | } | |
14156 | else | |
14157 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
14158 | } | |
38c1f2d7 MM |
14159 | break; |
14160 | } | |
e165f3f0 | 14161 | } |
a251ffd0 | 14162 | |
b54cf83a | 14163 | \f |
b54cf83a DE |
14164 | /* Power4 load update and store update instructions are cracked into a |
14165 | load or store and an integer insn which are executed in the same cycle. | |
14166 | Branches have their own dispatch slot which does not count against the | |
14167 | GCC issue rate, but it changes the program flow so there are no other | |
14168 | instructions to issue in this cycle. */ | |
14169 | ||
14170 | static int | |
a2369ed3 DJ |
14171 | rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED, |
14172 | int verbose ATTRIBUTE_UNUSED, | |
14173 | rtx insn, int more) | |
b54cf83a DE |
14174 | { |
14175 | if (GET_CODE (PATTERN (insn)) == USE | |
14176 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14177 | return more; | |
14178 | ||
ec507f2d | 14179 | if (rs6000_sched_groups) |
b54cf83a | 14180 | { |
cbe26ab8 DN |
14181 | if (is_microcoded_insn (insn)) |
14182 | return 0; | |
14183 | else if (is_cracked_insn (insn)) | |
14184 | return more > 2 ? more - 2 : 0; | |
b54cf83a | 14185 | } |
165b263e DE |
14186 | |
14187 | return more - 1; | |
b54cf83a DE |
14188 | } |
14189 | ||
a251ffd0 TG |
14190 | /* Adjust the cost of a scheduling dependency. Return the new cost of |
14191 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
14192 | ||
c237e94a | 14193 | static int |
a2369ed3 DJ |
14194 | rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED, |
14195 | int cost) | |
a251ffd0 TG |
14196 | { |
14197 | if (! recog_memoized (insn)) | |
14198 | return 0; | |
14199 | ||
14200 | if (REG_NOTE_KIND (link) != 0) | |
14201 | return 0; | |
14202 | ||
14203 | if (REG_NOTE_KIND (link) == 0) | |
14204 | { | |
ed947a96 DJ |
14205 | /* Data dependency; DEP_INSN writes a register that INSN reads |
14206 | some cycles later. */ | |
14207 | switch (get_attr_type (insn)) | |
14208 | { | |
14209 | case TYPE_JMPREG: | |
309323c2 | 14210 | /* Tell the first scheduling pass about the latency between |
ed947a96 DJ |
14211 | a mtctr and bctr (and mtlr and br/blr). The first |
14212 | scheduling pass will not know about this latency since | |
14213 | the mtctr instruction, which has the latency associated | |
14214 | to it, will be generated by reload. */ | |
309323c2 | 14215 | return TARGET_POWER ? 5 : 4; |
ed947a96 DJ |
14216 | case TYPE_BRANCH: |
14217 | /* Leave some extra cycles between a compare and its | |
14218 | dependent branch, to inhibit expensive mispredicts. */ | |
309323c2 DE |
14219 | if ((rs6000_cpu_attr == CPU_PPC603 |
14220 | || rs6000_cpu_attr == CPU_PPC604 | |
14221 | || rs6000_cpu_attr == CPU_PPC604E | |
14222 | || rs6000_cpu_attr == CPU_PPC620 | |
14223 | || rs6000_cpu_attr == CPU_PPC630 | |
14224 | || rs6000_cpu_attr == CPU_PPC750 | |
14225 | || rs6000_cpu_attr == CPU_PPC7400 | |
14226 | || rs6000_cpu_attr == CPU_PPC7450 | |
ec507f2d DE |
14227 | || rs6000_cpu_attr == CPU_POWER4 |
14228 | || rs6000_cpu_attr == CPU_POWER5) | |
ed947a96 DJ |
14229 | && recog_memoized (dep_insn) |
14230 | && (INSN_CODE (dep_insn) >= 0) | |
b54cf83a DE |
14231 | && (get_attr_type (dep_insn) == TYPE_CMP |
14232 | || get_attr_type (dep_insn) == TYPE_COMPARE | |
ed947a96 | 14233 | || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE |
9259f3b0 DE |
14234 | || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE |
14235 | || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE | |
ed947a96 | 14236 | || get_attr_type (dep_insn) == TYPE_FPCOMPARE |
b54cf83a DE |
14237 | || get_attr_type (dep_insn) == TYPE_CR_LOGICAL |
14238 | || get_attr_type (dep_insn) == TYPE_DELAYED_CR)) | |
ed947a96 DJ |
14239 | return cost + 2; |
14240 | default: | |
14241 | break; | |
14242 | } | |
a251ffd0 TG |
14243 | /* Fall out to return default cost. */ |
14244 | } | |
14245 | ||
14246 | return cost; | |
14247 | } | |
b6c9286a | 14248 | |
cbe26ab8 | 14249 | /* The function returns a true if INSN is microcoded. |
839a4992 | 14250 | Return false otherwise. */ |
cbe26ab8 DN |
14251 | |
14252 | static bool | |
14253 | is_microcoded_insn (rtx insn) | |
14254 | { | |
14255 | if (!insn || !INSN_P (insn) | |
14256 | || GET_CODE (PATTERN (insn)) == USE | |
14257 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14258 | return false; | |
14259 | ||
ec507f2d | 14260 | if (rs6000_sched_groups) |
cbe26ab8 DN |
14261 | { |
14262 | enum attr_type type = get_attr_type (insn); | |
14263 | if (type == TYPE_LOAD_EXT_U | |
14264 | || type == TYPE_LOAD_EXT_UX | |
14265 | || type == TYPE_LOAD_UX | |
14266 | || type == TYPE_STORE_UX | |
14267 | || type == TYPE_MFCR) | |
14268 | return true; | |
14269 | } | |
14270 | ||
14271 | return false; | |
14272 | } | |
14273 | ||
5c425df5 | 14274 | /* The function returns a nonzero value if INSN can be scheduled only |
cbe26ab8 DN |
14275 | as the first insn in a dispatch group ("dispatch-slot restricted"). |
14276 | In this case, the returned value indicates how many dispatch slots | |
14277 | the insn occupies (at the beginning of the group). | |
79ae11c4 DN |
14278 | Return 0 otherwise. */ |
14279 | ||
cbe26ab8 | 14280 | static int |
79ae11c4 DN |
14281 | is_dispatch_slot_restricted (rtx insn) |
14282 | { | |
14283 | enum attr_type type; | |
14284 | ||
ec507f2d | 14285 | if (!rs6000_sched_groups) |
79ae11c4 DN |
14286 | return 0; |
14287 | ||
14288 | if (!insn | |
14289 | || insn == NULL_RTX | |
14290 | || GET_CODE (insn) == NOTE | |
14291 | || GET_CODE (PATTERN (insn)) == USE | |
14292 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14293 | return 0; | |
14294 | ||
14295 | type = get_attr_type (insn); | |
14296 | ||
ec507f2d DE |
14297 | switch (type) |
14298 | { | |
14299 | case TYPE_MFCR: | |
14300 | case TYPE_MFCRF: | |
14301 | case TYPE_MTCR: | |
14302 | case TYPE_DELAYED_CR: | |
14303 | case TYPE_CR_LOGICAL: | |
14304 | case TYPE_MTJMPR: | |
14305 | case TYPE_MFJMPR: | |
14306 | return 1; | |
14307 | case TYPE_IDIV: | |
14308 | case TYPE_LDIV: | |
14309 | return 2; | |
14310 | default: | |
14311 | if (rs6000_cpu == PROCESSOR_POWER5 | |
14312 | && is_cracked_insn (insn)) | |
14313 | return 2; | |
14314 | return 0; | |
14315 | } | |
79ae11c4 DN |
14316 | } |
14317 | ||
cbe26ab8 DN |
14318 | /* The function returns true if INSN is cracked into 2 instructions |
14319 | by the processor (and therefore occupies 2 issue slots). */ | |
14320 | ||
14321 | static bool | |
14322 | is_cracked_insn (rtx insn) | |
14323 | { | |
14324 | if (!insn || !INSN_P (insn) | |
14325 | || GET_CODE (PATTERN (insn)) == USE | |
14326 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14327 | return false; | |
14328 | ||
ec507f2d | 14329 | if (rs6000_sched_groups) |
cbe26ab8 DN |
14330 | { |
14331 | enum attr_type type = get_attr_type (insn); | |
14332 | if (type == TYPE_LOAD_U || type == TYPE_STORE_U | |
14333 | || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U | |
14334 | || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX | |
14335 | || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR | |
14336 | || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE | |
14337 | || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE | |
14338 | || type == TYPE_IDIV || type == TYPE_LDIV | |
14339 | || type == TYPE_INSERT_WORD) | |
14340 | return true; | |
14341 | } | |
14342 | ||
14343 | return false; | |
14344 | } | |
14345 | ||
14346 | /* The function returns true if INSN can be issued only from | |
a3c9585f | 14347 | the branch slot. */ |
cbe26ab8 DN |
14348 | |
14349 | static bool | |
14350 | is_branch_slot_insn (rtx insn) | |
14351 | { | |
14352 | if (!insn || !INSN_P (insn) | |
14353 | || GET_CODE (PATTERN (insn)) == USE | |
14354 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
14355 | return false; | |
14356 | ||
ec507f2d | 14357 | if (rs6000_sched_groups) |
cbe26ab8 DN |
14358 | { |
14359 | enum attr_type type = get_attr_type (insn); | |
14360 | if (type == TYPE_BRANCH || type == TYPE_JMPREG) | |
14361 | return true; | |
14362 | return false; | |
14363 | } | |
14364 | ||
14365 | return false; | |
14366 | } | |
79ae11c4 | 14367 | |
a4f6c312 | 14368 | /* A C statement (sans semicolon) to update the integer scheduling |
79ae11c4 DN |
14369 | priority INSN_PRIORITY (INSN). Increase the priority to execute the |
14370 | INSN earlier, reduce the priority to execute INSN later. Do not | |
a4f6c312 SS |
14371 | define this macro if you do not need to adjust the scheduling |
14372 | priorities of insns. */ | |
bef84347 | 14373 | |
c237e94a | 14374 | static int |
a2369ed3 | 14375 | rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority) |
bef84347 | 14376 | { |
a4f6c312 SS |
14377 | /* On machines (like the 750) which have asymmetric integer units, |
14378 | where one integer unit can do multiply and divides and the other | |
14379 | can't, reduce the priority of multiply/divide so it is scheduled | |
14380 | before other integer operations. */ | |
bef84347 VM |
14381 | |
14382 | #if 0 | |
2c3c49de | 14383 | if (! INSN_P (insn)) |
bef84347 VM |
14384 | return priority; |
14385 | ||
14386 | if (GET_CODE (PATTERN (insn)) == USE) | |
14387 | return priority; | |
14388 | ||
14389 | switch (rs6000_cpu_attr) { | |
14390 | case CPU_PPC750: | |
14391 | switch (get_attr_type (insn)) | |
14392 | { | |
14393 | default: | |
14394 | break; | |
14395 | ||
14396 | case TYPE_IMUL: | |
14397 | case TYPE_IDIV: | |
3cb999d8 DE |
14398 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
14399 | priority, priority); | |
bef84347 VM |
14400 | if (priority >= 0 && priority < 0x01000000) |
14401 | priority >>= 3; | |
14402 | break; | |
14403 | } | |
14404 | } | |
14405 | #endif | |
14406 | ||
79ae11c4 DN |
14407 | if (is_dispatch_slot_restricted (insn) |
14408 | && reload_completed | |
14409 | && current_sched_info->sched_max_insns_priority | |
14410 | && rs6000_sched_restricted_insns_priority) | |
14411 | { | |
14412 | ||
14413 | /* Prioritize insns that can be dispatched only in the first dispatch slot. */ | |
14414 | if (rs6000_sched_restricted_insns_priority == 1) | |
14415 | /* Attach highest priority to insn. This means that in | |
14416 | haifa-sched.c:ready_sort(), dispatch-slot restriction considerations | |
14417 | precede 'priority' (critical path) considerations. */ | |
14418 | return current_sched_info->sched_max_insns_priority; | |
14419 | else if (rs6000_sched_restricted_insns_priority == 2) | |
14420 | /* Increase priority of insn by a minimal amount. This means that in | |
14421 | haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations | |
14422 | precede dispatch-slot restriction considerations. */ | |
14423 | return (priority + 1); | |
14424 | } | |
14425 | ||
bef84347 VM |
14426 | return priority; |
14427 | } | |
14428 | ||
a4f6c312 SS |
14429 | /* Return how many instructions the machine can issue per cycle. */ |
14430 | ||
c237e94a | 14431 | static int |
863d938c | 14432 | rs6000_issue_rate (void) |
b6c9286a | 14433 | { |
3317bab1 DE |
14434 | /* Use issue rate of 1 for first scheduling pass to decrease degradation. */ |
14435 | if (!reload_completed) | |
14436 | return 1; | |
14437 | ||
b6c9286a | 14438 | switch (rs6000_cpu_attr) { |
3cb999d8 DE |
14439 | case CPU_RIOS1: /* ? */ |
14440 | case CPU_RS64A: | |
14441 | case CPU_PPC601: /* ? */ | |
ed947a96 | 14442 | case CPU_PPC7450: |
3cb999d8 | 14443 | return 3; |
b54cf83a | 14444 | case CPU_PPC440: |
b6c9286a | 14445 | case CPU_PPC603: |
bef84347 | 14446 | case CPU_PPC750: |
ed947a96 | 14447 | case CPU_PPC7400: |
be12c2b0 | 14448 | case CPU_PPC8540: |
bef84347 | 14449 | return 2; |
3cb999d8 | 14450 | case CPU_RIOS2: |
b6c9286a | 14451 | case CPU_PPC604: |
19684119 | 14452 | case CPU_PPC604E: |
b6c9286a | 14453 | case CPU_PPC620: |
3cb999d8 | 14454 | case CPU_PPC630: |
b6c9286a | 14455 | return 4; |
cbe26ab8 | 14456 | case CPU_POWER4: |
ec507f2d | 14457 | case CPU_POWER5: |
cbe26ab8 | 14458 | return 5; |
b6c9286a MM |
14459 | default: |
14460 | return 1; | |
14461 | } | |
14462 | } | |
14463 | ||
be12c2b0 VM |
14464 | /* Return how many instructions to look ahead for better insn |
14465 | scheduling. */ | |
14466 | ||
14467 | static int | |
863d938c | 14468 | rs6000_use_sched_lookahead (void) |
be12c2b0 VM |
14469 | { |
14470 | if (rs6000_cpu_attr == CPU_PPC8540) | |
14471 | return 4; | |
14472 | return 0; | |
14473 | } | |
14474 | ||
569fa502 DN |
14475 | /* Determine is PAT refers to memory. */ |
14476 | ||
14477 | static bool | |
14478 | is_mem_ref (rtx pat) | |
14479 | { | |
14480 | const char * fmt; | |
14481 | int i, j; | |
14482 | bool ret = false; | |
14483 | ||
14484 | if (GET_CODE (pat) == MEM) | |
14485 | return true; | |
14486 | ||
14487 | /* Recursively process the pattern. */ | |
14488 | fmt = GET_RTX_FORMAT (GET_CODE (pat)); | |
14489 | ||
14490 | for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--) | |
14491 | { | |
14492 | if (fmt[i] == 'e') | |
14493 | ret |= is_mem_ref (XEXP (pat, i)); | |
14494 | else if (fmt[i] == 'E') | |
14495 | for (j = XVECLEN (pat, i) - 1; j >= 0; j--) | |
14496 | ret |= is_mem_ref (XVECEXP (pat, i, j)); | |
14497 | } | |
14498 | ||
14499 | return ret; | |
14500 | } | |
14501 | ||
14502 | /* Determine if PAT is a PATTERN of a load insn. */ | |
14503 | ||
14504 | static bool | |
14505 | is_load_insn1 (rtx pat) | |
14506 | { | |
14507 | if (!pat || pat == NULL_RTX) | |
14508 | return false; | |
14509 | ||
14510 | if (GET_CODE (pat) == SET) | |
14511 | return is_mem_ref (SET_SRC (pat)); | |
14512 | ||
14513 | if (GET_CODE (pat) == PARALLEL) | |
14514 | { | |
14515 | int i; | |
14516 | ||
14517 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
14518 | if (is_load_insn1 (XVECEXP (pat, 0, i))) | |
14519 | return true; | |
14520 | } | |
14521 | ||
14522 | return false; | |
14523 | } | |
14524 | ||
14525 | /* Determine if INSN loads from memory. */ | |
14526 | ||
14527 | static bool | |
14528 | is_load_insn (rtx insn) | |
14529 | { | |
14530 | if (!insn || !INSN_P (insn)) | |
14531 | return false; | |
14532 | ||
14533 | if (GET_CODE (insn) == CALL_INSN) | |
14534 | return false; | |
14535 | ||
14536 | return is_load_insn1 (PATTERN (insn)); | |
14537 | } | |
14538 | ||
14539 | /* Determine if PAT is a PATTERN of a store insn. */ | |
14540 | ||
14541 | static bool | |
14542 | is_store_insn1 (rtx pat) | |
14543 | { | |
14544 | if (!pat || pat == NULL_RTX) | |
14545 | return false; | |
14546 | ||
14547 | if (GET_CODE (pat) == SET) | |
14548 | return is_mem_ref (SET_DEST (pat)); | |
14549 | ||
14550 | if (GET_CODE (pat) == PARALLEL) | |
14551 | { | |
14552 | int i; | |
14553 | ||
14554 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
14555 | if (is_store_insn1 (XVECEXP (pat, 0, i))) | |
14556 | return true; | |
14557 | } | |
14558 | ||
14559 | return false; | |
14560 | } | |
14561 | ||
14562 | /* Determine if INSN stores to memory. */ | |
14563 | ||
14564 | static bool | |
14565 | is_store_insn (rtx insn) | |
14566 | { | |
14567 | if (!insn || !INSN_P (insn)) | |
14568 | return false; | |
14569 | ||
14570 | return is_store_insn1 (PATTERN (insn)); | |
14571 | } | |
14572 | ||
14573 | /* Returns whether the dependence between INSN and NEXT is considered | |
14574 | costly by the given target. */ | |
14575 | ||
14576 | static bool | |
14577 | rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance) | |
14578 | { | |
14579 | /* If the flag is not enbled - no dependence is considered costly; | |
14580 | allow all dependent insns in the same group. | |
14581 | This is the most aggressive option. */ | |
14582 | if (rs6000_sched_costly_dep == no_dep_costly) | |
14583 | return false; | |
14584 | ||
14585 | /* If the flag is set to 1 - a dependence is always considered costly; | |
14586 | do not allow dependent instructions in the same group. | |
14587 | This is the most conservative option. */ | |
14588 | if (rs6000_sched_costly_dep == all_deps_costly) | |
14589 | return true; | |
14590 | ||
14591 | if (rs6000_sched_costly_dep == store_to_load_dep_costly | |
14592 | && is_load_insn (next) | |
14593 | && is_store_insn (insn)) | |
14594 | /* Prevent load after store in the same group. */ | |
14595 | return true; | |
14596 | ||
14597 | if (rs6000_sched_costly_dep == true_store_to_load_dep_costly | |
14598 | && is_load_insn (next) | |
14599 | && is_store_insn (insn) | |
14600 | && (!link || (int) REG_NOTE_KIND (link) == 0)) | |
14601 | /* Prevent load after store in the same group if it is a true dependence. */ | |
14602 | return true; | |
14603 | ||
14604 | /* The flag is set to X; dependences with latency >= X are considered costly, | |
14605 | and will not be scheduled in the same group. */ | |
14606 | if (rs6000_sched_costly_dep <= max_dep_latency | |
14607 | && ((cost - distance) >= (int)rs6000_sched_costly_dep)) | |
14608 | return true; | |
14609 | ||
14610 | return false; | |
14611 | } | |
14612 | ||
cbe26ab8 DN |
14613 | /* Return the next insn after INSN that is found before TAIL is reached, |
14614 | skipping any "non-active" insns - insns that will not actually occupy | |
14615 | an issue slot. Return NULL_RTX if such an insn is not found. */ | |
14616 | ||
14617 | static rtx | |
14618 | get_next_active_insn (rtx insn, rtx tail) | |
14619 | { | |
14620 | rtx next_insn; | |
14621 | ||
14622 | if (!insn || insn == tail) | |
14623 | return NULL_RTX; | |
14624 | ||
14625 | next_insn = NEXT_INSN (insn); | |
14626 | ||
14627 | while (next_insn | |
14628 | && next_insn != tail | |
14629 | && (GET_CODE(next_insn) == NOTE | |
14630 | || GET_CODE (PATTERN (next_insn)) == USE | |
14631 | || GET_CODE (PATTERN (next_insn)) == CLOBBER)) | |
14632 | { | |
14633 | next_insn = NEXT_INSN (next_insn); | |
14634 | } | |
14635 | ||
14636 | if (!next_insn || next_insn == tail) | |
14637 | return NULL_RTX; | |
14638 | ||
14639 | return next_insn; | |
14640 | } | |
14641 | ||
839a4992 | 14642 | /* Return whether the presence of INSN causes a dispatch group termination |
cbe26ab8 DN |
14643 | of group WHICH_GROUP. |
14644 | ||
14645 | If WHICH_GROUP == current_group, this function will return true if INSN | |
14646 | causes the termination of the current group (i.e, the dispatch group to | |
14647 | which INSN belongs). This means that INSN will be the last insn in the | |
14648 | group it belongs to. | |
14649 | ||
14650 | If WHICH_GROUP == previous_group, this function will return true if INSN | |
14651 | causes the termination of the previous group (i.e, the dispatch group that | |
14652 | precedes the group to which INSN belongs). This means that INSN will be | |
14653 | the first insn in the group it belongs to). */ | |
14654 | ||
14655 | static bool | |
14656 | insn_terminates_group_p (rtx insn, enum group_termination which_group) | |
14657 | { | |
14658 | enum attr_type type; | |
14659 | ||
14660 | if (! insn) | |
14661 | return false; | |
569fa502 | 14662 | |
cbe26ab8 DN |
14663 | type = get_attr_type (insn); |
14664 | ||
14665 | if (is_microcoded_insn (insn)) | |
14666 | return true; | |
14667 | ||
14668 | if (which_group == current_group) | |
14669 | { | |
14670 | if (is_branch_slot_insn (insn)) | |
14671 | return true; | |
14672 | return false; | |
14673 | } | |
14674 | else if (which_group == previous_group) | |
14675 | { | |
14676 | if (is_dispatch_slot_restricted (insn)) | |
14677 | return true; | |
14678 | return false; | |
14679 | } | |
14680 | ||
14681 | return false; | |
14682 | } | |
14683 | ||
839a4992 | 14684 | /* Return true if it is recommended to keep NEXT_INSN "far" (in a separate |
cbe26ab8 DN |
14685 | dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */ |
14686 | ||
14687 | static bool | |
14688 | is_costly_group (rtx *group_insns, rtx next_insn) | |
14689 | { | |
14690 | int i; | |
14691 | rtx link; | |
14692 | int cost; | |
14693 | int issue_rate = rs6000_issue_rate (); | |
14694 | ||
14695 | for (i = 0; i < issue_rate; i++) | |
14696 | { | |
14697 | rtx insn = group_insns[i]; | |
14698 | if (!insn) | |
14699 | continue; | |
14700 | for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1)) | |
14701 | { | |
14702 | rtx next = XEXP (link, 0); | |
14703 | if (next == next_insn) | |
14704 | { | |
14705 | cost = insn_cost (insn, link, next_insn); | |
14706 | if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0)) | |
14707 | return true; | |
14708 | } | |
14709 | } | |
14710 | } | |
14711 | ||
14712 | return false; | |
14713 | } | |
14714 | ||
14715 | /* Utility of the function redefine_groups. | |
14716 | Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS | |
14717 | in the same dispatch group. If so, insert nops before NEXT_INSN, in order | |
14718 | to keep it "far" (in a separate group) from GROUP_INSNS, following | |
14719 | one of the following schemes, depending on the value of the flag | |
14720 | -minsert_sched_nops = X: | |
14721 | (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed | |
839a4992 | 14722 | in order to force NEXT_INSN into a separate group. |
cbe26ab8 DN |
14723 | (2) X < sched_finish_regroup_exact: insert exactly X nops. |
14724 | GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop | |
14725 | insertion (has a group just ended, how many vacant issue slots remain in the | |
14726 | last group, and how many dispatch groups were encountered so far). */ | |
14727 | ||
14728 | static int | |
14729 | force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn, | |
14730 | bool *group_end, int can_issue_more, int *group_count) | |
14731 | { | |
14732 | rtx nop; | |
14733 | bool force; | |
14734 | int issue_rate = rs6000_issue_rate (); | |
14735 | bool end = *group_end; | |
14736 | int i; | |
14737 | ||
14738 | if (next_insn == NULL_RTX) | |
14739 | return can_issue_more; | |
14740 | ||
14741 | if (rs6000_sched_insert_nops > sched_finish_regroup_exact) | |
14742 | return can_issue_more; | |
14743 | ||
14744 | force = is_costly_group (group_insns, next_insn); | |
14745 | if (!force) | |
14746 | return can_issue_more; | |
14747 | ||
14748 | if (sched_verbose > 6) | |
14749 | fprintf (dump,"force: group count = %d, can_issue_more = %d\n", | |
14750 | *group_count ,can_issue_more); | |
14751 | ||
14752 | if (rs6000_sched_insert_nops == sched_finish_regroup_exact) | |
14753 | { | |
14754 | if (*group_end) | |
14755 | can_issue_more = 0; | |
14756 | ||
14757 | /* Since only a branch can be issued in the last issue_slot, it is | |
14758 | sufficient to insert 'can_issue_more - 1' nops if next_insn is not | |
14759 | a branch. If next_insn is a branch, we insert 'can_issue_more' nops; | |
14760 | in this case the last nop will start a new group and the branch will be | |
14761 | forced to the new group. */ | |
14762 | if (can_issue_more && !is_branch_slot_insn (next_insn)) | |
14763 | can_issue_more--; | |
14764 | ||
14765 | while (can_issue_more > 0) | |
14766 | { | |
14767 | nop = gen_nop(); | |
14768 | emit_insn_before (nop, next_insn); | |
14769 | can_issue_more--; | |
14770 | } | |
14771 | ||
14772 | *group_end = true; | |
14773 | return 0; | |
14774 | } | |
14775 | ||
14776 | if (rs6000_sched_insert_nops < sched_finish_regroup_exact) | |
14777 | { | |
14778 | int n_nops = rs6000_sched_insert_nops; | |
14779 | ||
14780 | /* Nops can't be issued from the branch slot, so the effective | |
14781 | issue_rate for nops is 'issue_rate - 1'. */ | |
14782 | if (can_issue_more == 0) | |
14783 | can_issue_more = issue_rate; | |
14784 | can_issue_more--; | |
14785 | if (can_issue_more == 0) | |
14786 | { | |
14787 | can_issue_more = issue_rate - 1; | |
14788 | (*group_count)++; | |
14789 | end = true; | |
14790 | for (i = 0; i < issue_rate; i++) | |
14791 | { | |
14792 | group_insns[i] = 0; | |
14793 | } | |
14794 | } | |
14795 | ||
14796 | while (n_nops > 0) | |
14797 | { | |
14798 | nop = gen_nop (); | |
14799 | emit_insn_before (nop, next_insn); | |
14800 | if (can_issue_more == issue_rate - 1) /* new group begins */ | |
14801 | end = false; | |
14802 | can_issue_more--; | |
14803 | if (can_issue_more == 0) | |
14804 | { | |
14805 | can_issue_more = issue_rate - 1; | |
14806 | (*group_count)++; | |
14807 | end = true; | |
14808 | for (i = 0; i < issue_rate; i++) | |
14809 | { | |
14810 | group_insns[i] = 0; | |
14811 | } | |
14812 | } | |
14813 | n_nops--; | |
14814 | } | |
14815 | ||
14816 | /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */ | |
14817 | can_issue_more++; | |
14818 | ||
14819 | *group_end = /* Is next_insn going to start a new group? */ | |
14820 | (end | |
14821 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
14822 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
14823 | || (can_issue_more < issue_rate && | |
14824 | insn_terminates_group_p (next_insn, previous_group))); | |
14825 | if (*group_end && end) | |
14826 | (*group_count)--; | |
14827 | ||
14828 | if (sched_verbose > 6) | |
14829 | fprintf (dump, "done force: group count = %d, can_issue_more = %d\n", | |
14830 | *group_count, can_issue_more); | |
14831 | return can_issue_more; | |
14832 | } | |
14833 | ||
14834 | return can_issue_more; | |
14835 | } | |
14836 | ||
14837 | /* This function tries to synch the dispatch groups that the compiler "sees" | |
14838 | with the dispatch groups that the processor dispatcher is expected to | |
14839 | form in practice. It tries to achieve this synchronization by forcing the | |
14840 | estimated processor grouping on the compiler (as opposed to the function | |
14841 | 'pad_goups' which tries to force the scheduler's grouping on the processor). | |
14842 | ||
14843 | The function scans the insn sequence between PREV_HEAD_INSN and TAIL and | |
14844 | examines the (estimated) dispatch groups that will be formed by the processor | |
14845 | dispatcher. It marks these group boundaries to reflect the estimated | |
14846 | processor grouping, overriding the grouping that the scheduler had marked. | |
14847 | Depending on the value of the flag '-minsert-sched-nops' this function can | |
14848 | force certain insns into separate groups or force a certain distance between | |
14849 | them by inserting nops, for example, if there exists a "costly dependence" | |
14850 | between the insns. | |
14851 | ||
14852 | The function estimates the group boundaries that the processor will form as | |
14853 | folllows: It keeps track of how many vacant issue slots are available after | |
14854 | each insn. A subsequent insn will start a new group if one of the following | |
14855 | 4 cases applies: | |
14856 | - no more vacant issue slots remain in the current dispatch group. | |
14857 | - only the last issue slot, which is the branch slot, is vacant, but the next | |
14858 | insn is not a branch. | |
14859 | - only the last 2 or less issue slots, including the branch slot, are vacant, | |
14860 | which means that a cracked insn (which occupies two issue slots) can't be | |
14861 | issued in this group. | |
14862 | - less than 'issue_rate' slots are vacant, and the next insn always needs to | |
14863 | start a new group. */ | |
14864 | ||
14865 | static int | |
14866 | redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
14867 | { | |
14868 | rtx insn, next_insn; | |
14869 | int issue_rate; | |
14870 | int can_issue_more; | |
14871 | int slot, i; | |
14872 | bool group_end; | |
14873 | int group_count = 0; | |
14874 | rtx *group_insns; | |
14875 | ||
14876 | /* Initialize. */ | |
14877 | issue_rate = rs6000_issue_rate (); | |
14878 | group_insns = alloca (issue_rate * sizeof (rtx)); | |
14879 | for (i = 0; i < issue_rate; i++) | |
14880 | { | |
14881 | group_insns[i] = 0; | |
14882 | } | |
14883 | can_issue_more = issue_rate; | |
14884 | slot = 0; | |
14885 | insn = get_next_active_insn (prev_head_insn, tail); | |
14886 | group_end = false; | |
14887 | ||
14888 | while (insn != NULL_RTX) | |
14889 | { | |
14890 | slot = (issue_rate - can_issue_more); | |
14891 | group_insns[slot] = insn; | |
14892 | can_issue_more = | |
14893 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
14894 | if (insn_terminates_group_p (insn, current_group)) | |
14895 | can_issue_more = 0; | |
14896 | ||
14897 | next_insn = get_next_active_insn (insn, tail); | |
14898 | if (next_insn == NULL_RTX) | |
14899 | return group_count + 1; | |
14900 | ||
14901 | group_end = /* Is next_insn going to start a new group? */ | |
14902 | (can_issue_more == 0 | |
14903 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
14904 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
14905 | || (can_issue_more < issue_rate && | |
14906 | insn_terminates_group_p (next_insn, previous_group))); | |
14907 | ||
14908 | can_issue_more = force_new_group (sched_verbose, dump, group_insns, | |
14909 | next_insn, &group_end, can_issue_more, &group_count); | |
14910 | ||
14911 | if (group_end) | |
14912 | { | |
14913 | group_count++; | |
14914 | can_issue_more = 0; | |
14915 | for (i = 0; i < issue_rate; i++) | |
14916 | { | |
14917 | group_insns[i] = 0; | |
14918 | } | |
14919 | } | |
14920 | ||
14921 | if (GET_MODE (next_insn) == TImode && can_issue_more) | |
14922 | PUT_MODE(next_insn, VOIDmode); | |
14923 | else if (!can_issue_more && GET_MODE (next_insn) != TImode) | |
14924 | PUT_MODE (next_insn, TImode); | |
14925 | ||
14926 | insn = next_insn; | |
14927 | if (can_issue_more == 0) | |
14928 | can_issue_more = issue_rate; | |
14929 | } /* while */ | |
14930 | ||
14931 | return group_count; | |
14932 | } | |
14933 | ||
14934 | /* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the | |
14935 | dispatch group boundaries that the scheduler had marked. Pad with nops | |
14936 | any dispatch groups which have vacant issue slots, in order to force the | |
14937 | scheduler's grouping on the processor dispatcher. The function | |
14938 | returns the number of dispatch groups found. */ | |
14939 | ||
14940 | static int | |
14941 | pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
14942 | { | |
14943 | rtx insn, next_insn; | |
14944 | rtx nop; | |
14945 | int issue_rate; | |
14946 | int can_issue_more; | |
14947 | int group_end; | |
14948 | int group_count = 0; | |
14949 | ||
14950 | /* Initialize issue_rate. */ | |
14951 | issue_rate = rs6000_issue_rate (); | |
14952 | can_issue_more = issue_rate; | |
14953 | ||
14954 | insn = get_next_active_insn (prev_head_insn, tail); | |
14955 | next_insn = get_next_active_insn (insn, tail); | |
14956 | ||
14957 | while (insn != NULL_RTX) | |
14958 | { | |
14959 | can_issue_more = | |
14960 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
14961 | ||
14962 | group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode); | |
14963 | ||
14964 | if (next_insn == NULL_RTX) | |
14965 | break; | |
14966 | ||
14967 | if (group_end) | |
14968 | { | |
14969 | /* If the scheduler had marked group termination at this location | |
14970 | (between insn and next_indn), and neither insn nor next_insn will | |
14971 | force group termination, pad the group with nops to force group | |
14972 | termination. */ | |
14973 | if (can_issue_more | |
14974 | && (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
14975 | && !insn_terminates_group_p (insn, current_group) | |
14976 | && !insn_terminates_group_p (next_insn, previous_group)) | |
14977 | { | |
14978 | if (!is_branch_slot_insn(next_insn)) | |
14979 | can_issue_more--; | |
14980 | ||
14981 | while (can_issue_more) | |
14982 | { | |
14983 | nop = gen_nop (); | |
14984 | emit_insn_before (nop, next_insn); | |
14985 | can_issue_more--; | |
14986 | } | |
14987 | } | |
14988 | ||
14989 | can_issue_more = issue_rate; | |
14990 | group_count++; | |
14991 | } | |
14992 | ||
14993 | insn = next_insn; | |
14994 | next_insn = get_next_active_insn (insn, tail); | |
14995 | } | |
14996 | ||
14997 | return group_count; | |
14998 | } | |
14999 | ||
15000 | /* The following function is called at the end of scheduling BB. | |
15001 | After reload, it inserts nops at insn group bundling. */ | |
15002 | ||
15003 | static void | |
38f391a5 | 15004 | rs6000_sched_finish (FILE *dump, int sched_verbose) |
cbe26ab8 DN |
15005 | { |
15006 | int n_groups; | |
15007 | ||
15008 | if (sched_verbose) | |
15009 | fprintf (dump, "=== Finishing schedule.\n"); | |
15010 | ||
ec507f2d | 15011 | if (reload_completed && rs6000_sched_groups) |
cbe26ab8 DN |
15012 | { |
15013 | if (rs6000_sched_insert_nops == sched_finish_none) | |
15014 | return; | |
15015 | ||
15016 | if (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
15017 | n_groups = pad_groups (dump, sched_verbose, | |
15018 | current_sched_info->prev_head, | |
15019 | current_sched_info->next_tail); | |
15020 | else | |
15021 | n_groups = redefine_groups (dump, sched_verbose, | |
15022 | current_sched_info->prev_head, | |
15023 | current_sched_info->next_tail); | |
15024 | ||
15025 | if (sched_verbose >= 6) | |
15026 | { | |
15027 | fprintf (dump, "ngroups = %d\n", n_groups); | |
15028 | print_rtl (dump, current_sched_info->prev_head); | |
15029 | fprintf (dump, "Done finish_sched\n"); | |
15030 | } | |
15031 | } | |
15032 | } | |
b6c9286a | 15033 | \f |
b6c9286a MM |
15034 | /* Length in units of the trampoline for entering a nested function. */ |
15035 | ||
15036 | int | |
863d938c | 15037 | rs6000_trampoline_size (void) |
b6c9286a MM |
15038 | { |
15039 | int ret = 0; | |
15040 | ||
15041 | switch (DEFAULT_ABI) | |
15042 | { | |
15043 | default: | |
15044 | abort (); | |
15045 | ||
15046 | case ABI_AIX: | |
8f802bfb | 15047 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
15048 | break; |
15049 | ||
4dabc42d | 15050 | case ABI_DARWIN: |
b6c9286a | 15051 | case ABI_V4: |
03a7e1a5 | 15052 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 15053 | break; |
b6c9286a MM |
15054 | } |
15055 | ||
15056 | return ret; | |
15057 | } | |
15058 | ||
15059 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
15060 | FNADDR is an RTX for the address of the function's pure code. | |
15061 | CXT is an RTX for the static chain value for the function. */ | |
15062 | ||
15063 | void | |
a2369ed3 | 15064 | rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt) |
b6c9286a | 15065 | { |
ac2a93a1 | 15066 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
15067 | int regsize = (TARGET_32BIT) ? 4 : 8; |
15068 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
15069 | |
15070 | switch (DEFAULT_ABI) | |
15071 | { | |
15072 | default: | |
15073 | abort (); | |
15074 | ||
8bd04c56 | 15075 | /* Macros to shorten the code expansions below. */ |
39403d82 | 15076 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
15077 | #define MEM_PLUS(addr,offset) \ |
15078 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 15079 | |
b6c9286a MM |
15080 | /* Under AIX, just build the 3 word function descriptor */ |
15081 | case ABI_AIX: | |
8bd04c56 MM |
15082 | { |
15083 | rtx fn_reg = gen_reg_rtx (pmode); | |
15084 | rtx toc_reg = gen_reg_rtx (pmode); | |
15085 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
1cb18e3c | 15086 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); |
8bd04c56 MM |
15087 | emit_move_insn (MEM_DEREF (addr), fn_reg); |
15088 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
15089 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
15090 | } | |
b6c9286a MM |
15091 | break; |
15092 | ||
4dabc42d TC |
15093 | /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */ |
15094 | case ABI_DARWIN: | |
b6c9286a | 15095 | case ABI_V4: |
39403d82 | 15096 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
15097 | FALSE, VOIDmode, 4, |
15098 | addr, pmode, | |
15099 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
15100 | fnaddr, pmode, | |
15101 | ctx_reg, pmode); | |
b6c9286a | 15102 | break; |
b6c9286a MM |
15103 | } |
15104 | ||
15105 | return; | |
15106 | } | |
7509c759 MM |
15107 | |
15108 | \f | |
91d231cb | 15109 | /* Table of valid machine attributes. */ |
a4f6c312 | 15110 | |
91d231cb | 15111 | const struct attribute_spec rs6000_attribute_table[] = |
7509c759 | 15112 | { |
91d231cb | 15113 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
8bb418a3 | 15114 | { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute }, |
a5c76ee6 ZW |
15115 | { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, |
15116 | { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, | |
15117 | { NULL, 0, 0, false, false, false, NULL } | |
91d231cb | 15118 | }; |
7509c759 | 15119 | |
8bb418a3 ZL |
15120 | /* Handle the "altivec" attribute. The attribute may have |
15121 | arguments as follows: | |
15122 | ||
15123 | __attribute__((altivec(vector__))) | |
15124 | __attribute__((altivec(pixel__))) (always followed by 'unsigned short') | |
15125 | __attribute__((altivec(bool__))) (always followed by 'unsigned') | |
15126 | ||
15127 | and may appear more than once (e.g., 'vector bool char') in a | |
15128 | given declaration. */ | |
15129 | ||
15130 | static tree | |
15131 | rs6000_handle_altivec_attribute (tree *node, tree name, tree args, | |
15132 | int flags ATTRIBUTE_UNUSED, | |
15133 | bool *no_add_attrs) | |
15134 | { | |
15135 | tree type = *node, result = NULL_TREE; | |
15136 | enum machine_mode mode; | |
15137 | int unsigned_p; | |
15138 | char altivec_type | |
15139 | = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args) | |
15140 | && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE) | |
15141 | ? *IDENTIFIER_POINTER (TREE_VALUE (args)) | |
15142 | : '?'); | |
15143 | ||
15144 | while (POINTER_TYPE_P (type) | |
15145 | || TREE_CODE (type) == FUNCTION_TYPE | |
15146 | || TREE_CODE (type) == METHOD_TYPE | |
15147 | || TREE_CODE (type) == ARRAY_TYPE) | |
15148 | type = TREE_TYPE (type); | |
15149 | ||
15150 | mode = TYPE_MODE (type); | |
15151 | ||
15152 | if (rs6000_warn_altivec_long | |
15153 | && (type == long_unsigned_type_node || type == long_integer_type_node)) | |
15154 | warning ("use of 'long' in AltiVec types is deprecated; use 'int'"); | |
15155 | ||
15156 | switch (altivec_type) | |
15157 | { | |
15158 | case 'v': | |
8df83eae | 15159 | unsigned_p = TYPE_UNSIGNED (type); |
8bb418a3 ZL |
15160 | switch (mode) |
15161 | { | |
15162 | case SImode: | |
15163 | result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node); | |
15164 | break; | |
15165 | case HImode: | |
15166 | result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node); | |
15167 | break; | |
15168 | case QImode: | |
15169 | result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node); | |
15170 | break; | |
15171 | case SFmode: result = V4SF_type_node; break; | |
15172 | /* If the user says 'vector int bool', we may be handed the 'bool' | |
15173 | attribute _before_ the 'vector' attribute, and so select the proper | |
15174 | type in the 'b' case below. */ | |
15175 | case V4SImode: case V8HImode: case V16QImode: result = type; | |
15176 | default: break; | |
15177 | } | |
15178 | break; | |
15179 | case 'b': | |
15180 | switch (mode) | |
15181 | { | |
15182 | case SImode: case V4SImode: result = bool_V4SI_type_node; break; | |
15183 | case HImode: case V8HImode: result = bool_V8HI_type_node; break; | |
15184 | case QImode: case V16QImode: result = bool_V16QI_type_node; | |
15185 | default: break; | |
15186 | } | |
15187 | break; | |
15188 | case 'p': | |
15189 | switch (mode) | |
15190 | { | |
15191 | case V8HImode: result = pixel_V8HI_type_node; | |
15192 | default: break; | |
15193 | } | |
15194 | default: break; | |
15195 | } | |
15196 | ||
7958a2a6 FJ |
15197 | if (result && result != type && TYPE_READONLY (type)) |
15198 | result = build_qualified_type (result, TYPE_QUAL_CONST); | |
15199 | ||
8bb418a3 ZL |
15200 | *no_add_attrs = true; /* No need to hang on to the attribute. */ |
15201 | ||
15202 | if (!result) | |
15203 | warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); | |
15204 | else | |
15205 | *node = reconstruct_complex_type (*node, result); | |
15206 | ||
15207 | return NULL_TREE; | |
15208 | } | |
15209 | ||
f18eca82 ZL |
15210 | /* AltiVec defines four built-in scalar types that serve as vector |
15211 | elements; we must teach the compiler how to mangle them. */ | |
15212 | ||
15213 | static const char * | |
15214 | rs6000_mangle_fundamental_type (tree type) | |
15215 | { | |
15216 | if (type == bool_char_type_node) return "U6__boolc"; | |
15217 | if (type == bool_short_type_node) return "U6__bools"; | |
15218 | if (type == pixel_type_node) return "u7__pixel"; | |
15219 | if (type == bool_int_type_node) return "U6__booli"; | |
15220 | ||
15221 | /* For all other types, use normal C++ mangling. */ | |
15222 | return NULL; | |
15223 | } | |
15224 | ||
a5c76ee6 ZW |
15225 | /* Handle a "longcall" or "shortcall" attribute; arguments as in |
15226 | struct attribute_spec.handler. */ | |
a4f6c312 | 15227 | |
91d231cb | 15228 | static tree |
a2369ed3 DJ |
15229 | rs6000_handle_longcall_attribute (tree *node, tree name, |
15230 | tree args ATTRIBUTE_UNUSED, | |
15231 | int flags ATTRIBUTE_UNUSED, | |
15232 | bool *no_add_attrs) | |
91d231cb JM |
15233 | { |
15234 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
15235 | && TREE_CODE (*node) != FIELD_DECL | |
15236 | && TREE_CODE (*node) != TYPE_DECL) | |
15237 | { | |
15238 | warning ("`%s' attribute only applies to functions", | |
15239 | IDENTIFIER_POINTER (name)); | |
15240 | *no_add_attrs = true; | |
15241 | } | |
6a4cee5f | 15242 | |
91d231cb | 15243 | return NULL_TREE; |
7509c759 MM |
15244 | } |
15245 | ||
a5c76ee6 ZW |
15246 | /* Set longcall attributes on all functions declared when |
15247 | rs6000_default_long_calls is true. */ | |
15248 | static void | |
a2369ed3 | 15249 | rs6000_set_default_type_attributes (tree type) |
a5c76ee6 ZW |
15250 | { |
15251 | if (rs6000_default_long_calls | |
15252 | && (TREE_CODE (type) == FUNCTION_TYPE | |
15253 | || TREE_CODE (type) == METHOD_TYPE)) | |
15254 | TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"), | |
15255 | NULL_TREE, | |
15256 | TYPE_ATTRIBUTES (type)); | |
15257 | } | |
15258 | ||
3cb999d8 DE |
15259 | /* Return a reference suitable for calling a function with the |
15260 | longcall attribute. */ | |
a4f6c312 | 15261 | |
6a4cee5f | 15262 | struct rtx_def * |
a2369ed3 | 15263 | rs6000_longcall_ref (rtx call_ref) |
6a4cee5f | 15264 | { |
d330fd93 | 15265 | const char *call_name; |
6a4cee5f MM |
15266 | tree node; |
15267 | ||
15268 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
15269 | return call_ref; | |
15270 | ||
15271 | /* System V adds '.' to the internal name, so skip them. */ | |
15272 | call_name = XSTR (call_ref, 0); | |
15273 | if (*call_name == '.') | |
15274 | { | |
15275 | while (*call_name == '.') | |
15276 | call_name++; | |
15277 | ||
15278 | node = get_identifier (call_name); | |
39403d82 | 15279 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
15280 | } |
15281 | ||
15282 | return force_reg (Pmode, call_ref); | |
15283 | } | |
7509c759 | 15284 | \f |
b64a1b53 RH |
15285 | #ifdef USING_ELFOS_H |
15286 | ||
7509c759 MM |
15287 | /* A C statement or statements to switch to the appropriate section |
15288 | for output of RTX in mode MODE. You can assume that RTX is some | |
15289 | kind of constant in RTL. The argument MODE is redundant except in | |
15290 | the case of a `const_int' rtx. Select the section by calling | |
15291 | `text_section' or one of the alternatives for other sections. | |
15292 | ||
15293 | Do not define this macro if you put all constants in the read-only | |
15294 | data section. */ | |
15295 | ||
b64a1b53 | 15296 | static void |
a2369ed3 DJ |
15297 | rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x, |
15298 | unsigned HOST_WIDE_INT align) | |
7509c759 | 15299 | { |
a9098fd0 | 15300 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 15301 | toc_section (); |
7509c759 | 15302 | else |
b64a1b53 | 15303 | default_elf_select_rtx_section (mode, x, align); |
7509c759 MM |
15304 | } |
15305 | ||
15306 | /* A C statement or statements to switch to the appropriate | |
15307 | section for output of DECL. DECL is either a `VAR_DECL' node | |
15308 | or a constant of some sort. RELOC indicates whether forming | |
15309 | the initial value of DECL requires link-time relocations. */ | |
15310 | ||
ae46c4e0 | 15311 | static void |
a2369ed3 DJ |
15312 | rs6000_elf_select_section (tree decl, int reloc, |
15313 | unsigned HOST_WIDE_INT align) | |
7509c759 | 15314 | { |
f1384257 AM |
15315 | /* Pretend that we're always building for a shared library when |
15316 | ABI_AIX, because otherwise we end up with dynamic relocations | |
15317 | in read-only sections. This happens for function pointers, | |
15318 | references to vtables in typeinfo, and probably other cases. */ | |
0e5dbd9b DE |
15319 | default_elf_select_section_1 (decl, reloc, align, |
15320 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
63019373 GK |
15321 | } |
15322 | ||
15323 | /* A C statement to build up a unique section name, expressed as a | |
15324 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
15325 | RELOC indicates whether the initial value of EXP requires | |
15326 | link-time relocations. If you do not define this macro, GCC will use | |
15327 | the symbol name prefixed by `.' as the section name. Note - this | |
f5143c46 | 15328 | macro can now be called for uninitialized data items as well as |
4912a07c | 15329 | initialized data and functions. */ |
63019373 | 15330 | |
ae46c4e0 | 15331 | static void |
a2369ed3 | 15332 | rs6000_elf_unique_section (tree decl, int reloc) |
63019373 | 15333 | { |
f1384257 AM |
15334 | /* As above, pretend that we're always building for a shared library |
15335 | when ABI_AIX, to avoid dynamic relocations in read-only sections. */ | |
0e5dbd9b DE |
15336 | default_unique_section_1 (decl, reloc, |
15337 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7509c759 | 15338 | } |
d9407988 | 15339 | \f |
d1908feb JJ |
15340 | /* For a SYMBOL_REF, set generic flags and then perform some |
15341 | target-specific processing. | |
15342 | ||
d1908feb JJ |
15343 | When the AIX ABI is requested on a non-AIX system, replace the |
15344 | function name with the real name (with a leading .) rather than the | |
15345 | function descriptor name. This saves a lot of overriding code to | |
15346 | read the prefixes. */ | |
d9407988 | 15347 | |
fb49053f | 15348 | static void |
a2369ed3 | 15349 | rs6000_elf_encode_section_info (tree decl, rtx rtl, int first) |
d9407988 | 15350 | { |
d1908feb | 15351 | default_encode_section_info (decl, rtl, first); |
b2003250 | 15352 | |
d1908feb JJ |
15353 | if (first |
15354 | && TREE_CODE (decl) == FUNCTION_DECL | |
15355 | && !TARGET_AIX | |
15356 | && DEFAULT_ABI == ABI_AIX) | |
d9407988 | 15357 | { |
c6a2438a | 15358 | rtx sym_ref = XEXP (rtl, 0); |
d1908feb JJ |
15359 | size_t len = strlen (XSTR (sym_ref, 0)); |
15360 | char *str = alloca (len + 2); | |
15361 | str[0] = '.'; | |
15362 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
15363 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1); | |
d9407988 | 15364 | } |
d9407988 MM |
15365 | } |
15366 | ||
0e5dbd9b | 15367 | static bool |
a2369ed3 | 15368 | rs6000_elf_in_small_data_p (tree decl) |
0e5dbd9b DE |
15369 | { |
15370 | if (rs6000_sdata == SDATA_NONE) | |
15371 | return false; | |
15372 | ||
15373 | if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl)) | |
15374 | { | |
15375 | const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
15376 | if (strcmp (section, ".sdata") == 0 | |
15377 | || strcmp (section, ".sdata2") == 0 | |
20bfcd69 GK |
15378 | || strcmp (section, ".sbss") == 0 |
15379 | || strcmp (section, ".sbss2") == 0 | |
15380 | || strcmp (section, ".PPC.EMB.sdata0") == 0 | |
15381 | || strcmp (section, ".PPC.EMB.sbss0") == 0) | |
0e5dbd9b DE |
15382 | return true; |
15383 | } | |
15384 | else | |
15385 | { | |
15386 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); | |
15387 | ||
15388 | if (size > 0 | |
307b599c | 15389 | && (unsigned HOST_WIDE_INT) size <= g_switch_value |
20bfcd69 GK |
15390 | /* If it's not public, and we're not going to reference it there, |
15391 | there's no need to put it in the small data section. */ | |
0e5dbd9b DE |
15392 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))) |
15393 | return true; | |
15394 | } | |
15395 | ||
15396 | return false; | |
15397 | } | |
15398 | ||
b91da81f | 15399 | #endif /* USING_ELFOS_H */ |
000034eb | 15400 | |
a6c2a102 | 15401 | \f |
000034eb | 15402 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
15403 | ADDR can be effectively incremented by incrementing REG. |
15404 | ||
15405 | r0 is special and we must not select it as an address | |
15406 | register by this routine since our caller will try to | |
15407 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
15408 | |
15409 | struct rtx_def * | |
a2369ed3 | 15410 | find_addr_reg (rtx addr) |
000034eb DE |
15411 | { |
15412 | while (GET_CODE (addr) == PLUS) | |
15413 | { | |
02441cd6 JL |
15414 | if (GET_CODE (XEXP (addr, 0)) == REG |
15415 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 15416 | addr = XEXP (addr, 0); |
02441cd6 JL |
15417 | else if (GET_CODE (XEXP (addr, 1)) == REG |
15418 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
15419 | addr = XEXP (addr, 1); |
15420 | else if (CONSTANT_P (XEXP (addr, 0))) | |
15421 | addr = XEXP (addr, 1); | |
15422 | else if (CONSTANT_P (XEXP (addr, 1))) | |
15423 | addr = XEXP (addr, 0); | |
15424 | else | |
15425 | abort (); | |
15426 | } | |
02441cd6 | 15427 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
15428 | return addr; |
15429 | abort (); | |
15430 | } | |
15431 | ||
a6c2a102 | 15432 | void |
a2369ed3 | 15433 | rs6000_fatal_bad_address (rtx op) |
a6c2a102 DE |
15434 | { |
15435 | fatal_insn ("bad address", op); | |
15436 | } | |
c8023011 | 15437 | |
ee890fe2 SS |
15438 | #if TARGET_MACHO |
15439 | ||
15440 | #if 0 | |
15441 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
15442 | reference and a constant. */ | |
15443 | ||
15444 | int | |
a2369ed3 | 15445 | symbolic_operand (rtx op) |
ee890fe2 SS |
15446 | { |
15447 | switch (GET_CODE (op)) | |
15448 | { | |
15449 | case SYMBOL_REF: | |
15450 | case LABEL_REF: | |
15451 | return 1; | |
15452 | case CONST: | |
15453 | op = XEXP (op, 0); | |
15454 | return (GET_CODE (op) == SYMBOL_REF || | |
15455 | (GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
15456 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
15457 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
15458 | default: | |
15459 | return 0; | |
15460 | } | |
c8023011 | 15461 | } |
ee890fe2 SS |
15462 | #endif |
15463 | ||
efdba735 | 15464 | #if TARGET_MACHO |
ee890fe2 | 15465 | |
efdba735 | 15466 | static tree branch_island_list = 0; |
ee890fe2 | 15467 | |
efdba735 SH |
15468 | /* Remember to generate a branch island for far calls to the given |
15469 | function. */ | |
ee890fe2 | 15470 | |
efdba735 SH |
15471 | static void |
15472 | add_compiler_branch_island (tree label_name, tree function_name, int line_number) | |
ee890fe2 | 15473 | { |
efdba735 SH |
15474 | tree branch_island = build_tree_list (function_name, label_name); |
15475 | TREE_TYPE (branch_island) = build_int_2 (line_number, 0); | |
15476 | TREE_CHAIN (branch_island) = branch_island_list; | |
15477 | branch_island_list = branch_island; | |
ee890fe2 SS |
15478 | } |
15479 | ||
efdba735 SH |
15480 | #define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND) |
15481 | #define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND) | |
15482 | #define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \ | |
15483 | TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND)) | |
ee890fe2 | 15484 | |
efdba735 SH |
15485 | /* Generate far-jump branch islands for everything on the |
15486 | branch_island_list. Invoked immediately after the last instruction | |
15487 | of the epilogue has been emitted; the branch-islands must be | |
15488 | appended to, and contiguous with, the function body. Mach-O stubs | |
15489 | are generated in machopic_output_stub(). */ | |
ee890fe2 | 15490 | |
efdba735 SH |
15491 | static void |
15492 | macho_branch_islands (void) | |
15493 | { | |
15494 | char tmp_buf[512]; | |
15495 | tree branch_island; | |
15496 | ||
15497 | for (branch_island = branch_island_list; | |
15498 | branch_island; | |
15499 | branch_island = TREE_CHAIN (branch_island)) | |
15500 | { | |
15501 | const char *label = | |
15502 | IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island)); | |
15503 | const char *name = | |
15504 | darwin_strip_name_encoding ( | |
15505 | IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island))); | |
15506 | char name_buf[512]; | |
15507 | /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */ | |
15508 | if (name[0] == '*' || name[0] == '&') | |
15509 | strcpy (name_buf, name+1); | |
15510 | else | |
15511 | { | |
15512 | name_buf[0] = '_'; | |
15513 | strcpy (name_buf+1, name); | |
15514 | } | |
15515 | strcpy (tmp_buf, "\n"); | |
15516 | strcat (tmp_buf, label); | |
ee890fe2 | 15517 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 15518 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 15519 | fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 15520 | BRANCH_ISLAND_LINE_NUMBER(branch_island)); |
ee890fe2 | 15521 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 SH |
15522 | if (flag_pic) |
15523 | { | |
15524 | strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,"); | |
15525 | strcat (tmp_buf, label); | |
15526 | strcat (tmp_buf, "_pic\n"); | |
15527 | strcat (tmp_buf, label); | |
15528 | strcat (tmp_buf, "_pic:\n\tmflr r11\n"); | |
15529 | ||
15530 | strcat (tmp_buf, "\taddis r11,r11,ha16("); | |
15531 | strcat (tmp_buf, name_buf); | |
15532 | strcat (tmp_buf, " - "); | |
15533 | strcat (tmp_buf, label); | |
15534 | strcat (tmp_buf, "_pic)\n"); | |
15535 | ||
15536 | strcat (tmp_buf, "\tmtlr r0\n"); | |
15537 | ||
15538 | strcat (tmp_buf, "\taddi r12,r11,lo16("); | |
15539 | strcat (tmp_buf, name_buf); | |
15540 | strcat (tmp_buf, " - "); | |
15541 | strcat (tmp_buf, label); | |
15542 | strcat (tmp_buf, "_pic)\n"); | |
15543 | ||
15544 | strcat (tmp_buf, "\tmtctr r12\n\tbctr\n"); | |
15545 | } | |
15546 | else | |
15547 | { | |
15548 | strcat (tmp_buf, ":\nlis r12,hi16("); | |
15549 | strcat (tmp_buf, name_buf); | |
15550 | strcat (tmp_buf, ")\n\tori r12,r12,lo16("); | |
15551 | strcat (tmp_buf, name_buf); | |
15552 | strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr"); | |
15553 | } | |
15554 | output_asm_insn (tmp_buf, 0); | |
ee890fe2 | 15555 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 15556 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 15557 | fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 15558 | BRANCH_ISLAND_LINE_NUMBER (branch_island)); |
ee890fe2 | 15559 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 | 15560 | } |
ee890fe2 | 15561 | |
efdba735 | 15562 | branch_island_list = 0; |
ee890fe2 SS |
15563 | } |
15564 | ||
15565 | /* NO_PREVIOUS_DEF checks in the link list whether the function name is | |
15566 | already there or not. */ | |
15567 | ||
efdba735 | 15568 | static int |
a2369ed3 | 15569 | no_previous_def (tree function_name) |
ee890fe2 | 15570 | { |
efdba735 SH |
15571 | tree branch_island; |
15572 | for (branch_island = branch_island_list; | |
15573 | branch_island; | |
15574 | branch_island = TREE_CHAIN (branch_island)) | |
15575 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
ee890fe2 SS |
15576 | return 0; |
15577 | return 1; | |
15578 | } | |
15579 | ||
15580 | /* GET_PREV_LABEL gets the label name from the previous definition of | |
15581 | the function. */ | |
15582 | ||
efdba735 | 15583 | static tree |
a2369ed3 | 15584 | get_prev_label (tree function_name) |
ee890fe2 | 15585 | { |
efdba735 SH |
15586 | tree branch_island; |
15587 | for (branch_island = branch_island_list; | |
15588 | branch_island; | |
15589 | branch_island = TREE_CHAIN (branch_island)) | |
15590 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
15591 | return BRANCH_ISLAND_LABEL_NAME (branch_island); | |
ee890fe2 SS |
15592 | return 0; |
15593 | } | |
15594 | ||
15595 | /* INSN is either a function call or a millicode call. It may have an | |
15596 | unconditional jump in its delay slot. | |
15597 | ||
15598 | CALL_DEST is the routine we are calling. */ | |
15599 | ||
15600 | char * | |
efdba735 | 15601 | output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number) |
ee890fe2 SS |
15602 | { |
15603 | static char buf[256]; | |
efdba735 SH |
15604 | if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF |
15605 | && (INTVAL (operands[cookie_operand_number]) & CALL_LONG)) | |
ee890fe2 SS |
15606 | { |
15607 | tree labelname; | |
efdba735 | 15608 | tree funname = get_identifier (XSTR (operands[dest_operand_number], 0)); |
ee890fe2 SS |
15609 | |
15610 | if (no_previous_def (funname)) | |
15611 | { | |
308c142a | 15612 | int line_number = 0; |
ee890fe2 SS |
15613 | rtx label_rtx = gen_label_rtx (); |
15614 | char *label_buf, temp_buf[256]; | |
15615 | ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L", | |
15616 | CODE_LABEL_NUMBER (label_rtx)); | |
15617 | label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf; | |
15618 | labelname = get_identifier (label_buf); | |
15619 | for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn)); | |
15620 | if (insn) | |
15621 | line_number = NOTE_LINE_NUMBER (insn); | |
efdba735 | 15622 | add_compiler_branch_island (labelname, funname, line_number); |
ee890fe2 SS |
15623 | } |
15624 | else | |
15625 | labelname = get_prev_label (funname); | |
15626 | ||
efdba735 SH |
15627 | /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl' |
15628 | instruction will reach 'foo', otherwise link as 'bl L42'". | |
15629 | "L42" should be a 'branch island', that will do a far jump to | |
15630 | 'foo'. Branch islands are generated in | |
15631 | macho_branch_islands(). */ | |
ee890fe2 | 15632 | sprintf (buf, "jbsr %%z%d,%.246s", |
efdba735 | 15633 | dest_operand_number, IDENTIFIER_POINTER (labelname)); |
ee890fe2 SS |
15634 | } |
15635 | else | |
efdba735 SH |
15636 | sprintf (buf, "bl %%z%d", dest_operand_number); |
15637 | return buf; | |
ee890fe2 SS |
15638 | } |
15639 | ||
efdba735 | 15640 | #endif /* TARGET_MACHO */ |
ee890fe2 | 15641 | |
ee890fe2 SS |
15642 | /* Generate PIC and indirect symbol stubs. */ |
15643 | ||
15644 | void | |
a2369ed3 | 15645 | machopic_output_stub (FILE *file, const char *symb, const char *stub) |
ee890fe2 SS |
15646 | { |
15647 | unsigned int length; | |
a4f6c312 SS |
15648 | char *symbol_name, *lazy_ptr_name; |
15649 | char *local_label_0; | |
ee890fe2 SS |
15650 | static int label = 0; |
15651 | ||
df56a27f | 15652 | /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
772c5265 | 15653 | symb = (*targetm.strip_name_encoding) (symb); |
df56a27f | 15654 | |
ee890fe2 | 15655 | |
ee890fe2 SS |
15656 | length = strlen (symb); |
15657 | symbol_name = alloca (length + 32); | |
15658 | GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); | |
15659 | ||
15660 | lazy_ptr_name = alloca (length + 32); | |
15661 | GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length); | |
15662 | ||
ee890fe2 | 15663 | if (flag_pic == 2) |
d3c300d2 | 15664 | machopic_picsymbol_stub1_section (); |
ee890fe2 | 15665 | else |
d3c300d2 DJ |
15666 | machopic_symbol_stub1_section (); |
15667 | fprintf (file, "\t.align 2\n"); | |
ee890fe2 SS |
15668 | |
15669 | fprintf (file, "%s:\n", stub); | |
15670 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
15671 | ||
15672 | if (flag_pic == 2) | |
15673 | { | |
876455fa AP |
15674 | label++; |
15675 | local_label_0 = alloca (sizeof("\"L0000000000$spb\"")); | |
15676 | sprintf (local_label_0, "\"L%011d$spb\"", label); | |
15677 | ||
ee890fe2 SS |
15678 | fprintf (file, "\tmflr r0\n"); |
15679 | fprintf (file, "\tbcl 20,31,%s\n", local_label_0); | |
15680 | fprintf (file, "%s:\n\tmflr r11\n", local_label_0); | |
15681 | fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n", | |
15682 | lazy_ptr_name, local_label_0); | |
15683 | fprintf (file, "\tmtlr r0\n"); | |
d3c300d2 | 15684 | fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n", |
ee890fe2 SS |
15685 | lazy_ptr_name, local_label_0); |
15686 | fprintf (file, "\tmtctr r12\n"); | |
ee890fe2 SS |
15687 | fprintf (file, "\tbctr\n"); |
15688 | } | |
15689 | else | |
ab82a49f AP |
15690 | { |
15691 | fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name); | |
15692 | fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name); | |
15693 | fprintf (file, "\tmtctr r12\n"); | |
15694 | fprintf (file, "\tbctr\n"); | |
15695 | } | |
ee890fe2 SS |
15696 | |
15697 | machopic_lazy_symbol_ptr_section (); | |
15698 | fprintf (file, "%s:\n", lazy_ptr_name); | |
15699 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
15700 | fprintf (file, "\t.long dyld_stub_binding_helper\n"); | |
15701 | } | |
15702 | ||
15703 | /* Legitimize PIC addresses. If the address is already | |
15704 | position-independent, we return ORIG. Newly generated | |
15705 | position-independent addresses go into a reg. This is REG if non | |
15706 | zero, otherwise we allocate register(s) as necessary. */ | |
15707 | ||
c859cda6 | 15708 | #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000) |
ee890fe2 SS |
15709 | |
15710 | rtx | |
a2369ed3 DJ |
15711 | rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, |
15712 | rtx reg) | |
ee890fe2 SS |
15713 | { |
15714 | rtx base, offset; | |
15715 | ||
15716 | if (reg == NULL && ! reload_in_progress && ! reload_completed) | |
15717 | reg = gen_reg_rtx (Pmode); | |
15718 | ||
15719 | if (GET_CODE (orig) == CONST) | |
15720 | { | |
15721 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
15722 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
15723 | return orig; | |
15724 | ||
15725 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
15726 | { | |
2cf520bf | 15727 | /* Use a different reg for the intermediate value, as |
a3c9585f | 15728 | it will be marked UNCHANGING. */ |
2cf520bf GK |
15729 | rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode); |
15730 | ||
a4f6c312 SS |
15731 | base = |
15732 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), | |
2cf520bf | 15733 | Pmode, reg_temp); |
a4f6c312 SS |
15734 | offset = |
15735 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), | |
15736 | Pmode, reg); | |
ee890fe2 SS |
15737 | } |
15738 | else | |
15739 | abort (); | |
15740 | ||
15741 | if (GET_CODE (offset) == CONST_INT) | |
15742 | { | |
15743 | if (SMALL_INT (offset)) | |
ed8908e7 | 15744 | return plus_constant (base, INTVAL (offset)); |
ee890fe2 SS |
15745 | else if (! reload_in_progress && ! reload_completed) |
15746 | offset = force_reg (Pmode, offset); | |
15747 | else | |
c859cda6 DJ |
15748 | { |
15749 | rtx mem = force_const_mem (Pmode, orig); | |
15750 | return machopic_legitimize_pic_address (mem, Pmode, reg); | |
15751 | } | |
ee890fe2 | 15752 | } |
f1c25d3b | 15753 | return gen_rtx_PLUS (Pmode, base, offset); |
ee890fe2 SS |
15754 | } |
15755 | ||
15756 | /* Fall back on generic machopic code. */ | |
15757 | return machopic_legitimize_pic_address (orig, mode, reg); | |
15758 | } | |
15759 | ||
15760 | /* This is just a placeholder to make linking work without having to | |
15761 | add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is | |
15762 | ever needed for Darwin (not too likely!) this would have to get a | |
15763 | real definition. */ | |
15764 | ||
15765 | void | |
863d938c | 15766 | toc_section (void) |
ee890fe2 SS |
15767 | { |
15768 | } | |
15769 | ||
15770 | #endif /* TARGET_MACHO */ | |
7c262518 RH |
15771 | |
15772 | #if TARGET_ELF | |
15773 | static unsigned int | |
a2369ed3 | 15774 | rs6000_elf_section_type_flags (tree decl, const char *name, int reloc) |
7c262518 | 15775 | { |
1ff8f81a AM |
15776 | return default_section_type_flags_1 (decl, name, reloc, |
15777 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7c262518 | 15778 | } |
d9f6800d RH |
15779 | |
15780 | /* Record an element in the table of global constructors. SYMBOL is | |
15781 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
15782 | between 0 and MAX_INIT_PRIORITY. | |
15783 | ||
15784 | This differs from default_named_section_asm_out_constructor in | |
15785 | that we have special handling for -mrelocatable. */ | |
15786 | ||
15787 | static void | |
a2369ed3 | 15788 | rs6000_elf_asm_out_constructor (rtx symbol, int priority) |
d9f6800d RH |
15789 | { |
15790 | const char *section = ".ctors"; | |
15791 | char buf[16]; | |
15792 | ||
15793 | if (priority != DEFAULT_INIT_PRIORITY) | |
15794 | { | |
15795 | sprintf (buf, ".ctors.%.5u", | |
15796 | /* Invert the numbering so the linker puts us in the proper | |
15797 | order; constructors are run from right to left, and the | |
15798 | linker sorts in increasing order. */ | |
15799 | MAX_INIT_PRIORITY - priority); | |
15800 | section = buf; | |
15801 | } | |
15802 | ||
715bdd29 RH |
15803 | named_section_flags (section, SECTION_WRITE); |
15804 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
15805 | |
15806 | if (TARGET_RELOCATABLE) | |
15807 | { | |
15808 | fputs ("\t.long (", asm_out_file); | |
15809 | output_addr_const (asm_out_file, symbol); | |
15810 | fputs (")@fixup\n", asm_out_file); | |
15811 | } | |
15812 | else | |
c8af3574 | 15813 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d RH |
15814 | } |
15815 | ||
15816 | static void | |
a2369ed3 | 15817 | rs6000_elf_asm_out_destructor (rtx symbol, int priority) |
d9f6800d RH |
15818 | { |
15819 | const char *section = ".dtors"; | |
15820 | char buf[16]; | |
15821 | ||
15822 | if (priority != DEFAULT_INIT_PRIORITY) | |
15823 | { | |
15824 | sprintf (buf, ".dtors.%.5u", | |
15825 | /* Invert the numbering so the linker puts us in the proper | |
15826 | order; constructors are run from right to left, and the | |
15827 | linker sorts in increasing order. */ | |
15828 | MAX_INIT_PRIORITY - priority); | |
15829 | section = buf; | |
15830 | } | |
15831 | ||
715bdd29 RH |
15832 | named_section_flags (section, SECTION_WRITE); |
15833 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
15834 | |
15835 | if (TARGET_RELOCATABLE) | |
15836 | { | |
15837 | fputs ("\t.long (", asm_out_file); | |
15838 | output_addr_const (asm_out_file, symbol); | |
15839 | fputs (")@fixup\n", asm_out_file); | |
15840 | } | |
15841 | else | |
c8af3574 | 15842 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d | 15843 | } |
9739c90c JJ |
15844 | |
15845 | void | |
a2369ed3 | 15846 | rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl) |
9739c90c JJ |
15847 | { |
15848 | if (TARGET_64BIT) | |
15849 | { | |
15850 | fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file); | |
15851 | ASM_OUTPUT_LABEL (file, name); | |
15852 | fputs (DOUBLE_INT_ASM_OP, file); | |
15853 | putc ('.', file); | |
15854 | assemble_name (file, name); | |
15855 | fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file); | |
15856 | assemble_name (file, name); | |
15857 | fputs (",24\n\t.type\t.", file); | |
15858 | assemble_name (file, name); | |
15859 | fputs (",@function\n", file); | |
15860 | if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl)) | |
15861 | { | |
15862 | fputs ("\t.globl\t.", file); | |
15863 | assemble_name (file, name); | |
15864 | putc ('\n', file); | |
15865 | } | |
15866 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
15867 | putc ('.', file); | |
15868 | ASM_OUTPUT_LABEL (file, name); | |
15869 | return; | |
15870 | } | |
15871 | ||
15872 | if (TARGET_RELOCATABLE | |
15873 | && (get_pool_size () != 0 || current_function_profile) | |
3c9eb5f4 | 15874 | && uses_TOC ()) |
9739c90c JJ |
15875 | { |
15876 | char buf[256]; | |
15877 | ||
15878 | (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno); | |
15879 | ||
15880 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
15881 | fprintf (file, "\t.long "); | |
15882 | assemble_name (file, buf); | |
15883 | putc ('-', file); | |
15884 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
15885 | assemble_name (file, buf); | |
15886 | putc ('\n', file); | |
15887 | } | |
15888 | ||
15889 | ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); | |
15890 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
15891 | ||
15892 | if (DEFAULT_ABI == ABI_AIX) | |
15893 | { | |
15894 | const char *desc_name, *orig_name; | |
15895 | ||
15896 | orig_name = (*targetm.strip_name_encoding) (name); | |
15897 | desc_name = orig_name; | |
15898 | while (*desc_name == '.') | |
15899 | desc_name++; | |
15900 | ||
15901 | if (TREE_PUBLIC (decl)) | |
15902 | fprintf (file, "\t.globl %s\n", desc_name); | |
15903 | ||
15904 | fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); | |
15905 | fprintf (file, "%s:\n", desc_name); | |
15906 | fprintf (file, "\t.long %s\n", orig_name); | |
15907 | fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file); | |
15908 | if (DEFAULT_ABI == ABI_AIX) | |
15909 | fputs ("\t.long 0\n", file); | |
15910 | fprintf (file, "\t.previous\n"); | |
15911 | } | |
15912 | ASM_OUTPUT_LABEL (file, name); | |
15913 | } | |
7c262518 RH |
15914 | #endif |
15915 | ||
cbaaba19 | 15916 | #if TARGET_XCOFF |
7c262518 | 15917 | static void |
a2369ed3 | 15918 | rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name) |
b275d088 DE |
15919 | { |
15920 | fputs (GLOBAL_ASM_OP, stream); | |
15921 | RS6000_OUTPUT_BASENAME (stream, name); | |
15922 | putc ('\n', stream); | |
15923 | } | |
15924 | ||
15925 | static void | |
a2369ed3 | 15926 | rs6000_xcoff_asm_named_section (const char *name, unsigned int flags) |
7c262518 | 15927 | { |
0e5dbd9b DE |
15928 | int smclass; |
15929 | static const char * const suffix[3] = { "PR", "RO", "RW" }; | |
15930 | ||
15931 | if (flags & SECTION_CODE) | |
15932 | smclass = 0; | |
15933 | else if (flags & SECTION_WRITE) | |
15934 | smclass = 2; | |
15935 | else | |
15936 | smclass = 1; | |
15937 | ||
5b5198f7 | 15938 | fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n", |
0e5dbd9b | 15939 | (flags & SECTION_CODE) ? "." : "", |
5b5198f7 | 15940 | name, suffix[smclass], flags & SECTION_ENTSIZE); |
7c262518 | 15941 | } |
ae46c4e0 RH |
15942 | |
15943 | static void | |
a2369ed3 DJ |
15944 | rs6000_xcoff_select_section (tree decl, int reloc, |
15945 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
ae46c4e0 | 15946 | { |
5add3202 | 15947 | if (decl_readonly_section_1 (decl, reloc, 1)) |
ae46c4e0 | 15948 | { |
0e5dbd9b | 15949 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
15950 | read_only_data_section (); |
15951 | else | |
15952 | read_only_private_data_section (); | |
15953 | } | |
15954 | else | |
15955 | { | |
0e5dbd9b | 15956 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
15957 | data_section (); |
15958 | else | |
15959 | private_data_section (); | |
15960 | } | |
15961 | } | |
15962 | ||
15963 | static void | |
a2369ed3 | 15964 | rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED) |
ae46c4e0 RH |
15965 | { |
15966 | const char *name; | |
ae46c4e0 | 15967 | |
5b5198f7 DE |
15968 | /* Use select_section for private and uninitialized data. */ |
15969 | if (!TREE_PUBLIC (decl) | |
15970 | || DECL_COMMON (decl) | |
0e5dbd9b DE |
15971 | || DECL_INITIAL (decl) == NULL_TREE |
15972 | || DECL_INITIAL (decl) == error_mark_node | |
15973 | || (flag_zero_initialized_in_bss | |
15974 | && initializer_zerop (DECL_INITIAL (decl)))) | |
15975 | return; | |
15976 | ||
15977 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
15978 | name = (*targetm.strip_name_encoding) (name); | |
15979 | DECL_SECTION_NAME (decl) = build_string (strlen (name), name); | |
ae46c4e0 | 15980 | } |
b64a1b53 | 15981 | |
fb49053f RH |
15982 | /* Select section for constant in constant pool. |
15983 | ||
15984 | On RS/6000, all constants are in the private read-only data area. | |
15985 | However, if this is being placed in the TOC it must be output as a | |
15986 | toc entry. */ | |
15987 | ||
b64a1b53 | 15988 | static void |
a2369ed3 DJ |
15989 | rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x, |
15990 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
b64a1b53 RH |
15991 | { |
15992 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) | |
15993 | toc_section (); | |
15994 | else | |
15995 | read_only_private_data_section (); | |
15996 | } | |
772c5265 RH |
15997 | |
15998 | /* Remove any trailing [DS] or the like from the symbol name. */ | |
15999 | ||
16000 | static const char * | |
a2369ed3 | 16001 | rs6000_xcoff_strip_name_encoding (const char *name) |
772c5265 RH |
16002 | { |
16003 | size_t len; | |
16004 | if (*name == '*') | |
16005 | name++; | |
16006 | len = strlen (name); | |
16007 | if (name[len - 1] == ']') | |
16008 | return ggc_alloc_string (name, len - 4); | |
16009 | else | |
16010 | return name; | |
16011 | } | |
16012 | ||
5add3202 DE |
16013 | /* Section attributes. AIX is always PIC. */ |
16014 | ||
16015 | static unsigned int | |
a2369ed3 | 16016 | rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc) |
5add3202 | 16017 | { |
5b5198f7 DE |
16018 | unsigned int align; |
16019 | unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1); | |
16020 | ||
16021 | /* Align to at least UNIT size. */ | |
16022 | if (flags & SECTION_CODE) | |
16023 | align = MIN_UNITS_PER_WORD; | |
16024 | else | |
16025 | /* Increase alignment of large objects if not already stricter. */ | |
16026 | align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT), | |
16027 | int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD | |
16028 | ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD); | |
16029 | ||
16030 | return flags | (exact_log2 (align) & SECTION_ENTSIZE); | |
5add3202 | 16031 | } |
a5fe455b | 16032 | |
1bc7c5b6 ZW |
16033 | /* Output at beginning of assembler file. |
16034 | ||
16035 | Initialize the section names for the RS/6000 at this point. | |
16036 | ||
16037 | Specify filename, including full path, to assembler. | |
16038 | ||
16039 | We want to go into the TOC section so at least one .toc will be emitted. | |
16040 | Also, in order to output proper .bs/.es pairs, we need at least one static | |
16041 | [RW] section emitted. | |
16042 | ||
16043 | Finally, declare mcount when profiling to make the assembler happy. */ | |
16044 | ||
16045 | static void | |
863d938c | 16046 | rs6000_xcoff_file_start (void) |
1bc7c5b6 ZW |
16047 | { |
16048 | rs6000_gen_section_name (&xcoff_bss_section_name, | |
16049 | main_input_filename, ".bss_"); | |
16050 | rs6000_gen_section_name (&xcoff_private_data_section_name, | |
16051 | main_input_filename, ".rw_"); | |
16052 | rs6000_gen_section_name (&xcoff_read_only_section_name, | |
16053 | main_input_filename, ".ro_"); | |
16054 | ||
16055 | fputs ("\t.file\t", asm_out_file); | |
16056 | output_quoted_string (asm_out_file, main_input_filename); | |
16057 | fputc ('\n', asm_out_file); | |
16058 | toc_section (); | |
16059 | if (write_symbols != NO_DEBUG) | |
16060 | private_data_section (); | |
16061 | text_section (); | |
16062 | if (profile_flag) | |
16063 | fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT); | |
16064 | rs6000_file_start (); | |
16065 | } | |
16066 | ||
a5fe455b ZW |
16067 | /* Output at end of assembler file. |
16068 | On the RS/6000, referencing data should automatically pull in text. */ | |
16069 | ||
16070 | static void | |
863d938c | 16071 | rs6000_xcoff_file_end (void) |
a5fe455b ZW |
16072 | { |
16073 | text_section (); | |
16074 | fputs ("_section_.text:\n", asm_out_file); | |
16075 | data_section (); | |
16076 | fputs (TARGET_32BIT | |
16077 | ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", | |
16078 | asm_out_file); | |
16079 | } | |
f1384257 | 16080 | #endif /* TARGET_XCOFF */ |
0e5dbd9b | 16081 | |
f1384257 AM |
16082 | #if TARGET_MACHO |
16083 | /* Cross-module name binding. Darwin does not support overriding | |
7f3d8013 | 16084 | functions at dynamic-link time. */ |
0e5dbd9b | 16085 | |
2bcc50d0 | 16086 | static bool |
a2369ed3 | 16087 | rs6000_binds_local_p (tree decl) |
0e5dbd9b | 16088 | { |
f1384257 | 16089 | return default_binds_local_p_1 (decl, 0); |
0e5dbd9b | 16090 | } |
f1384257 | 16091 | #endif |
34bb030a | 16092 | |
3c50106f RH |
16093 | /* Compute a (partial) cost for rtx X. Return true if the complete |
16094 | cost has been computed, and false if subexpressions should be | |
16095 | scanned. In either case, *TOTAL contains the cost result. */ | |
16096 | ||
16097 | static bool | |
a2369ed3 DJ |
16098 | rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED, |
16099 | int *total) | |
3c50106f RH |
16100 | { |
16101 | switch (code) | |
16102 | { | |
16103 | /* On the RS/6000, if it is valid in the insn, it is free. | |
16104 | So this always returns 0. */ | |
16105 | case CONST_INT: | |
16106 | case CONST: | |
16107 | case LABEL_REF: | |
16108 | case SYMBOL_REF: | |
16109 | case CONST_DOUBLE: | |
16110 | case HIGH: | |
16111 | *total = 0; | |
16112 | return true; | |
16113 | ||
16114 | case PLUS: | |
16115 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
16116 | && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) | |
16117 | + 0x8000) >= 0x10000) | |
16118 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
16119 | ? COSTS_N_INSNS (2) | |
16120 | : COSTS_N_INSNS (1)); | |
16121 | return true; | |
16122 | ||
52190329 RS |
16123 | case MINUS: |
16124 | *total = COSTS_N_INSNS (1); | |
16125 | return true; | |
16126 | ||
3c50106f RH |
16127 | case AND: |
16128 | case IOR: | |
16129 | case XOR: | |
16130 | *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT | |
16131 | && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0 | |
16132 | && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0)) | |
16133 | ? COSTS_N_INSNS (2) | |
16134 | : COSTS_N_INSNS (1)); | |
16135 | return true; | |
16136 | ||
16137 | case MULT: | |
16138 | if (optimize_size) | |
16139 | { | |
16140 | *total = COSTS_N_INSNS (2); | |
16141 | return true; | |
16142 | } | |
16143 | switch (rs6000_cpu) | |
16144 | { | |
16145 | case PROCESSOR_RIOS1: | |
16146 | case PROCESSOR_PPC405: | |
16147 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16148 | ? COSTS_N_INSNS (5) | |
16149 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16150 | && INTVAL (XEXP (x, 1)) <= 255) | |
16151 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
16152 | return true; | |
16153 | ||
02ca7595 DE |
16154 | case PROCESSOR_PPC440: |
16155 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16156 | ? COSTS_N_INSNS (3) | |
16157 | : COSTS_N_INSNS (2)); | |
16158 | return true; | |
16159 | ||
3c50106f RH |
16160 | case PROCESSOR_RS64A: |
16161 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16162 | ? GET_MODE (XEXP (x, 1)) != DImode | |
16163 | ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34) | |
16164 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16165 | && INTVAL (XEXP (x, 1)) <= 255) | |
16166 | ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12)); | |
16167 | return true; | |
16168 | ||
16169 | case PROCESSOR_RIOS2: | |
16170 | case PROCESSOR_MPCCORE: | |
16171 | case PROCESSOR_PPC604e: | |
16172 | *total = COSTS_N_INSNS (2); | |
16173 | return true; | |
16174 | ||
16175 | case PROCESSOR_PPC601: | |
16176 | *total = COSTS_N_INSNS (5); | |
16177 | return true; | |
16178 | ||
16179 | case PROCESSOR_PPC603: | |
16180 | case PROCESSOR_PPC7400: | |
16181 | case PROCESSOR_PPC750: | |
16182 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16183 | ? COSTS_N_INSNS (5) | |
16184 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16185 | && INTVAL (XEXP (x, 1)) <= 255) | |
16186 | ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3)); | |
16187 | return true; | |
16188 | ||
16189 | case PROCESSOR_PPC7450: | |
16190 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT | |
16191 | ? COSTS_N_INSNS (4) | |
16192 | : COSTS_N_INSNS (3)); | |
16193 | return true; | |
16194 | ||
16195 | case PROCESSOR_PPC403: | |
16196 | case PROCESSOR_PPC604: | |
16197 | case PROCESSOR_PPC8540: | |
16198 | *total = COSTS_N_INSNS (4); | |
16199 | return true; | |
16200 | ||
16201 | case PROCESSOR_PPC620: | |
16202 | case PROCESSOR_PPC630: | |
3c50106f RH |
16203 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT |
16204 | ? GET_MODE (XEXP (x, 1)) != DImode | |
16205 | ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7) | |
16206 | : (INTVAL (XEXP (x, 1)) >= -256 | |
16207 | && INTVAL (XEXP (x, 1)) <= 255) | |
16208 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)); | |
16209 | return true; | |
16210 | ||
9259f3b0 | 16211 | case PROCESSOR_POWER4: |
ec507f2d | 16212 | case PROCESSOR_POWER5: |
9259f3b0 DE |
16213 | *total = (GET_CODE (XEXP (x, 1)) != CONST_INT |
16214 | ? GET_MODE (XEXP (x, 1)) != DImode | |
984e25ac DE |
16215 | ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4) |
16216 | : COSTS_N_INSNS (2)); | |
9259f3b0 DE |
16217 | return true; |
16218 | ||
3c50106f RH |
16219 | default: |
16220 | abort (); | |
16221 | } | |
16222 | ||
16223 | case DIV: | |
16224 | case MOD: | |
16225 | if (GET_CODE (XEXP (x, 1)) == CONST_INT | |
16226 | && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) | |
16227 | { | |
16228 | *total = COSTS_N_INSNS (2); | |
16229 | return true; | |
16230 | } | |
5efb1046 | 16231 | /* FALLTHRU */ |
3c50106f RH |
16232 | |
16233 | case UDIV: | |
16234 | case UMOD: | |
16235 | switch (rs6000_cpu) | |
16236 | { | |
16237 | case PROCESSOR_RIOS1: | |
16238 | *total = COSTS_N_INSNS (19); | |
16239 | return true; | |
16240 | ||
16241 | case PROCESSOR_RIOS2: | |
16242 | *total = COSTS_N_INSNS (13); | |
16243 | return true; | |
16244 | ||
16245 | case PROCESSOR_RS64A: | |
16246 | *total = (GET_MODE (XEXP (x, 1)) != DImode | |
16247 | ? COSTS_N_INSNS (65) | |
16248 | : COSTS_N_INSNS (67)); | |
16249 | return true; | |
16250 | ||
16251 | case PROCESSOR_MPCCORE: | |
16252 | *total = COSTS_N_INSNS (6); | |
16253 | return true; | |
16254 | ||
16255 | case PROCESSOR_PPC403: | |
16256 | *total = COSTS_N_INSNS (33); | |
16257 | return true; | |
16258 | ||
16259 | case PROCESSOR_PPC405: | |
16260 | *total = COSTS_N_INSNS (35); | |
16261 | return true; | |
16262 | ||
02ca7595 DE |
16263 | case PROCESSOR_PPC440: |
16264 | *total = COSTS_N_INSNS (34); | |
16265 | return true; | |
16266 | ||
3c50106f RH |
16267 | case PROCESSOR_PPC601: |
16268 | *total = COSTS_N_INSNS (36); | |
16269 | return true; | |
16270 | ||
16271 | case PROCESSOR_PPC603: | |
16272 | *total = COSTS_N_INSNS (37); | |
16273 | return true; | |
16274 | ||
16275 | case PROCESSOR_PPC604: | |
16276 | case PROCESSOR_PPC604e: | |
16277 | *total = COSTS_N_INSNS (20); | |
16278 | return true; | |
16279 | ||
16280 | case PROCESSOR_PPC620: | |
16281 | case PROCESSOR_PPC630: | |
3c50106f RH |
16282 | *total = (GET_MODE (XEXP (x, 1)) != DImode |
16283 | ? COSTS_N_INSNS (21) | |
16284 | : COSTS_N_INSNS (37)); | |
16285 | return true; | |
16286 | ||
16287 | case PROCESSOR_PPC750: | |
16288 | case PROCESSOR_PPC8540: | |
16289 | case PROCESSOR_PPC7400: | |
16290 | *total = COSTS_N_INSNS (19); | |
16291 | return true; | |
16292 | ||
16293 | case PROCESSOR_PPC7450: | |
16294 | *total = COSTS_N_INSNS (23); | |
16295 | return true; | |
984e25ac DE |
16296 | |
16297 | case PROCESSOR_POWER4: | |
ec507f2d | 16298 | case PROCESSOR_POWER5: |
984e25ac DE |
16299 | *total = (GET_MODE (XEXP (x, 1)) != DImode |
16300 | ? COSTS_N_INSNS (18) | |
16301 | : COSTS_N_INSNS (34)); | |
16302 | return true; | |
3c50106f RH |
16303 | |
16304 | default: | |
16305 | abort (); | |
16306 | } | |
16307 | ||
16308 | case FFS: | |
16309 | *total = COSTS_N_INSNS (4); | |
16310 | return true; | |
16311 | ||
16312 | case MEM: | |
a3c9585f | 16313 | /* MEM should be slightly more expensive than (plus (reg) (const)). */ |
3c50106f RH |
16314 | *total = 5; |
16315 | return true; | |
16316 | ||
16317 | default: | |
16318 | return false; | |
16319 | } | |
16320 | } | |
16321 | ||
34bb030a DE |
16322 | /* A C expression returning the cost of moving data from a register of class |
16323 | CLASS1 to one of CLASS2. */ | |
16324 | ||
16325 | int | |
a2369ed3 DJ |
16326 | rs6000_register_move_cost (enum machine_mode mode, |
16327 | enum reg_class from, enum reg_class to) | |
34bb030a DE |
16328 | { |
16329 | /* Moves from/to GENERAL_REGS. */ | |
16330 | if (reg_classes_intersect_p (to, GENERAL_REGS) | |
16331 | || reg_classes_intersect_p (from, GENERAL_REGS)) | |
16332 | { | |
16333 | if (! reg_classes_intersect_p (to, GENERAL_REGS)) | |
16334 | from = to; | |
16335 | ||
16336 | if (from == FLOAT_REGS || from == ALTIVEC_REGS) | |
16337 | return (rs6000_memory_move_cost (mode, from, 0) | |
16338 | + rs6000_memory_move_cost (mode, GENERAL_REGS, 0)); | |
16339 | ||
a3c9585f | 16340 | /* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */ |
34bb030a DE |
16341 | else if (from == CR_REGS) |
16342 | return 4; | |
16343 | ||
16344 | else | |
16345 | /* A move will cost one instruction per GPR moved. */ | |
16346 | return 2 * HARD_REGNO_NREGS (0, mode); | |
16347 | } | |
16348 | ||
16349 | /* Moving between two similar registers is just one instruction. */ | |
16350 | else if (reg_classes_intersect_p (to, from)) | |
16351 | return mode == TFmode ? 4 : 2; | |
16352 | ||
16353 | /* Everything else has to go through GENERAL_REGS. */ | |
16354 | else | |
16355 | return (rs6000_register_move_cost (mode, GENERAL_REGS, to) | |
16356 | + rs6000_register_move_cost (mode, from, GENERAL_REGS)); | |
16357 | } | |
16358 | ||
16359 | /* A C expressions returning the cost of moving data of MODE from a register to | |
16360 | or from memory. */ | |
16361 | ||
16362 | int | |
a2369ed3 DJ |
16363 | rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class, |
16364 | int in ATTRIBUTE_UNUSED) | |
34bb030a DE |
16365 | { |
16366 | if (reg_classes_intersect_p (class, GENERAL_REGS)) | |
16367 | return 4 * HARD_REGNO_NREGS (0, mode); | |
16368 | else if (reg_classes_intersect_p (class, FLOAT_REGS)) | |
16369 | return 4 * HARD_REGNO_NREGS (32, mode); | |
16370 | else if (reg_classes_intersect_p (class, ALTIVEC_REGS)) | |
16371 | return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode); | |
16372 | else | |
16373 | return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS); | |
16374 | } | |
16375 | ||
ded9bf77 AH |
16376 | /* Return an RTX representing where to find the function value of a |
16377 | function returning MODE. */ | |
16378 | static rtx | |
16379 | rs6000_complex_function_value (enum machine_mode mode) | |
16380 | { | |
16381 | unsigned int regno; | |
16382 | rtx r1, r2; | |
16383 | enum machine_mode inner = GET_MODE_INNER (mode); | |
fb7e4164 | 16384 | unsigned int inner_bytes = GET_MODE_SIZE (inner); |
ded9bf77 | 16385 | |
4ed78545 | 16386 | if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS) |
ded9bf77 AH |
16387 | regno = FP_ARG_RETURN; |
16388 | else | |
16389 | { | |
16390 | regno = GP_ARG_RETURN; | |
16391 | ||
16392 | /* 32-bit is OK since it'll go in r3/r4. */ | |
fb7e4164 | 16393 | if (TARGET_32BIT && inner_bytes >= 4) |
ded9bf77 AH |
16394 | return gen_rtx_REG (mode, regno); |
16395 | } | |
16396 | ||
fb7e4164 AM |
16397 | if (inner_bytes >= 8) |
16398 | return gen_rtx_REG (mode, regno); | |
16399 | ||
ded9bf77 AH |
16400 | r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno), |
16401 | const0_rtx); | |
16402 | r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1), | |
fb7e4164 | 16403 | GEN_INT (inner_bytes)); |
ded9bf77 AH |
16404 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); |
16405 | } | |
16406 | ||
a6ebc39a AH |
16407 | /* Define how to find the value returned by a function. |
16408 | VALTYPE is the data type of the value (as a tree). | |
16409 | If the precise function being called is known, FUNC is its FUNCTION_DECL; | |
16410 | otherwise, FUNC is 0. | |
16411 | ||
16412 | On the SPE, both FPs and vectors are returned in r3. | |
16413 | ||
16414 | On RS/6000 an integer value is in r3 and a floating-point value is in | |
16415 | fp1, unless -msoft-float. */ | |
16416 | ||
16417 | rtx | |
16418 | rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED) | |
16419 | { | |
16420 | enum machine_mode mode; | |
2a8fa26c | 16421 | unsigned int regno; |
a6ebc39a | 16422 | |
0e67400a FJ |
16423 | if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode) |
16424 | { | |
16425 | /* Long long return value need be split in -mpowerpc64, 32bit ABI. */ | |
16426 | return gen_rtx_PARALLEL (DImode, | |
16427 | gen_rtvec (2, | |
16428 | gen_rtx_EXPR_LIST (VOIDmode, | |
16429 | gen_rtx_REG (SImode, GP_ARG_RETURN), | |
16430 | const0_rtx), | |
16431 | gen_rtx_EXPR_LIST (VOIDmode, | |
16432 | gen_rtx_REG (SImode, | |
16433 | GP_ARG_RETURN + 1), | |
16434 | GEN_INT (4)))); | |
16435 | } | |
16436 | ||
a6ebc39a AH |
16437 | if ((INTEGRAL_TYPE_P (valtype) |
16438 | && TYPE_PRECISION (valtype) < BITS_PER_WORD) | |
16439 | || POINTER_TYPE_P (valtype)) | |
b78d48dd | 16440 | mode = TARGET_32BIT ? SImode : DImode; |
a6ebc39a AH |
16441 | else |
16442 | mode = TYPE_MODE (valtype); | |
16443 | ||
4ed78545 | 16444 | if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS) |
2a8fa26c | 16445 | regno = FP_ARG_RETURN; |
ded9bf77 | 16446 | else if (TREE_CODE (valtype) == COMPLEX_TYPE |
42ba5130 | 16447 | && targetm.calls.split_complex_arg) |
ded9bf77 | 16448 | return rs6000_complex_function_value (mode); |
44688022 AM |
16449 | else if (TREE_CODE (valtype) == VECTOR_TYPE |
16450 | && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI) | |
a6ebc39a AH |
16451 | regno = ALTIVEC_ARG_RETURN; |
16452 | else | |
16453 | regno = GP_ARG_RETURN; | |
16454 | ||
16455 | return gen_rtx_REG (mode, regno); | |
16456 | } | |
16457 | ||
ded9bf77 AH |
16458 | /* Define how to find the value returned by a library function |
16459 | assuming the value has mode MODE. */ | |
16460 | rtx | |
16461 | rs6000_libcall_value (enum machine_mode mode) | |
16462 | { | |
16463 | unsigned int regno; | |
16464 | ||
16465 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
16466 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
16467 | regno = FP_ARG_RETURN; | |
44688022 AM |
16468 | else if (ALTIVEC_VECTOR_MODE (mode) |
16469 | && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI) | |
ded9bf77 | 16470 | regno = ALTIVEC_ARG_RETURN; |
42ba5130 | 16471 | else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg) |
ded9bf77 AH |
16472 | return rs6000_complex_function_value (mode); |
16473 | else | |
16474 | regno = GP_ARG_RETURN; | |
16475 | ||
16476 | return gen_rtx_REG (mode, regno); | |
16477 | } | |
16478 | ||
d1d0c603 JJ |
16479 | /* Define the offset between two registers, FROM to be eliminated and its |
16480 | replacement TO, at the start of a routine. */ | |
16481 | HOST_WIDE_INT | |
16482 | rs6000_initial_elimination_offset (int from, int to) | |
16483 | { | |
16484 | rs6000_stack_t *info = rs6000_stack_info (); | |
16485 | HOST_WIDE_INT offset; | |
16486 | ||
16487 | if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
16488 | offset = info->push_p ? 0 : -info->total_size; | |
16489 | else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) | |
16490 | offset = info->total_size; | |
16491 | else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
16492 | offset = info->push_p ? info->total_size : 0; | |
16493 | else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM) | |
16494 | offset = 0; | |
16495 | else | |
16496 | abort (); | |
16497 | ||
16498 | return offset; | |
16499 | } | |
16500 | ||
62e1dfcf NC |
16501 | /* Return true if TYPE is of type __ev64_opaque__. */ |
16502 | ||
c8e4f0e9 | 16503 | static bool |
a2369ed3 | 16504 | is_ev64_opaque_type (tree type) |
62e1dfcf | 16505 | { |
c8e4f0e9 | 16506 | return (TARGET_SPE |
2abe3e28 AH |
16507 | && (type == opaque_V2SI_type_node |
16508 | || type == opaque_V2SF_type_node | |
36252949 | 16509 | || type == opaque_p_V2SI_type_node)); |
62e1dfcf NC |
16510 | } |
16511 | ||
96714395 | 16512 | static rtx |
a2369ed3 | 16513 | rs6000_dwarf_register_span (rtx reg) |
96714395 AH |
16514 | { |
16515 | unsigned regno; | |
16516 | ||
16517 | if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg))) | |
16518 | return NULL_RTX; | |
16519 | ||
16520 | regno = REGNO (reg); | |
16521 | ||
16522 | /* The duality of the SPE register size wreaks all kinds of havoc. | |
16523 | This is a way of distinguishing r0 in 32-bits from r0 in | |
16524 | 64-bits. */ | |
16525 | return | |
16526 | gen_rtx_PARALLEL (VOIDmode, | |
3bd104d1 AH |
16527 | BYTES_BIG_ENDIAN |
16528 | ? gen_rtvec (2, | |
16529 | gen_rtx_REG (SImode, regno + 1200), | |
16530 | gen_rtx_REG (SImode, regno)) | |
16531 | : gen_rtvec (2, | |
16532 | gen_rtx_REG (SImode, regno), | |
16533 | gen_rtx_REG (SImode, regno + 1200))); | |
96714395 AH |
16534 | } |
16535 | ||
93c9d1ba AM |
16536 | /* Map internal gcc register numbers to DWARF2 register numbers. */ |
16537 | ||
16538 | unsigned int | |
16539 | rs6000_dbx_register_number (unsigned int regno) | |
16540 | { | |
16541 | if (regno <= 63 || write_symbols != DWARF2_DEBUG) | |
16542 | return regno; | |
16543 | if (regno == MQ_REGNO) | |
16544 | return 100; | |
16545 | if (regno == LINK_REGISTER_REGNUM) | |
16546 | return 108; | |
16547 | if (regno == COUNT_REGISTER_REGNUM) | |
16548 | return 109; | |
16549 | if (CR_REGNO_P (regno)) | |
16550 | return regno - CR0_REGNO + 86; | |
16551 | if (regno == XER_REGNO) | |
16552 | return 101; | |
16553 | if (ALTIVEC_REGNO_P (regno)) | |
16554 | return regno - FIRST_ALTIVEC_REGNO + 1124; | |
16555 | if (regno == VRSAVE_REGNO) | |
16556 | return 356; | |
16557 | if (regno == VSCR_REGNO) | |
16558 | return 67; | |
16559 | if (regno == SPE_ACC_REGNO) | |
16560 | return 99; | |
16561 | if (regno == SPEFSCR_REGNO) | |
16562 | return 612; | |
16563 | /* SPE high reg number. We get these values of regno from | |
16564 | rs6000_dwarf_register_span. */ | |
16565 | if (regno >= 1200 && regno < 1232) | |
16566 | return regno; | |
16567 | ||
16568 | abort (); | |
16569 | } | |
16570 | ||
17211ab5 | 16571 | #include "gt-rs6000.h" |