OSDN Git Service

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