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_data[PROCESSOR_MAX] =
802 COSTS_N_INSNS (2), /* fp_add */
803 COSTS_N_INSNS (4), /* fp_mult_sf */
804 COSTS_N_INSNS (5), /* fp_mult_df */
805 COSTS_N_INSNS (12), /* fp_div_sf */
806 COSTS_N_INSNS (19), /* fp_div_df */
807 COSTS_N_INSNS (12), /* int_mult_si */
808 COSTS_N_INSNS (12), /* int_mult_di */
809 COSTS_N_INSNS (35), /* int_div_si */
810 COSTS_N_INSNS (35), /* int_div_di */
812 4 /* memory_latency */
817 COSTS_N_INSNS (6), /* int_mult_si */
818 COSTS_N_INSNS (6), /* int_mult_di */
819 COSTS_N_INSNS (36), /* int_div_si */
820 COSTS_N_INSNS (36), /* int_div_di */
822 4 /* memory_latency */
826 COSTS_N_INSNS (36), /* int_mult_si */
827 COSTS_N_INSNS (36), /* int_mult_di */
828 COSTS_N_INSNS (37), /* int_div_si */
829 COSTS_N_INSNS (37), /* int_div_di */
831 4 /* memory_latency */
835 COSTS_N_INSNS (4), /* int_mult_si */
836 COSTS_N_INSNS (11), /* int_mult_di */
837 COSTS_N_INSNS (36), /* int_div_si */
838 COSTS_N_INSNS (68), /* int_div_di */
840 4 /* memory_latency */
843 COSTS_N_INSNS (4), /* fp_add */
844 COSTS_N_INSNS (4), /* fp_mult_sf */
845 COSTS_N_INSNS (5), /* fp_mult_df */
846 COSTS_N_INSNS (17), /* fp_div_sf */
847 COSTS_N_INSNS (32), /* fp_div_df */
848 COSTS_N_INSNS (4), /* int_mult_si */
849 COSTS_N_INSNS (11), /* int_mult_di */
850 COSTS_N_INSNS (36), /* int_div_si */
851 COSTS_N_INSNS (68), /* int_div_di */
853 4 /* memory_latency */
860 COSTS_N_INSNS (5), /* int_mult_si */
861 COSTS_N_INSNS (5), /* int_mult_di */
862 COSTS_N_INSNS (41), /* int_div_si */
863 COSTS_N_INSNS (41), /* int_div_di */
865 4 /* memory_latency */
868 COSTS_N_INSNS (8), /* fp_add */
869 COSTS_N_INSNS (8), /* fp_mult_sf */
870 COSTS_N_INSNS (10), /* fp_mult_df */
871 COSTS_N_INSNS (34), /* fp_div_sf */
872 COSTS_N_INSNS (64), /* fp_div_df */
873 COSTS_N_INSNS (5), /* int_mult_si */
874 COSTS_N_INSNS (5), /* int_mult_di */
875 COSTS_N_INSNS (41), /* int_div_si */
876 COSTS_N_INSNS (41), /* int_div_di */
878 4 /* memory_latency */
881 COSTS_N_INSNS (4), /* fp_add */
882 COSTS_N_INSNS (4), /* fp_mult_sf */
883 COSTS_N_INSNS (5), /* fp_mult_df */
884 COSTS_N_INSNS (17), /* fp_div_sf */
885 COSTS_N_INSNS (32), /* fp_div_df */
886 COSTS_N_INSNS (5), /* int_mult_si */
887 COSTS_N_INSNS (5), /* int_mult_di */
888 COSTS_N_INSNS (41), /* int_div_si */
889 COSTS_N_INSNS (41), /* int_div_di */
891 4 /* memory_latency */
897 COSTS_N_INSNS (2), /* fp_add */
898 COSTS_N_INSNS (4), /* fp_mult_sf */
899 COSTS_N_INSNS (5), /* fp_mult_df */
900 COSTS_N_INSNS (12), /* fp_div_sf */
901 COSTS_N_INSNS (19), /* fp_div_df */
902 COSTS_N_INSNS (2), /* int_mult_si */
903 COSTS_N_INSNS (2), /* int_mult_di */
904 COSTS_N_INSNS (35), /* int_div_si */
905 COSTS_N_INSNS (35), /* int_div_di */
907 4 /* memory_latency */
910 COSTS_N_INSNS (3), /* fp_add */
911 COSTS_N_INSNS (5), /* fp_mult_sf */
912 COSTS_N_INSNS (6), /* fp_mult_df */
913 COSTS_N_INSNS (15), /* fp_div_sf */
914 COSTS_N_INSNS (16), /* fp_div_df */
915 COSTS_N_INSNS (17), /* int_mult_si */
916 COSTS_N_INSNS (17), /* int_mult_di */
917 COSTS_N_INSNS (38), /* int_div_si */
918 COSTS_N_INSNS (38), /* int_div_di */
920 6 /* memory_latency */
923 COSTS_N_INSNS (6), /* fp_add */
924 COSTS_N_INSNS (7), /* fp_mult_sf */
925 COSTS_N_INSNS (8), /* fp_mult_df */
926 COSTS_N_INSNS (23), /* fp_div_sf */
927 COSTS_N_INSNS (36), /* fp_div_df */
928 COSTS_N_INSNS (10), /* int_mult_si */
929 COSTS_N_INSNS (10), /* int_mult_di */
930 COSTS_N_INSNS (69), /* int_div_si */
931 COSTS_N_INSNS (69), /* int_div_di */
933 6 /* memory_latency */
945 /* The only costs that appear to be updated here are
946 integer multiplication. */
948 COSTS_N_INSNS (4), /* int_mult_si */
949 COSTS_N_INSNS (6), /* int_mult_di */
950 COSTS_N_INSNS (69), /* int_div_si */
951 COSTS_N_INSNS (69), /* int_div_di */
953 4 /* memory_latency */
965 COSTS_N_INSNS (6), /* fp_add */
966 COSTS_N_INSNS (4), /* fp_mult_sf */
967 COSTS_N_INSNS (5), /* fp_mult_df */
968 COSTS_N_INSNS (23), /* fp_div_sf */
969 COSTS_N_INSNS (36), /* fp_div_df */
970 COSTS_N_INSNS (5), /* int_mult_si */
971 COSTS_N_INSNS (5), /* int_mult_di */
972 COSTS_N_INSNS (36), /* int_div_si */
973 COSTS_N_INSNS (36), /* int_div_di */
975 4 /* memory_latency */
978 COSTS_N_INSNS (6), /* fp_add */
979 COSTS_N_INSNS (5), /* fp_mult_sf */
980 COSTS_N_INSNS (6), /* fp_mult_df */
981 COSTS_N_INSNS (30), /* fp_div_sf */
982 COSTS_N_INSNS (59), /* fp_div_df */
983 COSTS_N_INSNS (3), /* int_mult_si */
984 COSTS_N_INSNS (4), /* int_mult_di */
985 COSTS_N_INSNS (42), /* int_div_si */
986 COSTS_N_INSNS (74), /* int_div_di */
988 4 /* memory_latency */
991 COSTS_N_INSNS (6), /* fp_add */
992 COSTS_N_INSNS (5), /* fp_mult_sf */
993 COSTS_N_INSNS (6), /* fp_mult_df */
994 COSTS_N_INSNS (30), /* fp_div_sf */
995 COSTS_N_INSNS (59), /* fp_div_df */
996 COSTS_N_INSNS (5), /* int_mult_si */
997 COSTS_N_INSNS (9), /* int_mult_di */
998 COSTS_N_INSNS (42), /* int_div_si */
999 COSTS_N_INSNS (74), /* int_div_di */
1000 1, /* branch_cost */
1001 4 /* memory_latency */
1004 /* The only costs that are changed here are
1005 integer multiplication. */
1006 COSTS_N_INSNS (6), /* fp_add */
1007 COSTS_N_INSNS (7), /* fp_mult_sf */
1008 COSTS_N_INSNS (8), /* fp_mult_df */
1009 COSTS_N_INSNS (23), /* fp_div_sf */
1010 COSTS_N_INSNS (36), /* fp_div_df */
1011 COSTS_N_INSNS (5), /* int_mult_si */
1012 COSTS_N_INSNS (9), /* int_mult_di */
1013 COSTS_N_INSNS (69), /* int_div_si */
1014 COSTS_N_INSNS (69), /* int_div_di */
1015 1, /* branch_cost */
1016 4 /* memory_latency */
1022 /* The only costs that are changed here are
1023 integer multiplication. */
1024 COSTS_N_INSNS (6), /* fp_add */
1025 COSTS_N_INSNS (7), /* fp_mult_sf */
1026 COSTS_N_INSNS (8), /* fp_mult_df */
1027 COSTS_N_INSNS (23), /* fp_div_sf */
1028 COSTS_N_INSNS (36), /* fp_div_df */
1029 COSTS_N_INSNS (3), /* int_mult_si */
1030 COSTS_N_INSNS (8), /* int_mult_di */
1031 COSTS_N_INSNS (69), /* int_div_si */
1032 COSTS_N_INSNS (69), /* int_div_di */
1033 1, /* branch_cost */
1034 4 /* memory_latency */
1037 /* These costs are the same as the SB-1A below. */
1038 COSTS_N_INSNS (4), /* fp_add */
1039 COSTS_N_INSNS (4), /* fp_mult_sf */
1040 COSTS_N_INSNS (4), /* fp_mult_df */
1041 COSTS_N_INSNS (24), /* fp_div_sf */
1042 COSTS_N_INSNS (32), /* fp_div_df */
1043 COSTS_N_INSNS (3), /* int_mult_si */
1044 COSTS_N_INSNS (4), /* int_mult_di */
1045 COSTS_N_INSNS (36), /* int_div_si */
1046 COSTS_N_INSNS (68), /* int_div_di */
1047 1, /* branch_cost */
1048 4 /* memory_latency */
1051 /* These costs are the same as the SB-1 above. */
1052 COSTS_N_INSNS (4), /* fp_add */
1053 COSTS_N_INSNS (4), /* fp_mult_sf */
1054 COSTS_N_INSNS (4), /* fp_mult_df */
1055 COSTS_N_INSNS (24), /* fp_div_sf */
1056 COSTS_N_INSNS (32), /* fp_div_df */
1057 COSTS_N_INSNS (3), /* int_mult_si */
1058 COSTS_N_INSNS (4), /* int_mult_di */
1059 COSTS_N_INSNS (36), /* int_div_si */
1060 COSTS_N_INSNS (68), /* int_div_di */
1061 1, /* branch_cost */
1062 4 /* memory_latency */
1070 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
1071 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
1072 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
1075 /* Initialize the GCC target structure. */
1076 #undef TARGET_ASM_ALIGNED_HI_OP
1077 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
1078 #undef TARGET_ASM_ALIGNED_SI_OP
1079 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
1080 #undef TARGET_ASM_ALIGNED_DI_OP
1081 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
1083 #undef TARGET_ASM_FUNCTION_PROLOGUE
1084 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
1085 #undef TARGET_ASM_FUNCTION_EPILOGUE
1086 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
1087 #undef TARGET_ASM_SELECT_RTX_SECTION
1088 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
1089 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
1090 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
1092 #undef TARGET_SCHED_REORDER
1093 #define TARGET_SCHED_REORDER mips_sched_reorder
1094 #undef TARGET_SCHED_VARIABLE_ISSUE
1095 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
1096 #undef TARGET_SCHED_ADJUST_COST
1097 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
1098 #undef TARGET_SCHED_ISSUE_RATE
1099 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
1100 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
1101 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
1102 mips_multipass_dfa_lookahead
1104 #undef TARGET_DEFAULT_TARGET_FLAGS
1105 #define TARGET_DEFAULT_TARGET_FLAGS \
1107 | TARGET_CPU_DEFAULT \
1108 | TARGET_ENDIAN_DEFAULT \
1109 | TARGET_FP_EXCEPTIONS_DEFAULT \
1110 | MASK_CHECK_ZERO_DIV \
1112 #undef TARGET_HANDLE_OPTION
1113 #define TARGET_HANDLE_OPTION mips_handle_option
1115 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
1116 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
1118 #undef TARGET_VALID_POINTER_MODE
1119 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
1120 #undef TARGET_RTX_COSTS
1121 #define TARGET_RTX_COSTS mips_rtx_costs
1122 #undef TARGET_ADDRESS_COST
1123 #define TARGET_ADDRESS_COST mips_address_cost
1125 #undef TARGET_IN_SMALL_DATA_P
1126 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
1128 #undef TARGET_MACHINE_DEPENDENT_REORG
1129 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
1131 #undef TARGET_ASM_FILE_START
1132 #undef TARGET_ASM_FILE_END
1133 #define TARGET_ASM_FILE_START mips_file_start
1134 #define TARGET_ASM_FILE_END mips_file_end
1135 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
1136 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
1138 #undef TARGET_INIT_LIBFUNCS
1139 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
1141 #undef TARGET_BUILD_BUILTIN_VA_LIST
1142 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
1143 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
1144 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
1146 #undef TARGET_PROMOTE_FUNCTION_ARGS
1147 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
1148 #undef TARGET_PROMOTE_FUNCTION_RETURN
1149 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
1150 #undef TARGET_PROMOTE_PROTOTYPES
1151 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
1153 #undef TARGET_RETURN_IN_MEMORY
1154 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
1155 #undef TARGET_RETURN_IN_MSB
1156 #define TARGET_RETURN_IN_MSB mips_return_in_msb
1158 #undef TARGET_ASM_OUTPUT_MI_THUNK
1159 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
1160 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
1161 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
1163 #undef TARGET_SETUP_INCOMING_VARARGS
1164 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
1165 #undef TARGET_STRICT_ARGUMENT_NAMING
1166 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
1167 #undef TARGET_MUST_PASS_IN_STACK
1168 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
1169 #undef TARGET_PASS_BY_REFERENCE
1170 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
1171 #undef TARGET_CALLEE_COPIES
1172 #define TARGET_CALLEE_COPIES mips_callee_copies
1173 #undef TARGET_ARG_PARTIAL_BYTES
1174 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
1176 #undef TARGET_MODE_REP_EXTENDED
1177 #define TARGET_MODE_REP_EXTENDED mips_mode_rep_extended
1179 #undef TARGET_VECTOR_MODE_SUPPORTED_P
1180 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
1182 #undef TARGET_INIT_BUILTINS
1183 #define TARGET_INIT_BUILTINS mips_init_builtins
1184 #undef TARGET_EXPAND_BUILTIN
1185 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
1187 #undef TARGET_HAVE_TLS
1188 #define TARGET_HAVE_TLS HAVE_AS_TLS
1190 #undef TARGET_CANNOT_FORCE_CONST_MEM
1191 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
1193 #undef TARGET_ENCODE_SECTION_INFO
1194 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
1196 #undef TARGET_ATTRIBUTE_TABLE
1197 #define TARGET_ATTRIBUTE_TABLE mips_attribute_table
1199 #undef TARGET_EXTRA_LIVE_ON_ENTRY
1200 #define TARGET_EXTRA_LIVE_ON_ENTRY mips_extra_live_on_entry
1202 #undef TARGET_MIN_ANCHOR_OFFSET
1203 #define TARGET_MIN_ANCHOR_OFFSET -32768
1204 #undef TARGET_MAX_ANCHOR_OFFSET
1205 #define TARGET_MAX_ANCHOR_OFFSET 32767
1206 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
1207 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P mips_use_blocks_for_constant_p
1208 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
1209 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P mips_use_anchors_for_symbol_p
1211 struct gcc_target targetm = TARGET_INITIALIZER;
1213 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
1215 static enum mips_symbol_type
1216 mips_classify_symbol (rtx x)
1220 if (GET_CODE (x) == LABEL_REF)
1223 return SYMBOL_CONSTANT_POOL;
1224 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
1225 return SYMBOL_GOT_LOCAL;
1226 return SYMBOL_GENERAL;
1229 gcc_assert (GET_CODE (x) == SYMBOL_REF);
1231 if (SYMBOL_REF_TLS_MODEL (x))
1234 if (CONSTANT_POOL_ADDRESS_P (x))
1237 return SYMBOL_CONSTANT_POOL;
1239 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
1240 return SYMBOL_SMALL_DATA;
1243 /* Do not use small-data accesses for weak symbols; they may end up
1245 if (SYMBOL_REF_SMALL_P (x)
1246 && !SYMBOL_REF_WEAK (x))
1247 return SYMBOL_SMALL_DATA;
1249 if (TARGET_ABICALLS)
1251 decl = SYMBOL_REF_DECL (x);
1254 if (!SYMBOL_REF_LOCAL_P (x))
1255 return SYMBOL_GOT_GLOBAL;
1259 /* Don't use GOT accesses for locally-binding symbols if
1260 TARGET_ABSOLUTE_ABICALLS. Otherwise, there are three
1263 - o32 PIC (either with or without explicit relocs)
1264 - n32/n64 PIC without explicit relocs
1265 - n32/n64 PIC with explicit relocs
1267 In the first case, both local and global accesses will use an
1268 R_MIPS_GOT16 relocation. We must correctly predict which of
1269 the two semantics (local or global) the assembler and linker
1270 will apply. The choice doesn't depend on the symbol's
1271 visibility, so we deliberately ignore decl_visibility and
1274 In the second case, the assembler will not use R_MIPS_GOT16
1275 relocations, but it chooses between local and global accesses
1276 in the same way as for o32 PIC.
1278 In the third case we have more freedom since both forms of
1279 access will work for any kind of symbol. However, there seems
1280 little point in doing things differently.
1282 Note that weakref symbols are not TREE_PUBLIC, but their
1283 targets are global or weak symbols. Relocations in the
1284 object file will be against the target symbol, so it's
1285 that symbol's binding that matters here. */
1287 && (TREE_PUBLIC (decl) || DECL_WEAK (decl))
1288 && !(TARGET_ABSOLUTE_ABICALLS && targetm.binds_local_p (decl)))
1289 return SYMBOL_GOT_GLOBAL;
1292 if (!TARGET_ABSOLUTE_ABICALLS)
1293 return SYMBOL_GOT_LOCAL;
1296 return SYMBOL_GENERAL;
1300 /* Split X into a base and a constant offset, storing them in *BASE
1301 and *OFFSET respectively. */
1304 mips_split_const (rtx x, rtx *base, HOST_WIDE_INT *offset)
1308 if (GET_CODE (x) == CONST)
1311 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
1313 *offset += INTVAL (XEXP (x, 1));
1321 /* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
1322 to the same object as SYMBOL, or to the same object_block. */
1325 mips_offset_within_object_p (rtx symbol, HOST_WIDE_INT offset)
1327 if (GET_CODE (symbol) != SYMBOL_REF)
1330 if (CONSTANT_POOL_ADDRESS_P (symbol)
1332 && offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
1335 if (SYMBOL_REF_DECL (symbol) != 0
1337 && offset < int_size_in_bytes (TREE_TYPE (SYMBOL_REF_DECL (symbol))))
1340 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol)
1341 && SYMBOL_REF_BLOCK (symbol)
1342 && SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0
1343 && ((unsigned HOST_WIDE_INT) offset + SYMBOL_REF_BLOCK_OFFSET (symbol)
1344 < (unsigned HOST_WIDE_INT) SYMBOL_REF_BLOCK (symbol)->size))
1351 /* Return true if X is a symbolic constant that can be calculated in
1352 the same way as a bare symbol. If it is, store the type of the
1353 symbol in *SYMBOL_TYPE. */
1356 mips_symbolic_constant_p (rtx x, enum mips_symbol_type *symbol_type)
1358 HOST_WIDE_INT offset;
1360 mips_split_const (x, &x, &offset);
1361 if (UNSPEC_ADDRESS_P (x))
1362 *symbol_type = UNSPEC_ADDRESS_TYPE (x);
1363 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1365 *symbol_type = mips_classify_symbol (x);
1366 if (*symbol_type == SYMBOL_TLS)
1375 /* Check whether a nonzero offset is valid for the underlying
1377 switch (*symbol_type)
1379 case SYMBOL_GENERAL:
1380 case SYMBOL_64_HIGH:
1383 /* If the target has 64-bit pointers and the object file only
1384 supports 32-bit symbols, the values of those symbols will be
1385 sign-extended. In this case we can't allow an arbitrary offset
1386 in case the 32-bit value X + OFFSET has a different sign from X. */
1387 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
1388 return mips_offset_within_object_p (x, offset);
1390 /* In other cases the relocations can handle any offset. */
1393 case SYMBOL_CONSTANT_POOL:
1394 /* Allow constant pool references to be converted to LABEL+CONSTANT.
1395 In this case, we no longer have access to the underlying constant,
1396 but the original symbol-based access was known to be valid. */
1397 if (GET_CODE (x) == LABEL_REF)
1402 case SYMBOL_SMALL_DATA:
1403 /* Make sure that the offset refers to something within the
1404 underlying object. This should guarantee that the final
1405 PC- or GP-relative offset is within the 16-bit limit. */
1406 return mips_offset_within_object_p (x, offset);
1408 case SYMBOL_GOT_LOCAL:
1409 case SYMBOL_GOTOFF_PAGE:
1410 /* The linker should provide enough local GOT entries for a
1411 16-bit offset. Larger offsets may lead to GOT overflow. */
1412 return SMALL_OPERAND (offset);
1414 case SYMBOL_GOT_GLOBAL:
1415 case SYMBOL_GOTOFF_GLOBAL:
1416 case SYMBOL_GOTOFF_CALL:
1417 case SYMBOL_GOTOFF_LOADGP:
1422 case SYMBOL_GOTTPREL:
1430 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1433 mips_regno_mode_ok_for_base_p (int regno, enum machine_mode mode, int strict)
1435 if (regno >= FIRST_PSEUDO_REGISTER)
1439 regno = reg_renumber[regno];
1442 /* These fake registers will be eliminated to either the stack or
1443 hard frame pointer, both of which are usually valid base registers.
1444 Reload deals with the cases where the eliminated form isn't valid. */
1445 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
1448 /* In mips16 mode, the stack pointer can only address word and doubleword
1449 values, nothing smaller. There are two problems here:
1451 (a) Instantiating virtual registers can introduce new uses of the
1452 stack pointer. If these virtual registers are valid addresses,
1453 the stack pointer should be too.
1455 (b) Most uses of the stack pointer are not made explicit until
1456 FRAME_POINTER_REGNUM and ARG_POINTER_REGNUM have been eliminated.
1457 We don't know until that stage whether we'll be eliminating to the
1458 stack pointer (which needs the restriction) or the hard frame
1459 pointer (which doesn't).
1461 All in all, it seems more consistent to only enforce this restriction
1462 during and after reload. */
1463 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
1464 return !strict || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1466 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
1470 /* Return true if X is a valid base register for the given mode.
1471 Allow only hard registers if STRICT. */
1474 mips_valid_base_register_p (rtx x, enum machine_mode mode, int strict)
1476 if (!strict && GET_CODE (x) == SUBREG)
1480 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict));
1484 /* Return true if symbols of type SYMBOL_TYPE can directly address a value
1485 with mode MODE. This is used for both symbolic and LO_SUM addresses. */
1488 mips_symbolic_address_p (enum mips_symbol_type symbol_type,
1489 enum machine_mode mode)
1491 switch (symbol_type)
1493 case SYMBOL_GENERAL:
1494 return !TARGET_MIPS16;
1496 case SYMBOL_SMALL_DATA:
1499 case SYMBOL_CONSTANT_POOL:
1500 /* PC-relative addressing is only available for lw and ld. */
1501 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1503 case SYMBOL_GOT_LOCAL:
1506 case SYMBOL_GOT_GLOBAL:
1507 /* The address will have to be loaded from the GOT first. */
1510 case SYMBOL_GOTOFF_PAGE:
1511 case SYMBOL_GOTOFF_GLOBAL:
1512 case SYMBOL_GOTOFF_CALL:
1513 case SYMBOL_GOTOFF_LOADGP:
1518 case SYMBOL_GOTTPREL:
1520 case SYMBOL_64_HIGH:
1529 /* Return true if X is a valid address for machine mode MODE. If it is,
1530 fill in INFO appropriately. STRICT is true if we should only accept
1531 hard base registers. */
1534 mips_classify_address (struct mips_address_info *info, rtx x,
1535 enum machine_mode mode, int strict)
1537 switch (GET_CODE (x))
1541 info->type = ADDRESS_REG;
1543 info->offset = const0_rtx;
1544 return mips_valid_base_register_p (info->reg, mode, strict);
1547 info->type = ADDRESS_REG;
1548 info->reg = XEXP (x, 0);
1549 info->offset = XEXP (x, 1);
1550 return (mips_valid_base_register_p (info->reg, mode, strict)
1551 && const_arith_operand (info->offset, VOIDmode));
1554 info->type = ADDRESS_LO_SUM;
1555 info->reg = XEXP (x, 0);
1556 info->offset = XEXP (x, 1);
1557 return (mips_valid_base_register_p (info->reg, mode, strict)
1558 && mips_symbolic_constant_p (info->offset, &info->symbol_type)
1559 && mips_symbolic_address_p (info->symbol_type, mode)
1560 && mips_lo_relocs[info->symbol_type] != 0);
1563 /* Small-integer addresses don't occur very often, but they
1564 are legitimate if $0 is a valid base register. */
1565 info->type = ADDRESS_CONST_INT;
1566 return !TARGET_MIPS16 && SMALL_INT (x);
1571 info->type = ADDRESS_SYMBOLIC;
1572 return (mips_symbolic_constant_p (x, &info->symbol_type)
1573 && mips_symbolic_address_p (info->symbol_type, mode)
1574 && !mips_split_p[info->symbol_type]);
1581 /* Return true if X is a thread-local symbol. */
1584 mips_tls_operand_p (rtx x)
1586 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
1589 /* Return true if X can not be forced into a constant pool. */
1592 mips_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1594 return mips_tls_operand_p (*x);
1597 /* Return true if X can not be forced into a constant pool. */
1600 mips_cannot_force_const_mem (rtx x)
1603 HOST_WIDE_INT offset;
1607 /* As an optimization, reject constants that mips_legitimize_move
1610 Suppose we have a multi-instruction sequence that loads constant C
1611 into register R. If R does not get allocated a hard register, and
1612 R is used in an operand that allows both registers and memory
1613 references, reload will consider forcing C into memory and using
1614 one of the instruction's memory alternatives. Returning false
1615 here will force it to use an input reload instead. */
1616 if (GET_CODE (x) == CONST_INT)
1619 mips_split_const (x, &base, &offset);
1620 if (symbolic_operand (base, VOIDmode) && SMALL_OPERAND (offset))
1624 if (TARGET_HAVE_TLS && for_each_rtx (&x, &mips_tls_symbol_ref_1, 0))
1630 /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. MIPS16 uses per-function
1631 constant pools, but normal-mode code doesn't need to. */
1634 mips_use_blocks_for_constant_p (enum machine_mode mode ATTRIBUTE_UNUSED,
1635 rtx x ATTRIBUTE_UNUSED)
1637 return !TARGET_MIPS16;
1640 /* Return the number of instructions needed to load a symbol of the
1641 given type into a register. If valid in an address, the same number
1642 of instructions are needed for loads and stores. Treat extended
1643 mips16 instructions as two instructions. */
1646 mips_symbol_insns (enum mips_symbol_type type)
1650 case SYMBOL_GENERAL:
1651 /* In mips16 code, general symbols must be fetched from the
1656 /* When using 64-bit symbols, we need 5 preparatory instructions,
1659 lui $at,%highest(symbol)
1660 daddiu $at,$at,%higher(symbol)
1662 daddiu $at,$at,%hi(symbol)
1665 The final address is then $at + %lo(symbol). With 32-bit
1666 symbols we just need a preparatory lui. */
1667 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1669 case SYMBOL_SMALL_DATA:
1672 case SYMBOL_CONSTANT_POOL:
1673 /* This case is for mips16 only. Assume we'll need an
1674 extended instruction. */
1677 case SYMBOL_GOT_LOCAL:
1678 case SYMBOL_GOT_GLOBAL:
1679 /* Unless -funit-at-a-time is in effect, we can't be sure whether
1680 the local/global classification is accurate. See override_options
1683 The worst cases are:
1685 (1) For local symbols when generating o32 or o64 code. The assembler
1691 ...and the final address will be $at + %lo(symbol).
1693 (2) For global symbols when -mxgot. The assembler will use:
1695 lui $at,%got_hi(symbol)
1698 ...and the final address will be $at + %got_lo(symbol). */
1701 case SYMBOL_GOTOFF_PAGE:
1702 case SYMBOL_GOTOFF_GLOBAL:
1703 case SYMBOL_GOTOFF_CALL:
1704 case SYMBOL_GOTOFF_LOADGP:
1705 case SYMBOL_64_HIGH:
1711 case SYMBOL_GOTTPREL:
1713 /* Check whether the offset is a 16- or 32-bit value. */
1714 return mips_split_p[type] ? 2 : 1;
1717 /* We don't treat a bare TLS symbol as a constant. */
1723 /* Return true if X is a legitimate $sp-based address for mode MDOE. */
1726 mips_stack_address_p (rtx x, enum machine_mode mode)
1728 struct mips_address_info addr;
1730 return (mips_classify_address (&addr, x, mode, false)
1731 && addr.type == ADDRESS_REG
1732 && addr.reg == stack_pointer_rtx);
1735 /* Return true if a value at OFFSET bytes from BASE can be accessed
1736 using an unextended mips16 instruction. MODE is the mode of the
1739 Usually the offset in an unextended instruction is a 5-bit field.
1740 The offset is unsigned and shifted left once for HIs, twice
1741 for SIs, and so on. An exception is SImode accesses off the
1742 stack pointer, which have an 8-bit immediate field. */
1745 mips16_unextended_reference_p (enum machine_mode mode, rtx base, rtx offset)
1748 && GET_CODE (offset) == CONST_INT
1749 && INTVAL (offset) >= 0
1750 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1752 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1753 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1754 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1760 /* Return the number of instructions needed to load or store a value
1761 of mode MODE at X. Return 0 if X isn't valid for MODE.
1763 For mips16 code, count extended instructions as two instructions. */
1766 mips_address_insns (rtx x, enum machine_mode mode)
1768 struct mips_address_info addr;
1771 if (mode == BLKmode)
1772 /* BLKmode is used for single unaligned loads and stores. */
1775 /* Each word of a multi-word value will be accessed individually. */
1776 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1778 if (mips_classify_address (&addr, x, mode, false))
1783 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1787 case ADDRESS_LO_SUM:
1788 return (TARGET_MIPS16 ? factor * 2 : factor);
1790 case ADDRESS_CONST_INT:
1793 case ADDRESS_SYMBOLIC:
1794 return factor * mips_symbol_insns (addr.symbol_type);
1800 /* Likewise for constant X. */
1803 mips_const_insns (rtx x)
1805 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1806 enum mips_symbol_type symbol_type;
1807 HOST_WIDE_INT offset;
1809 switch (GET_CODE (x))
1813 || !mips_symbolic_constant_p (XEXP (x, 0), &symbol_type)
1814 || !mips_split_p[symbol_type])
1821 /* Unsigned 8-bit constants can be loaded using an unextended
1822 LI instruction. Unsigned 16-bit constants can be loaded
1823 using an extended LI. Negative constants must be loaded
1824 using LI and then negated. */
1825 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1826 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1827 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1828 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1831 return mips_build_integer (codes, INTVAL (x));
1835 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1841 /* See if we can refer to X directly. */
1842 if (mips_symbolic_constant_p (x, &symbol_type))
1843 return mips_symbol_insns (symbol_type);
1845 /* Otherwise try splitting the constant into a base and offset.
1846 16-bit offsets can be added using an extra addiu. Larger offsets
1847 must be calculated separately and then added to the base. */
1848 mips_split_const (x, &x, &offset);
1851 int n = mips_const_insns (x);
1854 if (SMALL_OPERAND (offset))
1857 return n + 1 + mips_build_integer (codes, offset);
1864 return mips_symbol_insns (mips_classify_symbol (x));
1872 /* Return the number of instructions needed for memory reference X.
1873 Count extended mips16 instructions as two instructions. */
1876 mips_fetch_insns (rtx x)
1878 gcc_assert (MEM_P (x));
1879 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1883 /* Return the number of instructions needed for an integer division. */
1886 mips_idiv_insns (void)
1891 if (TARGET_CHECK_ZERO_DIV)
1893 if (GENERATE_DIVIDE_TRAPS)
1899 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
1904 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1905 returns a nonzero value if X is a legitimate address for a memory
1906 operand of the indicated MODE. STRICT is nonzero if this function
1907 is called during reload. */
1910 mips_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1912 struct mips_address_info addr;
1914 return mips_classify_address (&addr, x, mode, strict);
1918 /* Copy VALUE to a register and return that register. If new psuedos
1919 are allowed, copy it into a new register, otherwise use DEST. */
1922 mips_force_temporary (rtx dest, rtx value)
1924 if (!no_new_pseudos)
1925 return force_reg (Pmode, value);
1928 emit_move_insn (copy_rtx (dest), value);
1934 /* Return a LO_SUM expression for ADDR. TEMP is as for mips_force_temporary
1935 and is used to load the high part into a register. */
1938 mips_split_symbol (rtx temp, rtx addr)
1943 high = mips16_gp_pseudo_reg ();
1945 high = mips_force_temporary (temp, gen_rtx_HIGH (Pmode, copy_rtx (addr)));
1946 return gen_rtx_LO_SUM (Pmode, high, addr);
1950 /* Return an UNSPEC address with underlying address ADDRESS and symbol
1951 type SYMBOL_TYPE. */
1954 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
1957 HOST_WIDE_INT offset;
1959 mips_split_const (address, &base, &offset);
1960 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
1961 UNSPEC_ADDRESS_FIRST + symbol_type);
1962 return plus_constant (gen_rtx_CONST (Pmode, base), offset);
1966 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
1967 high part to BASE and return the result. Just return BASE otherwise.
1968 TEMP is available as a temporary register if needed.
1970 The returned expression can be used as the first operand to a LO_SUM. */
1973 mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
1974 enum mips_symbol_type symbol_type)
1976 if (mips_split_p[symbol_type])
1978 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
1979 addr = mips_force_temporary (temp, addr);
1980 return mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
1986 /* Return a legitimate address for REG + OFFSET. TEMP is as for
1987 mips_force_temporary; it is only needed when OFFSET is not a
1991 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
1993 if (!SMALL_OPERAND (offset))
1998 /* Load the full offset into a register so that we can use
1999 an unextended instruction for the address itself. */
2000 high = GEN_INT (offset);
2005 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH. */
2006 high = GEN_INT (CONST_HIGH_PART (offset));
2007 offset = CONST_LOW_PART (offset);
2009 high = mips_force_temporary (temp, high);
2010 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
2012 return plus_constant (reg, offset);
2015 /* Emit a call to __tls_get_addr. SYM is the TLS symbol we are
2016 referencing, and TYPE is the symbol type to use (either global
2017 dynamic or local dynamic). V0 is an RTX for the return value
2018 location. The entire insn sequence is returned. */
2020 static GTY(()) rtx mips_tls_symbol;
2023 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
2025 rtx insn, loc, tga, a0;
2027 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
2029 if (!mips_tls_symbol)
2030 mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
2032 loc = mips_unspec_address (sym, type);
2036 emit_insn (gen_rtx_SET (Pmode, a0,
2037 gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
2038 tga = gen_rtx_MEM (Pmode, mips_tls_symbol);
2039 insn = emit_call_insn (gen_call_value (v0, tga, const0_rtx, const0_rtx));
2040 CONST_OR_PURE_CALL_P (insn) = 1;
2041 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), v0);
2042 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
2043 insn = get_insns ();
2050 /* Generate the code to access LOC, a thread local SYMBOL_REF. The
2051 return value will be a valid address and move_operand (either a REG
2055 mips_legitimize_tls_address (rtx loc)
2057 rtx dest, insn, v0, v1, tmp1, tmp2, eqv;
2058 enum tls_model model;
2060 v0 = gen_rtx_REG (Pmode, GP_RETURN);
2061 v1 = gen_rtx_REG (Pmode, GP_RETURN + 1);
2063 model = SYMBOL_REF_TLS_MODEL (loc);
2064 /* Only TARGET_ABICALLS code can have more than one module; other
2065 code must be be static and should not use a GOT. All TLS models
2066 reduce to local exec in this situation. */
2067 if (!TARGET_ABICALLS)
2068 model = TLS_MODEL_LOCAL_EXEC;
2072 case TLS_MODEL_GLOBAL_DYNAMIC:
2073 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
2074 dest = gen_reg_rtx (Pmode);
2075 emit_libcall_block (insn, dest, v0, loc);
2078 case TLS_MODEL_LOCAL_DYNAMIC:
2079 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
2080 tmp1 = gen_reg_rtx (Pmode);
2082 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
2083 share the LDM result with other LD model accesses. */
2084 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2086 emit_libcall_block (insn, tmp1, v0, eqv);
2088 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
2089 dest = gen_rtx_LO_SUM (Pmode, tmp2,
2090 mips_unspec_address (loc, SYMBOL_DTPREL));
2093 case TLS_MODEL_INITIAL_EXEC:
2094 tmp1 = gen_reg_rtx (Pmode);
2095 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
2096 if (Pmode == DImode)
2098 emit_insn (gen_tls_get_tp_di (v1));
2099 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
2103 emit_insn (gen_tls_get_tp_si (v1));
2104 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
2106 dest = gen_reg_rtx (Pmode);
2107 emit_insn (gen_add3_insn (dest, tmp1, v1));
2110 case TLS_MODEL_LOCAL_EXEC:
2111 if (Pmode == DImode)
2112 emit_insn (gen_tls_get_tp_di (v1));
2114 emit_insn (gen_tls_get_tp_si (v1));
2116 tmp1 = mips_unspec_offset_high (NULL, v1, loc, SYMBOL_TPREL);
2117 dest = gen_rtx_LO_SUM (Pmode, tmp1,
2118 mips_unspec_address (loc, SYMBOL_TPREL));
2128 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
2129 be legitimized in a way that the generic machinery might not expect,
2130 put the new address in *XLOC and return true. MODE is the mode of
2131 the memory being accessed. */
2134 mips_legitimize_address (rtx *xloc, enum machine_mode mode)
2136 enum mips_symbol_type symbol_type;
2138 if (mips_tls_operand_p (*xloc))
2140 *xloc = mips_legitimize_tls_address (*xloc);
2144 /* See if the address can split into a high part and a LO_SUM. */
2145 if (mips_symbolic_constant_p (*xloc, &symbol_type)
2146 && mips_symbolic_address_p (symbol_type, mode)
2147 && mips_split_p[symbol_type])
2149 *xloc = mips_split_symbol (0, *xloc);
2153 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
2155 /* Handle REG + CONSTANT using mips_add_offset. */
2158 reg = XEXP (*xloc, 0);
2159 if (!mips_valid_base_register_p (reg, mode, 0))
2160 reg = copy_to_mode_reg (Pmode, reg);
2161 *xloc = mips_add_offset (0, reg, INTVAL (XEXP (*xloc, 1)));
2169 /* Subroutine of mips_build_integer (with the same interface).
2170 Assume that the final action in the sequence should be a left shift. */
2173 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
2175 unsigned int i, shift;
2177 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
2178 since signed numbers are easier to load than unsigned ones. */
2180 while ((value & 1) == 0)
2181 value /= 2, shift++;
2183 i = mips_build_integer (codes, value);
2184 codes[i].code = ASHIFT;
2185 codes[i].value = shift;
2190 /* As for mips_build_shift, but assume that the final action will be
2191 an IOR or PLUS operation. */
2194 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
2196 unsigned HOST_WIDE_INT high;
2199 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
2200 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
2202 /* The constant is too complex to load with a simple lui/ori pair
2203 so our goal is to clear as many trailing zeros as possible.
2204 In this case, we know bit 16 is set and that the low 16 bits
2205 form a negative number. If we subtract that number from VALUE,
2206 we will clear at least the lowest 17 bits, maybe more. */
2207 i = mips_build_integer (codes, CONST_HIGH_PART (value));
2208 codes[i].code = PLUS;
2209 codes[i].value = CONST_LOW_PART (value);
2213 i = mips_build_integer (codes, high);
2214 codes[i].code = IOR;
2215 codes[i].value = value & 0xffff;
2221 /* Fill CODES with a sequence of rtl operations to load VALUE.
2222 Return the number of operations needed. */
2225 mips_build_integer (struct mips_integer_op *codes,
2226 unsigned HOST_WIDE_INT value)
2228 if (SMALL_OPERAND (value)
2229 || SMALL_OPERAND_UNSIGNED (value)
2230 || LUI_OPERAND (value))
2232 /* The value can be loaded with a single instruction. */
2233 codes[0].code = UNKNOWN;
2234 codes[0].value = value;
2237 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
2239 /* Either the constant is a simple LUI/ORI combination or its
2240 lowest bit is set. We don't want to shift in this case. */
2241 return mips_build_lower (codes, value);
2243 else if ((value & 0xffff) == 0)
2245 /* The constant will need at least three actions. The lowest
2246 16 bits are clear, so the final action will be a shift. */
2247 return mips_build_shift (codes, value);
2251 /* The final action could be a shift, add or inclusive OR.
2252 Rather than use a complex condition to select the best
2253 approach, try both mips_build_shift and mips_build_lower
2254 and pick the one that gives the shortest sequence.
2255 Note that this case is only used once per constant. */
2256 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
2257 unsigned int cost, alt_cost;
2259 cost = mips_build_shift (codes, value);
2260 alt_cost = mips_build_lower (alt_codes, value);
2261 if (alt_cost < cost)
2263 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
2271 /* Load VALUE into DEST, using TEMP as a temporary register if need be. */
2274 mips_move_integer (rtx dest, rtx temp, unsigned HOST_WIDE_INT value)
2276 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
2277 enum machine_mode mode;
2278 unsigned int i, cost;
2281 mode = GET_MODE (dest);
2282 cost = mips_build_integer (codes, value);
2284 /* Apply each binary operation to X. Invariant: X is a legitimate
2285 source operand for a SET pattern. */
2286 x = GEN_INT (codes[0].value);
2287 for (i = 1; i < cost; i++)
2291 emit_insn (gen_rtx_SET (VOIDmode, temp, x));
2295 x = force_reg (mode, x);
2296 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
2299 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
2303 /* Subroutine of mips_legitimize_move. Move constant SRC into register
2304 DEST given that SRC satisfies immediate_operand but doesn't satisfy
2308 mips_legitimize_const_move (enum machine_mode mode, rtx dest, rtx src)
2311 HOST_WIDE_INT offset;
2313 /* Split moves of big integers into smaller pieces. */
2314 if (splittable_const_int_operand (src, mode))
2316 mips_move_integer (dest, dest, INTVAL (src));
2320 /* Split moves of symbolic constants into high/low pairs. */
2321 if (splittable_symbolic_operand (src, mode))
2323 emit_insn (gen_rtx_SET (VOIDmode, dest, mips_split_symbol (dest, src)));
2327 if (mips_tls_operand_p (src))
2329 emit_move_insn (dest, mips_legitimize_tls_address (src));
2333 /* If we have (const (plus symbol offset)), load the symbol first
2334 and then add in the offset. This is usually better than forcing
2335 the constant into memory, at least in non-mips16 code. */
2336 mips_split_const (src, &base, &offset);
2339 && (!no_new_pseudos || SMALL_OPERAND (offset)))
2341 base = mips_force_temporary (dest, base);
2342 emit_move_insn (dest, mips_add_offset (0, base, offset));
2346 src = force_const_mem (mode, src);
2348 /* When using explicit relocs, constant pool references are sometimes
2349 not legitimate addresses. */
2350 if (!memory_operand (src, VOIDmode))
2351 src = replace_equiv_address (src, mips_split_symbol (dest, XEXP (src, 0)));
2352 emit_move_insn (dest, src);
2356 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
2357 sequence that is valid. */
2360 mips_legitimize_move (enum machine_mode mode, rtx dest, rtx src)
2362 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
2364 emit_move_insn (dest, force_reg (mode, src));
2368 /* Check for individual, fully-reloaded mflo and mfhi instructions. */
2369 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
2370 && REG_P (src) && MD_REG_P (REGNO (src))
2371 && REG_P (dest) && GP_REG_P (REGNO (dest)))
2373 int other_regno = REGNO (src) == HI_REGNUM ? LO_REGNUM : HI_REGNUM;
2374 if (GET_MODE_SIZE (mode) <= 4)
2375 emit_insn (gen_mfhilo_si (gen_rtx_REG (SImode, REGNO (dest)),
2376 gen_rtx_REG (SImode, REGNO (src)),
2377 gen_rtx_REG (SImode, other_regno)));
2379 emit_insn (gen_mfhilo_di (gen_rtx_REG (DImode, REGNO (dest)),
2380 gen_rtx_REG (DImode, REGNO (src)),
2381 gen_rtx_REG (DImode, other_regno)));
2385 /* We need to deal with constants that would be legitimate
2386 immediate_operands but not legitimate move_operands. */
2387 if (CONSTANT_P (src) && !move_operand (src, mode))
2389 mips_legitimize_const_move (mode, dest, src);
2390 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
2396 /* We need a lot of little routines to check constant values on the
2397 mips16. These are used to figure out how long the instruction will
2398 be. It would be much better to do this using constraints, but
2399 there aren't nearly enough letters available. */
2402 m16_check_op (rtx op, int low, int high, int mask)
2404 return (GET_CODE (op) == CONST_INT
2405 && INTVAL (op) >= low
2406 && INTVAL (op) <= high
2407 && (INTVAL (op) & mask) == 0);
2411 m16_uimm3_b (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2413 return m16_check_op (op, 0x1, 0x8, 0);
2417 m16_simm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2419 return m16_check_op (op, - 0x8, 0x7, 0);
2423 m16_nsimm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2425 return m16_check_op (op, - 0x7, 0x8, 0);
2429 m16_simm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2431 return m16_check_op (op, - 0x10, 0xf, 0);
2435 m16_nsimm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2437 return m16_check_op (op, - 0xf, 0x10, 0);
2441 m16_uimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2443 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2447 m16_nuimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2449 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2453 m16_simm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2455 return m16_check_op (op, - 0x80, 0x7f, 0);
2459 m16_nsimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2461 return m16_check_op (op, - 0x7f, 0x80, 0);
2465 m16_uimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2467 return m16_check_op (op, 0x0, 0xff, 0);
2471 m16_nuimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2473 return m16_check_op (op, - 0xff, 0x0, 0);
2477 m16_uimm8_m1_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2479 return m16_check_op (op, - 0x1, 0xfe, 0);
2483 m16_uimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2485 return m16_check_op (op, 0x0, 0xff << 2, 3);
2489 m16_nuimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2491 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2495 m16_simm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2497 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2501 m16_nsimm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2503 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2507 mips_rtx_costs (rtx x, int code, int outer_code, int *total)
2509 enum machine_mode mode = GET_MODE (x);
2510 bool float_mode_p = FLOAT_MODE_P (mode);
2517 /* A number between 1 and 8 inclusive is efficient for a shift.
2518 Otherwise, we will need an extended instruction. */
2519 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2520 || (outer_code) == LSHIFTRT)
2522 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2525 *total = COSTS_N_INSNS (1);
2529 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2530 if ((outer_code) == XOR
2531 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2537 /* We may be able to use slt or sltu for a comparison with a
2538 signed 16 bit value. (The boundary conditions aren't quite
2539 right, but this is just a heuristic anyhow.) */
2540 if (((outer_code) == LT || (outer_code) == LE
2541 || (outer_code) == GE || (outer_code) == GT
2542 || (outer_code) == LTU || (outer_code) == LEU
2543 || (outer_code) == GEU || (outer_code) == GTU)
2544 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2550 /* Equality comparisons with 0 are cheap. */
2551 if (((outer_code) == EQ || (outer_code) == NE)
2558 /* Constants in the range 0...255 can be loaded with an unextended
2559 instruction. They are therefore as cheap as a register move.
2561 Given the choice between "li R1,0...255" and "move R1,R2"
2562 (where R2 is a known constant), it is usually better to use "li",
2563 since we do not want to unnecessarily extend the lifetime
2565 if (outer_code == SET
2567 && INTVAL (x) < 256)
2575 /* These can be used anywhere. */
2580 /* Otherwise fall through to the handling below because
2581 we'll need to construct the constant. */
2587 if (LEGITIMATE_CONSTANT_P (x))
2589 *total = COSTS_N_INSNS (1);
2594 /* The value will need to be fetched from the constant pool. */
2595 *total = CONSTANT_POOL_COST;
2601 /* If the address is legitimate, return the number of
2602 instructions it needs, otherwise use the default handling. */
2603 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2606 *total = COSTS_N_INSNS (n + 1);
2613 *total = COSTS_N_INSNS (6);
2617 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2623 if (mode == DImode && !TARGET_64BIT)
2625 *total = COSTS_N_INSNS (2);
2633 if (mode == DImode && !TARGET_64BIT)
2635 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2643 *total = COSTS_N_INSNS (1);
2645 *total = COSTS_N_INSNS (4);
2649 *total = COSTS_N_INSNS (1);
2656 *total = mips_cost->fp_add;
2660 else if (mode == DImode && !TARGET_64BIT)
2662 *total = COSTS_N_INSNS (4);
2668 if (mode == DImode && !TARGET_64BIT)
2670 *total = COSTS_N_INSNS (4);
2677 *total = mips_cost->fp_mult_sf;
2679 else if (mode == DFmode)
2680 *total = mips_cost->fp_mult_df;
2682 else if (mode == SImode)
2683 *total = mips_cost->int_mult_si;
2686 *total = mips_cost->int_mult_di;
2695 *total = mips_cost->fp_div_sf;
2697 *total = mips_cost->fp_div_df;
2706 *total = mips_cost->int_div_di;
2708 *total = mips_cost->int_div_si;
2713 /* A sign extend from SImode to DImode in 64 bit mode is often
2714 zero instructions, because the result can often be used
2715 directly by another instruction; we'll call it one. */
2716 if (TARGET_64BIT && mode == DImode
2717 && GET_MODE (XEXP (x, 0)) == SImode)
2718 *total = COSTS_N_INSNS (1);
2720 *total = COSTS_N_INSNS (2);
2724 if (TARGET_64BIT && mode == DImode
2725 && GET_MODE (XEXP (x, 0)) == SImode)
2726 *total = COSTS_N_INSNS (2);
2728 *total = COSTS_N_INSNS (1);
2732 case UNSIGNED_FLOAT:
2735 case FLOAT_TRUNCATE:
2737 *total = mips_cost->fp_add;
2745 /* Provide the costs of an addressing mode that contains ADDR.
2746 If ADDR is not a valid address, its cost is irrelevant. */
2749 mips_address_cost (rtx addr)
2751 return mips_address_insns (addr, SImode);
2754 /* Return one word of double-word value OP, taking into account the fixed
2755 endianness of certain registers. HIGH_P is true to select the high part,
2756 false to select the low part. */
2759 mips_subword (rtx op, int high_p)
2762 enum machine_mode mode;
2764 mode = GET_MODE (op);
2765 if (mode == VOIDmode)
2768 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2769 byte = UNITS_PER_WORD;
2775 if (FP_REG_P (REGNO (op)))
2776 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2777 if (ACC_HI_REG_P (REGNO (op)))
2778 return gen_rtx_REG (word_mode, high_p ? REGNO (op) : REGNO (op) + 1);
2782 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
2784 return simplify_gen_subreg (word_mode, op, mode, byte);
2788 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2791 mips_split_64bit_move_p (rtx dest, rtx src)
2796 /* FP->FP moves can be done in a single instruction. */
2797 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2800 /* Check for floating-point loads and stores. They can be done using
2801 ldc1 and sdc1 on MIPS II and above. */
2804 if (FP_REG_RTX_P (dest) && MEM_P (src))
2806 if (FP_REG_RTX_P (src) && MEM_P (dest))
2813 /* Split a 64-bit move from SRC to DEST assuming that
2814 mips_split_64bit_move_p holds.
2816 Moves into and out of FPRs cause some difficulty here. Such moves
2817 will always be DFmode, since paired FPRs are not allowed to store
2818 DImode values. The most natural representation would be two separate
2819 32-bit moves, such as:
2821 (set (reg:SI $f0) (mem:SI ...))
2822 (set (reg:SI $f1) (mem:SI ...))
2824 However, the second insn is invalid because odd-numbered FPRs are
2825 not allowed to store independent values. Use the patterns load_df_low,
2826 load_df_high and store_df_high instead. */
2829 mips_split_64bit_move (rtx dest, rtx src)
2831 if (FP_REG_RTX_P (dest))
2833 /* Loading an FPR from memory or from GPRs. */
2834 emit_insn (gen_load_df_low (copy_rtx (dest), mips_subword (src, 0)));
2835 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2838 else if (FP_REG_RTX_P (src))
2840 /* Storing an FPR into memory or GPRs. */
2841 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2842 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2846 /* The operation can be split into two normal moves. Decide in
2847 which order to do them. */
2850 low_dest = mips_subword (dest, 0);
2851 if (REG_P (low_dest)
2852 && reg_overlap_mentioned_p (low_dest, src))
2854 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2855 emit_move_insn (low_dest, mips_subword (src, 0));
2859 emit_move_insn (low_dest, mips_subword (src, 0));
2860 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2865 /* Return the appropriate instructions to move SRC into DEST. Assume
2866 that SRC is operand 1 and DEST is operand 0. */
2869 mips_output_move (rtx dest, rtx src)
2871 enum rtx_code dest_code, src_code;
2874 dest_code = GET_CODE (dest);
2875 src_code = GET_CODE (src);
2876 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2878 if (dbl_p && mips_split_64bit_move_p (dest, src))
2881 if ((src_code == REG && GP_REG_P (REGNO (src)))
2882 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2884 if (dest_code == REG)
2886 if (GP_REG_P (REGNO (dest)))
2887 return "move\t%0,%z1";
2889 if (MD_REG_P (REGNO (dest)))
2892 if (DSP_ACC_REG_P (REGNO (dest)))
2894 static char retval[] = "mt__\t%z1,%q0";
2895 retval[2] = reg_names[REGNO (dest)][4];
2896 retval[3] = reg_names[REGNO (dest)][5];
2900 if (FP_REG_P (REGNO (dest)))
2901 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2903 if (ALL_COP_REG_P (REGNO (dest)))
2905 static char retval[] = "dmtc_\t%z1,%0";
2907 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2908 return (dbl_p ? retval : retval + 1);
2911 if (dest_code == MEM)
2912 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2914 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2916 if (src_code == REG)
2918 if (DSP_ACC_REG_P (REGNO (src)))
2920 static char retval[] = "mf__\t%0,%q1";
2921 retval[2] = reg_names[REGNO (src)][4];
2922 retval[3] = reg_names[REGNO (src)][5];
2926 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2927 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2929 if (FP_REG_P (REGNO (src)))
2930 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2932 if (ALL_COP_REG_P (REGNO (src)))
2934 static char retval[] = "dmfc_\t%0,%1";
2936 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2937 return (dbl_p ? retval : retval + 1);
2941 if (src_code == MEM)
2942 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
2944 if (src_code == CONST_INT)
2946 /* Don't use the X format, because that will give out of
2947 range numbers for 64 bit hosts and 32 bit targets. */
2949 return "li\t%0,%1\t\t\t# %X1";
2951 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
2954 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
2958 if (src_code == HIGH)
2959 return "lui\t%0,%h1";
2961 if (CONST_GP_P (src))
2962 return "move\t%0,%1";
2964 if (symbolic_operand (src, VOIDmode))
2965 return (dbl_p ? "dla\t%0,%1" : "la\t%0,%1");
2967 if (src_code == REG && FP_REG_P (REGNO (src)))
2969 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2971 if (GET_MODE (dest) == V2SFmode)
2972 return "mov.ps\t%0,%1";
2974 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2977 if (dest_code == MEM)
2978 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
2980 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2982 if (src_code == MEM)
2983 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
2985 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
2987 static char retval[] = "l_c_\t%0,%1";
2989 retval[1] = (dbl_p ? 'd' : 'w');
2990 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2993 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
2995 static char retval[] = "s_c_\t%1,%0";
2997 retval[1] = (dbl_p ? 'd' : 'w');
2998 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
3004 /* Restore $gp from its save slot. Valid only when using o32 or
3008 mips_restore_gp (void)
3012 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI);
3014 address = mips_add_offset (pic_offset_table_rtx,
3015 frame_pointer_needed
3016 ? hard_frame_pointer_rtx
3017 : stack_pointer_rtx,
3018 current_function_outgoing_args_size);
3019 slot = gen_rtx_MEM (Pmode, address);
3021 emit_move_insn (pic_offset_table_rtx, slot);
3022 if (!TARGET_EXPLICIT_RELOCS)
3023 emit_insn (gen_blockage ());
3026 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
3029 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
3031 emit_insn (gen_rtx_SET (VOIDmode, target,
3032 gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
3035 /* Return true if CMP1 is a suitable second operand for relational
3036 operator CODE. See also the *sCC patterns in mips.md. */
3039 mips_relational_operand_ok_p (enum rtx_code code, rtx cmp1)
3045 return reg_or_0_operand (cmp1, VOIDmode);
3049 return !TARGET_MIPS16 && cmp1 == const1_rtx;
3053 return arith_operand (cmp1, VOIDmode);
3056 return sle_operand (cmp1, VOIDmode);
3059 return sleu_operand (cmp1, VOIDmode);
3066 /* Canonicalize LE or LEU comparisons into LT comparisons when
3067 possible to avoid extra instructions or inverting the
3071 mips_canonicalize_comparison (enum rtx_code *code, rtx *cmp1,
3072 enum machine_mode mode)
3074 HOST_WIDE_INT original, plus_one;
3076 if (GET_CODE (*cmp1) != CONST_INT)
3079 original = INTVAL (*cmp1);
3080 plus_one = trunc_int_for_mode ((unsigned HOST_WIDE_INT) original + 1, mode);
3085 if (original < plus_one)
3088 *cmp1 = force_reg (mode, GEN_INT (plus_one));
3097 *cmp1 = force_reg (mode, GEN_INT (plus_one));
3110 /* Compare CMP0 and CMP1 using relational operator CODE and store the
3111 result in TARGET. CMP0 and TARGET are register_operands that have
3112 the same integer mode. If INVERT_PTR is nonnull, it's OK to set
3113 TARGET to the inverse of the result and flip *INVERT_PTR instead. */
3116 mips_emit_int_relational (enum rtx_code code, bool *invert_ptr,
3117 rtx target, rtx cmp0, rtx cmp1)
3119 /* First see if there is a MIPS instruction that can do this operation
3120 with CMP1 in its current form. If not, try to canonicalize the
3121 comparison to LT. If that fails, try doing the same for the
3122 inverse operation. If that also fails, force CMP1 into a register
3124 if (mips_relational_operand_ok_p (code, cmp1))
3125 mips_emit_binary (code, target, cmp0, cmp1);
3126 else if (mips_canonicalize_comparison (&code, &cmp1, GET_MODE (target)))
3127 mips_emit_binary (code, target, cmp0, cmp1);
3130 enum rtx_code inv_code = reverse_condition (code);
3131 if (!mips_relational_operand_ok_p (inv_code, cmp1))
3133 cmp1 = force_reg (GET_MODE (cmp0), cmp1);
3134 mips_emit_int_relational (code, invert_ptr, target, cmp0, cmp1);
3136 else if (invert_ptr == 0)
3138 rtx inv_target = gen_reg_rtx (GET_MODE (target));
3139 mips_emit_binary (inv_code, inv_target, cmp0, cmp1);
3140 mips_emit_binary (XOR, target, inv_target, const1_rtx);
3144 *invert_ptr = !*invert_ptr;
3145 mips_emit_binary (inv_code, target, cmp0, cmp1);
3150 /* Return a register that is zero iff CMP0 and CMP1 are equal.
3151 The register will have the same mode as CMP0. */
3154 mips_zero_if_equal (rtx cmp0, rtx cmp1)
3156 if (cmp1 == const0_rtx)
3159 if (uns_arith_operand (cmp1, VOIDmode))
3160 return expand_binop (GET_MODE (cmp0), xor_optab,
3161 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
3163 return expand_binop (GET_MODE (cmp0), sub_optab,
3164 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
3167 /* Convert *CODE into a code that can be used in a floating-point
3168 scc instruction (c.<cond>.<fmt>). Return true if the values of
3169 the condition code registers will be inverted, with 0 indicating
3170 that the condition holds. */
3173 mips_reverse_fp_cond_p (enum rtx_code *code)
3180 *code = reverse_condition_maybe_unordered (*code);
3188 /* Convert a comparison into something that can be used in a branch or
3189 conditional move. cmp_operands[0] and cmp_operands[1] are the values
3190 being compared and *CODE is the code used to compare them.
3192 Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
3193 If NEED_EQ_NE_P, then only EQ/NE comparisons against zero are possible,
3194 otherwise any standard branch condition can be used. The standard branch
3197 - EQ/NE between two registers.
3198 - any comparison between a register and zero. */
3201 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
3203 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT)
3205 if (!need_eq_ne_p && cmp_operands[1] == const0_rtx)
3207 *op0 = cmp_operands[0];
3208 *op1 = cmp_operands[1];
3210 else if (*code == EQ || *code == NE)
3214 *op0 = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
3219 *op0 = cmp_operands[0];
3220 *op1 = force_reg (GET_MODE (*op0), cmp_operands[1]);
3225 /* The comparison needs a separate scc instruction. Store the
3226 result of the scc in *OP0 and compare it against zero. */
3227 bool invert = false;
3228 *op0 = gen_reg_rtx (GET_MODE (cmp_operands[0]));
3230 mips_emit_int_relational (*code, &invert, *op0,
3231 cmp_operands[0], cmp_operands[1]);
3232 *code = (invert ? EQ : NE);
3237 enum rtx_code cmp_code;
3239 /* Floating-point tests use a separate c.cond.fmt comparison to
3240 set a condition code register. The branch or conditional move
3241 will then compare that register against zero.
3243 Set CMP_CODE to the code of the comparison instruction and
3244 *CODE to the code that the branch or move should use. */
3246 *code = mips_reverse_fp_cond_p (&cmp_code) ? EQ : NE;
3248 ? gen_reg_rtx (CCmode)
3249 : gen_rtx_REG (CCmode, FPSW_REGNUM));
3251 mips_emit_binary (cmp_code, *op0, cmp_operands[0], cmp_operands[1]);
3255 /* Try comparing cmp_operands[0] and cmp_operands[1] using rtl code CODE.
3256 Store the result in TARGET and return true if successful.
3258 On 64-bit targets, TARGET may be wider than cmp_operands[0]. */
3261 mips_emit_scc (enum rtx_code code, rtx target)
3263 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) != MODE_INT)
3266 target = gen_lowpart (GET_MODE (cmp_operands[0]), target);
3267 if (code == EQ || code == NE)
3269 rtx zie = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
3270 mips_emit_binary (code, target, zie, const0_rtx);
3273 mips_emit_int_relational (code, 0, target,
3274 cmp_operands[0], cmp_operands[1]);
3278 /* Emit the common code for doing conditional branches.
3279 operand[0] is the label to jump to.
3280 The comparison operands are saved away by cmp{si,di,sf,df}. */
3283 gen_conditional_branch (rtx *operands, enum rtx_code code)
3285 rtx op0, op1, condition;
3287 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
3288 condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3289 emit_jump_insn (gen_condjump (condition, operands[0]));
3294 (set temp (COND:CCV2 CMP_OP0 CMP_OP1))
3295 (set DEST (unspec [TRUE_SRC FALSE_SRC temp] UNSPEC_MOVE_TF_PS)) */
3298 mips_expand_vcondv2sf (rtx dest, rtx true_src, rtx false_src,
3299 enum rtx_code cond, rtx cmp_op0, rtx cmp_op1)
3304 reversed_p = mips_reverse_fp_cond_p (&cond);
3305 cmp_result = gen_reg_rtx (CCV2mode);
3306 emit_insn (gen_scc_ps (cmp_result,
3307 gen_rtx_fmt_ee (cond, VOIDmode, cmp_op0, cmp_op1)));
3309 emit_insn (gen_mips_cond_move_tf_ps (dest, false_src, true_src,
3312 emit_insn (gen_mips_cond_move_tf_ps (dest, true_src, false_src,
3316 /* Emit the common code for conditional moves. OPERANDS is the array
3317 of operands passed to the conditional move define_expand. */
3320 gen_conditional_move (rtx *operands)
3325 code = GET_CODE (operands[1]);
3326 mips_emit_compare (&code, &op0, &op1, true);
3327 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
3328 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
3329 gen_rtx_fmt_ee (code,
3332 operands[2], operands[3])));
3335 /* Emit a conditional trap. OPERANDS is the array of operands passed to
3336 the conditional_trap expander. */
3339 mips_gen_conditional_trap (rtx *operands)
3342 enum rtx_code cmp_code = GET_CODE (operands[0]);
3343 enum machine_mode mode = GET_MODE (cmp_operands[0]);
3345 /* MIPS conditional trap machine instructions don't have GT or LE
3346 flavors, so we must invert the comparison and convert to LT and
3347 GE, respectively. */
3350 case GT: cmp_code = LT; break;
3351 case LE: cmp_code = GE; break;
3352 case GTU: cmp_code = LTU; break;
3353 case LEU: cmp_code = GEU; break;
3356 if (cmp_code == GET_CODE (operands[0]))
3358 op0 = cmp_operands[0];
3359 op1 = cmp_operands[1];
3363 op0 = cmp_operands[1];
3364 op1 = cmp_operands[0];
3366 op0 = force_reg (mode, op0);
3367 if (!arith_operand (op1, mode))
3368 op1 = force_reg (mode, op1);
3370 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
3371 gen_rtx_fmt_ee (cmp_code, mode, op0, op1),
3375 /* Load function address ADDR into register DEST. SIBCALL_P is true
3376 if the address is needed for a sibling call. */
3379 mips_load_call_address (rtx dest, rtx addr, int sibcall_p)
3381 /* If we're generating PIC, and this call is to a global function,
3382 try to allow its address to be resolved lazily. This isn't
3383 possible for NewABI sibcalls since the value of $gp on entry
3384 to the stub would be our caller's gp, not ours. */
3385 if (TARGET_EXPLICIT_RELOCS
3386 && !(sibcall_p && TARGET_NEWABI)
3387 && global_got_operand (addr, VOIDmode))
3389 rtx high, lo_sum_symbol;
3391 high = mips_unspec_offset_high (dest, pic_offset_table_rtx,
3392 addr, SYMBOL_GOTOFF_CALL);
3393 lo_sum_symbol = mips_unspec_address (addr, SYMBOL_GOTOFF_CALL);
3394 if (Pmode == SImode)
3395 emit_insn (gen_load_callsi (dest, high, lo_sum_symbol));
3397 emit_insn (gen_load_calldi (dest, high, lo_sum_symbol));
3400 emit_move_insn (dest, addr);
3404 /* Expand a call or call_value instruction. RESULT is where the
3405 result will go (null for calls), ADDR is the address of the
3406 function, ARGS_SIZE is the size of the arguments and AUX is
3407 the value passed to us by mips_function_arg. SIBCALL_P is true
3408 if we are expanding a sibling call, false if we're expanding
3412 mips_expand_call (rtx result, rtx addr, rtx args_size, rtx aux, int sibcall_p)
3414 rtx orig_addr, pattern, insn;
3417 if (!call_insn_operand (addr, VOIDmode))
3419 addr = gen_reg_rtx (Pmode);
3420 mips_load_call_address (addr, orig_addr, sibcall_p);
3424 && mips16_hard_float
3425 && build_mips16_call_stub (result, addr, args_size,
3426 aux == 0 ? 0 : (int) GET_MODE (aux)))
3430 pattern = (sibcall_p
3431 ? gen_sibcall_internal (addr, args_size)
3432 : gen_call_internal (addr, args_size));
3433 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
3437 reg1 = XEXP (XVECEXP (result, 0, 0), 0);
3438 reg2 = XEXP (XVECEXP (result, 0, 1), 0);
3441 ? gen_sibcall_value_multiple_internal (reg1, addr, args_size, reg2)
3442 : gen_call_value_multiple_internal (reg1, addr, args_size, reg2));
3445 pattern = (sibcall_p
3446 ? gen_sibcall_value_internal (result, addr, args_size)
3447 : gen_call_value_internal (result, addr, args_size));
3449 insn = emit_call_insn (pattern);
3451 /* Lazy-binding stubs require $gp to be valid on entry. */
3452 if (global_got_operand (orig_addr, VOIDmode))
3453 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
3457 /* We can handle any sibcall when TARGET_SIBCALLS is true. */
3460 mips_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
3461 tree exp ATTRIBUTE_UNUSED)
3463 return TARGET_SIBCALLS;
3466 /* Emit code to move general operand SRC into condition-code
3467 register DEST. SCRATCH is a scratch TFmode float register.
3474 where FP1 and FP2 are single-precision float registers
3475 taken from SCRATCH. */
3478 mips_emit_fcc_reload (rtx dest, rtx src, rtx scratch)
3482 /* Change the source to SFmode. */
3484 src = adjust_address (src, SFmode, 0);
3485 else if (REG_P (src) || GET_CODE (src) == SUBREG)
3486 src = gen_rtx_REG (SFmode, true_regnum (src));
3488 fp1 = gen_rtx_REG (SFmode, REGNO (scratch));
3489 fp2 = gen_rtx_REG (SFmode, REGNO (scratch) + FP_INC);
3491 emit_move_insn (copy_rtx (fp1), src);
3492 emit_move_insn (copy_rtx (fp2), CONST0_RTX (SFmode));
3493 emit_insn (gen_slt_sf (dest, fp2, fp1));
3496 /* Emit code to change the current function's return address to
3497 ADDRESS. SCRATCH is available as a scratch register, if needed.
3498 ADDRESS and SCRATCH are both word-mode GPRs. */
3501 mips_set_return_address (rtx address, rtx scratch)
3505 compute_frame_size (get_frame_size ());
3506 gcc_assert ((cfun->machine->frame.mask >> 31) & 1);
3507 slot_address = mips_add_offset (scratch, stack_pointer_rtx,
3508 cfun->machine->frame.gp_sp_offset);
3510 emit_move_insn (gen_rtx_MEM (GET_MODE (address), slot_address), address);
3513 /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
3514 Assume that the areas do not overlap. */
3517 mips_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length)
3519 HOST_WIDE_INT offset, delta;
3520 unsigned HOST_WIDE_INT bits;
3522 enum machine_mode mode;
3525 /* Work out how many bits to move at a time. If both operands have
3526 half-word alignment, it is usually better to move in half words.
3527 For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr
3528 and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr.
3529 Otherwise move word-sized chunks. */
3530 if (MEM_ALIGN (src) == BITS_PER_WORD / 2
3531 && MEM_ALIGN (dest) == BITS_PER_WORD / 2)
3532 bits = BITS_PER_WORD / 2;
3534 bits = BITS_PER_WORD;
3536 mode = mode_for_size (bits, MODE_INT, 0);
3537 delta = bits / BITS_PER_UNIT;
3539 /* Allocate a buffer for the temporary registers. */
3540 regs = alloca (sizeof (rtx) * length / delta);
3542 /* Load as many BITS-sized chunks as possible. Use a normal load if
3543 the source has enough alignment, otherwise use left/right pairs. */
3544 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
3546 regs[i] = gen_reg_rtx (mode);
3547 if (MEM_ALIGN (src) >= bits)
3548 emit_move_insn (regs[i], adjust_address (src, mode, offset));
3551 rtx part = adjust_address (src, BLKmode, offset);
3552 if (!mips_expand_unaligned_load (regs[i], part, bits, 0))
3557 /* Copy the chunks to the destination. */
3558 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
3559 if (MEM_ALIGN (dest) >= bits)
3560 emit_move_insn (adjust_address (dest, mode, offset), regs[i]);
3563 rtx part = adjust_address (dest, BLKmode, offset);
3564 if (!mips_expand_unaligned_store (part, regs[i], bits, 0))
3568 /* Mop up any left-over bytes. */
3569 if (offset < length)
3571 src = adjust_address (src, BLKmode, offset);
3572 dest = adjust_address (dest, BLKmode, offset);
3573 move_by_pieces (dest, src, length - offset,
3574 MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), 0);
3578 #define MAX_MOVE_REGS 4
3579 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3582 /* Helper function for doing a loop-based block operation on memory
3583 reference MEM. Each iteration of the loop will operate on LENGTH
3586 Create a new base register for use within the loop and point it to
3587 the start of MEM. Create a new memory reference that uses this
3588 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
3591 mips_adjust_block_mem (rtx mem, HOST_WIDE_INT length,
3592 rtx *loop_reg, rtx *loop_mem)
3594 *loop_reg = copy_addr_to_reg (XEXP (mem, 0));
3596 /* Although the new mem does not refer to a known location,
3597 it does keep up to LENGTH bytes of alignment. */
3598 *loop_mem = change_address (mem, BLKmode, *loop_reg);
3599 set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT));
3603 /* Move LENGTH bytes from SRC to DEST using a loop that moves MAX_MOVE_BYTES
3604 per iteration. LENGTH must be at least MAX_MOVE_BYTES. Assume that the
3605 memory regions do not overlap. */
3608 mips_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length)
3610 rtx label, src_reg, dest_reg, final_src;
3611 HOST_WIDE_INT leftover;
3613 leftover = length % MAX_MOVE_BYTES;
3616 /* Create registers and memory references for use within the loop. */
3617 mips_adjust_block_mem (src, MAX_MOVE_BYTES, &src_reg, &src);
3618 mips_adjust_block_mem (dest, MAX_MOVE_BYTES, &dest_reg, &dest);
3620 /* Calculate the value that SRC_REG should have after the last iteration
3622 final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length),
3625 /* Emit the start of the loop. */
3626 label = gen_label_rtx ();
3629 /* Emit the loop body. */
3630 mips_block_move_straight (dest, src, MAX_MOVE_BYTES);
3632 /* Move on to the next block. */
3633 emit_move_insn (src_reg, plus_constant (src_reg, MAX_MOVE_BYTES));
3634 emit_move_insn (dest_reg, plus_constant (dest_reg, MAX_MOVE_BYTES));
3636 /* Emit the loop condition. */
3637 if (Pmode == DImode)
3638 emit_insn (gen_cmpdi (src_reg, final_src));
3640 emit_insn (gen_cmpsi (src_reg, final_src));
3641 emit_jump_insn (gen_bne (label));
3643 /* Mop up any left-over bytes. */
3645 mips_block_move_straight (dest, src, leftover);
3648 /* Expand a movmemsi instruction. */
3651 mips_expand_block_move (rtx dest, rtx src, rtx length)
3653 if (GET_CODE (length) == CONST_INT)
3655 if (INTVAL (length) <= 2 * MAX_MOVE_BYTES)
3657 mips_block_move_straight (dest, src, INTVAL (length));
3662 mips_block_move_loop (dest, src, INTVAL (length));
3669 /* Argument support functions. */
3671 /* Initialize CUMULATIVE_ARGS for a function. */
3674 init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
3675 rtx libname ATTRIBUTE_UNUSED)
3677 static CUMULATIVE_ARGS zero_cum;
3678 tree param, next_param;
3681 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
3683 /* Determine if this function has variable arguments. This is
3684 indicated by the last argument being 'void_type_mode' if there
3685 are no variable arguments. The standard MIPS calling sequence
3686 passes all arguments in the general purpose registers in this case. */
3688 for (param = fntype ? TYPE_ARG_TYPES (fntype) : 0;
3689 param != 0; param = next_param)
3691 next_param = TREE_CHAIN (param);
3692 if (next_param == 0 && TREE_VALUE (param) != void_type_node)
3693 cum->gp_reg_found = 1;
3698 /* Fill INFO with information about a single argument. CUM is the
3699 cumulative state for earlier arguments. MODE is the mode of this
3700 argument and TYPE is its type (if known). NAMED is true if this
3701 is a named (fixed) argument rather than a variable one. */
3704 mips_arg_info (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
3705 tree type, int named, struct mips_arg_info *info)
3707 bool doubleword_aligned_p;
3708 unsigned int num_bytes, num_words, max_regs;
3710 /* Work out the size of the argument. */
3711 num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
3712 num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3714 /* Decide whether it should go in a floating-point register, assuming
3715 one is free. Later code checks for availability.
3717 The checks against UNITS_PER_FPVALUE handle the soft-float and
3718 single-float cases. */
3722 /* The EABI conventions have traditionally been defined in terms
3723 of TYPE_MODE, regardless of the actual type. */
3724 info->fpr_p = ((GET_MODE_CLASS (mode) == MODE_FLOAT
3725 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3726 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
3731 /* Only leading floating-point scalars are passed in
3732 floating-point registers. We also handle vector floats the same
3733 say, which is OK because they are not covered by the standard ABI. */
3734 info->fpr_p = (!cum->gp_reg_found
3735 && cum->arg_number < 2
3736 && (type == 0 || SCALAR_FLOAT_TYPE_P (type)
3737 || VECTOR_FLOAT_TYPE_P (type))
3738 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3739 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3740 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
3745 /* Scalar and complex floating-point types are passed in
3746 floating-point registers. */
3747 info->fpr_p = (named
3748 && (type == 0 || FLOAT_TYPE_P (type))
3749 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3750 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3751 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3752 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_FPVALUE);
3754 /* ??? According to the ABI documentation, the real and imaginary
3755 parts of complex floats should be passed in individual registers.
3756 The real and imaginary parts of stack arguments are supposed
3757 to be contiguous and there should be an extra word of padding
3760 This has two problems. First, it makes it impossible to use a
3761 single "void *" va_list type, since register and stack arguments
3762 are passed differently. (At the time of writing, MIPSpro cannot
3763 handle complex float varargs correctly.) Second, it's unclear
3764 what should happen when there is only one register free.
3766 For now, we assume that named complex floats should go into FPRs
3767 if there are two FPRs free, otherwise they should be passed in the
3768 same way as a struct containing two floats. */
3770 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3771 && GET_MODE_UNIT_SIZE (mode) < UNITS_PER_FPVALUE)
3773 if (cum->num_gprs >= MAX_ARGS_IN_REGISTERS - 1)
3774 info->fpr_p = false;
3784 /* See whether the argument has doubleword alignment. */
3785 doubleword_aligned_p = FUNCTION_ARG_BOUNDARY (mode, type) > BITS_PER_WORD;
3787 /* Set REG_OFFSET to the register count we're interested in.
3788 The EABI allocates the floating-point registers separately,
3789 but the other ABIs allocate them like integer registers. */
3790 info->reg_offset = (mips_abi == ABI_EABI && info->fpr_p
3794 /* Advance to an even register if the argument is doubleword-aligned. */
3795 if (doubleword_aligned_p)
3796 info->reg_offset += info->reg_offset & 1;
3798 /* Work out the offset of a stack argument. */
3799 info->stack_offset = cum->stack_words;
3800 if (doubleword_aligned_p)
3801 info->stack_offset += info->stack_offset & 1;
3803 max_regs = MAX_ARGS_IN_REGISTERS - info->reg_offset;
3805 /* Partition the argument between registers and stack. */
3806 info->reg_words = MIN (num_words, max_regs);
3807 info->stack_words = num_words - info->reg_words;
3811 /* Implement FUNCTION_ARG_ADVANCE. */
3814 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3815 tree type, int named)
3817 struct mips_arg_info info;
3819 mips_arg_info (cum, mode, type, named, &info);
3822 cum->gp_reg_found = true;
3824 /* See the comment above the cumulative args structure in mips.h
3825 for an explanation of what this code does. It assumes the O32
3826 ABI, which passes at most 2 arguments in float registers. */
3827 if (cum->arg_number < 2 && info.fpr_p)
3828 cum->fp_code += (mode == SFmode ? 1 : 2) << ((cum->arg_number - 1) * 2);
3830 if (mips_abi != ABI_EABI || !info.fpr_p)
3831 cum->num_gprs = info.reg_offset + info.reg_words;
3832 else if (info.reg_words > 0)
3833 cum->num_fprs += FP_INC;
3835 if (info.stack_words > 0)
3836 cum->stack_words = info.stack_offset + info.stack_words;
3841 /* Implement FUNCTION_ARG. */
3844 function_arg (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
3845 tree type, int named)
3847 struct mips_arg_info info;
3849 /* We will be called with a mode of VOIDmode after the last argument
3850 has been seen. Whatever we return will be passed to the call
3851 insn. If we need a mips16 fp_code, return a REG with the code
3852 stored as the mode. */
3853 if (mode == VOIDmode)
3855 if (TARGET_MIPS16 && cum->fp_code != 0)
3856 return gen_rtx_REG ((enum machine_mode) cum->fp_code, 0);
3862 mips_arg_info (cum, mode, type, named, &info);
3864 /* Return straight away if the whole argument is passed on the stack. */
3865 if (info.reg_offset == MAX_ARGS_IN_REGISTERS)
3869 && TREE_CODE (type) == RECORD_TYPE
3871 && TYPE_SIZE_UNIT (type)
3872 && host_integerp (TYPE_SIZE_UNIT (type), 1)
3875 /* The Irix 6 n32/n64 ABIs say that if any 64 bit chunk of the
3876 structure contains a double in its entirety, then that 64 bit
3877 chunk is passed in a floating point register. */
3880 /* First check to see if there is any such field. */
3881 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3882 if (TREE_CODE (field) == FIELD_DECL
3883 && TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3884 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD
3885 && host_integerp (bit_position (field), 0)
3886 && int_bit_position (field) % BITS_PER_WORD == 0)
3891 /* Now handle the special case by returning a PARALLEL
3892 indicating where each 64 bit chunk goes. INFO.REG_WORDS
3893 chunks are passed in registers. */
3895 HOST_WIDE_INT bitpos;
3898 /* assign_parms checks the mode of ENTRY_PARM, so we must
3899 use the actual mode here. */
3900 ret = gen_rtx_PARALLEL (mode, rtvec_alloc (info.reg_words));
3903 field = TYPE_FIELDS (type);
3904 for (i = 0; i < info.reg_words; i++)
3908 for (; field; field = TREE_CHAIN (field))
3909 if (TREE_CODE (field) == FIELD_DECL
3910 && int_bit_position (field) >= bitpos)
3914 && int_bit_position (field) == bitpos
3915 && TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3916 && !TARGET_SOFT_FLOAT
3917 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD)
3918 reg = gen_rtx_REG (DFmode, FP_ARG_FIRST + info.reg_offset + i);
3920 reg = gen_rtx_REG (DImode, GP_ARG_FIRST + info.reg_offset + i);
3923 = gen_rtx_EXPR_LIST (VOIDmode, reg,
3924 GEN_INT (bitpos / BITS_PER_UNIT));
3926 bitpos += BITS_PER_WORD;
3932 /* Handle the n32/n64 conventions for passing complex floating-point
3933 arguments in FPR pairs. The real part goes in the lower register
3934 and the imaginary part goes in the upper register. */
3937 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3940 enum machine_mode inner;
3943 inner = GET_MODE_INNER (mode);
3944 reg = FP_ARG_FIRST + info.reg_offset;
3945 if (info.reg_words * UNITS_PER_WORD == GET_MODE_SIZE (inner))
3947 /* Real part in registers, imaginary part on stack. */
3948 gcc_assert (info.stack_words == info.reg_words);
3949 return gen_rtx_REG (inner, reg);
3953 gcc_assert (info.stack_words == 0);
3954 real = gen_rtx_EXPR_LIST (VOIDmode,
3955 gen_rtx_REG (inner, reg),
3957 imag = gen_rtx_EXPR_LIST (VOIDmode,
3959 reg + info.reg_words / 2),
3960 GEN_INT (GET_MODE_SIZE (inner)));
3961 return gen_rtx_PARALLEL (mode, gen_rtvec (2, real, imag));
3966 return gen_rtx_REG (mode, GP_ARG_FIRST + info.reg_offset);
3967 else if (info.reg_offset == 1)
3968 /* This code handles the special o32 case in which the second word
3969 of the argument structure is passed in floating-point registers. */
3970 return gen_rtx_REG (mode, FP_ARG_FIRST + FP_INC);
3972 return gen_rtx_REG (mode, FP_ARG_FIRST + info.reg_offset);
3976 /* Implement TARGET_ARG_PARTIAL_BYTES. */
3979 mips_arg_partial_bytes (CUMULATIVE_ARGS *cum,
3980 enum machine_mode mode, tree type, bool named)
3982 struct mips_arg_info info;
3984 mips_arg_info (cum, mode, type, named, &info);
3985 return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0;
3989 /* Implement FUNCTION_ARG_BOUNDARY. Every parameter gets at least
3990 PARM_BOUNDARY bits of alignment, but will be given anything up
3991 to STACK_BOUNDARY bits if the type requires it. */
3994 function_arg_boundary (enum machine_mode mode, tree type)
3996 unsigned int alignment;
3998 alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode);
3999 if (alignment < PARM_BOUNDARY)
4000 alignment = PARM_BOUNDARY;
4001 if (alignment > STACK_BOUNDARY)
4002 alignment = STACK_BOUNDARY;
4006 /* Return true if FUNCTION_ARG_PADDING (MODE, TYPE) should return
4007 upward rather than downward. In other words, return true if the
4008 first byte of the stack slot has useful data, false if the last
4012 mips_pad_arg_upward (enum machine_mode mode, tree type)
4014 /* On little-endian targets, the first byte of every stack argument
4015 is passed in the first byte of the stack slot. */
4016 if (!BYTES_BIG_ENDIAN)
4019 /* Otherwise, integral types are padded downward: the last byte of a
4020 stack argument is passed in the last byte of the stack slot. */
4022 ? INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)
4023 : GET_MODE_CLASS (mode) == MODE_INT)
4026 /* Big-endian o64 pads floating-point arguments downward. */
4027 if (mips_abi == ABI_O64)
4028 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
4031 /* Other types are padded upward for o32, o64, n32 and n64. */
4032 if (mips_abi != ABI_EABI)
4035 /* Arguments smaller than a stack slot are padded downward. */
4036 if (mode != BLKmode)
4037 return (GET_MODE_BITSIZE (mode) >= PARM_BOUNDARY);
4039 return (int_size_in_bytes (type) >= (PARM_BOUNDARY / BITS_PER_UNIT));
4043 /* Likewise BLOCK_REG_PADDING (MODE, TYPE, ...). Return !BYTES_BIG_ENDIAN
4044 if the least significant byte of the register has useful data. Return
4045 the opposite if the most significant byte does. */
4048 mips_pad_reg_upward (enum machine_mode mode, tree type)
4050 /* No shifting is required for floating-point arguments. */
4051 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
4052 return !BYTES_BIG_ENDIAN;
4054 /* Otherwise, apply the same padding to register arguments as we do
4055 to stack arguments. */
4056 return mips_pad_arg_upward (mode, type);
4060 mips_setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,<