OSDN Git Service

cd1e3bac8a4a04237a5819caa17fa7203996b75b
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.c
1 /* Subroutines used for code generation on IBM RS/6000.
2    Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4    Free Software Foundation, Inc.
5    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6
7    This file is part of GCC.
8
9    GCC is free software; you can redistribute it and/or modify it
10    under the terms of the GNU General Public License as published
11    by the Free Software Foundation; either version 3, or (at your
12    option) any later version.
13
14    GCC is distributed in the hope that it will be useful, but WITHOUT
15    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17    License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with GCC; see the file COPYING3.  If not see
21    <http://www.gnu.org/licenses/>.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
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"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "recog.h"
36 #include "obstack.h"
37 #include "tree.h"
38 #include "expr.h"
39 #include "optabs.h"
40 #include "except.h"
41 #include "function.h"
42 #include "output.h"
43 #include "basic-block.h"
44 #include "integrate.h"
45 #include "toplev.h"
46 #include "ggc.h"
47 #include "hashtab.h"
48 #include "tm_p.h"
49 #include "target.h"
50 #include "target-def.h"
51 #include "langhooks.h"
52 #include "reload.h"
53 #include "cfglayout.h"
54 #include "sched-int.h"
55 #include "gimple.h"
56 #include "tree-flow.h"
57 #include "intl.h"
58 #include "params.h"
59 #include "tm-constrs.h"
60 #if TARGET_XCOFF
61 #include "xcoffout.h"  /* get declarations of xcoff_*_section_name */
62 #endif
63 #if TARGET_MACHO
64 #include "gstab.h"  /* for N_SLINE */
65 #endif
66
67 #ifndef TARGET_NO_PROTOTYPE
68 #define TARGET_NO_PROTOTYPE 0
69 #endif
70
71 #define min(A,B)        ((A) < (B) ? (A) : (B))
72 #define max(A,B)        ((A) > (B) ? (A) : (B))
73
74 /* Structure used to define the rs6000 stack */
75 typedef struct rs6000_stack {
76   int first_gp_reg_save;        /* first callee saved GP register used */
77   int first_fp_reg_save;        /* first callee saved FP register used */
78   int first_altivec_reg_save;   /* first callee saved AltiVec register used */
79   int lr_save_p;                /* true if the link reg needs to be saved */
80   int cr_save_p;                /* true if the CR reg needs to be saved */
81   unsigned int vrsave_mask;     /* mask of vec registers to save */
82   int push_p;                   /* true if we need to allocate stack space */
83   int calls_p;                  /* true if the function makes any calls */
84   int world_save_p;             /* true if we're saving *everything*:
85                                    r13-r31, cr, f14-f31, vrsave, v20-v31  */
86   enum rs6000_abi abi;          /* which ABI to use */
87   int gp_save_offset;           /* offset to save GP regs from initial SP */
88   int fp_save_offset;           /* offset to save FP regs from initial SP */
89   int altivec_save_offset;      /* offset to save AltiVec regs from initial SP */
90   int lr_save_offset;           /* offset to save LR from initial SP */
91   int cr_save_offset;           /* offset to save CR from initial SP */
92   int vrsave_save_offset;       /* offset to save VRSAVE from initial SP */
93   int spe_gp_save_offset;       /* offset to save spe 64-bit gprs  */
94   int varargs_save_offset;      /* offset to save the varargs registers */
95   int ehrd_offset;              /* offset to EH return data */
96   int reg_size;                 /* register size (4 or 8) */
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 vrsave_size;              /* size to hold VRSAVE if not in save_size */
106   int altivec_padding_size;     /* size of altivec alignment padding if
107                                    not in save_size */
108   int spe_gp_size;              /* size of 64-bit GPR save size for SPE */
109   int spe_padding_size;
110   HOST_WIDE_INT total_size;     /* total bytes allocated for stack */
111   int spe_64bit_regs_used;
112 } rs6000_stack_t;
113
114 /* A C structure for machine-specific, per-function data.
115    This is added to the cfun structure.  */
116 typedef struct GTY(()) machine_function
117 {
118   /* Some local-dynamic symbol.  */
119   const char *some_ld_name;
120   /* Whether the instruction chain has been scanned already.  */
121   int insn_chain_scanned_p;
122   /* Flags if __builtin_return_address (n) with n >= 1 was used.  */
123   int ra_needs_full_frame;
124   /* Flags if __builtin_return_address (0) was used.  */
125   int ra_need_lr;
126   /* Cache lr_save_p after expansion of builtin_eh_return.  */
127   int lr_save_state;
128   /* Offset from virtual_stack_vars_rtx to the start of the ABI_V4
129      varargs save area.  */
130   HOST_WIDE_INT varargs_save_offset;
131   /* Temporary stack slot to use for SDmode copies.  This slot is
132      64-bits wide and is allocated early enough so that the offset
133      does not overflow the 16-bit load/store offset field.  */
134   rtx sdmode_stack_slot;
135 } machine_function;
136
137 /* Target cpu type */
138
139 enum processor_type rs6000_cpu;
140 struct rs6000_cpu_select rs6000_select[3] =
141 {
142   /* switch             name,                   tune    arch */
143   { (const char *)0,    "--with-cpu=",          1,      1 },
144   { (const char *)0,    "-mcpu=",               1,      1 },
145   { (const char *)0,    "-mtune=",              1,      0 },
146 };
147
148 /* Always emit branch hint bits.  */
149 static GTY(()) bool rs6000_always_hint;
150
151 /* Schedule instructions for group formation.  */
152 static GTY(()) bool rs6000_sched_groups;
153
154 /* Align branch targets.  */
155 static GTY(()) bool rs6000_align_branch_targets;
156
157 /* Support for -msched-costly-dep option.  */
158 const char *rs6000_sched_costly_dep_str;
159 enum rs6000_dependence_cost rs6000_sched_costly_dep;
160
161 /* Support for -minsert-sched-nops option.  */
162 const char *rs6000_sched_insert_nops_str;
163 enum rs6000_nop_insertion rs6000_sched_insert_nops;
164
165 /* Support targetm.vectorize.builtin_mask_for_load.  */
166 static GTY(()) tree altivec_builtin_mask_for_load;
167
168 /* Size of long double.  */
169 int rs6000_long_double_type_size;
170
171 /* IEEE quad extended precision long double. */
172 int rs6000_ieeequad;
173
174 /* Nonzero to use AltiVec ABI.  */
175 int rs6000_altivec_abi;
176
177 /* Nonzero if we want SPE SIMD instructions.  */
178 int rs6000_spe;
179
180 /* Nonzero if we want SPE ABI extensions.  */
181 int rs6000_spe_abi;
182
183 /* Nonzero if floating point operations are done in the GPRs.  */
184 int rs6000_float_gprs = 0;
185
186 /* Nonzero if we want Darwin's struct-by-value-in-regs ABI.  */
187 int rs6000_darwin64_abi;
188
189 /* Set to nonzero once AIX common-mode calls have been defined.  */
190 static GTY(()) int common_mode_defined;
191
192 /* Label number of label created for -mrelocatable, to call to so we can
193    get the address of the GOT section */
194 int rs6000_pic_labelno;
195
196 #ifdef USING_ELFOS_H
197 /* Which abi to adhere to */
198 const char *rs6000_abi_name;
199
200 /* Semantics of the small data area */
201 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
202
203 /* Which small data model to use */
204 const char *rs6000_sdata_name = (char *)0;
205
206 /* Counter for labels which are to be placed in .fixup.  */
207 int fixuplabelno = 0;
208 #endif
209
210 /* Bit size of immediate TLS offsets and string from which it is decoded.  */
211 int rs6000_tls_size = 32;
212 const char *rs6000_tls_size_string;
213
214 /* ABI enumeration available for subtarget to use.  */
215 enum rs6000_abi rs6000_current_abi;
216
217 /* Whether to use variant of AIX ABI for PowerPC64 Linux.  */
218 int dot_symbols;
219
220 /* Debug flags */
221 const char *rs6000_debug_name;
222 int rs6000_debug_stack;         /* debug stack applications */
223 int rs6000_debug_arg;           /* debug argument handling */
224 int rs6000_debug_reg;           /* debug register classes */
225 int rs6000_debug_addr;          /* debug memory addressing */
226 int rs6000_debug_cost;          /* debug rtx_costs */
227
228 /* Specify the machine mode that pointers have.  After generation of rtl, the
229    compiler makes no further distinction between pointers and any other objects
230    of this machine mode.  The type is unsigned since not all things that
231    include rs6000.h also include machmode.h.  */
232 unsigned rs6000_pmode;
233
234 /* Width in bits of a pointer.  */
235 unsigned rs6000_pointer_size;
236
237
238 /* Value is TRUE if register/mode pair is acceptable.  */
239 bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
240
241 /* Maximum number of registers needed for a given register class and mode.  */
242 unsigned char rs6000_class_max_nregs[NUM_MACHINE_MODES][LIM_REG_CLASSES];
243
244 /* How many registers are needed for a given register and mode.  */
245 unsigned char rs6000_hard_regno_nregs[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
246
247 /* Map register number to register class.  */
248 enum reg_class rs6000_regno_regclass[FIRST_PSEUDO_REGISTER];
249
250 /* Reload functions based on the type and the vector unit.  */
251 static enum insn_code rs6000_vector_reload[NUM_MACHINE_MODES][2];
252
253 /* Built in types.  */
254 tree rs6000_builtin_types[RS6000_BTI_MAX];
255 tree rs6000_builtin_decls[RS6000_BUILTIN_COUNT];
256
257 const char *rs6000_traceback_name;
258 static enum {
259   traceback_default = 0,
260   traceback_none,
261   traceback_part,
262   traceback_full
263 } rs6000_traceback;
264
265 /* Flag to say the TOC is initialized */
266 int toc_initialized;
267 char toc_label_name[10];
268
269 /* Cached value of rs6000_variable_issue. This is cached in
270    rs6000_variable_issue hook and returned from rs6000_sched_reorder2.  */
271 static short cached_can_issue_more;
272
273 static GTY(()) section *read_only_data_section;
274 static GTY(()) section *private_data_section;
275 static GTY(()) section *read_only_private_data_section;
276 static GTY(()) section *sdata2_section;
277 static GTY(()) section *toc_section;
278
279 /* Control alignment for fields within structures.  */
280 /* String from -malign-XXXXX.  */
281 int rs6000_alignment_flags;
282
283 /* True for any options that were explicitly set.  */
284 static struct {
285   bool aix_struct_ret;          /* True if -maix-struct-ret was used.  */
286   bool alignment;               /* True if -malign- was used.  */
287   bool spe_abi;                 /* True if -mabi=spe/no-spe was used.  */
288   bool altivec_abi;             /* True if -mabi=altivec/no-altivec used.  */
289   bool spe;                     /* True if -mspe= was used.  */
290   bool float_gprs;              /* True if -mfloat-gprs= was used.  */
291   bool long_double;             /* True if -mlong-double- was used.  */
292   bool ieee;                    /* True if -mabi=ieee/ibmlongdouble used.  */
293   bool vrsave;                  /* True if -mvrsave was used.  */
294 } rs6000_explicit_options;
295
296 struct builtin_description
297 {
298   /* mask is not const because we're going to alter it below.  This
299      nonsense will go away when we rewrite the -march infrastructure
300      to give us more target flag bits.  */
301   unsigned int mask;
302   const enum insn_code icode;
303   const char *const name;
304   const enum rs6000_builtins code;
305 };
306
307 /* Describe the vector unit used for modes.  */
308 enum rs6000_vector rs6000_vector_unit[NUM_MACHINE_MODES];
309 enum rs6000_vector rs6000_vector_mem[NUM_MACHINE_MODES];
310
311 /* Register classes for various constraints that are based on the target
312    switches.  */
313 enum reg_class rs6000_constraints[RS6000_CONSTRAINT_MAX];
314
315 /* Describe the alignment of a vector.  */
316 int rs6000_vector_align[NUM_MACHINE_MODES];
317
318 /* Map selected modes to types for builtins.  */
319 static GTY(()) tree builtin_mode_to_type[MAX_MACHINE_MODE][2];
320 \f
321 /* Target cpu costs.  */
322
323 struct processor_costs {
324   const int mulsi;        /* cost of SImode multiplication.  */
325   const int mulsi_const;  /* cost of SImode multiplication by constant.  */
326   const int mulsi_const9; /* cost of SImode mult by short constant.  */
327   const int muldi;        /* cost of DImode multiplication.  */
328   const int divsi;        /* cost of SImode division.  */
329   const int divdi;        /* cost of DImode division.  */
330   const int fp;           /* cost of simple SFmode and DFmode insns.  */
331   const int dmul;         /* cost of DFmode multiplication (and fmadd).  */
332   const int sdiv;         /* cost of SFmode division (fdivs).  */
333   const int ddiv;         /* cost of DFmode division (fdiv).  */
334   const int cache_line_size;    /* cache line size in bytes. */
335   const int l1_cache_size;      /* size of l1 cache, in kilobytes.  */
336   const int l2_cache_size;      /* size of l2 cache, in kilobytes.  */
337   const int simultaneous_prefetches; /* number of parallel prefetch
338                                         operations.  */
339 };
340
341 const struct processor_costs *rs6000_cost;
342
343 /* Processor costs (relative to an add) */
344
345 /* Instruction size costs on 32bit processors.  */
346 static const
347 struct processor_costs size32_cost = {
348   COSTS_N_INSNS (1),    /* mulsi */
349   COSTS_N_INSNS (1),    /* mulsi_const */
350   COSTS_N_INSNS (1),    /* mulsi_const9 */
351   COSTS_N_INSNS (1),    /* muldi */
352   COSTS_N_INSNS (1),    /* divsi */
353   COSTS_N_INSNS (1),    /* divdi */
354   COSTS_N_INSNS (1),    /* fp */
355   COSTS_N_INSNS (1),    /* dmul */
356   COSTS_N_INSNS (1),    /* sdiv */
357   COSTS_N_INSNS (1),    /* ddiv */
358   32,
359   0,
360   0,
361   0,
362 };
363
364 /* Instruction size costs on 64bit processors.  */
365 static const
366 struct processor_costs size64_cost = {
367   COSTS_N_INSNS (1),    /* mulsi */
368   COSTS_N_INSNS (1),    /* mulsi_const */
369   COSTS_N_INSNS (1),    /* mulsi_const9 */
370   COSTS_N_INSNS (1),    /* muldi */
371   COSTS_N_INSNS (1),    /* divsi */
372   COSTS_N_INSNS (1),    /* divdi */
373   COSTS_N_INSNS (1),    /* fp */
374   COSTS_N_INSNS (1),    /* dmul */
375   COSTS_N_INSNS (1),    /* sdiv */
376   COSTS_N_INSNS (1),    /* ddiv */
377   128,
378   0,
379   0,
380   0,
381 };
382
383 /* Instruction costs on RIOS1 processors.  */
384 static const
385 struct processor_costs rios1_cost = {
386   COSTS_N_INSNS (5),    /* mulsi */
387   COSTS_N_INSNS (4),    /* mulsi_const */
388   COSTS_N_INSNS (3),    /* mulsi_const9 */
389   COSTS_N_INSNS (5),    /* muldi */
390   COSTS_N_INSNS (19),   /* divsi */
391   COSTS_N_INSNS (19),   /* divdi */
392   COSTS_N_INSNS (2),    /* fp */
393   COSTS_N_INSNS (2),    /* dmul */
394   COSTS_N_INSNS (19),   /* sdiv */
395   COSTS_N_INSNS (19),   /* ddiv */
396   128,                  /* cache line size */
397   64,                   /* l1 cache */
398   512,                  /* l2 cache */
399   0,                    /* streams */
400 };
401
402 /* Instruction costs on RIOS2 processors.  */
403 static const
404 struct processor_costs rios2_cost = {
405   COSTS_N_INSNS (2),    /* mulsi */
406   COSTS_N_INSNS (2),    /* mulsi_const */
407   COSTS_N_INSNS (2),    /* mulsi_const9 */
408   COSTS_N_INSNS (2),    /* muldi */
409   COSTS_N_INSNS (13),   /* divsi */
410   COSTS_N_INSNS (13),   /* divdi */
411   COSTS_N_INSNS (2),    /* fp */
412   COSTS_N_INSNS (2),    /* dmul */
413   COSTS_N_INSNS (17),   /* sdiv */
414   COSTS_N_INSNS (17),   /* ddiv */
415   256,                  /* cache line size */
416   256,                  /* l1 cache */
417   1024,                 /* l2 cache */
418   0,                    /* streams */
419 };
420
421 /* Instruction costs on RS64A processors.  */
422 static const
423 struct processor_costs rs64a_cost = {
424   COSTS_N_INSNS (20),   /* mulsi */
425   COSTS_N_INSNS (12),   /* mulsi_const */
426   COSTS_N_INSNS (8),    /* mulsi_const9 */
427   COSTS_N_INSNS (34),   /* muldi */
428   COSTS_N_INSNS (65),   /* divsi */
429   COSTS_N_INSNS (67),   /* divdi */
430   COSTS_N_INSNS (4),    /* fp */
431   COSTS_N_INSNS (4),    /* dmul */
432   COSTS_N_INSNS (31),   /* sdiv */
433   COSTS_N_INSNS (31),   /* ddiv */
434   128,                  /* cache line size */
435   128,                  /* l1 cache */
436   2048,                 /* l2 cache */
437   1,                    /* streams */
438 };
439
440 /* Instruction costs on MPCCORE processors.  */
441 static const
442 struct processor_costs mpccore_cost = {
443   COSTS_N_INSNS (2),    /* mulsi */
444   COSTS_N_INSNS (2),    /* mulsi_const */
445   COSTS_N_INSNS (2),    /* mulsi_const9 */
446   COSTS_N_INSNS (2),    /* muldi */
447   COSTS_N_INSNS (6),    /* divsi */
448   COSTS_N_INSNS (6),    /* divdi */
449   COSTS_N_INSNS (4),    /* fp */
450   COSTS_N_INSNS (5),    /* dmul */
451   COSTS_N_INSNS (10),   /* sdiv */
452   COSTS_N_INSNS (17),   /* ddiv */
453   32,                   /* cache line size */
454   4,                    /* l1 cache */
455   16,                   /* l2 cache */
456   1,                    /* streams */
457 };
458
459 /* Instruction costs on PPC403 processors.  */
460 static const
461 struct processor_costs ppc403_cost = {
462   COSTS_N_INSNS (4),    /* mulsi */
463   COSTS_N_INSNS (4),    /* mulsi_const */
464   COSTS_N_INSNS (4),    /* mulsi_const9 */
465   COSTS_N_INSNS (4),    /* muldi */
466   COSTS_N_INSNS (33),   /* divsi */
467   COSTS_N_INSNS (33),   /* divdi */
468   COSTS_N_INSNS (11),   /* fp */
469   COSTS_N_INSNS (11),   /* dmul */
470   COSTS_N_INSNS (11),   /* sdiv */
471   COSTS_N_INSNS (11),   /* ddiv */
472   32,                   /* cache line size */
473   4,                    /* l1 cache */
474   16,                   /* l2 cache */
475   1,                    /* streams */
476 };
477
478 /* Instruction costs on PPC405 processors.  */
479 static const
480 struct processor_costs ppc405_cost = {
481   COSTS_N_INSNS (5),    /* mulsi */
482   COSTS_N_INSNS (4),    /* mulsi_const */
483   COSTS_N_INSNS (3),    /* mulsi_const9 */
484   COSTS_N_INSNS (5),    /* muldi */
485   COSTS_N_INSNS (35),   /* divsi */
486   COSTS_N_INSNS (35),   /* divdi */
487   COSTS_N_INSNS (11),   /* fp */
488   COSTS_N_INSNS (11),   /* dmul */
489   COSTS_N_INSNS (11),   /* sdiv */
490   COSTS_N_INSNS (11),   /* ddiv */
491   32,                   /* cache line size */
492   16,                   /* l1 cache */
493   128,                  /* l2 cache */
494   1,                    /* streams */
495 };
496
497 /* Instruction costs on PPC440 processors.  */
498 static const
499 struct processor_costs ppc440_cost = {
500   COSTS_N_INSNS (3),    /* mulsi */
501   COSTS_N_INSNS (2),    /* mulsi_const */
502   COSTS_N_INSNS (2),    /* mulsi_const9 */
503   COSTS_N_INSNS (3),    /* muldi */
504   COSTS_N_INSNS (34),   /* divsi */
505   COSTS_N_INSNS (34),   /* divdi */
506   COSTS_N_INSNS (5),    /* fp */
507   COSTS_N_INSNS (5),    /* dmul */
508   COSTS_N_INSNS (19),   /* sdiv */
509   COSTS_N_INSNS (33),   /* ddiv */
510   32,                   /* cache line size */
511   32,                   /* l1 cache */
512   256,                  /* l2 cache */
513   1,                    /* streams */
514 };
515
516 /* Instruction costs on PPC476 processors.  */
517 static const
518 struct processor_costs ppc476_cost = {
519   COSTS_N_INSNS (4),    /* mulsi */
520   COSTS_N_INSNS (4),    /* mulsi_const */
521   COSTS_N_INSNS (4),    /* mulsi_const9 */
522   COSTS_N_INSNS (4),    /* muldi */
523   COSTS_N_INSNS (11),   /* divsi */
524   COSTS_N_INSNS (11),   /* divdi */
525   COSTS_N_INSNS (6),    /* fp */
526   COSTS_N_INSNS (6),    /* dmul */
527   COSTS_N_INSNS (19),   /* sdiv */
528   COSTS_N_INSNS (33),   /* ddiv */
529   32,                   /* l1 cache line size */
530   32,                   /* l1 cache */
531   512,                  /* l2 cache */
532   1,                    /* streams */
533 };
534
535 /* Instruction costs on PPC601 processors.  */
536 static const
537 struct processor_costs ppc601_cost = {
538   COSTS_N_INSNS (5),    /* mulsi */
539   COSTS_N_INSNS (5),    /* mulsi_const */
540   COSTS_N_INSNS (5),    /* mulsi_const9 */
541   COSTS_N_INSNS (5),    /* muldi */
542   COSTS_N_INSNS (36),   /* divsi */
543   COSTS_N_INSNS (36),   /* divdi */
544   COSTS_N_INSNS (4),    /* fp */
545   COSTS_N_INSNS (5),    /* dmul */
546   COSTS_N_INSNS (17),   /* sdiv */
547   COSTS_N_INSNS (31),   /* ddiv */
548   32,                   /* cache line size */
549   32,                   /* l1 cache */
550   256,                  /* l2 cache */
551   1,                    /* streams */
552 };
553
554 /* Instruction costs on PPC603 processors.  */
555 static const
556 struct processor_costs ppc603_cost = {
557   COSTS_N_INSNS (5),    /* mulsi */
558   COSTS_N_INSNS (3),    /* mulsi_const */
559   COSTS_N_INSNS (2),    /* mulsi_const9 */
560   COSTS_N_INSNS (5),    /* muldi */
561   COSTS_N_INSNS (37),   /* divsi */
562   COSTS_N_INSNS (37),   /* divdi */
563   COSTS_N_INSNS (3),    /* fp */
564   COSTS_N_INSNS (4),    /* dmul */
565   COSTS_N_INSNS (18),   /* sdiv */
566   COSTS_N_INSNS (33),   /* ddiv */
567   32,                   /* cache line size */
568   8,                    /* l1 cache */
569   64,                   /* l2 cache */
570   1,                    /* streams */
571 };
572
573 /* Instruction costs on PPC604 processors.  */
574 static const
575 struct processor_costs ppc604_cost = {
576   COSTS_N_INSNS (4),    /* mulsi */
577   COSTS_N_INSNS (4),    /* mulsi_const */
578   COSTS_N_INSNS (4),    /* mulsi_const9 */
579   COSTS_N_INSNS (4),    /* muldi */
580   COSTS_N_INSNS (20),   /* divsi */
581   COSTS_N_INSNS (20),   /* divdi */
582   COSTS_N_INSNS (3),    /* fp */
583   COSTS_N_INSNS (3),    /* dmul */
584   COSTS_N_INSNS (18),   /* sdiv */
585   COSTS_N_INSNS (32),   /* ddiv */
586   32,                   /* cache line size */
587   16,                   /* l1 cache */
588   512,                  /* l2 cache */
589   1,                    /* streams */
590 };
591
592 /* Instruction costs on PPC604e processors.  */
593 static const
594 struct processor_costs ppc604e_cost = {
595   COSTS_N_INSNS (2),    /* mulsi */
596   COSTS_N_INSNS (2),    /* mulsi_const */
597   COSTS_N_INSNS (2),    /* mulsi_const9 */
598   COSTS_N_INSNS (2),    /* muldi */
599   COSTS_N_INSNS (20),   /* divsi */
600   COSTS_N_INSNS (20),   /* divdi */
601   COSTS_N_INSNS (3),    /* fp */
602   COSTS_N_INSNS (3),    /* dmul */
603   COSTS_N_INSNS (18),   /* sdiv */
604   COSTS_N_INSNS (32),   /* ddiv */
605   32,                   /* cache line size */
606   32,                   /* l1 cache */
607   1024,                 /* l2 cache */
608   1,                    /* streams */
609 };
610
611 /* Instruction costs on PPC620 processors.  */
612 static const
613 struct processor_costs ppc620_cost = {
614   COSTS_N_INSNS (5),    /* mulsi */
615   COSTS_N_INSNS (4),    /* mulsi_const */
616   COSTS_N_INSNS (3),    /* mulsi_const9 */
617   COSTS_N_INSNS (7),    /* muldi */
618   COSTS_N_INSNS (21),   /* divsi */
619   COSTS_N_INSNS (37),   /* divdi */
620   COSTS_N_INSNS (3),    /* fp */
621   COSTS_N_INSNS (3),    /* dmul */
622   COSTS_N_INSNS (18),   /* sdiv */
623   COSTS_N_INSNS (32),   /* ddiv */
624   128,                  /* cache line size */
625   32,                   /* l1 cache */
626   1024,                 /* l2 cache */
627   1,                    /* streams */
628 };
629
630 /* Instruction costs on PPC630 processors.  */
631 static const
632 struct processor_costs ppc630_cost = {
633   COSTS_N_INSNS (5),    /* mulsi */
634   COSTS_N_INSNS (4),    /* mulsi_const */
635   COSTS_N_INSNS (3),    /* mulsi_const9 */
636   COSTS_N_INSNS (7),    /* muldi */
637   COSTS_N_INSNS (21),   /* divsi */
638   COSTS_N_INSNS (37),   /* divdi */
639   COSTS_N_INSNS (3),    /* fp */
640   COSTS_N_INSNS (3),    /* dmul */
641   COSTS_N_INSNS (17),   /* sdiv */
642   COSTS_N_INSNS (21),   /* ddiv */
643   128,                  /* cache line size */
644   64,                   /* l1 cache */
645   1024,                 /* l2 cache */
646   1,                    /* streams */
647 };
648
649 /* Instruction costs on Cell processor.  */
650 /* COSTS_N_INSNS (1) ~ one add.  */
651 static const
652 struct processor_costs ppccell_cost = {
653   COSTS_N_INSNS (9/2)+2,    /* mulsi */
654   COSTS_N_INSNS (6/2),    /* mulsi_const */
655   COSTS_N_INSNS (6/2),    /* mulsi_const9 */
656   COSTS_N_INSNS (15/2)+2,   /* muldi */
657   COSTS_N_INSNS (38/2),   /* divsi */
658   COSTS_N_INSNS (70/2),   /* divdi */
659   COSTS_N_INSNS (10/2),   /* fp */
660   COSTS_N_INSNS (10/2),   /* dmul */
661   COSTS_N_INSNS (74/2),   /* sdiv */
662   COSTS_N_INSNS (74/2),   /* ddiv */
663   128,                  /* cache line size */
664   32,                   /* l1 cache */
665   512,                  /* l2 cache */
666   6,                    /* streams */
667 };
668
669 /* Instruction costs on PPC750 and PPC7400 processors.  */
670 static const
671 struct processor_costs ppc750_cost = {
672   COSTS_N_INSNS (5),    /* mulsi */
673   COSTS_N_INSNS (3),    /* mulsi_const */
674   COSTS_N_INSNS (2),    /* mulsi_const9 */
675   COSTS_N_INSNS (5),    /* muldi */
676   COSTS_N_INSNS (17),   /* divsi */
677   COSTS_N_INSNS (17),   /* divdi */
678   COSTS_N_INSNS (3),    /* fp */
679   COSTS_N_INSNS (3),    /* dmul */
680   COSTS_N_INSNS (17),   /* sdiv */
681   COSTS_N_INSNS (31),   /* ddiv */
682   32,                   /* cache line size */
683   32,                   /* l1 cache */
684   512,                  /* l2 cache */
685   1,                    /* streams */
686 };
687
688 /* Instruction costs on PPC7450 processors.  */
689 static const
690 struct processor_costs ppc7450_cost = {
691   COSTS_N_INSNS (4),    /* mulsi */
692   COSTS_N_INSNS (3),    /* mulsi_const */
693   COSTS_N_INSNS (3),    /* mulsi_const9 */
694   COSTS_N_INSNS (4),    /* muldi */
695   COSTS_N_INSNS (23),   /* divsi */
696   COSTS_N_INSNS (23),   /* divdi */
697   COSTS_N_INSNS (5),    /* fp */
698   COSTS_N_INSNS (5),    /* dmul */
699   COSTS_N_INSNS (21),   /* sdiv */
700   COSTS_N_INSNS (35),   /* ddiv */
701   32,                   /* cache line size */
702   32,                   /* l1 cache */
703   1024,                 /* l2 cache */
704   1,                    /* streams */
705 };
706
707 /* Instruction costs on PPC8540 processors.  */
708 static const
709 struct processor_costs ppc8540_cost = {
710   COSTS_N_INSNS (4),    /* mulsi */
711   COSTS_N_INSNS (4),    /* mulsi_const */
712   COSTS_N_INSNS (4),    /* mulsi_const9 */
713   COSTS_N_INSNS (4),    /* muldi */
714   COSTS_N_INSNS (19),   /* divsi */
715   COSTS_N_INSNS (19),   /* divdi */
716   COSTS_N_INSNS (4),    /* fp */
717   COSTS_N_INSNS (4),    /* dmul */
718   COSTS_N_INSNS (29),   /* sdiv */
719   COSTS_N_INSNS (29),   /* ddiv */
720   32,                   /* cache line size */
721   32,                   /* l1 cache */
722   256,                  /* l2 cache */
723   1,                    /* prefetch streams /*/
724 };
725
726 /* Instruction costs on E300C2 and E300C3 cores.  */
727 static const
728 struct processor_costs ppce300c2c3_cost = {
729   COSTS_N_INSNS (4),    /* mulsi */
730   COSTS_N_INSNS (4),    /* mulsi_const */
731   COSTS_N_INSNS (4),    /* mulsi_const9 */
732   COSTS_N_INSNS (4),    /* muldi */
733   COSTS_N_INSNS (19),   /* divsi */
734   COSTS_N_INSNS (19),   /* divdi */
735   COSTS_N_INSNS (3),    /* fp */
736   COSTS_N_INSNS (4),    /* dmul */
737   COSTS_N_INSNS (18),   /* sdiv */
738   COSTS_N_INSNS (33),   /* ddiv */
739   32,
740   16,                   /* l1 cache */
741   16,                   /* l2 cache */
742   1,                    /* prefetch streams /*/
743 };
744
745 /* Instruction costs on PPCE500MC processors.  */
746 static const
747 struct processor_costs ppce500mc_cost = {
748   COSTS_N_INSNS (4),    /* mulsi */
749   COSTS_N_INSNS (4),    /* mulsi_const */
750   COSTS_N_INSNS (4),    /* mulsi_const9 */
751   COSTS_N_INSNS (4),    /* muldi */
752   COSTS_N_INSNS (14),   /* divsi */
753   COSTS_N_INSNS (14),   /* divdi */
754   COSTS_N_INSNS (8),    /* fp */
755   COSTS_N_INSNS (10),   /* dmul */
756   COSTS_N_INSNS (36),   /* sdiv */
757   COSTS_N_INSNS (66),   /* ddiv */
758   64,                   /* cache line size */
759   32,                   /* l1 cache */
760   128,                  /* l2 cache */
761   1,                    /* prefetch streams /*/
762 };
763
764 /* Instruction costs on PPCE500MC64 processors.  */
765 static const
766 struct processor_costs ppce500mc64_cost = {
767   COSTS_N_INSNS (4),    /* mulsi */
768   COSTS_N_INSNS (4),    /* mulsi_const */
769   COSTS_N_INSNS (4),    /* mulsi_const9 */
770   COSTS_N_INSNS (4),    /* muldi */
771   COSTS_N_INSNS (14),   /* divsi */
772   COSTS_N_INSNS (14),   /* divdi */
773   COSTS_N_INSNS (4),    /* fp */
774   COSTS_N_INSNS (10),   /* dmul */
775   COSTS_N_INSNS (36),   /* sdiv */
776   COSTS_N_INSNS (66),   /* ddiv */
777   64,                   /* cache line size */
778   32,                   /* l1 cache */
779   128,                  /* l2 cache */
780   1,                    /* prefetch streams /*/
781 };
782
783 /* Instruction costs on POWER4 and POWER5 processors.  */
784 static const
785 struct processor_costs power4_cost = {
786   COSTS_N_INSNS (3),    /* mulsi */
787   COSTS_N_INSNS (2),    /* mulsi_const */
788   COSTS_N_INSNS (2),    /* mulsi_const9 */
789   COSTS_N_INSNS (4),    /* muldi */
790   COSTS_N_INSNS (18),   /* divsi */
791   COSTS_N_INSNS (34),   /* divdi */
792   COSTS_N_INSNS (3),    /* fp */
793   COSTS_N_INSNS (3),    /* dmul */
794   COSTS_N_INSNS (17),   /* sdiv */
795   COSTS_N_INSNS (17),   /* ddiv */
796   128,                  /* cache line size */
797   32,                   /* l1 cache */
798   1024,                 /* l2 cache */
799   8,                    /* prefetch streams /*/
800 };
801
802 /* Instruction costs on POWER6 processors.  */
803 static const
804 struct processor_costs power6_cost = {
805   COSTS_N_INSNS (8),    /* mulsi */
806   COSTS_N_INSNS (8),    /* mulsi_const */
807   COSTS_N_INSNS (8),    /* mulsi_const9 */
808   COSTS_N_INSNS (8),    /* muldi */
809   COSTS_N_INSNS (22),   /* divsi */
810   COSTS_N_INSNS (28),   /* divdi */
811   COSTS_N_INSNS (3),    /* fp */
812   COSTS_N_INSNS (3),    /* dmul */
813   COSTS_N_INSNS (13),   /* sdiv */
814   COSTS_N_INSNS (16),   /* ddiv */
815   128,                  /* cache line size */
816   64,                   /* l1 cache */
817   2048,                 /* l2 cache */
818   16,                   /* prefetch streams */
819 };
820
821 /* Instruction costs on POWER7 processors.  */
822 static const
823 struct processor_costs power7_cost = {
824   COSTS_N_INSNS (2),    /* mulsi */
825   COSTS_N_INSNS (2),    /* mulsi_const */
826   COSTS_N_INSNS (2),    /* mulsi_const9 */
827   COSTS_N_INSNS (2),    /* muldi */
828   COSTS_N_INSNS (18),   /* divsi */
829   COSTS_N_INSNS (34),   /* divdi */
830   COSTS_N_INSNS (3),    /* fp */
831   COSTS_N_INSNS (3),    /* dmul */
832   COSTS_N_INSNS (13),   /* sdiv */
833   COSTS_N_INSNS (16),   /* ddiv */
834   128,                  /* cache line size */
835   32,                   /* l1 cache */
836   256,                  /* l2 cache */
837   12,                   /* prefetch streams */
838 };
839
840 /* Instruction costs on POWER A2 processors.  */
841 static const
842 struct processor_costs ppca2_cost = {
843   COSTS_N_INSNS (16),    /* mulsi */
844   COSTS_N_INSNS (16),    /* mulsi_const */
845   COSTS_N_INSNS (16),    /* mulsi_const9 */
846   COSTS_N_INSNS (16),   /* muldi */
847   COSTS_N_INSNS (22),   /* divsi */
848   COSTS_N_INSNS (28),   /* divdi */
849   COSTS_N_INSNS (3),    /* fp */
850   COSTS_N_INSNS (3),    /* dmul */
851   COSTS_N_INSNS (59),   /* sdiv */
852   COSTS_N_INSNS (72),   /* ddiv */
853   64,
854   16,                   /* l1 cache */
855   2048,                 /* l2 cache */
856   16,                   /* prefetch streams */
857 };
858
859 \f
860 /* Table that classifies rs6000 builtin functions (pure, const, etc.).  */
861 #undef RS6000_BUILTIN
862 #undef RS6000_BUILTIN_EQUATE
863 #define RS6000_BUILTIN(NAME, TYPE) TYPE,
864 #define RS6000_BUILTIN_EQUATE(NAME, VALUE)
865
866 static const enum rs6000_btc builtin_classify[(int)RS6000_BUILTIN_COUNT] =
867 {
868 #include "rs6000-builtin.def"
869 };
870
871 #undef RS6000_BUILTIN
872 #undef RS6000_BUILTIN_EQUATE
873
874 \f
875 static bool rs6000_function_ok_for_sibcall (tree, tree);
876 static const char *rs6000_invalid_within_doloop (const_rtx);
877 static bool rs6000_legitimate_address_p (enum machine_mode, rtx, bool);
878 static bool rs6000_debug_legitimate_address_p (enum machine_mode, rtx, bool);
879 static rtx rs6000_generate_compare (rtx, enum machine_mode);
880 static void rs6000_emit_stack_tie (void);
881 static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
882 static bool spe_func_has_64bit_regs_p (void);
883 static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
884                              int, HOST_WIDE_INT);
885 static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
886 static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int, int);
887 static unsigned rs6000_hash_constant (rtx);
888 static unsigned toc_hash_function (const void *);
889 static int toc_hash_eq (const void *, const void *);
890 static bool reg_offset_addressing_ok_p (enum machine_mode);
891 static bool virtual_stack_registers_memory_p (rtx);
892 static bool constant_pool_expr_p (rtx);
893 static bool legitimate_small_data_p (enum machine_mode, rtx);
894 static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
895 static struct machine_function * rs6000_init_machine_status (void);
896 static bool rs6000_assemble_integer (rtx, unsigned int, int);
897 static bool no_global_regs_above (int, bool);
898 #ifdef HAVE_GAS_HIDDEN
899 static void rs6000_assemble_visibility (tree, int);
900 #endif
901 static int rs6000_ra_ever_killed (void);
902 static bool rs6000_attribute_takes_identifier_p (const_tree);
903 static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
904 static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
905 static bool rs6000_ms_bitfield_layout_p (const_tree);
906 static tree rs6000_handle_struct_attribute (tree *, tree, tree, int, bool *);
907 static void rs6000_eliminate_indexed_memrefs (rtx operands[2]);
908 static const char *rs6000_mangle_type (const_tree);
909 static void rs6000_set_default_type_attributes (tree);
910 static rtx rs6000_savres_routine_sym (rs6000_stack_t *, bool, bool, bool);
911 static rtx rs6000_emit_stack_reset (rs6000_stack_t *, rtx, rtx, int, bool);
912 static rtx rs6000_make_savres_rtx (rs6000_stack_t *, rtx, int,
913                                    enum machine_mode, bool, bool, bool);
914 static bool rs6000_reg_live_or_pic_offset_p (int);
915 static tree rs6000_builtin_vectorized_function (tree, tree, tree);
916 static int rs6000_savres_strategy (rs6000_stack_t *, bool, int, int);
917 static void rs6000_restore_saved_cr (rtx, int);
918 static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
919 static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
920 static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
921                                     tree);
922 static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
923 static bool rs6000_return_in_memory (const_tree, const_tree);
924 static rtx rs6000_function_value (const_tree, const_tree, bool);
925 static void rs6000_file_start (void);
926 #if TARGET_ELF
927 static int rs6000_elf_reloc_rw_mask (void);
928 static void rs6000_elf_asm_out_constructor (rtx, int);
929 static void rs6000_elf_asm_out_destructor (rtx, int);
930 static void rs6000_elf_end_indicate_exec_stack (void) ATTRIBUTE_UNUSED;
931 static void rs6000_elf_asm_init_sections (void);
932 static section *rs6000_elf_select_rtx_section (enum machine_mode, rtx,
933                                                unsigned HOST_WIDE_INT);
934 static void rs6000_elf_encode_section_info (tree, rtx, int)
935      ATTRIBUTE_UNUSED;
936 #endif
937 static bool rs6000_use_blocks_for_constant_p (enum machine_mode, const_rtx);
938 static void rs6000_alloc_sdmode_stack_slot (void);
939 static void rs6000_instantiate_decls (void);
940 #if TARGET_XCOFF
941 static void rs6000_xcoff_asm_output_anchor (rtx);
942 static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
943 static void rs6000_xcoff_asm_init_sections (void);
944 static int rs6000_xcoff_reloc_rw_mask (void);
945 static void rs6000_xcoff_asm_named_section (const char *, unsigned int, tree);
946 static section *rs6000_xcoff_select_section (tree, int,
947                                              unsigned HOST_WIDE_INT);
948 static void rs6000_xcoff_unique_section (tree, int);
949 static section *rs6000_xcoff_select_rtx_section
950   (enum machine_mode, rtx, unsigned HOST_WIDE_INT);
951 static const char * rs6000_xcoff_strip_name_encoding (const char *);
952 static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
953 static void rs6000_xcoff_file_start (void);
954 static void rs6000_xcoff_file_end (void);
955 #endif
956 static int rs6000_variable_issue (FILE *, int, rtx, int);
957 static bool rs6000_rtx_costs (rtx, int, int, int *, bool);
958 static bool rs6000_debug_rtx_costs (rtx, int, int, int *, bool);
959 static int rs6000_debug_address_cost (rtx, bool);
960 static int rs6000_adjust_cost (rtx, rtx, rtx, int);
961 static int rs6000_debug_adjust_cost (rtx, rtx, rtx, int);
962 static void rs6000_sched_init (FILE *, int, int);
963 static bool is_microcoded_insn (rtx);
964 static bool is_nonpipeline_insn (rtx);
965 static bool is_cracked_insn (rtx);
966 static bool is_branch_slot_insn (rtx);
967 static bool is_load_insn (rtx);
968 static rtx get_store_dest (rtx pat);
969 static bool is_store_insn (rtx);
970 static bool set_to_load_agen (rtx,rtx);
971 static bool adjacent_mem_locations (rtx,rtx);
972 static int rs6000_adjust_priority (rtx, int);
973 static int rs6000_issue_rate (void);
974 static bool rs6000_is_costly_dependence (dep_t, int, int);
975 static rtx get_next_active_insn (rtx, rtx);
976 static bool insn_terminates_group_p (rtx , enum group_termination);
977 static bool insn_must_be_first_in_group (rtx);
978 static bool insn_must_be_last_in_group (rtx);
979 static bool is_costly_group (rtx *, rtx);
980 static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
981 static int redefine_groups (FILE *, int, rtx, rtx);
982 static int pad_groups (FILE *, int, rtx, rtx);
983 static void rs6000_sched_finish (FILE *, int);
984 static int rs6000_sched_reorder (FILE *, int, rtx *, int *, int);
985 static int rs6000_sched_reorder2 (FILE *, int, rtx *, int *, int);
986 static int rs6000_use_sched_lookahead (void);
987 static int rs6000_use_sched_lookahead_guard (rtx);
988 static void * rs6000_alloc_sched_context (void);
989 static void rs6000_init_sched_context (void *, bool);
990 static void rs6000_set_sched_context (void *);
991 static void rs6000_free_sched_context (void *);
992 static tree rs6000_builtin_reciprocal (unsigned int, bool, bool);
993 static tree rs6000_builtin_mask_for_load (void);
994 static tree rs6000_builtin_mul_widen_even (tree);
995 static tree rs6000_builtin_mul_widen_odd (tree);
996 static tree rs6000_builtin_conversion (unsigned int, tree, tree);
997 static tree rs6000_builtin_vec_perm (tree, tree *);
998 static bool rs6000_builtin_support_vector_misalignment (enum
999                                                         machine_mode,
1000                                                         const_tree,
1001                                                         int, bool);
1002
1003 static void def_builtin (int, const char *, tree, int);
1004 static bool rs6000_vector_alignment_reachable (const_tree, bool);
1005 static void rs6000_init_builtins (void);
1006 static tree rs6000_builtin_decl (unsigned, bool);
1007
1008 static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
1009 static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
1010 static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
1011 static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
1012 static void altivec_init_builtins (void);
1013 static unsigned builtin_hash_function (const void *);
1014 static int builtin_hash_eq (const void *, const void *);
1015 static tree builtin_function_type (enum machine_mode, enum machine_mode,
1016                                    enum machine_mode, enum machine_mode,
1017                                    enum rs6000_builtins, const char *name);
1018 static void rs6000_common_init_builtins (void);
1019 static void rs6000_init_libfuncs (void);
1020
1021 static void paired_init_builtins (void);
1022 static rtx paired_expand_builtin (tree, rtx, bool *);
1023 static rtx paired_expand_lv_builtin (enum insn_code, tree, rtx);
1024 static rtx paired_expand_stv_builtin (enum insn_code, tree);
1025 static rtx paired_expand_predicate_builtin (enum insn_code, tree, rtx);
1026
1027 static void enable_mask_for_builtins (struct builtin_description *, int,
1028                                       enum rs6000_builtins,
1029                                       enum rs6000_builtins);
1030 static void spe_init_builtins (void);
1031 static rtx spe_expand_builtin (tree, rtx, bool *);
1032 static rtx spe_expand_stv_builtin (enum insn_code, tree);
1033 static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
1034 static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
1035 static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
1036 static rs6000_stack_t *rs6000_stack_info (void);
1037 static void debug_stack_info (rs6000_stack_t *);
1038
1039 static rtx altivec_expand_builtin (tree, rtx, bool *);
1040 static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
1041 static rtx altivec_expand_st_builtin (tree, rtx, bool *);
1042 static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
1043 static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
1044 static rtx altivec_expand_predicate_builtin (enum insn_code, tree, rtx);
1045 static rtx altivec_expand_stv_builtin (enum insn_code, tree);
1046 static rtx altivec_expand_vec_init_builtin (tree, tree, rtx);
1047 static rtx altivec_expand_vec_set_builtin (tree);
1048 static rtx altivec_expand_vec_ext_builtin (tree, rtx);
1049 static int get_element_number (tree, tree);
1050 static bool rs6000_handle_option (size_t, const char *, int);
1051 static void rs6000_parse_tls_size_option (void);
1052 static void rs6000_parse_yes_no_option (const char *, const char *, int *);
1053 static int first_altivec_reg_to_save (void);
1054 static unsigned int compute_vrsave_mask (void);
1055 static void compute_save_world_info (rs6000_stack_t *info_ptr);
1056 static void is_altivec_return_reg (rtx, void *);
1057 static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
1058 int easy_vector_constant (rtx, enum machine_mode);
1059 static rtx rs6000_dwarf_register_span (rtx);
1060 static void rs6000_init_dwarf_reg_sizes_extra (tree);
1061 static rtx rs6000_legitimize_address (rtx, rtx, enum machine_mode);
1062 static rtx rs6000_debug_legitimize_address (rtx, rtx, enum machine_mode);
1063 static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
1064 static void rs6000_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
1065 static rtx rs6000_delegitimize_address (rtx);
1066 static rtx rs6000_tls_get_addr (void);
1067 static rtx rs6000_got_sym (void);
1068 static int rs6000_tls_symbol_ref_1 (rtx *, void *);
1069 static const char *rs6000_get_some_local_dynamic_name (void);
1070 static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
1071 static rtx rs6000_complex_function_value (enum machine_mode);
1072 static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
1073                                     enum machine_mode, tree);
1074 static void rs6000_darwin64_record_arg_advance_flush (CUMULATIVE_ARGS *,
1075                                                       HOST_WIDE_INT);
1076 static void rs6000_darwin64_record_arg_advance_recurse (CUMULATIVE_ARGS *,
1077                                                         tree, HOST_WIDE_INT);
1078 static void rs6000_darwin64_record_arg_flush (CUMULATIVE_ARGS *,
1079                                               HOST_WIDE_INT,
1080                                               rtx[], int *);
1081 static void rs6000_darwin64_record_arg_recurse (CUMULATIVE_ARGS *,
1082                                                 const_tree, HOST_WIDE_INT,
1083                                                 rtx[], int *);
1084 static rtx rs6000_darwin64_record_arg (CUMULATIVE_ARGS *, const_tree, int, bool);
1085 static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int);
1086 static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
1087 static void setup_incoming_varargs (CUMULATIVE_ARGS *,
1088                                     enum machine_mode, tree,
1089                                     int *, int);
1090 static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
1091                                       const_tree, bool);
1092 static int rs6000_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
1093                                      tree, bool);
1094 static const char *invalid_arg_for_unprototyped_fn (const_tree, const_tree, const_tree);
1095 #if TARGET_MACHO
1096 static void macho_branch_islands (void);
1097 static int no_previous_def (tree function_name);
1098 static tree get_prev_label (tree function_name);
1099 static void rs6000_darwin_file_start (void);
1100 #endif
1101
1102 static tree rs6000_build_builtin_va_list (void);
1103 static void rs6000_va_start (tree, rtx);
1104 static tree rs6000_gimplify_va_arg (tree, tree, gimple_seq *, gimple_seq *);
1105 static bool rs6000_must_pass_in_stack (enum machine_mode, const_tree);
1106 static bool rs6000_scalar_mode_supported_p (enum machine_mode);
1107 static bool rs6000_vector_mode_supported_p (enum machine_mode);
1108 static rtx rs6000_emit_vector_compare_inner (enum rtx_code, rtx, rtx);
1109 static rtx rs6000_emit_vector_compare (enum rtx_code, rtx, rtx,
1110                                        enum machine_mode);
1111 static tree rs6000_stack_protect_fail (void);
1112
1113 static rtx rs6000_legitimize_reload_address (rtx, enum machine_mode, int, int,
1114                                              int, int *);
1115
1116 static rtx rs6000_debug_legitimize_reload_address (rtx, enum machine_mode, int,
1117                                                    int, int, int *);
1118
1119 rtx (*rs6000_legitimize_reload_address_ptr) (rtx, enum machine_mode, int, int,
1120                                              int, int *)
1121   = rs6000_legitimize_reload_address;
1122
1123 static bool rs6000_mode_dependent_address (const_rtx);
1124 static bool rs6000_debug_mode_dependent_address (const_rtx);
1125 bool (*rs6000_mode_dependent_address_ptr) (const_rtx)
1126   = rs6000_mode_dependent_address;
1127
1128 static enum reg_class rs6000_secondary_reload_class (enum reg_class,
1129                                                      enum machine_mode, rtx);
1130 static enum reg_class rs6000_debug_secondary_reload_class (enum reg_class,
1131                                                            enum machine_mode,
1132                                                            rtx);
1133 enum reg_class (*rs6000_secondary_reload_class_ptr) (enum reg_class,
1134                                                      enum machine_mode, rtx)
1135   = rs6000_secondary_reload_class;
1136
1137 static enum reg_class rs6000_preferred_reload_class (rtx, enum reg_class);
1138 static enum reg_class rs6000_debug_preferred_reload_class (rtx,
1139                                                            enum reg_class);
1140 enum reg_class (*rs6000_preferred_reload_class_ptr) (rtx, enum reg_class)
1141   = rs6000_preferred_reload_class;
1142
1143 static bool rs6000_secondary_memory_needed (enum reg_class, enum reg_class,
1144                                             enum machine_mode);
1145
1146 static bool rs6000_debug_secondary_memory_needed (enum reg_class,
1147                                                   enum reg_class,
1148                                                   enum machine_mode);
1149
1150 bool (*rs6000_secondary_memory_needed_ptr) (enum reg_class, enum reg_class,
1151                                             enum machine_mode)
1152   = rs6000_secondary_memory_needed;
1153
1154 static bool rs6000_cannot_change_mode_class (enum machine_mode,
1155                                              enum machine_mode,
1156                                              enum reg_class);
1157 static bool rs6000_debug_cannot_change_mode_class (enum machine_mode,
1158                                                    enum machine_mode,
1159                                                    enum reg_class);
1160
1161 bool (*rs6000_cannot_change_mode_class_ptr) (enum machine_mode,
1162                                              enum machine_mode,
1163                                              enum reg_class)
1164   = rs6000_cannot_change_mode_class;
1165
1166 static enum reg_class rs6000_secondary_reload (bool, rtx, enum reg_class,
1167                                                enum machine_mode,
1168                                                struct secondary_reload_info *);
1169
1170 static const enum reg_class *rs6000_ira_cover_classes (void);
1171
1172 const int INSN_NOT_AVAILABLE = -1;
1173 static enum machine_mode rs6000_eh_return_filter_mode (void);
1174 static bool rs6000_can_eliminate (const int, const int);
1175 static void rs6000_trampoline_init (rtx, tree, rtx);
1176
1177 /* Hash table stuff for keeping track of TOC entries.  */
1178
1179 struct GTY(()) toc_hash_struct
1180 {
1181   /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
1182      ASM_OUTPUT_SPECIAL_POOL_ENTRY_P.  */
1183   rtx key;
1184   enum machine_mode key_mode;
1185   int labelno;
1186 };
1187
1188 static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
1189
1190 /* Hash table to keep track of the argument types for builtin functions.  */
1191
1192 struct GTY(()) builtin_hash_struct
1193 {
1194   tree type;
1195   enum machine_mode mode[4];    /* return value + 3 arguments.  */
1196   unsigned char uns_p[4];       /* and whether the types are unsigned.  */
1197 };
1198
1199 static GTY ((param_is (struct builtin_hash_struct))) htab_t builtin_hash_table;
1200 \f
1201 /* Default register names.  */
1202 char rs6000_reg_names[][8] =
1203 {
1204       "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
1205       "8",  "9", "10", "11", "12", "13", "14", "15",
1206      "16", "17", "18", "19", "20", "21", "22", "23",
1207      "24", "25", "26", "27", "28", "29", "30", "31",
1208       "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
1209       "8",  "9", "10", "11", "12", "13", "14", "15",
1210      "16", "17", "18", "19", "20", "21", "22", "23",
1211      "24", "25", "26", "27", "28", "29", "30", "31",
1212      "mq", "lr", "ctr","ap",
1213       "0",  "1",  "2",  "3",  "4",  "5",  "6",  "7",
1214       "xer",
1215       /* AltiVec registers.  */
1216       "0",  "1",  "2",  "3",  "4",  "5",  "6", "7",
1217       "8",  "9",  "10", "11", "12", "13", "14", "15",
1218       "16", "17", "18", "19", "20", "21", "22", "23",
1219       "24", "25", "26", "27", "28", "29", "30", "31",
1220       "vrsave", "vscr",
1221       /* SPE registers.  */
1222       "spe_acc", "spefscr",
1223       /* Soft frame pointer.  */
1224       "sfp"
1225 };
1226
1227 #ifdef TARGET_REGNAMES
1228 static const char alt_reg_names[][8] =
1229 {
1230    "%r0",   "%r1",  "%r2",  "%r3",  "%r4",  "%r5",  "%r6",  "%r7",
1231    "%r8",   "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
1232   "%r16",  "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
1233   "%r24",  "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
1234    "%f0",   "%f1",  "%f2",  "%f3",  "%f4",  "%f5",  "%f6",  "%f7",
1235    "%f8",   "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
1236   "%f16",  "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
1237   "%f24",  "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
1238     "mq",    "lr",  "ctr",   "ap",
1239   "%cr0",  "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
1240    "xer",
1241   /* AltiVec registers.  */
1242    "%v0",  "%v1",  "%v2",  "%v3",  "%v4",  "%v5",  "%v6", "%v7",
1243    "%v8",  "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
1244   "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
1245   "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
1246   "vrsave", "vscr",
1247   /* SPE registers.  */
1248   "spe_acc", "spefscr",
1249   /* Soft frame pointer.  */
1250   "sfp"
1251 };
1252 #endif
1253
1254 /* Table of valid machine attributes.  */
1255
1256 static const struct attribute_spec rs6000_attribute_table[] =
1257 {
1258   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
1259   { "altivec",   1, 1, false, true,  false, rs6000_handle_altivec_attribute },
1260   { "longcall",  0, 0, false, true,  true,  rs6000_handle_longcall_attribute },
1261   { "shortcall", 0, 0, false, true,  true,  rs6000_handle_longcall_attribute },
1262   { "ms_struct", 0, 0, false, false, false, rs6000_handle_struct_attribute },
1263   { "gcc_struct", 0, 0, false, false, false, rs6000_handle_struct_attribute },
1264 #ifdef SUBTARGET_ATTRIBUTE_TABLE
1265   SUBTARGET_ATTRIBUTE_TABLE,
1266 #endif
1267   { NULL,        0, 0, false, false, false, NULL }
1268 };
1269 \f
1270 #ifndef MASK_STRICT_ALIGN
1271 #define MASK_STRICT_ALIGN 0
1272 #endif
1273 #ifndef TARGET_PROFILE_KERNEL
1274 #define TARGET_PROFILE_KERNEL 0
1275 #endif
1276
1277 /* The VRSAVE bitmask puts bit %v0 as the most significant bit.  */
1278 #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
1279 \f
1280 /* Initialize the GCC target structure.  */
1281 #undef TARGET_ATTRIBUTE_TABLE
1282 #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
1283 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
1284 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
1285 #undef TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P
1286 #define TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P rs6000_attribute_takes_identifier_p
1287
1288 #undef TARGET_ASM_ALIGNED_DI_OP
1289 #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
1290
1291 /* Default unaligned ops are only provided for ELF.  Find the ops needed
1292    for non-ELF systems.  */
1293 #ifndef OBJECT_FORMAT_ELF
1294 #if TARGET_XCOFF
1295 /* For XCOFF.  rs6000_assemble_integer will handle unaligned DIs on
1296    64-bit targets.  */
1297 #undef TARGET_ASM_UNALIGNED_HI_OP
1298 #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
1299 #undef TARGET_ASM_UNALIGNED_SI_OP
1300 #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
1301 #undef TARGET_ASM_UNALIGNED_DI_OP
1302 #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
1303 #else
1304 /* For Darwin.  */
1305 #undef TARGET_ASM_UNALIGNED_HI_OP
1306 #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
1307 #undef TARGET_ASM_UNALIGNED_SI_OP
1308 #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
1309 #undef TARGET_ASM_UNALIGNED_DI_OP
1310 #define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
1311 #undef TARGET_ASM_ALIGNED_DI_OP
1312 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
1313 #endif
1314 #endif
1315
1316 /* This hook deals with fixups for relocatable code and DI-mode objects
1317    in 64-bit code.  */
1318 #undef TARGET_ASM_INTEGER
1319 #define TARGET_ASM_INTEGER rs6000_assemble_integer
1320
1321 #ifdef HAVE_GAS_HIDDEN
1322 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
1323 #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
1324 #endif
1325
1326 #undef TARGET_HAVE_TLS
1327 #define TARGET_HAVE_TLS HAVE_AS_TLS
1328
1329 #undef TARGET_CANNOT_FORCE_CONST_MEM
1330 #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
1331
1332 #undef TARGET_DELEGITIMIZE_ADDRESS
1333 #define TARGET_DELEGITIMIZE_ADDRESS rs6000_delegitimize_address
1334
1335 #undef TARGET_ASM_FUNCTION_PROLOGUE
1336 #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
1337 #undef TARGET_ASM_FUNCTION_EPILOGUE
1338 #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
1339
1340 #undef TARGET_LEGITIMIZE_ADDRESS
1341 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
1342
1343 #undef  TARGET_SCHED_VARIABLE_ISSUE
1344 #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
1345
1346 #undef TARGET_SCHED_ISSUE_RATE
1347 #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
1348 #undef TARGET_SCHED_ADJUST_COST
1349 #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
1350 #undef TARGET_SCHED_ADJUST_PRIORITY
1351 #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
1352 #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
1353 #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
1354 #undef TARGET_SCHED_INIT
1355 #define TARGET_SCHED_INIT rs6000_sched_init
1356 #undef TARGET_SCHED_FINISH
1357 #define TARGET_SCHED_FINISH rs6000_sched_finish
1358 #undef TARGET_SCHED_REORDER
1359 #define TARGET_SCHED_REORDER rs6000_sched_reorder
1360 #undef TARGET_SCHED_REORDER2
1361 #define TARGET_SCHED_REORDER2 rs6000_sched_reorder2
1362
1363 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
1364 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
1365
1366 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
1367 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD rs6000_use_sched_lookahead_guard
1368
1369 #undef TARGET_SCHED_ALLOC_SCHED_CONTEXT
1370 #define TARGET_SCHED_ALLOC_SCHED_CONTEXT rs6000_alloc_sched_context
1371 #undef TARGET_SCHED_INIT_SCHED_CONTEXT
1372 #define TARGET_SCHED_INIT_SCHED_CONTEXT rs6000_init_sched_context
1373 #undef TARGET_SCHED_SET_SCHED_CONTEXT
1374 #define TARGET_SCHED_SET_SCHED_CONTEXT rs6000_set_sched_context
1375 #undef TARGET_SCHED_FREE_SCHED_CONTEXT
1376 #define TARGET_SCHED_FREE_SCHED_CONTEXT rs6000_free_sched_context
1377
1378 #undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
1379 #define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
1380 #undef TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_EVEN
1381 #define TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_EVEN rs6000_builtin_mul_widen_even
1382 #undef TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_ODD
1383 #define TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_ODD rs6000_builtin_mul_widen_odd
1384 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
1385 #define TARGET_VECTORIZE_BUILTIN_CONVERSION rs6000_builtin_conversion
1386 #undef TARGET_VECTORIZE_BUILTIN_VEC_PERM
1387 #define TARGET_VECTORIZE_BUILTIN_VEC_PERM rs6000_builtin_vec_perm
1388 #undef TARGET_SUPPORT_VECTOR_MISALIGNMENT
1389 #define TARGET_SUPPORT_VECTOR_MISALIGNMENT              \
1390   rs6000_builtin_support_vector_misalignment
1391 #undef TARGET_VECTOR_ALIGNMENT_REACHABLE
1392 #define TARGET_VECTOR_ALIGNMENT_REACHABLE rs6000_vector_alignment_reachable
1393
1394 #undef TARGET_INIT_BUILTINS
1395 #define TARGET_INIT_BUILTINS rs6000_init_builtins
1396 #undef TARGET_BUILTIN_DECL
1397 #define TARGET_BUILTIN_DECL rs6000_builtin_decl
1398
1399 #undef TARGET_EXPAND_BUILTIN
1400 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
1401
1402 #undef TARGET_MANGLE_TYPE
1403 #define TARGET_MANGLE_TYPE rs6000_mangle_type
1404
1405 #undef TARGET_INIT_LIBFUNCS
1406 #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
1407
1408 #if TARGET_MACHO
1409 #undef TARGET_BINDS_LOCAL_P
1410 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
1411 #endif
1412
1413 #undef TARGET_MS_BITFIELD_LAYOUT_P
1414 #define TARGET_MS_BITFIELD_LAYOUT_P rs6000_ms_bitfield_layout_p
1415
1416 #undef TARGET_ASM_OUTPUT_MI_THUNK
1417 #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
1418
1419 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
1420 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
1421
1422 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
1423 #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
1424
1425 #undef TARGET_INVALID_WITHIN_DOLOOP
1426 #define TARGET_INVALID_WITHIN_DOLOOP rs6000_invalid_within_doloop
1427
1428 #undef TARGET_RTX_COSTS
1429 #define TARGET_RTX_COSTS rs6000_rtx_costs
1430 #undef TARGET_ADDRESS_COST
1431 #define TARGET_ADDRESS_COST hook_int_rtx_bool_0
1432
1433 #undef TARGET_DWARF_REGISTER_SPAN
1434 #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
1435
1436 #undef TARGET_INIT_DWARF_REG_SIZES_EXTRA
1437 #define TARGET_INIT_DWARF_REG_SIZES_EXTRA rs6000_init_dwarf_reg_sizes_extra
1438
1439 /* On rs6000, function arguments are promoted, as are function return
1440    values.  */
1441 #undef TARGET_PROMOTE_FUNCTION_MODE
1442 #define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote
1443
1444 #undef TARGET_RETURN_IN_MEMORY
1445 #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
1446
1447 #undef TARGET_SETUP_INCOMING_VARARGS
1448 #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
1449
1450 /* Always strict argument naming on rs6000.  */
1451 #undef TARGET_STRICT_ARGUMENT_NAMING
1452 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
1453 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
1454 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
1455 #undef TARGET_SPLIT_COMPLEX_ARG
1456 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_const_tree_true
1457 #undef TARGET_MUST_PASS_IN_STACK
1458 #define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
1459 #undef TARGET_PASS_BY_REFERENCE
1460 #define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
1461 #undef TARGET_ARG_PARTIAL_BYTES
1462 #define TARGET_ARG_PARTIAL_BYTES rs6000_arg_partial_bytes
1463
1464 #undef TARGET_BUILD_BUILTIN_VA_LIST
1465 #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
1466
1467 #undef TARGET_EXPAND_BUILTIN_VA_START
1468 #define TARGET_EXPAND_BUILTIN_VA_START rs6000_va_start
1469
1470 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
1471 #define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
1472
1473 #undef TARGET_EH_RETURN_FILTER_MODE
1474 #define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
1475
1476 #undef TARGET_SCALAR_MODE_SUPPORTED_P
1477 #define TARGET_SCALAR_MODE_SUPPORTED_P rs6000_scalar_mode_supported_p
1478
1479 #undef TARGET_VECTOR_MODE_SUPPORTED_P
1480 #define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
1481
1482 #undef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN
1483 #define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN invalid_arg_for_unprototyped_fn
1484
1485 #undef TARGET_HANDLE_OPTION
1486 #define TARGET_HANDLE_OPTION rs6000_handle_option
1487
1488 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
1489 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
1490   rs6000_builtin_vectorized_function
1491
1492 #undef TARGET_DEFAULT_TARGET_FLAGS
1493 #define TARGET_DEFAULT_TARGET_FLAGS \
1494   (TARGET_DEFAULT)
1495
1496 #undef TARGET_STACK_PROTECT_FAIL
1497 #define TARGET_STACK_PROTECT_FAIL rs6000_stack_protect_fail
1498
1499 /* MPC604EUM 3.5.2 Weak Consistency between Multiple Processors
1500    The PowerPC architecture requires only weak consistency among
1501    processors--that is, memory accesses between processors need not be
1502    sequentially consistent and memory accesses among processors can occur
1503    in any order. The ability to order memory accesses weakly provides
1504    opportunities for more efficient use of the system bus. Unless a
1505    dependency exists, the 604e allows read operations to precede store
1506    operations.  */
1507 #undef TARGET_RELAXED_ORDERING
1508 #define TARGET_RELAXED_ORDERING true
1509
1510 #ifdef HAVE_AS_TLS
1511 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
1512 #define TARGET_ASM_OUTPUT_DWARF_DTPREL rs6000_output_dwarf_dtprel
1513 #endif
1514
1515 /* Use a 32-bit anchor range.  This leads to sequences like:
1516
1517         addis   tmp,anchor,high
1518         add     dest,tmp,low
1519
1520    where tmp itself acts as an anchor, and can be shared between
1521    accesses to the same 64k page.  */
1522 #undef TARGET_MIN_ANCHOR_OFFSET
1523 #define TARGET_MIN_ANCHOR_OFFSET -0x7fffffff - 1
1524 #undef TARGET_MAX_ANCHOR_OFFSET
1525 #define TARGET_MAX_ANCHOR_OFFSET 0x7fffffff
1526 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
1527 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P rs6000_use_blocks_for_constant_p
1528
1529 #undef TARGET_BUILTIN_RECIPROCAL
1530 #define TARGET_BUILTIN_RECIPROCAL rs6000_builtin_reciprocal
1531
1532 #undef TARGET_EXPAND_TO_RTL_HOOK
1533 #define TARGET_EXPAND_TO_RTL_HOOK rs6000_alloc_sdmode_stack_slot
1534
1535 #undef TARGET_INSTANTIATE_DECLS
1536 #define TARGET_INSTANTIATE_DECLS rs6000_instantiate_decls
1537
1538 #undef TARGET_SECONDARY_RELOAD
1539 #define TARGET_SECONDARY_RELOAD rs6000_secondary_reload
1540
1541 #undef TARGET_IRA_COVER_CLASSES
1542 #define TARGET_IRA_COVER_CLASSES rs6000_ira_cover_classes
1543
1544 #undef TARGET_LEGITIMATE_ADDRESS_P
1545 #define TARGET_LEGITIMATE_ADDRESS_P rs6000_legitimate_address_p
1546
1547 #undef TARGET_CAN_ELIMINATE
1548 #define TARGET_CAN_ELIMINATE rs6000_can_eliminate
1549
1550 #undef TARGET_TRAMPOLINE_INIT
1551 #define TARGET_TRAMPOLINE_INIT rs6000_trampoline_init
1552
1553 #undef TARGET_FUNCTION_VALUE
1554 #define TARGET_FUNCTION_VALUE rs6000_function_value
1555
1556 struct gcc_target targetm = TARGET_INITIALIZER;
1557 \f
1558 /* Return number of consecutive hard regs needed starting at reg REGNO
1559    to hold something of mode MODE.
1560    This is ordinarily the length in words of a value of mode MODE
1561    but can be less for certain modes in special long registers.
1562
1563    For the SPE, GPRs are 64 bits but only 32 bits are visible in
1564    scalar instructions.  The upper 32 bits are only available to the
1565    SIMD instructions.
1566
1567    POWER and PowerPC GPRs hold 32 bits worth;
1568    PowerPC64 GPRs and FPRs point register holds 64 bits worth.  */
1569
1570 static int
1571 rs6000_hard_regno_nregs_internal (int regno, enum machine_mode mode)
1572 {
1573   unsigned HOST_WIDE_INT reg_size;
1574
1575   if (FP_REGNO_P (regno))
1576     reg_size = (VECTOR_MEM_VSX_P (mode)
1577                 ? UNITS_PER_VSX_WORD
1578                 : UNITS_PER_FP_WORD);
1579
1580   else if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1581     reg_size = UNITS_PER_SPE_WORD;
1582
1583   else if (ALTIVEC_REGNO_P (regno))
1584     reg_size = UNITS_PER_ALTIVEC_WORD;
1585
1586   /* The value returned for SCmode in the E500 double case is 2 for
1587      ABI compatibility; storing an SCmode value in a single register
1588      would require function_arg and rs6000_spe_function_arg to handle
1589      SCmode so as to pass the value correctly in a pair of
1590      registers.  */
1591   else if (TARGET_E500_DOUBLE && FLOAT_MODE_P (mode) && mode != SCmode
1592            && !DECIMAL_FLOAT_MODE_P (mode))
1593     reg_size = UNITS_PER_FP_WORD;
1594
1595   else
1596     reg_size = UNITS_PER_WORD;
1597
1598   return (GET_MODE_SIZE (mode) + reg_size - 1) / reg_size;
1599 }
1600
1601 /* Value is 1 if hard register REGNO can hold a value of machine-mode
1602    MODE.  */
1603 static int
1604 rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
1605 {
1606   int last_regno = regno + rs6000_hard_regno_nregs[mode][regno] - 1;
1607
1608   /* VSX registers that overlap the FPR registers are larger than for non-VSX
1609      implementations.  Don't allow an item to be split between a FP register
1610      and an Altivec register.  */
1611   if (VECTOR_MEM_VSX_P (mode))
1612     {
1613       if (FP_REGNO_P (regno))
1614         return FP_REGNO_P (last_regno);
1615
1616       if (ALTIVEC_REGNO_P (regno))
1617         return ALTIVEC_REGNO_P (last_regno);
1618     }
1619
1620   /* The GPRs can hold any mode, but values bigger than one register
1621      cannot go past R31.  */
1622   if (INT_REGNO_P (regno))
1623     return INT_REGNO_P (last_regno);
1624
1625   /* The float registers (except for VSX vector modes) can only hold floating
1626      modes and DImode.  This excludes the 32-bit decimal float mode for
1627      now.  */
1628   if (FP_REGNO_P (regno))
1629     {
1630       if (SCALAR_FLOAT_MODE_P (mode)
1631           && (mode != TDmode || (regno % 2) == 0)
1632           && FP_REGNO_P (last_regno))
1633         return 1;
1634
1635       if (GET_MODE_CLASS (mode) == MODE_INT
1636           && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD)
1637         return 1;
1638
1639       if (PAIRED_SIMD_REGNO_P (regno) && TARGET_PAIRED_FLOAT
1640           && PAIRED_VECTOR_MODE (mode))
1641         return 1;
1642
1643       return 0;
1644     }
1645
1646   /* The CR register can only hold CC modes.  */
1647   if (CR_REGNO_P (regno))
1648     return GET_MODE_CLASS (mode) == MODE_CC;
1649
1650   if (XER_REGNO_P (regno))
1651     return mode == PSImode;
1652
1653   /* AltiVec only in AldyVec registers.  */
1654   if (ALTIVEC_REGNO_P (regno))
1655     return VECTOR_MEM_ALTIVEC_OR_VSX_P (mode);
1656
1657   /* ...but GPRs can hold SIMD data on the SPE in one register.  */
1658   if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1659     return 1;
1660
1661   /* We cannot put TImode anywhere except general register and it must be able
1662      to fit within the register set.  In the future, allow TImode in the
1663      Altivec or VSX registers.  */
1664
1665   return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1666 }
1667
1668 /* Print interesting facts about registers.  */
1669 static void
1670 rs6000_debug_reg_print (int first_regno, int last_regno, const char *reg_name)
1671 {
1672   int r, m;
1673
1674   for (r = first_regno; r <= last_regno; ++r)
1675     {
1676       const char *comma = "";
1677       int len;
1678
1679       if (first_regno == last_regno)
1680         fprintf (stderr, "%s:\t", reg_name);
1681       else
1682         fprintf (stderr, "%s%d:\t", reg_name, r - first_regno);
1683
1684       len = 8;
1685       for (m = 0; m < NUM_MACHINE_MODES; ++m)
1686         if (rs6000_hard_regno_mode_ok_p[m][r] && rs6000_hard_regno_nregs[m][r])
1687           {
1688             if (len > 70)
1689               {
1690                 fprintf (stderr, ",\n\t");
1691                 len = 8;
1692                 comma = "";
1693               }
1694
1695             if (rs6000_hard_regno_nregs[m][r] > 1)
1696               len += fprintf (stderr, "%s%s/%d", comma, GET_MODE_NAME (m),
1697                              rs6000_hard_regno_nregs[m][r]);
1698             else
1699               len += fprintf (stderr, "%s%s", comma, GET_MODE_NAME (m));
1700
1701             comma = ", ";
1702           }
1703
1704       if (call_used_regs[r])
1705         {
1706           if (len > 70)
1707             {
1708               fprintf (stderr, ",\n\t");
1709               len = 8;
1710               comma = "";
1711             }
1712
1713           len += fprintf (stderr, "%s%s", comma, "call-used");
1714           comma = ", ";
1715         }
1716
1717       if (fixed_regs[r])
1718         {
1719           if (len > 70)
1720             {
1721               fprintf (stderr, ",\n\t");
1722               len = 8;
1723               comma = "";
1724             }
1725
1726           len += fprintf (stderr, "%s%s", comma, "fixed");
1727           comma = ", ";
1728         }
1729
1730       if (len > 70)
1731         {
1732           fprintf (stderr, ",\n\t");
1733           comma = "";
1734         }
1735
1736       fprintf (stderr, "%sregno = %d\n", comma, r);
1737     }
1738 }
1739
1740 /* Print various interesting information with -mdebug=reg.  */
1741 static void
1742 rs6000_debug_reg_global (void)
1743 {
1744   const char *nl = (const char *)0;
1745   int m;
1746   char costly_num[20];
1747   char nop_num[20];
1748   const char *costly_str;
1749   const char *nop_str;
1750
1751   /* Map enum rs6000_vector to string.  */
1752   static const char *rs6000_debug_vector_unit[] = {
1753     "none",
1754     "altivec",
1755     "vsx",
1756     "paired",
1757     "spe",
1758     "other"
1759   };
1760
1761   fprintf (stderr, "Register information: (last virtual reg = %d)\n",
1762            LAST_VIRTUAL_REGISTER);
1763   rs6000_debug_reg_print (0, 31, "gr");
1764   rs6000_debug_reg_print (32, 63, "fp");
1765   rs6000_debug_reg_print (FIRST_ALTIVEC_REGNO,
1766                           LAST_ALTIVEC_REGNO,
1767                           "vs");
1768   rs6000_debug_reg_print (LR_REGNO, LR_REGNO, "lr");
1769   rs6000_debug_reg_print (CTR_REGNO, CTR_REGNO, "ctr");
1770   rs6000_debug_reg_print (CR0_REGNO, CR7_REGNO, "cr");
1771   rs6000_debug_reg_print (MQ_REGNO, MQ_REGNO, "mq");
1772   rs6000_debug_reg_print (XER_REGNO, XER_REGNO, "xer");
1773   rs6000_debug_reg_print (VRSAVE_REGNO, VRSAVE_REGNO, "vrsave");
1774   rs6000_debug_reg_print (VSCR_REGNO, VSCR_REGNO, "vscr");
1775   rs6000_debug_reg_print (SPE_ACC_REGNO, SPE_ACC_REGNO, "spe_a");
1776   rs6000_debug_reg_print (SPEFSCR_REGNO, SPEFSCR_REGNO, "spe_f");
1777
1778   fprintf (stderr,
1779            "\n"
1780            "d  reg_class = %s\n"
1781            "f  reg_class = %s\n"
1782            "v  reg_class = %s\n"
1783            "wa reg_class = %s\n"
1784            "wd reg_class = %s\n"
1785            "wf reg_class = %s\n"
1786            "ws reg_class = %s\n\n",
1787            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_d]],
1788            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_f]],
1789            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_v]],
1790            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wa]],
1791            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wd]],
1792            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wf]],
1793            reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_ws]]);
1794
1795   for (m = 0; m < NUM_MACHINE_MODES; ++m)
1796     if (rs6000_vector_unit[m] || rs6000_vector_mem[m])
1797       {
1798         nl = "\n";
1799         fprintf (stderr, "Vector mode: %-5s arithmetic: %-8s move: %-8s\n",
1800                  GET_MODE_NAME (m),
1801                  rs6000_debug_vector_unit[ rs6000_vector_unit[m] ],
1802                  rs6000_debug_vector_unit[ rs6000_vector_mem[m] ]);
1803       }
1804
1805   if (nl)
1806     fputs (nl, stderr);
1807
1808   switch (rs6000_sched_costly_dep)
1809     {
1810     case max_dep_latency:
1811       costly_str = "max_dep_latency";
1812       break;
1813
1814     case no_dep_costly:
1815       costly_str = "no_dep_costly";
1816       break;
1817
1818     case all_deps_costly:
1819       costly_str = "all_deps_costly";
1820       break;
1821
1822     case true_store_to_load_dep_costly:
1823       costly_str = "true_store_to_load_dep_costly";
1824       break;
1825
1826     case store_to_load_dep_costly:
1827       costly_str = "store_to_load_dep_costly";
1828       break;
1829
1830     default:
1831       costly_str = costly_num;
1832       sprintf (costly_num, "%d", (int)rs6000_sched_costly_dep);
1833       break;
1834     }
1835
1836   switch (rs6000_sched_insert_nops)
1837     {
1838     case sched_finish_regroup_exact:
1839       nop_str = "sched_finish_regroup_exact";
1840       break;
1841
1842     case sched_finish_pad_groups:
1843       nop_str = "sched_finish_pad_groups";
1844       break;
1845
1846     case sched_finish_none:
1847       nop_str = "sched_finish_none";
1848       break;
1849
1850     default:
1851       nop_str = nop_num;
1852       sprintf (nop_num, "%d", (int)rs6000_sched_insert_nops);
1853       break;
1854     }
1855
1856   fprintf (stderr,
1857            "always_hint                     = %s\n"
1858            "align_branch_targets            = %s\n"
1859            "sched_restricted_insns_priority = %d\n"
1860            "sched_costly_dep                = %s\n"
1861            "sched_insert_nops               = %s\n\n",
1862            rs6000_always_hint ? "true" : "false",
1863            rs6000_align_branch_targets ? "true" : "false",
1864            (int)rs6000_sched_restricted_insns_priority,
1865            costly_str, nop_str);
1866 }
1867
1868 /* Initialize the various global tables that are based on register size.  */
1869 static void
1870 rs6000_init_hard_regno_mode_ok (void)
1871 {
1872   int r, m, c;
1873   int align64;
1874   int align32;
1875
1876   /* Precalculate REGNO_REG_CLASS.  */
1877   rs6000_regno_regclass[0] = GENERAL_REGS;
1878   for (r = 1; r < 32; ++r)
1879     rs6000_regno_regclass[r] = BASE_REGS;
1880
1881   for (r = 32; r < 64; ++r)
1882     rs6000_regno_regclass[r] = FLOAT_REGS;
1883
1884   for (r = 64; r < FIRST_PSEUDO_REGISTER; ++r)
1885     rs6000_regno_regclass[r] = NO_REGS;
1886
1887   for (r = FIRST_ALTIVEC_REGNO; r <= LAST_ALTIVEC_REGNO; ++r)
1888     rs6000_regno_regclass[r] = ALTIVEC_REGS;
1889
1890   rs6000_regno_regclass[CR0_REGNO] = CR0_REGS;
1891   for (r = CR1_REGNO; r <= CR7_REGNO; ++r)
1892     rs6000_regno_regclass[r] = CR_REGS;
1893
1894   rs6000_regno_regclass[MQ_REGNO] = MQ_REGS;
1895   rs6000_regno_regclass[LR_REGNO] = LINK_REGS;
1896   rs6000_regno_regclass[CTR_REGNO] = CTR_REGS;
1897   rs6000_regno_regclass[XER_REGNO] = XER_REGS;
1898   rs6000_regno_regclass[VRSAVE_REGNO] = VRSAVE_REGS;
1899   rs6000_regno_regclass[VSCR_REGNO] = VRSAVE_REGS;
1900   rs6000_regno_regclass[SPE_ACC_REGNO] = SPE_ACC_REGS;
1901   rs6000_regno_regclass[SPEFSCR_REGNO] = SPEFSCR_REGS;
1902   rs6000_regno_regclass[ARG_POINTER_REGNUM] = BASE_REGS;
1903   rs6000_regno_regclass[FRAME_POINTER_REGNUM] = BASE_REGS;
1904
1905   /* Precalculate vector information, this must be set up before the
1906      rs6000_hard_regno_nregs_internal below.  */
1907   for (m = 0; m < NUM_MACHINE_MODES; ++m)
1908     {
1909       rs6000_vector_unit[m] = rs6000_vector_mem[m] = VECTOR_NONE;
1910       rs6000_vector_reload[m][0] = CODE_FOR_nothing;
1911       rs6000_vector_reload[m][1] = CODE_FOR_nothing;
1912     }
1913
1914   for (c = 0; c < (int)(int)RS6000_CONSTRAINT_MAX; c++)
1915     rs6000_constraints[c] = NO_REGS;
1916
1917   /* The VSX hardware allows native alignment for vectors, but control whether the compiler
1918      believes it can use native alignment or still uses 128-bit alignment.  */
1919   if (TARGET_VSX && !TARGET_VSX_ALIGN_128)
1920     {
1921       align64 = 64;
1922       align32 = 32;
1923     }
1924   else
1925     {
1926       align64 = 128;
1927       align32 = 128;
1928     }
1929
1930   /* V2DF mode, VSX only.  */
1931   if (TARGET_VSX)
1932     {
1933       rs6000_vector_unit[V2DFmode] = VECTOR_VSX;
1934       rs6000_vector_mem[V2DFmode] = VECTOR_VSX;
1935       rs6000_vector_align[V2DFmode] = align64;
1936     }
1937
1938   /* V4SF mode, either VSX or Altivec.  */
1939   if (TARGET_VSX)
1940     {
1941       rs6000_vector_unit[V4SFmode] = VECTOR_VSX;
1942       rs6000_vector_mem[V4SFmode] = VECTOR_VSX;
1943       rs6000_vector_align[V4SFmode] = align32;
1944     }
1945   else if (TARGET_ALTIVEC)
1946     {
1947       rs6000_vector_unit[V4SFmode] = VECTOR_ALTIVEC;
1948       rs6000_vector_mem[V4SFmode] = VECTOR_ALTIVEC;
1949       rs6000_vector_align[V4SFmode] = align32;
1950     }
1951
1952   /* V16QImode, V8HImode, V4SImode are Altivec only, but possibly do VSX loads
1953      and stores. */
1954   if (TARGET_ALTIVEC)
1955     {
1956       rs6000_vector_unit[V4SImode] = VECTOR_ALTIVEC;
1957       rs6000_vector_unit[V8HImode] = VECTOR_ALTIVEC;
1958       rs6000_vector_unit[V16QImode] = VECTOR_ALTIVEC;
1959       rs6000_vector_align[V4SImode] = align32;
1960       rs6000_vector_align[V8HImode] = align32;
1961       rs6000_vector_align[V16QImode] = align32;
1962
1963       if (TARGET_VSX)
1964         {
1965           rs6000_vector_mem[V4SImode] = VECTOR_VSX;
1966           rs6000_vector_mem[V8HImode] = VECTOR_VSX;
1967           rs6000_vector_mem[V16QImode] = VECTOR_VSX;
1968         }
1969       else
1970         {
1971           rs6000_vector_mem[V4SImode] = VECTOR_ALTIVEC;
1972           rs6000_vector_mem[V8HImode] = VECTOR_ALTIVEC;
1973           rs6000_vector_mem[V16QImode] = VECTOR_ALTIVEC;
1974         }
1975     }
1976
1977   /* V2DImode, only allow under VSX, which can do V2DI insert/splat/extract.
1978      Altivec doesn't have 64-bit support.  */
1979   if (TARGET_VSX)
1980     {
1981       rs6000_vector_mem[V2DImode] = VECTOR_VSX;
1982       rs6000_vector_unit[V2DImode] = VECTOR_NONE;
1983       rs6000_vector_align[V2DImode] = align64;
1984     }
1985
1986   /* DFmode, see if we want to use the VSX unit.  */
1987   if (TARGET_VSX && TARGET_VSX_SCALAR_DOUBLE)
1988     {
1989       rs6000_vector_unit[DFmode] = VECTOR_VSX;
1990       rs6000_vector_mem[DFmode]
1991         = (TARGET_VSX_SCALAR_MEMORY ? VECTOR_VSX : VECTOR_NONE);
1992       rs6000_vector_align[DFmode] = align64;
1993     }
1994
1995   /* TODO add SPE and paired floating point vector support.  */
1996
1997   /* Register class constaints for the constraints that depend on compile
1998      switches.  */
1999   if (TARGET_HARD_FLOAT && TARGET_FPRS)
2000     rs6000_constraints[RS6000_CONSTRAINT_f] = FLOAT_REGS;
2001
2002   if (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
2003     rs6000_constraints[RS6000_CONSTRAINT_d] = FLOAT_REGS;
2004
2005   if (TARGET_VSX)
2006     {
2007       /* At present, we just use VSX_REGS, but we have different constraints
2008          based on the use, in case we want to fine tune the default register
2009          class used.  wa = any VSX register, wf = register class to use for
2010          V4SF, wd = register class to use for V2DF, and ws = register classs to
2011          use for DF scalars.  */
2012       rs6000_constraints[RS6000_CONSTRAINT_wa] = VSX_REGS;
2013       rs6000_constraints[RS6000_CONSTRAINT_wf] = VSX_REGS;
2014       rs6000_constraints[RS6000_CONSTRAINT_wd] = VSX_REGS;
2015       if (TARGET_VSX_SCALAR_DOUBLE)
2016         rs6000_constraints[RS6000_CONSTRAINT_ws] = VSX_REGS;
2017     }
2018
2019   if (TARGET_ALTIVEC)
2020     rs6000_constraints[RS6000_CONSTRAINT_v] = ALTIVEC_REGS;
2021
2022   /* Set up the reload helper functions.  */
2023   if (TARGET_VSX || TARGET_ALTIVEC)
2024     {
2025       if (TARGET_64BIT)
2026         {
2027           rs6000_vector_reload[V16QImode][0] = CODE_FOR_reload_v16qi_di_store;
2028           rs6000_vector_reload[V16QImode][1] = CODE_FOR_reload_v16qi_di_load;
2029           rs6000_vector_reload[V8HImode][0]  = CODE_FOR_reload_v8hi_di_store;
2030           rs6000_vector_reload[V8HImode][1]  = CODE_FOR_reload_v8hi_di_load;
2031           rs6000_vector_reload[V4SImode][0]  = CODE_FOR_reload_v4si_di_store;
2032           rs6000_vector_reload[V4SImode][1]  = CODE_FOR_reload_v4si_di_load;
2033           rs6000_vector_reload[V2DImode][0]  = CODE_FOR_reload_v2di_di_store;
2034           rs6000_vector_reload[V2DImode][1]  = CODE_FOR_reload_v2di_di_load;
2035           rs6000_vector_reload[V4SFmode][0]  = CODE_FOR_reload_v4sf_di_store;
2036           rs6000_vector_reload[V4SFmode][1]  = CODE_FOR_reload_v4sf_di_load;
2037           rs6000_vector_reload[V2DFmode][0]  = CODE_FOR_reload_v2df_di_store;
2038           rs6000_vector_reload[V2DFmode][1]  = CODE_FOR_reload_v2df_di_load;
2039         }
2040       else
2041         {
2042           rs6000_vector_reload[V16QImode][0] = CODE_FOR_reload_v16qi_si_store;
2043           rs6000_vector_reload[V16QImode][1] = CODE_FOR_reload_v16qi_si_load;
2044           rs6000_vector_reload[V8HImode][0]  = CODE_FOR_reload_v8hi_si_store;
2045           rs6000_vector_reload[V8HImode][1]  = CODE_FOR_reload_v8hi_si_load;
2046           rs6000_vector_reload[V4SImode][0]  = CODE_FOR_reload_v4si_si_store;
2047           rs6000_vector_reload[V4SImode][1]  = CODE_FOR_reload_v4si_si_load;
2048           rs6000_vector_reload[V2DImode][0]  = CODE_FOR_reload_v2di_si_store;
2049           rs6000_vector_reload[V2DImode][1]  = CODE_FOR_reload_v2di_si_load;
2050           rs6000_vector_reload[V4SFmode][0]  = CODE_FOR_reload_v4sf_si_store;
2051           rs6000_vector_reload[V4SFmode][1]  = CODE_FOR_reload_v4sf_si_load;
2052           rs6000_vector_reload[V2DFmode][0]  = CODE_FOR_reload_v2df_si_store;
2053           rs6000_vector_reload[V2DFmode][1]  = CODE_FOR_reload_v2df_si_load;
2054         }
2055     }
2056
2057   /* Precalculate HARD_REGNO_NREGS.  */
2058   for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
2059     for (m = 0; m < NUM_MACHINE_MODES; ++m)
2060       rs6000_hard_regno_nregs[m][r]
2061         = rs6000_hard_regno_nregs_internal (r, (enum machine_mode)m);
2062
2063   /* Precalculate HARD_REGNO_MODE_OK.  */
2064   for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
2065     for (m = 0; m < NUM_MACHINE_MODES; ++m)
2066       if (rs6000_hard_regno_mode_ok (r, (enum machine_mode)m))
2067         rs6000_hard_regno_mode_ok_p[m][r] = true;
2068
2069   /* Precalculate CLASS_MAX_NREGS sizes.  */
2070   for (c = 0; c < LIM_REG_CLASSES; ++c)
2071     {
2072       int reg_size;
2073
2074       if (TARGET_VSX && VSX_REG_CLASS_P (c))
2075         reg_size = UNITS_PER_VSX_WORD;
2076
2077       else if (c == ALTIVEC_REGS)
2078         reg_size = UNITS_PER_ALTIVEC_WORD;
2079
2080       else if (c == FLOAT_REGS)
2081         reg_size = UNITS_PER_FP_WORD;
2082
2083       else
2084         reg_size = UNITS_PER_WORD;
2085
2086       for (m = 0; m < NUM_MACHINE_MODES; ++m)
2087         rs6000_class_max_nregs[m][c]
2088           = (GET_MODE_SIZE (m) + reg_size - 1) / reg_size;
2089     }
2090
2091   if (TARGET_E500_DOUBLE)
2092     rs6000_class_max_nregs[DFmode][GENERAL_REGS] = 1;
2093
2094   if (TARGET_DEBUG_REG)
2095     rs6000_debug_reg_global ();
2096 }
2097
2098 #if TARGET_MACHO
2099 /* The Darwin version of SUBTARGET_OVERRIDE_OPTIONS.  */
2100
2101 static void
2102 darwin_rs6000_override_options (void)
2103 {
2104   /* The Darwin ABI always includes AltiVec, can't be (validly) turned
2105      off.  */
2106   rs6000_altivec_abi = 1;
2107   TARGET_ALTIVEC_VRSAVE = 1;
2108   if (DEFAULT_ABI == ABI_DARWIN)
2109   {
2110     if (MACHO_DYNAMIC_NO_PIC_P)
2111       {
2112         if (flag_pic)
2113             warning (0, "-mdynamic-no-pic overrides -fpic or -fPIC");
2114         flag_pic = 0;
2115       }
2116     else if (flag_pic == 1)
2117       {
2118         flag_pic = 2;
2119       }
2120   }
2121   if (TARGET_64BIT && ! TARGET_POWERPC64)
2122     {
2123       target_flags |= MASK_POWERPC64;
2124       warning (0, "-m64 requires PowerPC64 architecture, enabling");
2125     }
2126   if (flag_mkernel)
2127     {
2128       rs6000_default_long_calls = 1;
2129       target_flags |= MASK_SOFT_FLOAT;
2130     }
2131
2132   /* Make -m64 imply -maltivec.  Darwin's 64-bit ABI includes
2133      Altivec.  */
2134   if (!flag_mkernel && !flag_apple_kext
2135       && TARGET_64BIT
2136       && ! (target_flags_explicit & MASK_ALTIVEC))
2137     target_flags |= MASK_ALTIVEC;
2138
2139   /* Unless the user (not the configurer) has explicitly overridden
2140      it with -mcpu=G3 or -mno-altivec, then 10.5+ targets default to
2141      G4 unless targetting the kernel.  */
2142   if (!flag_mkernel
2143       && !flag_apple_kext
2144       && strverscmp (darwin_macosx_version_min, "10.5") >= 0
2145       && ! (target_flags_explicit & MASK_ALTIVEC)
2146       && ! rs6000_select[1].string)
2147     {
2148       target_flags |= MASK_ALTIVEC;
2149     }
2150 }
2151 #endif
2152
2153 /* If not otherwise specified by a target, make 'long double' equivalent to
2154    'double'.  */
2155
2156 #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
2157 #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
2158 #endif
2159
2160 /* Override command line options.  Mostly we process the processor
2161    type and sometimes adjust other TARGET_ options.  */
2162
2163 void
2164 rs6000_override_options (const char *default_cpu)
2165 {
2166   size_t i, j;
2167   struct rs6000_cpu_select *ptr;
2168   int set_masks;
2169
2170   /* Simplifications for entries below.  */
2171
2172   enum {
2173     POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
2174     POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
2175   };
2176
2177   /* This table occasionally claims that a processor does not support
2178      a particular feature even though it does, but the feature is slower
2179      than the alternative.  Thus, it shouldn't be relied on as a
2180      complete description of the processor's support.
2181
2182      Please keep this list in order, and don't forget to update the
2183      documentation in invoke.texi when adding a new processor or
2184      flag.  */
2185   static struct ptt
2186     {
2187       const char *const name;           /* Canonical processor name.  */
2188       const enum processor_type processor; /* Processor type enum value.  */
2189       const int target_enable;  /* Target flags to enable.  */
2190     } const processor_target_table[]
2191       = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2192          {"403", PROCESSOR_PPC403,
2193           POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
2194          {"405", PROCESSOR_PPC405,
2195           POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW | MASK_DLMZB},
2196          {"405fp", PROCESSOR_PPC405,
2197           POWERPC_BASE_MASK | MASK_MULHW | MASK_DLMZB},
2198          {"440", PROCESSOR_PPC440,
2199           POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW | MASK_DLMZB},
2200          {"440fp", PROCESSOR_PPC440,
2201           POWERPC_BASE_MASK | MASK_MULHW | MASK_DLMZB},
2202          {"464", PROCESSOR_PPC440,
2203           POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW | MASK_DLMZB},
2204          {"464fp", PROCESSOR_PPC440,
2205           POWERPC_BASE_MASK | MASK_MULHW | MASK_DLMZB},
2206          {"476", PROCESSOR_PPC476,
2207           POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_PPC_GFXOPT | MASK_MFCRF
2208           | MASK_POPCNTB | MASK_FPRND | MASK_CMPB | MASK_MULHW | MASK_DLMZB},
2209          {"476fp", PROCESSOR_PPC476,
2210           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POPCNTB
2211           | MASK_FPRND | MASK_CMPB | MASK_MULHW | MASK_DLMZB},
2212          {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
2213          {"601", PROCESSOR_PPC601,
2214           MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
2215          {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2216          {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2217          {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2218          {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2219          {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2220          {"620", PROCESSOR_PPC620,
2221           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
2222          {"630", PROCESSOR_PPC630,
2223           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
2224          {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2225          {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
2226          {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
2227          {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2228          {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2229          {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2230          {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2231          {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_STRICT_ALIGN
2232           | MASK_ISEL},
2233          /* 8548 has a dummy entry for now.  */
2234          {"8548", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_STRICT_ALIGN
2235           | MASK_ISEL},
2236          {"a2", PROCESSOR_PPCA2,
2237           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_POPCNTB
2238           | MASK_CMPB | MASK_NO_UPDATE },
2239          {"e300c2", PROCESSOR_PPCE300C2, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2240          {"e300c3", PROCESSOR_PPCE300C3, POWERPC_BASE_MASK},
2241          {"e500mc", PROCESSOR_PPCE500MC, POWERPC_BASE_MASK | MASK_PPC_GFXOPT
2242           | MASK_ISEL},
2243          {"e500mc64", PROCESSOR_PPCE500MC64, POWERPC_BASE_MASK | MASK_POWERPC64
2244           | MASK_PPC_GFXOPT | MASK_ISEL},
2245          {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2246          {"970", PROCESSOR_POWER4,
2247           POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
2248          {"cell", PROCESSOR_CELL,
2249           POWERPC_7400_MASK  | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
2250          {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
2251          {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
2252          {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
2253          {"G4",  PROCESSOR_PPC7450, POWERPC_7400_MASK},
2254          {"G5", PROCESSOR_POWER4,
2255           POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
2256          {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
2257          {"power2", PROCESSOR_POWER,
2258           MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
2259          {"power3", PROCESSOR_PPC630,
2260           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
2261          {"power4", PROCESSOR_POWER4,
2262           POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GPOPT | MASK_PPC_GFXOPT
2263           | MASK_MFCRF},
2264          {"power5", PROCESSOR_POWER5,
2265           POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GPOPT | MASK_PPC_GFXOPT
2266           | MASK_MFCRF | MASK_POPCNTB},
2267          {"power5+", PROCESSOR_POWER5,
2268           POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GPOPT | MASK_PPC_GFXOPT
2269           | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND},
2270          {"power6", PROCESSOR_POWER6,
2271           POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GPOPT | MASK_PPC_GFXOPT
2272           | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND | MASK_CMPB | MASK_DFP},
2273          {"power6x", PROCESSOR_POWER6,
2274           POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GPOPT | MASK_PPC_GFXOPT
2275           | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND | MASK_CMPB | MASK_DFP
2276           | MASK_MFPGPR},
2277          {"power7", PROCESSOR_POWER7,
2278           POWERPC_7400_MASK | MASK_POWERPC64 | MASK_PPC_GPOPT | MASK_MFCRF
2279           | MASK_POPCNTB | MASK_FPRND | MASK_CMPB | MASK_DFP | MASK_POPCNTD
2280           | MASK_VSX},          /* Don't add MASK_ISEL by default */
2281          {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
2282          {"powerpc64", PROCESSOR_POWERPC64,
2283           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
2284          {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
2285          {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
2286          {"rios2", PROCESSOR_RIOS2,
2287           MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
2288          {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
2289          {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
2290          {"rs64", PROCESSOR_RS64A,
2291           POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}
2292       };
2293
2294   const size_t ptt_size = ARRAY_SIZE (processor_target_table);
2295
2296   /* Some OSs don't support saving the high part of 64-bit registers on
2297      context switch.  Other OSs don't support saving Altivec registers.
2298      On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
2299      settings; if the user wants either, the user must explicitly specify
2300      them and we won't interfere with the user's specification.  */
2301
2302   enum {
2303     POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
2304     POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT | MASK_STRICT_ALIGN
2305                      | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
2306                      | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND | MASK_MULHW
2307                      | MASK_DLMZB | MASK_CMPB | MASK_MFPGPR | MASK_DFP
2308                      | MASK_POPCNTD | MASK_VSX | MASK_ISEL | MASK_NO_UPDATE)
2309   };
2310
2311   /* Numerous experiment shows that IRA based loop pressure
2312      calculation works better for RTL loop invariant motion on targets
2313      with enough (>= 32) registers.  It is an expensive optimization.
2314      So it is on only for peak performance.  */
2315   if (optimize >= 3)
2316     flag_ira_loop_pressure = 1;
2317
2318   /* Set the pointer size.  */
2319   if (TARGET_64BIT)
2320     {
2321       rs6000_pmode = (int)DImode;
2322       rs6000_pointer_size = 64;
2323     }
2324   else
2325     {
2326       rs6000_pmode = (int)SImode;
2327       rs6000_pointer_size = 32;
2328     }
2329
2330   set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
2331 #ifdef OS_MISSING_POWERPC64
2332   if (OS_MISSING_POWERPC64)
2333     set_masks &= ~MASK_POWERPC64;
2334 #endif
2335 #ifdef OS_MISSING_ALTIVEC
2336   if (OS_MISSING_ALTIVEC)
2337     set_masks &= ~MASK_ALTIVEC;
2338 #endif
2339
2340   /* Don't override by the processor default if given explicitly.  */
2341   set_masks &= ~target_flags_explicit;
2342
2343   /* Identify the processor type.  */
2344   rs6000_select[0].string = default_cpu;
2345   rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
2346
2347   for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
2348     {
2349       ptr = &rs6000_select[i];
2350       if (ptr->string != (char *)0 && ptr->string[0] != '\0')
2351         {
2352           for (j = 0; j < ptt_size; j++)
2353             if (! strcmp (ptr->string, processor_target_table[j].name))
2354               {
2355                 if (ptr->set_tune_p)
2356                   rs6000_cpu = processor_target_table[j].processor;
2357
2358                 if (ptr->set_arch_p)
2359                   {
2360                     target_flags &= ~set_masks;
2361                     target_flags |= (processor_target_table[j].target_enable
2362                                      & set_masks);
2363                   }
2364                 break;
2365               }
2366
2367           if (j == ptt_size)
2368             error ("bad value (%s) for %s switch", ptr->string, ptr->name);
2369         }
2370     }
2371
2372   if (rs6000_cpu == PROCESSOR_PPCE300C2 || rs6000_cpu == PROCESSOR_PPCE300C3
2373       || rs6000_cpu == PROCESSOR_PPCE500MC || rs6000_cpu == PROCESSOR_PPCE500MC64)
2374     {
2375       if (TARGET_ALTIVEC)
2376         error ("AltiVec not supported in this target");
2377       if (TARGET_SPE)
2378         error ("Spe not supported in this target");
2379     }
2380
2381   /* Disable Cell microcode if we are optimizing for the Cell
2382      and not optimizing for size.  */
2383   if (rs6000_gen_cell_microcode == -1)
2384     rs6000_gen_cell_microcode = !(rs6000_cpu == PROCESSOR_CELL
2385                                   && !optimize_size);
2386
2387   /* If we are optimizing big endian systems for space and it's OK to
2388      use instructions that would be microcoded on the Cell, use the
2389      load/store multiple and string instructions.  */
2390   if (BYTES_BIG_ENDIAN && optimize_size && rs6000_gen_cell_microcode)
2391     target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
2392
2393   /* Don't allow -mmultiple or -mstring on little endian systems
2394      unless the cpu is a 750, because the hardware doesn't support the
2395      instructions used in little endian mode, and causes an alignment
2396      trap.  The 750 does not cause an alignment trap (except when the
2397      target is unaligned).  */
2398
2399   if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
2400     {
2401       if (TARGET_MULTIPLE)
2402         {
2403           target_flags &= ~MASK_MULTIPLE;
2404           if ((target_flags_explicit & MASK_MULTIPLE) != 0)
2405             warning (0, "-mmultiple is not supported on little endian systems");
2406         }
2407
2408       if (TARGET_STRING)
2409         {
2410           target_flags &= ~MASK_STRING;
2411           if ((target_flags_explicit & MASK_STRING) != 0)
2412             warning (0, "-mstring is not supported on little endian systems");
2413         }
2414     }
2415
2416   /* Add some warnings for VSX.  */
2417   if (TARGET_VSX)
2418     {
2419       const char *msg = NULL;
2420       if (!TARGET_HARD_FLOAT || !TARGET_FPRS
2421           || !TARGET_SINGLE_FLOAT || !TARGET_DOUBLE_FLOAT)
2422         {
2423           if (target_flags_explicit & MASK_VSX)
2424             msg = N_("-mvsx requires hardware floating point");
2425           else
2426             target_flags &= ~ MASK_VSX;
2427         }
2428       else if (TARGET_PAIRED_FLOAT)
2429         msg = N_("-mvsx and -mpaired are incompatible");
2430       /* The hardware will allow VSX and little endian, but until we make sure
2431          things like vector select, etc. work don't allow VSX on little endian
2432          systems at this point.  */
2433       else if (!BYTES_BIG_ENDIAN)
2434         msg = N_("-mvsx used with little endian code");
2435       else if (TARGET_AVOID_XFORM > 0)
2436         msg = N_("-mvsx needs indexed addressing");
2437       else if (!TARGET_ALTIVEC && (target_flags_explicit & MASK_ALTIVEC))
2438         {
2439           if (target_flags_explicit & MASK_VSX)
2440             msg = N_("-mvsx and -mno-altivec are incompatible");
2441           else
2442             msg = N_("-mno-altivec disables vsx");
2443         }
2444
2445       if (msg)
2446         {
2447           warning (0, msg);
2448           target_flags &= ~ MASK_VSX;
2449         }
2450       else if (TARGET_VSX && !TARGET_ALTIVEC)
2451         target_flags |= MASK_ALTIVEC;
2452     }
2453
2454   /* Set debug flags */
2455   if (rs6000_debug_name)
2456     {
2457       if (! strcmp (rs6000_debug_name, "all"))
2458         rs6000_debug_stack = rs6000_debug_arg = rs6000_debug_reg
2459           = rs6000_debug_addr = rs6000_debug_cost = 1;
2460       else if (! strcmp (rs6000_debug_name, "stack"))
2461         rs6000_debug_stack = 1;
2462       else if (! strcmp (rs6000_debug_name, "arg"))
2463         rs6000_debug_arg = 1;
2464       else if (! strcmp (rs6000_debug_name, "reg"))
2465         rs6000_debug_reg = 1;
2466       else if (! strcmp (rs6000_debug_name, "addr"))
2467         rs6000_debug_addr = 1;
2468       else if (! strcmp (rs6000_debug_name, "cost"))
2469         rs6000_debug_cost = 1;
2470       else
2471         error ("unknown -mdebug-%s switch", rs6000_debug_name);
2472
2473       /* If the appropriate debug option is enabled, replace the target hooks
2474          with debug versions that call the real version and then prints
2475          debugging information.  */
2476       if (TARGET_DEBUG_COST)
2477         {
2478           targetm.rtx_costs = rs6000_debug_rtx_costs;
2479           targetm.address_cost = rs6000_debug_address_cost;
2480           targetm.sched.adjust_cost = rs6000_debug_adjust_cost;
2481         }
2482
2483       if (TARGET_DEBUG_ADDR)
2484         {
2485           targetm.legitimate_address_p = rs6000_debug_legitimate_address_p;
2486           targetm.legitimize_address = rs6000_debug_legitimize_address;
2487           rs6000_secondary_reload_class_ptr
2488             = rs6000_debug_secondary_reload_class;
2489           rs6000_secondary_memory_needed_ptr
2490             = rs6000_debug_secondary_memory_needed;
2491           rs6000_cannot_change_mode_class_ptr
2492             = rs6000_debug_cannot_change_mode_class;
2493           rs6000_preferred_reload_class_ptr
2494             = rs6000_debug_preferred_reload_class;
2495           rs6000_legitimize_reload_address_ptr
2496             = rs6000_debug_legitimize_reload_address;
2497           rs6000_mode_dependent_address_ptr
2498             = rs6000_debug_mode_dependent_address;
2499         }
2500     }
2501
2502   if (rs6000_traceback_name)
2503     {
2504       if (! strncmp (rs6000_traceback_name, "full", 4))
2505         rs6000_traceback = traceback_full;
2506       else if (! strncmp (rs6000_traceback_name, "part", 4))
2507         rs6000_traceback = traceback_part;
2508       else if (! strncmp (rs6000_traceback_name, "no", 2))
2509         rs6000_traceback = traceback_none;
2510       else
2511         error ("unknown -mtraceback arg %qs; expecting %<full%>, %<partial%> or %<none%>",
2512                rs6000_traceback_name);
2513     }
2514
2515   if (!rs6000_explicit_options.long_double)
2516     rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
2517
2518 #ifndef POWERPC_LINUX
2519   if (!rs6000_explicit_options.ieee)
2520     rs6000_ieeequad = 1;
2521 #endif
2522
2523   /* Enable Altivec ABI for AIX -maltivec.  */
2524   if (TARGET_XCOFF && (TARGET_ALTIVEC || TARGET_VSX))
2525     rs6000_altivec_abi = 1;
2526
2527   /* The AltiVec ABI is the default for PowerPC-64 GNU/Linux.  For
2528      PowerPC-32 GNU/Linux, -maltivec implies the AltiVec ABI.  It can
2529      be explicitly overridden in either case.  */
2530   if (TARGET_ELF)
2531     {
2532       if (!rs6000_explicit_options.altivec_abi
2533           && (TARGET_64BIT || TARGET_ALTIVEC || TARGET_VSX))
2534         rs6000_altivec_abi = 1;
2535
2536       /* Enable VRSAVE for AltiVec ABI, unless explicitly overridden.  */
2537       if (!rs6000_explicit_options.vrsave)
2538         TARGET_ALTIVEC_VRSAVE = rs6000_altivec_abi;
2539     }
2540
2541   /* Set the Darwin64 ABI as default for 64-bit Darwin.  */
2542   if (DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT)
2543     {
2544       rs6000_darwin64_abi = 1;
2545 #if TARGET_MACHO
2546       darwin_one_byte_bool = 1;
2547 #endif
2548       /* Default to natural alignment, for better performance.  */
2549       rs6000_alignment_flags = MASK_ALIGN_NATURAL;
2550     }
2551
2552   /* Place FP constants in the constant pool instead of TOC
2553      if section anchors enabled.  */
2554   if (flag_section_anchors)
2555     TARGET_NO_FP_IN_TOC = 1;
2556
2557   /* Handle -mtls-size option.  */
2558   rs6000_parse_tls_size_option ();
2559
2560 #ifdef SUBTARGET_OVERRIDE_OPTIONS
2561   SUBTARGET_OVERRIDE_OPTIONS;
2562 #endif
2563 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
2564   SUBSUBTARGET_OVERRIDE_OPTIONS;
2565 #endif
2566 #ifdef SUB3TARGET_OVERRIDE_OPTIONS
2567   SUB3TARGET_OVERRIDE_OPTIONS;
2568 #endif
2569
2570   if (TARGET_E500 || rs6000_cpu == PROCESSOR_PPCE500MC
2571       || rs6000_cpu == PROCESSOR_PPCE500MC64)
2572     {
2573       /* The e500 and e500mc do not have string instructions, and we set
2574          MASK_STRING above when optimizing for size.  */
2575       if ((target_flags & MASK_STRING) != 0)
2576         target_flags = target_flags & ~MASK_STRING;
2577     }
2578   else if (rs6000_select[1].string != NULL)
2579     {
2580       /* For the powerpc-eabispe configuration, we set all these by
2581          default, so let's unset them if we manually set another
2582          CPU that is not the E500.  */
2583       if (!rs6000_explicit_options.spe_abi)
2584         rs6000_spe_abi = 0;
2585       if (!rs6000_explicit_options.spe)
2586         rs6000_spe = 0;
2587       if (!rs6000_explicit_options.float_gprs)
2588         rs6000_float_gprs = 0;
2589       if (!(target_flags_explicit & MASK_ISEL))
2590         target_flags &= ~MASK_ISEL;
2591     }
2592
2593   /* Detect invalid option combinations with E500.  */
2594   CHECK_E500_OPTIONS;
2595
2596   rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
2597                         && rs6000_cpu != PROCESSOR_POWER5
2598                         && rs6000_cpu != PROCESSOR_POWER6
2599                         && rs6000_cpu != PROCESSOR_POWER7
2600                         && rs6000_cpu != PROCESSOR_PPCA2
2601                         && rs6000_cpu != PROCESSOR_CELL);
2602   rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
2603                          || rs6000_cpu == PROCESSOR_POWER5
2604                          || rs6000_cpu == PROCESSOR_POWER7);
2605   rs6000_align_branch_targets = (rs6000_cpu == PROCESSOR_POWER4
2606                                  || rs6000_cpu == PROCESSOR_POWER5
2607                                  || rs6000_cpu == PROCESSOR_POWER6
2608                                  || rs6000_cpu == PROCESSOR_POWER7
2609                                  || rs6000_cpu == PROCESSOR_PPCE500MC
2610                                  || rs6000_cpu == PROCESSOR_PPCE500MC64);
2611
2612   /* Allow debug switches to override the above settings.  */
2613   if (TARGET_ALWAYS_HINT > 0)
2614     rs6000_always_hint = TARGET_ALWAYS_HINT;
2615
2616   if (TARGET_SCHED_GROUPS > 0)
2617     rs6000_sched_groups = TARGET_SCHED_GROUPS;
2618
2619   if (TARGET_ALIGN_BRANCH_TARGETS > 0)
2620     rs6000_align_branch_targets = TARGET_ALIGN_BRANCH_TARGETS;
2621
2622   rs6000_sched_restricted_insns_priority
2623     = (rs6000_sched_groups ? 1 : 0);
2624
2625   /* Handle -msched-costly-dep option.  */
2626   rs6000_sched_costly_dep
2627     = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
2628
2629   if (rs6000_sched_costly_dep_str)
2630     {
2631       if (! strcmp (rs6000_sched_costly_dep_str, "no"))
2632         rs6000_sched_costly_dep = no_dep_costly;
2633       else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
2634         rs6000_sched_costly_dep = all_deps_costly;
2635       else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
2636         rs6000_sched_costly_dep = true_store_to_load_dep_costly;
2637       else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
2638         rs6000_sched_costly_dep = store_to_load_dep_costly;
2639       else
2640         rs6000_sched_costly_dep = ((enum rs6000_dependence_cost)
2641                                    atoi (rs6000_sched_costly_dep_str));
2642     }
2643
2644   /* Handle -minsert-sched-nops option.  */
2645   rs6000_sched_insert_nops
2646     = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
2647
2648   if (rs6000_sched_insert_nops_str)
2649     {
2650       if (! strcmp (rs6000_sched_insert_nops_str, "no"))
2651         rs6000_sched_insert_nops = sched_finish_none;
2652       else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
2653         rs6000_sched_insert_nops = sched_finish_pad_groups;
2654       else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
2655         rs6000_sched_insert_nops = sched_finish_regroup_exact;
2656       else
2657         rs6000_sched_insert_nops = ((enum rs6000_nop_insertion)
2658                                     atoi (rs6000_sched_insert_nops_str));
2659     }
2660
2661 #ifdef TARGET_REGNAMES
2662   /* If the user desires alternate register names, copy in the
2663      alternate names now.  */
2664   if (TARGET_REGNAMES)
2665     memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
2666 #endif
2667
2668   /* Set aix_struct_return last, after the ABI is determined.
2669      If -maix-struct-return or -msvr4-struct-return was explicitly
2670      used, don't override with the ABI default.  */
2671   if (!rs6000_explicit_options.aix_struct_ret)
2672     aix_struct_return = (DEFAULT_ABI != ABI_V4 || DRAFT_V4_STRUCT_RET);
2673
2674   if (TARGET_LONG_DOUBLE_128 && !TARGET_IEEEQUAD)
2675     REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
2676
2677   if (TARGET_TOC)
2678     ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
2679
2680   /* We can only guarantee the availability of DI pseudo-ops when
2681      assembling for 64-bit targets.  */
2682   if (!TARGET_64BIT)
2683     {
2684       targetm.asm_out.aligned_op.di = NULL;
2685       targetm.asm_out.unaligned_op.di = NULL;
2686     }
2687
2688   /* Set branch target alignment, if not optimizing for size.  */
2689   if (!optimize_size)
2690     {
2691       /* Cell wants to be aligned 8byte for dual issue. */
2692       if (rs6000_cpu == PROCESSOR_CELL)
2693         {
2694           if (align_functions <= 0)
2695             align_functions = 8;
2696           if (align_jumps <= 0)
2697             align_jumps = 8;
2698           if (align_loops <= 0)
2699             align_loops = 8;
2700         }
2701       if (rs6000_align_branch_targets)
2702         {
2703           if (align_functions <= 0)
2704             align_functions = 16;
2705           if (align_jumps <= 0)
2706             align_jumps = 16;
2707           if (align_loops <= 0)
2708             align_loops = 16;
2709         }
2710       if (align_jumps_max_skip <= 0)
2711         align_jumps_max_skip = 15;
2712       if (align_loops_max_skip <= 0)
2713         align_loops_max_skip = 15;
2714     }
2715
2716   /* Arrange to save and restore machine status around nested functions.  */
2717   init_machine_status = rs6000_init_machine_status;
2718
2719   /* We should always be splitting complex arguments, but we can't break
2720      Linux and Darwin ABIs at the moment.  For now, only AIX is fixed.  */
2721   if (DEFAULT_ABI != ABI_AIX)
2722     targetm.calls.split_complex_arg = NULL;
2723
2724   /* Initialize rs6000_cost with the appropriate target costs.  */
2725   if (optimize_size)
2726     rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
2727   else
2728     switch (rs6000_cpu)
2729       {
2730       case PROCESSOR_RIOS1:
2731         rs6000_cost = &rios1_cost;
2732         break;
2733
2734       case PROCESSOR_RIOS2:
2735         rs6000_cost = &rios2_cost;
2736         break;
2737
2738       case PROCESSOR_RS64A:
2739         rs6000_cost = &rs64a_cost;
2740         break;
2741
2742       case PROCESSOR_MPCCORE:
2743         rs6000_cost = &mpccore_cost;
2744         break;
2745
2746       case PROCESSOR_PPC403:
2747         rs6000_cost = &ppc403_cost;
2748         break;
2749
2750       case PROCESSOR_PPC405:
2751         rs6000_cost = &ppc405_cost;
2752         break;
2753
2754       case PROCESSOR_PPC440:
2755         rs6000_cost = &ppc440_cost;
2756         break;
2757
2758       case PROCESSOR_PPC476:
2759         rs6000_cost = &ppc476_cost;
2760         break;
2761
2762       case PROCESSOR_PPC601:
2763         rs6000_cost = &ppc601_cost;
2764         break;
2765
2766       case PROCESSOR_PPC603:
2767         rs6000_cost = &ppc603_cost;
2768         break;
2769
2770       case PROCESSOR_PPC604:
2771         rs6000_cost = &ppc604_cost;
2772         break;
2773
2774       case PROCESSOR_PPC604e:
2775         rs6000_cost = &ppc604e_cost;
2776         break;
2777
2778       case PROCESSOR_PPC620:
2779         rs6000_cost = &ppc620_cost;
2780         break;
2781
2782       case PROCESSOR_PPC630:
2783         rs6000_cost = &ppc630_cost;
2784         break;
2785
2786       case PROCESSOR_CELL:
2787         rs6000_cost = &ppccell_cost;
2788         break;
2789
2790       case PROCESSOR_PPC750:
2791       case PROCESSOR_PPC7400:
2792         rs6000_cost = &ppc750_cost;
2793         break;
2794
2795       case PROCESSOR_PPC7450:
2796         rs6000_cost = &ppc7450_cost;
2797         break;
2798
2799       case PROCESSOR_PPC8540:
2800         rs6000_cost = &ppc8540_cost;
2801         break;
2802
2803       case PROCESSOR_PPCE300C2:
2804       case PROCESSOR_PPCE300C3:
2805         rs6000_cost = &ppce300c2c3_cost;
2806         break;
2807
2808       case PROCESSOR_PPCE500MC:
2809         rs6000_cost = &ppce500mc_cost;
2810         break;
2811
2812       case PROCESSOR_PPCE500MC64:
2813         rs6000_cost = &ppce500mc64_cost;
2814         break;
2815
2816       case PROCESSOR_POWER4:
2817       case PROCESSOR_POWER5:
2818         rs6000_cost = &power4_cost;
2819         break;
2820
2821       case PROCESSOR_POWER6:
2822         rs6000_cost = &power6_cost;
2823         break;
2824
2825       case PROCESSOR_POWER7:
2826         rs6000_cost = &power7_cost;
2827         break;
2828
2829       case PROCESSOR_PPCA2:
2830         rs6000_cost = &ppca2_cost;
2831         break;
2832
2833       default:
2834         gcc_unreachable ();
2835       }
2836
2837   if (!PARAM_SET_P (PARAM_SIMULTANEOUS_PREFETCHES))
2838     set_param_value ("simultaneous-prefetches",
2839                      rs6000_cost->simultaneous_prefetches);
2840   if (!PARAM_SET_P (PARAM_L1_CACHE_SIZE))
2841     set_param_value ("l1-cache-size", rs6000_cost->l1_cache_size);
2842   if (!PARAM_SET_P (PARAM_L1_CACHE_LINE_SIZE))
2843     set_param_value ("l1-cache-line-size", rs6000_cost->cache_line_size);
2844   if (!PARAM_SET_P (PARAM_L2_CACHE_SIZE))
2845     set_param_value ("l2-cache-size", rs6000_cost->l2_cache_size);
2846
2847   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
2848      can be optimized to ap = __builtin_next_arg (0).  */
2849   if (DEFAULT_ABI != ABI_V4)
2850     targetm.expand_builtin_va_start = NULL;
2851
2852   /* Set up single/double float flags.  
2853      If TARGET_HARD_FLOAT is set, but neither single or double is set, 
2854      then set both flags. */
2855   if (TARGET_HARD_FLOAT && TARGET_FPRS 
2856       && rs6000_single_float == 0 && rs6000_double_float == 0)
2857     rs6000_single_float = rs6000_double_float = 1;
2858
2859   /* Reset single and double FP flags if target is E500. */
2860   if (TARGET_E500) 
2861   {
2862     rs6000_single_float = rs6000_double_float = 0;
2863     if (TARGET_E500_SINGLE)
2864       rs6000_single_float = 1; 
2865     if (TARGET_E500_DOUBLE)
2866       rs6000_single_float = rs6000_double_float = 1;
2867   }
2868
2869   /* If not explicitly specified via option, decide whether to generate indexed
2870      load/store instructions.  */
2871   if (TARGET_AVOID_XFORM == -1)
2872     /* Avoid indexed addressing when targeting Power6 in order to avoid
2873      the DERAT mispredict penalty.  */
2874     TARGET_AVOID_XFORM = (rs6000_cpu == PROCESSOR_POWER6 && TARGET_CMPB);
2875
2876   rs6000_init_hard_regno_mode_ok ();
2877 }
2878
2879 /* Implement targetm.vectorize.builtin_mask_for_load.  */
2880 static tree
2881 rs6000_builtin_mask_for_load (void)
2882 {
2883   if (TARGET_ALTIVEC || TARGET_VSX)
2884     return altivec_builtin_mask_for_load;
2885   else
2886     return 0;
2887 }
2888
2889 /* Implement targetm.vectorize.builtin_conversion.
2890    Returns a decl of a function that implements conversion of an integer vector
2891    into a floating-point vector, or vice-versa.  DEST_TYPE is the
2892    destination type and SRC_TYPE the source type of the conversion.
2893    Return NULL_TREE if it is not available.  */
2894 static tree
2895 rs6000_builtin_conversion (unsigned int tcode, tree dest_type, tree src_type)
2896 {
2897   enum tree_code code = (enum tree_code) tcode;
2898
2899   switch (code)
2900     {
2901     case FIX_TRUNC_EXPR:
2902       switch (TYPE_MODE (dest_type))
2903         {
2904         case V2DImode:
2905           if (!VECTOR_UNIT_VSX_P (V2DFmode))
2906             return NULL_TREE;
2907
2908           return TYPE_UNSIGNED (dest_type)
2909             ? rs6000_builtin_decls[VSX_BUILTIN_XVCVDPUXDS_UNS]
2910             : rs6000_builtin_decls[VSX_BUILTIN_XVCVDPSXDS];
2911
2912         case V4SImode:
2913           if (VECTOR_UNIT_NONE_P (V4SImode) || VECTOR_UNIT_NONE_P (V4SFmode))
2914             return NULL_TREE;
2915
2916           return TYPE_UNSIGNED (dest_type)
2917             ? rs6000_builtin_decls[VECTOR_BUILTIN_FIXUNS_V4SF_V4SI]
2918             : rs6000_builtin_decls[VECTOR_BUILTIN_FIX_V4SF_V4SI];
2919
2920         default:
2921           return NULL_TREE;
2922         }
2923
2924     case FLOAT_EXPR:
2925       switch (TYPE_MODE (src_type))
2926         {
2927         case V2DImode:
2928           if (!VECTOR_UNIT_VSX_P (V2DFmode))
2929             return NULL_TREE;
2930
2931           return TYPE_UNSIGNED (src_type)
2932             ? rs6000_builtin_decls[VSX_BUILTIN_XVCVUXDDP]
2933             : rs6000_builtin_decls[VSX_BUILTIN_XVCVSXDDP];
2934
2935         case V4SImode:
2936           if (VECTOR_UNIT_NONE_P (V4SImode) || VECTOR_UNIT_NONE_P (V4SFmode))
2937             return NULL_TREE;
2938
2939           return TYPE_UNSIGNED (src_type)
2940             ? rs6000_builtin_decls[VECTOR_BUILTIN_UNSFLOAT_V4SI_V4SF]
2941             : rs6000_builtin_decls[VECTOR_BUILTIN_FLOAT_V4SI_V4SF];
2942
2943         default:
2944           return NULL_TREE;
2945         }
2946
2947     default:
2948       return NULL_TREE;
2949     }
2950 }
2951
2952 /* Implement targetm.vectorize.builtin_mul_widen_even.  */
2953 static tree
2954 rs6000_builtin_mul_widen_even (tree type)
2955 {
2956   if (!TARGET_ALTIVEC)
2957     return NULL_TREE;
2958
2959   switch (TYPE_MODE (type))
2960     {
2961     case V8HImode:
2962       return TYPE_UNSIGNED (type)
2963             ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULEUH_UNS]
2964             : rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULESH];
2965
2966     case V16QImode:
2967       return TYPE_UNSIGNED (type)
2968             ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULEUB_UNS]
2969             : rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULESB];
2970     default:
2971       return NULL_TREE;
2972     }
2973 }
2974
2975 /* Implement targetm.vectorize.builtin_mul_widen_odd.  */
2976 static tree
2977 rs6000_builtin_mul_widen_odd (tree type)
2978 {
2979   if (!TARGET_ALTIVEC)
2980     return NULL_TREE;
2981
2982   switch (TYPE_MODE (type))
2983     {
2984     case V8HImode:
2985       return TYPE_UNSIGNED (type)
2986             ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOUH_UNS]
2987             : rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOSH];
2988
2989     case V16QImode:
2990       return TYPE_UNSIGNED (type)
2991             ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOUB_UNS]
2992             : rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOSB];
2993     default:
2994       return NULL_TREE;
2995     }
2996 }
2997
2998
2999 /* Return true iff, data reference of TYPE can reach vector alignment (16)
3000    after applying N number of iterations.  This routine does not determine
3001    how may iterations are required to reach desired alignment.  */
3002
3003 static bool
3004 rs6000_vector_alignment_reachable (const_tree type ATTRIBUTE_UNUSED, bool is_packed)
3005 {
3006   if (is_packed)
3007     return false;
3008
3009   if (TARGET_32BIT)
3010     {
3011       if (rs6000_alignment_flags == MASK_ALIGN_NATURAL)
3012         return true;
3013
3014       if (rs6000_alignment_flags ==  MASK_ALIGN_POWER)
3015         return true;
3016
3017       return false;
3018     }
3019   else
3020     {
3021       if (TARGET_MACHO)
3022         return false;
3023
3024       /* Assuming that all other types are naturally aligned. CHECKME!  */
3025       return true;
3026     }
3027 }
3028
3029 /* Return true if the vector misalignment factor is supported by the
3030    target.  */ 
3031 bool
3032 rs6000_builtin_support_vector_misalignment (enum machine_mode mode,
3033                                             const_tree type,
3034                                             int misalignment,
3035                                             bool is_packed)
3036 {
3037   if (TARGET_VSX)
3038     {
3039       /* Return if movmisalign pattern is not supported for this mode.  */
3040       if (optab_handler (movmisalign_optab, mode)->insn_code ==
3041           CODE_FOR_nothing)
3042         return false;
3043
3044       if (misalignment == -1)
3045         {
3046           /* misalignment factor is unknown at compile time but we know
3047              it's word aligned.  */
3048           if (rs6000_vector_alignment_reachable (type, is_packed))
3049             return true;
3050           return false;
3051         }
3052       /* VSX supports word-aligned vector.  */
3053       if (misalignment % 4 == 0)
3054         return true;
3055     }
3056   return false;
3057 }
3058
3059 /* Implement targetm.vectorize.builtin_vec_perm.  */
3060 tree
3061 rs6000_builtin_vec_perm (tree type, tree *mask_element_type)
3062 {
3063   tree inner_type = TREE_TYPE (type);
3064   bool uns_p = TYPE_UNSIGNED (inner_type);
3065   tree d;
3066
3067   *mask_element_type = unsigned_char_type_node;
3068
3069   switch (TYPE_MODE (type))
3070     {
3071     case V16QImode:
3072       d = (uns_p
3073            ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_16QI_UNS]
3074            : rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_16QI]);
3075       break;
3076
3077     case V8HImode:
3078       d = (uns_p
3079            ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_8HI_UNS]
3080            : rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_8HI]);
3081       break;
3082
3083     case V4SImode:
3084       d = (uns_p
3085            ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_4SI_UNS]
3086            : rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_4SI]);
3087       break;
3088
3089     case V4SFmode:
3090       d = rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_4SF];
3091       break;
3092
3093     case V2DFmode:
3094       if (!TARGET_ALLOW_DF_PERMUTE)
3095         return NULL_TREE;
3096
3097       d = rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_2DF];
3098       break;
3099
3100     case V2DImode:
3101       if (!TARGET_ALLOW_DF_PERMUTE)
3102         return NULL_TREE;
3103
3104       d = (uns_p
3105            ? rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_2DI_UNS]
3106            : rs6000_builtin_decls[ALTIVEC_BUILTIN_VPERM_2DI]);
3107       break;
3108
3109     default:
3110       return NULL_TREE;
3111     }
3112
3113   gcc_assert (d);
3114   return d;
3115 }
3116
3117 /* Handle generic options of the form -mfoo=yes/no.
3118    NAME is the option name.
3119    VALUE is the option value.
3120    FLAG is the pointer to the flag where to store a 1 or 0, depending on
3121    whether the option value is 'yes' or 'no' respectively.  */
3122 static void
3123 rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
3124 {
3125   if (value == 0)
3126     return;
3127   else if (!strcmp (value, "yes"))
3128     *flag = 1;
3129   else if (!strcmp (value, "no"))
3130     *flag = 0;
3131   else
3132     error ("unknown -m%s= option specified: '%s'", name, value);
3133 }
3134
3135 /* Validate and record the size specified with the -mtls-size option.  */
3136
3137 static void
3138 rs6000_parse_tls_size_option (void)
3139 {
3140   if (rs6000_tls_size_string == 0)
3141     return;
3142   else if (strcmp (rs6000_tls_size_string, "16") == 0)
3143     rs6000_tls_size = 16;
3144   else if (strcmp (rs6000_tls_size_string, "32") == 0)
3145     rs6000_tls_size = 32;
3146   else if (strcmp (rs6000_tls_size_string, "64") == 0)
3147     rs6000_tls_size = 64;
3148   else
3149     error ("bad value %qs for -mtls-size switch", rs6000_tls_size_string);
3150 }
3151
3152 void
3153 optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
3154 {
3155   if (DEFAULT_ABI == ABI_DARWIN)
3156     /* The Darwin libraries never set errno, so we might as well
3157        avoid calling them when that's the only reason we would.  */
3158     flag_errno_math = 0;
3159
3160   /* Double growth factor to counter reduced min jump length.  */
3161   set_param_value ("max-grow-copy-bb-insns", 16);
3162
3163   /* Enable section anchors by default.
3164      Skip section anchors for Objective C and Objective C++
3165      until front-ends fixed.  */
3166   if (!TARGET_MACHO && lang_hooks.name[4] != 'O')
3167     flag_section_anchors = 2;
3168 }
3169
3170 static enum fpu_type_t
3171 rs6000_parse_fpu_option (const char *option)
3172 {
3173   if (!strcmp("none", option)) return FPU_NONE;
3174   if (!strcmp("sp_lite", option)) return FPU_SF_LITE;
3175   if (!strcmp("dp_lite", option)) return FPU_DF_LITE;
3176   if (!strcmp("sp_full", option)) return FPU_SF_FULL;
3177   if (!strcmp("dp_full", option)) return FPU_DF_FULL;
3178   error("unknown value %s for -mfpu", option);
3179   return FPU_NONE;
3180 }
3181
3182 /* Returns a function decl for a vectorized version of the builtin function
3183    with builtin function code FN and the result vector type TYPE, or NULL_TREE
3184    if it is not available.  */
3185
3186 static tree
3187 rs6000_builtin_vectorized_function (tree fndecl, tree type_out,
3188                                     tree type_in)
3189 {
3190   enum machine_mode in_mode, out_mode;
3191   int in_n, out_n;
3192   enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
3193
3194   if (TREE_CODE (type_out) != VECTOR_TYPE
3195       || TREE_CODE (type_in) != VECTOR_TYPE
3196       || !TARGET_VECTORIZE_BUILTINS
3197       || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
3198     return NULL_TREE;
3199
3200   out_mode = TYPE_MODE (TREE_TYPE (type_out));
3201   out_n = TYPE_VECTOR_SUBPARTS (type_out);
3202   in_mode = TYPE_MODE (TREE_TYPE (type_in));
3203   in_n = TYPE_VECTOR_SUBPARTS (type_in);
3204
3205   switch (fn)
3206     {
3207     case BUILT_IN_COPYSIGN:
3208       if (VECTOR_UNIT_VSX_P (V2DFmode)
3209           && out_mode == DFmode && out_n == 2
3210           && in_mode == DFmode && in_n == 2)
3211         return rs6000_builtin_decls[VSX_BUILTIN_CPSGNDP];
3212       break;
3213     case BUILT_IN_COPYSIGNF:
3214       if (out_mode != SFmode || out_n != 4
3215           || in_mode != SFmode || in_n != 4)
3216         break;
3217       if (VECTOR_UNIT_VSX_P (V4SFmode))
3218         return rs6000_builtin_decls[VSX_BUILTIN_CPSGNSP];
3219       if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
3220         return rs6000_builtin_decls[ALTIVEC_BUILTIN_COPYSIGN_V4SF];
3221       break;
3222     case BUILT_IN_SQRT:
3223       if (VECTOR_UNIT_VSX_P (V2DFmode)
3224           && out_mode == DFmode && out_n == 2
3225           && in_mode == DFmode && in_n == 2)
3226         return rs6000_builtin_decls[VSX_BUILTIN_XVSQRTDP];
3227       break;
3228     case BUILT_IN_SQRTF:
3229       if (VECTOR_UNIT_VSX_P (V4SFmode)
3230           && out_mode == SFmode && out_n == 4
3231           && in_mode == SFmode && in_n == 4)
3232         return rs6000_builtin_decls[VSX_BUILTIN_XVSQRTSP];
3233       break;
3234     case BUILT_IN_CEIL:
3235       if (VECTOR_UNIT_VSX_P (V2DFmode)
3236           && out_mode == DFmode && out_n == 2
3237           && in_mode == DFmode && in_n == 2)
3238         return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIP];
3239       break;
3240     case BUILT_IN_CEILF:
3241       if (out_mode != SFmode || out_n != 4
3242           || in_mode != SFmode || in_n != 4)
3243         break;
3244       if (VECTOR_UNIT_VSX_P (V4SFmode))
3245         return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIP];
3246       if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
3247         return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRFIP];
3248       break;
3249     case BUILT_IN_FLOOR:
3250       if (VECTOR_UNIT_VSX_P (V2DFmode)
3251           && out_mode == DFmode && out_n == 2
3252           && in_mode == DFmode && in_n == 2)
3253         return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIM];
3254       break;
3255     case BUILT_IN_FLOORF:
3256       if (out_mode != SFmode || out_n != 4
3257           || in_mode != SFmode || in_n != 4)
3258         break;
3259       if (VECTOR_UNIT_VSX_P (V4SFmode))
3260         return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIM];
3261       if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
3262         return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRFIM];
3263       break;
3264     case BUILT_IN_TRUNC:
3265       if (VECTOR_UNIT_VSX_P (V2DFmode)
3266           && out_mode == DFmode && out_n == 2
3267           && in_mode == DFmode && in_n == 2)
3268         return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIZ];
3269       break;
3270     case BUILT_IN_TRUNCF:
3271       if (out_mode != SFmode || out_n != 4
3272           || in_mode != SFmode || in_n != 4)
3273         break;
3274       if (VECTOR_UNIT_VSX_P (V4SFmode))
3275         return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIZ];
3276       if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
3277         return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRFIZ];
3278       break;
3279     case BUILT_IN_NEARBYINT:
3280       if (VECTOR_UNIT_VSX_P (V2DFmode)
3281           && flag_unsafe_math_optimizations
3282           && out_mode == DFmode && out_n == 2
3283           && in_mode == DFmode && in_n == 2)
3284         return rs6000_builtin_decls[VSX_BUILTIN_XVRDPI];
3285       break;
3286     case BUILT_IN_NEARBYINTF:
3287       if (VECTOR_UNIT_VSX_P (V4SFmode)
3288           && flag_unsafe_math_optimizations
3289           && out_mode == SFmode && out_n == 4
3290           && in_mode == SFmode && in_n == 4)
3291         return rs6000_builtin_decls[VSX_BUILTIN_XVRSPI];
3292       break;
3293     case BUILT_IN_RINT:
3294       if (VECTOR_UNIT_VSX_P (V2DFmode)
3295           && !flag_trapping_math
3296           && out_mode == DFmode && out_n == 2
3297           && in_mode == DFmode && in_n == 2)
3298         return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIC];
3299       break;
3300     case BUILT_IN_RINTF:
3301       if (VECTOR_UNIT_VSX_P (V4SFmode)
3302           && !flag_trapping_math
3303           && out_mode == SFmode && out_n == 4
3304           && in_mode == SFmode && in_n == 4)
3305         return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIC];
3306       break;
3307     default:
3308       break;
3309     }
3310   return NULL_TREE;
3311 }
3312
3313
3314 /* Implement TARGET_HANDLE_OPTION.  */
3315
3316 static bool
3317 rs6000_handle_option (size_t code, const char *arg, int value)
3318 {
3319   enum fpu_type_t fpu_type = FPU_NONE;
3320   int isel;
3321
3322   switch (code)
3323     {
3324     case OPT_mno_power:
3325       target_flags &= ~(MASK_POWER | MASK_POWER2
3326                         | MASK_MULTIPLE | MASK_STRING);
3327       target_flags_explicit |= (MASK_POWER | MASK_POWER2
3328                                 | MASK_MULTIPLE | MASK_STRING);
3329       break;
3330     case OPT_mno_powerpc:
3331       target_flags &= ~(MASK_POWERPC | MASK_PPC_GPOPT
3332                         | MASK_PPC_GFXOPT | MASK_POWERPC64);
3333       target_flags_explicit |= (MASK_POWERPC | MASK_PPC_GPOPT
3334                                 | MASK_PPC_GFXOPT | MASK_POWERPC64);
3335       break;
3336     case OPT_mfull_toc:
3337       target_flags &= ~MASK_MINIMAL_TOC;
3338       TARGET_NO_FP_IN_TOC = 0;
3339       TARGET_NO_SUM_IN_TOC = 0;
3340       target_flags_explicit |= MASK_MINIMAL_TOC;
3341 #ifdef TARGET_USES_SYSV4_OPT
3342       /* Note, V.4 no longer uses a normal TOC, so make -mfull-toc, be
3343          just the same as -mminimal-toc.  */
3344       target_flags |= MASK_MINIMAL_TOC;
3345       target_flags_explicit |= MASK_MINIMAL_TOC;
3346 #endif
3347       break;
3348
3349 #ifdef TARGET_USES_SYSV4_OPT
3350     case OPT_mtoc:
3351       /* Make -mtoc behave like -mminimal-toc.  */
3352       target_flags |= MASK_MINIMAL_TOC;
3353       target_flags_explicit |= MASK_MINIMAL_TOC;
3354       break;
3355 #endif
3356
3357 #ifdef TARGET_USES_AIX64_OPT
3358     case OPT_maix64:
3359 #else
3360     case OPT_m64:
3361 #endif
3362       target_flags |= MASK_POWERPC64 | MASK_POWERPC;
3363       target_flags |= ~target_flags_explicit & MASK_PPC_GFXOPT;
3364       target_flags_explicit |= MASK_POWERPC64 | MASK_POWERPC;
3365       break;
3366
3367 #ifdef TARGET_USES_AIX64_OPT
3368     case OPT_maix32:
3369 #else
3370     case OPT_m32:
3371 #endif
3372       target_flags &= ~MASK_POWERPC64;
3373       target_flags_explicit |= MASK_POWERPC64;
3374       break;
3375
3376     case OPT_minsert_sched_nops_:
3377       rs6000_sched_insert_nops_str = arg;
3378       break;
3379
3380     case OPT_mminimal_toc:
3381       if (value == 1)
3382         {
3383           TARGET_NO_FP_IN_TOC = 0;
3384           TARGET_NO_SUM_IN_TOC = 0;
3385         }
3386       break;
3387
3388     case OPT_mpower:
3389       if (value == 1)
3390         {
3391           target_flags |= (MASK_MULTIPLE | MASK_STRING);
3392           target_flags_explicit |= (MASK_MULTIPLE | MASK_STRING);
3393         }
3394       break;
3395
3396     case OPT_mpower2:
3397       if (value == 1)
3398         {
3399           target_flags |= (MASK_POWER | MASK_MULTIPLE | MASK_STRING);
3400           target_flags_explicit |= (MASK_POWER | MASK_MULTIPLE | MASK_STRING);
3401         }
3402       break;