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, 51 Franklin Street, Fifth Floor,
24 Boston, MA 02110-1301, 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"
61 /* True if X is an unspec wrapper around a SYMBOL_REF or LABEL_REF. */
62 #define UNSPEC_ADDRESS_P(X) \
63 (GET_CODE (X) == UNSPEC \
64 && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \
65 && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)
67 /* Extract the symbol or label from UNSPEC wrapper X. */
68 #define UNSPEC_ADDRESS(X) \
71 /* Extract the symbol type from UNSPEC wrapper X. */
72 #define UNSPEC_ADDRESS_TYPE(X) \
73 ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))
75 /* The maximum distance between the top of the stack frame and the
76 value $sp has when we save & restore registers.
78 Use a maximum gap of 0x100 in the mips16 case. We can then use
79 unextended instructions to save and restore registers, and to
80 allocate and deallocate the top part of the frame.
82 The value in the !mips16 case must be a SMALL_OPERAND and must
83 preserve the maximum stack alignment. */
84 #define MIPS_MAX_FIRST_STACK_STEP (TARGET_MIPS16 ? 0x100 : 0x7ff0)
86 /* True if INSN is a mips.md pattern or asm statement. */
87 #define USEFUL_INSN_P(INSN) \
89 && GET_CODE (PATTERN (INSN)) != USE \
90 && GET_CODE (PATTERN (INSN)) != CLOBBER \
91 && GET_CODE (PATTERN (INSN)) != ADDR_VEC \
92 && GET_CODE (PATTERN (INSN)) != ADDR_DIFF_VEC)
94 /* If INSN is a delayed branch sequence, return the first instruction
95 in the sequence, otherwise return INSN itself. */
96 #define SEQ_BEGIN(INSN) \
97 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
98 ? XVECEXP (PATTERN (INSN), 0, 0) \
101 /* Likewise for the last instruction in a delayed branch sequence. */
102 #define SEQ_END(INSN) \
103 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
104 ? XVECEXP (PATTERN (INSN), 0, XVECLEN (PATTERN (INSN), 0) - 1) \
107 /* Execute the following loop body with SUBINSN set to each instruction
108 between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */
109 #define FOR_EACH_SUBINSN(SUBINSN, INSN) \
110 for ((SUBINSN) = SEQ_BEGIN (INSN); \
111 (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \
112 (SUBINSN) = NEXT_INSN (SUBINSN))
114 /* Classifies an address.
117 A natural register + offset address. The register satisfies
118 mips_valid_base_register_p and the offset is a const_arith_operand.
121 A LO_SUM rtx. The first operand is a valid base register and
122 the second operand is a symbolic address.
125 A signed 16-bit constant address.
128 A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */
129 enum mips_address_type {
136 /* Classifies the prototype of a builtin function. */
137 enum mips_function_type
139 MIPS_V2SF_FTYPE_V2SF,
140 MIPS_V2SF_FTYPE_V2SF_V2SF,
141 MIPS_V2SF_FTYPE_V2SF_V2SF_INT,
142 MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF,
143 MIPS_V2SF_FTYPE_SF_SF,
144 MIPS_INT_FTYPE_V2SF_V2SF,
145 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF,
146 MIPS_INT_FTYPE_SF_SF,
147 MIPS_INT_FTYPE_DF_DF,
154 /* For MIPS DSP ASE */
156 MIPS_DI_FTYPE_DI_SI_SI,
157 MIPS_DI_FTYPE_DI_V2HI_V2HI,
158 MIPS_DI_FTYPE_DI_V4QI_V4QI,
160 MIPS_SI_FTYPE_PTR_SI,
164 MIPS_SI_FTYPE_V2HI_V2HI,
166 MIPS_SI_FTYPE_V4QI_V4QI,
169 MIPS_V2HI_FTYPE_SI_SI,
170 MIPS_V2HI_FTYPE_V2HI,
171 MIPS_V2HI_FTYPE_V2HI_SI,
172 MIPS_V2HI_FTYPE_V2HI_V2HI,
173 MIPS_V2HI_FTYPE_V4QI,
174 MIPS_V2HI_FTYPE_V4QI_V2HI,
176 MIPS_V4QI_FTYPE_V2HI_V2HI,
177 MIPS_V4QI_FTYPE_V4QI_SI,
178 MIPS_V4QI_FTYPE_V4QI_V4QI,
179 MIPS_VOID_FTYPE_SI_SI,
180 MIPS_VOID_FTYPE_V2HI_V2HI,
181 MIPS_VOID_FTYPE_V4QI_V4QI,
183 /* For MIPS DSP REV 2 ASE. */
184 MIPS_V4QI_FTYPE_V4QI,
185 MIPS_SI_FTYPE_SI_SI_SI,
186 MIPS_DI_FTYPE_DI_USI_USI,
188 MIPS_DI_FTYPE_USI_USI,
189 MIPS_V2HI_FTYPE_SI_SI_SI,
195 /* Specifies how a builtin function should be converted into rtl. */
196 enum mips_builtin_type
198 /* The builtin corresponds directly to an .md pattern. The return
199 value is mapped to operand 0 and the arguments are mapped to
200 operands 1 and above. */
203 /* The builtin corresponds directly to an .md pattern. There is no return
204 value and the arguments are mapped to operands 0 and above. */
205 MIPS_BUILTIN_DIRECT_NO_TARGET,
207 /* The builtin corresponds to a comparison instruction followed by
208 a mips_cond_move_tf_ps pattern. The first two arguments are the
209 values to compare and the second two arguments are the vector
210 operands for the movt.ps or movf.ps instruction (in assembly order). */
214 /* The builtin corresponds to a V2SF comparison instruction. Operand 0
215 of this instruction is the result of the comparison, which has mode
216 CCV2 or CCV4. The function arguments are mapped to operands 1 and
217 above. The function's return value is an SImode boolean that is
218 true under the following conditions:
220 MIPS_BUILTIN_CMP_ANY: one of the registers is true
221 MIPS_BUILTIN_CMP_ALL: all of the registers are true
222 MIPS_BUILTIN_CMP_LOWER: the first register is true
223 MIPS_BUILTIN_CMP_UPPER: the second register is true. */
224 MIPS_BUILTIN_CMP_ANY,
225 MIPS_BUILTIN_CMP_ALL,
226 MIPS_BUILTIN_CMP_UPPER,
227 MIPS_BUILTIN_CMP_LOWER,
229 /* As above, but the instruction only sets a single $fcc register. */
230 MIPS_BUILTIN_CMP_SINGLE,
232 /* For generating bposge32 branch instructions in MIPS32 DSP ASE. */
233 MIPS_BUILTIN_BPOSGE32
236 /* Invokes MACRO (COND) for each c.cond.fmt condition. */
237 #define MIPS_FP_CONDITIONS(MACRO) \
255 /* Enumerates the codes above as MIPS_FP_COND_<X>. */
256 #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X
257 enum mips_fp_condition {
258 MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)
261 /* Index X provides the string representation of MIPS_FP_COND_<X>. */
262 #define STRINGIFY(X) #X
263 static const char *const mips_fp_conditions[] = {
264 MIPS_FP_CONDITIONS (STRINGIFY)
267 /* A function to save or store a register. The first argument is the
268 register and the second is the stack slot. */
269 typedef void (*mips_save_restore_fn) (rtx, rtx);
271 struct mips16_constant;
272 struct mips_arg_info;
273 struct mips_address_info;
274 struct mips_integer_op;
277 static enum mips_symbol_type mips_classify_symbol (rtx);
278 static bool mips_valid_base_register_p (rtx, enum machine_mode, int);
279 static bool mips_symbolic_address_p (enum mips_symbol_type, enum machine_mode);
280 static bool mips_classify_address (struct mips_address_info *, rtx,
281 enum machine_mode, int);
282 static bool mips_cannot_force_const_mem (rtx);
283 static bool mips_use_blocks_for_constant_p (enum machine_mode, rtx);
284 static int mips_symbol_insns (enum mips_symbol_type);
285 static bool mips16_unextended_reference_p (enum machine_mode mode, rtx, rtx);
286 static rtx mips_force_temporary (rtx, rtx);
287 static rtx mips_unspec_offset_high (rtx, rtx, rtx, enum mips_symbol_type);
288 static rtx mips_add_offset (rtx, rtx, HOST_WIDE_INT);
289 static unsigned int mips_build_shift (struct mips_integer_op *, HOST_WIDE_INT);
290 static unsigned int mips_build_lower (struct mips_integer_op *,
291 unsigned HOST_WIDE_INT);
292 static unsigned int mips_build_integer (struct mips_integer_op *,
293 unsigned HOST_WIDE_INT);
294 static void mips_legitimize_const_move (enum machine_mode, rtx, rtx);
295 static int m16_check_op (rtx, int, int, int);
296 static bool mips_rtx_costs (rtx, int, int, int *);
297 static int mips_address_cost (rtx);
298 static void mips_emit_compare (enum rtx_code *, rtx *, rtx *, bool);
299 static void mips_load_call_address (rtx, rtx, int);
300 static bool mips_function_ok_for_sibcall (tree, tree);
301 static void mips_block_move_straight (rtx, rtx, HOST_WIDE_INT);
302 static void mips_adjust_block_mem (rtx, HOST_WIDE_INT, rtx *, rtx *);
303 static void mips_block_move_loop (rtx, rtx, HOST_WIDE_INT);
304 static void mips_arg_info (const CUMULATIVE_ARGS *, enum machine_mode,
305 tree, int, struct mips_arg_info *);
306 static bool mips_get_unaligned_mem (rtx *, unsigned int, int, rtx *, rtx *);
307 static void mips_set_architecture (const struct mips_cpu_info *);
308 static void mips_set_tune (const struct mips_cpu_info *);
309 static bool mips_handle_option (size_t, const char *, int);
310 static struct machine_function *mips_init_machine_status (void);
311 static void print_operand_reloc (FILE *, rtx, const char **);
312 static void mips_file_start (void);
313 static bool mips_rewrite_small_data_p (rtx);
314 static int mips_small_data_pattern_1 (rtx *, void *);
315 static int mips_rewrite_small_data_1 (rtx *, void *);
316 static bool mips_function_has_gp_insn (void);
317 static unsigned int mips_global_pointer (void);
318 static bool mips_save_reg_p (unsigned int);
319 static void mips_save_restore_reg (enum machine_mode, int, HOST_WIDE_INT,
320 mips_save_restore_fn);
321 static void mips_for_each_saved_reg (HOST_WIDE_INT, mips_save_restore_fn);
322 static void mips_output_cplocal (void);
323 static void mips_emit_loadgp (void);
324 static void mips_output_function_prologue (FILE *, HOST_WIDE_INT);
325 static void mips_set_frame_expr (rtx);
326 static rtx mips_frame_set (rtx, rtx);
327 static void mips_save_reg (rtx, rtx);
328 static void mips_output_function_epilogue (FILE *, HOST_WIDE_INT);
329 static void mips_restore_reg (rtx, rtx);
330 static void mips_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
331 HOST_WIDE_INT, tree);
332 static int symbolic_expression_p (rtx);
333 static section *mips_select_rtx_section (enum machine_mode, rtx,
334 unsigned HOST_WIDE_INT);
335 static section *mips_function_rodata_section (tree);
336 static bool mips_in_small_data_p (tree);
337 static bool mips_use_anchors_for_symbol_p (rtx);
338 static int mips_fpr_return_fields (tree, tree *);
339 static bool mips_return_in_msb (tree);
340 static rtx mips_return_fpr_pair (enum machine_mode mode,
341 enum machine_mode mode1, HOST_WIDE_INT,
342 enum machine_mode mode2, HOST_WIDE_INT);
343 static rtx mips16_gp_pseudo_reg (void);
344 static void mips16_fp_args (FILE *, int, int);
345 static void build_mips16_function_stub (FILE *);
346 static rtx dump_constants_1 (enum machine_mode, rtx, rtx);
347 static void dump_constants (struct mips16_constant *, rtx);
348 static int mips16_insn_length (rtx);
349 static int mips16_rewrite_pool_refs (rtx *, void *);
350 static void mips16_lay_out_constants (void);
351 static void mips_sim_reset (struct mips_sim *);
352 static void mips_sim_init (struct mips_sim *, state_t);
353 static void mips_sim_next_cycle (struct mips_sim *);
354 static void mips_sim_wait_reg (struct mips_sim *, rtx, rtx);
355 static int mips_sim_wait_regs_2 (rtx *, void *);
356 static void mips_sim_wait_regs_1 (rtx *, void *);
357 static void mips_sim_wait_regs (struct mips_sim *, rtx);
358 static void mips_sim_wait_units (struct mips_sim *, rtx);
359 static void mips_sim_wait_insn (struct mips_sim *, rtx);
360 static void mips_sim_record_set (rtx, rtx, void *);
361 static void mips_sim_issue_insn (struct mips_sim *, rtx);
362 static void mips_sim_issue_nop (struct mips_sim *);
363 static void mips_sim_finish_insn (struct mips_sim *, rtx);
364 static void vr4130_avoid_branch_rt_conflict (rtx);
365 static void vr4130_align_insns (void);
366 static void mips_avoid_hazard (rtx, rtx, int *, rtx *, rtx);
367 static void mips_avoid_hazards (void);
368 static void mips_reorg (void);
369 static bool mips_strict_matching_cpu_name_p (const char *, const char *);
370 static bool mips_matching_cpu_name_p (const char *, const char *);
371 static const struct mips_cpu_info *mips_parse_cpu (const char *);
372 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
373 static bool mips_return_in_memory (tree, tree);
374 static bool mips_strict_argument_naming (CUMULATIVE_ARGS *);
375 static void mips_macc_chains_record (rtx);
376 static void mips_macc_chains_reorder (rtx *, int);
377 static void vr4130_true_reg_dependence_p_1 (rtx, rtx, void *);
378 static bool vr4130_true_reg_dependence_p (rtx);
379 static bool vr4130_swap_insns_p (rtx, rtx);
380 static void vr4130_reorder (rtx *, int);
381 static void mips_promote_ready (rtx *, int, int);
382 static int mips_sched_reorder (FILE *, int, rtx *, int *, int);
383 static int mips_variable_issue (FILE *, int, rtx, int);
384 static int mips_adjust_cost (rtx, rtx, rtx, int);
385 static int mips_issue_rate (void);
386 static int mips_multipass_dfa_lookahead (void);
387 static void mips_init_libfuncs (void);
388 static void mips_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
390 static tree mips_build_builtin_va_list (void);
391 static tree mips_gimplify_va_arg_expr (tree, tree, tree *, tree *);
392 static bool mips_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode mode,
394 static bool mips_callee_copies (CUMULATIVE_ARGS *, enum machine_mode mode,
396 static int mips_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode mode,
398 static bool mips_valid_pointer_mode (enum machine_mode);
399 static bool mips_vector_mode_supported_p (enum machine_mode);
400 static rtx mips_prepare_builtin_arg (enum insn_code, unsigned int, tree, unsigned int);
401 static rtx mips_prepare_builtin_target (enum insn_code, unsigned int, rtx);
402 static rtx mips_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
403 static void mips_init_builtins (void);
404 static rtx mips_expand_builtin_direct (enum insn_code, rtx, tree, bool);
405 static rtx mips_expand_builtin_movtf (enum mips_builtin_type,
406 enum insn_code, enum mips_fp_condition,
408 static rtx mips_expand_builtin_compare (enum mips_builtin_type,
409 enum insn_code, enum mips_fp_condition,
411 static rtx mips_expand_builtin_bposge (enum mips_builtin_type, rtx);
412 static void mips_encode_section_info (tree, rtx, int);
413 static void mips_extra_live_on_entry (bitmap);
414 static int mips_mode_rep_extended (enum machine_mode, enum machine_mode);
415 static bool mips_offset_within_alignment_p (rtx, HOST_WIDE_INT);
417 /* Structure to be filled in by compute_frame_size with register
418 save masks, and offsets for the current function. */
420 struct mips_frame_info GTY(())
422 HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up */
423 HOST_WIDE_INT var_size; /* # bytes that variables take up */
424 HOST_WIDE_INT args_size; /* # bytes that outgoing arguments take up */
425 HOST_WIDE_INT cprestore_size; /* # bytes that the .cprestore slot takes up */
426 HOST_WIDE_INT gp_reg_size; /* # bytes needed to store gp regs */
427 HOST_WIDE_INT fp_reg_size; /* # bytes needed to store fp regs */
428 unsigned int mask; /* mask of saved gp registers */
429 unsigned int fmask; /* mask of saved fp registers */
430 HOST_WIDE_INT gp_save_offset; /* offset from vfp to store gp registers */
431 HOST_WIDE_INT fp_save_offset; /* offset from vfp to store fp registers */
432 HOST_WIDE_INT gp_sp_offset; /* offset from new sp to store gp registers */
433 HOST_WIDE_INT fp_sp_offset; /* offset from new sp to store fp registers */
434 bool initialized; /* true if frame size already calculated */
435 int num_gp; /* number of gp registers saved */
436 int num_fp; /* number of fp registers saved */
439 struct machine_function GTY(()) {
440 /* Pseudo-reg holding the value of $28 in a mips16 function which
441 refers to GP relative global variables. */
442 rtx mips16_gp_pseudo_rtx;
444 /* The number of extra stack bytes taken up by register varargs.
445 This area is allocated by the callee at the very top of the frame. */
448 /* Current frame information, calculated by compute_frame_size. */
449 struct mips_frame_info frame;
451 /* The register to use as the global pointer within this function. */
452 unsigned int global_pointer;
454 /* True if mips_adjust_insn_length should ignore an instruction's
456 bool ignore_hazard_length_p;
458 /* True if the whole function is suitable for .set noreorder and
460 bool all_noreorder_p;
462 /* True if the function is known to have an instruction that needs $gp. */
466 /* Information about a single argument. */
469 /* True if the argument is passed in a floating-point register, or
470 would have been if we hadn't run out of registers. */
473 /* The number of words passed in registers, rounded up. */
474 unsigned int reg_words;
476 /* For EABI, the offset of the first register from GP_ARG_FIRST or
477 FP_ARG_FIRST. For other ABIs, the offset of the first register from
478 the start of the ABI's argument structure (see the CUMULATIVE_ARGS
479 comment for details).
481 The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely
483 unsigned int reg_offset;
485 /* The number of words that must be passed on the stack, rounded up. */
486 unsigned int stack_words;
488 /* The offset from the start of the stack overflow area of the argument's
489 first stack word. Only meaningful when STACK_WORDS is nonzero. */
490 unsigned int stack_offset;
494 /* Information about an address described by mips_address_type.
500 REG is the base register and OFFSET is the constant offset.
503 REG is the register that contains the high part of the address,
504 OFFSET is the symbolic address being referenced and SYMBOL_TYPE
505 is the type of OFFSET's symbol.
508 SYMBOL_TYPE is the type of symbol being referenced. */
510 struct mips_address_info
512 enum mips_address_type type;
515 enum mips_symbol_type symbol_type;
519 /* One stage in a constant building sequence. These sequences have
523 A = A CODE[1] VALUE[1]
524 A = A CODE[2] VALUE[2]
527 where A is an accumulator, each CODE[i] is a binary rtl operation
528 and each VALUE[i] is a constant integer. */
529 struct mips_integer_op {
531 unsigned HOST_WIDE_INT value;
535 /* The largest number of operations needed to load an integer constant.
536 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
537 When the lowest bit is clear, we can try, but reject a sequence with
538 an extra SLL at the end. */
539 #define MIPS_MAX_INTEGER_OPS 7
542 /* Global variables for machine-dependent things. */
544 /* Threshold for data being put into the small data/bss area, instead
545 of the normal data area. */
546 int mips_section_threshold = -1;
548 /* Count the number of .file directives, so that .loc is up to date. */
549 int num_source_filenames = 0;
551 /* Count the number of sdb related labels are generated (to find block
552 start and end boundaries). */
553 int sdb_label_count = 0;
555 /* Next label # for each statement for Silicon Graphics IRIS systems. */
558 /* Name of the file containing the current function. */
559 const char *current_function_file = "";
561 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
567 /* The next branch instruction is a branch likely, not branch normal. */
568 int mips_branch_likely;
570 /* The operands passed to the last cmpMM expander. */
573 /* The target cpu for code generation. */
574 enum processor_type mips_arch;
575 const struct mips_cpu_info *mips_arch_info;
577 /* The target cpu for optimization and scheduling. */
578 enum processor_type mips_tune;
579 const struct mips_cpu_info *mips_tune_info;
581 /* Which instruction set architecture to use. */
584 /* Which ABI to use. */
585 int mips_abi = MIPS_ABI_DEFAULT;
587 /* Cost information to use. */
588 const struct mips_rtx_cost_data *mips_cost;
590 /* Whether we are generating mips16 hard float code. In mips16 mode
591 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
592 -msoft-float was not specified by the user, which means that we
593 should arrange to call mips32 hard floating point code. */
594 int mips16_hard_float;
596 /* The architecture selected by -mipsN. */
597 static const struct mips_cpu_info *mips_isa_info;
599 /* If TRUE, we split addresses into their high and low parts in the RTL. */
600 int mips_split_addresses;
602 /* Mode used for saving/restoring general purpose registers. */
603 static enum machine_mode gpr_mode;
605 /* Array giving truth value on whether or not a given hard register
606 can support a given mode. */
607 char mips_hard_regno_mode_ok[(int)MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
609 /* List of all MIPS punctuation characters used by print_operand. */
610 char mips_print_operand_punct[256];
612 /* Map GCC register number to debugger register number. */
613 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
615 /* A copy of the original flag_delayed_branch: see override_options. */
616 static int mips_flag_delayed_branch;
618 static GTY (()) int mips_output_filename_first_time = 1;
620 /* mips_split_p[X] is true if symbols of type X can be split by
621 mips_split_symbol(). */
622 bool mips_split_p[NUM_SYMBOL_TYPES];
624 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
625 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
626 if they are matched by a special .md file pattern. */
627 static const char *mips_lo_relocs[NUM_SYMBOL_TYPES];
629 /* Likewise for HIGHs. */
630 static const char *mips_hi_relocs[NUM_SYMBOL_TYPES];
632 /* Map hard register number to register class */
633 const enum reg_class mips_regno_to_class[] =
635 LEA_REGS, LEA_REGS, M16_NA_REGS, V1_REG,
636 M16_REGS, M16_REGS, M16_REGS, M16_REGS,
637 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
638 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
639 M16_NA_REGS, M16_NA_REGS, LEA_REGS, LEA_REGS,
640 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
641 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
642 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
643 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
644 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
645 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
646 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
647 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
648 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
649 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
650 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
651 HI_REG, LO_REG, NO_REGS, ST_REGS,
652 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
653 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
654 NO_REGS, ALL_REGS, ALL_REGS, NO_REGS,
655 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
656 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
657 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
658 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
659 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
660 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
661 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
662 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
663 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
664 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
665 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
666 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
667 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
668 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
669 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
670 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
671 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
672 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
673 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
674 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
675 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
676 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
677 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
678 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
679 DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS,
680 DSP_ACC_REGS, DSP_ACC_REGS, ALL_REGS, ALL_REGS,
681 ALL_REGS, ALL_REGS, ALL_REGS, ALL_REGS
684 /* Table of machine dependent attributes. */
685 const struct attribute_spec mips_attribute_table[] =
687 { "long_call", 0, 0, false, true, true, NULL },
688 { NULL, 0, 0, false, false, false, NULL }
691 /* A table describing all the processors gcc knows about. Names are
692 matched in the order listed. The first mention of an ISA level is
693 taken as the canonical name for that ISA.
695 To ease comparison, please keep this table in the same order as
696 gas's mips_cpu_info_table[]. */
697 const struct mips_cpu_info mips_cpu_info_table[] = {
698 /* Entries for generic ISAs */
699 { "mips1", PROCESSOR_R3000, 1 },
700 { "mips2", PROCESSOR_R6000, 2 },
701 { "mips3", PROCESSOR_R4000, 3 },
702 { "mips4", PROCESSOR_R8000, 4 },
703 { "mips32", PROCESSOR_4KC, 32 },
704 { "mips32r2", PROCESSOR_M4K, 33 },
705 { "mips64", PROCESSOR_5KC, 64 },
708 { "r3000", PROCESSOR_R3000, 1 },
709 { "r2000", PROCESSOR_R3000, 1 }, /* = r3000 */
710 { "r3900", PROCESSOR_R3900, 1 },
713 { "r6000", PROCESSOR_R6000, 2 },
716 { "r4000", PROCESSOR_R4000, 3 },
717 { "vr4100", PROCESSOR_R4100, 3 },
718 { "vr4111", PROCESSOR_R4111, 3 },
719 { "vr4120", PROCESSOR_R4120, 3 },
720 { "vr4130", PROCESSOR_R4130, 3 },
721 { "vr4300", PROCESSOR_R4300, 3 },
722 { "r4400", PROCESSOR_R4000, 3 }, /* = r4000 */
723 { "r4600", PROCESSOR_R4600, 3 },
724 { "orion", PROCESSOR_R4600, 3 }, /* = r4600 */
725 { "r4650", PROCESSOR_R4650, 3 },
728 { "r8000", PROCESSOR_R8000, 4 },
729 { "vr5000", PROCESSOR_R5000, 4 },
730 { "vr5400", PROCESSOR_R5400, 4 },
731 { "vr5500", PROCESSOR_R5500, 4 },
732 { "rm7000", PROCESSOR_R7000, 4 },
733 { "rm9000", PROCESSOR_R9000, 4 },
736 { "4kc", PROCESSOR_4KC, 32 },
737 { "4km", PROCESSOR_4KC, 32 }, /* = 4kc */
738 { "4kp", PROCESSOR_4KP, 32 },
740 /* MIPS32 Release 2 */
741 { "m4k", PROCESSOR_M4K, 33 },
742 { "4kec", PROCESSOR_4KC, 33 },
743 { "4kem", PROCESSOR_4KC, 33 },
744 { "4kep", PROCESSOR_4KP, 33 },
745 { "24kc", PROCESSOR_24KC, 33 }, /* 24K no FPU */
746 { "24kf", PROCESSOR_24KF, 33 }, /* 24K 1:2 FPU */
747 { "24kx", PROCESSOR_24KX, 33 }, /* 24K 1:1 FPU */
748 { "24kec", PROCESSOR_24KC, 33 }, /* 24K with DSP */
749 { "24kef", PROCESSOR_24KF, 33 },
750 { "24kex", PROCESSOR_24KX, 33 },
751 { "34kc", PROCESSOR_24KC, 33 }, /* 34K with MT/DSP */
752 { "34kf", PROCESSOR_24KF, 33 },
753 { "34kx", PROCESSOR_24KX, 33 },
754 { "74kc", PROCESSOR_74KC, 33 },
755 { "74kf", PROCESSOR_74KF, 33 },
756 { "74kx", PROCESSOR_74KX, 33 },
759 { "5kc", PROCESSOR_5KC, 64 },
760 { "5kf", PROCESSOR_5KF, 64 },
761 { "20kc", PROCESSOR_20KC, 64 },
762 { "sb1", PROCESSOR_SB1, 64 },
763 { "sb1a", PROCESSOR_SB1A, 64 },
764 { "sr71000", PROCESSOR_SR71000, 64 },
770 /* Default costs. If these are used for a processor we should look
771 up the actual costs. */
772 #define DEFAULT_COSTS COSTS_N_INSNS (6), /* fp_add */ \
773 COSTS_N_INSNS (7), /* fp_mult_sf */ \
774 COSTS_N_INSNS (8), /* fp_mult_df */ \
775 COSTS_N_INSNS (23), /* fp_div_sf */ \
776 COSTS_N_INSNS (36), /* fp_div_df */ \
777 COSTS_N_INSNS (10), /* int_mult_si */ \
778 COSTS_N_INSNS (10), /* int_mult_di */ \
779 COSTS_N_INSNS (69), /* int_div_si */ \
780 COSTS_N_INSNS (69), /* int_div_di */ \
781 2, /* branch_cost */ \
782 4 /* memory_latency */
784 /* Need to replace these with the costs of calling the appropriate
786 #define SOFT_FP_COSTS COSTS_N_INSNS (256), /* fp_add */ \
787 COSTS_N_INSNS (256), /* fp_mult_sf */ \
788 COSTS_N_INSNS (256), /* fp_mult_df */ \
789 COSTS_N_INSNS (256), /* fp_div_sf */ \
790 COSTS_N_INSNS (256) /* fp_div_df */
792 static struct mips_rtx_cost_data const mips_rtx_cost_optimize_size =
794 COSTS_N_INSNS (1), /* fp_add */
795 COSTS_N_INSNS (1), /* fp_mult_sf */
796 COSTS_N_INSNS (1), /* fp_mult_df */
797 COSTS_N_INSNS (1), /* fp_div_sf */
798 COSTS_N_INSNS (1), /* fp_div_df */
799 COSTS_N_INSNS (1), /* int_mult_si */
800 COSTS_N_INSNS (1), /* int_mult_di */
801 COSTS_N_INSNS (1), /* int_div_si */
802 COSTS_N_INSNS (1), /* int_div_di */
804 4 /* memory_latency */
807 static struct mips_rtx_cost_data const mips_rtx_cost_data[PROCESSOR_MAX] =
810 COSTS_N_INSNS (2), /* fp_add */
811 COSTS_N_INSNS (4), /* fp_mult_sf */
812 COSTS_N_INSNS (5), /* fp_mult_df */
813 COSTS_N_INSNS (12), /* fp_div_sf */
814 COSTS_N_INSNS (19), /* fp_div_df */
815 COSTS_N_INSNS (12), /* int_mult_si */
816 COSTS_N_INSNS (12), /* int_mult_di */
817 COSTS_N_INSNS (35), /* int_div_si */
818 COSTS_N_INSNS (35), /* int_div_di */
820 4 /* memory_latency */
825 COSTS_N_INSNS (6), /* int_mult_si */
826 COSTS_N_INSNS (6), /* int_mult_di */
827 COSTS_N_INSNS (36), /* int_div_si */
828 COSTS_N_INSNS (36), /* int_div_di */
830 4 /* memory_latency */
834 COSTS_N_INSNS (36), /* int_mult_si */
835 COSTS_N_INSNS (36), /* int_mult_di */
836 COSTS_N_INSNS (37), /* int_div_si */
837 COSTS_N_INSNS (37), /* int_div_di */
839 4 /* memory_latency */
843 COSTS_N_INSNS (4), /* int_mult_si */
844 COSTS_N_INSNS (11), /* int_mult_di */
845 COSTS_N_INSNS (36), /* int_div_si */
846 COSTS_N_INSNS (68), /* int_div_di */
848 4 /* memory_latency */
851 COSTS_N_INSNS (4), /* fp_add */
852 COSTS_N_INSNS (4), /* fp_mult_sf */
853 COSTS_N_INSNS (5), /* fp_mult_df */
854 COSTS_N_INSNS (17), /* fp_div_sf */
855 COSTS_N_INSNS (32), /* fp_div_df */
856 COSTS_N_INSNS (4), /* int_mult_si */
857 COSTS_N_INSNS (11), /* int_mult_di */
858 COSTS_N_INSNS (36), /* int_div_si */
859 COSTS_N_INSNS (68), /* int_div_di */
861 4 /* memory_latency */
868 COSTS_N_INSNS (5), /* int_mult_si */
869 COSTS_N_INSNS (5), /* int_mult_di */
870 COSTS_N_INSNS (41), /* int_div_si */
871 COSTS_N_INSNS (41), /* int_div_di */
873 4 /* memory_latency */
876 COSTS_N_INSNS (8), /* fp_add */
877 COSTS_N_INSNS (8), /* fp_mult_sf */
878 COSTS_N_INSNS (10), /* fp_mult_df */
879 COSTS_N_INSNS (34), /* fp_div_sf */
880 COSTS_N_INSNS (64), /* fp_div_df */
881 COSTS_N_INSNS (5), /* int_mult_si */
882 COSTS_N_INSNS (5), /* int_mult_di */
883 COSTS_N_INSNS (41), /* int_div_si */
884 COSTS_N_INSNS (41), /* int_div_di */
886 4 /* memory_latency */
889 COSTS_N_INSNS (4), /* fp_add */
890 COSTS_N_INSNS (4), /* fp_mult_sf */
891 COSTS_N_INSNS (5), /* fp_mult_df */
892 COSTS_N_INSNS (17), /* fp_div_sf */
893 COSTS_N_INSNS (32), /* fp_div_df */
894 COSTS_N_INSNS (5), /* int_mult_si */
895 COSTS_N_INSNS (5), /* int_mult_di */
896 COSTS_N_INSNS (41), /* int_div_si */
897 COSTS_N_INSNS (41), /* int_div_di */
899 4 /* memory_latency */
903 COSTS_N_INSNS (5), /* int_mult_si */
904 COSTS_N_INSNS (5), /* int_mult_di */
905 COSTS_N_INSNS (41), /* int_div_si */
906 COSTS_N_INSNS (41), /* int_div_di */
908 4 /* memory_latency */
911 COSTS_N_INSNS (8), /* fp_add */
912 COSTS_N_INSNS (8), /* fp_mult_sf */
913 COSTS_N_INSNS (10), /* fp_mult_df */
914 COSTS_N_INSNS (34), /* fp_div_sf */
915 COSTS_N_INSNS (64), /* fp_div_df */
916 COSTS_N_INSNS (5), /* int_mult_si */
917 COSTS_N_INSNS (5), /* int_mult_di */
918 COSTS_N_INSNS (41), /* int_div_si */
919 COSTS_N_INSNS (41), /* int_div_di */
921 4 /* memory_latency */
924 COSTS_N_INSNS (4), /* fp_add */
925 COSTS_N_INSNS (4), /* fp_mult_sf */
926 COSTS_N_INSNS (5), /* fp_mult_df */
927 COSTS_N_INSNS (17), /* fp_div_sf */
928 COSTS_N_INSNS (32), /* fp_div_df */
929 COSTS_N_INSNS (5), /* int_mult_si */
930 COSTS_N_INSNS (5), /* int_mult_di */
931 COSTS_N_INSNS (41), /* int_div_si */
932 COSTS_N_INSNS (41), /* int_div_di */
934 4 /* memory_latency */
940 COSTS_N_INSNS (2), /* fp_add */
941 COSTS_N_INSNS (4), /* fp_mult_sf */
942 COSTS_N_INSNS (5), /* fp_mult_df */
943 COSTS_N_INSNS (12), /* fp_div_sf */
944 COSTS_N_INSNS (19), /* fp_div_df */
945 COSTS_N_INSNS (2), /* int_mult_si */
946 COSTS_N_INSNS (2), /* int_mult_di */
947 COSTS_N_INSNS (35), /* int_div_si */
948 COSTS_N_INSNS (35), /* int_div_di */
950 4 /* memory_latency */
953 COSTS_N_INSNS (3), /* fp_add */
954 COSTS_N_INSNS (5), /* fp_mult_sf */
955 COSTS_N_INSNS (6), /* fp_mult_df */
956 COSTS_N_INSNS (15), /* fp_div_sf */
957 COSTS_N_INSNS (16), /* fp_div_df */
958 COSTS_N_INSNS (17), /* int_mult_si */
959 COSTS_N_INSNS (17), /* int_mult_di */
960 COSTS_N_INSNS (38), /* int_div_si */
961 COSTS_N_INSNS (38), /* int_div_di */
963 6 /* memory_latency */
966 COSTS_N_INSNS (6), /* fp_add */
967 COSTS_N_INSNS (7), /* fp_mult_sf */
968 COSTS_N_INSNS (8), /* fp_mult_df */
969 COSTS_N_INSNS (23), /* fp_div_sf */
970 COSTS_N_INSNS (36), /* fp_div_df */
971 COSTS_N_INSNS (10), /* int_mult_si */
972 COSTS_N_INSNS (10), /* int_mult_di */
973 COSTS_N_INSNS (69), /* int_div_si */
974 COSTS_N_INSNS (69), /* int_div_di */
976 6 /* memory_latency */
988 /* The only costs that appear to be updated here are
989 integer multiplication. */
991 COSTS_N_INSNS (4), /* int_mult_si */
992 COSTS_N_INSNS (6), /* int_mult_di */
993 COSTS_N_INSNS (69), /* int_div_si */
994 COSTS_N_INSNS (69), /* int_div_di */
996 4 /* memory_latency */
1008 COSTS_N_INSNS (6), /* fp_add */
1009 COSTS_N_INSNS (4), /* fp_mult_sf */
1010 COSTS_N_INSNS (5), /* fp_mult_df */
1011 COSTS_N_INSNS (23), /* fp_div_sf */
1012 COSTS_N_INSNS (36), /* fp_div_df */
1013 COSTS_N_INSNS (5), /* int_mult_si */
1014 COSTS_N_INSNS (5), /* int_mult_di */
1015 COSTS_N_INSNS (36), /* int_div_si */
1016 COSTS_N_INSNS (36), /* int_div_di */
1017 1, /* branch_cost */
1018 4 /* memory_latency */
1021 COSTS_N_INSNS (6), /* fp_add */
1022 COSTS_N_INSNS (5), /* fp_mult_sf */
1023 COSTS_N_INSNS (6), /* fp_mult_df */
1024 COSTS_N_INSNS (30), /* fp_div_sf */
1025 COSTS_N_INSNS (59), /* fp_div_df */
1026 COSTS_N_INSNS (3), /* int_mult_si */
1027 COSTS_N_INSNS (4), /* int_mult_di */
1028 COSTS_N_INSNS (42), /* int_div_si */
1029 COSTS_N_INSNS (74), /* int_div_di */
1030 1, /* branch_cost */
1031 4 /* memory_latency */
1034 COSTS_N_INSNS (6), /* fp_add */
1035 COSTS_N_INSNS (5), /* fp_mult_sf */
1036 COSTS_N_INSNS (6), /* fp_mult_df */
1037 COSTS_N_INSNS (30), /* fp_div_sf */
1038 COSTS_N_INSNS (59), /* fp_div_df */
1039 COSTS_N_INSNS (5), /* int_mult_si */
1040 COSTS_N_INSNS (9), /* int_mult_di */
1041 COSTS_N_INSNS (42), /* int_div_si */
1042 COSTS_N_INSNS (74), /* int_div_di */
1043 1, /* branch_cost */
1044 4 /* memory_latency */
1047 /* The only costs that are changed here are
1048 integer multiplication. */
1049 COSTS_N_INSNS (6), /* fp_add */
1050 COSTS_N_INSNS (7), /* fp_mult_sf */
1051 COSTS_N_INSNS (8), /* fp_mult_df */
1052 COSTS_N_INSNS (23), /* fp_div_sf */
1053 COSTS_N_INSNS (36), /* fp_div_df */
1054 COSTS_N_INSNS (5), /* int_mult_si */
1055 COSTS_N_INSNS (9), /* int_mult_di */
1056 COSTS_N_INSNS (69), /* int_div_si */
1057 COSTS_N_INSNS (69), /* int_div_di */
1058 1, /* branch_cost */
1059 4 /* memory_latency */
1065 /* The only costs that are changed here are
1066 integer multiplication. */
1067 COSTS_N_INSNS (6), /* fp_add */
1068 COSTS_N_INSNS (7), /* fp_mult_sf */
1069 COSTS_N_INSNS (8), /* fp_mult_df */
1070 COSTS_N_INSNS (23), /* fp_div_sf */
1071 COSTS_N_INSNS (36), /* fp_div_df */
1072 COSTS_N_INSNS (3), /* int_mult_si */
1073 COSTS_N_INSNS (8), /* int_mult_di */
1074 COSTS_N_INSNS (69), /* int_div_si */
1075 COSTS_N_INSNS (69), /* int_div_di */
1076 1, /* branch_cost */
1077 4 /* memory_latency */
1080 /* These costs are the same as the SB-1A below. */
1081 COSTS_N_INSNS (4), /* fp_add */
1082 COSTS_N_INSNS (4), /* fp_mult_sf */
1083 COSTS_N_INSNS (4), /* fp_mult_df */
1084 COSTS_N_INSNS (24), /* fp_div_sf */
1085 COSTS_N_INSNS (32), /* fp_div_df */
1086 COSTS_N_INSNS (3), /* int_mult_si */
1087 COSTS_N_INSNS (4), /* int_mult_di */
1088 COSTS_N_INSNS (36), /* int_div_si */
1089 COSTS_N_INSNS (68), /* int_div_di */
1090 1, /* branch_cost */
1091 4 /* memory_latency */
1094 /* These costs are the same as the SB-1 above. */
1095 COSTS_N_INSNS (4), /* fp_add */
1096 COSTS_N_INSNS (4), /* fp_mult_sf */
1097 COSTS_N_INSNS (4), /* fp_mult_df */
1098 COSTS_N_INSNS (24), /* fp_div_sf */
1099 COSTS_N_INSNS (32), /* fp_div_df */
1100 COSTS_N_INSNS (3), /* int_mult_si */
1101 COSTS_N_INSNS (4), /* int_mult_di */
1102 COSTS_N_INSNS (36), /* int_div_si */
1103 COSTS_N_INSNS (68), /* int_div_di */
1104 1, /* branch_cost */
1105 4 /* memory_latency */
1113 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
1114 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
1115 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
1118 /* Initialize the GCC target structure. */
1119 #undef TARGET_ASM_ALIGNED_HI_OP
1120 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
1121 #undef TARGET_ASM_ALIGNED_SI_OP
1122 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
1123 #undef TARGET_ASM_ALIGNED_DI_OP
1124 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
1126 #undef TARGET_ASM_FUNCTION_PROLOGUE
1127 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
1128 #undef TARGET_ASM_FUNCTION_EPILOGUE
1129 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
1130 #undef TARGET_ASM_SELECT_RTX_SECTION
1131 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
1132 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
1133 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
1135 #undef TARGET_SCHED_REORDER
1136 #define TARGET_SCHED_REORDER mips_sched_reorder
1137 #undef TARGET_SCHED_VARIABLE_ISSUE
1138 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
1139 #undef TARGET_SCHED_ADJUST_COST
1140 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
1141 #undef TARGET_SCHED_ISSUE_RATE
1142 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
1143 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
1144 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
1145 mips_multipass_dfa_lookahead
1147 #undef TARGET_DEFAULT_TARGET_FLAGS
1148 #define TARGET_DEFAULT_TARGET_FLAGS \
1150 | TARGET_CPU_DEFAULT \
1151 | TARGET_ENDIAN_DEFAULT \
1152 | TARGET_FP_EXCEPTIONS_DEFAULT \
1153 | MASK_CHECK_ZERO_DIV \
1155 #undef TARGET_HANDLE_OPTION
1156 #define TARGET_HANDLE_OPTION mips_handle_option
1158 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
1159 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
1161 #undef TARGET_VALID_POINTER_MODE
1162 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
1163 #undef TARGET_RTX_COSTS
1164 #define TARGET_RTX_COSTS mips_rtx_costs
1165 #undef TARGET_ADDRESS_COST
1166 #define TARGET_ADDRESS_COST mips_address_cost
1168 #undef TARGET_IN_SMALL_DATA_P
1169 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
1171 #undef TARGET_MACHINE_DEPENDENT_REORG
1172 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
1174 #undef TARGET_ASM_FILE_START
1175 #define TARGET_ASM_FILE_START mips_file_start
1176 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
1177 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
1179 #undef TARGET_INIT_LIBFUNCS
1180 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
1182 #undef TARGET_BUILD_BUILTIN_VA_LIST
1183 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
1184 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
1185 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
1187 #undef TARGET_PROMOTE_FUNCTION_ARGS
1188 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
1189 #undef TARGET_PROMOTE_FUNCTION_RETURN
1190 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
1191 #undef TARGET_PROMOTE_PROTOTYPES
1192 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
1194 #undef TARGET_RETURN_IN_MEMORY
1195 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
1196 #undef TARGET_RETURN_IN_MSB
1197 #define TARGET_RETURN_IN_MSB mips_return_in_msb
1199 #undef TARGET_ASM_OUTPUT_MI_THUNK
1200 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
1201 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
1202 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
1204 #undef TARGET_SETUP_INCOMING_VARARGS
1205 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
1206 #undef TARGET_STRICT_ARGUMENT_NAMING
1207 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
1208 #undef TARGET_MUST_PASS_IN_STACK
1209 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
1210 #undef TARGET_PASS_BY_REFERENCE
1211 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
1212 #undef TARGET_CALLEE_COPIES
1213 #define TARGET_CALLEE_COPIES mips_callee_copies
1214 #undef TARGET_ARG_PARTIAL_BYTES
1215 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
1217 #undef TARGET_MODE_REP_EXTENDED
1218 #define TARGET_MODE_REP_EXTENDED mips_mode_rep_extended
1220 #undef TARGET_VECTOR_MODE_SUPPORTED_P
1221 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
1223 #undef TARGET_INIT_BUILTINS
1224 #define TARGET_INIT_BUILTINS mips_init_builtins
1225 #undef TARGET_EXPAND_BUILTIN
1226 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
1228 #undef TARGET_HAVE_TLS
1229 #define TARGET_HAVE_TLS HAVE_AS_TLS
1231 #undef TARGET_CANNOT_FORCE_CONST_MEM
1232 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
1234 #undef TARGET_ENCODE_SECTION_INFO
1235 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
1237 #undef TARGET_ATTRIBUTE_TABLE
1238 #define TARGET_ATTRIBUTE_TABLE mips_attribute_table
1240 #undef TARGET_EXTRA_LIVE_ON_ENTRY
1241 #define TARGET_EXTRA_LIVE_ON_ENTRY mips_extra_live_on_entry
1243 #undef TARGET_MIN_ANCHOR_OFFSET
1244 #define TARGET_MIN_ANCHOR_OFFSET -32768
1245 #undef TARGET_MAX_ANCHOR_OFFSET
1246 #define TARGET_MAX_ANCHOR_OFFSET 32767
1247 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
1248 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P mips_use_blocks_for_constant_p
1249 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
1250 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P mips_use_anchors_for_symbol_p
1252 struct gcc_target targetm = TARGET_INITIALIZER;
1254 /* Return true if SYMBOL_REF X is associated with a global symbol
1255 (in the STB_GLOBAL sense). */
1258 mips_global_symbol_p (rtx x)
1262 decl = SYMBOL_REF_DECL (x);
1264 return !SYMBOL_REF_LOCAL_P (x);
1266 /* Weakref symbols are not TREE_PUBLIC, but their targets are global
1267 or weak symbols. Relocations in the object file will be against
1268 the target symbol, so it's that symbol's binding that matters here. */
1269 return DECL_P (decl) && (TREE_PUBLIC (decl) || DECL_WEAK (decl));
1272 /* Return true if SYMBOL_REF X binds locally. */
1275 mips_symbol_binds_local_p (rtx x)
1277 return (SYMBOL_REF_DECL (x)
1278 ? targetm.binds_local_p (SYMBOL_REF_DECL (x))
1279 : SYMBOL_REF_LOCAL_P (x));
1282 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
1284 static enum mips_symbol_type
1285 mips_classify_symbol (rtx x)
1288 return SYMBOL_GOT_DISP;
1290 if (GET_CODE (x) == LABEL_REF)
1293 return SYMBOL_CONSTANT_POOL;
1294 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
1295 return SYMBOL_GOT_PAGE_OFST;
1296 return SYMBOL_GENERAL;
1299 gcc_assert (GET_CODE (x) == SYMBOL_REF);
1301 if (SYMBOL_REF_TLS_MODEL (x))
1304 if (CONSTANT_POOL_ADDRESS_P (x))
1307 return SYMBOL_CONSTANT_POOL;
1309 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
1310 return SYMBOL_SMALL_DATA;
1313 /* Do not use small-data accesses for weak symbols; they may end up
1315 if (SYMBOL_REF_SMALL_P (x)
1316 && !SYMBOL_REF_WEAK (x))
1317 return SYMBOL_SMALL_DATA;
1319 if (TARGET_ABICALLS)
1321 /* Don't use GOT accesses for locally-binding symbols; we can use
1322 %hi and %lo instead. */
1323 if (TARGET_ABSOLUTE_ABICALLS && mips_symbol_binds_local_p (x))
1324 return SYMBOL_GENERAL;
1326 /* There are three cases to consider:
1328 - o32 PIC (either with or without explicit relocs)
1329 - n32/n64 PIC without explicit relocs
1330 - n32/n64 PIC with explicit relocs
1332 In the first case, both local and global accesses will use an
1333 R_MIPS_GOT16 relocation. We must correctly predict which of
1334 the two semantics (local or global) the assembler and linker
1335 will apply. The choice depends on the symbol's binding rather
1336 than its visibility.
1338 In the second case, the assembler will not use R_MIPS_GOT16
1339 relocations, but it chooses between local and global accesses
1340 in the same way as for o32 PIC.
1342 In the third case we have more freedom since both forms of
1343 access will work for any kind of symbol. However, there seems
1344 little point in doing things differently. */
1345 if (mips_global_symbol_p (x))
1346 return SYMBOL_GOT_DISP;
1348 return SYMBOL_GOT_PAGE_OFST;
1351 return SYMBOL_GENERAL;
1354 /* Returns true if OFFSET is within the range [0, ALIGN), where ALIGN
1355 is the alignment (in bytes) of SYMBOL_REF X. */
1358 mips_offset_within_alignment_p (rtx x, HOST_WIDE_INT offset)
1360 /* If for some reason we can't get the alignment for the
1361 symbol, initializing this to one means we won't accept any
1363 HOST_WIDE_INT align = 1;
1366 /* Get the alignment of the symbol we're referring to. */
1367 t = SYMBOL_REF_DECL (x);
1369 align = DECL_ALIGN_UNIT (t);
1371 if (offset >= 0 && offset < align)
1376 /* Return true if X is a symbolic constant that can be calculated in
1377 the same way as a bare symbol. If it is, store the type of the
1378 symbol in *SYMBOL_TYPE. */
1381 mips_symbolic_constant_p (rtx x, enum mips_symbol_type *symbol_type)
1385 split_const (x, &x, &offset);
1386 if (UNSPEC_ADDRESS_P (x))
1388 *symbol_type = UNSPEC_ADDRESS_TYPE (x);
1389 x = UNSPEC_ADDRESS (x);
1391 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1393 *symbol_type = mips_classify_symbol (x);
1394 if (*symbol_type == SYMBOL_TLS)
1400 if (offset == const0_rtx)
1403 /* Check whether a nonzero offset is valid for the underlying
1405 switch (*symbol_type)
1407 case SYMBOL_GENERAL:
1408 case SYMBOL_64_HIGH:
1411 /* If the target has 64-bit pointers and the object file only
1412 supports 32-bit symbols, the values of those symbols will be
1413 sign-extended. In this case we can't allow an arbitrary offset
1414 in case the 32-bit value X + OFFSET has a different sign from X. */
1415 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
1416 return offset_within_block_p (x, INTVAL (offset));
1418 /* In other cases the relocations can handle any offset. */
1421 case SYMBOL_CONSTANT_POOL:
1422 /* Allow constant pool references to be converted to LABEL+CONSTANT.
1423 In this case, we no longer have access to the underlying constant,
1424 but the original symbol-based access was known to be valid. */
1425 if (GET_CODE (x) == LABEL_REF)
1430 case SYMBOL_SMALL_DATA:
1431 /* Make sure that the offset refers to something within the
1432 same object block. This should guarantee that the final
1433 PC- or GP-relative offset is within the 16-bit limit. */
1434 return offset_within_block_p (x, INTVAL (offset));
1436 case SYMBOL_GOT_PAGE_OFST:
1437 case SYMBOL_GOTOFF_PAGE:
1438 /* If the symbol is global, the GOT entry will contain the symbol's
1439 address, and we will apply a 16-bit offset after loading it.
1440 If the symbol is local, the linker should provide enough local
1441 GOT entries for a 16-bit offset, but larger offsets may lead
1443 return SMALL_INT (offset);
1447 /* There is no carry between the HI and LO REL relocations, so the
1448 offset is only valid if we know it won't lead to such a carry. */
1449 return mips_offset_within_alignment_p (x, INTVAL (offset));
1451 case SYMBOL_GOT_DISP:
1452 case SYMBOL_GOTOFF_DISP:
1453 case SYMBOL_GOTOFF_CALL:
1454 case SYMBOL_GOTOFF_LOADGP:
1457 case SYMBOL_GOTTPREL:
1466 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1469 mips_regno_mode_ok_for_base_p (int regno, enum machine_mode mode, int strict)
1471 if (!HARD_REGISTER_NUM_P (regno))
1475 regno = reg_renumber[regno];
1478 /* These fake registers will be eliminated to either the stack or
1479 hard frame pointer, both of which are usually valid base registers.
1480 Reload deals with the cases where the eliminated form isn't valid. */
1481 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
1484 /* In mips16 mode, the stack pointer can only address word and doubleword
1485 values, nothing smaller. There are two problems here:
1487 (a) Instantiating virtual registers can introduce new uses of the
1488 stack pointer. If these virtual registers are valid addresses,
1489 the stack pointer should be too.
1491 (b) Most uses of the stack pointer are not made explicit until
1492 FRAME_POINTER_REGNUM and ARG_POINTER_REGNUM have been eliminated.
1493 We don't know until that stage whether we'll be eliminating to the
1494 stack pointer (which needs the restriction) or the hard frame
1495 pointer (which doesn't).
1497 All in all, it seems more consistent to only enforce this restriction
1498 during and after reload. */
1499 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
1500 return !strict || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1502 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
1506 /* Return true if X is a valid base register for the given mode.
1507 Allow only hard registers if STRICT. */
1510 mips_valid_base_register_p (rtx x, enum machine_mode mode, int strict)
1512 if (!strict && GET_CODE (x) == SUBREG)
1516 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict));
1520 /* Return true if symbols of type SYMBOL_TYPE can directly address a value
1521 with mode MODE. This is used for both symbolic and LO_SUM addresses. */
1524 mips_symbolic_address_p (enum mips_symbol_type symbol_type,
1525 enum machine_mode mode)
1527 switch (symbol_type)
1529 case SYMBOL_GENERAL:
1530 return !TARGET_MIPS16;
1532 case SYMBOL_SMALL_DATA:
1535 case SYMBOL_CONSTANT_POOL:
1536 /* PC-relative addressing is only available for lw and ld. */
1537 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1539 case SYMBOL_GOT_PAGE_OFST:
1542 case SYMBOL_GOT_DISP:
1543 /* The address will have to be loaded from the GOT first. */
1546 case SYMBOL_GOTOFF_PAGE:
1547 case SYMBOL_GOTOFF_DISP:
1548 case SYMBOL_GOTOFF_CALL:
1549 case SYMBOL_GOTOFF_LOADGP:
1554 case SYMBOL_GOTTPREL:
1556 case SYMBOL_64_HIGH:
1566 /* Return true if X is a valid address for machine mode MODE. If it is,
1567 fill in INFO appropriately. STRICT is true if we should only accept
1568 hard base registers. */
1571 mips_classify_address (struct mips_address_info *info, rtx x,
1572 enum machine_mode mode, int strict)
1574 switch (GET_CODE (x))
1578 info->type = ADDRESS_REG;
1580 info->offset = const0_rtx;
1581 return mips_valid_base_register_p (info->reg, mode, strict);
1584 info->type = ADDRESS_REG;
1585 info->reg = XEXP (x, 0);
1586 info->offset = XEXP (x, 1);
1587 return (mips_valid_base_register_p (info->reg, mode, strict)
1588 && const_arith_operand (info->offset, VOIDmode));
1591 info->type = ADDRESS_LO_SUM;
1592 info->reg = XEXP (x, 0);
1593 info->offset = XEXP (x, 1);
1594 return (mips_valid_base_register_p (info->reg, mode, strict)
1595 && mips_symbolic_constant_p (info->offset, &info->symbol_type)
1596 && mips_symbolic_address_p (info->symbol_type, mode)
1597 && mips_lo_relocs[info->symbol_type] != 0);
1600 /* Small-integer addresses don't occur very often, but they
1601 are legitimate if $0 is a valid base register. */
1602 info->type = ADDRESS_CONST_INT;
1603 return !TARGET_MIPS16 && SMALL_INT (x);
1608 info->type = ADDRESS_SYMBOLIC;
1609 return (mips_symbolic_constant_p (x, &info->symbol_type)
1610 && mips_symbolic_address_p (info->symbol_type, mode)
1611 && !mips_split_p[info->symbol_type]);
1618 /* Return true if X is a thread-local symbol. */
1621 mips_tls_operand_p (rtx x)
1623 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
1626 /* Return true if X can not be forced into a constant pool. */
1629 mips_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1631 return mips_tls_operand_p (*x);
1634 /* Return true if X can not be forced into a constant pool. */
1637 mips_cannot_force_const_mem (rtx x)
1643 /* As an optimization, reject constants that mips_legitimize_move
1646 Suppose we have a multi-instruction sequence that loads constant C
1647 into register R. If R does not get allocated a hard register, and
1648 R is used in an operand that allows both registers and memory
1649 references, reload will consider forcing C into memory and using
1650 one of the instruction's memory alternatives. Returning false
1651 here will force it to use an input reload instead. */
1652 if (GET_CODE (x) == CONST_INT)
1655 split_const (x, &base, &offset);
1656 if (symbolic_operand (base, VOIDmode) && SMALL_INT (offset))
1660 if (TARGET_HAVE_TLS && for_each_rtx (&x, &mips_tls_symbol_ref_1, 0))
1666 /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. MIPS16 uses per-function
1667 constant pools, but normal-mode code doesn't need to. */
1670 mips_use_blocks_for_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1671 rtx x ATTRIBUTE_UNUSED)
1673 return !TARGET_MIPS16;
1676 /* Return the number of instructions needed to load a symbol of the
1677 given type into a register. If valid in an address, the same number
1678 of instructions are needed for loads and stores. Treat extended
1679 mips16 instructions as two instructions. */
1682 mips_symbol_insns (enum mips_symbol_type type)
1686 case SYMBOL_GENERAL:
1687 /* In mips16 code, general symbols must be fetched from the
1692 /* When using 64-bit symbols, we need 5 preparatory instructions,
1695 lui $at,%highest(symbol)
1696 daddiu $at,$at,%higher(symbol)
1698 daddiu $at,$at,%hi(symbol)
1701 The final address is then $at + %lo(symbol). With 32-bit
1702 symbols we just need a preparatory lui. */
1703 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1705 case SYMBOL_SMALL_DATA:
1709 case SYMBOL_CONSTANT_POOL:
1710 /* This case is for mips16 only. Assume we'll need an
1711 extended instruction. */
1714 case SYMBOL_GOT_PAGE_OFST:
1715 case SYMBOL_GOT_DISP:
1716 /* Unless -funit-at-a-time is in effect, we can't be sure whether
1717 the local/global classification is accurate. See override_options
1720 The worst cases are:
1722 (1) For local symbols when generating o32 or o64 code. The assembler
1728 ...and the final address will be $at + %lo(symbol).
1730 (2) For global symbols when -mxgot. The assembler will use:
1732 lui $at,%got_hi(symbol)
1735 ...and the final address will be $at + %got_lo(symbol). */
1738 case SYMBOL_GOTOFF_PAGE:
1739 case SYMBOL_GOTOFF_DISP:
1740 case SYMBOL_GOTOFF_CALL:
1741 case SYMBOL_GOTOFF_LOADGP:
1742 case SYMBOL_64_HIGH:
1748 case SYMBOL_GOTTPREL:
1750 /* Check whether the offset is a 16- or 32-bit value. */
1751 return mips_split_p[type] ? 2 : 1;
1754 /* We don't treat a bare TLS symbol as a constant. */
1760 /* Return true if X is a legitimate $sp-based address for mode MDOE. */
1763 mips_stack_address_p (rtx x, enum machine_mode mode)
1765 struct mips_address_info addr;
1767 return (mips_classify_address (&addr, x, mode, false)
1768 && addr.type == ADDRESS_REG
1769 && addr.reg == stack_pointer_rtx);
1772 /* Return true if a value at OFFSET bytes from BASE can be accessed
1773 using an unextended mips16 instruction. MODE is the mode of the
1776 Usually the offset in an unextended instruction is a 5-bit field.
1777 The offset is unsigned and shifted left once for HIs, twice
1778 for SIs, and so on. An exception is SImode accesses off the
1779 stack pointer, which have an 8-bit immediate field. */
1782 mips16_unextended_reference_p (enum machine_mode mode, rtx base, rtx offset)
1785 && GET_CODE (offset) == CONST_INT
1786 && INTVAL (offset) >= 0
1787 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1789 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1790 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1791 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1797 /* Return the number of instructions needed to load or store a value
1798 of mode MODE at X. Return 0 if X isn't valid for MODE.
1800 For mips16 code, count extended instructions as two instructions. */
1803 mips_address_insns (rtx x, enum machine_mode mode)
1805 struct mips_address_info addr;
1808 if (mode == BLKmode)
1809 /* BLKmode is used for single unaligned loads and stores. */
1812 /* Each word of a multi-word value will be accessed individually. */
1813 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1815 if (mips_classify_address (&addr, x, mode, false))
1820 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1824 case ADDRESS_LO_SUM:
1825 return (TARGET_MIPS16 ? factor * 2 : factor);
1827 case ADDRESS_CONST_INT:
1830 case ADDRESS_SYMBOLIC:
1831 return factor * mips_symbol_insns (addr.symbol_type);
1837 /* Likewise for constant X. */
1840 mips_const_insns (rtx x)
1842 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1843 enum mips_symbol_type symbol_type;
1846 switch (GET_CODE (x))
1850 || !mips_symbolic_constant_p (XEXP (x, 0), &symbol_type)
1851 || !mips_split_p[symbol_type])
1858 /* Unsigned 8-bit constants can be loaded using an unextended
1859 LI instruction. Unsigned 16-bit constants can be loaded
1860 using an extended LI. Negative constants must be loaded
1861 using LI and then negated. */
1862 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1863 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1864 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1865 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1868 return mips_build_integer (codes, INTVAL (x));
1872 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1878 /* See if we can refer to X directly. */
1879 if (mips_symbolic_constant_p (x, &symbol_type))
1880 return mips_symbol_insns (symbol_type);
1882 /* Otherwise try splitting the constant into a base and offset.
1883 16-bit offsets can be added using an extra addiu. Larger offsets
1884 must be calculated separately and then added to the base. */
1885 split_const (x, &x, &offset);
1888 int n = mips_const_insns (x);
1891 if (SMALL_INT (offset))
1894 return n + 1 + mips_build_integer (codes, INTVAL (offset));
1901 return mips_symbol_insns (mips_classify_symbol (x));
1909 /* Return the number of instructions needed for memory reference X.
1910 Count extended mips16 instructions as two instructions. */
1913 mips_fetch_insns (rtx x)
1915 gcc_assert (MEM_P (x));
1916 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1920 /* Return the number of instructions needed for an integer division. */
1923 mips_idiv_insns (void)
1928 if (TARGET_CHECK_ZERO_DIV)
1930 if (GENERATE_DIVIDE_TRAPS)
1936 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
1941 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1942 returns a nonzero value if X is a legitimate address for a memory
1943 operand of the indicated MODE. STRICT is nonzero if this function
1944 is called during reload. */
1947 mips_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1949 struct mips_address_info addr;
1951 return mips_classify_address (&addr, x, mode, strict);
1955 /* Copy VALUE to a register and return that register. If new psuedos
1956 are allowed, copy it into a new register, otherwise use DEST. */
1959 mips_force_temporary (rtx dest, rtx value)
1961 if (!no_new_pseudos)
1962 return force_reg (Pmode, value);
1965 emit_move_insn (copy_rtx (dest), value);
1971 /* Return a LO_SUM expression for ADDR. TEMP is as for mips_force_temporary
1972 and is used to load the high part into a register. */
1975 mips_split_symbol (rtx temp, rtx addr)
1980 high = mips_force_temporary (temp, gen_rtx_HIGH (Pmode, copy_rtx (addr)));
1981 else if (no_new_pseudos)
1983 emit_insn (gen_load_const_gp (copy_rtx (temp)));
1987 high = mips16_gp_pseudo_reg ();
1988 return gen_rtx_LO_SUM (Pmode, high, addr);
1992 /* Return an UNSPEC address with underlying address ADDRESS and symbol
1993 type SYMBOL_TYPE. */
1996 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
2000 split_const (address, &base, &offset);
2001 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
2002 UNSPEC_ADDRESS_FIRST + symbol_type);
2003 if (offset != const0_rtx)
2004 base = gen_rtx_PLUS (Pmode, base, offset);
2005 return gen_rtx_CONST (Pmode, base);
2009 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
2010 high part to BASE and return the result. Just return BASE otherwise.
2011 TEMP is available as a temporary register if needed.
2013 The returned expression can be used as the first operand to a LO_SUM. */
2016 mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
2017 enum mips_symbol_type symbol_type)
2019 if (mips_split_p[symbol_type])
2021 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
2022 addr = mips_force_temporary (temp, addr);
2023 return mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
2029 /* Return a legitimate address for REG + OFFSET. TEMP is as for
2030 mips_force_temporary; it is only needed when OFFSET is not a
2034 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
2036 if (!SMALL_OPERAND (offset))
2041 /* Load the full offset into a register so that we can use
2042 an unextended instruction for the address itself. */
2043 high = GEN_INT (offset);
2048 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH. */
2049 high = GEN_INT (CONST_HIGH_PART (offset));
2050 offset = CONST_LOW_PART (offset);
2052 high = mips_force_temporary (temp, high);
2053 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
2055 return plus_constant (reg, offset);
2058 /* Emit a call to __tls_get_addr. SYM is the TLS symbol we are
2059 referencing, and TYPE is the symbol type to use (either global
2060 dynamic or local dynamic). V0 is an RTX for the return value
2061 location. The entire insn sequence is returned. */
2063 static GTY(()) rtx mips_tls_symbol;
2066 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
2068 rtx insn, loc, tga, a0;
2070 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
2072 if (!mips_tls_symbol)
2073 mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
2075 loc = mips_unspec_address (sym, type);
2079 emit_insn (gen_rtx_SET (Pmode, a0,
2080 gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
2081 tga = gen_rtx_MEM (Pmode, mips_tls_symbol);
2082 insn = emit_call_insn (gen_call_value (v0, tga, const0_rtx, const0_rtx));
2083 CONST_OR_PURE_CALL_P (insn) = 1;
2084 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), v0);
2085 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
2086 insn = get_insns ();
2093 /* Generate the code to access LOC, a thread local SYMBOL_REF. The
2094 return value will be a valid address and move_operand (either a REG
2098 mips_legitimize_tls_address (rtx loc)
2100 rtx dest, insn, v0, v1, tmp1, tmp2, eqv;
2101 enum tls_model model;
2103 v0 = gen_rtx_REG (Pmode, GP_RETURN);
2104 v1 = gen_rtx_REG (Pmode, GP_RETURN + 1);
2106 model = SYMBOL_REF_TLS_MODEL (loc);
2107 /* Only TARGET_ABICALLS code can have more than one module; other
2108 code must be be static and should not use a GOT. All TLS models
2109 reduce to local exec in this situation. */
2110 if (!TARGET_ABICALLS)
2111 model = TLS_MODEL_LOCAL_EXEC;
2115 case TLS_MODEL_GLOBAL_DYNAMIC:
2116 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
2117 dest = gen_reg_rtx (Pmode);
2118 emit_libcall_block (insn, dest, v0, loc);
2121 case TLS_MODEL_LOCAL_DYNAMIC:
2122 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
2123 tmp1 = gen_reg_rtx (Pmode);
2125 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2126 share the LDM result with other LD model accesses. */
2127 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2129 emit_libcall_block (insn, tmp1, v0, eqv);
2131 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
2132 dest = gen_rtx_LO_SUM (Pmode, tmp2,
2133 mips_unspec_address (loc, SYMBOL_DTPREL));
2136 case TLS_MODEL_INITIAL_EXEC:
2137 tmp1 = gen_reg_rtx (Pmode);
2138 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
2139 if (Pmode == DImode)
2141 emit_insn (gen_tls_get_tp_di (v1));
2142 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
2146 emit_insn (gen_tls_get_tp_si (v1));
2147 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
2149 dest = gen_reg_rtx (Pmode);
2150 emit_insn (gen_add3_insn (dest, tmp1, v1));
2153 case TLS_MODEL_LOCAL_EXEC:
2154 if (Pmode == DImode)
2155 emit_insn (gen_tls_get_tp_di (v1));
2157 emit_insn (gen_tls_get_tp_si (v1));
2159 tmp1 = mips_unspec_offset_high (NULL, v1, loc, SYMBOL_TPREL);
2160 dest = gen_rtx_LO_SUM (Pmode, tmp1,
2161 mips_unspec_address (loc, SYMBOL_TPREL));
2171 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
2172 be legitimized in a way that the generic machinery might not expect,
2173 put the new address in *XLOC and return true. MODE is the mode of
2174 the memory being accessed. */
2177 mips_legitimize_address (rtx *xloc, enum machine_mode mode)
2179 enum mips_symbol_type symbol_type;
2181 if (mips_tls_operand_p (*xloc))
2183 *xloc = mips_legitimize_tls_address (*xloc);
2187 /* See if the address can split into a high part and a LO_SUM. */
2188 if (mips_symbolic_constant_p (*xloc, &symbol_type)
2189 && mips_symbolic_address_p (symbol_type, mode)
2190 && mips_split_p[symbol_type])
2192 *xloc = mips_split_symbol (0, *xloc);
2196 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
2198 /* Handle REG + CONSTANT using mips_add_offset. */
2201 reg = XEXP (*xloc, 0);
2202 if (!mips_valid_base_register_p (reg, mode, 0))
2203 reg = copy_to_mode_reg (Pmode, reg);
2204 *xloc = mips_add_offset (0, reg, INTVAL (XEXP (*xloc, 1)));
2212 /* Subroutine of mips_build_integer (with the same interface).
2213 Assume that the final action in the sequence should be a left shift. */
2216 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
2218 unsigned int i, shift;
2220 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
2221 since signed numbers are easier to load than unsigned ones. */
2223 while ((value & 1) == 0)
2224 value /= 2, shift++;
2226 i = mips_build_integer (codes, value);
2227 codes[i].code = ASHIFT;
2228 codes[i].value = shift;
2233 /* As for mips_build_shift, but assume that the final action will be
2234 an IOR or PLUS operation. */
2237 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
2239 unsigned HOST_WIDE_INT high;
2242 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
2243 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
2245 /* The constant is too complex to load with a simple lui/ori pair
2246 so our goal is to clear as many trailing zeros as possible.
2247 In this case, we know bit 16 is set and that the low 16 bits
2248 form a negative number. If we subtract that number from VALUE,
2249 we will clear at least the lowest 17 bits, maybe more. */
2250 i = mips_build_integer (codes, CONST_HIGH_PART (value));
2251 codes[i].code = PLUS;
2252 codes[i].value = CONST_LOW_PART (value);
2256 i = mips_build_integer (codes, high);
2257 codes[i].code = IOR;
2258 codes[i].value = value & 0xffff;
2264 /* Fill CODES with a sequence of rtl operations to load VALUE.
2265 Return the number of operations needed. */
2268 mips_build_integer (struct mips_integer_op *codes,
2269 unsigned HOST_WIDE_INT value)
2271 if (SMALL_OPERAND (value)
2272 || SMALL_OPERAND_UNSIGNED (value)
2273 || LUI_OPERAND (value))
2275 /* The value can be loaded with a single instruction. */
2276 codes[0].code = UNKNOWN;
2277 codes[0].value = value;
2280 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
2282 /* Either the constant is a simple LUI/ORI combination or its
2283 lowest bit is set. We don't want to shift in this case. */
2284 return mips_build_lower (codes, value);
2286 else if ((value & 0xffff) == 0)
2288 /* The constant will need at least three actions. The lowest
2289 16 bits are clear, so the final action will be a shift. */
2290 return mips_build_shift (codes, value);
2294 /* The final action could be a shift, add or inclusive OR.
2295 Rather than use a complex condition to select the best
2296 approach, try both mips_build_shift and mips_build_lower
2297 and pick the one that gives the shortest sequence.
2298 Note that this case is only used once per constant. */
2299 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
2300 unsigned int cost, alt_cost;
2302 cost = mips_build_shift (codes, value);
2303 alt_cost = mips_build_lower (alt_codes, value);
2304 if (alt_cost < cost)
2306 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
2314 /* Load VALUE into DEST, using TEMP as a temporary register if need be. */
2317 mips_move_integer (rtx dest, rtx temp, unsigned HOST_WIDE_INT value)
2319 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
2320 enum machine_mode mode;
2321 unsigned int i, cost;
2324 mode = GET_MODE (dest);
2325 cost = mips_build_integer (codes, value);
2327 /* Apply each binary operation to X. Invariant: X is a legitimate
2328 source operand for a SET pattern. */
2329 x = GEN_INT (codes[0].value);
2330 for (i = 1; i < cost; i++)
2334 emit_insn (gen_rtx_SET (VOIDmode, temp, x));
2338 x = force_reg (mode, x);
2339 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
2342 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
2346 /* Subroutine of mips_legitimize_move. Move constant SRC into register
2347 DEST given that SRC satisfies immediate_operand but doesn't satisfy
2351 mips_legitimize_const_move (enum machine_mode mode, rtx dest, rtx src)
2355 /* Split moves of big integers into smaller pieces. */
2356 if (splittable_const_int_operand (src, mode))
2358 mips_move_integer (dest, dest, INTVAL (src));
2362 /* Split moves of symbolic constants into high/low pairs. */
2363 if (splittable_symbolic_operand (src, mode))
2365 emit_insn (gen_rtx_SET (VOIDmode, dest, mips_split_symbol (dest, src)));
2369 if (mips_tls_operand_p (src))
2371 emit_move_insn (dest, mips_legitimize_tls_address (src));
2375 /* If we have (const (plus symbol offset)), load the symbol first
2376 and then add in the offset. This is usually better than forcing
2377 the constant into memory, at least in non-mips16 code. */
2378 split_const (src, &base, &offset);
2380 && offset != const0_rtx
2381 && (!no_new_pseudos || SMALL_INT (offset)))
2383 base = mips_force_temporary (dest, base);
2384 emit_move_insn (dest, mips_add_offset (0, base, INTVAL (offset)));
2388 src = force_const_mem (mode, src);
2390 /* When using explicit relocs, constant pool references are sometimes
2391 not legitimate addresses. */
2392 if (!memory_operand (src, VOIDmode))
2393 src = replace_equiv_address (src, mips_split_symbol (dest, XEXP (src, 0)));
2394 emit_move_insn (dest, src);
2398 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
2399 sequence that is valid. */
2402 mips_legitimize_move (enum machine_mode mode, rtx dest, rtx src)
2404 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
2406 emit_move_insn (dest, force_reg (mode, src));
2410 /* Check for individual, fully-reloaded mflo and mfhi instructions. */
2411 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
2412 && REG_P (src) && MD_REG_P (REGNO (src))
2413 && REG_P (dest) && GP_REG_P (REGNO (dest)))
2415 int other_regno = REGNO (src) == HI_REGNUM ? LO_REGNUM : HI_REGNUM;
2416 if (GET_MODE_SIZE (mode) <= 4)
2417 emit_insn (gen_mfhilo_si (gen_rtx_REG (SImode, REGNO (dest)),
2418 gen_rtx_REG (SImode, REGNO (src)),
2419 gen_rtx_REG (SImode, other_regno)));
2421 emit_insn (gen_mfhilo_di (gen_rtx_REG (DImode, REGNO (dest)),
2422 gen_rtx_REG (DImode, REGNO (src)),
2423 gen_rtx_REG (DImode, other_regno)));
2427 /* We need to deal with constants that would be legitimate
2428 immediate_operands but not legitimate move_operands. */
2429 if (CONSTANT_P (src) && !move_operand (src, mode))
2431 mips_legitimize_const_move (mode, dest, src);
2432 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
2438 /* We need a lot of little routines to check constant values on the
2439 mips16. These are used to figure out how long the instruction will
2440 be. It would be much better to do this using constraints, but
2441 there aren't nearly enough letters available. */
2444 m16_check_op (rtx op, int low, int high, int mask)
2446 return (GET_CODE (op) == CONST_INT
2447 && INTVAL (op) >= low
2448 && INTVAL (op) <= high
2449 && (INTVAL (op) & mask) == 0);
2453 m16_uimm3_b (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2455 return m16_check_op (op, 0x1, 0x8, 0);
2459 m16_simm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2461 return m16_check_op (op, - 0x8, 0x7, 0);
2465 m16_nsimm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2467 return m16_check_op (op, - 0x7, 0x8, 0);
2471 m16_simm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2473 return m16_check_op (op, - 0x10, 0xf, 0);
2477 m16_nsimm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2479 return m16_check_op (op, - 0xf, 0x10, 0);
2483 m16_uimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2485 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2489 m16_nuimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2491 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2495 m16_simm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2497 return m16_check_op (op, - 0x80, 0x7f, 0);
2501 m16_nsimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2503 return m16_check_op (op, - 0x7f, 0x80, 0);
2507 m16_uimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2509 return m16_check_op (op, 0x0, 0xff, 0);
2513 m16_nuimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2515 return m16_check_op (op, - 0xff, 0x0, 0);
2519 m16_uimm8_m1_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2521 return m16_check_op (op, - 0x1, 0xfe, 0);
2525 m16_uimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2527 return m16_check_op (op, 0x0, 0xff << 2, 3);
2531 m16_nuimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2533 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2537 m16_simm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2539 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2543 m16_nsimm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2545 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2549 mips_rtx_costs (rtx x, int code, int outer_code, int *total)
2551 enum machine_mode mode = GET_MODE (x);
2552 bool float_mode_p = FLOAT_MODE_P (mode);
2559 /* A number between 1 and 8 inclusive is efficient for a shift.
2560 Otherwise, we will need an extended instruction. */
2561 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2562 || (outer_code) == LSHIFTRT)
2564 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2567 *total = COSTS_N_INSNS (1);
2571 /* We can use cmpi for an xor with an unsigned 16-bit value. */
2572 if ((outer_code) == XOR
2573 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2579 /* We may be able to use slt or sltu for a comparison with a
2580 signed 16-bit value. (The boundary conditions aren't quite
2581 right, but this is just a heuristic anyhow.) */
2582 if (((outer_code) == LT || (outer_code) == LE
2583 || (outer_code) == GE || (outer_code) == GT
2584 || (outer_code) == LTU || (outer_code) == LEU
2585 || (outer_code) == GEU || (outer_code) == GTU)
2586 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2592 /* Equality comparisons with 0 are cheap. */
2593 if (((outer_code) == EQ || (outer_code) == NE)
2600 /* Constants in the range 0...255 can be loaded with an unextended
2601 instruction. They are therefore as cheap as a register move.
2603 Given the choice between "li R1,0...255" and "move R1,R2"
2604 (where R2 is a known constant), it is usually better to use "li",
2605 since we do not want to unnecessarily extend the lifetime
2607 if (outer_code == SET
2609 && INTVAL (x) < 256)
2617 /* These can be used anywhere. */
2622 /* Otherwise fall through to the handling below because
2623 we'll need to construct the constant. */
2629 if (LEGITIMATE_CONSTANT_P (x))
2631 *total = COSTS_N_INSNS (1);
2636 /* The value will need to be fetched from the constant pool. */
2637 *total = CONSTANT_POOL_COST;
2643 /* If the address is legitimate, return the number of
2644 instructions it needs, otherwise use the default handling. */
2645 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2648 *total = COSTS_N_INSNS (n + 1);
2655 *total = COSTS_N_INSNS (6);
2659 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2665 if (mode == DImode && !TARGET_64BIT)
2667 *total = COSTS_N_INSNS (2);
2675 if (mode == DImode && !TARGET_64BIT)
2677 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2685 *total = COSTS_N_INSNS (1);
2687 *total = COSTS_N_INSNS (4);
2691 *total = COSTS_N_INSNS (1);
2698 *total = mips_cost->fp_add;
2702 else if (mode == DImode && !TARGET_64BIT)
2704 *total = COSTS_N_INSNS (4);
2710 if (mode == DImode && !TARGET_64BIT)
2712 *total = COSTS_N_INSNS (4);
2719 *total = mips_cost->fp_mult_sf;
2721 else if (mode == DFmode)
2722 *total = mips_cost->fp_mult_df;
2724 else if (mode == SImode)
2725 *total = mips_cost->int_mult_si;
2728 *total = mips_cost->int_mult_di;
2737 *total = mips_cost->fp_div_sf;
2739 *total = mips_cost->fp_div_df;
2748 *total = mips_cost->int_div_di;
2750 *total = mips_cost->int_div_si;
2755 /* A sign extend from SImode to DImode in 64-bit mode is often
2756 zero instructions, because the result can often be used
2757 directly by another instruction; we'll call it one. */
2758 if (TARGET_64BIT && mode == DImode
2759 && GET_MODE (XEXP (x, 0)) == SImode)
2760 *total = COSTS_N_INSNS (1);
2762 *total = COSTS_N_INSNS (2);
2766 if (TARGET_64BIT && mode == DImode
2767 && GET_MODE (XEXP (x, 0)) == SImode)
2768 *total = COSTS_N_INSNS (2);
2770 *total = COSTS_N_INSNS (1);
2774 case UNSIGNED_FLOAT:
2777 case FLOAT_TRUNCATE:
2779 *total = mips_cost->fp_add;
2787 /* Provide the costs of an addressing mode that contains ADDR.
2788 If ADDR is not a valid address, its cost is irrelevant. */
2791 mips_address_cost (rtx addr)
2793 return mips_address_insns (addr, SImode);
2796 /* Return one word of double-word value OP, taking into account the fixed
2797 endianness of certain registers. HIGH_P is true to select the high part,
2798 false to select the low part. */
2801 mips_subword (rtx op, int high_p)
2804 enum machine_mode mode;
2806 mode = GET_MODE (op);
2807 if (mode == VOIDmode)
2810 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2811 byte = UNITS_PER_WORD;
2817 if (FP_REG_P (REGNO (op)))
2818 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2819 if (ACC_HI_REG_P (REGNO (op)))
2820 return gen_rtx_REG (word_mode, high_p ? REGNO (op) : REGNO (op) + 1);
2824 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
2826 return simplify_gen_subreg (word_mode, op, mode, byte);
2830 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2833 mips_split_64bit_move_p (rtx dest, rtx src)
2838 /* FP->FP moves can be done in a single instruction. */
2839 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2842 /* Check for floating-point loads and stores. They can be done using
2843 ldc1 and sdc1 on MIPS II and above. */
2846 if (FP_REG_RTX_P (dest) && MEM_P (src))
2848 if (FP_REG_RTX_P (src) && MEM_P (dest))
2855 /* Split a 64-bit move from SRC to DEST assuming that
2856 mips_split_64bit_move_p holds.
2858 Moves into and out of FPRs cause some difficulty here. Such moves
2859 will always be DFmode, since paired FPRs are not allowed to store
2860 DImode values. The most natural representation would be two separate
2861 32-bit moves, such as:
2863 (set (reg:SI $f0) (mem:SI ...))
2864 (set (reg:SI $f1) (mem:SI ...))
2866 However, the second insn is invalid because odd-numbered FPRs are
2867 not allowed to store independent values. Use the patterns load_df_low,
2868 load_df_high and store_df_high instead. */
2871 mips_split_64bit_move (rtx dest, rtx src)
2873 if (FP_REG_RTX_P (dest))
2875 /* Loading an FPR from memory or from GPRs. */
2878 dest = gen_lowpart (DFmode, dest);
2879 emit_insn (gen_load_df_low (dest, mips_subword (src, 0)));
2880 emit_insn (gen_mthc1 (dest, mips_subword (src, 1),
2885 emit_insn (gen_load_df_low (copy_rtx (dest),
2886 mips_subword (src, 0)));
2887 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2891 else if (FP_REG_RTX_P (src))
2893 /* Storing an FPR into memory or GPRs. */
2896 src = gen_lowpart (DFmode, src);
2897 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2898 emit_insn (gen_mfhc1 (mips_subword (dest, 1), src));
2902 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2903 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2908 /* The operation can be split into two normal moves. Decide in
2909 which order to do them. */
2912 low_dest = mips_subword (dest, 0);
2913 if (REG_P (low_dest)
2914 && reg_overlap_mentioned_p (low_dest, src))
2916 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2917 emit_move_insn (low_dest, mips_subword (src, 0));
2921 emit_move_insn (low_dest, mips_subword (src, 0));
2922 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2927 /* Return the appropriate instructions to move SRC into DEST. Assume
2928 that SRC is operand 1 and DEST is operand 0. */
2931 mips_output_move (rtx dest, rtx src)
2933 enum rtx_code dest_code, src_code;
2936 dest_code = GET_CODE (dest);
2937 src_code = GET_CODE (src);
2938 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2940 if (dbl_p && mips_split_64bit_move_p (dest, src))
2943 if ((src_code == REG && GP_REG_P (REGNO (src)))
2944 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2946 if (dest_code == REG)
2948 if (GP_REG_P (REGNO (dest)))
2949 return "move\t%0,%z1";
2951 if (MD_REG_P (REGNO (dest)))
2954 if (DSP_ACC_REG_P (REGNO (dest)))
2956 static char retval[] = "mt__\t%z1,%q0";
2957 retval[2] = reg_names[REGNO (dest)][4];
2958 retval[3] = reg_names[REGNO (dest)][5];
2962 if (FP_REG_P (REGNO (dest)))
2963 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2965 if (ALL_COP_REG_P (REGNO (dest)))
2967 static char retval[] = "dmtc_\t%z1,%0";
2969 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2970 return (dbl_p ? retval : retval + 1);
2973 if (dest_code == MEM)
2974 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2976 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2978 if (src_code == REG)
2980 if (DSP_ACC_REG_P (REGNO (src)))
2982 static char retval[] = "mf__\t%0,%q1";
2983 retval[2] = reg_names[REGNO (src)][4];
2984 retval[3] = reg_names[REGNO (src)][5];
2988 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2989 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2991 if (FP_REG_P (REGNO (src)))
2992 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2994 if (ALL_COP_REG_P (REGNO (src)))
2996 static char retval[] = "dmfc_\t%0,%1";
2998 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2999 return (dbl_p ? retval : retval + 1);
3003 if (src_code == MEM)
3004 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
3006 if (src_code == CONST_INT)
3008 /* Don't use the X format, because that will give out of
3009 range numbers for 64-bit hosts and 32-bit targets. */
3011 return "li\t%0,%1\t\t\t# %X1";
3013 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
3016 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
3020 if (src_code == HIGH)
3021 return "lui\t%0,%h1";
3023 if (CONST_GP_P (src))
3024 return "move\t%0,%1";
3026 if (symbolic_operand (src, VOIDmode))
3027 return (dbl_p ? "dla\t%0,%1" : "la\t%0,%1");
3029 if (src_code == REG && FP_REG_P (REGNO (src)))
3031 if (dest_code == REG && FP_REG_P (REGNO (dest)))
3033 if (GET_MODE (dest) == V2SFmode)
3034 return "mov.ps\t%0,%1";
3036 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
3039 if (dest_code == MEM)
3040 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
3042 if (dest_code == REG && FP_REG_P (REGNO (dest)))
3044 if (src_code == MEM)
3045 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
3047 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
3049 static char retval[] = "l_c_\t%0,%1";
3051 retval[1] = (dbl_p ? 'd' : 'w');
3052 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
3055 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
3057 static char retval[] = "s_c_\t%1,%0";
3059 retval[1] = (dbl_p ? 'd' : 'w');
3060 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
3066 /* Restore $gp from its save slot. Valid only when using o32 or
3070 mips_restore_gp (void)
3074 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI);
3076 address = mips_add_offset (pic_offset_table_rtx,
3077 frame_pointer_needed
3078 ? hard_frame_pointer_rtx
3079 : stack_pointer_rtx,
3080 current_function_outgoing_args_size);
3081 slot = gen_rtx_MEM (Pmode, address);
3083 emit_move_insn (pic_offset_table_rtx, slot);
3084 if (!TARGET_EXPLICIT_RELOCS)
3085 emit_insn (gen_blockage ());
3088 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
3091 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
3093 emit_insn (gen_rtx_SET (VOIDmode, target,
3094 gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
3097 /* Return true if CMP1 is a suitable second operand for relational
3098 operator CODE. See also the *sCC patterns in mips.md. */
3101 mips_relational_operand_ok_p (enum rtx_code code, rtx cmp1)
3107 return reg_or_0_operand (cmp1, VOIDmode);
3111 return !TARGET_MIPS16 && cmp1 == const1_rtx;
3115 return arith_operand (cmp1, VOIDmode);
3118 return sle_operand (cmp1, VOIDmode);
3121 return sleu_operand (cmp1, VOIDmode);
3128 /* Canonicalize LE or LEU comparisons into LT comparisons when
3129 possible to avoid extra instructions or inverting the
3133 mips_canonicalize_comparison (enum rtx_code *code, rtx *cmp1,
3134 enum machine_mode mode)
3136 HOST_WIDE_INT original, plus_one;
3138 if (GET_CODE (*cmp1) != CONST_INT)
3141 original = INTVAL (*cmp1);
3142 plus_one = trunc_int_for_mode ((unsigned HOST_WIDE_INT) original + 1, mode);
3147 if (original < plus_one)
3150 *cmp1 = force_reg (mode, GEN_INT (plus_one));
3159 *cmp1 = force_reg (mode, GEN_INT (plus_one));
3172 /* Compare CMP0 and CMP1 using relational operator CODE and store the
3173 result in TARGET. CMP0 and TARGET are register_operands that have
3174 the same integer mode. If INVERT_PTR is nonnull, it's OK to set
3175 TARGET to the inverse of the result and flip *INVERT_PTR instead. */
3178 mips_emit_int_relational (enum rtx_code code, bool *invert_ptr,
3179 rtx target, rtx cmp0, rtx cmp1)
3181 /* First see if there is a MIPS instruction that can do this operation
3182 with CMP1 in its current form. If not, try to canonicalize the
3183 comparison to LT. If that fails, try doing the same for the
3184 inverse operation. If that also fails, force CMP1 into a register
3186 if (mips_relational_operand_ok_p (code, cmp1))
3187 mips_emit_binary (code, target, cmp0, cmp1);
3188 else if (mips_canonicalize_comparison (&code, &cmp1, GET_MODE (target)))
3189 mips_emit_binary (code, target, cmp0, cmp1);
3192 enum rtx_code inv_code = reverse_condition (code);
3193 if (!mips_relational_operand_ok_p (inv_code, cmp1))
3195 cmp1 = force_reg (GET_MODE (cmp0), cmp1);
3196 mips_emit_int_relational (code, invert_ptr, target, cmp0, cmp1);
3198 else if (invert_ptr == 0)
3200 rtx inv_target = gen_reg_rtx (GET_MODE (target));
3201 mips_emit_binary (inv_code, inv_target, cmp0, cmp1);
3202 mips_emit_binary (XOR, target, inv_target, const1_rtx);
3206 *invert_ptr = !*invert_ptr;
3207 mips_emit_binary (inv_code, target, cmp0, cmp1);
3212 /* Return a register that is zero iff CMP0 and CMP1 are equal.
3213 The register will have the same mode as CMP0. */
3216 mips_zero_if_equal (rtx cmp0, rtx cmp1)
3218 if (cmp1 == const0_rtx)
3221 if (uns_arith_operand (cmp1, VOIDmode))
3222 return expand_binop (GET_MODE (cmp0), xor_optab,
3223 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
3225 return expand_binop (GET_MODE (cmp0), sub_optab,
3226 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
3229 /* Convert *CODE into a code that can be used in a floating-point
3230 scc instruction (c.<cond>.<fmt>). Return true if the values of
3231 the condition code registers will be inverted, with 0 indicating
3232 that the condition holds. */
3235 mips_reverse_fp_cond_p (enum rtx_code *code)
3242 *code = reverse_condition_maybe_unordered (*code);
3250 /* Convert a comparison into something that can be used in a branch or
3251 conditional move. cmp_operands[0] and cmp_operands[1] are the values
3252 being compared and *CODE is the code used to compare them.
3254 Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
3255 If NEED_EQ_NE_P, then only EQ/NE comparisons against zero are possible,
3256 otherwise any standard branch condition can be used. The standard branch
3259 - EQ/NE between two registers.
3260 - any comparison between a register and zero. */
3263 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
3265 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT)
3267 if (!need_eq_ne_p && cmp_operands[1] == const0_rtx)
3269 *op0 = cmp_operands[0];
3270 *op1 = cmp_operands[1];
3272 else if (*code == EQ || *code == NE)
3276 *op0 = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
3281 *op0 = cmp_operands[0];
3282 *op1 = force_reg (GET_MODE (*op0), cmp_operands[1]);
3287 /* The comparison needs a separate scc instruction. Store the
3288 result of the scc in *OP0 and compare it against zero. */
3289 bool invert = false;
3290 *op0 = gen_reg_rtx (GET_MODE (cmp_operands[0]));
3292 mips_emit_int_relational (*code, &invert, *op0,
3293 cmp_operands[0], cmp_operands[1]);
3294 *code = (invert ? EQ : NE);
3299 enum rtx_code cmp_code;
3301 /* Floating-point tests use a separate c.cond.fmt comparison to
3302 set a condition code register. The branch or conditional move
3303 will then compare that register against zero.
3305 Set CMP_CODE to the code of the comparison instruction and
3306 *CODE to the code that the branch or move should use. */
3308 *code = mips_reverse_fp_cond_p (&cmp_code) ? EQ : NE;
3310 ? gen_reg_rtx (CCmode)
3311 : gen_rtx_REG (CCmode, FPSW_REGNUM));
3313 mips_emit_binary (cmp_code, *op0, cmp_operands[0], cmp_operands[1]);
3317 /* Try comparing cmp_operands[0] and cmp_operands[1] using rtl code CODE.
3318 Store the result in TARGET and return true if successful.
3320 On 64-bit targets, TARGET may be wider than cmp_operands[0]. */
3323 mips_emit_scc (enum rtx_code code, rtx target)
3325 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) != MODE_INT)
3328 target = gen_lowpart (GET_MODE (cmp_operands[0]), target);
3329 if (code == EQ || code == NE)
3331 rtx zie = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
3332 mips_emit_binary (code, target, zie, const0_rtx);
3335 mips_emit_int_relational (code, 0, target,
3336 cmp_operands[0], cmp_operands[1]);
3340 /* Emit the common code for doing conditional branches.
3341 operand[0] is the label to jump to.
3342 The comparison operands are saved away by cmp{si,di,sf,df}. */
3345 gen_conditional_branch (rtx *operands, enum rtx_code code)
3347 rtx op0, op1, condition;
3349 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
3350 condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3351 emit_jump_insn (gen_condjump (condition, operands[0]));
3356 (set temp (COND:CCV2 CMP_OP0 CMP_OP1))
3357 (set DEST (unspec [TRUE_SRC FALSE_SRC temp] UNSPEC_MOVE_TF_PS)) */
3360 mips_expand_vcondv2sf (rtx dest, rtx true_src, rtx false_src,
3361 enum rtx_code cond, rtx cmp_op0, rtx cmp_op1)
3366 reversed_p = mips_reverse_fp_cond_p (&cond);
3367 cmp_result = gen_reg_rtx (CCV2mode);
3368 emit_insn (gen_scc_ps (cmp_result,
3369 gen_rtx_fmt_ee (cond, VOIDmode, cmp_op0, cmp_op1)));
3371 emit_insn (gen_mips_cond_move_tf_ps (dest, false_src, true_src,
3374 emit_insn (gen_mips_cond_move_tf_ps (dest, true_src, false_src,
3378 /* Emit the common code for conditional moves. OPERANDS is the array
3379 of operands passed to the conditional move define_expand. */
3382 gen_conditional_move (rtx *operands)
3387 code = GET_CODE (operands[1]);
3388 mips_emit_compare (&code, &op0, &op1, true);
3389 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3390 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
3391 gen_rtx_fmt_ee (code,
3394 operands[2], operands[3])));
3397 /* Emit a conditional trap. OPERANDS is the array of operands passed to
3398 the conditional_trap expander. */
3401 mips_gen_conditional_trap (rtx *operands)
3404 enum rtx_code cmp_code = GET_CODE (operands[0]);
3405 enum machine_mode mode = GET_MODE (cmp_operands[0]);
3407 /* MIPS conditional trap machine instructions don't have GT or LE
3408 flavors, so we must invert the comparison and convert to LT and
3409 GE, respectively. */
3412 case GT: cmp_code = LT; break;
3413 case LE: cmp_code = GE; break;
3414 case GTU: cmp_code = LTU; break;
3415 case LEU: cmp_code = GEU; break;
3418 if (cmp_code == GET_CODE (operands[0]))
3420 op0 = cmp_operands[0];
3421 op1 = cmp_operands[1];
3425 op0 = cmp_operands[1];
3426 op1 = cmp_operands[0];
3428 op0 = force_reg (mode, op0);
3429 if (!arith_operand (op1, mode))
3430 op1 = force_reg (mode, op1);
3432 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
3433 gen_rtx_fmt_ee (cmp_code, mode, op0, op1),
3437 /* Return true if calls to X can use R_MIPS_CALL* relocations. */
3440 mips_ok_for_lazy_binding_p (rtx x)
3442 return (TARGET_USE_GOT
3443 && GET_CODE (x) == SYMBOL_REF
3444 && !mips_symbol_binds_local_p (x));
3447 /* Load function address ADDR into register DEST. SIBCALL_P is true
3448 if the address is needed for a sibling call. */
3451 mips_load_call_address (rtx dest, rtx addr, int sibcall_p)
3453 /* If we're generating PIC, and this call is to a global function,
3454 try to allow its address to be resolved lazily. This isn't
3455 possible if TARGET_CALL_SAVED_GP since the value of $gp on entry
3456 to the stub would be our caller's gp, not ours. */
3457 if (TARGET_EXPLICIT_RELOCS
3458 && !(sibcall_p && TARGET_CALL_SAVED_GP)