OSDN Git Service

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