1 /* Subroutines used for MIPS code generation.
2 Copyright (C) 1989, 1990, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by A. Lichnewsky, lich@inria.inria.fr.
5 Changes by Michael Meissner, meissner@osf.org.
6 64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 Brendan Eich, brendan@microunity.com.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GCC is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING. If not, write to
23 the Free Software Foundation, 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. */
28 #include "coretypes.h"
33 #include "hard-reg-set.h"
35 #include "insn-config.h"
36 #include "conditions.h"
37 #include "insn-attr.h"
53 #include "target-def.h"
54 #include "integrate.h"
55 #include "langhooks.h"
56 #include "cfglayout.h"
57 #include "sched-int.h"
58 #include "tree-gimple.h"
60 /* True if X is an unspec wrapper around a SYMBOL_REF or LABEL_REF. */
61 #define UNSPEC_ADDRESS_P(X) \
62 (GET_CODE (X) == UNSPEC \
63 && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \
64 && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)
66 /* Extract the symbol or label from UNSPEC wrapper X. */
67 #define UNSPEC_ADDRESS(X) \
70 /* Extract the symbol type from UNSPEC wrapper X. */
71 #define UNSPEC_ADDRESS_TYPE(X) \
72 ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))
74 /* The maximum distance between the top of the stack frame and the
75 value $sp has when we save & restore registers.
77 Use a maximum gap of 0x100 in the mips16 case. We can then use
78 unextended instructions to save and restore registers, and to
79 allocate and deallocate the top part of the frame.
81 The value in the !mips16 case must be a SMALL_OPERAND and must
82 preserve the maximum stack alignment. */
83 #define MIPS_MAX_FIRST_STACK_STEP (TARGET_MIPS16 ? 0x100 : 0x7ff0)
85 /* True if INSN is a mips.md pattern or asm statement. */
86 #define USEFUL_INSN_P(INSN) \
88 && GET_CODE (PATTERN (INSN)) != USE \
89 && GET_CODE (PATTERN (INSN)) != CLOBBER \
90 && GET_CODE (PATTERN (INSN)) != ADDR_VEC \
91 && GET_CODE (PATTERN (INSN)) != ADDR_DIFF_VEC)
93 /* If INSN is a delayed branch sequence, return the first instruction
94 in the sequence, otherwise return INSN itself. */
95 #define SEQ_BEGIN(INSN) \
96 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
97 ? XVECEXP (PATTERN (INSN), 0, 0) \
100 /* Likewise for the last instruction in a delayed branch sequence. */
101 #define SEQ_END(INSN) \
102 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
103 ? XVECEXP (PATTERN (INSN), 0, XVECLEN (PATTERN (INSN), 0) - 1) \
106 /* Execute the following loop body with SUBINSN set to each instruction
107 between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */
108 #define FOR_EACH_SUBINSN(SUBINSN, INSN) \
109 for ((SUBINSN) = SEQ_BEGIN (INSN); \
110 (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \
111 (SUBINSN) = NEXT_INSN (SUBINSN))
113 /* Classifies an address.
116 A natural register + offset address. The register satisfies
117 mips_valid_base_register_p and the offset is a const_arith_operand.
120 A LO_SUM rtx. The first operand is a valid base register and
121 the second operand is a symbolic address.
124 A signed 16-bit constant address.
127 A constant symbolic address (equivalent to CONSTANT_SYMBOLIC). */
128 enum mips_address_type {
135 /* Classifies the prototype of a builtin function. */
136 enum mips_function_type
138 MIPS_V2SF_FTYPE_V2SF,
139 MIPS_V2SF_FTYPE_V2SF_V2SF,
140 MIPS_V2SF_FTYPE_V2SF_V2SF_INT,
141 MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF,
142 MIPS_V2SF_FTYPE_SF_SF,
143 MIPS_INT_FTYPE_V2SF_V2SF,
144 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF,
145 MIPS_INT_FTYPE_SF_SF,
146 MIPS_INT_FTYPE_DF_DF,
157 /* Specifies how a builtin function should be converted into rtl. */
158 enum mips_builtin_type
160 /* The builtin corresponds directly to an .md pattern. The return
161 value is mapped to operand 0 and the arguments are mapped to
162 operands 1 and above. */
165 /* The builtin corresponds to a comparison instruction followed by
166 a mips_cond_move_tf_ps pattern. The first two arguments are the
167 values to compare and the second two arguments are the vector
168 operands for the movt.ps or movf.ps instruction (in assembly order). */
172 /* The builtin corresponds to a V2SF comparison instruction. Operand 0
173 of this instruction is the result of the comparison, which has mode
174 CCV2 or CCV4. The function arguments are mapped to operands 1 and
175 above. The function's return value is an SImode boolean that is
176 true under the following conditions:
178 MIPS_BUILTIN_CMP_ANY: one of the registers is true
179 MIPS_BUILTIN_CMP_ALL: all of the registers are true
180 MIPS_BUILTIN_CMP_LOWER: the first register is true
181 MIPS_BUILTIN_CMP_UPPER: the second register is true. */
182 MIPS_BUILTIN_CMP_ANY,
183 MIPS_BUILTIN_CMP_ALL,
184 MIPS_BUILTIN_CMP_UPPER,
185 MIPS_BUILTIN_CMP_LOWER,
187 /* As above, but the instruction only sets a single $fcc register. */
188 MIPS_BUILTIN_CMP_SINGLE
191 /* Invokes MACRO (COND) for each c.cond.fmt condition. */
192 #define MIPS_FP_CONDITIONS(MACRO) \
210 /* Enumerates the codes above as MIPS_FP_COND_<X>. */
211 #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X
212 enum mips_fp_condition {
213 MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)
216 /* Index X provides the string representation of MIPS_FP_COND_<X>. */
217 #define STRINGIFY(X) #X
218 static const char *const mips_fp_conditions[] = {
219 MIPS_FP_CONDITIONS (STRINGIFY)
222 /* A function to save or store a register. The first argument is the
223 register and the second is the stack slot. */
224 typedef void (*mips_save_restore_fn) (rtx, rtx);
226 struct mips16_constant;
227 struct mips_arg_info;
228 struct mips_address_info;
229 struct mips_integer_op;
232 static enum mips_symbol_type mips_classify_symbol (rtx);
233 static void mips_split_const (rtx, rtx *, HOST_WIDE_INT *);
234 static bool mips_offset_within_object_p (rtx, HOST_WIDE_INT);
235 static bool mips_valid_base_register_p (rtx, enum machine_mode, int);
236 static bool mips_symbolic_address_p (enum mips_symbol_type, enum machine_mode);
237 static bool mips_classify_address (struct mips_address_info *, rtx,
238 enum machine_mode, int);
239 static bool mips_cannot_force_const_mem (rtx);
240 static int mips_symbol_insns (enum mips_symbol_type);
241 static bool mips16_unextended_reference_p (enum machine_mode mode, rtx, rtx);
242 static rtx mips_force_temporary (rtx, rtx);
243 static rtx mips_split_symbol (rtx, rtx);
244 static rtx mips_unspec_offset_high (rtx, rtx, rtx, enum mips_symbol_type);
245 static rtx mips_add_offset (rtx, rtx, HOST_WIDE_INT);
246 static unsigned int mips_build_shift (struct mips_integer_op *, HOST_WIDE_INT);
247 static unsigned int mips_build_lower (struct mips_integer_op *,
248 unsigned HOST_WIDE_INT);
249 static unsigned int mips_build_integer (struct mips_integer_op *,
250 unsigned HOST_WIDE_INT);
251 static void mips_move_integer (rtx, unsigned HOST_WIDE_INT);
252 static void mips_legitimize_const_move (enum machine_mode, rtx, rtx);
253 static int m16_check_op (rtx, int, int, int);
254 static bool mips_rtx_costs (rtx, int, int, int *);
255 static int mips_address_cost (rtx);
256 static void mips_emit_compare (enum rtx_code *, rtx *, rtx *, bool);
257 static void mips_load_call_address (rtx, rtx, int);
258 static bool mips_function_ok_for_sibcall (tree, tree);
259 static void mips_block_move_straight (rtx, rtx, HOST_WIDE_INT);
260 static void mips_adjust_block_mem (rtx, HOST_WIDE_INT, rtx *, rtx *);
261 static void mips_block_move_loop (rtx, rtx, HOST_WIDE_INT);
262 static void mips_arg_info (const CUMULATIVE_ARGS *, enum machine_mode,
263 tree, int, struct mips_arg_info *);
264 static bool mips_get_unaligned_mem (rtx *, unsigned int, int, rtx *, rtx *);
265 static void mips_set_architecture (const struct mips_cpu_info *);
266 static void mips_set_tune (const struct mips_cpu_info *);
267 static bool mips_handle_option (size_t, const char *, int);
268 static struct machine_function *mips_init_machine_status (void);
269 static void print_operand_reloc (FILE *, rtx, const char **);
271 static void irix_output_external_libcall (rtx);
273 static void mips_file_start (void);
274 static void mips_file_end (void);
275 static bool mips_rewrite_small_data_p (rtx);
276 static int mips_small_data_pattern_1 (rtx *, void *);
277 static int mips_rewrite_small_data_1 (rtx *, void *);
278 static bool mips_function_has_gp_insn (void);
279 static unsigned int mips_global_pointer (void);
280 static bool mips_save_reg_p (unsigned int);
281 static void mips_save_restore_reg (enum machine_mode, int, HOST_WIDE_INT,
282 mips_save_restore_fn);
283 static void mips_for_each_saved_reg (HOST_WIDE_INT, mips_save_restore_fn);
284 static void mips_output_cplocal (void);
285 static void mips_emit_loadgp (void);
286 static void mips_output_function_prologue (FILE *, HOST_WIDE_INT);
287 static void mips_set_frame_expr (rtx);
288 static rtx mips_frame_set (rtx, rtx);
289 static void mips_save_reg (rtx, rtx);
290 static void mips_output_function_epilogue (FILE *, HOST_WIDE_INT);
291 static void mips_restore_reg (rtx, rtx);
292 static void mips_output_mi_thunk (FILE *, tree, HOST_WIDE_INT,
293 HOST_WIDE_INT, tree);
294 static int symbolic_expression_p (rtx);
295 static void mips_select_rtx_section (enum machine_mode, rtx,
296 unsigned HOST_WIDE_INT);
297 static void mips_function_rodata_section (tree);
298 static bool mips_in_small_data_p (tree);
299 static int mips_fpr_return_fields (tree, tree *);
300 static bool mips_return_in_msb (tree);
301 static rtx mips_return_fpr_pair (enum machine_mode mode,
302 enum machine_mode mode1, HOST_WIDE_INT,
303 enum machine_mode mode2, HOST_WIDE_INT);
304 static rtx mips16_gp_pseudo_reg (void);
305 static void mips16_fp_args (FILE *, int, int);
306 static void build_mips16_function_stub (FILE *);
307 static rtx dump_constants_1 (enum machine_mode, rtx, rtx);
308 static void dump_constants (struct mips16_constant *, rtx);
309 static int mips16_insn_length (rtx);
310 static int mips16_rewrite_pool_refs (rtx *, void *);
311 static void mips16_lay_out_constants (void);
312 static void mips_sim_reset (struct mips_sim *);
313 static void mips_sim_init (struct mips_sim *, state_t);
314 static void mips_sim_next_cycle (struct mips_sim *);
315 static void mips_sim_wait_reg (struct mips_sim *, rtx, rtx);
316 static int mips_sim_wait_regs_2 (rtx *, void *);
317 static void mips_sim_wait_regs_1 (rtx *, void *);
318 static void mips_sim_wait_regs (struct mips_sim *, rtx);
319 static void mips_sim_wait_units (struct mips_sim *, rtx);
320 static void mips_sim_wait_insn (struct mips_sim *, rtx);
321 static void mips_sim_record_set (rtx, rtx, void *);
322 static void mips_sim_issue_insn (struct mips_sim *, rtx);
323 static void mips_sim_issue_nop (struct mips_sim *);
324 static void mips_sim_finish_insn (struct mips_sim *, rtx);
325 static void vr4130_avoid_branch_rt_conflict (rtx);
326 static void vr4130_align_insns (void);
327 static void mips_avoid_hazard (rtx, rtx, int *, rtx *, rtx);
328 static void mips_avoid_hazards (void);
329 static void mips_reorg (void);
330 static bool mips_strict_matching_cpu_name_p (const char *, const char *);
331 static bool mips_matching_cpu_name_p (const char *, const char *);
332 static const struct mips_cpu_info *mips_parse_cpu (const char *);
333 static const struct mips_cpu_info *mips_cpu_info_from_isa (int);
334 static bool mips_return_in_memory (tree, tree);
335 static bool mips_strict_argument_naming (CUMULATIVE_ARGS *);
336 static void mips_macc_chains_record (rtx);
337 static void mips_macc_chains_reorder (rtx *, int);
338 static void vr4130_true_reg_dependence_p_1 (rtx, rtx, void *);
339 static bool vr4130_true_reg_dependence_p (rtx);
340 static bool vr4130_swap_insns_p (rtx, rtx);
341 static void vr4130_reorder (rtx *, int);
342 static void mips_promote_ready (rtx *, int, int);
343 static int mips_sched_reorder (FILE *, int, rtx *, int *, int);
344 static int mips_variable_issue (FILE *, int, rtx, int);
345 static int mips_adjust_cost (rtx, rtx, rtx, int);
346 static int mips_issue_rate (void);
347 static int mips_multipass_dfa_lookahead (void);
348 static void mips_init_libfuncs (void);
349 static void mips_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
351 static tree mips_build_builtin_va_list (void);
352 static tree mips_gimplify_va_arg_expr (tree, tree, tree *, tree *);
353 static bool mips_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode mode,
355 static bool mips_callee_copies (CUMULATIVE_ARGS *, enum machine_mode mode,
357 static int mips_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode mode,
359 static bool mips_valid_pointer_mode (enum machine_mode);
360 static bool mips_vector_mode_supported_p (enum machine_mode);
361 static rtx mips_prepare_builtin_arg (enum insn_code, unsigned int, tree *);
362 static rtx mips_prepare_builtin_target (enum insn_code, unsigned int, rtx);
363 static rtx mips_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
364 static void mips_init_builtins (void);
365 static rtx mips_expand_builtin_direct (enum insn_code, rtx, tree);
366 static rtx mips_expand_builtin_movtf (enum mips_builtin_type,
367 enum insn_code, enum mips_fp_condition,
369 static rtx mips_expand_builtin_compare (enum mips_builtin_type,
370 enum insn_code, enum mips_fp_condition,
373 /* Structure to be filled in by compute_frame_size with register
374 save masks, and offsets for the current function. */
376 struct mips_frame_info GTY(())
378 HOST_WIDE_INT total_size; /* # bytes that the entire frame takes up */
379 HOST_WIDE_INT var_size; /* # bytes that variables take up */
380 HOST_WIDE_INT args_size; /* # bytes that outgoing arguments take up */
381 HOST_WIDE_INT cprestore_size; /* # bytes that the .cprestore slot takes up */
382 HOST_WIDE_INT gp_reg_size; /* # bytes needed to store gp regs */
383 HOST_WIDE_INT fp_reg_size; /* # bytes needed to store fp regs */
384 unsigned int mask; /* mask of saved gp registers */
385 unsigned int fmask; /* mask of saved fp registers */
386 HOST_WIDE_INT gp_save_offset; /* offset from vfp to store gp registers */
387 HOST_WIDE_INT fp_save_offset; /* offset from vfp to store fp registers */
388 HOST_WIDE_INT gp_sp_offset; /* offset from new sp to store gp registers */
389 HOST_WIDE_INT fp_sp_offset; /* offset from new sp to store fp registers */
390 bool initialized; /* true if frame size already calculated */
391 int num_gp; /* number of gp registers saved */
392 int num_fp; /* number of fp registers saved */
395 struct machine_function GTY(()) {
396 /* Pseudo-reg holding the value of $28 in a mips16 function which
397 refers to GP relative global variables. */
398 rtx mips16_gp_pseudo_rtx;
400 /* Current frame information, calculated by compute_frame_size. */
401 struct mips_frame_info frame;
403 /* The register to use as the global pointer within this function. */
404 unsigned int global_pointer;
406 /* True if mips_adjust_insn_length should ignore an instruction's
408 bool ignore_hazard_length_p;
410 /* True if the whole function is suitable for .set noreorder and
412 bool all_noreorder_p;
414 /* True if the function is known to have an instruction that needs $gp. */
418 /* Information about a single argument. */
421 /* True if the argument is passed in a floating-point register, or
422 would have been if we hadn't run out of registers. */
425 /* The number of words passed in registers, rounded up. */
426 unsigned int reg_words;
428 /* For EABI, the offset of the first register from GP_ARG_FIRST or
429 FP_ARG_FIRST. For other ABIs, the offset of the first register from
430 the start of the ABI's argument structure (see the CUMULATIVE_ARGS
431 comment for details).
433 The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely
435 unsigned int reg_offset;
437 /* The number of words that must be passed on the stack, rounded up. */
438 unsigned int stack_words;
440 /* The offset from the start of the stack overflow area of the argument's
441 first stack word. Only meaningful when STACK_WORDS is nonzero. */
442 unsigned int stack_offset;
446 /* Information about an address described by mips_address_type.
452 REG is the base register and OFFSET is the constant offset.
455 REG is the register that contains the high part of the address,
456 OFFSET is the symbolic address being referenced and SYMBOL_TYPE
457 is the type of OFFSET's symbol.
460 SYMBOL_TYPE is the type of symbol being referenced. */
462 struct mips_address_info
464 enum mips_address_type type;
467 enum mips_symbol_type symbol_type;
471 /* One stage in a constant building sequence. These sequences have
475 A = A CODE[1] VALUE[1]
476 A = A CODE[2] VALUE[2]
479 where A is an accumulator, each CODE[i] is a binary rtl operation
480 and each VALUE[i] is a constant integer. */
481 struct mips_integer_op {
483 unsigned HOST_WIDE_INT value;
487 /* The largest number of operations needed to load an integer constant.
488 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
489 When the lowest bit is clear, we can try, but reject a sequence with
490 an extra SLL at the end. */
491 #define MIPS_MAX_INTEGER_OPS 7
494 /* Global variables for machine-dependent things. */
496 /* Threshold for data being put into the small data/bss area, instead
497 of the normal data area. */
498 int mips_section_threshold = -1;
500 /* Count the number of .file directives, so that .loc is up to date. */
501 int num_source_filenames = 0;
503 /* Count the number of sdb related labels are generated (to find block
504 start and end boundaries). */
505 int sdb_label_count = 0;
507 /* Next label # for each statement for Silicon Graphics IRIS systems. */
510 /* Linked list of all externals that are to be emitted when optimizing
511 for the global pointer if they haven't been declared by the end of
512 the program with an appropriate .comm or initialization. */
514 struct extern_list GTY (())
516 struct extern_list *next; /* next external */
517 const char *name; /* name of the external */
518 int size; /* size in bytes */
521 static GTY (()) struct extern_list *extern_head = 0;
523 /* Name of the file containing the current function. */
524 const char *current_function_file = "";
526 /* Number of nested .set noreorder, noat, nomacro, and volatile requests. */
532 /* The next branch instruction is a branch likely, not branch normal. */
533 int mips_branch_likely;
535 /* The operands passed to the last cmpMM expander. */
538 /* The target cpu for code generation. */
539 enum processor_type mips_arch;
540 const struct mips_cpu_info *mips_arch_info;
542 /* The target cpu for optimization and scheduling. */
543 enum processor_type mips_tune;
544 const struct mips_cpu_info *mips_tune_info;
546 /* Which instruction set architecture to use. */
549 /* Which ABI to use. */
550 int mips_abi = MIPS_ABI_DEFAULT;
552 /* Whether we are generating mips16 hard float code. In mips16 mode
553 we always set TARGET_SOFT_FLOAT; this variable is nonzero if
554 -msoft-float was not specified by the user, which means that we
555 should arrange to call mips32 hard floating point code. */
556 int mips16_hard_float;
558 /* The arguments passed to -march and -mtune. */
559 static const char *mips_arch_string;
560 static const char *mips_tune_string;
562 /* The architecture selected by -mipsN. */
563 static const struct mips_cpu_info *mips_isa_info;
565 const char *mips_cache_flush_func = CACHE_FLUSH_FUNC;
567 /* If TRUE, we split addresses into their high and low parts in the RTL. */
568 int mips_split_addresses;
570 /* Mode used for saving/restoring general purpose registers. */
571 static enum machine_mode gpr_mode;
573 /* Array giving truth value on whether or not a given hard register
574 can support a given mode. */
575 char mips_hard_regno_mode_ok[(int)MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
577 /* List of all MIPS punctuation characters used by print_operand. */
578 char mips_print_operand_punct[256];
580 /* Map GCC register number to debugger register number. */
581 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
583 /* A copy of the original flag_delayed_branch: see override_options. */
584 static int mips_flag_delayed_branch;
586 static GTY (()) int mips_output_filename_first_time = 1;
588 /* mips_split_p[X] is true if symbols of type X can be split by
589 mips_split_symbol(). */
590 static bool mips_split_p[NUM_SYMBOL_TYPES];
592 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
593 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
594 if they are matched by a special .md file pattern. */
595 static const char *mips_lo_relocs[NUM_SYMBOL_TYPES];
597 /* Likewise for HIGHs. */
598 static const char *mips_hi_relocs[NUM_SYMBOL_TYPES];
600 /* Map hard register number to register class */
601 const enum reg_class mips_regno_to_class[] =
603 LEA_REGS, LEA_REGS, M16_NA_REGS, V1_REG,
604 M16_REGS, M16_REGS, M16_REGS, M16_REGS,
605 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
606 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
607 M16_NA_REGS, M16_NA_REGS, LEA_REGS, LEA_REGS,
608 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
609 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
610 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
611 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
612 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
613 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
614 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
615 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
616 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
617 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
618 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
619 HI_REG, LO_REG, NO_REGS, ST_REGS,
620 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
621 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
622 NO_REGS, ALL_REGS, ALL_REGS, NO_REGS,
623 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
624 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
625 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
626 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
627 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
628 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
629 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
630 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
631 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
632 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
633 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
634 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
635 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
636 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
637 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
638 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
639 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
640 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
641 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
642 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
643 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
644 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
645 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
646 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS
649 /* Map register constraint character to register class. */
650 enum reg_class mips_char_to_class[256];
652 /* A table describing all the processors gcc knows about. Names are
653 matched in the order listed. The first mention of an ISA level is
654 taken as the canonical name for that ISA.
656 To ease comparison, please keep this table in the same order as
657 gas's mips_cpu_info_table[]. */
658 const struct mips_cpu_info mips_cpu_info_table[] = {
659 /* Entries for generic ISAs */
660 { "mips1", PROCESSOR_R3000, 1 },
661 { "mips2", PROCESSOR_R6000, 2 },
662 { "mips3", PROCESSOR_R4000, 3 },
663 { "mips4", PROCESSOR_R8000, 4 },
664 { "mips32", PROCESSOR_4KC, 32 },
665 { "mips32r2", PROCESSOR_M4K, 33 },
666 { "mips64", PROCESSOR_5KC, 64 },
669 { "r3000", PROCESSOR_R3000, 1 },
670 { "r2000", PROCESSOR_R3000, 1 }, /* = r3000 */
671 { "r3900", PROCESSOR_R3900, 1 },
674 { "r6000", PROCESSOR_R6000, 2 },
677 { "r4000", PROCESSOR_R4000, 3 },
678 { "vr4100", PROCESSOR_R4100, 3 },
679 { "vr4111", PROCESSOR_R4111, 3 },
680 { "vr4120", PROCESSOR_R4120, 3 },
681 { "vr4130", PROCESSOR_R4130, 3 },
682 { "vr4300", PROCESSOR_R4300, 3 },
683 { "r4400", PROCESSOR_R4000, 3 }, /* = r4000 */
684 { "r4600", PROCESSOR_R4600, 3 },
685 { "orion", PROCESSOR_R4600, 3 }, /* = r4600 */
686 { "r4650", PROCESSOR_R4650, 3 },
689 { "r8000", PROCESSOR_R8000, 4 },
690 { "vr5000", PROCESSOR_R5000, 4 },
691 { "vr5400", PROCESSOR_R5400, 4 },
692 { "vr5500", PROCESSOR_R5500, 4 },
693 { "rm7000", PROCESSOR_R7000, 4 },
694 { "rm9000", PROCESSOR_R9000, 4 },
697 { "4kc", PROCESSOR_4KC, 32 },
698 { "4km", PROCESSOR_4KC, 32 }, /* = 4kc */
699 { "4kp", PROCESSOR_4KP, 32 },
701 /* MIPS32 Release 2 */
702 { "m4k", PROCESSOR_M4K, 33 },
703 { "24k", PROCESSOR_24K, 33 },
704 { "24kc", PROCESSOR_24K, 33 }, /* 24K no FPU */
705 { "24kf", PROCESSOR_24K, 33 }, /* 24K 1:2 FPU */
706 { "24kx", PROCESSOR_24KX, 33 }, /* 24K 1:1 FPU */
709 { "5kc", PROCESSOR_5KC, 64 },
710 { "20kc", PROCESSOR_20KC, 64 },
711 { "sb1", PROCESSOR_SB1, 64 },
712 { "sr71000", PROCESSOR_SR71000, 64 },
718 /* Nonzero if -march should decide the default value of MASK_SOFT_FLOAT. */
719 #ifndef MIPS_MARCH_CONTROLS_SOFT_FLOAT
720 #define MIPS_MARCH_CONTROLS_SOFT_FLOAT 0
723 /* Initialize the GCC target structure. */
724 #undef TARGET_ASM_ALIGNED_HI_OP
725 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
726 #undef TARGET_ASM_ALIGNED_SI_OP
727 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
728 #undef TARGET_ASM_ALIGNED_DI_OP
729 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
731 #undef TARGET_ASM_FUNCTION_PROLOGUE
732 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
733 #undef TARGET_ASM_FUNCTION_EPILOGUE
734 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
735 #undef TARGET_ASM_SELECT_RTX_SECTION
736 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
737 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
738 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
740 #undef TARGET_SCHED_REORDER
741 #define TARGET_SCHED_REORDER mips_sched_reorder
742 #undef TARGET_SCHED_VARIABLE_ISSUE
743 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
744 #undef TARGET_SCHED_ADJUST_COST
745 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
746 #undef TARGET_SCHED_ISSUE_RATE
747 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
748 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
749 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
750 mips_multipass_dfa_lookahead
752 #undef TARGET_DEFAULT_TARGET_FLAGS
753 #define TARGET_DEFAULT_TARGET_FLAGS \
755 | TARGET_CPU_DEFAULT \
756 | TARGET_ENDIAN_DEFAULT \
757 | TARGET_FP_EXCEPTIONS_DEFAULT \
758 | MASK_CHECK_ZERO_DIV \
760 #undef TARGET_HANDLE_OPTION
761 #define TARGET_HANDLE_OPTION mips_handle_option
763 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
764 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
766 #undef TARGET_VALID_POINTER_MODE
767 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
768 #undef TARGET_RTX_COSTS
769 #define TARGET_RTX_COSTS mips_rtx_costs
770 #undef TARGET_ADDRESS_COST
771 #define TARGET_ADDRESS_COST mips_address_cost
773 #undef TARGET_IN_SMALL_DATA_P
774 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
776 #undef TARGET_MACHINE_DEPENDENT_REORG
777 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
779 #undef TARGET_ASM_FILE_START
780 #undef TARGET_ASM_FILE_END
781 #define TARGET_ASM_FILE_START mips_file_start
782 #define TARGET_ASM_FILE_END mips_file_end
783 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
784 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
786 #undef TARGET_INIT_LIBFUNCS
787 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
789 #undef TARGET_BUILD_BUILTIN_VA_LIST
790 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
791 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
792 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
794 #undef TARGET_PROMOTE_FUNCTION_ARGS
795 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
796 #undef TARGET_PROMOTE_FUNCTION_RETURN
797 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
798 #undef TARGET_PROMOTE_PROTOTYPES
799 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
801 #undef TARGET_RETURN_IN_MEMORY
802 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
803 #undef TARGET_RETURN_IN_MSB
804 #define TARGET_RETURN_IN_MSB mips_return_in_msb
806 #undef TARGET_ASM_OUTPUT_MI_THUNK
807 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
808 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
809 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
811 #undef TARGET_SETUP_INCOMING_VARARGS
812 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
813 #undef TARGET_STRICT_ARGUMENT_NAMING
814 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
815 #undef TARGET_MUST_PASS_IN_STACK
816 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
817 #undef TARGET_PASS_BY_REFERENCE
818 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
819 #undef TARGET_CALLEE_COPIES
820 #define TARGET_CALLEE_COPIES mips_callee_copies
821 #undef TARGET_ARG_PARTIAL_BYTES
822 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
824 #undef TARGET_VECTOR_MODE_SUPPORTED_P
825 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
827 #undef TARGET_INIT_BUILTINS
828 #define TARGET_INIT_BUILTINS mips_init_builtins
829 #undef TARGET_EXPAND_BUILTIN
830 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
832 #undef TARGET_HAVE_TLS
833 #define TARGET_HAVE_TLS HAVE_AS_TLS
835 #undef TARGET_CANNOT_FORCE_CONST_MEM
836 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
838 struct gcc_target targetm = TARGET_INITIALIZER;
840 /* Classify symbol X, which must be a SYMBOL_REF or a LABEL_REF. */
842 static enum mips_symbol_type
843 mips_classify_symbol (rtx x)
845 if (GET_CODE (x) == LABEL_REF)
848 return SYMBOL_CONSTANT_POOL;
850 return SYMBOL_GOT_LOCAL;
851 return SYMBOL_GENERAL;
854 gcc_assert (GET_CODE (x) == SYMBOL_REF);
856 if (SYMBOL_REF_TLS_MODEL (x))
859 if (CONSTANT_POOL_ADDRESS_P (x))
862 return SYMBOL_CONSTANT_POOL;
865 return SYMBOL_GOT_LOCAL;
867 if (GET_MODE_SIZE (get_pool_mode (x)) <= mips_section_threshold)
868 return SYMBOL_SMALL_DATA;
870 return SYMBOL_GENERAL;
873 if (SYMBOL_REF_SMALL_P (x))
874 return SYMBOL_SMALL_DATA;
878 if (SYMBOL_REF_DECL (x) == 0)
879 return SYMBOL_REF_LOCAL_P (x) ? SYMBOL_GOT_LOCAL : SYMBOL_GOT_GLOBAL;
881 /* There are three cases to consider:
883 - o32 PIC (either with or without explicit relocs)
884 - n32/n64 PIC without explicit relocs
885 - n32/n64 PIC with explicit relocs
887 In the first case, both local and global accesses will use an
888 R_MIPS_GOT16 relocation. We must correctly predict which of
889 the two semantics (local or global) the assembler and linker
890 will apply. The choice doesn't depend on the symbol's
891 visibility, so we deliberately ignore decl_visibility and
894 In the second case, the assembler will not use R_MIPS_GOT16
895 relocations, but it chooses between local and global accesses
896 in the same way as for o32 PIC.
898 In the third case we have more freedom since both forms of
899 access will work for any kind of symbol. However, there seems
900 little point in doing things differently. */
901 if (DECL_P (SYMBOL_REF_DECL (x)) && TREE_PUBLIC (SYMBOL_REF_DECL (x)))
902 return SYMBOL_GOT_GLOBAL;
904 return SYMBOL_GOT_LOCAL;
907 return SYMBOL_GENERAL;
911 /* Split X into a base and a constant offset, storing them in *BASE
912 and *OFFSET respectively. */
915 mips_split_const (rtx x, rtx *base, HOST_WIDE_INT *offset)
919 if (GET_CODE (x) == CONST)
922 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
924 *offset += INTVAL (XEXP (x, 1));
931 /* Return true if SYMBOL is a SYMBOL_REF and OFFSET + SYMBOL points
932 to the same object as SYMBOL. */
935 mips_offset_within_object_p (rtx symbol, HOST_WIDE_INT offset)
937 if (GET_CODE (symbol) != SYMBOL_REF)
940 if (CONSTANT_POOL_ADDRESS_P (symbol)
942 && offset < (int) GET_MODE_SIZE (get_pool_mode (symbol)))
945 if (SYMBOL_REF_DECL (symbol) != 0
947 && offset < int_size_in_bytes (TREE_TYPE (SYMBOL_REF_DECL (symbol))))
954 /* Return true if X is a symbolic constant that can be calculated in
955 the same way as a bare symbol. If it is, store the type of the
956 symbol in *SYMBOL_TYPE. */
959 mips_symbolic_constant_p (rtx x, enum mips_symbol_type *symbol_type)
961 HOST_WIDE_INT offset;
963 mips_split_const (x, &x, &offset);
964 if (UNSPEC_ADDRESS_P (x))
965 *symbol_type = UNSPEC_ADDRESS_TYPE (x);
966 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
968 *symbol_type = mips_classify_symbol (x);
969 if (*symbol_type == SYMBOL_TLS)
978 /* Check whether a nonzero offset is valid for the underlying
980 switch (*symbol_type)
986 /* If the target has 64-bit pointers and the object file only
987 supports 32-bit symbols, the values of those symbols will be
988 sign-extended. In this case we can't allow an arbitrary offset
989 in case the 32-bit value X + OFFSET has a different sign from X. */
990 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
991 return mips_offset_within_object_p (x, offset);
993 /* In other cases the relocations can handle any offset. */
996 case SYMBOL_CONSTANT_POOL:
997 /* Allow constant pool references to be converted to LABEL+CONSTANT.
998 In this case, we no longer have access to the underlying constant,
999 but the original symbol-based access was known to be valid. */
1000 if (GET_CODE (x) == LABEL_REF)
1005 case SYMBOL_SMALL_DATA:
1006 /* Make sure that the offset refers to something within the
1007 underlying object. This should guarantee that the final
1008 PC- or GP-relative offset is within the 16-bit limit. */
1009 return mips_offset_within_object_p (x, offset);
1011 case SYMBOL_GOT_LOCAL:
1012 case SYMBOL_GOTOFF_PAGE:
1013 /* The linker should provide enough local GOT entries for a
1014 16-bit offset. Larger offsets may lead to GOT overflow. */
1015 return SMALL_OPERAND (offset);
1017 case SYMBOL_GOT_GLOBAL:
1018 case SYMBOL_GOTOFF_GLOBAL:
1019 case SYMBOL_GOTOFF_CALL:
1020 case SYMBOL_GOTOFF_LOADGP:
1025 case SYMBOL_GOTTPREL:
1033 /* Return true if X is a symbolic constant whose value is not split
1034 into separate relocations. */
1037 mips_atomic_symbolic_constant_p (rtx x)
1039 enum mips_symbol_type type;
1040 return mips_symbolic_constant_p (x, &type) && !mips_split_p[type];
1044 /* This function is used to implement REG_MODE_OK_FOR_BASE_P. */
1047 mips_regno_mode_ok_for_base_p (int regno, enum machine_mode mode, int strict)
1049 if (regno >= FIRST_PSEUDO_REGISTER)
1053 regno = reg_renumber[regno];
1056 /* These fake registers will be eliminated to either the stack or
1057 hard frame pointer, both of which are usually valid base registers.
1058 Reload deals with the cases where the eliminated form isn't valid. */
1059 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
1062 /* In mips16 mode, the stack pointer can only address word and doubleword
1063 values, nothing smaller. There are two problems here:
1065 (a) Instantiating virtual registers can introduce new uses of the
1066 stack pointer. If these virtual registers are valid addresses,
1067 the stack pointer should be too.
1069 (b) Most uses of the stack pointer are not made explicit until
1070 FRAME_POINTER_REGNUM and ARG_POINTER_REGNUM have been eliminated.
1071 We don't know until that stage whether we'll be eliminating to the
1072 stack pointer (which needs the restriction) or the hard frame
1073 pointer (which doesn't).
1075 All in all, it seems more consistent to only enforce this restriction
1076 during and after reload. */
1077 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
1078 return !strict || GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1080 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
1084 /* Return true if X is a valid base register for the given mode.
1085 Allow only hard registers if STRICT. */
1088 mips_valid_base_register_p (rtx x, enum machine_mode mode, int strict)
1090 if (!strict && GET_CODE (x) == SUBREG)
1094 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict));
1098 /* Return true if symbols of type SYMBOL_TYPE can directly address a value
1099 with mode MODE. This is used for both symbolic and LO_SUM addresses. */
1102 mips_symbolic_address_p (enum mips_symbol_type symbol_type,
1103 enum machine_mode mode)
1105 switch (symbol_type)
1107 case SYMBOL_GENERAL:
1108 return !TARGET_MIPS16;
1110 case SYMBOL_SMALL_DATA:
1113 case SYMBOL_CONSTANT_POOL:
1114 /* PC-relative addressing is only available for lw and ld. */
1115 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
1117 case SYMBOL_GOT_LOCAL:
1120 case SYMBOL_GOT_GLOBAL:
1121 /* The address will have to be loaded from the GOT first. */
1128 case SYMBOL_GOTTPREL:
1132 case SYMBOL_GOTOFF_PAGE:
1133 case SYMBOL_GOTOFF_GLOBAL:
1134 case SYMBOL_GOTOFF_CALL:
1135 case SYMBOL_GOTOFF_LOADGP:
1136 case SYMBOL_64_HIGH:
1145 /* Return true if X is a valid address for machine mode MODE. If it is,
1146 fill in INFO appropriately. STRICT is true if we should only accept
1147 hard base registers. */
1150 mips_classify_address (struct mips_address_info *info, rtx x,
1151 enum machine_mode mode, int strict)
1153 switch (GET_CODE (x))
1157 info->type = ADDRESS_REG;
1159 info->offset = const0_rtx;
1160 return mips_valid_base_register_p (info->reg, mode, strict);
1163 info->type = ADDRESS_REG;
1164 info->reg = XEXP (x, 0);
1165 info->offset = XEXP (x, 1);
1166 return (mips_valid_base_register_p (info->reg, mode, strict)
1167 && const_arith_operand (info->offset, VOIDmode));
1170 info->type = ADDRESS_LO_SUM;
1171 info->reg = XEXP (x, 0);
1172 info->offset = XEXP (x, 1);
1173 return (mips_valid_base_register_p (info->reg, mode, strict)
1174 && mips_symbolic_constant_p (info->offset, &info->symbol_type)
1175 && mips_symbolic_address_p (info->symbol_type, mode)
1176 && mips_lo_relocs[info->symbol_type] != 0);
1179 /* Small-integer addresses don't occur very often, but they
1180 are legitimate if $0 is a valid base register. */
1181 info->type = ADDRESS_CONST_INT;
1182 return !TARGET_MIPS16 && SMALL_INT (x);
1187 info->type = ADDRESS_SYMBOLIC;
1188 return (mips_symbolic_constant_p (x, &info->symbol_type)
1189 && mips_symbolic_address_p (info->symbol_type, mode)
1190 && !mips_split_p[info->symbol_type]);
1197 /* Return true if X is a thread-local symbol. */
1200 mips_tls_operand_p (rtx x)
1202 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
1205 /* Return true if X can not be forced into a constant pool. */
1208 mips_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
1210 return mips_tls_operand_p (*x);
1213 /* Return true if X can not be forced into a constant pool. */
1216 mips_cannot_force_const_mem (rtx x)
1218 if (! TARGET_HAVE_TLS)
1221 return for_each_rtx (&x, &mips_tls_symbol_ref_1, 0);
1224 /* Return the number of instructions needed to load a symbol of the
1225 given type into a register. If valid in an address, the same number
1226 of instructions are needed for loads and stores. Treat extended
1227 mips16 instructions as two instructions. */
1230 mips_symbol_insns (enum mips_symbol_type type)
1234 case SYMBOL_GENERAL:
1235 /* In mips16 code, general symbols must be fetched from the
1240 /* When using 64-bit symbols, we need 5 preparatory instructions,
1243 lui $at,%highest(symbol)
1244 daddiu $at,$at,%higher(symbol)
1246 daddiu $at,$at,%hi(symbol)
1249 The final address is then $at + %lo(symbol). With 32-bit
1250 symbols we just need a preparatory lui. */
1251 return (ABI_HAS_64BIT_SYMBOLS ? 6 : 2);
1253 case SYMBOL_SMALL_DATA:
1256 case SYMBOL_CONSTANT_POOL:
1257 /* This case is for mips16 only. Assume we'll need an
1258 extended instruction. */
1261 case SYMBOL_GOT_LOCAL:
1262 case SYMBOL_GOT_GLOBAL:
1263 /* Unless -funit-at-a-time is in effect, we can't be sure whether
1264 the local/global classification is accurate. See override_options
1267 The worst cases are:
1269 (1) For local symbols when generating o32 or o64 code. The assembler
1275 ...and the final address will be $at + %lo(symbol).
1277 (2) For global symbols when -mxgot. The assembler will use:
1279 lui $at,%got_hi(symbol)
1282 ...and the final address will be $at + %got_lo(symbol). */
1285 case SYMBOL_GOTOFF_PAGE:
1286 case SYMBOL_GOTOFF_GLOBAL:
1287 case SYMBOL_GOTOFF_CALL:
1288 case SYMBOL_GOTOFF_LOADGP:
1289 case SYMBOL_64_HIGH:
1295 case SYMBOL_GOTTPREL:
1297 /* Check whether the offset is a 16- or 32-bit value. */
1298 return mips_split_p[type] ? 2 : 1;
1301 /* We don't treat a bare TLS symbol as a constant. */
1307 /* Return true if X is a legitimate $sp-based address for mode MDOE. */
1310 mips_stack_address_p (rtx x, enum machine_mode mode)
1312 struct mips_address_info addr;
1314 return (mips_classify_address (&addr, x, mode, false)
1315 && addr.type == ADDRESS_REG
1316 && addr.reg == stack_pointer_rtx);
1319 /* Return true if a value at OFFSET bytes from BASE can be accessed
1320 using an unextended mips16 instruction. MODE is the mode of the
1323 Usually the offset in an unextended instruction is a 5-bit field.
1324 The offset is unsigned and shifted left once for HIs, twice
1325 for SIs, and so on. An exception is SImode accesses off the
1326 stack pointer, which have an 8-bit immediate field. */
1329 mips16_unextended_reference_p (enum machine_mode mode, rtx base, rtx offset)
1332 && GET_CODE (offset) == CONST_INT
1333 && INTVAL (offset) >= 0
1334 && (INTVAL (offset) & (GET_MODE_SIZE (mode) - 1)) == 0)
1336 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
1337 return INTVAL (offset) < 256 * GET_MODE_SIZE (mode);
1338 return INTVAL (offset) < 32 * GET_MODE_SIZE (mode);
1344 /* Return the number of instructions needed to load or store a value
1345 of mode MODE at X. Return 0 if X isn't valid for MODE.
1347 For mips16 code, count extended instructions as two instructions. */
1350 mips_address_insns (rtx x, enum machine_mode mode)
1352 struct mips_address_info addr;
1355 if (mode == BLKmode)
1356 /* BLKmode is used for single unaligned loads and stores. */
1359 /* Each word of a multi-word value will be accessed individually. */
1360 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
1362 if (mips_classify_address (&addr, x, mode, false))
1367 && !mips16_unextended_reference_p (mode, addr.reg, addr.offset))
1371 case ADDRESS_LO_SUM:
1372 return (TARGET_MIPS16 ? factor * 2 : factor);
1374 case ADDRESS_CONST_INT:
1377 case ADDRESS_SYMBOLIC:
1378 return factor * mips_symbol_insns (addr.symbol_type);
1384 /* Likewise for constant X. */
1387 mips_const_insns (rtx x)
1389 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1390 enum mips_symbol_type symbol_type;
1391 HOST_WIDE_INT offset;
1393 switch (GET_CODE (x))
1397 || !mips_symbolic_constant_p (XEXP (x, 0), &symbol_type)
1398 || !mips_split_p[symbol_type])
1405 /* Unsigned 8-bit constants can be loaded using an unextended
1406 LI instruction. Unsigned 16-bit constants can be loaded
1407 using an extended LI. Negative constants must be loaded
1408 using LI and then negated. */
1409 return (INTVAL (x) >= 0 && INTVAL (x) < 256 ? 1
1410 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
1411 : INTVAL (x) > -256 && INTVAL (x) < 0 ? 2
1412 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
1415 return mips_build_integer (codes, INTVAL (x));
1419 return (!TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0);
1425 /* See if we can refer to X directly. */
1426 if (mips_symbolic_constant_p (x, &symbol_type))
1427 return mips_symbol_insns (symbol_type);
1429 /* Otherwise try splitting the constant into a base and offset.
1430 16-bit offsets can be added using an extra addiu. Larger offsets
1431 must be calculated separately and then added to the base. */
1432 mips_split_const (x, &x, &offset);
1435 int n = mips_const_insns (x);
1438 if (SMALL_OPERAND (offset))
1441 return n + 1 + mips_build_integer (codes, offset);
1448 return mips_symbol_insns (mips_classify_symbol (x));
1456 /* Return the number of instructions needed for memory reference X.
1457 Count extended mips16 instructions as two instructions. */
1460 mips_fetch_insns (rtx x)
1462 gcc_assert (MEM_P (x));
1463 return mips_address_insns (XEXP (x, 0), GET_MODE (x));
1467 /* Return the number of instructions needed for an integer division. */
1470 mips_idiv_insns (void)
1475 if (TARGET_CHECK_ZERO_DIV)
1477 if (GENERATE_DIVIDE_TRAPS)
1483 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
1488 /* This function is used to implement GO_IF_LEGITIMATE_ADDRESS. It
1489 returns a nonzero value if X is a legitimate address for a memory
1490 operand of the indicated MODE. STRICT is nonzero if this function
1491 is called during reload. */
1494 mips_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1496 struct mips_address_info addr;
1498 return mips_classify_address (&addr, x, mode, strict);
1502 /* Copy VALUE to a register and return that register. If new psuedos
1503 are allowed, copy it into a new register, otherwise use DEST. */
1506 mips_force_temporary (rtx dest, rtx value)
1508 if (!no_new_pseudos)
1509 return force_reg (Pmode, value);
1512 emit_move_insn (copy_rtx (dest), value);
1518 /* Return a LO_SUM expression for ADDR. TEMP is as for mips_force_temporary
1519 and is used to load the high part into a register. */
1522 mips_split_symbol (rtx temp, rtx addr)
1527 high = mips16_gp_pseudo_reg ();
1529 high = mips_force_temporary (temp, gen_rtx_HIGH (Pmode, copy_rtx (addr)));
1530 return gen_rtx_LO_SUM (Pmode, high, addr);
1534 /* Return an UNSPEC address with underlying address ADDRESS and symbol
1535 type SYMBOL_TYPE. */
1538 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
1541 HOST_WIDE_INT offset;
1543 mips_split_const (address, &base, &offset);
1544 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
1545 UNSPEC_ADDRESS_FIRST + symbol_type);
1546 return plus_constant (gen_rtx_CONST (Pmode, base), offset);
1550 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
1551 high part to BASE and return the result. Just return BASE otherwise.
1552 TEMP is available as a temporary register if needed.
1554 The returned expression can be used as the first operand to a LO_SUM. */
1557 mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
1558 enum mips_symbol_type symbol_type)
1560 if (mips_split_p[symbol_type])
1562 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
1563 addr = mips_force_temporary (temp, addr);
1564 return mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
1570 /* Return a legitimate address for REG + OFFSET. TEMP is as for
1571 mips_force_temporary; it is only needed when OFFSET is not a
1575 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
1577 if (!SMALL_OPERAND (offset))
1582 /* Load the full offset into a register so that we can use
1583 an unextended instruction for the address itself. */
1584 high = GEN_INT (offset);
1589 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH. */
1590 high = GEN_INT (CONST_HIGH_PART (offset));
1591 offset = CONST_LOW_PART (offset);
1593 high = mips_force_temporary (temp, high);
1594 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
1596 return plus_constant (reg, offset);
1599 /* Emit a call to __tls_get_addr. SYM is the TLS symbol we are
1600 referencing, and TYPE is the symbol type to use (either global
1601 dynamic or local dynamic). V0 is an RTX for the return value
1602 location. The entire insn sequence is returned. */
1604 static GTY(()) rtx mips_tls_symbol;
1607 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
1609 rtx insn, loc, tga, a0;
1611 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
1613 if (!mips_tls_symbol)
1614 mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
1616 loc = mips_unspec_address (sym, type);
1620 emit_insn (gen_rtx_SET (Pmode, a0,
1621 gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
1622 tga = gen_rtx_MEM (Pmode, mips_tls_symbol);
1623 insn = emit_call_insn (gen_call_value (v0, tga, const0_rtx, const0_rtx));
1624 CONST_OR_PURE_CALL_P (insn) = 1;
1625 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), v0);
1626 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
1627 insn = get_insns ();
1634 /* Generate the code to access LOC, a thread local SYMBOL_REF. The
1635 return value will be a valid address and move_operand (either a REG
1639 mips_legitimize_tls_address (rtx loc)
1641 rtx dest, insn, v0, v1, tmp1, tmp2, eqv;
1642 enum tls_model model;
1644 v0 = gen_rtx_REG (Pmode, GP_RETURN);
1645 v1 = gen_rtx_REG (Pmode, GP_RETURN + 1);
1647 model = SYMBOL_REF_TLS_MODEL (loc);
1651 case TLS_MODEL_GLOBAL_DYNAMIC:
1652 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
1653 dest = gen_reg_rtx (Pmode);
1654 emit_libcall_block (insn, dest, v0, loc);
1657 case TLS_MODEL_LOCAL_DYNAMIC:
1658 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
1659 tmp1 = gen_reg_rtx (Pmode);
1661 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
1662 share the LDM result with other LD model accesses. */
1663 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1665 emit_libcall_block (insn, tmp1, v0, eqv);
1667 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
1668 dest = gen_rtx_LO_SUM (Pmode, tmp2,
1669 mips_unspec_address (loc, SYMBOL_DTPREL));
1672 case TLS_MODEL_INITIAL_EXEC:
1673 tmp1 = gen_reg_rtx (Pmode);
1674 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
1675 if (Pmode == DImode)
1677 emit_insn (gen_tls_get_tp_di (v1));
1678 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
1682 emit_insn (gen_tls_get_tp_si (v1));
1683 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
1685 dest = gen_reg_rtx (Pmode);
1686 emit_insn (gen_add3_insn (dest, tmp1, v1));
1689 case TLS_MODEL_LOCAL_EXEC:
1691 if (Pmode == DImode)
1692 emit_insn (gen_tls_get_tp_di (v1));
1694 emit_insn (gen_tls_get_tp_si (v1));
1696 tmp1 = mips_unspec_offset_high (NULL, v1, loc, SYMBOL_TPREL);
1697 dest = gen_rtx_LO_SUM (Pmode, tmp1,
1698 mips_unspec_address (loc, SYMBOL_TPREL));
1708 /* This function is used to implement LEGITIMIZE_ADDRESS. If *XLOC can
1709 be legitimized in a way that the generic machinery might not expect,
1710 put the new address in *XLOC and return true. MODE is the mode of
1711 the memory being accessed. */
1714 mips_legitimize_address (rtx *xloc, enum machine_mode mode)
1716 enum mips_symbol_type symbol_type;
1718 if (mips_tls_operand_p (*xloc))
1720 *xloc = mips_legitimize_tls_address (*xloc);
1724 /* See if the address can split into a high part and a LO_SUM. */
1725 if (mips_symbolic_constant_p (*xloc, &symbol_type)
1726 && mips_symbolic_address_p (symbol_type, mode)
1727 && mips_split_p[symbol_type])
1729 *xloc = mips_split_symbol (0, *xloc);
1733 if (GET_CODE (*xloc) == PLUS && GET_CODE (XEXP (*xloc, 1)) == CONST_INT)
1735 /* Handle REG + CONSTANT using mips_add_offset. */
1738 reg = XEXP (*xloc, 0);
1739 if (!mips_valid_base_register_p (reg, mode, 0))
1740 reg = copy_to_mode_reg (Pmode, reg);
1741 *xloc = mips_add_offset (0, reg, INTVAL (XEXP (*xloc, 1)));
1749 /* Subroutine of mips_build_integer (with the same interface).
1750 Assume that the final action in the sequence should be a left shift. */
1753 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
1755 unsigned int i, shift;
1757 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
1758 since signed numbers are easier to load than unsigned ones. */
1760 while ((value & 1) == 0)
1761 value /= 2, shift++;
1763 i = mips_build_integer (codes, value);
1764 codes[i].code = ASHIFT;
1765 codes[i].value = shift;
1770 /* As for mips_build_shift, but assume that the final action will be
1771 an IOR or PLUS operation. */
1774 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
1776 unsigned HOST_WIDE_INT high;
1779 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
1780 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
1782 /* The constant is too complex to load with a simple lui/ori pair
1783 so our goal is to clear as many trailing zeros as possible.
1784 In this case, we know bit 16 is set and that the low 16 bits
1785 form a negative number. If we subtract that number from VALUE,
1786 we will clear at least the lowest 17 bits, maybe more. */
1787 i = mips_build_integer (codes, CONST_HIGH_PART (value));
1788 codes[i].code = PLUS;
1789 codes[i].value = CONST_LOW_PART (value);
1793 i = mips_build_integer (codes, high);
1794 codes[i].code = IOR;
1795 codes[i].value = value & 0xffff;
1801 /* Fill CODES with a sequence of rtl operations to load VALUE.
1802 Return the number of operations needed. */
1805 mips_build_integer (struct mips_integer_op *codes,
1806 unsigned HOST_WIDE_INT value)
1808 if (SMALL_OPERAND (value)
1809 || SMALL_OPERAND_UNSIGNED (value)
1810 || LUI_OPERAND (value))
1812 /* The value can be loaded with a single instruction. */
1813 codes[0].code = UNKNOWN;
1814 codes[0].value = value;
1817 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
1819 /* Either the constant is a simple LUI/ORI combination or its
1820 lowest bit is set. We don't want to shift in this case. */
1821 return mips_build_lower (codes, value);
1823 else if ((value & 0xffff) == 0)
1825 /* The constant will need at least three actions. The lowest
1826 16 bits are clear, so the final action will be a shift. */
1827 return mips_build_shift (codes, value);
1831 /* The final action could be a shift, add or inclusive OR.
1832 Rather than use a complex condition to select the best
1833 approach, try both mips_build_shift and mips_build_lower
1834 and pick the one that gives the shortest sequence.
1835 Note that this case is only used once per constant. */
1836 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
1837 unsigned int cost, alt_cost;
1839 cost = mips_build_shift (codes, value);
1840 alt_cost = mips_build_lower (alt_codes, value);
1841 if (alt_cost < cost)
1843 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
1851 /* Move VALUE into register DEST. */
1854 mips_move_integer (rtx dest, unsigned HOST_WIDE_INT value)
1856 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
1857 enum machine_mode mode;
1858 unsigned int i, cost;
1861 mode = GET_MODE (dest);
1862 cost = mips_build_integer (codes, value);
1864 /* Apply each binary operation to X. Invariant: X is a legitimate
1865 source operand for a SET pattern. */
1866 x = GEN_INT (codes[0].value);
1867 for (i = 1; i < cost; i++)
1870 emit_move_insn (dest, x), x = dest;
1872 x = force_reg (mode, x);
1873 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
1876 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
1880 /* Subroutine of mips_legitimize_move. Move constant SRC into register
1881 DEST given that SRC satisfies immediate_operand but doesn't satisfy
1885 mips_legitimize_const_move (enum machine_mode mode, rtx dest, rtx src)
1888 HOST_WIDE_INT offset;
1889 enum mips_symbol_type symbol_type;
1891 /* Split moves of big integers into smaller pieces. In mips16 code,
1892 it's better to force the constant into memory instead. */
1893 if (GET_CODE (src) == CONST_INT && !TARGET_MIPS16)
1895 mips_move_integer (dest, INTVAL (src));
1899 if (mips_tls_operand_p (src))
1901 emit_move_insn (dest, mips_legitimize_tls_address (src));
1905 /* See if the symbol can be split. For mips16, this is often worse than
1906 forcing it in the constant pool since it needs the single-register form
1907 of addiu or daddiu. */
1909 && mips_symbolic_constant_p (src, &symbol_type)
1910 && mips_split_p[symbol_type])
1912 emit_move_insn (dest, mips_split_symbol (dest, src));
1916 /* If we have (const (plus symbol offset)), load the symbol first
1917 and then add in the offset. This is usually better than forcing
1918 the constant into memory, at least in non-mips16 code. */
1919 mips_split_const (src, &base, &offset);
1922 && (!no_new_pseudos || SMALL_OPERAND (offset)))
1924 base = mips_force_temporary (dest, base);
1925 emit_move_insn (dest, mips_add_offset (0, base, offset));
1929 src = force_const_mem (mode, src);
1931 /* When using explicit relocs, constant pool references are sometimes
1932 not legitimate addresses. */
1933 if (!memory_operand (src, VOIDmode))
1934 src = replace_equiv_address (src, mips_split_symbol (dest, XEXP (src, 0)));
1935 emit_move_insn (dest, src);
1939 /* If (set DEST SRC) is not a valid instruction, emit an equivalent
1940 sequence that is valid. */
1943 mips_legitimize_move (enum machine_mode mode, rtx dest, rtx src)
1945 if (!register_operand (dest, mode) && !reg_or_0_operand (src, mode))
1947 emit_move_insn (dest, force_reg (mode, src));
1951 /* Check for individual, fully-reloaded mflo and mfhi instructions. */
1952 if (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
1953 && REG_P (src) && MD_REG_P (REGNO (src))
1954 && REG_P (dest) && GP_REG_P (REGNO (dest)))
1956 int other_regno = REGNO (src) == HI_REGNUM ? LO_REGNUM : HI_REGNUM;
1957 if (GET_MODE_SIZE (mode) <= 4)
1958 emit_insn (gen_mfhilo_si (gen_rtx_REG (SImode, REGNO (dest)),
1959 gen_rtx_REG (SImode, REGNO (src)),
1960 gen_rtx_REG (SImode, other_regno)));
1962 emit_insn (gen_mfhilo_di (gen_rtx_REG (DImode, REGNO (dest)),
1963 gen_rtx_REG (DImode, REGNO (src)),
1964 gen_rtx_REG (DImode, other_regno)));
1968 /* We need to deal with constants that would be legitimate
1969 immediate_operands but not legitimate move_operands. */
1970 if (CONSTANT_P (src) && !move_operand (src, mode))
1972 mips_legitimize_const_move (mode, dest, src);
1973 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
1979 /* We need a lot of little routines to check constant values on the
1980 mips16. These are used to figure out how long the instruction will
1981 be. It would be much better to do this using constraints, but
1982 there aren't nearly enough letters available. */
1985 m16_check_op (rtx op, int low, int high, int mask)
1987 return (GET_CODE (op) == CONST_INT
1988 && INTVAL (op) >= low
1989 && INTVAL (op) <= high
1990 && (INTVAL (op) & mask) == 0);
1994 m16_uimm3_b (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1996 return m16_check_op (op, 0x1, 0x8, 0);
2000 m16_simm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2002 return m16_check_op (op, - 0x8, 0x7, 0);
2006 m16_nsimm4_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2008 return m16_check_op (op, - 0x7, 0x8, 0);
2012 m16_simm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2014 return m16_check_op (op, - 0x10, 0xf, 0);
2018 m16_nsimm5_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2020 return m16_check_op (op, - 0xf, 0x10, 0);
2024 m16_uimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2026 return m16_check_op (op, (- 0x10) << 2, 0xf << 2, 3);
2030 m16_nuimm5_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2032 return m16_check_op (op, (- 0xf) << 2, 0x10 << 2, 3);
2036 m16_simm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2038 return m16_check_op (op, - 0x80, 0x7f, 0);
2042 m16_nsimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2044 return m16_check_op (op, - 0x7f, 0x80, 0);
2048 m16_uimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2050 return m16_check_op (op, 0x0, 0xff, 0);
2054 m16_nuimm8_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2056 return m16_check_op (op, - 0xff, 0x0, 0);
2060 m16_uimm8_m1_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2062 return m16_check_op (op, - 0x1, 0xfe, 0);
2066 m16_uimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2068 return m16_check_op (op, 0x0, 0xff << 2, 3);
2072 m16_nuimm8_4 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2074 return m16_check_op (op, (- 0xff) << 2, 0x0, 3);
2078 m16_simm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2080 return m16_check_op (op, (- 0x80) << 3, 0x7f << 3, 7);
2084 m16_nsimm8_8 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2086 return m16_check_op (op, (- 0x7f) << 3, 0x80 << 3, 7);
2090 mips_rtx_costs (rtx x, int code, int outer_code, int *total)
2092 enum machine_mode mode = GET_MODE (x);
2099 /* Always return 0, since we don't have different sized
2100 instructions, hence different costs according to Richard
2106 /* A number between 1 and 8 inclusive is efficient for a shift.
2107 Otherwise, we will need an extended instruction. */
2108 if ((outer_code) == ASHIFT || (outer_code) == ASHIFTRT
2109 || (outer_code) == LSHIFTRT)
2111 if (INTVAL (x) >= 1 && INTVAL (x) <= 8)
2114 *total = COSTS_N_INSNS (1);
2118 /* We can use cmpi for an xor with an unsigned 16 bit value. */
2119 if ((outer_code) == XOR
2120 && INTVAL (x) >= 0 && INTVAL (x) < 0x10000)
2126 /* We may be able to use slt or sltu for a comparison with a
2127 signed 16 bit value. (The boundary conditions aren't quite
2128 right, but this is just a heuristic anyhow.) */
2129 if (((outer_code) == LT || (outer_code) == LE
2130 || (outer_code) == GE || (outer_code) == GT
2131 || (outer_code) == LTU || (outer_code) == LEU
2132 || (outer_code) == GEU || (outer_code) == GTU)
2133 && INTVAL (x) >= -0x8000 && INTVAL (x) < 0x8000)
2139 /* Equality comparisons with 0 are cheap. */
2140 if (((outer_code) == EQ || (outer_code) == NE)
2147 /* Constants in the range 0...255 can be loaded with an unextended
2148 instruction. They are therefore as cheap as a register move.
2150 Given the choice between "li R1,0...255" and "move R1,R2"
2151 (where R2 is a known constant), it is usually better to use "li",
2152 since we do not want to unnecessarily extend the lifetime of R2. */
2153 if (outer_code == SET
2155 && INTVAL (x) < 256)
2161 /* Otherwise fall through to the handling below. */
2167 if (LEGITIMATE_CONSTANT_P (x))
2169 *total = COSTS_N_INSNS (1);
2174 /* The value will need to be fetched from the constant pool. */
2175 *total = CONSTANT_POOL_COST;
2181 /* If the address is legitimate, return the number of
2182 instructions it needs, otherwise use the default handling. */
2183 int n = mips_address_insns (XEXP (x, 0), GET_MODE (x));
2186 *total = COSTS_N_INSNS (1 + n);
2193 *total = COSTS_N_INSNS (6);
2197 *total = COSTS_N_INSNS ((mode == DImode && !TARGET_64BIT) ? 2 : 1);
2203 if (mode == DImode && !TARGET_64BIT)
2205 *total = COSTS_N_INSNS (2);
2213 if (mode == DImode && !TARGET_64BIT)
2215 *total = COSTS_N_INSNS ((GET_CODE (XEXP (x, 1)) == CONST_INT)
2222 if (mode == SFmode || mode == DFmode)
2223 *total = COSTS_N_INSNS (1);
2225 *total = COSTS_N_INSNS (4);
2229 *total = COSTS_N_INSNS (1);
2234 if (mode == SFmode || mode == DFmode)
2236 if (TUNE_MIPS3000 || TUNE_MIPS3900)
2237 *total = COSTS_N_INSNS (2);
2238 else if (TUNE_MIPS6000)
2239 *total = COSTS_N_INSNS (3);
2241 *total = COSTS_N_INSNS (4);
2243 *total = COSTS_N_INSNS (6);
2246 if (mode == DImode && !TARGET_64BIT)
2248 *total = COSTS_N_INSNS (4);
2254 if (mode == DImode && !TARGET_64BIT)
2268 *total = COSTS_N_INSNS (4);
2269 else if (TUNE_MIPS6000
2272 *total = COSTS_N_INSNS (5);
2274 *total = COSTS_N_INSNS (7);
2281 *total = COSTS_N_INSNS (4);
2282 else if (TUNE_MIPS3000
2285 *total = COSTS_N_INSNS (5);
2286 else if (TUNE_MIPS6000
2289 *total = COSTS_N_INSNS (6);
2291 *total = COSTS_N_INSNS (8);
2296 *total = COSTS_N_INSNS (12);
2297 else if (TUNE_MIPS3900)
2298 *total = COSTS_N_INSNS (2);
2299 else if (TUNE_MIPS4130)
2300 *total = COSTS_N_INSNS (mode == DImode ? 6 : 4);
2301 else if (TUNE_MIPS5400 || TUNE_SB1)
2302 *total = COSTS_N_INSNS (mode == DImode ? 4 : 3);
2303 else if (TUNE_MIPS5500 || TUNE_MIPS7000)
2304 *total = COSTS_N_INSNS (mode == DImode ? 9 : 5);
2305 else if (TUNE_MIPS9000)
2306 *total = COSTS_N_INSNS (mode == DImode ? 8 : 3);
2307 else if (TUNE_MIPS6000)
2308 *total = COSTS_N_INSNS (17);
2309 else if (TUNE_MIPS5000)
2310 *total = COSTS_N_INSNS (5);
2312 *total = COSTS_N_INSNS (10);
2321 *total = COSTS_N_INSNS (12);
2322 else if (TUNE_MIPS6000)
2323 *total = COSTS_N_INSNS (15);
2325 *total = COSTS_N_INSNS (24);
2326 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2327 *total = COSTS_N_INSNS (30);
2329 *total = COSTS_N_INSNS (23);
2337 *total = COSTS_N_INSNS (19);
2338 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2339 *total = COSTS_N_INSNS (59);
2340 else if (TUNE_MIPS6000)
2341 *total = COSTS_N_INSNS (16);
2343 *total = COSTS_N_INSNS (32);
2345 *total = COSTS_N_INSNS (36);
2354 *total = COSTS_N_INSNS (35);
2355 else if (TUNE_MIPS6000)
2356 *total = COSTS_N_INSNS (38);
2357 else if (TUNE_MIPS5000)
2358 *total = COSTS_N_INSNS (36);
2360 *total = COSTS_N_INSNS ((mode == SImode) ? 36 : 68);
2361 else if (TUNE_MIPS5400 || TUNE_MIPS5500)
2362 *total = COSTS_N_INSNS ((mode == SImode) ? 42 : 74);
2364 *total = COSTS_N_INSNS (69);
2368 /* A sign extend from SImode to DImode in 64 bit mode is often
2369 zero instructions, because the result can often be used
2370 directly by another instruction; we'll call it one. */
2371 if (TARGET_64BIT && mode == DImode
2372 && GET_MODE (XEXP (x, 0)) == SImode)
2373 *total = COSTS_N_INSNS (1);
2375 *total = COSTS_N_INSNS (2);
2379 if (TARGET_64BIT && mode == DImode
2380 && GET_MODE (XEXP (x, 0)) == SImode)
2381 *total = COSTS_N_INSNS (2);
2383 *total = COSTS_N_INSNS (1);
2391 /* Provide the costs of an addressing mode that contains ADDR.
2392 If ADDR is not a valid address, its cost is irrelevant. */
2395 mips_address_cost (rtx addr)
2397 return mips_address_insns (addr, SImode);
2400 /* Return one word of double-word value OP, taking into account the fixed
2401 endianness of certain registers. HIGH_P is true to select the high part,
2402 false to select the low part. */
2405 mips_subword (rtx op, int high_p)
2408 enum machine_mode mode;
2410 mode = GET_MODE (op);
2411 if (mode == VOIDmode)
2414 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
2415 byte = UNITS_PER_WORD;
2421 if (FP_REG_P (REGNO (op)))
2422 return gen_rtx_REG (word_mode, high_p ? REGNO (op) + 1 : REGNO (op));
2423 if (REGNO (op) == HI_REGNUM)
2424 return gen_rtx_REG (word_mode, high_p ? HI_REGNUM : LO_REGNUM);
2428 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
2430 return simplify_gen_subreg (word_mode, op, mode, byte);
2434 /* Return true if a 64-bit move from SRC to DEST should be split into two. */
2437 mips_split_64bit_move_p (rtx dest, rtx src)
2442 /* FP->FP moves can be done in a single instruction. */
2443 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
2446 /* Check for floating-point loads and stores. They can be done using
2447 ldc1 and sdc1 on MIPS II and above. */
2450 if (FP_REG_RTX_P (dest) && MEM_P (src))
2452 if (FP_REG_RTX_P (src) && MEM_P (dest))
2459 /* Split a 64-bit move from SRC to DEST assuming that
2460 mips_split_64bit_move_p holds.
2462 Moves into and out of FPRs cause some difficulty here. Such moves
2463 will always be DFmode, since paired FPRs are not allowed to store
2464 DImode values. The most natural representation would be two separate
2465 32-bit moves, such as:
2467 (set (reg:SI $f0) (mem:SI ...))
2468 (set (reg:SI $f1) (mem:SI ...))
2470 However, the second insn is invalid because odd-numbered FPRs are
2471 not allowed to store independent values. Use the patterns load_df_low,
2472 load_df_high and store_df_high instead. */
2475 mips_split_64bit_move (rtx dest, rtx src)
2477 if (FP_REG_RTX_P (dest))
2479 /* Loading an FPR from memory or from GPRs. */
2480 emit_insn (gen_load_df_low (copy_rtx (dest), mips_subword (src, 0)));
2481 emit_insn (gen_load_df_high (dest, mips_subword (src, 1),
2484 else if (FP_REG_RTX_P (src))
2486 /* Storing an FPR into memory or GPRs. */
2487 emit_move_insn (mips_subword (dest, 0), mips_subword (src, 0));
2488 emit_insn (gen_store_df_high (mips_subword (dest, 1), src));
2492 /* The operation can be split into two normal moves. Decide in
2493 which order to do them. */
2496 low_dest = mips_subword (dest, 0);
2497 if (REG_P (low_dest)
2498 && reg_overlap_mentioned_p (low_dest, src))
2500 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2501 emit_move_insn (low_dest, mips_subword (src, 0));
2505 emit_move_insn (low_dest, mips_subword (src, 0));
2506 emit_move_insn (mips_subword (dest, 1), mips_subword (src, 1));
2511 /* Return the appropriate instructions to move SRC into DEST. Assume
2512 that SRC is operand 1 and DEST is operand 0. */
2515 mips_output_move (rtx dest, rtx src)
2517 enum rtx_code dest_code, src_code;
2520 dest_code = GET_CODE (dest);
2521 src_code = GET_CODE (src);
2522 dbl_p = (GET_MODE_SIZE (GET_MODE (dest)) == 8);
2524 if (dbl_p && mips_split_64bit_move_p (dest, src))
2527 if ((src_code == REG && GP_REG_P (REGNO (src)))
2528 || (!TARGET_MIPS16 && src == CONST0_RTX (GET_MODE (dest))))
2530 if (dest_code == REG)
2532 if (GP_REG_P (REGNO (dest)))
2533 return "move\t%0,%z1";
2535 if (MD_REG_P (REGNO (dest)))
2538 if (FP_REG_P (REGNO (dest)))
2539 return (dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0");
2541 if (ALL_COP_REG_P (REGNO (dest)))
2543 static char retval[] = "dmtc_\t%z1,%0";
2545 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2546 return (dbl_p ? retval : retval + 1);
2549 if (dest_code == MEM)
2550 return (dbl_p ? "sd\t%z1,%0" : "sw\t%z1,%0");
2552 if (dest_code == REG && GP_REG_P (REGNO (dest)))
2554 if (src_code == REG)
2556 if (ST_REG_P (REGNO (src)) && ISA_HAS_8CC)
2557 return "lui\t%0,0x3f80\n\tmovf\t%0,%.,%1";
2559 if (FP_REG_P (REGNO (src)))
2560 return (dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1");
2562 if (ALL_COP_REG_P (REGNO (src)))
2564 static char retval[] = "dmfc_\t%0,%1";
2566 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2567 return (dbl_p ? retval : retval + 1);
2571 if (src_code == MEM)
2572 return (dbl_p ? "ld\t%0,%1" : "lw\t%0,%1");
2574 if (src_code == CONST_INT)
2576 /* Don't use the X format, because that will give out of
2577 range numbers for 64 bit hosts and 32 bit targets. */
2579 return "li\t%0,%1\t\t\t# %X1";
2581 if (INTVAL (src) >= 0 && INTVAL (src) <= 0xffff)
2584 if (INTVAL (src) < 0 && INTVAL (src) >= -0xffff)
2588 if (src_code == HIGH)
2589 return "lui\t%0,%h1";
2591 if (CONST_GP_P (src))
2592 return "move\t%0,%1";
2594 if (symbolic_operand (src, VOIDmode))
2595 return (dbl_p ? "dla\t%0,%1" : "la\t%0,%1");
2597 if (src_code == REG && FP_REG_P (REGNO (src)))
2599 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2601 if (GET_MODE (dest) == V2SFmode)
2602 return "mov.ps\t%0,%1";
2604 return (dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1");
2607 if (dest_code == MEM)
2608 return (dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0");
2610 if (dest_code == REG && FP_REG_P (REGNO (dest)))
2612 if (src_code == MEM)
2613 return (dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1");
2615 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
2617 static char retval[] = "l_c_\t%0,%1";
2619 retval[1] = (dbl_p ? 'd' : 'w');
2620 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
2623 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
2625 static char retval[] = "s_c_\t%1,%0";
2627 retval[1] = (dbl_p ? 'd' : 'w');
2628 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
2634 /* Restore $gp from its save slot. Valid only when using o32 or
2638 mips_restore_gp (void)
2642 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI);
2644 address = mips_add_offset (pic_offset_table_rtx,
2645 frame_pointer_needed
2646 ? hard_frame_pointer_rtx
2647 : stack_pointer_rtx,
2648 current_function_outgoing_args_size);
2649 slot = gen_rtx_MEM (Pmode, address);
2651 emit_move_insn (pic_offset_table_rtx, slot);
2652 if (!TARGET_EXPLICIT_RELOCS)
2653 emit_insn (gen_blockage ());
2656 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
2659 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
2661 emit_insn (gen_rtx_SET (VOIDmode, target,
2662 gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
2665 /* Return true if CMP1 is a suitable second operand for relational
2666 operator CODE. See also the *sCC patterns in mips.md. */
2669 mips_relational_operand_ok_p (enum rtx_code code, rtx cmp1)
2675 return reg_or_0_operand (cmp1, VOIDmode);
2679 return !TARGET_MIPS16 && cmp1 == const1_rtx;
2683 return arith_operand (cmp1, VOIDmode);
2686 return sle_operand (cmp1, VOIDmode);
2689 return sleu_operand (cmp1, VOIDmode);
2696 /* Compare CMP0 and CMP1 using relational operator CODE and store the
2697 result in TARGET. CMP0 and TARGET are register_operands that have
2698 the same integer mode. If INVERT_PTR is nonnull, it's OK to set
2699 TARGET to the inverse of the result and flip *INVERT_PTR instead. */
2702 mips_emit_int_relational (enum rtx_code code, bool *invert_ptr,
2703 rtx target, rtx cmp0, rtx cmp1)
2705 /* First see if there is a MIPS instruction that can do this operation
2706 with CMP1 in its current form. If not, try doing the same for the
2707 inverse operation. If that also fails, force CMP1 into a register
2709 if (mips_relational_operand_ok_p (code, cmp1))
2710 mips_emit_binary (code, target, cmp0, cmp1);
2713 enum rtx_code inv_code = reverse_condition (code);
2714 if (!mips_relational_operand_ok_p (inv_code, cmp1))
2716 cmp1 = force_reg (GET_MODE (cmp0), cmp1);
2717 mips_emit_int_relational (code, invert_ptr, target, cmp0, cmp1);
2719 else if (invert_ptr == 0)
2721 rtx inv_target = gen_reg_rtx (GET_MODE (target));
2722 mips_emit_binary (inv_code, inv_target, cmp0, cmp1);
2723 mips_emit_binary (XOR, target, inv_target, const1_rtx);
2727 *invert_ptr = !*invert_ptr;
2728 mips_emit_binary (inv_code, target, cmp0, cmp1);
2733 /* Return a register that is zero iff CMP0 and CMP1 are equal.
2734 The register will have the same mode as CMP0. */
2737 mips_zero_if_equal (rtx cmp0, rtx cmp1)
2739 if (cmp1 == const0_rtx)
2742 if (uns_arith_operand (cmp1, VOIDmode))
2743 return expand_binop (GET_MODE (cmp0), xor_optab,
2744 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
2746 return expand_binop (GET_MODE (cmp0), sub_optab,
2747 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
2750 /* Convert a comparison into something that can be used in a branch or
2751 conditional move. cmp_operands[0] and cmp_operands[1] are the values
2752 being compared and *CODE is the code used to compare them.
2754 Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
2755 If NEED_EQ_NE_P, then only EQ/NE comparisons against zero are possible,
2756 otherwise any standard branch condition can be used. The standard branch
2759 - EQ/NE between two registers.
2760 - any comparison between a register and zero. */
2763 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
2765 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT)
2767 if (!need_eq_ne_p && cmp_operands[1] == const0_rtx)
2769 *op0 = cmp_operands[0];
2770 *op1 = cmp_operands[1];
2772 else if (*code == EQ || *code == NE)
2776 *op0 = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
2781 *op0 = cmp_operands[0];
2782 *op1 = force_reg (GET_MODE (*op0), cmp_operands[1]);
2787 /* The comparison needs a separate scc instruction. Store the
2788 result of the scc in *OP0 and compare it against zero. */
2789 bool invert = false;
2790 *op0 = gen_reg_rtx (GET_MODE (cmp_operands[0]));
2792 mips_emit_int_relational (*code, &invert, *op0,
2793 cmp_operands[0], cmp_operands[1]);
2794 *code = (invert ? EQ : NE);
2799 enum rtx_code cmp_code;
2801 /* Floating-point tests use a separate c.cond.fmt comparison to
2802 set a condition code register. The branch or conditional move
2803 will then compare that register against zero.
2805 Set CMP_CODE to the code of the comparison instruction and
2806 *CODE to the code that the branch or move should use. */
2812 cmp_code = reverse_condition_maybe_unordered (*code);
2822 ? gen_reg_rtx (CCmode)
2823 : gen_rtx_REG (CCmode, FPSW_REGNUM));
2825 mips_emit_binary (cmp_code, *op0, cmp_operands[0], cmp_operands[1]);
2829 /* Try comparing cmp_operands[0] and cmp_operands[1] using rtl code CODE.
2830 Store the result in TARGET and return true if successful.
2832 On 64-bit targets, TARGET may be wider than cmp_operands[0]. */
2835 mips_emit_scc (enum rtx_code code, rtx target)
2837 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) != MODE_INT)
2840 target = gen_lowpart (GET_MODE (cmp_operands[0]), target);
2841 if (code == EQ || code == NE)
2843 rtx zie = mips_zero_if_equal (cmp_operands[0], cmp_operands[1]);
2844 mips_emit_binary (code, target, zie, const0_rtx);
2847 mips_emit_int_relational (code, 0, target,
2848 cmp_operands[0], cmp_operands[1]);
2852 /* Emit the common code for doing conditional branches.
2853 operand[0] is the label to jump to.
2854 The comparison operands are saved away by cmp{si,di,sf,df}. */
2857 gen_conditional_branch (rtx *operands, enum rtx_code code)
2859 rtx op0, op1, target;
2861 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
2862 target = gen_rtx_IF_THEN_ELSE (VOIDmode,
2863 gen_rtx_fmt_ee (code, GET_MODE (op0),
2865 gen_rtx_LABEL_REF (VOIDmode, operands[0]),
2867 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, target));
2870 /* Emit the common code for conditional moves. OPERANDS is the array
2871 of operands passed to the conditional move define_expand. */
2874 gen_conditional_move (rtx *operands)
2879 code = GET_CODE (operands[1]);
2880 mips_emit_compare (&code, &op0, &op1, true);
2881 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
2882 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]),
2883 gen_rtx_fmt_ee (code,
2886 operands[2], operands[3])));
2889 /* Emit a conditional trap. OPERANDS is the array of operands passed to
2890 the conditional_trap expander. */
2893 mips_gen_conditional_trap (rtx *operands)
2896 enum rtx_code cmp_code = GET_CODE (operands[0]);
2897 enum machine_mode mode = GET_MODE (cmp_operands[0]);
2899 /* MIPS conditional trap machine instructions don't have GT or LE
2900 flavors, so we must invert the comparison and convert to LT and
2901 GE, respectively. */
2904 case GT: cmp_code = LT; break;
2905 case LE: cmp_code = GE; break;
2906 case GTU: cmp_code = LTU; break;
2907 case LEU: cmp_code = GEU; break;
2910 if (cmp_code == GET_CODE (operands[0]))
2912 op0 = cmp_operands[0];
2913 op1 = cmp_operands[1];
2917 op0 = cmp_operands[1];
2918 op1 = cmp_operands[0];
2920 op0 = force_reg (mode, op0);
2921 if (!arith_operand (op1, mode))
2922 op1 = force_reg (mode, op1);
2924 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
2925 gen_rtx_fmt_ee (cmp_code, mode, op0, op1),
2929 /* Load function address ADDR into register DEST. SIBCALL_P is true
2930 if the address is needed for a sibling call. */
2933 mips_load_call_address (rtx dest, rtx addr, int sibcall_p)
2935 /* If we're generating PIC, and this call is to a global function,
2936 try to allow its address to be resolved lazily. This isn't
2937 possible for NewABI sibcalls since the value of $gp on entry
2938 to the stub would be our caller's gp, not ours. */
2939 if (TARGET_EXPLICIT_RELOCS
2940 && !(sibcall_p && TARGET_NEWABI)
2941 && global_got_operand (addr, VOIDmode))
2943 rtx high, lo_sum_symbol;
2945 high = mips_unspec_offset_high (dest, pic_offset_table_rtx,
2946 addr, SYMBOL_GOTOFF_CALL);
2947 lo_sum_symbol = mips_unspec_address (addr, SYMBOL_GOTOFF_CALL);
2948 if (Pmode == SImode)
2949 emit_insn (gen_load_callsi (dest, high, lo_sum_symbol));
2951 emit_insn (gen_load_calldi (dest, high, lo_sum_symbol));
2954 emit_move_insn (dest, addr);
2958 /* Expand a call or call_value instruction. RESULT is where the
2959 result will go (null for calls), ADDR is the address of the
2960 function, ARGS_SIZE is the size of the arguments and AUX is
2961 the value passed to us by mips_function_arg. SIBCALL_P is true
2962 if we are expanding a sibling call, false if we're expanding
2966 mips_expand_call (rtx result, rtx addr, rtx args_size, rtx aux, int sibcall_p)
2968 rtx orig_addr, pattern, insn;
2971 if (!call_insn_operand (addr, VOIDmode))
2973 addr = gen_reg_rtx (Pmode);
2974 mips_load_call_address (addr, orig_addr, sibcall_p);
2978 && mips16_hard_float
2979 && build_mips16_call_stub (result, addr, args_size,
2980 aux == 0 ? 0 : (int) GET_MODE (aux)))
2984 pattern = (sibcall_p
2985 ? gen_sibcall_internal (addr, args_size)
2986 : gen_call_internal (addr, args_size));
2987 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
2991 reg1 = XEXP (XVECEXP (result, 0, 0), 0);
2992 reg2 = XEXP (XVECEXP (result, 0, 1), 0);
2995 ? gen_sibcall_value_multiple_internal (reg1, addr, args_size, reg2)
2996 : gen_call_value_multiple_internal (reg1, addr, args_size, reg2));
2999 pattern = (sibcall_p
3000 ? gen_sibcall_value_internal (result, addr, args_size)
3001 : gen_call_value_internal (result, addr, args_size));
3003 insn = emit_call_insn (pattern);
3005 /* Lazy-binding stubs require $gp to be valid on entry. */
3006 if (global_got_operand (orig_addr, VOIDmode))
3007 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
3011 /* We can handle any sibcall when TARGET_SIBCALLS is true. */
3014 mips_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED,
3015 tree exp ATTRIBUTE_UNUSED)
3017 return TARGET_SIBCALLS;
3020 /* Emit code to move general operand SRC into condition-code
3021 register DEST. SCRATCH is a scratch TFmode float register.
3028 where FP1 and FP2 are single-precision float registers
3029 taken from SCRATCH. */
3032 mips_emit_fcc_reload (rtx dest, rtx src, rtx scratch)
3036 /* Change the source to SFmode. */
3038 src = adjust_address (src, SFmode, 0);
3039 else if (REG_P (src) || GET_CODE (src) == SUBREG)
3040 src = gen_rtx_REG (SFmode, true_regnum (src));
3042 fp1 = gen_rtx_REG (SFmode, REGNO (scratch));
3043 fp2 = gen_rtx_REG (SFmode, REGNO (scratch) + FP_INC);
3045 emit_move_insn (copy_rtx (fp1), src);
3046 emit_move_insn (copy_rtx (fp2), CONST0_RTX (SFmode));
3047 emit_insn (gen_slt_sf (dest, fp2, fp1));
3050 /* Emit code to change the current function's return address to
3051 ADDRESS. SCRATCH is available as a scratch register, if needed.
3052 ADDRESS and SCRATCH are both word-mode GPRs. */
3055 mips_set_return_address (rtx address, rtx scratch)
3059 compute_frame_size (get_frame_size ());
3060 gcc_assert ((cfun->machine->frame.mask >> 31) & 1);
3061 slot_address = mips_add_offset (scratch, stack_pointer_rtx,
3062 cfun->machine->frame.gp_sp_offset);
3064 emit_move_insn (gen_rtx_MEM (GET_MODE (address), slot_address), address);
3067 /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
3068 Assume that the areas do not overlap. */
3071 mips_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length)
3073 HOST_WIDE_INT offset, delta;
3074 unsigned HOST_WIDE_INT bits;
3076 enum machine_mode mode;
3079 /* Work out how many bits to move at a time. If both operands have
3080 half-word alignment, it is usually better to move in half words.
3081 For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr
3082 and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr.
3083 Otherwise move word-sized chunks. */
3084 if (MEM_ALIGN (src) == BITS_PER_WORD / 2
3085 && MEM_ALIGN (dest) == BITS_PER_WORD / 2)
3086 bits = BITS_PER_WORD / 2;
3088 bits = BITS_PER_WORD;
3090 mode = mode_for_size (bits, MODE_INT, 0);
3091 delta = bits / BITS_PER_UNIT;
3093 /* Allocate a buffer for the temporary registers. */
3094 regs = alloca (sizeof (rtx) * length / delta);
3096 /* Load as many BITS-sized chunks as possible. Use a normal load if
3097 the source has enough alignment, otherwise use left/right pairs. */
3098 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
3100 regs[i] = gen_reg_rtx (mode);
3101 if (MEM_ALIGN (src) >= bits)
3102 emit_move_insn (regs[i], adjust_address (src, mode, offset));
3105 rtx part = adjust_address (src, BLKmode, offset);
3106 if (!mips_expand_unaligned_load (regs[i], part, bits, 0))
3111 /* Copy the chunks to the destination. */
3112 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
3113 if (MEM_ALIGN (dest) >= bits)
3114 emit_move_insn (adjust_address (dest, mode, offset), regs[i]);
3117 rtx part = adjust_address (dest, BLKmode, offset);
3118 if (!mips_expand_unaligned_store (part, regs[i], bits, 0))
3122 /* Mop up any left-over bytes. */
3123 if (offset < length)
3125 src = adjust_address (src, BLKmode, offset);
3126 dest = adjust_address (dest, BLKmode, offset);
3127 move_by_pieces (dest, src, length - offset,
3128 MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), 0);
3132 #define MAX_MOVE_REGS 4
3133 #define MAX_MOVE_BYTES (MAX_MOVE_REGS * UNITS_PER_WORD)
3136 /* Helper function for doing a loop-based block operation on memory
3137 reference MEM. Each iteration of the loop will operate on LENGTH
3140 Create a new base register for use within the loop and point it to
3141 the start of MEM. Create a new memory reference that uses this
3142 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
3145 mips_adjust_block_mem (rtx mem, HOST_WIDE_INT length,
3146 rtx *loop_reg, rtx *loop_mem)
3148 *loop_reg = copy_addr_to_reg (XEXP (mem, 0));
3150 /* Although the new mem does not refer to a known location,
3151 it does keep up to LENGTH bytes of alignment. */
3152 *loop_mem = change_address (mem, BLKmode, *loop_reg);
3153 set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT));
3157 /* Move LENGTH bytes from SRC to DEST using a loop that moves MAX_MOVE_BYTES
3158 per iteration. LENGTH must be at least MAX_MOVE_BYTES. Assume that the
3159 memory regions do not overlap. */
3162 mips_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length)
3164 rtx label, src_reg, dest_reg, final_src;
3165 HOST_WIDE_INT leftover;
3167 leftover = length % MAX_MOVE_BYTES;
3170 /* Create registers and memory references for use within the loop. */
3171 mips_adjust_block_mem (src, MAX_MOVE_BYTES, &src_reg, &src);
3172 mips_adjust_block_mem (dest, MAX_MOVE_BYTES, &dest_reg, &dest);
3174 /* Calculate the value that SRC_REG should have after the last iteration
3176 final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length),
3179 /* Emit the start of the loop. */
3180 label = gen_label_rtx ();
3183 /* Emit the loop body. */
3184 mips_block_move_straight (dest, src, MAX_MOVE_BYTES);
3186 /* Move on to the next block. */
3187 emit_move_insn (src_reg, plus_constant (src_reg, MAX_MOVE_BYTES));
3188 emit_move_insn (dest_reg, plus_constant (dest_reg, MAX_MOVE_BYTES));
3190 /* Emit the loop condition. */
3191 if (Pmode == DImode)
3192 emit_insn (gen_cmpdi (src_reg, final_src));
3194 emit_insn (gen_cmpsi (src_reg, final_src));
3195 emit_jump_insn (gen_bne (label));
3197 /* Mop up any left-over bytes. */
3199 mips_block_move_straight (dest, src, leftover);
3202 /* Expand a movmemsi instruction. */
3205 mips_expand_block_move (rtx dest, rtx src, rtx length)
3207 if (GET_CODE (length) == CONST_INT)
3209 if (INTVAL (length) <= 2 * MAX_MOVE_BYTES)
3211 mips_block_move_straight (dest, src, INTVAL (length));
3216 mips_block_move_loop (dest, src, INTVAL (length));
3223 /* Argument support functions. */
3225 /* Initialize CUMULATIVE_ARGS for a function. */
3228 init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
3229 rtx libname ATTRIBUTE_UNUSED)
3231 static CUMULATIVE_ARGS zero_cum;
3232 tree param, next_param;
3235 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
3237 /* Determine if this function has variable arguments. This is
3238 indicated by the last argument being 'void_type_mode' if there
3239 are no variable arguments. The standard MIPS calling sequence
3240 passes all arguments in the general purpose registers in this case. */
3242 for (param = fntype ? TYPE_ARG_TYPES (fntype) : 0;
3243 param != 0; param = next_param)
3245 next_param = TREE_CHAIN (param);
3246 if (next_param == 0 && TREE_VALUE (param) != void_type_node)
3247 cum->gp_reg_found = 1;
3252 /* Fill INFO with information about a single argument. CUM is the
3253 cumulative state for earlier arguments. MODE is the mode of this
3254 argument and TYPE is its type (if known). NAMED is true if this
3255 is a named (fixed) argument rather than a variable one. */
3258 mips_arg_info (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
3259 tree type, int named, struct mips_arg_info *info)
3261 bool doubleword_aligned_p;
3262 unsigned int num_bytes, num_words, max_regs;
3264 /* Work out the size of the argument. */
3265 num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
3266 num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3268 /* Decide whether it should go in a floating-point register, assuming
3269 one is free. Later code checks for availability.
3271 The checks against UNITS_PER_FPVALUE handle the soft-float and
3272 single-float cases. */
3276 /* The EABI conventions have traditionally been defined in terms
3277 of TYPE_MODE, regardless of the actual type. */
3278 info->fpr_p = ((GET_MODE_CLASS (mode) == MODE_FLOAT
3279 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3280 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
3285 /* Only leading floating-point scalars are passed in
3286 floating-point registers. We also handle vector floats the same
3287 say, which is OK because they are not covered by the standard ABI. */
3288 info->fpr_p = (!cum->gp_reg_found
3289 && cum->arg_number < 2
3290 && (type == 0 || SCALAR_FLOAT_TYPE_P (type)
3291 || VECTOR_FLOAT_TYPE_P (type))
3292 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3293 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3294 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
3299 /* Scalar and complex floating-point types are passed in
3300 floating-point registers. */
3301 info->fpr_p = (named
3302 && (type == 0 || FLOAT_TYPE_P (type))
3303 && (GET_MODE_CLASS (mode) == MODE_FLOAT
3304 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3305 || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3306 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_FPVALUE);
3308 /* ??? According to the ABI documentation, the real and imaginary
3309 parts of complex floats should be passed in individual registers.
3310 The real and imaginary parts of stack arguments are supposed
3311 to be contiguous and there should be an extra word of padding
3314 This has two problems. First, it makes it impossible to use a
3315 single "void *" va_list type, since register and stack arguments
3316 are passed differently. (At the time of writing, MIPSpro cannot
3317 handle complex float varargs correctly.) Second, it's unclear
3318 what should happen when there is only one register free.
3320 For now, we assume that named complex floats should go into FPRs
3321 if there are two FPRs free, otherwise they should be passed in the
3322 same way as a struct containing two floats. */
3324 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
3325 && GET_MODE_UNIT_SIZE (mode) < UNITS_PER_FPVALUE)
3327 if (cum->num_gprs >= MAX_ARGS_IN_REGISTERS - 1)
3328 info->fpr_p = false;
3338 /* See whether the argument has doubleword alignment. */
3339 doubleword_aligned_p = FUNCTION_ARG_BOUNDARY (mode, type) > BITS_PER_WORD;
3341 /* Set REG_OFFSET to the register count we're interested in.
3342 The EABI allocates the floating-point registers separately,
3343 but the other ABIs allocate them like integer registers. */
3344 info->reg_offset = (mips_abi == ABI_EABI && info->fpr_p
3348 /* Advance to an even register if the argument is doubleword-aligned. */
3349 if (doubleword_aligned_p)
3350 info->reg_offset += info->reg_offset & 1;
3352 /* Work out the offset of a stack argument. */
3353 info->stack_offset = cum->stack_words;
3354 if (doubleword_aligned_p)
3355 info->stack_offset += info->stack_offset & 1;
3357 max_regs = MAX_ARGS_IN_REGISTERS - info->reg_offset;
3359 /* Partition the argument between registers and stack. */
3360 info->reg_words = MIN (num_words, max_regs);
3361 info->stack_words = num_words - info->reg_words;
3365 /* Implement FUNCTION_ARG_ADVANCE. */
3368 function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3369 tree type, int named)
3371 struct mips_arg_info info;
3373 mips_arg_info (cum, mode, type, named, &info);
3376 cum->gp_reg_found = true;
3378 /* See the comment above the cumulative args structure in mips.h
3379 for an explanation of what this code does. It assumes the O32
3380 ABI, which passes at most 2 arguments in float registers. */
3381 if (cum->arg_number < 2 && info.fpr_p)
3382 cum->fp_code += (mode == SFmode ? 1 : 2) << ((cum->arg_number - 1) * 2);
3384 if (mips_abi != ABI_EABI || !info.fpr_p)
3385 cum->num_gprs = info.reg_offset + info.reg_words;
3386 else if (info.reg_words > 0)
3387 cum->num_fprs += FP_INC;
3389 if (info.stack_words > 0)
3390 cum->stack_words = info.stack_offset + info.stack_words;
3395 /* Implement FUNCTION_ARG. */
3398 function_arg (const CUMULATIVE_ARGS *cum, enum machine_mode mode,
3399 tree type, int named)
3401 struct mips_arg_info info;
3403 /* We will be called with a mode of VOIDmode after the last argument
3404 has been seen. Whatever we return will be passed to the call
3405 insn. If we need a mips16 fp_code, return a REG with the code
3406 stored as the mode. */
3407 if (mode == VOIDmode)
3409 if (TARGET_MIPS16 && cum->fp_code != 0)
3410 return gen_rtx_REG ((enum machine_mode) cum->fp_code, 0);
3416 mips_arg_info (cum, mode, type, named, &info);
3418 /* Return straight away if the whole argument is passed on the stack. */
3419 if (info.reg_offset == MAX_ARGS_IN_REGISTERS)
3423 && TREE_CODE (type) == RECORD_TYPE
3425 && TYPE_SIZE_UNIT (type)
3426 && host_integerp (TYPE_SIZE_UNIT (type), 1)
3429 /* The Irix 6 n32/n64 ABIs say that if any 64 bit chunk of the
3430 structure contains a double in its entirety, then that 64 bit
3431 chunk is passed in a floating point register. */
3434 /* First check to see if there is any such field. */
3435 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3436 if (TREE_CODE (field) == FIELD_DECL
3437 && TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3438 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD
3439 && host_integerp (bit_position (field), 0)
3440 && int_bit_position (field) % BITS_PER_WORD == 0)
3445 /* Now handle the special case by returning a PARALLEL
3446 indicating where each 64 bit chunk goes. INFO.REG_WORDS
3447 chunks are passed in registers. */
3449 HOST_WIDE_INT bitpos;
3452 /* assign_parms checks the mode of ENTRY_PARM, so we must
3453 use the actual mode here. */
3454 ret = gen_rtx_PARALLEL (mode, rtvec_alloc (info.reg_words));
3457 field = TYPE_FIELDS (type);
3458 for (i = 0; i < info.reg_words; i++)
3462 for (; field; field = TREE_CHAIN (field))
3463 if (TREE_CODE (field) == FIELD_DECL
3464 && int_bit_position (field) >= bitpos)
3468 && int_bit_position (field) == bitpos
3469 && TREE_CODE (TREE_TYPE (field)) == REAL_TYPE
3470 && !TARGET_SOFT_FLOAT
3471 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD)
3472 reg = gen_rtx_REG (DFmode, FP_ARG_FIRST + info.reg_offset + i);
3474 reg = gen_rtx_REG (DImode, GP_ARG_FIRST + info.reg_offset + i);
3477 = gen_rtx_EXPR_LIST (VOIDmode, reg,
3478 GEN_INT (bitpos / BITS_PER_UNIT));
3480 bitpos += BITS_PER_WORD;
3486 /* Handle the n32/n64 conventions for passing complex floating-point
3487 arguments in FPR pairs. The real part goes in the lower register
3488 and the imaginary part goes in the upper register. */
3491 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
3494 enum machine_mode inner;
3497 inner = GET_MODE_INNER (mode);
3498 reg = FP_ARG_FIRST + info.reg_offset;
3499 real = gen_rtx_EXPR_LIST (VOIDmode,
3500 gen_rtx_REG (inner, reg),
3502 imag = gen_rtx_EXPR_LIST (VOIDmode,
3503 gen_rtx_REG (inner, reg + info.reg_words / 2),
3504 GEN_INT (GET_MODE_SIZE (inner)));
3505 return gen_rtx_PARALLEL (mode, gen_rtvec (2, real, imag));
3509 return gen_rtx_REG (mode, GP_ARG_FIRST + info.reg_offset);
3510 else if (info.reg_offset == 1)
3511 /* This code handles the special o32 case in which the second word