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,
187 /* Specifies how a builtin function should be converted into rtl. */
188 enum mips_builtin_type
190 /* The builtin corresponds directly to an .md pattern. The return
191 value is mapped to operand 0 and the arguments are mapped to
192 operands 1 and above. */
195 /* The builtin corresponds directly to an .md pattern. There is no return
196 value and the arguments are mapped to operands 0 and above. */
197 MIPS_BUILTIN_DIRECT_NO_TARGET,
199 /* The builtin corresponds to a comparison instruction followed by
200 a mips_cond_move_tf_ps pattern. The first two arguments are the
201 values to compare and the second two arguments are the vector
202 operands for the movt.ps or movf.ps instruction (in assembly order). */
206 /* The builtin corresponds to a V2SF comparison instruction. Operand 0
207 of this instruction is the result of the comparison, which has mode
208 CCV2 or CCV4. The function arguments are mapped to operands 1 and
209 above. The function's return value is an SImode boolean that is
210 true under the following conditions:
212 MIPS_BUILTIN_CMP_ANY: one of the registers is true
213 MIPS_BUILTIN_CMP_ALL: all of the registers are true
214 MIPS_BUILTIN_CMP_LOWER: the first register is true
215 MIPS_BUILTIN_CMP_UPPER: the second register is true. */
216 MIPS_BUILTIN_CMP_ANY,
217 MIPS_BUILTIN_CMP_ALL,
218 MIPS_BUILTIN_CMP_UPPER,
219 MIPS_BUILTIN_CMP_LOWER,
221 /* As above, but the instruction only sets a single $fcc register. */
222 MIPS_BUILTIN_CMP_SINGLE,
224 /* For generating bposge32 branch instructions in MIPS32 DSP ASE. */
225 MIPS_BUILTIN_BPOSGE32
228 /* Invokes MACRO (COND) for each c.cond.fmt condition. */
229 #define MIPS_FP_CONDITIONS(MACRO) \
247 /* Enumerates the codes above as MIPS_FP_COND_<X>. */
248 #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X
249 enum mips_fp_condition {
250 MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)
253 /* Index X provides the string representation of MIPS_FP_COND_<X>. */
254 #define STRINGIFY(X) #X
255 static const char *const mips_fp_conditions[] = {
256 MIPS_FP_CONDITIONS (STRINGIFY)
259 /* A function to save or store a register. The first argument is the
260 register and the second is the stack slot. */
261 typedef void (*mips_save_restore_fn) (rtx, rtx);
263 struct mips16_constant;
264 struct mips_arg_info;
265 struct mips_address_info;
266 struct mips_integer_op;
269 static enum mips_symbol_type mips_classify_symbol (rtx);
270 static void mips_split_const (rtx, rtx *, HOST_WIDE_INT *);
271 static bool mips_offset_within_object_p (rtx, HOST_WIDE_INT);
272 static bool mips_valid_base_register_p (rtx, enum machine_mode, int);
273 static bool mips_symbolic_address_p (enum mips_symbol_type, enum machine_mode);
274 static bool mips_classify_address (struct mips_address_info *, rtx,
275 enum machine_mode, int);
276 static bool mips_cannot_force_const_mem (rtx);
277 static bool mips_use_blocks_for_constant_p (enum machine_mode, rtx);
278 static int mips_symbol_insns (enum mips_symbol_type);
279 static bool mips16_unextended_reference_p (enum machine_mode mode, rtx, rtx);
280 static rtx mips_force_temporary (rtx, rtx);
281 static rtx mips_unspec_offset_high (rtx, rtx, rtx, enum mips_symbol_type);
282 static rtx mips_add_offset (rtx, rtx, HOST_WIDE_INT);
283 static unsigned int mips_build_shift (struct mips_integer_op *, HOST_WIDE_INT);
284 static unsigned int mips_build_lower (struct mips_integer_op *,
285 unsigned HOST_WIDE_INT);
286 static unsigned int mips_build_integer (struct mips_integer_op *,
287 unsigned HOST_WIDE_INT);
288 static void mips_legitimize_const_move (enum machine_mode, rtx, rtx);
289 static int m16_check_op (rtx, int, int, int);
290 static bool mips_rtx_costs (rtx, int, int, int *);
291 static int mips_address_cost (rtx);
292 static void mips_emit_compare (enum rtx_code *, rtx *, rtx *, bool);
293 static void mips_load_call_address (rtx, rtx, int);
294 static bool mips_function_ok_for_sibcall (tree, tree);
295 static void mips_block_move_straight (rtx, rtx, HOST_WIDE_INT);
296 static void mips_adjust_block_mem (rtx, HOST_WIDE_INT, rtx *, rtx *);
297 static void mips_block_move_loop (rtx, rtx, HOST_WIDE_INT);
298 static void mips_arg_info (const CUMULATIVE_ARGS *, enum machine_mode,
299 tree, int, struct mips_arg_info *);
300 static bool mips_get_unaligned_mem (rtx *, unsigned int, int, rtx *, rtx *);
301 static void mips_set_architecture (const struct mips_cpu_info *);
302 static void mips_set_tune (const struct mips_cpu_info *);
303 static bool mips_handle_option (size_t, const char *, int);
304 static struct machine_function *mips_init_machine_status (void);
305 static void print_operand_reloc (FILE *, rtx, const char **);
307 static void irix_output_external_libcall (rtx);
309 static void mips_file_start (void);
310 static void mips_file_end (void);
311 static bool mips_rewrite_small_data_p (rtx);
312 static int mips_small_data_pattern_1 (rtx *, void *);
313 static int mips_rewrite_small_data_1 (rtx *, void *);
314 static bool mips_function_has_gp_insn (void);
315 static unsigned int mips_global_pointer (void);
316 static bool mips_save_reg_p (unsigned int);
317 static void mips_save_restore_reg (enum machine_mode, int, HOST_WIDE_INT,
318 mips_save_restore_fn);
319 static void mips_for_each_saved_reg (HOST_WIDE_INT, mips_save_restore_fn);
320 static void mips_output_cplocal (void);
321 static void mips_emit_loadgp (void);
322 static void mips_output_function_prologue (FILE *, HOST_WIDE_INT);
323 static void mips_set_frame_expr (rtx);
324 static rtx mips_frame_set (rtx, rtx);
325 static void mips_save_reg (rtx, rtx);
326 static void mips_output_function_epilogue (FILE *, HOST_WIDE_INT);
327 static void mips_restore_reg (rtx, rtx);
328 static void mips_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
329 HOST_WIDE_INT, tree);
330 static int symbolic_expression_p (rtx);
331 static section *mips_select_rtx_section (enum machine_mode, rtx,
332 unsigned HOST_WIDE_INT);
333 static section *mips_function_rodata_section (tree);
334 static bool mips_in_small_data_p (tree);
335 static bool mips_use_anchors_for_symbol_p (rtx);
336 static int mips_fpr_return_fields (tree, tree *);
337 static bool mips_return_in_msb (tree);
338 static rtx mips_return_fpr_pair (enum machine_mode mode,
339 enum machine_mode mode1, HOST_WIDE_INT,
340 enum machine_mode mode2, HOST_WIDE_INT);
341 static rtx mips16_gp_pseudo_reg (void);
342 static void mips16_fp_args (FILE *, int, int);
343 static void build_mips16_function_stub (FILE *);
344 static rtx dump_constants_1 (enum machine_mode, rtx, rtx);
345 static void dump_constants (struct mips16_constant *, rtx);
346 static int mips16_insn_length (rtx);
347 static int mips16_rewrite_pool_refs (rtx *, void *);
348 static void mips16_lay_out_constants (void);
349 static void mips_sim_reset (struct mips_sim *);
350 static void mips_sim_init (struct mips_sim *, state_t);
351 static void mips_sim_next_cycle (struct mips_sim *);
352 static void mips_sim_wait_reg (struct mips_sim *, rtx, rtx);
353 static int mips_sim_wait_regs_2 (rtx *, void *);
354 static void mips_sim_wait_regs_1 (rtx *, void *);
355 static void mips_sim_wait_regs (struct mips_sim *, rtx);
356 static void mips_sim_wait_units (struct mips_sim *, rtx);
357 static void mips_sim_wait_insn (struct mips_sim *, rtx);
358 static void mips_sim_record_set (rtx, rtx, void *);
359 static void mips_sim_issue_insn (struct mips_sim *, rtx);
360 static void mips_sim_issue_nop (struct mips_sim *);
361 static void mips_sim_finish_insn (struct mips_sim *, rtx);
362 static void vr4130_avoid_branch_rt_conflict (rtx);
363 static void vr4130_align_insns (void);
364 static void mips_avoid_hazard (rtx, rtx, int *, rtx *, rtx);
365 static void mips_avoid_hazards (void);
366 static void mips_reorg (void);
367 static bool mips_strict_matching_cpu_name_p (const char *, const char *);
368 static bool mips_matching_cpu_name_p (const char *, const char *);
369 static const struct mips_cpu_info *mips_parse_cpu (const char *);
370 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
371 static bool mips_return_in_memory (tree, tree);
372 static bool mips_strict_argument_naming (CUMULATIVE_ARGS *);
373 static void mips_macc_chains_record (rtx);
374 static void mips_macc_chains_reorder (rtx *, int);
375 static void vr4130_true_reg_dependence_p_1 (rtx, rtx, void *);
376 static bool vr4130_true_reg_dependence_p (rtx);
377 static bool vr4130_swap_insns_p (rtx, rtx);
378 static void vr4130_reorder (rtx *, int);
379 static void mips_promote_ready (rtx *, int, int);
380 static int mips_sched_reorder (FILE *, int, rtx *, int *, int);
381 static int mips_variable_issue (FILE *, int, rtx, int);
382 static int mips_adjust_cost (rtx, rtx, rtx, int);
383 static int mips_issue_rate (void);
384 static int mips_multipass_dfa_lookahead (void);
385 static void mips_init_libfuncs (void);
386 static void mips_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
388 static tree mips_build_builtin_va_list (void);
389 static tree mips_gimplify_va_arg_expr (tree, tree, tree *, tree *);
390 static bool mips_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode mode,
392 static bool mips_callee_copies (CUMULATIVE_ARGS *, enum machine_mode mode,
394 static int mips_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode mode,
396 static bool mips_valid_pointer_mode (enum machine_mode);
397 static bool mips_vector_mode_supported_p (enum machine_mode);
398 static rtx mips_prepare_builtin_arg (enum insn_code, unsigned int, tree *);
399 static rtx mips_prepare_builtin_target (enum insn_code, unsigned int, rtx);
400 static rtx mips_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
401 static void mips_init_builtins (void);
402 static rtx mips_expand_builtin_direct (enum insn_code, rtx, tree, bool);
403 static rtx mips_expand_builtin_movtf (enum mips_builtin_type,
404 enum insn_code, enum mips_fp_condition,
406 static rtx mips_expand_builtin_compare (enum mips_builtin_type,
407 enum insn_code, enum mips_fp_condition,
409 static rtx mips_expand_builtin_bposge (enum mips_builtin_type, rtx);
410 static void mips_encode_section_info (tree, rtx, int);
411 static void mips_extra_live_on_entry (bitmap);
412 static int mips_mode_rep_extended (enum machine_mode, enum machine_mode);
414 /* Structure to be filled in by compute_frame_size with register
415 save masks, and offsets for the current function. */
417 struct mips_frame_info GTY(())
419 HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up */
420 HOST_WIDE_INT var_size; /* # bytes that variables take up */
421 HOST_WIDE_INT args_size; /* # bytes that outgoing arguments take up */
422 HOST_WIDE_INT cprestore_size; /* # bytes that the .cprestore slot takes up */
423 HOST_WIDE_INT gp_reg_size; /* # bytes needed to store gp regs */
424 HOST_WIDE_INT fp_reg_size; /* # bytes needed to store fp regs */
425 unsigned int mask; /* mask of saved gp registers */
426 unsigned int fmask; /* mask of saved fp registers */
427 HOST_WIDE_INT gp_save_offset; /* offset from vfp to store gp registers */
428 HOST_WIDE_INT fp_save_offset; /* offset from vfp to store fp registers */
429 HOST_WIDE_INT gp_sp_offset; /* offset from new sp to store gp registers */
430 HOST_WIDE_INT fp_sp_offset; /* offset from new sp to store fp registers */
431 bool initialized; /* true if frame size already calculated */
432 int num_gp; /* number of gp registers saved */
433 int num_fp; /* number of fp registers saved */
436 struct machine_function GTY(()) {
437 /* Pseudo-reg holding the value of $28 in a mips16 function which
438 refers to GP relative global variables. */
439 rtx mips16_gp_pseudo_rtx;
441 /* The number of extra stack bytes taken up by register varargs.
442 This area is allocated by the callee at the very top of the frame. */
445 /* Current frame information, calculated by compute_frame_size. */
446 struct mips_frame_info frame;
448 /* The register to use as the global pointer within this function. */
449 unsigned int global_pointer;
451 /* True if mips_adjust_insn_length should ignore an instruction's
453 bool ignore_hazard_length_p;
455 /* True if the whole function is suitable for .set noreorder and
457 bool all_noreorder_p;
459 /* True if the function is known to have an instruction that needs $gp. */
463 /* Information about a single argument. */
466 /* True if the argument is passed in a floating-point register, or
467 would have been if we hadn't run out of registers. */
470 /* The number of words passed in registers, rounded up. */
471 unsigned int reg_words;
473 /* For EABI, the offset of the first register from GP_ARG_FIRST or
474 FP_ARG_FIRST. For other ABIs, the offset of the first register from
475 the start of the ABI's argument structure (see the CUMULATIVE_ARGS
476 comment for details).
478 The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely
480 unsigned int reg_offset;
482 /* The number of words that must be passed on the stack, rounded up. */
483 unsigned int stack_words;
485 /* The offset from the start of the stack overflow area of the argument's
486 first stack word. Only meaningful when STACK_WORDS is nonzero. */
487 unsigned int stack_offset;
491 /* Information about an address described by mips_address_type.
497 REG is the base register and OFFSET is the constant offset.
500 REG is the register that contains the high part of the address,
501 OFFSET is the symbolic address being referenced and SYMBOL_TYPE
502 is the type of OFFSET's symbol.
505 SYMBOL_TYPE is the type of symbol being referenced. */
507 struct mips_address_info
509 enum mips_address_type type;
512 enum mips_symbol_type symbol_type;
516 /* One stage in a constant building sequence. These sequences have
520 A = A CODE[1] VALUE[1]
521 A = A CODE[2] VALUE[2]
524 where A is an accumulator, each CODE[i] is a binary rtl operation
525 and each VALUE[i] is a constant integer. */
526 struct mips_integer_op {
528 unsigned HOST_WIDE_INT value;
532 /* The largest number of operations needed to load an integer constant.
533 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
534 When the lowest bit is clear, we can try, but reject a sequence with
535 an extra SLL at the end. */
536 #define MIPS_MAX_INTEGER_OPS 7
539 /* Global variables for machine-dependent things. */
541 /* Threshold for data being put into the small data/bss area, instead
542 of the normal data area. */
543 int mips_section_threshold = -1;
545 /* Count the number of .file directives, so that .loc is up to date. */
546 int num_source_filenames = 0;
548 /* Count the number of sdb related labels are generated (to find block
549 start and end boundaries). */
550 int sdb_label_count = 0;
552 /* Next label # for each statement for Silicon Graphics IRIS systems. */
555 /* Linked list of all externals that are to be emitted when optimizing
556 for the global pointer if they haven't been declared by the end of
557 the program with an appropriate .comm or initialization. */
559 struct extern_list GTY (())
561 struct extern_list *next; /* next external */
562 const char *name; /* name of the external */
563 int size; /* size in bytes */
566 static GTY (()) struct extern_list *extern_head = 0;
568 /* Name of the file containing the current function. */
569 const char *current_function_file = "";
571 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
577 /* The next branch instruction is a branch likely, not branch normal. */
578 int mips_branch_likely;
580 /* The operands passed to the last cmpMM expander. */
583 /* The target cpu for code generation. */
584 enum processor_type mips_arch;
585 const struct mips_cpu_info *mips_arch_info;
587 /* The target cpu for optimization and scheduling. */
588 enum processor_type mips_tune;
589 const struct mips_cpu_info *mips_tune_info;
591 /* Which instruction set architecture to use. */
594 /* Which ABI to use. */
595 int mips_abi = MIPS_ABI_DEFAULT;
597 /* Cost information to use. */
598 const struct mips_rtx_cost_data *mips_cost;
600 /* Whether we are generating mips16 hard float code. In mips16 mode
601 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
602 -msoft-float was not specified by the user, which means that we
603 should arrange to call mips32 hard floating point code. */
604 int mips16_hard_float;
606 /* The architecture selected by -mipsN. */
607 static const struct mips_cpu_info *mips_isa_info;
609 /* If TRUE, we split addresses into their high and low parts in the RTL. */
610 int mips_split_addresses;
612 /* Mode used for saving/restoring general purpose registers. */
613 static enum machine_mode gpr_mode;
615 /* Array giving truth value on whether or not a given hard register
616 can support a given mode. */
617 char mips_hard_regno_mode_ok[(int)MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
619 /* List of all MIPS punctuation characters used by print_operand. */
620 char mips_print_operand_punct[256];
622 /* Map GCC register number to debugger register number. */
623 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
625 /* A copy of the original flag_delayed_branch: see override_options. */
626 static int mips_flag_delayed_branch;
628 static GTY (()) int mips_output_filename_first_time = 1;
630 /* mips_split_p[X] is true if symbols of type X can be split by
631 mips_split_symbol(). */
632 bool mips_split_p[NUM_SYMBOL_TYPES];
634 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
635 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
636 if they are matched by a special .md file pattern. */
637 static const char *mips_lo_relocs[NUM_SYMBOL_TYPES];
639 /* Likewise for HIGHs. */
640 static const char *mips_hi_relocs[NUM_SYMBOL_TYPES];
642 /* Map hard register number to register class */
643 const enum reg_class mips_regno_to_class[] =
645 LEA_REGS, LEA_REGS, M16_NA_REGS, V1_REG,
646 M16_REGS, M16_REGS, M16_REGS, M16_REGS,
647 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
648 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
649 M16_NA_REGS, M16_NA_REGS, LEA_REGS, LEA_REGS,
650 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
651 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
652 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
653 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
654 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
655 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
656 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
657 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
658 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
659 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
660 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
661 HI_REG, LO_REG, NO_REGS, ST_REGS,
662 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
663 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
664 NO_REGS, ALL_REGS, ALL_REGS, NO_REGS,
665 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
666 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
667 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
668 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
669 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
670 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
671 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
672 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
673 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
674 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
675 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
676 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
677 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
678 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
679 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
680 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
681 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
682 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
683 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
684 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
685 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
686 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
687 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
688 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
689 DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS,
690 DSP_ACC_REGS, DSP_ACC_REGS, ALL_REGS, ALL_REGS,
691 ALL_REGS, ALL_REGS, ALL_REGS, ALL_REGS
694 /* Table of machine dependent attributes. */
695 const struct attribute_spec mips_attribute_table[] =
697 { "long_call", 0, 0, false, true, true, NULL },
698 { NULL, 0, 0, false, false, false, NULL }
701 /* A table describing all the processors gcc knows about. Names are
702 matched in the order listed. The first mention of an ISA level is
703 taken as the canonical name for that ISA.
705 To ease comparison, please keep this table in the same order as
706 gas's mips_cpu_info_table[]. */
707 const struct mips_cpu_info mips_cpu_info_table[] = {
708 /* Entries for generic ISAs */
709 { "mips1", PROCESSOR_R3000, 1 },
710 { "mips2", PROCESSOR_R6000, 2 },
711 { "mips3", PROCESSOR_R4000, 3 },
712 { "mips4", PROCESSOR_R8000, 4 },
713 { "mips32", PROCESSOR_4KC, 32 },
714 { "mips32r2", PROCESSOR_M4K, 33 },
715 { "mips64", PROCESSOR_5KC, 64 },
718 { "r3000", PROCESSOR_R3000, 1 },
719 { "r2000", PROCESSOR_R3000, 1 }, /* = r3000 */
720 { "r3900", PROCESSOR_R3900, 1 },
723 { "r6000", PROCESSOR_R6000, 2 },
726 { "r4000", PROCESSOR_R4000, 3 },
727 { "vr4100", PROCESSOR_R4100, 3 },
728 { "vr4111", PROCESSOR_R4111, 3 },
729 { "vr4120", PROCESSOR_R4120, 3 },
730 { "vr4130", PROCESSOR_R4130, 3 },
731 { "vr4300", PROCESSOR_R4300, 3 },
732 { "r4400", PROCESSOR_R4000, 3 }, /* = r4000 */
733 { "r4600", PROCESSOR_R4600, 3 },
734 { "orion", PROCESSOR_R4600, 3 }, /* = r4600 */
735 { "r4650", PROCESSOR_R4650, 3 },
738 { "r8000", PROCESSOR_R8000, 4 },
739 { "vr5000", PROCESSOR_R5000, 4 },
740 { "vr5400", PROCESSOR_R5400, 4 },
741 { "vr5500", PROCESSOR_R5500, 4 },
742 { "rm7000", PROCESSOR_R7000, 4 },
743 { "rm9000", PROCESSOR_R9000, 4 },
746 { "4kc", PROCESSOR_4KC, 32 },
747 { "4km", PROCESSOR_4KC, 32 }, /* = 4kc */
748 { "4kp", PROCESSOR_4KP, 32 },
750 /* MIPS32 Release 2 */
751 { "m4k", PROCESSOR_M4K, 33 },
752 { "4kec", PROCESSOR_4KC, 33 },
753 { "4kem", PROCESSOR_4KC, 33 },
754 { "4kep", PROCESSOR_4KP, 33 },
755 { "24kc", PROCESSOR_24KC, 33 }, /* 24K no FPU */
756 { "24kf", PROCESSOR_24KF, 33 }, /* 24K 1:2 FPU */
757 { "24kx", PROCESSOR_24KX, 33 }, /* 24K 1:1 FPU */
758 { "24kec", PROCESSOR_24KC, 33 }, /* 24K with DSP */
759 { "24kef", PROCESSOR_24KF, 33 },
760 { "24kex", PROCESSOR_24KX, 33 },
761 { "34kc", PROCESSOR_24KC, 33 }, /* 34K with MT/DSP */
762 { "34kf", PROCESSOR_24KF, 33 },
763 { "34kx", PROCESSOR_24KX, 33 },
766 { "5kc", PROCESSOR_5KC, 64 },
767 { "5kf", PROCESSOR_5KF, 64 },
768 { "20kc", PROCESSOR_20KC, 64 },
769 { "sb1", PROCESSOR_SB1, 64 },
770 { "sb1a", PROCESSOR_SB1A, 64 },
771 { "sr71000", PROCESSOR_SR71000, 64 },
777 /* Default costs. If these are used for a processor we should look
778 up the actual costs. */
779 #define DEFAULT_COSTS COSTS_N_INSNS (6), /* fp_add */ \
780 COSTS_N_INSNS (7), /* fp_mult_sf */ \
781 COSTS_N_INSNS (8), /* fp_mult_df */ \
782 COSTS_N_INSNS (23), /* fp_div_sf */ \
783 COSTS_N_INSNS (36), /* fp_div_df */ \
784 COSTS_N_INSNS (10), /* int_mult_si */ \
785 COSTS_N_INSNS (10), /* int_mult_di */ \
786 COSTS_N_INSNS (69), /* int_div_si */ \
787 COSTS_N_INSNS (69), /* int_div_di */ \
788 2, /* branch_cost */ \
789 4 /* memory_latency */
791 /* Need to replace these with the costs of calling the appropriate
793 #define SOFT_FP_COSTS COSTS_N_INSNS (256), /* fp_add */ \
794 COSTS_N_INSNS (256), /* fp_mult_sf */ \
795 COSTS_N_INSNS (256), /* fp_mult_df */ \
796 COSTS_N_INSNS (256), /* fp_div_sf */ \
797 COSTS_N_INSNS (256) /* fp_div_df */
799 static struct mips_rtx_cost_data const mips_rtx_cost_optimize_size =
801 COSTS_N_INSNS (1), /* fp_add */
802 COSTS_N_INSNS (1), /* fp_mult_sf */
803 COSTS_N_INSNS (1), /* fp_mult_df */
804 COSTS_N_INSNS (1), /* fp_div_sf */
805 COSTS_N_INSNS (1), /* fp_div_df */
806 COSTS_N_INSNS (1), /* int_mult_si */
807 COSTS_N_INSNS (1), /* int_mult_di */
808 COSTS_N_INSNS (1), /* int_div_si */
809 COSTS_N_INSNS (1), /* int_div_di */
811 4 /* memory_latency */
814 static struct mips_rtx_cost_data const mips_rtx_cost_data[PROCESSOR_MAX] =
817 COSTS_N_INSNS (2), /* fp_add */
818 COSTS_N_INSNS (4), /* fp_mult_sf */
819 COSTS_N_INSNS (5), /* fp_mult_df */
820 COSTS_N_INSNS (12), /* fp_div_sf */
821 COSTS_N_INSNS (19), /* fp_div_df */
822 COSTS_N_INSNS (12), /* int_mult_si */
823 COSTS_N_INSNS (12), /* int_mult_di */
824 COSTS_N_INSNS (35), /* int_div_si */
825 COSTS_N_INSNS (35), /* int_div_di */
827 4 /* memory_latency */
832 COSTS_N_INSNS (6), /* int_mult_si */
833 COSTS_N_INSNS (6), /* int_mult_di */
834 COSTS_N_INSNS (36), /* int_div_si */
835 COSTS_N_INSNS (36), /* int_div_di */
837 4 /* memory_latency */
841 COSTS_N_INSNS (36), /* int_mult_si */
842 COSTS_N_INSNS (36), /* int_mult_di */
843 COSTS_N_INSNS (37), /* int_div_si */
844 COSTS_N_INSNS (37), /* int_div_di */
846 4 /* memory_latency */
850 COSTS_N_INSNS (4), /* int_mult_si */
851 COSTS_N_INSNS (11), /* int_mult_di */
852 COSTS_N_INSNS (36), /* int_div_si */
853 COSTS_N_INSNS (68), /* int_div_di */
855 4 /* memory_latency */
858 COSTS_N_INSNS (4), /* fp_add */
859 COSTS_N_INSNS (4), /* fp_mult_sf */
860 COSTS_N_INSNS (5), /* fp_mult_df */
861 COSTS_N_INSNS (17), /* fp_div_sf */
862 COSTS_N_INSNS (32), /* fp_div_df */
863 COSTS_N_INSNS (4), /* int_mult_si */
864 COSTS_N_INSNS (11), /* int_mult_di */
865 COSTS_N_INSNS (36), /* int_div_si */
866 COSTS_N_INSNS (68), /* int_div_di */
868 4 /* memory_latency */
875 COSTS_N_INSNS (5), /* int_mult_si */
876 COSTS_N_INSNS (5), /* int_mult_di */
877 COSTS_N_INSNS (41), /* int_div_si */
878 COSTS_N_INSNS (41), /* int_div_di */
880 4 /* memory_latency */
883 COSTS_N_INSNS (8), /* fp_add */
884 COSTS_N_INSNS (8), /* fp_mult_sf */
885 COSTS_N_INSNS (10), /* fp_mult_df */
886 COSTS_N_INSNS (34), /* fp_div_sf */
887 COSTS_N_INSNS (64), /* fp_div_df */
888 COSTS_N_INSNS (5), /* int_mult_si */
889 COSTS_N_INSNS (5), /* int_mult_di */
890 COSTS_N_INSNS (41), /* int_div_si */
891 COSTS_N_INSNS (41), /* int_div_di */
893 4 /* memory_latency */
896 COSTS_N_INSNS (4), /* fp_add */
897 COSTS_N_INSNS (4), /* fp_mult_sf */
898 COSTS_N_INSNS (5), /* fp_mult_df */
899 COSTS_N_INSNS (17), /* fp_div_sf */
900 COSTS_N_INSNS (32), /* fp_div_df */
901 COSTS_N_INSNS (5), /* int_mult_si */
902 COSTS_N_INSNS (5), /* int_mult_di */
903 COSTS_N_INSNS (41), /* int_div_si */
904 COSTS_N_INSNS (41), /* int_div_di */
906 4 /* memory_latency */
912 COSTS_N_INSNS (2), /* fp_add */
913 COSTS_N_INSNS (4), /* fp_mult_sf */
914 COSTS_N_INSNS (5), /* fp_mult_df */
915 COSTS_N_INSNS (12), /* fp_div_sf */
916 COSTS_N_INSNS (19), /* fp_div_df */
917 COSTS_N_INSNS (2), /* int_mult_si */
918 COSTS_N_INSNS (2), /* int_mult_di */
919 COSTS_N_INSNS (35), /* int_div_si */
920 COSTS_N_INSNS (35), /* int_div_di */
922 4 /* memory_latency */
925 COSTS_N_INSNS (3), /* fp_add */
926 COSTS_N_INSNS (5), /* fp_mult_sf */
927 COSTS_N_INSNS (6), /* fp_mult_df */
928 COSTS_N_INSNS (15), /* fp_div_sf */
929 COSTS_N_INSNS (16), /* fp_div_df */
930 COSTS_N_INSNS (17), /* int_mult_si */
931 COSTS_N_INSNS (17), /* int_mult_di */
932 COSTS_N_INSNS (38), /* int_div_si */
933 COSTS_N_INSNS (38), /* int_div_di */
935 6 /* memory_latency */
938 COSTS_N_INSNS (6), /* fp_add */
939 COSTS_N_INSNS (7), /* fp_mult_sf */
940 COSTS_N_INSNS (8), /* fp_mult_df */
941 COSTS_N_INSNS (23), /* fp_div_sf */
942 COSTS_N_INSNS (36), /* fp_div_df */
943 COSTS_N_INSNS (10), /* int_mult_si */
944 COSTS_N_INSNS (10), /* int_mult_di */
945 COSTS_N_INSNS (69), /* int_div_si */
946 COSTS_N_INSNS (69), /* int_div_di */
948 6 /* memory_latency */
960 /* The only costs that appear to be updated here are
961 integer multiplication. */
963 COSTS_N_INSNS (4), /* int_mult_si */
964 COSTS_N_INSNS (6), /* int_mult_di */
965 COSTS_N_INSNS (69), /* int_div_si */
966 COSTS_N_INSNS (69), /* int_div_di */
968 4 /* memory_latency */
980 COSTS_N_INSNS (6), /* fp_add */
981 COSTS_N_INSNS (4), /* fp_mult_sf */
982 COSTS_N_INSNS (5), /* fp_mult_df */
983 COSTS_N_INSNS (23), /* fp_div_sf */
984 COSTS_N_INSNS (36), /* fp_div_df */
985 COSTS_N_INSNS (5), /* int_mult_si */
986 COSTS_N_INSNS (5), /* int_mult_di */
987 COSTS_N_INSNS (36), /* int_div_si */
988 COSTS_N_INSNS (36), /* int_div_di */
990 4 /* memory_latency */
993 COSTS_N_INSNS (6), /* fp_add */
994 COSTS_N_INSNS (5), /* fp_mult_sf */
995 COSTS_N_INSNS (6), /* fp_mult_df */
996 COSTS_N_INSNS (30), /* fp_div_sf */
997 COSTS_N_INSNS (59), /* fp_div_df */
998 COSTS_N_INSNS (3), /* int_mult_si */
999 COSTS_N_INSNS (4), /* int_mult_di */
1000 COSTS_N_INSNS (42), /* int_div_si */
1001 COSTS_N_INSNS (74), /* int_div_di */
1002 1, /* branch_cost */
1003 4 /* memory_latency */
1006 COSTS_N_INSNS (6), /* fp_add */
1007 COSTS_N_INSNS (5), /* fp_mult_sf */
1008 COSTS_N_INSNS (6), /* fp_mult_df */
1009 COSTS_N_INSNS (30), /* fp_div_sf */
1010 COSTS_N_INSNS (59), /* fp_div_df */
1011 COSTS_N_INSNS (5), /* int_mult_si */
1012 COSTS_N_INSNS (9), /* int_mult_di */
1013 COSTS_N_INSNS (42), /* int_div_si */
1014 COSTS_N_INSNS (74), /* int_div_di */
1015 1, /* branch_cost */
1016 4 /* memory_latency */
1019 /* The only costs that are changed here are
1020 integer multiplication. */
1021 COSTS_N_INSNS (6), /* fp_add */
1022 COSTS_N_INSNS (7), /* fp_mult_sf */
1023 COSTS_N_INSNS (8), /* fp_mult_df */
1024 COSTS_N_INSNS (23), /* fp_div_sf */
1025 COSTS_N_INSNS (36), /* fp_div_df */
1026 COSTS_N_INSNS (5), /* int_mult_si */
1027 COSTS_N_INSNS (9), /* int_mult_di */
1028 COSTS_N_INSNS (69), /* int_div_si */
1029 COSTS_N_INSNS (69), /* int_div_di */
1030 1, /* branch_cost */
1031 4 /* memory_latency */
1037 /* The only costs that are changed here are
1038 integer multiplication. */
1039 COSTS_N_INSNS (6), /* fp_add */
1040 COSTS_N_INSNS (7), /* fp_mult_sf */
1041 COSTS_N_INSNS (8), /* fp_mult_df */
1042 COSTS_N_INSNS (23), /* fp_div_sf */
1043 COSTS_N_INSNS (36), /* fp_div_df */
1044 COSTS_N_INSNS (3), /* int_mult_si */
1045 COSTS_N_INSNS (8), /* int_mult_di */
1046 COSTS_N_INSNS (69), /* int_div_si */
1047 COSTS_N_INSNS (69), /* int_div_di */
1048 1, /* branch_cost */
1049 4 /* memory_latency */
1052 /* These costs are the same as the SB-1A below. */
1053 COSTS_N_INSNS (4), /* fp_add */
1054 COSTS_N_INSNS (4), /* fp_mult_sf */
1055 COSTS_N_INSNS (4), /* fp_mult_df */
1056 COSTS_N_INSNS (24), /* fp_div_sf */
1057 COSTS_N_INSNS (32), /* fp_div_df */
1058 COSTS_N_INSNS (3), /* int_mult_si */
1059 COSTS_N_INSNS (4), /* int_mult_di */
1060 COSTS_N_INSNS (36), /* int_div_si */
1061 COSTS_N_INSNS (68), /* int_div_di */
1062 1, /* branch_cost */
1063 4 /* memory_latency */
1066 /* These costs are the same as the SB-1 above. */
1067 COSTS_N_INSNS (4), /* fp_add */
1068 COSTS_N_INSNS (4), /* fp_mult_sf */
1069 COSTS_N_INSNS (4), /* fp_mult_df */
1070 COSTS_N_INSNS (24), /* fp_div_sf */
1071 COSTS_N_INSNS (32), /* fp_div_df */
1072 COSTS_N_INSNS (3), /* int_mult_si */
1073 COSTS_N_INSNS (4), /* int_mult_di */
1074 COSTS_N_INSNS (36), /* int_div_si */
1075 COSTS_N_INSNS (68), /* int_div_di */
1076 1, /* branch_cost */
1077 4 /* memory_latency */
1085 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
1086 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
1087 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
1090 /* Initialize the GCC target structure. */
1091 #undef TARGET_ASM_ALIGNED_HI_OP
1092 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
1093 #undef TARGET_ASM_ALIGNED_SI_OP
1094 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
1095 #undef TARGET_ASM_ALIGNED_DI_OP
1096 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
1098 #undef TARGET_ASM_FUNCTION_PROLOGUE
1099 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
1100 #undef TARGET_ASM_FUNCTION_EPILOGUE
1101 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
1102 #undef TARGET_ASM_SELECT_RTX_SECTION
1103 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
1104 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
1105 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
1107 #undef TARGET_SCHED_REORDER
1108 #define TARGET_SCHED_REORDER mips_sched_reorder
1109 #undef TARGET_SCHED_VARIABLE_ISSUE
1110 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
1111 #undef TARGET_SCHED_ADJUST_COST
1112 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
1113 #undef TARGET_SCHED_ISSUE_RATE
1114 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
1115 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
1116 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
1117 mips_multipass_dfa_lookahead
1119 #undef TARGET_DEFAULT_TARGET_FLAGS
1120 #define TARGET_DEFAULT_TARGET_FLAGS \
1122 | TARGET_CPU_DEFAULT \
1123 | TARGET_ENDIAN_DEFAULT \
1124 | TARGET_FP_EXCEPTIONS_DEFAULT \
1125 | MASK_CHECK_ZERO_DIV \
1127 #undef TARGET_HANDLE_OPTION
1128 #define TARGET_HANDLE_OPTION mips_handle_option
1130 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
1131 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
1133 #undef TARGET_VALID_POINTER_MODE
1134 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
1135 #undef TARGET_RTX_COSTS
1136 #define TARGET_RTX_COSTS mips_rtx_costs
1137 #undef TARGET_ADDRESS_COST
1138 #define TARGET_ADDRESS_COST mips_address_cost
1140 #undef TARGET_IN_SMALL_DATA_P
1141 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
1143 #undef TARGET_MACHINE_DEPENDENT_REORG
1144 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
1146 #undef TARGET_ASM_FILE_START
1147 #undef TARGET_ASM_FILE_END
1148 #define TARGET_ASM_FILE_START mips_file_start
1149 #define TARGET_ASM_FILE_END mips_file_end
1150 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
1151 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
1153 #undef TARGET_INIT_LIBFUNCS
1154 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
1156 #undef TARGET_BUILD_BUILTIN_VA_LIST
1157 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
1158 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
1159 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
1161 #undef TARGET_PROMOTE_FUNCTION_ARGS
1162 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
1163 #undef TARGET_PROMOTE_FUNCTION_RETURN
1164 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
1165 #undef TARGET_PROMOTE_PROTOTYPES
1166 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
1168 #undef TARGET_RETURN_IN_MEMORY
1169 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
1170 #undef TARGET_RETURN_IN_MSB
1171 #define TARGET_RETURN_IN_MSB mips_return_in_msb
1173 #undef TARGET_ASM_OUTPUT_MI_THUNK
1174 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
1175 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
1176 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
1178 #undef TARGET_SETUP_INCOMING_VARARGS
1179 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
1180 #undef TARGET_STRICT_ARGUMENT_NAMING
1181 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
1182 #undef TARGET_MUST_PASS_IN_STACK
1183 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
1184 #undef TARGET_PASS_BY_REFERENCE
1185 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
1186 #undef TARGET_CALLEE_COPIES
1187 #define TARGET_CALLEE_COPIES mips_callee_copies
1188 #undef TARGET_ARG_PARTIAL_BYTES
1189 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
1191 #undef TARGET_MODE_REP_EXTENDED
1192 #define TARGET_MODE_REP_EXTENDED mips_mode_rep_extended
1194 #undef TARGET_VECTOR_MODE_SUPPORTED_P
1195 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
1197 #undef TARGET_INIT_BUILTINS
1198 #define TARGET_INIT_BUILTINS mips_init_builtins
1199 #undef TARGET_EXPAND_BUILTIN
1200 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
1202 #undef TARGET_HAVE_TLS
1203 #define TARGET_HAVE_TLS HAVE_AS_TLS
1205 #undef TARGET_CANNOT_FORCE_CONST_MEM
1206 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
1208 #undef TARGET_ENCODE_SECTION_INFO
1209 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
1211 #undef TARGET_ATTRIBUTE_TABLE
1212 #define TARGET_ATTRIBUTE_TABLE mips_attribute_table
1214 #undef TARGET_EXTRA_LIVE_ON_ENTRY
1215 #define TARGET_EXTRA_LIVE_ON_ENTRY mips_extra_live_on_entry
1217 #undef TARGET_MIN_ANCHOR_OFFSET
1218 #define TARGET_MIN_ANCHOR_OFFSET -32768
1219 #undef TARGET_MAX_ANCHOR_OFFSET
1220 #define TARGET_MAX_ANCHOR_OFFSET 32767
1221 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
1222 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P mips_use_blocks_for_constant_p
1223 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
1224 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P mips_use_anchors_for_symbol_p
1226 struct gcc_target targetm = TARGET_INITIALIZER;
1228 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
1230 static enum mips_symbol_type
1231 mips_classify_symbol (rtx x)
1235 if (GET_CODE (x) == LABEL_REF)
1238 return SYMBOL_CONSTANT_POOL;
1239 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
1240 return SYMBOL_GOT_LOCAL;
1241 return SYMBOL_GENERAL;
1244 gcc_assert (GET_CODE (x) == SYMBOL_REF);
1246 if (SYMBOL_REF_TLS_MODEL (x))
1249 if (CONSTANT_POOL_ADDRESS_P (x))
1252 return SYMBOL_CONSTANT_POOL;
1254 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
1255 return SYMBOL_SMALL_DATA;
1258 /* Do not use small-data accesses for weak symbols; they may end up
1260 if (SYMBOL_REF_SMALL_P (x)
1261 && !SYMBOL_REF_WEAK (x))
1262 return SYMBOL_SMALL_DATA;
1264 if (TARGET_ABICALLS)
1266 decl = SYMBOL_REF_DECL (x);
1269 if (!SYMBOL_REF_LOCAL_P (x))
1270 return SYMBOL_GOT_GLOBAL;
1274 /* Don't use GOT accesses for locally-binding symbols if
1275 TARGET_ABSOLUTE_ABICALLS. Otherwise, there are three
1278 - o32 PIC (either with or without explicit relocs)
1279 - n32/n64 PIC without explicit relocs
1280 - n32/n64 PIC with explicit relocs
1282 In the first case, both local and global accesses will use an
1283 R_MIPS_GOT16 relocation. We must correctly predict which of
1284 the two semantics (local or global) the assembler and linker
1285 will apply. The choice doesn't depend on the symbol's
1286 visibility, so we deliberately ignore decl_visibility and
1289 In the second case, the assembler will not use R_MIPS_GOT16
1290 relocations, but it chooses between local and global accesses
1291 in the same way as for o32 PIC.
1293 In the third case we have more freedom since both forms of
1294 access will work for any kind of symbol. However, there seems
1295 little point in doing things differently.
1297 Note that weakref symbols are not TREE_PUBLIC, but their
1298 targets are global or weak symbols. Relocations in the
1299 object file will be against the target symbol, so it's
1300 that symbol's binding that matters here. */
1302 && (TREE_PUBLIC (decl) || DECL_WEAK (decl))
1303 && !(TARGET_ABSOLUTE_ABICALLS && targetm.binds_local_p (decl)))
1304 return SYMBOL_GOT_GLOBAL;
1307 if (!TARGET_ABSOLUTE_ABICALLS)
1308 return SYMBOL_GOT_LOCAL;
1311 return SYMBOL_GENERAL;
1315 /* Split X into a base and a constant offset, storing them in *BASE
1316 and *OFFSET respectively. */
1319 mips_split_const (rtx x, rtx *base, HOST_WIDE_INT *offset)
1323 if (GET_CODE (x) == CONST)
1326 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
1328 *offset += INTVAL (XEXP (x, 1));
1336 /* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
1337 to the same object as SYMBOL, or to the same object_block. */
1340 mips_offset_within_object_p (rtx symbol, HOST_WIDE_INT offset)
1342 if (GET_CODE (symbol) != SYMBOL_REF)
1345 if (CONSTANT_POOL_ADDRESS_P (symbol)
1347 && offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
1350 if (SYMBOL_REF_DECL (symbol) != 0
1352 && offset < int_size_in_bytes (TREE_TYPE (SYMBOL_REF_DECL (symbol))))
1355 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol)
1356 && SYMBOL_REF_BLOCK (symbol)
1357 && SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0
1358 && ((unsigned HOST_WIDE_INT) offset + SYMBOL_REF_BLOCK_OFFSET (symbol)
1359 < (unsigned HOST_WIDE_INT) SYMBOL_REF_BLOCK (symbol)->size))
1366 /* Return true if X is a symbolic constant that can be calculated in
1367 the same way as a bare symbol. If it is, store the type of the
1368 symbol in *SYMBOL_TYPE. */
1371 mips_symbolic_constant_p (rtx x, enum mips_symbol_type *symbol_type)
1373 HOST_WIDE_INT offset;
1375 mips_split_const (x, &x, &offset);
1376 if (UNSPEC_ADDRESS_P (x))
1377 *symbol_type = UNSPEC_ADDRESS_TYPE (x);
1378 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1380 *symbol_type = mips_classify_symbol (x);
1381 if (*symbol_type == SYMBOL_TLS)
1390 /* Check whether a nonzero offset is valid for the underlying
1392 switch (*symbol_type)
1394 case SYMBOL_GENERAL:
1395 case SYMBOL_64_HIGH:
1398 /* If the target has 64-bit pointers and the object file only
1399 supports 32-bit symbols, the values of those symbols will be
1400 sign-extended. In this case we can't allow an arbitrary offset
1401 in case the 32-bit value X + OFFSET has a different sign from X. */
1402 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
1403 return mips_offset_within_object_p (x, offset);
1405 /* In other cases the relocations can handle any offset. */
1408 case SYMBOL_CONSTANT_POOL:
1409 /* Allow constant pool references to be converted to LABEL+CONSTANT.
1410 In this case, we no longer have access to the underlying constant,
1411 but the original symbol-based access was known to be valid. */
1412 if (GET_CODE (x) == LABEL_REF)
1417 case SYMBOL_SMALL_DATA:
1418 /* Make sure that the offset refers to something within the
1419 underlying object. This should guarantee that the final
1420 PC- or GP-relative offset is within the 16-bit limit. */
1421 return mips_offset_within_object_p (x, offset);
1423 case SYMBOL_GOT_LOCAL:
1424 case SYMBOL_GOTOFF_PAGE:
1425 /* The linker should provide enough local GOT entries for a
1426 16-bit offset. Larger offsets may lead to GOT overflow. */
1427 return SMALL_OPERAND (offset);
1429 case SYMBOL_GOT_GLOBAL:
1430 case SYMBOL_GOTOFF_GLOBAL:
1431 case SYMBOL_GOTOFF_CALL:
1432 case SYMBOL_GOTOFF_LOADGP:
1437 case SYMBOL_GOTTPREL:
1445 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1448 mips_regno_mode_ok_for_base_p (int regno, enum machine_mode mode, int strict)
1450 if (regno >= FIRST_PSEUDO_REGISTER)
1454 regno = reg_renumber[regno];
1457 /* These fake registers will be eliminated to either the stack or
1458 hard frame pointer, both of which are usually valid base registers.
1459 Reload deals with the cases where the eliminated form isn't valid. */
1460 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
1463 /* In mips16 mode, the stack pointer can only address word and doubleword
1464 values, nothing smaller. There are two problems here:
1466 (a) Instantiating virtual registers can introduce new uses of the
1467 stack pointer. If these virtual registers are valid addresses,
1468 the stack pointer should be too.
1470 (b) Most uses of the stack pointer are not made explicit until
1471 FRAME_POINTER_REGNUM and ARG_POINTER_REGNUM have been eliminated.
1472 We don't know until that stage whether we'll be eliminating to the
1473 stack pointer (which needs the restriction) or the hard frame
1474 pointer (which doesn't).
1476 All in all, it seems more consistent to only enforce this restriction
1477 during and after reload. */
1478 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
1479 return !strict || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1481 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
1485 /* Return true if X is a valid base register for the given mode.
1486 Allow only hard registers if STRICT. */
1489 mips_valid_base_register_p (rtx x, enum machine_mode mode, int strict)
1491 if (!strict && GET_CODE (x) == SUBREG)
1495 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict));
1499 /* Return true if symbols of type SYMBOL_TYPE can directly address a value
1500 with mode MODE. This is used for both symbolic and LO_SUM addresses. */
1503 mips_symbolic_address_p (enum mips_symbol_type symbol_type,
1504 enum machine_mode mode)
1506 switch (symbol_type)
1508 case SYMBOL_GENERAL:
1509 return !TARGET_MIPS16;
1511 case SYMBOL_SMALL_DATA:
1514 case SYMBOL_CONSTANT_POOL:
1515 /* PC-relative addressing is only available for lw and ld. */
1516 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1518 case SYMBOL_GOT_LOCAL:
1521 case SYMBOL_GOT_GLOBAL:
1522 /* The address will have to be loaded from the GOT first. */
1525 case SYMBOL_GOTOFF_PAGE:
1526 case SYMBOL_GOTOFF_GLOBAL:
1527 case SYMBOL_GOTOFF_CALL:
1528 case SYMBOL_GOTOFF_LOADGP:
1533 case SYMBOL_GOTTPREL:
1535 case SYMBOL_64_HIGH:
1544 /* Return true if X is a valid address for machine mode MODE. If it is,
1545 fill in INFO appropriately. STRICT is true if we should only accept
1546 hard base registers. */
1549 mips_classify_address (struct mips_address_info *info, rtx x,
1550 enum machine_mode mode, int strict)
1552 switch (GET_CODE (x))
1556 info->type = ADDRESS_REG;
1558 info->offset = const0_rtx;
1559 return mips_valid_base_register_p (info->reg, mode, strict);
1562 info->type = ADDRESS_REG;
1563 info->reg = XEXP (x, 0);
1564 info->offset = XEXP (x, 1);
1565 return (mips_valid_base_register_p (info->reg, mode, strict)
1566 && const_arith_operand (info->offset, VOIDmode));
1569 info->type = ADDRESS_LO_SUM;
1570 info->reg = XEXP (x, 0);
1571 info->offset = XEXP (x, 1);
1572 return (mips_valid_base_register_p (info->reg, mode, strict)
1573 && mips_symbolic_constant_p (info->offset, &info->symbol_type)
1574 && mips_symbolic_address_p (info->symbol_type, mode)
1575 && mips_lo_relocs[info->symbol_type] != 0);
1578 /* Small-integer addresses don't occur very often, but they
1579 are legitimate if $0 is a valid base register. */
1580 info->type = ADDRESS_CONST_INT;
1581 return !TARGET_MIPS16 && SMALL_INT (x);
1586 info->type = ADDRESS_SYMBOLIC;
1587 return (mips_symbolic_constant_p (x, &info->symbol_type)
1588 && mips_symbolic_address_p (info->symbol_type, mode)
1589 && !mips_split_p[info->symbol_type]);
1596 /* Return true if X is a thread-local symbol. */
1599 mips_tls_operand_p (rtx x)
1601 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
1604 /* Return true if X can not be forced into a constant pool. */
1607 mips_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1609 return mips_tls_operand_p (*x);
1612 /* Return true if X can not be forced into a constant pool. */
1615 mips_cannot_force_const_mem (rtx x)
1618 HOST_WIDE_INT offset;
1622 /* As an optimization, reject constants that mips_legitimize_move
1625 Suppose we have a multi-instruction sequence that loads constant C
1626 into register R. If R does not get allocated a hard register, and
1627 R is used in an operand that allows both registers and memory
1628 references, reload will consider forcing C into memory and using
1629 one of the instruction's memory alternatives. Returning false
1630 here will force it to use an input reload instead. */
1631 if (GET_CODE (x) == CONST_INT)
1634 mips_split_const (x, &base, &offset);
1635 if (symbolic_operand (base, VOIDmode) && SMALL_OPERAND (offset))
1639 if (TARGET_HAVE_TLS && for_each_rtx (&x, &mips_tls_symbol_ref_1, 0))
1645 /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. MIPS16 uses per-function
1646 constant pools, but normal-mode code doesn't need to. */
1649 mips_use_blocks_for_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1650 rtx x ATTRIBUTE_UNUSED)
1652 return !TARGET_MIPS16;
1655 /* Return the number of instructions needed to load a symbol of the
1656 given type into a register. If valid in an address, the same number
1657 of instructions are needed for loads and stores. Treat extended
1658 mips16 instructions as two instructions. */
1661 mips_symbol_insns (enum mips_symbol_type type)
1665 case SYMBOL_GENERAL:
1666 /* In mips16 code, general symbols must be fetched from the
1671 /* When using 64-bit symbols, we need 5 preparatory instructions,
1674 lui $at,%highest(symbol)
1675 daddiu $at,$at,%higher(symbol)
1677 daddiu $at,$at,%hi(symbol)
1680 The final address is then $at + %lo(symbol). With 32-bit
1681 symbols we just need a preparatory lui. */
1682 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1684 case SYMBOL_SMALL_DATA:
1687 case SYMBOL_CONSTANT_POOL:
1688 /* This case is for mips16 only. Assume we'll need an
1689 extended instruction. */
1692 case SYMBOL_GOT_LOCAL:
1693 case SYMBOL_GOT_GLOBAL:
1694 /* Unless -funit-at-a-time is in effect, we can't be sure whether
1695 the local/global classification is accurate. See override_options
1698 The worst cases are:
1700 (1) For local symbols when generating o32 or o64 code. The assembler
1706 ...and the final address will be $at + %lo(symbol).
1708 (2) For global symbols when -mxgot. The assembler will use:
1710 lui $at,%got_hi(symbol)
1713 ...and the final address will be $at + %got_lo(symbol). */
1716 case SYMBOL_GOTOFF_PAGE:
1717 case SYMBOL_GOTOFF_GLOBAL:
1718 case SYMBOL_GOTOFF_CALL:
1719 case SYMBOL_GOTOFF_LOADGP:
1720 case SYMBOL_64_HIGH:
1726 case SYMBOL_GOTTPREL:
1728 /* Check whether the offset is a 16- or 32-bit value. */
1729 return mips_split_p[type] ? 2 : 1;
1732 /* We don't treat a bare TLS symbol as a constant. */
1738 /* Return true if X is a legitimate $sp-based address for mode MDOE. */
1741 mips_stack_address_p (rtx x, enum machine_mode mode)
1743 struct mips_address_info addr;
1745 return (mips_classify_address (&addr, x, mode, false)
1746 && addr.type == ADDRESS_REG
1747 && addr.reg == stack_pointer_rtx);
1750 /* Return true if a value at OFFSET bytes from BASE can be accessed
1751 using an unextended mips16 instruction. MODE is the mode of the
1754 Usually the offset in an unextended instruction is a 5-bit field.
1755 The offset is unsigned and shifted left once for HIs, twice
1756 for SIs, and so on. An exception is SImode accesses off the
1757 stack pointer, which have an 8-bit immediate field. */
1760 mips16_unextended_reference_p (enum machine_mode mode, rtx base, rtx offset)
1763 && GET_CODE (offset) == CONST_INT
1764 && INTVAL (offset) >= 0
1765 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1767 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1768 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1769 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1775 /* Return the number of instructions needed to load or store a value
1776 of mode MODE at X. Return 0 if X isn't valid for MODE.
1778 For mips16 code, count extended instructions as two instructions. */
1781 mips_address_insns (rtx x, enum machine_mode mode)
1783 struct mips_address_info addr;
1786 if (mode == BLKmode)
1787 /* BLKmode is used for single unaligned loads and stores. */
1790 /* Each word of a multi-word value will be accessed individually. */
1791 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1793 if (mips_classify_address (&addr, x, mode, false))
1798 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1802 case ADDRESS_LO_SUM:
1803 return (TARGET_MIPS16 ? factor * 2 : factor);
1805 case ADDRESS_CONST_INT:
1808 case ADDRESS_SYMBOLIC:
1809 return factor * mips_symbol_insns (addr.symbol_type);
1815 /* Likewise for constant X. */
1818 mips_const_insns (rtx x)
1820 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1821 enum mips_symbol_type symbol_type;
1822 HOST_WIDE_INT offset;
1824 switch (GET_CODE (x))
1828 || !mips_symbolic_constant_p (XEXP (x, 0), &symbol_type)
1829 || !mips_split_p[symbol_type])
1836 /* Unsigned 8-bit constants can be loaded using an unextended
1837 LI instruction. Unsigned 16-bit constants can be loaded
1838 using an extended LI. Negative constants must be loaded
1839 using LI and then negated. */
1840 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1841 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1842 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1843 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1846 return mips_build_integer (codes, INTVAL (x));
1850 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1856 /* See if we can refer to X directly. */
1857 if (mips_symbolic_constant_p (x, &symbol_type))
1858 return mips_symbol_insns (symbol_type);
1860 /* Otherwise try splitting the constant into a base and offset.
1861 16-bit offsets can be added using an extra addiu. Larger offsets
1862 must be calculated separately and then added to the base. */
1863 mips_split_const (x, &x, &offset);
1866 int n = mips_const_insns (x);
1869 if (SMALL_OPERAND (offset))
1872 return n + 1 + mips_build_integer (codes, offset);
1879 return mips_symbol_insns (mips_classify_symbol (x));
1887 /* Return the number of instructions needed for memory reference X.
1888 Count extended mips16 instructions as two instructions. */
1891 mips_fetch_insns (rtx x)
1893 gcc_assert (MEM_P (x));
1894 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1898 /* Return the number of instructions needed for an integer division. */
1901 mips_idiv_insns (void)
1906 if (TARGET_CHECK_ZERO_DIV)
1908 if (GENERATE_DIVIDE_TRAPS)
1914 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
1919 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1920 returns a nonzero value if X is a legitimate address for a memory
1921 operand of the indicated MODE. STRICT is nonzero if this function
1922 is called during reload. */
1925 mips_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1927 struct mips_address_info addr;
1929 return mips_classify_address (&addr, x, mode, strict);
1933 /* Copy VALUE to a register and return that register. If new psuedos
1934 are allowed, copy it into a new register, otherwise use DEST. */
1937 mips_force_temporary (rtx dest, rtx value)
1939 if (!no_new_pseudos)
1940 return force_reg (Pmode, value);
1943 emit_move_insn (copy_rtx (dest), value);
1949 /* Return a LO_SUM expression for ADDR. TEMP is as for mips_force_temporary
1950 and is used to load the high part into a register. */
1953 mips_split_symbol (rtx temp, rtx addr)
1958 high = mips16_gp_pseudo_reg ();
1960 high = mips_force_temporary (temp, gen_rtx_HIGH (Pmode, copy_rtx (addr)));
1961 return gen_rtx_LO_SUM (Pmode, high, addr);
1965 /* Return an UNSPEC address with underlying address ADDRESS and symbol
1966 type SYMBOL_TYPE. */
1969 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
1972 HOST_WIDE_INT offset;
1974 mips_split_const (address, &base, &offset);
1975 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
1976 UNSPEC_ADDRESS_FIRST + symbol_type);
1977 return plus_constant (gen_rtx_CONST (Pmode, base), offset);
1981 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
1982 high part to BASE and return the result. Just return BASE otherwise.
1983 TEMP is available as a temporary register if needed.
1985 The returned expression can be used as the first operand to a LO_SUM. */
1988 mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
1989 enum mips_symbol_type symbol_type)
1991 if (mips_split_p[symbol_type])
1993 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
1994 addr = mips_force_temporary (temp, addr);
1995 return mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
2001 /* Return a legitimate address for REG + OFFSET. TEMP is as for
2002 mips_force_temporary; it is only needed when OFFSET is not a
2006 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
2008 if (!SMALL_OPERAND (offset))
2013 /* Load the full offset into a register so that we can use
2014 an unextended instruction for the address itself. */
2015 high = GEN_INT (offset);
2020 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH. */
2021 high = GEN_INT (CONST_HIGH_PART (offset));
2022 offset = CONST_LOW_PART (offset);
2024 high = mips_force_temporary (temp, high);
2025 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
2027 return plus_constant (reg, offset);
2030 /* Emit a call to __tls_get_addr. SYM is the TLS symbol we are
2031 referencing, and TYPE is the symbol type to use (either global
2032 dynamic or local dynamic). V0 is an RTX for the return value
2033 location. The entire insn sequence is returned. */
2035 static GTY(()) rtx mips_tls_symbol;
2038 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
2040 rtx insn, loc, tga, a0;
2042 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
2044 if (!mips_tls_symbol)
2045 mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
2047 loc = mips_unspec_address (sym, type);
2051 emit_insn (gen_rtx_SET (Pmode, a0,
2052 gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
2053 tga = gen_rtx_MEM (Pmode, mips_tls_symbol);
2054 insn = emit_call_insn (gen_call_value (v0, tga, const0_rtx, const0_rtx));
2055 CONST_OR_PURE_CALL_P (insn) = 1;
2056 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), v0);
2057 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
2058 insn = get_insns ();
2065 /* Generate the code to access LOC, a thread local SYMBOL_REF. The
2066 return value will be a valid address and move_operand (either a REG
2070 mips_legitimize_tls_address (rtx loc)
2072 rtx dest, insn, v0, v1, tmp1, tmp2, eqv;
2073 enum tls_model model;
2075 v0 = gen_rtx_REG (Pmode, GP_RETURN);
2076 v1 = gen_rtx_REG (Pmode, GP_RETURN + 1);
2078 model = SYMBOL_REF_TLS_MODEL (loc);
2079 /* Only TARGET_ABICALLS code can have more than one module; other
2080 code must be be static and should not use a GOT. All TLS models
2081 reduce to local exec in this situation. */
2082 if (!TARGET_ABICALLS)
2083 model = TLS_MODEL_LOCAL_EXEC;
2087 case TLS_MODEL_GLOBAL_DYNAMIC:
2088 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
2089 dest = gen_reg_rtx (Pmode);
2090 emit_libcall_block (insn, dest, v0, loc);
2093 case TLS_MODEL_LOCAL_DYNAMIC:
2094 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
2095 tmp1 = gen_reg_rtx (Pmode);
2097 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2098 share the LDM result with other LD model accesses. */
2099 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2101 emit_libcall_block (insn, tmp1, v0, eqv);
2103 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
2104 dest = gen_rtx_LO_SUM (Pmode, tmp2,
2105 mips_unspec_address (loc, SYMBOL_DTPREL));
2108 case TLS_MODEL_INITIAL_EXEC:
2109 tmp1 = gen_reg_rtx (Pmode);
2110 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
2111 if (Pmode == DImode)
2113 emit_insn (gen_tls_get_tp_di (v1));
2114 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
2118 emit_insn (gen_tls_get_tp_si (v1));
2119 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
2121 dest = gen_reg_rtx (Pmode);
2122 emit_insn (gen_add3_insn (dest, tmp1, v1));
2125 case TLS_MODEL_LOCAL_EXEC:
2126 if (Pmode == DImode)
2127 emit_insn (gen_tls_get_tp_di (v1));
2129 emit_insn (gen_tls_get_tp_si (v1));
2131 tmp1 = mips_unspec_offset_high (NULL, v1, loc, SYMBOL_TPREL);
2132 dest = gen_rtx_LO_SUM (Pmode, tmp1,
2133 mips_unspec_address (loc, SYMBOL_TPREL));
2143 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
2144 be legitimized in a way that the generic machinery might not expect,
2145 put the new address in *XLOC and return true. MODE is the mode of
2146 the memory being accessed. */
2149 mips_legitimize_address (rtx *xloc, enum machine_mode mode)
2151 enum mips_symbol_type symbol_type;
2153 if (mips_tls_operand_p (*xloc))
2155 *xloc = mips_legitimize_tls_address (*xloc);
2159 /* See if the address can split into a high part and a LO_SUM. */
2160 if (mips_symbolic_constant_p (*xloc, &symbol_type)
2161 && mips_symbolic_address_p (symbol_type, mode)
2162 && mips_split_p[symbol_type])
2164 *xloc = mips_split_symbol (0, *xloc);
2168 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
2170 /* Handle REG + CONSTANT using mips_add_offset. */
2173 reg = XEXP (*xloc, 0);
2174 if (!mips_valid_base_register_p (reg, mode, 0))
2175 reg = copy_to_mode_reg (Pmode, reg);
2176 *xloc = mips_add_offset (0, reg, INTVAL (XEXP (*xloc, 1)));
2184 /* Subroutine of mips_build_integer (with the same interface).
2185 Assume that the final action in the sequence should be a left shift. */
2188 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
2190 unsigned int i, shift;
2192 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
2193 since signed numbers are easier to load than unsigned ones. */
2195 while ((value & 1) == 0)
2196 value /= 2, shift++;
2198 i = mips_build_integer (codes, value);
2199 codes[i].code = ASHIFT;
2200 codes[i].value = shift;
2205 /* As for mips_build_shift, but assume that the final action will be
2206 an IOR or PLUS operation. */
2209 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
2211 unsigned HOST_WIDE_INT high;
2214 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
2215 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
2217 /* The constant is too complex to load with a simple lui/ori pair
2218 so our goal is to clear as many trailing zeros as possible.
2219 In this case, we know bit 16 is set and that the low 16 bits
2220 form a negative number. If we subtract that number from VALUE,
2221 we will clear at least the lowest 17 bits, maybe more. */
2222 i = mips_build_integer (codes, CONST_HIGH_PART (value));
2223 codes[i].code = PLUS;
2224 codes[i].value = CONST_LOW_PART (value);
2228 i = mips_build_integer (codes, high);
2229 codes[i].code = IOR;
2230 codes[i].value = value & 0xffff;
2236 /* Fill CODES with a sequence of rtl operations to load VALUE.
2237 Return the number of operations needed. */
2240 mips_build_integer (struct mips_integer_op *codes,
2241 unsigned HOST_WIDE_INT value)
2243 if (SMALL_OPERAND (value)
2244 || SMALL_OPERAND_UNSIGNED (value)
2245 || LUI_OPERAND (value))
2247 /* The value can be loaded with a single instruction. */
2248 codes[0].code = UNKNOWN;
2249 codes[0].value = value;
2252 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
2254 /* Either the constant is a simple LUI/ORI combination or its
2255 lowest bit is set. We don't want to shift in this case. */
2256 return mips_build_lower (codes, value);
2258 else if ((value & 0xffff) == 0)
2260 /* The constant will need at least three actions. The lowest
2261 16 bits are clear, so the final action will be a shift. */
2262 return mips_build_shift (codes, value);
2266 /* The final action could be a shift, add or inclusive OR.
2267 Rather than use a complex condition to select the best
2268 approach, try both mips_build_shift and mips_build_lower
2269 and pick the one that gives the shortest sequence.
2270 Note that this case is only used once per constant. */
2271 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
2272 unsigned int cost, alt_cost;
2274 cost = mips_build_shift (codes, value);
2275 alt_cost = mips_build_lower (alt_codes, value);
2276 if (alt_cost < cost)
2278 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
2286 /* Load VALUE into DEST, using TEMP as a temporary register if need be. */
2289 mips_move_integer (rtx dest, rtx temp, unsigned HOST_WIDE_INT value)
2291 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
2292 enum machine_mode mode;
2293 unsigned int i, cost;
2296 mode = GET_MODE (dest);
2297 cost = mips_build_integer (codes, value);
2299 /* Apply each binary operation to X. Invariant: X is a legitimate
2300 source operand for a SET pattern. */
2301 x = GEN_INT (codes[0].value);
2302 for (i = 1; i < cost; i++)
2306 emit_insn (gen_rtx_SET (VOIDmode, temp, x));
2310 x = force_reg (mode, x);
2311 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
2314 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
2318 /* Subroutine of mips_legitimize_move. Move constant SRC into register
2319 DEST given that SRC satisfies immediate_operand but doesn't satisfy
2323 mips_legitimize_const_move (enum machine_mode mode, rtx dest, rtx src)
2326 HOST_WIDE_INT offset;
2328 /* Split moves of big integers into smaller pieces. */
2329 if (splittable_const_int_operand (src, mode))
2331 mips_move_integer (dest, dest, INTVAL (src));
2335 /* Split moves of symbolic constants into high/low pairs. */
2336 if (splittable_symbolic_operand (src, mode))
2338 emit_insn (gen_rtx_SET (VOIDmode, dest, mips_split_symbol (dest, src)));
2342 if (mips_tls_operand_p (src))
2344 emit_move_insn (dest, mips_legitimize_tls_address (src));
2348 /* If we have (const (plus symbol offset)), load the symbol first
2349 and then add in the offset. This is usually better than forcing
2350 the constant into memory, at least in non-mips16 code. */
2351 mips_split_const (src, &base, &offset);
2354 && (!no_new_pseudos || SMALL_OPERAND (offset)))
2356 base = mips_force_temporary (dest, base);
2357 emit_move_insn (dest, mips_add_offset (0, base, offset));
2361 src = force_const_mem (mode, src);
2363 /* When using explicit relocs, constant pool references are sometimes
2364 not legitimate addresses. */
2365 if (!memory_operand (src, VOIDmode))
2366 src = replace_equiv_address (src, mips_split_symbol (dest, XEXP (src, 0)));
2367 emit_move_insn (dest, src);
2371 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
2372 sequence that is valid. */
2375 mips_legitimize_move (enum machine_mode mode, rtx dest, rtx src)
2377 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
2379 emit_move_insn (dest, force_reg (mode, src));
2383 /* Check for individual, fully-reloaded mflo and mfhi instructions. */
2384 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
2385 && REG_P (src) && MD_REG_P (REGNO (src))
2386 && REG_P (dest) && GP_REG_P (REGNO (dest)))
2388 int other_regno = REGNO (src) == HI_REGNUM ? LO_REGNUM : HI_REGNUM;
2389 if (GET_MODE_SIZE (mode) <= 4)
2390 emit_insn (gen_mfhilo_si (gen_rtx_REG (SImode, REGNO (dest)),
2391 gen_rtx_REG (SImode, REGNO (src)),
2392 gen_rtx_REG (SImode, other_regno)));
2394 emit_insn (gen_mfhilo_di (gen_rtx_REG (DImode, REGNO (dest)),
2395 gen_rtx_REG (DImode, REGNO (src)),
2396 gen_rtx_REG (DImode, other_regno)));
2400 /* We need to deal with constants that would be legitimate
2401 immediate_operands but not legitimate move_operands. */
2402 if (CONSTANT_P (src) && !move_operand (src, mode))
2404 mips_legitimize_const_move (mode, dest, src);
2405 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
2411 /* We need a lot of little routines to check constant values on the
2412 mips16. These are used to figure out how long the instruction will
2413 be. It would be much better to do this using constraints, but
2414 there aren't nearly enough letters available. */
2417 m16_check_op (rtx op, int low, int high, int mask)
2419 return (GET_CODE (op) == CONST_INT
2420 && INTVAL (op) >= low
2421 && INTVAL (op) <= high
2422 && (INTVAL (op) & mask) == 0);
2426 m16_uimm3_b (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2428 return m16_check_op (op, 0x1, 0x8, 0);
2432 m16_simm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2434 return m16_check_op (op, - 0x8, 0x7, 0);
2438 m16_nsimm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2440 return m16_check_op (op, - 0x7, 0x8, 0);
2444 m16_simm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2446 return m16_check_op (op, - 0x10, 0xf, 0);
2450 m16_nsimm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2452 return m16_check_op (op, - 0xf, 0x10, 0);
2456 m16_uimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2458 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2462 m16_nuimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2464 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2468 m16_simm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2470 return m16_check_op (op, - 0x80, 0x7f, 0);
2474 m16_nsimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2476 return m16_check_op (op, - 0x7f, 0x80, 0);
2480 m16_uimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2482 return m16_check_op (op, 0x0, 0xff, 0);
2486 m16_nuimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2488 return m16_check_op (op, - 0xff, 0x0, 0);
2492 m16_uimm8_m1_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2494 return m16_check_op (op, - 0x1, 0xfe, 0);
2498 m16_uimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2500 return m16_check_op (op, 0x0, 0xff << 2, 3);
2504 m16_nuimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2506 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2510 m16_simm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2512 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2516 m16_nsimm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2518 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2522 mips_rtx_costs (rtx x, int code, int outer_code, int *total)
2524 enum machine_mode mode = GET_MODE (x);
2525 bool float_mode_p = FLOAT_MODE_P (mode);
2532 /* A number between 1 and 8 inclusive is efficient for a shift.
2533 Otherwise, we will need an extended instruction. */
2534 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2535 || (outer_code) == LSHIFTRT)
2537 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2540 *total = COSTS_N_INSNS (1);
2544 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2545 if ((outer_code) == XOR
2546 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2552 /* We may be able to use slt or sltu for a comparison with a
2553 signed 16 bit value. (The boundary conditions aren't quite
2554 right, but this is just a heuristic anyhow.) */
2555 if (((outer_code) == LT || (outer_code) == LE
2556 || (outer_code) == GE || (outer_code) == GT
2557 || (outer_code) == LTU || (outer_code) == LEU
2558 || (outer_code) == GEU || (outer_code) == GTU)
2559 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2565 /* Equality comparisons with 0 are cheap. */
2566 if (((outer_code) == EQ || (outer_code) == NE)
2573 /* Constants in the range 0...255 can be loaded with an unextended
2574 instruction. They are therefore as cheap as a register move.
2576 Given the choice between "li R1,0...255" and "move R1,R2"
2577 (where R2 is a known constant), it is usually better to use "li",
2578 since we do not want to unnecessarily extend the lifetime
2580 if (outer_code == SET
2582 && INTVAL (x) < 256)
2590 /* These can be used anywhere. */
2595 /* Otherwise fall through to the handling below because
2596 we'll need to construct the constant. */
2602 if (LEGITIMATE_CONSTANT_P (x))
2604 *total = COSTS_N_INSNS (1);
2609 /* The value will need to be fetched from the constant pool. */
2610 *total = CONSTANT_POOL_COST;
2616 /* If the address is legitimate, return the number of
2617 instructions it needs, otherwise use the default handling. */
2618 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2621 *total = COSTS_N_INSNS (n + 1);
2628 *total = COSTS_N_INSNS (6);
2632 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2638 if (mode == DImode && !TARGET_64BIT)
2640 *total = COSTS_N_INSNS (2);
2648 if (mode == DImode && !TARGET_64BIT)
2650 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2658 *total = COSTS_N_INSNS (1);
2660 *total = COSTS_N_INSNS (4);
2664 *total = COSTS_N_INSNS (1);
2671 *total = mips_cost->fp_add;
2675 else if (mode == DImode && !TARGET_64BIT)
2677 *total = COSTS_N_INSNS (4);
2683 if (mode == DImode && !TARGET_64BIT)
2685 *total = COSTS_N_INSNS (4);
2692 *total = mips_cost->fp_mult_sf;
2694 else if (mode == DFmode)
2695 *total = mips_cost->fp_mult_df;
2697 else if (mode == SImode)
2698 *total = mips_cost->int_mult_si;
2701 *total = mips_cost->int_mult_di;
2710 *total = mips_cost->fp_div_sf;
2712 *total = mips_cost->fp_div_df;
2721 *total = mips_cost->int_div_di;
2723 *total = mips_cost->int_div_si;
2728 /* A sign extend from SImode to DImode in 64 bit mode is often
2729 zero instructions, because the result can often be used
2730 directly by another instruction; we'll call it one. */
2731 if (TARGET_64BIT && mode == DImode
2732 && GET_MODE (XEXP (x, 0)) == SImode)
2733 *total = COSTS_N_INSNS (1);
2735 *total = COSTS_N_INSNS (2);
2739 if (TARGET_64BIT && mode == DImode
2740 && GET_MODE (XEXP (x, 0)) == SImode)
2741 *total = COSTS_N_INSNS (2);
2743 *total = COSTS_N_INSNS (1);
2747 case UNSIGNED_FLOAT:
2750 case FLOAT_TRUNCATE:
2752 *total = mips_cost->fp_add;
2760 /* Provide the costs of an addressing mode that contains ADDR.
2761 If ADDR is not a valid address, its cost is irrelevant. */
2764 mips_address_cost (rtx addr)
2766 return mips_address_insns (addr, SImode);
2769 /* Return one word of double-word value OP, taking into account the fixed
2770 endianness of certain registers. HIGH_P is true to select the high part,
2771 false to select the low part. */
2774 mips_subword (rtx op, int high_p)
2777 enum machine_mode mode;
2779 mode = GET_MODE (op);
2780 if (mode == VOIDmode)
2783 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2784 byte = UNITS_PER_WORD;
2790 if (FP_REG_P (REGNO (op)))
2791 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2792 if (ACC_HI_REG_P (REGNO (op)))
2793 return gen_rtx_REG (word_mode, high_p ? REGNO (op) : REGNO (op) + 1);
2797 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
2799 return simplify_gen_subreg (word_mode, op, mode, byte);
2803 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2806 mips_split_64bit_move_p (rtx dest, rtx src)
2811 /* FP->FP moves can be done in a single instruction. */
2812 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2815 /* Check for floating-point loads and stores. They can be done using
2816 ldc1 and sdc1 on MIPS II and above. */
2819 if (FP_REG_RTX_P (dest) && MEM_P (src))
2821 if (FP_REG_RTX_P (src) && MEM_P (dest))
2828 /* Split a 64-bit move from SRC to DEST assuming that
2829 mips_split_64bit_move_p holds.
2831 Moves into and out of FPRs cause some difficulty here. Such moves
2832 will always be DFmode, since paired FPRs are not allowed to store
2833 DImode values. The most natural representation would be two separate
2834 32-bit moves, such as:
2836 (set (reg:SI $f0) (mem:SI ...))
2837 (set (reg:SI $f1) (mem:SI ...))
2839 However, the second insn is invalid because odd-numbered FPRs are
2840 not allowed to store independent values. Use the patterns load_df_low,
2841 load_df_high and store_df_high instead. */
2844 mips_split_64bit_move (rtx dest, rtx src)
2846 if (FP_REG_RTX_P (dest))
2848 /* Loading an FPR from memory or from GPRs. */
2849 emit_insn (gen_load_df_low (copy_rtx (dest), mips_subword (src, 0)));
2850 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2853 else if (FP_REG_RTX_P (src))
2855 /* Storing an FPR into memory or GPRs. */
2856 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2857 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2861 /* The operation can be split into two normal moves. Decide in
2862 which order to do them. */
2865 low_dest = mips_subword (dest, 0);
2866 if (REG_P (low_dest)
2867 && reg_overlap_mentioned_p (low_dest, src))
2869 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2870 emit_move_insn (low_dest, mips_subword (src, 0));
2874 emit_move_insn (low_dest, mips_subword (src, 0));
2875 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2880 /* Return the appropriate instructions to move SRC into DEST. Assume
2881 that SRC is operand 1 and DEST is operand 0. */
2884 mips_output_move (rtx dest, rtx src)
2886 enum rtx_code dest_code, src_code;
2889 dest_code = GET_CODE (dest);
2890 src_code = GET_CODE (src);
2891 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2893 if (dbl_p && mips_split_64bit_move_p (dest, src))
2896 if ((src_code == REG && GP_REG_P (REGNO (src)))
2897 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2899 if (dest_code == REG)
2901 if (GP_REG_P (REGNO (dest)))
2902 return "move\t%0,%z1";
2904 if (MD_REG_P (REGNO (dest)))
2907 if (DSP_ACC_REG_P (REGNO (dest)))
2909 static char retval[] = "mt__\t%z1,%q0";
2910 retval[2] = reg_names[REGNO (dest)][4];
2911 retval[3] = reg_names[REGNO (dest)][5];
2915 if (FP_REG_P (REGNO (dest)))
2916 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2918 if (ALL_COP_REG_P (REGNO (dest)))
2920 static char retval[] = "dmtc_\t%z1,%0";
2922 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2923 return (dbl_p ? retval : retval + 1);
2926 if (dest_code == MEM)
2927 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2929 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2931 if (src_code == REG)
2933 if (DSP_ACC_REG_P (REGNO (src)))
2935 static char retval[] = "mf__\t%0,%q1";
2936 retval[2] = reg_names[REGNO (src)][4];
2937 retval[3] = reg_names[REGNO (src)][5];
2941 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2942 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2944 if (FP_REG_P (REGNO (src)))
2945 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2947 if (ALL_COP_REG_P (REGNO (src)))
2949 static char retval[] = "dmfc_\t%0,%1";
2951 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2952 return (dbl_p ? retval : retval + 1);
2956 if (src_code == MEM)
2957 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
2959 if (src_code == CONST_INT)
2961 /* Don't use the X format, because that will give out of
2962 range numbers for 64 bit hosts and 32 bit targets. */
2964 return "li\t%0,%1\t\t\t# %X1";
2966 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
2969 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
2973 if (src_code == HIGH)
2974 return "lui\t%0,%h1";
2976 if (CONST_GP_P (src))
2977 return "move\t%0,%1";
2979 if (symbolic_operand (src, VOIDmode))
2980 return (dbl_p ? "dla\t%0,%1" : "la\t%0,%1");
2982 if (src_code == REG && FP_REG_P (REGNO (src)))
2984 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2986 if (GET_MODE (dest) == V2SFmode)
2987 return "mov.ps\t%0,%1";
2989 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2992 if (dest_code == MEM)
2993 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
2995 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2997 if (src_code == MEM)
2998 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
3000 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
3002 static char retval[] = "l_c_\t%0,%1";
3004 retval[1] = (dbl_p ? 'd' : 'w');
3005 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
3008 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
3010 static char retval[] = "s_c_\t%1,%0";
3012 retval[1] = (dbl_p ? 'd' : 'w');
3013 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
3019 /* Restore $gp from its save slot. Valid only when using o32 or
3023 mips_restore_gp (void)
3027 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI);
3029 address = mips_add_offset (pic_offset_table_rtx,
3030 frame_pointer_needed
3031 ? hard_frame_pointer_rtx
3032 : stack_pointer_rtx,
3033 current_function_outgoing_args_size);
3034 slot = gen_rtx_MEM (Pmode, address);
3036 emit_move_insn (pic_offset_table_rtx, slot);
3037 if (!TARGET_EXPLICIT_RELOCS)
3038 emit_insn (gen_blockage ());
3041 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
3044 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
3046 emit_insn (gen_rtx_SET (VOIDmode, target,
3047 gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
3050 /* Return true if CMP1 is a suitable second operand for relational
3051 operator CODE. See also the *sCC patterns in mips.md. */
3054 mips_relational_operand_ok_p (enum rtx_code code, rtx cmp1)
3060 return reg_or_0_operand (cmp1, VOIDmode);
3064 return !TARGET_MIPS16 && cmp1 == const1_rtx;
3068 return arith_operand (cmp1, VOIDmode);
3071 return sle_operand (cmp1, VOIDmode);
3074 return sleu_operand (cmp1, VOIDmode);
3081 /* Canonicalize LE or LEU comparisons into LT comparisons when
3082 possible to avoid extra instructions or inverting the
3086 mips_canonicalize_comparison (enum rtx_code *code, rtx *cmp1,
3087 enum machine_mode mode)
3089 HOST_WIDE_INT original, plus_one;
3091 if (GET_CODE (*cmp1) != CONST_INT)
3094 original = INTVAL (*cmp1);
3095 plus_one = trunc_int_for_mode ((unsigned HOST_WIDE_INT) original + 1, mode);
3100 if (original < plus_one)
3103 *cmp1 = force_reg (mode, GEN_INT (plus_one));
3112 *cmp1 = force_reg (mode, GEN_INT (plus_one));
3125 /* Compare CMP0 and CMP1 using relational operator CODE and store the
3126 result in TARGET. CMP0 and TARGET are register_operands that have
3127 the same integer mode. If INVERT_PTR is nonnull, it's OK to set
3128 TARGET to the inverse of the result and flip *INVERT_PTR instead. */
3131 mips_emit_int_relational (enum rtx_code code, bool *invert_ptr,
3132 rtx target, rtx cmp0, rtx cmp1)
3134 /* First see if there is a MIPS instruction that can do this operation
3135 with CMP1 in its current form. If not, try to canonicalize the
3136 comparison to LT. If that fails, try doing the same for the
3137 inverse operation. If that also fails, force CMP1 into a register
3139 if (mips_relational_operand_ok_p (code, cmp1))
3140 mips_emit_binary (code, target, cmp0, cmp1);
3141 else if (mips_canonicalize_comparison (&code, &cmp1, GET_MODE (target)))
3142 mips_emit_binary (code, target, cmp0, cmp1);
3145 enum rtx_code inv_code = reverse_condition (code);
3146 if (!mips_relational_operand_ok_p (inv_code, cmp1))
3148 cmp1 = force_reg (GET_MODE (cmp0), cmp1);
3149 mips_emit_int_relational (code, invert_ptr, target, cmp0, cmp1);
3151 else if (invert_ptr == 0)
3153 rtx inv_target = gen_reg_rtx (GET_MODE (target));
3154 mips_emit_binary (inv_code, inv_target, cmp0, cmp1);
3155 mips_emit_binary (XOR, target, inv_target, const1_rtx);
3159 *invert_ptr = !*invert_ptr;
3160 mips_emit_binary (inv_code, target, cmp0, cmp1);
3165 /* Return a register that is zero iff CMP0 and CMP1 are equal.
3166 The register will have the same mode as CMP0. */
3169 mips_zero_if_equal (rtx cmp0, rtx cmp1)
3171 if (cmp1 == const0_rtx)
3174 if (uns_arith_operand (cmp1, VOIDmode))
3175 return expand_binop (GET_MODE (cmp0), xor_optab,
3176 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
3178 return expand_binop (GET_MODE (cmp0), sub_optab,
3179 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
3182 /* Convert *CODE into a code that can be used in a floating-point
3183 scc instruction (c.<cond>.<fmt>). Return true if the values of
3184 the condition code registers will be inverted, with 0 indicating
3185 that the condition holds. */
3188 mips_reverse_fp_cond_p (enum rtx_code *code)
3195 *code = reverse_condition_maybe_unordered (*code);
3203 /* Convert a comparison into something that can be used in a branch or
3204 conditional move. cmp_operands[0] and cmp_operands[1] are the values
3205 being compared and *CODE is the code used to compare them.
3207 Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
3208 If NEED_EQ_NE_P, then only EQ/NE comparisons against zero are possible,
3209 otherwise any standard branch condition can be used. The standard branch
3212 - EQ/NE between two registers.
3213 - any comparison between a register and zero. */
3216 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
3218 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT)
3220 if (!need_eq_ne_p && cmp_operands[1] == const0_rtx)
3222 *op0 = cmp_operands[0];
3223 *op1 = cmp_operands[1];
3225 else if (*code == EQ || *code == NE)
3229 *op0 = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
3234 *op0 = cmp_operands[0];
3235 *op1 = force_reg (GET_MODE (*op0), cmp_operands[1]);
3240 /* The comparison needs a separate scc instruction. Store the
3241 result of the scc in *OP0 and compare it against zero. */
3242 bool invert = false;
3243 *op0 = gen_reg_rtx (GET_MODE (cmp_operands[0]));
3245 mips_emit_int_relational (*code, &invert, *op0,
3246 cmp_operands[0], cmp_operands[1]);
3247 *code = (invert ? EQ : NE);
3252 enum rtx_code cmp_code;
3254 /* Floating-point tests use a separate c.cond.fmt comparison to
3255 set a condition code register. The branch or conditional move
3256 will then compare that register against zero.
3258 Set CMP_CODE to the code of the comparison instruction and
3259 *CODE to the code that the branch or move should use. */
3261 *code = mips_reverse_fp_cond_p (&cmp_code) ? EQ : NE;
3263 ? gen_reg_rtx (CCmode)
3264 : gen_rtx_REG (CCmode, FPSW_REGNUM));
3266 mips_emit_binary (cmp_code, *op0, cmp_operands[0], cmp_operands[1]);
3270 /* Try comparing cmp_operands[0] and cmp_operands[1] using rtl code CODE.
3271 Store the result in TARGET and return true if successful.
3273 On 64-bit targets, TARGET may be wider than cmp_operands[0]. */
3276 mips_emit_scc (enum rtx_code code, rtx target)
3278 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) != MODE_INT)
3281 target = gen_lowpart (GET_MODE (cmp_operands[0]), target);
3282 if (code == EQ || code == NE)
3284 rtx zie = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
3285 mips_emit_binary (code, target, zie, const0_rtx);
3288 mips_emit_int_relational (code, 0, target,
3289 cmp_operands[0], cmp_operands[1]);
3293 /* Emit the common code for doing conditional branches.
3294 operand[0] is the label to jump to.
3295 The comparison operands are saved away by cmp{si,di,sf,df}. */
3298 gen_conditional_branch (rtx *operands, enum rtx_code code)
3300 rtx op0, op1, condition;
3302 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
3303 condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3304 emit_jump_insn (gen_condjump (condition, operands[0]));
3309 (set temp (COND:CCV2 CMP_OP0 CMP_OP1))
3310 (set DEST (unspec [TRUE_SRC FALSE_SRC temp] UNSPEC_MOVE_TF_PS)) */
3313 mips_expand_vcondv2sf (rtx dest, rtx true_src, rtx false_src,
3314 enum rtx_code cond, rtx cmp_op0, rtx cmp_op1)
3319 reversed_p = mips_reverse_fp_cond_p (&cond);
3320 cmp_result = gen_reg_rtx (CCV2mode);
3321 emit_insn (gen_scc_ps (cmp_result,
3322 gen_rtx_fmt_ee (cond, VOIDmode, cmp_op0, cmp_op1)));
3324 emit_insn (gen_mips_cond_move_tf_ps (dest, false_src, true_src,
3327 emit_insn (gen_mips_cond_move_tf_ps (dest, true_src, false_src,
3331 /* Emit the common code for conditional moves. OPERANDS is the array
3332 of operands passed to the conditional move define_expand. */
3335 gen_conditional_move (rtx *operands)
3340 code = GET_CODE (operands[1]);
3341 mips_emit_compare (&code, &op0, &op1, true);
3342 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3343 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
3344 gen_rtx_fmt_ee (code,
3347 operands[2], operands[3])));
3350 /* Emit a conditional trap. OPERANDS is the array of operands passed to
3351 the conditional_trap expander. */
3354 mips_gen_conditional_trap (rtx *operands)
3357 enum rtx_code cmp_code = GET_CODE (operands[0]);
3358 enum machine_mode mode = GET_MODE (cmp_operands[0]);
3360 /* MIPS conditional trap machine instructions don't have GT or LE
3361 flavors, so we must invert the comparison and convert to LT and
3362 GE, respectively. */
3365 case GT: cmp_code = LT; break;
3366 case LE: cmp_code = GE; break;
3367 case GTU: cmp_code = LTU; break;
3368 case LEU: cmp_code = GEU; break;
3371 if (cmp_code == GET_CODE (operands[0]))
3373 op0 = cmp_operands[0];
3374 op1 = cmp_operands[1];
3378 op0 = cmp_operands[1];
3379 op1 = cmp_operands[0];
3381 op0 = force_reg (mode, op0);
3382 if (!arith_operand (op1, mode))
3383 op1 = force_reg (mode, op1);
3385 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
3386 gen_rtx_fmt_ee (cmp_code, mode, op0, op1),
3390 /* Load function address ADDR into register DEST. SIBCALL_P is true
3391 if the address is needed for a sibling call. */
3394 mips_load_call_address (rtx dest, rtx addr, int sibcall_p)
3396 /* If we're generating PIC, and this call is to a global function,
3397 try to allow its address to be resolved lazily. This isn't
3398 possible for NewABI sibcalls since the value of $gp on entry
3399 to the stub would be our caller's gp, not ours. */
3400 if (TARGET_EXPLICIT_RELOCS
3401 && !(sibcall_p && TARGET_NEWABI)
3402 && global_got_operand (addr, VOIDmode))
3404 rtx high, lo_sum_symbol;
3406 high = mips_unspec_offset_high (dest, pic_offset_table_rtx,
3407 addr, SYMBOL_GOTOFF_CALL);
3408 lo_sum_symbol = mips_unspec_address (addr, SYMBOL_GOTOFF_CALL);
3409 if (Pmode == SImode)
3410 emit_insn (gen_load_callsi (dest, high, lo_sum_symbol));
3412 emit_insn (gen_load_calldi (dest, high, lo_sum_symbol));
3415 emit_move_insn (dest, addr);
3419 /* Expand a call or call_value instruction. RESULT is where the
3420 result will go (null for calls), ADDR is the address of the
3421 function, ARGS_SIZE is the size of the arguments and AUX is
3422 the value passed to us by mips_function_arg. SIBCALL_P is true
3423 if we are expanding a sibling call, false if we're expanding
3427 mips_expand_call (rtx result, rtx addr, rtx args_size, rtx aux, int sibcall_p)
3429 rtx orig_addr, pattern, insn;
3432 if (!call_insn_operand (addr, VOIDmode))
3434 addr = gen_reg_rtx (Pmode);
3435 mips_load_call_address (addr, orig_addr, sibcall_p);
3439 && mips16_hard_float
3440 && build_mips16_call_stub (result, addr, args_size,
3441 aux == 0 ? 0 : (int) GET_MODE (aux)))
3445 pattern = (sibcall_p
3446 ? gen_sibcall_internal (addr, args_size)
3447 : gen_call_internal (addr, args_size));
3448 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
3452 reg1 = XEXP (XVECEXP (result, 0, 0), 0);
3453 reg2 = XEXP (XVECEXP (result, 0, 1), 0);
3456 ? gen_sibcall_value_multiple_internal (reg1, addr, args_size, reg2)
3457 : gen_call_value_multiple_internal (reg1, addr, args_size, reg2));
3460 pattern = (sibcall_p
3461 ? gen_sibcall_value_internal (result, addr, args_size)
3462 : gen_call_value_internal (result, addr, args_size));