]>
Commit | Line | Data |
---|---|---|
9878760c | 1 | /* Subroutines used for code generation on IBM RS/6000. |
f676971a | 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 */ | |
d62294f5 FJ |
82 | int world_save_p; /* true if we're saving *everything*: |
83 | r13-r31, cr, f14-f31, vrsave, v20-v31 */ | |
d1d0c603 JJ |
84 | enum rs6000_abi abi; /* which ABI to use */ |
85 | int gp_save_offset; /* offset to save GP regs from initial SP */ | |
86 | int fp_save_offset; /* offset to save FP regs from initial SP */ | |
87 | int altivec_save_offset; /* offset to save AltiVec regs from initial SP */ | |
88 | int lr_save_offset; /* offset to save LR from initial SP */ | |
89 | int cr_save_offset; /* offset to save CR from initial SP */ | |
90 | int vrsave_save_offset; /* offset to save VRSAVE from initial SP */ | |
91 | int spe_gp_save_offset; /* offset to save spe 64-bit gprs */ | |
92 | int toc_save_offset; /* offset to save the TOC pointer */ | |
93 | int varargs_save_offset; /* offset to save the varargs registers */ | |
94 | int ehrd_offset; /* offset to EH return data */ | |
95 | int reg_size; /* register size (4 or 8) */ | |
96 | int varargs_size; /* size to hold V.4 args passed in regs */ | |
97 | HOST_WIDE_INT vars_size; /* variable save area size */ | |
98 | int parm_size; /* outgoing parameter size */ | |
99 | int save_size; /* save area size */ | |
100 | int fixed_size; /* fixed size of stack frame */ | |
101 | int gp_size; /* size of saved GP registers */ | |
102 | int fp_size; /* size of saved FP registers */ | |
103 | int altivec_size; /* size of saved AltiVec registers */ | |
104 | int cr_size; /* size to hold CR if not in save_size */ | |
105 | int lr_size; /* size to hold LR if not in save_size */ | |
106 | int vrsave_size; /* size to hold VRSAVE if not in save_size */ | |
107 | int altivec_padding_size; /* size of altivec alignment padding if | |
108 | not in save_size */ | |
109 | int spe_gp_size; /* size of 64-bit GPR save size for SPE */ | |
110 | int spe_padding_size; | |
111 | int toc_size; /* size to hold TOC if not in save_size */ | |
112 | HOST_WIDE_INT total_size; /* total bytes allocated for stack */ | |
113 | int spe_64bit_regs_used; | |
114 | } rs6000_stack_t; | |
115 | ||
5248c961 RK |
116 | /* Target cpu type */ |
117 | ||
118 | enum processor_type rs6000_cpu; | |
8e3f41e7 MM |
119 | struct rs6000_cpu_select rs6000_select[3] = |
120 | { | |
815cdc52 MM |
121 | /* switch name, tune arch */ |
122 | { (const char *)0, "--with-cpu=", 1, 1 }, | |
123 | { (const char *)0, "-mcpu=", 1, 1 }, | |
124 | { (const char *)0, "-mtune=", 1, 0 }, | |
8e3f41e7 | 125 | }; |
5248c961 | 126 | |
ec507f2d DE |
127 | /* Always emit branch hint bits. */ |
128 | static GTY(()) bool rs6000_always_hint; | |
129 | ||
130 | /* Schedule instructions for group formation. */ | |
131 | static GTY(()) bool rs6000_sched_groups; | |
132 | ||
f676971a | 133 | /* Support adjust_priority scheduler hook |
79ae11c4 DN |
134 | and -mprioritize-restricted-insns= option. */ |
135 | const char *rs6000_sched_restricted_insns_priority_str; | |
136 | int rs6000_sched_restricted_insns_priority; | |
137 | ||
569fa502 DN |
138 | /* Support for -msched-costly-dep option. */ |
139 | const char *rs6000_sched_costly_dep_str; | |
140 | enum rs6000_dependence_cost rs6000_sched_costly_dep; | |
141 | ||
cbe26ab8 DN |
142 | /* Support for -minsert-sched-nops option. */ |
143 | const char *rs6000_sched_insert_nops_str; | |
144 | enum rs6000_nop_insertion rs6000_sched_insert_nops; | |
145 | ||
7ccf35ed DN |
146 | /* Support targetm.vectorize.builtin_mask_for_load. */ |
147 | tree altivec_builtin_mask_for_load; | |
148 | /* Support targetm.vectorize.builtin_mask_for_store. */ | |
149 | tree altivec_builtin_mask_for_store; | |
150 | ||
6fa3f289 ZW |
151 | /* Size of long double */ |
152 | const char *rs6000_long_double_size_string; | |
153 | int rs6000_long_double_type_size; | |
154 | ||
155 | /* Whether -mabi=altivec has appeared */ | |
156 | int rs6000_altivec_abi; | |
157 | ||
08b57fb3 AH |
158 | /* Whether VRSAVE instructions should be generated. */ |
159 | int rs6000_altivec_vrsave; | |
160 | ||
161 | /* String from -mvrsave= option. */ | |
162 | const char *rs6000_altivec_vrsave_string; | |
163 | ||
a3170dc6 AH |
164 | /* Nonzero if we want SPE ABI extensions. */ |
165 | int rs6000_spe_abi; | |
166 | ||
167 | /* Whether isel instructions should be generated. */ | |
168 | int rs6000_isel; | |
169 | ||
993f19a8 AH |
170 | /* Whether SPE simd instructions should be generated. */ |
171 | int rs6000_spe; | |
172 | ||
5da702b1 AH |
173 | /* Nonzero if floating point operations are done in the GPRs. */ |
174 | int rs6000_float_gprs = 0; | |
175 | ||
176 | /* String from -mfloat-gprs=. */ | |
177 | const char *rs6000_float_gprs_string; | |
a3170dc6 AH |
178 | |
179 | /* String from -misel=. */ | |
180 | const char *rs6000_isel_string; | |
181 | ||
993f19a8 AH |
182 | /* String from -mspe=. */ |
183 | const char *rs6000_spe_string; | |
184 | ||
a0ab749a | 185 | /* Set to nonzero once AIX common-mode calls have been defined. */ |
bbfb86aa | 186 | static GTY(()) int common_mode_defined; |
c81bebd7 | 187 | |
9878760c RK |
188 | /* Save information from a "cmpxx" operation until the branch or scc is |
189 | emitted. */ | |
9878760c RK |
190 | rtx rs6000_compare_op0, rs6000_compare_op1; |
191 | int rs6000_compare_fp_p; | |
874a0744 | 192 | |
874a0744 MM |
193 | /* Label number of label created for -mrelocatable, to call to so we can |
194 | get the address of the GOT section */ | |
195 | int rs6000_pic_labelno; | |
c81bebd7 | 196 | |
b91da81f | 197 | #ifdef USING_ELFOS_H |
c81bebd7 | 198 | /* Which abi to adhere to */ |
9739c90c | 199 | const char *rs6000_abi_name; |
d9407988 MM |
200 | |
201 | /* Semantics of the small data area */ | |
202 | enum rs6000_sdata_type rs6000_sdata = SDATA_DATA; | |
203 | ||
204 | /* Which small data model to use */ | |
815cdc52 | 205 | const char *rs6000_sdata_name = (char *)0; |
9ebbca7d GK |
206 | |
207 | /* Counter for labels which are to be placed in .fixup. */ | |
208 | int fixuplabelno = 0; | |
874a0744 | 209 | #endif |
4697a36c | 210 | |
c4501e62 JJ |
211 | /* Bit size of immediate TLS offsets and string from which it is decoded. */ |
212 | int rs6000_tls_size = 32; | |
213 | const char *rs6000_tls_size_string; | |
214 | ||
b6c9286a MM |
215 | /* ABI enumeration available for subtarget to use. */ |
216 | enum rs6000_abi rs6000_current_abi; | |
217 | ||
0ac081f6 AH |
218 | /* ABI string from -mabi= option. */ |
219 | const char *rs6000_abi_string; | |
220 | ||
85b776df AM |
221 | /* Whether to use variant of AIX ABI for PowerPC64 Linux. */ |
222 | int dot_symbols; | |
223 | ||
38c1f2d7 | 224 | /* Debug flags */ |
815cdc52 | 225 | const char *rs6000_debug_name; |
38c1f2d7 MM |
226 | int rs6000_debug_stack; /* debug stack applications */ |
227 | int rs6000_debug_arg; /* debug argument handling */ | |
228 | ||
0d1fbc8c AH |
229 | /* Value is TRUE if register/mode pair is accepatable. */ |
230 | bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER]; | |
231 | ||
6035d635 | 232 | /* Opaque types. */ |
2abe3e28 | 233 | static GTY(()) tree opaque_V2SI_type_node; |
2abe3e28 | 234 | static GTY(()) tree opaque_V2SF_type_node; |
6035d635 | 235 | static GTY(()) tree opaque_p_V2SI_type_node; |
4a5eab38 PB |
236 | static GTY(()) tree V16QI_type_node; |
237 | static GTY(()) tree V2SI_type_node; | |
238 | static GTY(()) tree V2SF_type_node; | |
239 | static GTY(()) tree V4HI_type_node; | |
240 | static GTY(()) tree V4SI_type_node; | |
241 | static GTY(()) tree V4SF_type_node; | |
242 | static GTY(()) tree V8HI_type_node; | |
243 | static GTY(()) tree unsigned_V16QI_type_node; | |
244 | static GTY(()) tree unsigned_V8HI_type_node; | |
245 | static GTY(()) tree unsigned_V4SI_type_node; | |
8bb418a3 ZL |
246 | static GTY(()) tree bool_char_type_node; /* __bool char */ |
247 | static GTY(()) tree bool_short_type_node; /* __bool short */ | |
248 | static GTY(()) tree bool_int_type_node; /* __bool int */ | |
249 | static GTY(()) tree pixel_type_node; /* __pixel */ | |
250 | static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */ | |
251 | static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */ | |
252 | static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */ | |
253 | static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */ | |
254 | ||
255 | int rs6000_warn_altivec_long = 1; /* On by default. */ | |
256 | const char *rs6000_warn_altivec_long_switch; | |
257 | ||
57ac7be9 AM |
258 | const char *rs6000_traceback_name; |
259 | static enum { | |
260 | traceback_default = 0, | |
261 | traceback_none, | |
262 | traceback_part, | |
263 | traceback_full | |
264 | } rs6000_traceback; | |
265 | ||
38c1f2d7 MM |
266 | /* Flag to say the TOC is initialized */ |
267 | int toc_initialized; | |
9ebbca7d | 268 | char toc_label_name[10]; |
38c1f2d7 | 269 | |
9ebbca7d | 270 | /* Alias set for saves and restores from the rs6000 stack. */ |
f103e34d | 271 | static GTY(()) int rs6000_sr_alias_set; |
c8023011 | 272 | |
a5c76ee6 ZW |
273 | /* Call distance, overridden by -mlongcall and #pragma longcall(1). |
274 | The only place that looks at this is rs6000_set_default_type_attributes; | |
275 | everywhere else should rely on the presence or absence of a longcall | |
276 | attribute on the function declaration. */ | |
277 | int rs6000_default_long_calls; | |
278 | const char *rs6000_longcall_switch; | |
279 | ||
a3c9585f KH |
280 | /* Control alignment for fields within structures. */ |
281 | /* String from -malign-XXXXX. */ | |
025d9908 KH |
282 | const char *rs6000_alignment_string; |
283 | int rs6000_alignment_flags; | |
284 | ||
a3170dc6 AH |
285 | struct builtin_description |
286 | { | |
287 | /* mask is not const because we're going to alter it below. This | |
288 | nonsense will go away when we rewrite the -march infrastructure | |
289 | to give us more target flag bits. */ | |
290 | unsigned int mask; | |
291 | const enum insn_code icode; | |
292 | const char *const name; | |
293 | const enum rs6000_builtins code; | |
294 | }; | |
8b897cfa RS |
295 | \f |
296 | /* Target cpu costs. */ | |
297 | ||
298 | struct processor_costs { | |
299 | const int mulsi; /* cost of SImode multiplication. */ | |
300 | const int mulsi_const; /* cost of SImode multiplication by constant. */ | |
301 | const int mulsi_const9; /* cost of SImode mult by short constant. */ | |
302 | const int muldi; /* cost of DImode multiplication. */ | |
303 | const int divsi; /* cost of SImode division. */ | |
304 | const int divdi; /* cost of DImode division. */ | |
f0517163 RS |
305 | const int fp; /* cost of simple SFmode and DFmode insns. */ |
306 | const int dmul; /* cost of DFmode multiplication (and fmadd). */ | |
307 | const int sdiv; /* cost of SFmode division (fdivs). */ | |
308 | const int ddiv; /* cost of DFmode division (fdiv). */ | |
8b897cfa RS |
309 | }; |
310 | ||
311 | const struct processor_costs *rs6000_cost; | |
312 | ||
313 | /* Processor costs (relative to an add) */ | |
314 | ||
315 | /* Instruction size costs on 32bit processors. */ | |
316 | static const | |
317 | struct processor_costs size32_cost = { | |
06a67bdd RS |
318 | COSTS_N_INSNS (1), /* mulsi */ |
319 | COSTS_N_INSNS (1), /* mulsi_const */ | |
320 | COSTS_N_INSNS (1), /* mulsi_const9 */ | |
321 | COSTS_N_INSNS (1), /* muldi */ | |
322 | COSTS_N_INSNS (1), /* divsi */ | |
323 | COSTS_N_INSNS (1), /* divdi */ | |
324 | COSTS_N_INSNS (1), /* fp */ | |
325 | COSTS_N_INSNS (1), /* dmul */ | |
326 | COSTS_N_INSNS (1), /* sdiv */ | |
327 | COSTS_N_INSNS (1), /* ddiv */ | |
8b897cfa RS |
328 | }; |
329 | ||
330 | /* Instruction size costs on 64bit processors. */ | |
331 | static const | |
332 | struct processor_costs size64_cost = { | |
06a67bdd RS |
333 | COSTS_N_INSNS (1), /* mulsi */ |
334 | COSTS_N_INSNS (1), /* mulsi_const */ | |
335 | COSTS_N_INSNS (1), /* mulsi_const9 */ | |
336 | COSTS_N_INSNS (1), /* muldi */ | |
337 | COSTS_N_INSNS (1), /* divsi */ | |
338 | COSTS_N_INSNS (1), /* divdi */ | |
339 | COSTS_N_INSNS (1), /* fp */ | |
340 | COSTS_N_INSNS (1), /* dmul */ | |
341 | COSTS_N_INSNS (1), /* sdiv */ | |
342 | COSTS_N_INSNS (1), /* ddiv */ | |
8b897cfa RS |
343 | }; |
344 | ||
345 | /* Instruction costs on RIOS1 processors. */ | |
346 | static const | |
347 | struct processor_costs rios1_cost = { | |
06a67bdd RS |
348 | COSTS_N_INSNS (5), /* mulsi */ |
349 | COSTS_N_INSNS (4), /* mulsi_const */ | |
350 | COSTS_N_INSNS (3), /* mulsi_const9 */ | |
351 | COSTS_N_INSNS (5), /* muldi */ | |
352 | COSTS_N_INSNS (19), /* divsi */ | |
353 | COSTS_N_INSNS (19), /* divdi */ | |
354 | COSTS_N_INSNS (2), /* fp */ | |
355 | COSTS_N_INSNS (2), /* dmul */ | |
356 | COSTS_N_INSNS (19), /* sdiv */ | |
357 | COSTS_N_INSNS (19), /* ddiv */ | |
8b897cfa RS |
358 | }; |
359 | ||
360 | /* Instruction costs on RIOS2 processors. */ | |
361 | static const | |
362 | struct processor_costs rios2_cost = { | |
06a67bdd RS |
363 | COSTS_N_INSNS (2), /* mulsi */ |
364 | COSTS_N_INSNS (2), /* mulsi_const */ | |
365 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
366 | COSTS_N_INSNS (2), /* muldi */ | |
367 | COSTS_N_INSNS (13), /* divsi */ | |
368 | COSTS_N_INSNS (13), /* divdi */ | |
369 | COSTS_N_INSNS (2), /* fp */ | |
370 | COSTS_N_INSNS (2), /* dmul */ | |
371 | COSTS_N_INSNS (17), /* sdiv */ | |
372 | COSTS_N_INSNS (17), /* ddiv */ | |
8b897cfa RS |
373 | }; |
374 | ||
375 | /* Instruction costs on RS64A processors. */ | |
376 | static const | |
377 | struct processor_costs rs64a_cost = { | |
06a67bdd RS |
378 | COSTS_N_INSNS (20), /* mulsi */ |
379 | COSTS_N_INSNS (12), /* mulsi_const */ | |
380 | COSTS_N_INSNS (8), /* mulsi_const9 */ | |
381 | COSTS_N_INSNS (34), /* muldi */ | |
382 | COSTS_N_INSNS (65), /* divsi */ | |
383 | COSTS_N_INSNS (67), /* divdi */ | |
384 | COSTS_N_INSNS (4), /* fp */ | |
385 | COSTS_N_INSNS (4), /* dmul */ | |
386 | COSTS_N_INSNS (31), /* sdiv */ | |
387 | COSTS_N_INSNS (31), /* ddiv */ | |
8b897cfa RS |
388 | }; |
389 | ||
390 | /* Instruction costs on MPCCORE processors. */ | |
391 | static const | |
392 | struct processor_costs mpccore_cost = { | |
06a67bdd RS |
393 | COSTS_N_INSNS (2), /* mulsi */ |
394 | COSTS_N_INSNS (2), /* mulsi_const */ | |
395 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
396 | COSTS_N_INSNS (2), /* muldi */ | |
397 | COSTS_N_INSNS (6), /* divsi */ | |
398 | COSTS_N_INSNS (6), /* divdi */ | |
399 | COSTS_N_INSNS (4), /* fp */ | |
400 | COSTS_N_INSNS (5), /* dmul */ | |
401 | COSTS_N_INSNS (10), /* sdiv */ | |
402 | COSTS_N_INSNS (17), /* ddiv */ | |
8b897cfa RS |
403 | }; |
404 | ||
405 | /* Instruction costs on PPC403 processors. */ | |
406 | static const | |
407 | struct processor_costs ppc403_cost = { | |
06a67bdd RS |
408 | COSTS_N_INSNS (4), /* mulsi */ |
409 | COSTS_N_INSNS (4), /* mulsi_const */ | |
410 | COSTS_N_INSNS (4), /* mulsi_const9 */ | |
411 | COSTS_N_INSNS (4), /* muldi */ | |
412 | COSTS_N_INSNS (33), /* divsi */ | |
413 | COSTS_N_INSNS (33), /* divdi */ | |
414 | COSTS_N_INSNS (11), /* fp */ | |
415 | COSTS_N_INSNS (11), /* dmul */ | |
416 | COSTS_N_INSNS (11), /* sdiv */ | |
417 | COSTS_N_INSNS (11), /* ddiv */ | |
8b897cfa RS |
418 | }; |
419 | ||
420 | /* Instruction costs on PPC405 processors. */ | |
421 | static const | |
422 | struct processor_costs ppc405_cost = { | |
06a67bdd RS |
423 | COSTS_N_INSNS (5), /* mulsi */ |
424 | COSTS_N_INSNS (4), /* mulsi_const */ | |
425 | COSTS_N_INSNS (3), /* mulsi_const9 */ | |
426 | COSTS_N_INSNS (5), /* muldi */ | |
427 | COSTS_N_INSNS (35), /* divsi */ | |
428 | COSTS_N_INSNS (35), /* divdi */ | |
429 | COSTS_N_INSNS (11), /* fp */ | |
430 | COSTS_N_INSNS (11), /* dmul */ | |
431 | COSTS_N_INSNS (11), /* sdiv */ | |
432 | COSTS_N_INSNS (11), /* ddiv */ | |
8b897cfa RS |
433 | }; |
434 | ||
435 | /* Instruction costs on PPC440 processors. */ | |
436 | static const | |
437 | struct processor_costs ppc440_cost = { | |
06a67bdd RS |
438 | COSTS_N_INSNS (3), /* mulsi */ |
439 | COSTS_N_INSNS (2), /* mulsi_const */ | |
440 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
441 | COSTS_N_INSNS (3), /* muldi */ | |
442 | COSTS_N_INSNS (34), /* divsi */ | |
443 | COSTS_N_INSNS (34), /* divdi */ | |
444 | COSTS_N_INSNS (5), /* fp */ | |
445 | COSTS_N_INSNS (5), /* dmul */ | |
446 | COSTS_N_INSNS (19), /* sdiv */ | |
447 | COSTS_N_INSNS (33), /* ddiv */ | |
8b897cfa RS |
448 | }; |
449 | ||
450 | /* Instruction costs on PPC601 processors. */ | |
451 | static const | |
452 | struct processor_costs ppc601_cost = { | |
06a67bdd RS |
453 | COSTS_N_INSNS (5), /* mulsi */ |
454 | COSTS_N_INSNS (5), /* mulsi_const */ | |
455 | COSTS_N_INSNS (5), /* mulsi_const9 */ | |
456 | COSTS_N_INSNS (5), /* muldi */ | |
457 | COSTS_N_INSNS (36), /* divsi */ | |
458 | COSTS_N_INSNS (36), /* divdi */ | |
459 | COSTS_N_INSNS (4), /* fp */ | |
460 | COSTS_N_INSNS (5), /* dmul */ | |
461 | COSTS_N_INSNS (17), /* sdiv */ | |
462 | COSTS_N_INSNS (31), /* ddiv */ | |
8b897cfa RS |
463 | }; |
464 | ||
465 | /* Instruction costs on PPC603 processors. */ | |
466 | static const | |
467 | struct processor_costs ppc603_cost = { | |
06a67bdd RS |
468 | COSTS_N_INSNS (5), /* mulsi */ |
469 | COSTS_N_INSNS (3), /* mulsi_const */ | |
470 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
471 | COSTS_N_INSNS (5), /* muldi */ | |
472 | COSTS_N_INSNS (37), /* divsi */ | |
473 | COSTS_N_INSNS (37), /* divdi */ | |
474 | COSTS_N_INSNS (3), /* fp */ | |
475 | COSTS_N_INSNS (4), /* dmul */ | |
476 | COSTS_N_INSNS (18), /* sdiv */ | |
477 | COSTS_N_INSNS (33), /* ddiv */ | |
8b897cfa RS |
478 | }; |
479 | ||
480 | /* Instruction costs on PPC604 processors. */ | |
481 | static const | |
482 | struct processor_costs ppc604_cost = { | |
06a67bdd RS |
483 | COSTS_N_INSNS (4), /* mulsi */ |
484 | COSTS_N_INSNS (4), /* mulsi_const */ | |
485 | COSTS_N_INSNS (4), /* mulsi_const9 */ | |
486 | COSTS_N_INSNS (4), /* muldi */ | |
487 | COSTS_N_INSNS (20), /* divsi */ | |
488 | COSTS_N_INSNS (20), /* divdi */ | |
489 | COSTS_N_INSNS (3), /* fp */ | |
490 | COSTS_N_INSNS (3), /* dmul */ | |
491 | COSTS_N_INSNS (18), /* sdiv */ | |
492 | COSTS_N_INSNS (32), /* ddiv */ | |
8b897cfa RS |
493 | }; |
494 | ||
495 | /* Instruction costs on PPC604e processors. */ | |
496 | static const | |
497 | struct processor_costs ppc604e_cost = { | |
06a67bdd RS |
498 | COSTS_N_INSNS (2), /* mulsi */ |
499 | COSTS_N_INSNS (2), /* mulsi_const */ | |
500 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
501 | COSTS_N_INSNS (2), /* muldi */ | |
502 | COSTS_N_INSNS (20), /* divsi */ | |
503 | COSTS_N_INSNS (20), /* divdi */ | |
504 | COSTS_N_INSNS (3), /* fp */ | |
505 | COSTS_N_INSNS (3), /* dmul */ | |
506 | COSTS_N_INSNS (18), /* sdiv */ | |
507 | COSTS_N_INSNS (32), /* ddiv */ | |
8b897cfa RS |
508 | }; |
509 | ||
f0517163 | 510 | /* Instruction costs on PPC620 processors. */ |
8b897cfa RS |
511 | static const |
512 | struct processor_costs ppc620_cost = { | |
06a67bdd RS |
513 | COSTS_N_INSNS (5), /* mulsi */ |
514 | COSTS_N_INSNS (4), /* mulsi_const */ | |
515 | COSTS_N_INSNS (3), /* mulsi_const9 */ | |
516 | COSTS_N_INSNS (7), /* muldi */ | |
517 | COSTS_N_INSNS (21), /* divsi */ | |
518 | COSTS_N_INSNS (37), /* divdi */ | |
519 | COSTS_N_INSNS (3), /* fp */ | |
520 | COSTS_N_INSNS (3), /* dmul */ | |
521 | COSTS_N_INSNS (18), /* sdiv */ | |
522 | COSTS_N_INSNS (32), /* ddiv */ | |
f0517163 RS |
523 | }; |
524 | ||
525 | /* Instruction costs on PPC630 processors. */ | |
526 | static const | |
527 | struct processor_costs ppc630_cost = { | |
06a67bdd RS |
528 | COSTS_N_INSNS (5), /* mulsi */ |
529 | COSTS_N_INSNS (4), /* mulsi_const */ | |
530 | COSTS_N_INSNS (3), /* mulsi_const9 */ | |
531 | COSTS_N_INSNS (7), /* muldi */ | |
532 | COSTS_N_INSNS (21), /* divsi */ | |
533 | COSTS_N_INSNS (37), /* divdi */ | |
534 | COSTS_N_INSNS (3), /* fp */ | |
535 | COSTS_N_INSNS (3), /* dmul */ | |
536 | COSTS_N_INSNS (17), /* sdiv */ | |
537 | COSTS_N_INSNS (21), /* ddiv */ | |
8b897cfa RS |
538 | }; |
539 | ||
540 | /* Instruction costs on PPC750 and PPC7400 processors. */ | |
541 | static const | |
542 | struct processor_costs ppc750_cost = { | |
06a67bdd RS |
543 | COSTS_N_INSNS (5), /* mulsi */ |
544 | COSTS_N_INSNS (3), /* mulsi_const */ | |
545 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
546 | COSTS_N_INSNS (5), /* muldi */ | |
547 | COSTS_N_INSNS (17), /* divsi */ | |
548 | COSTS_N_INSNS (17), /* divdi */ | |
549 | COSTS_N_INSNS (3), /* fp */ | |
550 | COSTS_N_INSNS (3), /* dmul */ | |
551 | COSTS_N_INSNS (17), /* sdiv */ | |
552 | COSTS_N_INSNS (31), /* ddiv */ | |
8b897cfa RS |
553 | }; |
554 | ||
555 | /* Instruction costs on PPC7450 processors. */ | |
556 | static const | |
557 | struct processor_costs ppc7450_cost = { | |
06a67bdd RS |
558 | COSTS_N_INSNS (4), /* mulsi */ |
559 | COSTS_N_INSNS (3), /* mulsi_const */ | |
560 | COSTS_N_INSNS (3), /* mulsi_const9 */ | |
561 | COSTS_N_INSNS (4), /* muldi */ | |
562 | COSTS_N_INSNS (23), /* divsi */ | |
563 | COSTS_N_INSNS (23), /* divdi */ | |
564 | COSTS_N_INSNS (5), /* fp */ | |
565 | COSTS_N_INSNS (5), /* dmul */ | |
566 | COSTS_N_INSNS (21), /* sdiv */ | |
567 | COSTS_N_INSNS (35), /* ddiv */ | |
8b897cfa | 568 | }; |
a3170dc6 | 569 | |
8b897cfa RS |
570 | /* Instruction costs on PPC8540 processors. */ |
571 | static const | |
572 | struct processor_costs ppc8540_cost = { | |
06a67bdd RS |
573 | COSTS_N_INSNS (4), /* mulsi */ |
574 | COSTS_N_INSNS (4), /* mulsi_const */ | |
575 | COSTS_N_INSNS (4), /* mulsi_const9 */ | |
576 | COSTS_N_INSNS (4), /* muldi */ | |
577 | COSTS_N_INSNS (19), /* divsi */ | |
578 | COSTS_N_INSNS (19), /* divdi */ | |
579 | COSTS_N_INSNS (4), /* fp */ | |
580 | COSTS_N_INSNS (4), /* dmul */ | |
581 | COSTS_N_INSNS (29), /* sdiv */ | |
582 | COSTS_N_INSNS (29), /* ddiv */ | |
8b897cfa RS |
583 | }; |
584 | ||
585 | /* Instruction costs on POWER4 and POWER5 processors. */ | |
586 | static const | |
587 | struct processor_costs power4_cost = { | |
06a67bdd RS |
588 | COSTS_N_INSNS (3), /* mulsi */ |
589 | COSTS_N_INSNS (2), /* mulsi_const */ | |
590 | COSTS_N_INSNS (2), /* mulsi_const9 */ | |
591 | COSTS_N_INSNS (4), /* muldi */ | |
592 | COSTS_N_INSNS (18), /* divsi */ | |
593 | COSTS_N_INSNS (34), /* divdi */ | |
594 | COSTS_N_INSNS (3), /* fp */ | |
595 | COSTS_N_INSNS (3), /* dmul */ | |
596 | COSTS_N_INSNS (17), /* sdiv */ | |
597 | COSTS_N_INSNS (17), /* ddiv */ | |
8b897cfa RS |
598 | }; |
599 | ||
600 | \f | |
a2369ed3 DJ |
601 | static bool rs6000_function_ok_for_sibcall (tree, tree); |
602 | static int num_insns_constant_wide (HOST_WIDE_INT); | |
603 | static void validate_condition_mode (enum rtx_code, enum machine_mode); | |
604 | static rtx rs6000_generate_compare (enum rtx_code); | |
605 | static void rs6000_maybe_dead (rtx); | |
606 | static void rs6000_emit_stack_tie (void); | |
607 | static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx); | |
608 | static rtx spe_synthesize_frame_save (rtx); | |
609 | static bool spe_func_has_64bit_regs_p (void); | |
b20a9cca | 610 | static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int, |
d1d0c603 | 611 | int, HOST_WIDE_INT); |
a2369ed3 DJ |
612 | static rtx gen_frame_mem_offset (enum machine_mode, rtx, int); |
613 | static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int); | |
614 | static unsigned rs6000_hash_constant (rtx); | |
615 | static unsigned toc_hash_function (const void *); | |
616 | static int toc_hash_eq (const void *, const void *); | |
617 | static int constant_pool_expr_1 (rtx, int *, int *); | |
618 | static bool constant_pool_expr_p (rtx); | |
619 | static bool toc_relative_expr_p (rtx); | |
620 | static bool legitimate_small_data_p (enum machine_mode, rtx); | |
a2369ed3 DJ |
621 | static bool legitimate_indexed_address_p (rtx, int); |
622 | static bool legitimate_indirect_address_p (rtx, int); | |
4c81e946 | 623 | static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode); |
a2369ed3 DJ |
624 | static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int); |
625 | static struct machine_function * rs6000_init_machine_status (void); | |
626 | static bool rs6000_assemble_integer (rtx, unsigned int, int); | |
5add3202 | 627 | #ifdef HAVE_GAS_HIDDEN |
a2369ed3 | 628 | static void rs6000_assemble_visibility (tree, int); |
5add3202 | 629 | #endif |
a2369ed3 DJ |
630 | static int rs6000_ra_ever_killed (void); |
631 | static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *); | |
8bb418a3 | 632 | static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *); |
76d2b81d | 633 | static void rs6000_eliminate_indexed_memrefs (rtx operands[2]); |
f18eca82 | 634 | static const char *rs6000_mangle_fundamental_type (tree); |
b86fe7b4 | 635 | extern const struct attribute_spec rs6000_attribute_table[]; |
a2369ed3 DJ |
636 | static void rs6000_set_default_type_attributes (tree); |
637 | static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT); | |
638 | static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT); | |
b20a9cca AM |
639 | static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, |
640 | tree); | |
a2369ed3 | 641 | static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT); |
c6e8c921 | 642 | static bool rs6000_return_in_memory (tree, tree); |
a2369ed3 | 643 | static void rs6000_file_start (void); |
7c262518 | 644 | #if TARGET_ELF |
a2369ed3 DJ |
645 | static unsigned int rs6000_elf_section_type_flags (tree, const char *, int); |
646 | static void rs6000_elf_asm_out_constructor (rtx, int); | |
647 | static void rs6000_elf_asm_out_destructor (rtx, int); | |
648 | static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT); | |
649 | static void rs6000_elf_unique_section (tree, int); | |
650 | static void rs6000_elf_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 651 | unsigned HOST_WIDE_INT); |
a56d7372 | 652 | static void rs6000_elf_encode_section_info (tree, rtx, int) |
0e5dbd9b | 653 | ATTRIBUTE_UNUSED; |
a2369ed3 | 654 | static bool rs6000_elf_in_small_data_p (tree); |
7c262518 | 655 | #endif |
cbaaba19 | 656 | #if TARGET_XCOFF |
a2369ed3 | 657 | static void rs6000_xcoff_asm_globalize_label (FILE *, const char *); |
8210e4c4 | 658 | static void rs6000_xcoff_asm_named_section (const char *, unsigned int, tree); |
a2369ed3 DJ |
659 | static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT); |
660 | static void rs6000_xcoff_unique_section (tree, int); | |
661 | static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx, | |
b20a9cca | 662 | unsigned HOST_WIDE_INT); |
a2369ed3 DJ |
663 | static const char * rs6000_xcoff_strip_name_encoding (const char *); |
664 | static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int); | |
665 | static void rs6000_xcoff_file_start (void); | |
666 | static void rs6000_xcoff_file_end (void); | |
f1384257 AM |
667 | #endif |
668 | #if TARGET_MACHO | |
a2369ed3 | 669 | static bool rs6000_binds_local_p (tree); |
f1384257 | 670 | #endif |
a2369ed3 DJ |
671 | static int rs6000_variable_issue (FILE *, int, rtx, int); |
672 | static bool rs6000_rtx_costs (rtx, int, int, int *); | |
673 | static int rs6000_adjust_cost (rtx, rtx, rtx, int); | |
cbe26ab8 | 674 | static bool is_microcoded_insn (rtx); |
79ae11c4 | 675 | static int is_dispatch_slot_restricted (rtx); |
cbe26ab8 DN |
676 | static bool is_cracked_insn (rtx); |
677 | static bool is_branch_slot_insn (rtx); | |
a2369ed3 DJ |
678 | static int rs6000_adjust_priority (rtx, int); |
679 | static int rs6000_issue_rate (void); | |
569fa502 | 680 | static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int); |
cbe26ab8 DN |
681 | static rtx get_next_active_insn (rtx, rtx); |
682 | static bool insn_terminates_group_p (rtx , enum group_termination); | |
683 | static bool is_costly_group (rtx *, rtx); | |
684 | static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *); | |
685 | static int redefine_groups (FILE *, int, rtx, rtx); | |
686 | static int pad_groups (FILE *, int, rtx, rtx); | |
687 | static void rs6000_sched_finish (FILE *, int); | |
a2369ed3 | 688 | static int rs6000_use_sched_lookahead (void); |
7ccf35ed DN |
689 | static tree rs6000_builtin_mask_for_load (void); |
690 | static tree rs6000_builtin_mask_for_store (void); | |
a2369ed3 DJ |
691 | |
692 | static void rs6000_init_builtins (void); | |
693 | static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx); | |
694 | static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx); | |
695 | static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx); | |
696 | static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int); | |
697 | static void altivec_init_builtins (void); | |
698 | static void rs6000_common_init_builtins (void); | |
c15c90bb | 699 | static void rs6000_init_libfuncs (void); |
a2369ed3 | 700 | |
b20a9cca AM |
701 | static void enable_mask_for_builtins (struct builtin_description *, int, |
702 | enum rs6000_builtins, | |
703 | enum rs6000_builtins); | |
7c62e993 | 704 | static tree build_opaque_vector_type (tree, int); |
a2369ed3 DJ |
705 | static void spe_init_builtins (void); |
706 | static rtx spe_expand_builtin (tree, rtx, bool *); | |
61bea3b0 | 707 | static rtx spe_expand_stv_builtin (enum insn_code, tree); |
a2369ed3 DJ |
708 | static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx); |
709 | static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx); | |
710 | static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx); | |
d1d0c603 JJ |
711 | static rs6000_stack_t *rs6000_stack_info (void); |
712 | static void debug_stack_info (rs6000_stack_t *); | |
a2369ed3 DJ |
713 | |
714 | static rtx altivec_expand_builtin (tree, rtx, bool *); | |
715 | static rtx altivec_expand_ld_builtin (tree, rtx, bool *); | |
716 | static rtx altivec_expand_st_builtin (tree, rtx, bool *); | |
717 | static rtx altivec_expand_dst_builtin (tree, rtx, bool *); | |
718 | static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx); | |
f676971a | 719 | static rtx altivec_expand_predicate_builtin (enum insn_code, |
a2369ed3 | 720 | const char *, tree, rtx); |
b4a62fa0 | 721 | static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx); |
a2369ed3 DJ |
722 | static rtx altivec_expand_stv_builtin (enum insn_code, tree); |
723 | static void rs6000_parse_abi_options (void); | |
724 | static void rs6000_parse_alignment_option (void); | |
725 | static void rs6000_parse_tls_size_option (void); | |
5da702b1 | 726 | static void rs6000_parse_yes_no_option (const char *, const char *, int *); |
a2369ed3 DJ |
727 | static int first_altivec_reg_to_save (void); |
728 | static unsigned int compute_vrsave_mask (void); | |
d62294f5 | 729 | static void compute_save_world_info(rs6000_stack_t *info_ptr); |
a2369ed3 DJ |
730 | static void is_altivec_return_reg (rtx, void *); |
731 | static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int); | |
732 | int easy_vector_constant (rtx, enum machine_mode); | |
733 | static int easy_vector_same (rtx, enum machine_mode); | |
452a7d36 | 734 | static int easy_vector_splat_const (int, enum machine_mode); |
a2369ed3 DJ |
735 | static bool is_ev64_opaque_type (tree); |
736 | static rtx rs6000_dwarf_register_span (rtx); | |
737 | static rtx rs6000_legitimize_tls_address (rtx, enum tls_model); | |
738 | static rtx rs6000_tls_get_addr (void); | |
739 | static rtx rs6000_got_sym (void); | |
740 | static inline int rs6000_tls_symbol_ref_1 (rtx *, void *); | |
741 | static const char *rs6000_get_some_local_dynamic_name (void); | |
742 | static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *); | |
ded9bf77 | 743 | static rtx rs6000_complex_function_value (enum machine_mode); |
b20a9cca | 744 | static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *, |
a2369ed3 | 745 | enum machine_mode, tree); |
ec6376ab | 746 | static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int); |
b1917422 | 747 | static void rs6000_move_block_from_reg (int regno, rtx x, int nregs); |
c6e8c921 GK |
748 | static void setup_incoming_varargs (CUMULATIVE_ARGS *, |
749 | enum machine_mode, tree, | |
750 | int *, int); | |
8cd5a4e0 RH |
751 | static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode, |
752 | tree, bool); | |
efdba735 SH |
753 | #if TARGET_MACHO |
754 | static void macho_branch_islands (void); | |
755 | static void add_compiler_branch_island (tree, tree, int); | |
756 | static int no_previous_def (tree function_name); | |
757 | static tree get_prev_label (tree function_name); | |
758 | #endif | |
759 | ||
c35d187f | 760 | static tree rs6000_build_builtin_va_list (void); |
23a60a04 | 761 | static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *); |
fe984136 | 762 | static bool rs6000_must_pass_in_stack (enum machine_mode, tree); |
f676971a | 763 | static bool rs6000_vector_mode_supported_p (enum machine_mode); |
17211ab5 | 764 | |
93f90be6 FJ |
765 | static enum machine_mode rs6000_eh_return_filter_mode (void); |
766 | ||
17211ab5 GK |
767 | /* Hash table stuff for keeping track of TOC entries. */ |
768 | ||
769 | struct toc_hash_struct GTY(()) | |
770 | { | |
771 | /* `key' will satisfy CONSTANT_P; in fact, it will satisfy | |
772 | ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */ | |
773 | rtx key; | |
774 | enum machine_mode key_mode; | |
775 | int labelno; | |
776 | }; | |
777 | ||
778 | static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table; | |
c81bebd7 MM |
779 | \f |
780 | /* Default register names. */ | |
781 | char rs6000_reg_names[][8] = | |
782 | { | |
802a0058 MM |
783 | "0", "1", "2", "3", "4", "5", "6", "7", |
784 | "8", "9", "10", "11", "12", "13", "14", "15", | |
785 | "16", "17", "18", "19", "20", "21", "22", "23", | |
786 | "24", "25", "26", "27", "28", "29", "30", "31", | |
787 | "0", "1", "2", "3", "4", "5", "6", "7", | |
788 | "8", "9", "10", "11", "12", "13", "14", "15", | |
789 | "16", "17", "18", "19", "20", "21", "22", "23", | |
790 | "24", "25", "26", "27", "28", "29", "30", "31", | |
791 | "mq", "lr", "ctr","ap", | |
792 | "0", "1", "2", "3", "4", "5", "6", "7", | |
0ac081f6 AH |
793 | "xer", |
794 | /* AltiVec registers. */ | |
0cd5e3a1 AH |
795 | "0", "1", "2", "3", "4", "5", "6", "7", |
796 | "8", "9", "10", "11", "12", "13", "14", "15", | |
797 | "16", "17", "18", "19", "20", "21", "22", "23", | |
798 | "24", "25", "26", "27", "28", "29", "30", "31", | |
59a4c851 AH |
799 | "vrsave", "vscr", |
800 | /* SPE registers. */ | |
801 | "spe_acc", "spefscr" | |
c81bebd7 MM |
802 | }; |
803 | ||
804 | #ifdef TARGET_REGNAMES | |
8b60264b | 805 | static const char alt_reg_names[][8] = |
c81bebd7 | 806 | { |
802a0058 MM |
807 | "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", |
808 | "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15", | |
809 | "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23", | |
810 | "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31", | |
811 | "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7", | |
812 | "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15", | |
813 | "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23", | |
814 | "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31", | |
815 | "mq", "lr", "ctr", "ap", | |
816 | "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7", | |
0ac081f6 | 817 | "xer", |
59a4c851 | 818 | /* AltiVec registers. */ |
0ac081f6 | 819 | "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7", |
59a4c851 AH |
820 | "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15", |
821 | "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23", | |
822 | "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31", | |
823 | "vrsave", "vscr", | |
824 | /* SPE registers. */ | |
825 | "spe_acc", "spefscr" | |
c81bebd7 MM |
826 | }; |
827 | #endif | |
9878760c | 828 | \f |
daf11973 MM |
829 | #ifndef MASK_STRICT_ALIGN |
830 | #define MASK_STRICT_ALIGN 0 | |
831 | #endif | |
ffcfcb5f AM |
832 | #ifndef TARGET_PROFILE_KERNEL |
833 | #define TARGET_PROFILE_KERNEL 0 | |
834 | #endif | |
3961e8fe RH |
835 | |
836 | /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */ | |
837 | #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO)) | |
c4501e62 JJ |
838 | |
839 | /* Return 1 for a symbol ref for a thread-local storage symbol. */ | |
840 | #define RS6000_SYMBOL_REF_TLS_P(RTX) \ | |
841 | (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0) | |
672a6f42 NB |
842 | \f |
843 | /* Initialize the GCC target structure. */ | |
91d231cb JM |
844 | #undef TARGET_ATTRIBUTE_TABLE |
845 | #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table | |
a5c76ee6 ZW |
846 | #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES |
847 | #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes | |
daf11973 | 848 | |
301d03af RS |
849 | #undef TARGET_ASM_ALIGNED_DI_OP |
850 | #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP | |
851 | ||
852 | /* Default unaligned ops are only provided for ELF. Find the ops needed | |
853 | for non-ELF systems. */ | |
854 | #ifndef OBJECT_FORMAT_ELF | |
cbaaba19 | 855 | #if TARGET_XCOFF |
ae6c1efd | 856 | /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on |
301d03af RS |
857 | 64-bit targets. */ |
858 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
859 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2," | |
860 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
861 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4," | |
862 | #undef TARGET_ASM_UNALIGNED_DI_OP | |
863 | #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8," | |
864 | #else | |
865 | /* For Darwin. */ | |
866 | #undef TARGET_ASM_UNALIGNED_HI_OP | |
867 | #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t" | |
868 | #undef TARGET_ASM_UNALIGNED_SI_OP | |
869 | #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t" | |
49bd1d27 SS |
870 | #undef TARGET_ASM_UNALIGNED_DI_OP |
871 | #define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t" | |
872 | #undef TARGET_ASM_ALIGNED_DI_OP | |
873 | #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t" | |
301d03af RS |
874 | #endif |
875 | #endif | |
876 | ||
877 | /* This hook deals with fixups for relocatable code and DI-mode objects | |
878 | in 64-bit code. */ | |
879 | #undef TARGET_ASM_INTEGER | |
880 | #define TARGET_ASM_INTEGER rs6000_assemble_integer | |
881 | ||
93638d7a AM |
882 | #ifdef HAVE_GAS_HIDDEN |
883 | #undef TARGET_ASM_ASSEMBLE_VISIBILITY | |
884 | #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility | |
885 | #endif | |
886 | ||
c4501e62 JJ |
887 | #undef TARGET_HAVE_TLS |
888 | #define TARGET_HAVE_TLS HAVE_AS_TLS | |
889 | ||
890 | #undef TARGET_CANNOT_FORCE_CONST_MEM | |
891 | #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p | |
892 | ||
08c148a8 NB |
893 | #undef TARGET_ASM_FUNCTION_PROLOGUE |
894 | #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue | |
895 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
896 | #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue | |
897 | ||
b54cf83a DE |
898 | #undef TARGET_SCHED_VARIABLE_ISSUE |
899 | #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue | |
900 | ||
c237e94a ZW |
901 | #undef TARGET_SCHED_ISSUE_RATE |
902 | #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate | |
903 | #undef TARGET_SCHED_ADJUST_COST | |
904 | #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost | |
905 | #undef TARGET_SCHED_ADJUST_PRIORITY | |
906 | #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority | |
f676971a | 907 | #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE |
569fa502 | 908 | #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence |
cbe26ab8 DN |
909 | #undef TARGET_SCHED_FINISH |
910 | #define TARGET_SCHED_FINISH rs6000_sched_finish | |
c237e94a | 911 | |
be12c2b0 VM |
912 | #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD |
913 | #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead | |
914 | ||
7ccf35ed DN |
915 | #undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD |
916 | #define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load | |
917 | ||
918 | #undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE | |
919 | #define TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE rs6000_builtin_mask_for_store | |
920 | ||
0ac081f6 AH |
921 | #undef TARGET_INIT_BUILTINS |
922 | #define TARGET_INIT_BUILTINS rs6000_init_builtins | |
923 | ||
924 | #undef TARGET_EXPAND_BUILTIN | |
925 | #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin | |
926 | ||
f18eca82 ZL |
927 | #undef TARGET_MANGLE_FUNDAMENTAL_TYPE |
928 | #define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type | |
929 | ||
c15c90bb ZW |
930 | #undef TARGET_INIT_LIBFUNCS |
931 | #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs | |
932 | ||
f1384257 | 933 | #if TARGET_MACHO |
0e5dbd9b DE |
934 | #undef TARGET_BINDS_LOCAL_P |
935 | #define TARGET_BINDS_LOCAL_P rs6000_binds_local_p | |
f1384257 | 936 | #endif |
0e5dbd9b | 937 | |
3961e8fe RH |
938 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
939 | #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk | |
940 | ||
3961e8fe | 941 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
5b71a4e7 | 942 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true |
00b960c7 | 943 | |
4977bab6 ZW |
944 | #undef TARGET_FUNCTION_OK_FOR_SIBCALL |
945 | #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall | |
946 | ||
3c50106f RH |
947 | #undef TARGET_RTX_COSTS |
948 | #define TARGET_RTX_COSTS rs6000_rtx_costs | |
dcefdf67 RH |
949 | #undef TARGET_ADDRESS_COST |
950 | #define TARGET_ADDRESS_COST hook_int_rtx_0 | |
3c50106f | 951 | |
c8e4f0e9 AH |
952 | #undef TARGET_VECTOR_OPAQUE_P |
953 | #define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type | |
62e1dfcf | 954 | |
96714395 AH |
955 | #undef TARGET_DWARF_REGISTER_SPAN |
956 | #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span | |
957 | ||
c6e8c921 GK |
958 | /* On rs6000, function arguments are promoted, as are function return |
959 | values. */ | |
960 | #undef TARGET_PROMOTE_FUNCTION_ARGS | |
961 | #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true | |
962 | #undef TARGET_PROMOTE_FUNCTION_RETURN | |
963 | #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true | |
964 | ||
c6e8c921 GK |
965 | #undef TARGET_RETURN_IN_MEMORY |
966 | #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory | |
967 | ||
968 | #undef TARGET_SETUP_INCOMING_VARARGS | |
969 | #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs | |
970 | ||
971 | /* Always strict argument naming on rs6000. */ | |
972 | #undef TARGET_STRICT_ARGUMENT_NAMING | |
973 | #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true | |
974 | #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED | |
975 | #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true | |
42ba5130 RH |
976 | #undef TARGET_SPLIT_COMPLEX_ARG |
977 | #define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true | |
fe984136 RH |
978 | #undef TARGET_MUST_PASS_IN_STACK |
979 | #define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack | |
8cd5a4e0 RH |
980 | #undef TARGET_PASS_BY_REFERENCE |
981 | #define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference | |
c6e8c921 | 982 | |
c35d187f RH |
983 | #undef TARGET_BUILD_BUILTIN_VA_LIST |
984 | #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list | |
985 | ||
cd3ce9b4 JM |
986 | #undef TARGET_GIMPLIFY_VA_ARG_EXPR |
987 | #define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg | |
988 | ||
93f90be6 FJ |
989 | #undef TARGET_EH_RETURN_FILTER_MODE |
990 | #define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode | |
991 | ||
f676971a EC |
992 | #undef TARGET_VECTOR_MODE_SUPPORTED_P |
993 | #define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p | |
994 | ||
f6897b10 | 995 | struct gcc_target targetm = TARGET_INITIALIZER; |
672a6f42 | 996 | \f |
0d1fbc8c AH |
997 | |
998 | /* Value is 1 if hard register REGNO can hold a value of machine-mode | |
999 | MODE. */ | |
1000 | static int | |
1001 | rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode) | |
1002 | { | |
1003 | /* The GPRs can hold any mode, but values bigger than one register | |
1004 | cannot go past R31. */ | |
1005 | if (INT_REGNO_P (regno)) | |
1006 | return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1); | |
1007 | ||
1008 | /* The float registers can only hold floating modes and DImode. */ | |
1009 | if (FP_REGNO_P (regno)) | |
1010 | return | |
1011 | (GET_MODE_CLASS (mode) == MODE_FLOAT | |
1012 | && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1)) | |
1013 | || (GET_MODE_CLASS (mode) == MODE_INT | |
1014 | && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD); | |
1015 | ||
1016 | /* The CR register can only hold CC modes. */ | |
1017 | if (CR_REGNO_P (regno)) | |
1018 | return GET_MODE_CLASS (mode) == MODE_CC; | |
1019 | ||
1020 | if (XER_REGNO_P (regno)) | |
1021 | return mode == PSImode; | |
1022 | ||
1023 | /* AltiVec only in AldyVec registers. */ | |
1024 | if (ALTIVEC_REGNO_P (regno)) | |
1025 | return ALTIVEC_VECTOR_MODE (mode); | |
1026 | ||
1027 | /* ...but GPRs can hold SIMD data on the SPE in one register. */ | |
1028 | if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
1029 | return 1; | |
1030 | ||
1031 | /* We cannot put TImode anywhere except general register and it must be | |
1032 | able to fit within the register set. */ | |
1033 | ||
1034 | return GET_MODE_SIZE (mode) <= UNITS_PER_WORD; | |
1035 | } | |
1036 | ||
1037 | /* Initialize rs6000_hard_regno_mode_ok_p table. */ | |
1038 | static void | |
1039 | rs6000_init_hard_regno_mode_ok (void) | |
1040 | { | |
1041 | int r, m; | |
1042 | ||
1043 | for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r) | |
1044 | for (m = 0; m < NUM_MACHINE_MODES; ++m) | |
1045 | if (rs6000_hard_regno_mode_ok (r, m)) | |
1046 | rs6000_hard_regno_mode_ok_p[m][r] = true; | |
1047 | } | |
1048 | ||
c1e55850 GK |
1049 | /* If not otherwise specified by a target, make 'long double' equivalent to |
1050 | 'double'. */ | |
1051 | ||
1052 | #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE | |
1053 | #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64 | |
1054 | #endif | |
1055 | ||
5248c961 RK |
1056 | /* Override command line options. Mostly we process the processor |
1057 | type and sometimes adjust other TARGET_ options. */ | |
1058 | ||
1059 | void | |
d779d0dc | 1060 | rs6000_override_options (const char *default_cpu) |
5248c961 | 1061 | { |
c4d38ccb | 1062 | size_t i, j; |
8e3f41e7 | 1063 | struct rs6000_cpu_select *ptr; |
66188a7e | 1064 | int set_masks; |
5248c961 | 1065 | |
66188a7e | 1066 | /* Simplifications for entries below. */ |
85638c0d | 1067 | |
66188a7e GK |
1068 | enum { |
1069 | POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS, | |
1070 | POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC | |
1071 | }; | |
85638c0d | 1072 | |
66188a7e GK |
1073 | /* This table occasionally claims that a processor does not support |
1074 | a particular feature even though it does, but the feature is slower | |
1075 | than the alternative. Thus, it shouldn't be relied on as a | |
f676971a | 1076 | complete description of the processor's support. |
66188a7e GK |
1077 | |
1078 | Please keep this list in order, and don't forget to update the | |
1079 | documentation in invoke.texi when adding a new processor or | |
1080 | flag. */ | |
5248c961 RK |
1081 | static struct ptt |
1082 | { | |
8b60264b KG |
1083 | const char *const name; /* Canonical processor name. */ |
1084 | const enum processor_type processor; /* Processor type enum value. */ | |
1085 | const int target_enable; /* Target flags to enable. */ | |
8b60264b | 1086 | } const processor_target_table[] |
66188a7e | 1087 | = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, |
49a0b204 | 1088 | {"403", PROCESSOR_PPC403, |
66188a7e GK |
1089 | POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN}, |
1090 | {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
1091 | {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK}, | |
1092 | {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
1093 | {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK}, | |
1094 | {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK}, | |
5248c961 | 1095 | {"601", PROCESSOR_PPC601, |
66188a7e GK |
1096 | MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING}, |
1097 | {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1098 | {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1099 | {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1100 | {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1101 | {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
7ddb6568 AM |
1102 | {"620", PROCESSOR_PPC620, |
1103 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
1104 | {"630", PROCESSOR_PPC630, | |
1105 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
66188a7e GK |
1106 | {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, |
1107 | {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK}, | |
1108 | {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK}, | |
1109 | {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1110 | {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
1111 | {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
1112 | {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
1113 | {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1114 | {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
7177e720 | 1115 | {"970", PROCESSOR_POWER4, |
66188a7e GK |
1116 | POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64}, |
1117 | {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS}, | |
1118 | {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT}, | |
1119 | {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT}, | |
1120 | {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK}, | |
49ffe578 | 1121 | {"G5", PROCESSOR_POWER4, |
66188a7e GK |
1122 | POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64}, |
1123 | {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
1124 | {"power2", PROCESSOR_POWER, | |
1125 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING}, | |
7ddb6568 AM |
1126 | {"power3", PROCESSOR_PPC630, |
1127 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}, | |
1128 | {"power4", PROCESSOR_POWER4, | |
fc091c8e | 1129 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64}, |
ec507f2d | 1130 | {"power5", PROCESSOR_POWER5, |
fc091c8e | 1131 | POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64}, |
66188a7e GK |
1132 | {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK}, |
1133 | {"powerpc64", PROCESSOR_POWERPC64, | |
1134 | POWERPC_BASE_MASK | MASK_POWERPC64}, | |
1135 | {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
1136 | {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
1137 | {"rios2", PROCESSOR_RIOS2, | |
1138 | MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING}, | |
1139 | {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
1140 | {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING}, | |
7ddb6568 | 1141 | {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64}, |
66188a7e | 1142 | }; |
5248c961 | 1143 | |
ca7558fc | 1144 | const size_t ptt_size = ARRAY_SIZE (processor_target_table); |
5248c961 | 1145 | |
66188a7e GK |
1146 | /* Some OSs don't support saving the high part of 64-bit registers on |
1147 | context switch. Other OSs don't support saving Altivec registers. | |
1148 | On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC | |
1149 | settings; if the user wants either, the user must explicitly specify | |
1150 | them and we won't interfere with the user's specification. */ | |
1151 | ||
1152 | enum { | |
1153 | POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING, | |
f676971a | 1154 | POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT |
66188a7e GK |
1155 | | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC |
1156 | | MASK_MFCRF) | |
1157 | }; | |
0d1fbc8c AH |
1158 | |
1159 | rs6000_init_hard_regno_mode_ok (); | |
1160 | ||
66188a7e GK |
1161 | set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT; |
1162 | #ifdef OS_MISSING_POWERPC64 | |
1163 | if (OS_MISSING_POWERPC64) | |
1164 | set_masks &= ~MASK_POWERPC64; | |
1165 | #endif | |
1166 | #ifdef OS_MISSING_ALTIVEC | |
1167 | if (OS_MISSING_ALTIVEC) | |
1168 | set_masks &= ~MASK_ALTIVEC; | |
1169 | #endif | |
1170 | ||
957211c3 AM |
1171 | /* Don't override these by the processor default if given explicitly. */ |
1172 | set_masks &= ~(target_flags_explicit | |
1173 | & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT)); | |
1174 | ||
a4f6c312 | 1175 | /* Identify the processor type. */ |
8e3f41e7 | 1176 | rs6000_select[0].string = default_cpu; |
3cb999d8 | 1177 | rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT; |
8e3f41e7 | 1178 | |
b6a1cbae | 1179 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
5248c961 | 1180 | { |
8e3f41e7 MM |
1181 | ptr = &rs6000_select[i]; |
1182 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
5248c961 | 1183 | { |
8e3f41e7 MM |
1184 | for (j = 0; j < ptt_size; j++) |
1185 | if (! strcmp (ptr->string, processor_target_table[j].name)) | |
1186 | { | |
1187 | if (ptr->set_tune_p) | |
1188 | rs6000_cpu = processor_target_table[j].processor; | |
1189 | ||
1190 | if (ptr->set_arch_p) | |
1191 | { | |
66188a7e GK |
1192 | target_flags &= ~set_masks; |
1193 | target_flags |= (processor_target_table[j].target_enable | |
1194 | & set_masks); | |
8e3f41e7 MM |
1195 | } |
1196 | break; | |
1197 | } | |
1198 | ||
4406229e | 1199 | if (j == ptt_size) |
8e3f41e7 | 1200 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); |
5248c961 RK |
1201 | } |
1202 | } | |
8a61d227 | 1203 | |
993f19a8 | 1204 | if (TARGET_E500) |
a3170dc6 AH |
1205 | rs6000_isel = 1; |
1206 | ||
dff9f1b6 DE |
1207 | /* If we are optimizing big endian systems for space, use the load/store |
1208 | multiple and string instructions. */ | |
ef792183 | 1209 | if (BYTES_BIG_ENDIAN && optimize_size) |
957211c3 | 1210 | target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING); |
938937d8 | 1211 | |
a4f6c312 SS |
1212 | /* Don't allow -mmultiple or -mstring on little endian systems |
1213 | unless the cpu is a 750, because the hardware doesn't support the | |
1214 | instructions used in little endian mode, and causes an alignment | |
1215 | trap. The 750 does not cause an alignment trap (except when the | |
1216 | target is unaligned). */ | |
bef84347 | 1217 | |
b21fb038 | 1218 | if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750) |
7e69e155 MM |
1219 | { |
1220 | if (TARGET_MULTIPLE) | |
1221 | { | |
1222 | target_flags &= ~MASK_MULTIPLE; | |
b21fb038 | 1223 | if ((target_flags_explicit & MASK_MULTIPLE) != 0) |
7e69e155 MM |
1224 | warning ("-mmultiple is not supported on little endian systems"); |
1225 | } | |
1226 | ||
1227 | if (TARGET_STRING) | |
1228 | { | |
1229 | target_flags &= ~MASK_STRING; | |
b21fb038 | 1230 | if ((target_flags_explicit & MASK_STRING) != 0) |
938937d8 | 1231 | warning ("-mstring is not supported on little endian systems"); |
7e69e155 MM |
1232 | } |
1233 | } | |
3933e0e1 | 1234 | |
38c1f2d7 MM |
1235 | /* Set debug flags */ |
1236 | if (rs6000_debug_name) | |
1237 | { | |
bfc79d3b | 1238 | if (! strcmp (rs6000_debug_name, "all")) |
38c1f2d7 | 1239 | rs6000_debug_stack = rs6000_debug_arg = 1; |
bfc79d3b | 1240 | else if (! strcmp (rs6000_debug_name, "stack")) |
38c1f2d7 | 1241 | rs6000_debug_stack = 1; |
bfc79d3b | 1242 | else if (! strcmp (rs6000_debug_name, "arg")) |
38c1f2d7 MM |
1243 | rs6000_debug_arg = 1; |
1244 | else | |
c725bd79 | 1245 | error ("unknown -mdebug-%s switch", rs6000_debug_name); |
38c1f2d7 MM |
1246 | } |
1247 | ||
57ac7be9 AM |
1248 | if (rs6000_traceback_name) |
1249 | { | |
1250 | if (! strncmp (rs6000_traceback_name, "full", 4)) | |
1251 | rs6000_traceback = traceback_full; | |
1252 | else if (! strncmp (rs6000_traceback_name, "part", 4)) | |
1253 | rs6000_traceback = traceback_part; | |
1254 | else if (! strncmp (rs6000_traceback_name, "no", 2)) | |
1255 | rs6000_traceback = traceback_none; | |
1256 | else | |
1257 | error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'", | |
1258 | rs6000_traceback_name); | |
1259 | } | |
1260 | ||
6fa3f289 | 1261 | /* Set size of long double */ |
c1e55850 | 1262 | rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE; |
6fa3f289 ZW |
1263 | if (rs6000_long_double_size_string) |
1264 | { | |
1265 | char *tail; | |
1266 | int size = strtol (rs6000_long_double_size_string, &tail, 10); | |
1267 | if (*tail != '\0' || (size != 64 && size != 128)) | |
1268 | error ("Unknown switch -mlong-double-%s", | |
1269 | rs6000_long_double_size_string); | |
1270 | else | |
1271 | rs6000_long_double_type_size = size; | |
1272 | } | |
1273 | ||
6d0ef01e HP |
1274 | /* Set Altivec ABI as default for powerpc64 linux. */ |
1275 | if (TARGET_ELF && TARGET_64BIT) | |
1276 | { | |
1277 | rs6000_altivec_abi = 1; | |
1278 | rs6000_altivec_vrsave = 1; | |
1279 | } | |
1280 | ||
0ac081f6 AH |
1281 | /* Handle -mabi= options. */ |
1282 | rs6000_parse_abi_options (); | |
1283 | ||
025d9908 KH |
1284 | /* Handle -malign-XXXXX option. */ |
1285 | rs6000_parse_alignment_option (); | |
1286 | ||
5da702b1 AH |
1287 | /* Handle generic -mFOO=YES/NO options. */ |
1288 | rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string, | |
1289 | &rs6000_altivec_vrsave); | |
1290 | rs6000_parse_yes_no_option ("isel", rs6000_isel_string, | |
1291 | &rs6000_isel); | |
1292 | rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe); | |
1293 | rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string, | |
1294 | &rs6000_float_gprs); | |
993f19a8 | 1295 | |
c4501e62 JJ |
1296 | /* Handle -mtls-size option. */ |
1297 | rs6000_parse_tls_size_option (); | |
1298 | ||
a7ae18e2 AH |
1299 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
1300 | SUBTARGET_OVERRIDE_OPTIONS; | |
1301 | #endif | |
1302 | #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS | |
1303 | SUBSUBTARGET_OVERRIDE_OPTIONS; | |
1304 | #endif | |
1305 | ||
5da702b1 AH |
1306 | if (TARGET_E500) |
1307 | { | |
e4463bf1 AH |
1308 | if (TARGET_ALTIVEC) |
1309 | error ("AltiVec and E500 instructions cannot coexist"); | |
1310 | ||
5da702b1 AH |
1311 | /* The e500 does not have string instructions, and we set |
1312 | MASK_STRING above when optimizing for size. */ | |
1313 | if ((target_flags & MASK_STRING) != 0) | |
1314 | target_flags = target_flags & ~MASK_STRING; | |
b6e59a3a AH |
1315 | |
1316 | /* No SPE means 64-bit long doubles, even if an E500. */ | |
1317 | if (rs6000_spe_string != 0 | |
1318 | && !strcmp (rs6000_spe_string, "no")) | |
1319 | rs6000_long_double_type_size = 64; | |
5da702b1 AH |
1320 | } |
1321 | else if (rs6000_select[1].string != NULL) | |
1322 | { | |
1323 | /* For the powerpc-eabispe configuration, we set all these by | |
1324 | default, so let's unset them if we manually set another | |
1325 | CPU that is not the E500. */ | |
1326 | if (rs6000_abi_string == 0) | |
1327 | rs6000_spe_abi = 0; | |
1328 | if (rs6000_spe_string == 0) | |
1329 | rs6000_spe = 0; | |
1330 | if (rs6000_float_gprs_string == 0) | |
1331 | rs6000_float_gprs = 0; | |
1332 | if (rs6000_isel_string == 0) | |
1333 | rs6000_isel = 0; | |
b6e59a3a | 1334 | if (rs6000_long_double_size_string == 0) |
c1e55850 | 1335 | rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE; |
5da702b1 | 1336 | } |
b5044283 | 1337 | |
ec507f2d DE |
1338 | rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4 |
1339 | && rs6000_cpu != PROCESSOR_POWER5); | |
1340 | rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4 | |
1341 | || rs6000_cpu == PROCESSOR_POWER5); | |
1342 | ||
a5c76ee6 ZW |
1343 | /* Handle -m(no-)longcall option. This is a bit of a cheap hack, |
1344 | using TARGET_OPTIONS to handle a toggle switch, but we're out of | |
1345 | bits in target_flags so TARGET_SWITCHES cannot be used. | |
1346 | Assumption here is that rs6000_longcall_switch points into the | |
1347 | text of the complete option, rather than being a copy, so we can | |
1348 | scan back for the presence or absence of the no- modifier. */ | |
1349 | if (rs6000_longcall_switch) | |
1350 | { | |
1351 | const char *base = rs6000_longcall_switch; | |
1352 | while (base[-1] != 'm') base--; | |
1353 | ||
1354 | if (*rs6000_longcall_switch != '\0') | |
1355 | error ("invalid option `%s'", base); | |
1356 | rs6000_default_long_calls = (base[0] != 'n'); | |
1357 | } | |
1358 | ||
8bb418a3 ZL |
1359 | /* Handle -m(no-)warn-altivec-long similarly. */ |
1360 | if (rs6000_warn_altivec_long_switch) | |
1361 | { | |
1362 | const char *base = rs6000_warn_altivec_long_switch; | |
1363 | while (base[-1] != 'm') base--; | |
1364 | ||
1365 | if (*rs6000_warn_altivec_long_switch != '\0') | |
1366 | error ("invalid option `%s'", base); | |
1367 | rs6000_warn_altivec_long = (base[0] != 'n'); | |
1368 | } | |
1369 | ||
cbe26ab8 | 1370 | /* Handle -mprioritize-restricted-insns option. */ |
ec507f2d DE |
1371 | rs6000_sched_restricted_insns_priority |
1372 | = (rs6000_sched_groups ? 1 : 0); | |
79ae11c4 DN |
1373 | if (rs6000_sched_restricted_insns_priority_str) |
1374 | rs6000_sched_restricted_insns_priority = | |
1375 | atoi (rs6000_sched_restricted_insns_priority_str); | |
1376 | ||
569fa502 | 1377 | /* Handle -msched-costly-dep option. */ |
ec507f2d DE |
1378 | rs6000_sched_costly_dep |
1379 | = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly); | |
569fa502 DN |
1380 | if (rs6000_sched_costly_dep_str) |
1381 | { | |
f676971a | 1382 | if (! strcmp (rs6000_sched_costly_dep_str, "no")) |
569fa502 DN |
1383 | rs6000_sched_costly_dep = no_dep_costly; |
1384 | else if (! strcmp (rs6000_sched_costly_dep_str, "all")) | |
1385 | rs6000_sched_costly_dep = all_deps_costly; | |
1386 | else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load")) | |
1387 | rs6000_sched_costly_dep = true_store_to_load_dep_costly; | |
1388 | else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load")) | |
1389 | rs6000_sched_costly_dep = store_to_load_dep_costly; | |
f676971a | 1390 | else |
cbe26ab8 DN |
1391 | rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str); |
1392 | } | |
1393 | ||
1394 | /* Handle -minsert-sched-nops option. */ | |
ec507f2d DE |
1395 | rs6000_sched_insert_nops |
1396 | = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none); | |
cbe26ab8 DN |
1397 | if (rs6000_sched_insert_nops_str) |
1398 | { | |
1399 | if (! strcmp (rs6000_sched_insert_nops_str, "no")) | |
1400 | rs6000_sched_insert_nops = sched_finish_none; | |
1401 | else if (! strcmp (rs6000_sched_insert_nops_str, "pad")) | |
1402 | rs6000_sched_insert_nops = sched_finish_pad_groups; | |
1403 | else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact")) | |
1404 | rs6000_sched_insert_nops = sched_finish_regroup_exact; | |
1405 | else | |
1406 | rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str); | |
569fa502 DN |
1407 | } |
1408 | ||
c81bebd7 | 1409 | #ifdef TARGET_REGNAMES |
a4f6c312 SS |
1410 | /* If the user desires alternate register names, copy in the |
1411 | alternate names now. */ | |
c81bebd7 | 1412 | if (TARGET_REGNAMES) |
4e135bdd | 1413 | memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names)); |
c81bebd7 MM |
1414 | #endif |
1415 | ||
6fa3f289 ZW |
1416 | /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined. |
1417 | If -maix-struct-return or -msvr4-struct-return was explicitly | |
1418 | used, don't override with the ABI default. */ | |
b21fb038 | 1419 | if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0) |
6fa3f289 ZW |
1420 | { |
1421 | if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET) | |
1422 | target_flags = (target_flags & ~MASK_AIX_STRUCT_RET); | |
1423 | else | |
1424 | target_flags |= MASK_AIX_STRUCT_RET; | |
1425 | } | |
1426 | ||
fcce224d DE |
1427 | if (TARGET_LONG_DOUBLE_128 |
1428 | && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)) | |
70a01792 | 1429 | REAL_MODE_FORMAT (TFmode) = &ibm_extended_format; |
fcce224d | 1430 | |
9ebbca7d GK |
1431 | /* Allocate an alias set for register saves & restores from stack. */ |
1432 | rs6000_sr_alias_set = new_alias_set (); | |
1433 | ||
f676971a | 1434 | if (TARGET_TOC) |
9ebbca7d | 1435 | ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1); |
71f123ca | 1436 | |
301d03af RS |
1437 | /* We can only guarantee the availability of DI pseudo-ops when |
1438 | assembling for 64-bit targets. */ | |
ae6c1efd | 1439 | if (!TARGET_64BIT) |
301d03af RS |
1440 | { |
1441 | targetm.asm_out.aligned_op.di = NULL; | |
1442 | targetm.asm_out.unaligned_op.di = NULL; | |
1443 | } | |
1444 | ||
1494c534 DE |
1445 | /* Set branch target alignment, if not optimizing for size. */ |
1446 | if (!optimize_size) | |
1447 | { | |
1448 | if (rs6000_sched_groups) | |
1449 | { | |
1450 | if (align_functions <= 0) | |
1451 | align_functions = 16; | |
1452 | if (align_jumps <= 0) | |
1453 | align_jumps = 16; | |
1454 | if (align_loops <= 0) | |
1455 | align_loops = 16; | |
1456 | } | |
1457 | if (align_jumps_max_skip <= 0) | |
1458 | align_jumps_max_skip = 15; | |
1459 | if (align_loops_max_skip <= 0) | |
1460 | align_loops_max_skip = 15; | |
1461 | } | |
2792d578 | 1462 | |
71f123ca FS |
1463 | /* Arrange to save and restore machine status around nested functions. */ |
1464 | init_machine_status = rs6000_init_machine_status; | |
42ba5130 RH |
1465 | |
1466 | /* We should always be splitting complex arguments, but we can't break | |
1467 | Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */ | |
1468 | if (DEFAULT_ABI != ABI_AIX) | |
1469 | targetm.calls.split_complex_arg = NULL; | |
8b897cfa RS |
1470 | |
1471 | /* Initialize rs6000_cost with the appropriate target costs. */ | |
1472 | if (optimize_size) | |
1473 | rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost; | |
1474 | else | |
1475 | switch (rs6000_cpu) | |
1476 | { | |
1477 | case PROCESSOR_RIOS1: | |
1478 | rs6000_cost = &rios1_cost; | |
1479 | break; | |
1480 | ||
1481 | case PROCESSOR_RIOS2: | |
1482 | rs6000_cost = &rios2_cost; | |
1483 | break; | |
1484 | ||
1485 | case PROCESSOR_RS64A: | |
1486 | rs6000_cost = &rs64a_cost; | |
1487 | break; | |
1488 | ||
1489 | case PROCESSOR_MPCCORE: | |
1490 | rs6000_cost = &mpccore_cost; | |
1491 | break; | |
1492 | ||
1493 | case PROCESSOR_PPC403: | |
1494 | rs6000_cost = &ppc403_cost; | |
1495 | break; | |
1496 | ||
1497 | case PROCESSOR_PPC405: | |
1498 | rs6000_cost = &ppc405_cost; | |
1499 | break; | |
1500 | ||
1501 | case PROCESSOR_PPC440: | |
1502 | rs6000_cost = &ppc440_cost; | |
1503 | break; | |
1504 | ||
1505 | case PROCESSOR_PPC601: | |
1506 | rs6000_cost = &ppc601_cost; | |
1507 | break; | |
1508 | ||
1509 | case PROCESSOR_PPC603: | |
1510 | rs6000_cost = &ppc603_cost; | |
1511 | break; | |
1512 | ||
1513 | case PROCESSOR_PPC604: | |
1514 | rs6000_cost = &ppc604_cost; | |
1515 | break; | |
1516 | ||
1517 | case PROCESSOR_PPC604e: | |
1518 | rs6000_cost = &ppc604e_cost; | |
1519 | break; | |
1520 | ||
1521 | case PROCESSOR_PPC620: | |
8b897cfa RS |
1522 | rs6000_cost = &ppc620_cost; |
1523 | break; | |
1524 | ||
f0517163 RS |
1525 | case PROCESSOR_PPC630: |
1526 | rs6000_cost = &ppc630_cost; | |
1527 | break; | |
1528 | ||
8b897cfa RS |
1529 | case PROCESSOR_PPC750: |
1530 | case PROCESSOR_PPC7400: | |
1531 | rs6000_cost = &ppc750_cost; | |
1532 | break; | |
1533 | ||
1534 | case PROCESSOR_PPC7450: | |
1535 | rs6000_cost = &ppc7450_cost; | |
1536 | break; | |
1537 | ||
1538 | case PROCESSOR_PPC8540: | |
1539 | rs6000_cost = &ppc8540_cost; | |
1540 | break; | |
1541 | ||
1542 | case PROCESSOR_POWER4: | |
1543 | case PROCESSOR_POWER5: | |
1544 | rs6000_cost = &power4_cost; | |
1545 | break; | |
1546 | ||
1547 | default: | |
1548 | abort (); | |
1549 | } | |
5248c961 | 1550 | } |
5accd822 | 1551 | |
7ccf35ed DN |
1552 | /* Implement targetm.vectorize.builtin_mask_for_load. */ |
1553 | static tree | |
1554 | rs6000_builtin_mask_for_load (void) | |
1555 | { | |
1556 | if (TARGET_ALTIVEC) | |
1557 | return altivec_builtin_mask_for_load; | |
1558 | else | |
1559 | return 0; | |
1560 | } | |
1561 | ||
1562 | /* Implement targetm.vectorize.builtin_mask_for_store. */ | |
1563 | static tree | |
1564 | rs6000_builtin_mask_for_store (void) | |
1565 | { | |
1566 | if (TARGET_ALTIVEC) | |
1567 | return altivec_builtin_mask_for_store; | |
1568 | else | |
1569 | return 0; | |
1570 | } | |
1571 | ||
5da702b1 AH |
1572 | /* Handle generic options of the form -mfoo=yes/no. |
1573 | NAME is the option name. | |
1574 | VALUE is the option value. | |
1575 | FLAG is the pointer to the flag where to store a 1 or 0, depending on | |
1576 | whether the option value is 'yes' or 'no' respectively. */ | |
993f19a8 | 1577 | static void |
5da702b1 | 1578 | rs6000_parse_yes_no_option (const char *name, const char *value, int *flag) |
993f19a8 | 1579 | { |
5da702b1 | 1580 | if (value == 0) |
993f19a8 | 1581 | return; |
5da702b1 AH |
1582 | else if (!strcmp (value, "yes")) |
1583 | *flag = 1; | |
1584 | else if (!strcmp (value, "no")) | |
1585 | *flag = 0; | |
08b57fb3 | 1586 | else |
5da702b1 | 1587 | error ("unknown -m%s= option specified: '%s'", name, value); |
08b57fb3 AH |
1588 | } |
1589 | ||
0ac081f6 | 1590 | /* Handle -mabi= options. */ |
00b960c7 | 1591 | static void |
863d938c | 1592 | rs6000_parse_abi_options (void) |
0ac081f6 AH |
1593 | { |
1594 | if (rs6000_abi_string == 0) | |
1595 | return; | |
1596 | else if (! strcmp (rs6000_abi_string, "altivec")) | |
5cc73f91 AH |
1597 | { |
1598 | rs6000_altivec_abi = 1; | |
1599 | rs6000_spe_abi = 0; | |
1600 | } | |
76a773f3 AH |
1601 | else if (! strcmp (rs6000_abi_string, "no-altivec")) |
1602 | rs6000_altivec_abi = 0; | |
a3170dc6 | 1603 | else if (! strcmp (rs6000_abi_string, "spe")) |
01f4962d NS |
1604 | { |
1605 | rs6000_spe_abi = 1; | |
5cc73f91 | 1606 | rs6000_altivec_abi = 0; |
01f4962d NS |
1607 | if (!TARGET_SPE_ABI) |
1608 | error ("not configured for ABI: '%s'", rs6000_abi_string); | |
1609 | } | |
f676971a | 1610 | |
a3170dc6 AH |
1611 | else if (! strcmp (rs6000_abi_string, "no-spe")) |
1612 | rs6000_spe_abi = 0; | |
0ac081f6 | 1613 | else |
c725bd79 | 1614 | error ("unknown ABI specified: '%s'", rs6000_abi_string); |
0ac081f6 AH |
1615 | } |
1616 | ||
025d9908 KH |
1617 | /* Handle -malign-XXXXXX options. */ |
1618 | static void | |
863d938c | 1619 | rs6000_parse_alignment_option (void) |
025d9908 | 1620 | { |
b20a9cca AM |
1621 | if (rs6000_alignment_string == 0) |
1622 | return; | |
1623 | else if (! strcmp (rs6000_alignment_string, "power")) | |
025d9908 KH |
1624 | rs6000_alignment_flags = MASK_ALIGN_POWER; |
1625 | else if (! strcmp (rs6000_alignment_string, "natural")) | |
1626 | rs6000_alignment_flags = MASK_ALIGN_NATURAL; | |
1627 | else | |
1628 | error ("unknown -malign-XXXXX option specified: '%s'", | |
1629 | rs6000_alignment_string); | |
1630 | } | |
1631 | ||
c4501e62 JJ |
1632 | /* Validate and record the size specified with the -mtls-size option. */ |
1633 | ||
1634 | static void | |
863d938c | 1635 | rs6000_parse_tls_size_option (void) |
c4501e62 JJ |
1636 | { |
1637 | if (rs6000_tls_size_string == 0) | |
1638 | return; | |
1639 | else if (strcmp (rs6000_tls_size_string, "16") == 0) | |
1640 | rs6000_tls_size = 16; | |
1641 | else if (strcmp (rs6000_tls_size_string, "32") == 0) | |
1642 | rs6000_tls_size = 32; | |
1643 | else if (strcmp (rs6000_tls_size_string, "64") == 0) | |
1644 | rs6000_tls_size = 64; | |
1645 | else | |
1646 | error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string); | |
1647 | } | |
1648 | ||
5accd822 | 1649 | void |
a2369ed3 | 1650 | optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED) |
5accd822 | 1651 | { |
5accd822 | 1652 | } |
3cfa4909 MM |
1653 | \f |
1654 | /* Do anything needed at the start of the asm file. */ | |
1655 | ||
1bc7c5b6 | 1656 | static void |
863d938c | 1657 | rs6000_file_start (void) |
3cfa4909 | 1658 | { |
c4d38ccb | 1659 | size_t i; |
3cfa4909 | 1660 | char buffer[80]; |
d330fd93 | 1661 | const char *start = buffer; |
3cfa4909 | 1662 | struct rs6000_cpu_select *ptr; |
1bc7c5b6 ZW |
1663 | const char *default_cpu = TARGET_CPU_DEFAULT; |
1664 | FILE *file = asm_out_file; | |
1665 | ||
1666 | default_file_start (); | |
1667 | ||
1668 | #ifdef TARGET_BI_ARCH | |
1669 | if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT) | |
1670 | default_cpu = 0; | |
1671 | #endif | |
3cfa4909 MM |
1672 | |
1673 | if (flag_verbose_asm) | |
1674 | { | |
1675 | sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START); | |
1676 | rs6000_select[0].string = default_cpu; | |
1677 | ||
b6a1cbae | 1678 | for (i = 0; i < ARRAY_SIZE (rs6000_select); i++) |
3cfa4909 MM |
1679 | { |
1680 | ptr = &rs6000_select[i]; | |
1681 | if (ptr->string != (char *)0 && ptr->string[0] != '\0') | |
1682 | { | |
1683 | fprintf (file, "%s %s%s", start, ptr->name, ptr->string); | |
1684 | start = ""; | |
1685 | } | |
1686 | } | |
1687 | ||
b91da81f | 1688 | #ifdef USING_ELFOS_H |
3cfa4909 MM |
1689 | switch (rs6000_sdata) |
1690 | { | |
1691 | case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break; | |
1692 | case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break; | |
1693 | case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break; | |
1694 | case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break; | |
1695 | } | |
1696 | ||
1697 | if (rs6000_sdata && g_switch_value) | |
1698 | { | |
307b599c MK |
1699 | fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start, |
1700 | g_switch_value); | |
3cfa4909 MM |
1701 | start = ""; |
1702 | } | |
1703 | #endif | |
1704 | ||
1705 | if (*start == '\0') | |
949ea356 | 1706 | putc ('\n', file); |
3cfa4909 MM |
1707 | } |
1708 | } | |
5248c961 | 1709 | \f |
a0ab749a | 1710 | /* Return nonzero if this function is known to have a null epilogue. */ |
9878760c RK |
1711 | |
1712 | int | |
863d938c | 1713 | direct_return (void) |
9878760c | 1714 | { |
4697a36c MM |
1715 | if (reload_completed) |
1716 | { | |
1717 | rs6000_stack_t *info = rs6000_stack_info (); | |
1718 | ||
1719 | if (info->first_gp_reg_save == 32 | |
1720 | && info->first_fp_reg_save == 64 | |
00b960c7 | 1721 | && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1 |
c81fc13e DE |
1722 | && ! info->lr_save_p |
1723 | && ! info->cr_save_p | |
00b960c7 | 1724 | && info->vrsave_mask == 0 |
c81fc13e | 1725 | && ! info->push_p) |
4697a36c MM |
1726 | return 1; |
1727 | } | |
1728 | ||
1729 | return 0; | |
9878760c RK |
1730 | } |
1731 | ||
1732 | /* Returns 1 always. */ | |
1733 | ||
1734 | int | |
f676971a | 1735 | any_operand (rtx op ATTRIBUTE_UNUSED, |
a2369ed3 | 1736 | enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
1737 | { |
1738 | return 1; | |
1739 | } | |
1740 | ||
85d346f1 DE |
1741 | /* Returns 1 always. */ |
1742 | ||
1743 | int | |
f676971a | 1744 | any_parallel_operand (rtx op ATTRIBUTE_UNUSED, |
85d346f1 DE |
1745 | enum machine_mode mode ATTRIBUTE_UNUSED) |
1746 | { | |
1747 | return 1; | |
1748 | } | |
1749 | ||
a4f6c312 | 1750 | /* Returns 1 if op is the count register. */ |
85d346f1 | 1751 | |
38c1f2d7 | 1752 | int |
a2369ed3 | 1753 | count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
b6c9286a MM |
1754 | { |
1755 | if (GET_CODE (op) != REG) | |
1756 | return 0; | |
1757 | ||
1758 | if (REGNO (op) == COUNT_REGISTER_REGNUM) | |
1759 | return 1; | |
1760 | ||
1761 | if (REGNO (op) > FIRST_PSEUDO_REGISTER) | |
1762 | return 1; | |
1763 | ||
1764 | return 0; | |
1765 | } | |
1766 | ||
0ec4e2a8 | 1767 | /* Returns 1 if op is an altivec register. */ |
85d346f1 | 1768 | |
0ec4e2a8 | 1769 | int |
a2369ed3 | 1770 | altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ec4e2a8 | 1771 | { |
f676971a | 1772 | |
0ec4e2a8 AH |
1773 | return (register_operand (op, mode) |
1774 | && (GET_CODE (op) != REG | |
1775 | || REGNO (op) > FIRST_PSEUDO_REGISTER | |
1776 | || ALTIVEC_REGNO_P (REGNO (op)))); | |
1777 | } | |
1778 | ||
38c1f2d7 | 1779 | int |
a2369ed3 | 1780 | xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
802a0058 MM |
1781 | { |
1782 | if (GET_CODE (op) != REG) | |
1783 | return 0; | |
1784 | ||
9ebbca7d | 1785 | if (XER_REGNO_P (REGNO (op))) |
802a0058 MM |
1786 | return 1; |
1787 | ||
802a0058 MM |
1788 | return 0; |
1789 | } | |
1790 | ||
c859cda6 | 1791 | /* Return 1 if OP is a signed 8-bit constant. Int multiplication |
6f317ef3 | 1792 | by such constants completes more quickly. */ |
c859cda6 DJ |
1793 | |
1794 | int | |
a2369ed3 | 1795 | s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
c859cda6 DJ |
1796 | { |
1797 | return ( GET_CODE (op) == CONST_INT | |
1798 | && (INTVAL (op) >= -128 && INTVAL (op) <= 127)); | |
1799 | } | |
1800 | ||
9878760c RK |
1801 | /* Return 1 if OP is a constant that can fit in a D field. */ |
1802 | ||
1803 | int | |
a2369ed3 | 1804 | short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1805 | { |
5f59ecb7 DE |
1806 | return (GET_CODE (op) == CONST_INT |
1807 | && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')); | |
9878760c RK |
1808 | } |
1809 | ||
5519a4f9 | 1810 | /* Similar for an unsigned D field. */ |
9878760c RK |
1811 | |
1812 | int | |
a2369ed3 | 1813 | u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 1814 | { |
19684119 | 1815 | return (GET_CODE (op) == CONST_INT |
c1f11548 | 1816 | && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K')); |
9878760c RK |
1817 | } |
1818 | ||
dcfedcd0 RK |
1819 | /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */ |
1820 | ||
1821 | int | |
a2369ed3 | 1822 | non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
1823 | { |
1824 | return (GET_CODE (op) == CONST_INT | |
a7653a2c | 1825 | && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000); |
dcfedcd0 RK |
1826 | } |
1827 | ||
2bfcf297 DB |
1828 | /* Returns 1 if OP is a CONST_INT that is a positive value |
1829 | and an exact power of 2. */ | |
1830 | ||
1831 | int | |
a2369ed3 | 1832 | exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2bfcf297 DB |
1833 | { |
1834 | return (GET_CODE (op) == CONST_INT | |
1835 | && INTVAL (op) > 0 | |
1836 | && exact_log2 (INTVAL (op)) >= 0); | |
1837 | } | |
1838 | ||
9878760c RK |
1839 | /* Returns 1 if OP is a register that is not special (i.e., not MQ, |
1840 | ctr, or lr). */ | |
1841 | ||
1842 | int | |
a2369ed3 | 1843 | gpc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1844 | { |
1845 | return (register_operand (op, mode) | |
802a0058 | 1846 | && (GET_CODE (op) != REG |
f676971a | 1847 | || (REGNO (op) >= ARG_POINTER_REGNUM |
9ebbca7d GK |
1848 | && !XER_REGNO_P (REGNO (op))) |
1849 | || REGNO (op) < MQ_REGNO)); | |
9878760c RK |
1850 | } |
1851 | ||
1852 | /* Returns 1 if OP is either a pseudo-register or a register denoting a | |
1853 | CR field. */ | |
1854 | ||
1855 | int | |
a2369ed3 | 1856 | cc_reg_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1857 | { |
1858 | return (register_operand (op, mode) | |
1859 | && (GET_CODE (op) != REG | |
1860 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1861 | || CR_REGNO_P (REGNO (op)))); | |
1862 | } | |
1863 | ||
815cdc52 MM |
1864 | /* Returns 1 if OP is either a pseudo-register or a register denoting a |
1865 | CR field that isn't CR0. */ | |
1866 | ||
1867 | int | |
a2369ed3 | 1868 | cc_reg_not_cr0_operand (rtx op, enum machine_mode mode) |
815cdc52 MM |
1869 | { |
1870 | return (register_operand (op, mode) | |
1871 | && (GET_CODE (op) != REG | |
1872 | || REGNO (op) >= FIRST_PSEUDO_REGISTER | |
1873 | || CR_REGNO_NOT_CR0_P (REGNO (op)))); | |
1874 | } | |
1875 | ||
a4f6c312 SS |
1876 | /* Returns 1 if OP is either a constant integer valid for a D-field or |
1877 | a non-special register. If a register, it must be in the proper | |
1878 | mode unless MODE is VOIDmode. */ | |
9878760c RK |
1879 | |
1880 | int | |
a2369ed3 | 1881 | reg_or_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1882 | { |
f5a28898 | 1883 | return short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1884 | } |
1885 | ||
a4f6c312 | 1886 | /* Similar, except check if the negation of the constant would be |
42f806e5 AM |
1887 | valid for a D-field. Don't allow a constant zero, since all the |
1888 | patterns that call this predicate use "addic r1,r2,-constant" on | |
1889 | a constant value to set a carry when r2 is greater or equal to | |
1890 | "constant". That doesn't work for zero. */ | |
9878760c RK |
1891 | |
1892 | int | |
a2369ed3 | 1893 | reg_or_neg_short_operand (rtx op, enum machine_mode mode) |
9878760c RK |
1894 | { |
1895 | if (GET_CODE (op) == CONST_INT) | |
42f806e5 | 1896 | return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0; |
9878760c | 1897 | |
cd2b37d9 | 1898 | return gpc_reg_operand (op, mode); |
9878760c RK |
1899 | } |
1900 | ||
768070a0 TR |
1901 | /* Returns 1 if OP is either a constant integer valid for a DS-field or |
1902 | a non-special register. If a register, it must be in the proper | |
1903 | mode unless MODE is VOIDmode. */ | |
1904 | ||
1905 | int | |
a2369ed3 | 1906 | reg_or_aligned_short_operand (rtx op, enum machine_mode mode) |
768070a0 TR |
1907 | { |
1908 | if (gpc_reg_operand (op, mode)) | |
1909 | return 1; | |
1910 | else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3)) | |
1911 | return 1; | |
1912 | ||
1913 | return 0; | |
1914 | } | |
1915 | ||
1916 | ||
a4f6c312 SS |
1917 | /* Return 1 if the operand is either a register or an integer whose |
1918 | high-order 16 bits are zero. */ | |
9878760c RK |
1919 | |
1920 | int | |
a2369ed3 | 1921 | reg_or_u_short_operand (rtx op, enum machine_mode mode) |
9878760c | 1922 | { |
e675f625 | 1923 | return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode); |
9878760c RK |
1924 | } |
1925 | ||
1926 | /* Return 1 is the operand is either a non-special register or ANY | |
1927 | constant integer. */ | |
1928 | ||
1929 | int | |
a2369ed3 | 1930 | reg_or_cint_operand (rtx op, enum machine_mode mode) |
9878760c | 1931 | { |
a4f6c312 | 1932 | return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode)); |
f6bf7de2 DE |
1933 | } |
1934 | ||
1935 | /* Return 1 is the operand is either a non-special register or ANY | |
1936 | 32-bit signed constant integer. */ | |
1937 | ||
1938 | int | |
a2369ed3 | 1939 | reg_or_arith_cint_operand (rtx op, enum machine_mode mode) |
f6bf7de2 | 1940 | { |
a4f6c312 SS |
1941 | return (gpc_reg_operand (op, mode) |
1942 | || (GET_CODE (op) == CONST_INT | |
f6bf7de2 | 1943 | #if HOST_BITS_PER_WIDE_INT != 32 |
a4f6c312 SS |
1944 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000) |
1945 | < (unsigned HOST_WIDE_INT) 0x100000000ll) | |
f6bf7de2 | 1946 | #endif |
a4f6c312 | 1947 | )); |
9878760c RK |
1948 | } |
1949 | ||
2bfcf297 DB |
1950 | /* Return 1 is the operand is either a non-special register or a 32-bit |
1951 | signed constant integer valid for 64-bit addition. */ | |
1952 | ||
1953 | int | |
a2369ed3 | 1954 | reg_or_add_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1955 | { |
a4f6c312 SS |
1956 | return (gpc_reg_operand (op, mode) |
1957 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1958 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1959 | && INTVAL (op) < 0x7fff8000 |
a65c591c | 1960 | #else |
a4f6c312 SS |
1961 | && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000) |
1962 | < 0x100000000ll) | |
2bfcf297 | 1963 | #endif |
a4f6c312 | 1964 | )); |
2bfcf297 DB |
1965 | } |
1966 | ||
1967 | /* Return 1 is the operand is either a non-special register or a 32-bit | |
1968 | signed constant integer valid for 64-bit subtraction. */ | |
1969 | ||
1970 | int | |
a2369ed3 | 1971 | reg_or_sub_cint64_operand (rtx op, enum machine_mode mode) |
2bfcf297 | 1972 | { |
a4f6c312 SS |
1973 | return (gpc_reg_operand (op, mode) |
1974 | || (GET_CODE (op) == CONST_INT | |
a65c591c | 1975 | #if HOST_BITS_PER_WIDE_INT == 32 |
a4f6c312 | 1976 | && (- INTVAL (op)) < 0x7fff8000 |
a65c591c | 1977 | #else |
a4f6c312 SS |
1978 | && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000) |
1979 | < 0x100000000ll) | |
2bfcf297 | 1980 | #endif |
a4f6c312 | 1981 | )); |
2bfcf297 DB |
1982 | } |
1983 | ||
9ebbca7d GK |
1984 | /* Return 1 is the operand is either a non-special register or ANY |
1985 | 32-bit unsigned constant integer. */ | |
1986 | ||
1987 | int | |
a2369ed3 | 1988 | reg_or_logical_cint_operand (rtx op, enum machine_mode mode) |
9ebbca7d | 1989 | { |
1d328b19 GK |
1990 | if (GET_CODE (op) == CONST_INT) |
1991 | { | |
1992 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT) | |
1993 | { | |
1994 | if (GET_MODE_BITSIZE (mode) <= 32) | |
a4f6c312 | 1995 | abort (); |
1d328b19 GK |
1996 | |
1997 | if (INTVAL (op) < 0) | |
1998 | return 0; | |
1999 | } | |
2000 | ||
2001 | return ((INTVAL (op) & GET_MODE_MASK (mode) | |
0858c623 | 2002 | & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0); |
1d328b19 GK |
2003 | } |
2004 | else if (GET_CODE (op) == CONST_DOUBLE) | |
2005 | { | |
2006 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT | |
2007 | || mode != DImode) | |
a4f6c312 | 2008 | abort (); |
1d328b19 GK |
2009 | |
2010 | return CONST_DOUBLE_HIGH (op) == 0; | |
2011 | } | |
f676971a | 2012 | else |
1d328b19 | 2013 | return gpc_reg_operand (op, mode); |
9ebbca7d GK |
2014 | } |
2015 | ||
51d3e7d6 | 2016 | /* Return 1 if the operand is an operand that can be loaded via the GOT. */ |
766a866c MM |
2017 | |
2018 | int | |
a2369ed3 | 2019 | got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
766a866c MM |
2020 | { |
2021 | return (GET_CODE (op) == SYMBOL_REF | |
2022 | || GET_CODE (op) == CONST | |
2023 | || GET_CODE (op) == LABEL_REF); | |
2024 | } | |
2025 | ||
38c1f2d7 MM |
2026 | /* Return 1 if the operand is a simple references that can be loaded via |
2027 | the GOT (labels involving addition aren't allowed). */ | |
2028 | ||
2029 | int | |
a2369ed3 | 2030 | got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
38c1f2d7 MM |
2031 | { |
2032 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF); | |
2033 | } | |
2034 | ||
4e74d8ec MM |
2035 | /* Return the number of instructions it takes to form a constant in an |
2036 | integer register. */ | |
2037 | ||
2038 | static int | |
a2369ed3 | 2039 | num_insns_constant_wide (HOST_WIDE_INT value) |
4e74d8ec MM |
2040 | { |
2041 | /* signed constant loadable with {cal|addi} */ | |
5f59ecb7 | 2042 | if (CONST_OK_FOR_LETTER_P (value, 'I')) |
0865c631 GK |
2043 | return 1; |
2044 | ||
4e74d8ec | 2045 | /* constant loadable with {cau|addis} */ |
5f59ecb7 | 2046 | else if (CONST_OK_FOR_LETTER_P (value, 'L')) |
4e74d8ec MM |
2047 | return 1; |
2048 | ||
5f59ecb7 | 2049 | #if HOST_BITS_PER_WIDE_INT == 64 |
c81fc13e | 2050 | else if (TARGET_POWERPC64) |
4e74d8ec | 2051 | { |
a65c591c DE |
2052 | HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000; |
2053 | HOST_WIDE_INT high = value >> 31; | |
4e74d8ec | 2054 | |
a65c591c | 2055 | if (high == 0 || high == -1) |
4e74d8ec MM |
2056 | return 2; |
2057 | ||
a65c591c | 2058 | high >>= 1; |
4e74d8ec | 2059 | |
a65c591c | 2060 | if (low == 0) |
4e74d8ec | 2061 | return num_insns_constant_wide (high) + 1; |
4e74d8ec MM |
2062 | else |
2063 | return (num_insns_constant_wide (high) | |
e396202a | 2064 | + num_insns_constant_wide (low) + 1); |
4e74d8ec MM |
2065 | } |
2066 | #endif | |
2067 | ||
2068 | else | |
2069 | return 2; | |
2070 | } | |
2071 | ||
2072 | int | |
a2369ed3 | 2073 | num_insns_constant (rtx op, enum machine_mode mode) |
4e74d8ec | 2074 | { |
4e74d8ec | 2075 | if (GET_CODE (op) == CONST_INT) |
0d30d435 DE |
2076 | { |
2077 | #if HOST_BITS_PER_WIDE_INT == 64 | |
4e2c1c44 DE |
2078 | if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1 |
2079 | && mask64_operand (op, mode)) | |
0d30d435 DE |
2080 | return 2; |
2081 | else | |
2082 | #endif | |
2083 | return num_insns_constant_wide (INTVAL (op)); | |
2084 | } | |
4e74d8ec | 2085 | |
6fc48950 MM |
2086 | else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode) |
2087 | { | |
2088 | long l; | |
2089 | REAL_VALUE_TYPE rv; | |
2090 | ||
2091 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
2092 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
e72247f4 | 2093 | return num_insns_constant_wide ((HOST_WIDE_INT) l); |
6fc48950 MM |
2094 | } |
2095 | ||
47ad8c61 | 2096 | else if (GET_CODE (op) == CONST_DOUBLE) |
4e74d8ec | 2097 | { |
47ad8c61 MM |
2098 | HOST_WIDE_INT low; |
2099 | HOST_WIDE_INT high; | |
2100 | long l[2]; | |
2101 | REAL_VALUE_TYPE rv; | |
2102 | int endian = (WORDS_BIG_ENDIAN == 0); | |
4e74d8ec | 2103 | |
47ad8c61 MM |
2104 | if (mode == VOIDmode || mode == DImode) |
2105 | { | |
2106 | high = CONST_DOUBLE_HIGH (op); | |
2107 | low = CONST_DOUBLE_LOW (op); | |
2108 | } | |
2109 | else | |
2110 | { | |
2111 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
2112 | REAL_VALUE_TO_TARGET_DOUBLE (rv, l); | |
2113 | high = l[endian]; | |
2114 | low = l[1 - endian]; | |
2115 | } | |
4e74d8ec | 2116 | |
47ad8c61 MM |
2117 | if (TARGET_32BIT) |
2118 | return (num_insns_constant_wide (low) | |
2119 | + num_insns_constant_wide (high)); | |
4e74d8ec MM |
2120 | |
2121 | else | |
47ad8c61 | 2122 | { |
e72247f4 | 2123 | if (high == 0 && low >= 0) |
47ad8c61 MM |
2124 | return num_insns_constant_wide (low); |
2125 | ||
e72247f4 | 2126 | else if (high == -1 && low < 0) |
47ad8c61 MM |
2127 | return num_insns_constant_wide (low); |
2128 | ||
a260abc9 DE |
2129 | else if (mask64_operand (op, mode)) |
2130 | return 2; | |
2131 | ||
47ad8c61 MM |
2132 | else if (low == 0) |
2133 | return num_insns_constant_wide (high) + 1; | |
2134 | ||
2135 | else | |
2136 | return (num_insns_constant_wide (high) | |
2137 | + num_insns_constant_wide (low) + 1); | |
2138 | } | |
4e74d8ec MM |
2139 | } |
2140 | ||
2141 | else | |
2142 | abort (); | |
2143 | } | |
2144 | ||
a4f6c312 SS |
2145 | /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a |
2146 | register with one instruction per word. We only do this if we can | |
2147 | safely read CONST_DOUBLE_{LOW,HIGH}. */ | |
9878760c RK |
2148 | |
2149 | int | |
a2369ed3 | 2150 | easy_fp_constant (rtx op, enum machine_mode mode) |
9878760c | 2151 | { |
9878760c RK |
2152 | if (GET_CODE (op) != CONST_DOUBLE |
2153 | || GET_MODE (op) != mode | |
4e74d8ec | 2154 | || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode)) |
9878760c RK |
2155 | return 0; |
2156 | ||
a4f6c312 | 2157 | /* Consider all constants with -msoft-float to be easy. */ |
a3170dc6 AH |
2158 | if ((TARGET_SOFT_FLOAT || !TARGET_FPRS) |
2159 | && mode != DImode) | |
b6c9286a MM |
2160 | return 1; |
2161 | ||
a4f6c312 | 2162 | /* If we are using V.4 style PIC, consider all constants to be hard. */ |
f607bc57 | 2163 | if (flag_pic && DEFAULT_ABI == ABI_V4) |
a7273471 MM |
2164 | return 0; |
2165 | ||
5ae4759c | 2166 | #ifdef TARGET_RELOCATABLE |
a4f6c312 SS |
2167 | /* Similarly if we are using -mrelocatable, consider all constants |
2168 | to be hard. */ | |
5ae4759c MM |
2169 | if (TARGET_RELOCATABLE) |
2170 | return 0; | |
2171 | #endif | |
2172 | ||
fcce224d DE |
2173 | if (mode == TFmode) |
2174 | { | |
2175 | long k[4]; | |
2176 | REAL_VALUE_TYPE rv; | |
2177 | ||
2178 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
2179 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
2180 | ||
2181 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 | |
2182 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1 | |
2183 | && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1 | |
2184 | && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1); | |
2185 | } | |
2186 | ||
2187 | else if (mode == DFmode) | |
042259f2 DE |
2188 | { |
2189 | long k[2]; | |
2190 | REAL_VALUE_TYPE rv; | |
2191 | ||
2192 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
2193 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
9878760c | 2194 | |
a65c591c DE |
2195 | return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1 |
2196 | && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1); | |
042259f2 | 2197 | } |
4e74d8ec MM |
2198 | |
2199 | else if (mode == SFmode) | |
042259f2 DE |
2200 | { |
2201 | long l; | |
2202 | REAL_VALUE_TYPE rv; | |
2203 | ||
2204 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
2205 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
9878760c | 2206 | |
4e74d8ec | 2207 | return num_insns_constant_wide (l) == 1; |
042259f2 | 2208 | } |
4e74d8ec | 2209 | |
a260abc9 | 2210 | else if (mode == DImode) |
c81fc13e | 2211 | return ((TARGET_POWERPC64 |
a260abc9 DE |
2212 | && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0) |
2213 | || (num_insns_constant (op, DImode) <= 2)); | |
4e74d8ec | 2214 | |
a9098fd0 GK |
2215 | else if (mode == SImode) |
2216 | return 1; | |
4e74d8ec MM |
2217 | else |
2218 | abort (); | |
9878760c | 2219 | } |
8f75773e | 2220 | |
effa5d5d | 2221 | /* Returns the constant for the splat instruction, if exists. */ |
452a7d36 HP |
2222 | |
2223 | static int | |
2224 | easy_vector_splat_const (int cst, enum machine_mode mode) | |
2225 | { | |
f676971a | 2226 | switch (mode) |
452a7d36 HP |
2227 | { |
2228 | case V4SImode: | |
f676971a EC |
2229 | if (EASY_VECTOR_15 (cst) |
2230 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
452a7d36 HP |
2231 | return cst; |
2232 | if ((cst & 0xffff) != ((cst >> 16) & 0xffff)) | |
2233 | break; | |
2234 | cst = cst >> 16; | |
2235 | case V8HImode: | |
f676971a EC |
2236 | if (EASY_VECTOR_15 (cst) |
2237 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
452a7d36 HP |
2238 | return cst; |
2239 | if ((cst & 0xff) != ((cst >> 8) & 0xff)) | |
2240 | break; | |
2241 | cst = cst >> 8; | |
2242 | case V16QImode: | |
f676971a EC |
2243 | if (EASY_VECTOR_15 (cst) |
2244 | || EASY_VECTOR_15_ADD_SELF (cst)) | |
452a7d36 | 2245 | return cst; |
f676971a | 2246 | default: |
452a7d36 HP |
2247 | break; |
2248 | } | |
2249 | return 0; | |
2250 | } | |
2251 | ||
2252 | ||
72ac76be | 2253 | /* Return nonzero if all elements of a vector have the same value. */ |
69ef87e2 AH |
2254 | |
2255 | static int | |
a2369ed3 | 2256 | easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
d744e06e AH |
2257 | { |
2258 | int units, i, cst; | |
2259 | ||
2260 | units = CONST_VECTOR_NUNITS (op); | |
2261 | ||
2262 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); | |
2263 | for (i = 1; i < units; ++i) | |
2264 | if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst) | |
2265 | break; | |
452a7d36 | 2266 | if (i == units && easy_vector_splat_const (cst, mode)) |
d744e06e AH |
2267 | return 1; |
2268 | return 0; | |
2269 | } | |
2270 | ||
2271 | /* Return 1 if the operand is a CONST_INT and can be put into a | |
2272 | register without using memory. */ | |
2273 | ||
2274 | int | |
a2369ed3 | 2275 | easy_vector_constant (rtx op, enum machine_mode mode) |
69ef87e2 | 2276 | { |
d744e06e | 2277 | int cst, cst2; |
69ef87e2 | 2278 | |
d744e06e AH |
2279 | if (GET_CODE (op) != CONST_VECTOR |
2280 | || (!TARGET_ALTIVEC | |
2281 | && !TARGET_SPE)) | |
69ef87e2 AH |
2282 | return 0; |
2283 | ||
d744e06e AH |
2284 | if (zero_constant (op, mode) |
2285 | && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode)) | |
2286 | || (TARGET_SPE && SPE_VECTOR_MODE (mode)))) | |
2287 | return 1; | |
69ef87e2 | 2288 | |
d744e06e AH |
2289 | if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT) |
2290 | return 0; | |
2291 | ||
f5119d10 AH |
2292 | if (TARGET_SPE && mode == V1DImode) |
2293 | return 0; | |
2294 | ||
d744e06e AH |
2295 | cst = INTVAL (CONST_VECTOR_ELT (op, 0)); |
2296 | cst2 = INTVAL (CONST_VECTOR_ELT (op, 1)); | |
2297 | ||
2298 | /* Limit SPE vectors to 15 bits signed. These we can generate with: | |
2299 | li r0, CONSTANT1 | |
2300 | evmergelo r0, r0, r0 | |
2301 | li r0, CONSTANT2 | |
2302 | ||
2303 | I don't know how efficient it would be to allow bigger constants, | |
2304 | considering we'll have an extra 'ori' for every 'li'. I doubt 5 | |
2305 | instructions is better than a 64-bit memory load, but I don't | |
2306 | have the e500 timing specs. */ | |
2307 | if (TARGET_SPE && mode == V2SImode | |
2308 | && cst >= -0x7fff && cst <= 0x7fff | |
f5119d10 | 2309 | && cst2 >= -0x7fff && cst2 <= 0x7fff) |
d744e06e AH |
2310 | return 1; |
2311 | ||
f676971a | 2312 | if (TARGET_ALTIVEC |
452a7d36 HP |
2313 | && easy_vector_same (op, mode)) |
2314 | { | |
2315 | cst = easy_vector_splat_const (cst, mode); | |
f676971a | 2316 | if (EASY_VECTOR_15_ADD_SELF (cst) |
452a7d36 HP |
2317 | || EASY_VECTOR_15 (cst)) |
2318 | return 1; | |
f676971a | 2319 | } |
d744e06e AH |
2320 | return 0; |
2321 | } | |
2322 | ||
2323 | /* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */ | |
2324 | ||
2325 | int | |
a2369ed3 | 2326 | easy_vector_constant_add_self (rtx op, enum machine_mode mode) |
d744e06e AH |
2327 | { |
2328 | int cst; | |
452a7d36 HP |
2329 | if (TARGET_ALTIVEC |
2330 | && GET_CODE (op) == CONST_VECTOR | |
2331 | && easy_vector_same (op, mode)) | |
2332 | { | |
2333 | cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode); | |
2334 | if (EASY_VECTOR_15_ADD_SELF (cst)) | |
f676971a | 2335 | return 1; |
452a7d36 HP |
2336 | } |
2337 | return 0; | |
2338 | } | |
d744e06e | 2339 | |
452a7d36 | 2340 | /* Generate easy_vector_constant out of a easy_vector_constant_add_self. */ |
d744e06e | 2341 | |
f676971a | 2342 | rtx |
452a7d36 HP |
2343 | gen_easy_vector_constant_add_self (rtx op) |
2344 | { | |
2345 | int i, units; | |
2346 | rtvec v; | |
2347 | units = GET_MODE_NUNITS (GET_MODE (op)); | |
2348 | v = rtvec_alloc (units); | |
2349 | ||
2350 | for (i = 0; i < units; i++) | |
f676971a | 2351 | RTVEC_ELT (v, i) = |
452a7d36 HP |
2352 | GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1); |
2353 | return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v); | |
d744e06e AH |
2354 | } |
2355 | ||
2356 | const char * | |
a2369ed3 | 2357 | output_vec_const_move (rtx *operands) |
d744e06e AH |
2358 | { |
2359 | int cst, cst2; | |
2360 | enum machine_mode mode; | |
2361 | rtx dest, vec; | |
2362 | ||
2363 | dest = operands[0]; | |
2364 | vec = operands[1]; | |
69ef87e2 | 2365 | |
d744e06e AH |
2366 | cst = INTVAL (CONST_VECTOR_ELT (vec, 0)); |
2367 | cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1)); | |
2368 | mode = GET_MODE (dest); | |
69ef87e2 | 2369 | |
d744e06e AH |
2370 | if (TARGET_ALTIVEC) |
2371 | { | |
2372 | if (zero_constant (vec, mode)) | |
2373 | return "vxor %0,%0,%0"; | |
ce1f50b2 | 2374 | else if (easy_vector_constant (vec, mode)) |
98ef3137 | 2375 | { |
d744e06e AH |
2376 | operands[1] = GEN_INT (cst); |
2377 | switch (mode) | |
2378 | { | |
2379 | case V4SImode: | |
452a7d36 | 2380 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
2381 | { |
2382 | operands[1] = GEN_INT (cst); | |
2383 | return "vspltisw %0,%1"; | |
2384 | } | |
452a7d36 HP |
2385 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
2386 | return "#"; | |
ce1f50b2 | 2387 | cst = cst >> 16; |
d744e06e | 2388 | case V8HImode: |
452a7d36 | 2389 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
2390 | { |
2391 | operands[1] = GEN_INT (cst); | |
2392 | return "vspltish %0,%1"; | |
2393 | } | |
452a7d36 HP |
2394 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
2395 | return "#"; | |
ce1f50b2 | 2396 | cst = cst >> 8; |
d744e06e | 2397 | case V16QImode: |
452a7d36 | 2398 | if (EASY_VECTOR_15 (cst)) |
ce1f50b2 HP |
2399 | { |
2400 | operands[1] = GEN_INT (cst); | |
2401 | return "vspltisb %0,%1"; | |
2402 | } | |
452a7d36 HP |
2403 | else if (EASY_VECTOR_15_ADD_SELF (cst)) |
2404 | return "#"; | |
d744e06e AH |
2405 | default: |
2406 | abort (); | |
2407 | } | |
98ef3137 | 2408 | } |
d744e06e AH |
2409 | else |
2410 | abort (); | |
69ef87e2 AH |
2411 | } |
2412 | ||
d744e06e AH |
2413 | if (TARGET_SPE) |
2414 | { | |
2415 | /* Vector constant 0 is handled as a splitter of V2SI, and in the | |
2416 | pattern of V1DI, V4HI, and V2SF. | |
2417 | ||
c1207243 | 2418 | FIXME: We should probably return # and add post reload |
d744e06e AH |
2419 | splitters for these, but this way is so easy ;-). |
2420 | */ | |
2421 | operands[1] = GEN_INT (cst); | |
2422 | operands[2] = GEN_INT (cst2); | |
2423 | if (cst == cst2) | |
2424 | return "li %0,%1\n\tevmergelo %0,%0,%0"; | |
2425 | else | |
2426 | return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2"; | |
2427 | } | |
2428 | ||
2429 | abort (); | |
69ef87e2 AH |
2430 | } |
2431 | ||
2432 | /* Return 1 if the operand is the constant 0. This works for scalars | |
2433 | as well as vectors. */ | |
2434 | int | |
a2369ed3 | 2435 | zero_constant (rtx op, enum machine_mode mode) |
69ef87e2 AH |
2436 | { |
2437 | return op == CONST0_RTX (mode); | |
2438 | } | |
2439 | ||
50a0b056 GK |
2440 | /* Return 1 if the operand is 0.0. */ |
2441 | int | |
a2369ed3 | 2442 | zero_fp_constant (rtx op, enum machine_mode mode) |
50a0b056 GK |
2443 | { |
2444 | return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode); | |
2445 | } | |
2446 | ||
a4f6c312 SS |
2447 | /* Return 1 if the operand is in volatile memory. Note that during |
2448 | the RTL generation phase, memory_operand does not return TRUE for | |
b6c9286a MM |
2449 | volatile memory references. So this function allows us to |
2450 | recognize volatile references where its safe. */ | |
2451 | ||
2452 | int | |
a2369ed3 | 2453 | volatile_mem_operand (rtx op, enum machine_mode mode) |
b6c9286a MM |
2454 | { |
2455 | if (GET_CODE (op) != MEM) | |
2456 | return 0; | |
2457 | ||
2458 | if (!MEM_VOLATILE_P (op)) | |
2459 | return 0; | |
2460 | ||
2461 | if (mode != GET_MODE (op)) | |
2462 | return 0; | |
2463 | ||
2464 | if (reload_completed) | |
2465 | return memory_operand (op, mode); | |
2466 | ||
2467 | if (reload_in_progress) | |
2468 | return strict_memory_address_p (mode, XEXP (op, 0)); | |
2469 | ||
2470 | return memory_address_p (mode, XEXP (op, 0)); | |
2471 | } | |
2472 | ||
97f6e72f | 2473 | /* Return 1 if the operand is an offsettable memory operand. */ |
914c2e77 RK |
2474 | |
2475 | int | |
a2369ed3 | 2476 | offsettable_mem_operand (rtx op, enum machine_mode mode) |
914c2e77 | 2477 | { |
97f6e72f | 2478 | return ((GET_CODE (op) == MEM) |
677a9668 | 2479 | && offsettable_address_p (reload_completed || reload_in_progress, |
97f6e72f | 2480 | mode, XEXP (op, 0))); |
914c2e77 RK |
2481 | } |
2482 | ||
9878760c RK |
2483 | /* Return 1 if the operand is either an easy FP constant (see above) or |
2484 | memory. */ | |
2485 | ||
2486 | int | |
a2369ed3 | 2487 | mem_or_easy_const_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2488 | { |
2489 | return memory_operand (op, mode) || easy_fp_constant (op, mode); | |
2490 | } | |
2491 | ||
2492 | /* Return 1 if the operand is either a non-special register or an item | |
5f59ecb7 | 2493 | that can be used as the operand of a `mode' add insn. */ |
9878760c RK |
2494 | |
2495 | int | |
a2369ed3 | 2496 | add_operand (rtx op, enum machine_mode mode) |
9878760c | 2497 | { |
2bfcf297 | 2498 | if (GET_CODE (op) == CONST_INT) |
e72247f4 DE |
2499 | return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
2500 | || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
2bfcf297 DB |
2501 | |
2502 | return gpc_reg_operand (op, mode); | |
9878760c RK |
2503 | } |
2504 | ||
dcfedcd0 RK |
2505 | /* Return 1 if OP is a constant but not a valid add_operand. */ |
2506 | ||
2507 | int | |
a2369ed3 | 2508 | non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dcfedcd0 RK |
2509 | { |
2510 | return (GET_CODE (op) == CONST_INT | |
e72247f4 DE |
2511 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I') |
2512 | && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L')); | |
dcfedcd0 RK |
2513 | } |
2514 | ||
9878760c RK |
2515 | /* Return 1 if the operand is a non-special register or a constant that |
2516 | can be used as the operand of an OR or XOR insn on the RS/6000. */ | |
2517 | ||
2518 | int | |
a2369ed3 | 2519 | logical_operand (rtx op, enum machine_mode mode) |
9878760c | 2520 | { |
40501e5f | 2521 | HOST_WIDE_INT opl, oph; |
1d328b19 | 2522 | |
dfbdccdb GK |
2523 | if (gpc_reg_operand (op, mode)) |
2524 | return 1; | |
1d328b19 | 2525 | |
dfbdccdb | 2526 | if (GET_CODE (op) == CONST_INT) |
40501e5f AM |
2527 | { |
2528 | opl = INTVAL (op) & GET_MODE_MASK (mode); | |
2529 | ||
2530 | #if HOST_BITS_PER_WIDE_INT <= 32 | |
2531 | if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0) | |
2532 | return 0; | |
2533 | #endif | |
2534 | } | |
dfbdccdb GK |
2535 | else if (GET_CODE (op) == CONST_DOUBLE) |
2536 | { | |
1d328b19 | 2537 | if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) |
40501e5f | 2538 | abort (); |
1d328b19 GK |
2539 | |
2540 | opl = CONST_DOUBLE_LOW (op); | |
2541 | oph = CONST_DOUBLE_HIGH (op); | |
40501e5f | 2542 | if (oph != 0) |
38886f37 | 2543 | return 0; |
dfbdccdb GK |
2544 | } |
2545 | else | |
2546 | return 0; | |
1d328b19 | 2547 | |
40501e5f AM |
2548 | return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0 |
2549 | || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0); | |
9878760c RK |
2550 | } |
2551 | ||
dcfedcd0 | 2552 | /* Return 1 if C is a constant that is not a logical operand (as |
1d328b19 | 2553 | above), but could be split into one. */ |
dcfedcd0 RK |
2554 | |
2555 | int | |
a2369ed3 | 2556 | non_logical_cint_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2557 | { |
dfbdccdb | 2558 | return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE) |
1d328b19 GK |
2559 | && ! logical_operand (op, mode) |
2560 | && reg_or_logical_cint_operand (op, mode)); | |
dcfedcd0 RK |
2561 | } |
2562 | ||
19ba8161 | 2563 | /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the |
9878760c RK |
2564 | RS/6000. It is if there are no more than two 1->0 or 0->1 transitions. |
2565 | Reject all ones and all zeros, since these should have been optimized | |
2566 | away and confuse the making of MB and ME. */ | |
2567 | ||
2568 | int | |
a2369ed3 | 2569 | mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c | 2570 | { |
02071907 | 2571 | HOST_WIDE_INT c, lsb; |
9878760c | 2572 | |
19ba8161 DE |
2573 | if (GET_CODE (op) != CONST_INT) |
2574 | return 0; | |
2575 | ||
2576 | c = INTVAL (op); | |
2577 | ||
57deb3a1 AM |
2578 | /* Fail in 64-bit mode if the mask wraps around because the upper |
2579 | 32-bits of the mask will all be 1s, contrary to GCC's internal view. */ | |
2580 | if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001) | |
2581 | return 0; | |
2582 | ||
c5059423 AM |
2583 | /* We don't change the number of transitions by inverting, |
2584 | so make sure we start with the LS bit zero. */ | |
2585 | if (c & 1) | |
2586 | c = ~c; | |
2587 | ||
2588 | /* Reject all zeros or all ones. */ | |
2589 | if (c == 0) | |
9878760c RK |
2590 | return 0; |
2591 | ||
c5059423 AM |
2592 | /* Find the first transition. */ |
2593 | lsb = c & -c; | |
2594 | ||
2595 | /* Invert to look for a second transition. */ | |
2596 | c = ~c; | |
9878760c | 2597 | |
c5059423 AM |
2598 | /* Erase first transition. */ |
2599 | c &= -lsb; | |
9878760c | 2600 | |
c5059423 AM |
2601 | /* Find the second transition (if any). */ |
2602 | lsb = c & -c; | |
2603 | ||
2604 | /* Match if all the bits above are 1's (or c is zero). */ | |
2605 | return c == -lsb; | |
9878760c RK |
2606 | } |
2607 | ||
0ba1b2ff AM |
2608 | /* Return 1 for the PowerPC64 rlwinm corner case. */ |
2609 | ||
2610 | int | |
a2369ed3 | 2611 | mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2612 | { |
2613 | HOST_WIDE_INT c, lsb; | |
2614 | ||
2615 | if (GET_CODE (op) != CONST_INT) | |
2616 | return 0; | |
2617 | ||
2618 | c = INTVAL (op); | |
2619 | ||
2620 | if ((c & 0x80000001) != 0x80000001) | |
2621 | return 0; | |
2622 | ||
2623 | c = ~c; | |
2624 | if (c == 0) | |
2625 | return 0; | |
2626 | ||
2627 | lsb = c & -c; | |
2628 | c = ~c; | |
2629 | c &= -lsb; | |
2630 | lsb = c & -c; | |
2631 | return c == -lsb; | |
2632 | } | |
2633 | ||
a260abc9 DE |
2634 | /* Return 1 if the operand is a constant that is a PowerPC64 mask. |
2635 | It is if there are no more than one 1->0 or 0->1 transitions. | |
0ba1b2ff AM |
2636 | Reject all zeros, since zero should have been optimized away and |
2637 | confuses the making of MB and ME. */ | |
9878760c RK |
2638 | |
2639 | int | |
a2369ed3 | 2640 | mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
a260abc9 DE |
2641 | { |
2642 | if (GET_CODE (op) == CONST_INT) | |
2643 | { | |
02071907 | 2644 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2645 | |
c5059423 | 2646 | c = INTVAL (op); |
a260abc9 | 2647 | |
0ba1b2ff | 2648 | /* Reject all zeros. */ |
c5059423 | 2649 | if (c == 0) |
e2c953b6 DE |
2650 | return 0; |
2651 | ||
0ba1b2ff AM |
2652 | /* We don't change the number of transitions by inverting, |
2653 | so make sure we start with the LS bit zero. */ | |
2654 | if (c & 1) | |
2655 | c = ~c; | |
2656 | ||
c5059423 AM |
2657 | /* Find the transition, and check that all bits above are 1's. */ |
2658 | lsb = c & -c; | |
e3981aab DE |
2659 | |
2660 | /* Match if all the bits above are 1's (or c is zero). */ | |
c5059423 | 2661 | return c == -lsb; |
e2c953b6 | 2662 | } |
0ba1b2ff AM |
2663 | return 0; |
2664 | } | |
2665 | ||
2666 | /* Like mask64_operand, but allow up to three transitions. This | |
2667 | predicate is used by insn patterns that generate two rldicl or | |
2668 | rldicr machine insns. */ | |
2669 | ||
2670 | int | |
a2369ed3 | 2671 | mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
0ba1b2ff AM |
2672 | { |
2673 | if (GET_CODE (op) == CONST_INT) | |
a260abc9 | 2674 | { |
0ba1b2ff | 2675 | HOST_WIDE_INT c, lsb; |
a260abc9 | 2676 | |
0ba1b2ff | 2677 | c = INTVAL (op); |
a260abc9 | 2678 | |
0ba1b2ff AM |
2679 | /* Disallow all zeros. */ |
2680 | if (c == 0) | |
2681 | return 0; | |
a260abc9 | 2682 | |
0ba1b2ff AM |
2683 | /* We don't change the number of transitions by inverting, |
2684 | so make sure we start with the LS bit zero. */ | |
2685 | if (c & 1) | |
2686 | c = ~c; | |
a260abc9 | 2687 | |
0ba1b2ff AM |
2688 | /* Find the first transition. */ |
2689 | lsb = c & -c; | |
a260abc9 | 2690 | |
0ba1b2ff AM |
2691 | /* Invert to look for a second transition. */ |
2692 | c = ~c; | |
2693 | ||
2694 | /* Erase first transition. */ | |
2695 | c &= -lsb; | |
2696 | ||
2697 | /* Find the second transition. */ | |
2698 | lsb = c & -c; | |
2699 | ||
2700 | /* Invert to look for a third transition. */ | |
2701 | c = ~c; | |
2702 | ||
2703 | /* Erase second transition. */ | |
2704 | c &= -lsb; | |
2705 | ||
2706 | /* Find the third transition (if any). */ | |
2707 | lsb = c & -c; | |
2708 | ||
2709 | /* Match if all the bits above are 1's (or c is zero). */ | |
2710 | return c == -lsb; | |
2711 | } | |
2712 | return 0; | |
2713 | } | |
2714 | ||
2715 | /* Generates shifts and masks for a pair of rldicl or rldicr insns to | |
2716 | implement ANDing by the mask IN. */ | |
2717 | void | |
a2369ed3 | 2718 | build_mask64_2_operands (rtx in, rtx *out) |
0ba1b2ff AM |
2719 | { |
2720 | #if HOST_BITS_PER_WIDE_INT >= 64 | |
2721 | unsigned HOST_WIDE_INT c, lsb, m1, m2; | |
2722 | int shift; | |
2723 | ||
2724 | if (GET_CODE (in) != CONST_INT) | |
2725 | abort (); | |
2726 | ||
2727 | c = INTVAL (in); | |
2728 | if (c & 1) | |
2729 | { | |
2730 | /* Assume c initially something like 0x00fff000000fffff. The idea | |
2731 | is to rotate the word so that the middle ^^^^^^ group of zeros | |
2732 | is at the MS end and can be cleared with an rldicl mask. We then | |
2733 | rotate back and clear off the MS ^^ group of zeros with a | |
2734 | second rldicl. */ | |
2735 | c = ~c; /* c == 0xff000ffffff00000 */ | |
2736 | lsb = c & -c; /* lsb == 0x0000000000100000 */ | |
2737 | m1 = -lsb; /* m1 == 0xfffffffffff00000 */ | |
2738 | c = ~c; /* c == 0x00fff000000fffff */ | |
2739 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2740 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2741 | c = ~c; /* c == 0xff000fffffffffff */ | |
2742 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2743 | shift = 0; | |
2744 | while ((lsb >>= 1) != 0) | |
2745 | shift++; /* shift == 44 on exit from loop */ | |
2746 | m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */ | |
2747 | m1 = ~m1; /* m1 == 0x000000ffffffffff */ | |
2748 | m2 = ~c; /* m2 == 0x00ffffffffffffff */ | |
a260abc9 DE |
2749 | } |
2750 | else | |
0ba1b2ff AM |
2751 | { |
2752 | /* Assume c initially something like 0xff000f0000000000. The idea | |
2753 | is to rotate the word so that the ^^^ middle group of zeros | |
2754 | is at the LS end and can be cleared with an rldicr mask. We then | |
2755 | rotate back and clear off the LS group of ^^^^^^^^^^ zeros with | |
2756 | a second rldicr. */ | |
2757 | lsb = c & -c; /* lsb == 0x0000010000000000 */ | |
2758 | m2 = -lsb; /* m2 == 0xffffff0000000000 */ | |
2759 | c = ~c; /* c == 0x00fff0ffffffffff */ | |
2760 | c &= -lsb; /* c == 0x00fff00000000000 */ | |
2761 | lsb = c & -c; /* lsb == 0x0000100000000000 */ | |
2762 | c = ~c; /* c == 0xff000fffffffffff */ | |
2763 | c &= -lsb; /* c == 0xff00000000000000 */ | |
2764 | shift = 0; | |
2765 | while ((lsb >>= 1) != 0) | |
2766 | shift++; /* shift == 44 on exit from loop */ | |
2767 | m1 = ~c; /* m1 == 0x00ffffffffffffff */ | |
2768 | m1 >>= shift; /* m1 == 0x0000000000000fff */ | |
2769 | m1 = ~m1; /* m1 == 0xfffffffffffff000 */ | |
2770 | } | |
2771 | ||
2772 | /* Note that when we only have two 0->1 and 1->0 transitions, one of the | |
2773 | masks will be all 1's. We are guaranteed more than one transition. */ | |
2774 | out[0] = GEN_INT (64 - shift); | |
2775 | out[1] = GEN_INT (m1); | |
2776 | out[2] = GEN_INT (shift); | |
2777 | out[3] = GEN_INT (m2); | |
2778 | #else | |
045572c7 GK |
2779 | (void)in; |
2780 | (void)out; | |
0ba1b2ff AM |
2781 | abort (); |
2782 | #endif | |
a260abc9 DE |
2783 | } |
2784 | ||
2785 | /* Return 1 if the operand is either a non-special register or a constant | |
2786 | that can be used as the operand of a PowerPC64 logical AND insn. */ | |
2787 | ||
2788 | int | |
a2369ed3 | 2789 | and64_operand (rtx op, enum machine_mode mode) |
9878760c | 2790 | { |
a4f6c312 | 2791 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2792 | return (gpc_reg_operand (op, mode) || mask64_operand (op, mode)); |
2793 | ||
2794 | return (logical_operand (op, mode) || mask64_operand (op, mode)); | |
9878760c RK |
2795 | } |
2796 | ||
0ba1b2ff AM |
2797 | /* Like the above, but also match constants that can be implemented |
2798 | with two rldicl or rldicr insns. */ | |
2799 | ||
2800 | int | |
a2369ed3 | 2801 | and64_2_operand (rtx op, enum machine_mode mode) |
0ba1b2ff | 2802 | { |
a3c9585f | 2803 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
0ba1b2ff AM |
2804 | return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode); |
2805 | ||
2806 | return logical_operand (op, mode) || mask64_2_operand (op, mode); | |
2807 | } | |
2808 | ||
a260abc9 DE |
2809 | /* Return 1 if the operand is either a non-special register or a |
2810 | constant that can be used as the operand of an RS/6000 logical AND insn. */ | |
dcfedcd0 RK |
2811 | |
2812 | int | |
a2369ed3 | 2813 | and_operand (rtx op, enum machine_mode mode) |
dcfedcd0 | 2814 | { |
a4f6c312 | 2815 | if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */ |
52d3af72 DE |
2816 | return (gpc_reg_operand (op, mode) || mask_operand (op, mode)); |
2817 | ||
2818 | return (logical_operand (op, mode) || mask_operand (op, mode)); | |
dcfedcd0 RK |
2819 | } |
2820 | ||
9878760c RK |
2821 | /* Return 1 if the operand is a general register or memory operand. */ |
2822 | ||
2823 | int | |
a2369ed3 | 2824 | reg_or_mem_operand (rtx op, enum machine_mode mode) |
9878760c | 2825 | { |
b6c9286a MM |
2826 | return (gpc_reg_operand (op, mode) |
2827 | || memory_operand (op, mode) | |
4c81e946 | 2828 | || macho_lo_sum_memory_operand (op, mode) |
b6c9286a | 2829 | || volatile_mem_operand (op, mode)); |
9878760c RK |
2830 | } |
2831 | ||
a7a813f7 | 2832 | /* Return 1 if the operand is a general register or memory operand without |
3cb999d8 | 2833 | pre_inc or pre_dec which produces invalid form of PowerPC lwa |
a7a813f7 RK |
2834 | instruction. */ |
2835 | ||
2836 | int | |
a2369ed3 | 2837 | lwa_operand (rtx op, enum machine_mode mode) |
a7a813f7 RK |
2838 | { |
2839 | rtx inner = op; | |
2840 | ||
2841 | if (reload_completed && GET_CODE (inner) == SUBREG) | |
2842 | inner = SUBREG_REG (inner); | |
f676971a | 2843 | |
a7a813f7 RK |
2844 | return gpc_reg_operand (inner, mode) |
2845 | || (memory_operand (inner, mode) | |
2846 | && GET_CODE (XEXP (inner, 0)) != PRE_INC | |
6a40a9d6 DE |
2847 | && GET_CODE (XEXP (inner, 0)) != PRE_DEC |
2848 | && (GET_CODE (XEXP (inner, 0)) != PLUS | |
e903c96a DE |
2849 | || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT |
2850 | || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0)); | |
a7a813f7 RK |
2851 | } |
2852 | ||
cc4d5fec JH |
2853 | /* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */ |
2854 | ||
2855 | int | |
a2369ed3 | 2856 | symbol_ref_operand (rtx op, enum machine_mode mode) |
cc4d5fec JH |
2857 | { |
2858 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2859 | return 0; | |
2860 | ||
473f51b6 DE |
2861 | return (GET_CODE (op) == SYMBOL_REF |
2862 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))); | |
cc4d5fec JH |
2863 | } |
2864 | ||
9878760c | 2865 | /* Return 1 if the operand, used inside a MEM, is a valid first argument |
cc4d5fec | 2866 | to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */ |
9878760c RK |
2867 | |
2868 | int | |
a2369ed3 | 2869 | call_operand (rtx op, enum machine_mode mode) |
9878760c RK |
2870 | { |
2871 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
2872 | return 0; | |
2873 | ||
2874 | return (GET_CODE (op) == SYMBOL_REF | |
cc4d5fec JH |
2875 | || (GET_CODE (op) == REG |
2876 | && (REGNO (op) == LINK_REGISTER_REGNUM | |
2877 | || REGNO (op) == COUNT_REGISTER_REGNUM | |
2878 | || REGNO (op) >= FIRST_PSEUDO_REGISTER))); | |
9878760c RK |
2879 | } |
2880 | ||
2af3d377 | 2881 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be in |
d1908feb | 2882 | this file. */ |
2af3d377 RK |
2883 | |
2884 | int | |
f676971a | 2885 | current_file_function_operand (rtx op, |
a2369ed3 | 2886 | enum machine_mode mode ATTRIBUTE_UNUSED) |
2af3d377 | 2887 | { |
473f51b6 DE |
2888 | return (GET_CODE (op) == SYMBOL_REF |
2889 | && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)) | |
2890 | && (SYMBOL_REF_LOCAL_P (op) | |
2891 | || (op == XEXP (DECL_RTL (current_function_decl), 0)))); | |
2af3d377 RK |
2892 | } |
2893 | ||
9878760c RK |
2894 | /* Return 1 if this operand is a valid input for a move insn. */ |
2895 | ||
2896 | int | |
a2369ed3 | 2897 | input_operand (rtx op, enum machine_mode mode) |
9878760c | 2898 | { |
eb4e8003 | 2899 | /* Memory is always valid. */ |
9878760c RK |
2900 | if (memory_operand (op, mode)) |
2901 | return 1; | |
2902 | ||
eb4e8003 RK |
2903 | /* For floating-point, easy constants are valid. */ |
2904 | if (GET_MODE_CLASS (mode) == MODE_FLOAT | |
2905 | && CONSTANT_P (op) | |
2906 | && easy_fp_constant (op, mode)) | |
2907 | return 1; | |
2908 | ||
4e74d8ec MM |
2909 | /* Allow any integer constant. */ |
2910 | if (GET_MODE_CLASS (mode) == MODE_INT | |
e675f625 | 2911 | && (GET_CODE (op) == CONST_INT |
e675f625 | 2912 | || GET_CODE (op) == CONST_DOUBLE)) |
4e74d8ec MM |
2913 | return 1; |
2914 | ||
d744e06e AH |
2915 | /* Allow easy vector constants. */ |
2916 | if (GET_CODE (op) == CONST_VECTOR | |
2917 | && easy_vector_constant (op, mode)) | |
2918 | return 1; | |
2919 | ||
eb4e8003 RK |
2920 | /* For floating-point or multi-word mode, the only remaining valid type |
2921 | is a register. */ | |
9878760c RK |
2922 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
2923 | || GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
eb4e8003 | 2924 | return register_operand (op, mode); |
9878760c | 2925 | |
88fe15a1 RK |
2926 | /* The only cases left are integral modes one word or smaller (we |
2927 | do not get called for MODE_CC values). These can be in any | |
2928 | register. */ | |
2929 | if (register_operand (op, mode)) | |
a8b3aeda | 2930 | return 1; |
88fe15a1 | 2931 | |
84cf9dda | 2932 | /* A SYMBOL_REF referring to the TOC is valid. */ |
4d588c14 | 2933 | if (legitimate_constant_pool_address_p (op)) |
84cf9dda RK |
2934 | return 1; |
2935 | ||
9ebbca7d | 2936 | /* A constant pool expression (relative to the TOC) is valid */ |
4d588c14 | 2937 | if (toc_relative_expr_p (op)) |
b6c9286a MM |
2938 | return 1; |
2939 | ||
88228c4b MM |
2940 | /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region |
2941 | to be valid. */ | |
f607bc57 | 2942 | if (DEFAULT_ABI == ABI_V4 |
88228c4b MM |
2943 | && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST) |
2944 | && small_data_operand (op, Pmode)) | |
2945 | return 1; | |
2946 | ||
042259f2 | 2947 | return 0; |
9878760c | 2948 | } |
7509c759 | 2949 | |
95727fb8 AP |
2950 | |
2951 | /* Darwin, AIX increases natural record alignment to doubleword if the first | |
2952 | field is an FP double while the FP fields remain word aligned. */ | |
2953 | ||
19d66194 | 2954 | unsigned int |
95727fb8 AP |
2955 | rs6000_special_round_type_align (tree type, int computed, int specified) |
2956 | { | |
2957 | tree field = TYPE_FIELDS (type); | |
95727fb8 AP |
2958 | |
2959 | /* Skip all the static variables only if ABI is greater than | |
71cc389b | 2960 | 1 or equal to 0. */ |
3ce5437a | 2961 | while (field != NULL && TREE_CODE (field) == VAR_DECL) |
95727fb8 AP |
2962 | field = TREE_CHAIN (field); |
2963 | ||
3ce5437a | 2964 | if (field == NULL || field == type || DECL_MODE (field) != DFmode) |
95727fb8 AP |
2965 | return MAX (computed, specified); |
2966 | ||
2967 | return MAX (MAX (computed, specified), 64); | |
2968 | } | |
2969 | ||
a4f6c312 | 2970 | /* Return 1 for an operand in small memory on V.4/eabi. */ |
7509c759 MM |
2971 | |
2972 | int | |
f676971a | 2973 | small_data_operand (rtx op ATTRIBUTE_UNUSED, |
a2369ed3 | 2974 | enum machine_mode mode ATTRIBUTE_UNUSED) |
7509c759 | 2975 | { |
38c1f2d7 | 2976 | #if TARGET_ELF |
5f59ecb7 | 2977 | rtx sym_ref; |
7509c759 | 2978 | |
d9407988 | 2979 | if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA) |
a54d04b7 | 2980 | return 0; |
a54d04b7 | 2981 | |
f607bc57 | 2982 | if (DEFAULT_ABI != ABI_V4) |
7509c759 MM |
2983 | return 0; |
2984 | ||
88228c4b MM |
2985 | if (GET_CODE (op) == SYMBOL_REF) |
2986 | sym_ref = op; | |
2987 | ||
2988 | else if (GET_CODE (op) != CONST | |
2989 | || GET_CODE (XEXP (op, 0)) != PLUS | |
2990 | || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF | |
2991 | || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT) | |
7509c759 MM |
2992 | return 0; |
2993 | ||
88228c4b | 2994 | else |
dbf55e53 MM |
2995 | { |
2996 | rtx sum = XEXP (op, 0); | |
2997 | HOST_WIDE_INT summand; | |
2998 | ||
2999 | /* We have to be careful here, because it is the referenced address | |
3000 | that must be 32k from _SDA_BASE_, not just the symbol. */ | |
3001 | summand = INTVAL (XEXP (sum, 1)); | |
307b599c | 3002 | if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value) |
dbf55e53 MM |
3003 | return 0; |
3004 | ||
3005 | sym_ref = XEXP (sum, 0); | |
3006 | } | |
88228c4b | 3007 | |
20bfcd69 | 3008 | return SYMBOL_REF_SMALL_P (sym_ref); |
d9407988 MM |
3009 | #else |
3010 | return 0; | |
3011 | #endif | |
7509c759 | 3012 | } |
46c07df8 | 3013 | |
d2288d5d HP |
3014 | /* Return true, if operand is a memory operand and has a |
3015 | displacement divisible by 4. */ | |
3016 | ||
3017 | int | |
3018 | word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) | |
3019 | { | |
3020 | rtx addr; | |
3021 | int off = 0; | |
3022 | ||
3023 | if (!memory_operand (op, mode)) | |
3024 | return 0; | |
3025 | ||
3026 | addr = XEXP (op, 0); | |
3027 | if (GET_CODE (addr) == PLUS | |
3028 | && GET_CODE (XEXP (addr, 0)) == REG | |
3029 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
3030 | off = INTVAL (XEXP (addr, 1)); | |
3031 | ||
3032 | return (off % 4) == 0; | |
3033 | } | |
3034 | ||
3a1f863f | 3035 | /* Return true if either operand is a general purpose register. */ |
46c07df8 | 3036 | |
3a1f863f DE |
3037 | bool |
3038 | gpr_or_gpr_p (rtx op0, rtx op1) | |
46c07df8 | 3039 | { |
3a1f863f DE |
3040 | return ((REG_P (op0) && INT_REGNO_P (REGNO (op0))) |
3041 | || (REG_P (op1) && INT_REGNO_P (REGNO (op1)))); | |
46c07df8 HP |
3042 | } |
3043 | ||
9ebbca7d | 3044 | \f |
4d588c14 RH |
3045 | /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */ |
3046 | ||
f676971a EC |
3047 | static int |
3048 | constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc) | |
9ebbca7d | 3049 | { |
f676971a | 3050 | switch (GET_CODE(op)) |
9ebbca7d GK |
3051 | { |
3052 | case SYMBOL_REF: | |
c4501e62 JJ |
3053 | if (RS6000_SYMBOL_REF_TLS_P (op)) |
3054 | return 0; | |
3055 | else if (CONSTANT_POOL_ADDRESS_P (op)) | |
a4f6c312 SS |
3056 | { |
3057 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode)) | |
3058 | { | |
3059 | *have_sym = 1; | |
3060 | return 1; | |
3061 | } | |
3062 | else | |
3063 | return 0; | |
3064 | } | |
3065 | else if (! strcmp (XSTR (op, 0), toc_label_name)) | |
3066 | { | |
3067 | *have_toc = 1; | |
3068 | return 1; | |
3069 | } | |
3070 | else | |
3071 | return 0; | |
9ebbca7d GK |
3072 | case PLUS: |
3073 | case MINUS: | |
c1f11548 DE |
3074 | return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc) |
3075 | && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc)); | |
9ebbca7d | 3076 | case CONST: |
a4f6c312 | 3077 | return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc); |
9ebbca7d | 3078 | case CONST_INT: |
a4f6c312 | 3079 | return 1; |
9ebbca7d | 3080 | default: |
a4f6c312 | 3081 | return 0; |
9ebbca7d GK |
3082 | } |
3083 | } | |
3084 | ||
4d588c14 | 3085 | static bool |
a2369ed3 | 3086 | constant_pool_expr_p (rtx op) |
9ebbca7d GK |
3087 | { |
3088 | int have_sym = 0; | |
3089 | int have_toc = 0; | |
3090 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym; | |
3091 | } | |
3092 | ||
4d588c14 | 3093 | static bool |
a2369ed3 | 3094 | toc_relative_expr_p (rtx op) |
9ebbca7d | 3095 | { |
4d588c14 RH |
3096 | int have_sym = 0; |
3097 | int have_toc = 0; | |
3098 | return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc; | |
3099 | } | |
3100 | ||
4d588c14 | 3101 | bool |
a2369ed3 | 3102 | legitimate_constant_pool_address_p (rtx x) |
4d588c14 RH |
3103 | { |
3104 | return (TARGET_TOC | |
3105 | && GET_CODE (x) == PLUS | |
3106 | && GET_CODE (XEXP (x, 0)) == REG | |
3107 | && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER) | |
3108 | && constant_pool_expr_p (XEXP (x, 1))); | |
3109 | } | |
3110 | ||
3111 | static bool | |
a2369ed3 | 3112 | legitimate_small_data_p (enum machine_mode mode, rtx x) |
4d588c14 RH |
3113 | { |
3114 | return (DEFAULT_ABI == ABI_V4 | |
3115 | && !flag_pic && !TARGET_TOC | |
3116 | && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST) | |
3117 | && small_data_operand (x, mode)); | |
3118 | } | |
3119 | ||
60cdabab DE |
3120 | /* SPE offset addressing is limited to 5-bits worth of double words. */ |
3121 | #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0) | |
3122 | ||
76d2b81d DJ |
3123 | bool |
3124 | rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict) | |
4d588c14 RH |
3125 | { |
3126 | unsigned HOST_WIDE_INT offset, extra; | |
3127 | ||
3128 | if (GET_CODE (x) != PLUS) | |
3129 | return false; | |
3130 | if (GET_CODE (XEXP (x, 0)) != REG) | |
3131 | return false; | |
3132 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
3133 | return false; | |
60cdabab DE |
3134 | if (legitimate_constant_pool_address_p (x)) |
3135 | return true; | |
4d588c14 RH |
3136 | if (GET_CODE (XEXP (x, 1)) != CONST_INT) |
3137 | return false; | |
3138 | ||
3139 | offset = INTVAL (XEXP (x, 1)); | |
3140 | extra = 0; | |
3141 | switch (mode) | |
3142 | { | |
3143 | case V16QImode: | |
3144 | case V8HImode: | |
3145 | case V4SFmode: | |
3146 | case V4SImode: | |
3147 | /* AltiVec vector modes. Only reg+reg addressing is valid here, | |
3148 | which leaves the only valid constant offset of zero, which by | |
3149 | canonicalization rules is also invalid. */ | |
3150 | return false; | |
3151 | ||
3152 | case V4HImode: | |
3153 | case V2SImode: | |
3154 | case V1DImode: | |
3155 | case V2SFmode: | |
3156 | /* SPE vector modes. */ | |
3157 | return SPE_CONST_OFFSET_OK (offset); | |
3158 | ||
3159 | case DFmode: | |
3160 | case DImode: | |
3364872d | 3161 | if (mode == DFmode || !TARGET_POWERPC64) |
4d588c14 RH |
3162 | extra = 4; |
3163 | else if (offset & 3) | |
3164 | return false; | |
3165 | break; | |
3166 | ||
3167 | case TFmode: | |
3168 | case TImode: | |
3364872d | 3169 | if (mode == TFmode || !TARGET_POWERPC64) |
4d588c14 RH |
3170 | extra = 12; |
3171 | else if (offset & 3) | |
3172 | return false; | |
3173 | else | |
3174 | extra = 8; | |
3175 | break; | |
3176 | ||
3177 | default: | |
3178 | break; | |
3179 | } | |
3180 | ||
b1917422 AM |
3181 | offset += 0x8000; |
3182 | return (offset < 0x10000) && (offset + extra < 0x10000); | |
4d588c14 RH |
3183 | } |
3184 | ||
3185 | static bool | |
a2369ed3 | 3186 | legitimate_indexed_address_p (rtx x, int strict) |
4d588c14 RH |
3187 | { |
3188 | rtx op0, op1; | |
3189 | ||
3190 | if (GET_CODE (x) != PLUS) | |
3191 | return false; | |
3192 | op0 = XEXP (x, 0); | |
3193 | op1 = XEXP (x, 1); | |
3194 | ||
3195 | if (!REG_P (op0) || !REG_P (op1)) | |
3196 | return false; | |
3197 | ||
3198 | return ((INT_REG_OK_FOR_BASE_P (op0, strict) | |
3199 | && INT_REG_OK_FOR_INDEX_P (op1, strict)) | |
3200 | || (INT_REG_OK_FOR_BASE_P (op1, strict) | |
3201 | && INT_REG_OK_FOR_INDEX_P (op0, strict))); | |
9ebbca7d GK |
3202 | } |
3203 | ||
4d588c14 | 3204 | static inline bool |
a2369ed3 | 3205 | legitimate_indirect_address_p (rtx x, int strict) |
4d588c14 RH |
3206 | { |
3207 | return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict); | |
3208 | } | |
3209 | ||
4c81e946 FJ |
3210 | static bool |
3211 | macho_lo_sum_memory_operand (rtx x, enum machine_mode mode) | |
3212 | { | |
3213 | if (!TARGET_MACHO || !flag_pic | |
3214 | || mode != SImode || GET_CODE(x) != MEM) | |
3215 | return false; | |
3216 | x = XEXP (x, 0); | |
3217 | ||
3218 | if (GET_CODE (x) != LO_SUM) | |
3219 | return false; | |
3220 | if (GET_CODE (XEXP (x, 0)) != REG) | |
3221 | return false; | |
3222 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0)) | |
3223 | return false; | |
3224 | x = XEXP (x, 1); | |
3225 | ||
3226 | return CONSTANT_P (x); | |
3227 | } | |
3228 | ||
4d588c14 | 3229 | static bool |
a2369ed3 | 3230 | legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict) |
4d588c14 RH |
3231 | { |
3232 | if (GET_CODE (x) != LO_SUM) | |
3233 | return false; | |
3234 | if (GET_CODE (XEXP (x, 0)) != REG) | |
3235 | return false; | |
3236 | if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict)) | |
3237 | return false; | |
3238 | x = XEXP (x, 1); | |
3239 | ||
8622e235 | 3240 | if (TARGET_ELF || TARGET_MACHO) |
4d588c14 | 3241 | { |
a29077da | 3242 | if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic) |
4d588c14 RH |
3243 | return false; |
3244 | if (TARGET_TOC) | |
3245 | return false; | |
3246 | if (GET_MODE_NUNITS (mode) != 1) | |
3247 | return false; | |
c1e55850 | 3248 | if (GET_MODE_BITSIZE (mode) > 64) |
4d588c14 RH |
3249 | return false; |
3250 | ||
3251 | return CONSTANT_P (x); | |
3252 | } | |
3253 | ||
3254 | return false; | |
3255 | } | |
3256 | ||
3257 | ||
9ebbca7d GK |
3258 | /* Try machine-dependent ways of modifying an illegitimate address |
3259 | to be legitimate. If we find one, return the new, valid address. | |
3260 | This is used from only one place: `memory_address' in explow.c. | |
3261 | ||
a4f6c312 SS |
3262 | OLDX is the address as it was before break_out_memory_refs was |
3263 | called. In some cases it is useful to look at this to decide what | |
3264 | needs to be done. | |
9ebbca7d | 3265 | |
a4f6c312 | 3266 | MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS. |
9ebbca7d | 3267 | |
a4f6c312 SS |
3268 | It is always safe for this function to do nothing. It exists to |
3269 | recognize opportunities to optimize the output. | |
9ebbca7d GK |
3270 | |
3271 | On RS/6000, first check for the sum of a register with a constant | |
3272 | integer that is out of range. If so, generate code to add the | |
3273 | constant with the low-order 16 bits masked to the register and force | |
3274 | this result into another register (this can be done with `cau'). | |
3275 | Then generate an address of REG+(CONST&0xffff), allowing for the | |
3276 | possibility of bit 16 being a one. | |
3277 | ||
3278 | Then check for the sum of a register and something not constant, try to | |
3279 | load the other things into a register and return the sum. */ | |
4d588c14 | 3280 | |
9ebbca7d | 3281 | rtx |
a2369ed3 DJ |
3282 | rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, |
3283 | enum machine_mode mode) | |
0ac081f6 | 3284 | { |
c4501e62 JJ |
3285 | if (GET_CODE (x) == SYMBOL_REF) |
3286 | { | |
3287 | enum tls_model model = SYMBOL_REF_TLS_MODEL (x); | |
3288 | if (model != 0) | |
3289 | return rs6000_legitimize_tls_address (x, model); | |
3290 | } | |
3291 | ||
f676971a | 3292 | if (GET_CODE (x) == PLUS |
9ebbca7d GK |
3293 | && GET_CODE (XEXP (x, 0)) == REG |
3294 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
3295 | && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000) | |
f676971a | 3296 | { |
9ebbca7d GK |
3297 | HOST_WIDE_INT high_int, low_int; |
3298 | rtx sum; | |
a65c591c DE |
3299 | low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000; |
3300 | high_int = INTVAL (XEXP (x, 1)) - low_int; | |
9ebbca7d GK |
3301 | sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0), |
3302 | GEN_INT (high_int)), 0); | |
3303 | return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int)); | |
3304 | } | |
f676971a | 3305 | else if (GET_CODE (x) == PLUS |
9ebbca7d GK |
3306 | && GET_CODE (XEXP (x, 0)) == REG |
3307 | && GET_CODE (XEXP (x, 1)) != CONST_INT | |
6ac7bf2c | 3308 | && GET_MODE_NUNITS (mode) == 1 |
a3170dc6 AH |
3309 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
3310 | || TARGET_POWERPC64 | |
fcce224d | 3311 | || (mode != DFmode && mode != TFmode)) |
9ebbca7d GK |
3312 | && (TARGET_POWERPC64 || mode != DImode) |
3313 | && mode != TImode) | |
3314 | { | |
3315 | return gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
3316 | force_reg (Pmode, force_operand (XEXP (x, 1), 0))); | |
3317 | } | |
0ac081f6 AH |
3318 | else if (ALTIVEC_VECTOR_MODE (mode)) |
3319 | { | |
3320 | rtx reg; | |
3321 | ||
3322 | /* Make sure both operands are registers. */ | |
3323 | if (GET_CODE (x) == PLUS) | |
9f85ed45 | 3324 | return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)), |
0ac081f6 AH |
3325 | force_reg (Pmode, XEXP (x, 1))); |
3326 | ||
3327 | reg = force_reg (Pmode, x); | |
3328 | return reg; | |
3329 | } | |
a3170dc6 AH |
3330 | else if (SPE_VECTOR_MODE (mode)) |
3331 | { | |
3332 | /* We accept [reg + reg] and [reg + OFFSET]. */ | |
3333 | ||
3334 | if (GET_CODE (x) == PLUS) | |
3335 | { | |
3336 | rtx op1 = XEXP (x, 0); | |
3337 | rtx op2 = XEXP (x, 1); | |
3338 | ||
3339 | op1 = force_reg (Pmode, op1); | |
3340 | ||
3341 | if (GET_CODE (op2) != REG | |
3342 | && (GET_CODE (op2) != CONST_INT | |
3343 | || !SPE_CONST_OFFSET_OK (INTVAL (op2)))) | |
3344 | op2 = force_reg (Pmode, op2); | |
3345 | ||
3346 | return gen_rtx_PLUS (Pmode, op1, op2); | |
3347 | } | |
3348 | ||
3349 | return force_reg (Pmode, x); | |
3350 | } | |
f1384257 AM |
3351 | else if (TARGET_ELF |
3352 | && TARGET_32BIT | |
3353 | && TARGET_NO_TOC | |
3354 | && ! flag_pic | |
9ebbca7d | 3355 | && GET_CODE (x) != CONST_INT |
f676971a | 3356 | && GET_CODE (x) != CONST_DOUBLE |
9ebbca7d | 3357 | && CONSTANT_P (x) |
6ac7bf2c GK |
3358 | && GET_MODE_NUNITS (mode) == 1 |
3359 | && (GET_MODE_BITSIZE (mode) <= 32 | |
a3170dc6 | 3360 | || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode))) |
9ebbca7d GK |
3361 | { |
3362 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
3363 | emit_insn (gen_elf_high (reg, x)); |
3364 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
9ebbca7d | 3365 | } |
ee890fe2 SS |
3366 | else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC |
3367 | && ! flag_pic | |
ab82a49f AP |
3368 | #if TARGET_MACHO |
3369 | && ! MACHO_DYNAMIC_NO_PIC_P | |
3370 | #endif | |
ee890fe2 | 3371 | && GET_CODE (x) != CONST_INT |
f676971a | 3372 | && GET_CODE (x) != CONST_DOUBLE |
ee890fe2 | 3373 | && CONSTANT_P (x) |
a3170dc6 | 3374 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode) |
f676971a | 3375 | && mode != DImode |
ee890fe2 SS |
3376 | && mode != TImode) |
3377 | { | |
3378 | rtx reg = gen_reg_rtx (Pmode); | |
8a1977f3 GK |
3379 | emit_insn (gen_macho_high (reg, x)); |
3380 | return gen_rtx_LO_SUM (Pmode, reg, x); | |
ee890fe2 | 3381 | } |
f676971a | 3382 | else if (TARGET_TOC |
4d588c14 | 3383 | && constant_pool_expr_p (x) |
a9098fd0 | 3384 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode)) |
9ebbca7d GK |
3385 | { |
3386 | return create_TOC_reference (x); | |
3387 | } | |
3388 | else | |
3389 | return NULL_RTX; | |
3390 | } | |
258bfae2 | 3391 | |
c973d557 JJ |
3392 | /* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL. |
3393 | We need to emit DTP-relative relocations. */ | |
3394 | ||
3395 | void | |
3396 | rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x) | |
3397 | { | |
3398 | switch (size) | |
3399 | { | |
3400 | case 4: | |
3401 | fputs ("\t.long\t", file); | |
3402 | break; | |
3403 | case 8: | |
3404 | fputs (DOUBLE_INT_ASM_OP, file); | |
3405 | break; | |
3406 | default: | |
3407 | abort (); | |
3408 | } | |
3409 | output_addr_const (file, x); | |
3410 | fputs ("@dtprel+0x8000", file); | |
3411 | } | |
3412 | ||
c4501e62 JJ |
3413 | /* Construct the SYMBOL_REF for the tls_get_addr function. */ |
3414 | ||
3415 | static GTY(()) rtx rs6000_tls_symbol; | |
3416 | static rtx | |
863d938c | 3417 | rs6000_tls_get_addr (void) |
c4501e62 JJ |
3418 | { |
3419 | if (!rs6000_tls_symbol) | |
3420 | rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr"); | |
3421 | ||
3422 | return rs6000_tls_symbol; | |
3423 | } | |
3424 | ||
3425 | /* Construct the SYMBOL_REF for TLS GOT references. */ | |
3426 | ||
3427 | static GTY(()) rtx rs6000_got_symbol; | |
3428 | static rtx | |
863d938c | 3429 | rs6000_got_sym (void) |
c4501e62 JJ |
3430 | { |
3431 | if (!rs6000_got_symbol) | |
3432 | { | |
3433 | rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); | |
3434 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL; | |
3435 | SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL; | |
f676971a | 3436 | } |
c4501e62 JJ |
3437 | |
3438 | return rs6000_got_symbol; | |
3439 | } | |
3440 | ||
3441 | /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute | |
3442 | this (thread-local) address. */ | |
3443 | ||
3444 | static rtx | |
a2369ed3 | 3445 | rs6000_legitimize_tls_address (rtx addr, enum tls_model model) |
c4501e62 JJ |
3446 | { |
3447 | rtx dest, insn; | |
3448 | ||
3449 | dest = gen_reg_rtx (Pmode); | |
3450 | if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16) | |
3451 | { | |
3452 | rtx tlsreg; | |
3453 | ||
3454 | if (TARGET_64BIT) | |
3455 | { | |
3456 | tlsreg = gen_rtx_REG (Pmode, 13); | |
3457 | insn = gen_tls_tprel_64 (dest, tlsreg, addr); | |
3458 | } | |
3459 | else | |
3460 | { | |
3461 | tlsreg = gen_rtx_REG (Pmode, 2); | |
3462 | insn = gen_tls_tprel_32 (dest, tlsreg, addr); | |
3463 | } | |
3464 | emit_insn (insn); | |
3465 | } | |
3466 | else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32) | |
3467 | { | |
3468 | rtx tlsreg, tmp; | |
3469 | ||
3470 | tmp = gen_reg_rtx (Pmode); | |
3471 | if (TARGET_64BIT) | |
3472 | { | |
3473 | tlsreg = gen_rtx_REG (Pmode, 13); | |
3474 | insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr); | |
3475 | } | |
3476 | else | |
3477 | { | |
3478 | tlsreg = gen_rtx_REG (Pmode, 2); | |
3479 | insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr); | |
3480 | } | |
3481 | emit_insn (insn); | |
3482 | if (TARGET_64BIT) | |
3483 | insn = gen_tls_tprel_lo_64 (dest, tmp, addr); | |
3484 | else | |
3485 | insn = gen_tls_tprel_lo_32 (dest, tmp, addr); | |
3486 | emit_insn (insn); | |
3487 | } | |
3488 | else | |
3489 | { | |
3490 | rtx r3, got, tga, tmp1, tmp2, eqv; | |
3491 | ||
3492 | if (TARGET_64BIT) | |
3493 | got = gen_rtx_REG (Pmode, TOC_REGISTER); | |
3494 | else | |
3495 | { | |
3496 | if (flag_pic == 1) | |
3497 | got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); | |
3498 | else | |
3499 | { | |
3500 | rtx gsym = rs6000_got_sym (); | |
3501 | got = gen_reg_rtx (Pmode); | |
3502 | if (flag_pic == 0) | |
3503 | rs6000_emit_move (got, gsym, Pmode); | |
3504 | else | |
3505 | { | |
3506 | char buf[30]; | |
3507 | static int tls_got_labelno = 0; | |
3508 | rtx tempLR, lab, tmp3, mem; | |
3509 | rtx first, last; | |
3510 | ||
3511 | ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++); | |
3512 | lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
3513 | tempLR = gen_reg_rtx (Pmode); | |
3514 | tmp1 = gen_reg_rtx (Pmode); | |
3515 | tmp2 = gen_reg_rtx (Pmode); | |
3516 | tmp3 = gen_reg_rtx (Pmode); | |
542a8afa | 3517 | mem = gen_const_mem (Pmode, tmp1); |
c4501e62 JJ |
3518 | |
3519 | first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab, | |
3520 | gsym)); | |
3521 | emit_move_insn (tmp1, tempLR); | |
3522 | emit_move_insn (tmp2, mem); | |
3523 | emit_insn (gen_addsi3 (tmp3, tmp1, tmp2)); | |
3524 | last = emit_move_insn (got, tmp3); | |
3525 | REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym, | |
3526 | REG_NOTES (last)); | |
3527 | REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last, | |
3528 | REG_NOTES (first)); | |
3529 | REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first, | |
3530 | REG_NOTES (last)); | |
3531 | } | |
3532 | } | |
3533 | } | |
3534 | ||
3535 | if (model == TLS_MODEL_GLOBAL_DYNAMIC) | |
3536 | { | |
3537 | r3 = gen_rtx_REG (Pmode, 3); | |
3538 | if (TARGET_64BIT) | |
3539 | insn = gen_tls_gd_64 (r3, got, addr); | |
3540 | else | |
3541 | insn = gen_tls_gd_32 (r3, got, addr); | |
3542 | start_sequence (); | |
3543 | emit_insn (insn); | |
3544 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
3545 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
3546 | insn = emit_call_insn (insn); | |
3547 | CONST_OR_PURE_CALL_P (insn) = 1; | |
3548 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
3549 | insn = get_insns (); | |
3550 | end_sequence (); | |
3551 | emit_libcall_block (insn, dest, r3, addr); | |
3552 | } | |
3553 | else if (model == TLS_MODEL_LOCAL_DYNAMIC) | |
3554 | { | |
3555 | r3 = gen_rtx_REG (Pmode, 3); | |
3556 | if (TARGET_64BIT) | |
3557 | insn = gen_tls_ld_64 (r3, got); | |
3558 | else | |
3559 | insn = gen_tls_ld_32 (r3, got); | |
3560 | start_sequence (); | |
3561 | emit_insn (insn); | |
3562 | tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ()); | |
3563 | insn = gen_call_value (r3, tga, const0_rtx, const0_rtx); | |
3564 | insn = emit_call_insn (insn); | |
3565 | CONST_OR_PURE_CALL_P (insn) = 1; | |
3566 | use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3); | |
3567 | insn = get_insns (); | |
3568 | end_sequence (); | |
3569 | tmp1 = gen_reg_rtx (Pmode); | |
3570 | eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), | |
3571 | UNSPEC_TLSLD); | |
3572 | emit_libcall_block (insn, tmp1, r3, eqv); | |
3573 | if (rs6000_tls_size == 16) | |
3574 | { | |
3575 | if (TARGET_64BIT) | |
3576 | insn = gen_tls_dtprel_64 (dest, tmp1, addr); | |
3577 | else | |
3578 | insn = gen_tls_dtprel_32 (dest, tmp1, addr); | |
3579 | } | |
3580 | else if (rs6000_tls_size == 32) | |
3581 | { | |
3582 | tmp2 = gen_reg_rtx (Pmode); | |
3583 | if (TARGET_64BIT) | |
3584 | insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr); | |
3585 | else | |
3586 | insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr); | |
3587 | emit_insn (insn); | |
3588 | if (TARGET_64BIT) | |
3589 | insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr); | |
3590 | else | |
3591 | insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr); | |
3592 | } | |
3593 | else | |
3594 | { | |
3595 | tmp2 = gen_reg_rtx (Pmode); | |
3596 | if (TARGET_64BIT) | |
3597 | insn = gen_tls_got_dtprel_64 (tmp2, got, addr); | |
3598 | else | |
3599 | insn = gen_tls_got_dtprel_32 (tmp2, got, addr); | |
3600 | emit_insn (insn); | |
3601 | insn = gen_rtx_SET (Pmode, dest, | |
3602 | gen_rtx_PLUS (Pmode, tmp2, tmp1)); | |
3603 | } | |
3604 | emit_insn (insn); | |
3605 | } | |
3606 | else | |
3607 | { | |
3608 | /* IE, or 64 bit offset LE. */ | |
3609 | tmp2 = gen_reg_rtx (Pmode); | |
3610 | if (TARGET_64BIT) | |
3611 | insn = gen_tls_got_tprel_64 (tmp2, got, addr); | |
3612 | else | |
3613 | insn = gen_tls_got_tprel_32 (tmp2, got, addr); | |
3614 | emit_insn (insn); | |
3615 | if (TARGET_64BIT) | |
3616 | insn = gen_tls_tls_64 (dest, tmp2, addr); | |
3617 | else | |
3618 | insn = gen_tls_tls_32 (dest, tmp2, addr); | |
3619 | emit_insn (insn); | |
3620 | } | |
3621 | } | |
3622 | ||
3623 | return dest; | |
3624 | } | |
3625 | ||
3626 | /* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in | |
3627 | instruction definitions. */ | |
3628 | ||
3629 | int | |
a2369ed3 | 3630 | rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED) |
c4501e62 JJ |
3631 | { |
3632 | return RS6000_SYMBOL_REF_TLS_P (x); | |
3633 | } | |
3634 | ||
3635 | /* Return 1 if X contains a thread-local symbol. */ | |
3636 | ||
3637 | bool | |
a2369ed3 | 3638 | rs6000_tls_referenced_p (rtx x) |
c4501e62 | 3639 | { |
cd413cab AP |
3640 | if (! TARGET_HAVE_TLS) |
3641 | return false; | |
3642 | ||
c4501e62 JJ |
3643 | return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0); |
3644 | } | |
3645 | ||
3646 | /* Return 1 if *X is a thread-local symbol. This is the same as | |
3647 | rs6000_tls_symbol_ref except for the type of the unused argument. */ | |
3648 | ||
3649 | static inline int | |
a2369ed3 | 3650 | rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
3651 | { |
3652 | return RS6000_SYMBOL_REF_TLS_P (*x); | |
3653 | } | |
3654 | ||
24ea750e DJ |
3655 | /* The convention appears to be to define this wherever it is used. |
3656 | With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P | |
3657 | is now used here. */ | |
3658 | #ifndef REG_MODE_OK_FOR_BASE_P | |
3659 | #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO) | |
3660 | #endif | |
3661 | ||
3662 | /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to | |
3663 | replace the input X, or the original X if no replacement is called for. | |
3664 | The output parameter *WIN is 1 if the calling macro should goto WIN, | |
3665 | 0 if it should not. | |
3666 | ||
3667 | For RS/6000, we wish to handle large displacements off a base | |
3668 | register by splitting the addend across an addiu/addis and the mem insn. | |
3669 | This cuts number of extra insns needed from 3 to 1. | |
3670 | ||
3671 | On Darwin, we use this to generate code for floating point constants. | |
3672 | A movsf_low is generated so we wind up with 2 instructions rather than 3. | |
3673 | The Darwin code is inside #if TARGET_MACHO because only then is | |
3674 | machopic_function_base_name() defined. */ | |
3675 | rtx | |
f676971a | 3676 | rs6000_legitimize_reload_address (rtx x, enum machine_mode mode, |
a2369ed3 | 3677 | int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win) |
24ea750e | 3678 | { |
f676971a | 3679 | /* We must recognize output that we have already generated ourselves. */ |
24ea750e DJ |
3680 | if (GET_CODE (x) == PLUS |
3681 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3682 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG | |
3683 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
3684 | && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
3685 | { | |
3686 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3687 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3688 | opnum, (enum reload_type)type); | |
3689 | *win = 1; | |
3690 | return x; | |
3691 | } | |
3deb2758 | 3692 | |
24ea750e DJ |
3693 | #if TARGET_MACHO |
3694 | if (DEFAULT_ABI == ABI_DARWIN && flag_pic | |
3695 | && GET_CODE (x) == LO_SUM | |
3696 | && GET_CODE (XEXP (x, 0)) == PLUS | |
3697 | && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx | |
3698 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH | |
3699 | && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST | |
3700 | && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1) | |
3701 | && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS | |
3702 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF | |
3703 | && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF) | |
3704 | { | |
3705 | /* Result of previous invocation of this function on Darwin | |
6f317ef3 | 3706 | floating point constant. */ |
24ea750e DJ |
3707 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
3708 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, | |
3709 | opnum, (enum reload_type)type); | |
3710 | *win = 1; | |
3711 | return x; | |
3712 | } | |
3713 | #endif | |
3714 | if (GET_CODE (x) == PLUS | |
3715 | && GET_CODE (XEXP (x, 0)) == REG | |
3716 | && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER | |
3717 | && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode) | |
78c875e8 | 3718 | && GET_CODE (XEXP (x, 1)) == CONST_INT |
93638d7a | 3719 | && !SPE_VECTOR_MODE (mode) |
78c875e8 | 3720 | && !ALTIVEC_VECTOR_MODE (mode)) |
24ea750e DJ |
3721 | { |
3722 | HOST_WIDE_INT val = INTVAL (XEXP (x, 1)); | |
3723 | HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; | |
3724 | HOST_WIDE_INT high | |
3725 | = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000; | |
3726 | ||
3727 | /* Check for 32-bit overflow. */ | |
3728 | if (high + low != val) | |
3729 | { | |
3730 | *win = 0; | |
3731 | return x; | |
3732 | } | |
3733 | ||
3734 | /* Reload the high part into a base reg; leave the low part | |
3735 | in the mem directly. */ | |
3736 | ||
3737 | x = gen_rtx_PLUS (GET_MODE (x), | |
3738 | gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), | |
3739 | GEN_INT (high)), | |
3740 | GEN_INT (low)); | |
3741 | ||
3742 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, | |
3743 | BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0, | |
3744 | opnum, (enum reload_type)type); | |
3745 | *win = 1; | |
3746 | return x; | |
3747 | } | |
3748 | #if TARGET_MACHO | |
3749 | if (GET_CODE (x) == SYMBOL_REF | |
3750 | && DEFAULT_ABI == ABI_DARWIN | |
69ef87e2 | 3751 | && !ALTIVEC_VECTOR_MODE (mode) |
a29077da GK |
3752 | && (flag_pic || MACHO_DYNAMIC_NO_PIC_P) |
3753 | /* Don't do this for TFmode, since the result isn't offsettable. */ | |
3754 | && mode != TFmode) | |
24ea750e | 3755 | { |
a29077da GK |
3756 | if (flag_pic) |
3757 | { | |
3758 | rtx offset = gen_rtx_CONST (Pmode, | |
3759 | gen_rtx_MINUS (Pmode, x, | |
11abc112 | 3760 | machopic_function_base_sym ())); |
a29077da GK |
3761 | x = gen_rtx_LO_SUM (GET_MODE (x), |
3762 | gen_rtx_PLUS (Pmode, pic_offset_table_rtx, | |
3763 | gen_rtx_HIGH (Pmode, offset)), offset); | |
3764 | } | |
3765 | else | |
3766 | x = gen_rtx_LO_SUM (GET_MODE (x), | |
3767 | gen_rtx_HIGH (Pmode, x), x); | |
3768 | ||
24ea750e | 3769 | push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL, |
a29077da GK |
3770 | BASE_REG_CLASS, Pmode, VOIDmode, 0, 0, |
3771 | opnum, (enum reload_type)type); | |
24ea750e DJ |
3772 | *win = 1; |
3773 | return x; | |
3774 | } | |
3775 | #endif | |
3776 | if (TARGET_TOC | |
4d588c14 | 3777 | && constant_pool_expr_p (x) |
c1f11548 | 3778 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode)) |
24ea750e DJ |
3779 | { |
3780 | (x) = create_TOC_reference (x); | |
3781 | *win = 1; | |
3782 | return x; | |
3783 | } | |
3784 | *win = 0; | |
3785 | return x; | |
f676971a | 3786 | } |
24ea750e | 3787 | |
258bfae2 FS |
3788 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression |
3789 | that is a valid memory address for an instruction. | |
3790 | The MODE argument is the machine mode for the MEM expression | |
3791 | that wants to use this address. | |
3792 | ||
3793 | On the RS/6000, there are four valid address: a SYMBOL_REF that | |
3794 | refers to a constant pool entry of an address (or the sum of it | |
3795 | plus a constant), a short (16-bit signed) constant plus a register, | |
3796 | the sum of two registers, or a register indirect, possibly with an | |
5bdc5878 | 3797 | auto-increment. For DFmode and DImode with a constant plus register, |
258bfae2 FS |
3798 | we must ensure that both words are addressable or PowerPC64 with offset |
3799 | word aligned. | |
3800 | ||
3801 | For modes spanning multiple registers (DFmode in 32-bit GPRs, | |
76d2b81d | 3802 | 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because |
258bfae2 FS |
3803 | adjacent memory cells are accessed by adding word-sized offsets |
3804 | during assembly output. */ | |
3805 | int | |
a2369ed3 | 3806 | rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict) |
258bfae2 | 3807 | { |
c4501e62 JJ |
3808 | if (RS6000_SYMBOL_REF_TLS_P (x)) |
3809 | return 0; | |
4d588c14 | 3810 | if (legitimate_indirect_address_p (x, reg_ok_strict)) |
258bfae2 FS |
3811 | return 1; |
3812 | if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC) | |
0d6d6892 | 3813 | && !ALTIVEC_VECTOR_MODE (mode) |
a3170dc6 | 3814 | && !SPE_VECTOR_MODE (mode) |
258bfae2 | 3815 | && TARGET_UPDATE |
4d588c14 | 3816 | && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict)) |
258bfae2 | 3817 | return 1; |
4d588c14 | 3818 | if (legitimate_small_data_p (mode, x)) |
258bfae2 | 3819 | return 1; |
4d588c14 | 3820 | if (legitimate_constant_pool_address_p (x)) |
258bfae2 FS |
3821 | return 1; |
3822 | /* If not REG_OK_STRICT (before reload) let pass any stack offset. */ | |
3823 | if (! reg_ok_strict | |
3824 | && GET_CODE (x) == PLUS | |
3825 | && GET_CODE (XEXP (x, 0)) == REG | |
708d2456 HP |
3826 | && (XEXP (x, 0) == virtual_stack_vars_rtx |
3827 | || XEXP (x, 0) == arg_pointer_rtx) | |
258bfae2 FS |
3828 | && GET_CODE (XEXP (x, 1)) == CONST_INT) |
3829 | return 1; | |
76d2b81d | 3830 | if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3831 | return 1; |
3832 | if (mode != TImode | |
76d2b81d | 3833 | && mode != TFmode |
a3170dc6 AH |
3834 | && ((TARGET_HARD_FLOAT && TARGET_FPRS) |
3835 | || TARGET_POWERPC64 | |
fcce224d | 3836 | || (mode != DFmode && mode != TFmode)) |
258bfae2 | 3837 | && (TARGET_POWERPC64 || mode != DImode) |
4d588c14 | 3838 | && legitimate_indexed_address_p (x, reg_ok_strict)) |
258bfae2 | 3839 | return 1; |
4d588c14 | 3840 | if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict)) |
258bfae2 FS |
3841 | return 1; |
3842 | return 0; | |
3843 | } | |
4d588c14 RH |
3844 | |
3845 | /* Go to LABEL if ADDR (a legitimate address expression) | |
3846 | has an effect that depends on the machine mode it is used for. | |
3847 | ||
3848 | On the RS/6000 this is true of all integral offsets (since AltiVec | |
3849 | modes don't allow them) or is a pre-increment or decrement. | |
3850 | ||
3851 | ??? Except that due to conceptual problems in offsettable_address_p | |
3852 | we can't really report the problems of integral offsets. So leave | |
f676971a | 3853 | this assuming that the adjustable offset must be valid for the |
4d588c14 RH |
3854 | sub-words of a TFmode operand, which is what we had before. */ |
3855 | ||
3856 | bool | |
a2369ed3 | 3857 | rs6000_mode_dependent_address (rtx addr) |
4d588c14 RH |
3858 | { |
3859 | switch (GET_CODE (addr)) | |
3860 | { | |
3861 | case PLUS: | |
3862 | if (GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
3863 | { | |
3864 | unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1)); | |
3865 | return val + 12 + 0x8000 >= 0x10000; | |
3866 | } | |
3867 | break; | |
3868 | ||
3869 | case LO_SUM: | |
3870 | return true; | |
3871 | ||
3872 | case PRE_INC: | |
3873 | case PRE_DEC: | |
3874 | return TARGET_UPDATE; | |
3875 | ||
3876 | default: | |
3877 | break; | |
3878 | } | |
3879 | ||
3880 | return false; | |
3881 | } | |
d8ecbcdb AH |
3882 | |
3883 | /* Return number of consecutive hard regs needed starting at reg REGNO | |
3884 | to hold something of mode MODE. | |
3885 | This is ordinarily the length in words of a value of mode MODE | |
3886 | but can be less for certain modes in special long registers. | |
3887 | ||
3888 | For the SPE, GPRs are 64 bits but only 32 bits are visible in | |
3889 | scalar instructions. The upper 32 bits are only available to the | |
3890 | SIMD instructions. | |
3891 | ||
3892 | POWER and PowerPC GPRs hold 32 bits worth; | |
3893 | PowerPC64 GPRs and FPRs point register holds 64 bits worth. */ | |
3894 | ||
3895 | int | |
3896 | rs6000_hard_regno_nregs (int regno, enum machine_mode mode) | |
3897 | { | |
3898 | if (FP_REGNO_P (regno)) | |
3899 | return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD; | |
3900 | ||
3901 | if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
3902 | return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD; | |
3903 | ||
3904 | if (ALTIVEC_REGNO_P (regno)) | |
3905 | return | |
3906 | (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD; | |
3907 | ||
3908 | return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
3909 | } | |
2aa4498c AH |
3910 | |
3911 | /* Change register usage conditional on target flags. */ | |
3912 | void | |
3913 | rs6000_conditional_register_usage (void) | |
3914 | { | |
3915 | int i; | |
3916 | ||
3917 | /* Set MQ register fixed (already call_used) if not POWER | |
3918 | architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not | |
3919 | be allocated. */ | |
3920 | if (! TARGET_POWER) | |
3921 | fixed_regs[64] = 1; | |
3922 | ||
3923 | /* 64-bit AIX reserves GPR13 for thread-private data. */ | |
3924 | if (TARGET_64BIT) | |
3925 | fixed_regs[13] = call_used_regs[13] | |
3926 | = call_really_used_regs[13] = 1; | |
3927 | ||
3928 | /* Conditionally disable FPRs. */ | |
3929 | if (TARGET_SOFT_FLOAT || !TARGET_FPRS) | |
3930 | for (i = 32; i < 64; i++) | |
3931 | fixed_regs[i] = call_used_regs[i] | |
3932 | = call_really_used_regs[i] = 1; | |
3933 | ||
3934 | if (DEFAULT_ABI == ABI_V4 | |
3935 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM | |
3936 | && flag_pic == 2) | |
3937 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3938 | ||
3939 | if (DEFAULT_ABI == ABI_V4 | |
3940 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM | |
3941 | && flag_pic == 1) | |
3942 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3943 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3944 | = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3945 | ||
3946 | if (DEFAULT_ABI == ABI_DARWIN | |
3947 | && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM) | |
3948 | global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3949 | = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3950 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3951 | = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3952 | ||
b4db40bf JJ |
3953 | if (TARGET_TOC && TARGET_MINIMAL_TOC) |
3954 | fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] | |
3955 | = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
3956 | ||
2aa4498c AH |
3957 | if (TARGET_ALTIVEC) |
3958 | global_regs[VSCR_REGNO] = 1; | |
3959 | ||
3960 | if (TARGET_SPE) | |
3961 | { | |
3962 | global_regs[SPEFSCR_REGNO] = 1; | |
3963 | fixed_regs[FIXED_SCRATCH] | |
3964 | = call_used_regs[FIXED_SCRATCH] | |
3965 | = call_really_used_regs[FIXED_SCRATCH] = 1; | |
3966 | } | |
3967 | ||
3968 | if (! TARGET_ALTIVEC) | |
3969 | { | |
3970 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
3971 | fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1; | |
3972 | call_really_used_regs[VRSAVE_REGNO] = 1; | |
3973 | } | |
3974 | ||
3975 | if (TARGET_ALTIVEC_ABI) | |
3976 | for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i) | |
3977 | call_used_regs[i] = call_really_used_regs[i] = 1; | |
3978 | } | |
fb4d4348 | 3979 | \f |
a4f6c312 SS |
3980 | /* Try to output insns to set TARGET equal to the constant C if it can |
3981 | be done in less than N insns. Do all computations in MODE. | |
3982 | Returns the place where the output has been placed if it can be | |
3983 | done and the insns have been emitted. If it would take more than N | |
3984 | insns, zero is returned and no insns and emitted. */ | |
2bfcf297 DB |
3985 | |
3986 | rtx | |
f676971a | 3987 | rs6000_emit_set_const (rtx dest, enum machine_mode mode, |
a2369ed3 | 3988 | rtx source, int n ATTRIBUTE_UNUSED) |
2bfcf297 | 3989 | { |
af8cb5c5 | 3990 | rtx result, insn, set; |
2bfcf297 DB |
3991 | HOST_WIDE_INT c0, c1; |
3992 | ||
af8cb5c5 | 3993 | if (mode == QImode || mode == HImode) |
2bfcf297 DB |
3994 | { |
3995 | if (dest == NULL) | |
3996 | dest = gen_reg_rtx (mode); | |
3997 | emit_insn (gen_rtx_SET (VOIDmode, dest, source)); | |
3998 | return dest; | |
3999 | } | |
af8cb5c5 | 4000 | else if (mode == SImode) |
2bfcf297 | 4001 | { |
af8cb5c5 DE |
4002 | result = no_new_pseudos ? dest : gen_reg_rtx (SImode); |
4003 | ||
4004 | emit_insn (gen_rtx_SET (VOIDmode, result, | |
4005 | GEN_INT (INTVAL (source) | |
4006 | & (~ (HOST_WIDE_INT) 0xffff)))); | |
4007 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
4008 | gen_rtx_IOR (SImode, result, | |
4009 | GEN_INT (INTVAL (source) & 0xffff)))); | |
4010 | result = dest; | |
2bfcf297 | 4011 | } |
af8cb5c5 | 4012 | else if (mode == DImode) |
2bfcf297 | 4013 | { |
af8cb5c5 DE |
4014 | if (GET_CODE (source) == CONST_INT) |
4015 | { | |
4016 | c0 = INTVAL (source); | |
4017 | c1 = -(c0 < 0); | |
4018 | } | |
4019 | else if (GET_CODE (source) == CONST_DOUBLE) | |
4020 | { | |
2bfcf297 | 4021 | #if HOST_BITS_PER_WIDE_INT >= 64 |
af8cb5c5 DE |
4022 | c0 = CONST_DOUBLE_LOW (source); |
4023 | c1 = -(c0 < 0); | |
2bfcf297 | 4024 | #else |
af8cb5c5 DE |
4025 | c0 = CONST_DOUBLE_LOW (source); |
4026 | c1 = CONST_DOUBLE_HIGH (source); | |
2bfcf297 | 4027 | #endif |
af8cb5c5 DE |
4028 | } |
4029 | else | |
4030 | abort (); | |
4031 | ||
4032 | result = rs6000_emit_set_long_const (dest, c0, c1); | |
2bfcf297 DB |
4033 | } |
4034 | else | |
a4f6c312 | 4035 | abort (); |
2bfcf297 | 4036 | |
af8cb5c5 DE |
4037 | insn = get_last_insn (); |
4038 | set = single_set (insn); | |
4039 | if (! CONSTANT_P (SET_SRC (set))) | |
4040 | set_unique_reg_note (insn, REG_EQUAL, source); | |
4041 | ||
4042 | return result; | |
2bfcf297 DB |
4043 | } |
4044 | ||
4045 | /* Having failed to find a 3 insn sequence in rs6000_emit_set_const, | |
4046 | fall back to a straight forward decomposition. We do this to avoid | |
4047 | exponential run times encountered when looking for longer sequences | |
4048 | with rs6000_emit_set_const. */ | |
4049 | static rtx | |
a2369ed3 | 4050 | rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2) |
2bfcf297 DB |
4051 | { |
4052 | if (!TARGET_POWERPC64) | |
4053 | { | |
4054 | rtx operand1, operand2; | |
4055 | ||
4056 | operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0, | |
4057 | DImode); | |
4058 | operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, | |
4059 | DImode); | |
4060 | emit_move_insn (operand1, GEN_INT (c1)); | |
4061 | emit_move_insn (operand2, GEN_INT (c2)); | |
4062 | } | |
4063 | else | |
4064 | { | |
bc06712d | 4065 | HOST_WIDE_INT ud1, ud2, ud3, ud4; |
252b88f7 | 4066 | |
bc06712d | 4067 | ud1 = c1 & 0xffff; |
f921c9c9 | 4068 | ud2 = (c1 & 0xffff0000) >> 16; |
2bfcf297 | 4069 | #if HOST_BITS_PER_WIDE_INT >= 64 |
bc06712d | 4070 | c2 = c1 >> 32; |
2bfcf297 | 4071 | #endif |
bc06712d | 4072 | ud3 = c2 & 0xffff; |
f921c9c9 | 4073 | ud4 = (c2 & 0xffff0000) >> 16; |
2bfcf297 | 4074 | |
f676971a | 4075 | if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) |
bc06712d | 4076 | || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) |
2bfcf297 | 4077 | { |
bc06712d | 4078 | if (ud1 & 0x8000) |
b78d48dd | 4079 | emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000))); |
bc06712d TR |
4080 | else |
4081 | emit_move_insn (dest, GEN_INT (ud1)); | |
2bfcf297 | 4082 | } |
2bfcf297 | 4083 | |
f676971a | 4084 | else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000)) |
bc06712d | 4085 | || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000))) |
252b88f7 | 4086 | { |
bc06712d | 4087 | if (ud2 & 0x8000) |
f676971a | 4088 | emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000) |
bc06712d | 4089 | - 0x80000000)); |
252b88f7 | 4090 | else |
bc06712d TR |
4091 | emit_move_insn (dest, GEN_INT (ud2 << 16)); |
4092 | if (ud1 != 0) | |
4093 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
252b88f7 | 4094 | } |
f676971a | 4095 | else if ((ud4 == 0xffff && (ud3 & 0x8000)) |
bc06712d TR |
4096 | || (ud4 == 0 && ! (ud3 & 0x8000))) |
4097 | { | |
4098 | if (ud3 & 0x8000) | |
f676971a | 4099 | emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000) |
bc06712d TR |
4100 | - 0x80000000)); |
4101 | else | |
4102 | emit_move_insn (dest, GEN_INT (ud3 << 16)); | |
4103 | ||
4104 | if (ud2 != 0) | |
4105 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2))); | |
4106 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16))); | |
4107 | if (ud1 != 0) | |
4108 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
4109 | } | |
f676971a | 4110 | else |
bc06712d TR |
4111 | { |
4112 | if (ud4 & 0x8000) | |
f676971a | 4113 | emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000) |
bc06712d TR |
4114 | - 0x80000000)); |
4115 | else | |
4116 | emit_move_insn (dest, GEN_INT (ud4 << 16)); | |
4117 | ||
4118 | if (ud3 != 0) | |
4119 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3))); | |
2bfcf297 | 4120 | |
bc06712d TR |
4121 | emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32))); |
4122 | if (ud2 != 0) | |
f676971a EC |
4123 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, |
4124 | GEN_INT (ud2 << 16))); | |
bc06712d TR |
4125 | if (ud1 != 0) |
4126 | emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1))); | |
4127 | } | |
4128 | } | |
2bfcf297 DB |
4129 | return dest; |
4130 | } | |
4131 | ||
76d2b81d DJ |
4132 | /* Helper for the following. Get rid of [r+r] memory refs |
4133 | in cases where it won't work (TImode, TFmode). */ | |
4134 | ||
4135 | static void | |
4136 | rs6000_eliminate_indexed_memrefs (rtx operands[2]) | |
4137 | { | |
4138 | if (GET_CODE (operands[0]) == MEM | |
4139 | && GET_CODE (XEXP (operands[0], 0)) != REG | |
4140 | && ! reload_in_progress) | |
4141 | operands[0] | |
4142 | = replace_equiv_address (operands[0], | |
4143 | copy_addr_to_reg (XEXP (operands[0], 0))); | |
4144 | ||
4145 | if (GET_CODE (operands[1]) == MEM | |
4146 | && GET_CODE (XEXP (operands[1], 0)) != REG | |
4147 | && ! reload_in_progress) | |
4148 | operands[1] | |
4149 | = replace_equiv_address (operands[1], | |
4150 | copy_addr_to_reg (XEXP (operands[1], 0))); | |
4151 | } | |
4152 | ||
fb4d4348 GK |
4153 | /* Emit a move from SOURCE to DEST in mode MODE. */ |
4154 | void | |
a2369ed3 | 4155 | rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode) |
fb4d4348 GK |
4156 | { |
4157 | rtx operands[2]; | |
4158 | operands[0] = dest; | |
4159 | operands[1] = source; | |
f676971a | 4160 | |
fb4d4348 GK |
4161 | /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */ |
4162 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
4163 | && ! FLOAT_MODE_P (mode) | |
4164 | && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT) | |
4165 | { | |
4166 | /* FIXME. This should never happen. */ | |
4167 | /* Since it seems that it does, do the safe thing and convert | |
4168 | to a CONST_INT. */ | |
2496c7bd | 4169 | operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode); |
fb4d4348 GK |
4170 | } |
4171 | if (GET_CODE (operands[1]) == CONST_DOUBLE | |
4172 | && ! FLOAT_MODE_P (mode) | |
4173 | && ((CONST_DOUBLE_HIGH (operands[1]) == 0 | |
4174 | && CONST_DOUBLE_LOW (operands[1]) >= 0) | |
4175 | || (CONST_DOUBLE_HIGH (operands[1]) == -1 | |
4176 | && CONST_DOUBLE_LOW (operands[1]) < 0))) | |
4177 | abort (); | |
c9e8cb32 DD |
4178 | |
4179 | /* Check if GCC is setting up a block move that will end up using FP | |
4180 | registers as temporaries. We must make sure this is acceptable. */ | |
4181 | if (GET_CODE (operands[0]) == MEM | |
4182 | && GET_CODE (operands[1]) == MEM | |
4183 | && mode == DImode | |
41543739 GK |
4184 | && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0])) |
4185 | || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1]))) | |
4186 | && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32 | |
4187 | ? 32 : MEM_ALIGN (operands[0]))) | |
4188 | || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32 | |
f676971a | 4189 | ? 32 |
41543739 GK |
4190 | : MEM_ALIGN (operands[1])))) |
4191 | && ! MEM_VOLATILE_P (operands [0]) | |
4192 | && ! MEM_VOLATILE_P (operands [1])) | |
c9e8cb32 | 4193 | { |
41543739 GK |
4194 | emit_move_insn (adjust_address (operands[0], SImode, 0), |
4195 | adjust_address (operands[1], SImode, 0)); | |
4196 | emit_move_insn (adjust_address (operands[0], SImode, 4), | |
4197 | adjust_address (operands[1], SImode, 4)); | |
c9e8cb32 DD |
4198 | return; |
4199 | } | |
630d42a0 | 4200 | |
67cef334 DE |
4201 | if (!no_new_pseudos) |
4202 | { | |
4203 | if (GET_CODE (operands[1]) == MEM && optimize > 0 | |
4204 | && (mode == QImode || mode == HImode || mode == SImode) | |
4205 | && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode)) | |
4206 | { | |
4207 | rtx reg = gen_reg_rtx (word_mode); | |
4208 | ||
4209 | emit_insn (gen_rtx_SET (word_mode, reg, | |
4210 | gen_rtx_ZERO_EXTEND (word_mode, | |
4211 | operands[1]))); | |
4212 | operands[1] = gen_lowpart (mode, reg); | |
4213 | } | |
4214 | if (GET_CODE (operands[0]) != REG) | |
4215 | operands[1] = force_reg (mode, operands[1]); | |
4216 | } | |
a9098fd0 | 4217 | |
a3170dc6 AH |
4218 | if (mode == SFmode && ! TARGET_POWERPC |
4219 | && TARGET_HARD_FLOAT && TARGET_FPRS | |
ffc14f31 | 4220 | && GET_CODE (operands[0]) == MEM) |
fb4d4348 | 4221 | { |
ffc14f31 GK |
4222 | int regnum; |
4223 | ||
4224 | if (reload_in_progress || reload_completed) | |
4225 | regnum = true_regnum (operands[1]); | |
4226 | else if (GET_CODE (operands[1]) == REG) | |
4227 | regnum = REGNO (operands[1]); | |
4228 | else | |
4229 | regnum = -1; | |
f676971a | 4230 | |
fb4d4348 GK |
4231 | /* If operands[1] is a register, on POWER it may have |
4232 | double-precision data in it, so truncate it to single | |
4233 | precision. */ | |
4234 | if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER) | |
4235 | { | |
4236 | rtx newreg; | |
4237 | newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode)); | |
4238 | emit_insn (gen_aux_truncdfsf2 (newreg, operands[1])); | |
4239 | operands[1] = newreg; | |
4240 | } | |
4241 | } | |
4242 | ||
c4501e62 JJ |
4243 | /* Recognize the case where operand[1] is a reference to thread-local |
4244 | data and load its address to a register. */ | |
4245 | if (GET_CODE (operands[1]) == SYMBOL_REF) | |
4246 | { | |
4247 | enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]); | |
4248 | if (model != 0) | |
4249 | operands[1] = rs6000_legitimize_tls_address (operands[1], model); | |
4250 | } | |
4251 | ||
8f4e6caf RH |
4252 | /* Handle the case where reload calls us with an invalid address. */ |
4253 | if (reload_in_progress && mode == Pmode | |
69ef87e2 | 4254 | && (! general_operand (operands[1], mode) |
8f4e6caf RH |
4255 | || ! nonimmediate_operand (operands[0], mode))) |
4256 | goto emit_set; | |
4257 | ||
a9baceb1 GK |
4258 | /* 128-bit constant floating-point values on Darwin should really be |
4259 | loaded as two parts. */ | |
4260 | if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN) | |
4261 | && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128 | |
4262 | && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE) | |
4263 | { | |
4264 | /* DImode is used, not DFmode, because simplify_gen_subreg doesn't | |
4265 | know how to get a DFmode SUBREG of a TFmode. */ | |
4266 | rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0), | |
4267 | simplify_gen_subreg (DImode, operands[1], mode, 0), | |
4268 | DImode); | |
4269 | rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, | |
4270 | GET_MODE_SIZE (DImode)), | |
4271 | simplify_gen_subreg (DImode, operands[1], mode, | |
4272 | GET_MODE_SIZE (DImode)), | |
4273 | DImode); | |
4274 | return; | |
4275 | } | |
4276 | ||
fb4d4348 GK |
4277 | /* FIXME: In the long term, this switch statement should go away |
4278 | and be replaced by a sequence of tests based on things like | |
4279 | mode == Pmode. */ | |
4280 | switch (mode) | |
4281 | { | |
4282 | case HImode: | |
4283 | case QImode: | |
4284 | if (CONSTANT_P (operands[1]) | |
4285 | && GET_CODE (operands[1]) != CONST_INT) | |
a9098fd0 | 4286 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 GK |
4287 | break; |
4288 | ||
06f4e019 | 4289 | case TFmode: |
76d2b81d DJ |
4290 | rs6000_eliminate_indexed_memrefs (operands); |
4291 | /* fall through */ | |
4292 | ||
fb4d4348 GK |
4293 | case DFmode: |
4294 | case SFmode: | |
f676971a | 4295 | if (CONSTANT_P (operands[1]) |
fb4d4348 | 4296 | && ! easy_fp_constant (operands[1], mode)) |
a9098fd0 | 4297 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 | 4298 | break; |
f676971a | 4299 | |
0ac081f6 AH |
4300 | case V16QImode: |
4301 | case V8HImode: | |
4302 | case V4SFmode: | |
4303 | case V4SImode: | |
a3170dc6 AH |
4304 | case V4HImode: |
4305 | case V2SFmode: | |
4306 | case V2SImode: | |
00a892b8 | 4307 | case V1DImode: |
69ef87e2 | 4308 | if (CONSTANT_P (operands[1]) |
d744e06e | 4309 | && !easy_vector_constant (operands[1], mode)) |
0ac081f6 AH |
4310 | operands[1] = force_const_mem (mode, operands[1]); |
4311 | break; | |
f676971a | 4312 | |
fb4d4348 | 4313 | case SImode: |
a9098fd0 | 4314 | case DImode: |
fb4d4348 GK |
4315 | /* Use default pattern for address of ELF small data */ |
4316 | if (TARGET_ELF | |
a9098fd0 | 4317 | && mode == Pmode |
f607bc57 | 4318 | && DEFAULT_ABI == ABI_V4 |
f676971a | 4319 | && (GET_CODE (operands[1]) == SYMBOL_REF |
a9098fd0 GK |
4320 | || GET_CODE (operands[1]) == CONST) |
4321 | && small_data_operand (operands[1], mode)) | |
fb4d4348 GK |
4322 | { |
4323 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
4324 | return; | |
4325 | } | |
4326 | ||
f607bc57 | 4327 | if (DEFAULT_ABI == ABI_V4 |
a9098fd0 GK |
4328 | && mode == Pmode && mode == SImode |
4329 | && flag_pic == 1 && got_operand (operands[1], mode)) | |
fb4d4348 GK |
4330 | { |
4331 | emit_insn (gen_movsi_got (operands[0], operands[1])); | |
4332 | return; | |
4333 | } | |
4334 | ||
ee890fe2 | 4335 | if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN) |
f1384257 AM |
4336 | && TARGET_NO_TOC |
4337 | && ! flag_pic | |
a9098fd0 | 4338 | && mode == Pmode |
fb4d4348 GK |
4339 | && CONSTANT_P (operands[1]) |
4340 | && GET_CODE (operands[1]) != HIGH | |
4341 | && GET_CODE (operands[1]) != CONST_INT) | |
4342 | { | |
a9098fd0 | 4343 | rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode)); |
fb4d4348 GK |
4344 | |
4345 | /* If this is a function address on -mcall-aixdesc, | |
4346 | convert it to the address of the descriptor. */ | |
4347 | if (DEFAULT_ABI == ABI_AIX | |
4348 | && GET_CODE (operands[1]) == SYMBOL_REF | |
4349 | && XSTR (operands[1], 0)[0] == '.') | |
4350 | { | |
4351 | const char *name = XSTR (operands[1], 0); | |
4352 | rtx new_ref; | |
4353 | while (*name == '.') | |
4354 | name++; | |
4355 | new_ref = gen_rtx_SYMBOL_REF (Pmode, name); | |
4356 | CONSTANT_POOL_ADDRESS_P (new_ref) | |
4357 | = CONSTANT_POOL_ADDRESS_P (operands[1]); | |
d1908feb | 4358 | SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]); |
fb4d4348 | 4359 | SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]); |
d1908feb | 4360 | SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]); |
fb4d4348 GK |
4361 | operands[1] = new_ref; |
4362 | } | |
7509c759 | 4363 | |
ee890fe2 SS |
4364 | if (DEFAULT_ABI == ABI_DARWIN) |
4365 | { | |
ab82a49f AP |
4366 | #if TARGET_MACHO |
4367 | if (MACHO_DYNAMIC_NO_PIC_P) | |
4368 | { | |
4369 | /* Take care of any required data indirection. */ | |
4370 | operands[1] = rs6000_machopic_legitimize_pic_address ( | |
4371 | operands[1], mode, operands[0]); | |
4372 | if (operands[0] != operands[1]) | |
4373 | emit_insn (gen_rtx_SET (VOIDmode, | |
4374 | operands[0], operands[1])); | |
4375 | return; | |
4376 | } | |
4377 | #endif | |
ac9e2cff AP |
4378 | if (mode == DImode) |
4379 | { | |
4380 | emit_insn (gen_macho_high_di (target, operands[1])); | |
4381 | emit_insn (gen_macho_low_di (operands[0], target, operands[1])); | |
4382 | } | |
4383 | else | |
4384 | { | |
4385 | emit_insn (gen_macho_high (target, operands[1])); | |
4386 | emit_insn (gen_macho_low (operands[0], target, operands[1])); | |
4387 | } | |
ee890fe2 SS |
4388 | return; |
4389 | } | |
4390 | ||
fb4d4348 GK |
4391 | emit_insn (gen_elf_high (target, operands[1])); |
4392 | emit_insn (gen_elf_low (operands[0], target, operands[1])); | |
4393 | return; | |
4394 | } | |
4395 | ||
a9098fd0 GK |
4396 | /* If this is a SYMBOL_REF that refers to a constant pool entry, |
4397 | and we have put it in the TOC, we just need to make a TOC-relative | |
4398 | reference to it. */ | |
4399 | if (TARGET_TOC | |
4400 | && GET_CODE (operands[1]) == SYMBOL_REF | |
4d588c14 | 4401 | && constant_pool_expr_p (operands[1]) |
a9098fd0 GK |
4402 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]), |
4403 | get_pool_mode (operands[1]))) | |
fb4d4348 | 4404 | { |
a9098fd0 | 4405 | operands[1] = create_TOC_reference (operands[1]); |
fb4d4348 | 4406 | } |
a9098fd0 GK |
4407 | else if (mode == Pmode |
4408 | && CONSTANT_P (operands[1]) | |
38886f37 AO |
4409 | && ((GET_CODE (operands[1]) != CONST_INT |
4410 | && ! easy_fp_constant (operands[1], mode)) | |
4411 | || (GET_CODE (operands[1]) == CONST_INT | |
4412 | && num_insns_constant (operands[1], mode) > 2) | |
4413 | || (GET_CODE (operands[0]) == REG | |
4414 | && FP_REGNO_P (REGNO (operands[0])))) | |
a9098fd0 | 4415 | && GET_CODE (operands[1]) != HIGH |
4d588c14 RH |
4416 | && ! legitimate_constant_pool_address_p (operands[1]) |
4417 | && ! toc_relative_expr_p (operands[1])) | |
fb4d4348 GK |
4418 | { |
4419 | /* Emit a USE operation so that the constant isn't deleted if | |
4420 | expensive optimizations are turned on because nobody | |
4421 | references it. This should only be done for operands that | |
4422 | contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set. | |
4423 | This should not be done for operands that contain LABEL_REFs. | |
4424 | For now, we just handle the obvious case. */ | |
4425 | if (GET_CODE (operands[1]) != LABEL_REF) | |
4426 | emit_insn (gen_rtx_USE (VOIDmode, operands[1])); | |
4427 | ||
c859cda6 | 4428 | #if TARGET_MACHO |
ee890fe2 | 4429 | /* Darwin uses a special PIC legitimizer. */ |
ab82a49f | 4430 | if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT) |
ee890fe2 | 4431 | { |
ee890fe2 SS |
4432 | operands[1] = |
4433 | rs6000_machopic_legitimize_pic_address (operands[1], mode, | |
c859cda6 DJ |
4434 | operands[0]); |
4435 | if (operands[0] != operands[1]) | |
4436 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); | |
ee890fe2 SS |
4437 | return; |
4438 | } | |
c859cda6 | 4439 | #endif |
ee890fe2 | 4440 | |
fb4d4348 GK |
4441 | /* If we are to limit the number of things we put in the TOC and |
4442 | this is a symbol plus a constant we can add in one insn, | |
4443 | just put the symbol in the TOC and add the constant. Don't do | |
4444 | this if reload is in progress. */ | |
4445 | if (GET_CODE (operands[1]) == CONST | |
4446 | && TARGET_NO_SUM_IN_TOC && ! reload_in_progress | |
4447 | && GET_CODE (XEXP (operands[1], 0)) == PLUS | |
a9098fd0 | 4448 | && add_operand (XEXP (XEXP (operands[1], 0), 1), mode) |
fb4d4348 GK |
4449 | && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF |
4450 | || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF) | |
4451 | && ! side_effects_p (operands[0])) | |
4452 | { | |
a4f6c312 SS |
4453 | rtx sym = |
4454 | force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0)); | |
fb4d4348 GK |
4455 | rtx other = XEXP (XEXP (operands[1], 0), 1); |
4456 | ||
a9098fd0 GK |
4457 | sym = force_reg (mode, sym); |
4458 | if (mode == SImode) | |
4459 | emit_insn (gen_addsi3 (operands[0], sym, other)); | |
4460 | else | |
4461 | emit_insn (gen_adddi3 (operands[0], sym, other)); | |
fb4d4348 GK |
4462 | return; |
4463 | } | |
4464 | ||
a9098fd0 | 4465 | operands[1] = force_const_mem (mode, operands[1]); |
fb4d4348 | 4466 | |
f676971a | 4467 | if (TARGET_TOC |
4d588c14 | 4468 | && constant_pool_expr_p (XEXP (operands[1], 0)) |
d34c5b80 DE |
4469 | && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P ( |
4470 | get_pool_constant (XEXP (operands[1], 0)), | |
4471 | get_pool_mode (XEXP (operands[1], 0)))) | |
a9098fd0 | 4472 | { |
ba4828e0 | 4473 | operands[1] |
542a8afa RH |
4474 | = gen_const_mem (mode, |
4475 | create_TOC_reference (XEXP (operands[1], 0))); | |
ba4828e0 | 4476 | set_mem_alias_set (operands[1], get_TOC_alias_set ()); |
a9098fd0 | 4477 | } |
fb4d4348 GK |
4478 | } |
4479 | break; | |
a9098fd0 | 4480 | |
fb4d4348 | 4481 | case TImode: |
76d2b81d DJ |
4482 | rs6000_eliminate_indexed_memrefs (operands); |
4483 | ||
27dc0551 DE |
4484 | if (TARGET_POWER) |
4485 | { | |
4486 | emit_insn (gen_rtx_PARALLEL (VOIDmode, | |
4487 | gen_rtvec (2, | |
4488 | gen_rtx_SET (VOIDmode, | |
4489 | operands[0], operands[1]), | |
4490 | gen_rtx_CLOBBER (VOIDmode, | |
4491 | gen_rtx_SCRATCH (SImode))))); | |
4492 | return; | |
4493 | } | |
fb4d4348 GK |
4494 | break; |
4495 | ||
4496 | default: | |
4497 | abort (); | |
4498 | } | |
4499 | ||
a9098fd0 GK |
4500 | /* Above, we may have called force_const_mem which may have returned |
4501 | an invalid address. If we can, fix this up; otherwise, reload will | |
4502 | have to deal with it. */ | |
8f4e6caf RH |
4503 | if (GET_CODE (operands[1]) == MEM && ! reload_in_progress) |
4504 | operands[1] = validize_mem (operands[1]); | |
a9098fd0 | 4505 | |
8f4e6caf | 4506 | emit_set: |
fb4d4348 GK |
4507 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1])); |
4508 | } | |
4697a36c | 4509 | \f |
2858f73a GK |
4510 | /* Nonzero if we can use a floating-point register to pass this arg. */ |
4511 | #define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \ | |
4512 | (GET_MODE_CLASS (MODE) == MODE_FLOAT \ | |
4513 | && (CUM)->fregno <= FP_ARG_MAX_REG \ | |
4514 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
4515 | ||
4516 | /* Nonzero if we can use an AltiVec register to pass this arg. */ | |
4517 | #define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \ | |
4518 | (ALTIVEC_VECTOR_MODE (MODE) \ | |
4519 | && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \ | |
4520 | && TARGET_ALTIVEC_ABI \ | |
83953138 | 4521 | && (NAMED)) |
2858f73a | 4522 | |
c6e8c921 GK |
4523 | /* Return a nonzero value to say to return the function value in |
4524 | memory, just as large structures are always returned. TYPE will be | |
4525 | the data type of the value, and FNTYPE will be the type of the | |
4526 | function doing the returning, or @code{NULL} for libcalls. | |
4527 | ||
4528 | The AIX ABI for the RS/6000 specifies that all structures are | |
4529 | returned in memory. The Darwin ABI does the same. The SVR4 ABI | |
4530 | specifies that structures <= 8 bytes are returned in r3/r4, but a | |
4531 | draft put them in memory, and GCC used to implement the draft | |
4532 | instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET | |
4533 | controls this instead of DEFAULT_ABI; V.4 targets needing backward | |
4534 | compatibility can change DRAFT_V4_STRUCT_RET to override the | |
4535 | default, and -m switches get the final word. See | |
4536 | rs6000_override_options for more details. | |
4537 | ||
4538 | The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit | |
4539 | long double support is enabled. These values are returned in memory. | |
4540 | ||
4541 | int_size_in_bytes returns -1 for variable size objects, which go in | |
4542 | memory always. The cast to unsigned makes -1 > 8. */ | |
4543 | ||
4544 | static bool | |
4545 | rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED) | |
4546 | { | |
4547 | if (AGGREGATE_TYPE_P (type) | |
4548 | && (TARGET_AIX_STRUCT_RET | |
4549 | || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8)) | |
4550 | return true; | |
4551 | if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode) | |
4552 | return true; | |
4553 | return false; | |
4554 | } | |
4555 | ||
4697a36c MM |
4556 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
4557 | for a call to a function whose data type is FNTYPE. | |
4558 | For a library call, FNTYPE is 0. | |
4559 | ||
4560 | For incoming args we set the number of arguments in the prototype large | |
1c20ae99 | 4561 | so we never return a PARALLEL. */ |
4697a36c MM |
4562 | |
4563 | void | |
f676971a | 4564 | init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, |
0f6937fe AM |
4565 | rtx libname ATTRIBUTE_UNUSED, int incoming, |
4566 | int libcall, int n_named_args) | |
4697a36c MM |
4567 | { |
4568 | static CUMULATIVE_ARGS zero_cumulative; | |
4569 | ||
4570 | *cum = zero_cumulative; | |
4571 | cum->words = 0; | |
4572 | cum->fregno = FP_ARG_MIN_REG; | |
0ac081f6 | 4573 | cum->vregno = ALTIVEC_ARG_MIN_REG; |
4697a36c | 4574 | cum->prototype = (fntype && TYPE_ARG_TYPES (fntype)); |
ddcc8263 DE |
4575 | cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall) |
4576 | ? CALL_LIBCALL : CALL_NORMAL); | |
4cc833b7 | 4577 | cum->sysv_gregno = GP_ARG_MIN_REG; |
a6c9bed4 AH |
4578 | cum->stdarg = fntype |
4579 | && (TYPE_ARG_TYPES (fntype) != 0 | |
4580 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
4581 | != void_type_node)); | |
4697a36c | 4582 | |
0f6937fe AM |
4583 | cum->nargs_prototype = 0; |
4584 | if (incoming || cum->prototype) | |
4585 | cum->nargs_prototype = n_named_args; | |
4697a36c | 4586 | |
a5c76ee6 ZW |
4587 | /* Check for a longcall attribute. */ |
4588 | if (fntype | |
4589 | && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype)) | |
4590 | && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))) | |
6a4cee5f MM |
4591 | cum->call_cookie = CALL_LONG; |
4592 | ||
4697a36c MM |
4593 | if (TARGET_DEBUG_ARG) |
4594 | { | |
4595 | fprintf (stderr, "\ninit_cumulative_args:"); | |
4596 | if (fntype) | |
4597 | { | |
4598 | tree ret_type = TREE_TYPE (fntype); | |
4599 | fprintf (stderr, " ret code = %s,", | |
4600 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
4601 | } | |
4602 | ||
6a4cee5f MM |
4603 | if (cum->call_cookie & CALL_LONG) |
4604 | fprintf (stderr, " longcall,"); | |
4605 | ||
4697a36c MM |
4606 | fprintf (stderr, " proto = %d, nargs = %d\n", |
4607 | cum->prototype, cum->nargs_prototype); | |
4608 | } | |
f676971a EC |
4609 | |
4610 | if (fntype | |
4611 | && !TARGET_ALTIVEC | |
6d0ef01e HP |
4612 | && TARGET_ALTIVEC_ABI |
4613 | && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype)))) | |
4614 | { | |
4615 | error ("Cannot return value in vector register because" | |
4616 | " altivec instructions are disabled, use -maltivec" | |
4617 | " to enable them."); | |
4618 | } | |
4697a36c MM |
4619 | } |
4620 | \f | |
fe984136 RH |
4621 | /* Return true if TYPE must be passed on the stack and not in registers. */ |
4622 | ||
4623 | static bool | |
4624 | rs6000_must_pass_in_stack (enum machine_mode mode, tree type) | |
4625 | { | |
4626 | if (DEFAULT_ABI == ABI_AIX || TARGET_64BIT) | |
4627 | return must_pass_in_stack_var_size (mode, type); | |
4628 | else | |
4629 | return must_pass_in_stack_var_size_or_pad (mode, type); | |
4630 | } | |
4631 | ||
c229cba9 DE |
4632 | /* If defined, a C expression which determines whether, and in which |
4633 | direction, to pad out an argument with extra space. The value | |
4634 | should be of type `enum direction': either `upward' to pad above | |
4635 | the argument, `downward' to pad below, or `none' to inhibit | |
4636 | padding. | |
4637 | ||
4638 | For the AIX ABI structs are always stored left shifted in their | |
4639 | argument slot. */ | |
4640 | ||
9ebbca7d | 4641 | enum direction |
a2369ed3 | 4642 | function_arg_padding (enum machine_mode mode, tree type) |
c229cba9 | 4643 | { |
6e985040 AM |
4644 | #ifndef AGGREGATE_PADDING_FIXED |
4645 | #define AGGREGATE_PADDING_FIXED 0 | |
4646 | #endif | |
4647 | #ifndef AGGREGATES_PAD_UPWARD_ALWAYS | |
4648 | #define AGGREGATES_PAD_UPWARD_ALWAYS 0 | |
4649 | #endif | |
4650 | ||
4651 | if (!AGGREGATE_PADDING_FIXED) | |
4652 | { | |
4653 | /* GCC used to pass structures of the same size as integer types as | |
4654 | if they were in fact integers, ignoring FUNCTION_ARG_PADDING. | |
19525b57 | 4655 | i.e. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were |
6e985040 AM |
4656 | passed padded downward, except that -mstrict-align further |
4657 | muddied the water in that multi-component structures of 2 and 4 | |
4658 | bytes in size were passed padded upward. | |
4659 | ||
4660 | The following arranges for best compatibility with previous | |
4661 | versions of gcc, but removes the -mstrict-align dependency. */ | |
4662 | if (BYTES_BIG_ENDIAN) | |
4663 | { | |
4664 | HOST_WIDE_INT size = 0; | |
4665 | ||
4666 | if (mode == BLKmode) | |
4667 | { | |
4668 | if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) | |
4669 | size = int_size_in_bytes (type); | |
4670 | } | |
4671 | else | |
4672 | size = GET_MODE_SIZE (mode); | |
4673 | ||
4674 | if (size == 1 || size == 2 || size == 4) | |
4675 | return downward; | |
4676 | } | |
4677 | return upward; | |
4678 | } | |
4679 | ||
4680 | if (AGGREGATES_PAD_UPWARD_ALWAYS) | |
4681 | { | |
4682 | if (type != 0 && AGGREGATE_TYPE_P (type)) | |
4683 | return upward; | |
4684 | } | |
c229cba9 | 4685 | |
d3704c46 KH |
4686 | /* Fall back to the default. */ |
4687 | return DEFAULT_FUNCTION_ARG_PADDING (mode, type); | |
c229cba9 DE |
4688 | } |
4689 | ||
b6c9286a | 4690 | /* If defined, a C expression that gives the alignment boundary, in bits, |
f676971a | 4691 | of an argument with the specified mode and type. If it is not defined, |
b6c9286a | 4692 | PARM_BOUNDARY is used for all arguments. |
f676971a | 4693 | |
2310f99a | 4694 | V.4 wants long longs to be double word aligned. */ |
b6c9286a MM |
4695 | |
4696 | int | |
a2369ed3 | 4697 | function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED) |
b6c9286a | 4698 | { |
4ed78545 AM |
4699 | if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8) |
4700 | return 64; | |
4701 | else if (SPE_VECTOR_MODE (mode)) | |
e1f83b4d | 4702 | return 64; |
b2d04ecf | 4703 | else if (ALTIVEC_VECTOR_MODE (mode)) |
0ac081f6 | 4704 | return 128; |
9ebbca7d | 4705 | else |
b6c9286a | 4706 | return PARM_BOUNDARY; |
b6c9286a | 4707 | } |
c53bdcf5 AM |
4708 | |
4709 | /* Compute the size (in words) of a function argument. */ | |
4710 | ||
4711 | static unsigned long | |
4712 | rs6000_arg_size (enum machine_mode mode, tree type) | |
4713 | { | |
4714 | unsigned long size; | |
4715 | ||
4716 | if (mode != BLKmode) | |
4717 | size = GET_MODE_SIZE (mode); | |
4718 | else | |
4719 | size = int_size_in_bytes (type); | |
4720 | ||
4721 | if (TARGET_32BIT) | |
4722 | return (size + 3) >> 2; | |
4723 | else | |
4724 | return (size + 7) >> 3; | |
4725 | } | |
b6c9286a | 4726 | \f |
4697a36c MM |
4727 | /* Update the data in CUM to advance over an argument |
4728 | of mode MODE and data type TYPE. | |
b2d04ecf AM |
4729 | (TYPE is null for libcalls where that information may not be available.) |
4730 | ||
4731 | Note that for args passed by reference, function_arg will be called | |
4732 | with MODE and TYPE set to that of the pointer to the arg, not the arg | |
4733 | itself. */ | |
4697a36c MM |
4734 | |
4735 | void | |
f676971a | 4736 | function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
a2369ed3 | 4737 | tree type, int named) |
4697a36c MM |
4738 | { |
4739 | cum->nargs_prototype--; | |
4740 | ||
0ac081f6 AH |
4741 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
4742 | { | |
4ed78545 AM |
4743 | bool stack = false; |
4744 | ||
2858f73a | 4745 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
6d0ef01e HP |
4746 | { |
4747 | cum->vregno++; | |
4748 | if (!TARGET_ALTIVEC) | |
4749 | error ("Cannot pass argument in vector register because" | |
4750 | " altivec instructions are disabled, use -maltivec" | |
4751 | " to enable them."); | |
4ed78545 AM |
4752 | |
4753 | /* PowerPC64 Linux and AIX allocate GPRs for a vector argument | |
f676971a | 4754 | even if it is going to be passed in a vector register. |
4ed78545 AM |
4755 | Darwin does the same for variable-argument functions. */ |
4756 | if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT) | |
4757 | || (cum->stdarg && DEFAULT_ABI != ABI_V4)) | |
4758 | stack = true; | |
6d0ef01e | 4759 | } |
4ed78545 AM |
4760 | else |
4761 | stack = true; | |
4762 | ||
4763 | if (stack) | |
c72d6c26 | 4764 | { |
a594a19c | 4765 | int align; |
f676971a | 4766 | |
2858f73a GK |
4767 | /* Vector parameters must be 16-byte aligned. This places |
4768 | them at 2 mod 4 in terms of words in 32-bit mode, since | |
4769 | the parameter save area starts at offset 24 from the | |
4770 | stack. In 64-bit mode, they just have to start on an | |
4771 | even word, since the parameter save area is 16-byte | |
4772 | aligned. Space for GPRs is reserved even if the argument | |
4773 | will be passed in memory. */ | |
4774 | if (TARGET_32BIT) | |
4ed78545 | 4775 | align = (2 - cum->words) & 3; |
2858f73a GK |
4776 | else |
4777 | align = cum->words & 1; | |
c53bdcf5 | 4778 | cum->words += align + rs6000_arg_size (mode, type); |
f676971a | 4779 | |
a594a19c GK |
4780 | if (TARGET_DEBUG_ARG) |
4781 | { | |
f676971a | 4782 | fprintf (stderr, "function_adv: words = %2d, align=%d, ", |
a594a19c GK |
4783 | cum->words, align); |
4784 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n", | |
f676971a | 4785 | cum->nargs_prototype, cum->prototype, |
2858f73a | 4786 | GET_MODE_NAME (mode)); |
a594a19c GK |
4787 | } |
4788 | } | |
0ac081f6 | 4789 | } |
a4b0320c | 4790 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) |
a6c9bed4 AH |
4791 | && !cum->stdarg |
4792 | && cum->sysv_gregno <= GP_ARG_MAX_REG) | |
a4b0320c | 4793 | cum->sysv_gregno++; |
f607bc57 | 4794 | else if (DEFAULT_ABI == ABI_V4) |
4697a36c | 4795 | { |
a3170dc6 | 4796 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 | 4797 | && (mode == SFmode || mode == DFmode)) |
4697a36c | 4798 | { |
4cc833b7 RH |
4799 | if (cum->fregno <= FP_ARG_V4_MAX_REG) |
4800 | cum->fregno++; | |
4801 | else | |
4802 | { | |
4803 | if (mode == DFmode) | |
4804 | cum->words += cum->words & 1; | |
c53bdcf5 | 4805 | cum->words += rs6000_arg_size (mode, type); |
4cc833b7 | 4806 | } |
4697a36c | 4807 | } |
4cc833b7 RH |
4808 | else |
4809 | { | |
b2d04ecf | 4810 | int n_words = rs6000_arg_size (mode, type); |
4cc833b7 RH |
4811 | int gregno = cum->sysv_gregno; |
4812 | ||
4ed78545 AM |
4813 | /* Long long and SPE vectors are put in (r3,r4), (r5,r6), |
4814 | (r7,r8) or (r9,r10). As does any other 2 word item such | |
4815 | as complex int due to a historical mistake. */ | |
4816 | if (n_words == 2) | |
4817 | gregno += (1 - gregno) & 1; | |
4cc833b7 | 4818 | |
4ed78545 | 4819 | /* Multi-reg args are not split between registers and stack. */ |
4cc833b7 RH |
4820 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
4821 | { | |
4ed78545 AM |
4822 | /* Long long and SPE vectors are aligned on the stack. |
4823 | So are other 2 word items such as complex int due to | |
4824 | a historical mistake. */ | |
4cc833b7 RH |
4825 | if (n_words == 2) |
4826 | cum->words += cum->words & 1; | |
4827 | cum->words += n_words; | |
4828 | } | |
4697a36c | 4829 | |
4cc833b7 RH |
4830 | /* Note: continuing to accumulate gregno past when we've started |
4831 | spilling to the stack indicates the fact that we've started | |
4832 | spilling to the stack to expand_builtin_saveregs. */ | |
4833 | cum->sysv_gregno = gregno + n_words; | |
4834 | } | |
4697a36c | 4835 | |
4cc833b7 RH |
4836 | if (TARGET_DEBUG_ARG) |
4837 | { | |
4838 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
4839 | cum->words, cum->fregno); | |
4840 | fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ", | |
4841 | cum->sysv_gregno, cum->nargs_prototype, cum->prototype); | |
4842 | fprintf (stderr, "mode = %4s, named = %d\n", | |
4843 | GET_MODE_NAME (mode), named); | |
4844 | } | |
4697a36c MM |
4845 | } |
4846 | else | |
4cc833b7 | 4847 | { |
b2d04ecf AM |
4848 | int n_words = rs6000_arg_size (mode, type); |
4849 | int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; | |
a4f6c312 | 4850 | |
b2d04ecf AM |
4851 | /* The simple alignment calculation here works because |
4852 | function_arg_boundary / PARM_BOUNDARY will only be 1 or 2. | |
4853 | If we ever want to handle alignments larger than 8 bytes for | |
4854 | 32-bit or 16 bytes for 64-bit, then we'll need to take into | |
4855 | account the offset to the start of the parm save area. */ | |
4856 | align &= cum->words; | |
4857 | cum->words += align + n_words; | |
4697a36c | 4858 | |
a3170dc6 AH |
4859 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
4860 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
c53bdcf5 | 4861 | cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3; |
4cc833b7 RH |
4862 | |
4863 | if (TARGET_DEBUG_ARG) | |
4864 | { | |
4865 | fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ", | |
4866 | cum->words, cum->fregno); | |
4867 | fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ", | |
4868 | cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode)); | |
4869 | fprintf (stderr, "named = %d, align = %d\n", named, align); | |
4870 | } | |
4871 | } | |
4697a36c | 4872 | } |
a6c9bed4 AH |
4873 | |
4874 | /* Determine where to put a SIMD argument on the SPE. */ | |
b78d48dd | 4875 | |
a6c9bed4 | 4876 | static rtx |
f676971a | 4877 | rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
a2369ed3 | 4878 | tree type) |
a6c9bed4 AH |
4879 | { |
4880 | if (cum->stdarg) | |
4881 | { | |
4882 | int gregno = cum->sysv_gregno; | |
c53bdcf5 | 4883 | int n_words = rs6000_arg_size (mode, type); |
a6c9bed4 AH |
4884 | |
4885 | /* SPE vectors are put in odd registers. */ | |
4886 | if (n_words == 2 && (gregno & 1) == 0) | |
4887 | gregno += 1; | |
4888 | ||
4889 | if (gregno + n_words - 1 <= GP_ARG_MAX_REG) | |
4890 | { | |
4891 | rtx r1, r2; | |
4892 | enum machine_mode m = SImode; | |
4893 | ||
4894 | r1 = gen_rtx_REG (m, gregno); | |
4895 | r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx); | |
4896 | r2 = gen_rtx_REG (m, gregno + 1); | |
4897 | r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4)); | |
4898 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); | |
4899 | } | |
4900 | else | |
b78d48dd | 4901 | return NULL_RTX; |
a6c9bed4 AH |
4902 | } |
4903 | else | |
4904 | { | |
4905 | if (cum->sysv_gregno <= GP_ARG_MAX_REG) | |
4906 | return gen_rtx_REG (mode, cum->sysv_gregno); | |
4907 | else | |
b78d48dd | 4908 | return NULL_RTX; |
a6c9bed4 AH |
4909 | } |
4910 | } | |
4911 | ||
b78d48dd FJ |
4912 | /* Determine where to place an argument in 64-bit mode with 32-bit ABI. */ |
4913 | ||
4914 | static rtx | |
ec6376ab | 4915 | rs6000_mixed_function_arg (enum machine_mode mode, tree type, int align_words) |
b78d48dd | 4916 | { |
ec6376ab AM |
4917 | int n_units; |
4918 | int i, k; | |
4919 | rtx rvec[GP_ARG_NUM_REG + 1]; | |
4920 | ||
4921 | if (align_words >= GP_ARG_NUM_REG) | |
4922 | return NULL_RTX; | |
4923 | ||
4924 | n_units = rs6000_arg_size (mode, type); | |
4925 | ||
4926 | /* Optimize the simple case where the arg fits in one gpr, except in | |
4927 | the case of BLKmode due to assign_parms assuming that registers are | |
4928 | BITS_PER_WORD wide. */ | |
4929 | if (n_units == 0 | |
4930 | || (n_units == 1 && mode != BLKmode)) | |
4931 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
4932 | ||
4933 | k = 0; | |
4934 | if (align_words + n_units > GP_ARG_NUM_REG) | |
4935 | /* Not all of the arg fits in gprs. Say that it goes in memory too, | |
4936 | using a magic NULL_RTX component. | |
4937 | FIXME: This is not strictly correct. Only some of the arg | |
4938 | belongs in memory, not all of it. However, there isn't any way | |
4939 | to do this currently, apart from building rtx descriptions for | |
4940 | the pieces of memory we want stored. Due to bugs in the generic | |
4941 | code we can't use the normal function_arg_partial_nregs scheme | |
4942 | with the PARALLEL arg description we emit here. | |
4943 | In any case, the code to store the whole arg to memory is often | |
4944 | more efficient than code to store pieces, and we know that space | |
4945 | is available in the right place for the whole arg. */ | |
4946 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx); | |
4947 | ||
4948 | i = 0; | |
4949 | do | |
36a454e1 | 4950 | { |
ec6376ab AM |
4951 | rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words); |
4952 | rtx off = GEN_INT (i++ * 4); | |
4953 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off); | |
36a454e1 | 4954 | } |
ec6376ab AM |
4955 | while (++align_words < GP_ARG_NUM_REG && --n_units != 0); |
4956 | ||
4957 | return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec)); | |
b78d48dd FJ |
4958 | } |
4959 | ||
4697a36c MM |
4960 | /* Determine where to put an argument to a function. |
4961 | Value is zero to push the argument on the stack, | |
4962 | or a hard register in which to store the argument. | |
4963 | ||
4964 | MODE is the argument's machine mode. | |
4965 | TYPE is the data type of the argument (as a tree). | |
4966 | This is null for libcalls where that information may | |
4967 | not be available. | |
4968 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
4969 | the preceding args and about the function being called. | |
4970 | NAMED is nonzero if this argument is a named parameter | |
4971 | (otherwise it is an extra parameter matching an ellipsis). | |
4972 | ||
4973 | On RS/6000 the first eight words of non-FP are normally in registers | |
4974 | and the rest are pushed. Under AIX, the first 13 FP args are in registers. | |
4975 | Under V.4, the first 8 FP args are in registers. | |
4976 | ||
4977 | If this is floating-point and no prototype is specified, we use | |
4978 | both an FP and integer register (or possibly FP reg and stack). Library | |
b9599e46 | 4979 | functions (when CALL_LIBCALL is set) always have the proper types for args, |
4697a36c | 4980 | so we can pass the FP value just in one register. emit_library_function |
b2d04ecf AM |
4981 | doesn't support PARALLEL anyway. |
4982 | ||
4983 | Note that for args passed by reference, function_arg will be called | |
4984 | with MODE and TYPE set to that of the pointer to the arg, not the arg | |
4985 | itself. */ | |
4697a36c MM |
4986 | |
4987 | struct rtx_def * | |
f676971a | 4988 | function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
a2369ed3 | 4989 | tree type, int named) |
4697a36c | 4990 | { |
4cc833b7 | 4991 | enum rs6000_abi abi = DEFAULT_ABI; |
4697a36c | 4992 | |
a4f6c312 SS |
4993 | /* Return a marker to indicate whether CR1 needs to set or clear the |
4994 | bit that V.4 uses to say fp args were passed in registers. | |
4995 | Assume that we don't need the marker for software floating point, | |
4996 | or compiler generated library calls. */ | |
4697a36c MM |
4997 | if (mode == VOIDmode) |
4998 | { | |
f607bc57 | 4999 | if (abi == ABI_V4 |
7509c759 | 5000 | && cum->nargs_prototype < 0 |
b9599e46 FS |
5001 | && (cum->call_cookie & CALL_LIBCALL) == 0 |
5002 | && (cum->prototype || TARGET_NO_PROTOTYPE)) | |
7509c759 | 5003 | { |
a3170dc6 AH |
5004 | /* For the SPE, we need to crxor CR6 always. */ |
5005 | if (TARGET_SPE_ABI) | |
5006 | return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS); | |
5007 | else if (TARGET_HARD_FLOAT && TARGET_FPRS) | |
5008 | return GEN_INT (cum->call_cookie | |
5009 | | ((cum->fregno == FP_ARG_MIN_REG) | |
5010 | ? CALL_V4_SET_FP_ARGS | |
5011 | : CALL_V4_CLEAR_FP_ARGS)); | |
7509c759 | 5012 | } |
4697a36c | 5013 | |
7509c759 | 5014 | return GEN_INT (cum->call_cookie); |
4697a36c MM |
5015 | } |
5016 | ||
2858f73a | 5017 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)) |
c72d6c26 HP |
5018 | if (TARGET_64BIT && ! cum->prototype) |
5019 | { | |
5020 | /* Vector parameters get passed in vector register | |
5021 | and also in GPRs or memory, in absence of prototype. */ | |
5022 | int align_words; | |
5023 | rtx slot; | |
5024 | align_words = (cum->words + 1) & ~1; | |
5025 | ||
5026 | if (align_words >= GP_ARG_NUM_REG) | |
5027 | { | |
5028 | slot = NULL_RTX; | |
5029 | } | |
5030 | else | |
5031 | { | |
5032 | slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
5033 | } | |
5034 | return gen_rtx_PARALLEL (mode, | |
5035 | gen_rtvec (2, | |
5036 | gen_rtx_EXPR_LIST (VOIDmode, | |
5037 | slot, const0_rtx), | |
5038 | gen_rtx_EXPR_LIST (VOIDmode, | |
5039 | gen_rtx_REG (mode, cum->vregno), | |
5040 | const0_rtx))); | |
5041 | } | |
5042 | else | |
5043 | return gen_rtx_REG (mode, cum->vregno); | |
2858f73a | 5044 | else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) |
0ac081f6 | 5045 | { |
2858f73a | 5046 | if (named || abi == ABI_V4) |
a594a19c | 5047 | return NULL_RTX; |
0ac081f6 | 5048 | else |
a594a19c GK |
5049 | { |
5050 | /* Vector parameters to varargs functions under AIX or Darwin | |
5051 | get passed in memory and possibly also in GPRs. */ | |
ec6376ab AM |
5052 | int align, align_words, n_words; |
5053 | enum machine_mode part_mode; | |
a594a19c GK |
5054 | |
5055 | /* Vector parameters must be 16-byte aligned. This places them at | |
2858f73a GK |
5056 | 2 mod 4 in terms of words in 32-bit mode, since the parameter |
5057 | save area starts at offset 24 from the stack. In 64-bit mode, | |
5058 | they just have to start on an even word, since the parameter | |
5059 | save area is 16-byte aligned. */ | |
5060 | if (TARGET_32BIT) | |
4ed78545 | 5061 | align = (2 - cum->words) & 3; |
2858f73a GK |
5062 | else |
5063 | align = cum->words & 1; | |
a594a19c GK |
5064 | align_words = cum->words + align; |
5065 | ||
5066 | /* Out of registers? Memory, then. */ | |
5067 | if (align_words >= GP_ARG_NUM_REG) | |
5068 | return NULL_RTX; | |
ec6376ab AM |
5069 | |
5070 | if (TARGET_32BIT && TARGET_POWERPC64) | |
5071 | return rs6000_mixed_function_arg (mode, type, align_words); | |
5072 | ||
2858f73a GK |
5073 | /* The vector value goes in GPRs. Only the part of the |
5074 | value in GPRs is reported here. */ | |
ec6376ab AM |
5075 | part_mode = mode; |
5076 | n_words = rs6000_arg_size (mode, type); | |
5077 | if (align_words + n_words > GP_ARG_NUM_REG) | |
839a4992 | 5078 | /* Fortunately, there are only two possibilities, the value |
2858f73a GK |
5079 | is either wholly in GPRs or half in GPRs and half not. */ |
5080 | part_mode = DImode; | |
ec6376ab AM |
5081 | |
5082 | return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words); | |
a594a19c | 5083 | } |
0ac081f6 | 5084 | } |
a6c9bed4 AH |
5085 | else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)) |
5086 | return rs6000_spe_function_arg (cum, mode, type); | |
f607bc57 | 5087 | else if (abi == ABI_V4) |
4697a36c | 5088 | { |
a3170dc6 | 5089 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
4cc833b7 RH |
5090 | && (mode == SFmode || mode == DFmode)) |
5091 | { | |
5092 | if (cum->fregno <= FP_ARG_V4_MAX_REG) | |
5093 | return gen_rtx_REG (mode, cum->fregno); | |
5094 | else | |
b78d48dd | 5095 | return NULL_RTX; |
4cc833b7 RH |
5096 | } |
5097 | else | |
5098 | { | |
b2d04ecf | 5099 | int n_words = rs6000_arg_size (mode, type); |
4cc833b7 RH |
5100 | int gregno = cum->sysv_gregno; |
5101 | ||
4ed78545 AM |
5102 | /* Long long and SPE vectors are put in (r3,r4), (r5,r6), |
5103 | (r7,r8) or (r9,r10). As does any other 2 word item such | |
5104 | as complex int due to a historical mistake. */ | |
5105 | if (n_words == 2) | |
5106 | gregno += (1 - gregno) & 1; | |
4cc833b7 | 5107 | |
4ed78545 | 5108 | /* Multi-reg args are not split between registers and stack. */ |
ec6376ab | 5109 | if (gregno + n_words - 1 > GP_ARG_MAX_REG) |
b78d48dd | 5110 | return NULL_RTX; |
ec6376ab AM |
5111 | |
5112 | if (TARGET_32BIT && TARGET_POWERPC64) | |
5113 | return rs6000_mixed_function_arg (mode, type, | |
5114 | gregno - GP_ARG_MIN_REG); | |
5115 | return gen_rtx_REG (mode, gregno); | |
4cc833b7 | 5116 | } |
4697a36c | 5117 | } |
4cc833b7 RH |
5118 | else |
5119 | { | |
b2d04ecf AM |
5120 | int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; |
5121 | int align_words = cum->words + (cum->words & align); | |
b78d48dd | 5122 | |
2858f73a | 5123 | if (USE_FP_FOR_ARG_P (cum, mode, type)) |
4cc833b7 | 5124 | { |
ec6376ab AM |
5125 | rtx rvec[GP_ARG_NUM_REG + 1]; |
5126 | rtx r; | |
5127 | int k; | |
c53bdcf5 AM |
5128 | bool needs_psave; |
5129 | enum machine_mode fmode = mode; | |
c53bdcf5 AM |
5130 | unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3; |
5131 | ||
5132 | if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1) | |
5133 | { | |
c53bdcf5 AM |
5134 | /* Currently, we only ever need one reg here because complex |
5135 | doubles are split. */ | |
ec6376ab | 5136 | if (cum->fregno != FP_ARG_MAX_REG || fmode != TFmode) |
c53bdcf5 | 5137 | abort (); |
ec6376ab AM |
5138 | |
5139 | /* Long double split over regs and memory. */ | |
5140 | fmode = DFmode; | |
c53bdcf5 | 5141 | } |
c53bdcf5 AM |
5142 | |
5143 | /* Do we also need to pass this arg in the parameter save | |
5144 | area? */ | |
5145 | needs_psave = (type | |
5146 | && (cum->nargs_prototype <= 0 | |
5147 | || (DEFAULT_ABI == ABI_AIX | |
5148 | && TARGET_XL_CALL | |
5149 | && align_words >= GP_ARG_NUM_REG))); | |
5150 | ||
5151 | if (!needs_psave && mode == fmode) | |
ec6376ab | 5152 | return gen_rtx_REG (fmode, cum->fregno); |
c53bdcf5 | 5153 | |
ec6376ab | 5154 | k = 0; |
c53bdcf5 AM |
5155 | if (needs_psave) |
5156 | { | |
ec6376ab | 5157 | /* Describe the part that goes in gprs or the stack. |
c53bdcf5 | 5158 | This piece must come first, before the fprs. */ |
c53bdcf5 AM |
5159 | if (align_words < GP_ARG_NUM_REG) |
5160 | { | |
5161 | unsigned long n_words = rs6000_arg_size (mode, type); | |
ec6376ab AM |
5162 | |
5163 | if (align_words + n_words > GP_ARG_NUM_REG | |
5164 | || (TARGET_32BIT && TARGET_POWERPC64)) | |
5165 | { | |
5166 | /* If this is partially on the stack, then we only | |
5167 | include the portion actually in registers here. */ | |
5168 | enum machine_mode rmode = TARGET_32BIT ? SImode : DImode; | |
5169 | rtx off; | |
2e6c9641 FJ |
5170 | int i=0; |
5171 | if (align_words + n_words > GP_ARG_NUM_REG | |
5172 | && (TARGET_32BIT && TARGET_POWERPC64)) | |
5173 | /* Not all of the arg fits in gprs. Say that it goes in memory too, | |
5174 | using a magic NULL_RTX component. Also see comment in | |
5175 | rs6000_mixed_function_arg for why the normal | |
5176 | function_arg_partial_nregs scheme doesn't work in this case. */ | |
5177 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx); | |
ec6376ab AM |
5178 | do |
5179 | { | |
5180 | r = gen_rtx_REG (rmode, | |
5181 | GP_ARG_MIN_REG + align_words); | |
2e6c9641 | 5182 | off = GEN_INT (i++ * GET_MODE_SIZE (rmode)); |
ec6376ab AM |
5183 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off); |
5184 | } | |
5185 | while (++align_words < GP_ARG_NUM_REG && --n_words != 0); | |
5186 | } | |
5187 | else | |
5188 | { | |
5189 | /* The whole arg fits in gprs. */ | |
5190 | r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
5191 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx); | |
5192 | } | |
c53bdcf5 | 5193 | } |
ec6376ab AM |
5194 | else |
5195 | /* It's entirely in memory. */ | |
5196 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx); | |
c53bdcf5 AM |
5197 | } |
5198 | ||
ec6376ab AM |
5199 | /* Describe where this piece goes in the fprs. */ |
5200 | r = gen_rtx_REG (fmode, cum->fregno); | |
5201 | rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx); | |
5202 | ||
5203 | return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec)); | |
4cc833b7 RH |
5204 | } |
5205 | else if (align_words < GP_ARG_NUM_REG) | |
b2d04ecf | 5206 | { |
ec6376ab AM |
5207 | if (TARGET_32BIT && TARGET_POWERPC64) |
5208 | return rs6000_mixed_function_arg (mode, type, align_words); | |
b2d04ecf AM |
5209 | |
5210 | return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words); | |
5211 | } | |
4cc833b7 RH |
5212 | else |
5213 | return NULL_RTX; | |
4697a36c | 5214 | } |
4697a36c MM |
5215 | } |
5216 | \f | |
ec6376ab AM |
5217 | /* For an arg passed partly in registers and partly in memory, this is |
5218 | the number of registers used. For args passed entirely in registers | |
5219 | or entirely in memory, zero. When an arg is described by a PARALLEL, | |
5220 | perhaps using more than one register type, this function returns the | |
5221 | number of registers used by the first element of the PARALLEL. */ | |
4697a36c MM |
5222 | |
5223 | int | |
f676971a | 5224 | function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
2858f73a | 5225 | tree type, int named) |
4697a36c | 5226 | { |
c53bdcf5 | 5227 | int ret = 0; |
ec6376ab AM |
5228 | int align; |
5229 | int parm_offset; | |
5230 | int align_words; | |
c53bdcf5 | 5231 | |
f607bc57 | 5232 | if (DEFAULT_ABI == ABI_V4) |
4697a36c | 5233 | return 0; |
4697a36c | 5234 | |
c53bdcf5 AM |
5235 | if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named) |
5236 | && cum->nargs_prototype >= 0) | |
5237 | return 0; | |
5238 | ||
ec6376ab AM |
5239 | align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1; |
5240 | parm_offset = TARGET_32BIT ? 2 : 0; | |
5241 | align_words = cum->words + ((parm_offset - cum->words) & align); | |
5242 | ||
5243 | if (USE_FP_FOR_ARG_P (cum, mode, type) | |
5244 | /* If we are passing this arg in gprs as well, then this function | |
5245 | should return the number of gprs (or memory) partially passed, | |
5246 | *not* the number of fprs. */ | |
5247 | && !(type | |
5248 | && (cum->nargs_prototype <= 0 | |
5249 | || (DEFAULT_ABI == ABI_AIX | |
5250 | && TARGET_XL_CALL | |
5251 | && align_words >= GP_ARG_NUM_REG)))) | |
4697a36c | 5252 | { |
c53bdcf5 | 5253 | if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1) |
ec6376ab | 5254 | ret = FP_ARG_MAX_REG + 1 - cum->fregno; |
c53bdcf5 | 5255 | else if (cum->nargs_prototype >= 0) |
4697a36c MM |
5256 | return 0; |
5257 | } | |
5258 | ||
ec6376ab AM |
5259 | if (align_words < GP_ARG_NUM_REG |
5260 | && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type)) | |
5261 | ret = GP_ARG_NUM_REG - align_words; | |
4697a36c | 5262 | |
c53bdcf5 AM |
5263 | if (ret != 0 && TARGET_DEBUG_ARG) |
5264 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
4697a36c | 5265 | |
c53bdcf5 | 5266 | return ret; |
4697a36c MM |
5267 | } |
5268 | \f | |
5269 | /* A C expression that indicates when an argument must be passed by | |
5270 | reference. If nonzero for an argument, a copy of that argument is | |
5271 | made in memory and a pointer to the argument is passed instead of | |
5272 | the argument itself. The pointer is passed in whatever way is | |
5273 | appropriate for passing a pointer to that type. | |
5274 | ||
b2d04ecf AM |
5275 | Under V.4, aggregates and long double are passed by reference. |
5276 | ||
5277 | As an extension to all 32-bit ABIs, AltiVec vectors are passed by | |
5278 | reference unless the AltiVec vector extension ABI is in force. | |
c8c99a68 DE |
5279 | |
5280 | As an extension to all ABIs, variable sized types are passed by | |
5281 | reference. */ | |
4697a36c | 5282 | |
8cd5a4e0 | 5283 | static bool |
f676971a EC |
5284 | rs6000_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED, |
5285 | enum machine_mode mode ATTRIBUTE_UNUSED, | |
8cd5a4e0 | 5286 | tree type, bool named ATTRIBUTE_UNUSED) |
4697a36c | 5287 | { |
b2d04ecf AM |
5288 | if ((DEFAULT_ABI == ABI_V4 |
5289 | && ((type && AGGREGATE_TYPE_P (type)) | |
5290 | || mode == TFmode)) | |
5291 | || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
5292 | || (type && int_size_in_bytes (type) < 0)) | |
4697a36c MM |
5293 | { |
5294 | if (TARGET_DEBUG_ARG) | |
b2d04ecf | 5295 | fprintf (stderr, "function_arg_pass_by_reference\n"); |
4697a36c MM |
5296 | |
5297 | return 1; | |
5298 | } | |
b2d04ecf | 5299 | return 0; |
4697a36c | 5300 | } |
5985c7a6 FJ |
5301 | |
5302 | static void | |
2d9db8eb | 5303 | rs6000_move_block_from_reg (int regno, rtx x, int nregs) |
5985c7a6 FJ |
5304 | { |
5305 | int i; | |
5306 | enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode; | |
5307 | ||
5308 | if (nregs == 0) | |
5309 | return; | |
5310 | ||
5311 | for (i = 0; i < nregs; i++) | |
5312 | { | |
5313 | rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode)); | |
5314 | if (reload_completed) | |
5315 | { | |
5316 | if (! strict_memory_address_p (reg_mode, XEXP (tem, 0))) | |
5317 | tem = NULL_RTX; | |
5318 | else | |
f676971a | 5319 | tem = simplify_gen_subreg (reg_mode, x, BLKmode, |
5985c7a6 FJ |
5320 | i * GET_MODE_SIZE(reg_mode)); |
5321 | } | |
5322 | else | |
5323 | tem = replace_equiv_address (tem, XEXP (tem, 0)); | |
5324 | ||
5325 | if (tem == NULL_RTX) | |
5326 | abort (); | |
5327 | ||
5328 | emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i)); | |
5329 | } | |
5330 | } | |
5331 | ||
4697a36c MM |
5332 | \f |
5333 | /* Perform any needed actions needed for a function that is receiving a | |
f676971a | 5334 | variable number of arguments. |
4697a36c MM |
5335 | |
5336 | CUM is as above. | |
5337 | ||
5338 | MODE and TYPE are the mode and type of the current parameter. | |
5339 | ||
5340 | PRETEND_SIZE is a variable that should be set to the amount of stack | |
5341 | that must be pushed by the prolog to pretend that our caller pushed | |
5342 | it. | |
5343 | ||
5344 | Normally, this macro will push all remaining incoming registers on the | |
5345 | stack and set PRETEND_SIZE to the length of the registers pushed. */ | |
5346 | ||
c6e8c921 | 5347 | static void |
f676971a | 5348 | setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode, |
a2369ed3 | 5349 | tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl) |
4697a36c | 5350 | { |
4cc833b7 RH |
5351 | CUMULATIVE_ARGS next_cum; |
5352 | int reg_size = TARGET_32BIT ? 4 : 8; | |
ca5adc63 | 5353 | rtx save_area = NULL_RTX, mem; |
dfafc897 | 5354 | int first_reg_offset, set; |
4697a36c | 5355 | |
f31bf321 | 5356 | /* Skip the last named argument. */ |
d34c5b80 | 5357 | next_cum = *cum; |
f31bf321 | 5358 | function_arg_advance (&next_cum, mode, type, 1); |
4cc833b7 | 5359 | |
f607bc57 | 5360 | if (DEFAULT_ABI == ABI_V4) |
d34c5b80 | 5361 | { |
60e2d0ca | 5362 | if (! no_rtl) |
2c4974b7 | 5363 | save_area = plus_constant (virtual_stack_vars_rtx, |
bd227acc | 5364 | - RS6000_VARARGS_SIZE); |
4cc833b7 RH |
5365 | |
5366 | first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG; | |
4697a36c | 5367 | } |
60e2d0ca | 5368 | else |
4697a36c | 5369 | { |
d34c5b80 | 5370 | first_reg_offset = next_cum.words; |
4cc833b7 | 5371 | save_area = virtual_incoming_args_rtx; |
4697a36c | 5372 | |
fe984136 | 5373 | if (targetm.calls.must_pass_in_stack (mode, type)) |
c53bdcf5 | 5374 | first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type); |
4cc833b7 | 5375 | } |
4697a36c | 5376 | |
dfafc897 | 5377 | set = get_varargs_alias_set (); |
c81fc13e | 5378 | if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG) |
4cc833b7 | 5379 | { |
dfafc897 FS |
5380 | mem = gen_rtx_MEM (BLKmode, |
5381 | plus_constant (save_area, | |
5382 | first_reg_offset * reg_size)), | |
ba4828e0 | 5383 | set_mem_alias_set (mem, set); |
8ac61af7 | 5384 | set_mem_align (mem, BITS_PER_WORD); |
dfafc897 | 5385 | |
f676971a | 5386 | rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem, |
5985c7a6 | 5387 | GP_ARG_NUM_REG - first_reg_offset); |
4697a36c MM |
5388 | } |
5389 | ||
4697a36c | 5390 | /* Save FP registers if needed. */ |
f607bc57 | 5391 | if (DEFAULT_ABI == ABI_V4 |
a3170dc6 AH |
5392 | && TARGET_HARD_FLOAT && TARGET_FPRS |
5393 | && ! no_rtl | |
4cc833b7 | 5394 | && next_cum.fregno <= FP_ARG_V4_MAX_REG) |
4697a36c | 5395 | { |
4cc833b7 | 5396 | int fregno = next_cum.fregno; |
9ebbca7d | 5397 | rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO); |
4cc833b7 RH |
5398 | rtx lab = gen_label_rtx (); |
5399 | int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8); | |
4697a36c | 5400 | |
4cc833b7 | 5401 | emit_jump_insn (gen_rtx_SET (VOIDmode, |
4697a36c | 5402 | pc_rtx, |
39403d82 | 5403 | gen_rtx_IF_THEN_ELSE (VOIDmode, |
4cc833b7 RH |
5404 | gen_rtx_NE (VOIDmode, cr1, |
5405 | const0_rtx), | |
39403d82 | 5406 | gen_rtx_LABEL_REF (VOIDmode, lab), |
4697a36c MM |
5407 | pc_rtx))); |
5408 | ||
4cc833b7 RH |
5409 | while (fregno <= FP_ARG_V4_MAX_REG) |
5410 | { | |
dfafc897 | 5411 | mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off)); |
ba4828e0 | 5412 | set_mem_alias_set (mem, set); |
dfafc897 | 5413 | emit_move_insn (mem, gen_rtx_REG (DFmode, fregno)); |
4cc833b7 RH |
5414 | fregno++; |
5415 | off += 8; | |
4697a36c | 5416 | } |
4cc833b7 RH |
5417 | |
5418 | emit_label (lab); | |
4697a36c | 5419 | } |
4697a36c | 5420 | } |
4697a36c | 5421 | |
dfafc897 | 5422 | /* Create the va_list data type. */ |
2c4974b7 | 5423 | |
c35d187f RH |
5424 | static tree |
5425 | rs6000_build_builtin_va_list (void) | |
dfafc897 | 5426 | { |
64c2816f | 5427 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl; |
4697a36c | 5428 | |
9ebbca7d GK |
5429 | /* For AIX, prefer 'char *' because that's what the system |
5430 | header files like. */ | |
f607bc57 | 5431 | if (DEFAULT_ABI != ABI_V4) |
9ebbca7d | 5432 | return build_pointer_type (char_type_node); |
dfafc897 | 5433 | |
f1e639b1 | 5434 | record = (*lang_hooks.types.make_type) (RECORD_TYPE); |
bab45a51 | 5435 | type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record); |
0f4fd75d | 5436 | |
f676971a | 5437 | f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"), |
9ebbca7d | 5438 | unsigned_char_type_node); |
f676971a | 5439 | f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), |
9ebbca7d | 5440 | unsigned_char_type_node); |
64c2816f DT |
5441 | /* Give the two bytes of padding a name, so that -Wpadded won't warn on |
5442 | every user file. */ | |
5443 | f_res = build_decl (FIELD_DECL, get_identifier ("reserved"), | |
5444 | short_unsigned_type_node); | |
dfafc897 FS |
5445 | f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"), |
5446 | ptr_type_node); | |
5447 | f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"), | |
5448 | ptr_type_node); | |
5449 | ||
5450 | DECL_FIELD_CONTEXT (f_gpr) = record; | |
5451 | DECL_FIELD_CONTEXT (f_fpr) = record; | |
64c2816f | 5452 | DECL_FIELD_CONTEXT (f_res) = record; |
dfafc897 FS |
5453 | DECL_FIELD_CONTEXT (f_ovf) = record; |
5454 | DECL_FIELD_CONTEXT (f_sav) = record; | |
5455 | ||
bab45a51 FS |
5456 | TREE_CHAIN (record) = type_decl; |
5457 | TYPE_NAME (record) = type_decl; | |
dfafc897 FS |
5458 | TYPE_FIELDS (record) = f_gpr; |
5459 | TREE_CHAIN (f_gpr) = f_fpr; | |
64c2816f DT |
5460 | TREE_CHAIN (f_fpr) = f_res; |
5461 | TREE_CHAIN (f_res) = f_ovf; | |
dfafc897 FS |
5462 | TREE_CHAIN (f_ovf) = f_sav; |
5463 | ||
5464 | layout_type (record); | |
5465 | ||
5466 | /* The correct type is an array type of one element. */ | |
5467 | return build_array_type (record, build_index_type (size_zero_node)); | |
5468 | } | |
5469 | ||
5470 | /* Implement va_start. */ | |
5471 | ||
5472 | void | |
a2369ed3 | 5473 | rs6000_va_start (tree valist, rtx nextarg) |
4697a36c | 5474 | { |
dfafc897 | 5475 | HOST_WIDE_INT words, n_gpr, n_fpr; |
c566f9bd | 5476 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
dfafc897 | 5477 | tree gpr, fpr, ovf, sav, t; |
2c4974b7 | 5478 | |
dfafc897 | 5479 | /* Only SVR4 needs something special. */ |
f607bc57 | 5480 | if (DEFAULT_ABI != ABI_V4) |
dfafc897 | 5481 | { |
e5faf155 | 5482 | std_expand_builtin_va_start (valist, nextarg); |
dfafc897 FS |
5483 | return; |
5484 | } | |
5485 | ||
973a648b | 5486 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); |
dfafc897 | 5487 | f_fpr = TREE_CHAIN (f_gpr); |
c566f9bd DT |
5488 | f_res = TREE_CHAIN (f_fpr); |
5489 | f_ovf = TREE_CHAIN (f_res); | |
dfafc897 FS |
5490 | f_sav = TREE_CHAIN (f_ovf); |
5491 | ||
8ebecc3b | 5492 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); |
44de5aeb RK |
5493 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE); |
5494 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE); | |
5495 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE); | |
5496 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE); | |
dfafc897 FS |
5497 | |
5498 | /* Count number of gp and fp argument registers used. */ | |
4cc833b7 | 5499 | words = current_function_args_info.words; |
dfafc897 FS |
5500 | n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG; |
5501 | n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG; | |
5502 | ||
5503 | if (TARGET_DEBUG_ARG) | |
4a0a75dd KG |
5504 | fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = " |
5505 | HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n", | |
5506 | words, n_gpr, n_fpr); | |
dfafc897 | 5507 | |
4a90aeeb | 5508 | t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, |
7d60be94 | 5509 | build_int_cst (NULL_TREE, n_gpr)); |
dfafc897 FS |
5510 | TREE_SIDE_EFFECTS (t) = 1; |
5511 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5512 | ||
4a90aeeb | 5513 | t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, |
7d60be94 | 5514 | build_int_cst (NULL_TREE, n_fpr)); |
dfafc897 FS |
5515 | TREE_SIDE_EFFECTS (t) = 1; |
5516 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5517 | ||
5518 | /* Find the overflow area. */ | |
5519 | t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx); | |
5520 | if (words != 0) | |
5521 | t = build (PLUS_EXPR, TREE_TYPE (ovf), t, | |
7d60be94 | 5522 | build_int_cst (NULL_TREE, words * UNITS_PER_WORD)); |
dfafc897 FS |
5523 | t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); |
5524 | TREE_SIDE_EFFECTS (t) = 1; | |
5525 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5526 | ||
5527 | /* Find the register save area. */ | |
5528 | t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx); | |
5529 | t = build (PLUS_EXPR, TREE_TYPE (sav), t, | |
7d60be94 | 5530 | build_int_cst (NULL_TREE, -RS6000_VARARGS_SIZE)); |
dfafc897 FS |
5531 | t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t); |
5532 | TREE_SIDE_EFFECTS (t) = 1; | |
5533 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
5534 | } | |
5535 | ||
5536 | /* Implement va_arg. */ | |
5537 | ||
23a60a04 JM |
5538 | tree |
5539 | rs6000_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p) | |
cd3ce9b4 | 5540 | { |
cd3ce9b4 JM |
5541 | tree f_gpr, f_fpr, f_res, f_ovf, f_sav; |
5542 | tree gpr, fpr, ovf, sav, reg, t, u; | |
08b0dc1b | 5543 | int size, rsize, n_reg, sav_ofs, sav_scale; |
cd3ce9b4 JM |
5544 | tree lab_false, lab_over, addr; |
5545 | int align; | |
5546 | tree ptrtype = build_pointer_type (type); | |
5547 | ||
08b0dc1b RH |
5548 | if (pass_by_reference (NULL, TYPE_MODE (type), type, false)) |
5549 | { | |
5550 | t = rs6000_gimplify_va_arg (valist, ptrtype, pre_p, post_p); | |
5551 | return build_fold_indirect_ref (t); | |
5552 | } | |
5553 | ||
cd3ce9b4 JM |
5554 | if (DEFAULT_ABI != ABI_V4) |
5555 | { | |
08b0dc1b | 5556 | if (targetm.calls.split_complex_arg && TREE_CODE (type) == COMPLEX_TYPE) |
cd3ce9b4 JM |
5557 | { |
5558 | tree elem_type = TREE_TYPE (type); | |
5559 | enum machine_mode elem_mode = TYPE_MODE (elem_type); | |
5560 | int elem_size = GET_MODE_SIZE (elem_mode); | |
5561 | ||
5562 | if (elem_size < UNITS_PER_WORD) | |
5563 | { | |
23a60a04 | 5564 | tree real_part, imag_part; |
cd3ce9b4 JM |
5565 | tree post = NULL_TREE; |
5566 | ||
23a60a04 JM |
5567 | real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p, |
5568 | &post); | |
5569 | /* Copy the value into a temporary, lest the formal temporary | |
5570 | be reused out from under us. */ | |
5571 | real_part = get_initialized_tmp_var (real_part, pre_p, &post); | |
cd3ce9b4 JM |
5572 | append_to_statement_list (post, pre_p); |
5573 | ||
23a60a04 JM |
5574 | imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p, |
5575 | post_p); | |
cd3ce9b4 | 5576 | |
23a60a04 | 5577 | return build (COMPLEX_EXPR, type, real_part, imag_part); |
cd3ce9b4 JM |
5578 | } |
5579 | } | |
5580 | ||
23a60a04 | 5581 | return std_gimplify_va_arg_expr (valist, type, pre_p, post_p); |
cd3ce9b4 JM |
5582 | } |
5583 | ||
5584 | f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node)); | |
5585 | f_fpr = TREE_CHAIN (f_gpr); | |
5586 | f_res = TREE_CHAIN (f_fpr); | |
5587 | f_ovf = TREE_CHAIN (f_res); | |
5588 | f_sav = TREE_CHAIN (f_ovf); | |
5589 | ||
5590 | valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist); | |
44de5aeb RK |
5591 | gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE); |
5592 | fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE); | |
5593 | ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE); | |
5594 | sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE); | |
cd3ce9b4 JM |
5595 | |
5596 | size = int_size_in_bytes (type); | |
5597 | rsize = (size + 3) / 4; | |
5598 | align = 1; | |
5599 | ||
08b0dc1b RH |
5600 | if (TARGET_HARD_FLOAT && TARGET_FPRS |
5601 | && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode)) | |
cd3ce9b4 JM |
5602 | { |
5603 | /* FP args go in FP registers, if present. */ | |
cd3ce9b4 JM |
5604 | reg = fpr; |
5605 | n_reg = 1; | |
5606 | sav_ofs = 8*4; | |
5607 | sav_scale = 8; | |
5608 | if (TYPE_MODE (type) == DFmode) | |
5609 | align = 8; | |
5610 | } | |
5611 | else | |
5612 | { | |
5613 | /* Otherwise into GP registers. */ | |
cd3ce9b4 JM |
5614 | reg = gpr; |
5615 | n_reg = rsize; | |
5616 | sav_ofs = 0; | |
5617 | sav_scale = 4; | |
5618 | if (n_reg == 2) | |
5619 | align = 8; | |
5620 | } | |
5621 | ||
5622 | /* Pull the value out of the saved registers.... */ | |
5623 | ||
5624 | lab_over = NULL; | |
5625 | addr = create_tmp_var (ptr_type_node, "addr"); | |
5626 | DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set (); | |
5627 | ||
5628 | /* AltiVec vectors never go in registers when -mabi=altivec. */ | |
5629 | if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))) | |
5630 | align = 16; | |
5631 | else | |
5632 | { | |
5633 | lab_false = create_artificial_label (); | |
5634 | lab_over = create_artificial_label (); | |
5635 | ||
5636 | /* Long long and SPE vectors are aligned in the registers. | |
5637 | As are any other 2 gpr item such as complex int due to a | |
5638 | historical mistake. */ | |
5639 | u = reg; | |
5640 | if (n_reg == 2) | |
5641 | { | |
5642 | u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), reg, | |
95674810 | 5643 | size_int (n_reg - 1)); |
cd3ce9b4 JM |
5644 | u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u); |
5645 | } | |
5646 | ||
95674810 | 5647 | t = fold_convert (TREE_TYPE (reg), size_int (8 - n_reg + 1)); |
cd3ce9b4 JM |
5648 | t = build2 (GE_EXPR, boolean_type_node, u, t); |
5649 | u = build1 (GOTO_EXPR, void_type_node, lab_false); | |
5650 | t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE); | |
5651 | gimplify_and_add (t, pre_p); | |
5652 | ||
5653 | t = sav; | |
5654 | if (sav_ofs) | |
95674810 | 5655 | t = build2 (PLUS_EXPR, ptr_type_node, sav, size_int (sav_ofs)); |
cd3ce9b4 | 5656 | |
95674810 | 5657 | u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, size_int (n_reg)); |
cd3ce9b4 | 5658 | u = build1 (CONVERT_EXPR, integer_type_node, u); |
95674810 | 5659 | u = build2 (MULT_EXPR, integer_type_node, u, size_int (sav_scale)); |
cd3ce9b4 JM |
5660 | t = build2 (PLUS_EXPR, ptr_type_node, t, u); |
5661 | ||
5662 | t = build2 (MODIFY_EXPR, void_type_node, addr, t); | |
5663 | gimplify_and_add (t, pre_p); | |
5664 | ||
5665 | t = build1 (GOTO_EXPR, void_type_node, lab_over); | |
5666 | gimplify_and_add (t, pre_p); | |
5667 | ||
5668 | t = build1 (LABEL_EXPR, void_type_node, lab_false); | |
5669 | append_to_statement_list (t, pre_p); | |
5670 | ||
5671 | if (n_reg > 2) | |
5672 | { | |
5673 | /* Ensure that we don't find any more args in regs. | |
5674 | Alignment has taken care of the n_reg == 2 case. */ | |
95674810 | 5675 | t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, size_int (8)); |
cd3ce9b4 JM |
5676 | gimplify_and_add (t, pre_p); |
5677 | } | |
5678 | } | |
5679 | ||
5680 | /* ... otherwise out of the overflow area. */ | |
5681 | ||
5682 | /* Care for on-stack alignment if needed. */ | |
5683 | t = ovf; | |
5684 | if (align != 1) | |
5685 | { | |
95674810 | 5686 | t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (align - 1)); |
4a90aeeb | 5687 | t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, |
7d60be94 | 5688 | build_int_cst (NULL_TREE, -align)); |
cd3ce9b4 JM |
5689 | } |
5690 | gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue); | |
5691 | ||
5692 | u = build2 (MODIFY_EXPR, void_type_node, addr, t); | |
5693 | gimplify_and_add (u, pre_p); | |
5694 | ||
95674810 | 5695 | t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (size)); |
cd3ce9b4 JM |
5696 | t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t); |
5697 | gimplify_and_add (t, pre_p); | |
5698 | ||
5699 | if (lab_over) | |
5700 | { | |
5701 | t = build1 (LABEL_EXPR, void_type_node, lab_over); | |
5702 | append_to_statement_list (t, pre_p); | |
5703 | } | |
5704 | ||
08b0dc1b | 5705 | addr = fold_convert (ptrtype, addr); |
23a60a04 | 5706 | return build_fold_indirect_ref (addr); |
cd3ce9b4 JM |
5707 | } |
5708 | ||
0ac081f6 AH |
5709 | /* Builtins. */ |
5710 | ||
6e34d3a3 JM |
5711 | #define def_builtin(MASK, NAME, TYPE, CODE) \ |
5712 | do { \ | |
5713 | if ((MASK) & target_flags) \ | |
5714 | lang_hooks.builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \ | |
5715 | NULL, NULL_TREE); \ | |
0ac081f6 AH |
5716 | } while (0) |
5717 | ||
24408032 AH |
5718 | /* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */ |
5719 | ||
2212663f | 5720 | static const struct builtin_description bdesc_3arg[] = |
24408032 AH |
5721 | { |
5722 | { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP }, | |
5723 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS }, | |
5724 | { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS }, | |
5725 | { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM}, | |
5726 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM }, | |
5727 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM }, | |
5728 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM }, | |
5729 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM }, | |
5730 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS }, | |
5731 | { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS }, | |
f676971a | 5732 | { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP }, |
24408032 AH |
5733 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF }, |
5734 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI }, | |
5735 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI }, | |
5736 | { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI }, | |
5737 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF }, | |
5738 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI }, | |
5739 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI }, | |
5740 | { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI }, | |
5741 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI }, | |
5742 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI }, | |
5743 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI }, | |
5744 | { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF }, | |
5745 | }; | |
2212663f | 5746 | |
95385cbb AH |
5747 | /* DST operations: void foo (void *, const int, const char). */ |
5748 | ||
5749 | static const struct builtin_description bdesc_dst[] = | |
5750 | { | |
5751 | { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST }, | |
5752 | { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT }, | |
5753 | { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST }, | |
5754 | { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT } | |
5755 | }; | |
5756 | ||
2212663f | 5757 | /* Simple binary operations: VECc = foo (VECa, VECb). */ |
24408032 | 5758 | |
a3170dc6 | 5759 | static struct builtin_description bdesc_2arg[] = |
0ac081f6 | 5760 | { |
f18c054f DB |
5761 | { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM }, |
5762 | { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM }, | |
5763 | { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM }, | |
5764 | { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP }, | |
0ac081f6 AH |
5765 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW }, |
5766 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS }, | |
5767 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS }, | |
5768 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS }, | |
5769 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS }, | |
5770 | { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS }, | |
5771 | { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS }, | |
f18c054f | 5772 | { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND }, |
0ac081f6 AH |
5773 | { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC }, |
5774 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB }, | |
5775 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB }, | |
5776 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH }, | |
5777 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH }, | |
5778 | { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW }, | |
5779 | { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW }, | |
617e0e1d DB |
5780 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX }, |
5781 | { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX }, | |
0ac081f6 AH |
5782 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP }, |
5783 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB }, | |
5784 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH }, | |
5785 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW }, | |
5786 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP }, | |
5787 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP }, | |
5788 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB }, | |
5789 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB }, | |
5790 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH }, | |
5791 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH }, | |
5792 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW }, | |
5793 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW }, | |
5794 | { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP }, | |
617e0e1d DB |
5795 | { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS }, |
5796 | { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS }, | |
f18c054f DB |
5797 | { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB }, |
5798 | { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB }, | |
df966bff AH |
5799 | { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH }, |
5800 | { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH }, | |
5801 | { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW }, | |
5802 | { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW }, | |
5803 | { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP }, | |
0ac081f6 AH |
5804 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB }, |
5805 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH }, | |
5806 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW }, | |
5807 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB }, | |
5808 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH }, | |
5809 | { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW }, | |
f18c054f DB |
5810 | { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB }, |
5811 | { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB }, | |
5812 | { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH }, | |
5813 | { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH }, | |
5814 | { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW }, | |
5815 | { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW }, | |
5816 | { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP }, | |
0ac081f6 AH |
5817 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB }, |
5818 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB }, | |
5819 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH }, | |
5820 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH }, | |
5821 | { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB }, | |
5822 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB }, | |
5823 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH }, | |
5824 | { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH }, | |
5825 | { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR }, | |
f18c054f | 5826 | { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR }, |
0ac081f6 AH |
5827 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM }, |
5828 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM }, | |
5829 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX }, | |
5830 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS }, | |
5831 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS }, | |
5832 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS }, | |
5833 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS }, | |
5834 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS }, | |
5835 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS }, | |
5836 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS }, | |
5837 | { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS }, | |
5838 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB }, | |
5839 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH }, | |
5840 | { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW }, | |
5841 | { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB }, | |
5842 | { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH }, | |
5843 | { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW }, | |
5844 | { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL }, | |
5845 | { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO }, | |
2212663f DB |
5846 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB }, |
5847 | { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH }, | |
5848 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW }, | |
0ac081f6 | 5849 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB }, |
f18c054f DB |
5850 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH }, |
5851 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW }, | |
0ac081f6 AH |
5852 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB }, |
5853 | { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH }, | |
5854 | { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW }, | |
5855 | { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR }, | |
5856 | { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO }, | |
f18c054f DB |
5857 | { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM }, |
5858 | { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM }, | |
5859 | { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM }, | |
5860 | { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP }, | |
0ac081f6 AH |
5861 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW }, |
5862 | { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS }, | |
5863 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS }, | |
5864 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS }, | |
5865 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS }, | |
5866 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS }, | |
5867 | { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS }, | |
5868 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS }, | |
5869 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS }, | |
5870 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS }, | |
5871 | { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS }, | |
5872 | { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS }, | |
f18c054f | 5873 | { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR }, |
a3170dc6 AH |
5874 | |
5875 | /* Place holder, leave as first spe builtin. */ | |
5876 | { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW }, | |
5877 | { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND }, | |
5878 | { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC }, | |
5879 | { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS }, | |
5880 | { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU }, | |
5881 | { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV }, | |
5882 | { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD }, | |
5883 | { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV }, | |
5884 | { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL }, | |
5885 | { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB }, | |
5886 | { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI }, | |
5887 | { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO }, | |
5888 | { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO }, | |
5889 | { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI }, | |
5890 | { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA }, | |
5891 | { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN }, | |
5892 | { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA }, | |
5893 | { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN }, | |
5894 | { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA }, | |
5895 | { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN }, | |
5896 | { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF }, | |
5897 | { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA }, | |
5898 | { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW }, | |
5899 | { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW }, | |
5900 | { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI }, | |
5901 | { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA }, | |
5902 | { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW }, | |
5903 | { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW }, | |
5904 | { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF }, | |
5905 | { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA }, | |
5906 | { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW }, | |
5907 | { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW }, | |
5908 | { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW }, | |
5909 | { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW }, | |
5910 | { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI }, | |
5911 | { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA }, | |
5912 | { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW }, | |
5913 | { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW }, | |
5914 | { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW }, | |
5915 | { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW }, | |
5916 | { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA }, | |
5917 | { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN }, | |
5918 | { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA }, | |
5919 | { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN }, | |
5920 | { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA }, | |
5921 | { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN }, | |
5922 | { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF }, | |
5923 | { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA }, | |
5924 | { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW }, | |
5925 | { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW }, | |
5926 | { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI }, | |
5927 | { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA }, | |
5928 | { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW }, | |
5929 | { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW }, | |
5930 | { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF }, | |
5931 | { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA }, | |
5932 | { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW }, | |
5933 | { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW }, | |
5934 | { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW }, | |
5935 | { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW }, | |
5936 | { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI }, | |
5937 | { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA }, | |
5938 | { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW }, | |
5939 | { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW }, | |
5940 | { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW }, | |
5941 | { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW }, | |
5942 | { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF }, | |
5943 | { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA }, | |
5944 | { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI }, | |
5945 | { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA }, | |
5946 | { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF }, | |
5947 | { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA }, | |
5948 | { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI }, | |
5949 | { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA }, | |
a3170dc6 AH |
5950 | { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW }, |
5951 | { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW }, | |
a3170dc6 AH |
5952 | { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW }, |
5953 | { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW }, | |
5954 | { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI }, | |
5955 | { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA }, | |
5956 | { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW }, | |
5957 | { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW }, | |
5958 | { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW }, | |
5959 | { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW }, | |
5960 | { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF }, | |
5961 | { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA }, | |
5962 | { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA }, | |
5963 | { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN }, | |
5964 | { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI }, | |
5965 | { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA }, | |
5966 | { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA }, | |
5967 | { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN }, | |
5968 | { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF }, | |
5969 | { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA }, | |
5970 | { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA }, | |
5971 | { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN }, | |
5972 | { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI }, | |
5973 | { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA }, | |
5974 | { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA }, | |
5975 | { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN }, | |
5976 | { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND }, | |
5977 | { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR }, | |
5978 | { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR }, | |
5979 | { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC }, | |
5980 | { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW }, | |
5981 | { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW }, | |
5982 | { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS }, | |
5983 | { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU }, | |
5984 | { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW }, | |
5985 | ||
5986 | /* SPE binary operations expecting a 5-bit unsigned literal. */ | |
5987 | { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW }, | |
5988 | ||
5989 | { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI }, | |
5990 | { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI }, | |
5991 | { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS }, | |
5992 | { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU }, | |
5993 | { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW }, | |
5994 | { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA }, | |
5995 | { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA }, | |
5996 | { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA }, | |
5997 | { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA }, | |
5998 | { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA }, | |
5999 | { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA }, | |
6000 | { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN }, | |
6001 | { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN }, | |
6002 | { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN }, | |
6003 | { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN }, | |
6004 | { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN }, | |
6005 | { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN }, | |
6006 | { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA }, | |
6007 | { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA }, | |
6008 | { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA }, | |
6009 | { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA }, | |
6010 | { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN }, | |
6011 | { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN }, | |
6012 | { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN }, | |
6013 | { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN }, | |
6014 | { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC }, | |
6015 | ||
6016 | /* Place-holder. Leave as last binary SPE builtin. */ | |
17edbda5 | 6017 | { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR }, |
ae4b4a02 AH |
6018 | }; |
6019 | ||
6020 | /* AltiVec predicates. */ | |
6021 | ||
6022 | struct builtin_description_predicates | |
6023 | { | |
6024 | const unsigned int mask; | |
6025 | const enum insn_code icode; | |
6026 | const char *opcode; | |
6027 | const char *const name; | |
6028 | const enum rs6000_builtins code; | |
6029 | }; | |
6030 | ||
6031 | static const struct builtin_description_predicates bdesc_altivec_preds[] = | |
6032 | { | |
6033 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P }, | |
6034 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P }, | |
6035 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P }, | |
6036 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P }, | |
6037 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P }, | |
6038 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P }, | |
6039 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P }, | |
6040 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P }, | |
6041 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P }, | |
6042 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P }, | |
6043 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P }, | |
6044 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P }, | |
6045 | { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P } | |
0ac081f6 | 6046 | }; |
24408032 | 6047 | |
a3170dc6 AH |
6048 | /* SPE predicates. */ |
6049 | static struct builtin_description bdesc_spe_predicates[] = | |
6050 | { | |
6051 | /* Place-holder. Leave as first. */ | |
6052 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ }, | |
6053 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS }, | |
6054 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU }, | |
6055 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS }, | |
6056 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU }, | |
6057 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ }, | |
6058 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT }, | |
6059 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT }, | |
6060 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ }, | |
6061 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT }, | |
6062 | /* Place-holder. Leave as last. */ | |
6063 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT }, | |
6064 | }; | |
6065 | ||
6066 | /* SPE evsel predicates. */ | |
6067 | static struct builtin_description bdesc_spe_evsel[] = | |
6068 | { | |
6069 | /* Place-holder. Leave as first. */ | |
6070 | { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS }, | |
6071 | { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU }, | |
6072 | { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS }, | |
6073 | { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU }, | |
6074 | { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ }, | |
6075 | { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT }, | |
6076 | { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT }, | |
6077 | { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ }, | |
6078 | { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT }, | |
6079 | { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT }, | |
6080 | /* Place-holder. Leave as last. */ | |
6081 | { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ }, | |
6082 | }; | |
6083 | ||
b6d08ca1 | 6084 | /* ABS* operations. */ |
100c4561 AH |
6085 | |
6086 | static const struct builtin_description bdesc_abs[] = | |
6087 | { | |
6088 | { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI }, | |
6089 | { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI }, | |
6090 | { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF }, | |
6091 | { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI }, | |
6092 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI }, | |
6093 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI }, | |
6094 | { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI } | |
6095 | }; | |
6096 | ||
617e0e1d DB |
6097 | /* Simple unary operations: VECb = foo (unsigned literal) or VECb = |
6098 | foo (VECa). */ | |
24408032 | 6099 | |
a3170dc6 | 6100 | static struct builtin_description bdesc_1arg[] = |
2212663f | 6101 | { |
617e0e1d DB |
6102 | { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP }, |
6103 | { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP }, | |
6104 | { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP }, | |
6105 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM }, | |
6106 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN }, | |
6107 | { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP }, | |
6108 | { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ }, | |
6109 | { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP }, | |
2212663f DB |
6110 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB }, |
6111 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH }, | |
6112 | { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW }, | |
20e26713 AH |
6113 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB }, |
6114 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX }, | |
6115 | { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH }, | |
6116 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB }, | |
6117 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX }, | |
6118 | { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH }, | |
a3170dc6 AH |
6119 | |
6120 | /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and | |
6121 | end with SPE_BUILTIN_EVSUBFUSIAAW. */ | |
6122 | { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS }, | |
6123 | { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW }, | |
6124 | { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW }, | |
6125 | { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW }, | |
6126 | { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW }, | |
6127 | { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW }, | |
6128 | { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW }, | |
6129 | { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB }, | |
6130 | { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH }, | |
6131 | { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS }, | |
6132 | { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF }, | |
6133 | { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI }, | |
6134 | { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF }, | |
6135 | { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI }, | |
6136 | { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF }, | |
6137 | { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI }, | |
6138 | { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ }, | |
6139 | { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF }, | |
6140 | { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI }, | |
6141 | { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ }, | |
6142 | { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS }, | |
6143 | { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG }, | |
6144 | { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA }, | |
6a599451 | 6145 | { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG }, |
a3170dc6 AH |
6146 | { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW }, |
6147 | { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW }, | |
6148 | { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW }, | |
6149 | { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW }, | |
a3170dc6 AH |
6150 | |
6151 | /* Place-holder. Leave as last unary SPE builtin. */ | |
6152 | { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW }, | |
2212663f DB |
6153 | }; |
6154 | ||
6155 | static rtx | |
a2369ed3 | 6156 | rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
6157 | { |
6158 | rtx pat; | |
6159 | tree arg0 = TREE_VALUE (arglist); | |
6160 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6161 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6162 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6163 | ||
0559cc77 DE |
6164 | if (icode == CODE_FOR_nothing) |
6165 | /* Builtin not supported on this processor. */ | |
6166 | return 0; | |
6167 | ||
20e26713 AH |
6168 | /* If we got invalid arguments bail out before generating bad rtl. */ |
6169 | if (arg0 == error_mark_node) | |
9a171fcd | 6170 | return const0_rtx; |
20e26713 | 6171 | |
0559cc77 DE |
6172 | if (icode == CODE_FOR_altivec_vspltisb |
6173 | || icode == CODE_FOR_altivec_vspltish | |
6174 | || icode == CODE_FOR_altivec_vspltisw | |
6175 | || icode == CODE_FOR_spe_evsplatfi | |
6176 | || icode == CODE_FOR_spe_evsplati) | |
b44140e7 AH |
6177 | { |
6178 | /* Only allow 5-bit *signed* literals. */ | |
b44140e7 AH |
6179 | if (GET_CODE (op0) != CONST_INT |
6180 | || INTVAL (op0) > 0x1f | |
6181 | || INTVAL (op0) < -0x1f) | |
6182 | { | |
6183 | error ("argument 1 must be a 5-bit signed literal"); | |
9a171fcd | 6184 | return const0_rtx; |
b44140e7 | 6185 | } |
b44140e7 AH |
6186 | } |
6187 | ||
c62f2db5 | 6188 | if (target == 0 |
2212663f DB |
6189 | || GET_MODE (target) != tmode |
6190 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6191 | target = gen_reg_rtx (tmode); | |
6192 | ||
6193 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6194 | op0 = copy_to_mode_reg (mode0, op0); | |
6195 | ||
6196 | pat = GEN_FCN (icode) (target, op0); | |
6197 | if (! pat) | |
6198 | return 0; | |
6199 | emit_insn (pat); | |
0ac081f6 | 6200 | |
2212663f DB |
6201 | return target; |
6202 | } | |
ae4b4a02 | 6203 | |
100c4561 | 6204 | static rtx |
a2369ed3 | 6205 | altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target) |
100c4561 AH |
6206 | { |
6207 | rtx pat, scratch1, scratch2; | |
6208 | tree arg0 = TREE_VALUE (arglist); | |
6209 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6210 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6211 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6212 | ||
6213 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
6214 | if (arg0 == error_mark_node) | |
9a171fcd | 6215 | return const0_rtx; |
100c4561 AH |
6216 | |
6217 | if (target == 0 | |
6218 | || GET_MODE (target) != tmode | |
6219 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6220 | target = gen_reg_rtx (tmode); | |
6221 | ||
6222 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6223 | op0 = copy_to_mode_reg (mode0, op0); | |
6224 | ||
6225 | scratch1 = gen_reg_rtx (mode0); | |
6226 | scratch2 = gen_reg_rtx (mode0); | |
6227 | ||
6228 | pat = GEN_FCN (icode) (target, op0, scratch1, scratch2); | |
6229 | if (! pat) | |
6230 | return 0; | |
6231 | emit_insn (pat); | |
6232 | ||
6233 | return target; | |
6234 | } | |
6235 | ||
0ac081f6 | 6236 | static rtx |
a2369ed3 | 6237 | rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target) |
0ac081f6 AH |
6238 | { |
6239 | rtx pat; | |
6240 | tree arg0 = TREE_VALUE (arglist); | |
6241 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6242 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6243 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6244 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6245 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6246 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6247 | ||
0559cc77 DE |
6248 | if (icode == CODE_FOR_nothing) |
6249 | /* Builtin not supported on this processor. */ | |
6250 | return 0; | |
6251 | ||
20e26713 AH |
6252 | /* If we got invalid arguments bail out before generating bad rtl. */ |
6253 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 6254 | return const0_rtx; |
20e26713 | 6255 | |
0559cc77 DE |
6256 | if (icode == CODE_FOR_altivec_vcfux |
6257 | || icode == CODE_FOR_altivec_vcfsx | |
6258 | || icode == CODE_FOR_altivec_vctsxs | |
6259 | || icode == CODE_FOR_altivec_vctuxs | |
6260 | || icode == CODE_FOR_altivec_vspltb | |
6261 | || icode == CODE_FOR_altivec_vsplth | |
6262 | || icode == CODE_FOR_altivec_vspltw | |
6263 | || icode == CODE_FOR_spe_evaddiw | |
6264 | || icode == CODE_FOR_spe_evldd | |
6265 | || icode == CODE_FOR_spe_evldh | |
6266 | || icode == CODE_FOR_spe_evldw | |
6267 | || icode == CODE_FOR_spe_evlhhesplat | |
6268 | || icode == CODE_FOR_spe_evlhhossplat | |
6269 | || icode == CODE_FOR_spe_evlhhousplat | |
6270 | || icode == CODE_FOR_spe_evlwhe | |
6271 | || icode == CODE_FOR_spe_evlwhos | |
6272 | || icode == CODE_FOR_spe_evlwhou | |
6273 | || icode == CODE_FOR_spe_evlwhsplat | |
6274 | || icode == CODE_FOR_spe_evlwwsplat | |
6275 | || icode == CODE_FOR_spe_evrlwi | |
6276 | || icode == CODE_FOR_spe_evslwi | |
6277 | || icode == CODE_FOR_spe_evsrwis | |
f5119d10 | 6278 | || icode == CODE_FOR_spe_evsubifw |
0559cc77 | 6279 | || icode == CODE_FOR_spe_evsrwiu) |
b44140e7 AH |
6280 | { |
6281 | /* Only allow 5-bit unsigned literals. */ | |
8bb418a3 | 6282 | STRIP_NOPS (arg1); |
b44140e7 AH |
6283 | if (TREE_CODE (arg1) != INTEGER_CST |
6284 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
6285 | { | |
6286 | error ("argument 2 must be a 5-bit unsigned literal"); | |
9a171fcd | 6287 | return const0_rtx; |
b44140e7 | 6288 | } |
b44140e7 AH |
6289 | } |
6290 | ||
c62f2db5 | 6291 | if (target == 0 |
0ac081f6 AH |
6292 | || GET_MODE (target) != tmode |
6293 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6294 | target = gen_reg_rtx (tmode); | |
6295 | ||
6296 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6297 | op0 = copy_to_mode_reg (mode0, op0); | |
6298 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6299 | op1 = copy_to_mode_reg (mode1, op1); | |
6300 | ||
6301 | pat = GEN_FCN (icode) (target, op0, op1); | |
6302 | if (! pat) | |
6303 | return 0; | |
6304 | emit_insn (pat); | |
6305 | ||
6306 | return target; | |
6307 | } | |
6525c0e7 | 6308 | |
ae4b4a02 | 6309 | static rtx |
f676971a | 6310 | altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode, |
a2369ed3 | 6311 | tree arglist, rtx target) |
ae4b4a02 AH |
6312 | { |
6313 | rtx pat, scratch; | |
6314 | tree cr6_form = TREE_VALUE (arglist); | |
6315 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6316 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6317 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6318 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6319 | enum machine_mode tmode = SImode; | |
6320 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6321 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6322 | int cr6_form_int; | |
6323 | ||
6324 | if (TREE_CODE (cr6_form) != INTEGER_CST) | |
6325 | { | |
6326 | error ("argument 1 of __builtin_altivec_predicate must be a constant"); | |
9a171fcd | 6327 | return const0_rtx; |
ae4b4a02 AH |
6328 | } |
6329 | else | |
6330 | cr6_form_int = TREE_INT_CST_LOW (cr6_form); | |
6331 | ||
6332 | if (mode0 != mode1) | |
6333 | abort (); | |
6334 | ||
6335 | /* If we have invalid arguments, bail out before generating bad rtl. */ | |
6336 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
9a171fcd | 6337 | return const0_rtx; |
ae4b4a02 AH |
6338 | |
6339 | if (target == 0 | |
6340 | || GET_MODE (target) != tmode | |
6341 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6342 | target = gen_reg_rtx (tmode); | |
6343 | ||
6344 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6345 | op0 = copy_to_mode_reg (mode0, op0); | |
6346 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6347 | op1 = copy_to_mode_reg (mode1, op1); | |
6348 | ||
6349 | scratch = gen_reg_rtx (mode0); | |
6350 | ||
6351 | pat = GEN_FCN (icode) (scratch, op0, op1, | |
f1c25d3b | 6352 | gen_rtx_SYMBOL_REF (Pmode, opcode)); |
ae4b4a02 AH |
6353 | if (! pat) |
6354 | return 0; | |
6355 | emit_insn (pat); | |
6356 | ||
6357 | /* The vec_any* and vec_all* predicates use the same opcodes for two | |
6358 | different operations, but the bits in CR6 will be different | |
6359 | depending on what information we want. So we have to play tricks | |
6360 | with CR6 to get the right bits out. | |
6361 | ||
6362 | If you think this is disgusting, look at the specs for the | |
6363 | AltiVec predicates. */ | |
6364 | ||
6365 | switch (cr6_form_int) | |
6366 | { | |
6367 | case 0: | |
6368 | emit_insn (gen_cr6_test_for_zero (target)); | |
6369 | break; | |
6370 | case 1: | |
6371 | emit_insn (gen_cr6_test_for_zero_reverse (target)); | |
6372 | break; | |
6373 | case 2: | |
6374 | emit_insn (gen_cr6_test_for_lt (target)); | |
6375 | break; | |
6376 | case 3: | |
6377 | emit_insn (gen_cr6_test_for_lt_reverse (target)); | |
6378 | break; | |
6379 | default: | |
6380 | error ("argument 1 of __builtin_altivec_predicate is out of range"); | |
6381 | break; | |
6382 | } | |
6383 | ||
6384 | return target; | |
6385 | } | |
6386 | ||
b4a62fa0 | 6387 | static rtx |
38f391a5 | 6388 | altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target) |
b4a62fa0 SB |
6389 | { |
6390 | rtx pat, addr; | |
6391 | tree arg0 = TREE_VALUE (arglist); | |
6392 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6393 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6394 | enum machine_mode mode0 = Pmode; | |
6395 | enum machine_mode mode1 = Pmode; | |
6396 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6397 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6398 | ||
6399 | if (icode == CODE_FOR_nothing) | |
6400 | /* Builtin not supported on this processor. */ | |
6401 | return 0; | |
6402 | ||
6403 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6404 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
6405 | return const0_rtx; | |
6406 | ||
6407 | if (target == 0 | |
6408 | || GET_MODE (target) != tmode | |
6409 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6410 | target = gen_reg_rtx (tmode); | |
6411 | ||
f676971a | 6412 | op1 = copy_to_mode_reg (mode1, op1); |
b4a62fa0 SB |
6413 | |
6414 | if (op0 == const0_rtx) | |
6415 | { | |
6416 | addr = gen_rtx_MEM (tmode, op1); | |
6417 | } | |
6418 | else | |
6419 | { | |
6420 | op0 = copy_to_mode_reg (mode0, op0); | |
6421 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1)); | |
6422 | } | |
6423 | ||
6424 | pat = GEN_FCN (icode) (target, addr); | |
6425 | ||
6426 | if (! pat) | |
6427 | return 0; | |
6428 | emit_insn (pat); | |
6429 | ||
6430 | return target; | |
6431 | } | |
6432 | ||
61bea3b0 AH |
6433 | static rtx |
6434 | spe_expand_stv_builtin (enum insn_code icode, tree arglist) | |
6435 | { | |
6436 | tree arg0 = TREE_VALUE (arglist); | |
6437 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6438 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6439 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6440 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6441 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6442 | rtx pat; | |
6443 | enum machine_mode mode0 = insn_data[icode].operand[0].mode; | |
6444 | enum machine_mode mode1 = insn_data[icode].operand[1].mode; | |
6445 | enum machine_mode mode2 = insn_data[icode].operand[2].mode; | |
6446 | ||
6447 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
6448 | if (arg0 == error_mark_node | |
6449 | || arg1 == error_mark_node | |
6450 | || arg2 == error_mark_node) | |
6451 | return const0_rtx; | |
6452 | ||
6453 | if (! (*insn_data[icode].operand[2].predicate) (op0, mode2)) | |
6454 | op0 = copy_to_mode_reg (mode2, op0); | |
6455 | if (! (*insn_data[icode].operand[0].predicate) (op1, mode0)) | |
6456 | op1 = copy_to_mode_reg (mode0, op1); | |
6457 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
6458 | op2 = copy_to_mode_reg (mode1, op2); | |
6459 | ||
6460 | pat = GEN_FCN (icode) (op1, op2, op0); | |
6461 | if (pat) | |
6462 | emit_insn (pat); | |
6463 | return NULL_RTX; | |
6464 | } | |
6465 | ||
6525c0e7 | 6466 | static rtx |
a2369ed3 | 6467 | altivec_expand_stv_builtin (enum insn_code icode, tree arglist) |
6525c0e7 AH |
6468 | { |
6469 | tree arg0 = TREE_VALUE (arglist); | |
6470 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6471 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6472 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6473 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6474 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
b4a62fa0 SB |
6475 | rtx pat, addr; |
6476 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6477 | enum machine_mode mode1 = Pmode; | |
6478 | enum machine_mode mode2 = Pmode; | |
6525c0e7 AH |
6479 | |
6480 | /* Invalid arguments. Bail before doing anything stoopid! */ | |
6481 | if (arg0 == error_mark_node | |
6482 | || arg1 == error_mark_node | |
6483 | || arg2 == error_mark_node) | |
9a171fcd | 6484 | return const0_rtx; |
6525c0e7 | 6485 | |
b4a62fa0 SB |
6486 | if (! (*insn_data[icode].operand[1].predicate) (op0, tmode)) |
6487 | op0 = copy_to_mode_reg (tmode, op0); | |
6488 | ||
f676971a | 6489 | op2 = copy_to_mode_reg (mode2, op2); |
b4a62fa0 SB |
6490 | |
6491 | if (op1 == const0_rtx) | |
6492 | { | |
6493 | addr = gen_rtx_MEM (tmode, op2); | |
6494 | } | |
6495 | else | |
6496 | { | |
6497 | op1 = copy_to_mode_reg (mode1, op1); | |
6498 | addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2)); | |
6499 | } | |
6525c0e7 | 6500 | |
b4a62fa0 | 6501 | pat = GEN_FCN (icode) (addr, op0); |
6525c0e7 AH |
6502 | if (pat) |
6503 | emit_insn (pat); | |
6504 | return NULL_RTX; | |
6505 | } | |
6506 | ||
2212663f | 6507 | static rtx |
a2369ed3 | 6508 | rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target) |
2212663f DB |
6509 | { |
6510 | rtx pat; | |
6511 | tree arg0 = TREE_VALUE (arglist); | |
6512 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6513 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6514 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6515 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6516 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6517 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
6518 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
6519 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
6520 | enum machine_mode mode2 = insn_data[icode].operand[3].mode; | |
0ac081f6 | 6521 | |
774b5662 DE |
6522 | if (icode == CODE_FOR_nothing) |
6523 | /* Builtin not supported on this processor. */ | |
6524 | return 0; | |
6525 | ||
20e26713 AH |
6526 | /* If we got invalid arguments bail out before generating bad rtl. */ |
6527 | if (arg0 == error_mark_node | |
6528 | || arg1 == error_mark_node | |
6529 | || arg2 == error_mark_node) | |
9a171fcd | 6530 | return const0_rtx; |
20e26713 | 6531 | |
774b5662 DE |
6532 | if (icode == CODE_FOR_altivec_vsldoi_4sf |
6533 | || icode == CODE_FOR_altivec_vsldoi_4si | |
6534 | || icode == CODE_FOR_altivec_vsldoi_8hi | |
6535 | || icode == CODE_FOR_altivec_vsldoi_16qi) | |
b44140e7 AH |
6536 | { |
6537 | /* Only allow 4-bit unsigned literals. */ | |
8bb418a3 | 6538 | STRIP_NOPS (arg2); |
b44140e7 AH |
6539 | if (TREE_CODE (arg2) != INTEGER_CST |
6540 | || TREE_INT_CST_LOW (arg2) & ~0xf) | |
6541 | { | |
6542 | error ("argument 3 must be a 4-bit unsigned literal"); | |
e3277ffb | 6543 | return const0_rtx; |
b44140e7 | 6544 | } |
b44140e7 AH |
6545 | } |
6546 | ||
c62f2db5 | 6547 | if (target == 0 |
2212663f DB |
6548 | || GET_MODE (target) != tmode |
6549 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6550 | target = gen_reg_rtx (tmode); | |
6551 | ||
6552 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
6553 | op0 = copy_to_mode_reg (mode0, op0); | |
6554 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
6555 | op1 = copy_to_mode_reg (mode1, op1); | |
6556 | if (! (*insn_data[icode].operand[3].predicate) (op2, mode2)) | |
6557 | op2 = copy_to_mode_reg (mode2, op2); | |
6558 | ||
6559 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
6560 | if (! pat) | |
6561 | return 0; | |
6562 | emit_insn (pat); | |
6563 | ||
6564 | return target; | |
6565 | } | |
92898235 | 6566 | |
3a9b8c7e | 6567 | /* Expand the lvx builtins. */ |
0ac081f6 | 6568 | static rtx |
a2369ed3 | 6569 | altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp) |
0ac081f6 | 6570 | { |
0ac081f6 AH |
6571 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
6572 | tree arglist = TREE_OPERAND (exp, 1); | |
0ac081f6 | 6573 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
3a9b8c7e AH |
6574 | tree arg0; |
6575 | enum machine_mode tmode, mode0; | |
7c3abc73 | 6576 | rtx pat, op0; |
3a9b8c7e | 6577 | enum insn_code icode; |
92898235 | 6578 | |
0ac081f6 AH |
6579 | switch (fcode) |
6580 | { | |
f18c054f DB |
6581 | case ALTIVEC_BUILTIN_LD_INTERNAL_16qi: |
6582 | icode = CODE_FOR_altivec_lvx_16qi; | |
3a9b8c7e | 6583 | break; |
f18c054f DB |
6584 | case ALTIVEC_BUILTIN_LD_INTERNAL_8hi: |
6585 | icode = CODE_FOR_altivec_lvx_8hi; | |
3a9b8c7e AH |
6586 | break; |
6587 | case ALTIVEC_BUILTIN_LD_INTERNAL_4si: | |
6588 | icode = CODE_FOR_altivec_lvx_4si; | |
6589 | break; | |
6590 | case ALTIVEC_BUILTIN_LD_INTERNAL_4sf: | |
6591 | icode = CODE_FOR_altivec_lvx_4sf; | |
6592 | break; | |
6593 | default: | |
6594 | *expandedp = false; | |
6595 | return NULL_RTX; | |
6596 | } | |
0ac081f6 | 6597 | |
3a9b8c7e | 6598 | *expandedp = true; |
f18c054f | 6599 | |
3a9b8c7e AH |
6600 | arg0 = TREE_VALUE (arglist); |
6601 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6602 | tmode = insn_data[icode].operand[0].mode; | |
6603 | mode0 = insn_data[icode].operand[1].mode; | |
f18c054f | 6604 | |
3a9b8c7e AH |
6605 | if (target == 0 |
6606 | || GET_MODE (target) != tmode | |
6607 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6608 | target = gen_reg_rtx (tmode); | |
24408032 | 6609 | |
3a9b8c7e AH |
6610 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) |
6611 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
f18c054f | 6612 | |
3a9b8c7e AH |
6613 | pat = GEN_FCN (icode) (target, op0); |
6614 | if (! pat) | |
6615 | return 0; | |
6616 | emit_insn (pat); | |
6617 | return target; | |
6618 | } | |
f18c054f | 6619 | |
3a9b8c7e AH |
6620 | /* Expand the stvx builtins. */ |
6621 | static rtx | |
f676971a | 6622 | altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
a2369ed3 | 6623 | bool *expandedp) |
3a9b8c7e AH |
6624 | { |
6625 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6626 | tree arglist = TREE_OPERAND (exp, 1); | |
6627 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6628 | tree arg0, arg1; | |
6629 | enum machine_mode mode0, mode1; | |
7c3abc73 | 6630 | rtx pat, op0, op1; |
3a9b8c7e | 6631 | enum insn_code icode; |
f18c054f | 6632 | |
3a9b8c7e AH |
6633 | switch (fcode) |
6634 | { | |
6635 | case ALTIVEC_BUILTIN_ST_INTERNAL_16qi: | |
6636 | icode = CODE_FOR_altivec_stvx_16qi; | |
6637 | break; | |
6638 | case ALTIVEC_BUILTIN_ST_INTERNAL_8hi: | |
6639 | icode = CODE_FOR_altivec_stvx_8hi; | |
6640 | break; | |
6641 | case ALTIVEC_BUILTIN_ST_INTERNAL_4si: | |
6642 | icode = CODE_FOR_altivec_stvx_4si; | |
6643 | break; | |
6644 | case ALTIVEC_BUILTIN_ST_INTERNAL_4sf: | |
6645 | icode = CODE_FOR_altivec_stvx_4sf; | |
6646 | break; | |
6647 | default: | |
6648 | *expandedp = false; | |
6649 | return NULL_RTX; | |
6650 | } | |
24408032 | 6651 | |
3a9b8c7e AH |
6652 | arg0 = TREE_VALUE (arglist); |
6653 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6654 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6655 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6656 | mode0 = insn_data[icode].operand[0].mode; | |
6657 | mode1 = insn_data[icode].operand[1].mode; | |
f18c054f | 6658 | |
3a9b8c7e AH |
6659 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
6660 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); | |
6661 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
6662 | op1 = copy_to_mode_reg (mode1, op1); | |
f18c054f | 6663 | |
3a9b8c7e AH |
6664 | pat = GEN_FCN (icode) (op0, op1); |
6665 | if (pat) | |
6666 | emit_insn (pat); | |
f18c054f | 6667 | |
3a9b8c7e AH |
6668 | *expandedp = true; |
6669 | return NULL_RTX; | |
6670 | } | |
f18c054f | 6671 | |
3a9b8c7e AH |
6672 | /* Expand the dst builtins. */ |
6673 | static rtx | |
f676971a | 6674 | altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED, |
a2369ed3 | 6675 | bool *expandedp) |
3a9b8c7e AH |
6676 | { |
6677 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6678 | tree arglist = TREE_OPERAND (exp, 1); | |
6679 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6680 | tree arg0, arg1, arg2; | |
6681 | enum machine_mode mode0, mode1, mode2; | |
7c3abc73 | 6682 | rtx pat, op0, op1, op2; |
3a9b8c7e | 6683 | struct builtin_description *d; |
a3170dc6 | 6684 | size_t i; |
f18c054f | 6685 | |
3a9b8c7e | 6686 | *expandedp = false; |
f18c054f | 6687 | |
3a9b8c7e AH |
6688 | /* Handle DST variants. */ |
6689 | d = (struct builtin_description *) bdesc_dst; | |
6690 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
6691 | if (d->code == fcode) | |
6692 | { | |
6693 | arg0 = TREE_VALUE (arglist); | |
6694 | arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
6695 | arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6696 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6697 | op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
6698 | op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
6699 | mode0 = insn_data[d->icode].operand[0].mode; | |
6700 | mode1 = insn_data[d->icode].operand[1].mode; | |
6701 | mode2 = insn_data[d->icode].operand[2].mode; | |
24408032 | 6702 | |
3a9b8c7e AH |
6703 | /* Invalid arguments, bail out before generating bad rtl. */ |
6704 | if (arg0 == error_mark_node | |
6705 | || arg1 == error_mark_node | |
6706 | || arg2 == error_mark_node) | |
6707 | return const0_rtx; | |
f18c054f | 6708 | |
86e7df90 | 6709 | *expandedp = true; |
8bb418a3 | 6710 | STRIP_NOPS (arg2); |
3a9b8c7e AH |
6711 | if (TREE_CODE (arg2) != INTEGER_CST |
6712 | || TREE_INT_CST_LOW (arg2) & ~0x3) | |
6713 | { | |
6714 | error ("argument to `%s' must be a 2-bit unsigned literal", d->name); | |
6715 | return const0_rtx; | |
6716 | } | |
f18c054f | 6717 | |
3a9b8c7e | 6718 | if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0)) |
b4a62fa0 | 6719 | op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0)); |
3a9b8c7e AH |
6720 | if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1)) |
6721 | op1 = copy_to_mode_reg (mode1, op1); | |
24408032 | 6722 | |
3a9b8c7e AH |
6723 | pat = GEN_FCN (d->icode) (op0, op1, op2); |
6724 | if (pat != 0) | |
6725 | emit_insn (pat); | |
f18c054f | 6726 | |
3a9b8c7e AH |
6727 | return NULL_RTX; |
6728 | } | |
f18c054f | 6729 | |
3a9b8c7e AH |
6730 | return NULL_RTX; |
6731 | } | |
24408032 | 6732 | |
3a9b8c7e AH |
6733 | /* Expand the builtin in EXP and store the result in TARGET. Store |
6734 | true in *EXPANDEDP if we found a builtin to expand. */ | |
6735 | static rtx | |
a2369ed3 | 6736 | altivec_expand_builtin (tree exp, rtx target, bool *expandedp) |
3a9b8c7e AH |
6737 | { |
6738 | struct builtin_description *d; | |
6739 | struct builtin_description_predicates *dp; | |
6740 | size_t i; | |
6741 | enum insn_code icode; | |
6742 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6743 | tree arglist = TREE_OPERAND (exp, 1); | |
7c3abc73 AH |
6744 | tree arg0; |
6745 | rtx op0, pat; | |
6746 | enum machine_mode tmode, mode0; | |
3a9b8c7e | 6747 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); |
0ac081f6 | 6748 | |
3a9b8c7e AH |
6749 | target = altivec_expand_ld_builtin (exp, target, expandedp); |
6750 | if (*expandedp) | |
6751 | return target; | |
0ac081f6 | 6752 | |
3a9b8c7e AH |
6753 | target = altivec_expand_st_builtin (exp, target, expandedp); |
6754 | if (*expandedp) | |
6755 | return target; | |
6756 | ||
6757 | target = altivec_expand_dst_builtin (exp, target, expandedp); | |
6758 | if (*expandedp) | |
6759 | return target; | |
6760 | ||
6761 | *expandedp = true; | |
95385cbb | 6762 | |
3a9b8c7e AH |
6763 | switch (fcode) |
6764 | { | |
6525c0e7 AH |
6765 | case ALTIVEC_BUILTIN_STVX: |
6766 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist); | |
6767 | case ALTIVEC_BUILTIN_STVEBX: | |
6768 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist); | |
6769 | case ALTIVEC_BUILTIN_STVEHX: | |
6770 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist); | |
6771 | case ALTIVEC_BUILTIN_STVEWX: | |
6772 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist); | |
6773 | case ALTIVEC_BUILTIN_STVXL: | |
6774 | return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist); | |
3a9b8c7e | 6775 | |
95385cbb AH |
6776 | case ALTIVEC_BUILTIN_MFVSCR: |
6777 | icode = CODE_FOR_altivec_mfvscr; | |
6778 | tmode = insn_data[icode].operand[0].mode; | |
6779 | ||
6780 | if (target == 0 | |
6781 | || GET_MODE (target) != tmode | |
6782 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
6783 | target = gen_reg_rtx (tmode); | |
f676971a | 6784 | |
95385cbb | 6785 | pat = GEN_FCN (icode) (target); |
0ac081f6 AH |
6786 | if (! pat) |
6787 | return 0; | |
6788 | emit_insn (pat); | |
95385cbb AH |
6789 | return target; |
6790 | ||
6791 | case ALTIVEC_BUILTIN_MTVSCR: | |
6792 | icode = CODE_FOR_altivec_mtvscr; | |
6793 | arg0 = TREE_VALUE (arglist); | |
6794 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
6795 | mode0 = insn_data[icode].operand[0].mode; | |
6796 | ||
6797 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6798 | if (arg0 == error_mark_node) | |
9a171fcd | 6799 | return const0_rtx; |
95385cbb AH |
6800 | |
6801 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
6802 | op0 = copy_to_mode_reg (mode0, op0); | |
6803 | ||
6804 | pat = GEN_FCN (icode) (op0); | |
6805 | if (pat) | |
6806 | emit_insn (pat); | |
6807 | return NULL_RTX; | |
3a9b8c7e | 6808 | |
95385cbb AH |
6809 | case ALTIVEC_BUILTIN_DSSALL: |
6810 | emit_insn (gen_altivec_dssall ()); | |
6811 | return NULL_RTX; | |
6812 | ||
6813 | case ALTIVEC_BUILTIN_DSS: | |
6814 | icode = CODE_FOR_altivec_dss; | |
6815 | arg0 = TREE_VALUE (arglist); | |
8bb418a3 | 6816 | STRIP_NOPS (arg0); |
95385cbb AH |
6817 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); |
6818 | mode0 = insn_data[icode].operand[0].mode; | |
6819 | ||
6820 | /* If we got invalid arguments bail out before generating bad rtl. */ | |
6821 | if (arg0 == error_mark_node) | |
9a171fcd | 6822 | return const0_rtx; |
95385cbb | 6823 | |
b44140e7 AH |
6824 | if (TREE_CODE (arg0) != INTEGER_CST |
6825 | || TREE_INT_CST_LOW (arg0) & ~0x3) | |
6826 | { | |
6827 | error ("argument to dss must be a 2-bit unsigned literal"); | |
9a171fcd | 6828 | return const0_rtx; |
b44140e7 AH |
6829 | } |
6830 | ||
95385cbb AH |
6831 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) |
6832 | op0 = copy_to_mode_reg (mode0, op0); | |
6833 | ||
6834 | emit_insn (gen_altivec_dss (op0)); | |
0ac081f6 | 6835 | return NULL_RTX; |
f676971a | 6836 | |
8bb418a3 ZL |
6837 | case ALTIVEC_BUILTIN_COMPILETIME_ERROR: |
6838 | arg0 = TREE_VALUE (arglist); | |
97dc04b3 RH |
6839 | while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR |
6840 | || TREE_CODE (arg0) == ARRAY_REF) | |
8bb418a3 ZL |
6841 | arg0 = TREE_OPERAND (arg0, 0); |
6842 | error ("invalid parameter combination for `%s' AltiVec intrinsic", | |
6843 | TREE_STRING_POINTER (arg0)); | |
6844 | ||
6845 | return const0_rtx; | |
0ac081f6 | 6846 | } |
24408032 | 6847 | |
100c4561 AH |
6848 | /* Expand abs* operations. */ |
6849 | d = (struct builtin_description *) bdesc_abs; | |
ca7558fc | 6850 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) |
100c4561 AH |
6851 | if (d->code == fcode) |
6852 | return altivec_expand_abs_builtin (d->icode, arglist, target); | |
6853 | ||
ae4b4a02 AH |
6854 | /* Expand the AltiVec predicates. */ |
6855 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
ca7558fc | 6856 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) |
ae4b4a02 AH |
6857 | if (dp->code == fcode) |
6858 | return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target); | |
6859 | ||
6525c0e7 AH |
6860 | /* LV* are funky. We initialized them differently. */ |
6861 | switch (fcode) | |
6862 | { | |
6863 | case ALTIVEC_BUILTIN_LVSL: | |
b4a62fa0 | 6864 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl, |
6525c0e7 AH |
6865 | arglist, target); |
6866 | case ALTIVEC_BUILTIN_LVSR: | |
b4a62fa0 | 6867 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr, |
92898235 | 6868 | arglist, target); |
6525c0e7 | 6869 | case ALTIVEC_BUILTIN_LVEBX: |
b4a62fa0 | 6870 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx, |
92898235 | 6871 | arglist, target); |
6525c0e7 | 6872 | case ALTIVEC_BUILTIN_LVEHX: |
b4a62fa0 | 6873 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx, |
92898235 | 6874 | arglist, target); |
6525c0e7 | 6875 | case ALTIVEC_BUILTIN_LVEWX: |
b4a62fa0 | 6876 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx, |
92898235 | 6877 | arglist, target); |
6525c0e7 | 6878 | case ALTIVEC_BUILTIN_LVXL: |
b4a62fa0 | 6879 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl, |
92898235 | 6880 | arglist, target); |
6525c0e7 | 6881 | case ALTIVEC_BUILTIN_LVX: |
b4a62fa0 | 6882 | return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx, |
92898235 | 6883 | arglist, target); |
6525c0e7 AH |
6884 | default: |
6885 | break; | |
6886 | /* Fall through. */ | |
6887 | } | |
95385cbb | 6888 | |
92898235 | 6889 | *expandedp = false; |
0ac081f6 AH |
6890 | return NULL_RTX; |
6891 | } | |
6892 | ||
a3170dc6 AH |
6893 | /* Binops that need to be initialized manually, but can be expanded |
6894 | automagically by rs6000_expand_binop_builtin. */ | |
6895 | static struct builtin_description bdesc_2arg_spe[] = | |
6896 | { | |
6897 | { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX }, | |
6898 | { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX }, | |
6899 | { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX }, | |
6900 | { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX }, | |
6901 | { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX }, | |
6902 | { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX }, | |
6903 | { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX }, | |
6904 | { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX }, | |
6905 | { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX }, | |
6906 | { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX }, | |
6907 | { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX }, | |
6908 | { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD }, | |
6909 | { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW }, | |
6910 | { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH }, | |
6911 | { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE }, | |
6912 | { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU }, | |
6913 | { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS }, | |
6914 | { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT }, | |
6915 | { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT }, | |
6916 | { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT }, | |
6917 | { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT }, | |
6918 | { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT } | |
6919 | }; | |
6920 | ||
6921 | /* Expand the builtin in EXP and store the result in TARGET. Store | |
6922 | true in *EXPANDEDP if we found a builtin to expand. | |
6923 | ||
6924 | This expands the SPE builtins that are not simple unary and binary | |
6925 | operations. */ | |
6926 | static rtx | |
a2369ed3 | 6927 | spe_expand_builtin (tree exp, rtx target, bool *expandedp) |
a3170dc6 AH |
6928 | { |
6929 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
6930 | tree arglist = TREE_OPERAND (exp, 1); | |
6931 | tree arg1, arg0; | |
6932 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
6933 | enum insn_code icode; | |
6934 | enum machine_mode tmode, mode0; | |
6935 | rtx pat, op0; | |
6936 | struct builtin_description *d; | |
6937 | size_t i; | |
6938 | ||
6939 | *expandedp = true; | |
6940 | ||
6941 | /* Syntax check for a 5-bit unsigned immediate. */ | |
6942 | switch (fcode) | |
6943 | { | |
6944 | case SPE_BUILTIN_EVSTDD: | |
6945 | case SPE_BUILTIN_EVSTDH: | |
6946 | case SPE_BUILTIN_EVSTDW: | |
6947 | case SPE_BUILTIN_EVSTWHE: | |
6948 | case SPE_BUILTIN_EVSTWHO: | |
6949 | case SPE_BUILTIN_EVSTWWE: | |
6950 | case SPE_BUILTIN_EVSTWWO: | |
6951 | arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
6952 | if (TREE_CODE (arg1) != INTEGER_CST | |
6953 | || TREE_INT_CST_LOW (arg1) & ~0x1f) | |
6954 | { | |
6955 | error ("argument 2 must be a 5-bit unsigned literal"); | |
6956 | return const0_rtx; | |
6957 | } | |
6958 | break; | |
6959 | default: | |
6960 | break; | |
6961 | } | |
6962 | ||
00332c9f AH |
6963 | /* The evsplat*i instructions are not quite generic. */ |
6964 | switch (fcode) | |
6965 | { | |
6966 | case SPE_BUILTIN_EVSPLATFI: | |
6967 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi, | |
6968 | arglist, target); | |
6969 | case SPE_BUILTIN_EVSPLATI: | |
6970 | return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati, | |
6971 | arglist, target); | |
6972 | default: | |
6973 | break; | |
6974 | } | |
6975 | ||
a3170dc6 AH |
6976 | d = (struct builtin_description *) bdesc_2arg_spe; |
6977 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d) | |
6978 | if (d->code == fcode) | |
6979 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
6980 | ||
6981 | d = (struct builtin_description *) bdesc_spe_predicates; | |
6982 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d) | |
6983 | if (d->code == fcode) | |
6984 | return spe_expand_predicate_builtin (d->icode, arglist, target); | |
6985 | ||
6986 | d = (struct builtin_description *) bdesc_spe_evsel; | |
6987 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d) | |
6988 | if (d->code == fcode) | |
6989 | return spe_expand_evsel_builtin (d->icode, arglist, target); | |
6990 | ||
6991 | switch (fcode) | |
6992 | { | |
6993 | case SPE_BUILTIN_EVSTDDX: | |
61bea3b0 | 6994 | return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist); |
a3170dc6 | 6995 | case SPE_BUILTIN_EVSTDHX: |
61bea3b0 | 6996 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist); |
a3170dc6 | 6997 | case SPE_BUILTIN_EVSTDWX: |
61bea3b0 | 6998 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist); |
a3170dc6 | 6999 | case SPE_BUILTIN_EVSTWHEX: |
61bea3b0 | 7000 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist); |
a3170dc6 | 7001 | case SPE_BUILTIN_EVSTWHOX: |
61bea3b0 | 7002 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist); |
a3170dc6 | 7003 | case SPE_BUILTIN_EVSTWWEX: |
61bea3b0 | 7004 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist); |
a3170dc6 | 7005 | case SPE_BUILTIN_EVSTWWOX: |
61bea3b0 | 7006 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist); |
a3170dc6 | 7007 | case SPE_BUILTIN_EVSTDD: |
61bea3b0 | 7008 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist); |
a3170dc6 | 7009 | case SPE_BUILTIN_EVSTDH: |
61bea3b0 | 7010 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist); |
a3170dc6 | 7011 | case SPE_BUILTIN_EVSTDW: |
61bea3b0 | 7012 | return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist); |
a3170dc6 | 7013 | case SPE_BUILTIN_EVSTWHE: |
61bea3b0 | 7014 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist); |
a3170dc6 | 7015 | case SPE_BUILTIN_EVSTWHO: |
61bea3b0 | 7016 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist); |
a3170dc6 | 7017 | case SPE_BUILTIN_EVSTWWE: |
61bea3b0 | 7018 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist); |
a3170dc6 | 7019 | case SPE_BUILTIN_EVSTWWO: |
61bea3b0 | 7020 | return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist); |
a3170dc6 AH |
7021 | case SPE_BUILTIN_MFSPEFSCR: |
7022 | icode = CODE_FOR_spe_mfspefscr; | |
7023 | tmode = insn_data[icode].operand[0].mode; | |
7024 | ||
7025 | if (target == 0 | |
7026 | || GET_MODE (target) != tmode | |
7027 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
7028 | target = gen_reg_rtx (tmode); | |
f676971a | 7029 | |
a3170dc6 AH |
7030 | pat = GEN_FCN (icode) (target); |
7031 | if (! pat) | |
7032 | return 0; | |
7033 | emit_insn (pat); | |
7034 | return target; | |
7035 | case SPE_BUILTIN_MTSPEFSCR: | |
7036 | icode = CODE_FOR_spe_mtspefscr; | |
7037 | arg0 = TREE_VALUE (arglist); | |
7038 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
7039 | mode0 = insn_data[icode].operand[0].mode; | |
7040 | ||
7041 | if (arg0 == error_mark_node) | |
7042 | return const0_rtx; | |
7043 | ||
7044 | if (! (*insn_data[icode].operand[0].predicate) (op0, mode0)) | |
7045 | op0 = copy_to_mode_reg (mode0, op0); | |
7046 | ||
7047 | pat = GEN_FCN (icode) (op0); | |
7048 | if (pat) | |
7049 | emit_insn (pat); | |
7050 | return NULL_RTX; | |
7051 | default: | |
7052 | break; | |
7053 | } | |
7054 | ||
7055 | *expandedp = false; | |
7056 | return NULL_RTX; | |
7057 | } | |
7058 | ||
7059 | static rtx | |
a2369ed3 | 7060 | spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
7061 | { |
7062 | rtx pat, scratch, tmp; | |
7063 | tree form = TREE_VALUE (arglist); | |
7064 | tree arg0 = TREE_VALUE (TREE_CHAIN (arglist)); | |
7065 | tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
7066 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
7067 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
7068 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
7069 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
7070 | int form_int; | |
7071 | enum rtx_code code; | |
7072 | ||
7073 | if (TREE_CODE (form) != INTEGER_CST) | |
7074 | { | |
7075 | error ("argument 1 of __builtin_spe_predicate must be a constant"); | |
7076 | return const0_rtx; | |
7077 | } | |
7078 | else | |
7079 | form_int = TREE_INT_CST_LOW (form); | |
7080 | ||
7081 | if (mode0 != mode1) | |
7082 | abort (); | |
7083 | ||
7084 | if (arg0 == error_mark_node || arg1 == error_mark_node) | |
7085 | return const0_rtx; | |
7086 | ||
7087 | if (target == 0 | |
7088 | || GET_MODE (target) != SImode | |
7089 | || ! (*insn_data[icode].operand[0].predicate) (target, SImode)) | |
7090 | target = gen_reg_rtx (SImode); | |
7091 | ||
7092 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
7093 | op0 = copy_to_mode_reg (mode0, op0); | |
7094 | if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) | |
7095 | op1 = copy_to_mode_reg (mode1, op1); | |
7096 | ||
7097 | scratch = gen_reg_rtx (CCmode); | |
7098 | ||
7099 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
7100 | if (! pat) | |
7101 | return const0_rtx; | |
7102 | emit_insn (pat); | |
7103 | ||
7104 | /* There are 4 variants for each predicate: _any_, _all_, _upper_, | |
7105 | _lower_. We use one compare, but look in different bits of the | |
7106 | CR for each variant. | |
7107 | ||
7108 | There are 2 elements in each SPE simd type (upper/lower). The CR | |
7109 | bits are set as follows: | |
7110 | ||
7111 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
7112 | U | L | (U | L) | (U & L) | |
7113 | ||
7114 | So, for an "all" relationship, BIT 3 would be set. | |
7115 | For an "any" relationship, BIT 2 would be set. Etc. | |
7116 | ||
7117 | Following traditional nomenclature, these bits map to: | |
7118 | ||
7119 | BIT0 | BIT 1 | BIT 2 | BIT 3 | |
7120 | LT | GT | EQ | OV | |
7121 | ||
7122 | Later, we will generate rtl to look in the LT/EQ/EQ/OV bits. | |
7123 | */ | |
7124 | ||
7125 | switch (form_int) | |
7126 | { | |
7127 | /* All variant. OV bit. */ | |
7128 | case 0: | |
7129 | /* We need to get to the OV bit, which is the ORDERED bit. We | |
7130 | could generate (ordered:SI (reg:CC xx) (const_int 0)), but | |
7131 | that's ugly and will trigger a validate_condition_mode abort. | |
7132 | So let's just use another pattern. */ | |
7133 | emit_insn (gen_move_from_CR_ov_bit (target, scratch)); | |
7134 | return target; | |
7135 | /* Any variant. EQ bit. */ | |
7136 | case 1: | |
7137 | code = EQ; | |
7138 | break; | |
7139 | /* Upper variant. LT bit. */ | |
7140 | case 2: | |
7141 | code = LT; | |
7142 | break; | |
7143 | /* Lower variant. GT bit. */ | |
7144 | case 3: | |
7145 | code = GT; | |
7146 | break; | |
7147 | default: | |
7148 | error ("argument 1 of __builtin_spe_predicate is out of range"); | |
7149 | return const0_rtx; | |
7150 | } | |
7151 | ||
7152 | tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx); | |
7153 | emit_move_insn (target, tmp); | |
7154 | ||
7155 | return target; | |
7156 | } | |
7157 | ||
7158 | /* The evsel builtins look like this: | |
7159 | ||
7160 | e = __builtin_spe_evsel_OP (a, b, c, d); | |
7161 | ||
7162 | and work like this: | |
7163 | ||
7164 | e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper]; | |
7165 | e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower]; | |
7166 | */ | |
7167 | ||
7168 | static rtx | |
a2369ed3 | 7169 | spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target) |
a3170dc6 AH |
7170 | { |
7171 | rtx pat, scratch; | |
7172 | tree arg0 = TREE_VALUE (arglist); | |
7173 | tree arg1 = TREE_VALUE (TREE_CHAIN (arglist)); | |
7174 | tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist))); | |
7175 | tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist)))); | |
7176 | rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
7177 | rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0); | |
7178 | rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0); | |
7179 | rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0); | |
7180 | enum machine_mode mode0 = insn_data[icode].operand[1].mode; | |
7181 | enum machine_mode mode1 = insn_data[icode].operand[2].mode; | |
7182 | ||
7183 | if (mode0 != mode1) | |
7184 | abort (); | |
7185 | ||
7186 | if (arg0 == error_mark_node || arg1 == error_mark_node | |
7187 | || arg2 == error_mark_node || arg3 == error_mark_node) | |
7188 | return const0_rtx; | |
7189 | ||
7190 | if (target == 0 | |
7191 | || GET_MODE (target) != mode0 | |
7192 | || ! (*insn_data[icode].operand[0].predicate) (target, mode0)) | |
7193 | target = gen_reg_rtx (mode0); | |
7194 | ||
7195 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
7196 | op0 = copy_to_mode_reg (mode0, op0); | |
7197 | if (! (*insn_data[icode].operand[1].predicate) (op1, mode1)) | |
7198 | op1 = copy_to_mode_reg (mode0, op1); | |
7199 | if (! (*insn_data[icode].operand[1].predicate) (op2, mode1)) | |
7200 | op2 = copy_to_mode_reg (mode0, op2); | |
7201 | if (! (*insn_data[icode].operand[1].predicate) (op3, mode1)) | |
7202 | op3 = copy_to_mode_reg (mode0, op3); | |
7203 | ||
7204 | /* Generate the compare. */ | |
7205 | scratch = gen_reg_rtx (CCmode); | |
7206 | pat = GEN_FCN (icode) (scratch, op0, op1); | |
7207 | if (! pat) | |
7208 | return const0_rtx; | |
7209 | emit_insn (pat); | |
7210 | ||
7211 | if (mode0 == V2SImode) | |
7212 | emit_insn (gen_spe_evsel (target, op2, op3, scratch)); | |
7213 | else | |
7214 | emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch)); | |
7215 | ||
7216 | return target; | |
7217 | } | |
7218 | ||
0ac081f6 AH |
7219 | /* Expand an expression EXP that calls a built-in function, |
7220 | with result going to TARGET if that's convenient | |
7221 | (and in mode MODE if that's convenient). | |
7222 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
7223 | IGNORE is nonzero if the value is to be ignored. */ | |
7224 | ||
7225 | static rtx | |
a2369ed3 | 7226 | rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, |
f676971a | 7227 | enum machine_mode mode ATTRIBUTE_UNUSED, |
a2369ed3 | 7228 | int ignore ATTRIBUTE_UNUSED) |
0ac081f6 | 7229 | { |
92898235 AH |
7230 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); |
7231 | tree arglist = TREE_OPERAND (exp, 1); | |
7232 | unsigned int fcode = DECL_FUNCTION_CODE (fndecl); | |
7233 | struct builtin_description *d; | |
7234 | size_t i; | |
7235 | rtx ret; | |
7236 | bool success; | |
f676971a | 7237 | |
7ccf35ed DN |
7238 | if (fcode == ALTIVEC_BUILTIN_MASK_FOR_LOAD |
7239 | || fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE) | |
7240 | { | |
7241 | int icode = (int) CODE_FOR_altivec_lvsr; | |
7242 | enum machine_mode tmode = insn_data[icode].operand[0].mode; | |
7243 | enum machine_mode mode = insn_data[icode].operand[1].mode; | |
7244 | tree arg; | |
7245 | rtx op, addr, pat; | |
7246 | ||
7247 | if (!TARGET_ALTIVEC) | |
7248 | abort (); | |
7249 | ||
7250 | arg = TREE_VALUE (arglist); | |
7251 | if (TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE) | |
7252 | abort (); | |
7253 | op = expand_expr (arg, NULL_RTX, Pmode, EXPAND_NORMAL); | |
7254 | addr = memory_address (mode, op); | |
7255 | if (fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE) | |
7256 | op = addr; | |
7257 | else | |
7258 | { | |
7259 | /* For the load case need to negate the address. */ | |
7260 | op = gen_reg_rtx (GET_MODE (addr)); | |
7261 | emit_insn (gen_rtx_SET (VOIDmode, op, | |
7262 | gen_rtx_NEG (GET_MODE (addr), addr))); | |
7263 | } | |
7264 | op = gen_rtx_MEM (mode, op); | |
7265 | ||
7266 | if (target == 0 | |
7267 | || GET_MODE (target) != tmode | |
7268 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
7269 | target = gen_reg_rtx (tmode); | |
7270 | ||
7271 | /*pat = gen_altivec_lvsr (target, op);*/ | |
7272 | pat = GEN_FCN (icode) (target, op); | |
7273 | if (!pat) | |
7274 | return 0; | |
7275 | emit_insn (pat); | |
7276 | ||
7277 | return target; | |
7278 | } | |
7279 | ||
0ac081f6 | 7280 | if (TARGET_ALTIVEC) |
92898235 AH |
7281 | { |
7282 | ret = altivec_expand_builtin (exp, target, &success); | |
7283 | ||
a3170dc6 AH |
7284 | if (success) |
7285 | return ret; | |
7286 | } | |
7287 | if (TARGET_SPE) | |
7288 | { | |
7289 | ret = spe_expand_builtin (exp, target, &success); | |
7290 | ||
92898235 AH |
7291 | if (success) |
7292 | return ret; | |
7293 | } | |
7294 | ||
0559cc77 DE |
7295 | if (TARGET_ALTIVEC || TARGET_SPE) |
7296 | { | |
7297 | /* Handle simple unary operations. */ | |
7298 | d = (struct builtin_description *) bdesc_1arg; | |
7299 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) | |
7300 | if (d->code == fcode) | |
7301 | return rs6000_expand_unop_builtin (d->icode, arglist, target); | |
7302 | ||
7303 | /* Handle simple binary operations. */ | |
7304 | d = (struct builtin_description *) bdesc_2arg; | |
7305 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) | |
7306 | if (d->code == fcode) | |
7307 | return rs6000_expand_binop_builtin (d->icode, arglist, target); | |
7308 | ||
7309 | /* Handle simple ternary operations. */ | |
7310 | d = (struct builtin_description *) bdesc_3arg; | |
7311 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) | |
7312 | if (d->code == fcode) | |
7313 | return rs6000_expand_ternop_builtin (d->icode, arglist, target); | |
7314 | } | |
0ac081f6 AH |
7315 | |
7316 | abort (); | |
92898235 | 7317 | return NULL_RTX; |
0ac081f6 AH |
7318 | } |
7319 | ||
7c62e993 PB |
7320 | static tree |
7321 | build_opaque_vector_type (tree node, int nunits) | |
7322 | { | |
7323 | node = copy_node (node); | |
7324 | TYPE_MAIN_VARIANT (node) = node; | |
7325 | return build_vector_type (node, nunits); | |
7326 | } | |
7327 | ||
0ac081f6 | 7328 | static void |
863d938c | 7329 | rs6000_init_builtins (void) |
0ac081f6 | 7330 | { |
4a5eab38 PB |
7331 | V2SI_type_node = build_vector_type (intSI_type_node, 2); |
7332 | V2SF_type_node = build_vector_type (float_type_node, 2); | |
7333 | V4HI_type_node = build_vector_type (intHI_type_node, 4); | |
7334 | V4SI_type_node = build_vector_type (intSI_type_node, 4); | |
7335 | V4SF_type_node = build_vector_type (float_type_node, 4); | |
7e463bda | 7336 | V8HI_type_node = build_vector_type (intHI_type_node, 8); |
4a5eab38 PB |
7337 | V16QI_type_node = build_vector_type (intQI_type_node, 16); |
7338 | ||
7339 | unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16); | |
7340 | unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8); | |
7341 | unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4); | |
7342 | ||
7c62e993 PB |
7343 | opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2); |
7344 | opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2); | |
6035d635 | 7345 | opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node); |
3fdaa45a | 7346 | |
8bb418a3 ZL |
7347 | /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...' |
7348 | types, especially in C++ land. Similarly, 'vector pixel' is distinct from | |
7349 | 'vector unsigned short'. */ | |
7350 | ||
8dd16ecc NS |
7351 | bool_char_type_node = build_distinct_type_copy (unsigned_intQI_type_node); |
7352 | bool_short_type_node = build_distinct_type_copy (unsigned_intHI_type_node); | |
7353 | bool_int_type_node = build_distinct_type_copy (unsigned_intSI_type_node); | |
7354 | pixel_type_node = build_distinct_type_copy (unsigned_intHI_type_node); | |
8bb418a3 ZL |
7355 | |
7356 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7357 | get_identifier ("__bool char"), | |
7358 | bool_char_type_node)); | |
7359 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7360 | get_identifier ("__bool short"), | |
7361 | bool_short_type_node)); | |
7362 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7363 | get_identifier ("__bool int"), | |
7364 | bool_int_type_node)); | |
7365 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7366 | get_identifier ("__pixel"), | |
7367 | pixel_type_node)); | |
7368 | ||
4a5eab38 PB |
7369 | bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16); |
7370 | bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8); | |
7371 | bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4); | |
7372 | pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8); | |
8bb418a3 ZL |
7373 | |
7374 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7375 | get_identifier ("__vector unsigned char"), | |
7376 | unsigned_V16QI_type_node)); | |
7377 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7378 | get_identifier ("__vector signed char"), | |
7379 | V16QI_type_node)); | |
7380 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7381 | get_identifier ("__vector __bool char"), | |
7382 | bool_V16QI_type_node)); | |
7383 | ||
7384 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7385 | get_identifier ("__vector unsigned short"), | |
7386 | unsigned_V8HI_type_node)); | |
7387 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7388 | get_identifier ("__vector signed short"), | |
7389 | V8HI_type_node)); | |
7390 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7391 | get_identifier ("__vector __bool short"), | |
7392 | bool_V8HI_type_node)); | |
7393 | ||
7394 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7395 | get_identifier ("__vector unsigned int"), | |
7396 | unsigned_V4SI_type_node)); | |
7397 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7398 | get_identifier ("__vector signed int"), | |
7399 | V4SI_type_node)); | |
7400 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7401 | get_identifier ("__vector __bool int"), | |
7402 | bool_V4SI_type_node)); | |
7403 | ||
7404 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7405 | get_identifier ("__vector float"), | |
7406 | V4SF_type_node)); | |
7407 | (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL, | |
7408 | get_identifier ("__vector __pixel"), | |
7409 | pixel_V8HI_type_node)); | |
7410 | ||
a3170dc6 | 7411 | if (TARGET_SPE) |
3fdaa45a | 7412 | spe_init_builtins (); |
0ac081f6 AH |
7413 | if (TARGET_ALTIVEC) |
7414 | altivec_init_builtins (); | |
0559cc77 DE |
7415 | if (TARGET_ALTIVEC || TARGET_SPE) |
7416 | rs6000_common_init_builtins (); | |
0ac081f6 AH |
7417 | } |
7418 | ||
a3170dc6 AH |
7419 | /* Search through a set of builtins and enable the mask bits. |
7420 | DESC is an array of builtins. | |
b6d08ca1 | 7421 | SIZE is the total number of builtins. |
a3170dc6 AH |
7422 | START is the builtin enum at which to start. |
7423 | END is the builtin enum at which to end. */ | |
0ac081f6 | 7424 | static void |
a2369ed3 | 7425 | enable_mask_for_builtins (struct builtin_description *desc, int size, |
f676971a | 7426 | enum rs6000_builtins start, |
a2369ed3 | 7427 | enum rs6000_builtins end) |
a3170dc6 AH |
7428 | { |
7429 | int i; | |
7430 | ||
7431 | for (i = 0; i < size; ++i) | |
7432 | if (desc[i].code == start) | |
7433 | break; | |
7434 | ||
7435 | if (i == size) | |
7436 | return; | |
7437 | ||
7438 | for (; i < size; ++i) | |
7439 | { | |
7440 | /* Flip all the bits on. */ | |
7441 | desc[i].mask = target_flags; | |
7442 | if (desc[i].code == end) | |
7443 | break; | |
7444 | } | |
7445 | } | |
7446 | ||
7447 | static void | |
863d938c | 7448 | spe_init_builtins (void) |
0ac081f6 | 7449 | { |
a3170dc6 AH |
7450 | tree endlink = void_list_node; |
7451 | tree puint_type_node = build_pointer_type (unsigned_type_node); | |
7452 | tree pushort_type_node = build_pointer_type (short_unsigned_type_node); | |
ae4b4a02 | 7453 | struct builtin_description *d; |
0ac081f6 AH |
7454 | size_t i; |
7455 | ||
a3170dc6 AH |
7456 | tree v2si_ftype_4_v2si |
7457 | = build_function_type | |
3fdaa45a AH |
7458 | (opaque_V2SI_type_node, |
7459 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
7460 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
7461 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
7462 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
7463 | endlink))))); |
7464 | ||
7465 | tree v2sf_ftype_4_v2sf | |
7466 | = build_function_type | |
3fdaa45a AH |
7467 | (opaque_V2SF_type_node, |
7468 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
7469 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
7470 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
7471 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
7472 | endlink))))); |
7473 | ||
7474 | tree int_ftype_int_v2si_v2si | |
7475 | = build_function_type | |
7476 | (integer_type_node, | |
7477 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
7478 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
7479 | tree_cons (NULL_TREE, opaque_V2SI_type_node, | |
a3170dc6 AH |
7480 | endlink)))); |
7481 | ||
7482 | tree int_ftype_int_v2sf_v2sf | |
7483 | = build_function_type | |
7484 | (integer_type_node, | |
7485 | tree_cons (NULL_TREE, integer_type_node, | |
3fdaa45a AH |
7486 | tree_cons (NULL_TREE, opaque_V2SF_type_node, |
7487 | tree_cons (NULL_TREE, opaque_V2SF_type_node, | |
a3170dc6 AH |
7488 | endlink)))); |
7489 | ||
7490 | tree void_ftype_v2si_puint_int | |
7491 | = build_function_type (void_type_node, | |
3fdaa45a | 7492 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
7493 | tree_cons (NULL_TREE, puint_type_node, |
7494 | tree_cons (NULL_TREE, | |
7495 | integer_type_node, | |
7496 | endlink)))); | |
7497 | ||
7498 | tree void_ftype_v2si_puint_char | |
7499 | = build_function_type (void_type_node, | |
3fdaa45a | 7500 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
a3170dc6 AH |
7501 | tree_cons (NULL_TREE, puint_type_node, |
7502 | tree_cons (NULL_TREE, | |
7503 | char_type_node, | |
7504 | endlink)))); | |
7505 | ||
7506 | tree void_ftype_v2si_pv2si_int | |
7507 | = build_function_type (void_type_node, | |
3fdaa45a | 7508 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 7509 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7510 | tree_cons (NULL_TREE, |
7511 | integer_type_node, | |
7512 | endlink)))); | |
7513 | ||
7514 | tree void_ftype_v2si_pv2si_char | |
7515 | = build_function_type (void_type_node, | |
3fdaa45a | 7516 | tree_cons (NULL_TREE, opaque_V2SI_type_node, |
6035d635 | 7517 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7518 | tree_cons (NULL_TREE, |
7519 | char_type_node, | |
7520 | endlink)))); | |
7521 | ||
7522 | tree void_ftype_int | |
7523 | = build_function_type (void_type_node, | |
7524 | tree_cons (NULL_TREE, integer_type_node, endlink)); | |
7525 | ||
7526 | tree int_ftype_void | |
36e8d515 | 7527 | = build_function_type (integer_type_node, endlink); |
a3170dc6 AH |
7528 | |
7529 | tree v2si_ftype_pv2si_int | |
3fdaa45a | 7530 | = build_function_type (opaque_V2SI_type_node, |
6035d635 | 7531 | tree_cons (NULL_TREE, opaque_p_V2SI_type_node, |
a3170dc6 AH |
7532 | tree_cons (NULL_TREE, integer_type_node, |
7533 | endlink))); | |
7534 | ||
7535 | tree v2si_ftype_puint_int | |
3fdaa45a | 7536 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
7537 | tree_cons (NULL_TREE, puint_type_node, |
7538 | tree_cons (NULL_TREE, integer_type_node, | |
7539 | endlink))); | |
7540 | ||
7541 | tree v2si_ftype_pushort_int | |
3fdaa45a | 7542 | = build_function_type (opaque_V2SI_type_node, |
a3170dc6 AH |
7543 | tree_cons (NULL_TREE, pushort_type_node, |
7544 | tree_cons (NULL_TREE, integer_type_node, | |
7545 | endlink))); | |
7546 | ||
00332c9f AH |
7547 | tree v2si_ftype_signed_char |
7548 | = build_function_type (opaque_V2SI_type_node, | |
7549 | tree_cons (NULL_TREE, signed_char_type_node, | |
7550 | endlink)); | |
7551 | ||
a3170dc6 AH |
7552 | /* The initialization of the simple binary and unary builtins is |
7553 | done in rs6000_common_init_builtins, but we have to enable the | |
7554 | mask bits here manually because we have run out of `target_flags' | |
7555 | bits. We really need to redesign this mask business. */ | |
7556 | ||
7557 | enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg, | |
7558 | ARRAY_SIZE (bdesc_2arg), | |
7559 | SPE_BUILTIN_EVADDW, | |
7560 | SPE_BUILTIN_EVXOR); | |
7561 | enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg, | |
7562 | ARRAY_SIZE (bdesc_1arg), | |
7563 | SPE_BUILTIN_EVABS, | |
7564 | SPE_BUILTIN_EVSUBFUSIAAW); | |
7565 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates, | |
7566 | ARRAY_SIZE (bdesc_spe_predicates), | |
7567 | SPE_BUILTIN_EVCMPEQ, | |
7568 | SPE_BUILTIN_EVFSTSTLT); | |
7569 | enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel, | |
7570 | ARRAY_SIZE (bdesc_spe_evsel), | |
7571 | SPE_BUILTIN_EVSEL_CMPGTS, | |
7572 | SPE_BUILTIN_EVSEL_FSTSTEQ); | |
7573 | ||
36252949 AH |
7574 | (*lang_hooks.decls.pushdecl) |
7575 | (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"), | |
7576 | opaque_V2SI_type_node)); | |
7577 | ||
a3170dc6 | 7578 | /* Initialize irregular SPE builtins. */ |
f676971a | 7579 | |
a3170dc6 AH |
7580 | def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR); |
7581 | def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR); | |
7582 | def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX); | |
7583 | def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX); | |
7584 | def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX); | |
7585 | def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX); | |
7586 | def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX); | |
7587 | def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX); | |
7588 | def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX); | |
7589 | def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD); | |
7590 | def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH); | |
7591 | def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW); | |
7592 | def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE); | |
7593 | def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO); | |
7594 | def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE); | |
7595 | def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO); | |
00332c9f AH |
7596 | def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI); |
7597 | def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI); | |
a3170dc6 AH |
7598 | |
7599 | /* Loads. */ | |
7600 | def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX); | |
7601 | def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX); | |
7602 | def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX); | |
7603 | def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX); | |
7604 | def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX); | |
7605 | def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX); | |
7606 | def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX); | |
7607 | def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX); | |
7608 | def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX); | |
7609 | def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX); | |
7610 | def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX); | |
7611 | def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD); | |
7612 | def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW); | |
7613 | def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH); | |
7614 | def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT); | |
7615 | def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT); | |
7616 | def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT); | |
7617 | def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE); | |
7618 | def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS); | |
7619 | def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU); | |
7620 | def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT); | |
7621 | def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT); | |
7622 | ||
7623 | /* Predicates. */ | |
7624 | d = (struct builtin_description *) bdesc_spe_predicates; | |
7625 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++) | |
7626 | { | |
7627 | tree type; | |
7628 | ||
7629 | switch (insn_data[d->icode].operand[1].mode) | |
7630 | { | |
7631 | case V2SImode: | |
7632 | type = int_ftype_int_v2si_v2si; | |
7633 | break; | |
7634 | case V2SFmode: | |
7635 | type = int_ftype_int_v2sf_v2sf; | |
7636 | break; | |
7637 | default: | |
7638 | abort (); | |
7639 | } | |
7640 | ||
7641 | def_builtin (d->mask, d->name, type, d->code); | |
7642 | } | |
7643 | ||
7644 | /* Evsel predicates. */ | |
7645 | d = (struct builtin_description *) bdesc_spe_evsel; | |
7646 | for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++) | |
7647 | { | |
7648 | tree type; | |
7649 | ||
7650 | switch (insn_data[d->icode].operand[1].mode) | |
7651 | { | |
7652 | case V2SImode: | |
7653 | type = v2si_ftype_4_v2si; | |
7654 | break; | |
7655 | case V2SFmode: | |
7656 | type = v2sf_ftype_4_v2sf; | |
7657 | break; | |
7658 | default: | |
7659 | abort (); | |
7660 | } | |
7661 | ||
7662 | def_builtin (d->mask, d->name, type, d->code); | |
7663 | } | |
7664 | } | |
7665 | ||
7666 | static void | |
863d938c | 7667 | altivec_init_builtins (void) |
a3170dc6 AH |
7668 | { |
7669 | struct builtin_description *d; | |
7670 | struct builtin_description_predicates *dp; | |
7671 | size_t i; | |
7672 | tree pfloat_type_node = build_pointer_type (float_type_node); | |
7673 | tree pint_type_node = build_pointer_type (integer_type_node); | |
7674 | tree pshort_type_node = build_pointer_type (short_integer_type_node); | |
7675 | tree pchar_type_node = build_pointer_type (char_type_node); | |
7676 | ||
7677 | tree pvoid_type_node = build_pointer_type (void_type_node); | |
7678 | ||
0dbc3651 ZW |
7679 | tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST)); |
7680 | tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST)); | |
7681 | tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST)); | |
7682 | tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); | |
7683 | ||
7684 | tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST)); | |
7685 | ||
a3170dc6 AH |
7686 | tree int_ftype_int_v4si_v4si |
7687 | = build_function_type_list (integer_type_node, | |
7688 | integer_type_node, V4SI_type_node, | |
7689 | V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7690 | tree v4sf_ftype_pcfloat |
7691 | = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE); | |
a3170dc6 | 7692 | tree void_ftype_pfloat_v4sf |
b4de2f7d | 7693 | = build_function_type_list (void_type_node, |
a3170dc6 | 7694 | pfloat_type_node, V4SF_type_node, NULL_TREE); |
0dbc3651 ZW |
7695 | tree v4si_ftype_pcint |
7696 | = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE); | |
7697 | tree void_ftype_pint_v4si | |
b4de2f7d AH |
7698 | = build_function_type_list (void_type_node, |
7699 | pint_type_node, V4SI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7700 | tree v8hi_ftype_pcshort |
7701 | = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE); | |
f18c054f | 7702 | tree void_ftype_pshort_v8hi |
b4de2f7d AH |
7703 | = build_function_type_list (void_type_node, |
7704 | pshort_type_node, V8HI_type_node, NULL_TREE); | |
0dbc3651 ZW |
7705 | tree v16qi_ftype_pcchar |
7706 | = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE); | |
f18c054f | 7707 | tree void_ftype_pchar_v16qi |
b4de2f7d AH |
7708 | = build_function_type_list (void_type_node, |
7709 | pchar_type_node, V16QI_type_node, NULL_TREE); | |
95385cbb | 7710 | tree void_ftype_v4si |
b4de2f7d | 7711 | = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE); |
a3170dc6 AH |
7712 | tree v8hi_ftype_void |
7713 | = build_function_type (V8HI_type_node, void_list_node); | |
7714 | tree void_ftype_void | |
7715 | = build_function_type (void_type_node, void_list_node); | |
e34b6648 JJ |
7716 | tree void_ftype_int |
7717 | = build_function_type_list (void_type_node, integer_type_node, NULL_TREE); | |
0dbc3651 | 7718 | |
b4a62fa0 | 7719 | tree v16qi_ftype_long_pcvoid |
a3170dc6 | 7720 | = build_function_type_list (V16QI_type_node, |
b4a62fa0 SB |
7721 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
7722 | tree v8hi_ftype_long_pcvoid | |
a3170dc6 | 7723 | = build_function_type_list (V8HI_type_node, |
b4a62fa0 SB |
7724 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
7725 | tree v4si_ftype_long_pcvoid | |
a3170dc6 | 7726 | = build_function_type_list (V4SI_type_node, |
b4a62fa0 | 7727 | long_integer_type_node, pcvoid_type_node, NULL_TREE); |
0dbc3651 | 7728 | |
b4a62fa0 | 7729 | tree void_ftype_v4si_long_pvoid |
b4de2f7d | 7730 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7731 | V4SI_type_node, long_integer_type_node, |
b4de2f7d | 7732 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 7733 | tree void_ftype_v16qi_long_pvoid |
b4de2f7d | 7734 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7735 | V16QI_type_node, long_integer_type_node, |
b4de2f7d | 7736 | pvoid_type_node, NULL_TREE); |
b4a62fa0 | 7737 | tree void_ftype_v8hi_long_pvoid |
b4de2f7d | 7738 | = build_function_type_list (void_type_node, |
b4a62fa0 | 7739 | V8HI_type_node, long_integer_type_node, |
b4de2f7d | 7740 | pvoid_type_node, NULL_TREE); |
a3170dc6 AH |
7741 | tree int_ftype_int_v8hi_v8hi |
7742 | = build_function_type_list (integer_type_node, | |
7743 | integer_type_node, V8HI_type_node, | |
7744 | V8HI_type_node, NULL_TREE); | |
7745 | tree int_ftype_int_v16qi_v16qi | |
7746 | = build_function_type_list (integer_type_node, | |
7747 | integer_type_node, V16QI_type_node, | |
7748 | V16QI_type_node, NULL_TREE); | |
7749 | tree int_ftype_int_v4sf_v4sf | |
7750 | = build_function_type_list (integer_type_node, | |
7751 | integer_type_node, V4SF_type_node, | |
7752 | V4SF_type_node, NULL_TREE); | |
7753 | tree v4si_ftype_v4si | |
7754 | = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE); | |
7755 | tree v8hi_ftype_v8hi | |
7756 | = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE); | |
7757 | tree v16qi_ftype_v16qi | |
7758 | = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE); | |
7759 | tree v4sf_ftype_v4sf | |
7760 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
8bb418a3 | 7761 | tree void_ftype_pcvoid_int_int |
a3170dc6 | 7762 | = build_function_type_list (void_type_node, |
0dbc3651 | 7763 | pcvoid_type_node, integer_type_node, |
8bb418a3 ZL |
7764 | integer_type_node, NULL_TREE); |
7765 | tree int_ftype_pcchar | |
7766 | = build_function_type_list (integer_type_node, | |
7767 | pcchar_type_node, NULL_TREE); | |
7768 | ||
7ccf35ed DN |
7769 | tree id; |
7770 | tree decl; | |
7771 | ||
0dbc3651 ZW |
7772 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat, |
7773 | ALTIVEC_BUILTIN_LD_INTERNAL_4sf); | |
7774 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf, | |
7775 | ALTIVEC_BUILTIN_ST_INTERNAL_4sf); | |
7776 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint, | |
7777 | ALTIVEC_BUILTIN_LD_INTERNAL_4si); | |
7778 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si, | |
7779 | ALTIVEC_BUILTIN_ST_INTERNAL_4si); | |
7780 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort, | |
7781 | ALTIVEC_BUILTIN_LD_INTERNAL_8hi); | |
7782 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi, | |
7783 | ALTIVEC_BUILTIN_ST_INTERNAL_8hi); | |
7784 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar, | |
7785 | ALTIVEC_BUILTIN_LD_INTERNAL_16qi); | |
7786 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi, | |
7787 | ALTIVEC_BUILTIN_ST_INTERNAL_16qi); | |
a3170dc6 AH |
7788 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR); |
7789 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR); | |
7790 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL); | |
e34b6648 | 7791 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_int, ALTIVEC_BUILTIN_DSS); |
b4a62fa0 SB |
7792 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL); |
7793 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR); | |
7794 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX); | |
7795 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX); | |
7796 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX); | |
7797 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL); | |
7798 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX); | |
7799 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX); | |
7800 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX); | |
7801 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL); | |
7802 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX); | |
7803 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX); | |
a3170dc6 | 7804 | |
8bb418a3 ZL |
7805 | /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */ |
7806 | def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar, | |
7807 | ALTIVEC_BUILTIN_COMPILETIME_ERROR); | |
7808 | ||
a3170dc6 AH |
7809 | /* Add the DST variants. */ |
7810 | d = (struct builtin_description *) bdesc_dst; | |
7811 | for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++) | |
8bb418a3 | 7812 | def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code); |
a3170dc6 AH |
7813 | |
7814 | /* Initialize the predicates. */ | |
7815 | dp = (struct builtin_description_predicates *) bdesc_altivec_preds; | |
7816 | for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++) | |
7817 | { | |
7818 | enum machine_mode mode1; | |
7819 | tree type; | |
7820 | ||
7821 | mode1 = insn_data[dp->icode].operand[1].mode; | |
7822 | ||
7823 | switch (mode1) | |
7824 | { | |
7825 | case V4SImode: | |
7826 | type = int_ftype_int_v4si_v4si; | |
7827 | break; | |
7828 | case V8HImode: | |
7829 | type = int_ftype_int_v8hi_v8hi; | |
7830 | break; | |
7831 | case V16QImode: | |
7832 | type = int_ftype_int_v16qi_v16qi; | |
7833 | break; | |
7834 | case V4SFmode: | |
7835 | type = int_ftype_int_v4sf_v4sf; | |
7836 | break; | |
7837 | default: | |
7838 | abort (); | |
7839 | } | |
f676971a | 7840 | |
a3170dc6 AH |
7841 | def_builtin (dp->mask, dp->name, type, dp->code); |
7842 | } | |
7843 | ||
7844 | /* Initialize the abs* operators. */ | |
7845 | d = (struct builtin_description *) bdesc_abs; | |
7846 | for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++) | |
7847 | { | |
7848 | enum machine_mode mode0; | |
7849 | tree type; | |
7850 | ||
7851 | mode0 = insn_data[d->icode].operand[0].mode; | |
7852 | ||
7853 | switch (mode0) | |
7854 | { | |
7855 | case V4SImode: | |
7856 | type = v4si_ftype_v4si; | |
7857 | break; | |
7858 | case V8HImode: | |
7859 | type = v8hi_ftype_v8hi; | |
7860 | break; | |
7861 | case V16QImode: | |
7862 | type = v16qi_ftype_v16qi; | |
7863 | break; | |
7864 | case V4SFmode: | |
7865 | type = v4sf_ftype_v4sf; | |
7866 | break; | |
7867 | default: | |
7868 | abort (); | |
7869 | } | |
f676971a | 7870 | |
a3170dc6 AH |
7871 | def_builtin (d->mask, d->name, type, d->code); |
7872 | } | |
7ccf35ed DN |
7873 | |
7874 | /* Initialize target builtin that implements | |
7875 | targetm.vectorize.builtin_mask_for_load. */ | |
7876 | id = get_identifier ("__builtin_altivec_mask_for_load"); | |
7877 | decl = build_decl (FUNCTION_DECL, id, v16qi_ftype_long_pcvoid); | |
7878 | DECL_BUILT_IN_CLASS (decl) = BUILT_IN_MD; | |
7879 | DECL_FUNCTION_CODE (decl) = ALTIVEC_BUILTIN_MASK_FOR_LOAD; | |
7880 | /* Record the decl. Will be used by rs6000_builtin_mask_for_load. */ | |
7881 | altivec_builtin_mask_for_load = decl; | |
7882 | ||
7883 | /* Initialize target builtin that implements | |
7884 | targetm.vectorize.builtin_mask_for_store. */ | |
7885 | id = get_identifier ("__builtin_altivec_mask_for_store"); | |
7886 | decl = build_decl (FUNCTION_DECL, id, v16qi_ftype_long_pcvoid); | |
7887 | DECL_BUILT_IN_CLASS (decl) = BUILT_IN_MD; | |
7888 | DECL_FUNCTION_CODE (decl) = ALTIVEC_BUILTIN_MASK_FOR_STORE; | |
7889 | /* Record the decl. Will be used by rs6000_builtin_mask_for_store. */ | |
7890 | altivec_builtin_mask_for_store = decl; | |
a3170dc6 AH |
7891 | } |
7892 | ||
7893 | static void | |
863d938c | 7894 | rs6000_common_init_builtins (void) |
a3170dc6 AH |
7895 | { |
7896 | struct builtin_description *d; | |
7897 | size_t i; | |
7898 | ||
7899 | tree v4sf_ftype_v4sf_v4sf_v16qi | |
7900 | = build_function_type_list (V4SF_type_node, | |
7901 | V4SF_type_node, V4SF_type_node, | |
7902 | V16QI_type_node, NULL_TREE); | |
7903 | tree v4si_ftype_v4si_v4si_v16qi | |
7904 | = build_function_type_list (V4SI_type_node, | |
7905 | V4SI_type_node, V4SI_type_node, | |
7906 | V16QI_type_node, NULL_TREE); | |
7907 | tree v8hi_ftype_v8hi_v8hi_v16qi | |
7908 | = build_function_type_list (V8HI_type_node, | |
7909 | V8HI_type_node, V8HI_type_node, | |
7910 | V16QI_type_node, NULL_TREE); | |
7911 | tree v16qi_ftype_v16qi_v16qi_v16qi | |
7912 | = build_function_type_list (V16QI_type_node, | |
7913 | V16QI_type_node, V16QI_type_node, | |
7914 | V16QI_type_node, NULL_TREE); | |
b9e4e5d1 ZL |
7915 | tree v4si_ftype_int |
7916 | = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE); | |
7917 | tree v8hi_ftype_int | |
7918 | = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE); | |
7919 | tree v16qi_ftype_int | |
7920 | = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE); | |
a3170dc6 AH |
7921 | tree v8hi_ftype_v16qi |
7922 | = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE); | |
7923 | tree v4sf_ftype_v4sf | |
7924 | = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE); | |
7925 | ||
7926 | tree v2si_ftype_v2si_v2si | |
2abe3e28 AH |
7927 | = build_function_type_list (opaque_V2SI_type_node, |
7928 | opaque_V2SI_type_node, | |
7929 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7930 | |
7931 | tree v2sf_ftype_v2sf_v2sf | |
2abe3e28 AH |
7932 | = build_function_type_list (opaque_V2SF_type_node, |
7933 | opaque_V2SF_type_node, | |
7934 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7935 | |
7936 | tree v2si_ftype_int_int | |
2abe3e28 | 7937 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
7938 | integer_type_node, integer_type_node, |
7939 | NULL_TREE); | |
7940 | ||
7941 | tree v2si_ftype_v2si | |
2abe3e28 AH |
7942 | = build_function_type_list (opaque_V2SI_type_node, |
7943 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7944 | |
7945 | tree v2sf_ftype_v2sf | |
2abe3e28 AH |
7946 | = build_function_type_list (opaque_V2SF_type_node, |
7947 | opaque_V2SF_type_node, NULL_TREE); | |
f676971a | 7948 | |
a3170dc6 | 7949 | tree v2sf_ftype_v2si |
2abe3e28 AH |
7950 | = build_function_type_list (opaque_V2SF_type_node, |
7951 | opaque_V2SI_type_node, NULL_TREE); | |
a3170dc6 AH |
7952 | |
7953 | tree v2si_ftype_v2sf | |
2abe3e28 AH |
7954 | = build_function_type_list (opaque_V2SI_type_node, |
7955 | opaque_V2SF_type_node, NULL_TREE); | |
a3170dc6 AH |
7956 | |
7957 | tree v2si_ftype_v2si_char | |
2abe3e28 AH |
7958 | = build_function_type_list (opaque_V2SI_type_node, |
7959 | opaque_V2SI_type_node, | |
7960 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
7961 | |
7962 | tree v2si_ftype_int_char | |
2abe3e28 | 7963 | = build_function_type_list (opaque_V2SI_type_node, |
a3170dc6 AH |
7964 | integer_type_node, char_type_node, NULL_TREE); |
7965 | ||
7966 | tree v2si_ftype_char | |
2abe3e28 AH |
7967 | = build_function_type_list (opaque_V2SI_type_node, |
7968 | char_type_node, NULL_TREE); | |
a3170dc6 AH |
7969 | |
7970 | tree int_ftype_int_int | |
7971 | = build_function_type_list (integer_type_node, | |
7972 | integer_type_node, integer_type_node, | |
7973 | NULL_TREE); | |
95385cbb | 7974 | |
0ac081f6 | 7975 | tree v4si_ftype_v4si_v4si |
b4de2f7d AH |
7976 | = build_function_type_list (V4SI_type_node, |
7977 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
b9e4e5d1 | 7978 | tree v4sf_ftype_v4si_int |
b4de2f7d | 7979 | = build_function_type_list (V4SF_type_node, |
b9e4e5d1 ZL |
7980 | V4SI_type_node, integer_type_node, NULL_TREE); |
7981 | tree v4si_ftype_v4sf_int | |
b4de2f7d | 7982 | = build_function_type_list (V4SI_type_node, |
b9e4e5d1 ZL |
7983 | V4SF_type_node, integer_type_node, NULL_TREE); |
7984 | tree v4si_ftype_v4si_int | |
b4de2f7d | 7985 | = build_function_type_list (V4SI_type_node, |
b9e4e5d1 ZL |
7986 | V4SI_type_node, integer_type_node, NULL_TREE); |
7987 | tree v8hi_ftype_v8hi_int | |
b4de2f7d | 7988 | = build_function_type_list (V8HI_type_node, |
b9e4e5d1 ZL |
7989 | V8HI_type_node, integer_type_node, NULL_TREE); |
7990 | tree v16qi_ftype_v16qi_int | |
b4de2f7d | 7991 | = build_function_type_list (V16QI_type_node, |
b9e4e5d1 ZL |
7992 | V16QI_type_node, integer_type_node, NULL_TREE); |
7993 | tree v16qi_ftype_v16qi_v16qi_int | |
b4de2f7d AH |
7994 | = build_function_type_list (V16QI_type_node, |
7995 | V16QI_type_node, V16QI_type_node, | |
b9e4e5d1 ZL |
7996 | integer_type_node, NULL_TREE); |
7997 | tree v8hi_ftype_v8hi_v8hi_int | |
b4de2f7d AH |
7998 | = build_function_type_list (V8HI_type_node, |
7999 | V8HI_type_node, V8HI_type_node, | |
b9e4e5d1 ZL |
8000 | integer_type_node, NULL_TREE); |
8001 | tree v4si_ftype_v4si_v4si_int | |
b4de2f7d AH |
8002 | = build_function_type_list (V4SI_type_node, |
8003 | V4SI_type_node, V4SI_type_node, | |
b9e4e5d1 ZL |
8004 | integer_type_node, NULL_TREE); |
8005 | tree v4sf_ftype_v4sf_v4sf_int | |
b4de2f7d AH |
8006 | = build_function_type_list (V4SF_type_node, |
8007 | V4SF_type_node, V4SF_type_node, | |
b9e4e5d1 | 8008 | integer_type_node, NULL_TREE); |
0ac081f6 | 8009 | tree v4sf_ftype_v4sf_v4sf |
b4de2f7d AH |
8010 | = build_function_type_list (V4SF_type_node, |
8011 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
617e0e1d | 8012 | tree v4sf_ftype_v4sf_v4sf_v4si |
b4de2f7d AH |
8013 | = build_function_type_list (V4SF_type_node, |
8014 | V4SF_type_node, V4SF_type_node, | |
8015 | V4SI_type_node, NULL_TREE); | |
2212663f | 8016 | tree v4sf_ftype_v4sf_v4sf_v4sf |
b4de2f7d AH |
8017 | = build_function_type_list (V4SF_type_node, |
8018 | V4SF_type_node, V4SF_type_node, | |
8019 | V4SF_type_node, NULL_TREE); | |
f676971a | 8020 | tree v4si_ftype_v4si_v4si_v4si |
b4de2f7d AH |
8021 | = build_function_type_list (V4SI_type_node, |
8022 | V4SI_type_node, V4SI_type_node, | |
8023 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 8024 | tree v8hi_ftype_v8hi_v8hi |
b4de2f7d AH |
8025 | = build_function_type_list (V8HI_type_node, |
8026 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
2212663f | 8027 | tree v8hi_ftype_v8hi_v8hi_v8hi |
b4de2f7d AH |
8028 | = build_function_type_list (V8HI_type_node, |
8029 | V8HI_type_node, V8HI_type_node, | |
8030 | V8HI_type_node, NULL_TREE); | |
2212663f | 8031 | tree v4si_ftype_v8hi_v8hi_v4si |
b4de2f7d AH |
8032 | = build_function_type_list (V4SI_type_node, |
8033 | V8HI_type_node, V8HI_type_node, | |
8034 | V4SI_type_node, NULL_TREE); | |
2212663f | 8035 | tree v4si_ftype_v16qi_v16qi_v4si |
b4de2f7d AH |
8036 | = build_function_type_list (V4SI_type_node, |
8037 | V16QI_type_node, V16QI_type_node, | |
8038 | V4SI_type_node, NULL_TREE); | |
0ac081f6 | 8039 | tree v16qi_ftype_v16qi_v16qi |
b4de2f7d AH |
8040 | = build_function_type_list (V16QI_type_node, |
8041 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 8042 | tree v4si_ftype_v4sf_v4sf |
b4de2f7d AH |
8043 | = build_function_type_list (V4SI_type_node, |
8044 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
0ac081f6 | 8045 | tree v8hi_ftype_v16qi_v16qi |
b4de2f7d AH |
8046 | = build_function_type_list (V8HI_type_node, |
8047 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 8048 | tree v4si_ftype_v8hi_v8hi |
b4de2f7d AH |
8049 | = build_function_type_list (V4SI_type_node, |
8050 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 8051 | tree v8hi_ftype_v4si_v4si |
b4de2f7d AH |
8052 | = build_function_type_list (V8HI_type_node, |
8053 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
0ac081f6 | 8054 | tree v16qi_ftype_v8hi_v8hi |
b4de2f7d AH |
8055 | = build_function_type_list (V16QI_type_node, |
8056 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 8057 | tree v4si_ftype_v16qi_v4si |
b4de2f7d AH |
8058 | = build_function_type_list (V4SI_type_node, |
8059 | V16QI_type_node, V4SI_type_node, NULL_TREE); | |
fa066a23 | 8060 | tree v4si_ftype_v16qi_v16qi |
b4de2f7d AH |
8061 | = build_function_type_list (V4SI_type_node, |
8062 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 8063 | tree v4si_ftype_v8hi_v4si |
b4de2f7d AH |
8064 | = build_function_type_list (V4SI_type_node, |
8065 | V8HI_type_node, V4SI_type_node, NULL_TREE); | |
a3170dc6 AH |
8066 | tree v4si_ftype_v8hi |
8067 | = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE); | |
8068 | tree int_ftype_v4si_v4si | |
8069 | = build_function_type_list (integer_type_node, | |
8070 | V4SI_type_node, V4SI_type_node, NULL_TREE); | |
8071 | tree int_ftype_v4sf_v4sf | |
8072 | = build_function_type_list (integer_type_node, | |
8073 | V4SF_type_node, V4SF_type_node, NULL_TREE); | |
8074 | tree int_ftype_v16qi_v16qi | |
8075 | = build_function_type_list (integer_type_node, | |
8076 | V16QI_type_node, V16QI_type_node, NULL_TREE); | |
0ac081f6 | 8077 | tree int_ftype_v8hi_v8hi |
b4de2f7d AH |
8078 | = build_function_type_list (integer_type_node, |
8079 | V8HI_type_node, V8HI_type_node, NULL_TREE); | |
0ac081f6 | 8080 | |
6f317ef3 | 8081 | /* Add the simple ternary operators. */ |
2212663f | 8082 | d = (struct builtin_description *) bdesc_3arg; |
ca7558fc | 8083 | for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++) |
2212663f | 8084 | { |
f676971a | 8085 | |
2212663f DB |
8086 | enum machine_mode mode0, mode1, mode2, mode3; |
8087 | tree type; | |
8088 | ||
0559cc77 | 8089 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f | 8090 | continue; |
f676971a | 8091 | |
2212663f DB |
8092 | mode0 = insn_data[d->icode].operand[0].mode; |
8093 | mode1 = insn_data[d->icode].operand[1].mode; | |
8094 | mode2 = insn_data[d->icode].operand[2].mode; | |
8095 | mode3 = insn_data[d->icode].operand[3].mode; | |
f676971a | 8096 | |
2212663f DB |
8097 | /* When all four are of the same mode. */ |
8098 | if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3) | |
8099 | { | |
8100 | switch (mode0) | |
8101 | { | |
617e0e1d DB |
8102 | case V4SImode: |
8103 | type = v4si_ftype_v4si_v4si_v4si; | |
8104 | break; | |
2212663f DB |
8105 | case V4SFmode: |
8106 | type = v4sf_ftype_v4sf_v4sf_v4sf; | |
8107 | break; | |
8108 | case V8HImode: | |
8109 | type = v8hi_ftype_v8hi_v8hi_v8hi; | |
f676971a | 8110 | break; |
2212663f DB |
8111 | case V16QImode: |
8112 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
f676971a | 8113 | break; |
2212663f | 8114 | default: |
f676971a | 8115 | abort(); |
2212663f DB |
8116 | } |
8117 | } | |
8118 | else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode) | |
8119 | { | |
8120 | switch (mode0) | |
8121 | { | |
8122 | case V4SImode: | |
8123 | type = v4si_ftype_v4si_v4si_v16qi; | |
8124 | break; | |
8125 | case V4SFmode: | |
8126 | type = v4sf_ftype_v4sf_v4sf_v16qi; | |
8127 | break; | |
8128 | case V8HImode: | |
8129 | type = v8hi_ftype_v8hi_v8hi_v16qi; | |
f676971a | 8130 | break; |
2212663f DB |
8131 | case V16QImode: |
8132 | type = v16qi_ftype_v16qi_v16qi_v16qi; | |
f676971a | 8133 | break; |
2212663f | 8134 | default: |
f676971a | 8135 | abort(); |
2212663f DB |
8136 | } |
8137 | } | |
f676971a | 8138 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode |
2212663f | 8139 | && mode3 == V4SImode) |
24408032 | 8140 | type = v4si_ftype_v16qi_v16qi_v4si; |
f676971a | 8141 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode |
2212663f | 8142 | && mode3 == V4SImode) |
24408032 | 8143 | type = v4si_ftype_v8hi_v8hi_v4si; |
f676971a | 8144 | else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode |
617e0e1d | 8145 | && mode3 == V4SImode) |
24408032 AH |
8146 | type = v4sf_ftype_v4sf_v4sf_v4si; |
8147 | ||
8148 | /* vchar, vchar, vchar, 4 bit literal. */ | |
8149 | else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0 | |
8150 | && mode3 == QImode) | |
b9e4e5d1 | 8151 | type = v16qi_ftype_v16qi_v16qi_int; |
24408032 AH |
8152 | |
8153 | /* vshort, vshort, vshort, 4 bit literal. */ | |
8154 | else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0 | |
8155 | && mode3 == QImode) | |
b9e4e5d1 | 8156 | type = v8hi_ftype_v8hi_v8hi_int; |
24408032 AH |
8157 | |
8158 | /* vint, vint, vint, 4 bit literal. */ | |
8159 | else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0 | |
8160 | && mode3 == QImode) | |
b9e4e5d1 | 8161 | type = v4si_ftype_v4si_v4si_int; |
24408032 AH |
8162 | |
8163 | /* vfloat, vfloat, vfloat, 4 bit literal. */ | |
8164 | else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0 | |
8165 | && mode3 == QImode) | |
b9e4e5d1 | 8166 | type = v4sf_ftype_v4sf_v4sf_int; |
24408032 | 8167 | |
2212663f DB |
8168 | else |
8169 | abort (); | |
8170 | ||
8171 | def_builtin (d->mask, d->name, type, d->code); | |
8172 | } | |
8173 | ||
0ac081f6 | 8174 | /* Add the simple binary operators. */ |
00b960c7 | 8175 | d = (struct builtin_description *) bdesc_2arg; |
ca7558fc | 8176 | for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
0ac081f6 AH |
8177 | { |
8178 | enum machine_mode mode0, mode1, mode2; | |
8179 | tree type; | |
8180 | ||
0559cc77 | 8181 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
0ac081f6 | 8182 | continue; |
f676971a | 8183 | |
0ac081f6 AH |
8184 | mode0 = insn_data[d->icode].operand[0].mode; |
8185 | mode1 = insn_data[d->icode].operand[1].mode; | |
8186 | mode2 = insn_data[d->icode].operand[2].mode; | |
8187 | ||
8188 | /* When all three operands are of the same mode. */ | |
8189 | if (mode0 == mode1 && mode1 == mode2) | |
8190 | { | |
8191 | switch (mode0) | |
8192 | { | |
8193 | case V4SFmode: | |
8194 | type = v4sf_ftype_v4sf_v4sf; | |
8195 | break; | |
8196 | case V4SImode: | |
8197 | type = v4si_ftype_v4si_v4si; | |
8198 | break; | |
8199 | case V16QImode: | |
8200 | type = v16qi_ftype_v16qi_v16qi; | |
8201 | break; | |
8202 | case V8HImode: | |
8203 | type = v8hi_ftype_v8hi_v8hi; | |
8204 | break; | |
a3170dc6 AH |
8205 | case V2SImode: |
8206 | type = v2si_ftype_v2si_v2si; | |
8207 | break; | |
8208 | case V2SFmode: | |
8209 | type = v2sf_ftype_v2sf_v2sf; | |
8210 | break; | |
8211 | case SImode: | |
8212 | type = int_ftype_int_int; | |
8213 | break; | |
0ac081f6 AH |
8214 | default: |
8215 | abort (); | |
8216 | } | |
8217 | } | |
8218 | ||
8219 | /* A few other combos we really don't want to do manually. */ | |
8220 | ||
8221 | /* vint, vfloat, vfloat. */ | |
8222 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode) | |
8223 | type = v4si_ftype_v4sf_v4sf; | |
8224 | ||
8225 | /* vshort, vchar, vchar. */ | |
8226 | else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode) | |
8227 | type = v8hi_ftype_v16qi_v16qi; | |
8228 | ||
8229 | /* vint, vshort, vshort. */ | |
8230 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode) | |
8231 | type = v4si_ftype_v8hi_v8hi; | |
8232 | ||
8233 | /* vshort, vint, vint. */ | |
8234 | else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode) | |
8235 | type = v8hi_ftype_v4si_v4si; | |
8236 | ||
8237 | /* vchar, vshort, vshort. */ | |
8238 | else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode) | |
8239 | type = v16qi_ftype_v8hi_v8hi; | |
8240 | ||
8241 | /* vint, vchar, vint. */ | |
8242 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode) | |
8243 | type = v4si_ftype_v16qi_v4si; | |
8244 | ||
fa066a23 AH |
8245 | /* vint, vchar, vchar. */ |
8246 | else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode) | |
8247 | type = v4si_ftype_v16qi_v16qi; | |
8248 | ||
0ac081f6 AH |
8249 | /* vint, vshort, vint. */ |
8250 | else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode) | |
8251 | type = v4si_ftype_v8hi_v4si; | |
f676971a | 8252 | |
2212663f DB |
8253 | /* vint, vint, 5 bit literal. */ |
8254 | else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode) | |
b9e4e5d1 | 8255 | type = v4si_ftype_v4si_int; |
f676971a | 8256 | |
2212663f DB |
8257 | /* vshort, vshort, 5 bit literal. */ |
8258 | else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode) | |
b9e4e5d1 | 8259 | type = v8hi_ftype_v8hi_int; |
f676971a | 8260 | |
2212663f DB |
8261 | /* vchar, vchar, 5 bit literal. */ |
8262 | else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode) | |
b9e4e5d1 | 8263 | type = v16qi_ftype_v16qi_int; |
0ac081f6 | 8264 | |
617e0e1d DB |
8265 | /* vfloat, vint, 5 bit literal. */ |
8266 | else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode) | |
b9e4e5d1 | 8267 | type = v4sf_ftype_v4si_int; |
f676971a | 8268 | |
617e0e1d DB |
8269 | /* vint, vfloat, 5 bit literal. */ |
8270 | else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode) | |
b9e4e5d1 | 8271 | type = v4si_ftype_v4sf_int; |
617e0e1d | 8272 | |
a3170dc6 AH |
8273 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode) |
8274 | type = v2si_ftype_int_int; | |
8275 | ||
8276 | else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode) | |
8277 | type = v2si_ftype_v2si_char; | |
8278 | ||
8279 | else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode) | |
8280 | type = v2si_ftype_int_char; | |
8281 | ||
0ac081f6 AH |
8282 | /* int, x, x. */ |
8283 | else if (mode0 == SImode) | |
8284 | { | |
8285 | switch (mode1) | |
8286 | { | |
8287 | case V4SImode: | |
8288 | type = int_ftype_v4si_v4si; | |
8289 | break; | |
8290 | case V4SFmode: | |
8291 | type = int_ftype_v4sf_v4sf; | |
8292 | break; | |
8293 | case V16QImode: | |
8294 | type = int_ftype_v16qi_v16qi; | |
8295 | break; | |
8296 | case V8HImode: | |
8297 | type = int_ftype_v8hi_v8hi; | |
8298 | break; | |
8299 | default: | |
8300 | abort (); | |
8301 | } | |
8302 | } | |
8303 | ||
8304 | else | |
8305 | abort (); | |
8306 | ||
2212663f DB |
8307 | def_builtin (d->mask, d->name, type, d->code); |
8308 | } | |
24408032 | 8309 | |
2212663f DB |
8310 | /* Add the simple unary operators. */ |
8311 | d = (struct builtin_description *) bdesc_1arg; | |
ca7558fc | 8312 | for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
2212663f DB |
8313 | { |
8314 | enum machine_mode mode0, mode1; | |
8315 | tree type; | |
8316 | ||
0559cc77 | 8317 | if (d->name == 0 || d->icode == CODE_FOR_nothing) |
2212663f | 8318 | continue; |
f676971a | 8319 | |
2212663f DB |
8320 | mode0 = insn_data[d->icode].operand[0].mode; |
8321 | mode1 = insn_data[d->icode].operand[1].mode; | |
8322 | ||
8323 | if (mode0 == V4SImode && mode1 == QImode) | |
b9e4e5d1 | 8324 | type = v4si_ftype_int; |
2212663f | 8325 | else if (mode0 == V8HImode && mode1 == QImode) |
b9e4e5d1 | 8326 | type = v8hi_ftype_int; |
2212663f | 8327 | else if (mode0 == V16QImode && mode1 == QImode) |
b9e4e5d1 | 8328 | type = v16qi_ftype_int; |
617e0e1d DB |
8329 | else if (mode0 == V4SFmode && mode1 == V4SFmode) |
8330 | type = v4sf_ftype_v4sf; | |
20e26713 AH |
8331 | else if (mode0 == V8HImode && mode1 == V16QImode) |
8332 | type = v8hi_ftype_v16qi; | |
8333 | else if (mode0 == V4SImode && mode1 == V8HImode) | |
8334 | type = v4si_ftype_v8hi; | |
a3170dc6 AH |
8335 | else if (mode0 == V2SImode && mode1 == V2SImode) |
8336 | type = v2si_ftype_v2si; | |
8337 | else if (mode0 == V2SFmode && mode1 == V2SFmode) | |
8338 | type = v2sf_ftype_v2sf; | |
8339 | else if (mode0 == V2SFmode && mode1 == V2SImode) | |
8340 | type = v2sf_ftype_v2si; | |
8341 | else if (mode0 == V2SImode && mode1 == V2SFmode) | |
8342 | type = v2si_ftype_v2sf; | |
8343 | else if (mode0 == V2SImode && mode1 == QImode) | |
8344 | type = v2si_ftype_char; | |
2212663f DB |
8345 | else |
8346 | abort (); | |
8347 | ||
0ac081f6 AH |
8348 | def_builtin (d->mask, d->name, type, d->code); |
8349 | } | |
8350 | } | |
8351 | ||
c15c90bb ZW |
8352 | static void |
8353 | rs6000_init_libfuncs (void) | |
8354 | { | |
8355 | if (!TARGET_HARD_FLOAT) | |
8356 | return; | |
8357 | ||
c9034561 | 8358 | if (DEFAULT_ABI != ABI_V4) |
c15c90bb | 8359 | { |
c9034561 | 8360 | if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC) |
c15c90bb | 8361 | { |
c9034561 | 8362 | /* AIX library routines for float->int conversion. */ |
85363ca0 ZW |
8363 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc"); |
8364 | set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc"); | |
4274207b DE |
8365 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc"); |
8366 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc"); | |
c15c90bb ZW |
8367 | } |
8368 | ||
c9034561 | 8369 | /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
8370 | set_optab_libfunc (add_optab, TFmode, "_xlqadd"); |
8371 | set_optab_libfunc (sub_optab, TFmode, "_xlqsub"); | |
8372 | set_optab_libfunc (smul_optab, TFmode, "_xlqmul"); | |
8373 | set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv"); | |
8374 | } | |
c9034561 | 8375 | else |
c15c90bb | 8376 | { |
c9034561 | 8377 | /* 32-bit SVR4 quad floating point routines. */ |
c15c90bb ZW |
8378 | |
8379 | set_optab_libfunc (add_optab, TFmode, "_q_add"); | |
8380 | set_optab_libfunc (sub_optab, TFmode, "_q_sub"); | |
8381 | set_optab_libfunc (neg_optab, TFmode, "_q_neg"); | |
8382 | set_optab_libfunc (smul_optab, TFmode, "_q_mul"); | |
8383 | set_optab_libfunc (sdiv_optab, TFmode, "_q_div"); | |
8384 | if (TARGET_PPC_GPOPT || TARGET_POWER2) | |
8385 | set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt"); | |
8386 | ||
c9034561 ZW |
8387 | set_optab_libfunc (eq_optab, TFmode, "_q_feq"); |
8388 | set_optab_libfunc (ne_optab, TFmode, "_q_fne"); | |
8389 | set_optab_libfunc (gt_optab, TFmode, "_q_fgt"); | |
8390 | set_optab_libfunc (ge_optab, TFmode, "_q_fge"); | |
8391 | set_optab_libfunc (lt_optab, TFmode, "_q_flt"); | |
8392 | set_optab_libfunc (le_optab, TFmode, "_q_fle"); | |
8393 | ||
85363ca0 ZW |
8394 | set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq"); |
8395 | set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq"); | |
8396 | set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos"); | |
8397 | set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod"); | |
8398 | set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi"); | |
8399 | set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou"); | |
8400 | set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq"); | |
c15c90bb ZW |
8401 | } |
8402 | } | |
fba73eb1 DE |
8403 | |
8404 | \f | |
8405 | /* Expand a block clear operation, and return 1 if successful. Return 0 | |
8406 | if we should let the compiler generate normal code. | |
8407 | ||
8408 | operands[0] is the destination | |
8409 | operands[1] is the length | |
8410 | operands[2] is the alignment */ | |
8411 | ||
8412 | int | |
8413 | expand_block_clear (rtx operands[]) | |
8414 | { | |
8415 | rtx orig_dest = operands[0]; | |
8416 | rtx bytes_rtx = operands[1]; | |
8417 | rtx align_rtx = operands[2]; | |
5514620a GK |
8418 | bool constp = (GET_CODE (bytes_rtx) == CONST_INT); |
8419 | HOST_WIDE_INT align; | |
8420 | HOST_WIDE_INT bytes; | |
fba73eb1 DE |
8421 | int offset; |
8422 | int clear_bytes; | |
5514620a | 8423 | int clear_step; |
fba73eb1 DE |
8424 | |
8425 | /* If this is not a fixed size move, just call memcpy */ | |
8426 | if (! constp) | |
8427 | return 0; | |
8428 | ||
8429 | /* If this is not a fixed size alignment, abort */ | |
8430 | if (GET_CODE (align_rtx) != CONST_INT) | |
8431 | abort (); | |
8432 | align = INTVAL (align_rtx) * BITS_PER_UNIT; | |
8433 | ||
8434 | /* Anything to clear? */ | |
8435 | bytes = INTVAL (bytes_rtx); | |
8436 | if (bytes <= 0) | |
8437 | return 1; | |
8438 | ||
5514620a GK |
8439 | /* Use the builtin memset after a point, to avoid huge code bloat. |
8440 | When optimize_size, avoid any significant code bloat; calling | |
8441 | memset is about 4 instructions, so allow for one instruction to | |
8442 | load zero and three to do clearing. */ | |
8443 | if (TARGET_ALTIVEC && align >= 128) | |
8444 | clear_step = 16; | |
8445 | else if (TARGET_POWERPC64 && align >= 32) | |
8446 | clear_step = 8; | |
8447 | else | |
8448 | clear_step = 4; | |
fba73eb1 | 8449 | |
5514620a GK |
8450 | if (optimize_size && bytes > 3 * clear_step) |
8451 | return 0; | |
8452 | if (! optimize_size && bytes > 8 * clear_step) | |
fba73eb1 DE |
8453 | return 0; |
8454 | ||
8455 | for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes) | |
8456 | { | |
fba73eb1 DE |
8457 | enum machine_mode mode = BLKmode; |
8458 | rtx dest; | |
f676971a | 8459 | |
5514620a GK |
8460 | if (bytes >= 16 && TARGET_ALTIVEC && align >= 128) |
8461 | { | |
8462 | clear_bytes = 16; | |
8463 | mode = V4SImode; | |
8464 | } | |
8465 | else if (bytes >= 8 && TARGET_POWERPC64 | |
8466 | /* 64-bit loads and stores require word-aligned | |
8467 | displacements. */ | |
8468 | && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32))) | |
fba73eb1 DE |
8469 | { |
8470 | clear_bytes = 8; | |
8471 | mode = DImode; | |
fba73eb1 | 8472 | } |
5514620a | 8473 | else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT)) |
fba73eb1 DE |
8474 | { /* move 4 bytes */ |
8475 | clear_bytes = 4; | |
8476 | mode = SImode; | |
fba73eb1 | 8477 | } |
5514620a | 8478 | else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT)) |
fba73eb1 DE |
8479 | { /* move 2 bytes */ |
8480 | clear_bytes = 2; | |
8481 | mode = HImode; | |
fba73eb1 DE |
8482 | } |
8483 | else /* move 1 byte at a time */ | |
8484 | { | |
8485 | clear_bytes = 1; | |
8486 | mode = QImode; | |
fba73eb1 | 8487 | } |
f676971a | 8488 | |
fba73eb1 | 8489 | dest = adjust_address (orig_dest, mode, offset); |
f676971a | 8490 | |
5514620a | 8491 | emit_move_insn (dest, CONST0_RTX (mode)); |
fba73eb1 DE |
8492 | } |
8493 | ||
8494 | return 1; | |
8495 | } | |
8496 | ||
35aff10b | 8497 | \f |
7e69e155 MM |
8498 | /* Expand a block move operation, and return 1 if successful. Return 0 |
8499 | if we should let the compiler generate normal code. | |
8500 | ||
8501 | operands[0] is the destination | |
8502 | operands[1] is the source | |
8503 | operands[2] is the length | |
8504 | operands[3] is the alignment */ | |
8505 | ||
3933e0e1 MM |
8506 | #define MAX_MOVE_REG 4 |
8507 | ||
7e69e155 | 8508 | int |
a2369ed3 | 8509 | expand_block_move (rtx operands[]) |
7e69e155 | 8510 | { |
b6c9286a MM |
8511 | rtx orig_dest = operands[0]; |
8512 | rtx orig_src = operands[1]; | |
7e69e155 | 8513 | rtx bytes_rtx = operands[2]; |
7e69e155 | 8514 | rtx align_rtx = operands[3]; |
3933e0e1 | 8515 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); |
5ee95df6 | 8516 | int align; |
3933e0e1 MM |
8517 | int bytes; |
8518 | int offset; | |
7e69e155 | 8519 | int move_bytes; |
cabfd258 GK |
8520 | rtx stores[MAX_MOVE_REG]; |
8521 | int num_reg = 0; | |
7e69e155 | 8522 | |
3933e0e1 | 8523 | /* If this is not a fixed size move, just call memcpy */ |
cc0d9ba8 | 8524 | if (! constp) |
3933e0e1 MM |
8525 | return 0; |
8526 | ||
5ee95df6 FS |
8527 | /* If this is not a fixed size alignment, abort */ |
8528 | if (GET_CODE (align_rtx) != CONST_INT) | |
8529 | abort (); | |
fba73eb1 | 8530 | align = INTVAL (align_rtx) * BITS_PER_UNIT; |
5ee95df6 | 8531 | |
7e69e155 | 8532 | /* Anything to move? */ |
3933e0e1 MM |
8533 | bytes = INTVAL (bytes_rtx); |
8534 | if (bytes <= 0) | |
7e69e155 MM |
8535 | return 1; |
8536 | ||
ea9982a8 | 8537 | /* store_one_arg depends on expand_block_move to handle at least the size of |
f676971a | 8538 | reg_parm_stack_space. */ |
ea9982a8 | 8539 | if (bytes > (TARGET_POWERPC64 ? 64 : 32)) |
7e69e155 MM |
8540 | return 0; |
8541 | ||
cabfd258 | 8542 | for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes) |
7e69e155 | 8543 | { |
cabfd258 | 8544 | union { |
70128ad9 | 8545 | rtx (*movmemsi) (rtx, rtx, rtx, rtx); |
a2369ed3 | 8546 | rtx (*mov) (rtx, rtx); |
cabfd258 GK |
8547 | } gen_func; |
8548 | enum machine_mode mode = BLKmode; | |
8549 | rtx src, dest; | |
f676971a | 8550 | |
5514620a GK |
8551 | /* Altivec first, since it will be faster than a string move |
8552 | when it applies, and usually not significantly larger. */ | |
8553 | if (TARGET_ALTIVEC && bytes >= 16 && align >= 128) | |
8554 | { | |
8555 | move_bytes = 16; | |
8556 | mode = V4SImode; | |
8557 | gen_func.mov = gen_movv4si; | |
8558 | } | |
8559 | else if (TARGET_STRING | |
cabfd258 GK |
8560 | && bytes > 24 /* move up to 32 bytes at a time */ |
8561 | && ! fixed_regs[5] | |
8562 | && ! fixed_regs[6] | |
8563 | && ! fixed_regs[7] | |
8564 | && ! fixed_regs[8] | |
8565 | && ! fixed_regs[9] | |
8566 | && ! fixed_regs[10] | |
8567 | && ! fixed_regs[11] | |
8568 | && ! fixed_regs[12]) | |
7e69e155 | 8569 | { |
cabfd258 | 8570 | move_bytes = (bytes > 32) ? 32 : bytes; |
70128ad9 | 8571 | gen_func.movmemsi = gen_movmemsi_8reg; |
cabfd258 GK |
8572 | } |
8573 | else if (TARGET_STRING | |
8574 | && bytes > 16 /* move up to 24 bytes at a time */ | |
8575 | && ! fixed_regs[5] | |
8576 | && ! fixed_regs[6] | |
8577 | && ! fixed_regs[7] | |
8578 | && ! fixed_regs[8] | |
8579 | && ! fixed_regs[9] | |
8580 | && ! fixed_regs[10]) | |
8581 | { | |
8582 | move_bytes = (bytes > 24) ? 24 : bytes; | |
70128ad9 | 8583 | gen_func.movmemsi = gen_movmemsi_6reg; |
cabfd258 GK |
8584 | } |
8585 | else if (TARGET_STRING | |
8586 | && bytes > 8 /* move up to 16 bytes at a time */ | |
8587 | && ! fixed_regs[5] | |
8588 | && ! fixed_regs[6] | |
8589 | && ! fixed_regs[7] | |
8590 | && ! fixed_regs[8]) | |
8591 | { | |
8592 | move_bytes = (bytes > 16) ? 16 : bytes; | |
70128ad9 | 8593 | gen_func.movmemsi = gen_movmemsi_4reg; |
cabfd258 GK |
8594 | } |
8595 | else if (bytes >= 8 && TARGET_POWERPC64 | |
8596 | /* 64-bit loads and stores require word-aligned | |
8597 | displacements. */ | |
fba73eb1 | 8598 | && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32))) |
cabfd258 GK |
8599 | { |
8600 | move_bytes = 8; | |
8601 | mode = DImode; | |
8602 | gen_func.mov = gen_movdi; | |
8603 | } | |
8604 | else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64) | |
8605 | { /* move up to 8 bytes at a time */ | |
8606 | move_bytes = (bytes > 8) ? 8 : bytes; | |
70128ad9 | 8607 | gen_func.movmemsi = gen_movmemsi_2reg; |
cabfd258 | 8608 | } |
cd7d9ca4 | 8609 | else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT)) |
cabfd258 GK |
8610 | { /* move 4 bytes */ |
8611 | move_bytes = 4; | |
8612 | mode = SImode; | |
8613 | gen_func.mov = gen_movsi; | |
8614 | } | |
cd7d9ca4 | 8615 | else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT)) |
cabfd258 GK |
8616 | { /* move 2 bytes */ |
8617 | move_bytes = 2; | |
8618 | mode = HImode; | |
8619 | gen_func.mov = gen_movhi; | |
8620 | } | |
8621 | else if (TARGET_STRING && bytes > 1) | |
8622 | { /* move up to 4 bytes at a time */ | |
8623 | move_bytes = (bytes > 4) ? 4 : bytes; | |
70128ad9 | 8624 | gen_func.movmemsi = gen_movmemsi_1reg; |
cabfd258 GK |
8625 | } |
8626 | else /* move 1 byte at a time */ | |
8627 | { | |
8628 | move_bytes = 1; | |
8629 | mode = QImode; | |
8630 | gen_func.mov = gen_movqi; | |
8631 | } | |
f676971a | 8632 | |
cabfd258 GK |
8633 | src = adjust_address (orig_src, mode, offset); |
8634 | dest = adjust_address (orig_dest, mode, offset); | |
f676971a EC |
8635 | |
8636 | if (mode != BLKmode) | |
cabfd258 GK |
8637 | { |
8638 | rtx tmp_reg = gen_reg_rtx (mode); | |
f676971a | 8639 | |
cabfd258 GK |
8640 | emit_insn ((*gen_func.mov) (tmp_reg, src)); |
8641 | stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg); | |
4c64a852 | 8642 | } |
3933e0e1 | 8643 | |
cabfd258 GK |
8644 | if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes) |
8645 | { | |
8646 | int i; | |
8647 | for (i = 0; i < num_reg; i++) | |
8648 | emit_insn (stores[i]); | |
8649 | num_reg = 0; | |
8650 | } | |
35aff10b | 8651 | |
cabfd258 | 8652 | if (mode == BLKmode) |
7e69e155 | 8653 | { |
70128ad9 | 8654 | /* Move the address into scratch registers. The movmemsi |
cabfd258 GK |
8655 | patterns require zero offset. */ |
8656 | if (!REG_P (XEXP (src, 0))) | |
b6c9286a | 8657 | { |
cabfd258 GK |
8658 | rtx src_reg = copy_addr_to_reg (XEXP (src, 0)); |
8659 | src = replace_equiv_address (src, src_reg); | |
b6c9286a | 8660 | } |
cabfd258 | 8661 | set_mem_size (src, GEN_INT (move_bytes)); |
f676971a | 8662 | |
cabfd258 | 8663 | if (!REG_P (XEXP (dest, 0))) |
3933e0e1 | 8664 | { |
cabfd258 GK |
8665 | rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0)); |
8666 | dest = replace_equiv_address (dest, dest_reg); | |
7e69e155 | 8667 | } |
cabfd258 | 8668 | set_mem_size (dest, GEN_INT (move_bytes)); |
f676971a | 8669 | |
70128ad9 | 8670 | emit_insn ((*gen_func.movmemsi) (dest, src, |
cabfd258 GK |
8671 | GEN_INT (move_bytes & 31), |
8672 | align_rtx)); | |
7e69e155 | 8673 | } |
7e69e155 MM |
8674 | } |
8675 | ||
8676 | return 1; | |
8677 | } | |
8678 | ||
d62294f5 FJ |
8679 | \f |
8680 | /* Return 1 if OP is suitable for a save_world call in prologue. It is | |
8681 | known to be a PARALLEL. */ | |
8682 | int | |
8683 | save_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) | |
8684 | { | |
8685 | int index; | |
8686 | int i; | |
8687 | rtx elt; | |
8688 | int count = XVECLEN (op, 0); | |
8689 | ||
8690 | if (count != 55) | |
8691 | return 0; | |
8692 | ||
8693 | index = 0; | |
8694 | if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER | |
8695 | || GET_CODE (XVECEXP (op, 0, index++)) != USE) | |
8696 | return 0; | |
8697 | ||
8698 | for (i=1; i <= 18; i++) | |
8699 | { | |
8700 | elt = XVECEXP (op, 0, index++); | |
8701 | if (GET_CODE (elt) != SET | |
8702 | || GET_CODE (SET_DEST (elt)) != MEM | |
8703 | || ! memory_operand (SET_DEST (elt), DFmode) | |
8704 | || GET_CODE (SET_SRC (elt)) != REG | |
8705 | || GET_MODE (SET_SRC (elt)) != DFmode) | |
8706 | return 0; | |
8707 | } | |
8708 | ||
8709 | for (i=1; i <= 12; i++) | |
8710 | { | |
8711 | elt = XVECEXP (op, 0, index++); | |
8712 | if (GET_CODE (elt) != SET | |
8713 | || GET_CODE (SET_DEST (elt)) != MEM | |
8714 | || GET_CODE (SET_SRC (elt)) != REG | |
8715 | || GET_MODE (SET_SRC (elt)) != V4SImode) | |
8716 | return 0; | |
8717 | } | |
8718 | ||
8719 | for (i=1; i <= 19; i++) | |
8720 | { | |
8721 | elt = XVECEXP (op, 0, index++); | |
8722 | if (GET_CODE (elt) != SET | |
8723 | || GET_CODE (SET_DEST (elt)) != MEM | |
8724 | || ! memory_operand (SET_DEST (elt), Pmode) | |
8725 | || GET_CODE (SET_SRC (elt)) != REG | |
8726 | || GET_MODE (SET_SRC (elt)) != Pmode) | |
8727 | return 0; | |
8728 | } | |
8729 | ||
8730 | elt = XVECEXP (op, 0, index++); | |
8731 | if (GET_CODE (elt) != SET | |
8732 | || GET_CODE (SET_DEST (elt)) != MEM | |
8733 | || ! memory_operand (SET_DEST (elt), Pmode) | |
8734 | || GET_CODE (SET_SRC (elt)) != REG | |
8735 | || REGNO (SET_SRC (elt)) != CR2_REGNO | |
8736 | || GET_MODE (SET_SRC (elt)) != Pmode) | |
8737 | return 0; | |
8738 | ||
8739 | if (GET_CODE (XVECEXP (op, 0, index++)) != USE | |
8740 | || GET_CODE (XVECEXP (op, 0, index++)) != USE | |
8741 | || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER) | |
8742 | return 0; | |
8743 | return 1; | |
8744 | } | |
8745 | ||
8746 | /* Return 1 if OP is suitable for a save_world call in prologue. It is | |
8747 | known to be a PARALLEL. */ | |
8748 | int | |
8749 | restore_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) | |
8750 | { | |
8751 | int index; | |
8752 | int i; | |
8753 | rtx elt; | |
8754 | int count = XVECLEN (op, 0); | |
8755 | ||
8756 | if (count != 59) | |
8757 | return 0; | |
8758 | ||
8759 | index = 0; | |
8760 | if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN | |
8761 | || GET_CODE (XVECEXP (op, 0, index++)) != USE | |
8762 | || GET_CODE (XVECEXP (op, 0, index++)) != USE | |
8763 | || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER) | |
8764 | return 0; | |
8765 | ||
8766 | elt = XVECEXP (op, 0, index++); | |
8767 | if (GET_CODE (elt) != SET | |
8768 | || GET_CODE (SET_SRC (elt)) != MEM | |
8769 | || ! memory_operand (SET_SRC (elt), Pmode) | |
8770 | || GET_CODE (SET_DEST (elt)) != REG | |
8771 | || REGNO (SET_DEST (elt)) != CR2_REGNO | |
8772 | || GET_MODE (SET_DEST (elt)) != Pmode) | |
8773 | return 0; | |
8774 | ||
8775 | for (i=1; i <= 19; i++) | |
8776 | { | |
8777 | elt = XVECEXP (op, 0, index++); | |
8778 | if (GET_CODE (elt) != SET | |
8779 | || GET_CODE (SET_SRC (elt)) != MEM | |
8780 | || ! memory_operand (SET_SRC (elt), Pmode) | |
8781 | || GET_CODE (SET_DEST (elt)) != REG | |
8782 | || GET_MODE (SET_DEST (elt)) != Pmode) | |
8783 | return 0; | |
8784 | } | |
8785 | ||
8786 | for (i=1; i <= 12; i++) | |
8787 | { | |
8788 | elt = XVECEXP (op, 0, index++); | |
8789 | if (GET_CODE (elt) != SET | |
8790 | || GET_CODE (SET_SRC (elt)) != MEM | |
8791 | || GET_CODE (SET_DEST (elt)) != REG | |
8792 | || GET_MODE (SET_DEST (elt)) != V4SImode) | |
8793 | return 0; | |
8794 | } | |
8795 | ||
8796 | for (i=1; i <= 18; i++) | |
8797 | { | |
8798 | elt = XVECEXP (op, 0, index++); | |
8799 | if (GET_CODE (elt) != SET | |
8800 | || GET_CODE (SET_SRC (elt)) != MEM | |
8801 | || ! memory_operand (SET_SRC (elt), DFmode) | |
8802 | || GET_CODE (SET_DEST (elt)) != REG | |
8803 | || GET_MODE (SET_DEST (elt)) != DFmode) | |
8804 | return 0; | |
8805 | } | |
8806 | ||
8807 | if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER | |
8808 | || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER | |
8809 | || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER | |
8810 | || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER | |
8811 | || GET_CODE (XVECEXP (op, 0, index++)) != USE) | |
8812 | return 0; | |
8813 | return 1; | |
8814 | } | |
8815 | ||
9878760c RK |
8816 | \f |
8817 | /* Return 1 if OP is a load multiple operation. It is known to be a | |
8818 | PARALLEL and the first section will be tested. */ | |
8819 | ||
8820 | int | |
a2369ed3 | 8821 | load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8822 | { |
8823 | int count = XVECLEN (op, 0); | |
e2c953b6 | 8824 | unsigned int dest_regno; |
9878760c RK |
8825 | rtx src_addr; |
8826 | int i; | |
8827 | ||
8828 | /* Perform a quick check so we don't blow up below. */ | |
8829 | if (count <= 1 | |
8830 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8831 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
8832 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
8833 | return 0; | |
8834 | ||
8835 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8836 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
8837 | ||
8838 | for (i = 1; i < count; i++) | |
8839 | { | |
8840 | rtx elt = XVECEXP (op, 0, i); | |
8841 | ||
8842 | if (GET_CODE (elt) != SET | |
8843 | || GET_CODE (SET_DEST (elt)) != REG | |
8844 | || GET_MODE (SET_DEST (elt)) != SImode | |
8845 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
8846 | || GET_CODE (SET_SRC (elt)) != MEM | |
8847 | || GET_MODE (SET_SRC (elt)) != SImode | |
8848 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
8849 | || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) | |
8850 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT | |
8851 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4) | |
8852 | return 0; | |
8853 | } | |
8854 | ||
8855 | return 1; | |
8856 | } | |
8857 | ||
8858 | /* Similar, but tests for store multiple. Here, the second vector element | |
8859 | is a CLOBBER. It will be tested later. */ | |
8860 | ||
8861 | int | |
a2369ed3 | 8862 | store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
8863 | { |
8864 | int count = XVECLEN (op, 0) - 1; | |
e2c953b6 | 8865 | unsigned int src_regno; |
9878760c RK |
8866 | rtx dest_addr; |
8867 | int i; | |
8868 | ||
8869 | /* Perform a quick check so we don't blow up below. */ | |
8870 | if (count <= 1 | |
8871 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8872 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
8873 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
8874 | return 0; | |
8875 | ||
8876 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8877 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
8878 | ||
8879 | for (i = 1; i < count; i++) | |
8880 | { | |
8881 | rtx elt = XVECEXP (op, 0, i + 1); | |
8882 | ||
8883 | if (GET_CODE (elt) != SET | |
8884 | || GET_CODE (SET_SRC (elt)) != REG | |
8885 | || GET_MODE (SET_SRC (elt)) != SImode | |
8886 | || REGNO (SET_SRC (elt)) != src_regno + i | |
8887 | || GET_CODE (SET_DEST (elt)) != MEM | |
8888 | || GET_MODE (SET_DEST (elt)) != SImode | |
8889 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
8890 | || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) | |
8891 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT | |
8892 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4) | |
8893 | return 0; | |
8894 | } | |
8895 | ||
8896 | return 1; | |
8897 | } | |
9ebbca7d | 8898 | |
9caa3eb2 DE |
8899 | /* Return a string to perform a load_multiple operation. |
8900 | operands[0] is the vector. | |
8901 | operands[1] is the source address. | |
8902 | operands[2] is the first destination register. */ | |
8903 | ||
8904 | const char * | |
a2369ed3 | 8905 | rs6000_output_load_multiple (rtx operands[3]) |
9caa3eb2 DE |
8906 | { |
8907 | /* We have to handle the case where the pseudo used to contain the address | |
8908 | is assigned to one of the output registers. */ | |
8909 | int i, j; | |
8910 | int words = XVECLEN (operands[0], 0); | |
8911 | rtx xop[10]; | |
8912 | ||
8913 | if (XVECLEN (operands[0], 0) == 1) | |
8914 | return "{l|lwz} %2,0(%1)"; | |
8915 | ||
8916 | for (i = 0; i < words; i++) | |
8917 | if (refers_to_regno_p (REGNO (operands[2]) + i, | |
8918 | REGNO (operands[2]) + i + 1, operands[1], 0)) | |
8919 | { | |
8920 | if (i == words-1) | |
8921 | { | |
8922 | xop[0] = GEN_INT (4 * (words-1)); | |
8923 | xop[1] = operands[1]; | |
8924 | xop[2] = operands[2]; | |
8925 | output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop); | |
8926 | return ""; | |
8927 | } | |
8928 | else if (i == 0) | |
8929 | { | |
8930 | xop[0] = GEN_INT (4 * (words-1)); | |
8931 | xop[1] = operands[1]; | |
8932 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
8933 | 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); | |
8934 | return ""; | |
8935 | } | |
8936 | else | |
8937 | { | |
8938 | for (j = 0; j < words; j++) | |
8939 | if (j != i) | |
8940 | { | |
8941 | xop[0] = GEN_INT (j * 4); | |
8942 | xop[1] = operands[1]; | |
8943 | xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j); | |
8944 | output_asm_insn ("{l|lwz} %2,%0(%1)", xop); | |
8945 | } | |
8946 | xop[0] = GEN_INT (i * 4); | |
8947 | xop[1] = operands[1]; | |
8948 | output_asm_insn ("{l|lwz} %1,%0(%1)", xop); | |
8949 | return ""; | |
8950 | } | |
8951 | } | |
8952 | ||
8953 | return "{lsi|lswi} %2,%1,%N0"; | |
8954 | } | |
8955 | ||
00b960c7 AH |
8956 | /* Return 1 for a parallel vrsave operation. */ |
8957 | ||
8958 | int | |
a2369ed3 | 8959 | vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
00b960c7 AH |
8960 | { |
8961 | int count = XVECLEN (op, 0); | |
8962 | unsigned int dest_regno, src_regno; | |
8963 | int i; | |
8964 | ||
8965 | if (count <= 1 | |
8966 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
8967 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
a004eb82 | 8968 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE) |
00b960c7 AH |
8969 | return 0; |
8970 | ||
8971 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
8972 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
8973 | ||
8974 | if (dest_regno != VRSAVE_REGNO | |
8975 | && src_regno != VRSAVE_REGNO) | |
8976 | return 0; | |
8977 | ||
8978 | for (i = 1; i < count; i++) | |
8979 | { | |
8980 | rtx elt = XVECEXP (op, 0, i); | |
8981 | ||
9aa86737 AH |
8982 | if (GET_CODE (elt) != CLOBBER |
8983 | && GET_CODE (elt) != SET) | |
00b960c7 AH |
8984 | return 0; |
8985 | } | |
8986 | ||
8987 | return 1; | |
8988 | } | |
8989 | ||
2c4a9cff DE |
8990 | /* Return 1 for an PARALLEL suitable for mfcr. */ |
8991 | ||
8992 | int | |
a2369ed3 | 8993 | mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
2c4a9cff DE |
8994 | { |
8995 | int count = XVECLEN (op, 0); | |
8996 | int i; | |
8997 | ||
8998 | /* Perform a quick check so we don't blow up below. */ | |
8999 | if (count < 1 | |
9000 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
9001 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
9002 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9003 | return 0; | |
9004 | ||
9005 | for (i = 0; i < count; i++) | |
9006 | { | |
9007 | rtx exp = XVECEXP (op, 0, i); | |
9008 | rtx unspec; | |
9009 | int maskval; | |
9010 | rtx src_reg; | |
9011 | ||
9012 | src_reg = XVECEXP (SET_SRC (exp), 0, 0); | |
9013 | ||
9014 | if (GET_CODE (src_reg) != REG | |
9015 | || GET_MODE (src_reg) != CCmode | |
9016 | || ! CR_REGNO_P (REGNO (src_reg))) | |
9017 | return 0; | |
9018 | ||
9019 | if (GET_CODE (exp) != SET | |
9020 | || GET_CODE (SET_DEST (exp)) != REG | |
9021 | || GET_MODE (SET_DEST (exp)) != SImode | |
9022 | || ! INT_REGNO_P (REGNO (SET_DEST (exp)))) | |
9023 | return 0; | |
9024 | unspec = SET_SRC (exp); | |
9025 | maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg)); | |
9026 | ||
9027 | if (GET_CODE (unspec) != UNSPEC | |
9028 | || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR | |
9029 | || XVECLEN (unspec, 0) != 2 | |
9030 | || XVECEXP (unspec, 0, 0) != src_reg | |
9031 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
9032 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
9033 | return 0; | |
9034 | } | |
9035 | return 1; | |
9036 | } | |
9037 | ||
a4f6c312 | 9038 | /* Return 1 for an PARALLEL suitable for mtcrf. */ |
9ebbca7d GK |
9039 | |
9040 | int | |
a2369ed3 | 9041 | mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
9042 | { |
9043 | int count = XVECLEN (op, 0); | |
9044 | int i; | |
9ebbca7d GK |
9045 | rtx src_reg; |
9046 | ||
9047 | /* Perform a quick check so we don't blow up below. */ | |
e35b9579 GK |
9048 | if (count < 1 |
9049 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
9050 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC | |
9051 | || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2) | |
9ebbca7d | 9052 | return 0; |
e35b9579 | 9053 | src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0); |
f676971a | 9054 | |
9ebbca7d GK |
9055 | if (GET_CODE (src_reg) != REG |
9056 | || GET_MODE (src_reg) != SImode | |
9057 | || ! INT_REGNO_P (REGNO (src_reg))) | |
9058 | return 0; | |
9059 | ||
e35b9579 | 9060 | for (i = 0; i < count; i++) |
9ebbca7d GK |
9061 | { |
9062 | rtx exp = XVECEXP (op, 0, i); | |
9063 | rtx unspec; | |
9064 | int maskval; | |
f676971a | 9065 | |
9ebbca7d GK |
9066 | if (GET_CODE (exp) != SET |
9067 | || GET_CODE (SET_DEST (exp)) != REG | |
9068 | || GET_MODE (SET_DEST (exp)) != CCmode | |
9069 | || ! CR_REGNO_P (REGNO (SET_DEST (exp)))) | |
9070 | return 0; | |
9071 | unspec = SET_SRC (exp); | |
9072 | maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp))); | |
f676971a | 9073 | |
9ebbca7d | 9074 | if (GET_CODE (unspec) != UNSPEC |
615158e2 | 9075 | || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR |
9ebbca7d GK |
9076 | || XVECLEN (unspec, 0) != 2 |
9077 | || XVECEXP (unspec, 0, 0) != src_reg | |
9078 | || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT | |
9079 | || INTVAL (XVECEXP (unspec, 0, 1)) != maskval) | |
9080 | return 0; | |
9081 | } | |
e35b9579 | 9082 | return 1; |
9ebbca7d GK |
9083 | } |
9084 | ||
a4f6c312 | 9085 | /* Return 1 for an PARALLEL suitable for lmw. */ |
9ebbca7d GK |
9086 | |
9087 | int | |
a2369ed3 | 9088 | lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
9089 | { |
9090 | int count = XVECLEN (op, 0); | |
e2c953b6 | 9091 | unsigned int dest_regno; |
9ebbca7d | 9092 | rtx src_addr; |
e2c953b6 | 9093 | unsigned int base_regno; |
9ebbca7d GK |
9094 | HOST_WIDE_INT offset; |
9095 | int i; | |
9096 | ||
9097 | /* Perform a quick check so we don't blow up below. */ | |
9098 | if (count <= 1 | |
9099 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
9100 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG | |
9101 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM) | |
9102 | return 0; | |
9103 | ||
9104 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0))); | |
9105 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0); | |
9106 | ||
9107 | if (dest_regno > 31 | |
e2c953b6 | 9108 | || count != 32 - (int) dest_regno) |
9ebbca7d GK |
9109 | return 0; |
9110 | ||
4d588c14 | 9111 | if (legitimate_indirect_address_p (src_addr, 0)) |
9ebbca7d GK |
9112 | { |
9113 | offset = 0; | |
9114 | base_regno = REGNO (src_addr); | |
9115 | if (base_regno == 0) | |
9116 | return 0; | |
9117 | } | |
76d2b81d | 9118 | else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0)) |
9ebbca7d GK |
9119 | { |
9120 | offset = INTVAL (XEXP (src_addr, 1)); | |
9121 | base_regno = REGNO (XEXP (src_addr, 0)); | |
9122 | } | |
9123 | else | |
9124 | return 0; | |
9125 | ||
9126 | for (i = 0; i < count; i++) | |
9127 | { | |
9128 | rtx elt = XVECEXP (op, 0, i); | |
9129 | rtx newaddr; | |
9130 | rtx addr_reg; | |
9131 | HOST_WIDE_INT newoffset; | |
9132 | ||
9133 | if (GET_CODE (elt) != SET | |
9134 | || GET_CODE (SET_DEST (elt)) != REG | |
9135 | || GET_MODE (SET_DEST (elt)) != SImode | |
9136 | || REGNO (SET_DEST (elt)) != dest_regno + i | |
9137 | || GET_CODE (SET_SRC (elt)) != MEM | |
9138 | || GET_MODE (SET_SRC (elt)) != SImode) | |
9139 | return 0; | |
9140 | newaddr = XEXP (SET_SRC (elt), 0); | |
4d588c14 | 9141 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
9142 | { |
9143 | newoffset = 0; | |
9144 | addr_reg = newaddr; | |
9145 | } | |
76d2b81d | 9146 | else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
9147 | { |
9148 | addr_reg = XEXP (newaddr, 0); | |
9149 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
9150 | } | |
9151 | else | |
9152 | return 0; | |
9153 | if (REGNO (addr_reg) != base_regno | |
9154 | || newoffset != offset + 4 * i) | |
9155 | return 0; | |
9156 | } | |
9157 | ||
9158 | return 1; | |
9159 | } | |
9160 | ||
a4f6c312 | 9161 | /* Return 1 for an PARALLEL suitable for stmw. */ |
9ebbca7d GK |
9162 | |
9163 | int | |
a2369ed3 | 9164 | stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9ebbca7d GK |
9165 | { |
9166 | int count = XVECLEN (op, 0); | |
e2c953b6 | 9167 | unsigned int src_regno; |
9ebbca7d | 9168 | rtx dest_addr; |
e2c953b6 | 9169 | unsigned int base_regno; |
9ebbca7d GK |
9170 | HOST_WIDE_INT offset; |
9171 | int i; | |
9172 | ||
9173 | /* Perform a quick check so we don't blow up below. */ | |
9174 | if (count <= 1 | |
9175 | || GET_CODE (XVECEXP (op, 0, 0)) != SET | |
9176 | || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM | |
9177 | || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG) | |
9178 | return 0; | |
9179 | ||
9180 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0))); | |
9181 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0); | |
9182 | ||
9183 | if (src_regno > 31 | |
e2c953b6 | 9184 | || count != 32 - (int) src_regno) |
9ebbca7d GK |
9185 | return 0; |
9186 | ||
4d588c14 | 9187 | if (legitimate_indirect_address_p (dest_addr, 0)) |
9ebbca7d GK |
9188 | { |
9189 | offset = 0; | |
9190 | base_regno = REGNO (dest_addr); | |
9191 | if (base_regno == 0) | |
9192 | return 0; | |
9193 | } | |
76d2b81d | 9194 | else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0)) |
9ebbca7d GK |
9195 | { |
9196 | offset = INTVAL (XEXP (dest_addr, 1)); | |
9197 | base_regno = REGNO (XEXP (dest_addr, 0)); | |
9198 | } | |
9199 | else | |
9200 | return 0; | |
9201 | ||
9202 | for (i = 0; i < count; i++) | |
9203 | { | |
9204 | rtx elt = XVECEXP (op, 0, i); | |
9205 | rtx newaddr; | |
9206 | rtx addr_reg; | |
9207 | HOST_WIDE_INT newoffset; | |
9208 | ||
9209 | if (GET_CODE (elt) != SET | |
9210 | || GET_CODE (SET_SRC (elt)) != REG | |
9211 | || GET_MODE (SET_SRC (elt)) != SImode | |
9212 | || REGNO (SET_SRC (elt)) != src_regno + i | |
9213 | || GET_CODE (SET_DEST (elt)) != MEM | |
9214 | || GET_MODE (SET_DEST (elt)) != SImode) | |
9215 | return 0; | |
9216 | newaddr = XEXP (SET_DEST (elt), 0); | |
4d588c14 | 9217 | if (legitimate_indirect_address_p (newaddr, 0)) |
9ebbca7d GK |
9218 | { |
9219 | newoffset = 0; | |
9220 | addr_reg = newaddr; | |
9221 | } | |
76d2b81d | 9222 | else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0)) |
9ebbca7d GK |
9223 | { |
9224 | addr_reg = XEXP (newaddr, 0); | |
9225 | newoffset = INTVAL (XEXP (newaddr, 1)); | |
9226 | } | |
9227 | else | |
9228 | return 0; | |
9229 | if (REGNO (addr_reg) != base_regno | |
9230 | || newoffset != offset + 4 * i) | |
9231 | return 0; | |
9232 | } | |
9233 | ||
9234 | return 1; | |
9235 | } | |
9878760c | 9236 | \f |
a4f6c312 SS |
9237 | /* A validation routine: say whether CODE, a condition code, and MODE |
9238 | match. The other alternatives either don't make sense or should | |
9239 | never be generated. */ | |
39a10a29 | 9240 | |
39a10a29 | 9241 | static void |
a2369ed3 | 9242 | validate_condition_mode (enum rtx_code code, enum machine_mode mode) |
39a10a29 | 9243 | { |
ec8e098d PB |
9244 | if ((GET_RTX_CLASS (code) != RTX_COMPARE |
9245 | && GET_RTX_CLASS (code) != RTX_COMM_COMPARE) | |
39a10a29 GK |
9246 | || GET_MODE_CLASS (mode) != MODE_CC) |
9247 | abort (); | |
9248 | ||
9249 | /* These don't make sense. */ | |
9250 | if ((code == GT || code == LT || code == GE || code == LE) | |
9251 | && mode == CCUNSmode) | |
9252 | abort (); | |
9253 | ||
9254 | if ((code == GTU || code == LTU || code == GEU || code == LEU) | |
9255 | && mode != CCUNSmode) | |
9256 | abort (); | |
9257 | ||
9258 | if (mode != CCFPmode | |
9259 | && (code == ORDERED || code == UNORDERED | |
9260 | || code == UNEQ || code == LTGT | |
9261 | || code == UNGT || code == UNLT | |
9262 | || code == UNGE || code == UNLE)) | |
a4f6c312 | 9263 | abort (); |
f676971a EC |
9264 | |
9265 | /* These should never be generated except for | |
bc9ec0e0 | 9266 | flag_finite_math_only. */ |
39a10a29 | 9267 | if (mode == CCFPmode |
ad72b533 | 9268 | && ! flag_finite_math_only |
39a10a29 GK |
9269 | && (code == LE || code == GE |
9270 | || code == UNEQ || code == LTGT | |
9271 | || code == UNGT || code == UNLT)) | |
9272 | abort (); | |
9273 | ||
9274 | /* These are invalid; the information is not there. */ | |
f676971a | 9275 | if (mode == CCEQmode |
39a10a29 GK |
9276 | && code != EQ && code != NE) |
9277 | abort (); | |
9278 | } | |
9279 | ||
9878760c RK |
9280 | /* Return 1 if OP is a comparison operation that is valid for a branch insn. |
9281 | We only check the opcode against the mode of the CC value here. */ | |
9282 | ||
9283 | int | |
a2369ed3 | 9284 | branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
9878760c RK |
9285 | { |
9286 | enum rtx_code code = GET_CODE (op); | |
9287 | enum machine_mode cc_mode; | |
9288 | ||
ec8e098d | 9289 | if (!COMPARISON_P (op)) |
9878760c RK |
9290 | return 0; |
9291 | ||
9292 | cc_mode = GET_MODE (XEXP (op, 0)); | |
9293 | if (GET_MODE_CLASS (cc_mode) != MODE_CC) | |
9294 | return 0; | |
9295 | ||
39a10a29 | 9296 | validate_condition_mode (code, cc_mode); |
9878760c | 9297 | |
39a10a29 GK |
9298 | return 1; |
9299 | } | |
9300 | ||
9301 | /* Return 1 if OP is a comparison operation that is valid for a branch | |
9302 | insn and which is true if the corresponding bit in the CC register | |
9303 | is set. */ | |
9304 | ||
9305 | int | |
a2369ed3 | 9306 | branch_positive_comparison_operator (rtx op, enum machine_mode mode) |
39a10a29 GK |
9307 | { |
9308 | enum rtx_code code; | |
9309 | ||
8daf2e65 | 9310 | if (! branch_comparison_operator (op, mode)) |
9878760c RK |
9311 | return 0; |
9312 | ||
39a10a29 GK |
9313 | code = GET_CODE (op); |
9314 | return (code == EQ || code == LT || code == GT | |
9315 | || code == LTU || code == GTU | |
9316 | || code == UNORDERED); | |
9878760c RK |
9317 | } |
9318 | ||
b7053a3f GK |
9319 | /* Return 1 if OP is a comparison operation that is valid for an scc |
9320 | insn: it must be a positive comparison. */ | |
9878760c RK |
9321 | |
9322 | int | |
a2369ed3 | 9323 | scc_comparison_operator (rtx op, enum machine_mode mode) |
9878760c | 9324 | { |
b7053a3f | 9325 | return branch_positive_comparison_operator (op, mode); |
9878760c | 9326 | } |
e0cd0770 JC |
9327 | |
9328 | int | |
a2369ed3 | 9329 | trap_comparison_operator (rtx op, enum machine_mode mode) |
e0cd0770 JC |
9330 | { |
9331 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
9332 | return 0; | |
ec8e098d | 9333 | return COMPARISON_P (op); |
e0cd0770 | 9334 | } |
dfbdccdb GK |
9335 | |
9336 | int | |
a2369ed3 | 9337 | boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
dfbdccdb GK |
9338 | { |
9339 | enum rtx_code code = GET_CODE (op); | |
9340 | return (code == AND || code == IOR || code == XOR); | |
9341 | } | |
1d328b19 GK |
9342 | |
9343 | int | |
a2369ed3 | 9344 | boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
1d328b19 GK |
9345 | { |
9346 | enum rtx_code code = GET_CODE (op); | |
9347 | return (code == IOR || code == XOR); | |
9348 | } | |
50a0b056 GK |
9349 | |
9350 | int | |
a2369ed3 | 9351 | min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED) |
50a0b056 GK |
9352 | { |
9353 | enum rtx_code code = GET_CODE (op); | |
9354 | return (code == SMIN || code == SMAX || code == UMIN || code == UMAX); | |
9355 | } | |
9878760c RK |
9356 | \f |
9357 | /* Return 1 if ANDOP is a mask that has no bits on that are not in the | |
9358 | mask required to convert the result of a rotate insn into a shift | |
b1765bde | 9359 | left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */ |
9878760c RK |
9360 | |
9361 | int | |
a2369ed3 | 9362 | includes_lshift_p (rtx shiftop, rtx andop) |
9878760c | 9363 | { |
e2c953b6 DE |
9364 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9365 | ||
9366 | shift_mask <<= INTVAL (shiftop); | |
9878760c | 9367 | |
b1765bde | 9368 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
9878760c RK |
9369 | } |
9370 | ||
9371 | /* Similar, but for right shift. */ | |
9372 | ||
9373 | int | |
a2369ed3 | 9374 | includes_rshift_p (rtx shiftop, rtx andop) |
9878760c | 9375 | { |
a7653a2c | 9376 | unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0; |
9878760c RK |
9377 | |
9378 | shift_mask >>= INTVAL (shiftop); | |
9379 | ||
b1765bde | 9380 | return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0; |
e2c953b6 DE |
9381 | } |
9382 | ||
c5059423 AM |
9383 | /* Return 1 if ANDOP is a mask suitable for use with an rldic insn |
9384 | to perform a left shift. It must have exactly SHIFTOP least | |
b6d08ca1 | 9385 | significant 0's, then one or more 1's, then zero or more 0's. */ |
e2c953b6 DE |
9386 | |
9387 | int | |
a2369ed3 | 9388 | includes_rldic_lshift_p (rtx shiftop, rtx andop) |
e2c953b6 | 9389 | { |
c5059423 AM |
9390 | if (GET_CODE (andop) == CONST_INT) |
9391 | { | |
02071907 | 9392 | HOST_WIDE_INT c, lsb, shift_mask; |
e2c953b6 | 9393 | |
c5059423 | 9394 | c = INTVAL (andop); |
02071907 | 9395 | if (c == 0 || c == ~0) |
c5059423 | 9396 | return 0; |
e2c953b6 | 9397 | |
02071907 | 9398 | shift_mask = ~0; |
c5059423 AM |
9399 | shift_mask <<= INTVAL (shiftop); |
9400 | ||
b6d08ca1 | 9401 | /* Find the least significant one bit. */ |
c5059423 AM |
9402 | lsb = c & -c; |
9403 | ||
9404 | /* It must coincide with the LSB of the shift mask. */ | |
9405 | if (-lsb != shift_mask) | |
9406 | return 0; | |
e2c953b6 | 9407 | |
c5059423 AM |
9408 | /* Invert to look for the next transition (if any). */ |
9409 | c = ~c; | |
9410 | ||
9411 | /* Remove the low group of ones (originally low group of zeros). */ | |
9412 | c &= -lsb; | |
9413 | ||
9414 | /* Again find the lsb, and check we have all 1's above. */ | |
9415 | lsb = c & -c; | |
9416 | return c == -lsb; | |
9417 | } | |
9418 | else if (GET_CODE (andop) == CONST_DOUBLE | |
9419 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
9420 | { | |
02071907 AM |
9421 | HOST_WIDE_INT low, high, lsb; |
9422 | HOST_WIDE_INT shift_mask_low, shift_mask_high; | |
c5059423 AM |
9423 | |
9424 | low = CONST_DOUBLE_LOW (andop); | |
9425 | if (HOST_BITS_PER_WIDE_INT < 64) | |
9426 | high = CONST_DOUBLE_HIGH (andop); | |
9427 | ||
9428 | if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0)) | |
02071907 | 9429 | || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0))) |
c5059423 AM |
9430 | return 0; |
9431 | ||
9432 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
9433 | { | |
02071907 | 9434 | shift_mask_high = ~0; |
c5059423 AM |
9435 | if (INTVAL (shiftop) > 32) |
9436 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
9437 | ||
9438 | lsb = high & -high; | |
9439 | ||
9440 | if (-lsb != shift_mask_high || INTVAL (shiftop) < 32) | |
9441 | return 0; | |
9442 | ||
9443 | high = ~high; | |
9444 | high &= -lsb; | |
9445 | ||
9446 | lsb = high & -high; | |
9447 | return high == -lsb; | |
9448 | } | |
9449 | ||
02071907 | 9450 | shift_mask_low = ~0; |
c5059423 AM |
9451 | shift_mask_low <<= INTVAL (shiftop); |
9452 | ||
9453 | lsb = low & -low; | |
9454 | ||
9455 | if (-lsb != shift_mask_low) | |
9456 | return 0; | |
9457 | ||
9458 | if (HOST_BITS_PER_WIDE_INT < 64) | |
9459 | high = ~high; | |
9460 | low = ~low; | |
9461 | low &= -lsb; | |
9462 | ||
9463 | if (HOST_BITS_PER_WIDE_INT < 64 && low == 0) | |
9464 | { | |
9465 | lsb = high & -high; | |
9466 | return high == -lsb; | |
9467 | } | |
9468 | ||
9469 | lsb = low & -low; | |
9470 | return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0); | |
9471 | } | |
9472 | else | |
9473 | return 0; | |
9474 | } | |
e2c953b6 | 9475 | |
c5059423 AM |
9476 | /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn |
9477 | to perform a left shift. It must have SHIFTOP or more least | |
c1207243 | 9478 | significant 0's, with the remainder of the word 1's. */ |
e2c953b6 | 9479 | |
c5059423 | 9480 | int |
a2369ed3 | 9481 | includes_rldicr_lshift_p (rtx shiftop, rtx andop) |
c5059423 | 9482 | { |
e2c953b6 | 9483 | if (GET_CODE (andop) == CONST_INT) |
c5059423 | 9484 | { |
02071907 | 9485 | HOST_WIDE_INT c, lsb, shift_mask; |
c5059423 | 9486 | |
02071907 | 9487 | shift_mask = ~0; |
c5059423 AM |
9488 | shift_mask <<= INTVAL (shiftop); |
9489 | c = INTVAL (andop); | |
9490 | ||
c1207243 | 9491 | /* Find the least significant one bit. */ |
c5059423 AM |
9492 | lsb = c & -c; |
9493 | ||
9494 | /* It must be covered by the shift mask. | |
a4f6c312 | 9495 | This test also rejects c == 0. */ |
c5059423 AM |
9496 | if ((lsb & shift_mask) == 0) |
9497 | return 0; | |
9498 | ||
9499 | /* Check we have all 1's above the transition, and reject all 1's. */ | |
9500 | return c == -lsb && lsb != 1; | |
9501 | } | |
9502 | else if (GET_CODE (andop) == CONST_DOUBLE | |
9503 | && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode)) | |
9504 | { | |
02071907 | 9505 | HOST_WIDE_INT low, lsb, shift_mask_low; |
c5059423 AM |
9506 | |
9507 | low = CONST_DOUBLE_LOW (andop); | |
9508 | ||
9509 | if (HOST_BITS_PER_WIDE_INT < 64) | |
9510 | { | |
02071907 | 9511 | HOST_WIDE_INT high, shift_mask_high; |
c5059423 AM |
9512 | |
9513 | high = CONST_DOUBLE_HIGH (andop); | |
9514 | ||
9515 | if (low == 0) | |
9516 | { | |
02071907 | 9517 | shift_mask_high = ~0; |
c5059423 AM |
9518 | if (INTVAL (shiftop) > 32) |
9519 | shift_mask_high <<= INTVAL (shiftop) - 32; | |
9520 | ||
9521 | lsb = high & -high; | |
9522 | ||
9523 | if ((lsb & shift_mask_high) == 0) | |
9524 | return 0; | |
9525 | ||
9526 | return high == -lsb; | |
9527 | } | |
9528 | if (high != ~0) | |
9529 | return 0; | |
9530 | } | |
9531 | ||
02071907 | 9532 | shift_mask_low = ~0; |
c5059423 AM |
9533 | shift_mask_low <<= INTVAL (shiftop); |
9534 | ||
9535 | lsb = low & -low; | |
9536 | ||
9537 | if ((lsb & shift_mask_low) == 0) | |
9538 | return 0; | |
9539 | ||
9540 | return low == -lsb && lsb != 1; | |
9541 | } | |
e2c953b6 | 9542 | else |
c5059423 | 9543 | return 0; |
9878760c | 9544 | } |
35068b43 | 9545 | |
11ac38b2 DE |
9546 | /* Return 1 if operands will generate a valid arguments to rlwimi |
9547 | instruction for insert with right shift in 64-bit mode. The mask may | |
9548 | not start on the first bit or stop on the last bit because wrap-around | |
9549 | effects of instruction do not correspond to semantics of RTL insn. */ | |
9550 | ||
9551 | int | |
9552 | insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop) | |
9553 | { | |
9554 | if (INTVAL (startop) < 64 | |
9555 | && INTVAL (startop) > 32 | |
9556 | && (INTVAL (sizeop) + INTVAL (startop) < 64) | |
9557 | && (INTVAL (sizeop) + INTVAL (startop) > 33) | |
9558 | && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96) | |
9559 | && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64) | |
9560 | && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop)) | |
9561 | return 1; | |
9562 | ||
9563 | return 0; | |
9564 | } | |
9565 | ||
35068b43 | 9566 | /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates |
90f81f99 | 9567 | for lfq and stfq insns iff the registers are hard registers. */ |
35068b43 RK |
9568 | |
9569 | int | |
a2369ed3 | 9570 | registers_ok_for_quad_peep (rtx reg1, rtx reg2) |
35068b43 RK |
9571 | { |
9572 | /* We might have been passed a SUBREG. */ | |
f676971a | 9573 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) |
35068b43 | 9574 | return 0; |
f676971a | 9575 | |
90f81f99 AP |
9576 | /* We might have been passed non floating point registers. */ |
9577 | if (!FP_REGNO_P (REGNO (reg1)) | |
9578 | || !FP_REGNO_P (REGNO (reg2))) | |
9579 | return 0; | |
35068b43 RK |
9580 | |
9581 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
9582 | } | |
9583 | ||
a4f6c312 SS |
9584 | /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn. |
9585 | addr1 and addr2 must be in consecutive memory locations | |
9586 | (addr2 == addr1 + 8). */ | |
35068b43 RK |
9587 | |
9588 | int | |
90f81f99 | 9589 | mems_ok_for_quad_peep (rtx mem1, rtx mem2) |
35068b43 | 9590 | { |
90f81f99 | 9591 | rtx addr1, addr2; |
e2c953b6 | 9592 | unsigned int reg1; |
35068b43 RK |
9593 | int offset1; |
9594 | ||
90f81f99 AP |
9595 | /* The mems cannot be volatile. */ |
9596 | if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2)) | |
9597 | return 0; | |
f676971a | 9598 | |
90f81f99 AP |
9599 | addr1 = XEXP (mem1, 0); |
9600 | addr2 = XEXP (mem2, 0); | |
9601 | ||
35068b43 RK |
9602 | /* Extract an offset (if used) from the first addr. */ |
9603 | if (GET_CODE (addr1) == PLUS) | |
9604 | { | |
9605 | /* If not a REG, return zero. */ | |
9606 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
9607 | return 0; | |
9608 | else | |
9609 | { | |
9610 | reg1 = REGNO (XEXP (addr1, 0)); | |
9611 | /* The offset must be constant! */ | |
9612 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
9613 | return 0; | |
9614 | offset1 = INTVAL (XEXP (addr1, 1)); | |
9615 | } | |
9616 | } | |
9617 | else if (GET_CODE (addr1) != REG) | |
9618 | return 0; | |
9619 | else | |
9620 | { | |
9621 | reg1 = REGNO (addr1); | |
9622 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
9623 | offset1 = 0; | |
9624 | } | |
9625 | ||
a2369ed3 | 9626 | /* Make sure the second address is a (mem (plus (reg) (const_int))) |
f676971a | 9627 | or if it is (mem (reg)) then make sure that offset1 is -8 and the same |
0f6937fe | 9628 | register as addr1. */ |
984e25ac | 9629 | if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2)) |
0f6937fe | 9630 | return 1; |
35068b43 RK |
9631 | if (GET_CODE (addr2) != PLUS) |
9632 | return 0; | |
9633 | ||
9634 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
9635 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
9636 | return 0; | |
9637 | ||
9638 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
9639 | return 0; | |
9640 | ||
9641 | /* The offset for the second addr must be 8 more than the first addr. */ | |
9642 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 8) | |
9643 | return 0; | |
9644 | ||
9645 | /* All the tests passed. addr1 and addr2 are valid for lfq or stfq | |
9646 | instructions. */ | |
9647 | return 1; | |
9648 | } | |
9878760c RK |
9649 | \f |
9650 | /* Return the register class of a scratch register needed to copy IN into | |
9651 | or out of a register in CLASS in MODE. If it can be done directly, | |
9652 | NO_REGS is returned. */ | |
9653 | ||
9654 | enum reg_class | |
f676971a | 9655 | secondary_reload_class (enum reg_class class, |
a9baceb1 GK |
9656 | enum machine_mode mode ATTRIBUTE_UNUSED, |
9657 | rtx in) | |
9878760c | 9658 | { |
5accd822 | 9659 | int regno; |
9878760c | 9660 | |
ab82a49f AP |
9661 | if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN |
9662 | #if TARGET_MACHO | |
9663 | && MACHOPIC_INDIRECT | |
9664 | #endif | |
9665 | )) | |
46fad5b7 DJ |
9666 | { |
9667 | /* We cannot copy a symbolic operand directly into anything | |
9668 | other than BASE_REGS for TARGET_ELF. So indicate that a | |
9669 | register from BASE_REGS is needed as an intermediate | |
9670 | register. | |
f676971a | 9671 | |
46fad5b7 DJ |
9672 | On Darwin, pic addresses require a load from memory, which |
9673 | needs a base register. */ | |
9674 | if (class != BASE_REGS | |
9675 | && (GET_CODE (in) == SYMBOL_REF | |
9676 | || GET_CODE (in) == HIGH | |
9677 | || GET_CODE (in) == LABEL_REF | |
9678 | || GET_CODE (in) == CONST)) | |
9679 | return BASE_REGS; | |
9680 | } | |
e7b7998a | 9681 | |
5accd822 DE |
9682 | if (GET_CODE (in) == REG) |
9683 | { | |
9684 | regno = REGNO (in); | |
9685 | if (regno >= FIRST_PSEUDO_REGISTER) | |
9686 | { | |
9687 | regno = true_regnum (in); | |
9688 | if (regno >= FIRST_PSEUDO_REGISTER) | |
9689 | regno = -1; | |
9690 | } | |
9691 | } | |
9692 | else if (GET_CODE (in) == SUBREG) | |
9693 | { | |
9694 | regno = true_regnum (in); | |
9695 | if (regno >= FIRST_PSEUDO_REGISTER) | |
9696 | regno = -1; | |
9697 | } | |
9698 | else | |
9699 | regno = -1; | |
9700 | ||
9878760c RK |
9701 | /* We can place anything into GENERAL_REGS and can put GENERAL_REGS |
9702 | into anything. */ | |
9703 | if (class == GENERAL_REGS || class == BASE_REGS | |
9704 | || (regno >= 0 && INT_REGNO_P (regno))) | |
9705 | return NO_REGS; | |
9706 | ||
9707 | /* Constants, memory, and FP registers can go into FP registers. */ | |
9708 | if ((regno == -1 || FP_REGNO_P (regno)) | |
9709 | && (class == FLOAT_REGS || class == NON_SPECIAL_REGS)) | |
9710 | return NO_REGS; | |
9711 | ||
0ac081f6 AH |
9712 | /* Memory, and AltiVec registers can go into AltiVec registers. */ |
9713 | if ((regno == -1 || ALTIVEC_REGNO_P (regno)) | |
9714 | && class == ALTIVEC_REGS) | |
9715 | return NO_REGS; | |
9716 | ||
9878760c RK |
9717 | /* We can copy among the CR registers. */ |
9718 | if ((class == CR_REGS || class == CR0_REGS) | |
9719 | && regno >= 0 && CR_REGNO_P (regno)) | |
9720 | return NO_REGS; | |
9721 | ||
9722 | /* Otherwise, we need GENERAL_REGS. */ | |
9723 | return GENERAL_REGS; | |
9724 | } | |
9725 | \f | |
9726 | /* Given a comparison operation, return the bit number in CCR to test. We | |
f676971a | 9727 | know this is a valid comparison. |
9878760c RK |
9728 | |
9729 | SCC_P is 1 if this is for an scc. That means that %D will have been | |
9730 | used instead of %C, so the bits will be in different places. | |
9731 | ||
b4ac57ab | 9732 | Return -1 if OP isn't a valid comparison for some reason. */ |
9878760c RK |
9733 | |
9734 | int | |
a2369ed3 | 9735 | ccr_bit (rtx op, int scc_p) |
9878760c RK |
9736 | { |
9737 | enum rtx_code code = GET_CODE (op); | |
9738 | enum machine_mode cc_mode; | |
9739 | int cc_regnum; | |
9740 | int base_bit; | |
9ebbca7d | 9741 | rtx reg; |
9878760c | 9742 | |
ec8e098d | 9743 | if (!COMPARISON_P (op)) |
9878760c RK |
9744 | return -1; |
9745 | ||
9ebbca7d GK |
9746 | reg = XEXP (op, 0); |
9747 | ||
9748 | if (GET_CODE (reg) != REG | |
9749 | || ! CR_REGNO_P (REGNO (reg))) | |
9750 | abort (); | |
9751 | ||
9752 | cc_mode = GET_MODE (reg); | |
9753 | cc_regnum = REGNO (reg); | |
9754 | base_bit = 4 * (cc_regnum - CR0_REGNO); | |
9878760c | 9755 | |
39a10a29 | 9756 | validate_condition_mode (code, cc_mode); |
c5defebb | 9757 | |
b7053a3f GK |
9758 | /* When generating a sCOND operation, only positive conditions are |
9759 | allowed. */ | |
9760 | if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED | |
9761 | && code != GTU && code != LTU) | |
9762 | abort (); | |
f676971a | 9763 | |
9878760c RK |
9764 | switch (code) |
9765 | { | |
9766 | case NE: | |
9767 | return scc_p ? base_bit + 3 : base_bit + 2; | |
9768 | case EQ: | |
9769 | return base_bit + 2; | |
1c882ea4 | 9770 | case GT: case GTU: case UNLE: |
9878760c | 9771 | return base_bit + 1; |
1c882ea4 | 9772 | case LT: case LTU: case UNGE: |
9878760c | 9773 | return base_bit; |
1c882ea4 GK |
9774 | case ORDERED: case UNORDERED: |
9775 | return base_bit + 3; | |
9878760c RK |
9776 | |
9777 | case GE: case GEU: | |
39a10a29 | 9778 | /* If scc, we will have done a cror to put the bit in the |
9878760c RK |
9779 | unordered position. So test that bit. For integer, this is ! LT |
9780 | unless this is an scc insn. */ | |
39a10a29 | 9781 | return scc_p ? base_bit + 3 : base_bit; |
9878760c RK |
9782 | |
9783 | case LE: case LEU: | |
39a10a29 | 9784 | return scc_p ? base_bit + 3 : base_bit + 1; |
1c882ea4 | 9785 | |
9878760c RK |
9786 | default: |
9787 | abort (); | |
9788 | } | |
9789 | } | |
1ff7789b | 9790 | \f |
8d30c4ee | 9791 | /* Return the GOT register. */ |
1ff7789b MM |
9792 | |
9793 | struct rtx_def * | |
a2369ed3 | 9794 | rs6000_got_register (rtx value ATTRIBUTE_UNUSED) |
1ff7789b | 9795 | { |
a4f6c312 SS |
9796 | /* The second flow pass currently (June 1999) can't update |
9797 | regs_ever_live without disturbing other parts of the compiler, so | |
9798 | update it here to make the prolog/epilogue code happy. */ | |
1db02437 FS |
9799 | if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]) |
9800 | regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1; | |
1ff7789b | 9801 | |
8d30c4ee | 9802 | current_function_uses_pic_offset_table = 1; |
3cb999d8 | 9803 | |
1ff7789b MM |
9804 | return pic_offset_table_rtx; |
9805 | } | |
a7df97e6 | 9806 | \f |
e2500fed GK |
9807 | /* Function to init struct machine_function. |
9808 | This will be called, via a pointer variable, | |
9809 | from push_function_context. */ | |
a7df97e6 | 9810 | |
e2500fed | 9811 | static struct machine_function * |
863d938c | 9812 | rs6000_init_machine_status (void) |
a7df97e6 | 9813 | { |
e2500fed | 9814 | return ggc_alloc_cleared (sizeof (machine_function)); |
a7df97e6 | 9815 | } |
9878760c | 9816 | \f |
0ba1b2ff AM |
9817 | /* These macros test for integers and extract the low-order bits. */ |
9818 | #define INT_P(X) \ | |
9819 | ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \ | |
9820 | && GET_MODE (X) == VOIDmode) | |
9821 | ||
9822 | #define INT_LOWPART(X) \ | |
9823 | (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X)) | |
9824 | ||
9825 | int | |
a2369ed3 | 9826 | extract_MB (rtx op) |
0ba1b2ff AM |
9827 | { |
9828 | int i; | |
9829 | unsigned long val = INT_LOWPART (op); | |
9830 | ||
9831 | /* If the high bit is zero, the value is the first 1 bit we find | |
9832 | from the left. */ | |
9833 | if ((val & 0x80000000) == 0) | |
9834 | { | |
9835 | if ((val & 0xffffffff) == 0) | |
9836 | abort (); | |
9837 | ||
9838 | i = 1; | |
9839 | while (((val <<= 1) & 0x80000000) == 0) | |
9840 | ++i; | |
9841 | return i; | |
9842 | } | |
9843 | ||
9844 | /* If the high bit is set and the low bit is not, or the mask is all | |
9845 | 1's, the value is zero. */ | |
9846 | if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff) | |
9847 | return 0; | |
9848 | ||
9849 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
9850 | from the right. */ | |
9851 | i = 31; | |
9852 | while (((val >>= 1) & 1) != 0) | |
9853 | --i; | |
9854 | ||
9855 | return i; | |
9856 | } | |
9857 | ||
9858 | int | |
a2369ed3 | 9859 | extract_ME (rtx op) |
0ba1b2ff AM |
9860 | { |
9861 | int i; | |
9862 | unsigned long val = INT_LOWPART (op); | |
9863 | ||
9864 | /* If the low bit is zero, the value is the first 1 bit we find from | |
9865 | the right. */ | |
9866 | if ((val & 1) == 0) | |
9867 | { | |
9868 | if ((val & 0xffffffff) == 0) | |
9869 | abort (); | |
9870 | ||
9871 | i = 30; | |
9872 | while (((val >>= 1) & 1) == 0) | |
9873 | --i; | |
9874 | ||
9875 | return i; | |
9876 | } | |
9877 | ||
9878 | /* If the low bit is set and the high bit is not, or the mask is all | |
9879 | 1's, the value is 31. */ | |
9880 | if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff) | |
9881 | return 31; | |
9882 | ||
9883 | /* Otherwise we have a wrap-around mask. Look for the first 0 bit | |
9884 | from the left. */ | |
9885 | i = 0; | |
9886 | while (((val <<= 1) & 0x80000000) != 0) | |
9887 | ++i; | |
9888 | ||
9889 | return i; | |
9890 | } | |
9891 | ||
c4501e62 JJ |
9892 | /* Locate some local-dynamic symbol still in use by this function |
9893 | so that we can print its name in some tls_ld pattern. */ | |
9894 | ||
9895 | static const char * | |
863d938c | 9896 | rs6000_get_some_local_dynamic_name (void) |
c4501e62 JJ |
9897 | { |
9898 | rtx insn; | |
9899 | ||
9900 | if (cfun->machine->some_ld_name) | |
9901 | return cfun->machine->some_ld_name; | |
9902 | ||
9903 | for (insn = get_insns (); insn ; insn = NEXT_INSN (insn)) | |
9904 | if (INSN_P (insn) | |
9905 | && for_each_rtx (&PATTERN (insn), | |
9906 | rs6000_get_some_local_dynamic_name_1, 0)) | |
9907 | return cfun->machine->some_ld_name; | |
9908 | ||
9909 | abort (); | |
9910 | } | |
9911 | ||
9912 | /* Helper function for rs6000_get_some_local_dynamic_name. */ | |
9913 | ||
9914 | static int | |
a2369ed3 | 9915 | rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED) |
c4501e62 JJ |
9916 | { |
9917 | rtx x = *px; | |
9918 | ||
9919 | if (GET_CODE (x) == SYMBOL_REF) | |
9920 | { | |
9921 | const char *str = XSTR (x, 0); | |
9922 | if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC) | |
9923 | { | |
9924 | cfun->machine->some_ld_name = str; | |
9925 | return 1; | |
9926 | } | |
9927 | } | |
9928 | ||
9929 | return 0; | |
9930 | } | |
9931 | ||
85b776df AM |
9932 | /* Write out a function code label. */ |
9933 | ||
9934 | void | |
9935 | rs6000_output_function_entry (FILE *file, const char *fname) | |
9936 | { | |
9937 | if (fname[0] != '.') | |
9938 | { | |
9939 | switch (DEFAULT_ABI) | |
9940 | { | |
9941 | default: | |
9942 | abort (); | |
9943 | ||
9944 | case ABI_AIX: | |
9945 | if (DOT_SYMBOLS) | |
9946 | putc ('.', file); | |
9947 | else | |
9948 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L."); | |
9949 | break; | |
9950 | ||
9951 | case ABI_V4: | |
9952 | case ABI_DARWIN: | |
9953 | break; | |
9954 | } | |
9955 | } | |
9956 | if (TARGET_AIX) | |
9957 | RS6000_OUTPUT_BASENAME (file, fname); | |
9958 | else | |
9959 | assemble_name (file, fname); | |
9960 | } | |
9961 | ||
9878760c RK |
9962 | /* Print an operand. Recognize special options, documented below. */ |
9963 | ||
38c1f2d7 | 9964 | #if TARGET_ELF |
d9407988 | 9965 | #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel") |
8fbd2dc7 | 9966 | #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13) |
ba5e43aa MM |
9967 | #else |
9968 | #define SMALL_DATA_RELOC "sda21" | |
8fbd2dc7 | 9969 | #define SMALL_DATA_REG 0 |
ba5e43aa MM |
9970 | #endif |
9971 | ||
9878760c | 9972 | void |
a2369ed3 | 9973 | print_operand (FILE *file, rtx x, int code) |
9878760c RK |
9974 | { |
9975 | int i; | |
a260abc9 | 9976 | HOST_WIDE_INT val; |
0ba1b2ff | 9977 | unsigned HOST_WIDE_INT uval; |
9878760c RK |
9978 | |
9979 | switch (code) | |
9980 | { | |
a8b3aeda | 9981 | case '.': |
a85d226b RK |
9982 | /* Write out an instruction after the call which may be replaced |
9983 | with glue code by the loader. This depends on the AIX version. */ | |
9984 | asm_fprintf (file, RS6000_CALL_GLUE); | |
a8b3aeda RK |
9985 | return; |
9986 | ||
81eace42 GK |
9987 | /* %a is output_address. */ |
9988 | ||
9854d9ed RK |
9989 | case 'A': |
9990 | /* If X is a constant integer whose low-order 5 bits are zero, | |
9991 | write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug | |
76229ac8 | 9992 | in the AIX assembler where "sri" with a zero shift count |
20e26713 | 9993 | writes a trash instruction. */ |
9854d9ed | 9994 | if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0) |
76229ac8 | 9995 | putc ('l', file); |
9854d9ed | 9996 | else |
76229ac8 | 9997 | putc ('r', file); |
9854d9ed RK |
9998 | return; |
9999 | ||
10000 | case 'b': | |
e2c953b6 DE |
10001 | /* If constant, low-order 16 bits of constant, unsigned. |
10002 | Otherwise, write normally. */ | |
10003 | if (INT_P (x)) | |
10004 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff); | |
10005 | else | |
10006 | print_operand (file, x, 0); | |
cad12a8d RK |
10007 | return; |
10008 | ||
a260abc9 DE |
10009 | case 'B': |
10010 | /* If the low-order bit is zero, write 'r'; otherwise, write 'l' | |
10011 | for 64-bit mask direction. */ | |
296b8152 | 10012 | putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file); |
a238cd8b | 10013 | return; |
a260abc9 | 10014 | |
81eace42 GK |
10015 | /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise |
10016 | output_operand. */ | |
10017 | ||
423c1189 AH |
10018 | case 'c': |
10019 | /* X is a CR register. Print the number of the GT bit of the CR. */ | |
10020 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
10021 | output_operand_lossage ("invalid %%E value"); | |
10022 | else | |
10023 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1); | |
10024 | return; | |
10025 | ||
10026 | case 'D': | |
6b1fedc3 | 10027 | /* Like 'J' but get to the EQ bit. */ |
423c1189 AH |
10028 | if (GET_CODE (x) != REG) |
10029 | abort (); | |
10030 | ||
6b1fedc3 AH |
10031 | /* Bit 1 is EQ bit. */ |
10032 | i = 4 * (REGNO (x) - CR0_REGNO) + 2; | |
423c1189 AH |
10033 | |
10034 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
10035 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
10036 | return; | |
10037 | ||
9854d9ed | 10038 | case 'E': |
39a10a29 | 10039 | /* X is a CR register. Print the number of the EQ bit of the CR */ |
9854d9ed RK |
10040 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) |
10041 | output_operand_lossage ("invalid %%E value"); | |
78fbdbf7 | 10042 | else |
39a10a29 | 10043 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2); |
a85d226b | 10044 | return; |
9854d9ed RK |
10045 | |
10046 | case 'f': | |
10047 | /* X is a CR register. Print the shift count needed to move it | |
10048 | to the high-order four bits. */ | |
10049 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
10050 | output_operand_lossage ("invalid %%f value"); | |
10051 | else | |
9ebbca7d | 10052 | fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
10053 | return; |
10054 | ||
10055 | case 'F': | |
10056 | /* Similar, but print the count for the rotate in the opposite | |
10057 | direction. */ | |
10058 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
10059 | output_operand_lossage ("invalid %%F value"); | |
10060 | else | |
9ebbca7d | 10061 | fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO)); |
9854d9ed RK |
10062 | return; |
10063 | ||
10064 | case 'G': | |
10065 | /* X is a constant integer. If it is negative, print "m", | |
43aa4e05 | 10066 | otherwise print "z". This is to make an aze or ame insn. */ |
9854d9ed RK |
10067 | if (GET_CODE (x) != CONST_INT) |
10068 | output_operand_lossage ("invalid %%G value"); | |
10069 | else if (INTVAL (x) >= 0) | |
76229ac8 | 10070 | putc ('z', file); |
9854d9ed | 10071 | else |
76229ac8 | 10072 | putc ('m', file); |
9854d9ed | 10073 | return; |
e2c953b6 | 10074 | |
9878760c | 10075 | case 'h': |
a4f6c312 SS |
10076 | /* If constant, output low-order five bits. Otherwise, write |
10077 | normally. */ | |
9878760c | 10078 | if (INT_P (x)) |
5f59ecb7 | 10079 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31); |
9878760c RK |
10080 | else |
10081 | print_operand (file, x, 0); | |
10082 | return; | |
10083 | ||
64305719 | 10084 | case 'H': |
a4f6c312 SS |
10085 | /* If constant, output low-order six bits. Otherwise, write |
10086 | normally. */ | |
64305719 | 10087 | if (INT_P (x)) |
5f59ecb7 | 10088 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63); |
64305719 DE |
10089 | else |
10090 | print_operand (file, x, 0); | |
10091 | return; | |
10092 | ||
9854d9ed RK |
10093 | case 'I': |
10094 | /* Print `i' if this is a constant, else nothing. */ | |
9878760c | 10095 | if (INT_P (x)) |
76229ac8 | 10096 | putc ('i', file); |
9878760c RK |
10097 | return; |
10098 | ||
9854d9ed RK |
10099 | case 'j': |
10100 | /* Write the bit number in CCR for jump. */ | |
10101 | i = ccr_bit (x, 0); | |
10102 | if (i == -1) | |
10103 | output_operand_lossage ("invalid %%j code"); | |
9878760c | 10104 | else |
9854d9ed | 10105 | fprintf (file, "%d", i); |
9878760c RK |
10106 | return; |
10107 | ||
9854d9ed RK |
10108 | case 'J': |
10109 | /* Similar, but add one for shift count in rlinm for scc and pass | |
10110 | scc flag to `ccr_bit'. */ | |
10111 | i = ccr_bit (x, 1); | |
10112 | if (i == -1) | |
10113 | output_operand_lossage ("invalid %%J code"); | |
10114 | else | |
a0466a68 RK |
10115 | /* If we want bit 31, write a shift count of zero, not 32. */ |
10116 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
9878760c RK |
10117 | return; |
10118 | ||
9854d9ed RK |
10119 | case 'k': |
10120 | /* X must be a constant. Write the 1's complement of the | |
10121 | constant. */ | |
9878760c | 10122 | if (! INT_P (x)) |
9854d9ed | 10123 | output_operand_lossage ("invalid %%k value"); |
e2c953b6 DE |
10124 | else |
10125 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x)); | |
9878760c RK |
10126 | return; |
10127 | ||
81eace42 | 10128 | case 'K': |
9ebbca7d GK |
10129 | /* X must be a symbolic constant on ELF. Write an |
10130 | expression suitable for an 'addi' that adds in the low 16 | |
10131 | bits of the MEM. */ | |
10132 | if (GET_CODE (x) != CONST) | |
10133 | { | |
10134 | print_operand_address (file, x); | |
10135 | fputs ("@l", file); | |
10136 | } | |
10137 | else | |
10138 | { | |
10139 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
10140 | || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF | |
10141 | && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
10142 | || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT) | |
53cd5d6c | 10143 | output_operand_lossage ("invalid %%K value"); |
9ebbca7d GK |
10144 | print_operand_address (file, XEXP (XEXP (x, 0), 0)); |
10145 | fputs ("@l", file); | |
ed8d2920 MM |
10146 | /* For GNU as, there must be a non-alphanumeric character |
10147 | between 'l' and the number. The '-' is added by | |
10148 | print_operand() already. */ | |
10149 | if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0) | |
10150 | fputs ("+", file); | |
9ebbca7d GK |
10151 | print_operand (file, XEXP (XEXP (x, 0), 1), 0); |
10152 | } | |
81eace42 GK |
10153 | return; |
10154 | ||
10155 | /* %l is output_asm_label. */ | |
9ebbca7d | 10156 | |
9854d9ed RK |
10157 | case 'L': |
10158 | /* Write second word of DImode or DFmode reference. Works on register | |
10159 | or non-indexed memory only. */ | |
10160 | if (GET_CODE (x) == REG) | |
fb5c67a7 | 10161 | fputs (reg_names[REGNO (x) + 1], file); |
9854d9ed RK |
10162 | else if (GET_CODE (x) == MEM) |
10163 | { | |
10164 | /* Handle possible auto-increment. Since it is pre-increment and | |
1427100a | 10165 | we have already done it, we can just use an offset of word. */ |
9854d9ed RK |
10166 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
10167 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
ed8908e7 RK |
10168 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), |
10169 | UNITS_PER_WORD)); | |
9854d9ed | 10170 | else |
d7624dc0 RK |
10171 | output_address (XEXP (adjust_address_nv (x, SImode, |
10172 | UNITS_PER_WORD), | |
10173 | 0)); | |
ed8908e7 | 10174 | |
ba5e43aa | 10175 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
10176 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
10177 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 10178 | } |
9878760c | 10179 | return; |
f676971a | 10180 | |
9878760c RK |
10181 | case 'm': |
10182 | /* MB value for a mask operand. */ | |
b1765bde | 10183 | if (! mask_operand (x, SImode)) |
9878760c RK |
10184 | output_operand_lossage ("invalid %%m value"); |
10185 | ||
0ba1b2ff | 10186 | fprintf (file, "%d", extract_MB (x)); |
9878760c RK |
10187 | return; |
10188 | ||
10189 | case 'M': | |
10190 | /* ME value for a mask operand. */ | |
b1765bde | 10191 | if (! mask_operand (x, SImode)) |
a260abc9 | 10192 | output_operand_lossage ("invalid %%M value"); |
9878760c | 10193 | |
0ba1b2ff | 10194 | fprintf (file, "%d", extract_ME (x)); |
9878760c RK |
10195 | return; |
10196 | ||
81eace42 GK |
10197 | /* %n outputs the negative of its operand. */ |
10198 | ||
9878760c RK |
10199 | case 'N': |
10200 | /* Write the number of elements in the vector times 4. */ | |
10201 | if (GET_CODE (x) != PARALLEL) | |
10202 | output_operand_lossage ("invalid %%N value"); | |
e2c953b6 DE |
10203 | else |
10204 | fprintf (file, "%d", XVECLEN (x, 0) * 4); | |
9878760c RK |
10205 | return; |
10206 | ||
10207 | case 'O': | |
10208 | /* Similar, but subtract 1 first. */ | |
10209 | if (GET_CODE (x) != PARALLEL) | |
1427100a | 10210 | output_operand_lossage ("invalid %%O value"); |
e2c953b6 DE |
10211 | else |
10212 | fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4); | |
9878760c RK |
10213 | return; |
10214 | ||
9854d9ed RK |
10215 | case 'p': |
10216 | /* X is a CONST_INT that is a power of two. Output the logarithm. */ | |
10217 | if (! INT_P (x) | |
2bfcf297 | 10218 | || INT_LOWPART (x) < 0 |
9854d9ed RK |
10219 | || (i = exact_log2 (INT_LOWPART (x))) < 0) |
10220 | output_operand_lossage ("invalid %%p value"); | |
e2c953b6 DE |
10221 | else |
10222 | fprintf (file, "%d", i); | |
9854d9ed RK |
10223 | return; |
10224 | ||
9878760c RK |
10225 | case 'P': |
10226 | /* The operand must be an indirect memory reference. The result | |
8bb418a3 | 10227 | is the register name. */ |
9878760c RK |
10228 | if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG |
10229 | || REGNO (XEXP (x, 0)) >= 32) | |
10230 | output_operand_lossage ("invalid %%P value"); | |
e2c953b6 | 10231 | else |
fb5c67a7 | 10232 | fputs (reg_names[REGNO (XEXP (x, 0))], file); |
9878760c RK |
10233 | return; |
10234 | ||
dfbdccdb GK |
10235 | case 'q': |
10236 | /* This outputs the logical code corresponding to a boolean | |
10237 | expression. The expression may have one or both operands | |
39a10a29 GK |
10238 | negated (if one, only the first one). For condition register |
10239 | logical operations, it will also treat the negated | |
10240 | CR codes as NOTs, but not handle NOTs of them. */ | |
dfbdccdb | 10241 | { |
63bc1d05 | 10242 | const char *const *t = 0; |
dfbdccdb GK |
10243 | const char *s; |
10244 | enum rtx_code code = GET_CODE (x); | |
10245 | static const char * const tbl[3][3] = { | |
10246 | { "and", "andc", "nor" }, | |
10247 | { "or", "orc", "nand" }, | |
10248 | { "xor", "eqv", "xor" } }; | |
10249 | ||
10250 | if (code == AND) | |
10251 | t = tbl[0]; | |
10252 | else if (code == IOR) | |
10253 | t = tbl[1]; | |
10254 | else if (code == XOR) | |
10255 | t = tbl[2]; | |
10256 | else | |
10257 | output_operand_lossage ("invalid %%q value"); | |
10258 | ||
10259 | if (GET_CODE (XEXP (x, 0)) != NOT) | |
10260 | s = t[0]; | |
10261 | else | |
10262 | { | |
10263 | if (GET_CODE (XEXP (x, 1)) == NOT) | |
10264 | s = t[2]; | |
10265 | else | |
10266 | s = t[1]; | |
10267 | } | |
f676971a | 10268 | |
dfbdccdb GK |
10269 | fputs (s, file); |
10270 | } | |
10271 | return; | |
10272 | ||
2c4a9cff DE |
10273 | case 'Q': |
10274 | if (TARGET_MFCRF) | |
3b6ce0af | 10275 | fputc (',', file); |
5efb1046 | 10276 | /* FALLTHRU */ |
2c4a9cff DE |
10277 | else |
10278 | return; | |
10279 | ||
9854d9ed RK |
10280 | case 'R': |
10281 | /* X is a CR register. Print the mask for `mtcrf'. */ | |
10282 | if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x))) | |
10283 | output_operand_lossage ("invalid %%R value"); | |
10284 | else | |
9ebbca7d | 10285 | fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO)); |
9878760c | 10286 | return; |
9854d9ed RK |
10287 | |
10288 | case 's': | |
10289 | /* Low 5 bits of 32 - value */ | |
10290 | if (! INT_P (x)) | |
10291 | output_operand_lossage ("invalid %%s value"); | |
e2c953b6 DE |
10292 | else |
10293 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31); | |
9878760c | 10294 | return; |
9854d9ed | 10295 | |
a260abc9 | 10296 | case 'S': |
0ba1b2ff | 10297 | /* PowerPC64 mask position. All 0's is excluded. |
a260abc9 DE |
10298 | CONST_INT 32-bit mask is considered sign-extended so any |
10299 | transition must occur within the CONST_INT, not on the boundary. */ | |
b1765bde | 10300 | if (! mask64_operand (x, DImode)) |
a260abc9 DE |
10301 | output_operand_lossage ("invalid %%S value"); |
10302 | ||
0ba1b2ff | 10303 | uval = INT_LOWPART (x); |
a260abc9 | 10304 | |
0ba1b2ff | 10305 | if (uval & 1) /* Clear Left */ |
a260abc9 | 10306 | { |
f099d360 GK |
10307 | #if HOST_BITS_PER_WIDE_INT > 64 |
10308 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
10309 | #endif | |
0ba1b2ff | 10310 | i = 64; |
a260abc9 | 10311 | } |
0ba1b2ff | 10312 | else /* Clear Right */ |
a260abc9 | 10313 | { |
0ba1b2ff | 10314 | uval = ~uval; |
f099d360 GK |
10315 | #if HOST_BITS_PER_WIDE_INT > 64 |
10316 | uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1; | |
10317 | #endif | |
0ba1b2ff | 10318 | i = 63; |
a260abc9 | 10319 | } |
0ba1b2ff AM |
10320 | while (uval != 0) |
10321 | --i, uval >>= 1; | |
10322 | if (i < 0) | |
10323 | abort (); | |
10324 | fprintf (file, "%d", i); | |
10325 | return; | |
a260abc9 | 10326 | |
a3170dc6 AH |
10327 | case 't': |
10328 | /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */ | |
10329 | if (GET_CODE (x) != REG || GET_MODE (x) != CCmode) | |
10330 | abort (); | |
10331 | ||
10332 | /* Bit 3 is OV bit. */ | |
10333 | i = 4 * (REGNO (x) - CR0_REGNO) + 3; | |
10334 | ||
10335 | /* If we want bit 31, write a shift count of zero, not 32. */ | |
10336 | fprintf (file, "%d", i == 31 ? 0 : i + 1); | |
10337 | return; | |
10338 | ||
cccf3bdc DE |
10339 | case 'T': |
10340 | /* Print the symbolic name of a branch target register. */ | |
10341 | if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM | |
10342 | && REGNO (x) != COUNT_REGISTER_REGNUM)) | |
10343 | output_operand_lossage ("invalid %%T value"); | |
e2c953b6 | 10344 | else if (REGNO (x) == LINK_REGISTER_REGNUM) |
cccf3bdc DE |
10345 | fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file); |
10346 | else | |
10347 | fputs ("ctr", file); | |
10348 | return; | |
10349 | ||
9854d9ed | 10350 | case 'u': |
802a0058 | 10351 | /* High-order 16 bits of constant for use in unsigned operand. */ |
9854d9ed RK |
10352 | if (! INT_P (x)) |
10353 | output_operand_lossage ("invalid %%u value"); | |
e2c953b6 | 10354 | else |
f676971a | 10355 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
e2c953b6 | 10356 | (INT_LOWPART (x) >> 16) & 0xffff); |
9878760c RK |
10357 | return; |
10358 | ||
802a0058 MM |
10359 | case 'v': |
10360 | /* High-order 16 bits of constant for use in signed operand. */ | |
10361 | if (! INT_P (x)) | |
10362 | output_operand_lossage ("invalid %%v value"); | |
e2c953b6 | 10363 | else |
134c32f6 DE |
10364 | fprintf (file, HOST_WIDE_INT_PRINT_HEX, |
10365 | (INT_LOWPART (x) >> 16) & 0xffff); | |
10366 | return; | |
802a0058 | 10367 | |
9854d9ed RK |
10368 | case 'U': |
10369 | /* Print `u' if this has an auto-increment or auto-decrement. */ | |
10370 | if (GET_CODE (x) == MEM | |
10371 | && (GET_CODE (XEXP (x, 0)) == PRE_INC | |
10372 | || GET_CODE (XEXP (x, 0)) == PRE_DEC)) | |
76229ac8 | 10373 | putc ('u', file); |
9854d9ed | 10374 | return; |
9878760c | 10375 | |
e0cd0770 JC |
10376 | case 'V': |
10377 | /* Print the trap code for this operand. */ | |
10378 | switch (GET_CODE (x)) | |
10379 | { | |
10380 | case EQ: | |
10381 | fputs ("eq", file); /* 4 */ | |
10382 | break; | |
10383 | case NE: | |
10384 | fputs ("ne", file); /* 24 */ | |
10385 | break; | |
10386 | case LT: | |
10387 | fputs ("lt", file); /* 16 */ | |
10388 | break; | |
10389 | case LE: | |
10390 | fputs ("le", file); /* 20 */ | |
10391 | break; | |
10392 | case GT: | |
10393 | fputs ("gt", file); /* 8 */ | |
10394 | break; | |
10395 | case GE: | |
10396 | fputs ("ge", file); /* 12 */ | |
10397 | break; | |
10398 | case LTU: | |
10399 | fputs ("llt", file); /* 2 */ | |
10400 | break; | |
10401 | case LEU: | |
10402 | fputs ("lle", file); /* 6 */ | |
10403 | break; | |
10404 | case GTU: | |
10405 | fputs ("lgt", file); /* 1 */ | |
10406 | break; | |
10407 | case GEU: | |
10408 | fputs ("lge", file); /* 5 */ | |
10409 | break; | |
10410 | default: | |
10411 | abort (); | |
10412 | } | |
10413 | break; | |
10414 | ||
9854d9ed RK |
10415 | case 'w': |
10416 | /* If constant, low-order 16 bits of constant, signed. Otherwise, write | |
10417 | normally. */ | |
10418 | if (INT_P (x)) | |
f676971a | 10419 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, |
5f59ecb7 | 10420 | ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000); |
9854d9ed RK |
10421 | else |
10422 | print_operand (file, x, 0); | |
9878760c RK |
10423 | return; |
10424 | ||
9854d9ed | 10425 | case 'W': |
e2c953b6 | 10426 | /* MB value for a PowerPC64 rldic operand. */ |
e2c953b6 DE |
10427 | val = (GET_CODE (x) == CONST_INT |
10428 | ? INTVAL (x) : CONST_DOUBLE_HIGH (x)); | |
10429 | ||
10430 | if (val < 0) | |
10431 | i = -1; | |
9854d9ed | 10432 | else |
e2c953b6 DE |
10433 | for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++) |
10434 | if ((val <<= 1) < 0) | |
10435 | break; | |
10436 | ||
10437 | #if HOST_BITS_PER_WIDE_INT == 32 | |
10438 | if (GET_CODE (x) == CONST_INT && i >= 0) | |
10439 | i += 32; /* zero-extend high-part was all 0's */ | |
10440 | else if (GET_CODE (x) == CONST_DOUBLE && i == 32) | |
10441 | { | |
10442 | val = CONST_DOUBLE_LOW (x); | |
10443 | ||
10444 | if (val == 0) | |
a4f6c312 | 10445 | abort (); |
e2c953b6 DE |
10446 | else if (val < 0) |
10447 | --i; | |
10448 | else | |
10449 | for ( ; i < 64; i++) | |
10450 | if ((val <<= 1) < 0) | |
10451 | break; | |
10452 | } | |
10453 | #endif | |
10454 | ||
10455 | fprintf (file, "%d", i + 1); | |
9854d9ed | 10456 | return; |
9878760c | 10457 | |
9854d9ed RK |
10458 | case 'X': |
10459 | if (GET_CODE (x) == MEM | |
4d588c14 | 10460 | && legitimate_indexed_address_p (XEXP (x, 0), 0)) |
76229ac8 | 10461 | putc ('x', file); |
9854d9ed | 10462 | return; |
9878760c | 10463 | |
9854d9ed RK |
10464 | case 'Y': |
10465 | /* Like 'L', for third word of TImode */ | |
10466 | if (GET_CODE (x) == REG) | |
fb5c67a7 | 10467 | fputs (reg_names[REGNO (x) + 2], file); |
9854d9ed | 10468 | else if (GET_CODE (x) == MEM) |
9878760c | 10469 | { |
9854d9ed RK |
10470 | if (GET_CODE (XEXP (x, 0)) == PRE_INC |
10471 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 10472 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8)); |
9854d9ed | 10473 | else |
d7624dc0 | 10474 | output_address (XEXP (adjust_address_nv (x, SImode, 8), 0)); |
ba5e43aa | 10475 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
10476 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
10477 | reg_names[SMALL_DATA_REG]); | |
9878760c RK |
10478 | } |
10479 | return; | |
f676971a | 10480 | |
9878760c | 10481 | case 'z': |
b4ac57ab RS |
10482 | /* X is a SYMBOL_REF. Write out the name preceded by a |
10483 | period and without any trailing data in brackets. Used for function | |
4d30c363 MM |
10484 | names. If we are configured for System V (or the embedded ABI) on |
10485 | the PowerPC, do not emit the period, since those systems do not use | |
10486 | TOCs and the like. */ | |
9878760c RK |
10487 | if (GET_CODE (x) != SYMBOL_REF) |
10488 | abort (); | |
10489 | ||
9bf6462a AP |
10490 | /* Mark the decl as referenced so that cgraph will output the function. */ |
10491 | if (SYMBOL_REF_DECL (x)) | |
10492 | mark_decl_referenced (SYMBOL_REF_DECL (x)); | |
10493 | ||
85b776df | 10494 | /* For macho, check to see if we need a stub. */ |
f9da97f0 AP |
10495 | if (TARGET_MACHO) |
10496 | { | |
10497 | const char *name = XSTR (x, 0); | |
a031e781 | 10498 | #if TARGET_MACHO |
3b48085e | 10499 | if (MACHOPIC_INDIRECT |
11abc112 MM |
10500 | && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION) |
10501 | name = machopic_indirection_name (x, /*stub_p=*/true); | |
f9da97f0 AP |
10502 | #endif |
10503 | assemble_name (file, name); | |
10504 | } | |
85b776df | 10505 | else if (!DOT_SYMBOLS) |
9739c90c | 10506 | assemble_name (file, XSTR (x, 0)); |
85b776df AM |
10507 | else |
10508 | rs6000_output_function_entry (file, XSTR (x, 0)); | |
9878760c RK |
10509 | return; |
10510 | ||
9854d9ed RK |
10511 | case 'Z': |
10512 | /* Like 'L', for last word of TImode. */ | |
10513 | if (GET_CODE (x) == REG) | |
fb5c67a7 | 10514 | fputs (reg_names[REGNO (x) + 3], file); |
9854d9ed RK |
10515 | else if (GET_CODE (x) == MEM) |
10516 | { | |
10517 | if (GET_CODE (XEXP (x, 0)) == PRE_INC | |
10518 | || GET_CODE (XEXP (x, 0)) == PRE_DEC) | |
a54d04b7 | 10519 | output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12)); |
9854d9ed | 10520 | else |
d7624dc0 | 10521 | output_address (XEXP (adjust_address_nv (x, SImode, 12), 0)); |
ba5e43aa | 10522 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
10523 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
10524 | reg_names[SMALL_DATA_REG]); | |
9854d9ed | 10525 | } |
5c23c401 | 10526 | return; |
0ac081f6 | 10527 | |
a3170dc6 | 10528 | /* Print AltiVec or SPE memory operand. */ |
0ac081f6 AH |
10529 | case 'y': |
10530 | { | |
10531 | rtx tmp; | |
10532 | ||
10533 | if (GET_CODE (x) != MEM) | |
10534 | abort (); | |
10535 | ||
10536 | tmp = XEXP (x, 0); | |
10537 | ||
993f19a8 | 10538 | if (TARGET_E500) |
a3170dc6 AH |
10539 | { |
10540 | /* Handle [reg]. */ | |
10541 | if (GET_CODE (tmp) == REG) | |
10542 | { | |
10543 | fprintf (file, "0(%s)", reg_names[REGNO (tmp)]); | |
10544 | break; | |
10545 | } | |
10546 | /* Handle [reg+UIMM]. */ | |
10547 | else if (GET_CODE (tmp) == PLUS && | |
10548 | GET_CODE (XEXP (tmp, 1)) == CONST_INT) | |
10549 | { | |
10550 | int x; | |
10551 | ||
10552 | if (GET_CODE (XEXP (tmp, 0)) != REG) | |
10553 | abort (); | |
10554 | ||
10555 | x = INTVAL (XEXP (tmp, 1)); | |
10556 | fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]); | |
10557 | break; | |
10558 | } | |
10559 | ||
10560 | /* Fall through. Must be [reg+reg]. */ | |
10561 | } | |
0ac081f6 | 10562 | if (GET_CODE (tmp) == REG) |
c62f2db5 | 10563 | fprintf (file, "0,%s", reg_names[REGNO (tmp)]); |
0ac081f6 AH |
10564 | else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG) |
10565 | { | |
10566 | if (REGNO (XEXP (tmp, 0)) == 0) | |
10567 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ], | |
10568 | reg_names[ REGNO (XEXP (tmp, 0)) ]); | |
10569 | else | |
10570 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ], | |
10571 | reg_names[ REGNO (XEXP (tmp, 1)) ]); | |
10572 | } | |
10573 | else | |
10574 | abort (); | |
10575 | break; | |
10576 | } | |
f676971a | 10577 | |
9878760c RK |
10578 | case 0: |
10579 | if (GET_CODE (x) == REG) | |
10580 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
10581 | else if (GET_CODE (x) == MEM) | |
10582 | { | |
10583 | /* We need to handle PRE_INC and PRE_DEC here, since we need to | |
10584 | know the width from the mode. */ | |
10585 | if (GET_CODE (XEXP (x, 0)) == PRE_INC) | |
79ba6d34 MM |
10586 | fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)), |
10587 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 10588 | else if (GET_CODE (XEXP (x, 0)) == PRE_DEC) |
79ba6d34 MM |
10589 | fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)), |
10590 | reg_names[REGNO (XEXP (XEXP (x, 0), 0))]); | |
9878760c | 10591 | else |
a54d04b7 | 10592 | output_address (XEXP (x, 0)); |
9878760c RK |
10593 | } |
10594 | else | |
a54d04b7 | 10595 | output_addr_const (file, x); |
a85d226b | 10596 | return; |
9878760c | 10597 | |
c4501e62 JJ |
10598 | case '&': |
10599 | assemble_name (file, rs6000_get_some_local_dynamic_name ()); | |
10600 | return; | |
10601 | ||
9878760c RK |
10602 | default: |
10603 | output_operand_lossage ("invalid %%xn code"); | |
10604 | } | |
10605 | } | |
10606 | \f | |
10607 | /* Print the address of an operand. */ | |
10608 | ||
10609 | void | |
a2369ed3 | 10610 | print_operand_address (FILE *file, rtx x) |
9878760c RK |
10611 | { |
10612 | if (GET_CODE (x) == REG) | |
4697a36c | 10613 | fprintf (file, "0(%s)", reg_names[ REGNO (x) ]); |
9ebbca7d GK |
10614 | else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST |
10615 | || GET_CODE (x) == LABEL_REF) | |
9878760c RK |
10616 | { |
10617 | output_addr_const (file, x); | |
ba5e43aa | 10618 | if (small_data_operand (x, GET_MODE (x))) |
8fbd2dc7 MM |
10619 | fprintf (file, "@%s(%s)", SMALL_DATA_RELOC, |
10620 | reg_names[SMALL_DATA_REG]); | |
9ebbca7d | 10621 | else if (TARGET_TOC) |
a4f6c312 | 10622 | abort (); |
9878760c RK |
10623 | } |
10624 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG) | |
10625 | { | |
10626 | if (REGNO (XEXP (x, 0)) == 0) | |
4697a36c MM |
10627 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ], |
10628 | reg_names[ REGNO (XEXP (x, 0)) ]); | |
9878760c | 10629 | else |
4697a36c MM |
10630 | fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ], |
10631 | reg_names[ REGNO (XEXP (x, 1)) ]); | |
9878760c RK |
10632 | } |
10633 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT) | |
4a0a75dd KG |
10634 | fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)", |
10635 | INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]); | |
3cb999d8 DE |
10636 | #if TARGET_ELF |
10637 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
10638 | && CONSTANT_P (XEXP (x, 1))) | |
4697a36c MM |
10639 | { |
10640 | output_addr_const (file, XEXP (x, 1)); | |
10641 | fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
10642 | } | |
c859cda6 DJ |
10643 | #endif |
10644 | #if TARGET_MACHO | |
10645 | else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG | |
10646 | && CONSTANT_P (XEXP (x, 1))) | |
10647 | { | |
10648 | fprintf (file, "lo16("); | |
10649 | output_addr_const (file, XEXP (x, 1)); | |
10650 | fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]); | |
10651 | } | |
3cb999d8 | 10652 | #endif |
4d588c14 | 10653 | else if (legitimate_constant_pool_address_p (x)) |
9ebbca7d | 10654 | { |
2bfcf297 | 10655 | if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC)) |
9ebbca7d | 10656 | { |
2bfcf297 DB |
10657 | rtx contains_minus = XEXP (x, 1); |
10658 | rtx minus, symref; | |
10659 | const char *name; | |
f676971a | 10660 | |
9ebbca7d | 10661 | /* Find the (minus (sym) (toc)) buried in X, and temporarily |
a4f6c312 | 10662 | turn it into (sym) for output_addr_const. */ |
9ebbca7d GK |
10663 | while (GET_CODE (XEXP (contains_minus, 0)) != MINUS) |
10664 | contains_minus = XEXP (contains_minus, 0); | |
10665 | ||
2bfcf297 DB |
10666 | minus = XEXP (contains_minus, 0); |
10667 | symref = XEXP (minus, 0); | |
10668 | XEXP (contains_minus, 0) = symref; | |
10669 | if (TARGET_ELF) | |
10670 | { | |
10671 | char *newname; | |
10672 | ||
10673 | name = XSTR (symref, 0); | |
10674 | newname = alloca (strlen (name) + sizeof ("@toc")); | |
10675 | strcpy (newname, name); | |
10676 | strcat (newname, "@toc"); | |
10677 | XSTR (symref, 0) = newname; | |
10678 | } | |
10679 | output_addr_const (file, XEXP (x, 1)); | |
10680 | if (TARGET_ELF) | |
10681 | XSTR (symref, 0) = name; | |
9ebbca7d GK |
10682 | XEXP (contains_minus, 0) = minus; |
10683 | } | |
10684 | else | |
10685 | output_addr_const (file, XEXP (x, 1)); | |
10686 | ||
10687 | fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]); | |
10688 | } | |
9878760c RK |
10689 | else |
10690 | abort (); | |
10691 | } | |
10692 | \f | |
88cad84b | 10693 | /* Target hook for assembling integer objects. The PowerPC version has |
301d03af RS |
10694 | to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP |
10695 | is defined. It also needs to handle DI-mode objects on 64-bit | |
10696 | targets. */ | |
10697 | ||
10698 | static bool | |
a2369ed3 | 10699 | rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p) |
301d03af RS |
10700 | { |
10701 | #ifdef RELOCATABLE_NEEDS_FIXUP | |
10702 | /* Special handling for SI values. */ | |
10703 | if (size == 4 && aligned_p) | |
10704 | { | |
a2369ed3 | 10705 | extern int in_toc_section (void); |
301d03af | 10706 | static int recurse = 0; |
f676971a | 10707 | |
301d03af RS |
10708 | /* For -mrelocatable, we mark all addresses that need to be fixed up |
10709 | in the .fixup section. */ | |
10710 | if (TARGET_RELOCATABLE | |
10711 | && !in_toc_section () | |
10712 | && !in_text_section () | |
642af3be | 10713 | && !in_unlikely_text_section () |
301d03af RS |
10714 | && !recurse |
10715 | && GET_CODE (x) != CONST_INT | |
10716 | && GET_CODE (x) != CONST_DOUBLE | |
10717 | && CONSTANT_P (x)) | |
10718 | { | |
10719 | char buf[256]; | |
10720 | ||
10721 | recurse = 1; | |
10722 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno); | |
10723 | fixuplabelno++; | |
10724 | ASM_OUTPUT_LABEL (asm_out_file, buf); | |
10725 | fprintf (asm_out_file, "\t.long\t("); | |
10726 | output_addr_const (asm_out_file, x); | |
10727 | fprintf (asm_out_file, ")@fixup\n"); | |
10728 | fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n"); | |
10729 | ASM_OUTPUT_ALIGN (asm_out_file, 2); | |
10730 | fprintf (asm_out_file, "\t.long\t"); | |
10731 | assemble_name (asm_out_file, buf); | |
10732 | fprintf (asm_out_file, "\n\t.previous\n"); | |
10733 | recurse = 0; | |
10734 | return true; | |
10735 | } | |
10736 | /* Remove initial .'s to turn a -mcall-aixdesc function | |
10737 | address into the address of the descriptor, not the function | |
10738 | itself. */ | |
10739 | else if (GET_CODE (x) == SYMBOL_REF | |
10740 | && XSTR (x, 0)[0] == '.' | |
10741 | && DEFAULT_ABI == ABI_AIX) | |
10742 | { | |
10743 | const char *name = XSTR (x, 0); | |
10744 | while (*name == '.') | |
10745 | name++; | |
10746 | ||
10747 | fprintf (asm_out_file, "\t.long\t%s\n", name); | |
10748 | return true; | |
10749 | } | |
10750 | } | |
10751 | #endif /* RELOCATABLE_NEEDS_FIXUP */ | |
10752 | return default_assemble_integer (x, size, aligned_p); | |
10753 | } | |
93638d7a AM |
10754 | |
10755 | #ifdef HAVE_GAS_HIDDEN | |
10756 | /* Emit an assembler directive to set symbol visibility for DECL to | |
10757 | VISIBILITY_TYPE. */ | |
10758 | ||
5add3202 | 10759 | static void |
a2369ed3 | 10760 | rs6000_assemble_visibility (tree decl, int vis) |
93638d7a | 10761 | { |
93638d7a AM |
10762 | /* Functions need to have their entry point symbol visibility set as |
10763 | well as their descriptor symbol visibility. */ | |
85b776df AM |
10764 | if (DEFAULT_ABI == ABI_AIX |
10765 | && DOT_SYMBOLS | |
10766 | && TREE_CODE (decl) == FUNCTION_DECL) | |
93638d7a | 10767 | { |
25fdb4dc RH |
10768 | static const char * const visibility_types[] = { |
10769 | NULL, "internal", "hidden", "protected" | |
10770 | }; | |
10771 | ||
10772 | const char *name, *type; | |
93638d7a AM |
10773 | |
10774 | name = ((* targetm.strip_name_encoding) | |
10775 | (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)))); | |
25fdb4dc | 10776 | type = visibility_types[vis]; |
93638d7a | 10777 | |
25fdb4dc RH |
10778 | fprintf (asm_out_file, "\t.%s\t%s\n", type, name); |
10779 | fprintf (asm_out_file, "\t.%s\t.%s\n", type, name); | |
93638d7a | 10780 | } |
25fdb4dc RH |
10781 | else |
10782 | default_assemble_visibility (decl, vis); | |
93638d7a AM |
10783 | } |
10784 | #endif | |
301d03af | 10785 | \f |
39a10a29 | 10786 | enum rtx_code |
a2369ed3 | 10787 | rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code) |
39a10a29 GK |
10788 | { |
10789 | /* Reversal of FP compares takes care -- an ordered compare | |
10790 | becomes an unordered compare and vice versa. */ | |
f676971a | 10791 | if (mode == CCFPmode |
bc9ec0e0 GK |
10792 | && (!flag_finite_math_only |
10793 | || code == UNLT || code == UNLE || code == UNGT || code == UNGE | |
10794 | || code == UNEQ || code == LTGT)) | |
bab6226b | 10795 | return reverse_condition_maybe_unordered (code); |
39a10a29 | 10796 | else |
bab6226b | 10797 | return reverse_condition (code); |
39a10a29 GK |
10798 | } |
10799 | ||
39a10a29 GK |
10800 | /* Generate a compare for CODE. Return a brand-new rtx that |
10801 | represents the result of the compare. */ | |
a4f6c312 | 10802 | |
39a10a29 | 10803 | static rtx |
a2369ed3 | 10804 | rs6000_generate_compare (enum rtx_code code) |
39a10a29 GK |
10805 | { |
10806 | enum machine_mode comp_mode; | |
10807 | rtx compare_result; | |
10808 | ||
10809 | if (rs6000_compare_fp_p) | |
10810 | comp_mode = CCFPmode; | |
10811 | else if (code == GTU || code == LTU | |
10812 | || code == GEU || code == LEU) | |
10813 | comp_mode = CCUNSmode; | |
10814 | else | |
10815 | comp_mode = CCmode; | |
10816 | ||
10817 | /* First, the compare. */ | |
10818 | compare_result = gen_reg_rtx (comp_mode); | |
a3170dc6 AH |
10819 | |
10820 | /* SPE FP compare instructions on the GPRs. Yuck! */ | |
993f19a8 AH |
10821 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) |
10822 | && rs6000_compare_fp_p) | |
a3170dc6 AH |
10823 | { |
10824 | rtx cmp, or1, or2, or_result, compare_result2; | |
10825 | ||
423c1189 AH |
10826 | /* Note: The E500 comparison instructions set the GT bit (x + |
10827 | 1), on success. This explains the mess. */ | |
10828 | ||
a3170dc6 AH |
10829 | switch (code) |
10830 | { | |
423c1189 | 10831 | case EQ: case UNEQ: case NE: case LTGT: |
bc9ec0e0 | 10832 | cmp = flag_finite_math_only |
a3170dc6 AH |
10833 | ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0, |
10834 | rs6000_compare_op1) | |
10835 | : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0, | |
10836 | rs6000_compare_op1); | |
10837 | break; | |
423c1189 | 10838 | case GT: case GTU: case UNGT: case UNGE: case GE: case GEU: |
bc9ec0e0 | 10839 | cmp = flag_finite_math_only |
a3170dc6 AH |
10840 | ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0, |
10841 | rs6000_compare_op1) | |
10842 | : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0, | |
10843 | rs6000_compare_op1); | |
10844 | break; | |
423c1189 | 10845 | case LT: case LTU: case UNLT: case UNLE: case LE: case LEU: |
bc9ec0e0 | 10846 | cmp = flag_finite_math_only |
a3170dc6 AH |
10847 | ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0, |
10848 | rs6000_compare_op1) | |
10849 | : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0, | |
10850 | rs6000_compare_op1); | |
10851 | break; | |
10852 | default: | |
10853 | abort (); | |
10854 | } | |
10855 | ||
10856 | /* Synthesize LE and GE from LT/GT || EQ. */ | |
10857 | if (code == LE || code == GE || code == LEU || code == GEU) | |
10858 | { | |
a3170dc6 AH |
10859 | emit_insn (cmp); |
10860 | ||
10861 | switch (code) | |
10862 | { | |
10863 | case LE: code = LT; break; | |
10864 | case GE: code = GT; break; | |
10865 | case LEU: code = LT; break; | |
10866 | case GEU: code = GT; break; | |
10867 | default: abort (); | |
10868 | } | |
10869 | ||
10870 | or1 = gen_reg_rtx (SImode); | |
10871 | or2 = gen_reg_rtx (SImode); | |
10872 | or_result = gen_reg_rtx (CCEQmode); | |
10873 | compare_result2 = gen_reg_rtx (CCFPmode); | |
10874 | ||
10875 | /* Do the EQ. */ | |
bc9ec0e0 | 10876 | cmp = flag_finite_math_only |
a3170dc6 AH |
10877 | ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0, |
10878 | rs6000_compare_op1) | |
10879 | : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0, | |
10880 | rs6000_compare_op1); | |
10881 | emit_insn (cmp); | |
10882 | ||
423c1189 AH |
10883 | or1 = gen_rtx_GT (SImode, compare_result, const0_rtx); |
10884 | or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx); | |
a3170dc6 AH |
10885 | |
10886 | /* OR them together. */ | |
10887 | cmp = gen_rtx_SET (VOIDmode, or_result, | |
10888 | gen_rtx_COMPARE (CCEQmode, | |
10889 | gen_rtx_IOR (SImode, or1, or2), | |
10890 | const_true_rtx)); | |
10891 | compare_result = or_result; | |
10892 | code = EQ; | |
10893 | } | |
10894 | else | |
10895 | { | |
a3170dc6 | 10896 | if (code == NE || code == LTGT) |
a3170dc6 | 10897 | code = NE; |
423c1189 AH |
10898 | else |
10899 | code = EQ; | |
a3170dc6 AH |
10900 | } |
10901 | ||
10902 | emit_insn (cmp); | |
10903 | } | |
10904 | else | |
10905 | emit_insn (gen_rtx_SET (VOIDmode, compare_result, | |
10906 | gen_rtx_COMPARE (comp_mode, | |
f676971a | 10907 | rs6000_compare_op0, |
a3170dc6 | 10908 | rs6000_compare_op1))); |
f676971a | 10909 | |
ca5adc63 | 10910 | /* Some kinds of FP comparisons need an OR operation; |
bc9ec0e0 | 10911 | under flag_finite_math_only we don't bother. */ |
39a10a29 | 10912 | if (rs6000_compare_fp_p |
bc9ec0e0 | 10913 | && ! flag_finite_math_only |
993f19a8 | 10914 | && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS) |
39a10a29 GK |
10915 | && (code == LE || code == GE |
10916 | || code == UNEQ || code == LTGT | |
10917 | || code == UNGT || code == UNLT)) | |
10918 | { | |
10919 | enum rtx_code or1, or2; | |
10920 | rtx or1_rtx, or2_rtx, compare2_rtx; | |
10921 | rtx or_result = gen_reg_rtx (CCEQmode); | |
f676971a | 10922 | |
39a10a29 GK |
10923 | switch (code) |
10924 | { | |
10925 | case LE: or1 = LT; or2 = EQ; break; | |
10926 | case GE: or1 = GT; or2 = EQ; break; | |
10927 | case UNEQ: or1 = UNORDERED; or2 = EQ; break; | |
10928 | case LTGT: or1 = LT; or2 = GT; break; | |
10929 | case UNGT: or1 = UNORDERED; or2 = GT; break; | |
10930 | case UNLT: or1 = UNORDERED; or2 = LT; break; | |
10931 | default: abort (); | |
10932 | } | |
10933 | validate_condition_mode (or1, comp_mode); | |
10934 | validate_condition_mode (or2, comp_mode); | |
1c563bed KH |
10935 | or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx); |
10936 | or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx); | |
39a10a29 GK |
10937 | compare2_rtx = gen_rtx_COMPARE (CCEQmode, |
10938 | gen_rtx_IOR (SImode, or1_rtx, or2_rtx), | |
10939 | const_true_rtx); | |
10940 | emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx)); | |
10941 | ||
10942 | compare_result = or_result; | |
10943 | code = EQ; | |
10944 | } | |
10945 | ||
10946 | validate_condition_mode (code, GET_MODE (compare_result)); | |
f676971a | 10947 | |
1c563bed | 10948 | return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx); |
39a10a29 GK |
10949 | } |
10950 | ||
10951 | ||
10952 | /* Emit the RTL for an sCOND pattern. */ | |
10953 | ||
10954 | void | |
a2369ed3 | 10955 | rs6000_emit_sCOND (enum rtx_code code, rtx result) |
39a10a29 GK |
10956 | { |
10957 | rtx condition_rtx; | |
10958 | enum machine_mode op_mode; | |
b7053a3f | 10959 | enum rtx_code cond_code; |
39a10a29 GK |
10960 | |
10961 | condition_rtx = rs6000_generate_compare (code); | |
b7053a3f GK |
10962 | cond_code = GET_CODE (condition_rtx); |
10963 | ||
423c1189 AH |
10964 | if (TARGET_E500 && rs6000_compare_fp_p |
10965 | && !TARGET_FPRS && TARGET_HARD_FLOAT) | |
10966 | { | |
10967 | rtx t; | |
10968 | ||
10969 | PUT_MODE (condition_rtx, SImode); | |
10970 | t = XEXP (condition_rtx, 0); | |
10971 | ||
10972 | if (cond_code != NE && cond_code != EQ) | |
10973 | abort (); | |
10974 | ||
10975 | if (cond_code == NE) | |
6b1fedc3 | 10976 | emit_insn (gen_e500_flip_eq_bit (t, t)); |
423c1189 | 10977 | |
6b1fedc3 | 10978 | emit_insn (gen_move_from_CR_eq_bit (result, t)); |
423c1189 AH |
10979 | return; |
10980 | } | |
10981 | ||
b7053a3f GK |
10982 | if (cond_code == NE |
10983 | || cond_code == GE || cond_code == LE | |
10984 | || cond_code == GEU || cond_code == LEU | |
10985 | || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE) | |
10986 | { | |
10987 | rtx not_result = gen_reg_rtx (CCEQmode); | |
10988 | rtx not_op, rev_cond_rtx; | |
10989 | enum machine_mode cc_mode; | |
f676971a | 10990 | |
b7053a3f GK |
10991 | cc_mode = GET_MODE (XEXP (condition_rtx, 0)); |
10992 | ||
1c563bed | 10993 | rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code), |
0f4c242b | 10994 | SImode, XEXP (condition_rtx, 0), const0_rtx); |
b7053a3f GK |
10995 | not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx); |
10996 | emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op)); | |
10997 | condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx); | |
10998 | } | |
39a10a29 GK |
10999 | |
11000 | op_mode = GET_MODE (rs6000_compare_op0); | |
11001 | if (op_mode == VOIDmode) | |
11002 | op_mode = GET_MODE (rs6000_compare_op1); | |
11003 | ||
11004 | if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p)) | |
11005 | { | |
11006 | PUT_MODE (condition_rtx, DImode); | |
11007 | convert_move (result, condition_rtx, 0); | |
11008 | } | |
11009 | else | |
11010 | { | |
11011 | PUT_MODE (condition_rtx, SImode); | |
11012 | emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx)); | |
11013 | } | |
11014 | } | |
11015 | ||
39a10a29 GK |
11016 | /* Emit a branch of kind CODE to location LOC. */ |
11017 | ||
11018 | void | |
a2369ed3 | 11019 | rs6000_emit_cbranch (enum rtx_code code, rtx loc) |
39a10a29 GK |
11020 | { |
11021 | rtx condition_rtx, loc_ref; | |
11022 | ||
11023 | condition_rtx = rs6000_generate_compare (code); | |
11024 | loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc); | |
11025 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, | |
11026 | gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx, | |
11027 | loc_ref, pc_rtx))); | |
11028 | } | |
11029 | ||
12a4e8c5 GK |
11030 | /* Return the string to output a conditional branch to LABEL, which is |
11031 | the operand number of the label, or -1 if the branch is really a | |
f676971a | 11032 | conditional return. |
12a4e8c5 GK |
11033 | |
11034 | OP is the conditional expression. XEXP (OP, 0) is assumed to be a | |
11035 | condition code register and its mode specifies what kind of | |
11036 | comparison we made. | |
11037 | ||
a0ab749a | 11038 | REVERSED is nonzero if we should reverse the sense of the comparison. |
12a4e8c5 GK |
11039 | |
11040 | INSN is the insn. */ | |
11041 | ||
11042 | char * | |
a2369ed3 | 11043 | output_cbranch (rtx op, const char *label, int reversed, rtx insn) |
12a4e8c5 GK |
11044 | { |
11045 | static char string[64]; | |
11046 | enum rtx_code code = GET_CODE (op); | |
11047 | rtx cc_reg = XEXP (op, 0); | |
11048 | enum machine_mode mode = GET_MODE (cc_reg); | |
11049 | int cc_regno = REGNO (cc_reg) - CR0_REGNO; | |
39a10a29 | 11050 | int need_longbranch = label != NULL && get_attr_length (insn) == 8; |
12a4e8c5 GK |
11051 | int really_reversed = reversed ^ need_longbranch; |
11052 | char *s = string; | |
11053 | const char *ccode; | |
11054 | const char *pred; | |
11055 | rtx note; | |
11056 | ||
39a10a29 GK |
11057 | validate_condition_mode (code, mode); |
11058 | ||
11059 | /* Work out which way this really branches. We could use | |
11060 | reverse_condition_maybe_unordered here always but this | |
11061 | makes the resulting assembler clearer. */ | |
12a4e8c5 | 11062 | if (really_reversed) |
de40e1df DJ |
11063 | { |
11064 | /* Reversal of FP compares takes care -- an ordered compare | |
11065 | becomes an unordered compare and vice versa. */ | |
11066 | if (mode == CCFPmode) | |
11067 | code = reverse_condition_maybe_unordered (code); | |
11068 | else | |
11069 | code = reverse_condition (code); | |
11070 | } | |
12a4e8c5 | 11071 | |
993f19a8 | 11072 | if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode) |
a3170dc6 AH |
11073 | { |
11074 | /* The efscmp/tst* instructions twiddle bit 2, which maps nicely | |
11075 | to the GT bit. */ | |
11076 | if (code == EQ) | |
11077 | /* Opposite of GT. */ | |
a3170dc6 | 11078 | code = GT; |
423c1189 AH |
11079 | else if (code == NE) |
11080 | code = UNLE; | |
a3170dc6 AH |
11081 | else |
11082 | abort (); | |
11083 | } | |
11084 | ||
39a10a29 | 11085 | switch (code) |
12a4e8c5 GK |
11086 | { |
11087 | /* Not all of these are actually distinct opcodes, but | |
11088 | we distinguish them for clarity of the resulting assembler. */ | |
50a0b056 GK |
11089 | case NE: case LTGT: |
11090 | ccode = "ne"; break; | |
11091 | case EQ: case UNEQ: | |
11092 | ccode = "eq"; break; | |
f676971a | 11093 | case GE: case GEU: |
50a0b056 | 11094 | ccode = "ge"; break; |
f676971a | 11095 | case GT: case GTU: case UNGT: |
50a0b056 | 11096 | ccode = "gt"; break; |
f676971a | 11097 | case LE: case LEU: |
50a0b056 | 11098 | ccode = "le"; break; |
f676971a | 11099 | case LT: case LTU: case UNLT: |
50a0b056 | 11100 | ccode = "lt"; break; |
12a4e8c5 GK |
11101 | case UNORDERED: ccode = "un"; break; |
11102 | case ORDERED: ccode = "nu"; break; | |
11103 | case UNGE: ccode = "nl"; break; | |
11104 | case UNLE: ccode = "ng"; break; | |
11105 | default: | |
a4f6c312 | 11106 | abort (); |
12a4e8c5 | 11107 | } |
f676971a EC |
11108 | |
11109 | /* Maybe we have a guess as to how likely the branch is. | |
94a54f47 | 11110 | The old mnemonics don't have a way to specify this information. */ |
f4857b9b | 11111 | pred = ""; |
12a4e8c5 GK |
11112 | note = find_reg_note (insn, REG_BR_PROB, NULL_RTX); |
11113 | if (note != NULL_RTX) | |
11114 | { | |
11115 | /* PROB is the difference from 50%. */ | |
11116 | int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2; | |
f4857b9b AM |
11117 | |
11118 | /* Only hint for highly probable/improbable branches on newer | |
11119 | cpus as static prediction overrides processor dynamic | |
11120 | prediction. For older cpus we may as well always hint, but | |
11121 | assume not taken for branches that are very close to 50% as a | |
11122 | mispredicted taken branch is more expensive than a | |
f676971a | 11123 | mispredicted not-taken branch. */ |
ec507f2d | 11124 | if (rs6000_always_hint |
f4857b9b AM |
11125 | || abs (prob) > REG_BR_PROB_BASE / 100 * 48) |
11126 | { | |
11127 | if (abs (prob) > REG_BR_PROB_BASE / 20 | |
11128 | && ((prob > 0) ^ need_longbranch)) | |
7f3d8013 | 11129 | pred = "+"; |
f4857b9b AM |
11130 | else |
11131 | pred = "-"; | |
11132 | } | |
12a4e8c5 | 11133 | } |
12a4e8c5 GK |
11134 | |
11135 | if (label == NULL) | |
94a54f47 | 11136 | s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred); |
12a4e8c5 | 11137 | else |
94a54f47 | 11138 | s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred); |
12a4e8c5 | 11139 | |
37c67319 | 11140 | /* We need to escape any '%' characters in the reg_names string. |
a3c9585f | 11141 | Assume they'd only be the first character.... */ |
37c67319 GK |
11142 | if (reg_names[cc_regno + CR0_REGNO][0] == '%') |
11143 | *s++ = '%'; | |
94a54f47 | 11144 | s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]); |
12a4e8c5 GK |
11145 | |
11146 | if (label != NULL) | |
11147 | { | |
11148 | /* If the branch distance was too far, we may have to use an | |
11149 | unconditional branch to go the distance. */ | |
11150 | if (need_longbranch) | |
44518ddd | 11151 | s += sprintf (s, ",$+8\n\tb %s", label); |
12a4e8c5 GK |
11152 | else |
11153 | s += sprintf (s, ",%s", label); | |
11154 | } | |
11155 | ||
11156 | return string; | |
11157 | } | |
50a0b056 | 11158 | |
6b1fedc3 | 11159 | /* Return the string to flip the EQ bit on a CR. */ |
423c1189 | 11160 | char * |
6b1fedc3 | 11161 | output_e500_flip_eq_bit (rtx dst, rtx src) |
423c1189 AH |
11162 | { |
11163 | static char string[64]; | |
11164 | int a, b; | |
11165 | ||
11166 | if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst)) | |
11167 | || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src))) | |
11168 | abort (); | |
11169 | ||
6b1fedc3 AH |
11170 | /* EQ bit. */ |
11171 | a = 4 * (REGNO (dst) - CR0_REGNO) + 2; | |
11172 | b = 4 * (REGNO (src) - CR0_REGNO) + 2; | |
423c1189 AH |
11173 | |
11174 | sprintf (string, "crnot %d,%d", a, b); | |
11175 | return string; | |
11176 | } | |
11177 | ||
50a0b056 GK |
11178 | /* Emit a conditional move: move TRUE_COND to DEST if OP of the |
11179 | operands of the last comparison is nonzero/true, FALSE_COND if it | |
11180 | is zero/false. Return 0 if the hardware has no such operation. */ | |
a4f6c312 | 11181 | |
50a0b056 | 11182 | int |
a2369ed3 | 11183 | rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
50a0b056 GK |
11184 | { |
11185 | enum rtx_code code = GET_CODE (op); | |
11186 | rtx op0 = rs6000_compare_op0; | |
11187 | rtx op1 = rs6000_compare_op1; | |
11188 | REAL_VALUE_TYPE c1; | |
3148ad6d DJ |
11189 | enum machine_mode compare_mode = GET_MODE (op0); |
11190 | enum machine_mode result_mode = GET_MODE (dest); | |
50a0b056 GK |
11191 | rtx temp; |
11192 | ||
a3c9585f | 11193 | /* These modes should always match. */ |
a3170dc6 AH |
11194 | if (GET_MODE (op1) != compare_mode |
11195 | /* In the isel case however, we can use a compare immediate, so | |
11196 | op1 may be a small constant. */ | |
11197 | && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode))) | |
3148ad6d | 11198 | return 0; |
178c3eff | 11199 | if (GET_MODE (true_cond) != result_mode) |
3148ad6d | 11200 | return 0; |
178c3eff | 11201 | if (GET_MODE (false_cond) != result_mode) |
3148ad6d DJ |
11202 | return 0; |
11203 | ||
50a0b056 | 11204 | /* First, work out if the hardware can do this at all, or |
a3c9585f | 11205 | if it's too slow.... */ |
50a0b056 | 11206 | if (! rs6000_compare_fp_p) |
a3170dc6 AH |
11207 | { |
11208 | if (TARGET_ISEL) | |
11209 | return rs6000_emit_int_cmove (dest, op, true_cond, false_cond); | |
11210 | return 0; | |
11211 | } | |
fef98bf2 AH |
11212 | else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS |
11213 | && GET_MODE_CLASS (compare_mode) == MODE_FLOAT) | |
11214 | return 0; | |
50a0b056 GK |
11215 | |
11216 | /* Eliminate half of the comparisons by switching operands, this | |
11217 | makes the remaining code simpler. */ | |
11218 | if (code == UNLT || code == UNGT || code == UNORDERED || code == NE | |
bc9ec0e0 | 11219 | || code == LTGT || code == LT || code == UNLE) |
50a0b056 GK |
11220 | { |
11221 | code = reverse_condition_maybe_unordered (code); | |
11222 | temp = true_cond; | |
11223 | true_cond = false_cond; | |
11224 | false_cond = temp; | |
11225 | } | |
11226 | ||
11227 | /* UNEQ and LTGT take four instructions for a comparison with zero, | |
11228 | it'll probably be faster to use a branch here too. */ | |
bc9ec0e0 | 11229 | if (code == UNEQ && HONOR_NANS (compare_mode)) |
50a0b056 | 11230 | return 0; |
f676971a | 11231 | |
50a0b056 GK |
11232 | if (GET_CODE (op1) == CONST_DOUBLE) |
11233 | REAL_VALUE_FROM_CONST_DOUBLE (c1, op1); | |
f676971a | 11234 | |
b6d08ca1 | 11235 | /* We're going to try to implement comparisons by performing |
50a0b056 GK |
11236 | a subtract, then comparing against zero. Unfortunately, |
11237 | Inf - Inf is NaN which is not zero, and so if we don't | |
27d30956 | 11238 | know that the operand is finite and the comparison |
50a0b056 | 11239 | would treat EQ different to UNORDERED, we can't do it. */ |
bc9ec0e0 | 11240 | if (HONOR_INFINITIES (compare_mode) |
50a0b056 | 11241 | && code != GT && code != UNGE |
045572c7 | 11242 | && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1)) |
50a0b056 GK |
11243 | /* Constructs of the form (a OP b ? a : b) are safe. */ |
11244 | && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond)) | |
f676971a | 11245 | || (! rtx_equal_p (op0, true_cond) |
50a0b056 GK |
11246 | && ! rtx_equal_p (op1, true_cond)))) |
11247 | return 0; | |
11248 | /* At this point we know we can use fsel. */ | |
11249 | ||
11250 | /* Reduce the comparison to a comparison against zero. */ | |
3148ad6d | 11251 | temp = gen_reg_rtx (compare_mode); |
50a0b056 | 11252 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 11253 | gen_rtx_MINUS (compare_mode, op0, op1))); |
50a0b056 | 11254 | op0 = temp; |
3148ad6d | 11255 | op1 = CONST0_RTX (compare_mode); |
50a0b056 GK |
11256 | |
11257 | /* If we don't care about NaNs we can reduce some of the comparisons | |
11258 | down to faster ones. */ | |
bc9ec0e0 | 11259 | if (! HONOR_NANS (compare_mode)) |
50a0b056 GK |
11260 | switch (code) |
11261 | { | |
11262 | case GT: | |
11263 | code = LE; | |
11264 | temp = true_cond; | |
11265 | true_cond = false_cond; | |
11266 | false_cond = temp; | |
11267 | break; | |
11268 | case UNGE: | |
11269 | code = GE; | |
11270 | break; | |
11271 | case UNEQ: | |
11272 | code = EQ; | |
11273 | break; | |
11274 | default: | |
11275 | break; | |
11276 | } | |
11277 | ||
11278 | /* Now, reduce everything down to a GE. */ | |
11279 | switch (code) | |
11280 | { | |
11281 | case GE: | |
11282 | break; | |
11283 | ||
11284 | case LE: | |
3148ad6d DJ |
11285 | temp = gen_reg_rtx (compare_mode); |
11286 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
11287 | op0 = temp; |
11288 | break; | |
11289 | ||
11290 | case ORDERED: | |
3148ad6d DJ |
11291 | temp = gen_reg_rtx (compare_mode); |
11292 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0))); | |
50a0b056 GK |
11293 | op0 = temp; |
11294 | break; | |
11295 | ||
11296 | case EQ: | |
3148ad6d | 11297 | temp = gen_reg_rtx (compare_mode); |
f676971a | 11298 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d DJ |
11299 | gen_rtx_NEG (compare_mode, |
11300 | gen_rtx_ABS (compare_mode, op0)))); | |
50a0b056 GK |
11301 | op0 = temp; |
11302 | break; | |
11303 | ||
11304 | case UNGE: | |
bc9ec0e0 | 11305 | /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */ |
3148ad6d | 11306 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 11307 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
3148ad6d | 11308 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
11309 | gen_rtx_GE (VOIDmode, |
11310 | op0, op1), | |
11311 | true_cond, false_cond))); | |
bc9ec0e0 GK |
11312 | false_cond = true_cond; |
11313 | true_cond = temp; | |
50a0b056 | 11314 | |
3148ad6d DJ |
11315 | temp = gen_reg_rtx (compare_mode); |
11316 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
11317 | op0 = temp; |
11318 | break; | |
11319 | ||
11320 | case GT: | |
bc9ec0e0 | 11321 | /* a GT 0 <-> (a GE 0 && -a UNLT 0) */ |
3148ad6d | 11322 | temp = gen_reg_rtx (result_mode); |
50a0b056 | 11323 | emit_insn (gen_rtx_SET (VOIDmode, temp, |
f676971a | 11324 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
11325 | gen_rtx_GE (VOIDmode, |
11326 | op0, op1), | |
11327 | true_cond, false_cond))); | |
bc9ec0e0 GK |
11328 | true_cond = false_cond; |
11329 | false_cond = temp; | |
50a0b056 | 11330 | |
3148ad6d DJ |
11331 | temp = gen_reg_rtx (compare_mode); |
11332 | emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0))); | |
50a0b056 GK |
11333 | op0 = temp; |
11334 | break; | |
11335 | ||
11336 | default: | |
11337 | abort (); | |
11338 | } | |
11339 | ||
11340 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
3148ad6d | 11341 | gen_rtx_IF_THEN_ELSE (result_mode, |
50a0b056 GK |
11342 | gen_rtx_GE (VOIDmode, |
11343 | op0, op1), | |
11344 | true_cond, false_cond))); | |
11345 | return 1; | |
11346 | } | |
11347 | ||
a3170dc6 AH |
11348 | /* Same as above, but for ints (isel). */ |
11349 | ||
11350 | static int | |
a2369ed3 | 11351 | rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond) |
a3170dc6 AH |
11352 | { |
11353 | rtx condition_rtx, cr; | |
11354 | ||
11355 | /* All isel implementations thus far are 32-bits. */ | |
11356 | if (GET_MODE (rs6000_compare_op0) != SImode) | |
11357 | return 0; | |
11358 | ||
11359 | /* We still have to do the compare, because isel doesn't do a | |
11360 | compare, it just looks at the CRx bits set by a previous compare | |
11361 | instruction. */ | |
11362 | condition_rtx = rs6000_generate_compare (GET_CODE (op)); | |
11363 | cr = XEXP (condition_rtx, 0); | |
11364 | ||
11365 | if (GET_MODE (cr) == CCmode) | |
11366 | emit_insn (gen_isel_signed (dest, condition_rtx, | |
11367 | true_cond, false_cond, cr)); | |
11368 | else | |
11369 | emit_insn (gen_isel_unsigned (dest, condition_rtx, | |
11370 | true_cond, false_cond, cr)); | |
11371 | ||
11372 | return 1; | |
11373 | } | |
11374 | ||
11375 | const char * | |
a2369ed3 | 11376 | output_isel (rtx *operands) |
a3170dc6 AH |
11377 | { |
11378 | enum rtx_code code; | |
11379 | ||
11380 | code = GET_CODE (operands[1]); | |
11381 | if (code == GE || code == GEU || code == LE || code == LEU || code == NE) | |
11382 | { | |
11383 | PUT_CODE (operands[1], reverse_condition (code)); | |
11384 | return "isel %0,%3,%2,%j1"; | |
11385 | } | |
11386 | else | |
11387 | return "isel %0,%2,%3,%j1"; | |
11388 | } | |
11389 | ||
50a0b056 | 11390 | void |
a2369ed3 | 11391 | rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1) |
50a0b056 GK |
11392 | { |
11393 | enum machine_mode mode = GET_MODE (op0); | |
5dc8d536 | 11394 | enum rtx_code c; |
50a0b056 | 11395 | rtx target; |
5dc8d536 AH |
11396 | |
11397 | if (code == SMAX || code == SMIN) | |
11398 | c = GE; | |
11399 | else | |
11400 | c = GEU; | |
11401 | ||
50a0b056 | 11402 | if (code == SMAX || code == UMAX) |
f676971a | 11403 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
11404 | op0, op1, mode, 0); |
11405 | else | |
f676971a | 11406 | target = emit_conditional_move (dest, c, op0, op1, mode, |
50a0b056 GK |
11407 | op1, op0, mode, 0); |
11408 | if (target == NULL_RTX) | |
11409 | abort (); | |
11410 | if (target != dest) | |
11411 | emit_move_insn (dest, target); | |
11412 | } | |
46c07df8 | 11413 | |
a9baceb1 GK |
11414 | /* Emit instructions to move SRC to DST. Called by splitters for |
11415 | multi-register moves. It will emit at most one instruction for | |
11416 | each register that is accessed; that is, it won't emit li/lis pairs | |
11417 | (or equivalent for 64-bit code). One of SRC or DST must be a hard | |
11418 | register. */ | |
46c07df8 | 11419 | |
46c07df8 | 11420 | void |
a9baceb1 | 11421 | rs6000_split_multireg_move (rtx dst, rtx src) |
46c07df8 | 11422 | { |
a9baceb1 GK |
11423 | /* The register number of the first register being moved. */ |
11424 | int reg; | |
11425 | /* The mode that is to be moved. */ | |
11426 | enum machine_mode mode; | |
11427 | /* The mode that the move is being done in, and its size. */ | |
11428 | enum machine_mode reg_mode; | |
11429 | int reg_mode_size; | |
11430 | /* The number of registers that will be moved. */ | |
11431 | int nregs; | |
11432 | ||
11433 | reg = REG_P (dst) ? REGNO (dst) : REGNO (src); | |
11434 | mode = GET_MODE (dst); | |
11435 | nregs = HARD_REGNO_NREGS (reg, mode); | |
11436 | if (FP_REGNO_P (reg)) | |
11437 | reg_mode = DFmode; | |
11438 | else if (ALTIVEC_REGNO_P (reg)) | |
11439 | reg_mode = V16QImode; | |
11440 | else | |
11441 | reg_mode = word_mode; | |
11442 | reg_mode_size = GET_MODE_SIZE (reg_mode); | |
f676971a | 11443 | |
a9baceb1 GK |
11444 | if (reg_mode_size * nregs != GET_MODE_SIZE (mode)) |
11445 | abort (); | |
f676971a | 11446 | |
a9baceb1 GK |
11447 | if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst))) |
11448 | { | |
11449 | /* Move register range backwards, if we might have destructive | |
11450 | overlap. */ | |
11451 | int i; | |
11452 | for (i = nregs - 1; i >= 0; i--) | |
f676971a | 11453 | emit_insn (gen_rtx_SET (VOIDmode, |
a9baceb1 GK |
11454 | simplify_gen_subreg (reg_mode, dst, mode, |
11455 | i * reg_mode_size), | |
11456 | simplify_gen_subreg (reg_mode, src, mode, | |
11457 | i * reg_mode_size))); | |
11458 | } | |
46c07df8 HP |
11459 | else |
11460 | { | |
a9baceb1 GK |
11461 | int i; |
11462 | int j = -1; | |
11463 | bool used_update = false; | |
46c07df8 | 11464 | |
c1e55850 | 11465 | if (MEM_P (src) && INT_REGNO_P (reg)) |
46c07df8 HP |
11466 | { |
11467 | rtx breg; | |
3a1f863f | 11468 | |
a9baceb1 GK |
11469 | if (GET_CODE (XEXP (src, 0)) == PRE_INC |
11470 | || GET_CODE (XEXP (src, 0)) == PRE_DEC) | |
3a1f863f DE |
11471 | { |
11472 | rtx delta_rtx; | |
a9baceb1 | 11473 | breg = XEXP (XEXP (src, 0), 0); |
f676971a EC |
11474 | delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC |
11475 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (src))) | |
11476 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))); | |
a9baceb1 GK |
11477 | emit_insn (TARGET_32BIT |
11478 | ? gen_addsi3 (breg, breg, delta_rtx) | |
11479 | : gen_adddi3 (breg, breg, delta_rtx)); | |
3a1f863f DE |
11480 | src = gen_rtx_MEM (mode, breg); |
11481 | } | |
c1e55850 GK |
11482 | else if (! offsettable_memref_p (src)) |
11483 | { | |
11484 | rtx newsrc, basereg; | |
11485 | basereg = gen_rtx_REG (Pmode, reg); | |
11486 | emit_insn (gen_rtx_SET (VOIDmode, basereg, XEXP (src, 0))); | |
11487 | newsrc = gen_rtx_MEM (GET_MODE (src), basereg); | |
11488 | MEM_COPY_ATTRIBUTES (newsrc, src); | |
11489 | src = newsrc; | |
11490 | } | |
3a1f863f | 11491 | |
0423421f AM |
11492 | breg = XEXP (src, 0); |
11493 | if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM) | |
11494 | breg = XEXP (breg, 0); | |
11495 | ||
11496 | /* If the base register we are using to address memory is | |
11497 | also a destination reg, then change that register last. */ | |
11498 | if (REG_P (breg) | |
11499 | && REGNO (breg) >= REGNO (dst) | |
3a1f863f DE |
11500 | && REGNO (breg) < REGNO (dst) + nregs) |
11501 | j = REGNO (breg) - REGNO (dst); | |
46c07df8 HP |
11502 | } |
11503 | ||
a9baceb1 | 11504 | if (GET_CODE (dst) == MEM && INT_REGNO_P (reg)) |
3a1f863f DE |
11505 | { |
11506 | rtx breg; | |
11507 | ||
a9baceb1 GK |
11508 | if (GET_CODE (XEXP (dst, 0)) == PRE_INC |
11509 | || GET_CODE (XEXP (dst, 0)) == PRE_DEC) | |
3a1f863f DE |
11510 | { |
11511 | rtx delta_rtx; | |
a9baceb1 | 11512 | breg = XEXP (XEXP (dst, 0), 0); |
f676971a EC |
11513 | delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC |
11514 | ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst))) | |
11515 | : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))); | |
3a1f863f DE |
11516 | |
11517 | /* We have to update the breg before doing the store. | |
11518 | Use store with update, if available. */ | |
11519 | ||
11520 | if (TARGET_UPDATE) | |
11521 | { | |
a9baceb1 | 11522 | rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0); |
2e6c9641 FJ |
11523 | emit_insn (TARGET_32BIT |
11524 | ? (TARGET_POWERPC64 | |
11525 | ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc) | |
11526 | : gen_movsi_update (breg, breg, delta_rtx, nsrc)) | |
11527 | : gen_movdi_di_update (breg, breg, delta_rtx, nsrc)); | |
a9baceb1 | 11528 | used_update = true; |
3a1f863f DE |
11529 | } |
11530 | else | |
a9baceb1 GK |
11531 | emit_insn (TARGET_32BIT |
11532 | ? gen_addsi3 (breg, breg, delta_rtx) | |
11533 | : gen_adddi3 (breg, breg, delta_rtx)); | |
3a1f863f DE |
11534 | dst = gen_rtx_MEM (mode, breg); |
11535 | } | |
c1e55850 | 11536 | else if (! offsettable_memref_p (dst)) |
112ccb83 | 11537 | abort (); |
3a1f863f DE |
11538 | } |
11539 | ||
46c07df8 | 11540 | for (i = 0; i < nregs; i++) |
f676971a | 11541 | { |
3a1f863f DE |
11542 | /* Calculate index to next subword. */ |
11543 | ++j; | |
f676971a | 11544 | if (j == nregs) |
3a1f863f | 11545 | j = 0; |
46c07df8 | 11546 | |
112cdef5 | 11547 | /* If compiler already emitted move of first word by |
a9baceb1 | 11548 | store with update, no need to do anything. */ |
3a1f863f | 11549 | if (j == 0 && used_update) |
a9baceb1 | 11550 | continue; |
f676971a | 11551 | |
a9baceb1 GK |
11552 | emit_insn (gen_rtx_SET (VOIDmode, |
11553 | simplify_gen_subreg (reg_mode, dst, mode, | |
11554 | j * reg_mode_size), | |
11555 | simplify_gen_subreg (reg_mode, src, mode, | |
11556 | j * reg_mode_size))); | |
3a1f863f | 11557 | } |
46c07df8 HP |
11558 | } |
11559 | } | |
11560 | ||
12a4e8c5 | 11561 | \f |
a4f6c312 SS |
11562 | /* This page contains routines that are used to determine what the |
11563 | function prologue and epilogue code will do and write them out. */ | |
9878760c | 11564 | |
a4f6c312 SS |
11565 | /* Return the first fixed-point register that is required to be |
11566 | saved. 32 if none. */ | |
9878760c RK |
11567 | |
11568 | int | |
863d938c | 11569 | first_reg_to_save (void) |
9878760c RK |
11570 | { |
11571 | int first_reg; | |
11572 | ||
11573 | /* Find lowest numbered live register. */ | |
11574 | for (first_reg = 13; first_reg <= 31; first_reg++) | |
f676971a | 11575 | if (regs_ever_live[first_reg] |
a38d360d | 11576 | && (! call_used_regs[first_reg] |
1db02437 | 11577 | || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 11578 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
b4db40bf JJ |
11579 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic) |
11580 | || (TARGET_TOC && TARGET_MINIMAL_TOC))))) | |
9878760c RK |
11581 | break; |
11582 | ||
ee890fe2 | 11583 | #if TARGET_MACHO |
93638d7a AM |
11584 | if (flag_pic |
11585 | && current_function_uses_pic_offset_table | |
11586 | && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM) | |
1db02437 | 11587 | return RS6000_PIC_OFFSET_TABLE_REGNUM; |
ee890fe2 SS |
11588 | #endif |
11589 | ||
9878760c RK |
11590 | return first_reg; |
11591 | } | |
11592 | ||
11593 | /* Similar, for FP regs. */ | |
11594 | ||
11595 | int | |
863d938c | 11596 | first_fp_reg_to_save (void) |
9878760c RK |
11597 | { |
11598 | int first_reg; | |
11599 | ||
11600 | /* Find lowest numbered live register. */ | |
11601 | for (first_reg = 14 + 32; first_reg <= 63; first_reg++) | |
11602 | if (regs_ever_live[first_reg]) | |
11603 | break; | |
11604 | ||
11605 | return first_reg; | |
11606 | } | |
00b960c7 AH |
11607 | |
11608 | /* Similar, for AltiVec regs. */ | |
11609 | ||
11610 | static int | |
863d938c | 11611 | first_altivec_reg_to_save (void) |
00b960c7 AH |
11612 | { |
11613 | int i; | |
11614 | ||
11615 | /* Stack frame remains as is unless we are in AltiVec ABI. */ | |
11616 | if (! TARGET_ALTIVEC_ABI) | |
11617 | return LAST_ALTIVEC_REGNO + 1; | |
11618 | ||
11619 | /* Find lowest numbered live register. */ | |
11620 | for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i) | |
11621 | if (regs_ever_live[i]) | |
11622 | break; | |
11623 | ||
11624 | return i; | |
11625 | } | |
11626 | ||
11627 | /* Return a 32-bit mask of the AltiVec registers we need to set in | |
11628 | VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in | |
11629 | the 32-bit word is 0. */ | |
11630 | ||
11631 | static unsigned int | |
863d938c | 11632 | compute_vrsave_mask (void) |
00b960c7 AH |
11633 | { |
11634 | unsigned int i, mask = 0; | |
11635 | ||
11636 | /* First, find out if we use _any_ altivec registers. */ | |
11637 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
11638 | if (regs_ever_live[i]) | |
11639 | mask |= ALTIVEC_REG_BIT (i); | |
11640 | ||
11641 | if (mask == 0) | |
11642 | return mask; | |
11643 | ||
00b960c7 AH |
11644 | /* Next, remove the argument registers from the set. These must |
11645 | be in the VRSAVE mask set by the caller, so we don't need to add | |
11646 | them in again. More importantly, the mask we compute here is | |
11647 | used to generate CLOBBERs in the set_vrsave insn, and we do not | |
11648 | wish the argument registers to die. */ | |
a6cf80f2 | 11649 | for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i) |
00b960c7 AH |
11650 | mask &= ~ALTIVEC_REG_BIT (i); |
11651 | ||
11652 | /* Similarly, remove the return value from the set. */ | |
11653 | { | |
11654 | bool yes = false; | |
11655 | diddle_return_value (is_altivec_return_reg, &yes); | |
11656 | if (yes) | |
11657 | mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN); | |
11658 | } | |
11659 | ||
11660 | return mask; | |
11661 | } | |
11662 | ||
d62294f5 FJ |
11663 | /* For a very restricted set of circumstances, we can cut down the |
11664 | size of prologs/epilogs by calling our own save/restore-the-world | |
11665 | routines. */ | |
11666 | ||
11667 | static void | |
11668 | compute_save_world_info(rs6000_stack_t *info_ptr) | |
11669 | { | |
11670 | info_ptr->world_save_p = | |
11671 | (DEFAULT_ABI == ABI_DARWIN) | |
11672 | && ! (current_function_calls_setjmp && flag_exceptions) | |
11673 | && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO | |
11674 | && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO | |
11675 | && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO | |
11676 | && info_ptr->cr_save_p; | |
f676971a | 11677 | |
d62294f5 FJ |
11678 | /* This will not work in conjunction with sibcalls. Make sure there |
11679 | are none. (This check is expensive, but seldom executed.) */ | |
11680 | if ( info_ptr->world_save_p ) | |
f676971a | 11681 | { |
d62294f5 FJ |
11682 | rtx insn; |
11683 | for ( insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn)) | |
11684 | if ( GET_CODE (insn) == CALL_INSN | |
11685 | && SIBLING_CALL_P (insn)) | |
f676971a | 11686 | { |
d62294f5 FJ |
11687 | info_ptr->world_save_p = 0; |
11688 | break; | |
11689 | } | |
11690 | } | |
f676971a | 11691 | |
d62294f5 FJ |
11692 | if (info_ptr->world_save_p) |
11693 | { | |
11694 | /* Even if we're not touching VRsave, make sure there's room on the | |
11695 | stack for it, if it looks like we're calling SAVE_WORLD, which | |
11696 | will attempt to save it. */ | |
11697 | info_ptr->vrsave_size = 4; | |
11698 | ||
11699 | /* "Save" the VRsave register too if we're saving the world. */ | |
11700 | if (info_ptr->vrsave_mask == 0) | |
11701 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
11702 | ||
11703 | /* Because the Darwin register save/restore routines only handle | |
112cdef5 | 11704 | F14 .. F31 and V20 .. V31 as per the ABI, perform a consistency |
d62294f5 | 11705 | check and abort if there's something worng. */ |
f676971a | 11706 | if (info_ptr->first_fp_reg_save < FIRST_SAVED_FP_REGNO |
d62294f5 FJ |
11707 | || info_ptr->first_altivec_reg_save < FIRST_SAVED_ALTIVEC_REGNO) |
11708 | abort (); | |
11709 | } | |
f676971a | 11710 | return; |
d62294f5 FJ |
11711 | } |
11712 | ||
11713 | ||
00b960c7 | 11714 | static void |
a2369ed3 | 11715 | is_altivec_return_reg (rtx reg, void *xyes) |
00b960c7 AH |
11716 | { |
11717 | bool *yes = (bool *) xyes; | |
11718 | if (REGNO (reg) == ALTIVEC_ARG_RETURN) | |
11719 | *yes = true; | |
11720 | } | |
11721 | ||
4697a36c MM |
11722 | \f |
11723 | /* Calculate the stack information for the current function. This is | |
11724 | complicated by having two separate calling sequences, the AIX calling | |
11725 | sequence and the V.4 calling sequence. | |
11726 | ||
592696dd | 11727 | AIX (and Darwin/Mac OS X) stack frames look like: |
a260abc9 | 11728 | 32-bit 64-bit |
4697a36c | 11729 | SP----> +---------------------------------------+ |
a260abc9 | 11730 | | back chain to caller | 0 0 |
4697a36c | 11731 | +---------------------------------------+ |
a260abc9 | 11732 | | saved CR | 4 8 (8-11) |
4697a36c | 11733 | +---------------------------------------+ |
a260abc9 | 11734 | | saved LR | 8 16 |
4697a36c | 11735 | +---------------------------------------+ |
a260abc9 | 11736 | | reserved for compilers | 12 24 |
4697a36c | 11737 | +---------------------------------------+ |
a260abc9 | 11738 | | reserved for binders | 16 32 |
4697a36c | 11739 | +---------------------------------------+ |
a260abc9 | 11740 | | saved TOC pointer | 20 40 |
4697a36c | 11741 | +---------------------------------------+ |
a260abc9 | 11742 | | Parameter save area (P) | 24 48 |
4697a36c | 11743 | +---------------------------------------+ |
a260abc9 | 11744 | | Alloca space (A) | 24+P etc. |
802a0058 | 11745 | +---------------------------------------+ |
a7df97e6 | 11746 | | Local variable space (L) | 24+P+A |
4697a36c | 11747 | +---------------------------------------+ |
a7df97e6 | 11748 | | Float/int conversion temporary (X) | 24+P+A+L |
4697a36c | 11749 | +---------------------------------------+ |
00b960c7 AH |
11750 | | Save area for AltiVec registers (W) | 24+P+A+L+X |
11751 | +---------------------------------------+ | |
11752 | | AltiVec alignment padding (Y) | 24+P+A+L+X+W | |
11753 | +---------------------------------------+ | |
11754 | | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y | |
4697a36c | 11755 | +---------------------------------------+ |
00b960c7 AH |
11756 | | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z |
11757 | +---------------------------------------+ | |
11758 | | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G | |
4697a36c MM |
11759 | +---------------------------------------+ |
11760 | old SP->| back chain to caller's caller | | |
11761 | +---------------------------------------+ | |
11762 | ||
5376a30c KR |
11763 | The required alignment for AIX configurations is two words (i.e., 8 |
11764 | or 16 bytes). | |
11765 | ||
11766 | ||
4697a36c MM |
11767 | V.4 stack frames look like: |
11768 | ||
11769 | SP----> +---------------------------------------+ | |
11770 | | back chain to caller | 0 | |
11771 | +---------------------------------------+ | |
5eb387b8 | 11772 | | caller's saved LR | 4 |
4697a36c MM |
11773 | +---------------------------------------+ |
11774 | | Parameter save area (P) | 8 | |
11775 | +---------------------------------------+ | |
a7df97e6 | 11776 | | Alloca space (A) | 8+P |
f676971a | 11777 | +---------------------------------------+ |
a7df97e6 | 11778 | | Varargs save area (V) | 8+P+A |
f676971a | 11779 | +---------------------------------------+ |
a7df97e6 | 11780 | | Local variable space (L) | 8+P+A+V |
f676971a | 11781 | +---------------------------------------+ |
a7df97e6 | 11782 | | Float/int conversion temporary (X) | 8+P+A+V+L |
4697a36c | 11783 | +---------------------------------------+ |
00b960c7 AH |
11784 | | Save area for AltiVec registers (W) | 8+P+A+V+L+X |
11785 | +---------------------------------------+ | |
11786 | | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W | |
11787 | +---------------------------------------+ | |
11788 | | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y | |
11789 | +---------------------------------------+ | |
a3170dc6 AH |
11790 | | SPE: area for 64-bit GP registers | |
11791 | +---------------------------------------+ | |
11792 | | SPE alignment padding | | |
11793 | +---------------------------------------+ | |
00b960c7 | 11794 | | saved CR (C) | 8+P+A+V+L+X+W+Y+Z |
f676971a | 11795 | +---------------------------------------+ |
00b960c7 | 11796 | | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C |
f676971a | 11797 | +---------------------------------------+ |
00b960c7 | 11798 | | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G |
4697a36c MM |
11799 | +---------------------------------------+ |
11800 | old SP->| back chain to caller's caller | | |
11801 | +---------------------------------------+ | |
b6c9286a | 11802 | |
5376a30c KR |
11803 | The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is |
11804 | given. (But note below and in sysv4.h that we require only 8 and | |
11805 | may round up the size of our stack frame anyways. The historical | |
11806 | reason is early versions of powerpc-linux which didn't properly | |
11807 | align the stack at program startup. A happy side-effect is that | |
11808 | -mno-eabi libraries can be used with -meabi programs.) | |
11809 | ||
50d440bc | 11810 | The EABI configuration defaults to the V.4 layout. However, |
5376a30c KR |
11811 | the stack alignment requirements may differ. If -mno-eabi is not |
11812 | given, the required stack alignment is 8 bytes; if -mno-eabi is | |
11813 | given, the required alignment is 16 bytes. (But see V.4 comment | |
11814 | above.) */ | |
4697a36c | 11815 | |
61b2fbe7 MM |
11816 | #ifndef ABI_STACK_BOUNDARY |
11817 | #define ABI_STACK_BOUNDARY STACK_BOUNDARY | |
11818 | #endif | |
11819 | ||
d1d0c603 | 11820 | static rs6000_stack_t * |
863d938c | 11821 | rs6000_stack_info (void) |
4697a36c MM |
11822 | { |
11823 | static rs6000_stack_t info, zero_info; | |
11824 | rs6000_stack_t *info_ptr = &info; | |
327e5343 | 11825 | int reg_size = TARGET_32BIT ? 4 : 8; |
83720594 | 11826 | int ehrd_size; |
64045029 | 11827 | int save_align; |
44688022 | 11828 | HOST_WIDE_INT non_fixed_size; |
4697a36c | 11829 | |
a4f6c312 | 11830 | /* Zero all fields portably. */ |
4697a36c MM |
11831 | info = zero_info; |
11832 | ||
c19de7aa AH |
11833 | if (TARGET_SPE) |
11834 | { | |
11835 | /* Cache value so we don't rescan instruction chain over and over. */ | |
9b7b447f AH |
11836 | if (cfun->machine->insn_chain_scanned_p == 0) |
11837 | { | |
11838 | cfun->machine->insn_chain_scanned_p = 1; | |
11839 | info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p (); | |
11840 | } | |
c19de7aa AH |
11841 | } |
11842 | ||
a4f6c312 | 11843 | /* Select which calling sequence. */ |
178274da | 11844 | info_ptr->abi = DEFAULT_ABI; |
9878760c | 11845 | |
a4f6c312 | 11846 | /* Calculate which registers need to be saved & save area size. */ |
4697a36c | 11847 | info_ptr->first_gp_reg_save = first_reg_to_save (); |
f676971a | 11848 | /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM, |
906fb125 | 11849 | even if it currently looks like we won't. */ |
2bfcf297 | 11850 | if (((TARGET_TOC && TARGET_MINIMAL_TOC) |
178274da AM |
11851 | || (flag_pic == 1 && DEFAULT_ABI == ABI_V4) |
11852 | || (flag_pic && DEFAULT_ABI == ABI_DARWIN)) | |
1db02437 FS |
11853 | && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM) |
11854 | info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM); | |
906fb125 GK |
11855 | else |
11856 | info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save); | |
4697a36c | 11857 | |
a3170dc6 AH |
11858 | /* For the SPE, we have an additional upper 32-bits on each GPR. |
11859 | Ideally we should save the entire 64-bits only when the upper | |
11860 | half is used in SIMD instructions. Since we only record | |
11861 | registers live (not the size they are used in), this proves | |
11862 | difficult because we'd have to traverse the instruction chain at | |
11863 | the right time, taking reload into account. This is a real pain, | |
c19de7aa AH |
11864 | so we opt to save the GPRs in 64-bits always if but one register |
11865 | gets used in 64-bits. Otherwise, all the registers in the frame | |
11866 | get saved in 32-bits. | |
a3170dc6 | 11867 | |
c19de7aa | 11868 | So... since when we save all GPRs (except the SP) in 64-bits, the |
a3170dc6 | 11869 | traditional GP save area will be empty. */ |
c19de7aa | 11870 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11871 | info_ptr->gp_size = 0; |
11872 | ||
4697a36c MM |
11873 | info_ptr->first_fp_reg_save = first_fp_reg_to_save (); |
11874 | info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save); | |
11875 | ||
00b960c7 AH |
11876 | info_ptr->first_altivec_reg_save = first_altivec_reg_to_save (); |
11877 | info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1 | |
11878 | - info_ptr->first_altivec_reg_save); | |
11879 | ||
592696dd | 11880 | /* Does this function call anything? */ |
71f123ca FS |
11881 | info_ptr->calls_p = (! current_function_is_leaf |
11882 | || cfun->machine->ra_needs_full_frame); | |
b6c9286a | 11883 | |
a4f6c312 | 11884 | /* Determine if we need to save the link register. */ |
71f123ca | 11885 | if (rs6000_ra_ever_killed () |
ffcfcb5f AM |
11886 | || (DEFAULT_ABI == ABI_AIX |
11887 | && current_function_profile | |
11888 | && !TARGET_PROFILE_KERNEL) | |
4697a36c MM |
11889 | #ifdef TARGET_RELOCATABLE |
11890 | || (TARGET_RELOCATABLE && (get_pool_size () != 0)) | |
11891 | #endif | |
11892 | || (info_ptr->first_fp_reg_save != 64 | |
11893 | && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save)) | |
00b960c7 | 11894 | || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO |
178274da | 11895 | || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca) |
a4f6c312 SS |
11896 | || (DEFAULT_ABI == ABI_DARWIN |
11897 | && flag_pic | |
11898 | && current_function_uses_pic_offset_table) | |
4697a36c MM |
11899 | || info_ptr->calls_p) |
11900 | { | |
11901 | info_ptr->lr_save_p = 1; | |
9ebbca7d | 11902 | regs_ever_live[LINK_REGISTER_REGNUM] = 1; |
4697a36c MM |
11903 | } |
11904 | ||
9ebbca7d | 11905 | /* Determine if we need to save the condition code registers. */ |
f676971a | 11906 | if (regs_ever_live[CR2_REGNO] |
9ebbca7d GK |
11907 | || regs_ever_live[CR3_REGNO] |
11908 | || regs_ever_live[CR4_REGNO]) | |
4697a36c MM |
11909 | { |
11910 | info_ptr->cr_save_p = 1; | |
178274da | 11911 | if (DEFAULT_ABI == ABI_V4) |
4697a36c MM |
11912 | info_ptr->cr_size = reg_size; |
11913 | } | |
11914 | ||
83720594 RH |
11915 | /* If the current function calls __builtin_eh_return, then we need |
11916 | to allocate stack space for registers that will hold data for | |
11917 | the exception handler. */ | |
11918 | if (current_function_calls_eh_return) | |
11919 | { | |
11920 | unsigned int i; | |
11921 | for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i) | |
11922 | continue; | |
a3170dc6 AH |
11923 | |
11924 | /* SPE saves EH registers in 64-bits. */ | |
c19de7aa AH |
11925 | ehrd_size = i * (TARGET_SPE_ABI |
11926 | && info_ptr->spe_64bit_regs_used != 0 | |
11927 | ? UNITS_PER_SPE_WORD : UNITS_PER_WORD); | |
83720594 RH |
11928 | } |
11929 | else | |
11930 | ehrd_size = 0; | |
11931 | ||
592696dd | 11932 | /* Determine various sizes. */ |
4697a36c MM |
11933 | info_ptr->reg_size = reg_size; |
11934 | info_ptr->fixed_size = RS6000_SAVE_AREA; | |
11935 | info_ptr->varargs_size = RS6000_VARARGS_AREA; | |
189e03e3 | 11936 | info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8); |
a4f6c312 | 11937 | info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size, |
03e007d7 | 11938 | TARGET_ALTIVEC ? 16 : 8); |
00b960c7 | 11939 | |
c19de7aa | 11940 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
11941 | info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save); |
11942 | else | |
11943 | info_ptr->spe_gp_size = 0; | |
11944 | ||
4d774ff8 HP |
11945 | if (TARGET_ALTIVEC_ABI) |
11946 | info_ptr->vrsave_mask = compute_vrsave_mask (); | |
00b960c7 | 11947 | else |
4d774ff8 HP |
11948 | info_ptr->vrsave_mask = 0; |
11949 | ||
11950 | if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask) | |
11951 | info_ptr->vrsave_size = 4; | |
11952 | else | |
11953 | info_ptr->vrsave_size = 0; | |
b6c9286a | 11954 | |
d62294f5 FJ |
11955 | compute_save_world_info (info_ptr); |
11956 | ||
592696dd | 11957 | /* Calculate the offsets. */ |
178274da | 11958 | switch (DEFAULT_ABI) |
4697a36c | 11959 | { |
b6c9286a | 11960 | case ABI_NONE: |
24d304eb | 11961 | default: |
b6c9286a MM |
11962 | abort (); |
11963 | ||
11964 | case ABI_AIX: | |
ee890fe2 | 11965 | case ABI_DARWIN: |
b6c9286a MM |
11966 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
11967 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
00b960c7 AH |
11968 | |
11969 | if (TARGET_ALTIVEC_ABI) | |
11970 | { | |
11971 | info_ptr->vrsave_save_offset | |
11972 | = info_ptr->gp_save_offset - info_ptr->vrsave_size; | |
11973 | ||
11974 | /* Align stack so vector save area is on a quadword boundary. */ | |
11975 | if (info_ptr->altivec_size != 0) | |
11976 | info_ptr->altivec_padding_size | |
11977 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
11978 | else | |
11979 | info_ptr->altivec_padding_size = 0; | |
11980 | ||
11981 | info_ptr->altivec_save_offset | |
11982 | = info_ptr->vrsave_save_offset | |
11983 | - info_ptr->altivec_padding_size | |
11984 | - info_ptr->altivec_size; | |
11985 | ||
11986 | /* Adjust for AltiVec case. */ | |
11987 | info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size; | |
11988 | } | |
11989 | else | |
11990 | info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size; | |
a260abc9 DE |
11991 | info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */ |
11992 | info_ptr->lr_save_offset = 2*reg_size; | |
24d304eb RK |
11993 | break; |
11994 | ||
11995 | case ABI_V4: | |
b6c9286a MM |
11996 | info_ptr->fp_save_offset = - info_ptr->fp_size; |
11997 | info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size; | |
a7df97e6 | 11998 | info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size; |
00b960c7 | 11999 | |
c19de7aa | 12000 | if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0) |
a3170dc6 AH |
12001 | { |
12002 | /* Align stack so SPE GPR save area is aligned on a | |
12003 | double-word boundary. */ | |
12004 | if (info_ptr->spe_gp_size != 0) | |
12005 | info_ptr->spe_padding_size | |
12006 | = 8 - (-info_ptr->cr_save_offset % 8); | |
12007 | else | |
12008 | info_ptr->spe_padding_size = 0; | |
12009 | ||
12010 | info_ptr->spe_gp_save_offset | |
12011 | = info_ptr->cr_save_offset | |
12012 | - info_ptr->spe_padding_size | |
12013 | - info_ptr->spe_gp_size; | |
12014 | ||
12015 | /* Adjust for SPE case. */ | |
12016 | info_ptr->toc_save_offset | |
12017 | = info_ptr->spe_gp_save_offset - info_ptr->toc_size; | |
12018 | } | |
12019 | else if (TARGET_ALTIVEC_ABI) | |
00b960c7 AH |
12020 | { |
12021 | info_ptr->vrsave_save_offset | |
12022 | = info_ptr->cr_save_offset - info_ptr->vrsave_size; | |
12023 | ||
12024 | /* Align stack so vector save area is on a quadword boundary. */ | |
12025 | if (info_ptr->altivec_size != 0) | |
12026 | info_ptr->altivec_padding_size | |
12027 | = 16 - (-info_ptr->vrsave_save_offset % 16); | |
12028 | else | |
12029 | info_ptr->altivec_padding_size = 0; | |
12030 | ||
12031 | info_ptr->altivec_save_offset | |
12032 | = info_ptr->vrsave_save_offset | |
12033 | - info_ptr->altivec_padding_size | |
12034 | - info_ptr->altivec_size; | |
12035 | ||
12036 | /* Adjust for AltiVec case. */ | |
12037 | info_ptr->toc_save_offset | |
12038 | = info_ptr->altivec_save_offset - info_ptr->toc_size; | |
12039 | } | |
12040 | else | |
12041 | info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size; | |
83720594 | 12042 | info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size; |
b6c9286a MM |
12043 | info_ptr->lr_save_offset = reg_size; |
12044 | break; | |
4697a36c MM |
12045 | } |
12046 | ||
64045029 | 12047 | save_align = (TARGET_ALTIVEC_ABI || DEFAULT_ABI == ABI_DARWIN) ? 16 : 8; |
00b960c7 AH |
12048 | info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size |
12049 | + info_ptr->gp_size | |
12050 | + info_ptr->altivec_size | |
12051 | + info_ptr->altivec_padding_size | |
a3170dc6 AH |
12052 | + info_ptr->spe_gp_size |
12053 | + info_ptr->spe_padding_size | |
00b960c7 AH |
12054 | + ehrd_size |
12055 | + info_ptr->cr_size | |
12056 | + info_ptr->lr_size | |
12057 | + info_ptr->vrsave_size | |
12058 | + info_ptr->toc_size, | |
64045029 | 12059 | save_align); |
00b960c7 | 12060 | |
44688022 | 12061 | non_fixed_size = (info_ptr->vars_size |
ff381587 | 12062 | + info_ptr->parm_size |
ff381587 | 12063 | + info_ptr->save_size |
44688022 | 12064 | + info_ptr->varargs_size); |
ff381587 | 12065 | |
44688022 AM |
12066 | info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size, |
12067 | ABI_STACK_BOUNDARY / BITS_PER_UNIT); | |
ff381587 MM |
12068 | |
12069 | /* Determine if we need to allocate any stack frame: | |
12070 | ||
a4f6c312 SS |
12071 | For AIX we need to push the stack if a frame pointer is needed |
12072 | (because the stack might be dynamically adjusted), if we are | |
12073 | debugging, if we make calls, or if the sum of fp_save, gp_save, | |
12074 | and local variables are more than the space needed to save all | |
12075 | non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8 | |
12076 | + 18*8 = 288 (GPR13 reserved). | |
ff381587 | 12077 | |
a4f6c312 SS |
12078 | For V.4 we don't have the stack cushion that AIX uses, but assume |
12079 | that the debugger can handle stackless frames. */ | |
ff381587 MM |
12080 | |
12081 | if (info_ptr->calls_p) | |
12082 | info_ptr->push_p = 1; | |
12083 | ||
178274da | 12084 | else if (DEFAULT_ABI == ABI_V4) |
44688022 | 12085 | info_ptr->push_p = non_fixed_size != 0; |
ff381587 | 12086 | |
178274da AM |
12087 | else if (frame_pointer_needed) |
12088 | info_ptr->push_p = 1; | |
12089 | ||
12090 | else if (TARGET_XCOFF && write_symbols != NO_DEBUG) | |
12091 | info_ptr->push_p = 1; | |
12092 | ||
ff381587 | 12093 | else |
44688022 | 12094 | info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288); |
ff381587 | 12095 | |
a4f6c312 | 12096 | /* Zero offsets if we're not saving those registers. */ |
8dda1a21 | 12097 | if (info_ptr->fp_size == 0) |
4697a36c MM |
12098 | info_ptr->fp_save_offset = 0; |
12099 | ||
8dda1a21 | 12100 | if (info_ptr->gp_size == 0) |
4697a36c MM |
12101 | info_ptr->gp_save_offset = 0; |
12102 | ||
00b960c7 AH |
12103 | if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0) |
12104 | info_ptr->altivec_save_offset = 0; | |
12105 | ||
12106 | if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0) | |
12107 | info_ptr->vrsave_save_offset = 0; | |
12108 | ||
c19de7aa AH |
12109 | if (! TARGET_SPE_ABI |
12110 | || info_ptr->spe_64bit_regs_used == 0 | |
12111 | || info_ptr->spe_gp_size == 0) | |
a3170dc6 AH |
12112 | info_ptr->spe_gp_save_offset = 0; |
12113 | ||
c81fc13e | 12114 | if (! info_ptr->lr_save_p) |
4697a36c MM |
12115 | info_ptr->lr_save_offset = 0; |
12116 | ||
c81fc13e | 12117 | if (! info_ptr->cr_save_p) |
4697a36c MM |
12118 | info_ptr->cr_save_offset = 0; |
12119 | ||
c81fc13e | 12120 | if (! info_ptr->toc_save_p) |
b6c9286a MM |
12121 | info_ptr->toc_save_offset = 0; |
12122 | ||
4697a36c MM |
12123 | return info_ptr; |
12124 | } | |
12125 | ||
c19de7aa AH |
12126 | /* Return true if the current function uses any GPRs in 64-bit SIMD |
12127 | mode. */ | |
12128 | ||
12129 | static bool | |
863d938c | 12130 | spe_func_has_64bit_regs_p (void) |
c19de7aa AH |
12131 | { |
12132 | rtx insns, insn; | |
12133 | ||
12134 | /* Functions that save and restore all the call-saved registers will | |
12135 | need to save/restore the registers in 64-bits. */ | |
12136 | if (current_function_calls_eh_return | |
12137 | || current_function_calls_setjmp | |
12138 | || current_function_has_nonlocal_goto) | |
12139 | return true; | |
12140 | ||
12141 | insns = get_insns (); | |
12142 | ||
12143 | for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn)) | |
12144 | { | |
12145 | if (INSN_P (insn)) | |
12146 | { | |
12147 | rtx i; | |
12148 | ||
12149 | i = PATTERN (insn); | |
12150 | if (GET_CODE (i) == SET | |
12151 | && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i)))) | |
12152 | return true; | |
12153 | } | |
12154 | } | |
12155 | ||
12156 | return false; | |
12157 | } | |
12158 | ||
d1d0c603 | 12159 | static void |
a2369ed3 | 12160 | debug_stack_info (rs6000_stack_t *info) |
9878760c | 12161 | { |
d330fd93 | 12162 | const char *abi_string; |
24d304eb | 12163 | |
c81fc13e | 12164 | if (! info) |
4697a36c MM |
12165 | info = rs6000_stack_info (); |
12166 | ||
12167 | fprintf (stderr, "\nStack information for function %s:\n", | |
12168 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
12169 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
12170 | : "<unknown>")); | |
12171 | ||
24d304eb RK |
12172 | switch (info->abi) |
12173 | { | |
b6c9286a MM |
12174 | default: abi_string = "Unknown"; break; |
12175 | case ABI_NONE: abi_string = "NONE"; break; | |
50d440bc | 12176 | case ABI_AIX: abi_string = "AIX"; break; |
ee890fe2 | 12177 | case ABI_DARWIN: abi_string = "Darwin"; break; |
b6c9286a | 12178 | case ABI_V4: abi_string = "V.4"; break; |
24d304eb RK |
12179 | } |
12180 | ||
12181 | fprintf (stderr, "\tABI = %5s\n", abi_string); | |
12182 | ||
00b960c7 AH |
12183 | if (TARGET_ALTIVEC_ABI) |
12184 | fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n"); | |
12185 | ||
a3170dc6 AH |
12186 | if (TARGET_SPE_ABI) |
12187 | fprintf (stderr, "\tSPE ABI extensions enabled.\n"); | |
12188 | ||
4697a36c MM |
12189 | if (info->first_gp_reg_save != 32) |
12190 | fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save); | |
12191 | ||
12192 | if (info->first_fp_reg_save != 64) | |
12193 | fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save); | |
9878760c | 12194 | |
00b960c7 AH |
12195 | if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO) |
12196 | fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n", | |
12197 | info->first_altivec_reg_save); | |
12198 | ||
4697a36c MM |
12199 | if (info->lr_save_p) |
12200 | fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p); | |
9878760c | 12201 | |
4697a36c MM |
12202 | if (info->cr_save_p) |
12203 | fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p); | |
12204 | ||
b6c9286a MM |
12205 | if (info->toc_save_p) |
12206 | fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p); | |
12207 | ||
00b960c7 AH |
12208 | if (info->vrsave_mask) |
12209 | fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask); | |
12210 | ||
4697a36c MM |
12211 | if (info->push_p) |
12212 | fprintf (stderr, "\tpush_p = %5d\n", info->push_p); | |
12213 | ||
12214 | if (info->calls_p) | |
12215 | fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p); | |
12216 | ||
4697a36c MM |
12217 | if (info->gp_save_offset) |
12218 | fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset); | |
12219 | ||
12220 | if (info->fp_save_offset) | |
12221 | fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset); | |
12222 | ||
00b960c7 AH |
12223 | if (info->altivec_save_offset) |
12224 | fprintf (stderr, "\taltivec_save_offset = %5d\n", | |
12225 | info->altivec_save_offset); | |
12226 | ||
a3170dc6 AH |
12227 | if (info->spe_gp_save_offset) |
12228 | fprintf (stderr, "\tspe_gp_save_offset = %5d\n", | |
12229 | info->spe_gp_save_offset); | |
12230 | ||
00b960c7 AH |
12231 | if (info->vrsave_save_offset) |
12232 | fprintf (stderr, "\tvrsave_save_offset = %5d\n", | |
12233 | info->vrsave_save_offset); | |
12234 | ||
4697a36c MM |
12235 | if (info->lr_save_offset) |
12236 | fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset); | |
12237 | ||
12238 | if (info->cr_save_offset) | |
12239 | fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset); | |
12240 | ||
b6c9286a MM |
12241 | if (info->toc_save_offset) |
12242 | fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset); | |
12243 | ||
4697a36c MM |
12244 | if (info->varargs_save_offset) |
12245 | fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset); | |
12246 | ||
12247 | if (info->total_size) | |
d1d0c603 JJ |
12248 | fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
12249 | info->total_size); | |
4697a36c MM |
12250 | |
12251 | if (info->varargs_size) | |
12252 | fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size); | |
12253 | ||
12254 | if (info->vars_size) | |
d1d0c603 JJ |
12255 | fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n", |
12256 | info->vars_size); | |
4697a36c MM |
12257 | |
12258 | if (info->parm_size) | |
12259 | fprintf (stderr, "\tparm_size = %5d\n", info->parm_size); | |
12260 | ||
12261 | if (info->fixed_size) | |
12262 | fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size); | |
12263 | ||
12264 | if (info->gp_size) | |
12265 | fprintf (stderr, "\tgp_size = %5d\n", info->gp_size); | |
12266 | ||
a3170dc6 AH |
12267 | if (info->spe_gp_size) |
12268 | fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size); | |
12269 | ||
4697a36c MM |
12270 | if (info->fp_size) |
12271 | fprintf (stderr, "\tfp_size = %5d\n", info->fp_size); | |
12272 | ||
00b960c7 AH |
12273 | if (info->altivec_size) |
12274 | fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size); | |
12275 | ||
12276 | if (info->vrsave_size) | |
12277 | fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size); | |
12278 | ||
12279 | if (info->altivec_padding_size) | |
12280 | fprintf (stderr, "\taltivec_padding_size= %5d\n", | |
12281 | info->altivec_padding_size); | |
12282 | ||
a3170dc6 AH |
12283 | if (info->spe_padding_size) |
12284 | fprintf (stderr, "\tspe_padding_size = %5d\n", | |
12285 | info->spe_padding_size); | |
12286 | ||
a4f6c312 | 12287 | if (info->lr_size) |
ed947a96 | 12288 | fprintf (stderr, "\tlr_size = %5d\n", info->lr_size); |
b6c9286a | 12289 | |
4697a36c MM |
12290 | if (info->cr_size) |
12291 | fprintf (stderr, "\tcr_size = %5d\n", info->cr_size); | |
12292 | ||
a4f6c312 | 12293 | if (info->toc_size) |
b6c9286a MM |
12294 | fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size); |
12295 | ||
4697a36c MM |
12296 | if (info->save_size) |
12297 | fprintf (stderr, "\tsave_size = %5d\n", info->save_size); | |
12298 | ||
12299 | if (info->reg_size != 4) | |
12300 | fprintf (stderr, "\treg_size = %5d\n", info->reg_size); | |
12301 | ||
12302 | fprintf (stderr, "\n"); | |
9878760c | 12303 | } |
71f123ca FS |
12304 | |
12305 | rtx | |
a2369ed3 | 12306 | rs6000_return_addr (int count, rtx frame) |
71f123ca | 12307 | { |
a4f6c312 SS |
12308 | /* Currently we don't optimize very well between prolog and body |
12309 | code and for PIC code the code can be actually quite bad, so | |
12310 | don't try to be too clever here. */ | |
f1384257 | 12311 | if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic)) |
71f123ca FS |
12312 | { |
12313 | cfun->machine->ra_needs_full_frame = 1; | |
8ac61af7 RK |
12314 | |
12315 | return | |
12316 | gen_rtx_MEM | |
12317 | (Pmode, | |
12318 | memory_address | |
12319 | (Pmode, | |
12320 | plus_constant (copy_to_reg | |
12321 | (gen_rtx_MEM (Pmode, | |
12322 | memory_address (Pmode, frame))), | |
12323 | RETURN_ADDRESS_OFFSET))); | |
71f123ca FS |
12324 | } |
12325 | ||
8c29550d | 12326 | cfun->machine->ra_need_lr = 1; |
9e2f7ec7 | 12327 | return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM); |
71f123ca FS |
12328 | } |
12329 | ||
5e1bf043 DJ |
12330 | /* Say whether a function is a candidate for sibcall handling or not. |
12331 | We do not allow indirect calls to be optimized into sibling calls. | |
12332 | Also, we can't do it if there are any vector parameters; there's | |
12333 | nowhere to put the VRsave code so it works; note that functions with | |
12334 | vector parameters are required to have a prototype, so the argument | |
12335 | type info must be available here. (The tail recursion case can work | |
12336 | with vector parameters, but there's no way to distinguish here.) */ | |
4977bab6 | 12337 | static bool |
a2369ed3 | 12338 | rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) |
5e1bf043 DJ |
12339 | { |
12340 | tree type; | |
4977bab6 | 12341 | if (decl) |
5e1bf043 DJ |
12342 | { |
12343 | if (TARGET_ALTIVEC_VRSAVE) | |
12344 | { | |
4977bab6 | 12345 | for (type = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
5e1bf043 DJ |
12346 | type; type = TREE_CHAIN (type)) |
12347 | { | |
c15b529f | 12348 | if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE) |
4977bab6 | 12349 | return false; |
5e1bf043 DJ |
12350 | } |
12351 | } | |
12352 | if (DEFAULT_ABI == ABI_DARWIN | |
4977bab6 | 12353 | || (*targetm.binds_local_p) (decl)) |
2bcc50d0 | 12354 | { |
4977bab6 | 12355 | tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl)); |
2bcc50d0 AM |
12356 | |
12357 | if (!lookup_attribute ("longcall", attr_list) | |
12358 | || lookup_attribute ("shortcall", attr_list)) | |
4977bab6 | 12359 | return true; |
2bcc50d0 | 12360 | } |
5e1bf043 | 12361 | } |
4977bab6 | 12362 | return false; |
5e1bf043 DJ |
12363 | } |
12364 | ||
71f123ca | 12365 | static int |
863d938c | 12366 | rs6000_ra_ever_killed (void) |
71f123ca FS |
12367 | { |
12368 | rtx top; | |
5e1bf043 DJ |
12369 | rtx reg; |
12370 | rtx insn; | |
71f123ca | 12371 | |
dd292d0a | 12372 | if (current_function_is_thunk) |
71f123ca | 12373 | return 0; |
eb0424da | 12374 | |
36f7e964 AH |
12375 | /* regs_ever_live has LR marked as used if any sibcalls are present, |
12376 | but this should not force saving and restoring in the | |
12377 | pro/epilogue. Likewise, reg_set_between_p thinks a sibcall | |
a3c9585f | 12378 | clobbers LR, so that is inappropriate. */ |
36f7e964 | 12379 | |
5e1bf043 DJ |
12380 | /* Also, the prologue can generate a store into LR that |
12381 | doesn't really count, like this: | |
36f7e964 | 12382 | |
5e1bf043 DJ |
12383 | move LR->R0 |
12384 | bcl to set PIC register | |
12385 | move LR->R31 | |
12386 | move R0->LR | |
36f7e964 AH |
12387 | |
12388 | When we're called from the epilogue, we need to avoid counting | |
12389 | this as a store. */ | |
f676971a | 12390 | |
71f123ca FS |
12391 | push_topmost_sequence (); |
12392 | top = get_insns (); | |
12393 | pop_topmost_sequence (); | |
5e1bf043 | 12394 | reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); |
71f123ca | 12395 | |
5e1bf043 DJ |
12396 | for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn)) |
12397 | { | |
12398 | if (INSN_P (insn)) | |
12399 | { | |
12400 | if (FIND_REG_INC_NOTE (insn, reg)) | |
12401 | return 1; | |
f676971a | 12402 | else if (GET_CODE (insn) == CALL_INSN |
c15b529f | 12403 | && !SIBLING_CALL_P (insn)) |
5e1bf043 | 12404 | return 1; |
36f7e964 AH |
12405 | else if (set_of (reg, insn) != NULL_RTX |
12406 | && !prologue_epilogue_contains (insn)) | |
5e1bf043 DJ |
12407 | return 1; |
12408 | } | |
12409 | } | |
12410 | return 0; | |
71f123ca | 12411 | } |
4697a36c | 12412 | \f |
8cd8f856 GK |
12413 | /* Add a REG_MAYBE_DEAD note to the insn. */ |
12414 | static void | |
a2369ed3 | 12415 | rs6000_maybe_dead (rtx insn) |
8cd8f856 GK |
12416 | { |
12417 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD, | |
12418 | const0_rtx, | |
12419 | REG_NOTES (insn)); | |
12420 | } | |
12421 | ||
9ebbca7d | 12422 | /* Emit instructions needed to load the TOC register. |
c7ca610e | 12423 | This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is |
9ebbca7d | 12424 | a constant pool; or for SVR4 -fpic. */ |
c7ca610e RK |
12425 | |
12426 | void | |
a2369ed3 | 12427 | rs6000_emit_load_toc_table (int fromprolog) |
c7ca610e | 12428 | { |
027fbf43 | 12429 | rtx dest, insn; |
1db02437 | 12430 | dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM); |
c7ca610e | 12431 | |
20b71b17 AM |
12432 | if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1) |
12433 | { | |
12434 | rtx temp = (fromprolog | |
12435 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
12436 | : gen_reg_rtx (Pmode)); | |
027fbf43 JJ |
12437 | insn = emit_insn (gen_load_toc_v4_pic_si (temp)); |
12438 | if (fromprolog) | |
12439 | rs6000_maybe_dead (insn); | |
12440 | insn = emit_move_insn (dest, temp); | |
12441 | if (fromprolog) | |
12442 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
12443 | } |
12444 | else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2) | |
12445 | { | |
12446 | char buf[30]; | |
12447 | rtx tempLR = (fromprolog | |
12448 | ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM) | |
12449 | : gen_reg_rtx (Pmode)); | |
12450 | rtx temp0 = (fromprolog | |
12451 | ? gen_rtx_REG (Pmode, 0) | |
12452 | : gen_reg_rtx (Pmode)); | |
12453 | rtx symF; | |
12454 | ||
12455 | /* possibly create the toc section */ | |
12456 | if (! toc_initialized) | |
38c1f2d7 | 12457 | { |
20b71b17 AM |
12458 | toc_section (); |
12459 | function_section (current_function_decl); | |
38c1f2d7 | 12460 | } |
9ebbca7d | 12461 | |
20b71b17 AM |
12462 | if (fromprolog) |
12463 | { | |
12464 | rtx symL; | |
38c1f2d7 | 12465 | |
20b71b17 AM |
12466 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); |
12467 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
9ebbca7d | 12468 | |
20b71b17 AM |
12469 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno); |
12470 | symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
12471 | ||
12472 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR, | |
12473 | symF))); | |
12474 | rs6000_maybe_dead (emit_move_insn (dest, tempLR)); | |
12475 | rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, | |
12476 | symL, | |
12477 | symF))); | |
9ebbca7d GK |
12478 | } |
12479 | else | |
20b71b17 AM |
12480 | { |
12481 | rtx tocsym; | |
12482 | static int reload_toc_labelno = 0; | |
12483 | ||
12484 | tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name); | |
12485 | ||
12486 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++); | |
12487 | symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
12488 | ||
027fbf43 JJ |
12489 | emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym)); |
12490 | emit_move_insn (dest, tempLR); | |
12491 | emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest)); | |
20b71b17 | 12492 | } |
027fbf43 JJ |
12493 | insn = emit_insn (gen_addsi3 (dest, temp0, dest)); |
12494 | if (fromprolog) | |
12495 | rs6000_maybe_dead (insn); | |
9ebbca7d | 12496 | } |
20b71b17 AM |
12497 | else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC) |
12498 | { | |
12499 | /* This is for AIX code running in non-PIC ELF32. */ | |
12500 | char buf[30]; | |
12501 | rtx realsym; | |
12502 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
12503 | realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf)); | |
12504 | ||
027fbf43 JJ |
12505 | insn = emit_insn (gen_elf_high (dest, realsym)); |
12506 | if (fromprolog) | |
12507 | rs6000_maybe_dead (insn); | |
12508 | insn = emit_insn (gen_elf_low (dest, dest, realsym)); | |
12509 | if (fromprolog) | |
12510 | rs6000_maybe_dead (insn); | |
20b71b17 AM |
12511 | } |
12512 | else if (DEFAULT_ABI == ABI_AIX) | |
9ebbca7d GK |
12513 | { |
12514 | if (TARGET_32BIT) | |
027fbf43 | 12515 | insn = emit_insn (gen_load_toc_aix_si (dest)); |
9ebbca7d | 12516 | else |
027fbf43 JJ |
12517 | insn = emit_insn (gen_load_toc_aix_di (dest)); |
12518 | if (fromprolog) | |
12519 | rs6000_maybe_dead (insn); | |
9ebbca7d | 12520 | } |
20b71b17 AM |
12521 | else |
12522 | abort (); | |
9ebbca7d GK |
12523 | } |
12524 | ||
d1d0c603 JJ |
12525 | /* Emit instructions to restore the link register after determining where |
12526 | its value has been stored. */ | |
12527 | ||
12528 | void | |
12529 | rs6000_emit_eh_reg_restore (rtx source, rtx scratch) | |
12530 | { | |
12531 | rs6000_stack_t *info = rs6000_stack_info (); | |
12532 | rtx operands[2]; | |
12533 | ||
12534 | operands[0] = source; | |
12535 | operands[1] = scratch; | |
12536 | ||
12537 | if (info->lr_save_p) | |
12538 | { | |
12539 | rtx frame_rtx = stack_pointer_rtx; | |
12540 | HOST_WIDE_INT sp_offset = 0; | |
12541 | rtx tmp; | |
12542 | ||
12543 | if (frame_pointer_needed | |
12544 | || current_function_calls_alloca | |
12545 | || info->total_size > 32767) | |
12546 | { | |
12547 | emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx)); | |
12548 | frame_rtx = operands[1]; | |
12549 | } | |
12550 | else if (info->push_p) | |
12551 | sp_offset = info->total_size; | |
12552 | ||
12553 | tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset); | |
12554 | tmp = gen_rtx_MEM (Pmode, tmp); | |
12555 | emit_move_insn (tmp, operands[0]); | |
12556 | } | |
12557 | else | |
12558 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]); | |
12559 | } | |
12560 | ||
f103e34d GK |
12561 | static GTY(()) int set = -1; |
12562 | ||
f676971a | 12563 | int |
863d938c | 12564 | get_TOC_alias_set (void) |
9ebbca7d | 12565 | { |
f103e34d GK |
12566 | if (set == -1) |
12567 | set = new_alias_set (); | |
12568 | return set; | |
f676971a | 12569 | } |
9ebbca7d | 12570 | |
c1207243 | 12571 | /* This returns nonzero if the current function uses the TOC. This is |
3c9eb5f4 AM |
12572 | determined by the presence of (use (unspec ... UNSPEC_TOC)), which |
12573 | is generated by the ABI_V4 load_toc_* patterns. */ | |
c954844a | 12574 | #if TARGET_ELF |
3c9eb5f4 | 12575 | static int |
f676971a | 12576 | uses_TOC (void) |
9ebbca7d | 12577 | { |
c4501e62 | 12578 | rtx insn; |
38c1f2d7 | 12579 | |
c4501e62 JJ |
12580 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
12581 | if (INSN_P (insn)) | |
12582 | { | |
12583 | rtx pat = PATTERN (insn); | |
12584 | int i; | |
9ebbca7d | 12585 | |
f676971a | 12586 | if (GET_CODE (pat) == PARALLEL) |
c4501e62 JJ |
12587 | for (i = 0; i < XVECLEN (pat, 0); i++) |
12588 | { | |
12589 | rtx sub = XVECEXP (pat, 0, i); | |
12590 | if (GET_CODE (sub) == USE) | |
12591 | { | |
12592 | sub = XEXP (sub, 0); | |
12593 | if (GET_CODE (sub) == UNSPEC | |
12594 | && XINT (sub, 1) == UNSPEC_TOC) | |
12595 | return 1; | |
12596 | } | |
12597 | } | |
12598 | } | |
12599 | return 0; | |
9ebbca7d | 12600 | } |
c954844a | 12601 | #endif |
38c1f2d7 | 12602 | |
9ebbca7d | 12603 | rtx |
f676971a | 12604 | create_TOC_reference (rtx symbol) |
9ebbca7d | 12605 | { |
f676971a | 12606 | return gen_rtx_PLUS (Pmode, |
a8a05998 | 12607 | gen_rtx_REG (Pmode, TOC_REGISTER), |
f676971a EC |
12608 | gen_rtx_CONST (Pmode, |
12609 | gen_rtx_MINUS (Pmode, symbol, | |
b999aaeb | 12610 | gen_rtx_SYMBOL_REF (Pmode, toc_label_name)))); |
9ebbca7d | 12611 | } |
38c1f2d7 | 12612 | |
fc4767bb JJ |
12613 | /* If _Unwind_* has been called from within the same module, |
12614 | toc register is not guaranteed to be saved to 40(1) on function | |
12615 | entry. Save it there in that case. */ | |
c7ca610e | 12616 | |
9ebbca7d | 12617 | void |
863d938c | 12618 | rs6000_aix_emit_builtin_unwind_init (void) |
9ebbca7d GK |
12619 | { |
12620 | rtx mem; | |
12621 | rtx stack_top = gen_reg_rtx (Pmode); | |
12622 | rtx opcode_addr = gen_reg_rtx (Pmode); | |
fc4767bb JJ |
12623 | rtx opcode = gen_reg_rtx (SImode); |
12624 | rtx tocompare = gen_reg_rtx (SImode); | |
12625 | rtx no_toc_save_needed = gen_label_rtx (); | |
9ebbca7d GK |
12626 | |
12627 | mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx); | |
12628 | emit_move_insn (stack_top, mem); | |
12629 | ||
fc4767bb JJ |
12630 | mem = gen_rtx_MEM (Pmode, |
12631 | gen_rtx_PLUS (Pmode, stack_top, | |
9ebbca7d GK |
12632 | GEN_INT (2 * GET_MODE_SIZE (Pmode)))); |
12633 | emit_move_insn (opcode_addr, mem); | |
fc4767bb JJ |
12634 | emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr)); |
12635 | emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014 | |
2496c7bd | 12636 | : 0xE8410028, SImode)); |
9ebbca7d | 12637 | |
fc4767bb | 12638 | do_compare_rtx_and_jump (opcode, tocompare, EQ, 1, |
06f4e019 | 12639 | SImode, NULL_RTX, NULL_RTX, |
fc4767bb | 12640 | no_toc_save_needed); |
9ebbca7d | 12641 | |
fc4767bb JJ |
12642 | mem = gen_rtx_MEM (Pmode, |
12643 | gen_rtx_PLUS (Pmode, stack_top, | |
12644 | GEN_INT (5 * GET_MODE_SIZE (Pmode)))); | |
12645 | emit_move_insn (mem, gen_rtx_REG (Pmode, 2)); | |
12646 | emit_label (no_toc_save_needed); | |
9ebbca7d | 12647 | } |
38c1f2d7 | 12648 | \f |
ba4828e0 RK |
12649 | /* This ties together stack memory (MEM with an alias set of |
12650 | rs6000_sr_alias_set) and the change to the stack pointer. */ | |
12651 | ||
9ebbca7d | 12652 | static void |
863d938c | 12653 | rs6000_emit_stack_tie (void) |
9ebbca7d | 12654 | { |
ba4828e0 RK |
12655 | rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM)); |
12656 | ||
12657 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
12658 | emit_insn (gen_stack_tie (mem)); |
12659 | } | |
38c1f2d7 | 12660 | |
9ebbca7d GK |
12661 | /* Emit the correct code for allocating stack space, as insns. |
12662 | If COPY_R12, make sure a copy of the old frame is left in r12. | |
12663 | The generated code may use hard register 0 as a temporary. */ | |
12664 | ||
12665 | static void | |
a2369ed3 | 12666 | rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12) |
38c1f2d7 | 12667 | { |
9ebbca7d GK |
12668 | rtx insn; |
12669 | rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); | |
12670 | rtx tmp_reg = gen_rtx_REG (Pmode, 0); | |
12671 | rtx todec = GEN_INT (-size); | |
a157febd GK |
12672 | |
12673 | if (current_function_limit_stack) | |
12674 | { | |
12675 | if (REG_P (stack_limit_rtx) | |
f676971a | 12676 | && REGNO (stack_limit_rtx) > 1 |
a157febd GK |
12677 | && REGNO (stack_limit_rtx) <= 31) |
12678 | { | |
5b71a4e7 | 12679 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
12680 | ? gen_addsi3 (tmp_reg, |
12681 | stack_limit_rtx, | |
12682 | GEN_INT (size)) | |
12683 | : gen_adddi3 (tmp_reg, | |
12684 | stack_limit_rtx, | |
12685 | GEN_INT (size))); | |
5b71a4e7 | 12686 | |
9ebbca7d GK |
12687 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, |
12688 | const0_rtx)); | |
a157febd GK |
12689 | } |
12690 | else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF | |
9ebbca7d | 12691 | && TARGET_32BIT |
f607bc57 | 12692 | && DEFAULT_ABI == ABI_V4) |
a157febd | 12693 | { |
9ebbca7d | 12694 | rtx toload = gen_rtx_CONST (VOIDmode, |
f676971a EC |
12695 | gen_rtx_PLUS (Pmode, |
12696 | stack_limit_rtx, | |
9ebbca7d | 12697 | GEN_INT (size))); |
5b71a4e7 | 12698 | |
9ebbca7d GK |
12699 | emit_insn (gen_elf_high (tmp_reg, toload)); |
12700 | emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload)); | |
12701 | emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg, | |
12702 | const0_rtx)); | |
a157febd GK |
12703 | } |
12704 | else | |
12705 | warning ("stack limit expression is not supported"); | |
12706 | } | |
12707 | ||
9ebbca7d GK |
12708 | if (copy_r12 || ! TARGET_UPDATE) |
12709 | emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg); | |
12710 | ||
38c1f2d7 MM |
12711 | if (TARGET_UPDATE) |
12712 | { | |
9ebbca7d | 12713 | if (size > 32767) |
38c1f2d7 | 12714 | { |
9ebbca7d GK |
12715 | /* Need a note here so that try_split doesn't get confused. */ |
12716 | if (get_last_insn() == NULL_RTX) | |
2e040219 | 12717 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d GK |
12718 | insn = emit_move_insn (tmp_reg, todec); |
12719 | try_split (PATTERN (insn), insn, 0); | |
12720 | todec = tmp_reg; | |
38c1f2d7 | 12721 | } |
5b71a4e7 DE |
12722 | |
12723 | insn = emit_insn (TARGET_32BIT | |
12724 | ? gen_movsi_update (stack_reg, stack_reg, | |
12725 | todec, stack_reg) | |
2e6c9641 | 12726 | : gen_movdi_di_update (stack_reg, stack_reg, |
9ebbca7d | 12727 | todec, stack_reg)); |
38c1f2d7 MM |
12728 | } |
12729 | else | |
12730 | { | |
5b71a4e7 DE |
12731 | insn = emit_insn (TARGET_32BIT |
12732 | ? gen_addsi3 (stack_reg, stack_reg, todec) | |
12733 | : gen_adddi3 (stack_reg, stack_reg, todec)); | |
9ebbca7d GK |
12734 | emit_move_insn (gen_rtx_MEM (Pmode, stack_reg), |
12735 | gen_rtx_REG (Pmode, 12)); | |
12736 | } | |
f676971a | 12737 | |
9ebbca7d | 12738 | RTX_FRAME_RELATED_P (insn) = 1; |
f676971a | 12739 | REG_NOTES (insn) = |
9ebbca7d | 12740 | gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, |
f676971a | 12741 | gen_rtx_SET (VOIDmode, stack_reg, |
9ebbca7d GK |
12742 | gen_rtx_PLUS (Pmode, stack_reg, |
12743 | GEN_INT (-size))), | |
12744 | REG_NOTES (insn)); | |
12745 | } | |
12746 | ||
a4f6c312 SS |
12747 | /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced |
12748 | with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2 | |
12749 | is not NULL. It would be nice if dwarf2out_frame_debug_expr could | |
12750 | deduce these equivalences by itself so it wasn't necessary to hold | |
12751 | its hand so much. */ | |
9ebbca7d GK |
12752 | |
12753 | static void | |
f676971a | 12754 | rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val, |
a2369ed3 | 12755 | rtx reg2, rtx rreg) |
9ebbca7d GK |
12756 | { |
12757 | rtx real, temp; | |
12758 | ||
e56c4463 JL |
12759 | /* copy_rtx will not make unique copies of registers, so we need to |
12760 | ensure we don't have unwanted sharing here. */ | |
12761 | if (reg == reg2) | |
12762 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
12763 | ||
12764 | if (reg == rreg) | |
12765 | reg = gen_raw_REG (GET_MODE (reg), REGNO (reg)); | |
12766 | ||
9ebbca7d GK |
12767 | real = copy_rtx (PATTERN (insn)); |
12768 | ||
89e7058f AH |
12769 | if (reg2 != NULL_RTX) |
12770 | real = replace_rtx (real, reg2, rreg); | |
f676971a EC |
12771 | |
12772 | real = replace_rtx (real, reg, | |
9ebbca7d GK |
12773 | gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, |
12774 | STACK_POINTER_REGNUM), | |
12775 | GEN_INT (val))); | |
f676971a | 12776 | |
9ebbca7d GK |
12777 | /* We expect that 'real' is either a SET or a PARALLEL containing |
12778 | SETs (and possibly other stuff). In a PARALLEL, all the SETs | |
12779 | are important so they all have to be marked RTX_FRAME_RELATED_P. */ | |
12780 | ||
12781 | if (GET_CODE (real) == SET) | |
12782 | { | |
12783 | rtx set = real; | |
f676971a | 12784 | |
9ebbca7d GK |
12785 | temp = simplify_rtx (SET_SRC (set)); |
12786 | if (temp) | |
12787 | SET_SRC (set) = temp; | |
12788 | temp = simplify_rtx (SET_DEST (set)); | |
12789 | if (temp) | |
12790 | SET_DEST (set) = temp; | |
12791 | if (GET_CODE (SET_DEST (set)) == MEM) | |
38c1f2d7 | 12792 | { |
9ebbca7d GK |
12793 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); |
12794 | if (temp) | |
12795 | XEXP (SET_DEST (set), 0) = temp; | |
38c1f2d7 | 12796 | } |
38c1f2d7 | 12797 | } |
9ebbca7d GK |
12798 | else if (GET_CODE (real) == PARALLEL) |
12799 | { | |
12800 | int i; | |
12801 | for (i = 0; i < XVECLEN (real, 0); i++) | |
12802 | if (GET_CODE (XVECEXP (real, 0, i)) == SET) | |
12803 | { | |
12804 | rtx set = XVECEXP (real, 0, i); | |
f676971a | 12805 | |
9ebbca7d GK |
12806 | temp = simplify_rtx (SET_SRC (set)); |
12807 | if (temp) | |
12808 | SET_SRC (set) = temp; | |
12809 | temp = simplify_rtx (SET_DEST (set)); | |
12810 | if (temp) | |
12811 | SET_DEST (set) = temp; | |
12812 | if (GET_CODE (SET_DEST (set)) == MEM) | |
12813 | { | |
12814 | temp = simplify_rtx (XEXP (SET_DEST (set), 0)); | |
12815 | if (temp) | |
12816 | XEXP (SET_DEST (set), 0) = temp; | |
12817 | } | |
12818 | RTX_FRAME_RELATED_P (set) = 1; | |
12819 | } | |
12820 | } | |
12821 | else | |
a4f6c312 | 12822 | abort (); |
c19de7aa AH |
12823 | |
12824 | if (TARGET_SPE) | |
12825 | real = spe_synthesize_frame_save (real); | |
12826 | ||
9ebbca7d GK |
12827 | RTX_FRAME_RELATED_P (insn) = 1; |
12828 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
12829 | real, | |
12830 | REG_NOTES (insn)); | |
38c1f2d7 MM |
12831 | } |
12832 | ||
c19de7aa AH |
12833 | /* Given an SPE frame note, return a PARALLEL of SETs with the |
12834 | original note, plus a synthetic register save. */ | |
12835 | ||
12836 | static rtx | |
a2369ed3 | 12837 | spe_synthesize_frame_save (rtx real) |
c19de7aa AH |
12838 | { |
12839 | rtx synth, offset, reg, real2; | |
12840 | ||
12841 | if (GET_CODE (real) != SET | |
12842 | || GET_MODE (SET_SRC (real)) != V2SImode) | |
12843 | return real; | |
12844 | ||
12845 | /* For the SPE, registers saved in 64-bits, get a PARALLEL for their | |
12846 | frame related note. The parallel contains a set of the register | |
41f3a930 | 12847 | being saved, and another set to a synthetic register (n+1200). |
c19de7aa AH |
12848 | This is so we can differentiate between 64-bit and 32-bit saves. |
12849 | Words cannot describe this nastiness. */ | |
12850 | ||
12851 | if (GET_CODE (SET_DEST (real)) != MEM | |
12852 | || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS | |
12853 | || GET_CODE (SET_SRC (real)) != REG) | |
12854 | abort (); | |
12855 | ||
12856 | /* Transform: | |
12857 | (set (mem (plus (reg x) (const y))) | |
12858 | (reg z)) | |
12859 | into: | |
12860 | (set (mem (plus (reg x) (const y+4))) | |
41f3a930 | 12861 | (reg z+1200)) |
c19de7aa AH |
12862 | */ |
12863 | ||
12864 | real2 = copy_rtx (real); | |
12865 | PUT_MODE (SET_DEST (real2), SImode); | |
12866 | reg = SET_SRC (real2); | |
12867 | real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg))); | |
12868 | synth = copy_rtx (real2); | |
12869 | ||
12870 | if (BYTES_BIG_ENDIAN) | |
12871 | { | |
12872 | offset = XEXP (XEXP (SET_DEST (real2), 0), 1); | |
12873 | real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4)); | |
12874 | } | |
12875 | ||
12876 | reg = SET_SRC (synth); | |
41f3a930 | 12877 | |
c19de7aa | 12878 | synth = replace_rtx (synth, reg, |
41f3a930 | 12879 | gen_rtx_REG (SImode, REGNO (reg) + 1200)); |
c19de7aa AH |
12880 | |
12881 | offset = XEXP (XEXP (SET_DEST (synth), 0), 1); | |
12882 | synth = replace_rtx (synth, offset, | |
12883 | GEN_INT (INTVAL (offset) | |
12884 | + (BYTES_BIG_ENDIAN ? 0 : 4))); | |
12885 | ||
12886 | RTX_FRAME_RELATED_P (synth) = 1; | |
12887 | RTX_FRAME_RELATED_P (real2) = 1; | |
12888 | if (BYTES_BIG_ENDIAN) | |
12889 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2)); | |
12890 | else | |
12891 | real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth)); | |
12892 | ||
12893 | return real; | |
12894 | } | |
12895 | ||
00b960c7 AH |
12896 | /* Returns an insn that has a vrsave set operation with the |
12897 | appropriate CLOBBERs. */ | |
12898 | ||
12899 | static rtx | |
a2369ed3 | 12900 | generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep) |
00b960c7 AH |
12901 | { |
12902 | int nclobs, i; | |
12903 | rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1]; | |
a004eb82 | 12904 | rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
00b960c7 | 12905 | |
a004eb82 AH |
12906 | clobs[0] |
12907 | = gen_rtx_SET (VOIDmode, | |
12908 | vrsave, | |
12909 | gen_rtx_UNSPEC_VOLATILE (SImode, | |
12910 | gen_rtvec (2, reg, vrsave), | |
12911 | 30)); | |
00b960c7 AH |
12912 | |
12913 | nclobs = 1; | |
12914 | ||
9aa86737 AH |
12915 | /* We need to clobber the registers in the mask so the scheduler |
12916 | does not move sets to VRSAVE before sets of AltiVec registers. | |
12917 | ||
12918 | However, if the function receives nonlocal gotos, reload will set | |
12919 | all call saved registers live. We will end up with: | |
12920 | ||
12921 | (set (reg 999) (mem)) | |
12922 | (parallel [ (set (reg vrsave) (unspec blah)) | |
12923 | (clobber (reg 999))]) | |
12924 | ||
12925 | The clobber will cause the store into reg 999 to be dead, and | |
12926 | flow will attempt to delete an epilogue insn. In this case, we | |
12927 | need an unspec use/set of the register. */ | |
00b960c7 AH |
12928 | |
12929 | for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i) | |
44688022 | 12930 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) |
9aa86737 AH |
12931 | { |
12932 | if (!epiloguep || call_used_regs [i]) | |
12933 | clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode, | |
12934 | gen_rtx_REG (V4SImode, i)); | |
12935 | else | |
12936 | { | |
12937 | rtx reg = gen_rtx_REG (V4SImode, i); | |
9aa86737 AH |
12938 | |
12939 | clobs[nclobs++] | |
a004eb82 AH |
12940 | = gen_rtx_SET (VOIDmode, |
12941 | reg, | |
12942 | gen_rtx_UNSPEC (V4SImode, | |
12943 | gen_rtvec (1, reg), 27)); | |
9aa86737 AH |
12944 | } |
12945 | } | |
00b960c7 AH |
12946 | |
12947 | insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs)); | |
12948 | ||
12949 | for (i = 0; i < nclobs; ++i) | |
12950 | XVECEXP (insn, 0, i) = clobs[i]; | |
12951 | ||
12952 | return insn; | |
12953 | } | |
12954 | ||
89e7058f AH |
12955 | /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes. |
12956 | Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */ | |
12957 | ||
12958 | static void | |
f676971a | 12959 | emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode, |
d1d0c603 | 12960 | unsigned int regno, int offset, HOST_WIDE_INT total_size) |
89e7058f AH |
12961 | { |
12962 | rtx reg, offset_rtx, insn, mem, addr, int_rtx; | |
12963 | rtx replacea, replaceb; | |
12964 | ||
12965 | int_rtx = GEN_INT (offset); | |
12966 | ||
12967 | /* Some cases that need register indexed addressing. */ | |
12968 | if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode)) | |
a3170dc6 AH |
12969 | || (TARGET_SPE_ABI |
12970 | && SPE_VECTOR_MODE (mode) | |
12971 | && !SPE_CONST_OFFSET_OK (offset))) | |
89e7058f AH |
12972 | { |
12973 | /* Whomever calls us must make sure r11 is available in the | |
12974 | flow path of instructions in the prologue. */ | |
12975 | offset_rtx = gen_rtx_REG (Pmode, 11); | |
12976 | emit_move_insn (offset_rtx, int_rtx); | |
12977 | ||
12978 | replacea = offset_rtx; | |
12979 | replaceb = int_rtx; | |
12980 | } | |
12981 | else | |
12982 | { | |
12983 | offset_rtx = int_rtx; | |
12984 | replacea = NULL_RTX; | |
12985 | replaceb = NULL_RTX; | |
12986 | } | |
12987 | ||
12988 | reg = gen_rtx_REG (mode, regno); | |
12989 | addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx); | |
12990 | mem = gen_rtx_MEM (mode, addr); | |
12991 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
12992 | ||
12993 | insn = emit_move_insn (mem, reg); | |
12994 | ||
12995 | rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb); | |
12996 | } | |
12997 | ||
a3170dc6 AH |
12998 | /* Emit an offset memory reference suitable for a frame store, while |
12999 | converting to a valid addressing mode. */ | |
13000 | ||
13001 | static rtx | |
a2369ed3 | 13002 | gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset) |
a3170dc6 AH |
13003 | { |
13004 | rtx int_rtx, offset_rtx; | |
13005 | ||
13006 | int_rtx = GEN_INT (offset); | |
13007 | ||
13008 | if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode)) | |
13009 | { | |
13010 | offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
13011 | emit_move_insn (offset_rtx, int_rtx); | |
13012 | } | |
13013 | else | |
13014 | offset_rtx = int_rtx; | |
13015 | ||
13016 | return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx)); | |
13017 | } | |
13018 | ||
699c914a MS |
13019 | #ifndef TARGET_FIX_AND_CONTINUE |
13020 | #define TARGET_FIX_AND_CONTINUE 0 | |
13021 | #endif | |
13022 | ||
9ebbca7d GK |
13023 | /* Emit function prologue as insns. */ |
13024 | ||
9878760c | 13025 | void |
863d938c | 13026 | rs6000_emit_prologue (void) |
9878760c | 13027 | { |
4697a36c | 13028 | rs6000_stack_t *info = rs6000_stack_info (); |
0e67400a | 13029 | enum machine_mode reg_mode = Pmode; |
327e5343 | 13030 | int reg_size = TARGET_32BIT ? 4 : 8; |
9ebbca7d GK |
13031 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM); |
13032 | rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12); | |
13033 | rtx frame_reg_rtx = sp_reg_rtx; | |
b78d48dd | 13034 | rtx cr_save_rtx = NULL_RTX; |
9ebbca7d GK |
13035 | rtx insn; |
13036 | int saving_FPRs_inline; | |
13037 | int using_store_multiple; | |
13038 | HOST_WIDE_INT sp_offset = 0; | |
f676971a | 13039 | |
699c914a MS |
13040 | if (TARGET_FIX_AND_CONTINUE) |
13041 | { | |
13042 | /* gdb on darwin arranges to forward a function from the old | |
13043 | address by modifying the first 4 instructions of the function | |
13044 | to branch to the overriding function. This is necessary to | |
13045 | permit function pointers that point to the old function to | |
13046 | actually forward to the new function. */ | |
13047 | emit_insn (gen_nop ()); | |
13048 | emit_insn (gen_nop ()); | |
13049 | emit_insn (gen_nop ()); | |
13050 | emit_insn (gen_nop ()); | |
13051 | } | |
13052 | ||
13053 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) | |
13054 | { | |
13055 | reg_mode = V2SImode; | |
13056 | reg_size = 8; | |
13057 | } | |
a3170dc6 | 13058 | |
9ebbca7d | 13059 | using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
13060 | && (!TARGET_SPE_ABI |
13061 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
13062 | && info->first_gp_reg_save < 31); |
13063 | saving_FPRs_inline = (info->first_fp_reg_save == 64 | |
8c29550d | 13064 | || FP_SAVE_INLINE (info->first_fp_reg_save) |
acd0b319 | 13065 | || current_function_calls_eh_return |
8c29550d | 13066 | || cfun->machine->ra_need_lr); |
9ebbca7d GK |
13067 | |
13068 | /* For V.4, update stack before we do any saving and set back pointer. */ | |
fc4767bb | 13069 | if (info->push_p |
acd0b319 AM |
13070 | && (DEFAULT_ABI == ABI_V4 |
13071 | || current_function_calls_eh_return)) | |
9ebbca7d GK |
13072 | { |
13073 | if (info->total_size < 32767) | |
13074 | sp_offset = info->total_size; | |
13075 | else | |
13076 | frame_reg_rtx = frame_ptr_rtx; | |
f676971a | 13077 | rs6000_emit_allocate_stack (info->total_size, |
9ebbca7d GK |
13078 | (frame_reg_rtx != sp_reg_rtx |
13079 | && (info->cr_save_p | |
13080 | || info->lr_save_p | |
13081 | || info->first_fp_reg_save < 64 | |
13082 | || info->first_gp_reg_save < 32 | |
13083 | ))); | |
13084 | if (frame_reg_rtx != sp_reg_rtx) | |
13085 | rs6000_emit_stack_tie (); | |
13086 | } | |
13087 | ||
d62294f5 FJ |
13088 | /* Handle world saves specially here. */ |
13089 | if (info->world_save_p) | |
13090 | { | |
13091 | int i, j, sz; | |
13092 | rtx treg; | |
13093 | rtvec p; | |
13094 | ||
13095 | /* save_world expects lr in r0. */ | |
13096 | if (info->lr_save_p) | |
13097 | { | |
13098 | insn = emit_move_insn (gen_rtx_REG (Pmode, 0), | |
13099 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
13100 | RTX_FRAME_RELATED_P (insn) = 1; | |
13101 | } | |
13102 | ||
13103 | /* The SAVE_WORLD and RESTORE_WORLD routines make a number of | |
13104 | assumptions about the offsets of various bits of the stack | |
13105 | frame. Abort if things aren't what they should be. */ | |
13106 | if (info->gp_save_offset != -220 | |
13107 | || info->fp_save_offset != -144 | |
13108 | || info->lr_save_offset != 8 | |
13109 | || info->cr_save_offset != 4 | |
13110 | || !info->push_p | |
13111 | || !info->lr_save_p | |
13112 | || (current_function_calls_eh_return && info->ehrd_offset != -432) | |
13113 | || (info->vrsave_save_offset != -224 | |
13114 | || info->altivec_save_offset != (-224 -16 -192))) | |
13115 | abort (); | |
13116 | ||
13117 | treg = gen_rtx_REG (SImode, 11); | |
13118 | emit_move_insn (treg, GEN_INT (-info->total_size)); | |
13119 | ||
13120 | /* SAVE_WORLD takes the caller's LR in R0 and the frame size | |
13121 | in R11. It also clobbers R12, so beware! */ | |
13122 | ||
13123 | /* Preserve CR2 for save_world prologues */ | |
13124 | sz = 6; | |
13125 | sz += 32 - info->first_gp_reg_save; | |
13126 | sz += 64 - info->first_fp_reg_save; | |
13127 | sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1; | |
13128 | p = rtvec_alloc (sz); | |
13129 | j = 0; | |
13130 | RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, | |
13131 | gen_rtx_REG (Pmode, | |
13132 | LINK_REGISTER_REGNUM)); | |
13133 | RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, | |
13134 | gen_rtx_SYMBOL_REF (Pmode, | |
13135 | "*save_world")); | |
13136 | /* We do floats first so that the instruction pattern matches | |
13137 | properly. */ | |
13138 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
13139 | { | |
13140 | rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
13141 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13142 | GEN_INT (info->fp_save_offset | |
13143 | + sp_offset + 8 * i)); | |
13144 | rtx mem = gen_rtx_MEM (DFmode, addr); | |
13145 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13146 | ||
13147 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg); | |
13148 | } | |
13149 | for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++) | |
13150 | { | |
13151 | rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i); | |
13152 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13153 | GEN_INT (info->altivec_save_offset | |
13154 | + sp_offset + 16 * i)); | |
13155 | rtx mem = gen_rtx_MEM (V4SImode, addr); | |
13156 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13157 | ||
13158 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg); | |
13159 | } | |
13160 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
13161 | { | |
13162 | rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
13163 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13164 | GEN_INT (info->gp_save_offset | |
13165 | + sp_offset + reg_size * i)); | |
13166 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
13167 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13168 | ||
13169 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg); | |
13170 | } | |
13171 | ||
13172 | { | |
13173 | /* CR register traditionally saved as CR2. */ | |
13174 | rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO); | |
13175 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13176 | GEN_INT (info->cr_save_offset | |
13177 | + sp_offset)); | |
13178 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
13179 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13180 | ||
13181 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg); | |
13182 | } | |
13183 | /* Prevent any attempt to delete the setting of r0 and treg! */ | |
13184 | RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0)); | |
13185 | RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, treg); | |
13186 | RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, sp_reg_rtx); | |
13187 | ||
13188 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
13189 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
13190 | NULL_RTX, NULL_RTX); | |
13191 | ||
13192 | if (current_function_calls_eh_return) | |
13193 | { | |
13194 | unsigned int i; | |
13195 | for (i = 0; ; ++i) | |
13196 | { | |
13197 | unsigned int regno = EH_RETURN_DATA_REGNO (i); | |
13198 | if (regno == INVALID_REGNUM) | |
13199 | break; | |
13200 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno, | |
13201 | info->ehrd_offset + sp_offset | |
13202 | + reg_size * (int) i, | |
13203 | info->total_size); | |
13204 | } | |
13205 | } | |
13206 | } | |
13207 | ||
9aa86737 | 13208 | /* Save AltiVec registers if needed. */ |
d62294f5 | 13209 | if (! info->world_save_p && TARGET_ALTIVEC_ABI && info->altivec_size != 0) |
9aa86737 AH |
13210 | { |
13211 | int i; | |
13212 | ||
13213 | /* There should be a non inline version of this, for when we | |
13214 | are saving lots of vector registers. */ | |
13215 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
13216 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
13217 | { | |
13218 | rtx areg, savereg, mem; | |
13219 | int offset; | |
13220 | ||
13221 | offset = info->altivec_save_offset + sp_offset | |
13222 | + 16 * (i - info->first_altivec_reg_save); | |
13223 | ||
13224 | savereg = gen_rtx_REG (V4SImode, i); | |
13225 | ||
13226 | areg = gen_rtx_REG (Pmode, 0); | |
13227 | emit_move_insn (areg, GEN_INT (offset)); | |
13228 | ||
13229 | /* AltiVec addressing mode is [reg+reg]. */ | |
13230 | mem = gen_rtx_MEM (V4SImode, | |
13231 | gen_rtx_PLUS (Pmode, frame_reg_rtx, areg)); | |
f676971a | 13232 | |
9aa86737 AH |
13233 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
13234 | ||
13235 | insn = emit_move_insn (mem, savereg); | |
13236 | ||
5c242421 SB |
13237 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
13238 | areg, GEN_INT (offset)); | |
9aa86737 AH |
13239 | } |
13240 | } | |
13241 | ||
13242 | /* VRSAVE is a bit vector representing which AltiVec registers | |
13243 | are used. The OS uses this to determine which vector | |
13244 | registers to save on a context switch. We need to save | |
13245 | VRSAVE on the stack frame, add whatever AltiVec registers we | |
13246 | used in this function, and do the corresponding magic in the | |
13247 | epilogue. */ | |
13248 | ||
4d774ff8 | 13249 | if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE |
d62294f5 | 13250 | && ! info->world_save_p && info->vrsave_mask != 0) |
9aa86737 | 13251 | { |
a004eb82 | 13252 | rtx reg, mem, vrsave; |
9aa86737 AH |
13253 | int offset; |
13254 | ||
13255 | /* Get VRSAVE onto a GPR. */ | |
13256 | reg = gen_rtx_REG (SImode, 12); | |
a004eb82 | 13257 | vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO); |
b188f760 AH |
13258 | if (TARGET_MACHO) |
13259 | emit_insn (gen_get_vrsave_internal (reg)); | |
13260 | else | |
13261 | emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave)); | |
9aa86737 AH |
13262 | |
13263 | /* Save VRSAVE. */ | |
13264 | offset = info->vrsave_save_offset + sp_offset; | |
13265 | mem | |
13266 | = gen_rtx_MEM (SImode, | |
13267 | gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset))); | |
13268 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13269 | insn = emit_move_insn (mem, reg); | |
13270 | ||
13271 | /* Include the registers in the mask. */ | |
13272 | emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask))); | |
13273 | ||
13274 | insn = emit_insn (generate_set_vrsave (reg, info, 0)); | |
13275 | } | |
13276 | ||
9ebbca7d | 13277 | /* If we use the link register, get it into r0. */ |
d62294f5 | 13278 | if (! info->world_save_p && info->lr_save_p) |
f8a57be8 GK |
13279 | { |
13280 | insn = emit_move_insn (gen_rtx_REG (Pmode, 0), | |
13281 | gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)); | |
13282 | RTX_FRAME_RELATED_P (insn) = 1; | |
13283 | } | |
9ebbca7d GK |
13284 | |
13285 | /* If we need to save CR, put it into r12. */ | |
d62294f5 | 13286 | if (! info->world_save_p && info->cr_save_p && frame_reg_rtx != frame_ptr_rtx) |
9ebbca7d | 13287 | { |
f8a57be8 | 13288 | rtx set; |
f676971a | 13289 | |
9ebbca7d | 13290 | cr_save_rtx = gen_rtx_REG (SImode, 12); |
f8a57be8 GK |
13291 | insn = emit_insn (gen_movesi_from_cr (cr_save_rtx)); |
13292 | RTX_FRAME_RELATED_P (insn) = 1; | |
13293 | /* Now, there's no way that dwarf2out_frame_debug_expr is going | |
13294 | to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'. | |
13295 | But that's OK. All we have to do is specify that _one_ condition | |
13296 | code register is saved in this stack slot. The thrower's epilogue | |
13297 | will then restore all the call-saved registers. | |
13298 | We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */ | |
13299 | set = gen_rtx_SET (VOIDmode, cr_save_rtx, | |
13300 | gen_rtx_REG (SImode, CR2_REGNO)); | |
13301 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
13302 | set, | |
13303 | REG_NOTES (insn)); | |
9ebbca7d GK |
13304 | } |
13305 | ||
a4f6c312 SS |
13306 | /* Do any required saving of fpr's. If only one or two to save, do |
13307 | it ourselves. Otherwise, call function. */ | |
d62294f5 | 13308 | if (! info->world_save_p && saving_FPRs_inline) |
9ebbca7d GK |
13309 | { |
13310 | int i; | |
13311 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
f676971a | 13312 | if ((regs_ever_live[info->first_fp_reg_save+i] |
9ebbca7d | 13313 | && ! call_used_regs[info->first_fp_reg_save+i])) |
89e7058f AH |
13314 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode, |
13315 | info->first_fp_reg_save + i, | |
13316 | info->fp_save_offset + sp_offset + 8 * i, | |
13317 | info->total_size); | |
9ebbca7d | 13318 | } |
d62294f5 | 13319 | else if (! info->world_save_p && info->first_fp_reg_save != 64) |
9ebbca7d GK |
13320 | { |
13321 | int i; | |
13322 | char rname[30]; | |
520a57c8 | 13323 | const char *alloc_rname; |
9ebbca7d GK |
13324 | rtvec p; |
13325 | p = rtvec_alloc (2 + 64 - info->first_fp_reg_save); | |
f676971a EC |
13326 | |
13327 | RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode, | |
13328 | gen_rtx_REG (Pmode, | |
9ebbca7d GK |
13329 | LINK_REGISTER_REGNUM)); |
13330 | sprintf (rname, "%s%d%s", SAVE_FP_PREFIX, | |
13331 | info->first_fp_reg_save - 32, SAVE_FP_SUFFIX); | |
a8a05998 | 13332 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
13333 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
13334 | gen_rtx_SYMBOL_REF (Pmode, | |
13335 | alloc_rname)); | |
13336 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
13337 | { | |
13338 | rtx addr, reg, mem; | |
13339 | reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
13340 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
f676971a | 13341 | GEN_INT (info->fp_save_offset |
9ebbca7d GK |
13342 | + sp_offset + 8*i)); |
13343 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 13344 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
13345 | |
13346 | RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg); | |
13347 | } | |
13348 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
f676971a | 13349 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
9ebbca7d GK |
13350 | NULL_RTX, NULL_RTX); |
13351 | } | |
b6c9286a | 13352 | |
9ebbca7d GK |
13353 | /* Save GPRs. This is done as a PARALLEL if we are using |
13354 | the store-multiple instructions. */ | |
d62294f5 | 13355 | if (! info->world_save_p && using_store_multiple) |
b6c9286a | 13356 | { |
308c142a | 13357 | rtvec p; |
9ebbca7d GK |
13358 | int i; |
13359 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
9ebbca7d GK |
13360 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) |
13361 | { | |
13362 | rtx addr, reg, mem; | |
13363 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
f676971a EC |
13364 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
13365 | GEN_INT (info->gp_save_offset | |
13366 | + sp_offset | |
9ebbca7d GK |
13367 | + reg_size * i)); |
13368 | mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 13369 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d GK |
13370 | |
13371 | RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg); | |
13372 | } | |
13373 | insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
f676971a | 13374 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
9ebbca7d | 13375 | NULL_RTX, NULL_RTX); |
b6c9286a | 13376 | } |
d62294f5 | 13377 | else if (! info->world_save_p) |
b6c9286a | 13378 | { |
9ebbca7d GK |
13379 | int i; |
13380 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
f676971a | 13381 | if ((regs_ever_live[info->first_gp_reg_save+i] |
b4db40bf JJ |
13382 | && (! call_used_regs[info->first_gp_reg_save+i] |
13383 | || (i+info->first_gp_reg_save | |
13384 | == RS6000_PIC_OFFSET_TABLE_REGNUM | |
13385 | && TARGET_TOC && TARGET_MINIMAL_TOC))) | |
1db02437 | 13386 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 13387 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 13388 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
a3170dc6 AH |
13389 | { |
13390 | rtx addr, reg, mem; | |
13391 | reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
13392 | ||
c19de7aa | 13393 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
13394 | { |
13395 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
13396 | rtx b; | |
13397 | ||
13398 | if (!SPE_CONST_OFFSET_OK (offset)) | |
13399 | { | |
13400 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
13401 | emit_move_insn (b, GEN_INT (offset)); | |
13402 | } | |
13403 | else | |
13404 | b = GEN_INT (offset); | |
13405 | ||
13406 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
13407 | mem = gen_rtx_MEM (V2SImode, addr); | |
13408 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13409 | insn = emit_move_insn (mem, reg); | |
13410 | ||
13411 | if (GET_CODE (b) == CONST_INT) | |
13412 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
13413 | NULL_RTX, NULL_RTX); | |
13414 | else | |
13415 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, | |
13416 | b, GEN_INT (offset)); | |
13417 | } | |
13418 | else | |
13419 | { | |
f676971a EC |
13420 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
13421 | GEN_INT (info->gp_save_offset | |
13422 | + sp_offset | |
a3170dc6 AH |
13423 | + reg_size * i)); |
13424 | mem = gen_rtx_MEM (reg_mode, addr); | |
13425 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13426 | ||
13427 | insn = emit_move_insn (mem, reg); | |
f676971a | 13428 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
a3170dc6 AH |
13429 | NULL_RTX, NULL_RTX); |
13430 | } | |
13431 | } | |
9ebbca7d GK |
13432 | } |
13433 | ||
83720594 RH |
13434 | /* ??? There's no need to emit actual instructions here, but it's the |
13435 | easiest way to get the frame unwind information emitted. */ | |
d62294f5 | 13436 | if (! info->world_save_p && current_function_calls_eh_return) |
83720594 | 13437 | { |
78e1b90d DE |
13438 | unsigned int i, regno; |
13439 | ||
fc4767bb JJ |
13440 | /* In AIX ABI we need to pretend we save r2 here. */ |
13441 | if (TARGET_AIX) | |
13442 | { | |
13443 | rtx addr, reg, mem; | |
13444 | ||
13445 | reg = gen_rtx_REG (reg_mode, 2); | |
13446 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13447 | GEN_INT (sp_offset + 5 * reg_size)); | |
13448 | mem = gen_rtx_MEM (reg_mode, addr); | |
13449 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13450 | ||
13451 | insn = emit_move_insn (mem, reg); | |
f676971a | 13452 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
fc4767bb JJ |
13453 | NULL_RTX, NULL_RTX); |
13454 | PATTERN (insn) = gen_blockage (); | |
13455 | } | |
13456 | ||
83720594 RH |
13457 | for (i = 0; ; ++i) |
13458 | { | |
83720594 RH |
13459 | regno = EH_RETURN_DATA_REGNO (i); |
13460 | if (regno == INVALID_REGNUM) | |
13461 | break; | |
13462 | ||
89e7058f AH |
13463 | emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno, |
13464 | info->ehrd_offset + sp_offset | |
13465 | + reg_size * (int) i, | |
13466 | info->total_size); | |
83720594 RH |
13467 | } |
13468 | } | |
13469 | ||
9ebbca7d | 13470 | /* Save lr if we used it. */ |
d62294f5 | 13471 | if (! info->world_save_p && info->lr_save_p) |
9ebbca7d GK |
13472 | { |
13473 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13474 | GEN_INT (info->lr_save_offset + sp_offset)); | |
13475 | rtx reg = gen_rtx_REG (Pmode, 0); | |
13476 | rtx mem = gen_rtx_MEM (Pmode, addr); | |
13477 | /* This should not be of rs6000_sr_alias_set, because of | |
13478 | __builtin_return_address. */ | |
f676971a | 13479 | |
9ebbca7d | 13480 | insn = emit_move_insn (mem, reg); |
f676971a | 13481 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
f8a57be8 | 13482 | NULL_RTX, NULL_RTX); |
9ebbca7d GK |
13483 | } |
13484 | ||
13485 | /* Save CR if we use any that must be preserved. */ | |
d62294f5 | 13486 | if (! info->world_save_p && info->cr_save_p) |
9ebbca7d GK |
13487 | { |
13488 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13489 | GEN_INT (info->cr_save_offset + sp_offset)); | |
13490 | rtx mem = gen_rtx_MEM (SImode, addr); | |
f8a57be8 GK |
13491 | /* See the large comment above about why CR2_REGNO is used. */ |
13492 | rtx magic_eh_cr_reg = gen_rtx_REG (SImode, CR2_REGNO); | |
ba4828e0 RK |
13493 | |
13494 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d GK |
13495 | |
13496 | /* If r12 was used to hold the original sp, copy cr into r0 now | |
13497 | that it's free. */ | |
13498 | if (REGNO (frame_reg_rtx) == 12) | |
13499 | { | |
f8a57be8 GK |
13500 | rtx set; |
13501 | ||
9ebbca7d | 13502 | cr_save_rtx = gen_rtx_REG (SImode, 0); |
f8a57be8 GK |
13503 | insn = emit_insn (gen_movesi_from_cr (cr_save_rtx)); |
13504 | RTX_FRAME_RELATED_P (insn) = 1; | |
13505 | set = gen_rtx_SET (VOIDmode, cr_save_rtx, magic_eh_cr_reg); | |
13506 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
13507 | set, | |
13508 | REG_NOTES (insn)); | |
f676971a | 13509 | |
9ebbca7d GK |
13510 | } |
13511 | insn = emit_move_insn (mem, cr_save_rtx); | |
13512 | ||
f676971a | 13513 | rs6000_frame_related (insn, frame_ptr_rtx, info->total_size, |
f8a57be8 | 13514 | NULL_RTX, NULL_RTX); |
9ebbca7d GK |
13515 | } |
13516 | ||
f676971a | 13517 | /* Update stack and set back pointer unless this is V.4, |
9ebbca7d | 13518 | for which it was done previously. */ |
d62294f5 | 13519 | if (! info->world_save_p && info->push_p |
fc4767bb | 13520 | && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return)) |
9ebbca7d GK |
13521 | rs6000_emit_allocate_stack (info->total_size, FALSE); |
13522 | ||
13523 | /* Set frame pointer, if needed. */ | |
13524 | if (frame_pointer_needed) | |
13525 | { | |
f676971a | 13526 | insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM), |
9ebbca7d GK |
13527 | sp_reg_rtx); |
13528 | RTX_FRAME_RELATED_P (insn) = 1; | |
b6c9286a | 13529 | } |
9878760c | 13530 | |
1db02437 | 13531 | /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */ |
9ebbca7d | 13532 | if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0) |
f607bc57 | 13533 | || (DEFAULT_ABI == ABI_V4 && flag_pic == 1 |
1db02437 | 13534 | && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])) |
9ebbca7d GK |
13535 | { |
13536 | /* If emit_load_toc_table will use the link register, we need to save | |
c4501e62 | 13537 | it. We use R12 for this purpose because emit_load_toc_table |
9ebbca7d GK |
13538 | can use register 0. This allows us to use a plain 'blr' to return |
13539 | from the procedure more often. */ | |
f1384257 AM |
13540 | int save_LR_around_toc_setup = (TARGET_ELF |
13541 | && DEFAULT_ABI != ABI_AIX | |
13542 | && flag_pic | |
d5fa86ba GK |
13543 | && ! info->lr_save_p |
13544 | && EXIT_BLOCK_PTR->pred != NULL); | |
9ebbca7d | 13545 | if (save_LR_around_toc_setup) |
c4501e62 JJ |
13546 | { |
13547 | rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); | |
f8a57be8 GK |
13548 | |
13549 | insn = emit_move_insn (frame_ptr_rtx, lr); | |
13550 | rs6000_maybe_dead (insn); | |
13551 | RTX_FRAME_RELATED_P (insn) = 1; | |
13552 | ||
c4501e62 | 13553 | rs6000_emit_load_toc_table (TRUE); |
f8a57be8 GK |
13554 | |
13555 | insn = emit_move_insn (lr, frame_ptr_rtx); | |
13556 | rs6000_maybe_dead (insn); | |
13557 | RTX_FRAME_RELATED_P (insn) = 1; | |
c4501e62 JJ |
13558 | } |
13559 | else | |
13560 | rs6000_emit_load_toc_table (TRUE); | |
9ebbca7d | 13561 | } |
ee890fe2 | 13562 | |
fcce224d | 13563 | #if TARGET_MACHO |
ee890fe2 SS |
13564 | if (DEFAULT_ABI == ABI_DARWIN |
13565 | && flag_pic && current_function_uses_pic_offset_table) | |
13566 | { | |
f8a57be8 | 13567 | rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM); |
11abc112 | 13568 | rtx src = machopic_function_base_sym (); |
ee890fe2 | 13569 | |
f8a57be8 | 13570 | rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (lr, src))); |
ee890fe2 | 13571 | |
f676971a | 13572 | insn = emit_move_insn (gen_rtx_REG (Pmode, |
f8a57be8 GK |
13573 | RS6000_PIC_OFFSET_TABLE_REGNUM), |
13574 | lr); | |
13575 | rs6000_maybe_dead (insn); | |
ee890fe2 | 13576 | } |
fcce224d | 13577 | #endif |
9ebbca7d GK |
13578 | } |
13579 | ||
9ebbca7d | 13580 | /* Write function prologue. */ |
a4f6c312 | 13581 | |
08c148a8 | 13582 | static void |
f676971a | 13583 | rs6000_output_function_prologue (FILE *file, |
a2369ed3 | 13584 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) |
9ebbca7d GK |
13585 | { |
13586 | rs6000_stack_t *info = rs6000_stack_info (); | |
13587 | ||
4697a36c MM |
13588 | if (TARGET_DEBUG_STACK) |
13589 | debug_stack_info (info); | |
9878760c | 13590 | |
a4f6c312 SS |
13591 | /* Write .extern for any function we will call to save and restore |
13592 | fp values. */ | |
13593 | if (info->first_fp_reg_save < 64 | |
13594 | && !FP_SAVE_INLINE (info->first_fp_reg_save)) | |
4d30c363 | 13595 | fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n", |
4697a36c | 13596 | SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX, |
a4f6c312 SS |
13597 | RESTORE_FP_PREFIX, info->first_fp_reg_save - 32, |
13598 | RESTORE_FP_SUFFIX); | |
9878760c | 13599 | |
c764f757 RK |
13600 | /* Write .extern for AIX common mode routines, if needed. */ |
13601 | if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined) | |
13602 | { | |
f6709c70 JW |
13603 | fputs ("\t.extern __mulh\n", file); |
13604 | fputs ("\t.extern __mull\n", file); | |
13605 | fputs ("\t.extern __divss\n", file); | |
13606 | fputs ("\t.extern __divus\n", file); | |
13607 | fputs ("\t.extern __quoss\n", file); | |
13608 | fputs ("\t.extern __quous\n", file); | |
c764f757 RK |
13609 | common_mode_defined = 1; |
13610 | } | |
9878760c | 13611 | |
9ebbca7d | 13612 | if (! HAVE_prologue) |
979721f8 | 13613 | { |
9ebbca7d | 13614 | start_sequence (); |
9dda4cc8 | 13615 | |
a4f6c312 SS |
13616 | /* A NOTE_INSN_DELETED is supposed to be at the start and end of |
13617 | the "toplevel" insn chain. */ | |
2e040219 | 13618 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 13619 | rs6000_emit_prologue (); |
2e040219 | 13620 | emit_note (NOTE_INSN_DELETED); |
178c3eff | 13621 | |
a3c9585f | 13622 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
178c3eff DJ |
13623 | { |
13624 | rtx insn; | |
13625 | unsigned addr = 0; | |
13626 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
13627 | { | |
13628 | INSN_ADDRESSES_NEW (insn, addr); | |
13629 | addr += 4; | |
13630 | } | |
13631 | } | |
9dda4cc8 | 13632 | |
9ebbca7d | 13633 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
13634 | debug_rtx_list (get_insns (), 100); |
13635 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 13636 | end_sequence (); |
979721f8 MM |
13637 | } |
13638 | ||
9ebbca7d GK |
13639 | rs6000_pic_labelno++; |
13640 | } | |
f676971a | 13641 | |
9ebbca7d | 13642 | /* Emit function epilogue as insns. |
9878760c | 13643 | |
9ebbca7d GK |
13644 | At present, dwarf2out_frame_debug_expr doesn't understand |
13645 | register restores, so we don't bother setting RTX_FRAME_RELATED_P | |
13646 | anywhere in the epilogue. Most of the insns below would in any case | |
13647 | need special notes to explain where r11 is in relation to the stack. */ | |
9878760c | 13648 | |
9ebbca7d | 13649 | void |
a2369ed3 | 13650 | rs6000_emit_epilogue (int sibcall) |
9ebbca7d GK |
13651 | { |
13652 | rs6000_stack_t *info; | |
13653 | int restoring_FPRs_inline; | |
13654 | int using_load_multiple; | |
13655 | int using_mfcr_multiple; | |
13656 | int use_backchain_to_restore_sp; | |
13657 | int sp_offset = 0; | |
13658 | rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1); | |
13659 | rtx frame_reg_rtx = sp_reg_rtx; | |
0e67400a | 13660 | enum machine_mode reg_mode = Pmode; |
327e5343 | 13661 | int reg_size = TARGET_32BIT ? 4 : 8; |
9ebbca7d GK |
13662 | int i; |
13663 | ||
c19de7aa AH |
13664 | info = rs6000_stack_info (); |
13665 | ||
13666 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) | |
a3170dc6 AH |
13667 | { |
13668 | reg_mode = V2SImode; | |
13669 | reg_size = 8; | |
13670 | } | |
13671 | ||
9ebbca7d | 13672 | using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64 |
c19de7aa AH |
13673 | && (!TARGET_SPE_ABI |
13674 | || info->spe_64bit_regs_used == 0) | |
9ebbca7d GK |
13675 | && info->first_gp_reg_save < 31); |
13676 | restoring_FPRs_inline = (sibcall | |
83720594 | 13677 | || current_function_calls_eh_return |
9ebbca7d GK |
13678 | || info->first_fp_reg_save == 64 |
13679 | || FP_SAVE_INLINE (info->first_fp_reg_save)); | |
f676971a | 13680 | use_backchain_to_restore_sp = (frame_pointer_needed |
9ebbca7d GK |
13681 | || current_function_calls_alloca |
13682 | || info->total_size > 32767); | |
13683 | using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601 | |
13684 | || rs6000_cpu == PROCESSOR_PPC603 | |
13685 | || rs6000_cpu == PROCESSOR_PPC750 | |
13686 | || optimize_size); | |
13687 | ||
d62294f5 FJ |
13688 | if (info->world_save_p) |
13689 | { | |
13690 | int i, j; | |
13691 | char rname[30]; | |
13692 | const char *alloc_rname; | |
13693 | rtvec p; | |
13694 | ||
13695 | /* eh_rest_world_r10 will return to the location saved in the LR | |
13696 | stack slot (which is not likely to be our caller.) | |
13697 | Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8. | |
13698 | rest_world is similar, except any R10 parameter is ignored. | |
13699 | The exception-handling stuff that was here in 2.95 is no | |
13700 | longer necessary. */ | |
13701 | ||
13702 | p = rtvec_alloc (9 | |
13703 | + 1 | |
f676971a | 13704 | + 32 - info->first_gp_reg_save |
d62294f5 FJ |
13705 | + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save |
13706 | + 63 + 1 - info->first_fp_reg_save); | |
13707 | ||
13708 | strcpy (rname, (current_function_calls_eh_return) ? | |
13709 | "*eh_rest_world_r10" : "*rest_world"); | |
13710 | alloc_rname = ggc_strdup (rname); | |
13711 | ||
13712 | j = 0; | |
13713 | RTVEC_ELT (p, j++) = gen_rtx_RETURN (VOIDmode); | |
13714 | RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, | |
13715 | gen_rtx_REG (Pmode, | |
13716 | LINK_REGISTER_REGNUM)); | |
13717 | RTVEC_ELT (p, j++) | |
13718 | = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname)); | |
13719 | /* The instruction pattern requires a clobber here; | |
13720 | it is shared with the restVEC helper. */ | |
13721 | RTVEC_ELT (p, j++) | |
13722 | = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11)); | |
13723 | ||
13724 | { | |
13725 | /* CR register traditionally saved as CR2. */ | |
13726 | rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO); | |
13727 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13728 | GEN_INT (info->cr_save_offset)); | |
13729 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
13730 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13731 | ||
13732 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem); | |
13733 | } | |
13734 | ||
13735 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
13736 | { | |
13737 | rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i); | |
13738 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13739 | GEN_INT (info->gp_save_offset | |
13740 | + reg_size * i)); | |
13741 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
13742 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13743 | ||
13744 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem); | |
13745 | } | |
13746 | for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++) | |
13747 | { | |
13748 | rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i); | |
13749 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13750 | GEN_INT (info->altivec_save_offset | |
13751 | + 16 * i)); | |
13752 | rtx mem = gen_rtx_MEM (V4SImode, addr); | |
13753 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13754 | ||
13755 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem); | |
13756 | } | |
13757 | for (i = 0; info->first_fp_reg_save + i <= 63; i++) | |
13758 | { | |
13759 | rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i); | |
13760 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13761 | GEN_INT (info->fp_save_offset | |
13762 | + 8 * i)); | |
13763 | rtx mem = gen_rtx_MEM (DFmode, addr); | |
13764 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13765 | ||
13766 | RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem); | |
13767 | } | |
13768 | RTVEC_ELT (p, j++) | |
13769 | = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0)); | |
13770 | RTVEC_ELT (p, j++) | |
13771 | = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12)); | |
13772 | RTVEC_ELT (p, j++) | |
13773 | = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7)); | |
13774 | RTVEC_ELT (p, j++) | |
13775 | = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8)); | |
13776 | RTVEC_ELT (p, j++) | |
13777 | = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10)); | |
13778 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
13779 | ||
13780 | return; | |
13781 | } | |
13782 | ||
9ebbca7d GK |
13783 | /* If we have a frame pointer, a call to alloca, or a large stack |
13784 | frame, restore the old stack pointer using the backchain. Otherwise, | |
13785 | we know what size to update it with. */ | |
13786 | if (use_backchain_to_restore_sp) | |
bacbde18 | 13787 | { |
9ebbca7d GK |
13788 | /* Under V.4, don't reset the stack pointer until after we're done |
13789 | loading the saved registers. */ | |
f607bc57 | 13790 | if (DEFAULT_ABI == ABI_V4) |
9ebbca7d | 13791 | frame_reg_rtx = gen_rtx_REG (Pmode, 11); |
4697a36c | 13792 | |
9ebbca7d GK |
13793 | emit_move_insn (frame_reg_rtx, |
13794 | gen_rtx_MEM (Pmode, sp_reg_rtx)); | |
f676971a | 13795 | |
bacbde18 | 13796 | } |
9ebbca7d | 13797 | else if (info->push_p) |
85638c0d | 13798 | { |
fc4767bb JJ |
13799 | if (DEFAULT_ABI == ABI_V4 |
13800 | || current_function_calls_eh_return) | |
9ebbca7d GK |
13801 | sp_offset = info->total_size; |
13802 | else | |
13803 | { | |
13804 | emit_insn (TARGET_32BIT | |
13805 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, | |
13806 | GEN_INT (info->total_size)) | |
13807 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
13808 | GEN_INT (info->total_size))); | |
13809 | } | |
85638c0d | 13810 | } |
f676971a | 13811 | |
9aa86737 AH |
13812 | /* Restore AltiVec registers if needed. */ |
13813 | if (TARGET_ALTIVEC_ABI && info->altivec_size != 0) | |
13814 | { | |
13815 | int i; | |
13816 | ||
13817 | for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i) | |
13818 | if (info->vrsave_mask & ALTIVEC_REG_BIT (i)) | |
13819 | { | |
13820 | rtx addr, areg, mem; | |
13821 | ||
13822 | areg = gen_rtx_REG (Pmode, 0); | |
13823 | emit_move_insn | |
13824 | (areg, GEN_INT (info->altivec_save_offset | |
13825 | + sp_offset | |
13826 | + 16 * (i - info->first_altivec_reg_save))); | |
13827 | ||
13828 | /* AltiVec addressing mode is [reg+reg]. */ | |
13829 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg); | |
13830 | mem = gen_rtx_MEM (V4SImode, addr); | |
13831 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13832 | ||
13833 | emit_move_insn (gen_rtx_REG (V4SImode, i), mem); | |
13834 | } | |
13835 | } | |
13836 | ||
13837 | /* Restore VRSAVE if needed. */ | |
44688022 | 13838 | if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE |
4d774ff8 | 13839 | && info->vrsave_mask != 0) |
9aa86737 AH |
13840 | { |
13841 | rtx addr, mem, reg; | |
13842 | ||
13843 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13844 | GEN_INT (info->vrsave_save_offset + sp_offset)); | |
13845 | mem = gen_rtx_MEM (SImode, addr); | |
13846 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13847 | reg = gen_rtx_REG (SImode, 12); | |
13848 | emit_move_insn (reg, mem); | |
13849 | ||
13850 | emit_insn (generate_set_vrsave (reg, info, 1)); | |
13851 | } | |
13852 | ||
9ebbca7d GK |
13853 | /* Get the old lr if we saved it. */ |
13854 | if (info->lr_save_p) | |
b6c9286a | 13855 | { |
a3170dc6 AH |
13856 | rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx, |
13857 | info->lr_save_offset + sp_offset); | |
ba4828e0 RK |
13858 | |
13859 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 13860 | |
9ebbca7d | 13861 | emit_move_insn (gen_rtx_REG (Pmode, 0), mem); |
b6c9286a | 13862 | } |
f676971a | 13863 | |
9ebbca7d GK |
13864 | /* Get the old cr if we saved it. */ |
13865 | if (info->cr_save_p) | |
13866 | { | |
13867 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13868 | GEN_INT (info->cr_save_offset + sp_offset)); | |
13869 | rtx mem = gen_rtx_MEM (SImode, addr); | |
ba4828e0 RK |
13870 | |
13871 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
b6c9286a | 13872 | |
9ebbca7d GK |
13873 | emit_move_insn (gen_rtx_REG (SImode, 12), mem); |
13874 | } | |
f676971a | 13875 | |
9ebbca7d | 13876 | /* Set LR here to try to overlap restores below. */ |
4697a36c | 13877 | if (info->lr_save_p) |
9ebbca7d GK |
13878 | emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), |
13879 | gen_rtx_REG (Pmode, 0)); | |
f676971a | 13880 | |
83720594 RH |
13881 | /* Load exception handler data registers, if needed. */ |
13882 | if (current_function_calls_eh_return) | |
13883 | { | |
78e1b90d DE |
13884 | unsigned int i, regno; |
13885 | ||
fc4767bb JJ |
13886 | if (TARGET_AIX) |
13887 | { | |
13888 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
13889 | GEN_INT (sp_offset + 5 * reg_size)); | |
13890 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
13891 | ||
13892 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
13893 | ||
13894 | emit_move_insn (gen_rtx_REG (reg_mode, 2), mem); | |
13895 | } | |
13896 | ||
83720594 RH |
13897 | for (i = 0; ; ++i) |
13898 | { | |
a3170dc6 | 13899 | rtx mem; |
83720594 RH |
13900 | |
13901 | regno = EH_RETURN_DATA_REGNO (i); | |
13902 | if (regno == INVALID_REGNUM) | |
13903 | break; | |
13904 | ||
a3170dc6 AH |
13905 | mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx, |
13906 | info->ehrd_offset + sp_offset | |
13907 | + reg_size * (int) i); | |
ba4828e0 | 13908 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
83720594 RH |
13909 | |
13910 | emit_move_insn (gen_rtx_REG (reg_mode, regno), mem); | |
13911 | } | |
13912 | } | |
f676971a | 13913 | |
9ebbca7d GK |
13914 | /* Restore GPRs. This is done as a PARALLEL if we are using |
13915 | the load-multiple instructions. */ | |
13916 | if (using_load_multiple) | |
979721f8 | 13917 | { |
9ebbca7d GK |
13918 | rtvec p; |
13919 | p = rtvec_alloc (32 - info->first_gp_reg_save); | |
13920 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
979721f8 | 13921 | { |
f676971a EC |
13922 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
13923 | GEN_INT (info->gp_save_offset | |
13924 | + sp_offset | |
9ebbca7d GK |
13925 | + reg_size * i)); |
13926 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 RK |
13927 | |
13928 | set_mem_alias_set (mem, rs6000_sr_alias_set); | |
9ebbca7d | 13929 | |
f676971a | 13930 | RTVEC_ELT (p, i) = |
9ebbca7d GK |
13931 | gen_rtx_SET (VOIDmode, |
13932 | gen_rtx_REG (reg_mode, info->first_gp_reg_save + i), | |
13933 | mem); | |
979721f8 | 13934 | } |
9ebbca7d | 13935 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
979721f8 | 13936 | } |
9ebbca7d GK |
13937 | else |
13938 | for (i = 0; i < 32 - info->first_gp_reg_save; i++) | |
f676971a | 13939 | if ((regs_ever_live[info->first_gp_reg_save+i] |
b4db40bf JJ |
13940 | && (! call_used_regs[info->first_gp_reg_save+i] |
13941 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM | |
13942 | && TARGET_TOC && TARGET_MINIMAL_TOC))) | |
1db02437 | 13943 | || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM |
14f00213 | 13944 | && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0) |
f607bc57 | 13945 | || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))) |
9ebbca7d | 13946 | { |
f676971a EC |
13947 | rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, |
13948 | GEN_INT (info->gp_save_offset | |
13949 | + sp_offset | |
9ebbca7d GK |
13950 | + reg_size * i)); |
13951 | rtx mem = gen_rtx_MEM (reg_mode, addr); | |
ba4828e0 | 13952 | |
a3170dc6 | 13953 | /* Restore 64-bit quantities for SPE. */ |
c19de7aa | 13954 | if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0) |
a3170dc6 AH |
13955 | { |
13956 | int offset = info->spe_gp_save_offset + sp_offset + 8 * i; | |
13957 | rtx b; | |
13958 | ||
13959 | if (!SPE_CONST_OFFSET_OK (offset)) | |
13960 | { | |
13961 | b = gen_rtx_REG (Pmode, FIXED_SCRATCH); | |
13962 | emit_move_insn (b, GEN_INT (offset)); | |
13963 | } | |
13964 | else | |
13965 | b = GEN_INT (offset); | |
13966 | ||
13967 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b); | |
13968 | mem = gen_rtx_MEM (V2SImode, addr); | |
13969 | } | |
13970 | ||
ba4828e0 | 13971 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d | 13972 | |
f676971a | 13973 | emit_move_insn (gen_rtx_REG (reg_mode, |
a3170dc6 | 13974 | info->first_gp_reg_save + i), mem); |
9ebbca7d | 13975 | } |
9878760c | 13976 | |
9ebbca7d GK |
13977 | /* Restore fpr's if we need to do it without calling a function. */ |
13978 | if (restoring_FPRs_inline) | |
13979 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) | |
f676971a | 13980 | if ((regs_ever_live[info->first_fp_reg_save+i] |
9ebbca7d GK |
13981 | && ! call_used_regs[info->first_fp_reg_save+i])) |
13982 | { | |
13983 | rtx addr, mem; | |
13984 | addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, | |
f676971a EC |
13985 | GEN_INT (info->fp_save_offset |
13986 | + sp_offset | |
a4f6c312 | 13987 | + 8 * i)); |
9ebbca7d | 13988 | mem = gen_rtx_MEM (DFmode, addr); |
ba4828e0 | 13989 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d | 13990 | |
f676971a | 13991 | emit_move_insn (gen_rtx_REG (DFmode, |
9ebbca7d GK |
13992 | info->first_fp_reg_save + i), |
13993 | mem); | |
13994 | } | |
8d30c4ee | 13995 | |
9ebbca7d GK |
13996 | /* If we saved cr, restore it here. Just those that were used. */ |
13997 | if (info->cr_save_p) | |
979721f8 | 13998 | { |
9ebbca7d | 13999 | rtx r12_rtx = gen_rtx_REG (SImode, 12); |
e35b9579 | 14000 | int count = 0; |
f676971a | 14001 | |
9ebbca7d | 14002 | if (using_mfcr_multiple) |
979721f8 | 14003 | { |
9ebbca7d GK |
14004 | for (i = 0; i < 8; i++) |
14005 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
e35b9579 | 14006 | count++; |
9ebbca7d | 14007 | if (count == 0) |
e35b9579 GK |
14008 | abort (); |
14009 | } | |
14010 | ||
14011 | if (using_mfcr_multiple && count > 1) | |
14012 | { | |
14013 | rtvec p; | |
14014 | int ndx; | |
f676971a | 14015 | |
e35b9579 | 14016 | p = rtvec_alloc (count); |
9ebbca7d | 14017 | |
e35b9579 | 14018 | ndx = 0; |
9ebbca7d GK |
14019 | for (i = 0; i < 8; i++) |
14020 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
14021 | { | |
14022 | rtvec r = rtvec_alloc (2); | |
14023 | RTVEC_ELT (r, 0) = r12_rtx; | |
14024 | RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i)); | |
e35b9579 | 14025 | RTVEC_ELT (p, ndx) = |
f676971a | 14026 | gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i), |
615158e2 | 14027 | gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR)); |
e35b9579 | 14028 | ndx++; |
9ebbca7d GK |
14029 | } |
14030 | emit_insn (gen_rtx_PARALLEL (VOIDmode, p)); | |
e35b9579 GK |
14031 | if (ndx != count) |
14032 | abort (); | |
979721f8 MM |
14033 | } |
14034 | else | |
9ebbca7d GK |
14035 | for (i = 0; i < 8; i++) |
14036 | if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i]) | |
979721f8 | 14037 | { |
f676971a | 14038 | emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode, |
9ebbca7d GK |
14039 | CR0_REGNO+i), |
14040 | r12_rtx)); | |
979721f8 | 14041 | } |
979721f8 MM |
14042 | } |
14043 | ||
9ebbca7d GK |
14044 | /* If this is V.4, unwind the stack pointer after all of the loads |
14045 | have been done. We need to emit a block here so that sched | |
14046 | doesn't decide to move the sp change before the register restores | |
14047 | (which may not have any obvious dependency on the stack). This | |
14048 | doesn't hurt performance, because there is no scheduling that can | |
14049 | be done after this point. */ | |
fc4767bb JJ |
14050 | if (DEFAULT_ABI == ABI_V4 |
14051 | || current_function_calls_eh_return) | |
b6c9286a | 14052 | { |
9ebbca7d GK |
14053 | if (frame_reg_rtx != sp_reg_rtx) |
14054 | rs6000_emit_stack_tie (); | |
b6c9286a | 14055 | |
9ebbca7d | 14056 | if (use_backchain_to_restore_sp) |
b6c9286a | 14057 | { |
9ebbca7d | 14058 | emit_move_insn (sp_reg_rtx, frame_reg_rtx); |
b6c9286a | 14059 | } |
9ebbca7d | 14060 | else if (sp_offset != 0) |
13f1623b | 14061 | { |
5b71a4e7 | 14062 | emit_insn (TARGET_32BIT |
9ebbca7d GK |
14063 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, |
14064 | GEN_INT (sp_offset)) | |
14065 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, | |
14066 | GEN_INT (sp_offset))); | |
13f1623b | 14067 | } |
9ebbca7d | 14068 | } |
b6c9286a | 14069 | |
83720594 RH |
14070 | if (current_function_calls_eh_return) |
14071 | { | |
14072 | rtx sa = EH_RETURN_STACKADJ_RTX; | |
5b71a4e7 | 14073 | emit_insn (TARGET_32BIT |
83720594 RH |
14074 | ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa) |
14075 | : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa)); | |
14076 | } | |
14077 | ||
9ebbca7d GK |
14078 | if (!sibcall) |
14079 | { | |
14080 | rtvec p; | |
14081 | if (! restoring_FPRs_inline) | |
14082 | p = rtvec_alloc (3 + 64 - info->first_fp_reg_save); | |
14083 | else | |
14084 | p = rtvec_alloc (2); | |
b6c9286a | 14085 | |
e35b9579 | 14086 | RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode); |
f676971a EC |
14087 | RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode, |
14088 | gen_rtx_REG (Pmode, | |
9ebbca7d | 14089 | LINK_REGISTER_REGNUM)); |
9ebbca7d GK |
14090 | |
14091 | /* If we have to restore more than two FP registers, branch to the | |
14092 | restore function. It will return to our caller. */ | |
14093 | if (! restoring_FPRs_inline) | |
14094 | { | |
14095 | int i; | |
14096 | char rname[30]; | |
520a57c8 | 14097 | const char *alloc_rname; |
979721f8 | 14098 | |
f676971a | 14099 | sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX, |
9ebbca7d | 14100 | info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX); |
a8a05998 | 14101 | alloc_rname = ggc_strdup (rname); |
9ebbca7d GK |
14102 | RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, |
14103 | gen_rtx_SYMBOL_REF (Pmode, | |
14104 | alloc_rname)); | |
b6c9286a | 14105 | |
9ebbca7d GK |
14106 | for (i = 0; i < 64 - info->first_fp_reg_save; i++) |
14107 | { | |
14108 | rtx addr, mem; | |
14109 | addr = gen_rtx_PLUS (Pmode, sp_reg_rtx, | |
14110 | GEN_INT (info->fp_save_offset + 8*i)); | |
14111 | mem = gen_rtx_MEM (DFmode, addr); | |
ba4828e0 | 14112 | set_mem_alias_set (mem, rs6000_sr_alias_set); |
9ebbca7d | 14113 | |
f676971a | 14114 | RTVEC_ELT (p, i+3) = |
9ebbca7d GK |
14115 | gen_rtx_SET (VOIDmode, |
14116 | gen_rtx_REG (DFmode, info->first_fp_reg_save + i), | |
14117 | mem); | |
b6c9286a MM |
14118 | } |
14119 | } | |
f676971a | 14120 | |
9ebbca7d | 14121 | emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p)); |
3daf36a4 | 14122 | } |
9878760c RK |
14123 | } |
14124 | ||
14125 | /* Write function epilogue. */ | |
14126 | ||
08c148a8 | 14127 | static void |
f676971a | 14128 | rs6000_output_function_epilogue (FILE *file, |
a2369ed3 | 14129 | HOST_WIDE_INT size ATTRIBUTE_UNUSED) |
9878760c | 14130 | { |
4697a36c | 14131 | rs6000_stack_t *info = rs6000_stack_info (); |
9878760c | 14132 | |
9ebbca7d | 14133 | if (! HAVE_epilogue) |
9878760c | 14134 | { |
9ebbca7d GK |
14135 | rtx insn = get_last_insn (); |
14136 | /* If the last insn was a BARRIER, we don't have to write anything except | |
14137 | the trace table. */ | |
14138 | if (GET_CODE (insn) == NOTE) | |
14139 | insn = prev_nonnote_insn (insn); | |
14140 | if (insn == 0 || GET_CODE (insn) != BARRIER) | |
4697a36c | 14141 | { |
9ebbca7d GK |
14142 | /* This is slightly ugly, but at least we don't have two |
14143 | copies of the epilogue-emitting code. */ | |
14144 | start_sequence (); | |
14145 | ||
14146 | /* A NOTE_INSN_DELETED is supposed to be at the start | |
14147 | and end of the "toplevel" insn chain. */ | |
2e040219 | 14148 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 14149 | rs6000_emit_epilogue (FALSE); |
2e040219 | 14150 | emit_note (NOTE_INSN_DELETED); |
9ebbca7d | 14151 | |
a3c9585f | 14152 | /* Expand INSN_ADDRESSES so final() doesn't crash. */ |
178c3eff DJ |
14153 | { |
14154 | rtx insn; | |
14155 | unsigned addr = 0; | |
14156 | for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) | |
14157 | { | |
14158 | INSN_ADDRESSES_NEW (insn, addr); | |
14159 | addr += 4; | |
14160 | } | |
14161 | } | |
14162 | ||
9ebbca7d | 14163 | if (TARGET_DEBUG_STACK) |
a4f6c312 SS |
14164 | debug_rtx_list (get_insns (), 100); |
14165 | final (get_insns (), file, FALSE, FALSE); | |
9ebbca7d | 14166 | end_sequence (); |
4697a36c | 14167 | } |
9878760c | 14168 | } |
b4ac57ab | 14169 | |
efdba735 SH |
14170 | #if TARGET_MACHO |
14171 | macho_branch_islands (); | |
0e5da0be GK |
14172 | /* Mach-O doesn't support labels at the end of objects, so if |
14173 | it looks like we might want one, insert a NOP. */ | |
14174 | { | |
14175 | rtx insn = get_last_insn (); | |
14176 | while (insn | |
14177 | && NOTE_P (insn) | |
14178 | && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL) | |
14179 | insn = PREV_INSN (insn); | |
f676971a EC |
14180 | if (insn |
14181 | && (LABEL_P (insn) | |
0e5da0be GK |
14182 | || (NOTE_P (insn) |
14183 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
14184 | fputs ("\tnop\n", file); | |
14185 | } | |
14186 | #endif | |
14187 | ||
9b30bae2 | 14188 | /* Output a traceback table here. See /usr/include/sys/debug.h for info |
314fc5a9 ILT |
14189 | on its format. |
14190 | ||
14191 | We don't output a traceback table if -finhibit-size-directive was | |
14192 | used. The documentation for -finhibit-size-directive reads | |
14193 | ``don't output a @code{.size} assembler directive, or anything | |
14194 | else that would cause trouble if the function is split in the | |
14195 | middle, and the two halves are placed at locations far apart in | |
14196 | memory.'' The traceback table has this property, since it | |
14197 | includes the offset from the start of the function to the | |
4d30c363 MM |
14198 | traceback table itself. |
14199 | ||
14200 | System V.4 Powerpc's (and the embedded ABI derived from it) use a | |
b6c9286a | 14201 | different traceback table. */ |
57ac7be9 AM |
14202 | if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive |
14203 | && rs6000_traceback != traceback_none) | |
9b30bae2 | 14204 | { |
69c75916 | 14205 | const char *fname = NULL; |
3ac88239 | 14206 | const char *language_string = lang_hooks.name; |
6041bf2f | 14207 | int fixed_parms = 0, float_parms = 0, parm_info = 0; |
314fc5a9 | 14208 | int i; |
57ac7be9 AM |
14209 | int optional_tbtab; |
14210 | ||
14211 | if (rs6000_traceback == traceback_full) | |
14212 | optional_tbtab = 1; | |
14213 | else if (rs6000_traceback == traceback_part) | |
14214 | optional_tbtab = 0; | |
14215 | else | |
14216 | optional_tbtab = !optimize_size && !TARGET_ELF; | |
314fc5a9 | 14217 | |
69c75916 AM |
14218 | if (optional_tbtab) |
14219 | { | |
14220 | fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
14221 | while (*fname == '.') /* V.4 encodes . in the name */ | |
14222 | fname++; | |
14223 | ||
14224 | /* Need label immediately before tbtab, so we can compute | |
14225 | its offset from the function start. */ | |
14226 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); | |
14227 | ASM_OUTPUT_LABEL (file, fname); | |
14228 | } | |
314fc5a9 ILT |
14229 | |
14230 | /* The .tbtab pseudo-op can only be used for the first eight | |
14231 | expressions, since it can't handle the possibly variable | |
14232 | length fields that follow. However, if you omit the optional | |
14233 | fields, the assembler outputs zeros for all optional fields | |
14234 | anyways, giving each variable length field is minimum length | |
14235 | (as defined in sys/debug.h). Thus we can not use the .tbtab | |
14236 | pseudo-op at all. */ | |
14237 | ||
14238 | /* An all-zero word flags the start of the tbtab, for debuggers | |
14239 | that have to find it by searching forward from the entry | |
14240 | point or from the current pc. */ | |
19d2d16f | 14241 | fputs ("\t.long 0\n", file); |
314fc5a9 ILT |
14242 | |
14243 | /* Tbtab format type. Use format type 0. */ | |
19d2d16f | 14244 | fputs ("\t.byte 0,", file); |
314fc5a9 | 14245 | |
5fc921c1 DE |
14246 | /* Language type. Unfortunately, there does not seem to be any |
14247 | official way to discover the language being compiled, so we | |
14248 | use language_string. | |
14249 | C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9. | |
14250 | Java is 13. Objective-C is 14. */ | |
14251 | if (! strcmp (language_string, "GNU C")) | |
314fc5a9 | 14252 | i = 0; |
6de9cd9a DN |
14253 | else if (! strcmp (language_string, "GNU F77") |
14254 | || ! strcmp (language_string, "GNU F95")) | |
314fc5a9 | 14255 | i = 1; |
8b83775b | 14256 | else if (! strcmp (language_string, "GNU Pascal")) |
314fc5a9 | 14257 | i = 2; |
5fc921c1 DE |
14258 | else if (! strcmp (language_string, "GNU Ada")) |
14259 | i = 3; | |
314fc5a9 ILT |
14260 | else if (! strcmp (language_string, "GNU C++")) |
14261 | i = 9; | |
9517ead8 AG |
14262 | else if (! strcmp (language_string, "GNU Java")) |
14263 | i = 13; | |
5fc921c1 DE |
14264 | else if (! strcmp (language_string, "GNU Objective-C")) |
14265 | i = 14; | |
314fc5a9 ILT |
14266 | else |
14267 | abort (); | |
14268 | fprintf (file, "%d,", i); | |
14269 | ||
14270 | /* 8 single bit fields: global linkage (not set for C extern linkage, | |
14271 | apparently a PL/I convention?), out-of-line epilogue/prologue, offset | |
14272 | from start of procedure stored in tbtab, internal function, function | |
14273 | has controlled storage, function has no toc, function uses fp, | |
14274 | function logs/aborts fp operations. */ | |
14275 | /* Assume that fp operations are used if any fp reg must be saved. */ | |
6041bf2f DE |
14276 | fprintf (file, "%d,", |
14277 | (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1)); | |
314fc5a9 ILT |
14278 | |
14279 | /* 6 bitfields: function is interrupt handler, name present in | |
14280 | proc table, function calls alloca, on condition directives | |
14281 | (controls stack walks, 3 bits), saves condition reg, saves | |
14282 | link reg. */ | |
14283 | /* The `function calls alloca' bit seems to be set whenever reg 31 is | |
14284 | set up as a frame pointer, even when there is no alloca call. */ | |
14285 | fprintf (file, "%d,", | |
6041bf2f DE |
14286 | ((optional_tbtab << 6) |
14287 | | ((optional_tbtab & frame_pointer_needed) << 5) | |
14288 | | (info->cr_save_p << 1) | |
14289 | | (info->lr_save_p))); | |
314fc5a9 | 14290 | |
6041bf2f | 14291 | /* 3 bitfields: saves backchain, fixup code, number of fpr saved |
314fc5a9 ILT |
14292 | (6 bits). */ |
14293 | fprintf (file, "%d,", | |
4697a36c | 14294 | (info->push_p << 7) | (64 - info->first_fp_reg_save)); |
314fc5a9 ILT |
14295 | |
14296 | /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */ | |
14297 | fprintf (file, "%d,", (32 - first_reg_to_save ())); | |
14298 | ||
6041bf2f DE |
14299 | if (optional_tbtab) |
14300 | { | |
14301 | /* Compute the parameter info from the function decl argument | |
14302 | list. */ | |
14303 | tree decl; | |
14304 | int next_parm_info_bit = 31; | |
314fc5a9 | 14305 | |
6041bf2f DE |
14306 | for (decl = DECL_ARGUMENTS (current_function_decl); |
14307 | decl; decl = TREE_CHAIN (decl)) | |
14308 | { | |
14309 | rtx parameter = DECL_INCOMING_RTL (decl); | |
14310 | enum machine_mode mode = GET_MODE (parameter); | |
314fc5a9 | 14311 | |
6041bf2f DE |
14312 | if (GET_CODE (parameter) == REG) |
14313 | { | |
14314 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
14315 | { | |
14316 | int bits; | |
14317 | ||
14318 | float_parms++; | |
14319 | ||
14320 | if (mode == SFmode) | |
14321 | bits = 0x2; | |
fcce224d | 14322 | else if (mode == DFmode || mode == TFmode) |
6041bf2f DE |
14323 | bits = 0x3; |
14324 | else | |
14325 | abort (); | |
14326 | ||
14327 | /* If only one bit will fit, don't or in this entry. */ | |
14328 | if (next_parm_info_bit > 0) | |
14329 | parm_info |= (bits << (next_parm_info_bit - 1)); | |
14330 | next_parm_info_bit -= 2; | |
14331 | } | |
14332 | else | |
14333 | { | |
14334 | fixed_parms += ((GET_MODE_SIZE (mode) | |
14335 | + (UNITS_PER_WORD - 1)) | |
14336 | / UNITS_PER_WORD); | |
14337 | next_parm_info_bit -= 1; | |
14338 | } | |
14339 | } | |
14340 | } | |
14341 | } | |
314fc5a9 ILT |
14342 | |
14343 | /* Number of fixed point parameters. */ | |
14344 | /* This is actually the number of words of fixed point parameters; thus | |
14345 | an 8 byte struct counts as 2; and thus the maximum value is 8. */ | |
14346 | fprintf (file, "%d,", fixed_parms); | |
14347 | ||
14348 | /* 2 bitfields: number of floating point parameters (7 bits), parameters | |
14349 | all on stack. */ | |
14350 | /* This is actually the number of fp registers that hold parameters; | |
14351 | and thus the maximum value is 13. */ | |
14352 | /* Set parameters on stack bit if parameters are not in their original | |
14353 | registers, regardless of whether they are on the stack? Xlc | |
14354 | seems to set the bit when not optimizing. */ | |
14355 | fprintf (file, "%d\n", ((float_parms << 1) | (! optimize))); | |
14356 | ||
6041bf2f DE |
14357 | if (! optional_tbtab) |
14358 | return; | |
14359 | ||
314fc5a9 ILT |
14360 | /* Optional fields follow. Some are variable length. */ |
14361 | ||
14362 | /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float, | |
14363 | 11 double float. */ | |
14364 | /* There is an entry for each parameter in a register, in the order that | |
14365 | they occur in the parameter list. Any intervening arguments on the | |
14366 | stack are ignored. If the list overflows a long (max possible length | |
14367 | 34 bits) then completely leave off all elements that don't fit. */ | |
14368 | /* Only emit this long if there was at least one parameter. */ | |
14369 | if (fixed_parms || float_parms) | |
14370 | fprintf (file, "\t.long %d\n", parm_info); | |
14371 | ||
14372 | /* Offset from start of code to tb table. */ | |
19d2d16f | 14373 | fputs ("\t.long ", file); |
314fc5a9 | 14374 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT"); |
85b776df AM |
14375 | if (TARGET_AIX) |
14376 | RS6000_OUTPUT_BASENAME (file, fname); | |
14377 | else | |
14378 | assemble_name (file, fname); | |
14379 | putc ('-', file); | |
14380 | rs6000_output_function_entry (file, fname); | |
19d2d16f | 14381 | putc ('\n', file); |
314fc5a9 ILT |
14382 | |
14383 | /* Interrupt handler mask. */ | |
14384 | /* Omit this long, since we never set the interrupt handler bit | |
14385 | above. */ | |
14386 | ||
14387 | /* Number of CTL (controlled storage) anchors. */ | |
14388 | /* Omit this long, since the has_ctl bit is never set above. */ | |
14389 | ||
14390 | /* Displacement into stack of each CTL anchor. */ | |
14391 | /* Omit this list of longs, because there are no CTL anchors. */ | |
14392 | ||
14393 | /* Length of function name. */ | |
69c75916 AM |
14394 | if (*fname == '*') |
14395 | ++fname; | |
296b8152 | 14396 | fprintf (file, "\t.short %d\n", (int) strlen (fname)); |
314fc5a9 ILT |
14397 | |
14398 | /* Function name. */ | |
14399 | assemble_string (fname, strlen (fname)); | |
14400 | ||
14401 | /* Register for alloca automatic storage; this is always reg 31. | |
14402 | Only emit this if the alloca bit was set above. */ | |
14403 | if (frame_pointer_needed) | |
19d2d16f | 14404 | fputs ("\t.byte 31\n", file); |
b1765bde DE |
14405 | |
14406 | fputs ("\t.align 2\n", file); | |
9b30bae2 | 14407 | } |
9878760c | 14408 | } |
17167fd8 | 14409 | \f |
a4f6c312 SS |
14410 | /* A C compound statement that outputs the assembler code for a thunk |
14411 | function, used to implement C++ virtual function calls with | |
14412 | multiple inheritance. The thunk acts as a wrapper around a virtual | |
14413 | function, adjusting the implicit object parameter before handing | |
14414 | control off to the real function. | |
14415 | ||
14416 | First, emit code to add the integer DELTA to the location that | |
14417 | contains the incoming first argument. Assume that this argument | |
14418 | contains a pointer, and is the one used to pass the `this' pointer | |
14419 | in C++. This is the incoming argument *before* the function | |
14420 | prologue, e.g. `%o0' on a sparc. The addition must preserve the | |
14421 | values of all other incoming arguments. | |
17167fd8 MM |
14422 | |
14423 | After the addition, emit code to jump to FUNCTION, which is a | |
a4f6c312 SS |
14424 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does |
14425 | not touch the return address. Hence returning from FUNCTION will | |
14426 | return to whoever called the current `thunk'. | |
17167fd8 | 14427 | |
a4f6c312 SS |
14428 | The effect must be as if FUNCTION had been called directly with the |
14429 | adjusted first argument. This macro is responsible for emitting | |
14430 | all of the code for a thunk function; output_function_prologue() | |
14431 | and output_function_epilogue() are not invoked. | |
17167fd8 | 14432 | |
a4f6c312 SS |
14433 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already |
14434 | been extracted from it.) It might possibly be useful on some | |
14435 | targets, but probably not. | |
17167fd8 | 14436 | |
a4f6c312 SS |
14437 | If you do not define this macro, the target-independent code in the |
14438 | C++ frontend will generate a less efficient heavyweight thunk that | |
14439 | calls FUNCTION instead of jumping to it. The generic approach does | |
14440 | not support varargs. */ | |
17167fd8 | 14441 | |
3961e8fe | 14442 | static void |
f676971a EC |
14443 | rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, |
14444 | HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, | |
a2369ed3 | 14445 | tree function) |
17167fd8 | 14446 | { |
5b71a4e7 | 14447 | rtx this, insn, funexp; |
17167fd8 | 14448 | |
5b71a4e7 | 14449 | reload_completed = 1; |
fe3ad572 | 14450 | epilogue_completed = 1; |
5b71a4e7 | 14451 | no_new_pseudos = 1; |
6429e3be | 14452 | reset_block_changes (); |
56a7189a | 14453 | |
5b71a4e7 | 14454 | /* Mark the end of the (empty) prologue. */ |
2e040219 | 14455 | emit_note (NOTE_INSN_PROLOGUE_END); |
17167fd8 | 14456 | |
5b71a4e7 DE |
14457 | /* Find the "this" pointer. If the function returns a structure, |
14458 | the structure return pointer is in r3. */ | |
61f71b34 | 14459 | if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) |
5b71a4e7 | 14460 | this = gen_rtx_REG (Pmode, 4); |
56a7189a | 14461 | else |
5b71a4e7 | 14462 | this = gen_rtx_REG (Pmode, 3); |
17167fd8 | 14463 | |
5b71a4e7 DE |
14464 | /* Apply the constant offset, if required. */ |
14465 | if (delta) | |
14466 | { | |
14467 | rtx delta_rtx = GEN_INT (delta); | |
14468 | emit_insn (TARGET_32BIT | |
14469 | ? gen_addsi3 (this, this, delta_rtx) | |
14470 | : gen_adddi3 (this, this, delta_rtx)); | |
17167fd8 MM |
14471 | } |
14472 | ||
5b71a4e7 DE |
14473 | /* Apply the offset from the vtable, if required. */ |
14474 | if (vcall_offset) | |
17167fd8 | 14475 | { |
5b71a4e7 DE |
14476 | rtx vcall_offset_rtx = GEN_INT (vcall_offset); |
14477 | rtx tmp = gen_rtx_REG (Pmode, 12); | |
17167fd8 | 14478 | |
5b71a4e7 | 14479 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, this)); |
eeff9307 JJ |
14480 | if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000) |
14481 | { | |
14482 | emit_insn (TARGET_32BIT | |
14483 | ? gen_addsi3 (tmp, tmp, vcall_offset_rtx) | |
14484 | : gen_adddi3 (tmp, tmp, vcall_offset_rtx)); | |
14485 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp)); | |
14486 | } | |
14487 | else | |
14488 | { | |
14489 | rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx); | |
14490 | ||
14491 | emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc)); | |
14492 | } | |
5b71a4e7 DE |
14493 | emit_insn (TARGET_32BIT |
14494 | ? gen_addsi3 (this, this, tmp) | |
14495 | : gen_adddi3 (this, this, tmp)); | |
17167fd8 MM |
14496 | } |
14497 | ||
5b71a4e7 DE |
14498 | /* Generate a tail call to the target function. */ |
14499 | if (!TREE_USED (function)) | |
14500 | { | |
14501 | assemble_external (function); | |
14502 | TREE_USED (function) = 1; | |
14503 | } | |
14504 | funexp = XEXP (DECL_RTL (function), 0); | |
5b71a4e7 | 14505 | funexp = gen_rtx_MEM (FUNCTION_MODE, funexp); |
ee890fe2 SS |
14506 | |
14507 | #if TARGET_MACHO | |
ab82a49f | 14508 | if (MACHOPIC_INDIRECT) |
5b71a4e7 | 14509 | funexp = machopic_indirect_call_target (funexp); |
ee890fe2 | 14510 | #endif |
5b71a4e7 DE |
14511 | |
14512 | /* gen_sibcall expects reload to convert scratch pseudo to LR so we must | |
14513 | generate sibcall RTL explicitly to avoid constraint abort. */ | |
14514 | insn = emit_call_insn ( | |
14515 | gen_rtx_PARALLEL (VOIDmode, | |
14516 | gen_rtvec (4, | |
14517 | gen_rtx_CALL (VOIDmode, | |
14518 | funexp, const0_rtx), | |
14519 | gen_rtx_USE (VOIDmode, const0_rtx), | |
14520 | gen_rtx_USE (VOIDmode, | |
14521 | gen_rtx_REG (SImode, | |
14522 | LINK_REGISTER_REGNUM)), | |
14523 | gen_rtx_RETURN (VOIDmode)))); | |
14524 | SIBLING_CALL_P (insn) = 1; | |
14525 | emit_barrier (); | |
14526 | ||
14527 | /* Run just enough of rest_of_compilation to get the insns emitted. | |
14528 | There's not really enough bulk here to make other passes such as | |
14529 | instruction scheduling worth while. Note that use_thunk calls | |
14530 | assemble_start_function and assemble_end_function. */ | |
14531 | insn = get_insns (); | |
a2855205 | 14532 | insn_locators_initialize (); |
5b71a4e7 DE |
14533 | shorten_branches (insn); |
14534 | final_start_function (insn, file, 1); | |
14535 | final (insn, file, 1, 0); | |
14536 | final_end_function (); | |
14537 | ||
14538 | reload_completed = 0; | |
fe3ad572 | 14539 | epilogue_completed = 0; |
5b71a4e7 | 14540 | no_new_pseudos = 0; |
9ebbca7d | 14541 | } |
9ebbca7d GK |
14542 | \f |
14543 | /* A quick summary of the various types of 'constant-pool tables' | |
14544 | under PowerPC: | |
14545 | ||
f676971a | 14546 | Target Flags Name One table per |
9ebbca7d GK |
14547 | AIX (none) AIX TOC object file |
14548 | AIX -mfull-toc AIX TOC object file | |
14549 | AIX -mminimal-toc AIX minimal TOC translation unit | |
14550 | SVR4/EABI (none) SVR4 SDATA object file | |
14551 | SVR4/EABI -fpic SVR4 pic object file | |
14552 | SVR4/EABI -fPIC SVR4 PIC translation unit | |
14553 | SVR4/EABI -mrelocatable EABI TOC function | |
14554 | SVR4/EABI -maix AIX TOC object file | |
f676971a | 14555 | SVR4/EABI -maix -mminimal-toc |
9ebbca7d GK |
14556 | AIX minimal TOC translation unit |
14557 | ||
14558 | Name Reg. Set by entries contains: | |
14559 | made by addrs? fp? sum? | |
14560 | ||
14561 | AIX TOC 2 crt0 as Y option option | |
14562 | AIX minimal TOC 30 prolog gcc Y Y option | |
14563 | SVR4 SDATA 13 crt0 gcc N Y N | |
14564 | SVR4 pic 30 prolog ld Y not yet N | |
14565 | SVR4 PIC 30 prolog gcc Y option option | |
14566 | EABI TOC 30 prolog gcc Y option option | |
14567 | ||
14568 | */ | |
14569 | ||
9ebbca7d GK |
14570 | /* Hash functions for the hash table. */ |
14571 | ||
14572 | static unsigned | |
a2369ed3 | 14573 | rs6000_hash_constant (rtx k) |
9ebbca7d | 14574 | { |
46b33600 RH |
14575 | enum rtx_code code = GET_CODE (k); |
14576 | enum machine_mode mode = GET_MODE (k); | |
14577 | unsigned result = (code << 3) ^ mode; | |
14578 | const char *format; | |
14579 | int flen, fidx; | |
f676971a | 14580 | |
46b33600 RH |
14581 | format = GET_RTX_FORMAT (code); |
14582 | flen = strlen (format); | |
14583 | fidx = 0; | |
9ebbca7d | 14584 | |
46b33600 RH |
14585 | switch (code) |
14586 | { | |
14587 | case LABEL_REF: | |
14588 | return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0)); | |
14589 | ||
14590 | case CONST_DOUBLE: | |
14591 | if (mode != VOIDmode) | |
14592 | return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result; | |
14593 | flen = 2; | |
14594 | break; | |
14595 | ||
14596 | case CODE_LABEL: | |
14597 | fidx = 3; | |
14598 | break; | |
14599 | ||
14600 | default: | |
14601 | break; | |
14602 | } | |
9ebbca7d GK |
14603 | |
14604 | for (; fidx < flen; fidx++) | |
14605 | switch (format[fidx]) | |
14606 | { | |
14607 | case 's': | |
14608 | { | |
14609 | unsigned i, len; | |
14610 | const char *str = XSTR (k, fidx); | |
14611 | len = strlen (str); | |
14612 | result = result * 613 + len; | |
14613 | for (i = 0; i < len; i++) | |
14614 | result = result * 613 + (unsigned) str[i]; | |
17167fd8 MM |
14615 | break; |
14616 | } | |
9ebbca7d GK |
14617 | case 'u': |
14618 | case 'e': | |
14619 | result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx)); | |
14620 | break; | |
14621 | case 'i': | |
14622 | case 'n': | |
14623 | result = result * 613 + (unsigned) XINT (k, fidx); | |
14624 | break; | |
14625 | case 'w': | |
14626 | if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) | |
14627 | result = result * 613 + (unsigned) XWINT (k, fidx); | |
14628 | else | |
14629 | { | |
14630 | size_t i; | |
14631 | for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++) | |
14632 | result = result * 613 + (unsigned) (XWINT (k, fidx) | |
14633 | >> CHAR_BIT * i); | |
14634 | } | |
14635 | break; | |
09501938 DE |
14636 | case '0': |
14637 | break; | |
9ebbca7d | 14638 | default: |
a4f6c312 | 14639 | abort (); |
9ebbca7d | 14640 | } |
46b33600 | 14641 | |
9ebbca7d GK |
14642 | return result; |
14643 | } | |
14644 | ||
14645 | static unsigned | |
a2369ed3 | 14646 | toc_hash_function (const void *hash_entry) |
9ebbca7d | 14647 | { |
f676971a | 14648 | const struct toc_hash_struct *thc = |
a9098fd0 GK |
14649 | (const struct toc_hash_struct *) hash_entry; |
14650 | return rs6000_hash_constant (thc->key) ^ thc->key_mode; | |
9ebbca7d GK |
14651 | } |
14652 | ||
14653 | /* Compare H1 and H2 for equivalence. */ | |
14654 | ||
14655 | static int | |
a2369ed3 | 14656 | toc_hash_eq (const void *h1, const void *h2) |
9ebbca7d GK |
14657 | { |
14658 | rtx r1 = ((const struct toc_hash_struct *) h1)->key; | |
14659 | rtx r2 = ((const struct toc_hash_struct *) h2)->key; | |
14660 | ||
a9098fd0 GK |
14661 | if (((const struct toc_hash_struct *) h1)->key_mode |
14662 | != ((const struct toc_hash_struct *) h2)->key_mode) | |
14663 | return 0; | |
14664 | ||
5692c7bc | 14665 | return rtx_equal_p (r1, r2); |
9ebbca7d GK |
14666 | } |
14667 | ||
28e510bd MM |
14668 | /* These are the names given by the C++ front-end to vtables, and |
14669 | vtable-like objects. Ideally, this logic should not be here; | |
14670 | instead, there should be some programmatic way of inquiring as | |
14671 | to whether or not an object is a vtable. */ | |
14672 | ||
14673 | #define VTABLE_NAME_P(NAME) \ | |
14674 | (strncmp ("_vt.", name, strlen("_vt.")) == 0 \ | |
14675 | || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \ | |
14676 | || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \ | |
26be75db | 14677 | || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \ |
f676971a | 14678 | || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0) |
28e510bd MM |
14679 | |
14680 | void | |
a2369ed3 | 14681 | rs6000_output_symbol_ref (FILE *file, rtx x) |
28e510bd MM |
14682 | { |
14683 | /* Currently C++ toc references to vtables can be emitted before it | |
14684 | is decided whether the vtable is public or private. If this is | |
14685 | the case, then the linker will eventually complain that there is | |
f676971a | 14686 | a reference to an unknown section. Thus, for vtables only, |
28e510bd MM |
14687 | we emit the TOC reference to reference the symbol and not the |
14688 | section. */ | |
14689 | const char *name = XSTR (x, 0); | |
54ee9799 | 14690 | |
f676971a | 14691 | if (VTABLE_NAME_P (name)) |
54ee9799 DE |
14692 | { |
14693 | RS6000_OUTPUT_BASENAME (file, name); | |
14694 | } | |
14695 | else | |
14696 | assemble_name (file, name); | |
28e510bd MM |
14697 | } |
14698 | ||
a4f6c312 SS |
14699 | /* Output a TOC entry. We derive the entry name from what is being |
14700 | written. */ | |
9878760c RK |
14701 | |
14702 | void | |
a2369ed3 | 14703 | output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode) |
9878760c RK |
14704 | { |
14705 | char buf[256]; | |
3cce094d | 14706 | const char *name = buf; |
ec940faa | 14707 | const char *real_name; |
9878760c RK |
14708 | rtx base = x; |
14709 | int offset = 0; | |
14710 | ||
4697a36c MM |
14711 | if (TARGET_NO_TOC) |
14712 | abort (); | |
14713 | ||
9ebbca7d GK |
14714 | /* When the linker won't eliminate them, don't output duplicate |
14715 | TOC entries (this happens on AIX if there is any kind of TOC, | |
17211ab5 GK |
14716 | and on SVR4 under -fPIC or -mrelocatable). Don't do this for |
14717 | CODE_LABELs. */ | |
14718 | if (TARGET_TOC && GET_CODE (x) != LABEL_REF) | |
9ebbca7d GK |
14719 | { |
14720 | struct toc_hash_struct *h; | |
14721 | void * * found; | |
f676971a | 14722 | |
17211ab5 | 14723 | /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS |
39e3f58c | 14724 | time because GGC is not initialized at that point. */ |
17211ab5 | 14725 | if (toc_hash_table == NULL) |
f676971a | 14726 | toc_hash_table = htab_create_ggc (1021, toc_hash_function, |
17211ab5 GK |
14727 | toc_hash_eq, NULL); |
14728 | ||
9ebbca7d GK |
14729 | h = ggc_alloc (sizeof (*h)); |
14730 | h->key = x; | |
a9098fd0 | 14731 | h->key_mode = mode; |
9ebbca7d | 14732 | h->labelno = labelno; |
f676971a | 14733 | |
9ebbca7d GK |
14734 | found = htab_find_slot (toc_hash_table, h, 1); |
14735 | if (*found == NULL) | |
14736 | *found = h; | |
f676971a | 14737 | else /* This is indeed a duplicate. |
9ebbca7d GK |
14738 | Set this label equal to that label. */ |
14739 | { | |
14740 | fputs ("\t.set ", file); | |
14741 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
14742 | fprintf (file, "%d,", labelno); | |
14743 | ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC"); | |
f676971a | 14744 | fprintf (file, "%d\n", ((*(const struct toc_hash_struct **) |
9ebbca7d GK |
14745 | found)->labelno)); |
14746 | return; | |
14747 | } | |
14748 | } | |
14749 | ||
14750 | /* If we're going to put a double constant in the TOC, make sure it's | |
14751 | aligned properly when strict alignment is on. */ | |
ff1720ed RK |
14752 | if (GET_CODE (x) == CONST_DOUBLE |
14753 | && STRICT_ALIGNMENT | |
a9098fd0 | 14754 | && GET_MODE_BITSIZE (mode) >= 64 |
ff1720ed RK |
14755 | && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) { |
14756 | ASM_OUTPUT_ALIGN (file, 3); | |
14757 | } | |
14758 | ||
4977bab6 | 14759 | (*targetm.asm_out.internal_label) (file, "LC", labelno); |
9878760c | 14760 | |
37c37a57 RK |
14761 | /* Handle FP constants specially. Note that if we have a minimal |
14762 | TOC, things we put here aren't actually in the TOC, so we can allow | |
14763 | FP constants. */ | |
fcce224d DE |
14764 | if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode) |
14765 | { | |
14766 | REAL_VALUE_TYPE rv; | |
14767 | long k[4]; | |
14768 | ||
14769 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
14770 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k); | |
14771 | ||
14772 | if (TARGET_64BIT) | |
14773 | { | |
14774 | if (TARGET_MINIMAL_TOC) | |
14775 | fputs (DOUBLE_INT_ASM_OP, file); | |
14776 | else | |
14777 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
14778 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
14779 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
14780 | fprintf (file, "0x%lx%08lx,0x%lx%08lx\n", | |
14781 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
14782 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
14783 | return; | |
14784 | } | |
14785 | else | |
14786 | { | |
14787 | if (TARGET_MINIMAL_TOC) | |
14788 | fputs ("\t.long ", file); | |
14789 | else | |
14790 | fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],", | |
14791 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
14792 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
14793 | fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n", | |
14794 | k[0] & 0xffffffff, k[1] & 0xffffffff, | |
14795 | k[2] & 0xffffffff, k[3] & 0xffffffff); | |
14796 | return; | |
14797 | } | |
14798 | } | |
14799 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) | |
9878760c | 14800 | { |
042259f2 DE |
14801 | REAL_VALUE_TYPE rv; |
14802 | long k[2]; | |
0adc764e | 14803 | |
042259f2 DE |
14804 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
14805 | REAL_VALUE_TO_TARGET_DOUBLE (rv, k); | |
31bfaa0b | 14806 | |
13ded975 DE |
14807 | if (TARGET_64BIT) |
14808 | { | |
14809 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14810 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 14811 | else |
2f0552b6 AM |
14812 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
14813 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
14814 | fprintf (file, "0x%lx%08lx\n", | |
14815 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
14816 | return; |
14817 | } | |
1875cc88 | 14818 | else |
13ded975 DE |
14819 | { |
14820 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14821 | fputs ("\t.long ", file); |
13ded975 | 14822 | else |
2f0552b6 AM |
14823 | fprintf (file, "\t.tc FD_%lx_%lx[TC],", |
14824 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
14825 | fprintf (file, "0x%lx,0x%lx\n", | |
14826 | k[0] & 0xffffffff, k[1] & 0xffffffff); | |
13ded975 DE |
14827 | return; |
14828 | } | |
9878760c | 14829 | } |
a9098fd0 | 14830 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
9878760c | 14831 | { |
042259f2 DE |
14832 | REAL_VALUE_TYPE rv; |
14833 | long l; | |
9878760c | 14834 | |
042259f2 DE |
14835 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); |
14836 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
14837 | ||
31bfaa0b DE |
14838 | if (TARGET_64BIT) |
14839 | { | |
14840 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14841 | fputs (DOUBLE_INT_ASM_OP, file); |
31bfaa0b | 14842 | else |
2f0552b6 AM |
14843 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
14844 | fprintf (file, "0x%lx00000000\n", l & 0xffffffff); | |
31bfaa0b DE |
14845 | return; |
14846 | } | |
042259f2 | 14847 | else |
31bfaa0b DE |
14848 | { |
14849 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14850 | fputs ("\t.long ", file); |
31bfaa0b | 14851 | else |
2f0552b6 AM |
14852 | fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff); |
14853 | fprintf (file, "0x%lx\n", l & 0xffffffff); | |
31bfaa0b DE |
14854 | return; |
14855 | } | |
042259f2 | 14856 | } |
f176e826 | 14857 | else if (GET_MODE (x) == VOIDmode |
a9098fd0 | 14858 | && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)) |
042259f2 | 14859 | { |
e2c953b6 | 14860 | unsigned HOST_WIDE_INT low; |
042259f2 DE |
14861 | HOST_WIDE_INT high; |
14862 | ||
14863 | if (GET_CODE (x) == CONST_DOUBLE) | |
14864 | { | |
14865 | low = CONST_DOUBLE_LOW (x); | |
14866 | high = CONST_DOUBLE_HIGH (x); | |
14867 | } | |
14868 | else | |
14869 | #if HOST_BITS_PER_WIDE_INT == 32 | |
14870 | { | |
14871 | low = INTVAL (x); | |
0858c623 | 14872 | high = (low & 0x80000000) ? ~0 : 0; |
042259f2 DE |
14873 | } |
14874 | #else | |
14875 | { | |
0858c623 | 14876 | low = INTVAL (x) & 0xffffffff; |
042259f2 DE |
14877 | high = (HOST_WIDE_INT) INTVAL (x) >> 32; |
14878 | } | |
14879 | #endif | |
9878760c | 14880 | |
a9098fd0 GK |
14881 | /* TOC entries are always Pmode-sized, but since this |
14882 | is a bigendian machine then if we're putting smaller | |
14883 | integer constants in the TOC we have to pad them. | |
14884 | (This is still a win over putting the constants in | |
14885 | a separate constant pool, because then we'd have | |
02a4ec28 FS |
14886 | to have both a TOC entry _and_ the actual constant.) |
14887 | ||
14888 | For a 32-bit target, CONST_INT values are loaded and shifted | |
14889 | entirely within `low' and can be stored in one TOC entry. */ | |
14890 | ||
14891 | if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode)) | |
a9098fd0 | 14892 | abort ();/* It would be easy to make this work, but it doesn't now. */ |
02a4ec28 FS |
14893 | |
14894 | if (POINTER_SIZE > GET_MODE_BITSIZE (mode)) | |
fb52d8de AM |
14895 | { |
14896 | #if HOST_BITS_PER_WIDE_INT == 32 | |
14897 | lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode), | |
14898 | POINTER_SIZE, &low, &high, 0); | |
14899 | #else | |
14900 | low |= high << 32; | |
14901 | low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode); | |
14902 | high = (HOST_WIDE_INT) low >> 32; | |
14903 | low &= 0xffffffff; | |
14904 | #endif | |
14905 | } | |
a9098fd0 | 14906 | |
13ded975 DE |
14907 | if (TARGET_64BIT) |
14908 | { | |
14909 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14910 | fputs (DOUBLE_INT_ASM_OP, file); |
13ded975 | 14911 | else |
2f0552b6 AM |
14912 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
14913 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
14914 | fprintf (file, "0x%lx%08lx\n", | |
14915 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
13ded975 DE |
14916 | return; |
14917 | } | |
1875cc88 | 14918 | else |
13ded975 | 14919 | { |
02a4ec28 FS |
14920 | if (POINTER_SIZE < GET_MODE_BITSIZE (mode)) |
14921 | { | |
14922 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14923 | fputs ("\t.long ", file); |
02a4ec28 | 14924 | else |
2bfcf297 | 14925 | fprintf (file, "\t.tc ID_%lx_%lx[TC],", |
2f0552b6 AM |
14926 | (long) high & 0xffffffff, (long) low & 0xffffffff); |
14927 | fprintf (file, "0x%lx,0x%lx\n", | |
14928 | (long) high & 0xffffffff, (long) low & 0xffffffff); | |
02a4ec28 | 14929 | } |
13ded975 | 14930 | else |
02a4ec28 FS |
14931 | { |
14932 | if (TARGET_MINIMAL_TOC) | |
2bfcf297 | 14933 | fputs ("\t.long ", file); |
02a4ec28 | 14934 | else |
2f0552b6 AM |
14935 | fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff); |
14936 | fprintf (file, "0x%lx\n", (long) low & 0xffffffff); | |
02a4ec28 | 14937 | } |
13ded975 DE |
14938 | return; |
14939 | } | |
9878760c RK |
14940 | } |
14941 | ||
14942 | if (GET_CODE (x) == CONST) | |
14943 | { | |
2bfcf297 DB |
14944 | if (GET_CODE (XEXP (x, 0)) != PLUS) |
14945 | abort (); | |
14946 | ||
9878760c RK |
14947 | base = XEXP (XEXP (x, 0), 0); |
14948 | offset = INTVAL (XEXP (XEXP (x, 0), 1)); | |
14949 | } | |
f676971a | 14950 | |
9878760c RK |
14951 | if (GET_CODE (base) == SYMBOL_REF) |
14952 | name = XSTR (base, 0); | |
14953 | else if (GET_CODE (base) == LABEL_REF) | |
14954 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0))); | |
14955 | else if (GET_CODE (base) == CODE_LABEL) | |
14956 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base)); | |
14957 | else | |
14958 | abort (); | |
14959 | ||
772c5265 | 14960 | real_name = (*targetm.strip_name_encoding) (name); |
1875cc88 | 14961 | if (TARGET_MINIMAL_TOC) |
2bfcf297 | 14962 | fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file); |
1875cc88 JW |
14963 | else |
14964 | { | |
b6c9286a | 14965 | fprintf (file, "\t.tc %s", real_name); |
9878760c | 14966 | |
1875cc88 JW |
14967 | if (offset < 0) |
14968 | fprintf (file, ".N%d", - offset); | |
14969 | else if (offset) | |
14970 | fprintf (file, ".P%d", offset); | |
9878760c | 14971 | |
19d2d16f | 14972 | fputs ("[TC],", file); |
1875cc88 | 14973 | } |
581bc4de MM |
14974 | |
14975 | /* Currently C++ toc references to vtables can be emitted before it | |
14976 | is decided whether the vtable is public or private. If this is | |
14977 | the case, then the linker will eventually complain that there is | |
14978 | a TOC reference to an unknown section. Thus, for vtables only, | |
14979 | we emit the TOC reference to reference the symbol and not the | |
14980 | section. */ | |
28e510bd | 14981 | if (VTABLE_NAME_P (name)) |
581bc4de | 14982 | { |
54ee9799 | 14983 | RS6000_OUTPUT_BASENAME (file, name); |
581bc4de MM |
14984 | if (offset < 0) |
14985 | fprintf (file, "%d", offset); | |
14986 | else if (offset > 0) | |
14987 | fprintf (file, "+%d", offset); | |
14988 | } | |
14989 | else | |
14990 | output_addr_const (file, x); | |
19d2d16f | 14991 | putc ('\n', file); |
9878760c RK |
14992 | } |
14993 | \f | |
14994 | /* Output an assembler pseudo-op to write an ASCII string of N characters | |
14995 | starting at P to FILE. | |
14996 | ||
14997 | On the RS/6000, we have to do this using the .byte operation and | |
14998 | write out special characters outside the quoted string. | |
14999 | Also, the assembler is broken; very long strings are truncated, | |
a4f6c312 | 15000 | so we must artificially break them up early. */ |
9878760c RK |
15001 | |
15002 | void | |
a2369ed3 | 15003 | output_ascii (FILE *file, const char *p, int n) |
9878760c RK |
15004 | { |
15005 | char c; | |
15006 | int i, count_string; | |
d330fd93 KG |
15007 | const char *for_string = "\t.byte \""; |
15008 | const char *for_decimal = "\t.byte "; | |
15009 | const char *to_close = NULL; | |
9878760c RK |
15010 | |
15011 | count_string = 0; | |
15012 | for (i = 0; i < n; i++) | |
15013 | { | |
15014 | c = *p++; | |
15015 | if (c >= ' ' && c < 0177) | |
15016 | { | |
15017 | if (for_string) | |
15018 | fputs (for_string, file); | |
15019 | putc (c, file); | |
15020 | ||
15021 | /* Write two quotes to get one. */ | |
15022 | if (c == '"') | |
15023 | { | |
15024 | putc (c, file); | |
15025 | ++count_string; | |
15026 | } | |
15027 | ||
15028 | for_string = NULL; | |
15029 | for_decimal = "\"\n\t.byte "; | |
15030 | to_close = "\"\n"; | |
15031 | ++count_string; | |
15032 | ||
15033 | if (count_string >= 512) | |
15034 | { | |
15035 | fputs (to_close, file); | |
15036 | ||
15037 | for_string = "\t.byte \""; | |
15038 | for_decimal = "\t.byte "; | |
15039 | to_close = NULL; | |
15040 | count_string = 0; | |
15041 | } | |
15042 | } | |
15043 | else | |
15044 | { | |
15045 | if (for_decimal) | |
15046 | fputs (for_decimal, file); | |
15047 | fprintf (file, "%d", c); | |
15048 | ||
15049 | for_string = "\n\t.byte \""; | |
15050 | for_decimal = ", "; | |
15051 | to_close = "\n"; | |
15052 | count_string = 0; | |
15053 | } | |
15054 | } | |
15055 | ||
15056 | /* Now close the string if we have written one. Then end the line. */ | |
15057 | if (to_close) | |
9ebbca7d | 15058 | fputs (to_close, file); |
9878760c RK |
15059 | } |
15060 | \f | |
15061 | /* Generate a unique section name for FILENAME for a section type | |
15062 | represented by SECTION_DESC. Output goes into BUF. | |
15063 | ||
15064 | SECTION_DESC can be any string, as long as it is different for each | |
15065 | possible section type. | |
15066 | ||
15067 | We name the section in the same manner as xlc. The name begins with an | |
15068 | underscore followed by the filename (after stripping any leading directory | |
11e5fe42 RK |
15069 | names) with the last period replaced by the string SECTION_DESC. If |
15070 | FILENAME does not contain a period, SECTION_DESC is appended to the end of | |
15071 | the name. */ | |
9878760c RK |
15072 | |
15073 | void | |
f676971a | 15074 | rs6000_gen_section_name (char **buf, const char *filename, |
a2369ed3 | 15075 | const char *section_desc) |
9878760c | 15076 | { |
9ebbca7d | 15077 | const char *q, *after_last_slash, *last_period = 0; |
9878760c RK |
15078 | char *p; |
15079 | int len; | |
9878760c RK |
15080 | |
15081 | after_last_slash = filename; | |
15082 | for (q = filename; *q; q++) | |
11e5fe42 RK |
15083 | { |
15084 | if (*q == '/') | |
15085 | after_last_slash = q + 1; | |
15086 | else if (*q == '.') | |
15087 | last_period = q; | |
15088 | } | |
9878760c | 15089 | |
11e5fe42 | 15090 | len = strlen (after_last_slash) + strlen (section_desc) + 2; |
6d9f628e | 15091 | *buf = (char *) xmalloc (len); |
9878760c RK |
15092 | |
15093 | p = *buf; | |
15094 | *p++ = '_'; | |
15095 | ||
15096 | for (q = after_last_slash; *q; q++) | |
15097 | { | |
11e5fe42 | 15098 | if (q == last_period) |
9878760c RK |
15099 | { |
15100 | strcpy (p, section_desc); | |
15101 | p += strlen (section_desc); | |
e3981aab | 15102 | break; |
9878760c RK |
15103 | } |
15104 | ||
e9a780ec | 15105 | else if (ISALNUM (*q)) |
9878760c RK |
15106 | *p++ = *q; |
15107 | } | |
15108 | ||
11e5fe42 | 15109 | if (last_period == 0) |
9878760c RK |
15110 | strcpy (p, section_desc); |
15111 | else | |
15112 | *p = '\0'; | |
15113 | } | |
e165f3f0 | 15114 | \f |
a4f6c312 | 15115 | /* Emit profile function. */ |
411707f4 | 15116 | |
411707f4 | 15117 | void |
a2369ed3 | 15118 | output_profile_hook (int labelno ATTRIBUTE_UNUSED) |
411707f4 | 15119 | { |
ffcfcb5f AM |
15120 | if (TARGET_PROFILE_KERNEL) |
15121 | return; | |
15122 | ||
8480e480 CC |
15123 | if (DEFAULT_ABI == ABI_AIX) |
15124 | { | |
9739c90c JJ |
15125 | #ifndef NO_PROFILE_COUNTERS |
15126 | # define NO_PROFILE_COUNTERS 0 | |
15127 | #endif | |
f676971a | 15128 | if (NO_PROFILE_COUNTERS) |
9739c90c JJ |
15129 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0); |
15130 | else | |
15131 | { | |
15132 | char buf[30]; | |
15133 | const char *label_name; | |
15134 | rtx fun; | |
411707f4 | 15135 | |
9739c90c JJ |
15136 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
15137 | label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf)); | |
15138 | fun = gen_rtx_SYMBOL_REF (Pmode, label_name); | |
411707f4 | 15139 | |
9739c90c JJ |
15140 | emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1, |
15141 | fun, Pmode); | |
15142 | } | |
8480e480 | 15143 | } |
ee890fe2 SS |
15144 | else if (DEFAULT_ABI == ABI_DARWIN) |
15145 | { | |
d5fa86ba | 15146 | const char *mcount_name = RS6000_MCOUNT; |
ee890fe2 SS |
15147 | int caller_addr_regno = LINK_REGISTER_REGNUM; |
15148 | ||
15149 | /* Be conservative and always set this, at least for now. */ | |
15150 | current_function_uses_pic_offset_table = 1; | |
15151 | ||
15152 | #if TARGET_MACHO | |
15153 | /* For PIC code, set up a stub and collect the caller's address | |
15154 | from r0, which is where the prologue puts it. */ | |
11abc112 MM |
15155 | if (MACHOPIC_INDIRECT |
15156 | && current_function_uses_pic_offset_table) | |
15157 | caller_addr_regno = 0; | |
ee890fe2 SS |
15158 | #endif |
15159 | emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name), | |
15160 | 0, VOIDmode, 1, | |
15161 | gen_rtx_REG (Pmode, caller_addr_regno), Pmode); | |
15162 | } | |
411707f4 CC |
15163 | } |
15164 | ||
a4f6c312 | 15165 | /* Write function profiler code. */ |
e165f3f0 RK |
15166 | |
15167 | void | |
a2369ed3 | 15168 | output_function_profiler (FILE *file, int labelno) |
e165f3f0 | 15169 | { |
3daf36a4 | 15170 | char buf[100]; |
09eeeacb | 15171 | int save_lr = 8; |
e165f3f0 | 15172 | |
38c1f2d7 | 15173 | switch (DEFAULT_ABI) |
3daf36a4 | 15174 | { |
38c1f2d7 MM |
15175 | default: |
15176 | abort (); | |
15177 | ||
15178 | case ABI_V4: | |
09eeeacb | 15179 | save_lr = 4; |
09eeeacb AM |
15180 | if (!TARGET_32BIT) |
15181 | { | |
15182 | warning ("no profiling of 64-bit code for this ABI"); | |
15183 | return; | |
15184 | } | |
ffcfcb5f | 15185 | ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno); |
38c1f2d7 MM |
15186 | fprintf (file, "\tmflr %s\n", reg_names[0]); |
15187 | if (flag_pic == 1) | |
15188 | { | |
dfdfa60f | 15189 | fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file); |
09eeeacb AM |
15190 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
15191 | reg_names[0], save_lr, reg_names[1]); | |
17167fd8 | 15192 | asm_fprintf (file, "\tmflr %s\n", reg_names[12]); |
dfdfa60f | 15193 | asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]); |
38c1f2d7 | 15194 | assemble_name (file, buf); |
17167fd8 | 15195 | asm_fprintf (file, "@got(%s)\n", reg_names[12]); |
38c1f2d7 | 15196 | } |
9ebbca7d | 15197 | else if (flag_pic > 1) |
38c1f2d7 | 15198 | { |
09eeeacb AM |
15199 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
15200 | reg_names[0], save_lr, reg_names[1]); | |
9ebbca7d GK |
15201 | /* Now, we need to get the address of the label. */ |
15202 | fputs ("\tbl 1f\n\t.long ", file); | |
034e84c4 | 15203 | assemble_name (file, buf); |
9ebbca7d GK |
15204 | fputs ("-.\n1:", file); |
15205 | asm_fprintf (file, "\tmflr %s\n", reg_names[11]); | |
f676971a | 15206 | asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n", |
9ebbca7d GK |
15207 | reg_names[0], reg_names[11]); |
15208 | asm_fprintf (file, "\t{cax|add} %s,%s,%s\n", | |
15209 | reg_names[0], reg_names[0], reg_names[11]); | |
38c1f2d7 | 15210 | } |
38c1f2d7 MM |
15211 | else |
15212 | { | |
17167fd8 | 15213 | asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]); |
38c1f2d7 | 15214 | assemble_name (file, buf); |
dfdfa60f | 15215 | fputs ("@ha\n", file); |
09eeeacb AM |
15216 | asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n", |
15217 | reg_names[0], save_lr, reg_names[1]); | |
a260abc9 | 15218 | asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]); |
38c1f2d7 | 15219 | assemble_name (file, buf); |
17167fd8 | 15220 | asm_fprintf (file, "@l(%s)\n", reg_names[12]); |
38c1f2d7 MM |
15221 | } |
15222 | ||
50d440bc | 15223 | /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */ |
3b6ce0af DE |
15224 | fprintf (file, "\tbl %s%s\n", |
15225 | RS6000_MCOUNT, flag_pic ? "@plt" : ""); | |
38c1f2d7 MM |
15226 | break; |
15227 | ||
15228 | case ABI_AIX: | |
ee890fe2 | 15229 | case ABI_DARWIN: |
ffcfcb5f AM |
15230 | if (!TARGET_PROFILE_KERNEL) |
15231 | { | |
a3c9585f | 15232 | /* Don't do anything, done in output_profile_hook (). */ |
ffcfcb5f AM |
15233 | } |
15234 | else | |
15235 | { | |
15236 | if (TARGET_32BIT) | |
15237 | abort (); | |
15238 | ||
15239 | asm_fprintf (file, "\tmflr %s\n", reg_names[0]); | |
15240 | asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]); | |
15241 | ||
6de9cd9a | 15242 | if (cfun->static_chain_decl != NULL) |
ffcfcb5f AM |
15243 | { |
15244 | asm_fprintf (file, "\tstd %s,24(%s)\n", | |
15245 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
15246 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
15247 | asm_fprintf (file, "\tld %s,24(%s)\n", | |
15248 | reg_names[STATIC_CHAIN_REGNUM], reg_names[1]); | |
15249 | } | |
15250 | else | |
15251 | fprintf (file, "\tbl %s\n", RS6000_MCOUNT); | |
15252 | } | |
38c1f2d7 MM |
15253 | break; |
15254 | } | |
e165f3f0 | 15255 | } |
a251ffd0 | 15256 | |
b54cf83a | 15257 | \f |
b54cf83a DE |
15258 | /* Power4 load update and store update instructions are cracked into a |
15259 | load or store and an integer insn which are executed in the same cycle. | |
15260 | Branches have their own dispatch slot which does not count against the | |
15261 | GCC issue rate, but it changes the program flow so there are no other | |
15262 | instructions to issue in this cycle. */ | |
15263 | ||
15264 | static int | |
f676971a EC |
15265 | rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED, |
15266 | int verbose ATTRIBUTE_UNUSED, | |
a2369ed3 | 15267 | rtx insn, int more) |
b54cf83a DE |
15268 | { |
15269 | if (GET_CODE (PATTERN (insn)) == USE | |
15270 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
15271 | return more; | |
15272 | ||
ec507f2d | 15273 | if (rs6000_sched_groups) |
b54cf83a | 15274 | { |
cbe26ab8 DN |
15275 | if (is_microcoded_insn (insn)) |
15276 | return 0; | |
15277 | else if (is_cracked_insn (insn)) | |
15278 | return more > 2 ? more - 2 : 0; | |
b54cf83a | 15279 | } |
165b263e DE |
15280 | |
15281 | return more - 1; | |
b54cf83a DE |
15282 | } |
15283 | ||
a251ffd0 TG |
15284 | /* Adjust the cost of a scheduling dependency. Return the new cost of |
15285 | a dependency LINK or INSN on DEP_INSN. COST is the current cost. */ | |
15286 | ||
c237e94a | 15287 | static int |
0a4f0294 | 15288 | rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost) |
a251ffd0 TG |
15289 | { |
15290 | if (! recog_memoized (insn)) | |
15291 | return 0; | |
15292 | ||
15293 | if (REG_NOTE_KIND (link) != 0) | |
15294 | return 0; | |
15295 | ||
15296 | if (REG_NOTE_KIND (link) == 0) | |
15297 | { | |
ed947a96 DJ |
15298 | /* Data dependency; DEP_INSN writes a register that INSN reads |
15299 | some cycles later. */ | |
15300 | switch (get_attr_type (insn)) | |
15301 | { | |
15302 | case TYPE_JMPREG: | |
309323c2 | 15303 | /* Tell the first scheduling pass about the latency between |
ed947a96 DJ |
15304 | a mtctr and bctr (and mtlr and br/blr). The first |
15305 | scheduling pass will not know about this latency since | |
15306 | the mtctr instruction, which has the latency associated | |
15307 | to it, will be generated by reload. */ | |
309323c2 | 15308 | return TARGET_POWER ? 5 : 4; |
ed947a96 DJ |
15309 | case TYPE_BRANCH: |
15310 | /* Leave some extra cycles between a compare and its | |
15311 | dependent branch, to inhibit expensive mispredicts. */ | |
309323c2 DE |
15312 | if ((rs6000_cpu_attr == CPU_PPC603 |
15313 | || rs6000_cpu_attr == CPU_PPC604 | |
15314 | || rs6000_cpu_attr == CPU_PPC604E | |
15315 | || rs6000_cpu_attr == CPU_PPC620 | |
15316 | || rs6000_cpu_attr == CPU_PPC630 | |
15317 | || rs6000_cpu_attr == CPU_PPC750 | |
15318 | || rs6000_cpu_attr == CPU_PPC7400 | |
15319 | || rs6000_cpu_attr == CPU_PPC7450 | |
ec507f2d DE |
15320 | || rs6000_cpu_attr == CPU_POWER4 |
15321 | || rs6000_cpu_attr == CPU_POWER5) | |
ed947a96 DJ |
15322 | && recog_memoized (dep_insn) |
15323 | && (INSN_CODE (dep_insn) >= 0) | |
b54cf83a DE |
15324 | && (get_attr_type (dep_insn) == TYPE_CMP |
15325 | || get_attr_type (dep_insn) == TYPE_COMPARE | |
ed947a96 | 15326 | || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE |
9259f3b0 DE |
15327 | || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE |
15328 | || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE | |
ed947a96 | 15329 | || get_attr_type (dep_insn) == TYPE_FPCOMPARE |
b54cf83a DE |
15330 | || get_attr_type (dep_insn) == TYPE_CR_LOGICAL |
15331 | || get_attr_type (dep_insn) == TYPE_DELAYED_CR)) | |
ed947a96 DJ |
15332 | return cost + 2; |
15333 | default: | |
15334 | break; | |
15335 | } | |
a251ffd0 TG |
15336 | /* Fall out to return default cost. */ |
15337 | } | |
15338 | ||
15339 | return cost; | |
15340 | } | |
b6c9286a | 15341 | |
cbe26ab8 | 15342 | /* The function returns a true if INSN is microcoded. |
839a4992 | 15343 | Return false otherwise. */ |
cbe26ab8 DN |
15344 | |
15345 | static bool | |
15346 | is_microcoded_insn (rtx insn) | |
15347 | { | |
15348 | if (!insn || !INSN_P (insn) | |
15349 | || GET_CODE (PATTERN (insn)) == USE | |
15350 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
15351 | return false; | |
15352 | ||
ec507f2d | 15353 | if (rs6000_sched_groups) |
cbe26ab8 DN |
15354 | { |
15355 | enum attr_type type = get_attr_type (insn); | |
15356 | if (type == TYPE_LOAD_EXT_U | |
15357 | || type == TYPE_LOAD_EXT_UX | |
15358 | || type == TYPE_LOAD_UX | |
15359 | || type == TYPE_STORE_UX | |
15360 | || type == TYPE_MFCR) | |
15361 | return true; | |
15362 | } | |
15363 | ||
15364 | return false; | |
15365 | } | |
15366 | ||
5c425df5 | 15367 | /* The function returns a nonzero value if INSN can be scheduled only |
cbe26ab8 DN |
15368 | as the first insn in a dispatch group ("dispatch-slot restricted"). |
15369 | In this case, the returned value indicates how many dispatch slots | |
15370 | the insn occupies (at the beginning of the group). | |
79ae11c4 DN |
15371 | Return 0 otherwise. */ |
15372 | ||
cbe26ab8 | 15373 | static int |
79ae11c4 DN |
15374 | is_dispatch_slot_restricted (rtx insn) |
15375 | { | |
15376 | enum attr_type type; | |
15377 | ||
ec507f2d | 15378 | if (!rs6000_sched_groups) |
79ae11c4 DN |
15379 | return 0; |
15380 | ||
15381 | if (!insn | |
15382 | || insn == NULL_RTX | |
15383 | || GET_CODE (insn) == NOTE | |
15384 | || GET_CODE (PATTERN (insn)) == USE | |
15385 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
15386 | return 0; | |
15387 | ||
15388 | type = get_attr_type (insn); | |
15389 | ||
ec507f2d DE |
15390 | switch (type) |
15391 | { | |
15392 | case TYPE_MFCR: | |
15393 | case TYPE_MFCRF: | |
15394 | case TYPE_MTCR: | |
15395 | case TYPE_DELAYED_CR: | |
15396 | case TYPE_CR_LOGICAL: | |
15397 | case TYPE_MTJMPR: | |
15398 | case TYPE_MFJMPR: | |
15399 | return 1; | |
15400 | case TYPE_IDIV: | |
15401 | case TYPE_LDIV: | |
15402 | return 2; | |
15403 | default: | |
15404 | if (rs6000_cpu == PROCESSOR_POWER5 | |
15405 | && is_cracked_insn (insn)) | |
15406 | return 2; | |
15407 | return 0; | |
15408 | } | |
79ae11c4 DN |
15409 | } |
15410 | ||
cbe26ab8 DN |
15411 | /* The function returns true if INSN is cracked into 2 instructions |
15412 | by the processor (and therefore occupies 2 issue slots). */ | |
15413 | ||
15414 | static bool | |
15415 | is_cracked_insn (rtx insn) | |
15416 | { | |
15417 | if (!insn || !INSN_P (insn) | |
15418 | || GET_CODE (PATTERN (insn)) == USE | |
15419 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
15420 | return false; | |
15421 | ||
ec507f2d | 15422 | if (rs6000_sched_groups) |
cbe26ab8 DN |
15423 | { |
15424 | enum attr_type type = get_attr_type (insn); | |
15425 | if (type == TYPE_LOAD_U || type == TYPE_STORE_U | |
15426 | || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U | |
15427 | || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX | |
15428 | || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR | |
15429 | || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE | |
15430 | || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE | |
15431 | || type == TYPE_IDIV || type == TYPE_LDIV | |
15432 | || type == TYPE_INSERT_WORD) | |
15433 | return true; | |
15434 | } | |
15435 | ||
15436 | return false; | |
15437 | } | |
15438 | ||
15439 | /* The function returns true if INSN can be issued only from | |
a3c9585f | 15440 | the branch slot. */ |
cbe26ab8 DN |
15441 | |
15442 | static bool | |
15443 | is_branch_slot_insn (rtx insn) | |
15444 | { | |
15445 | if (!insn || !INSN_P (insn) | |
15446 | || GET_CODE (PATTERN (insn)) == USE | |
15447 | || GET_CODE (PATTERN (insn)) == CLOBBER) | |
15448 | return false; | |
15449 | ||
ec507f2d | 15450 | if (rs6000_sched_groups) |
cbe26ab8 DN |
15451 | { |
15452 | enum attr_type type = get_attr_type (insn); | |
15453 | if (type == TYPE_BRANCH || type == TYPE_JMPREG) | |
f676971a | 15454 | return true; |
cbe26ab8 DN |
15455 | return false; |
15456 | } | |
15457 | ||
15458 | return false; | |
15459 | } | |
79ae11c4 | 15460 | |
a4f6c312 | 15461 | /* A C statement (sans semicolon) to update the integer scheduling |
79ae11c4 DN |
15462 | priority INSN_PRIORITY (INSN). Increase the priority to execute the |
15463 | INSN earlier, reduce the priority to execute INSN later. Do not | |
a4f6c312 SS |
15464 | define this macro if you do not need to adjust the scheduling |
15465 | priorities of insns. */ | |
bef84347 | 15466 | |
c237e94a | 15467 | static int |
a2369ed3 | 15468 | rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority) |
bef84347 | 15469 | { |
a4f6c312 SS |
15470 | /* On machines (like the 750) which have asymmetric integer units, |
15471 | where one integer unit can do multiply and divides and the other | |
15472 | can't, reduce the priority of multiply/divide so it is scheduled | |
15473 | before other integer operations. */ | |
bef84347 VM |
15474 | |
15475 | #if 0 | |
2c3c49de | 15476 | if (! INSN_P (insn)) |
bef84347 VM |
15477 | return priority; |
15478 | ||
15479 | if (GET_CODE (PATTERN (insn)) == USE) | |
15480 | return priority; | |
15481 | ||
15482 | switch (rs6000_cpu_attr) { | |
15483 | case CPU_PPC750: | |
15484 | switch (get_attr_type (insn)) | |
15485 | { | |
15486 | default: | |
15487 | break; | |
15488 | ||
15489 | case TYPE_IMUL: | |
15490 | case TYPE_IDIV: | |
3cb999d8 DE |
15491 | fprintf (stderr, "priority was %#x (%d) before adjustment\n", |
15492 | priority, priority); | |
bef84347 VM |
15493 | if (priority >= 0 && priority < 0x01000000) |
15494 | priority >>= 3; | |
15495 | break; | |
15496 | } | |
15497 | } | |
15498 | #endif | |
15499 | ||
79ae11c4 DN |
15500 | if (is_dispatch_slot_restricted (insn) |
15501 | && reload_completed | |
f676971a | 15502 | && current_sched_info->sched_max_insns_priority |
79ae11c4 DN |
15503 | && rs6000_sched_restricted_insns_priority) |
15504 | { | |
15505 | ||
15506 | /* Prioritize insns that can be dispatched only in the first dispatch slot. */ | |
15507 | if (rs6000_sched_restricted_insns_priority == 1) | |
f676971a EC |
15508 | /* Attach highest priority to insn. This means that in |
15509 | haifa-sched.c:ready_sort(), dispatch-slot restriction considerations | |
79ae11c4 | 15510 | precede 'priority' (critical path) considerations. */ |
f676971a | 15511 | return current_sched_info->sched_max_insns_priority; |
79ae11c4 | 15512 | else if (rs6000_sched_restricted_insns_priority == 2) |
f676971a | 15513 | /* Increase priority of insn by a minimal amount. This means that in |
79ae11c4 DN |
15514 | haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations |
15515 | precede dispatch-slot restriction considerations. */ | |
f676971a EC |
15516 | return (priority + 1); |
15517 | } | |
79ae11c4 | 15518 | |
bef84347 VM |
15519 | return priority; |
15520 | } | |
15521 | ||
a4f6c312 SS |
15522 | /* Return how many instructions the machine can issue per cycle. */ |
15523 | ||
c237e94a | 15524 | static int |
863d938c | 15525 | rs6000_issue_rate (void) |
b6c9286a | 15526 | { |
3317bab1 DE |
15527 | /* Use issue rate of 1 for first scheduling pass to decrease degradation. */ |
15528 | if (!reload_completed) | |
15529 | return 1; | |
15530 | ||
b6c9286a | 15531 | switch (rs6000_cpu_attr) { |
3cb999d8 DE |
15532 | case CPU_RIOS1: /* ? */ |
15533 | case CPU_RS64A: | |
15534 | case CPU_PPC601: /* ? */ | |
ed947a96 | 15535 | case CPU_PPC7450: |
3cb999d8 | 15536 | return 3; |
b54cf83a | 15537 | case CPU_PPC440: |
b6c9286a | 15538 | case CPU_PPC603: |
bef84347 | 15539 | case CPU_PPC750: |
ed947a96 | 15540 | case CPU_PPC7400: |
be12c2b0 | 15541 | case CPU_PPC8540: |
f676971a | 15542 | return 2; |
3cb999d8 | 15543 | case CPU_RIOS2: |
b6c9286a | 15544 | case CPU_PPC604: |
19684119 | 15545 | case CPU_PPC604E: |
b6c9286a | 15546 | case CPU_PPC620: |
3cb999d8 | 15547 | case CPU_PPC630: |
b6c9286a | 15548 | return 4; |
cbe26ab8 | 15549 | case CPU_POWER4: |
ec507f2d | 15550 | case CPU_POWER5: |
cbe26ab8 | 15551 | return 5; |
b6c9286a MM |
15552 | default: |
15553 | return 1; | |
15554 | } | |
15555 | } | |
15556 | ||
be12c2b0 VM |
15557 | /* Return how many instructions to look ahead for better insn |
15558 | scheduling. */ | |
15559 | ||
15560 | static int | |
863d938c | 15561 | rs6000_use_sched_lookahead (void) |
be12c2b0 VM |
15562 | { |
15563 | if (rs6000_cpu_attr == CPU_PPC8540) | |
15564 | return 4; | |
15565 | return 0; | |
15566 | } | |
15567 | ||
569fa502 DN |
15568 | /* Determine is PAT refers to memory. */ |
15569 | ||
15570 | static bool | |
15571 | is_mem_ref (rtx pat) | |
15572 | { | |
15573 | const char * fmt; | |
15574 | int i, j; | |
15575 | bool ret = false; | |
15576 | ||
15577 | if (GET_CODE (pat) == MEM) | |
15578 | return true; | |
15579 | ||
15580 | /* Recursively process the pattern. */ | |
15581 | fmt = GET_RTX_FORMAT (GET_CODE (pat)); | |
15582 | ||
15583 | for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--) | |
15584 | { | |
15585 | if (fmt[i] == 'e') | |
15586 | ret |= is_mem_ref (XEXP (pat, i)); | |
15587 | else if (fmt[i] == 'E') | |
15588 | for (j = XVECLEN (pat, i) - 1; j >= 0; j--) | |
15589 | ret |= is_mem_ref (XVECEXP (pat, i, j)); | |
15590 | } | |
15591 | ||
15592 | return ret; | |
15593 | } | |
15594 | ||
15595 | /* Determine if PAT is a PATTERN of a load insn. */ | |
f676971a | 15596 | |
569fa502 DN |
15597 | static bool |
15598 | is_load_insn1 (rtx pat) | |
15599 | { | |
15600 | if (!pat || pat == NULL_RTX) | |
15601 | return false; | |
15602 | ||
15603 | if (GET_CODE (pat) == SET) | |
15604 | return is_mem_ref (SET_SRC (pat)); | |
15605 | ||
15606 | if (GET_CODE (pat) == PARALLEL) | |
15607 | { | |
15608 | int i; | |
15609 | ||
15610 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
15611 | if (is_load_insn1 (XVECEXP (pat, 0, i))) | |
15612 | return true; | |
15613 | } | |
15614 | ||
15615 | return false; | |
15616 | } | |
15617 | ||
15618 | /* Determine if INSN loads from memory. */ | |
15619 | ||
15620 | static bool | |
15621 | is_load_insn (rtx insn) | |
15622 | { | |
15623 | if (!insn || !INSN_P (insn)) | |
15624 | return false; | |
15625 | ||
15626 | if (GET_CODE (insn) == CALL_INSN) | |
15627 | return false; | |
15628 | ||
15629 | return is_load_insn1 (PATTERN (insn)); | |
15630 | } | |
15631 | ||
15632 | /* Determine if PAT is a PATTERN of a store insn. */ | |
15633 | ||
15634 | static bool | |
15635 | is_store_insn1 (rtx pat) | |
15636 | { | |
15637 | if (!pat || pat == NULL_RTX) | |
15638 | return false; | |
15639 | ||
15640 | if (GET_CODE (pat) == SET) | |
15641 | return is_mem_ref (SET_DEST (pat)); | |
15642 | ||
15643 | if (GET_CODE (pat) == PARALLEL) | |
15644 | { | |
15645 | int i; | |
15646 | ||
15647 | for (i = 0; i < XVECLEN (pat, 0); i++) | |
15648 | if (is_store_insn1 (XVECEXP (pat, 0, i))) | |
15649 | return true; | |
15650 | } | |
15651 | ||
15652 | return false; | |
15653 | } | |
15654 | ||
15655 | /* Determine if INSN stores to memory. */ | |
15656 | ||
15657 | static bool | |
15658 | is_store_insn (rtx insn) | |
15659 | { | |
15660 | if (!insn || !INSN_P (insn)) | |
15661 | return false; | |
15662 | ||
15663 | return is_store_insn1 (PATTERN (insn)); | |
15664 | } | |
15665 | ||
15666 | /* Returns whether the dependence between INSN and NEXT is considered | |
15667 | costly by the given target. */ | |
15668 | ||
15669 | static bool | |
15670 | rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance) | |
f676971a | 15671 | { |
569fa502 | 15672 | /* If the flag is not enbled - no dependence is considered costly; |
f676971a | 15673 | allow all dependent insns in the same group. |
569fa502 DN |
15674 | This is the most aggressive option. */ |
15675 | if (rs6000_sched_costly_dep == no_dep_costly) | |
15676 | return false; | |
15677 | ||
f676971a | 15678 | /* If the flag is set to 1 - a dependence is always considered costly; |
569fa502 DN |
15679 | do not allow dependent instructions in the same group. |
15680 | This is the most conservative option. */ | |
15681 | if (rs6000_sched_costly_dep == all_deps_costly) | |
f676971a | 15682 | return true; |
569fa502 | 15683 | |
f676971a EC |
15684 | if (rs6000_sched_costly_dep == store_to_load_dep_costly |
15685 | && is_load_insn (next) | |
569fa502 DN |
15686 | && is_store_insn (insn)) |
15687 | /* Prevent load after store in the same group. */ | |
15688 | return true; | |
15689 | ||
15690 | if (rs6000_sched_costly_dep == true_store_to_load_dep_costly | |
f676971a | 15691 | && is_load_insn (next) |
569fa502 DN |
15692 | && is_store_insn (insn) |
15693 | && (!link || (int) REG_NOTE_KIND (link) == 0)) | |
15694 | /* Prevent load after store in the same group if it is a true dependence. */ | |
15695 | return true; | |
f676971a EC |
15696 | |
15697 | /* The flag is set to X; dependences with latency >= X are considered costly, | |
569fa502 DN |
15698 | and will not be scheduled in the same group. */ |
15699 | if (rs6000_sched_costly_dep <= max_dep_latency | |
15700 | && ((cost - distance) >= (int)rs6000_sched_costly_dep)) | |
15701 | return true; | |
15702 | ||
15703 | return false; | |
15704 | } | |
15705 | ||
f676971a | 15706 | /* Return the next insn after INSN that is found before TAIL is reached, |
cbe26ab8 DN |
15707 | skipping any "non-active" insns - insns that will not actually occupy |
15708 | an issue slot. Return NULL_RTX if such an insn is not found. */ | |
15709 | ||
15710 | static rtx | |
15711 | get_next_active_insn (rtx insn, rtx tail) | |
15712 | { | |
15713 | rtx next_insn; | |
15714 | ||
15715 | if (!insn || insn == tail) | |
15716 | return NULL_RTX; | |
15717 | ||
15718 | next_insn = NEXT_INSN (insn); | |
15719 | ||
15720 | while (next_insn | |
15721 | && next_insn != tail | |
15722 | && (GET_CODE(next_insn) == NOTE | |
15723 | || GET_CODE (PATTERN (next_insn)) == USE | |
15724 | || GET_CODE (PATTERN (next_insn)) == CLOBBER)) | |
15725 | { | |
15726 | next_insn = NEXT_INSN (next_insn); | |
15727 | } | |
15728 | ||
15729 | if (!next_insn || next_insn == tail) | |
15730 | return NULL_RTX; | |
15731 | ||
15732 | return next_insn; | |
15733 | } | |
15734 | ||
839a4992 | 15735 | /* Return whether the presence of INSN causes a dispatch group termination |
cbe26ab8 DN |
15736 | of group WHICH_GROUP. |
15737 | ||
15738 | If WHICH_GROUP == current_group, this function will return true if INSN | |
15739 | causes the termination of the current group (i.e, the dispatch group to | |
15740 | which INSN belongs). This means that INSN will be the last insn in the | |
15741 | group it belongs to. | |
15742 | ||
15743 | If WHICH_GROUP == previous_group, this function will return true if INSN | |
15744 | causes the termination of the previous group (i.e, the dispatch group that | |
15745 | precedes the group to which INSN belongs). This means that INSN will be | |
15746 | the first insn in the group it belongs to). */ | |
15747 | ||
15748 | static bool | |
15749 | insn_terminates_group_p (rtx insn, enum group_termination which_group) | |
15750 | { | |
15751 | enum attr_type type; | |
15752 | ||
15753 | if (! insn) | |
15754 | return false; | |
569fa502 | 15755 | |
cbe26ab8 DN |
15756 | type = get_attr_type (insn); |
15757 | ||
15758 | if (is_microcoded_insn (insn)) | |
15759 | return true; | |
15760 | ||
15761 | if (which_group == current_group) | |
15762 | { | |
15763 | if (is_branch_slot_insn (insn)) | |
15764 | return true; | |
15765 | return false; | |
15766 | } | |
15767 | else if (which_group == previous_group) | |
15768 | { | |
15769 | if (is_dispatch_slot_restricted (insn)) | |
15770 | return true; | |
15771 | return false; | |
15772 | } | |
15773 | ||
15774 | return false; | |
15775 | } | |
15776 | ||
839a4992 | 15777 | /* Return true if it is recommended to keep NEXT_INSN "far" (in a separate |
cbe26ab8 DN |
15778 | dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */ |
15779 | ||
15780 | static bool | |
15781 | is_costly_group (rtx *group_insns, rtx next_insn) | |
15782 | { | |
15783 | int i; | |
15784 | rtx link; | |
15785 | int cost; | |
15786 | int issue_rate = rs6000_issue_rate (); | |
15787 | ||
15788 | for (i = 0; i < issue_rate; i++) | |
15789 | { | |
15790 | rtx insn = group_insns[i]; | |
15791 | if (!insn) | |
15792 | continue; | |
15793 | for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1)) | |
15794 | { | |
15795 | rtx next = XEXP (link, 0); | |
15796 | if (next == next_insn) | |
15797 | { | |
15798 | cost = insn_cost (insn, link, next_insn); | |
15799 | if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0)) | |
15800 | return true; | |
15801 | } | |
15802 | } | |
15803 | } | |
15804 | ||
15805 | return false; | |
15806 | } | |
15807 | ||
f676971a | 15808 | /* Utility of the function redefine_groups. |
cbe26ab8 DN |
15809 | Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS |
15810 | in the same dispatch group. If so, insert nops before NEXT_INSN, in order | |
15811 | to keep it "far" (in a separate group) from GROUP_INSNS, following | |
15812 | one of the following schemes, depending on the value of the flag | |
15813 | -minsert_sched_nops = X: | |
15814 | (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed | |
839a4992 | 15815 | in order to force NEXT_INSN into a separate group. |
f676971a EC |
15816 | (2) X < sched_finish_regroup_exact: insert exactly X nops. |
15817 | GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop | |
cbe26ab8 DN |
15818 | insertion (has a group just ended, how many vacant issue slots remain in the |
15819 | last group, and how many dispatch groups were encountered so far). */ | |
15820 | ||
f676971a | 15821 | static int |
cbe26ab8 DN |
15822 | force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn, |
15823 | bool *group_end, int can_issue_more, int *group_count) | |
15824 | { | |
15825 | rtx nop; | |
15826 | bool force; | |
15827 | int issue_rate = rs6000_issue_rate (); | |
15828 | bool end = *group_end; | |
15829 | int i; | |
15830 | ||
15831 | if (next_insn == NULL_RTX) | |
15832 | return can_issue_more; | |
15833 | ||
15834 | if (rs6000_sched_insert_nops > sched_finish_regroup_exact) | |
15835 | return can_issue_more; | |
15836 | ||
15837 | force = is_costly_group (group_insns, next_insn); | |
15838 | if (!force) | |
15839 | return can_issue_more; | |
15840 | ||
15841 | if (sched_verbose > 6) | |
15842 | fprintf (dump,"force: group count = %d, can_issue_more = %d\n", | |
15843 | *group_count ,can_issue_more); | |
15844 | ||
15845 | if (rs6000_sched_insert_nops == sched_finish_regroup_exact) | |
15846 | { | |
15847 | if (*group_end) | |
15848 | can_issue_more = 0; | |
15849 | ||
15850 | /* Since only a branch can be issued in the last issue_slot, it is | |
15851 | sufficient to insert 'can_issue_more - 1' nops if next_insn is not | |
15852 | a branch. If next_insn is a branch, we insert 'can_issue_more' nops; | |
15853 | in this case the last nop will start a new group and the branch will be | |
15854 | forced to the new group. */ | |
15855 | if (can_issue_more && !is_branch_slot_insn (next_insn)) | |
15856 | can_issue_more--; | |
15857 | ||
15858 | while (can_issue_more > 0) | |
15859 | { | |
15860 | nop = gen_nop(); | |
15861 | emit_insn_before (nop, next_insn); | |
15862 | can_issue_more--; | |
15863 | } | |
15864 | ||
15865 | *group_end = true; | |
15866 | return 0; | |
f676971a | 15867 | } |
cbe26ab8 DN |
15868 | |
15869 | if (rs6000_sched_insert_nops < sched_finish_regroup_exact) | |
15870 | { | |
15871 | int n_nops = rs6000_sched_insert_nops; | |
15872 | ||
f676971a | 15873 | /* Nops can't be issued from the branch slot, so the effective |
cbe26ab8 DN |
15874 | issue_rate for nops is 'issue_rate - 1'. */ |
15875 | if (can_issue_more == 0) | |
15876 | can_issue_more = issue_rate; | |
15877 | can_issue_more--; | |
15878 | if (can_issue_more == 0) | |
15879 | { | |
15880 | can_issue_more = issue_rate - 1; | |
15881 | (*group_count)++; | |
15882 | end = true; | |
15883 | for (i = 0; i < issue_rate; i++) | |
15884 | { | |
15885 | group_insns[i] = 0; | |
15886 | } | |
15887 | } | |
15888 | ||
15889 | while (n_nops > 0) | |
15890 | { | |
15891 | nop = gen_nop (); | |
15892 | emit_insn_before (nop, next_insn); | |
15893 | if (can_issue_more == issue_rate - 1) /* new group begins */ | |
15894 | end = false; | |
15895 | can_issue_more--; | |
15896 | if (can_issue_more == 0) | |
15897 | { | |
15898 | can_issue_more = issue_rate - 1; | |
15899 | (*group_count)++; | |
15900 | end = true; | |
15901 | for (i = 0; i < issue_rate; i++) | |
15902 | { | |
15903 | group_insns[i] = 0; | |
f676971a EC |
15904 | } |
15905 | } | |
cbe26ab8 DN |
15906 | n_nops--; |
15907 | } | |
15908 | ||
15909 | /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */ | |
f676971a | 15910 | can_issue_more++; |
cbe26ab8 DN |
15911 | |
15912 | *group_end = /* Is next_insn going to start a new group? */ | |
f676971a | 15913 | (end |
cbe26ab8 DN |
15914 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) |
15915 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
15916 | || (can_issue_more < issue_rate && | |
15917 | insn_terminates_group_p (next_insn, previous_group))); | |
15918 | if (*group_end && end) | |
15919 | (*group_count)--; | |
15920 | ||
15921 | if (sched_verbose > 6) | |
15922 | fprintf (dump, "done force: group count = %d, can_issue_more = %d\n", | |
15923 | *group_count, can_issue_more); | |
f676971a EC |
15924 | return can_issue_more; |
15925 | } | |
cbe26ab8 DN |
15926 | |
15927 | return can_issue_more; | |
15928 | } | |
15929 | ||
15930 | /* This function tries to synch the dispatch groups that the compiler "sees" | |
f676971a | 15931 | with the dispatch groups that the processor dispatcher is expected to |
cbe26ab8 DN |
15932 | form in practice. It tries to achieve this synchronization by forcing the |
15933 | estimated processor grouping on the compiler (as opposed to the function | |
15934 | 'pad_goups' which tries to force the scheduler's grouping on the processor). | |
15935 | ||
15936 | The function scans the insn sequence between PREV_HEAD_INSN and TAIL and | |
15937 | examines the (estimated) dispatch groups that will be formed by the processor | |
15938 | dispatcher. It marks these group boundaries to reflect the estimated | |
15939 | processor grouping, overriding the grouping that the scheduler had marked. | |
15940 | Depending on the value of the flag '-minsert-sched-nops' this function can | |
15941 | force certain insns into separate groups or force a certain distance between | |
15942 | them by inserting nops, for example, if there exists a "costly dependence" | |
15943 | between the insns. | |
15944 | ||
15945 | The function estimates the group boundaries that the processor will form as | |
15946 | folllows: It keeps track of how many vacant issue slots are available after | |
15947 | each insn. A subsequent insn will start a new group if one of the following | |
15948 | 4 cases applies: | |
15949 | - no more vacant issue slots remain in the current dispatch group. | |
15950 | - only the last issue slot, which is the branch slot, is vacant, but the next | |
15951 | insn is not a branch. | |
15952 | - only the last 2 or less issue slots, including the branch slot, are vacant, | |
15953 | which means that a cracked insn (which occupies two issue slots) can't be | |
15954 | issued in this group. | |
f676971a | 15955 | - less than 'issue_rate' slots are vacant, and the next insn always needs to |
cbe26ab8 DN |
15956 | start a new group. */ |
15957 | ||
15958 | static int | |
15959 | redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
15960 | { | |
15961 | rtx insn, next_insn; | |
15962 | int issue_rate; | |
15963 | int can_issue_more; | |
15964 | int slot, i; | |
15965 | bool group_end; | |
15966 | int group_count = 0; | |
15967 | rtx *group_insns; | |
15968 | ||
15969 | /* Initialize. */ | |
15970 | issue_rate = rs6000_issue_rate (); | |
15971 | group_insns = alloca (issue_rate * sizeof (rtx)); | |
f676971a | 15972 | for (i = 0; i < issue_rate; i++) |
cbe26ab8 DN |
15973 | { |
15974 | group_insns[i] = 0; | |
15975 | } | |
15976 | can_issue_more = issue_rate; | |
15977 | slot = 0; | |
15978 | insn = get_next_active_insn (prev_head_insn, tail); | |
15979 | group_end = false; | |
15980 | ||
15981 | while (insn != NULL_RTX) | |
15982 | { | |
15983 | slot = (issue_rate - can_issue_more); | |
15984 | group_insns[slot] = insn; | |
15985 | can_issue_more = | |
15986 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
15987 | if (insn_terminates_group_p (insn, current_group)) | |
15988 | can_issue_more = 0; | |
15989 | ||
15990 | next_insn = get_next_active_insn (insn, tail); | |
15991 | if (next_insn == NULL_RTX) | |
15992 | return group_count + 1; | |
15993 | ||
15994 | group_end = /* Is next_insn going to start a new group? */ | |
15995 | (can_issue_more == 0 | |
15996 | || (can_issue_more == 1 && !is_branch_slot_insn (next_insn)) | |
15997 | || (can_issue_more <= 2 && is_cracked_insn (next_insn)) | |
15998 | || (can_issue_more < issue_rate && | |
15999 | insn_terminates_group_p (next_insn, previous_group))); | |
16000 | ||
f676971a | 16001 | can_issue_more = force_new_group (sched_verbose, dump, group_insns, |
cbe26ab8 DN |
16002 | next_insn, &group_end, can_issue_more, &group_count); |
16003 | ||
16004 | if (group_end) | |
16005 | { | |
16006 | group_count++; | |
16007 | can_issue_more = 0; | |
16008 | for (i = 0; i < issue_rate; i++) | |
16009 | { | |
16010 | group_insns[i] = 0; | |
16011 | } | |
16012 | } | |
16013 | ||
16014 | if (GET_MODE (next_insn) == TImode && can_issue_more) | |
16015 | PUT_MODE(next_insn, VOIDmode); | |
16016 | else if (!can_issue_more && GET_MODE (next_insn) != TImode) | |
16017 | PUT_MODE (next_insn, TImode); | |
16018 | ||
16019 | insn = next_insn; | |
16020 | if (can_issue_more == 0) | |
16021 | can_issue_more = issue_rate; | |
16022 | } /* while */ | |
16023 | ||
16024 | return group_count; | |
16025 | } | |
16026 | ||
16027 | /* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the | |
16028 | dispatch group boundaries that the scheduler had marked. Pad with nops | |
16029 | any dispatch groups which have vacant issue slots, in order to force the | |
16030 | scheduler's grouping on the processor dispatcher. The function | |
16031 | returns the number of dispatch groups found. */ | |
16032 | ||
16033 | static int | |
16034 | pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail) | |
16035 | { | |
16036 | rtx insn, next_insn; | |
16037 | rtx nop; | |
16038 | int issue_rate; | |
16039 | int can_issue_more; | |
16040 | int group_end; | |
16041 | int group_count = 0; | |
16042 | ||
16043 | /* Initialize issue_rate. */ | |
16044 | issue_rate = rs6000_issue_rate (); | |
16045 | can_issue_more = issue_rate; | |
16046 | ||
16047 | insn = get_next_active_insn (prev_head_insn, tail); | |
16048 | next_insn = get_next_active_insn (insn, tail); | |
16049 | ||
16050 | while (insn != NULL_RTX) | |
16051 | { | |
16052 | can_issue_more = | |
16053 | rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more); | |
16054 | ||
16055 | group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode); | |
16056 | ||
16057 | if (next_insn == NULL_RTX) | |
16058 | break; | |
16059 | ||
16060 | if (group_end) | |
16061 | { | |
16062 | /* If the scheduler had marked group termination at this location | |
16063 | (between insn and next_indn), and neither insn nor next_insn will | |
16064 | force group termination, pad the group with nops to force group | |
16065 | termination. */ | |
16066 | if (can_issue_more | |
16067 | && (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
16068 | && !insn_terminates_group_p (insn, current_group) | |
16069 | && !insn_terminates_group_p (next_insn, previous_group)) | |
16070 | { | |
16071 | if (!is_branch_slot_insn(next_insn)) | |
16072 | can_issue_more--; | |
16073 | ||
16074 | while (can_issue_more) | |
16075 | { | |
16076 | nop = gen_nop (); | |
16077 | emit_insn_before (nop, next_insn); | |
16078 | can_issue_more--; | |
16079 | } | |
16080 | } | |
16081 | ||
16082 | can_issue_more = issue_rate; | |
16083 | group_count++; | |
16084 | } | |
16085 | ||
16086 | insn = next_insn; | |
16087 | next_insn = get_next_active_insn (insn, tail); | |
16088 | } | |
16089 | ||
16090 | return group_count; | |
16091 | } | |
16092 | ||
16093 | /* The following function is called at the end of scheduling BB. | |
16094 | After reload, it inserts nops at insn group bundling. */ | |
16095 | ||
16096 | static void | |
38f391a5 | 16097 | rs6000_sched_finish (FILE *dump, int sched_verbose) |
cbe26ab8 DN |
16098 | { |
16099 | int n_groups; | |
16100 | ||
16101 | if (sched_verbose) | |
16102 | fprintf (dump, "=== Finishing schedule.\n"); | |
16103 | ||
ec507f2d | 16104 | if (reload_completed && rs6000_sched_groups) |
cbe26ab8 DN |
16105 | { |
16106 | if (rs6000_sched_insert_nops == sched_finish_none) | |
16107 | return; | |
16108 | ||
16109 | if (rs6000_sched_insert_nops == sched_finish_pad_groups) | |
16110 | n_groups = pad_groups (dump, sched_verbose, | |
16111 | current_sched_info->prev_head, | |
16112 | current_sched_info->next_tail); | |
16113 | else | |
16114 | n_groups = redefine_groups (dump, sched_verbose, | |
16115 | current_sched_info->prev_head, | |
16116 | current_sched_info->next_tail); | |
16117 | ||
16118 | if (sched_verbose >= 6) | |
16119 | { | |
16120 | fprintf (dump, "ngroups = %d\n", n_groups); | |
16121 | print_rtl (dump, current_sched_info->prev_head); | |
16122 | fprintf (dump, "Done finish_sched\n"); | |
16123 | } | |
16124 | } | |
16125 | } | |
b6c9286a | 16126 | \f |
b6c9286a MM |
16127 | /* Length in units of the trampoline for entering a nested function. */ |
16128 | ||
16129 | int | |
863d938c | 16130 | rs6000_trampoline_size (void) |
b6c9286a MM |
16131 | { |
16132 | int ret = 0; | |
16133 | ||
16134 | switch (DEFAULT_ABI) | |
16135 | { | |
16136 | default: | |
16137 | abort (); | |
16138 | ||
16139 | case ABI_AIX: | |
8f802bfb | 16140 | ret = (TARGET_32BIT) ? 12 : 24; |
b6c9286a MM |
16141 | break; |
16142 | ||
4dabc42d | 16143 | case ABI_DARWIN: |
b6c9286a | 16144 | case ABI_V4: |
03a7e1a5 | 16145 | ret = (TARGET_32BIT) ? 40 : 48; |
b6c9286a | 16146 | break; |
b6c9286a MM |
16147 | } |
16148 | ||
16149 | return ret; | |
16150 | } | |
16151 | ||
16152 | /* Emit RTL insns to initialize the variable parts of a trampoline. | |
16153 | FNADDR is an RTX for the address of the function's pure code. | |
16154 | CXT is an RTX for the static chain value for the function. */ | |
16155 | ||
16156 | void | |
a2369ed3 | 16157 | rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt) |
b6c9286a | 16158 | { |
ac2a93a1 | 16159 | enum machine_mode pmode = Pmode; |
8bd04c56 MM |
16160 | int regsize = (TARGET_32BIT) ? 4 : 8; |
16161 | rtx ctx_reg = force_reg (pmode, cxt); | |
b6c9286a MM |
16162 | |
16163 | switch (DEFAULT_ABI) | |
16164 | { | |
16165 | default: | |
16166 | abort (); | |
16167 | ||
8bd04c56 | 16168 | /* Macros to shorten the code expansions below. */ |
39403d82 | 16169 | #define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr)) |
c5c76735 JL |
16170 | #define MEM_PLUS(addr,offset) \ |
16171 | gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset))) | |
7c59dc5d | 16172 | |
b6c9286a MM |
16173 | /* Under AIX, just build the 3 word function descriptor */ |
16174 | case ABI_AIX: | |
8bd04c56 MM |
16175 | { |
16176 | rtx fn_reg = gen_reg_rtx (pmode); | |
16177 | rtx toc_reg = gen_reg_rtx (pmode); | |
16178 | emit_move_insn (fn_reg, MEM_DEREF (fnaddr)); | |
1cb18e3c | 16179 | emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize)); |
8bd04c56 MM |
16180 | emit_move_insn (MEM_DEREF (addr), fn_reg); |
16181 | emit_move_insn (MEM_PLUS (addr, regsize), toc_reg); | |
16182 | emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg); | |
16183 | } | |
b6c9286a MM |
16184 | break; |
16185 | ||
4dabc42d TC |
16186 | /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */ |
16187 | case ABI_DARWIN: | |
b6c9286a | 16188 | case ABI_V4: |
39403d82 | 16189 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), |
eaf1bcf1 MM |
16190 | FALSE, VOIDmode, 4, |
16191 | addr, pmode, | |
16192 | GEN_INT (rs6000_trampoline_size ()), SImode, | |
16193 | fnaddr, pmode, | |
16194 | ctx_reg, pmode); | |
b6c9286a | 16195 | break; |
b6c9286a MM |
16196 | } |
16197 | ||
16198 | return; | |
16199 | } | |
7509c759 MM |
16200 | |
16201 | \f | |
91d231cb | 16202 | /* Table of valid machine attributes. */ |
a4f6c312 | 16203 | |
91d231cb | 16204 | const struct attribute_spec rs6000_attribute_table[] = |
7509c759 | 16205 | { |
91d231cb | 16206 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ |
8bb418a3 | 16207 | { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute }, |
a5c76ee6 ZW |
16208 | { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, |
16209 | { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute }, | |
16210 | { NULL, 0, 0, false, false, false, NULL } | |
91d231cb | 16211 | }; |
7509c759 | 16212 | |
8bb418a3 ZL |
16213 | /* Handle the "altivec" attribute. The attribute may have |
16214 | arguments as follows: | |
f676971a | 16215 | |
8bb418a3 ZL |
16216 | __attribute__((altivec(vector__))) |
16217 | __attribute__((altivec(pixel__))) (always followed by 'unsigned short') | |
16218 | __attribute__((altivec(bool__))) (always followed by 'unsigned') | |
16219 | ||
16220 | and may appear more than once (e.g., 'vector bool char') in a | |
16221 | given declaration. */ | |
16222 | ||
16223 | static tree | |
16224 | rs6000_handle_altivec_attribute (tree *node, tree name, tree args, | |
16225 | int flags ATTRIBUTE_UNUSED, | |
16226 | bool *no_add_attrs) | |
16227 | { | |
16228 | tree type = *node, result = NULL_TREE; | |
16229 | enum machine_mode mode; | |
16230 | int unsigned_p; | |
16231 | char altivec_type | |
16232 | = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args) | |
16233 | && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE) | |
16234 | ? *IDENTIFIER_POINTER (TREE_VALUE (args)) | |
f676971a | 16235 | : '?'); |
8bb418a3 ZL |
16236 | |
16237 | while (POINTER_TYPE_P (type) | |
16238 | || TREE_CODE (type) == FUNCTION_TYPE | |
16239 | || TREE_CODE (type) == METHOD_TYPE | |
16240 | || TREE_CODE (type) == ARRAY_TYPE) | |
16241 | type = TREE_TYPE (type); | |
16242 | ||
16243 | mode = TYPE_MODE (type); | |
16244 | ||
16245 | if (rs6000_warn_altivec_long | |
16246 | && (type == long_unsigned_type_node || type == long_integer_type_node)) | |
16247 | warning ("use of 'long' in AltiVec types is deprecated; use 'int'"); | |
16248 | ||
16249 | switch (altivec_type) | |
16250 | { | |
16251 | case 'v': | |
8df83eae | 16252 | unsigned_p = TYPE_UNSIGNED (type); |
8bb418a3 ZL |
16253 | switch (mode) |
16254 | { | |
16255 | case SImode: | |
16256 | result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node); | |
16257 | break; | |
16258 | case HImode: | |
16259 | result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node); | |
16260 | break; | |
16261 | case QImode: | |
16262 | result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node); | |
16263 | break; | |
16264 | case SFmode: result = V4SF_type_node; break; | |
16265 | /* If the user says 'vector int bool', we may be handed the 'bool' | |
16266 | attribute _before_ the 'vector' attribute, and so select the proper | |
16267 | type in the 'b' case below. */ | |
16268 | case V4SImode: case V8HImode: case V16QImode: result = type; | |
16269 | default: break; | |
16270 | } | |
16271 | break; | |
16272 | case 'b': | |
16273 | switch (mode) | |
16274 | { | |
16275 | case SImode: case V4SImode: result = bool_V4SI_type_node; break; | |
16276 | case HImode: case V8HImode: result = bool_V8HI_type_node; break; | |
16277 | case QImode: case V16QImode: result = bool_V16QI_type_node; | |
16278 | default: break; | |
16279 | } | |
16280 | break; | |
16281 | case 'p': | |
16282 | switch (mode) | |
16283 | { | |
16284 | case V8HImode: result = pixel_V8HI_type_node; | |
16285 | default: break; | |
16286 | } | |
16287 | default: break; | |
16288 | } | |
16289 | ||
7958a2a6 FJ |
16290 | if (result && result != type && TYPE_READONLY (type)) |
16291 | result = build_qualified_type (result, TYPE_QUAL_CONST); | |
16292 | ||
8bb418a3 ZL |
16293 | *no_add_attrs = true; /* No need to hang on to the attribute. */ |
16294 | ||
16295 | if (!result) | |
16296 | warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); | |
16297 | else | |
16298 | *node = reconstruct_complex_type (*node, result); | |
16299 | ||
16300 | return NULL_TREE; | |
16301 | } | |
16302 | ||
f18eca82 ZL |
16303 | /* AltiVec defines four built-in scalar types that serve as vector |
16304 | elements; we must teach the compiler how to mangle them. */ | |
16305 | ||
16306 | static const char * | |
16307 | rs6000_mangle_fundamental_type (tree type) | |
16308 | { | |
16309 | if (type == bool_char_type_node) return "U6__boolc"; | |
16310 | if (type == bool_short_type_node) return "U6__bools"; | |
16311 | if (type == pixel_type_node) return "u7__pixel"; | |
16312 | if (type == bool_int_type_node) return "U6__booli"; | |
16313 | ||
16314 | /* For all other types, use normal C++ mangling. */ | |
16315 | return NULL; | |
16316 | } | |
16317 | ||
a5c76ee6 ZW |
16318 | /* Handle a "longcall" or "shortcall" attribute; arguments as in |
16319 | struct attribute_spec.handler. */ | |
a4f6c312 | 16320 | |
91d231cb | 16321 | static tree |
f676971a EC |
16322 | rs6000_handle_longcall_attribute (tree *node, tree name, |
16323 | tree args ATTRIBUTE_UNUSED, | |
16324 | int flags ATTRIBUTE_UNUSED, | |
a2369ed3 | 16325 | bool *no_add_attrs) |
91d231cb JM |
16326 | { |
16327 | if (TREE_CODE (*node) != FUNCTION_TYPE | |
16328 | && TREE_CODE (*node) != FIELD_DECL | |
16329 | && TREE_CODE (*node) != TYPE_DECL) | |
16330 | { | |
16331 | warning ("`%s' attribute only applies to functions", | |
16332 | IDENTIFIER_POINTER (name)); | |
16333 | *no_add_attrs = true; | |
16334 | } | |
6a4cee5f | 16335 | |
91d231cb | 16336 | return NULL_TREE; |
7509c759 MM |
16337 | } |
16338 | ||
a5c76ee6 ZW |
16339 | /* Set longcall attributes on all functions declared when |
16340 | rs6000_default_long_calls is true. */ | |
16341 | static void | |
a2369ed3 | 16342 | rs6000_set_default_type_attributes (tree type) |
a5c76ee6 ZW |
16343 | { |
16344 | if (rs6000_default_long_calls | |
16345 | && (TREE_CODE (type) == FUNCTION_TYPE | |
16346 | || TREE_CODE (type) == METHOD_TYPE)) | |
16347 | TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"), | |
16348 | NULL_TREE, | |
16349 | TYPE_ATTRIBUTES (type)); | |
16350 | } | |
16351 | ||
3cb999d8 DE |
16352 | /* Return a reference suitable for calling a function with the |
16353 | longcall attribute. */ | |
a4f6c312 | 16354 | |
6a4cee5f | 16355 | struct rtx_def * |
a2369ed3 | 16356 | rs6000_longcall_ref (rtx call_ref) |
6a4cee5f | 16357 | { |
d330fd93 | 16358 | const char *call_name; |
6a4cee5f MM |
16359 | tree node; |
16360 | ||
16361 | if (GET_CODE (call_ref) != SYMBOL_REF) | |
16362 | return call_ref; | |
16363 | ||
16364 | /* System V adds '.' to the internal name, so skip them. */ | |
16365 | call_name = XSTR (call_ref, 0); | |
16366 | if (*call_name == '.') | |
16367 | { | |
16368 | while (*call_name == '.') | |
16369 | call_name++; | |
16370 | ||
16371 | node = get_identifier (call_name); | |
39403d82 | 16372 | call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node)); |
6a4cee5f MM |
16373 | } |
16374 | ||
16375 | return force_reg (Pmode, call_ref); | |
16376 | } | |
7509c759 | 16377 | \f |
b64a1b53 RH |
16378 | #ifdef USING_ELFOS_H |
16379 | ||
7509c759 MM |
16380 | /* A C statement or statements to switch to the appropriate section |
16381 | for output of RTX in mode MODE. You can assume that RTX is some | |
16382 | kind of constant in RTL. The argument MODE is redundant except in | |
16383 | the case of a `const_int' rtx. Select the section by calling | |
16384 | `text_section' or one of the alternatives for other sections. | |
16385 | ||
16386 | Do not define this macro if you put all constants in the read-only | |
16387 | data section. */ | |
16388 | ||
b64a1b53 | 16389 | static void |
f676971a | 16390 | rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x, |
a2369ed3 | 16391 | unsigned HOST_WIDE_INT align) |
7509c759 | 16392 | { |
a9098fd0 | 16393 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) |
7509c759 | 16394 | toc_section (); |
7509c759 | 16395 | else |
b64a1b53 | 16396 | default_elf_select_rtx_section (mode, x, align); |
7509c759 MM |
16397 | } |
16398 | ||
16399 | /* A C statement or statements to switch to the appropriate | |
16400 | section for output of DECL. DECL is either a `VAR_DECL' node | |
16401 | or a constant of some sort. RELOC indicates whether forming | |
16402 | the initial value of DECL requires link-time relocations. */ | |
16403 | ||
ae46c4e0 | 16404 | static void |
f676971a | 16405 | rs6000_elf_select_section (tree decl, int reloc, |
a2369ed3 | 16406 | unsigned HOST_WIDE_INT align) |
7509c759 | 16407 | { |
f1384257 AM |
16408 | /* Pretend that we're always building for a shared library when |
16409 | ABI_AIX, because otherwise we end up with dynamic relocations | |
16410 | in read-only sections. This happens for function pointers, | |
16411 | references to vtables in typeinfo, and probably other cases. */ | |
0e5dbd9b DE |
16412 | default_elf_select_section_1 (decl, reloc, align, |
16413 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
63019373 GK |
16414 | } |
16415 | ||
16416 | /* A C statement to build up a unique section name, expressed as a | |
16417 | STRING_CST node, and assign it to DECL_SECTION_NAME (decl). | |
16418 | RELOC indicates whether the initial value of EXP requires | |
16419 | link-time relocations. If you do not define this macro, GCC will use | |
16420 | the symbol name prefixed by `.' as the section name. Note - this | |
f5143c46 | 16421 | macro can now be called for uninitialized data items as well as |
4912a07c | 16422 | initialized data and functions. */ |
63019373 | 16423 | |
ae46c4e0 | 16424 | static void |
a2369ed3 | 16425 | rs6000_elf_unique_section (tree decl, int reloc) |
63019373 | 16426 | { |
f1384257 AM |
16427 | /* As above, pretend that we're always building for a shared library |
16428 | when ABI_AIX, to avoid dynamic relocations in read-only sections. */ | |
0e5dbd9b DE |
16429 | default_unique_section_1 (decl, reloc, |
16430 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7509c759 | 16431 | } |
d9407988 | 16432 | \f |
d1908feb JJ |
16433 | /* For a SYMBOL_REF, set generic flags and then perform some |
16434 | target-specific processing. | |
16435 | ||
d1908feb JJ |
16436 | When the AIX ABI is requested on a non-AIX system, replace the |
16437 | function name with the real name (with a leading .) rather than the | |
16438 | function descriptor name. This saves a lot of overriding code to | |
16439 | read the prefixes. */ | |
d9407988 | 16440 | |
fb49053f | 16441 | static void |
a2369ed3 | 16442 | rs6000_elf_encode_section_info (tree decl, rtx rtl, int first) |
d9407988 | 16443 | { |
d1908feb | 16444 | default_encode_section_info (decl, rtl, first); |
b2003250 | 16445 | |
d1908feb JJ |
16446 | if (first |
16447 | && TREE_CODE (decl) == FUNCTION_DECL | |
16448 | && !TARGET_AIX | |
16449 | && DEFAULT_ABI == ABI_AIX) | |
d9407988 | 16450 | { |
c6a2438a | 16451 | rtx sym_ref = XEXP (rtl, 0); |
d1908feb JJ |
16452 | size_t len = strlen (XSTR (sym_ref, 0)); |
16453 | char *str = alloca (len + 2); | |
16454 | str[0] = '.'; | |
16455 | memcpy (str + 1, XSTR (sym_ref, 0), len + 1); | |
16456 | XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1); | |
d9407988 | 16457 | } |
d9407988 MM |
16458 | } |
16459 | ||
0e5dbd9b | 16460 | static bool |
a2369ed3 | 16461 | rs6000_elf_in_small_data_p (tree decl) |
0e5dbd9b DE |
16462 | { |
16463 | if (rs6000_sdata == SDATA_NONE) | |
16464 | return false; | |
16465 | ||
16466 | if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl)) | |
16467 | { | |
16468 | const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
16469 | if (strcmp (section, ".sdata") == 0 | |
16470 | || strcmp (section, ".sdata2") == 0 | |
20bfcd69 GK |
16471 | || strcmp (section, ".sbss") == 0 |
16472 | || strcmp (section, ".sbss2") == 0 | |
16473 | || strcmp (section, ".PPC.EMB.sdata0") == 0 | |
16474 | || strcmp (section, ".PPC.EMB.sbss0") == 0) | |
0e5dbd9b DE |
16475 | return true; |
16476 | } | |
16477 | else | |
16478 | { | |
16479 | HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); | |
16480 | ||
16481 | if (size > 0 | |
307b599c | 16482 | && (unsigned HOST_WIDE_INT) size <= g_switch_value |
20bfcd69 GK |
16483 | /* If it's not public, and we're not going to reference it there, |
16484 | there's no need to put it in the small data section. */ | |
0e5dbd9b DE |
16485 | && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl))) |
16486 | return true; | |
16487 | } | |
16488 | ||
16489 | return false; | |
16490 | } | |
16491 | ||
b91da81f | 16492 | #endif /* USING_ELFOS_H */ |
000034eb | 16493 | |
a6c2a102 | 16494 | \f |
000034eb | 16495 | /* Return a REG that occurs in ADDR with coefficient 1. |
02441cd6 JL |
16496 | ADDR can be effectively incremented by incrementing REG. |
16497 | ||
16498 | r0 is special and we must not select it as an address | |
16499 | register by this routine since our caller will try to | |
16500 | increment the returned register via an "la" instruction. */ | |
000034eb DE |
16501 | |
16502 | struct rtx_def * | |
a2369ed3 | 16503 | find_addr_reg (rtx addr) |
000034eb DE |
16504 | { |
16505 | while (GET_CODE (addr) == PLUS) | |
16506 | { | |
02441cd6 JL |
16507 | if (GET_CODE (XEXP (addr, 0)) == REG |
16508 | && REGNO (XEXP (addr, 0)) != 0) | |
000034eb | 16509 | addr = XEXP (addr, 0); |
02441cd6 JL |
16510 | else if (GET_CODE (XEXP (addr, 1)) == REG |
16511 | && REGNO (XEXP (addr, 1)) != 0) | |
000034eb DE |
16512 | addr = XEXP (addr, 1); |
16513 | else if (CONSTANT_P (XEXP (addr, 0))) | |
16514 | addr = XEXP (addr, 1); | |
16515 | else if (CONSTANT_P (XEXP (addr, 1))) | |
16516 | addr = XEXP (addr, 0); | |
16517 | else | |
16518 | abort (); | |
16519 | } | |
02441cd6 | 16520 | if (GET_CODE (addr) == REG && REGNO (addr) != 0) |
000034eb DE |
16521 | return addr; |
16522 | abort (); | |
16523 | } | |
16524 | ||
a6c2a102 | 16525 | void |
a2369ed3 | 16526 | rs6000_fatal_bad_address (rtx op) |
a6c2a102 DE |
16527 | { |
16528 | fatal_insn ("bad address", op); | |
16529 | } | |
c8023011 | 16530 | |
ee890fe2 SS |
16531 | #if TARGET_MACHO |
16532 | ||
16533 | #if 0 | |
16534 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
16535 | reference and a constant. */ | |
16536 | ||
16537 | int | |
a2369ed3 | 16538 | symbolic_operand (rtx op) |
ee890fe2 SS |
16539 | { |
16540 | switch (GET_CODE (op)) | |
16541 | { | |
16542 | case SYMBOL_REF: | |
16543 | case LABEL_REF: | |
16544 | return 1; | |
16545 | case CONST: | |
16546 | op = XEXP (op, 0); | |
16547 | return (GET_CODE (op) == SYMBOL_REF || | |
16548 | (GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
16549 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
16550 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
16551 | default: | |
16552 | return 0; | |
16553 | } | |
c8023011 | 16554 | } |
ee890fe2 SS |
16555 | #endif |
16556 | ||
efdba735 | 16557 | #if TARGET_MACHO |
ee890fe2 | 16558 | |
efdba735 | 16559 | static tree branch_island_list = 0; |
ee890fe2 | 16560 | |
efdba735 SH |
16561 | /* Remember to generate a branch island for far calls to the given |
16562 | function. */ | |
ee890fe2 | 16563 | |
f676971a | 16564 | static void |
efdba735 | 16565 | add_compiler_branch_island (tree label_name, tree function_name, int line_number) |
ee890fe2 | 16566 | { |
efdba735 | 16567 | tree branch_island = build_tree_list (function_name, label_name); |
7d60be94 | 16568 | TREE_TYPE (branch_island) = build_int_cst (NULL_TREE, line_number); |
efdba735 SH |
16569 | TREE_CHAIN (branch_island) = branch_island_list; |
16570 | branch_island_list = branch_island; | |
ee890fe2 SS |
16571 | } |
16572 | ||
efdba735 SH |
16573 | #define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND) |
16574 | #define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND) | |
16575 | #define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \ | |
16576 | TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND)) | |
ee890fe2 | 16577 | |
efdba735 SH |
16578 | /* Generate far-jump branch islands for everything on the |
16579 | branch_island_list. Invoked immediately after the last instruction | |
16580 | of the epilogue has been emitted; the branch-islands must be | |
16581 | appended to, and contiguous with, the function body. Mach-O stubs | |
16582 | are generated in machopic_output_stub(). */ | |
ee890fe2 | 16583 | |
efdba735 SH |
16584 | static void |
16585 | macho_branch_islands (void) | |
16586 | { | |
16587 | char tmp_buf[512]; | |
16588 | tree branch_island; | |
16589 | ||
16590 | for (branch_island = branch_island_list; | |
16591 | branch_island; | |
16592 | branch_island = TREE_CHAIN (branch_island)) | |
16593 | { | |
16594 | const char *label = | |
16595 | IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island)); | |
16596 | const char *name = | |
11abc112 | 16597 | IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)); |
efdba735 SH |
16598 | char name_buf[512]; |
16599 | /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */ | |
16600 | if (name[0] == '*' || name[0] == '&') | |
16601 | strcpy (name_buf, name+1); | |
16602 | else | |
16603 | { | |
16604 | name_buf[0] = '_'; | |
16605 | strcpy (name_buf+1, name); | |
16606 | } | |
16607 | strcpy (tmp_buf, "\n"); | |
16608 | strcat (tmp_buf, label); | |
ee890fe2 | 16609 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 16610 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 16611 | fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 16612 | BRANCH_ISLAND_LINE_NUMBER(branch_island)); |
ee890fe2 | 16613 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 SH |
16614 | if (flag_pic) |
16615 | { | |
16616 | strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,"); | |
16617 | strcat (tmp_buf, label); | |
16618 | strcat (tmp_buf, "_pic\n"); | |
16619 | strcat (tmp_buf, label); | |
16620 | strcat (tmp_buf, "_pic:\n\tmflr r11\n"); | |
f676971a | 16621 | |
efdba735 SH |
16622 | strcat (tmp_buf, "\taddis r11,r11,ha16("); |
16623 | strcat (tmp_buf, name_buf); | |
16624 | strcat (tmp_buf, " - "); | |
16625 | strcat (tmp_buf, label); | |
16626 | strcat (tmp_buf, "_pic)\n"); | |
f676971a | 16627 | |
efdba735 | 16628 | strcat (tmp_buf, "\tmtlr r0\n"); |
f676971a | 16629 | |
efdba735 SH |
16630 | strcat (tmp_buf, "\taddi r12,r11,lo16("); |
16631 | strcat (tmp_buf, name_buf); | |
16632 | strcat (tmp_buf, " - "); | |
16633 | strcat (tmp_buf, label); | |
16634 | strcat (tmp_buf, "_pic)\n"); | |
f676971a | 16635 | |
efdba735 SH |
16636 | strcat (tmp_buf, "\tmtctr r12\n\tbctr\n"); |
16637 | } | |
16638 | else | |
16639 | { | |
16640 | strcat (tmp_buf, ":\nlis r12,hi16("); | |
16641 | strcat (tmp_buf, name_buf); | |
16642 | strcat (tmp_buf, ")\n\tori r12,r12,lo16("); | |
16643 | strcat (tmp_buf, name_buf); | |
16644 | strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr"); | |
16645 | } | |
16646 | output_asm_insn (tmp_buf, 0); | |
ee890fe2 | 16647 | #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) |
efdba735 | 16648 | if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG) |
f7efd730 | 16649 | fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n", |
efdba735 | 16650 | BRANCH_ISLAND_LINE_NUMBER (branch_island)); |
ee890fe2 | 16651 | #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ |
efdba735 | 16652 | } |
ee890fe2 | 16653 | |
efdba735 | 16654 | branch_island_list = 0; |
ee890fe2 SS |
16655 | } |
16656 | ||
16657 | /* NO_PREVIOUS_DEF checks in the link list whether the function name is | |
16658 | already there or not. */ | |
16659 | ||
efdba735 | 16660 | static int |
a2369ed3 | 16661 | no_previous_def (tree function_name) |
ee890fe2 | 16662 | { |
efdba735 SH |
16663 | tree branch_island; |
16664 | for (branch_island = branch_island_list; | |
16665 | branch_island; | |
16666 | branch_island = TREE_CHAIN (branch_island)) | |
16667 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
ee890fe2 SS |
16668 | return 0; |
16669 | return 1; | |
16670 | } | |
16671 | ||
16672 | /* GET_PREV_LABEL gets the label name from the previous definition of | |
16673 | the function. */ | |
16674 | ||
efdba735 | 16675 | static tree |
a2369ed3 | 16676 | get_prev_label (tree function_name) |
ee890fe2 | 16677 | { |
efdba735 SH |
16678 | tree branch_island; |
16679 | for (branch_island = branch_island_list; | |
16680 | branch_island; | |
16681 | branch_island = TREE_CHAIN (branch_island)) | |
16682 | if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island)) | |
16683 | return BRANCH_ISLAND_LABEL_NAME (branch_island); | |
ee890fe2 SS |
16684 | return 0; |
16685 | } | |
16686 | ||
16687 | /* INSN is either a function call or a millicode call. It may have an | |
f676971a | 16688 | unconditional jump in its delay slot. |
ee890fe2 SS |
16689 | |
16690 | CALL_DEST is the routine we are calling. */ | |
16691 | ||
16692 | char * | |
efdba735 | 16693 | output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number) |
ee890fe2 SS |
16694 | { |
16695 | static char buf[256]; | |
efdba735 SH |
16696 | if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF |
16697 | && (INTVAL (operands[cookie_operand_number]) & CALL_LONG)) | |
ee890fe2 SS |
16698 | { |
16699 | tree labelname; | |
efdba735 | 16700 | tree funname = get_identifier (XSTR (operands[dest_operand_number], 0)); |
f676971a | 16701 | |
ee890fe2 SS |
16702 | if (no_previous_def (funname)) |
16703 | { | |
308c142a | 16704 | int line_number = 0; |
ee890fe2 SS |
16705 | rtx label_rtx = gen_label_rtx (); |
16706 | char *label_buf, temp_buf[256]; | |
16707 | ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L", | |
16708 | CODE_LABEL_NUMBER (label_rtx)); | |
16709 | label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf; | |
16710 | labelname = get_identifier (label_buf); | |
16711 | for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn)); | |
16712 | if (insn) | |
16713 | line_number = NOTE_LINE_NUMBER (insn); | |
efdba735 | 16714 | add_compiler_branch_island (labelname, funname, line_number); |
ee890fe2 SS |
16715 | } |
16716 | else | |
16717 | labelname = get_prev_label (funname); | |
16718 | ||
efdba735 SH |
16719 | /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl' |
16720 | instruction will reach 'foo', otherwise link as 'bl L42'". | |
16721 | "L42" should be a 'branch island', that will do a far jump to | |
16722 | 'foo'. Branch islands are generated in | |
16723 | macho_branch_islands(). */ | |
ee890fe2 | 16724 | sprintf (buf, "jbsr %%z%d,%.246s", |
efdba735 | 16725 | dest_operand_number, IDENTIFIER_POINTER (labelname)); |
ee890fe2 SS |
16726 | } |
16727 | else | |
efdba735 SH |
16728 | sprintf (buf, "bl %%z%d", dest_operand_number); |
16729 | return buf; | |
ee890fe2 SS |
16730 | } |
16731 | ||
efdba735 | 16732 | #endif /* TARGET_MACHO */ |
ee890fe2 | 16733 | |
ee890fe2 SS |
16734 | /* Generate PIC and indirect symbol stubs. */ |
16735 | ||
16736 | void | |
a2369ed3 | 16737 | machopic_output_stub (FILE *file, const char *symb, const char *stub) |
ee890fe2 SS |
16738 | { |
16739 | unsigned int length; | |
a4f6c312 SS |
16740 | char *symbol_name, *lazy_ptr_name; |
16741 | char *local_label_0; | |
ee890fe2 SS |
16742 | static int label = 0; |
16743 | ||
df56a27f | 16744 | /* Lose our funky encoding stuff so it doesn't contaminate the stub. */ |
772c5265 | 16745 | symb = (*targetm.strip_name_encoding) (symb); |
df56a27f | 16746 | |
ee890fe2 | 16747 | |
ee890fe2 SS |
16748 | length = strlen (symb); |
16749 | symbol_name = alloca (length + 32); | |
16750 | GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length); | |
16751 | ||
16752 | lazy_ptr_name = alloca (length + 32); | |
16753 | GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length); | |
16754 | ||
ee890fe2 | 16755 | if (flag_pic == 2) |
d3c300d2 | 16756 | machopic_picsymbol_stub1_section (); |
ee890fe2 | 16757 | else |
d3c300d2 | 16758 | machopic_symbol_stub1_section (); |
ee890fe2 SS |
16759 | |
16760 | if (flag_pic == 2) | |
16761 | { | |
d974312d DJ |
16762 | fprintf (file, "\t.align 5\n"); |
16763 | ||
16764 | fprintf (file, "%s:\n", stub); | |
16765 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
16766 | ||
876455fa AP |
16767 | label++; |
16768 | local_label_0 = alloca (sizeof("\"L0000000000$spb\"")); | |
16769 | sprintf (local_label_0, "\"L%011d$spb\"", label); | |
f676971a | 16770 | |
ee890fe2 SS |
16771 | fprintf (file, "\tmflr r0\n"); |
16772 | fprintf (file, "\tbcl 20,31,%s\n", local_label_0); | |
16773 | fprintf (file, "%s:\n\tmflr r11\n", local_label_0); | |
16774 | fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n", | |
16775 | lazy_ptr_name, local_label_0); | |
16776 | fprintf (file, "\tmtlr r0\n"); | |
d3c300d2 | 16777 | fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n", |
ee890fe2 SS |
16778 | lazy_ptr_name, local_label_0); |
16779 | fprintf (file, "\tmtctr r12\n"); | |
ee890fe2 SS |
16780 | fprintf (file, "\tbctr\n"); |
16781 | } | |
16782 | else | |
d974312d DJ |
16783 | { |
16784 | fprintf (file, "\t.align 4\n"); | |
16785 | ||
16786 | fprintf (file, "%s:\n", stub); | |
16787 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
16788 | ||
16789 | fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name); | |
16790 | fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name); | |
16791 | fprintf (file, "\tmtctr r12\n"); | |
16792 | fprintf (file, "\tbctr\n"); | |
16793 | } | |
f676971a | 16794 | |
ee890fe2 SS |
16795 | machopic_lazy_symbol_ptr_section (); |
16796 | fprintf (file, "%s:\n", lazy_ptr_name); | |
16797 | fprintf (file, "\t.indirect_symbol %s\n", symbol_name); | |
49bd1d27 SS |
16798 | fprintf (file, "%sdyld_stub_binding_helper\n", |
16799 | (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t")); | |
ee890fe2 SS |
16800 | } |
16801 | ||
16802 | /* Legitimize PIC addresses. If the address is already | |
16803 | position-independent, we return ORIG. Newly generated | |
16804 | position-independent addresses go into a reg. This is REG if non | |
16805 | zero, otherwise we allocate register(s) as necessary. */ | |
16806 | ||
c859cda6 | 16807 | #define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000) |
ee890fe2 SS |
16808 | |
16809 | rtx | |
f676971a | 16810 | rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode, |
a2369ed3 | 16811 | rtx reg) |
ee890fe2 SS |
16812 | { |
16813 | rtx base, offset; | |
16814 | ||
16815 | if (reg == NULL && ! reload_in_progress && ! reload_completed) | |
16816 | reg = gen_reg_rtx (Pmode); | |
16817 | ||
16818 | if (GET_CODE (orig) == CONST) | |
16819 | { | |
16820 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
16821 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
16822 | return orig; | |
16823 | ||
16824 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
16825 | { | |
2cf520bf | 16826 | /* Use a different reg for the intermediate value, as |
a3c9585f | 16827 | it will be marked UNCHANGING. */ |
2cf520bf GK |
16828 | rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode); |
16829 | ||
a4f6c312 SS |
16830 | base = |
16831 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0), | |
2cf520bf | 16832 | Pmode, reg_temp); |
a4f6c312 SS |
16833 | offset = |
16834 | rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1), | |
16835 | Pmode, reg); | |
ee890fe2 SS |
16836 | } |
16837 | else | |
16838 | abort (); | |
16839 | ||
16840 | if (GET_CODE (offset) == CONST_INT) | |
16841 | { | |
16842 | if (SMALL_INT (offset)) | |
ed8908e7 | 16843 | return plus_constant (base, INTVAL (offset)); |
ee890fe2 SS |
16844 | else if (! reload_in_progress && ! reload_completed) |
16845 | offset = force_reg (Pmode, offset); | |
16846 | else | |
c859cda6 DJ |
16847 | { |
16848 | rtx mem = force_const_mem (Pmode, orig); | |
16849 | return machopic_legitimize_pic_address (mem, Pmode, reg); | |
16850 | } | |
ee890fe2 | 16851 | } |
f1c25d3b | 16852 | return gen_rtx_PLUS (Pmode, base, offset); |
ee890fe2 SS |
16853 | } |
16854 | ||
16855 | /* Fall back on generic machopic code. */ | |
16856 | return machopic_legitimize_pic_address (orig, mode, reg); | |
16857 | } | |
16858 | ||
16859 | /* This is just a placeholder to make linking work without having to | |
16860 | add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is | |
16861 | ever needed for Darwin (not too likely!) this would have to get a | |
16862 | real definition. */ | |
16863 | ||
16864 | void | |
863d938c | 16865 | toc_section (void) |
ee890fe2 SS |
16866 | { |
16867 | } | |
16868 | ||
16869 | #endif /* TARGET_MACHO */ | |
7c262518 RH |
16870 | |
16871 | #if TARGET_ELF | |
16872 | static unsigned int | |
a2369ed3 | 16873 | rs6000_elf_section_type_flags (tree decl, const char *name, int reloc) |
7c262518 | 16874 | { |
1ff8f81a AM |
16875 | return default_section_type_flags_1 (decl, name, reloc, |
16876 | flag_pic || DEFAULT_ABI == ABI_AIX); | |
7c262518 | 16877 | } |
d9f6800d RH |
16878 | |
16879 | /* Record an element in the table of global constructors. SYMBOL is | |
16880 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
16881 | between 0 and MAX_INIT_PRIORITY. | |
16882 | ||
16883 | This differs from default_named_section_asm_out_constructor in | |
16884 | that we have special handling for -mrelocatable. */ | |
16885 | ||
16886 | static void | |
a2369ed3 | 16887 | rs6000_elf_asm_out_constructor (rtx symbol, int priority) |
d9f6800d RH |
16888 | { |
16889 | const char *section = ".ctors"; | |
16890 | char buf[16]; | |
16891 | ||
16892 | if (priority != DEFAULT_INIT_PRIORITY) | |
16893 | { | |
16894 | sprintf (buf, ".ctors.%.5u", | |
16895 | /* Invert the numbering so the linker puts us in the proper | |
16896 | order; constructors are run from right to left, and the | |
16897 | linker sorts in increasing order. */ | |
16898 | MAX_INIT_PRIORITY - priority); | |
16899 | section = buf; | |
16900 | } | |
16901 | ||
715bdd29 RH |
16902 | named_section_flags (section, SECTION_WRITE); |
16903 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
16904 | |
16905 | if (TARGET_RELOCATABLE) | |
16906 | { | |
16907 | fputs ("\t.long (", asm_out_file); | |
16908 | output_addr_const (asm_out_file, symbol); | |
16909 | fputs (")@fixup\n", asm_out_file); | |
16910 | } | |
16911 | else | |
c8af3574 | 16912 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d RH |
16913 | } |
16914 | ||
16915 | static void | |
a2369ed3 | 16916 | rs6000_elf_asm_out_destructor (rtx symbol, int priority) |
d9f6800d RH |
16917 | { |
16918 | const char *section = ".dtors"; | |
16919 | char buf[16]; | |
16920 | ||
16921 | if (priority != DEFAULT_INIT_PRIORITY) | |
16922 | { | |
16923 | sprintf (buf, ".dtors.%.5u", | |
16924 | /* Invert the numbering so the linker puts us in the proper | |
16925 | order; constructors are run from right to left, and the | |
16926 | linker sorts in increasing order. */ | |
16927 | MAX_INIT_PRIORITY - priority); | |
16928 | section = buf; | |
16929 | } | |
16930 | ||
715bdd29 RH |
16931 | named_section_flags (section, SECTION_WRITE); |
16932 | assemble_align (POINTER_SIZE); | |
d9f6800d RH |
16933 | |
16934 | if (TARGET_RELOCATABLE) | |
16935 | { | |
16936 | fputs ("\t.long (", asm_out_file); | |
16937 | output_addr_const (asm_out_file, symbol); | |
16938 | fputs (")@fixup\n", asm_out_file); | |
16939 | } | |
16940 | else | |
c8af3574 | 16941 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
d9f6800d | 16942 | } |
9739c90c JJ |
16943 | |
16944 | void | |
a2369ed3 | 16945 | rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl) |
9739c90c JJ |
16946 | { |
16947 | if (TARGET_64BIT) | |
16948 | { | |
16949 | fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file); | |
16950 | ASM_OUTPUT_LABEL (file, name); | |
16951 | fputs (DOUBLE_INT_ASM_OP, file); | |
85b776df AM |
16952 | rs6000_output_function_entry (file, name); |
16953 | fputs (",.TOC.@tocbase,0\n\t.previous\n", file); | |
16954 | if (DOT_SYMBOLS) | |
9739c90c | 16955 | { |
85b776df | 16956 | fputs ("\t.size\t", file); |
9739c90c | 16957 | assemble_name (file, name); |
85b776df AM |
16958 | fputs (",24\n\t.type\t.", file); |
16959 | assemble_name (file, name); | |
16960 | fputs (",@function\n", file); | |
16961 | if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl)) | |
16962 | { | |
16963 | fputs ("\t.globl\t.", file); | |
16964 | assemble_name (file, name); | |
16965 | putc ('\n', file); | |
16966 | } | |
9739c90c | 16967 | } |
85b776df AM |
16968 | else |
16969 | ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); | |
9739c90c | 16970 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); |
85b776df AM |
16971 | rs6000_output_function_entry (file, name); |
16972 | fputs (":\n", file); | |
9739c90c JJ |
16973 | return; |
16974 | } | |
16975 | ||
16976 | if (TARGET_RELOCATABLE | |
16977 | && (get_pool_size () != 0 || current_function_profile) | |
3c9eb5f4 | 16978 | && uses_TOC ()) |
9739c90c JJ |
16979 | { |
16980 | char buf[256]; | |
16981 | ||
16982 | (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno); | |
16983 | ||
16984 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1); | |
16985 | fprintf (file, "\t.long "); | |
16986 | assemble_name (file, buf); | |
16987 | putc ('-', file); | |
16988 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno); | |
16989 | assemble_name (file, buf); | |
16990 | putc ('\n', file); | |
16991 | } | |
16992 | ||
16993 | ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function"); | |
16994 | ASM_DECLARE_RESULT (file, DECL_RESULT (decl)); | |
16995 | ||
16996 | if (DEFAULT_ABI == ABI_AIX) | |
16997 | { | |
16998 | const char *desc_name, *orig_name; | |
16999 | ||
17000 | orig_name = (*targetm.strip_name_encoding) (name); | |
17001 | desc_name = orig_name; | |
17002 | while (*desc_name == '.') | |
17003 | desc_name++; | |
17004 | ||
17005 | if (TREE_PUBLIC (decl)) | |
17006 | fprintf (file, "\t.globl %s\n", desc_name); | |
17007 | ||
17008 | fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP); | |
17009 | fprintf (file, "%s:\n", desc_name); | |
17010 | fprintf (file, "\t.long %s\n", orig_name); | |
17011 | fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file); | |
17012 | if (DEFAULT_ABI == ABI_AIX) | |
17013 | fputs ("\t.long 0\n", file); | |
17014 | fprintf (file, "\t.previous\n"); | |
17015 | } | |
17016 | ASM_OUTPUT_LABEL (file, name); | |
17017 | } | |
7c262518 RH |
17018 | #endif |
17019 | ||
cbaaba19 | 17020 | #if TARGET_XCOFF |
7c262518 | 17021 | static void |
a2369ed3 | 17022 | rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name) |
b275d088 DE |
17023 | { |
17024 | fputs (GLOBAL_ASM_OP, stream); | |
17025 | RS6000_OUTPUT_BASENAME (stream, name); | |
17026 | putc ('\n', stream); | |
17027 | } | |
17028 | ||
17029 | static void | |
c18a5b6c MM |
17030 | rs6000_xcoff_asm_named_section (const char *name, unsigned int flags, |
17031 | tree decl ATTRIBUTE_UNUSED) | |
7c262518 | 17032 | { |
0e5dbd9b DE |
17033 | int smclass; |
17034 | static const char * const suffix[3] = { "PR", "RO", "RW" }; | |
17035 | ||
17036 | if (flags & SECTION_CODE) | |
17037 | smclass = 0; | |
17038 | else if (flags & SECTION_WRITE) | |
17039 | smclass = 2; | |
17040 | else | |
17041 | smclass = 1; | |
17042 | ||
5b5198f7 | 17043 | fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n", |
0e5dbd9b | 17044 | (flags & SECTION_CODE) ? "." : "", |
5b5198f7 | 17045 | name, suffix[smclass], flags & SECTION_ENTSIZE); |
7c262518 | 17046 | } |
ae46c4e0 RH |
17047 | |
17048 | static void | |
f676971a | 17049 | rs6000_xcoff_select_section (tree decl, int reloc, |
a2369ed3 | 17050 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) |
ae46c4e0 | 17051 | { |
5add3202 | 17052 | if (decl_readonly_section_1 (decl, reloc, 1)) |
ae46c4e0 | 17053 | { |
0e5dbd9b | 17054 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
17055 | read_only_data_section (); |
17056 | else | |
17057 | read_only_private_data_section (); | |
17058 | } | |
17059 | else | |
17060 | { | |
0e5dbd9b | 17061 | if (TREE_PUBLIC (decl)) |
ae46c4e0 RH |
17062 | data_section (); |
17063 | else | |
17064 | private_data_section (); | |
17065 | } | |
17066 | } | |
17067 | ||
17068 | static void | |
a2369ed3 | 17069 | rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED) |
ae46c4e0 RH |
17070 | { |
17071 | const char *name; | |
ae46c4e0 | 17072 | |
5b5198f7 DE |
17073 | /* Use select_section for private and uninitialized data. */ |
17074 | if (!TREE_PUBLIC (decl) | |
17075 | || DECL_COMMON (decl) | |
0e5dbd9b DE |
17076 | || DECL_INITIAL (decl) == NULL_TREE |
17077 | || DECL_INITIAL (decl) == error_mark_node | |
17078 | || (flag_zero_initialized_in_bss | |
17079 | && initializer_zerop (DECL_INITIAL (decl)))) | |
17080 | return; | |
17081 | ||
17082 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
17083 | name = (*targetm.strip_name_encoding) (name); | |
17084 | DECL_SECTION_NAME (decl) = build_string (strlen (name), name); | |
ae46c4e0 | 17085 | } |
b64a1b53 | 17086 | |
fb49053f RH |
17087 | /* Select section for constant in constant pool. |
17088 | ||
17089 | On RS/6000, all constants are in the private read-only data area. | |
17090 | However, if this is being placed in the TOC it must be output as a | |
17091 | toc entry. */ | |
17092 | ||
b64a1b53 | 17093 | static void |
f676971a | 17094 | rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x, |
a2369ed3 | 17095 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) |
b64a1b53 RH |
17096 | { |
17097 | if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode)) | |
17098 | toc_section (); | |
17099 | else | |
17100 | read_only_private_data_section (); | |
17101 | } | |
772c5265 RH |
17102 | |
17103 | /* Remove any trailing [DS] or the like from the symbol name. */ | |
17104 | ||
17105 | static const char * | |
a2369ed3 | 17106 | rs6000_xcoff_strip_name_encoding (const char *name) |
772c5265 RH |
17107 | { |
17108 | size_t len; | |
17109 | if (*name == '*') | |
17110 | name++; | |
17111 | len = strlen (name); | |
17112 | if (name[len - 1] == ']') | |
17113 | return ggc_alloc_string (name, len - 4); | |
17114 | else | |
17115 | return name; | |
17116 | } | |
17117 | ||
5add3202 DE |
17118 | /* Section attributes. AIX is always PIC. */ |
17119 | ||
17120 | static unsigned int | |
a2369ed3 | 17121 | rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc) |
5add3202 | 17122 | { |
5b5198f7 DE |
17123 | unsigned int align; |
17124 | unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1); | |
17125 | ||
17126 | /* Align to at least UNIT size. */ | |
17127 | if (flags & SECTION_CODE) | |
17128 | align = MIN_UNITS_PER_WORD; | |
17129 | else | |
17130 | /* Increase alignment of large objects if not already stricter. */ | |
17131 | align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT), | |
17132 | int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD | |
17133 | ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD); | |
17134 | ||
17135 | return flags | (exact_log2 (align) & SECTION_ENTSIZE); | |
5add3202 | 17136 | } |
a5fe455b | 17137 | |
1bc7c5b6 ZW |
17138 | /* Output at beginning of assembler file. |
17139 | ||
17140 | Initialize the section names for the RS/6000 at this point. | |
17141 | ||
17142 | Specify filename, including full path, to assembler. | |
17143 | ||
17144 | We want to go into the TOC section so at least one .toc will be emitted. | |
17145 | Also, in order to output proper .bs/.es pairs, we need at least one static | |
17146 | [RW] section emitted. | |
17147 | ||
17148 | Finally, declare mcount when profiling to make the assembler happy. */ | |
17149 | ||
17150 | static void | |
863d938c | 17151 | rs6000_xcoff_file_start (void) |
1bc7c5b6 ZW |
17152 | { |
17153 | rs6000_gen_section_name (&xcoff_bss_section_name, | |
17154 | main_input_filename, ".bss_"); | |
17155 | rs6000_gen_section_name (&xcoff_private_data_section_name, | |
17156 | main_input_filename, ".rw_"); | |
17157 | rs6000_gen_section_name (&xcoff_read_only_section_name, | |
17158 | main_input_filename, ".ro_"); | |
17159 | ||
17160 | fputs ("\t.file\t", asm_out_file); | |
17161 | output_quoted_string (asm_out_file, main_input_filename); | |
17162 | fputc ('\n', asm_out_file); | |
17163 | toc_section (); | |
17164 | if (write_symbols != NO_DEBUG) | |
17165 | private_data_section (); | |
17166 | text_section (); | |
17167 | if (profile_flag) | |
17168 | fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT); | |
17169 | rs6000_file_start (); | |
17170 | } | |
17171 | ||
a5fe455b ZW |
17172 | /* Output at end of assembler file. |
17173 | On the RS/6000, referencing data should automatically pull in text. */ | |
17174 | ||
17175 | static void | |
863d938c | 17176 | rs6000_xcoff_file_end (void) |
a5fe455b ZW |
17177 | { |
17178 | text_section (); | |
17179 | fputs ("_section_.text:\n", asm_out_file); | |
17180 | data_section (); | |
17181 | fputs (TARGET_32BIT | |
17182 | ? "\t.long _section_.text\n" : "\t.llong _section_.text\n", | |
17183 | asm_out_file); | |
17184 | } | |
f1384257 | 17185 | #endif /* TARGET_XCOFF */ |
0e5dbd9b | 17186 | |
f1384257 AM |
17187 | #if TARGET_MACHO |
17188 | /* Cross-module name binding. Darwin does not support overriding | |
7f3d8013 | 17189 | functions at dynamic-link time. */ |
0e5dbd9b | 17190 | |
2bcc50d0 | 17191 | static bool |
a2369ed3 | 17192 | rs6000_binds_local_p (tree decl) |
0e5dbd9b | 17193 | { |
f1384257 | 17194 | return default_binds_local_p_1 (decl, 0); |
0e5dbd9b | 17195 | } |
f1384257 | 17196 | #endif |
34bb030a | 17197 | |
3c50106f RH |
17198 | /* Compute a (partial) cost for rtx X. Return true if the complete |
17199 | cost has been computed, and false if subexpressions should be | |
17200 | scanned. In either case, *TOTAL contains the cost result. */ | |
17201 | ||
17202 | static bool | |
1494c534 | 17203 | rs6000_rtx_costs (rtx x, int code, int outer_code, int *total) |
3c50106f | 17204 | { |
f0517163 RS |
17205 | enum machine_mode mode = GET_MODE (x); |
17206 | ||
3c50106f RH |
17207 | switch (code) |
17208 | { | |
30a555d9 | 17209 | /* On the RS/6000, if it is valid in the insn, it is free. */ |
3c50106f | 17210 | case CONST_INT: |
066cd967 DE |
17211 | if (((outer_code == SET |
17212 | || outer_code == PLUS | |
17213 | || outer_code == MINUS) | |
17214 | && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I') | |
17215 | || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L'))) | |
17216 | || ((outer_code == IOR || outer_code == XOR) | |
17217 | && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K') | |
17218 | || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L'))) | |
627b6fe2 DJ |
17219 | || ((outer_code == DIV || outer_code == UDIV |
17220 | || outer_code == MOD || outer_code == UMOD) | |
17221 | && exact_log2 (INTVAL (x)) >= 0) | |
066cd967 DE |
17222 | || (outer_code == AND |
17223 | && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K') | |
17224 | || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L') | |
d5861a7a | 17225 | || mask_operand (x, VOIDmode))) |
066cd967 DE |
17226 | || outer_code == ASHIFT |
17227 | || outer_code == ASHIFTRT | |
17228 | || outer_code == LSHIFTRT | |
17229 | || outer_code == ROTATE | |
17230 | || outer_code == ROTATERT | |
d5861a7a | 17231 | || outer_code == ZERO_EXTRACT |
066cd967 DE |
17232 | || (outer_code == MULT |
17233 | && CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')) | |
17234 | || (outer_code == COMPARE | |
17235 | && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I') | |
17236 | || CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')))) | |
17237 | { | |
17238 | *total = 0; | |
17239 | return true; | |
17240 | } | |
17241 | else if ((outer_code == PLUS | |
17242 | && reg_or_add_cint64_operand (x, VOIDmode)) | |
17243 | || (outer_code == MINUS | |
17244 | && reg_or_sub_cint64_operand (x, VOIDmode)) | |
17245 | || ((outer_code == SET | |
17246 | || outer_code == IOR | |
17247 | || outer_code == XOR) | |
17248 | && (INTVAL (x) | |
17249 | & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0)) | |
17250 | { | |
17251 | *total = COSTS_N_INSNS (1); | |
17252 | return true; | |
17253 | } | |
17254 | /* FALLTHRU */ | |
17255 | ||
17256 | case CONST_DOUBLE: | |
17257 | if (mode == DImode | |
17258 | && ((outer_code == AND | |
17259 | && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K') | |
17260 | || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L') | |
d5861a7a | 17261 | || mask64_operand (x, DImode))) |
066cd967 DE |
17262 | || ((outer_code == IOR || outer_code == XOR) |
17263 | && CONST_DOUBLE_HIGH (x) == 0 | |
17264 | && (CONST_DOUBLE_LOW (x) | |
17265 | & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0))) | |
17266 | { | |
17267 | *total = 0; | |
17268 | return true; | |
17269 | } | |
17270 | else if (mode == DImode | |
17271 | && (outer_code == SET | |
17272 | || outer_code == IOR | |
17273 | || outer_code == XOR) | |
17274 | && CONST_DOUBLE_HIGH (x) == 0) | |
17275 | { | |
17276 | *total = COSTS_N_INSNS (1); | |
17277 | return true; | |
17278 | } | |
17279 | /* FALLTHRU */ | |
17280 | ||
3c50106f | 17281 | case CONST: |
066cd967 | 17282 | case HIGH: |
3c50106f | 17283 | case SYMBOL_REF: |
066cd967 DE |
17284 | case MEM: |
17285 | /* When optimizing for size, MEM should be slightly more expensive | |
17286 | than generating address, e.g., (plus (reg) (const)). | |
c112cf2b | 17287 | L1 cache latency is about two instructions. */ |
066cd967 | 17288 | *total = optimize_size ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2); |
3c50106f RH |
17289 | return true; |
17290 | ||
30a555d9 DE |
17291 | case LABEL_REF: |
17292 | *total = 0; | |
17293 | return true; | |
17294 | ||
3c50106f | 17295 | case PLUS: |
f0517163 | 17296 | if (mode == DFmode) |
066cd967 DE |
17297 | { |
17298 | if (GET_CODE (XEXP (x, 0)) == MULT) | |
17299 | { | |
17300 | /* FNMA accounted in outer NEG. */ | |
17301 | if (outer_code == NEG) | |
17302 | *total = rs6000_cost->dmul - rs6000_cost->fp; | |
17303 | else | |
17304 | *total = rs6000_cost->dmul; | |
17305 | } | |
17306 | else | |
17307 | *total = rs6000_cost->fp; | |
17308 | } | |
f0517163 | 17309 | else if (mode == SFmode) |
066cd967 DE |
17310 | { |
17311 | /* FNMA accounted in outer NEG. */ | |
17312 | if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT) | |
17313 | *total = 0; | |
17314 | else | |
17315 | *total = rs6000_cost->fp; | |
17316 | } | |
938bf747 RS |
17317 | else if (GET_CODE (XEXP (x, 0)) == MULT) |
17318 | { | |
17319 | /* The rs6000 doesn't have shift-and-add instructions. */ | |
17320 | rs6000_rtx_costs (XEXP (x, 0), MULT, PLUS, total); | |
17321 | *total += COSTS_N_INSNS (1); | |
17322 | } | |
f0517163 | 17323 | else |
066cd967 DE |
17324 | *total = COSTS_N_INSNS (1); |
17325 | return false; | |
3c50106f | 17326 | |
52190329 | 17327 | case MINUS: |
f0517163 | 17328 | if (mode == DFmode) |
066cd967 DE |
17329 | { |
17330 | if (GET_CODE (XEXP (x, 0)) == MULT) | |
17331 | { | |
17332 | /* FNMA accounted in outer NEG. */ | |
17333 | if (outer_code == NEG) | |
17334 | *total = 0; | |
17335 | else | |
17336 | *total = rs6000_cost->dmul; | |
17337 | } | |
17338 | else | |
17339 | *total = rs6000_cost->fp; | |
17340 | } | |
f0517163 | 17341 | else if (mode == SFmode) |
066cd967 DE |
17342 | { |
17343 | /* FNMA accounted in outer NEG. */ | |
17344 | if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT) | |
17345 | *total = 0; | |
17346 | else | |
17347 | *total = rs6000_cost->fp; | |
17348 | } | |
938bf747 RS |
17349 | else if (GET_CODE (XEXP (x, 0)) == MULT) |
17350 | { | |
17351 | /* The rs6000 doesn't have shift-and-sub instructions. */ | |
17352 | rs6000_rtx_costs (XEXP (x, 0), MULT, MINUS, total); | |
17353 | *total += COSTS_N_INSNS (1); | |
17354 | } | |
f0517163 RS |
17355 | else |
17356 | *total = COSTS_N_INSNS (1); | |
066cd967 | 17357 | return false; |
3c50106f RH |
17358 | |
17359 | case MULT: | |
8b897cfa | 17360 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) |
3c50106f | 17361 | { |
8b897cfa RS |
17362 | if (INTVAL (XEXP (x, 1)) >= -256 |
17363 | && INTVAL (XEXP (x, 1)) <= 255) | |
06a67bdd | 17364 | *total = rs6000_cost->mulsi_const9; |
8b897cfa | 17365 | else |
06a67bdd | 17366 | *total = rs6000_cost->mulsi_const; |
3c50106f | 17367 | } |
066cd967 DE |
17368 | /* FMA accounted in outer PLUS/MINUS. */ |
17369 | else if ((mode == DFmode || mode == SFmode) | |
17370 | && (outer_code == PLUS || outer_code == MINUS)) | |
17371 | *total = 0; | |
f0517163 | 17372 | else if (mode == DFmode) |
06a67bdd | 17373 | *total = rs6000_cost->dmul; |
f0517163 | 17374 | else if (mode == SFmode) |
06a67bdd | 17375 | *total = rs6000_cost->fp; |
f0517163 | 17376 | else if (mode == DImode) |
06a67bdd | 17377 | *total = rs6000_cost->muldi; |
8b897cfa | 17378 | else |
06a67bdd | 17379 | *total = rs6000_cost->mulsi; |
066cd967 | 17380 | return false; |
3c50106f RH |
17381 | |
17382 | case DIV: | |
17383 | case MOD: | |
f0517163 RS |
17384 | if (FLOAT_MODE_P (mode)) |
17385 | { | |
06a67bdd RS |
17386 | *total = mode == DFmode ? rs6000_cost->ddiv |
17387 | : rs6000_cost->sdiv; | |
066cd967 | 17388 | return false; |
f0517163 | 17389 | } |
5efb1046 | 17390 | /* FALLTHRU */ |
3c50106f RH |
17391 | |
17392 | case UDIV: | |
17393 | case UMOD: | |
627b6fe2 DJ |
17394 | if (GET_CODE (XEXP (x, 1)) == CONST_INT |
17395 | && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) | |
17396 | { | |
17397 | if (code == DIV || code == MOD) | |
17398 | /* Shift, addze */ | |
17399 | *total = COSTS_N_INSNS (2); | |
17400 | else | |
17401 | /* Shift */ | |
17402 | *total = COSTS_N_INSNS (1); | |
17403 | } | |
17404 | else | |
17405 | { | |
17406 | if (GET_MODE (XEXP (x, 1)) == DImode) | |
17407 | *total = rs6000_cost->divdi; | |
17408 | else | |
17409 | *total = rs6000_cost->divsi; | |
17410 | } | |
17411 | /* Add in shift and subtract for MOD. */ | |
17412 | if (code == MOD || code == UMOD) | |
17413 | *total += COSTS_N_INSNS (2); | |
066cd967 | 17414 | return false; |
3c50106f RH |
17415 | |
17416 | case FFS: | |
17417 | *total = COSTS_N_INSNS (4); | |
066cd967 | 17418 | return false; |
3c50106f | 17419 | |
06a67bdd | 17420 | case NOT: |
066cd967 DE |
17421 | if (outer_code == AND || outer_code == IOR || outer_code == XOR) |
17422 | { | |
17423 | *total = 0; | |
17424 | return false; | |
17425 | } | |
17426 | /* FALLTHRU */ | |
17427 | ||
17428 | case AND: | |
17429 | case IOR: | |
17430 | case XOR: | |
d5861a7a DE |
17431 | case ZERO_EXTRACT: |
17432 | *total = COSTS_N_INSNS (1); | |
17433 | return false; | |
17434 | ||
066cd967 DE |
17435 | case ASHIFT: |
17436 | case ASHIFTRT: | |
17437 | case LSHIFTRT: | |
17438 | case ROTATE: | |
17439 | case ROTATERT: | |
d5861a7a | 17440 | /* Handle mul_highpart. */ |
066cd967 DE |
17441 | if (outer_code == TRUNCATE |
17442 | && GET_CODE (XEXP (x, 0)) == MULT) | |
17443 | { | |
17444 | if (mode == DImode) | |
17445 | *total = rs6000_cost->muldi; | |
17446 | else | |
17447 | *total = rs6000_cost->mulsi; | |
17448 | return true; | |
17449 | } | |
d5861a7a DE |
17450 | else if (outer_code == AND) |
17451 | *total = 0; | |
17452 | else | |
17453 | *total = COSTS_N_INSNS (1); | |
17454 | return false; | |
17455 | ||
17456 | case SIGN_EXTEND: | |
17457 | case ZERO_EXTEND: | |
17458 | if (GET_CODE (XEXP (x, 0)) == MEM) | |
17459 | *total = 0; | |
17460 | else | |
17461 | *total = COSTS_N_INSNS (1); | |
066cd967 | 17462 | return false; |
06a67bdd | 17463 | |
066cd967 DE |
17464 | case COMPARE: |
17465 | case NEG: | |
17466 | case ABS: | |
17467 | if (!FLOAT_MODE_P (mode)) | |
17468 | { | |
17469 | *total = COSTS_N_INSNS (1); | |
17470 | return false; | |
17471 | } | |
17472 | /* FALLTHRU */ | |
17473 | ||
17474 | case FLOAT: | |
17475 | case UNSIGNED_FLOAT: | |
17476 | case FIX: | |
17477 | case UNSIGNED_FIX: | |
17478 | case FLOAT_EXTEND: | |
06a67bdd RS |
17479 | case FLOAT_TRUNCATE: |
17480 | *total = rs6000_cost->fp; | |
066cd967 | 17481 | return false; |
06a67bdd RS |
17482 | |
17483 | case UNSPEC: | |
17484 | switch (XINT (x, 1)) | |
17485 | { | |
17486 | case UNSPEC_FRSP: | |
17487 | *total = rs6000_cost->fp; | |
17488 | return true; | |
17489 | ||
17490 | default: | |
17491 | break; | |
17492 | } | |
17493 | break; | |
17494 | ||
17495 | case CALL: | |
17496 | case IF_THEN_ELSE: | |
17497 | if (optimize_size) | |
17498 | { | |
17499 | *total = COSTS_N_INSNS (1); | |
17500 | return true; | |
17501 | } | |
066cd967 DE |
17502 | else if (FLOAT_MODE_P (mode) |
17503 | && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS) | |
17504 | { | |
17505 | *total = rs6000_cost->fp; | |
17506 | return false; | |
17507 | } | |
17508 | ||
06a67bdd RS |
17509 | break; |
17510 | ||
3c50106f | 17511 | default: |
06a67bdd | 17512 | break; |
3c50106f | 17513 | } |
06a67bdd RS |
17514 | |
17515 | return false; | |
3c50106f RH |
17516 | } |
17517 | ||
34bb030a DE |
17518 | /* A C expression returning the cost of moving data from a register of class |
17519 | CLASS1 to one of CLASS2. */ | |
17520 | ||
17521 | int | |
f676971a | 17522 | rs6000_register_move_cost (enum machine_mode mode, |
a2369ed3 | 17523 | enum reg_class from, enum reg_class to) |
34bb030a DE |
17524 | { |
17525 | /* Moves from/to GENERAL_REGS. */ | |
17526 | if (reg_classes_intersect_p (to, GENERAL_REGS) | |
17527 | || reg_classes_intersect_p (from, GENERAL_REGS)) | |
17528 | { | |
17529 | if (! reg_classes_intersect_p (to, GENERAL_REGS)) | |
17530 | from = to; | |
17531 | ||
17532 | if (from == FLOAT_REGS || from == ALTIVEC_REGS) | |
17533 | return (rs6000_memory_move_cost (mode, from, 0) | |
17534 | + rs6000_memory_move_cost (mode, GENERAL_REGS, 0)); | |
17535 | ||
a3c9585f | 17536 | /* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */ |
34bb030a DE |
17537 | else if (from == CR_REGS) |
17538 | return 4; | |
17539 | ||
17540 | else | |
17541 | /* A move will cost one instruction per GPR moved. */ | |
17542 | return 2 * HARD_REGNO_NREGS (0, mode); | |
17543 | } | |
17544 | ||
17545 | /* Moving between two similar registers is just one instruction. */ | |
17546 | else if (reg_classes_intersect_p (to, from)) | |
17547 | return mode == TFmode ? 4 : 2; | |
17548 | ||
17549 | /* Everything else has to go through GENERAL_REGS. */ | |
17550 | else | |
f676971a | 17551 | return (rs6000_register_move_cost (mode, GENERAL_REGS, to) |
34bb030a DE |
17552 | + rs6000_register_move_cost (mode, from, GENERAL_REGS)); |
17553 | } | |
17554 | ||
17555 | /* A C expressions returning the cost of moving data of MODE from a register to | |
17556 | or from memory. */ | |
17557 | ||
17558 | int | |
f676971a | 17559 | rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class, |
a2369ed3 | 17560 | int in ATTRIBUTE_UNUSED) |
34bb030a DE |
17561 | { |
17562 | if (reg_classes_intersect_p (class, GENERAL_REGS)) | |
17563 | return 4 * HARD_REGNO_NREGS (0, mode); | |
17564 | else if (reg_classes_intersect_p (class, FLOAT_REGS)) | |
17565 | return 4 * HARD_REGNO_NREGS (32, mode); | |
17566 | else if (reg_classes_intersect_p (class, ALTIVEC_REGS)) | |
17567 | return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode); | |
17568 | else | |
17569 | return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS); | |
17570 | } | |
17571 | ||
ded9bf77 AH |
17572 | /* Return an RTX representing where to find the function value of a |
17573 | function returning MODE. */ | |
17574 | static rtx | |
17575 | rs6000_complex_function_value (enum machine_mode mode) | |
17576 | { | |
17577 | unsigned int regno; | |
17578 | rtx r1, r2; | |
17579 | enum machine_mode inner = GET_MODE_INNER (mode); | |
fb7e4164 | 17580 | unsigned int inner_bytes = GET_MODE_SIZE (inner); |
ded9bf77 | 17581 | |
4ed78545 | 17582 | if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS) |
ded9bf77 AH |
17583 | regno = FP_ARG_RETURN; |
17584 | else | |
17585 | { | |
17586 | regno = GP_ARG_RETURN; | |
17587 | ||
17588 | /* 32-bit is OK since it'll go in r3/r4. */ | |
fb7e4164 | 17589 | if (TARGET_32BIT && inner_bytes >= 4) |
ded9bf77 AH |
17590 | return gen_rtx_REG (mode, regno); |
17591 | } | |
17592 | ||
fb7e4164 AM |
17593 | if (inner_bytes >= 8) |
17594 | return gen_rtx_REG (mode, regno); | |
17595 | ||
ded9bf77 AH |
17596 | r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno), |
17597 | const0_rtx); | |
17598 | r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1), | |
fb7e4164 | 17599 | GEN_INT (inner_bytes)); |
ded9bf77 AH |
17600 | return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2)); |
17601 | } | |
17602 | ||
a6ebc39a AH |
17603 | /* Define how to find the value returned by a function. |
17604 | VALTYPE is the data type of the value (as a tree). | |
17605 | If the precise function being called is known, FUNC is its FUNCTION_DECL; | |
17606 | otherwise, FUNC is 0. | |
17607 | ||
17608 | On the SPE, both FPs and vectors are returned in r3. | |
17609 | ||
17610 | On RS/6000 an integer value is in r3 and a floating-point value is in | |
17611 | fp1, unless -msoft-float. */ | |
17612 | ||
17613 | rtx | |
17614 | rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED) | |
17615 | { | |
17616 | enum machine_mode mode; | |
2a8fa26c | 17617 | unsigned int regno; |
a6ebc39a | 17618 | |
0e67400a FJ |
17619 | if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode) |
17620 | { | |
17621 | /* Long long return value need be split in -mpowerpc64, 32bit ABI. */ | |
17622 | return gen_rtx_PARALLEL (DImode, | |
17623 | gen_rtvec (2, | |
17624 | gen_rtx_EXPR_LIST (VOIDmode, | |
17625 | gen_rtx_REG (SImode, GP_ARG_RETURN), | |
17626 | const0_rtx), | |
17627 | gen_rtx_EXPR_LIST (VOIDmode, | |
17628 | gen_rtx_REG (SImode, | |
17629 | GP_ARG_RETURN + 1), | |
17630 | GEN_INT (4)))); | |
17631 | } | |
17632 | ||
a6ebc39a AH |
17633 | if ((INTEGRAL_TYPE_P (valtype) |
17634 | && TYPE_PRECISION (valtype) < BITS_PER_WORD) | |
17635 | || POINTER_TYPE_P (valtype)) | |
b78d48dd | 17636 | mode = TARGET_32BIT ? SImode : DImode; |
a6ebc39a AH |
17637 | else |
17638 | mode = TYPE_MODE (valtype); | |
17639 | ||
4ed78545 | 17640 | if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS) |
2a8fa26c | 17641 | regno = FP_ARG_RETURN; |
ded9bf77 | 17642 | else if (TREE_CODE (valtype) == COMPLEX_TYPE |
42ba5130 | 17643 | && targetm.calls.split_complex_arg) |
ded9bf77 | 17644 | return rs6000_complex_function_value (mode); |
44688022 | 17645 | else if (TREE_CODE (valtype) == VECTOR_TYPE |
d0b2079e FJ |
17646 | && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI |
17647 | && ALTIVEC_VECTOR_MODE(mode)) | |
a6ebc39a AH |
17648 | regno = ALTIVEC_ARG_RETURN; |
17649 | else | |
17650 | regno = GP_ARG_RETURN; | |
17651 | ||
17652 | return gen_rtx_REG (mode, regno); | |
17653 | } | |
17654 | ||
ded9bf77 AH |
17655 | /* Define how to find the value returned by a library function |
17656 | assuming the value has mode MODE. */ | |
17657 | rtx | |
17658 | rs6000_libcall_value (enum machine_mode mode) | |
17659 | { | |
17660 | unsigned int regno; | |
17661 | ||
2e6c9641 FJ |
17662 | if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode) |
17663 | { | |
17664 | /* Long long return value need be split in -mpowerpc64, 32bit ABI. */ | |
17665 | return gen_rtx_PARALLEL (DImode, | |
17666 | gen_rtvec (2, | |
17667 | gen_rtx_EXPR_LIST (VOIDmode, | |
17668 | gen_rtx_REG (SImode, GP_ARG_RETURN), | |
17669 | const0_rtx), | |
17670 | gen_rtx_EXPR_LIST (VOIDmode, | |
17671 | gen_rtx_REG (SImode, | |
17672 | GP_ARG_RETURN + 1), | |
17673 | GEN_INT (4)))); | |
17674 | } | |
17675 | ||
ded9bf77 AH |
17676 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
17677 | && TARGET_HARD_FLOAT && TARGET_FPRS) | |
17678 | regno = FP_ARG_RETURN; | |
44688022 AM |
17679 | else if (ALTIVEC_VECTOR_MODE (mode) |
17680 | && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI) | |
ded9bf77 | 17681 | regno = ALTIVEC_ARG_RETURN; |
42ba5130 | 17682 | else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg) |
ded9bf77 AH |
17683 | return rs6000_complex_function_value (mode); |
17684 | else | |
17685 | regno = GP_ARG_RETURN; | |
17686 | ||
17687 | return gen_rtx_REG (mode, regno); | |
17688 | } | |
17689 | ||
d1d0c603 JJ |
17690 | /* Define the offset between two registers, FROM to be eliminated and its |
17691 | replacement TO, at the start of a routine. */ | |
17692 | HOST_WIDE_INT | |
17693 | rs6000_initial_elimination_offset (int from, int to) | |
17694 | { | |
17695 | rs6000_stack_t *info = rs6000_stack_info (); | |
17696 | HOST_WIDE_INT offset; | |
17697 | ||
17698 | if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
17699 | offset = info->push_p ? 0 : -info->total_size; | |
17700 | else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) | |
17701 | offset = info->total_size; | |
17702 | else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) | |
17703 | offset = info->push_p ? info->total_size : 0; | |
17704 | else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM) | |
17705 | offset = 0; | |
17706 | else | |
17707 | abort (); | |
17708 | ||
17709 | return offset; | |
17710 | } | |
17711 | ||
62e1dfcf NC |
17712 | /* Return true if TYPE is of type __ev64_opaque__. */ |
17713 | ||
c8e4f0e9 | 17714 | static bool |
a2369ed3 | 17715 | is_ev64_opaque_type (tree type) |
62e1dfcf | 17716 | { |
c8e4f0e9 | 17717 | return (TARGET_SPE |
2abe3e28 AH |
17718 | && (type == opaque_V2SI_type_node |
17719 | || type == opaque_V2SF_type_node | |
36252949 | 17720 | || type == opaque_p_V2SI_type_node)); |
62e1dfcf NC |
17721 | } |
17722 | ||
96714395 | 17723 | static rtx |
a2369ed3 | 17724 | rs6000_dwarf_register_span (rtx reg) |
96714395 AH |
17725 | { |
17726 | unsigned regno; | |
17727 | ||
17728 | if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg))) | |
17729 | return NULL_RTX; | |
17730 | ||
17731 | regno = REGNO (reg); | |
17732 | ||
17733 | /* The duality of the SPE register size wreaks all kinds of havoc. | |
17734 | This is a way of distinguishing r0 in 32-bits from r0 in | |
17735 | 64-bits. */ | |
17736 | return | |
17737 | gen_rtx_PARALLEL (VOIDmode, | |
3bd104d1 AH |
17738 | BYTES_BIG_ENDIAN |
17739 | ? gen_rtvec (2, | |
17740 | gen_rtx_REG (SImode, regno + 1200), | |
17741 | gen_rtx_REG (SImode, regno)) | |
17742 | : gen_rtvec (2, | |
17743 | gen_rtx_REG (SImode, regno), | |
17744 | gen_rtx_REG (SImode, regno + 1200))); | |
96714395 AH |
17745 | } |
17746 | ||
93c9d1ba AM |
17747 | /* Map internal gcc register numbers to DWARF2 register numbers. */ |
17748 | ||
17749 | unsigned int | |
17750 | rs6000_dbx_register_number (unsigned int regno) | |
17751 | { | |
17752 | if (regno <= 63 || write_symbols != DWARF2_DEBUG) | |
17753 | return regno; | |
17754 | if (regno == MQ_REGNO) | |
17755 | return 100; | |
17756 | if (regno == LINK_REGISTER_REGNUM) | |
17757 | return 108; | |
17758 | if (regno == COUNT_REGISTER_REGNUM) | |
17759 | return 109; | |
17760 | if (CR_REGNO_P (regno)) | |
17761 | return regno - CR0_REGNO + 86; | |
17762 | if (regno == XER_REGNO) | |
17763 | return 101; | |
17764 | if (ALTIVEC_REGNO_P (regno)) | |
17765 | return regno - FIRST_ALTIVEC_REGNO + 1124; | |
17766 | if (regno == VRSAVE_REGNO) | |
17767 | return 356; | |
17768 | if (regno == VSCR_REGNO) | |
17769 | return 67; | |
17770 | if (regno == SPE_ACC_REGNO) | |
17771 | return 99; | |
17772 | if (regno == SPEFSCR_REGNO) | |
17773 | return 612; | |
17774 | /* SPE high reg number. We get these values of regno from | |
17775 | rs6000_dwarf_register_span. */ | |
17776 | if (regno >= 1200 && regno < 1232) | |
17777 | return regno; | |
17778 | ||
17779 | abort (); | |
17780 | } | |
17781 | ||
93f90be6 | 17782 | /* target hook eh_return_filter_mode */ |
f676971a | 17783 | static enum machine_mode |
93f90be6 FJ |
17784 | rs6000_eh_return_filter_mode (void) |
17785 | { | |
17786 | return TARGET_32BIT ? SImode : word_mode; | |
17787 | } | |
17788 | ||
f676971a EC |
17789 | /* Target hook for vector_mode_supported_p. */ |
17790 | static bool | |
17791 | rs6000_vector_mode_supported_p (enum machine_mode mode) | |
17792 | { | |
17793 | ||
17794 | if (TARGET_SPE && SPE_VECTOR_MODE (mode)) | |
17795 | return true; | |
17796 | ||
17797 | else if (TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode)) | |
17798 | return true; | |
17799 | ||
17800 | else | |
17801 | return false; | |
17802 | } | |
17803 | ||
17211ab5 | 17804 | #include "gt-rs6000.h" |