OSDN Git Service

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