1 /* Subroutines used for MIPS code generation.
2 Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by A. Lichnewsky, lich@inria.inria.fr.
5 Changes by Michael Meissner, meissner@osf.org.
6 64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 Brendan Eich, brendan@microunity.com.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GCC is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING. If not, write to
23 the Free Software Foundation, 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
28 #include "coretypes.h"
33 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "conditions.h"
37 #include "insn-attr.h"
53 #include "target-def.h"
54 #include "integrate.h"
55 #include "langhooks.h"
56 #include "cfglayout.h"
57 #include "sched-int.h"
58 #include "tree-gimple.h"
60 /* True if X is an unspec wrapper around a SYMBOL_REF or LABEL_REF. */
61 #define UNSPEC_ADDRESS_P(X) \
62 (GET_CODE (X) == UNSPEC \
63 && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \
64 && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)
66 /* Extract the symbol or label from UNSPEC wrapper X. */
67 #define UNSPEC_ADDRESS(X) \
70 /* Extract the symbol type from UNSPEC wrapper X. */
71 #define UNSPEC_ADDRESS_TYPE(X) \
72 ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))
74 /* The maximum distance between the top of the stack frame and the
75 value $sp has when we save & restore registers.
77 Use a maximum gap of 0x100 in the mips16 case. We can then use
78 unextended instructions to save and restore registers, and to
79 allocate and deallocate the top part of the frame.
81 The value in the !mips16 case must be a SMALL_OPERAND and must
82 preserve the maximum stack alignment. */
83 #define MIPS_MAX_FIRST_STACK_STEP (TARGET_MIPS16 ? 0x100 : 0x7ff0)
85 /* True if INSN is a mips.md pattern or asm statement. */
86 #define USEFUL_INSN_P(INSN) \
88 && GET_CODE (PATTERN (INSN)) != USE \
89 && GET_CODE (PATTERN (INSN)) != CLOBBER \
90 && GET_CODE (PATTERN (INSN)) != ADDR_VEC \
91 && GET_CODE (PATTERN (INSN)) != ADDR_DIFF_VEC)
93 /* If INSN is a delayed branch sequence, return the first instruction
94 in the sequence, otherwise return INSN itself. */
95 #define SEQ_BEGIN(INSN) \
96 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
97 ? XVECEXP (PATTERN (INSN), 0, 0) \
100 /* Likewise for the last instruction in a delayed branch sequence. */
101 #define SEQ_END(INSN) \
102 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
103 ? XVECEXP (PATTERN (INSN), 0, XVECLEN (PATTERN (INSN), 0) - 1) \
106 /* Execute the following loop body with SUBINSN set to each instruction
107 between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */
108 #define FOR_EACH_SUBINSN(SUBINSN, INSN) \
109 for ((SUBINSN) = SEQ_BEGIN (INSN); \
110 (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \
111 (SUBINSN) = NEXT_INSN (SUBINSN))
113 /* Classifies an address.
116 A natural register + offset address. The register satisfies
117 mips_valid_base_register_p and the offset is a const_arith_operand.
120 A LO_SUM rtx. The first operand is a valid base register and
121 the second operand is a symbolic address.
124 A signed 16-bit constant address.
127 A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */
128 enum mips_address_type {
135 /* Classifies the prototype of a builtin function. */
136 enum mips_function_type
138 MIPS_V2SF_FTYPE_V2SF,
139 MIPS_V2SF_FTYPE_V2SF_V2SF,
140 MIPS_V2SF_FTYPE_V2SF_V2SF_INT,
141 MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF,
142 MIPS_V2SF_FTYPE_SF_SF,
143 MIPS_INT_FTYPE_V2SF_V2SF,
144 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF,
145 MIPS_INT_FTYPE_SF_SF,
146 MIPS_INT_FTYPE_DF_DF,
157 /* Specifies how a builtin function should be converted into rtl. */
158 enum mips_builtin_type
160 /* The builtin corresponds directly to an .md pattern. The return
161 value is mapped to operand 0 and the arguments are mapped to
162 operands 1 and above. */
165 /* The builtin corresponds to a comparison instruction followed by
166 a mips_cond_move_tf_ps pattern. The first two arguments are the
167 values to compare and the second two arguments are the vector
168 operands for the movt.ps or movf.ps instruction (in assembly order). */
172 /* The builtin corresponds to a V2SF comparison instruction. Operand 0
173 of this instruction is the result of the comparison, which has mode
174 CCV2 or CCV4. The function arguments are mapped to operands 1 and
175 above. The function's return value is an SImode boolean that is
176 true under the following conditions:
178 MIPS_BUILTIN_CMP_ANY: one of the registers is true
179 MIPS_BUILTIN_CMP_ALL: all of the registers are true
180 MIPS_BUILTIN_CMP_LOWER: the first register is true
181 MIPS_BUILTIN_CMP_UPPER: the second register is true. */
182 MIPS_BUILTIN_CMP_ANY,
183 MIPS_BUILTIN_CMP_ALL,
184 MIPS_BUILTIN_CMP_UPPER,
185 MIPS_BUILTIN_CMP_LOWER,
187 /* As above, but the instruction only sets a single $fcc register. */
188 MIPS_BUILTIN_CMP_SINGLE
191 /* Invokes MACRO (COND) for each c.cond.fmt condition. */
192 #define MIPS_FP_CONDITIONS(MACRO) \
210 /* Enumerates the codes above as MIPS_FP_COND_<X>. */
211 #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X
212 enum mips_fp_condition {
213 MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)
216 /* Index X provides the string representation of MIPS_FP_COND_<X>. */
217 #define STRINGIFY(X) #X
218 static const char *const mips_fp_conditions[] = {
219 MIPS_FP_CONDITIONS (STRINGIFY)
222 /* A function to save or store a register. The first argument is the
223 register and the second is the stack slot. */
224 typedef void (*mips_save_restore_fn) (rtx, rtx);
226 struct mips16_constant;
227 struct mips_arg_info;
228 struct mips_address_info;
229 struct mips_integer_op;
232 static enum mips_symbol_type mips_classify_symbol (rtx);
233 static void mips_split_const (rtx, rtx *, HOST_WIDE_INT *);
234 static bool mips_offset_within_object_p (rtx, HOST_WIDE_INT);
235 static bool mips_valid_base_register_p (rtx, enum machine_mode, int);
236 static bool mips_symbolic_address_p (enum mips_symbol_type, enum machine_mode);
237 static bool mips_classify_address (struct mips_address_info *, rtx,
238 enum machine_mode, int);
239 static bool mips_cannot_force_const_mem (rtx);
240 static int mips_symbol_insns (enum mips_symbol_type);
241 static bool mips16_unextended_reference_p (enum machine_mode mode, rtx, rtx);
242 static rtx mips_force_temporary (rtx, rtx);
243 static rtx mips_split_symbol (rtx, rtx);
244 static rtx mips_unspec_offset_high (rtx, rtx, rtx, enum mips_symbol_type);
245 static rtx mips_add_offset (rtx, rtx, HOST_WIDE_INT);
246 static unsigned int mips_build_shift (struct mips_integer_op *, HOST_WIDE_INT);
247 static unsigned int mips_build_lower (struct mips_integer_op *,
248 unsigned HOST_WIDE_INT);
249 static unsigned int mips_build_integer (struct mips_integer_op *,
250 unsigned HOST_WIDE_INT);
251 static void mips_move_integer (rtx, unsigned HOST_WIDE_INT);
252 static void mips_legitimize_const_move (enum machine_mode, rtx, rtx);
253 static int m16_check_op (rtx, int, int, int);
254 static bool mips_rtx_costs (rtx, int, int, int *);
255 static int mips_address_cost (rtx);
256 static void mips_emit_compare (enum rtx_code *, rtx *, rtx *, bool);
257 static void mips_load_call_address (rtx, rtx, int);
258 static bool mips_function_ok_for_sibcall (tree, tree);
259 static void mips_block_move_straight (rtx, rtx, HOST_WIDE_INT);
260 static void mips_adjust_block_mem (rtx, HOST_WIDE_INT, rtx *, rtx *);
261 static void mips_block_move_loop (rtx, rtx, HOST_WIDE_INT);
262 static void mips_arg_info (const CUMULATIVE_ARGS *, enum machine_mode,
263 tree, int, struct mips_arg_info *);
264 static bool mips_get_unaligned_mem (rtx *, unsigned int, int, rtx *, rtx *);
265 static void mips_set_architecture (const struct mips_cpu_info *);
266 static void mips_set_tune (const struct mips_cpu_info *);
267 static bool mips_handle_option (size_t, const char *, int);
268 static struct machine_function *mips_init_machine_status (void);
269 static void print_operand_reloc (FILE *, rtx, const char **);
271 static void irix_output_external_libcall (rtx);
273 static void mips_file_start (void);
274 static void mips_file_end (void);
275 static bool mips_rewrite_small_data_p (rtx);
276 static int mips_small_data_pattern_1 (rtx *, void *);
277 static int mips_rewrite_small_data_1 (rtx *, void *);
278 static bool mips_function_has_gp_insn (void);
279 static unsigned int mips_global_pointer (void);
280 static bool mips_save_reg_p (unsigned int);
281 static void mips_save_restore_reg (enum machine_mode, int, HOST_WIDE_INT,
282 mips_save_restore_fn);
283 static void mips_for_each_saved_reg (HOST_WIDE_INT, mips_save_restore_fn);
284 static void mips_output_cplocal (void);
285 static void mips_emit_loadgp (void);
286 static void mips_output_function_prologue (FILE *, HOST_WIDE_INT);
287 static void mips_set_frame_expr (rtx);
288 static rtx mips_frame_set (rtx, rtx);
289 static void mips_save_reg (rtx, rtx);
290 static void mips_output_function_epilogue (FILE *, HOST_WIDE_INT);
291 static void mips_restore_reg (rtx, rtx);
292 static void mips_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
293 HOST_WIDE_INT, tree);
294 static int symbolic_expression_p (rtx);
295 static void mips_select_rtx_section (enum machine_mode, rtx,
296 unsigned HOST_WIDE_INT);
297 static void mips_function_rodata_section (tree);
298 static bool mips_in_small_data_p (tree);
299 static int mips_fpr_return_fields (tree, tree *);
300 static bool mips_return_in_msb (tree);
301 static rtx mips_return_fpr_pair (enum machine_mode mode,
302 enum machine_mode mode1, HOST_WIDE_INT,
303 enum machine_mode mode2, HOST_WIDE_INT);
304 static rtx mips16_gp_pseudo_reg (void);
305 static void mips16_fp_args (FILE *, int, int);
306 static void build_mips16_function_stub (FILE *);
307 static rtx dump_constants_1 (enum machine_mode, rtx, rtx);
308 static void dump_constants (struct mips16_constant *, rtx);
309 static int mips16_insn_length (rtx);
310 static int mips16_rewrite_pool_refs (rtx *, void *);
311 static void mips16_lay_out_constants (void);
312 static void mips_sim_reset (struct mips_sim *);
313 static void mips_sim_init (struct mips_sim *, state_t);
314 static void mips_sim_next_cycle (struct mips_sim *);
315 static void mips_sim_wait_reg (struct mips_sim *, rtx, rtx);
316 static int mips_sim_wait_regs_2 (rtx *, void *);
317 static void mips_sim_wait_regs_1 (rtx *, void *);
318 static void mips_sim_wait_regs (struct mips_sim *, rtx);
319 static void mips_sim_wait_units (struct mips_sim *, rtx);
320 static void mips_sim_wait_insn (struct mips_sim *, rtx);
321 static void mips_sim_record_set (rtx, rtx, void *);
322 static void mips_sim_issue_insn (struct mips_sim *, rtx);
323 static void mips_sim_issue_nop (struct mips_sim *);
324 static void mips_sim_finish_insn (struct mips_sim *, rtx);
325 static void vr4130_avoid_branch_rt_conflict (rtx);
326 static void vr4130_align_insns (void);
327 static void mips_avoid_hazard (rtx, rtx, int *, rtx *, rtx);
328 static void mips_avoid_hazards (void);
329 static void mips_reorg (void);
330 static bool mips_strict_matching_cpu_name_p (const char *, const char *);
331 static bool mips_matching_cpu_name_p (const char *, const char *);
332 static const struct mips_cpu_info *mips_parse_cpu (const char *);
333 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
334 static bool mips_return_in_memory (tree, tree);
335 static bool mips_strict_argument_naming (CUMULATIVE_ARGS *);
336 static void mips_macc_chains_record (rtx);
337 static void mips_macc_chains_reorder (rtx *, int);
338 static void vr4130_true_reg_dependence_p_1 (rtx, rtx, void *);
339 static bool vr4130_true_reg_dependence_p (rtx);
340 static bool vr4130_swap_insns_p (rtx, rtx);
341 static void vr4130_reorder (rtx *, int);
342 static void mips_promote_ready (rtx *, int, int);
343 static int mips_sched_reorder (FILE *, int, rtx *, int *, int);
344 static int mips_variable_issue (FILE *, int, rtx, int);
345 static int mips_adjust_cost (rtx, rtx, rtx, int);
346 static int mips_issue_rate (void);
347 static int mips_multipass_dfa_lookahead (void);
348 static void mips_init_libfuncs (void);
349 static void mips_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
351 static tree mips_build_builtin_va_list (void);
352 static tree mips_gimplify_va_arg_expr (tree, tree, tree *, tree *);
353 static bool mips_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode mode,
355 static bool mips_callee_copies (CUMULATIVE_ARGS *, enum machine_mode mode,
357 static int mips_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode mode,
359 static bool mips_valid_pointer_mode (enum machine_mode);
360 static bool mips_vector_mode_supported_p (enum machine_mode);
361 static rtx mips_prepare_builtin_arg (enum insn_code, unsigned int, tree *);
362 static rtx mips_prepare_builtin_target (enum insn_code, unsigned int, rtx);
363 static rtx mips_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
364 static void mips_init_builtins (void);
365 static rtx mips_expand_builtin_direct (enum insn_code, rtx, tree);
366 static rtx mips_expand_builtin_movtf (enum mips_builtin_type,
367 enum insn_code, enum mips_fp_condition,
369 static rtx mips_expand_builtin_compare (enum mips_builtin_type,
370 enum insn_code, enum mips_fp_condition,
373 /* Structure to be filled in by compute_frame_size with register
374 save masks, and offsets for the current function. */
376 struct mips_frame_info GTY(())
378 HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up */
379 HOST_WIDE_INT var_size; /* # bytes that variables take up */
380 HOST_WIDE_INT args_size; /* # bytes that outgoing arguments take up */
381 HOST_WIDE_INT cprestore_size; /* # bytes that the .cprestore slot takes up */
382 HOST_WIDE_INT gp_reg_size; /* # bytes needed to store gp regs */
383 HOST_WIDE_INT fp_reg_size; /* # bytes needed to store fp regs */
384 unsigned int mask; /* mask of saved gp registers */
385 unsigned int fmask; /* mask of saved fp registers */
386 HOST_WIDE_INT gp_save_offset; /* offset from vfp to store gp registers */
387 HOST_WIDE_INT fp_save_offset; /* offset from vfp to store fp registers */
388 HOST_WIDE_INT gp_sp_offset; /* offset from new sp to store gp registers */
389 HOST_WIDE_INT fp_sp_offset; /* offset from new sp to store fp registers */
390 bool initialized; /* true if frame size already calculated */
391 int num_gp; /* number of gp registers saved */
392 int num_fp; /* number of fp registers saved */
395 struct machine_function GTY(()) {
396 /* Pseudo-reg holding the value of $28 in a mips16 function which
397 refers to GP relative global variables. */
398 rtx mips16_gp_pseudo_rtx;
400 /* Current frame information, calculated by compute_frame_size. */
401 struct mips_frame_info frame;
403 /* The register to use as the global pointer within this function. */
404 unsigned int global_pointer;
406 /* True if mips_adjust_insn_length should ignore an instruction's
408 bool ignore_hazard_length_p;
410 /* True if the whole function is suitable for .set noreorder and
412 bool all_noreorder_p;
414 /* True if the function is known to have an instruction that needs $gp. */
418 /* Information about a single argument. */
421 /* True if the argument is passed in a floating-point register, or
422 would have been if we hadn't run out of registers. */
425 /* The number of words passed in registers, rounded up. */
426 unsigned int reg_words;
428 /* For EABI, the offset of the first register from GP_ARG_FIRST or
429 FP_ARG_FIRST. For other ABIs, the offset of the first register from
430 the start of the ABI's argument structure (see the CUMULATIVE_ARGS
431 comment for details).
433 The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely
435 unsigned int reg_offset;
437 /* The number of words that must be passed on the stack, rounded up. */
438 unsigned int stack_words;
440 /* The offset from the start of the stack overflow area of the argument's
441 first stack word. Only meaningful when STACK_WORDS is nonzero. */
442 unsigned int stack_offset;
446 /* Information about an address described by mips_address_type.
452 REG is the base register and OFFSET is the constant offset.
455 REG is the register that contains the high part of the address,
456 OFFSET is the symbolic address being referenced and SYMBOL_TYPE
457 is the type of OFFSET's symbol.
460 SYMBOL_TYPE is the type of symbol being referenced. */
462 struct mips_address_info
464 enum mips_address_type type;
467 enum mips_symbol_type symbol_type;
471 /* One stage in a constant building sequence. These sequences have
475 A = A CODE[1] VALUE[1]
476 A = A CODE[2] VALUE[2]
479 where A is an accumulator, each CODE[i] is a binary rtl operation
480 and each VALUE[i] is a constant integer. */
481 struct mips_integer_op {
483 unsigned HOST_WIDE_INT value;
487 /* The largest number of operations needed to load an integer constant.
488 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
489 When the lowest bit is clear, we can try, but reject a sequence with
490 an extra SLL at the end. */
491 #define MIPS_MAX_INTEGER_OPS 7
494 /* Global variables for machine-dependent things. */
496 /* Threshold for data being put into the small data/bss area, instead
497 of the normal data area. */
498 int mips_section_threshold = -1;
500 /* Count the number of .file directives, so that .loc is up to date. */
501 int num_source_filenames = 0;
503 /* Count the number of sdb related labels are generated (to find block
504 start and end boundaries). */
505 int sdb_label_count = 0;
507 /* Next label # for each statement for Silicon Graphics IRIS systems. */
510 /* Linked list of all externals that are to be emitted when optimizing
511 for the global pointer if they haven't been declared by the end of
512 the program with an appropriate .comm or initialization. */
514 struct extern_list GTY (())
516 struct extern_list *next; /* next external */
517 const char *name; /* name of the external */
518 int size; /* size in bytes */
521 static GTY (()) struct extern_list *extern_head = 0;
523 /* Name of the file containing the current function. */
524 const char *current_function_file = "";
526 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
532 /* The next branch instruction is a branch likely, not branch normal. */
533 int mips_branch_likely;
535 /* The operands passed to the last cmpMM expander. */
538 /* The target cpu for code generation. */
539 enum processor_type mips_arch;
540 const struct mips_cpu_info *mips_arch_info;
542 /* The target cpu for optimization and scheduling. */
543 enum processor_type mips_tune;
544 const struct mips_cpu_info *mips_tune_info;
546 /* Which instruction set architecture to use. */
549 /* Which ABI to use. */
550 int mips_abi = MIPS_ABI_DEFAULT;
552 /* Whether we are generating mips16 hard float code. In mips16 mode
553 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
554 -msoft-float was not specified by the user, which means that we
555 should arrange to call mips32 hard floating point code. */
556 int mips16_hard_float;
558 /* The arguments passed to -march and -mtune. */
559 static const char *mips_arch_string;
560 static const char *mips_tune_string;
562 /* The architecture selected by -mipsN. */
563 static const struct mips_cpu_info *mips_isa_info;
565 const char *mips_cache_flush_func = CACHE_FLUSH_FUNC;
567 /* If TRUE, we split addresses into their high and low parts in the RTL. */
568 int mips_split_addresses;
570 /* Mode used for saving/restoring general purpose registers. */
571 static enum machine_mode gpr_mode;
573 /* Array giving truth value on whether or not a given hard register
574 can support a given mode. */
575 char mips_hard_regno_mode_ok[(int)MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
577 /* List of all MIPS punctuation characters used by print_operand. */
578 char mips_print_operand_punct[256];
580 /* Map GCC register number to debugger register number. */
581 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
583 /* A copy of the original flag_delayed_branch: see override_options. */
584 static int mips_flag_delayed_branch;
586 static GTY (()) int mips_output_filename_first_time = 1;
588 /* mips_split_p[X] is true if symbols of type X can be split by
589 mips_split_symbol(). */
590 static bool mips_split_p[NUM_SYMBOL_TYPES];
592 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
593 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
594 if they are matched by a special .md file pattern. */
595 static const char *mips_lo_relocs[NUM_SYMBOL_TYPES];
597 /* Likewise for HIGHs. */
598 static const char *mips_hi_relocs[NUM_SYMBOL_TYPES];
600 /* Map hard register number to register class */
601 const enum reg_class mips_regno_to_class[] =
603 LEA_REGS, LEA_REGS, M16_NA_REGS, V1_REG,
604 M16_REGS, M16_REGS, M16_REGS, M16_REGS,
605 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
606 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
607 M16_NA_REGS, M16_NA_REGS, LEA_REGS, LEA_REGS,
608 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
609 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
610 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
611 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
612 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
613 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
614 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
615 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
616 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
617 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
618 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
619 HI_REG, LO_REG, NO_REGS, ST_REGS,
620 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
621 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
622 NO_REGS, ALL_REGS, ALL_REGS, NO_REGS,
623 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
624 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
625 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
626 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
627 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
628 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
629 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
630 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
631 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
632 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
633 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
634 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
635 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
636 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
637 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
638 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
639 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
640 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
641 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
642 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
643 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
644 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
645 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
646 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS
649 /* Map register constraint character to register class. */
650 enum reg_class mips_char_to_class[256];
652 /* A table describing all the processors gcc knows about. Names are
653 matched in the order listed. The first mention of an ISA level is
654 taken as the canonical name for that ISA.
656 To ease comparison, please keep this table in the same order as
657 gas's mips_cpu_info_table[]. */
658 const struct mips_cpu_info mips_cpu_info_table[] = {
659 /* Entries for generic ISAs */
660 { "mips1", PROCESSOR_R3000, 1 },
661 { "mips2", PROCESSOR_R6000, 2 },
662 { "mips3", PROCESSOR_R4000, 3 },
663 { "mips4", PROCESSOR_R8000, 4 },
664 { "mips32", PROCESSOR_4KC, 32 },
665 { "mips32r2", PROCESSOR_M4K, 33 },
666 { "mips64", PROCESSOR_5KC, 64 },
669 { "r3000", PROCESSOR_R3000, 1 },
670 { "r2000", PROCESSOR_R3000, 1 }, /* = r3000 */
671 { "r3900", PROCESSOR_R3900, 1 },
674 { "r6000", PROCESSOR_R6000, 2 },
677 { "r4000", PROCESSOR_R4000, 3 },
678 { "vr4100", PROCESSOR_R4100, 3 },
679 { "vr4111", PROCESSOR_R4111, 3 },
680 { "vr4120", PROCESSOR_R4120, 3 },
681 { "vr4130", PROCESSOR_R4130, 3 },
682 { "vr4300", PROCESSOR_R4300, 3 },
683 { "r4400", PROCESSOR_R4000, 3 }, /* = r4000 */
684 { "r4600", PROCESSOR_R4600, 3 },
685 { "orion", PROCESSOR_R4600, 3 }, /* = r4600 */
686 { "r4650", PROCESSOR_R4650, 3 },
689 { "r8000", PROCESSOR_R8000, 4 },
690 { "vr5000", PROCESSOR_R5000, 4 },
691 { "vr5400", PROCESSOR_R5400, 4 },
692 { "vr5500", PROCESSOR_R5500, 4 },
693 { "rm7000", PROCESSOR_R7000, 4 },
694 { "rm9000", PROCESSOR_R9000, 4 },
697 { "4kc", PROCESSOR_4KC, 32 },
698 { "4kp", PROCESSOR_4KC, 32 }, /* = 4kc */
700 /* MIPS32 Release 2 */
701 { "m4k", PROCESSOR_M4K, 33 },
702 { "24k", PROCESSOR_24K, 33 },
703 { "24kc", PROCESSOR_24K, 33 }, /* 24K no FPU */
704 { "24kf", PROCESSOR_24K, 33 }, /* 24K 1:2 FPU */
705 { "24kx", PROCESSOR_24KX, 33 }, /* 24K 1:1 FPU */
708 { "5kc", PROCESSOR_5KC, 64 },
709 { "20kc", PROCESSOR_20KC, 64 },
710 { "sb1", PROCESSOR_SB1, 64 },
711 { "sr71000", PROCESSOR_SR71000, 64 },
717 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
718 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
719 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
722 /* Initialize the GCC target structure. */
723 #undef TARGET_ASM_ALIGNED_HI_OP
724 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
725 #undef TARGET_ASM_ALIGNED_SI_OP
726 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
727 #undef TARGET_ASM_ALIGNED_DI_OP
728 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
730 #undef TARGET_ASM_FUNCTION_PROLOGUE
731 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
732 #undef TARGET_ASM_FUNCTION_EPILOGUE
733 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
734 #undef TARGET_ASM_SELECT_RTX_SECTION
735 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
736 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
737 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
739 #undef TARGET_SCHED_REORDER
740 #define TARGET_SCHED_REORDER mips_sched_reorder
741 #undef TARGET_SCHED_VARIABLE_ISSUE
742 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
743 #undef TARGET_SCHED_ADJUST_COST
744 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
745 #undef TARGET_SCHED_ISSUE_RATE
746 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
747 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
748 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
749 mips_multipass_dfa_lookahead
751 #undef TARGET_DEFAULT_TARGET_FLAGS
752 #define TARGET_DEFAULT_TARGET_FLAGS \
754 | TARGET_CPU_DEFAULT \
755 | TARGET_ENDIAN_DEFAULT \
756 | TARGET_FP_EXCEPTIONS_DEFAULT \
757 | MASK_CHECK_ZERO_DIV \
759 #undef TARGET_HANDLE_OPTION
760 #define TARGET_HANDLE_OPTION mips_handle_option
762 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
763 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
765 #undef TARGET_VALID_POINTER_MODE
766 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
767 #undef TARGET_RTX_COSTS
768 #define TARGET_RTX_COSTS mips_rtx_costs
769 #undef TARGET_ADDRESS_COST
770 #define TARGET_ADDRESS_COST mips_address_cost
772 #undef TARGET_IN_SMALL_DATA_P
773 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
775 #undef TARGET_MACHINE_DEPENDENT_REORG
776 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
778 #undef TARGET_ASM_FILE_START
779 #undef TARGET_ASM_FILE_END
780 #define TARGET_ASM_FILE_START mips_file_start
781 #define TARGET_ASM_FILE_END mips_file_end
782 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
783 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
785 #undef TARGET_INIT_LIBFUNCS
786 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
788 #undef TARGET_BUILD_BUILTIN_VA_LIST
789 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
790 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
791 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
793 #undef TARGET_PROMOTE_FUNCTION_ARGS
794 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
795 #undef TARGET_PROMOTE_FUNCTION_RETURN
796 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
797 #undef TARGET_PROMOTE_PROTOTYPES
798 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
800 #undef TARGET_RETURN_IN_MEMORY
801 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
802 #undef TARGET_RETURN_IN_MSB
803 #define TARGET_RETURN_IN_MSB mips_return_in_msb
805 #undef TARGET_ASM_OUTPUT_MI_THUNK
806 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
807 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
808 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
810 #undef TARGET_SETUP_INCOMING_VARARGS
811 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
812 #undef TARGET_STRICT_ARGUMENT_NAMING
813 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
814 #undef TARGET_MUST_PASS_IN_STACK
815 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
816 #undef TARGET_PASS_BY_REFERENCE
817 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
818 #undef TARGET_CALLEE_COPIES
819 #define TARGET_CALLEE_COPIES mips_callee_copies
820 #undef TARGET_ARG_PARTIAL_BYTES
821 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
823 #undef TARGET_VECTOR_MODE_SUPPORTED_P
824 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
826 #undef TARGET_INIT_BUILTINS
827 #define TARGET_INIT_BUILTINS mips_init_builtins
828 #undef TARGET_EXPAND_BUILTIN
829 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
831 #undef TARGET_HAVE_TLS
832 #define TARGET_HAVE_TLS HAVE_AS_TLS
834 #undef TARGET_CANNOT_FORCE_CONST_MEM
835 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
837 struct gcc_target targetm = TARGET_INITIALIZER;
839 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
841 static enum mips_symbol_type
842 mips_classify_symbol (rtx x)
844 if (GET_CODE (x) == LABEL_REF)
847 return SYMBOL_CONSTANT_POOL;
849 return SYMBOL_GOT_LOCAL;
850 return SYMBOL_GENERAL;
853 gcc_assert (GET_CODE (x) == SYMBOL_REF);
855 if (SYMBOL_REF_TLS_MODEL (x))
858 if (CONSTANT_POOL_ADDRESS_P (x))
861 return SYMBOL_CONSTANT_POOL;
864 return SYMBOL_GOT_LOCAL;
866 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
867 return SYMBOL_SMALL_DATA;
869 return SYMBOL_GENERAL;
872 if (SYMBOL_REF_SMALL_P (x))
873 return SYMBOL_SMALL_DATA;
877 if (SYMBOL_REF_DECL (x) == 0)
878 return SYMBOL_REF_LOCAL_P (x) ? SYMBOL_GOT_LOCAL : SYMBOL_GOT_GLOBAL;
880 /* There are three cases to consider:
882 - o32 PIC (either with or without explicit relocs)
883 - n32/n64 PIC without explicit relocs
884 - n32/n64 PIC with explicit relocs
886 In the first case, both local and global accesses will use an
887 R_MIPS_GOT16 relocation. We must correctly predict which of
888 the two semantics (local or global) the assembler and linker
889 will apply. The choice doesn't depend on the symbol's
890 visibility, so we deliberately ignore decl_visibility and
893 In the second case, the assembler will not use R_MIPS_GOT16
894 relocations, but it chooses between local and global accesses
895 in the same way as for o32 PIC.
897 In the third case we have more freedom since both forms of
898 access will work for any kind of symbol. However, there seems
899 little point in doing things differently. */
900 if (DECL_P (SYMBOL_REF_DECL (x)) && TREE_PUBLIC (SYMBOL_REF_DECL (x)))
901 return SYMBOL_GOT_GLOBAL;
903 return SYMBOL_GOT_LOCAL;
906 return SYMBOL_GENERAL;
910 /* Split X into a base and a constant offset, storing them in *BASE
911 and *OFFSET respectively. */
914 mips_split_const (rtx x, rtx *base, HOST_WIDE_INT *offset)
918 if (GET_CODE (x) == CONST)
921 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
923 *offset += INTVAL (XEXP (x, 1));
930 /* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
931 to the same object as SYMBOL. */
934 mips_offset_within_object_p (rtx symbol, HOST_WIDE_INT offset)
936 if (GET_CODE (symbol) != SYMBOL_REF)
939 if (CONSTANT_POOL_ADDRESS_P (symbol)
941 && offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
944 if (SYMBOL_REF_DECL (symbol) != 0
946 && offset < int_size_in_bytes (TREE_TYPE (SYMBOL_REF_DECL (symbol))))
953 /* Return true if X is a symbolic constant that can be calculated in
954 the same way as a bare symbol. If it is, store the type of the
955 symbol in *SYMBOL_TYPE. */
958 mips_symbolic_constant_p (rtx x, enum mips_symbol_type *symbol_type)
960 HOST_WIDE_INT offset;
962 mips_split_const (x, &x, &offset);
963 if (UNSPEC_ADDRESS_P (x))
964 *symbol_type = UNSPEC_ADDRESS_TYPE (x);
965 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
967 *symbol_type = mips_classify_symbol (x);
968 if (*symbol_type == SYMBOL_TLS)
977 /* Check whether a nonzero offset is valid for the underlying
979 switch (*symbol_type)
985 /* If the target has 64-bit pointers and the object file only
986 supports 32-bit symbols, the values of those symbols will be
987 sign-extended. In this case we can't allow an arbitrary offset
988 in case the 32-bit value X + OFFSET has a different sign from X. */
989 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
990 return mips_offset_within_object_p (x, offset);
992 /* In other cases the relocations can handle any offset. */
995 case SYMBOL_CONSTANT_POOL:
996 /* Allow constant pool references to be converted to LABEL+CONSTANT.
997 In this case, we no longer have access to the underlying constant,
998 but the original symbol-based access was known to be valid. */
999 if (GET_CODE (x) == LABEL_REF)
1004 case SYMBOL_SMALL_DATA:
1005 /* Make sure that the offset refers to something within the
1006 underlying object. This should guarantee that the final
1007 PC- or GP-relative offset is within the 16-bit limit. */
1008 return mips_offset_within_object_p (x, offset);
1010 case SYMBOL_GOT_LOCAL:
1011 case SYMBOL_GOTOFF_PAGE:
1012 /* The linker should provide enough local GOT entries for a
1013 16-bit offset. Larger offsets may lead to GOT overflow. */
1014 return SMALL_OPERAND (offset);
1016 case SYMBOL_GOT_GLOBAL:
1017 case SYMBOL_GOTOFF_GLOBAL:
1018 case SYMBOL_GOTOFF_CALL:
1019 case SYMBOL_GOTOFF_LOADGP:
1024 case SYMBOL_GOTTPREL:
1032 /* Return true if X is a symbolic constant whose value is not split
1033 into separate relocations. */
1036 mips_atomic_symbolic_constant_p (rtx x)
1038 enum mips_symbol_type type;
1039 return mips_symbolic_constant_p (x, &type) && !mips_split_p[type];
1043 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1046 mips_regno_mode_ok_for_base_p (int regno, enum machine_mode mode, int strict)
1048 if (regno >= FIRST_PSEUDO_REGISTER)
1052 regno = reg_renumber[regno];
1055 /* These fake registers will be eliminated to either the stack or
1056 hard frame pointer, both of which are usually valid base registers.
1057 Reload deals with the cases where the eliminated form isn't valid. */
1058 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
1061 /* In mips16 mode, the stack pointer can only address word and doubleword
1062 values, nothing smaller. There are two problems here:
1064 (a) Instantiating virtual registers can introduce new uses of the
1065 stack pointer. If these virtual registers are valid addresses,
1066 the stack pointer should be too.
1068 (b) Most uses of the stack pointer are not made explicit until
1069 FRAME_POINTER_REGNUM and ARG_POINTER_REGNUM have been eliminated.
1070 We don't know until that stage whether we'll be eliminating to the
1071 stack pointer (which needs the restriction) or the hard frame
1072 pointer (which doesn't).
1074 All in all, it seems more consistent to only enforce this restriction
1075 during and after reload. */
1076 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
1077 return !strict || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1079 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
1083 /* Return true if X is a valid base register for the given mode.
1084 Allow only hard registers if STRICT. */
1087 mips_valid_base_register_p (rtx x, enum machine_mode mode, int strict)
1089 if (!strict && GET_CODE (x) == SUBREG)
1093 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict));
1097 /* Return true if symbols of type SYMBOL_TYPE can directly address a value
1098 with mode MODE. This is used for both symbolic and LO_SUM addresses. */
1101 mips_symbolic_address_p (enum mips_symbol_type symbol_type,
1102 enum machine_mode mode)
1104 switch (symbol_type)
1106 case SYMBOL_GENERAL:
1107 return !TARGET_MIPS16;
1109 case SYMBOL_SMALL_DATA:
1112 case SYMBOL_CONSTANT_POOL:
1113 /* PC-relative addressing is only available for lw and ld. */
1114 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1116 case SYMBOL_GOT_LOCAL:
1119 case SYMBOL_GOT_GLOBAL:
1120 /* The address will have to be loaded from the GOT first. */
1127 case SYMBOL_GOTTPREL:
1131 case SYMBOL_GOTOFF_PAGE:
1132 case SYMBOL_GOTOFF_GLOBAL:
1133 case SYMBOL_GOTOFF_CALL:
1134 case SYMBOL_GOTOFF_LOADGP:
1135 case SYMBOL_64_HIGH:
1144 /* Return true if X is a valid address for machine mode MODE. If it is,
1145 fill in INFO appropriately. STRICT is true if we should only accept
1146 hard base registers. */
1149 mips_classify_address (struct mips_address_info *info, rtx x,
1150 enum machine_mode mode, int strict)
1152 switch (GET_CODE (x))
1156 info->type = ADDRESS_REG;
1158 info->offset = const0_rtx;
1159 return mips_valid_base_register_p (info->reg, mode, strict);
1162 info->type = ADDRESS_REG;
1163 info->reg = XEXP (x, 0);
1164 info->offset = XEXP (x, 1);
1165 return (mips_valid_base_register_p (info->reg, mode, strict)
1166 && const_arith_operand (info->offset, VOIDmode));
1169 info->type = ADDRESS_LO_SUM;
1170 info->reg = XEXP (x, 0);
1171 info->offset = XEXP (x, 1);
1172 return (mips_valid_base_register_p (info->reg, mode, strict)
1173 && mips_symbolic_constant_p (info->offset, &info->symbol_type)
1174 && mips_symbolic_address_p (info->symbol_type, mode)
1175 && mips_lo_relocs[info->symbol_type] != 0);
1178 /* Small-integer addresses don't occur very often, but they
1179 are legitimate if $0 is a valid base register. */
1180 info->type = ADDRESS_CONST_INT;
1181 return !TARGET_MIPS16 && SMALL_INT (x);
1186 info->type = ADDRESS_SYMBOLIC;
1187 return (mips_symbolic_constant_p (x, &info->symbol_type)
1188 && mips_symbolic_address_p (info->symbol_type, mode)
1189 && !mips_split_p[info->symbol_type]);
1196 /* Return true if X is a thread-local symbol. */
1199 mips_tls_operand_p (rtx x)
1201 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
1204 /* Return true if X can not be forced into a constant pool. */
1207 mips_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1209 return mips_tls_operand_p (*x);
1212 /* Return true if X can not be forced into a constant pool. */
1215 mips_cannot_force_const_mem (rtx x)
1217 if (! TARGET_HAVE_TLS)
1220 return for_each_rtx (&x, &mips_tls_symbol_ref_1, 0);
1223 /* Return the number of instructions needed to load a symbol of the
1224 given type into a register. If valid in an address, the same number
1225 of instructions are needed for loads and stores. Treat extended
1226 mips16 instructions as two instructions. */
1229 mips_symbol_insns (enum mips_symbol_type type)
1233 case SYMBOL_GENERAL:
1234 /* In mips16 code, general symbols must be fetched from the
1239 /* When using 64-bit symbols, we need 5 preparatory instructions,
1242 lui $at,%highest(symbol)
1243 daddiu $at,$at,%higher(symbol)
1245 daddiu $at,$at,%hi(symbol)
1248 The final address is then $at + %lo(symbol). With 32-bit
1249 symbols we just need a preparatory lui. */
1250 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1252 case SYMBOL_SMALL_DATA:
1255 case SYMBOL_CONSTANT_POOL:
1256 /* This case is for mips16 only. Assume we'll need an
1257 extended instruction. */
1260 case SYMBOL_GOT_LOCAL:
1261 case SYMBOL_GOT_GLOBAL:
1262 /* Unless -funit-at-a-time is in effect, we can't be sure whether
1263 the local/global classification is accurate. See override_options
1266 The worst cases are:
1268 (1) For local symbols when generating o32 or o64 code. The assembler
1274 ...and the final address will be $at + %lo(symbol).
1276 (2) For global symbols when -mxgot. The assembler will use:
1278 lui $at,%got_hi(symbol)
1281 ...and the final address will be $at + %got_lo(symbol). */
1284 case SYMBOL_GOTOFF_PAGE:
1285 case SYMBOL_GOTOFF_GLOBAL:
1286 case SYMBOL_GOTOFF_CALL:
1287 case SYMBOL_GOTOFF_LOADGP:
1288 case SYMBOL_64_HIGH:
1294 case SYMBOL_GOTTPREL:
1296 /* Check whether the offset is a 16- or 32-bit value. */
1297 return mips_split_p[type] ? 2 : 1;
1300 /* We don't treat a bare TLS symbol as a constant. */
1306 /* Return true if X is a legitimate $sp-based address for mode MDOE. */
1309 mips_stack_address_p (rtx x, enum machine_mode mode)
1311 struct mips_address_info addr;
1313 return (mips_classify_address (&addr, x, mode, false)
1314 && addr.type == ADDRESS_REG
1315 && addr.reg == stack_pointer_rtx);
1318 /* Return true if a value at OFFSET bytes from BASE can be accessed
1319 using an unextended mips16 instruction. MODE is the mode of the
1322 Usually the offset in an unextended instruction is a 5-bit field.
1323 The offset is unsigned and shifted left once for HIs, twice
1324 for SIs, and so on. An exception is SImode accesses off the
1325 stack pointer, which have an 8-bit immediate field. */
1328 mips16_unextended_reference_p (enum machine_mode mode, rtx base, rtx offset)
1331 && GET_CODE (offset) == CONST_INT
1332 && INTVAL (offset) >= 0
1333 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1335 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1336 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1337 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1343 /* Return the number of instructions needed to load or store a value
1344 of mode MODE at X. Return 0 if X isn't valid for MODE.
1346 For mips16 code, count extended instructions as two instructions. */
1349 mips_address_insns (rtx x, enum machine_mode mode)
1351 struct mips_address_info addr;
1354 if (mode == BLKmode)
1355 /* BLKmode is used for single unaligned loads and stores. */
1358 /* Each word of a multi-word value will be accessed individually. */
1359 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1361 if (mips_classify_address (&addr, x, mode, false))
1366 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1370 case ADDRESS_LO_SUM:
1371 return (TARGET_MIPS16 ? factor * 2 : factor);
1373 case ADDRESS_CONST_INT:
1376 case ADDRESS_SYMBOLIC:
1377 return factor * mips_symbol_insns (addr.symbol_type);
1383 /* Likewise for constant X. */
1386 mips_const_insns (rtx x)
1388 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1389 enum mips_symbol_type symbol_type;
1390 HOST_WIDE_INT offset;
1392 switch (GET_CODE (x))
1396 || !mips_symbolic_constant_p (XEXP (x, 0), &symbol_type)
1397 || !mips_split_p[symbol_type])
1404 /* Unsigned 8-bit constants can be loaded using an unextended
1405 LI instruction. Unsigned 16-bit constants can be loaded
1406 using an extended LI. Negative constants must be loaded
1407 using LI and then negated. */
1408 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1409 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1410 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1411 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1414 return mips_build_integer (codes, INTVAL (x));
1418 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1424 /* See if we can refer to X directly. */
1425 if (mips_symbolic_constant_p (x, &symbol_type))
1426 return mips_symbol_insns (symbol_type);
1428 /* Otherwise try splitting the constant into a base and offset.
1429 16-bit offsets can be added using an extra addiu. Larger offsets
1430 must be calculated separately and then added to the base. */
1431 mips_split_const (x, &x, &offset);
1434 int n = mips_const_insns (x);
1437 if (SMALL_OPERAND (offset))
1440 return n + 1 + mips_build_integer (codes, offset);
1447 return mips_symbol_insns (mips_classify_symbol (x));
1455 /* Return the number of instructions needed for memory reference X.
1456 Count extended mips16 instructions as two instructions. */
1459 mips_fetch_insns (rtx x)
1461 gcc_assert (MEM_P (x));
1462 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1466 /* Return the number of instructions needed for an integer division. */
1469 mips_idiv_insns (void)
1474 if (TARGET_CHECK_ZERO_DIV)
1476 if (GENERATE_DIVIDE_TRAPS)
1482 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
1487 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1488 returns a nonzero value if X is a legitimate address for a memory
1489 operand of the indicated MODE. STRICT is nonzero if this function
1490 is called during reload. */
1493 mips_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1495 struct mips_address_info addr;
1497 return mips_classify_address (&addr, x, mode, strict);
1501 /* Copy VALUE to a register and return that register. If new psuedos
1502 are allowed, copy it into a new register, otherwise use DEST. */
1505 mips_force_temporary (rtx dest, rtx value)
1507 if (!no_new_pseudos)
1508 return force_reg (Pmode, value);
1511 emit_move_insn (copy_rtx (dest), value);
1517 /* Return a LO_SUM expression for ADDR. TEMP is as for mips_force_temporary
1518 and is used to load the high part into a register. */
1521 mips_split_symbol (rtx temp, rtx addr)
1526 high = mips16_gp_pseudo_reg ();
1528 high = mips_force_temporary (temp, gen_rtx_HIGH (Pmode, copy_rtx (addr)));
1529 return gen_rtx_LO_SUM (Pmode, high, addr);
1533 /* Return an UNSPEC address with underlying address ADDRESS and symbol
1534 type SYMBOL_TYPE. */
1537 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
1540 HOST_WIDE_INT offset;
1542 mips_split_const (address, &base, &offset);
1543 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
1544 UNSPEC_ADDRESS_FIRST + symbol_type);
1545 return plus_constant (gen_rtx_CONST (Pmode, base), offset);
1549 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
1550 high part to BASE and return the result. Just return BASE otherwise.
1551 TEMP is available as a temporary register if needed.
1553 The returned expression can be used as the first operand to a LO_SUM. */
1556 mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
1557 enum mips_symbol_type symbol_type)
1559 if (mips_split_p[symbol_type])
1561 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
1562 addr = mips_force_temporary (temp, addr);
1563 return mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
1569 /* Return a legitimate address for REG + OFFSET. TEMP is as for
1570 mips_force_temporary; it is only needed when OFFSET is not a
1574 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
1576 if (!SMALL_OPERAND (offset))
1581 /* Load the full offset into a register so that we can use
1582 an unextended instruction for the address itself. */
1583 high = GEN_INT (offset);
1588 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH. */
1589 high = GEN_INT (CONST_HIGH_PART (offset));
1590 offset = CONST_LOW_PART (offset);
1592 high = mips_force_temporary (temp, high);
1593 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
1595 return plus_constant (reg, offset);
1598 /* Emit a call to __tls_get_addr. SYM is the TLS symbol we are
1599 referencing, and TYPE is the symbol type to use (either global
1600 dynamic or local dynamic). V0 is an RTX for the return value
1601 location. The entire insn sequence is returned. */
1603 static GTY(()) rtx mips_tls_symbol;
1606 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
1608 rtx insn, loc, tga, a0;
1610 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
1612 if (!mips_tls_symbol)
1613 mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
1615 loc = mips_unspec_address (sym, type);
1619 emit_insn (gen_rtx_SET (Pmode, a0,
1620 gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
1621 tga = gen_rtx_MEM (Pmode, mips_tls_symbol);
1622 insn = emit_call_insn (gen_call_value (v0, tga, const0_rtx, const0_rtx));
1623 CONST_OR_PURE_CALL_P (insn) = 1;
1624 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), v0);
1625 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
1626 insn = get_insns ();
1633 /* Generate the code to access LOC, a thread local SYMBOL_REF. The
1634 return value will be a valid address and move_operand (either a REG
1638 mips_legitimize_tls_address (rtx loc)
1640 rtx dest, insn, v0, v1, tmp1, tmp2, eqv;
1641 enum tls_model model;
1643 v0 = gen_rtx_REG (Pmode, GP_RETURN);
1644 v1 = gen_rtx_REG (Pmode, GP_RETURN + 1);
1646 model = SYMBOL_REF_TLS_MODEL (loc);
1650 case TLS_MODEL_GLOBAL_DYNAMIC:
1651 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
1652 dest = gen_reg_rtx (Pmode);
1653 emit_libcall_block (insn, dest, v0, loc);
1656 case TLS_MODEL_LOCAL_DYNAMIC:
1657 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
1658 tmp1 = gen_reg_rtx (Pmode);
1660 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
1661 share the LDM result with other LD model accesses. */
1662 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1664 emit_libcall_block (insn, tmp1, v0, eqv);
1666 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
1667 dest = gen_rtx_LO_SUM (Pmode, tmp2,
1668 mips_unspec_address (loc, SYMBOL_DTPREL));
1671 case TLS_MODEL_INITIAL_EXEC:
1672 tmp1 = gen_reg_rtx (Pmode);
1673 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
1674 if (Pmode == DImode)
1676 emit_insn (gen_tls_get_tp_di (v1));
1677 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
1681 emit_insn (gen_tls_get_tp_si (v1));
1682 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
1684 dest = gen_reg_rtx (Pmode);
1685 emit_insn (gen_add3_insn (dest, tmp1, v1));
1688 case TLS_MODEL_LOCAL_EXEC:
1690 if (Pmode == DImode)
1691 emit_insn (gen_tls_get_tp_di (v1));
1693 emit_insn (gen_tls_get_tp_si (v1));
1695 tmp1 = mips_unspec_offset_high (NULL, v1, loc, SYMBOL_TPREL);
1696 dest = gen_rtx_LO_SUM (Pmode, tmp1,
1697 mips_unspec_address (loc, SYMBOL_TPREL));
1707 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
1708 be legitimized in a way that the generic machinery might not expect,
1709 put the new address in *XLOC and return true. MODE is the mode of
1710 the memory being accessed. */
1713 mips_legitimize_address (rtx *xloc, enum machine_mode mode)
1715 enum mips_symbol_type symbol_type;
1717 if (mips_tls_operand_p (*xloc))
1719 *xloc = mips_legitimize_tls_address (*xloc);
1723 /* See if the address can split into a high part and a LO_SUM. */
1724 if (mips_symbolic_constant_p (*xloc, &symbol_type)
1725 && mips_symbolic_address_p (symbol_type, mode)
1726 && mips_split_p[symbol_type])
1728 *xloc = mips_split_symbol (0, *xloc);
1732 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
1734 /* Handle REG + CONSTANT using mips_add_offset. */
1737 reg = XEXP (*xloc, 0);
1738 if (!mips_valid_base_register_p (reg, mode, 0))
1739 reg = copy_to_mode_reg (Pmode, reg);
1740 *xloc = mips_add_offset (0, reg, INTVAL (XEXP (*xloc, 1)));
1748 /* Subroutine of mips_build_integer (with the same interface).
1749 Assume that the final action in the sequence should be a left shift. */
1752 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
1754 unsigned int i, shift;
1756 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
1757 since signed numbers are easier to load than unsigned ones. */
1759 while ((value & 1) == 0)
1760 value /= 2, shift++;
1762 i = mips_build_integer (codes, value);
1763 codes[i].code = ASHIFT;
1764 codes[i].value = shift;
1769 /* As for mips_build_shift, but assume that the final action will be
1770 an IOR or PLUS operation. */
1773 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
1775 unsigned HOST_WIDE_INT high;
1778 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
1779 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
1781 /* The constant is too complex to load with a simple lui/ori pair
1782 so our goal is to clear as many trailing zeros as possible.
1783 In this case, we know bit 16 is set and that the low 16 bits
1784 form a negative number. If we subtract that number from VALUE,
1785 we will clear at least the lowest 17 bits, maybe more. */
1786 i = mips_build_integer (codes, CONST_HIGH_PART (value));
1787 codes[i].code = PLUS;
1788 codes[i].value = CONST_LOW_PART (value);
1792 i = mips_build_integer (codes, high);
1793 codes[i].code = IOR;
1794 codes[i].value = value & 0xffff;
1800 /* Fill CODES with a sequence of rtl operations to load VALUE.
1801 Return the number of operations needed. */
1804 mips_build_integer (struct mips_integer_op *codes,
1805 unsigned HOST_WIDE_INT value)
1807 if (SMALL_OPERAND (value)
1808 || SMALL_OPERAND_UNSIGNED (value)
1809 || LUI_OPERAND (value))
1811 /* The value can be loaded with a single instruction. */
1812 codes[0].code = UNKNOWN;
1813 codes[0].value = value;
1816 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
1818 /* Either the constant is a simple LUI/ORI combination or its
1819 lowest bit is set. We don't want to shift in this case. */
1820 return mips_build_lower (codes, value);
1822 else if ((value & 0xffff) == 0)
1824 /* The constant will need at least three actions. The lowest
1825 16 bits are clear, so the final action will be a shift. */
1826 return mips_build_shift (codes, value);
1830 /* The final action could be a shift, add or inclusive OR.
1831 Rather than use a complex condition to select the best
1832 approach, try both mips_build_shift and mips_build_lower
1833 and pick the one that gives the shortest sequence.
1834 Note that this case is only used once per constant. */
1835 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
1836 unsigned int cost, alt_cost;
1838 cost = mips_build_shift (codes, value);
1839 alt_cost = mips_build_lower (alt_codes, value);
1840 if (alt_cost < cost)
1842 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
1850 /* Move VALUE into register DEST. */
1853 mips_move_integer (rtx dest, unsigned HOST_WIDE_INT value)
1855 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1856 enum machine_mode mode;
1857 unsigned int i, cost;
1860 mode = GET_MODE (dest);
1861 cost = mips_build_integer (codes, value);
1863 /* Apply each binary operation to X. Invariant: X is a legitimate
1864 source operand for a SET pattern. */
1865 x = GEN_INT (codes[0].value);
1866 for (i = 1; i < cost; i++)
1869 emit_move_insn (dest, x), x = dest;
1871 x = force_reg (mode, x);
1872 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
1875 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
1879 /* Subroutine of mips_legitimize_move. Move constant SRC into register
1880 DEST given that SRC satisfies immediate_operand but doesn't satisfy
1884 mips_legitimize_const_move (enum machine_mode mode, rtx dest, rtx src)
1887 HOST_WIDE_INT offset;
1888 enum mips_symbol_type symbol_type;
1890 /* Split moves of big integers into smaller pieces. In mips16 code,
1891 it's better to force the constant into memory instead. */
1892 if (GET_CODE (src) == CONST_INT && !TARGET_MIPS16)
1894 mips_move_integer (dest, INTVAL (src));
1898 if (mips_tls_operand_p (src))
1900 emit_move_insn (dest, mips_legitimize_tls_address (src));
1904 /* See if the symbol can be split. For mips16, this is often worse than
1905 forcing it in the constant pool since it needs the single-register form
1906 of addiu or daddiu. */
1908 && mips_symbolic_constant_p (src, &symbol_type)
1909 && mips_split_p[symbol_type])
1911 emit_move_insn (dest, mips_split_symbol (dest, src));
1915 /* If we have (const (plus symbol offset)), load the symbol first
1916 and then add in the offset. This is usually better than forcing
1917 the constant into memory, at least in non-mips16 code. */
1918 mips_split_const (src, &base, &offset);
1921 && (!no_new_pseudos || SMALL_OPERAND (offset)))
1923 base = mips_force_temporary (dest, base);
1924 emit_move_insn (dest, mips_add_offset (0, base, offset));
1928 src = force_const_mem (mode, src);
1930 /* When using explicit relocs, constant pool references are sometimes
1931 not legitimate addresses. */
1932 if (!memory_operand (src, VOIDmode))
1933 src = replace_equiv_address (src, mips_split_symbol (dest, XEXP (src, 0)));
1934 emit_move_insn (dest, src);
1938 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
1939 sequence that is valid. */
1942 mips_legitimize_move (enum machine_mode mode, rtx dest, rtx src)
1944 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
1946 emit_move_insn (dest, force_reg (mode, src));
1950 /* Check for individual, fully-reloaded mflo and mfhi instructions. */
1951 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
1952 && REG_P (src) && MD_REG_P (REGNO (src))
1953 && REG_P (dest) && GP_REG_P (REGNO (dest)))
1955 int other_regno = REGNO (src) == HI_REGNUM ? LO_REGNUM : HI_REGNUM;
1956 if (GET_MODE_SIZE (mode) <= 4)
1957 emit_insn (gen_mfhilo_si (gen_rtx_REG (SImode, REGNO (dest)),
1958 gen_rtx_REG (SImode, REGNO (src)),
1959 gen_rtx_REG (SImode, other_regno)));
1961 emit_insn (gen_mfhilo_di (gen_rtx_REG (DImode, REGNO (dest)),
1962 gen_rtx_REG (DImode, REGNO (src)),
1963 gen_rtx_REG (DImode, other_regno)));
1967 /* We need to deal with constants that would be legitimate
1968 immediate_operands but not legitimate move_operands. */
1969 if (CONSTANT_P (src) && !move_operand (src, mode))
1971 mips_legitimize_const_move (mode, dest, src);
1972 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
1978 /* We need a lot of little routines to check constant values on the
1979 mips16. These are used to figure out how long the instruction will
1980 be. It would be much better to do this using constraints, but
1981 there aren't nearly enough letters available. */
1984 m16_check_op (rtx op, int low, int high, int mask)
1986 return (GET_CODE (op) == CONST_INT
1987 && INTVAL (op) >= low
1988 && INTVAL (op) <= high
1989 && (INTVAL (op) & mask) == 0);
1993 m16_uimm3_b (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1995 return m16_check_op (op, 0x1, 0x8, 0);
1999 m16_simm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2001 return m16_check_op (op, - 0x8, 0x7, 0);
2005 m16_nsimm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2007 return m16_check_op (op, - 0x7, 0x8, 0);
2011 m16_simm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2013 return m16_check_op (op, - 0x10, 0xf, 0);
2017 m16_nsimm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2019 return m16_check_op (op, - 0xf, 0x10, 0);
2023 m16_uimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2025 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2029 m16_nuimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2031 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2035 m16_simm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2037 return m16_check_op (op, - 0x80, 0x7f, 0);
2041 m16_nsimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2043 return m16_check_op (op, - 0x7f, 0x80, 0);
2047 m16_uimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2049 return m16_check_op (op, 0x0, 0xff, 0);
2053 m16_nuimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2055 return m16_check_op (op, - 0xff, 0x0, 0);
2059 m16_uimm8_m1_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2061 return m16_check_op (op, - 0x1, 0xfe, 0);
2065 m16_uimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2067 return m16_check_op (op, 0x0, 0xff << 2, 3);
2071 m16_nuimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2073 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2077 m16_simm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2079 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2083 m16_nsimm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2085 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2089 mips_rtx_costs (rtx x, int code, int outer_code, int *total)
2091 enum machine_mode mode = GET_MODE (x);
2098 /* Always return 0, since we don't have different sized
2099 instructions, hence different costs according to Richard
2105 /* A number between 1 and 8 inclusive is efficient for a shift.
2106 Otherwise, we will need an extended instruction. */
2107 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2108 || (outer_code) == LSHIFTRT)
2110 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2113 *total = COSTS_N_INSNS (1);
2117 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2118 if ((outer_code) == XOR
2119 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2125 /* We may be able to use slt or sltu for a comparison with a
2126 signed 16 bit value. (The boundary conditions aren't quite
2127 right, but this is just a heuristic anyhow.) */
2128 if (((outer_code) == LT || (outer_code) == LE
2129 || (outer_code) == GE || (outer_code) == GT
2130 || (outer_code) == LTU || (outer_code) == LEU
2131 || (outer_code) == GEU || (outer_code) == GTU)
2132 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2138 /* Equality comparisons with 0 are cheap. */
2139 if (((outer_code) == EQ || (outer_code) == NE)
2146 /* Constants in the range 0...255 can be loaded with an unextended
2147 instruction. They are therefore as cheap as a register move.
2149 Given the choice between "li R1,0...255" and "move R1,R2"
2150 (where R2 is a known constant), it is usually better to use "li",
2151 since we do not want to unnecessarily extend the lifetime of R2. */
2152 if (outer_code == SET
2154 && INTVAL (x) < 256)
2160 /* Otherwise fall through to the handling below. */
2166 if (LEGITIMATE_CONSTANT_P (x))
2168 *total = COSTS_N_INSNS (1);
2173 /* The value will need to be fetched from the constant pool. */
2174 *total = CONSTANT_POOL_COST;
2180 /* If the address is legitimate, return the number of
2181 instructions it needs, otherwise use the default handling. */
2182 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2185 *total = COSTS_N_INSNS (1 + n);
2192 *total = COSTS_N_INSNS (6);
2196 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2202 if (mode == DImode && !TARGET_64BIT)
2204 *total = COSTS_N_INSNS (2);
2212 if (mode == DImode && !TARGET_64BIT)
2214 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2221 if (mode == SFmode || mode == DFmode)
2222 *total = COSTS_N_INSNS (1);
2224 *total = COSTS_N_INSNS (4);
2228 *total = COSTS_N_INSNS (1);
2233 if (mode == SFmode || mode == DFmode)
2235 if (TUNE_MIPS3000 || TUNE_MIPS3900)
2236 *total = COSTS_N_INSNS (2);
2237 else if (TUNE_MIPS6000)
2238 *total = COSTS_N_INSNS (3);
2240 *total = COSTS_N_INSNS (4);
2242 *total = COSTS_N_INSNS (6);
2245 if (mode == DImode && !TARGET_64BIT)
2247 *total = COSTS_N_INSNS (4);
2253 if (mode == DImode && !TARGET_64BIT)
2267 *total = COSTS_N_INSNS (4);
2268 else if (TUNE_MIPS6000
2271 *total = COSTS_N_INSNS (5);
2273 *total = COSTS_N_INSNS (7);
2280 *total = COSTS_N_INSNS (4);
2281 else if (TUNE_MIPS3000
2284 *total = COSTS_N_INSNS (5);
2285 else if (TUNE_MIPS6000
2288 *total = COSTS_N_INSNS (6);
2290 *total = COSTS_N_INSNS (8);
2295 *total = COSTS_N_INSNS (12);
2296 else if (TUNE_MIPS3900)
2297 *total = COSTS_N_INSNS (2);
2298 else if (TUNE_MIPS4130)
2299 *total = COSTS_N_INSNS (mode == DImode ? 6 : 4);
2300 else if (TUNE_MIPS5400 || TUNE_SB1)
2301 *total = COSTS_N_INSNS (mode == DImode ? 4 : 3);
2302 else if (TUNE_MIPS5500 || TUNE_MIPS7000)
2303 *total = COSTS_N_INSNS (mode == DImode ? 9 : 5);
2304 else if (TUNE_MIPS9000)
2305 *total = COSTS_N_INSNS (mode == DImode ? 8 : 3);
2306 else if (TUNE_MIPS6000)
2307 *total = COSTS_N_INSNS (17);
2308 else if (TUNE_MIPS5000)
2309 *total = COSTS_N_INSNS (5);
2311 *total = COSTS_N_INSNS (10);
2320 *total = COSTS_N_INSNS (12);
2321 else if (TUNE_MIPS6000)
2322 *total = COSTS_N_INSNS (15);
2324 *total = COSTS_N_INSNS (24);
2325 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2326 *total = COSTS_N_INSNS (30);
2328 *total = COSTS_N_INSNS (23);
2336 *total = COSTS_N_INSNS (19);
2337 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2338 *total = COSTS_N_INSNS (59);
2339 else if (TUNE_MIPS6000)
2340 *total = COSTS_N_INSNS (16);
2342 *total = COSTS_N_INSNS (32);
2344 *total = COSTS_N_INSNS (36);
2353 *total = COSTS_N_INSNS (35);
2354 else if (TUNE_MIPS6000)
2355 *total = COSTS_N_INSNS (38);
2356 else if (TUNE_MIPS5000)
2357 *total = COSTS_N_INSNS (36);
2359 *total = COSTS_N_INSNS ((mode == SImode) ? 36 : 68);
2360 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2361 *total = COSTS_N_INSNS ((mode == SImode) ? 42 : 74);
2363 *total = COSTS_N_INSNS (69);
2367 /* A sign extend from SImode to DImode in 64 bit mode is often
2368 zero instructions, because the result can often be used
2369 directly by another instruction; we'll call it one. */
2370 if (TARGET_64BIT && mode == DImode
2371 && GET_MODE (XEXP (x, 0)) == SImode)
2372 *total = COSTS_N_INSNS (1);
2374 *total = COSTS_N_INSNS (2);
2378 if (TARGET_64BIT && mode == DImode
2379 && GET_MODE (XEXP (x, 0)) == SImode)
2380 *total = COSTS_N_INSNS (2);
2382 *total = COSTS_N_INSNS (1);
2390 /* Provide the costs of an addressing mode that contains ADDR.
2391 If ADDR is not a valid address, its cost is irrelevant. */
2394 mips_address_cost (rtx addr)
2396 return mips_address_insns (addr, SImode);
2399 /* Return one word of double-word value OP, taking into account the fixed
2400 endianness of certain registers. HIGH_P is true to select the high part,
2401 false to select the low part. */
2404 mips_subword (rtx op, int high_p)
2407 enum machine_mode mode;
2409 mode = GET_MODE (op);
2410 if (mode == VOIDmode)
2413 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2414 byte = UNITS_PER_WORD;
2420 if (FP_REG_P (REGNO (op)))
2421 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2422 if (REGNO (op) == HI_REGNUM)
2423 return gen_rtx_REG (word_mode, high_p ? HI_REGNUM : LO_REGNUM);
2427 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
2429 return simplify_gen_subreg (word_mode, op, mode, byte);
2433 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2436 mips_split_64bit_move_p (rtx dest, rtx src)
2441 /* FP->FP moves can be done in a single instruction. */
2442 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2445 /* Check for floating-point loads and stores. They can be done using
2446 ldc1 and sdc1 on MIPS II and above. */
2449 if (FP_REG_RTX_P (dest) && MEM_P (src))
2451 if (FP_REG_RTX_P (src) && MEM_P (dest))
2458 /* Split a 64-bit move from SRC to DEST assuming that
2459 mips_split_64bit_move_p holds.
2461 Moves into and out of FPRs cause some difficulty here. Such moves
2462 will always be DFmode, since paired FPRs are not allowed to store
2463 DImode values. The most natural representation would be two separate
2464 32-bit moves, such as:
2466 (set (reg:SI $f0) (mem:SI ...))
2467 (set (reg:SI $f1) (mem:SI ...))
2469 However, the second insn is invalid because odd-numbered FPRs are
2470 not allowed to store independent values. Use the patterns load_df_low,
2471 load_df_high and store_df_high instead. */
2474 mips_split_64bit_move (rtx dest, rtx src)
2476 if (FP_REG_RTX_P (dest))
2478 /* Loading an FPR from memory or from GPRs. */
2479 emit_insn (gen_load_df_low (copy_rtx (dest), mips_subword (src, 0)));
2480 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2483 else if (FP_REG_RTX_P (src))
2485 /* Storing an FPR into memory or GPRs. */
2486 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2487 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2491 /* The operation can be split into two normal moves. Decide in
2492 which order to do them. */
2495 low_dest = mips_subword (dest, 0);
2496 if (REG_P (low_dest)
2497 && reg_overlap_mentioned_p (low_dest, src))
2499 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2500 emit_move_insn (low_dest, mips_subword (src, 0));
2504 emit_move_insn (low_dest, mips_subword (src, 0));
2505 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2510 /* Return the appropriate instructions to move SRC into DEST. Assume
2511 that SRC is operand 1 and DEST is operand 0. */
2514 mips_output_move (rtx dest, rtx src)
2516 enum rtx_code dest_code, src_code;
2519 dest_code = GET_CODE (dest);
2520 src_code = GET_CODE (src);
2521 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2523 if (dbl_p && mips_split_64bit_move_p (dest, src))
2526 if ((src_code == REG && GP_REG_P (REGNO (src)))
2527 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2529 if (dest_code == REG)
2531 if (GP_REG_P (REGNO (dest)))
2532 return "move\t%0,%z1";
2534 if (MD_REG_P (REGNO (dest)))
2537 if (FP_REG_P (REGNO (dest)))
2538 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2540 if (ALL_COP_REG_P (REGNO (dest)))
2542 static char retval[] = "dmtc_\t%z1,%0";
2544 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2545 return (dbl_p ? retval : retval + 1);
2548 if (dest_code == MEM)
2549 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2551 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2553 if (src_code == REG)
2555 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2556 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2558 if (FP_REG_P (REGNO (src)))
2559 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2561 if (ALL_COP_REG_P (REGNO (src)))
2563 static char retval[] = "dmfc_\t%0,%1";
2565 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2566 return (dbl_p ? retval : retval + 1);
2570 if (src_code == MEM)
2571 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
2573 if (src_code == CONST_INT)
2575 /* Don't use the X format, because that will give out of
2576 range numbers for 64 bit hosts and 32 bit targets. */
2578 return "li\t%0,%1\t\t\t# %X1";
2580 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
2583 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
2587 if (src_code == HIGH)
2588 return "lui\t%0,%h1";
2590 if (CONST_GP_P (src))
2591 return "move\t%0,%1";
2593 if (symbolic_operand (src, VOIDmode))
2594 return (dbl_p ? "dla\t%0,%1" : "la\t%0,%1");
2596 if (src_code == REG && FP_REG_P (REGNO (src)))
2598 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2600 if (GET_MODE (dest) == V2SFmode)
2601 return "mov.ps\t%0,%1";
2603 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2606 if (dest_code == MEM)
2607 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
2609 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2611 if (src_code == MEM)
2612 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
2614 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
2616 static char retval[] = "l_c_\t%0,%1";
2618 retval[1] = (dbl_p ? 'd' : 'w');
2619 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2622 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
2624 static char retval[] = "s_c_\t%1,%0";
2626 retval[1] = (dbl_p ? 'd' : 'w');
2627 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2633 /* Restore $gp from its save slot. Valid only when using o32 or
2637 mips_restore_gp (void)
2641 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI);
2643 address = mips_add_offset (pic_offset_table_rtx,
2644 frame_pointer_needed
2645 ? hard_frame_pointer_rtx
2646 : stack_pointer_rtx,
2647 current_function_outgoing_args_size);
2648 slot = gen_rtx_MEM (Pmode, address);
2650 emit_move_insn (pic_offset_table_rtx, slot);
2651 if (!TARGET_EXPLICIT_RELOCS)
2652 emit_insn (gen_blockage ());
2655 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
2658 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
2660 emit_insn (gen_rtx_SET (VOIDmode, target,
2661 gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
2664 /* Return true if CMP1 is a suitable second operand for relational
2665 operator CODE. See also the *sCC patterns in mips.md. */
2668 mips_relational_operand_ok_p (enum rtx_code code, rtx cmp1)
2674 return reg_or_0_operand (cmp1, VOIDmode);
2678 return !TARGET_MIPS16 && cmp1 == const1_rtx;
2682 return arith_operand (cmp1, VOIDmode);
2685 return sle_operand (cmp1, VOIDmode);
2688 return sleu_operand (cmp1, VOIDmode);
2695 /* Compare CMP0 and CMP1 using relational operator CODE and store the
2696 result in TARGET. CMP0 and TARGET are register_operands that have
2697 the same integer mode. If INVERT_PTR is nonnull, it's OK to set
2698 TARGET to the inverse of the result and flip *INVERT_PTR instead. */
2701 mips_emit_int_relational (enum rtx_code code, bool *invert_ptr,
2702 rtx target, rtx cmp0, rtx cmp1)
2704 /* First see if there is a MIPS instruction that can do this operation
2705 with CMP1 in its current form. If not, try doing the same for the
2706 inverse operation. If that also fails, force CMP1 into a register
2708 if (mips_relational_operand_ok_p (code, cmp1))
2709 mips_emit_binary (code, target, cmp0, cmp1);
2712 enum rtx_code inv_code = reverse_condition (code);
2713 if (!mips_relational_operand_ok_p (inv_code, cmp1))
2715 cmp1 = force_reg (GET_MODE (cmp0), cmp1);
2716 mips_emit_int_relational (code, invert_ptr, target, cmp0, cmp1);
2718 else if (invert_ptr == 0)
2720 rtx inv_target = gen_reg_rtx (GET_MODE (target));
2721 mips_emit_binary (inv_code, inv_target, cmp0, cmp1);
2722 mips_emit_binary (XOR, target, inv_target, const1_rtx);
2726 *invert_ptr = !*invert_ptr;
2727 mips_emit_binary (inv_code, target, cmp0, cmp1);
2732 /* Return a register that is zero iff CMP0 and CMP1 are equal.
2733 The register will have the same mode as CMP0. */
2736 mips_zero_if_equal (rtx cmp0, rtx cmp1)
2738 if (cmp1 == const0_rtx)
2741 if (uns_arith_operand (cmp1, VOIDmode))
2742 return expand_binop (GET_MODE (cmp0), xor_optab,
2743 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
2745 return expand_binop (GET_MODE (cmp0), sub_optab,
2746 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
2749 /* Convert a comparison into something that can be used in a branch or
2750 conditional move. cmp_operands[0] and cmp_operands[1] are the values
2751 being compared and *CODE is the code used to compare them.
2753 Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
2754 If NEED_EQ_NE_P, then only EQ/NE comparisons against zero are possible,
2755 otherwise any standard branch condition can be used. The standard branch
2758 - EQ/NE between two registers.
2759 - any comparison between a register and zero. */
2762 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
2764 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT)
2766 if (!need_eq_ne_p && cmp_operands[1] == const0_rtx)
2768 *op0 = cmp_operands[0];
2769 *op1 = cmp_operands[1];
2771 else if (*code == EQ || *code == NE)
2775 *op0 = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
2780 *op0 = cmp_operands[0];
2781 *op1 = force_reg (GET_MODE (*op0), cmp_operands[1]);
2786 /* The comparison needs a separate scc instruction. Store the
2787 result of the scc in *OP0 and compare it against zero. */
2788 bool invert = false;
2789 *op0 = gen_reg_rtx (GET_MODE (cmp_operands[0]));
2791 mips_emit_int_relational (*code, &invert, *op0,
2792 cmp_operands[0], cmp_operands[1]);
2793 *code = (invert ? EQ : NE);
2798 enum rtx_code cmp_code;
2800 /* Floating-point tests use a separate c.cond.fmt comparison to
2801 set a condition code register. The branch or conditional move
2802 will then compare that register against zero.
2804 Set CMP_CODE to the code of the comparison instruction and
2805 *CODE to the code that the branch or move should use. */
2811 cmp_code = reverse_condition_maybe_unordered (*code);
2821 ? gen_reg_rtx (CCmode)
2822 : gen_rtx_REG (CCmode, FPSW_REGNUM));
2824 mips_emit_binary (cmp_code, *op0, cmp_operands[0], cmp_operands[1]);
2828 /* Try comparing cmp_operands[0] and cmp_operands[1] using rtl code CODE.
2829 Store the result in TARGET and return true if successful.
2831 On 64-bit targets, TARGET may be wider than cmp_operands[0]. */
2834 mips_emit_scc (enum rtx_code code, rtx target)
2836 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) != MODE_INT)
2839 target = gen_lowpart (GET_MODE (cmp_operands[0]), target);
2840 if (code == EQ || code == NE)
2842 rtx zie = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
2843 mips_emit_binary (code, target, zie, const0_rtx);
2846 mips_emit_int_relational (code, 0, target,
2847 cmp_operands[0], cmp_operands[1]);
2851 /* Emit the common code for doing conditional branches.
2852 operand[0] is the label to jump to.
2853 The comparison operands are saved away by cmp{si,di,sf,df}. */
2856 gen_conditional_branch (rtx *operands, enum rtx_code code)
2858 rtx op0, op1, target;
2860 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
2861 target = gen_rtx_IF_THEN_ELSE (VOIDmode,
2862 gen_rtx_fmt_ee (code, GET_MODE (op0),
2864 gen_rtx_LABEL_REF (VOIDmode, operands[0]),
2866 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, target));
2869 /* Emit the common code for conditional moves. OPERANDS is the array
2870 of operands passed to the conditional move define_expand. */
2873 gen_conditional_move (rtx *operands)
2878 code = GET_CODE (operands[1]);
2879 mips_emit_compare (&code, &op0, &op1, true);
2880 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2881 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2882 gen_rtx_fmt_ee (code,
2885 operands[2], operands[3])));
2888 /* Emit a conditional trap. OPERANDS is the array of operands passed to
2889 the conditional_trap expander. */
2892 mips_gen_conditional_trap (rtx *operands)
2895 enum rtx_code cmp_code = GET_CODE (operands[0]);
2896 enum machine_mode mode = GET_MODE (cmp_operands[0]);
2898 /* MIPS conditional trap machine instructions don't have GT or LE
2899 flavors, so we must invert the comparison and convert to LT and
2900 GE, respectively. */
2903 case GT: cmp_code = LT; break;
2904 case LE: cmp_code = GE; break;
2905 case GTU: cmp_code = LTU; break;
2906 case LEU: cmp_code = GEU; break;
2909 if (cmp_code == GET_CODE (operands[0]))
2911 op0 = cmp_operands[0];
2912 op1 = cmp_operands[1];
2916 op0 = cmp_operands[1];
2917 op1 = cmp_operands[0];
2919 op0 = force_reg (mode, op0);
2920 if (!arith_operand (op1, mode))
2921 op1 = force_reg (mode, op1);
2923 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
2924 gen_rtx_fmt_ee (cmp_code, mode, op0, op1),
2928 /* Load function address ADDR into register DEST. SIBCALL_P is true
2929 if the address is needed for a sibling call. */
2932 mips_load_call_address (rtx dest, rtx addr, int sibcall_p)
2934 /* If we're generating PIC, and this call is to a global function,
2935 try to allow its address to be resolved lazily. This isn't
2936 possible for NewABI sibcalls since the value of $gp on entry
2937 to the stub would be our caller's gp, not ours. */
2938 if (TARGET_EXPLICIT_RELOCS
2939 && !(sibcall_p && TARGET_NEWABI)
2940 && global_got_operand (addr, VOIDmode))
2942 rtx high, lo_sum_symbol;
2944 high = mips_unspec_offset_high (dest, pic_offset_table_rtx,
2945 addr, SYMBOL_GOTOFF_CALL);
2946 lo_sum_symbol = mips_unspec_address (addr, SYMBOL_GOTOFF_CALL);
2947 if (Pmode == SImode)
2948 emit_insn (gen_load_callsi (dest, high, lo_sum_symbol));
2950 emit_insn (gen_load_calldi (dest, high, lo_sum_symbol));
2953 emit_move_insn (dest, addr);
2957 /* Expand a call or call_value instruction. RESULT is where the
2958 result will go (null for calls), ADDR is the address of the
2959 function, ARGS_SIZE is the size of the arguments and AUX is
2960 the value passed to us by mips_function_arg. SIBCALL_P is true
2961 if we are expanding a sibling call, false if we're expanding
2965 mips_expand_call (rtx result, rtx addr, rtx args_size, rtx aux, int sibcall_p)
2967 rtx orig_addr, pattern, insn;
2970 if (!call_insn_operand (addr, VOIDmode))
2972 addr = gen_reg_rtx (Pmode);
2973 mips_load_call_address (addr, orig_addr, sibcall_p);
2977 && mips16_hard_float
2978 && build_mips16_call_stub (result, addr, args_size,
2979 aux == 0 ? 0 : (int) GET_MODE (aux)))
2983 pattern = (sibcall_p
2984 ? gen_sibcall_internal (addr, args_size)
2985 : gen_call_internal (addr, args_size));
2986 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
2990 reg1 = XEXP (XVECEXP (result, 0, 0), 0);
2991 reg2 = XEXP (XVECEXP (result, 0, 1), 0);
2994 ? gen_sibcall_value_multiple_internal (reg1, addr, args_size, reg2)
2995 : gen_call_value_multiple_internal (reg1, addr, args_size, reg2));
2998 pattern = (sibcall_p
2999 ? gen_sibcall_value_internal (result, addr, args_size)
3000 : gen_call_value_internal (result, addr, args_size));
3002 insn = emit_call_insn (pattern);
3004 /* Lazy-binding stubs require $gp to be valid on entry. */
3005 if (global_got_operand (orig_addr, VOIDmode))
3006 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
3010 /* We can handle any sibcall when TARGET_SIBCALLS is true. */
3013 mips_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
3014 tree exp ATTRIBUTE_UNUSED)
3016 return TARGET_SIBCALLS;
3019 /* Emit code to move general operand SRC into condition-code
3020 register DEST. SCRATCH is a scratch TFmode float register.
3027 where FP1 and FP2 are single-precision float registers
3028 taken from SCRATCH. */
3031 mips_emit_fcc_reload (rtx dest, rtx src, rtx scratch)
3035 /* Change the source to SFmode. */
3037 src = adjust_address (src, SFmode, 0);
3038 else if (REG_P (src) || GET_CODE (src) == SUBREG)
3039 src = gen_rtx_REG (SFmode, true_regnum (src));
3041 fp1 = gen_rtx_REG (SFmode, REGNO (scratch));
3042 fp2 = gen_rtx_REG (SFmode, REGNO (scratch) + FP_INC);
3044 emit_move_insn (copy_rtx (fp1), src);
3045 emit_move_insn (copy_rtx (fp2), CONST0_RTX (SFmode));
3046 emit_insn (gen_slt_sf (dest, fp2, fp1));
3049 /* Emit code to change the current function's return address to
3050 ADDRESS. SCRATCH is available as a scratch register, if needed.
3051 ADDRESS and SCRATCH are both word-mode GPRs. */
3054 mips_set_return_address (rtx address, rtx scratch)
3058 compute_frame_size (get_frame_size ());
3059 gcc_assert ((cfun->machine->frame.mask >> 31) & 1);
3060 slot_address = mips_add_offset (scratch, stack_pointer_rtx,
3061 cfun->machine->frame.gp_sp_offset);
3063 emit_move_insn (gen_rtx_MEM (GET_MODE (address), slot_address), address);
3066 /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
3067 Assume that the areas do not overlap. */
3070 mips_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length)
3072 HOST_WIDE_INT offset, delta;
3073 unsigned HOST_WIDE_INT bits;
3075 enum machine_mode mode;
3078 /* Work out how many bits to move at a time. If both operands have
3079 half-word alignment, it is usually better to move in half words.
3080 For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr
3081 and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr.
3082 Otherwise move word-sized chunks. */
3083 if (MEM_ALIGN (src) == BITS_PER_WORD / 2
3084 && MEM_ALIGN (dest) == BITS_PER_WORD / 2)
3085 bits = BITS_PER_WORD / 2;
3087 bits = BITS_PER_WORD;
3089 mode = mode_for_size (bits, MODE_INT, 0);
3090 delta = bits / BITS_PER_UNIT;
3092 /* Allocate a buffer for the temporary registers. */
3093 regs = alloca (sizeof (rtx) * length / delta);
3095 /* Load as many BITS-sized chunks as possible. Use a normal load if
3096 the source has enough alignment, otherwise use left/right pairs. */
3097 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
3099 regs[i] = gen_reg_rtx (mode);
3100 if (MEM_ALIGN (src) >= bits)
3101 emit_move_insn (regs[i], adjust_address (src, mode, offset));
3104 rtx part = adjust_address (src, BLKmode, offset);
3105 if (!mips_expand_unaligned_load (regs[i], part, bits, 0))
3110 /* Copy the chunks to the destination. */
3111 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
3112 if (MEM_ALIGN (dest) >= bits)
3113 emit_move_insn (adjust_address (dest, mode, offset), regs[i]);
3116 rtx part = adjust_address (dest, BLKmode, offset);
3117 if (!mips_expand_unaligned_store (part, regs[i], bits, 0))
3121 /* Mop up any left-over bytes. */
3122 if (offset < length)
3124 src = adjust_address (src, BLKmode, offset);
3125 dest = adjust_address (dest, BLKmode, offset);
3126 move_by_pieces (dest, src, length - offset,
3127 MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), 0);
3131 #define MAX_MOVE_REGS 4
3132 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3135 /* Helper function for doing a loop-based block operation on memory
3136 reference MEM. Each iteration of the loop will operate on LENGTH
3139 Create a new base register for use within the loop and point it to
3140 the start of MEM. Create a new memory reference that uses this
3141 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
3144 mips_adjust_block_mem (rtx mem, HOST_WIDE_INT length,
3145 rtx *loop_reg, rtx *loop_mem)
3147 *loop_reg = copy_addr_to_reg (XEXP (mem, 0));
3149 /* Although the new mem does not refer to a known location,
3150 it does keep up to LENGTH bytes of alignment. */
3151 *loop_mem = change_address (mem, BLKmode, *loop_reg);
3152 set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT));
3156 /* Move LENGTH bytes from SRC to DEST using a loop that moves MAX_MOVE_BYTES
3157 per iteration. LENGTH must be at least MAX_MOVE_BYTES. Assume that the
3158 memory regions do not overlap. */
3161 mips_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length)
3163 rtx label, src_reg, dest_reg, final_src;
3164 HOST_WIDE_INT leftover;
3166 leftover = length % MAX_MOVE_BYTES;
3169 /* Create registers and memory references for use within the loop. */
3170 mips_adjust_block_mem (src, MAX_MOVE_BYTES, &src_reg, &src);
3171 mips_adjust_block_mem (dest, MAX_MOVE_BYTES, &dest_reg, &dest);
3173 /* Calculate the value that SRC_REG should have after the last iteration
3175 final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length),
3178 /* Emit the start of the loop. */
3179 label = gen_label_rtx ();
3182 /* Emit the loop body. */
3183 mips_block_move_straight (dest, src, MAX_MOVE_BYTES);
3185 /* Move on to the next block. */
3186 emit_move_insn (src_reg, plus_constant (src_reg, MAX_MOVE_BYTES));
3187 emit_move_insn (dest_reg, plus_constant (dest_reg, MAX_MOVE_BYTES));
3189 /* Emit the loop condition. */
3190 if (Pmode == DImode)
3191 emit_insn (gen_cmpdi (src_reg, final_src));
3193 emit_insn (gen_cmpsi (src_reg, final_src));
3194 emit_jump_insn (gen_bne (label));
3196 /* Mop up any left-over bytes. */
3198 mips_block_move_straight (dest, src, leftover);
3201 /* Expand a movmemsi instruction. */
3204 mips_expand_block_move (rtx dest, rtx src, rtx length)
3206 if (GET_CODE (length) == CONST_INT)
3208 if (INTVAL (length) <= 2 * MAX_MOVE_BYTES)
3210 mips_block_move_straight (dest, src, INTVAL (length));
3215 mips_block_move_loop (dest, src, INTVAL (length));
3222 /* Argument support functions. */
3224 /* Initialize CUMULATIVE_ARGS for a function. */
3227 init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
3228 rtx libname ATTRIBUTE_UNUSED)
3230 static CUMULATIVE_ARGS zero_cum;
3231 tree param, next_param;
3234 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
3236 /* Determine if this function has variable arguments. This is
3237 indicated by the last argument being 'void_type_mode' if there
3238 are no variable arguments. The standard MIPS calling sequence
3239 passes all arguments in the general purpose registers in this case. */
3241 for (param = fntype ? TYPE_ARG_TYPES (fntype) : 0;
3242 param != 0; param = next_param)
3244 next_param = TREE_CHAIN (param);
3245 if (next_param == 0 && TREE_VALUE (param) != void_type_node)
3246 cum->gp_reg_found = 1;
3251 /* Fill INFO with information about a single argument. CUM is the
3252 cumulative state for earlier arguments. MODE is the mode of this
3253 argument and TYPE is its type (if known). NAMED is true if this
3254 is a named (fixed) argument rather than a variable one. */
3257 mips_arg_info (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
3258 tree type, int named, struct mips_arg_info *info)
3260 bool doubleword_aligned_p;
3261 unsigned int num_bytes, num_words, max_regs;
3263 /* Work out the size of the argument. */
3264 num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
3265 num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3267 /* Decide whether it should go in a floating-point register, assuming
3268 one is free. Later code checks for availability.
3270 The checks against UNITS_PER_FPVALUE handle the soft-float and
3271 single-float cases. */
3275 /* The EABI conventions have traditionally been defined in terms
3276 of TYPE_MODE, regardless of the actual type. */
3277 info->fpr_p = ((GET_MODE_CLASS (mode) == MODE_FLOAT
3278 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3279 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
3284 /* Only leading floating-point scalars are passed in
3285 floating-point registers. We also handle vector floats the same
3286 say, which is OK because they are not covered by the standard ABI. */
3287 info->fpr_p = (!cum->gp_reg_found
3288 && cum->arg_number < 2
3289 && (type == 0 || SCALAR_FLOAT_TYPE_P (type)
3290 || VECTOR_FLOAT_TYPE_P (type))
3291 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3292 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3293 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
3298 /* Scalar and complex floating-point types are passed in
3299 floating-point registers. */
3300 info->fpr_p = (named
3301 && (type == 0 || FLOAT_TYPE_P (type))
3302 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3303 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3304 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3305 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_FPVALUE);
3307 /* ??? According to the ABI documentation, the real and imaginary
3308 parts of complex floats should be passed in individual registers.
3309 The real and imaginary parts of stack arguments are supposed
3310 to be contiguous and there should be an extra word of padding
3313 This has two problems. First, it makes it impossible to use a
3314 single "void *" va_list type, since register and stack arguments
3315 are passed differently. (At the time of writing, MIPSpro cannot
3316 handle complex float varargs correctly.) Second, it's unclear
3317 what should happen when there is only one register free.
3319 For now, we assume that named complex floats should go into FPRs
3320 if there are two FPRs free, otherwise they should be passed in the
3321 same way as a struct containing two floats. */
3323 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3324 && GET_MODE_UNIT_SIZE (mode) < UNITS_PER_FPVALUE)
3326 if (cum->num_gprs >= MAX_ARGS_IN_REGISTERS - 1)
3327 info->fpr_p = false;
3337 /* See whether the argument has doubleword alignment. */
3338 doubleword_aligned_p = FUNCTION_ARG_BOUNDARY (mode, type) > BITS_PER_WORD;
3340 /* Set REG_OFFSET to the register count we're interested in.
3341 The EABI allocates the floating-point registers separately,
3342 but the other ABIs allocate them like integer registers. */
3343 info->reg_offset = (mips_abi == ABI_EABI && info->fpr_p
3347 /* Advance to an even register if the argument is doubleword-aligned. */
3348 if (doubleword_aligned_p)
3349 info->reg_offset += info->reg_offset & 1;
3351 /* Work out the offset of a stack argument. */
3352 info->stack_offset = cum->stack_words;
3353 if (doubleword_aligned_p)
3354 info->stack_offset += info->stack_offset & 1;
3356 max_regs = MAX_ARGS_IN_REGISTERS - info->reg_offset;
3358 /* Partition the argument between registers and stack. */
3359 info->reg_words = MIN (num_words, max_regs);
3360 info->stack_words = num_words - info->reg_words;
3364 /* Implement FUNCTION_ARG_ADVANCE. */
3367 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3368 tree type, int named)
3370 struct mips_arg_info info;
3372 mips_arg_info (cum, mode, type, named, &info);
3375 cum->gp_reg_found = true;
3377 /* See the comment above the cumulative args structure in mips.h
3378 for an explanation of what this code does. It assumes the O32
3379 ABI, which passes at most 2 arguments in float registers. */
3380 if (cum->arg_number < 2 && info.fpr_p)
3381 cum->fp_code += (mode == SFmode ? 1 : 2) << ((cum->arg_number - 1) * 2);
3383 if (mips_abi != ABI_EABI || !info.fpr_p)
3384 cum->num_gprs = info.reg_offset + info.reg_words;
3385 else if (info.reg_words > 0)
3386 cum->num_fprs += FP_INC;
3388 if (info.stack_words > 0)
3389 cum->stack_words = info.stack_offset + info.stack_words;
3394 /* Implement FUNCTION_ARG. */
3397 function_arg (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
3398 tree type, int named)
3400 struct mips_arg_info info;
3402 /* We will be called with a mode of VOIDmode after the last argument
3403 has been seen. Whatever we return will be passed to the call
3404 insn. If we need a mips16 fp_code, return a REG with the code
3405 stored as the mode. */
3406 if (mode == VOIDmode)
3408 if (TARGET_MIPS16 && cum->fp_code != 0)
3409 return gen_rtx_REG ((enum machine_mode) cum->fp_code, 0);
3415 mips_arg_info (cum, mode, type, named, &info);
3417 /* Return straight away if the whole argument is passed on the stack. */
3418 if (info.reg_offset == MAX_ARGS_IN_REGISTERS)
3422 && TREE_CODE (type) == RECORD_TYPE
3424 && TYPE_SIZE_UNIT (type)
3425 && host_integerp (TYPE_SIZE_UNIT (type), 1)
3428 /* The Irix 6 n32/n64 ABIs say that if any 64 bit chunk of the
3429 structure contains a double in its entirety, then that 64 bit
3430 chunk is passed in a floating point register. */
3433 /* First check to see if there is any such field. */
3434 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3435 if (TREE_CODE (field) == FIELD_DECL
3436 && TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3437 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD
3438 && host_integerp (bit_position (field), 0)
3439 && int_bit_position (field) % BITS_PER_WORD == 0)
3444 /* Now handle the special case by returning a PARALLEL
3445 indicating where each 64 bit chunk goes. INFO.REG_WORDS
3446 chunks are passed in registers. */
3448 HOST_WIDE_INT bitpos;
3451 /* assign_parms checks the mode of ENTRY_PARM, so we must
3452 use the actual mode here. */
3453 ret = gen_rtx_PARALLEL (mode, rtvec_alloc (info.reg_words));
3456 field = TYPE_FIELDS (type);
3457 for (i = 0; i < info.reg_words; i++)
3461 for (; field; field = TREE_CHAIN (field))
3462 if (TREE_CODE (field) == FIELD_DECL
3463 && int_bit_position (field) >= bitpos)
3467 && int_bit_position (field) == bitpos
3468 && TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3469 && !TARGET_SOFT_FLOAT
3470 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD)
3471 reg = gen_rtx_REG (DFmode, FP_ARG_FIRST + info.reg_offset + i);
3473 reg = gen_rtx_REG (DImode, GP_ARG_FIRST + info.reg_offset + i);
3476 = gen_rtx_EXPR_LIST (VOIDmode, reg,
3477 GEN_INT (bitpos / BITS_PER_UNIT));
3479 bitpos += BITS_PER_WORD;
3485 /* Handle the n32/n64 conventions for passing complex floating-point
3486 arguments in FPR pairs. The real part goes in the lower register
3487 and the imaginary part goes in the upper register. */
3490 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3493 enum machine_mode inner;
3496 inner = GET_MODE_INNER (mode);
3497 reg = FP_ARG_FIRST + info.reg_offset;
3498 real = gen_rtx_EXPR_LIST (VOIDmode,
3499 gen_rtx_REG (inner, reg),
3501 imag = gen_rtx_EXPR_LIST (VOIDmode,
3502 gen_rtx_REG (inner, reg + info.reg_words / 2),
3503 GEN_INT (GET_MODE_SIZE (inner)));
3504 return gen_rtx_PARALLEL (mode, gen_rtvec (2, real, imag));
3508 return gen_rtx_REG (mode, GP_ARG_FIRST + info.reg_offset);
3509 else if (info.reg_offset == 1)
3510 /* This code handles the special o32 case in which the second word
3511 of the argument structure is passed in floating-point registers. */
3512 return gen_rtx_REG (mode, FP_ARG_FIRST + FP_INC);
3514 return gen_rtx_REG (mode, FP_ARG_FIRST + info.reg_offset);
3518 /* Implement TARGET_ARG_PARTIAL_BYTES. */
3521 mips_arg_partial_bytes (CUMULATIVE_ARGS *cum,
3522 enum machine_mode mode, tree type, bool named)
3524 struct mips_arg_info info;
3526 mips_arg_info (cum, mode, type, named, &info);
3527 return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0;
3531 /* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least
3532 PARM_BOUNDARY bits of alignment, but will be given anything up
3533 to STACK_BOUNDARY bits if the type requires it. */
3536 function_arg_boundary (enum machine_mode mode, tree type)
3538 unsigned int alignment;
3540 alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode);
3541 if (alignment < PARM_BOUNDARY)
3542 alignment = PARM_BOUNDARY;
3543 if (alignment > STACK_BOUNDARY)
3544 alignment = STACK_BOUNDARY;
3548 /* Return true if FUNCTION_ARG_PADDING (MODE, TYPE) should return
3549 upward rather than downward. In other words, return true if the
3550 first byte of the stack slot has useful data, false if the last
3554 mips_pad_arg_upward (enum machine_mode mode, tree type)
3556 /* On little-endian targets, the first byte of every stack argument
3557 is passed in the first byte of the stack slot. */
3558 if (!BYTES_BIG_ENDIAN)
3561 /* Otherwise, integral types are padded downward: the last byte of a
3562 stack argument is passed in the last byte of the stack slot. */
3564 ? INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)
3565 : GET_MODE_CLASS (mode) == MODE_INT)
3568 /* Big-endian o64 pads floating-point arguments downward. */
3569 if (mips_abi == ABI_O64)
3570 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
3573 /* Other types are padded upward for o32, o64, n32 and n64. */
3574 if (mips_abi != ABI_EABI)
3577 /* Arguments smaller than a stack slot are padded downward. */
3578 if (mode != BLKmode)
3579 return (GET_MODE_BITSIZE (mode) >= PARM_BOUNDARY);
3581 return (int_size_in_bytes (type) >= (PARM_BOUNDARY / BITS_PER_UNIT));
3585 /* Likewise BLOCK_REG_PADDING (MODE, TYPE, ...). Return !BYTES_BIG_ENDIAN
3586 if the least significant byte of the register has useful data. Return
3587 the opposite if the most significant byte does. */
3590 mips_pad_reg_upward (enum machine_mode mode, tree type)
3592 /* No shifting is required for floating-point arguments. */
3593 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
3594 return !BYTES_BIG_ENDIAN;
3596 /* Otherwise, apply the same padding to register arguments as we do
3597 to stack arguments. */
3598 return mips_pad_arg_upward (mode, type);
3602 mips_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3603 tree type, int *pretend_size, int no_rtl)
3605 CUMULATIVE_ARGS local_cum;
3606 int gp_saved, fp_saved;
3608 /* The caller has advanced CUM up to, but not beyond, the last named
3609 argument. Advance a local copy of CUM past the last "real" named
3610 argument, to find out how many registers are left over. */
3613 FUNCTION_ARG_ADVANCE (local_cum, mode, type, 1);
3615 /* Found out how many registers we need to save. */
3616 gp_saved = MAX_ARGS_IN_REGISTERS - local_cum.num_gprs;
3617 fp_saved = (EABI_FLOAT_VARARGS_P
3618 ? MAX_ARGS_IN_REGISTERS - local_cum.num_fprs
3627 ptr = virtual_incoming_args_rtx;
3632 ptr = plus_constant (ptr, local_cum.num_gprs * UNITS_PER_WORD);
3636 ptr = plus_constant (ptr, -gp_saved * UNITS_PER_WORD);
3639 mem = gen_rtx_MEM (BLKmode, ptr);
3640 set_mem_alias_set (mem, get_varargs_alias_set ());
3642 move_block_from_reg (local_cum.num_gprs + GP_ARG_FIRST,
3647 /* We can't use move_block_from_reg, because it will use
3649 enum machine_mode mode;
3652 /* Set OFF to the offset from virtual_incoming_args_rtx of
3653 the first float register. The FP save area lies below
3654 the integer one, and is aligned to UNITS_PER_FPVALUE bytes. */
3655 off = -gp_saved * UNITS_PER_WORD;
3656 off &= ~(UNITS_PER_FPVALUE - 1);
3657 off -= fp_saved * UNITS_PER_FPREG;
3659 mode = TARGET_SINGLE_FLOAT ? SFmode : DFmode;
3661 for (i = local_cum.num_fprs; i < MAX_ARGS_IN_REGISTERS; i += FP_INC)
3665 ptr = plus_constant (virtual_incoming_args_rtx, off);
3666 mem = gen_rtx_MEM (mode, ptr);
3667 set_mem_alias_set (mem, get_varargs_alias_set ());
3668 emit_move_insn (mem, gen_rtx_REG (mode, FP_ARG_FIRST + i));
3669 off += UNITS_PER_HWFPVALUE;
3675 /* No need for pretend arguments: the register parameter area was
3676 allocated by the caller. */
3680 *pretend_size = (gp_saved * UNITS_PER_WORD) + (fp_saved * UNITS_PER_FPREG);
3683 /* Create the va_list data type.
3684 We keep 3 pointers, and two offsets.
3685 Two pointers are to the overflow area, which starts at the CFA.
3686 One of these is constant, for addressing into the GPR save area below it.
3687 The other is advanced up the stack through the overflow region.
3688 The third pointer is to the GPR save area. Since the FPR save area
3689 is just below it, we can address FPR slots off this pointer.
3690 We also keep two one-byte offsets, which are to be subtracted from the
3691 constant pointers to yield addresses in the GPR and FPR save areas.
3692 These are downcounted as float or non-float arguments are used,
3693 and when they get to zero, the argument must be obtained from the
3695 If !EABI_FLOAT_VARARGS_P, then no FPR save area exists, and a single
3696 pointer is enough. It's started at the GPR save area, and is
3698 Note that the GPR save area is not constant size, due to optimization
3699 in the prologue. Hence, we can't use a design with two pointers
3700 and two offsets, although we could have designed this with two pointers
3701 and three offsets. */
3704 mips_build_builtin_va_list (void)
3706 if (EABI_FLOAT_VARARGS_P)
3708 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff, f_res, record;
3711 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
3713 f_ovfl = build_decl (FIELD_DECL, get_identifier ("__overflow_argptr"),
3715 f_gtop = build_decl (FIELD_DECL, get_identifier ("__gpr_top"),
3717 f_ftop = build_decl (FIELD_DECL, get_identifier ("__fpr_top"),
3719 f_goff = build_decl (FIELD_DECL, get_identifier ("__gpr_offset"),
3720 unsigned_char_type_node);
3721 f_foff = build_decl (FIELD_DECL, get_identifier ("__fpr_offset"),
3722 unsigned_char_type_node);
3723 /* Explicitly pad to the size of a pointer, so that -Wpadded won't
3724 warn on every user file. */
3725 index = build_int_cst (NULL_TREE, GET_MODE_SIZE (ptr_mode) - 2 - 1);
3726 array = build_array_type (unsigned_char_type_node,
3727 build_index_type (index));
3728 f_res = build_decl (FIELD_DECL, get_identifier ("__reserved"), array);
3730 DECL_FIELD_CONTEXT (f_ovfl) = record;
3731 DECL_FIELD_CONTEXT (f_gtop) = record;
3732 DECL_FIELD_CONTEXT (f_ftop) = record;
3733 DECL_FIELD_CONTEXT (f_goff) = record;
3734 DECL_FIELD_CONTEXT (f_foff) = record;
3735 DECL_FIELD_CONTEXT (f_res) = record;
3737 TYPE_FIELDS (record) = f_ovfl;
3738 TREE_CHAIN (f_ovfl) = f_gtop;
3739 TREE_CHAIN (f_gtop) = f_ftop;
3740 TREE_CHAIN (f_ftop) = f_goff;
3741 TREE_CHAIN (f_goff) = f_foff;
3742 TREE_CHAIN (f_foff) = f_res;
3744 layout_type (record);
3747 else if (TARGET_IRIX && TARGET_IRIX6)
3748 /* On IRIX 6, this type is 'char *'. */
3749 return build_pointer_type (char_type_node);
3751 /* Otherwise, we use 'void *'. */
3752 return ptr_type_node;
3755 /* Implement va_start. */
3758 mips_va_start (tree valist, rtx nextarg)
3760 const CUMULATIVE_ARGS *cum = ¤t_function_args_info;
3762 /* ARG_POINTER_REGNUM is initialized to STACK_POINTER_BOUNDARY, but
3763 since the stack is aligned for a pair of argument-passing slots,
3764 and the beginning of a variable argument list may be an odd slot,
3765 we have to decrease its alignment. */
3766 if (cfun && cfun->emit->regno_pointer_align)
3767 while (((current_function_pretend_args_size * BITS_PER_UNIT)
3768 & (REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) - 1)) != 0)
3769 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) /= 2;
3771 if (mips_abi == ABI_EABI)
3773 int gpr_save_area_size;
3776 = (MAX_ARGS_IN_REGISTERS - cum->num_gprs) * UNITS_PER_WORD;
3778 if (EABI_FLOAT_VARARGS_P)
3780 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff;
3781 tree ovfl, gtop, ftop, goff, foff;
3784 int fpr_save_area_size;
3786 f_ovfl = TYPE_FIELDS (va_list_type_node);
3787 f_gtop = TREE_CHAIN (f_ovfl);
3788 f_ftop = TREE_CHAIN (f_gtop);
3789 f_goff = TREE_CHAIN (f_ftop);
3790 f_foff = TREE_CHAIN (f_goff);
3792 ovfl = build (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl,
3794 gtop = build (COMPONENT_REF, TREE_TYPE (f_gtop), valist, f_gtop,
3796 ftop = build (COMPONENT_REF, TREE_TYPE (f_ftop), valist, f_ftop,
3798 goff = build (COMPONENT_REF, TREE_TYPE (f_goff), valist, f_goff,
3800 foff = build (COMPONENT_REF, TREE_TYPE (f_foff), valist, f_foff,
3803 /* Emit code to initialize OVFL, which points to the next varargs
3804 stack argument. CUM->STACK_WORDS gives the number of stack
3805 words used by named arguments. */
3806 t = make_tree (TREE_TYPE (ovfl), virtual_incoming_args_rtx);
3807 if (cum->stack_words > 0)
3808 t = build (PLUS_EXPR, TREE_TYPE (ovfl), t,
3809 build_int_cst (NULL_TREE,
3810 cum->stack_words * UNITS_PER_WORD));
3811 t = build (MODIFY_EXPR, TREE_TYPE (ovfl), ovfl, t);
3812 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3814 /* Emit code to initialize GTOP, the top of the GPR save area. */
3815 t = make_tree (TREE_TYPE (gtop), virtual_incoming_args_rtx);
3816 t = build (MODIFY_EXPR, TREE_TYPE (gtop), gtop, t);
3817 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3819 /* Emit code to initialize FTOP, the top of the FPR save area.
3820 This address is gpr_save_area_bytes below GTOP, rounded
3821 down to the next fp-aligned boundary. */
3822 t = make_tree (TREE_TYPE (ftop), virtual_incoming_args_rtx);
3823 fpr_offset = gpr_save_area_size + UNITS_PER_FPVALUE - 1;
3824 fpr_offset &= ~(UNITS_PER_FPVALUE - 1);
3826 t = build (PLUS_EXPR, TREE_TYPE (ftop), t,
3827 build_int_cst (NULL_TREE, -fpr_offset));
3828 t = build (MODIFY_EXPR, TREE_TYPE (ftop), ftop, t);
3829 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3831 /* Emit code to initialize GOFF, the offset from GTOP of the
3832 next GPR argument. */
3833 t = build (MODIFY_EXPR, TREE_TYPE (goff), goff,
3834 build_int_cst (NULL_TREE, gpr_save_area_size));
3835 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3837 /* Likewise emit code to initialize FOFF, the offset from FTOP
3838 of the next FPR argument. */
3840 = (MAX_ARGS_IN_REGISTERS - cum->num_fprs) * UNITS_PER_FPREG;
3841 t = build (MODIFY_EXPR, TREE_TYPE (foff), foff,
3842 build_int_cst (NULL_TREE, fpr_save_area_size));
3843 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3847 /* Everything is in the GPR save area, or in the overflow
3848 area which is contiguous with it. */
3849 nextarg = plus_constant (nextarg, -gpr_save_area_size);
3850 std_expand_builtin_va_start (valist, nextarg);
3854 std_expand_builtin_va_start (valist, nextarg);
3857 /* Implement va_arg. */
3860 mips_gimplify_va_arg_expr (tree valist, tree type, tree *pre_p, tree *post_p)
3862 HOST_WIDE_INT size, rsize;
3866 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
3869 type = build_pointer_type (type);
3871 size = int_size_in_bytes (type);
3872 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
3874 if (mips_abi != ABI_EABI || !EABI_FLOAT_VARARGS_P)
3875 addr = std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
3878 /* Not a simple merged stack. */
3880 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff;
3881 tree ovfl, top, off, align;
3882 HOST_WIDE_INT osize;
3885 f_ovfl = TYPE_FIELDS (va_list_type_node);
3886 f_gtop = TREE_CHAIN (f_ovfl);
3887 f_ftop = TREE_CHAIN (f_gtop);
3888 f_goff = TREE_CHAIN (f_ftop);
3889 f_foff = TREE_CHAIN (f_goff);
3891 /* We maintain separate pointers and offsets for floating-point
3892 and integer arguments, but we need similar code in both cases.
3895 TOP be the top of the register save area;
3896 OFF be the offset from TOP of the next register;
3897 ADDR_RTX be the address of the argument;
3898 RSIZE be the number of bytes used to store the argument
3899 when it's in the register save area;
3900 OSIZE be the number of bytes used to store it when it's
3901 in the stack overflow area; and
3902 PADDING be (BYTES_BIG_ENDIAN ? OSIZE - RSIZE : 0)
3904 The code we want is:
3906 1: off &= -rsize; // round down
3909 4: addr_rtx = top - off;
3914 9: ovfl += ((intptr_t) ovfl + osize - 1) & -osize;
3915 10: addr_rtx = ovfl + PADDING;
3919 [1] and [9] can sometimes be optimized away. */
3921 ovfl = build (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl,
3924 if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT
3925 && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FPVALUE)
3927 top = build (COMPONENT_REF, TREE_TYPE (f_ftop), valist, f_ftop,
3929 off = build (COMPONENT_REF, TREE_TYPE (f_foff), valist, f_foff,
3932 /* When floating-point registers are saved to the stack,
3933 each one will take up UNITS_PER_HWFPVALUE bytes, regardless
3934 of the float's precision. */
3935 rsize = UNITS_PER_HWFPVALUE;
3937 /* Overflow arguments are padded to UNITS_PER_WORD bytes
3938 (= PARM_BOUNDARY bits). This can be different from RSIZE
3941 (1) On 32-bit targets when TYPE is a structure such as:
3943 struct s { float f; };
3945 Such structures are passed in paired FPRs, so RSIZE
3946 will be 8 bytes. However, the structure only takes
3947 up 4 bytes of memory, so OSIZE will only be 4.
3949 (2) In combinations such as -mgp64 -msingle-float
3950 -fshort-double. Doubles passed in registers
3951 will then take up 4 (UNITS_PER_HWFPVALUE) bytes,
3952 but those passed on the stack take up
3953 UNITS_PER_WORD bytes. */
3954 osize = MAX (GET_MODE_SIZE (TYPE_MODE (type)), UNITS_PER_WORD);
3958 top = build (COMPONENT_REF, TREE_TYPE (f_gtop), valist, f_gtop,
3960 off = build (COMPONENT_REF, TREE_TYPE (f_goff), valist, f_goff,
3962 if (rsize > UNITS_PER_WORD)
3964 /* [1] Emit code for: off &= -rsize. */
3965 t = build (BIT_AND_EXPR, TREE_TYPE (off), off,
3966 build_int_cst (NULL_TREE, -rsize));
3967 t = build (MODIFY_EXPR, TREE_TYPE (off), off, t);
3968 gimplify_and_add (t, pre_p);
3973 /* [2] Emit code to branch if off == 0. */
3974 t = build (NE_EXPR, boolean_type_node, off,
3975 build_int_cst (TREE_TYPE (off), 0));
3976 addr = build (COND_EXPR, ptr_type_node, t, NULL, NULL);
3978 /* [5] Emit code for: off -= rsize. We do this as a form of
3979 post-increment not available to C. Also widen for the
3980 coming pointer arithmetic. */
3981 t = fold_convert (TREE_TYPE (off), build_int_cst (NULL_TREE, rsize));
3982 t = build (POSTDECREMENT_EXPR, TREE_TYPE (off), off, t);
3983 t = fold_convert (sizetype, t);
3984 t = fold_convert (TREE_TYPE (top), t);
3986 /* [4] Emit code for: addr_rtx = top - off. On big endian machines,
3987 the argument has RSIZE - SIZE bytes of leading padding. */
3988 t = build (MINUS_EXPR, TREE_TYPE (top), top, t);
3989 if (BYTES_BIG_ENDIAN && rsize > size)
3991 u = fold_convert (TREE_TYPE (t), build_int_cst (NULL_TREE,
3993 t = build (PLUS_EXPR, TREE_TYPE (t), t, u);
3995 COND_EXPR_THEN (addr) = t;
3997 if (osize > UNITS_PER_WORD)
3999 /* [9] Emit: ovfl += ((intptr_t) ovfl + osize - 1) & -osize. */
4000 u = fold_convert (TREE_TYPE (ovfl),
4001 build_int_cst (NULL_TREE, osize - 1));
4002 t = build (PLUS_EXPR, TREE_TYPE (ovfl), ovfl, u);
4003 u = fold_convert (TREE_TYPE (ovfl),
4004 build_int_cst (NULL_TREE, -osize));
4005 t = build (BIT_AND_EXPR, TREE_TYPE (ovfl), t, u);
4006 align = build (MODIFY_EXPR, TREE_TYPE (ovfl), ovfl, t);
4011 /* [10, 11]. Emit code to store ovfl in addr_rtx, then
4012 post-increment ovfl by osize. On big-endian machines,
4013 the argument has OSIZE - SIZE bytes of leading padding. */
4014 u = fold_convert (TREE_TYPE (ovfl),
4015 build_int_cst (NULL_TREE, osize));
4016 t = build (POSTINCREMENT_EXPR, TREE_TYPE (ovfl), ovfl, u);
4017 if (BYTES_BIG_ENDIAN && osize > size)
4019 u = fold_convert (TREE_TYPE (t),
4020 build_int_cst (NULL_TREE, osize - size));
4021 t = build (PLUS_EXPR, TREE_TYPE (t), t, u);
4024 /* String [9] and [10,11] together. */
4026 t = build (COMPOUND_EXPR, TREE_TYPE (t), align, t);
4027 COND_EXPR_ELSE (addr) = t;
4029 addr = fold_convert (build_pointer_type (type), addr);
4030 addr = build_fold_indirect_ref (addr);
4034 addr = build_fold_indirect_ref (addr);
4039 /* Return true if it is possible to use left/right accesses for a
4040 bitfield of WIDTH bits starting BITPOS bits into *OP. When
4041 returning true, update *OP, *LEFT and *RIGHT as follows:
4043 *OP is a BLKmode reference to the whole field.
4045 *LEFT is a QImode reference to the first byte if big endian or
4046 the last byte if little endian. This address can be used in the
4047 left-side instructions (lwl, swl, ldl, sdl).
4049 *RIGHT is a QImode reference to the opposite end of the field and
4050 can be used in the parterning right-side instruction. */
4053 mips_get_unaligned_mem (rtx *op, unsigned int width, int bitpos,
4054 rtx *left, rtx *right)
4058 /* Check that the operand really is a MEM. Not all the extv and
4059 extzv predicates are checked. */
4063 /* Check that the size is valid. */
4064 if (width != 32 && (!TARGET_64BIT || width != 64))
4067 /* We can only access byte-aligned values. Since we are always passed
4068 a reference to the first byte of the field, it is not necessary to
4069 do anything with BITPOS after this check. */
4070 if (bitpos % BITS_PER_UNIT != 0)
4073 /* Reject aligned bitfields: we want to use a normal load or store
4074 instead of a left/right pair. */
4075 if (MEM_ALIGN (*op) >= width)
4078 /* Adjust *OP to refer to the whole field. This also has the effect
4079 of legitimizing *OP's address for BLKmode, possibly simplifying it. */
4080 *op = adjust_address (*op, BLKmode, 0);
4081 set_mem_size (*op, GEN_INT (width / BITS_PER_UNIT));
4083 /* Get references to both ends of the field. We deliberately don't