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 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2, or (at your
11 option) any later version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the
20 Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
43 #include "basic-block.h"
44 #include "integrate.h"
50 #include "target-def.h"
51 #include "langhooks.h"
54 #ifndef TARGET_NO_PROTOTYPE
55 #define TARGET_NO_PROTOTYPE 0
58 #define EASY_VECTOR_15(n, x, y) ((n) >= -16 && (n) <= 15 \
59 && easy_vector_same (x, y))
61 #define EASY_VECTOR_15_ADD_SELF(n, x, y) ((n) >= 0x10 && (n) <= 0x1e \
63 && easy_vector_same (x, y))
65 #define min(A,B) ((A) < (B) ? (A) : (B))
66 #define max(A,B) ((A) > (B) ? (A) : (B))
70 enum processor_type rs6000_cpu;
71 struct rs6000_cpu_select rs6000_select[3] =
73 /* switch name, tune arch */
74 { (const char *)0, "--with-cpu=", 1, 1 },
75 { (const char *)0, "-mcpu=", 1, 1 },
76 { (const char *)0, "-mtune=", 1, 0 },
79 /* Size of long double */
80 const char *rs6000_long_double_size_string;
81 int rs6000_long_double_type_size;
83 /* Whether -mabi=altivec has appeared */
84 int rs6000_altivec_abi;
86 /* Whether VRSAVE instructions should be generated. */
87 int rs6000_altivec_vrsave;
89 /* String from -mvrsave= option. */
90 const char *rs6000_altivec_vrsave_string;
92 /* Nonzero if we want SPE ABI extensions. */
95 /* Whether isel instructions should be generated. */
98 /* Whether SPE simd instructions should be generated. */
101 /* Nonzero if floating point operations are done in the GPRs. */
102 int rs6000_float_gprs = 0;
104 /* String from -mfloat-gprs=. */
105 const char *rs6000_float_gprs_string;
107 /* String from -misel=. */
108 const char *rs6000_isel_string;
110 /* String from -mspe=. */
111 const char *rs6000_spe_string;
113 /* Set to nonzero once AIX common-mode calls have been defined. */
114 static GTY(()) int common_mode_defined;
116 /* Save information from a "cmpxx" operation until the branch or scc is
118 rtx rs6000_compare_op0, rs6000_compare_op1;
119 int rs6000_compare_fp_p;
121 /* Label number of label created for -mrelocatable, to call to so we can
122 get the address of the GOT section */
123 int rs6000_pic_labelno;
126 /* Which abi to adhere to */
127 const char *rs6000_abi_name;
129 /* Semantics of the small data area */
130 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
132 /* Which small data model to use */
133 const char *rs6000_sdata_name = (char *)0;
135 /* Counter for labels which are to be placed in .fixup. */
136 int fixuplabelno = 0;
139 /* Bit size of immediate TLS offsets and string from which it is decoded. */
140 int rs6000_tls_size = 32;
141 const char *rs6000_tls_size_string;
143 /* ABI enumeration available for subtarget to use. */
144 enum rs6000_abi rs6000_current_abi;
146 /* ABI string from -mabi= option. */
147 const char *rs6000_abi_string;
150 const char *rs6000_debug_name;
151 int rs6000_debug_stack; /* debug stack applications */
152 int rs6000_debug_arg; /* debug argument handling */
155 static GTY(()) tree opaque_V2SI_type_node;
156 static GTY(()) tree opaque_V2SF_type_node;
157 static GTY(()) tree opaque_p_V2SI_type_node;
159 const char *rs6000_traceback_name;
161 traceback_default = 0,
167 /* Flag to say the TOC is initialized */
169 char toc_label_name[10];
171 /* Alias set for saves and restores from the rs6000 stack. */
172 static int rs6000_sr_alias_set;
174 /* Call distance, overridden by -mlongcall and #pragma longcall(1).
175 The only place that looks at this is rs6000_set_default_type_attributes;
176 everywhere else should rely on the presence or absence of a longcall
177 attribute on the function declaration. */
178 int rs6000_default_long_calls;
179 const char *rs6000_longcall_switch;
181 /* Control alignment for fields within structures. */
182 /* String from -malign-XXXXX. */
183 const char *rs6000_alignment_string;
184 int rs6000_alignment_flags;
186 struct builtin_description
188 /* mask is not const because we're going to alter it below. This
189 nonsense will go away when we rewrite the -march infrastructure
190 to give us more target flag bits. */
192 const enum insn_code icode;
193 const char *const name;
194 const enum rs6000_builtins code;
197 static bool rs6000_function_ok_for_sibcall PARAMS ((tree, tree));
198 static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
199 static void validate_condition_mode
200 PARAMS ((enum rtx_code, enum machine_mode));
201 static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
202 static void rs6000_maybe_dead PARAMS ((rtx));
203 static void rs6000_emit_stack_tie PARAMS ((void));
204 static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
205 static rtx spe_synthesize_frame_save PARAMS ((rtx));
206 static bool spe_func_has_64bit_regs_p PARAMS ((void));
207 static void emit_frame_save PARAMS ((rtx, rtx, enum machine_mode,
208 unsigned int, int, int));
209 static rtx gen_frame_mem_offset PARAMS ((enum machine_mode, rtx, int));
210 static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
211 static unsigned rs6000_hash_constant PARAMS ((rtx));
212 static unsigned toc_hash_function PARAMS ((const void *));
213 static int toc_hash_eq PARAMS ((const void *, const void *));
214 static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
215 static bool constant_pool_expr_p PARAMS ((rtx));
216 static bool toc_relative_expr_p PARAMS ((rtx));
217 static bool legitimate_small_data_p PARAMS ((enum machine_mode, rtx));
218 static bool legitimate_offset_address_p PARAMS ((enum machine_mode, rtx, int));
219 static bool legitimate_indexed_address_p PARAMS ((rtx, int));
220 static bool legitimate_indirect_address_p PARAMS ((rtx, int));
221 static bool legitimate_lo_sum_address_p PARAMS ((enum machine_mode, rtx, int));
222 static struct machine_function * rs6000_init_machine_status PARAMS ((void));
223 static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int));
224 #ifdef HAVE_GAS_HIDDEN
225 static void rs6000_assemble_visibility PARAMS ((tree, int));
227 static int rs6000_ra_ever_killed PARAMS ((void));
228 static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *));
229 extern const struct attribute_spec rs6000_attribute_table[];
230 static void rs6000_set_default_type_attributes PARAMS ((tree));
231 static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
232 static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
233 static void rs6000_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
234 HOST_WIDE_INT, tree));
235 static rtx rs6000_emit_set_long_const PARAMS ((rtx,
236 HOST_WIDE_INT, HOST_WIDE_INT));
238 static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
240 static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
241 static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
242 static void rs6000_elf_select_section PARAMS ((tree, int,
243 unsigned HOST_WIDE_INT));
244 static void rs6000_elf_unique_section PARAMS ((tree, int));
245 static void rs6000_elf_select_rtx_section PARAMS ((enum machine_mode, rtx,
246 unsigned HOST_WIDE_INT));
247 static void rs6000_elf_encode_section_info PARAMS ((tree, rtx, int))
249 static bool rs6000_elf_in_small_data_p PARAMS ((tree));
252 static void rs6000_xcoff_asm_globalize_label PARAMS ((FILE *, const char *));
253 static void rs6000_xcoff_asm_named_section PARAMS ((const char *, unsigned int));
254 static void rs6000_xcoff_select_section PARAMS ((tree, int,
255 unsigned HOST_WIDE_INT));
256 static void rs6000_xcoff_unique_section PARAMS ((tree, int));
257 static void rs6000_xcoff_select_rtx_section PARAMS ((enum machine_mode, rtx,
258 unsigned HOST_WIDE_INT));
259 static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *));
260 static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int));
261 static void rs6000_xcoff_file_end PARAMS ((void));
264 static bool rs6000_binds_local_p PARAMS ((tree));
266 static int rs6000_use_dfa_pipeline_interface PARAMS ((void));
267 static int rs6000_variable_issue PARAMS ((FILE *, int, rtx, int));
268 static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *));
269 static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
270 static int rs6000_adjust_priority PARAMS ((rtx, int));
271 static int rs6000_issue_rate PARAMS ((void));
272 static int rs6000_use_sched_lookahead PARAMS ((void));
274 static void rs6000_init_builtins PARAMS ((void));
275 static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
276 static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
277 static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
278 static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
279 static void altivec_init_builtins PARAMS ((void));
280 static void rs6000_common_init_builtins PARAMS ((void));
282 static void enable_mask_for_builtins PARAMS ((struct builtin_description *,
283 int, enum rs6000_builtins,
284 enum rs6000_builtins));
285 static void spe_init_builtins PARAMS ((void));
286 static rtx spe_expand_builtin PARAMS ((tree, rtx, bool *));
287 static rtx spe_expand_predicate_builtin PARAMS ((enum insn_code, tree, rtx));
288 static rtx spe_expand_evsel_builtin PARAMS ((enum insn_code, tree, rtx));
289 static int rs6000_emit_int_cmove PARAMS ((rtx, rtx, rtx, rtx));
291 static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *));
292 static rtx altivec_expand_ld_builtin PARAMS ((tree, rtx, bool *));
293 static rtx altivec_expand_st_builtin PARAMS ((tree, rtx, bool *));
294 static rtx altivec_expand_dst_builtin PARAMS ((tree, rtx, bool *));
295 static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
296 static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
297 static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
298 static void rs6000_parse_abi_options PARAMS ((void));
299 static void rs6000_parse_alignment_option PARAMS ((void));
300 static void rs6000_parse_tls_size_option PARAMS ((void));
301 static void rs6000_parse_yes_no_option (const char *, const char *, int *);
302 static int first_altivec_reg_to_save PARAMS ((void));
303 static unsigned int compute_vrsave_mask PARAMS ((void));
304 static void is_altivec_return_reg PARAMS ((rtx, void *));
305 static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
306 int easy_vector_constant PARAMS ((rtx, enum machine_mode));
307 static int easy_vector_same PARAMS ((rtx, enum machine_mode));
308 static bool is_ev64_opaque_type PARAMS ((tree));
309 static rtx rs6000_dwarf_register_span PARAMS ((rtx));
310 static rtx rs6000_legitimize_tls_address PARAMS ((rtx, enum tls_model));
311 static rtx rs6000_tls_get_addr PARAMS ((void));
312 static rtx rs6000_got_sym PARAMS ((void));
313 static inline int rs6000_tls_symbol_ref_1 PARAMS ((rtx *, void *));
314 static const char *rs6000_get_some_local_dynamic_name PARAMS ((void));
315 static int rs6000_get_some_local_dynamic_name_1 PARAMS ((rtx *, void *));
316 static rtx rs6000_complex_function_value (enum machine_mode);
318 /* Hash table stuff for keeping track of TOC entries. */
320 struct toc_hash_struct GTY(())
322 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
323 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
325 enum machine_mode key_mode;
329 static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
331 /* Default register names. */
332 char rs6000_reg_names[][8] =
334 "0", "1", "2", "3", "4", "5", "6", "7",
335 "8", "9", "10", "11", "12", "13", "14", "15",
336 "16", "17", "18", "19", "20", "21", "22", "23",
337 "24", "25", "26", "27", "28", "29", "30", "31",
338 "0", "1", "2", "3", "4", "5", "6", "7",
339 "8", "9", "10", "11", "12", "13", "14", "15",
340 "16", "17", "18", "19", "20", "21", "22", "23",
341 "24", "25", "26", "27", "28", "29", "30", "31",
342 "mq", "lr", "ctr","ap",
343 "0", "1", "2", "3", "4", "5", "6", "7",
345 /* AltiVec registers. */
346 "0", "1", "2", "3", "4", "5", "6", "7",
347 "8", "9", "10", "11", "12", "13", "14", "15",
348 "16", "17", "18", "19", "20", "21", "22", "23",
349 "24", "25", "26", "27", "28", "29", "30", "31",
355 #ifdef TARGET_REGNAMES
356 static const char alt_reg_names[][8] =
358 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
359 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
360 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
361 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
362 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
363 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
364 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
365 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
366 "mq", "lr", "ctr", "ap",
367 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
369 /* AltiVec registers. */
370 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
371 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
372 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
373 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
380 #ifndef MASK_STRICT_ALIGN
381 #define MASK_STRICT_ALIGN 0
383 #ifndef TARGET_PROFILE_KERNEL
384 #define TARGET_PROFILE_KERNEL 0
387 /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
388 #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
390 /* Return 1 for a symbol ref for a thread-local storage symbol. */
391 #define RS6000_SYMBOL_REF_TLS_P(RTX) \
392 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
394 /* Initialize the GCC target structure. */
395 #undef TARGET_ATTRIBUTE_TABLE
396 #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
397 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
398 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
400 #undef TARGET_ASM_ALIGNED_DI_OP
401 #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
403 /* Default unaligned ops are only provided for ELF. Find the ops needed
404 for non-ELF systems. */
405 #ifndef OBJECT_FORMAT_ELF
407 /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
409 #undef TARGET_ASM_UNALIGNED_HI_OP
410 #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
411 #undef TARGET_ASM_UNALIGNED_SI_OP
412 #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
413 #undef TARGET_ASM_UNALIGNED_DI_OP
414 #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
417 #undef TARGET_ASM_UNALIGNED_HI_OP
418 #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
419 #undef TARGET_ASM_UNALIGNED_SI_OP
420 #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
424 /* This hook deals with fixups for relocatable code and DI-mode objects
426 #undef TARGET_ASM_INTEGER
427 #define TARGET_ASM_INTEGER rs6000_assemble_integer
429 #ifdef HAVE_GAS_HIDDEN
430 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
431 #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
434 #undef TARGET_HAVE_TLS
435 #define TARGET_HAVE_TLS HAVE_AS_TLS
437 #undef TARGET_CANNOT_FORCE_CONST_MEM
438 #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
440 #undef TARGET_ASM_FUNCTION_PROLOGUE
441 #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
442 #undef TARGET_ASM_FUNCTION_EPILOGUE
443 #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
445 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
446 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
447 #undef TARGET_SCHED_VARIABLE_ISSUE
448 #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
450 #undef TARGET_SCHED_ISSUE_RATE
451 #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
452 #undef TARGET_SCHED_ADJUST_COST
453 #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
454 #undef TARGET_SCHED_ADJUST_PRIORITY
455 #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
457 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
458 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
460 #undef TARGET_INIT_BUILTINS
461 #define TARGET_INIT_BUILTINS rs6000_init_builtins
463 #undef TARGET_EXPAND_BUILTIN
464 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
467 #undef TARGET_BINDS_LOCAL_P
468 #define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
471 #undef TARGET_ASM_OUTPUT_MI_THUNK
472 #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
474 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
475 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
477 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
478 #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
480 #undef TARGET_RTX_COSTS
481 #define TARGET_RTX_COSTS rs6000_rtx_costs
482 #undef TARGET_ADDRESS_COST
483 #define TARGET_ADDRESS_COST hook_int_rtx_0
485 #undef TARGET_VECTOR_OPAQUE_P
486 #define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
488 #undef TARGET_DWARF_REGISTER_SPAN
489 #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
491 struct gcc_target targetm = TARGET_INITIALIZER;
493 /* Override command line options. Mostly we process the processor
494 type and sometimes adjust other TARGET_ options. */
497 rs6000_override_options (default_cpu)
498 const char *default_cpu;
501 struct rs6000_cpu_select *ptr;
503 /* Simplify the entries below by making a mask for any POWER
504 variant and any PowerPC variant. */
506 #define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
507 #define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
508 | MASK_PPC_GFXOPT | MASK_POWERPC64)
509 #define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
513 const char *const name; /* Canonical processor name. */
514 const enum processor_type processor; /* Processor type enum value. */
515 const int target_enable; /* Target flags to enable. */
516 const int target_disable; /* Target flags to disable. */
517 } const processor_target_table[]
518 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
519 POWER_MASKS | POWERPC_MASKS},
520 {"power", PROCESSOR_POWER,
521 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
522 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
523 {"power2", PROCESSOR_POWER,
524 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
525 POWERPC_MASKS | MASK_NEW_MNEMONICS},
526 {"power3", PROCESSOR_PPC630,
527 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
529 {"power4", PROCESSOR_POWER4,
530 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
532 {"powerpc", PROCESSOR_POWERPC,
533 MASK_POWERPC | MASK_NEW_MNEMONICS,
534 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
535 {"powerpc64", PROCESSOR_POWERPC64,
536 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
537 POWER_MASKS | POWERPC_OPT_MASKS},
538 {"rios", PROCESSOR_RIOS1,
539 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
540 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
541 {"rios1", PROCESSOR_RIOS1,
542 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
543 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
544 {"rsc", PROCESSOR_PPC601,
545 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
546 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
547 {"rsc1", PROCESSOR_PPC601,
548 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
549 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
550 {"rios2", PROCESSOR_RIOS2,
551 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
552 POWERPC_MASKS | MASK_NEW_MNEMONICS},
553 {"rs64a", PROCESSOR_RS64A,
554 MASK_POWERPC | MASK_NEW_MNEMONICS,
555 POWER_MASKS | POWERPC_OPT_MASKS},
556 {"401", PROCESSOR_PPC403,
557 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
558 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
559 {"403", PROCESSOR_PPC403,
560 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
561 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
562 {"405", PROCESSOR_PPC405,
563 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
564 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
565 {"405fp", PROCESSOR_PPC405,
566 MASK_POWERPC | MASK_NEW_MNEMONICS,
567 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
568 {"440", PROCESSOR_PPC440,
569 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
570 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
571 {"440fp", PROCESSOR_PPC440,
572 MASK_POWERPC | MASK_NEW_MNEMONICS,
573 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
574 {"505", PROCESSOR_MPCCORE,
575 MASK_POWERPC | MASK_NEW_MNEMONICS,
576 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
577 {"601", PROCESSOR_PPC601,
578 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
579 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
580 {"602", PROCESSOR_PPC603,
581 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
582 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
583 {"603", PROCESSOR_PPC603,
584 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
585 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
586 {"603e", PROCESSOR_PPC603,
587 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
588 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
589 {"ec603e", PROCESSOR_PPC603,
590 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
591 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
592 {"604", PROCESSOR_PPC604,
593 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
594 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
595 {"604e", PROCESSOR_PPC604e,
596 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
597 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
598 {"620", PROCESSOR_PPC620,
599 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
601 {"630", PROCESSOR_PPC630,
602 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
604 {"740", PROCESSOR_PPC750,
605 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
606 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
607 {"750", PROCESSOR_PPC750,
608 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
609 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
610 {"7400", PROCESSOR_PPC7400,
611 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
612 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
613 {"7450", PROCESSOR_PPC7450,
614 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
615 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
616 {"8540", PROCESSOR_PPC8540,
617 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
618 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
619 {"801", PROCESSOR_MPCCORE,
620 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
621 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
622 {"821", PROCESSOR_MPCCORE,
623 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
624 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
625 {"823", PROCESSOR_MPCCORE,
626 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
627 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
628 {"860", PROCESSOR_MPCCORE,
629 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
630 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
632 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
634 /* Save current -mmultiple/-mno-multiple status. */
635 int multiple = TARGET_MULTIPLE;
636 /* Save current -mstring/-mno-string status. */
637 int string = TARGET_STRING;
639 /* Identify the processor type. */
640 rs6000_select[0].string = default_cpu;
641 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
643 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
645 ptr = &rs6000_select[i];
646 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
648 for (j = 0; j < ptt_size; j++)
649 if (! strcmp (ptr->string, processor_target_table[j].name))
652 rs6000_cpu = processor_target_table[j].processor;
656 target_flags |= processor_target_table[j].target_enable;
657 target_flags &= ~processor_target_table[j].target_disable;
663 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
670 /* If we are optimizing big endian systems for space, use the load/store
671 multiple and string instructions. */
672 if (BYTES_BIG_ENDIAN && optimize_size)
673 target_flags |= MASK_MULTIPLE | MASK_STRING;
675 /* If -mmultiple or -mno-multiple was explicitly used, don't
676 override with the processor default */
677 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
678 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
680 /* If -mstring or -mno-string was explicitly used, don't override
681 with the processor default. */
682 if ((target_flags_explicit & MASK_STRING) != 0)
683 target_flags = (target_flags & ~MASK_STRING) | string;
685 /* Don't allow -mmultiple or -mstring on little endian systems
686 unless the cpu is a 750, because the hardware doesn't support the
687 instructions used in little endian mode, and causes an alignment
688 trap. The 750 does not cause an alignment trap (except when the
689 target is unaligned). */
691 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
695 target_flags &= ~MASK_MULTIPLE;
696 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
697 warning ("-mmultiple is not supported on little endian systems");
702 target_flags &= ~MASK_STRING;
703 if ((target_flags_explicit & MASK_STRING) != 0)
704 warning ("-mstring is not supported on little endian systems");
708 /* Set debug flags */
709 if (rs6000_debug_name)
711 if (! strcmp (rs6000_debug_name, "all"))
712 rs6000_debug_stack = rs6000_debug_arg = 1;
713 else if (! strcmp (rs6000_debug_name, "stack"))
714 rs6000_debug_stack = 1;
715 else if (! strcmp (rs6000_debug_name, "arg"))
716 rs6000_debug_arg = 1;
718 error ("unknown -mdebug-%s switch", rs6000_debug_name);
721 if (rs6000_traceback_name)
723 if (! strncmp (rs6000_traceback_name, "full", 4))
724 rs6000_traceback = traceback_full;
725 else if (! strncmp (rs6000_traceback_name, "part", 4))
726 rs6000_traceback = traceback_part;
727 else if (! strncmp (rs6000_traceback_name, "no", 2))
728 rs6000_traceback = traceback_none;
730 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
731 rs6000_traceback_name);
734 /* Set size of long double */
735 rs6000_long_double_type_size = 64;
736 if (rs6000_long_double_size_string)
739 int size = strtol (rs6000_long_double_size_string, &tail, 10);
740 if (*tail != '\0' || (size != 64 && size != 128))
741 error ("Unknown switch -mlong-double-%s",
742 rs6000_long_double_size_string);
744 rs6000_long_double_type_size = size;
747 /* Handle -mabi= options. */
748 rs6000_parse_abi_options ();
750 /* Handle -malign-XXXXX option. */
751 rs6000_parse_alignment_option ();
753 /* Handle generic -mFOO=YES/NO options. */
754 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
755 &rs6000_altivec_vrsave);
756 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
758 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
759 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
762 /* Handle -mtls-size option. */
763 rs6000_parse_tls_size_option ();
765 #ifdef SUBTARGET_OVERRIDE_OPTIONS
766 SUBTARGET_OVERRIDE_OPTIONS;
768 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
769 SUBSUBTARGET_OVERRIDE_OPTIONS;
774 /* The e500 does not have string instructions, and we set
775 MASK_STRING above when optimizing for size. */
776 if ((target_flags & MASK_STRING) != 0)
777 target_flags = target_flags & ~MASK_STRING;
779 /* No SPE means 64-bit long doubles, even if an E500. */
780 if (rs6000_spe_string != 0
781 && !strcmp (rs6000_spe_string, "no"))
782 rs6000_long_double_type_size = 64;
784 else if (rs6000_select[1].string != NULL)
786 /* For the powerpc-eabispe configuration, we set all these by
787 default, so let's unset them if we manually set another
788 CPU that is not the E500. */
789 if (rs6000_abi_string == 0)
791 if (rs6000_spe_string == 0)
793 if (rs6000_float_gprs_string == 0)
794 rs6000_float_gprs = 0;
795 if (rs6000_isel_string == 0)
797 if (rs6000_long_double_size_string == 0)
798 rs6000_long_double_type_size = 64;
801 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
802 using TARGET_OPTIONS to handle a toggle switch, but we're out of
803 bits in target_flags so TARGET_SWITCHES cannot be used.
804 Assumption here is that rs6000_longcall_switch points into the
805 text of the complete option, rather than being a copy, so we can
806 scan back for the presence or absence of the no- modifier. */
807 if (rs6000_longcall_switch)
809 const char *base = rs6000_longcall_switch;
810 while (base[-1] != 'm') base--;
812 if (*rs6000_longcall_switch != '\0')
813 error ("invalid option `%s'", base);
814 rs6000_default_long_calls = (base[0] != 'n');
817 #ifdef TARGET_REGNAMES
818 /* If the user desires alternate register names, copy in the
819 alternate names now. */
821 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
824 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
825 If -maix-struct-return or -msvr4-struct-return was explicitly
826 used, don't override with the ABI default. */
827 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
829 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
830 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
832 target_flags |= MASK_AIX_STRUCT_RET;
835 if (TARGET_LONG_DOUBLE_128
836 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
837 real_format_for_mode[TFmode - QFmode] = &ibm_extended_format;
839 /* Allocate an alias set for register saves & restores from stack. */
840 rs6000_sr_alias_set = new_alias_set ();
843 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
845 /* We can only guarantee the availability of DI pseudo-ops when
846 assembling for 64-bit targets. */
849 targetm.asm_out.aligned_op.di = NULL;
850 targetm.asm_out.unaligned_op.di = NULL;
853 /* Set maximum branch target alignment at two instructions, eight bytes. */
854 align_jumps_max_skip = 8;
855 align_loops_max_skip = 8;
857 /* Arrange to save and restore machine status around nested functions. */
858 init_machine_status = rs6000_init_machine_status;
861 /* Handle generic options of the form -mfoo=yes/no.
862 NAME is the option name.
863 VALUE is the option value.
864 FLAG is the pointer to the flag where to store a 1 or 0, depending on
865 whether the option value is 'yes' or 'no' respectively. */
867 rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
871 else if (!strcmp (value, "yes"))
873 else if (!strcmp (value, "no"))
876 error ("unknown -m%s= option specified: '%s'", name, value);
879 /* Handle -mabi= options. */
881 rs6000_parse_abi_options ()
883 if (rs6000_abi_string == 0)
885 else if (! strcmp (rs6000_abi_string, "altivec"))
886 rs6000_altivec_abi = 1;
887 else if (! strcmp (rs6000_abi_string, "no-altivec"))
888 rs6000_altivec_abi = 0;
889 else if (! strcmp (rs6000_abi_string, "spe"))
893 error ("not configured for ABI: '%s'", rs6000_abi_string);
896 else if (! strcmp (rs6000_abi_string, "no-spe"))
899 error ("unknown ABI specified: '%s'", rs6000_abi_string);
902 /* Handle -malign-XXXXXX options. */
904 rs6000_parse_alignment_option ()
906 if (rs6000_alignment_string == 0
907 || ! strcmp (rs6000_alignment_string, "power"))
908 rs6000_alignment_flags = MASK_ALIGN_POWER;
909 else if (! strcmp (rs6000_alignment_string, "natural"))
910 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
912 error ("unknown -malign-XXXXX option specified: '%s'",
913 rs6000_alignment_string);
916 /* Validate and record the size specified with the -mtls-size option. */
919 rs6000_parse_tls_size_option ()
921 if (rs6000_tls_size_string == 0)
923 else if (strcmp (rs6000_tls_size_string, "16") == 0)
924 rs6000_tls_size = 16;
925 else if (strcmp (rs6000_tls_size_string, "32") == 0)
926 rs6000_tls_size = 32;
927 else if (strcmp (rs6000_tls_size_string, "64") == 0)
928 rs6000_tls_size = 64;
930 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
934 optimization_options (level, size)
935 int level ATTRIBUTE_UNUSED;
936 int size ATTRIBUTE_UNUSED;
940 /* Do anything needed at the start of the asm file. */
943 rs6000_file_start (file, default_cpu)
945 const char *default_cpu;
949 const char *start = buffer;
950 struct rs6000_cpu_select *ptr;
952 if (flag_verbose_asm)
954 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
955 rs6000_select[0].string = default_cpu;
957 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
959 ptr = &rs6000_select[i];
960 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
962 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
968 switch (rs6000_sdata)
970 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
971 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
972 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
973 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
976 if (rs6000_sdata && g_switch_value)
978 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
989 /* Return nonzero if this function is known to have a null epilogue. */
994 if (reload_completed)
996 rs6000_stack_t *info = rs6000_stack_info ();
998 if (info->first_gp_reg_save == 32
999 && info->first_fp_reg_save == 64
1000 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
1001 && ! info->lr_save_p
1002 && ! info->cr_save_p
1003 && info->vrsave_mask == 0
1011 /* Returns 1 always. */
1014 any_operand (op, mode)
1015 rtx op ATTRIBUTE_UNUSED;
1016 enum machine_mode mode ATTRIBUTE_UNUSED;
1021 /* Returns 1 if op is the count register. */
1023 count_register_operand (op, mode)
1025 enum machine_mode mode ATTRIBUTE_UNUSED;
1027 if (GET_CODE (op) != REG)
1030 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1033 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1039 /* Returns 1 if op is an altivec register. */
1041 altivec_register_operand (op, mode)
1043 enum machine_mode mode ATTRIBUTE_UNUSED;
1046 return (register_operand (op, mode)
1047 && (GET_CODE (op) != REG
1048 || REGNO (op) > FIRST_PSEUDO_REGISTER
1049 || ALTIVEC_REGNO_P (REGNO (op))));
1053 xer_operand (op, mode)
1055 enum machine_mode mode ATTRIBUTE_UNUSED;
1057 if (GET_CODE (op) != REG)
1060 if (XER_REGNO_P (REGNO (op)))
1066 /* Return 1 if OP is a signed 8-bit constant. Int multiplication
1067 by such constants completes more quickly. */
1070 s8bit_cint_operand (op, mode)
1072 enum machine_mode mode ATTRIBUTE_UNUSED;
1074 return ( GET_CODE (op) == CONST_INT
1075 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1078 /* Return 1 if OP is a constant that can fit in a D field. */
1081 short_cint_operand (op, mode)
1083 enum machine_mode mode ATTRIBUTE_UNUSED;
1085 return (GET_CODE (op) == CONST_INT
1086 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
1089 /* Similar for an unsigned D field. */
1092 u_short_cint_operand (op, mode)
1094 enum machine_mode mode ATTRIBUTE_UNUSED;
1096 return (GET_CODE (op) == CONST_INT
1097 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
1100 /* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1103 non_short_cint_operand (op, mode)
1105 enum machine_mode mode ATTRIBUTE_UNUSED;
1107 return (GET_CODE (op) == CONST_INT
1108 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
1111 /* Returns 1 if OP is a CONST_INT that is a positive value
1112 and an exact power of 2. */
1115 exact_log2_cint_operand (op, mode)
1117 enum machine_mode mode ATTRIBUTE_UNUSED;
1119 return (GET_CODE (op) == CONST_INT
1121 && exact_log2 (INTVAL (op)) >= 0);
1124 /* Returns 1 if OP is a register that is not special (i.e., not MQ,
1128 gpc_reg_operand (op, mode)
1130 enum machine_mode mode;
1132 return (register_operand (op, mode)
1133 && (GET_CODE (op) != REG
1134 || (REGNO (op) >= ARG_POINTER_REGNUM
1135 && !XER_REGNO_P (REGNO (op)))
1136 || REGNO (op) < MQ_REGNO));
1139 /* Returns 1 if OP is either a pseudo-register or a register denoting a
1143 cc_reg_operand (op, mode)
1145 enum machine_mode mode;
1147 return (register_operand (op, mode)
1148 && (GET_CODE (op) != REG
1149 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1150 || CR_REGNO_P (REGNO (op))));
1153 /* Returns 1 if OP is either a pseudo-register or a register denoting a
1154 CR field that isn't CR0. */
1157 cc_reg_not_cr0_operand (op, mode)
1159 enum machine_mode mode;
1161 return (register_operand (op, mode)
1162 && (GET_CODE (op) != REG
1163 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1164 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1167 /* Returns 1 if OP is either a constant integer valid for a D-field or
1168 a non-special register. If a register, it must be in the proper
1169 mode unless MODE is VOIDmode. */
1172 reg_or_short_operand (op, mode)
1174 enum machine_mode mode;
1176 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
1179 /* Similar, except check if the negation of the constant would be
1180 valid for a D-field. */
1183 reg_or_neg_short_operand (op, mode)
1185 enum machine_mode mode;
1187 if (GET_CODE (op) == CONST_INT)
1188 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1190 return gpc_reg_operand (op, mode);
1193 /* Returns 1 if OP is either a constant integer valid for a DS-field or
1194 a non-special register. If a register, it must be in the proper
1195 mode unless MODE is VOIDmode. */
1198 reg_or_aligned_short_operand (op, mode)
1200 enum machine_mode mode;
1202 if (gpc_reg_operand (op, mode))
1204 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1211 /* Return 1 if the operand is either a register or an integer whose
1212 high-order 16 bits are zero. */
1215 reg_or_u_short_operand (op, mode)
1217 enum machine_mode mode;
1219 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
1222 /* Return 1 is the operand is either a non-special register or ANY
1223 constant integer. */
1226 reg_or_cint_operand (op, mode)
1228 enum machine_mode mode;
1230 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
1233 /* Return 1 is the operand is either a non-special register or ANY
1234 32-bit signed constant integer. */
1237 reg_or_arith_cint_operand (op, mode)
1239 enum machine_mode mode;
1241 return (gpc_reg_operand (op, mode)
1242 || (GET_CODE (op) == CONST_INT
1243 #if HOST_BITS_PER_WIDE_INT != 32
1244 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1245 < (unsigned HOST_WIDE_INT) 0x100000000ll)
1250 /* Return 1 is the operand is either a non-special register or a 32-bit
1251 signed constant integer valid for 64-bit addition. */
1254 reg_or_add_cint64_operand (op, mode)
1256 enum machine_mode mode;
1258 return (gpc_reg_operand (op, mode)
1259 || (GET_CODE (op) == CONST_INT
1260 #if HOST_BITS_PER_WIDE_INT == 32
1261 && INTVAL (op) < 0x7fff8000
1263 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1269 /* Return 1 is the operand is either a non-special register or a 32-bit
1270 signed constant integer valid for 64-bit subtraction. */
1273 reg_or_sub_cint64_operand (op, mode)
1275 enum machine_mode mode;
1277 return (gpc_reg_operand (op, mode)
1278 || (GET_CODE (op) == CONST_INT
1279 #if HOST_BITS_PER_WIDE_INT == 32
1280 && (- INTVAL (op)) < 0x7fff8000
1282 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1288 /* Return 1 is the operand is either a non-special register or ANY
1289 32-bit unsigned constant integer. */
1292 reg_or_logical_cint_operand (op, mode)
1294 enum machine_mode mode;
1296 if (GET_CODE (op) == CONST_INT)
1298 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1300 if (GET_MODE_BITSIZE (mode) <= 32)
1303 if (INTVAL (op) < 0)
1307 return ((INTVAL (op) & GET_MODE_MASK (mode)
1308 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1310 else if (GET_CODE (op) == CONST_DOUBLE)
1312 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1316 return CONST_DOUBLE_HIGH (op) == 0;
1319 return gpc_reg_operand (op, mode);
1322 /* Return 1 if the operand is an operand that can be loaded via the GOT. */
1325 got_operand (op, mode)
1327 enum machine_mode mode ATTRIBUTE_UNUSED;
1329 return (GET_CODE (op) == SYMBOL_REF
1330 || GET_CODE (op) == CONST
1331 || GET_CODE (op) == LABEL_REF);
1334 /* Return 1 if the operand is a simple references that can be loaded via
1335 the GOT (labels involving addition aren't allowed). */
1338 got_no_const_operand (op, mode)
1340 enum machine_mode mode ATTRIBUTE_UNUSED;
1342 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1345 /* Return the number of instructions it takes to form a constant in an
1346 integer register. */
1349 num_insns_constant_wide (value)
1350 HOST_WIDE_INT value;
1352 /* signed constant loadable with {cal|addi} */
1353 if (CONST_OK_FOR_LETTER_P (value, 'I'))
1356 /* constant loadable with {cau|addis} */
1357 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
1360 #if HOST_BITS_PER_WIDE_INT == 64
1361 else if (TARGET_POWERPC64)
1363 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1364 HOST_WIDE_INT high = value >> 31;
1366 if (high == 0 || high == -1)
1372 return num_insns_constant_wide (high) + 1;
1374 return (num_insns_constant_wide (high)
1375 + num_insns_constant_wide (low) + 1);
1384 num_insns_constant (op, mode)
1386 enum machine_mode mode;
1388 if (GET_CODE (op) == CONST_INT)
1390 #if HOST_BITS_PER_WIDE_INT == 64
1391 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1392 && mask64_operand (op, mode))
1396 return num_insns_constant_wide (INTVAL (op));
1399 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1404 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1405 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1406 return num_insns_constant_wide ((HOST_WIDE_INT) l);
1409 else if (GET_CODE (op) == CONST_DOUBLE)
1415 int endian = (WORDS_BIG_ENDIAN == 0);
1417 if (mode == VOIDmode || mode == DImode)
1419 high = CONST_DOUBLE_HIGH (op);
1420 low = CONST_DOUBLE_LOW (op);
1424 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1425 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1427 low = l[1 - endian];
1431 return (num_insns_constant_wide (low)
1432 + num_insns_constant_wide (high));
1436 if (high == 0 && low >= 0)
1437 return num_insns_constant_wide (low);
1439 else if (high == -1 && low < 0)
1440 return num_insns_constant_wide (low);
1442 else if (mask64_operand (op, mode))
1446 return num_insns_constant_wide (high) + 1;
1449 return (num_insns_constant_wide (high)
1450 + num_insns_constant_wide (low) + 1);
1458 /* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1459 register with one instruction per word. We only do this if we can
1460 safely read CONST_DOUBLE_{LOW,HIGH}. */
1463 easy_fp_constant (op, mode)
1465 enum machine_mode mode;
1467 if (GET_CODE (op) != CONST_DOUBLE
1468 || GET_MODE (op) != mode
1469 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
1472 /* Consider all constants with -msoft-float to be easy. */
1473 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1477 /* If we are using V.4 style PIC, consider all constants to be hard. */
1478 if (flag_pic && DEFAULT_ABI == ABI_V4)
1481 #ifdef TARGET_RELOCATABLE
1482 /* Similarly if we are using -mrelocatable, consider all constants
1484 if (TARGET_RELOCATABLE)
1493 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1494 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1496 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1497 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1498 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1499 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1502 else if (mode == DFmode)
1507 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1508 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1510 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1511 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
1514 else if (mode == SFmode)
1519 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1520 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1522 return num_insns_constant_wide (l) == 1;
1525 else if (mode == DImode)
1526 return ((TARGET_POWERPC64
1527 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1528 || (num_insns_constant (op, DImode) <= 2));
1530 else if (mode == SImode)
1536 /* Return non zero if all elements of a vector have the same value. */
1539 easy_vector_same (op, mode)
1541 enum machine_mode mode ATTRIBUTE_UNUSED;
1545 units = CONST_VECTOR_NUNITS (op);
1547 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1548 for (i = 1; i < units; ++i)
1549 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1556 /* Return 1 if the operand is a CONST_INT and can be put into a
1557 register without using memory. */
1560 easy_vector_constant (op, mode)
1562 enum machine_mode mode;
1566 if (GET_CODE (op) != CONST_VECTOR
1571 if (zero_constant (op, mode)
1572 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1573 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1576 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1579 if (TARGET_SPE && mode == V1DImode)
1582 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1583 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1585 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1587 evmergelo r0, r0, r0
1590 I don't know how efficient it would be to allow bigger constants,
1591 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1592 instructions is better than a 64-bit memory load, but I don't
1593 have the e500 timing specs. */
1594 if (TARGET_SPE && mode == V2SImode
1595 && cst >= -0x7fff && cst <= 0x7fff
1596 && cst2 >= -0x7fff && cst2 <= 0x7fff)
1599 if (TARGET_ALTIVEC && EASY_VECTOR_15 (cst, op, mode))
1602 if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode))
1608 /* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1611 easy_vector_constant_add_self (op, mode)
1613 enum machine_mode mode;
1617 if (!easy_vector_constant (op, mode))
1620 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1622 return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode);
1626 output_vec_const_move (operands)
1630 enum machine_mode mode;
1636 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1637 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1638 mode = GET_MODE (dest);
1642 if (zero_constant (vec, mode))
1643 return "vxor %0,%0,%0";
1644 else if (EASY_VECTOR_15 (cst, vec, mode))
1646 operands[1] = GEN_INT (cst);
1650 return "vspltisw %0,%1";
1652 return "vspltish %0,%1";
1654 return "vspltisb %0,%1";
1659 else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode))
1667 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1668 pattern of V1DI, V4HI, and V2SF.
1670 FIXME: We should probabl return # and add post reload
1671 splitters for these, but this way is so easy ;-).
1673 operands[1] = GEN_INT (cst);
1674 operands[2] = GEN_INT (cst2);
1676 return "li %0,%1\n\tevmergelo %0,%0,%0";
1678 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1684 /* Return 1 if the operand is the constant 0. This works for scalars
1685 as well as vectors. */
1687 zero_constant (op, mode)
1689 enum machine_mode mode;
1691 return op == CONST0_RTX (mode);
1694 /* Return 1 if the operand is 0.0. */
1696 zero_fp_constant (op, mode)
1698 enum machine_mode mode;
1700 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1703 /* Return 1 if the operand is in volatile memory. Note that during
1704 the RTL generation phase, memory_operand does not return TRUE for
1705 volatile memory references. So this function allows us to
1706 recognize volatile references where its safe. */
1709 volatile_mem_operand (op, mode)
1711 enum machine_mode mode;
1713 if (GET_CODE (op) != MEM)
1716 if (!MEM_VOLATILE_P (op))
1719 if (mode != GET_MODE (op))
1722 if (reload_completed)
1723 return memory_operand (op, mode);
1725 if (reload_in_progress)
1726 return strict_memory_address_p (mode, XEXP (op, 0));
1728 return memory_address_p (mode, XEXP (op, 0));
1731 /* Return 1 if the operand is an offsettable memory operand. */
1734 offsettable_mem_operand (op, mode)
1736 enum machine_mode mode;
1738 return ((GET_CODE (op) == MEM)
1739 && offsettable_address_p (reload_completed || reload_in_progress,
1740 mode, XEXP (op, 0)));
1743 /* Return 1 if the operand is either an easy FP constant (see above) or
1747 mem_or_easy_const_operand (op, mode)
1749 enum machine_mode mode;
1751 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1754 /* Return 1 if the operand is either a non-special register or an item
1755 that can be used as the operand of a `mode' add insn. */
1758 add_operand (op, mode)
1760 enum machine_mode mode;
1762 if (GET_CODE (op) == CONST_INT)
1763 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1764 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
1766 return gpc_reg_operand (op, mode);
1769 /* Return 1 if OP is a constant but not a valid add_operand. */
1772 non_add_cint_operand (op, mode)
1774 enum machine_mode mode ATTRIBUTE_UNUSED;
1776 return (GET_CODE (op) == CONST_INT
1777 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1778 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
1781 /* Return 1 if the operand is a non-special register or a constant that
1782 can be used as the operand of an OR or XOR insn on the RS/6000. */
1785 logical_operand (op, mode)
1787 enum machine_mode mode;
1789 HOST_WIDE_INT opl, oph;
1791 if (gpc_reg_operand (op, mode))
1794 if (GET_CODE (op) == CONST_INT)
1796 opl = INTVAL (op) & GET_MODE_MASK (mode);
1798 #if HOST_BITS_PER_WIDE_INT <= 32
1799 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1803 else if (GET_CODE (op) == CONST_DOUBLE)
1805 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
1808 opl = CONST_DOUBLE_LOW (op);
1809 oph = CONST_DOUBLE_HIGH (op);
1816 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1817 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
1820 /* Return 1 if C is a constant that is not a logical operand (as
1821 above), but could be split into one. */
1824 non_logical_cint_operand (op, mode)
1826 enum machine_mode mode;
1828 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1829 && ! logical_operand (op, mode)
1830 && reg_or_logical_cint_operand (op, mode));
1833 /* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
1834 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1835 Reject all ones and all zeros, since these should have been optimized
1836 away and confuse the making of MB and ME. */
1839 mask_operand (op, mode)
1841 enum machine_mode mode ATTRIBUTE_UNUSED;
1843 HOST_WIDE_INT c, lsb;
1845 if (GET_CODE (op) != CONST_INT)
1850 /* Fail in 64-bit mode if the mask wraps around because the upper
1851 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1852 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1855 /* We don't change the number of transitions by inverting,
1856 so make sure we start with the LS bit zero. */
1860 /* Reject all zeros or all ones. */
1864 /* Find the first transition. */
1867 /* Invert to look for a second transition. */
1870 /* Erase first transition. */
1873 /* Find the second transition (if any). */
1876 /* Match if all the bits above are 1's (or c is zero). */
1880 /* Return 1 for the PowerPC64 rlwinm corner case. */
1883 mask_operand_wrap (op, mode)
1885 enum machine_mode mode ATTRIBUTE_UNUSED;
1887 HOST_WIDE_INT c, lsb;
1889 if (GET_CODE (op) != CONST_INT)
1894 if ((c & 0x80000001) != 0x80000001)
1908 /* Return 1 if the operand is a constant that is a PowerPC64 mask.
1909 It is if there are no more than one 1->0 or 0->1 transitions.
1910 Reject all zeros, since zero should have been optimized away and
1911 confuses the making of MB and ME. */
1914 mask64_operand (op, mode)
1916 enum machine_mode mode ATTRIBUTE_UNUSED;
1918 if (GET_CODE (op) == CONST_INT)
1920 HOST_WIDE_INT c, lsb;
1924 /* Reject all zeros. */
1928 /* We don't change the number of transitions by inverting,
1929 so make sure we start with the LS bit zero. */
1933 /* Find the transition, and check that all bits above are 1's. */
1936 /* Match if all the bits above are 1's (or c is zero). */
1942 /* Like mask64_operand, but allow up to three transitions. This
1943 predicate is used by insn patterns that generate two rldicl or
1944 rldicr machine insns. */
1947 mask64_2_operand (op, mode)
1949 enum machine_mode mode ATTRIBUTE_UNUSED;
1951 if (GET_CODE (op) == CONST_INT)
1953 HOST_WIDE_INT c, lsb;
1957 /* Disallow all zeros. */
1961 /* We don't change the number of transitions by inverting,
1962 so make sure we start with the LS bit zero. */
1966 /* Find the first transition. */
1969 /* Invert to look for a second transition. */
1972 /* Erase first transition. */
1975 /* Find the second transition. */
1978 /* Invert to look for a third transition. */
1981 /* Erase second transition. */
1984 /* Find the third transition (if any). */
1987 /* Match if all the bits above are 1's (or c is zero). */
1993 /* Generates shifts and masks for a pair of rldicl or rldicr insns to
1994 implement ANDing by the mask IN. */
1996 build_mask64_2_operands (in, out)
2000 #if HOST_BITS_PER_WIDE_INT >= 64
2001 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2004 if (GET_CODE (in) != CONST_INT)
2010 /* Assume c initially something like 0x00fff000000fffff. The idea
2011 is to rotate the word so that the middle ^^^^^^ group of zeros
2012 is at the MS end and can be cleared with an rldicl mask. We then
2013 rotate back and clear off the MS ^^ group of zeros with a
2015 c = ~c; /* c == 0xff000ffffff00000 */
2016 lsb = c & -c; /* lsb == 0x0000000000100000 */
2017 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2018 c = ~c; /* c == 0x00fff000000fffff */
2019 c &= -lsb; /* c == 0x00fff00000000000 */
2020 lsb = c & -c; /* lsb == 0x0000100000000000 */
2021 c = ~c; /* c == 0xff000fffffffffff */
2022 c &= -lsb; /* c == 0xff00000000000000 */
2024 while ((lsb >>= 1) != 0)
2025 shift++; /* shift == 44 on exit from loop */
2026 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2027 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2028 m2 = ~c; /* m2 == 0x00ffffffffffffff */
2032 /* Assume c initially something like 0xff000f0000000000. The idea
2033 is to rotate the word so that the ^^^ middle group of zeros
2034 is at the LS end and can be cleared with an rldicr mask. We then
2035 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2037 lsb = c & -c; /* lsb == 0x0000010000000000 */
2038 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2039 c = ~c; /* c == 0x00fff0ffffffffff */
2040 c &= -lsb; /* c == 0x00fff00000000000 */
2041 lsb = c & -c; /* lsb == 0x0000100000000000 */
2042 c = ~c; /* c == 0xff000fffffffffff */
2043 c &= -lsb; /* c == 0xff00000000000000 */
2045 while ((lsb >>= 1) != 0)
2046 shift++; /* shift == 44 on exit from loop */
2047 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2048 m1 >>= shift; /* m1 == 0x0000000000000fff */
2049 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2052 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2053 masks will be all 1's. We are guaranteed more than one transition. */
2054 out[0] = GEN_INT (64 - shift);
2055 out[1] = GEN_INT (m1);
2056 out[2] = GEN_INT (shift);
2057 out[3] = GEN_INT (m2);
2065 /* Return 1 if the operand is either a non-special register or a constant
2066 that can be used as the operand of a PowerPC64 logical AND insn. */
2069 and64_operand (op, mode)
2071 enum machine_mode mode;
2073 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
2074 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2076 return (logical_operand (op, mode) || mask64_operand (op, mode));
2079 /* Like the above, but also match constants that can be implemented
2080 with two rldicl or rldicr insns. */
2083 and64_2_operand (op, mode)
2085 enum machine_mode mode;
2087 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
2088 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2090 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2093 /* Return 1 if the operand is either a non-special register or a
2094 constant that can be used as the operand of an RS/6000 logical AND insn. */
2097 and_operand (op, mode)
2099 enum machine_mode mode;
2101 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
2102 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2104 return (logical_operand (op, mode) || mask_operand (op, mode));
2107 /* Return 1 if the operand is a general register or memory operand. */
2110 reg_or_mem_operand (op, mode)
2112 enum machine_mode mode;
2114 return (gpc_reg_operand (op, mode)
2115 || memory_operand (op, mode)
2116 || volatile_mem_operand (op, mode));
2119 /* Return 1 if the operand is a general register or memory operand without
2120 pre_inc or pre_dec which produces invalid form of PowerPC lwa
2124 lwa_operand (op, mode)
2126 enum machine_mode mode;
2130 if (reload_completed && GET_CODE (inner) == SUBREG)
2131 inner = SUBREG_REG (inner);
2133 return gpc_reg_operand (inner, mode)
2134 || (memory_operand (inner, mode)
2135 && GET_CODE (XEXP (inner, 0)) != PRE_INC
2136 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2137 && (GET_CODE (XEXP (inner, 0)) != PLUS
2138 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2139 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
2142 /* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2145 symbol_ref_operand (op, mode)
2147 enum machine_mode mode;
2149 if (mode != VOIDmode && GET_MODE (op) != mode)
2152 return (GET_CODE (op) == SYMBOL_REF
2153 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
2156 /* Return 1 if the operand, used inside a MEM, is a valid first argument
2157 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
2160 call_operand (op, mode)
2162 enum machine_mode mode;
2164 if (mode != VOIDmode && GET_MODE (op) != mode)
2167 return (GET_CODE (op) == SYMBOL_REF
2168 || (GET_CODE (op) == REG
2169 && (REGNO (op) == LINK_REGISTER_REGNUM
2170 || REGNO (op) == COUNT_REGISTER_REGNUM
2171 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
2174 /* Return 1 if the operand is a SYMBOL_REF for a function known to be in
2178 current_file_function_operand (op, mode)
2180 enum machine_mode mode ATTRIBUTE_UNUSED;
2182 return (GET_CODE (op) == SYMBOL_REF
2183 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2184 && (SYMBOL_REF_LOCAL_P (op)
2185 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2188 /* Return 1 if this operand is a valid input for a move insn. */
2191 input_operand (op, mode)
2193 enum machine_mode mode;
2195 /* Memory is always valid. */
2196 if (memory_operand (op, mode))
2199 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
2200 if (GET_CODE (op) == CONSTANT_P_RTX)
2203 /* For floating-point, easy constants are valid. */
2204 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2206 && easy_fp_constant (op, mode))
2209 /* Allow any integer constant. */
2210 if (GET_MODE_CLASS (mode) == MODE_INT
2211 && (GET_CODE (op) == CONST_INT
2212 || GET_CODE (op) == CONST_DOUBLE))
2215 /* Allow easy vector constants. */
2216 if (GET_CODE (op) == CONST_VECTOR
2217 && easy_vector_constant (op, mode))
2220 /* For floating-point or multi-word mode, the only remaining valid type
2222 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2223 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
2224 return register_operand (op, mode);
2226 /* The only cases left are integral modes one word or smaller (we
2227 do not get called for MODE_CC values). These can be in any
2229 if (register_operand (op, mode))
2232 /* A SYMBOL_REF referring to the TOC is valid. */
2233 if (legitimate_constant_pool_address_p (op))
2236 /* A constant pool expression (relative to the TOC) is valid */
2237 if (toc_relative_expr_p (op))
2240 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2242 if (DEFAULT_ABI == ABI_V4
2243 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2244 && small_data_operand (op, Pmode))
2250 /* Return 1 for an operand in small memory on V.4/eabi. */
2253 small_data_operand (op, mode)
2254 rtx op ATTRIBUTE_UNUSED;
2255 enum machine_mode mode ATTRIBUTE_UNUSED;
2260 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
2263 if (DEFAULT_ABI != ABI_V4)
2266 if (GET_CODE (op) == SYMBOL_REF)
2269 else if (GET_CODE (op) != CONST
2270 || GET_CODE (XEXP (op, 0)) != PLUS
2271 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2272 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
2277 rtx sum = XEXP (op, 0);
2278 HOST_WIDE_INT summand;
2280 /* We have to be careful here, because it is the referenced address
2281 that must be 32k from _SDA_BASE_, not just the symbol. */
2282 summand = INTVAL (XEXP (sum, 1));
2283 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
2286 sym_ref = XEXP (sum, 0);
2289 return SYMBOL_REF_SMALL_P (sym_ref);
2295 /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2298 constant_pool_expr_1 (op, have_sym, have_toc)
2303 switch (GET_CODE(op))
2306 if (RS6000_SYMBOL_REF_TLS_P (op))
2308 else if (CONSTANT_POOL_ADDRESS_P (op))
2310 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2318 else if (! strcmp (XSTR (op, 0), toc_label_name))
2327 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2328 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
2330 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
2339 constant_pool_expr_p (op)
2344 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2348 toc_relative_expr_p (op)
2353 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2356 /* SPE offset addressing is limited to 5-bits worth of double words. */
2357 #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2360 legitimate_constant_pool_address_p (x)
2364 && GET_CODE (x) == PLUS
2365 && GET_CODE (XEXP (x, 0)) == REG
2366 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2367 && constant_pool_expr_p (XEXP (x, 1)));
2371 legitimate_small_data_p (mode, x)
2372 enum machine_mode mode;
2375 return (DEFAULT_ABI == ABI_V4
2376 && !flag_pic && !TARGET_TOC
2377 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2378 && small_data_operand (x, mode));
2382 legitimate_offset_address_p (mode, x, strict)
2383 enum machine_mode mode;
2387 unsigned HOST_WIDE_INT offset, extra;
2389 if (GET_CODE (x) != PLUS)
2391 if (GET_CODE (XEXP (x, 0)) != REG)
2393 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2395 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2398 offset = INTVAL (XEXP (x, 1));
2406 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2407 which leaves the only valid constant offset of zero, which by
2408 canonicalization rules is also invalid. */
2415 /* SPE vector modes. */
2416 return SPE_CONST_OFFSET_OK (offset);
2422 else if (offset & 3)
2430 else if (offset & 3)
2440 return (offset + extra >= offset) && (offset + extra + 0x8000 < 0x10000);
2444 legitimate_indexed_address_p (x, strict)
2450 if (GET_CODE (x) != PLUS)
2455 if (!REG_P (op0) || !REG_P (op1))
2458 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2459 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2460 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2461 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
2465 legitimate_indirect_address_p (x, strict)
2469 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2473 legitimate_lo_sum_address_p (mode, x, strict)
2474 enum machine_mode mode;
2478 if (GET_CODE (x) != LO_SUM)
2480 if (GET_CODE (XEXP (x, 0)) != REG)
2482 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2488 if (DEFAULT_ABI != ABI_AIX && flag_pic)
2492 if (GET_MODE_NUNITS (mode) != 1)
2494 if (GET_MODE_BITSIZE (mode) > 32
2495 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2498 return CONSTANT_P (x);
2505 /* Try machine-dependent ways of modifying an illegitimate address
2506 to be legitimate. If we find one, return the new, valid address.
2507 This is used from only one place: `memory_address' in explow.c.
2509 OLDX is the address as it was before break_out_memory_refs was
2510 called. In some cases it is useful to look at this to decide what
2513 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
2515 It is always safe for this function to do nothing. It exists to
2516 recognize opportunities to optimize the output.
2518 On RS/6000, first check for the sum of a register with a constant
2519 integer that is out of range. If so, generate code to add the
2520 constant with the low-order 16 bits masked to the register and force
2521 this result into another register (this can be done with `cau').
2522 Then generate an address of REG+(CONST&0xffff), allowing for the
2523 possibility of bit 16 being a one.
2525 Then check for the sum of a register and something not constant, try to
2526 load the other things into a register and return the sum. */
2529 rs6000_legitimize_address (x, oldx, mode)
2531 rtx oldx ATTRIBUTE_UNUSED;
2532 enum machine_mode mode;
2534 if (GET_CODE (x) == SYMBOL_REF)
2536 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2538 return rs6000_legitimize_tls_address (x, model);
2541 if (GET_CODE (x) == PLUS
2542 && GET_CODE (XEXP (x, 0)) == REG
2543 && GET_CODE (XEXP (x, 1)) == CONST_INT
2544 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2546 HOST_WIDE_INT high_int, low_int;
2548 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2549 high_int = INTVAL (XEXP (x, 1)) - low_int;
2550 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2551 GEN_INT (high_int)), 0);
2552 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2554 else if (GET_CODE (x) == PLUS
2555 && GET_CODE (XEXP (x, 0)) == REG
2556 && GET_CODE (XEXP (x, 1)) != CONST_INT
2557 && GET_MODE_NUNITS (mode) == 1
2558 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2560 || (mode != DFmode && mode != TFmode))
2561 && (TARGET_POWERPC64 || mode != DImode)
2564 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2565 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2567 else if (ALTIVEC_VECTOR_MODE (mode))
2571 /* Make sure both operands are registers. */
2572 if (GET_CODE (x) == PLUS)
2573 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
2574 force_reg (Pmode, XEXP (x, 1)));
2576 reg = force_reg (Pmode, x);
2579 else if (SPE_VECTOR_MODE (mode))
2581 /* We accept [reg + reg] and [reg + OFFSET]. */
2583 if (GET_CODE (x) == PLUS)
2585 rtx op1 = XEXP (x, 0);
2586 rtx op2 = XEXP (x, 1);
2588 op1 = force_reg (Pmode, op1);
2590 if (GET_CODE (op2) != REG
2591 && (GET_CODE (op2) != CONST_INT
2592 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2593 op2 = force_reg (Pmode, op2);
2595 return gen_rtx_PLUS (Pmode, op1, op2);
2598 return force_reg (Pmode, x);
2604 && GET_CODE (x) != CONST_INT
2605 && GET_CODE (x) != CONST_DOUBLE
2607 && GET_MODE_NUNITS (mode) == 1
2608 && (GET_MODE_BITSIZE (mode) <= 32
2609 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
2611 rtx reg = gen_reg_rtx (Pmode);
2612 emit_insn (gen_elf_high (reg, (x)));
2613 return gen_rtx_LO_SUM (Pmode, reg, (x));
2615 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2618 && ! MACHO_DYNAMIC_NO_PIC_P
2620 && GET_CODE (x) != CONST_INT
2621 && GET_CODE (x) != CONST_DOUBLE
2623 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
2627 rtx reg = gen_reg_rtx (Pmode);
2628 emit_insn (gen_macho_high (reg, (x)));
2629 return gen_rtx_LO_SUM (Pmode, reg, (x));
2632 && constant_pool_expr_p (x)
2633 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
2635 return create_TOC_reference (x);
2641 /* Construct the SYMBOL_REF for the tls_get_addr function. */
2643 static GTY(()) rtx rs6000_tls_symbol;
2645 rs6000_tls_get_addr ()
2647 if (!rs6000_tls_symbol)
2648 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2650 return rs6000_tls_symbol;
2653 /* Construct the SYMBOL_REF for TLS GOT references. */
2655 static GTY(()) rtx rs6000_got_symbol;
2659 if (!rs6000_got_symbol)
2661 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2662 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2663 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2666 return rs6000_got_symbol;
2669 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2670 this (thread-local) address. */
2673 rs6000_legitimize_tls_address (addr, model)
2675 enum tls_model model;
2679 dest = gen_reg_rtx (Pmode);
2680 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2686 tlsreg = gen_rtx_REG (Pmode, 13);
2687 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2691 tlsreg = gen_rtx_REG (Pmode, 2);
2692 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2696 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2700 tmp = gen_reg_rtx (Pmode);
2703 tlsreg = gen_rtx_REG (Pmode, 13);
2704 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2708 tlsreg = gen_rtx_REG (Pmode, 2);
2709 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2713 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2715 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2720 rtx r3, got, tga, tmp1, tmp2, eqv;
2723 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2727 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2730 rtx gsym = rs6000_got_sym ();
2731 got = gen_reg_rtx (Pmode);
2733 rs6000_emit_move (got, gsym, Pmode);
2737 static int tls_got_labelno = 0;
2738 rtx tempLR, lab, tmp3, mem;
2741 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2742 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2743 tempLR = gen_reg_rtx (Pmode);
2744 tmp1 = gen_reg_rtx (Pmode);
2745 tmp2 = gen_reg_rtx (Pmode);
2746 tmp3 = gen_reg_rtx (Pmode);
2747 mem = gen_rtx_MEM (Pmode, tmp1);
2748 RTX_UNCHANGING_P (mem) = 1;
2750 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2752 emit_move_insn (tmp1, tempLR);
2753 emit_move_insn (tmp2, mem);
2754 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2755 last = emit_move_insn (got, tmp3);
2756 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2758 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2760 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2766 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
2768 r3 = gen_rtx_REG (Pmode, 3);
2770 insn = gen_tls_gd_64 (r3, got, addr);
2772 insn = gen_tls_gd_32 (r3, got, addr);
2775 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2776 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2777 insn = emit_call_insn (insn);
2778 CONST_OR_PURE_CALL_P (insn) = 1;
2779 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2780 insn = get_insns ();
2782 emit_libcall_block (insn, dest, r3, addr);
2784 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
2786 r3 = gen_rtx_REG (Pmode, 3);
2788 insn = gen_tls_ld_64 (r3, got);
2790 insn = gen_tls_ld_32 (r3, got);
2793 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2794 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2795 insn = emit_call_insn (insn);
2796 CONST_OR_PURE_CALL_P (insn) = 1;
2797 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2798 insn = get_insns ();
2800 tmp1 = gen_reg_rtx (Pmode);
2801 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2803 emit_libcall_block (insn, tmp1, r3, eqv);
2804 if (rs6000_tls_size == 16)
2807 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
2809 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
2811 else if (rs6000_tls_size == 32)
2813 tmp2 = gen_reg_rtx (Pmode);
2815 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
2817 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
2820 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
2822 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
2826 tmp2 = gen_reg_rtx (Pmode);
2828 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
2830 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
2832 insn = gen_rtx_SET (Pmode, dest,
2833 gen_rtx_PLUS (Pmode, tmp2, tmp1));
2839 /* IE, or 64 bit offset LE. */
2840 tmp2 = gen_reg_rtx (Pmode);
2842 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
2844 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
2847 insn = gen_tls_tls_64 (dest, tmp2, addr);
2849 insn = gen_tls_tls_32 (dest, tmp2, addr);
2857 /* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
2858 instruction definitions. */
2861 rs6000_tls_symbol_ref (x, mode)
2863 enum machine_mode mode ATTRIBUTE_UNUSED;
2865 return RS6000_SYMBOL_REF_TLS_P (x);
2868 /* Return 1 if X contains a thread-local symbol. */
2871 rs6000_tls_referenced_p (x)
2874 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
2877 /* Return 1 if *X is a thread-local symbol. This is the same as
2878 rs6000_tls_symbol_ref except for the type of the unused argument. */
2881 rs6000_tls_symbol_ref_1 (x, data)
2883 void *data ATTRIBUTE_UNUSED;
2885 return RS6000_SYMBOL_REF_TLS_P (*x);
2888 /* The convention appears to be to define this wherever it is used.
2889 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
2890 is now used here. */
2891 #ifndef REG_MODE_OK_FOR_BASE_P
2892 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
2895 /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
2896 replace the input X, or the original X if no replacement is called for.
2897 The output parameter *WIN is 1 if the calling macro should goto WIN,
2900 For RS/6000, we wish to handle large displacements off a base
2901 register by splitting the addend across an addiu/addis and the mem insn.
2902 This cuts number of extra insns needed from 3 to 1.
2904 On Darwin, we use this to generate code for floating point constants.
2905 A movsf_low is generated so we wind up with 2 instructions rather than 3.
2906 The Darwin code is inside #if TARGET_MACHO because only then is
2907 machopic_function_base_name() defined. */
2909 rs6000_legitimize_reload_address (x, mode, opnum, type, ind_levels, win)
2911 enum machine_mode mode;
2914 int ind_levels ATTRIBUTE_UNUSED;
2917 /* We must recognize output that we have already generated ourselves. */
2918 if (GET_CODE (x) == PLUS
2919 && GET_CODE (XEXP (x, 0)) == PLUS
2920 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2921 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2922 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2924 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2925 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2926 opnum, (enum reload_type)type);
2932 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
2933 && GET_CODE (x) == LO_SUM
2934 && GET_CODE (XEXP (x, 0)) == PLUS
2935 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
2936 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
2937 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
2938 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
2939 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
2940 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
2941 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
2943 /* Result of previous invocation of this function on Darwin
2944 floating point constant. */
2945 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2946 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2947 opnum, (enum reload_type)type);
2952 if (GET_CODE (x) == PLUS
2953 && GET_CODE (XEXP (x, 0)) == REG
2954 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2955 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
2956 && GET_CODE (XEXP (x, 1)) == CONST_INT
2957 && !SPE_VECTOR_MODE (mode)
2958 && !ALTIVEC_VECTOR_MODE (mode))
2960 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2961 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2963 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2965 /* Check for 32-bit overflow. */
2966 if (high + low != val)
2972 /* Reload the high part into a base reg; leave the low part
2973 in the mem directly. */
2975 x = gen_rtx_PLUS (GET_MODE (x),
2976 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2980 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2981 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2982 opnum, (enum reload_type)type);
2987 if (GET_CODE (x) == SYMBOL_REF
2988 && DEFAULT_ABI == ABI_DARWIN
2989 && !ALTIVEC_VECTOR_MODE (mode)
2992 /* Darwin load of floating point constant. */
2993 rtx offset = gen_rtx (CONST, Pmode,
2994 gen_rtx (MINUS, Pmode, x,
2995 gen_rtx (SYMBOL_REF, Pmode,
2996 machopic_function_base_name ())));
2997 x = gen_rtx (LO_SUM, GET_MODE (x),
2998 gen_rtx (PLUS, Pmode, pic_offset_table_rtx,
2999 gen_rtx (HIGH, Pmode, offset)), offset);
3000 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3001 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3002 opnum, (enum reload_type)type);
3006 if (GET_CODE (x) == SYMBOL_REF
3007 && DEFAULT_ABI == ABI_DARWIN
3008 && !ALTIVEC_VECTOR_MODE (mode)
3009 && MACHO_DYNAMIC_NO_PIC_P)
3011 /* Darwin load of floating point constant. */
3012 x = gen_rtx (LO_SUM, GET_MODE (x),
3013 gen_rtx (HIGH, Pmode, x), x);
3014 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3015 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3016 opnum, (enum reload_type)type);
3022 && constant_pool_expr_p (x)
3023 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
3025 (x) = create_TOC_reference (x);
3033 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3034 that is a valid memory address for an instruction.
3035 The MODE argument is the machine mode for the MEM expression
3036 that wants to use this address.
3038 On the RS/6000, there are four valid address: a SYMBOL_REF that
3039 refers to a constant pool entry of an address (or the sum of it
3040 plus a constant), a short (16-bit signed) constant plus a register,
3041 the sum of two registers, or a register indirect, possibly with an
3042 auto-increment. For DFmode and DImode with a constant plus register,
3043 we must ensure that both words are addressable or PowerPC64 with offset
3046 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3047 32-bit DImode, TImode), indexed addressing cannot be used because
3048 adjacent memory cells are accessed by adding word-sized offsets
3049 during assembly output. */
3051 rs6000_legitimate_address (mode, x, reg_ok_strict)
3052 enum machine_mode mode;
3056 if (RS6000_SYMBOL_REF_TLS_P (x))
3058 if (legitimate_indirect_address_p (x, reg_ok_strict))
3060 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
3061 && !ALTIVEC_VECTOR_MODE (mode)
3062 && !SPE_VECTOR_MODE (mode)
3064 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
3066 if (legitimate_small_data_p (mode, x))
3068 if (legitimate_constant_pool_address_p (x))
3070 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3072 && GET_CODE (x) == PLUS
3073 && GET_CODE (XEXP (x, 0)) == REG
3074 && XEXP (x, 0) == virtual_stack_vars_rtx
3075 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3077 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
3080 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3082 || (mode != DFmode && mode != TFmode))
3083 && (TARGET_POWERPC64 || mode != DImode)
3084 && legitimate_indexed_address_p (x, reg_ok_strict))
3086 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
3091 /* Go to LABEL if ADDR (a legitimate address expression)
3092 has an effect that depends on the machine mode it is used for.
3094 On the RS/6000 this is true of all integral offsets (since AltiVec
3095 modes don't allow them) or is a pre-increment or decrement.
3097 ??? Except that due to conceptual problems in offsettable_address_p
3098 we can't really report the problems of integral offsets. So leave
3099 this assuming that the adjustable offset must be valid for the
3100 sub-words of a TFmode operand, which is what we had before. */
3103 rs6000_mode_dependent_address (addr)
3106 switch (GET_CODE (addr))
3109 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3111 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3112 return val + 12 + 0x8000 >= 0x10000;
3121 return TARGET_UPDATE;
3130 /* Try to output insns to set TARGET equal to the constant C if it can
3131 be done in less than N insns. Do all computations in MODE.
3132 Returns the place where the output has been placed if it can be
3133 done and the insns have been emitted. If it would take more than N
3134 insns, zero is returned and no insns and emitted. */
3137 rs6000_emit_set_const (dest, mode, source, n)
3139 enum machine_mode mode;
3140 int n ATTRIBUTE_UNUSED;
3142 rtx result, insn, set;
3143 HOST_WIDE_INT c0, c1;
3145 if (mode == QImode || mode == HImode)
3148 dest = gen_reg_rtx (mode);
3149 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3152 else if (mode == SImode)
3154 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3156 emit_insn (gen_rtx_SET (VOIDmode, result,
3157 GEN_INT (INTVAL (source)
3158 & (~ (HOST_WIDE_INT) 0xffff))));
3159 emit_insn (gen_rtx_SET (VOIDmode, dest,
3160 gen_rtx_IOR (SImode, result,
3161 GEN_INT (INTVAL (source) & 0xffff))));
3164 else if (mode == DImode)
3166 if (GET_CODE (source) == CONST_INT)
3168 c0 = INTVAL (source);
3171 else if (GET_CODE (source) == CONST_DOUBLE)
3173 #if HOST_BITS_PER_WIDE_INT >= 64
3174 c0 = CONST_DOUBLE_LOW (source);
3177 c0 = CONST_DOUBLE_LOW (source);
3178 c1 = CONST_DOUBLE_HIGH (source);
3184 result = rs6000_emit_set_long_const (dest, c0, c1);
3189 insn = get_last_insn ();
3190 set = single_set (insn);
3191 if (! CONSTANT_P (SET_SRC (set)))
3192 set_unique_reg_note (insn, REG_EQUAL, source);
3197 /* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3198 fall back to a straight forward decomposition. We do this to avoid
3199 exponential run times encountered when looking for longer sequences
3200 with rs6000_emit_set_const. */
3202 rs6000_emit_set_long_const (dest, c1, c2)
3204 HOST_WIDE_INT c1, c2;
3206 if (!TARGET_POWERPC64)
3208 rtx operand1, operand2;
3210 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3212 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3214 emit_move_insn (operand1, GEN_INT (c1));
3215 emit_move_insn (operand2, GEN_INT (c2));
3219 HOST_WIDE_INT ud1, ud2, ud3, ud4;
3222 ud2 = (c1 & 0xffff0000) >> 16;
3223 #if HOST_BITS_PER_WIDE_INT >= 64
3227 ud4 = (c2 & 0xffff0000) >> 16;
3229 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3230 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
3233 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
3235 emit_move_insn (dest, GEN_INT (ud1));
3238 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3239 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
3242 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3245 emit_move_insn (dest, GEN_INT (ud2 << 16));
3247 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3249 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3250 || (ud4 == 0 && ! (ud3 & 0x8000)))
3253 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3256 emit_move_insn (dest, GEN_INT (ud3 << 16));
3259 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3260 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3262 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3267 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3270 emit_move_insn (dest, GEN_INT (ud4 << 16));
3273 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
3275 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3277 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3278 GEN_INT (ud2 << 16)));
3280 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3286 /* Emit a move from SOURCE to DEST in mode MODE. */
3288 rs6000_emit_move (dest, source, mode)
3291 enum machine_mode mode;
3295 operands[1] = source;
3297 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3298 if (GET_CODE (operands[1]) == CONST_DOUBLE
3299 && ! FLOAT_MODE_P (mode)
3300 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3302 /* FIXME. This should never happen. */
3303 /* Since it seems that it does, do the safe thing and convert
3305 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
3307 if (GET_CODE (operands[1]) == CONST_DOUBLE
3308 && ! FLOAT_MODE_P (mode)
3309 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3310 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3311 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3312 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3315 /* Check if GCC is setting up a block move that will end up using FP
3316 registers as temporaries. We must make sure this is acceptable. */
3317 if (GET_CODE (operands[0]) == MEM
3318 && GET_CODE (operands[1]) == MEM
3320 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3321 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3322 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3323 ? 32 : MEM_ALIGN (operands[0])))
3324 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3326 : MEM_ALIGN (operands[1]))))
3327 && ! MEM_VOLATILE_P (operands [0])
3328 && ! MEM_VOLATILE_P (operands [1]))
3330 emit_move_insn (adjust_address (operands[0], SImode, 0),
3331 adjust_address (operands[1], SImode, 0));
3332 emit_move_insn (adjust_address (operands[0], SImode, 4),
3333 adjust_address (operands[1], SImode, 4));
3337 if (!no_new_pseudos)
3339 if (GET_CODE (operands[1]) == MEM && optimize > 0
3340 && (mode == QImode || mode == HImode || mode == SImode)
3341 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3343 rtx reg = gen_reg_rtx (word_mode);
3345 emit_insn (gen_rtx_SET (word_mode, reg,
3346 gen_rtx_ZERO_EXTEND (word_mode,
3348 operands[1] = gen_lowpart (mode, reg);
3350 if (GET_CODE (operands[0]) != REG)
3351 operands[1] = force_reg (mode, operands[1]);
3354 if (mode == SFmode && ! TARGET_POWERPC
3355 && TARGET_HARD_FLOAT && TARGET_FPRS
3356 && GET_CODE (operands[0]) == MEM)
3360 if (reload_in_progress || reload_completed)
3361 regnum = true_regnum (operands[1]);
3362 else if (GET_CODE (operands[1]) == REG)
3363 regnum = REGNO (operands[1]);
3367 /* If operands[1] is a register, on POWER it may have
3368 double-precision data in it, so truncate it to single
3370 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3373 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3374 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3375 operands[1] = newreg;
3379 /* Recognize the case where operand[1] is a reference to thread-local
3380 data and load its address to a register. */
3381 if (GET_CODE (operands[1]) == SYMBOL_REF)
3383 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3385 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3388 /* Handle the case where reload calls us with an invalid address. */
3389 if (reload_in_progress && mode == Pmode
3390 && (! general_operand (operands[1], mode)
3391 || ! nonimmediate_operand (operands[0], mode)))
3394 /* Handle the case of CONSTANT_P_RTX. */
3395 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3398 /* FIXME: In the long term, this switch statement should go away
3399 and be replaced by a sequence of tests based on things like
3405 if (CONSTANT_P (operands[1])
3406 && GET_CODE (operands[1]) != CONST_INT)
3407 operands[1] = force_const_mem (mode, operands[1]);
3413 if (CONSTANT_P (operands[1])
3414 && ! easy_fp_constant (operands[1], mode))
3415 operands[1] = force_const_mem (mode, operands[1]);
3426 if (CONSTANT_P (operands[1])
3427 && !easy_vector_constant (operands[1], mode))
3428 operands[1] = force_const_mem (mode, operands[1]);
3433 /* Use default pattern for address of ELF small data */
3436 && DEFAULT_ABI == ABI_V4
3437 && (GET_CODE (operands[1]) == SYMBOL_REF
3438 || GET_CODE (operands[1]) == CONST)
3439 && small_data_operand (operands[1], mode))
3441 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3445 if (DEFAULT_ABI == ABI_V4
3446 && mode == Pmode && mode == SImode
3447 && flag_pic == 1 && got_operand (operands[1], mode))
3449 emit_insn (gen_movsi_got (operands[0], operands[1]));
3453 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
3457 && CONSTANT_P (operands[1])
3458 && GET_CODE (operands[1]) != HIGH
3459 && GET_CODE (operands[1]) != CONST_INT)
3461 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
3463 /* If this is a function address on -mcall-aixdesc,
3464 convert it to the address of the descriptor. */
3465 if (DEFAULT_ABI == ABI_AIX