Merge aosp-toolchain/gcc/gcc-4_9 changes.
[official-gcc.git] / gcc-4_9 / gcc / config / mips / mips.c
blob524c6d52d932ba6fbc92e0f4d4bdf3549241a08a
1 /* Subroutines used for MIPS code generation.
2 Copyright (C) 1989-2014 Free Software Foundation, Inc.
3 Contributed by A. Lichnewsky, lich@inria.inria.fr.
4 Changes by Michael Meissner, meissner@osf.org.
5 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
6 Brendan Eich, brendan@microunity.com.
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
13 any later version.
15 GCC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "regs.h"
30 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
34 #include "recog.h"
35 #include "output.h"
36 #include "tree.h"
37 #include "varasm.h"
38 #include "stringpool.h"
39 #include "stor-layout.h"
40 #include "calls.h"
41 #include "function.h"
42 #include "expr.h"
43 #include "optabs.h"
44 #include "libfuncs.h"
45 #include "flags.h"
46 #include "reload.h"
47 #include "tm_p.h"
48 #include "ggc.h"
49 #include "gstab.h"
50 #include "hash-table.h"
51 #include "debug.h"
52 #include "target.h"
53 #include "target-def.h"
54 #include "common/common-target.h"
55 #include "langhooks.h"
56 #include "sched-int.h"
57 #include "pointer-set.h"
58 #include "vec.h"
59 #include "basic-block.h"
60 #include "tree-ssa-alias.h"
61 #include "internal-fn.h"
62 #include "gimple-fold.h"
63 #include "tree-eh.h"
64 #include "gimple-expr.h"
65 #include "is-a.h"
66 #include "gimple.h"
67 #include "gimplify.h"
68 #include "bitmap.h"
69 #include "diagnostic.h"
70 #include "target-globals.h"
71 #include "opts.h"
72 #include "tree-pass.h"
73 #include "context.h"
75 /* Definitions used in ready queue reordering for first scheduling pass. */
77 static int *level = NULL;
78 static int *consumer_luid = NULL;
80 #define LEVEL(INSN) \
81 level[INSN_UID ((INSN))]
83 #define CONSUMER_LUID(INSN) \
84 consumer_luid[INSN_UID ((INSN))]
86 /* True if X is an UNSPEC wrapper around a SYMBOL_REF or LABEL_REF. */
87 #define UNSPEC_ADDRESS_P(X) \
88 (GET_CODE (X) == UNSPEC \
89 && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \
90 && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES)
92 /* Extract the symbol or label from UNSPEC wrapper X. */
93 #define UNSPEC_ADDRESS(X) \
94 XVECEXP (X, 0, 0)
96 /* Extract the symbol type from UNSPEC wrapper X. */
97 #define UNSPEC_ADDRESS_TYPE(X) \
98 ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST))
100 /* The maximum distance between the top of the stack frame and the
101 value $sp has when we save and restore registers.
103 The value for normal-mode code must be a SMALL_OPERAND and must
104 preserve the maximum stack alignment. We therefore use a value
105 of 0x7ff0 in this case.
107 microMIPS LWM and SWM support 12-bit offsets (from -0x800 to 0x7ff),
108 so we use a maximum of 0x7f0 for TARGET_MICROMIPS.
110 MIPS16e SAVE and RESTORE instructions can adjust the stack pointer by
111 up to 0x7f8 bytes and can usually save or restore all the registers
112 that we need to save or restore. (Note that we can only use these
113 instructions for o32, for which the stack alignment is 8 bytes.)
115 We use a maximum gap of 0x100 or 0x400 for MIPS16 code when SAVE and
116 RESTORE are not available. We can then use unextended instructions
117 to save and restore registers, and to allocate and deallocate the top
118 part of the frame. */
119 #define MIPS_MAX_FIRST_STACK_STEP \
120 (!TARGET_COMPRESSION ? 0x7ff0 \
121 : TARGET_MICROMIPS || GENERATE_MIPS16E_SAVE_RESTORE ? 0x7f8 \
122 : TARGET_64BIT ? 0x100 : 0x400)
124 /* True if INSN is a mips.md pattern or asm statement. */
125 /* ??? This test exists through the compiler, perhaps it should be
126 moved to rtl.h. */
127 #define USEFUL_INSN_P(INSN) \
128 (NONDEBUG_INSN_P (INSN) \
129 && GET_CODE (PATTERN (INSN)) != USE \
130 && GET_CODE (PATTERN (INSN)) != CLOBBER)
132 /* If INSN is a delayed branch sequence, return the first instruction
133 in the sequence, otherwise return INSN itself. */
134 #define SEQ_BEGIN(INSN) \
135 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
136 ? XVECEXP (PATTERN (INSN), 0, 0) \
137 : (INSN))
139 /* Likewise for the last instruction in a delayed branch sequence. */
140 #define SEQ_END(INSN) \
141 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \
142 ? XVECEXP (PATTERN (INSN), 0, XVECLEN (PATTERN (INSN), 0) - 1) \
143 : (INSN))
145 /* Execute the following loop body with SUBINSN set to each instruction
146 between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */
147 #define FOR_EACH_SUBINSN(SUBINSN, INSN) \
148 for ((SUBINSN) = SEQ_BEGIN (INSN); \
149 (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \
150 (SUBINSN) = NEXT_INSN (SUBINSN))
152 /* True if bit BIT is set in VALUE. */
153 #define BITSET_P(VALUE, BIT) (((VALUE) & (1 << (BIT))) != 0)
155 /* Return the opcode for a ptr_mode load of the form:
157 l[wd] DEST, OFFSET(BASE). */
158 #define MIPS_LOAD_PTR(DEST, OFFSET, BASE) \
159 (((ptr_mode == DImode ? 0x37 : 0x23) << 26) \
160 | ((BASE) << 21) \
161 | ((DEST) << 16) \
162 | (OFFSET))
164 /* Return the opcode to move register SRC into register DEST. */
165 #define MIPS_MOVE(DEST, SRC) \
166 ((TARGET_64BIT ? 0x2d : 0x21) \
167 | ((DEST) << 11) \
168 | ((SRC) << 21))
170 /* Return the opcode for:
172 lui DEST, VALUE. */
173 #define MIPS_LUI(DEST, VALUE) \
174 ((0xf << 26) | ((DEST) << 16) | (VALUE))
176 /* Return the opcode to jump to register DEST. When the JR opcode is not
177 available use JALR $0, DEST. */
178 #define MIPS_JR(DEST) \
179 (TARGET_CB_ALWAYS ? ((0x1b << 27) | ((DEST) << 16)) \
180 : (((DEST) << 21) | (ISA_HAS_JR ? 0x8 : 0x9)))
182 /* Return the opcode for:
184 bal . + (1 + OFFSET) * 4. */
185 #define MIPS_BAL(OFFSET) \
186 ((0x1 << 26) | (0x11 << 16) | (OFFSET))
188 /* Return the usual opcode for a nop. */
189 #define MIPS_NOP 0
191 /* Classifies an address.
193 ADDRESS_REG
194 A natural register + offset address. The register satisfies
195 mips_valid_base_register_p and the offset is a const_arith_operand.
197 ADDRESS_LO_SUM
198 A LO_SUM rtx. The first operand is a valid base register and
199 the second operand is a symbolic address.
201 ADDRESS_CONST_INT
202 A signed 16-bit constant address.
204 ADDRESS_SYMBOLIC:
205 A constant symbolic address. */
206 enum mips_address_type {
207 ADDRESS_REG,
208 ADDRESS_LO_SUM,
209 ADDRESS_CONST_INT,
210 ADDRESS_SYMBOLIC
213 /* Macros to create an enumeration identifier for a function prototype. */
214 #define MIPS_FTYPE_NAME1(A, B) MIPS_##A##_FTYPE_##B
215 #define MIPS_FTYPE_NAME2(A, B, C) MIPS_##A##_FTYPE_##B##_##C
216 #define MIPS_FTYPE_NAME3(A, B, C, D) MIPS_##A##_FTYPE_##B##_##C##_##D
217 #define MIPS_FTYPE_NAME4(A, B, C, D, E) MIPS_##A##_FTYPE_##B##_##C##_##D##_##E
219 /* Classifies the prototype of a built-in function. */
220 enum mips_function_type {
221 #define DEF_MIPS_FTYPE(NARGS, LIST) MIPS_FTYPE_NAME##NARGS LIST,
222 #include "config/mips/mips-ftypes.def"
223 #undef DEF_MIPS_FTYPE
224 MIPS_MAX_FTYPE_MAX
227 /* Specifies how a built-in function should be converted into rtl. */
228 enum mips_builtin_type {
229 /* The function corresponds directly to an .md pattern. The return
230 value is mapped to operand 0 and the arguments are mapped to
231 operands 1 and above. */
232 MIPS_BUILTIN_DIRECT,
234 /* The function corresponds directly to an .md pattern. There is no return
235 value and the arguments are mapped to operands 0 and above. */
236 MIPS_BUILTIN_DIRECT_NO_TARGET,
238 /* The function corresponds to a comparison instruction followed by
239 a mips_cond_move_tf_ps pattern. The first two arguments are the
240 values to compare and the second two arguments are the vector
241 operands for the movt.ps or movf.ps instruction (in assembly order). */
242 MIPS_BUILTIN_MOVF,
243 MIPS_BUILTIN_MOVT,
245 /* The function corresponds to a V2SF comparison instruction. Operand 0
246 of this instruction is the result of the comparison, which has mode
247 CCV2 or CCV4. The function arguments are mapped to operands 1 and
248 above. The function's return value is an SImode boolean that is
249 true under the following conditions:
251 MIPS_BUILTIN_CMP_ANY: one of the registers is true
252 MIPS_BUILTIN_CMP_ALL: all of the registers are true
253 MIPS_BUILTIN_CMP_LOWER: the first register is true
254 MIPS_BUILTIN_CMP_UPPER: the second register is true. */
255 MIPS_BUILTIN_CMP_ANY,
256 MIPS_BUILTIN_CMP_ALL,
257 MIPS_BUILTIN_CMP_UPPER,
258 MIPS_BUILTIN_CMP_LOWER,
260 /* As above, but the instruction only sets a single $fcc register. */
261 MIPS_BUILTIN_CMP_SINGLE,
263 /* For generating bposge32 branch instructions in MIPS32 DSP ASE. */
264 MIPS_BUILTIN_BPOSGE32
267 /* Invoke MACRO (COND) for each C.cond.fmt condition. */
268 #define MIPS_FP_CONDITIONS(MACRO) \
269 MACRO (f), \
270 MACRO (un), \
271 MACRO (eq), \
272 MACRO (ueq), \
273 MACRO (olt), \
274 MACRO (ult), \
275 MACRO (ole), \
276 MACRO (ule), \
277 MACRO (sf), \
278 MACRO (ngle), \
279 MACRO (seq), \
280 MACRO (ngl), \
281 MACRO (lt), \
282 MACRO (nge), \
283 MACRO (le), \
284 MACRO (ngt)
286 /* Enumerates the codes above as MIPS_FP_COND_<X>. */
287 #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X
288 enum mips_fp_condition {
289 MIPS_FP_CONDITIONS (DECLARE_MIPS_COND)
291 #undef DECLARE_MIPS_COND
293 /* Index X provides the string representation of MIPS_FP_COND_<X>. */
294 #define STRINGIFY(X) #X
295 static const char *const mips_fp_conditions[] = {
296 MIPS_FP_CONDITIONS (STRINGIFY)
298 #undef STRINGIFY
300 /* A class used to control a comdat-style stub that we output in each
301 translation unit that needs it. */
302 class mips_one_only_stub {
303 public:
304 virtual ~mips_one_only_stub () {}
306 /* Return the name of the stub. */
307 virtual const char *get_name () = 0;
309 /* Output the body of the function to asm_out_file. */
310 virtual void output_body () = 0;
313 /* Tuning information that is automatically derived from other sources
314 (such as the scheduler). */
315 static struct {
316 /* The architecture and tuning settings that this structure describes. */
317 enum processor arch;
318 enum processor tune;
320 /* True if this structure describes MIPS16 settings. */
321 bool mips16_p;
323 /* True if the structure has been initialized. */
324 bool initialized_p;
326 /* True if "MULT $0, $0" is preferable to "MTLO $0; MTHI $0"
327 when optimizing for speed. */
328 bool fast_mult_zero_zero_p;
329 } mips_tuning_info;
331 /* Information about a function's frame layout. */
332 struct GTY(()) mips_frame_info {
333 /* The size of the frame in bytes. */
334 HOST_WIDE_INT total_size;
336 /* The number of bytes allocated to variables. */
337 HOST_WIDE_INT var_size;
339 /* The number of bytes allocated to outgoing function arguments. */
340 HOST_WIDE_INT args_size;
342 /* The number of bytes allocated to the .cprestore slot, or 0 if there
343 is no such slot. */
344 HOST_WIDE_INT cprestore_size;
346 /* Bit X is set if the function saves or restores GPR X. */
347 unsigned int mask;
349 /* Likewise FPR X. */
350 unsigned int fmask;
352 /* Likewise doubleword accumulator X ($acX). */
353 unsigned int acc_mask;
355 /* The number of GPRs, FPRs, doubleword accumulators and COP0
356 registers saved. */
357 unsigned int num_gp;
358 unsigned int num_fp;
359 unsigned int num_acc;
360 unsigned int num_cop0_regs;
362 /* The offset of the topmost GPR, FPR, accumulator and COP0-register
363 save slots from the top of the frame, or zero if no such slots are
364 needed. */
365 HOST_WIDE_INT gp_save_offset;
366 HOST_WIDE_INT fp_save_offset;
367 HOST_WIDE_INT acc_save_offset;
368 HOST_WIDE_INT cop0_save_offset;
370 /* Likewise, but giving offsets from the bottom of the frame. */
371 HOST_WIDE_INT gp_sp_offset;
372 HOST_WIDE_INT fp_sp_offset;
373 HOST_WIDE_INT acc_sp_offset;
374 HOST_WIDE_INT cop0_sp_offset;
376 /* Similar, but the value passed to _mcount. */
377 HOST_WIDE_INT ra_fp_offset;
379 /* The offset of arg_pointer_rtx from the bottom of the frame. */
380 HOST_WIDE_INT arg_pointer_offset;
382 /* The offset of hard_frame_pointer_rtx from the bottom of the frame. */
383 HOST_WIDE_INT hard_frame_pointer_offset;
386 struct GTY(()) machine_function {
387 /* The next floating-point condition-code register to allocate
388 for ISA_HAS_8CC targets, relative to ST_REG_FIRST. */
389 unsigned int next_fcc;
391 /* The register returned by mips16_gp_pseudo_reg; see there for details. */
392 rtx mips16_gp_pseudo_rtx;
394 /* The number of extra stack bytes taken up by register varargs.
395 This area is allocated by the callee at the very top of the frame. */
396 int varargs_size;
398 /* The current frame information, calculated by mips_compute_frame_info. */
399 struct mips_frame_info frame;
401 /* The register to use as the function's global pointer, or INVALID_REGNUM
402 if the function doesn't need one. */
403 unsigned int global_pointer;
405 /* How many instructions it takes to load a label into $AT, or 0 if
406 this property hasn't yet been calculated. */
407 unsigned int load_label_num_insns;
409 /* True if mips_adjust_insn_length should ignore an instruction's
410 hazard attribute. */
411 bool ignore_hazard_length_p;
413 /* True if the whole function is suitable for .set noreorder and
414 .set nomacro. */
415 bool all_noreorder_p;
417 /* True if the function has "inflexible" and "flexible" references
418 to the global pointer. See mips_cfun_has_inflexible_gp_ref_p
419 and mips_cfun_has_flexible_gp_ref_p for details. */
420 bool has_inflexible_gp_insn_p;
421 bool has_flexible_gp_insn_p;
423 /* True if the function's prologue must load the global pointer
424 value into pic_offset_table_rtx and store the same value in
425 the function's cprestore slot (if any). Even if this value
426 is currently false, we may decide to set it to true later;
427 see mips_must_initialize_gp_p () for details. */
428 bool must_initialize_gp_p;
430 /* True if the current function must restore $gp after any potential
431 clobber. This value is only meaningful during the first post-epilogue
432 split_insns pass; see mips_must_initialize_gp_p () for details. */
433 bool must_restore_gp_when_clobbered_p;
435 /* True if this is an interrupt handler. */
436 bool interrupt_handler_p;
438 /* True if this is an interrupt handler that uses shadow registers. */
439 bool use_shadow_register_set_p;
441 /* True if this is an interrupt handler that should keep interrupts
442 masked. */
443 bool keep_interrupts_masked_p;
445 /* True if this is an interrupt handler that should use DERET
446 instead of ERET. */
447 bool use_debug_exception_return_p;
450 /* Information about a single argument. */
451 struct mips_arg_info {
452 /* True if the argument is passed in a floating-point register, or
453 would have been if we hadn't run out of registers. */
454 bool fpr_p;
456 /* The number of words passed in registers, rounded up. */
457 unsigned int reg_words;
459 /* For EABI, the offset of the first register from GP_ARG_FIRST or
460 FP_ARG_FIRST. For other ABIs, the offset of the first register from
461 the start of the ABI's argument structure (see the CUMULATIVE_ARGS
462 comment for details).
464 The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely
465 on the stack. */
466 unsigned int reg_offset;
468 /* The number of words that must be passed on the stack, rounded up. */
469 unsigned int stack_words;
471 /* The offset from the start of the stack overflow area of the argument's
472 first stack word. Only meaningful when STACK_WORDS is nonzero. */
473 unsigned int stack_offset;
476 /* Information about an address described by mips_address_type.
478 ADDRESS_CONST_INT
479 No fields are used.
481 ADDRESS_REG
482 REG is the base register and OFFSET is the constant offset.
484 ADDRESS_LO_SUM
485 REG and OFFSET are the operands to the LO_SUM and SYMBOL_TYPE
486 is the type of symbol it references.
488 ADDRESS_SYMBOLIC
489 SYMBOL_TYPE is the type of symbol that the address references. */
490 struct mips_address_info {
491 enum mips_address_type type;
492 rtx reg;
493 rtx offset;
494 enum mips_symbol_type symbol_type;
497 /* One stage in a constant building sequence. These sequences have
498 the form:
500 A = VALUE[0]
501 A = A CODE[1] VALUE[1]
502 A = A CODE[2] VALUE[2]
505 where A is an accumulator, each CODE[i] is a binary rtl operation
506 and each VALUE[i] is a constant integer. CODE[0] is undefined. */
507 struct mips_integer_op {
508 enum rtx_code code;
509 unsigned HOST_WIDE_INT value;
512 /* The largest number of operations needed to load an integer constant.
513 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI.
514 When the lowest bit is clear, we can try, but reject a sequence with
515 an extra SLL at the end. */
516 #define MIPS_MAX_INTEGER_OPS 7
518 /* Information about a MIPS16e SAVE or RESTORE instruction. */
519 struct mips16e_save_restore_info {
520 /* The number of argument registers saved by a SAVE instruction.
521 0 for RESTORE instructions. */
522 unsigned int nargs;
524 /* Bit X is set if the instruction saves or restores GPR X. */
525 unsigned int mask;
527 /* The total number of bytes to allocate. */
528 HOST_WIDE_INT size;
531 /* Costs of various operations on the different architectures. */
533 struct mips_rtx_cost_data
535 unsigned short fp_add;
536 unsigned short fp_mult_sf;
537 unsigned short fp_mult_df;
538 unsigned short fp_div_sf;
539 unsigned short fp_div_df;
540 unsigned short int_mult_si;
541 unsigned short int_mult_di;
542 unsigned short int_div_si;
543 unsigned short int_div_di;
544 unsigned short branch_cost;
545 unsigned short memory_latency;
548 /* Global variables for machine-dependent things. */
550 /* The -G setting, or the configuration's default small-data limit if
551 no -G option is given. */
552 static unsigned int mips_small_data_threshold;
554 /* The number of file directives written by mips_output_filename. */
555 int num_source_filenames;
557 /* The name that appeared in the last .file directive written by
558 mips_output_filename, or "" if mips_output_filename hasn't
559 written anything yet. */
560 const char *current_function_file = "";
562 /* Arrays that map GCC register numbers to debugger register numbers. */
563 int mips_dbx_regno[FIRST_PSEUDO_REGISTER];
564 int mips_dwarf_regno[FIRST_PSEUDO_REGISTER];
566 /* Information about the current function's epilogue, used only while
567 expanding it. */
568 static struct {
569 /* A list of queued REG_CFA_RESTORE notes. */
570 rtx cfa_restores;
572 /* The CFA is currently defined as CFA_REG + CFA_OFFSET. */
573 rtx cfa_reg;
574 HOST_WIDE_INT cfa_offset;
576 /* The offset of the CFA from the stack pointer while restoring
577 registers. */
578 HOST_WIDE_INT cfa_restore_sp_offset;
579 } mips_epilogue;
581 /* The nesting depth of the PRINT_OPERAND '%(', '%<' and '%[' constructs. */
582 struct mips_asm_switch mips_noreorder = { "reorder", 0 };
583 struct mips_asm_switch mips_nomacro = { "macro", 0 };
584 struct mips_asm_switch mips_noat = { "at", 0 };
586 /* True if we're writing out a branch-likely instruction rather than a
587 normal branch. */
588 static bool mips_branch_likely;
590 /* The current instruction-set architecture. */
591 enum processor mips_arch;
592 const struct mips_cpu_info *mips_arch_info;
594 /* The processor that we should tune the code for. */
595 enum processor mips_tune;
596 const struct mips_cpu_info *mips_tune_info;
598 /* The ISA level associated with mips_arch. */
599 int mips_isa;
601 /* The ISA revision level. This is 0 for MIPS I to V and N for
602 MIPS{32,64}rN. */
603 int mips_isa_rev;
605 /* The architecture selected by -mipsN, or null if -mipsN wasn't used. */
606 static const struct mips_cpu_info *mips_isa_option_info;
608 /* Which cost information to use. */
609 static const struct mips_rtx_cost_data *mips_cost;
611 /* The ambient target flags, excluding MASK_MIPS16. */
612 static int mips_base_target_flags;
614 /* The default compression mode. */
615 unsigned int mips_base_compression_flags;
617 /* The ambient values of other global variables. */
618 static int mips_base_schedule_insns; /* flag_schedule_insns */
619 static int mips_base_reorder_blocks_and_partition; /* flag_reorder... */
620 static int mips_base_move_loop_invariants; /* flag_move_loop_invariants */
621 static int mips_base_align_loops; /* align_loops */
622 static int mips_base_align_jumps; /* align_jumps */
623 static int mips_base_align_functions; /* align_functions */
625 /* Index [M][R] is true if register R is allowed to hold a value of mode M. */
626 bool mips_hard_regno_mode_ok[(int) MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER];
628 /* Index C is true if character C is a valid PRINT_OPERAND punctation
629 character. */
630 static bool mips_print_operand_punct[256];
632 static GTY (()) int mips_output_filename_first_time = 1;
634 /* mips_split_p[X] is true if symbols of type X can be split by
635 mips_split_symbol. */
636 bool mips_split_p[NUM_SYMBOL_TYPES];
638 /* mips_split_hi_p[X] is true if the high parts of symbols of type X
639 can be split by mips_split_symbol. */
640 bool mips_split_hi_p[NUM_SYMBOL_TYPES];
642 /* mips_use_pcrel_pool_p[X] is true if symbols of type X should be
643 forced into a PC-relative constant pool. */
644 bool mips_use_pcrel_pool_p[NUM_SYMBOL_TYPES];
646 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X
647 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or
648 if they are matched by a special .md file pattern. */
649 const char *mips_lo_relocs[NUM_SYMBOL_TYPES];
651 /* Likewise for HIGHs. */
652 const char *mips_hi_relocs[NUM_SYMBOL_TYPES];
654 /* Target state for MIPS16. */
655 struct target_globals *mips16_globals;
657 /* Cached value of can_issue_more. This is cached in mips_variable_issue hook
658 and returned from mips_sched_reorder2. */
659 static int cached_can_issue_more;
661 /* The stubs for various MIPS16 support functions, if used. */
662 static mips_one_only_stub *mips16_rdhwr_stub;
663 static mips_one_only_stub *mips16_get_fcsr_stub;
664 static mips_one_only_stub *mips16_set_fcsr_stub;
666 /* Index R is the smallest register class that contains register R. */
667 const enum reg_class mips_regno_to_class[FIRST_PSEUDO_REGISTER] = {
668 LEA_REGS, LEA_REGS, M16_STORE_REGS, V1_REG,
669 M16_STORE_REGS, M16_STORE_REGS, M16_STORE_REGS, M16_STORE_REGS,
670 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
671 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
672 M16_REGS, M16_STORE_REGS, LEA_REGS, LEA_REGS,
673 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS,
674 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS,
675 LEA_REGS, M16_SP_REGS, LEA_REGS, LEA_REGS,
677 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
678 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
679 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
680 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
681 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
682 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
683 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
684 FP_REGS, FP_REGS, FP_REGS, FP_REGS,
685 MD0_REG, MD1_REG, NO_REGS, ST_REGS,
686 ST_REGS, ST_REGS, ST_REGS, ST_REGS,
687 ST_REGS, ST_REGS, ST_REGS, NO_REGS,
688 NO_REGS, FRAME_REGS, FRAME_REGS, NO_REGS,
689 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
690 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
691 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
692 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
693 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
694 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
695 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
696 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS,
697 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
698 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
699 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
700 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
701 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
702 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
703 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
704 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS,
705 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
706 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
707 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
708 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
709 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
710 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
711 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
712 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS,
713 DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS,
714 DSP_ACC_REGS, DSP_ACC_REGS, ALL_REGS, ALL_REGS,
715 ALL_REGS, ALL_REGS, ALL_REGS, ALL_REGS
718 /* The value of TARGET_ATTRIBUTE_TABLE. */
719 static const struct attribute_spec mips_attribute_table[] = {
720 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
721 om_diagnostic } */
722 { "long_call", 0, 0, false, true, true, NULL, false },
723 { "far", 0, 0, false, true, true, NULL, false },
724 { "near", 0, 0, false, true, true, NULL, false },
725 /* We would really like to treat "mips16" and "nomips16" as type
726 attributes, but GCC doesn't provide the hooks we need to support
727 the right conversion rules. As declaration attributes, they affect
728 code generation but don't carry other semantics. */
729 { "mips16", 0, 0, true, false, false, NULL, false },
730 { "nomips16", 0, 0, true, false, false, NULL, false },
731 { "micromips", 0, 0, true, false, false, NULL, false },
732 { "nomicromips", 0, 0, true, false, false, NULL, false },
733 { "nocompression", 0, 0, true, false, false, NULL, false },
734 /* Allow functions to be specified as interrupt handlers */
735 { "interrupt", 0, 0, false, true, true, NULL, false },
736 { "use_shadow_register_set", 0, 0, false, true, true, NULL, false },
737 { "keep_interrupts_masked", 0, 0, false, true, true, NULL, false },
738 { "use_debug_exception_return", 0, 0, false, true, true, NULL, false },
739 { NULL, 0, 0, false, false, false, NULL, false }
742 /* A table describing all the processors GCC knows about; see
743 mips-cpus.def for details. */
744 static const struct mips_cpu_info mips_cpu_info_table[] = {
745 #define MIPS_CPU(NAME, CPU, ISA, FLAGS) \
746 { NAME, CPU, ISA, FLAGS },
747 #include "mips-cpus.def"
748 #undef MIPS_CPU
751 /* Default costs. If these are used for a processor we should look
752 up the actual costs. */
753 #define DEFAULT_COSTS COSTS_N_INSNS (6), /* fp_add */ \
754 COSTS_N_INSNS (7), /* fp_mult_sf */ \
755 COSTS_N_INSNS (8), /* fp_mult_df */ \
756 COSTS_N_INSNS (23), /* fp_div_sf */ \
757 COSTS_N_INSNS (36), /* fp_div_df */ \
758 COSTS_N_INSNS (10), /* int_mult_si */ \
759 COSTS_N_INSNS (10), /* int_mult_di */ \
760 COSTS_N_INSNS (69), /* int_div_si */ \
761 COSTS_N_INSNS (69), /* int_div_di */ \
762 2, /* branch_cost */ \
763 4 /* memory_latency */
765 /* Floating-point costs for processors without an FPU. Just assume that
766 all floating-point libcalls are very expensive. */
767 #define SOFT_FP_COSTS COSTS_N_INSNS (256), /* fp_add */ \
768 COSTS_N_INSNS (256), /* fp_mult_sf */ \
769 COSTS_N_INSNS (256), /* fp_mult_df */ \
770 COSTS_N_INSNS (256), /* fp_div_sf */ \
771 COSTS_N_INSNS (256) /* fp_div_df */
773 /* Costs to use when optimizing for size. */
774 static const struct mips_rtx_cost_data mips_rtx_cost_optimize_size = {
775 COSTS_N_INSNS (1), /* fp_add */
776 COSTS_N_INSNS (1), /* fp_mult_sf */
777 COSTS_N_INSNS (1), /* fp_mult_df */
778 COSTS_N_INSNS (1), /* fp_div_sf */
779 COSTS_N_INSNS (1), /* fp_div_df */
780 COSTS_N_INSNS (1), /* int_mult_si */
781 COSTS_N_INSNS (1), /* int_mult_di */
782 COSTS_N_INSNS (1), /* int_div_si */
783 COSTS_N_INSNS (1), /* int_div_di */
784 2, /* branch_cost */
785 4 /* memory_latency */
788 /* Costs to use when optimizing for speed, indexed by processor. */
789 static const struct mips_rtx_cost_data
790 mips_rtx_cost_data[NUM_PROCESSOR_VALUES] = {
791 { /* R3000 */
792 COSTS_N_INSNS (2), /* fp_add */
793 COSTS_N_INSNS (4), /* fp_mult_sf */
794 COSTS_N_INSNS (5), /* fp_mult_df */
795 COSTS_N_INSNS (12), /* fp_div_sf */
796 COSTS_N_INSNS (19), /* fp_div_df */
797 COSTS_N_INSNS (12), /* int_mult_si */
798 COSTS_N_INSNS (12), /* int_mult_di */
799 COSTS_N_INSNS (35), /* int_div_si */
800 COSTS_N_INSNS (35), /* int_div_di */
801 1, /* branch_cost */
802 4 /* memory_latency */
804 { /* 4KC */
805 SOFT_FP_COSTS,
806 COSTS_N_INSNS (6), /* int_mult_si */
807 COSTS_N_INSNS (6), /* int_mult_di */
808 COSTS_N_INSNS (36), /* int_div_si */
809 COSTS_N_INSNS (36), /* int_div_di */
810 1, /* branch_cost */
811 4 /* memory_latency */
813 { /* 4KP */
814 SOFT_FP_COSTS,
815 COSTS_N_INSNS (36), /* int_mult_si */
816 COSTS_N_INSNS (36), /* int_mult_di */
817 COSTS_N_INSNS (37), /* int_div_si */
818 COSTS_N_INSNS (37), /* int_div_di */
819 1, /* branch_cost */
820 4 /* memory_latency */
822 { /* 5KC */
823 SOFT_FP_COSTS,
824 COSTS_N_INSNS (4), /* int_mult_si */
825 COSTS_N_INSNS (11), /* int_mult_di */
826 COSTS_N_INSNS (36), /* int_div_si */
827 COSTS_N_INSNS (68), /* int_div_di */
828 1, /* branch_cost */
829 4 /* memory_latency */
831 { /* 5KF */
832 COSTS_N_INSNS (4), /* fp_add */
833 COSTS_N_INSNS (4), /* fp_mult_sf */
834 COSTS_N_INSNS (5), /* fp_mult_df */
835 COSTS_N_INSNS (17), /* fp_div_sf */
836 COSTS_N_INSNS (32), /* fp_div_df */
837 COSTS_N_INSNS (4), /* int_mult_si */
838 COSTS_N_INSNS (11), /* int_mult_di */
839 COSTS_N_INSNS (36), /* int_div_si */
840 COSTS_N_INSNS (68), /* int_div_di */
841 1, /* branch_cost */
842 4 /* memory_latency */
844 { /* 20KC */
845 COSTS_N_INSNS (4), /* fp_add */
846 COSTS_N_INSNS (4), /* fp_mult_sf */
847 COSTS_N_INSNS (5), /* fp_mult_df */
848 COSTS_N_INSNS (17), /* fp_div_sf */
849 COSTS_N_INSNS (32), /* fp_div_df */
850 COSTS_N_INSNS (4), /* int_mult_si */
851 COSTS_N_INSNS (7), /* int_mult_di */
852 COSTS_N_INSNS (42), /* int_div_si */
853 COSTS_N_INSNS (72), /* int_div_di */
854 1, /* branch_cost */
855 4 /* memory_latency */
857 { /* 24KC */
858 SOFT_FP_COSTS,
859 COSTS_N_INSNS (5), /* int_mult_si */
860 COSTS_N_INSNS (5), /* int_mult_di */
861 COSTS_N_INSNS (41), /* int_div_si */
862 COSTS_N_INSNS (41), /* int_div_di */
863 1, /* branch_cost */
864 4 /* memory_latency */
866 { /* 24KF2_1 */
867 COSTS_N_INSNS (8), /* fp_add */
868 COSTS_N_INSNS (8), /* fp_mult_sf */
869 COSTS_N_INSNS (10), /* fp_mult_df */
870 COSTS_N_INSNS (34), /* fp_div_sf */
871 COSTS_N_INSNS (64), /* fp_div_df */
872 COSTS_N_INSNS (5), /* int_mult_si */
873 COSTS_N_INSNS (5), /* int_mult_di */
874 COSTS_N_INSNS (41), /* int_div_si */
875 COSTS_N_INSNS (41), /* int_div_di */
876 1, /* branch_cost */
877 4 /* memory_latency */
879 { /* 24KF1_1 */
880 COSTS_N_INSNS (4), /* fp_add */
881 COSTS_N_INSNS (4), /* fp_mult_sf */
882 COSTS_N_INSNS (5), /* fp_mult_df */
883 COSTS_N_INSNS (17), /* fp_div_sf */
884 COSTS_N_INSNS (32), /* fp_div_df */
885 COSTS_N_INSNS (5), /* int_mult_si */
886 COSTS_N_INSNS (5), /* int_mult_di */
887 COSTS_N_INSNS (41), /* int_div_si */
888 COSTS_N_INSNS (41), /* int_div_di */
889 1, /* branch_cost */
890 4 /* memory_latency */
892 { /* 74KC */
893 SOFT_FP_COSTS,
894 COSTS_N_INSNS (5), /* int_mult_si */
895 COSTS_N_INSNS (5), /* int_mult_di */
896 COSTS_N_INSNS (41), /* int_div_si */
897 COSTS_N_INSNS (41), /* int_div_di */
898 1, /* branch_cost */
899 4 /* memory_latency */
901 { /* 74KF2_1 */
902 COSTS_N_INSNS (8), /* fp_add */
903 COSTS_N_INSNS (8), /* fp_mult_sf */
904 COSTS_N_INSNS (10), /* fp_mult_df */
905 COSTS_N_INSNS (34), /* fp_div_sf */
906 COSTS_N_INSNS (64), /* fp_div_df */
907 COSTS_N_INSNS (5), /* int_mult_si */
908 COSTS_N_INSNS (5), /* int_mult_di */
909 COSTS_N_INSNS (41), /* int_div_si */
910 COSTS_N_INSNS (41), /* int_div_di */
911 1, /* branch_cost */
912 4 /* memory_latency */
914 { /* 74KF1_1 */
915 COSTS_N_INSNS (4), /* fp_add */
916 COSTS_N_INSNS (4), /* fp_mult_sf */
917 COSTS_N_INSNS (5), /* fp_mult_df */
918 COSTS_N_INSNS (17), /* fp_div_sf */
919 COSTS_N_INSNS (32), /* fp_div_df */
920 COSTS_N_INSNS (5), /* int_mult_si */
921 COSTS_N_INSNS (5), /* int_mult_di */
922 COSTS_N_INSNS (41), /* int_div_si */
923 COSTS_N_INSNS (41), /* int_div_di */
924 1, /* branch_cost */
925 4 /* memory_latency */
927 { /* 74KF3_2 */
928 COSTS_N_INSNS (6), /* fp_add */
929 COSTS_N_INSNS (6), /* fp_mult_sf */
930 COSTS_N_INSNS (7), /* fp_mult_df */
931 COSTS_N_INSNS (25), /* fp_div_sf */
932 COSTS_N_INSNS (48), /* fp_div_df */
933 COSTS_N_INSNS (5), /* int_mult_si */
934 COSTS_N_INSNS (5), /* int_mult_di */
935 COSTS_N_INSNS (41), /* int_div_si */
936 COSTS_N_INSNS (41), /* int_div_di */
937 1, /* branch_cost */
938 4 /* memory_latency */
940 { /* Loongson-2E */
941 DEFAULT_COSTS
943 { /* Loongson-2F */
944 DEFAULT_COSTS
946 { /* Loongson-3A */
947 DEFAULT_COSTS
949 { /* M4k */
950 DEFAULT_COSTS
952 /* Octeon */
954 SOFT_FP_COSTS,
955 COSTS_N_INSNS (5), /* int_mult_si */
956 COSTS_N_INSNS (5), /* int_mult_di */
957 COSTS_N_INSNS (72), /* int_div_si */
958 COSTS_N_INSNS (72), /* int_div_di */
959 1, /* branch_cost */
960 4 /* memory_latency */
962 /* Octeon II */
964 SOFT_FP_COSTS,
965 COSTS_N_INSNS (6), /* int_mult_si */
966 COSTS_N_INSNS (6), /* int_mult_di */
967 COSTS_N_INSNS (18), /* int_div_si */
968 COSTS_N_INSNS (35), /* int_div_di */
969 4, /* branch_cost */
970 4 /* memory_latency */
972 /* Octeon III */
974 COSTS_N_INSNS (6), /* fp_add */
975 COSTS_N_INSNS (6), /* fp_mult_sf */
976 COSTS_N_INSNS (7), /* fp_mult_df */
977 COSTS_N_INSNS (25), /* fp_div_sf */
978 COSTS_N_INSNS (48), /* fp_div_df */
979 COSTS_N_INSNS (6), /* int_mult_si */
980 COSTS_N_INSNS (6), /* int_mult_di */
981 COSTS_N_INSNS (18), /* int_div_si */
982 COSTS_N_INSNS (35), /* int_div_di */
983 4, /* branch_cost */
984 4 /* memory_latency */
986 { /* R3900 */
987 COSTS_N_INSNS (2), /* fp_add */
988 COSTS_N_INSNS (4), /* fp_mult_sf */
989 COSTS_N_INSNS (5), /* fp_mult_df */
990 COSTS_N_INSNS (12), /* fp_div_sf */
991 COSTS_N_INSNS (19), /* fp_div_df */
992 COSTS_N_INSNS (2), /* int_mult_si */
993 COSTS_N_INSNS (2), /* int_mult_di */
994 COSTS_N_INSNS (35), /* int_div_si */
995 COSTS_N_INSNS (35), /* int_div_di */
996 1, /* branch_cost */
997 4 /* memory_latency */
999 { /* R6000 */
1000 COSTS_N_INSNS (3), /* fp_add */
1001 COSTS_N_INSNS (5), /* fp_mult_sf */
1002 COSTS_N_INSNS (6), /* fp_mult_df */
1003 COSTS_N_INSNS (15), /* fp_div_sf */
1004 COSTS_N_INSNS (16), /* fp_div_df */
1005 COSTS_N_INSNS (17), /* int_mult_si */
1006 COSTS_N_INSNS (17), /* int_mult_di */
1007 COSTS_N_INSNS (38), /* int_div_si */
1008 COSTS_N_INSNS (38), /* int_div_di */
1009 2, /* branch_cost */
1010 6 /* memory_latency */
1012 { /* R4000 */
1013 COSTS_N_INSNS (6), /* fp_add */
1014 COSTS_N_INSNS (7), /* fp_mult_sf */
1015 COSTS_N_INSNS (8), /* fp_mult_df */
1016 COSTS_N_INSNS (23), /* fp_div_sf */
1017 COSTS_N_INSNS (36), /* fp_div_df */
1018 COSTS_N_INSNS (10), /* int_mult_si */
1019 COSTS_N_INSNS (10), /* int_mult_di */
1020 COSTS_N_INSNS (69), /* int_div_si */
1021 COSTS_N_INSNS (69), /* int_div_di */
1022 2, /* branch_cost */
1023 6 /* memory_latency */
1025 { /* R4100 */
1026 DEFAULT_COSTS
1028 { /* R4111 */
1029 DEFAULT_COSTS
1031 { /* R4120 */
1032 DEFAULT_COSTS
1034 { /* R4130 */
1035 /* The only costs that appear to be updated here are
1036 integer multiplication. */
1037 SOFT_FP_COSTS,
1038 COSTS_N_INSNS (4), /* int_mult_si */
1039 COSTS_N_INSNS (6), /* int_mult_di */
1040 COSTS_N_INSNS (69), /* int_div_si */
1041 COSTS_N_INSNS (69), /* int_div_di */
1042 1, /* branch_cost */
1043 4 /* memory_latency */
1045 { /* R4300 */
1046 DEFAULT_COSTS
1048 { /* R4600 */
1049 DEFAULT_COSTS
1051 { /* R4650 */
1052 DEFAULT_COSTS
1054 { /* R4700 */
1055 DEFAULT_COSTS
1057 { /* R5000 */
1058 COSTS_N_INSNS (6), /* fp_add */
1059 COSTS_N_INSNS (4), /* fp_mult_sf */
1060 COSTS_N_INSNS (5), /* fp_mult_df */
1061 COSTS_N_INSNS (23), /* fp_div_sf */
1062 COSTS_N_INSNS (36), /* fp_div_df */
1063 COSTS_N_INSNS (5), /* int_mult_si */
1064 COSTS_N_INSNS (5), /* int_mult_di */
1065 COSTS_N_INSNS (36), /* int_div_si */
1066 COSTS_N_INSNS (36), /* int_div_di */
1067 1, /* branch_cost */
1068 4 /* memory_latency */
1070 { /* R5400 */
1071 COSTS_N_INSNS (6), /* fp_add */
1072 COSTS_N_INSNS (5), /* fp_mult_sf */
1073 COSTS_N_INSNS (6), /* fp_mult_df */
1074 COSTS_N_INSNS (30), /* fp_div_sf */
1075 COSTS_N_INSNS (59), /* fp_div_df */
1076 COSTS_N_INSNS (3), /* int_mult_si */
1077 COSTS_N_INSNS (4), /* int_mult_di */
1078 COSTS_N_INSNS (42), /* int_div_si */
1079 COSTS_N_INSNS (74), /* int_div_di */
1080 1, /* branch_cost */
1081 4 /* memory_latency */
1083 { /* R5500 */
1084 COSTS_N_INSNS (6), /* fp_add */
1085 COSTS_N_INSNS (5), /* fp_mult_sf */
1086 COSTS_N_INSNS (6), /* fp_mult_df */
1087 COSTS_N_INSNS (30), /* fp_div_sf */
1088 COSTS_N_INSNS (59), /* fp_div_df */
1089 COSTS_N_INSNS (5), /* int_mult_si */
1090 COSTS_N_INSNS (9), /* int_mult_di */
1091 COSTS_N_INSNS (42), /* int_div_si */
1092 COSTS_N_INSNS (74), /* int_div_di */
1093 1, /* branch_cost */
1094 4 /* memory_latency */
1096 { /* R5900 */
1097 COSTS_N_INSNS (4), /* fp_add */
1098 COSTS_N_INSNS (4), /* fp_mult_sf */
1099 COSTS_N_INSNS (256), /* fp_mult_df */
1100 COSTS_N_INSNS (8), /* fp_div_sf */
1101 COSTS_N_INSNS (256), /* fp_div_df */
1102 COSTS_N_INSNS (4), /* int_mult_si */
1103 COSTS_N_INSNS (256), /* int_mult_di */
1104 COSTS_N_INSNS (37), /* int_div_si */
1105 COSTS_N_INSNS (256), /* int_div_di */
1106 1, /* branch_cost */
1107 4 /* memory_latency */
1109 { /* R7000 */
1110 /* The only costs that are changed here are
1111 integer multiplication. */
1112 COSTS_N_INSNS (6), /* fp_add */
1113 COSTS_N_INSNS (7), /* fp_mult_sf */
1114 COSTS_N_INSNS (8), /* fp_mult_df */
1115 COSTS_N_INSNS (23), /* fp_div_sf */
1116 COSTS_N_INSNS (36), /* fp_div_df */
1117 COSTS_N_INSNS (5), /* int_mult_si */
1118 COSTS_N_INSNS (9), /* int_mult_di */
1119 COSTS_N_INSNS (69), /* int_div_si */
1120 COSTS_N_INSNS (69), /* int_div_di */
1121 1, /* branch_cost */
1122 4 /* memory_latency */
1124 { /* R8000 */
1125 DEFAULT_COSTS
1127 { /* R9000 */
1128 /* The only costs that are changed here are
1129 integer multiplication. */
1130 COSTS_N_INSNS (6), /* fp_add */
1131 COSTS_N_INSNS (7), /* fp_mult_sf */
1132 COSTS_N_INSNS (8), /* fp_mult_df */
1133 COSTS_N_INSNS (23), /* fp_div_sf */
1134 COSTS_N_INSNS (36), /* fp_div_df */
1135 COSTS_N_INSNS (3), /* int_mult_si */
1136 COSTS_N_INSNS (8), /* int_mult_di */
1137 COSTS_N_INSNS (69), /* int_div_si */
1138 COSTS_N_INSNS (69), /* int_div_di */
1139 1, /* branch_cost */
1140 4 /* memory_latency */
1142 { /* R1x000 */
1143 COSTS_N_INSNS (2), /* fp_add */
1144 COSTS_N_INSNS (2), /* fp_mult_sf */
1145 COSTS_N_INSNS (2), /* fp_mult_df */
1146 COSTS_N_INSNS (12), /* fp_div_sf */
1147 COSTS_N_INSNS (19), /* fp_div_df */
1148 COSTS_N_INSNS (5), /* int_mult_si */
1149 COSTS_N_INSNS (9), /* int_mult_di */
1150 COSTS_N_INSNS (34), /* int_div_si */
1151 COSTS_N_INSNS (66), /* int_div_di */
1152 1, /* branch_cost */
1153 4 /* memory_latency */
1155 { /* SB1 */
1156 /* These costs are the same as the SB-1A below. */
1157 COSTS_N_INSNS (4), /* fp_add */
1158 COSTS_N_INSNS (4), /* fp_mult_sf */
1159 COSTS_N_INSNS (4), /* fp_mult_df */
1160 COSTS_N_INSNS (24), /* fp_div_sf */
1161 COSTS_N_INSNS (32), /* fp_div_df */
1162 COSTS_N_INSNS (3), /* int_mult_si */
1163 COSTS_N_INSNS (4), /* int_mult_di */
1164 COSTS_N_INSNS (36), /* int_div_si */
1165 COSTS_N_INSNS (68), /* int_div_di */
1166 1, /* branch_cost */
1167 4 /* memory_latency */
1169 { /* SB1-A */
1170 /* These costs are the same as the SB-1 above. */
1171 COSTS_N_INSNS (4), /* fp_add */
1172 COSTS_N_INSNS (4), /* fp_mult_sf */
1173 COSTS_N_INSNS (4), /* fp_mult_df */
1174 COSTS_N_INSNS (24), /* fp_div_sf */
1175 COSTS_N_INSNS (32), /* fp_div_df */
1176 COSTS_N_INSNS (3), /* int_mult_si */
1177 COSTS_N_INSNS (4), /* int_mult_di */
1178 COSTS_N_INSNS (36), /* int_div_si */
1179 COSTS_N_INSNS (68), /* int_div_di */
1180 1, /* branch_cost */
1181 4 /* memory_latency */
1183 { /* SR71000 */
1184 DEFAULT_COSTS
1186 { /* XLR */
1187 SOFT_FP_COSTS,
1188 COSTS_N_INSNS (8), /* int_mult_si */
1189 COSTS_N_INSNS (8), /* int_mult_di */
1190 COSTS_N_INSNS (72), /* int_div_si */
1191 COSTS_N_INSNS (72), /* int_div_di */
1192 1, /* branch_cost */
1193 4 /* memory_latency */
1195 { /* XLP */
1196 /* These costs are the same as 5KF above. */
1197 COSTS_N_INSNS (4), /* fp_add */
1198 COSTS_N_INSNS (4), /* fp_mult_sf */
1199 COSTS_N_INSNS (5), /* fp_mult_df */
1200 COSTS_N_INSNS (17), /* fp_div_sf */
1201 COSTS_N_INSNS (32), /* fp_div_df */
1202 COSTS_N_INSNS (4), /* int_mult_si */
1203 COSTS_N_INSNS (11), /* int_mult_di */
1204 COSTS_N_INSNS (36), /* int_div_si */
1205 COSTS_N_INSNS (68), /* int_div_di */
1206 1, /* branch_cost */
1207 4 /* memory_latency */
1209 { /* P5600 */
1210 COSTS_N_INSNS (4), /* fp_add */
1211 COSTS_N_INSNS (5), /* fp_mult_sf */
1212 COSTS_N_INSNS (5), /* fp_mult_df */
1213 COSTS_N_INSNS (17), /* fp_div_sf */
1214 COSTS_N_INSNS (17), /* fp_div_df */
1215 COSTS_N_INSNS (5), /* int_mult_si */
1216 COSTS_N_INSNS (5), /* int_mult_di */
1217 COSTS_N_INSNS (8), /* int_div_si */
1218 COSTS_N_INSNS (8), /* int_div_di */
1219 2, /* branch_cost */
1220 4 /* memory_latency */
1222 { /* W32 */
1223 COSTS_N_INSNS (4), /* fp_add */
1224 COSTS_N_INSNS (4), /* fp_mult_sf */
1225 COSTS_N_INSNS (5), /* fp_mult_df */
1226 COSTS_N_INSNS (17), /* fp_div_sf */
1227 COSTS_N_INSNS (32), /* fp_div_df */
1228 COSTS_N_INSNS (5), /* int_mult_si */
1229 COSTS_N_INSNS (5), /* int_mult_di */
1230 COSTS_N_INSNS (41), /* int_div_si */
1231 COSTS_N_INSNS (41), /* int_div_di */
1232 1, /* branch_cost */
1233 4 /* memory_latency */
1235 { /* W64 */
1236 COSTS_N_INSNS (4), /* fp_add */
1237 COSTS_N_INSNS (4), /* fp_mult_sf */
1238 COSTS_N_INSNS (5), /* fp_mult_df */
1239 COSTS_N_INSNS (17), /* fp_div_sf */
1240 COSTS_N_INSNS (32), /* fp_div_df */
1241 COSTS_N_INSNS (5), /* int_mult_si */
1242 COSTS_N_INSNS (5), /* int_mult_di */
1243 COSTS_N_INSNS (41), /* int_div_si */
1244 COSTS_N_INSNS (41), /* int_div_di */
1245 1, /* branch_cost */
1246 4 /* memory_latency */
1248 { /* I6400 */
1249 COSTS_N_INSNS (4), /* fp_add */
1250 COSTS_N_INSNS (5), /* fp_mult_sf */
1251 COSTS_N_INSNS (5), /* fp_mult_df */
1252 COSTS_N_INSNS (32), /* fp_div_sf */
1253 COSTS_N_INSNS (32), /* fp_div_df */
1254 COSTS_N_INSNS (5), /* int_mult_si */
1255 COSTS_N_INSNS (5), /* int_mult_di */
1256 COSTS_N_INSNS (36), /* int_div_si */
1257 COSTS_N_INSNS (36), /* int_div_di */
1258 2, /* branch_cost */
1259 4 /* memory_latency */
1263 static rtx mips_find_pic_call_symbol (rtx, rtx, bool);
1264 static int mips_register_move_cost (machine_mode, reg_class_t,
1265 reg_class_t);
1266 static unsigned int mips_function_arg_boundary (machine_mode, const_tree);
1267 static machine_mode mips_get_reg_raw_mode (int regno);
1269 /* This hash table keeps track of implicit "mips16" and "nomips16" attributes
1270 for -mflip_mips16. It maps decl names onto a boolean mode setting. */
1271 struct GTY (()) mflip_mips16_entry {
1272 const char *name;
1273 bool mips16_p;
1275 static GTY ((param_is (struct mflip_mips16_entry))) htab_t mflip_mips16_htab;
1277 /* Hash table callbacks for mflip_mips16_htab. */
1279 static hashval_t
1280 mflip_mips16_htab_hash (const void *entry)
1282 return htab_hash_string (((const struct mflip_mips16_entry *) entry)->name);
1285 static int
1286 mflip_mips16_htab_eq (const void *entry, const void *name)
1288 return strcmp (((const struct mflip_mips16_entry *) entry)->name,
1289 (const char *) name) == 0;
1292 /* True if -mflip-mips16 should next add an attribute for the default MIPS16
1293 mode, false if it should next add an attribute for the opposite mode. */
1294 static GTY(()) bool mips16_flipper;
1296 /* DECL is a function that needs a default "mips16" or "nomips16" attribute
1297 for -mflip-mips16. Return true if it should use "mips16" and false if
1298 it should use "nomips16". */
1300 static bool
1301 mflip_mips16_use_mips16_p (tree decl)
1303 struct mflip_mips16_entry *entry;
1304 const char *name;
1305 hashval_t hash;
1306 void **slot;
1307 bool base_is_mips16 = (mips_base_compression_flags & MASK_MIPS16) != 0;
1309 /* Use the opposite of the command-line setting for anonymous decls. */
1310 if (!DECL_NAME (decl))
1311 return !base_is_mips16;
1313 if (!mflip_mips16_htab)
1314 mflip_mips16_htab = htab_create_ggc (37, mflip_mips16_htab_hash,
1315 mflip_mips16_htab_eq, NULL);
1317 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1318 hash = htab_hash_string (name);
1319 slot = htab_find_slot_with_hash (mflip_mips16_htab, name, hash, INSERT);
1320 entry = (struct mflip_mips16_entry *) *slot;
1321 if (!entry)
1323 mips16_flipper = !mips16_flipper;
1324 entry = ggc_alloc_mflip_mips16_entry ();
1325 entry->name = name;
1326 entry->mips16_p = mips16_flipper ? !base_is_mips16 : base_is_mips16;
1327 *slot = entry;
1329 return entry->mips16_p;
1332 /* Predicates to test for presence of "near" and "far"/"long_call"
1333 attributes on the given TYPE. */
1335 static bool
1336 mips_near_type_p (const_tree type)
1338 return lookup_attribute ("near", TYPE_ATTRIBUTES (type)) != NULL;
1341 static bool
1342 mips_far_type_p (const_tree type)
1344 return (lookup_attribute ("long_call", TYPE_ATTRIBUTES (type)) != NULL
1345 || lookup_attribute ("far", TYPE_ATTRIBUTES (type)) != NULL);
1349 /* Check if the interrupt attribute is set for a function. */
1351 static bool
1352 mips_interrupt_type_p (tree type)
1354 return lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type)) != NULL;
1357 /* Check if the attribute to use shadow register set is set for a function. */
1359 static bool
1360 mips_use_shadow_register_set_p (tree type)
1362 return lookup_attribute ("use_shadow_register_set",
1363 TYPE_ATTRIBUTES (type)) != NULL;
1366 /* Check if the attribute to keep interrupts masked is set for a function. */
1368 static bool
1369 mips_keep_interrupts_masked_p (tree type)
1371 return lookup_attribute ("keep_interrupts_masked",
1372 TYPE_ATTRIBUTES (type)) != NULL;
1375 /* Check if the attribute to use debug exception return is set for
1376 a function. */
1378 static bool
1379 mips_use_debug_exception_return_p (tree type)
1381 return lookup_attribute ("use_debug_exception_return",
1382 TYPE_ATTRIBUTES (type)) != NULL;
1385 /* Return the set of compression modes that are explicitly required
1386 by the attributes in ATTRIBUTES. */
1388 static unsigned int
1389 mips_get_compress_on_flags (tree attributes)
1391 unsigned int flags = 0;
1393 if (lookup_attribute ("mips16", attributes) != NULL)
1394 flags |= MASK_MIPS16;
1396 if (lookup_attribute ("micromips", attributes) != NULL)
1397 flags |= MASK_MICROMIPS;
1399 return flags;
1402 /* Return the set of compression modes that are explicitly forbidden
1403 by the attributes in ATTRIBUTES. */
1405 static unsigned int
1406 mips_get_compress_off_flags (tree attributes)
1408 unsigned int flags = 0;
1410 if (lookup_attribute ("nocompression", attributes) != NULL)
1411 flags |= MASK_MIPS16 | MASK_MICROMIPS;
1413 if (lookup_attribute ("nomips16", attributes) != NULL)
1414 flags |= MASK_MIPS16;
1416 if (lookup_attribute ("nomicromips", attributes) != NULL)
1417 flags |= MASK_MICROMIPS;
1419 return flags;
1422 /* Return the compression mode that should be used for function DECL.
1423 Return the ambient setting if DECL is null. */
1425 static unsigned int
1426 mips_get_compress_mode (tree decl)
1428 unsigned int flags, force_on;
1430 flags = mips_base_compression_flags;
1431 if (decl)
1433 /* Nested functions must use the same frame pointer as their
1434 parent and must therefore use the same ISA mode. */
1435 tree parent = decl_function_context (decl);
1436 if (parent)
1437 decl = parent;
1438 force_on = mips_get_compress_on_flags (DECL_ATTRIBUTES (decl));
1439 if (force_on)
1440 return force_on;
1441 flags &= ~mips_get_compress_off_flags (DECL_ATTRIBUTES (decl));
1443 return flags;
1446 /* Return the attribute name associated with MASK_MIPS16 and MASK_MICROMIPS
1447 flags FLAGS. */
1449 static const char *
1450 mips_get_compress_on_name (unsigned int flags)
1452 if (flags == MASK_MIPS16)
1453 return "mips16";
1454 return "micromips";
1457 /* Return the attribute name that forbids MASK_MIPS16 and MASK_MICROMIPS
1458 flags FLAGS. */
1460 static const char *
1461 mips_get_compress_off_name (unsigned int flags)
1463 if (flags == MASK_MIPS16)
1464 return "nomips16";
1465 if (flags == MASK_MICROMIPS)
1466 return "nomicromips";
1467 return "nocompression";
1470 /* Implement TARGET_COMP_TYPE_ATTRIBUTES. */
1472 static int
1473 mips_comp_type_attributes (const_tree type1, const_tree type2)
1475 /* Disallow mixed near/far attributes. */
1476 if (mips_far_type_p (type1) && mips_near_type_p (type2))
1477 return 0;
1478 if (mips_near_type_p (type1) && mips_far_type_p (type2))
1479 return 0;
1480 return 1;
1483 /* Implement TARGET_INSERT_ATTRIBUTES. */
1485 static void
1486 mips_insert_attributes (tree decl, tree *attributes)
1488 const char *name;
1489 unsigned int compression_flags, nocompression_flags;
1491 /* Check for "mips16" and "nomips16" attributes. */
1492 compression_flags = mips_get_compress_on_flags (*attributes);
1493 nocompression_flags = mips_get_compress_off_flags (*attributes);
1495 if (TREE_CODE (decl) != FUNCTION_DECL)
1497 if (nocompression_flags)
1498 error ("%qs attribute only applies to functions",
1499 mips_get_compress_off_name (nocompression_flags));
1501 if (compression_flags)
1502 error ("%qs attribute only applies to functions",
1503 mips_get_compress_on_name (nocompression_flags));
1505 else
1507 compression_flags |= mips_get_compress_on_flags (DECL_ATTRIBUTES (decl));
1508 nocompression_flags |=
1509 mips_get_compress_off_flags (DECL_ATTRIBUTES (decl));
1511 if (compression_flags && nocompression_flags)
1512 error ("%qE cannot have both %qs and %qs attributes",
1513 DECL_NAME (decl), mips_get_compress_on_name (compression_flags),
1514 mips_get_compress_off_name (nocompression_flags));
1516 if (compression_flags & MASK_MIPS16
1517 && compression_flags & MASK_MICROMIPS)
1518 error ("%qE cannot have both %qs and %qs attributes",
1519 DECL_NAME (decl), "mips16", "micromips");
1521 if (TARGET_FLIP_MIPS16
1522 && !DECL_ARTIFICIAL (decl)
1523 && compression_flags == 0
1524 && nocompression_flags == 0)
1526 /* Implement -mflip-mips16. If DECL has neither a "nomips16" nor a
1527 "mips16" attribute, arbitrarily pick one. We must pick the same
1528 setting for duplicate declarations of a function. */
1529 name = mflip_mips16_use_mips16_p (decl) ? "mips16" : "nomips16";
1530 *attributes = tree_cons (get_identifier (name), NULL, *attributes);
1531 name = "nomicromips";
1532 *attributes = tree_cons (get_identifier (name), NULL, *attributes);
1537 /* Implement TARGET_MERGE_DECL_ATTRIBUTES. */
1539 static tree
1540 mips_merge_decl_attributes (tree olddecl, tree newdecl)
1542 unsigned int diff;
1544 diff = (mips_get_compress_on_flags (DECL_ATTRIBUTES (olddecl))
1545 ^ mips_get_compress_on_flags (DECL_ATTRIBUTES (newdecl)));
1546 if (diff)
1547 error ("%qE redeclared with conflicting %qs attributes",
1548 DECL_NAME (newdecl), mips_get_compress_on_name (diff));
1550 diff = (mips_get_compress_off_flags (DECL_ATTRIBUTES (olddecl))
1551 ^ mips_get_compress_off_flags (DECL_ATTRIBUTES (newdecl)));
1552 if (diff)
1553 error ("%qE redeclared with conflicting %qs attributes",
1554 DECL_NAME (newdecl), mips_get_compress_off_name (diff));
1556 return merge_attributes (DECL_ATTRIBUTES (olddecl),
1557 DECL_ATTRIBUTES (newdecl));
1560 /* Implement TARGET_CAN_INLINE_P. */
1562 static bool
1563 mips_can_inline_p (tree caller, tree callee)
1565 if (mips_get_compress_mode (callee) != mips_get_compress_mode (caller))
1566 return false;
1567 return default_target_can_inline_p (caller, callee);
1570 /* If X is a PLUS of a CONST_INT, return the two terms in *BASE_PTR
1571 and *OFFSET_PTR. Return X in *BASE_PTR and 0 in *OFFSET_PTR otherwise. */
1573 static void
1574 mips_split_plus (rtx x, rtx *base_ptr, HOST_WIDE_INT *offset_ptr)
1576 if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
1578 *base_ptr = XEXP (x, 0);
1579 *offset_ptr = INTVAL (XEXP (x, 1));
1581 else
1583 *base_ptr = x;
1584 *offset_ptr = 0;
1588 static unsigned int mips_build_integer (struct mips_integer_op *,
1589 unsigned HOST_WIDE_INT);
1591 /* A subroutine of mips_build_integer, with the same interface.
1592 Assume that the final action in the sequence should be a left shift. */
1594 static unsigned int
1595 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value)
1597 unsigned int i, shift;
1599 /* Shift VALUE right until its lowest bit is set. Shift arithmetically
1600 since signed numbers are easier to load than unsigned ones. */
1601 shift = 0;
1602 while ((value & 1) == 0)
1603 value /= 2, shift++;
1605 i = mips_build_integer (codes, value);
1606 codes[i].code = ASHIFT;
1607 codes[i].value = shift;
1608 return i + 1;
1611 /* As for mips_build_shift, but assume that the final action will be
1612 an IOR or PLUS operation. */
1614 static unsigned int
1615 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value)
1617 unsigned HOST_WIDE_INT high;
1618 unsigned int i;
1620 high = value & ~(unsigned HOST_WIDE_INT) 0xffff;
1621 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000)
1623 /* The constant is too complex to load with a simple LUI/ORI pair,
1624 so we want to give the recursive call as many trailing zeros as
1625 possible. In this case, we know bit 16 is set and that the
1626 low 16 bits form a negative number. If we subtract that number
1627 from VALUE, we will clear at least the lowest 17 bits, maybe more. */
1628 i = mips_build_integer (codes, CONST_HIGH_PART (value));
1629 codes[i].code = PLUS;
1630 codes[i].value = CONST_LOW_PART (value);
1632 else
1634 /* Either this is a simple LUI/ORI pair, or clearing the lowest 16
1635 bits gives a value with at least 17 trailing zeros. */
1636 i = mips_build_integer (codes, high);
1637 codes[i].code = IOR;
1638 codes[i].value = value & 0xffff;
1640 return i + 1;
1643 /* Fill CODES with a sequence of rtl operations to load VALUE.
1644 Return the number of operations needed. */
1646 static unsigned int
1647 mips_build_integer (struct mips_integer_op *codes,
1648 unsigned HOST_WIDE_INT value)
1650 if (SMALL_OPERAND (value)
1651 || SMALL_OPERAND_UNSIGNED (value)
1652 || LUI_OPERAND (value))
1654 /* The value can be loaded with a single instruction. */
1655 codes[0].code = UNKNOWN;
1656 codes[0].value = value;
1657 return 1;
1659 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value)))
1661 /* Either the constant is a simple LUI/ORI combination or its
1662 lowest bit is set. We don't want to shift in this case. */
1663 return mips_build_lower (codes, value);
1665 else if ((value & 0xffff) == 0)
1667 /* The constant will need at least three actions. The lowest
1668 16 bits are clear, so the final action will be a shift. */
1669 return mips_build_shift (codes, value);
1671 else
1673 /* The final action could be a shift, add or inclusive OR.
1674 Rather than use a complex condition to select the best
1675 approach, try both mips_build_shift and mips_build_lower
1676 and pick the one that gives the shortest sequence.
1677 Note that this case is only used once per constant. */
1678 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS];
1679 unsigned int cost, alt_cost;
1681 cost = mips_build_shift (codes, value);
1682 alt_cost = mips_build_lower (alt_codes, value);
1683 if (alt_cost < cost)
1685 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0]));
1686 cost = alt_cost;
1688 return cost;
1692 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */
1694 static bool
1695 mips_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
1697 return mips_const_insns (x) > 0;
1700 /* Return a SYMBOL_REF for a MIPS16 function called NAME. */
1702 static rtx
1703 mips16_stub_function (const char *name)
1705 rtx x;
1707 x = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
1708 SYMBOL_REF_FLAGS (x) |= (SYMBOL_FLAG_EXTERNAL | SYMBOL_FLAG_FUNCTION);
1709 return x;
1712 /* Return a legitimate call address for STUB, given that STUB is a MIPS16
1713 support function. */
1715 static rtx
1716 mips16_stub_call_address (mips_one_only_stub *stub)
1718 rtx fn = mips16_stub_function (stub->get_name ());
1719 SYMBOL_REF_FLAGS (fn) |= SYMBOL_FLAG_LOCAL;
1720 if (!call_insn_operand (fn, VOIDmode))
1721 fn = force_reg (Pmode, fn);
1722 return fn;
1725 /* A stub for moving the thread pointer into TLS_GET_TP_REGNUM. */
1727 class mips16_rdhwr_one_only_stub : public mips_one_only_stub
1729 virtual const char *get_name ();
1730 virtual void output_body ();
1733 const char *
1734 mips16_rdhwr_one_only_stub::get_name ()
1736 return "__mips16_rdhwr";
1739 void
1740 mips16_rdhwr_one_only_stub::output_body ()
1742 fprintf (asm_out_file,
1743 "\t.set\tpush\n"
1744 "\t.set\tmips32r2\n"
1745 "\t.set\tnoreorder\n"
1746 "\trdhwr\t$3,$29\n"
1747 "\t.set\tpop\n"
1748 "\tj\t$31\n");
1751 /* A stub for moving the FCSR into GET_FCSR_REGNUM. */
1752 class mips16_get_fcsr_one_only_stub : public mips_one_only_stub
1754 virtual const char *get_name ();
1755 virtual void output_body ();
1758 const char *
1759 mips16_get_fcsr_one_only_stub::get_name ()
1761 return "__mips16_get_fcsr";
1764 void
1765 mips16_get_fcsr_one_only_stub::output_body ()
1767 fprintf (asm_out_file,
1768 "\tcfc1\t%s,$31\n"
1769 "\tj\t$31\n", reg_names[GET_FCSR_REGNUM]);
1772 /* A stub for moving SET_FCSR_REGNUM into the FCSR. */
1773 class mips16_set_fcsr_one_only_stub : public mips_one_only_stub
1775 virtual const char *get_name ();
1776 virtual void output_body ();
1779 const char *
1780 mips16_set_fcsr_one_only_stub::get_name ()
1782 return "__mips16_set_fcsr";
1785 void
1786 mips16_set_fcsr_one_only_stub::output_body ()
1788 fprintf (asm_out_file,
1789 "\tctc1\t%s,$31\n"
1790 "\tj\t$31\n", reg_names[SET_FCSR_REGNUM]);
1793 /* Return true if symbols of type TYPE require a GOT access. */
1795 static bool
1796 mips_got_symbol_type_p (enum mips_symbol_type type)
1798 switch (type)
1800 case SYMBOL_GOT_PAGE_OFST:
1801 case SYMBOL_GOT_DISP:
1802 return true;
1804 default:
1805 return false;
1809 /* Return true if X is a thread-local symbol. */
1811 static bool
1812 mips_tls_symbol_p (rtx x)
1814 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0;
1817 /* Return true if SYMBOL_REF X is associated with a global symbol
1818 (in the STB_GLOBAL sense). */
1820 static bool
1821 mips_global_symbol_p (const_rtx x)
1823 const_tree decl = SYMBOL_REF_DECL (x);
1825 if (!decl)
1826 return !SYMBOL_REF_LOCAL_P (x) || SYMBOL_REF_EXTERNAL_P (x);
1828 /* Weakref symbols are not TREE_PUBLIC, but their targets are global
1829 or weak symbols. Relocations in the object file will be against
1830 the target symbol, so it's that symbol's binding that matters here. */
1831 return DECL_P (decl) && (TREE_PUBLIC (decl) || DECL_WEAK (decl));
1834 /* Return true if function X is a libgcc MIPS16 stub function. */
1836 static bool
1837 mips16_stub_function_p (const_rtx x)
1839 return (GET_CODE (x) == SYMBOL_REF
1840 && strncmp (XSTR (x, 0), "__mips16_", 9) == 0);
1843 /* Return true if function X is a locally-defined and locally-binding
1844 MIPS16 function. */
1846 static bool
1847 mips16_local_function_p (const_rtx x)
1849 return (GET_CODE (x) == SYMBOL_REF
1850 && SYMBOL_REF_LOCAL_P (x)
1851 && !SYMBOL_REF_EXTERNAL_P (x)
1852 && (mips_get_compress_mode (SYMBOL_REF_DECL (x)) & MASK_MIPS16));
1855 /* Return true if SYMBOL_REF X binds locally. */
1857 static bool
1858 mips_symbol_binds_local_p (const_rtx x)
1860 return (SYMBOL_REF_DECL (x)
1861 ? targetm.binds_local_p (SYMBOL_REF_DECL (x))
1862 : SYMBOL_REF_LOCAL_P (x));
1865 bool
1866 mips_const_vector_bitimm_set_p (rtx op, machine_mode mode)
1868 if (GET_CODE (op) == CONST_VECTOR && op != const0_rtx)
1870 rtx elt0 = CONST_VECTOR_ELT (op, 0);
1871 HOST_WIDE_INT val = INTVAL (elt0);
1872 int vlog2 = exact_log2 (val);
1874 if (vlog2 != -1)
1876 gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT);
1877 if (!(0 <= vlog2 && vlog2 <= GET_MODE_UNIT_SIZE (mode) - 1))
1878 return false;
1880 return mips_const_vector_same_int_p (op, mode, 0, val);
1884 return false;
1887 bool
1888 mips_const_vector_bitimm_clr_p (rtx op, machine_mode mode)
1890 if (GET_CODE (op) == CONST_VECTOR && op != constm1_rtx)
1892 rtx elt0 = CONST_VECTOR_ELT (op, 0);
1893 HOST_WIDE_INT val = INTVAL (elt0);
1894 int vlog2 = exact_log2 (~val);
1896 if (vlog2 != -1)
1898 gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT);
1899 if (!(0 <= vlog2 && vlog2 <= GET_MODE_UNIT_SIZE (mode) - 1))
1900 return false;
1902 return mips_const_vector_same_val_p (op, mode);
1906 return false;
1909 /* Return true if OP is a constant vector with the number of units in MODE,
1910 and each unit has the same value. */
1912 bool
1913 mips_const_vector_same_val_p (rtx op, machine_mode mode)
1915 int i, nunits = GET_MODE_NUNITS (mode);
1916 rtx first;
1918 if (GET_CODE (op) != CONST_VECTOR || GET_MODE (op) != mode)
1919 return false;
1921 first = CONST_VECTOR_ELT (op, 0);
1922 for (i = 1; i < nunits; i++)
1923 if (!rtx_equal_p (first, CONST_VECTOR_ELT (op, i)))
1924 return false;
1926 return true;
1929 /* Return true if OP is a constant vector with the number of units in MODE,
1930 and each unit has the same value. */
1932 bool
1933 mips_const_vector_same_byte_p (rtx op, machine_mode mode)
1935 int i, nunits = GET_MODE_NUNITS (mode);
1936 rtx first;
1938 gcc_assert (mode == V16QImode);
1940 if (GET_CODE (op) != CONST_VECTOR || GET_MODE (op) != mode)
1941 return false;
1943 first = CONST_VECTOR_ELT (op, 0);
1944 for (i = 1; i < nunits; i++)
1945 if (!rtx_equal_p (first, CONST_VECTOR_ELT (op, i)))
1946 return false;
1948 /* It's an 8-bit mode don't care if signed or unsigned. */
1949 return true;
1952 /* Return true if OP is a constant vector with the number of units in MODE,
1953 and each unit has the same integer value in the range [LOW, HIGH]. */
1955 bool
1956 mips_const_vector_same_int_p (rtx op, machine_mode mode, HOST_WIDE_INT low,
1957 HOST_WIDE_INT high)
1959 HOST_WIDE_INT value;
1960 rtx elem0;
1962 if (!mips_const_vector_same_val_p (op, mode))
1963 return false;
1965 elem0 = CONST_VECTOR_ELT (op, 0);
1966 if (!CONST_INT_P (elem0))
1967 return false;
1969 value = INTVAL (elem0);
1970 return (value >= low && value <= high);
1973 /* Return true if rtx constants of mode MODE should be put into a small
1974 data section. */
1976 static bool
1977 mips_rtx_constant_in_small_data_p (machine_mode mode)
1979 return (!TARGET_EMBEDDED_DATA
1980 && TARGET_LOCAL_SDATA
1981 && GET_MODE_SIZE (mode) <= mips_small_data_threshold);
1984 /* Return true if X should not be moved directly into register $25.
1985 We need this because many versions of GAS will treat "la $25,foo" as
1986 part of a call sequence and so allow a global "foo" to be lazily bound. */
1988 bool
1989 mips_dangerous_for_la25_p (rtx x)
1991 return (!TARGET_EXPLICIT_RELOCS
1992 && TARGET_USE_GOT
1993 && GET_CODE (x) == SYMBOL_REF
1994 && mips_global_symbol_p (x));
1997 /* Return true if calls to X might need $25 to be valid on entry. */
1999 bool
2000 mips_use_pic_fn_addr_reg_p (const_rtx x)
2002 if (!TARGET_USE_PIC_FN_ADDR_REG)
2003 return false;
2005 /* MIPS16 stub functions are guaranteed not to use $25. */
2006 if (mips16_stub_function_p (x))
2007 return false;
2009 if (GET_CODE (x) == SYMBOL_REF)
2011 /* If PLTs and copy relocations are available, the static linker
2012 will make sure that $25 is valid on entry to the target function. */
2013 if (TARGET_ABICALLS_PIC0)
2014 return false;
2016 /* Locally-defined functions use absolute accesses to set up
2017 the global pointer. */
2018 if (TARGET_ABSOLUTE_ABICALLS
2019 && mips_symbol_binds_local_p (x)
2020 && !SYMBOL_REF_EXTERNAL_P (x))
2021 return false;
2024 return true;
2027 /* Return the method that should be used to access SYMBOL_REF or
2028 LABEL_REF X in context CONTEXT. */
2030 static enum mips_symbol_type
2031 mips_classify_symbol (const_rtx x, enum mips_symbol_context context)
2033 if (TARGET_RTP_PIC)
2034 return SYMBOL_GOT_DISP;
2036 if (GET_CODE (x) == LABEL_REF)
2038 /* Only return SYMBOL_PC_RELATIVE if we are generating MIPS16
2039 code and if we know that the label is in the current function's
2040 text section. LABEL_REFs are used for jump tables as well as
2041 text labels, so we must check whether jump tables live in the
2042 text section. */
2043 if (TARGET_MIPS16_SHORT_JUMP_TABLES
2044 && !LABEL_REF_NONLOCAL_P (x))
2045 return SYMBOL_PC_RELATIVE;
2047 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
2048 return SYMBOL_GOT_PAGE_OFST;
2050 return SYMBOL_ABSOLUTE;
2053 gcc_assert (GET_CODE (x) == SYMBOL_REF);
2055 if (SYMBOL_REF_TLS_MODEL (x))
2056 return SYMBOL_TLS;
2058 if (CONSTANT_POOL_ADDRESS_P (x))
2060 if (TARGET_MIPS16_TEXT_LOADS)
2061 return SYMBOL_PC_RELATIVE;
2063 if (TARGET_MIPS16_PCREL_LOADS && context == SYMBOL_CONTEXT_MEM)
2064 return SYMBOL_PC_RELATIVE;
2066 if (mips_rtx_constant_in_small_data_p (get_pool_mode (x)))
2067 return SYMBOL_GP_RELATIVE;
2070 /* Do not use small-data accesses for weak symbols; they may end up
2071 being zero. */
2072 if (TARGET_GPOPT && SYMBOL_REF_SMALL_P (x) && !SYMBOL_REF_WEAK (x))
2073 return SYMBOL_GP_RELATIVE;
2075 /* Don't use GOT accesses for locally-binding symbols when -mno-shared
2076 is in effect. */
2077 if (TARGET_ABICALLS_PIC2
2078 && !(TARGET_ABSOLUTE_ABICALLS && mips_symbol_binds_local_p (x)))
2080 /* There are three cases to consider:
2082 - o32 PIC (either with or without explicit relocs)
2083 - n32/n64 PIC without explicit relocs
2084 - n32/n64 PIC with explicit relocs
2086 In the first case, both local and global accesses will use an
2087 R_MIPS_GOT16 relocation. We must correctly predict which of
2088 the two semantics (local or global) the assembler and linker
2089 will apply. The choice depends on the symbol's binding rather
2090 than its visibility.
2092 In the second case, the assembler will not use R_MIPS_GOT16
2093 relocations, but it chooses between local and global accesses
2094 in the same way as for o32 PIC.
2096 In the third case we have more freedom since both forms of
2097 access will work for any kind of symbol. However, there seems
2098 little point in doing things differently. */
2099 if (mips_global_symbol_p (x))
2100 return SYMBOL_GOT_DISP;
2102 return SYMBOL_GOT_PAGE_OFST;
2105 return SYMBOL_ABSOLUTE;
2108 /* Classify the base of symbolic expression X, given that X appears in
2109 context CONTEXT. */
2111 static enum mips_symbol_type
2112 mips_classify_symbolic_expression (rtx x, enum mips_symbol_context context)
2114 rtx offset;
2116 split_const (x, &x, &offset);
2117 if (UNSPEC_ADDRESS_P (x))
2118 return UNSPEC_ADDRESS_TYPE (x);
2120 return mips_classify_symbol (x, context);
2123 /* Return true if OFFSET is within the range [0, ALIGN), where ALIGN
2124 is the alignment in bytes of SYMBOL_REF X. */
2126 static bool
2127 mips_offset_within_alignment_p (rtx x, HOST_WIDE_INT offset)
2129 HOST_WIDE_INT align;
2131 align = SYMBOL_REF_DECL (x) ? DECL_ALIGN_UNIT (SYMBOL_REF_DECL (x)) : 1;
2132 return IN_RANGE (offset, 0, align - 1);
2135 /* Return true if X is a symbolic constant that can be used in context
2136 CONTEXT. If it is, store the type of the symbol in *SYMBOL_TYPE. */
2138 bool
2139 mips_symbolic_constant_p (rtx x, enum mips_symbol_context context,
2140 enum mips_symbol_type *symbol_type)
2142 rtx offset;
2144 split_const (x, &x, &offset);
2145 if (UNSPEC_ADDRESS_P (x))
2147 *symbol_type = UNSPEC_ADDRESS_TYPE (x);
2148 x = UNSPEC_ADDRESS (x);
2150 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
2152 *symbol_type = mips_classify_symbol (x, context);
2153 if (*symbol_type == SYMBOL_TLS)
2154 return false;
2156 else
2157 return false;
2159 if (offset == const0_rtx)
2160 return true;
2162 /* Check whether a nonzero offset is valid for the underlying
2163 relocations. */
2164 switch (*symbol_type)
2166 case SYMBOL_ABSOLUTE:
2167 case SYMBOL_64_HIGH:
2168 case SYMBOL_64_MID:
2169 case SYMBOL_64_LOW:
2170 /* If the target has 64-bit pointers and the object file only
2171 supports 32-bit symbols, the values of those symbols will be
2172 sign-extended. In this case we can't allow an arbitrary offset
2173 in case the 32-bit value X + OFFSET has a different sign from X. */
2174 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS)
2175 return offset_within_block_p (x, INTVAL (offset));
2177 /* In other cases the relocations can handle any offset. */
2178 return true;
2180 case SYMBOL_PC_RELATIVE:
2181 /* Allow constant pool references to be converted to LABEL+CONSTANT.
2182 In this case, we no longer have access to the underlying constant,
2183 but the original symbol-based access was known to be valid. */
2184 if (GET_CODE (x) == LABEL_REF)
2185 return true;
2187 /* Fall through. */
2189 case SYMBOL_GP_RELATIVE:
2190 /* Make sure that the offset refers to something within the
2191 same object block. This should guarantee that the final
2192 PC- or GP-relative offset is within the 16-bit limit. */
2193 return offset_within_block_p (x, INTVAL (offset));
2195 case SYMBOL_GOT_PAGE_OFST:
2196 case SYMBOL_GOTOFF_PAGE:
2197 /* If the symbol is global, the GOT entry will contain the symbol's
2198 address, and we will apply a 16-bit offset after loading it.
2199 If the symbol is local, the linker should provide enough local
2200 GOT entries for a 16-bit offset, but larger offsets may lead
2201 to GOT overflow. */
2202 return SMALL_INT (offset);
2204 case SYMBOL_TPREL:
2205 case SYMBOL_DTPREL:
2206 /* There is no carry between the HI and LO REL relocations, so the
2207 offset is only valid if we know it won't lead to such a carry. */
2208 return mips_offset_within_alignment_p (x, INTVAL (offset));
2210 case SYMBOL_GOT_DISP:
2211 case SYMBOL_GOTOFF_DISP:
2212 case SYMBOL_GOTOFF_CALL:
2213 case SYMBOL_GOTOFF_LOADGP:
2214 case SYMBOL_TLSGD:
2215 case SYMBOL_TLSLDM:
2216 case SYMBOL_GOTTPREL:
2217 case SYMBOL_TLS:
2218 case SYMBOL_HALF:
2219 return false;
2221 gcc_unreachable ();
2224 /* Like mips_symbol_insns, but treat extended MIPS16 instructions as a
2225 single instruction. We rely on the fact that, in the worst case,
2226 all instructions involved in a MIPS16 address calculation are usually
2227 extended ones. */
2229 static int
2230 mips_symbol_insns_1 (enum mips_symbol_type type, machine_mode mode)
2232 if (mips_use_pcrel_pool_p[(int) type])
2234 if (mode == MAX_MACHINE_MODE)
2235 /* LEAs will be converted into constant-pool references by
2236 mips_reorg. */
2237 type = SYMBOL_PC_RELATIVE;
2238 else
2239 /* The constant must be loaded and then dereferenced. */
2240 return 0;
2243 switch (type)
2245 case SYMBOL_ABSOLUTE:
2246 /* When using 64-bit symbols, we need 5 preparatory instructions,
2247 such as:
2249 lui $at,%highest(symbol)
2250 daddiu $at,$at,%higher(symbol)
2251 dsll $at,$at,16
2252 daddiu $at,$at,%hi(symbol)
2253 dsll $at,$at,16
2255 The final address is then $at + %lo(symbol). With 32-bit
2256 symbols we just need a preparatory LUI for normal mode and
2257 a preparatory LI and SLL for MIPS16. */
2258 return ABI_HAS_64BIT_SYMBOLS ? 6 : TARGET_MIPS16 ? 3 : 2;
2260 case SYMBOL_GP_RELATIVE:
2261 /* Treat GP-relative accesses as taking a single instruction on
2262 MIPS16 too; the copy of $gp can often be shared. */
2263 return 1;
2265 case SYMBOL_PC_RELATIVE:
2266 /* PC-relative constants can be only be used with ADDIUPC,
2267 DADDIUPC, LWPC and LDPC. */
2268 if (mode == MAX_MACHINE_MODE
2269 || GET_MODE_SIZE (mode) == 4
2270 || GET_MODE_SIZE (mode) == 8)
2271 return 1;
2273 /* The constant must be loaded using ADDIUPC or DADDIUPC first. */
2274 return 0;
2276 case SYMBOL_GOT_DISP:
2277 /* The constant will have to be loaded from the GOT before it
2278 is used in an address. */
2279 if (mode != MAX_MACHINE_MODE)
2280 return 0;
2282 /* Fall through. */
2284 case SYMBOL_GOT_PAGE_OFST:
2285 /* Unless -funit-at-a-time is in effect, we can't be sure whether the
2286 local/global classification is accurate. The worst cases are:
2288 (1) For local symbols when generating o32 or o64 code. The assembler
2289 will use:
2291 lw $at,%got(symbol)
2294 ...and the final address will be $at + %lo(symbol).
2296 (2) For global symbols when -mxgot. The assembler will use:
2298 lui $at,%got_hi(symbol)
2299 (d)addu $at,$at,$gp
2301 ...and the final address will be $at + %got_lo(symbol). */
2302 return 3;
2304 case SYMBOL_GOTOFF_PAGE:
2305 case SYMBOL_GOTOFF_DISP:
2306 case SYMBOL_GOTOFF_CALL:
2307 case SYMBOL_GOTOFF_LOADGP:
2308 case SYMBOL_64_HIGH:
2309 case SYMBOL_64_MID:
2310 case SYMBOL_64_LOW:
2311 case SYMBOL_TLSGD:
2312 case SYMBOL_TLSLDM:
2313 case SYMBOL_DTPREL:
2314 case SYMBOL_GOTTPREL:
2315 case SYMBOL_TPREL:
2316 case SYMBOL_HALF:
2317 /* A 16-bit constant formed by a single relocation, or a 32-bit
2318 constant formed from a high 16-bit relocation and a low 16-bit
2319 relocation. Use mips_split_p to determine which. 32-bit
2320 constants need an "lui; addiu" sequence for normal mode and
2321 an "li; sll; addiu" sequence for MIPS16 mode. */
2322 return !mips_split_p[type] ? 1 : TARGET_MIPS16 ? 3 : 2;
2324 case SYMBOL_TLS:
2325 /* We don't treat a bare TLS symbol as a constant. */
2326 return 0;
2328 gcc_unreachable ();
2331 /* If MODE is MAX_MACHINE_MODE, return the number of instructions needed
2332 to load symbols of type TYPE into a register. Return 0 if the given
2333 type of symbol cannot be used as an immediate operand.
2335 Otherwise, return the number of instructions needed to load or store
2336 values of mode MODE to or from addresses of type TYPE. Return 0 if
2337 the given type of symbol is not valid in addresses.
2339 In both cases, instruction counts are based off BASE_INSN_LENGTH. */
2341 static int
2342 mips_symbol_insns (enum mips_symbol_type type, machine_mode mode)
2344 /* MSA LD.* and ST.* cannot support loading symbols via an immediate
2345 operand. */
2346 if (MSA_SUPPORTED_MODE_P (mode))
2347 return 0;
2349 return mips_symbol_insns_1 (type, mode) * (TARGET_MIPS16 ? 2 : 1);
2352 /* A for_each_rtx callback. Stop the search if *X references a
2353 thread-local symbol. */
2355 static int
2356 mips_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
2358 return mips_tls_symbol_p (*x);
2361 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
2363 static bool
2364 mips_cannot_force_const_mem (machine_mode mode, rtx x)
2366 enum mips_symbol_type type;
2367 rtx base, offset;
2369 /* There is no assembler syntax for expressing an address-sized
2370 high part. */
2371 if (GET_CODE (x) == HIGH)
2372 return true;
2374 /* As an optimization, reject constants that mips_legitimize_move
2375 can expand inline.
2377 Suppose we have a multi-instruction sequence that loads constant C
2378 into register R. If R does not get allocated a hard register, and
2379 R is used in an operand that allows both registers and memory
2380 references, reload will consider forcing C into memory and using
2381 one of the instruction's memory alternatives. Returning false
2382 here will force it to use an input reload instead. */
2383 if (CONST_INT_P (x) && mips_legitimate_constant_p (mode, x))
2384 return true;
2386 split_const (x, &base, &offset);
2387 if (mips_symbolic_constant_p (base, SYMBOL_CONTEXT_LEA, &type))
2389 /* See whether we explicitly want these symbols in the pool. */
2390 if (mips_use_pcrel_pool_p[(int) type])
2391 return false;
2393 /* The same optimization as for CONST_INT. */
2394 if (SMALL_INT (offset) && mips_symbol_insns (type, MAX_MACHINE_MODE) > 0)
2395 return true;
2397 /* If MIPS16 constant pools live in the text section, they should
2398 not refer to anything that might need run-time relocation. */
2399 if (TARGET_MIPS16_PCREL_LOADS && mips_got_symbol_type_p (type))
2400 return true;
2403 /* TLS symbols must be computed by mips_legitimize_move. */
2404 if (for_each_rtx (&x, &mips_tls_symbol_ref_1, NULL))
2405 return true;
2407 return false;
2410 /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. We can't use blocks for
2411 constants when we're using a per-function constant pool. */
2413 static bool
2414 mips_use_blocks_for_constant_p (machine_mode mode ATTRIBUTE_UNUSED,
2415 const_rtx x ATTRIBUTE_UNUSED)
2417 return !TARGET_MIPS16_PCREL_LOADS;
2420 /* Return true if register REGNO is a valid base register for mode MODE.
2421 STRICT_P is true if REG_OK_STRICT is in effect. */
2424 mips_regno_mode_ok_for_base_p (int regno, machine_mode mode,
2425 bool strict_p)
2427 if (!HARD_REGISTER_NUM_P (regno))
2429 if (!strict_p)
2430 return true;
2431 regno = reg_renumber[regno];
2434 /* These fake registers will be eliminated to either the stack or
2435 hard frame pointer, both of which are usually valid base registers.
2436 Reload deals with the cases where the eliminated form isn't valid. */
2437 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM)
2438 return true;
2440 /* In MIPS16 mode, the stack pointer can only address word and doubleword
2441 values, nothing smaller. */
2442 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM)
2443 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8;
2445 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno);
2448 /* Return true if X is a valid base register for mode MODE.
2449 STRICT_P is true if REG_OK_STRICT is in effect. */
2451 static bool
2452 mips_valid_base_register_p (rtx x, machine_mode mode, bool strict_p)
2454 if (!strict_p && GET_CODE (x) == SUBREG)
2455 x = SUBREG_REG (x);
2457 return (REG_P (x)
2458 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict_p));
2461 /* Return true if, for every base register BASE_REG, (plus BASE_REG X)
2462 can address a value of mode MODE. */
2464 static bool
2465 mips_valid_offset_p (rtx x, machine_mode mode)
2467 /* Check that X is a signed 16-bit number. */
2468 if (!const_arith_operand (x, Pmode))
2469 return false;
2471 /* We may need to split multiword moves, so make sure that every word
2472 is accessible. */
2473 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
2474 && !SMALL_OPERAND (INTVAL (x) + GET_MODE_SIZE (mode) - UNITS_PER_WORD))
2475 return false;
2477 /* MSA LD.* and ST.* supports 10-bit signed offsets. */
2478 if (MSA_SUPPORTED_MODE_P (mode)
2479 && !mips_signed_immediate_p (INTVAL (x), 10,
2480 mips_ldst_scaled_shift (mode)))
2481 return false;
2483 return true;
2486 /* Return true if a LO_SUM can address a value of mode MODE when the
2487 LO_SUM symbol has type SYMBOL_TYPE. */
2489 static bool
2490 mips_valid_lo_sum_p (enum mips_symbol_type symbol_type, machine_mode mode)
2492 /* Check that symbols of type SYMBOL_TYPE can be used to access values
2493 of mode MODE. */
2494 if (mips_symbol_insns (symbol_type, mode) == 0)
2495 return false;
2497 /* Check that there is a known low-part relocation. */
2498 if (mips_lo_relocs[symbol_type] == NULL)
2499 return false;
2501 /* We may need to split multiword moves, so make sure that each word
2502 can be accessed without inducing a carry. This is mainly needed
2503 for o64, which has historically only guaranteed 64-bit alignment
2504 for 128-bit types. */
2505 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
2506 && GET_MODE_BITSIZE (mode) > GET_MODE_ALIGNMENT (mode))
2507 return false;
2509 /* MSA LD.* and ST.* cannot support loading symbols via %lo($base). */
2510 if (MSA_SUPPORTED_MODE_P (mode))
2511 return false;
2513 return true;
2516 /* Return true if X is a valid address for machine mode MODE. If it is,
2517 fill in INFO appropriately. STRICT_P is true if REG_OK_STRICT is in
2518 effect. */
2520 static bool
2521 mips_classify_address (struct mips_address_info *info, rtx x,
2522 machine_mode mode, bool strict_p)
2524 switch (GET_CODE (x))
2526 case REG:
2527 case SUBREG:
2528 info->type = ADDRESS_REG;
2529 info->reg = x;
2530 info->offset = const0_rtx;
2531 return mips_valid_base_register_p (info->reg, mode, strict_p);
2533 case PLUS:
2534 info->type = ADDRESS_REG;
2535 info->reg = XEXP (x, 0);
2536 info->offset = XEXP (x, 1);
2537 return (mips_valid_base_register_p (info->reg, mode, strict_p)
2538 && mips_valid_offset_p (info->offset, mode));
2540 case LO_SUM:
2541 info->type = ADDRESS_LO_SUM;
2542 info->reg = XEXP (x, 0);
2543 info->offset = XEXP (x, 1);
2544 /* We have to trust the creator of the LO_SUM to do something vaguely
2545 sane. Target-independent code that creates a LO_SUM should also
2546 create and verify the matching HIGH. Target-independent code that
2547 adds an offset to a LO_SUM must prove that the offset will not
2548 induce a carry. Failure to do either of these things would be
2549 a bug, and we are not required to check for it here. The MIPS
2550 backend itself should only create LO_SUMs for valid symbolic
2551 constants, with the high part being either a HIGH or a copy
2552 of _gp. */
2553 info->symbol_type
2554 = mips_classify_symbolic_expression (info->offset, SYMBOL_CONTEXT_MEM);
2555 return (mips_valid_base_register_p (info->reg, mode, strict_p)
2556 && mips_valid_lo_sum_p (info->symbol_type, mode));
2558 case CONST_INT:
2559 /* Small-integer addresses don't occur very often, but they
2560 are legitimate if $0 is a valid base register. */
2561 info->type = ADDRESS_CONST_INT;
2562 return !TARGET_MIPS16 && SMALL_INT (x);
2564 case CONST:
2565 case LABEL_REF:
2566 case SYMBOL_REF:
2567 info->type = ADDRESS_SYMBOLIC;
2568 return (mips_symbolic_constant_p (x, SYMBOL_CONTEXT_MEM,
2569 &info->symbol_type)
2570 && mips_symbol_insns (info->symbol_type, mode) > 0
2571 && !mips_split_p[info->symbol_type]);
2573 default:
2574 return false;
2578 /* Implement TARGET_LEGITIMATE_ADDRESS_P. */
2580 static bool
2581 mips_legitimate_address_p (machine_mode mode, rtx x, bool strict_p)
2583 struct mips_address_info addr;
2585 return mips_classify_address (&addr, x, mode, strict_p);
2588 /* Return true if X is a legitimate $sp-based address for mode MDOE. */
2590 bool
2591 mips_stack_address_p (rtx x, machine_mode mode)
2593 struct mips_address_info addr;
2595 return (mips_classify_address (&addr, x, mode, false)
2596 && addr.type == ADDRESS_REG
2597 && addr.reg == stack_pointer_rtx);
2600 /* Return true if ADDR matches the pattern for the LWXS load scaled indexed
2601 address instruction. Note that such addresses are not considered
2602 legitimate in the TARGET_LEGITIMATE_ADDRESS_P sense, because their use
2603 is so restricted. */
2605 static bool
2606 mips_lwxs_address_p (rtx addr)
2608 if (ISA_HAS_LWXS
2609 && GET_CODE (addr) == PLUS
2610 && REG_P (XEXP (addr, 1)))
2612 rtx offset = XEXP (addr, 0);
2613 if (GET_CODE (offset) == MULT
2614 && REG_P (XEXP (offset, 0))
2615 && CONST_INT_P (XEXP (offset, 1))
2616 && INTVAL (XEXP (offset, 1)) == 4)
2617 return true;
2619 return false;
2622 /* Return true if ADDR matches the pattern for the L{B,H,W,D}{,U}X load
2623 indexed address instruction. Note that such addresses are
2624 not considered legitimate in the TARGET_LEGITIMATE_ADDRESS_P
2625 sense, because their use is so restricted. */
2627 static bool
2628 mips_lx_address_p (rtx addr, machine_mode mode)
2630 if (GET_CODE (addr) != PLUS
2631 || !REG_P (XEXP (addr, 0))
2632 || !REG_P (XEXP (addr, 1)))
2633 return false;
2634 if (ISA_HAS_LBX && mode == QImode)
2635 return true;
2636 if (ISA_HAS_LHX && mode == HImode)
2637 return true;
2638 if (ISA_HAS_LWX && mode == SImode)
2639 return true;
2640 if (ISA_HAS_LDX && mode == DImode)
2641 return true;
2642 if (MSA_SUPPORTED_MODE_P (mode))
2643 return true;
2644 return false;
2647 /* Return true if a value at OFFSET bytes from base register BASE can be
2648 accessed using an unextended MIPS16 instruction. MODE is the mode of
2649 the value.
2651 Usually the offset in an unextended instruction is a 5-bit field.
2652 The offset is unsigned and shifted left once for LH and SH, twice
2653 for LW and SW, and so on. An exception is LWSP and SWSP, which have
2654 an 8-bit immediate field that's shifted left twice. */
2656 static bool
2657 mips16_unextended_reference_p (machine_mode mode, rtx base,
2658 unsigned HOST_WIDE_INT offset)
2660 if (mode != BLKmode && offset % GET_MODE_SIZE (mode) == 0)
2662 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx)
2663 return offset < 256U * GET_MODE_SIZE (mode);
2664 return offset < 32U * GET_MODE_SIZE (mode);
2666 return false;
2669 /* Return the number of instructions needed to load or store a value
2670 of mode MODE at address X, assuming that BASE_INSN_LENGTH is the
2671 length of one instruction. Return 0 if X isn't valid for MODE.
2672 Assume that multiword moves may need to be split into word moves
2673 if MIGHT_SPLIT_P, otherwise assume that a single load or store is
2674 enough. */
2677 mips_address_insns (rtx x, machine_mode mode, bool might_split_p)
2679 struct mips_address_info addr;
2680 int factor;
2681 bool msa_p = (!might_split_p && MSA_SUPPORTED_MODE_P (mode));
2683 /* BLKmode is used for single unaligned loads and stores and should
2684 not count as a multiword mode. (GET_MODE_SIZE (BLKmode) is pretty
2685 meaningless, so we have to single it out as a special case one way
2686 or the other.) */
2687 if (mode != BLKmode && might_split_p)
2688 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
2689 else
2690 factor = 1;
2692 if (mips_classify_address (&addr, x, mode, false))
2693 switch (addr.type)
2695 case ADDRESS_REG:
2696 if (msa_p)
2698 /* MSA LD.* and ST.* supports 10-bit signed offsets. */
2699 if (mips_signed_immediate_p (INTVAL (addr.offset), 10,
2700 mips_ldst_scaled_shift (mode)))
2701 return 1;
2702 else
2703 return 0;
2705 if (TARGET_MIPS16
2706 && !mips16_unextended_reference_p (mode, addr.reg,
2707 UINTVAL (addr.offset)))
2708 return factor * 2;
2709 return factor;
2711 case ADDRESS_LO_SUM:
2712 return msa_p ? 0 : TARGET_MIPS16 ? factor * 2 : factor;
2714 case ADDRESS_CONST_INT:
2715 return msa_p ? 0 : factor;
2717 case ADDRESS_SYMBOLIC:
2718 return msa_p ? 0 : factor * mips_symbol_insns (addr.symbol_type, mode);
2720 return 0;
2723 /* Return true if X fits within an unsigned field of BITS bits that is
2724 shifted left SHIFT bits before being used. */
2726 bool
2727 mips_unsigned_immediate_p (unsigned HOST_WIDE_INT x, int bits, int shift = 0)
2729 return (x & ((1 << shift) - 1)) == 0 && x < ((unsigned) 1 << (shift + bits));
2732 /* Return true if X fits within a signed field of BITS bits that is
2733 shifted left SHIFT bits before being used. */
2735 bool
2736 mips_signed_immediate_p (unsigned HOST_WIDE_INT x, int bits, int shift = 0)
2738 x += 1 << (bits + shift - 1);
2739 return mips_unsigned_immediate_p (x, bits, shift);
2742 /* Return the scale shift that applied to MSA LD/ST address offset. */
2745 mips_ldst_scaled_shift (machine_mode mode)
2747 int shift = exact_log2 (GET_MODE_UNIT_SIZE (mode));
2749 if (shift < 0 || shift > 8)
2750 gcc_unreachable ();
2752 return shift;
2755 /* Return true if X is legitimate for accessing values of mode MODE,
2756 if it is based on a MIPS16 register, and if the offset satisfies
2757 OFFSET_PREDICATE. */
2759 bool
2760 m16_based_address_p (rtx x, machine_mode mode,
2761 insn_operand_predicate_fn offset_predicate)
2763 struct mips_address_info addr;
2765 return (mips_classify_address (&addr, x, mode, false)
2766 && addr.type == ADDRESS_REG
2767 && M16_REG_P (REGNO (addr.reg))
2768 && offset_predicate (addr.offset, mode));
2771 /* Return true if X is a legitimate address that conforms to the requirements
2772 for a microMIPS LWSP or SWSP insn. */
2774 bool
2775 lwsp_swsp_address_p (rtx x, machine_mode mode)
2777 struct mips_address_info addr;
2779 return (mips_classify_address (&addr, x, mode, false)
2780 && addr.type == ADDRESS_REG
2781 && REGNO (addr.reg) == STACK_POINTER_REGNUM
2782 && uw5_operand (addr.offset, mode));
2785 /* Return true if X is a legitimate address with a 12-bit offset.
2786 MODE is the mode of the value being accessed. */
2788 bool
2789 umips_12bit_offset_address_p (rtx x, machine_mode mode)
2791 struct mips_address_info addr;
2793 return (mips_classify_address (&addr, x, mode, false)
2794 && addr.type == ADDRESS_REG
2795 && CONST_INT_P (addr.offset)
2796 && UMIPS_12BIT_OFFSET_P (INTVAL (addr.offset)));
2799 /* Return true if X is a legitimate address with a 9-bit offset.
2800 MODE is the mode of the value being accessed. */
2802 bool
2803 mips_9bit_offset_address_p (rtx x, machine_mode mode)
2805 struct mips_address_info addr;
2807 return (mips_classify_address (&addr, x, mode, false)
2808 && addr.type == ADDRESS_REG
2809 && CONST_INT_P (addr.offset)
2810 && MIPS_9BIT_OFFSET_P (INTVAL (addr.offset)));
2813 /* Return the number of instructions needed to load constant X,
2814 assuming that BASE_INSN_LENGTH is the length of one instruction.
2815 Return 0 if X isn't a valid constant. */
2818 mips_const_insns (rtx x)
2820 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
2821 enum mips_symbol_type symbol_type;
2822 rtx offset;
2824 switch (GET_CODE (x))
2826 case HIGH:
2827 if (!mips_symbolic_constant_p (XEXP (x, 0), SYMBOL_CONTEXT_LEA,
2828 &symbol_type)
2829 || !mips_split_p[symbol_type])
2830 return 0;
2832 /* This is simply an LUI for normal mode. It is an extended
2833 LI followed by an extended SLL for MIPS16. */
2834 return TARGET_MIPS16 ? 4 : 1;
2836 case CONST_INT:
2837 if (TARGET_MIPS16)
2838 /* Unsigned 8-bit constants can be loaded using an unextended
2839 LI instruction. Unsigned 16-bit constants can be loaded
2840 using an extended LI. Negative constants must be loaded
2841 using LI and then negated. */
2842 return (IN_RANGE (INTVAL (x), 0, 255) ? 1
2843 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2
2844 : IN_RANGE (-INTVAL (x), 0, 255) ? 2
2845 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3
2846 : 0);
2848 return mips_build_integer (codes, INTVAL (x));
2850 case CONST_VECTOR:
2851 if (TARGET_MSA
2852 && mips_const_vector_same_int_p (x, GET_MODE (x), -512, 511))
2853 return 1;
2854 /* Fall through. */
2855 case CONST_DOUBLE:
2856 /* Allow zeros for normal mode, where we can use $0. */
2857 return !TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0;
2859 case CONST:
2860 if (CONST_GP_P (x))
2861 return 1;
2863 /* See if we can refer to X directly. */
2864 if (mips_symbolic_constant_p (x, SYMBOL_CONTEXT_LEA, &symbol_type))
2865 return mips_symbol_insns (symbol_type, MAX_MACHINE_MODE);
2867 /* Otherwise try splitting the constant into a base and offset.
2868 If the offset is a 16-bit value, we can load the base address
2869 into a register and then use (D)ADDIU to add in the offset.
2870 If the offset is larger, we can load the base and offset
2871 into separate registers and add them together with (D)ADDU.
2872 However, the latter is only possible before reload; during
2873 and after reload, we must have the option of forcing the
2874 constant into the pool instead. */
2875 split_const (x, &x, &offset);
2876 if (offset != 0)
2878 int n = mips_const_insns (x);
2879 if (n != 0)
2881 if (SMALL_INT (offset))
2882 return n + 1;
2883 else if (!targetm.cannot_force_const_mem (GET_MODE (x), x))
2884 return n + 1 + mips_build_integer (codes, INTVAL (offset));
2887 return 0;
2889 case SYMBOL_REF:
2890 case LABEL_REF:
2891 return mips_symbol_insns (mips_classify_symbol (x, SYMBOL_CONTEXT_LEA),
2892 MAX_MACHINE_MODE);
2894 default:
2895 return 0;
2899 /* X is a doubleword constant that can be handled by splitting it into
2900 two words and loading each word separately. Return the number of
2901 instructions required to do this, assuming that BASE_INSN_LENGTH
2902 is the length of one instruction. */
2905 mips_split_const_insns (rtx x)
2907 unsigned int low, high;
2909 low = mips_const_insns (mips_subword (x, false));
2910 high = mips_const_insns (mips_subword (x, true));
2911 gcc_assert (low > 0 && high > 0);
2912 return low + high;
2915 /* Return one word of 128-bit value OP, taking into account the fixed
2916 endianness of certain registers. BYTE selects from the byte address. */
2919 mips_subword_at_byte (rtx op, unsigned int byte)
2921 machine_mode mode;
2923 mode = GET_MODE (op);
2924 if (mode == VOIDmode)
2925 mode = TImode;
2927 gcc_assert (!FP_REG_RTX_P (op));
2929 if (MEM_P (op))
2930 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
2932 return simplify_gen_subreg (word_mode, op, mode, byte);
2935 /* Return the number of instructions needed to implement INSN,
2936 given that it loads from or stores to MEM. Assume that
2937 BASE_INSN_LENGTH is the length of one instruction. */
2940 mips_load_store_insns (rtx mem, rtx insn)
2942 machine_mode mode;
2943 bool might_split_p;
2944 rtx set;
2946 gcc_assert (MEM_P (mem));
2947 mode = GET_MODE (mem);
2949 /* Try to prove that INSN does not need to be split. */
2950 might_split_p = GET_MODE_SIZE (mode) > UNITS_PER_WORD;
2951 if (might_split_p)
2953 set = single_set (insn);
2954 if (set && !mips_split_move_insn_p (SET_DEST (set), SET_SRC (set), insn))
2955 might_split_p = false;
2958 return mips_address_insns (XEXP (mem, 0), mode, might_split_p);
2961 /* Return the number of instructions needed for an integer division,
2962 assuming that BASE_INSN_LENGTH is the length of one instruction. */
2965 mips_idiv_insns (void)
2967 int count;
2969 count = 1;
2970 if (TARGET_CHECK_ZERO_DIV)
2972 if (GENERATE_DIVIDE_TRAPS)
2973 count++;
2974 else
2975 count += 2;
2978 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
2979 count++;
2980 return count;
2983 /* Return the number of instructions needed for an MSA integer division. */
2986 mips_msa_idiv_insns (void)
2988 if (TARGET_CHECK_ZERO_DIV)
2989 return 3;
2990 else
2991 return 1;
2994 /* Emit a move from SRC to DEST. Assume that the move expanders can
2995 handle all moves if !can_create_pseudo_p (). The distinction is
2996 important because, unlike emit_move_insn, the move expanders know
2997 how to force Pmode objects into the constant pool even when the
2998 constant pool address is not itself legitimate. */
3001 mips_emit_move (rtx dest, rtx src)
3003 return (can_create_pseudo_p ()
3004 ? emit_move_insn (dest, src)
3005 : emit_move_insn_1 (dest, src));
3008 /* Emit a move from SRC to DEST, splitting compound moves into individual
3009 instructions. SPLIT_TYPE is the type of split to perform. */
3011 static void
3012 mips_emit_move_or_split (rtx dest, rtx src, enum mips_split_type split_type)
3014 if (mips_split_move_p (dest, src, split_type))
3015 mips_split_move (dest, src, split_type);
3016 else
3017 mips_emit_move (dest, src);
3020 /* Emit an instruction of the form (set TARGET (CODE OP0)). */
3022 static void
3023 mips_emit_unary (enum rtx_code code, rtx target, rtx op0)
3025 emit_insn (gen_rtx_SET (VOIDmode, target,
3026 gen_rtx_fmt_e (code, GET_MODE (op0), op0)));
3029 /* Compute (CODE OP0) and store the result in a new register of mode MODE.
3030 Return that new register. */
3032 static rtx
3033 mips_force_unary (machine_mode mode, enum rtx_code code, rtx op0)
3035 rtx reg;
3037 reg = gen_reg_rtx (mode);
3038 mips_emit_unary (code, reg, op0);
3039 return reg;
3042 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */
3044 void
3045 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1)
3047 emit_insn (gen_rtx_SET (VOIDmode, target,
3048 gen_rtx_fmt_ee (code, GET_MODE (target), op0, op1)));
3051 /* Compute (CODE OP0 OP1) and store the result in a new register
3052 of mode MODE. Return that new register. */
3054 static rtx
3055 mips_force_binary (machine_mode mode, enum rtx_code code, rtx op0, rtx op1)
3057 rtx reg;
3059 reg = gen_reg_rtx (mode);
3060 mips_emit_binary (code, reg, op0, op1);
3061 return reg;
3064 /* Copy VALUE to a register and return that register. If new pseudos
3065 are allowed, copy it into a new register, otherwise use DEST. */
3067 static rtx
3068 mips_force_temporary (rtx dest, rtx value)
3070 if (can_create_pseudo_p ())
3071 return force_reg (Pmode, value);
3072 else
3074 mips_emit_move (dest, value);
3075 return dest;
3079 /* Emit a call sequence with call pattern PATTERN and return the call
3080 instruction itself (which is not necessarily the last instruction
3081 emitted). ORIG_ADDR is the original, unlegitimized address,
3082 ADDR is the legitimized form, and LAZY_P is true if the call
3083 address is lazily-bound. */
3085 static rtx
3086 mips_emit_call_insn (rtx pattern, rtx orig_addr, rtx addr, bool lazy_p)
3088 rtx insn, reg;
3090 insn = emit_call_insn (pattern);
3092 if (TARGET_MIPS16 && mips_use_pic_fn_addr_reg_p (orig_addr))
3094 /* MIPS16 JALRs only take MIPS16 registers. If the target
3095 function requires $25 to be valid on entry, we must copy it
3096 there separately. The move instruction can be put in the
3097 call's delay slot. */
3098 reg = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
3099 emit_insn_before (gen_move_insn (reg, addr), insn);
3100 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), reg);
3103 if (lazy_p)
3104 /* Lazy-binding stubs require $gp to be valid on entry. */
3105 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx);
3107 if (TARGET_USE_GOT)
3109 /* See the comment above load_call<mode> for details. */
3110 use_reg (&CALL_INSN_FUNCTION_USAGE (insn),
3111 gen_rtx_REG (Pmode, GOT_VERSION_REGNUM));
3112 emit_insn (gen_update_got_version ());
3114 return insn;
3117 /* Wrap symbol or label BASE in an UNSPEC address of type SYMBOL_TYPE,
3118 then add CONST_INT OFFSET to the result. */
3120 static rtx
3121 mips_unspec_address_offset (rtx base, rtx offset,
3122 enum mips_symbol_type symbol_type)
3124 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base),
3125 UNSPEC_ADDRESS_FIRST + symbol_type);
3126 if (offset != const0_rtx)
3127 base = gen_rtx_PLUS (Pmode, base, offset);
3128 return gen_rtx_CONST (Pmode, base);
3131 /* Return an UNSPEC address with underlying address ADDRESS and symbol
3132 type SYMBOL_TYPE. */
3135 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type)
3137 rtx base, offset;
3139 split_const (address, &base, &offset);
3140 return mips_unspec_address_offset (base, offset, symbol_type);
3143 /* If OP is an UNSPEC address, return the address to which it refers,
3144 otherwise return OP itself. */
3147 mips_strip_unspec_address (rtx op)
3149 rtx base, offset;
3151 split_const (op, &base, &offset);
3152 if (UNSPEC_ADDRESS_P (base))
3153 op = plus_constant (Pmode, UNSPEC_ADDRESS (base), INTVAL (offset));
3154 return op;
3157 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the
3158 high part to BASE and return the result. Just return BASE otherwise.
3159 TEMP is as for mips_force_temporary.
3161 The returned expression can be used as the first operand to a LO_SUM. */
3163 static rtx
3164 mips_unspec_offset_high (rtx temp, rtx base, rtx addr,
3165 enum mips_symbol_type symbol_type)
3167 if (mips_split_p[symbol_type])
3169 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type));
3170 addr = mips_force_temporary (temp, addr);
3171 base = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base));
3173 return base;
3176 /* Return an instruction that copies $gp into register REG. We want
3177 GCC to treat the register's value as constant, so that its value
3178 can be rematerialized on demand. */
3180 static rtx
3181 gen_load_const_gp (rtx reg)
3183 return PMODE_INSN (gen_load_const_gp, (reg));
3186 /* Return a pseudo register that contains the value of $gp throughout
3187 the current function. Such registers are needed by MIPS16 functions,
3188 for which $gp itself is not a valid base register or addition operand. */
3190 static rtx
3191 mips16_gp_pseudo_reg (void)
3193 if (cfun->machine->mips16_gp_pseudo_rtx == NULL_RTX)
3195 rtx insn, scan;
3197 cfun->machine->mips16_gp_pseudo_rtx = gen_reg_rtx (Pmode);
3199 push_topmost_sequence ();
3201 scan = get_insns ();
3202 while (NEXT_INSN (scan) && !INSN_P (NEXT_INSN (scan)))
3203 scan = NEXT_INSN (scan);
3205 insn = gen_load_const_gp (cfun->machine->mips16_gp_pseudo_rtx);
3206 insn = emit_insn_after (insn, scan);
3207 INSN_LOCATION (insn) = 0;
3209 pop_topmost_sequence ();
3212 return cfun->machine->mips16_gp_pseudo_rtx;
3215 /* Return a base register that holds pic_offset_table_rtx.
3216 TEMP, if nonnull, is a scratch Pmode base register. */
3219 mips_pic_base_register (rtx temp)
3221 if (!TARGET_MIPS16)
3222 return pic_offset_table_rtx;
3224 if (currently_expanding_to_rtl)
3225 return mips16_gp_pseudo_reg ();
3227 if (can_create_pseudo_p ())
3228 temp = gen_reg_rtx (Pmode);
3230 if (TARGET_USE_GOT)
3231 /* The first post-reload split exposes all references to $gp
3232 (both uses and definitions). All references must remain
3233 explicit after that point.
3235 It is safe to introduce uses of $gp at any time, so for
3236 simplicity, we do that before the split too. */
3237 mips_emit_move (temp, pic_offset_table_rtx);
3238 else
3239 emit_insn (gen_load_const_gp (temp));
3240 return temp;
3243 /* Return the RHS of a load_call<mode> insn. */
3245 static rtx
3246 mips_unspec_call (rtx reg, rtx symbol)
3248 rtvec vec;
3250 vec = gen_rtvec (3, reg, symbol, gen_rtx_REG (SImode, GOT_VERSION_REGNUM));
3251 return gen_rtx_UNSPEC (Pmode, vec, UNSPEC_LOAD_CALL);
3254 /* If SRC is the RHS of a load_call<mode> insn, return the underlying symbol
3255 reference. Return NULL_RTX otherwise. */
3257 static rtx
3258 mips_strip_unspec_call (rtx src)
3260 if (GET_CODE (src) == UNSPEC && XINT (src, 1) == UNSPEC_LOAD_CALL)
3261 return mips_strip_unspec_address (XVECEXP (src, 0, 1));
3262 return NULL_RTX;
3265 /* Create and return a GOT reference of type TYPE for address ADDR.
3266 TEMP, if nonnull, is a scratch Pmode base register. */
3269 mips_got_load (rtx temp, rtx addr, enum mips_symbol_type type)
3271 rtx base, high, lo_sum_symbol;
3273 base = mips_pic_base_register (temp);
3275 /* If we used the temporary register to load $gp, we can't use
3276 it for the high part as well. */
3277 if (temp != NULL && reg_overlap_mentioned_p (base, temp))
3278 temp = NULL;
3280 high = mips_unspec_offset_high (temp, base, addr, type);
3281 lo_sum_symbol = mips_unspec_address (addr, type);
3283 if (type == SYMBOL_GOTOFF_CALL)
3284 return mips_unspec_call (high, lo_sum_symbol);
3285 else
3286 return PMODE_INSN (gen_unspec_got, (high, lo_sum_symbol));
3289 /* If MODE is MAX_MACHINE_MODE, ADDR appears as a move operand, otherwise
3290 it appears in a MEM of that mode. Return true if ADDR is a legitimate
3291 constant in that context and can be split into high and low parts.
3292 If so, and if LOW_OUT is nonnull, emit the high part and store the
3293 low part in *LOW_OUT. Leave *LOW_OUT unchanged otherwise.
3295 TEMP is as for mips_force_temporary and is used to load the high
3296 part into a register.
3298 When MODE is MAX_MACHINE_MODE, the low part is guaranteed to be
3299 a legitimize SET_SRC for an .md pattern, otherwise the low part
3300 is guaranteed to be a legitimate address for mode MODE. */
3302 bool
3303 mips_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out)
3305 enum mips_symbol_context context;
3306 enum mips_symbol_type symbol_type;
3307 rtx high;
3309 context = (mode == MAX_MACHINE_MODE
3310 ? SYMBOL_CONTEXT_LEA
3311 : SYMBOL_CONTEXT_MEM);
3312 if (GET_CODE (addr) == HIGH && context == SYMBOL_CONTEXT_LEA)
3314 addr = XEXP (addr, 0);
3315 if (mips_symbolic_constant_p (addr, context, &symbol_type)
3316 && mips_symbol_insns (symbol_type, mode) > 0
3317 && mips_split_hi_p[symbol_type])
3319 if (low_out)
3320 switch (symbol_type)
3322 case SYMBOL_GOT_PAGE_OFST:
3323 /* The high part of a page/ofst pair is loaded from the GOT. */
3324 *low_out = mips_got_load (temp, addr, SYMBOL_GOTOFF_PAGE);
3325 break;
3327 default:
3328 gcc_unreachable ();
3330 return true;
3333 else
3335 if (mips_symbolic_constant_p (addr, context, &symbol_type)
3336 && mips_symbol_insns (symbol_type, mode) > 0
3337 && mips_split_p[symbol_type])
3339 if (low_out)
3340 switch (symbol_type)
3342 case SYMBOL_GOT_DISP:
3343 /* SYMBOL_GOT_DISP symbols are loaded from the GOT. */
3344 *low_out = mips_got_load (temp, addr, SYMBOL_GOTOFF_DISP);
3345 break;
3347 case SYMBOL_GP_RELATIVE:
3348 high = mips_pic_base_register (temp);
3349 *low_out = gen_rtx_LO_SUM (Pmode, high, addr);
3350 break;
3352 default:
3353 high = gen_rtx_HIGH (Pmode, copy_rtx (addr));
3354 high = mips_force_temporary (temp, high);
3355 *low_out = gen_rtx_LO_SUM (Pmode, high, addr);
3356 break;
3358 return true;
3361 return false;
3364 /* Return a legitimate address for REG + OFFSET. TEMP is as for
3365 mips_force_temporary; it is only needed when OFFSET is not a
3366 SMALL_OPERAND. */
3368 static rtx
3369 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset)
3371 if (!SMALL_OPERAND (offset))
3373 rtx high;
3375 if (TARGET_MIPS16)
3377 /* Load the full offset into a register so that we can use
3378 an unextended instruction for the address itself. */
3379 high = GEN_INT (offset);
3380 offset = 0;
3382 else
3384 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH.
3385 The addition inside the macro CONST_HIGH_PART may cause an
3386 overflow, so we need to force a sign-extension check. */
3387 high = gen_int_mode (CONST_HIGH_PART (offset), Pmode);
3388 offset = CONST_LOW_PART (offset);
3390 high = mips_force_temporary (temp, high);
3391 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg));
3393 return plus_constant (Pmode, reg, offset);
3396 /* The __tls_get_attr symbol. */
3397 static GTY(()) rtx mips_tls_symbol;
3399 /* Return an instruction sequence that calls __tls_get_addr. SYM is
3400 the TLS symbol we are referencing and TYPE is the symbol type to use
3401 (either global dynamic or local dynamic). V0 is an RTX for the
3402 return value location. */
3404 static rtx
3405 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0)
3407 rtx insn, loc, a0;
3409 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST);
3411 if (!mips_tls_symbol)
3412 mips_tls_symbol = init_one_libfunc ("__tls_get_addr");
3414 loc = mips_unspec_address (sym, type);
3416 start_sequence ();
3418 emit_insn (gen_rtx_SET (Pmode, a0,
3419 gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, loc)));
3420 insn = mips_expand_call (MIPS_CALL_NORMAL, v0, mips_tls_symbol,
3421 const0_rtx, NULL_RTX, false);
3422 RTL_CONST_CALL_P (insn) = 1;
3423 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
3424 insn = get_insns ();
3426 end_sequence ();
3428 return insn;
3431 /* Return a pseudo register that contains the current thread pointer. */
3434 mips_expand_thread_pointer (rtx tp)
3436 rtx fn;
3438 if (TARGET_MIPS16)
3440 if (!mips16_rdhwr_stub)
3441 mips16_rdhwr_stub = new mips16_rdhwr_one_only_stub ();
3442 fn = mips16_stub_call_address (mips16_rdhwr_stub);
3443 emit_insn (PMODE_INSN (gen_tls_get_tp_mips16, (tp, fn)));
3445 else
3446 emit_insn (PMODE_INSN (gen_tls_get_tp, (tp)));
3447 return tp;
3450 static rtx
3451 mips_get_tp (void)
3453 return mips_expand_thread_pointer (gen_reg_rtx (Pmode));
3456 /* Generate the code to access LOC, a thread-local SYMBOL_REF, and return
3457 its address. The return value will be both a valid address and a valid
3458 SET_SRC (either a REG or a LO_SUM). */
3460 static rtx
3461 mips_legitimize_tls_address (rtx loc)
3463 rtx dest, insn, v0, tp, tmp1, tmp2, eqv, offset;
3464 enum tls_model model;
3466 model = SYMBOL_REF_TLS_MODEL (loc);
3467 /* Only TARGET_ABICALLS code can have more than one module; other
3468 code must be be static and should not use a GOT. All TLS models
3469 reduce to local exec in this situation. */
3470 if (!TARGET_ABICALLS)
3471 model = TLS_MODEL_LOCAL_EXEC;
3473 switch (model)
3475 case TLS_MODEL_GLOBAL_DYNAMIC:
3476 v0 = gen_rtx_REG (Pmode, GP_RETURN);
3477 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0);
3478 dest = gen_reg_rtx (Pmode);
3479 emit_libcall_block (insn, dest, v0, loc);
3480 break;
3482 case TLS_MODEL_LOCAL_DYNAMIC:
3483 v0 = gen_rtx_REG (Pmode, GP_RETURN);
3484 insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0);
3485 tmp1 = gen_reg_rtx (Pmode);
3487 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to
3488 share the LDM result with other LD model accesses. */
3489 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3490 UNSPEC_TLS_LDM);
3491 emit_libcall_block (insn, tmp1, v0, eqv);
3493 offset = mips_unspec_address (loc, SYMBOL_DTPREL);
3494 if (mips_split_p[SYMBOL_DTPREL])
3496 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL);
3497 dest = gen_rtx_LO_SUM (Pmode, tmp2, offset);
3499 else
3500 dest = expand_binop (Pmode, add_optab, tmp1, offset,
3501 0, 0, OPTAB_DIRECT);
3502 break;
3504 case TLS_MODEL_INITIAL_EXEC:
3505 tp = mips_get_tp ();
3506 tmp1 = gen_reg_rtx (Pmode);
3507 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL);
3508 if (Pmode == DImode)
3509 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2));
3510 else
3511 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2));
3512 dest = gen_reg_rtx (Pmode);
3513 emit_insn (gen_add3_insn (dest, tmp1, tp));
3514 break;
3516 case TLS_MODEL_LOCAL_EXEC:
3517 tmp1 = mips_get_tp ();
3518 offset = mips_unspec_address (loc, SYMBOL_TPREL);
3519 if (mips_split_p[SYMBOL_TPREL])
3521 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_TPREL);
3522 dest = gen_rtx_LO_SUM (Pmode, tmp2, offset);
3524 else
3525 dest = expand_binop (Pmode, add_optab, tmp1, offset,
3526 0, 0, OPTAB_DIRECT);
3527 break;
3529 default:
3530 gcc_unreachable ();
3532 return dest;
3535 /* Implement "TARGET = __builtin_mips_get_fcsr ()" for MIPS16,
3536 using a stub. */
3538 void
3539 mips16_expand_get_fcsr (rtx target)
3541 if (!mips16_get_fcsr_stub)
3542 mips16_get_fcsr_stub = new mips16_get_fcsr_one_only_stub ();
3543 rtx fn = mips16_stub_call_address (mips16_get_fcsr_stub);
3544 emit_insn (PMODE_INSN (gen_mips_get_fcsr_mips16, (fn)));
3545 emit_move_insn (target, gen_rtx_REG (SImode, GET_FCSR_REGNUM));
3548 /* Implement __builtin_mips_set_fcsr (TARGET) for MIPS16, using a stub. */
3550 void
3551 mips16_expand_set_fcsr (rtx newval)
3553 if (!mips16_set_fcsr_stub)
3554 mips16_set_fcsr_stub = new mips16_set_fcsr_one_only_stub ();
3555 rtx fn = mips16_stub_call_address (mips16_set_fcsr_stub);
3556 emit_move_insn (gen_rtx_REG (SImode, SET_FCSR_REGNUM), newval);
3557 emit_insn (PMODE_INSN (gen_mips_set_fcsr_mips16, (fn)));
3560 /* If X is not a valid address for mode MODE, force it into a register. */
3562 static rtx
3563 mips_force_address (rtx x, machine_mode mode)
3565 if (!mips_legitimate_address_p (mode, x, false))
3566 x = force_reg (Pmode, x);
3567 return x;
3570 /* This function is used to implement LEGITIMIZE_ADDRESS. If X can
3571 be legitimized in a way that the generic machinery might not expect,
3572 return a new address, otherwise return NULL. MODE is the mode of
3573 the memory being accessed. */
3575 static rtx
3576 mips_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3577 machine_mode mode)
3579 rtx base, addr;
3580 HOST_WIDE_INT offset;
3582 if (mips_tls_symbol_p (x))
3583 return mips_legitimize_tls_address (x);
3585 /* See if the address can split into a high part and a LO_SUM. */
3586 if (mips_split_symbol (NULL, x, mode, &addr))
3587 return mips_force_address (addr, mode);
3589 /* Handle BASE + OFFSET using mips_add_offset. */
3590 mips_split_plus (x, &base, &offset);
3591 if (offset != 0)
3593 if (!mips_valid_base_register_p (base, mode, false))
3594 base = copy_to_mode_reg (Pmode, base);
3595 addr = mips_add_offset (NULL, base, offset);
3596 return mips_force_address (addr, mode);
3599 return x;
3602 /* Load VALUE into DEST. TEMP is as for mips_force_temporary. */
3604 void
3605 mips_move_integer (rtx temp, rtx dest, unsigned HOST_WIDE_INT value)
3607 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS];
3608 machine_mode mode;
3609 unsigned int i, num_ops;
3610 rtx x;
3612 mode = GET_MODE (dest);
3613 num_ops = mips_build_integer (codes, value);
3615 /* Apply each binary operation to X. Invariant: X is a legitimate
3616 source operand for a SET pattern. */
3617 x = GEN_INT (codes[0].value);
3618 for (i = 1; i < num_ops; i++)
3620 if (!can_create_pseudo_p ())
3622 emit_insn (gen_rtx_SET (VOIDmode, temp, x));
3623 x = temp;
3625 else
3626 x = force_reg (mode, x);
3627 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value));
3630 emit_insn (gen_rtx_SET (VOIDmode, dest, x));
3633 /* Subroutine of mips_legitimize_move. Move constant SRC into register
3634 DEST given that SRC satisfies immediate_operand but doesn't satisfy
3635 move_operand. */
3637 static void
3638 mips_legitimize_const_move (machine_mode mode, rtx dest, rtx src)
3640 rtx base, offset;
3642 /* Split moves of big integers into smaller pieces. */
3643 if (splittable_const_int_operand (src, mode))
3645 mips_move_integer (dest, dest, INTVAL (src));
3646 return;
3649 /* Split moves of symbolic constants into high/low pairs. */
3650 if (mips_split_symbol (dest, src, MAX_MACHINE_MODE, &src))
3652 emit_insn (gen_rtx_SET (VOIDmode, dest, src));
3653 return;
3656 /* Generate the appropriate access sequences for TLS symbols. */
3657 if (mips_tls_symbol_p (src))
3659 mips_emit_move (dest, mips_legitimize_tls_address (src));
3660 return;
3663 /* If we have (const (plus symbol offset)), and that expression cannot
3664 be forced into memory, load the symbol first and add in the offset.
3665 In non-MIPS16 mode, prefer to do this even if the constant _can_ be
3666 forced into memory, as it usually produces better code. */
3667 split_const (src, &base, &offset);
3668 if (offset != const0_rtx
3669 && (targetm.cannot_force_const_mem (mode, src)
3670 || (!TARGET_MIPS16 && can_create_pseudo_p ())))
3672 base = mips_force_temporary (dest, base);
3673 mips_emit_move (dest, mips_add_offset (NULL, base, INTVAL (offset)));
3674 return;
3677 src = force_const_mem (mode, src);
3679 /* When using explicit relocs, constant pool references are sometimes
3680 not legitimate addresses. */
3681 mips_split_symbol (dest, XEXP (src, 0), mode, &XEXP (src, 0));
3682 mips_emit_move (dest, src);
3685 /* If (set DEST SRC) is not a valid move instruction, emit an equivalent
3686 sequence that is valid. */
3688 bool
3689 mips_legitimize_move (machine_mode mode, rtx dest, rtx src)
3691 if (!register_operand (dest, mode) && !register_operand (src, mode))
3693 if (TARGET_MIPS16 || !const_0_operand (src, mode)
3694 || MSA_SUPPORTED_MODE_P (mode))
3696 mips_emit_move (dest, force_reg (mode, src));
3697 return true;
3701 /* We need to deal with constants that would be legitimate
3702 immediate_operands but aren't legitimate move_operands. */
3703 if (CONSTANT_P (src) && !move_operand (src, mode))
3705 mips_legitimize_const_move (mode, dest, src);
3706 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src));
3707 return true;
3709 return false;
3712 /* Return true if value X in context CONTEXT is a small-data address
3713 that can be rewritten as a LO_SUM. */
3715 static bool
3716 mips_rewrite_small_data_p (rtx x, enum mips_symbol_context context)
3718 enum mips_symbol_type symbol_type;
3720 return (mips_lo_relocs[SYMBOL_GP_RELATIVE]
3721 && !mips_split_p[SYMBOL_GP_RELATIVE]
3722 && mips_symbolic_constant_p (x, context, &symbol_type)
3723 && symbol_type == SYMBOL_GP_RELATIVE);
3726 /* A for_each_rtx callback for mips_small_data_pattern_p. DATA is the
3727 containing MEM, or null if none. */
3729 static int
3730 mips_small_data_pattern_1 (rtx *loc, void *data)
3732 enum mips_symbol_context context;
3734 /* Ignore things like "g" constraints in asms. We make no particular
3735 guarantee about which symbolic constants are acceptable as asm operands
3736 versus which must be forced into a GPR. */
3737 if (GET_CODE (*loc) == LO_SUM || GET_CODE (*loc) == ASM_OPERANDS)
3738 return -1;
3740 if (MEM_P (*loc))
3742 if (for_each_rtx (&XEXP (*loc, 0), mips_small_data_pattern_1, *loc))
3743 return 1;
3744 return -1;
3747 context = data ? SYMBOL_CONTEXT_MEM : SYMBOL_CONTEXT_LEA;
3748 return mips_rewrite_small_data_p (*loc, context);
3751 /* Return true if OP refers to small data symbols directly, not through
3752 a LO_SUM. */
3754 bool
3755 mips_small_data_pattern_p (rtx op)
3757 return for_each_rtx (&op, mips_small_data_pattern_1, NULL);
3760 /* A for_each_rtx callback, used by mips_rewrite_small_data.
3761 DATA is the containing MEM, or null if none. */
3763 static int
3764 mips_rewrite_small_data_1 (rtx *loc, void *data)
3766 enum mips_symbol_context context;
3768 if (MEM_P (*loc))
3770 for_each_rtx (&XEXP (*loc, 0), mips_rewrite_small_data_1, *loc);
3771 return -1;
3774 context = data ? SYMBOL_CONTEXT_MEM : SYMBOL_CONTEXT_LEA;
3775 if (mips_rewrite_small_data_p (*loc, context))
3776 *loc = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, *loc);
3778 if (GET_CODE (*loc) == LO_SUM)
3779 return -1;
3781 return 0;
3784 /* Rewrite instruction pattern PATTERN so that it refers to small data
3785 using explicit relocations. */
3788 mips_rewrite_small_data (rtx pattern)
3790 pattern = copy_insn (pattern);
3791 for_each_rtx (&pattern, mips_rewrite_small_data_1, NULL);
3792 return pattern;
3795 /* The cost of loading values from the constant pool. It should be
3796 larger than the cost of any constant we want to synthesize inline. */
3797 #define CONSTANT_POOL_COST COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 8)
3799 /* Return the cost of X when used as an operand to the MIPS16 instruction
3800 that implements CODE. Return -1 if there is no such instruction, or if
3801 X is not a valid immediate operand for it. */
3803 static int
3804 mips16_constant_cost (int code, HOST_WIDE_INT x)
3806 switch (code)
3808 case ASHIFT:
3809 case ASHIFTRT:
3810 case LSHIFTRT:
3811 /* Shifts by between 1 and 8 bits (inclusive) are unextended,
3812 other shifts are extended. The shift patterns truncate the shift
3813 count to the right size, so there are no out-of-range values. */
3814 if (IN_RANGE (x, 1, 8))
3815 return 0;
3816 return COSTS_N_INSNS (1);
3818 case PLUS:
3819 if (IN_RANGE (x, -128, 127))
3820 return 0;
3821 if (SMALL_OPERAND (x))
3822 return COSTS_N_INSNS (1);
3823 return -1;
3825 case LEU:
3826 /* Like LE, but reject the always-true case. */
3827 if (x == -1)
3828 return -1;
3829 case LE:
3830 /* We add 1 to the immediate and use SLT. */
3831 x += 1;
3832 case XOR:
3833 /* We can use CMPI for an xor with an unsigned 16-bit X. */
3834 case LT:
3835 case LTU:
3836 if (IN_RANGE (x, 0, 255))
3837 return 0;
3838 if (SMALL_OPERAND_UNSIGNED (x))
3839 return COSTS_N_INSNS (1);
3840 return -1;
3842 case EQ:
3843 case NE:
3844 /* Equality comparisons with 0 are cheap. */
3845 if (x == 0)
3846 return 0;
3847 return -1;
3849 default:
3850 return -1;
3854 /* Return true if there is a non-MIPS16 instruction that implements CODE
3855 and if that instruction accepts X as an immediate operand. */
3857 static int
3858 mips_immediate_operand_p (int code, HOST_WIDE_INT x)
3860 switch (code)
3862 case ASHIFT:
3863 case ASHIFTRT:
3864 case LSHIFTRT:
3865 /* All shift counts are truncated to a valid constant. */
3866 return true;
3868 case ROTATE:
3869 case ROTATERT:
3870 /* Likewise rotates, if the target supports rotates at all. */
3871 return ISA_HAS_ROR;
3873 case AND:
3874 case IOR:
3875 case XOR:
3876 /* These instructions take 16-bit unsigned immediates. */
3877 return SMALL_OPERAND_UNSIGNED (x);
3879 case PLUS:
3880 case LT:
3881 case LTU:
3882 /* These instructions take 16-bit signed immediates. */
3883 return SMALL_OPERAND (x);
3885 case EQ:
3886 case NE:
3887 case GT:
3888 case GTU:
3889 /* The "immediate" forms of these instructions are really
3890 implemented as comparisons with register 0. */
3891 return x == 0;
3893 case GE:
3894 case GEU:
3895 /* Likewise, meaning that the only valid immediate operand is 1. */
3896 return x == 1;
3898 case LE:
3899 /* We add 1 to the immediate and use SLT. */
3900 return SMALL_OPERAND (x + 1);
3902 case LEU:
3903 /* Likewise SLTU, but reject the always-true case. */
3904 return SMALL_OPERAND (x + 1) && x + 1 != 0;
3906 case SIGN_EXTRACT:
3907 case ZERO_EXTRACT:
3908 /* The bit position and size are immediate operands. */
3909 return ISA_HAS_EXT_INS;
3911 default:
3912 /* By default assume that $0 can be used for 0. */
3913 return x == 0;
3917 /* Return the cost of binary operation X, given that the instruction
3918 sequence for a word-sized or smaller operation has cost SINGLE_COST
3919 and that the sequence of a double-word operation has cost DOUBLE_COST.
3920 If SPEED is true, optimize for speed otherwise optimize for size. */
3922 static int
3923 mips_binary_cost (rtx x, int single_cost, int double_cost, bool speed)
3925 int cost;
3927 if (GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD * 2)
3928 cost = double_cost;
3929 else
3930 cost = single_cost;
3931 return (cost
3932 + set_src_cost (XEXP (x, 0), speed)
3933 + rtx_cost (XEXP (x, 1), GET_CODE (x), 1, speed));
3936 /* Return the cost of floating-point multiplications of mode MODE. */
3938 static int
3939 mips_fp_mult_cost (machine_mode mode)
3941 return mode == DFmode ? mips_cost->fp_mult_df : mips_cost->fp_mult_sf;
3944 /* Return the cost of floating-point divisions of mode MODE. */
3946 static int
3947 mips_fp_div_cost (machine_mode mode)
3949 return mode == DFmode ? mips_cost->fp_div_df : mips_cost->fp_div_sf;
3952 /* Return the cost of sign-extending OP to mode MODE, not including the
3953 cost of OP itself. */
3955 static int
3956 mips_sign_extend_cost (machine_mode mode, rtx op)
3958 if (MEM_P (op))
3959 /* Extended loads are as cheap as unextended ones. */
3960 return 0;
3962 if (TARGET_64BIT && mode == DImode && GET_MODE (op) == SImode)
3963 /* A sign extension from SImode to DImode in 64-bit mode is free. */
3964 return 0;
3966 if (ISA_HAS_SEB_SEH || GENERATE_MIPS16E)
3967 /* We can use SEB or SEH. */
3968 return COSTS_N_INSNS (1);
3970 /* We need to use a shift left and a shift right. */
3971 return COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 2);
3974 /* Return the cost of zero-extending OP to mode MODE, not including the
3975 cost of OP itself. */
3977 static int
3978 mips_zero_extend_cost (machine_mode mode, rtx op)
3980 if (MEM_P (op))
3981 /* Extended loads are as cheap as unextended ones. */
3982 return 0;
3984 if (TARGET_64BIT && mode == DImode && GET_MODE (op) == SImode)
3985 /* We need a shift left by 32 bits and a shift right by 32 bits. */
3986 return COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 2);
3988 if (GENERATE_MIPS16E)
3989 /* We can use ZEB or ZEH. */
3990 return COSTS_N_INSNS (1);
3992 if (TARGET_MIPS16)
3993 /* We need to load 0xff or 0xffff into a register and use AND. */
3994 return COSTS_N_INSNS (GET_MODE (op) == QImode ? 2 : 3);
3996 /* We can use ANDI. */
3997 return COSTS_N_INSNS (1);
4000 /* Return the cost of moving between two registers of mode MODE,
4001 assuming that the move will be in pieces of at most UNITS bytes. */
4003 static int
4004 mips_set_reg_reg_piece_cost (machine_mode mode, unsigned int units)
4006 return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
4009 /* Return the cost of moving between two registers of mode MODE. */
4011 static int
4012 mips_set_reg_reg_cost (machine_mode mode)
4014 switch (GET_MODE_CLASS (mode))
4016 case MODE_CC:
4017 return mips_set_reg_reg_piece_cost (mode, GET_MODE_SIZE (CCmode));
4019 case MODE_FLOAT:
4020 case MODE_COMPLEX_FLOAT:
4021 case MODE_VECTOR_FLOAT:
4022 if (TARGET_HARD_FLOAT)
4023 return mips_set_reg_reg_piece_cost (mode, UNITS_PER_HWFPVALUE);
4024 /* Fall through */
4026 default:
4027 return mips_set_reg_reg_piece_cost (mode, UNITS_PER_WORD);
4031 /* Implement TARGET_RTX_COSTS. */
4033 static bool
4034 mips_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
4035 int *total, bool speed)
4037 machine_mode mode = GET_MODE (x);
4038 bool float_mode_p = FLOAT_MODE_P (mode);
4039 int cost;
4040 rtx addr;
4042 /* The cost of a COMPARE is hard to define for MIPS. COMPAREs don't
4043 appear in the instruction stream, and the cost of a comparison is
4044 really the cost of the branch or scc condition. At the time of
4045 writing, GCC only uses an explicit outer COMPARE code when optabs
4046 is testing whether a constant is expensive enough to force into a
4047 register. We want optabs to pass such constants through the MIPS
4048 expanders instead, so make all constants very cheap here. */
4049 if (outer_code == COMPARE)
4051 gcc_assert (CONSTANT_P (x));
4052 *total = 0;
4053 return true;
4056 switch (code)
4058 case CONST_INT:
4059 /* Treat *clear_upper32-style ANDs as having zero cost in the
4060 second operand. The cost is entirely in the first operand.
4062 ??? This is needed because we would otherwise try to CSE
4063 the constant operand. Although that's the right thing for
4064 instructions that continue to be a register operation throughout
4065 compilation, it is disastrous for instructions that could
4066 later be converted into a memory operation. */
4067 if (TARGET_64BIT
4068 && outer_code == AND
4069 && UINTVAL (x) == 0xffffffff)
4071 *total = 0;
4072 return true;
4075 if (TARGET_MIPS16)
4077 cost = mips16_constant_cost (outer_code, INTVAL (x));
4078 if (cost >= 0)
4080 *total = cost;
4081 return true;
4084 else
4086 /* When not optimizing for size, we care more about the cost
4087 of hot code, and hot code is often in a loop. If a constant
4088 operand needs to be forced into a register, we will often be
4089 able to hoist the constant load out of the loop, so the load
4090 should not contribute to the cost. */
4091 if (speed || mips_immediate_operand_p (outer_code, INTVAL (x)))
4093 *total = 0;
4094 return true;
4097 /* Fall through. */
4099 case CONST:
4100 case SYMBOL_REF:
4101 case LABEL_REF:
4102 case CONST_DOUBLE:
4103 if (force_to_mem_operand (x, VOIDmode))
4105 *total = COSTS_N_INSNS (1);
4106 return true;
4108 cost = mips_const_insns (x);
4109 if (cost > 0)
4111 /* If the constant is likely to be stored in a GPR, SETs of
4112 single-insn constants are as cheap as register sets; we
4113 never want to CSE them.
4115 Don't reduce the cost of storing a floating-point zero in
4116 FPRs. If we have a zero in an FPR for other reasons, we
4117 can get better cfg-cleanup and delayed-branch results by
4118 using it consistently, rather than using $0 sometimes and
4119 an FPR at other times. Also, moves between floating-point
4120 registers are sometimes cheaper than (D)MTC1 $0. */
4121 if (cost == 1
4122 && outer_code == SET
4123 && !(float_mode_p && TARGET_HARD_FLOAT))
4124 cost = 0;
4125 /* When non-MIPS16 code loads a constant N>1 times, we rarely
4126 want to CSE the constant itself. It is usually better to
4127 have N copies of the last operation in the sequence and one
4128 shared copy of the other operations. (Note that this is
4129 not true for MIPS16 code, where the final operation in the
4130 sequence is often an extended instruction.)
4132 Also, if we have a CONST_INT, we don't know whether it is
4133 for a word or doubleword operation, so we cannot rely on
4134 the result of mips_build_integer. */
4135 else if (!TARGET_MIPS16
4136 && (outer_code == SET || mode == VOIDmode))
4137 cost = 1;
4138 *total = COSTS_N_INSNS (cost);
4139 return true;
4141 /* The value will need to be fetched from the constant pool. */
4142 *total = CONSTANT_POOL_COST;
4143 return true;
4145 case MEM:
4146 /* If the address is legitimate, return the number of
4147 instructions it needs. */
4148 addr = XEXP (x, 0);
4149 cost = mips_address_insns (addr, mode, true);
4150 if (cost > 0)
4152 *total = COSTS_N_INSNS (cost + 1);
4153 return true;
4155 /* Check for a scaled indexed address. */
4156 if (mips_lwxs_address_p (addr)
4157 || mips_lx_address_p (addr, mode))
4159 *total = COSTS_N_INSNS (2);
4160 return true;
4162 /* Otherwise use the default handling. */
4163 return false;
4165 case FFS:
4166 *total = COSTS_N_INSNS (6);
4167 return false;
4169 case NOT:
4170 *total = COSTS_N_INSNS (GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1);
4171 return false;
4173 case AND:
4174 /* Check for a *clear_upper32 pattern and treat it like a zero
4175 extension. See the pattern's comment for details. */
4176 if (TARGET_64BIT
4177 && mode == DImode
4178 && CONST_INT_P (XEXP (x, 1))
4179 && UINTVAL (XEXP (x, 1)) == 0xffffffff)
4181 *total = (mips_zero_extend_cost (mode, XEXP (x, 0))
4182 + set_src_cost (XEXP (x, 0), speed));
4183 return true;
4185 if (ISA_HAS_CINS && CONST_INT_P (XEXP (x, 1)))
4187 rtx op = XEXP (x, 0);
4188 if (GET_CODE (op) == ASHIFT
4189 && CONST_INT_P (XEXP (op, 1))
4190 && mask_low_and_shift_p (mode, XEXP (x, 1), XEXP (op, 1), 32))
4192 *total = COSTS_N_INSNS (1) + set_src_cost (XEXP (op, 0), speed);
4193 return true;
4196 /* (AND (NOT op0) (NOT op1) is a nor operation that can be done in
4197 a single instruction. */
4198 if (!TARGET_MIPS16
4199 && GET_CODE (XEXP (x, 0)) == NOT
4200 && GET_CODE (XEXP (x, 1)) == NOT)
4202 cost = GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1;
4203 *total = (COSTS_N_INSNS (cost)
4204 + set_src_cost (XEXP (XEXP (x, 0), 0), speed)
4205 + set_src_cost (XEXP (XEXP (x, 1), 0), speed));
4206 return true;
4209 /* Fall through. */
4211 case IOR:
4212 case XOR:
4213 /* Double-word operations use two single-word operations. */
4214 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (2),
4215 speed);
4216 return true;
4218 case ASHIFT:
4219 case ASHIFTRT:
4220 case LSHIFTRT:
4221 case ROTATE:
4222 case ROTATERT:
4223 if (CONSTANT_P (XEXP (x, 1)))
4224 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (4),
4225 speed);
4226 else
4227 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (12),
4228 speed);
4229 return true;
4231 case ABS:
4232 if (float_mode_p)
4233 *total = mips_cost->fp_add;
4234 else
4235 *total = COSTS_N_INSNS (4);
4236 return false;
4238 case LO_SUM:
4239 /* Low-part immediates need an extended MIPS16 instruction. */
4240 *total = (COSTS_N_INSNS (TARGET_MIPS16 ? 2 : 1)
4241 + set_src_cost (XEXP (x, 0), speed));
4242 return true;
4244 case LT:
4245 case LTU:
4246 case LE:
4247 case LEU:
4248 case GT:
4249 case GTU:
4250 case GE:
4251 case GEU:
4252 case EQ:
4253 case NE:
4254 case UNORDERED:
4255 case LTGT:
4256 case UNGE:
4257 case UNGT:
4258 case UNLE:
4259 case UNLT:
4260 /* Branch comparisons have VOIDmode, so use the first operand's
4261 mode instead. */
4262 mode = GET_MODE (XEXP (x, 0));
4263 if (FLOAT_MODE_P (mode))
4265 *total = mips_cost->fp_add;
4266 return false;
4268 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (4),
4269 speed);
4270 return true;
4272 case MINUS:
4273 if (float_mode_p
4274 && (ISA_HAS_NMADD4_NMSUB4 || ISA_HAS_NMADD3_NMSUB3)
4275 && TARGET_FUSED_MADD
4276 && !HONOR_NANS (mode)
4277 && !HONOR_SIGNED_ZEROS (mode))
4279 /* See if we can use NMADD or NMSUB. See mips.md for the
4280 associated patterns. */
4281 rtx op0 = XEXP (x, 0);
4282 rtx op1 = XEXP (x, 1);
4283 if (GET_CODE (op0) == MULT && GET_CODE (XEXP (op0, 0)) == NEG)
4285 *total = (mips_fp_mult_cost (mode)
4286 + set_src_cost (XEXP (XEXP (op0, 0), 0), speed)
4287 + set_src_cost (XEXP (op0, 1), speed)
4288 + set_src_cost (op1, speed));
4289 return true;
4291 if (GET_CODE (op1) == MULT)
4293 *total = (mips_fp_mult_cost (mode)
4294 + set_src_cost (op0, speed)
4295 + set_src_cost (XEXP (op1, 0), speed)
4296 + set_src_cost (XEXP (op1, 1), speed));
4297 return true;
4300 /* Fall through. */
4302 case PLUS:
4303 if (float_mode_p)
4305 /* If this is part of a MADD or MSUB, treat the PLUS as
4306 being free. */
4307 if ((ISA_HAS_FP_MADD4_MSUB4 || ISA_HAS_FP_MADD3_MSUB3)
4308 && TARGET_FUSED_MADD
4309 && GET_CODE (XEXP (x, 0)) == MULT)
4310 *total = 0;
4311 else
4312 *total = mips_cost->fp_add;
4313 return false;
4316 /* If it's an add + mult (which is equivalent to shift left) and
4317 it's immediate operand satisfies const_immlsa_operand predicate. */
4318 if (((ISA_HAS_LSA && mode == SImode)
4319 || (ISA_HAS_DLSA && mode == DImode))
4320 && GET_CODE (XEXP (x, 0)) == MULT)
4322 rtx op2 = XEXP (XEXP (x, 0), 1);
4323 if (const_immlsa_operand (op2, mode))
4325 *total = (COSTS_N_INSNS (1)
4326 + set_src_cost (XEXP (XEXP (x, 0), 0), speed)
4327 + set_src_cost (XEXP (x, 1), speed));
4328 return true;
4332 /* Double-word operations require three single-word operations and
4333 an SLTU. The MIPS16 version then needs to move the result of
4334 the SLTU from $24 to a MIPS16 register. */
4335 *total = mips_binary_cost (x, COSTS_N_INSNS (1),
4336 COSTS_N_INSNS (TARGET_MIPS16 ? 5 : 4),
4337 speed);
4338 return true;
4340 case NEG:
4341 if (float_mode_p
4342 && (ISA_HAS_NMADD4_NMSUB4 || ISA_HAS_NMADD3_NMSUB3)
4343 && TARGET_FUSED_MADD
4344 && !HONOR_NANS (mode)
4345 && HONOR_SIGNED_ZEROS (mode))
4347 /* See if we can use NMADD or NMSUB. See mips.md for the
4348 associated patterns. */
4349 rtx op = XEXP (x, 0);
4350 if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS)
4351 && GET_CODE (XEXP (op, 0)) == MULT)
4353 *total = (mips_fp_mult_cost (mode)
4354 + set_src_cost (XEXP (XEXP (op, 0), 0), speed)
4355 + set_src_cost (XEXP (XEXP (op, 0), 1), speed)
4356 + set_src_cost (XEXP (op, 1), speed));
4357 return true;
4361 if (float_mode_p)
4362 *total = mips_cost->fp_add;
4363 else
4364 *total = COSTS_N_INSNS (GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 4 : 1);
4365 return false;
4367 case FMA:
4368 if (ISA_HAS_FP_MADDF_MSUBF)
4369 *total = mips_fp_mult_cost (mode);
4370 return false;
4372 case MULT:
4373 if (float_mode_p)
4374 *total = mips_fp_mult_cost (mode);
4375 else if (mode == DImode && !TARGET_64BIT)
4376 /* Synthesized from 2 mulsi3s, 1 mulsidi3 and two additions,
4377 where the mulsidi3 always includes an MFHI and an MFLO. */
4378 *total = (speed
4379 ? mips_cost->int_mult_si * 3 + 6
4380 : COSTS_N_INSNS (ISA_HAS_MUL3 ? 7 : 9));
4381 else if (!speed)
4382 *total = COSTS_N_INSNS ((ISA_HAS_MUL3 || ISA_HAS_R6MUL) ? 1 : 2) + 1;
4383 else if (mode == DImode)
4384 *total = mips_cost->int_mult_di;
4385 else
4386 *total = mips_cost->int_mult_si;
4387 return false;
4389 case DIV:
4390 /* Check for a reciprocal. */
4391 if (float_mode_p
4392 && ISA_HAS_FP_RECIP_RSQRT (mode)
4393 && flag_unsafe_math_optimizations
4394 && XEXP (x, 0) == CONST1_RTX (mode))
4396 if (outer_code == SQRT || GET_CODE (XEXP (x, 1)) == SQRT)
4397 /* An rsqrt<mode>a or rsqrt<mode>b pattern. Count the
4398 division as being free. */
4399 *total = set_src_cost (XEXP (x, 1), speed);
4400 else
4401 *total = (mips_fp_div_cost (mode)
4402 + set_src_cost (XEXP (x, 1), speed));
4403 return true;
4405 /* Fall through. */
4407 case SQRT:
4408 case MOD:
4409 if (float_mode_p)
4411 *total = mips_fp_div_cost (mode);
4412 return false;
4414 /* Fall through. */
4416 case UDIV:
4417 case UMOD:
4418 if (!speed)
4420 /* It is our responsibility to make division by a power of 2
4421 as cheap as 2 register additions if we want the division
4422 expanders to be used for such operations; see the setting
4423 of sdiv_pow2_cheap in optabs.c. Using (D)DIV for MIPS16
4424 should always produce shorter code than using
4425 expand_sdiv2_pow2. */
4426 if (TARGET_MIPS16
4427 && CONST_INT_P (XEXP (x, 1))
4428 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
4430 *total = COSTS_N_INSNS (2) + set_src_cost (XEXP (x, 0), speed);
4431 return true;
4433 *total = COSTS_N_INSNS (mips_idiv_insns ());
4434 if (MSA_SUPPORTED_MODE_P (mode))
4435 *total = COSTS_N_INSNS (mips_msa_idiv_insns ());
4436 else
4437 *total = COSTS_N_INSNS (mips_idiv_insns ());
4439 else if (mode == DImode)
4440 *total = mips_cost->int_div_di;
4441 else
4442 *total = mips_cost->int_div_si;
4443 return false;
4445 case SIGN_EXTEND:
4446 *total = mips_sign_extend_cost (mode, XEXP (x, 0));
4447 return false;
4449 case ZERO_EXTEND:
4450 if (outer_code == SET
4451 && ISA_HAS_BADDU
4452 && (GET_CODE (XEXP (x, 0)) == TRUNCATE
4453 || GET_CODE (XEXP (x, 0)) == SUBREG)
4454 && GET_MODE (XEXP (x, 0)) == QImode
4455 && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS)
4457 *total = set_src_cost (XEXP (XEXP (x, 0), 0), speed);
4458 return true;
4460 *total = mips_zero_extend_cost (mode, XEXP (x, 0));
4461 return false;
4462 case TRUNCATE:
4463 /* Costings for highpart multiplies. Matching patterns of the form:
4465 (lshiftrt:DI (mult:DI (sign_extend:DI (...)
4466 (sign_extend:DI (...))
4467 (const_int 32)
4469 if (ISA_HAS_R6MUL
4470 && (GET_CODE (XEXP (x, 0)) == ASHIFTRT
4471 || GET_CODE (XEXP (x, 0)) == LSHIFTRT)
4472 && CONST_INT_P (XEXP (XEXP (x, 0), 1))
4473 && ((INTVAL (XEXP (XEXP (x, 0), 1)) == 32
4474 && GET_MODE (XEXP (x, 0)) == DImode)
4475 || (ISA_HAS_R6DMUL
4476 && INTVAL (XEXP (XEXP (x, 0), 1)) == 64
4477 && GET_MODE (XEXP (x, 0)) == TImode))
4478 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
4479 && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND
4480 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == SIGN_EXTEND)
4481 || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND
4482 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1))
4483 == ZERO_EXTEND))))
4485 if (!speed)
4486 *total = COSTS_N_INSNS (1) + 1;
4487 else if (mode == DImode)
4488 *total = mips_cost->int_mult_di;
4489 else
4490 *total = mips_cost->int_mult_si;
4492 /* Sign extension is free, zero extension costs for DImode when
4493 on a 64bit core / when DMUL is present. */
4494 for (int i = 0; i < 2; ++i)
4496 rtx op = XEXP (XEXP (XEXP (x, 0), 0), i);
4497 if (ISA_HAS_R6DMUL
4498 && GET_CODE (op) == ZERO_EXTEND
4499 && GET_MODE (op) == DImode)
4500 *total += rtx_cost (op, MULT, i, speed);
4501 else
4502 *total += rtx_cost (XEXP (op, 0), GET_CODE (op), 0, speed);
4505 return true;
4507 return false;
4509 case FLOAT:
4510 case UNSIGNED_FLOAT:
4511 case FIX:
4512 case FLOAT_EXTEND:
4513 case FLOAT_TRUNCATE:
4514 *total = mips_cost->fp_add;
4515 return false;
4517 case SET:
4518 if (register_operand (SET_DEST (x), VOIDmode)
4519 && reg_or_0_operand (SET_SRC (x), VOIDmode))
4521 *total = mips_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
4522 return true;
4524 return false;
4526 default:
4527 return false;
4531 /* Implement TARGET_ADDRESS_COST. */
4533 static int
4534 mips_address_cost (rtx addr, machine_mode mode,
4535 addr_space_t as ATTRIBUTE_UNUSED,
4536 bool speed ATTRIBUTE_UNUSED)
4538 return mips_address_insns (addr, mode, false);
4541 /* Information about a single instruction in a multi-instruction
4542 asm sequence. */
4543 struct mips_multi_member {
4544 /* True if this is a label, false if it is code. */
4545 bool is_label_p;
4547 /* The output_asm_insn format of the instruction. */
4548 const char *format;
4550 /* The operands to the instruction. */
4551 rtx operands[MAX_RECOG_OPERANDS];
4553 typedef struct mips_multi_member mips_multi_member;
4555 /* The instructions that make up the current multi-insn sequence. */
4556 static vec<mips_multi_member> mips_multi_members;
4558 /* How many instructions (as opposed to labels) are in the current
4559 multi-insn sequence. */
4560 static unsigned int mips_multi_num_insns;
4562 /* Start a new multi-insn sequence. */
4564 static void
4565 mips_multi_start (void)
4567 mips_multi_members.truncate (0);
4568 mips_multi_num_insns = 0;
4571 /* Add a new, uninitialized member to the current multi-insn sequence. */
4573 static struct mips_multi_member *
4574 mips_multi_add (void)
4576 mips_multi_member empty;
4577 return mips_multi_members.safe_push (empty);
4580 /* Add a normal insn with the given asm format to the current multi-insn
4581 sequence. The other arguments are a null-terminated list of operands. */
4583 static void
4584 mips_multi_add_insn (const char *format, ...)
4586 struct mips_multi_member *member;
4587 va_list ap;
4588 unsigned int i;
4589 rtx op;
4591 member = mips_multi_add ();
4592 member->is_label_p = false;
4593 member->format = format;
4594 va_start (ap, format);
4595 i = 0;
4596 while ((op = va_arg (ap, rtx)))
4597 member->operands[i++] = op;
4598 va_end (ap);
4599 mips_multi_num_insns++;
4602 /* Add the given label definition to the current multi-insn sequence.
4603 The definition should include the colon. */
4605 static void
4606 mips_multi_add_label (const char *label)
4608 struct mips_multi_member *member;
4610 member = mips_multi_add ();
4611 member->is_label_p = true;
4612 member->format = label;
4615 /* Return the index of the last member of the current multi-insn sequence. */
4617 static unsigned int
4618 mips_multi_last_index (void)
4620 return mips_multi_members.length () - 1;
4623 /* Add a copy of an existing instruction to the current multi-insn
4624 sequence. I is the index of the instruction that should be copied. */
4626 static void
4627 mips_multi_copy_insn (unsigned int i)
4629 struct mips_multi_member *member;
4631 member = mips_multi_add ();
4632 memcpy (member, &mips_multi_members[i], sizeof (*member));
4633 gcc_assert (!member->is_label_p);
4636 /* Change the operand of an existing instruction in the current
4637 multi-insn sequence. I is the index of the instruction,
4638 OP is the index of the operand, and X is the new value. */
4640 static void
4641 mips_multi_set_operand (unsigned int i, unsigned int op, rtx x)
4643 mips_multi_members[i].operands[op] = x;
4646 /* Write out the asm code for the current multi-insn sequence. */
4648 static void
4649 mips_multi_write (void)
4651 struct mips_multi_member *member;
4652 unsigned int i;
4654 FOR_EACH_VEC_ELT (mips_multi_members, i, member)
4655 if (member->is_label_p)
4656 fprintf (asm_out_file, "%s\n", member->format);
4657 else
4658 output_asm_insn (member->format, member->operands);
4661 /* Return one word of double-word value OP, taking into account the fixed
4662 endianness of certain registers. HIGH_P is true to select the high part,
4663 false to select the low part. */
4666 mips_subword (rtx op, bool high_p)
4668 unsigned int byte, offset;
4669 machine_mode mode;
4671 mode = GET_MODE (op);
4672 if (mode == VOIDmode)
4673 mode = TARGET_64BIT ? TImode : DImode;
4675 if (TARGET_BIG_ENDIAN ? !high_p : high_p)
4676 byte = UNITS_PER_WORD;
4677 else
4678 byte = 0;
4680 if (FP_REG_RTX_P (op))
4682 /* Paired FPRs are always ordered little-endian. */
4683 offset = (UNITS_PER_WORD < UNITS_PER_HWFPVALUE ? high_p : byte != 0);
4684 return gen_rtx_REG (word_mode, REGNO (op) + offset);
4687 if (MEM_P (op))
4688 return mips_rewrite_small_data (adjust_address (op, word_mode, byte));
4690 return simplify_gen_subreg (word_mode, op, mode, byte);
4693 /* Return true if SRC should be moved into DEST using "MULT $0, $0".
4694 SPLIT_TYPE is the condition under which moves should be split. */
4696 static bool
4697 mips_mult_move_p (rtx dest, rtx src, enum mips_split_type split_type)
4699 return ((split_type != SPLIT_FOR_SPEED
4700 || mips_tuning_info.fast_mult_zero_zero_p)
4701 && src == const0_rtx
4702 && REG_P (dest)
4703 && GET_MODE_SIZE (GET_MODE (dest)) == 2 * UNITS_PER_WORD
4704 && (ISA_HAS_DSP_MULT
4705 ? ACC_REG_P (REGNO (dest))
4706 : MD_REG_P (REGNO (dest))));
4709 /* Return true if a move from SRC to DEST should be split into two.
4710 SPLIT_TYPE describes the split condition. */
4712 bool
4713 mips_split_move_p (rtx dest, rtx src, enum mips_split_type split_type)
4715 /* Check whether the move can be done using some variant of MULT $0,$0. */
4716 if (mips_mult_move_p (dest, src, split_type))
4717 return false;
4719 /* FPR-to-FPR moves can be done in a single instruction, if they're
4720 allowed at all. */
4721 unsigned int size = GET_MODE_SIZE (GET_MODE (dest));
4722 if (size == 8 && FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
4723 return false;
4725 /* Check for floating-point loads and stores. */
4726 if (size == 8 && ISA_HAS_LDC1_SDC1)
4728 if (FP_REG_RTX_P (dest) && MEM_P (src))
4729 return false;
4730 if (FP_REG_RTX_P (src) && MEM_P (dest))
4731 return false;
4734 /* Check if MSA moves need splitting. */
4735 if (MSA_SUPPORTED_MODE_P (GET_MODE (dest)))
4736 return mips_split_128bit_move_p (dest, src);
4738 /* Otherwise split all multiword moves. */
4739 return size > UNITS_PER_WORD;
4742 /* Split a move from SRC to DEST, given that mips_split_move_p holds.
4743 SPLIT_TYPE describes the split condition. */
4745 void
4746 mips_split_move (rtx dest, rtx src, enum mips_split_type split_type)
4748 rtx low_dest;
4750 gcc_checking_assert (mips_split_move_p (dest, src, split_type));
4751 if (MSA_SUPPORTED_MODE_P (GET_MODE (dest)))
4752 mips_split_128bit_move (dest, src);
4753 else if (FP_REG_RTX_P (dest) || FP_REG_RTX_P (src))
4755 if (!TARGET_64BIT && GET_MODE (dest) == DImode)
4756 emit_insn (gen_move_doubleword_fprdi (dest, src));
4757 else if (!TARGET_64BIT && GET_MODE (dest) == DFmode)
4758 emit_insn (gen_move_doubleword_fprdf (dest, src));
4759 else if (!TARGET_64BIT && GET_MODE (dest) == V2SFmode)
4760 emit_insn (gen_move_doubleword_fprv2sf (dest, src));
4761 else if (!TARGET_64BIT && GET_MODE (dest) == V2SImode)
4762 emit_insn (gen_move_doubleword_fprv2si (dest, src));
4763 else if (!TARGET_64BIT && GET_MODE (dest) == V4HImode)
4764 emit_insn (gen_move_doubleword_fprv4hi (dest, src));
4765 else if (!TARGET_64BIT && GET_MODE (dest) == V8QImode)
4766 emit_insn (gen_move_doubleword_fprv8qi (dest, src));
4767 else if (TARGET_64BIT && GET_MODE (dest) == TFmode)
4768 emit_insn (gen_move_doubleword_fprtf (dest, src));
4769 else
4770 gcc_unreachable ();
4772 else if (REG_P (dest) && REGNO (dest) == MD_REG_FIRST)
4774 low_dest = mips_subword (dest, false);
4775 mips_emit_move (low_dest, mips_subword (src, false));
4776 if (TARGET_64BIT)
4777 emit_insn (gen_mthidi_ti (dest, mips_subword (src, true), low_dest));
4778 else
4779 emit_insn (gen_mthisi_di (dest, mips_subword (src, true), low_dest));
4781 else if (REG_P (src) && REGNO (src) == MD_REG_FIRST)
4783 mips_emit_move (mips_subword (dest, false), mips_subword (src, false));
4784 if (TARGET_64BIT)
4785 emit_insn (gen_mfhidi_ti (mips_subword (dest, true), src));
4786 else
4787 emit_insn (gen_mfhisi_di (mips_subword (dest, true), src));
4789 else
4791 /* The operation can be split into two normal moves. Decide in
4792 which order to do them. */
4793 low_dest = mips_subword (dest, false);
4794 if (REG_P (low_dest)
4795 && reg_overlap_mentioned_p (low_dest, src))
4797 mips_emit_move (mips_subword (dest, true), mips_subword (src, true));
4798 mips_emit_move (low_dest, mips_subword (src, false));
4800 else
4802 mips_emit_move (low_dest, mips_subword (src, false));
4803 mips_emit_move (mips_subword (dest, true), mips_subword (src, true));
4808 /* Return the split type for instruction INSN. */
4810 static enum mips_split_type
4811 mips_insn_split_type (rtx insn)
4813 basic_block bb = BLOCK_FOR_INSN (insn);
4814 if (bb)
4816 if (optimize_bb_for_speed_p (bb))
4817 return SPLIT_FOR_SPEED;
4818 else
4819 return SPLIT_FOR_SIZE;
4821 /* Once CFG information has been removed, we should trust the optimization
4822 decisions made by previous passes and only split where necessary. */
4823 return SPLIT_IF_NECESSARY;
4826 /* Return true if a 128-bit move from SRC to DEST should be split. */
4828 bool
4829 mips_split_128bit_move_p (rtx dest, rtx src)
4831 /* MSA-to-MSA moves can be done in a single instruction. */
4832 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest))
4833 return false;
4835 /* Check for MSA loads and stores. */
4836 if (FP_REG_RTX_P (dest) && MEM_P (src))
4837 return false;
4838 if (FP_REG_RTX_P (src) && MEM_P (dest))
4839 return false;
4841 /* Check for MSA set to an immediate const vector with valid replicated
4842 element. */
4843 if (FP_REG_RTX_P (dest)
4844 && mips_const_vector_same_int_p (src, GET_MODE (src), -512, 511))
4845 return false;
4847 return true;
4850 /* Split a 128-bit move from SRC to DEST. */
4852 void
4853 mips_split_128bit_move (rtx dest, rtx src)
4855 int byte, index;
4856 rtx low_dest, low_src, d, s;
4858 if (FP_REG_RTX_P (dest))
4860 gcc_assert (!MEM_P (src));
4862 rtx new_dest = dest;
4863 if (!TARGET_64BIT)
4865 if (GET_MODE (dest) != V4SImode)
4866 new_dest = simplify_gen_subreg (V4SImode, dest, GET_MODE (dest), 0);
4868 else
4870 if (GET_MODE (dest) != V2DImode)
4871 new_dest = simplify_gen_subreg (V2DImode, dest, GET_MODE (dest), 0);
4874 for (byte = 0, index = 0; byte < GET_MODE_SIZE (TImode);
4875 byte += UNITS_PER_WORD, index++)
4877 s = mips_subword_at_byte (src, byte);
4878 if (!TARGET_64BIT)
4879 emit_insn (gen_msa_insert_w (new_dest, new_dest, GEN_INT (index),
4880 s));
4881 else
4882 emit_insn (gen_msa_insert_d (new_dest, new_dest, GEN_INT (index),
4883 s));
4886 else if (FP_REG_RTX_P (src))
4888 gcc_assert (!MEM_P (dest));
4890 rtx new_src = src;
4891 if (!TARGET_64BIT)
4893 if (GET_MODE (src) != V4SImode)
4894 new_src = simplify_gen_subreg (V4SImode, src, GET_MODE (src), 0);
4896 else
4898 if (GET_MODE (src) != V2DImode)
4899 new_src = simplify_gen_subreg (V2DImode, src, GET_MODE (src), 0);
4902 for (byte = 0, index = 0; byte < GET_MODE_SIZE (TImode);
4903 byte += UNITS_PER_WORD, index++)
4905 d = mips_subword_at_byte (dest, byte);
4906 if (!TARGET_64BIT)
4907 emit_insn (gen_msa_copy_s_w (d, new_src, GEN_INT (index)));
4908 else
4909 emit_insn (gen_msa_copy_s_d (d, new_src, GEN_INT (index)));
4912 else
4914 low_dest = mips_subword_at_byte (dest, 0);
4915 low_src = mips_subword_at_byte (src, 0);
4916 gcc_assert (REG_P (low_dest) && REG_P (low_src));
4917 /* Make sure the source register is not written before reading. */
4918 if (REGNO (low_dest) <= REGNO (low_src))
4920 for (byte = 0; byte < GET_MODE_SIZE (TImode);
4921 byte += UNITS_PER_WORD)
4923 d = mips_subword_at_byte (dest, byte);
4924 s = mips_subword_at_byte (src, byte);
4925 mips_emit_move (d, s);
4928 else
4930 for (byte = GET_MODE_SIZE (TImode) - UNITS_PER_WORD; byte >= 0;
4931 byte -= UNITS_PER_WORD)
4933 d = mips_subword_at_byte (dest, byte);
4934 s = mips_subword_at_byte (src, byte);
4935 mips_emit_move (d, s);
4941 /* Split a COPY_S.D with operands DEST, SRC and INDEX. GEN is a function
4942 used to generate subregs. */
4944 void
4945 mips_split_msa_copy_d (rtx dest, rtx src, rtx index,
4946 rtx (*gen_fn)(rtx, rtx, rtx))
4948 gcc_assert ((GET_MODE (src) == V2DImode && GET_MODE (dest) == DImode)
4949 || (GET_MODE (src) == V2DFmode && GET_MODE (dest) == DFmode));
4951 /* Note that low is always from the lower index, and high is always
4952 from the higher index. */
4953 rtx low = mips_subword (dest, false);
4954 rtx high = mips_subword (dest, true);
4955 rtx new_src = simplify_gen_subreg (V4SImode, src, GET_MODE (src), 0);
4957 emit_insn (gen_fn (low, new_src, GEN_INT (INTVAL (index) * 2)));
4958 emit_insn (gen_fn (high, new_src, GEN_INT (INTVAL (index) * 2 + 1)));
4961 /* Split a INSERT.D with operand DEST, SRC1.INDEX and SRC2. */
4963 void
4964 mips_split_msa_insert_d (rtx dest, rtx src1, rtx index, rtx src2)
4966 int i;
4967 gcc_assert (GET_MODE (dest) == GET_MODE (src1));
4968 gcc_assert ((GET_MODE (dest) == V2DImode
4969 && (GET_MODE (src2) == DImode || src2 == const0_rtx))
4970 || (GET_MODE (dest) == V2DFmode && GET_MODE (src2) == DFmode));
4972 /* Note that low is always from the lower index, and high is always
4973 from the higher index. */
4974 rtx low = mips_subword (src2, false);
4975 rtx high = mips_subword (src2, true);
4976 rtx new_dest = simplify_gen_subreg (V4SImode, dest, GET_MODE (dest), 0);
4977 rtx new_src1 = simplify_gen_subreg (V4SImode, src1, GET_MODE (src1), 0);
4978 i = exact_log2 (INTVAL (index));
4979 gcc_assert (i != -1);
4981 emit_insn (gen_msa_insert_w (new_dest, new_src1,
4982 GEN_INT (i * 2), low));
4983 emit_insn (gen_msa_insert_w (new_dest, new_dest,
4984 GEN_INT (i * 2 + 1), high));
4987 /* Split fill.d. */
4989 void
4990 mips_split_msa_fill_d (rtx dest, rtx src)
4992 gcc_assert ((GET_MODE (dest) == V2DImode
4993 && (GET_MODE (src) == DImode || src == const0_rtx))
4994 || (GET_MODE (dest) == V2DFmode && GET_MODE (src) == DFmode));
4996 /* Note that low is always from the lower index, and high is always
4997 from the higher index. */
4998 rtx low, high;
4999 if (src == const0_rtx)
5001 low = src;
5002 high = src;
5004 else
5006 low = mips_subword (src, false);
5007 high = mips_subword (src, true);
5009 rtx new_dest = simplify_gen_subreg (V4SImode, dest, GET_MODE (dest), 0);
5010 emit_insn (gen_msa_fill_w (new_dest, low));
5011 emit_insn (gen_msa_insert_w (new_dest, new_dest, const1_rtx, high));
5012 emit_insn (gen_msa_insert_w (new_dest, new_dest, GEN_INT (3), high));
5015 /* Return true if a move from SRC to DEST in INSN should be split. */
5017 bool
5018 mips_split_move_insn_p (rtx dest, rtx src, rtx insn)
5020 return mips_split_move_p (dest, src, mips_insn_split_type (insn));
5023 /* Split a move from SRC to DEST in INSN, given that mips_split_move_insn_p
5024 holds. */
5026 void
5027 mips_split_move_insn (rtx dest, rtx src, rtx insn)
5029 mips_split_move (dest, src, mips_insn_split_type (insn));
5032 /* Return the appropriate instructions to move SRC into DEST. Assume
5033 that SRC is operand 1 and DEST is operand 0. */
5035 const char *
5036 mips_output_move (rtx dest, rtx src)
5038 enum rtx_code dest_code = GET_CODE (dest);
5039 enum rtx_code src_code = GET_CODE (src);
5040 machine_mode mode = GET_MODE (dest);
5041 bool dbl_p = (GET_MODE_SIZE (mode) == 8);
5042 bool msa_p = MSA_SUPPORTED_MODE_P (mode);
5043 enum mips_symbol_type symbol_type;
5045 if (mips_split_move_p (dest, src, SPLIT_IF_NECESSARY))
5046 return "#";
5048 if (msa_p
5049 && dest_code == REG && FP_REG_P (REGNO (dest))
5050 && src_code == CONST_VECTOR
5051 && CONST_INT_P (CONST_VECTOR_ELT (src, 0)))
5053 gcc_assert (const_yi_operand (src, mode));
5054 return "ldi.%v0\t%w0,%E1";
5057 if ((src_code == REG && GP_REG_P (REGNO (src)))
5058 || (!TARGET_MIPS16 && src == CONST0_RTX (mode)))
5060 if (dest_code == REG)
5062 if (GP_REG_P (REGNO (dest)))
5063 return "move\t%0,%z1";
5065 if (mips_mult_move_p (dest, src, SPLIT_IF_NECESSARY))
5067 if (ISA_HAS_DSP_MULT)
5068 return "mult\t%q0,%.,%.";
5069 else
5070 return "mult\t%.,%.";
5073 /* Moves to HI are handled by special .md insns. */
5074 if (REGNO (dest) == LO_REGNUM)
5076 if (ISA_HAS_MULT)
5077 return "mtlo\t%z1";
5078 else
5079 return "mtlo\t%z1,$ac0";
5082 if (DSP_ACC_REG_P (REGNO (dest)))
5084 static char retval[] = "mt__\t%z1,%q0";
5086 retval[2] = reg_names[REGNO (dest)][4];
5087 retval[3] = reg_names[REGNO (dest)][5];
5088 return retval;
5091 if (FP_REG_P (REGNO (dest)))
5093 if (msa_p)
5095 gcc_assert (src == CONST0_RTX (GET_MODE (src)));
5096 return "ldi.%v0\t%w0,0";
5099 return dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0";
5102 if (ALL_COP_REG_P (REGNO (dest)))
5104 static char retval[] = "dmtc_\t%z1,%0";
5106 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
5107 return dbl_p ? retval : retval + 1;
5110 if (dest_code == MEM)
5111 switch (GET_MODE_SIZE (mode))
5113 case 1: return "sb\t%z1,%0";
5114 case 2: return "sh\t%z1,%0";
5115 case 4: return "sw\t%z1,%0";
5116 case 8: return "sd\t%z1,%0";
5117 default: gcc_unreachable ();
5120 if (dest_code == REG && GP_REG_P (REGNO (dest)))
5122 if (src_code == REG)
5124 /* Moves from HI are handled by special .md insns. */
5125 if (REGNO (src) == LO_REGNUM)
5127 /* When generating VR4120 or VR4130 code, we use MACC and
5128 DMACC instead of MFLO. This avoids both the normal
5129 MIPS III HI/LO hazards and the errata related to
5130 -mfix-vr4130. */
5131 if (ISA_HAS_MACCHI)
5132 return dbl_p ? "dmacc\t%0,%.,%." : "macc\t%0,%.,%.";
5133 if (ISA_HAS_MULT)
5134 return "mflo\t%0";
5135 else
5136 return "mflo\t%0,$ac0";
5139 if (DSP_ACC_REG_P (REGNO (src)))
5141 static char retval[] = "mf__\t%0,%q1";
5143 retval[2] = reg_names[REGNO (src)][4];
5144 retval[3] = reg_names[REGNO (src)][5];
5145 return retval;
5148 if (FP_REG_P (REGNO (src)))
5150 gcc_assert (!msa_p);
5151 return dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1";
5154 if (ALL_COP_REG_P (REGNO (src)))
5156 static char retval[] = "dmfc_\t%0,%1";
5158 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
5159 return dbl_p ? retval : retval + 1;
5163 if (src_code == MEM)
5164 switch (GET_MODE_SIZE (mode))
5166 case 1: return "lbu\t%0,%1";
5167 case 2: return "lhu\t%0,%1";
5168 case 4: return "lw\t%0,%1";
5169 case 8: return "ld\t%0,%1";
5170 default: gcc_unreachable ();
5173 if (src_code == CONST_INT)
5175 /* Don't use the X format for the operand itself, because that
5176 will give out-of-range numbers for 64-bit hosts and 32-bit
5177 targets. */
5178 if (!TARGET_MIPS16)
5179 return "li\t%0,%1\t\t\t# %X1";
5181 if (SMALL_OPERAND_UNSIGNED (INTVAL (src)))
5182 return "li\t%0,%1";
5184 if (SMALL_OPERAND_UNSIGNED (-INTVAL (src)))
5185 return "#";
5188 if (src_code == HIGH)
5189 return TARGET_MIPS16 ? "#" : "lui\t%0,%h1";
5191 if (CONST_GP_P (src))
5192 return "move\t%0,%1";
5194 if (mips_symbolic_constant_p (src, SYMBOL_CONTEXT_LEA, &symbol_type)
5195 && mips_lo_relocs[symbol_type] != 0)
5197 /* A signed 16-bit constant formed by applying a relocation
5198 operator to a symbolic address. */
5199 gcc_assert (!mips_split_p[symbol_type]);
5200 return "li\t%0,%R1";
5203 if (symbolic_operand (src, VOIDmode))
5205 gcc_assert (TARGET_MIPS16
5206 ? TARGET_MIPS16_TEXT_LOADS
5207 : !TARGET_EXPLICIT_RELOCS);
5208 return dbl_p ? "dla\t%0,%1" : "la\t%0,%1";
5211 if (src_code == REG && FP_REG_P (REGNO (src)))
5213 if (dest_code == REG && FP_REG_P (REGNO (dest)))
5215 if (GET_MODE (dest) == V2SFmode)
5216 return "mov.ps\t%0,%1";
5217 else if (msa_p)
5218 return "move.v\t%w0,%w1";
5219 else
5220 return dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1";
5223 if (dest_code == MEM)
5225 if (msa_p)
5226 return "st.%v1\t%w1,%0";
5228 return dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0";
5231 if (dest_code == REG && FP_REG_P (REGNO (dest)))
5233 if (src_code == MEM)
5235 if (msa_p)
5236 return "ld.%v0\t%w0,%1";
5238 return dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1";
5241 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM)
5243 static char retval[] = "l_c_\t%0,%1";
5245 retval[1] = (dbl_p ? 'd' : 'w');
5246 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest));
5247 return retval;
5249 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src)))
5251 static char retval[] = "s_c_\t%1,%0";
5253 retval[1] = (dbl_p ? 'd' : 'w');
5254 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src));
5255 return retval;
5257 gcc_unreachable ();
5260 /* Return true if CMP1 is a suitable second operand for integer ordering
5261 test CODE. See also the *sCC patterns in mips.md. */
5263 static bool
5264 mips_int_order_operand_ok_p (enum rtx_code code, rtx cmp1)
5266 switch (code)
5268 case GT:
5269 case GTU:
5270 return reg_or_0_operand (cmp1, VOIDmode);
5272 case GE:
5273 case GEU:
5274 return !TARGET_MIPS16 && cmp1 == const1_rtx;
5276 case LT:
5277 case LTU:
5278 return arith_operand (cmp1, VOIDmode);
5280 case LE:
5281 return sle_operand (cmp1, VOIDmode);
5283 case LEU:
5284 return sleu_operand (cmp1, VOIDmode);
5286 default:
5287 gcc_unreachable ();
5291 /* Return true if *CMP1 (of mode MODE) is a valid second operand for
5292 integer ordering test *CODE, or if an equivalent combination can
5293 be formed by adjusting *CODE and *CMP1. When returning true, update
5294 *CODE and *CMP1 with the chosen code and operand, otherwise leave
5295 them alone. */
5297 static bool
5298 mips_canonicalize_int_order_test (enum rtx_code *code, rtx *cmp1,
5299 machine_mode mode)
5301 HOST_WIDE_INT plus_one;
5303 if (mips_int_order_operand_ok_p (*code, *cmp1))
5304 return true;
5306 if (CONST_INT_P (*cmp1))
5307 switch (*code)
5309 case LE:
5310 plus_one = trunc_int_for_mode (UINTVAL (*cmp1) + 1, mode);
5311 if (INTVAL (*cmp1) < plus_one)
5313 *code = LT;
5314 *cmp1 = force_reg (mode, GEN_INT (plus_one));
5315 return true;
5317 break;
5319 case LEU:
5320 plus_one = trunc_int_for_mode (UINTVAL (*cmp1) + 1, mode);
5321 if (plus_one != 0)
5323 *code = LTU;
5324 *cmp1 = force_reg (mode, GEN_INT (plus_one));
5325 return true;
5327 break;
5329 default:
5330 break;
5332 return false;
5335 /* Compare CMP0 and CMP1 using ordering test CODE and store the result
5336 in TARGET. CMP0 and TARGET are register_operands. If INVERT_PTR
5337 is nonnull, it's OK to set TARGET to the inverse of the result and
5338 flip *INVERT_PTR instead. */
5340 static void
5341 mips_emit_int_order_test (enum rtx_code code, bool *invert_ptr,
5342 rtx target, rtx cmp0, rtx cmp1)
5344 machine_mode mode;
5346 /* First see if there is a MIPS instruction that can do this operation.
5347 If not, try doing the same for the inverse operation. If that also
5348 fails, force CMP1 into a register and try again. */
5349 mode = GET_MODE (cmp0);
5350 if (mips_canonicalize_int_order_test (&code, &cmp1, mode))
5351 mips_emit_binary (code, target, cmp0, cmp1);
5352 else
5354 enum rtx_code inv_code = reverse_condition (code);
5355 if (!mips_canonicalize_int_order_test (&inv_code, &cmp1, mode))
5357 cmp1 = force_reg (mode, cmp1);
5358 mips_emit_int_order_test (code, invert_ptr, target, cmp0, cmp1);
5360 else if (invert_ptr == 0)
5362 rtx inv_target;
5364 inv_target = mips_force_binary (GET_MODE (target),
5365 inv_code, cmp0, cmp1);
5366 mips_emit_binary (XOR, target, inv_target, const1_rtx);
5368 else
5370 *invert_ptr = !*invert_ptr;
5371 mips_emit_binary (inv_code, target, cmp0, cmp1);
5376 /* Return a register that is zero iff CMP0 and CMP1 are equal.
5377 The register will have the same mode as CMP0. */
5379 static rtx
5380 mips_zero_if_equal (rtx cmp0, rtx cmp1)
5382 if (cmp1 == const0_rtx)
5383 return cmp0;
5385 if (uns_arith_operand (cmp1, VOIDmode))
5386 return expand_binop (GET_MODE (cmp0), xor_optab,
5387 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
5389 return expand_binop (GET_MODE (cmp0), sub_optab,
5390 cmp0, cmp1, 0, 0, OPTAB_DIRECT);
5393 /* Convert *CODE into a code that can be used in a floating-point
5394 scc instruction (C.cond.fmt). Return true if the values of
5395 the condition code registers will be inverted, with 0 indicating
5396 that the condition holds. */
5398 static bool
5399 mips_reversed_fp_cond (enum rtx_code *code)
5401 switch (*code)
5403 case NE:
5404 case LTGT:
5405 case ORDERED:
5406 *code = reverse_condition_maybe_unordered (*code);
5407 return true;
5409 default:
5410 return false;
5414 /* Allocate a floating-point condition-code register of mode MODE.
5416 These condition code registers are used for certain kinds
5417 of compound operation, such as compare and branches, vconds,
5418 and built-in functions. At expand time, their use is entirely
5419 controlled by MIPS-specific code and is entirely internal
5420 to these compound operations.
5422 We could (and did in the past) expose condition-code values
5423 as pseudo registers and leave the register allocator to pick
5424 appropriate registers. The problem is that it is not practically
5425 possible for the rtl optimizers to guarantee that no spills will
5426 be needed, even when AVOID_CCMODE_COPIES is defined. We would
5427 therefore need spill and reload sequences to handle the worst case.
5429 Although such sequences do exist, they are very expensive and are
5430 not something we'd want to use. This is especially true of CCV2 and
5431 CCV4, where all the shuffling would greatly outweigh whatever benefit
5432 the vectorization itself provides.
5434 The main benefit of having more than one condition-code register
5435 is to allow the pipelining of operations, especially those involving
5436 comparisons and conditional moves. We don't really expect the
5437 registers to be live for long periods, and certainly never want
5438 them to be live across calls.
5440 Also, there should be no penalty attached to using all the available
5441 registers. They are simply bits in the same underlying FPU control
5442 register.
5444 We therefore expose the hardware registers from the outset and use
5445 a simple round-robin allocation scheme. */
5447 static rtx
5448 mips_allocate_fcc (machine_mode mode)
5450 unsigned int regno, count;
5452 gcc_assert (TARGET_HARD_FLOAT && ISA_HAS_8CC);
5454 if (mode == CCmode)
5455 count = 1;
5456 else if (mode == CCV2mode)
5457 count = 2;
5458 else if (mode == CCV4mode)
5459 count = 4;
5460 else
5461 gcc_unreachable ();
5463 cfun->machine->next_fcc += -cfun->machine->next_fcc & (count - 1);
5464 if (cfun->machine->next_fcc > ST_REG_LAST - ST_REG_FIRST)
5465 cfun->machine->next_fcc = 0;
5466 regno = ST_REG_FIRST + cfun->machine->next_fcc;
5467 cfun->machine->next_fcc += count;
5468 return gen_rtx_REG (mode, regno);
5471 /* Convert a comparison into something that can be used in a branch or
5472 conditional move. On entry, *OP0 and *OP1 are the values being
5473 compared and *CODE is the code used to compare them.
5475 Update *CODE, *OP0 and *OP1 so that they describe the final comparison.
5476 If NEED_EQ_NE_P, then only EQ or NE comparisons against zero are possible,
5477 otherwise any standard branch condition can be used. The standard branch
5478 conditions are:
5480 - EQ or NE between two registers.
5481 - any comparison between a register and zero.
5482 - if mips R6 then any of the conditional branches are valid. */
5484 static void
5485 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p)
5487 rtx cmp_op0 = *op0;
5488 rtx cmp_op1 = *op1;
5490 if (GET_MODE_CLASS (GET_MODE (*op0)) == MODE_INT)
5492 if (!need_eq_ne_p && *op1 == const0_rtx)
5494 else if (*code == EQ || *code == NE)
5496 if (need_eq_ne_p)
5498 *op0 = mips_zero_if_equal (cmp_op0, cmp_op1);
5499 *op1 = const0_rtx;
5501 else
5502 *op1 = force_reg (GET_MODE (cmp_op0), cmp_op1);
5504 else if (!need_eq_ne_p && TARGET_CB_MAYBE)
5506 bool swap = false;
5507 switch (*code)
5509 case LE:
5510 swap = true;
5511 *code = GE;
5512 break;
5513 case GT:
5514 swap = true;
5515 *code = LT;
5516 break;
5517 case LEU:
5518 swap = true;
5519 *code = GEU;
5520 break;
5521 case GTU:
5522 swap = true;
5523 *code = LTU;
5524 break;
5525 case GE:
5526 case LT:
5527 case GEU:
5528 case LTU:
5529 /* Do nothing. */
5530 break;
5531 default:
5532 gcc_unreachable ();
5534 *op1 = force_reg (GET_MODE (cmp_op0), cmp_op1);
5535 if (swap)
5537 rtx tmp = *op1;
5538 *op1 = *op0;
5539 *op0 = tmp;
5542 else
5544 /* The comparison needs a separate scc instruction. Store the
5545 result of the scc in *OP0 and compare it against zero. */
5546 bool invert = false;
5547 *op0 = gen_reg_rtx (GET_MODE (cmp_op0));
5548 mips_emit_int_order_test (*code, &invert, *op0, cmp_op0, cmp_op1);
5549 *code = (invert ? EQ : NE);
5550 *op1 = const0_rtx;
5553 else if (ALL_FIXED_POINT_MODE_P (GET_MODE (cmp_op0)))
5555 *op0 = gen_rtx_REG (CCDSPmode, CCDSP_CC_REGNUM);
5556 mips_emit_binary (*code, *op0, cmp_op0, cmp_op1);
5557 *code = NE;
5558 *op1 = const0_rtx;
5560 else
5562 enum rtx_code cmp_code;
5564 /* Floating-point tests use a separate C.cond.fmt or CMP.cond.fmt
5565 comparison to set a register. The branch or conditional move will
5566 then compare that register against zero.
5568 Set CMP_CODE to the code of the comparison instruction and
5569 *CODE to the code that the branch or move should use. */
5570 cmp_code = *code;
5571 if (ISA_HAS_CCF)
5573 /* All FP conditions can be implemented directly with CMP.cond.fmt
5574 or by reversing the operands. */
5575 *code = NE;
5576 *op0 = gen_reg_rtx (CCFmode);
5578 else
5580 /* Three FP conditions cannot be implemented by reversing the
5581 operands for C.cond.fmt, instead a reversed condition code is
5582 required and a test for false. */
5583 *code = mips_reversed_fp_cond (&cmp_code) ? EQ : NE;
5584 if (ISA_HAS_8CC)
5585 *op0 = mips_allocate_fcc (CCmode);
5586 else
5587 *op0 = gen_rtx_REG (CCmode, FPSW_REGNUM);
5590 *op1 = const0_rtx;
5591 mips_emit_binary (cmp_code, *op0, cmp_op0, cmp_op1);
5595 /* Try performing the comparison in OPERANDS[1], whose arms are OPERANDS[2]
5596 and OPERAND[3]. Store the result in OPERANDS[0].
5598 On 64-bit targets, the mode of the comparison and target will always be
5599 SImode, thus possibly narrower than that of the comparison's operands. */
5601 void
5602 mips_expand_scc (rtx operands[])
5604 rtx target = operands[0];
5605 enum rtx_code code = GET_CODE (operands[1]);
5606 rtx op0 = operands[2];
5607 rtx op1 = operands[3];
5609 gcc_assert (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT);
5611 if (code == EQ || code == NE)
5613 if (ISA_HAS_SEQ_SNE
5614 && reg_imm10_operand (op1, GET_MODE (op1)))
5615 mips_emit_binary (code, target, op0, op1);
5616 else
5618 rtx zie = mips_zero_if_equal (op0, op1);
5619 mips_emit_binary (code, target, zie, const0_rtx);
5622 else
5623 mips_emit_int_order_test (code, 0, target, op0, op1);
5626 /* Compare OPERANDS[1] with OPERANDS[2] using comparison code
5627 CODE and jump to OPERANDS[3] if the condition holds. */
5629 void
5630 mips_expand_conditional_branch (rtx *operands)
5632 enum rtx_code code = GET_CODE (operands[0]);
5633 rtx op0 = operands[1];
5634 rtx op1 = operands[2];
5635 rtx condition;
5637 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16);
5638 condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
5639 emit_jump_insn (gen_condjump (condition, operands[3]));
5642 /* Generate RTL to test OPERAND[1]. The test is specified by GEN_FN,
5643 then sets OPERANDS[0] to 1 or 0 if the test is true/false respectively
5644 according to GEN_FN. */
5646 void
5647 mips_expand_msa_branch (rtx *operands, rtx (*gen_fn)(rtx, rtx, rtx))
5649 rtx labelT = gen_label_rtx ();
5650 rtx labelE = gen_label_rtx ();
5651 rtx tmp = gen_fn (labelT, operands[1], const0_rtx);
5653 tmp = emit_jump_insn (tmp);
5654 JUMP_LABEL (tmp) = labelT;
5655 emit_move_insn (operands[0], const0_rtx);
5656 tmp = emit_jump_insn (gen_jump (labelE));
5657 emit_barrier ();
5658 JUMP_LABEL (tmp) = labelE;
5659 emit_label (labelT);
5660 LABEL_NUSES (labelT) = 1;
5661 emit_move_insn (operands[0], const1_rtx);
5662 emit_label (labelE);
5663 LABEL_NUSES (labelE) = 1;
5666 /* Implement:
5668 (set temp (COND:CCV2 CMP_OP0 CMP_OP1))
5669 (set DEST (unspec [TRUE_SRC FALSE_SRC temp] UNSPEC_MOVE_TF_PS)) */
5671 void
5672 mips_expand_vcondv2sf (rtx dest, rtx true_src, rtx false_src,
5673 enum rtx_code cond, rtx cmp_op0, rtx cmp_op1)
5675 rtx cmp_result;
5676 bool reversed_p;
5678 reversed_p = mips_reversed_fp_cond (&cond);
5679 cmp_result = mips_allocate_fcc (CCV2mode);
5680 emit_insn (gen_scc_ps (cmp_result,
5681 gen_rtx_fmt_ee (cond, VOIDmode, cmp_op0, cmp_op1)));
5682 if (reversed_p)
5683 emit_insn (gen_mips_cond_move_tf_ps (dest, false_src, true_src,
5684 cmp_result));
5685 else
5686 emit_insn (gen_mips_cond_move_tf_ps (dest, true_src, false_src,
5687 cmp_result));
5690 /* Perform the comparison in OPERANDS[1]. Move OPERANDS[2] into OPERANDS[0]
5691 if the condition holds, otherwise move OPERANDS[3] into OPERANDS[0]. */
5693 void
5694 mips_expand_conditional_move (rtx *operands)
5696 rtx cond;
5697 enum rtx_code code = GET_CODE (operands[1]);
5698 rtx op0 = XEXP (operands[1], 0);
5699 rtx op1 = XEXP (operands[1], 1);
5701 mips_emit_compare (&code, &op0, &op1, true);
5702 cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);
5704 /* There is no direct support for general conditional GP move involving
5705 two registers using SEL. */
5706 if (ISA_HAS_SEL
5707 && INTEGRAL_MODE_P (GET_MODE (operands[2]))
5708 && register_operand (operands[2], VOIDmode)
5709 && register_operand (operands[3], VOIDmode))
5711 machine_mode mode = GET_MODE (operands[0]);
5712 rtx temp = gen_reg_rtx (mode);
5713 rtx temp2 = gen_reg_rtx (mode);
5715 emit_insn (gen_rtx_SET (VOIDmode, temp,
5716 gen_rtx_IF_THEN_ELSE (mode, cond,
5717 operands[2], const0_rtx)));
5719 /* Flip the test for the second operand. */
5720 cond = gen_rtx_fmt_ee ((code == EQ) ? NE : EQ, GET_MODE (op0), op0, op1);
5722 emit_insn (gen_rtx_SET (VOIDmode, temp2,
5723 gen_rtx_IF_THEN_ELSE (mode, cond,
5724 operands[3], const0_rtx)));
5726 /* Merge the two results, at least one is guaranteed to be zero. */
5727 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5728 gen_rtx_IOR (mode, temp, temp2)));
5730 else
5732 if (FLOAT_MODE_P (GET_MODE (operands[2])) && !ISA_HAS_SEL)
5734 operands[2] = force_reg (GET_MODE (operands[0]), operands[2]);
5735 operands[3] = force_reg (GET_MODE (operands[0]), operands[3]);
5738 emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5739 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]), cond,
5740 operands[2], operands[3])));
5744 /* Perform the comparison in COMPARISON, then trap if the condition holds. */
5746 void
5747 mips_expand_conditional_trap (rtx comparison)
5749 rtx op0, op1;
5750 machine_mode mode;
5751 enum rtx_code code;
5753 /* MIPS conditional trap instructions don't have GT or LE flavors,
5754 so we must swap the operands and convert to LT and GE respectively. */
5755 code = GET_CODE (comparison);
5756 switch (code)
5758 case GT:
5759 case LE:
5760 case GTU:
5761 case LEU:
5762 code = swap_condition (code);
5763 op0 = XEXP (comparison, 1);
5764 op1 = XEXP (comparison, 0);
5765 break;
5767 default:
5768 op0 = XEXP (comparison, 0);
5769 op1 = XEXP (comparison, 1);
5770 break;
5773 mode = GET_MODE (XEXP (comparison, 0));
5774 op0 = force_reg (mode, op0);
5775 if (!(ISA_HAS_COND_TRAPI
5776 ? arith_operand (op1, mode)
5777 : reg_or_0_operand (op1, mode)))
5778 op1 = force_reg (mode, op1);
5780 emit_insn (gen_rtx_TRAP_IF (VOIDmode,
5781 gen_rtx_fmt_ee (code, mode, op0, op1),
5782 const0_rtx));
5785 /* Initialize *CUM for a call to a function of type FNTYPE. */
5787 void
5788 mips_init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype)
5790 memset (cum, 0, sizeof (*cum));
5791 cum->prototype = (fntype && prototype_p (fntype));
5792 cum->gp_reg_found = (cum->prototype && stdarg_p (fntype));
5795 /* Fill INFO with information about a single argument. CUM is the
5796 cumulative state for earlier arguments. MODE is the mode of this
5797 argument and TYPE is its type (if known). NAMED is true if this
5798 is a named (fixed) argument rather than a variable one. */
5800 static void
5801 mips_get_arg_info (struct mips_arg_info *info, const CUMULATIVE_ARGS *cum,
5802 machine_mode mode, const_tree type, bool named)
5804 bool doubleword_aligned_p;
5805 unsigned int num_bytes, num_words, max_regs;
5807 /* Work out the size of the argument. */
5808 num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
5809 num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
5811 /* Decide whether it should go in a floating-point register, assuming
5812 one is free. Later code checks for availability.
5814 The checks against UNITS_PER_FPVALUE handle the soft-float and
5815 single-float cases. */
5816 switch (mips_abi)
5818 case ABI_EABI:
5819 /* The EABI conventions have traditionally been defined in terms
5820 of TYPE_MODE, regardless of the actual type. */
5821 info->fpr_p = ((GET_MODE_CLASS (mode) == MODE_FLOAT
5822 || mode == V2SFmode)
5823 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
5824 break;
5826 case ABI_32:
5827 case ABI_O64:
5828 /* Only leading floating-point scalars are passed in
5829 floating-point registers. We also handle vector floats the same
5830 say, which is OK because they are not covered by the standard ABI. */
5831 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode);
5832 info->fpr_p = (!cum->gp_reg_found
5833 && cum->arg_number < 2
5834 && (type == 0
5835 || SCALAR_FLOAT_TYPE_P (type)
5836 || VECTOR_FLOAT_TYPE_P (type))
5837 && (GET_MODE_CLASS (mode) == MODE_FLOAT
5838 || mode == V2SFmode)
5839 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE);
5840 break;
5842 case ABI_N32:
5843 case ABI_64:
5844 /* Scalar, complex and vector floating-point types are passed in
5845 floating-point registers, as long as this is a named rather
5846 than a variable argument. */
5847 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode);
5848 info->fpr_p = (named
5849 && (type == 0 || FLOAT_TYPE_P (type))
5850 && (GET_MODE_CLASS (mode) == MODE_FLOAT
5851 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5852 || mode == V2SFmode)
5853 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_FPVALUE);
5855 /* ??? According to the ABI documentation, the real and imaginary
5856 parts of complex floats should be passed in individual registers.
5857 The real and imaginary parts of stack arguments are supposed
5858 to be contiguous and there should be an extra word of padding
5859 at the end.
5861 This has two problems. First, it makes it impossible to use a
5862 single "void *" va_list type, since register and stack arguments
5863 are passed differently. (At the time of writing, MIPSpro cannot
5864 handle complex float varargs correctly.) Second, it's unclear
5865 what should happen when there is only one register free.
5867 For now, we assume that named complex floats should go into FPRs
5868 if there are two FPRs free, otherwise they should be passed in the
5869 same way as a struct containing two floats. */
5870 if (info->fpr_p
5871 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5872 && GET_MODE_UNIT_SIZE (mode) < UNITS_PER_FPVALUE)
5874 if (cum->num_gprs >= MAX_ARGS_IN_REGISTERS - 1)
5875 info->fpr_p = false;
5876 else
5877 num_words = 2;
5879 break;
5881 default:
5882 gcc_unreachable ();
5885 /* See whether the argument has doubleword alignment. */
5886 doubleword_aligned_p = (mips_function_arg_boundary (mode, type)
5887 > BITS_PER_WORD);
5889 /* Set REG_OFFSET to the register count we're interested in.
5890 The EABI allocates the floating-point registers separately,
5891 but the other ABIs allocate them like integer registers. */
5892 info->reg_offset = (mips_abi == ABI_EABI && info->fpr_p
5893 ? cum->num_fprs
5894 : cum->num_gprs);
5896 /* Advance to an even register if the argument is doubleword-aligned. */
5897 if (doubleword_aligned_p)
5898 info->reg_offset += info->reg_offset & 1;
5900 /* Work out the offset of a stack argument. */
5901 info->stack_offset = cum->stack_words;
5902 if (doubleword_aligned_p)
5903 info->stack_offset += info->stack_offset & 1;
5905 max_regs = MAX_ARGS_IN_REGISTERS - info->reg_offset;
5907 /* Partition the argument between registers and stack. */
5908 info->reg_words = MIN (num_words, max_regs);
5909 info->stack_words = num_words - info->reg_words;
5912 /* INFO describes a register argument that has the normal format for the
5913 argument's mode. Return the register it uses, assuming that FPRs are
5914 available if HARD_FLOAT_P. */
5916 static unsigned int
5917 mips_arg_regno (const struct mips_arg_info *info, bool hard_float_p)
5919 if (!info->fpr_p || !hard_float_p)
5920 return GP_ARG_FIRST + info->reg_offset;
5921 else if (mips_abi == ABI_32 && TARGET_DOUBLE_FLOAT && info->reg_offset > 0)
5922 /* In o32, the second argument is always passed in $f14
5923 for TARGET_DOUBLE_FLOAT, regardless of whether the
5924 first argument was a word or doubleword. */
5925 return FP_ARG_FIRST + 2;
5926 else
5927 return FP_ARG_FIRST + info->reg_offset;
5930 /* Implement TARGET_STRICT_ARGUMENT_NAMING. */
5932 static bool
5933 mips_strict_argument_naming (cumulative_args_t ca ATTRIBUTE_UNUSED)
5935 return !TARGET_OLDABI;
5938 /* Implement TARGET_FUNCTION_ARG. */
5940 static rtx
5941 mips_function_arg (cumulative_args_t cum_v, machine_mode mode,
5942 const_tree type, bool named)
5944 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
5945 struct mips_arg_info info;
5947 /* We will be called with a mode of VOIDmode after the last argument
5948 has been seen. Whatever we return will be passed to the call expander.
5949 If we need a MIPS16 fp_code, return a REG with the code stored as
5950 the mode. */
5951 if (mode == VOIDmode)
5953 if (TARGET_MIPS16 && cum->fp_code != 0)
5954 return gen_rtx_REG ((machine_mode) cum->fp_code, 0);
5955 else
5956 return NULL;
5959 mips_get_arg_info (&info, cum, mode, type, named);
5961 /* Return straight away if the whole argument is passed on the stack. */
5962 if (info.reg_offset == MAX_ARGS_IN_REGISTERS)
5963 return NULL;
5965 /* The n32 and n64 ABIs say that if any 64-bit chunk of the structure
5966 contains a double in its entirety, then that 64-bit chunk is passed
5967 in a floating-point register. */
5968 if (TARGET_NEWABI
5969 && TARGET_HARD_FLOAT
5970 && named
5971 && type != 0
5972 && TREE_CODE (type) == RECORD_TYPE
5973 && TYPE_SIZE_UNIT (type)
5974 && tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)))
5976 tree field;
5978 /* First check to see if there is any such field. */
5979 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
5980 if (TREE_CODE (field) == FIELD_DECL
5981 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (field))
5982 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD
5983 && tree_fits_shwi_p (bit_position (field))
5984 && int_bit_position (field) % BITS_PER_WORD == 0)
5985 break;
5987 if (field != 0)
5989 /* Now handle the special case by returning a PARALLEL
5990 indicating where each 64-bit chunk goes. INFO.REG_WORDS
5991 chunks are passed in registers. */
5992 unsigned int i;
5993 HOST_WIDE_INT bitpos;
5994 rtx ret;
5996 /* assign_parms checks the mode of ENTRY_PARM, so we must
5997 use the actual mode here. */
5998 ret = gen_rtx_PARALLEL (mode, rtvec_alloc (info.reg_words));
6000 bitpos = 0;
6001 field = TYPE_FIELDS (type);
6002 for (i = 0; i < info.reg_words; i++)
6004 rtx reg;
6006 for (; field; field = DECL_CHAIN (field))
6007 if (TREE_CODE (field) == FIELD_DECL
6008 && int_bit_position (field) >= bitpos)
6009 break;
6011 if (field
6012 && int_bit_position (field) == bitpos
6013 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (field))
6014 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD)
6015 reg = gen_rtx_REG (DFmode, FP_ARG_FIRST + info.reg_offset + i);
6016 else
6017 reg = gen_rtx_REG (DImode, GP_ARG_FIRST + info.reg_offset + i);
6019 XVECEXP (ret, 0, i)
6020 = gen_rtx_EXPR_LIST (VOIDmode, reg,
6021 GEN_INT (bitpos / BITS_PER_UNIT));
6023 bitpos += BITS_PER_WORD;
6025 return ret;
6029 /* Handle the n32/n64 conventions for passing complex floating-point
6030 arguments in FPR pairs. The real part goes in the lower register
6031 and the imaginary part goes in the upper register. */
6032 if (TARGET_NEWABI
6033 && info.fpr_p
6034 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
6036 rtx real, imag;
6037 machine_mode inner;
6038 unsigned int regno;
6040 inner = GET_MODE_INNER (mode);
6041 regno = FP_ARG_FIRST + info.reg_offset;
6042 if (info.reg_words * UNITS_PER_WORD == GET_MODE_SIZE (inner))
6044 /* Real part in registers, imaginary part on stack. */
6045 gcc_assert (info.stack_words == info.reg_words);
6046 return gen_rtx_REG (inner, regno);
6048 else
6050 gcc_assert (info.stack_words == 0);
6051 real = gen_rtx_EXPR_LIST (VOIDmode,
6052 gen_rtx_REG (inner, regno),
6053 const0_rtx);
6054 imag = gen_rtx_EXPR_LIST (VOIDmode,
6055 gen_rtx_REG (inner,
6056 regno + info.reg_words / 2),
6057 GEN_INT (GET_MODE_SIZE (inner)));
6058 return gen_rtx_PARALLEL (mode, gen_rtvec (2, real, imag));
6062 return gen_rtx_REG (mode, mips_arg_regno (&info, TARGET_HARD_FLOAT));
6065 /* Implement TARGET_FUNCTION_ARG_ADVANCE. */
6067 static void
6068 mips_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
6069 const_tree type, bool named)
6071 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
6072 struct mips_arg_info info;
6074 mips_get_arg_info (&info, cum, mode, type, named);
6076 if (!info.fpr_p)
6077 cum->gp_reg_found = true;
6079 /* See the comment above the CUMULATIVE_ARGS structure in mips.h for
6080 an explanation of what this code does. It assumes that we're using
6081 either the o32 or the o64 ABI, both of which pass at most 2 arguments
6082 in FPRs. */
6083 if (cum->arg_number < 2 && info.fpr_p)
6084 cum->fp_code += (mode == SFmode ? 1 : 2) << (cum->arg_number * 2);
6086 /* Advance the register count. This has the effect of setting
6087 num_gprs to MAX_ARGS_IN_REGISTERS if a doubleword-aligned
6088 argument required us to skip the final GPR and pass the whole
6089 argument on the stack. */
6090 if (mips_abi != ABI_EABI || !info.fpr_p)
6091 cum->num_gprs = info.reg_offset + info.reg_words;
6092 else if (info.reg_words > 0)
6093 cum->num_fprs += MAX_FPRS_PER_FMT;
6095 /* Advance the stack word count. */
6096 if (info.stack_words > 0)
6097 cum->stack_words = info.stack_offset + info.stack_words;
6099 cum->arg_number++;
6102 /* Implement TARGET_ARG_PARTIAL_BYTES. */
6104 static int
6105 mips_arg_partial_bytes (cumulative_args_t cum,
6106 machine_mode mode, tree type, bool named)
6108 struct mips_arg_info info;
6110 mips_get_arg_info (&info, get_cumulative_args (cum), mode, type, named);
6111 return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0;
6114 /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at
6115 least PARM_BOUNDARY bits of alignment, but will be given anything up
6116 to STACK_BOUNDARY bits if the type requires it. */
6118 static unsigned int
6119 mips_function_arg_boundary (machine_mode mode, const_tree type)
6121 unsigned int alignment;
6123 alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode);
6124 if (alignment < PARM_BOUNDARY)
6125 alignment = PARM_BOUNDARY;
6126 if (alignment > STACK_BOUNDARY)
6127 alignment = STACK_BOUNDARY;
6128 return alignment;
6131 /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */
6133 static machine_mode
6134 mips_get_reg_raw_mode (int regno)
6136 if (TARGET_FLOATXX && FP_REG_P (regno))
6137 return DFmode;
6138 return default_get_reg_raw_mode (regno);
6141 /* Return true if FUNCTION_ARG_PADDING (MODE, TYPE) should return
6142 upward rather than downward. In other words, return true if the
6143 first byte of the stack slot has useful data, false if the last
6144 byte does. */
6146 bool
6147 mips_pad_arg_upward (machine_mode mode, const_tree type)
6149 /* On little-endian targets, the first byte of every stack argument
6150 is passed in the first byte of the stack slot. */
6151 if (!BYTES_BIG_ENDIAN)
6152 return true;
6154 /* Otherwise, integral types are padded downward: the last byte of a
6155 stack argument is passed in the last byte of the stack slot. */
6156 if (type != 0
6157 ? (INTEGRAL_TYPE_P (type)
6158 || POINTER_TYPE_P (type)
6159 || FIXED_POINT_TYPE_P (type))
6160 : (SCALAR_INT_MODE_P (mode)
6161 || ALL_SCALAR_FIXED_POINT_MODE_P (mode)))
6162 return false;
6164 /* Big-endian o64 pads floating-point arguments downward. */
6165 if (mips_abi == ABI_O64)
6166 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
6167 return false;
6169 /* Other types are padded upward for o32, o64, n32 and n64. */
6170 if (mips_abi != ABI_EABI)
6171 return true;
6173 /* Arguments smaller than a stack slot are padded downward. */
6174 if (mode != BLKmode)
6175 return GET_MODE_BITSIZE (mode) >= PARM_BOUNDARY;
6176 else
6177 return int_size_in_bytes (type) >= (PARM_BOUNDARY / BITS_PER_UNIT);
6180 /* Likewise BLOCK_REG_PADDING (MODE, TYPE, ...). Return !BYTES_BIG_ENDIAN
6181 if the least significant byte of the register has useful data. Return
6182 the opposite if the most significant byte does. */
6184 bool
6185 mips_pad_reg_upward (machine_mode mode, tree type)
6187 /* No shifting is required for floating-point arguments. */
6188 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT)
6189 return !BYTES_BIG_ENDIAN;
6191 /* Otherwise, apply the same padding to register arguments as we do
6192 to stack arguments. */
6193 return mips_pad_arg_upward (mode, type);
6196 /* Return nonzero when an argument must be passed by reference. */
6198 static bool
6199 mips_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
6200 machine_mode mode, const_tree type,
6201 bool named ATTRIBUTE_UNUSED)
6203 if (mips_abi == ABI_EABI)
6205 int size;
6207 /* ??? How should SCmode be handled? */
6208 if (mode == DImode || mode == DFmode
6209 || mode == DQmode || mode == UDQmode
6210 || mode == DAmode || mode == UDAmode)
6211 return 0;
6213 size = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
6214 return size == -1 || size > UNITS_PER_WORD;
6216 else
6218 /* If we have a variable-sized parameter, we have no choice. */
6219 return targetm.calls.must_pass_in_stack (mode, type);
6223 /* Implement TARGET_CALLEE_COPIES. */
6225 static bool
6226 mips_callee_copies (cumulative_args_t cum ATTRIBUTE_UNUSED,
6227 machine_mode mode ATTRIBUTE_UNUSED,
6228 const_tree type ATTRIBUTE_UNUSED, bool named)
6230 return mips_abi == ABI_EABI && named;
6233 /* See whether VALTYPE is a record whose fields should be returned in
6234 floating-point registers. If so, return the number of fields and
6235 list them in FIELDS (which should have two elements). Return 0
6236 otherwise.
6238 For n32 & n64, a structure with one or two fields is returned in
6239 floating-point registers as long as every field has a floating-point
6240 type. */
6242 static int
6243 mips_fpr_return_fields (const_tree valtype, tree *fields)
6245 tree field;
6246 int i;
6248 if (!TARGET_NEWABI)
6249 return 0;
6251 if (TREE_CODE (valtype) != RECORD_TYPE)
6252 return 0;
6254 i = 0;
6255 for (field = TYPE_FIELDS (valtype); field != 0; field = DECL_CHAIN (field))
6257 if (TREE_CODE (field) != FIELD_DECL)
6258 continue;
6260 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (field)))
6261 return 0;
6263 if (i == 2)
6264 return 0;
6266 fields[i++] = field;
6268 return i;
6271 /* Implement TARGET_RETURN_IN_MSB. For n32 & n64, we should return
6272 a value in the most significant part of $2/$3 if:
6274 - the target is big-endian;
6276 - the value has a structure or union type (we generalize this to
6277 cover aggregates from other languages too); and
6279 - the structure is not returned in floating-point registers. */
6281 static bool
6282 mips_return_in_msb (const_tree valtype)
6284 tree fields[2];
6286 return (TARGET_NEWABI
6287 && TARGET_BIG_ENDIAN
6288 && AGGREGATE_TYPE_P (valtype)
6289 && mips_fpr_return_fields (valtype, fields) == 0);
6292 /* Return true if the function return value MODE will get returned in a
6293 floating-point register. */
6295 static bool
6296 mips_return_mode_in_fpr_p (machine_mode mode)
6298 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode);
6299 return ((GET_MODE_CLASS (mode) == MODE_FLOAT
6300 || mode == V2SFmode
6301 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
6302 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_HWFPVALUE);
6305 /* Return the representation of an FPR return register when the
6306 value being returned in FP_RETURN has mode VALUE_MODE and the
6307 return type itself has mode TYPE_MODE. On NewABI targets,
6308 the two modes may be different for structures like:
6310 struct __attribute__((packed)) foo { float f; }
6312 where we return the SFmode value of "f" in FP_RETURN, but where
6313 the structure itself has mode BLKmode. */
6315 static rtx
6316 mips_return_fpr_single (machine_mode type_mode,
6317 machine_mode value_mode)
6319 rtx x;
6321 x = gen_rtx_REG (value_mode, FP_RETURN);
6322 if (type_mode != value_mode)
6324 x = gen_rtx_EXPR_LIST (VOIDmode, x, const0_rtx);
6325 x = gen_rtx_PARALLEL (type_mode, gen_rtvec (1, x));
6327 return x;
6330 /* Return a composite value in a pair of floating-point registers.
6331 MODE1 and OFFSET1 are the mode and byte offset for the first value,
6332 likewise MODE2 and OFFSET2 for the second. MODE is the mode of the
6333 complete value.
6335 For n32 & n64, $f0 always holds the first value and $f2 the second.
6336 Otherwise the values are packed together as closely as possible. */
6338 static rtx
6339 mips_return_fpr_pair (machine_mode mode,
6340 machine_mode mode1, HOST_WIDE_INT offset1,
6341 machine_mode mode2, HOST_WIDE_INT offset2)
6343 int inc;
6345 inc = (TARGET_NEWABI || mips_abi == ABI_32 ? 2 : MAX_FPRS_PER_FMT);
6346 return gen_rtx_PARALLEL
6347 (mode,
6348 gen_rtvec (2,
6349 gen_rtx_EXPR_LIST (VOIDmode,
6350 gen_rtx_REG (mode1, FP_RETURN),
6351 GEN_INT (offset1)),
6352 gen_rtx_EXPR_LIST (VOIDmode,
6353 gen_rtx_REG (mode2, FP_RETURN + inc),
6354 GEN_INT (offset2))));
6358 /* Implement TARGET_FUNCTION_VALUE and TARGET_LIBCALL_VALUE.
6359 For normal calls, VALTYPE is the return type and MODE is VOIDmode.
6360 For libcalls, VALTYPE is null and MODE is the mode of the return value. */
6362 static rtx
6363 mips_function_value_1 (const_tree valtype, const_tree fn_decl_or_type,
6364 machine_mode mode)
6366 if (valtype)
6368 tree fields[2];
6369 int unsigned_p;
6370 const_tree func;
6372 if (fn_decl_or_type && DECL_P (fn_decl_or_type))
6373 func = fn_decl_or_type;
6374 else
6375 func = NULL;
6377 mode = TYPE_MODE (valtype);
6378 unsigned_p = TYPE_UNSIGNED (valtype);
6380 /* Since TARGET_PROMOTE_FUNCTION_MODE unconditionally promotes,
6381 return values, promote the mode here too. */
6382 mode = promote_function_mode (valtype, mode, &unsigned_p, func, 1);
6384 /* Handle structures whose fields are returned in $f0/$f2. */
6385 switch (mips_fpr_return_fields (valtype, fields))
6387 case 1:
6388 return mips_return_fpr_single (mode,
6389 TYPE_MODE (TREE_TYPE (fields[0])));
6391 case 2:
6392 return mips_return_fpr_pair (mode,
6393 TYPE_MODE (TREE_TYPE (fields[0])),
6394 int_byte_position (fields[0]),
6395 TYPE_MODE (TREE_TYPE (fields[1])),
6396 int_byte_position (fields[1]));
6399 /* If a value is passed in the most significant part of a register, see
6400 whether we have to round the mode up to a whole number of words. */
6401 if (mips_return_in_msb (valtype))
6403 HOST_WIDE_INT size = int_size_in_bytes (valtype);
6404 if (size % UNITS_PER_WORD != 0)
6406 size += UNITS_PER_WORD - size % UNITS_PER_WORD;
6407 mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
6411 /* For EABI, the class of return register depends entirely on MODE.
6412 For example, "struct { some_type x; }" and "union { some_type x; }"
6413 are returned in the same way as a bare "some_type" would be.
6414 Other ABIs only use FPRs for scalar, complex or vector types. */
6415 if (mips_abi != ABI_EABI && !FLOAT_TYPE_P (valtype))
6416 return gen_rtx_REG (mode, GP_RETURN);
6419 if (!TARGET_MIPS16)
6421 /* Handle long doubles for n32 & n64. */
6422 if (mode == TFmode)
6423 return mips_return_fpr_pair (mode,
6424 DImode, 0,
6425 DImode, GET_MODE_SIZE (mode) / 2);
6427 if (mips_return_mode_in_fpr_p (mode))
6429 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
6430 return mips_return_fpr_pair (mode,
6431 GET_MODE_INNER (mode), 0,
6432 GET_MODE_INNER (mode),
6433 GET_MODE_SIZE (mode) / 2);
6434 else
6435 return gen_rtx_REG (mode, FP_RETURN);
6439 return gen_rtx_REG (mode, GP_RETURN);
6442 /* Implement TARGET_FUNCTION_VALUE. */
6444 static rtx
6445 mips_function_value (const_tree valtype, const_tree fn_decl_or_type,
6446 bool outgoing ATTRIBUTE_UNUSED)
6448 return mips_function_value_1 (valtype, fn_decl_or_type, VOIDmode);
6451 /* Implement TARGET_LIBCALL_VALUE. */
6453 static rtx
6454 mips_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED)
6456 return mips_function_value_1 (NULL_TREE, NULL_TREE, mode);
6459 /* Implement TARGET_FUNCTION_VALUE_REGNO_P.
6461 On the MIPS, R2 R3 and F0 F2 are the only register thus used. */
6463 static bool
6464 mips_function_value_regno_p (const unsigned int regno)
6466 /* Most types only require one GPR or one FPR for return values but for
6467 hard-float two FPRs can be used for _Complex types (for all ABIs)
6468 and long doubles (for n64). */
6469 if (regno == GP_RETURN
6470 || regno == FP_RETURN
6471 || (FP_RETURN != GP_RETURN
6472 && regno == FP_RETURN + 2))
6473 return true;
6475 /* For o32 FP32, _Complex double will be returned in four 32-bit registers.
6476 This does not apply to o32 FPXX as floating-point function argument and
6477 return registers are described as 64-bit even though floating-point
6478 registers are primarily described as 32-bit internally.
6479 See: mips_get_reg_raw_mode. */
6480 if ((mips_abi == ABI_32 && TARGET_FLOAT32)
6481 && FP_RETURN != GP_RETURN
6482 && (regno == FP_RETURN + 1
6483 || regno == FP_RETURN + 3))
6484 return true;
6486 return false;
6489 /* Implement TARGET_RETURN_IN_MEMORY. Under the o32 and o64 ABIs,
6490 all BLKmode objects are returned in memory. Under the n32, n64
6491 and embedded ABIs, small structures are returned in a register.
6492 Objects with varying size must still be returned in memory, of
6493 course. */
6495 static bool
6496 mips_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED)
6498 return (TARGET_OLDABI
6499 ? TYPE_MODE (type) == BLKmode
6500 : !IN_RANGE (int_size_in_bytes (type), 0, 2 * UNITS_PER_WORD));
6503 /* Implement TARGET_SETUP_INCOMING_VARARGS. */
6505 static void
6506 mips_setup_incoming_varargs (cumulative_args_t cum, machine_mode mode,
6507 tree type, int *pretend_size ATTRIBUTE_UNUSED,
6508 int no_rtl)
6510 CUMULATIVE_ARGS local_cum;
6511 int gp_saved, fp_saved;
6513 /* The caller has advanced CUM up to, but not beyond, the last named
6514 argument. Advance a local copy of CUM past the last "real" named
6515 argument, to find out how many registers are left over. */
6516 local_cum = *get_cumulative_args (cum);
6517 mips_function_arg_advance (pack_cumulative_args (&local_cum), mode, type,
6518 true);
6520 /* Found out how many registers we need to save. */
6521 gp_saved = MAX_ARGS_IN_REGISTERS - local_cum.num_gprs;
6522 fp_saved = (EABI_FLOAT_VARARGS_P
6523 ? MAX_ARGS_IN_REGISTERS - local_cum.num_fprs
6524 : 0);
6526 if (!no_rtl)
6528 if (gp_saved > 0)
6530 rtx ptr, mem;
6532 ptr = plus_constant (Pmode, virtual_incoming_args_rtx,
6533 REG_PARM_STACK_SPACE (cfun->decl)
6534 - gp_saved * UNITS_PER_WORD);
6535 mem = gen_frame_mem (BLKmode, ptr);
6536 set_mem_alias_set (mem, get_varargs_alias_set ());
6538 move_block_from_reg (local_cum.num_gprs + GP_ARG_FIRST,
6539 mem, gp_saved);
6541 if (fp_saved > 0)
6543 /* We can't use move_block_from_reg, because it will use
6544 the wrong mode. */
6545 machine_mode mode;
6546 int off, i;
6548 /* Set OFF to the offset from virtual_incoming_args_rtx of
6549 the first float register. The FP save area lies below
6550 the integer one, and is aligned to UNITS_PER_FPVALUE bytes. */
6551 off = (-gp_saved * UNITS_PER_WORD) & -UNITS_PER_FPVALUE;
6552 off -= fp_saved * UNITS_PER_FPREG;
6554 mode = TARGET_SINGLE_FLOAT ? SFmode : DFmode;
6556 for (i = local_cum.num_fprs; i < MAX_ARGS_IN_REGISTERS;
6557 i += MAX_FPRS_PER_FMT)
6559 rtx ptr, mem;
6561 ptr = plus_constant (Pmode, virtual_incoming_args_rtx, off);
6562 mem = gen_frame_mem (mode, ptr);
6563 set_mem_alias_set (mem, get_varargs_alias_set ());
6564 mips_emit_move (mem, gen_rtx_REG (mode, FP_ARG_FIRST + i));
6565 off += UNITS_PER_HWFPVALUE;
6569 if (REG_PARM_STACK_SPACE (cfun->decl) == 0)
6570 cfun->machine->varargs_size = (gp_saved * UNITS_PER_WORD
6571 + fp_saved * UNITS_PER_FPREG);
6574 /* Implement TARGET_BUILTIN_VA_LIST. */
6576 static tree
6577 mips_build_builtin_va_list (void)
6579 if (EABI_FLOAT_VARARGS_P)
6581 /* We keep 3 pointers, and two offsets.
6583 Two pointers are to the overflow area, which starts at the CFA.
6584 One of these is constant, for addressing into the GPR save area
6585 below it. The other is advanced up the stack through the
6586 overflow region.
6588 The third pointer is to the bottom of the GPR save area.
6589 Since the FPR save area is just below it, we can address
6590 FPR slots off this pointer.
6592 We also keep two one-byte offsets, which are to be subtracted
6593 from the constant pointers to yield addresses in the GPR and
6594 FPR save areas. These are downcounted as float or non-float
6595 arguments are used, and when they get to zero, the argument
6596 must be obtained from the overflow region. */
6597 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff, f_res, record;
6598 tree array, index;
6600 record = lang_hooks.types.make_type (RECORD_TYPE);
6602 f_ovfl = build_decl (BUILTINS_LOCATION,
6603 FIELD_DECL, get_identifier ("__overflow_argptr"),
6604 ptr_type_node);
6605 f_gtop = build_decl (BUILTINS_LOCATION,
6606 FIELD_DECL, get_identifier ("__gpr_top"),
6607 ptr_type_node);
6608 f_ftop = build_decl (BUILTINS_LOCATION,
6609 FIELD_DECL, get_identifier ("__fpr_top"),
6610 ptr_type_node);
6611 f_goff = build_decl (BUILTINS_LOCATION,
6612 FIELD_DECL, get_identifier ("__gpr_offset"),
6613 unsigned_char_type_node);
6614 f_foff = build_decl (BUILTINS_LOCATION,
6615 FIELD_DECL, get_identifier ("__fpr_offset"),
6616 unsigned_char_type_node);
6617 /* Explicitly pad to the size of a pointer, so that -Wpadded won't
6618 warn on every user file. */
6619 index = build_int_cst (NULL_TREE, GET_MODE_SIZE (ptr_mode) - 2 - 1);
6620 array = build_array_type (unsigned_char_type_node,
6621 build_index_type (index));
6622 f_res = build_decl (BUILTINS_LOCATION,
6623 FIELD_DECL, get_identifier ("__reserved"), array);
6625 DECL_FIELD_CONTEXT (f_ovfl) = record;
6626 DECL_FIELD_CONTEXT (f_gtop) = record;
6627 DECL_FIELD_CONTEXT (f_ftop) = record;
6628 DECL_FIELD_CONTEXT (f_goff) = record;
6629 DECL_FIELD_CONTEXT (f_foff) = record;
6630 DECL_FIELD_CONTEXT (f_res) = record;
6632 TYPE_FIELDS (record) = f_ovfl;
6633 DECL_CHAIN (f_ovfl) = f_gtop;
6634 DECL_CHAIN (f_gtop) = f_ftop;
6635 DECL_CHAIN (f_ftop) = f_goff;
6636 DECL_CHAIN (f_goff) = f_foff;
6637 DECL_CHAIN (f_foff) = f_res;
6639 layout_type (record);
6640 return record;
6642 else
6643 /* Otherwise, we use 'void *'. */
6644 return ptr_type_node;
6647 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */
6649 static void
6650 mips_va_start (tree valist, rtx nextarg)
6652 if (EABI_FLOAT_VARARGS_P)
6654 const CUMULATIVE_ARGS *cum;
6655 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff;
6656 tree ovfl, gtop, ftop, goff, foff;
6657 tree t;
6658 int gpr_save_area_size;
6659 int fpr_save_area_size;
6660 int fpr_offset;
6662 cum = &crtl->args.info;
6663 gpr_save_area_size
6664 = (MAX_ARGS_IN_REGISTERS - cum->num_gprs) * UNITS_PER_WORD;
6665 fpr_save_area_size
6666 = (MAX_ARGS_IN_REGISTERS - cum->num_fprs) * UNITS_PER_FPREG;
6668 f_ovfl = TYPE_FIELDS (va_list_type_node);
6669 f_gtop = DECL_CHAIN (f_ovfl);
6670 f_ftop = DECL_CHAIN (f_gtop);
6671 f_goff = DECL_CHAIN (f_ftop);
6672 f_foff = DECL_CHAIN (f_goff);
6674 ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl,
6675 NULL_TREE);
6676 gtop = build3 (COMPONENT_REF, TREE_TYPE (f_gtop), valist, f_gtop,
6677 NULL_TREE);
6678 ftop = build3 (COMPONENT_REF, TREE_TYPE (f_ftop), valist, f_ftop,
6679 NULL_TREE);
6680 goff = build3 (COMPONENT_REF, TREE_TYPE (f_goff), valist, f_goff,
6681 NULL_TREE);
6682 foff = build3 (COMPONENT_REF, TREE_TYPE (f_foff), valist, f_foff,
6683 NULL_TREE);
6685 /* Emit code to initialize OVFL, which points to the next varargs
6686 stack argument. CUM->STACK_WORDS gives the number of stack
6687 words used by named arguments. */
6688 t = make_tree (TREE_TYPE (ovfl), virtual_incoming_args_rtx);
6689 if (cum->stack_words > 0)
6690 t = fold_build_pointer_plus_hwi (t, cum->stack_words * UNITS_PER_WORD);
6691 t = build2 (MODIFY_EXPR, TREE_TYPE (ovfl), ovfl, t);
6692 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6694 /* Emit code to initialize GTOP, the top of the GPR save area. */
6695 t = make_tree (TREE_TYPE (gtop), virtual_incoming_args_rtx);
6696 t = build2 (MODIFY_EXPR, TREE_TYPE (gtop), gtop, t);
6697 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6699 /* Emit code to initialize FTOP, the top of the FPR save area.
6700 This address is gpr_save_area_bytes below GTOP, rounded
6701 down to the next fp-aligned boundary. */
6702 t = make_tree (TREE_TYPE (ftop), virtual_incoming_args_rtx);
6703 fpr_offset = gpr_save_area_size + UNITS_PER_FPVALUE - 1;
6704 fpr_offset &= -UNITS_PER_FPVALUE;
6705 if (fpr_offset)
6706 t = fold_build_pointer_plus_hwi (t, -fpr_offset);
6707 t = build2 (MODIFY_EXPR, TREE_TYPE (ftop), ftop, t);
6708 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6710 /* Emit code to initialize GOFF, the offset from GTOP of the
6711 next GPR argument. */
6712 t = build2 (MODIFY_EXPR, TREE_TYPE (goff), goff,
6713 build_int_cst (TREE_TYPE (goff), gpr_save_area_size));
6714 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6716 /* Likewise emit code to initialize FOFF, the offset from FTOP
6717 of the next FPR argument. */
6718 t = build2 (MODIFY_EXPR, TREE_TYPE (foff), foff,
6719 build_int_cst (TREE_TYPE (foff), fpr_save_area_size));
6720 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6722 else
6724 nextarg = plus_constant (Pmode, nextarg, -cfun->machine->varargs_size);
6725 std_expand_builtin_va_start (valist, nextarg);
6729 /* Like std_gimplify_va_arg_expr, but apply alignment to zero-sized
6730 types as well. */
6732 static tree
6733 mips_std_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
6734 gimple_seq *post_p)
6736 tree addr, t, type_size, rounded_size, valist_tmp;
6737 unsigned HOST_WIDE_INT align, boundary;
6738 bool indirect;
6740 indirect = pass_by_reference (NULL, TYPE_MODE (type), type, false);
6741 if (indirect)
6742 type = build_pointer_type (type);
6744 align = PARM_BOUNDARY / BITS_PER_UNIT;
6745 boundary = targetm.calls.function_arg_boundary (TYPE_MODE (type), type);
6747 /* When we align parameter on stack for caller, if the parameter
6748 alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
6749 aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee
6750 here with caller. */
6751 if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
6752 boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
6754 boundary /= BITS_PER_UNIT;
6756 /* Hoist the valist value into a temporary for the moment. */
6757 valist_tmp = get_initialized_tmp_var (valist, pre_p, NULL);
6759 /* va_list pointer is aligned to PARM_BOUNDARY. If argument actually
6760 requires greater alignment, we must perform dynamic alignment. */
6761 if (boundary > align)
6763 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
6764 fold_build_pointer_plus_hwi (valist_tmp, boundary - 1));
6765 gimplify_and_add (t, pre_p);
6767 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
6768 fold_build2 (BIT_AND_EXPR, TREE_TYPE (valist),
6769 valist_tmp,
6770 build_int_cst (TREE_TYPE (valist), -boundary)));
6771 gimplify_and_add (t, pre_p);
6773 else
6774 boundary = align;
6776 /* If the actual alignment is less than the alignment of the type,
6777 adjust the type accordingly so that we don't assume strict alignment
6778 when dereferencing the pointer. */
6779 boundary *= BITS_PER_UNIT;
6780 if (boundary < TYPE_ALIGN (type))
6782 type = build_variant_type_copy (type);
6783 TYPE_ALIGN (type) = boundary;
6786 /* Compute the rounded size of the type. */
6787 type_size = size_in_bytes (type);
6788 rounded_size = round_up (type_size, align);
6790 /* Reduce rounded_size so it's sharable with the postqueue. */
6791 gimplify_expr (&rounded_size, pre_p, post_p, is_gimple_val, fb_rvalue);
6793 /* Get AP. */
6794 addr = valist_tmp;
6795 if (PAD_VARARGS_DOWN && !integer_zerop (rounded_size))
6797 /* Small args are padded downward. */
6798 t = fold_build2_loc (input_location, GT_EXPR, sizetype,
6799 rounded_size, size_int (align));
6800 t = fold_build3 (COND_EXPR, sizetype, t, size_zero_node,
6801 size_binop (MINUS_EXPR, rounded_size, type_size));
6802 addr = fold_build_pointer_plus (addr, t);
6805 /* Compute new value for AP. */
6806 t = fold_build_pointer_plus (valist_tmp, rounded_size);
6807 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist, t);
6808 gimplify_and_add (t, pre_p);
6810 addr = fold_convert (build_pointer_type (type), addr);
6812 if (indirect)
6813 addr = build_va_arg_indirect_ref (addr);
6815 return build_va_arg_indirect_ref (addr);
6818 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */
6820 static tree
6821 mips_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
6822 gimple_seq *post_p)
6824 tree addr;
6825 bool indirect_p;
6827 indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, 0);
6828 if (indirect_p)
6829 type = build_pointer_type (type);
6831 if (!EABI_FLOAT_VARARGS_P)
6832 addr = mips_std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6833 else
6835 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff;
6836 tree ovfl, top, off, align;
6837 HOST_WIDE_INT size, rsize, osize;
6838 tree t, u;
6840 f_ovfl = TYPE_FIELDS (va_list_type_node);
6841 f_gtop = DECL_CHAIN (f_ovfl);
6842 f_ftop = DECL_CHAIN (f_gtop);
6843 f_goff = DECL_CHAIN (f_ftop);
6844 f_foff = DECL_CHAIN (f_goff);
6846 /* Let:
6848 TOP be the top of the GPR or FPR save area;
6849 OFF be the offset from TOP of the next register;
6850 ADDR_RTX be the address of the argument;
6851 SIZE be the number of bytes in the argument type;
6852 RSIZE be the number of bytes used to store the argument
6853 when it's in the register save area; and
6854 OSIZE be the number of bytes used to store it when it's
6855 in the stack overflow area.
6857 The code we want is:
6859 1: off &= -rsize; // round down
6860 2: if (off != 0)
6861 3: {
6862 4: addr_rtx = top - off + (BYTES_BIG_ENDIAN ? RSIZE - SIZE : 0);
6863 5: off -= rsize;
6864 6: }
6865 7: else
6866 8: {
6867 9: ovfl = ((intptr_t) ovfl + osize - 1) & -osize;
6868 10: addr_rtx = ovfl + (BYTES_BIG_ENDIAN ? OSIZE - SIZE : 0);
6869 11: ovfl += osize;
6870 14: }
6872 [1] and [9] can sometimes be optimized away. */
6874 ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl,
6875 NULL_TREE);
6876 size = int_size_in_bytes (type);
6878 if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT
6879 && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FPVALUE)
6881 top = build3 (COMPONENT_REF, TREE_TYPE (f_ftop),
6882 unshare_expr (valist), f_ftop, NULL_TREE);
6883 off = build3 (COMPONENT_REF, TREE_TYPE (f_foff),
6884 unshare_expr (valist), f_foff, NULL_TREE);
6886 /* When va_start saves FPR arguments to the stack, each slot
6887 takes up UNITS_PER_HWFPVALUE bytes, regardless of the
6888 argument's precision. */
6889 rsize = UNITS_PER_HWFPVALUE;
6891 /* Overflow arguments are padded to UNITS_PER_WORD bytes
6892 (= PARM_BOUNDARY bits). This can be different from RSIZE
6893 in two cases:
6895 (1) On 32-bit targets when TYPE is a structure such as:
6897 struct s { float f; };
6899 Such structures are passed in paired FPRs, so RSIZE
6900 will be 8 bytes. However, the structure only takes
6901 up 4 bytes of memory, so OSIZE will only be 4.
6903 (2) In combinations such as -mgp64 -msingle-float
6904 -fshort-double. Doubles passed in registers will then take
6905 up 4 (UNITS_PER_HWFPVALUE) bytes, but those passed on the
6906 stack take up UNITS_PER_WORD bytes. */
6907 osize = MAX (GET_MODE_SIZE (TYPE_MODE (type)), UNITS_PER_WORD);
6909 else
6911 top = build3 (COMPONENT_REF, TREE_TYPE (f_gtop),
6912 unshare_expr (valist), f_gtop, NULL_TREE);
6913 off = build3 (COMPONENT_REF, TREE_TYPE (f_goff),
6914 unshare_expr (valist), f_goff, NULL_TREE);
6915 rsize = (size + UNITS_PER_WORD - 1) & -UNITS_PER_WORD;
6916 if (rsize > UNITS_PER_WORD)
6918 /* [1] Emit code for: off &= -rsize. */
6919 t = build2 (BIT_AND_EXPR, TREE_TYPE (off), unshare_expr (off),
6920 build_int_cst (TREE_TYPE (off), -rsize));
6921 gimplify_assign (unshare_expr (off), t, pre_p);
6923 osize = rsize;
6926 /* [2] Emit code to branch if off == 0. */
6927 t = build2 (NE_EXPR, boolean_type_node, unshare_expr (off),
6928 build_int_cst (TREE_TYPE (off), 0));
6929 addr = build3 (COND_EXPR, ptr_type_node, t, NULL_TREE, NULL_TREE);
6931 /* [5] Emit code for: off -= rsize. We do this as a form of
6932 post-decrement not available to C. */
6933 t = fold_convert (TREE_TYPE (off), build_int_cst (NULL_TREE, rsize));
6934 t = build2 (POSTDECREMENT_EXPR, TREE_TYPE (off), off, t);
6936 /* [4] Emit code for:
6937 addr_rtx = top - off + (BYTES_BIG_ENDIAN ? RSIZE - SIZE : 0). */
6938 t = fold_convert (sizetype, t);
6939 t = fold_build1 (NEGATE_EXPR, sizetype, t);
6940 t = fold_build_pointer_plus (top, t);
6941 if (BYTES_BIG_ENDIAN && rsize > size)
6942 t = fold_build_pointer_plus_hwi (t, rsize - size);
6943 COND_EXPR_THEN (addr) = t;
6945 if (osize > UNITS_PER_WORD)
6947 /* [9] Emit: ovfl = ((intptr_t) ovfl + osize - 1) & -osize. */
6948 t = fold_build_pointer_plus_hwi (unshare_expr (ovfl), osize - 1);
6949 u = build_int_cst (TREE_TYPE (t), -osize);
6950 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, u);
6951 align = build2 (MODIFY_EXPR, TREE_TYPE (ovfl),
6952 unshare_expr (ovfl), t);
6954 else
6955 align = NULL;
6957 /* [10, 11] Emit code for:
6958 addr_rtx = ovfl + (BYTES_BIG_ENDIAN ? OSIZE - SIZE : 0)
6959 ovfl += osize. */
6960 u = fold_convert (TREE_TYPE (ovfl), build_int_cst (NULL_TREE, osize));
6961 t = build2 (POSTINCREMENT_EXPR, TREE_TYPE (ovfl), ovfl, u);
6962 if (BYTES_BIG_ENDIAN && osize > size)
6963 t = fold_build_pointer_plus_hwi (t, osize - size);
6965 /* String [9] and [10, 11] together. */
6966 if (align)
6967 t = build2 (COMPOUND_EXPR, TREE_TYPE (t), align, t);
6968 COND_EXPR_ELSE (addr) = t;
6970 addr = fold_convert (build_pointer_type (type), addr);
6971 addr = build_va_arg_indirect_ref (addr);
6974 if (indirect_p)
6975 addr = build_va_arg_indirect_ref (addr);
6977 return addr;
6980 /* Declare a unique, locally-binding function called NAME, then start
6981 its definition. */
6983 static void
6984 mips_start_unique_function (const char *name)
6986 tree decl;
6988 decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
6989 get_identifier (name),
6990 build_function_type_list (void_type_node, NULL_TREE));
6991 DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
6992 NULL_TREE, void_type_node);
6993 TREE_PUBLIC (decl) = 1;
6994 TREE_STATIC (decl) = 1;
6996 DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl);
6998 targetm.asm_out.unique_section (decl, 0);
6999 switch_to_section (get_named_section (decl, NULL, 0));
7001 targetm.asm_out.globalize_label (asm_out_file, name);
7002 fputs ("\t.hidden\t", asm_out_file);
7003 assemble_name (asm_out_file, name);
7004 putc ('\n', asm_out_file);
7007 /* Start a definition of function NAME. MIPS16_P indicates whether the
7008 function contains MIPS16 code. */
7010 static void
7011 mips_start_function_definition (const char *name, bool mips16_p)
7013 if (mips16_p)
7014 fprintf (asm_out_file, "\t.set\tmips16\n");
7015 else
7016 fprintf (asm_out_file, "\t.set\tnomips16\n");
7018 if (TARGET_MICROMIPS)
7019 fprintf (asm_out_file, "\t.set\tmicromips\n");
7020 #ifdef HAVE_GAS_MICROMIPS
7021 else
7022 fprintf (asm_out_file, "\t.set\tnomicromips\n");
7023 #endif
7025 if (!flag_inhibit_size_directive)
7027 fputs ("\t.ent\t", asm_out_file);
7028 assemble_name (asm_out_file, name);
7029 fputs ("\n", asm_out_file);
7032 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, name, "function");
7034 /* Start the definition proper. */
7035 assemble_name (asm_out_file, name);
7036 fputs (":\n", asm_out_file);
7039 /* End a function definition started by mips_start_function_definition. */
7041 static void
7042 mips_end_function_definition (const char *name)
7044 if (!flag_inhibit_size_directive)
7046 fputs ("\t.end\t", asm_out_file);
7047 assemble_name (asm_out_file, name);
7048 fputs ("\n", asm_out_file);
7052 /* If *STUB_PTR points to a stub, output a comdat-style definition for it,
7053 then free *STUB_PTR. */
7055 static void
7056 mips_finish_stub (mips_one_only_stub **stub_ptr)
7058 mips_one_only_stub *stub = *stub_ptr;
7059 if (!stub)
7060 return;
7062 const char *name = stub->get_name ();
7063 mips_start_unique_function (name);
7064 mips_start_function_definition (name, false);
7065 stub->output_body ();
7066 mips_end_function_definition (name);
7067 delete stub;
7068 *stub_ptr = 0;
7071 /* Return true if calls to X can use R_MIPS_CALL* relocations. */
7073 static bool
7074 mips_ok_for_lazy_binding_p (rtx x)
7076 return (TARGET_USE_GOT
7077 && GET_CODE (x) == SYMBOL_REF
7078 && !SYMBOL_REF_BIND_NOW_P (x)
7079 && !mips_symbol_binds_local_p (x));
7082 /* Load function address ADDR into register DEST. TYPE is as for
7083 mips_expand_call. Return true if we used an explicit lazy-binding
7084 sequence. */
7086 static bool
7087 mips_load_call_address (enum mips_call_type type, rtx dest, rtx addr)
7089 /* If we're generating PIC, and this call is to a global function,
7090 try to allow its address to be resolved lazily. This isn't
7091 possible for sibcalls when $gp is call-saved because the value
7092 of $gp on entry to the stub would be our caller's gp, not ours. */
7093 if (TARGET_EXPLICIT_RELOCS
7094 && !(type == MIPS_CALL_SIBCALL && TARGET_CALL_SAVED_GP)
7095 && mips_ok_for_lazy_binding_p (addr))
7097 addr = mips_got_load (dest, addr, SYMBOL_GOTOFF_CALL);
7098 emit_insn (gen_rtx_SET (VOIDmode, dest, addr));
7099 return true;
7101 else
7103 mips_emit_move (dest, addr);
7104 return false;
7108 /* Each locally-defined hard-float MIPS16 function has a local symbol
7109 associated with it. This hash table maps the function symbol (FUNC)
7110 to the local symbol (LOCAL). */
7111 struct GTY(()) mips16_local_alias {
7112 rtx func;
7113 rtx local;
7115 static GTY ((param_is (struct mips16_local_alias))) htab_t mips16_local_aliases;
7117 /* Hash table callbacks for mips16_local_aliases. */
7119 static hashval_t
7120 mips16_local_aliases_hash (const void *entry)
7122 const struct mips16_local_alias *alias;
7124 alias = (const struct mips16_local_alias *) entry;
7125 return htab_hash_string (XSTR (alias->func, 0));
7128 static int
7129 mips16_local_aliases_eq (const void *entry1, const void *entry2)
7131 const struct mips16_local_alias *alias1, *alias2;
7133 alias1 = (const struct mips16_local_alias *) entry1;
7134 alias2 = (const struct mips16_local_alias *) entry2;
7135 return rtx_equal_p (alias1->func, alias2->func);
7138 /* FUNC is the symbol for a locally-defined hard-float MIPS16 function.
7139 Return a local alias for it, creating a new one if necessary. */
7141 static rtx
7142 mips16_local_alias (rtx func)
7144 struct mips16_local_alias *alias, tmp_alias;
7145 void **slot;
7147 /* Create the hash table if this is the first call. */
7148 if (mips16_local_aliases == NULL)
7149 mips16_local_aliases = htab_create_ggc (37, mips16_local_aliases_hash,
7150 mips16_local_aliases_eq, NULL);
7152 /* Look up the function symbol, creating a new entry if need be. */
7153 tmp_alias.func = func;
7154 slot = htab_find_slot (mips16_local_aliases, &tmp_alias, INSERT);
7155 gcc_assert (slot != NULL);
7157 alias = (struct mips16_local_alias *) *slot;
7158 if (alias == NULL)
7160 const char *func_name, *local_name;
7161 rtx local;
7163 /* Create a new SYMBOL_REF for the local symbol. The choice of
7164 __fn_local_* is based on the __fn_stub_* names that we've
7165 traditionally used for the non-MIPS16 stub. */
7166 func_name = targetm.strip_name_encoding (XSTR (func, 0));
7167 local_name = ACONCAT (("__fn_local_", func_name, NULL));
7168 local = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (local_name));
7169 SYMBOL_REF_FLAGS (local) = SYMBOL_REF_FLAGS (func) | SYMBOL_FLAG_LOCAL;
7171 /* Create a new structure to represent the mapping. */
7172 alias = ggc_alloc_mips16_local_alias ();
7173 alias->func = func;
7174 alias->local = local;
7175 *slot = alias;
7177 return alias->local;
7180 /* A chained list of functions for which mips16_build_call_stub has already
7181 generated a stub. NAME is the name of the function and FP_RET_P is true
7182 if the function returns a value in floating-point registers. */
7183 struct mips16_stub {
7184 struct mips16_stub *next;
7185 char *name;
7186 bool fp_ret_p;
7188 static struct mips16_stub *mips16_stubs;
7190 /* Return the two-character string that identifies floating-point
7191 return mode MODE in the name of a MIPS16 function stub. */
7193 static const char *
7194 mips16_call_stub_mode_suffix (machine_mode mode)
7196 if (mode == SFmode)
7197 return "sf";
7198 else if (mode == DFmode)
7199 return "df";
7200 else if (mode == SCmode)
7201 return "sc";
7202 else if (mode == DCmode)
7203 return "dc";
7204 else if (mode == V2SFmode)
7206 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT);
7207 return "df";
7209 else
7210 gcc_unreachable ();
7213 /* Write instructions to move a 32-bit value between general register
7214 GPREG and floating-point register FPREG. DIRECTION is 't' to move
7215 from GPREG to FPREG and 'f' to move in the opposite direction. */
7217 static void
7218 mips_output_32bit_xfer (char direction, unsigned int gpreg, unsigned int fpreg)
7220 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
7221 reg_names[gpreg], reg_names[fpreg]);
7224 /* Likewise for 64-bit values. */
7226 static void
7227 mips_output_64bit_xfer (char direction, unsigned int gpreg, unsigned int fpreg)
7229 if (TARGET_64BIT)
7230 fprintf (asm_out_file, "\tdm%cc1\t%s,%s\n", direction,
7231 reg_names[gpreg], reg_names[fpreg]);
7232 else if (ISA_HAS_MXHC1)
7234 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
7235 reg_names[gpreg + TARGET_BIG_ENDIAN], reg_names[fpreg]);
7236 fprintf (asm_out_file, "\tm%chc1\t%s,%s\n", direction,
7237 reg_names[gpreg + TARGET_LITTLE_ENDIAN], reg_names[fpreg]);
7239 else if (TARGET_FLOATXX && direction == 't')
7241 /* Use the argument save area to move via memory. */
7242 fprintf (asm_out_file, "\tsw\t%s,0($sp)\n", reg_names[gpreg]);
7243 fprintf (asm_out_file, "\tsw\t%s,4($sp)\n", reg_names[gpreg + 1]);
7244 fprintf (asm_out_file, "\tldc1\t%s,0($sp)\n", reg_names[fpreg]);
7246 else if (TARGET_FLOATXX && direction == 'f')
7248 /* Use the argument save area to move via memory. */
7249 fprintf (asm_out_file, "\tsdc1\t%s,0($sp)\n", reg_names[fpreg]);
7250 fprintf (asm_out_file, "\tlw\t%s,0($sp)\n", reg_names[gpreg]);
7251 fprintf (asm_out_file, "\tlw\t%s,4($sp)\n", reg_names[gpreg + 1]);
7253 else
7255 /* Move the least-significant word. */
7256 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
7257 reg_names[gpreg + TARGET_BIG_ENDIAN], reg_names[fpreg]);
7258 /* ...then the most significant word. */
7259 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction,
7260 reg_names[gpreg + TARGET_LITTLE_ENDIAN], reg_names[fpreg + 1]);
7264 /* Write out code to move floating-point arguments into or out of
7265 general registers. FP_CODE is the code describing which arguments
7266 are present (see the comment above the definition of CUMULATIVE_ARGS
7267 in mips.h). DIRECTION is as for mips_output_32bit_xfer. */
7269 static void
7270 mips_output_args_xfer (int fp_code, char direction)
7272 unsigned int gparg, fparg, f;
7273 CUMULATIVE_ARGS cum;
7275 /* This code only works for o32 and o64. */
7276 gcc_assert (TARGET_OLDABI);
7278 mips_init_cumulative_args (&cum, NULL);
7280 for (f = (unsigned int) fp_code; f != 0; f >>= 2)
7282 machine_mode mode;
7283 struct mips_arg_info info;
7285 if ((f & 3) == 1)
7286 mode = SFmode;
7287 else if ((f & 3) == 2)
7288 mode = DFmode;
7289 else
7290 gcc_unreachable ();
7292 mips_get_arg_info (&info, &cum, mode, NULL, true);
7293 gparg = mips_arg_regno (&info, false);
7294 fparg = mips_arg_regno (&info, true);
7296 if (mode == SFmode)
7297 mips_output_32bit_xfer (direction, gparg, fparg);
7298 else
7299 mips_output_64bit_xfer (direction, gparg, fparg);
7301 mips_function_arg_advance (pack_cumulative_args (&cum), mode, NULL, true);
7305 /* Write a MIPS16 stub for the current function. This stub is used
7306 for functions which take arguments in the floating-point registers.
7307 It is normal-mode code that moves the floating-point arguments
7308 into the general registers and then jumps to the MIPS16 code. */
7310 static void
7311 mips16_build_function_stub (void)
7313 const char *fnname, *alias_name, *separator;
7314 char *secname, *stubname;
7315 tree stubdecl;
7316 unsigned int f;
7317 rtx symbol, alias;
7319 /* Create the name of the stub, and its unique section. */
7320 symbol = XEXP (DECL_RTL (current_function_decl), 0);
7321 alias = mips16_local_alias (symbol);
7323 fnname = targetm.strip_name_encoding (XSTR (symbol, 0));
7324 alias_name = targetm.strip_name_encoding (XSTR (alias, 0));
7325 secname = ACONCAT ((".mips16.fn.", fnname, NULL));
7326 stubname = ACONCAT (("__fn_stub_", fnname, NULL));
7328 /* Build a decl for the stub. */
7329 stubdecl = build_decl (BUILTINS_LOCATION,
7330 FUNCTION_DECL, get_identifier (stubname),
7331 build_function_type_list (void_type_node, NULL_TREE));
7332 DECL_SECTION_NAME (stubdecl) = build_string (strlen (secname), secname);
7333 DECL_RESULT (stubdecl) = build_decl (BUILTINS_LOCATION,
7334 RESULT_DECL, NULL_TREE, void_type_node);
7336 /* Output a comment. */
7337 fprintf (asm_out_file, "\t# Stub function for %s (",
7338 current_function_name ());
7339 separator = "";
7340 for (f = (unsigned int) crtl->args.info.fp_code; f != 0; f >>= 2)
7342 fprintf (asm_out_file, "%s%s", separator,
7343 (f & 3) == 1 ? "float" : "double");
7344 separator = ", ";
7346 fprintf (asm_out_file, ")\n");
7348 /* Start the function definition. */
7349 assemble_start_function (stubdecl, stubname);
7350 mips_start_function_definition (stubname, false);
7352 /* If generating pic2 code, either set up the global pointer or
7353 switch to pic0. */
7354 if (TARGET_ABICALLS_PIC2)
7356 if (TARGET_ABSOLUTE_ABICALLS)
7357 fprintf (asm_out_file, "\t.option\tpic0\n");
7358 else
7360 output_asm_insn ("%(.cpload\t%^%)", NULL);
7361 /* Emit an R_MIPS_NONE relocation to tell the linker what the
7362 target function is. Use a local GOT access when loading the
7363 symbol, to cut down on the number of unnecessary GOT entries
7364 for stubs that aren't needed. */
7365 output_asm_insn (".reloc\t0,R_MIPS_NONE,%0", &symbol);
7366 symbol = alias;
7370 /* Load the address of the MIPS16 function into $25. Do this first so
7371 that targets with coprocessor interlocks can use an MFC1 to fill the
7372 delay slot. */
7373 output_asm_insn ("la\t%^,%0", &symbol);
7375 /* Move the arguments from floating-point registers to general registers. */
7376 mips_output_args_xfer (crtl->args.info.fp_code, 'f');
7378 /* Jump to the MIPS16 function. */
7379 output_asm_insn ("jr\t%^", NULL);
7381 if (TARGET_ABICALLS_PIC2 && TARGET_ABSOLUTE_ABICALLS)
7382 fprintf (asm_out_file, "\t.option\tpic2\n");
7384 mips_end_function_definition (stubname);
7386 /* If the linker needs to create a dynamic symbol for the target
7387 function, it will associate the symbol with the stub (which,
7388 unlike the target function, follows the proper calling conventions).
7389 It is therefore useful to have a local alias for the target function,
7390 so that it can still be identified as MIPS16 code. As an optimization,
7391 this symbol can also be used for indirect MIPS16 references from
7392 within this file. */
7393 ASM_OUTPUT_DEF (asm_out_file, alias_name, fnname);
7395 switch_to_section (function_section (current_function_decl));
7398 /* The current function is a MIPS16 function that returns a value in an FPR.
7399 Copy the return value from its soft-float to its hard-float location.
7400 libgcc2 has special non-MIPS16 helper functions for each case. */
7402 static void
7403 mips16_copy_fpr_return_value (void)
7405 rtx fn, insn, retval;
7406 tree return_type;
7407 machine_mode return_mode;
7408 const char *name;
7410 return_type = DECL_RESULT (current_function_decl);
7411 return_mode = DECL_MODE (return_type);
7413 name = ACONCAT (("__mips16_ret_",
7414 mips16_call_stub_mode_suffix (return_mode),
7415 NULL));
7416 fn = mips16_stub_function (name);
7418 /* The function takes arguments in $2 (and possibly $3), so calls
7419 to it cannot be lazily bound. */
7420 SYMBOL_REF_FLAGS (fn) |= SYMBOL_FLAG_BIND_NOW;
7422 /* Model the call as something that takes the GPR return value as
7423 argument and returns an "updated" value. */
7424 retval = gen_rtx_REG (return_mode, GP_RETURN);
7425 insn = mips_expand_call (MIPS_CALL_EPILOGUE, retval, fn,
7426 const0_rtx, NULL_RTX, false);
7427 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), retval);
7430 /* Consider building a stub for a MIPS16 call to function *FN_PTR.
7431 RETVAL is the location of the return value, or null if this is
7432 a "call" rather than a "call_value". ARGS_SIZE is the size of the
7433 arguments and FP_CODE is the code built by mips_function_arg;
7434 see the comment before the fp_code field in CUMULATIVE_ARGS for details.
7436 There are three alternatives:
7438 - If a stub was needed, emit the call and return the call insn itself.
7440 - If we can avoid using a stub by redirecting the call, set *FN_PTR
7441 to the new target and return null.
7443 - If *FN_PTR doesn't need a stub, return null and leave *FN_PTR
7444 unmodified.
7446 A stub is needed for calls to functions that, in normal mode,
7447 receive arguments in FPRs or return values in FPRs. The stub
7448 copies the arguments from their soft-float positions to their
7449 hard-float positions, calls the real function, then copies the
7450 return value from its hard-float position to its soft-float
7451 position.
7453 We can emit a JAL to *FN_PTR even when *FN_PTR might need a stub.
7454 If *FN_PTR turns out to be to a non-MIPS16 function, the linker
7455 automatically redirects the JAL to the stub, otherwise the JAL
7456 continues to call FN directly. */
7458 static rtx
7459 mips16_build_call_stub (rtx retval, rtx *fn_ptr, rtx args_size, int fp_code)
7461 const char *fnname;
7462 bool fp_ret_p;
7463 struct mips16_stub *l;
7464 rtx insn, fn;
7466 /* We don't need to do anything if we aren't in MIPS16 mode, or if
7467 we were invoked with the -msoft-float option. */
7468 if (!TARGET_MIPS16 || TARGET_SOFT_FLOAT_ABI)
7469 return NULL_RTX;
7471 /* Figure out whether the value might come back in a floating-point
7472 register. */
7473 fp_ret_p = retval && mips_return_mode_in_fpr_p (GET_MODE (retval));
7475 /* We don't need to do anything if there were no floating-point
7476 arguments and the value will not be returned in a floating-point
7477 register. */
7478 if (fp_code == 0 && !fp_ret_p)
7479 return NULL_RTX;
7481 /* We don't need to do anything if this is a call to a special
7482 MIPS16 support function. */
7483 fn = *fn_ptr;
7484 if (mips16_stub_function_p (fn))
7485 return NULL_RTX;
7487 /* If we're calling a locally-defined MIPS16 function, we know that
7488 it will return values in both the "soft-float" and "hard-float"
7489 registers. There is no need to use a stub to move the latter
7490 to the former. */
7491 if (fp_code == 0 && mips16_local_function_p (fn))
7492 return NULL_RTX;
7494 /* This code will only work for o32 and o64 abis. The other ABI's
7495 require more sophisticated support. */
7496 gcc_assert (TARGET_OLDABI);
7498 /* If we're calling via a function pointer, use one of the magic
7499 libgcc.a stubs provided for each (FP_CODE, FP_RET_P) combination.
7500 Each stub expects the function address to arrive in register $2. */
7501 if (GET_CODE (fn) != SYMBOL_REF
7502 || !call_insn_operand (fn, VOIDmode))
7504 char buf[30];
7505 rtx stub_fn, insn, addr;
7506 bool lazy_p;
7508 /* If this is a locally-defined and locally-binding function,
7509 avoid the stub by calling the local alias directly. */
7510 if (mips16_local_function_p (fn))
7512 *fn_ptr = mips16_local_alias (fn);
7513 return NULL_RTX;
7516 /* Create a SYMBOL_REF for the libgcc.a function. */
7517 if (fp_ret_p)
7518 sprintf (buf, "__mips16_call_stub_%s_%d",
7519 mips16_call_stub_mode_suffix (GET_MODE (retval)),
7520 fp_code);
7521 else
7522 sprintf (buf, "__mips16_call_stub_%d", fp_code);
7523 stub_fn = mips16_stub_function (buf);
7525 /* The function uses $2 as an argument, so calls to it
7526 cannot be lazily bound. */
7527 SYMBOL_REF_FLAGS (stub_fn) |= SYMBOL_FLAG_BIND_NOW;
7529 /* Load the target function into $2. */
7530 addr = gen_rtx_REG (Pmode, GP_REG_FIRST + 2);
7531 lazy_p = mips_load_call_address (MIPS_CALL_NORMAL, addr, fn);
7533 /* Emit the call. */
7534 insn = mips_expand_call (MIPS_CALL_NORMAL, retval, stub_fn,
7535 args_size, NULL_RTX, lazy_p);
7537 /* Tell GCC that this call does indeed use the value of $2. */
7538 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), addr);
7540 /* If we are handling a floating-point return value, we need to
7541 save $18 in the function prologue. Putting a note on the
7542 call will mean that df_regs_ever_live_p ($18) will be true if the
7543 call is not eliminated, and we can check that in the prologue
7544 code. */
7545 if (fp_ret_p)
7546 CALL_INSN_FUNCTION_USAGE (insn) =
7547 gen_rtx_EXPR_LIST (VOIDmode,
7548 gen_rtx_CLOBBER (VOIDmode,
7549 gen_rtx_REG (word_mode, 18)),
7550 CALL_INSN_FUNCTION_USAGE (insn));
7552 return insn;
7555 /* We know the function we are going to call. If we have already
7556 built a stub, we don't need to do anything further. */
7557 fnname = targetm.strip_name_encoding (XSTR (fn, 0));
7558 for (l = mips16_stubs; l != NULL; l = l->next)
7559 if (strcmp (l->name, fnname) == 0)
7560 break;
7562 if (l == NULL)
7564 const char *separator;
7565 char *secname, *stubname;
7566 tree stubid, stubdecl;
7567 unsigned int f;
7569 /* If the function does not return in FPRs, the special stub
7570 section is named
7571 .mips16.call.FNNAME
7573 If the function does return in FPRs, the stub section is named
7574 .mips16.call.fp.FNNAME
7576 Build a decl for the stub. */
7577 secname = ACONCAT ((".mips16.call.", fp_ret_p ? "fp." : "",
7578 fnname, NULL));
7579 stubname = ACONCAT (("__call_stub_", fp_ret_p ? "fp_" : "",
7580 fnname, NULL));
7581 stubid = get_identifier (stubname);
7582 stubdecl = build_decl (BUILTINS_LOCATION,
7583 FUNCTION_DECL, stubid,
7584 build_function_type_list (void_type_node,
7585 NULL_TREE));
7586 DECL_SECTION_NAME (stubdecl) = build_string (strlen (secname), secname);
7587 DECL_RESULT (stubdecl) = build_decl (BUILTINS_LOCATION,
7588 RESULT_DECL, NULL_TREE,
7589 void_type_node);
7591 /* Output a comment. */
7592 fprintf (asm_out_file, "\t# Stub function to call %s%s (",
7593 (fp_ret_p
7594 ? (GET_MODE (retval) == SFmode ? "float " : "double ")
7595 : ""),
7596 fnname);
7597 separator = "";
7598 for (f = (unsigned int) fp_code; f != 0; f >>= 2)
7600 fprintf (asm_out_file, "%s%s", separator,
7601 (f & 3) == 1 ? "float" : "double");
7602 separator = ", ";
7604 fprintf (asm_out_file, ")\n");
7606 /* Start the function definition. */
7607 assemble_start_function (stubdecl, stubname);
7608 mips_start_function_definition (stubname, false);
7610 if (fp_ret_p)
7612 fprintf (asm_out_file, "\t.cfi_startproc\n");
7614 /* Create a fake CFA 4 bytes below the stack pointer.
7615 This works around unwinders (like libgcc's) that expect
7616 the CFA for non-signal frames to be unique. */
7617 fprintf (asm_out_file, "\t.cfi_def_cfa 29,-4\n");
7619 /* "Save" $sp in itself so we don't use the fake CFA.
7620 This is: DW_CFA_val_expression r29, { DW_OP_reg29 }. */
7621 fprintf (asm_out_file, "\t.cfi_escape 0x16,29,1,0x6d\n");
7623 else
7625 /* Load the address of the MIPS16 function into $25. Do this
7626 first so that targets with coprocessor interlocks can use
7627 an MFC1 to fill the delay slot. */
7628 if (TARGET_EXPLICIT_RELOCS)
7630 output_asm_insn ("lui\t%^,%%hi(%0)", &fn);
7631 output_asm_insn ("addiu\t%^,%^,%%lo(%0)", &fn);
7633 else
7634 output_asm_insn ("la\t%^,%0", &fn);
7637 /* Move the arguments from general registers to floating-point
7638 registers. */
7639 mips_output_args_xfer (fp_code, 't');
7641 if (fp_ret_p)
7643 /* Save the return address in $18 and call the non-MIPS16 function.
7644 The stub's caller knows that $18 might be clobbered, even though
7645 $18 is usually a call-saved register. */
7646 fprintf (asm_out_file, "\tmove\t%s,%s\n",
7647 reg_names[GP_REG_FIRST + 18], reg_names[RETURN_ADDR_REGNUM]);
7648 output_asm_insn (mips_output_jump (&fn, 0, -1, true), &fn);
7649 fprintf (asm_out_file, "\t.cfi_register 31,18\n");
7651 /* Move the result from floating-point registers to
7652 general registers. */
7653 switch (GET_MODE (retval))
7655 case SCmode:
7656 mips_output_32bit_xfer ('f', GP_RETURN + TARGET_BIG_ENDIAN,
7657 TARGET_BIG_ENDIAN
7658 ? FP_REG_FIRST + 2
7659 : FP_REG_FIRST);
7660 mips_output_32bit_xfer ('f', GP_RETURN + TARGET_LITTLE_ENDIAN,
7661 TARGET_LITTLE_ENDIAN
7662 ? FP_REG_FIRST + 2
7663 : FP_REG_FIRST);
7664 if (GET_MODE (retval) == SCmode && TARGET_64BIT)
7666 /* On 64-bit targets, complex floats are returned in
7667 a single GPR, such that "sd" on a suitably-aligned
7668 target would store the value correctly. */
7669 fprintf (asm_out_file, "\tdsll\t%s,%s,32\n",
7670 reg_names[GP_RETURN + TARGET_BIG_ENDIAN],
7671 reg_names[GP_RETURN + TARGET_BIG_ENDIAN]);
7672 fprintf (asm_out_file, "\tdsll\t%s,%s,32\n",
7673 reg_names[GP_RETURN + TARGET_LITTLE_ENDIAN],
7674 reg_names[GP_RETURN + TARGET_LITTLE_ENDIAN]);
7675 fprintf (asm_out_file, "\tdsrl\t%s,%s,32\n",
7676 reg_names[GP_RETURN + TARGET_BIG_ENDIAN],
7677 reg_names[GP_RETURN + TARGET_BIG_ENDIAN]);
7678 fprintf (asm_out_file, "\tor\t%s,%s,%s\n",
7679 reg_names[GP_RETURN],
7680 reg_names[GP_RETURN],
7681 reg_names[GP_RETURN + 1]);
7683 break;
7685 case SFmode:
7686 mips_output_32bit_xfer ('f', GP_RETURN, FP_REG_FIRST);
7687 break;
7689 case DCmode:
7690 mips_output_64bit_xfer ('f', GP_RETURN + (8 / UNITS_PER_WORD),
7691 FP_REG_FIRST + 2);
7692 /* Fall though. */
7693 case DFmode:
7694 case V2SFmode:
7695 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT
7696 || GET_MODE (retval) != V2SFmode);
7697 mips_output_64bit_xfer ('f', GP_RETURN, FP_REG_FIRST);
7698 break;
7700 default:
7701 gcc_unreachable ();
7703 fprintf (asm_out_file, "\tjr\t%s\n", reg_names[GP_REG_FIRST + 18]);
7704 fprintf (asm_out_file, "\t.cfi_endproc\n");
7706 else
7708 /* Jump to the previously-loaded address. */
7709 output_asm_insn ("jr\t%^", NULL);
7712 #ifdef ASM_DECLARE_FUNCTION_SIZE
7713 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, stubname, stubdecl);
7714 #endif
7716 mips_end_function_definition (stubname);
7718 /* Record this stub. */
7719 l = XNEW (struct mips16_stub);
7720 l->name = xstrdup (fnname);
7721 l->fp_ret_p = fp_ret_p;
7722 l->next = mips16_stubs;
7723 mips16_stubs = l;
7726 /* If we expect a floating-point return value, but we've built a
7727 stub which does not expect one, then we're in trouble. We can't
7728 use the existing stub, because it won't handle the floating-point
7729 value. We can't build a new stub, because the linker won't know
7730 which stub to use for the various calls in this object file.
7731 Fortunately, this case is illegal, since it means that a function
7732 was declared in two different ways in a single compilation. */
7733 if (fp_ret_p && !l->fp_ret_p)
7734 error ("cannot handle inconsistent calls to %qs", fnname);
7736 if (retval == NULL_RTX)
7737 insn = gen_call_internal_direct (fn, args_size);
7738 else
7739 insn = gen_call_value_internal_direct (retval, fn, args_size);
7740 insn = mips_emit_call_insn (insn, fn, fn, false);
7742 /* If we are calling a stub which handles a floating-point return
7743 value, we need to arrange to save $18 in the prologue. We do this
7744 by marking the function call as using the register. The prologue
7745 will later see that it is used, and emit code to save it. */
7746 if (fp_ret_p)
7747 CALL_INSN_FUNCTION_USAGE (insn) =
7748 gen_rtx_EXPR_LIST (VOIDmode,
7749 gen_rtx_CLOBBER (VOIDmode,
7750 gen_rtx_REG (word_mode, 18)),
7751 CALL_INSN_FUNCTION_USAGE (insn));
7753 return insn;
7756 /* Expand a call of type TYPE. RESULT is where the result will go (null
7757 for "call"s and "sibcall"s), ADDR is the address of the function,
7758 ARGS_SIZE is the size of the arguments and AUX is the value passed
7759 to us by mips_function_arg. LAZY_P is true if this call already
7760 involves a lazily-bound function address (such as when calling
7761 functions through a MIPS16 hard-float stub).
7763 Return the call itself. */
7766 mips_expand_call (enum mips_call_type type, rtx result, rtx addr,
7767 rtx args_size, rtx aux, bool lazy_p)
7769 rtx orig_addr, pattern, insn;
7770 int fp_code;
7772 fp_code = aux == 0 ? 0 : (int) GET_MODE (aux);
7773 insn = mips16_build_call_stub (result, &addr, args_size, fp_code);
7774 if (insn)
7776 gcc_assert (!lazy_p && type == MIPS_CALL_NORMAL);
7777 return insn;
7780 orig_addr = addr;
7781 if (!call_insn_operand (addr, VOIDmode))
7783 if (type == MIPS_CALL_EPILOGUE)
7784 addr = MIPS_EPILOGUE_TEMP (Pmode);
7785 else
7786 addr = gen_reg_rtx (Pmode);
7787 lazy_p |= mips_load_call_address (type, addr, orig_addr);
7790 if (result == 0)
7792 rtx (*fn) (rtx, rtx);
7794 if (type == MIPS_CALL_SIBCALL)
7795 fn = gen_sibcall_internal;
7796 else
7797 fn = gen_call_internal;
7799 pattern = fn (addr, args_size);
7801 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2)
7803 /* Handle return values created by mips_return_fpr_pair. */
7804 rtx (*fn) (rtx, rtx, rtx, rtx);
7805 rtx reg1, reg2;
7807 if (type == MIPS_CALL_SIBCALL)
7808 fn = gen_sibcall_value_multiple_internal;
7809 else
7810 fn = gen_call_value_multiple_internal;
7812 reg1 = XEXP (XVECEXP (result, 0, 0), 0);
7813 reg2 = XEXP (XVECEXP (result, 0, 1), 0);
7814 pattern = fn (reg1, addr, args_size, reg2);
7816 else
7818 rtx (*fn) (rtx, rtx, rtx);
7820 if (type == MIPS_CALL_SIBCALL)
7821 fn = gen_sibcall_value_internal;
7822 else
7823 fn = gen_call_value_internal;
7825 /* Handle return values created by mips_return_fpr_single. */
7826 if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 1)
7827 result = XEXP (XVECEXP (result, 0, 0), 0);
7828 pattern = fn (result, addr, args_size);
7831 return mips_emit_call_insn (pattern, orig_addr, addr, lazy_p);
7834 /* Split call instruction INSN into a $gp-clobbering call and
7835 (where necessary) an instruction to restore $gp from its save slot.
7836 CALL_PATTERN is the pattern of the new call. */
7838 void
7839 mips_split_call (rtx insn, rtx call_pattern)
7841 emit_call_insn (call_pattern);
7842 if (!find_reg_note (insn, REG_NORETURN, 0))
7843 /* Pick a temporary register that is suitable for both MIPS16 and
7844 non-MIPS16 code. $4 and $5 are used for returning complex double
7845 values in soft-float code, so $6 is the first suitable candidate. */
7846 mips_restore_gp_from_cprestore_slot (gen_rtx_REG (Pmode, GP_ARG_FIRST + 2));
7849 /* Return true if a call to DECL may need to use JALX. */
7851 static bool
7852 mips_call_may_need_jalx_p (tree decl)
7854 /* If the current translation unit would use a different mode for DECL,
7855 assume that the call needs JALX. */
7856 if (mips_get_compress_mode (decl) != TARGET_COMPRESSION)
7857 return true;
7859 /* mips_get_compress_mode is always accurate for locally-binding
7860 functions in the current translation unit. */
7861 if (!DECL_EXTERNAL (decl) && targetm.binds_local_p (decl))
7862 return false;
7864 /* When -minterlink-compressed is in effect, assume that functions
7865 could use a different encoding mode unless an attribute explicitly
7866 tells us otherwise. */
7867 if (TARGET_INTERLINK_COMPRESSED)
7869 if (!TARGET_COMPRESSION
7870 && mips_get_compress_off_flags (DECL_ATTRIBUTES (decl)) ==0)
7871 return true;
7872 if (TARGET_COMPRESSION
7873 && mips_get_compress_on_flags (DECL_ATTRIBUTES (decl)) == 0)
7874 return true;
7877 return false;
7880 /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL. */
7882 static bool
7883 mips_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
7885 if (!TARGET_SIBCALLS)
7886 return false;
7888 /* Interrupt handlers need special epilogue code and therefore can't
7889 use sibcalls. */
7890 if (mips_interrupt_type_p (TREE_TYPE (current_function_decl)))
7891 return false;
7893 /* Direct Js are only possible to functions that use the same ISA encoding.
7894 There is no JX counterpoart of JALX. */
7895 if (decl
7896 && const_call_insn_operand (XEXP (DECL_RTL (decl), 0), VOIDmode)
7897 && mips_call_may_need_jalx_p (decl))
7898 return false;
7900 /* Sibling calls should not prevent lazy binding. Lazy-binding stubs
7901 require $gp to be valid on entry, so sibcalls can only use stubs
7902 if $gp is call-clobbered. */
7903 if (decl
7904 && TARGET_CALL_SAVED_GP
7905 && !TARGET_ABICALLS_PIC0
7906 && !targetm.binds_local_p (decl))
7907 return false;
7909 /* Otherwise OK. */
7910 return true;
7913 /* Implement MOVE_BY_PIECES_P. */
7915 bool
7916 mips_move_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align)
7918 if (HAVE_movmemsi)
7920 /* movmemsi is meant to generate code that is at least as good as
7921 move_by_pieces. However, movmemsi effectively uses a by-pieces
7922 implementation both for moves smaller than a word and for
7923 word-aligned moves of no more than MIPS_MAX_MOVE_BYTES_STRAIGHT
7924 bytes. We should allow the tree-level optimisers to do such
7925 moves by pieces, as it often exposes other optimization
7926 opportunities. We might as well continue to use movmemsi at
7927 the rtl level though, as it produces better code when
7928 scheduling is disabled (such as at -O). */
7929 if (currently_expanding_to_rtl)
7930 return false;
7931 if (align < BITS_PER_WORD)
7932 return size < UNITS_PER_WORD;
7933 return size <= MIPS_MAX_MOVE_BYTES_STRAIGHT;
7935 /* The default value. If this becomes a target hook, we should
7936 call the default definition instead. */
7937 return (move_by_pieces_ninsns (size, align, MOVE_MAX_PIECES + 1)
7938 < (unsigned int) MOVE_RATIO (optimize_insn_for_speed_p ()));
7941 /* Implement STORE_BY_PIECES_P. */
7943 bool
7944 mips_store_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align)
7946 /* Storing by pieces involves moving constants into registers
7947 of size MIN (ALIGN, BITS_PER_WORD), then storing them.
7948 We need to decide whether it is cheaper to load the address of
7949 constant data into a register and use a block move instead. */
7951 /* If the data is only byte aligned, then:
7953 (a1) A block move of less than 4 bytes would involve three 3 LBs and
7954 3 SBs. We might as well use 3 single-instruction LIs and 3 SBs
7955 instead.
7957 (a2) A block move of 4 bytes from aligned source data can use an
7958 LW/SWL/SWR sequence. This is often better than the 4 LIs and
7959 4 SBs that we would generate when storing by pieces. */
7960 if (align <= BITS_PER_UNIT)
7961 return size < 4 || !ISA_HAS_LWL_LWR;
7963 /* If the data is 2-byte aligned, then:
7965 (b1) A block move of less than 4 bytes would use a combination of LBs,
7966 LHs, SBs and SHs. We get better code by using single-instruction
7967 LIs, SBs and SHs instead.
7969 (b2) A block move of 4 bytes from aligned source data would again use
7970 an LW/SWL/SWR sequence. In most cases, loading the address of
7971 the source data would require at least one extra instruction.
7972 It is often more efficient to use 2 single-instruction LIs and
7973 2 SHs instead.
7975 (b3) A block move of up to 3 additional bytes would be like (b1).
7977 (b4) A block move of 8 bytes from aligned source data can use two
7978 LW/SWL/SWR sequences or a single LD/SDL/SDR sequence. Both
7979 sequences are better than the 4 LIs and 4 SHs that we'd generate
7980 when storing by pieces.
7982 The reasoning for higher alignments is similar:
7984 (c1) A block move of less than 4 bytes would be the same as (b1).
7986 (c2) A block move of 4 bytes would use an LW/SW sequence. Again,
7987 loading the address of the source data would typically require
7988 at least one extra instruction. It is generally better to use
7989 LUI/ORI/SW instead.
7991 (c3) A block move of up to 3 additional bytes would be like (b1).
7993 (c4) A block move of 8 bytes can use two LW/SW sequences or a single
7994 LD/SD sequence, and in these cases we've traditionally preferred
7995 the memory copy over the more bulky constant moves. */
7996 return (size < 8
7997 || (align < 4 * BITS_PER_UNIT
7998 && !ISA_HAS_LWL_LWR));
8001 /* Emit straight-line code to move LENGTH bytes from SRC to DEST.
8002 Assume that the areas do not overlap. */
8004 static void
8005 mips_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length)
8007 HOST_WIDE_INT offset, delta;
8008 unsigned HOST_WIDE_INT bits;
8009 int i;
8010 machine_mode mode;
8011 rtx *regs;
8013 /* Work out how many bits to move at a time. If both operands have
8014 half-word alignment, it is usually better to move in half words.
8015 For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr
8016 and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr.
8017 Otherwise move word-sized chunks. */
8018 if (MEM_ALIGN (src) == BITS_PER_WORD / 2
8019 && MEM_ALIGN (dest) == BITS_PER_WORD / 2)
8020 bits = BITS_PER_WORD / 2;
8021 else
8022 bits = BITS_PER_WORD;
8024 mode = mode_for_size (bits, MODE_INT, 0);
8025 delta = bits / BITS_PER_UNIT;
8027 /* Allocate a buffer for the temporary registers. */
8028 regs = XALLOCAVEC (rtx, length / delta);
8030 /* Load as many BITS-sized chunks as possible. Use a normal load if
8031 the source has enough alignment, otherwise use left/right pairs. */
8032 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
8034 regs[i] = gen_reg_rtx (mode);
8035 if (MEM_ALIGN (src) >= bits)
8036 mips_emit_move (regs[i], adjust_address (src, mode, offset));
8037 else
8039 rtx part = adjust_address (src, BLKmode, offset);
8040 set_mem_size (part, delta);
8041 if (!mips_expand_ext_as_unaligned_load (regs[i], part, bits, 0, 0))
8042 gcc_unreachable ();
8046 /* Copy the chunks to the destination. */
8047 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++)
8048 if (MEM_ALIGN (dest) >= bits)
8049 mips_emit_move (adjust_address (dest, mode, offset), regs[i]);
8050 else
8052 rtx part = adjust_address (dest, BLKmode, offset);
8053 set_mem_size (part, delta);
8054 if (!mips_expand_ins_as_unaligned_store (part, regs[i], bits, 0))
8055 gcc_unreachable ();
8058 /* Mop up any left-over bytes. */
8059 if (offset < length)
8061 src = adjust_address (src, BLKmode, offset);
8062 dest = adjust_address (dest, BLKmode, offset);
8063 move_by_pieces (dest, src, length - offset,
8064 MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), 0);
8068 /* Helper function for doing a loop-based block operation on memory
8069 reference MEM. Each iteration of the loop will operate on LENGTH
8070 bytes of MEM.
8072 Create a new base register for use within the loop and point it to
8073 the start of MEM. Create a new memory reference that uses this
8074 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */
8076 static void
8077 mips_adjust_block_mem (rtx mem, HOST_WIDE_INT length,
8078 rtx *loop_reg, rtx *loop_mem)
8080 *loop_reg = copy_addr_to_reg (XEXP (mem, 0));
8082 /* Although the new mem does not refer to a known location,
8083 it does keep up to LENGTH bytes of alignment. */
8084 *loop_mem = change_address (mem, BLKmode, *loop_reg);
8085 set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT));
8088 /* Move LENGTH bytes from SRC to DEST using a loop that moves BYTES_PER_ITER
8089 bytes at a time. LENGTH must be at least BYTES_PER_ITER. Assume that
8090 the memory regions do not overlap. */
8092 static void
8093 mips_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length,
8094 HOST_WIDE_INT bytes_per_iter)
8096 rtx label, src_reg, dest_reg, final_src, test;
8097 HOST_WIDE_INT leftover;
8099 leftover = length % bytes_per_iter;
8100 length -= leftover;
8102 /* Create registers and memory references for use within the loop. */
8103 mips_adjust_block_mem (src, bytes_per_iter, &src_reg, &src);
8104 mips_adjust_block_mem (dest, bytes_per_iter, &dest_reg, &dest);
8106 /* Calculate the value that SRC_REG should have after the last iteration
8107 of the loop. */
8108 final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length),
8109 0, 0, OPTAB_WIDEN);
8111 /* Emit the start of the loop. */
8112 label = gen_label_rtx ();
8113 emit_label (label);
8115 /* Emit the loop body. */
8116 mips_block_move_straight (dest, src, bytes_per_iter);
8118 /* Move on to the next block. */
8119 mips_emit_move (src_reg, plus_constant (Pmode, src_reg, bytes_per_iter));
8120 mips_emit_move (dest_reg, plus_constant (Pmode, dest_reg, bytes_per_iter));
8122 /* Emit the loop condition. */
8123 test = gen_rtx_NE (VOIDmode, src_reg, final_src);
8124 if (Pmode == DImode)
8125 emit_jump_insn (gen_cbranchdi4 (test, src_reg, final_src, label));
8126 else
8127 emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label));
8129 /* Mop up any left-over bytes. */
8130 if (leftover)
8131 mips_block_move_straight (dest, src, leftover);
8134 /* Expand a movmemsi instruction, which copies LENGTH bytes from
8135 memory reference SRC to memory reference DEST. */
8137 bool
8138 mips_expand_block_move (rtx dest, rtx src, rtx length)
8140 if (!ISA_HAS_LWL_LWR
8141 && (MEM_ALIGN (src) < BITS_PER_WORD
8142 || MEM_ALIGN (dest) < BITS_PER_WORD))
8143 return false;
8145 if (CONST_INT_P (length))
8147 if (INTVAL (length) <= MIPS_MAX_MOVE_BYTES_STRAIGHT)
8149 mips_block_move_straight (dest, src, INTVAL (length));
8150 return true;
8152 else if (optimize)
8154 mips_block_move_loop (dest, src, INTVAL (length),
8155 MIPS_MAX_MOVE_BYTES_PER_LOOP_ITER);
8156 return true;
8159 return false;
8162 /* Expand a loop of synci insns for the address range [BEGIN, END). */
8164 void
8165 mips_expand_synci_loop (rtx begin, rtx end)
8167 rtx inc, label, end_label, cmp_result, mask, length;
8169 /* Create end_label. */
8170 end_label = gen_label_rtx ();
8172 /* Check if begin equals end. */
8173 cmp_result = gen_rtx_EQ (VOIDmode, begin, end);
8174 emit_jump_insn (gen_condjump (cmp_result, end_label));
8176 /* Load INC with the cache line size (rdhwr INC,$1). */
8177 inc = gen_reg_rtx (Pmode);
8178 emit_insn (PMODE_INSN (gen_rdhwr_synci_step, (inc)));
8180 /* Check if inc is 0. */
8181 cmp_result = gen_rtx_EQ (VOIDmode, inc, const0_rtx);
8182 emit_jump_insn (gen_condjump (cmp_result, end_label));
8184 /* Calculate mask. */
8185 mask = mips_force_unary (Pmode, NEG, inc);
8187 /* Mask out begin by mask. */
8188 begin = mips_force_binary (Pmode, AND, begin, mask);
8190 /* Calculate length. */
8191 length = mips_force_binary (Pmode, MINUS, end, begin);
8193 /* Loop back to here. */
8194 label = gen_label_rtx ();
8195 emit_label (label);
8197 emit_insn (gen_synci (begin));
8199 /* Update length. */
8200 mips_emit_binary (MINUS, length, length, inc);
8202 /* Update begin. */
8203 mips_emit_binary (PLUS, begin, begin, inc);
8205 /* Check if length is greater than 0. */
8206 cmp_result = gen_rtx_GT (VOIDmode, length, const0_rtx);
8207 emit_jump_insn (gen_condjump (cmp_result, label));
8209 emit_label (end_label);
8212 /* Expand a QI or HI mode atomic memory operation.
8214 GENERATOR contains a pointer to the gen_* function that generates
8215 the SI mode underlying atomic operation using masks that we
8216 calculate.
8218 RESULT is the return register for the operation. Its value is NULL
8219 if unused.
8221 MEM is the location of the atomic access.
8223 OLDVAL is the first operand for the operation.
8225 NEWVAL is the optional second operand for the operation. Its value
8226 is NULL if unused. */
8228 void
8229 mips_expand_atomic_qihi (union mips_gen_fn_ptrs generator,
8230 rtx result, rtx mem, rtx oldval, rtx newval)
8232 rtx orig_addr, memsi_addr, memsi, shift, shiftsi, unshifted_mask;
8233 rtx unshifted_mask_reg, mask, inverted_mask, si_op;
8234 rtx res = NULL;
8235 machine_mode mode;
8237 mode = GET_MODE (mem);
8239 /* Compute the address of the containing SImode value. */
8240 orig_addr = force_reg (Pmode, XEXP (mem, 0));
8241 memsi_addr = mips_force_binary (Pmode, AND, orig_addr,
8242 force_reg (Pmode, GEN_INT (-4)));
8244 /* Create a memory reference for it. */
8245 memsi = gen_rtx_MEM (SImode, memsi_addr);
8246 set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER);
8247 MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem);
8249 /* Work out the byte offset of the QImode or HImode value,
8250 counting from the least significant byte. */
8251 shift = mips_force_binary (Pmode, AND, orig_addr, GEN_INT (3));
8252 if (TARGET_BIG_ENDIAN)
8253 mips_emit_binary (XOR, shift, shift, GEN_INT (mode == QImode ? 3 : 2));
8255 /* Multiply by eight to convert the shift value from bytes to bits. */
8256 mips_emit_binary (ASHIFT, shift, shift, GEN_INT (3));
8258 /* Make the final shift an SImode value, so that it can be used in
8259 SImode operations. */
8260 shiftsi = force_reg (SImode, gen_lowpart (SImode, shift));
8262 /* Set MASK to an inclusive mask of the QImode or HImode value. */
8263 unshifted_mask = GEN_INT (GET_MODE_MASK (mode));
8264 unshifted_mask_reg = force_reg (SImode, unshifted_mask);
8265 mask = mips_force_binary (SImode, ASHIFT, unshifted_mask_reg, shiftsi);
8267 /* Compute the equivalent exclusive mask. */
8268 inverted_mask = gen_reg_rtx (SImode);
8269 emit_insn (gen_rtx_SET (VOIDmode, inverted_mask,
8270 gen_rtx_NOT (SImode, mask)));
8272 /* Shift the old value into place. */
8273 if (oldval != const0_rtx)
8275 oldval = convert_modes (SImode, mode, oldval, true);
8276 oldval = force_reg (SImode, oldval);
8277 oldval = mips_force_binary (SImode, ASHIFT, oldval, shiftsi);
8280 /* Do the same for the new value. */
8281 if (newval && newval != const0_rtx)
8283 newval = convert_modes (SImode, mode, newval, true);
8284 newval = force_reg (SImode, newval);
8285 newval = mips_force_binary (SImode, ASHIFT, newval, shiftsi);
8288 /* Do the SImode atomic access. */
8289 if (result)
8290 res = gen_reg_rtx (SImode);
8291 if (newval)
8292 si_op = generator.fn_6 (res, memsi, mask, inverted_mask, oldval, newval);
8293 else if (result)
8294 si_op = generator.fn_5 (res, memsi, mask, inverted_mask, oldval);
8295 else
8296 si_op = generator.fn_4 (memsi, mask, inverted_mask, oldval);
8298 emit_insn (si_op);
8300 if (result)
8302 /* Shift and convert the result. */
8303 mips_emit_binary (AND, res, res, mask);
8304 mips_emit_binary (LSHIFTRT, res, res, shiftsi);
8305 mips_emit_move (result, gen_lowpart (GET_MODE (result), res));
8309 /* Return true if it is possible to use left/right accesses for a
8310 bitfield of WIDTH bits starting BITPOS bits into BLKmode memory OP.
8311 When returning true, update *LEFT and *RIGHT as follows:
8313 *LEFT is a QImode reference to the first byte if big endian or
8314 the last byte if little endian. This address can be used in the
8315 left-side instructions (LWL, SWL, LDL, SDL).
8317 *RIGHT is a QImode reference to the opposite end of the field and
8318 can be used in the patterning right-side instruction. */
8320 static bool
8321 mips_get_unaligned_mem (rtx op, HOST_WIDE_INT width, HOST_WIDE_INT bitpos,
8322 rtx *left, rtx *right)
8324 rtx first, last;
8326 /* Check that the size is valid. */
8327 if (width != 32 && (!TARGET_64BIT || width != 64))
8328 return false;
8330 /* We can only access byte-aligned values. Since we are always passed
8331 a reference to the first byte of the field, it is not necessary to
8332 do anything with BITPOS after this check. */
8333 if (bitpos % BITS_PER_UNIT != 0)
8334 return false;
8336 /* Reject aligned bitfields: we want to use a normal load or store
8337 instead of a left/right pair. */
8338 if (MEM_ALIGN (op) >= width)
8339 return false;
8341 /* Get references to both ends of the field. */
8342 first = adjust_address (op, QImode, 0);
8343 last = adjust_address (op, QImode, width / BITS_PER_UNIT - 1);
8345 /* Allocate to LEFT and RIGHT according to endianness. LEFT should
8346 correspond to the MSB and RIGHT to the LSB. */
8347 if (TARGET_BIG_ENDIAN)
8348 *left = first, *right = last;
8349 else
8350 *left = last, *right = first;
8352 return true;
8355 /* Try to use left/right loads to expand an "extv" or "extzv" pattern.
8356 DEST, SRC, WIDTH and BITPOS are the operands passed to the expander;
8357 the operation is the equivalent of:
8359 (set DEST (*_extract SRC WIDTH BITPOS))
8361 Return true on success. */
8363 bool
8364 mips_expand_ext_as_unaligned_load (rtx dest, rtx src, HOST_WIDE_INT width,
8365 HOST_WIDE_INT bitpos, bool unsigned_p)
8367 rtx left, right, temp;
8368 rtx dest1 = NULL_RTX;
8370 /* If TARGET_64BIT, the destination of a 32-bit "extz" or "extzv" will
8371 be a DImode, create a new temp and emit a zero extend at the end. */
8372 if (GET_MODE (dest) == DImode
8373 && REG_P (dest)
8374 && GET_MODE_BITSIZE (SImode) == width)
8376 dest1 = dest;
8377 dest = gen_reg_rtx (SImode);
8380 if (!mips_get_unaligned_mem (src, width, bitpos, &left, &right))
8381 return false;
8383 temp = gen_reg_rtx (GET_MODE (dest));
8384 if (GET_MODE (dest) == DImode)
8386 emit_insn (gen_mov_ldl (temp, src, left));
8387 emit_insn (gen_mov_ldr (dest, copy_rtx (src), right, temp));
8389 else
8391 emit_insn (gen_mov_lwl (temp, src, left));
8392 emit_insn (gen_mov_lwr (dest, copy_rtx (src), right, temp));
8395 /* If we were loading 32bits and the original register was DI then
8396 sign/zero extend into the orignal dest. */
8397 if (dest1)
8399 if (unsigned_p)
8400 emit_insn (gen_zero_extendsidi2 (dest1, dest));
8401 else
8402 emit_insn (gen_extendsidi2 (dest1, dest));
8404 return true;
8407 /* Try to use left/right stores to expand an "ins" pattern. DEST, WIDTH,
8408 BITPOS and SRC are the operands passed to the expander; the operation
8409 is the equivalent of:
8411 (set (zero_extract DEST WIDTH BITPOS) SRC)
8413 Return true on success. */
8415 bool
8416 mips_expand_ins_as_unaligned_store (rtx dest, rtx src, HOST_WIDE_INT width,
8417 HOST_WIDE_INT bitpos)
8419 rtx left, right;
8420 machine_mode mode;
8422 if (!mips_get_unaligned_mem (dest, width, bitpos, &left, &right))
8423 return false;
8425 mode = mode_for_size (width, MODE_INT, 0);
8426 src = gen_lowpart (mode, src);
8427 if (mode == DImode)
8429 emit_insn (gen_mov_sdl (dest, src, left));
8430 emit_insn (gen_mov_sdr (copy_rtx (dest), copy_rtx (src), right));
8432 else
8434 emit_insn (gen_mov_swl (dest, src, left));
8435 emit_insn (gen_mov_swr (copy_rtx (dest), copy_rtx (src), right));
8437 return true;
8440 /* Return true if X is a MEM with the same size as MODE. */
8442 bool
8443 mips_mem_fits_mode_p (machine_mode mode, rtx x)
8445 return (MEM_P (x)
8446 && MEM_SIZE_KNOWN_P (x)
8447 && MEM_SIZE (x) == GET_MODE_SIZE (mode));
8450 /* Return true if (zero_extract OP WIDTH BITPOS) can be used as the
8451 source of an "ext" instruction or the destination of an "ins"
8452 instruction. OP must be a register operand and the following
8453 conditions must hold:
8455 0 <= BITPOS < GET_MODE_BITSIZE (GET_MODE (op))
8456 0 < WIDTH <= GET_MODE_BITSIZE (GET_MODE (op))
8457 0 < BITPOS + WIDTH <= GET_MODE_BITSIZE (GET_MODE (op))
8459 Also reject lengths equal to a word as they are better handled
8460 by the move patterns. */
8462 bool
8463 mips_use_ins_ext_p (rtx op, HOST_WIDE_INT width, HOST_WIDE_INT bitpos)
8465 if (!ISA_HAS_EXT_INS
8466 || !register_operand (op, VOIDmode)
8467 || GET_MODE_BITSIZE (GET_MODE (op)) > BITS_PER_WORD)
8468 return false;
8470 if (!IN_RANGE (width, 1, GET_MODE_BITSIZE (GET_MODE (op)) - 1))
8471 return false;
8473 if (bitpos < 0 || bitpos + width > GET_MODE_BITSIZE (GET_MODE (op)))
8474 return false;
8476 return true;
8479 /* Check if MASK and SHIFT are valid in mask-low-and-shift-left
8480 operation if MAXLEN is the maxium length of consecutive bits that
8481 can make up MASK. MODE is the mode of the operation. See
8482 mask_low_and_shift_len for the actual definition. */
8484 bool
8485 mask_low_and_shift_p (machine_mode mode, rtx mask, rtx shift, int maxlen)
8487 return IN_RANGE (mask_low_and_shift_len (mode, mask, shift), 1, maxlen);
8490 /* Return true iff OP1 and OP2 are valid operands together for the
8491 *and<MODE>3 and *and<MODE>3_mips16 patterns. For the cases to consider,
8492 see the table in the comment before the pattern. */
8494 bool
8495 and_operands_ok (machine_mode mode, rtx op1, rtx op2)
8497 return (memory_operand (op1, mode)
8498 ? and_load_operand (op2, mode)
8499 : and_reg_operand (op2, mode));
8502 /* The canonical form of a mask-low-and-shift-left operation is
8503 (and (ashift X SHIFT) MASK) where MASK has the lower SHIFT number of bits
8504 cleared. Thus we need to shift MASK to the right before checking if it
8505 is a valid mask value. MODE is the mode of the operation. If true
8506 return the length of the mask, otherwise return -1. */
8509 mask_low_and_shift_len (machine_mode mode, rtx mask, rtx shift)
8511 HOST_WIDE_INT shval;
8513 shval = INTVAL (shift) & (GET_MODE_BITSIZE (mode) - 1);
8514 return exact_log2 ((UINTVAL (mask) >> shval) + 1);
8517 /* Return true if -msplit-addresses is selected and should be honored.
8519 -msplit-addresses is a half-way house between explicit relocations
8520 and the traditional assembler macros. It can split absolute 32-bit
8521 symbolic constants into a high/lo_sum pair but uses macros for other
8522 sorts of access.
8524 Like explicit relocation support for REL targets, it relies
8525 on GNU extensions in the assembler and the linker.
8527 Although this code should work for -O0, it has traditionally
8528 been treated as an optimization. */
8530 static bool
8531 mips_split_addresses_p (void)
8533 return (TARGET_SPLIT_ADDRESSES
8534 && optimize
8535 && !TARGET_MIPS16
8536 && !flag_pic
8537 && !ABI_HAS_64BIT_SYMBOLS);
8540 /* (Re-)Initialize mips_split_p, mips_lo_relocs and mips_hi_relocs. */
8542 static void
8543 mips_init_relocs (void)
8545 memset (mips_split_p, '\0', sizeof (mips_split_p));
8546 memset (mips_split_hi_p, '\0', sizeof (mips_split_hi_p));
8547 memset (mips_use_pcrel_pool_p, '\0', sizeof (mips_use_pcrel_pool_p));
8548 memset (mips_hi_relocs, '\0', sizeof (mips_hi_relocs));
8549 memset (mips_lo_relocs, '\0', sizeof (mips_lo_relocs));
8551 if (TARGET_MIPS16_PCREL_LOADS)
8552 mips_use_pcrel_pool_p[SYMBOL_ABSOLUTE] = true;
8553 else
8555 if (ABI_HAS_64BIT_SYMBOLS)
8557 if (TARGET_EXPLICIT_RELOCS)
8559 mips_split_p[SYMBOL_64_HIGH] = true;
8560 mips_hi_relocs[SYMBOL_64_HIGH] = "%highest(";
8561 mips_lo_relocs[SYMBOL_64_HIGH] = "%higher(";
8563 mips_split_p[SYMBOL_64_MID] = true;
8564 mips_hi_relocs[SYMBOL_64_MID] = "%higher(";
8565 mips_lo_relocs[SYMBOL_64_MID] = "%hi(";
8567 mips_split_p[SYMBOL_64_LOW] = true;
8568 mips_hi_relocs[SYMBOL_64_LOW] = "%hi(";
8569 mips_lo_relocs[SYMBOL_64_LOW] = "%lo(";
8571 mips_split_p[SYMBOL_ABSOLUTE] = true;
8572 mips_lo_relocs[SYMBOL_ABSOLUTE] = "%lo(";
8575 else
8577 if (TARGET_EXPLICIT_RELOCS
8578 || mips_split_addresses_p ()
8579 || TARGET_MIPS16)
8581 mips_split_p[SYMBOL_ABSOLUTE] = true;
8582 mips_hi_relocs[SYMBOL_ABSOLUTE] = "%hi(";
8583 mips_lo_relocs[SYMBOL_ABSOLUTE] = "%lo(";
8588 if (TARGET_MIPS16)
8590 /* The high part is provided by a pseudo copy of $gp. */
8591 mips_split_p[SYMBOL_GP_RELATIVE] = true;
8592 mips_lo_relocs[SYMBOL_GP_RELATIVE] = "%gprel(";
8594 else if (TARGET_EXPLICIT_RELOCS)
8595 /* Small data constants are kept whole until after reload,
8596 then lowered by mips_rewrite_small_data. */
8597 mips_lo_relocs[SYMBOL_GP_RELATIVE] = "%gp_rel(";
8599 if (TARGET_EXPLICIT_RELOCS)
8601 mips_split_p[SYMBOL_GOT_PAGE_OFST] = true;
8602 if (TARGET_NEWABI)
8604 mips_lo_relocs[SYMBOL_GOTOFF_PAGE] = "%got_page(";
8605 mips_lo_relocs[SYMBOL_GOT_PAGE_OFST] = "%got_ofst(";
8607 else
8609 mips_lo_relocs[SYMBOL_GOTOFF_PAGE] = "%got(";
8610 mips_lo_relocs[SYMBOL_GOT_PAGE_OFST] = "%lo(";
8612 if (TARGET_MIPS16)
8613 /* Expose the use of $28 as soon as possible. */
8614 mips_split_hi_p[SYMBOL_GOT_PAGE_OFST] = true;
8616 if (TARGET_XGOT)
8618 /* The HIGH and LO_SUM are matched by special .md patterns. */
8619 mips_split_p[SYMBOL_GOT_DISP] = true;
8621 mips_split_p[SYMBOL_GOTOFF_DISP] = true;
8622 mips_hi_relocs[SYMBOL_GOTOFF_DISP] = "%got_hi(";
8623 mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got_lo(";
8625 mips_split_p[SYMBOL_GOTOFF_CALL] = true;
8626 mips_hi_relocs[SYMBOL_GOTOFF_CALL] = "%call_hi(";
8627 mips_lo_relocs[SYMBOL_GOTOFF_CALL] = "%call_lo(";
8629 else
8631 if (TARGET_NEWABI)
8632 mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got_disp(";
8633 else
8634 mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got(";
8635 mips_lo_relocs[SYMBOL_GOTOFF_CALL] = "%call16(";
8636 if (TARGET_MIPS16)
8637 /* Expose the use of $28 as soon as possible. */
8638 mips_split_p[SYMBOL_GOT_DISP] = true;
8642 if (TARGET_NEWABI)
8644 mips_split_p[SYMBOL_GOTOFF_LOADGP] = true;
8645 mips_hi_relocs[SYMBOL_GOTOFF_LOADGP] = "%hi(%neg(%gp_rel(";
8646 mips_lo_relocs[SYMBOL_GOTOFF_LOADGP] = "%lo(%neg(%gp_rel(";
8649 mips_lo_relocs[SYMBOL_TLSGD] = "%tlsgd(";
8650 mips_lo_relocs[SYMBOL_TLSLDM] = "%tlsldm(";
8652 if (TARGET_MIPS16_PCREL_LOADS)
8654 mips_use_pcrel_pool_p[SYMBOL_DTPREL] = true;
8655 mips_use_pcrel_pool_p[SYMBOL_TPREL] = true;
8657 else
8659 mips_split_p[SYMBOL_DTPREL] = true;
8660 mips_hi_relocs[SYMBOL_DTPREL] = "%dtprel_hi(";
8661 mips_lo_relocs[SYMBOL_DTPREL] = "%dtprel_lo(";
8663 mips_split_p[SYMBOL_TPREL] = true;
8664 mips_hi_relocs[SYMBOL_TPREL] = "%tprel_hi(";
8665 mips_lo_relocs[SYMBOL_TPREL] = "%tprel_lo(";
8668 mips_lo_relocs[SYMBOL_GOTTPREL] = "%gottprel(";
8669 mips_lo_relocs[SYMBOL_HALF] = "%half(";
8672 /* Print symbolic operand OP, which is part of a HIGH or LO_SUM
8673 in context CONTEXT. RELOCS is the array of relocations to use. */
8675 static void
8676 mips_print_operand_reloc (FILE *file, rtx op, enum mips_symbol_context context,
8677 const char **relocs)
8679 enum mips_symbol_type symbol_type;
8680 const char *p;
8682 symbol_type = mips_classify_symbolic_expression (op, context);
8683 gcc_assert (relocs[symbol_type]);
8685 fputs (relocs[symbol_type], file);
8686 output_addr_const (file, mips_strip_unspec_address (op));
8687 for (p = relocs[symbol_type]; *p != 0; p++)
8688 if (*p == '(')
8689 fputc (')', file);
8692 /* Start a new block with the given asm switch enabled. If we need
8693 to print a directive, emit PREFIX before it and SUFFIX after it. */
8695 static void
8696 mips_push_asm_switch_1 (struct mips_asm_switch *asm_switch,
8697 const char *prefix, const char *suffix)
8699 if (asm_switch->nesting_level == 0)
8700 fprintf (asm_out_file, "%s.set\tno%s%s", prefix, asm_switch->name, suffix);
8701 asm_switch->nesting_level++;
8704 /* Likewise, but end a block. */
8706 static void
8707 mips_pop_asm_switch_1 (struct mips_asm_switch *asm_switch,
8708 const char *prefix, const char *suffix)
8710 gcc_assert (asm_switch->nesting_level);
8711 asm_switch->nesting_level--;
8712 if (asm_switch->nesting_level == 0)
8713 fprintf (asm_out_file, "%s.set\t%s%s", prefix, asm_switch->name, suffix);
8716 /* Wrappers around mips_push_asm_switch_1 and mips_pop_asm_switch_1
8717 that either print a complete line or print nothing. */
8719 void
8720 mips_push_asm_switch (struct mips_asm_switch *asm_switch)
8722 mips_push_asm_switch_1 (asm_switch, "\t", "\n");
8725 void
8726 mips_pop_asm_switch (struct mips_asm_switch *asm_switch)
8728 mips_pop_asm_switch_1 (asm_switch, "\t", "\n");
8731 /* Print the text for PRINT_OPERAND punctation character CH to FILE.
8732 The punctuation characters are:
8734 '(' Start a nested ".set noreorder" block.
8735 ')' End a nested ".set noreorder" block.
8736 '[' Start a nested ".set noat" block.
8737 ']' End a nested ".set noat" block.
8738 '<' Start a nested ".set nomacro" block.
8739 '>' End a nested ".set nomacro" block.
8740 '*' Behave like %(%< if generating a delayed-branch sequence.
8741 '#' Print a nop if in a ".set noreorder" block.
8742 '/' Like '#', but do nothing within a delayed-branch sequence.
8743 '?' Print "l" if mips_branch_likely is true
8744 '~' Print a nop if mips_branch_likely is true
8745 '.' Print the name of the register with a hard-wired zero (zero or $0).
8746 '@' Print the name of the assembler temporary register (at or $1).
8747 '^' Print the name of the pic call-through register (t9 or $25).
8748 '+' Print the name of the gp register (usually gp or $28).
8749 '$' Print the name of the stack pointer register (sp or $29).
8750 ':' Print "c" to use the compact version if the delay slot is a nop.
8751 '!' Print "s" to use the short version if the delay slot contains a
8752 16-bit instruction.
8754 See also mips_init_print_operand_punct. */
8756 static void
8757 mips_print_operand_punctuation (FILE *file, int ch)
8759 switch (ch)
8761 case '(':
8762 mips_push_asm_switch_1 (&mips_noreorder, "", "\n\t");
8763 break;
8765 case ')':
8766 mips_pop_asm_switch_1 (&mips_noreorder, "\n\t", "");
8767 break;
8769 case '[':
8770 mips_push_asm_switch_1 (&mips_noat, "", "\n\t");
8771 break;
8773 case ']':
8774 mips_pop_asm_switch_1 (&mips_noat, "\n\t", "");
8775 break;
8777 case '<':
8778 mips_push_asm_switch_1 (&mips_nomacro, "", "\n\t");
8779 break;
8781 case '>':
8782 mips_pop_asm_switch_1 (&mips_nomacro, "\n\t", "");
8783 break;
8785 case '*':
8786 if (final_sequence != 0)
8788 mips_print_operand_punctuation (file, '(');
8789 mips_print_operand_punctuation (file, '<');
8791 break;
8793 case '#':
8794 if (mips_noreorder.nesting_level > 0)
8795 fputs ("\n\tnop", file);
8796 break;
8798 case '/':
8799 /* Print an extra newline so that the delayed insn is separated
8800 from the following ones. This looks neater and is consistent
8801 with non-nop delayed sequences. */
8802 if (mips_noreorder.nesting_level > 0 && final_sequence == 0)
8803 fputs ("\n\tnop\n", file);
8804 break;
8806 case '?':
8807 if (mips_branch_likely)
8808 putc ('l', file);
8809 break;
8811 case '~':
8812 if (mips_branch_likely)
8813 fputs ("\n\tnop", file);
8814 break;
8816 case '.':
8817 fputs (reg_names[GP_REG_FIRST + 0], file);
8818 break;
8820 case '@':
8821 fputs (reg_names[AT_REGNUM], file);
8822 break;
8824 case '^':
8825 fputs (reg_names[PIC_FUNCTION_ADDR_REGNUM], file);
8826 break;
8828 case '+':
8829 fputs (reg_names[PIC_OFFSET_TABLE_REGNUM], file);
8830 break;
8832 case '$':
8833 fputs (reg_names[STACK_POINTER_REGNUM], file);
8834 break;
8836 case ':':
8837 /* When final_sequence is 0, the delay slot will be a nop. We can
8838 use the compact version where available. The %: formatter will
8839 only be present if a compact form of the branch is available. */
8840 if (final_sequence == 0)
8841 putc ('c', file);
8842 break;
8844 case '!':
8845 /* If the delay slot instruction is short, then use the
8846 compact version. */
8847 if (TARGET_MICROMIPS && !TARGET_INTERLINK_COMPRESSED && mips_isa_rev <= 5
8848 && (final_sequence == 0
8849 || get_attr_length (XVECEXP (final_sequence, 0, 1)) == 2))
8850 putc ('s', file);
8851 break;
8853 default:
8854 gcc_unreachable ();
8855 break;
8859 /* Initialize mips_print_operand_punct. */
8861 static void
8862 mips_init_print_operand_punct (void)
8864 const char *p;
8866 for (p = "()[]<>*#/?~.@^+$:!"; *p; p++)
8867 mips_print_operand_punct[(unsigned char) *p] = true;
8870 /* PRINT_OPERAND prefix LETTER refers to the integer branch instruction
8871 associated with condition CODE. Print the condition part of the
8872 opcode to FILE. */
8874 static void
8875 mips_print_int_branch_condition (FILE *file, enum rtx_code code, int letter)
8877 switch (code)
8879 case EQ:
8880 case NE:
8881 case GT:
8882 case GE:
8883 case LT:
8884 case LE:
8885 case GTU:
8886 case GEU:
8887 case LTU:
8888 case LEU:
8889 /* Conveniently, the MIPS names for these conditions are the same
8890 as their RTL equivalents. */
8891 fputs (GET_RTX_NAME (code), file);
8892 break;
8894 default:
8895 output_operand_lossage ("'%%%c' is not a valid operand prefix", letter);
8896 break;
8900 /* Likewise floating-point branches. */
8902 static void
8903 mips_print_float_branch_condition (FILE *file, enum rtx_code code, int letter)
8905 switch (code)
8907 case EQ:
8908 if (ISA_HAS_CCF)
8909 fputs ("c1eqz", file);
8910 else
8911 fputs ("c1f", file);
8912 break;
8914 case NE:
8915 if (ISA_HAS_CCF)
8916 fputs ("c1nez", file);
8917 else
8918 fputs ("c1t", file);
8919 break;
8921 default:
8922 output_operand_lossage ("'%%%c' is not a valid operand prefix", letter);
8923 break;
8927 /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */
8929 static bool
8930 mips_print_operand_punct_valid_p (unsigned char code)
8932 return mips_print_operand_punct[code];
8935 /* Implement TARGET_PRINT_OPERAND. The MIPS-specific operand codes are:
8937 'E' Print CONST_INT_OP element 0 of a replicated CONST_VECTOR in decimal.
8938 'X' Print CONST_INT OP in hexadecimal format.
8939 'x' Print the low 16 bits of CONST_INT OP in hexadecimal format.
8940 'd' Print CONST_INT OP in decimal.
8941 'B' Print CONST_INT as an unsigned byte [0..255].
8942 'm' Print one less than CONST_INT OP in decimal.
8943 'y' Print exact log2 of CONST_INT OP in decimal.
8944 'h' Print the high-part relocation associated with OP, after stripping
8945 any outermost HIGH.
8946 'R' Print the low-part relocation associated with OP.
8947 'C' Print the integer branch condition for comparison OP.
8948 'N' Print the inverse of the integer branch condition for comparison OP.
8949 'F' Print the FPU branch condition for comparison OP.
8950 'W' Print the inverse of the FPU branch condition for comparison OP.
8951 'w' Print a MSA register.
8952 'T' Print 'f' for (eq:CC ...), 't' for (ne:CC ...),
8953 'z' for (eq:?I ...), 'n' for (ne:?I ...).
8954 't' Like 'T', but with the EQ/NE cases reversed
8955 'Y' Print mips_fp_conditions[INTVAL (OP)]
8956 'Z' Print OP and a comma for ISA_HAS_8CC, otherwise print nothing.
8957 'q' Print a DSP accumulator register.
8958 'D' Print the second part of a double-word register or memory operand.
8959 'L' Print the low-order register in a double-word register operand.
8960 'M' Print high-order register in a double-word register operand.
8961 'z' Print $0 if OP is zero, otherwise print OP normally.
8962 'b' Print the address of a memory operand, without offset.
8963 'v' Print the insn size suffix b,h,w,d,f or d for vector modes V16QI,V8HI,V4SI,
8964 V2SI,V4DF and V2DF. */
8966 static void
8967 mips_print_operand (FILE *file, rtx op, int letter)
8969 enum rtx_code code;
8971 if (mips_print_operand_punct_valid_p (letter))
8973 mips_print_operand_punctuation (file, letter);
8974 return;
8977 gcc_assert (op);
8978 code = GET_CODE (op);
8980 switch (letter)
8982 case 'E':
8983 if (GET_CODE (op) == CONST_VECTOR)
8985 gcc_assert (mips_const_vector_same_val_p (op, GET_MODE (op)));
8986 op = CONST_VECTOR_ELT (op, 0);
8987 gcc_assert (CONST_INT_P (op));
8988 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
8990 else
8991 output_operand_lossage ("invalid use of '%%%c'", letter);
8992 break;
8994 case 'X':
8995 if (CONST_INT_P (op))
8996 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op));
8997 else
8998 output_operand_lossage ("invalid use of '%%%c'", letter);
8999 break;
9001 case 'x':
9002 if (CONST_INT_P (op))
9003 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op) & 0xffff);
9004 else
9005 output_operand_lossage ("invalid use of '%%%c'", letter);
9006 break;
9008 case 'd':
9009 if (CONST_INT_P (op))
9010 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op));
9011 else
9012 output_operand_lossage ("invalid use of '%%%c'", letter);
9013 break;
9015 case 'B':
9016 if (CONST_INT_P (op))
9018 HOST_WIDE_INT val = INTVAL (op);
9019 if (val < 0)
9021 gcc_assert (val >= -128);
9022 val += 256;
9023 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
9025 else
9027 gcc_assert (val <= 255);
9028 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
9031 else
9032 output_operand_lossage ("invalid use of '%%%c'", letter);
9033 break;
9035 case 'K':
9036 if (CONST_INT_P (op))
9038 int val = INTVAL (op);
9039 int i;
9040 for (i = 0; i < 16; i++)
9042 if ((val & (1 << i)) == val)
9044 fprintf (file, "%d", i);
9045 break;
9048 if (i == 16)
9049 output_operand_lossage ("invalid use of '%%%c' - Mask inappropriate", letter);
9051 else
9052 output_operand_lossage ("invalid use of '%%%c'", letter);
9053 break;
9055 case 'm':
9056 if (CONST_INT_P (op))
9057 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op) - 1);
9058 else
9059 output_operand_lossage ("invalid use of '%%%c'", letter);
9060 break;
9062 case 'y':
9063 if (CONST_INT_P (op))
9065 int val = exact_log2 (INTVAL (op));
9066 if (val != -1)
9067 fprintf (file, "%d", val);
9068 else
9069 output_operand_lossage ("invalid use of '%%%c'", letter);
9071 else
9072 output_operand_lossage ("invalid use of '%%%c'", letter);
9073 break;
9075 case 'h':
9076 if (code == HIGH)
9077 op = XEXP (op, 0);
9078 mips_print_operand_reloc (file, op, SYMBOL_CONTEXT_LEA, mips_hi_relocs);
9079 break;
9081 case 'R':
9082 mips_print_operand_reloc (file, op, SYMBOL_CONTEXT_LEA, mips_lo_relocs);
9083 break;
9085 case 'C':
9086 mips_print_int_branch_condition (file, code, letter);
9087 break;
9089 case 'N':
9090 mips_print_int_branch_condition (file, reverse_condition (code), letter);
9091 break;
9093 case 'F':
9094 mips_print_float_branch_condition (file, code, letter);
9095 break;
9097 case 'W':
9098 mips_print_float_branch_condition (file, reverse_condition (code),
9099 letter);
9100 break;
9102 case 'T':
9103 case 't':
9105 int truth = (code == NE) == (letter == 'T');
9106 fputc ("zfnt"[truth * 2 + ST_REG_P (REGNO (XEXP (op, 0)))], file);
9108 break;
9110 case 'Y':
9111 if (code == CONST_INT && UINTVAL (op) < ARRAY_SIZE (mips_fp_conditions))
9112 fputs (mips_fp_conditions[UINTVAL (op)], file);
9113 else
9114 output_operand_lossage ("'%%%c' is not a valid operand prefix",
9115 letter);
9116 break;
9118 case 'Z':
9119 if (ISA_HAS_8CC || ISA_HAS_CCF)
9121 mips_print_operand (file, op, 0);
9122 fputc (',', file);
9124 break;
9126 case 'q':
9127 if (code == REG && MD_REG_P (REGNO (op)))
9128 fprintf (file, "$ac0");
9129 else if (code == REG && DSP_ACC_REG_P (REGNO (op)))
9130 fprintf (file, "$ac%c", reg_names[REGNO (op)][3]);
9131 else
9132 output_operand_lossage ("invalid use of '%%%c'", letter);
9133 break;
9135 case 'w':
9136 if (code == REG && MSA_REG_P (REGNO (op)))
9137 fprintf (file, "$w%s", &reg_names[REGNO (op)][2]);
9138 else
9139 output_operand_lossage ("invalid use of '%%%c'", letter);
9140 break;
9142 case 'v':
9143 switch (GET_MODE (op))
9145 case V16QImode:
9146 fprintf (file, "b");
9147 break;
9148 case V8HImode:
9149 fprintf (file, "h");
9150 break;
9151 case V4SImode:
9152 fprintf (file, "w");
9153 break;
9154 case V2DImode:
9155 fprintf (file, "d");
9156 break;
9157 case V4SFmode:
9158 fprintf (file, "w");
9159 break;
9160 case V2DFmode:
9161 fprintf (file, "d");
9162 break;
9163 default:
9164 output_operand_lossage ("invalid use of '%%%c'", letter);
9166 break;
9168 default:
9169 switch (code)
9171 case REG:
9173 unsigned int regno = REGNO (op);
9174 if ((letter == 'M' && TARGET_LITTLE_ENDIAN)
9175 || (letter == 'L' && TARGET_BIG_ENDIAN)
9176 || letter == 'D')
9177 regno++;
9178 else if (letter && letter != 'z' && letter != 'M' && letter != 'L')
9179 output_operand_lossage ("invalid use of '%%%c'", letter);
9180 /* We need to print $0 .. $31 for COP0 registers. */
9181 if (COP0_REG_P (regno))
9182 fprintf (file, "$%s", &reg_names[regno][4]);
9183 else
9184 fprintf (file, "%s", reg_names[regno]);
9186 break;
9188 case MEM:
9189 if (letter == 'D')
9190 output_address (plus_constant (Pmode, XEXP (op, 0), 4));
9191 else if (letter == 'b')
9193 gcc_assert (REG_P (XEXP (op, 0)));
9194 mips_print_operand (file, XEXP (op, 0), 0);
9196 else if (letter && letter != 'z')
9197 output_operand_lossage ("invalid use of '%%%c'", letter);
9198 else
9199 output_address (XEXP (op, 0));
9200 break;
9202 default:
9203 if (letter == 'z' && op == CONST0_RTX (GET_MODE (op)))
9204 fputs (reg_names[GP_REG_FIRST], file);
9205 else if (letter && letter != 'z')
9206 output_operand_lossage ("invalid use of '%%%c'", letter);
9207 else if (CONST_GP_P (op))
9208 fputs (reg_names[GLOBAL_POINTER_REGNUM], file);
9209 else
9210 output_addr_const (file, mips_strip_unspec_address (op));
9211 break;
9216 /* Implement TARGET_PRINT_OPERAND_ADDRESS. */
9218 static void
9219 mips_print_operand_address (FILE *file, rtx x)
9221 struct mips_address_info addr;
9223 if (mips_classify_address (&addr, x, word_mode, true))
9224 switch (addr.type)
9226 case ADDRESS_REG:
9227 mips_print_operand (file, addr.offset, 0);
9228 fprintf (file, "(%s)", reg_names[REGNO (addr.reg)]);
9229 return;
9231 case ADDRESS_LO_SUM:
9232 mips_print_operand_reloc (file, addr.offset, SYMBOL_CONTEXT_MEM,
9233 mips_lo_relocs);
9234 fprintf (file, "(%s)", reg_names[REGNO (addr.reg)]);
9235 return;
9237 case ADDRESS_CONST_INT:
9238 output_addr_const (file, x);
9239 fprintf (file, "(%s)", reg_names[GP_REG_FIRST]);
9240 return;
9242 case ADDRESS_SYMBOLIC:
9243 output_addr_const (file, mips_strip_unspec_address (x));
9244 return;
9246 gcc_unreachable ();
9249 /* Implement TARGET_ENCODE_SECTION_INFO. */
9251 static void
9252 mips_encode_section_info (tree decl, rtx rtl, int first)
9254 default_encode_section_info (decl, rtl, first);
9256 if (TREE_CODE (decl) == FUNCTION_DECL)
9258 rtx symbol = XEXP (rtl, 0);
9259 tree type = TREE_TYPE (decl);
9261 /* Encode whether the symbol is short or long. */
9262 if ((TARGET_LONG_CALLS && !mips_near_type_p (type))
9263 || mips_far_type_p (type))
9264 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LONG_CALL;
9268 /* Implement TARGET_SELECT_RTX_SECTION. */
9270 static section *
9271 mips_select_rtx_section (machine_mode mode, rtx x,
9272 unsigned HOST_WIDE_INT align)
9274 /* ??? Consider using mergeable small data sections. */
9275 if (mips_rtx_constant_in_small_data_p (mode))
9276 return get_named_section (NULL, ".sdata", 0);
9278 return default_elf_select_rtx_section (mode, x, align);
9281 /* Implement TARGET_ASM_FUNCTION_RODATA_SECTION.
9283 The complication here is that, with the combination TARGET_ABICALLS
9284 && !TARGET_ABSOLUTE_ABICALLS && !TARGET_GPWORD, jump tables will use
9285 absolute addresses, and should therefore not be included in the
9286 read-only part of a DSO. Handle such cases by selecting a normal
9287 data section instead of a read-only one. The logic apes that in
9288 default_function_rodata_section. */
9290 static section *
9291 mips_function_rodata_section (tree decl)
9293 if (!TARGET_ABICALLS || TARGET_ABSOLUTE_ABICALLS || TARGET_GPWORD)
9294 return default_function_rodata_section (decl);
9296 if (decl && DECL_SECTION_NAME (decl))
9298 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
9299 if (DECL_ONE_ONLY (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
9301 char *rname = ASTRDUP (name);
9302 rname[14] = 'd';
9303 return get_section (rname, SECTION_LINKONCE | SECTION_WRITE, decl);
9305 else if (flag_function_sections
9306 && flag_data_sections
9307 && strncmp (name, ".text.", 6) == 0)
9309 char *rname = ASTRDUP (name);
9310 memcpy (rname + 1, "data", 4);
9311 return get_section (rname, SECTION_WRITE, decl);
9314 return data_section;
9317 /* Implement TARGET_IN_SMALL_DATA_P. */
9319 static bool
9320 mips_in_small_data_p (const_tree decl)
9322 unsigned HOST_WIDE_INT size;
9324 if (TREE_CODE (decl) == STRING_CST || TREE_CODE (decl) == FUNCTION_DECL)
9325 return false;
9327 /* We don't yet generate small-data references for -mabicalls
9328 or VxWorks RTP code. See the related -G handling in
9329 mips_option_override. */
9330 if (TARGET_ABICALLS || TARGET_VXWORKS_RTP)
9331 return false;
9333 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl) != 0)
9335 const char *name;
9337 /* Reject anything that isn't in a known small-data section. */
9338 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
9339 if (strcmp (name, ".sdata") != 0 && strcmp (name, ".sbss") != 0)
9340 return false;
9342 /* If a symbol is defined externally, the assembler will use the
9343 usual -G rules when deciding how to implement macros. */
9344 if (mips_lo_relocs[SYMBOL_GP_RELATIVE] || !DECL_EXTERNAL (decl))
9345 return true;
9347 else if (TARGET_EMBEDDED_DATA)
9349 /* Don't put constants into the small data section: we want them
9350 to be in ROM rather than RAM. */
9351 if (TREE_CODE (decl) != VAR_DECL)
9352 return false;
9354 if (TREE_READONLY (decl)
9355 && !TREE_SIDE_EFFECTS (decl)
9356 && (!DECL_INITIAL (decl) || TREE_CONSTANT (DECL_INITIAL (decl))))
9357 return false;
9360 /* Enforce -mlocal-sdata. */
9361 if (!TARGET_LOCAL_SDATA && !TREE_PUBLIC (decl))
9362 return false;
9364 /* Enforce -mextern-sdata. */
9365 if (!TARGET_EXTERN_SDATA && DECL_P (decl))
9367 if (DECL_EXTERNAL (decl))
9368 return false;
9369 if (DECL_COMMON (decl) && DECL_INITIAL (decl) == NULL)
9370 return false;
9373 /* We have traditionally not treated zero-sized objects as small data,
9374 so this is now effectively part of the ABI. */
9375 size = int_size_in_bytes (TREE_TYPE (decl));
9376 return size > 0 && size <= mips_small_data_threshold;
9379 /* Implement TARGET_USE_ANCHORS_FOR_SYMBOL_P. We don't want to use
9380 anchors for small data: the GP register acts as an anchor in that
9381 case. We also don't want to use them for PC-relative accesses,
9382 where the PC acts as an anchor. */
9384 static bool
9385 mips_use_anchors_for_symbol_p (const_rtx symbol)
9387 switch (mips_classify_symbol (symbol, SYMBOL_CONTEXT_MEM))
9389 case SYMBOL_PC_RELATIVE:
9390 case SYMBOL_GP_RELATIVE:
9391 return false;
9393 default:
9394 return default_use_anchors_for_symbol_p (symbol);
9398 /* The MIPS debug format wants all automatic variables and arguments
9399 to be in terms of the virtual frame pointer (stack pointer before
9400 any adjustment in the function), while the MIPS 3.0 linker wants
9401 the frame pointer to be the stack pointer after the initial
9402 adjustment. So, we do the adjustment here. The arg pointer (which
9403 is eliminated) points to the virtual frame pointer, while the frame
9404 pointer (which may be eliminated) points to the stack pointer after
9405 the initial adjustments. */
9407 HOST_WIDE_INT
9408 mips_debugger_offset (rtx addr, HOST_WIDE_INT offset)
9410 rtx offset2 = const0_rtx;
9411 rtx reg = eliminate_constant_term (addr, &offset2);
9413 if (offset == 0)
9414 offset = INTVAL (offset2);
9416 if (reg == stack_pointer_rtx
9417 || reg == frame_pointer_rtx
9418 || reg == hard_frame_pointer_rtx)
9420 offset -= cfun->machine->frame.total_size;
9421 if (reg == hard_frame_pointer_rtx)
9422 offset += cfun->machine->frame.hard_frame_pointer_offset;
9425 return offset;
9428 /* Implement ASM_OUTPUT_EXTERNAL. */
9430 void
9431 mips_output_external (FILE *file, tree decl, const char *name)
9433 default_elf_asm_output_external (file, decl, name);
9435 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
9436 set in order to avoid putting out names that are never really
9437 used. */
9438 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
9440 if (!TARGET_EXPLICIT_RELOCS && mips_in_small_data_p (decl))
9442 /* When using assembler macros, emit .extern directives for
9443 all small-data externs so that the assembler knows how
9444 big they are.
9446 In most cases it would be safe (though pointless) to emit
9447 .externs for other symbols too. One exception is when an
9448 object is within the -G limit but declared by the user to
9449 be in a section other than .sbss or .sdata. */
9450 fputs ("\t.extern\t", file);
9451 assemble_name (file, name);
9452 fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n",
9453 int_size_in_bytes (TREE_TYPE (decl)));
9458 /* Implement TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
9460 static void
9461 mips_output_filename (FILE *stream, const char *name)
9463 /* If we are emitting DWARF-2, let dwarf2out handle the ".file"
9464 directives. */
9465 if (write_symbols == DWARF2_DEBUG)
9466 return;
9467 else if (mips_output_filename_first_time)
9469 mips_output_filename_first_time = 0;
9470 num_source_filenames += 1;
9471 current_function_file = name;
9472 fprintf (stream, "\t.file\t%d ", num_source_filenames);
9473 output_quoted_string (stream, name);
9474 putc ('\n', stream);
9476 /* If we are emitting stabs, let dbxout.c handle this (except for
9477 the mips_output_filename_first_time case). */
9478 else if (write_symbols == DBX_DEBUG)
9479 return;
9480 else if (name != current_function_file
9481 && strcmp (name, current_function_file) != 0)
9483 num_source_filenames += 1;
9484 current_function_file = name;
9485 fprintf (stream, "\t.file\t%d ", num_source_filenames);
9486 output_quoted_string (stream, name);
9487 putc ('\n', stream);
9491 /* Implement TARGET_ASM_OUTPUT_DWARF_DTPREL. */
9493 static void ATTRIBUTE_UNUSED
9494 mips_output_dwarf_dtprel (FILE *file, int size, rtx x)
9496 switch (size)
9498 case 4:
9499 fputs ("\t.dtprelword\t", file);
9500 break;
9502 case 8:
9503 fputs ("\t.dtpreldword\t", file);
9504 break;
9506 default:
9507 gcc_unreachable ();
9509 output_addr_const (file, x);
9510 fputs ("+0x8000", file);
9513 /* Implement TARGET_DWARF_REGISTER_SPAN. */
9515 static rtx
9516 mips_dwarf_register_span (rtx reg)
9518 rtx high, low;
9519 machine_mode mode;
9521 /* TARGET_FLOATXX is implemented as 32-bit floating-point registers but
9522 ensures that double-precision registers are treated as if they were
9523 64-bit physical registers. The code will run correctly with 32-bit or
9524 64-bit registers which means that dwarf information cannot be precise
9525 for all scenarios. We choose to state that the 64-bit values are stored
9526 in a single 64-bit 'piece'. This slightly unusual construct can then be
9527 interpreted as either a pair of registers if the registers are 32-bit or
9528 a single 64-bit register depending on hardware. */
9529 mode = GET_MODE (reg);
9530 if (FP_REG_P (REGNO (reg))
9531 && TARGET_FLOATXX
9532 && GET_MODE_SIZE (mode) > UNITS_PER_FPREG)
9534 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, reg));
9536 /* By default, GCC maps increasing register numbers to increasing
9537 memory locations, but paired FPRs are always little-endian,
9538 regardless of the prevailing endianness. */
9539 else if (FP_REG_P (REGNO (reg))
9540 && TARGET_BIG_ENDIAN
9541 && MAX_FPRS_PER_FMT > 1
9542 && GET_MODE_SIZE (mode) > UNITS_PER_FPREG)
9544 gcc_assert (GET_MODE_SIZE (mode) == UNITS_PER_HWFPVALUE);
9545 high = mips_subword (reg, true);
9546 low = mips_subword (reg, false);
9547 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, high, low));
9550 return NULL_RTX;
9553 /* Implement TARGET_DWARF_FRAME_REG_MODE. */
9555 static machine_mode
9556 mips_dwarf_frame_reg_mode (int regno)
9558 machine_mode mode = default_dwarf_frame_reg_mode (regno);
9560 if (FP_REG_P (regno) && mips_abi == ABI_32 && TARGET_FLOAT64)
9561 mode = SImode;
9563 return mode;
9566 /* DSP ALU can bypass data with no delays for the following pairs. */
9567 enum insn_code dspalu_bypass_table[][2] =
9569 {CODE_FOR_mips_addsc, CODE_FOR_mips_addwc},
9570 {CODE_FOR_mips_cmpu_eq_qb, CODE_FOR_mips_pick_qb},
9571 {CODE_FOR_mips_cmpu_lt_qb, CODE_FOR_mips_pick_qb},
9572 {CODE_FOR_mips_cmpu_le_qb, CODE_FOR_mips_pick_qb},
9573 {CODE_FOR_mips_cmp_eq_ph, CODE_FOR_mips_pick_ph},
9574 {CODE_FOR_mips_cmp_lt_ph, CODE_FOR_mips_pick_ph},
9575 {CODE_FOR_mips_cmp_le_ph, CODE_FOR_mips_pick_ph},
9576 {CODE_FOR_mips_wrdsp, CODE_FOR_mips_insv}
9580 mips_dspalu_bypass_p (rtx out_insn, rtx in_insn)
9582 int i;
9583 int num_bypass = ARRAY_SIZE (dspalu_bypass_table);
9584 enum insn_code out_icode = (enum insn_code) INSN_CODE (out_insn);
9585 enum insn_code in_icode = (enum insn_code) INSN_CODE (in_insn);
9587 for (i = 0; i < num_bypass; i++)
9589 if (out_icode == dspalu_bypass_table[i][0]
9590 && in_icode == dspalu_bypass_table[i][1])
9591 return true;
9594 return false;
9596 /* Implement ASM_OUTPUT_ASCII. */
9598 void
9599 mips_output_ascii (FILE *stream, const char *string, size_t len)
9601 size_t i;
9602 int cur_pos;
9604 cur_pos = 17;
9605 fprintf (stream, "\t.ascii\t\"");
9606 for (i = 0; i < len; i++)
9608 int c;
9610 c = (unsigned char) string[i];
9611 if (ISPRINT (c))
9613 if (c == '\\' || c == '\"')
9615 putc ('\\', stream);
9616 cur_pos++;
9618 putc (c, stream);
9619 cur_pos++;
9621 else
9623 fprintf (stream, "\\%03o", c);
9624 cur_pos += 4;
9627 if (cur_pos > 72 && i+1 < len)
9629 cur_pos = 17;
9630 fprintf (stream, "\"\n\t.ascii\t\"");
9633 fprintf (stream, "\"\n");
9636 /* Return the pseudo-op for full SYMBOL_(D)TPREL address *ADDR.
9637 Update *ADDR with the operand that should be printed. */
9639 const char *
9640 mips_output_tls_reloc_directive (rtx *addr)
9642 enum mips_symbol_type type;
9644 type = mips_classify_symbolic_expression (*addr, SYMBOL_CONTEXT_LEA);
9645 *addr = mips_strip_unspec_address (*addr);
9646 switch (type)
9648 case SYMBOL_DTPREL:
9649 return Pmode == SImode ? ".dtprelword\t%0" : ".dtpreldword\t%0";
9651 case SYMBOL_TPREL:
9652 return Pmode == SImode ? ".tprelword\t%0" : ".tpreldword\t%0";
9654 default:
9655 gcc_unreachable ();
9659 /* Emit either a label, .comm, or .lcomm directive. When using assembler
9660 macros, mark the symbol as written so that mips_asm_output_external
9661 won't emit an .extern for it. STREAM is the output file, NAME is the
9662 name of the symbol, INIT_STRING is the string that should be written
9663 before the symbol and FINAL_STRING is the string that should be
9664 written after it. FINAL_STRING is a printf format that consumes the
9665 remaining arguments. */
9667 void
9668 mips_declare_object (FILE *stream, const char *name, const char *init_string,
9669 const char *final_string, ...)
9671 va_list ap;
9673 fputs (init_string, stream);
9674 assemble_name (stream, name);
9675 va_start (ap, final_string);
9676 vfprintf (stream, final_string, ap);
9677 va_end (ap);
9679 if (!TARGET_EXPLICIT_RELOCS)
9681 tree name_tree = get_identifier (name);
9682 TREE_ASM_WRITTEN (name_tree) = 1;
9686 /* Declare a common object of SIZE bytes using asm directive INIT_STRING.
9687 NAME is the name of the object and ALIGN is the required alignment
9688 in bytes. TAKES_ALIGNMENT_P is true if the directive takes a third
9689 alignment argument. */
9691 void
9692 mips_declare_common_object (FILE *stream, const char *name,
9693 const char *init_string,
9694 unsigned HOST_WIDE_INT size,
9695 unsigned int align, bool takes_alignment_p)
9697 if (!takes_alignment_p)
9699 size += (align / BITS_PER_UNIT) - 1;
9700 size -= size % (align / BITS_PER_UNIT);
9701 mips_declare_object (stream, name, init_string,
9702 "," HOST_WIDE_INT_PRINT_UNSIGNED "\n", size);
9704 else
9705 mips_declare_object (stream, name, init_string,
9706 "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
9707 size, align / BITS_PER_UNIT);
9710 /* Implement ASM_OUTPUT_ALIGNED_DECL_COMMON. This is usually the same as the
9711 elfos.h version, but we also need to handle -muninit-const-in-rodata. */
9713 void
9714 mips_output_aligned_decl_common (FILE *stream, tree decl, const char *name,
9715 unsigned HOST_WIDE_INT size,
9716 unsigned int align)
9718 /* If the target wants uninitialized const declarations in
9719 .rdata then don't put them in .comm. */
9720 if (TARGET_EMBEDDED_DATA
9721 && TARGET_UNINIT_CONST_IN_RODATA
9722 && TREE_CODE (decl) == VAR_DECL
9723 && TREE_READONLY (decl)
9724 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
9726 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
9727 targetm.asm_out.globalize_label (stream, name);
9729 switch_to_section (readonly_data_section);
9730 ASM_OUTPUT_ALIGN (stream, floor_log2 (align / BITS_PER_UNIT));
9731 mips_declare_object (stream, name, "",
9732 ":\n\t.space\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n",
9733 size);
9735 else
9736 mips_declare_common_object (stream, name, "\n\t.comm\t",
9737 size, align, true);
9740 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE
9741 extern int size_directive_output;
9743 /* Implement ASM_DECLARE_OBJECT_NAME. This is like most of the standard ELF
9744 definitions except that it uses mips_declare_object to emit the label. */
9746 void
9747 mips_declare_object_name (FILE *stream, const char *name,
9748 tree decl ATTRIBUTE_UNUSED)
9750 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE
9751 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object");
9752 #endif
9754 size_directive_output = 0;
9755 if (!flag_inhibit_size_directive && DECL_SIZE (decl))
9757 HOST_WIDE_INT size;
9759 size_directive_output = 1;
9760 size = int_size_in_bytes (TREE_TYPE (decl));
9761 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
9764 mips_declare_object (stream, name, "", ":\n");
9767 /* Implement ASM_FINISH_DECLARE_OBJECT. This is generic ELF stuff. */
9769 void
9770 mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end)
9772 const char *name;
9774 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
9775 if (!flag_inhibit_size_directive
9776 && DECL_SIZE (decl) != 0
9777 && !at_end
9778 && top_level
9779 && DECL_INITIAL (decl) == error_mark_node
9780 && !size_directive_output)
9782 HOST_WIDE_INT size;
9784 size_directive_output = 1;
9785 size = int_size_in_bytes (TREE_TYPE (decl));
9786 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size);
9789 #endif
9791 /* Return the FOO in the name of the ".mdebug.FOO" section associated
9792 with the current ABI. */
9794 static const char *
9795 mips_mdebug_abi_name (void)
9797 switch (mips_abi)
9799 case ABI_32:
9800 return "abi32";
9801 case ABI_O64:
9802 return "abiO64";
9803 case ABI_N32:
9804 return "abiN32";
9805 case ABI_64:
9806 return "abi64";
9807 case ABI_EABI:
9808 return TARGET_64BIT ? "eabi64" : "eabi32";
9809 default:
9810 gcc_unreachable ();
9814 /* Implement TARGET_ASM_FILE_START. */
9816 static void
9817 mips_file_start (void)
9819 default_file_start ();
9821 /* Generate a special section to describe the ABI switches used to
9822 produce the resultant binary. */
9824 /* Record the ABI itself. Modern versions of binutils encode
9825 this information in the ELF header flags, but GDB needs the
9826 information in order to correctly debug binaries produced by
9827 older binutils. See the function mips_gdbarch_init in
9828 gdb/mips-tdep.c. */
9829 fprintf (asm_out_file, "\t.section .mdebug.%s\n\t.previous\n",
9830 mips_mdebug_abi_name ());
9832 /* There is no ELF header flag to distinguish long32 forms of the
9833 EABI from long64 forms. Emit a special section to help tools
9834 such as GDB. Do the same for o64, which is sometimes used with
9835 -mlong64. */
9836 if (mips_abi == ABI_EABI || mips_abi == ABI_O64)
9837 fprintf (asm_out_file, "\t.section .gcc_compiled_long%d\n"
9838 "\t.previous\n", TARGET_LONG64 ? 64 : 32);
9840 /* Record the NaN encoding. */
9841 if (HAVE_AS_NAN || mips_nan != MIPS_IEEE_754_DEFAULT)
9842 fprintf (asm_out_file, "\t.nan\t%s\n",
9843 mips_nan == MIPS_IEEE_754_2008 ? "2008" : "legacy");
9845 #ifdef HAVE_AS_DOT_MODULE
9846 /* Record the FP ABI. See below for comments. */
9847 if (TARGET_NO_FLOAT)
9848 #ifdef HAVE_AS_GNU_ATTRIBUTE
9849 fputs ("\t.gnu_attribute 4, 0\n", asm_out_file);
9850 #else
9852 #endif
9853 else if (!TARGET_HARD_FLOAT_ABI)
9854 fputs ("\t.module\tsoftfloat\n", asm_out_file);
9855 else if (!TARGET_DOUBLE_FLOAT)
9856 fputs ("\t.module\tsinglefloat\n", asm_out_file);
9857 else if (TARGET_FLOATXX)
9858 fputs ("\t.module\tfp=xx\n", asm_out_file);
9859 else if (TARGET_FLOAT64)
9860 fputs ("\t.module\tfp=64\n", asm_out_file);
9861 else
9862 fputs ("\t.module\tfp=32\n", asm_out_file);
9864 if (TARGET_ODD_SPREG)
9865 fputs ("\t.module\toddspreg\n", asm_out_file);
9866 else
9867 fputs ("\t.module\tnooddspreg\n", asm_out_file);
9869 #else
9870 #ifdef HAVE_AS_GNU_ATTRIBUTE
9872 int attr;
9874 /* No floating-point operations, -mno-float. */
9875 if (TARGET_NO_FLOAT)
9876 attr = 0;
9877 /* Soft-float code, -msoft-float. */
9878 else if (!TARGET_HARD_FLOAT_ABI)
9879 attr = 3;
9880 /* Single-float code, -msingle-float. */
9881 else if (!TARGET_DOUBLE_FLOAT)
9882 attr = 2;
9883 /* 64-bit FP registers on a 32-bit target, -mips32r2 -mfp64.
9884 Reserved attr=4.
9885 This case used 12 callee-saved double-precision registers
9886 and is deprecated. */
9887 /* 64-bit or 32-bit FP registers on a 32-bit target, -mfpxx. */
9888 else if (TARGET_FLOATXX)
9889 attr = 5;
9890 /* 64-bit FP registers on a 32-bit target, -mfp64 -modd-spreg. */
9891 else if (mips_abi == ABI_32 && TARGET_FLOAT64 && TARGET_ODD_SPREG)
9892 attr = 6;
9893 /* 64-bit FP registers on a 32-bit target, -mfp64 -mno-odd-spreg. */
9894 else if (mips_abi == ABI_32 && TARGET_FLOAT64)
9895 attr = 7;
9896 /* Regular FP code, FP regs same size as GP regs, -mdouble-float. */
9897 else
9898 attr = 1;
9900 fprintf (asm_out_file, "\t.gnu_attribute 4, %d\n", attr);
9902 /* 128-bit MSA. */
9903 if (TARGET_MSA)
9904 fprintf (asm_out_file, "\t.gnu_attribute 8, 1\n");
9906 #endif
9907 #endif
9909 /* If TARGET_ABICALLS, tell GAS to generate -KPIC code. */
9910 if (TARGET_ABICALLS)
9912 fprintf (asm_out_file, "\t.abicalls\n");
9913 if (TARGET_ABICALLS_PIC0)
9914 fprintf (asm_out_file, "\t.option\tpic0\n");
9917 if (flag_verbose_asm)
9918 fprintf (asm_out_file, "\n%s -G value = %d, Arch = %s, ISA = %d\n",
9919 ASM_COMMENT_START,
9920 mips_small_data_threshold, mips_arch_info->name, mips_isa);
9923 /* Implement TARGET_ASM_CODE_END. */
9925 static void
9926 mips_code_end (void)
9928 mips_finish_stub (&mips16_rdhwr_stub);
9929 mips_finish_stub (&mips16_get_fcsr_stub);
9930 mips_finish_stub (&mips16_set_fcsr_stub);
9933 /* Make the last instruction frame-related and note that it performs
9934 the operation described by FRAME_PATTERN. */
9936 static void
9937 mips_set_frame_expr (rtx frame_pattern)
9939 rtx insn;
9941 insn = get_last_insn ();
9942 RTX_FRAME_RELATED_P (insn) = 1;
9943 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR,
9944 frame_pattern,
9945 REG_NOTES (insn));
9948 /* Return a frame-related rtx that stores REG at MEM.
9949 REG must be a single register. */
9951 static rtx
9952 mips_frame_set (rtx mem, rtx reg)
9954 rtx set;
9956 set = gen_rtx_SET (VOIDmode, mem, reg);
9957 RTX_FRAME_RELATED_P (set) = 1;
9959 return set;
9962 /* Record that the epilogue has restored call-saved register REG. */
9964 static void
9965 mips_add_cfa_restore (rtx reg)
9967 mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
9968 mips_epilogue.cfa_restores);
9971 /* If a MIPS16e SAVE or RESTORE instruction saves or restores register
9972 mips16e_s2_s8_regs[X], it must also save the registers in indexes
9973 X + 1 onwards. Likewise mips16e_a0_a3_regs. */
9974 static const unsigned char mips16e_s2_s8_regs[] = {
9975 30, 23, 22, 21, 20, 19, 18
9977 static const unsigned char mips16e_a0_a3_regs[] = {
9978 4, 5, 6, 7
9981 /* A list of the registers that can be saved by the MIPS16e SAVE instruction,
9982 ordered from the uppermost in memory to the lowest in memory. */
9983 static const unsigned char mips16e_save_restore_regs[] = {
9984 31, 30, 23, 22, 21, 20, 19, 18, 17, 16, 7, 6, 5, 4
9987 /* Return the index of the lowest X in the range [0, SIZE) for which
9988 bit REGS[X] is set in MASK. Return SIZE if there is no such X. */
9990 static unsigned int
9991 mips16e_find_first_register (unsigned int mask, const unsigned char *regs,
9992 unsigned int size)
9994 unsigned int i;
9996 for (i = 0; i < size; i++)
9997 if (BITSET_P (mask, regs[i]))
9998 break;
10000 return i;
10003 /* *MASK_PTR is a mask of general-purpose registers and *NUM_REGS_PTR
10004 is the number of set bits. If *MASK_PTR contains REGS[X] for some X
10005 in [0, SIZE), adjust *MASK_PTR and *NUM_REGS_PTR so that the same
10006 is true for all indexes (X, SIZE). */
10008 static void
10009 mips16e_mask_registers (unsigned int *mask_ptr, const unsigned char *regs,
10010 unsigned int size, unsigned int *num_regs_ptr)
10012 unsigned int i;
10014 i = mips16e_find_first_register (*mask_ptr, regs, size);
10015 for (i++; i < size; i++)
10016 if (!BITSET_P (*mask_ptr, regs[i]))
10018 *num_regs_ptr += 1;
10019 *mask_ptr |= 1 << regs[i];
10023 /* Return a simplified form of X using the register values in REG_VALUES.
10024 REG_VALUES[R] is the last value assigned to hard register R, or null
10025 if R has not been modified.
10027 This function is rather limited, but is good enough for our purposes. */
10029 static rtx
10030 mips16e_collect_propagate_value (rtx x, rtx *reg_values)
10032 x = avoid_constant_pool_reference (x);
10034 if (UNARY_P (x))
10036 rtx x0 = mips16e_collect_propagate_value (XEXP (x, 0), reg_values);
10037 return simplify_gen_unary (GET_CODE (x), GET_MODE (x),
10038 x0, GET_MODE (XEXP (x, 0)));
10041 if (ARITHMETIC_P (x))
10043 rtx x0 = mips16e_collect_propagate_value (XEXP (x, 0), reg_values);
10044 rtx x1 = mips16e_collect_propagate_value (XEXP (x, 1), reg_values);
10045 return simplify_gen_binary (GET_CODE (x), GET_MODE (x), x0, x1);
10048 if (REG_P (x)
10049 && reg_values[REGNO (x)]
10050 && !rtx_unstable_p (reg_values[REGNO (x)]))
10051 return reg_values[REGNO (x)];
10053 return x;
10056 /* Return true if (set DEST SRC) stores an argument register into its
10057 caller-allocated save slot, storing the number of that argument
10058 register in *REGNO_PTR if so. REG_VALUES is as for
10059 mips16e_collect_propagate_value. */
10061 static bool
10062 mips16e_collect_argument_save_p (rtx dest, rtx src, rtx *reg_values,
10063 unsigned int *regno_ptr)
10065 unsigned int argno, regno;
10066 HOST_WIDE_INT offset, required_offset;
10067 rtx addr, base;
10069 /* Check that this is a word-mode store. */
10070 if (!MEM_P (dest) || !REG_P (src) || GET_MODE (dest) != word_mode)
10071 return false;
10073 /* Check that the register being saved is an unmodified argument
10074 register. */
10075 regno = REGNO (src);
10076 if (!IN_RANGE (regno, GP_ARG_FIRST, GP_ARG_LAST) || reg_values[regno])
10077 return false;
10078 argno = regno - GP_ARG_FIRST;
10080 /* Check whether the address is an appropriate stack-pointer or
10081 frame-pointer access. */
10082 addr = mips16e_collect_propagate_value (XEXP (dest, 0), reg_values);
10083 mips_split_plus (addr, &base, &offset);
10084 required_offset = cfun->machine->frame.total_size + argno * UNITS_PER_WORD;
10085 if (base == hard_frame_pointer_rtx)
10086 required_offset -= cfun->machine->frame.hard_frame_pointer_offset;
10087 else if (base != stack_pointer_rtx)
10088 return false;
10089 if (offset != required_offset)
10090 return false;
10092 *regno_ptr = regno;
10093 return true;
10096 /* A subroutine of mips_expand_prologue, called only when generating
10097 MIPS16e SAVE instructions. Search the start of the function for any
10098 instructions that save argument registers into their caller-allocated
10099 save slots. Delete such instructions and return a value N such that
10100 saving [GP_ARG_FIRST, GP_ARG_FIRST + N) would make all the deleted
10101 instructions redundant. */
10103 static unsigned int
10104 mips16e_collect_argument_saves (void)
10106 rtx reg_values[FIRST_PSEUDO_REGISTER];
10107 rtx insn, next, set, dest, src;
10108 unsigned int nargs, regno;
10110 push_topmost_sequence ();
10111 nargs = 0;
10112 memset (reg_values, 0, sizeof (reg_values));
10113 for (insn = get_insns (); insn; insn = next)
10115 next = NEXT_INSN (insn);
10116 if (NOTE_P (insn) || DEBUG_INSN_P (insn))
10117 continue;
10119 if (!INSN_P (insn))
10120 break;
10122 set = PATTERN (insn);
10123 if (GET_CODE (set) != SET)
10124 break;
10126 dest = SET_DEST (set);
10127 src = SET_SRC (set);
10128 if (mips16e_collect_argument_save_p (dest, src, reg_values, &regno))
10130 if (!BITSET_P (cfun->machine->frame.mask, regno))
10132 delete_insn (insn);
10133 nargs = MAX (nargs, (regno - GP_ARG_FIRST) + 1);
10136 else if (REG_P (dest) && GET_MODE (dest) == word_mode)
10137 reg_values[REGNO (dest)]
10138 = mips16e_collect_propagate_value (src, reg_values);
10139 else
10140 break;
10142 pop_topmost_sequence ();
10144 return nargs;
10147 /* Return a move between register REGNO and memory location SP + OFFSET.
10148 REG_PARM_P is true if SP + OFFSET belongs to REG_PARM_STACK_SPACE.
10149 Make the move a load if RESTORE_P, otherwise make it a store. */
10151 static rtx
10152 mips16e_save_restore_reg (bool restore_p, bool reg_parm_p,
10153 HOST_WIDE_INT offset, unsigned int regno)
10155 rtx reg, mem;
10157 mem = gen_frame_mem (SImode, plus_constant (Pmode, stack_pointer_rtx,
10158 offset));
10159 reg = gen_rtx_REG (SImode, regno);
10160 if (restore_p)
10162 mips_add_cfa_restore (reg);
10163 return gen_rtx_SET (VOIDmode, reg, mem);
10165 if (reg_parm_p)
10166 return gen_rtx_SET (VOIDmode, mem, reg);
10167 return mips_frame_set (mem, reg);
10170 /* Return RTL for a MIPS16e SAVE or RESTORE instruction; RESTORE_P says which.
10171 The instruction must:
10173 - Allocate or deallocate SIZE bytes in total; SIZE is known
10174 to be nonzero.
10176 - Save or restore as many registers in *MASK_PTR as possible.
10177 The instruction saves the first registers at the top of the
10178 allocated area, with the other registers below it.
10180 - Save NARGS argument registers above the allocated area.
10182 (NARGS is always zero if RESTORE_P.)
10184 The SAVE and RESTORE instructions cannot save and restore all general
10185 registers, so there may be some registers left over for the caller to
10186 handle. Destructively modify *MASK_PTR so that it contains the registers
10187 that still need to be saved or restored. The caller can save these
10188 registers in the memory immediately below *OFFSET_PTR, which is a
10189 byte offset from the bottom of the allocated stack area. */
10191 static rtx
10192 mips16e_build_save_restore (bool restore_p, unsigned int *mask_ptr,
10193 HOST_WIDE_INT *offset_ptr, unsigned int nargs,
10194 HOST_WIDE_INT size)
10196 rtx pattern, set;
10197 HOST_WIDE_INT offset, top_offset;
10198 unsigned int i, regno;
10199 int n;
10201 gcc_assert (cfun->machine->frame.num_fp == 0);
10203 /* Calculate the number of elements in the PARALLEL. We need one element
10204 for the stack adjustment, one for each argument register save, and one
10205 for each additional register move. */
10206 n = 1 + nargs;
10207 for (i = 0; i < ARRAY_SIZE (mips16e_save_restore_regs); i++)
10208 if (BITSET_P (*mask_ptr, mips16e_save_restore_regs[i]))
10209 n++;
10211 /* Create the final PARALLEL. */
10212 pattern = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (n));
10213 n = 0;
10215 /* Add the stack pointer adjustment. */
10216 set = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10217 plus_constant (Pmode, stack_pointer_rtx,
10218 restore_p ? size : -size));
10219 RTX_FRAME_RELATED_P (set) = 1;
10220 XVECEXP (pattern, 0, n++) = set;
10222 /* Stack offsets in the PARALLEL are relative to the old stack pointer. */
10223 top_offset = restore_p ? size : 0;
10225 /* Save the arguments. */
10226 for (i = 0; i < nargs; i++)
10228 offset = top_offset + i * UNITS_PER_WORD;
10229 set = mips16e_save_restore_reg (restore_p, true, offset,
10230 GP_ARG_FIRST + i);
10231 XVECEXP (pattern, 0, n++) = set;
10234 /* Then fill in the other register moves. */
10235 offset = top_offset;
10236 for (i = 0; i < ARRAY_SIZE (mips16e_save_restore_regs); i++)
10238 regno = mips16e_save_restore_regs[i];
10239 if (BITSET_P (*mask_ptr, regno))
10241 offset -= UNITS_PER_WORD;
10242 set = mips16e_save_restore_reg (restore_p, false, offset, regno);
10243 XVECEXP (pattern, 0, n++) = set;
10244 *mask_ptr &= ~(1 << regno);
10248 /* Tell the caller what offset it should use for the remaining registers. */
10249 *offset_ptr = size + (offset - top_offset);
10251 gcc_assert (n == XVECLEN (pattern, 0));
10253 return pattern;
10256 /* PATTERN is a PARALLEL whose first element adds ADJUST to the stack
10257 pointer. Return true if PATTERN matches the kind of instruction
10258 generated by mips16e_build_save_restore. If INFO is nonnull,
10259 initialize it when returning true. */
10261 bool
10262 mips16e_save_restore_pattern_p (rtx pattern, HOST_WIDE_INT adjust,
10263 struct mips16e_save_restore_info *info)
10265 unsigned int i, nargs, mask, extra;
10266 HOST_WIDE_INT top_offset, save_offset, offset;
10267 rtx set, reg, mem, base;
10268 int n;
10270 if (!GENERATE_MIPS16E_SAVE_RESTORE)
10271 return false;
10273 /* Stack offsets in the PARALLEL are relative to the old stack pointer. */
10274 top_offset = adjust > 0 ? adjust : 0;
10276 /* Interpret all other members of the PARALLEL. */
10277 save_offset = top_offset - UNITS_PER_WORD;
10278 mask = 0;
10279 nargs = 0;
10280 i = 0;
10281 for (n = 1; n < XVECLEN (pattern, 0); n++)
10283 /* Check that we have a SET. */
10284 set = XVECEXP (pattern, 0, n);
10285 if (GET_CODE (set) != SET)
10286 return false;
10288 /* Check that the SET is a load (if restoring) or a store
10289 (if saving). */
10290 mem = adjust > 0 ? SET_SRC (set) : SET_DEST (set);
10291 if (!MEM_P (mem))
10292 return false;
10294 /* Check that the address is the sum of the stack pointer and a
10295 possibly-zero constant offset. */
10296 mips_split_plus (XEXP (mem, 0), &base, &offset);
10297 if (base != stack_pointer_rtx)
10298 return false;
10300 /* Check that SET's other operand is a register. */
10301 reg = adjust > 0 ? SET_DEST (set) : SET_SRC (set);
10302 if (!REG_P (reg))
10303 return false;
10305 /* Check for argument saves. */
10306 if (offset == top_offset + nargs * UNITS_PER_WORD
10307 && REGNO (reg) == GP_ARG_FIRST + nargs)
10308 nargs++;
10309 else if (offset == save_offset)
10311 while (mips16e_save_restore_regs[i++] != REGNO (reg))
10312 if (i == ARRAY_SIZE (mips16e_save_restore_regs))
10313 return false;
10315 mask |= 1 << REGNO (reg);
10316 save_offset -= UNITS_PER_WORD;
10318 else
10319 return false;
10322 /* Check that the restrictions on register ranges are met. */
10323 extra = 0;
10324 mips16e_mask_registers (&mask, mips16e_s2_s8_regs,
10325 ARRAY_SIZE (mips16e_s2_s8_regs), &extra);
10326 mips16e_mask_registers (&mask, mips16e_a0_a3_regs,
10327 ARRAY_SIZE (mips16e_a0_a3_regs), &extra);
10328 if (extra != 0)
10329 return false;
10331 /* Make sure that the topmost argument register is not saved twice.
10332 The checks above ensure that the same is then true for the other
10333 argument registers. */
10334 if (nargs > 0 && BITSET_P (mask, GP_ARG_FIRST + nargs - 1))
10335 return false;
10337 /* Pass back information, if requested. */
10338 if (info)
10340 info->nargs = nargs;
10341 info->mask = mask;
10342 info->size = (adjust > 0 ? adjust : -adjust);
10345 return true;
10348 /* Add a MIPS16e SAVE or RESTORE register-range argument to string S
10349 for the register range [MIN_REG, MAX_REG]. Return a pointer to
10350 the null terminator. */
10352 static char *
10353 mips16e_add_register_range (char *s, unsigned int min_reg,
10354 unsigned int max_reg)
10356 if (min_reg != max_reg)
10357 s += sprintf (s, ",%s-%s", reg_names[min_reg], reg_names[max_reg]);
10358 else
10359 s += sprintf (s, ",%s", reg_names[min_reg]);
10360 return s;
10363 /* Return the assembly instruction for a MIPS16e SAVE or RESTORE instruction.
10364 PATTERN and ADJUST are as for mips16e_save_restore_pattern_p. */
10366 const char *
10367 mips16e_output_save_restore (rtx pattern, HOST_WIDE_INT adjust)
10369 static char buffer[300];
10371 struct mips16e_save_restore_info info;
10372 unsigned int i, end;
10373 char *s;
10375 /* Parse the pattern. */
10376 if (!mips16e_save_restore_pattern_p (pattern, adjust, &info))
10377 gcc_unreachable ();
10379 /* Add the mnemonic. */
10380 s = strcpy (buffer, adjust > 0 ? "restore\t" : "save\t");
10381 s += strlen (s);
10383 /* Save the arguments. */
10384 if (info.nargs > 1)
10385 s += sprintf (s, "%s-%s,", reg_names[GP_ARG_FIRST],
10386 reg_names[GP_ARG_FIRST + info.nargs - 1]);
10387 else if (info.nargs == 1)
10388 s += sprintf (s, "%s,", reg_names[GP_ARG_FIRST]);
10390 /* Emit the amount of stack space to allocate or deallocate. */
10391 s += sprintf (s, "%d", (int) info.size);
10393 /* Save or restore $16. */
10394 if (BITSET_P (info.mask, 16))
10395 s += sprintf (s, ",%s", reg_names[GP_REG_FIRST + 16]);
10397 /* Save or restore $17. */
10398 if (BITSET_P (info.mask, 17))
10399 s += sprintf (s, ",%s", reg_names[GP_REG_FIRST + 17]);
10401 /* Save or restore registers in the range $s2...$s8, which
10402 mips16e_s2_s8_regs lists in decreasing order. Note that this
10403 is a software register range; the hardware registers are not
10404 numbered consecutively. */
10405 end = ARRAY_SIZE (mips16e_s2_s8_regs);
10406 i = mips16e_find_first_register (info.mask, mips16e_s2_s8_regs, end);
10407 if (i < end)
10408 s = mips16e_add_register_range (s, mips16e_s2_s8_regs[end - 1],
10409 mips16e_s2_s8_regs[i]);
10411 /* Save or restore registers in the range $a0...$a3. */
10412 end = ARRAY_SIZE (mips16e_a0_a3_regs);
10413 i = mips16e_find_first_register (info.mask, mips16e_a0_a3_regs, end);
10414 if (i < end)
10415 s = mips16e_add_register_range (s, mips16e_a0_a3_regs[i],
10416 mips16e_a0_a3_regs[end - 1]);
10418 /* Save or restore $31. */
10419 if (BITSET_P (info.mask, RETURN_ADDR_REGNUM))
10420 s += sprintf (s, ",%s", reg_names[RETURN_ADDR_REGNUM]);
10422 return buffer;
10425 /* Return true if the current function returns its value in a floating-point
10426 register in MIPS16 mode. */
10428 static bool
10429 mips16_cfun_returns_in_fpr_p (void)
10431 tree return_type = DECL_RESULT (current_function_decl);
10432 return (TARGET_MIPS16
10433 && TARGET_HARD_FLOAT_ABI
10434 && !aggregate_value_p (return_type, current_function_decl)
10435 && mips_return_mode_in_fpr_p (DECL_MODE (return_type)));
10438 /* Return true if predicate PRED is true for at least one instruction.
10439 Cache the result in *CACHE, and assume that the result is true
10440 if *CACHE is already true. */
10442 static bool
10443 mips_find_gp_ref (bool *cache, bool (*pred) (rtx))
10445 rtx insn;
10447 if (!*cache)
10449 push_topmost_sequence ();
10450 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
10451 if (USEFUL_INSN_P (insn) && pred (insn))
10453 *cache = true;
10454 break;
10456 pop_topmost_sequence ();
10458 return *cache;
10461 /* Return true if INSN refers to the global pointer in an "inflexible" way.
10462 See mips_cfun_has_inflexible_gp_ref_p for details. */
10464 static bool
10465 mips_insn_has_inflexible_gp_ref_p (rtx insn)
10467 /* Uses of pic_offset_table_rtx in CALL_INSN_FUNCTION_USAGE
10468 indicate that the target could be a traditional MIPS
10469 lazily-binding stub. */
10470 return find_reg_fusage (insn, USE, pic_offset_table_rtx);
10473 /* Return true if the current function refers to the global pointer
10474 in a way that forces $28 to be valid. This means that we can't
10475 change the choice of global pointer, even for NewABI code.
10477 One example of this (and one which needs several checks) is that
10478 $28 must be valid when calling traditional MIPS lazy-binding stubs.
10479 (This restriction does not apply to PLTs.) */
10481 static bool
10482 mips_cfun_has_inflexible_gp_ref_p (void)
10484 /* If the function has a nonlocal goto, $28 must hold the correct
10485 global pointer for the target function. That is, the target
10486 of the goto implicitly uses $28. */
10487 if (crtl->has_nonlocal_goto)
10488 return true;
10490 if (TARGET_ABICALLS_PIC2)
10492 /* Symbolic accesses implicitly use the global pointer unless
10493 -mexplicit-relocs is in effect. JAL macros to symbolic addresses
10494 might go to traditional MIPS lazy-binding stubs. */
10495 if (!TARGET_EXPLICIT_RELOCS)
10496 return true;
10498 /* FUNCTION_PROFILER includes a JAL to _mcount, which again
10499 can be lazily-bound. */
10500 if (crtl->profile)
10501 return true;
10503 /* MIPS16 functions that return in FPRs need to call an
10504 external libgcc routine. This call is only made explict
10505 during mips_expand_epilogue, and it too might be lazily bound. */
10506 if (mips16_cfun_returns_in_fpr_p ())
10507 return true;
10510 return mips_find_gp_ref (&cfun->machine->has_inflexible_gp_insn_p,
10511 mips_insn_has_inflexible_gp_ref_p);
10514 /* Return true if INSN refers to the global pointer in a "flexible" way.
10515 See mips_cfun_has_flexible_gp_ref_p for details. */
10517 static bool
10518 mips_insn_has_flexible_gp_ref_p (rtx insn)
10520 return (get_attr_got (insn) != GOT_UNSET
10521 || mips_small_data_pattern_p (PATTERN (insn))
10522 || reg_overlap_mentioned_p (pic_offset_table_rtx, PATTERN (insn)));
10525 /* Return true if the current function references the global pointer,
10526 but if those references do not inherently require the global pointer
10527 to be $28. Assume !mips_cfun_has_inflexible_gp_ref_p (). */
10529 static bool
10530 mips_cfun_has_flexible_gp_ref_p (void)
10532 /* Reload can sometimes introduce constant pool references
10533 into a function that otherwise didn't need them. For example,
10534 suppose we have an instruction like:
10536 (set (reg:DF R1) (float:DF (reg:SI R2)))
10538 If R2 turns out to be a constant such as 1, the instruction may
10539 have a REG_EQUAL note saying that R1 == 1.0. Reload then has
10540 the option of using this constant if R2 doesn't get allocated
10541 to a register.
10543 In cases like these, reload will have added the constant to the
10544 pool but no instruction will yet refer to it. */
10545 if (TARGET_ABICALLS_PIC2 && !reload_completed && crtl->uses_const_pool)
10546 return true;
10548 return mips_find_gp_ref (&cfun->machine->has_flexible_gp_insn_p,
10549 mips_insn_has_flexible_gp_ref_p);
10552 /* Return the register that should be used as the global pointer
10553 within this function. Return INVALID_REGNUM if the function
10554 doesn't need a global pointer. */
10556 static unsigned int
10557 mips_global_pointer (void)
10559 unsigned int regno;
10561 /* $gp is always available unless we're using a GOT. */
10562 if (!TARGET_USE_GOT)
10563 return GLOBAL_POINTER_REGNUM;
10565 /* If there are inflexible references to $gp, we must use the
10566 standard register. */
10567 if (mips_cfun_has_inflexible_gp_ref_p ())
10568 return GLOBAL_POINTER_REGNUM;
10570 /* If there are no current references to $gp, then the only uses
10571 we can introduce later are those involved in long branches. */
10572 if (TARGET_ABSOLUTE_JUMPS && !mips_cfun_has_flexible_gp_ref_p ())
10573 return INVALID_REGNUM;
10575 /* If the global pointer is call-saved, try to use a call-clobbered
10576 alternative. */
10577 if (TARGET_CALL_SAVED_GP && crtl->is_leaf)
10578 for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
10579 if (!df_regs_ever_live_p (regno)
10580 && call_really_used_regs[regno]
10581 && !fixed_regs[regno]
10582 && regno != PIC_FUNCTION_ADDR_REGNUM)
10583 return regno;
10585 return GLOBAL_POINTER_REGNUM;
10588 /* Return true if the current function's prologue must load the global
10589 pointer value into pic_offset_table_rtx and store the same value in
10590 the function's cprestore slot (if any).
10592 One problem we have to deal with is that, when emitting GOT-based
10593 position independent code, long-branch sequences will need to load
10594 the address of the branch target from the GOT. We don't know until
10595 the very end of compilation whether (and where) the function needs
10596 long branches, so we must ensure that _any_ branch can access the
10597 global pointer in some form. However, we do not want to pessimize
10598 the usual case in which all branches are short.
10600 We handle this as follows:
10602 (1) During reload, we set cfun->machine->global_pointer to
10603 INVALID_REGNUM if we _know_ that the current function
10604 doesn't need a global pointer. This is only valid if
10605 long branches don't need the GOT.
10607 Otherwise, we assume that we might need a global pointer
10608 and pick an appropriate register.
10610 (2) If cfun->machine->global_pointer != INVALID_REGNUM,
10611 we ensure that the global pointer is available at every
10612 block boundary bar entry and exit. We do this in one of two ways:
10614 - If the function has a cprestore slot, we ensure that this
10615 slot is valid at every branch. However, as explained in
10616 point (6) below, there is no guarantee that pic_offset_table_rtx
10617 itself is valid if new uses of the global pointer are introduced
10618 after the first post-epilogue split.
10620 We guarantee that the cprestore slot is valid by loading it
10621 into a fake register, CPRESTORE_SLOT_REGNUM. We then make
10622 this register live at every block boundary bar function entry
10623 and exit. It is then invalid to move the load (and thus the
10624 preceding store) across a block boundary.
10626 - If the function has no cprestore slot, we guarantee that
10627 pic_offset_table_rtx itself is valid at every branch.
10629 See mips_eh_uses for the handling of the register liveness.
10631 (3) During prologue and epilogue generation, we emit "ghost"
10632 placeholder instructions to manipulate the global pointer.
10634 (4) During prologue generation, we set cfun->machine->must_initialize_gp_p
10635 and cfun->machine->must_restore_gp_when_clobbered_p if we already know
10636 that the function needs a global pointer. (There is no need to set
10637 them earlier than this, and doing it as late as possible leads to
10638 fewer false positives.)
10640 (5) If cfun->machine->must_initialize_gp_p is true during a
10641 split_insns pass, we split the ghost instructions into real
10642 instructions. These split instructions can then be optimized in
10643 the usual way. Otherwise, we keep the ghost instructions intact,
10644 and optimize for the case where they aren't needed. We still
10645 have the option of splitting them later, if we need to introduce
10646 new uses of the global pointer.
10648 For example, the scheduler ignores a ghost instruction that
10649 stores $28 to the stack, but it handles the split form of
10650 the ghost instruction as an ordinary store.
10652 (6) [OldABI only.] If cfun->machine->must_restore_gp_when_clobbered_p
10653 is true during the first post-epilogue split_insns pass, we split
10654 calls and restore_gp patterns into instructions that explicitly
10655 load pic_offset_table_rtx from the cprestore slot. Otherwise,
10656 we split these patterns into instructions that _don't_ load from
10657 the cprestore slot.
10659 If cfun->machine->must_restore_gp_when_clobbered_p is true at the
10660 time of the split, then any instructions that exist at that time
10661 can make free use of pic_offset_table_rtx. However, if we want
10662 to introduce new uses of the global pointer after the split,
10663 we must explicitly load the value from the cprestore slot, since
10664 pic_offset_table_rtx itself might not be valid at a given point
10665 in the function.
10667 The idea is that we want to be able to delete redundant
10668 loads from the cprestore slot in the usual case where no
10669 long branches are needed.
10671 (7) If cfun->machine->must_initialize_gp_p is still false at the end
10672 of md_reorg, we decide whether the global pointer is needed for
10673 long branches. If so, we set cfun->machine->must_initialize_gp_p
10674 to true and split the ghost instructions into real instructions
10675 at that stage.
10677 Note that the ghost instructions must have a zero length for three reasons:
10679 - Giving the length of the underlying $gp sequence might cause
10680 us to use long branches in cases where they aren't really needed.
10682 - They would perturb things like alignment calculations.
10684 - More importantly, the hazard detection in md_reorg relies on
10685 empty instructions having a zero length.
10687 If we find a long branch and split the ghost instructions at the
10688 end of md_reorg, the split could introduce more long branches.
10689 That isn't a problem though, because we still do the split before
10690 the final shorten_branches pass.
10692 This is extremely ugly, but it seems like the best compromise between
10693 correctness and efficiency. */
10695 bool
10696 mips_must_initialize_gp_p (void)
10698 return cfun->machine->must_initialize_gp_p;
10701 /* Return true if REGNO is a register that is ordinarily call-clobbered
10702 but must nevertheless be preserved by an interrupt handler. */
10704 static bool
10705 mips_interrupt_extra_call_saved_reg_p (unsigned int regno)
10707 if ((ISA_HAS_HILO || TARGET_DSP)
10708 && MD_REG_P (regno))
10709 return true;
10711 if (TARGET_DSP && DSP_ACC_REG_P (regno))
10712 return true;
10714 if (GP_REG_P (regno) && !cfun->machine->use_shadow_register_set_p)
10716 /* $0 is hard-wired. */
10717 if (regno == GP_REG_FIRST)
10718 return false;
10720 /* The interrupt handler can treat kernel registers as
10721 scratch registers. */
10722 if (KERNEL_REG_P (regno))
10723 return false;
10725 /* The function will return the stack pointer to its original value
10726 anyway. */
10727 if (regno == STACK_POINTER_REGNUM)
10728 return false;
10730 /* Otherwise, return true for registers that aren't ordinarily
10731 call-clobbered. */
10732 return call_really_used_regs[regno];
10735 return false;
10738 /* Return true if the current function should treat register REGNO
10739 as call-saved. */
10741 static bool
10742 mips_cfun_call_saved_reg_p (unsigned int regno)
10744 /* If the user makes an ordinarily-call-saved register global,
10745 that register is no longer call-saved. */
10746 if (global_regs[regno])
10747 return false;
10749 /* Interrupt handlers need to save extra registers. */
10750 if (cfun->machine->interrupt_handler_p
10751 && mips_interrupt_extra_call_saved_reg_p (regno))
10752 return true;
10754 /* call_insns preserve $28 unless they explicitly say otherwise,
10755 so call_really_used_regs[] treats $28 as call-saved. However,
10756 we want the ABI property rather than the default call_insn
10757 property here. */
10758 return (regno == GLOBAL_POINTER_REGNUM
10759 ? TARGET_CALL_SAVED_GP
10760 : !call_really_used_regs[regno]);
10763 /* Return true if the function body might clobber register REGNO.
10764 We know that REGNO is call-saved. */
10766 static bool
10767 mips_cfun_might_clobber_call_saved_reg_p (unsigned int regno)
10769 /* Some functions should be treated as clobbering all call-saved
10770 registers. */
10771 if (crtl->saves_all_registers)
10772 return true;
10774 /* DF handles cases where a register is explicitly referenced in
10775 the rtl. Incoming values are passed in call-clobbered registers,
10776 so we can assume that any live call-saved register is set within
10777 the function. */
10778 if (df_regs_ever_live_p (regno))
10779 return true;
10781 /* Check for registers that are clobbered by FUNCTION_PROFILER.
10782 These clobbers are not explicit in the rtl. */
10783 if (crtl->profile && MIPS_SAVE_REG_FOR_PROFILING_P (regno))
10784 return true;
10786 /* If we're using a call-saved global pointer, the function's
10787 prologue will need to set it up. */
10788 if (cfun->machine->global_pointer == regno)
10789 return true;
10791 /* The function's prologue will need to set the frame pointer if
10792 frame_pointer_needed. */
10793 if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed)
10794 return true;
10796 /* If a MIPS16 function returns a value in FPRs, its epilogue
10797 will need to call an external libgcc routine. This yet-to-be
10798 generated call_insn will clobber $31. */
10799 if (regno == RETURN_ADDR_REGNUM && mips16_cfun_returns_in_fpr_p ())
10800 return true;
10802 /* If REGNO is ordinarily call-clobbered, we must assume that any
10803 called function could modify it. */
10804 if (cfun->machine->interrupt_handler_p
10805 && !crtl->is_leaf
10806 && mips_interrupt_extra_call_saved_reg_p (regno))
10807 return true;
10809 return false;
10812 /* Return true if the current function must save register REGNO. */
10814 static bool
10815 mips_save_reg_p (unsigned int regno)
10817 if (mips_cfun_call_saved_reg_p (regno))
10819 if (mips_cfun_might_clobber_call_saved_reg_p (regno))
10820 return true;
10822 /* Save both registers in an FPR pair if either one is used. This is
10823 needed for the case when MIN_FPRS_PER_FMT == 1, which allows the odd
10824 register to be used without the even register. */
10825 if (FP_REG_P (regno)
10826 && MAX_FPRS_PER_FMT == 2
10827 && mips_cfun_might_clobber_call_saved_reg_p (regno + 1))
10828 return true;
10831 /* We need to save the incoming return address if __builtin_eh_return
10832 is being used to set a different return address. */
10833 if (regno == RETURN_ADDR_REGNUM && crtl->calls_eh_return)
10834 return true;
10836 return false;
10839 /* Populate the current function's mips_frame_info structure.
10841 MIPS stack frames look like:
10843 +-------------------------------+
10845 | incoming stack arguments |
10847 +-------------------------------+
10849 | caller-allocated save area |
10850 A | for register arguments |
10852 +-------------------------------+ <-- incoming stack pointer
10854 | callee-allocated save area |
10855 B | for arguments that are |
10856 | split between registers and |
10857 | the stack |
10859 +-------------------------------+ <-- arg_pointer_rtx
10861 C | callee-allocated save area |
10862 | for register varargs |
10864 +-------------------------------+ <-- frame_pointer_rtx
10865 | | + cop0_sp_offset
10866 | COP0 reg save area | + UNITS_PER_WORD
10868 +-------------------------------+ <-- frame_pointer_rtx + acc_sp_offset
10869 | | + UNITS_PER_WORD
10870 | accumulator save area |
10872 +-------------------------------+ <-- stack_pointer_rtx + fp_sp_offset
10873 | | + UNITS_PER_HWFPVALUE
10874 | FPR save area |
10876 +-------------------------------+ <-- stack_pointer_rtx + gp_sp_offset
10877 | | + UNITS_PER_WORD
10878 | GPR save area |
10880 +-------------------------------+ <-- frame_pointer_rtx with
10881 | | \ -fstack-protector
10882 | local variables | | var_size
10883 | | /
10884 +-------------------------------+
10885 | | \
10886 | $gp save area | | cprestore_size
10887 | | /
10888 P +-------------------------------+ <-- hard_frame_pointer_rtx for
10889 | | \ MIPS16 code
10890 | outgoing stack arguments | |
10891 | | |
10892 +-------------------------------+ | args_size
10893 | | |
10894 | caller-allocated save area | |
10895 | for register arguments | |
10896 | | /
10897 +-------------------------------+ <-- stack_pointer_rtx
10898 frame_pointer_rtx without
10899 -fstack-protector
10900 hard_frame_pointer_rtx for
10901 non-MIPS16 code.
10903 At least two of A, B and C will be empty.
10905 Dynamic stack allocations such as alloca insert data at point P.
10906 They decrease stack_pointer_rtx but leave frame_pointer_rtx and
10907 hard_frame_pointer_rtx unchanged. */
10909 static void
10910 mips_compute_frame_info (void)
10912 struct mips_frame_info *frame;
10913 HOST_WIDE_INT offset, size;
10914 unsigned int regno, i;
10916 /* Set this function's interrupt properties. */
10917 if (mips_interrupt_type_p (TREE_TYPE (current_function_decl)))
10919 if (mips_isa_rev < 2)
10920 error ("the %<interrupt%> attribute requires a MIPS32r2 processor or greater");
10921 else if (TARGET_MIPS16)
10922 error ("interrupt handlers cannot be MIPS16 functions");
10923 else
10925 cfun->machine->interrupt_handler_p = true;
10926 cfun->machine->use_shadow_register_set_p =
10927 mips_use_shadow_register_set_p (TREE_TYPE (current_function_decl));
10928 cfun->machine->keep_interrupts_masked_p =
10929 mips_keep_interrupts_masked_p (TREE_TYPE (current_function_decl));
10930 cfun->machine->use_debug_exception_return_p =
10931 mips_use_debug_exception_return_p (TREE_TYPE
10932 (current_function_decl));
10936 frame = &cfun->machine->frame;
10937 memset (frame, 0, sizeof (*frame));
10938 size = get_frame_size ();
10940 cfun->machine->global_pointer = mips_global_pointer ();
10942 /* The first two blocks contain the outgoing argument area and the $gp save
10943 slot. This area isn't needed in leaf functions, but if the
10944 target-independent frame size is nonzero, we have already committed to
10945 allocating these in STARTING_FRAME_OFFSET for !FRAME_GROWS_DOWNWARD. */
10946 if ((size == 0 || FRAME_GROWS_DOWNWARD) && crtl->is_leaf)
10948 /* The MIPS 3.0 linker does not like functions that dynamically
10949 allocate the stack and have 0 for STACK_DYNAMIC_OFFSET, since it
10950 looks like we are trying to create a second frame pointer to the
10951 function, so allocate some stack space to make it happy. */
10952 if (cfun->calls_alloca)
10953 frame->args_size = REG_PARM_STACK_SPACE (cfun->decl);
10954 else
10955 frame->args_size = 0;
10956 frame->cprestore_size = 0;
10958 else
10960 frame->args_size = crtl->outgoing_args_size;
10961 frame->cprestore_size = MIPS_GP_SAVE_AREA_SIZE;
10963 offset = frame->args_size + frame->cprestore_size;
10965 /* Move above the local variables. */
10966 frame->var_size = MIPS_STACK_ALIGN (size);
10967 offset += frame->var_size;
10969 /* Find out which GPRs we need to save. */
10970 for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++)
10971 if (mips_save_reg_p (regno))
10973 frame->num_gp++;
10974 frame->mask |= 1 << (regno - GP_REG_FIRST);
10977 /* If this function calls eh_return, we must also save and restore the
10978 EH data registers. */
10979 if (crtl->calls_eh_return)
10980 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; i++)
10982 frame->num_gp++;
10983 frame->mask |= 1 << (EH_RETURN_DATA_REGNO (i) - GP_REG_FIRST);
10986 /* The MIPS16e SAVE and RESTORE instructions have two ranges of registers:
10987 $a3-$a0 and $s2-$s8. If we save one register in the range, we must
10988 save all later registers too. */
10989 if (GENERATE_MIPS16E_SAVE_RESTORE)
10991 mips16e_mask_registers (&frame->mask, mips16e_s2_s8_regs,
10992 ARRAY_SIZE (mips16e_s2_s8_regs), &frame->num_gp);
10993 mips16e_mask_registers (&frame->mask, mips16e_a0_a3_regs,
10994 ARRAY_SIZE (mips16e_a0_a3_regs), &frame->num_gp);
10997 /* Move above the GPR save area. */
10998 if (frame->num_gp > 0)
11000 offset += MIPS_STACK_ALIGN (frame->num_gp * UNITS_PER_WORD);
11001 frame->gp_sp_offset = offset - UNITS_PER_WORD;
11004 /* Find out which FPRs we need to save. This loop must iterate over
11005 the same space as its companion in mips_for_each_saved_gpr_and_fpr. */
11006 if (TARGET_HARD_FLOAT)
11007 for (regno = FP_REG_FIRST; regno <= FP_REG_LAST; regno += MAX_FPRS_PER_FMT)
11008 if (mips_save_reg_p (regno))
11010 frame->num_fp += MAX_FPRS_PER_FMT;
11011 frame->fmask |= ~(~0 << MAX_FPRS_PER_FMT) << (regno - FP_REG_FIRST);
11014 /* Move above the FPR save area. */
11015 if (frame->num_fp > 0)
11017 offset += MIPS_STACK_ALIGN (frame->num_fp * UNITS_PER_FPREG);
11018 frame->fp_sp_offset = offset - UNITS_PER_HWFPVALUE;
11021 /* Add in space for the interrupt context information. */
11022 if (cfun->machine->interrupt_handler_p)
11024 /* Check HI/LO. */
11025 if (mips_save_reg_p (LO_REGNUM) || mips_save_reg_p (HI_REGNUM))
11027 frame->num_acc++;
11028 frame->acc_mask |= (1 << 0);
11031 /* Check accumulators 1, 2, 3. */
11032 for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2)
11033 if (mips_save_reg_p (i) || mips_save_reg_p (i + 1))
11035 frame->num_acc++;
11036 frame->acc_mask |= 1 << (((i - DSP_ACC_REG_FIRST) / 2) + 1);
11039 /* All interrupt context functions need space to preserve STATUS. */
11040 frame->num_cop0_regs++;
11042 /* If we don't keep interrupts masked, we need to save EPC. */
11043 if (!cfun->machine->keep_interrupts_masked_p)
11044 frame->num_cop0_regs++;
11047 /* Move above the accumulator save area. */
11048 if (frame->num_acc > 0)
11050 /* Each accumulator needs 2 words. */
11051 offset += frame->num_acc * 2 * UNITS_PER_WORD;
11052 frame->acc_sp_offset = offset - UNITS_PER_WORD;
11055 /* Move above the COP0 register save area. */
11056 if (frame->num_cop0_regs > 0)
11058 offset += frame->num_cop0_regs * UNITS_PER_WORD;
11059 frame->cop0_sp_offset = offset - UNITS_PER_WORD;
11062 /* Move above the callee-allocated varargs save area. */
11063 offset += MIPS_STACK_ALIGN (cfun->machine->varargs_size);
11064 frame->arg_pointer_offset = offset;
11066 /* Move above the callee-allocated area for pretend stack arguments. */
11067 offset += crtl->args.pretend_args_size;
11068 frame->total_size = offset;
11070 /* Work out the offsets of the save areas from the top of the frame. */
11071 if (frame->gp_sp_offset > 0)
11072 frame->gp_save_offset = frame->gp_sp_offset - offset;
11073 if (frame->fp_sp_offset > 0)
11074 frame->fp_save_offset = frame->fp_sp_offset - offset;
11075 if (frame->acc_sp_offset > 0)
11076 frame->acc_save_offset = frame->acc_sp_offset - offset;
11077 if (frame->num_cop0_regs > 0)
11078 frame->cop0_save_offset = frame->cop0_sp_offset - offset;
11080 /* MIPS16 code offsets the frame pointer by the size of the outgoing
11081 arguments. This tends to increase the chances of using unextended
11082 instructions for local variables and incoming arguments. */
11083 if (TARGET_MIPS16)
11084 frame->hard_frame_pointer_offset = frame->args_size;
11087 /* Return the style of GP load sequence that is being used for the
11088 current function. */
11090 enum mips_loadgp_style
11091 mips_current_loadgp_style (void)
11093 if (!TARGET_USE_GOT || cfun->machine->global_pointer == INVALID_REGNUM)
11094 return LOADGP_NONE;
11096 if (TARGET_RTP_PIC)
11097 return LOADGP_RTP;
11099 if (TARGET_ABSOLUTE_ABICALLS)
11100 return LOADGP_ABSOLUTE;
11102 return TARGET_NEWABI ? LOADGP_NEWABI : LOADGP_OLDABI;
11105 /* Implement TARGET_FRAME_POINTER_REQUIRED. */
11107 static bool
11108 mips_frame_pointer_required (void)
11110 /* If the function contains dynamic stack allocations, we need to
11111 use the frame pointer to access the static parts of the frame. */
11112 if (cfun->calls_alloca)
11113 return true;
11115 /* In MIPS16 mode, we need a frame pointer for a large frame; otherwise,
11116 reload may be unable to compute the address of a local variable,
11117 since there is no way to add a large constant to the stack pointer
11118 without using a second temporary register. */
11119 if (TARGET_MIPS16)
11121 mips_compute_frame_info ();
11122 if (!SMALL_OPERAND (cfun->machine->frame.total_size))
11123 return true;
11126 return false;
11129 /* Make sure that we're not trying to eliminate to the wrong hard frame
11130 pointer. */
11132 static bool
11133 mips_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
11135 return (to == HARD_FRAME_POINTER_REGNUM || to == STACK_POINTER_REGNUM);
11138 /* Implement INITIAL_ELIMINATION_OFFSET. FROM is either the frame pointer
11139 or argument pointer. TO is either the stack pointer or hard frame
11140 pointer. */
11142 HOST_WIDE_INT
11143 mips_initial_elimination_offset (int from, int to)
11145 HOST_WIDE_INT offset;
11147 mips_compute_frame_info ();
11149 /* Set OFFSET to the offset from the end-of-prologue stack pointer. */
11150 switch (from)
11152 case FRAME_POINTER_REGNUM:
11153 if (FRAME_GROWS_DOWNWARD)
11154 offset = (cfun->machine->frame.args_size
11155 + cfun->machine->frame.cprestore_size
11156 + cfun->machine->frame.var_size);
11157 else
11158 offset = 0;
11159 break;
11161 case ARG_POINTER_REGNUM:
11162 offset = cfun->machine->frame.arg_pointer_offset;
11163 break;
11165 default:
11166 gcc_unreachable ();
11169 if (to == HARD_FRAME_POINTER_REGNUM)
11170 offset -= cfun->machine->frame.hard_frame_pointer_offset;
11172 return offset;
11175 /* Implement TARGET_EXTRA_LIVE_ON_ENTRY. */
11177 static void
11178 mips_extra_live_on_entry (bitmap regs)
11180 if (TARGET_USE_GOT)
11182 /* PIC_FUNCTION_ADDR_REGNUM is live if we need it to set up
11183 the global pointer. */
11184 if (!TARGET_ABSOLUTE_ABICALLS)
11185 bitmap_set_bit (regs, PIC_FUNCTION_ADDR_REGNUM);
11187 /* The prologue may set MIPS16_PIC_TEMP_REGNUM to the value of
11188 the global pointer. */
11189 if (TARGET_MIPS16)
11190 bitmap_set_bit (regs, MIPS16_PIC_TEMP_REGNUM);
11192 /* See the comment above load_call<mode> for details. */
11193 bitmap_set_bit (regs, GOT_VERSION_REGNUM);
11197 /* Implement RETURN_ADDR_RTX. We do not support moving back to a
11198 previous frame. */
11201 mips_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
11203 if (count != 0)
11204 return const0_rtx;
11206 return get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM);
11209 /* Emit code to change the current function's return address to
11210 ADDRESS. SCRATCH is available as a scratch register, if needed.
11211 ADDRESS and SCRATCH are both word-mode GPRs. */
11213 void
11214 mips_set_return_address (rtx address, rtx scratch)
11216 rtx slot_address;
11218 gcc_assert (BITSET_P (cfun->machine->frame.mask, RETURN_ADDR_REGNUM));
11219 slot_address = mips_add_offset (scratch, stack_pointer_rtx,
11220 cfun->machine->frame.gp_sp_offset);
11221 mips_emit_move (gen_frame_mem (GET_MODE (address), slot_address), address);
11224 /* Return true if the current function has a cprestore slot. */
11226 bool
11227 mips_cfun_has_cprestore_slot_p (void)
11229 return (cfun->machine->global_pointer != INVALID_REGNUM
11230 && cfun->machine->frame.cprestore_size > 0);
11233 /* Fill *BASE and *OFFSET such that *BASE + *OFFSET refers to the
11234 cprestore slot. LOAD_P is true if the caller wants to load from
11235 the cprestore slot; it is false if the caller wants to store to
11236 the slot. */
11238 static void
11239 mips_get_cprestore_base_and_offset (rtx *base, HOST_WIDE_INT *offset,
11240 bool load_p)
11242 const struct mips_frame_info *frame;
11244 frame = &cfun->machine->frame;
11245 /* .cprestore always uses the stack pointer instead of the frame pointer.
11246 We have a free choice for direct stores for non-MIPS16 functions,
11247 and for MIPS16 functions whose cprestore slot is in range of the
11248 stack pointer. Using the stack pointer would sometimes give more
11249 (early) scheduling freedom, but using the frame pointer would
11250 sometimes give more (late) scheduling freedom. It's hard to
11251 predict which applies to a given function, so let's keep things
11252 simple.
11254 Loads must always use the frame pointer in functions that call
11255 alloca, and there's little benefit to using the stack pointer
11256 otherwise. */
11257 if (frame_pointer_needed && !(TARGET_CPRESTORE_DIRECTIVE && !load_p))
11259 *base = hard_frame_pointer_rtx;
11260 *offset = frame->args_size - frame->hard_frame_pointer_offset;
11262 else
11264 *base = stack_pointer_rtx;
11265 *offset = frame->args_size;
11269 /* Return true if X is the load or store address of the cprestore slot;
11270 LOAD_P says which. */
11272 bool
11273 mips_cprestore_address_p (rtx x, bool load_p)
11275 rtx given_base, required_base;
11276 HOST_WIDE_INT given_offset, required_offset;
11278 mips_split_plus (x, &given_base, &given_offset);
11279 mips_get_cprestore_base_and_offset (&required_base, &required_offset, load_p);
11280 return given_base == required_base && given_offset == required_offset;
11283 /* Return a MEM rtx for the cprestore slot. LOAD_P is true if we are
11284 going to load from it, false if we are going to store to it.
11285 Use TEMP as a temporary register if need be. */
11287 static rtx
11288 mips_cprestore_slot (rtx temp, bool load_p)
11290 rtx base;
11291 HOST_WIDE_INT offset;
11293 mips_get_cprestore_base_and_offset (&base, &offset, load_p);
11294 return gen_frame_mem (Pmode, mips_add_offset (temp, base, offset));
11297 /* Emit instructions to save global pointer value GP into cprestore
11298 slot MEM. OFFSET is the offset that MEM applies to the base register.
11300 MEM may not be a legitimate address. If it isn't, TEMP is a
11301 temporary register that can be used, otherwise it is a SCRATCH. */
11303 void
11304 mips_save_gp_to_cprestore_slot (rtx mem, rtx offset, rtx gp, rtx temp)
11306 if (TARGET_CPRESTORE_DIRECTIVE)
11308 gcc_assert (gp == pic_offset_table_rtx);
11309 emit_insn (PMODE_INSN (gen_cprestore, (mem, offset)));
11311 else
11312 mips_emit_move (mips_cprestore_slot (temp, false), gp);
11315 /* Restore $gp from its save slot, using TEMP as a temporary base register
11316 if need be. This function is for o32 and o64 abicalls only.
11318 See mips_must_initialize_gp_p for details about how we manage the
11319 global pointer. */
11321 void
11322 mips_restore_gp_from_cprestore_slot (rtx temp)
11324 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI && epilogue_completed);
11326 if (!cfun->machine->must_restore_gp_when_clobbered_p)
11328 emit_note (NOTE_INSN_DELETED);
11329 return;
11332 if (TARGET_MIPS16)
11334 mips_emit_move (temp, mips_cprestore_slot (temp, true));
11335 mips_emit_move (pic_offset_table_rtx, temp);
11337 else
11338 mips_emit_move (pic_offset_table_rtx, mips_cprestore_slot (temp, true));
11339 if (!TARGET_EXPLICIT_RELOCS)
11340 emit_insn (gen_blockage ());
11343 /* A function to save or store a register. The first argument is the
11344 register and the second is the stack slot. */
11345 typedef void (*mips_save_restore_fn) (rtx, rtx);
11347 /* Use FN to save or restore register REGNO. MODE is the register's
11348 mode and OFFSET is the offset of its save slot from the current
11349 stack pointer. */
11351 static void
11352 mips_save_restore_reg (machine_mode mode, int regno,
11353 HOST_WIDE_INT offset, mips_save_restore_fn fn)
11355 rtx mem;
11357 mem = gen_frame_mem (mode, plus_constant (Pmode, stack_pointer_rtx,
11358 offset));
11359 fn (gen_rtx_REG (mode, regno), mem);
11362 /* Call FN for each accumlator that is saved by the current function.
11363 SP_OFFSET is the offset of the current stack pointer from the start
11364 of the frame. */
11366 static void
11367 mips_for_each_saved_acc (HOST_WIDE_INT sp_offset, mips_save_restore_fn fn)
11369 HOST_WIDE_INT offset;
11370 int regno;
11372 offset = cfun->machine->frame.acc_sp_offset - sp_offset;
11373 if (BITSET_P (cfun->machine->frame.acc_mask, 0))
11375 mips_save_restore_reg (word_mode, LO_REGNUM, offset, fn);
11376 offset -= UNITS_PER_WORD;
11377 mips_save_restore_reg (word_mode, HI_REGNUM, offset, fn);
11378 offset -= UNITS_PER_WORD;
11381 for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno++)
11382 if (BITSET_P (cfun->machine->frame.acc_mask,
11383 ((regno - DSP_ACC_REG_FIRST) / 2) + 1))
11385 mips_save_restore_reg (word_mode, regno, offset, fn);
11386 offset -= UNITS_PER_WORD;
11390 /* Save register REG to MEM. Make the instruction frame-related. */
11392 static void
11393 mips_save_reg (rtx reg, rtx mem)
11395 if (GET_MODE (reg) == DFmode
11396 && (!TARGET_FLOAT64
11397 || mips_abi == ABI_32))
11399 rtx x1, x2;
11401 mips_emit_move_or_split (mem, reg, SPLIT_IF_NECESSARY);
11403 x1 = mips_frame_set (mips_subword (mem, false),
11404 mips_subword (reg, false));
11405 x2 = mips_frame_set (mips_subword (mem, true),
11406 mips_subword (reg, true));
11407 mips_set_frame_expr (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, x1, x2)));
11409 else
11410 mips_emit_save_slot_move (mem, reg, MIPS_PROLOGUE_TEMP (GET_MODE (reg)));
11413 /* Capture the register combinations that are allowed in a SWM or LWM
11414 instruction. The entries are ordered by number of registers set in
11415 the mask. We also ignore the single register encodings because a
11416 normal SW/LW is preferred. */
11418 static const unsigned int umips_swm_mask[17] = {
11419 0xc0ff0000, 0x80ff0000, 0x40ff0000, 0x807f0000,
11420 0x00ff0000, 0x803f0000, 0x007f0000, 0x801f0000,
11421 0x003f0000, 0x800f0000, 0x001f0000, 0x80070000,
11422 0x000f0000, 0x80030000, 0x00070000, 0x80010000,
11423 0x00030000
11426 static const unsigned int umips_swm_encoding[17] = {
11427 25, 24, 9, 23, 8, 22, 7, 21, 6, 20, 5, 19, 4, 18, 3, 17, 2
11430 /* Try to use a microMIPS LWM or SWM instruction to save or restore
11431 as many GPRs in *MASK as possible. *OFFSET is the offset from the
11432 stack pointer of the topmost save slot.
11434 Remove from *MASK all registers that were handled using LWM and SWM.
11435 Update *OFFSET so that it points to the first unused save slot. */
11437 static bool
11438 umips_build_save_restore (mips_save_restore_fn fn,
11439 unsigned *mask, HOST_WIDE_INT *offset)
11441 int nregs;
11442 unsigned int i, j;
11443 rtx pattern, set, reg, mem;
11444 HOST_WIDE_INT this_offset;
11445 rtx this_base;
11447 /* Try matching $16 to $31 (s0 to ra). */
11448 for (i = 0; i < ARRAY_SIZE (umips_swm_mask); i++)
11449 if ((*mask & 0xffff0000) == umips_swm_mask[i])
11450 break;
11452 if (i == ARRAY_SIZE (umips_swm_mask))
11453 return false;
11455 /* Get the offset of the lowest save slot. */
11456 nregs = (umips_swm_encoding[i] & 0xf) + (umips_swm_encoding[i] >> 4);
11457 this_offset = *offset - UNITS_PER_WORD * (nregs - 1);
11459 /* LWM/SWM can only support offsets from -2048 to 2047. */
11460 if (!UMIPS_12BIT_OFFSET_P (this_offset))
11461 return false;
11463 /* Create the final PARALLEL. */
11464 pattern = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs));
11465 this_base = stack_pointer_rtx;
11467 /* For registers $16-$23 and $30. */
11468 for (j = 0; j < (umips_swm_encoding[i] & 0xf); j++)
11470 HOST_WIDE_INT offset = this_offset + j * UNITS_PER_WORD;
11471 mem = gen_frame_mem (SImode, plus_constant (Pmode, this_base, offset));
11472 unsigned int regno = (j != 8) ? 16 + j : 30;
11473 *mask &= ~(1 << regno);
11474 reg = gen_rtx_REG (SImode, regno);
11475 if (fn == mips_save_reg)
11476 set = mips_frame_set (mem, reg);
11477 else
11479 set = gen_rtx_SET (VOIDmode, reg, mem);
11480 mips_add_cfa_restore (reg);
11482 XVECEXP (pattern, 0, j) = set;
11485 /* For register $31. */
11486 if (umips_swm_encoding[i] >> 4)
11488 HOST_WIDE_INT offset = this_offset + j * UNITS_PER_WORD;
11489 *mask &= ~(1 << 31);
11490 mem = gen_frame_mem (SImode, plus_constant (Pmode, this_base, offset));
11491 reg = gen_rtx_REG (SImode, 31);
11492 if (fn == mips_save_reg)
11493 set = mips_frame_set (mem, reg);
11494 else
11496 set = gen_rtx_SET (VOIDmode, reg, mem);
11497 mips_add_cfa_restore (reg);
11499 XVECEXP (pattern, 0, j) = set;
11502 pattern = emit_insn (pattern);
11503 if (fn == mips_save_reg)
11504 RTX_FRAME_RELATED_P (pattern) = 1;
11506 /* Adjust the last offset. */
11507 *offset -= UNITS_PER_WORD * nregs;
11509 return true;
11512 /* Call FN for each register that is saved by the current function.
11513 SP_OFFSET is the offset of the current stack pointer from the start
11514 of the frame. */
11516 static void
11517 mips_for_each_saved_gpr_and_fpr (HOST_WIDE_INT sp_offset,
11518 mips_save_restore_fn fn)
11520 machine_mode fpr_mode;
11521 int regno;
11522 const struct mips_frame_info *frame = &cfun->machine->frame;
11523 HOST_WIDE_INT offset;
11524 unsigned int mask;
11526 /* Save registers starting from high to low. The debuggers prefer at least
11527 the return register be stored at func+4, and also it allows us not to
11528 need a nop in the epilogue if at least one register is reloaded in
11529 addition to return address. */
11530 offset = frame->gp_sp_offset - sp_offset;
11531 mask = frame->mask;
11533 if (TARGET_MICROMIPS)
11534 umips_build_save_restore (fn, &mask, &offset);
11536 for (regno = GP_REG_LAST; regno >= GP_REG_FIRST; regno--)
11537 if (BITSET_P (mask, regno - GP_REG_FIRST))
11539 /* Record the ra offset for use by mips_function_profiler. */
11540 if (regno == RETURN_ADDR_REGNUM)
11541 cfun->machine->frame.ra_fp_offset = offset + sp_offset;
11542 mips_save_restore_reg (word_mode, regno, offset, fn);
11543 offset -= UNITS_PER_WORD;
11546 /* This loop must iterate over the same space as its companion in
11547 mips_compute_frame_info. */
11548 offset = cfun->machine->frame.fp_sp_offset - sp_offset;
11549 fpr_mode = (TARGET_SINGLE_FLOAT ? SFmode : DFmode);
11550 for (regno = FP_REG_LAST - MAX_FPRS_PER_FMT + 1;
11551 regno >= FP_REG_FIRST;
11552 regno -= MAX_FPRS_PER_FMT)
11553 if (BITSET_P (cfun->machine->frame.fmask, regno - FP_REG_FIRST))
11555 if (!TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT
11556 && (fixed_regs[regno] || fixed_regs[regno + 1]))
11558 if (fixed_regs[regno])
11559 mips_save_restore_reg (SFmode, regno + 1, offset, fn);
11560 else
11561 mips_save_restore_reg (SFmode, regno, offset, fn);
11563 else
11564 mips_save_restore_reg (fpr_mode, regno, offset, fn);
11565 offset -= GET_MODE_SIZE (fpr_mode);
11569 /* Return true if a move between register REGNO and its save slot (MEM)
11570 can be done in a single move. LOAD_P is true if we are loading
11571 from the slot, false if we are storing to it. */
11573 static bool
11574 mips_direct_save_slot_move_p (unsigned int regno, rtx mem, bool load_p)
11576 /* There is a specific MIPS16 instruction for saving $31 to the stack. */
11577 if (TARGET_MIPS16 && !load_p && regno == RETURN_ADDR_REGNUM)
11578 return false;
11580 return mips_secondary_reload_class (REGNO_REG_CLASS (regno),
11581 GET_MODE (mem), mem, load_p) == NO_REGS;
11584 /* Emit a move from SRC to DEST, given that one of them is a register
11585 save slot and that the other is a register. TEMP is a temporary
11586 GPR of the same mode that is available if need be. */
11588 void
11589 mips_emit_save_slot_move (rtx dest, rtx src, rtx temp)
11591 unsigned int regno;
11592 rtx mem;
11594 if (REG_P (src))
11596 regno = REGNO (src);
11597 mem = dest;
11599 else
11601 regno = REGNO (dest);
11602 mem = src;
11605 if (regno == cfun->machine->global_pointer && !mips_must_initialize_gp_p ())
11607 /* We don't yet know whether we'll need this instruction or not.
11608 Postpone the decision by emitting a ghost move. This move
11609 is specifically not frame-related; only the split version is. */
11610 if (TARGET_64BIT)
11611 emit_insn (gen_move_gpdi (dest, src));
11612 else
11613 emit_insn (gen_move_gpsi (dest, src));
11614 return;
11617 if (regno == HI_REGNUM)
11619 if (REG_P (dest))
11621 mips_emit_move (temp, src);
11622 if (TARGET_64BIT)
11623 emit_insn (gen_mthisi_di (gen_rtx_REG (TImode, MD_REG_FIRST),
11624 temp, gen_rtx_REG (DImode, LO_REGNUM)));
11625 else
11626 emit_insn (gen_mthisi_di (gen_rtx_REG (DImode, MD_REG_FIRST),
11627 temp, gen_rtx_REG (SImode, LO_REGNUM)));
11629 else
11631 if (TARGET_64BIT)
11632 emit_insn (gen_mfhidi_ti (temp,
11633 gen_rtx_REG (TImode, MD_REG_FIRST)));
11634 else
11635 emit_insn (gen_mfhisi_di (temp,
11636 gen_rtx_REG (DImode, MD_REG_FIRST)));
11637 mips_emit_move (dest, temp);
11640 else if (mips_direct_save_slot_move_p (regno, mem, mem == src))
11641 mips_emit_move (dest, src);
11642 else
11644 gcc_assert (!reg_overlap_mentioned_p (dest, temp));
11645 mips_emit_move (temp, src);
11646 mips_emit_move (dest, temp);
11648 if (MEM_P (dest))
11649 mips_set_frame_expr (mips_frame_set (dest, src));
11652 /* If we're generating n32 or n64 abicalls, and the current function
11653 does not use $28 as its global pointer, emit a cplocal directive.
11654 Use pic_offset_table_rtx as the argument to the directive. */
11656 static void
11657 mips_output_cplocal (void)
11659 if (!TARGET_EXPLICIT_RELOCS
11660 && mips_must_initialize_gp_p ()
11661 && cfun->machine->global_pointer != GLOBAL_POINTER_REGNUM)
11662 output_asm_insn (".cplocal %+", 0);
11665 /* Implement TARGET_OUTPUT_FUNCTION_PROLOGUE. */
11667 static void
11668 mips_output_function_prologue (FILE *file, HOST_WIDE_INT size ATTRIBUTE_UNUSED)
11670 const char *fnname;
11672 /* In MIPS16 mode, we may need to generate a non-MIPS16 stub to handle
11673 floating-point arguments. */
11674 if (TARGET_MIPS16
11675 && TARGET_HARD_FLOAT_ABI
11676 && crtl->args.info.fp_code != 0)
11677 mips16_build_function_stub ();
11679 /* Get the function name the same way that toplev.c does before calling
11680 assemble_start_function. This is needed so that the name used here
11681 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
11682 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
11683 mips_start_function_definition (fnname, TARGET_MIPS16);
11685 /* Output MIPS-specific frame information. */
11686 if (!flag_inhibit_size_directive)
11688 const struct mips_frame_info *frame;
11690 frame = &cfun->machine->frame;
11692 /* .frame FRAMEREG, FRAMESIZE, RETREG. */
11693 fprintf (file,
11694 "\t.frame\t%s," HOST_WIDE_INT_PRINT_DEC ",%s\t\t"
11695 "# vars= " HOST_WIDE_INT_PRINT_DEC
11696 ", regs= %d/%d"
11697 ", args= " HOST_WIDE_INT_PRINT_DEC
11698 ", gp= " HOST_WIDE_INT_PRINT_DEC "\n",
11699 reg_names[frame_pointer_needed
11700 ? HARD_FRAME_POINTER_REGNUM
11701 : STACK_POINTER_REGNUM],
11702 (frame_pointer_needed
11703 ? frame->total_size - frame->hard_frame_pointer_offset
11704 : frame->total_size),
11705 reg_names[RETURN_ADDR_REGNUM],
11706 frame->var_size,
11707 frame->num_gp, frame->num_fp,
11708 frame->args_size,
11709 frame->cprestore_size);
11711 /* .mask MASK, OFFSET. */
11712 fprintf (file, "\t.mask\t0x%08x," HOST_WIDE_INT_PRINT_DEC "\n",
11713 frame->mask, frame->gp_save_offset);
11715 /* .fmask MASK, OFFSET. */
11716 fprintf (file, "\t.fmask\t0x%08x," HOST_WIDE_INT_PRINT_DEC "\n",
11717 frame->fmask, frame->fp_save_offset);
11720 /* Handle the initialization of $gp for SVR4 PIC, if applicable.
11721 Also emit the ".set noreorder; .set nomacro" sequence for functions
11722 that need it. */
11723 if (mips_must_initialize_gp_p ()
11724 && mips_current_loadgp_style () == LOADGP_OLDABI)
11726 if (TARGET_MIPS16)
11728 /* This is a fixed-form sequence. The position of the
11729 first two instructions is important because of the
11730 way _gp_disp is defined. */
11731 output_asm_insn ("li\t$2,%%hi(_gp_disp)", 0);
11732 output_asm_insn ("addiu\t$3,$pc,%%lo(_gp_disp)", 0);
11733 output_asm_insn ("sll\t$2,16", 0);
11734 output_asm_insn ("addu\t$2,$3", 0);
11736 else
11738 /* .cpload must be in a .set noreorder but not a
11739 .set nomacro block. */
11740 mips_push_asm_switch (&mips_noreorder);
11741 output_asm_insn (".cpload\t%^", 0);
11742 if (!cfun->machine->all_noreorder_p)
11743 mips_pop_asm_switch (&mips_noreorder);
11744 else
11745 mips_push_asm_switch (&mips_nomacro);
11748 else if (cfun->machine->all_noreorder_p)
11750 mips_push_asm_switch (&mips_noreorder);
11751 mips_push_asm_switch (&mips_nomacro);
11754 /* Tell the assembler which register we're using as the global
11755 pointer. This is needed for thunks, since they can use either
11756 explicit relocs or assembler macros. */
11757 mips_output_cplocal ();
11760 /* Implement TARGET_OUTPUT_FUNCTION_EPILOGUE. */
11762 static void
11763 mips_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED,
11764 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
11766 const char *fnname;
11768 /* Reinstate the normal $gp. */
11769 SET_REGNO (pic_offset_table_rtx, GLOBAL_POINTER_REGNUM);
11770 mips_output_cplocal ();
11772 if (cfun->machine->all_noreorder_p)
11774 mips_pop_asm_switch (&mips_nomacro);
11775 mips_pop_asm_switch (&mips_noreorder);
11778 /* Get the function name the same way that toplev.c does before calling
11779 assemble_start_function. This is needed so that the name used here
11780 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */
11781 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
11782 mips_end_function_definition (fnname);
11785 /* Emit an optimisation barrier for accesses to the current frame. */
11787 static void
11788 mips_frame_barrier (void)
11790 emit_clobber (gen_frame_mem (BLKmode, stack_pointer_rtx));
11794 /* The __gnu_local_gp symbol. */
11796 static GTY(()) rtx mips_gnu_local_gp;
11798 /* If we're generating n32 or n64 abicalls, emit instructions
11799 to set up the global pointer. */
11801 static void
11802 mips_emit_loadgp (void)
11804 rtx addr, offset, incoming_address, base, index, pic_reg;
11806 pic_reg = TARGET_MIPS16 ? MIPS16_PIC_TEMP : pic_offset_table_rtx;
11807 switch (mips_current_loadgp_style ())
11809 case LOADGP_ABSOLUTE:
11810 if (mips_gnu_local_gp == NULL)
11812 mips_gnu_local_gp = gen_rtx_SYMBOL_REF (Pmode, "__gnu_local_gp");
11813 SYMBOL_REF_FLAGS (mips_gnu_local_gp) |= SYMBOL_FLAG_LOCAL;
11815 emit_insn (PMODE_INSN (gen_loadgp_absolute,
11816 (pic_reg, mips_gnu_local_gp)));
11817 break;
11819 case LOADGP_OLDABI:
11820 /* Added by mips_output_function_prologue. */
11821 break;
11823 case LOADGP_NEWABI:
11824 addr = XEXP (DECL_RTL (current_function_decl), 0);
11825 offset = mips_unspec_address (addr, SYMBOL_GOTOFF_LOADGP);
11826 incoming_address = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
11827 emit_insn (PMODE_INSN (gen_loadgp_newabi,
11828 (pic_reg, offset, incoming_address)));
11829 break;
11831 case LOADGP_RTP:
11832 base = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (VXWORKS_GOTT_BASE));
11833 index = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (VXWORKS_GOTT_INDEX));
11834 emit_insn (PMODE_INSN (gen_loadgp_rtp, (pic_reg, base, index)));
11835 break;
11837 default:
11838 return;
11841 if (TARGET_MIPS16)
11842 emit_insn (PMODE_INSN (gen_copygp_mips16,
11843 (pic_offset_table_rtx, pic_reg)));
11845 /* Emit a blockage if there are implicit uses of the GP register.
11846 This includes profiled functions, because FUNCTION_PROFILE uses
11847 a jal macro. */
11848 if (!TARGET_EXPLICIT_RELOCS || crtl->profile)
11849 emit_insn (gen_loadgp_blockage ());
11852 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
11854 #if PROBE_INTERVAL > 32768
11855 #error Cannot use indexed addressing mode for stack probing
11856 #endif
11858 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
11859 inclusive. These are offsets from the current stack pointer. */
11861 static void
11862 mips_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
11864 if (TARGET_MIPS16)
11865 sorry ("-fstack-check=specific not implemented for MIPS16");
11867 /* See if we have a constant small number of probes to generate. If so,
11868 that's the easy case. */
11869 if (first + size <= 32768)
11871 HOST_WIDE_INT i;
11873 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
11874 it exceeds SIZE. If only one probe is needed, this will not
11875 generate any code. Then probe at FIRST + SIZE. */
11876 for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
11877 emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
11878 -(first + i)));
11880 emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
11881 -(first + size)));
11884 /* Otherwise, do the same as above, but in a loop. Note that we must be
11885 extra careful with variables wrapping around because we might be at
11886 the very top (or the very bottom) of the address space and we have
11887 to be able to handle this case properly; in particular, we use an
11888 equality test for the loop condition. */
11889 else
11891 HOST_WIDE_INT rounded_size;
11892 rtx r3 = MIPS_PROLOGUE_TEMP (Pmode);
11893 rtx r12 = MIPS_PROLOGUE_TEMP2 (Pmode);
11895 /* Sanity check for the addressing mode we're going to use. */
11896 gcc_assert (first <= 32768);
11899 /* Step 1: round SIZE to the previous multiple of the interval. */
11901 rounded_size = size & -PROBE_INTERVAL;
11904 /* Step 2: compute initial and final value of the loop counter. */
11906 /* TEST_ADDR = SP + FIRST. */
11907 emit_insn (gen_rtx_SET (VOIDmode, r3,
11908 plus_constant (Pmode, stack_pointer_rtx,
11909 -first)));
11911 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
11912 if (rounded_size > 32768)
11914 emit_move_insn (r12, GEN_INT (rounded_size));
11915 emit_insn (gen_rtx_SET (VOIDmode, r12,
11916 gen_rtx_MINUS (Pmode, r3, r12)));
11918 else
11919 emit_insn (gen_rtx_SET (VOIDmode, r12,
11920 plus_constant (Pmode, r3, -rounded_size)));
11923 /* Step 3: the loop
11925 while (TEST_ADDR != LAST_ADDR)
11927 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
11928 probe at TEST_ADDR
11931 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
11932 until it is equal to ROUNDED_SIZE. */
11934 emit_insn (PMODE_INSN (gen_probe_stack_range, (r3, r3, r12)));
11937 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
11938 that SIZE is equal to ROUNDED_SIZE. */
11940 if (size != rounded_size)
11941 emit_stack_probe (plus_constant (Pmode, r12, rounded_size - size));
11944 /* Make sure nothing is scheduled before we are done. */
11945 emit_insn (gen_blockage ());
11948 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
11949 absolute addresses. */
11951 const char *
11952 mips_output_probe_stack_range (rtx reg1, rtx reg2)
11954 static int labelno = 0;
11955 char loop_lab[32], end_lab[32], tmp[64];
11956 rtx xops[2];
11958 ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
11959 ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
11961 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
11963 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
11964 xops[0] = reg1;
11965 xops[1] = reg2;
11966 strcpy (tmp, "%(%<beq\t%0,%1,");
11967 output_asm_insn (strcat (tmp, &end_lab[1]), xops);
11969 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
11970 xops[1] = GEN_INT (-PROBE_INTERVAL);
11971 if (TARGET_64BIT && TARGET_LONG64)
11972 output_asm_insn ("daddiu\t%0,%0,%1", xops);
11973 else
11974 output_asm_insn ("addiu\t%0,%0,%1", xops);
11976 /* Probe at TEST_ADDR and branch. */
11977 fprintf (asm_out_file, "\tb\t");
11978 assemble_name_raw (asm_out_file, loop_lab);
11979 fputc ('\n', asm_out_file);
11980 if (TARGET_64BIT)
11981 output_asm_insn ("sd\t$0,0(%0)%)", xops);
11982 else
11983 output_asm_insn ("sw\t$0,0(%0)%)", xops);
11985 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
11987 return "";
11990 /* A for_each_rtx callback. Stop the search if *X is a kernel register. */
11992 static int
11993 mips_kernel_reg_p (rtx *x, void *data ATTRIBUTE_UNUSED)
11995 return REG_P (*x) && KERNEL_REG_P (REGNO (*x));
11998 /* Expand the "prologue" pattern. */
12000 void
12001 mips_expand_prologue (void)
12003 const struct mips_frame_info *frame;
12004 HOST_WIDE_INT size;
12005 unsigned int nargs;
12006 rtx insn;
12008 if (cfun->machine->global_pointer != INVALID_REGNUM)
12010 /* Check whether an insn uses pic_offset_table_rtx, either explicitly
12011 or implicitly. If so, we can commit to using a global pointer
12012 straight away, otherwise we need to defer the decision. */
12013 if (mips_cfun_has_inflexible_gp_ref_p ()
12014 || mips_cfun_has_flexible_gp_ref_p ())
12016 cfun->machine->must_initialize_gp_p = true;
12017 cfun->machine->must_restore_gp_when_clobbered_p = true;
12020 SET_REGNO (pic_offset_table_rtx, cfun->machine->global_pointer);
12023 frame = &cfun->machine->frame;
12024 size = frame->total_size;
12026 if (flag_stack_usage_info)
12027 current_function_static_stack_size = size;
12029 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
12031 if (crtl->is_leaf && !cfun->calls_alloca)
12033 if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
12034 mips_emit_probe_stack_range (STACK_CHECK_PROTECT,
12035 size - STACK_CHECK_PROTECT);
12037 else if (size > 0)
12038 mips_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
12041 /* Save the registers. Allocate up to MIPS_MAX_FIRST_STACK_STEP
12042 bytes beforehand; this is enough to cover the register save area
12043 without going out of range. */
12044 if (((frame->mask | frame->fmask | frame->acc_mask) != 0)
12045 || frame->num_cop0_regs > 0)
12047 HOST_WIDE_INT step1;
12049 step1 = MIN (size, MIPS_MAX_FIRST_STACK_STEP);
12050 if (GENERATE_MIPS16E_SAVE_RESTORE)
12052 HOST_WIDE_INT offset;
12053 unsigned int mask, regno;
12055 /* Try to merge argument stores into the save instruction. */
12056 nargs = mips16e_collect_argument_saves ();
12058 /* Build the save instruction. */
12059 mask = frame->mask;
12060 insn = mips16e_build_save_restore (false, &mask, &offset,
12061 nargs, step1);
12062 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
12063 mips_frame_barrier ();
12064 size -= step1;
12066 /* Check if we need to save other registers. */
12067 for (regno = GP_REG_FIRST; regno < GP_REG_LAST; regno++)
12068 if (BITSET_P (mask, regno - GP_REG_FIRST))
12070 offset -= UNITS_PER_WORD;
12071 mips_save_restore_reg (word_mode, regno,
12072 offset, mips_save_reg);
12075 else
12077 if (cfun->machine->interrupt_handler_p)
12079 HOST_WIDE_INT offset;
12080 rtx mem;
12082 /* If this interrupt is using a shadow register set, we need to
12083 get the stack pointer from the previous register set. */
12084 if (cfun->machine->use_shadow_register_set_p)
12085 emit_insn (gen_mips_rdpgpr (stack_pointer_rtx,
12086 stack_pointer_rtx));
12088 if (!cfun->machine->keep_interrupts_masked_p)
12090 /* Move from COP0 Cause to K0. */
12091 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K0_REG_NUM),
12092 gen_rtx_REG (SImode,
12093 COP0_CAUSE_REG_NUM)));
12094 /* Move from COP0 EPC to K1. */
12095 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM),
12096 gen_rtx_REG (SImode,
12097 COP0_EPC_REG_NUM)));
12100 /* Allocate the first part of the frame. */
12101 insn = gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx,
12102 GEN_INT (-step1));
12103 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
12104 mips_frame_barrier ();
12105 size -= step1;
12107 /* Start at the uppermost location for saving. */
12108 offset = frame->cop0_sp_offset - size;
12109 if (!cfun->machine->keep_interrupts_masked_p)
12111 /* Push EPC into its stack slot. */
12112 mem = gen_frame_mem (word_mode,
12113 plus_constant (Pmode, stack_pointer_rtx,
12114 offset));
12115 mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM));
12116 offset -= UNITS_PER_WORD;
12119 /* Move from COP0 Status to K1. */
12120 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM),
12121 gen_rtx_REG (SImode,
12122 COP0_STATUS_REG_NUM)));
12124 /* Right justify the RIPL in k0. */
12125 if (!cfun->machine->keep_interrupts_masked_p)
12126 emit_insn (gen_lshrsi3 (gen_rtx_REG (SImode, K0_REG_NUM),
12127 gen_rtx_REG (SImode, K0_REG_NUM),
12128 GEN_INT (CAUSE_IPL)));
12130 /* Push Status into its stack slot. */
12131 mem = gen_frame_mem (word_mode,
12132 plus_constant (Pmode, stack_pointer_rtx,
12133 offset));
12134 mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM));
12135 offset -= UNITS_PER_WORD;
12137 /* Insert the RIPL into our copy of SR (k1) as the new IPL. */
12138 if (!cfun->machine->keep_interrupts_masked_p)
12139 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
12140 GEN_INT (6),
12141 GEN_INT (SR_IPL),
12142 gen_rtx_REG (SImode, K0_REG_NUM)));
12144 if (!cfun->machine->keep_interrupts_masked_p)
12145 /* Enable interrupts by clearing the KSU ERL and EXL bits.
12146 IE is already the correct value, so we don't have to do
12147 anything explicit. */
12148 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
12149 GEN_INT (4),
12150 GEN_INT (SR_EXL),
12151 gen_rtx_REG (SImode, GP_REG_FIRST)));
12152 else
12153 /* Disable interrupts by clearing the KSU, ERL, EXL,
12154 and IE bits. */
12155 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
12156 GEN_INT (5),
12157 GEN_INT (SR_IE),
12158 gen_rtx_REG (SImode, GP_REG_FIRST)));
12160 if (TARGET_HARD_FLOAT)
12161 /* Disable COP1 for hard-float. This will lead to an exception
12162 if floating-point code is executed in an ISR. */
12163 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM),
12164 GEN_INT (1),
12165 GEN_INT (SR_COP1),
12166 gen_rtx_REG (SImode, GP_REG_FIRST)));
12168 else
12170 insn = gen_add3_insn (stack_pointer_rtx,
12171 stack_pointer_rtx,
12172 GEN_INT (-step1));
12173 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
12174 mips_frame_barrier ();
12175 size -= step1;
12177 mips_for_each_saved_acc (size, mips_save_reg);
12178 mips_for_each_saved_gpr_and_fpr (size, mips_save_reg);
12182 /* Allocate the rest of the frame. */
12183 if (size > 0)
12185 if (SMALL_OPERAND (-size))
12186 RTX_FRAME_RELATED_P (emit_insn (gen_add3_insn (stack_pointer_rtx,
12187 stack_pointer_rtx,
12188 GEN_INT (-size)))) = 1;
12189 else
12191 mips_emit_move (MIPS_PROLOGUE_TEMP (Pmode), GEN_INT (size));
12192 if (TARGET_MIPS16)
12194 /* There are no instructions to add or subtract registers
12195 from the stack pointer, so use the frame pointer as a
12196 temporary. We should always be using a frame pointer
12197 in this case anyway. */
12198 gcc_assert (frame_pointer_needed);
12199 mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx);
12200 emit_insn (gen_sub3_insn (hard_frame_pointer_rtx,
12201 hard_frame_pointer_rtx,
12202 MIPS_PROLOGUE_TEMP (Pmode)));
12203 mips_emit_move (stack_pointer_rtx, hard_frame_pointer_rtx);
12205 else
12206 emit_insn (gen_sub3_insn (stack_pointer_rtx,
12207 stack_pointer_rtx,
12208 MIPS_PROLOGUE_TEMP (Pmode)));
12210 /* Describe the combined effect of the previous instructions. */
12211 mips_set_frame_expr
12212 (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
12213 plus_constant (Pmode, stack_pointer_rtx, -size)));
12215 mips_frame_barrier ();
12218 /* Set up the frame pointer, if we're using one. */
12219 if (frame_pointer_needed)
12221 HOST_WIDE_INT offset;
12223 offset = frame->hard_frame_pointer_offset;
12224 if (offset == 0)
12226 insn = mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx);
12227 RTX_FRAME_RELATED_P (insn) = 1;
12229 else if (SMALL_OPERAND (offset))
12231 insn = gen_add3_insn (hard_frame_pointer_rtx,
12232 stack_pointer_rtx, GEN_INT (offset));
12233 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1;
12235 else
12237 mips_emit_move (MIPS_PROLOGUE_TEMP (Pmode), GEN_INT (offset));
12238 mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx);
12239 emit_insn (gen_add3_insn (hard_frame_pointer_rtx,
12240 hard_frame_pointer_rtx,
12241 MIPS_PROLOGUE_TEMP (Pmode)));
12242 mips_set_frame_expr
12243 (gen_rtx_SET (VOIDmode, hard_frame_pointer_rtx,
12244 plus_constant (Pmode, stack_pointer_rtx, offset)));
12248 mips_emit_loadgp ();
12250 /* Initialize the $gp save slot. */
12251 if (mips_cfun_has_cprestore_slot_p ())
12253 rtx base, mem, gp, temp;
12254 HOST_WIDE_INT offset;
12256 mips_get_cprestore_base_and_offset (&base, &offset, false);
12257 mem = gen_frame_mem (Pmode, plus_constant (Pmode, base, offset));
12258 gp = TARGET_MIPS16 ? MIPS16_PIC_TEMP : pic_offset_table_rtx;
12259 temp = (SMALL_OPERAND (offset)
12260 ? gen_rtx_SCRATCH (Pmode)
12261 : MIPS_PROLOGUE_TEMP (Pmode));
12262 emit_insn (PMODE_INSN (gen_potential_cprestore,
12263 (mem, GEN_INT (offset), gp, temp)));
12265 mips_get_cprestore_base_and_offset (&base, &offset, true);
12266 mem = gen_frame_mem (Pmode, plus_constant (Pmode, base, offset));
12267 emit_insn (PMODE_INSN (gen_use_cprestore, (mem)));
12270 /* We need to search back to the last use of K0 or K1. */
12271 if (cfun->machine->interrupt_handler_p)
12273 for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn))
12274 if (INSN_P (insn)
12275 && for_each_rtx (&PATTERN (insn), mips_kernel_reg_p, NULL))
12276 break;
12277 /* Emit a move from K1 to COP0 Status after insn. */
12278 gcc_assert (insn != NULL_RTX);
12279 emit_insn_after (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM),
12280 gen_rtx_REG (SImode, K1_REG_NUM)),
12281 insn);
12284 /* If we are profiling, make sure no instructions are scheduled before
12285 the call to mcount. */
12286 if (crtl->profile)
12287 emit_insn (gen_blockage ());
12290 /* Attach all pending register saves to the previous instruction.
12291 Return that instruction. */
12293 static rtx
12294 mips_epilogue_emit_cfa_restores (void)
12296 rtx insn;
12298 insn = get_last_insn ();
12299 gcc_assert (insn && !REG_NOTES (insn));
12300 if (mips_epilogue.cfa_restores)
12302 RTX_FRAME_RELATED_P (insn) = 1;
12303 REG_NOTES (insn) = mips_epilogue.cfa_restores;
12304 mips_epilogue.cfa_restores = 0;
12306 return insn;
12309 /* Like mips_epilogue_emit_cfa_restores, but also record that the CFA is
12310 now at REG + OFFSET. */
12312 static void
12313 mips_epilogue_set_cfa (rtx reg, HOST_WIDE_INT offset)
12315 rtx insn;
12317 insn = mips_epilogue_emit_cfa_restores ();
12318 if (reg != mips_epilogue.cfa_reg || offset != mips_epilogue.cfa_offset)
12320 RTX_FRAME_RELATED_P (insn) = 1;
12321 REG_NOTES (insn) = alloc_reg_note (REG_CFA_DEF_CFA,
12322 plus_constant (Pmode, reg, offset),
12323 REG_NOTES (insn));
12324 mips_epilogue.cfa_reg = reg;
12325 mips_epilogue.cfa_offset = offset;
12329 /* Emit instructions to restore register REG from slot MEM. Also update
12330 the cfa_restores list. */
12332 static void
12333 mips_restore_reg (rtx reg, rtx mem)
12335 /* There's no MIPS16 instruction to load $31 directly. Load into
12336 $7 instead and adjust the return insn appropriately. */
12337 if (TARGET_MIPS16 && REGNO (reg) == RETURN_ADDR_REGNUM)
12338 reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7);
12339 else if (GET_MODE (reg) == DFmode
12340 && (!TARGET_FLOAT64
12341 || mips_abi == ABI_32))
12343 mips_add_cfa_restore (mips_subword (reg, true));
12344 mips_add_cfa_restore (mips_subword (reg, false));
12346 else
12347 mips_add_cfa_restore (reg);
12349 mips_emit_save_slot_move (reg, mem, MIPS_EPILOGUE_TEMP (GET_MODE (reg)));
12350 if (REGNO (reg) == REGNO (mips_epilogue.cfa_reg))
12351 /* The CFA is currently defined in terms of the register whose
12352 value we have just restored. Redefine the CFA in terms of
12353 the stack pointer. */
12354 mips_epilogue_set_cfa (stack_pointer_rtx,
12355 mips_epilogue.cfa_restore_sp_offset);
12358 /* Emit code to set the stack pointer to BASE + OFFSET, given that
12359 BASE + OFFSET is NEW_FRAME_SIZE bytes below the top of the frame.
12360 BASE, if not the stack pointer, is available as a temporary. */
12362 static void
12363 mips_deallocate_stack (rtx base, rtx offset, HOST_WIDE_INT new_frame_size)
12365 if (base == stack_pointer_rtx && offset == const0_rtx)
12366 return;
12368 mips_frame_barrier ();
12369 if (offset == const0_rtx)
12371 emit_move_insn (stack_pointer_rtx, base);
12372 mips_epilogue_set_cfa (stack_pointer_rtx, new_frame_size);
12374 else if (TARGET_MIPS16 && base != stack_pointer_rtx)
12376 emit_insn (gen_add3_insn (base, base, offset));
12377 mips_epilogue_set_cfa (base, new_frame_size);
12378 emit_move_insn (stack_pointer_rtx, base);
12380 else
12382 emit_insn (gen_add3_insn (stack_pointer_rtx, base, offset));
12383 mips_epilogue_set_cfa (stack_pointer_rtx, new_frame_size);
12387 /* Emit any instructions needed before a return. */
12389 void
12390 mips_expand_before_return (void)
12392 /* When using a call-clobbered gp, we start out with unified call
12393 insns that include instructions to restore the gp. We then split
12394 these unified calls after reload. These split calls explicitly
12395 clobber gp, so there is no need to define
12396 PIC_OFFSET_TABLE_REG_CALL_CLOBBERED.
12398 For consistency, we should also insert an explicit clobber of $28
12399 before return insns, so that the post-reload optimizers know that
12400 the register is not live on exit. */
12401 if (TARGET_CALL_CLOBBERED_GP)
12402 emit_clobber (pic_offset_table_rtx);
12405 /* Expand an "epilogue" or "sibcall_epilogue" pattern; SIBCALL_P
12406 says which. */
12408 void
12409 mips_expand_epilogue (bool sibcall_p)
12411 const struct mips_frame_info *frame;
12412 HOST_WIDE_INT step1, step2;
12413 rtx base, adjust, insn;
12414 bool use_jraddiusp_p = false;
12416 if (!sibcall_p && mips_can_use_return_insn ())
12418 emit_jump_insn (gen_return ());
12419 return;
12422 /* In MIPS16 mode, if the return value should go into a floating-point
12423 register, we need to call a helper routine to copy it over. */
12424 if (mips16_cfun_returns_in_fpr_p ())
12425 mips16_copy_fpr_return_value ();
12427 /* Split the frame into two. STEP1 is the amount of stack we should
12428 deallocate before restoring the registers. STEP2 is the amount we
12429 should deallocate afterwards.
12431 Start off by assuming that no registers need to be restored. */
12432 frame = &cfun->machine->frame;
12433 step1 = frame->total_size;
12434 step2 = 0;
12436 /* Work out which register holds the frame address. */
12437 if (!frame_pointer_needed)
12438 base = stack_pointer_rtx;
12439 else
12441 base = hard_frame_pointer_rtx;
12442 step1 -= frame->hard_frame_pointer_offset;
12444 mips_epilogue.cfa_reg = base;
12445 mips_epilogue.cfa_offset = step1;
12446 mips_epilogue.cfa_restores = NULL_RTX;
12448 /* If we need to restore registers, deallocate as much stack as
12449 possible in the second step without going out of range. */
12450 if ((frame->mask | frame->fmask | frame->acc_mask) != 0
12451 || frame->num_cop0_regs > 0)
12453 step2 = MIN (step1, MIPS_MAX_FIRST_STACK_STEP);
12454 step1 -= step2;
12457 /* Get an rtx for STEP1 that we can add to BASE. */
12458 adjust = GEN_INT (step1);
12459 if (!SMALL_OPERAND (step1))
12461 mips_emit_move (MIPS_EPILOGUE_TEMP (Pmode), adjust);
12462 adjust = MIPS_EPILOGUE_TEMP (Pmode);
12464 mips_deallocate_stack (base, adjust, step2);
12466 /* If we're using addressing macros, $gp is implicitly used by all
12467 SYMBOL_REFs. We must emit a blockage insn before restoring $gp
12468 from the stack. */
12469 if (TARGET_CALL_SAVED_GP && !TARGET_EXPLICIT_RELOCS)
12470 emit_insn (gen_blockage ());
12472 mips_epilogue.cfa_restore_sp_offset = step2;
12473 if (GENERATE_MIPS16E_SAVE_RESTORE && frame->mask != 0)
12475 unsigned int regno, mask;
12476 HOST_WIDE_INT offset;
12477 rtx restore;
12479 /* Generate the restore instruction. */
12480 mask = frame->mask;
12481 restore = mips16e_build_save_restore (true, &mask, &offset, 0, step2);
12483 /* Restore any other registers manually. */
12484 for (regno = GP_REG_FIRST; regno < GP_REG_LAST; regno++)
12485 if (BITSET_P (mask, regno - GP_REG_FIRST))
12487 offset -= UNITS_PER_WORD;
12488 mips_save_restore_reg (word_mode, regno, offset, mips_restore_reg);
12491 /* Restore the remaining registers and deallocate the final bit
12492 of the frame. */
12493 mips_frame_barrier ();
12494 emit_insn (restore);
12495 mips_epilogue_set_cfa (stack_pointer_rtx, 0);
12497 else
12499 /* Restore the registers. */
12500 mips_for_each_saved_acc (frame->total_size - step2, mips_restore_reg);
12501 mips_for_each_saved_gpr_and_fpr (frame->total_size - step2,
12502 mips_restore_reg);
12504 if (cfun->machine->interrupt_handler_p)
12506 HOST_WIDE_INT offset;
12507 rtx mem;
12509 offset = frame->cop0_sp_offset - (frame->total_size - step2);
12510 if (!cfun->machine->keep_interrupts_masked_p)
12512 /* Restore the original EPC. */
12513 mem = gen_frame_mem (word_mode,
12514 plus_constant (Pmode, stack_pointer_rtx,
12515 offset));
12516 mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
12517 offset -= UNITS_PER_WORD;
12519 /* Move to COP0 EPC. */
12520 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_EPC_REG_NUM),
12521 gen_rtx_REG (SImode, K0_REG_NUM)));
12524 /* Restore the original Status. */
12525 mem = gen_frame_mem (word_mode,
12526 plus_constant (Pmode, stack_pointer_rtx,
12527 offset));
12528 mips_emit_move (gen_rtx_REG (word_mode, K0_REG_NUM), mem);
12529 offset -= UNITS_PER_WORD;
12531 /* If we don't use shadow register set, we need to update SP. */
12532 if (!cfun->machine->use_shadow_register_set_p)
12533 mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
12534 else
12535 /* The choice of position is somewhat arbitrary in this case. */
12536 mips_epilogue_emit_cfa_restores ();
12538 /* Move to COP0 Status. */
12539 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM),
12540 gen_rtx_REG (SImode, K0_REG_NUM)));
12542 else if (TARGET_MICROMIPS
12543 && !crtl->calls_eh_return
12544 && !sibcall_p
12545 && step2 > 0
12546 && mips_unsigned_immediate_p (step2, 5, 2))
12547 use_jraddiusp_p = true;
12548 else
12549 /* Deallocate the final bit of the frame. */
12550 mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0);
12553 if (!use_jraddiusp_p)
12554 gcc_assert (!mips_epilogue.cfa_restores);
12556 /* Add in the __builtin_eh_return stack adjustment. We need to
12557 use a temporary in MIPS16 code. */
12558 if (crtl->calls_eh_return)
12560 if (TARGET_MIPS16)
12562 mips_emit_move (MIPS_EPILOGUE_TEMP (Pmode), stack_pointer_rtx);
12563 emit_insn (gen_add3_insn (MIPS_EPILOGUE_TEMP (Pmode),
12564 MIPS_EPILOGUE_TEMP (Pmode),
12565 EH_RETURN_STACKADJ_RTX));
12566 mips_emit_move (stack_pointer_rtx, MIPS_EPILOGUE_TEMP (Pmode));
12568 else
12569 emit_insn (gen_add3_insn (stack_pointer_rtx,
12570 stack_pointer_rtx,
12571 EH_RETURN_STACKADJ_RTX));
12574 if (!sibcall_p)
12576 mips_expand_before_return ();
12577 if (cfun->machine->interrupt_handler_p)
12579 /* Interrupt handlers generate eret or deret. */
12580 if (cfun->machine->use_debug_exception_return_p)
12581 emit_jump_insn (gen_mips_deret ());
12582 else
12583 emit_jump_insn (gen_mips_eret ());
12585 else
12587 rtx pat;
12589 /* When generating MIPS16 code, the normal
12590 mips_for_each_saved_gpr_and_fpr path will restore the return
12591 address into $7 rather than $31. */
12592 if (TARGET_MIPS16
12593 && !GENERATE_MIPS16E_SAVE_RESTORE
12594 && BITSET_P (frame->mask, RETURN_ADDR_REGNUM))
12596 /* simple_returns cannot rely on values that are only available
12597 on paths through the epilogue (because return paths that do
12598 not pass through the epilogue may nevertheless reuse a
12599 simple_return that occurs at the end of the epilogue).
12600 Use a normal return here instead. */
12601 rtx reg = gen_rtx_REG (Pmode, GP_REG_FIRST + 7);
12602 pat = gen_return_internal (reg);
12604 else if (use_jraddiusp_p)
12605 pat = gen_jraddiusp (GEN_INT (step2));
12606 else
12608 rtx reg = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
12609 pat = gen_simple_return_internal (reg);
12611 emit_jump_insn (pat);
12612 if (use_jraddiusp_p)
12613 mips_epilogue_set_cfa (stack_pointer_rtx, step2);
12617 /* Search from the beginning to the first use of K0 or K1. */
12618 if (cfun->machine->interrupt_handler_p
12619 && !cfun->machine->keep_interrupts_masked_p)
12621 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
12622 if (INSN_P (insn)
12623 && for_each_rtx (&PATTERN(insn), mips_kernel_reg_p, NULL))
12624 break;
12625 gcc_assert (insn != NULL_RTX);
12626 /* Insert disable interrupts before the first use of K0 or K1. */
12627 emit_insn_before (gen_mips_di (), insn);
12628 emit_insn_before (gen_mips_ehb (), insn);
12632 /* Return nonzero if this function is known to have a null epilogue.
12633 This allows the optimizer to omit jumps to jumps if no stack
12634 was created. */
12636 bool
12637 mips_can_use_return_insn (void)
12639 /* Interrupt handlers need to go through the epilogue. */
12640 if (cfun->machine->interrupt_handler_p)
12641 return false;
12643 if (!reload_completed)
12644 return false;
12646 if (crtl->profile)
12647 return false;
12649 /* In MIPS16 mode, a function that returns a floating-point value
12650 needs to arrange to copy the return value into the floating-point
12651 registers. */
12652 if (mips16_cfun_returns_in_fpr_p ())
12653 return false;
12655 return cfun->machine->frame.total_size == 0;
12658 /* Return true if register REGNO can store a value of mode MODE.
12659 The result of this function is cached in mips_hard_regno_mode_ok. */
12661 static bool
12662 mips_hard_regno_mode_ok_p (unsigned int regno, machine_mode mode)
12664 unsigned int size;
12665 enum mode_class mclass;
12667 if (mode == CCV2mode)
12668 return (ISA_HAS_8CC
12669 && ST_REG_P (regno)
12670 && (regno - ST_REG_FIRST) % 2 == 0);
12672 if (mode == CCV4mode)
12673 return (ISA_HAS_8CC
12674 && ST_REG_P (regno)
12675 && (regno - ST_REG_FIRST) % 4 == 0);
12677 if (mode == CCmode)
12678 return ISA_HAS_8CC ? ST_REG_P (regno) : regno == FPSW_REGNUM;
12680 size = GET_MODE_SIZE (mode);
12681 mclass = GET_MODE_CLASS (mode);
12683 if (GP_REG_P (regno) && mode != CCFmode && !MSA_SUPPORTED_MODE_P (mode))
12684 return ((regno - GP_REG_FIRST) & 1) == 0 || size <= UNITS_PER_WORD;
12686 /* For MSA, allow TImode and 128-bit vector modes in all FPR. */
12687 if (FP_REG_P (regno) && MSA_SUPPORTED_MODE_P (mode))
12688 return true;
12690 if (FP_REG_P (regno)
12691 && (((regno - FP_REG_FIRST) % MAX_FPRS_PER_FMT) == 0
12692 || (MIN_FPRS_PER_FMT == 1 && size <= UNITS_PER_FPREG)))
12694 /* Deny use of odd-numbered registers for 32-bit data for
12695 the o32 FP64A ABI. */
12696 if (TARGET_O32_FP64A_ABI && size <= 4 && (regno & 1) != 0)
12697 return false;
12699 /* Prevent the use of odd-numbered registers for CCFmode with the
12700 o32 FPXX ABI, otherwise allow them.
12701 The FPXX ABI does not permit double-precision data to be placed
12702 in odd-numbered registers and double-precision compares write
12703 them as 64-bit values. Without this restriction the R6 FPXX
12704 ABI would not be able to execute in FR=1 FRE=1 mode. */
12705 if (mode == CCFmode && ISA_HAS_CCF)
12706 return !(TARGET_FLOATXX && (regno & 1) != 0);
12708 /* Allow 64-bit vector modes for Loongson-2E/2F. */
12709 if (TARGET_LOONGSON_VECTORS
12710 && (mode == V2SImode
12711 || mode == V4HImode
12712 || mode == V8QImode
12713 || mode == DImode))
12714 return true;
12716 if (mclass == MODE_FLOAT
12717 || mclass == MODE_COMPLEX_FLOAT
12718 || mclass == MODE_VECTOR_FLOAT)
12719 return size <= UNITS_PER_FPVALUE;
12721 /* Allow integer modes that fit into a single register. We need
12722 to put integers into FPRs when using instructions like CVT
12723 and TRUNC. There's no point allowing sizes smaller than a word,
12724 because the FPU has no appropriate load/store instructions. */
12725 if (mclass == MODE_INT)
12726 return size >= MIN_UNITS_PER_WORD && size <= UNITS_PER_FPREG;
12729 /* Don't allow MSA vector modes in accumulators. */
12730 if (ACC_REG_P (regno)
12731 && !MSA_SUPPORTED_MODE_P (mode)
12732 && (INTEGRAL_MODE_P (mode) || ALL_FIXED_POINT_MODE_P (mode)))
12734 if (MD_REG_P (regno))
12736 /* After a multiplication or division, clobbering HI makes
12737 the value of LO unpredictable, and vice versa. This means
12738 that, for all interesting cases, HI and LO are effectively
12739 a single register.
12741 We model this by requiring that any value that uses HI
12742 also uses LO. */
12743 if (size <= UNITS_PER_WORD * 2)
12744 return regno == (size <= UNITS_PER_WORD ? LO_REGNUM : MD_REG_FIRST);
12746 else
12748 /* DSP accumulators do not have the same restrictions as
12749 HI and LO, so we can treat them as normal doubleword
12750 registers. */
12751 if (size <= UNITS_PER_WORD)
12752 return true;
12754 if (size <= UNITS_PER_WORD * 2
12755 && ((regno - DSP_ACC_REG_FIRST) & 1) == 0)
12756 return true;
12760 if (ALL_COP_REG_P (regno))
12761 return mclass == MODE_INT && size <= UNITS_PER_WORD;
12763 if (regno == GOT_VERSION_REGNUM)
12764 return mode == SImode;
12766 return false;
12769 /* Implement HARD_REGNO_NREGS. */
12771 unsigned int
12772 mips_hard_regno_nregs (int regno, machine_mode mode)
12774 if (ST_REG_P (regno))
12775 /* The size of FP status registers is always 4, because they only hold
12776 CCmode values, and CCmode is always considered to be 4 bytes wide. */
12777 return (GET_MODE_SIZE (mode) + 3) / 4;
12779 if (FP_REG_P (regno))
12781 if (MSA_SUPPORTED_MODE_P (mode))
12782 return 1;
12784 return (GET_MODE_SIZE (mode) + UNITS_PER_FPREG - 1) / UNITS_PER_FPREG;
12787 /* All other registers are word-sized. */
12788 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
12791 /* Implement CLASS_MAX_NREGS, taking the maximum of the cases
12792 in mips_hard_regno_nregs. */
12795 mips_class_max_nregs (enum reg_class rclass, machine_mode mode)
12797 int size;
12798 HARD_REG_SET left;
12800 size = 0x8000;
12801 COPY_HARD_REG_SET (left, reg_class_contents[(int) rclass]);
12802 if (hard_reg_set_intersect_p (left, reg_class_contents[(int) ST_REGS]))
12804 if (HARD_REGNO_MODE_OK (ST_REG_FIRST, mode))
12806 if (MSA_SUPPORTED_MODE_P (mode))
12807 size = MIN (size, UNITS_PER_MSA_REG);
12808 else
12809 size = MIN (size, UNITS_PER_FPREG);
12812 AND_COMPL_HARD_REG_SET (left, reg_class_contents[(int) ST_REGS]);
12814 if (hard_reg_set_intersect_p (left, reg_class_contents[(int) FP_REGS]))
12816 if (HARD_REGNO_MODE_OK (FP_REG_FIRST, mode))
12818 if (MSA_SUPPORTED_MODE_P (mode))
12819 size = MIN (size, UNITS_PER_MSA_REG);
12820 else
12821 size = MIN (size, UNITS_PER_FPREG);
12824 AND_COMPL_HARD_REG_SET (left, reg_class_contents[(int) FP_REGS]);
12826 if (!hard_reg_set_empty_p (left))
12827 size = MIN (size, UNITS_PER_WORD);
12828 return (GET_MODE_SIZE (mode) + size - 1) / size;
12831 /* Implement CANNOT_CHANGE_MODE_CLASS. */
12833 bool
12834 mips_cannot_change_mode_class (machine_mode from,
12835 machine_mode to,
12836 enum reg_class rclass)
12838 /* Allow conversions between different Loongson integer vectors,
12839 and between those vectors and DImode. */
12840 if (GET_MODE_SIZE (from) == 8 && GET_MODE_SIZE (to) == 8
12841 && INTEGRAL_MODE_P (from) && INTEGRAL_MODE_P (to))
12842 return false;
12844 /* Allow conversions between different MSA vector modes and TImode. */
12845 if (MSA_SUPPORTED_MODE_P (from) && MSA_SUPPORTED_MODE_P (to))
12846 return false;
12848 /* Otherwise, there are several problems with changing the modes of
12849 values in floating-point registers:
12851 - When a multi-word value is stored in paired floating-point
12852 registers, the first register always holds the low word. We
12853 therefore can't allow FPRs to change between single-word and
12854 multi-word modes on big-endian targets.
12856 - GCC assumes that each word of a multiword register can be
12857 accessed individually using SUBREGs. This is not true for
12858 floating-point registers if they are bigger than a word.
12860 - Loading a 32-bit value into a 64-bit floating-point register
12861 will not sign-extend the value, despite what LOAD_EXTEND_OP
12862 says. We can't allow FPRs to change from SImode to a wider
12863 mode on 64-bit targets.
12865 - If the FPU has already interpreted a value in one format, we
12866 must not ask it to treat the value as having a different
12867 format.
12869 We therefore disallow all mode changes involving FPRs. */
12871 return reg_classes_intersect_p (FP_REGS, rclass);
12874 /* Implement target hook small_register_classes_for_mode_p. */
12876 static bool
12877 mips_small_register_classes_for_mode_p (machine_mode mode
12878 ATTRIBUTE_UNUSED)
12880 return TARGET_MIPS16;
12883 /* Return true if moves in mode MODE can use the FPU's mov.fmt instruction,
12884 or use the MSA's move.v instruction. */
12886 static bool
12887 mips_mode_ok_for_mov_fmt_p (machine_mode mode)
12889 switch (mode)
12891 case CCFmode:
12892 case SFmode:
12893 return TARGET_HARD_FLOAT;
12895 case DFmode:
12896 return TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT;
12898 case V2SFmode:
12899 return TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT;
12901 default:
12902 return MSA_SUPPORTED_MODE_P (mode);
12906 /* Implement MODES_TIEABLE_P. */
12908 bool
12909 mips_modes_tieable_p (machine_mode mode1, machine_mode mode2)
12911 /* FPRs allow no mode punning, so it's not worth tying modes if we'd
12912 prefer to put one of them in FPRs. */
12913 return (mode1 == mode2
12914 || (!mips_mode_ok_for_mov_fmt_p (mode1)
12915 && !mips_mode_ok_for_mov_fmt_p (mode2)));
12918 /* Implement TARGET_PREFERRED_RELOAD_CLASS. */
12920 static reg_class_t
12921 mips_preferred_reload_class (rtx x, reg_class_t rclass)
12923 if (mips_dangerous_for_la25_p (x) && reg_class_subset_p (LEA_REGS, rclass))
12924 return LEA_REGS;
12926 if (reg_class_subset_p (FP_REGS, rclass)
12927 && mips_mode_ok_for_mov_fmt_p (GET_MODE (x)))
12928 return FP_REGS;
12930 if (reg_class_subset_p (GR_REGS, rclass))
12931 rclass = GR_REGS;
12933 if (TARGET_MIPS16 && reg_class_subset_p (M16_REGS, rclass))
12934 rclass = M16_REGS;
12936 return rclass;
12939 /* RCLASS is a class involved in a REGISTER_MOVE_COST calculation.
12940 Return a "canonical" class to represent it in later calculations. */
12942 static reg_class_t
12943 mips_canonicalize_move_class (reg_class_t rclass)
12945 /* All moves involving accumulator registers have the same cost. */
12946 if (reg_class_subset_p (rclass, ACC_REGS))
12947 rclass = ACC_REGS;
12949 /* Likewise promote subclasses of general registers to the most
12950 interesting containing class. */
12951 if (TARGET_MIPS16 && reg_class_subset_p (rclass, M16_REGS))
12952 rclass = M16_REGS;
12953 else if (reg_class_subset_p (rclass, GENERAL_REGS))
12954 rclass = GENERAL_REGS;
12956 return rclass;
12959 /* Return the cost of moving a value from a register of class FROM to a GPR.
12960 Return 0 for classes that are unions of other classes handled by this
12961 function. */
12963 static int
12964 mips_move_to_gpr_cost (machine_mode mode, reg_class_t from)
12966 switch (from)
12968 case M16_REGS:
12969 case GENERAL_REGS:
12970 /* A MIPS16 MOVE instruction, or a non-MIPS16 MOVE macro. */
12971 return 2;
12973 case ACC_REGS:
12974 /* MFLO and MFHI. */
12975 return 6;
12977 case FP_REGS:
12978 /* MFC1, etc. */
12979 return 4;
12981 case COP0_REGS:
12982 case COP2_REGS:
12983 case COP3_REGS:
12984 /* This choice of value is historical. */
12985 return 5;
12987 default:
12988 return 0;
12992 /* Return the cost of moving a value from a GPR to a register of class TO.
12993 Return 0 for classes that are unions of other classes handled by this
12994 function. */
12996 static int
12997 mips_move_from_gpr_cost (machine_mode mode, reg_class_t to)
12999 switch (to)
13001 case M16_REGS:
13002 case GENERAL_REGS:
13003 /* A MIPS16 MOVE instruction, or a non-MIPS16 MOVE macro. */
13004 return 2;
13006 case ACC_REGS:
13007 /* MTLO and MTHI. */
13008 return 6;
13010 case FP_REGS:
13011 /* MTC1, etc. */
13012 return 4;
13014 case COP0_REGS:
13015 case COP2_REGS:
13016 case COP3_REGS:
13017 /* This choice of value is historical. */
13018 return 5;
13020 default:
13021 return 0;
13025 /* Implement TARGET_REGISTER_MOVE_COST. Return 0 for classes that are the
13026 maximum of the move costs for subclasses; regclass will work out
13027 the maximum for us. */
13029 static int
13030 mips_register_move_cost (machine_mode mode,
13031 reg_class_t from, reg_class_t to)
13033 reg_class_t dregs;
13034 int cost1, cost2;
13036 from = mips_canonicalize_move_class (from);
13037 to = mips_canonicalize_move_class (to);
13039 /* Handle moves that can be done without using general-purpose registers. */
13040 if (from == FP_REGS)
13042 if (to == FP_REGS && mips_mode_ok_for_mov_fmt_p (mode))
13043 /* MOV.FMT. */
13044 return 4;
13047 /* Handle cases in which only one class deviates from the ideal. */
13048 dregs = TARGET_MIPS16 ? M16_REGS : GENERAL_REGS;
13049 if (from == dregs)
13050 return mips_move_from_gpr_cost (mode, to);
13051 if (to == dregs)
13052 return mips_move_to_gpr_cost (mode, from);
13054 /* Handles cases that require a GPR temporary. */
13055 cost1 = mips_move_to_gpr_cost (mode, from);
13056 if (cost1 != 0)
13058 cost2 = mips_move_from_gpr_cost (mode, to);
13059 if (cost2 != 0)
13060 return cost1 + cost2;
13063 return 0;
13066 /* Implement TARGET_REGISTER_PRIORITY. */
13068 static int
13069 mips_register_priority (int hard_regno)
13071 /* Treat MIPS16 registers with higher priority than other regs. */
13072 if (TARGET_MIPS16
13073 && TEST_HARD_REG_BIT (reg_class_contents[M16_REGS], hard_regno))
13074 return 1;
13075 return 0;
13078 /* Implement TARGET_MEMORY_MOVE_COST. */
13080 static int
13081 mips_memory_move_cost (machine_mode mode, reg_class_t rclass, bool in)
13083 return (mips_cost->memory_latency
13084 + memory_move_secondary_cost (mode, rclass, in));
13087 /* Implement SECONDARY_MEMORY_NEEDED. */
13089 bool
13090 mips_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
13091 machine_mode mode)
13093 /* Ignore spilled pseudos. */
13094 if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
13095 return false;
13097 if (((class1 == FP_REGS) != (class2 == FP_REGS))
13098 && ((TARGET_FLOATXX && !ISA_HAS_MXHC1)
13099 || TARGET_O32_FP64A_ABI)
13100 && GET_MODE_SIZE (mode) >= 8)
13101 return true;
13103 return false;
13106 /* Return the register class required for a secondary register when
13107 copying between one of the registers in RCLASS and value X, which
13108 has mode MODE. X is the source of the move if IN_P, otherwise it
13109 is the destination. Return NO_REGS if no secondary register is
13110 needed. */
13112 enum reg_class
13113 mips_secondary_reload_class (enum reg_class rclass,
13114 machine_mode mode, rtx x, bool)
13116 int regno;
13118 /* If X is a constant that cannot be loaded into $25, it must be loaded
13119 into some other GPR. No other register class allows a direct move. */
13120 if (mips_dangerous_for_la25_p (x))
13121 return reg_class_subset_p (rclass, LEA_REGS) ? NO_REGS : LEA_REGS;
13123 regno = true_regnum (x);
13124 if (TARGET_MIPS16)
13126 /* In MIPS16 mode, every move must involve a member of M16_REGS. */
13127 if (!reg_class_subset_p (rclass, M16_REGS) && !M16_REG_P (regno))
13128 return M16_REGS;
13130 return NO_REGS;
13133 /* Copying from accumulator registers to anywhere other than a general
13134 register requires a temporary general register. */
13135 if (reg_class_subset_p (rclass, ACC_REGS))
13136 return GP_REG_P (regno) ? NO_REGS : GR_REGS;
13137 if (ACC_REG_P (regno))
13138 return reg_class_subset_p (rclass, GR_REGS) ? NO_REGS : GR_REGS;
13140 if (reg_class_subset_p (rclass, FP_REGS))
13142 if (regno < 0
13143 || (MEM_P (x)
13144 && (GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8)))
13145 /* In this case we can use lwc1, swc1, ldc1 or sdc1. We'll use
13146 pairs of lwc1s and swc1s if ldc1 and sdc1 are not supported. */
13147 return NO_REGS;
13149 if (MEM_P (x) && MSA_SUPPORTED_MODE_P (mode))
13150 /* In this case we can use MSA LD.* and ST.*. */
13151 return NO_REGS;
13153 if (GP_REG_P (regno) || x == CONST0_RTX (mode))
13154 /* In this case we can use mtc1, mfc1, dmtc1 or dmfc1. */
13155 return NO_REGS;
13157 if (CONSTANT_P (x) && !targetm.cannot_force_const_mem (mode, x))
13158 /* We can force the constant to memory and use lwc1
13159 and ldc1. As above, we will use pairs of lwc1s if
13160 ldc1 is not supported. */
13161 return NO_REGS;
13163 if (FP_REG_P (regno) && mips_mode_ok_for_mov_fmt_p (mode))
13164 /* In this case we can use mov.fmt. */
13165 return NO_REGS;
13167 /* Otherwise, we need to reload through an integer register. */
13168 return GR_REGS;
13170 if (FP_REG_P (regno))
13171 return reg_class_subset_p (rclass, GR_REGS) ? NO_REGS : GR_REGS;
13173 return NO_REGS;
13176 /* Implement TARGET_MODE_REP_EXTENDED. */
13178 static int
13179 mips_mode_rep_extended (machine_mode mode, machine_mode mode_rep)
13181 /* On 64-bit targets, SImode register values are sign-extended to DImode. */
13182 if (TARGET_64BIT && mode == SImode && mode_rep == DImode)
13183 return SIGN_EXTEND;
13185 return UNKNOWN;
13188 /* Implement TARGET_VALID_POINTER_MODE. */
13190 static bool
13191 mips_valid_pointer_mode (machine_mode mode)
13193 return mode == SImode || (TARGET_64BIT && mode == DImode);
13196 /* Implement TARGET_VECTOR_MODE_SUPPORTED_P. */
13198 static bool
13199 mips_vector_mode_supported_p (machine_mode mode)
13201 switch (mode)
13203 case V2SFmode:
13204 return TARGET_PAIRED_SINGLE_FLOAT;
13206 case V2HImode:
13207 case V4QImode:
13208 case V2HQmode:
13209 case V2UHQmode:
13210 case V2HAmode:
13211 case V2UHAmode:
13212 case V4QQmode:
13213 case V4UQQmode:
13214 return TARGET_DSP;
13216 case V2SImode:
13217 case V4HImode:
13218 case V8QImode:
13219 return TARGET_LOONGSON_VECTORS;
13221 default:
13222 return MSA_SUPPORTED_MODE_P (mode);
13226 /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. */
13228 static bool
13229 mips_scalar_mode_supported_p (machine_mode mode)
13231 if (ALL_FIXED_POINT_MODE_P (mode)
13232 && GET_MODE_PRECISION (mode) <= 2 * BITS_PER_WORD)
13233 return true;
13235 return default_scalar_mode_supported_p (mode);
13238 /* Implement TARGET_VECTORIZE_PREFERRED_SIMD_MODE. */
13240 static machine_mode
13241 mips_preferred_simd_mode (machine_mode mode)
13243 if (TARGET_PAIRED_SINGLE_FLOAT
13244 && mode == SFmode)
13245 return V2SFmode;
13247 if (! TARGET_MSA)
13248 return word_mode;
13250 switch (mode)
13252 case QImode:
13253 return V16QImode;
13254 case HImode:
13255 return V8HImode;
13256 case SImode:
13257 return V4SImode;
13258 case DImode:
13259 return V2DImode;
13261 case SFmode:
13262 return V4SFmode;
13264 case DFmode:
13265 return V2DFmode;
13267 default:
13268 break;
13270 return word_mode;
13273 static unsigned int
13274 mips_autovectorize_vector_sizes (void)
13276 return TARGET_MSA ? 16 : 0;
13279 /* Implement TARGET_INIT_LIBFUNCS. */
13281 static void
13282 mips_init_libfuncs (void)
13284 if (TARGET_FIX_VR4120)
13286 /* Register the special divsi3 and modsi3 functions needed to work
13287 around VR4120 division errata. */
13288 set_optab_libfunc (sdiv_optab, SImode, "__vr4120_divsi3");
13289 set_optab_libfunc (smod_optab, SImode, "__vr4120_modsi3");
13292 if (TARGET_MIPS16 && TARGET_HARD_FLOAT_ABI)
13294 /* Register the MIPS16 -mhard-float stubs. */
13295 set_optab_libfunc (add_optab, SFmode, "__mips16_addsf3");
13296 set_optab_libfunc (sub_optab, SFmode, "__mips16_subsf3");
13297 set_optab_libfunc (smul_optab, SFmode, "__mips16_mulsf3");
13298 set_optab_libfunc (sdiv_optab, SFmode, "__mips16_divsf3");
13300 set_optab_libfunc (eq_optab, SFmode, "__mips16_eqsf2");
13301 set_optab_libfunc (ne_optab, SFmode, "__mips16_nesf2");
13302 set_optab_libfunc (gt_optab, SFmode, "__mips16_gtsf2");
13303 set_optab_libfunc (ge_optab, SFmode, "__mips16_gesf2");
13304 set_optab_libfunc (lt_optab, SFmode, "__mips16_ltsf2");
13305 set_optab_libfunc (le_optab, SFmode, "__mips16_lesf2");
13306 set_optab_libfunc (unord_optab, SFmode, "__mips16_unordsf2");
13308 set_conv_libfunc (sfix_optab, SImode, SFmode, "__mips16_fix_truncsfsi");
13309 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__mips16_floatsisf");
13310 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__mips16_floatunsisf");
13312 if (TARGET_DOUBLE_FLOAT)
13314 set_optab_libfunc (add_optab, DFmode, "__mips16_adddf3");
13315 set_optab_libfunc (sub_optab, DFmode, "__mips16_subdf3");
13316 set_optab_libfunc (smul_optab, DFmode, "__mips16_muldf3");
13317 set_optab_libfunc (sdiv_optab, DFmode, "__mips16_divdf3");
13319 set_optab_libfunc (eq_optab, DFmode, "__mips16_eqdf2");
13320 set_optab_libfunc (ne_optab, DFmode, "__mips16_nedf2");
13321 set_optab_libfunc (gt_optab, DFmode, "__mips16_gtdf2");
13322 set_optab_libfunc (ge_optab, DFmode, "__mips16_gedf2");
13323 set_optab_libfunc (lt_optab, DFmode, "__mips16_ltdf2");
13324 set_optab_libfunc (le_optab, DFmode, "__mips16_ledf2");
13325 set_optab_libfunc (unord_optab, DFmode, "__mips16_unorddf2");
13327 set_conv_libfunc (sext_optab, DFmode, SFmode,
13328 "__mips16_extendsfdf2");
13329 set_conv_libfunc (trunc_optab, SFmode, DFmode,
13330 "__mips16_truncdfsf2");
13331 set_conv_libfunc (sfix_optab, SImode, DFmode,
13332 "__mips16_fix_truncdfsi");
13333 set_conv_libfunc (sfloat_optab, DFmode, SImode,
13334 "__mips16_floatsidf");
13335 set_conv_libfunc (ufloat_optab, DFmode, SImode,
13336 "__mips16_floatunsidf");
13340 /* The MIPS16 ISA does not have an encoding for "sync", so we rely
13341 on an external non-MIPS16 routine to implement __sync_synchronize.
13342 Similarly for the rest of the ll/sc libfuncs. */
13343 if (TARGET_MIPS16)
13345 synchronize_libfunc = init_one_libfunc ("__sync_synchronize");
13346 init_sync_libfuncs (UNITS_PER_WORD);
13350 /* Build up a multi-insn sequence that loads label TARGET into $AT. */
13352 static void
13353 mips_process_load_label (rtx target)
13355 rtx base, gp, intop;
13356 HOST_WIDE_INT offset;
13358 mips_multi_start ();
13359 switch (mips_abi)
13361 case ABI_N32:
13362 mips_multi_add_insn ("lw\t%@,%%got_page(%0)(%+)", target, 0);
13363 mips_multi_add_insn ("addiu\t%@,%@,%%got_ofst(%0)", target, 0);
13364 break;
13366 case ABI_64:
13367 mips_multi_add_insn ("ld\t%@,%%got_page(%0)(%+)", target, 0);
13368 mips_multi_add_insn ("daddiu\t%@,%@,%%got_ofst(%0)", target, 0);
13369 break;
13371 default:
13372 gp = pic_offset_table_rtx;
13373 if (mips_cfun_has_cprestore_slot_p ())
13375 gp = gen_rtx_REG (Pmode, AT_REGNUM);
13376 mips_get_cprestore_base_and_offset (&base, &offset, true);
13377 if (!SMALL_OPERAND (offset))
13379 intop = GEN_INT (CONST_HIGH_PART (offset));
13380 mips_multi_add_insn ("lui\t%0,%1", gp, intop, 0);
13381 mips_multi_add_insn ("addu\t%0,%0,%1", gp, base, 0);
13383 base = gp;
13384 offset = CONST_LOW_PART (offset);
13386 intop = GEN_INT (offset);
13387 if (ISA_HAS_LOAD_DELAY)
13388 mips_multi_add_insn ("lw\t%0,%1(%2)%#", gp, intop, base, 0);
13389 else
13390 mips_multi_add_insn ("lw\t%0,%1(%2)", gp, intop, base, 0);
13392 if (ISA_HAS_LOAD_DELAY)
13393 mips_multi_add_insn ("lw\t%@,%%got(%0)(%1)%#", target, gp, 0);
13394 else
13395 mips_multi_add_insn ("lw\t%@,%%got(%0)(%1)", target, gp, 0);
13396 mips_multi_add_insn ("addiu\t%@,%@,%%lo(%0)", target, 0);
13397 break;
13401 /* Return the number of instructions needed to load a label into $AT. */
13403 static unsigned int
13404 mips_load_label_num_insns (void)
13406 if (cfun->machine->load_label_num_insns == 0)
13408 mips_process_load_label (pc_rtx);
13409 cfun->machine->load_label_num_insns = mips_multi_num_insns;
13411 return cfun->machine->load_label_num_insns;
13414 /* Emit an asm sequence to start a noat block and load the address
13415 of a label into $1. */
13417 void
13418 mips_output_load_label (rtx target)
13420 mips_push_asm_switch (&mips_noat);
13421 if (TARGET_EXPLICIT_RELOCS)
13423 mips_process_load_label (target);
13424 mips_multi_write ();
13426 else
13428 if (Pmode == DImode)
13429 output_asm_insn ("dla\t%@,%0", &target);
13430 else
13431 output_asm_insn ("la\t%@,%0", &target);
13435 /* Return the length of INSN. LENGTH is the initial length computed by
13436 attributes in the machine-description file. */
13439 mips_adjust_insn_length (rtx insn, int length)
13441 /* mips.md uses MAX_PIC_BRANCH_LENGTH as a placeholder for the length
13442 of a PIC long-branch sequence. Substitute the correct value. */
13443 if (length == MAX_PIC_BRANCH_LENGTH
13444 && JUMP_P (insn)
13445 && INSN_CODE (insn) >= 0
13446 && get_attr_type (insn) == TYPE_BRANCH)
13448 /* Add the branch-over instruction and its delay slot, if this
13449 is a conditional branch. */
13450 length = simplejump_p (insn) ? 0 : 8;
13452 /* Add the size of a load into $AT. */
13453 length += BASE_INSN_LENGTH * mips_load_label_num_insns ();
13455 /* Add the length of an indirect jump, ignoring the delay slot. */
13456 length += TARGET_COMPRESSION ? 2 : 4;
13459 /* A unconditional jump has an unfilled delay slot if it is not part
13460 of a sequence. A conditional jump normally has a delay slot, but
13461 does not on MIPS16. */
13462 if (CALL_P (insn) || (TARGET_MIPS16 ? simplejump_p (insn) : JUMP_P (insn)))
13463 length += TARGET_MIPS16 ? 2 : 4;
13465 /* See how many nops might be needed to avoid hardware hazards. */
13466 if (!cfun->machine->ignore_hazard_length_p
13467 && INSN_P (insn)
13468 && INSN_CODE (insn) >= 0)
13469 switch (get_attr_hazard (insn))
13471 case HAZARD_NONE:
13472 break;
13474 case HAZARD_DELAY:
13475 case HAZARD_FORBIDDEN_SLOT:
13476 length += NOP_INSN_LENGTH;
13477 break;
13479 case HAZARD_HILO:
13480 length += NOP_INSN_LENGTH * 2;
13481 break;
13484 return length;
13487 /* Return the asm template for a call. OPERANDS are the operands, TARGET_OPNO
13488 is the operand number of the target. SIZE_OPNO is the operand number of
13489 the argument size operand that can optionally hold the call attributes. If
13490 SIZE_OPNO is not -1 and the call is indirect, use the function symbol from
13491 the call attributes to attach a R_MIPS_JALR relocation to the call.
13493 When generating GOT code without explicit relocation operators, all calls
13494 should use assembly macros. Otherwise, all indirect calls should use "jr"
13495 or "jalr"; we will arrange to restore $gp afterwards if necessary. Finally,
13496 we can only generate direct calls for -mabicalls by temporarily switching
13497 to non-PIC mode.
13499 For microMIPS jal(r), we try to generate jal(r)s when a 16-bit
13500 instruction is in the delay slot of jal(r).
13502 Where compact branches are available, we try to use them if the delay slot
13503 has a NOP (or equivalently delay slots were not enabled for the instruction
13504 anyway). */
13506 const char *
13507 mips_output_jump (rtx *operands, int target_opno, int size_opno, bool link_p)
13509 static char buffer[300];
13510 char *s = buffer;
13511 bool reg_p = REG_P (operands[target_opno]);
13513 const char *and_link = link_p ? "al" : "";
13514 const char *reg = reg_p ? "r" : "";
13515 const char *compact = "";
13516 const char *nop = "%/";
13517 const char *short_delay = link_p ? "%!" : "";
13518 const char *insn_name = TARGET_CB_NEVER || reg_p ? "j" : "b";
13520 /* Compact branches can only be described when the ISA has support for them
13521 as both the compact formatter '%:' and the delay slot NOP formatter '%/'
13522 work as a mutually exclusive pair. I.e. a NOP is never required if a
13523 compact form is available. */
13524 if (!final_sequence
13525 && (TARGET_CB_MAYBE
13526 || (ISA_HAS_JRC && !link_p && reg_p)))
13528 compact = "c";
13529 nop = "";
13533 if (TARGET_USE_GOT && !TARGET_EXPLICIT_RELOCS)
13534 sprintf (s, "%%*%s%s\t%%%d%%/", insn_name, link_p ? "al" : "", target_opno);
13535 else
13537 if (!reg_p && TARGET_ABICALLS_PIC2)
13538 s += sprintf (s, ".option\tpic0\n\t");
13540 if (reg_p && mips_get_pic_call_symbol (operands, size_opno))
13542 s += sprintf (s, "%%*.reloc\t1f,R_MIPS_JALR,%%%d\n1:\t", size_opno);
13543 /* Not sure why this shouldn't permit a short delay but it did not
13544 allow it before so we still don't allow it. */
13545 short_delay = "";
13547 else
13548 s += sprintf (s, "%%*");
13550 s += sprintf (s, "%s%s%s%s%s\t%%%d%s", insn_name, and_link, reg, compact, short_delay,
13551 target_opno, nop);
13553 if (!reg_p && TARGET_ABICALLS_PIC2)
13554 s += sprintf (s, "\n\t.option\tpic2");
13556 return buffer;
13559 /* Return the assembly code for INSN, which has the operands given by
13560 OPERANDS, and which branches to OPERANDS[0] if some condition is true.
13561 BRANCH_IF_TRUE is the asm template that should be used if OPERANDS[0]
13562 is in range of a direct branch. BRANCH_IF_FALSE is an inverted
13563 version of BRANCH_IF_TRUE. */
13565 const char *
13566 mips_output_conditional_branch (rtx insn, rtx *operands,
13567 const char *branch_if_true,
13568 const char *branch_if_false)
13570 unsigned int length;
13571 rtx taken, not_taken;
13573 gcc_assert (LABEL_P (operands[0]));
13575 length = get_attr_length (insn);
13576 if (length <= 8)
13578 /* Just a simple conditional branch. */
13579 mips_branch_likely = final_sequence && INSN_ANNULLED_BRANCH_P (insn);
13580 return branch_if_true;
13583 /* Generate a reversed branch around a direct jump. This fallback does
13584 not use branch-likely instructions. */
13585 mips_branch_likely = false;
13586 not_taken = gen_label_rtx ();
13587 taken = operands[0];
13589 /* Generate the reversed branch to NOT_TAKEN. */
13590 operands[0] = not_taken;
13591 output_asm_insn (branch_if_false, operands);
13593 /* If INSN has a delay slot, we must provide delay slots for both the
13594 branch to NOT_TAKEN and the conditional jump. We must also ensure
13595 that INSN's delay slot is executed in the appropriate cases. */
13596 if (final_sequence)
13598 /* This first delay slot will always be executed, so use INSN's
13599 delay slot if is not annulled. */
13600 if (!INSN_ANNULLED_BRANCH_P (insn))
13602 final_scan_insn (XVECEXP (final_sequence, 0, 1),
13603 asm_out_file, optimize, 1, NULL);
13604 INSN_DELETED_P (XVECEXP (final_sequence, 0, 1)) = 1;
13606 else
13607 output_asm_insn ("nop", 0);
13608 fprintf (asm_out_file, "\n");
13611 /* Output the unconditional branch to TAKEN. */
13612 if (TARGET_ABSOLUTE_JUMPS && TARGET_CB_MAYBE)
13614 /* Add a hazard nop. */
13615 if (!final_sequence)
13617 output_asm_insn ("nop\t\t# hazard nop", 0);
13618 fprintf (asm_out_file, "\n");
13620 output_asm_insn (MIPS_ABSOLUTE_JUMP ("bc\t%0"), &taken);
13622 else if (TARGET_ABSOLUTE_JUMPS)
13623 output_asm_insn (MIPS_ABSOLUTE_JUMP ("j\t%0%/"), &taken);
13624 else
13626 mips_output_load_label (taken);
13627 if (TARGET_CB_MAYBE)
13628 output_asm_insn ("jrc\t%@%]", 0);
13629 else
13630 output_asm_insn ("jr\t%@%]%/", 0);
13633 /* Now deal with its delay slot; see above. */
13634 if (final_sequence)
13636 /* This delay slot will only be executed if the branch is taken.
13637 Use INSN's delay slot if is annulled. */
13638 if (INSN_ANNULLED_BRANCH_P (insn))
13640 final_scan_insn (XVECEXP (final_sequence, 0, 1),
13641 asm_out_file, optimize, 1, NULL);
13642 INSN_DELETED_P (XVECEXP (final_sequence, 0, 1)) = 1;
13644 else if (TARGET_CB_NEVER)
13645 output_asm_insn ("nop", 0);
13646 fprintf (asm_out_file, "\n");
13649 /* Output NOT_TAKEN. */
13650 targetm.asm_out.internal_label (asm_out_file, "L",
13651 CODE_LABEL_NUMBER (not_taken));
13652 return "";
13655 const char *
13656 mips_output_equal_conditional_branch (rtx insn, rtx *operands, bool inverted_p)
13658 const char *branch[2];
13659 /* For a simple BNEZ or BEQZ microMIPSr3 branch. */
13660 if (TARGET_MICROMIPS
13661 && mips_isa_rev <= 5
13662 && operands[3] == const0_rtx
13663 && get_attr_length (insn) <= 8)
13665 if (mips_cb == MIPS_CB_OPTIMAL)
13667 branch[!inverted_p] = "%*b%C1z%:\t%2,%0";
13668 branch[inverted_p] = "%*b%N1z%:\t%2,%0";
13670 else
13672 branch[!inverted_p] = "%*b%C1z\t%2,%0%/";
13673 branch[inverted_p] = "%*b%N1z\t%2,%0%/";
13676 else if (TARGET_CB_MAYBE)
13678 if (operands[3] == const0_rtx)
13680 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1z", "%2,%0");
13681 branch[inverted_p] = MIPS_BRANCH_C ("b%N1z", "%2,%0");
13683 else if (REGNO (operands[2]) != REGNO (operands[3]))
13685 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1", "%2,%3,%0");
13686 branch[inverted_p] = MIPS_BRANCH_C ("b%N1", "%2,%3,%0");
13688 else
13690 /* This case is stupid. Fix me. */
13691 if (GET_CODE (operands[1]) == NE)
13692 inverted_p = !inverted_p;
13694 branch[!inverted_p] = MIPS_BRANCH_C ("b", "%0");
13695 branch[inverted_p] = "%*\t\t# branch never";
13698 else
13700 branch[!inverted_p] = MIPS_BRANCH ("b%C1", "%2,%z3,%0");
13701 branch[inverted_p] = MIPS_BRANCH ("b%N1", "%2,%z3,%0");
13704 return mips_output_conditional_branch (insn, operands, branch[1], branch[0]);
13707 /* Return the assembly code for INSN, which branches to OPERANDS[0]
13708 if some ordering condition is true. The condition is given by
13709 OPERANDS[1] if !INVERTED_P, otherwise it is the inverse of
13710 OPERANDS[1]. OPERANDS[2] is the comparison's first operand;
13711 its second is always zero. */
13713 const char *
13714 mips_output_order_conditional_branch (rtx insn, rtx *operands, bool inverted_p)
13716 const char *branch[2];
13718 if (operands[3] != const0_rtx)
13720 if (REGNO (operands[2]) == REGNO (operands[3]))
13722 switch (GET_CODE (operands[1]))
13724 case LT:
13725 case LTU:
13726 inverted_p = !inverted_p;
13727 /* Fall through. */
13728 case GE:
13729 case GEU:
13730 branch[!inverted_p] = MIPS_BRANCH_C ("b", "%0");
13731 branch[inverted_p] = "%*\t\t# branch never";
13732 break;
13733 default:
13734 gcc_unreachable ();
13737 else
13739 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1", "%2,%3,%0");
13740 branch[inverted_p] = MIPS_BRANCH_C ("b%N1", "%2,%3,%0");
13743 else
13745 /* Make BRANCH[1] branch to OPERANDS[0] when the condition is true.
13746 Make BRANCH[0] branch on the inverse condition. */
13747 switch (GET_CODE (operands[1]))
13749 /* These cases are equivalent to comparisons against zero. */
13750 case LEU:
13751 inverted_p = !inverted_p;
13752 /* Fall through. */
13753 case GTU:
13754 if (TARGET_CB_MAYBE)
13756 branch[!inverted_p] = MIPS_BRANCH_C ("bnez", "%2,%0");
13757 branch[inverted_p] = MIPS_BRANCH_C ("beqz", "%2,%0");
13759 else
13761 branch[!inverted_p] = MIPS_BRANCH ("bne", "%2,%.,%0");
13762 branch[inverted_p] = MIPS_BRANCH ("beq", "%2,%.,%0");
13764 break;
13766 /* These cases are always true or always false. */
13767 case LTU:
13768 inverted_p = !inverted_p;
13769 /* Fall through. */
13770 case GEU:
13771 if (TARGET_CB_MAYBE)
13773 branch[!inverted_p] = MIPS_BRANCH_C ("b", "%0");
13774 branch[inverted_p] = "%*\t\t# branch never";
13776 else
13778 branch[!inverted_p] = MIPS_BRANCH ("beq", "%.,%.,%0");
13779 branch[inverted_p] = MIPS_BRANCH ("bne", "%.,%.,%0");
13781 break;
13783 default:
13784 if (TARGET_CB_MAYBE)
13786 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1z", "%2,%0");
13787 branch[inverted_p] = MIPS_BRANCH_C ("b%N1z", "%2,%0");
13789 else
13791 branch[!inverted_p] = MIPS_BRANCH ("b%C1z", "%2,%0");
13792 branch[inverted_p] = MIPS_BRANCH ("b%N1z", "%2,%0");
13794 break;
13797 return mips_output_conditional_branch (insn, operands, branch[1], branch[0]);
13800 /* Start a block of code that needs access to the LL, SC and SYNC
13801 instructions. */
13803 static void
13804 mips_start_ll_sc_sync_block (void)
13806 if (!ISA_HAS_LL_SC)
13808 output_asm_insn (".set\tpush", 0);
13809 if (TARGET_64BIT)
13810 output_asm_insn (".set\tmips3", 0);
13811 else
13812 output_asm_insn (".set\tmips2", 0);
13816 /* End a block started by mips_start_ll_sc_sync_block. */
13818 static void
13819 mips_end_ll_sc_sync_block (void)
13821 if (!ISA_HAS_LL_SC)
13822 output_asm_insn (".set\tpop", 0);
13825 /* Output and/or return the asm template for a sync instruction. */
13827 const char *
13828 mips_output_sync (void)
13830 mips_start_ll_sc_sync_block ();
13831 output_asm_insn ("sync", 0);
13832 mips_end_ll_sc_sync_block ();
13833 return "";
13836 /* Return the asm template associated with sync_insn1 value TYPE.
13837 IS_64BIT_P is true if we want a 64-bit rather than 32-bit operation. */
13839 static const char *
13840 mips_sync_insn1_template (enum attr_sync_insn1 type, bool is_64bit_p)
13842 switch (type)
13844 case SYNC_INSN1_MOVE:
13845 return "move\t%0,%z2";
13846 case SYNC_INSN1_LI:
13847 return "li\t%0,%2";
13848 case SYNC_INSN1_ADDU:
13849 return is_64bit_p ? "daddu\t%0,%1,%z2" : "addu\t%0,%1,%z2";
13850 case SYNC_INSN1_ADDIU:
13851 return is_64bit_p ? "daddiu\t%0,%1,%2" : "addiu\t%0,%1,%2";
13852 case SYNC_INSN1_SUBU:
13853 return is_64bit_p ? "dsubu\t%0,%1,%z2" : "subu\t%0,%1,%z2";
13854 case SYNC_INSN1_AND:
13855 return "and\t%0,%1,%z2";
13856 case SYNC_INSN1_ANDI:
13857 return "andi\t%0,%1,%2";
13858 case SYNC_INSN1_OR:
13859 return "or\t%0,%1,%z2";
13860 case SYNC_INSN1_ORI:
13861 return "ori\t%0,%1,%2";
13862 case SYNC_INSN1_XOR:
13863 return "xor\t%0,%1,%z2";
13864 case SYNC_INSN1_XORI:
13865 return "xori\t%0,%1,%2";
13867 gcc_unreachable ();
13870 /* Return the asm template associated with sync_insn2 value TYPE. */
13872 static const char *
13873 mips_sync_insn2_template (enum attr_sync_insn2 type)
13875 switch (type)
13877 case SYNC_INSN2_NOP:
13878 gcc_unreachable ();
13879 case SYNC_INSN2_AND:
13880 return "and\t%0,%1,%z2";
13881 case SYNC_INSN2_XOR:
13882 return "xor\t%0,%1,%z2";
13883 case SYNC_INSN2_NOT:
13884 return "nor\t%0,%1,%.";
13886 gcc_unreachable ();
13889 /* OPERANDS are the operands to a sync loop instruction and INDEX is
13890 the value of the one of the sync_* attributes. Return the operand
13891 referred to by the attribute, or DEFAULT_VALUE if the insn doesn't
13892 have the associated attribute. */
13894 static rtx
13895 mips_get_sync_operand (rtx *operands, int index, rtx default_value)
13897 if (index > 0)
13898 default_value = operands[index - 1];
13899 return default_value;
13902 /* INSN is a sync loop with operands OPERANDS. Build up a multi-insn
13903 sequence for it. */
13905 static void
13906 mips_process_sync_loop (rtx insn, rtx *operands)
13908 rtx at, mem, oldval, newval, inclusive_mask, exclusive_mask;
13909 rtx required_oldval, insn1_op2, tmp1, tmp2, tmp3, cmp;
13910 unsigned int tmp3_insn;
13911 enum attr_sync_insn1 insn1;
13912 enum attr_sync_insn2 insn2;
13913 bool is_64bit_p;
13914 int memmodel_attr;
13915 enum memmodel model;
13917 /* Read an operand from the sync_WHAT attribute and store it in
13918 variable WHAT. DEFAULT is the default value if no attribute
13919 is specified. */
13920 #define READ_OPERAND(WHAT, DEFAULT) \
13921 WHAT = mips_get_sync_operand (operands, (int) get_attr_sync_##WHAT (insn), \
13922 DEFAULT)
13924 /* Read the memory. */
13925 READ_OPERAND (mem, 0);
13926 gcc_assert (mem);
13927 is_64bit_p = (GET_MODE_BITSIZE (GET_MODE (mem)) == 64);
13929 /* Read the other attributes. */
13930 at = gen_rtx_REG (GET_MODE (mem), AT_REGNUM);
13931 READ_OPERAND (oldval, at);
13932 READ_OPERAND (cmp, 0);
13933 READ_OPERAND (newval, at);
13934 READ_OPERAND (inclusive_mask, 0);
13935 READ_OPERAND (exclusive_mask, 0);
13936 READ_OPERAND (required_oldval, 0);
13937 READ_OPERAND (insn1_op2, 0);
13938 insn1 = get_attr_sync_insn1 (insn);
13939 insn2 = get_attr_sync_insn2 (insn);
13941 /* Don't bother setting CMP result that is never used. */
13942 if (cmp && find_reg_note (insn, REG_UNUSED, cmp))
13943 cmp = 0;
13945 memmodel_attr = get_attr_sync_memmodel (insn);
13946 switch (memmodel_attr)
13948 case 10:
13949 model = MEMMODEL_ACQ_REL;
13950 break;
13951 case 11:
13952 model = MEMMODEL_ACQUIRE;
13953 break;
13954 default:
13955 model = (enum memmodel) INTVAL (operands[memmodel_attr]);
13958 mips_multi_start ();
13960 /* Output the release side of the memory barrier. */
13961 if (need_atomic_barrier_p (model, true))
13963 if (required_oldval == 0 && TARGET_OCTEON)
13965 /* Octeon doesn't reorder reads, so a full barrier can be
13966 created by using SYNCW to order writes combined with the
13967 write from the following SC. When the SC successfully
13968 completes, we know that all preceding writes are also
13969 committed to the coherent memory system. It is possible
13970 for a single SYNCW to fail, but a pair of them will never
13971 fail, so we use two. */
13972 mips_multi_add_insn ("syncw", NULL);
13973 mips_multi_add_insn ("syncw", NULL);
13975 else
13976 mips_multi_add_insn ("sync", NULL);
13979 /* Output the branch-back label. */
13980 mips_multi_add_label ("1:");
13982 /* OLDVAL = *MEM. */
13983 mips_multi_add_insn (is_64bit_p ? "lld\t%0,%1" : "ll\t%0,%1",
13984 oldval, mem, NULL);
13986 /* if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2. */
13987 if (required_oldval)
13989 if (inclusive_mask == 0)
13990 tmp1 = oldval;
13991 else
13993 gcc_assert (oldval != at);
13994 mips_multi_add_insn ("and\t%0,%1,%2",
13995 at, oldval, inclusive_mask, NULL);
13996 tmp1 = at;
13998 if (TARGET_CB_NEVER)
13999 mips_multi_add_insn ("bne\t%0,%z1,2f", tmp1, required_oldval, NULL);
14001 /* CMP = 0 [delay slot]. */
14002 if (cmp)
14003 mips_multi_add_insn ("li\t%0,0", cmp, NULL);
14005 if (TARGET_CB_MAYBE && required_oldval == const0_rtx)
14006 mips_multi_add_insn ("bnezc\t%0,2f", tmp1, NULL);
14007 else if (TARGET_CB_MAYBE)
14008 mips_multi_add_insn ("bnec\t%0,%1,2f", tmp1, required_oldval, NULL);
14012 /* $TMP1 = OLDVAL & EXCLUSIVE_MASK. */
14013 if (exclusive_mask == 0)
14014 tmp1 = const0_rtx;
14015 else
14017 gcc_assert (oldval != at);
14018 mips_multi_add_insn ("and\t%0,%1,%z2",
14019 at, oldval, exclusive_mask, NULL);
14020 tmp1 = at;
14023 /* $TMP2 = INSN1 (OLDVAL, INSN1_OP2).
14025 We can ignore moves if $TMP4 != INSN1_OP2, since we'll still emit
14026 at least one instruction in that case. */
14027 if (insn1 == SYNC_INSN1_MOVE
14028 && (tmp1 != const0_rtx || insn2 != SYNC_INSN2_NOP))
14029 tmp2 = insn1_op2;
14030 else
14032 mips_multi_add_insn (mips_sync_insn1_template (insn1, is_64bit_p),
14033 newval, oldval, insn1_op2, NULL);
14034 tmp2 = newval;
14037 /* $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK). */
14038 if (insn2 == SYNC_INSN2_NOP)
14039 tmp3 = tmp2;
14040 else
14042 mips_multi_add_insn (mips_sync_insn2_template (insn2),
14043 newval, tmp2, inclusive_mask, NULL);
14044 tmp3 = newval;
14046 tmp3_insn = mips_multi_last_index ();
14048 /* $AT = $TMP1 | $TMP3. */
14049 if (tmp1 == const0_rtx || tmp3 == const0_rtx)
14051 mips_multi_set_operand (tmp3_insn, 0, at);
14052 tmp3 = at;
14054 else
14056 gcc_assert (tmp1 != tmp3);
14057 mips_multi_add_insn ("or\t%0,%1,%2", at, tmp1, tmp3, NULL);
14060 /* if (!commit (*MEM = $AT)) goto 1.
14062 This will sometimes be a delayed branch; see the write code below
14063 for details. */
14064 mips_multi_add_insn (is_64bit_p ? "scd\t%0,%1" : "sc\t%0,%1", at, mem, NULL);
14066 /* When using branch likely (-mfix-r10000), the delay slot instruction
14067 will be annulled on false. The normal delay slot instructions
14068 calculate the overall result of the atomic operation and must not
14069 be annulled. To ensure this behaviour unconditionally use a NOP
14070 in the delay slot for the branch likely case. */
14072 if (TARGET_CB_MAYBE)
14073 mips_multi_add_insn ("beqzc\t%0,1b", at, NULL);
14074 else
14075 mips_multi_add_insn ("beq%?\t%0,%.,1b%~", at, NULL);
14077 /* if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]. */
14078 if (insn1 != SYNC_INSN1_MOVE && insn1 != SYNC_INSN1_LI && tmp3 != newval)
14080 mips_multi_copy_insn (tmp3_insn);
14081 mips_multi_set_operand (mips_multi_last_index (), 0, newval);
14083 else if (!(required_oldval && cmp) && !mips_branch_likely)
14084 mips_multi_add_insn ("nop", NULL);
14086 /* CMP = 1 -- either standalone or in a delay slot. */
14087 if (required_oldval && cmp)
14088 mips_multi_add_insn ("li\t%0,1", cmp, NULL);
14090 /* Output the acquire side of the memory barrier. */
14091 if (TARGET_SYNC_AFTER_SC && need_atomic_barrier_p (model, false))
14092 mips_multi_add_insn ("sync", NULL);
14094 /* Output the exit label, if needed. */
14095 if (required_oldval)
14096 mips_multi_add_label ("2:");
14098 #undef READ_OPERAND
14101 /* Output and/or return the asm template for sync loop INSN, which has
14102 the operands given by OPERANDS. */
14104 const char *
14105 mips_output_sync_loop (rtx insn, rtx *operands)
14107 /* Use branch-likely instructions to work around the LL/SC R10000
14108 errata. */
14109 mips_branch_likely = TARGET_FIX_R10000;
14111 mips_process_sync_loop (insn, operands);
14113 mips_push_asm_switch (&mips_noreorder);
14114 mips_push_asm_switch (&mips_nomacro);
14115 mips_push_asm_switch (&mips_noat);
14116 mips_start_ll_sc_sync_block ();
14118 mips_multi_write ();
14120 mips_end_ll_sc_sync_block ();
14121 mips_pop_asm_switch (&mips_noat);
14122 mips_pop_asm_switch (&mips_nomacro);
14123 mips_pop_asm_switch (&mips_noreorder);
14125 return "";
14128 /* Return the number of individual instructions in sync loop INSN,
14129 which has the operands given by OPERANDS. */
14131 unsigned int
14132 mips_sync_loop_insns (rtx insn, rtx *operands)
14134 /* Use branch-likely instructions to work around the LL/SC R10000
14135 errata. */
14136 mips_branch_likely = TARGET_FIX_R10000;
14137 mips_process_sync_loop (insn, operands);
14138 return mips_multi_num_insns;
14141 /* Return the assembly code for DIV or DDIV instruction DIVISION, which has
14142 the operands given by OPERANDS. Add in a divide-by-zero check if needed.
14144 When working around R4000 and R4400 errata, we need to make sure that
14145 the division is not immediately followed by a shift[1][2]. We also
14146 need to stop the division from being put into a branch delay slot[3].
14147 The easiest way to avoid both problems is to add a nop after the
14148 division. When a divide-by-zero check is needed, this nop can be
14149 used to fill the branch delay slot.
14151 [1] If a double-word or a variable shift executes immediately
14152 after starting an integer division, the shift may give an
14153 incorrect result. See quotations of errata #16 and #28 from
14154 "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
14155 in mips.md for details.
14157 [2] A similar bug to [1] exists for all revisions of the
14158 R4000 and the R4400 when run in an MC configuration.
14159 From "MIPS R4000MC Errata, Processor Revision 2.2 and 3.0":
14161 "19. In this following sequence:
14163 ddiv (or ddivu or div or divu)
14164 dsll32 (or dsrl32, dsra32)
14166 if an MPT stall occurs, while the divide is slipping the cpu
14167 pipeline, then the following double shift would end up with an
14168 incorrect result.
14170 Workaround: The compiler needs to avoid generating any
14171 sequence with divide followed by extended double shift."
14173 This erratum is also present in "MIPS R4400MC Errata, Processor
14174 Revision 1.0" and "MIPS R4400MC Errata, Processor Revision 2.0
14175 & 3.0" as errata #10 and #4, respectively.
14177 [3] From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
14178 (also valid for MIPS R4000MC processors):
14180 "52. R4000SC: This bug does not apply for the R4000PC.
14182 There are two flavors of this bug:
14184 1) If the instruction just after divide takes an RF exception
14185 (tlb-refill, tlb-invalid) and gets an instruction cache
14186 miss (both primary and secondary) and the line which is
14187 currently in secondary cache at this index had the first
14188 data word, where the bits 5..2 are set, then R4000 would
14189 get a wrong result for the div.
14193 div r8, r9
14194 ------------------- # end-of page. -tlb-refill
14198 div r8, r9
14199 ------------------- # end-of page. -tlb-invalid
14202 2) If the divide is in the taken branch delay slot, where the
14203 target takes RF exception and gets an I-cache miss for the
14204 exception vector or where I-cache miss occurs for the
14205 target address, under the above mentioned scenarios, the
14206 div would get wrong results.
14209 j r2 # to next page mapped or unmapped
14210 div r8,r9 # this bug would be there as long
14211 # as there is an ICache miss and
14212 nop # the "data pattern" is present
14215 beq r0, r0, NextPage # to Next page
14216 div r8,r9
14219 This bug is present for div, divu, ddiv, and ddivu
14220 instructions.
14222 Workaround: For item 1), OS could make sure that the next page
14223 after the divide instruction is also mapped. For item 2), the
14224 compiler could make sure that the divide instruction is not in
14225 the branch delay slot."
14227 These processors have PRId values of 0x00004220 and 0x00004300 for
14228 the R4000 and 0x00004400, 0x00004500 and 0x00004600 for the R4400. */
14230 const char *
14231 mips_output_division (const char *division, rtx *operands)
14233 const char *s;
14235 s = division;
14236 if (TARGET_FIX_R4000 || TARGET_FIX_R4400)
14238 output_asm_insn (s, operands);
14239 s = "nop";
14241 if (TARGET_CHECK_ZERO_DIV)
14243 if (TARGET_MIPS16)
14245 output_asm_insn (s, operands);
14246 s = "bnez\t%2,1f\n\tbreak\t7\n1:";
14248 else if (GENERATE_DIVIDE_TRAPS)
14250 /* Avoid long replay penalty on load miss by putting the trap before
14251 the divide. */
14252 if (TUNE_74K)
14253 output_asm_insn ("teq\t%2,%.,7", operands);
14254 else
14256 output_asm_insn (s, operands);
14257 s = "teq\t%2,%.,7";
14260 else
14262 output_asm_insn ("%(bne\t%2,%.,1f", operands);
14263 output_asm_insn (s, operands);
14264 s = "break\t7%)\n1:";
14267 return s;
14270 const char *
14271 mips_msa_output_division (const char *division, rtx *operands)
14273 const char *s;
14275 s = division;
14276 if (TARGET_CHECK_ZERO_DIV)
14278 output_asm_insn ("%(bnz.%v0\t%w2,1f", operands);
14279 output_asm_insn (s, operands);
14280 s = "break\t7%)\n1:";
14282 return s;
14285 /* Return true if destination of IN_INSN is used as add source in
14286 OUT_INSN. Both IN_INSN and OUT_INSN are of type fmadd. Example:
14287 madd.s dst, x, y, z
14288 madd.s a, dst, b, c */
14290 bool
14291 mips_fmadd_bypass (rtx out_insn, rtx in_insn)
14293 int dst_reg, src_reg;
14295 gcc_assert (get_attr_type (in_insn) == TYPE_FMADD);
14296 gcc_assert (get_attr_type (out_insn) == TYPE_FMADD);
14298 extract_insn (in_insn);
14299 dst_reg = REG_P (recog_data.operand[0]);
14301 extract_insn (out_insn);
14302 src_reg = REG_P (recog_data.operand[1]);
14304 if (dst_reg == src_reg)
14305 return true;
14307 return false;
14310 /* Return true if IN_INSN is a multiply-add or multiply-subtract
14311 instruction and if OUT_INSN assigns to the accumulator operand. */
14313 bool
14314 mips_linked_madd_p (rtx out_insn, rtx in_insn)
14316 enum attr_accum_in accum_in;
14317 int accum_in_opnum;
14318 rtx accum_in_op;
14320 if (recog_memoized (in_insn) < 0)
14321 return false;
14323 accum_in = get_attr_accum_in (in_insn);
14324 if (accum_in == ACCUM_IN_NONE)
14325 return false;
14327 accum_in_opnum = accum_in - ACCUM_IN_0;
14329 extract_insn (in_insn);
14330 gcc_assert (accum_in_opnum < recog_data.n_operands);
14331 accum_in_op = recog_data.operand[accum_in_opnum];
14333 return reg_set_p (accum_in_op, out_insn);
14336 /* True if the dependency between OUT_INSN and IN_INSN is on the store
14337 data rather than the address. We need this because the cprestore
14338 pattern is type "store", but is defined using an UNSPEC_VOLATILE,
14339 which causes the default routine to abort. We just return false
14340 for that case. */
14342 bool
14343 mips_store_data_bypass_p (rtx out_insn, rtx in_insn)
14345 if (GET_CODE (PATTERN (in_insn)) == UNSPEC_VOLATILE)
14346 return false;
14348 return !store_data_bypass_p (out_insn, in_insn);
14352 /* Variables and flags used in scheduler hooks when tuning for
14353 Loongson 2E/2F. */
14354 static struct
14356 /* Variables to support Loongson 2E/2F round-robin [F]ALU1/2 dispatch
14357 strategy. */
14359 /* If true, then next ALU1/2 instruction will go to ALU1. */
14360 bool alu1_turn_p;
14362 /* If true, then next FALU1/2 unstruction will go to FALU1. */
14363 bool falu1_turn_p;
14365 /* Codes to query if [f]alu{1,2}_core units are subscribed or not. */
14366 int alu1_core_unit_code;
14367 int alu2_core_unit_code;
14368 int falu1_core_unit_code;
14369 int falu2_core_unit_code;
14371 /* True if current cycle has a multi instruction.
14372 This flag is used in mips_ls2_dfa_post_advance_cycle. */
14373 bool cycle_has_multi_p;
14375 /* Instructions to subscribe ls2_[f]alu{1,2}_turn_enabled units.
14376 These are used in mips_ls2_dfa_post_advance_cycle to initialize
14377 DFA state.
14378 E.g., when alu1_turn_enabled_insn is issued it makes next ALU1/2
14379 instruction to go ALU1. */
14380 rtx alu1_turn_enabled_insn;
14381 rtx alu2_turn_enabled_insn;
14382 rtx falu1_turn_enabled_insn;
14383 rtx falu2_turn_enabled_insn;
14384 } mips_ls2;
14386 /* Implement TARGET_SCHED_ADJUST_COST. We assume that anti and output
14387 dependencies have no cost, except on the 20Kc where output-dependence
14388 is treated like input-dependence. */
14390 static int
14391 mips_adjust_cost (rtx insn ATTRIBUTE_UNUSED, rtx link,
14392 rtx dep ATTRIBUTE_UNUSED, int cost)
14394 if (REG_NOTE_KIND (link) == REG_DEP_OUTPUT
14395 && TUNE_20KC)
14396 return cost;
14397 if (REG_NOTE_KIND (link) != 0)
14398 return 0;
14399 return cost;
14402 /* Return the number of instructions that can be issued per cycle. */
14404 static int
14405 mips_issue_rate (void)
14407 switch (mips_tune)
14409 case PROCESSOR_74KC:
14410 case PROCESSOR_74KF2_1:
14411 case PROCESSOR_74KF1_1:
14412 case PROCESSOR_74KF3_2:
14413 /* The 74k is not strictly quad-issue cpu, but can be seen as one
14414 by the scheduler. It can issue 1 ALU, 1 AGEN and 2 FPU insns,
14415 but in reality only a maximum of 3 insns can be issued as
14416 floating-point loads and stores also require a slot in the
14417 AGEN pipe. */
14418 case PROCESSOR_R10000:
14419 /* All R10K Processors are quad-issue (being the first MIPS
14420 processors to support this feature). */
14421 return 4;
14423 case PROCESSOR_20KC:
14424 case PROCESSOR_R4130:
14425 case PROCESSOR_R5400:
14426 case PROCESSOR_R5500:
14427 case PROCESSOR_R5900:
14428 case PROCESSOR_R7000:
14429 case PROCESSOR_R9000:
14430 case PROCESSOR_OCTEON:
14431 case PROCESSOR_OCTEON2:
14432 case PROCESSOR_OCTEON3:
14433 case PROCESSOR_I6400:
14434 return 2;
14436 case PROCESSOR_SB1:
14437 case PROCESSOR_SB1A:
14438 /* This is actually 4, but we get better performance if we claim 3.
14439 This is partly because of unwanted speculative code motion with the
14440 larger number, and partly because in most common cases we can't
14441 reach the theoretical max of 4. */
14442 return 3;
14444 case PROCESSOR_LOONGSON_2E:
14445 case PROCESSOR_LOONGSON_2F:
14446 case PROCESSOR_LOONGSON_3A:
14447 case PROCESSOR_P5600:
14448 return 4;
14450 case PROCESSOR_XLP:
14451 return (reload_completed ? 4 : 3);
14453 default:
14454 return 1;
14458 /* Implement TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN hook for Loongson2. */
14460 static void
14461 mips_ls2_init_dfa_post_cycle_insn (void)
14463 start_sequence ();
14464 emit_insn (gen_ls2_alu1_turn_enabled_insn ());
14465 mips_ls2.alu1_turn_enabled_insn = get_insns ();
14466 end_sequence ();
14468 start_sequence ();
14469 emit_insn (gen_ls2_alu2_turn_enabled_insn ());
14470 mips_ls2.alu2_turn_enabled_insn = get_insns ();
14471 end_sequence ();
14473 start_sequence ();
14474 emit_insn (gen_ls2_falu1_turn_enabled_insn ());
14475 mips_ls2.falu1_turn_enabled_insn = get_insns ();
14476 end_sequence ();
14478 start_sequence ();
14479 emit_insn (gen_ls2_falu2_turn_enabled_insn ());
14480 mips_ls2.falu2_turn_enabled_insn = get_insns ();
14481 end_sequence ();
14483 mips_ls2.alu1_core_unit_code = get_cpu_unit_code ("ls2_alu1_core");
14484 mips_ls2.alu2_core_unit_code = get_cpu_unit_code ("ls2_alu2_core");
14485 mips_ls2.falu1_core_unit_code = get_cpu_unit_code ("ls2_falu1_core");
14486 mips_ls2.falu2_core_unit_code = get_cpu_unit_code ("ls2_falu2_core");
14489 /* Implement TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN hook.
14490 Init data used in mips_dfa_post_advance_cycle. */
14492 static void
14493 mips_init_dfa_post_cycle_insn (void)
14495 if (TUNE_LOONGSON_2EF)
14496 mips_ls2_init_dfa_post_cycle_insn ();
14499 /* Initialize STATE when scheduling for Loongson 2E/2F.
14500 Support round-robin dispatch scheme by enabling only one of
14501 ALU1/ALU2 and one of FALU1/FALU2 units for ALU1/2 and FALU1/2 instructions
14502 respectively. */
14504 static void
14505 mips_ls2_dfa_post_advance_cycle (state_t state)
14507 if (cpu_unit_reservation_p (state, mips_ls2.alu1_core_unit_code))
14509 /* Though there are no non-pipelined ALU1 insns,
14510 we can get an instruction of type 'multi' before reload. */
14511 gcc_assert (mips_ls2.cycle_has_multi_p);
14512 mips_ls2.alu1_turn_p = false;
14515 mips_ls2.cycle_has_multi_p = false;
14517 if (cpu_unit_reservation_p (state, mips_ls2.alu2_core_unit_code))
14518 /* We have a non-pipelined alu instruction in the core,
14519 adjust round-robin counter. */
14520 mips_ls2.alu1_turn_p = true;
14522 if (mips_ls2.alu1_turn_p)
14524 if (state_transition (state, mips_ls2.alu1_turn_enabled_insn) >= 0)
14525 gcc_unreachable ();
14527 else
14529 if (state_transition (state, mips_ls2.alu2_turn_enabled_insn) >= 0)
14530 gcc_unreachable ();
14533 if (cpu_unit_reservation_p (state, mips_ls2.falu1_core_unit_code))
14535 /* There are no non-pipelined FALU1 insns. */
14536 gcc_unreachable ();
14537 mips_ls2.falu1_turn_p = false;
14540 if (cpu_unit_reservation_p (state, mips_ls2.falu2_core_unit_code))
14541 /* We have a non-pipelined falu instruction in the core,
14542 adjust round-robin counter. */
14543 mips_ls2.falu1_turn_p = true;
14545 if (mips_ls2.falu1_turn_p)
14547 if (state_transition (state, mips_ls2.falu1_turn_enabled_insn) >= 0)
14548 gcc_unreachable ();
14550 else
14552 if (state_transition (state, mips_ls2.falu2_turn_enabled_insn) >= 0)
14553 gcc_unreachable ();
14557 /* Implement TARGET_SCHED_DFA_POST_ADVANCE_CYCLE.
14558 This hook is being called at the start of each cycle. */
14560 static void
14561 mips_dfa_post_advance_cycle (void)
14563 if (TUNE_LOONGSON_2EF)
14564 mips_ls2_dfa_post_advance_cycle (curr_state);
14567 /* Implement TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD. This should
14568 be as wide as the scheduling freedom in the DFA. */
14570 static int
14571 mips_multipass_dfa_lookahead (void)
14573 /* Can schedule up to 4 of the 6 function units in any one cycle. */
14574 if (TUNE_SB1)
14575 return 4;
14577 if (TUNE_LOONGSON_2EF || TUNE_LOONGSON_3A)
14578 return 4;
14580 if (TUNE_OCTEON)
14581 return 2;
14583 if (TUNE_P5600 || TUNE_I6400)
14584 return 4;
14586 return 0;
14589 /* Remove the instruction at index LOWER from ready queue READY and
14590 reinsert it in front of the instruction at index HIGHER. LOWER must
14591 be <= HIGHER. */
14593 static void
14594 mips_promote_ready (rtx *ready, int lower, int higher)
14596 rtx new_head;
14597 int i;
14599 new_head = ready[lower];
14600 for (i = lower; i < higher; i++)
14601 ready[i] = ready[i + 1];
14602 ready[i] = new_head;
14605 /* If the priority of the instruction at POS2 in the ready queue READY
14606 is within LIMIT units of that of the instruction at POS1, swap the
14607 instructions if POS2 is not already less than POS1. */
14609 static void
14610 mips_maybe_swap_ready (rtx *ready, int pos1, int pos2, int limit)
14612 if (pos1 < pos2
14613 && INSN_PRIORITY (ready[pos1]) + limit >= INSN_PRIORITY (ready[pos2]))
14615 rtx temp;
14617 temp = ready[pos1];
14618 ready[pos1] = ready[pos2];
14619 ready[pos2] = temp;
14623 /* Used by TUNE_MACC_CHAINS to record the last scheduled instruction
14624 that may clobber hi or lo. */
14625 static rtx mips_macc_chains_last_hilo;
14627 /* A TUNE_MACC_CHAINS helper function. Record that instruction INSN has
14628 been scheduled, updating mips_macc_chains_last_hilo appropriately. */
14630 static void
14631 mips_macc_chains_record (rtx insn)
14633 if (get_attr_may_clobber_hilo (insn))
14634 mips_macc_chains_last_hilo = insn;
14637 /* A TUNE_MACC_CHAINS helper function. Search ready queue READY, which
14638 has NREADY elements, looking for a multiply-add or multiply-subtract
14639 instruction that is cumulative with mips_macc_chains_last_hilo.
14640 If there is one, promote it ahead of anything else that might
14641 clobber hi or lo. */
14643 static void
14644 mips_macc_chains_reorder (rtx *ready, int nready)
14646 int i, j;
14648 if (mips_macc_chains_last_hilo != 0)
14649 for (i = nready - 1; i >= 0; i--)
14650 if (mips_linked_madd_p (mips_macc_chains_last_hilo, ready[i]))
14652 for (j = nready - 1; j > i; j--)
14653 if (recog_memoized (ready[j]) >= 0
14654 && get_attr_may_clobber_hilo (ready[j]))
14656 mips_promote_ready (ready, i, j);
14657 break;
14659 break;
14663 /* The last instruction to be scheduled. */
14664 static rtx vr4130_last_insn;
14666 /* A note_stores callback used by vr4130_true_reg_dependence_p. DATA
14667 points to an rtx that is initially an instruction. Nullify the rtx
14668 if the instruction uses the value of register X. */
14670 static void
14671 vr4130_true_reg_dependence_p_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
14672 void *data)
14674 rtx *insn_ptr;
14676 insn_ptr = (rtx *) data;
14677 if (REG_P (x)
14678 && *insn_ptr != 0
14679 && reg_referenced_p (x, PATTERN (*insn_ptr)))
14680 *insn_ptr = 0;
14683 /* Return true if there is true register dependence between vr4130_last_insn
14684 and INSN. */
14686 static bool
14687 vr4130_true_reg_dependence_p (rtx insn)
14689 note_stores (PATTERN (vr4130_last_insn),
14690 vr4130_true_reg_dependence_p_1, &insn);
14691 return insn == 0;
14694 /* A TUNE_MIPS4130 helper function. Given that INSN1 is at the head of
14695 the ready queue and that INSN2 is the instruction after it, return
14696 true if it is worth promoting INSN2 ahead of INSN1. Look for cases
14697 in which INSN1 and INSN2 can probably issue in parallel, but for
14698 which (INSN2, INSN1) should be less sensitive to instruction
14699 alignment than (INSN1, INSN2). See 4130.md for more details. */
14701 static bool
14702 vr4130_swap_insns_p (rtx insn1, rtx insn2)
14704 sd_iterator_def sd_it;
14705 dep_t dep;
14707 /* Check for the following case:
14709 1) there is some other instruction X with an anti dependence on INSN1;
14710 2) X has a higher priority than INSN2; and
14711 3) X is an arithmetic instruction (and thus has no unit restrictions).
14713 If INSN1 is the last instruction blocking X, it would better to
14714 choose (INSN1, X) over (INSN2, INSN1). */
14715 FOR_EACH_DEP (insn1, SD_LIST_FORW, sd_it, dep)
14716 if (DEP_TYPE (dep) == REG_DEP_ANTI
14717 && INSN_PRIORITY (DEP_CON (dep)) > INSN_PRIORITY (insn2)
14718 && recog_memoized (DEP_CON (dep)) >= 0
14719 && get_attr_vr4130_class (DEP_CON (dep)) == VR4130_CLASS_ALU)
14720 return false;
14722 if (vr4130_last_insn != 0
14723 && recog_memoized (insn1) >= 0
14724 && recog_memoized (insn2) >= 0)
14726 /* See whether INSN1 and INSN2 use different execution units,
14727 or if they are both ALU-type instructions. If so, they can
14728 probably execute in parallel. */
14729 enum attr_vr4130_class class1 = get_attr_vr4130_class (insn1);
14730 enum attr_vr4130_class class2 = get_attr_vr4130_class (insn2);
14731 if (class1 != class2 || class1 == VR4130_CLASS_ALU)
14733 /* If only one of the instructions has a dependence on
14734 vr4130_last_insn, prefer to schedule the other one first. */
14735 bool dep1_p = vr4130_true_reg_dependence_p (insn1);
14736 bool dep2_p = vr4130_true_reg_dependence_p (insn2);
14737 if (dep1_p != dep2_p)
14738 return dep1_p;
14740 /* Prefer to schedule INSN2 ahead of INSN1 if vr4130_last_insn
14741 is not an ALU-type instruction and if INSN1 uses the same
14742 execution unit. (Note that if this condition holds, we already
14743 know that INSN2 uses a different execution unit.) */
14744 if (class1 != VR4130_CLASS_ALU
14745 && recog_memoized (vr4130_last_insn) >= 0
14746 && class1 == get_attr_vr4130_class (vr4130_last_insn))
14747 return true;
14750 return false;
14753 /* A TUNE_MIPS4130 helper function. (READY, NREADY) describes a ready
14754 queue with at least two instructions. Swap the first two if
14755 vr4130_swap_insns_p says that it could be worthwhile. */
14757 static void
14758 vr4130_reorder (rtx *ready, int nready)
14760 if (vr4130_swap_insns_p (ready[nready - 1], ready[nready - 2]))
14761 mips_promote_ready (ready, nready - 2, nready - 1);
14764 /* Record whether last 74k AGEN instruction was a load or store. */
14765 static enum attr_type mips_last_74k_agen_insn = TYPE_UNKNOWN;
14767 /* Initialize mips_last_74k_agen_insn from INSN. A null argument
14768 resets to TYPE_UNKNOWN state. */
14770 static void
14771 mips_74k_agen_init (rtx insn)
14773 if (!insn || CALL_P (insn) || JUMP_P (insn))
14774 mips_last_74k_agen_insn = TYPE_UNKNOWN;
14775 else
14777 enum attr_type type = get_attr_type (insn);
14778 if (type == TYPE_LOAD || type == TYPE_STORE)
14779 mips_last_74k_agen_insn = type;
14783 /* A TUNE_74K helper function. The 74K AGEN pipeline likes multiple
14784 loads to be grouped together, and multiple stores to be grouped
14785 together. Swap things around in the ready queue to make this happen. */
14787 static void
14788 mips_74k_agen_reorder (rtx *ready, int nready)
14790 int i;
14791 int store_pos, load_pos;
14793 store_pos = -1;
14794 load_pos = -1;
14796 for (i = nready - 1; i >= 0; i--)
14798 rtx insn = ready[i];
14799 if (USEFUL_INSN_P (insn))
14800 switch (get_attr_type (insn))
14802 case TYPE_STORE:
14803 if (store_pos == -1)
14804 store_pos = i;
14805 break;
14807 case TYPE_LOAD:
14808 if (load_pos == -1)
14809 load_pos = i;
14810 break;
14812 default:
14813 break;
14817 if (load_pos == -1 || store_pos == -1)
14818 return;
14820 switch (mips_last_74k_agen_insn)
14822 case TYPE_UNKNOWN:
14823 /* Prefer to schedule loads since they have a higher latency. */
14824 case TYPE_LOAD:
14825 /* Swap loads to the front of the queue. */
14826 mips_maybe_swap_ready (ready, load_pos, store_pos, 4);
14827 break;
14828 case TYPE_STORE:
14829 /* Swap stores to the front of the queue. */
14830 mips_maybe_swap_ready (ready, store_pos, load_pos, 4);
14831 break;
14832 default:
14833 break;
14837 /* These functions are called when -msched-weight is set. */
14839 /* Find register born in given X if any. */
14841 static int
14842 find_reg_born (rtx x)
14844 if (GET_CODE (x) == CLOBBER)
14845 return 1;
14847 if (GET_CODE (x) == SET)
14849 if (REG_P (SET_DEST (x)) && reg_mentioned_p (SET_DEST (x), SET_SRC (x)))
14850 return 0;
14851 return 1;
14853 return 0;
14856 /* Calculate register weight for given INSN. */
14858 static int
14859 get_weight (rtx insn)
14861 int weight = 0;
14862 rtx x;
14864 /* Increment weight for each register born here. */
14865 x = PATTERN (insn);
14866 weight = find_reg_born (x);
14868 if (GET_CODE (x) == PARALLEL)
14870 int i;
14871 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
14873 x = XVECEXP (PATTERN (insn), 0, i);
14874 weight += find_reg_born (x);
14878 /* Decrement weight for each register that dies here. */
14879 for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
14881 if (REG_NOTE_KIND (x) == REG_DEAD || REG_NOTE_KIND (x) == REG_UNUSED)
14883 rtx note = XEXP (x, 0);
14884 if (REG_P (note))
14885 weight--;
14888 return weight;
14891 /* TARGET_SCHED_WEIGHT helper function.
14892 Allocate and initialize global data. */
14894 static void
14895 mips_weight_init_global (int old_max_uid)
14897 level = (int *) xcalloc (old_max_uid, sizeof (int));
14898 consumer_luid = (int *) xcalloc (old_max_uid, sizeof (int));
14901 /* Implement TARGET_SCHED_INIT_GLOBAL. */
14903 static void
14904 mips_sched_init_global (FILE *dump ATTRIBUTE_UNUSED,
14905 int verbose ATTRIBUTE_UNUSED,
14906 int old_max_uid)
14908 if (!reload_completed && TARGET_SCHED_WEIGHT)
14909 mips_weight_init_global (old_max_uid);
14912 /* TARGET_SCHED_WEIGHT helper function. Called for each basic block
14913 with dependency chain information in HEAD and TAIL.
14914 Calculates LEVEL for each INSN from its forward dependencies
14915 and finds out UID of first consumer instruction (CONSUMER_LUID) of INSN. */
14917 static void
14918 mips_weight_evaluation (rtx head, rtx tail)
14920 sd_iterator_def sd_it;
14921 dep_t dep;
14922 rtx prev_head, insn, x;
14923 prev_head = PREV_INSN (head);
14925 for (insn = tail; insn != prev_head; insn = PREV_INSN (insn))
14926 if (INSN_P (insn))
14928 FOR_EACH_DEP (insn, SD_LIST_FORW, sd_it, dep)
14930 x = DEP_CON (dep);
14931 if (! DEBUG_INSN_P (x))
14933 if (LEVEL (x) > LEVEL (insn))
14934 LEVEL (insn) = LEVEL (x);
14935 CONSUMER_LUID (insn) = INSN_LUID (x);
14938 LEVEL (insn)++;
14942 /* Implement TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK. */
14944 static void
14945 mips_evaluation_hook (rtx head, rtx tail)
14947 if (!reload_completed && TARGET_SCHED_WEIGHT)
14948 mips_weight_evaluation (head, tail);
14951 /* Implement TARGET_SCHED_SET_SCHED_FLAGS.
14952 Enables DONT_BREAK_DEPENDENCIES for the first scheduling pass.
14953 It prevents breaking of dependencies on mem/inc pair in the first pass
14954 which would otherwise increase stalls. */
14956 static void
14957 mips_set_sched_flags (spec_info_t spec_info ATTRIBUTE_UNUSED)
14959 if (!reload_completed && TARGET_SCHED_WEIGHT)
14961 unsigned int *flags = &(current_sched_info->flags);
14962 *flags |= DONT_BREAK_DEPENDENCIES;
14966 static void
14967 mips_weight_finish_global ()
14969 if (level != NULL)
14970 free (level);
14972 if (consumer_luid != NULL)
14973 free (consumer_luid);
14976 /* Implement TARGET_SCHED_FINISH_GLOBAL. */
14978 static void
14979 mips_sched_finish_global (FILE *dump ATTRIBUTE_UNUSED,
14980 int verbose ATTRIBUTE_UNUSED)
14982 if (!reload_completed && TARGET_SCHED_WEIGHT)
14983 mips_weight_finish_global ();
14987 /* This is a TARGET_SCHED_WEIGHT (option -msched-weight) helper function
14988 which is called during reordering of instructions in the first pass
14989 of the scheduler. The function swaps the instruction at (NREADY - 1)
14990 of the READY list with another instruction in READY list as per
14991 the following algorithm. The scheduler then picks the instruction
14992 at READY[NREADY - 1] and schedules it.
14994 Every instruction is assigned with a value LEVEL.
14995 [See: mips_weight_evaluation().]
14997 1. INSN with highest LEVEL is chosen to be scheduled next, ties broken by
14998 1a. Choosing INSN that is used early in the flow or
14999 1b. Choosing INSN with greater INSN_TICK.
15001 2. Choose INSN having less LEVEL number iff,
15002 2a. It is used early and
15003 2b. Has greater INSN_TICK and
15004 2c. Contributes less to the register pressure. */
15006 static void
15007 mips_sched_weight (rtx *ready, int nready)
15009 int max_level = LEVEL (ready[nready-1]), toswap = nready-1;
15010 int i;
15011 #define INSN_TICK(INSN) (HID (INSN)->tick)
15013 for (i = nready - 2; i >= 0; i--)
15015 rtx insn = ready[i];
15016 if (LEVEL (insn) == max_level)
15018 if (INSN_PRIORITY (insn) >= INSN_PRIORITY (ready[toswap]))
15020 if (CONSUMER_LUID (insn) < CONSUMER_LUID (ready[toswap]))
15021 toswap = i;
15023 else if (INSN_TICK (insn) > INSN_TICK(ready[toswap]))
15024 toswap = i;
15026 if (LEVEL (insn) > max_level)
15028 max_level = LEVEL (insn);
15029 toswap = i;
15031 if (LEVEL (insn) < max_level)
15033 if (CONSUMER_LUID (insn) < CONSUMER_LUID (ready[toswap])
15034 && INSN_TICK (insn) > INSN_TICK(ready[toswap])
15035 && get_weight (insn) < get_weight (ready[toswap]))
15036 toswap = i;
15040 if (toswap != (nready-1))
15042 rtx temp = ready[nready-1];
15043 ready[nready-1] = ready[toswap];
15044 ready[toswap] = temp;
15046 #undef INSN_TICK
15050 /* Implement TARGET_SCHED_INIT. */
15052 static void
15053 mips_sched_init (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
15054 int max_ready ATTRIBUTE_UNUSED)
15056 mips_macc_chains_last_hilo = 0;
15057 vr4130_last_insn = 0;
15058 mips_74k_agen_init (NULL_RTX);
15060 /* When scheduling for Loongson2, branch instructions go to ALU1,
15061 therefore basic block is most likely to start with round-robin counter
15062 pointed to ALU2. */
15063 mips_ls2.alu1_turn_p = false;
15064 mips_ls2.falu1_turn_p = true;
15067 /* Subroutine used by TARGET_SCHED_REORDER and TARGET_SCHED_REORDER2. */
15069 static void
15070 mips_sched_reorder_1 (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
15071 rtx *ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED)
15073 if (!reload_completed
15074 && TUNE_MACC_CHAINS
15075 && *nreadyp > 0)
15076 mips_macc_chains_reorder (ready, *nreadyp);
15078 if (reload_completed
15079 && TUNE_MIPS4130
15080 && !TARGET_VR4130_ALIGN
15081 && *nreadyp > 1)
15082 vr4130_reorder (ready, *nreadyp);
15084 if (TUNE_74K)
15085 mips_74k_agen_reorder (ready, *nreadyp);
15087 if (! reload_completed
15088 && TARGET_SCHED_WEIGHT
15089 && *nreadyp > 1)
15090 mips_sched_weight (ready, *nreadyp);
15093 /* Implement TARGET_SCHED_REORDER. */
15095 static int
15096 mips_sched_reorder (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
15097 rtx *ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED)
15099 mips_sched_reorder_1 (file, verbose, ready, nreadyp, cycle);
15100 return mips_issue_rate ();
15103 /* Implement TARGET_SCHED_REORDER2. */
15105 static int
15106 mips_sched_reorder2 (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
15107 rtx *ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED)
15109 mips_sched_reorder_1 (file, verbose, ready, nreadyp, cycle);
15110 return cached_can_issue_more;
15113 /* Update round-robin counters for ALU1/2 and FALU1/2. */
15115 static void
15116 mips_ls2_variable_issue (rtx insn)
15118 if (mips_ls2.alu1_turn_p)
15120 if (cpu_unit_reservation_p (curr_state, mips_ls2.alu1_core_unit_code))
15121 mips_ls2.alu1_turn_p = false;
15123 else
15125 if (cpu_unit_reservation_p (curr_state, mips_ls2.alu2_core_unit_code))
15126 mips_ls2.alu1_turn_p = true;
15129 if (mips_ls2.falu1_turn_p)
15131 if (cpu_unit_reservation_p (curr_state, mips_ls2.falu1_core_unit_code))
15132 mips_ls2.falu1_turn_p = false;
15134 else
15136 if (cpu_unit_reservation_p (curr_state, mips_ls2.falu2_core_unit_code))
15137 mips_ls2.falu1_turn_p = true;
15140 if (recog_memoized (insn) >= 0)
15141 mips_ls2.cycle_has_multi_p |= (get_attr_type (insn) == TYPE_MULTI);
15144 /* Implement TARGET_SCHED_VARIABLE_ISSUE. */
15146 static int
15147 mips_variable_issue (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED,
15148 rtx insn, int more)
15150 /* Ignore USEs and CLOBBERs; don't count them against the issue rate. */
15151 if (USEFUL_INSN_P (insn))
15153 if (get_attr_type (insn) != TYPE_GHOST)
15154 more--;
15155 if (!reload_completed && TUNE_MACC_CHAINS)
15156 mips_macc_chains_record (insn);
15157 vr4130_last_insn = insn;
15158 if (TUNE_74K)
15159 mips_74k_agen_init (insn);
15160 else if (TUNE_LOONGSON_2EF)
15161 mips_ls2_variable_issue (insn);
15164 /* Instructions of type 'multi' should all be split before
15165 the second scheduling pass. */
15166 gcc_assert (!reload_completed
15167 || recog_memoized (insn) < 0
15168 || get_attr_type (insn) != TYPE_MULTI);
15170 cached_can_issue_more = more;
15171 return more;
15174 /* Given that we have an rtx of the form (prefetch ... WRITE LOCALITY),
15175 return the first operand of the associated PREF or PREFX insn. */
15178 mips_prefetch_cookie (rtx write, rtx locality)
15180 /* store_streamed / load_streamed. */
15181 if (INTVAL (locality) <= 0)
15182 return GEN_INT (INTVAL (write) + 4);
15184 /* store / load. */
15185 if (INTVAL (locality) <= 2)
15186 return write;
15188 /* store_retained / load_retained. */
15189 return GEN_INT (INTVAL (write) + 6);
15192 /* Flags that indicate when a built-in function is available.
15194 BUILTIN_AVAIL_NON_MIPS16
15195 The function is available on the current target if !TARGET_MIPS16.
15197 BUILTIN_AVAIL_MIPS16
15198 The function is available on the current target if TARGET_MIPS16. */
15199 #define BUILTIN_AVAIL_NON_MIPS16 1
15200 #define BUILTIN_AVAIL_MIPS16 2
15202 /* Declare an availability predicate for built-in functions that
15203 require non-MIPS16 mode and also require COND to be true.
15204 NAME is the main part of the predicate's name. */
15205 #define AVAIL_NON_MIPS16(NAME, COND) \
15206 static unsigned int \
15207 mips_builtin_avail_##NAME (void) \
15209 return (COND) ? BUILTIN_AVAIL_NON_MIPS16 : 0; \
15212 /* Declare an availability predicate for built-in functions that
15213 support both MIPS16 and non-MIPS16 code and also require COND
15214 to be true. NAME is the main part of the predicate's name. */
15215 #define AVAIL_ALL(NAME, COND) \
15216 static unsigned int \
15217 mips_builtin_avail_##NAME (void) \
15219 return (COND) ? BUILTIN_AVAIL_NON_MIPS16 | BUILTIN_AVAIL_MIPS16 : 0; \
15222 /* This structure describes a single built-in function. */
15223 struct mips_builtin_description {
15224 /* The code of the main .md file instruction. See mips_builtin_type
15225 for more information. */
15226 enum insn_code icode;
15228 /* The floating-point comparison code to use with ICODE, if any. */
15229 enum mips_fp_condition cond;
15231 /* The name of the built-in function. */
15232 const char *name;
15234 /* Specifies how the function should be expanded. */
15235 enum mips_builtin_type builtin_type;
15237 /* The function's prototype. */
15238 enum mips_function_type function_type;
15240 /* Whether the function is available. */
15241 unsigned int (*avail) (void);
15244 AVAIL_ALL (hard_float, TARGET_HARD_FLOAT_ABI)
15245 AVAIL_NON_MIPS16 (paired_single, TARGET_PAIRED_SINGLE_FLOAT)
15246 AVAIL_NON_MIPS16 (sb1_paired_single, TARGET_SB1 && TARGET_PAIRED_SINGLE_FLOAT)
15247 AVAIL_NON_MIPS16 (mips3d, TARGET_MIPS3D)
15248 AVAIL_NON_MIPS16 (dsp, TARGET_DSP)
15249 AVAIL_NON_MIPS16 (dspr2, TARGET_DSPR2)
15250 AVAIL_NON_MIPS16 (dsp_32, !TARGET_64BIT && TARGET_DSP)
15251 AVAIL_NON_MIPS16 (dsp_64, TARGET_64BIT && TARGET_DSP)
15252 AVAIL_NON_MIPS16 (dspr2_32, !TARGET_64BIT && TARGET_DSPR2)
15253 AVAIL_NON_MIPS16 (loongson, TARGET_LOONGSON_VECTORS)
15254 AVAIL_NON_MIPS16 (cache, TARGET_CACHE_BUILTIN)
15255 AVAIL_NON_MIPS16 (msa, TARGET_MSA)
15257 /* Construct a mips_builtin_description from the given arguments.
15259 INSN is the name of the associated instruction pattern, without the
15260 leading CODE_FOR_mips_.
15262 CODE is the floating-point condition code associated with the
15263 function. It can be 'f' if the field is not applicable.
15265 NAME is the name of the function itself, without the leading
15266 "__builtin_mips_".
15268 BUILTIN_TYPE and FUNCTION_TYPE are mips_builtin_description fields.
15270 AVAIL is the name of the availability predicate, without the leading
15271 mips_builtin_avail_. */
15272 #define MIPS_BUILTIN(INSN, COND, NAME, BUILTIN_TYPE, \
15273 FUNCTION_TYPE, AVAIL) \
15274 { CODE_FOR_mips_ ## INSN, MIPS_FP_COND_ ## COND, \
15275 "__builtin_mips_" NAME, BUILTIN_TYPE, FUNCTION_TYPE, \
15276 mips_builtin_avail_ ## AVAIL }
15278 /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT function
15279 mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE and AVAIL
15280 are as for MIPS_BUILTIN. */
15281 #define DIRECT_BUILTIN(INSN, FUNCTION_TYPE, AVAIL) \
15282 MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT, FUNCTION_TYPE, AVAIL)
15284 /* Define __builtin_mips_<INSN>_<COND>_{s,d} functions, both of which
15285 are subject to mips_builtin_avail_<AVAIL>. */
15286 #define CMP_SCALAR_BUILTINS(INSN, COND, AVAIL) \
15287 MIPS_BUILTIN (INSN ## _cond_s, COND, #INSN "_" #COND "_s", \
15288 MIPS_BUILTIN_CMP_SINGLE, MIPS_INT_FTYPE_SF_SF, AVAIL), \
15289 MIPS_BUILTIN (INSN ## _cond_d, COND, #INSN "_" #COND "_d", \
15290 MIPS_BUILTIN_CMP_SINGLE, MIPS_INT_FTYPE_DF_DF, AVAIL)
15292 /* Define __builtin_mips_{any,all,upper,lower}_<INSN>_<COND>_ps.
15293 The lower and upper forms are subject to mips_builtin_avail_<AVAIL>
15294 while the any and all forms are subject to mips_builtin_avail_mips3d. */
15295 #define CMP_PS_BUILTINS(INSN, COND, AVAIL) \
15296 MIPS_BUILTIN (INSN ## _cond_ps, COND, "any_" #INSN "_" #COND "_ps", \
15297 MIPS_BUILTIN_CMP_ANY, MIPS_INT_FTYPE_V2SF_V2SF, \
15298 mips3d), \
15299 MIPS_BUILTIN (INSN ## _cond_ps, COND, "all_" #INSN "_" #COND "_ps", \
15300 MIPS_BUILTIN_CMP_ALL, MIPS_INT_FTYPE_V2SF_V2SF, \
15301 mips3d), \
15302 MIPS_BUILTIN (INSN ## _cond_ps, COND, "lower_" #INSN "_" #COND "_ps", \
15303 MIPS_BUILTIN_CMP_LOWER, MIPS_INT_FTYPE_V2SF_V2SF, \
15304 AVAIL), \
15305 MIPS_BUILTIN (INSN ## _cond_ps, COND, "upper_" #INSN "_" #COND "_ps", \
15306 MIPS_BUILTIN_CMP_UPPER, MIPS_INT_FTYPE_V2SF_V2SF, \
15307 AVAIL)
15309 /* Define __builtin_mips_{any,all}_<INSN>_<COND>_4s. The functions
15310 are subject to mips_builtin_avail_mips3d. */
15311 #define CMP_4S_BUILTINS(INSN, COND) \
15312 MIPS_BUILTIN (INSN ## _cond_4s, COND, "any_" #INSN "_" #COND "_4s", \
15313 MIPS_BUILTIN_CMP_ANY, \
15314 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, mips3d), \
15315 MIPS_BUILTIN (INSN ## _cond_4s, COND, "all_" #INSN "_" #COND "_4s", \
15316 MIPS_BUILTIN_CMP_ALL, \
15317 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, mips3d)
15319 /* Define __builtin_mips_mov{t,f}_<INSN>_<COND>_ps. The comparison
15320 instruction requires mips_builtin_avail_<AVAIL>. */
15321 #define MOVTF_BUILTINS(INSN, COND, AVAIL) \
15322 MIPS_BUILTIN (INSN ## _cond_ps, COND, "movt_" #INSN "_" #COND "_ps", \
15323 MIPS_BUILTIN_MOVT, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, \
15324 AVAIL), \
15325 MIPS_BUILTIN (INSN ## _cond_ps, COND, "movf_" #INSN "_" #COND "_ps", \
15326 MIPS_BUILTIN_MOVF, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, \
15327 AVAIL)
15329 /* Define all the built-in functions related to C.cond.fmt condition COND. */
15330 #define CMP_BUILTINS(COND) \
15331 MOVTF_BUILTINS (c, COND, paired_single), \
15332 MOVTF_BUILTINS (cabs, COND, mips3d), \
15333 CMP_SCALAR_BUILTINS (cabs, COND, mips3d), \
15334 CMP_PS_BUILTINS (c, COND, paired_single), \
15335 CMP_PS_BUILTINS (cabs, COND, mips3d), \
15336 CMP_4S_BUILTINS (c, COND), \
15337 CMP_4S_BUILTINS (cabs, COND)
15339 /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT_NO_TARGET
15340 function mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE
15341 and AVAIL are as for MIPS_BUILTIN. */
15342 #define DIRECT_NO_TARGET_BUILTIN(INSN, FUNCTION_TYPE, AVAIL) \
15343 MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT_NO_TARGET, \
15344 FUNCTION_TYPE, AVAIL)
15346 /* Define __builtin_mips_bposge<VALUE>. <VALUE> is 32 for the MIPS32 DSP
15347 branch instruction. AVAIL is as for MIPS_BUILTIN. */
15348 #define BPOSGE_BUILTIN(VALUE, AVAIL) \
15349 MIPS_BUILTIN (bposge, f, "bposge" #VALUE, \
15350 MIPS_BUILTIN_BPOSGE ## VALUE, MIPS_SI_FTYPE_VOID, AVAIL)
15352 /* Define a Loongson MIPS_BUILTIN_DIRECT function __builtin_loongson_<FN_NAME>
15353 for instruction CODE_FOR_loongson_<INSN>. FUNCTION_TYPE is a
15354 builtin_description field. */
15355 #define LOONGSON_BUILTIN_ALIAS(INSN, FN_NAME, FUNCTION_TYPE) \
15356 { CODE_FOR_loongson_ ## INSN, MIPS_FP_COND_f, \
15357 "__builtin_loongson_" #FN_NAME, MIPS_BUILTIN_DIRECT, \
15358 FUNCTION_TYPE, mips_builtin_avail_loongson }
15360 /* Define a Loongson MIPS_BUILTIN_DIRECT function __builtin_loongson_<INSN>
15361 for instruction CODE_FOR_loongson_<INSN>. FUNCTION_TYPE is a
15362 builtin_description field. */
15363 #define LOONGSON_BUILTIN(INSN, FUNCTION_TYPE) \
15364 LOONGSON_BUILTIN_ALIAS (INSN, INSN, FUNCTION_TYPE)
15366 /* Like LOONGSON_BUILTIN, but add _<SUFFIX> to the end of the function name.
15367 We use functions of this form when the same insn can be usefully applied
15368 to more than one datatype. */
15369 #define LOONGSON_BUILTIN_SUFFIX(INSN, SUFFIX, FUNCTION_TYPE) \
15370 LOONGSON_BUILTIN_ALIAS (INSN, INSN ## _ ## SUFFIX, FUNCTION_TYPE)
15372 /* Define a MSA MIPS_BUILTIN_DIRECT function __builtin_msa_<INSN>
15373 for instruction CODE_FOR_msa_<INSN>. FUNCTION_TYPE is a
15374 builtin_description field. */
15375 #define MSA_BUILTIN(INSN, FUNCTION_TYPE) \
15376 { CODE_FOR_msa_ ## INSN, MIPS_FP_COND_f, \
15377 "__builtin_msa_" #INSN, MIPS_BUILTIN_DIRECT, \
15378 FUNCTION_TYPE, mips_builtin_avail_msa }
15380 /* Define a MSA MIPS_BUILTIN_DIRECT_NO_TARGET function __builtin_msa_<INSN>
15381 for instruction CODE_FOR_msa_<INSN>. FUNCTION_TYPE is a
15382 builtin_description field. */
15383 #define MSA_NO_TARGET_BUILTIN(INSN, FUNCTION_TYPE) \
15384 { CODE_FOR_msa_ ## INSN, MIPS_FP_COND_f, \
15385 "__builtin_msa_" #INSN, MIPS_BUILTIN_DIRECT_NO_TARGET, \
15386 FUNCTION_TYPE, mips_builtin_avail_msa }
15388 #define CODE_FOR_mips_sqrt_ps CODE_FOR_sqrtv2sf2
15389 #define CODE_FOR_mips_addq_ph CODE_FOR_addv2hi3
15390 #define CODE_FOR_mips_addu_qb CODE_FOR_addv4qi3
15391 #define CODE_FOR_mips_subq_ph CODE_FOR_subv2hi3
15392 #define CODE_FOR_mips_subu_qb CODE_FOR_subv4qi3
15393 #define CODE_FOR_mips_mul_ph CODE_FOR_mulv2hi3
15394 #define CODE_FOR_mips_mult CODE_FOR_mulsidi3_32bit
15395 #define CODE_FOR_mips_multu CODE_FOR_umulsidi3_32bit
15397 #define CODE_FOR_loongson_packsswh CODE_FOR_vec_pack_ssat_v2si
15398 #define CODE_FOR_loongson_packsshb CODE_FOR_vec_pack_ssat_v4hi
15399 #define CODE_FOR_loongson_packushb CODE_FOR_vec_pack_usat_v4hi
15400 #define CODE_FOR_loongson_paddw CODE_FOR_addv2si3
15401 #define CODE_FOR_loongson_paddh CODE_FOR_addv4hi3
15402 #define CODE_FOR_loongson_paddb CODE_FOR_addv8qi3
15403 #define CODE_FOR_loongson_paddsh CODE_FOR_ssaddv4hi3
15404 #define CODE_FOR_loongson_paddsb CODE_FOR_ssaddv8qi3
15405 #define CODE_FOR_loongson_paddush CODE_FOR_usaddv4hi3
15406 #define CODE_FOR_loongson_paddusb CODE_FOR_usaddv8qi3
15407 #define CODE_FOR_loongson_pmaxsh CODE_FOR_smaxv4hi3
15408 #define CODE_FOR_loongson_pmaxub CODE_FOR_umaxv8qi3
15409 #define CODE_FOR_loongson_pminsh CODE_FOR_sminv4hi3
15410 #define CODE_FOR_loongson_pminub CODE_FOR_uminv8qi3
15411 #define CODE_FOR_loongson_pmulhuh CODE_FOR_umulv4hi3_highpart
15412 #define CODE_FOR_loongson_pmulhh CODE_FOR_smulv4hi3_highpart
15413 #define CODE_FOR_loongson_pmullh CODE_FOR_mulv4hi3
15414 #define CODE_FOR_loongson_psllh CODE_FOR_ashlv4hi3
15415 #define CODE_FOR_loongson_psllw CODE_FOR_ashlv2si3
15416 #define CODE_FOR_loongson_psrlh CODE_FOR_lshrv4hi3
15417 #define CODE_FOR_loongson_psrlw CODE_FOR_lshrv2si3
15418 #define CODE_FOR_loongson_psrah CODE_FOR_ashrv4hi3
15419 #define CODE_FOR_loongson_psraw CODE_FOR_ashrv2si3
15420 #define CODE_FOR_loongson_psubw CODE_FOR_subv2si3
15421 #define CODE_FOR_loongson_psubh CODE_FOR_subv4hi3
15422 #define CODE_FOR_loongson_psubb CODE_FOR_subv8qi3
15423 #define CODE_FOR_loongson_psubsh CODE_FOR_sssubv4hi3
15424 #define CODE_FOR_loongson_psubsb CODE_FOR_sssubv8qi3
15425 #define CODE_FOR_loongson_psubush CODE_FOR_ussubv4hi3
15426 #define CODE_FOR_loongson_psubusb CODE_FOR_ussubv8qi3
15428 #define CODE_FOR_msa_adds_s_b CODE_FOR_ssaddv16qi3
15429 #define CODE_FOR_msa_adds_s_h CODE_FOR_ssaddv8hi3
15430 #define CODE_FOR_msa_adds_s_w CODE_FOR_ssaddv4si3
15431 #define CODE_FOR_msa_adds_s_d CODE_FOR_ssaddv2di3
15432 #define CODE_FOR_msa_adds_u_b CODE_FOR_usaddv16qi3
15433 #define CODE_FOR_msa_adds_u_h CODE_FOR_usaddv8hi3
15434 #define CODE_FOR_msa_adds_u_w CODE_FOR_usaddv4si3
15435 #define CODE_FOR_msa_adds_u_d CODE_FOR_usaddv2di3
15436 #define CODE_FOR_msa_addv_b CODE_FOR_addv16qi3
15437 #define CODE_FOR_msa_addv_h CODE_FOR_addv8hi3
15438 #define CODE_FOR_msa_addv_w CODE_FOR_addv4si3
15439 #define CODE_FOR_msa_addv_d CODE_FOR_addv2di3
15440 #define CODE_FOR_msa_and_v CODE_FOR_andv16qi3
15441 #define CODE_FOR_msa_bmnz_v CODE_FOR_msa_bmnz_v_b
15442 #define CODE_FOR_msa_bmz_v CODE_FOR_msa_bmz_v_b
15443 #define CODE_FOR_msa_bnz_v CODE_FOR_msa_bnz_v_b
15444 #define CODE_FOR_msa_bz_v CODE_FOR_msa_bz_v_b
15445 #define CODE_FOR_msa_bsel_v CODE_FOR_msa_bsel_v_b
15446 #define CODE_FOR_msa_div_s_b CODE_FOR_divv16qi3
15447 #define CODE_FOR_msa_div_s_h CODE_FOR_divv8hi3
15448 #define CODE_FOR_msa_div_s_w CODE_FOR_divv4si3
15449 #define CODE_FOR_msa_div_s_d CODE_FOR_divv2di3
15450 #define CODE_FOR_msa_div_u_b CODE_FOR_udivv16qi3
15451 #define CODE_FOR_msa_div_u_h CODE_FOR_udivv8hi3
15452 #define CODE_FOR_msa_div_u_w CODE_FOR_udivv4si3
15453 #define CODE_FOR_msa_div_u_d CODE_FOR_udivv2di3
15454 #define CODE_FOR_msa_fadd_w CODE_FOR_addv4sf3
15455 #define CODE_FOR_msa_fadd_d CODE_FOR_addv2df3
15456 #define CODE_FOR_msa_ffint_s_w CODE_FOR_floatv4siv4sf2
15457 #define CODE_FOR_msa_ffint_s_d CODE_FOR_floatv2div2df2
15458 #define CODE_FOR_msa_ffint_u_w CODE_FOR_floatunsv4siv4sf2
15459 #define CODE_FOR_msa_ffint_u_d CODE_FOR_floatunsv2div2df2
15460 #define CODE_FOR_msa_fsub_w CODE_FOR_subv4sf3
15461 #define CODE_FOR_msa_fsub_d CODE_FOR_subv2df3
15462 #define CODE_FOR_msa_fmul_w CODE_FOR_mulv4sf3
15463 #define CODE_FOR_msa_fmul_d CODE_FOR_mulv2df3
15464 #define CODE_FOR_msa_fdiv_w CODE_FOR_divv4sf3
15465 #define CODE_FOR_msa_fdiv_d CODE_FOR_divv2df3
15466 #define CODE_FOR_msa_fmax_w CODE_FOR_smaxv4sf3
15467 #define CODE_FOR_msa_fmax_d CODE_FOR_smaxv2df3
15468 #define CODE_FOR_msa_fmax_a_w CODE_FOR_umaxv4sf3
15469 #define CODE_FOR_msa_fmax_a_d CODE_FOR_umaxv2df3
15470 #define CODE_FOR_msa_fmin_w CODE_FOR_sminv4sf3
15471 #define CODE_FOR_msa_fmin_d CODE_FOR_sminv2df3
15472 #define CODE_FOR_msa_fmin_a_w CODE_FOR_uminv4sf3
15473 #define CODE_FOR_msa_fmin_a_d CODE_FOR_uminv2df3
15474 #define CODE_FOR_msa_fsqrt_w CODE_FOR_sqrtv4sf2
15475 #define CODE_FOR_msa_fsqrt_d CODE_FOR_sqrtv2df2
15476 #define CODE_FOR_msa_max_s_b CODE_FOR_smaxv16qi3
15477 #define CODE_FOR_msa_max_s_h CODE_FOR_smaxv8hi3
15478 #define CODE_FOR_msa_max_s_w CODE_FOR_smaxv4si3
15479 #define CODE_FOR_msa_max_s_d CODE_FOR_smaxv2di3
15480 #define CODE_FOR_msa_max_u_b CODE_FOR_umaxv16qi3
15481 #define CODE_FOR_msa_max_u_h CODE_FOR_umaxv8hi3
15482 #define CODE_FOR_msa_max_u_w CODE_FOR_umaxv4si3
15483 #define CODE_FOR_msa_max_u_d CODE_FOR_umaxv2di3
15484 #define CODE_FOR_msa_min_s_b CODE_FOR_sminv16qi3
15485 #define CODE_FOR_msa_min_s_h CODE_FOR_sminv8hi3
15486 #define CODE_FOR_msa_min_s_w CODE_FOR_sminv4si3
15487 #define CODE_FOR_msa_min_s_d CODE_FOR_sminv2di3
15488 #define CODE_FOR_msa_min_u_b CODE_FOR_uminv16qi3
15489 #define CODE_FOR_msa_min_u_h CODE_FOR_uminv8hi3
15490 #define CODE_FOR_msa_min_u_w CODE_FOR_uminv4si3
15491 #define CODE_FOR_msa_min_u_d CODE_FOR_uminv2di3
15492 #define CODE_FOR_msa_mod_s_b CODE_FOR_modv16qi3
15493 #define CODE_FOR_msa_mod_s_h CODE_FOR_modv8hi3
15494 #define CODE_FOR_msa_mod_s_w CODE_FOR_modv4si3
15495 #define CODE_FOR_msa_mod_s_d CODE_FOR_modv2di3
15496 #define CODE_FOR_msa_mod_u_b CODE_FOR_umodv16qi3
15497 #define CODE_FOR_msa_mod_u_h CODE_FOR_umodv8hi3
15498 #define CODE_FOR_msa_mod_u_w CODE_FOR_umodv4si3
15499 #define CODE_FOR_msa_mod_u_d CODE_FOR_umodv2di3
15500 #define CODE_FOR_msa_mod_s_b CODE_FOR_modv16qi3
15501 #define CODE_FOR_msa_mod_s_h CODE_FOR_modv8hi3
15502 #define CODE_FOR_msa_mod_s_w CODE_FOR_modv4si3
15503 #define CODE_FOR_msa_mod_s_d CODE_FOR_modv2di3
15504 #define CODE_FOR_msa_mod_u_b CODE_FOR_umodv16qi3
15505 #define CODE_FOR_msa_mod_u_h CODE_FOR_umodv8hi3
15506 #define CODE_FOR_msa_mod_u_w CODE_FOR_umodv4si3
15507 #define CODE_FOR_msa_mod_u_d CODE_FOR_umodv2di3
15508 #define CODE_FOR_msa_mulv_b CODE_FOR_mulv16qi3
15509 #define CODE_FOR_msa_mulv_h CODE_FOR_mulv8hi3
15510 #define CODE_FOR_msa_mulv_w CODE_FOR_mulv4si3
15511 #define CODE_FOR_msa_mulv_d CODE_FOR_mulv2di3
15512 #define CODE_FOR_msa_nlzc_b CODE_FOR_clzv16qi2
15513 #define CODE_FOR_msa_nlzc_h CODE_FOR_clzv8hi2
15514 #define CODE_FOR_msa_nlzc_w CODE_FOR_clzv4si2
15515 #define CODE_FOR_msa_nlzc_d CODE_FOR_clzv2di2
15516 #define CODE_FOR_msa_nor_v CODE_FOR_msa_nor_v_b
15517 #define CODE_FOR_msa_or_v CODE_FOR_iorv16qi3
15518 #define CODE_FOR_msa_pcnt_b CODE_FOR_popcountv16qi2
15519 #define CODE_FOR_msa_pcnt_h CODE_FOR_popcountv8hi2
15520 #define CODE_FOR_msa_pcnt_w CODE_FOR_popcountv4si2
15521 #define CODE_FOR_msa_pcnt_d CODE_FOR_popcountv2di2
15522 #define CODE_FOR_msa_xor_v CODE_FOR_xorv16qi3
15523 #define CODE_FOR_msa_sll_b CODE_FOR_vashlv16qi3
15524 #define CODE_FOR_msa_sll_h CODE_FOR_vashlv8hi3
15525 #define CODE_FOR_msa_sll_w CODE_FOR_vashlv4si3
15526 #define CODE_FOR_msa_sll_d CODE_FOR_vashlv2di3
15527 #define CODE_FOR_msa_sra_b CODE_FOR_vashrv16qi3
15528 #define CODE_FOR_msa_sra_h CODE_FOR_vashrv8hi3
15529 #define CODE_FOR_msa_sra_w CODE_FOR_vashrv4si3
15530 #define CODE_FOR_msa_sra_d CODE_FOR_vashrv2di3
15531 #define CODE_FOR_msa_srl_b CODE_FOR_vlshrv16qi3
15532 #define CODE_FOR_msa_srl_h CODE_FOR_vlshrv8hi3
15533 #define CODE_FOR_msa_srl_w CODE_FOR_vlshrv4si3
15534 #define CODE_FOR_msa_srl_d CODE_FOR_vlshrv2di3
15535 #define CODE_FOR_msa_subv_b CODE_FOR_subv16qi3
15536 #define CODE_FOR_msa_subv_h CODE_FOR_subv8hi3
15537 #define CODE_FOR_msa_subv_w CODE_FOR_subv4si3
15538 #define CODE_FOR_msa_subv_d CODE_FOR_subv2di3
15540 #define CODE_FOR_msa_move_v CODE_FOR_movv16qi
15542 #define CODE_FOR_msa_vshf_b CODE_FOR_msa_vshfv16qi
15543 #define CODE_FOR_msa_vshf_h CODE_FOR_msa_vshfv8hi
15544 #define CODE_FOR_msa_vshf_w CODE_FOR_msa_vshfv4si
15545 #define CODE_FOR_msa_vshf_d CODE_FOR_msa_vshfv2di
15547 #define CODE_FOR_msa_ilvod_d CODE_FOR_msa_ilvl_d
15548 #define CODE_FOR_msa_ilvev_d CODE_FOR_msa_ilvr_d
15550 #define CODE_FOR_msa_ldi_b CODE_FOR_msa_ldiv16qi
15551 #define CODE_FOR_msa_ldi_h CODE_FOR_msa_ldiv8hi
15552 #define CODE_FOR_msa_ldi_w CODE_FOR_msa_ldiv4si
15553 #define CODE_FOR_msa_ldi_d CODE_FOR_msa_ldiv2di
15555 #define CODE_FOR_msa_cast_to_vector_float CODE_FOR_msa_cast_to_vector_w_f
15556 #define CODE_FOR_msa_cast_to_vector_double CODE_FOR_msa_cast_to_vector_d_f
15557 #define CODE_FOR_msa_cast_to_scalar_float CODE_FOR_msa_cast_to_scalar_w_f
15558 #define CODE_FOR_msa_cast_to_scalar_double CODE_FOR_msa_cast_to_scalar_d_f
15560 static const struct mips_builtin_description mips_builtins[] = {
15561 #define MIPS_GET_FCSR 0
15562 DIRECT_BUILTIN (get_fcsr, MIPS_USI_FTYPE_VOID, hard_float),
15563 #define MIPS_SET_FCSR 1
15564 DIRECT_NO_TARGET_BUILTIN (set_fcsr, MIPS_VOID_FTYPE_USI, hard_float),
15566 DIRECT_BUILTIN (pll_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
15567 DIRECT_BUILTIN (pul_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
15568 DIRECT_BUILTIN (plu_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
15569 DIRECT_BUILTIN (puu_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single),
15570 DIRECT_BUILTIN (cvt_ps_s, MIPS_V2SF_FTYPE_SF_SF, paired_single),
15571 DIRECT_BUILTIN (cvt_s_pl, MIPS_SF_FTYPE_V2SF, paired_single),
15572 DIRECT_BUILTIN (cvt_s_pu, MIPS_SF_FTYPE_V2SF, paired_single),
15573 DIRECT_BUILTIN (abs_ps, MIPS_V2SF_FTYPE_V2SF, paired_single),
15575 DIRECT_BUILTIN (alnv_ps, MIPS_V2SF_FTYPE_V2SF_V2SF_INT, paired_single),
15576 DIRECT_BUILTIN (addr_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
15577 DIRECT_BUILTIN (mulr_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
15578 DIRECT_BUILTIN (cvt_pw_ps, MIPS_V2SF_FTYPE_V2SF, mips3d),
15579 DIRECT_BUILTIN (cvt_ps_pw, MIPS_V2SF_FTYPE_V2SF, mips3d),
15581 DIRECT_BUILTIN (recip1_s, MIPS_SF_FTYPE_SF, mips3d),
15582 DIRECT_BUILTIN (recip1_d, MIPS_DF_FTYPE_DF, mips3d),
15583 DIRECT_BUILTIN (recip1_ps, MIPS_V2SF_FTYPE_V2SF, mips3d),
15584 DIRECT_BUILTIN (recip2_s, MIPS_SF_FTYPE_SF_SF, mips3d),
15585 DIRECT_BUILTIN (recip2_d, MIPS_DF_FTYPE_DF_DF, mips3d),
15586 DIRECT_BUILTIN (recip2_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
15588 DIRECT_BUILTIN (rsqrt1_s, MIPS_SF_FTYPE_SF, mips3d),
15589 DIRECT_BUILTIN (rsqrt1_d, MIPS_DF_FTYPE_DF, mips3d),
15590 DIRECT_BUILTIN (rsqrt1_ps, MIPS_V2SF_FTYPE_V2SF, mips3d),
15591 DIRECT_BUILTIN (rsqrt2_s, MIPS_SF_FTYPE_SF_SF, mips3d),
15592 DIRECT_BUILTIN (rsqrt2_d, MIPS_DF_FTYPE_DF_DF, mips3d),
15593 DIRECT_BUILTIN (rsqrt2_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d),
15595 MIPS_FP_CONDITIONS (CMP_BUILTINS),
15597 /* Built-in functions for the SB-1 processor. */
15598 DIRECT_BUILTIN (sqrt_ps, MIPS_V2SF_FTYPE_V2SF, sb1_paired_single),
15600 /* Built-in functions for the DSP ASE (32-bit and 64-bit). */
15601 DIRECT_BUILTIN (addq_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15602 DIRECT_BUILTIN (addq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15603 DIRECT_BUILTIN (addq_s_w, MIPS_SI_FTYPE_SI_SI, dsp),
15604 DIRECT_BUILTIN (addu_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
15605 DIRECT_BUILTIN (addu_s_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
15606 DIRECT_BUILTIN (subq_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15607 DIRECT_BUILTIN (subq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15608 DIRECT_BUILTIN (subq_s_w, MIPS_SI_FTYPE_SI_SI, dsp),
15609 DIRECT_BUILTIN (subu_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
15610 DIRECT_BUILTIN (subu_s_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
15611 DIRECT_BUILTIN (addsc, MIPS_SI_FTYPE_SI_SI, dsp),
15612 DIRECT_BUILTIN (addwc, MIPS_SI_FTYPE_SI_SI, dsp),
15613 DIRECT_BUILTIN (modsub, MIPS_SI_FTYPE_SI_SI, dsp),
15614 DIRECT_BUILTIN (raddu_w_qb, MIPS_SI_FTYPE_V4QI, dsp),
15615 DIRECT_BUILTIN (absq_s_ph, MIPS_V2HI_FTYPE_V2HI, dsp),
15616 DIRECT_BUILTIN (absq_s_w, MIPS_SI_FTYPE_SI, dsp),
15617 DIRECT_BUILTIN (precrq_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dsp),
15618 DIRECT_BUILTIN (precrq_ph_w, MIPS_V2HI_FTYPE_SI_SI, dsp),
15619 DIRECT_BUILTIN (precrq_rs_ph_w, MIPS_V2HI_FTYPE_SI_SI, dsp),
15620 DIRECT_BUILTIN (precrqu_s_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dsp),
15621 DIRECT_BUILTIN (preceq_w_phl, MIPS_SI_FTYPE_V2HI, dsp),
15622 DIRECT_BUILTIN (preceq_w_phr, MIPS_SI_FTYPE_V2HI, dsp),
15623 DIRECT_BUILTIN (precequ_ph_qbl, MIPS_V2HI_FTYPE_V4QI, dsp),
15624 DIRECT_BUILTIN (precequ_ph_qbr, MIPS_V2HI_FTYPE_V4QI, dsp),
15625 DIRECT_BUILTIN (precequ_ph_qbla, MIPS_V2HI_FTYPE_V4QI, dsp),
15626 DIRECT_BUILTIN (precequ_ph_qbra, MIPS_V2HI_FTYPE_V4QI, dsp),
15627 DIRECT_BUILTIN (preceu_ph_qbl, MIPS_V2HI_FTYPE_V4QI, dsp),
15628 DIRECT_BUILTIN (preceu_ph_qbr, MIPS_V2HI_FTYPE_V4QI, dsp),
15629 DIRECT_BUILTIN (preceu_ph_qbla, MIPS_V2HI_FTYPE_V4QI, dsp),
15630 DIRECT_BUILTIN (preceu_ph_qbra, MIPS_V2HI_FTYPE_V4QI, dsp),
15631 DIRECT_BUILTIN (shll_qb, MIPS_V4QI_FTYPE_V4QI_SI, dsp),
15632 DIRECT_BUILTIN (shll_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
15633 DIRECT_BUILTIN (shll_s_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
15634 DIRECT_BUILTIN (shll_s_w, MIPS_SI_FTYPE_SI_SI, dsp),
15635 DIRECT_BUILTIN (shrl_qb, MIPS_V4QI_FTYPE_V4QI_SI, dsp),
15636 DIRECT_BUILTIN (shra_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
15637 DIRECT_BUILTIN (shra_r_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp),
15638 DIRECT_BUILTIN (shra_r_w, MIPS_SI_FTYPE_SI_SI, dsp),
15639 DIRECT_BUILTIN (muleu_s_ph_qbl, MIPS_V2HI_FTYPE_V4QI_V2HI, dsp),
15640 DIRECT_BUILTIN (muleu_s_ph_qbr, MIPS_V2HI_FTYPE_V4QI_V2HI, dsp),
15641 DIRECT_BUILTIN (mulq_rs_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15642 DIRECT_BUILTIN (muleq_s_w_phl, MIPS_SI_FTYPE_V2HI_V2HI, dsp),
15643 DIRECT_BUILTIN (muleq_s_w_phr, MIPS_SI_FTYPE_V2HI_V2HI, dsp),
15644 DIRECT_BUILTIN (bitrev, MIPS_SI_FTYPE_SI, dsp),
15645 DIRECT_BUILTIN (insv, MIPS_SI_FTYPE_SI_SI, dsp),
15646 DIRECT_BUILTIN (repl_qb, MIPS_V4QI_FTYPE_SI, dsp),
15647 DIRECT_BUILTIN (repl_ph, MIPS_V2HI_FTYPE_SI, dsp),
15648 DIRECT_NO_TARGET_BUILTIN (cmpu_eq_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp),
15649 DIRECT_NO_TARGET_BUILTIN (cmpu_lt_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp),
15650 DIRECT_NO_TARGET_BUILTIN (cmpu_le_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp),
15651 DIRECT_BUILTIN (cmpgu_eq_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp),
15652 DIRECT_BUILTIN (cmpgu_lt_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp),
15653 DIRECT_BUILTIN (cmpgu_le_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp),
15654 DIRECT_NO_TARGET_BUILTIN (cmp_eq_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp),
15655 DIRECT_NO_TARGET_BUILTIN (cmp_lt_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp),
15656 DIRECT_NO_TARGET_BUILTIN (cmp_le_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp),
15657 DIRECT_BUILTIN (pick_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp),
15658 DIRECT_BUILTIN (pick_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15659 DIRECT_BUILTIN (packrl_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp),
15660 DIRECT_NO_TARGET_BUILTIN (wrdsp, MIPS_VOID_FTYPE_SI_SI, dsp),
15661 DIRECT_BUILTIN (rddsp, MIPS_SI_FTYPE_SI, dsp),
15662 DIRECT_BUILTIN (lbux, MIPS_SI_FTYPE_POINTER_SI, dsp),
15663 DIRECT_BUILTIN (lhx, MIPS_SI_FTYPE_POINTER_SI, dsp),
15664 DIRECT_BUILTIN (lwx, MIPS_SI_FTYPE_POINTER_SI, dsp),
15665 BPOSGE_BUILTIN (32, dsp),
15667 /* The following are for the MIPS DSP ASE REV 2 (32-bit and 64-bit). */
15668 DIRECT_BUILTIN (absq_s_qb, MIPS_V4QI_FTYPE_V4QI, dspr2),
15669 DIRECT_BUILTIN (addu_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15670 DIRECT_BUILTIN (addu_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15671 DIRECT_BUILTIN (adduh_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
15672 DIRECT_BUILTIN (adduh_r_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
15673 DIRECT_BUILTIN (append, MIPS_SI_FTYPE_SI_SI_SI, dspr2),
15674 DIRECT_BUILTIN (balign, MIPS_SI_FTYPE_SI_SI_SI, dspr2),
15675 DIRECT_BUILTIN (cmpgdu_eq_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2),
15676 DIRECT_BUILTIN (cmpgdu_lt_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2),
15677 DIRECT_BUILTIN (cmpgdu_le_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2),
15678 DIRECT_BUILTIN (mul_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15679 DIRECT_BUILTIN (mul_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15680 DIRECT_BUILTIN (mulq_rs_w, MIPS_SI_FTYPE_SI_SI, dspr2),
15681 DIRECT_BUILTIN (mulq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15682 DIRECT_BUILTIN (mulq_s_w, MIPS_SI_FTYPE_SI_SI, dspr2),
15683 DIRECT_BUILTIN (precr_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dspr2),
15684 DIRECT_BUILTIN (precr_sra_ph_w, MIPS_V2HI_FTYPE_SI_SI_SI, dspr2),
15685 DIRECT_BUILTIN (precr_sra_r_ph_w, MIPS_V2HI_FTYPE_SI_SI_SI, dspr2),
15686 DIRECT_BUILTIN (prepend, MIPS_SI_FTYPE_SI_SI_SI, dspr2),
15687 DIRECT_BUILTIN (shra_qb, MIPS_V4QI_FTYPE_V4QI_SI, dspr2),
15688 DIRECT_BUILTIN (shra_r_qb, MIPS_V4QI_FTYPE_V4QI_SI, dspr2),
15689 DIRECT_BUILTIN (shrl_ph, MIPS_V2HI_FTYPE_V2HI_SI, dspr2),
15690 DIRECT_BUILTIN (subu_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15691 DIRECT_BUILTIN (subu_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15692 DIRECT_BUILTIN (subuh_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
15693 DIRECT_BUILTIN (subuh_r_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2),
15694 DIRECT_BUILTIN (addqh_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15695 DIRECT_BUILTIN (addqh_r_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15696 DIRECT_BUILTIN (addqh_w, MIPS_SI_FTYPE_SI_SI, dspr2),
15697 DIRECT_BUILTIN (addqh_r_w, MIPS_SI_FTYPE_SI_SI, dspr2),
15698 DIRECT_BUILTIN (subqh_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15699 DIRECT_BUILTIN (subqh_r_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2),
15700 DIRECT_BUILTIN (subqh_w, MIPS_SI_FTYPE_SI_SI, dspr2),
15701 DIRECT_BUILTIN (subqh_r_w, MIPS_SI_FTYPE_SI_SI, dspr2),
15703 /* Built-in functions for the DSP ASE (32-bit only). */
15704 DIRECT_BUILTIN (dpau_h_qbl, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
15705 DIRECT_BUILTIN (dpau_h_qbr, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
15706 DIRECT_BUILTIN (dpsu_h_qbl, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
15707 DIRECT_BUILTIN (dpsu_h_qbr, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32),
15708 DIRECT_BUILTIN (dpaq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15709 DIRECT_BUILTIN (dpsq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15710 DIRECT_BUILTIN (mulsaq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15711 DIRECT_BUILTIN (dpaq_sa_l_w, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
15712 DIRECT_BUILTIN (dpsq_sa_l_w, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
15713 DIRECT_BUILTIN (maq_s_w_phl, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15714 DIRECT_BUILTIN (maq_s_w_phr, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15715 DIRECT_BUILTIN (maq_sa_w_phl, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15716 DIRECT_BUILTIN (maq_sa_w_phr, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32),
15717 DIRECT_BUILTIN (extr_w, MIPS_SI_FTYPE_DI_SI, dsp_32),
15718 DIRECT_BUILTIN (extr_r_w, MIPS_SI_FTYPE_DI_SI, dsp_32),
15719 DIRECT_BUILTIN (extr_rs_w, MIPS_SI_FTYPE_DI_SI, dsp_32),
15720 DIRECT_BUILTIN (extr_s_h, MIPS_SI_FTYPE_DI_SI, dsp_32),
15721 DIRECT_BUILTIN (extp, MIPS_SI_FTYPE_DI_SI, dsp_32),
15722 DIRECT_BUILTIN (extpdp, MIPS_SI_FTYPE_DI_SI, dsp_32),
15723 DIRECT_BUILTIN (shilo, MIPS_DI_FTYPE_DI_SI, dsp_32),
15724 DIRECT_BUILTIN (mthlip, MIPS_DI_FTYPE_DI_SI, dsp_32),
15725 DIRECT_BUILTIN (madd, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
15726 DIRECT_BUILTIN (maddu, MIPS_DI_FTYPE_DI_USI_USI, dsp_32),
15727 DIRECT_BUILTIN (msub, MIPS_DI_FTYPE_DI_SI_SI, dsp_32),
15728 DIRECT_BUILTIN (msubu, MIPS_DI_FTYPE_DI_USI_USI, dsp_32),
15729 DIRECT_BUILTIN (mult, MIPS_DI_FTYPE_SI_SI, dsp_32),
15730 DIRECT_BUILTIN (multu, MIPS_DI_FTYPE_USI_USI, dsp_32),
15732 /* Built-in functions for the DSP ASE (64-bit only). */
15733 DIRECT_BUILTIN (ldx, MIPS_DI_FTYPE_POINTER_SI, dsp_64),
15735 /* The following are for the MIPS DSP ASE REV 2 (32-bit only). */
15736 DIRECT_BUILTIN (dpa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15737 DIRECT_BUILTIN (dps_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15738 DIRECT_BUILTIN (mulsa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15739 DIRECT_BUILTIN (dpax_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15740 DIRECT_BUILTIN (dpsx_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15741 DIRECT_BUILTIN (dpaqx_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15742 DIRECT_BUILTIN (dpaqx_sa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15743 DIRECT_BUILTIN (dpsqx_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15744 DIRECT_BUILTIN (dpsqx_sa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32),
15746 /* Builtin functions for ST Microelectronics Loongson-2E/2F cores. */
15747 LOONGSON_BUILTIN (packsswh, MIPS_V4HI_FTYPE_V2SI_V2SI),
15748 LOONGSON_BUILTIN (packsshb, MIPS_V8QI_FTYPE_V4HI_V4HI),
15749 LOONGSON_BUILTIN (packushb, MIPS_UV8QI_FTYPE_UV4HI_UV4HI),
15750 LOONGSON_BUILTIN_SUFFIX (paddw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15751 LOONGSON_BUILTIN_SUFFIX (paddh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15752 LOONGSON_BUILTIN_SUFFIX (paddb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15753 LOONGSON_BUILTIN_SUFFIX (paddw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
15754 LOONGSON_BUILTIN_SUFFIX (paddh, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15755 LOONGSON_BUILTIN_SUFFIX (paddb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
15756 LOONGSON_BUILTIN_SUFFIX (paddd, u, MIPS_UDI_FTYPE_UDI_UDI),
15757 LOONGSON_BUILTIN_SUFFIX (paddd, s, MIPS_DI_FTYPE_DI_DI),
15758 LOONGSON_BUILTIN (paddsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15759 LOONGSON_BUILTIN (paddsb, MIPS_V8QI_FTYPE_V8QI_V8QI),
15760 LOONGSON_BUILTIN (paddush, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15761 LOONGSON_BUILTIN (paddusb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15762 LOONGSON_BUILTIN_ALIAS (pandn_d, pandn_ud, MIPS_UDI_FTYPE_UDI_UDI),
15763 LOONGSON_BUILTIN_ALIAS (pandn_w, pandn_uw, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15764 LOONGSON_BUILTIN_ALIAS (pandn_h, pandn_uh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15765 LOONGSON_BUILTIN_ALIAS (pandn_b, pandn_ub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15766 LOONGSON_BUILTIN_ALIAS (pandn_d, pandn_sd, MIPS_DI_FTYPE_DI_DI),
15767 LOONGSON_BUILTIN_ALIAS (pandn_w, pandn_sw, MIPS_V2SI_FTYPE_V2SI_V2SI),
15768 LOONGSON_BUILTIN_ALIAS (pandn_h, pandn_sh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15769 LOONGSON_BUILTIN_ALIAS (pandn_b, pandn_sb, MIPS_V8QI_FTYPE_V8QI_V8QI),
15770 LOONGSON_BUILTIN (pavgh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15771 LOONGSON_BUILTIN (pavgb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15772 LOONGSON_BUILTIN_SUFFIX (pcmpeqw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15773 LOONGSON_BUILTIN_SUFFIX (pcmpeqh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15774 LOONGSON_BUILTIN_SUFFIX (pcmpeqb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15775 LOONGSON_BUILTIN_SUFFIX (pcmpeqw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
15776 LOONGSON_BUILTIN_SUFFIX (pcmpeqh, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15777 LOONGSON_BUILTIN_SUFFIX (pcmpeqb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
15778 LOONGSON_BUILTIN_SUFFIX (pcmpgtw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15779 LOONGSON_BUILTIN_SUFFIX (pcmpgth, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15780 LOONGSON_BUILTIN_SUFFIX (pcmpgtb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15781 LOONGSON_BUILTIN_SUFFIX (pcmpgtw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
15782 LOONGSON_BUILTIN_SUFFIX (pcmpgth, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15783 LOONGSON_BUILTIN_SUFFIX (pcmpgtb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
15784 LOONGSON_BUILTIN_SUFFIX (pextrh, u, MIPS_UV4HI_FTYPE_UV4HI_USI),
15785 LOONGSON_BUILTIN_SUFFIX (pextrh, s, MIPS_V4HI_FTYPE_V4HI_USI),
15786 LOONGSON_BUILTIN_SUFFIX (pinsrh_0, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15787 LOONGSON_BUILTIN_SUFFIX (pinsrh_1, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15788 LOONGSON_BUILTIN_SUFFIX (pinsrh_2, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15789 LOONGSON_BUILTIN_SUFFIX (pinsrh_3, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15790 LOONGSON_BUILTIN_SUFFIX (pinsrh_0, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15791 LOONGSON_BUILTIN_SUFFIX (pinsrh_1, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15792 LOONGSON_BUILTIN_SUFFIX (pinsrh_2, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15793 LOONGSON_BUILTIN_SUFFIX (pinsrh_3, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15794 LOONGSON_BUILTIN (pmaddhw, MIPS_V2SI_FTYPE_V4HI_V4HI),
15795 LOONGSON_BUILTIN (pmaxsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15796 LOONGSON_BUILTIN (pmaxub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15797 LOONGSON_BUILTIN (pminsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15798 LOONGSON_BUILTIN (pminub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15799 LOONGSON_BUILTIN_SUFFIX (pmovmskb, u, MIPS_UV8QI_FTYPE_UV8QI),
15800 LOONGSON_BUILTIN_SUFFIX (pmovmskb, s, MIPS_V8QI_FTYPE_V8QI),
15801 LOONGSON_BUILTIN (pmulhuh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15802 LOONGSON_BUILTIN (pmulhh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15803 LOONGSON_BUILTIN (pmullh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15804 LOONGSON_BUILTIN (pmuluw, MIPS_UDI_FTYPE_UV2SI_UV2SI),
15805 LOONGSON_BUILTIN (pasubub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15806 LOONGSON_BUILTIN (biadd, MIPS_UV4HI_FTYPE_UV8QI),
15807 LOONGSON_BUILTIN (psadbh, MIPS_UV4HI_FTYPE_UV8QI_UV8QI),
15808 LOONGSON_BUILTIN_SUFFIX (pshufh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
15809 LOONGSON_BUILTIN_SUFFIX (pshufh, s, MIPS_V4HI_FTYPE_V4HI_UQI),
15810 LOONGSON_BUILTIN_SUFFIX (psllh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
15811 LOONGSON_BUILTIN_SUFFIX (psllh, s, MIPS_V4HI_FTYPE_V4HI_UQI),
15812 LOONGSON_BUILTIN_SUFFIX (psllw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI),
15813 LOONGSON_BUILTIN_SUFFIX (psllw, s, MIPS_V2SI_FTYPE_V2SI_UQI),
15814 LOONGSON_BUILTIN_SUFFIX (psrah, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
15815 LOONGSON_BUILTIN_SUFFIX (psrah, s, MIPS_V4HI_FTYPE_V4HI_UQI),
15816 LOONGSON_BUILTIN_SUFFIX (psraw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI),
15817 LOONGSON_BUILTIN_SUFFIX (psraw, s, MIPS_V2SI_FTYPE_V2SI_UQI),
15818 LOONGSON_BUILTIN_SUFFIX (psrlh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI),
15819 LOONGSON_BUILTIN_SUFFIX (psrlh, s, MIPS_V4HI_FTYPE_V4HI_UQI),
15820 LOONGSON_BUILTIN_SUFFIX (psrlw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI),
15821 LOONGSON_BUILTIN_SUFFIX (psrlw, s, MIPS_V2SI_FTYPE_V2SI_UQI),
15822 LOONGSON_BUILTIN_SUFFIX (psubw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15823 LOONGSON_BUILTIN_SUFFIX (psubh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15824 LOONGSON_BUILTIN_SUFFIX (psubb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15825 LOONGSON_BUILTIN_SUFFIX (psubw, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
15826 LOONGSON_BUILTIN_SUFFIX (psubh, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15827 LOONGSON_BUILTIN_SUFFIX (psubb, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
15828 LOONGSON_BUILTIN_SUFFIX (psubd, u, MIPS_UDI_FTYPE_UDI_UDI),
15829 LOONGSON_BUILTIN_SUFFIX (psubd, s, MIPS_DI_FTYPE_DI_DI),
15830 LOONGSON_BUILTIN (psubsh, MIPS_V4HI_FTYPE_V4HI_V4HI),
15831 LOONGSON_BUILTIN (psubsb, MIPS_V8QI_FTYPE_V8QI_V8QI),
15832 LOONGSON_BUILTIN (psubush, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15833 LOONGSON_BUILTIN (psubusb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15834 LOONGSON_BUILTIN_SUFFIX (punpckhbh, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15835 LOONGSON_BUILTIN_SUFFIX (punpckhhw, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15836 LOONGSON_BUILTIN_SUFFIX (punpckhwd, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15837 LOONGSON_BUILTIN_SUFFIX (punpckhbh, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
15838 LOONGSON_BUILTIN_SUFFIX (punpckhhw, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15839 LOONGSON_BUILTIN_SUFFIX (punpckhwd, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
15840 LOONGSON_BUILTIN_SUFFIX (punpcklbh, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI),
15841 LOONGSON_BUILTIN_SUFFIX (punpcklhw, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI),
15842 LOONGSON_BUILTIN_SUFFIX (punpcklwd, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI),
15843 LOONGSON_BUILTIN_SUFFIX (punpcklbh, s, MIPS_V8QI_FTYPE_V8QI_V8QI),
15844 LOONGSON_BUILTIN_SUFFIX (punpcklhw, s, MIPS_V4HI_FTYPE_V4HI_V4HI),
15845 LOONGSON_BUILTIN_SUFFIX (punpcklwd, s, MIPS_V2SI_FTYPE_V2SI_V2SI),
15847 /* Sundry other built-in functions. */
15848 DIRECT_NO_TARGET_BUILTIN (cache, MIPS_VOID_FTYPE_SI_CVPOINTER, cache),
15850 /* Built-in functions for MSA. */
15851 MSA_BUILTIN (sll_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15852 MSA_BUILTIN (sll_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15853 MSA_BUILTIN (sll_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15854 MSA_BUILTIN (sll_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15855 MSA_BUILTIN (slli_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15856 MSA_BUILTIN (slli_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15857 MSA_BUILTIN (slli_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15858 MSA_BUILTIN (slli_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15859 MSA_BUILTIN (sra_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15860 MSA_BUILTIN (sra_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15861 MSA_BUILTIN (sra_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15862 MSA_BUILTIN (sra_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15863 MSA_BUILTIN (srai_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15864 MSA_BUILTIN (srai_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15865 MSA_BUILTIN (srai_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15866 MSA_BUILTIN (srai_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15867 MSA_BUILTIN (srar_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15868 MSA_BUILTIN (srar_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15869 MSA_BUILTIN (srar_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15870 MSA_BUILTIN (srar_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15871 MSA_BUILTIN (srari_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15872 MSA_BUILTIN (srari_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15873 MSA_BUILTIN (srari_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15874 MSA_BUILTIN (srari_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15875 MSA_BUILTIN (srl_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15876 MSA_BUILTIN (srl_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15877 MSA_BUILTIN (srl_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15878 MSA_BUILTIN (srl_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15879 MSA_BUILTIN (srli_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15880 MSA_BUILTIN (srli_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15881 MSA_BUILTIN (srli_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15882 MSA_BUILTIN (srli_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15883 MSA_BUILTIN (srlr_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15884 MSA_BUILTIN (srlr_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15885 MSA_BUILTIN (srlr_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15886 MSA_BUILTIN (srlr_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15887 MSA_BUILTIN (srlri_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15888 MSA_BUILTIN (srlri_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15889 MSA_BUILTIN (srlri_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15890 MSA_BUILTIN (srlri_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15891 MSA_BUILTIN (bclr_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
15892 MSA_BUILTIN (bclr_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
15893 MSA_BUILTIN (bclr_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
15894 MSA_BUILTIN (bclr_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
15895 MSA_BUILTIN (bclri_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
15896 MSA_BUILTIN (bclri_h, MIPS_UV8HI_FTYPE_UV8HI_UQI),
15897 MSA_BUILTIN (bclri_w, MIPS_UV4SI_FTYPE_UV4SI_UQI),
15898 MSA_BUILTIN (bclri_d, MIPS_UV2DI_FTYPE_UV2DI_UQI),
15899 MSA_BUILTIN (bset_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
15900 MSA_BUILTIN (bset_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
15901 MSA_BUILTIN (bset_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
15902 MSA_BUILTIN (bset_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
15903 MSA_BUILTIN (bseti_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
15904 MSA_BUILTIN (bseti_h, MIPS_UV8HI_FTYPE_UV8HI_UQI),
15905 MSA_BUILTIN (bseti_w, MIPS_UV4SI_FTYPE_UV4SI_UQI),
15906 MSA_BUILTIN (bseti_d, MIPS_UV2DI_FTYPE_UV2DI_UQI),
15907 MSA_BUILTIN (bneg_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
15908 MSA_BUILTIN (bneg_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
15909 MSA_BUILTIN (bneg_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
15910 MSA_BUILTIN (bneg_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
15911 MSA_BUILTIN (bnegi_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
15912 MSA_BUILTIN (bnegi_h, MIPS_UV8HI_FTYPE_UV8HI_UQI),
15913 MSA_BUILTIN (bnegi_w, MIPS_UV4SI_FTYPE_UV4SI_UQI),
15914 MSA_BUILTIN (bnegi_d, MIPS_UV2DI_FTYPE_UV2DI_UQI),
15915 MSA_BUILTIN (binsl_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI),
15916 MSA_BUILTIN (binsl_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UV8HI),
15917 MSA_BUILTIN (binsl_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UV4SI),
15918 MSA_BUILTIN (binsl_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UV2DI),
15919 MSA_BUILTIN (binsli_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI),
15920 MSA_BUILTIN (binsli_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UQI),
15921 MSA_BUILTIN (binsli_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UQI),
15922 MSA_BUILTIN (binsli_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UQI),
15923 MSA_BUILTIN (binsr_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI),
15924 MSA_BUILTIN (binsr_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UV8HI),
15925 MSA_BUILTIN (binsr_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UV4SI),
15926 MSA_BUILTIN (binsr_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UV2DI),
15927 MSA_BUILTIN (binsri_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI),
15928 MSA_BUILTIN (binsri_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UQI),
15929 MSA_BUILTIN (binsri_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UQI),
15930 MSA_BUILTIN (binsri_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UQI),
15931 MSA_BUILTIN (addv_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15932 MSA_BUILTIN (addv_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15933 MSA_BUILTIN (addv_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15934 MSA_BUILTIN (addv_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15935 MSA_BUILTIN (addvi_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15936 MSA_BUILTIN (addvi_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15937 MSA_BUILTIN (addvi_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15938 MSA_BUILTIN (addvi_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15939 MSA_BUILTIN (subv_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15940 MSA_BUILTIN (subv_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15941 MSA_BUILTIN (subv_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15942 MSA_BUILTIN (subv_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15943 MSA_BUILTIN (subvi_b, MIPS_V16QI_FTYPE_V16QI_UQI),
15944 MSA_BUILTIN (subvi_h, MIPS_V8HI_FTYPE_V8HI_UQI),
15945 MSA_BUILTIN (subvi_w, MIPS_V4SI_FTYPE_V4SI_UQI),
15946 MSA_BUILTIN (subvi_d, MIPS_V2DI_FTYPE_V2DI_UQI),
15947 MSA_BUILTIN (max_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15948 MSA_BUILTIN (max_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15949 MSA_BUILTIN (max_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15950 MSA_BUILTIN (max_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15951 MSA_BUILTIN (maxi_s_b, MIPS_V16QI_FTYPE_V16QI_QI),
15952 MSA_BUILTIN (maxi_s_h, MIPS_V8HI_FTYPE_V8HI_QI),
15953 MSA_BUILTIN (maxi_s_w, MIPS_V4SI_FTYPE_V4SI_QI),
15954 MSA_BUILTIN (maxi_s_d, MIPS_V2DI_FTYPE_V2DI_QI),
15955 MSA_BUILTIN (max_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
15956 MSA_BUILTIN (max_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
15957 MSA_BUILTIN (max_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
15958 MSA_BUILTIN (max_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
15959 MSA_BUILTIN (maxi_u_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
15960 MSA_BUILTIN (maxi_u_h, MIPS_UV8HI_FTYPE_UV8HI_UQI),
15961 MSA_BUILTIN (maxi_u_w, MIPS_UV4SI_FTYPE_UV4SI_UQI),
15962 MSA_BUILTIN (maxi_u_d, MIPS_UV2DI_FTYPE_UV2DI_UQI),
15963 MSA_BUILTIN (min_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15964 MSA_BUILTIN (min_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15965 MSA_BUILTIN (min_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15966 MSA_BUILTIN (min_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15967 MSA_BUILTIN (mini_s_b, MIPS_V16QI_FTYPE_V16QI_QI),
15968 MSA_BUILTIN (mini_s_h, MIPS_V8HI_FTYPE_V8HI_QI),
15969 MSA_BUILTIN (mini_s_w, MIPS_V4SI_FTYPE_V4SI_QI),
15970 MSA_BUILTIN (mini_s_d, MIPS_V2DI_FTYPE_V2DI_QI),
15971 MSA_BUILTIN (min_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
15972 MSA_BUILTIN (min_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
15973 MSA_BUILTIN (min_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
15974 MSA_BUILTIN (min_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
15975 MSA_BUILTIN (mini_u_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
15976 MSA_BUILTIN (mini_u_h, MIPS_UV8HI_FTYPE_UV8HI_UQI),
15977 MSA_BUILTIN (mini_u_w, MIPS_UV4SI_FTYPE_UV4SI_UQI),
15978 MSA_BUILTIN (mini_u_d, MIPS_UV2DI_FTYPE_UV2DI_UQI),
15979 MSA_BUILTIN (max_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15980 MSA_BUILTIN (max_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15981 MSA_BUILTIN (max_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15982 MSA_BUILTIN (max_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15983 MSA_BUILTIN (min_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15984 MSA_BUILTIN (min_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15985 MSA_BUILTIN (min_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15986 MSA_BUILTIN (min_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15987 MSA_BUILTIN (ceq_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15988 MSA_BUILTIN (ceq_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15989 MSA_BUILTIN (ceq_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15990 MSA_BUILTIN (ceq_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15991 MSA_BUILTIN (ceqi_b, MIPS_V16QI_FTYPE_V16QI_QI),
15992 MSA_BUILTIN (ceqi_h, MIPS_V8HI_FTYPE_V8HI_QI),
15993 MSA_BUILTIN (ceqi_w, MIPS_V4SI_FTYPE_V4SI_QI),
15994 MSA_BUILTIN (ceqi_d, MIPS_V2DI_FTYPE_V2DI_QI),
15995 MSA_BUILTIN (clt_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
15996 MSA_BUILTIN (clt_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
15997 MSA_BUILTIN (clt_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
15998 MSA_BUILTIN (clt_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
15999 MSA_BUILTIN (clti_s_b, MIPS_V16QI_FTYPE_V16QI_QI),
16000 MSA_BUILTIN (clti_s_h, MIPS_V8HI_FTYPE_V8HI_QI),
16001 MSA_BUILTIN (clti_s_w, MIPS_V4SI_FTYPE_V4SI_QI),
16002 MSA_BUILTIN (clti_s_d, MIPS_V2DI_FTYPE_V2DI_QI),
16003 MSA_BUILTIN (clt_u_b, MIPS_V16QI_FTYPE_UV16QI_UV16QI),
16004 MSA_BUILTIN (clt_u_h, MIPS_V8HI_FTYPE_UV8HI_UV8HI),
16005 MSA_BUILTIN (clt_u_w, MIPS_V4SI_FTYPE_UV4SI_UV4SI),
16006 MSA_BUILTIN (clt_u_d, MIPS_V2DI_FTYPE_UV2DI_UV2DI),
16007 MSA_BUILTIN (clti_u_b, MIPS_V16QI_FTYPE_UV16QI_UQI),
16008 MSA_BUILTIN (clti_u_h, MIPS_V8HI_FTYPE_UV8HI_UQI),
16009 MSA_BUILTIN (clti_u_w, MIPS_V4SI_FTYPE_UV4SI_UQI),
16010 MSA_BUILTIN (clti_u_d, MIPS_V2DI_FTYPE_UV2DI_UQI),
16011 MSA_BUILTIN (cle_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16012 MSA_BUILTIN (cle_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16013 MSA_BUILTIN (cle_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16014 MSA_BUILTIN (cle_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16015 MSA_BUILTIN (clei_s_b, MIPS_V16QI_FTYPE_V16QI_QI),
16016 MSA_BUILTIN (clei_s_h, MIPS_V8HI_FTYPE_V8HI_QI),
16017 MSA_BUILTIN (clei_s_w, MIPS_V4SI_FTYPE_V4SI_QI),
16018 MSA_BUILTIN (clei_s_d, MIPS_V2DI_FTYPE_V2DI_QI),
16019 MSA_BUILTIN (cle_u_b, MIPS_V16QI_FTYPE_UV16QI_UV16QI),
16020 MSA_BUILTIN (cle_u_h, MIPS_V8HI_FTYPE_UV8HI_UV8HI),
16021 MSA_BUILTIN (cle_u_w, MIPS_V4SI_FTYPE_UV4SI_UV4SI),
16022 MSA_BUILTIN (cle_u_d, MIPS_V2DI_FTYPE_UV2DI_UV2DI),
16023 MSA_BUILTIN (clei_u_b, MIPS_V16QI_FTYPE_UV16QI_UQI),
16024 MSA_BUILTIN (clei_u_h, MIPS_V8HI_FTYPE_UV8HI_UQI),
16025 MSA_BUILTIN (clei_u_w, MIPS_V4SI_FTYPE_UV4SI_UQI),
16026 MSA_BUILTIN (clei_u_d, MIPS_V2DI_FTYPE_UV2DI_UQI),
16027 MSA_BUILTIN (ld_b, MIPS_V16QI_FTYPE_POINTER_SI),
16028 MSA_BUILTIN (ld_h, MIPS_V8HI_FTYPE_POINTER_SI),
16029 MSA_BUILTIN (ld_w, MIPS_V4SI_FTYPE_POINTER_SI),
16030 MSA_BUILTIN (ld_d, MIPS_V2DI_FTYPE_POINTER_SI),
16031 MSA_NO_TARGET_BUILTIN (st_b, MIPS_VOID_FTYPE_V16QI_POINTER_SI),
16032 MSA_NO_TARGET_BUILTIN (st_h, MIPS_VOID_FTYPE_V8HI_POINTER_SI),
16033 MSA_NO_TARGET_BUILTIN (st_w, MIPS_VOID_FTYPE_V4SI_POINTER_SI),
16034 MSA_NO_TARGET_BUILTIN (st_d, MIPS_VOID_FTYPE_V2DI_POINTER_SI),
16035 MSA_BUILTIN (sat_s_b, MIPS_V16QI_FTYPE_V16QI_UQI),
16036 MSA_BUILTIN (sat_s_h, MIPS_V8HI_FTYPE_V8HI_UQI),
16037 MSA_BUILTIN (sat_s_w, MIPS_V4SI_FTYPE_V4SI_UQI),
16038 MSA_BUILTIN (sat_s_d, MIPS_V2DI_FTYPE_V2DI_UQI),
16039 MSA_BUILTIN (sat_u_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
16040 MSA_BUILTIN (sat_u_h, MIPS_UV8HI_FTYPE_UV8HI_UQI),
16041 MSA_BUILTIN (sat_u_w, MIPS_UV4SI_FTYPE_UV4SI_UQI),
16042 MSA_BUILTIN (sat_u_d, MIPS_UV2DI_FTYPE_UV2DI_UQI),
16043 MSA_BUILTIN (add_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16044 MSA_BUILTIN (add_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16045 MSA_BUILTIN (add_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16046 MSA_BUILTIN (add_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16047 MSA_BUILTIN (adds_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16048 MSA_BUILTIN (adds_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16049 MSA_BUILTIN (adds_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16050 MSA_BUILTIN (adds_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16051 MSA_BUILTIN (adds_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16052 MSA_BUILTIN (adds_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16053 MSA_BUILTIN (adds_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16054 MSA_BUILTIN (adds_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16055 MSA_BUILTIN (adds_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16056 MSA_BUILTIN (adds_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16057 MSA_BUILTIN (adds_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16058 MSA_BUILTIN (adds_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16059 MSA_BUILTIN (ave_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16060 MSA_BUILTIN (ave_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16061 MSA_BUILTIN (ave_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16062 MSA_BUILTIN (ave_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16063 MSA_BUILTIN (ave_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16064 MSA_BUILTIN (ave_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16065 MSA_BUILTIN (ave_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16066 MSA_BUILTIN (ave_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16067 MSA_BUILTIN (aver_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16068 MSA_BUILTIN (aver_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16069 MSA_BUILTIN (aver_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16070 MSA_BUILTIN (aver_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16071 MSA_BUILTIN (aver_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16072 MSA_BUILTIN (aver_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16073 MSA_BUILTIN (aver_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16074 MSA_BUILTIN (aver_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16075 MSA_BUILTIN (subs_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16076 MSA_BUILTIN (subs_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16077 MSA_BUILTIN (subs_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16078 MSA_BUILTIN (subs_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16079 MSA_BUILTIN (subs_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16080 MSA_BUILTIN (subs_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16081 MSA_BUILTIN (subs_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16082 MSA_BUILTIN (subs_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16083 MSA_BUILTIN (subsuu_s_b, MIPS_V16QI_FTYPE_UV16QI_UV16QI),
16084 MSA_BUILTIN (subsuu_s_h, MIPS_V8HI_FTYPE_UV8HI_UV8HI),
16085 MSA_BUILTIN (subsuu_s_w, MIPS_V4SI_FTYPE_UV4SI_UV4SI),
16086 MSA_BUILTIN (subsuu_s_d, MIPS_V2DI_FTYPE_UV2DI_UV2DI),
16087 MSA_BUILTIN (subsus_u_b, MIPS_UV16QI_FTYPE_UV16QI_V16QI),
16088 MSA_BUILTIN (subsus_u_h, MIPS_UV8HI_FTYPE_UV8HI_V8HI),
16089 MSA_BUILTIN (subsus_u_w, MIPS_UV4SI_FTYPE_UV4SI_V4SI),
16090 MSA_BUILTIN (subsus_u_d, MIPS_UV2DI_FTYPE_UV2DI_V2DI),
16091 MSA_BUILTIN (asub_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16092 MSA_BUILTIN (asub_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16093 MSA_BUILTIN (asub_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16094 MSA_BUILTIN (asub_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16095 MSA_BUILTIN (asub_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16096 MSA_BUILTIN (asub_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16097 MSA_BUILTIN (asub_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16098 MSA_BUILTIN (asub_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16099 MSA_BUILTIN (mulv_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16100 MSA_BUILTIN (mulv_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16101 MSA_BUILTIN (mulv_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16102 MSA_BUILTIN (mulv_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16103 MSA_BUILTIN (maddv_b, MIPS_V16QI_FTYPE_V16QI_V16QI_V16QI),
16104 MSA_BUILTIN (maddv_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16105 MSA_BUILTIN (maddv_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16106 MSA_BUILTIN (maddv_d, MIPS_V2DI_FTYPE_V2DI_V2DI_V2DI),
16107 MSA_BUILTIN (msubv_b, MIPS_V16QI_FTYPE_V16QI_V16QI_V16QI),
16108 MSA_BUILTIN (msubv_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16109 MSA_BUILTIN (msubv_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16110 MSA_BUILTIN (msubv_d, MIPS_V2DI_FTYPE_V2DI_V2DI_V2DI),
16111 MSA_BUILTIN (div_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16112 MSA_BUILTIN (div_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16113 MSA_BUILTIN (div_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16114 MSA_BUILTIN (div_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16115 MSA_BUILTIN (div_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16116 MSA_BUILTIN (div_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16117 MSA_BUILTIN (div_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16118 MSA_BUILTIN (div_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16119 MSA_BUILTIN (hadd_s_h, MIPS_V8HI_FTYPE_V16QI_V16QI),
16120 MSA_BUILTIN (hadd_s_w, MIPS_V4SI_FTYPE_V8HI_V8HI),
16121 MSA_BUILTIN (hadd_s_d, MIPS_V2DI_FTYPE_V4SI_V4SI),
16122 MSA_BUILTIN (hadd_u_h, MIPS_UV8HI_FTYPE_UV16QI_UV16QI),
16123 MSA_BUILTIN (hadd_u_w, MIPS_UV4SI_FTYPE_UV8HI_UV8HI),
16124 MSA_BUILTIN (hadd_u_d, MIPS_UV2DI_FTYPE_UV4SI_UV4SI),
16125 MSA_BUILTIN (hsub_s_h, MIPS_V8HI_FTYPE_V16QI_V16QI),
16126 MSA_BUILTIN (hsub_s_w, MIPS_V4SI_FTYPE_V8HI_V8HI),
16127 MSA_BUILTIN (hsub_s_d, MIPS_V2DI_FTYPE_V4SI_V4SI),
16128 MSA_BUILTIN (hsub_u_h, MIPS_V8HI_FTYPE_UV16QI_UV16QI),
16129 MSA_BUILTIN (hsub_u_w, MIPS_V4SI_FTYPE_UV8HI_UV8HI),
16130 MSA_BUILTIN (hsub_u_d, MIPS_V2DI_FTYPE_UV4SI_UV4SI),
16131 MSA_BUILTIN (mod_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16132 MSA_BUILTIN (mod_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16133 MSA_BUILTIN (mod_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16134 MSA_BUILTIN (mod_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16135 MSA_BUILTIN (mod_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16136 MSA_BUILTIN (mod_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI),
16137 MSA_BUILTIN (mod_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI),
16138 MSA_BUILTIN (mod_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI),
16139 MSA_BUILTIN (dotp_s_h, MIPS_V8HI_FTYPE_V16QI_V16QI),
16140 MSA_BUILTIN (dotp_s_w, MIPS_V4SI_FTYPE_V8HI_V8HI),
16141 MSA_BUILTIN (dotp_s_d, MIPS_V2DI_FTYPE_V4SI_V4SI),
16142 MSA_BUILTIN (dotp_u_h, MIPS_UV8HI_FTYPE_UV16QI_UV16QI),
16143 MSA_BUILTIN (dotp_u_w, MIPS_UV4SI_FTYPE_UV8HI_UV8HI),
16144 MSA_BUILTIN (dotp_u_d, MIPS_UV2DI_FTYPE_UV4SI_UV4SI),
16145 MSA_BUILTIN (dpadd_s_h, MIPS_V8HI_FTYPE_V8HI_V16QI_V16QI),
16146 MSA_BUILTIN (dpadd_s_w, MIPS_V4SI_FTYPE_V4SI_V8HI_V8HI),
16147 MSA_BUILTIN (dpadd_s_d, MIPS_V2DI_FTYPE_V2DI_V4SI_V4SI),
16148 MSA_BUILTIN (dpadd_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV16QI_UV16QI),
16149 MSA_BUILTIN (dpadd_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV8HI_UV8HI),
16150 MSA_BUILTIN (dpadd_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV4SI_UV4SI),
16151 MSA_BUILTIN (dpsub_s_h, MIPS_V8HI_FTYPE_V8HI_V16QI_V16QI),
16152 MSA_BUILTIN (dpsub_s_w, MIPS_V4SI_FTYPE_V4SI_V8HI_V8HI),
16153 MSA_BUILTIN (dpsub_s_d, MIPS_V2DI_FTYPE_V2DI_V4SI_V4SI),
16154 MSA_BUILTIN (dpsub_u_h, MIPS_V8HI_FTYPE_V8HI_UV16QI_UV16QI),
16155 MSA_BUILTIN (dpsub_u_w, MIPS_V4SI_FTYPE_V4SI_UV8HI_UV8HI),
16156 MSA_BUILTIN (dpsub_u_d, MIPS_V2DI_FTYPE_V2DI_UV4SI_UV4SI),
16157 MSA_BUILTIN (sld_b, MIPS_V16QI_FTYPE_V16QI_V16QI_SI),
16158 MSA_BUILTIN (sld_h, MIPS_V8HI_FTYPE_V8HI_V8HI_SI),
16159 MSA_BUILTIN (sld_w, MIPS_V4SI_FTYPE_V4SI_V4SI_SI),
16160 MSA_BUILTIN (sld_d, MIPS_V2DI_FTYPE_V2DI_V2DI_SI),
16161 MSA_BUILTIN (sldi_b, MIPS_V16QI_FTYPE_V16QI_V16QI_UQI),
16162 MSA_BUILTIN (sldi_h, MIPS_V8HI_FTYPE_V8HI_V8HI_UQI),
16163 MSA_BUILTIN (sldi_w, MIPS_V4SI_FTYPE_V4SI_V4SI_UQI),
16164 MSA_BUILTIN (sldi_d, MIPS_V2DI_FTYPE_V2DI_V2DI_UQI),
16165 MSA_BUILTIN (splat_b, MIPS_V16QI_FTYPE_V16QI_SI),
16166 MSA_BUILTIN (splat_h, MIPS_V8HI_FTYPE_V8HI_SI),
16167 MSA_BUILTIN (splat_w, MIPS_V4SI_FTYPE_V4SI_SI),
16168 MSA_BUILTIN (splat_d, MIPS_V2DI_FTYPE_V2DI_SI),
16169 MSA_BUILTIN (splati_b, MIPS_V16QI_FTYPE_V16QI_UQI),
16170 MSA_BUILTIN (splati_h, MIPS_V8HI_FTYPE_V8HI_UQI),
16171 MSA_BUILTIN (splati_w, MIPS_V4SI_FTYPE_V4SI_UQI),
16172 MSA_BUILTIN (splati_d, MIPS_V2DI_FTYPE_V2DI_UQI),
16173 MSA_BUILTIN (pckev_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16174 MSA_BUILTIN (pckev_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16175 MSA_BUILTIN (pckev_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16176 MSA_BUILTIN (pckev_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16177 MSA_BUILTIN (pckod_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16178 MSA_BUILTIN (pckod_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16179 MSA_BUILTIN (pckod_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16180 MSA_BUILTIN (pckod_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16181 MSA_BUILTIN (ilvl_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16182 MSA_BUILTIN (ilvl_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16183 MSA_BUILTIN (ilvl_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16184 MSA_BUILTIN (ilvl_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16185 MSA_BUILTIN (ilvr_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16186 MSA_BUILTIN (ilvr_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16187 MSA_BUILTIN (ilvr_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16188 MSA_BUILTIN (ilvr_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16189 MSA_BUILTIN (ilvev_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16190 MSA_BUILTIN (ilvev_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16191 MSA_BUILTIN (ilvev_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16192 MSA_BUILTIN (ilvev_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16193 MSA_BUILTIN (ilvod_b, MIPS_V16QI_FTYPE_V16QI_V16QI),
16194 MSA_BUILTIN (ilvod_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16195 MSA_BUILTIN (ilvod_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16196 MSA_BUILTIN (ilvod_d, MIPS_V2DI_FTYPE_V2DI_V2DI),
16197 MSA_BUILTIN (vshf_b, MIPS_V16QI_FTYPE_V16QI_V16QI_V16QI),
16198 MSA_BUILTIN (vshf_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16199 MSA_BUILTIN (vshf_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16200 MSA_BUILTIN (vshf_d, MIPS_V2DI_FTYPE_V2DI_V2DI_V2DI),
16201 MSA_BUILTIN (and_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16202 MSA_BUILTIN (andi_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
16203 MSA_BUILTIN (or_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16204 MSA_BUILTIN (ori_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
16205 MSA_BUILTIN (nor_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16206 MSA_BUILTIN (nori_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
16207 MSA_BUILTIN (xor_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI),
16208 MSA_BUILTIN (xori_b, MIPS_UV16QI_FTYPE_UV16QI_UQI),
16209 MSA_BUILTIN (bmnz_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI),
16210 MSA_BUILTIN (bmnzi_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI),
16211 MSA_BUILTIN (bmz_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI),
16212 MSA_BUILTIN (bmzi_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI),
16213 MSA_BUILTIN (bsel_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI),
16214 MSA_BUILTIN (bseli_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI),
16215 MSA_BUILTIN (shf_b, MIPS_V16QI_FTYPE_V16QI_UQI),
16216 MSA_BUILTIN (shf_h, MIPS_V8HI_FTYPE_V8HI_UQI),
16217 MSA_BUILTIN (shf_w, MIPS_V4SI_FTYPE_V4SI_UQI),
16218 MSA_BUILTIN (bnz_v, MIPS_SI_FTYPE_UV16QI),
16219 MSA_BUILTIN (bz_v, MIPS_SI_FTYPE_UV16QI),
16220 MSA_BUILTIN (fill_b, MIPS_V16QI_FTYPE_SI),
16221 MSA_BUILTIN (fill_h, MIPS_V8HI_FTYPE_SI),
16222 MSA_BUILTIN (fill_w, MIPS_V4SI_FTYPE_SI),
16223 MSA_BUILTIN (fill_d, MIPS_V2DI_FTYPE_DI),
16224 MSA_BUILTIN (pcnt_b, MIPS_V16QI_FTYPE_V16QI),
16225 MSA_BUILTIN (pcnt_h, MIPS_V8HI_FTYPE_V8HI),
16226 MSA_BUILTIN (pcnt_w, MIPS_V4SI_FTYPE_V4SI),
16227 MSA_BUILTIN (pcnt_d, MIPS_V2DI_FTYPE_V2DI),
16228 MSA_BUILTIN (nloc_b, MIPS_V16QI_FTYPE_V16QI),
16229 MSA_BUILTIN (nloc_h, MIPS_V8HI_FTYPE_V8HI),
16230 MSA_BUILTIN (nloc_w, MIPS_V4SI_FTYPE_V4SI),
16231 MSA_BUILTIN (nloc_d, MIPS_V2DI_FTYPE_V2DI),
16232 MSA_BUILTIN (nlzc_b, MIPS_V16QI_FTYPE_V16QI),
16233 MSA_BUILTIN (nlzc_h, MIPS_V8HI_FTYPE_V8HI),
16234 MSA_BUILTIN (nlzc_w, MIPS_V4SI_FTYPE_V4SI),
16235 MSA_BUILTIN (nlzc_d, MIPS_V2DI_FTYPE_V2DI),
16236 MSA_BUILTIN (copy_s_b, MIPS_SI_FTYPE_V16QI_UQI),
16237 MSA_BUILTIN (copy_s_h, MIPS_SI_FTYPE_V8HI_UQI),
16238 MSA_BUILTIN (copy_s_w, MIPS_SI_FTYPE_V4SI_UQI),
16239 MSA_BUILTIN (copy_s_d, MIPS_DI_FTYPE_V2DI_UQI),
16240 MSA_BUILTIN (copy_u_b, MIPS_SI_FTYPE_V16QI_UQI),
16241 MSA_BUILTIN (copy_u_h, MIPS_SI_FTYPE_V8HI_UQI),
16242 MSA_BUILTIN (copy_u_w, MIPS_SI_FTYPE_V4SI_UQI),
16243 MSA_BUILTIN (copy_u_d, MIPS_DI_FTYPE_V2DI_UQI),
16244 MSA_BUILTIN (insert_b, MIPS_V16QI_FTYPE_V16QI_UQI_SI),
16245 MSA_BUILTIN (insert_h, MIPS_V8HI_FTYPE_V8HI_UQI_SI),
16246 MSA_BUILTIN (insert_w, MIPS_V4SI_FTYPE_V4SI_UQI_SI),
16247 MSA_BUILTIN (insert_d, MIPS_V2DI_FTYPE_V2DI_UQI_DI),
16248 MSA_BUILTIN (insve_b, MIPS_V16QI_FTYPE_V16QI_UQI_V16QI),
16249 MSA_BUILTIN (insve_h, MIPS_V8HI_FTYPE_V8HI_UQI_V8HI),
16250 MSA_BUILTIN (insve_w, MIPS_V4SI_FTYPE_V4SI_UQI_V4SI),
16251 MSA_BUILTIN (insve_d, MIPS_V2DI_FTYPE_V2DI_UQI_V2DI),
16252 MSA_BUILTIN (bnz_b, MIPS_SI_FTYPE_UV16QI),
16253 MSA_BUILTIN (bnz_h, MIPS_SI_FTYPE_UV8HI),
16254 MSA_BUILTIN (bnz_w, MIPS_SI_FTYPE_UV4SI),
16255 MSA_BUILTIN (bnz_d, MIPS_SI_FTYPE_UV2DI),
16256 MSA_BUILTIN (bz_b, MIPS_SI_FTYPE_UV16QI),
16257 MSA_BUILTIN (bz_h, MIPS_SI_FTYPE_UV8HI),
16258 MSA_BUILTIN (bz_w, MIPS_SI_FTYPE_UV4SI),
16259 MSA_BUILTIN (bz_d, MIPS_SI_FTYPE_UV2DI),
16260 MSA_BUILTIN (ldi_b, MIPS_V16QI_FTYPE_HI),
16261 MSA_BUILTIN (ldi_h, MIPS_V8HI_FTYPE_HI),
16262 MSA_BUILTIN (ldi_w, MIPS_V4SI_FTYPE_HI),
16263 MSA_BUILTIN (ldi_d, MIPS_V2DI_FTYPE_HI),
16264 MSA_BUILTIN (fcaf_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16265 MSA_BUILTIN (fcaf_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16266 MSA_BUILTIN (fcor_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16267 MSA_BUILTIN (fcor_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16268 MSA_BUILTIN (fcun_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16269 MSA_BUILTIN (fcun_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16270 MSA_BUILTIN (fcune_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16271 MSA_BUILTIN (fcune_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16272 MSA_BUILTIN (fcueq_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16273 MSA_BUILTIN (fcueq_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16274 MSA_BUILTIN (fceq_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16275 MSA_BUILTIN (fceq_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16276 MSA_BUILTIN (fcne_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16277 MSA_BUILTIN (fcne_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16278 MSA_BUILTIN (fclt_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16279 MSA_BUILTIN (fclt_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16280 MSA_BUILTIN (fcult_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16281 MSA_BUILTIN (fcult_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16282 MSA_BUILTIN (fcle_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16283 MSA_BUILTIN (fcle_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16284 MSA_BUILTIN (fcule_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16285 MSA_BUILTIN (fcule_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16286 MSA_BUILTIN (fsaf_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16287 MSA_BUILTIN (fsaf_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16288 MSA_BUILTIN (fsor_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16289 MSA_BUILTIN (fsor_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16290 MSA_BUILTIN (fsun_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16291 MSA_BUILTIN (fsun_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16292 MSA_BUILTIN (fsune_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16293 MSA_BUILTIN (fsune_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16294 MSA_BUILTIN (fsueq_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16295 MSA_BUILTIN (fsueq_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16296 MSA_BUILTIN (fseq_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16297 MSA_BUILTIN (fseq_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16298 MSA_BUILTIN (fsne_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16299 MSA_BUILTIN (fsne_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16300 MSA_BUILTIN (fslt_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16301 MSA_BUILTIN (fslt_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16302 MSA_BUILTIN (fsult_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16303 MSA_BUILTIN (fsult_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16304 MSA_BUILTIN (fsle_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16305 MSA_BUILTIN (fsle_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16306 MSA_BUILTIN (fsule_w, MIPS_V4SI_FTYPE_V4SF_V4SF),
16307 MSA_BUILTIN (fsule_d, MIPS_V2DI_FTYPE_V2DF_V2DF),
16308 MSA_BUILTIN (fadd_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16309 MSA_BUILTIN (fadd_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16310 MSA_BUILTIN (fsub_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16311 MSA_BUILTIN (fsub_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16312 MSA_BUILTIN (fmul_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16313 MSA_BUILTIN (fmul_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16314 MSA_BUILTIN (fdiv_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16315 MSA_BUILTIN (fdiv_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16316 MSA_BUILTIN (fmadd_w, MIPS_V4SF_FTYPE_V4SF_V4SF_V4SF),
16317 MSA_BUILTIN (fmadd_d, MIPS_V2DF_FTYPE_V2DF_V2DF_V2DF),
16318 MSA_BUILTIN (fmsub_w, MIPS_V4SF_FTYPE_V4SF_V4SF_V4SF),
16319 MSA_BUILTIN (fmsub_d, MIPS_V2DF_FTYPE_V2DF_V2DF_V2DF),
16320 MSA_BUILTIN (fexp2_w, MIPS_V4SF_FTYPE_V4SF_V4SI),
16321 MSA_BUILTIN (fexp2_d, MIPS_V2DF_FTYPE_V2DF_V2DI),
16322 MSA_BUILTIN (fexdo_h, MIPS_V8HI_FTYPE_V4SF_V4SF),
16323 MSA_BUILTIN (fexdo_w, MIPS_V4SF_FTYPE_V2DF_V2DF),
16324 MSA_BUILTIN (ftq_h, MIPS_V8HI_FTYPE_V4SF_V4SF),
16325 MSA_BUILTIN (ftq_w, MIPS_V4SI_FTYPE_V2DF_V2DF),
16326 MSA_BUILTIN (fmin_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16327 MSA_BUILTIN (fmin_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16328 MSA_BUILTIN (fmin_a_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16329 MSA_BUILTIN (fmin_a_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16330 MSA_BUILTIN (fmax_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16331 MSA_BUILTIN (fmax_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16332 MSA_BUILTIN (fmax_a_w, MIPS_V4SF_FTYPE_V4SF_V4SF),
16333 MSA_BUILTIN (fmax_a_d, MIPS_V2DF_FTYPE_V2DF_V2DF),
16334 MSA_BUILTIN (mul_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16335 MSA_BUILTIN (mul_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16336 MSA_BUILTIN (mulr_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI),
16337 MSA_BUILTIN (mulr_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI),
16338 MSA_BUILTIN (madd_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16339 MSA_BUILTIN (madd_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16340 MSA_BUILTIN (maddr_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16341 MSA_BUILTIN (maddr_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16342 MSA_BUILTIN (msub_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16343 MSA_BUILTIN (msub_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16344 MSA_BUILTIN (msubr_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI),
16345 MSA_BUILTIN (msubr_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI),
16346 MSA_BUILTIN (fclass_w, MIPS_V4SI_FTYPE_V4SF),
16347 MSA_BUILTIN (fclass_d, MIPS_V2DI_FTYPE_V2DF),
16348 MSA_BUILTIN (fsqrt_w, MIPS_V4SF_FTYPE_V4SF),
16349 MSA_BUILTIN (fsqrt_d, MIPS_V2DF_FTYPE_V2DF),
16350 MSA_BUILTIN (frcp_w, MIPS_V4SF_FTYPE_V4SF),
16351 MSA_BUILTIN (frcp_d, MIPS_V2DF_FTYPE_V2DF),
16352 MSA_BUILTIN (frint_w, MIPS_V4SF_FTYPE_V4SF),
16353 MSA_BUILTIN (frint_d, MIPS_V2DF_FTYPE_V2DF),
16354 MSA_BUILTIN (frsqrt_w, MIPS_V4SF_FTYPE_V4SF),
16355 MSA_BUILTIN (frsqrt_d, MIPS_V2DF_FTYPE_V2DF),
16356 MSA_BUILTIN (flog2_w, MIPS_V4SF_FTYPE_V4SF),
16357 MSA_BUILTIN (flog2_d, MIPS_V2DF_FTYPE_V2DF),
16358 MSA_BUILTIN (fexupl_w, MIPS_V4SF_FTYPE_V8HI),
16359 MSA_BUILTIN (fexupl_d, MIPS_V2DF_FTYPE_V4SF),
16360 MSA_BUILTIN (fexupr_w, MIPS_V4SF_FTYPE_V8HI),
16361 MSA_BUILTIN (fexupr_d, MIPS_V2DF_FTYPE_V4SF),
16362 MSA_BUILTIN (ffql_w, MIPS_V4SF_FTYPE_V8HI),
16363 MSA_BUILTIN (ffql_d, MIPS_V2DF_FTYPE_V4SI),
16364 MSA_BUILTIN (ffqr_w, MIPS_V4SF_FTYPE_V8HI),
16365 MSA_BUILTIN (ffqr_d, MIPS_V2DF_FTYPE_V4SI),
16366 MSA_BUILTIN (ftint_s_w, MIPS_V4SI_FTYPE_V4SF),
16367 MSA_BUILTIN (ftint_s_d, MIPS_V2DI_FTYPE_V2DF),
16368 MSA_BUILTIN (ftint_u_w, MIPS_UV4SI_FTYPE_V4SF),
16369 MSA_BUILTIN (ftint_u_d, MIPS_UV2DI_FTYPE_V2DF),
16370 MSA_BUILTIN (ftrunc_s_w, MIPS_V4SI_FTYPE_V4SF),
16371 MSA_BUILTIN (ftrunc_s_d, MIPS_V2DI_FTYPE_V2DF),
16372 MSA_BUILTIN (ftrunc_u_w, MIPS_UV4SI_FTYPE_V4SF),
16373 MSA_BUILTIN (ftrunc_u_d, MIPS_UV2DI_FTYPE_V2DF),
16374 MSA_BUILTIN (ffint_s_w, MIPS_V4SF_FTYPE_V4SI),
16375 MSA_BUILTIN (ffint_s_d, MIPS_V2DF_FTYPE_V2DI),
16376 MSA_BUILTIN (ffint_u_w, MIPS_V4SF_FTYPE_UV4SI),
16377 MSA_BUILTIN (ffint_u_d, MIPS_V2DF_FTYPE_UV2DI),
16378 MSA_NO_TARGET_BUILTIN (ctcmsa, MIPS_VOID_FTYPE_UQI_SI),
16379 MSA_BUILTIN (cfcmsa, MIPS_SI_FTYPE_UQI),
16380 MSA_BUILTIN (move_v, MIPS_V16QI_FTYPE_V16QI),
16381 MSA_BUILTIN (cast_to_vector_float, MIPS_V4SF_FTYPE_SF),
16382 MSA_BUILTIN (cast_to_vector_double, MIPS_V2DF_FTYPE_DF),
16383 MSA_BUILTIN (cast_to_scalar_float, MIPS_SF_FTYPE_V4SF),
16384 MSA_BUILTIN (cast_to_scalar_double, MIPS_DF_FTYPE_V2DF)
16387 /* Index I is the function declaration for mips_builtins[I], or null if the
16388 function isn't defined on this target. */
16389 static GTY(()) tree mips_builtin_decls[ARRAY_SIZE (mips_builtins)];
16390 /* Get the index I of the function declaration for mips_builtin_decls[I]
16391 using the instruction code or return null if not defined for the target. */
16392 static GTY(()) int mips_get_builtin_decl_index[LAST_INSN_CODE];
16394 /* MODE is a vector mode whose elements have type TYPE. Return the type
16395 of the vector itself. */
16397 static tree
16398 mips_builtin_vector_type (tree type, machine_mode mode)
16400 static tree types[2 * (int) MAX_MACHINE_MODE];
16401 int mode_index;
16403 mode_index = (int) mode;
16405 if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type))
16406 mode_index += MAX_MACHINE_MODE;
16408 if (types[mode_index] == NULL_TREE)
16409 types[mode_index] = build_vector_type_for_mode (type, mode);
16410 return types[mode_index];
16413 /* Return a type for 'const volatile void *'. */
16415 static tree
16416 mips_build_cvpointer_type (void)
16418 static tree cache;
16420 if (cache == NULL_TREE)
16421 cache = build_pointer_type (build_qualified_type
16422 (void_type_node,
16423 TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE));
16424 return cache;
16427 /* Source-level argument types. */
16428 #define MIPS_ATYPE_VOID void_type_node
16429 #define MIPS_ATYPE_INT integer_type_node
16430 #define MIPS_ATYPE_POINTER ptr_type_node
16431 #define MIPS_ATYPE_CVPOINTER mips_build_cvpointer_type ()
16433 /* Standard mode-based argument types. */
16434 #define MIPS_ATYPE_QI intQI_type_node
16435 #define MIPS_ATYPE_UQI unsigned_intQI_type_node
16436 #define MIPS_ATYPE_HI intHI_type_node
16437 #define MIPS_ATYPE_SI intSI_type_node
16438 #define MIPS_ATYPE_USI unsigned_intSI_type_node
16439 #define MIPS_ATYPE_DI intDI_type_node
16440 #define MIPS_ATYPE_UDI unsigned_intDI_type_node
16441 #define MIPS_ATYPE_SF float_type_node
16442 #define MIPS_ATYPE_DF double_type_node
16444 /* Vector argument types. */
16445 #define MIPS_ATYPE_V2SF mips_builtin_vector_type (float_type_node, V2SFmode)
16446 #define MIPS_ATYPE_V2HI mips_builtin_vector_type (intHI_type_node, V2HImode)
16447 #define MIPS_ATYPE_V2SI mips_builtin_vector_type (intSI_type_node, V2SImode)
16448 #define MIPS_ATYPE_V4QI mips_builtin_vector_type (intQI_type_node, V4QImode)
16449 #define MIPS_ATYPE_V4HI mips_builtin_vector_type (intHI_type_node, V4HImode)
16450 #define MIPS_ATYPE_V8QI mips_builtin_vector_type (intQI_type_node, V8QImode)
16451 #define MIPS_ATYPE_V2DI mips_builtin_vector_type (intDI_type_node, V2DImode)
16452 #define MIPS_ATYPE_V4SI mips_builtin_vector_type (intSI_type_node, V4SImode)
16453 #define MIPS_ATYPE_V8HI mips_builtin_vector_type (intHI_type_node, V8HImode)
16454 #define MIPS_ATYPE_V16QI mips_builtin_vector_type (intQI_type_node, V16QImode)
16455 #define MIPS_ATYPE_V2DF mips_builtin_vector_type (double_type_node, V2DFmode)
16456 #define MIPS_ATYPE_V4SF mips_builtin_vector_type (float_type_node, V4SFmode)
16458 #define MIPS_ATYPE_UV2DI mips_builtin_vector_type (unsigned_intDI_type_node, V2DImode)
16459 #define MIPS_ATYPE_UV4SI mips_builtin_vector_type (unsigned_intSI_type_node, V4SImode)
16460 #define MIPS_ATYPE_UV8HI mips_builtin_vector_type (unsigned_intHI_type_node, V8HImode)
16461 #define MIPS_ATYPE_UV16QI mips_builtin_vector_type (unsigned_intQI_type_node, V16QImode)
16463 #define MIPS_ATYPE_UV2SI \
16464 mips_builtin_vector_type (unsigned_intSI_type_node, V2SImode)
16465 #define MIPS_ATYPE_UV4HI \
16466 mips_builtin_vector_type (unsigned_intHI_type_node, V4HImode)
16467 #define MIPS_ATYPE_UV8QI \
16468 mips_builtin_vector_type (unsigned_intQI_type_node, V8QImode)
16470 /* MIPS_FTYPE_ATYPESN takes N MIPS_FTYPES-like type codes and lists
16471 their associated MIPS_ATYPEs. */
16472 #define MIPS_FTYPE_ATYPES1(A, B) \
16473 MIPS_ATYPE_##A, MIPS_ATYPE_##B
16475 #define MIPS_FTYPE_ATYPES2(A, B, C) \
16476 MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C
16478 #define MIPS_FTYPE_ATYPES3(A, B, C, D) \
16479 MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C, MIPS_ATYPE_##D
16481 #define MIPS_FTYPE_ATYPES4(A, B, C, D, E) \
16482 MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C, MIPS_ATYPE_##D, \
16483 MIPS_ATYPE_##E
16485 /* Return the function type associated with function prototype TYPE. */
16487 static tree
16488 mips_build_function_type (enum mips_function_type type)
16490 static tree types[(int) MIPS_MAX_FTYPE_MAX];
16492 if (types[(int) type] == NULL_TREE)
16493 switch (type)
16495 #define DEF_MIPS_FTYPE(NUM, ARGS) \
16496 case MIPS_FTYPE_NAME##NUM ARGS: \
16497 types[(int) type] \
16498 = build_function_type_list (MIPS_FTYPE_ATYPES##NUM ARGS, \
16499 NULL_TREE); \
16500 break;
16501 #include "config/mips/mips-ftypes.def"
16502 #undef DEF_MIPS_FTYPE
16503 default:
16504 gcc_unreachable ();
16507 return types[(int) type];
16510 /* Implement TARGET_INIT_BUILTINS. */
16512 static void
16513 mips_init_builtins (void)
16515 const struct mips_builtin_description *d;
16516 unsigned int i;
16518 /* Iterate through all of the bdesc arrays, initializing all of the
16519 builtin functions. */
16520 for (i = 0; i < ARRAY_SIZE (mips_builtins); i++)
16522 d = &mips_builtins[i];
16523 if (d->avail ())
16525 mips_builtin_decls[i]
16526 = add_builtin_function (d->name,
16527 mips_build_function_type (d->function_type),
16528 i, BUILT_IN_MD, NULL, NULL);
16529 mips_get_builtin_decl_index[d->icode] = i;
16534 /* Implement TARGET_BUILTIN_DECL. */
16536 static tree
16537 mips_builtin_decl (unsigned int code, bool initialize_p ATTRIBUTE_UNUSED)
16539 if (code >= ARRAY_SIZE (mips_builtins))
16540 return error_mark_node;
16541 return mips_builtin_decls[code];
16544 /* Implement TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION. */
16546 static tree
16547 mips_builtin_vectorized_function (tree fndecl, tree type_out,
16548 tree type_in)
16550 machine_mode in_mode, out_mode;
16551 enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
16552 int in_n, out_n;
16554 if (TREE_CODE (type_out) != VECTOR_TYPE
16555 || TREE_CODE (type_in) != VECTOR_TYPE
16556 || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL
16557 || !ISA_HAS_MSA)
16558 return NULL_TREE;
16560 out_mode = TYPE_MODE (TREE_TYPE (type_out));
16561 out_n = TYPE_VECTOR_SUBPARTS (type_out);
16562 in_mode = TYPE_MODE (TREE_TYPE (type_in));
16563 in_n = TYPE_VECTOR_SUBPARTS (type_in);
16565 /* INSN is the name of the associated instruction pattern, without
16566 the leading CODE_FOR_. */
16567 #define MIPS_GET_BUILTIN(INSN) \
16568 mips_builtin_decls[mips_get_builtin_decl_index[CODE_FOR_##INSN]]
16570 switch (fn)
16572 case BUILT_IN_SQRT:
16573 if (out_mode == DFmode && out_n == 2
16574 && in_mode == DFmode && in_n == 2)
16575 return MIPS_GET_BUILTIN (msa_fsqrt_d);
16576 break;
16577 case BUILT_IN_SQRTF:
16578 if (out_mode == SFmode && out_n == 4
16579 && in_mode == SFmode && in_n == 4)
16580 return MIPS_GET_BUILTIN (msa_fsqrt_w);
16581 break;
16582 default:
16583 break;
16586 return NULL_TREE;
16589 /* Take argument ARGNO from EXP's argument list and convert it into
16590 an expand operand. Store the operand in *OP. */
16592 static void
16593 mips_prepare_builtin_arg (struct expand_operand *op, tree exp,
16594 unsigned int argno)
16596 tree arg;
16597 rtx value;
16599 arg = CALL_EXPR_ARG (exp, argno);
16600 value = expand_normal (arg);
16601 create_input_operand (op, value, TYPE_MODE (TREE_TYPE (arg)));
16604 /* Expand instruction ICODE as part of a built-in function sequence.
16605 Use the first NOPS elements of OPS as the instruction's operands.
16606 HAS_TARGET_P is true if operand 0 is a target; it is false if the
16607 instruction has no target.
16609 Return the target rtx if HAS_TARGET_P, otherwise return const0_rtx. */
16611 static rtx
16612 mips_expand_builtin_insn (enum insn_code icode, unsigned int nops,
16613 struct expand_operand *ops, bool has_target_p)
16615 if (!maybe_expand_insn (icode, nops, ops))
16617 error ("invalid argument to built-in function");
16618 return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx;
16620 return has_target_p ? ops[0].value : const0_rtx;
16623 /* Expand a floating-point comparison for built-in function call EXP.
16624 The first NARGS arguments are the values to be compared. ICODE is
16625 the .md pattern that does the comparison and COND is the condition
16626 that is being tested. Return an rtx for the result. */
16628 static rtx
16629 mips_expand_builtin_compare_1 (enum insn_code icode,
16630 enum mips_fp_condition cond,
16631 tree exp, int nargs)
16633 struct expand_operand ops[MAX_RECOG_OPERANDS];
16634 rtx output;
16635 int opno, argno;
16637 /* The instruction should have a target operand, an operand for each
16638 argument, and an operand for COND. */
16639 gcc_assert (nargs + 2 == insn_data[(int) icode].n_generator_args);
16641 output = mips_allocate_fcc (insn_data[(int) icode].operand[0].mode);
16642 opno = 0;
16643 create_fixed_operand (&ops[opno++], output);
16644 for (argno = 0; argno < nargs; argno++)
16645 mips_prepare_builtin_arg (&ops[opno++], exp, argno);
16646 create_integer_operand (&ops[opno++], (int) cond);
16647 return mips_expand_builtin_insn (icode, opno, ops, true);
16650 /* Expand a MIPS_BUILTIN_DIRECT or MIPS_BUILTIN_DIRECT_NO_TARGET function;
16651 HAS_TARGET_P says which. EXP is the CALL_EXPR that calls the function
16652 and ICODE is the code of the associated .md pattern. TARGET, if nonnull,
16653 suggests a good place to put the result. */
16655 static rtx
16656 mips_expand_builtin_direct (enum insn_code icode, rtx target, tree exp,
16657 bool has_target_p)
16659 struct expand_operand ops[MAX_RECOG_OPERANDS];
16660 int opno, argno;
16662 /* Map any target to operand 0. */
16663 opno = 0;
16664 if (has_target_p)
16665 create_output_operand (&ops[opno++], target, TYPE_MODE (TREE_TYPE (exp)));
16667 /* Map the arguments to the other operands. */
16668 gcc_assert (opno + call_expr_nargs (exp)
16669 == insn_data[icode].n_generator_args);
16670 for (argno = 0; argno < call_expr_nargs (exp); argno++)
16671 mips_prepare_builtin_arg (&ops[opno++], exp, argno);
16673 return mips_expand_builtin_insn (icode, opno, ops, has_target_p);
16676 /* Expand a __builtin_mips_movt_*_ps or __builtin_mips_movf_*_ps
16677 function; TYPE says which. EXP is the CALL_EXPR that calls the
16678 function, ICODE is the instruction that should be used to compare
16679 the first two arguments, and COND is the condition it should test.
16680 TARGET, if nonnull, suggests a good place to put the result. */
16682 static rtx
16683 mips_expand_builtin_movtf (enum mips_builtin_type type,
16684 enum insn_code icode, enum mips_fp_condition cond,
16685 rtx target, tree exp)
16687 struct expand_operand ops[4];
16688 rtx cmp_result;
16690 cmp_result = mips_expand_builtin_compare_1 (icode, cond, exp, 2);
16691 create_output_operand (&ops[0], target, TYPE_MODE (TREE_TYPE (exp)));
16692 if (type == MIPS_BUILTIN_MOVT)
16694 mips_prepare_builtin_arg (&ops[2], exp, 2);
16695 mips_prepare_builtin_arg (&ops[1], exp, 3);
16697 else
16699 mips_prepare_builtin_arg (&ops[1], exp, 2);
16700 mips_prepare_builtin_arg (&ops[2], exp, 3);
16702 create_fixed_operand (&ops[3], cmp_result);
16703 return mips_expand_builtin_insn (CODE_FOR_mips_cond_move_tf_ps,
16704 4, ops, true);
16707 /* Move VALUE_IF_TRUE into TARGET if CONDITION is true; move VALUE_IF_FALSE
16708 into TARGET otherwise. Return TARGET. */
16710 static rtx
16711 mips_builtin_branch_and_move (rtx condition, rtx target,
16712 rtx value_if_true, rtx value_if_false)
16714 rtx true_label, done_label;
16716 true_label = gen_label_rtx ();
16717 done_label = gen_label_rtx ();
16719 /* First assume that CONDITION is false. */
16720 mips_emit_move (target, value_if_false);
16722 /* Branch to TRUE_LABEL if CONDITION is true and DONE_LABEL otherwise. */
16723 emit_jump_insn (gen_condjump (condition, true_label));
16724 emit_jump_insn (gen_jump (done_label));
16725 emit_barrier ();
16727 /* Fix TARGET if CONDITION is true. */
16728 emit_label (true_label);
16729 mips_emit_move (target, value_if_true);
16731 emit_label (done_label);
16732 return target;
16735 /* Expand a comparison built-in function of type BUILTIN_TYPE. EXP is
16736 the CALL_EXPR that calls the function, ICODE is the code of the
16737 comparison instruction, and COND is the condition it should test.
16738 TARGET, if nonnull, suggests a good place to put the boolean result. */
16740 static rtx
16741 mips_expand_builtin_compare (enum mips_builtin_type builtin_type,
16742 enum insn_code icode, enum mips_fp_condition cond,
16743 rtx target, tree exp)
16745 rtx offset, condition, cmp_result;
16747 if (target == 0 || GET_MODE (target) != SImode)
16748 target = gen_reg_rtx (SImode);
16749 cmp_result = mips_expand_builtin_compare_1 (icode, cond, exp,
16750 call_expr_nargs (exp));
16752 /* If the comparison sets more than one register, we define the result
16753 to be 0 if all registers are false and -1 if all registers are true.
16754 The value of the complete result is indeterminate otherwise. */
16755 switch (builtin_type)
16757 case MIPS_BUILTIN_CMP_ALL:
16758 condition = gen_rtx_NE (VOIDmode, cmp_result, constm1_rtx);
16759 return mips_builtin_branch_and_move (condition, target,
16760 const0_rtx, const1_rtx);
16762 case MIPS_BUILTIN_CMP_UPPER:
16763 case MIPS_BUILTIN_CMP_LOWER:
16764 offset = GEN_INT (builtin_type == MIPS_BUILTIN_CMP_UPPER);
16765 condition = gen_single_cc (cmp_result, offset);
16766 return mips_builtin_branch_and_move (condition, target,
16767 const1_rtx, const0_rtx);
16769 default:
16770 condition = gen_rtx_NE (VOIDmode, cmp_result, const0_rtx);
16771 return mips_builtin_branch_and_move (condition, target,
16772 const1_rtx, const0_rtx);
16776 /* Expand a bposge built-in function of type BUILTIN_TYPE. TARGET,
16777 if nonnull, suggests a good place to put the boolean result. */
16779 static rtx
16780 mips_expand_builtin_bposge (enum mips_builtin_type builtin_type, rtx target)
16782 rtx condition, cmp_result;
16783 int cmp_value;
16785 if (target == 0 || GET_MODE (target) != SImode)
16786 target = gen_reg_rtx (SImode);
16788 cmp_result = gen_rtx_REG (CCDSPmode, CCDSP_PO_REGNUM);
16790 if (builtin_type == MIPS_BUILTIN_BPOSGE32)
16791 cmp_value = 32;
16792 else
16793 gcc_assert (0);
16795 condition = gen_rtx_GE (VOIDmode, cmp_result, GEN_INT (cmp_value));
16796 return mips_builtin_branch_and_move (condition, target,
16797 const1_rtx, const0_rtx);
16800 /* Implement TARGET_EXPAND_BUILTIN. */
16802 static rtx
16803 mips_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
16804 machine_mode mode, int ignore)
16806 tree fndecl;
16807 unsigned int fcode, avail;
16808 const struct mips_builtin_description *d;
16810 fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
16811 fcode = DECL_FUNCTION_CODE (fndecl);
16812 gcc_assert (fcode < ARRAY_SIZE (mips_builtins));
16813 d = &mips_builtins[fcode];
16814 avail = d->avail ();
16815 gcc_assert (avail != 0);
16816 if (TARGET_MIPS16 && !(avail & BUILTIN_AVAIL_MIPS16))
16818 error ("built-in function %qE not supported for MIPS16",
16819 DECL_NAME (fndecl));
16820 return ignore ? const0_rtx : CONST0_RTX (mode);
16822 switch (d->builtin_type)
16824 case MIPS_BUILTIN_DIRECT:
16825 return mips_expand_builtin_direct (d->icode, target, exp, true);
16827 case MIPS_BUILTIN_DIRECT_NO_TARGET:
16828 return mips_expand_builtin_direct (d->icode, target, exp, false);
16830 case MIPS_BUILTIN_MOVT:
16831 case MIPS_BUILTIN_MOVF:
16832 return mips_expand_builtin_movtf (d->builtin_type, d->icode,
16833 d->cond, target, exp);
16835 case MIPS_BUILTIN_CMP_ANY:
16836 case MIPS_BUILTIN_CMP_ALL:
16837 case MIPS_BUILTIN_CMP_UPPER:
16838 case MIPS_BUILTIN_CMP_LOWER:
16839 case MIPS_BUILTIN_CMP_SINGLE:
16840 return mips_expand_builtin_compare (d->builtin_type, d->icode,
16841 d->cond, target, exp);
16843 case MIPS_BUILTIN_BPOSGE32:
16844 return mips_expand_builtin_bposge (d->builtin_type, target);
16846 gcc_unreachable ();
16849 /* An entry in the MIPS16 constant pool. VALUE is the pool constant,
16850 MODE is its mode, and LABEL is the CODE_LABEL associated with it. */
16851 struct mips16_constant {
16852 struct mips16_constant *next;
16853 rtx value;
16854 rtx label;
16855 machine_mode mode;
16858 /* Information about an incomplete MIPS16 constant pool. FIRST is the
16859 first constant, HIGHEST_ADDRESS is the highest address that the first
16860 byte of the pool can have, and INSN_ADDRESS is the current instruction
16861 address. */
16862 struct mips16_constant_pool {
16863 struct mips16_constant *first;
16864 int highest_address;
16865 int insn_address;
16868 /* Add constant VALUE to POOL and return its label. MODE is the
16869 value's mode (used for CONST_INTs, etc.). */
16871 static rtx
16872 mips16_add_constant (struct mips16_constant_pool *pool,
16873 rtx value, machine_mode mode)
16875 struct mips16_constant **p, *c;
16876 bool first_of_size_p;
16878 /* See whether the constant is already in the pool. If so, return the
16879 existing label, otherwise leave P pointing to the place where the
16880 constant should be added.
16882 Keep the pool sorted in increasing order of mode size so that we can
16883 reduce the number of alignments needed. */
16884 first_of_size_p = true;
16885 for (p = &pool->first; *p != 0; p = &(*p)->next)
16887 if (mode == (*p)->mode && rtx_equal_p (value, (*p)->value))
16888 return (*p)->label;
16889 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE ((*p)->mode))
16890 break;
16891 if (GET_MODE_SIZE (mode) == GET_MODE_SIZE ((*p)->mode))
16892 first_of_size_p = false;
16895 /* In the worst case, the constant needed by the earliest instruction
16896 will end up at the end of the pool. The entire pool must then be
16897 accessible from that instruction.
16899 When adding the first constant, set the pool's highest address to
16900 the address of the first out-of-range byte. Adjust this address
16901 downwards each time a new constant is added. */
16902 if (pool->first == 0)
16903 /* For LWPC, ADDIUPC and DADDIUPC, the base PC value is the address
16904 of the instruction with the lowest two bits clear. The base PC
16905 value for LDPC has the lowest three bits clear. Assume the worst
16906 case here; namely that the PC-relative instruction occupies the
16907 last 2 bytes in an aligned word. */
16908 pool->highest_address = pool->insn_address - (UNITS_PER_WORD - 2) + 0x8000;
16909 pool->highest_address -= GET_MODE_SIZE (mode);
16910 if (first_of_size_p)
16911 /* Take into account the worst possible padding due to alignment. */
16912 pool->highest_address -= GET_MODE_SIZE (mode) - 1;
16914 /* Create a new entry. */
16915 c = XNEW (struct mips16_constant);
16916 c->value = value;
16917 c->mode = mode;
16918 c->label = gen_label_rtx ();
16919 c->next = *p;
16920 *p = c;
16922 return c->label;
16925 /* Output constant VALUE after instruction INSN and return the last
16926 instruction emitted. MODE is the mode of the constant. */
16928 static rtx
16929 mips16_emit_constants_1 (machine_mode mode, rtx value, rtx insn)
16931 if (SCALAR_INT_MODE_P (mode) || ALL_SCALAR_FIXED_POINT_MODE_P (mode))
16933 rtx size = GEN_INT (GET_MODE_SIZE (mode));
16934 return emit_insn_after (gen_consttable_int (value, size), insn);
16937 if (SCALAR_FLOAT_MODE_P (mode))
16938 return emit_insn_after (gen_consttable_float (value), insn);
16940 if (VECTOR_MODE_P (mode))
16942 int i;
16944 for (i = 0; i < CONST_VECTOR_NUNITS (value); i++)
16945 insn = mips16_emit_constants_1 (GET_MODE_INNER (mode),
16946 CONST_VECTOR_ELT (value, i), insn);
16947 return insn;
16950 gcc_unreachable ();
16953 /* Dump out the constants in CONSTANTS after INSN. */
16955 static void
16956 mips16_emit_constants (struct mips16_constant *constants, rtx insn)
16958 struct mips16_constant *c, *next;
16959 int align;
16961 align = 0;
16962 for (c = constants; c != NULL; c = next)
16964 /* If necessary, increase the alignment of PC. */
16965 if (align < GET_MODE_SIZE (c->mode))
16967 int align_log = floor_log2 (GET_MODE_SIZE (c->mode));
16968 insn = emit_insn_after (gen_align (GEN_INT (align_log)), insn);
16970 align = GET_MODE_SIZE (c->mode);
16972 insn = emit_label_after (c->label, insn);
16973 insn = mips16_emit_constants_1 (c->mode, c->value, insn);
16975 next = c->next;
16976 free (c);
16979 emit_barrier_after (insn);
16982 /* Return the length of instruction INSN. */
16984 static int
16985 mips16_insn_length (rtx insn)
16987 if (JUMP_TABLE_DATA_P (insn))
16989 rtx body = PATTERN (insn);
16990 if (GET_CODE (body) == ADDR_VEC)
16991 return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, 0);
16992 else if (GET_CODE (body) == ADDR_DIFF_VEC)
16993 return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, 1);
16994 else
16995 gcc_unreachable ();
16997 return get_attr_length (insn);
17000 /* If *X is a symbolic constant that refers to the constant pool, add
17001 the constant to POOL and rewrite *X to use the constant's label. */
17003 static void
17004 mips16_rewrite_pool_constant (struct mips16_constant_pool *pool, rtx *x)
17006 rtx base, offset, label;
17008 split_const (*x, &base, &offset);
17009 if (GET_CODE (base) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (base))
17011 label = mips16_add_constant (pool, copy_rtx (get_pool_constant (base)),
17012 get_pool_mode (base));
17013 base = gen_rtx_LABEL_REF (Pmode, label);
17014 *x = mips_unspec_address_offset (base, offset, SYMBOL_PC_RELATIVE);
17018 /* This structure is used to communicate with mips16_rewrite_pool_refs.
17019 INSN is the instruction we're rewriting and POOL points to the current
17020 constant pool. */
17021 struct mips16_rewrite_pool_refs_info {
17022 rtx insn;
17023 struct mips16_constant_pool *pool;
17026 /* Rewrite *X so that constant pool references refer to the constant's
17027 label instead. DATA points to a mips16_rewrite_pool_refs_info
17028 structure. */
17030 static int
17031 mips16_rewrite_pool_refs (rtx *x, void *data)
17033 struct mips16_rewrite_pool_refs_info *info =
17034 (struct mips16_rewrite_pool_refs_info *) data;
17036 if (force_to_mem_operand (*x, Pmode))
17038 rtx mem = force_const_mem (GET_MODE (*x), *x);
17039 validate_change (info->insn, x, mem, false);
17042 if (MEM_P (*x))
17044 mips16_rewrite_pool_constant (info->pool, &XEXP (*x, 0));
17045 return -1;
17048 /* Don't rewrite the __mips16_rdwr symbol. */
17049 if (GET_CODE (*x) == UNSPEC && XINT (*x, 1) == UNSPEC_TLS_GET_TP)
17050 return -1;
17052 if (TARGET_MIPS16_TEXT_LOADS)
17053 mips16_rewrite_pool_constant (info->pool, x);
17055 return GET_CODE (*x) == CONST ? -1 : 0;
17058 /* Return whether CFG is used in mips_reorg. */
17060 static bool
17061 mips_cfg_in_reorg (void)
17063 return (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE
17064 || TARGET_RELAX_PIC_CALLS);
17067 /* Build MIPS16 constant pools. Split the instructions if SPLIT_P,
17068 otherwise assume that they are already split. */
17070 static void
17071 mips16_lay_out_constants (bool split_p)
17073 struct mips16_constant_pool pool;
17074 struct mips16_rewrite_pool_refs_info info;
17075 rtx insn, barrier;
17077 if (!TARGET_MIPS16_PCREL_LOADS)
17078 return;
17080 if (split_p)
17082 if (mips_cfg_in_reorg ())
17083 split_all_insns ();
17084 else
17085 split_all_insns_noflow ();
17087 barrier = 0;
17088 memset (&pool, 0, sizeof (pool));
17089 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
17091 /* Rewrite constant pool references in INSN. */
17092 if (USEFUL_INSN_P (insn))
17094 info.insn = insn;
17095 info.pool = &pool;
17096 for_each_rtx (&PATTERN (insn), mips16_rewrite_pool_refs, &info);
17099 pool.insn_address += mips16_insn_length (insn);
17101 if (pool.first != NULL)
17103 /* If there are no natural barriers between the first user of
17104 the pool and the highest acceptable address, we'll need to
17105 create a new instruction to jump around the constant pool.
17106 In the worst case, this instruction will be 4 bytes long.
17108 If it's too late to do this transformation after INSN,
17109 do it immediately before INSN. */
17110 if (barrier == 0 && pool.insn_address + 4 > pool.highest_address)
17112 rtx label, jump;
17114 label = gen_label_rtx ();
17116 jump = emit_jump_insn_before (gen_jump (label), insn);
17117 JUMP_LABEL (jump) = label;
17118 LABEL_NUSES (label) = 1;
17119 barrier = emit_barrier_after (jump);
17121 emit_label_after (label, barrier);
17122 pool.insn_address += 4;
17125 /* See whether the constant pool is now out of range of the first
17126 user. If so, output the constants after the previous barrier.
17127 Note that any instructions between BARRIER and INSN (inclusive)
17128 will use negative offsets to refer to the pool. */
17129 if (pool.insn_address > pool.highest_address)
17131 mips16_emit_constants (pool.first, barrier);
17132 pool.first = NULL;
17133 barrier = 0;
17135 else if (BARRIER_P (insn))
17136 barrier = insn;
17139 mips16_emit_constants (pool.first, get_last_insn ());
17142 /* Return true if it is worth r10k_simplify_address's while replacing
17143 an address with X. We are looking for constants, and for addresses
17144 at a known offset from the incoming stack pointer. */
17146 static bool
17147 r10k_simplified_address_p (rtx x)
17149 if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1)))
17150 x = XEXP (x, 0);
17151 return x == virtual_incoming_args_rtx || CONSTANT_P (x);
17154 /* X is an expression that appears in INSN. Try to use the UD chains
17155 to simplify it, returning the simplified form on success and the
17156 original form otherwise. Replace the incoming value of $sp with
17157 virtual_incoming_args_rtx (which should never occur in X otherwise). */
17159 static rtx
17160 r10k_simplify_address (rtx x, rtx insn)
17162 rtx newx, op0, op1, set, def_insn, note;
17163 df_ref use, def;
17164 struct df_link *defs;
17166 newx = NULL_RTX;
17167 if (UNARY_P (x))
17169 op0 = r10k_simplify_address (XEXP (x, 0), insn);
17170 if (op0 != XEXP (x, 0))
17171 newx = simplify_gen_unary (GET_CODE (x), GET_MODE (x),
17172 op0, GET_MODE (XEXP (x, 0)));
17174 else if (BINARY_P (x))
17176 op0 = r10k_simplify_address (XEXP (x, 0), insn);
17177 op1 = r10k_simplify_address (XEXP (x, 1), insn);
17178 if (op0 != XEXP (x, 0) || op1 != XEXP (x, 1))
17179 newx = simplify_gen_binary (GET_CODE (x), GET_MODE (x), op0, op1);
17181 else if (GET_CODE (x) == LO_SUM)
17183 /* LO_SUMs can be offset from HIGHs, if we know they won't
17184 overflow. See mips_classify_address for the rationale behind
17185 the lax check. */
17186 op0 = r10k_simplify_address (XEXP (x, 0), insn);
17187 if (GET_CODE (op0) == HIGH)
17188 newx = XEXP (x, 1);
17190 else if (REG_P (x))
17192 /* Uses are recorded by regno_reg_rtx, not X itself. */
17193 use = df_find_use (insn, regno_reg_rtx[REGNO (x)]);
17194 gcc_assert (use);
17195 defs = DF_REF_CHAIN (use);
17197 /* Require a single definition. */
17198 if (defs && defs->next == NULL)
17200 def = defs->ref;
17201 if (DF_REF_IS_ARTIFICIAL (def))
17203 /* Replace the incoming value of $sp with
17204 virtual_incoming_args_rtx. */
17205 if (x == stack_pointer_rtx
17206 && DF_REF_BB (def) == ENTRY_BLOCK_PTR_FOR_FN (cfun))
17207 newx = virtual_incoming_args_rtx;
17209 else if (dominated_by_p (CDI_DOMINATORS, DF_REF_BB (use),
17210 DF_REF_BB (def)))
17212 /* Make sure that DEF_INSN is a single set of REG. */
17213 def_insn = DF_REF_INSN (def);
17214 if (NONJUMP_INSN_P (def_insn))
17216 set = single_set (def_insn);
17217 if (set && rtx_equal_p (SET_DEST (set), x))
17219 /* Prefer to use notes, since the def-use chains
17220 are often shorter. */
17221 note = find_reg_equal_equiv_note (def_insn);
17222 if (note)
17223 newx = XEXP (note, 0);
17224 else
17225 newx = SET_SRC (set);
17226 newx = r10k_simplify_address (newx, def_insn);
17232 if (newx && r10k_simplified_address_p (newx))
17233 return newx;
17234 return x;
17237 /* Return true if ADDRESS is known to be an uncached address
17238 on R10K systems. */
17240 static bool
17241 r10k_uncached_address_p (unsigned HOST_WIDE_INT address)
17243 unsigned HOST_WIDE_INT upper;
17245 /* Check for KSEG1. */
17246 if (address + 0x60000000 < 0x20000000)
17247 return true;
17249 /* Check for uncached XKPHYS addresses. */
17250 if (Pmode == DImode)
17252 upper = (address >> 40) & 0xf9ffff;
17253 if (upper == 0x900000 || upper == 0xb80000)
17254 return true;
17256 return false;
17259 /* Return true if we can prove that an access to address X in instruction
17260 INSN would be safe from R10K speculation. This X is a general
17261 expression; it might not be a legitimate address. */
17263 static bool
17264 r10k_safe_address_p (rtx x, rtx insn)
17266 rtx base, offset;
17267 HOST_WIDE_INT offset_val;
17269 x = r10k_simplify_address (x, insn);
17271 /* Check for references to the stack frame. It doesn't really matter
17272 how much of the frame has been allocated at INSN; -mr10k-cache-barrier
17273 allows us to assume that accesses to any part of the eventual frame
17274 is safe from speculation at any point in the function. */
17275 mips_split_plus (x, &base, &offset_val);
17276 if (base == virtual_incoming_args_rtx
17277 && offset_val >= -cfun->machine->frame.total_size
17278 && offset_val < cfun->machine->frame.args_size)
17279 return true;
17281 /* Check for uncached addresses. */
17282 if (CONST_INT_P (x))
17283 return r10k_uncached_address_p (INTVAL (x));
17285 /* Check for accesses to a static object. */
17286 split_const (x, &base, &offset);
17287 return offset_within_block_p (base, INTVAL (offset));
17290 /* Return true if a MEM with MEM_EXPR EXPR and MEM_OFFSET OFFSET is
17291 an in-range access to an automatic variable, or to an object with
17292 a link-time-constant address. */
17294 static bool
17295 r10k_safe_mem_expr_p (tree expr, unsigned HOST_WIDE_INT offset)
17297 HOST_WIDE_INT bitoffset, bitsize;
17298 tree inner, var_offset;
17299 machine_mode mode;
17300 int unsigned_p, volatile_p;
17302 inner = get_inner_reference (expr, &bitsize, &bitoffset, &var_offset, &mode,
17303 &unsigned_p, &volatile_p, false);
17304 if (!DECL_P (inner) || !DECL_SIZE_UNIT (inner) || var_offset)
17305 return false;
17307 offset += bitoffset / BITS_PER_UNIT;
17308 return offset < tree_to_uhwi (DECL_SIZE_UNIT (inner));
17311 /* A for_each_rtx callback for which DATA points to the instruction
17312 containing *X. Stop the search if we find a MEM that is not safe
17313 from R10K speculation. */
17315 static int
17316 r10k_needs_protection_p_1 (rtx *loc, void *data)
17318 rtx mem;
17320 mem = *loc;
17321 if (!MEM_P (mem))
17322 return 0;
17324 if (MEM_EXPR (mem)
17325 && MEM_OFFSET_KNOWN_P (mem)
17326 && r10k_safe_mem_expr_p (MEM_EXPR (mem), MEM_OFFSET (mem)))
17327 return -1;
17329 if (r10k_safe_address_p (XEXP (mem, 0), (rtx) data))
17330 return -1;
17332 return 1;
17335 /* A note_stores callback for which DATA points to an instruction pointer.
17336 If *DATA is nonnull, make it null if it X contains a MEM that is not
17337 safe from R10K speculation. */
17339 static void
17340 r10k_needs_protection_p_store (rtx x, const_rtx pat ATTRIBUTE_UNUSED,
17341 void *data)
17343 rtx *insn_ptr;
17345 insn_ptr = (rtx *) data;
17346 if (*insn_ptr && for_each_rtx (&x, r10k_needs_protection_p_1, *insn_ptr))
17347 *insn_ptr = NULL_RTX;
17350 /* A for_each_rtx callback that iterates over the pattern of a CALL_INSN.
17351 Return nonzero if the call is not to a declared function. */
17353 static int
17354 r10k_needs_protection_p_call (rtx *loc, void *data ATTRIBUTE_UNUSED)
17356 rtx x;
17358 x = *loc;
17359 if (!MEM_P (x))
17360 return 0;
17362 x = XEXP (x, 0);
17363 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_DECL (x))
17364 return -1;
17366 return 1;
17369 /* Return true if instruction INSN needs to be protected by an R10K
17370 cache barrier. */
17372 static bool
17373 r10k_needs_protection_p (rtx insn)
17375 if (CALL_P (insn))
17376 return for_each_rtx (&PATTERN (insn), r10k_needs_protection_p_call, NULL);
17378 if (mips_r10k_cache_barrier == R10K_CACHE_BARRIER_STORE)
17380 note_stores (PATTERN (insn), r10k_needs_protection_p_store, &insn);
17381 return insn == NULL_RTX;
17384 return for_each_rtx (&PATTERN (insn), r10k_needs_protection_p_1, insn);
17387 /* Return true if BB is only reached by blocks in PROTECTED_BBS and if every
17388 edge is unconditional. */
17390 static bool
17391 r10k_protected_bb_p (basic_block bb, sbitmap protected_bbs)
17393 edge_iterator ei;
17394 edge e;
17396 FOR_EACH_EDGE (e, ei, bb->preds)
17397 if (!single_succ_p (e->src)
17398 || !bitmap_bit_p (protected_bbs, e->src->index)
17399 || (e->flags & EDGE_COMPLEX) != 0)
17400 return false;
17401 return true;
17404 /* Implement -mr10k-cache-barrier= for the current function. */
17406 static void
17407 r10k_insert_cache_barriers (void)
17409 int *rev_post_order;
17410 unsigned int i, n;
17411 basic_block bb;
17412 sbitmap protected_bbs;
17413 rtx insn, end, unprotected_region;
17415 if (TARGET_MIPS16)
17417 sorry ("%qs does not support MIPS16 code", "-mr10k-cache-barrier");
17418 return;
17421 /* Calculate dominators. */
17422 calculate_dominance_info (CDI_DOMINATORS);
17424 /* Bit X of PROTECTED_BBS is set if the last operation in basic block
17425 X is protected by a cache barrier. */
17426 protected_bbs = sbitmap_alloc (last_basic_block_for_fn (cfun));
17427 bitmap_clear (protected_bbs);
17429 /* Iterate over the basic blocks in reverse post-order. */
17430 rev_post_order = XNEWVEC (int, last_basic_block_for_fn (cfun));
17431 n = pre_and_rev_post_order_compute (NULL, rev_post_order, false);
17432 for (i = 0; i < n; i++)
17434 bb = BASIC_BLOCK_FOR_FN (cfun, rev_post_order[i]);
17436 /* If this block is only reached by unconditional edges, and if the
17437 source of every edge is protected, the beginning of the block is
17438 also protected. */
17439 if (r10k_protected_bb_p (bb, protected_bbs))
17440 unprotected_region = NULL_RTX;
17441 else
17442 unprotected_region = pc_rtx;
17443 end = NEXT_INSN (BB_END (bb));
17445 /* UNPROTECTED_REGION is:
17447 - null if we are processing a protected region,
17448 - pc_rtx if we are processing an unprotected region but have
17449 not yet found the first instruction in it
17450 - the first instruction in an unprotected region otherwise. */
17451 for (insn = BB_HEAD (bb); insn != end; insn = NEXT_INSN (insn))
17453 if (unprotected_region && USEFUL_INSN_P (insn))
17455 if (recog_memoized (insn) == CODE_FOR_mips_cache)
17456 /* This CACHE instruction protects the following code. */
17457 unprotected_region = NULL_RTX;
17458 else
17460 /* See if INSN is the first instruction in this
17461 unprotected region. */
17462 if (unprotected_region == pc_rtx)
17463 unprotected_region = insn;
17465 /* See if INSN needs to be protected. If so,
17466 we must insert a cache barrier somewhere between
17467 PREV_INSN (UNPROTECTED_REGION) and INSN. It isn't
17468 clear which position is better performance-wise,
17469 but as a tie-breaker, we assume that it is better
17470 to allow delay slots to be back-filled where
17471 possible, and that it is better not to insert
17472 barriers in the middle of already-scheduled code.
17473 We therefore insert the barrier at the beginning
17474 of the region. */
17475 if (r10k_needs_protection_p (insn))
17477 emit_insn_before (gen_r10k_cache_barrier (),
17478 unprotected_region);
17479 unprotected_region = NULL_RTX;
17484 if (CALL_P (insn))
17485 /* The called function is not required to protect the exit path.
17486 The code that follows a call is therefore unprotected. */
17487 unprotected_region = pc_rtx;
17490 /* Record whether the end of this block is protected. */
17491 if (unprotected_region == NULL_RTX)
17492 bitmap_set_bit (protected_bbs, bb->index);
17494 XDELETEVEC (rev_post_order);
17496 sbitmap_free (protected_bbs);
17498 free_dominance_info (CDI_DOMINATORS);
17501 /* If INSN is a call, return the underlying CALL expr. Return NULL_RTX
17502 otherwise. If INSN has two call rtx, then store the second one in
17503 SECOND_CALL. */
17505 static rtx
17506 mips_call_expr_from_insn (rtx insn, rtx *second_call)
17508 rtx x;
17509 rtx x2;
17511 if (!CALL_P (insn))
17512 return NULL_RTX;
17514 x = PATTERN (insn);
17515 if (GET_CODE (x) == PARALLEL)
17517 /* Calls returning complex values have two CALL rtx. Look for the second
17518 one here, and return it via the SECOND_CALL arg. */
17519 x2 = XVECEXP (x, 0, 1);
17520 if (GET_CODE (x2) == SET)
17521 x2 = XEXP (x2, 1);
17522 if (GET_CODE (x2) == CALL)
17523 *second_call = x2;
17525 x = XVECEXP (x, 0, 0);
17527 if (GET_CODE (x) == SET)
17528 x = XEXP (x, 1);
17529 gcc_assert (GET_CODE (x) == CALL);
17531 return x;
17534 /* REG is set in DEF. See if the definition is one of the ways we load a
17535 register with a symbol address for a mips_use_pic_fn_addr_reg_p call.
17536 If it is, return the symbol reference of the function, otherwise return
17537 NULL_RTX.
17539 If RECURSE_P is true, use mips_find_pic_call_symbol to interpret
17540 the values of source registers, otherwise treat such registers as
17541 having an unknown value. */
17543 static rtx
17544 mips_pic_call_symbol_from_set (df_ref def, rtx reg, bool recurse_p)
17546 rtx def_insn, set;
17548 if (DF_REF_IS_ARTIFICIAL (def))
17549 return NULL_RTX;
17551 def_insn = DF_REF_INSN (def);
17552 set = single_set (def_insn);
17553 if (set && rtx_equal_p (SET_DEST (set), reg))
17555 rtx note, src, symbol;
17557 /* First see whether the source is a plain symbol. This is used
17558 when calling symbols that are not lazily bound. */
17559 src = SET_SRC (set);
17560 if (GET_CODE (src) == SYMBOL_REF)
17561 return src;
17563 /* Handle %call16 references. */
17564 symbol = mips_strip_unspec_call (src);
17565 if (symbol)
17567 gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
17568 return symbol;
17571 /* If we have something more complicated, look for a
17572 REG_EQUAL or REG_EQUIV note. */
17573 note = find_reg_equal_equiv_note (def_insn);
17574 if (note && GET_CODE (XEXP (note, 0)) == SYMBOL_REF)
17575 return XEXP (note, 0);
17577 /* Follow at most one simple register copy. Such copies are
17578 interesting in cases like:
17580 for (...)
17582 locally_binding_fn (...);
17585 and:
17587 locally_binding_fn (...);
17589 locally_binding_fn (...);
17591 where the load of locally_binding_fn can legitimately be
17592 hoisted or shared. However, we do not expect to see complex
17593 chains of copies, so a full worklist solution to the problem
17594 would probably be overkill. */
17595 if (recurse_p && REG_P (src))
17596 return mips_find_pic_call_symbol (def_insn, src, false);
17599 return NULL_RTX;
17602 /* Find the definition of the use of REG in INSN. See if the definition
17603 is one of the ways we load a register with a symbol address for a
17604 mips_use_pic_fn_addr_reg_p call. If it is return the symbol reference
17605 of the function, otherwise return NULL_RTX. RECURSE_P is as for
17606 mips_pic_call_symbol_from_set. */
17608 static rtx
17609 mips_find_pic_call_symbol (rtx insn, rtx reg, bool recurse_p)
17611 df_ref use;
17612 struct df_link *defs;
17613 rtx symbol;
17615 use = df_find_use (insn, regno_reg_rtx[REGNO (reg)]);
17616 if (!use)
17617 return NULL_RTX;
17618 defs = DF_REF_CHAIN (use);
17619 if (!defs)
17620 return NULL_RTX;
17621 symbol = mips_pic_call_symbol_from_set (defs->ref, reg, recurse_p);
17622 if (!symbol)
17623 return NULL_RTX;
17625 /* If we have more than one definition, they need to be identical. */
17626 for (defs = defs->next; defs; defs = defs->next)
17628 rtx other;
17630 other = mips_pic_call_symbol_from_set (defs->ref, reg, recurse_p);
17631 if (!rtx_equal_p (symbol, other))
17632 return NULL_RTX;
17635 return symbol;
17638 /* Replace the args_size operand of the call expression CALL with the
17639 call-attribute UNSPEC and fill in SYMBOL as the function symbol. */
17641 static void
17642 mips_annotate_pic_call_expr (rtx call, rtx symbol)
17644 rtx args_size;
17646 args_size = XEXP (call, 1);
17647 XEXP (call, 1) = gen_rtx_UNSPEC (GET_MODE (args_size),
17648 gen_rtvec (2, args_size, symbol),
17649 UNSPEC_CALL_ATTR);
17652 /* OPERANDS[ARGS_SIZE_OPNO] is the arg_size operand of a CALL expression. See
17653 if instead of the arg_size argument it contains the call attributes. If
17654 yes return true along with setting OPERANDS[ARGS_SIZE_OPNO] to the function
17655 symbol from the call attributes. Also return false if ARGS_SIZE_OPNO is
17656 -1. */
17658 bool
17659 mips_get_pic_call_symbol (rtx *operands, int args_size_opno)
17661 rtx args_size, symbol;
17663 if (!TARGET_RELAX_PIC_CALLS || args_size_opno == -1)
17664 return false;
17666 args_size = operands[args_size_opno];
17667 if (GET_CODE (args_size) != UNSPEC)
17668 return false;
17669 gcc_assert (XINT (args_size, 1) == UNSPEC_CALL_ATTR);
17671 symbol = XVECEXP (args_size, 0, 1);
17672 gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
17674 operands[args_size_opno] = symbol;
17675 return true;
17678 /* Use DF to annotate PIC indirect calls with the function symbol they
17679 dispatch to. */
17681 static void
17682 mips_annotate_pic_calls (void)
17684 basic_block bb;
17685 rtx insn;
17687 FOR_EACH_BB_FN (bb, cfun)
17688 FOR_BB_INSNS (bb, insn)
17690 rtx call, reg, symbol, second_call;
17692 second_call = 0;
17693 call = mips_call_expr_from_insn (insn, &second_call);
17694 if (!call)
17695 continue;
17696 gcc_assert (MEM_P (XEXP (call, 0)));
17697 reg = XEXP (XEXP (call, 0), 0);
17698 if (!REG_P (reg))
17699 continue;
17701 symbol = mips_find_pic_call_symbol (insn, reg, true);
17702 if (symbol)
17704 mips_annotate_pic_call_expr (call, symbol);
17705 if (second_call)
17706 mips_annotate_pic_call_expr (second_call, symbol);
17711 /* A temporary variable used by for_each_rtx callbacks, etc. */
17712 static rtx mips_sim_insn;
17714 /* A structure representing the state of the processor pipeline.
17715 Used by the mips_sim_* family of functions. */
17716 struct mips_sim {
17717 /* The maximum number of instructions that can be issued in a cycle.
17718 (Caches mips_issue_rate.) */
17719 unsigned int issue_rate;
17721 /* The current simulation time. */
17722 unsigned int time;
17724 /* How many more instructions can be issued in the current cycle. */
17725 unsigned int insns_left;
17727 /* LAST_SET[X].INSN is the last instruction to set register X.
17728 LAST_SET[X].TIME is the time at which that instruction was issued.
17729 INSN is null if no instruction has yet set register X. */
17730 struct {
17731 rtx insn;
17732 unsigned int time;
17733 } last_set[FIRST_PSEUDO_REGISTER];
17735 /* The pipeline's current DFA state. */
17736 state_t dfa_state;
17739 /* Reset STATE to the initial simulation state. */
17741 static void
17742 mips_sim_reset (struct mips_sim *state)
17744 curr_state = state->dfa_state;
17746 state->time = 0;
17747 state->insns_left = state->issue_rate;
17748 memset (&state->last_set, 0, sizeof (state->last_set));
17749 state_reset (curr_state);
17751 targetm.sched.init (0, false, 0);
17752 advance_state (curr_state);
17755 /* Initialize STATE before its first use. DFA_STATE points to an
17756 allocated but uninitialized DFA state. */
17758 static void
17759 mips_sim_init (struct mips_sim *state, state_t dfa_state)
17761 if (targetm.sched.init_dfa_pre_cycle_insn)
17762 targetm.sched.init_dfa_pre_cycle_insn ();
17764 if (targetm.sched.init_dfa_post_cycle_insn)
17765 targetm.sched.init_dfa_post_cycle_insn ();
17767 state->issue_rate = mips_issue_rate ();
17768 state->dfa_state = dfa_state;
17769 mips_sim_reset (state);
17772 /* Advance STATE by one clock cycle. */
17774 static void
17775 mips_sim_next_cycle (struct mips_sim *state)
17777 curr_state = state->dfa_state;
17779 state->time++;
17780 state->insns_left = state->issue_rate;
17781 advance_state (curr_state);
17784 /* Advance simulation state STATE until instruction INSN can read
17785 register REG. */
17787 static void
17788 mips_sim_wait_reg (struct mips_sim *state, rtx insn, rtx reg)
17790 unsigned int regno, end_regno;
17792 end_regno = END_REGNO (reg);
17793 for (regno = REGNO (reg); regno < end_regno; regno++)
17794 if (state->last_set[regno].insn != 0)
17796 unsigned int t;
17798 t = (state->last_set[regno].time
17799 + insn_latency (state->last_set[regno].insn, insn));
17800 while (state->time < t)
17801 mips_sim_next_cycle (state);
17805 /* A for_each_rtx callback. If *X is a register, advance simulation state
17806 DATA until mips_sim_insn can read the register's value. */
17808 static int
17809 mips_sim_wait_regs_2 (rtx *x, void *data)
17811 if (REG_P (*x))
17812 mips_sim_wait_reg ((struct mips_sim *) data, mips_sim_insn, *x);
17813 return 0;
17816 /* Call mips_sim_wait_regs_2 (R, DATA) for each register R mentioned in *X. */
17818 static void
17819 mips_sim_wait_regs_1 (rtx *x, void *data)
17821 for_each_rtx (x, mips_sim_wait_regs_2, data);
17824 /* Advance simulation state STATE until all of INSN's register
17825 dependencies are satisfied. */
17827 static void
17828 mips_sim_wait_regs (struct mips_sim *state, rtx insn)
17830 mips_sim_insn = insn;
17831 note_uses (&PATTERN (insn), mips_sim_wait_regs_1, state);
17834 /* Advance simulation state STATE until the units required by
17835 instruction INSN are available. */
17837 static void
17838 mips_sim_wait_units (struct mips_sim *state, rtx insn)
17840 state_t tmp_state;
17842 tmp_state = alloca (state_size ());
17843 while (state->insns_left == 0
17844 || (memcpy (tmp_state, state->dfa_state, state_size ()),
17845 state_transition (tmp_state, insn) >= 0))
17846 mips_sim_next_cycle (state);
17849 /* Advance simulation state STATE until INSN is ready to issue. */
17851 static void
17852 mips_sim_wait_insn (struct mips_sim *state, rtx insn)
17854 mips_sim_wait_regs (state, insn);
17855 mips_sim_wait_units (state, insn);
17858 /* mips_sim_insn has just set X. Update the LAST_SET array
17859 in simulation state DATA. */
17861 static void
17862 mips_sim_record_set (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data)
17864 struct mips_sim *state;
17866 state = (struct mips_sim *) data;
17867 if (REG_P (x))
17869 unsigned int regno, end_regno;
17871 end_regno = END_REGNO (x);
17872 for (regno = REGNO (x); regno < end_regno; regno++)
17874 state->last_set[regno].insn = mips_sim_insn;
17875 state->last_set[regno].time = state->time;
17880 /* Issue instruction INSN in scheduler state STATE. Assume that INSN
17881 can issue immediately (i.e., that mips_sim_wait_insn has already
17882 been called). */
17884 static void
17885 mips_sim_issue_insn (struct mips_sim *state, rtx insn)
17887 curr_state = state->dfa_state;
17889 state_transition (curr_state, insn);
17890 state->insns_left = targetm.sched.variable_issue (0, false, insn,
17891 state->insns_left);
17893 mips_sim_insn = insn;
17894 note_stores (PATTERN (insn), mips_sim_record_set, state);
17897 /* Simulate issuing a NOP in state STATE. */
17899 static void
17900 mips_sim_issue_nop (struct mips_sim *state)
17902 if (state->insns_left == 0)
17903 mips_sim_next_cycle (state);
17904 state->insns_left--;
17907 /* Update simulation state STATE so that it's ready to accept the instruction
17908 after INSN. INSN should be part of the main rtl chain, not a member of a
17909 SEQUENCE. */
17911 static void
17912 mips_sim_finish_insn (struct mips_sim *state, rtx insn)
17914 /* If INSN is a jump with an implicit delay slot, simulate a nop. */
17915 if (JUMP_P (insn))
17916 mips_sim_issue_nop (state);
17918 switch (GET_CODE (SEQ_BEGIN (insn)))
17920 case CODE_LABEL:
17921 case CALL_INSN:
17922 /* We can't predict the processor state after a call or label. */
17923 mips_sim_reset (state);
17924 break;
17926 case JUMP_INSN:
17927 /* The delay slots of branch likely instructions are only executed
17928 when the branch is taken. Therefore, if the caller has simulated
17929 the delay slot instruction, STATE does not really reflect the state
17930 of the pipeline for the instruction after the delay slot. Also,
17931 branch likely instructions tend to incur a penalty when not taken,
17932 so there will probably be an extra delay between the branch and
17933 the instruction after the delay slot. */
17934 if (INSN_ANNULLED_BRANCH_P (SEQ_BEGIN (insn)))
17935 mips_sim_reset (state);
17936 break;
17938 default:
17939 break;
17943 /* Use simulator state STATE to calculate the execution time of
17944 instruction sequence SEQ. */
17946 static unsigned int
17947 mips_seq_time (struct mips_sim *state, rtx seq)
17949 mips_sim_reset (state);
17950 for (rtx insn = seq; insn; insn = NEXT_INSN (insn))
17952 mips_sim_wait_insn (state, insn);
17953 mips_sim_issue_insn (state, insn);
17955 return state->time;
17958 /* Return the execution-time cost of mips_tuning_info.fast_mult_zero_zero_p
17959 setting SETTING, using STATE to simulate instruction sequences. */
17961 static unsigned int
17962 mips_mult_zero_zero_cost (struct mips_sim *state, bool setting)
17964 mips_tuning_info.fast_mult_zero_zero_p = setting;
17965 start_sequence ();
17967 machine_mode dword_mode = TARGET_64BIT ? TImode : DImode;
17968 rtx hilo = gen_rtx_REG (dword_mode, MD_REG_FIRST);
17969 mips_emit_move_or_split (hilo, const0_rtx, SPLIT_FOR_SPEED);
17971 /* If the target provides mulsidi3_32bit then that's the most likely
17972 consumer of the result. Test for bypasses. */
17973 if (dword_mode == DImode && HAVE_maddsidi4)
17975 rtx gpr = gen_rtx_REG (SImode, GP_REG_FIRST + 4);
17976 emit_insn (gen_maddsidi4 (hilo, gpr, gpr, hilo));
17979 unsigned int time = mips_seq_time (state, get_insns ());
17980 end_sequence ();
17981 return time;
17984 /* Check the relative speeds of "MULT $0,$0" and "MTLO $0; MTHI $0"
17985 and set up mips_tuning_info.fast_mult_zero_zero_p accordingly.
17986 Prefer MULT -- which is shorter -- in the event of a tie. */
17988 static void
17989 mips_set_fast_mult_zero_zero_p (struct mips_sim *state)
17991 if (TARGET_MIPS16 || (!ISA_HAS_HILO && !TARGET_DSP))
17992 /* No MTLO or MTHI available for MIPS16. Also, when there are no HI or LO
17993 registers then there is no reason to zero them, arbitrarily choose to
17994 say that "MULT $0,$0" would be faster. */
17995 mips_tuning_info.fast_mult_zero_zero_p = true;
17996 else
17998 unsigned int true_time = mips_mult_zero_zero_cost (state, true);
17999 unsigned int false_time = mips_mult_zero_zero_cost (state, false);
18000 mips_tuning_info.fast_mult_zero_zero_p = (true_time <= false_time);
18004 /* Set up costs based on the current architecture and tuning settings. */
18006 static void
18007 mips_set_tuning_info (void)
18009 if (mips_tuning_info.initialized_p
18010 && mips_tuning_info.arch == mips_arch
18011 && mips_tuning_info.tune == mips_tune
18012 && mips_tuning_info.mips16_p == TARGET_MIPS16)
18013 return;
18015 mips_tuning_info.arch = mips_arch;
18016 mips_tuning_info.tune = mips_tune;
18017 mips_tuning_info.mips16_p = TARGET_MIPS16;
18018 mips_tuning_info.initialized_p = true;
18020 dfa_start ();
18022 struct mips_sim state;
18023 mips_sim_init (&state, alloca (state_size ()));
18025 mips_set_fast_mult_zero_zero_p (&state);
18027 dfa_finish ();
18030 /* Implement TARGET_EXPAND_TO_RTL_HOOK. */
18032 static void
18033 mips_expand_to_rtl_hook (void)
18035 /* We need to call this at a point where we can safely create sequences
18036 of instructions, so TARGET_OVERRIDE_OPTIONS is too early. We also
18037 need to call it at a point where the DFA infrastructure is not
18038 already in use, so we can't just call it lazily on demand.
18040 At present, mips_tuning_info is only needed during post-expand
18041 RTL passes such as split_insns, so this hook should be early enough.
18042 We may need to move the call elsewhere if mips_tuning_info starts
18043 to be used for other things (such as rtx_costs, or expanders that
18044 could be called during gimple optimization). */
18045 mips_set_tuning_info ();
18048 /* The VR4130 pipeline issues aligned pairs of instructions together,
18049 but it stalls the second instruction if it depends on the first.
18050 In order to cut down the amount of logic required, this dependence
18051 check is not based on a full instruction decode. Instead, any non-SPECIAL
18052 instruction is assumed to modify the register specified by bits 20-16
18053 (which is usually the "rt" field).
18055 In BEQ, BEQL, BNE and BNEL instructions, the rt field is actually an
18056 input, so we can end up with a false dependence between the branch
18057 and its delay slot. If this situation occurs in instruction INSN,
18058 try to avoid it by swapping rs and rt. */
18060 static void
18061 vr4130_avoid_branch_rt_conflict (rtx insn)
18063 rtx first, second;
18065 first = SEQ_BEGIN (insn);
18066 second = SEQ_END (insn);
18067 if (JUMP_P (first)
18068 && NONJUMP_INSN_P (second)
18069 && GET_CODE (PATTERN (first)) == SET
18070 && GET_CODE (SET_DEST (PATTERN (first))) == PC
18071 && GET_CODE (SET_SRC (PATTERN (first))) == IF_THEN_ELSE)
18073 /* Check for the right kind of condition. */
18074 rtx cond = XEXP (SET_SRC (PATTERN (first)), 0);
18075 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE)
18076 && REG_P (XEXP (cond, 0))
18077 && REG_P (XEXP (cond, 1))
18078 && reg_referenced_p (XEXP (cond, 1), PATTERN (second))
18079 && !reg_referenced_p (XEXP (cond, 0), PATTERN (second)))
18081 /* SECOND mentions the rt register but not the rs register. */
18082 rtx tmp = XEXP (cond, 0);
18083 XEXP (cond, 0) = XEXP (cond, 1);
18084 XEXP (cond, 1) = tmp;
18089 /* Implement -mvr4130-align. Go through each basic block and simulate the
18090 processor pipeline. If we find that a pair of instructions could execute
18091 in parallel, and the first of those instructions is not 8-byte aligned,
18092 insert a nop to make it aligned. */
18094 static void
18095 vr4130_align_insns (void)
18097 struct mips_sim state;
18098 rtx insn, subinsn, last, last2, next;
18099 bool aligned_p;
18101 dfa_start ();
18103 /* LAST is the last instruction before INSN to have a nonzero length.
18104 LAST2 is the last such instruction before LAST. */
18105 last = 0;
18106 last2 = 0;
18108 /* ALIGNED_P is true if INSN is known to be at an aligned address. */
18109 aligned_p = true;
18111 mips_sim_init (&state, alloca (state_size ()));
18112 for (insn = get_insns (); insn != 0; insn = next)
18114 unsigned int length;
18116 next = NEXT_INSN (insn);
18118 /* See the comment above vr4130_avoid_branch_rt_conflict for details.
18119 This isn't really related to the alignment pass, but we do it on
18120 the fly to avoid a separate instruction walk. */
18121 vr4130_avoid_branch_rt_conflict (insn);
18123 length = get_attr_length (insn);
18124 if (length > 0 && USEFUL_INSN_P (insn))
18125 FOR_EACH_SUBINSN (subinsn, insn)
18127 mips_sim_wait_insn (&state, subinsn);
18129 /* If we want this instruction to issue in parallel with the
18130 previous one, make sure that the previous instruction is
18131 aligned. There are several reasons why this isn't worthwhile
18132 when the second instruction is a call:
18134 - Calls are less likely to be performance critical,
18135 - There's a good chance that the delay slot can execute
18136 in parallel with the call.
18137 - The return address would then be unaligned.
18139 In general, if we're going to insert a nop between instructions
18140 X and Y, it's better to insert it immediately after X. That
18141 way, if the nop makes Y aligned, it will also align any labels
18142 between X and Y. */
18143 if (state.insns_left != state.issue_rate
18144 && !CALL_P (subinsn))
18146 if (subinsn == SEQ_BEGIN (insn) && aligned_p)
18148 /* SUBINSN is the first instruction in INSN and INSN is
18149 aligned. We want to align the previous instruction
18150 instead, so insert a nop between LAST2 and LAST.
18152 Note that LAST could be either a single instruction
18153 or a branch with a delay slot. In the latter case,
18154 LAST, like INSN, is already aligned, but the delay
18155 slot must have some extra delay that stops it from
18156 issuing at the same time as the branch. We therefore
18157 insert a nop before the branch in order to align its
18158 delay slot. */
18159 gcc_assert (last2);
18160 emit_insn_after (gen_nop (), last2);
18161 aligned_p = false;
18163 else if (subinsn != SEQ_BEGIN (insn) && !aligned_p)
18165 /* SUBINSN is the delay slot of INSN, but INSN is
18166 currently unaligned. Insert a nop between
18167 LAST and INSN to align it. */
18168 gcc_assert (last);
18169 emit_insn_after (gen_nop (), last);
18170 aligned_p = true;
18173 mips_sim_issue_insn (&state, subinsn);
18175 mips_sim_finish_insn (&state, insn);
18177 /* Update LAST, LAST2 and ALIGNED_P for the next instruction. */
18178 length = get_attr_length (insn);
18179 if (length > 0)
18181 /* If the instruction is an asm statement or multi-instruction
18182 mips.md patern, the length is only an estimate. Insert an
18183 8 byte alignment after it so that the following instructions
18184 can be handled correctly. */
18185 if (NONJUMP_INSN_P (SEQ_BEGIN (insn))
18186 && (recog_memoized (insn) < 0 || length >= 8))
18188 next = emit_insn_after (gen_align (GEN_INT (3)), insn);
18189 next = NEXT_INSN (next);
18190 mips_sim_next_cycle (&state);
18191 aligned_p = true;
18193 else if (length & 4)
18194 aligned_p = !aligned_p;
18195 last2 = last;
18196 last = insn;
18199 /* See whether INSN is an aligned label. */
18200 if (LABEL_P (insn) && label_to_alignment (insn) >= 3)
18201 aligned_p = true;
18203 dfa_finish ();
18206 /* This structure records that the current function has a LO_SUM
18207 involving SYMBOL_REF or LABEL_REF BASE and that MAX_OFFSET is
18208 the largest offset applied to BASE by all such LO_SUMs. */
18209 struct mips_lo_sum_offset {
18210 rtx base;
18211 HOST_WIDE_INT offset;
18214 /* Return a hash value for SYMBOL_REF or LABEL_REF BASE. */
18216 static hashval_t
18217 mips_hash_base (rtx base)
18219 int do_not_record_p;
18221 return hash_rtx (base, GET_MODE (base), &do_not_record_p, NULL, false);
18224 /* Hashtable helpers. */
18226 struct mips_lo_sum_offset_hasher : typed_free_remove <mips_lo_sum_offset>
18228 typedef mips_lo_sum_offset value_type;
18229 typedef rtx_def compare_type;
18230 static inline hashval_t hash (const value_type *);
18231 static inline bool equal (const value_type *, const compare_type *);
18234 /* Hash-table callbacks for mips_lo_sum_offsets. */
18236 inline hashval_t
18237 mips_lo_sum_offset_hasher::hash (const value_type *entry)
18239 return mips_hash_base (entry->base);
18242 inline bool
18243 mips_lo_sum_offset_hasher::equal (const value_type *entry,
18244 const compare_type *value)
18246 return rtx_equal_p (entry->base, value);
18249 typedef hash_table <mips_lo_sum_offset_hasher> mips_offset_table;
18251 /* Look up symbolic constant X in HTAB, which is a hash table of
18252 mips_lo_sum_offsets. If OPTION is NO_INSERT, return true if X can be
18253 paired with a recorded LO_SUM, otherwise record X in the table. */
18255 static bool
18256 mips_lo_sum_offset_lookup (mips_offset_table htab, rtx x,
18257 enum insert_option option)
18259 rtx base, offset;
18260 mips_lo_sum_offset **slot;
18261 struct mips_lo_sum_offset *entry;
18263 /* Split X into a base and offset. */
18264 split_const (x, &base, &offset);
18265 if (UNSPEC_ADDRESS_P (base))
18266 base = UNSPEC_ADDRESS (base);
18268 /* Look up the base in the hash table. */
18269 slot = htab.find_slot_with_hash (base, mips_hash_base (base), option);
18270 if (slot == NULL)
18271 return false;
18273 entry = (struct mips_lo_sum_offset *) *slot;
18274 if (option == INSERT)
18276 if (entry == NULL)
18278 entry = XNEW (struct mips_lo_sum_offset);
18279 entry->base = base;
18280 entry->offset = INTVAL (offset);
18281 *slot = entry;
18283 else
18285 if (INTVAL (offset) > entry->offset)
18286 entry->offset = INTVAL (offset);
18289 return INTVAL (offset) <= entry->offset;
18292 /* A for_each_rtx callback for which DATA is a mips_lo_sum_offset hash table.
18293 Record every LO_SUM in *LOC. */
18295 static int
18296 mips_record_lo_sum (rtx *loc, void *data)
18298 if (GET_CODE (*loc) == LO_SUM)
18299 mips_lo_sum_offset_lookup (*(mips_offset_table*) data,
18300 XEXP (*loc, 1), INSERT);
18301 return 0;
18304 /* Return true if INSN is a SET of an orphaned high-part relocation.
18305 HTAB is a hash table of mips_lo_sum_offsets that describes all the
18306 LO_SUMs in the current function. */
18308 static bool
18309 mips_orphaned_high_part_p (mips_offset_table htab, rtx insn)
18311 enum mips_symbol_type type;
18312 rtx x, set;
18314 set = single_set (insn);
18315 if (set)
18317 /* Check for %his. */
18318 x = SET_SRC (set);
18319 if (GET_CODE (x) == HIGH
18320 && absolute_symbolic_operand (XEXP (x, 0), VOIDmode))
18321 return !mips_lo_sum_offset_lookup (htab, XEXP (x, 0), NO_INSERT);
18323 /* Check for local %gots (and %got_pages, which is redundant but OK). */
18324 if (GET_CODE (x) == UNSPEC
18325 && XINT (x, 1) == UNSPEC_LOAD_GOT
18326 && mips_symbolic_constant_p (XVECEXP (x, 0, 1),
18327 SYMBOL_CONTEXT_LEA, &type)
18328 && type == SYMBOL_GOTOFF_PAGE)
18329 return !mips_lo_sum_offset_lookup (htab, XVECEXP (x, 0, 1), NO_INSERT);
18331 return false;
18334 /* Subroutine of mips_reorg_process_insns. If there is a hazard between
18335 INSN and a previous instruction, avoid it by inserting nops after
18336 instruction AFTER.
18338 *DELAYED_REG and *HILO_DELAY describe the hazards that apply at
18339 this point. If *DELAYED_REG is non-null, INSN must wait a cycle
18340 before using the value of that register. *HILO_DELAY counts the
18341 number of instructions since the last hilo hazard (that is,
18342 the number of instructions since the last MFLO or MFHI).
18344 After inserting nops for INSN, update *DELAYED_REG and *HILO_DELAY
18345 for the next instruction.
18347 LO_REG is an rtx for the LO register, used in dependence checking. */
18349 static void
18350 mips_avoid_hazard (rtx after, rtx insn, int *hilo_delay,
18351 rtx *delayed_reg, rtx lo_reg, bool *fs_delay)
18353 rtx pattern, set;
18354 int nops, ninsns;
18356 pattern = PATTERN (insn);
18358 /* Do not put the whole function in .set noreorder if it contains
18359 an asm statement. We don't know whether there will be hazards
18360 between the asm statement and the gcc-generated code. */
18361 if (GET_CODE (pattern) == ASM_INPUT || asm_noperands (pattern) >= 0)
18362 cfun->machine->all_noreorder_p = false;
18364 /* Ignore zero-length instructions (barriers and the like). */
18365 ninsns = get_attr_length (insn) / 4;
18366 if (ninsns == 0)
18367 return;
18369 /* Work out how many nops are needed. Note that we only care about
18370 registers that are explicitly mentioned in the instruction's pattern.
18371 It doesn't matter that calls use the argument registers or that they
18372 clobber hi and lo. */
18373 if (*hilo_delay < 2 && reg_set_p (lo_reg, pattern))
18374 nops = 2 - *hilo_delay;
18375 else if (*delayed_reg != 0 && reg_referenced_p (*delayed_reg, pattern))
18376 nops = 1;
18377 /* If processing a forbidden slot hazard then a NOP is required if the
18378 branch instruction was not in a sequence (as the sequence would
18379 imply it is not actually a compact branch anyway) and the current
18380 insn is not an inline asm, and can't go in a delay slot. */
18381 else if (*fs_delay && get_attr_can_delay (insn) == CAN_DELAY_NO
18382 && GET_CODE (PATTERN (after)) != SEQUENCE
18383 && GET_CODE (pattern) != ASM_INPUT
18384 && asm_noperands (pattern) < 0)
18385 nops = 1;
18386 else
18387 nops = 0;
18389 /* Insert the nops between this instruction and the previous one.
18390 Each new nop takes us further from the last hilo hazard. */
18391 *hilo_delay += nops;
18392 while (nops-- > 0)
18393 emit_insn_after (gen_hazard_nop (), after);
18395 /* Set up the state for the next instruction. */
18396 *hilo_delay += ninsns;
18397 *delayed_reg = 0;
18398 *fs_delay = false;
18399 if (INSN_CODE (insn) >= 0)
18400 switch (get_attr_hazard (insn))
18402 case HAZARD_NONE:
18403 break;
18405 case HAZARD_FORBIDDEN_SLOT:
18406 if (TARGET_CB_MAYBE)
18407 *fs_delay = true;
18408 break;
18410 case HAZARD_HILO:
18411 *hilo_delay = 0;
18412 break;
18414 case HAZARD_DELAY:
18415 set = single_set (insn);
18416 gcc_assert (set);
18417 *delayed_reg = SET_DEST (set);
18418 break;
18422 /* Go through the instruction stream and insert nops where necessary.
18423 Also delete any high-part relocations whose partnering low parts
18424 are now all dead. See if the whole function can then be put into
18425 .set noreorder and .set nomacro. */
18427 static void
18428 mips_reorg_process_insns (void)
18430 rtx insn, last_insn, subinsn, next_insn, lo_reg, delayed_reg;
18431 int hilo_delay;
18432 mips_offset_table htab;
18433 bool fs_delay;
18435 /* Force all instructions to be split into their final form. */
18436 split_all_insns_noflow ();
18438 /* Recalculate instruction lengths without taking nops into account. */
18439 cfun->machine->ignore_hazard_length_p = true;
18440 shorten_branches (get_insns ());
18442 cfun->machine->all_noreorder_p = true;
18444 /* We don't track MIPS16 PC-relative offsets closely enough to make
18445 a good job of "set .noreorder" code in MIPS16 mode. */
18446 if (TARGET_MIPS16)
18447 cfun->machine->all_noreorder_p = false;
18449 /* Code that doesn't use explicit relocs can't be ".set nomacro". */
18450 if (!TARGET_EXPLICIT_RELOCS)
18451 cfun->machine->all_noreorder_p = false;
18453 /* Profiled functions can't be all noreorder because the profiler
18454 support uses assembler macros. */
18455 if (crtl->profile)
18456 cfun->machine->all_noreorder_p = false;
18458 /* Code compiled with -mfix-vr4120, -mfix-rm7000 or -mfix-24k can't be
18459 all noreorder because we rely on the assembler to work around some
18460 errata. The R5900 too has several bugs. */
18461 if (TARGET_FIX_VR4120
18462 || TARGET_FIX_RM7000
18463 || TARGET_FIX_24K
18464 || TARGET_MIPS5900)
18465 cfun->machine->all_noreorder_p = false;
18467 /* The same is true for -mfix-vr4130 if we might generate MFLO or
18468 MFHI instructions. Note that we avoid using MFLO and MFHI if
18469 the VR4130 MACC and DMACC instructions are available instead;
18470 see the *mfhilo_{si,di}_macc patterns. */
18471 if (TARGET_FIX_VR4130 && !ISA_HAS_MACCHI)
18472 cfun->machine->all_noreorder_p = false;
18474 htab.create (37);
18476 /* Make a first pass over the instructions, recording all the LO_SUMs. */
18477 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
18478 FOR_EACH_SUBINSN (subinsn, insn)
18479 if (USEFUL_INSN_P (subinsn))
18481 rtx body = PATTERN (insn);
18482 int noperands = asm_noperands (body);
18483 if (noperands >= 0)
18485 rtx *ops = XALLOCAVEC (rtx, noperands);
18486 bool *used = XALLOCAVEC (bool, noperands);
18487 const char *string = decode_asm_operands (body, ops, NULL, NULL,
18488 NULL, NULL);
18489 get_referenced_operands (string, used, noperands);
18490 for (int i = 0; i < noperands; ++i)
18491 if (used[i])
18492 for_each_rtx (&ops[i], mips_record_lo_sum, &htab);
18494 else
18495 for_each_rtx (&PATTERN (subinsn), mips_record_lo_sum, &htab);
18498 last_insn = 0;
18499 hilo_delay = 2;
18500 delayed_reg = 0;
18501 lo_reg = gen_rtx_REG (SImode, LO_REGNUM);
18502 fs_delay = false;
18504 /* Make a second pass over the instructions. Delete orphaned
18505 high-part relocations or turn them into NOPs. Avoid hazards
18506 by inserting NOPs. */
18507 for (insn = get_insns (); insn != 0; insn = next_insn)
18509 next_insn = NEXT_INSN (insn);
18510 if (USEFUL_INSN_P (insn))
18512 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
18514 /* If we find an orphaned high-part relocation in a delay
18515 slot, it's easier to turn that instruction into a NOP than
18516 to delete it. The delay slot will be a NOP either way. */
18517 FOR_EACH_SUBINSN (subinsn, insn)
18518 if (INSN_P (subinsn))
18520 if (mips_orphaned_high_part_p (htab, subinsn))
18522 PATTERN (subinsn) = gen_nop ();
18523 INSN_CODE (subinsn) = CODE_FOR_nop;
18525 mips_avoid_hazard (last_insn, subinsn, &hilo_delay,
18526 &delayed_reg, lo_reg, &fs_delay);
18528 last_insn = insn;
18530 else
18532 /* INSN is a single instruction. Delete it if it's an
18533 orphaned high-part relocation. */
18534 if (mips_orphaned_high_part_p (htab, insn))
18535 delete_insn (insn);
18536 /* Also delete cache barriers if the last instruction
18537 was an annulled branch. INSN will not be speculatively
18538 executed. */
18539 else if (recog_memoized (insn) == CODE_FOR_r10k_cache_barrier
18540 && last_insn
18541 && JUMP_P (SEQ_BEGIN (last_insn))
18542 && INSN_ANNULLED_BRANCH_P (SEQ_BEGIN (last_insn)))
18543 delete_insn (insn);
18544 else
18546 mips_avoid_hazard (last_insn, insn, &hilo_delay,
18547 &delayed_reg, lo_reg, &fs_delay);
18548 last_insn = insn;
18554 htab.dispose ();
18557 /* Return true if the function has a long branch instruction. */
18559 static bool
18560 mips_has_long_branch_p (void)
18562 rtx insn, subinsn;
18563 int normal_length;
18565 /* We need up-to-date instruction lengths. */
18566 shorten_branches (get_insns ());
18568 /* Look for a branch that is longer than normal. The normal length for
18569 non-MIPS16 branches is 8, because the length includes the delay slot.
18570 It is 4 for MIPS16, because MIPS16 branches are extended instructions,
18571 but they have no delay slot. */
18572 normal_length = (TARGET_MIPS16 ? 4 : 8);
18573 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
18574 FOR_EACH_SUBINSN (subinsn, insn)
18575 if (JUMP_P (subinsn)
18576 && get_attr_length (subinsn) > normal_length
18577 && (any_condjump_p (subinsn) || any_uncondjump_p (subinsn)))
18578 return true;
18580 return false;
18583 /* If we are using a GOT, but have not decided to use a global pointer yet,
18584 see whether we need one to implement long branches. Convert the ghost
18585 global-pointer instructions into real ones if so. */
18587 static bool
18588 mips_expand_ghost_gp_insns (void)
18590 /* Quick exit if we already know that we will or won't need a
18591 global pointer. */
18592 if (!TARGET_USE_GOT
18593 || cfun->machine->global_pointer == INVALID_REGNUM
18594 || mips_must_initialize_gp_p ())
18595 return false;
18597 /* Run a full check for long branches. */
18598 if (!mips_has_long_branch_p ())
18599 return false;
18601 /* We've now established that we need $gp. */
18602 cfun->machine->must_initialize_gp_p = true;
18603 split_all_insns_noflow ();
18605 return true;
18608 /* Subroutine of mips_reorg to manage passes that require DF. */
18610 static void
18611 mips_df_reorg (void)
18613 /* Create def-use chains. */
18614 df_set_flags (DF_EQ_NOTES);
18615 df_chain_add_problem (DF_UD_CHAIN);
18616 df_analyze ();
18618 if (TARGET_RELAX_PIC_CALLS)
18619 mips_annotate_pic_calls ();
18621 if (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE)
18622 r10k_insert_cache_barriers ();
18624 df_finish_pass (false);
18627 /* Emit code to load LABEL_REF SRC into MIPS16 register DEST. This is
18628 called very late in mips_reorg, but the caller is required to run
18629 mips16_lay_out_constants on the result. */
18631 static void
18632 mips16_load_branch_target (rtx dest, rtx src)
18634 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS)
18636 rtx page, low;
18638 if (mips_cfun_has_cprestore_slot_p ())
18639 mips_emit_move (dest, mips_cprestore_slot (dest, true));
18640 else
18641 mips_emit_move (dest, pic_offset_table_rtx);
18642 page = mips_unspec_address (src, SYMBOL_GOTOFF_PAGE);
18643 low = mips_unspec_address (src, SYMBOL_GOT_PAGE_OFST);
18644 emit_insn (gen_rtx_SET (VOIDmode, dest,
18645 PMODE_INSN (gen_unspec_got, (dest, page))));
18646 emit_insn (gen_rtx_SET (VOIDmode, dest,
18647 gen_rtx_LO_SUM (Pmode, dest, low)));
18649 else
18651 src = mips_unspec_address (src, SYMBOL_ABSOLUTE);
18652 mips_emit_move (dest, src);
18656 /* If we're compiling a MIPS16 function, look for and split any long branches.
18657 This must be called after all other instruction modifications in
18658 mips_reorg. */
18660 static void
18661 mips16_split_long_branches (void)
18663 bool something_changed;
18665 if (!TARGET_MIPS16)
18666 return;
18668 /* Loop until the alignments for all targets are sufficient. */
18671 rtx insn;
18673 shorten_branches (get_insns ());
18674 something_changed = false;
18675 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
18676 if (JUMP_P (insn)
18677 && get_attr_length (insn) > 4
18678 && (any_condjump_p (insn) || any_uncondjump_p (insn)))
18680 rtx old_label, new_label, temp, saved_temp;
18681 rtx target, jump, jump_sequence;
18683 start_sequence ();
18685 /* Free up a MIPS16 register by saving it in $1. */
18686 saved_temp = gen_rtx_REG (Pmode, AT_REGNUM);
18687 temp = gen_rtx_REG (Pmode, GP_REG_FIRST + 2);
18688 emit_move_insn (saved_temp, temp);
18690 /* Load the branch target into TEMP. */
18691 old_label = JUMP_LABEL (insn);
18692 target = gen_rtx_LABEL_REF (Pmode, old_label);
18693 mips16_load_branch_target (temp, target);
18695 /* Jump to the target and restore the register's
18696 original value. */
18697 jump = emit_jump_insn (PMODE_INSN (gen_indirect_jump_and_restore,
18698 (temp, temp, saved_temp)));
18699 JUMP_LABEL (jump) = old_label;
18700 LABEL_NUSES (old_label)++;
18702 /* Rewrite any symbolic references that are supposed to use
18703 a PC-relative constant pool. */
18704 mips16_lay_out_constants (false);
18706 if (simplejump_p (insn))
18707 /* We're going to replace INSN with a longer form. */
18708 new_label = NULL_RTX;
18709 else
18711 /* Create a branch-around label for the original
18712 instruction. */
18713 new_label = gen_label_rtx ();
18714 emit_label (new_label);
18717 jump_sequence = get_insns ();
18718 end_sequence ();
18720 emit_insn_after (jump_sequence, insn);
18721 if (new_label)
18722 invert_jump (insn, new_label, false);
18723 else
18724 delete_insn (insn);
18725 something_changed = true;
18728 while (something_changed);
18731 /* Implement TARGET_MACHINE_DEPENDENT_REORG. */
18733 static void
18734 mips_reorg (void)
18736 /* Restore the BLOCK_FOR_INSN pointers, which are needed by DF. Also during
18737 insn splitting in mips16_lay_out_constants, DF insn info is only kept up
18738 to date if the CFG is available. */
18739 if (mips_cfg_in_reorg ())
18740 compute_bb_for_insn ();
18741 mips16_lay_out_constants (true);
18742 if (mips_cfg_in_reorg ())
18744 mips_df_reorg ();
18745 free_bb_for_insn ();
18749 /* We use a machine specific pass to do a second machine dependent reorg
18750 pass after delay branch scheduling. */
18752 static unsigned int
18753 mips_machine_reorg2 (void)
18755 mips_reorg_process_insns ();
18756 if (!TARGET_MIPS16
18757 && TARGET_EXPLICIT_RELOCS
18758 && TUNE_MIPS4130
18759 && TARGET_VR4130_ALIGN)
18760 vr4130_align_insns ();
18761 if (mips_expand_ghost_gp_insns ())
18762 /* The expansion could invalidate some of the VR4130 alignment
18763 optimizations, but this should be an extremely rare case anyhow. */
18764 mips_reorg_process_insns ();
18765 mips16_split_long_branches ();
18766 return 0;
18769 namespace {
18771 const pass_data pass_data_mips_machine_reorg2 =
18773 RTL_PASS, /* type */
18774 "mach2", /* name */
18775 OPTGROUP_NONE, /* optinfo_flags */
18776 false, /* has_gate */
18777 true, /* has_execute */
18778 TV_MACH_DEP, /* tv_id */
18779 0, /* properties_required */
18780 0, /* properties_provided */
18781 0, /* properties_destroyed */
18782 0, /* todo_flags_start */
18783 TODO_verify_rtl_sharing, /* todo_flags_finish */
18786 class pass_mips_machine_reorg2 : public rtl_opt_pass
18788 public:
18789 pass_mips_machine_reorg2(gcc::context *ctxt)
18790 : rtl_opt_pass(pass_data_mips_machine_reorg2, ctxt)
18793 /* opt_pass methods: */
18794 unsigned int execute () { return mips_machine_reorg2 (); }
18796 }; // class pass_mips_machine_reorg2
18798 } // anon namespace
18800 rtl_opt_pass *
18801 make_pass_mips_machine_reorg2 (gcc::context *ctxt)
18803 return new pass_mips_machine_reorg2 (ctxt);
18807 /* Implement TARGET_ASM_OUTPUT_MI_THUNK. Generate rtl rather than asm text
18808 in order to avoid duplicating too much logic from elsewhere. */
18810 static void
18811 mips_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
18812 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
18813 tree function)
18815 rtx this_rtx, temp1, temp2, insn, fnaddr;
18816 bool use_sibcall_p;
18818 /* Pretend to be a post-reload pass while generating rtl. */
18819 reload_completed = 1;
18821 /* Mark the end of the (empty) prologue. */
18822 emit_note (NOTE_INSN_PROLOGUE_END);
18824 /* Determine if we can use a sibcall to call FUNCTION directly. */
18825 fnaddr = XEXP (DECL_RTL (function), 0);
18826 use_sibcall_p = (mips_function_ok_for_sibcall (function, NULL)
18827 && const_call_insn_operand (fnaddr, Pmode));
18829 /* Determine if we need to load FNADDR from the GOT. */
18830 if (!use_sibcall_p
18831 && (mips_got_symbol_type_p
18832 (mips_classify_symbol (fnaddr, SYMBOL_CONTEXT_LEA))))
18834 /* Pick a global pointer. Use a call-clobbered register if
18835 TARGET_CALL_SAVED_GP. */
18836 cfun->machine->global_pointer
18837 = TARGET_CALL_SAVED_GP ? 15 : GLOBAL_POINTER_REGNUM;
18838 cfun->machine->must_initialize_gp_p = true;
18839 SET_REGNO (pic_offset_table_rtx, cfun->machine->global_pointer);
18841 /* Set up the global pointer for n32 or n64 abicalls. */
18842 mips_emit_loadgp ();
18845 /* We need two temporary registers in some cases. */
18846 temp1 = gen_rtx_REG (Pmode, 2);
18847 temp2 = gen_rtx_REG (Pmode, 3);
18849 /* Find out which register contains the "this" pointer. */
18850 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
18851 this_rtx = gen_rtx_REG (Pmode, GP_ARG_FIRST + 1);
18852 else
18853 this_rtx = gen_rtx_REG (Pmode, GP_ARG_FIRST);
18855 /* Add DELTA to THIS_RTX. */
18856 if (delta != 0)
18858 rtx offset = GEN_INT (delta);
18859 if (!SMALL_OPERAND (delta))
18861 mips_emit_move (temp1, offset);
18862 offset = temp1;
18864 emit_insn (gen_add3_insn (this_rtx, this_rtx, offset));
18867 /* If needed, add *(*THIS_RTX + VCALL_OFFSET) to THIS_RTX. */
18868 if (vcall_offset != 0)
18870 rtx addr;
18872 /* Set TEMP1 to *THIS_RTX. */
18873 mips_emit_move (temp1, gen_rtx_MEM (Pmode, this_rtx));
18875 /* Set ADDR to a legitimate address for *THIS_RTX + VCALL_OFFSET. */
18876 addr = mips_add_offset (temp2, temp1, vcall_offset);
18878 /* Load the offset and add it to THIS_RTX. */
18879 mips_emit_move (temp1, gen_rtx_MEM (Pmode, addr));
18880 emit_insn (gen_add3_insn (this_rtx, this_rtx, temp1));
18883 /* Jump to the target function. Use a sibcall if direct jumps are
18884 allowed, otherwise load the address into a register first. */
18885 if (use_sibcall_p)
18887 insn = emit_call_insn (gen_sibcall_internal (fnaddr, const0_rtx));
18888 SIBLING_CALL_P (insn) = 1;
18890 else
18892 /* This is messy. GAS treats "la $25,foo" as part of a call
18893 sequence and may allow a global "foo" to be lazily bound.
18894 The general move patterns therefore reject this combination.
18896 In this context, lazy binding would actually be OK
18897 for TARGET_CALL_CLOBBERED_GP, but it's still wrong for
18898 TARGET_CALL_SAVED_GP; see mips_load_call_address.
18899 We must therefore load the address via a temporary
18900 register if mips_dangerous_for_la25_p.
18902 If we jump to the temporary register rather than $25,
18903 the assembler can use the move insn to fill the jump's
18904 delay slot.
18906 We can use the same technique for MIPS16 code, where $25
18907 is not a valid JR register. */
18908 if (TARGET_USE_PIC_FN_ADDR_REG
18909 && !TARGET_MIPS16
18910 && !mips_dangerous_for_la25_p (fnaddr))
18911 temp1 = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
18912 mips_load_call_address (MIPS_CALL_SIBCALL, temp1, fnaddr);
18914 if (TARGET_USE_PIC_FN_ADDR_REG
18915 && REGNO (temp1) != PIC_FUNCTION_ADDR_REGNUM)
18916 mips_emit_move (gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM), temp1);
18917 emit_jump_insn (gen_indirect_jump (temp1));
18920 /* Run just enough of rest_of_compilation. This sequence was
18921 "borrowed" from alpha.c. */
18922 insn = get_insns ();
18923 split_all_insns_noflow ();
18924 mips16_lay_out_constants (true);
18925 shorten_branches (insn);
18926 final_start_function (insn, file, 1);
18927 final (insn, file, 1);
18928 final_end_function ();
18930 /* Clean up the vars set above. Note that final_end_function resets
18931 the global pointer for us. */
18932 reload_completed = 0;
18936 /* The last argument passed to mips_set_compression_mode,
18937 or negative if the function hasn't been called yet. */
18938 static unsigned int old_compression_mode = -1;
18940 /* Set up the target-dependent global state for ISA mode COMPRESSION_MODE,
18941 which is either MASK_MIPS16 or MASK_MICROMIPS. */
18943 static void
18944 mips_set_compression_mode (unsigned int compression_mode)
18947 if (compression_mode == old_compression_mode)
18948 return;
18950 /* Restore base settings of various flags. */
18951 target_flags = mips_base_target_flags;
18952 flag_schedule_insns = mips_base_schedule_insns;
18953 flag_reorder_blocks_and_partition = mips_base_reorder_blocks_and_partition;
18954 flag_move_loop_invariants = mips_base_move_loop_invariants;
18955 align_loops = mips_base_align_loops;
18956 align_jumps = mips_base_align_jumps;
18957 align_functions = mips_base_align_functions;
18958 target_flags &= ~(MASK_MIPS16 | MASK_MICROMIPS);
18959 target_flags |= compression_mode;
18961 if (compression_mode & MASK_MIPS16)
18963 /* Switch to MIPS16 mode. */
18964 target_flags |= MASK_MIPS16;
18966 /* Turn off SYNCI if it was on, MIPS16 doesn't support it. */
18967 target_flags &= ~MASK_SYNCI;
18969 /* Don't run the scheduler before reload, since it tends to
18970 increase register pressure. */
18971 flag_schedule_insns = 0;
18973 /* Don't do hot/cold partitioning. mips16_lay_out_constants expects
18974 the whole function to be in a single section. */
18975 flag_reorder_blocks_and_partition = 0;
18977 /* Don't move loop invariants, because it tends to increase
18978 register pressure. It also introduces an extra move in cases
18979 where the constant is the first operand in a two-operand binary
18980 instruction, or when it forms a register argument to a functon
18981 call. */
18982 flag_move_loop_invariants = 0;
18984 target_flags |= MASK_EXPLICIT_RELOCS;
18986 /* Experiments suggest we get the best overall section-anchor
18987 results from using the range of an unextended LW or SW. Code
18988 that makes heavy use of byte or short accesses can do better
18989 with ranges of 0...31 and 0...63 respectively, but most code is
18990 sensitive to the range of LW and SW instead. */
18991 targetm.min_anchor_offset = 0;
18992 targetm.max_anchor_offset = 127;
18994 targetm.const_anchor = 0;
18996 /* MIPS16 has no BAL instruction. */
18997 target_flags &= ~MASK_RELAX_PIC_CALLS;
18999 /* The R4000 errata don't apply to any known MIPS16 cores.
19000 It's simpler to make the R4000 fixes and MIPS16 mode
19001 mutually exclusive. */
19002 target_flags &= ~MASK_FIX_R4000;
19004 if (flag_pic && !TARGET_OLDABI)
19005 sorry ("MIPS16 PIC for ABIs other than o32 and o64");
19007 if (TARGET_XGOT)
19008 sorry ("MIPS16 -mxgot code");
19010 if (TARGET_HARD_FLOAT_ABI && !TARGET_OLDABI)
19011 sorry ("hard-float MIPS16 code for ABIs other than o32 and o64");
19013 if (TARGET_MSA)
19014 sorry ("MSA MIPS16 code");
19016 else
19018 /* Switch to microMIPS or the standard encoding. */
19020 if (TARGET_MICROMIPS)
19021 /* Avoid branch likely. */
19022 target_flags &= ~MASK_BRANCHLIKELY;
19024 /* Provide default values for align_* for 64-bit targets. */
19025 if (TARGET_64BIT)
19027 if (align_loops == 0)
19028 align_loops = 8;
19029 if (align_jumps == 0)
19030 align_jumps = 8;
19031 if (align_functions == 0)
19032 align_functions = 8;
19035 targetm.min_anchor_offset = -32768;
19036 targetm.max_anchor_offset = 32767;
19038 targetm.const_anchor = 0x8000;
19041 /* (Re)initialize MIPS target internals for new ISA. */
19042 mips_init_relocs ();
19044 if (compression_mode & MASK_MIPS16)
19046 if (!mips16_globals)
19047 mips16_globals = save_target_globals_default_opts ();
19048 else
19049 restore_target_globals (mips16_globals);
19051 else
19052 restore_target_globals (&default_target_globals);
19054 old_compression_mode = compression_mode;
19057 /* Implement TARGET_SET_CURRENT_FUNCTION. Decide whether the current
19058 function should use the MIPS16 or microMIPS ISA and switch modes
19059 accordingly. */
19061 static void
19062 mips_set_current_function (tree fndecl)
19064 mips_set_compression_mode (mips_get_compress_mode (fndecl));
19067 /* Allocate a chunk of memory for per-function machine-dependent data. */
19069 static struct machine_function *
19070 mips_init_machine_status (void)
19072 return ggc_alloc_cleared_machine_function ();
19075 /* Return the processor associated with the given ISA level, or null
19076 if the ISA isn't valid. */
19078 static const struct mips_cpu_info *
19079 mips_cpu_info_from_isa (int isa)
19081 unsigned int i;
19083 for (i = 0; i < ARRAY_SIZE (mips_cpu_info_table); i++)
19084 if (mips_cpu_info_table[i].isa == isa)
19085 return mips_cpu_info_table + i;
19087 return NULL;
19090 /* Return a mips_cpu_info entry determined by an option valued
19091 OPT. */
19093 static const struct mips_cpu_info *
19094 mips_cpu_info_from_opt (int opt)
19096 switch (opt)
19098 case MIPS_ARCH_OPTION_FROM_ABI:
19099 /* 'from-abi' selects the most compatible architecture for the
19100 given ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit
19101 ABIs. For the EABIs, we have to decide whether we're using
19102 the 32-bit or 64-bit version. */
19103 return mips_cpu_info_from_isa (ABI_NEEDS_32BIT_REGS ? 1
19104 : ABI_NEEDS_64BIT_REGS ? 3
19105 : (TARGET_64BIT ? 3 : 1));
19107 case MIPS_ARCH_OPTION_NATIVE:
19108 gcc_unreachable ();
19110 default:
19111 return &mips_cpu_info_table[opt];
19115 /* Return a default mips_cpu_info entry, given that no -march= option
19116 was explicitly specified. */
19118 static const struct mips_cpu_info *
19119 mips_default_arch (void)
19121 #if defined (MIPS_CPU_STRING_DEFAULT)
19122 unsigned int i;
19123 for (i = 0; i < ARRAY_SIZE (mips_cpu_info_table); i++)
19124 if (strcmp (mips_cpu_info_table[i].name, MIPS_CPU_STRING_DEFAULT) == 0)
19125 return mips_cpu_info_table + i;
19126 gcc_unreachable ();
19127 #elif defined (MIPS_ISA_DEFAULT)
19128 return mips_cpu_info_from_isa (MIPS_ISA_DEFAULT);
19129 #else
19130 /* 'from-abi' makes a good default: you get whatever the ABI
19131 requires. */
19132 return mips_cpu_info_from_opt (MIPS_ARCH_OPTION_FROM_ABI);
19133 #endif
19136 /* Set up globals to generate code for the ISA or processor
19137 described by INFO. */
19139 static void
19140 mips_set_architecture (const struct mips_cpu_info *info)
19142 if (info != 0)
19144 mips_arch_info = info;
19145 mips_arch = info->cpu;
19146 mips_isa = info->isa;
19147 if (mips_isa < 32)
19148 mips_isa_rev = 0;
19149 else
19150 mips_isa_rev = (mips_isa & 31) + 1;
19154 /* Likewise for tuning. */
19156 static void
19157 mips_set_tune (const struct mips_cpu_info *info)
19159 if (info != 0)
19161 mips_tune_info = info;
19162 mips_tune = info->cpu;
19166 /* Implement TARGET_OPTION_OVERRIDE. */
19168 static void
19169 mips_option_override (void)
19171 int i, start, regno, mode;
19173 if (global_options_set.x_mips_isa_option)
19174 mips_isa_option_info = &mips_cpu_info_table[mips_isa_option];
19176 #ifdef SUBTARGET_OVERRIDE_OPTIONS
19177 SUBTARGET_OVERRIDE_OPTIONS;
19178 #endif
19180 /* MIPS16 and microMIPS cannot coexist. */
19181 if (TARGET_MICROMIPS && TARGET_MIPS16)
19182 error ("unsupported combination: %s", "-mips16 -mmicromips");
19184 /* Save the base compression state and process flags as though we
19185 were generating uncompressed code. */
19186 mips_base_compression_flags = TARGET_COMPRESSION;
19187 target_flags &= ~TARGET_COMPRESSION;
19189 /* -mno-float overrides -mhard-float and -msoft-float. */
19190 if (TARGET_NO_FLOAT)
19192 target_flags |= MASK_SOFT_FLOAT_ABI;
19193 target_flags_explicit |= MASK_SOFT_FLOAT_ABI;
19196 if (TARGET_FLIP_MIPS16)
19197 TARGET_INTERLINK_COMPRESSED = 1;
19199 /* Set the small data limit. */
19200 mips_small_data_threshold = (global_options_set.x_g_switch_value
19201 ? g_switch_value
19202 : MIPS_DEFAULT_GVALUE);
19204 /* The following code determines the architecture and register size.
19205 Similar code was added to GAS 2.14 (see tc-mips.c:md_after_parse_args()).
19206 The GAS and GCC code should be kept in sync as much as possible. */
19208 if (global_options_set.x_mips_arch_option)
19209 mips_set_architecture (mips_cpu_info_from_opt (mips_arch_option));
19211 if (mips_isa_option_info != 0)
19213 if (mips_arch_info == 0)
19214 mips_set_architecture (mips_isa_option_info);
19215 else if (mips_arch_info->isa != mips_isa_option_info->isa)
19216 error ("%<-%s%> conflicts with the other architecture options, "
19217 "which specify a %s processor",
19218 mips_isa_option_info->name,
19219 mips_cpu_info_from_isa (mips_arch_info->isa)->name);
19222 if (mips_arch_info == 0)
19223 mips_set_architecture (mips_default_arch ());
19225 if (ABI_NEEDS_64BIT_REGS && !ISA_HAS_64BIT_REGS)
19226 error ("%<-march=%s%> is not compatible with the selected ABI",
19227 mips_arch_info->name);
19229 /* Optimize for mips_arch, unless -mtune selects a different processor. */
19230 if (global_options_set.x_mips_tune_option)
19231 mips_set_tune (mips_cpu_info_from_opt (mips_tune_option));
19233 if (mips_tune_info == 0)
19234 mips_set_tune (mips_arch_info);
19236 if ((target_flags_explicit & MASK_64BIT) != 0)
19238 /* The user specified the size of the integer registers. Make sure
19239 it agrees with the ABI and ISA. */
19240 if (TARGET_64BIT && !ISA_HAS_64BIT_REGS)
19241 error ("%<-mgp64%> used with a 32-bit processor");
19242 else if (!TARGET_64BIT && ABI_NEEDS_64BIT_REGS)
19243 error ("%<-mgp32%> used with a 64-bit ABI");
19244 else if (TARGET_64BIT && ABI_NEEDS_32BIT_REGS)
19245 error ("%<-mgp64%> used with a 32-bit ABI");
19247 else
19249 /* Infer the integer register size from the ABI and processor.
19250 Restrict ourselves to 32-bit registers if that's all the
19251 processor has, or if the ABI cannot handle 64-bit registers. */
19252 if (ABI_NEEDS_32BIT_REGS || !ISA_HAS_64BIT_REGS)
19253 target_flags &= ~MASK_64BIT;
19254 else
19255 target_flags |= MASK_64BIT;
19258 if ((target_flags_explicit & MASK_FLOAT64) != 0)
19260 if (mips_isa_rev >= 6 && !TARGET_FLOAT64)
19261 error ("the %qs architecture does not support %<-mfp32%>",
19262 mips_arch_info->name);
19263 else if (TARGET_SINGLE_FLOAT && TARGET_FLOAT64)
19264 error ("unsupported combination: %s", "-mfp64 -msingle-float");
19265 else if (TARGET_64BIT && TARGET_DOUBLE_FLOAT && !TARGET_FLOAT64)
19266 error ("unsupported combination: %s", "-mgp64 -mfp32 -mdouble-float");
19267 else if (!TARGET_64BIT && TARGET_FLOAT64)
19269 if (!ISA_HAS_MXHC1)
19270 error ("%<-mgp32%> and %<-mfp64%> can only be combined if"
19271 " the target supports the mfhc1 and mthc1 instructions");
19272 else if (mips_abi != ABI_32)
19273 error ("%<-mgp32%> and %<-mfp64%> can only be combined when using"
19274 " the o32 ABI");
19277 else
19279 /* -msingle-float selects 32-bit float registers. On r6 and later,
19280 -mdouble-float selects 64-bit float registers, since the old paired
19281 register model is not supported. -mmsa selects 64-bit registers for
19282 O32. In other cases the float registers should be the same size as
19283 the integer ones. */
19284 if (mips_isa_rev >= 6 && TARGET_DOUBLE_FLOAT && !TARGET_FLOATXX)
19285 target_flags |= MASK_FLOAT64;
19286 else if (TARGET_64BIT && TARGET_DOUBLE_FLOAT)
19287 target_flags |= MASK_FLOAT64;
19288 else if (mips_abi == ABI_32 && TARGET_MSA && !TARGET_FLOATXX)
19289 target_flags |= MASK_FLOAT64;
19290 else
19291 target_flags &= ~MASK_FLOAT64;
19294 if (mips_abi != ABI_32 && TARGET_FLOATXX)
19295 error ("%<-mfpxx%> can only be used with the o32 ABI");
19296 else if (TARGET_FLOAT64 && TARGET_FLOATXX)
19297 error ("unsupported combination: %s", "-mfp64 -mfpxx");
19298 else if (ISA_MIPS1 && !TARGET_FLOAT32)
19299 error ("%<-march=%s%> requires %<-mfp32%>", mips_arch_info->name);
19300 else if (TARGET_FLOATXX && !mips_lra_flag)
19301 error ("%<-mfpxx%> requires %<-mlra%>");
19303 /* End of code shared with GAS. */
19305 /* The R5900 FPU only supports single precision. */
19306 if (TARGET_MIPS5900 && TARGET_HARD_FLOAT_ABI && TARGET_DOUBLE_FLOAT)
19307 error ("unsupported combination: %s",
19308 "-march=r5900 -mhard-float -mdouble-float");
19310 /* If a -mlong* option was given, check that it matches the ABI,
19311 otherwise infer the -mlong* setting from the other options. */
19312 if ((target_flags_explicit & MASK_LONG64) != 0)
19314 if (TARGET_LONG64)
19316 if (mips_abi == ABI_N32)
19317 error ("%qs is incompatible with %qs", "-mabi=n32", "-mlong64");
19318 else if (mips_abi == ABI_32)
19319 error ("%qs is incompatible with %qs", "-mabi=32", "-mlong64");
19320 else if (mips_abi == ABI_O64 && TARGET_ABICALLS)
19321 /* We have traditionally allowed non-abicalls code to use
19322 an LP64 form of o64. However, it would take a bit more
19323 effort to support the combination of 32-bit GOT entries
19324 and 64-bit pointers, so we treat the abicalls case as
19325 an error. */
19326 error ("the combination of %qs and %qs is incompatible with %qs",
19327 "-mabi=o64", "-mabicalls", "-mlong64");
19329 else
19331 if (mips_abi == ABI_64)
19332 error ("%qs is incompatible with %qs", "-mabi=64", "-mlong32");
19335 else
19337 if ((mips_abi == ABI_EABI && TARGET_64BIT) || mips_abi == ABI_64)
19338 target_flags |= MASK_LONG64;
19339 else
19340 target_flags &= ~MASK_LONG64;
19343 if (!TARGET_OLDABI)
19344 flag_pcc_struct_return = 0;
19346 /* Decide which rtx_costs structure to use. */
19347 if (optimize_size)
19348 mips_cost = &mips_rtx_cost_optimize_size;
19349 else
19350 mips_cost = &mips_rtx_cost_data[mips_tune];
19352 /* If the user hasn't specified a branch cost, use the processor's
19353 default. */
19354 if (mips_branch_cost == 0)
19355 mips_branch_cost = mips_cost->branch_cost;
19357 /* If neither -mbranch-likely nor -mno-branch-likely was given
19358 on the command line, set MASK_BRANCHLIKELY based on the target
19359 architecture and tuning flags. Annulled delay slots are a
19360 size win, so we only consider the processor-specific tuning
19361 for !optimize_size. */
19362 if ((target_flags_explicit & MASK_BRANCHLIKELY) == 0)
19364 if (ISA_HAS_BRANCHLIKELY
19365 && (optimize_size
19366 || (mips_tune_info->tune_flags & PTF_AVOID_BRANCHLIKELY) == 0))
19367 target_flags |= MASK_BRANCHLIKELY;
19368 else
19369 target_flags &= ~MASK_BRANCHLIKELY;
19371 else if (TARGET_BRANCHLIKELY && !ISA_HAS_BRANCHLIKELY)
19372 warning (0, "the %qs architecture does not support branch-likely"
19373 " instructions", mips_arch_info->name);
19375 /* If the user hasn't specified -mimadd or -mno-imadd set
19376 MASK_IMADD based on the target architecture and tuning
19377 flags. */
19378 if ((target_flags_explicit & MASK_IMADD) == 0)
19380 if (ISA_HAS_MADD_MSUB &&
19381 (mips_tune_info->tune_flags & PTF_AVOID_IMADD) == 0)
19382 target_flags |= MASK_IMADD;
19383 else
19384 target_flags &= ~MASK_IMADD;
19386 else if (TARGET_IMADD && !ISA_HAS_MADD_MSUB)
19387 warning (0, "the %qs architecture does not support madd or msub"
19388 " instructions", mips_arch_info->name);
19390 /* If neither -modd-spreg nor -mno-odd-spreg was given on the command
19391 line, set MASK_ODD_SPREG based on the ISA and ABI. */
19392 if ((target_flags_explicit & MASK_ODD_SPREG) == 0)
19394 /* Disable TARGET_ODD_SPREG when using the o32 FPXX ABI. */
19395 if (!ISA_HAS_ODD_SPREG || TARGET_FLOATXX)
19396 target_flags &= ~MASK_ODD_SPREG;
19397 else
19398 target_flags |= MASK_ODD_SPREG;
19400 else if (TARGET_ODD_SPREG && !ISA_HAS_ODD_SPREG)
19401 warning (0, "the %qs architecture does not support odd single-precision"
19402 " registers", mips_arch_info->name);
19404 if (!TARGET_ODD_SPREG && TARGET_64BIT)
19406 error ("unsupported combination: %s", "-mgp64 -mno-odd-spreg");
19407 /* Allow compilation to continue further even though invalid output
19408 will be produced. */
19409 target_flags |= MASK_ODD_SPREG;
19412 if (!ISA_HAS_COMPACT_BRANCHES && mips_cb == MIPS_CB_ALWAYS)
19414 error ("unsupported combination: %qs%s %s",
19415 mips_arch_info->name, TARGET_MICROMIPS ? " -mmicromips" : "",
19416 "-mcompact-branches=always");
19418 else if (!ISA_HAS_DELAY_SLOTS && mips_cb == MIPS_CB_NEVER)
19420 error ("unsupported combination: %qs%s %s",
19421 mips_arch_info->name, TARGET_MICROMIPS ? " -mmicromips" : "",
19422 "-mcompact-branches=never");
19425 /* Require explicit relocs for MIPS R6 onwards. This enables simplification
19426 of the compact branch and jump support through the backend. */
19427 if (!TARGET_EXPLICIT_RELOCS && mips_isa_rev >= 6)
19429 error ("unsupported combination: %qs %s",
19430 mips_arch_info->name, "-mno-explicit-relocs");
19433 /* The effect of -mabicalls isn't defined for the EABI. */
19434 if (mips_abi == ABI_EABI && TARGET_ABICALLS)
19436 error ("unsupported combination: %s", "-mabicalls -mabi=eabi");
19437 target_flags &= ~MASK_ABICALLS;
19440 /* PIC requires -mabicalls. */
19441 if (flag_pic)
19443 if (mips_abi == ABI_EABI)
19444 error ("cannot generate position-independent code for %qs",
19445 "-mabi=eabi");
19446 else if (!TARGET_ABICALLS)
19447 error ("position-independent code requires %qs", "-mabicalls");
19450 if (TARGET_ABICALLS_PIC2)
19451 /* We need to set flag_pic for executables as well as DSOs
19452 because we may reference symbols that are not defined in
19453 the final executable. (MIPS does not use things like
19454 copy relocs, for example.)
19456 There is a body of code that uses __PIC__ to distinguish
19457 between -mabicalls and -mno-abicalls code. The non-__PIC__
19458 variant is usually appropriate for TARGET_ABICALLS_PIC0, as
19459 long as any indirect jumps use $25. */
19460 flag_pic = 1;
19462 /* -mvr4130-align is a "speed over size" optimization: it usually produces
19463 faster code, but at the expense of more nops. Enable it at -O3 and
19464 above. */
19465 if (optimize > 2 && (target_flags_explicit & MASK_VR4130_ALIGN) == 0)
19466 target_flags |= MASK_VR4130_ALIGN;
19468 /* Prefer a call to memcpy over inline code when optimizing for size,
19469 though see MOVE_RATIO in mips.h. */
19470 if (optimize_size && (target_flags_explicit & MASK_MEMCPY) == 0)
19471 target_flags |= MASK_MEMCPY;
19473 /* If we have a nonzero small-data limit, check that the -mgpopt
19474 setting is consistent with the other target flags. */
19475 if (mips_small_data_threshold > 0)
19477 if (!TARGET_GPOPT)
19479 if (!TARGET_EXPLICIT_RELOCS)
19480 error ("%<-mno-gpopt%> needs %<-mexplicit-relocs%>");
19482 TARGET_LOCAL_SDATA = false;
19483 TARGET_EXTERN_SDATA = false;
19485 else
19487 if (TARGET_VXWORKS_RTP)
19488 warning (0, "cannot use small-data accesses for %qs", "-mrtp");
19490 if (TARGET_ABICALLS)
19491 warning (0, "cannot use small-data accesses for %qs",
19492 "-mabicalls");
19496 /* Set NaN and ABS defaults. */
19497 if (mips_nan == MIPS_IEEE_754_DEFAULT && !ISA_HAS_IEEE_754_LEGACY)
19498 mips_nan = MIPS_IEEE_754_2008;
19499 if (mips_abs == MIPS_IEEE_754_DEFAULT && !ISA_HAS_IEEE_754_LEGACY)
19500 mips_abs = MIPS_IEEE_754_2008;
19502 /* Check for IEEE 754 legacy/2008 support. */
19503 if ((mips_nan == MIPS_IEEE_754_LEGACY
19504 || mips_abs == MIPS_IEEE_754_LEGACY)
19505 && !ISA_HAS_IEEE_754_LEGACY)
19506 warning (0, "the %qs architecture does not support %<-m%s=legacy%>",
19507 mips_arch_info->name,
19508 mips_nan == MIPS_IEEE_754_LEGACY ? "nan" : "abs");
19510 if ((mips_nan == MIPS_IEEE_754_2008
19511 || mips_abs == MIPS_IEEE_754_2008)
19512 && !ISA_HAS_IEEE_754_2008)
19513 warning (0, "the %qs architecture does not support %<-m%s=2008%>",
19514 mips_arch_info->name,
19515 mips_nan == MIPS_IEEE_754_2008 ? "nan" : "abs");
19517 /* Pre-IEEE 754-2008 MIPS hardware has a quirky almost-IEEE format
19518 for all its floating point. */
19519 if (mips_nan != MIPS_IEEE_754_2008)
19521 REAL_MODE_FORMAT (SFmode) = &mips_single_format;
19522 REAL_MODE_FORMAT (DFmode) = &mips_double_format;
19523 REAL_MODE_FORMAT (TFmode) = &mips_quad_format;
19526 /* Make sure that the user didn't turn off paired single support when
19527 MIPS-3D support is requested. */
19528 if (TARGET_MIPS3D
19529 && (target_flags_explicit & MASK_PAIRED_SINGLE_FLOAT)
19530 && !TARGET_PAIRED_SINGLE_FLOAT)
19531 error ("%<-mips3d%> requires %<-mpaired-single%>");
19533 /* If TARGET_MIPS3D, enable MASK_PAIRED_SINGLE_FLOAT. */
19534 if (TARGET_MIPS3D)
19535 target_flags |= MASK_PAIRED_SINGLE_FLOAT;
19537 /* Make sure that when TARGET_PAIRED_SINGLE_FLOAT is true, TARGET_FLOAT64
19538 and TARGET_HARD_FLOAT_ABI are both true. */
19539 if (TARGET_PAIRED_SINGLE_FLOAT && !(TARGET_FLOAT64 && TARGET_HARD_FLOAT_ABI))
19541 error ("%qs must be used with %qs",
19542 TARGET_MIPS3D ? "-mips3d" : "-mpaired-single",
19543 TARGET_HARD_FLOAT_ABI ? "-mfp64" : "-mhard-float");
19544 target_flags &= ~MASK_PAIRED_SINGLE_FLOAT;
19545 TARGET_MIPS3D = 0;
19548 /* Make sure that when TARGET_MSA is true, TARGET_FLOAT64 and
19549 TARGET_HARD_FLOAT_ABI and both true. */
19550 if (TARGET_MSA && !(TARGET_FLOAT64 && TARGET_HARD_FLOAT_ABI))
19551 error ("%<-mmsa%> must be used with %<-mfp64%> and %<-mhard-float%>");
19553 /* Make sure that -mpaired-single is only used on ISAs that support it.
19554 We must disable it otherwise since it relies on other ISA properties
19555 like ISA_HAS_8CC having their normal values. */
19556 if (TARGET_PAIRED_SINGLE_FLOAT && !ISA_HAS_PAIRED_SINGLE)
19558 error ("the %qs architecture does not support paired-single"
19559 " instructions", mips_arch_info->name);
19560 target_flags &= ~MASK_PAIRED_SINGLE_FLOAT;
19561 TARGET_MIPS3D = 0;
19564 if (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE
19565 && !TARGET_CACHE_BUILTIN)
19567 error ("%qs requires a target that provides the %qs instruction",
19568 "-mr10k-cache-barrier", "cache");
19569 mips_r10k_cache_barrier = R10K_CACHE_BARRIER_NONE;
19572 /* If TARGET_DSPR2, enable TARGET_DSP. */
19573 if (TARGET_DSPR2)
19574 TARGET_DSP = true;
19576 if (TARGET_DSPR3)
19578 TARGET_DSP = true;
19579 TARGET_DSPR2 = true;
19584 /* .eh_frame addresses should be the same width as a C pointer.
19585 Most MIPS ABIs support only one pointer size, so the assembler
19586 will usually know exactly how big an .eh_frame address is.
19588 Unfortunately, this is not true of the 64-bit EABI. The ABI was
19589 originally defined to use 64-bit pointers (i.e. it is LP64), and
19590 this is still the default mode. However, we also support an n32-like
19591 ILP32 mode, which is selected by -mlong32. The problem is that the
19592 assembler has traditionally not had an -mlong option, so it has
19593 traditionally not known whether we're using the ILP32 or LP64 form.
19595 As it happens, gas versions up to and including 2.19 use _32-bit_
19596 addresses for EABI64 .cfi_* directives. This is wrong for the
19597 default LP64 mode, so we can't use the directives by default.
19598 Moreover, since gas's current behavior is at odds with gcc's
19599 default behavior, it seems unwise to rely on future versions
19600 of gas behaving the same way. We therefore avoid using .cfi
19601 directives for -mlong32 as well. */
19602 if (mips_abi == ABI_EABI && TARGET_64BIT)
19603 flag_dwarf2_cfi_asm = 0;
19605 /* .cfi_* directives generate a read-only section, so fall back on
19606 manual .eh_frame creation if we need the section to be writable. */
19607 if (TARGET_WRITABLE_EH_FRAME)
19608 flag_dwarf2_cfi_asm = 0;
19610 mips_init_print_operand_punct ();
19612 /* Set up array to map GCC register number to debug register number.
19613 Ignore the special purpose register numbers. */
19615 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
19617 mips_dbx_regno[i] = IGNORED_DWARF_REGNUM;
19618 if (GP_REG_P (i) || FP_REG_P (i) || ALL_COP_REG_P (i))
19619 mips_dwarf_regno[i] = i;
19620 else
19621 mips_dwarf_regno[i] = INVALID_REGNUM;
19624 start = GP_DBX_FIRST - GP_REG_FIRST;
19625 for (i = GP_REG_FIRST; i <= GP_REG_LAST; i++)
19626 mips_dbx_regno[i] = i + start;
19628 start = FP_DBX_FIRST - FP_REG_FIRST;
19629 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++)
19630 mips_dbx_regno[i] = i + start;
19632 /* Accumulator debug registers use big-endian ordering. */
19633 mips_dbx_regno[HI_REGNUM] = MD_DBX_FIRST + 0;
19634 mips_dbx_regno[LO_REGNUM] = MD_DBX_FIRST + 1;
19635 mips_dwarf_regno[HI_REGNUM] = MD_REG_FIRST + 0;
19636 mips_dwarf_regno[LO_REGNUM] = MD_REG_FIRST + 1;
19637 for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2)
19639 mips_dwarf_regno[i + TARGET_LITTLE_ENDIAN] = i;
19640 mips_dwarf_regno[i + TARGET_BIG_ENDIAN] = i + 1;
19643 /* Set up mips_hard_regno_mode_ok. */
19644 for (mode = 0; mode < MAX_MACHINE_MODE; mode++)
19645 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
19646 mips_hard_regno_mode_ok[mode][regno]
19647 = mips_hard_regno_mode_ok_p (regno, (machine_mode) mode);
19649 /* Function to allocate machine-dependent function status. */
19650 init_machine_status = &mips_init_machine_status;
19652 /* Default to working around R4000 errata only if the processor
19653 was selected explicitly. */
19654 if ((target_flags_explicit & MASK_FIX_R4000) == 0
19655 && strcmp (mips_arch_info->name, "r4000") == 0)
19656 target_flags |= MASK_FIX_R4000;
19658 /* Default to working around R4400 errata only if the processor
19659 was selected explicitly. */
19660 if ((target_flags_explicit & MASK_FIX_R4400) == 0
19661 && strcmp (mips_arch_info->name, "r4400") == 0)
19662 target_flags |= MASK_FIX_R4400;
19664 /* Default to working around R10000 errata only if the processor
19665 was selected explicitly. */
19666 if ((target_flags_explicit & MASK_FIX_R10000) == 0
19667 && strcmp (mips_arch_info->name, "r10000") == 0)
19668 target_flags |= MASK_FIX_R10000;
19670 /* Make sure that branch-likely instructions available when using
19671 -mfix-r10000. The instructions are not available if either:
19673 1. -mno-branch-likely was passed.
19674 2. The selected ISA does not support branch-likely and
19675 the command line does not include -mbranch-likely. */
19676 if (TARGET_FIX_R10000
19677 && ((target_flags_explicit & MASK_BRANCHLIKELY) == 0
19678 ? !ISA_HAS_BRANCHLIKELY
19679 : !TARGET_BRANCHLIKELY))
19680 sorry ("%qs requires branch-likely instructions", "-mfix-r10000");
19682 if (TARGET_SYNCI && !ISA_HAS_SYNCI)
19684 warning (0, "the %qs architecture does not support the synci "
19685 "instruction", mips_arch_info->name);
19686 target_flags &= ~MASK_SYNCI;
19689 /* Only optimize PIC indirect calls if they are actually required. */
19690 if (!TARGET_USE_GOT || !TARGET_EXPLICIT_RELOCS)
19691 target_flags &= ~MASK_RELAX_PIC_CALLS;
19693 /* Save base state of options. */
19694 mips_base_target_flags = target_flags;
19695 mips_base_schedule_insns = flag_schedule_insns;
19696 mips_base_reorder_blocks_and_partition = flag_reorder_blocks_and_partition;
19697 mips_base_move_loop_invariants = flag_move_loop_invariants;
19698 mips_base_align_loops = align_loops;
19699 mips_base_align_jumps = align_jumps;
19700 mips_base_align_functions = align_functions;
19702 /* Now select the ISA mode.
19704 Do all CPP-sensitive stuff in uncompressed mode; we'll switch modes
19705 later if required. */
19706 mips_set_compression_mode (0);
19708 /* We register a second machine specific reorg pass after delay slot
19709 filling. Registering the pass must be done at start up. It's
19710 convenient to do it here. */
19711 opt_pass *new_pass = make_pass_mips_machine_reorg2 (g);
19712 struct register_pass_info insert_pass_mips_machine_reorg2 =
19714 new_pass, /* pass */
19715 "dbr", /* reference_pass_name */
19716 1, /* ref_pass_instance_number */
19717 PASS_POS_INSERT_AFTER /* po_op */
19719 register_pass (&insert_pass_mips_machine_reorg2);
19721 if (TARGET_HARD_FLOAT_ABI && TARGET_MIPS5900)
19722 REAL_MODE_FORMAT (SFmode) = &spu_single_format;
19725 /* Swap the register information for registers I and I + 1, which
19726 currently have the wrong endianness. Note that the registers'
19727 fixedness and call-clobberedness might have been set on the
19728 command line. */
19730 static void
19731 mips_swap_registers (unsigned int i)
19733 int tmpi;
19734 const char *tmps;
19736 #define SWAP_INT(X, Y) (tmpi = (X), (X) = (Y), (Y) = tmpi)
19737 #define SWAP_STRING(X, Y) (tmps = (X), (X) = (Y), (Y) = tmps)
19739 SWAP_INT (fixed_regs[i], fixed_regs[i + 1]);
19740 SWAP_INT (call_used_regs[i], call_used_regs[i + 1]);
19741 SWAP_INT (call_really_used_regs[i], call_really_used_regs[i + 1]);
19742 SWAP_STRING (reg_names[i], reg_names[i + 1]);
19744 #undef SWAP_STRING
19745 #undef SWAP_INT
19748 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */
19750 static void
19751 mips_conditional_register_usage (void)
19754 if (ISA_HAS_DSP)
19756 /* These DSP control register fields are global. */
19757 global_regs[CCDSP_PO_REGNUM] = 1;
19758 global_regs[CCDSP_SC_REGNUM] = 1;
19760 else
19761 AND_COMPL_HARD_REG_SET (accessible_reg_set,
19762 reg_class_contents[(int) DSP_ACC_REGS]);
19764 if (!ISA_HAS_HILO && !ISA_HAS_DSP)
19765 AND_COMPL_HARD_REG_SET (accessible_reg_set,
19766 reg_class_contents[(int) MD_REGS]);
19768 if (!TARGET_HARD_FLOAT)
19770 AND_COMPL_HARD_REG_SET (accessible_reg_set,
19771 reg_class_contents[(int) FP_REGS]);
19772 AND_COMPL_HARD_REG_SET (accessible_reg_set,
19773 reg_class_contents[(int) ST_REGS]);
19775 else if (!ISA_HAS_8CC)
19777 /* We only have a single condition-code register. We implement
19778 this by fixing all the condition-code registers and generating
19779 RTL that refers directly to ST_REG_FIRST. */
19780 AND_COMPL_HARD_REG_SET (accessible_reg_set,
19781 reg_class_contents[(int) ST_REGS]);
19782 if (!ISA_HAS_CCF)
19783 SET_HARD_REG_BIT (accessible_reg_set, FPSW_REGNUM);
19784 fixed_regs[FPSW_REGNUM] = call_used_regs[FPSW_REGNUM] = 1;
19786 if (TARGET_MIPS16)
19788 /* In MIPS16 mode, we prohibit the unused $s registers, since they
19789 are call-saved, and saving them via a MIPS16 register would
19790 probably waste more time than just reloading the value.
19792 We permit the $t temporary registers when optimizing for speed
19793 but not when optimizing for space because using them results in
19794 code that is larger (but faster) then not using them. We do
19795 allow $24 (t8) because it is used in CMP and CMPI instructions
19796 and $25 (t9) because it is used as the function call address in
19797 SVR4 PIC code. */
19799 fixed_regs[18] = call_used_regs[18] = 1;
19800 fixed_regs[19] = call_used_regs[19] = 1;
19801 fixed_regs[20] = call_used_regs[20] = 1;
19802 fixed_regs[21] = call_used_regs[21] = 1;
19803 fixed_regs[22] = call_used_regs[22] = 1;
19804 fixed_regs[23] = call_used_regs[23] = 1;
19805 fixed_regs[26] = call_used_regs[26] = 1;
19806 fixed_regs[27] = call_used_regs[27] = 1;
19807 fixed_regs[30] = call_used_regs[30] = 1;
19808 if (optimize_size)
19810 fixed_regs[8] = call_used_regs[8] = 1;
19811 fixed_regs[9] = call_used_regs[9] = 1;
19812 fixed_regs[10] = call_used_regs[10] = 1;
19813 fixed_regs[11] = call_used_regs[11] = 1;
19814 fixed_regs[12] = call_used_regs[12] = 1;
19815 fixed_regs[13] = call_used_regs[13] = 1;
19816 fixed_regs[14] = call_used_regs[14] = 1;
19817 fixed_regs[15] = call_used_regs[15] = 1;
19820 /* Do not allow HI and LO to be treated as register operands.
19821 There are no MTHI or MTLO instructions (or any real need
19822 for them) and one-way registers cannot easily be reloaded. */
19823 AND_COMPL_HARD_REG_SET (operand_reg_set,
19824 reg_class_contents[(int) MD_REGS]);
19826 /* $f20-$f23 are call-clobbered for n64. */
19827 if (mips_abi == ABI_64)
19829 int regno;
19830 for (regno = FP_REG_FIRST + 20; regno < FP_REG_FIRST + 24; regno++)
19831 call_really_used_regs[regno] = call_used_regs[regno] = 1;
19833 /* Odd registers in the range $f21-$f31 (inclusive) are call-clobbered
19834 for n32 and o32 FP64. */
19835 if (mips_abi == ABI_N32
19836 || (mips_abi == ABI_32
19837 && TARGET_FLOAT64))
19839 int regno;
19840 for (regno = FP_REG_FIRST + 21; regno <= FP_REG_FIRST + 31; regno+=2)
19841 call_really_used_regs[regno] = call_used_regs[regno] = 1;
19843 /* Make sure that double-register accumulator values are correctly
19844 ordered for the current endianness. */
19845 if (TARGET_LITTLE_ENDIAN)
19847 unsigned int regno;
19849 mips_swap_registers (MD_REG_FIRST);
19850 for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno += 2)
19851 mips_swap_registers (regno);
19855 /* Implement EH_USES. */
19857 bool
19858 mips_eh_uses (unsigned int regno)
19860 if (reload_completed && !TARGET_ABSOLUTE_JUMPS)
19862 /* We need to force certain registers to be live in order to handle
19863 PIC long branches correctly. See mips_must_initialize_gp_p for
19864 details. */
19865 if (mips_cfun_has_cprestore_slot_p ())
19867 if (regno == CPRESTORE_SLOT_REGNUM)
19868 return true;
19870 else
19872 if (cfun->machine->global_pointer == regno)
19873 return true;
19877 return false;
19880 /* Implement EPILOGUE_USES. */
19882 bool
19883 mips_epilogue_uses (unsigned int regno)
19885 /* Say that the epilogue uses the return address register. Note that
19886 in the case of sibcalls, the values "used by the epilogue" are
19887 considered live at the start of the called function. */
19888 if (regno == RETURN_ADDR_REGNUM)
19889 return true;
19891 /* If using a GOT, say that the epilogue also uses GOT_VERSION_REGNUM.
19892 See the comment above load_call<mode> for details. */
19893 if (TARGET_USE_GOT && (regno) == GOT_VERSION_REGNUM)
19894 return true;
19896 /* An interrupt handler must preserve some registers that are
19897 ordinarily call-clobbered. */
19898 if (cfun->machine->interrupt_handler_p
19899 && mips_interrupt_extra_call_saved_reg_p (regno))
19900 return true;
19902 return false;
19905 /* A for_each_rtx callback. Stop the search if *X is an AT register. */
19907 static int
19908 mips_at_reg_p (rtx *x, void *data ATTRIBUTE_UNUSED)
19910 return REG_P (*x) && REGNO (*x) == AT_REGNUM;
19913 /* Return true if INSN needs to be wrapped in ".set noat".
19914 INSN has NOPERANDS operands, stored in OPVEC. */
19916 static bool
19917 mips_need_noat_wrapper_p (rtx insn, rtx *opvec, int noperands)
19919 int i;
19921 if (recog_memoized (insn) >= 0)
19922 for (i = 0; i < noperands; i++)
19923 if (for_each_rtx (&opvec[i], mips_at_reg_p, NULL))
19924 return true;
19925 return false;
19928 /* Implement FINAL_PRESCAN_INSN. */
19930 void
19931 mips_final_prescan_insn (rtx insn, rtx *opvec, int noperands)
19933 if (mips_need_noat_wrapper_p (insn, opvec, noperands))
19934 mips_push_asm_switch (&mips_noat);
19937 /* Implement TARGET_ASM_FINAL_POSTSCAN_INSN. */
19939 static void
19940 mips_final_postscan_insn (FILE *file ATTRIBUTE_UNUSED, rtx insn,
19941 rtx *opvec, int noperands)
19943 if (mips_need_noat_wrapper_p (insn, opvec, noperands))
19944 mips_pop_asm_switch (&mips_noat);
19947 /* Return the function that is used to expand the <u>mulsidi3 pattern.
19948 EXT_CODE is the code of the extension used. Return NULL if widening
19949 multiplication shouldn't be used. */
19951 mulsidi3_gen_fn
19952 mips_mulsidi3_gen_fn (enum rtx_code ext_code)
19954 bool signed_p;
19956 signed_p = ext_code == SIGN_EXTEND;
19957 if (TARGET_64BIT)
19959 /* Don't use widening multiplication with MULT when we have DMUL. Even
19960 with the extension of its input operands DMUL is faster. Note that
19961 the extension is not needed for signed multiplication. In order to
19962 ensure that we always remove the redundant sign-extension in this
19963 case we still expand mulsidi3 for DMUL. */
19964 if (ISA_HAS_R6DMUL)
19965 return signed_p ? gen_mulsidi3_64bit_r6dmul : NULL;
19966 if (ISA_HAS_DMUL3)
19967 return signed_p ? gen_mulsidi3_64bit_dmul : NULL;
19968 if (TARGET_MIPS16)
19969 return (signed_p
19970 ? gen_mulsidi3_64bit_mips16
19971 : gen_umulsidi3_64bit_mips16);
19972 if (TARGET_FIX_R4000)
19973 return NULL;
19974 return signed_p ? gen_mulsidi3_64bit : gen_umulsidi3_64bit;
19976 else
19978 if (ISA_HAS_R6MUL)
19979 return (signed_p ? gen_mulsidi3_32bit_r6 : gen_umulsidi3_32bit_r6);
19980 if (TARGET_MIPS16)
19981 return (signed_p
19982 ? gen_mulsidi3_32bit_mips16
19983 : gen_umulsidi3_32bit_mips16);
19984 if (TARGET_FIX_R4000 && !ISA_HAS_DSP)
19985 return signed_p ? gen_mulsidi3_32bit_r4000 : gen_umulsidi3_32bit_r4000;
19986 return signed_p ? gen_mulsidi3_32bit : gen_umulsidi3_32bit;
19990 /* Return true if PATTERN matches the kind of instruction generated by
19991 umips_build_save_restore. SAVE_P is true for store. */
19993 bool
19994 umips_save_restore_pattern_p (bool save_p, rtx pattern)
19996 int n;
19997 unsigned int i;
19998 HOST_WIDE_INT first_offset = 0;
19999 rtx first_base = 0;
20000 unsigned int regmask = 0;
20002 for (n = 0; n < XVECLEN (pattern, 0); n++)
20004 rtx set, reg, mem, this_base;
20005 HOST_WIDE_INT this_offset;
20007 /* Check that we have a SET. */
20008 set = XVECEXP (pattern, 0, n);
20009 if (GET_CODE (set) != SET)
20010 return false;
20012 /* Check that the SET is a load (if restoring) or a store
20013 (if saving). */
20014 mem = save_p ? SET_DEST (set) : SET_SRC (set);
20015 if (!MEM_P (mem) || MEM_VOLATILE_P (mem))
20016 return false;
20018 /* Check that the address is the sum of base and a possibly-zero
20019 constant offset. Determine if the offset is in range. */
20020 mips_split_plus (XEXP (mem, 0), &this_base, &this_offset);
20021 if (!REG_P (this_base))
20022 return false;
20024 if (n == 0)
20026 if (!UMIPS_12BIT_OFFSET_P (this_offset))
20027 return false;
20028 first_base = this_base;
20029 first_offset = this_offset;
20031 else
20033 /* Check that the save slots are consecutive. */
20034 if (REGNO (this_base) != REGNO (first_base)
20035 || this_offset != first_offset + UNITS_PER_WORD * n)
20036 return false;
20039 /* Check that SET's other operand is a register. */
20040 reg = save_p ? SET_SRC (set) : SET_DEST (set);
20041 if (!REG_P (reg))
20042 return false;
20044 regmask |= 1 << REGNO (reg);
20047 for (i = 0; i < ARRAY_SIZE (umips_swm_mask); i++)
20048 if (regmask == umips_swm_mask[i])
20049 return true;
20051 return false;
20054 /* Return the assembly instruction for microMIPS LWM or SWM.
20055 SAVE_P and PATTERN are as for umips_save_restore_pattern_p. */
20057 const char *
20058 umips_output_save_restore (bool save_p, rtx pattern)
20060 static char buffer[300];
20061 char *s;
20062 int n;
20063 HOST_WIDE_INT offset;
20064 rtx base, mem, set, last_set, last_reg;
20066 /* Parse the pattern. */
20067 gcc_assert (umips_save_restore_pattern_p (save_p, pattern));
20069 s = strcpy (buffer, save_p ? "swm\t" : "lwm\t");
20070 s += strlen (s);
20071 n = XVECLEN (pattern, 0);
20073 set = XVECEXP (pattern, 0, 0);
20074 mem = save_p ? SET_DEST (set) : SET_SRC (set);
20075 mips_split_plus (XEXP (mem, 0), &base, &offset);
20077 last_set = XVECEXP (pattern, 0, n - 1);
20078 last_reg = save_p ? SET_SRC (last_set) : SET_DEST (last_set);
20080 if (REGNO (last_reg) == 31)
20081 n--;
20083 gcc_assert (n <= 9);
20084 if (n == 0)
20086 else if (n == 1)
20087 s += sprintf (s, "%s,", reg_names[16]);
20088 else if (n < 9)
20089 s += sprintf (s, "%s-%s,", reg_names[16], reg_names[15 + n]);
20090 else if (n == 9)
20091 s += sprintf (s, "%s-%s,%s,", reg_names[16], reg_names[23],
20092 reg_names[30]);
20094 if (REGNO (last_reg) == 31)
20095 s += sprintf (s, "%s,", reg_names[31]);
20097 s += sprintf (s, "%d(%s)", (int)offset, reg_names[REGNO (base)]);
20098 return buffer;
20101 /* Return true if MEM1 and MEM2 use the same base register, and the
20102 offset of MEM2 equals the offset of MEM1 plus 4. FIRST_REG is the
20103 register into (from) which the contents of MEM1 will be loaded
20104 (stored), depending on the value of LOAD_P.
20105 SWAP_P is true when the 1st and 2nd instructions are swapped. */
20107 static bool
20108 umips_load_store_pair_p_1 (bool load_p, bool swap_p,
20109 rtx first_reg, rtx mem1, rtx mem2)
20111 rtx base1, base2;
20112 HOST_WIDE_INT offset1, offset2;
20114 if (!MEM_P (mem1) || !MEM_P (mem2))
20115 return false;
20117 mips_split_plus (XEXP (mem1, 0), &base1, &offset1);
20118 mips_split_plus (XEXP (mem2, 0), &base2, &offset2);
20120 if (!REG_P (base1) || !rtx_equal_p (base1, base2))
20121 return false;
20123 /* Avoid invalid load pair instructions. */
20124 if (load_p && REGNO (first_reg) == REGNO (base1))
20125 return false;
20127 /* We must avoid this case for anti-dependence.
20128 Ex: lw $3, 4($3)
20129 lw $2, 0($3)
20130 first_reg is $2, but the base is $3. */
20131 if (load_p
20132 && swap_p
20133 && REGNO (first_reg) + 1 == REGNO (base1))
20134 return false;
20136 if (offset2 != offset1 + 4)
20137 return false;
20139 if (!UMIPS_12BIT_OFFSET_P (offset1))
20140 return false;
20142 return true;
20145 bool
20146 mips_load_store_bonding_p (rtx *operands, machine_mode mode, bool load_p)
20148 rtx reg1, reg2, mem1, mem2, base1, base2;
20149 enum reg_class rc1, rc2;
20150 HOST_WIDE_INT offset1, offset2;
20152 if (load_p)
20154 reg1 = operands[0];
20155 reg2 = operands[2];
20156 mem1 = operands[1];
20157 mem2 = operands[3];
20159 else
20161 reg1 = operands[1];
20162 reg2 = operands[3];
20163 mem1 = operands[0];
20164 mem2 = operands[2];
20167 if (!mips_address_insns (XEXP (mem1, 0), mode, false)
20168 || !mips_address_insns (XEXP (mem2, 0), mode, false))
20169 return false;
20171 mips_split_plus (XEXP (mem1, 0), &base1, &offset1);
20172 mips_split_plus (XEXP (mem2, 0), &base2, &offset2);
20174 /* Base regs do not match. */
20175 if (!REG_P (base1) || !rtx_equal_p (base1, base2))
20176 return false;
20178 /* Either of the loads is clobbering base register. */
20179 if (load_p
20180 && (REGNO (reg1) == REGNO (base1)
20181 || (REGNO (reg2) == REGNO (base1))))
20182 return false;
20184 /* Loading in same registers. */
20185 if (load_p
20186 && REGNO (reg1) == REGNO (reg2))
20187 return false;
20189 /* The loads/stores are not of same type. */
20190 rc1 = REGNO_REG_CLASS (REGNO (reg1));
20191 rc2 = REGNO_REG_CLASS (REGNO (reg2));
20192 if (rc1 != rc2
20193 && !reg_class_subset_p (rc1, rc2)
20194 && !reg_class_subset_p (rc2, rc1))
20195 return false;
20197 if (abs(offset1 - offset2) != GET_MODE_SIZE (mode))
20198 return false;
20200 return true;
20203 /* OPERANDS describes the operands to a pair of SETs, in the order
20204 dest1, src1, dest2, src2. Return true if the operands can be used
20205 in an LWP or SWP instruction; LOAD_P says which. */
20207 bool
20208 umips_load_store_pair_p (bool load_p, rtx *operands)
20210 rtx reg1, reg2, mem1, mem2;
20212 if (load_p)
20214 reg1 = operands[0];
20215 reg2 = operands[2];
20216 mem1 = operands[1];
20217 mem2 = operands[3];
20219 else
20221 reg1 = operands[1];
20222 reg2 = operands[3];
20223 mem1 = operands[0];
20224 mem2 = operands[2];
20227 if (REGNO (reg2) == REGNO (reg1) + 1)
20228 return umips_load_store_pair_p_1 (load_p, false, reg1, mem1, mem2);
20230 if (REGNO (reg1) == REGNO (reg2) + 1)
20231 return umips_load_store_pair_p_1 (load_p, true, reg2, mem2, mem1);
20233 return false;
20236 /* Return the assembly instruction for a microMIPS LWP or SWP in which
20237 the first register is REG and the first memory slot is MEM.
20238 LOAD_P is true for LWP. */
20240 static void
20241 umips_output_load_store_pair_1 (bool load_p, rtx reg, rtx mem)
20243 rtx ops[] = {reg, mem};
20245 if (load_p)
20246 output_asm_insn ("lwp\t%0,%1", ops);
20247 else
20248 output_asm_insn ("swp\t%0,%1", ops);
20251 /* Output the assembly instruction for a microMIPS LWP or SWP instruction.
20252 LOAD_P and OPERANDS are as for umips_load_store_pair_p. */
20254 void
20255 umips_output_load_store_pair (bool load_p, rtx *operands)
20257 rtx reg1, reg2, mem1, mem2;
20258 if (load_p)
20260 reg1 = operands[0];
20261 reg2 = operands[2];
20262 mem1 = operands[1];
20263 mem2 = operands[3];
20265 else
20267 reg1 = operands[1];
20268 reg2 = operands[3];
20269 mem1 = operands[0];
20270 mem2 = operands[2];
20273 if (REGNO (reg2) == REGNO (reg1) + 1)
20275 umips_output_load_store_pair_1 (load_p, reg1, mem1);
20276 return;
20279 gcc_assert (REGNO (reg1) == REGNO (reg2) + 1);
20280 umips_output_load_store_pair_1 (load_p, reg2, mem2);
20283 /* Return true if REG1 and REG2 match the criteria for a movep insn. */
20285 bool
20286 umips_movep_target_p (rtx reg1, rtx reg2)
20288 int regno1, regno2, pair;
20289 unsigned int i;
20290 static const int match[8] = {
20291 0x00000060, /* 5, 6 */
20292 0x000000a0, /* 5, 7 */
20293 0x000000c0, /* 6, 7 */
20294 0x00200010, /* 4, 21 */
20295 0x00400010, /* 4, 22 */
20296 0x00000030, /* 4, 5 */
20297 0x00000050, /* 4, 6 */
20298 0x00000090 /* 4, 7 */
20301 if (!REG_P (reg1) || !REG_P (reg2))
20302 return false;
20304 regno1 = REGNO (reg1);
20305 regno2 = REGNO (reg2);
20307 if (!GP_REG_P (regno1) || !GP_REG_P (regno2))
20308 return false;
20310 pair = (1 << regno1) | (1 << regno2);
20312 for (i = 0; i < ARRAY_SIZE (match); i++)
20313 if (pair == match[i])
20314 return true;
20316 return false;
20319 /* Return the size in bytes of the trampoline code, padded to
20320 TRAMPOLINE_ALIGNMENT bits. The static chain pointer and target
20321 function address immediately follow. */
20324 mips_trampoline_code_size (void)
20326 if (TARGET_USE_PIC_FN_ADDR_REG)
20327 return 4 * 4;
20328 else if (ptr_mode == DImode)
20329 return 8 * 4;
20330 else if (ISA_HAS_LOAD_DELAY)
20331 return 6 * 4;
20332 else
20333 return 4 * 4;
20336 /* Implement TARGET_TRAMPOLINE_INIT. */
20338 static void
20339 mips_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
20341 rtx addr, end_addr, high, low, opcode, mem;
20342 rtx trampoline[8];
20343 unsigned int i, j;
20344 HOST_WIDE_INT end_addr_offset, static_chain_offset, target_function_offset;
20346 /* Work out the offsets of the pointers from the start of the
20347 trampoline code. */
20348 end_addr_offset = mips_trampoline_code_size ();
20349 static_chain_offset = end_addr_offset;
20350 target_function_offset = static_chain_offset + GET_MODE_SIZE (ptr_mode);
20352 /* Get pointers to the beginning and end of the code block. */
20353 addr = force_reg (Pmode, XEXP (m_tramp, 0));
20354 end_addr = mips_force_binary (Pmode, PLUS, addr, GEN_INT (end_addr_offset));
20356 #define OP(X) gen_int_mode (X, SImode)
20358 /* Build up the code in TRAMPOLINE. */
20359 i = 0;
20360 if (TARGET_USE_PIC_FN_ADDR_REG)
20362 /* $25 contains the address of the trampoline. Emit code of the form:
20364 l[wd] $1, target_function_offset($25)
20365 l[wd] $static_chain, static_chain_offset($25)
20366 jr $1
20367 move $25,$1. */
20368 trampoline[i++] = OP (MIPS_LOAD_PTR (AT_REGNUM,
20369 target_function_offset,
20370 PIC_FUNCTION_ADDR_REGNUM));
20371 trampoline[i++] = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM,
20372 static_chain_offset,
20373 PIC_FUNCTION_ADDR_REGNUM));
20374 trampoline[i++] = OP (MIPS_JR (AT_REGNUM));
20375 trampoline[i++] = OP (MIPS_MOVE (PIC_FUNCTION_ADDR_REGNUM, AT_REGNUM));
20377 else if (ptr_mode == DImode)
20379 /* It's too cumbersome to create the full 64-bit address, so let's
20380 instead use:
20382 move $1, $31
20383 bal 1f
20385 1: l[wd] $25, target_function_offset - 12($31)
20386 l[wd] $static_chain, static_chain_offset - 12($31)
20387 jr $25
20388 move $31, $1
20390 where 12 is the offset of "1:" from the start of the code block. */
20391 trampoline[i++] = OP (MIPS_MOVE (AT_REGNUM, RETURN_ADDR_REGNUM));
20392 trampoline[i++] = OP (MIPS_BAL (1));
20393 trampoline[i++] = OP (MIPS_NOP);
20394 trampoline[i++] = OP (MIPS_LOAD_PTR (PIC_FUNCTION_ADDR_REGNUM,
20395 target_function_offset - 12,
20396 RETURN_ADDR_REGNUM));
20397 trampoline[i++] = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM,
20398 static_chain_offset - 12,
20399 RETURN_ADDR_REGNUM));
20400 trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM));
20401 trampoline[i++] = OP (MIPS_MOVE (RETURN_ADDR_REGNUM, AT_REGNUM));
20403 else
20405 /* If the target has load delays, emit:
20407 lui $1, %hi(end_addr)
20408 lw $25, %lo(end_addr + ...)($1)
20409 lw $static_chain, %lo(end_addr + ...)($1)
20410 jr $25
20413 Otherwise emit:
20415 lui $1, %hi(end_addr)
20416 lw $25, %lo(end_addr + ...)($1)
20417 jr $25
20418 lw $static_chain, %lo(end_addr + ...)($1). */
20420 /* Split END_ADDR into %hi and %lo values. Trampolines are aligned
20421 to 64 bits, so the %lo value will have the bottom 3 bits clear. */
20422 high = expand_simple_binop (SImode, PLUS, end_addr, GEN_INT (0x8000),
20423 NULL, false, OPTAB_WIDEN);
20424 high = expand_simple_binop (SImode, LSHIFTRT, high, GEN_INT (16),
20425 NULL, false, OPTAB_WIDEN);
20426 low = convert_to_mode (SImode, gen_lowpart (HImode, end_addr), true);
20428 /* Emit the LUI. */
20429 opcode = OP (MIPS_LUI (AT_REGNUM, 0));
20430 trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, high,
20431 NULL, false, OPTAB_WIDEN);
20433 /* Emit the load of the target function. */
20434 opcode = OP (MIPS_LOAD_PTR (PIC_FUNCTION_ADDR_REGNUM,
20435 target_function_offset - end_addr_offset,
20436 AT_REGNUM));
20437 trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low,
20438 NULL, false, OPTAB_WIDEN);
20440 /* Emit the JR here, if we can. */
20441 if (!ISA_HAS_LOAD_DELAY)
20442 trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM));
20444 /* Emit the load of the static chain register. */
20445 opcode = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM,
20446 static_chain_offset - end_addr_offset,
20447 AT_REGNUM));
20448 trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low,
20449 NULL, false, OPTAB_WIDEN);
20451 /* Emit the JR, if we couldn't above. */
20452 if (ISA_HAS_LOAD_DELAY)
20454 trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM));
20455 trampoline[i++] = OP (MIPS_NOP);
20459 #undef OP
20461 /* If we are using compact branches we don't have delay slots so
20462 place the instruction that was in the delay slot before the JRC
20463 instruction. */
20465 if (TARGET_CB_ALWAYS)
20467 rtx temp;
20468 temp = trampoline[i-2];
20469 trampoline[i-2] = trampoline[i-1];
20470 trampoline[i-1] = temp;
20473 /* Copy the trampoline code. Leave any padding uninitialized. */
20474 for (j = 0; j < i; j++)
20476 mem = adjust_address (m_tramp, SImode, j * GET_MODE_SIZE (SImode));
20477 mips_emit_move (mem, trampoline[j]);
20480 /* Set up the static chain pointer field. */
20481 mem = adjust_address (m_tramp, ptr_mode, static_chain_offset);
20482 mips_emit_move (mem, chain_value);
20484 /* Set up the target function field. */
20485 mem = adjust_address (m_tramp, ptr_mode, target_function_offset);
20486 mips_emit_move (mem, XEXP (DECL_RTL (fndecl), 0));
20488 /* Flush the code part of the trampoline. */
20489 emit_insn (gen_add3_insn (end_addr, addr, GEN_INT (TRAMPOLINE_SIZE)));
20490 emit_insn (gen_clear_cache (addr, end_addr));
20493 /* Implement FUNCTION_PROFILER. */
20495 void mips_function_profiler (FILE *file)
20497 if (TARGET_MIPS16)
20498 sorry ("mips16 function profiling");
20499 if (TARGET_LONG_CALLS)
20501 /* For TARGET_LONG_CALLS use $3 for the address of _mcount. */
20502 if (Pmode == DImode)
20503 fprintf (file, "\tdla\t%s,_mcount\n", reg_names[3]);
20504 else
20505 fprintf (file, "\tla\t%s,_mcount\n", reg_names[3]);
20507 mips_push_asm_switch (&mips_noat);
20508 fprintf (file, "\tmove\t%s,%s\t\t# save current return address\n",
20509 reg_names[AT_REGNUM], reg_names[RETURN_ADDR_REGNUM]);
20510 /* _mcount treats $2 as the static chain register. */
20511 if (cfun->static_chain_decl != NULL)
20512 fprintf (file, "\tmove\t%s,%s\n", reg_names[2],
20513 reg_names[STATIC_CHAIN_REGNUM]);
20514 if (TARGET_MCOUNT_RA_ADDRESS)
20516 /* If TARGET_MCOUNT_RA_ADDRESS load $12 with the address of the
20517 ra save location. */
20518 if (cfun->machine->frame.ra_fp_offset == 0)
20519 /* ra not saved, pass zero. */
20520 fprintf (file, "\tmove\t%s,%s\n", reg_names[12], reg_names[0]);
20521 else
20522 fprintf (file, "\t%s\t%s," HOST_WIDE_INT_PRINT_DEC "(%s)\n",
20523 Pmode == DImode ? "dla" : "la", reg_names[12],
20524 cfun->machine->frame.ra_fp_offset,
20525 reg_names[STACK_POINTER_REGNUM]);
20527 if (!TARGET_NEWABI)
20528 fprintf (file,
20529 "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from stack\n",
20530 TARGET_64BIT ? "dsubu" : "subu",
20531 reg_names[STACK_POINTER_REGNUM],
20532 reg_names[STACK_POINTER_REGNUM],
20533 Pmode == DImode ? 16 : 8);
20535 if (TARGET_LONG_CALLS)
20536 fprintf (file, "\tjalr\t%s\n", reg_names[3]);
20537 else
20538 fprintf (file, "\tjal\t_mcount\n");
20539 mips_pop_asm_switch (&mips_noat);
20540 /* _mcount treats $2 as the static chain register. */
20541 if (cfun->static_chain_decl != NULL)
20542 fprintf (file, "\tmove\t%s,%s\n", reg_names[STATIC_CHAIN_REGNUM],
20543 reg_names[2]);
20546 /* Implement TARGET_SHIFT_TRUNCATION_MASK. We want to keep the default
20547 behaviour of TARGET_SHIFT_TRUNCATION_MASK for non-vector modes even
20548 when TARGET_LOONGSON_VECTORS is true. */
20550 static unsigned HOST_WIDE_INT
20551 mips_shift_truncation_mask (machine_mode mode)
20553 if (TARGET_LOONGSON_VECTORS && VECTOR_MODE_P (mode))
20554 return 0;
20556 return GET_MODE_BITSIZE (mode) - 1;
20559 /* Implement TARGET_PREPARE_PCH_SAVE. */
20561 static void
20562 mips_prepare_pch_save (void)
20564 /* We are called in a context where the current MIPS16 vs. non-MIPS16
20565 setting should be irrelevant. The question then is: which setting
20566 makes most sense at load time?
20568 The PCH is loaded before the first token is read. We should never
20569 have switched into MIPS16 mode by that point, and thus should not
20570 have populated mips16_globals. Nor can we load the entire contents
20571 of mips16_globals from the PCH file, because mips16_globals contains
20572 a combination of GGC and non-GGC data.
20574 There is therefore no point in trying save the GGC part of
20575 mips16_globals to the PCH file, or to preserve MIPS16ness across
20576 the PCH save and load. The loading compiler would not have access
20577 to the non-GGC parts of mips16_globals (either from the PCH file,
20578 or from a copy that the loading compiler generated itself) and would
20579 have to call target_reinit anyway.
20581 It therefore seems best to switch back to non-MIPS16 mode at
20582 save time, and to ensure that mips16_globals remains null after
20583 a PCH load. */
20584 mips_set_compression_mode (0);
20585 mips16_globals = 0;
20588 /* Generate or test for an insn that supports a constant permutation. */
20590 #define MAX_VECT_LEN 16
20592 struct expand_vec_perm_d
20594 rtx target, op0, op1;
20595 unsigned char perm[MAX_VECT_LEN];
20596 machine_mode vmode;
20597 unsigned char nelt;
20598 bool one_vector_p;
20599 bool testing_p;
20602 /* Construct (set target (vec_select op0 (parallel perm))) and
20603 return true if that's a valid instruction in the active ISA. */
20605 static bool
20606 mips_expand_vselect (rtx target, rtx op0,
20607 const unsigned char *perm, unsigned nelt)
20609 rtx rperm[MAX_VECT_LEN], x;
20610 unsigned i;
20612 for (i = 0; i < nelt; ++i)
20613 rperm[i] = GEN_INT (perm[i]);
20615 x = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, rperm));
20616 x = gen_rtx_VEC_SELECT (GET_MODE (target), op0, x);
20617 x = gen_rtx_SET (VOIDmode, target, x);
20619 x = emit_insn (x);
20620 if (recog_memoized (x) < 0)
20622 remove_insn (x);
20623 return false;
20625 return true;
20628 /* Similar, but generate a vec_concat from op0 and op1 as well. */
20630 static bool
20631 mips_expand_vselect_vconcat (rtx target, rtx op0, rtx op1,
20632 const unsigned char *perm, unsigned nelt)
20634 machine_mode v2mode;
20635 rtx x;
20637 v2mode = GET_MODE_2XWIDER_MODE (GET_MODE (op0));
20638 x = gen_rtx_VEC_CONCAT (v2mode, op0, op1);
20639 return mips_expand_vselect (target, x, perm, nelt);
20642 /* Recognize patterns for even-odd extraction. */
20644 static bool
20645 mips_expand_vpc_loongson_even_odd (struct expand_vec_perm_d *d)
20647 unsigned i, odd, nelt = d->nelt;
20648 rtx t0, t1, t2, t3;
20650 if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS))
20651 return false;
20652 /* Even-odd for V2SI/V2SFmode is matched by interleave directly. */
20653 if (nelt < 4)
20654 return false;
20656 odd = d->perm[0];
20657 if (odd > 1)
20658 return false;
20659 for (i = 1; i < nelt; ++i)
20660 if (d->perm[i] != i * 2 + odd)
20661 return false;
20663 if (d->testing_p)
20664 return true;
20666 /* We need 2*log2(N)-1 operations to achieve odd/even with interleave. */
20667 t0 = gen_reg_rtx (d->vmode);
20668 t1 = gen_reg_rtx (d->vmode);
20669 switch (d->vmode)
20671 case V4HImode:
20672 emit_insn (gen_loongson_punpckhhw (t0, d->op0, d->op1));
20673 emit_insn (gen_loongson_punpcklhw (t1, d->op0, d->op1));
20674 if (odd)
20675 emit_insn (gen_loongson_punpckhhw (d->target, t1, t0));
20676 else
20677 emit_insn (gen_loongson_punpcklhw (d->target, t1, t0));
20678 break;
20680 case V8QImode:
20681 t2 = gen_reg_rtx (d->vmode);
20682 t3 = gen_reg_rtx (d->vmode);
20683 emit_insn (gen_loongson_punpckhbh (t0, d->op0, d->op1));
20684 emit_insn (gen_loongson_punpcklbh (t1, d->op0, d->op1));
20685 emit_insn (gen_loongson_punpckhbh (t2, t1, t0));
20686 emit_insn (gen_loongson_punpcklbh (t3, t1, t0));
20687 if (odd)
20688 emit_insn (gen_loongson_punpckhbh (d->target, t3, t2));
20689 else
20690 emit_insn (gen_loongson_punpcklbh (d->target, t3, t2));
20691 break;
20693 default:
20694 gcc_unreachable ();
20696 return true;
20699 /* Recognize patterns for the Loongson PSHUFH instruction. */
20701 static bool
20702 mips_expand_vpc_loongson_pshufh (struct expand_vec_perm_d *d)
20704 unsigned i, mask;
20705 rtx rmask;
20707 if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS))
20708 return false;
20709 if (d->vmode != V4HImode)
20710 return false;
20711 if (d->testing_p)
20712 return true;
20714 /* Convert the selector into the packed 8-bit form for pshufh. */
20715 /* Recall that loongson is little-endian only. No big-endian
20716 adjustment required. */
20717 for (i = mask = 0; i < 4; i++)
20718 mask |= (d->perm[i] & 3) << (i * 2);
20719 rmask = force_reg (SImode, GEN_INT (mask));
20721 if (d->one_vector_p)
20722 emit_insn (gen_loongson_pshufh (d->target, d->op0, rmask));
20723 else
20725 rtx t0, t1, x, merge, rmerge[4];
20727 t0 = gen_reg_rtx (V4HImode);
20728 t1 = gen_reg_rtx (V4HImode);
20729 emit_insn (gen_loongson_pshufh (t1, d->op1, rmask));
20730 emit_insn (gen_loongson_pshufh (t0, d->op0, rmask));
20732 for (i = 0; i < 4; ++i)
20733 rmerge[i] = (d->perm[i] & 4 ? constm1_rtx : const0_rtx);
20734 merge = gen_rtx_CONST_VECTOR (V4HImode, gen_rtvec_v (4, rmerge));
20735 merge = force_reg (V4HImode, merge);
20737 x = gen_rtx_AND (V4HImode, merge, t1);
20738 emit_insn (gen_rtx_SET (VOIDmode, t1, x));
20740 x = gen_rtx_NOT (V4HImode, merge);
20741 x = gen_rtx_AND (V4HImode, x, t0);
20742 emit_insn (gen_rtx_SET (VOIDmode, t0, x));
20744 x = gen_rtx_IOR (V4HImode, t0, t1);
20745 emit_insn (gen_rtx_SET (VOIDmode, d->target, x));
20748 return true;
20751 /* Recognize broadcast patterns for the Loongson. */
20753 static bool
20754 mips_expand_vpc_loongson_bcast (struct expand_vec_perm_d *d)
20756 unsigned i, elt;
20757 rtx t0, t1;
20759 if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS))
20760 return false;
20761 /* Note that we've already matched V2SI via punpck and V4HI via pshufh. */
20762 if (d->vmode != V8QImode)
20763 return false;
20764 if (!d->one_vector_p)
20765 return false;
20767 elt = d->perm[0];
20768 for (i = 1; i < 8; ++i)
20769 if (d->perm[i] != elt)
20770 return false;
20772 if (d->testing_p)
20773 return true;
20775 /* With one interleave we put two of the desired element adjacent. */
20776 t0 = gen_reg_rtx (V8QImode);
20777 if (elt < 4)
20778 emit_insn (gen_loongson_punpcklbh (t0, d->op0, d->op0));
20779 else
20780 emit_insn (gen_loongson_punpckhbh (t0, d->op0, d->op0));
20782 /* Shuffle that one HImode element into all locations. */
20783 elt &= 3;
20784 elt *= 0x55;
20785 t1 = gen_reg_rtx (V4HImode);
20786 emit_insn (gen_loongson_pshufh (t1, gen_lowpart (V4HImode, t0),
20787 force_reg (SImode, GEN_INT (elt))));
20789 emit_move_insn (d->target, gen_lowpart (V8QImode, t1));
20790 return true;
20793 static bool
20794 mips_expand_vec_perm_const_1 (struct expand_vec_perm_d *d)
20796 unsigned int i, nelt = d->nelt;
20797 unsigned char perm2[MAX_VECT_LEN];
20799 if (d->one_vector_p)
20801 /* Try interleave with alternating operands. */
20802 memcpy (perm2, d->perm, sizeof(perm2));
20803 for (i = 1; i < nelt; i += 2)
20804 perm2[i] += nelt;
20805 if (mips_expand_vselect_vconcat (d->target, d->op0, d->op1, perm2, nelt))
20806 return true;
20808 else
20810 if (mips_expand_vselect_vconcat (d->target, d->op0, d->op1,
20811 d->perm, nelt))
20812 return true;
20814 /* Try again with swapped operands. */
20815 for (i = 0; i < nelt; ++i)
20816 perm2[i] = (d->perm[i] + nelt) & (2 * nelt - 1);
20817 if (mips_expand_vselect_vconcat (d->target, d->op1, d->op0, perm2, nelt))
20818 return true;
20821 if (mips_expand_vpc_loongson_even_odd (d))
20822 return true;
20823 if (mips_expand_vpc_loongson_pshufh (d))
20824 return true;
20825 if (mips_expand_vpc_loongson_bcast (d))
20826 return true;
20827 return false;
20830 /* Expand a vec_perm_const pattern. */
20832 bool
20833 mips_expand_vec_perm_const (rtx operands[4])
20835 struct expand_vec_perm_d d;
20836 int i, nelt, which;
20837 unsigned char orig_perm[MAX_VECT_LEN];
20838 rtx sel;
20839 bool ok;
20841 d.target = operands[0];
20842 d.op0 = operands[1];
20843 d.op1 = operands[2];
20844 sel = operands[3];
20846 d.vmode = GET_MODE (d.target);
20847 gcc_assert (VECTOR_MODE_P (d.vmode));
20848 d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
20849 d.testing_p = false;
20851 for (i = which = 0; i < nelt; ++i)
20853 rtx e = XVECEXP (sel, 0, i);
20854 int ei = INTVAL (e) & (2 * nelt - 1);
20855 which |= (ei < nelt ? 1 : 2);
20856 orig_perm[i] = ei;
20858 memcpy (d.perm, orig_perm, MAX_VECT_LEN);
20860 switch (which)
20862 default:
20863 gcc_unreachable();
20865 case 3:
20866 d.one_vector_p = false;
20867 if (!rtx_equal_p (d.op0, d.op1))
20868 break;
20869 /* FALLTHRU */
20871 case 2:
20872 for (i = 0; i < nelt; ++i)
20873 d.perm[i] &= nelt - 1;
20874 d.op0 = d.op1;
20875 d.one_vector_p = true;
20876 break;
20878 case 1:
20879 d.op1 = d.op0;
20880 d.one_vector_p = true;
20881 break;
20884 ok = mips_expand_vec_perm_const_1 (&d);
20886 /* If we were given a two-vector permutation which just happened to
20887 have both input vectors equal, we folded this into a one-vector
20888 permutation. There are several loongson patterns that are matched
20889 via direct vec_select+vec_concat expansion, but we do not have
20890 support in mips_expand_vec_perm_const_1 to guess the adjustment
20891 that should be made for a single operand. Just try again with
20892 the original permutation. */
20893 if (!ok && which == 3)
20895 d.op0 = operands[1];
20896 d.op1 = operands[2];
20897 d.one_vector_p = false;
20898 memcpy (d.perm, orig_perm, MAX_VECT_LEN);
20899 ok = mips_expand_vec_perm_const_1 (&d);
20902 return ok;
20905 /* Implement TARGET_SCHED_REASSOCIATION_WIDTH. */
20907 static int
20908 mips_sched_reassociation_width (unsigned int opc ATTRIBUTE_UNUSED,
20909 machine_mode mode)
20911 if (MSA_SUPPORTED_MODE_P (mode))
20912 return 2;
20913 return 1;
20916 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST_OK. */
20918 static bool
20919 mips_vectorize_vec_perm_const_ok (machine_mode vmode,
20920 const unsigned char *sel)
20922 struct expand_vec_perm_d d;
20923 unsigned int i, nelt, which;
20924 bool ret;
20926 d.vmode = vmode;
20927 d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
20928 d.testing_p = true;
20929 memcpy (d.perm, sel, nelt);
20931 /* Categorize the set of elements in the selector. */
20932 for (i = which = 0; i < nelt; ++i)
20934 unsigned char e = d.perm[i];
20935 gcc_assert (e < 2 * nelt);
20936 which |= (e < nelt ? 1 : 2);
20939 /* For all elements from second vector, fold the elements to first. */
20940 if (which == 2)
20941 for (i = 0; i < nelt; ++i)
20942 d.perm[i] -= nelt;
20944 /* Check whether the mask can be applied to the vector type. */
20945 d.one_vector_p = (which != 3);
20947 d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1);
20948 d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2);
20949 if (!d.one_vector_p)
20950 d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3);
20952 start_sequence ();
20953 ret = mips_expand_vec_perm_const_1 (&d);
20954 end_sequence ();
20956 return ret;
20959 /* Expand an integral vector unpack operation. */
20961 void
20962 mips_expand_vec_unpack (rtx operands[2], bool unsigned_p, bool high_p)
20964 machine_mode imode = GET_MODE (operands[1]);
20965 rtx (*unpack) (rtx, rtx, rtx);
20966 rtx (*cmpFunc) (rtx, rtx, rtx);
20967 rtx tmp, dest, zero;
20969 if (ISA_HAS_MSA)
20971 switch (imode)
20973 case V4SImode:
20974 if (BYTES_BIG_ENDIAN != high_p)
20975 unpack = gen_msa_ilvl_w;
20976 else
20977 unpack = gen_msa_ilvr_w;
20979 cmpFunc = gen_msa_clti_si_w;
20980 break;
20982 case V8HImode:
20983 if (BYTES_BIG_ENDIAN != high_p)
20984 unpack = gen_msa_ilvl_h;
20985 else
20986 unpack = gen_msa_ilvr_h;
20988 cmpFunc = gen_msa_clti_si_h;
20989 break;
20991 case V16QImode:
20992 if (BYTES_BIG_ENDIAN != high_p)
20993 unpack = gen_msa_ilvl_b;
20994 else
20995 unpack = gen_msa_ilvr_b;
20997 cmpFunc = gen_msa_clti_si_b;
20998 break;
21000 default:
21001 gcc_unreachable ();
21002 break;
21005 if (!unsigned_p)
21007 /* Extract sign extention for each element comparing each element with
21008 immediate zero. */
21009 tmp = gen_reg_rtx (imode);
21010 emit_insn (cmpFunc (tmp, operands[1], CONST0_RTX (imode)));
21012 else
21014 tmp = force_reg (imode, CONST0_RTX (imode));
21017 dest = gen_reg_rtx (imode);
21019 emit_insn (unpack (dest, tmp, operands[1]));
21020 emit_move_insn (operands[0], gen_lowpart (GET_MODE (operands[0]), dest));
21021 return;
21024 switch (imode)
21026 case V8QImode:
21027 if (high_p)
21028 unpack = gen_loongson_punpckhbh;
21029 else
21030 unpack = gen_loongson_punpcklbh;
21031 cmpFunc = gen_loongson_pcmpgtb;
21032 break;
21033 case V4HImode:
21034 if (high_p)
21035 unpack = gen_loongson_punpckhhw;
21036 else
21037 unpack = gen_loongson_punpcklhw;
21038 cmpFunc = gen_loongson_pcmpgth;
21039 break;
21040 default:
21041 gcc_unreachable ();
21044 zero = force_reg (imode, CONST0_RTX (imode));
21045 if (unsigned_p)
21046 tmp = zero;
21047 else
21049 tmp = gen_reg_rtx (imode);
21050 emit_insn (cmpFunc (tmp, zero, operands[1]));
21053 dest = gen_reg_rtx (imode);
21054 emit_insn (unpack (dest, operands[1], tmp));
21056 emit_move_insn (operands[0], gen_lowpart (GET_MODE (operands[0]), dest));
21059 /* A subroutine of mips_expand_vec_init, match constant vector elements. */
21061 static inline bool
21062 mips_constant_elt_p (rtx x)
21064 return CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE;
21067 /* A subroutine of mips_expand_vec_init, expand via broadcast. */
21069 static void
21070 mips_expand_vi_broadcast (machine_mode vmode, rtx target, rtx elt)
21072 struct expand_vec_perm_d d;
21073 rtx t1;
21074 bool ok;
21076 if (elt != const0_rtx)
21077 elt = force_reg (GET_MODE_INNER (vmode), elt);
21078 if (REG_P (elt))
21079 elt = gen_lowpart (DImode, elt);
21081 t1 = gen_reg_rtx (vmode);
21082 switch (vmode)
21084 case V8QImode:
21085 emit_insn (gen_loongson_vec_init1_v8qi (t1, elt));
21086 break;
21087 case V4HImode:
21088 emit_insn (gen_loongson_vec_init1_v4hi (t1, elt));
21089 break;
21090 default:
21091 gcc_unreachable ();
21094 memset (&d, 0, sizeof (d));
21095 d.target = target;
21096 d.op0 = t1;
21097 d.op1 = t1;
21098 d.vmode = vmode;
21099 d.nelt = GET_MODE_NUNITS (vmode);
21100 d.one_vector_p = true;
21102 ok = mips_expand_vec_perm_const_1 (&d);
21103 gcc_assert (ok);
21106 /* A subroutine of mips_expand_vec_init, replacing all of the non-constant
21107 elements of VALS with zeros, copy the constant vector to TARGET. */
21109 static void
21110 mips_expand_vi_constant (machine_mode vmode, unsigned nelt,
21111 rtx target, rtx vals)
21113 rtvec vec = shallow_copy_rtvec (XVEC (vals, 0));
21114 unsigned i;
21116 for (i = 0; i < nelt; ++i)
21118 rtx elem = RTVEC_ELT (vec, i);
21119 if (!mips_constant_elt_p (elem))
21120 RTVEC_ELT (vec, i) = CONST0_RTX (GET_MODE (elem));
21123 emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, vec));
21127 /* A subroutine of mips_expand_vec_init, expand via pinsrh. */
21129 static void
21130 mips_expand_vi_loongson_one_pinsrh (rtx target, rtx vals, unsigned one_var)
21132 mips_expand_vi_constant (V4HImode, 4, target, vals);
21134 emit_insn (gen_vec_setv4hi (target, target, XVECEXP (vals, 0, one_var),
21135 GEN_INT (one_var)));
21138 /* A subroutine of mips_expand_vec_init, expand anything via memory. */
21140 static void
21141 mips_expand_vi_general (machine_mode vmode, machine_mode imode,
21142 unsigned nelt, unsigned nvar, rtx target, rtx vals)
21144 rtx mem = assign_stack_temp (vmode, GET_MODE_SIZE (vmode));
21145 unsigned int i, isize = GET_MODE_SIZE (imode);
21147 if (nvar < nelt)
21148 mips_expand_vi_constant (vmode, nelt, mem, vals);
21150 for (i = 0; i < nelt; ++i)
21152 rtx x = XVECEXP (vals, 0, i);
21153 if (!mips_constant_elt_p (x))
21154 emit_move_insn (adjust_address (mem, imode, i * isize), x);
21157 emit_move_insn (target, mem);
21160 /* Expand a vector initialization. */
21162 void
21163 mips_expand_vector_init (rtx target, rtx vals)
21165 machine_mode vmode = GET_MODE (target);
21166 machine_mode imode = GET_MODE_INNER (vmode);
21167 unsigned i, nelt = GET_MODE_NUNITS (vmode);
21168 unsigned nvar = 0, one_var = -1u;
21169 bool all_same = true;
21170 rtx x;
21172 for (i = 0; i < nelt; ++i)
21174 x = XVECEXP (vals, 0, i);
21175 if (!mips_constant_elt_p (x))
21176 nvar++, one_var = i;
21177 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
21178 all_same = false;
21181 if (TARGET_MSA)
21183 if (all_same)
21185 rtx same = XVECEXP (vals, 0, 0);
21186 rtx temp, temp2;
21188 if (CONST_INT_P (same) && nvar == 0 && mips_signed_immediate_p (INTVAL (same), 10, 0))
21190 switch (vmode)
21192 case V16QImode:
21193 emit_insn (gen_msa_ldiv16qi (target, same));
21194 return;
21196 case V8HImode:
21197 emit_insn (gen_msa_ldiv8hi (target, same));
21198 return;
21200 case V4SImode:
21201 emit_insn (gen_msa_ldiv4si (target, same));
21202 return;
21204 case V2DImode:
21205 emit_insn (gen_msa_ldiv2di (target, same));
21206 return;
21208 default:
21209 break;
21212 temp = gen_reg_rtx (imode);
21213 if (imode == GET_MODE (same))
21214 temp2 = same;
21215 else if (GET_MODE_SIZE (imode) >= UNITS_PER_WORD)
21216 temp2 = simplify_gen_subreg (imode, same, GET_MODE (same), 0);
21217 else
21219 unsigned offset = 0;
21221 if (TARGET_BIG_ENDIAN)
21222 offset = GET_MODE_SIZE (GET_MODE (same)) - GET_MODE_SIZE (imode);
21223 temp2 = simplify_gen_subreg (imode, same, GET_MODE (same), offset);
21225 emit_move_insn (temp, temp2);
21227 switch (vmode)
21229 case V16QImode:
21230 emit_insn (gen_msa_fill_b_insn (target, temp));
21231 break;
21233 case V8HImode:
21234 emit_insn (gen_msa_fill_h_insn (target, temp));
21235 break;
21237 case V4SImode:
21238 emit_insn (gen_msa_fill_w (target, temp));
21239 break;
21241 case V2DImode:
21242 emit_insn (gen_msa_fill_d (target, temp));
21243 break;
21245 case V4SFmode:
21246 emit_insn (gen_msa_splati_w_f_s (target, temp, const0_rtx));
21247 break;
21249 case V2DFmode:
21250 emit_insn (gen_msa_splati_d_f_s (target, temp, const0_rtx));
21251 break;
21253 default:
21254 gcc_unreachable ();
21257 return;
21259 rtvec vec = shallow_copy_rtvec (XVEC (vals, 0));
21261 for (i = 0; i < nelt; ++i)
21262 RTVEC_ELT (vec, i) = CONST0_RTX (imode);
21264 emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, vec));
21266 for (i = 0; i < nelt; ++i)
21268 rtx temp = gen_reg_rtx (imode);
21269 emit_move_insn (temp, XVECEXP (vals, 0, i));
21270 switch (vmode)
21272 case V16QImode:
21273 emit_insn (gen_vec_setv16qi (target, temp, GEN_INT (i)));
21274 break;
21276 case V8HImode:
21277 emit_insn (gen_vec_setv8hi (target, temp, GEN_INT (i)));
21278 break;
21280 case V4SImode:
21281 emit_insn (gen_vec_setv4si (target, temp, GEN_INT (i)));
21282 break;
21284 case V2DImode:
21285 emit_insn (gen_vec_setv2di (target, temp, GEN_INT (i)));
21286 break;
21288 case V4SFmode:
21289 emit_insn (gen_vec_setv4sf (target, temp, GEN_INT (i)));
21290 break;
21292 case V2DFmode:
21293 emit_insn (gen_vec_setv2df (target, temp, GEN_INT (i)));
21294 break;
21296 default:
21297 gcc_unreachable ();
21301 return;
21304 /* Load constants from the pool, or whatever's handy. */
21305 if (nvar == 0)
21307 emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, XVEC (vals, 0)));
21308 return;
21311 /* For two-part initialization, always use CONCAT. */
21312 if (nelt == 2)
21314 rtx op0 = force_reg (imode, XVECEXP (vals, 0, 0));
21315 rtx op1 = force_reg (imode, XVECEXP (vals, 0, 1));
21316 x = gen_rtx_VEC_CONCAT (vmode, op0, op1);
21317 emit_insn (gen_rtx_SET (VOIDmode, target, x));
21318 return;
21321 /* Loongson is the only cpu with vectors with more elements. */
21322 gcc_assert (TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS);
21324 /* If all values are identical, broadcast the value. */
21325 if (all_same)
21327 mips_expand_vi_broadcast (vmode, target, XVECEXP (vals, 0, 0));
21328 return;
21331 /* If we've only got one non-variable V4HImode, use PINSRH. */
21332 if (nvar == 1 && vmode == V4HImode)
21334 mips_expand_vi_loongson_one_pinsrh (target, vals, one_var);
21335 return;
21338 mips_expand_vi_general (vmode, imode, nelt, nvar, target, vals);
21341 /* Expand a vector reduction. */
21343 void
21344 mips_expand_vec_reduc (rtx target, rtx in, rtx (*gen)(rtx, rtx, rtx))
21346 machine_mode vmode = GET_MODE (in);
21347 unsigned char perm2[2];
21348 rtx last, next, fold, x;
21349 bool ok;
21351 last = in;
21352 fold = gen_reg_rtx (vmode);
21353 switch (vmode)
21355 case V2SFmode:
21356 /* Use PUL/PLU to produce { L, H } op { H, L }.
21357 By reversing the pair order, rather than a pure interleave high,
21358 we avoid erroneous exceptional conditions that we might otherwise
21359 produce from the computation of H op H. */
21360 perm2[0] = 1;
21361 perm2[1] = 2;
21362 ok = mips_expand_vselect_vconcat (fold, last, last, perm2, 2);
21363 gcc_assert (ok);
21364 break;
21366 case V2SImode:
21367 /* Use interleave to produce { H, L } op { H, H }. */
21368 emit_insn (gen_loongson_punpckhwd (fold, last, last));
21369 break;
21371 case V4HImode:
21372 /* Perform the first reduction with interleave,
21373 and subsequent reductions with shifts. */
21374 emit_insn (gen_loongson_punpckhwd_hi (fold, last, last));
21376 next = gen_reg_rtx (vmode);
21377 emit_insn (gen (next, last, fold));
21378 last = next;
21380 fold = gen_reg_rtx (vmode);
21381 x = force_reg (SImode, GEN_INT (16));
21382 emit_insn (gen_vec_shr_v4hi (fold, last, x));
21383 break;
21385 case V8QImode:
21386 emit_insn (gen_loongson_punpckhwd_qi (fold, last, last));
21388 next = gen_reg_rtx (vmode);
21389 emit_insn (gen (next, last, fold));
21390 last = next;
21392 fold = gen_reg_rtx (vmode);
21393 x = force_reg (SImode, GEN_INT (16));
21394 emit_insn (gen_vec_shr_v8qi (fold, last, x));
21396 next = gen_reg_rtx (vmode);
21397 emit_insn (gen (next, last, fold));
21398 last = next;
21400 fold = gen_reg_rtx (vmode);
21401 x = force_reg (SImode, GEN_INT (8));
21402 emit_insn (gen_vec_shr_v8qi (fold, last, x));
21403 break;
21405 default:
21406 gcc_unreachable ();
21409 emit_insn (gen (target, last, fold));
21412 /* Expand a vector minimum/maximum. */
21414 void
21415 mips_expand_vec_minmax (rtx target, rtx op0, rtx op1,
21416 rtx (*cmp) (rtx, rtx, rtx), bool min_p)
21418 machine_mode vmode = GET_MODE (target);
21419 rtx tc, t0, t1, x;
21421 tc = gen_reg_rtx (vmode);
21422 t0 = gen_reg_rtx (vmode);
21423 t1 = gen_reg_rtx (vmode);
21425 /* op0 > op1 */
21426 emit_insn (cmp (tc, op0, op1));
21428 x = gen_rtx_AND (vmode, tc, (min_p ? op1 : op0));
21429 emit_insn (gen_rtx_SET (VOIDmode, t0, x));
21431 x = gen_rtx_NOT (vmode, tc);
21432 x = gen_rtx_AND (vmode, x, (min_p ? op0 : op1));
21433 emit_insn (gen_rtx_SET (VOIDmode, t1, x));
21435 x = gen_rtx_IOR (vmode, t0, t1);
21436 emit_insn (gen_rtx_SET (VOIDmode, target, x));
21439 /* Implement HARD_REGNO_CALLER_SAVE_MODE. */
21441 machine_mode
21442 mips_hard_regno_caller_save_mode (unsigned int regno,
21443 unsigned int nregs,
21444 machine_mode mode)
21446 /* For performance, avoid saving/restoring upper parts of a register
21447 by returning MODE as save mode when the mode is known. */
21448 if (mode == VOIDmode)
21449 return choose_hard_reg_mode (regno, nregs, false);
21450 else
21451 return mode;
21454 static void
21455 mips_expand_msa_one_cmpl (rtx dest, rtx src)
21457 machine_mode mode = GET_MODE (dest);
21458 switch (mode)
21460 case V16QImode:
21461 emit_insn (gen_msa_nor_v_b (dest, src, src));
21462 break;
21463 case V8HImode:
21464 emit_insn (gen_msa_nor_v_h (dest, src, src));
21465 break;
21466 case V4SImode:
21467 emit_insn (gen_msa_nor_v_w (dest, src, src));
21468 break;
21469 case V2DImode:
21470 emit_insn (gen_msa_nor_v_d (dest, src, src));
21471 break;
21472 default:
21473 gcc_unreachable ();
21477 static void
21478 mips_expand_msa_cmp (rtx dest, enum rtx_code cond, rtx op0, rtx op1)
21480 machine_mode cmp_mode = GET_MODE (op0);
21482 switch (cmp_mode)
21484 case V16QImode:
21485 switch (cond)
21487 case EQ:
21488 emit_insn (gen_msa_ceq_b (dest, op0, op1));
21489 break;
21490 case LT:
21491 emit_insn (gen_msa_clt_s_b (dest, op0, op1));
21492 break;
21493 case LE:
21494 emit_insn (gen_msa_cle_s_b (dest, op0, op1));
21495 break;
21496 case LTU:
21497 emit_insn (gen_msa_clt_u_b (dest, op0, op1));
21498 break;
21499 case LEU:
21500 emit_insn (gen_msa_cle_u_b (dest, op0, op1));
21501 break;
21502 case GE: // swap
21503 emit_insn (gen_msa_cle_s_b (dest, op1, op0));
21504 break;
21505 case GT: // swap
21506 emit_insn (gen_msa_clt_s_b (dest, op1, op0));
21507 break;
21508 case GEU: // swap
21509 emit_insn (gen_msa_cle_u_b (dest, op1, op0));
21510 break;
21511 case GTU: // swap
21512 emit_insn (gen_msa_clt_u_b (dest, op1, op0));
21513 break;
21514 default:
21515 gcc_unreachable ();
21517 break;
21519 case V8HImode:
21520 switch (cond)
21522 case EQ:
21523 emit_insn (gen_msa_ceq_h (dest, op0, op1));
21524 break;
21525 case LT:
21526 emit_insn (gen_msa_clt_s_h (dest, op0, op1));
21527 break;
21528 case LE:
21529 emit_insn (gen_msa_cle_s_h (dest, op0, op1));
21530 break;
21531 case LTU:
21532 emit_insn (gen_msa_clt_u_h (dest, op0, op1));
21533 break;
21534 case LEU:
21535 emit_insn (gen_msa_cle_u_h (dest, op0, op1));
21536 break;
21537 case GE: // swap
21538 emit_insn (gen_msa_cle_s_h (dest, op1, op0));
21539 break;
21540 case GT: // swap
21541 emit_insn (gen_msa_clt_s_h (dest, op1, op0));
21542 break;
21543 case GEU: // swap
21544 emit_insn (gen_msa_cle_u_h (dest, op1, op0));
21545 break;
21546 case GTU: // swap
21547 emit_insn (gen_msa_clt_u_h (dest, op1, op0));
21548 break;
21549 default:
21550 gcc_unreachable ();
21552 break;
21554 case V4SImode:
21555 switch (cond)
21557 case EQ:
21558 emit_insn (gen_msa_ceq_w (dest, op0, op1));
21559 break;
21560 case LT:
21561 emit_insn (gen_msa_clt_s_w (dest, op0, op1));
21562 break;
21563 case LE:
21564 emit_insn (gen_msa_cle_s_w (dest, op0, op1));
21565 break;
21566 case LTU:
21567 emit_insn (gen_msa_clt_u_w (dest, op0, op1));
21568 break;
21569 case LEU:
21570 emit_insn (gen_msa_cle_u_w (dest, op0, op1));
21571 break;
21572 case GE: // swap
21573 emit_insn (gen_msa_cle_s_w (dest, op1, op0));
21574 break;
21575 case GT: // swap
21576 emit_insn (gen_msa_clt_s_w (dest, op1, op0));
21577 break;
21578 case GEU: // swap
21579 emit_insn (gen_msa_cle_u_w (dest, op1, op0));
21580 break;
21581 case GTU: // swap
21582 emit_insn (gen_msa_clt_u_w (dest, op1, op0));
21583 break;
21584 default:
21585 gcc_unreachable ();
21587 break;
21589 case V2DImode:
21590 switch (cond)
21592 case EQ:
21593 emit_insn (gen_msa_ceq_d (dest, op0, op1));
21594 break;
21595 case LT:
21596 emit_insn (gen_msa_clt_s_d (dest, op0, op1));
21597 break;
21598 case LE:
21599 emit_insn (gen_msa_cle_s_d (dest, op0, op1));
21600 break;
21601 case LTU:
21602 emit_insn (gen_msa_clt_u_d (dest, op0, op1));
21603 break;
21604 case LEU:
21605 emit_insn (gen_msa_cle_u_d (dest, op0, op1));
21606 break;
21607 case GE: // swap
21608 emit_insn (gen_msa_cle_s_d (dest, op1, op0));
21609 break;
21610 case GT: // swap
21611 emit_insn (gen_msa_clt_s_d (dest, op1, op0));
21612 break;
21613 case GEU: // swap
21614 emit_insn (gen_msa_cle_u_d (dest, op1, op0));
21615 break;
21616 case GTU: // swap
21617 emit_insn (gen_msa_clt_u_d (dest, op1, op0));
21618 break;
21619 default:
21620 gcc_unreachable ();
21622 break;
21624 case V4SFmode:
21625 switch (cond)
21627 case UNORDERED:
21628 emit_insn (gen_msa_fcun_w (dest, op0, op1));
21629 break;
21630 case EQ:
21631 emit_insn (gen_msa_fceq_w (dest, op0, op1));
21632 break;
21633 case NE:
21634 emit_insn (gen_msa_fcne_w (dest, op0, op1));
21635 break;
21636 case LTGT:
21637 emit_insn (gen_msa_fcne_w (dest, op0, op1));
21638 break;
21639 case GT: // use slt, swap op0 and op1
21640 emit_insn (gen_msa_fslt_w (dest, op1, op0));
21641 break;
21642 case GE: // use sle, swap op0 and op1
21643 emit_insn (gen_msa_fsle_w (dest, op1, op0));
21644 break;
21645 case LT: // use slt
21646 emit_insn (gen_msa_fslt_w (dest, op0, op1));
21647 break;
21648 case LE: // use sle
21649 emit_insn (gen_msa_fsle_w (dest, op0, op1));
21650 break;
21651 case UNGE: // use cule, swap op0 and op1
21652 emit_insn (gen_msa_fcule_w (dest, op1, op0));
21653 break;
21654 case UNGT: // use cult, swap op0 and op1
21655 emit_insn (gen_msa_fcult_w (dest, op1, op0));
21656 break;
21657 case UNLE:
21658 emit_insn (gen_msa_fcule_w (dest, op0, op1));
21659 break;
21660 case UNLT:
21661 emit_insn (gen_msa_fcult_w (dest, op0, op1));
21662 break;
21663 default:
21664 gcc_unreachable ();
21666 break;
21668 case V2DFmode:
21669 switch (cond)
21671 case UNORDERED:
21672 emit_insn (gen_msa_fcun_d (dest, op0, op1));
21673 break;
21674 case EQ:
21675 emit_insn (gen_msa_fceq_d (dest, op0, op1));
21676 break;
21677 case NE:
21678 emit_insn (gen_msa_fcne_d (dest, op0, op1));
21679 break;
21680 case LTGT:
21681 emit_insn (gen_msa_fcne_d (dest, op0, op1));
21682 break;
21683 case GT: // use slt, swap op0 and op1
21684 emit_insn (gen_msa_fslt_d (dest, op1, op0));
21685 break;
21686 case GE: // use sle, swap op0 and op1
21687 emit_insn (gen_msa_fsle_d (dest, op1, op0));
21688 break;
21689 case LT: // use slt
21690 emit_insn (gen_msa_fslt_d (dest, op0, op1));
21691 break;
21692 case LE: // use sle
21693 emit_insn (gen_msa_fsle_d (dest, op0, op1));
21694 break;
21695 case UNGE: // use cule, swap op0 and op1
21696 emit_insn (gen_msa_fcule_d (dest, op1, op0));
21697 break;
21698 case UNGT: // use uclt, swap op0 and op1
21699 emit_insn (gen_msa_fcult_d (dest, op1, op0));
21700 break;
21701 case UNLE:
21702 emit_insn (gen_msa_fcule_d (dest, op0, op1));
21703 break;
21704 case UNLT:
21705 emit_insn (gen_msa_fcult_d (dest, op0, op1));
21706 break;
21707 default:
21708 gcc_unreachable ();
21710 break;
21712 default:
21713 gcc_unreachable ();
21714 break;
21718 static bool
21719 mips_msa_reversed_int_cond (enum rtx_code *cond)
21721 switch (*cond)
21723 case NE:
21724 *cond = EQ;
21725 return true;
21727 default:
21728 return false;
21732 static bool
21733 mips_msa_reversed_fp_cond (enum rtx_code *code)
21735 switch (*code)
21737 case ORDERED:
21738 case UNEQ:
21739 *code = reverse_condition_maybe_unordered (*code);
21740 return true;
21742 default:
21743 return false;
21747 /* Generate RTL for comparing CMP_OP0, CMP_ OP1 using condition COND
21748 and store the result -1 or 0 in DEST TRUE_SRC and DEST_SRC
21749 must be -1 and 0 respectively. */
21751 static void
21752 mips_expand_msa_vcond (rtx dest, rtx true_src, rtx false_src,
21753 enum rtx_code cond, rtx cmp_op0, rtx cmp_op1)
21755 machine_mode dest_mode = GET_MODE (dest);
21756 machine_mode cmp_mode = GET_MODE (cmp_op0);
21757 bool reversed_p;
21759 if (FLOAT_MODE_P (cmp_mode))
21760 reversed_p = mips_msa_reversed_fp_cond (&cond);
21761 else
21762 reversed_p = mips_msa_reversed_int_cond (&cond);
21764 mips_expand_msa_cmp (dest, cond, cmp_op0, cmp_op1);
21765 if (reversed_p)
21766 mips_expand_msa_one_cmpl (dest, dest);
21768 /* MSA vcond only produces result -1 and 0 for true and false. */
21769 gcc_assert ((true_src == CONSTM1_RTX (dest_mode))
21770 && (false_src == CONST0_RTX (dest_mode)));
21773 /* Expand VEC_COND_EXPR, where:
21774 MODE is mode of the result
21775 VIMODE equivalent integer mode
21776 OPERANDS operands of VEC_COND_EXPR
21777 gen_msa_and_fn used to generate a VIMODE vector msa AND
21778 gen_msa_nor_fn used to generate a VIMODE vector msa NOR
21779 gen_msa_ior_fn used to generate a VIMODE vector msa AND. */
21781 void
21782 mips_expand_vec_cond_expr (machine_mode mode,
21783 machine_mode vimode,
21784 rtx *operands,
21785 rtx (*gen_msa_and_fn)(rtx, rtx, rtx),
21786 rtx (*gen_msa_nor_fn)(rtx, rtx, rtx),
21787 rtx (*gen_msa_ior_fn)(rtx, rtx, rtx))
21789 rtx true_val = CONSTM1_RTX (vimode);
21790 rtx false_val = CONST0_RTX (vimode);
21792 if (operands[1] == true_val && operands[2] == false_val)
21793 mips_expand_msa_vcond (operands[0], operands[1], operands[2],
21794 GET_CODE (operands[3]), operands[4], operands[5]);
21795 else
21797 rtx res = gen_reg_rtx (vimode);
21798 rtx temp1 = gen_reg_rtx (vimode);
21799 rtx temp2 = gen_reg_rtx (vimode);
21800 rtx xres = gen_reg_rtx (vimode);
21802 mips_expand_msa_vcond (res, true_val, false_val,
21803 GET_CODE (operands[3]), operands[4], operands[5]);
21805 /* This results in a vector result with whose T/F elements having
21806 the value -1 or 0 for (T/F repectively). This result may need
21807 adjusting if needed results operands[]/operands[1] are different. */
21809 /* Adjust True elements to be operand[1]. */
21810 emit_move_insn (xres, res);
21811 if (operands[1] != true_val)
21813 rtx xop1 = operands[1]; /* Assume we can use operands[1]. */
21815 if (mode != vimode)
21817 xop1 = gen_reg_rtx (vimode);
21818 if (GET_CODE (operands[1]) == CONST_VECTOR)
21820 rtx xtemp = gen_reg_rtx (mode);
21821 emit_move_insn (xtemp, operands[1]);
21822 emit_move_insn (xop1,
21823 gen_rtx_SUBREG (vimode, xtemp, 0));
21825 else
21826 emit_move_insn (xop1,
21827 gen_rtx_SUBREG (vimode, operands[1], 0));
21829 else if (GET_CODE (operands[1]) == CONST_VECTOR)
21831 xop1 = gen_reg_rtx (mode);
21832 emit_move_insn (xop1, operands[1]);
21835 emit_insn (gen_msa_and_fn (temp1, xres, xop1));
21837 else
21838 emit_move_insn (temp1, xres);
21840 /* Adjust False elements to be operand[0]. */
21841 emit_insn (gen_msa_nor_fn (temp2, xres, xres));
21842 if (operands[2] != false_val)
21844 rtx xop2 = operands[2]; ; /* Assume we can use operands[2]. */
21846 if (mode != vimode)
21848 xop2 = gen_reg_rtx (vimode);
21849 if (GET_CODE (operands[2]) == CONST_VECTOR)
21851 rtx xtemp = gen_reg_rtx (mode);
21852 emit_move_insn (xtemp, operands[2]);
21853 emit_move_insn (xop2,
21854 gen_rtx_SUBREG (vimode, xtemp, 0));
21856 else
21857 emit_move_insn (xop2,
21858 gen_rtx_SUBREG (vimode, operands[2], 0));
21860 else if (GET_CODE (operands[2]) == CONST_VECTOR)
21862 xop2 = gen_reg_rtx (mode);
21863 emit_move_insn (xop2, operands[2]);
21866 emit_insn (gen_msa_and_fn (temp2, temp2, xop2));
21868 else
21869 emit_insn (gen_msa_and_fn (temp2, temp2, xres));
21871 /* Combine together into result. */
21872 emit_insn (gen_msa_ior_fn (xres, temp1, temp2));
21873 emit_move_insn (operands[0],
21874 gen_rtx_SUBREG (mode, xres, 0));
21878 /* Implement TARGET_CASE_VALUES_THRESHOLD. */
21880 unsigned int
21881 mips_case_values_threshold (void)
21883 /* In MIPS16 mode using a larger case threshold generates smaller code. */
21884 if (TARGET_MIPS16 && optimize_size)
21885 return 10;
21886 else
21887 return default_case_values_threshold ();
21890 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */
21892 static void
21893 mips_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
21895 if (!TARGET_HARD_FLOAT_ABI)
21896 return;
21897 tree exceptions_var = create_tmp_var (MIPS_ATYPE_USI, NULL);
21898 tree fcsr_orig_var = create_tmp_var (MIPS_ATYPE_USI, NULL);
21899 tree fcsr_mod_var = create_tmp_var (MIPS_ATYPE_USI, NULL);
21900 tree get_fcsr = mips_builtin_decls[MIPS_GET_FCSR];
21901 tree set_fcsr = mips_builtin_decls[MIPS_SET_FCSR];
21902 tree get_fcsr_hold_call = build_call_expr (get_fcsr, 0);
21903 tree hold_assign_orig = build2 (MODIFY_EXPR, MIPS_ATYPE_USI,
21904 fcsr_orig_var, get_fcsr_hold_call);
21905 tree hold_mod_val = build2 (BIT_AND_EXPR, MIPS_ATYPE_USI, fcsr_orig_var,
21906 build_int_cst (MIPS_ATYPE_USI, 0xfffff003));
21907 tree hold_assign_mod = build2 (MODIFY_EXPR, MIPS_ATYPE_USI,
21908 fcsr_mod_var, hold_mod_val);
21909 tree set_fcsr_hold_call = build_call_expr (set_fcsr, 1, fcsr_mod_var);
21910 tree hold_all = build2 (COMPOUND_EXPR, MIPS_ATYPE_USI,
21911 hold_assign_orig, hold_assign_mod);
21912 *hold = build2 (COMPOUND_EXPR, void_type_node, hold_all,
21913 set_fcsr_hold_call);
21915 *clear = build_call_expr (set_fcsr, 1, fcsr_mod_var);
21917 tree get_fcsr_update_call = build_call_expr (get_fcsr, 0);
21918 *update = build2 (MODIFY_EXPR, MIPS_ATYPE_USI,
21919 exceptions_var, get_fcsr_update_call);
21920 tree set_fcsr_update_call = build_call_expr (set_fcsr, 1, fcsr_orig_var);
21921 *update = build2 (COMPOUND_EXPR, void_type_node, *update,
21922 set_fcsr_update_call);
21923 tree atomic_feraiseexcept
21924 = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
21925 tree int_exceptions_var = fold_convert (integer_type_node,
21926 exceptions_var);
21927 tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
21928 1, int_exceptions_var);
21929 *update = build2 (COMPOUND_EXPR, void_type_node, *update,
21930 atomic_feraiseexcept_call);
21933 /* Implement TARGET_SPILL_CLASS. */
21935 static reg_class_t
21936 mips_spill_class (reg_class_t rclass ATTRIBUTE_UNUSED,
21937 machine_mode mode ATTRIBUTE_UNUSED)
21939 if (TARGET_MIPS16)
21940 return SPILL_REGS;
21941 return NO_REGS;
21944 /* Implement TARGET_LRA_P. */
21946 static bool
21947 mips_lra_p (void)
21949 return mips_lra_flag;
21952 /* Initialize the GCC target structure. */
21953 #undef TARGET_ASM_ALIGNED_HI_OP
21954 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
21955 #undef TARGET_ASM_ALIGNED_SI_OP
21956 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
21957 #undef TARGET_ASM_ALIGNED_DI_OP
21958 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t"
21960 #undef TARGET_OPTION_OVERRIDE
21961 #define TARGET_OPTION_OVERRIDE mips_option_override
21963 #undef TARGET_LEGITIMIZE_ADDRESS
21964 #define TARGET_LEGITIMIZE_ADDRESS mips_legitimize_address
21966 #undef TARGET_ASM_FUNCTION_PROLOGUE
21967 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue
21968 #undef TARGET_ASM_FUNCTION_EPILOGUE
21969 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue
21970 #undef TARGET_ASM_SELECT_RTX_SECTION
21971 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section
21972 #undef TARGET_ASM_FUNCTION_RODATA_SECTION
21973 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section
21975 #undef TARGET_SCHED_INIT
21976 #define TARGET_SCHED_INIT mips_sched_init
21977 #undef TARGET_SCHED_REORDER
21978 #define TARGET_SCHED_REORDER mips_sched_reorder
21979 #undef TARGET_SCHED_REORDER2
21980 #define TARGET_SCHED_REORDER2 mips_sched_reorder2
21981 #undef TARGET_SCHED_VARIABLE_ISSUE
21982 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue
21983 #undef TARGET_SCHED_ADJUST_COST
21984 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost
21985 #undef TARGET_SCHED_ISSUE_RATE
21986 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate
21987 #undef TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN
21988 #define TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN mips_init_dfa_post_cycle_insn
21989 #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE
21990 #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE mips_dfa_post_advance_cycle
21991 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
21992 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
21993 mips_multipass_dfa_lookahead
21994 #undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P
21995 #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P \
21996 mips_small_register_classes_for_mode_p
21998 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
21999 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall
22001 #undef TARGET_INSERT_ATTRIBUTES
22002 #define TARGET_INSERT_ATTRIBUTES mips_insert_attributes
22003 #undef TARGET_MERGE_DECL_ATTRIBUTES
22004 #define TARGET_MERGE_DECL_ATTRIBUTES mips_merge_decl_attributes
22005 #undef TARGET_CAN_INLINE_P
22006 #define TARGET_CAN_INLINE_P mips_can_inline_p
22007 #undef TARGET_SET_CURRENT_FUNCTION
22008 #define TARGET_SET_CURRENT_FUNCTION mips_set_current_function
22010 #undef TARGET_VALID_POINTER_MODE
22011 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
22012 #undef TARGET_REGISTER_MOVE_COST
22013 #define TARGET_REGISTER_MOVE_COST mips_register_move_cost
22014 #undef TARGET_REGISTER_PRIORITY
22015 #define TARGET_REGISTER_PRIORITY mips_register_priority
22016 #undef TARGET_MEMORY_MOVE_COST
22017 #define TARGET_MEMORY_MOVE_COST mips_memory_move_cost
22018 #undef TARGET_RTX_COSTS
22019 #define TARGET_RTX_COSTS mips_rtx_costs
22020 #undef TARGET_ADDRESS_COST
22021 #define TARGET_ADDRESS_COST mips_address_cost
22023 #undef TARGET_IN_SMALL_DATA_P
22024 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p
22026 #undef TARGET_MACHINE_DEPENDENT_REORG
22027 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg
22029 #undef TARGET_PREFERRED_RELOAD_CLASS
22030 #define TARGET_PREFERRED_RELOAD_CLASS mips_preferred_reload_class
22032 #undef TARGET_EXPAND_TO_RTL_HOOK
22033 #define TARGET_EXPAND_TO_RTL_HOOK mips_expand_to_rtl_hook
22034 #undef TARGET_ASM_FILE_START
22035 #define TARGET_ASM_FILE_START mips_file_start
22036 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
22037 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
22038 #undef TARGET_ASM_CODE_END
22039 #define TARGET_ASM_CODE_END mips_code_end
22041 #undef TARGET_INIT_LIBFUNCS
22042 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs
22044 #undef TARGET_BUILD_BUILTIN_VA_LIST
22045 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list
22046 #undef TARGET_EXPAND_BUILTIN_VA_START
22047 #define TARGET_EXPAND_BUILTIN_VA_START mips_va_start
22048 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
22049 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr
22051 #undef TARGET_PROMOTE_FUNCTION_MODE
22052 #define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote
22053 #undef TARGET_PROMOTE_PROTOTYPES
22054 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
22056 #undef TARGET_FUNCTION_VALUE
22057 #define TARGET_FUNCTION_VALUE mips_function_value
22058 #undef TARGET_LIBCALL_VALUE
22059 #define TARGET_LIBCALL_VALUE mips_libcall_value
22060 #undef TARGET_FUNCTION_VALUE_REGNO_P
22061 #define TARGET_FUNCTION_VALUE_REGNO_P mips_function_value_regno_p
22062 #undef TARGET_RETURN_IN_MEMORY
22063 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory
22064 #undef TARGET_RETURN_IN_MSB
22065 #define TARGET_RETURN_IN_MSB mips_return_in_msb
22067 #undef TARGET_ASM_OUTPUT_MI_THUNK
22068 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk
22069 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
22070 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
22072 #undef TARGET_PRINT_OPERAND
22073 #define TARGET_PRINT_OPERAND mips_print_operand
22074 #undef TARGET_PRINT_OPERAND_ADDRESS
22075 #define TARGET_PRINT_OPERAND_ADDRESS mips_print_operand_address
22076 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
22077 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mips_print_operand_punct_valid_p
22079 #undef TARGET_SETUP_INCOMING_VARARGS
22080 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs
22081 #undef TARGET_STRICT_ARGUMENT_NAMING
22082 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming
22083 #undef TARGET_MUST_PASS_IN_STACK
22084 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size
22085 #undef TARGET_PASS_BY_REFERENCE
22086 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference
22087 #undef TARGET_CALLEE_COPIES
22088 #define TARGET_CALLEE_COPIES mips_callee_copies
22089 #undef TARGET_ARG_PARTIAL_BYTES
22090 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes
22091 #undef TARGET_FUNCTION_ARG
22092 #define TARGET_FUNCTION_ARG mips_function_arg
22093 #undef TARGET_FUNCTION_ARG_ADVANCE
22094 #define TARGET_FUNCTION_ARG_ADVANCE mips_function_arg_advance
22095 #undef TARGET_FUNCTION_ARG_BOUNDARY
22096 #define TARGET_FUNCTION_ARG_BOUNDARY mips_function_arg_boundary
22097 #undef TARGET_GET_RAW_RESULT_MODE
22098 #define TARGET_GET_RAW_RESULT_MODE mips_get_reg_raw_mode
22099 #undef TARGET_GET_RAW_ARG_MODE
22100 #define TARGET_GET_RAW_ARG_MODE mips_get_reg_raw_mode
22102 #undef TARGET_MODE_REP_EXTENDED
22103 #define TARGET_MODE_REP_EXTENDED mips_mode_rep_extended
22105 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
22106 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
22107 mips_builtin_vectorized_function
22108 #undef TARGET_VECTOR_MODE_SUPPORTED_P
22109 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p
22111 #undef TARGET_SCALAR_MODE_SUPPORTED_P
22112 #define TARGET_SCALAR_MODE_SUPPORTED_P mips_scalar_mode_supported_p
22114 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
22115 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE mips_preferred_simd_mode
22116 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
22117 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
22118 mips_autovectorize_vector_sizes
22120 #undef TARGET_INIT_BUILTINS
22121 #define TARGET_INIT_BUILTINS mips_init_builtins
22122 #undef TARGET_BUILTIN_DECL
22123 #define TARGET_BUILTIN_DECL mips_builtin_decl
22124 #undef TARGET_EXPAND_BUILTIN
22125 #define TARGET_EXPAND_BUILTIN mips_expand_builtin
22127 #undef TARGET_HAVE_TLS
22128 #define TARGET_HAVE_TLS HAVE_AS_TLS
22130 #undef TARGET_CANNOT_FORCE_CONST_MEM
22131 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem
22133 #undef TARGET_LEGITIMATE_CONSTANT_P
22134 #define TARGET_LEGITIMATE_CONSTANT_P mips_legitimate_constant_p
22136 #undef TARGET_ENCODE_SECTION_INFO
22137 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
22139 #undef TARGET_ATTRIBUTE_TABLE
22140 #define TARGET_ATTRIBUTE_TABLE mips_attribute_table
22141 /* All our function attributes are related to how out-of-line copies should
22142 be compiled or called. They don't in themselves prevent inlining. */
22143 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
22144 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
22146 #undef TARGET_EXTRA_LIVE_ON_ENTRY
22147 #define TARGET_EXTRA_LIVE_ON_ENTRY mips_extra_live_on_entry
22149 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
22150 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P mips_use_blocks_for_constant_p
22151 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P
22152 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P mips_use_anchors_for_symbol_p
22154 #undef TARGET_COMP_TYPE_ATTRIBUTES
22155 #define TARGET_COMP_TYPE_ATTRIBUTES mips_comp_type_attributes
22157 #ifdef HAVE_AS_DTPRELWORD
22158 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
22159 #define TARGET_ASM_OUTPUT_DWARF_DTPREL mips_output_dwarf_dtprel
22160 #endif
22161 #undef TARGET_DWARF_REGISTER_SPAN
22162 #define TARGET_DWARF_REGISTER_SPAN mips_dwarf_register_span
22163 #undef TARGET_DWARF_FRAME_REG_MODE
22164 #define TARGET_DWARF_FRAME_REG_MODE mips_dwarf_frame_reg_mode
22166 #undef TARGET_ASM_FINAL_POSTSCAN_INSN
22167 #define TARGET_ASM_FINAL_POSTSCAN_INSN mips_final_postscan_insn
22169 #undef TARGET_LEGITIMATE_ADDRESS_P
22170 #define TARGET_LEGITIMATE_ADDRESS_P mips_legitimate_address_p
22172 #undef TARGET_FRAME_POINTER_REQUIRED
22173 #define TARGET_FRAME_POINTER_REQUIRED mips_frame_pointer_required
22175 #undef TARGET_CAN_ELIMINATE
22176 #define TARGET_CAN_ELIMINATE mips_can_eliminate
22178 #undef TARGET_CONDITIONAL_REGISTER_USAGE
22179 #define TARGET_CONDITIONAL_REGISTER_USAGE mips_conditional_register_usage
22181 #undef TARGET_TRAMPOLINE_INIT
22182 #define TARGET_TRAMPOLINE_INIT mips_trampoline_init
22184 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME
22185 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mips_output_filename
22187 #undef TARGET_SHIFT_TRUNCATION_MASK
22188 #define TARGET_SHIFT_TRUNCATION_MASK mips_shift_truncation_mask
22190 #undef TARGET_PREPARE_PCH_SAVE
22191 #define TARGET_PREPARE_PCH_SAVE mips_prepare_pch_save
22193 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
22194 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK mips_vectorize_vec_perm_const_ok
22196 #undef TARGET_SCHED_REASSOCIATION_WIDTH
22197 #define TARGET_SCHED_REASSOCIATION_WIDTH mips_sched_reassociation_width
22199 #undef TARGET_CASE_VALUES_THRESHOLD
22200 #define TARGET_CASE_VALUES_THRESHOLD mips_case_values_threshold
22202 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
22203 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV mips_atomic_assign_expand_fenv
22205 #undef TARGET_SPILL_CLASS
22206 #define TARGET_SPILL_CLASS mips_spill_class
22207 #undef TARGET_LRA_P
22208 #define TARGET_LRA_P mips_lra_p
22210 #undef TARGET_SCHED_INIT_GLOBAL
22211 #define TARGET_SCHED_INIT_GLOBAL mips_sched_init_global
22213 #undef TARGET_SCHED_FINISH_GLOBAL
22214 #define TARGET_SCHED_FINISH_GLOBAL mips_sched_finish_global
22216 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
22217 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK mips_evaluation_hook
22219 #undef TARGET_SCHED_SET_SCHED_FLAGS
22220 #define TARGET_SCHED_SET_SCHED_FLAGS mips_set_sched_flags
22222 struct gcc_target targetm = TARGET_INITIALIZER;
22224 #include "gt-mips.h"