1 /* Subroutines used for MIPS code generation. 2 Copyright (C) 1989-2020 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. 7 8 This file is part of GCC. 9 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. 14 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. 19 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/>. */ 23 24 #define IN_TARGET_CODE 1 25 26 #include "config.h" 27 #include "system.h" 28 #include "coretypes.h" 29 #include "backend.h" 30 #include "target.h" 31 #include "rtl.h" 32 #include "tree.h" 33 #include "memmodel.h" 34 #include "gimple.h" 35 #include "cfghooks.h" 36 #include "df.h" 37 #include "tm_p.h" 38 #include "stringpool.h" 39 #include "attribs.h" 40 #include "optabs.h" 41 #include "regs.h" 42 #include "emit-rtl.h" 43 #include "recog.h" 44 #include "cgraph.h" 45 #include "diagnostic.h" 46 #include "insn-attr.h" 47 #include "output.h" 48 #include "alias.h" 49 #include "fold-const.h" 50 #include "varasm.h" 51 #include "stor-layout.h" 52 #include "calls.h" 53 #include "explow.h" 54 #include "expr.h" 55 #include "libfuncs.h" 56 #include "reload.h" 57 #include "common/common-target.h" 58 #include "langhooks.h" 59 #include "cfgrtl.h" 60 #include "cfganal.h" 61 #include "sched-int.h" 62 #include "gimplify.h" 63 #include "target-globals.h" 64 #include "tree-pass.h" 65 #include "context.h" 66 #include "builtins.h" 67 #include "rtl-iter.h" 68 69 /* This file should be included last. */ 70 #include "target-def.h" 71 72 /* True if X is an UNSPEC wrapper around a SYMBOL_REF or LABEL_REF. */ 73 #define UNSPEC_ADDRESS_P(X) \ 74 (GET_CODE (X) == UNSPEC \ 75 && XINT (X, 1) >= UNSPEC_ADDRESS_FIRST \ 76 && XINT (X, 1) < UNSPEC_ADDRESS_FIRST + NUM_SYMBOL_TYPES) 77 78 /* Extract the symbol or label from UNSPEC wrapper X. */ 79 #define UNSPEC_ADDRESS(X) \ 80 XVECEXP (X, 0, 0) 81 82 /* Extract the symbol type from UNSPEC wrapper X. */ 83 #define UNSPEC_ADDRESS_TYPE(X) \ 84 ((enum mips_symbol_type) (XINT (X, 1) - UNSPEC_ADDRESS_FIRST)) 85 86 /* The maximum distance between the top of the stack frame and the 87 value $sp has when we save and restore registers. 88 89 The value for normal-mode code must be a SMALL_OPERAND and must 90 preserve the maximum stack alignment. We therefore use a value 91 of 0x7ff0 in this case. 92 93 microMIPS LWM and SWM support 12-bit offsets (from -0x800 to 0x7ff), 94 so we use a maximum of 0x7f0 for TARGET_MICROMIPS. 95 96 MIPS16e SAVE and RESTORE instructions can adjust the stack pointer by 97 up to 0x7f8 bytes and can usually save or restore all the registers 98 that we need to save or restore. (Note that we can only use these 99 instructions for o32, for which the stack alignment is 8 bytes.) 100 101 We use a maximum gap of 0x100 or 0x400 for MIPS16 code when SAVE and 102 RESTORE are not available. We can then use unextended instructions 103 to save and restore registers, and to allocate and deallocate the top 104 part of the frame. */ 105 #define MIPS_MAX_FIRST_STACK_STEP \ 106 (!TARGET_COMPRESSION ? 0x7ff0 \ 107 : TARGET_MICROMIPS || GENERATE_MIPS16E_SAVE_RESTORE ? 0x7f8 \ 108 : TARGET_64BIT ? 0x100 : 0x400) 109 110 /* True if INSN is a mips.md pattern or asm statement. */ 111 /* ??? This test exists through the compiler, perhaps it should be 112 moved to rtl.h. */ 113 #define USEFUL_INSN_P(INSN) \ 114 (NONDEBUG_INSN_P (INSN) \ 115 && GET_CODE (PATTERN (INSN)) != USE \ 116 && GET_CODE (PATTERN (INSN)) != CLOBBER) 117 118 /* If INSN is a delayed branch sequence, return the first instruction 119 in the sequence, otherwise return INSN itself. */ 120 #define SEQ_BEGIN(INSN) \ 121 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \ 122 ? as_a <rtx_insn *> (XVECEXP (PATTERN (INSN), 0, 0)) \ 123 : (INSN)) 124 125 /* Likewise for the last instruction in a delayed branch sequence. */ 126 #define SEQ_END(INSN) \ 127 (INSN_P (INSN) && GET_CODE (PATTERN (INSN)) == SEQUENCE \ 128 ? as_a <rtx_insn *> (XVECEXP (PATTERN (INSN), \ 129 0, \ 130 XVECLEN (PATTERN (INSN), 0) - 1)) \ 131 : (INSN)) 132 133 /* Execute the following loop body with SUBINSN set to each instruction 134 between SEQ_BEGIN (INSN) and SEQ_END (INSN) inclusive. */ 135 #define FOR_EACH_SUBINSN(SUBINSN, INSN) \ 136 for ((SUBINSN) = SEQ_BEGIN (INSN); \ 137 (SUBINSN) != NEXT_INSN (SEQ_END (INSN)); \ 138 (SUBINSN) = NEXT_INSN (SUBINSN)) 139 140 /* True if bit BIT is set in VALUE. */ 141 #define BITSET_P(VALUE, BIT) (((VALUE) & (1 << (BIT))) != 0) 142 143 /* Return the opcode for a ptr_mode load of the form: 144 145 l[wd] DEST, OFFSET(BASE). */ 146 #define MIPS_LOAD_PTR(DEST, OFFSET, BASE) \ 147 (((ptr_mode == DImode ? 0x37 : 0x23) << 26) \ 148 | ((BASE) << 21) \ 149 | ((DEST) << 16) \ 150 | (OFFSET)) 151 152 /* Return the opcode to move register SRC into register DEST. */ 153 #define MIPS_MOVE(DEST, SRC) \ 154 ((TARGET_64BIT ? 0x2d : 0x21) \ 155 | ((DEST) << 11) \ 156 | ((SRC) << 21)) 157 158 /* Return the opcode for: 159 160 lui DEST, VALUE. */ 161 #define MIPS_LUI(DEST, VALUE) \ 162 ((0xf << 26) | ((DEST) << 16) | (VALUE)) 163 164 /* Return the opcode to jump to register DEST. When the JR opcode is not 165 available use JALR $0, DEST. */ 166 #define MIPS_JR(DEST) \ 167 (TARGET_CB_ALWAYS ? ((0x1b << 27) | ((DEST) << 16)) \ 168 : (((DEST) << 21) | (ISA_HAS_JR ? 0x8 : 0x9))) 169 170 /* Return the opcode for: 171 172 bal . + (1 + OFFSET) * 4. */ 173 #define MIPS_BAL(OFFSET) \ 174 ((0x1 << 26) | (0x11 << 16) | (OFFSET)) 175 176 /* Return the usual opcode for a nop. */ 177 #define MIPS_NOP 0 178 179 /* Classifies an address. 180 181 ADDRESS_REG 182 A natural register + offset address. The register satisfies 183 mips_valid_base_register_p and the offset is a const_arith_operand. 184 185 ADDRESS_LO_SUM 186 A LO_SUM rtx. The first operand is a valid base register and 187 the second operand is a symbolic address. 188 189 ADDRESS_CONST_INT 190 A signed 16-bit constant address. 191 192 ADDRESS_SYMBOLIC: 193 A constant symbolic address. */ 194 enum mips_address_type { 195 ADDRESS_REG, 196 ADDRESS_LO_SUM, 197 ADDRESS_CONST_INT, 198 ADDRESS_SYMBOLIC 199 }; 200 201 /* Classifies an unconditional branch of interest for the P6600. */ 202 203 enum mips_ucbranch_type 204 { 205 /* May not even be a branch. */ 206 UC_UNDEFINED, 207 UC_BALC, 208 UC_OTHER 209 }; 210 211 /* Macros to create an enumeration identifier for a function prototype. */ 212 #define MIPS_FTYPE_NAME1(A, B) MIPS_##A##_FTYPE_##B 213 #define MIPS_FTYPE_NAME2(A, B, C) MIPS_##A##_FTYPE_##B##_##C 214 #define MIPS_FTYPE_NAME3(A, B, C, D) MIPS_##A##_FTYPE_##B##_##C##_##D 215 #define MIPS_FTYPE_NAME4(A, B, C, D, E) MIPS_##A##_FTYPE_##B##_##C##_##D##_##E 216 217 /* Classifies the prototype of a built-in function. */ 218 enum mips_function_type { 219 #define DEF_MIPS_FTYPE(NARGS, LIST) MIPS_FTYPE_NAME##NARGS LIST, 220 #include "config/mips/mips-ftypes.def" 221 #undef DEF_MIPS_FTYPE 222 MIPS_MAX_FTYPE_MAX 223 }; 224 225 /* Specifies how a built-in function should be converted into rtl. */ 226 enum mips_builtin_type { 227 /* The function corresponds directly to an .md pattern. The return 228 value is mapped to operand 0 and the arguments are mapped to 229 operands 1 and above. */ 230 MIPS_BUILTIN_DIRECT, 231 232 /* The function corresponds directly to an .md pattern. There is no return 233 value and the arguments are mapped to operands 0 and above. */ 234 MIPS_BUILTIN_DIRECT_NO_TARGET, 235 236 /* The function corresponds to a comparison instruction followed by 237 a mips_cond_move_tf_ps pattern. The first two arguments are the 238 values to compare and the second two arguments are the vector 239 operands for the movt.ps or movf.ps instruction (in assembly order). */ 240 MIPS_BUILTIN_MOVF, 241 MIPS_BUILTIN_MOVT, 242 243 /* The function corresponds to a V2SF comparison instruction. Operand 0 244 of this instruction is the result of the comparison, which has mode 245 CCV2 or CCV4. The function arguments are mapped to operands 1 and 246 above. The function's return value is an SImode boolean that is 247 true under the following conditions: 248 249 MIPS_BUILTIN_CMP_ANY: one of the registers is true 250 MIPS_BUILTIN_CMP_ALL: all of the registers are true 251 MIPS_BUILTIN_CMP_LOWER: the first register is true 252 MIPS_BUILTIN_CMP_UPPER: the second register is true. */ 253 MIPS_BUILTIN_CMP_ANY, 254 MIPS_BUILTIN_CMP_ALL, 255 MIPS_BUILTIN_CMP_UPPER, 256 MIPS_BUILTIN_CMP_LOWER, 257 258 /* As above, but the instruction only sets a single $fcc register. */ 259 MIPS_BUILTIN_CMP_SINGLE, 260 261 /* The function corresponds to an MSA conditional branch instruction 262 combined with a compare instruction. */ 263 MIPS_BUILTIN_MSA_TEST_BRANCH, 264 265 /* For generating bposge32 branch instructions in MIPS32 DSP ASE. */ 266 MIPS_BUILTIN_BPOSGE32 267 }; 268 269 /* Invoke MACRO (COND) for each C.cond.fmt condition. */ 270 #define MIPS_FP_CONDITIONS(MACRO) \ 271 MACRO (f), \ 272 MACRO (un), \ 273 MACRO (eq), \ 274 MACRO (ueq), \ 275 MACRO (olt), \ 276 MACRO (ult), \ 277 MACRO (ole), \ 278 MACRO (ule), \ 279 MACRO (sf), \ 280 MACRO (ngle), \ 281 MACRO (seq), \ 282 MACRO (ngl), \ 283 MACRO (lt), \ 284 MACRO (nge), \ 285 MACRO (le), \ 286 MACRO (ngt) 287 288 /* Enumerates the codes above as MIPS_FP_COND_<X>. */ 289 #define DECLARE_MIPS_COND(X) MIPS_FP_COND_ ## X 290 enum mips_fp_condition { 291 MIPS_FP_CONDITIONS (DECLARE_MIPS_COND) 292 }; 293 #undef DECLARE_MIPS_COND 294 295 /* Index X provides the string representation of MIPS_FP_COND_<X>. */ 296 #define STRINGIFY(X) #X 297 static const char *const mips_fp_conditions[] = { 298 MIPS_FP_CONDITIONS (STRINGIFY) 299 }; 300 #undef STRINGIFY 301 302 /* A class used to control a comdat-style stub that we output in each 303 translation unit that needs it. */ 304 class mips_one_only_stub { 305 public: 306 virtual ~mips_one_only_stub () {} 307 308 /* Return the name of the stub. */ 309 virtual const char *get_name () = 0; 310 311 /* Output the body of the function to asm_out_file. */ 312 virtual void output_body () = 0; 313 }; 314 315 /* Tuning information that is automatically derived from other sources 316 (such as the scheduler). */ 317 static struct { 318 /* The architecture and tuning settings that this structure describes. */ 319 enum processor arch; 320 enum processor tune; 321 322 /* True if this structure describes MIPS16 settings. */ 323 bool mips16_p; 324 325 /* True if the structure has been initialized. */ 326 bool initialized_p; 327 328 /* True if "MULT $0, $0" is preferable to "MTLO $0; MTHI $0" 329 when optimizing for speed. */ 330 bool fast_mult_zero_zero_p; 331 } mips_tuning_info; 332 333 /* Information about a single argument. */ 334 struct mips_arg_info { 335 /* True if the argument is passed in a floating-point register, or 336 would have been if we hadn't run out of registers. */ 337 bool fpr_p; 338 339 /* The number of words passed in registers, rounded up. */ 340 unsigned int reg_words; 341 342 /* For EABI, the offset of the first register from GP_ARG_FIRST or 343 FP_ARG_FIRST. For other ABIs, the offset of the first register from 344 the start of the ABI's argument structure (see the CUMULATIVE_ARGS 345 comment for details). 346 347 The value is MAX_ARGS_IN_REGISTERS if the argument is passed entirely 348 on the stack. */ 349 unsigned int reg_offset; 350 351 /* The number of words that must be passed on the stack, rounded up. */ 352 unsigned int stack_words; 353 354 /* The offset from the start of the stack overflow area of the argument's 355 first stack word. Only meaningful when STACK_WORDS is nonzero. */ 356 unsigned int stack_offset; 357 }; 358 359 /* Information about an address described by mips_address_type. 360 361 ADDRESS_CONST_INT 362 No fields are used. 363 364 ADDRESS_REG 365 REG is the base register and OFFSET is the constant offset. 366 367 ADDRESS_LO_SUM 368 REG and OFFSET are the operands to the LO_SUM and SYMBOL_TYPE 369 is the type of symbol it references. 370 371 ADDRESS_SYMBOLIC 372 SYMBOL_TYPE is the type of symbol that the address references. */ 373 struct mips_address_info { 374 enum mips_address_type type; 375 rtx reg; 376 rtx offset; 377 enum mips_symbol_type symbol_type; 378 }; 379 380 /* One stage in a constant building sequence. These sequences have 381 the form: 382 383 A = VALUE[0] 384 A = A CODE[1] VALUE[1] 385 A = A CODE[2] VALUE[2] 386 ... 387 388 where A is an accumulator, each CODE[i] is a binary rtl operation 389 and each VALUE[i] is a constant integer. CODE[0] is undefined. */ 390 struct mips_integer_op { 391 enum rtx_code code; 392 unsigned HOST_WIDE_INT value; 393 }; 394 395 /* The largest number of operations needed to load an integer constant. 396 The worst accepted case for 64-bit constants is LUI,ORI,SLL,ORI,SLL,ORI. 397 When the lowest bit is clear, we can try, but reject a sequence with 398 an extra SLL at the end. */ 399 #define MIPS_MAX_INTEGER_OPS 7 400 401 /* Information about a MIPS16e SAVE or RESTORE instruction. */ 402 struct mips16e_save_restore_info { 403 /* The number of argument registers saved by a SAVE instruction. 404 0 for RESTORE instructions. */ 405 unsigned int nargs; 406 407 /* Bit X is set if the instruction saves or restores GPR X. */ 408 unsigned int mask; 409 410 /* The total number of bytes to allocate. */ 411 HOST_WIDE_INT size; 412 }; 413 414 /* Costs of various operations on the different architectures. */ 415 416 struct mips_rtx_cost_data 417 { 418 unsigned short fp_add; 419 unsigned short fp_mult_sf; 420 unsigned short fp_mult_df; 421 unsigned short fp_div_sf; 422 unsigned short fp_div_df; 423 unsigned short int_mult_si; 424 unsigned short int_mult_di; 425 unsigned short int_div_si; 426 unsigned short int_div_di; 427 unsigned short branch_cost; 428 unsigned short memory_latency; 429 }; 430 431 /* Global variables for machine-dependent things. */ 432 433 /* The -G setting, or the configuration's default small-data limit if 434 no -G option is given. */ 435 static unsigned int mips_small_data_threshold; 436 437 /* The number of file directives written by mips_output_filename. */ 438 int num_source_filenames; 439 440 /* The name that appeared in the last .file directive written by 441 mips_output_filename, or "" if mips_output_filename hasn't 442 written anything yet. */ 443 const char *current_function_file = ""; 444 445 /* Arrays that map GCC register numbers to debugger register numbers. */ 446 int mips_dbx_regno[FIRST_PSEUDO_REGISTER]; 447 int mips_dwarf_regno[FIRST_PSEUDO_REGISTER]; 448 449 /* Information about the current function's epilogue, used only while 450 expanding it. */ 451 static struct { 452 /* A list of queued REG_CFA_RESTORE notes. */ 453 rtx cfa_restores; 454 455 /* The CFA is currently defined as CFA_REG + CFA_OFFSET. */ 456 rtx cfa_reg; 457 HOST_WIDE_INT cfa_offset; 458 459 /* The offset of the CFA from the stack pointer while restoring 460 registers. */ 461 HOST_WIDE_INT cfa_restore_sp_offset; 462 } mips_epilogue; 463 464 /* The nesting depth of the PRINT_OPERAND '%(', '%<' and '%[' constructs. */ 465 struct mips_asm_switch mips_noreorder = { "reorder", 0 }; 466 struct mips_asm_switch mips_nomacro = { "macro", 0 }; 467 struct mips_asm_switch mips_noat = { "at", 0 }; 468 469 /* True if we're writing out a branch-likely instruction rather than a 470 normal branch. */ 471 static bool mips_branch_likely; 472 473 /* The current instruction-set architecture. */ 474 enum processor mips_arch; 475 const struct mips_cpu_info *mips_arch_info; 476 477 /* The processor that we should tune the code for. */ 478 enum processor mips_tune; 479 const struct mips_cpu_info *mips_tune_info; 480 481 /* The ISA level associated with mips_arch. */ 482 int mips_isa; 483 484 /* The ISA revision level. This is 0 for MIPS I to V and N for 485 MIPS{32,64}rN. */ 486 int mips_isa_rev; 487 488 /* The architecture selected by -mipsN, or null if -mipsN wasn't used. */ 489 static const struct mips_cpu_info *mips_isa_option_info; 490 491 /* Which cost information to use. */ 492 static const struct mips_rtx_cost_data *mips_cost; 493 494 /* The ambient target flags, excluding MASK_MIPS16. */ 495 static int mips_base_target_flags; 496 497 /* The default compression mode. */ 498 unsigned int mips_base_compression_flags; 499 500 /* The ambient values of other global variables. */ 501 static int mips_base_schedule_insns; /* flag_schedule_insns */ 502 static int mips_base_reorder_blocks_and_partition; /* flag_reorder... */ 503 static int mips_base_move_loop_invariants; /* flag_move_loop_invariants */ 504 static const char *mips_base_align_loops; /* align_loops */ 505 static const char *mips_base_align_jumps; /* align_jumps */ 506 static const char *mips_base_align_functions; /* align_functions */ 507 508 /* Index [M][R] is true if register R is allowed to hold a value of mode M. */ 509 static bool mips_hard_regno_mode_ok_p[MAX_MACHINE_MODE][FIRST_PSEUDO_REGISTER]; 510 511 /* Index C is true if character C is a valid PRINT_OPERAND punctation 512 character. */ 513 static bool mips_print_operand_punct[256]; 514 515 static GTY (()) int mips_output_filename_first_time = 1; 516 517 /* mips_split_p[X] is true if symbols of type X can be split by 518 mips_split_symbol. */ 519 bool mips_split_p[NUM_SYMBOL_TYPES]; 520 521 /* mips_split_hi_p[X] is true if the high parts of symbols of type X 522 can be split by mips_split_symbol. */ 523 bool mips_split_hi_p[NUM_SYMBOL_TYPES]; 524 525 /* mips_use_pcrel_pool_p[X] is true if symbols of type X should be 526 forced into a PC-relative constant pool. */ 527 bool mips_use_pcrel_pool_p[NUM_SYMBOL_TYPES]; 528 529 /* mips_lo_relocs[X] is the relocation to use when a symbol of type X 530 appears in a LO_SUM. It can be null if such LO_SUMs aren't valid or 531 if they are matched by a special .md file pattern. */ 532 const char *mips_lo_relocs[NUM_SYMBOL_TYPES]; 533 534 /* Likewise for HIGHs. */ 535 const char *mips_hi_relocs[NUM_SYMBOL_TYPES]; 536 537 /* Target state for MIPS16. */ 538 struct target_globals *mips16_globals; 539 540 /* Target state for MICROMIPS. */ 541 struct target_globals *micromips_globals; 542 543 /* Cached value of can_issue_more. This is cached in mips_variable_issue hook 544 and returned from mips_sched_reorder2. */ 545 static int cached_can_issue_more; 546 547 /* The stubs for various MIPS16 support functions, if used. */ 548 static mips_one_only_stub *mips16_rdhwr_stub; 549 static mips_one_only_stub *mips16_get_fcsr_stub; 550 static mips_one_only_stub *mips16_set_fcsr_stub; 551 552 /* Index R is the smallest register class that contains register R. */ 553 const enum reg_class mips_regno_to_class[FIRST_PSEUDO_REGISTER] = { 554 LEA_REGS, LEA_REGS, M16_STORE_REGS, V1_REG, 555 M16_STORE_REGS, M16_STORE_REGS, M16_STORE_REGS, M16_STORE_REGS, 556 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS, 557 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS, 558 M16_REGS, M16_STORE_REGS, LEA_REGS, LEA_REGS, 559 LEA_REGS, LEA_REGS, LEA_REGS, LEA_REGS, 560 T_REG, PIC_FN_ADDR_REG, LEA_REGS, LEA_REGS, 561 LEA_REGS, M16_SP_REGS, LEA_REGS, LEA_REGS, 562 563 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 564 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 565 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 566 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 567 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 568 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 569 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 570 FP_REGS, FP_REGS, FP_REGS, FP_REGS, 571 MD0_REG, MD1_REG, NO_REGS, ST_REGS, 572 ST_REGS, ST_REGS, ST_REGS, ST_REGS, 573 ST_REGS, ST_REGS, ST_REGS, NO_REGS, 574 NO_REGS, FRAME_REGS, FRAME_REGS, NO_REGS, 575 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 576 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 577 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 578 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 579 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 580 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 581 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 582 COP0_REGS, COP0_REGS, COP0_REGS, COP0_REGS, 583 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 584 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 585 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 586 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 587 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 588 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 589 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 590 COP2_REGS, COP2_REGS, COP2_REGS, COP2_REGS, 591 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 592 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 593 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 594 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 595 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 596 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 597 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 598 COP3_REGS, COP3_REGS, COP3_REGS, COP3_REGS, 599 DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS, DSP_ACC_REGS, 600 DSP_ACC_REGS, DSP_ACC_REGS, ALL_REGS, ALL_REGS, 601 ALL_REGS, ALL_REGS, ALL_REGS, ALL_REGS 602 }; 603 604 static tree mips_handle_interrupt_attr (tree *, tree, tree, int, bool *); 605 static tree mips_handle_use_shadow_register_set_attr (tree *, tree, tree, int, 606 bool *); 607 608 /* The value of TARGET_ATTRIBUTE_TABLE. */ 609 static const struct attribute_spec mips_attribute_table[] = { 610 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, 611 affects_type_identity, handler, exclude } */ 612 { "long_call", 0, 0, false, true, true, false, NULL, NULL }, 613 { "short_call", 0, 0, false, true, true, false, NULL, NULL }, 614 { "far", 0, 0, false, true, true, false, NULL, NULL }, 615 { "near", 0, 0, false, true, true, false, NULL, NULL }, 616 /* We would really like to treat "mips16" and "nomips16" as type 617 attributes, but GCC doesn't provide the hooks we need to support 618 the right conversion rules. As declaration attributes, they affect 619 code generation but don't carry other semantics. */ 620 { "mips16", 0, 0, true, false, false, false, NULL, NULL }, 621 { "nomips16", 0, 0, true, false, false, false, NULL, NULL }, 622 { "micromips", 0, 0, true, false, false, false, NULL, NULL }, 623 { "nomicromips", 0, 0, true, false, false, false, NULL, NULL }, 624 { "nocompression", 0, 0, true, false, false, false, NULL, NULL }, 625 /* Allow functions to be specified as interrupt handlers */ 626 { "interrupt", 0, 1, false, true, true, false, mips_handle_interrupt_attr, 627 NULL }, 628 { "use_shadow_register_set", 0, 1, false, true, true, false, 629 mips_handle_use_shadow_register_set_attr, NULL }, 630 { "keep_interrupts_masked", 0, 0, false, true, true, false, NULL, NULL }, 631 { "use_debug_exception_return", 0, 0, false, true, true, false, NULL, NULL }, 632 { NULL, 0, 0, false, false, false, false, NULL, NULL } 633 }; 634 635 /* A table describing all the processors GCC knows about; see 636 mips-cpus.def for details. */ 637 static const struct mips_cpu_info mips_cpu_info_table[] = { 638 #define MIPS_CPU(NAME, CPU, ISA, FLAGS) \ 639 { NAME, CPU, ISA, FLAGS }, 640 #include "mips-cpus.def" 641 #undef MIPS_CPU 642 }; 643 644 /* Default costs. If these are used for a processor we should look 645 up the actual costs. */ 646 #define DEFAULT_COSTS COSTS_N_INSNS (6), /* fp_add */ \ 647 COSTS_N_INSNS (7), /* fp_mult_sf */ \ 648 COSTS_N_INSNS (8), /* fp_mult_df */ \ 649 COSTS_N_INSNS (23), /* fp_div_sf */ \ 650 COSTS_N_INSNS (36), /* fp_div_df */ \ 651 COSTS_N_INSNS (10), /* int_mult_si */ \ 652 COSTS_N_INSNS (10), /* int_mult_di */ \ 653 COSTS_N_INSNS (69), /* int_div_si */ \ 654 COSTS_N_INSNS (69), /* int_div_di */ \ 655 2, /* branch_cost */ \ 656 4 /* memory_latency */ 657 658 /* Floating-point costs for processors without an FPU. Just assume that 659 all floating-point libcalls are very expensive. */ 660 #define SOFT_FP_COSTS COSTS_N_INSNS (256), /* fp_add */ \ 661 COSTS_N_INSNS (256), /* fp_mult_sf */ \ 662 COSTS_N_INSNS (256), /* fp_mult_df */ \ 663 COSTS_N_INSNS (256), /* fp_div_sf */ \ 664 COSTS_N_INSNS (256) /* fp_div_df */ 665 666 /* Costs to use when optimizing for size. */ 667 static const struct mips_rtx_cost_data mips_rtx_cost_optimize_size = { 668 COSTS_N_INSNS (1), /* fp_add */ 669 COSTS_N_INSNS (1), /* fp_mult_sf */ 670 COSTS_N_INSNS (1), /* fp_mult_df */ 671 COSTS_N_INSNS (1), /* fp_div_sf */ 672 COSTS_N_INSNS (1), /* fp_div_df */ 673 COSTS_N_INSNS (1), /* int_mult_si */ 674 COSTS_N_INSNS (1), /* int_mult_di */ 675 COSTS_N_INSNS (1), /* int_div_si */ 676 COSTS_N_INSNS (1), /* int_div_di */ 677 2, /* branch_cost */ 678 4 /* memory_latency */ 679 }; 680 681 /* Costs to use when optimizing for speed, indexed by processor. */ 682 static const struct mips_rtx_cost_data 683 mips_rtx_cost_data[NUM_PROCESSOR_VALUES] = { 684 { /* R3000 */ 685 COSTS_N_INSNS (2), /* fp_add */ 686 COSTS_N_INSNS (4), /* fp_mult_sf */ 687 COSTS_N_INSNS (5), /* fp_mult_df */ 688 COSTS_N_INSNS (12), /* fp_div_sf */ 689 COSTS_N_INSNS (19), /* fp_div_df */ 690 COSTS_N_INSNS (12), /* int_mult_si */ 691 COSTS_N_INSNS (12), /* int_mult_di */ 692 COSTS_N_INSNS (35), /* int_div_si */ 693 COSTS_N_INSNS (35), /* int_div_di */ 694 1, /* branch_cost */ 695 4 /* memory_latency */ 696 }, 697 { /* 4KC */ 698 SOFT_FP_COSTS, 699 COSTS_N_INSNS (6), /* int_mult_si */ 700 COSTS_N_INSNS (6), /* int_mult_di */ 701 COSTS_N_INSNS (36), /* int_div_si */ 702 COSTS_N_INSNS (36), /* int_div_di */ 703 1, /* branch_cost */ 704 4 /* memory_latency */ 705 }, 706 { /* 4KP */ 707 SOFT_FP_COSTS, 708 COSTS_N_INSNS (36), /* int_mult_si */ 709 COSTS_N_INSNS (36), /* int_mult_di */ 710 COSTS_N_INSNS (37), /* int_div_si */ 711 COSTS_N_INSNS (37), /* int_div_di */ 712 1, /* branch_cost */ 713 4 /* memory_latency */ 714 }, 715 { /* 5KC */ 716 SOFT_FP_COSTS, 717 COSTS_N_INSNS (4), /* int_mult_si */ 718 COSTS_N_INSNS (11), /* int_mult_di */ 719 COSTS_N_INSNS (36), /* int_div_si */ 720 COSTS_N_INSNS (68), /* int_div_di */ 721 1, /* branch_cost */ 722 4 /* memory_latency */ 723 }, 724 { /* 5KF */ 725 COSTS_N_INSNS (4), /* fp_add */ 726 COSTS_N_INSNS (4), /* fp_mult_sf */ 727 COSTS_N_INSNS (5), /* fp_mult_df */ 728 COSTS_N_INSNS (17), /* fp_div_sf */ 729 COSTS_N_INSNS (32), /* fp_div_df */ 730 COSTS_N_INSNS (4), /* int_mult_si */ 731 COSTS_N_INSNS (11), /* int_mult_di */ 732 COSTS_N_INSNS (36), /* int_div_si */ 733 COSTS_N_INSNS (68), /* int_div_di */ 734 1, /* branch_cost */ 735 4 /* memory_latency */ 736 }, 737 { /* 20KC */ 738 COSTS_N_INSNS (4), /* fp_add */ 739 COSTS_N_INSNS (4), /* fp_mult_sf */ 740 COSTS_N_INSNS (5), /* fp_mult_df */ 741 COSTS_N_INSNS (17), /* fp_div_sf */ 742 COSTS_N_INSNS (32), /* fp_div_df */ 743 COSTS_N_INSNS (4), /* int_mult_si */ 744 COSTS_N_INSNS (7), /* int_mult_di */ 745 COSTS_N_INSNS (42), /* int_div_si */ 746 COSTS_N_INSNS (72), /* int_div_di */ 747 1, /* branch_cost */ 748 4 /* memory_latency */ 749 }, 750 { /* 24KC */ 751 SOFT_FP_COSTS, 752 COSTS_N_INSNS (5), /* int_mult_si */ 753 COSTS_N_INSNS (5), /* int_mult_di */ 754 COSTS_N_INSNS (41), /* int_div_si */ 755 COSTS_N_INSNS (41), /* int_div_di */ 756 1, /* branch_cost */ 757 4 /* memory_latency */ 758 }, 759 { /* 24KF2_1 */ 760 COSTS_N_INSNS (8), /* fp_add */ 761 COSTS_N_INSNS (8), /* fp_mult_sf */ 762 COSTS_N_INSNS (10), /* fp_mult_df */ 763 COSTS_N_INSNS (34), /* fp_div_sf */ 764 COSTS_N_INSNS (64), /* fp_div_df */ 765 COSTS_N_INSNS (5), /* int_mult_si */ 766 COSTS_N_INSNS (5), /* int_mult_di */ 767 COSTS_N_INSNS (41), /* int_div_si */ 768 COSTS_N_INSNS (41), /* int_div_di */ 769 1, /* branch_cost */ 770 4 /* memory_latency */ 771 }, 772 { /* 24KF1_1 */ 773 COSTS_N_INSNS (4), /* fp_add */ 774 COSTS_N_INSNS (4), /* fp_mult_sf */ 775 COSTS_N_INSNS (5), /* fp_mult_df */ 776 COSTS_N_INSNS (17), /* fp_div_sf */ 777 COSTS_N_INSNS (32), /* fp_div_df */ 778 COSTS_N_INSNS (5), /* int_mult_si */ 779 COSTS_N_INSNS (5), /* int_mult_di */ 780 COSTS_N_INSNS (41), /* int_div_si */ 781 COSTS_N_INSNS (41), /* int_div_di */ 782 1, /* branch_cost */ 783 4 /* memory_latency */ 784 }, 785 { /* 74KC */ 786 SOFT_FP_COSTS, 787 COSTS_N_INSNS (5), /* int_mult_si */ 788 COSTS_N_INSNS (5), /* int_mult_di */ 789 COSTS_N_INSNS (41), /* int_div_si */ 790 COSTS_N_INSNS (41), /* int_div_di */ 791 1, /* branch_cost */ 792 4 /* memory_latency */ 793 }, 794 { /* 74KF2_1 */ 795 COSTS_N_INSNS (8), /* fp_add */ 796 COSTS_N_INSNS (8), /* fp_mult_sf */ 797 COSTS_N_INSNS (10), /* fp_mult_df */ 798 COSTS_N_INSNS (34), /* fp_div_sf */ 799 COSTS_N_INSNS (64), /* fp_div_df */ 800 COSTS_N_INSNS (5), /* int_mult_si */ 801 COSTS_N_INSNS (5), /* int_mult_di */ 802 COSTS_N_INSNS (41), /* int_div_si */ 803 COSTS_N_INSNS (41), /* int_div_di */ 804 1, /* branch_cost */ 805 4 /* memory_latency */ 806 }, 807 { /* 74KF1_1 */ 808 COSTS_N_INSNS (4), /* fp_add */ 809 COSTS_N_INSNS (4), /* fp_mult_sf */ 810 COSTS_N_INSNS (5), /* fp_mult_df */ 811 COSTS_N_INSNS (17), /* fp_div_sf */ 812 COSTS_N_INSNS (32), /* fp_div_df */ 813 COSTS_N_INSNS (5), /* int_mult_si */ 814 COSTS_N_INSNS (5), /* int_mult_di */ 815 COSTS_N_INSNS (41), /* int_div_si */ 816 COSTS_N_INSNS (41), /* int_div_di */ 817 1, /* branch_cost */ 818 4 /* memory_latency */ 819 }, 820 { /* 74KF3_2 */ 821 COSTS_N_INSNS (6), /* fp_add */ 822 COSTS_N_INSNS (6), /* fp_mult_sf */ 823 COSTS_N_INSNS (7), /* fp_mult_df */ 824 COSTS_N_INSNS (25), /* fp_div_sf */ 825 COSTS_N_INSNS (48), /* fp_div_df */ 826 COSTS_N_INSNS (5), /* int_mult_si */ 827 COSTS_N_INSNS (5), /* int_mult_di */ 828 COSTS_N_INSNS (41), /* int_div_si */ 829 COSTS_N_INSNS (41), /* int_div_di */ 830 1, /* branch_cost */ 831 4 /* memory_latency */ 832 }, 833 { /* Loongson-2E */ 834 DEFAULT_COSTS 835 }, 836 { /* Loongson-2F */ 837 DEFAULT_COSTS 838 }, 839 { /* Loongson gs464. */ 840 DEFAULT_COSTS 841 }, 842 { /* Loongson gs464e. */ 843 DEFAULT_COSTS 844 }, 845 { /* Loongson gs264e. */ 846 DEFAULT_COSTS 847 }, 848 { /* M4k */ 849 DEFAULT_COSTS 850 }, 851 /* Octeon */ 852 { 853 SOFT_FP_COSTS, 854 COSTS_N_INSNS (5), /* int_mult_si */ 855 COSTS_N_INSNS (5), /* int_mult_di */ 856 COSTS_N_INSNS (72), /* int_div_si */ 857 COSTS_N_INSNS (72), /* int_div_di */ 858 1, /* branch_cost */ 859 4 /* memory_latency */ 860 }, 861 /* Octeon II */ 862 { 863 SOFT_FP_COSTS, 864 COSTS_N_INSNS (6), /* int_mult_si */ 865 COSTS_N_INSNS (6), /* int_mult_di */ 866 COSTS_N_INSNS (18), /* int_div_si */ 867 COSTS_N_INSNS (35), /* int_div_di */ 868 4, /* branch_cost */ 869 4 /* memory_latency */ 870 }, 871 /* Octeon III */ 872 { 873 COSTS_N_INSNS (6), /* fp_add */ 874 COSTS_N_INSNS (6), /* fp_mult_sf */ 875 COSTS_N_INSNS (7), /* fp_mult_df */ 876 COSTS_N_INSNS (25), /* fp_div_sf */ 877 COSTS_N_INSNS (48), /* fp_div_df */ 878 COSTS_N_INSNS (6), /* int_mult_si */ 879 COSTS_N_INSNS (6), /* int_mult_di */ 880 COSTS_N_INSNS (18), /* int_div_si */ 881 COSTS_N_INSNS (35), /* int_div_di */ 882 4, /* branch_cost */ 883 4 /* memory_latency */ 884 }, 885 { /* R3900 */ 886 COSTS_N_INSNS (2), /* fp_add */ 887 COSTS_N_INSNS (4), /* fp_mult_sf */ 888 COSTS_N_INSNS (5), /* fp_mult_df */ 889 COSTS_N_INSNS (12), /* fp_div_sf */ 890 COSTS_N_INSNS (19), /* fp_div_df */ 891 COSTS_N_INSNS (2), /* int_mult_si */ 892 COSTS_N_INSNS (2), /* int_mult_di */ 893 COSTS_N_INSNS (35), /* int_div_si */ 894 COSTS_N_INSNS (35), /* int_div_di */ 895 1, /* branch_cost */ 896 4 /* memory_latency */ 897 }, 898 { /* R6000 */ 899 COSTS_N_INSNS (3), /* fp_add */ 900 COSTS_N_INSNS (5), /* fp_mult_sf */ 901 COSTS_N_INSNS (6), /* fp_mult_df */ 902 COSTS_N_INSNS (15), /* fp_div_sf */ 903 COSTS_N_INSNS (16), /* fp_div_df */ 904 COSTS_N_INSNS (17), /* int_mult_si */ 905 COSTS_N_INSNS (17), /* int_mult_di */ 906 COSTS_N_INSNS (38), /* int_div_si */ 907 COSTS_N_INSNS (38), /* int_div_di */ 908 2, /* branch_cost */ 909 6 /* memory_latency */ 910 }, 911 { /* R4000 */ 912 COSTS_N_INSNS (6), /* fp_add */ 913 COSTS_N_INSNS (7), /* fp_mult_sf */ 914 COSTS_N_INSNS (8), /* fp_mult_df */ 915 COSTS_N_INSNS (23), /* fp_div_sf */ 916 COSTS_N_INSNS (36), /* fp_div_df */ 917 COSTS_N_INSNS (10), /* int_mult_si */ 918 COSTS_N_INSNS (10), /* int_mult_di */ 919 COSTS_N_INSNS (69), /* int_div_si */ 920 COSTS_N_INSNS (69), /* int_div_di */ 921 2, /* branch_cost */ 922 6 /* memory_latency */ 923 }, 924 { /* R4100 */ 925 DEFAULT_COSTS 926 }, 927 { /* R4111 */ 928 DEFAULT_COSTS 929 }, 930 { /* R4120 */ 931 DEFAULT_COSTS 932 }, 933 { /* R4130 */ 934 /* The only costs that appear to be updated here are 935 integer multiplication. */ 936 SOFT_FP_COSTS, 937 COSTS_N_INSNS (4), /* int_mult_si */ 938 COSTS_N_INSNS (6), /* int_mult_di */ 939 COSTS_N_INSNS (69), /* int_div_si */ 940 COSTS_N_INSNS (69), /* int_div_di */ 941 1, /* branch_cost */ 942 4 /* memory_latency */ 943 }, 944 { /* R4300 */ 945 DEFAULT_COSTS 946 }, 947 { /* R4600 */ 948 DEFAULT_COSTS 949 }, 950 { /* R4650 */ 951 DEFAULT_COSTS 952 }, 953 { /* R4700 */ 954 DEFAULT_COSTS 955 }, 956 { /* R5000 */ 957 COSTS_N_INSNS (6), /* fp_add */ 958 COSTS_N_INSNS (4), /* fp_mult_sf */ 959 COSTS_N_INSNS (5), /* fp_mult_df */ 960 COSTS_N_INSNS (23), /* fp_div_sf */ 961 COSTS_N_INSNS (36), /* fp_div_df */ 962 COSTS_N_INSNS (5), /* int_mult_si */ 963 COSTS_N_INSNS (5), /* int_mult_di */ 964 COSTS_N_INSNS (36), /* int_div_si */ 965 COSTS_N_INSNS (36), /* int_div_di */ 966 1, /* branch_cost */ 967 4 /* memory_latency */ 968 }, 969 { /* R5400 */ 970 COSTS_N_INSNS (6), /* fp_add */ 971 COSTS_N_INSNS (5), /* fp_mult_sf */ 972 COSTS_N_INSNS (6), /* fp_mult_df */ 973 COSTS_N_INSNS (30), /* fp_div_sf */ 974 COSTS_N_INSNS (59), /* fp_div_df */ 975 COSTS_N_INSNS (3), /* int_mult_si */ 976 COSTS_N_INSNS (4), /* int_mult_di */ 977 COSTS_N_INSNS (42), /* int_div_si */ 978 COSTS_N_INSNS (74), /* int_div_di */ 979 1, /* branch_cost */ 980 4 /* memory_latency */ 981 }, 982 { /* R5500 */ 983 COSTS_N_INSNS (6), /* fp_add */ 984 COSTS_N_INSNS (5), /* fp_mult_sf */ 985 COSTS_N_INSNS (6), /* fp_mult_df */ 986 COSTS_N_INSNS (30), /* fp_div_sf */ 987 COSTS_N_INSNS (59), /* fp_div_df */ 988 COSTS_N_INSNS (5), /* int_mult_si */ 989 COSTS_N_INSNS (9), /* int_mult_di */ 990 COSTS_N_INSNS (42), /* int_div_si */ 991 COSTS_N_INSNS (74), /* int_div_di */ 992 1, /* branch_cost */ 993 4 /* memory_latency */ 994 }, 995 { /* R5900 */ 996 COSTS_N_INSNS (4), /* fp_add */ 997 COSTS_N_INSNS (4), /* fp_mult_sf */ 998 COSTS_N_INSNS (256), /* fp_mult_df */ 999 COSTS_N_INSNS (8), /* fp_div_sf */ 1000 COSTS_N_INSNS (256), /* fp_div_df */ 1001 COSTS_N_INSNS (4), /* int_mult_si */ 1002 COSTS_N_INSNS (256), /* int_mult_di */ 1003 COSTS_N_INSNS (37), /* int_div_si */ 1004 COSTS_N_INSNS (256), /* int_div_di */ 1005 1, /* branch_cost */ 1006 4 /* memory_latency */ 1007 }, 1008 { /* R7000 */ 1009 /* The only costs that are changed here are 1010 integer multiplication. */ 1011 COSTS_N_INSNS (6), /* fp_add */ 1012 COSTS_N_INSNS (7), /* fp_mult_sf */ 1013 COSTS_N_INSNS (8), /* fp_mult_df */ 1014 COSTS_N_INSNS (23), /* fp_div_sf */ 1015 COSTS_N_INSNS (36), /* fp_div_df */ 1016 COSTS_N_INSNS (5), /* int_mult_si */ 1017 COSTS_N_INSNS (9), /* int_mult_di */ 1018 COSTS_N_INSNS (69), /* int_div_si */ 1019 COSTS_N_INSNS (69), /* int_div_di */ 1020 1, /* branch_cost */ 1021 4 /* memory_latency */ 1022 }, 1023 { /* R8000 */ 1024 DEFAULT_COSTS 1025 }, 1026 { /* R9000 */ 1027 /* The only costs that are changed here are 1028 integer multiplication. */ 1029 COSTS_N_INSNS (6), /* fp_add */ 1030 COSTS_N_INSNS (7), /* fp_mult_sf */ 1031 COSTS_N_INSNS (8), /* fp_mult_df */ 1032 COSTS_N_INSNS (23), /* fp_div_sf */ 1033 COSTS_N_INSNS (36), /* fp_div_df */ 1034 COSTS_N_INSNS (3), /* int_mult_si */ 1035 COSTS_N_INSNS (8), /* int_mult_di */ 1036 COSTS_N_INSNS (69), /* int_div_si */ 1037 COSTS_N_INSNS (69), /* int_div_di */ 1038 1, /* branch_cost */ 1039 4 /* memory_latency */ 1040 }, 1041 { /* R1x000 */ 1042 COSTS_N_INSNS (2), /* fp_add */ 1043 COSTS_N_INSNS (2), /* fp_mult_sf */ 1044 COSTS_N_INSNS (2), /* fp_mult_df */ 1045 COSTS_N_INSNS (12), /* fp_div_sf */ 1046 COSTS_N_INSNS (19), /* fp_div_df */ 1047 COSTS_N_INSNS (5), /* int_mult_si */ 1048 COSTS_N_INSNS (9), /* int_mult_di */ 1049 COSTS_N_INSNS (34), /* int_div_si */ 1050 COSTS_N_INSNS (66), /* int_div_di */ 1051 1, /* branch_cost */ 1052 4 /* memory_latency */ 1053 }, 1054 { /* SB1 */ 1055 /* These costs are the same as the SB-1A below. */ 1056 COSTS_N_INSNS (4), /* fp_add */ 1057 COSTS_N_INSNS (4), /* fp_mult_sf */ 1058 COSTS_N_INSNS (4), /* fp_mult_df */ 1059 COSTS_N_INSNS (24), /* fp_div_sf */ 1060 COSTS_N_INSNS (32), /* fp_div_df */ 1061 COSTS_N_INSNS (3), /* int_mult_si */ 1062 COSTS_N_INSNS (4), /* int_mult_di */ 1063 COSTS_N_INSNS (36), /* int_div_si */ 1064 COSTS_N_INSNS (68), /* int_div_di */ 1065 1, /* branch_cost */ 1066 4 /* memory_latency */ 1067 }, 1068 { /* SB1-A */ 1069 /* These costs are the same as the SB-1 above. */ 1070 COSTS_N_INSNS (4), /* fp_add */ 1071 COSTS_N_INSNS (4), /* fp_mult_sf */ 1072 COSTS_N_INSNS (4), /* fp_mult_df */ 1073 COSTS_N_INSNS (24), /* fp_div_sf */ 1074 COSTS_N_INSNS (32), /* fp_div_df */ 1075 COSTS_N_INSNS (3), /* int_mult_si */ 1076 COSTS_N_INSNS (4), /* int_mult_di */ 1077 COSTS_N_INSNS (36), /* int_div_si */ 1078 COSTS_N_INSNS (68), /* int_div_di */ 1079 1, /* branch_cost */ 1080 4 /* memory_latency */ 1081 }, 1082 { /* SR71000 */ 1083 DEFAULT_COSTS 1084 }, 1085 { /* XLR */ 1086 SOFT_FP_COSTS, 1087 COSTS_N_INSNS (8), /* int_mult_si */ 1088 COSTS_N_INSNS (8), /* int_mult_di */ 1089 COSTS_N_INSNS (72), /* int_div_si */ 1090 COSTS_N_INSNS (72), /* int_div_di */ 1091 1, /* branch_cost */ 1092 4 /* memory_latency */ 1093 }, 1094 { /* XLP */ 1095 /* These costs are the same as 5KF above. */ 1096 COSTS_N_INSNS (4), /* fp_add */ 1097 COSTS_N_INSNS (4), /* fp_mult_sf */ 1098 COSTS_N_INSNS (5), /* fp_mult_df */ 1099 COSTS_N_INSNS (17), /* fp_div_sf */ 1100 COSTS_N_INSNS (32), /* fp_div_df */ 1101 COSTS_N_INSNS (4), /* int_mult_si */ 1102 COSTS_N_INSNS (11), /* int_mult_di */ 1103 COSTS_N_INSNS (36), /* int_div_si */ 1104 COSTS_N_INSNS (68), /* int_div_di */ 1105 1, /* branch_cost */ 1106 4 /* memory_latency */ 1107 }, 1108 { /* P5600 */ 1109 COSTS_N_INSNS (4), /* fp_add */ 1110 COSTS_N_INSNS (5), /* fp_mult_sf */ 1111 COSTS_N_INSNS (5), /* fp_mult_df */ 1112 COSTS_N_INSNS (17), /* fp_div_sf */ 1113 COSTS_N_INSNS (17), /* fp_div_df */ 1114 COSTS_N_INSNS (5), /* int_mult_si */ 1115 COSTS_N_INSNS (5), /* int_mult_di */ 1116 COSTS_N_INSNS (8), /* int_div_si */ 1117 COSTS_N_INSNS (8), /* int_div_di */ 1118 2, /* branch_cost */ 1119 4 /* memory_latency */ 1120 }, 1121 { /* M5100 */ 1122 COSTS_N_INSNS (4), /* fp_add */ 1123 COSTS_N_INSNS (4), /* fp_mult_sf */ 1124 COSTS_N_INSNS (5), /* fp_mult_df */ 1125 COSTS_N_INSNS (17), /* fp_div_sf */ 1126 COSTS_N_INSNS (32), /* fp_div_df */ 1127 COSTS_N_INSNS (5), /* int_mult_si */ 1128 COSTS_N_INSNS (5), /* int_mult_di */ 1129 COSTS_N_INSNS (34), /* int_div_si */ 1130 COSTS_N_INSNS (68), /* int_div_di */ 1131 1, /* branch_cost */ 1132 4 /* memory_latency */ 1133 }, 1134 { /* I6400 */ 1135 COSTS_N_INSNS (4), /* fp_add */ 1136 COSTS_N_INSNS (5), /* fp_mult_sf */ 1137 COSTS_N_INSNS (5), /* fp_mult_df */ 1138 COSTS_N_INSNS (32), /* fp_div_sf */ 1139 COSTS_N_INSNS (32), /* fp_div_df */ 1140 COSTS_N_INSNS (5), /* int_mult_si */ 1141 COSTS_N_INSNS (5), /* int_mult_di */ 1142 COSTS_N_INSNS (36), /* int_div_si */ 1143 COSTS_N_INSNS (36), /* int_div_di */ 1144 2, /* branch_cost */ 1145 4 /* memory_latency */ 1146 }, 1147 { /* P6600 */ 1148 COSTS_N_INSNS (4), /* fp_add */ 1149 COSTS_N_INSNS (5), /* fp_mult_sf */ 1150 COSTS_N_INSNS (5), /* fp_mult_df */ 1151 COSTS_N_INSNS (17), /* fp_div_sf */ 1152 COSTS_N_INSNS (17), /* fp_div_df */ 1153 COSTS_N_INSNS (5), /* int_mult_si */ 1154 COSTS_N_INSNS (5), /* int_mult_di */ 1155 COSTS_N_INSNS (8), /* int_div_si */ 1156 COSTS_N_INSNS (8), /* int_div_di */ 1157 2, /* branch_cost */ 1158 4 /* memory_latency */ 1159 } 1160 }; 1161 1162 static rtx mips_find_pic_call_symbol (rtx_insn *, rtx, bool); 1163 static int mips_register_move_cost (machine_mode, reg_class_t, 1164 reg_class_t); 1165 static unsigned int mips_function_arg_boundary (machine_mode, const_tree); 1166 static rtx mips_gen_const_int_vector_shuffle (machine_mode, int); 1167 1168 /* This hash table keeps track of implicit "mips16" and "nomips16" attributes 1169 for -mflip_mips16. It maps decl names onto a boolean mode setting. */ 1170 static GTY (()) hash_map<nofree_string_hash, bool> *mflip_mips16_htab; 1171 1172 /* True if -mflip-mips16 should next add an attribute for the default MIPS16 1173 mode, false if it should next add an attribute for the opposite mode. */ 1174 static GTY(()) bool mips16_flipper; 1175 1176 /* DECL is a function that needs a default "mips16" or "nomips16" attribute 1177 for -mflip-mips16. Return true if it should use "mips16" and false if 1178 it should use "nomips16". */ 1179 1180 static bool 1181 mflip_mips16_use_mips16_p (tree decl) 1182 { 1183 const char *name; 1184 bool base_is_mips16 = (mips_base_compression_flags & MASK_MIPS16) != 0; 1185 1186 /* Use the opposite of the command-line setting for anonymous decls. */ 1187 if (!DECL_NAME (decl)) 1188 return !base_is_mips16; 1189 1190 if (!mflip_mips16_htab) 1191 mflip_mips16_htab = hash_map<nofree_string_hash, bool>::create_ggc (37); 1192 1193 name = IDENTIFIER_POINTER (DECL_NAME (decl)); 1194 1195 bool existed; 1196 bool *slot = &mflip_mips16_htab->get_or_insert (name, &existed); 1197 if (!existed) 1198 { 1199 mips16_flipper = !mips16_flipper; 1200 *slot = mips16_flipper ? !base_is_mips16 : base_is_mips16; 1201 } 1202 return *slot; 1203 } 1204 1205 /* Predicates to test for presence of "near"/"short_call" and "far"/"long_call" 1206 attributes on the given TYPE. */ 1207 1208 static bool 1209 mips_near_type_p (const_tree type) 1210 { 1211 return (lookup_attribute ("short_call", TYPE_ATTRIBUTES (type)) != NULL 1212 || lookup_attribute ("near", TYPE_ATTRIBUTES (type)) != NULL); 1213 } 1214 1215 static bool 1216 mips_far_type_p (const_tree type) 1217 { 1218 return (lookup_attribute ("long_call", TYPE_ATTRIBUTES (type)) != NULL 1219 || lookup_attribute ("far", TYPE_ATTRIBUTES (type)) != NULL); 1220 } 1221 1222 1223 /* Check if the interrupt attribute is set for a function. */ 1224 1225 static bool 1226 mips_interrupt_type_p (tree type) 1227 { 1228 return lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type)) != NULL; 1229 } 1230 1231 /* Return the mask for the "interrupt" attribute. */ 1232 1233 static enum mips_int_mask 1234 mips_interrupt_mask (tree type) 1235 { 1236 tree attr = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type)); 1237 tree args, cst; 1238 const char *str; 1239 1240 /* For missing attributes or no arguments then return 'eic' as a safe 1241 fallback. */ 1242 if (attr == NULL) 1243 return INT_MASK_EIC; 1244 1245 args = TREE_VALUE (attr); 1246 1247 if (args == NULL) 1248 return INT_MASK_EIC; 1249 1250 cst = TREE_VALUE (args); 1251 1252 if (strcmp (TREE_STRING_POINTER (cst), "eic") == 0) 1253 return INT_MASK_EIC; 1254 1255 /* The validation code in mips_handle_interrupt_attr guarantees that the 1256 argument is now in the form: 1257 vector=(sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5). */ 1258 str = TREE_STRING_POINTER (cst); 1259 1260 gcc_assert (strlen (str) == strlen ("vector=sw0")); 1261 1262 if (str[7] == 's') 1263 return (enum mips_int_mask) (INT_MASK_SW0 + (str[9] - '0')); 1264 1265 return (enum mips_int_mask) (INT_MASK_HW0 + (str[9] - '0')); 1266 } 1267 1268 /* Return the mips_shadow_set if the "use_shadow_register_set" attribute is 1269 set for a function. */ 1270 1271 static enum mips_shadow_set 1272 mips_use_shadow_register_set (tree type) 1273 { 1274 tree attr = lookup_attribute ("use_shadow_register_set", 1275 TYPE_ATTRIBUTES (type)); 1276 tree args; 1277 1278 /* The validation code in mips_handle_use_shadow_register_set_attr guarantees 1279 that if an argument is present then it means: Assume the shadow register 1280 set has a valid stack pointer in it. */ 1281 if (attr == NULL) 1282 return SHADOW_SET_NO; 1283 1284 args = TREE_VALUE (attr); 1285 1286 if (args == NULL) 1287 return SHADOW_SET_YES; 1288 1289 return SHADOW_SET_INTSTACK; 1290 } 1291 1292 /* Check if the attribute to keep interrupts masked is set for a function. */ 1293 1294 static bool 1295 mips_keep_interrupts_masked_p (tree type) 1296 { 1297 return lookup_attribute ("keep_interrupts_masked", 1298 TYPE_ATTRIBUTES (type)) != NULL; 1299 } 1300 1301 /* Check if the attribute to use debug exception return is set for 1302 a function. */ 1303 1304 static bool 1305 mips_use_debug_exception_return_p (tree type) 1306 { 1307 return lookup_attribute ("use_debug_exception_return", 1308 TYPE_ATTRIBUTES (type)) != NULL; 1309 } 1310 1311 /* Return the set of compression modes that are explicitly required 1312 by the attributes in ATTRIBUTES. */ 1313 1314 static unsigned int 1315 mips_get_compress_on_flags (tree attributes) 1316 { 1317 unsigned int flags = 0; 1318 1319 if (lookup_attribute ("mips16", attributes) != NULL) 1320 flags |= MASK_MIPS16; 1321 1322 if (lookup_attribute ("micromips", attributes) != NULL) 1323 flags |= MASK_MICROMIPS; 1324 1325 return flags; 1326 } 1327 1328 /* Return the set of compression modes that are explicitly forbidden 1329 by the attributes in ATTRIBUTES. */ 1330 1331 static unsigned int 1332 mips_get_compress_off_flags (tree attributes) 1333 { 1334 unsigned int flags = 0; 1335 1336 if (lookup_attribute ("nocompression", attributes) != NULL) 1337 flags |= MASK_MIPS16 | MASK_MICROMIPS; 1338 1339 if (lookup_attribute ("nomips16", attributes) != NULL) 1340 flags |= MASK_MIPS16; 1341 1342 if (lookup_attribute ("nomicromips", attributes) != NULL) 1343 flags |= MASK_MICROMIPS; 1344 1345 return flags; 1346 } 1347 1348 /* Return the compression mode that should be used for function DECL. 1349 Return the ambient setting if DECL is null. */ 1350 1351 static unsigned int 1352 mips_get_compress_mode (tree decl) 1353 { 1354 unsigned int flags, force_on; 1355 1356 flags = mips_base_compression_flags; 1357 if (decl) 1358 { 1359 /* Nested functions must use the same frame pointer as their 1360 parent and must therefore use the same ISA mode. */ 1361 tree parent = decl_function_context (decl); 1362 if (parent) 1363 decl = parent; 1364 force_on = mips_get_compress_on_flags (DECL_ATTRIBUTES (decl)); 1365 if (force_on) 1366 return force_on; 1367 flags &= ~mips_get_compress_off_flags (DECL_ATTRIBUTES (decl)); 1368 } 1369 return flags; 1370 } 1371 1372 /* Return the attribute name associated with MASK_MIPS16 and MASK_MICROMIPS 1373 flags FLAGS. */ 1374 1375 static const char * 1376 mips_get_compress_on_name (unsigned int flags) 1377 { 1378 if (flags == MASK_MIPS16) 1379 return "mips16"; 1380 return "micromips"; 1381 } 1382 1383 /* Return the attribute name that forbids MASK_MIPS16 and MASK_MICROMIPS 1384 flags FLAGS. */ 1385 1386 static const char * 1387 mips_get_compress_off_name (unsigned int flags) 1388 { 1389 if (flags == MASK_MIPS16) 1390 return "nomips16"; 1391 if (flags == MASK_MICROMIPS) 1392 return "nomicromips"; 1393 return "nocompression"; 1394 } 1395 1396 /* Implement TARGET_COMP_TYPE_ATTRIBUTES. */ 1397 1398 static int 1399 mips_comp_type_attributes (const_tree type1, const_tree type2) 1400 { 1401 /* Disallow mixed near/far attributes. */ 1402 if (mips_far_type_p (type1) && mips_near_type_p (type2)) 1403 return 0; 1404 if (mips_near_type_p (type1) && mips_far_type_p (type2)) 1405 return 0; 1406 return 1; 1407 } 1408 1409 /* Implement TARGET_INSERT_ATTRIBUTES. */ 1410 1411 static void 1412 mips_insert_attributes (tree decl, tree *attributes) 1413 { 1414 const char *name; 1415 unsigned int compression_flags, nocompression_flags; 1416 1417 /* Check for "mips16" and "nomips16" attributes. */ 1418 compression_flags = mips_get_compress_on_flags (*attributes); 1419 nocompression_flags = mips_get_compress_off_flags (*attributes); 1420 1421 if (TREE_CODE (decl) != FUNCTION_DECL) 1422 { 1423 if (nocompression_flags) 1424 error ("%qs attribute only applies to functions", 1425 mips_get_compress_off_name (nocompression_flags)); 1426 1427 if (compression_flags) 1428 error ("%qs attribute only applies to functions", 1429 mips_get_compress_on_name (nocompression_flags)); 1430 } 1431 else 1432 { 1433 compression_flags |= mips_get_compress_on_flags (DECL_ATTRIBUTES (decl)); 1434 nocompression_flags |= 1435 mips_get_compress_off_flags (DECL_ATTRIBUTES (decl)); 1436 1437 if (compression_flags && nocompression_flags) 1438 error ("%qE cannot have both %qs and %qs attributes", 1439 DECL_NAME (decl), mips_get_compress_on_name (compression_flags), 1440 mips_get_compress_off_name (nocompression_flags)); 1441 1442 if (compression_flags & MASK_MIPS16 1443 && compression_flags & MASK_MICROMIPS) 1444 error ("%qE cannot have both %qs and %qs attributes", 1445 DECL_NAME (decl), "mips16", "micromips"); 1446 1447 if (TARGET_FLIP_MIPS16 1448 && !DECL_ARTIFICIAL (decl) 1449 && compression_flags == 0 1450 && nocompression_flags == 0) 1451 { 1452 /* Implement -mflip-mips16. If DECL has neither a "nomips16" nor a 1453 "mips16" attribute, arbitrarily pick one. We must pick the same 1454 setting for duplicate declarations of a function. */ 1455 name = mflip_mips16_use_mips16_p (decl) ? "mips16" : "nomips16"; 1456 *attributes = tree_cons (get_identifier (name), NULL, *attributes); 1457 name = "nomicromips"; 1458 *attributes = tree_cons (get_identifier (name), NULL, *attributes); 1459 } 1460 } 1461 } 1462 1463 /* Implement TARGET_MERGE_DECL_ATTRIBUTES. */ 1464 1465 static tree 1466 mips_merge_decl_attributes (tree olddecl, tree newdecl) 1467 { 1468 unsigned int diff; 1469 1470 diff = (mips_get_compress_on_flags (DECL_ATTRIBUTES (olddecl)) 1471 ^ mips_get_compress_on_flags (DECL_ATTRIBUTES (newdecl))); 1472 if (diff) 1473 error ("%qE redeclared with conflicting %qs attributes", 1474 DECL_NAME (newdecl), mips_get_compress_on_name (diff)); 1475 1476 diff = (mips_get_compress_off_flags (DECL_ATTRIBUTES (olddecl)) 1477 ^ mips_get_compress_off_flags (DECL_ATTRIBUTES (newdecl))); 1478 if (diff) 1479 error ("%qE redeclared with conflicting %qs attributes", 1480 DECL_NAME (newdecl), mips_get_compress_off_name (diff)); 1481 1482 return merge_attributes (DECL_ATTRIBUTES (olddecl), 1483 DECL_ATTRIBUTES (newdecl)); 1484 } 1485 1486 /* Implement TARGET_CAN_INLINE_P. */ 1487 1488 static bool 1489 mips_can_inline_p (tree caller, tree callee) 1490 { 1491 if (mips_get_compress_mode (callee) != mips_get_compress_mode (caller)) 1492 return false; 1493 return default_target_can_inline_p (caller, callee); 1494 } 1495 1496 /* Handle an "interrupt" attribute with an optional argument. */ 1497 1498 static tree 1499 mips_handle_interrupt_attr (tree *node ATTRIBUTE_UNUSED, tree name, tree args, 1500 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) 1501 { 1502 /* Check for an argument. */ 1503 if (is_attribute_p ("interrupt", name) && args != NULL) 1504 { 1505 tree cst; 1506 1507 cst = TREE_VALUE (args); 1508 if (TREE_CODE (cst) != STRING_CST) 1509 { 1510 warning (OPT_Wattributes, 1511 "%qE attribute requires a string argument", 1512 name); 1513 *no_add_attrs = true; 1514 } 1515 else if (strcmp (TREE_STRING_POINTER (cst), "eic") != 0 1516 && strncmp (TREE_STRING_POINTER (cst), "vector=", 7) != 0) 1517 { 1518 warning (OPT_Wattributes, 1519 "argument to %qE attribute is neither eic, nor " 1520 "vector=<line>", name); 1521 *no_add_attrs = true; 1522 } 1523 else if (strncmp (TREE_STRING_POINTER (cst), "vector=", 7) == 0) 1524 { 1525 const char *arg = TREE_STRING_POINTER (cst) + 7; 1526 1527 /* Acceptable names are: sw0,sw1,hw0,hw1,hw2,hw3,hw4,hw5. */ 1528 if (strlen (arg) != 3 1529 || (arg[0] != 's' && arg[0] != 'h') 1530 || arg[1] != 'w' 1531 || (arg[0] == 's' && arg[2] != '0' && arg[2] != '1') 1532 || (arg[0] == 'h' && (arg[2] < '0' || arg[2] > '5'))) 1533 { 1534 warning (OPT_Wattributes, 1535 "interrupt vector to %qE attribute is not " 1536 "vector=(sw0|sw1|hw0|hw1|hw2|hw3|hw4|hw5)", 1537 name); 1538 *no_add_attrs = true; 1539 } 1540 } 1541 1542 return NULL_TREE; 1543 } 1544 1545 return NULL_TREE; 1546 } 1547 1548 /* Handle a "use_shadow_register_set" attribute with an optional argument. */ 1549 1550 static tree 1551 mips_handle_use_shadow_register_set_attr (tree *node ATTRIBUTE_UNUSED, 1552 tree name, tree args, 1553 int flags ATTRIBUTE_UNUSED, 1554 bool *no_add_attrs) 1555 { 1556 /* Check for an argument. */ 1557 if (is_attribute_p ("use_shadow_register_set", name) && args != NULL) 1558 { 1559 tree cst; 1560 1561 cst = TREE_VALUE (args); 1562 if (TREE_CODE (cst) != STRING_CST) 1563 { 1564 warning (OPT_Wattributes, 1565 "%qE attribute requires a string argument", 1566 name); 1567 *no_add_attrs = true; 1568 } 1569 else if (strcmp (TREE_STRING_POINTER (cst), "intstack") != 0) 1570 { 1571 warning (OPT_Wattributes, 1572 "argument to %qE attribute is not intstack", name); 1573 *no_add_attrs = true; 1574 } 1575 1576 return NULL_TREE; 1577 } 1578 1579 return NULL_TREE; 1580 } 1581 1582 /* If X is a PLUS of a CONST_INT, return the two terms in *BASE_PTR 1583 and *OFFSET_PTR. Return X in *BASE_PTR and 0 in *OFFSET_PTR otherwise. */ 1584 1585 static void 1586 mips_split_plus (rtx x, rtx *base_ptr, HOST_WIDE_INT *offset_ptr) 1587 { 1588 if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1))) 1589 { 1590 *base_ptr = XEXP (x, 0); 1591 *offset_ptr = INTVAL (XEXP (x, 1)); 1592 } 1593 else 1594 { 1595 *base_ptr = x; 1596 *offset_ptr = 0; 1597 } 1598 } 1599 1600 static unsigned int mips_build_integer (struct mips_integer_op *, 1601 unsigned HOST_WIDE_INT); 1602 1603 /* A subroutine of mips_build_integer, with the same interface. 1604 Assume that the final action in the sequence should be a left shift. */ 1605 1606 static unsigned int 1607 mips_build_shift (struct mips_integer_op *codes, HOST_WIDE_INT value) 1608 { 1609 unsigned int i, shift; 1610 1611 /* Shift VALUE right until its lowest bit is set. Shift arithmetically 1612 since signed numbers are easier to load than unsigned ones. */ 1613 shift = 0; 1614 while ((value & 1) == 0) 1615 value /= 2, shift++; 1616 1617 i = mips_build_integer (codes, value); 1618 codes[i].code = ASHIFT; 1619 codes[i].value = shift; 1620 return i + 1; 1621 } 1622 1623 /* As for mips_build_shift, but assume that the final action will be 1624 an IOR or PLUS operation. */ 1625 1626 static unsigned int 1627 mips_build_lower (struct mips_integer_op *codes, unsigned HOST_WIDE_INT value) 1628 { 1629 unsigned HOST_WIDE_INT high; 1630 unsigned int i; 1631 1632 high = value & ~(unsigned HOST_WIDE_INT) 0xffff; 1633 if (!LUI_OPERAND (high) && (value & 0x18000) == 0x18000) 1634 { 1635 /* The constant is too complex to load with a simple LUI/ORI pair, 1636 so we want to give the recursive call as many trailing zeros as 1637 possible. In this case, we know bit 16 is set and that the 1638 low 16 bits form a negative number. If we subtract that number 1639 from VALUE, we will clear at least the lowest 17 bits, maybe more. */ 1640 i = mips_build_integer (codes, CONST_HIGH_PART (value)); 1641 codes[i].code = PLUS; 1642 codes[i].value = CONST_LOW_PART (value); 1643 } 1644 else 1645 { 1646 /* Either this is a simple LUI/ORI pair, or clearing the lowest 16 1647 bits gives a value with at least 17 trailing zeros. */ 1648 i = mips_build_integer (codes, high); 1649 codes[i].code = IOR; 1650 codes[i].value = value & 0xffff; 1651 } 1652 return i + 1; 1653 } 1654 1655 /* Fill CODES with a sequence of rtl operations to load VALUE. 1656 Return the number of operations needed. */ 1657 1658 static unsigned int 1659 mips_build_integer (struct mips_integer_op *codes, 1660 unsigned HOST_WIDE_INT value) 1661 { 1662 if (SMALL_OPERAND (value) 1663 || SMALL_OPERAND_UNSIGNED (value) 1664 || LUI_OPERAND (value)) 1665 { 1666 /* The value can be loaded with a single instruction. */ 1667 codes[0].code = UNKNOWN; 1668 codes[0].value = value; 1669 return 1; 1670 } 1671 else if ((value & 1) != 0 || LUI_OPERAND (CONST_HIGH_PART (value))) 1672 { 1673 /* Either the constant is a simple LUI/ORI combination or its 1674 lowest bit is set. We don't want to shift in this case. */ 1675 return mips_build_lower (codes, value); 1676 } 1677 else if ((value & 0xffff) == 0) 1678 { 1679 /* The constant will need at least three actions. The lowest 1680 16 bits are clear, so the final action will be a shift. */ 1681 return mips_build_shift (codes, value); 1682 } 1683 else 1684 { 1685 /* The final action could be a shift, add or inclusive OR. 1686 Rather than use a complex condition to select the best 1687 approach, try both mips_build_shift and mips_build_lower 1688 and pick the one that gives the shortest sequence. 1689 Note that this case is only used once per constant. */ 1690 struct mips_integer_op alt_codes[MIPS_MAX_INTEGER_OPS]; 1691 unsigned int cost, alt_cost; 1692 1693 cost = mips_build_shift (codes, value); 1694 alt_cost = mips_build_lower (alt_codes, value); 1695 if (alt_cost < cost) 1696 { 1697 memcpy (codes, alt_codes, alt_cost * sizeof (codes[0])); 1698 cost = alt_cost; 1699 } 1700 return cost; 1701 } 1702 } 1703 1704 /* Implement TARGET_LEGITIMATE_CONSTANT_P. */ 1705 1706 static bool 1707 mips_legitimate_constant_p (machine_mode mode ATTRIBUTE_UNUSED, rtx x) 1708 { 1709 return mips_const_insns (x) > 0; 1710 } 1711 1712 /* Return a SYMBOL_REF for a MIPS16 function called NAME. */ 1713 1714 static rtx 1715 mips16_stub_function (const char *name) 1716 { 1717 rtx x; 1718 1719 x = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name)); 1720 SYMBOL_REF_FLAGS (x) |= (SYMBOL_FLAG_EXTERNAL | SYMBOL_FLAG_FUNCTION); 1721 return x; 1722 } 1723 1724 /* Return a legitimate call address for STUB, given that STUB is a MIPS16 1725 support function. */ 1726 1727 static rtx 1728 mips16_stub_call_address (mips_one_only_stub *stub) 1729 { 1730 rtx fn = mips16_stub_function (stub->get_name ()); 1731 SYMBOL_REF_FLAGS (fn) |= SYMBOL_FLAG_LOCAL; 1732 if (!call_insn_operand (fn, VOIDmode)) 1733 fn = force_reg (Pmode, fn); 1734 return fn; 1735 } 1736 1737 /* A stub for moving the thread pointer into TLS_GET_TP_REGNUM. */ 1738 1739 class mips16_rdhwr_one_only_stub : public mips_one_only_stub 1740 { 1741 virtual const char *get_name (); 1742 virtual void output_body (); 1743 }; 1744 1745 const char * 1746 mips16_rdhwr_one_only_stub::get_name () 1747 { 1748 return "__mips16_rdhwr"; 1749 } 1750 1751 void 1752 mips16_rdhwr_one_only_stub::output_body () 1753 { 1754 fprintf (asm_out_file, 1755 "\t.set\tpush\n" 1756 "\t.set\tmips32r2\n" 1757 "\t.set\tnoreorder\n" 1758 "\trdhwr\t$3,$29\n" 1759 "\t.set\tpop\n" 1760 "\tj\t$31\n"); 1761 } 1762 1763 /* A stub for moving the FCSR into GET_FCSR_REGNUM. */ 1764 class mips16_get_fcsr_one_only_stub : public mips_one_only_stub 1765 { 1766 virtual const char *get_name (); 1767 virtual void output_body (); 1768 }; 1769 1770 const char * 1771 mips16_get_fcsr_one_only_stub::get_name () 1772 { 1773 return "__mips16_get_fcsr"; 1774 } 1775 1776 void 1777 mips16_get_fcsr_one_only_stub::output_body () 1778 { 1779 fprintf (asm_out_file, 1780 "\tcfc1\t%s,$31\n" 1781 "\tj\t$31\n", reg_names[GET_FCSR_REGNUM]); 1782 } 1783 1784 /* A stub for moving SET_FCSR_REGNUM into the FCSR. */ 1785 class mips16_set_fcsr_one_only_stub : public mips_one_only_stub 1786 { 1787 virtual const char *get_name (); 1788 virtual void output_body (); 1789 }; 1790 1791 const char * 1792 mips16_set_fcsr_one_only_stub::get_name () 1793 { 1794 return "__mips16_set_fcsr"; 1795 } 1796 1797 void 1798 mips16_set_fcsr_one_only_stub::output_body () 1799 { 1800 fprintf (asm_out_file, 1801 "\tctc1\t%s,$31\n" 1802 "\tj\t$31\n", reg_names[SET_FCSR_REGNUM]); 1803 } 1804 1805 /* Return true if symbols of type TYPE require a GOT access. */ 1806 1807 static bool 1808 mips_got_symbol_type_p (enum mips_symbol_type type) 1809 { 1810 switch (type) 1811 { 1812 case SYMBOL_GOT_PAGE_OFST: 1813 case SYMBOL_GOT_DISP: 1814 return true; 1815 1816 default: 1817 return false; 1818 } 1819 } 1820 1821 /* Return true if X is a thread-local symbol. */ 1822 1823 static bool 1824 mips_tls_symbol_p (rtx x) 1825 { 1826 return GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (x) != 0; 1827 } 1828 1829 /* Return true if SYMBOL_REF X is associated with a global symbol 1830 (in the STB_GLOBAL sense). */ 1831 1832 static bool 1833 mips_global_symbol_p (const_rtx x) 1834 { 1835 const_tree decl = SYMBOL_REF_DECL (x); 1836 1837 if (!decl) 1838 return !SYMBOL_REF_LOCAL_P (x) || SYMBOL_REF_EXTERNAL_P (x); 1839 1840 /* Weakref symbols are not TREE_PUBLIC, but their targets are global 1841 or weak symbols. Relocations in the object file will be against 1842 the target symbol, so it's that symbol's binding that matters here. */ 1843 return DECL_P (decl) && (TREE_PUBLIC (decl) || DECL_WEAK (decl)); 1844 } 1845 1846 /* Return true if function X is a libgcc MIPS16 stub function. */ 1847 1848 static bool 1849 mips16_stub_function_p (const_rtx x) 1850 { 1851 return (GET_CODE (x) == SYMBOL_REF 1852 && strncmp (XSTR (x, 0), "__mips16_", 9) == 0); 1853 } 1854 1855 /* Return true if function X is a locally-defined and locally-binding 1856 MIPS16 function. */ 1857 1858 static bool 1859 mips16_local_function_p (const_rtx x) 1860 { 1861 return (GET_CODE (x) == SYMBOL_REF 1862 && SYMBOL_REF_LOCAL_P (x) 1863 && !SYMBOL_REF_EXTERNAL_P (x) 1864 && (mips_get_compress_mode (SYMBOL_REF_DECL (x)) & MASK_MIPS16)); 1865 } 1866 1867 /* Return true if SYMBOL_REF X binds locally. */ 1868 1869 static bool 1870 mips_symbol_binds_local_p (const_rtx x) 1871 { 1872 return (SYMBOL_REF_DECL (x) 1873 ? targetm.binds_local_p (SYMBOL_REF_DECL (x)) 1874 : SYMBOL_REF_LOCAL_P (x)); 1875 } 1876 1877 /* Return true if OP is a constant vector with the number of units in MODE, 1878 and each unit has the same bit set. */ 1879 1880 bool 1881 mips_const_vector_bitimm_set_p (rtx op, machine_mode mode) 1882 { 1883 if (GET_CODE (op) == CONST_VECTOR && op != CONST0_RTX (mode)) 1884 { 1885 unsigned HOST_WIDE_INT val = UINTVAL (CONST_VECTOR_ELT (op, 0)); 1886 int vlog2 = exact_log2 (val & GET_MODE_MASK (GET_MODE_INNER (mode))); 1887 1888 if (vlog2 != -1) 1889 { 1890 gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT); 1891 gcc_assert (vlog2 >= 0 && vlog2 <= GET_MODE_UNIT_BITSIZE (mode) - 1); 1892 return mips_const_vector_same_val_p (op, mode); 1893 } 1894 } 1895 1896 return false; 1897 } 1898 1899 /* Return true if OP is a constant vector with the number of units in MODE, 1900 and each unit has the same bit clear. */ 1901 1902 bool 1903 mips_const_vector_bitimm_clr_p (rtx op, machine_mode mode) 1904 { 1905 if (GET_CODE (op) == CONST_VECTOR && op != CONSTM1_RTX (mode)) 1906 { 1907 unsigned HOST_WIDE_INT val = ~UINTVAL (CONST_VECTOR_ELT (op, 0)); 1908 int vlog2 = exact_log2 (val & GET_MODE_MASK (GET_MODE_INNER (mode))); 1909 1910 if (vlog2 != -1) 1911 { 1912 gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT); 1913 gcc_assert (vlog2 >= 0 && vlog2 <= GET_MODE_UNIT_BITSIZE (mode) - 1); 1914 return mips_const_vector_same_val_p (op, mode); 1915 } 1916 } 1917 1918 return false; 1919 } 1920 1921 /* Return true if OP is a constant vector with the number of units in MODE, 1922 and each unit has the same value. */ 1923 1924 bool 1925 mips_const_vector_same_val_p (rtx op, machine_mode mode) 1926 { 1927 int i, nunits = GET_MODE_NUNITS (mode); 1928 rtx first; 1929 1930 if (GET_CODE (op) != CONST_VECTOR || GET_MODE (op) != mode) 1931 return false; 1932 1933 first = CONST_VECTOR_ELT (op, 0); 1934 for (i = 1; i < nunits; i++) 1935 if (!rtx_equal_p (first, CONST_VECTOR_ELT (op, i))) 1936 return false; 1937 1938 return true; 1939 } 1940 1941 /* Return true if OP is a constant vector with the number of units in MODE, 1942 and each unit has the same value as well as replicated bytes in the value. 1943 */ 1944 1945 bool 1946 mips_const_vector_same_bytes_p (rtx op, machine_mode mode) 1947 { 1948 int i, bytes; 1949 HOST_WIDE_INT val, first_byte; 1950 rtx first; 1951 1952 if (!mips_const_vector_same_val_p (op, mode)) 1953 return false; 1954 1955 first = CONST_VECTOR_ELT (op, 0); 1956 bytes = GET_MODE_UNIT_SIZE (mode); 1957 val = INTVAL (first); 1958 first_byte = val & 0xff; 1959 for (i = 1; i < bytes; i++) 1960 { 1961 val >>= 8; 1962 if ((val & 0xff) != first_byte) 1963 return false; 1964 } 1965 1966 return true; 1967 } 1968 1969 /* Return true if OP is a constant vector with the number of units in MODE, 1970 and each unit has the same integer value in the range [LOW, HIGH]. */ 1971 1972 bool 1973 mips_const_vector_same_int_p (rtx op, machine_mode mode, HOST_WIDE_INT low, 1974 HOST_WIDE_INT high) 1975 { 1976 HOST_WIDE_INT value; 1977 rtx elem0; 1978 1979 if (!mips_const_vector_same_val_p (op, mode)) 1980 return false; 1981 1982 elem0 = CONST_VECTOR_ELT (op, 0); 1983 if (!CONST_INT_P (elem0)) 1984 return false; 1985 1986 value = INTVAL (elem0); 1987 return (value >= low && value <= high); 1988 } 1989 1990 /* Return true if OP is a constant vector with repeated 4-element sets 1991 in mode MODE. */ 1992 1993 bool 1994 mips_const_vector_shuffle_set_p (rtx op, machine_mode mode) 1995 { 1996 int nunits = GET_MODE_NUNITS (mode); 1997 int nsets = nunits / 4; 1998 int set = 0; 1999 int i, j; 2000 2001 /* Check if we have the same 4-element sets. */ 2002 for (j = 0; j < nsets; j++, set = 4 * j) 2003 for (i = 0; i < 4; i++) 2004 if ((INTVAL (XVECEXP (op, 0, i)) 2005 != (INTVAL (XVECEXP (op, 0, set + i)) - set)) 2006 || !IN_RANGE (INTVAL (XVECEXP (op, 0, set + i)), 0, set + 3)) 2007 return false; 2008 return true; 2009 } 2010 2011 /* Return true if rtx constants of mode MODE should be put into a small 2012 data section. */ 2013 2014 static bool 2015 mips_rtx_constant_in_small_data_p (machine_mode mode) 2016 { 2017 return (!TARGET_EMBEDDED_DATA 2018 && TARGET_LOCAL_SDATA 2019 && GET_MODE_SIZE (mode) <= mips_small_data_threshold); 2020 } 2021 2022 /* Return true if X should not be moved directly into register $25. 2023 We need this because many versions of GAS will treat "la $25,foo" as 2024 part of a call sequence and so allow a global "foo" to be lazily bound. */ 2025 2026 bool 2027 mips_dangerous_for_la25_p (rtx x) 2028 { 2029 return (!TARGET_EXPLICIT_RELOCS 2030 && TARGET_USE_GOT 2031 && GET_CODE (x) == SYMBOL_REF 2032 && mips_global_symbol_p (x)); 2033 } 2034 2035 /* Return true if calls to X might need $25 to be valid on entry. */ 2036 2037 bool 2038 mips_use_pic_fn_addr_reg_p (const_rtx x) 2039 { 2040 if (!TARGET_USE_PIC_FN_ADDR_REG) 2041 return false; 2042 2043 /* MIPS16 stub functions are guaranteed not to use $25. */ 2044 if (mips16_stub_function_p (x)) 2045 return false; 2046 2047 if (GET_CODE (x) == SYMBOL_REF) 2048 { 2049 /* If PLTs and copy relocations are available, the static linker 2050 will make sure that $25 is valid on entry to the target function. */ 2051 if (TARGET_ABICALLS_PIC0) 2052 return false; 2053 2054 /* Locally-defined functions use absolute accesses to set up 2055 the global pointer. */ 2056 if (TARGET_ABSOLUTE_ABICALLS 2057 && mips_symbol_binds_local_p (x) 2058 && !SYMBOL_REF_EXTERNAL_P (x)) 2059 return false; 2060 } 2061 2062 return true; 2063 } 2064 2065 /* Return the method that should be used to access SYMBOL_REF or 2066 LABEL_REF X in context CONTEXT. */ 2067 2068 static enum mips_symbol_type 2069 mips_classify_symbol (const_rtx x, enum mips_symbol_context context) 2070 { 2071 if (TARGET_RTP_PIC) 2072 return SYMBOL_GOT_DISP; 2073 2074 if (GET_CODE (x) == LABEL_REF) 2075 { 2076 /* Only return SYMBOL_PC_RELATIVE if we are generating MIPS16 2077 code and if we know that the label is in the current function's 2078 text section. LABEL_REFs are used for jump tables as well as 2079 text labels, so we must check whether jump tables live in the 2080 text section. */ 2081 if (TARGET_MIPS16_SHORT_JUMP_TABLES 2082 && !LABEL_REF_NONLOCAL_P (x)) 2083 return SYMBOL_PC_RELATIVE; 2084 2085 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS) 2086 return SYMBOL_GOT_PAGE_OFST; 2087 2088 return SYMBOL_ABSOLUTE; 2089 } 2090 2091 gcc_assert (GET_CODE (x) == SYMBOL_REF); 2092 2093 if (SYMBOL_REF_TLS_MODEL (x)) 2094 return SYMBOL_TLS; 2095 2096 if (CONSTANT_POOL_ADDRESS_P (x)) 2097 { 2098 if (TARGET_MIPS16_TEXT_LOADS) 2099 return SYMBOL_PC_RELATIVE; 2100 2101 if (TARGET_MIPS16_PCREL_LOADS && context == SYMBOL_CONTEXT_MEM) 2102 return SYMBOL_PC_RELATIVE; 2103 2104 if (mips_rtx_constant_in_small_data_p (get_pool_mode (x))) 2105 return SYMBOL_GP_RELATIVE; 2106 } 2107 2108 /* Do not use small-data accesses for weak symbols; they may end up 2109 being zero. */ 2110 if (TARGET_GPOPT && SYMBOL_REF_SMALL_P (x) && !SYMBOL_REF_WEAK (x)) 2111 return SYMBOL_GP_RELATIVE; 2112 2113 /* Don't use GOT accesses for locally-binding symbols when -mno-shared 2114 is in effect. */ 2115 if (TARGET_ABICALLS_PIC2 2116 && !(TARGET_ABSOLUTE_ABICALLS && mips_symbol_binds_local_p (x))) 2117 { 2118 /* There are three cases to consider: 2119 2120 - o32 PIC (either with or without explicit relocs) 2121 - n32/n64 PIC without explicit relocs 2122 - n32/n64 PIC with explicit relocs 2123 2124 In the first case, both local and global accesses will use an 2125 R_MIPS_GOT16 relocation. We must correctly predict which of 2126 the two semantics (local or global) the assembler and linker 2127 will apply. The choice depends on the symbol's binding rather 2128 than its visibility. 2129 2130 In the second case, the assembler will not use R_MIPS_GOT16 2131 relocations, but it chooses between local and global accesses 2132 in the same way as for o32 PIC. 2133 2134 In the third case we have more freedom since both forms of 2135 access will work for any kind of symbol. However, there seems 2136 little point in doing things differently. */ 2137 if (mips_global_symbol_p (x)) 2138 return SYMBOL_GOT_DISP; 2139 2140 return SYMBOL_GOT_PAGE_OFST; 2141 } 2142 2143 return SYMBOL_ABSOLUTE; 2144 } 2145 2146 /* Classify the base of symbolic expression X, given that X appears in 2147 context CONTEXT. */ 2148 2149 static enum mips_symbol_type 2150 mips_classify_symbolic_expression (rtx x, enum mips_symbol_context context) 2151 { 2152 rtx offset; 2153 2154 split_const (x, &x, &offset); 2155 if (UNSPEC_ADDRESS_P (x)) 2156 return UNSPEC_ADDRESS_TYPE (x); 2157 2158 return mips_classify_symbol (x, context); 2159 } 2160 2161 /* Return true if OFFSET is within the range [0, ALIGN), where ALIGN 2162 is the alignment in bytes of SYMBOL_REF X. */ 2163 2164 static bool 2165 mips_offset_within_alignment_p (rtx x, HOST_WIDE_INT offset) 2166 { 2167 HOST_WIDE_INT align; 2168 2169 align = SYMBOL_REF_DECL (x) ? DECL_ALIGN_UNIT (SYMBOL_REF_DECL (x)) : 1; 2170 return IN_RANGE (offset, 0, align - 1); 2171 } 2172 2173 /* Return true if X is a symbolic constant that can be used in context 2174 CONTEXT. If it is, store the type of the symbol in *SYMBOL_TYPE. */ 2175 2176 bool 2177 mips_symbolic_constant_p (rtx x, enum mips_symbol_context context, 2178 enum mips_symbol_type *symbol_type) 2179 { 2180 rtx offset; 2181 2182 split_const (x, &x, &offset); 2183 if (UNSPEC_ADDRESS_P (x)) 2184 { 2185 *symbol_type = UNSPEC_ADDRESS_TYPE (x); 2186 x = UNSPEC_ADDRESS (x); 2187 } 2188 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF) 2189 { 2190 *symbol_type = mips_classify_symbol (x, context); 2191 if (*symbol_type == SYMBOL_TLS) 2192 return false; 2193 } 2194 else 2195 return false; 2196 2197 if (offset == const0_rtx) 2198 return true; 2199 2200 /* Check whether a nonzero offset is valid for the underlying 2201 relocations. */ 2202 switch (*symbol_type) 2203 { 2204 case SYMBOL_ABSOLUTE: 2205 case SYMBOL_64_HIGH: 2206 case SYMBOL_64_MID: 2207 case SYMBOL_64_LOW: 2208 /* If the target has 64-bit pointers and the object file only 2209 supports 32-bit symbols, the values of those symbols will be 2210 sign-extended. In this case we can't allow an arbitrary offset 2211 in case the 32-bit value X + OFFSET has a different sign from X. */ 2212 if (Pmode == DImode && !ABI_HAS_64BIT_SYMBOLS) 2213 return offset_within_block_p (x, INTVAL (offset)); 2214 2215 /* In other cases the relocations can handle any offset. */ 2216 return true; 2217 2218 case SYMBOL_PC_RELATIVE: 2219 /* Allow constant pool references to be converted to LABEL+CONSTANT. 2220 In this case, we no longer have access to the underlying constant, 2221 but the original symbol-based access was known to be valid. */ 2222 if (GET_CODE (x) == LABEL_REF) 2223 return true; 2224 2225 /* Fall through. */ 2226 2227 case SYMBOL_GP_RELATIVE: 2228 /* Make sure that the offset refers to something within the 2229 same object block. This should guarantee that the final 2230 PC- or GP-relative offset is within the 16-bit limit. */ 2231 return offset_within_block_p (x, INTVAL (offset)); 2232 2233 case SYMBOL_GOT_PAGE_OFST: 2234 case SYMBOL_GOTOFF_PAGE: 2235 /* If the symbol is global, the GOT entry will contain the symbol's 2236 address, and we will apply a 16-bit offset after loading it. 2237 If the symbol is local, the linker should provide enough local 2238 GOT entries for a 16-bit offset, but larger offsets may lead 2239 to GOT overflow. */ 2240 return SMALL_INT (offset); 2241 2242 case SYMBOL_TPREL: 2243 case SYMBOL_DTPREL: 2244 /* There is no carry between the HI and LO REL relocations, so the 2245 offset is only valid if we know it won't lead to such a carry. */ 2246 return mips_offset_within_alignment_p (x, INTVAL (offset)); 2247 2248 case SYMBOL_GOT_DISP: 2249 case SYMBOL_GOTOFF_DISP: 2250 case SYMBOL_GOTOFF_CALL: 2251 case SYMBOL_GOTOFF_LOADGP: 2252 case SYMBOL_TLSGD: 2253 case SYMBOL_TLSLDM: 2254 case SYMBOL_GOTTPREL: 2255 case SYMBOL_TLS: 2256 case SYMBOL_HALF: 2257 return false; 2258 } 2259 gcc_unreachable (); 2260 } 2261 2262 /* Like mips_symbol_insns, but treat extended MIPS16 instructions as a 2263 single instruction. We rely on the fact that, in the worst case, 2264 all instructions involved in a MIPS16 address calculation are usually 2265 extended ones. */ 2266 2267 static int 2268 mips_symbol_insns_1 (enum mips_symbol_type type, machine_mode mode) 2269 { 2270 if (mips_use_pcrel_pool_p[(int) type]) 2271 { 2272 if (mode == MAX_MACHINE_MODE) 2273 /* LEAs will be converted into constant-pool references by 2274 mips_reorg. */ 2275 type = SYMBOL_PC_RELATIVE; 2276 else 2277 /* The constant must be loaded and then dereferenced. */ 2278 return 0; 2279 } 2280 2281 switch (type) 2282 { 2283 case SYMBOL_ABSOLUTE: 2284 /* When using 64-bit symbols, we need 5 preparatory instructions, 2285 such as: 2286 2287 lui $at,%highest(symbol) 2288 daddiu $at,$at,%higher(symbol) 2289 dsll $at,$at,16 2290 daddiu $at,$at,%hi(symbol) 2291 dsll $at,$at,16 2292 2293 The final address is then $at + %lo(symbol). With 32-bit 2294 symbols we just need a preparatory LUI for normal mode and 2295 a preparatory LI and SLL for MIPS16. */ 2296 return ABI_HAS_64BIT_SYMBOLS ? 6 : TARGET_MIPS16 ? 3 : 2; 2297 2298 case SYMBOL_GP_RELATIVE: 2299 /* Treat GP-relative accesses as taking a single instruction on 2300 MIPS16 too; the copy of $gp can often be shared. */ 2301 return 1; 2302 2303 case SYMBOL_PC_RELATIVE: 2304 /* PC-relative constants can be only be used with ADDIUPC, 2305 DADDIUPC, LWPC and LDPC. */ 2306 if (mode == MAX_MACHINE_MODE 2307 || GET_MODE_SIZE (mode) == 4 2308 || GET_MODE_SIZE (mode) == 8) 2309 return 1; 2310 2311 /* The constant must be loaded using ADDIUPC or DADDIUPC first. */ 2312 return 0; 2313 2314 case SYMBOL_GOT_DISP: 2315 /* The constant will have to be loaded from the GOT before it 2316 is used in an address. */ 2317 if (mode != MAX_MACHINE_MODE) 2318 return 0; 2319 2320 /* Fall through. */ 2321 2322 case SYMBOL_GOT_PAGE_OFST: 2323 /* Unless -funit-at-a-time is in effect, we can't be sure whether the 2324 local/global classification is accurate. The worst cases are: 2325 2326 (1) For local symbols when generating o32 or o64 code. The assembler 2327 will use: 2328 2329 lw $at,%got(symbol) 2330 nop 2331 2332 ...and the final address will be $at + %lo(symbol). 2333 2334 (2) For global symbols when -mxgot. The assembler will use: 2335 2336 lui $at,%got_hi(symbol) 2337 (d)addu $at,$at,$gp 2338 2339 ...and the final address will be $at + %got_lo(symbol). */ 2340 return 3; 2341 2342 case SYMBOL_GOTOFF_PAGE: 2343 case SYMBOL_GOTOFF_DISP: 2344 case SYMBOL_GOTOFF_CALL: 2345 case SYMBOL_GOTOFF_LOADGP: 2346 case SYMBOL_64_HIGH: 2347 case SYMBOL_64_MID: 2348 case SYMBOL_64_LOW: 2349 case SYMBOL_TLSGD: 2350 case SYMBOL_TLSLDM: 2351 case SYMBOL_DTPREL: 2352 case SYMBOL_GOTTPREL: 2353 case SYMBOL_TPREL: 2354 case SYMBOL_HALF: 2355 /* A 16-bit constant formed by a single relocation, or a 32-bit 2356 constant formed from a high 16-bit relocation and a low 16-bit 2357 relocation. Use mips_split_p to determine which. 32-bit 2358 constants need an "lui; addiu" sequence for normal mode and 2359 an "li; sll; addiu" sequence for MIPS16 mode. */ 2360 return !mips_split_p[type] ? 1 : TARGET_MIPS16 ? 3 : 2; 2361 2362 case SYMBOL_TLS: 2363 /* We don't treat a bare TLS symbol as a constant. */ 2364 return 0; 2365 } 2366 gcc_unreachable (); 2367 } 2368 2369 /* If MODE is MAX_MACHINE_MODE, return the number of instructions needed 2370 to load symbols of type TYPE into a register. Return 0 if the given 2371 type of symbol cannot be used as an immediate operand. 2372 2373 Otherwise, return the number of instructions needed to load or store 2374 values of mode MODE to or from addresses of type TYPE. Return 0 if 2375 the given type of symbol is not valid in addresses. 2376 2377 In both cases, instruction counts are based off BASE_INSN_LENGTH. */ 2378 2379 static int 2380 mips_symbol_insns (enum mips_symbol_type type, machine_mode mode) 2381 { 2382 /* MSA LD.* and ST.* cannot support loading symbols via an immediate 2383 operand. */ 2384 if (MSA_SUPPORTED_MODE_P (mode)) 2385 return 0; 2386 2387 return mips_symbol_insns_1 (type, mode) * (TARGET_MIPS16 ? 2 : 1); 2388 } 2389 2390 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */ 2391 2392 static bool 2393 mips_cannot_force_const_mem (machine_mode mode, rtx x) 2394 { 2395 enum mips_symbol_type type; 2396 rtx base, offset; 2397 2398 /* There is no assembler syntax for expressing an address-sized 2399 high part. */ 2400 if (GET_CODE (x) == HIGH) 2401 return true; 2402 2403 /* As an optimization, reject constants that mips_legitimize_move 2404 can expand inline. 2405 2406 Suppose we have a multi-instruction sequence that loads constant C 2407 into register R. If R does not get allocated a hard register, and 2408 R is used in an operand that allows both registers and memory 2409 references, reload will consider forcing C into memory and using 2410 one of the instruction's memory alternatives. Returning false 2411 here will force it to use an input reload instead. */ 2412 if ((CONST_INT_P (x) || GET_CODE (x) == CONST_VECTOR) 2413 && mips_legitimate_constant_p (mode, x)) 2414 return true; 2415 2416 split_const (x, &base, &offset); 2417 if (mips_symbolic_constant_p (base, SYMBOL_CONTEXT_LEA, &type)) 2418 { 2419 /* See whether we explicitly want these symbols in the pool. */ 2420 if (mips_use_pcrel_pool_p[(int) type]) 2421 return false; 2422 2423 /* The same optimization as for CONST_INT. */ 2424 if (SMALL_INT (offset) && mips_symbol_insns (type, MAX_MACHINE_MODE) > 0) 2425 return true; 2426 2427 /* If MIPS16 constant pools live in the text section, they should 2428 not refer to anything that might need run-time relocation. */ 2429 if (TARGET_MIPS16_PCREL_LOADS && mips_got_symbol_type_p (type)) 2430 return true; 2431 } 2432 2433 /* TLS symbols must be computed by mips_legitimize_move. */ 2434 if (tls_referenced_p (x)) 2435 return true; 2436 2437 return false; 2438 } 2439 2440 /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. We can't use blocks for 2441 constants when we're using a per-function constant pool. */ 2442 2443 static bool 2444 mips_use_blocks_for_constant_p (machine_mode mode ATTRIBUTE_UNUSED, 2445 const_rtx x ATTRIBUTE_UNUSED) 2446 { 2447 return !TARGET_MIPS16_PCREL_LOADS; 2448 } 2449 2450 /* Return true if register REGNO is a valid base register for mode MODE. 2451 STRICT_P is true if REG_OK_STRICT is in effect. */ 2452 2453 int 2454 mips_regno_mode_ok_for_base_p (int regno, machine_mode mode, 2455 bool strict_p) 2456 { 2457 if (!HARD_REGISTER_NUM_P (regno)) 2458 { 2459 if (!strict_p) 2460 return true; 2461 regno = reg_renumber[regno]; 2462 } 2463 2464 /* These fake registers will be eliminated to either the stack or 2465 hard frame pointer, both of which are usually valid base registers. 2466 Reload deals with the cases where the eliminated form isn't valid. */ 2467 if (regno == ARG_POINTER_REGNUM || regno == FRAME_POINTER_REGNUM) 2468 return true; 2469 2470 /* In MIPS16 mode, the stack pointer can only address word and doubleword 2471 values, nothing smaller. */ 2472 if (TARGET_MIPS16 && regno == STACK_POINTER_REGNUM) 2473 return GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8; 2474 2475 return TARGET_MIPS16 ? M16_REG_P (regno) : GP_REG_P (regno); 2476 } 2477 2478 /* Return true if X is a valid base register for mode MODE. 2479 STRICT_P is true if REG_OK_STRICT is in effect. */ 2480 2481 static bool 2482 mips_valid_base_register_p (rtx x, machine_mode mode, bool strict_p) 2483 { 2484 if (!strict_p && GET_CODE (x) == SUBREG) 2485 x = SUBREG_REG (x); 2486 2487 return (REG_P (x) 2488 && mips_regno_mode_ok_for_base_p (REGNO (x), mode, strict_p)); 2489 } 2490 2491 /* Return true if, for every base register BASE_REG, (plus BASE_REG X) 2492 can address a value of mode MODE. */ 2493 2494 static bool 2495 mips_valid_offset_p (rtx x, machine_mode mode) 2496 { 2497 /* Check that X is a signed 16-bit number. */ 2498 if (!const_arith_operand (x, Pmode)) 2499 return false; 2500 2501 /* We may need to split multiword moves, so make sure that every word 2502 is accessible. */ 2503 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD 2504 && !SMALL_OPERAND (INTVAL (x) + GET_MODE_SIZE (mode) - UNITS_PER_WORD)) 2505 return false; 2506 2507 /* MSA LD.* and ST.* supports 10-bit signed offsets. */ 2508 if (MSA_SUPPORTED_MODE_P (mode) 2509 && !mips_signed_immediate_p (INTVAL (x), 10, 2510 mips_ldst_scaled_shift (mode))) 2511 return false; 2512 2513 return true; 2514 } 2515 2516 /* Return true if a LO_SUM can address a value of mode MODE when the 2517 LO_SUM symbol has type SYMBOL_TYPE. */ 2518 2519 static bool 2520 mips_valid_lo_sum_p (enum mips_symbol_type symbol_type, machine_mode mode) 2521 { 2522 /* Check that symbols of type SYMBOL_TYPE can be used to access values 2523 of mode MODE. */ 2524 if (mips_symbol_insns (symbol_type, mode) == 0) 2525 return false; 2526 2527 /* Check that there is a known low-part relocation. */ 2528 if (mips_lo_relocs[symbol_type] == NULL) 2529 return false; 2530 2531 /* We may need to split multiword moves, so make sure that each word 2532 can be accessed without inducing a carry. This is mainly needed 2533 for o64, which has historically only guaranteed 64-bit alignment 2534 for 128-bit types. */ 2535 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD 2536 && GET_MODE_BITSIZE (mode) > GET_MODE_ALIGNMENT (mode)) 2537 return false; 2538 2539 /* MSA LD.* and ST.* cannot support loading symbols via %lo($base). */ 2540 if (MSA_SUPPORTED_MODE_P (mode)) 2541 return false; 2542 2543 return true; 2544 } 2545 2546 /* Return true if X is a valid address for machine mode MODE. If it is, 2547 fill in INFO appropriately. STRICT_P is true if REG_OK_STRICT is in 2548 effect. */ 2549 2550 static bool 2551 mips_classify_address (struct mips_address_info *info, rtx x, 2552 machine_mode mode, bool strict_p) 2553 { 2554 switch (GET_CODE (x)) 2555 { 2556 case REG: 2557 case SUBREG: 2558 info->type = ADDRESS_REG; 2559 info->reg = x; 2560 info->offset = const0_rtx; 2561 return mips_valid_base_register_p (info->reg, mode, strict_p); 2562 2563 case PLUS: 2564 info->type = ADDRESS_REG; 2565 info->reg = XEXP (x, 0); 2566 info->offset = XEXP (x, 1); 2567 return (mips_valid_base_register_p (info->reg, mode, strict_p) 2568 && mips_valid_offset_p (info->offset, mode)); 2569 2570 case LO_SUM: 2571 info->type = ADDRESS_LO_SUM; 2572 info->reg = XEXP (x, 0); 2573 info->offset = XEXP (x, 1); 2574 /* We have to trust the creator of the LO_SUM to do something vaguely 2575 sane. Target-independent code that creates a LO_SUM should also 2576 create and verify the matching HIGH. Target-independent code that 2577 adds an offset to a LO_SUM must prove that the offset will not 2578 induce a carry. Failure to do either of these things would be 2579 a bug, and we are not required to check for it here. The MIPS 2580 backend itself should only create LO_SUMs for valid symbolic 2581 constants, with the high part being either a HIGH or a copy 2582 of _gp. */ 2583 info->symbol_type 2584 = mips_classify_symbolic_expression (info->offset, SYMBOL_CONTEXT_MEM); 2585 return (mips_valid_base_register_p (info->reg, mode, strict_p) 2586 && mips_valid_lo_sum_p (info->symbol_type, mode)); 2587 2588 case CONST_INT: 2589 /* Small-integer addresses don't occur very often, but they 2590 are legitimate if $0 is a valid base register. */ 2591 info->type = ADDRESS_CONST_INT; 2592 return !TARGET_MIPS16 && SMALL_INT (x); 2593 2594 case CONST: 2595 case LABEL_REF: 2596 case SYMBOL_REF: 2597 info->type = ADDRESS_SYMBOLIC; 2598 return (mips_symbolic_constant_p (x, SYMBOL_CONTEXT_MEM, 2599 &info->symbol_type) 2600 && mips_symbol_insns (info->symbol_type, mode) > 0 2601 && !mips_split_p[info->symbol_type]); 2602 2603 default: 2604 return false; 2605 } 2606 } 2607 2608 /* Implement TARGET_LEGITIMATE_ADDRESS_P. */ 2609 2610 static bool 2611 mips_legitimate_address_p (machine_mode mode, rtx x, bool strict_p) 2612 { 2613 struct mips_address_info addr; 2614 2615 return mips_classify_address (&addr, x, mode, strict_p); 2616 } 2617 2618 /* Return true if X is a legitimate $sp-based address for mode MODE. */ 2619 2620 bool 2621 mips_stack_address_p (rtx x, machine_mode mode) 2622 { 2623 struct mips_address_info addr; 2624 2625 return (mips_classify_address (&addr, x, mode, false) 2626 && addr.type == ADDRESS_REG 2627 && addr.reg == stack_pointer_rtx); 2628 } 2629 2630 /* Return true if ADDR matches the pattern for the LWXS load scaled indexed 2631 address instruction. Note that such addresses are not considered 2632 legitimate in the TARGET_LEGITIMATE_ADDRESS_P sense, because their use 2633 is so restricted. */ 2634 2635 static bool 2636 mips_lwxs_address_p (rtx addr) 2637 { 2638 if (ISA_HAS_LWXS 2639 && GET_CODE (addr) == PLUS 2640 && REG_P (XEXP (addr, 1))) 2641 { 2642 rtx offset = XEXP (addr, 0); 2643 if (GET_CODE (offset) == MULT 2644 && REG_P (XEXP (offset, 0)) 2645 && CONST_INT_P (XEXP (offset, 1)) 2646 && INTVAL (XEXP (offset, 1)) == 4) 2647 return true; 2648 } 2649 return false; 2650 } 2651 2652 /* Return true if ADDR matches the pattern for the L{B,H,W,D}{,U}X load 2653 indexed address instruction. Note that such addresses are 2654 not considered legitimate in the TARGET_LEGITIMATE_ADDRESS_P 2655 sense, because their use is so restricted. */ 2656 2657 static bool 2658 mips_lx_address_p (rtx addr, machine_mode mode) 2659 { 2660 if (GET_CODE (addr) != PLUS 2661 || !REG_P (XEXP (addr, 0)) 2662 || !REG_P (XEXP (addr, 1))) 2663 return false; 2664 if (ISA_HAS_LBX && mode == QImode) 2665 return true; 2666 if (ISA_HAS_LHX && mode == HImode) 2667 return true; 2668 if (ISA_HAS_LWX && mode == SImode) 2669 return true; 2670 if (ISA_HAS_LDX && mode == DImode) 2671 return true; 2672 if (MSA_SUPPORTED_MODE_P (mode)) 2673 return true; 2674 return false; 2675 } 2676 2677 /* Return true if a value at OFFSET bytes from base register BASE can be 2678 accessed using an unextended MIPS16 instruction. MODE is the mode of 2679 the value. 2680 2681 Usually the offset in an unextended instruction is a 5-bit field. 2682 The offset is unsigned and shifted left once for LH and SH, twice 2683 for LW and SW, and so on. An exception is LWSP and SWSP, which have 2684 an 8-bit immediate field that's shifted left twice. */ 2685 2686 static bool 2687 mips16_unextended_reference_p (machine_mode mode, rtx base, 2688 unsigned HOST_WIDE_INT offset) 2689 { 2690 if (mode != BLKmode && offset % GET_MODE_SIZE (mode) == 0) 2691 { 2692 if (GET_MODE_SIZE (mode) == 4 && base == stack_pointer_rtx) 2693 return offset < 256U * GET_MODE_SIZE (mode); 2694 return offset < 32U * GET_MODE_SIZE (mode); 2695 } 2696 return false; 2697 } 2698 2699 /* Return the number of instructions needed to load or store a value 2700 of mode MODE at address X, assuming that BASE_INSN_LENGTH is the 2701 length of one instruction. Return 0 if X isn't valid for MODE. 2702 Assume that multiword moves may need to be split into word moves 2703 if MIGHT_SPLIT_P, otherwise assume that a single load or store is 2704 enough. */ 2705 2706 int 2707 mips_address_insns (rtx x, machine_mode mode, bool might_split_p) 2708 { 2709 struct mips_address_info addr; 2710 int factor; 2711 bool msa_p = (!might_split_p && MSA_SUPPORTED_MODE_P (mode)); 2712 2713 /* BLKmode is used for single unaligned loads and stores and should 2714 not count as a multiword mode. (GET_MODE_SIZE (BLKmode) is pretty 2715 meaningless, so we have to single it out as a special case one way 2716 or the other.) */ 2717 if (mode != BLKmode && might_split_p) 2718 factor = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; 2719 else 2720 factor = 1; 2721 2722 if (mips_classify_address (&addr, x, mode, false)) 2723 switch (addr.type) 2724 { 2725 case ADDRESS_REG: 2726 if (msa_p) 2727 { 2728 /* MSA LD.* and ST.* supports 10-bit signed offsets. */ 2729 if (mips_signed_immediate_p (INTVAL (addr.offset), 10, 2730 mips_ldst_scaled_shift (mode))) 2731 return 1; 2732 else 2733 return 0; 2734 } 2735 if (TARGET_MIPS16 2736 && !mips16_unextended_reference_p (mode, addr.reg, 2737 UINTVAL (addr.offset))) 2738 return factor * 2; 2739 return factor; 2740 2741 case ADDRESS_LO_SUM: 2742 return msa_p ? 0 : TARGET_MIPS16 ? factor * 2 : factor; 2743 2744 case ADDRESS_CONST_INT: 2745 return msa_p ? 0 : factor; 2746 2747 case ADDRESS_SYMBOLIC: 2748 return msa_p ? 0 : factor * mips_symbol_insns (addr.symbol_type, mode); 2749 } 2750 return 0; 2751 } 2752 2753 /* Return true if X fits within an unsigned field of BITS bits that is 2754 shifted left SHIFT bits before being used. */ 2755 2756 bool 2757 mips_unsigned_immediate_p (unsigned HOST_WIDE_INT x, int bits, int shift = 0) 2758 { 2759 return (x & ((1 << shift) - 1)) == 0 && x < ((unsigned) 1 << (shift + bits)); 2760 } 2761 2762 /* Return true if X fits within a signed field of BITS bits that is 2763 shifted left SHIFT bits before being used. */ 2764 2765 bool 2766 mips_signed_immediate_p (unsigned HOST_WIDE_INT x, int bits, int shift = 0) 2767 { 2768 x += 1 << (bits + shift - 1); 2769 return mips_unsigned_immediate_p (x, bits, shift); 2770 } 2771 2772 /* Return the scale shift that applied to MSA LD/ST address offset. */ 2773 2774 int 2775 mips_ldst_scaled_shift (machine_mode mode) 2776 { 2777 int shift = exact_log2 (GET_MODE_UNIT_SIZE (mode)); 2778 2779 if (shift < 0 || shift > 8) 2780 gcc_unreachable (); 2781 2782 return shift; 2783 } 2784 2785 /* Return true if X is legitimate for accessing values of mode MODE, 2786 if it is based on a MIPS16 register, and if the offset satisfies 2787 OFFSET_PREDICATE. */ 2788 2789 bool 2790 m16_based_address_p (rtx x, machine_mode mode, 2791 insn_operand_predicate_fn offset_predicate) 2792 { 2793 struct mips_address_info addr; 2794 2795 return (mips_classify_address (&addr, x, mode, false) 2796 && addr.type == ADDRESS_REG 2797 && M16_REG_P (REGNO (addr.reg)) 2798 && offset_predicate (addr.offset, mode)); 2799 } 2800 2801 /* Return true if X is a legitimate address that conforms to the requirements 2802 for a microMIPS LWSP or SWSP insn. */ 2803 2804 bool 2805 lwsp_swsp_address_p (rtx x, machine_mode mode) 2806 { 2807 struct mips_address_info addr; 2808 2809 return (mips_classify_address (&addr, x, mode, false) 2810 && addr.type == ADDRESS_REG 2811 && REGNO (addr.reg) == STACK_POINTER_REGNUM 2812 && uw5_operand (addr.offset, mode)); 2813 } 2814 2815 /* Return true if X is a legitimate address with a 12-bit offset. 2816 MODE is the mode of the value being accessed. */ 2817 2818 bool 2819 umips_12bit_offset_address_p (rtx x, machine_mode mode) 2820 { 2821 struct mips_address_info addr; 2822 2823 return (mips_classify_address (&addr, x, mode, false) 2824 && addr.type == ADDRESS_REG 2825 && CONST_INT_P (addr.offset) 2826 && UMIPS_12BIT_OFFSET_P (INTVAL (addr.offset))); 2827 } 2828 2829 /* Return true if X is a legitimate address with a 9-bit offset. 2830 MODE is the mode of the value being accessed. */ 2831 2832 bool 2833 mips_9bit_offset_address_p (rtx x, machine_mode mode) 2834 { 2835 struct mips_address_info addr; 2836 2837 return (mips_classify_address (&addr, x, mode, false) 2838 && addr.type == ADDRESS_REG 2839 && CONST_INT_P (addr.offset) 2840 && MIPS_9BIT_OFFSET_P (INTVAL (addr.offset))); 2841 } 2842 2843 /* Return the number of instructions needed to load constant X, 2844 assuming that BASE_INSN_LENGTH is the length of one instruction. 2845 Return 0 if X isn't a valid constant. */ 2846 2847 int 2848 mips_const_insns (rtx x) 2849 { 2850 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS]; 2851 enum mips_symbol_type symbol_type; 2852 rtx offset; 2853 2854 switch (GET_CODE (x)) 2855 { 2856 case HIGH: 2857 if (!mips_symbolic_constant_p (XEXP (x, 0), SYMBOL_CONTEXT_LEA, 2858 &symbol_type) 2859 || !mips_split_p[symbol_type]) 2860 return 0; 2861 2862 /* This is simply an LUI for normal mode. It is an extended 2863 LI followed by an extended SLL for MIPS16. */ 2864 return TARGET_MIPS16 ? 4 : 1; 2865 2866 case CONST_INT: 2867 if (TARGET_MIPS16) 2868 /* Unsigned 8-bit constants can be loaded using an unextended 2869 LI instruction. Unsigned 16-bit constants can be loaded 2870 using an extended LI. Negative constants must be loaded 2871 using LI and then negated. */ 2872 return (IN_RANGE (INTVAL (x), 0, 255) ? 1 2873 : SMALL_OPERAND_UNSIGNED (INTVAL (x)) ? 2 2874 : IN_RANGE (-INTVAL (x), 0, 255) ? 2 2875 : SMALL_OPERAND_UNSIGNED (-INTVAL (x)) ? 3 2876 : 0); 2877 2878 return mips_build_integer (codes, INTVAL (x)); 2879 2880 case CONST_VECTOR: 2881 if (ISA_HAS_MSA 2882 && mips_const_vector_same_int_p (x, GET_MODE (x), -512, 511)) 2883 return 1; 2884 /* Fall through. */ 2885 case CONST_DOUBLE: 2886 /* Allow zeros for normal mode, where we can use $0. */ 2887 return !TARGET_MIPS16 && x == CONST0_RTX (GET_MODE (x)) ? 1 : 0; 2888 2889 case CONST: 2890 if (CONST_GP_P (x)) 2891 return 1; 2892 2893 /* See if we can refer to X directly. */ 2894 if (mips_symbolic_constant_p (x, SYMBOL_CONTEXT_LEA, &symbol_type)) 2895 return mips_symbol_insns (symbol_type, MAX_MACHINE_MODE); 2896 2897 /* Otherwise try splitting the constant into a base and offset. 2898 If the offset is a 16-bit value, we can load the base address 2899 into a register and then use (D)ADDIU to add in the offset. 2900 If the offset is larger, we can load the base and offset 2901 into separate registers and add them together with (D)ADDU. 2902 However, the latter is only possible before reload; during 2903 and after reload, we must have the option of forcing the 2904 constant into the pool instead. */ 2905 split_const (x, &x, &offset); 2906 if (offset != 0) 2907 { 2908 int n = mips_const_insns (x); 2909 if (n != 0) 2910 { 2911 if (SMALL_INT (offset)) 2912 return n + 1; 2913 else if (!targetm.cannot_force_const_mem (GET_MODE (x), x)) 2914 return n + 1 + mips_build_integer (codes, INTVAL (offset)); 2915 } 2916 } 2917 return 0; 2918 2919 case SYMBOL_REF: 2920 case LABEL_REF: 2921 return mips_symbol_insns (mips_classify_symbol (x, SYMBOL_CONTEXT_LEA), 2922 MAX_MACHINE_MODE); 2923 2924 default: 2925 return 0; 2926 } 2927 } 2928 2929 /* X is a doubleword constant that can be handled by splitting it into 2930 two words and loading each word separately. Return the number of 2931 instructions required to do this, assuming that BASE_INSN_LENGTH 2932 is the length of one instruction. */ 2933 2934 int 2935 mips_split_const_insns (rtx x) 2936 { 2937 unsigned int low, high; 2938 2939 low = mips_const_insns (mips_subword (x, false)); 2940 high = mips_const_insns (mips_subword (x, true)); 2941 gcc_assert (low > 0 && high > 0); 2942 return low + high; 2943 } 2944 2945 /* Return one word of 128-bit value OP, taking into account the fixed 2946 endianness of certain registers. BYTE selects from the byte address. */ 2947 2948 rtx 2949 mips_subword_at_byte (rtx op, unsigned int byte) 2950 { 2951 machine_mode mode; 2952 2953 mode = GET_MODE (op); 2954 if (mode == VOIDmode) 2955 mode = TImode; 2956 2957 gcc_assert (!FP_REG_RTX_P (op)); 2958 2959 if (MEM_P (op)) 2960 return mips_rewrite_small_data (adjust_address (op, word_mode, byte)); 2961 2962 return simplify_gen_subreg (word_mode, op, mode, byte); 2963 } 2964 2965 /* Return the number of instructions needed to implement INSN, 2966 given that it loads from or stores to MEM. Assume that 2967 BASE_INSN_LENGTH is the length of one instruction. */ 2968 2969 int 2970 mips_load_store_insns (rtx mem, rtx_insn *insn) 2971 { 2972 machine_mode mode; 2973 bool might_split_p; 2974 rtx set; 2975 2976 gcc_assert (MEM_P (mem)); 2977 mode = GET_MODE (mem); 2978 2979 /* Try to prove that INSN does not need to be split. */ 2980 might_split_p = GET_MODE_SIZE (mode) > UNITS_PER_WORD; 2981 if (might_split_p) 2982 { 2983 set = single_set (insn); 2984 if (set && !mips_split_move_insn_p (SET_DEST (set), SET_SRC (set), insn)) 2985 might_split_p = false; 2986 } 2987 2988 return mips_address_insns (XEXP (mem, 0), mode, might_split_p); 2989 } 2990 2991 /* Return the number of instructions needed for an integer division, 2992 assuming that BASE_INSN_LENGTH is the length of one instruction. */ 2993 2994 int 2995 mips_idiv_insns (machine_mode mode) 2996 { 2997 int count; 2998 2999 count = 1; 3000 if (TARGET_CHECK_ZERO_DIV) 3001 { 3002 if (GENERATE_DIVIDE_TRAPS && !MSA_SUPPORTED_MODE_P (mode)) 3003 count++; 3004 else 3005 count += 2; 3006 } 3007 3008 if (TARGET_FIX_R4000 || TARGET_FIX_R4400) 3009 count++; 3010 return count; 3011 } 3012 3013 3014 /* Emit a move from SRC to DEST. Assume that the move expanders can 3015 handle all moves if !can_create_pseudo_p (). The distinction is 3016 important because, unlike emit_move_insn, the move expanders know 3017 how to force Pmode objects into the constant pool even when the 3018 constant pool address is not itself legitimate. */ 3019 3020 rtx_insn * 3021 mips_emit_move (rtx dest, rtx src) 3022 { 3023 return (can_create_pseudo_p () 3024 ? emit_move_insn (dest, src) 3025 : emit_move_insn_1 (dest, src)); 3026 } 3027 3028 /* Emit a move from SRC to DEST, splitting compound moves into individual 3029 instructions. SPLIT_TYPE is the type of split to perform. */ 3030 3031 static void 3032 mips_emit_move_or_split (rtx dest, rtx src, enum mips_split_type split_type) 3033 { 3034 if (mips_split_move_p (dest, src, split_type)) 3035 mips_split_move (dest, src, split_type, NULL); 3036 else 3037 mips_emit_move (dest, src); 3038 } 3039 3040 /* Emit an instruction of the form (set TARGET (CODE OP0)). */ 3041 3042 static void 3043 mips_emit_unary (enum rtx_code code, rtx target, rtx op0) 3044 { 3045 emit_insn (gen_rtx_SET (target, gen_rtx_fmt_e (code, GET_MODE (op0), op0))); 3046 } 3047 3048 /* Compute (CODE OP0) and store the result in a new register of mode MODE. 3049 Return that new register. */ 3050 3051 static rtx 3052 mips_force_unary (machine_mode mode, enum rtx_code code, rtx op0) 3053 { 3054 rtx reg; 3055 3056 reg = gen_reg_rtx (mode); 3057 mips_emit_unary (code, reg, op0); 3058 return reg; 3059 } 3060 3061 /* Emit an instruction of the form (set TARGET (CODE OP0 OP1)). */ 3062 3063 void 3064 mips_emit_binary (enum rtx_code code, rtx target, rtx op0, rtx op1) 3065 { 3066 emit_insn (gen_rtx_SET (target, gen_rtx_fmt_ee (code, GET_MODE (target), 3067 op0, op1))); 3068 } 3069 3070 /* Compute (CODE OP0 OP1) and store the result in a new register 3071 of mode MODE. Return that new register. */ 3072 3073 static rtx 3074 mips_force_binary (machine_mode mode, enum rtx_code code, rtx op0, rtx op1) 3075 { 3076 rtx reg; 3077 3078 reg = gen_reg_rtx (mode); 3079 mips_emit_binary (code, reg, op0, op1); 3080 return reg; 3081 } 3082 3083 /* Copy VALUE to a register and return that register. If new pseudos 3084 are allowed, copy it into a new register, otherwise use DEST. */ 3085 3086 static rtx 3087 mips_force_temporary (rtx dest, rtx value) 3088 { 3089 if (can_create_pseudo_p ()) 3090 return force_reg (Pmode, value); 3091 else 3092 { 3093 mips_emit_move (dest, value); 3094 return dest; 3095 } 3096 } 3097 3098 /* Emit a call sequence with call pattern PATTERN and return the call 3099 instruction itself (which is not necessarily the last instruction 3100 emitted). ORIG_ADDR is the original, unlegitimized address, 3101 ADDR is the legitimized form, and LAZY_P is true if the call 3102 address is lazily-bound. */ 3103 3104 static rtx_insn * 3105 mips_emit_call_insn (rtx pattern, rtx orig_addr, rtx addr, bool lazy_p) 3106 { 3107 rtx_insn *insn; 3108 rtx reg; 3109 3110 insn = emit_call_insn (pattern); 3111 3112 if (TARGET_MIPS16 && mips_use_pic_fn_addr_reg_p (orig_addr)) 3113 { 3114 /* MIPS16 JALRs only take MIPS16 registers. If the target 3115 function requires $25 to be valid on entry, we must copy it 3116 there separately. The move instruction can be put in the 3117 call's delay slot. */ 3118 reg = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM); 3119 emit_insn_before (gen_move_insn (reg, addr), insn); 3120 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), reg); 3121 } 3122 3123 if (lazy_p) 3124 /* Lazy-binding stubs require $gp to be valid on entry. */ 3125 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), pic_offset_table_rtx); 3126 3127 if (TARGET_USE_GOT) 3128 { 3129 /* See the comment above load_call<mode> for details. */ 3130 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), 3131 gen_rtx_REG (Pmode, GOT_VERSION_REGNUM)); 3132 emit_insn (gen_update_got_version ()); 3133 } 3134 3135 if (TARGET_MIPS16 3136 && TARGET_EXPLICIT_RELOCS 3137 && TARGET_CALL_CLOBBERED_GP) 3138 { 3139 rtx post_call_tmp_reg = gen_rtx_REG (word_mode, POST_CALL_TMP_REG); 3140 clobber_reg (&CALL_INSN_FUNCTION_USAGE (insn), post_call_tmp_reg); 3141 } 3142 3143 return insn; 3144 } 3145 3146 /* Wrap symbol or label BASE in an UNSPEC address of type SYMBOL_TYPE, 3147 then add CONST_INT OFFSET to the result. */ 3148 3149 static rtx 3150 mips_unspec_address_offset (rtx base, rtx offset, 3151 enum mips_symbol_type symbol_type) 3152 { 3153 base = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, base), 3154 UNSPEC_ADDRESS_FIRST + symbol_type); 3155 if (offset != const0_rtx) 3156 base = gen_rtx_PLUS (Pmode, base, offset); 3157 return gen_rtx_CONST (Pmode, base); 3158 } 3159 3160 /* Return an UNSPEC address with underlying address ADDRESS and symbol 3161 type SYMBOL_TYPE. */ 3162 3163 rtx 3164 mips_unspec_address (rtx address, enum mips_symbol_type symbol_type) 3165 { 3166 rtx base, offset; 3167 3168 split_const (address, &base, &offset); 3169 return mips_unspec_address_offset (base, offset, symbol_type); 3170 } 3171 3172 /* If OP is an UNSPEC address, return the address to which it refers, 3173 otherwise return OP itself. */ 3174 3175 rtx 3176 mips_strip_unspec_address (rtx op) 3177 { 3178 rtx base, offset; 3179 3180 split_const (op, &base, &offset); 3181 if (UNSPEC_ADDRESS_P (base)) 3182 op = plus_constant (Pmode, UNSPEC_ADDRESS (base), INTVAL (offset)); 3183 return op; 3184 } 3185 3186 /* If mips_unspec_address (ADDR, SYMBOL_TYPE) is a 32-bit value, add the 3187 high part to BASE and return the result. Just return BASE otherwise. 3188 TEMP is as for mips_force_temporary. 3189 3190 The returned expression can be used as the first operand to a LO_SUM. */ 3191 3192 static rtx 3193 mips_unspec_offset_high (rtx temp, rtx base, rtx addr, 3194 enum mips_symbol_type symbol_type) 3195 { 3196 if (mips_split_p[symbol_type]) 3197 { 3198 addr = gen_rtx_HIGH (Pmode, mips_unspec_address (addr, symbol_type)); 3199 addr = mips_force_temporary (temp, addr); 3200 base = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, addr, base)); 3201 } 3202 return base; 3203 } 3204 3205 /* Return an instruction that copies $gp into register REG. We want 3206 GCC to treat the register's value as constant, so that its value 3207 can be rematerialized on demand. */ 3208 3209 static rtx 3210 gen_load_const_gp (rtx reg) 3211 { 3212 return PMODE_INSN (gen_load_const_gp, (reg)); 3213 } 3214 3215 /* Return a pseudo register that contains the value of $gp throughout 3216 the current function. Such registers are needed by MIPS16 functions, 3217 for which $gp itself is not a valid base register or addition operand. */ 3218 3219 static rtx 3220 mips16_gp_pseudo_reg (void) 3221 { 3222 if (cfun->machine->mips16_gp_pseudo_rtx == NULL_RTX) 3223 { 3224 rtx_insn *scan; 3225 3226 cfun->machine->mips16_gp_pseudo_rtx = gen_reg_rtx (Pmode); 3227 3228 push_topmost_sequence (); 3229 3230 scan = get_insns (); 3231 while (NEXT_INSN (scan) && !INSN_P (NEXT_INSN (scan))) 3232 scan = NEXT_INSN (scan); 3233 3234 rtx set = gen_load_const_gp (cfun->machine->mips16_gp_pseudo_rtx); 3235 rtx_insn *insn = emit_insn_after (set, scan); 3236 INSN_LOCATION (insn) = 0; 3237 3238 pop_topmost_sequence (); 3239 } 3240 3241 return cfun->machine->mips16_gp_pseudo_rtx; 3242 } 3243 3244 /* Return a base register that holds pic_offset_table_rtx. 3245 TEMP, if nonnull, is a scratch Pmode base register. */ 3246 3247 rtx 3248 mips_pic_base_register (rtx temp) 3249 { 3250 if (!TARGET_MIPS16) 3251 return pic_offset_table_rtx; 3252 3253 if (currently_expanding_to_rtl) 3254 return mips16_gp_pseudo_reg (); 3255 3256 if (can_create_pseudo_p ()) 3257 temp = gen_reg_rtx (Pmode); 3258 3259 if (TARGET_USE_GOT) 3260 /* The first post-reload split exposes all references to $gp 3261 (both uses and definitions). All references must remain 3262 explicit after that point. 3263 3264 It is safe to introduce uses of $gp at any time, so for 3265 simplicity, we do that before the split too. */ 3266 mips_emit_move (temp, pic_offset_table_rtx); 3267 else 3268 emit_insn (gen_load_const_gp (temp)); 3269 return temp; 3270 } 3271 3272 /* Return the RHS of a load_call<mode> insn. */ 3273 3274 static rtx 3275 mips_unspec_call (rtx reg, rtx symbol) 3276 { 3277 rtvec vec; 3278 3279 vec = gen_rtvec (3, reg, symbol, gen_rtx_REG (SImode, GOT_VERSION_REGNUM)); 3280 return gen_rtx_UNSPEC (Pmode, vec, UNSPEC_LOAD_CALL); 3281 } 3282 3283 /* If SRC is the RHS of a load_call<mode> insn, return the underlying symbol 3284 reference. Return NULL_RTX otherwise. */ 3285 3286 static rtx 3287 mips_strip_unspec_call (rtx src) 3288 { 3289 if (GET_CODE (src) == UNSPEC && XINT (src, 1) == UNSPEC_LOAD_CALL) 3290 return mips_strip_unspec_address (XVECEXP (src, 0, 1)); 3291 return NULL_RTX; 3292 } 3293 3294 /* Create and return a GOT reference of type TYPE for address ADDR. 3295 TEMP, if nonnull, is a scratch Pmode base register. */ 3296 3297 rtx 3298 mips_got_load (rtx temp, rtx addr, enum mips_symbol_type type) 3299 { 3300 rtx base, high, lo_sum_symbol; 3301 3302 base = mips_pic_base_register (temp); 3303 3304 /* If we used the temporary register to load $gp, we can't use 3305 it for the high part as well. */ 3306 if (temp != NULL && reg_overlap_mentioned_p (base, temp)) 3307 temp = NULL; 3308 3309 high = mips_unspec_offset_high (temp, base, addr, type); 3310 lo_sum_symbol = mips_unspec_address (addr, type); 3311 3312 if (type == SYMBOL_GOTOFF_CALL) 3313 return mips_unspec_call (high, lo_sum_symbol); 3314 else 3315 return PMODE_INSN (gen_unspec_got, (high, lo_sum_symbol)); 3316 } 3317 3318 /* If MODE is MAX_MACHINE_MODE, ADDR appears as a move operand, otherwise 3319 it appears in a MEM of that mode. Return true if ADDR is a legitimate 3320 constant in that context and can be split into high and low parts. 3321 If so, and if LOW_OUT is nonnull, emit the high part and store the 3322 low part in *LOW_OUT. Leave *LOW_OUT unchanged otherwise. 3323 3324 TEMP is as for mips_force_temporary and is used to load the high 3325 part into a register. 3326 3327 When MODE is MAX_MACHINE_MODE, the low part is guaranteed to be 3328 a legitimize SET_SRC for an .md pattern, otherwise the low part 3329 is guaranteed to be a legitimate address for mode MODE. */ 3330 3331 bool 3332 mips_split_symbol (rtx temp, rtx addr, machine_mode mode, rtx *low_out) 3333 { 3334 enum mips_symbol_context context; 3335 enum mips_symbol_type symbol_type; 3336 rtx high; 3337 3338 context = (mode == MAX_MACHINE_MODE 3339 ? SYMBOL_CONTEXT_LEA 3340 : SYMBOL_CONTEXT_MEM); 3341 if (GET_CODE (addr) == HIGH && context == SYMBOL_CONTEXT_LEA) 3342 { 3343 addr = XEXP (addr, 0); 3344 if (mips_symbolic_constant_p (addr, context, &symbol_type) 3345 && mips_symbol_insns (symbol_type, mode) > 0 3346 && mips_split_hi_p[symbol_type]) 3347 { 3348 if (low_out) 3349 switch (symbol_type) 3350 { 3351 case SYMBOL_GOT_PAGE_OFST: 3352 /* The high part of a page/ofst pair is loaded from the GOT. */ 3353 *low_out = mips_got_load (temp, addr, SYMBOL_GOTOFF_PAGE); 3354 break; 3355 3356 default: 3357 gcc_unreachable (); 3358 } 3359 return true; 3360 } 3361 } 3362 else 3363 { 3364 if (mips_symbolic_constant_p (addr, context, &symbol_type) 3365 && mips_symbol_insns (symbol_type, mode) > 0 3366 && mips_split_p[symbol_type]) 3367 { 3368 if (low_out) 3369 switch (symbol_type) 3370 { 3371 case SYMBOL_GOT_DISP: 3372 /* SYMBOL_GOT_DISP symbols are loaded from the GOT. */ 3373 *low_out = mips_got_load (temp, addr, SYMBOL_GOTOFF_DISP); 3374 break; 3375 3376 case SYMBOL_GP_RELATIVE: 3377 high = mips_pic_base_register (temp); 3378 *low_out = gen_rtx_LO_SUM (Pmode, high, addr); 3379 break; 3380 3381 default: 3382 high = gen_rtx_HIGH (Pmode, copy_rtx (addr)); 3383 high = mips_force_temporary (temp, high); 3384 *low_out = gen_rtx_LO_SUM (Pmode, high, addr); 3385 break; 3386 } 3387 return true; 3388 } 3389 } 3390 return false; 3391 } 3392 3393 /* Return a legitimate address for REG + OFFSET. TEMP is as for 3394 mips_force_temporary; it is only needed when OFFSET is not a 3395 SMALL_OPERAND. */ 3396 3397 static rtx 3398 mips_add_offset (rtx temp, rtx reg, HOST_WIDE_INT offset) 3399 { 3400 if (!SMALL_OPERAND (offset)) 3401 { 3402 rtx high; 3403 3404 if (TARGET_MIPS16) 3405 { 3406 /* Load the full offset into a register so that we can use 3407 an unextended instruction for the address itself. */ 3408 high = GEN_INT (offset); 3409 offset = 0; 3410 } 3411 else 3412 { 3413 /* Leave OFFSET as a 16-bit offset and put the excess in HIGH. 3414 The addition inside the macro CONST_HIGH_PART may cause an 3415 overflow, so we need to force a sign-extension check. */ 3416 high = gen_int_mode (CONST_HIGH_PART (offset), Pmode); 3417 offset = CONST_LOW_PART (offset); 3418 } 3419 high = mips_force_temporary (temp, high); 3420 reg = mips_force_temporary (temp, gen_rtx_PLUS (Pmode, high, reg)); 3421 } 3422 return plus_constant (Pmode, reg, offset); 3423 } 3424 3425 /* The __tls_get_attr symbol. */ 3426 static GTY(()) rtx mips_tls_symbol; 3427 3428 /* Return an instruction sequence that calls __tls_get_addr. SYM is 3429 the TLS symbol we are referencing and TYPE is the symbol type to use 3430 (either global dynamic or local dynamic). V0 is an RTX for the 3431 return value location. */ 3432 3433 static rtx_insn * 3434 mips_call_tls_get_addr (rtx sym, enum mips_symbol_type type, rtx v0) 3435 { 3436 rtx loc, a0; 3437 rtx_insn *insn; 3438 3439 a0 = gen_rtx_REG (Pmode, GP_ARG_FIRST); 3440 3441 if (!mips_tls_symbol) 3442 mips_tls_symbol = init_one_libfunc ("__tls_get_addr"); 3443 3444 loc = mips_unspec_address (sym, type); 3445 3446 start_sequence (); 3447 3448 emit_insn (gen_rtx_SET (a0, gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, 3449 loc))); 3450 insn = mips_expand_call (MIPS_CALL_NORMAL, v0, mips_tls_symbol, 3451 const0_rtx, NULL_RTX, false); 3452 RTL_CONST_CALL_P (insn) = 1; 3453 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0); 3454 insn = get_insns (); 3455 3456 end_sequence (); 3457 3458 return insn; 3459 } 3460 3461 /* Return a pseudo register that contains the current thread pointer. */ 3462 3463 rtx 3464 mips_expand_thread_pointer (rtx tp) 3465 { 3466 rtx fn; 3467 3468 if (TARGET_MIPS16) 3469 { 3470 if (!mips16_rdhwr_stub) 3471 mips16_rdhwr_stub = new mips16_rdhwr_one_only_stub (); 3472 fn = mips16_stub_call_address (mips16_rdhwr_stub); 3473 emit_insn (PMODE_INSN (gen_tls_get_tp_mips16, (tp, fn))); 3474 } 3475 else 3476 emit_insn (PMODE_INSN (gen_tls_get_tp, (tp))); 3477 return tp; 3478 } 3479 3480 static rtx 3481 mips_get_tp (void) 3482 { 3483 return mips_expand_thread_pointer (gen_reg_rtx (Pmode)); 3484 } 3485 3486 /* Generate the code to access LOC, a thread-local SYMBOL_REF, and return 3487 its address. The return value will be both a valid address and a valid 3488 SET_SRC (either a REG or a LO_SUM). */ 3489 3490 static rtx 3491 mips_legitimize_tls_address (rtx loc) 3492 { 3493 rtx dest, v0, tp, tmp1, tmp2, eqv, offset; 3494 enum tls_model model; 3495 3496 model = SYMBOL_REF_TLS_MODEL (loc); 3497 /* Only TARGET_ABICALLS code can have more than one module; other 3498 code must be static and should not use a GOT. All TLS models 3499 reduce to local exec in this situation. */ 3500 if (!TARGET_ABICALLS) 3501 model = TLS_MODEL_LOCAL_EXEC; 3502 3503 switch (model) 3504 { 3505 case TLS_MODEL_GLOBAL_DYNAMIC: 3506 { 3507 v0 = gen_rtx_REG (Pmode, GP_RETURN); 3508 rtx_insn *insn = mips_call_tls_get_addr (loc, SYMBOL_TLSGD, v0); 3509 dest = gen_reg_rtx (Pmode); 3510 emit_libcall_block (insn, dest, v0, loc); 3511 break; 3512 } 3513 3514 case TLS_MODEL_LOCAL_DYNAMIC: 3515 { 3516 v0 = gen_rtx_REG (Pmode, GP_RETURN); 3517 rtx_insn *insn = mips_call_tls_get_addr (loc, SYMBOL_TLSLDM, v0); 3518 tmp1 = gen_reg_rtx (Pmode); 3519 3520 /* Attach a unique REG_EQUIV, to allow the RTL optimizers to 3521 share the LDM result with other LD model accesses. */ 3522 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx), 3523 UNSPEC_TLS_LDM); 3524 emit_libcall_block (insn, tmp1, v0, eqv); 3525 3526 offset = mips_unspec_address (loc, SYMBOL_DTPREL); 3527 if (mips_split_p[SYMBOL_DTPREL]) 3528 { 3529 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_DTPREL); 3530 dest = gen_rtx_LO_SUM (Pmode, tmp2, offset); 3531 } 3532 else 3533 dest = expand_binop (Pmode, add_optab, tmp1, offset, 3534 0, 0, OPTAB_DIRECT); 3535 break; 3536 } 3537 3538 case TLS_MODEL_INITIAL_EXEC: 3539 tp = mips_get_tp (); 3540 tmp1 = gen_reg_rtx (Pmode); 3541 tmp2 = mips_unspec_address (loc, SYMBOL_GOTTPREL); 3542 if (Pmode == DImode) 3543 emit_insn (gen_load_gotdi (tmp1, pic_offset_table_rtx, tmp2)); 3544 else 3545 emit_insn (gen_load_gotsi (tmp1, pic_offset_table_rtx, tmp2)); 3546 dest = gen_reg_rtx (Pmode); 3547 emit_insn (gen_add3_insn (dest, tmp1, tp)); 3548 break; 3549 3550 case TLS_MODEL_LOCAL_EXEC: 3551 tmp1 = mips_get_tp (); 3552 offset = mips_unspec_address (loc, SYMBOL_TPREL); 3553 if (mips_split_p[SYMBOL_TPREL]) 3554 { 3555 tmp2 = mips_unspec_offset_high (NULL, tmp1, loc, SYMBOL_TPREL); 3556 dest = gen_rtx_LO_SUM (Pmode, tmp2, offset); 3557 } 3558 else 3559 dest = expand_binop (Pmode, add_optab, tmp1, offset, 3560 0, 0, OPTAB_DIRECT); 3561 break; 3562 3563 default: 3564 gcc_unreachable (); 3565 } 3566 return dest; 3567 } 3568 3569 /* Implement "TARGET = __builtin_mips_get_fcsr ()" for MIPS16, 3570 using a stub. */ 3571 3572 void 3573 mips16_expand_get_fcsr (rtx target) 3574 { 3575 if (!mips16_get_fcsr_stub) 3576 mips16_get_fcsr_stub = new mips16_get_fcsr_one_only_stub (); 3577 rtx fn = mips16_stub_call_address (mips16_get_fcsr_stub); 3578 emit_insn (PMODE_INSN (gen_mips_get_fcsr_mips16, (fn))); 3579 emit_move_insn (target, gen_rtx_REG (SImode, GET_FCSR_REGNUM)); 3580 } 3581 3582 /* Implement __builtin_mips_set_fcsr (TARGET) for MIPS16, using a stub. */ 3583 3584 void 3585 mips16_expand_set_fcsr (rtx newval) 3586 { 3587 if (!mips16_set_fcsr_stub) 3588 mips16_set_fcsr_stub = new mips16_set_fcsr_one_only_stub (); 3589 rtx fn = mips16_stub_call_address (mips16_set_fcsr_stub); 3590 emit_move_insn (gen_rtx_REG (SImode, SET_FCSR_REGNUM), newval); 3591 emit_insn (PMODE_INSN (gen_mips_set_fcsr_mips16, (fn))); 3592 } 3593 3594 /* If X is not a valid address for mode MODE, force it into a register. */ 3595 3596 static rtx 3597 mips_force_address (rtx x, machine_mode mode) 3598 { 3599 if (!mips_legitimate_address_p (mode, x, false)) 3600 x = force_reg (Pmode, x); 3601 return x; 3602 } 3603 3604 /* This function is used to implement LEGITIMIZE_ADDRESS. If X can 3605 be legitimized in a way that the generic machinery might not expect, 3606 return a new address, otherwise return NULL. MODE is the mode of 3607 the memory being accessed. */ 3608 3609 static rtx 3610 mips_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, 3611 machine_mode mode) 3612 { 3613 rtx base, addr; 3614 HOST_WIDE_INT offset; 3615 3616 if (mips_tls_symbol_p (x)) 3617 return mips_legitimize_tls_address (x); 3618 3619 /* See if the address can split into a high part and a LO_SUM. */ 3620 if (mips_split_symbol (NULL, x, mode, &addr)) 3621 return mips_force_address (addr, mode); 3622 3623 /* Handle BASE + OFFSET using mips_add_offset. */ 3624 mips_split_plus (x, &base, &offset); 3625 if (offset != 0) 3626 { 3627 if (!mips_valid_base_register_p (base, mode, false)) 3628 base = copy_to_mode_reg (Pmode, base); 3629 addr = mips_add_offset (NULL, base, offset); 3630 return mips_force_address (addr, mode); 3631 } 3632 3633 return x; 3634 } 3635 3636 /* Load VALUE into DEST. TEMP is as for mips_force_temporary. */ 3637 3638 void 3639 mips_move_integer (rtx temp, rtx dest, unsigned HOST_WIDE_INT value) 3640 { 3641 struct mips_integer_op codes[MIPS_MAX_INTEGER_OPS]; 3642 machine_mode mode; 3643 unsigned int i, num_ops; 3644 rtx x; 3645 3646 mode = GET_MODE (dest); 3647 num_ops = mips_build_integer (codes, value); 3648 3649 /* Apply each binary operation to X. Invariant: X is a legitimate 3650 source operand for a SET pattern. */ 3651 x = GEN_INT (codes[0].value); 3652 for (i = 1; i < num_ops; i++) 3653 { 3654 if (!can_create_pseudo_p ()) 3655 { 3656 emit_insn (gen_rtx_SET (temp, x)); 3657 x = temp; 3658 } 3659 else 3660 x = force_reg (mode, x); 3661 x = gen_rtx_fmt_ee (codes[i].code, mode, x, GEN_INT (codes[i].value)); 3662 } 3663 3664 emit_insn (gen_rtx_SET (dest, x)); 3665 } 3666 3667 /* Subroutine of mips_legitimize_move. Move constant SRC into register 3668 DEST given that SRC satisfies immediate_operand but doesn't satisfy 3669 move_operand. */ 3670 3671 static void 3672 mips_legitimize_const_move (machine_mode mode, rtx dest, rtx src) 3673 { 3674 rtx base, offset; 3675 3676 /* Split moves of big integers into smaller pieces. */ 3677 if (splittable_const_int_operand (src, mode)) 3678 { 3679 mips_move_integer (dest, dest, INTVAL (src)); 3680 return; 3681 } 3682 3683 /* Split moves of symbolic constants into high/low pairs. */ 3684 if (mips_split_symbol (dest, src, MAX_MACHINE_MODE, &src)) 3685 { 3686 emit_insn (gen_rtx_SET (dest, src)); 3687 return; 3688 } 3689 3690 /* Generate the appropriate access sequences for TLS symbols. */ 3691 if (mips_tls_symbol_p (src)) 3692 { 3693 mips_emit_move (dest, mips_legitimize_tls_address (src)); 3694 return; 3695 } 3696 3697 /* If we have (const (plus symbol offset)), and that expression cannot 3698 be forced into memory, load the symbol first and add in the offset. 3699 In non-MIPS16 mode, prefer to do this even if the constant _can_ be 3700 forced into memory, as it usually produces better code. */ 3701 split_const (src, &base, &offset); 3702 if (offset != const0_rtx 3703 && (targetm.cannot_force_const_mem (mode, src) 3704 || (!TARGET_MIPS16 && can_create_pseudo_p ()))) 3705 { 3706 base = mips_force_temporary (dest, base); 3707 mips_emit_move (dest, mips_add_offset (NULL, base, INTVAL (offset))); 3708 return; 3709 } 3710 3711 src = force_const_mem (mode, src); 3712 3713 /* When using explicit relocs, constant pool references are sometimes 3714 not legitimate addresses. */ 3715 mips_split_symbol (dest, XEXP (src, 0), mode, &XEXP (src, 0)); 3716 mips_emit_move (dest, src); 3717 } 3718 3719 /* If (set DEST SRC) is not a valid move instruction, emit an equivalent 3720 sequence that is valid. */ 3721 3722 bool 3723 mips_legitimize_move (machine_mode mode, rtx dest, rtx src) 3724 { 3725 /* Both src and dest are non-registers; one special case is supported where 3726 the source is (const_int 0) and the store can source the zero register. 3727 MIPS16 and MSA are never able to source the zero register directly in 3728 memory operations. */ 3729 if (!register_operand (dest, mode) 3730 && !register_operand (src, mode) 3731 && (TARGET_MIPS16 || !const_0_operand (src, mode) 3732 || MSA_SUPPORTED_MODE_P (mode))) 3733 { 3734 mips_emit_move (dest, force_reg (mode, src)); 3735 return true; 3736 } 3737 3738 /* We need to deal with constants that would be legitimate 3739 immediate_operands but aren't legitimate move_operands. */ 3740 if (CONSTANT_P (src) && !move_operand (src, mode)) 3741 { 3742 mips_legitimize_const_move (mode, dest, src); 3743 set_unique_reg_note (get_last_insn (), REG_EQUAL, copy_rtx (src)); 3744 return true; 3745 } 3746 return false; 3747 } 3748 3749 /* Return true if value X in context CONTEXT is a small-data address 3750 that can be rewritten as a LO_SUM. */ 3751 3752 static bool 3753 mips_rewrite_small_data_p (rtx x, enum mips_symbol_context context) 3754 { 3755 enum mips_symbol_type symbol_type; 3756 3757 return (mips_lo_relocs[SYMBOL_GP_RELATIVE] 3758 && !mips_split_p[SYMBOL_GP_RELATIVE] 3759 && mips_symbolic_constant_p (x, context, &symbol_type) 3760 && symbol_type == SYMBOL_GP_RELATIVE); 3761 } 3762 3763 /* Return true if OP refers to small data symbols directly, not through 3764 a LO_SUM. CONTEXT is the context in which X appears. */ 3765 3766 static int 3767 mips_small_data_pattern_1 (rtx x, enum mips_symbol_context context) 3768 { 3769 subrtx_var_iterator::array_type array; 3770 FOR_EACH_SUBRTX_VAR (iter, array, x, ALL) 3771 { 3772 rtx x = *iter; 3773 3774 /* Ignore things like "g" constraints in asms. We make no particular 3775 guarantee about which symbolic constants are acceptable as asm operands 3776 versus which must be forced into a GPR. */ 3777 if (GET_CODE (x) == LO_SUM || GET_CODE (x) == ASM_OPERANDS) 3778 iter.skip_subrtxes (); 3779 else if (MEM_P (x)) 3780 { 3781 if (mips_small_data_pattern_1 (XEXP (x, 0), SYMBOL_CONTEXT_MEM)) 3782 return true; 3783 iter.skip_subrtxes (); 3784 } 3785 else if (mips_rewrite_small_data_p (x, context)) 3786 return true; 3787 } 3788 return false; 3789 } 3790 3791 /* Return true if OP refers to small data symbols directly, not through 3792 a LO_SUM. */ 3793 3794 bool 3795 mips_small_data_pattern_p (rtx op) 3796 { 3797 return mips_small_data_pattern_1 (op, SYMBOL_CONTEXT_LEA); 3798 } 3799 3800 /* Rewrite *LOC so that it refers to small data using explicit 3801 relocations. CONTEXT is the context in which *LOC appears. */ 3802 3803 static void 3804 mips_rewrite_small_data_1 (rtx *loc, enum mips_symbol_context context) 3805 { 3806 subrtx_ptr_iterator::array_type array; 3807 FOR_EACH_SUBRTX_PTR (iter, array, loc, ALL) 3808 { 3809 rtx *loc = *iter; 3810 if (MEM_P (*loc)) 3811 { 3812 mips_rewrite_small_data_1 (&XEXP (*loc, 0), SYMBOL_CONTEXT_MEM); 3813 iter.skip_subrtxes (); 3814 } 3815 else if (mips_rewrite_small_data_p (*loc, context)) 3816 { 3817 *loc = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, *loc); 3818 iter.skip_subrtxes (); 3819 } 3820 else if (GET_CODE (*loc) == LO_SUM) 3821 iter.skip_subrtxes (); 3822 } 3823 } 3824 3825 /* Rewrite instruction pattern PATTERN so that it refers to small data 3826 using explicit relocations. */ 3827 3828 rtx 3829 mips_rewrite_small_data (rtx pattern) 3830 { 3831 pattern = copy_insn (pattern); 3832 mips_rewrite_small_data_1 (&pattern, SYMBOL_CONTEXT_LEA); 3833 return pattern; 3834 } 3835 3836 /* The cost of loading values from the constant pool. It should be 3837 larger than the cost of any constant we want to synthesize inline. */ 3838 #define CONSTANT_POOL_COST COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 8) 3839 3840 /* Return the cost of X when used as an operand to the MIPS16 instruction 3841 that implements CODE. Return -1 if there is no such instruction, or if 3842 X is not a valid immediate operand for it. */ 3843 3844 static int 3845 mips16_constant_cost (int code, HOST_WIDE_INT x) 3846 { 3847 switch (code) 3848 { 3849 case ASHIFT: 3850 case ASHIFTRT: 3851 case LSHIFTRT: 3852 /* Shifts by between 1 and 8 bits (inclusive) are unextended, 3853 other shifts are extended. The shift patterns truncate the shift 3854 count to the right size, so there are no out-of-range values. */ 3855 if (IN_RANGE (x, 1, 8)) 3856 return 0; 3857 return COSTS_N_INSNS (1); 3858 3859 case PLUS: 3860 if (IN_RANGE (x, -128, 127)) 3861 return 0; 3862 if (SMALL_OPERAND (x)) 3863 return COSTS_N_INSNS (1); 3864 return -1; 3865 3866 case LEU: 3867 /* Like LE, but reject the always-true case. */ 3868 if (x == -1) 3869 return -1; 3870 /* FALLTHRU */ 3871 case LE: 3872 /* We add 1 to the immediate and use SLT. */ 3873 x += 1; 3874 /* FALLTHRU */ 3875 case XOR: 3876 /* We can use CMPI for an xor with an unsigned 16-bit X. */ 3877 case LT: 3878 case LTU: 3879 if (IN_RANGE (x, 0, 255)) 3880 return 0; 3881 if (SMALL_OPERAND_UNSIGNED (x)) 3882 return COSTS_N_INSNS (1); 3883 return -1; 3884 3885 case EQ: 3886 case NE: 3887 /* Equality comparisons with 0 are cheap. */ 3888 if (x == 0) 3889 return 0; 3890 return -1; 3891 3892 default: 3893 return -1; 3894 } 3895 } 3896 3897 /* Return true if there is a non-MIPS16 instruction that implements CODE 3898 and if that instruction accepts X as an immediate operand. */ 3899 3900 static int 3901 mips_immediate_operand_p (int code, HOST_WIDE_INT x) 3902 { 3903 switch (code) 3904 { 3905 case ASHIFT: 3906 case ASHIFTRT: 3907 case LSHIFTRT: 3908 /* All shift counts are truncated to a valid constant. */ 3909 return true; 3910 3911 case ROTATE: 3912 case ROTATERT: 3913 /* Likewise rotates, if the target supports rotates at all. */ 3914 return ISA_HAS_ROR; 3915 3916 case AND: 3917 case IOR: 3918 case XOR: 3919 /* These instructions take 16-bit unsigned immediates. */ 3920 return SMALL_OPERAND_UNSIGNED (x); 3921 3922 case PLUS: 3923 case LT: 3924 case LTU: 3925 /* These instructions take 16-bit signed immediates. */ 3926 return SMALL_OPERAND (x); 3927 3928 case EQ: 3929 case NE: 3930 case GT: 3931 case GTU: 3932 /* The "immediate" forms of these instructions are really 3933 implemented as comparisons with register 0. */ 3934 return x == 0; 3935 3936 case GE: 3937 case GEU: 3938 /* Likewise, meaning that the only valid immediate operand is 1. */ 3939 return x == 1; 3940 3941 case LE: 3942 /* We add 1 to the immediate and use SLT. */ 3943 return SMALL_OPERAND (x + 1); 3944 3945 case LEU: 3946 /* Likewise SLTU, but reject the always-true case. */ 3947 return SMALL_OPERAND (x + 1) && x + 1 != 0; 3948 3949 case SIGN_EXTRACT: 3950 case ZERO_EXTRACT: 3951 /* The bit position and size are immediate operands. */ 3952 return ISA_HAS_EXT_INS; 3953 3954 default: 3955 /* By default assume that $0 can be used for 0. */ 3956 return x == 0; 3957 } 3958 } 3959 3960 /* Return the cost of binary operation X, given that the instruction 3961 sequence for a word-sized or smaller operation has cost SINGLE_COST 3962 and that the sequence of a double-word operation has cost DOUBLE_COST. 3963 If SPEED is true, optimize for speed otherwise optimize for size. */ 3964 3965 static int 3966 mips_binary_cost (rtx x, int single_cost, int double_cost, bool speed) 3967 { 3968 int cost; 3969 3970 if (GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD * 2) 3971 cost = double_cost; 3972 else 3973 cost = single_cost; 3974 return (cost 3975 + set_src_cost (XEXP (x, 0), GET_MODE (x), speed) 3976 + rtx_cost (XEXP (x, 1), GET_MODE (x), GET_CODE (x), 1, speed)); 3977 } 3978 3979 /* Return the cost of floating-point multiplications of mode MODE. */ 3980 3981 static int 3982 mips_fp_mult_cost (machine_mode mode) 3983 { 3984 return mode == DFmode ? mips_cost->fp_mult_df : mips_cost->fp_mult_sf; 3985 } 3986 3987 /* Return the cost of floating-point divisions of mode MODE. */ 3988 3989 static int 3990 mips_fp_div_cost (machine_mode mode) 3991 { 3992 return mode == DFmode ? mips_cost->fp_div_df : mips_cost->fp_div_sf; 3993 } 3994 3995 /* Return the cost of sign-extending OP to mode MODE, not including the 3996 cost of OP itself. */ 3997 3998 static int 3999 mips_sign_extend_cost (machine_mode mode, rtx op) 4000 { 4001 if (MEM_P (op)) 4002 /* Extended loads are as cheap as unextended ones. */ 4003 return 0; 4004 4005 if (TARGET_64BIT && mode == DImode && GET_MODE (op) == SImode) 4006 /* A sign extension from SImode to DImode in 64-bit mode is free. */ 4007 return 0; 4008 4009 if (ISA_HAS_SEB_SEH || GENERATE_MIPS16E) 4010 /* We can use SEB or SEH. */ 4011 return COSTS_N_INSNS (1); 4012 4013 /* We need to use a shift left and a shift right. */ 4014 return COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 2); 4015 } 4016 4017 /* Return the cost of zero-extending OP to mode MODE, not including the 4018 cost of OP itself. */ 4019 4020 static int 4021 mips_zero_extend_cost (machine_mode mode, rtx op) 4022 { 4023 if (MEM_P (op)) 4024 /* Extended loads are as cheap as unextended ones. */ 4025 return 0; 4026 4027 if (TARGET_64BIT && mode == DImode && GET_MODE (op) == SImode) 4028 /* We need a shift left by 32 bits and a shift right by 32 bits. */ 4029 return COSTS_N_INSNS (TARGET_MIPS16 ? 4 : 2); 4030 4031 if (GENERATE_MIPS16E) 4032 /* We can use ZEB or ZEH. */ 4033 return COSTS_N_INSNS (1); 4034 4035 if (TARGET_MIPS16) 4036 /* We need to load 0xff or 0xffff into a register and use AND. */ 4037 return COSTS_N_INSNS (GET_MODE (op) == QImode ? 2 : 3); 4038 4039 /* We can use ANDI. */ 4040 return COSTS_N_INSNS (1); 4041 } 4042 4043 /* Return the cost of moving between two registers of mode MODE, 4044 assuming that the move will be in pieces of at most UNITS bytes. */ 4045 4046 static int 4047 mips_set_reg_reg_piece_cost (machine_mode mode, unsigned int units) 4048 { 4049 return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units); 4050 } 4051 4052 /* Return the cost of moving between two registers of mode MODE. */ 4053 4054 static int 4055 mips_set_reg_reg_cost (machine_mode mode) 4056 { 4057 switch (GET_MODE_CLASS (mode)) 4058 { 4059 case MODE_CC: 4060 return mips_set_reg_reg_piece_cost (mode, GET_MODE_SIZE (CCmode)); 4061 4062 case MODE_FLOAT: 4063 case MODE_COMPLEX_FLOAT: 4064 case MODE_VECTOR_FLOAT: 4065 if (TARGET_HARD_FLOAT) 4066 return mips_set_reg_reg_piece_cost (mode, UNITS_PER_HWFPVALUE); 4067 /* Fall through */ 4068 4069 default: 4070 return mips_set_reg_reg_piece_cost (mode, UNITS_PER_WORD); 4071 } 4072 } 4073 4074 /* Implement TARGET_RTX_COSTS. */ 4075 4076 static bool 4077 mips_rtx_costs (rtx x, machine_mode mode, int outer_code, 4078 int opno ATTRIBUTE_UNUSED, int *total, bool speed) 4079 { 4080 int code = GET_CODE (x); 4081 bool float_mode_p = FLOAT_MODE_P (mode); 4082 int cost; 4083 rtx addr; 4084 4085 /* The cost of a COMPARE is hard to define for MIPS. COMPAREs don't 4086 appear in the instruction stream, and the cost of a comparison is 4087 really the cost of the branch or scc condition. At the time of 4088 writing, GCC only uses an explicit outer COMPARE code when optabs 4089 is testing whether a constant is expensive enough to force into a 4090 register. We want optabs to pass such constants through the MIPS 4091 expanders instead, so make all constants very cheap here. */ 4092 if (outer_code == COMPARE) 4093 { 4094 gcc_assert (CONSTANT_P (x)); 4095 *total = 0; 4096 return true; 4097 } 4098 4099 switch (code) 4100 { 4101 case CONST_INT: 4102 /* Treat *clear_upper32-style ANDs as having zero cost in the 4103 second operand. The cost is entirely in the first operand. 4104 4105 ??? This is needed because we would otherwise try to CSE 4106 the constant operand. Although that's the right thing for 4107 instructions that continue to be a register operation throughout 4108 compilation, it is disastrous for instructions that could 4109 later be converted into a memory operation. */ 4110 if (TARGET_64BIT 4111 && outer_code == AND 4112 && UINTVAL (x) == 0xffffffff) 4113 { 4114 *total = 0; 4115 return true; 4116 } 4117 4118 if (TARGET_MIPS16) 4119 { 4120 cost = mips16_constant_cost (outer_code, INTVAL (x)); 4121 if (cost >= 0) 4122 { 4123 *total = cost; 4124 return true; 4125 } 4126 } 4127 else 4128 { 4129 /* When not optimizing for size, we care more about the cost 4130 of hot code, and hot code is often in a loop. If a constant 4131 operand needs to be forced into a register, we will often be 4132 able to hoist the constant load out of the loop, so the load 4133 should not contribute to the cost. */ 4134 if (speed || mips_immediate_operand_p (outer_code, INTVAL (x))) 4135 { 4136 *total = 0; 4137 return true; 4138 } 4139 } 4140 /* Fall through. */ 4141 4142 case CONST: 4143 case SYMBOL_REF: 4144 case LABEL_REF: 4145 case CONST_DOUBLE: 4146 if (force_to_mem_operand (x, VOIDmode)) 4147 { 4148 *total = COSTS_N_INSNS (1); 4149 return true; 4150 } 4151 cost = mips_const_insns (x); 4152 if (cost > 0) 4153 { 4154 /* If the constant is likely to be stored in a GPR, SETs of 4155 single-insn constants are as cheap as register sets; we 4156 never want to CSE them. 4157 4158 Don't reduce the cost of storing a floating-point zero in 4159 FPRs. If we have a zero in an FPR for other reasons, we 4160 can get better cfg-cleanup and delayed-branch results by 4161 using it consistently, rather than using $0 sometimes and 4162 an FPR at other times. Also, moves between floating-point 4163 registers are sometimes cheaper than (D)MTC1 $0. */ 4164 if (cost == 1 4165 && outer_code == SET 4166 && !(float_mode_p && TARGET_HARD_FLOAT)) 4167 cost = 0; 4168 /* When non-MIPS16 code loads a constant N>1 times, we rarely 4169 want to CSE the constant itself. It is usually better to 4170 have N copies of the last operation in the sequence and one 4171 shared copy of the other operations. (Note that this is 4172 not true for MIPS16 code, where the final operation in the 4173 sequence is often an extended instruction.) 4174 4175 Also, if we have a CONST_INT, we don't know whether it is 4176 for a word or doubleword operation, so we cannot rely on 4177 the result of mips_build_integer. */ 4178 else if (!TARGET_MIPS16 4179 && (outer_code == SET || GET_MODE (x) == VOIDmode)) 4180 cost = 1; 4181 *total = COSTS_N_INSNS (cost); 4182 return true; 4183 } 4184 /* The value will need to be fetched from the constant pool. */ 4185 *total = CONSTANT_POOL_COST; 4186 return true; 4187 4188 case MEM: 4189 /* If the address is legitimate, return the number of 4190 instructions it needs. */ 4191 addr = XEXP (x, 0); 4192 cost = mips_address_insns (addr, mode, true); 4193 if (cost > 0) 4194 { 4195 *total = COSTS_N_INSNS (cost + 1); 4196 return true; 4197 } 4198 /* Check for a scaled indexed address. */ 4199 if (mips_lwxs_address_p (addr) 4200 || mips_lx_address_p (addr, mode)) 4201 { 4202 *total = COSTS_N_INSNS (2); 4203 return true; 4204 } 4205 /* Otherwise use the default handling. */ 4206 return false; 4207 4208 case FFS: 4209 *total = COSTS_N_INSNS (6); 4210 return false; 4211 4212 case NOT: 4213 *total = COSTS_N_INSNS (GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1); 4214 return false; 4215 4216 case AND: 4217 /* Check for a *clear_upper32 pattern and treat it like a zero 4218 extension. See the pattern's comment for details. */ 4219 if (TARGET_64BIT 4220 && mode == DImode 4221 && CONST_INT_P (XEXP (x, 1)) 4222 && UINTVAL (XEXP (x, 1)) == 0xffffffff) 4223 { 4224 *total = (mips_zero_extend_cost (mode, XEXP (x, 0)) 4225 + set_src_cost (XEXP (x, 0), mode, speed)); 4226 return true; 4227 } 4228 if (ISA_HAS_CINS && CONST_INT_P (XEXP (x, 1))) 4229 { 4230 rtx op = XEXP (x, 0); 4231 if (GET_CODE (op) == ASHIFT 4232 && CONST_INT_P (XEXP (op, 1)) 4233 && mask_low_and_shift_p (mode, XEXP (x, 1), XEXP (op, 1), 32)) 4234 { 4235 *total = COSTS_N_INSNS (1); 4236 *total += set_src_cost (XEXP (op, 0), mode, speed); 4237 return true; 4238 } 4239 } 4240 /* (AND (NOT op0) (NOT op1) is a nor operation that can be done in 4241 a single instruction. */ 4242 if (!TARGET_MIPS16 4243 && GET_CODE (XEXP (x, 0)) == NOT 4244 && GET_CODE (XEXP (x, 1)) == NOT) 4245 { 4246 cost = GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1; 4247 *total = (COSTS_N_INSNS (cost) 4248 + set_src_cost (XEXP (XEXP (x, 0), 0), mode, speed) 4249 + set_src_cost (XEXP (XEXP (x, 1), 0), mode, speed)); 4250 return true; 4251 } 4252 4253 /* Fall through. */ 4254 4255 case IOR: 4256 case XOR: 4257 /* Double-word operations use two single-word operations. */ 4258 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (2), 4259 speed); 4260 return true; 4261 4262 case ASHIFT: 4263 case ASHIFTRT: 4264 case LSHIFTRT: 4265 case ROTATE: 4266 case ROTATERT: 4267 if (CONSTANT_P (XEXP (x, 1))) 4268 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (4), 4269 speed); 4270 else 4271 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (12), 4272 speed); 4273 return true; 4274 4275 case ABS: 4276 if (float_mode_p) 4277 *total = mips_cost->fp_add; 4278 else 4279 *total = COSTS_N_INSNS (4); 4280 return false; 4281 4282 case LO_SUM: 4283 /* Low-part immediates need an extended MIPS16 instruction. */ 4284 *total = (COSTS_N_INSNS (TARGET_MIPS16 ? 2 : 1) 4285 + set_src_cost (XEXP (x, 0), mode, speed)); 4286 return true; 4287 4288 case LT: 4289 case LTU: 4290 case LE: 4291 case LEU: 4292 case GT: 4293 case GTU: 4294 case GE: 4295 case GEU: 4296 case EQ: 4297 case NE: 4298 case UNORDERED: 4299 case LTGT: 4300 case UNGE: 4301 case UNGT: 4302 case UNLE: 4303 case UNLT: 4304 /* Branch comparisons have VOIDmode, so use the first operand's 4305 mode instead. */ 4306 mode = GET_MODE (XEXP (x, 0)); 4307 if (FLOAT_MODE_P (mode)) 4308 { 4309 *total = mips_cost->fp_add; 4310 return false; 4311 } 4312 *total = mips_binary_cost (x, COSTS_N_INSNS (1), COSTS_N_INSNS (4), 4313 speed); 4314 return true; 4315 4316 case MINUS: 4317 if (float_mode_p && ISA_HAS_UNFUSED_MADD4 && !HONOR_SIGNED_ZEROS (mode)) 4318 { 4319 /* See if we can use NMADD or NMSUB via the *nmadd4<mode>_fastmath 4320 or *nmsub4<mode>_fastmath patterns. These patterns check for 4321 HONOR_SIGNED_ZEROS so we check here too. */ 4322 rtx op0 = XEXP (x, 0); 4323 rtx op1 = XEXP (x, 1); 4324 if (GET_CODE (op0) == MULT && GET_CODE (XEXP (op0, 0)) == NEG) 4325 { 4326 *total = (mips_fp_mult_cost (mode) 4327 + set_src_cost (XEXP (XEXP (op0, 0), 0), mode, speed) 4328 + set_src_cost (XEXP (op0, 1), mode, speed) 4329 + set_src_cost (op1, mode, speed)); 4330 return true; 4331 } 4332 if (GET_CODE (op1) == MULT) 4333 { 4334 *total = (mips_fp_mult_cost (mode) 4335 + set_src_cost (op0, mode, speed) 4336 + set_src_cost (XEXP (op1, 0), mode, speed) 4337 + set_src_cost (XEXP (op1, 1), mode, speed)); 4338 return true; 4339 } 4340 } 4341 /* Fall through. */ 4342 4343 case PLUS: 4344 if (float_mode_p) 4345 { 4346 /* If this is part of a MADD or MSUB, treat the PLUS as 4347 being free. */ 4348 if (ISA_HAS_UNFUSED_MADD4 && GET_CODE (XEXP (x, 0)) == MULT) 4349 *total = 0; 4350 else 4351 *total = mips_cost->fp_add; 4352 return false; 4353 } 4354 4355 /* If it's an add + mult (which is equivalent to shift left) and 4356 it's immediate operand satisfies const_immlsa_operand predicate. */ 4357 if (((ISA_HAS_LSA && mode == SImode) 4358 || (ISA_HAS_DLSA && mode == DImode)) 4359 && GET_CODE (XEXP (x, 0)) == MULT) 4360 { 4361 rtx op2 = XEXP (XEXP (x, 0), 1); 4362 if (const_immlsa_operand (op2, mode)) 4363 { 4364 *total = (COSTS_N_INSNS (1) 4365 + set_src_cost (XEXP (XEXP (x, 0), 0), mode, speed) 4366 + set_src_cost (XEXP (x, 1), mode, speed)); 4367 return true; 4368 } 4369 } 4370 4371 /* Double-word operations require three single-word operations and 4372 an SLTU. The MIPS16 version then needs to move the result of 4373 the SLTU from $24 to a MIPS16 register. */ 4374 *total = mips_binary_cost (x, COSTS_N_INSNS (1), 4375 COSTS_N_INSNS (TARGET_MIPS16 ? 5 : 4), 4376 speed); 4377 return true; 4378 4379 case NEG: 4380 if (float_mode_p && ISA_HAS_UNFUSED_MADD4) 4381 { 4382 /* See if we can use NMADD or NMSUB via the *nmadd4<mode> or 4383 *nmsub4<mode> patterns. */ 4384 rtx op = XEXP (x, 0); 4385 if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS) 4386 && GET_CODE (XEXP (op, 0)) == MULT) 4387 { 4388 *total = (mips_fp_mult_cost (mode) 4389 + set_src_cost (XEXP (XEXP (op, 0), 0), mode, speed) 4390 + set_src_cost (XEXP (XEXP (op, 0), 1), mode, speed) 4391 + set_src_cost (XEXP (op, 1), mode, speed)); 4392 return true; 4393 } 4394 } 4395 4396 if (float_mode_p) 4397 *total = mips_cost->fp_add; 4398 else 4399 *total = COSTS_N_INSNS (GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 4 : 1); 4400 return false; 4401 4402 case FMA: 4403 *total = mips_fp_mult_cost (mode); 4404 return false; 4405 4406 case MULT: 4407 if (float_mode_p) 4408 *total = mips_fp_mult_cost (mode); 4409 else if (mode == DImode && !TARGET_64BIT) 4410 /* Synthesized from 2 mulsi3s, 1 mulsidi3 and two additions, 4411 where the mulsidi3 always includes an MFHI and an MFLO. */ 4412 *total = (speed 4413 ? mips_cost->int_mult_si * 3 + 6 4414 : COSTS_N_INSNS (ISA_HAS_MUL3 ? 7 : 9)); 4415 else if (!speed) 4416 *total = COSTS_N_INSNS ((ISA_HAS_MUL3 || ISA_HAS_R6MUL) ? 1 : 2) + 1; 4417 else if (mode == DImode) 4418 *total = mips_cost->int_mult_di; 4419 else 4420 *total = mips_cost->int_mult_si; 4421 return false; 4422 4423 case DIV: 4424 /* Check for a reciprocal. */ 4425 if (float_mode_p 4426 && ISA_HAS_FP_RECIP_RSQRT (mode) 4427 && flag_unsafe_math_optimizations 4428 && XEXP (x, 0) == CONST1_RTX (mode)) 4429 { 4430 if (outer_code == SQRT || GET_CODE (XEXP (x, 1)) == SQRT) 4431 /* An rsqrt<mode>a or rsqrt<mode>b pattern. Count the 4432 division as being free. */ 4433 *total = set_src_cost (XEXP (x, 1), mode, speed); 4434 else 4435 *total = (mips_fp_div_cost (mode) 4436 + set_src_cost (XEXP (x, 1), mode, speed)); 4437 return true; 4438 } 4439 /* Fall through. */ 4440 4441 case SQRT: 4442 case MOD: 4443 if (float_mode_p) 4444 { 4445 *total = mips_fp_div_cost (mode); 4446 return false; 4447 } 4448 /* Fall through. */ 4449 4450 case UDIV: 4451 case UMOD: 4452 if (!speed) 4453 { 4454 /* It is our responsibility to make division by a power of 2 4455 as cheap as 2 register additions if we want the division 4456 expanders to be used for such operations; see the setting 4457 of sdiv_pow2_cheap in optabs.c. Using (D)DIV for MIPS16 4458 should always produce shorter code than using 4459 expand_sdiv2_pow2. */ 4460 if (TARGET_MIPS16 4461 && CONST_INT_P (XEXP (x, 1)) 4462 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0) 4463 { 4464 *total = COSTS_N_INSNS (2); 4465 *total += set_src_cost (XEXP (x, 0), mode, speed); 4466 return true; 4467 } 4468 *total = COSTS_N_INSNS (mips_idiv_insns (mode)); 4469 } 4470 else if (mode == DImode) 4471 *total = mips_cost->int_div_di; 4472 else 4473 *total = mips_cost->int_div_si; 4474 return false; 4475 4476 case SIGN_EXTEND: 4477 *total = mips_sign_extend_cost (mode, XEXP (x, 0)); 4478 return false; 4479 4480 case ZERO_EXTEND: 4481 if (outer_code == SET 4482 && ISA_HAS_BADDU 4483 && (GET_CODE (XEXP (x, 0)) == TRUNCATE 4484 || GET_CODE (XEXP (x, 0)) == SUBREG) 4485 && GET_MODE (XEXP (x, 0)) == QImode 4486 && GET_CODE (XEXP (XEXP (x, 0), 0)) == PLUS) 4487 { 4488 *total = set_src_cost (XEXP (XEXP (x, 0), 0), VOIDmode, speed); 4489 return true; 4490 } 4491 *total = mips_zero_extend_cost (mode, XEXP (x, 0)); 4492 return false; 4493 case TRUNCATE: 4494 /* Costings for highpart multiplies. Matching patterns of the form: 4495 4496 (lshiftrt:DI (mult:DI (sign_extend:DI (...) 4497 (sign_extend:DI (...)) 4498 (const_int 32) 4499 */ 4500 if (ISA_HAS_R6MUL 4501 && (GET_CODE (XEXP (x, 0)) == ASHIFTRT 4502 || GET_CODE (XEXP (x, 0)) == LSHIFTRT) 4503 && CONST_INT_P (XEXP (XEXP (x, 0), 1)) 4504 && ((INTVAL (XEXP (XEXP (x, 0), 1)) == 32 4505 && GET_MODE (XEXP (x, 0)) == DImode) 4506 || (ISA_HAS_R6DMUL 4507 && INTVAL (XEXP (XEXP (x, 0), 1)) == 64 4508 && GET_MODE (XEXP (x, 0)) == TImode)) 4509 && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT 4510 && ((GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND 4511 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) == SIGN_EXTEND) 4512 || (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND 4513 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1)) 4514 == ZERO_EXTEND)))) 4515 { 4516 if (!speed) 4517 *total = COSTS_N_INSNS (1) + 1; 4518 else if (mode == DImode) 4519 *total = mips_cost->int_mult_di; 4520 else 4521 *total = mips_cost->int_mult_si; 4522 4523 /* Sign extension is free, zero extension costs for DImode when 4524 on a 64bit core / when DMUL is present. */ 4525 for (int i = 0; i < 2; ++i) 4526 { 4527 rtx op = XEXP (XEXP (XEXP (x, 0), 0), i); 4528 if (ISA_HAS_R6DMUL 4529 && GET_CODE (op) == ZERO_EXTEND 4530 && GET_MODE (op) == DImode) 4531 *total += rtx_cost (op, DImode, MULT, i, speed); 4532 else 4533 *total += rtx_cost (XEXP (op, 0), VOIDmode, GET_CODE (op), 4534 0, speed); 4535 } 4536 4537 return true; 4538 } 4539 return false; 4540 4541 case FLOAT: 4542 case UNSIGNED_FLOAT: 4543 case FIX: 4544 case FLOAT_EXTEND: 4545 case FLOAT_TRUNCATE: 4546 *total = mips_cost->fp_add; 4547 return false; 4548 4549 case SET: 4550 if (register_operand (SET_DEST (x), VOIDmode) 4551 && reg_or_0_operand (SET_SRC (x), VOIDmode)) 4552 { 4553 *total = mips_set_reg_reg_cost (GET_MODE (SET_DEST (x))); 4554 return true; 4555 } 4556 return false; 4557 4558 default: 4559 return false; 4560 } 4561 } 4562 4563 /* Implement TARGET_ADDRESS_COST. */ 4564 4565 static int 4566 mips_address_cost (rtx addr, machine_mode mode, 4567 addr_space_t as ATTRIBUTE_UNUSED, 4568 bool speed ATTRIBUTE_UNUSED) 4569 { 4570 return mips_address_insns (addr, mode, false); 4571 } 4572 4573 /* Implement TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P. */ 4574 4575 static bool 4576 mips_no_speculation_in_delay_slots_p () 4577 { 4578 return TARGET_CB_MAYBE; 4579 } 4580 4581 /* Information about a single instruction in a multi-instruction 4582 asm sequence. */ 4583 struct mips_multi_member { 4584 /* True if this is a label, false if it is code. */ 4585 bool is_label_p; 4586 4587 /* The output_asm_insn format of the instruction. */ 4588 const char *format; 4589 4590 /* The operands to the instruction. */ 4591 rtx operands[MAX_RECOG_OPERANDS]; 4592 }; 4593 typedef struct mips_multi_member mips_multi_member; 4594 4595 /* The instructions that make up the current multi-insn sequence. */ 4596 static vec<mips_multi_member> mips_multi_members; 4597 4598 /* How many instructions (as opposed to labels) are in the current 4599 multi-insn sequence. */ 4600 static unsigned int mips_multi_num_insns; 4601 4602 /* Start a new multi-insn sequence. */ 4603 4604 static void 4605 mips_multi_start (void) 4606 { 4607 mips_multi_members.truncate (0); 4608 mips_multi_num_insns = 0; 4609 } 4610 4611 /* Add a new, zero initialized member to the current multi-insn sequence. */ 4612 4613 static struct mips_multi_member * 4614 mips_multi_add (void) 4615 { 4616 mips_multi_member empty; 4617 memset (&empty, 0, sizeof (empty)); 4618 return mips_multi_members.safe_push (empty); 4619 } 4620 4621 /* Add a normal insn with the given asm format to the current multi-insn 4622 sequence. The other arguments are a null-terminated list of operands. */ 4623 4624 static void 4625 mips_multi_add_insn (const char *format, ...) 4626 { 4627 struct mips_multi_member *member; 4628 va_list ap; 4629 unsigned int i; 4630 rtx op; 4631 4632 member = mips_multi_add (); 4633 member->is_label_p = false; 4634 member->format = format; 4635 va_start (ap, format); 4636 i = 0; 4637 while ((op = va_arg (ap, rtx))) 4638 member->operands[i++] = op; 4639 va_end (ap); 4640 mips_multi_num_insns++; 4641 } 4642 4643 /* Add the given label definition to the current multi-insn sequence. 4644 The definition should include the colon. */ 4645 4646 static void 4647 mips_multi_add_label (const char *label) 4648 { 4649 struct mips_multi_member *member; 4650 4651 member = mips_multi_add (); 4652 member->is_label_p = true; 4653 member->format = label; 4654 } 4655 4656 /* Return the index of the last member of the current multi-insn sequence. */ 4657 4658 static unsigned int 4659 mips_multi_last_index (void) 4660 { 4661 return mips_multi_members.length () - 1; 4662 } 4663 4664 /* Add a copy of an existing instruction to the current multi-insn 4665 sequence. I is the index of the instruction that should be copied. */ 4666 4667 static void 4668 mips_multi_copy_insn (unsigned int i) 4669 { 4670 struct mips_multi_member *member; 4671 4672 member = mips_multi_add (); 4673 memcpy (member, &mips_multi_members[i], sizeof (*member)); 4674 gcc_assert (!member->is_label_p); 4675 } 4676 4677 /* Change the operand of an existing instruction in the current 4678 multi-insn sequence. I is the index of the instruction, 4679 OP is the index of the operand, and X is the new value. */ 4680 4681 static void 4682 mips_multi_set_operand (unsigned int i, unsigned int op, rtx x) 4683 { 4684 mips_multi_members[i].operands[op] = x; 4685 } 4686 4687 /* Write out the asm code for the current multi-insn sequence. */ 4688 4689 static void 4690 mips_multi_write (void) 4691 { 4692 struct mips_multi_member *member; 4693 unsigned int i; 4694 4695 FOR_EACH_VEC_ELT (mips_multi_members, i, member) 4696 if (member->is_label_p) 4697 fprintf (asm_out_file, "%s\n", member->format); 4698 else 4699 output_asm_insn (member->format, member->operands); 4700 } 4701 4702 /* Return one word of double-word value OP, taking into account the fixed 4703 endianness of certain registers. HIGH_P is true to select the high part, 4704 false to select the low part. */ 4705 4706 rtx 4707 mips_subword (rtx op, bool high_p) 4708 { 4709 unsigned int byte, offset; 4710 machine_mode mode; 4711 4712 mode = GET_MODE (op); 4713 if (mode == VOIDmode) 4714 mode = TARGET_64BIT ? TImode : DImode; 4715 4716 if (TARGET_BIG_ENDIAN ? !high_p : high_p) 4717 byte = UNITS_PER_WORD; 4718 else 4719 byte = 0; 4720 4721 if (FP_REG_RTX_P (op)) 4722 { 4723 /* Paired FPRs are always ordered little-endian. */ 4724 offset = (UNITS_PER_WORD < UNITS_PER_HWFPVALUE ? high_p : byte != 0); 4725 return gen_rtx_REG (word_mode, REGNO (op) + offset); 4726 } 4727 4728 if (MEM_P (op)) 4729 return mips_rewrite_small_data (adjust_address (op, word_mode, byte)); 4730 4731 return simplify_gen_subreg (word_mode, op, mode, byte); 4732 } 4733 4734 /* Return true if SRC should be moved into DEST using "MULT $0, $0". 4735 SPLIT_TYPE is the condition under which moves should be split. */ 4736 4737 static bool 4738 mips_mult_move_p (rtx dest, rtx src, enum mips_split_type split_type) 4739 { 4740 return ((split_type != SPLIT_FOR_SPEED 4741 || mips_tuning_info.fast_mult_zero_zero_p) 4742 && src == const0_rtx 4743 && REG_P (dest) 4744 && GET_MODE_SIZE (GET_MODE (dest)) == 2 * UNITS_PER_WORD 4745 && (ISA_HAS_DSP_MULT 4746 ? ACC_REG_P (REGNO (dest)) 4747 : MD_REG_P (REGNO (dest)))); 4748 } 4749 4750 /* Return true if a move from SRC to DEST should be split into two. 4751 SPLIT_TYPE describes the split condition. */ 4752 4753 bool 4754 mips_split_move_p (rtx dest, rtx src, enum mips_split_type split_type) 4755 { 4756 /* Check whether the move can be done using some variant of MULT $0,$0. */ 4757 if (mips_mult_move_p (dest, src, split_type)) 4758 return false; 4759 4760 /* FPR-to-FPR moves can be done in a single instruction, if they're 4761 allowed at all. */ 4762 unsigned int size = GET_MODE_SIZE (GET_MODE (dest)); 4763 if (size == 8 && FP_REG_RTX_P (src) && FP_REG_RTX_P (dest)) 4764 return false; 4765 4766 /* Check for floating-point loads and stores. */ 4767 if (size == 8 && ISA_HAS_LDC1_SDC1) 4768 { 4769 if (FP_REG_RTX_P (dest) && MEM_P (src)) 4770 return false; 4771 if (FP_REG_RTX_P (src) && MEM_P (dest)) 4772 return false; 4773 } 4774 4775 /* Check if MSA moves need splitting. */ 4776 if (MSA_SUPPORTED_MODE_P (GET_MODE (dest))) 4777 return mips_split_128bit_move_p (dest, src); 4778 4779 /* Otherwise split all multiword moves. */ 4780 return size > UNITS_PER_WORD; 4781 } 4782 4783 /* Split a move from SRC to DEST, given that mips_split_move_p holds. 4784 SPLIT_TYPE describes the split condition. INSN is the insn being 4785 split, if we know it, NULL otherwise. */ 4786 4787 void 4788 mips_split_move (rtx dest, rtx src, enum mips_split_type split_type, rtx insn_) 4789 { 4790 rtx low_dest; 4791 4792 gcc_checking_assert (mips_split_move_p (dest, src, split_type)); 4793 if (MSA_SUPPORTED_MODE_P (GET_MODE (dest))) 4794 mips_split_128bit_move (dest, src); 4795 else if (FP_REG_RTX_P (dest) || FP_REG_RTX_P (src)) 4796 { 4797 if (!TARGET_64BIT && GET_MODE (dest) == DImode) 4798 emit_insn (gen_move_doubleword_fprdi (dest, src)); 4799 else if (!TARGET_64BIT && GET_MODE (dest) == DFmode) 4800 emit_insn (gen_move_doubleword_fprdf (dest, src)); 4801 else if (!TARGET_64BIT && GET_MODE (dest) == V2SFmode) 4802 emit_insn (gen_move_doubleword_fprv2sf (dest, src)); 4803 else if (!TARGET_64BIT && GET_MODE (dest) == V2SImode) 4804 emit_insn (gen_move_doubleword_fprv2si (dest, src)); 4805 else if (!TARGET_64BIT && GET_MODE (dest) == V4HImode) 4806 emit_insn (gen_move_doubleword_fprv4hi (dest, src)); 4807 else if (!TARGET_64BIT && GET_MODE (dest) == V8QImode) 4808 emit_insn (gen_move_doubleword_fprv8qi (dest, src)); 4809 else if (TARGET_64BIT && GET_MODE (dest) == TFmode) 4810 emit_insn (gen_move_doubleword_fprtf (dest, src)); 4811 else 4812 gcc_unreachable (); 4813 } 4814 else if (REG_P (dest) && REGNO (dest) == MD_REG_FIRST) 4815 { 4816 low_dest = mips_subword (dest, false); 4817 mips_emit_move (low_dest, mips_subword (src, false)); 4818 if (TARGET_64BIT) 4819 emit_insn (gen_mthidi_ti (dest, mips_subword (src, true), low_dest)); 4820 else 4821 emit_insn (gen_mthisi_di (dest, mips_subword (src, true), low_dest)); 4822 } 4823 else if (REG_P (src) && REGNO (src) == MD_REG_FIRST) 4824 { 4825 mips_emit_move (mips_subword (dest, false), mips_subword (src, false)); 4826 if (TARGET_64BIT) 4827 emit_insn (gen_mfhidi_ti (mips_subword (dest, true), src)); 4828 else 4829 emit_insn (gen_mfhisi_di (mips_subword (dest, true), src)); 4830 } 4831 else 4832 { 4833 /* The operation can be split into two normal moves. Decide in 4834 which order to do them. */ 4835 low_dest = mips_subword (dest, false); 4836 if (REG_P (low_dest) 4837 && reg_overlap_mentioned_p (low_dest, src)) 4838 { 4839 mips_emit_move (mips_subword (dest, true), mips_subword (src, true)); 4840 mips_emit_move (low_dest, mips_subword (src, false)); 4841 } 4842 else 4843 { 4844 mips_emit_move (low_dest, mips_subword (src, false)); 4845 mips_emit_move (mips_subword (dest, true), mips_subword (src, true)); 4846 } 4847 } 4848 4849 /* This is a hack. See if the next insn uses DEST and if so, see if we 4850 can forward SRC for DEST. This is most useful if the next insn is a 4851 simple store. */ 4852 rtx_insn *insn = (rtx_insn *)insn_; 4853 struct mips_address_info addr = {}; 4854 if (insn) 4855 { 4856 rtx_insn *next = next_nonnote_nondebug_insn_bb (insn); 4857 if (next) 4858 { 4859 rtx set = single_set (next); 4860 if (set && SET_SRC (set) == dest) 4861 { 4862 if (MEM_P (src)) 4863 { 4864 rtx tmp = XEXP (src, 0); 4865 mips_classify_address (&addr, tmp, GET_MODE (tmp), true); 4866 if (addr.reg && !reg_overlap_mentioned_p (dest, addr.reg)) 4867 validate_change (next, &SET_SRC (set), src, false); 4868 } 4869 else 4870 validate_change (next, &SET_SRC (set), src, false); 4871 } 4872 } 4873 } 4874 } 4875 4876 /* Return the split type for instruction INSN. */ 4877 4878 static enum mips_split_type 4879 mips_insn_split_type (rtx insn) 4880 { 4881 basic_block bb = BLOCK_FOR_INSN (insn); 4882 if (bb) 4883 { 4884 if (optimize_bb_for_speed_p (bb)) 4885 return SPLIT_FOR_SPEED; 4886 else 4887 return SPLIT_FOR_SIZE; 4888 } 4889 /* Once CFG information has been removed, we should trust the optimization 4890 decisions made by previous passes and only split where necessary. */ 4891 return SPLIT_IF_NECESSARY; 4892 } 4893 4894 /* Return true if a 128-bit move from SRC to DEST should be split. */ 4895 4896 bool 4897 mips_split_128bit_move_p (rtx dest, rtx src) 4898 { 4899 /* MSA-to-MSA moves can be done in a single instruction. */ 4900 if (FP_REG_RTX_P (src) && FP_REG_RTX_P (dest)) 4901 return false; 4902 4903 /* Check for MSA loads and stores. */ 4904 if (FP_REG_RTX_P (dest) && MEM_P (src)) 4905 return false; 4906 if (FP_REG_RTX_P (src) && MEM_P (dest)) 4907 return false; 4908 4909 /* Check for MSA set to an immediate const vector with valid replicated 4910 element. */ 4911 if (FP_REG_RTX_P (dest) 4912 && mips_const_vector_same_int_p (src, GET_MODE (src), -512, 511)) 4913 return false; 4914 4915 /* Check for MSA load zero immediate. */ 4916 if (FP_REG_RTX_P (dest) && src == CONST0_RTX (GET_MODE (src))) 4917 return false; 4918 4919 return true; 4920 } 4921 4922 /* Split a 128-bit move from SRC to DEST. */ 4923 4924 void 4925 mips_split_128bit_move (rtx dest, rtx src) 4926 { 4927 int byte, index; 4928 rtx low_dest, low_src, d, s; 4929 4930 if (FP_REG_RTX_P (dest)) 4931 { 4932 gcc_assert (!MEM_P (src)); 4933 4934 rtx new_dest = dest; 4935 if (!TARGET_64BIT) 4936 { 4937 if (GET_MODE (dest) != V4SImode) 4938 new_dest = simplify_gen_subreg (V4SImode, dest, GET_MODE (dest), 0); 4939 } 4940 else 4941 { 4942 if (GET_MODE (dest) != V2DImode) 4943 new_dest = simplify_gen_subreg (V2DImode, dest, GET_MODE (dest), 0); 4944 } 4945 4946 for (byte = 0, index = 0; byte < GET_MODE_SIZE (TImode); 4947 byte += UNITS_PER_WORD, index++) 4948 { 4949 s = mips_subword_at_byte (src, byte); 4950 if (!TARGET_64BIT) 4951 emit_insn (gen_msa_insert_w (new_dest, s, new_dest, 4952 GEN_INT (1 << index))); 4953 else 4954 emit_insn (gen_msa_insert_d (new_dest, s, new_dest, 4955 GEN_INT (1 << index))); 4956 } 4957 } 4958 else if (FP_REG_RTX_P (src)) 4959 { 4960 gcc_assert (!MEM_P (dest)); 4961 4962 rtx new_src = src; 4963 if (!TARGET_64BIT) 4964 { 4965 if (GET_MODE (src) != V4SImode) 4966 new_src = simplify_gen_subreg (V4SImode, src, GET_MODE (src), 0); 4967 } 4968 else 4969 { 4970 if (GET_MODE (src) != V2DImode) 4971 new_src = simplify_gen_subreg (V2DImode, src, GET_MODE (src), 0); 4972 } 4973 4974 for (byte = 0, index = 0; byte < GET_MODE_SIZE (TImode); 4975 byte += UNITS_PER_WORD, index++) 4976 { 4977 d = mips_subword_at_byte (dest, byte); 4978 if (!TARGET_64BIT) 4979 emit_insn (gen_msa_copy_s_w (d, new_src, GEN_INT (index))); 4980 else 4981 emit_insn (gen_msa_copy_s_d (d, new_src, GEN_INT (index))); 4982 } 4983 } 4984 else 4985 { 4986 low_dest = mips_subword_at_byte (dest, 0); 4987 low_src = mips_subword_at_byte (src, 0); 4988 gcc_assert (REG_P (low_dest) && REG_P (low_src)); 4989 /* Make sure the source register is not written before reading. */ 4990 if (REGNO (low_dest) <= REGNO (low_src)) 4991 { 4992 for (byte = 0; byte < GET_MODE_SIZE (TImode); 4993 byte += UNITS_PER_WORD) 4994 { 4995 d = mips_subword_at_byte (dest, byte); 4996 s = mips_subword_at_byte (src, byte); 4997 mips_emit_move (d, s); 4998 } 4999 } 5000 else 5001 { 5002 for (byte = GET_MODE_SIZE (TImode) - UNITS_PER_WORD; byte >= 0; 5003 byte -= UNITS_PER_WORD) 5004 { 5005 d = mips_subword_at_byte (dest, byte); 5006 s = mips_subword_at_byte (src, byte); 5007 mips_emit_move (d, s); 5008 } 5009 } 5010 } 5011 } 5012 5013 /* Split a COPY_S.D with operands DEST, SRC and INDEX. GEN is a function 5014 used to generate subregs. */ 5015 5016 void 5017 mips_split_msa_copy_d (rtx dest, rtx src, rtx index, 5018 rtx (*gen_fn)(rtx, rtx, rtx)) 5019 { 5020 gcc_assert ((GET_MODE (src) == V2DImode && GET_MODE (dest) == DImode) 5021 || (GET_MODE (src) == V2DFmode && GET_MODE (dest) == DFmode)); 5022 5023 /* Note that low is always from the lower index, and high is always 5024 from the higher index. */ 5025 rtx low = mips_subword (dest, false); 5026 rtx high = mips_subword (dest, true); 5027 rtx new_src = simplify_gen_subreg (V4SImode, src, GET_MODE (src), 0); 5028 5029 emit_insn (gen_fn (low, new_src, GEN_INT (INTVAL (index) * 2))); 5030 emit_insn (gen_fn (high, new_src, GEN_INT (INTVAL (index) * 2 + 1))); 5031 } 5032 5033 /* Split a INSERT.D with operand DEST, SRC1.INDEX and SRC2. */ 5034 5035 void 5036 mips_split_msa_insert_d (rtx dest, rtx src1, rtx index, rtx src2) 5037 { 5038 int i; 5039 gcc_assert (GET_MODE (dest) == GET_MODE (src1)); 5040 gcc_assert ((GET_MODE (dest) == V2DImode 5041 && (GET_MODE (src2) == DImode || src2 == const0_rtx)) 5042 || (GET_MODE (dest) == V2DFmode && GET_MODE (src2) == DFmode)); 5043 5044 /* Note that low is always from the lower index, and high is always 5045 from the higher index. */ 5046 rtx low = mips_subword (src2, false); 5047 rtx high = mips_subword (src2, true); 5048 rtx new_dest = simplify_gen_subreg (V4SImode, dest, GET_MODE (dest), 0); 5049 rtx new_src1 = simplify_gen_subreg (V4SImode, src1, GET_MODE (src1), 0); 5050 i = exact_log2 (INTVAL (index)); 5051 gcc_assert (i != -1); 5052 5053 emit_insn (gen_msa_insert_w (new_dest, low, new_src1, 5054 GEN_INT (1 << (i * 2)))); 5055 emit_insn (gen_msa_insert_w (new_dest, high, new_dest, 5056 GEN_INT (1 << (i * 2 + 1)))); 5057 } 5058 5059 /* Split FILL.D. */ 5060 5061 void 5062 mips_split_msa_fill_d (rtx dest, rtx src) 5063 { 5064 gcc_assert ((GET_MODE (dest) == V2DImode 5065 && (GET_MODE (src) == DImode || src == const0_rtx)) 5066 || (GET_MODE (dest) == V2DFmode && GET_MODE (src) == DFmode)); 5067 5068 /* Note that low is always from the lower index, and high is always 5069 from the higher index. */ 5070 rtx low, high; 5071 if (src == const0_rtx) 5072 { 5073 low = src; 5074 high = src; 5075 } 5076 else 5077 { 5078 low = mips_subword (src, false); 5079 high = mips_subword (src, true); 5080 } 5081 rtx new_dest = simplify_gen_subreg (V4SImode, dest, GET_MODE (dest), 0); 5082 emit_insn (gen_msa_fill_w (new_dest, low)); 5083 emit_insn (gen_msa_insert_w (new_dest, high, new_dest, GEN_INT (1 << 1))); 5084 emit_insn (gen_msa_insert_w (new_dest, high, new_dest, GEN_INT (1 << 3))); 5085 } 5086 5087 /* Return true if a move from SRC to DEST in INSN should be split. */ 5088 5089 bool 5090 mips_split_move_insn_p (rtx dest, rtx src, rtx insn) 5091 { 5092 return mips_split_move_p (dest, src, mips_insn_split_type (insn)); 5093 } 5094 5095 /* Split a move from SRC to DEST in INSN, given that mips_split_move_insn_p 5096 holds. */ 5097 5098 void 5099 mips_split_move_insn (rtx dest, rtx src, rtx insn) 5100 { 5101 mips_split_move (dest, src, mips_insn_split_type (insn), insn); 5102 } 5103 5104 /* Return the appropriate instructions to move SRC into DEST. Assume 5105 that SRC is operand 1 and DEST is operand 0. */ 5106 5107 const char * 5108 mips_output_move (rtx dest, rtx src) 5109 { 5110 enum rtx_code dest_code = GET_CODE (dest); 5111 enum rtx_code src_code = GET_CODE (src); 5112 machine_mode mode = GET_MODE (dest); 5113 bool dbl_p = (GET_MODE_SIZE (mode) == 8); 5114 bool msa_p = MSA_SUPPORTED_MODE_P (mode); 5115 enum mips_symbol_type symbol_type; 5116 5117 if (mips_split_move_p (dest, src, SPLIT_IF_NECESSARY)) 5118 return "#"; 5119 5120 if (msa_p 5121 && dest_code == REG && FP_REG_P (REGNO (dest)) 5122 && src_code == CONST_VECTOR 5123 && CONST_INT_P (CONST_VECTOR_ELT (src, 0))) 5124 { 5125 gcc_assert (mips_const_vector_same_int_p (src, mode, -512, 511)); 5126 return "ldi.%v0\t%w0,%E1"; 5127 } 5128 5129 if ((src_code == REG && GP_REG_P (REGNO (src))) 5130 || (!TARGET_MIPS16 && src == CONST0_RTX (mode))) 5131 { 5132 if (dest_code == REG) 5133 { 5134 if (GP_REG_P (REGNO (dest))) 5135 return "move\t%0,%z1"; 5136 5137 if (mips_mult_move_p (dest, src, SPLIT_IF_NECESSARY)) 5138 { 5139 if (ISA_HAS_DSP_MULT) 5140 return "mult\t%q0,%.,%."; 5141 else 5142 return "mult\t%.,%."; 5143 } 5144 5145 /* Moves to HI are handled by special .md insns. */ 5146 if (REGNO (dest) == LO_REGNUM) 5147 return "mtlo\t%z1"; 5148 5149 if (DSP_ACC_REG_P (REGNO (dest))) 5150 { 5151 static char retval[] = "mt__\t%z1,%q0"; 5152 5153 retval[2] = reg_names[REGNO (dest)][4]; 5154 retval[3] = reg_names[REGNO (dest)][5]; 5155 return retval; 5156 } 5157 5158 if (FP_REG_P (REGNO (dest))) 5159 { 5160 if (msa_p) 5161 { 5162 gcc_assert (src == CONST0_RTX (GET_MODE (src))); 5163 return "ldi.%v0\t%w0,0"; 5164 } 5165 5166 return dbl_p ? "dmtc1\t%z1,%0" : "mtc1\t%z1,%0"; 5167 } 5168 5169 if (ALL_COP_REG_P (REGNO (dest))) 5170 { 5171 static char retval[] = "dmtc_\t%z1,%0"; 5172 5173 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest)); 5174 return dbl_p ? retval : retval + 1; 5175 } 5176 } 5177 if (dest_code == MEM) 5178 switch (GET_MODE_SIZE (mode)) 5179 { 5180 case 1: return "sb\t%z1,%0"; 5181 case 2: return "sh\t%z1,%0"; 5182 case 4: return "sw\t%z1,%0"; 5183 case 8: return "sd\t%z1,%0"; 5184 default: gcc_unreachable (); 5185 } 5186 } 5187 if (dest_code == REG && GP_REG_P (REGNO (dest))) 5188 { 5189 if (src_code == REG) 5190 { 5191 /* Moves from HI are handled by special .md insns. */ 5192 if (REGNO (src) == LO_REGNUM) 5193 { 5194 /* When generating VR4120 or VR4130 code, we use MACC and 5195 DMACC instead of MFLO. This avoids both the normal 5196 MIPS III HI/LO hazards and the errata related to 5197 -mfix-vr4130. */ 5198 if (ISA_HAS_MACCHI) 5199 return dbl_p ? "dmacc\t%0,%.,%." : "macc\t%0,%.,%."; 5200 return "mflo\t%0"; 5201 } 5202 5203 if (DSP_ACC_REG_P (REGNO (src))) 5204 { 5205 static char retval[] = "mf__\t%0,%q1"; 5206 5207 retval[2] = reg_names[REGNO (src)][4]; 5208 retval[3] = reg_names[REGNO (src)][5]; 5209 return retval; 5210 } 5211 5212 if (FP_REG_P (REGNO (src))) 5213 { 5214 gcc_assert (!msa_p); 5215 return dbl_p ? "dmfc1\t%0,%1" : "mfc1\t%0,%1"; 5216 } 5217 5218 if (ALL_COP_REG_P (REGNO (src))) 5219 { 5220 static char retval[] = "dmfc_\t%0,%1"; 5221 5222 retval[4] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src)); 5223 return dbl_p ? retval : retval + 1; 5224 } 5225 } 5226 5227 if (src_code == MEM) 5228 switch (GET_MODE_SIZE (mode)) 5229 { 5230 case 1: return "lbu\t%0,%1"; 5231 case 2: return "lhu\t%0,%1"; 5232 case 4: return "lw\t%0,%1"; 5233 case 8: return "ld\t%0,%1"; 5234 default: gcc_unreachable (); 5235 } 5236 5237 if (src_code == CONST_INT) 5238 { 5239 /* Don't use the X format for the operand itself, because that 5240 will give out-of-range numbers for 64-bit hosts and 32-bit 5241 targets. */ 5242 if (!TARGET_MIPS16) 5243 return "li\t%0,%1\t\t\t# %X1"; 5244 5245 if (SMALL_OPERAND_UNSIGNED (INTVAL (src))) 5246 return "li\t%0,%1"; 5247 5248 if (SMALL_OPERAND_UNSIGNED (-INTVAL (src))) 5249 return "#"; 5250 } 5251 5252 if (src_code == HIGH) 5253 return TARGET_MIPS16 ? "#" : "lui\t%0,%h1"; 5254 5255 if (CONST_GP_P (src)) 5256 return "move\t%0,%1"; 5257 5258 if (mips_symbolic_constant_p (src, SYMBOL_CONTEXT_LEA, &symbol_type) 5259 && mips_lo_relocs[symbol_type] != 0) 5260 { 5261 /* A signed 16-bit constant formed by applying a relocation 5262 operator to a symbolic address. */ 5263 gcc_assert (!mips_split_p[symbol_type]); 5264 return "li\t%0,%R1"; 5265 } 5266 5267 if (symbolic_operand (src, VOIDmode)) 5268 { 5269 gcc_assert (TARGET_MIPS16 5270 ? TARGET_MIPS16_TEXT_LOADS 5271 : !TARGET_EXPLICIT_RELOCS); 5272 return dbl_p ? "dla\t%0,%1" : "la\t%0,%1"; 5273 } 5274 } 5275 if (src_code == REG && FP_REG_P (REGNO (src))) 5276 { 5277 if (dest_code == REG && FP_REG_P (REGNO (dest))) 5278 { 5279 if (GET_MODE (dest) == V2SFmode) 5280 return "mov.ps\t%0,%1"; 5281 else if (msa_p) 5282 return "move.v\t%w0,%w1"; 5283 else 5284 return dbl_p ? "mov.d\t%0,%1" : "mov.s\t%0,%1"; 5285 } 5286 5287 if (dest_code == MEM) 5288 { 5289 if (msa_p) 5290 return "st.%v1\t%w1,%0"; 5291 5292 return dbl_p ? "sdc1\t%1,%0" : "swc1\t%1,%0"; 5293 } 5294 } 5295 if (dest_code == REG && FP_REG_P (REGNO (dest))) 5296 { 5297 if (src_code == MEM) 5298 { 5299 if (msa_p) 5300 return "ld.%v0\t%w0,%1"; 5301 5302 return dbl_p ? "ldc1\t%0,%1" : "lwc1\t%0,%1"; 5303 } 5304 } 5305 if (dest_code == REG && ALL_COP_REG_P (REGNO (dest)) && src_code == MEM) 5306 { 5307 static char retval[] = "l_c_\t%0,%1"; 5308 5309 retval[1] = (dbl_p ? 'd' : 'w'); 5310 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (dest)); 5311 return retval; 5312 } 5313 if (dest_code == MEM && src_code == REG && ALL_COP_REG_P (REGNO (src))) 5314 { 5315 static char retval[] = "s_c_\t%1,%0"; 5316 5317 retval[1] = (dbl_p ? 'd' : 'w'); 5318 retval[3] = COPNUM_AS_CHAR_FROM_REGNUM (REGNO (src)); 5319 return retval; 5320 } 5321 gcc_unreachable (); 5322 } 5323 5324 /* Return true if CMP1 is a suitable second operand for integer ordering 5325 test CODE. See also the *sCC patterns in mips.md. */ 5326 5327 static bool 5328 mips_int_order_operand_ok_p (enum rtx_code code, rtx cmp1) 5329 { 5330 switch (code) 5331 { 5332 case GT: 5333 case GTU: 5334 return reg_or_0_operand (cmp1, VOIDmode); 5335 5336 case GE: 5337 case GEU: 5338 return !TARGET_MIPS16 && cmp1 == const1_rtx; 5339 5340 case LT: 5341 case LTU: 5342 return arith_operand (cmp1, VOIDmode); 5343 5344 case LE: 5345 return sle_operand (cmp1, VOIDmode); 5346 5347 case LEU: 5348 return sleu_operand (cmp1, VOIDmode); 5349 5350 default: 5351 gcc_unreachable (); 5352 } 5353 } 5354 5355 /* Return true if *CMP1 (of mode MODE) is a valid second operand for 5356 integer ordering test *CODE, or if an equivalent combination can 5357 be formed by adjusting *CODE and *CMP1. When returning true, update 5358 *CODE and *CMP1 with the chosen code and operand, otherwise leave 5359 them alone. */ 5360 5361 static bool 5362 mips_canonicalize_int_order_test (enum rtx_code *code, rtx *cmp1, 5363 machine_mode mode) 5364 { 5365 HOST_WIDE_INT plus_one; 5366 5367 if (mips_int_order_operand_ok_p (*code, *cmp1)) 5368 return true; 5369 5370 if (CONST_INT_P (*cmp1)) 5371 switch (*code) 5372 { 5373 case LE: 5374 plus_one = trunc_int_for_mode (UINTVAL (*cmp1) + 1, mode); 5375 if (INTVAL (*cmp1) < plus_one) 5376 { 5377 *code = LT; 5378 *cmp1 = force_reg (mode, GEN_INT (plus_one)); 5379 return true; 5380 } 5381 break; 5382 5383 case LEU: 5384 plus_one = trunc_int_for_mode (UINTVAL (*cmp1) + 1, mode); 5385 if (plus_one != 0) 5386 { 5387 *code = LTU; 5388 *cmp1 = force_reg (mode, GEN_INT (plus_one)); 5389 return true; 5390 } 5391 break; 5392 5393 default: 5394 break; 5395 } 5396 return false; 5397 } 5398 5399 /* Compare CMP0 and CMP1 using ordering test CODE and store the result 5400 in TARGET. CMP0 and TARGET are register_operands. If INVERT_PTR 5401 is nonnull, it's OK to set TARGET to the inverse of the result and 5402 flip *INVERT_PTR instead. */ 5403 5404 static void 5405 mips_emit_int_order_test (enum rtx_code code, bool *invert_ptr, 5406 rtx target, rtx cmp0, rtx cmp1) 5407 { 5408 machine_mode mode; 5409 5410 /* First see if there is a MIPS instruction that can do this operation. 5411 If not, try doing the same for the inverse operation. If that also 5412 fails, force CMP1 into a register and try again. */ 5413 mode = GET_MODE (cmp0); 5414 if (mips_canonicalize_int_order_test (&code, &cmp1, mode)) 5415 mips_emit_binary (code, target, cmp0, cmp1); 5416 else 5417 { 5418 enum rtx_code inv_code = reverse_condition (code); 5419 if (!mips_canonicalize_int_order_test (&inv_code, &cmp1, mode)) 5420 { 5421 cmp1 = force_reg (mode, cmp1); 5422 mips_emit_int_order_test (code, invert_ptr, target, cmp0, cmp1); 5423 } 5424 else if (invert_ptr == 0) 5425 { 5426 rtx inv_target; 5427 5428 inv_target = mips_force_binary (GET_MODE (target), 5429 inv_code, cmp0, cmp1); 5430 mips_emit_binary (XOR, target, inv_target, const1_rtx); 5431 } 5432 else 5433 { 5434 *invert_ptr = !*invert_ptr; 5435 mips_emit_binary (inv_code, target, cmp0, cmp1); 5436 } 5437 } 5438 } 5439 5440 /* Return a register that is zero iff CMP0 and CMP1 are equal. 5441 The register will have the same mode as CMP0. */ 5442 5443 static rtx 5444 mips_zero_if_equal (rtx cmp0, rtx cmp1) 5445 { 5446 if (cmp1 == const0_rtx) 5447 return cmp0; 5448 5449 if (uns_arith_operand (cmp1, VOIDmode)) 5450 return expand_binop (GET_MODE (cmp0), xor_optab, 5451 cmp0, cmp1, 0, 0, OPTAB_DIRECT); 5452 5453 return expand_binop (GET_MODE (cmp0), sub_optab, 5454 cmp0, cmp1, 0, 0, OPTAB_DIRECT); 5455 } 5456 5457 /* Convert *CODE into a code that can be used in a floating-point 5458 scc instruction (C.cond.fmt). Return true if the values of 5459 the condition code registers will be inverted, with 0 indicating 5460 that the condition holds. */ 5461 5462 static bool 5463 mips_reversed_fp_cond (enum rtx_code *code) 5464 { 5465 switch (*code) 5466 { 5467 case NE: 5468 case LTGT: 5469 case ORDERED: 5470 *code = reverse_condition_maybe_unordered (*code); 5471 return true; 5472 5473 default: 5474 return false; 5475 } 5476 } 5477 5478 /* Allocate a floating-point condition-code register of mode MODE. 5479 5480 These condition code registers are used for certain kinds 5481 of compound operation, such as compare and branches, vconds, 5482 and built-in functions. At expand time, their use is entirely 5483 controlled by MIPS-specific code and is entirely internal 5484 to these compound operations. 5485 5486 We could (and did in the past) expose condition-code values 5487 as pseudo registers and leave the register allocator to pick 5488 appropriate registers. The problem is that it is not practically 5489 possible for the rtl optimizers to guarantee that no spills will 5490 be needed, even when AVOID_CCMODE_COPIES is defined. We would 5491 therefore need spill and reload sequences to handle the worst case. 5492 5493 Although such sequences do exist, they are very expensive and are 5494 not something we'd want to use. This is especially true of CCV2 and 5495 CCV4, where all the shuffling would greatly outweigh whatever benefit 5496 the vectorization itself provides. 5497 5498 The main benefit of having more than one condition-code register 5499 is to allow the pipelining of operations, especially those involving 5500 comparisons and conditional moves. We don't really expect the 5501 registers to be live for long periods, and certainly never want 5502 them to be live across calls. 5503 5504 Also, there should be no penalty attached to using all the available 5505 registers. They are simply bits in the same underlying FPU control 5506 register. 5507 5508 We therefore expose the hardware registers from the outset and use 5509 a simple round-robin allocation scheme. */ 5510 5511 static rtx 5512 mips_allocate_fcc (machine_mode mode) 5513 { 5514 unsigned int regno, count; 5515 5516 gcc_assert (TARGET_HARD_FLOAT && ISA_HAS_8CC); 5517 5518 if (mode == CCmode) 5519 count = 1; 5520 else if (mode == CCV2mode) 5521 count = 2; 5522 else if (mode == CCV4mode) 5523 count = 4; 5524 else 5525 gcc_unreachable (); 5526 5527 cfun->machine->next_fcc += -cfun->machine->next_fcc & (count - 1); 5528 if (cfun->machine->next_fcc > ST_REG_LAST - ST_REG_FIRST) 5529 cfun->machine->next_fcc = 0; 5530 regno = ST_REG_FIRST + cfun->machine->next_fcc; 5531 cfun->machine->next_fcc += count; 5532 return gen_rtx_REG (mode, regno); 5533 } 5534 5535 /* Convert a comparison into something that can be used in a branch or 5536 conditional move. On entry, *OP0 and *OP1 are the values being 5537 compared and *CODE is the code used to compare them. 5538 5539 Update *CODE, *OP0 and *OP1 so that they describe the final comparison. 5540 If NEED_EQ_NE_P, then only EQ or NE comparisons against zero are possible, 5541 otherwise any standard branch condition can be used. The standard branch 5542 conditions are: 5543 5544 - EQ or NE between two registers. 5545 - any comparison between a register and zero. 5546 - if compact branches are available then any condition is valid. */ 5547 5548 static void 5549 mips_emit_compare (enum rtx_code *code, rtx *op0, rtx *op1, bool need_eq_ne_p) 5550 { 5551 rtx cmp_op0 = *op0; 5552 rtx cmp_op1 = *op1; 5553 5554 if (GET_MODE_CLASS (GET_MODE (*op0)) == MODE_INT) 5555 { 5556 if (!need_eq_ne_p && *op1 == const0_rtx) 5557 ; 5558 else if (*code == EQ || *code == NE) 5559 { 5560 if (need_eq_ne_p) 5561 { 5562 *op0 = mips_zero_if_equal (cmp_op0, cmp_op1); 5563 *op1 = const0_rtx; 5564 } 5565 else 5566 *op1 = force_reg (GET_MODE (cmp_op0), cmp_op1); 5567 } 5568 else if (!need_eq_ne_p && TARGET_CB_MAYBE) 5569 { 5570 bool swap = false; 5571 switch (*code) 5572 { 5573 case LE: 5574 swap = true; 5575 *code = GE; 5576 break; 5577 case GT: 5578 swap = true; 5579 *code = LT; 5580 break; 5581 case LEU: 5582 swap = true; 5583 *code = GEU; 5584 break; 5585 case GTU: 5586 swap = true; 5587 *code = LTU; 5588 break; 5589 case GE: 5590 case LT: 5591 case GEU: 5592 case LTU: 5593 /* Do nothing. */ 5594 break; 5595 default: 5596 gcc_unreachable (); 5597 } 5598 *op1 = force_reg (GET_MODE (cmp_op0), cmp_op1); 5599 if (swap) 5600 { 5601 rtx tmp = *op1; 5602 *op1 = *op0; 5603 *op0 = tmp; 5604 } 5605 } 5606 else 5607 { 5608 /* The comparison needs a separate scc instruction. Store the 5609 result of the scc in *OP0 and compare it against zero. */ 5610 bool invert = false; 5611 *op0 = gen_reg_rtx (GET_MODE (cmp_op0)); 5612 mips_emit_int_order_test (*code, &invert, *op0, cmp_op0, cmp_op1); 5613 *code = (invert ? EQ : NE); 5614 *op1 = const0_rtx; 5615 } 5616 } 5617 else if (ALL_FIXED_POINT_MODE_P (GET_MODE (cmp_op0))) 5618 { 5619 *op0 = gen_rtx_REG (CCDSPmode, CCDSP_CC_REGNUM); 5620 mips_emit_binary (*code, *op0, cmp_op0, cmp_op1); 5621 *code = NE; 5622 *op1 = const0_rtx; 5623 } 5624 else 5625 { 5626 enum rtx_code cmp_code; 5627 5628 /* Floating-point tests use a separate C.cond.fmt or CMP.cond.fmt 5629 comparison to set a register. The branch or conditional move will 5630 then compare that register against zero. 5631 5632 Set CMP_CODE to the code of the comparison instruction and 5633 *CODE to the code that the branch or move should use. */ 5634 cmp_code = *code; 5635 if (ISA_HAS_CCF) 5636 { 5637 /* All FP conditions can be implemented directly with CMP.cond.fmt 5638 or by reversing the operands. */ 5639 *code = NE; 5640 *op0 = gen_reg_rtx (CCFmode); 5641 } 5642 else 5643 { 5644 /* Three FP conditions cannot be implemented by reversing the 5645 operands for C.cond.fmt, instead a reversed condition code is 5646 required and a test for false. */ 5647 *code = mips_reversed_fp_cond (&cmp_code) ? EQ : NE; 5648 if (ISA_HAS_8CC) 5649 *op0 = mips_allocate_fcc (CCmode); 5650 else 5651 *op0 = gen_rtx_REG (CCmode, FPSW_REGNUM); 5652 } 5653 5654 *op1 = const0_rtx; 5655 mips_emit_binary (cmp_code, *op0, cmp_op0, cmp_op1); 5656 } 5657 } 5658 5659 /* Try performing the comparison in OPERANDS[1], whose arms are OPERANDS[2] 5660 and OPERAND[3]. Store the result in OPERANDS[0]. 5661 5662 On 64-bit targets, the mode of the comparison and target will always be 5663 SImode, thus possibly narrower than that of the comparison's operands. */ 5664 5665 void 5666 mips_expand_scc (rtx operands[]) 5667 { 5668 rtx target = operands[0]; 5669 enum rtx_code code = GET_CODE (operands[1]); 5670 rtx op0 = operands[2]; 5671 rtx op1 = operands[3]; 5672 5673 gcc_assert (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT); 5674 5675 if (code == EQ || code == NE) 5676 { 5677 if (ISA_HAS_SEQ_SNE 5678 && reg_imm10_operand (op1, GET_MODE (op1))) 5679 mips_emit_binary (code, target, op0, op1); 5680 else 5681 { 5682 rtx zie = mips_zero_if_equal (op0, op1); 5683 mips_emit_binary (code, target, zie, const0_rtx); 5684 } 5685 } 5686 else 5687 mips_emit_int_order_test (code, 0, target, op0, op1); 5688 } 5689 5690 /* Compare OPERANDS[1] with OPERANDS[2] using comparison code 5691 CODE and jump to OPERANDS[3] if the condition holds. */ 5692 5693 void 5694 mips_expand_conditional_branch (rtx *operands) 5695 { 5696 enum rtx_code code = GET_CODE (operands[0]); 5697 rtx op0 = operands[1]; 5698 rtx op1 = operands[2]; 5699 rtx condition; 5700 5701 mips_emit_compare (&code, &op0, &op1, TARGET_MIPS16); 5702 condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1); 5703 emit_jump_insn (gen_condjump (condition, operands[3])); 5704 } 5705 5706 /* Implement: 5707 5708 (set temp (COND:CCV2 CMP_OP0 CMP_OP1)) 5709 (set DEST (unspec [TRUE_SRC FALSE_SRC temp] UNSPEC_MOVE_TF_PS)) */ 5710 5711 void 5712 mips_expand_vcondv2sf (rtx dest, rtx true_src, rtx false_src, 5713 enum rtx_code cond, rtx cmp_op0, rtx cmp_op1) 5714 { 5715 rtx cmp_result; 5716 bool reversed_p; 5717 5718 reversed_p = mips_reversed_fp_cond (&cond); 5719 cmp_result = mips_allocate_fcc (CCV2mode); 5720 emit_insn (gen_scc_ps (cmp_result, 5721 gen_rtx_fmt_ee (cond, VOIDmode, cmp_op0, cmp_op1))); 5722 if (reversed_p) 5723 emit_insn (gen_mips_cond_move_tf_ps (dest, false_src, true_src, 5724 cmp_result)); 5725 else 5726 emit_insn (gen_mips_cond_move_tf_ps (dest, true_src, false_src, 5727 cmp_result)); 5728 } 5729 5730 /* Perform the comparison in OPERANDS[1]. Move OPERANDS[2] into OPERANDS[0] 5731 if the condition holds, otherwise move OPERANDS[3] into OPERANDS[0]. */ 5732 5733 void 5734 mips_expand_conditional_move (rtx *operands) 5735 { 5736 rtx cond; 5737 enum rtx_code code = GET_CODE (operands[1]); 5738 rtx op0 = XEXP (operands[1], 0); 5739 rtx op1 = XEXP (operands[1], 1); 5740 5741 mips_emit_compare (&code, &op0, &op1, true); 5742 cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1); 5743 5744 /* There is no direct support for general conditional GP move involving 5745 two registers using SEL. */ 5746 if (ISA_HAS_SEL 5747 && INTEGRAL_MODE_P (GET_MODE (operands[2])) 5748 && register_operand (operands[2], VOIDmode) 5749 && register_operand (operands[3], VOIDmode)) 5750 { 5751 machine_mode mode = GET_MODE (operands[0]); 5752 rtx temp = gen_reg_rtx (mode); 5753 rtx temp2 = gen_reg_rtx (mode); 5754 5755 emit_insn (gen_rtx_SET (temp, 5756 gen_rtx_IF_THEN_ELSE (mode, cond, 5757 operands[2], const0_rtx))); 5758 5759 /* Flip the test for the second operand. */ 5760 cond = gen_rtx_fmt_ee ((code == EQ) ? NE : EQ, GET_MODE (op0), op0, op1); 5761 5762 emit_insn (gen_rtx_SET (temp2, 5763 gen_rtx_IF_THEN_ELSE (mode, cond, 5764 operands[3], const0_rtx))); 5765 5766 /* Merge the two results, at least one is guaranteed to be zero. */ 5767 emit_insn (gen_rtx_SET (operands[0], gen_rtx_IOR (mode, temp, temp2))); 5768 } 5769 else 5770 { 5771 if (FLOAT_MODE_P (GET_MODE (operands[2])) && !ISA_HAS_SEL) 5772 { 5773 operands[2] = force_reg (GET_MODE (operands[0]), operands[2]); 5774 operands[3] = force_reg (GET_MODE (operands[0]), operands[3]); 5775 } 5776 5777 emit_insn (gen_rtx_SET (operands[0], 5778 gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]), cond, 5779 operands[2], operands[3]))); 5780 } 5781 } 5782 5783 /* Perform the comparison in COMPARISON, then trap if the condition holds. */ 5784 5785 void 5786 mips_expand_conditional_trap (rtx comparison) 5787 { 5788 rtx op0, op1; 5789 machine_mode mode; 5790 enum rtx_code code; 5791 5792 /* MIPS conditional trap instructions don't have GT or LE flavors, 5793 so we must swap the operands and convert to LT and GE respectively. */ 5794 code = GET_CODE (comparison); 5795 switch (code) 5796 { 5797 case GT: 5798 case LE: 5799 case GTU: 5800 case LEU: 5801 code = swap_condition (code); 5802 op0 = XEXP (comparison, 1); 5803 op1 = XEXP (comparison, 0); 5804 break; 5805 5806 default: 5807 op0 = XEXP (comparison, 0); 5808 op1 = XEXP (comparison, 1); 5809 break; 5810 } 5811 5812 mode = GET_MODE (XEXP (comparison, 0)); 5813 op0 = force_reg (mode, op0); 5814 if (!(ISA_HAS_COND_TRAPI 5815 ? arith_operand (op1, mode) 5816 : reg_or_0_operand (op1, mode))) 5817 op1 = force_reg (mode, op1); 5818 5819 emit_insn (gen_rtx_TRAP_IF (VOIDmode, 5820 gen_rtx_fmt_ee (code, mode, op0, op1), 5821 const0_rtx)); 5822 } 5823 5824 /* Initialize *CUM for a call to a function of type FNTYPE. */ 5825 5826 void 5827 mips_init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype) 5828 { 5829 memset (cum, 0, sizeof (*cum)); 5830 cum->prototype = (fntype && prototype_p (fntype)); 5831 cum->gp_reg_found = (cum->prototype && stdarg_p (fntype)); 5832 } 5833 5834 /* Fill INFO with information about a single argument. CUM is the 5835 cumulative state for earlier arguments. MODE is the mode of this 5836 argument and TYPE is its type (if known). NAMED is true if this 5837 is a named (fixed) argument rather than a variable one. */ 5838 5839 static void 5840 mips_get_arg_info (struct mips_arg_info *info, const CUMULATIVE_ARGS *cum, 5841 machine_mode mode, const_tree type, bool named) 5842 { 5843 bool doubleword_aligned_p; 5844 unsigned int num_bytes, num_words, max_regs; 5845 5846 /* Work out the size of the argument. */ 5847 num_bytes = type ? int_size_in_bytes (type) : GET_MODE_SIZE (mode); 5848 num_words = (num_bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; 5849 5850 /* Decide whether it should go in a floating-point register, assuming 5851 one is free. Later code checks for availability. 5852 5853 The checks against UNITS_PER_FPVALUE handle the soft-float and 5854 single-float cases. */ 5855 switch (mips_abi) 5856 { 5857 case ABI_EABI: 5858 /* The EABI conventions have traditionally been defined in terms 5859 of TYPE_MODE, regardless of the actual type. */ 5860 info->fpr_p = ((GET_MODE_CLASS (mode) == MODE_FLOAT 5861 || mode == V2SFmode) 5862 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE); 5863 break; 5864 5865 case ABI_32: 5866 case ABI_O64: 5867 /* Only leading floating-point scalars are passed in 5868 floating-point registers. We also handle vector floats the same 5869 say, which is OK because they are not covered by the standard ABI. */ 5870 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode); 5871 info->fpr_p = (!cum->gp_reg_found 5872 && cum->arg_number < 2 5873 && (type == 0 5874 || SCALAR_FLOAT_TYPE_P (type) 5875 || VECTOR_FLOAT_TYPE_P (type)) 5876 && (GET_MODE_CLASS (mode) == MODE_FLOAT 5877 || mode == V2SFmode) 5878 && GET_MODE_SIZE (mode) <= UNITS_PER_FPVALUE); 5879 break; 5880 5881 case ABI_N32: 5882 case ABI_64: 5883 /* Scalar, complex and vector floating-point types are passed in 5884 floating-point registers, as long as this is a named rather 5885 than a variable argument. */ 5886 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode); 5887 info->fpr_p = (named 5888 && (type == 0 || FLOAT_TYPE_P (type)) 5889 && (GET_MODE_CLASS (mode) == MODE_FLOAT 5890 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT 5891 || mode == V2SFmode) 5892 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_FPVALUE); 5893 5894 /* ??? According to the ABI documentation, the real and imaginary 5895 parts of complex floats should be passed in individual registers. 5896 The real and imaginary parts of stack arguments are supposed 5897 to be contiguous and there should be an extra word of padding 5898 at the end. 5899 5900 This has two problems. First, it makes it impossible to use a 5901 single "void *" va_list type, since register and stack arguments 5902 are passed differently. (At the time of writing, MIPSpro cannot 5903 handle complex float varargs correctly.) Second, it's unclear 5904 what should happen when there is only one register free. 5905 5906 For now, we assume that named complex floats should go into FPRs 5907 if there are two FPRs free, otherwise they should be passed in the 5908 same way as a struct containing two floats. */ 5909 if (info->fpr_p 5910 && GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT 5911 && GET_MODE_UNIT_SIZE (mode) < UNITS_PER_FPVALUE) 5912 { 5913 if (cum->num_gprs >= MAX_ARGS_IN_REGISTERS - 1) 5914 info->fpr_p = false; 5915 else 5916 num_words = 2; 5917 } 5918 break; 5919 5920 default: 5921 gcc_unreachable (); 5922 } 5923 5924 /* See whether the argument has doubleword alignment. */ 5925 doubleword_aligned_p = (mips_function_arg_boundary (mode, type) 5926 > BITS_PER_WORD); 5927 5928 /* Set REG_OFFSET to the register count we're interested in. 5929 The EABI allocates the floating-point registers separately, 5930 but the other ABIs allocate them like integer registers. */ 5931 info->reg_offset = (mips_abi == ABI_EABI && info->fpr_p 5932 ? cum->num_fprs 5933 : cum->num_gprs); 5934 5935 /* Advance to an even register if the argument is doubleword-aligned. */ 5936 if (doubleword_aligned_p) 5937 info->reg_offset += info->reg_offset & 1; 5938 5939 /* Work out the offset of a stack argument. */ 5940 info->stack_offset = cum->stack_words; 5941 if (doubleword_aligned_p) 5942 info->stack_offset += info->stack_offset & 1; 5943 5944 max_regs = MAX_ARGS_IN_REGISTERS - info->reg_offset; 5945 5946 /* Partition the argument between registers and stack. */ 5947 info->reg_words = MIN (num_words, max_regs); 5948 info->stack_words = num_words - info->reg_words; 5949 } 5950 5951 /* INFO describes a register argument that has the normal format for the 5952 argument's mode. Return the register it uses, assuming that FPRs are 5953 available if HARD_FLOAT_P. */ 5954 5955 static unsigned int 5956 mips_arg_regno (const struct mips_arg_info *info, bool hard_float_p) 5957 { 5958 if (!info->fpr_p || !hard_float_p) 5959 return GP_ARG_FIRST + info->reg_offset; 5960 else if (mips_abi == ABI_32 && TARGET_DOUBLE_FLOAT && info->reg_offset > 0) 5961 /* In o32, the second argument is always passed in $f14 5962 for TARGET_DOUBLE_FLOAT, regardless of whether the 5963 first argument was a word or doubleword. */ 5964 return FP_ARG_FIRST + 2; 5965 else 5966 return FP_ARG_FIRST + info->reg_offset; 5967 } 5968 5969 /* Implement TARGET_STRICT_ARGUMENT_NAMING. */ 5970 5971 static bool 5972 mips_strict_argument_naming (cumulative_args_t ca ATTRIBUTE_UNUSED) 5973 { 5974 return !TARGET_OLDABI; 5975 } 5976 5977 /* Implement TARGET_FUNCTION_ARG. */ 5978 5979 static rtx 5980 mips_function_arg (cumulative_args_t cum_v, const function_arg_info &arg) 5981 { 5982 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); 5983 struct mips_arg_info info; 5984 5985 /* We will be called with an end marker after the last argument 5986 has been seen. Whatever we return will be passed to the call expander. 5987 If we need a MIPS16 fp_code, return a REG with the code stored as 5988 the mode. */ 5989 if (arg.end_marker_p ()) 5990 { 5991 if (TARGET_MIPS16 && cum->fp_code != 0) 5992 return gen_rtx_REG ((machine_mode) cum->fp_code, 0); 5993 else 5994 return NULL; 5995 } 5996 5997 mips_get_arg_info (&info, cum, arg.mode, arg.type, arg.named); 5998 5999 /* Return straight away if the whole argument is passed on the stack. */ 6000 if (info.reg_offset == MAX_ARGS_IN_REGISTERS) 6001 return NULL; 6002 6003 /* The n32 and n64 ABIs say that if any 64-bit chunk of the structure 6004 contains a double in its entirety, then that 64-bit chunk is passed 6005 in a floating-point register. */ 6006 if (TARGET_NEWABI 6007 && TARGET_HARD_FLOAT 6008 && arg.named 6009 && arg.type != 0 6010 && TREE_CODE (arg.type) == RECORD_TYPE 6011 && TYPE_SIZE_UNIT (arg.type) 6012 && tree_fits_uhwi_p (TYPE_SIZE_UNIT (arg.type))) 6013 { 6014 tree field; 6015 6016 /* First check to see if there is any such field. */ 6017 for (field = TYPE_FIELDS (arg.type); field; field = DECL_CHAIN (field)) 6018 if (TREE_CODE (field) == FIELD_DECL 6019 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (field)) 6020 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD 6021 && tree_fits_shwi_p (bit_position (field)) 6022 && int_bit_position (field) % BITS_PER_WORD == 0) 6023 break; 6024 6025 if (field != 0) 6026 { 6027 /* Now handle the special case by returning a PARALLEL 6028 indicating where each 64-bit chunk goes. INFO.REG_WORDS 6029 chunks are passed in registers. */ 6030 unsigned int i; 6031 HOST_WIDE_INT bitpos; 6032 rtx ret; 6033 6034 /* assign_parms checks the mode of ENTRY_PARM, so we must 6035 use the actual mode here. */ 6036 ret = gen_rtx_PARALLEL (arg.mode, rtvec_alloc (info.reg_words)); 6037 6038 bitpos = 0; 6039 field = TYPE_FIELDS (arg.type); 6040 for (i = 0; i < info.reg_words; i++) 6041 { 6042 rtx reg; 6043 6044 for (; field; field = DECL_CHAIN (field)) 6045 if (TREE_CODE (field) == FIELD_DECL 6046 && int_bit_position (field) >= bitpos) 6047 break; 6048 6049 if (field 6050 && int_bit_position (field) == bitpos 6051 && SCALAR_FLOAT_TYPE_P (TREE_TYPE (field)) 6052 && TYPE_PRECISION (TREE_TYPE (field)) == BITS_PER_WORD) 6053 reg = gen_rtx_REG (DFmode, FP_ARG_FIRST + info.reg_offset + i); 6054 else 6055 reg = gen_rtx_REG (DImode, GP_ARG_FIRST + info.reg_offset + i); 6056 6057 XVECEXP (ret, 0, i) 6058 = gen_rtx_EXPR_LIST (VOIDmode, reg, 6059 GEN_INT (bitpos / BITS_PER_UNIT)); 6060 6061 bitpos += BITS_PER_WORD; 6062 } 6063 return ret; 6064 } 6065 } 6066 6067 /* Handle the n32/n64 conventions for passing complex floating-point 6068 arguments in FPR pairs. The real part goes in the lower register 6069 and the imaginary part goes in the upper register. */ 6070 if (TARGET_NEWABI 6071 && info.fpr_p 6072 && GET_MODE_CLASS (arg.mode) == MODE_COMPLEX_FLOAT) 6073 { 6074 rtx real, imag; 6075 machine_mode inner; 6076 unsigned int regno; 6077 6078 inner = GET_MODE_INNER (arg.mode); 6079 regno = FP_ARG_FIRST + info.reg_offset; 6080 if (info.reg_words * UNITS_PER_WORD == GET_MODE_SIZE (inner)) 6081 { 6082 /* Real part in registers, imaginary part on stack. */ 6083 gcc_assert (info.stack_words == info.reg_words); 6084 return gen_rtx_REG (inner, regno); 6085 } 6086 else 6087 { 6088 gcc_assert (info.stack_words == 0); 6089 real = gen_rtx_EXPR_LIST (VOIDmode, 6090 gen_rtx_REG (inner, regno), 6091 const0_rtx); 6092 imag = gen_rtx_EXPR_LIST (VOIDmode, 6093 gen_rtx_REG (inner, 6094 regno + info.reg_words / 2), 6095 GEN_INT (GET_MODE_SIZE (inner))); 6096 return gen_rtx_PARALLEL (arg.mode, gen_rtvec (2, real, imag)); 6097 } 6098 } 6099 6100 return gen_rtx_REG (arg.mode, mips_arg_regno (&info, TARGET_HARD_FLOAT)); 6101 } 6102 6103 /* Implement TARGET_FUNCTION_ARG_ADVANCE. */ 6104 6105 static void 6106 mips_function_arg_advance (cumulative_args_t cum_v, 6107 const function_arg_info &arg) 6108 { 6109 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); 6110 struct mips_arg_info info; 6111 6112 mips_get_arg_info (&info, cum, arg.mode, arg.type, arg.named); 6113 6114 if (!info.fpr_p) 6115 cum->gp_reg_found = true; 6116 6117 /* See the comment above the CUMULATIVE_ARGS structure in mips.h for 6118 an explanation of what this code does. It assumes that we're using 6119 either the o32 or the o64 ABI, both of which pass at most 2 arguments 6120 in FPRs. */ 6121 if (cum->arg_number < 2 && info.fpr_p) 6122 cum->fp_code += (arg.mode == SFmode ? 1 : 2) << (cum->arg_number * 2); 6123 6124 /* Advance the register count. This has the effect of setting 6125 num_gprs to MAX_ARGS_IN_REGISTERS if a doubleword-aligned 6126 argument required us to skip the final GPR and pass the whole 6127 argument on the stack. */ 6128 if (mips_abi != ABI_EABI || !info.fpr_p) 6129 cum->num_gprs = info.reg_offset + info.reg_words; 6130 else if (info.reg_words > 0) 6131 cum->num_fprs += MAX_FPRS_PER_FMT; 6132 6133 /* Advance the stack word count. */ 6134 if (info.stack_words > 0) 6135 cum->stack_words = info.stack_offset + info.stack_words; 6136 6137 cum->arg_number++; 6138 } 6139 6140 /* Implement TARGET_ARG_PARTIAL_BYTES. */ 6141 6142 static int 6143 mips_arg_partial_bytes (cumulative_args_t cum, const function_arg_info &arg) 6144 { 6145 struct mips_arg_info info; 6146 6147 mips_get_arg_info (&info, get_cumulative_args (cum), 6148 arg.mode, arg.type, arg.named); 6149 return info.stack_words > 0 ? info.reg_words * UNITS_PER_WORD : 0; 6150 } 6151 6152 /* Implement TARGET_FUNCTION_ARG_BOUNDARY. Every parameter gets at 6153 least PARM_BOUNDARY bits of alignment, but will be given anything up 6154 to STACK_BOUNDARY bits if the type requires it. */ 6155 6156 static unsigned int 6157 mips_function_arg_boundary (machine_mode mode, const_tree type) 6158 { 6159 unsigned int alignment; 6160 6161 alignment = type ? TYPE_ALIGN (type) : GET_MODE_ALIGNMENT (mode); 6162 if (alignment < PARM_BOUNDARY) 6163 alignment = PARM_BOUNDARY; 6164 if (alignment > STACK_BOUNDARY) 6165 alignment = STACK_BOUNDARY; 6166 return alignment; 6167 } 6168 6169 /* Implement TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE. */ 6170 6171 static fixed_size_mode 6172 mips_get_reg_raw_mode (int regno) 6173 { 6174 if (TARGET_FLOATXX && FP_REG_P (regno)) 6175 return DFmode; 6176 return default_get_reg_raw_mode (regno); 6177 } 6178 6179 /* Implement TARGET_FUNCTION_ARG_PADDING; return PAD_UPWARD if the first 6180 byte of the stack slot has useful data, PAD_DOWNWARD if the last byte 6181 does. */ 6182 6183 static pad_direction 6184 mips_function_arg_padding (machine_mode mode, const_tree type) 6185 { 6186 /* On little-endian targets, the first byte of every stack argument 6187 is passed in the first byte of the stack slot. */ 6188 if (!BYTES_BIG_ENDIAN) 6189 return PAD_UPWARD; 6190 6191 /* Otherwise, integral types are padded downward: the last byte of a 6192 stack argument is passed in the last byte of the stack slot. */ 6193 if (type != 0 6194 ? (INTEGRAL_TYPE_P (type) 6195 || POINTER_TYPE_P (type) 6196 || FIXED_POINT_TYPE_P (type)) 6197 : (SCALAR_INT_MODE_P (mode) 6198 || ALL_SCALAR_FIXED_POINT_MODE_P (mode))) 6199 return PAD_DOWNWARD; 6200 6201 /* Big-endian o64 pads floating-point arguments downward. */ 6202 if (mips_abi == ABI_O64) 6203 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT) 6204 return PAD_DOWNWARD; 6205 6206 /* Other types are padded upward for o32, o64, n32 and n64. */ 6207 if (mips_abi != ABI_EABI) 6208 return PAD_UPWARD; 6209 6210 /* Arguments smaller than a stack slot are padded downward. */ 6211 if (mode != BLKmode 6212 ? GET_MODE_BITSIZE (mode) >= PARM_BOUNDARY 6213 : int_size_in_bytes (type) >= (PARM_BOUNDARY / BITS_PER_UNIT)) 6214 return PAD_UPWARD; 6215 6216 return PAD_DOWNWARD; 6217 } 6218 6219 /* Likewise BLOCK_REG_PADDING (MODE, TYPE, ...). Return !BYTES_BIG_ENDIAN 6220 if the least significant byte of the register has useful data. Return 6221 the opposite if the most significant byte does. */ 6222 6223 bool 6224 mips_pad_reg_upward (machine_mode mode, tree type) 6225 { 6226 /* No shifting is required for floating-point arguments. */ 6227 if (type != 0 ? FLOAT_TYPE_P (type) : GET_MODE_CLASS (mode) == MODE_FLOAT) 6228 return !BYTES_BIG_ENDIAN; 6229 6230 /* Otherwise, apply the same padding to register arguments as we do 6231 to stack arguments. */ 6232 return mips_function_arg_padding (mode, type) == PAD_UPWARD; 6233 } 6234 6235 /* Return nonzero when an argument must be passed by reference. */ 6236 6237 static bool 6238 mips_pass_by_reference (cumulative_args_t, const function_arg_info &arg) 6239 { 6240 if (mips_abi == ABI_EABI) 6241 { 6242 int size; 6243 6244 /* ??? How should SCmode be handled? */ 6245 if (arg.mode == DImode || arg.mode == DFmode 6246 || arg.mode == DQmode || arg.mode == UDQmode 6247 || arg.mode == DAmode || arg.mode == UDAmode) 6248 return 0; 6249 6250 size = arg.type_size_in_bytes (); 6251 return size == -1 || size > UNITS_PER_WORD; 6252 } 6253 else 6254 { 6255 /* If we have a variable-sized parameter, we have no choice. */ 6256 return targetm.calls.must_pass_in_stack (arg); 6257 } 6258 } 6259 6260 /* Implement TARGET_CALLEE_COPIES. */ 6261 6262 static bool 6263 mips_callee_copies (cumulative_args_t, const function_arg_info &arg) 6264 { 6265 return mips_abi == ABI_EABI && arg.named; 6266 } 6267 6268 /* See whether VALTYPE is a record whose fields should be returned in 6269 floating-point registers. If so, return the number of fields and 6270 list them in FIELDS (which should have two elements). Return 0 6271 otherwise. 6272 6273 For n32 & n64, a structure with one or two fields is returned in 6274 floating-point registers as long as every field has a floating-point 6275 type. */ 6276 6277 static int 6278 mips_fpr_return_fields (const_tree valtype, tree *fields) 6279 { 6280 tree field; 6281 int i; 6282 6283 if (!TARGET_NEWABI) 6284 return 0; 6285 6286 if (TREE_CODE (valtype) != RECORD_TYPE) 6287 return 0; 6288 6289 i = 0; 6290 for (field = TYPE_FIELDS (valtype); field != 0; field = DECL_CHAIN (field)) 6291 { 6292 if (TREE_CODE (field) != FIELD_DECL) 6293 continue; 6294 6295 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (field))) 6296 return 0; 6297 6298 if (i == 2) 6299 return 0; 6300 6301 fields[i++] = field; 6302 } 6303 return i; 6304 } 6305 6306 /* Implement TARGET_RETURN_IN_MSB. For n32 & n64, we should return 6307 a value in the most significant part of $2/$3 if: 6308 6309 - the target is big-endian; 6310 6311 - the value has a structure or union type (we generalize this to 6312 cover aggregates from other languages too); and 6313 6314 - the structure is not returned in floating-point registers. */ 6315 6316 static bool 6317 mips_return_in_msb (const_tree valtype) 6318 { 6319 tree fields[2]; 6320 6321 return (TARGET_NEWABI 6322 && TARGET_BIG_ENDIAN 6323 && AGGREGATE_TYPE_P (valtype) 6324 && mips_fpr_return_fields (valtype, fields) == 0); 6325 } 6326 6327 /* Return true if the function return value MODE will get returned in a 6328 floating-point register. */ 6329 6330 static bool 6331 mips_return_mode_in_fpr_p (machine_mode mode) 6332 { 6333 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT || mode != V2SFmode); 6334 return ((GET_MODE_CLASS (mode) == MODE_FLOAT 6335 || mode == V2SFmode 6336 || GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) 6337 && GET_MODE_UNIT_SIZE (mode) <= UNITS_PER_HWFPVALUE); 6338 } 6339 6340 /* Return the representation of an FPR return register when the 6341 value being returned in FP_RETURN has mode VALUE_MODE and the 6342 return type itself has mode TYPE_MODE. On NewABI targets, 6343 the two modes may be different for structures like: 6344 6345 struct __attribute__((packed)) foo { float f; } 6346 6347 where we return the SFmode value of "f" in FP_RETURN, but where 6348 the structure itself has mode BLKmode. */ 6349 6350 static rtx 6351 mips_return_fpr_single (machine_mode type_mode, 6352 machine_mode value_mode) 6353 { 6354 rtx x; 6355 6356 x = gen_rtx_REG (value_mode, FP_RETURN); 6357 if (type_mode != value_mode) 6358 { 6359 x = gen_rtx_EXPR_LIST (VOIDmode, x, const0_rtx); 6360 x = gen_rtx_PARALLEL (type_mode, gen_rtvec (1, x)); 6361 } 6362 return x; 6363 } 6364 6365 /* Return a composite value in a pair of floating-point registers. 6366 MODE1 and OFFSET1 are the mode and byte offset for the first value, 6367 likewise MODE2 and OFFSET2 for the second. MODE is the mode of the 6368 complete value. 6369 6370 For n32 & n64, $f0 always holds the first value and $f2 the second. 6371 Otherwise the values are packed together as closely as possible. */ 6372 6373 static rtx 6374 mips_return_fpr_pair (machine_mode mode, 6375 machine_mode mode1, HOST_WIDE_INT offset1, 6376 machine_mode mode2, HOST_WIDE_INT offset2) 6377 { 6378 int inc; 6379 6380 inc = (TARGET_NEWABI || mips_abi == ABI_32 ? 2 : MAX_FPRS_PER_FMT); 6381 return gen_rtx_PARALLEL 6382 (mode, 6383 gen_rtvec (2, 6384 gen_rtx_EXPR_LIST (VOIDmode, 6385 gen_rtx_REG (mode1, FP_RETURN), 6386 GEN_INT (offset1)), 6387 gen_rtx_EXPR_LIST (VOIDmode, 6388 gen_rtx_REG (mode2, FP_RETURN + inc), 6389 GEN_INT (offset2)))); 6390 6391 } 6392 6393 /* Implement TARGET_FUNCTION_VALUE and TARGET_LIBCALL_VALUE. 6394 For normal calls, VALTYPE is the return type and MODE is VOIDmode. 6395 For libcalls, VALTYPE is null and MODE is the mode of the return value. */ 6396 6397 static rtx 6398 mips_function_value_1 (const_tree valtype, const_tree fn_decl_or_type, 6399 machine_mode mode) 6400 { 6401 if (valtype) 6402 { 6403 tree fields[2]; 6404 int unsigned_p; 6405 const_tree func; 6406 6407 if (fn_decl_or_type && DECL_P (fn_decl_or_type)) 6408 func = fn_decl_or_type; 6409 else 6410 func = NULL; 6411 6412 mode = TYPE_MODE (valtype); 6413 unsigned_p = TYPE_UNSIGNED (valtype); 6414 6415 /* Since TARGET_PROMOTE_FUNCTION_MODE unconditionally promotes, 6416 return values, promote the mode here too. */ 6417 mode = promote_function_mode (valtype, mode, &unsigned_p, func, 1); 6418 6419 /* Handle structures whose fields are returned in $f0/$f2. */ 6420 switch (mips_fpr_return_fields (valtype, fields)) 6421 { 6422 case 1: 6423 return mips_return_fpr_single (mode, 6424 TYPE_MODE (TREE_TYPE (fields[0]))); 6425 6426 case 2: 6427 return mips_return_fpr_pair (mode, 6428 TYPE_MODE (TREE_TYPE (fields[0])), 6429 int_byte_position (fields[0]), 6430 TYPE_MODE (TREE_TYPE (fields[1])), 6431 int_byte_position (fields[1])); 6432 } 6433 6434 /* If a value is passed in the most significant part of a register, see 6435 whether we have to round the mode up to a whole number of words. */ 6436 if (mips_return_in_msb (valtype)) 6437 { 6438 HOST_WIDE_INT size = int_size_in_bytes (valtype); 6439 if (size % UNITS_PER_WORD != 0) 6440 { 6441 size += UNITS_PER_WORD - size % UNITS_PER_WORD; 6442 mode = int_mode_for_size (size * BITS_PER_UNIT, 0).require (); 6443 } 6444 } 6445 6446 /* For EABI, the class of return register depends entirely on MODE. 6447 For example, "struct { some_type x; }" and "union { some_type x; }" 6448 are returned in the same way as a bare "some_type" would be. 6449 Other ABIs only use FPRs for scalar, complex or vector types. */ 6450 if (mips_abi != ABI_EABI && !FLOAT_TYPE_P (valtype)) 6451 return gen_rtx_REG (mode, GP_RETURN); 6452 } 6453 6454 if (!TARGET_MIPS16) 6455 { 6456 /* Handle long doubles for n32 & n64. */ 6457 if (mode == TFmode) 6458 return mips_return_fpr_pair (mode, 6459 DImode, 0, 6460 DImode, GET_MODE_SIZE (mode) / 2); 6461 6462 if (mips_return_mode_in_fpr_p (mode)) 6463 { 6464 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT) 6465 return mips_return_fpr_pair (mode, 6466 GET_MODE_INNER (mode), 0, 6467 GET_MODE_INNER (mode), 6468 GET_MODE_SIZE (mode) / 2); 6469 else 6470 return gen_rtx_REG (mode, FP_RETURN); 6471 } 6472 } 6473 6474 return gen_rtx_REG (mode, GP_RETURN); 6475 } 6476 6477 /* Implement TARGET_FUNCTION_VALUE. */ 6478 6479 static rtx 6480 mips_function_value (const_tree valtype, const_tree fn_decl_or_type, 6481 bool outgoing ATTRIBUTE_UNUSED) 6482 { 6483 return mips_function_value_1 (valtype, fn_decl_or_type, VOIDmode); 6484 } 6485 6486 /* Implement TARGET_LIBCALL_VALUE. */ 6487 6488 static rtx 6489 mips_libcall_value (machine_mode mode, const_rtx fun ATTRIBUTE_UNUSED) 6490 { 6491 return mips_function_value_1 (NULL_TREE, NULL_TREE, mode); 6492 } 6493 6494 /* Implement TARGET_FUNCTION_VALUE_REGNO_P. 6495 6496 On the MIPS, R2 R3 and F0 F2 are the only register thus used. */ 6497 6498 static bool 6499 mips_function_value_regno_p (const unsigned int regno) 6500 { 6501 /* Most types only require one GPR or one FPR for return values but for 6502 hard-float two FPRs can be used for _Complex types (for all ABIs) 6503 and long doubles (for n64). */ 6504 if (regno == GP_RETURN 6505 || regno == FP_RETURN 6506 || (FP_RETURN != GP_RETURN 6507 && regno == FP_RETURN + 2)) 6508 return true; 6509 6510 /* For o32 FP32, _Complex double will be returned in four 32-bit registers. 6511 This does not apply to o32 FPXX as floating-point function argument and 6512 return registers are described as 64-bit even though floating-point 6513 registers are primarily described as 32-bit internally. 6514 See: mips_get_reg_raw_mode. */ 6515 if ((mips_abi == ABI_32 && TARGET_FLOAT32) 6516 && FP_RETURN != GP_RETURN 6517 && (regno == FP_RETURN + 1 6518 || regno == FP_RETURN + 3)) 6519 return true; 6520 6521 return false; 6522 } 6523 6524 /* Implement TARGET_RETURN_IN_MEMORY. Under the o32 and o64 ABIs, 6525 all BLKmode objects are returned in memory. Under the n32, n64 6526 and embedded ABIs, small structures are returned in a register. 6527 Objects with varying size must still be returned in memory, of 6528 course. */ 6529 6530 static bool 6531 mips_return_in_memory (const_tree type, const_tree fndecl ATTRIBUTE_UNUSED) 6532 { 6533 if (TARGET_OLDABI) 6534 /* Ensure that any floating point vector types are returned via memory 6535 even if they are supported through a vector mode with some ASEs. */ 6536 return (VECTOR_FLOAT_TYPE_P (type) 6537 || TYPE_MODE (type) == BLKmode); 6538 6539 return (!IN_RANGE (int_size_in_bytes (type), 0, 2 * UNITS_PER_WORD)); 6540 } 6541 6542 /* Implement TARGET_SETUP_INCOMING_VARARGS. */ 6543 6544 static void 6545 mips_setup_incoming_varargs (cumulative_args_t cum, 6546 const function_arg_info &arg, 6547 int *pretend_size ATTRIBUTE_UNUSED, int no_rtl) 6548 { 6549 CUMULATIVE_ARGS local_cum; 6550 int gp_saved, fp_saved; 6551 6552 /* The caller has advanced CUM up to, but not beyond, the last named 6553 argument. Advance a local copy of CUM past the last "real" named 6554 argument, to find out how many registers are left over. */ 6555 local_cum = *get_cumulative_args (cum); 6556 mips_function_arg_advance (pack_cumulative_args (&local_cum), arg); 6557 6558 /* Found out how many registers we need to save. */ 6559 gp_saved = MAX_ARGS_IN_REGISTERS - local_cum.num_gprs; 6560 fp_saved = (EABI_FLOAT_VARARGS_P 6561 ? MAX_ARGS_IN_REGISTERS - local_cum.num_fprs 6562 : 0); 6563 6564 if (!no_rtl) 6565 { 6566 if (gp_saved > 0) 6567 { 6568 rtx ptr, mem; 6569 6570 ptr = plus_constant (Pmode, virtual_incoming_args_rtx, 6571 REG_PARM_STACK_SPACE (cfun->decl) 6572 - gp_saved * UNITS_PER_WORD); 6573 mem = gen_frame_mem (BLKmode, ptr); 6574 set_mem_alias_set (mem, get_varargs_alias_set ()); 6575 6576 move_block_from_reg (local_cum.num_gprs + GP_ARG_FIRST, 6577 mem, gp_saved); 6578 } 6579 if (fp_saved > 0) 6580 { 6581 /* We can't use move_block_from_reg, because it will use 6582 the wrong mode. */ 6583 machine_mode mode; 6584 int off, i; 6585 6586 /* Set OFF to the offset from virtual_incoming_args_rtx of 6587 the first float register. The FP save area lies below 6588 the integer one, and is aligned to UNITS_PER_FPVALUE bytes. */ 6589 off = ROUND_DOWN (-gp_saved * UNITS_PER_WORD, UNITS_PER_FPVALUE); 6590 off -= fp_saved * UNITS_PER_FPREG; 6591 6592 mode = TARGET_SINGLE_FLOAT ? SFmode : DFmode; 6593 6594 for (i = local_cum.num_fprs; i < MAX_ARGS_IN_REGISTERS; 6595 i += MAX_FPRS_PER_FMT) 6596 { 6597 rtx ptr, mem; 6598 6599 ptr = plus_constant (Pmode, virtual_incoming_args_rtx, off); 6600 mem = gen_frame_mem (mode, ptr); 6601 set_mem_alias_set (mem, get_varargs_alias_set ()); 6602 mips_emit_move (mem, gen_rtx_REG (mode, FP_ARG_FIRST + i)); 6603 off += UNITS_PER_HWFPVALUE; 6604 } 6605 } 6606 } 6607 if (REG_PARM_STACK_SPACE (cfun->decl) == 0) 6608 cfun->machine->varargs_size = (gp_saved * UNITS_PER_WORD 6609 + fp_saved * UNITS_PER_FPREG); 6610 } 6611 6612 /* Implement TARGET_BUILTIN_VA_LIST. */ 6613 6614 static tree 6615 mips_build_builtin_va_list (void) 6616 { 6617 if (EABI_FLOAT_VARARGS_P) 6618 { 6619 /* We keep 3 pointers, and two offsets. 6620 6621 Two pointers are to the overflow area, which starts at the CFA. 6622 One of these is constant, for addressing into the GPR save area 6623 below it. The other is advanced up the stack through the 6624 overflow region. 6625 6626 The third pointer is to the bottom of the GPR save area. 6627 Since the FPR save area is just below it, we can address 6628 FPR slots off this pointer. 6629 6630 We also keep two one-byte offsets, which are to be subtracted 6631 from the constant pointers to yield addresses in the GPR and 6632 FPR save areas. These are downcounted as float or non-float 6633 arguments are used, and when they get to zero, the argument 6634 must be obtained from the overflow region. */ 6635 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff, f_res, record; 6636 tree array, index; 6637 6638 record = lang_hooks.types.make_type (RECORD_TYPE); 6639 6640 f_ovfl = build_decl (BUILTINS_LOCATION, 6641 FIELD_DECL, get_identifier ("__overflow_argptr"), 6642 ptr_type_node); 6643 f_gtop = build_decl (BUILTINS_LOCATION, 6644 FIELD_DECL, get_identifier ("__gpr_top"), 6645 ptr_type_node); 6646 f_ftop = build_decl (BUILTINS_LOCATION, 6647 FIELD_DECL, get_identifier ("__fpr_top"), 6648 ptr_type_node); 6649 f_goff = build_decl (BUILTINS_LOCATION, 6650 FIELD_DECL, get_identifier ("__gpr_offset"), 6651 unsigned_char_type_node); 6652 f_foff = build_decl (BUILTINS_LOCATION, 6653 FIELD_DECL, get_identifier ("__fpr_offset"), 6654 unsigned_char_type_node); 6655 /* Explicitly pad to the size of a pointer, so that -Wpadded won't 6656 warn on every user file. */ 6657 index = build_int_cst (NULL_TREE, GET_MODE_SIZE (ptr_mode) - 2 - 1); 6658 array = build_array_type (unsigned_char_type_node, 6659 build_index_type (index)); 6660 f_res = build_decl (BUILTINS_LOCATION, 6661 FIELD_DECL, get_identifier ("__reserved"), array); 6662 6663 DECL_FIELD_CONTEXT (f_ovfl) = record; 6664 DECL_FIELD_CONTEXT (f_gtop) = record; 6665 DECL_FIELD_CONTEXT (f_ftop) = record; 6666 DECL_FIELD_CONTEXT (f_goff) = record; 6667 DECL_FIELD_CONTEXT (f_foff) = record; 6668 DECL_FIELD_CONTEXT (f_res) = record; 6669 6670 TYPE_FIELDS (record) = f_ovfl; 6671 DECL_CHAIN (f_ovfl) = f_gtop; 6672 DECL_CHAIN (f_gtop) = f_ftop; 6673 DECL_CHAIN (f_ftop) = f_goff; 6674 DECL_CHAIN (f_goff) = f_foff; 6675 DECL_CHAIN (f_foff) = f_res; 6676 6677 layout_type (record); 6678 return record; 6679 } 6680 else 6681 /* Otherwise, we use 'void *'. */ 6682 return ptr_type_node; 6683 } 6684 6685 /* Implement TARGET_EXPAND_BUILTIN_VA_START. */ 6686 6687 static void 6688 mips_va_start (tree valist, rtx nextarg) 6689 { 6690 if (EABI_FLOAT_VARARGS_P) 6691 { 6692 const CUMULATIVE_ARGS *cum; 6693 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff; 6694 tree ovfl, gtop, ftop, goff, foff; 6695 tree t; 6696 int gpr_save_area_size; 6697 int fpr_save_area_size; 6698 int fpr_offset; 6699 6700 cum = &crtl->args.info; 6701 gpr_save_area_size 6702 = (MAX_ARGS_IN_REGISTERS - cum->num_gprs) * UNITS_PER_WORD; 6703 fpr_save_area_size 6704 = (MAX_ARGS_IN_REGISTERS - cum->num_fprs) * UNITS_PER_FPREG; 6705 6706 f_ovfl = TYPE_FIELDS (va_list_type_node); 6707 f_gtop = DECL_CHAIN (f_ovfl); 6708 f_ftop = DECL_CHAIN (f_gtop); 6709 f_goff = DECL_CHAIN (f_ftop); 6710 f_foff = DECL_CHAIN (f_goff); 6711 6712 ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl, 6713 NULL_TREE); 6714 gtop = build3 (COMPONENT_REF, TREE_TYPE (f_gtop), valist, f_gtop, 6715 NULL_TREE); 6716 ftop = build3 (COMPONENT_REF, TREE_TYPE (f_ftop), valist, f_ftop, 6717 NULL_TREE); 6718 goff = build3 (COMPONENT_REF, TREE_TYPE (f_goff), valist, f_goff, 6719 NULL_TREE); 6720 foff = build3 (COMPONENT_REF, TREE_TYPE (f_foff), valist, f_foff, 6721 NULL_TREE); 6722 6723 /* Emit code to initialize OVFL, which points to the next varargs 6724 stack argument. CUM->STACK_WORDS gives the number of stack 6725 words used by named arguments. */ 6726 t = make_tree (TREE_TYPE (ovfl), virtual_incoming_args_rtx); 6727 if (cum->stack_words > 0) 6728 t = fold_build_pointer_plus_hwi (t, cum->stack_words * UNITS_PER_WORD); 6729 t = build2 (MODIFY_EXPR, TREE_TYPE (ovfl), ovfl, t); 6730 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); 6731 6732 /* Emit code to initialize GTOP, the top of the GPR save area. */ 6733 t = make_tree (TREE_TYPE (gtop), virtual_incoming_args_rtx); 6734 t = build2 (MODIFY_EXPR, TREE_TYPE (gtop), gtop, t); 6735 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); 6736 6737 /* Emit code to initialize FTOP, the top of the FPR save area. 6738 This address is gpr_save_area_bytes below GTOP, rounded 6739 down to the next fp-aligned boundary. */ 6740 t = make_tree (TREE_TYPE (ftop), virtual_incoming_args_rtx); 6741 fpr_offset = gpr_save_area_size + UNITS_PER_FPVALUE - 1; 6742 fpr_offset &= -UNITS_PER_FPVALUE; 6743 if (fpr_offset) 6744 t = fold_build_pointer_plus_hwi (t, -fpr_offset); 6745 t = build2 (MODIFY_EXPR, TREE_TYPE (ftop), ftop, t); 6746 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); 6747 6748 /* Emit code to initialize GOFF, the offset from GTOP of the 6749 next GPR argument. */ 6750 t = build2 (MODIFY_EXPR, TREE_TYPE (goff), goff, 6751 build_int_cst (TREE_TYPE (goff), gpr_save_area_size)); 6752 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); 6753 6754 /* Likewise emit code to initialize FOFF, the offset from FTOP 6755 of the next FPR argument. */ 6756 t = build2 (MODIFY_EXPR, TREE_TYPE (foff), foff, 6757 build_int_cst (TREE_TYPE (foff), fpr_save_area_size)); 6758 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); 6759 } 6760 else 6761 { 6762 nextarg = plus_constant (Pmode, nextarg, -cfun->machine->varargs_size); 6763 std_expand_builtin_va_start (valist, nextarg); 6764 } 6765 } 6766 6767 /* Like std_gimplify_va_arg_expr, but apply alignment to zero-sized 6768 types as well. */ 6769 6770 static tree 6771 mips_std_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, 6772 gimple_seq *post_p) 6773 { 6774 tree addr, t, type_size, rounded_size, valist_tmp; 6775 unsigned HOST_WIDE_INT align, boundary; 6776 bool indirect; 6777 6778 indirect = pass_va_arg_by_reference (type); 6779 if (indirect) 6780 type = build_pointer_type (type); 6781 6782 align = PARM_BOUNDARY / BITS_PER_UNIT; 6783 boundary = targetm.calls.function_arg_boundary (TYPE_MODE (type), type); 6784 6785 /* When we align parameter on stack for caller, if the parameter 6786 alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be 6787 aligned at MAX_SUPPORTED_STACK_ALIGNMENT. We will match callee 6788 here with caller. */ 6789 if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT) 6790 boundary = MAX_SUPPORTED_STACK_ALIGNMENT; 6791 6792 boundary /= BITS_PER_UNIT; 6793 6794 /* Hoist the valist value into a temporary for the moment. */ 6795 valist_tmp = get_initialized_tmp_var (valist, pre_p, NULL); 6796 6797 /* va_list pointer is aligned to PARM_BOUNDARY. If argument actually 6798 requires greater alignment, we must perform dynamic alignment. */ 6799 if (boundary > align) 6800 { 6801 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp, 6802 fold_build_pointer_plus_hwi (valist_tmp, boundary - 1)); 6803 gimplify_and_add (t, pre_p); 6804 6805 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp, 6806 fold_build2 (BIT_AND_EXPR, TREE_TYPE (valist), 6807 valist_tmp, 6808 build_int_cst (TREE_TYPE (valist), -boundary))); 6809 gimplify_and_add (t, pre_p); 6810 } 6811 else 6812 boundary = align; 6813 6814 /* If the actual alignment is less than the alignment of the type, 6815 adjust the type accordingly so that we don't assume strict alignment 6816 when dereferencing the pointer. */ 6817 boundary *= BITS_PER_UNIT; 6818 if (boundary < TYPE_ALIGN (type)) 6819 { 6820 type = build_variant_type_copy (type); 6821 SET_TYPE_ALIGN (type, boundary); 6822 } 6823 6824 /* Compute the rounded size of the type. */ 6825 type_size = size_in_bytes (type); 6826 rounded_size = round_up (type_size, align); 6827 6828 /* Reduce rounded_size so it's sharable with the postqueue. */ 6829 gimplify_expr (&rounded_size, pre_p, post_p, is_gimple_val, fb_rvalue); 6830 6831 /* Get AP. */ 6832 addr = valist_tmp; 6833 if (PAD_VARARGS_DOWN && !integer_zerop (rounded_size)) 6834 { 6835 /* Small args are padded downward. */ 6836 t = fold_build2_loc (input_location, GT_EXPR, sizetype, 6837 rounded_size, size_int (align)); 6838 t = fold_build3 (COND_EXPR, sizetype, t, size_zero_node, 6839 size_binop (MINUS_EXPR, rounded_size, type_size)); 6840 addr = fold_build_pointer_plus (addr, t); 6841 } 6842 6843 /* Compute new value for AP. */ 6844 t = fold_build_pointer_plus (valist_tmp, rounded_size); 6845 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist, t); 6846 gimplify_and_add (t, pre_p); 6847 6848 addr = fold_convert (build_pointer_type (type), addr); 6849 6850 if (indirect) 6851 addr = build_va_arg_indirect_ref (addr); 6852 6853 return build_va_arg_indirect_ref (addr); 6854 } 6855 6856 /* Implement TARGET_GIMPLIFY_VA_ARG_EXPR. */ 6857 6858 static tree 6859 mips_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p, 6860 gimple_seq *post_p) 6861 { 6862 tree addr; 6863 bool indirect_p; 6864 6865 indirect_p = pass_va_arg_by_reference (type); 6866 if (indirect_p) 6867 type = build_pointer_type (type); 6868 6869 if (!EABI_FLOAT_VARARGS_P) 6870 addr = mips_std_gimplify_va_arg_expr (valist, type, pre_p, post_p); 6871 else 6872 { 6873 tree f_ovfl, f_gtop, f_ftop, f_goff, f_foff; 6874 tree ovfl, top, off, align; 6875 HOST_WIDE_INT size, rsize, osize; 6876 tree t, u; 6877 6878 f_ovfl = TYPE_FIELDS (va_list_type_node); 6879 f_gtop = DECL_CHAIN (f_ovfl); 6880 f_ftop = DECL_CHAIN (f_gtop); 6881 f_goff = DECL_CHAIN (f_ftop); 6882 f_foff = DECL_CHAIN (f_goff); 6883 6884 /* Let: 6885 6886 TOP be the top of the GPR or FPR save area; 6887 OFF be the offset from TOP of the next register; 6888 ADDR_RTX be the address of the argument; 6889 SIZE be the number of bytes in the argument type; 6890 RSIZE be the number of bytes used to store the argument 6891 when it's in the register save area; and 6892 OSIZE be the number of bytes used to store it when it's 6893 in the stack overflow area. 6894 6895 The code we want is: 6896 6897 1: off &= -rsize; // round down 6898 2: if (off != 0) 6899 3: { 6900 4: addr_rtx = top - off + (BYTES_BIG_ENDIAN ? RSIZE - SIZE : 0); 6901 5: off -= rsize; 6902 6: } 6903 7: else 6904 8: { 6905 9: ovfl = ((intptr_t) ovfl + osize - 1) & -osize; 6906 10: addr_rtx = ovfl + (BYTES_BIG_ENDIAN ? OSIZE - SIZE : 0); 6907 11: ovfl += osize; 6908 14: } 6909 6910 [1] and [9] can sometimes be optimized away. */ 6911 6912 ovfl = build3 (COMPONENT_REF, TREE_TYPE (f_ovfl), valist, f_ovfl, 6913 NULL_TREE); 6914 size = int_size_in_bytes (type); 6915 6916 if (GET_MODE_CLASS (TYPE_MODE (type)) == MODE_FLOAT 6917 && GET_MODE_SIZE (TYPE_MODE (type)) <= UNITS_PER_FPVALUE) 6918 { 6919 top = build3 (COMPONENT_REF, TREE_TYPE (f_ftop), 6920 unshare_expr (valist), f_ftop, NULL_TREE); 6921 off = build3 (COMPONENT_REF, TREE_TYPE (f_foff), 6922 unshare_expr (valist), f_foff, NULL_TREE); 6923 6924 /* When va_start saves FPR arguments to the stack, each slot 6925 takes up UNITS_PER_HWFPVALUE bytes, regardless of the 6926 argument's precision. */ 6927 rsize = UNITS_PER_HWFPVALUE; 6928 6929 /* Overflow arguments are padded to UNITS_PER_WORD bytes 6930 (= PARM_BOUNDARY bits). This can be different from RSIZE 6931 in two cases: 6932 6933 (1) On 32-bit targets when TYPE is a structure such as: 6934 6935 struct s { float f; }; 6936 6937 Such structures are passed in paired FPRs, so RSIZE 6938 will be 8 bytes. However, the structure only takes 6939 up 4 bytes of memory, so OSIZE will only be 4. 6940 6941 (2) In combinations such as -mgp64 -msingle-float 6942 -fshort-double. Doubles passed in registers will then take 6943 up 4 (UNITS_PER_HWFPVALUE) bytes, but those passed on the 6944 stack take up UNITS_PER_WORD bytes. */ 6945 osize = MAX (GET_MODE_SIZE (TYPE_MODE (type)), UNITS_PER_WORD); 6946 } 6947 else 6948 { 6949 top = build3 (COMPONENT_REF, TREE_TYPE (f_gtop), 6950 unshare_expr (valist), f_gtop, NULL_TREE); 6951 off = build3 (COMPONENT_REF, TREE_TYPE (f_goff), 6952 unshare_expr (valist), f_goff, NULL_TREE); 6953 rsize = ROUND_UP (size, UNITS_PER_WORD); 6954 if (rsize > UNITS_PER_WORD) 6955 { 6956 /* [1] Emit code for: off &= -rsize. */ 6957 t = build2 (BIT_AND_EXPR, TREE_TYPE (off), unshare_expr (off), 6958 build_int_cst (TREE_TYPE (off), -rsize)); 6959 gimplify_assign (unshare_expr (off), t, pre_p); 6960 } 6961 osize = rsize; 6962 } 6963 6964 /* [2] Emit code to branch if off == 0. */ 6965 t = build2 (NE_EXPR, boolean_type_node, unshare_expr (off), 6966 build_int_cst (TREE_TYPE (off), 0)); 6967 addr = build3 (COND_EXPR, ptr_type_node, t, NULL_TREE, NULL_TREE); 6968 6969 /* [5] Emit code for: off -= rsize. We do this as a form of 6970 post-decrement not available to C. */ 6971 t = fold_convert (TREE_TYPE (off), build_int_cst (NULL_TREE, rsize)); 6972 t = build2 (POSTDECREMENT_EXPR, TREE_TYPE (off), off, t); 6973 6974 /* [4] Emit code for: 6975 addr_rtx = top - off + (BYTES_BIG_ENDIAN ? RSIZE - SIZE : 0). */ 6976 t = fold_convert (sizetype, t); 6977 t = fold_build1 (NEGATE_EXPR, sizetype, t); 6978 t = fold_build_pointer_plus (top, t); 6979 if (BYTES_BIG_ENDIAN && rsize > size) 6980 t = fold_build_pointer_plus_hwi (t, rsize - size); 6981 COND_EXPR_THEN (addr) = t; 6982 6983 if (osize > UNITS_PER_WORD) 6984 { 6985 /* [9] Emit: ovfl = ((intptr_t) ovfl + osize - 1) & -osize. */ 6986 t = fold_build_pointer_plus_hwi (unshare_expr (ovfl), osize - 1); 6987 u = build_int_cst (TREE_TYPE (t), -osize); 6988 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t, u); 6989 align = build2 (MODIFY_EXPR, TREE_TYPE (ovfl), 6990 unshare_expr (ovfl), t); 6991 } 6992 else 6993 align = NULL; 6994 6995 /* [10, 11] Emit code for: 6996 addr_rtx = ovfl + (BYTES_BIG_ENDIAN ? OSIZE - SIZE : 0) 6997 ovfl += osize. */ 6998 u = fold_convert (TREE_TYPE (ovfl), build_int_cst (NULL_TREE, osize)); 6999 t = build2 (POSTINCREMENT_EXPR, TREE_TYPE (ovfl), ovfl, u); 7000 if (BYTES_BIG_ENDIAN && osize > size) 7001 t = fold_build_pointer_plus_hwi (t, osize - size); 7002 7003 /* String [9] and [10, 11] together. */ 7004 if (align) 7005 t = build2 (COMPOUND_EXPR, TREE_TYPE (t), align, t); 7006 COND_EXPR_ELSE (addr) = t; 7007 7008 addr = fold_convert (build_pointer_type (type), addr); 7009 addr = build_va_arg_indirect_ref (addr); 7010 } 7011 7012 if (indirect_p) 7013 addr = build_va_arg_indirect_ref (addr); 7014 7015 return addr; 7016 } 7017 7018 /* Declare a unique, locally-binding function called NAME, then start 7019 its definition. */ 7020 7021 static void 7022 mips_start_unique_function (const char *name) 7023 { 7024 tree decl; 7025 7026 decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, 7027 get_identifier (name), 7028 build_function_type_list (void_type_node, NULL_TREE)); 7029 DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL, 7030 NULL_TREE, void_type_node); 7031 TREE_PUBLIC (decl) = 1; 7032 TREE_STATIC (decl) = 1; 7033 7034 cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl)); 7035 7036 targetm.asm_out.unique_section (decl, 0); 7037 switch_to_section (get_named_section (decl, NULL, 0)); 7038 7039 targetm.asm_out.globalize_label (asm_out_file, name); 7040 fputs ("\t.hidden\t", asm_out_file); 7041 assemble_name (asm_out_file, name); 7042 putc ('\n', asm_out_file); 7043 } 7044 7045 /* Start a definition of function NAME. MIPS16_P indicates whether the 7046 function contains MIPS16 code. */ 7047 7048 static void 7049 mips_start_function_definition (const char *name, bool mips16_p) 7050 { 7051 if (mips16_p) 7052 fprintf (asm_out_file, "\t.set\tmips16\n"); 7053 else 7054 fprintf (asm_out_file, "\t.set\tnomips16\n"); 7055 7056 if (TARGET_MICROMIPS) 7057 fprintf (asm_out_file, "\t.set\tmicromips\n"); 7058 #ifdef HAVE_GAS_MICROMIPS 7059 else 7060 fprintf (asm_out_file, "\t.set\tnomicromips\n"); 7061 #endif 7062 7063 if (!flag_inhibit_size_directive) 7064 { 7065 fputs ("\t.ent\t", asm_out_file); 7066 assemble_name (asm_out_file, name); 7067 fputs ("\n", asm_out_file); 7068 } 7069 7070 ASM_OUTPUT_TYPE_DIRECTIVE (asm_out_file, name, "function"); 7071 7072 /* Start the definition proper. */ 7073 assemble_name (asm_out_file, name); 7074 fputs (":\n", asm_out_file); 7075 } 7076 7077 /* End a function definition started by mips_start_function_definition. */ 7078 7079 static void 7080 mips_end_function_definition (const char *name) 7081 { 7082 if (!flag_inhibit_size_directive) 7083 { 7084 fputs ("\t.end\t", asm_out_file); 7085 assemble_name (asm_out_file, name); 7086 fputs ("\n", asm_out_file); 7087 } 7088 } 7089 7090 /* If *STUB_PTR points to a stub, output a comdat-style definition for it, 7091 then free *STUB_PTR. */ 7092 7093 static void 7094 mips_finish_stub (mips_one_only_stub **stub_ptr) 7095 { 7096 mips_one_only_stub *stub = *stub_ptr; 7097 if (!stub) 7098 return; 7099 7100 const char *name = stub->get_name (); 7101 mips_start_unique_function (name); 7102 mips_start_function_definition (name, false); 7103 stub->output_body (); 7104 mips_end_function_definition (name); 7105 delete stub; 7106 *stub_ptr = 0; 7107 } 7108 7109 /* Return true if calls to X can use R_MIPS_CALL* relocations. */ 7110 7111 static bool 7112 mips_ok_for_lazy_binding_p (rtx x) 7113 { 7114 return (TARGET_USE_GOT 7115 && GET_CODE (x) == SYMBOL_REF 7116 && !SYMBOL_REF_BIND_NOW_P (x) 7117 && !mips_symbol_binds_local_p (x)); 7118 } 7119 7120 /* Load function address ADDR into register DEST. TYPE is as for 7121 mips_expand_call. Return true if we used an explicit lazy-binding 7122 sequence. */ 7123 7124 static bool 7125 mips_load_call_address (enum mips_call_type type, rtx dest, rtx addr) 7126 { 7127 /* If we're generating PIC, and this call is to a global function, 7128 try to allow its address to be resolved lazily. This isn't 7129 possible for sibcalls when $gp is call-saved because the value 7130 of $gp on entry to the stub would be our caller's gp, not ours. */ 7131 if (TARGET_EXPLICIT_RELOCS 7132 && !(type == MIPS_CALL_SIBCALL && TARGET_CALL_SAVED_GP) 7133 && mips_ok_for_lazy_binding_p (addr)) 7134 { 7135 addr = mips_got_load (dest, addr, SYMBOL_GOTOFF_CALL); 7136 emit_insn (gen_rtx_SET (dest, addr)); 7137 return true; 7138 } 7139 else 7140 { 7141 mips_emit_move (dest, addr); 7142 return false; 7143 } 7144 } 7145 7146 /* Each locally-defined hard-float MIPS16 function has a local symbol 7147 associated with it. This hash table maps the function symbol (FUNC) 7148 to the local symbol (LOCAL). */ 7149 static GTY (()) hash_map<nofree_string_hash, rtx> *mips16_local_aliases; 7150 7151 /* FUNC is the symbol for a locally-defined hard-float MIPS16 function. 7152 Return a local alias for it, creating a new one if necessary. */ 7153 7154 static rtx 7155 mips16_local_alias (rtx func) 7156 { 7157 /* Create the hash table if this is the first call. */ 7158 if (mips16_local_aliases == NULL) 7159 mips16_local_aliases = hash_map<nofree_string_hash, rtx>::create_ggc (37); 7160 7161 /* Look up the function symbol, creating a new entry if need be. */ 7162 bool existed; 7163 const char *func_name = XSTR (func, 0); 7164 rtx *slot = &mips16_local_aliases->get_or_insert (func_name, &existed); 7165 gcc_assert (slot != NULL); 7166 7167 if (!existed) 7168 { 7169 rtx local; 7170 7171 /* Create a new SYMBOL_REF for the local symbol. The choice of 7172 __fn_local_* is based on the __fn_stub_* names that we've 7173 traditionally used for the non-MIPS16 stub. */ 7174 func_name = targetm.strip_name_encoding (XSTR (func, 0)); 7175 const char *local_name = ACONCAT (("__fn_local_", func_name, NULL)); 7176 local = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (local_name)); 7177 SYMBOL_REF_FLAGS (local) = SYMBOL_REF_FLAGS (func) | SYMBOL_FLAG_LOCAL; 7178 7179 /* Create a new structure to represent the mapping. */ 7180 *slot = local; 7181 } 7182 return *slot; 7183 } 7184 7185 /* A chained list of functions for which mips16_build_call_stub has already 7186 generated a stub. NAME is the name of the function and FP_RET_P is true 7187 if the function returns a value in floating-point registers. */ 7188 struct mips16_stub { 7189 struct mips16_stub *next; 7190 char *name; 7191 bool fp_ret_p; 7192 }; 7193 static struct mips16_stub *mips16_stubs; 7194 7195 /* Return the two-character string that identifies floating-point 7196 return mode MODE in the name of a MIPS16 function stub. */ 7197 7198 static const char * 7199 mips16_call_stub_mode_suffix (machine_mode mode) 7200 { 7201 if (mode == SFmode) 7202 return "sf"; 7203 else if (mode == DFmode) 7204 return "df"; 7205 else if (mode == SCmode) 7206 return "sc"; 7207 else if (mode == DCmode) 7208 return "dc"; 7209 else if (mode == V2SFmode) 7210 { 7211 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT); 7212 return "df"; 7213 } 7214 else 7215 gcc_unreachable (); 7216 } 7217 7218 /* Write instructions to move a 32-bit value between general register 7219 GPREG and floating-point register FPREG. DIRECTION is 't' to move 7220 from GPREG to FPREG and 'f' to move in the opposite direction. */ 7221 7222 static void 7223 mips_output_32bit_xfer (char direction, unsigned int gpreg, unsigned int fpreg) 7224 { 7225 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction, 7226 reg_names[gpreg], reg_names[fpreg]); 7227 } 7228 7229 /* Likewise for 64-bit values. */ 7230 7231 static void 7232 mips_output_64bit_xfer (char direction, unsigned int gpreg, unsigned int fpreg) 7233 { 7234 if (TARGET_64BIT) 7235 fprintf (asm_out_file, "\tdm%cc1\t%s,%s\n", direction, 7236 reg_names[gpreg], reg_names[fpreg]); 7237 else if (ISA_HAS_MXHC1) 7238 { 7239 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction, 7240 reg_names[gpreg + TARGET_BIG_ENDIAN], reg_names[fpreg]); 7241 fprintf (asm_out_file, "\tm%chc1\t%s,%s\n", direction, 7242 reg_names[gpreg + TARGET_LITTLE_ENDIAN], reg_names[fpreg]); 7243 } 7244 else if (TARGET_FLOATXX && direction == 't') 7245 { 7246 /* Use the argument save area to move via memory. */ 7247 fprintf (asm_out_file, "\tsw\t%s,0($sp)\n", reg_names[gpreg]); 7248 fprintf (asm_out_file, "\tsw\t%s,4($sp)\n", reg_names[gpreg + 1]); 7249 fprintf (asm_out_file, "\tldc1\t%s,0($sp)\n", reg_names[fpreg]); 7250 } 7251 else if (TARGET_FLOATXX && direction == 'f') 7252 { 7253 /* Use the argument save area to move via memory. */ 7254 fprintf (asm_out_file, "\tsdc1\t%s,0($sp)\n", reg_names[fpreg]); 7255 fprintf (asm_out_file, "\tlw\t%s,0($sp)\n", reg_names[gpreg]); 7256 fprintf (asm_out_file, "\tlw\t%s,4($sp)\n", reg_names[gpreg + 1]); 7257 } 7258 else 7259 { 7260 /* Move the least-significant word. */ 7261 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction, 7262 reg_names[gpreg + TARGET_BIG_ENDIAN], reg_names[fpreg]); 7263 /* ...then the most significant word. */ 7264 fprintf (asm_out_file, "\tm%cc1\t%s,%s\n", direction, 7265 reg_names[gpreg + TARGET_LITTLE_ENDIAN], reg_names[fpreg + 1]); 7266 } 7267 } 7268 7269 /* Write out code to move floating-point arguments into or out of 7270 general registers. FP_CODE is the code describing which arguments 7271 are present (see the comment above the definition of CUMULATIVE_ARGS 7272 in mips.h). DIRECTION is as for mips_output_32bit_xfer. */ 7273 7274 static void 7275 mips_output_args_xfer (int fp_code, char direction) 7276 { 7277 unsigned int gparg, fparg, f; 7278 CUMULATIVE_ARGS cum; 7279 7280 /* This code only works for o32 and o64. */ 7281 gcc_assert (TARGET_OLDABI); 7282 7283 mips_init_cumulative_args (&cum, NULL); 7284 7285 for (f = (unsigned int) fp_code; f != 0; f >>= 2) 7286 { 7287 machine_mode mode; 7288 struct mips_arg_info info; 7289 7290 if ((f & 3) == 1) 7291 mode = SFmode; 7292 else if ((f & 3) == 2) 7293 mode = DFmode; 7294 else 7295 gcc_unreachable (); 7296 7297 mips_get_arg_info (&info, &cum, mode, NULL, true); 7298 gparg = mips_arg_regno (&info, false); 7299 fparg = mips_arg_regno (&info, true); 7300 7301 if (mode == SFmode) 7302 mips_output_32bit_xfer (direction, gparg, fparg); 7303 else 7304 mips_output_64bit_xfer (direction, gparg, fparg); 7305 7306 function_arg_info arg (mode, /*named=*/true); 7307 mips_function_arg_advance (pack_cumulative_args (&cum), arg); 7308 } 7309 } 7310 7311 /* Write a MIPS16 stub for the current function. This stub is used 7312 for functions which take arguments in the floating-point registers. 7313 It is normal-mode code that moves the floating-point arguments 7314 into the general registers and then jumps to the MIPS16 code. */ 7315 7316 static void 7317 mips16_build_function_stub (void) 7318 { 7319 const char *fnname, *alias_name, *separator; 7320 char *secname, *stubname; 7321 tree stubdecl; 7322 unsigned int f; 7323 rtx symbol, alias; 7324 7325 /* Create the name of the stub, and its unique section. */ 7326 symbol = XEXP (DECL_RTL (current_function_decl), 0); 7327 alias = mips16_local_alias (symbol); 7328 7329 fnname = targetm.strip_name_encoding (XSTR (symbol, 0)); 7330 alias_name = targetm.strip_name_encoding (XSTR (alias, 0)); 7331 secname = ACONCAT ((".mips16.fn.", fnname, NULL)); 7332 stubname = ACONCAT (("__fn_stub_", fnname, NULL)); 7333 7334 /* Build a decl for the stub. */ 7335 stubdecl = build_decl (BUILTINS_LOCATION, 7336 FUNCTION_DECL, get_identifier (stubname), 7337 build_function_type_list (void_type_node, NULL_TREE)); 7338 set_decl_section_name (stubdecl, secname); 7339 DECL_RESULT (stubdecl) = build_decl (BUILTINS_LOCATION, 7340 RESULT_DECL, NULL_TREE, void_type_node); 7341 7342 /* Output a comment. */ 7343 fprintf (asm_out_file, "\t# Stub function for %s (", 7344 current_function_name ()); 7345 separator = ""; 7346 for (f = (unsigned int) crtl->args.info.fp_code; f != 0; f >>= 2) 7347 { 7348 fprintf (asm_out_file, "%s%s", separator, 7349 (f & 3) == 1 ? "float" : "double"); 7350 separator = ", "; 7351 } 7352 fprintf (asm_out_file, ")\n"); 7353 7354 /* Start the function definition. */ 7355 assemble_start_function (stubdecl, stubname); 7356 mips_start_function_definition (stubname, false); 7357 7358 /* If generating pic2 code, either set up the global pointer or 7359 switch to pic0. */ 7360 if (TARGET_ABICALLS_PIC2) 7361 { 7362 if (TARGET_ABSOLUTE_ABICALLS) 7363 fprintf (asm_out_file, "\t.option\tpic0\n"); 7364 else 7365 { 7366 output_asm_insn ("%(.cpload\t%^%)", NULL); 7367 /* Emit an R_MIPS_NONE relocation to tell the linker what the 7368 target function is. Use a local GOT access when loading the 7369 symbol, to cut down on the number of unnecessary GOT entries 7370 for stubs that aren't needed. */ 7371 output_asm_insn (".reloc\t0,R_MIPS_NONE,%0", &symbol); 7372 symbol = alias; 7373 } 7374 } 7375 7376 /* Load the address of the MIPS16 function into $25. Do this first so 7377 that targets with coprocessor interlocks can use an MFC1 to fill the 7378 delay slot. */ 7379 output_asm_insn ("la\t%^,%0", &symbol); 7380 7381 /* Move the arguments from floating-point registers to general registers. */ 7382 mips_output_args_xfer (crtl->args.info.fp_code, 'f'); 7383 7384 /* Jump to the MIPS16 function. */ 7385 output_asm_insn ("jr\t%^", NULL); 7386 7387 if (TARGET_ABICALLS_PIC2 && TARGET_ABSOLUTE_ABICALLS) 7388 fprintf (asm_out_file, "\t.option\tpic2\n"); 7389 7390 mips_end_function_definition (stubname); 7391 7392 /* If the linker needs to create a dynamic symbol for the target 7393 function, it will associate the symbol with the stub (which, 7394 unlike the target function, follows the proper calling conventions). 7395 It is therefore useful to have a local alias for the target function, 7396 so that it can still be identified as MIPS16 code. As an optimization, 7397 this symbol can also be used for indirect MIPS16 references from 7398 within this file. */ 7399 ASM_OUTPUT_DEF (asm_out_file, alias_name, fnname); 7400 7401 switch_to_section (function_section (current_function_decl)); 7402 } 7403 7404 /* The current function is a MIPS16 function that returns a value in an FPR. 7405 Copy the return value from its soft-float to its hard-float location. 7406 libgcc2 has special non-MIPS16 helper functions for each case. */ 7407 7408 static void 7409 mips16_copy_fpr_return_value (void) 7410 { 7411 rtx fn, insn, retval; 7412 tree return_type; 7413 machine_mode return_mode; 7414 const char *name; 7415 7416 return_type = DECL_RESULT (current_function_decl); 7417 return_mode = DECL_MODE (return_type); 7418 7419 name = ACONCAT (("__mips16_ret_", 7420 mips16_call_stub_mode_suffix (return_mode), 7421 NULL)); 7422 fn = mips16_stub_function (name); 7423 7424 /* The function takes arguments in $2 (and possibly $3), so calls 7425 to it cannot be lazily bound. */ 7426 SYMBOL_REF_FLAGS (fn) |= SYMBOL_FLAG_BIND_NOW; 7427 7428 /* Model the call as something that takes the GPR return value as 7429 argument and returns an "updated" value. */ 7430 retval = gen_rtx_REG (return_mode, GP_RETURN); 7431 insn = mips_expand_call (MIPS_CALL_EPILOGUE, retval, fn, 7432 const0_rtx, NULL_RTX, false); 7433 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), retval); 7434 } 7435 7436 /* Consider building a stub for a MIPS16 call to function *FN_PTR. 7437 RETVAL is the location of the return value, or null if this is 7438 a "call" rather than a "call_value". ARGS_SIZE is the size of the 7439 arguments and FP_CODE is the code built by mips_function_arg; 7440 see the comment before the fp_code field in CUMULATIVE_ARGS for details. 7441 7442 There are three alternatives: 7443 7444 - If a stub was needed, emit the call and return the call insn itself. 7445 7446 - If we can avoid using a stub by redirecting the call, set *FN_PTR 7447 to the new target and return null. 7448 7449 - If *FN_PTR doesn't need a stub, return null and leave *FN_PTR 7450 unmodified. 7451 7452 A stub is needed for calls to functions that, in normal mode, 7453 receive arguments in FPRs or return values in FPRs. The stub 7454 copies the arguments from their soft-float positions to their 7455 hard-float positions, calls the real function, then copies the 7456 return value from its hard-float position to its soft-float 7457 position. 7458 7459 We can emit a JAL to *FN_PTR even when *FN_PTR might need a stub. 7460 If *FN_PTR turns out to be to a non-MIPS16 function, the linker 7461 automatically redirects the JAL to the stub, otherwise the JAL 7462 continues to call FN directly. */ 7463 7464 static rtx_insn * 7465 mips16_build_call_stub (rtx retval, rtx *fn_ptr, rtx args_size, int fp_code) 7466 { 7467 const char *fnname; 7468 bool fp_ret_p; 7469 struct mips16_stub *l; 7470 rtx_insn *insn; 7471 rtx pattern, fn; 7472 7473 /* We don't need to do anything if we aren't in MIPS16 mode, or if 7474 we were invoked with the -msoft-float option. */ 7475 if (!TARGET_MIPS16 || TARGET_SOFT_FLOAT_ABI) 7476 return NULL; 7477 7478 /* Figure out whether the value might come back in a floating-point 7479 register. */ 7480 fp_ret_p = retval && mips_return_mode_in_fpr_p (GET_MODE (retval)); 7481 7482 /* We don't need to do anything if there were no floating-point 7483 arguments and the value will not be returned in a floating-point 7484 register. */ 7485 if (fp_code == 0 && !fp_ret_p) 7486 return NULL; 7487 7488 /* We don't need to do anything if this is a call to a special 7489 MIPS16 support function. */ 7490 fn = *fn_ptr; 7491 if (mips16_stub_function_p (fn)) 7492 return NULL; 7493 7494 /* If we're calling a locally-defined MIPS16 function, we know that 7495 it will return values in both the "soft-float" and "hard-float" 7496 registers. There is no need to use a stub to move the latter 7497 to the former. */ 7498 if (fp_code == 0 && mips16_local_function_p (fn)) 7499 return NULL; 7500 7501 /* This code will only work for o32 and o64 abis. The other ABI's 7502 require more sophisticated support. */ 7503 gcc_assert (TARGET_OLDABI); 7504 7505 /* If we're calling via a function pointer, use one of the magic 7506 libgcc.a stubs provided for each (FP_CODE, FP_RET_P) combination. 7507 Each stub expects the function address to arrive in register $2. */ 7508 if (GET_CODE (fn) != SYMBOL_REF 7509 || !call_insn_operand (fn, VOIDmode)) 7510 { 7511 char buf[32]; 7512 rtx stub_fn, addr; 7513 rtx_insn *insn; 7514 bool lazy_p; 7515 7516 /* If this is a locally-defined and locally-binding function, 7517 avoid the stub by calling the local alias directly. */ 7518 if (mips16_local_function_p (fn)) 7519 { 7520 *fn_ptr = mips16_local_alias (fn); 7521 return NULL; 7522 } 7523 7524 /* Create a SYMBOL_REF for the libgcc.a function. */ 7525 if (fp_ret_p) 7526 sprintf (buf, "__mips16_call_stub_%s_%d", 7527 mips16_call_stub_mode_suffix (GET_MODE (retval)), 7528 fp_code); 7529 else 7530 sprintf (buf, "__mips16_call_stub_%d", fp_code); 7531 stub_fn = mips16_stub_function (buf); 7532 7533 /* The function uses $2 as an argument, so calls to it 7534 cannot be lazily bound. */ 7535 SYMBOL_REF_FLAGS (stub_fn) |= SYMBOL_FLAG_BIND_NOW; 7536 7537 /* Load the target function into $2. */ 7538 addr = gen_rtx_REG (Pmode, GP_REG_FIRST + 2); 7539 lazy_p = mips_load_call_address (MIPS_CALL_NORMAL, addr, fn); 7540 7541 /* Emit the call. */ 7542 insn = mips_expand_call (MIPS_CALL_NORMAL, retval, stub_fn, 7543 args_size, NULL_RTX, lazy_p); 7544 7545 /* Tell GCC that this call does indeed use the value of $2. */ 7546 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), addr); 7547 7548 /* If we are handling a floating-point return value, we need to 7549 save $18 in the function prologue. Putting a note on the 7550 call will mean that df_regs_ever_live_p ($18) will be true if the 7551 call is not eliminated, and we can check that in the prologue 7552 code. */ 7553 if (fp_ret_p) 7554 CALL_INSN_FUNCTION_USAGE (insn) = 7555 gen_rtx_EXPR_LIST (VOIDmode, 7556 gen_rtx_CLOBBER (VOIDmode, 7557 gen_rtx_REG (word_mode, 18)), 7558 CALL_INSN_FUNCTION_USAGE (insn)); 7559 7560 return insn; 7561 } 7562 7563 /* We know the function we are going to call. If we have already 7564 built a stub, we don't need to do anything further. */ 7565 fnname = targetm.strip_name_encoding (XSTR (fn, 0)); 7566 for (l = mips16_stubs; l != NULL; l = l->next) 7567 if (strcmp (l->name, fnname) == 0) 7568 break; 7569 7570 if (l == NULL) 7571 { 7572 const char *separator; 7573 char *secname, *stubname; 7574 tree stubid, stubdecl; 7575 unsigned int f; 7576 7577 /* If the function does not return in FPRs, the special stub 7578 section is named 7579 .mips16.call.FNNAME 7580 7581 If the function does return in FPRs, the stub section is named 7582 .mips16.call.fp.FNNAME 7583 7584 Build a decl for the stub. */ 7585 secname = ACONCAT ((".mips16.call.", fp_ret_p ? "fp." : "", 7586 fnname, NULL)); 7587 stubname = ACONCAT (("__call_stub_", fp_ret_p ? "fp_" : "", 7588 fnname, NULL)); 7589 stubid = get_identifier (stubname); 7590 stubdecl = build_decl (BUILTINS_LOCATION, 7591 FUNCTION_DECL, stubid, 7592 build_function_type_list (void_type_node, 7593 NULL_TREE)); 7594 set_decl_section_name (stubdecl, secname); 7595 DECL_RESULT (stubdecl) = build_decl (BUILTINS_LOCATION, 7596 RESULT_DECL, NULL_TREE, 7597 void_type_node); 7598 7599 /* Output a comment. */ 7600 fprintf (asm_out_file, "\t# Stub function to call %s%s (", 7601 (fp_ret_p 7602 ? (GET_MODE (retval) == SFmode ? "float " : "double ") 7603 : ""), 7604 fnname); 7605 separator = ""; 7606 for (f = (unsigned int) fp_code; f != 0; f >>= 2) 7607 { 7608 fprintf (asm_out_file, "%s%s", separator, 7609 (f & 3) == 1 ? "float" : "double"); 7610 separator = ", "; 7611 } 7612 fprintf (asm_out_file, ")\n"); 7613 7614 /* Start the function definition. */ 7615 assemble_start_function (stubdecl, stubname); 7616 mips_start_function_definition (stubname, false); 7617 7618 if (fp_ret_p) 7619 { 7620 fprintf (asm_out_file, "\t.cfi_startproc\n"); 7621 7622 /* Create a fake CFA 4 bytes below the stack pointer. 7623 This works around unwinders (like libgcc's) that expect 7624 the CFA for non-signal frames to be unique. */ 7625 fprintf (asm_out_file, "\t.cfi_def_cfa 29,-4\n"); 7626 7627 /* "Save" $sp in itself so we don't use the fake CFA. 7628 This is: DW_CFA_val_expression r29, { DW_OP_reg29 }. */ 7629 fprintf (asm_out_file, "\t.cfi_escape 0x16,29,1,0x6d\n"); 7630 7631 /* Save the return address in $18. The stub's caller knows 7632 that $18 might be clobbered, even though $18 is usually 7633 a call-saved register. 7634 7635 Do it early on in case the last move to a floating-point 7636 register can be scheduled into the delay slot of the 7637 call we are about to make. */ 7638 fprintf (asm_out_file, "\tmove\t%s,%s\n", 7639 reg_names[GP_REG_FIRST + 18], 7640 reg_names[RETURN_ADDR_REGNUM]); 7641 } 7642 else 7643 { 7644 /* Load the address of the MIPS16 function into $25. Do this 7645 first so that targets with coprocessor interlocks can use 7646 an MFC1 to fill the delay slot. */ 7647 if (TARGET_EXPLICIT_RELOCS) 7648 { 7649 output_asm_insn ("lui\t%^,%%hi(%0)", &fn); 7650 output_asm_insn ("addiu\t%^,%^,%%lo(%0)", &fn); 7651 } 7652 else 7653 output_asm_insn ("la\t%^,%0", &fn); 7654 } 7655 7656 /* Move the arguments from general registers to floating-point 7657 registers. */ 7658 mips_output_args_xfer (fp_code, 't'); 7659 7660 if (fp_ret_p) 7661 { 7662 /* Now call the non-MIPS16 function. */ 7663 output_asm_insn (mips_output_jump (&fn, 0, -1, true), &fn); 7664 fprintf (asm_out_file, "\t.cfi_register 31,18\n"); 7665 7666 /* Move the result from floating-point registers to 7667 general registers. */ 7668 switch (GET_MODE (retval)) 7669 { 7670 case E_SCmode: 7671 mips_output_32bit_xfer ('f', GP_RETURN + TARGET_BIG_ENDIAN, 7672 TARGET_BIG_ENDIAN 7673 ? FP_REG_FIRST + 2 7674 : FP_REG_FIRST); 7675 mips_output_32bit_xfer ('f', GP_RETURN + TARGET_LITTLE_ENDIAN, 7676 TARGET_LITTLE_ENDIAN 7677 ? FP_REG_FIRST + 2 7678 : FP_REG_FIRST); 7679 if (GET_MODE (retval) == SCmode && TARGET_64BIT) 7680 { 7681 /* On 64-bit targets, complex floats are returned in 7682 a single GPR, such that "sd" on a suitably-aligned 7683 target would store the value correctly. */ 7684 fprintf (asm_out_file, "\tdsll\t%s,%s,32\n", 7685 reg_names[GP_RETURN + TARGET_BIG_ENDIAN], 7686 reg_names[GP_RETURN + TARGET_BIG_ENDIAN]); 7687 fprintf (asm_out_file, "\tdsll\t%s,%s,32\n", 7688 reg_names[GP_RETURN + TARGET_LITTLE_ENDIAN], 7689 reg_names[GP_RETURN + TARGET_LITTLE_ENDIAN]); 7690 fprintf (asm_out_file, "\tdsrl\t%s,%s,32\n", 7691 reg_names[GP_RETURN + TARGET_BIG_ENDIAN], 7692 reg_names[GP_RETURN + TARGET_BIG_ENDIAN]); 7693 fprintf (asm_out_file, "\tor\t%s,%s,%s\n", 7694 reg_names[GP_RETURN], 7695 reg_names[GP_RETURN], 7696 reg_names[GP_RETURN + 1]); 7697 } 7698 break; 7699 7700 case E_SFmode: 7701 mips_output_32bit_xfer ('f', GP_RETURN, FP_REG_FIRST); 7702 break; 7703 7704 case E_DCmode: 7705 mips_output_64bit_xfer ('f', GP_RETURN + (8 / UNITS_PER_WORD), 7706 FP_REG_FIRST + 2); 7707 /* FALLTHRU */ 7708 case E_DFmode: 7709 case E_V2SFmode: 7710 gcc_assert (TARGET_PAIRED_SINGLE_FLOAT 7711 || GET_MODE (retval) != V2SFmode); 7712 mips_output_64bit_xfer ('f', GP_RETURN, FP_REG_FIRST); 7713 break; 7714 7715 default: 7716 gcc_unreachable (); 7717 } 7718 fprintf (asm_out_file, "\tjr\t%s\n", reg_names[GP_REG_FIRST + 18]); 7719 fprintf (asm_out_file, "\t.cfi_endproc\n"); 7720 } 7721 else 7722 { 7723 /* Jump to the previously-loaded address. */ 7724 output_asm_insn ("jr\t%^", NULL); 7725 } 7726 7727 #ifdef ASM_DECLARE_FUNCTION_SIZE 7728 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, stubname, stubdecl); 7729 #endif 7730 7731 mips_end_function_definition (stubname); 7732 7733 /* Record this stub. */ 7734 l = XNEW (struct mips16_stub); 7735 l->name = xstrdup (fnname); 7736 l->fp_ret_p = fp_ret_p; 7737 l->next = mips16_stubs; 7738 mips16_stubs = l; 7739 } 7740 7741 /* If we expect a floating-point return value, but we've built a 7742 stub which does not expect one, then we're in trouble. We can't 7743 use the existing stub, because it won't handle the floating-point 7744 value. We can't build a new stub, because the linker won't know 7745 which stub to use for the various calls in this object file. 7746 Fortunately, this case is illegal, since it means that a function 7747 was declared in two different ways in a single compilation. */ 7748 if (fp_ret_p && !l->fp_ret_p) 7749 error ("cannot handle inconsistent calls to %qs", fnname); 7750 7751 if (retval == NULL_RTX) 7752 pattern = gen_call_internal_direct (fn, args_size); 7753 else 7754 pattern = gen_call_value_internal_direct (retval, fn, args_size); 7755 insn = mips_emit_call_insn (pattern, fn, fn, false); 7756 7757 /* If we are calling a stub which handles a floating-point return 7758 value, we need to arrange to save $18 in the prologue. We do this 7759 by marking the function call as using the register. The prologue 7760 will later see that it is used, and emit code to save it. */ 7761 if (fp_ret_p) 7762 CALL_INSN_FUNCTION_USAGE (insn) = 7763 gen_rtx_EXPR_LIST (VOIDmode, 7764 gen_rtx_CLOBBER (VOIDmode, 7765 gen_rtx_REG (word_mode, 18)), 7766 CALL_INSN_FUNCTION_USAGE (insn)); 7767 7768 return insn; 7769 } 7770 7771 /* Expand a call of type TYPE. RESULT is where the result will go (null 7772 for "call"s and "sibcall"s), ADDR is the address of the function, 7773 ARGS_SIZE is the size of the arguments and AUX is the value passed 7774 to us by mips_function_arg. LAZY_P is true if this call already 7775 involves a lazily-bound function address (such as when calling 7776 functions through a MIPS16 hard-float stub). 7777 7778 Return the call itself. */ 7779 7780 rtx_insn * 7781 mips_expand_call (enum mips_call_type type, rtx result, rtx addr, 7782 rtx args_size, rtx aux, bool lazy_p) 7783 { 7784 rtx orig_addr, pattern; 7785 rtx_insn *insn; 7786 int fp_code; 7787 7788 fp_code = aux == 0 ? 0 : (int) GET_MODE (aux); 7789 insn = mips16_build_call_stub (result, &addr, args_size, fp_code); 7790 if (insn) 7791 { 7792 gcc_assert (!lazy_p && type == MIPS_CALL_NORMAL); 7793 return insn; 7794 } 7795 7796 orig_addr = addr; 7797 if (!call_insn_operand (addr, VOIDmode)) 7798 { 7799 if (type == MIPS_CALL_EPILOGUE) 7800 addr = MIPS_EPILOGUE_TEMP (Pmode); 7801 else 7802 addr = gen_reg_rtx (Pmode); 7803 lazy_p |= mips_load_call_address (type, addr, orig_addr); 7804 } 7805 7806 if (result == 0) 7807 { 7808 rtx (*fn) (rtx, rtx); 7809 7810 if (type == MIPS_CALL_SIBCALL) 7811 fn = gen_sibcall_internal; 7812 else 7813 fn = gen_call_internal; 7814 7815 pattern = fn (addr, args_size); 7816 } 7817 else if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 2) 7818 { 7819 /* Handle return values created by mips_return_fpr_pair. */ 7820 rtx (*fn) (rtx, rtx, rtx, rtx); 7821 rtx reg1, reg2; 7822 7823 if (type == MIPS_CALL_SIBCALL) 7824 fn = gen_sibcall_value_multiple_internal; 7825 else 7826 fn = gen_call_value_multiple_internal; 7827 7828 reg1 = XEXP (XVECEXP (result, 0, 0), 0); 7829 reg2 = XEXP (XVECEXP (result, 0, 1), 0); 7830 pattern = fn (reg1, addr, args_size, reg2); 7831 } 7832 else 7833 { 7834 rtx (*fn) (rtx, rtx, rtx); 7835 7836 if (type == MIPS_CALL_SIBCALL) 7837 fn = gen_sibcall_value_internal; 7838 else 7839 fn = gen_call_value_internal; 7840 7841 /* Handle return values created by mips_return_fpr_single. */ 7842 if (GET_CODE (result) == PARALLEL && XVECLEN (result, 0) == 1) 7843 result = XEXP (XVECEXP (result, 0, 0), 0); 7844 pattern = fn (result, addr, args_size); 7845 } 7846 7847 return mips_emit_call_insn (pattern, orig_addr, addr, lazy_p); 7848 } 7849 7850 /* Split call instruction INSN into a $gp-clobbering call and 7851 (where necessary) an instruction to restore $gp from its save slot. 7852 CALL_PATTERN is the pattern of the new call. */ 7853 7854 void 7855 mips_split_call (rtx insn, rtx call_pattern) 7856 { 7857 emit_call_insn (call_pattern); 7858 if (!find_reg_note (insn, REG_NORETURN, 0)) 7859 mips_restore_gp_from_cprestore_slot (gen_rtx_REG (Pmode, 7860 POST_CALL_TMP_REG)); 7861 } 7862 7863 /* Return true if a call to DECL may need to use JALX. */ 7864 7865 static bool 7866 mips_call_may_need_jalx_p (tree decl) 7867 { 7868 /* If the current translation unit would use a different mode for DECL, 7869 assume that the call needs JALX. */ 7870 if (mips_get_compress_mode (decl) != TARGET_COMPRESSION) 7871 return true; 7872 7873 /* mips_get_compress_mode is always accurate for locally-binding 7874 functions in the current translation unit. */ 7875 if (!DECL_EXTERNAL (decl) && targetm.binds_local_p (decl)) 7876 return false; 7877 7878 /* When -minterlink-compressed is in effect, assume that functions 7879 could use a different encoding mode unless an attribute explicitly 7880 tells us otherwise. */ 7881 if (TARGET_INTERLINK_COMPRESSED) 7882 { 7883 if (!TARGET_COMPRESSION 7884 && mips_get_compress_off_flags (DECL_ATTRIBUTES (decl)) ==0) 7885 return true; 7886 if (TARGET_COMPRESSION 7887 && mips_get_compress_on_flags (DECL_ATTRIBUTES (decl)) == 0) 7888 return true; 7889 } 7890 7891 return false; 7892 } 7893 7894 /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL. */ 7895 7896 static bool 7897 mips_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED) 7898 { 7899 if (!TARGET_SIBCALLS) 7900 return false; 7901 7902 /* Interrupt handlers need special epilogue code and therefore can't 7903 use sibcalls. */ 7904 if (mips_interrupt_type_p (TREE_TYPE (current_function_decl))) 7905 return false; 7906 7907 /* Direct Js are only possible to functions that use the same ISA encoding. 7908 There is no JX counterpoart of JALX. */ 7909 if (decl 7910 && const_call_insn_operand (XEXP (DECL_RTL (decl), 0), VOIDmode) 7911 && mips_call_may_need_jalx_p (decl)) 7912 return false; 7913 7914 /* Sibling calls should not prevent lazy binding. Lazy-binding stubs 7915 require $gp to be valid on entry, so sibcalls can only use stubs 7916 if $gp is call-clobbered. */ 7917 if (decl 7918 && TARGET_CALL_SAVED_GP 7919 && !TARGET_ABICALLS_PIC0 7920 && !targetm.binds_local_p (decl)) 7921 return false; 7922 7923 /* Otherwise OK. */ 7924 return true; 7925 } 7926 7927 /* Implement TARGET_USE_MOVE_BY_PIECES_INFRASTRUCTURE_P. */ 7928 7929 bool 7930 mips_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size, 7931 unsigned int align, 7932 enum by_pieces_operation op, 7933 bool speed_p) 7934 { 7935 if (op == STORE_BY_PIECES) 7936 return mips_store_by_pieces_p (size, align); 7937 if (op == MOVE_BY_PIECES && HAVE_cpymemsi) 7938 { 7939 /* cpymemsi is meant to generate code that is at least as good as 7940 move_by_pieces. However, cpymemsi effectively uses a by-pieces 7941 implementation both for moves smaller than a word and for 7942 word-aligned moves of no more than MIPS_MAX_MOVE_BYTES_STRAIGHT 7943 bytes. We should allow the tree-level optimisers to do such 7944 moves by pieces, as it often exposes other optimization 7945 opportunities. We might as well continue to use cpymemsi at 7946 the rtl level though, as it produces better code when 7947 scheduling is disabled (such as at -O). */ 7948 if (currently_expanding_to_rtl) 7949 return false; 7950 if (align < BITS_PER_WORD) 7951 return size < UNITS_PER_WORD; 7952 return size <= MIPS_MAX_MOVE_BYTES_STRAIGHT; 7953 } 7954 7955 return default_use_by_pieces_infrastructure_p (size, align, op, speed_p); 7956 } 7957 7958 /* Implement a handler for STORE_BY_PIECES operations 7959 for TARGET_USE_MOVE_BY_PIECES_INFRASTRUCTURE_P. */ 7960 7961 bool 7962 mips_store_by_pieces_p (unsigned HOST_WIDE_INT size, unsigned int align) 7963 { 7964 /* Storing by pieces involves moving constants into registers 7965 of size MIN (ALIGN, BITS_PER_WORD), then storing them. 7966 We need to decide whether it is cheaper to load the address of 7967 constant data into a register and use a block move instead. */ 7968 7969 /* If the data is only byte aligned, then: 7970 7971 (a1) A block move of less than 4 bytes would involve three 3 LBs and 7972 3 SBs. We might as well use 3 single-instruction LIs and 3 SBs 7973 instead. 7974 7975 (a2) A block move of 4 bytes from aligned source data can use an 7976 LW/SWL/SWR sequence. This is often better than the 4 LIs and 7977 4 SBs that we would generate when storing by pieces. */ 7978 if (align <= BITS_PER_UNIT) 7979 return size < 4; 7980 7981 /* If the data is 2-byte aligned, then: 7982 7983 (b1) A block move of less than 4 bytes would use a combination of LBs, 7984 LHs, SBs and SHs. We get better code by using single-instruction 7985 LIs, SBs and SHs instead. 7986 7987 (b2) A block move of 4 bytes from aligned source data would again use 7988 an LW/SWL/SWR sequence. In most cases, loading the address of 7989 the source data would require at least one extra instruction. 7990 It is often more efficient to use 2 single-instruction LIs and 7991 2 SHs instead. 7992 7993 (b3) A block move of up to 3 additional bytes would be like (b1). 7994 7995 (b4) A block move of 8 bytes from aligned source data can use two 7996 LW/SWL/SWR sequences or a single LD/SDL/SDR sequence. Both 7997 sequences are better than the 4 LIs and 4 SHs that we'd generate 7998 when storing by pieces. 7999 8000 The reasoning for higher alignments is similar: 8001 8002 (c1) A block move of less than 4 bytes would be the same as (b1). 8003 8004 (c2) A block move of 4 bytes would use an LW/SW sequence. Again, 8005 loading the address of the source data would typically require 8006 at least one extra instruction. It is generally better to use 8007 LUI/ORI/SW instead. 8008 8009 (c3) A block move of up to 3 additional bytes would be like (b1). 8010 8011 (c4) A block move of 8 bytes can use two LW/SW sequences or a single 8012 LD/SD sequence, and in these cases we've traditionally preferred 8013 the memory copy over the more bulky constant moves. */ 8014 return size < 8; 8015 } 8016 8017 /* Emit straight-line code to move LENGTH bytes from SRC to DEST. 8018 Assume that the areas do not overlap. */ 8019 8020 static void 8021 mips_block_move_straight (rtx dest, rtx src, HOST_WIDE_INT length) 8022 { 8023 HOST_WIDE_INT offset, delta; 8024 unsigned HOST_WIDE_INT bits; 8025 int i; 8026 machine_mode mode; 8027 rtx *regs; 8028 8029 /* Work out how many bits to move at a time. If both operands have 8030 half-word alignment, it is usually better to move in half words. 8031 For instance, lh/lh/sh/sh is usually better than lwl/lwr/swl/swr 8032 and lw/lw/sw/sw is usually better than ldl/ldr/sdl/sdr. 8033 Otherwise move word-sized chunks. 8034 8035 For ISA_HAS_LWL_LWR we rely on the lwl/lwr & swl/swr load. Otherwise 8036 picking the minimum of alignment or BITS_PER_WORD gets us the 8037 desired size for bits. */ 8038 8039 if (!ISA_HAS_LWL_LWR) 8040 bits = MIN (BITS_PER_WORD, MIN (MEM_ALIGN (src), MEM_ALIGN (dest))); 8041 else 8042 { 8043 if (MEM_ALIGN (src) == BITS_PER_WORD / 2 8044 && MEM_ALIGN (dest) == BITS_PER_WORD / 2) 8045 bits = BITS_PER_WORD / 2; 8046 else 8047 bits = BITS_PER_WORD; 8048 } 8049 8050 mode = int_mode_for_size (bits, 0).require (); 8051 delta = bits / BITS_PER_UNIT; 8052 8053 /* Allocate a buffer for the temporary registers. */ 8054 regs = XALLOCAVEC (rtx, length / delta); 8055 8056 /* Load as many BITS-sized chunks as possible. Use a normal load if 8057 the source has enough alignment, otherwise use left/right pairs. */ 8058 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++) 8059 { 8060 regs[i] = gen_reg_rtx (mode); 8061 if (MEM_ALIGN (src) >= bits) 8062 mips_emit_move (regs[i], adjust_address (src, mode, offset)); 8063 else 8064 { 8065 rtx part = adjust_address (src, BLKmode, offset); 8066 set_mem_size (part, delta); 8067 if (!mips_expand_ext_as_unaligned_load (regs[i], part, bits, 0, 0)) 8068 gcc_unreachable (); 8069 } 8070 } 8071 8072 /* Copy the chunks to the destination. */ 8073 for (offset = 0, i = 0; offset + delta <= length; offset += delta, i++) 8074 if (MEM_ALIGN (dest) >= bits) 8075 mips_emit_move (adjust_address (dest, mode, offset), regs[i]); 8076 else 8077 { 8078 rtx part = adjust_address (dest, BLKmode, offset); 8079 set_mem_size (part, delta); 8080 if (!mips_expand_ins_as_unaligned_store (part, regs[i], bits, 0)) 8081 gcc_unreachable (); 8082 } 8083 8084 /* Mop up any left-over bytes. */ 8085 if (offset < length) 8086 { 8087 src = adjust_address (src, BLKmode, offset); 8088 dest = adjust_address (dest, BLKmode, offset); 8089 move_by_pieces (dest, src, length - offset, 8090 MIN (MEM_ALIGN (src), MEM_ALIGN (dest)), RETURN_BEGIN); 8091 } 8092 } 8093 8094 /* Helper function for doing a loop-based block operation on memory 8095 reference MEM. Each iteration of the loop will operate on LENGTH 8096 bytes of MEM. 8097 8098 Create a new base register for use within the loop and point it to 8099 the start of MEM. Create a new memory reference that uses this 8100 register. Store them in *LOOP_REG and *LOOP_MEM respectively. */ 8101 8102 static void 8103 mips_adjust_block_mem (rtx mem, HOST_WIDE_INT length, 8104 rtx *loop_reg, rtx *loop_mem) 8105 { 8106 *loop_reg = copy_addr_to_reg (XEXP (mem, 0)); 8107 8108 /* Although the new mem does not refer to a known location, 8109 it does keep up to LENGTH bytes of alignment. */ 8110 *loop_mem = change_address (mem, BLKmode, *loop_reg); 8111 set_mem_align (*loop_mem, MIN (MEM_ALIGN (mem), length * BITS_PER_UNIT)); 8112 } 8113 8114 /* Move LENGTH bytes from SRC to DEST using a loop that moves BYTES_PER_ITER 8115 bytes at a time. LENGTH must be at least BYTES_PER_ITER. Assume that 8116 the memory regions do not overlap. */ 8117 8118 static void 8119 mips_block_move_loop (rtx dest, rtx src, HOST_WIDE_INT length, 8120 HOST_WIDE_INT bytes_per_iter) 8121 { 8122 rtx_code_label *label; 8123 rtx src_reg, dest_reg, final_src, test; 8124 HOST_WIDE_INT leftover; 8125 8126 leftover = length % bytes_per_iter; 8127 length -= leftover; 8128 8129 /* Create registers and memory references for use within the loop. */ 8130 mips_adjust_block_mem (src, bytes_per_iter, &src_reg, &src); 8131 mips_adjust_block_mem (dest, bytes_per_iter, &dest_reg, &dest); 8132 8133 /* Calculate the value that SRC_REG should have after the last iteration 8134 of the loop. */ 8135 final_src = expand_simple_binop (Pmode, PLUS, src_reg, GEN_INT (length), 8136 0, 0, OPTAB_WIDEN); 8137 8138 /* Emit the start of the loop. */ 8139 label = gen_label_rtx (); 8140 emit_label (label); 8141 8142 /* Emit the loop body. */ 8143 mips_block_move_straight (dest, src, bytes_per_iter); 8144 8145 /* Move on to the next block. */ 8146 mips_emit_move (src_reg, plus_constant (Pmode, src_reg, bytes_per_iter)); 8147 mips_emit_move (dest_reg, plus_constant (Pmode, dest_reg, bytes_per_iter)); 8148 8149 /* Emit the loop condition. */ 8150 test = gen_rtx_NE (VOIDmode, src_reg, final_src); 8151 if (Pmode == DImode) 8152 emit_jump_insn (gen_cbranchdi4 (test, src_reg, final_src, label)); 8153 else 8154 emit_jump_insn (gen_cbranchsi4 (test, src_reg, final_src, label)); 8155 8156 /* Mop up any left-over bytes. */ 8157 if (leftover) 8158 mips_block_move_straight (dest, src, leftover); 8159 else 8160 /* Temporary fix for PR79150. */ 8161 emit_insn (gen_nop ()); 8162 } 8163 8164 /* Expand a cpymemsi instruction, which copies LENGTH bytes from 8165 memory reference SRC to memory reference DEST. */ 8166 8167 bool 8168 mips_expand_block_move (rtx dest, rtx src, rtx length) 8169 { 8170 if (!ISA_HAS_LWL_LWR 8171 && (MEM_ALIGN (src) < MIPS_MIN_MOVE_MEM_ALIGN 8172 || MEM_ALIGN (dest) < MIPS_MIN_MOVE_MEM_ALIGN)) 8173 return false; 8174 8175 if (CONST_INT_P (length)) 8176 { 8177 if (INTVAL (length) <= MIPS_MAX_MOVE_BYTES_STRAIGHT) 8178 { 8179 mips_block_move_straight (dest, src, INTVAL (length)); 8180 return true; 8181 } 8182 else if (optimize) 8183 { 8184 mips_block_move_loop (dest, src, INTVAL (length), 8185 MIPS_MAX_MOVE_BYTES_PER_LOOP_ITER); 8186 return true; 8187 } 8188 } 8189 return false; 8190 } 8191 8192 /* Expand a loop of synci insns for the address range [BEGIN, END). */ 8193 8194 void 8195 mips_expand_synci_loop (rtx begin, rtx end) 8196 { 8197 rtx inc, cmp_result, mask, length; 8198 rtx_code_label *label, *end_label; 8199 8200 /* Create end_label. */ 8201 end_label = gen_label_rtx (); 8202 8203 /* Check if begin equals end. */ 8204 cmp_result = gen_rtx_EQ (VOIDmode, begin, end); 8205 emit_jump_insn (gen_condjump (cmp_result, end_label)); 8206 8207 /* Load INC with the cache line size (rdhwr INC,$1). */ 8208 inc = gen_reg_rtx (Pmode); 8209 emit_insn (PMODE_INSN (gen_rdhwr_synci_step, (inc))); 8210 8211 /* Check if inc is 0. */ 8212 cmp_result = gen_rtx_EQ (VOIDmode, inc, const0_rtx); 8213 emit_jump_insn (gen_condjump (cmp_result, end_label)); 8214 8215 /* Calculate mask. */ 8216 mask = mips_force_unary (Pmode, NEG, inc); 8217 8218 /* Mask out begin by mask. */ 8219 begin = mips_force_binary (Pmode, AND, begin, mask); 8220 8221 /* Calculate length. */ 8222 length = mips_force_binary (Pmode, MINUS, end, begin); 8223 8224 /* Loop back to here. */ 8225 label = gen_label_rtx (); 8226 emit_label (label); 8227 8228 emit_insn (gen_synci (begin)); 8229 8230 /* Update length. */ 8231 mips_emit_binary (MINUS, length, length, inc); 8232 8233 /* Update begin. */ 8234 mips_emit_binary (PLUS, begin, begin, inc); 8235 8236 /* Check if length is greater than 0. */ 8237 cmp_result = gen_rtx_GT (VOIDmode, length, const0_rtx); 8238 emit_jump_insn (gen_condjump (cmp_result, label)); 8239 8240 emit_label (end_label); 8241 } 8242 8243 /* Expand a QI or HI mode atomic memory operation. 8244 8245 GENERATOR contains a pointer to the gen_* function that generates 8246 the SI mode underlying atomic operation using masks that we 8247 calculate. 8248 8249 RESULT is the return register for the operation. Its value is NULL 8250 if unused. 8251 8252 MEM is the location of the atomic access. 8253 8254 OLDVAL is the first operand for the operation. 8255 8256 NEWVAL is the optional second operand for the operation. Its value 8257 is NULL if unused. */ 8258 8259 void 8260 mips_expand_atomic_qihi (union mips_gen_fn_ptrs generator, 8261 rtx result, rtx mem, rtx oldval, rtx newval) 8262 { 8263 rtx orig_addr, memsi_addr, memsi, shift, shiftsi, unshifted_mask; 8264 rtx unshifted_mask_reg, mask, inverted_mask, si_op; 8265 rtx res = NULL; 8266 machine_mode mode; 8267 8268 mode = GET_MODE (mem); 8269 8270 /* Compute the address of the containing SImode value. */ 8271 orig_addr = force_reg (Pmode, XEXP (mem, 0)); 8272 memsi_addr = mips_force_binary (Pmode, AND, orig_addr, 8273 force_reg (Pmode, GEN_INT (-4))); 8274 8275 /* Create a memory reference for it. */ 8276 memsi = gen_rtx_MEM (SImode, memsi_addr); 8277 set_mem_alias_set (memsi, ALIAS_SET_MEMORY_BARRIER); 8278 MEM_VOLATILE_P (memsi) = MEM_VOLATILE_P (mem); 8279 8280 /* Work out the byte offset of the QImode or HImode value, 8281 counting from the least significant byte. */ 8282 shift = mips_force_binary (Pmode, AND, orig_addr, GEN_INT (3)); 8283 if (TARGET_BIG_ENDIAN) 8284 mips_emit_binary (XOR, shift, shift, GEN_INT (mode == QImode ? 3 : 2)); 8285 8286 /* Multiply by eight to convert the shift value from bytes to bits. */ 8287 mips_emit_binary (ASHIFT, shift, shift, GEN_INT (3)); 8288 8289 /* Make the final shift an SImode value, so that it can be used in 8290 SImode operations. */ 8291 shiftsi = force_reg (SImode, gen_lowpart (SImode, shift)); 8292 8293 /* Set MASK to an inclusive mask of the QImode or HImode value. */ 8294 unshifted_mask = GEN_INT (GET_MODE_MASK (mode)); 8295 unshifted_mask_reg = force_reg (SImode, unshifted_mask); 8296 mask = mips_force_binary (SImode, ASHIFT, unshifted_mask_reg, shiftsi); 8297 8298 /* Compute the equivalent exclusive mask. */ 8299 inverted_mask = gen_reg_rtx (SImode); 8300 emit_insn (gen_rtx_SET (inverted_mask, gen_rtx_NOT (SImode, mask))); 8301 8302 /* Shift the old value into place. */ 8303 if (oldval != const0_rtx) 8304 { 8305 oldval = convert_modes (SImode, mode, oldval, true); 8306 oldval = force_reg (SImode, oldval); 8307 oldval = mips_force_binary (SImode, ASHIFT, oldval, shiftsi); 8308 } 8309 8310 /* Do the same for the new value. */ 8311 if (newval && newval != const0_rtx) 8312 { 8313 newval = convert_modes (SImode, mode, newval, true); 8314 newval = force_reg (SImode, newval); 8315 newval = mips_force_binary (SImode, ASHIFT, newval, shiftsi); 8316 } 8317 8318 /* Do the SImode atomic access. */ 8319 if (result) 8320 res = gen_reg_rtx (SImode); 8321 if (newval) 8322 si_op = generator.fn_6 (res, memsi, mask, inverted_mask, oldval, newval); 8323 else if (result) 8324 si_op = generator.fn_5 (res, memsi, mask, inverted_mask, oldval); 8325 else 8326 si_op = generator.fn_4 (memsi, mask, inverted_mask, oldval); 8327 8328 emit_insn (si_op); 8329 8330 if (result) 8331 { 8332 /* Shift and convert the result. */ 8333 mips_emit_binary (AND, res, res, mask); 8334 mips_emit_binary (LSHIFTRT, res, res, shiftsi); 8335 mips_emit_move (result, gen_lowpart (GET_MODE (result), res)); 8336 } 8337 } 8338 8339 /* Return true if it is possible to use left/right accesses for a 8340 bitfield of WIDTH bits starting BITPOS bits into BLKmode memory OP. 8341 When returning true, update *LEFT and *RIGHT as follows: 8342 8343 *LEFT is a QImode reference to the first byte if big endian or 8344 the last byte if little endian. This address can be used in the 8345 left-side instructions (LWL, SWL, LDL, SDL). 8346 8347 *RIGHT is a QImode reference to the opposite end of the field and 8348 can be used in the patterning right-side instruction. */ 8349 8350 static bool 8351 mips_get_unaligned_mem (rtx op, HOST_WIDE_INT width, HOST_WIDE_INT bitpos, 8352 rtx *left, rtx *right) 8353 { 8354 rtx first, last; 8355 8356 /* Check that the size is valid. */ 8357 if (width != 32 && (!TARGET_64BIT || width != 64)) 8358 return false; 8359 8360 /* We can only access byte-aligned values. Since we are always passed 8361 a reference to the first byte of the field, it is not necessary to 8362 do anything with BITPOS after this check. */ 8363 if (bitpos % BITS_PER_UNIT != 0) 8364 return false; 8365 8366 /* Reject aligned bitfields: we want to use a normal load or store 8367 instead of a left/right pair. */ 8368 if (MEM_ALIGN (op) >= width) 8369 return false; 8370 8371 /* Get references to both ends of the field. */ 8372 first = adjust_address (op, QImode, 0); 8373 last = adjust_address (op, QImode, width / BITS_PER_UNIT - 1); 8374 8375 /* Allocate to LEFT and RIGHT according to endianness. LEFT should 8376 correspond to the MSB and RIGHT to the LSB. */ 8377 if (TARGET_BIG_ENDIAN) 8378 *left = first, *right = last; 8379 else 8380 *left = last, *right = first; 8381 8382 return true; 8383 } 8384 8385 /* Try to use left/right loads to expand an "extv" or "extzv" pattern. 8386 DEST, SRC, WIDTH and BITPOS are the operands passed to the expander; 8387 the operation is the equivalent of: 8388 8389 (set DEST (*_extract SRC WIDTH BITPOS)) 8390 8391 Return true on success. */ 8392 8393 bool 8394 mips_expand_ext_as_unaligned_load (rtx dest, rtx src, HOST_WIDE_INT width, 8395 HOST_WIDE_INT bitpos, bool unsigned_p) 8396 { 8397 rtx left, right, temp; 8398 rtx dest1 = NULL_RTX; 8399 8400 /* If TARGET_64BIT, the destination of a 32-bit "extz" or "extzv" will 8401 be a DImode, create a new temp and emit a zero extend at the end. */ 8402 if (GET_MODE (dest) == DImode 8403 && REG_P (dest) 8404 && GET_MODE_BITSIZE (SImode) == width) 8405 { 8406 dest1 = dest; 8407 dest = gen_reg_rtx (SImode); 8408 } 8409 8410 if (!mips_get_unaligned_mem (src, width, bitpos, &left, &right)) 8411 return false; 8412 8413 temp = gen_reg_rtx (GET_MODE (dest)); 8414 if (GET_MODE (dest) == DImode) 8415 { 8416 emit_insn (gen_mov_ldl (temp, src, left)); 8417 emit_insn (gen_mov_ldr (dest, copy_rtx (src), right, temp)); 8418 } 8419 else 8420 { 8421 emit_insn (gen_mov_lwl (temp, src, left)); 8422 emit_insn (gen_mov_lwr (dest, copy_rtx (src), right, temp)); 8423 } 8424 8425 /* If we were loading 32bits and the original register was DI then 8426 sign/zero extend into the orignal dest. */ 8427 if (dest1) 8428 { 8429 if (unsigned_p) 8430 emit_insn (gen_zero_extendsidi2 (dest1, dest)); 8431 else 8432 emit_insn (gen_extendsidi2 (dest1, dest)); 8433 } 8434 return true; 8435 } 8436 8437 /* Try to use left/right stores to expand an "ins" pattern. DEST, WIDTH, 8438 BITPOS and SRC are the operands passed to the expander; the operation 8439 is the equivalent of: 8440 8441 (set (zero_extract DEST WIDTH BITPOS) SRC) 8442 8443 Return true on success. */ 8444 8445 bool 8446 mips_expand_ins_as_unaligned_store (rtx dest, rtx src, HOST_WIDE_INT width, 8447 HOST_WIDE_INT bitpos) 8448 { 8449 rtx left, right; 8450 machine_mode mode; 8451 8452 if (!mips_get_unaligned_mem (dest, width, bitpos, &left, &right)) 8453 return false; 8454 8455 mode = int_mode_for_size (width, 0).require (); 8456 src = gen_lowpart (mode, src); 8457 if (mode == DImode) 8458 { 8459 emit_insn (gen_mov_sdl (dest, src, left)); 8460 emit_insn (gen_mov_sdr (copy_rtx (dest), copy_rtx (src), right)); 8461 } 8462 else 8463 { 8464 emit_insn (gen_mov_swl (dest, src, left)); 8465 emit_insn (gen_mov_swr (copy_rtx (dest), copy_rtx (src), right)); 8466 } 8467 return true; 8468 } 8469 8470 /* Return true if X is a MEM with the same size as MODE. */ 8471 8472 bool 8473 mips_mem_fits_mode_p (machine_mode mode, rtx x) 8474 { 8475 return (MEM_P (x) 8476 && MEM_SIZE_KNOWN_P (x) 8477 && MEM_SIZE (x) == GET_MODE_SIZE (mode)); 8478 } 8479 8480 /* Return true if (zero_extract OP WIDTH BITPOS) can be used as the 8481 source of an "ext" instruction or the destination of an "ins" 8482 instruction. OP must be a register operand and the following 8483 conditions must hold: 8484 8485 0 <= BITPOS < GET_MODE_BITSIZE (GET_MODE (op)) 8486 0 < WIDTH <= GET_MODE_BITSIZE (GET_MODE (op)) 8487 0 < BITPOS + WIDTH <= GET_MODE_BITSIZE (GET_MODE (op)) 8488 8489 Also reject lengths equal to a word as they are better handled 8490 by the move patterns. */ 8491 8492 bool 8493 mips_use_ins_ext_p (rtx op, HOST_WIDE_INT width, HOST_WIDE_INT bitpos) 8494 { 8495 if (!ISA_HAS_EXT_INS 8496 || !register_operand (op, VOIDmode) 8497 || GET_MODE_BITSIZE (GET_MODE (op)) > BITS_PER_WORD) 8498 return false; 8499 8500 if (!IN_RANGE (width, 1, GET_MODE_BITSIZE (GET_MODE (op)) - 1)) 8501 return false; 8502 8503 if (bitpos < 0 || bitpos + width > GET_MODE_BITSIZE (GET_MODE (op))) 8504 return false; 8505 8506 return true; 8507 } 8508 8509 /* Check if MASK and SHIFT are valid in mask-low-and-shift-left 8510 operation if MAXLEN is the maxium length of consecutive bits that 8511 can make up MASK. MODE is the mode of the operation. See 8512 mask_low_and_shift_len for the actual definition. */ 8513 8514 bool 8515 mask_low_and_shift_p (machine_mode mode, rtx mask, rtx shift, int maxlen) 8516 { 8517 return IN_RANGE (mask_low_and_shift_len (mode, mask, shift), 1, maxlen); 8518 } 8519 8520 /* Return true iff OP1 and OP2 are valid operands together for the 8521 *and<MODE>3 and *and<MODE>3_mips16 patterns. For the cases to consider, 8522 see the table in the comment before the pattern. */ 8523 8524 bool 8525 and_operands_ok (machine_mode mode, rtx op1, rtx op2) 8526 { 8527 8528 if (memory_operand (op1, mode)) 8529 { 8530 if (TARGET_MIPS16) { 8531 struct mips_address_info addr; 8532 if (!mips_classify_address (&addr, op1, mode, false)) 8533 return false; 8534 } 8535 return and_load_operand (op2, mode); 8536 } 8537 else 8538 return and_reg_operand (op2, mode); 8539 } 8540 8541 /* The canonical form of a mask-low-and-shift-left operation is 8542 (and (ashift X SHIFT) MASK) where MASK has the lower SHIFT number of bits 8543 cleared. Thus we need to shift MASK to the right before checking if it 8544 is a valid mask value. MODE is the mode of the operation. If true 8545 return the length of the mask, otherwise return -1. */ 8546 8547 int 8548 mask_low_and_shift_len (machine_mode mode, rtx mask, rtx shift) 8549 { 8550 HOST_WIDE_INT shval; 8551 8552 shval = INTVAL (shift) & (GET_MODE_BITSIZE (mode) - 1); 8553 return exact_log2 ((UINTVAL (mask) >> shval) + 1); 8554 } 8555 8556 /* Return true if -msplit-addresses is selected and should be honored. 8557 8558 -msplit-addresses is a half-way house between explicit relocations 8559 and the traditional assembler macros. It can split absolute 32-bit 8560 symbolic constants into a high/lo_sum pair but uses macros for other 8561 sorts of access. 8562 8563 Like explicit relocation support for REL targets, it relies 8564 on GNU extensions in the assembler and the linker. 8565 8566 Although this code should work for -O0, it has traditionally 8567 been treated as an optimization. */ 8568 8569 static bool 8570 mips_split_addresses_p (void) 8571 { 8572 return (TARGET_SPLIT_ADDRESSES 8573 && optimize 8574 && !TARGET_MIPS16 8575 && !flag_pic 8576 && !ABI_HAS_64BIT_SYMBOLS); 8577 } 8578 8579 /* (Re-)Initialize mips_split_p, mips_lo_relocs and mips_hi_relocs. */ 8580 8581 static void 8582 mips_init_relocs (void) 8583 { 8584 memset (mips_split_p, '\0', sizeof (mips_split_p)); 8585 memset (mips_split_hi_p, '\0', sizeof (mips_split_hi_p)); 8586 memset (mips_use_pcrel_pool_p, '\0', sizeof (mips_use_pcrel_pool_p)); 8587 memset (mips_hi_relocs, '\0', sizeof (mips_hi_relocs)); 8588 memset (mips_lo_relocs, '\0', sizeof (mips_lo_relocs)); 8589 8590 if (TARGET_MIPS16_PCREL_LOADS) 8591 mips_use_pcrel_pool_p[SYMBOL_ABSOLUTE] = true; 8592 else 8593 { 8594 if (ABI_HAS_64BIT_SYMBOLS) 8595 { 8596 if (TARGET_EXPLICIT_RELOCS) 8597 { 8598 mips_split_p[SYMBOL_64_HIGH] = true; 8599 mips_hi_relocs[SYMBOL_64_HIGH] = "%highest("; 8600 mips_lo_relocs[SYMBOL_64_HIGH] = "%higher("; 8601 8602 mips_split_p[SYMBOL_64_MID] = true; 8603 mips_hi_relocs[SYMBOL_64_MID] = "%higher("; 8604 mips_lo_relocs[SYMBOL_64_MID] = "%hi("; 8605 8606 mips_split_p[SYMBOL_64_LOW] = true; 8607 mips_hi_relocs[SYMBOL_64_LOW] = "%hi("; 8608 mips_lo_relocs[SYMBOL_64_LOW] = "%lo("; 8609 8610 mips_split_p[SYMBOL_ABSOLUTE] = true; 8611 mips_lo_relocs[SYMBOL_ABSOLUTE] = "%lo("; 8612 } 8613 } 8614 else 8615 { 8616 if (TARGET_EXPLICIT_RELOCS 8617 || mips_split_addresses_p () 8618 || TARGET_MIPS16) 8619 { 8620 mips_split_p[SYMBOL_ABSOLUTE] = true; 8621 mips_hi_relocs[SYMBOL_ABSOLUTE] = "%hi("; 8622 mips_lo_relocs[SYMBOL_ABSOLUTE] = "%lo("; 8623 } 8624 } 8625 } 8626 8627 if (TARGET_MIPS16) 8628 { 8629 /* The high part is provided by a pseudo copy of $gp. */ 8630 mips_split_p[SYMBOL_GP_RELATIVE] = true; 8631 mips_lo_relocs[SYMBOL_GP_RELATIVE] = "%gprel("; 8632 } 8633 else if (TARGET_EXPLICIT_RELOCS) 8634 /* Small data constants are kept whole until after reload, 8635 then lowered by mips_rewrite_small_data. */ 8636 mips_lo_relocs[SYMBOL_GP_RELATIVE] = "%gp_rel("; 8637 8638 if (TARGET_EXPLICIT_RELOCS) 8639 { 8640 mips_split_p[SYMBOL_GOT_PAGE_OFST] = true; 8641 if (TARGET_NEWABI) 8642 { 8643 mips_lo_relocs[SYMBOL_GOTOFF_PAGE] = "%got_page("; 8644 mips_lo_relocs[SYMBOL_GOT_PAGE_OFST] = "%got_ofst("; 8645 } 8646 else 8647 { 8648 mips_lo_relocs[SYMBOL_GOTOFF_PAGE] = "%got("; 8649 mips_lo_relocs[SYMBOL_GOT_PAGE_OFST] = "%lo("; 8650 } 8651 if (TARGET_MIPS16) 8652 /* Expose the use of $28 as soon as possible. */ 8653 mips_split_hi_p[SYMBOL_GOT_PAGE_OFST] = true; 8654 8655 if (TARGET_XGOT) 8656 { 8657 /* The HIGH and LO_SUM are matched by special .md patterns. */ 8658 mips_split_p[SYMBOL_GOT_DISP] = true; 8659 8660 mips_split_p[SYMBOL_GOTOFF_DISP] = true; 8661 mips_hi_relocs[SYMBOL_GOTOFF_DISP] = "%got_hi("; 8662 mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got_lo("; 8663 8664 mips_split_p[SYMBOL_GOTOFF_CALL] = true; 8665 mips_hi_relocs[SYMBOL_GOTOFF_CALL] = "%call_hi("; 8666 mips_lo_relocs[SYMBOL_GOTOFF_CALL] = "%call_lo("; 8667 } 8668 else 8669 { 8670 if (TARGET_NEWABI) 8671 mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got_disp("; 8672 else 8673 mips_lo_relocs[SYMBOL_GOTOFF_DISP] = "%got("; 8674 mips_lo_relocs[SYMBOL_GOTOFF_CALL] = "%call16("; 8675 if (TARGET_MIPS16) 8676 /* Expose the use of $28 as soon as possible. */ 8677 mips_split_p[SYMBOL_GOT_DISP] = true; 8678 } 8679 } 8680 8681 if (TARGET_NEWABI) 8682 { 8683 mips_split_p[SYMBOL_GOTOFF_LOADGP] = true; 8684 mips_hi_relocs[SYMBOL_GOTOFF_LOADGP] = "%hi(%neg(%gp_rel("; 8685 mips_lo_relocs[SYMBOL_GOTOFF_LOADGP] = "%lo(%neg(%gp_rel("; 8686 } 8687 8688 mips_lo_relocs[SYMBOL_TLSGD] = "%tlsgd("; 8689 mips_lo_relocs[SYMBOL_TLSLDM] = "%tlsldm("; 8690 8691 if (TARGET_MIPS16_PCREL_LOADS) 8692 { 8693 mips_use_pcrel_pool_p[SYMBOL_DTPREL] = true; 8694 mips_use_pcrel_pool_p[SYMBOL_TPREL] = true; 8695 } 8696 else 8697 { 8698 mips_split_p[SYMBOL_DTPREL] = true; 8699 mips_hi_relocs[SYMBOL_DTPREL] = "%dtprel_hi("; 8700 mips_lo_relocs[SYMBOL_DTPREL] = "%dtprel_lo("; 8701 8702 mips_split_p[SYMBOL_TPREL] = true; 8703 mips_hi_relocs[SYMBOL_TPREL] = "%tprel_hi("; 8704 mips_lo_relocs[SYMBOL_TPREL] = "%tprel_lo("; 8705 } 8706 8707 mips_lo_relocs[SYMBOL_GOTTPREL] = "%gottprel("; 8708 mips_lo_relocs[SYMBOL_HALF] = "%half("; 8709 } 8710 8711 /* Print symbolic operand OP, which is part of a HIGH or LO_SUM 8712 in context CONTEXT. RELOCS is the array of relocations to use. */ 8713 8714 static void 8715 mips_print_operand_reloc (FILE *file, rtx op, enum mips_symbol_context context, 8716 const char **relocs) 8717 { 8718 enum mips_symbol_type symbol_type; 8719 const char *p; 8720 8721 symbol_type = mips_classify_symbolic_expression (op, context); 8722 gcc_assert (relocs[symbol_type]); 8723 8724 fputs (relocs[symbol_type], file); 8725 output_addr_const (file, mips_strip_unspec_address (op)); 8726 for (p = relocs[symbol_type]; *p != 0; p++) 8727 if (*p == '(') 8728 fputc (')', file); 8729 } 8730 8731 /* Start a new block with the given asm switch enabled. If we need 8732 to print a directive, emit PREFIX before it and SUFFIX after it. */ 8733 8734 static void 8735 mips_push_asm_switch_1 (struct mips_asm_switch *asm_switch, 8736 const char *prefix, const char *suffix) 8737 { 8738 if (asm_switch->nesting_level == 0) 8739 fprintf (asm_out_file, "%s.set\tno%s%s", prefix, asm_switch->name, suffix); 8740 asm_switch->nesting_level++; 8741 } 8742 8743 /* Likewise, but end a block. */ 8744 8745 static void 8746 mips_pop_asm_switch_1 (struct mips_asm_switch *asm_switch, 8747 const char *prefix, const char *suffix) 8748 { 8749 gcc_assert (asm_switch->nesting_level); 8750 asm_switch->nesting_level--; 8751 if (asm_switch->nesting_level == 0) 8752 fprintf (asm_out_file, "%s.set\t%s%s", prefix, asm_switch->name, suffix); 8753 } 8754 8755 /* Wrappers around mips_push_asm_switch_1 and mips_pop_asm_switch_1 8756 that either print a complete line or print nothing. */ 8757 8758 void 8759 mips_push_asm_switch (struct mips_asm_switch *asm_switch) 8760 { 8761 mips_push_asm_switch_1 (asm_switch, "\t", "\n"); 8762 } 8763 8764 void 8765 mips_pop_asm_switch (struct mips_asm_switch *asm_switch) 8766 { 8767 mips_pop_asm_switch_1 (asm_switch, "\t", "\n"); 8768 } 8769 8770 /* Print the text for PRINT_OPERAND punctation character CH to FILE. 8771 The punctuation characters are: 8772 8773 '(' Start a nested ".set noreorder" block. 8774 ')' End a nested ".set noreorder" block. 8775 '[' Start a nested ".set noat" block. 8776 ']' End a nested ".set noat" block. 8777 '<' Start a nested ".set nomacro" block. 8778 '>' End a nested ".set nomacro" block. 8779 '*' Behave like %(%< if generating a delayed-branch sequence. 8780 '#' Print a nop if in a ".set noreorder" block. 8781 '/' Like '#', but do nothing within a delayed-branch sequence. 8782 '?' Print "l" if mips_branch_likely is true 8783 '~' Print a nop if mips_branch_likely is true 8784 '.' Print the name of the register with a hard-wired zero (zero or $0). 8785 '@' Print the name of the assembler temporary register (at or $1). 8786 '^' Print the name of the pic call-through register (t9 or $25). 8787 '+' Print the name of the gp register (usually gp or $28). 8788 '$' Print the name of the stack pointer register (sp or $29). 8789 ':' Print "c" to use the compact version if the delay slot is a nop. 8790 '!' Print "s" to use the short version if the delay slot contains a 8791 16-bit instruction. 8792 8793 See also mips_init_print_operand_punct. */ 8794 8795 static void 8796 mips_print_operand_punctuation (FILE *file, int ch) 8797 { 8798 switch (ch) 8799 { 8800 case '(': 8801 mips_push_asm_switch_1 (&mips_noreorder, "", "\n\t"); 8802 break; 8803 8804 case ')': 8805 mips_pop_asm_switch_1 (&mips_noreorder, "\n\t", ""); 8806 break; 8807 8808 case '[': 8809 mips_push_asm_switch_1 (&mips_noat, "", "\n\t"); 8810 break; 8811 8812 case ']': 8813 mips_pop_asm_switch_1 (&mips_noat, "\n\t", ""); 8814 break; 8815 8816 case '<': 8817 mips_push_asm_switch_1 (&mips_nomacro, "", "\n\t"); 8818 break; 8819 8820 case '>': 8821 mips_pop_asm_switch_1 (&mips_nomacro, "\n\t", ""); 8822 break; 8823 8824 case '*': 8825 if (final_sequence != 0) 8826 { 8827 mips_print_operand_punctuation (file, '('); 8828 mips_print_operand_punctuation (file, '<'); 8829 } 8830 break; 8831 8832 case '#': 8833 if (mips_noreorder.nesting_level > 0) 8834 fputs ("\n\tnop", file); 8835 break; 8836 8837 case '/': 8838 /* Print an extra newline so that the delayed insn is separated 8839 from the following ones. This looks neater and is consistent 8840 with non-nop delayed sequences. */ 8841 if (mips_noreorder.nesting_level > 0 && final_sequence == 0) 8842 fputs ("\n\tnop\n", file); 8843 break; 8844 8845 case '?': 8846 if (mips_branch_likely) 8847 putc ('l', file); 8848 break; 8849 8850 case '~': 8851 if (mips_branch_likely) 8852 fputs ("\n\tnop", file); 8853 break; 8854 8855 case '.': 8856 fputs (reg_names[GP_REG_FIRST + 0], file); 8857 break; 8858 8859 case '@': 8860 fputs (reg_names[AT_REGNUM], file); 8861 break; 8862 8863 case '^': 8864 fputs (reg_names[PIC_FUNCTION_ADDR_REGNUM], file); 8865 break; 8866 8867 case '+': 8868 fputs (reg_names[PIC_OFFSET_TABLE_REGNUM], file); 8869 break; 8870 8871 case '$': 8872 fputs (reg_names[STACK_POINTER_REGNUM], file); 8873 break; 8874 8875 case ':': 8876 /* When final_sequence is 0, the delay slot will be a nop. We can 8877 use the compact version where available. The %: formatter will 8878 only be present if a compact form of the branch is available. */ 8879 if (final_sequence == 0) 8880 putc ('c', file); 8881 break; 8882 8883 case '!': 8884 /* If the delay slot instruction is short, then use the 8885 compact version. */ 8886 if (TARGET_MICROMIPS && !TARGET_INTERLINK_COMPRESSED && mips_isa_rev <= 5 8887 && (final_sequence == 0 8888 || get_attr_length (final_sequence->insn (1)) == 2)) 8889 putc ('s', file); 8890 break; 8891 8892 default: 8893 gcc_unreachable (); 8894 break; 8895 } 8896 } 8897 8898 /* Initialize mips_print_operand_punct. */ 8899 8900 static void 8901 mips_init_print_operand_punct (void) 8902 { 8903 const char *p; 8904 8905 for (p = "()[]<>*#/?~.@^+$:!"; *p; p++) 8906 mips_print_operand_punct[(unsigned char) *p] = true; 8907 } 8908 8909 /* PRINT_OPERAND prefix LETTER refers to the integer branch instruction 8910 associated with condition CODE. Print the condition part of the 8911 opcode to FILE. */ 8912 8913 static void 8914 mips_print_int_branch_condition (FILE *file, enum rtx_code code, int letter) 8915 { 8916 switch (code) 8917 { 8918 case EQ: 8919 case NE: 8920 case GT: 8921 case GE: 8922 case LT: 8923 case LE: 8924 case GTU: 8925 case GEU: 8926 case LTU: 8927 case LEU: 8928 /* Conveniently, the MIPS names for these conditions are the same 8929 as their RTL equivalents. */ 8930 fputs (GET_RTX_NAME (code), file); 8931 break; 8932 8933 default: 8934 output_operand_lossage ("'%%%c' is not a valid operand prefix", letter); 8935 break; 8936 } 8937 } 8938 8939 /* Likewise floating-point branches. */ 8940 8941 static void 8942 mips_print_float_branch_condition (FILE *file, enum rtx_code code, int letter) 8943 { 8944 switch (code) 8945 { 8946 case EQ: 8947 if (ISA_HAS_CCF) 8948 fputs ("c1eqz", file); 8949 else 8950 fputs ("c1f", file); 8951 break; 8952 8953 case NE: 8954 if (ISA_HAS_CCF) 8955 fputs ("c1nez", file); 8956 else 8957 fputs ("c1t", file); 8958 break; 8959 8960 default: 8961 output_operand_lossage ("'%%%c' is not a valid operand prefix", letter); 8962 break; 8963 } 8964 } 8965 8966 /* Implement TARGET_PRINT_OPERAND_PUNCT_VALID_P. */ 8967 8968 static bool 8969 mips_print_operand_punct_valid_p (unsigned char code) 8970 { 8971 return mips_print_operand_punct[code]; 8972 } 8973 8974 /* Implement TARGET_PRINT_OPERAND. The MIPS-specific operand codes are: 8975 8976 'E' Print CONST_INT OP element 0 of a replicated CONST_VECTOR in decimal. 8977 'X' Print CONST_INT OP in hexadecimal format. 8978 'x' Print the low 16 bits of CONST_INT OP in hexadecimal format. 8979 'd' Print CONST_INT OP in decimal. 8980 'B' Print CONST_INT OP element 0 of a replicated CONST_VECTOR 8981 as an unsigned byte [0..255]. 8982 'm' Print one less than CONST_INT OP in decimal. 8983 'y' Print exact log2 of CONST_INT OP in decimal. 8984 'h' Print the high-part relocation associated with OP, after stripping 8985 any outermost HIGH. 8986 'R' Print the low-part relocation associated with OP. 8987 'C' Print the integer branch condition for comparison OP. 8988 'N' Print the inverse of the integer branch condition for comparison OP. 8989 'F' Print the FPU branch condition for comparison OP. 8990 'W' Print the inverse of the FPU branch condition for comparison OP. 8991 'w' Print a MSA register. 8992 'T' Print 'f' for (eq:CC ...), 't' for (ne:CC ...), 8993 'z' for (eq:?I ...), 'n' for (ne:?I ...). 8994 't' Like 'T', but with the EQ/NE cases reversed 8995 'Y' Print mips_fp_conditions[INTVAL (OP)] 8996 'Z' Print OP and a comma for ISA_HAS_8CC, otherwise print nothing. 8997 'q' Print a DSP accumulator register. 8998 'D' Print the second part of a double-word register or memory operand. 8999 'L' Print the low-order register in a double-word register operand. 9000 'M' Print high-order register in a double-word register operand. 9001 'z' Print $0 if OP is zero, otherwise print OP normally. 9002 'b' Print the address of a memory operand, without offset. 9003 'v' Print the insn size suffix b, h, w or d for vector modes V16QI, V8HI, 9004 V4SI, V2SI, and w, d for vector modes V4SF, V2DF respectively. 9005 'V' Print exact log2 of CONST_INT OP element 0 of a replicated 9006 CONST_VECTOR in decimal. */ 9007 9008 static void 9009 mips_print_operand (FILE *file, rtx op, int letter) 9010 { 9011 enum rtx_code code; 9012 9013 if (mips_print_operand_punct_valid_p (letter)) 9014 { 9015 mips_print_operand_punctuation (file, letter); 9016 return; 9017 } 9018 9019 gcc_assert (op); 9020 code = GET_CODE (op); 9021 9022 switch (letter) 9023 { 9024 case 'E': 9025 if (GET_CODE (op) == CONST_VECTOR) 9026 { 9027 gcc_assert (mips_const_vector_same_val_p (op, GET_MODE (op))); 9028 op = CONST_VECTOR_ELT (op, 0); 9029 gcc_assert (CONST_INT_P (op)); 9030 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op)); 9031 } 9032 else 9033 output_operand_lossage ("invalid use of '%%%c'", letter); 9034 break; 9035 9036 case 'X': 9037 if (CONST_INT_P (op)) 9038 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op)); 9039 else 9040 output_operand_lossage ("invalid use of '%%%c'", letter); 9041 break; 9042 9043 case 'x': 9044 if (CONST_INT_P (op)) 9045 fprintf (file, HOST_WIDE_INT_PRINT_HEX, INTVAL (op) & 0xffff); 9046 else 9047 output_operand_lossage ("invalid use of '%%%c'", letter); 9048 break; 9049 9050 case 'd': 9051 if (CONST_INT_P (op)) 9052 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op)); 9053 else 9054 output_operand_lossage ("invalid use of '%%%c'", letter); 9055 break; 9056 9057 case 'B': 9058 if (GET_CODE (op) == CONST_VECTOR) 9059 { 9060 gcc_assert (mips_const_vector_same_val_p (op, GET_MODE (op))); 9061 op = CONST_VECTOR_ELT (op, 0); 9062 gcc_assert (CONST_INT_P (op)); 9063 unsigned HOST_WIDE_INT val8 = UINTVAL (op) & GET_MODE_MASK (QImode); 9064 fprintf (file, HOST_WIDE_INT_PRINT_UNSIGNED, val8); 9065 } 9066 else 9067 output_operand_lossage ("invalid use of '%%%c'", letter); 9068 break; 9069 9070 case 'm': 9071 if (CONST_INT_P (op)) 9072 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (op) - 1); 9073 else 9074 output_operand_lossage ("invalid use of '%%%c'", letter); 9075 break; 9076 9077 case 'y': 9078 if (CONST_INT_P (op)) 9079 { 9080 int val = exact_log2 (INTVAL (op)); 9081 if (val != -1) 9082 fprintf (file, "%d", val); 9083 else 9084 output_operand_lossage ("invalid use of '%%%c'", letter); 9085 } 9086 else 9087 output_operand_lossage ("invalid use of '%%%c'", letter); 9088 break; 9089 9090 case 'V': 9091 if (GET_CODE (op) == CONST_VECTOR) 9092 { 9093 machine_mode mode = GET_MODE_INNER (GET_MODE (op)); 9094 unsigned HOST_WIDE_INT val = UINTVAL (CONST_VECTOR_ELT (op, 0)); 9095 int vlog2 = exact_log2 (val & GET_MODE_MASK (mode)); 9096 if (vlog2 != -1) 9097 fprintf (file, "%d", vlog2); 9098 else 9099 output_operand_lossage ("invalid use of '%%%c'", letter); 9100 } 9101 else 9102 output_operand_lossage ("invalid use of '%%%c'", letter); 9103 break; 9104 9105 case 'h': 9106 if (code == HIGH) 9107 op = XEXP (op, 0); 9108 mips_print_operand_reloc (file, op, SYMBOL_CONTEXT_LEA, mips_hi_relocs); 9109 break; 9110 9111 case 'R': 9112 mips_print_operand_reloc (file, op, SYMBOL_CONTEXT_LEA, mips_lo_relocs); 9113 break; 9114 9115 case 'C': 9116 mips_print_int_branch_condition (file, code, letter); 9117 break; 9118 9119 case 'N': 9120 mips_print_int_branch_condition (file, reverse_condition (code), letter); 9121 break; 9122 9123 case 'F': 9124 mips_print_float_branch_condition (file, code, letter); 9125 break; 9126 9127 case 'W': 9128 mips_print_float_branch_condition (file, reverse_condition (code), 9129 letter); 9130 break; 9131 9132 case 'T': 9133 case 't': 9134 { 9135 int truth = (code == NE) == (letter == 'T'); 9136 fputc ("zfnt"[truth * 2 + ST_REG_P (REGNO (XEXP (op, 0)))], file); 9137 } 9138 break; 9139 9140 case 'Y': 9141 if (code == CONST_INT && UINTVAL (op) < ARRAY_SIZE (mips_fp_conditions)) 9142 fputs (mips_fp_conditions[UINTVAL (op)], file); 9143 else 9144 output_operand_lossage ("'%%%c' is not a valid operand prefix", 9145 letter); 9146 break; 9147 9148 case 'Z': 9149 if (ISA_HAS_8CC || ISA_HAS_CCF) 9150 { 9151 mips_print_operand (file, op, 0); 9152 fputc (',', file); 9153 } 9154 break; 9155 9156 case 'q': 9157 if (code == REG && MD_REG_P (REGNO (op))) 9158 fprintf (file, "$ac0"); 9159 else if (code == REG && DSP_ACC_REG_P (REGNO (op))) 9160 fprintf (file, "$ac%c", reg_names[REGNO (op)][3]); 9161 else 9162 output_operand_lossage ("invalid use of '%%%c'", letter); 9163 break; 9164 9165 case 'w': 9166 if (code == REG && MSA_REG_P (REGNO (op))) 9167 fprintf (file, "$w%s", ®_names[REGNO (op)][2]); 9168 else 9169 output_operand_lossage ("invalid use of '%%%c'", letter); 9170 break; 9171 9172 case 'v': 9173 switch (GET_MODE (op)) 9174 { 9175 case E_V16QImode: 9176 fprintf (file, "b"); 9177 break; 9178 case E_V8HImode: 9179 fprintf (file, "h"); 9180 break; 9181 case E_V4SImode: 9182 case E_V4SFmode: 9183 fprintf (file, "w"); 9184 break; 9185 case E_V2DImode: 9186 case E_V2DFmode: 9187 fprintf (file, "d"); 9188 break; 9189 default: 9190 output_operand_lossage ("invalid use of '%%%c'", letter); 9191 } 9192 break; 9193 9194 default: 9195 switch (code) 9196 { 9197 case REG: 9198 { 9199 unsigned int regno = REGNO (op); 9200 if ((letter == 'M' && TARGET_LITTLE_ENDIAN) 9201 || (letter == 'L' && TARGET_BIG_ENDIAN) 9202 || letter == 'D') 9203 regno++; 9204 else if (letter && letter != 'z' && letter != 'M' && letter != 'L') 9205 output_operand_lossage ("invalid use of '%%%c'", letter); 9206 /* We need to print $0 .. $31 for COP0 registers. */ 9207 if (COP0_REG_P (regno)) 9208 fprintf (file, "$%s", ®_names[regno][4]); 9209 else 9210 fprintf (file, "%s", reg_names[regno]); 9211 } 9212 break; 9213 9214 case MEM: 9215 if (letter == 'D') 9216 output_address (GET_MODE (op), plus_constant (Pmode, 9217 XEXP (op, 0), 4)); 9218 else if (letter == 'b') 9219 { 9220 gcc_assert (REG_P (XEXP (op, 0))); 9221 mips_print_operand (file, XEXP (op, 0), 0); 9222 } 9223 else if (letter && letter != 'z') 9224 output_operand_lossage ("invalid use of '%%%c'", letter); 9225 else 9226 output_address (GET_MODE (op), XEXP (op, 0)); 9227 break; 9228 9229 default: 9230 if (letter == 'z' && op == CONST0_RTX (GET_MODE (op))) 9231 fputs (reg_names[GP_REG_FIRST], file); 9232 else if (letter && letter != 'z') 9233 output_operand_lossage ("invalid use of '%%%c'", letter); 9234 else if (CONST_GP_P (op)) 9235 fputs (reg_names[GLOBAL_POINTER_REGNUM], file); 9236 else 9237 output_addr_const (file, mips_strip_unspec_address (op)); 9238 break; 9239 } 9240 } 9241 } 9242 9243 /* Implement TARGET_PRINT_OPERAND_ADDRESS. */ 9244 9245 static void 9246 mips_print_operand_address (FILE *file, machine_mode /*mode*/, rtx x) 9247 { 9248 struct mips_address_info addr; 9249 9250 if (mips_classify_address (&addr, x, word_mode, true)) 9251 switch (addr.type) 9252 { 9253 case ADDRESS_REG: 9254 mips_print_operand (file, addr.offset, 0); 9255 fprintf (file, "(%s)", reg_names[REGNO (addr.reg)]); 9256 return; 9257 9258 case ADDRESS_LO_SUM: 9259 mips_print_operand_reloc (file, addr.offset, SYMBOL_CONTEXT_MEM, 9260 mips_lo_relocs); 9261 fprintf (file, "(%s)", reg_names[REGNO (addr.reg)]); 9262 return; 9263 9264 case ADDRESS_CONST_INT: 9265 output_addr_const (file, x); 9266 fprintf (file, "(%s)", reg_names[GP_REG_FIRST]); 9267 return; 9268 9269 case ADDRESS_SYMBOLIC: 9270 output_addr_const (file, mips_strip_unspec_address (x)); 9271 return; 9272 } 9273 gcc_unreachable (); 9274 } 9275 9276 /* Implement TARGET_ENCODE_SECTION_INFO. */ 9277 9278 static void 9279 mips_encode_section_info (tree decl, rtx rtl, int first) 9280 { 9281 default_encode_section_info (decl, rtl, first); 9282 9283 if (TREE_CODE (decl) == FUNCTION_DECL) 9284 { 9285 rtx symbol = XEXP (rtl, 0); 9286 tree type = TREE_TYPE (decl); 9287 9288 /* Encode whether the symbol is short or long. */ 9289 if ((TARGET_LONG_CALLS && !mips_near_type_p (type)) 9290 || mips_far_type_p (type)) 9291 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LONG_CALL; 9292 } 9293 } 9294 9295 /* Implement TARGET_SELECT_RTX_SECTION. */ 9296 9297 static section * 9298 mips_select_rtx_section (machine_mode mode, rtx x, 9299 unsigned HOST_WIDE_INT align) 9300 { 9301 /* ??? Consider using mergeable small data sections. */ 9302 if (mips_rtx_constant_in_small_data_p (mode)) 9303 return get_named_section (NULL, ".sdata", 0); 9304 9305 return default_elf_select_rtx_section (mode, x, align); 9306 } 9307 9308 /* Implement TARGET_ASM_FUNCTION_RODATA_SECTION. 9309 9310 The complication here is that, with the combination TARGET_ABICALLS 9311 && !TARGET_ABSOLUTE_ABICALLS && !TARGET_GPWORD, jump tables will use 9312 absolute addresses, and should therefore not be included in the 9313 read-only part of a DSO. Handle such cases by selecting a normal 9314 data section instead of a read-only one. The logic apes that in 9315 default_function_rodata_section. */ 9316 9317 static section * 9318 mips_function_rodata_section (tree decl) 9319 { 9320 if (!TARGET_ABICALLS || TARGET_ABSOLUTE_ABICALLS || TARGET_GPWORD) 9321 return default_function_rodata_section (decl); 9322 9323 if (decl && DECL_SECTION_NAME (decl)) 9324 { 9325 const char *name = DECL_SECTION_NAME (decl); 9326 if (DECL_COMDAT_GROUP (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0) 9327 { 9328 char *rname = ASTRDUP (name); 9329 rname[14] = 'd'; 9330 return get_section (rname, SECTION_LINKONCE | SECTION_WRITE, decl); 9331 } 9332 else if (flag_function_sections 9333 && flag_data_sections 9334 && strncmp (name, ".text.", 6) == 0) 9335 { 9336 char *rname = ASTRDUP (name); 9337 memcpy (rname + 1, "data", 4); 9338 return get_section (rname, SECTION_WRITE, decl); 9339 } 9340 } 9341 return data_section; 9342 } 9343 9344 /* Implement TARGET_IN_SMALL_DATA_P. */ 9345 9346 static bool 9347 mips_in_small_data_p (const_tree decl) 9348 { 9349 unsigned HOST_WIDE_INT size; 9350 9351 if (TREE_CODE (decl) == STRING_CST || TREE_CODE (decl) == FUNCTION_DECL) 9352 return false; 9353 9354 /* We don't yet generate small-data references for -mabicalls 9355 or VxWorks RTP code. See the related -G handling in 9356 mips_option_override. */ 9357 if (TARGET_ABICALLS || TARGET_VXWORKS_RTP) 9358 return false; 9359 9360 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl) != 0) 9361 { 9362 const char *name; 9363 9364 /* Reject anything that isn't in a known small-data section. */ 9365 name = DECL_SECTION_NAME (decl); 9366 if (strcmp (name, ".sdata") != 0 && strcmp (name, ".sbss") != 0) 9367 return false; 9368 9369 /* If a symbol is defined externally, the assembler will use the 9370 usual -G rules when deciding how to implement macros. */ 9371 if (mips_lo_relocs[SYMBOL_GP_RELATIVE] || !DECL_EXTERNAL (decl)) 9372 return true; 9373 } 9374 else if (TARGET_EMBEDDED_DATA) 9375 { 9376 /* Don't put constants into the small data section: we want them 9377 to be in ROM rather than RAM. */ 9378 if (TREE_CODE (decl) != VAR_DECL) 9379 return false; 9380 9381 if (TREE_READONLY (decl) 9382 && !TREE_SIDE_EFFECTS (decl) 9383 && (!DECL_INITIAL (decl) || TREE_CONSTANT (DECL_INITIAL (decl)))) 9384 return false; 9385 } 9386 9387 /* Enforce -mlocal-sdata. */ 9388 if (!TARGET_LOCAL_SDATA && !TREE_PUBLIC (decl)) 9389 return false; 9390 9391 /* Enforce -mextern-sdata. */ 9392 if (!TARGET_EXTERN_SDATA && DECL_P (decl)) 9393 { 9394 if (DECL_EXTERNAL (decl)) 9395 return false; 9396 if (DECL_COMMON (decl) && DECL_INITIAL (decl) == NULL) 9397 return false; 9398 } 9399 9400 /* We have traditionally not treated zero-sized objects as small data, 9401 so this is now effectively part of the ABI. */ 9402 size = int_size_in_bytes (TREE_TYPE (decl)); 9403 return size > 0 && size <= mips_small_data_threshold; 9404 } 9405 9406 /* Implement TARGET_USE_ANCHORS_FOR_SYMBOL_P. We don't want to use 9407 anchors for small data: the GP register acts as an anchor in that 9408 case. We also don't want to use them for PC-relative accesses, 9409 where the PC acts as an anchor. */ 9410 9411 static bool 9412 mips_use_anchors_for_symbol_p (const_rtx symbol) 9413 { 9414 switch (mips_classify_symbol (symbol, SYMBOL_CONTEXT_MEM)) 9415 { 9416 case SYMBOL_PC_RELATIVE: 9417 case SYMBOL_GP_RELATIVE: 9418 return false; 9419 9420 default: 9421 return default_use_anchors_for_symbol_p (symbol); 9422 } 9423 } 9424 9425 /* The MIPS debug format wants all automatic variables and arguments 9426 to be in terms of the virtual frame pointer (stack pointer before 9427 any adjustment in the function), while the MIPS 3.0 linker wants 9428 the frame pointer to be the stack pointer after the initial 9429 adjustment. So, we do the adjustment here. The arg pointer (which 9430 is eliminated) points to the virtual frame pointer, while the frame 9431 pointer (which may be eliminated) points to the stack pointer after 9432 the initial adjustments. */ 9433 9434 HOST_WIDE_INT 9435 mips_debugger_offset (rtx addr, HOST_WIDE_INT offset) 9436 { 9437 rtx offset2 = const0_rtx; 9438 rtx reg = eliminate_constant_term (addr, &offset2); 9439 9440 if (offset == 0) 9441 offset = INTVAL (offset2); 9442 9443 if (reg == stack_pointer_rtx 9444 || reg == frame_pointer_rtx 9445 || reg == hard_frame_pointer_rtx) 9446 { 9447 offset -= cfun->machine->frame.total_size; 9448 if (reg == hard_frame_pointer_rtx) 9449 offset += cfun->machine->frame.hard_frame_pointer_offset; 9450 } 9451 9452 return offset; 9453 } 9454 9455 /* Implement ASM_OUTPUT_EXTERNAL. */ 9456 9457 void 9458 mips_output_external (FILE *file, tree decl, const char *name) 9459 { 9460 default_elf_asm_output_external (file, decl, name); 9461 9462 /* We output the name if and only if TREE_SYMBOL_REFERENCED is 9463 set in order to avoid putting out names that are never really 9464 used. */ 9465 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))) 9466 { 9467 if (!TARGET_EXPLICIT_RELOCS && mips_in_small_data_p (decl)) 9468 { 9469 /* When using assembler macros, emit .extern directives for 9470 all small-data externs so that the assembler knows how 9471 big they are. 9472 9473 In most cases it would be safe (though pointless) to emit 9474 .externs for other symbols too. One exception is when an 9475 object is within the -G limit but declared by the user to 9476 be in a section other than .sbss or .sdata. */ 9477 fputs ("\t.extern\t", file); 9478 assemble_name (file, name); 9479 fprintf (file, ", " HOST_WIDE_INT_PRINT_DEC "\n", 9480 int_size_in_bytes (TREE_TYPE (decl))); 9481 } 9482 } 9483 } 9484 9485 /* Implement TARGET_ASM_OUTPUT_SOURCE_FILENAME. */ 9486 9487 static void ATTRIBUTE_UNUSED 9488 mips_output_filename (FILE *stream, const char *name) 9489 { 9490 /* If we are emitting DWARF-2, let dwarf2out handle the ".file" 9491 directives. */ 9492 if (write_symbols == DWARF2_DEBUG) 9493 return; 9494 else if (mips_output_filename_first_time) 9495 { 9496 mips_output_filename_first_time = 0; 9497 num_source_filenames += 1; 9498 current_function_file = name; 9499 fprintf (stream, "\t.file\t%d ", num_source_filenames); 9500 output_quoted_string (stream, name); 9501 putc ('\n', stream); 9502 } 9503 /* If we are emitting stabs, let dbxout.c handle this (except for 9504 the mips_output_filename_first_time case). */ 9505 else if (write_symbols == DBX_DEBUG) 9506 return; 9507 else if (name != current_function_file 9508 && strcmp (name, current_function_file) != 0) 9509 { 9510 num_source_filenames += 1; 9511 current_function_file = name; 9512 fprintf (stream, "\t.file\t%d ", num_source_filenames); 9513 output_quoted_string (stream, name); 9514 putc ('\n', stream); 9515 } 9516 } 9517 9518 /* Implement TARGET_ASM_OUTPUT_DWARF_DTPREL. */ 9519 9520 static void ATTRIBUTE_UNUSED 9521 mips_output_dwarf_dtprel (FILE *file, int size, rtx x) 9522 { 9523 switch (size) 9524 { 9525 case 4: 9526 fputs ("\t.dtprelword\t", file); 9527 break; 9528 9529 case 8: 9530 fputs ("\t.dtpreldword\t", file); 9531 break; 9532 9533 default: 9534 gcc_unreachable (); 9535 } 9536 output_addr_const (file, x); 9537 fputs ("+0x8000", file); 9538 } 9539 9540 /* Implement TARGET_DWARF_REGISTER_SPAN. */ 9541 9542 static rtx 9543 mips_dwarf_register_span (rtx reg) 9544 { 9545 rtx high, low; 9546 machine_mode mode; 9547 9548 /* TARGET_FLOATXX is implemented as 32-bit floating-point registers but 9549 ensures that double-precision registers are treated as if they were 9550 64-bit physical registers. The code will run correctly with 32-bit or 9551 64-bit registers which means that dwarf information cannot be precise 9552 for all scenarios. We choose to state that the 64-bit values are stored 9553 in a single 64-bit 'piece'. This slightly unusual construct can then be 9554 interpreted as either a pair of registers if the registers are 32-bit or 9555 a single 64-bit register depending on hardware. */ 9556 mode = GET_MODE (reg); 9557 if (FP_REG_P (REGNO (reg)) 9558 && TARGET_FLOATXX 9559 && GET_MODE_SIZE (mode) > UNITS_PER_FPREG) 9560 { 9561 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, reg)); 9562 } 9563 /* By default, GCC maps increasing register numbers to increasing 9564 memory locations, but paired FPRs are always little-endian, 9565 regardless of the prevailing endianness. */ 9566 else if (FP_REG_P (REGNO (reg)) 9567 && TARGET_BIG_ENDIAN 9568 && MAX_FPRS_PER_FMT > 1 9569 && GET_MODE_SIZE (mode) > UNITS_PER_FPREG) 9570 { 9571 gcc_assert (GET_MODE_SIZE (mode) == UNITS_PER_HWFPVALUE); 9572 high = mips_subword (reg, true); 9573 low = mips_subword (reg, false); 9574 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, high, low)); 9575 } 9576 9577 return NULL_RTX; 9578 } 9579 9580 /* Implement TARGET_DWARF_FRAME_REG_MODE. */ 9581 9582 static machine_mode 9583 mips_dwarf_frame_reg_mode (int regno) 9584 { 9585 machine_mode mode = default_dwarf_frame_reg_mode (regno); 9586 9587 if (FP_REG_P (regno) && mips_abi == ABI_32 && !TARGET_FLOAT32) 9588 mode = SImode; 9589 9590 return mode; 9591 } 9592 9593 /* DSP ALU can bypass data with no delays for the following pairs. */ 9594 enum insn_code dspalu_bypass_table[][2] = 9595 { 9596 {CODE_FOR_mips_addsc, CODE_FOR_mips_addwc}, 9597 {CODE_FOR_mips_cmpu_eq_qb, CODE_FOR_mips_pick_qb}, 9598 {CODE_FOR_mips_cmpu_lt_qb, CODE_FOR_mips_pick_qb}, 9599 {CODE_FOR_mips_cmpu_le_qb, CODE_FOR_mips_pick_qb}, 9600 {CODE_FOR_mips_cmp_eq_ph, CODE_FOR_mips_pick_ph}, 9601 {CODE_FOR_mips_cmp_lt_ph, CODE_FOR_mips_pick_ph}, 9602 {CODE_FOR_mips_cmp_le_ph, CODE_FOR_mips_pick_ph}, 9603 {CODE_FOR_mips_wrdsp, CODE_FOR_mips_insv} 9604 }; 9605 9606 int 9607 mips_dspalu_bypass_p (rtx out_insn, rtx in_insn) 9608 { 9609 int i; 9610 int num_bypass = ARRAY_SIZE (dspalu_bypass_table); 9611 enum insn_code out_icode = (enum insn_code) INSN_CODE (out_insn); 9612 enum insn_code in_icode = (enum insn_code) INSN_CODE (in_insn); 9613 9614 for (i = 0; i < num_bypass; i++) 9615 { 9616 if (out_icode == dspalu_bypass_table[i][0] 9617 && in_icode == dspalu_bypass_table[i][1]) 9618 return true; 9619 } 9620 9621 return false; 9622 } 9623 /* Implement ASM_OUTPUT_ASCII. */ 9624 9625 void 9626 mips_output_ascii (FILE *stream, const char *string, size_t len) 9627 { 9628 size_t i; 9629 int cur_pos; 9630 9631 cur_pos = 17; 9632 fprintf (stream, "\t.ascii\t\""); 9633 for (i = 0; i < len; i++) 9634 { 9635 int c; 9636 9637 c = (unsigned char) string[i]; 9638 if (ISPRINT (c)) 9639 { 9640 if (c == '\\' || c == '\"') 9641 { 9642 putc ('\\', stream); 9643 cur_pos++; 9644 } 9645 putc (c, stream); 9646 cur_pos++; 9647 } 9648 else 9649 { 9650 fprintf (stream, "\\%03o", c); 9651 cur_pos += 4; 9652 } 9653 9654 if (cur_pos > 72 && i+1 < len) 9655 { 9656 cur_pos = 17; 9657 fprintf (stream, "\"\n\t.ascii\t\""); 9658 } 9659 } 9660 fprintf (stream, "\"\n"); 9661 } 9662 9663 /* Return the pseudo-op for full SYMBOL_(D)TPREL address *ADDR. 9664 Update *ADDR with the operand that should be printed. */ 9665 9666 const char * 9667 mips_output_tls_reloc_directive (rtx *addr) 9668 { 9669 enum mips_symbol_type type; 9670 9671 type = mips_classify_symbolic_expression (*addr, SYMBOL_CONTEXT_LEA); 9672 *addr = mips_strip_unspec_address (*addr); 9673 switch (type) 9674 { 9675 case SYMBOL_DTPREL: 9676 return Pmode == SImode ? ".dtprelword\t%0" : ".dtpreldword\t%0"; 9677 9678 case SYMBOL_TPREL: 9679 return Pmode == SImode ? ".tprelword\t%0" : ".tpreldword\t%0"; 9680 9681 default: 9682 gcc_unreachable (); 9683 } 9684 } 9685 9686 /* Emit either a label, .comm, or .lcomm directive. When using assembler 9687 macros, mark the symbol as written so that mips_asm_output_external 9688 won't emit an .extern for it. STREAM is the output file, NAME is the 9689 name of the symbol, INIT_STRING is the string that should be written 9690 before the symbol and FINAL_STRING is the string that should be 9691 written after it. FINAL_STRING is a printf format that consumes the 9692 remaining arguments. */ 9693 9694 void 9695 mips_declare_object (FILE *stream, const char *name, const char *init_string, 9696 const char *final_string, ...) 9697 { 9698 va_list ap; 9699 9700 fputs (init_string, stream); 9701 assemble_name (stream, name); 9702 va_start (ap, final_string); 9703 vfprintf (stream, final_string, ap); 9704 va_end (ap); 9705 9706 if (!TARGET_EXPLICIT_RELOCS) 9707 { 9708 tree name_tree = get_identifier (name); 9709 TREE_ASM_WRITTEN (name_tree) = 1; 9710 } 9711 } 9712 9713 /* Declare a common object of SIZE bytes using asm directive INIT_STRING. 9714 NAME is the name of the object and ALIGN is the required alignment 9715 in bytes. TAKES_ALIGNMENT_P is true if the directive takes a third 9716 alignment argument. */ 9717 9718 void 9719 mips_declare_common_object (FILE *stream, const char *name, 9720 const char *init_string, 9721 unsigned HOST_WIDE_INT size, 9722 unsigned int align, bool takes_alignment_p) 9723 { 9724 if (!takes_alignment_p) 9725 { 9726 size += (align / BITS_PER_UNIT) - 1; 9727 size -= size % (align / BITS_PER_UNIT); 9728 mips_declare_object (stream, name, init_string, 9729 "," HOST_WIDE_INT_PRINT_UNSIGNED "\n", size); 9730 } 9731 else 9732 mips_declare_object (stream, name, init_string, 9733 "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n", 9734 size, align / BITS_PER_UNIT); 9735 } 9736 9737 /* Implement ASM_OUTPUT_ALIGNED_DECL_COMMON. This is usually the same as the 9738 elfos.h version, but we also need to handle -muninit-const-in-rodata. */ 9739 9740 void 9741 mips_output_aligned_decl_common (FILE *stream, tree decl, const char *name, 9742 unsigned HOST_WIDE_INT size, 9743 unsigned int align) 9744 { 9745 /* If the target wants uninitialized const declarations in 9746 .rdata then don't put them in .comm. */ 9747 if (TARGET_EMBEDDED_DATA 9748 && TARGET_UNINIT_CONST_IN_RODATA 9749 && TREE_CODE (decl) == VAR_DECL 9750 && TREE_READONLY (decl) 9751 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)) 9752 { 9753 if (TREE_PUBLIC (decl) && DECL_NAME (decl)) 9754 targetm.asm_out.globalize_label (stream, name); 9755 9756 switch_to_section (readonly_data_section); 9757 ASM_OUTPUT_ALIGN (stream, floor_log2 (align / BITS_PER_UNIT)); 9758 mips_declare_object (stream, name, "", 9759 ":\n\t.space\t" HOST_WIDE_INT_PRINT_UNSIGNED "\n", 9760 size); 9761 } 9762 else 9763 mips_declare_common_object (stream, name, "\n\t.comm\t", 9764 size, align, true); 9765 } 9766 9767 #ifdef ASM_OUTPUT_SIZE_DIRECTIVE 9768 extern int size_directive_output; 9769 9770 /* Implement ASM_DECLARE_OBJECT_NAME. This is like most of the standard ELF 9771 definitions except that it uses mips_declare_object to emit the label. */ 9772 9773 void 9774 mips_declare_object_name (FILE *stream, const char *name, 9775 tree decl ATTRIBUTE_UNUSED) 9776 { 9777 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE 9778 #ifdef USE_GNU_UNIQUE_OBJECT 9779 /* As in elfos.h. */ 9780 if (USE_GNU_UNIQUE_OBJECT && DECL_ONE_ONLY (decl) 9781 && (!DECL_ARTIFICIAL (decl) || !TREE_READONLY (decl))) 9782 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "gnu_unique_object"); 9783 else 9784 #endif 9785 ASM_OUTPUT_TYPE_DIRECTIVE (stream, name, "object"); 9786 #endif 9787 9788 size_directive_output = 0; 9789 if (!flag_inhibit_size_directive && DECL_SIZE (decl)) 9790 { 9791 HOST_WIDE_INT size; 9792 9793 size_directive_output = 1; 9794 size = int_size_in_bytes (TREE_TYPE (decl)); 9795 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); 9796 } 9797 9798 mips_declare_object (stream, name, "", ":\n"); 9799 } 9800 9801 /* Implement ASM_FINISH_DECLARE_OBJECT. This is generic ELF stuff. */ 9802 9803 void 9804 mips_finish_declare_object (FILE *stream, tree decl, int top_level, int at_end) 9805 { 9806 const char *name; 9807 9808 name = XSTR (XEXP (DECL_RTL (decl), 0), 0); 9809 if (!flag_inhibit_size_directive 9810 && DECL_SIZE (decl) != 0 9811 && !at_end 9812 && top_level 9813 && DECL_INITIAL (decl) == error_mark_node 9814 && !size_directive_output) 9815 { 9816 HOST_WIDE_INT size; 9817 9818 size_directive_output = 1; 9819 size = int_size_in_bytes (TREE_TYPE (decl)); 9820 ASM_OUTPUT_SIZE_DIRECTIVE (stream, name, size); 9821 } 9822 } 9823 #endif 9824 9825 /* Mark text contents as code or data, mainly for the purpose of correct 9826 disassembly. Emit a local symbol and set its type appropriately for 9827 that purpose. Also emit `.insn' if marking contents as code so that 9828 the ISA mode is recorded and any padding that follows is disassembled 9829 as correct instructions. */ 9830 9831 void 9832 mips_set_text_contents_type (FILE *file ATTRIBUTE_UNUSED, 9833 const char *prefix ATTRIBUTE_UNUSED, 9834 unsigned long num ATTRIBUTE_UNUSED, 9835 bool function_p ATTRIBUTE_UNUSED) 9836 { 9837 #ifdef ASM_OUTPUT_TYPE_DIRECTIVE 9838 char buf[(sizeof (num) * 10) / 4 + 2]; 9839 const char *fnname; 9840 char *sname; 9841 rtx symbol; 9842 9843 sprintf (buf, "%lu", num); 9844 symbol = XEXP (DECL_RTL (current_function_decl), 0); 9845 fnname = targetm.strip_name_encoding (XSTR (symbol, 0)); 9846 sname = ACONCAT ((prefix, fnname, "_", buf, NULL)); 9847 9848 ASM_OUTPUT_TYPE_DIRECTIVE (file, sname, function_p ? "function" : "object"); 9849 assemble_name (file, sname); 9850 fputs (":\n", file); 9851 if (function_p) 9852 fputs ("\t.insn\n", file); 9853 #endif 9854 } 9855 9856 /* Return the FOO in the name of the ".mdebug.FOO" section associated 9857 with the current ABI. */ 9858 9859 static const char * 9860 mips_mdebug_abi_name (void) 9861 { 9862 switch (mips_abi) 9863 { 9864 case ABI_32: 9865 return "abi32"; 9866 case ABI_O64: 9867 return "abiO64"; 9868 case ABI_N32: 9869 return "abiN32"; 9870 case ABI_64: 9871 return "abi64"; 9872 case ABI_EABI: 9873 return TARGET_64BIT ? "eabi64" : "eabi32"; 9874 default: 9875 gcc_unreachable (); 9876 } 9877 } 9878 9879 /* Implement TARGET_ASM_FILE_START. */ 9880 9881 static void 9882 mips_file_start (void) 9883 { 9884 default_file_start (); 9885 9886 /* Generate a special section to describe the ABI switches used to 9887 produce the resultant binary. */ 9888 9889 /* Record the ABI itself. Modern versions of binutils encode 9890 this information in the ELF header flags, but GDB needs the 9891 information in order to correctly debug binaries produced by 9892 older binutils. See the function mips_gdbarch_init in 9893 gdb/mips-tdep.c. */ 9894 fprintf (asm_out_file, "\t.section .mdebug.%s\n\t.previous\n", 9895 mips_mdebug_abi_name ()); 9896 9897 /* There is no ELF header flag to distinguish long32 forms of the 9898 EABI from long64 forms. Emit a special section to help tools 9899 such as GDB. Do the same for o64, which is sometimes used with 9900 -mlong64. */ 9901 if (mips_abi == ABI_EABI || mips_abi == ABI_O64) 9902 fprintf (asm_out_file, "\t.section .gcc_compiled_long%d\n" 9903 "\t.previous\n", TARGET_LONG64 ? 64 : 32); 9904 9905 /* Record the NaN encoding. */ 9906 if (HAVE_AS_NAN || mips_nan != MIPS_IEEE_754_DEFAULT) 9907 fprintf (asm_out_file, "\t.nan\t%s\n", 9908 mips_nan == MIPS_IEEE_754_2008 ? "2008" : "legacy"); 9909 9910 #ifdef HAVE_AS_DOT_MODULE 9911 /* Record the FP ABI. See below for comments. */ 9912 if (TARGET_NO_FLOAT) 9913 #ifdef HAVE_AS_GNU_ATTRIBUTE 9914 fputs ("\t.gnu_attribute 4, 0\n", asm_out_file); 9915 #else 9916 ; 9917 #endif 9918 else if (!TARGET_HARD_FLOAT_ABI) 9919 fputs ("\t.module\tsoftfloat\n", asm_out_file); 9920 else if (!TARGET_DOUBLE_FLOAT) 9921 fputs ("\t.module\tsinglefloat\n", asm_out_file); 9922 else if (TARGET_FLOATXX) 9923 fputs ("\t.module\tfp=xx\n", asm_out_file); 9924 else if (TARGET_FLOAT64) 9925 fputs ("\t.module\tfp=64\n", asm_out_file); 9926 else 9927 fputs ("\t.module\tfp=32\n", asm_out_file); 9928 9929 if (TARGET_ODD_SPREG) 9930 fputs ("\t.module\toddspreg\n", asm_out_file); 9931 else 9932 fputs ("\t.module\tnooddspreg\n", asm_out_file); 9933 9934 #else 9935 #ifdef HAVE_AS_GNU_ATTRIBUTE 9936 { 9937 int attr; 9938 9939 /* No floating-point operations, -mno-float. */ 9940 if (TARGET_NO_FLOAT) 9941 attr = 0; 9942 /* Soft-float code, -msoft-float. */ 9943 else if (!TARGET_HARD_FLOAT_ABI) 9944 attr = 3; 9945 /* Single-float code, -msingle-float. */ 9946 else if (!TARGET_DOUBLE_FLOAT) 9947 attr = 2; 9948 /* 64-bit FP registers on a 32-bit target, -mips32r2 -mfp64. 9949 Reserved attr=4. 9950 This case used 12 callee-saved double-precision registers 9951 and is deprecated. */ 9952 /* 64-bit or 32-bit FP registers on a 32-bit target, -mfpxx. */ 9953 else if (TARGET_FLOATXX) 9954 attr = 5; 9955 /* 64-bit FP registers on a 32-bit target, -mfp64 -modd-spreg. */ 9956 else if (mips_abi == ABI_32 && TARGET_FLOAT64 && TARGET_ODD_SPREG) 9957 attr = 6; 9958 /* 64-bit FP registers on a 32-bit target, -mfp64 -mno-odd-spreg. */ 9959 else if (mips_abi == ABI_32 && TARGET_FLOAT64) 9960 attr = 7; 9961 /* Regular FP code, FP regs same size as GP regs, -mdouble-float. */ 9962 else 9963 attr = 1; 9964 9965 fprintf (asm_out_file, "\t.gnu_attribute 4, %d\n", attr); 9966 9967 /* 128-bit MSA. */ 9968 if (ISA_HAS_MSA) 9969 fprintf (asm_out_file, "\t.gnu_attribute 8, 1\n"); 9970 } 9971 #endif 9972 #endif 9973 9974 /* If TARGET_ABICALLS, tell GAS to generate -KPIC code. */ 9975 if (TARGET_ABICALLS) 9976 { 9977 fprintf (asm_out_file, "\t.abicalls\n"); 9978 if (TARGET_ABICALLS_PIC0) 9979 fprintf (asm_out_file, "\t.option\tpic0\n"); 9980 } 9981 9982 if (flag_verbose_asm) 9983 fprintf (asm_out_file, "\n%s -G value = %d, Arch = %s, ISA = %d\n", 9984 ASM_COMMENT_START, 9985 mips_small_data_threshold, mips_arch_info->name, mips_isa); 9986 } 9987 9988 /* Implement TARGET_ASM_CODE_END. */ 9989 9990 static void 9991 mips_code_end (void) 9992 { 9993 mips_finish_stub (&mips16_rdhwr_stub); 9994 mips_finish_stub (&mips16_get_fcsr_stub); 9995 mips_finish_stub (&mips16_set_fcsr_stub); 9996 } 9997 9998 /* Make the last instruction frame-related and note that it performs 9999 the operation described by FRAME_PATTERN. */ 10000 10001 static void 10002 mips_set_frame_expr (rtx frame_pattern) 10003 { 10004 rtx_insn *insn; 10005 10006 insn = get_last_insn (); 10007 RTX_FRAME_RELATED_P (insn) = 1; 10008 REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR, 10009 frame_pattern, 10010 REG_NOTES (insn)); 10011 } 10012 10013 /* Return a frame-related rtx that stores REG at MEM. 10014 REG must be a single register. */ 10015 10016 static rtx 10017 mips_frame_set (rtx mem, rtx reg) 10018 { 10019 rtx set; 10020 10021 set = gen_rtx_SET (mem, reg); 10022 RTX_FRAME_RELATED_P (set) = 1; 10023 10024 return set; 10025 } 10026 10027 /* Record that the epilogue has restored call-saved register REG. */ 10028 10029 static void 10030 mips_add_cfa_restore (rtx reg) 10031 { 10032 mips_epilogue.cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, 10033 mips_epilogue.cfa_restores); 10034 } 10035 10036 /* If a MIPS16e SAVE or RESTORE instruction saves or restores register 10037 mips16e_s2_s8_regs[X], it must also save the registers in indexes 10038 X + 1 onwards. Likewise mips16e_a0_a3_regs. */ 10039 static const unsigned char mips16e_s2_s8_regs[] = { 10040 30, 23, 22, 21, 20, 19, 18 10041 }; 10042 static const unsigned char mips16e_a0_a3_regs[] = { 10043 4, 5, 6, 7 10044 }; 10045 10046 /* A list of the registers that can be saved by the MIPS16e SAVE instruction, 10047 ordered from the uppermost in memory to the lowest in memory. */ 10048 static const unsigned char mips16e_save_restore_regs[] = { 10049 31, 30, 23, 22, 21, 20, 19, 18, 17, 16, 7, 6, 5, 4 10050 }; 10051 10052 /* Return the index of the lowest X in the range [0, SIZE) for which 10053 bit REGS[X] is set in MASK. Return SIZE if there is no such X. */ 10054 10055 static unsigned int 10056 mips16e_find_first_register (unsigned int mask, const unsigned char *regs, 10057 unsigned int size) 10058 { 10059 unsigned int i; 10060 10061 for (i = 0; i < size; i++) 10062 if (BITSET_P (mask, regs[i])) 10063 break; 10064 10065 return i; 10066 } 10067 10068 /* *MASK_PTR is a mask of general-purpose registers and *NUM_REGS_PTR 10069 is the number of set bits. If *MASK_PTR contains REGS[X] for some X 10070 in [0, SIZE), adjust *MASK_PTR and *NUM_REGS_PTR so that the same 10071 is true for all indexes (X, SIZE). */ 10072 10073 static void 10074 mips16e_mask_registers (unsigned int *mask_ptr, const unsigned char *regs, 10075 unsigned int size, unsigned int *num_regs_ptr) 10076 { 10077 unsigned int i; 10078 10079 i = mips16e_find_first_register (*mask_ptr, regs, size); 10080 for (i++; i < size; i++) 10081 if (!BITSET_P (*mask_ptr, regs[i])) 10082 { 10083 *num_regs_ptr += 1; 10084 *mask_ptr |= 1 << regs[i]; 10085 } 10086 } 10087 10088 /* Return a simplified form of X using the register values in REG_VALUES. 10089 REG_VALUES[R] is the last value assigned to hard register R, or null 10090 if R has not been modified. 10091 10092 This function is rather limited, but is good enough for our purposes. */ 10093 10094 static rtx 10095 mips16e_collect_propagate_value (rtx x, rtx *reg_values) 10096 { 10097 x = avoid_constant_pool_reference (x); 10098 10099 if (UNARY_P (x)) 10100 { 10101 rtx x0 = mips16e_collect_propagate_value (XEXP (x, 0), reg_values); 10102 return simplify_gen_unary (GET_CODE (x), GET_MODE (x), 10103 x0, GET_MODE (XEXP (x, 0))); 10104 } 10105 10106 if (ARITHMETIC_P (x)) 10107 { 10108 rtx x0 = mips16e_collect_propagate_value (XEXP (x, 0), reg_values); 10109 rtx x1 = mips16e_collect_propagate_value (XEXP (x, 1), reg_values); 10110 return simplify_gen_binary (GET_CODE (x), GET_MODE (x), x0, x1); 10111 } 10112 10113 if (REG_P (x) 10114 && reg_values[REGNO (x)] 10115 && !rtx_unstable_p (reg_values[REGNO (x)])) 10116 return reg_values[REGNO (x)]; 10117 10118 return x; 10119 } 10120 10121 /* Return true if (set DEST SRC) stores an argument register into its 10122 caller-allocated save slot, storing the number of that argument 10123 register in *REGNO_PTR if so. REG_VALUES is as for 10124 mips16e_collect_propagate_value. */ 10125 10126 static bool 10127 mips16e_collect_argument_save_p (rtx dest, rtx src, rtx *reg_values, 10128 unsigned int *regno_ptr) 10129 { 10130 unsigned int argno, regno; 10131 HOST_WIDE_INT offset, required_offset; 10132 rtx addr, base; 10133 10134 /* Check that this is a word-mode store. */ 10135 if (!MEM_P (dest) || !REG_P (src) || GET_MODE (dest) != word_mode) 10136 return false; 10137 10138 /* Check that the register being saved is an unmodified argument 10139 register. */ 10140 regno = REGNO (src); 10141 if (!IN_RANGE (regno, GP_ARG_FIRST, GP_ARG_LAST) || reg_values[regno]) 10142 return false; 10143 argno = regno - GP_ARG_FIRST; 10144 10145 /* Check whether the address is an appropriate stack-pointer or 10146 frame-pointer access. */ 10147 addr = mips16e_collect_propagate_value (XEXP (dest, 0), reg_values); 10148 mips_split_plus (addr, &base, &offset); 10149 required_offset = cfun->machine->frame.total_size + argno * UNITS_PER_WORD; 10150 if (base == hard_frame_pointer_rtx) 10151 required_offset -= cfun->machine->frame.hard_frame_pointer_offset; 10152 else if (base != stack_pointer_rtx) 10153 return false; 10154 if (offset != required_offset) 10155 return false; 10156 10157 *regno_ptr = regno; 10158 return true; 10159 } 10160 10161 /* A subroutine of mips_expand_prologue, called only when generating 10162 MIPS16e SAVE instructions. Search the start of the function for any 10163 instructions that save argument registers into their caller-allocated 10164 save slots. Delete such instructions and return a value N such that 10165 saving [GP_ARG_FIRST, GP_ARG_FIRST + N) would make all the deleted 10166 instructions redundant. */ 10167 10168 static unsigned int 10169 mips16e_collect_argument_saves (void) 10170 { 10171 rtx reg_values[FIRST_PSEUDO_REGISTER]; 10172 rtx_insn *insn, *next; 10173 rtx set, dest, src; 10174 unsigned int nargs, regno; 10175 10176 push_topmost_sequence (); 10177 nargs = 0; 10178 memset (reg_values, 0, sizeof (reg_values)); 10179 for (insn = get_insns (); insn; insn = next) 10180 { 10181 next = NEXT_INSN (insn); 10182 if (NOTE_P (insn) || DEBUG_INSN_P (insn)) 10183 continue; 10184 10185 if (!INSN_P (insn)) 10186 break; 10187 10188 set = PATTERN (insn); 10189 if (GET_CODE (set) != SET) 10190 break; 10191 10192 dest = SET_DEST (set); 10193 src = SET_SRC (set); 10194 if (mips16e_collect_argument_save_p (dest, src, reg_values, ®no)) 10195 { 10196 if (!BITSET_P (cfun->machine->frame.mask, regno)) 10197 { 10198 delete_insn (insn); 10199 nargs = MAX (nargs, (regno - GP_ARG_FIRST) + 1); 10200 } 10201 } 10202 else if (REG_P (dest) && GET_MODE (dest) == word_mode) 10203 reg_values[REGNO (dest)] 10204 = mips16e_collect_propagate_value (src, reg_values); 10205 else 10206 break; 10207 } 10208 pop_topmost_sequence (); 10209 10210 return nargs; 10211 } 10212 10213 /* Return a move between register REGNO and memory location SP + OFFSET. 10214 REG_PARM_P is true if SP + OFFSET belongs to REG_PARM_STACK_SPACE. 10215 Make the move a load if RESTORE_P, otherwise make it a store. */ 10216 10217 static rtx 10218 mips16e_save_restore_reg (bool restore_p, bool reg_parm_p, 10219 HOST_WIDE_INT offset, unsigned int regno) 10220 { 10221 rtx reg, mem; 10222 10223 mem = gen_frame_mem (SImode, plus_constant (Pmode, stack_pointer_rtx, 10224 offset)); 10225 reg = gen_rtx_REG (SImode, regno); 10226 if (restore_p) 10227 { 10228 mips_add_cfa_restore (reg); 10229 return gen_rtx_SET (reg, mem); 10230 } 10231 if (reg_parm_p) 10232 return gen_rtx_SET (mem, reg); 10233 return mips_frame_set (mem, reg); 10234 } 10235 10236 /* Return RTL for a MIPS16e SAVE or RESTORE instruction; RESTORE_P says which. 10237 The instruction must: 10238 10239 - Allocate or deallocate SIZE bytes in total; SIZE is known 10240 to be nonzero. 10241 10242 - Save or restore as many registers in *MASK_PTR as possible. 10243 The instruction saves the first registers at the top of the 10244 allocated area, with the other registers below it. 10245 10246 - Save NARGS argument registers above the allocated area. 10247 10248 (NARGS is always zero if RESTORE_P.) 10249 10250 The SAVE and RESTORE instructions cannot save and restore all general 10251 registers, so there may be some registers left over for the caller to 10252 handle. Destructively modify *MASK_PTR so that it contains the registers 10253 that still need to be saved or restored. The caller can save these 10254 registers in the memory immediately below *OFFSET_PTR, which is a 10255 byte offset from the bottom of the allocated stack area. */ 10256 10257 static rtx 10258 mips16e_build_save_restore (bool restore_p, unsigned int *mask_ptr, 10259 HOST_WIDE_INT *offset_ptr, unsigned int nargs, 10260 HOST_WIDE_INT size) 10261 { 10262 rtx pattern, set; 10263 HOST_WIDE_INT offset, top_offset; 10264 unsigned int i, regno; 10265 int n; 10266 10267 gcc_assert (cfun->machine->frame.num_fp == 0); 10268 10269 /* Calculate the number of elements in the PARALLEL. We need one element 10270 for the stack adjustment, one for each argument register save, and one 10271 for each additional register move. */ 10272 n = 1 + nargs; 10273 for (i = 0; i < ARRAY_SIZE (mips16e_save_restore_regs); i++) 10274 if (BITSET_P (*mask_ptr, mips16e_save_restore_regs[i])) 10275 n++; 10276 10277 /* Create the final PARALLEL. */ 10278 pattern = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (n)); 10279 n = 0; 10280 10281 /* Add the stack pointer adjustment. */ 10282 set = gen_rtx_SET (stack_pointer_rtx, 10283 plus_constant (Pmode, stack_pointer_rtx, 10284 restore_p ? size : -size)); 10285 RTX_FRAME_RELATED_P (set) = 1; 10286 XVECEXP (pattern, 0, n++) = set; 10287 10288 /* Stack offsets in the PARALLEL are relative to the old stack pointer. */ 10289 top_offset = restore_p ? size : 0; 10290 10291 /* Save the arguments. */ 10292 for (i = 0; i < nargs; i++) 10293 { 10294 offset = top_offset + i * UNITS_PER_WORD; 10295 set = mips16e_save_restore_reg (restore_p, true, offset, 10296 GP_ARG_FIRST + i); 10297 XVECEXP (pattern, 0, n++) = set; 10298 } 10299 10300 /* Then fill in the other register moves. */ 10301 offset = top_offset; 10302 for (i = 0; i < ARRAY_SIZE (mips16e_save_restore_regs); i++) 10303 { 10304 regno = mips16e_save_restore_regs[i]; 10305 if (BITSET_P (*mask_ptr, regno)) 10306 { 10307 offset -= UNITS_PER_WORD; 10308 set = mips16e_save_restore_reg (restore_p, false, offset, regno); 10309 XVECEXP (pattern, 0, n++) = set; 10310 *mask_ptr &= ~(1 << regno); 10311 } 10312 } 10313 10314 /* Tell the caller what offset it should use for the remaining registers. */ 10315 *offset_ptr = size + (offset - top_offset); 10316 10317 gcc_assert (n == XVECLEN (pattern, 0)); 10318 10319 return pattern; 10320 } 10321 10322 /* PATTERN is a PARALLEL whose first element adds ADJUST to the stack 10323 pointer. Return true if PATTERN matches the kind of instruction 10324 generated by mips16e_build_save_restore. If INFO is nonnull, 10325 initialize it when returning true. */ 10326 10327 bool 10328 mips16e_save_restore_pattern_p (rtx pattern, HOST_WIDE_INT adjust, 10329 struct mips16e_save_restore_info *info) 10330 { 10331 unsigned int i, nargs, mask, extra; 10332 HOST_WIDE_INT top_offset, save_offset, offset; 10333 rtx set, reg, mem, base; 10334 int n; 10335 10336 if (!GENERATE_MIPS16E_SAVE_RESTORE) 10337 return false; 10338 10339 /* Stack offsets in the PARALLEL are relative to the old stack pointer. */ 10340 top_offset = adjust > 0 ? adjust : 0; 10341 10342 /* Interpret all other members of the PARALLEL. */ 10343 save_offset = top_offset - UNITS_PER_WORD; 10344 mask = 0; 10345 nargs = 0; 10346 i = 0; 10347 for (n = 1; n < XVECLEN (pattern, 0); n++) 10348 { 10349 /* Check that we have a SET. */ 10350 set = XVECEXP (pattern, 0, n); 10351 if (GET_CODE (set) != SET) 10352 return false; 10353 10354 /* Check that the SET is a load (if restoring) or a store 10355 (if saving). */ 10356 mem = adjust > 0 ? SET_SRC (set) : SET_DEST (set); 10357 if (!MEM_P (mem)) 10358 return false; 10359 10360 /* Check that the address is the sum of the stack pointer and a 10361 possibly-zero constant offset. */ 10362 mips_split_plus (XEXP (mem, 0), &base, &offset); 10363 if (base != stack_pointer_rtx) 10364 return false; 10365 10366 /* Check that SET's other operand is a register. */ 10367 reg = adjust > 0 ? SET_DEST (set) : SET_SRC (set); 10368 if (!REG_P (reg)) 10369 return false; 10370 10371 /* Check for argument saves. */ 10372 if (offset == top_offset + nargs * UNITS_PER_WORD 10373 && REGNO (reg) == GP_ARG_FIRST + nargs) 10374 nargs++; 10375 else if (offset == save_offset) 10376 { 10377 while (mips16e_save_restore_regs[i++] != REGNO (reg)) 10378 if (i == ARRAY_SIZE (mips16e_save_restore_regs)) 10379 return false; 10380 10381 mask |= 1 << REGNO (reg); 10382 save_offset -= UNITS_PER_WORD; 10383 } 10384 else 10385 return false; 10386 } 10387 10388 /* Check that the restrictions on register ranges are met. */ 10389 extra = 0; 10390 mips16e_mask_registers (&mask, mips16e_s2_s8_regs, 10391 ARRAY_SIZE (mips16e_s2_s8_regs), &extra); 10392 mips16e_mask_registers (&mask, mips16e_a0_a3_regs, 10393 ARRAY_SIZE (mips16e_a0_a3_regs), &extra); 10394 if (extra != 0) 10395 return false; 10396 10397 /* Make sure that the topmost argument register is not saved twice. 10398 The checks above ensure that the same is then true for the other 10399 argument registers. */ 10400 if (nargs > 0 && BITSET_P (mask, GP_ARG_FIRST + nargs - 1)) 10401 return false; 10402 10403 /* Pass back information, if requested. */ 10404 if (info) 10405 { 10406 info->nargs = nargs; 10407 info->mask = mask; 10408 info->size = (adjust > 0 ? adjust : -adjust); 10409 } 10410 10411 return true; 10412 } 10413 10414 /* Add a MIPS16e SAVE or RESTORE register-range argument to string S 10415 for the register range [MIN_REG, MAX_REG]. Return a pointer to 10416 the null terminator. */ 10417 10418 static char * 10419 mips16e_add_register_range (char *s, unsigned int min_reg, 10420 unsigned int max_reg) 10421 { 10422 if (min_reg != max_reg) 10423 s += sprintf (s, ",%s-%s", reg_names[min_reg], reg_names[max_reg]); 10424 else 10425 s += sprintf (s, ",%s", reg_names[min_reg]); 10426 return s; 10427 } 10428 10429 /* Return the assembly instruction for a MIPS16e SAVE or RESTORE instruction. 10430 PATTERN and ADJUST are as for mips16e_save_restore_pattern_p. */ 10431 10432 const char * 10433 mips16e_output_save_restore (rtx pattern, HOST_WIDE_INT adjust) 10434 { 10435 static char buffer[300]; 10436 10437 struct mips16e_save_restore_info info; 10438 unsigned int i, end; 10439 char *s; 10440 10441 /* Parse the pattern. */ 10442 if (!mips16e_save_restore_pattern_p (pattern, adjust, &info)) 10443 gcc_unreachable (); 10444 10445 /* Add the mnemonic. */ 10446 s = strcpy (buffer, adjust > 0 ? "restore\t" : "save\t"); 10447 s += strlen (s); 10448 10449 /* Save the arguments. */ 10450 if (info.nargs > 1) 10451 s += sprintf (s, "%s-%s,", reg_names[GP_ARG_FIRST], 10452 reg_names[GP_ARG_FIRST + info.nargs - 1]); 10453 else if (info.nargs == 1) 10454 s += sprintf (s, "%s,", reg_names[GP_ARG_FIRST]); 10455 10456 /* Emit the amount of stack space to allocate or deallocate. */ 10457 s += sprintf (s, "%d", (int) info.size); 10458 10459 /* Save or restore $16. */ 10460 if (BITSET_P (info.mask, 16)) 10461 s += sprintf (s, ",%s", reg_names[GP_REG_FIRST + 16]); 10462 10463 /* Save or restore $17. */ 10464 if (BITSET_P (info.mask, 17)) 10465 s += sprintf (s, ",%s", reg_names[GP_REG_FIRST + 17]); 10466 10467 /* Save or restore registers in the range $s2...$s8, which 10468 mips16e_s2_s8_regs lists in decreasing order. Note that this 10469 is a software register range; the hardware registers are not 10470 numbered consecutively. */ 10471 end = ARRAY_SIZE (mips16e_s2_s8_regs); 10472 i = mips16e_find_first_register (info.mask, mips16e_s2_s8_regs, end); 10473 if (i < end) 10474 s = mips16e_add_register_range (s, mips16e_s2_s8_regs[end - 1], 10475 mips16e_s2_s8_regs[i]); 10476 10477 /* Save or restore registers in the range $a0...$a3. */ 10478 end = ARRAY_SIZE (mips16e_a0_a3_regs); 10479 i = mips16e_find_first_register (info.mask, mips16e_a0_a3_regs, end); 10480 if (i < end) 10481 s = mips16e_add_register_range (s, mips16e_a0_a3_regs[i], 10482 mips16e_a0_a3_regs[end - 1]); 10483 10484 /* Save or restore $31. */ 10485 if (BITSET_P (info.mask, RETURN_ADDR_REGNUM)) 10486 s += sprintf (s, ",%s", reg_names[RETURN_ADDR_REGNUM]); 10487 10488 return buffer; 10489 } 10490 10491 /* Return true if the current function returns its value in a floating-point 10492 register in MIPS16 mode. */ 10493 10494 static bool 10495 mips16_cfun_returns_in_fpr_p (void) 10496 { 10497 tree return_type = DECL_RESULT (current_function_decl); 10498 return (TARGET_MIPS16 10499 && TARGET_HARD_FLOAT_ABI 10500 && !aggregate_value_p (return_type, current_function_decl) 10501 && mips_return_mode_in_fpr_p (DECL_MODE (return_type))); 10502 } 10503 10504 /* Return true if predicate PRED is true for at least one instruction. 10505 Cache the result in *CACHE, and assume that the result is true 10506 if *CACHE is already true. */ 10507 10508 static bool 10509 mips_find_gp_ref (bool *cache, bool (*pred) (rtx_insn *)) 10510 { 10511 rtx_insn *insn, *subinsn; 10512 10513 if (!*cache) 10514 { 10515 push_topmost_sequence (); 10516 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 10517 FOR_EACH_SUBINSN (subinsn, insn) 10518 if (USEFUL_INSN_P (subinsn) && pred (subinsn)) 10519 { 10520 *cache = true; 10521 break; 10522 } 10523 pop_topmost_sequence (); 10524 } 10525 return *cache; 10526 } 10527 10528 /* Return true if INSN refers to the global pointer in an "inflexible" way. 10529 See mips_cfun_has_inflexible_gp_ref_p for details. */ 10530 10531 static bool 10532 mips_insn_has_inflexible_gp_ref_p (rtx_insn *insn) 10533 { 10534 /* Uses of pic_offset_table_rtx in CALL_INSN_FUNCTION_USAGE 10535 indicate that the target could be a traditional MIPS 10536 lazily-binding stub. */ 10537 return find_reg_fusage (insn, USE, pic_offset_table_rtx); 10538 } 10539 10540 /* Return true if the current function refers to the global pointer 10541 in a way that forces $28 to be valid. This means that we can't 10542 change the choice of global pointer, even for NewABI code. 10543 10544 One example of this (and one which needs several checks) is that 10545 $28 must be valid when calling traditional MIPS lazy-binding stubs. 10546 (This restriction does not apply to PLTs.) */ 10547 10548 static bool 10549 mips_cfun_has_inflexible_gp_ref_p (void) 10550 { 10551 /* If the function has a nonlocal goto, $28 must hold the correct 10552 global pointer for the target function. That is, the target 10553 of the goto implicitly uses $28. */ 10554 if (crtl->has_nonlocal_goto) 10555 return true; 10556 10557 if (TARGET_ABICALLS_PIC2) 10558 { 10559 /* Symbolic accesses implicitly use the global pointer unless 10560 -mexplicit-relocs is in effect. JAL macros to symbolic addresses 10561 might go to traditional MIPS lazy-binding stubs. */ 10562 if (!TARGET_EXPLICIT_RELOCS) 10563 return true; 10564 10565 /* FUNCTION_PROFILER includes a JAL to _mcount, which again 10566 can be lazily-bound. */ 10567 if (crtl->profile) 10568 return true; 10569 10570 /* MIPS16 functions that return in FPRs need to call an 10571 external libgcc routine. This call is only made explict 10572 during mips_expand_epilogue, and it too might be lazily bound. */ 10573 if (mips16_cfun_returns_in_fpr_p ()) 10574 return true; 10575 } 10576 10577 return mips_find_gp_ref (&cfun->machine->has_inflexible_gp_insn_p, 10578 mips_insn_has_inflexible_gp_ref_p); 10579 } 10580 10581 /* Return true if INSN refers to the global pointer in a "flexible" way. 10582 See mips_cfun_has_flexible_gp_ref_p for details. */ 10583 10584 static bool 10585 mips_insn_has_flexible_gp_ref_p (rtx_insn *insn) 10586 { 10587 return (get_attr_got (insn) != GOT_UNSET 10588 || mips_small_data_pattern_p (PATTERN (insn)) 10589 || reg_overlap_mentioned_p (pic_offset_table_rtx, PATTERN (insn))); 10590 } 10591 10592 /* Return true if the current function references the global pointer, 10593 but if those references do not inherently require the global pointer 10594 to be $28. Assume !mips_cfun_has_inflexible_gp_ref_p (). */ 10595 10596 static bool 10597 mips_cfun_has_flexible_gp_ref_p (void) 10598 { 10599 /* Reload can sometimes introduce constant pool references 10600 into a function that otherwise didn't need them. For example, 10601 suppose we have an instruction like: 10602 10603 (set (reg:DF R1) (float:DF (reg:SI R2))) 10604 10605 If R2 turns out to be a constant such as 1, the instruction may 10606 have a REG_EQUAL note saying that R1 == 1.0. Reload then has 10607 the option of using this constant if R2 doesn't get allocated 10608 to a register. 10609 10610 In cases like these, reload will have added the constant to the 10611 pool but no instruction will yet refer to it. */ 10612 if (TARGET_ABICALLS_PIC2 && !reload_completed && crtl->uses_const_pool) 10613 return true; 10614 10615 return mips_find_gp_ref (&cfun->machine->has_flexible_gp_insn_p, 10616 mips_insn_has_flexible_gp_ref_p); 10617 } 10618 10619 /* Return the register that should be used as the global pointer 10620 within this function. Return INVALID_REGNUM if the function 10621 doesn't need a global pointer. */ 10622 10623 static unsigned int 10624 mips_global_pointer (void) 10625 { 10626 unsigned int regno; 10627 10628 /* $gp is always available unless we're using a GOT. */ 10629 if (!TARGET_USE_GOT) 10630 return GLOBAL_POINTER_REGNUM; 10631 10632 /* If there are inflexible references to $gp, we must use the 10633 standard register. */ 10634 if (mips_cfun_has_inflexible_gp_ref_p ()) 10635 return GLOBAL_POINTER_REGNUM; 10636 10637 /* If there are no current references to $gp, then the only uses 10638 we can introduce later are those involved in long branches. */ 10639 if (TARGET_ABSOLUTE_JUMPS && !mips_cfun_has_flexible_gp_ref_p ()) 10640 return INVALID_REGNUM; 10641 10642 /* If the global pointer is call-saved, try to use a call-clobbered 10643 alternative. */ 10644 if (TARGET_CALL_SAVED_GP && crtl->is_leaf) 10645 for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++) 10646 if (!df_regs_ever_live_p (regno) 10647 && call_used_regs[regno] 10648 && !fixed_regs[regno] 10649 && regno != PIC_FUNCTION_ADDR_REGNUM) 10650 return regno; 10651 10652 return GLOBAL_POINTER_REGNUM; 10653 } 10654 10655 /* Return true if the current function's prologue must load the global 10656 pointer value into pic_offset_table_rtx and store the same value in 10657 the function's cprestore slot (if any). 10658 10659 One problem we have to deal with is that, when emitting GOT-based 10660 position independent code, long-branch sequences will need to load 10661 the address of the branch target from the GOT. We don't know until 10662 the very end of compilation whether (and where) the function needs 10663 long branches, so we must ensure that _any_ branch can access the 10664 global pointer in some form. However, we do not want to pessimize 10665 the usual case in which all branches are short. 10666 10667 We handle this as follows: 10668 10669 (1) During reload, we set cfun->machine->global_pointer to 10670 INVALID_REGNUM if we _know_ that the current function 10671 doesn't need a global pointer. This is only valid if 10672 long branches don't need the GOT. 10673 10674 Otherwise, we assume that we might need a global pointer 10675 and pick an appropriate register. 10676 10677 (2) If cfun->machine->global_pointer != INVALID_REGNUM, 10678 we ensure that the global pointer is available at every 10679 block boundary bar entry and exit. We do this in one of two ways: 10680 10681 - If the function has a cprestore slot, we ensure that this 10682 slot is valid at every branch. However, as explained in 10683 point (6) below, there is no guarantee that pic_offset_table_rtx 10684 itself is valid if new uses of the global pointer are introduced 10685 after the first post-epilogue split. 10686 10687 We guarantee that the cprestore slot is valid by loading it 10688 into a fake register, CPRESTORE_SLOT_REGNUM. We then make 10689 this register live at every block boundary bar function entry 10690 and exit. It is then invalid to move the load (and thus the 10691 preceding store) across a block boundary. 10692 10693 - If the function has no cprestore slot, we guarantee that 10694 pic_offset_table_rtx itself is valid at every branch. 10695 10696 See mips_eh_uses for the handling of the register liveness. 10697 10698 (3) During prologue and epilogue generation, we emit "ghost" 10699 placeholder instructions to manipulate the global pointer. 10700 10701 (4) During prologue generation, we set cfun->machine->must_initialize_gp_p 10702 and cfun->machine->must_restore_gp_when_clobbered_p if we already know 10703 that the function needs a global pointer. (There is no need to set 10704 them earlier than this, and doing it as late as possible leads to 10705 fewer false positives.) 10706 10707 (5) If cfun->machine->must_initialize_gp_p is true during a 10708 split_insns pass, we split the ghost instructions into real 10709 instructions. These split instructions can then be optimized in 10710 the usual way. Otherwise, we keep the ghost instructions intact, 10711 and optimize for the case where they aren't needed. We still 10712 have the option of splitting them later, if we need to introduce 10713 new uses of the global pointer. 10714 10715 For example, the scheduler ignores a ghost instruction that 10716 stores $28 to the stack, but it handles the split form of 10717 the ghost instruction as an ordinary store. 10718 10719 (6) [OldABI only.] If cfun->machine->must_restore_gp_when_clobbered_p 10720 is true during the first post-epilogue split_insns pass, we split 10721 calls and restore_gp patterns into instructions that explicitly 10722 load pic_offset_table_rtx from the cprestore slot. Otherwise, 10723 we split these patterns into instructions that _don't_ load from 10724 the cprestore slot. 10725 10726 If cfun->machine->must_restore_gp_when_clobbered_p is true at the 10727 time of the split, then any instructions that exist at that time 10728 can make free use of pic_offset_table_rtx. However, if we want 10729 to introduce new uses of the global pointer after the split, 10730 we must explicitly load the value from the cprestore slot, since 10731 pic_offset_table_rtx itself might not be valid at a given point 10732 in the function. 10733 10734 The idea is that we want to be able to delete redundant 10735 loads from the cprestore slot in the usual case where no 10736 long branches are needed. 10737 10738 (7) If cfun->machine->must_initialize_gp_p is still false at the end 10739 of md_reorg, we decide whether the global pointer is needed for 10740 long branches. If so, we set cfun->machine->must_initialize_gp_p 10741 to true and split the ghost instructions into real instructions 10742 at that stage. 10743 10744 Note that the ghost instructions must have a zero length for three reasons: 10745 10746 - Giving the length of the underlying $gp sequence might cause 10747 us to use long branches in cases where they aren't really needed. 10748 10749 - They would perturb things like alignment calculations. 10750 10751 - More importantly, the hazard detection in md_reorg relies on 10752 empty instructions having a zero length. 10753 10754 If we find a long branch and split the ghost instructions at the 10755 end of md_reorg, the split could introduce more long branches. 10756 That isn't a problem though, because we still do the split before 10757 the final shorten_branches pass. 10758 10759 This is extremely ugly, but it seems like the best compromise between 10760 correctness and efficiency. */ 10761 10762 bool 10763 mips_must_initialize_gp_p (void) 10764 { 10765 return cfun->machine->must_initialize_gp_p; 10766 } 10767 10768 /* Return true if REGNO is a register that is ordinarily call-clobbered 10769 but must nevertheless be preserved by an interrupt handler. */ 10770 10771 static bool 10772 mips_interrupt_extra_call_saved_reg_p (unsigned int regno) 10773 { 10774 if ((ISA_HAS_HILO || TARGET_DSP) 10775 && MD_REG_P (regno)) 10776 return true; 10777 10778 if (TARGET_DSP && DSP_ACC_REG_P (regno)) 10779 return true; 10780 10781 if (GP_REG_P (regno) 10782 && cfun->machine->use_shadow_register_set == SHADOW_SET_NO) 10783 { 10784 /* $0 is hard-wired. */ 10785 if (regno == GP_REG_FIRST) 10786 return false; 10787 10788 /* The interrupt handler can treat kernel registers as 10789 scratch registers. */ 10790 if (KERNEL_REG_P (regno)) 10791 return false; 10792 10793 /* The function will return the stack pointer to its original value 10794 anyway. */ 10795 if (regno == STACK_POINTER_REGNUM) 10796 return false; 10797 10798 /* Otherwise, return true for registers that aren't ordinarily 10799 call-clobbered. */ 10800 return call_used_regs[regno]; 10801 } 10802 10803 return false; 10804 } 10805 10806 /* Return true if the current function should treat register REGNO 10807 as call-saved. */ 10808 10809 static bool 10810 mips_cfun_call_saved_reg_p (unsigned int regno) 10811 { 10812 /* If the user makes an ordinarily-call-saved register global, 10813 that register is no longer call-saved. */ 10814 if (global_regs[regno]) 10815 return false; 10816 10817 /* Interrupt handlers need to save extra registers. */ 10818 if (cfun->machine->interrupt_handler_p 10819 && mips_interrupt_extra_call_saved_reg_p (regno)) 10820 return true; 10821 10822 /* call_insns preserve $28 unless they explicitly say otherwise, 10823 so call_used_regs[] treats $28 as call-saved. However, 10824 we want the ABI property rather than the default call_insn 10825 property here. */ 10826 return (regno == GLOBAL_POINTER_REGNUM 10827 ? TARGET_CALL_SAVED_GP 10828 : !call_used_regs[regno]); 10829 } 10830 10831 /* Return true if the function body might clobber register REGNO. 10832 We know that REGNO is call-saved. */ 10833 10834 static bool 10835 mips_cfun_might_clobber_call_saved_reg_p (unsigned int regno) 10836 { 10837 /* Some functions should be treated as clobbering all call-saved 10838 registers. */ 10839 if (crtl->saves_all_registers) 10840 return true; 10841 10842 /* DF handles cases where a register is explicitly referenced in 10843 the rtl. Incoming values are passed in call-clobbered registers, 10844 so we can assume that any live call-saved register is set within 10845 the function. */ 10846 if (df_regs_ever_live_p (regno)) 10847 return true; 10848 10849 /* Check for registers that are clobbered by FUNCTION_PROFILER. 10850 These clobbers are not explicit in the rtl. */ 10851 if (crtl->profile && MIPS_SAVE_REG_FOR_PROFILING_P (regno)) 10852 return true; 10853 10854 /* If we're using a call-saved global pointer, the function's 10855 prologue will need to set it up. */ 10856 if (cfun->machine->global_pointer == regno) 10857 return true; 10858 10859 /* The function's prologue will need to set the frame pointer if 10860 frame_pointer_needed. */ 10861 if (regno == HARD_FRAME_POINTER_REGNUM && frame_pointer_needed) 10862 return true; 10863 10864 /* If a MIPS16 function returns a value in FPRs, its epilogue 10865 will need to call an external libgcc routine. This yet-to-be 10866 generated call_insn will clobber $31. */ 10867 if (regno == RETURN_ADDR_REGNUM && mips16_cfun_returns_in_fpr_p ()) 10868 return true; 10869 10870 /* If REGNO is ordinarily call-clobbered, we must assume that any 10871 called function could modify it. */ 10872 if (cfun->machine->interrupt_handler_p 10873 && !crtl->is_leaf 10874 && mips_interrupt_extra_call_saved_reg_p (regno)) 10875 return true; 10876 10877 return false; 10878 } 10879 10880 /* Return true if the current function must save register REGNO. */ 10881 10882 static bool 10883 mips_save_reg_p (unsigned int regno) 10884 { 10885 if (mips_cfun_call_saved_reg_p (regno)) 10886 { 10887 if (mips_cfun_might_clobber_call_saved_reg_p (regno)) 10888 return true; 10889 10890 /* Save both registers in an FPR pair if either one is used. This is 10891 needed for the case when MIN_FPRS_PER_FMT == 1, which allows the odd 10892 register to be used without the even register. */ 10893 if (FP_REG_P (regno) 10894 && MAX_FPRS_PER_FMT == 2 10895 && mips_cfun_might_clobber_call_saved_reg_p (regno + 1)) 10896 return true; 10897 } 10898 10899 /* We need to save the incoming return address if __builtin_eh_return 10900 is being used to set a different return address. */ 10901 if (regno == RETURN_ADDR_REGNUM && crtl->calls_eh_return) 10902 return true; 10903 10904 return false; 10905 } 10906 10907 /* Populate the current function's mips_frame_info structure. 10908 10909 MIPS stack frames look like: 10910 10911 +-------------------------------+ 10912 | | 10913 | incoming stack arguments | 10914 | | 10915 +-------------------------------+ 10916 | | 10917 | caller-allocated save area | 10918 A | for register arguments | 10919 | | 10920 +-------------------------------+ <-- incoming stack pointer 10921 | | 10922 | callee-allocated save area | 10923 B | for arguments that are | 10924 | split between registers and | 10925 | the stack | 10926 | | 10927 +-------------------------------+ <-- arg_pointer_rtx 10928 | | 10929 C | callee-allocated save area | 10930 | for register varargs | 10931 | | 10932 +-------------------------------+ <-- frame_pointer_rtx 10933 | | + cop0_sp_offset 10934 | COP0 reg save area | + UNITS_PER_WORD 10935 | | 10936 +-------------------------------+ <-- frame_pointer_rtx + acc_sp_offset 10937 | | + UNITS_PER_WORD 10938 | accumulator save area | 10939 | | 10940 +-------------------------------+ <-- stack_pointer_rtx + fp_sp_offset 10941 | | + UNITS_PER_HWFPVALUE 10942 | FPR save area | 10943 | | 10944 +-------------------------------+ <-- stack_pointer_rtx + gp_sp_offset 10945 | | + UNITS_PER_WORD 10946 | GPR save area | 10947 | | 10948 +-------------------------------+ <-- frame_pointer_rtx with 10949 | | \ -fstack-protector 10950 | local variables | | var_size 10951 | | / 10952 +-------------------------------+ 10953 | | \ 10954 | $gp save area | | cprestore_size 10955 | | / 10956 P +-------------------------------+ <-- hard_frame_pointer_rtx for 10957 | | \ MIPS16 code 10958 | outgoing stack arguments | | 10959 | | | 10960 +-------------------------------+ | args_size 10961 | | | 10962 | caller-allocated save area | | 10963 | for register arguments | | 10964 | | / 10965 +-------------------------------+ <-- stack_pointer_rtx 10966 frame_pointer_rtx without 10967 -fstack-protector 10968 hard_frame_pointer_rtx for 10969 non-MIPS16 code. 10970 10971 At least two of A, B and C will be empty. 10972 10973 Dynamic stack allocations such as alloca insert data at point P. 10974 They decrease stack_pointer_rtx but leave frame_pointer_rtx and 10975 hard_frame_pointer_rtx unchanged. */ 10976 10977 static void 10978 mips_compute_frame_info (void) 10979 { 10980 struct mips_frame_info *frame; 10981 HOST_WIDE_INT offset, size; 10982 unsigned int regno, i; 10983 10984 /* Skip re-computing the frame info after reload completed. */ 10985 if (reload_completed) 10986 return; 10987 10988 /* Set this function's interrupt properties. */ 10989 if (mips_interrupt_type_p (TREE_TYPE (current_function_decl))) 10990 { 10991 if (mips_isa_rev < 2) 10992 error ("the %<interrupt%> attribute requires a MIPS32r2 processor or greater"); 10993 else if (TARGET_MIPS16) 10994 error ("interrupt handlers cannot be MIPS16 functions"); 10995 else 10996 { 10997 cfun->machine->interrupt_handler_p = true; 10998 cfun->machine->int_mask = 10999 mips_interrupt_mask (TREE_TYPE (current_function_decl)); 11000 cfun->machine->use_shadow_register_set = 11001 mips_use_shadow_register_set (TREE_TYPE (current_function_decl)); 11002 cfun->machine->keep_interrupts_masked_p = 11003 mips_keep_interrupts_masked_p (TREE_TYPE (current_function_decl)); 11004 cfun->machine->use_debug_exception_return_p = 11005 mips_use_debug_exception_return_p (TREE_TYPE 11006 (current_function_decl)); 11007 } 11008 } 11009 11010 frame = &cfun->machine->frame; 11011 memset (frame, 0, sizeof (*frame)); 11012 size = get_frame_size (); 11013 11014 /* The first two blocks contain the outgoing argument area and the $gp save 11015 slot. This area isn't needed in leaf functions. We can also skip it 11016 if we know that none of the called functions will use this space. 11017 11018 But if the target-independent frame size is nonzero, we have already 11019 committed to allocating these in TARGET_STARTING_FRAME_OFFSET for 11020 !FRAME_GROWS_DOWNWARD. */ 11021 11022 if ((size == 0 || FRAME_GROWS_DOWNWARD) 11023 && (crtl->is_leaf || (cfun->machine->optimize_call_stack && !flag_pic))) 11024 { 11025 /* The MIPS 3.0 linker does not like functions that dynamically 11026 allocate the stack and have 0 for STACK_DYNAMIC_OFFSET, since it 11027 looks like we are trying to create a second frame pointer to the 11028 function, so allocate some stack space to make it happy. */ 11029 if (cfun->calls_alloca) 11030 frame->args_size = REG_PARM_STACK_SPACE (cfun->decl); 11031 else 11032 frame->args_size = 0; 11033 frame->cprestore_size = 0; 11034 } 11035 else 11036 { 11037 frame->args_size = crtl->outgoing_args_size; 11038 frame->cprestore_size = MIPS_GP_SAVE_AREA_SIZE; 11039 } 11040 11041 /* MIPS16 code offsets the frame pointer by the size of the outgoing 11042 arguments. This tends to increase the chances of using unextended 11043 instructions for local variables and incoming arguments. */ 11044 if (TARGET_MIPS16) 11045 frame->hard_frame_pointer_offset = frame->args_size; 11046 11047 /* PR 69129 / 69012: Beware of a possible race condition. mips_global_pointer 11048 might call mips_cfun_has_inflexible_gp_ref_p which in turn can call 11049 mips_find_gp_ref which will iterate over the current insn sequence. 11050 If any of these insns use the cprestore_save_slot_operand or 11051 cprestore_load_slot_operand predicates in order to be recognised then 11052 they will call mips_cprestore_address_p which calls 11053 mips_get_cprestore_base_and_offset which expects the frame information 11054 to be filled in... In fact mips_get_cprestore_base_and_offset only 11055 needs the args_size and hard_frame_pointer_offset fields to be filled 11056 in, which is why the global_pointer field is initialised here and not 11057 earlier. */ 11058 cfun->machine->global_pointer = mips_global_pointer (); 11059 11060 offset = frame->args_size + frame->cprestore_size; 11061 11062 /* Move above the local variables. */ 11063 frame->var_size = MIPS_STACK_ALIGN (size); 11064 offset += frame->var_size; 11065 11066 /* Find out which GPRs we need to save. */ 11067 for (regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++) 11068 if (mips_save_reg_p (regno)) 11069 { 11070 frame->num_gp++; 11071 frame->mask |= 1 << (regno - GP_REG_FIRST); 11072 } 11073 11074 /* If this function calls eh_return, we must also save and restore the 11075 EH data registers. */ 11076 if (crtl->calls_eh_return) 11077 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; i++) 11078 { 11079 frame->num_gp++; 11080 frame->mask |= 1 << (EH_RETURN_DATA_REGNO (i) - GP_REG_FIRST); 11081 } 11082 11083 /* The MIPS16e SAVE and RESTORE instructions have two ranges of registers: 11084 $a3-$a0 and $s2-$s8. If we save one register in the range, we must 11085 save all later registers too. */ 11086 if (GENERATE_MIPS16E_SAVE_RESTORE) 11087 { 11088 mips16e_mask_registers (&frame->mask, mips16e_s2_s8_regs, 11089 ARRAY_SIZE (mips16e_s2_s8_regs), &frame->num_gp); 11090 mips16e_mask_registers (&frame->mask, mips16e_a0_a3_regs, 11091 ARRAY_SIZE (mips16e_a0_a3_regs), &frame->num_gp); 11092 } 11093 11094 /* Move above the GPR save area. */ 11095 if (frame->num_gp > 0) 11096 { 11097 offset += MIPS_STACK_ALIGN (frame->num_gp * UNITS_PER_WORD); 11098 frame->gp_sp_offset = offset - UNITS_PER_WORD; 11099 } 11100 11101 /* Find out which FPRs we need to save. This loop must iterate over 11102 the same space as its companion in mips_for_each_saved_gpr_and_fpr. */ 11103 if (TARGET_HARD_FLOAT) 11104 for (regno = FP_REG_FIRST; regno <= FP_REG_LAST; regno += MAX_FPRS_PER_FMT) 11105 if (mips_save_reg_p (regno)) 11106 { 11107 frame->num_fp += MAX_FPRS_PER_FMT; 11108 frame->fmask |= ~(~0U << MAX_FPRS_PER_FMT) << (regno - FP_REG_FIRST); 11109 } 11110 11111 /* Move above the FPR save area. */ 11112 if (frame->num_fp > 0) 11113 { 11114 offset += MIPS_STACK_ALIGN (frame->num_fp * UNITS_PER_FPREG); 11115 frame->fp_sp_offset = offset - UNITS_PER_HWFPVALUE; 11116 } 11117 11118 /* Add in space for the interrupt context information. */ 11119 if (cfun->machine->interrupt_handler_p) 11120 { 11121 /* Check HI/LO. */ 11122 if (mips_save_reg_p (LO_REGNUM) || mips_save_reg_p (HI_REGNUM)) 11123 { 11124 frame->num_acc++; 11125 frame->acc_mask |= (1 << 0); 11126 } 11127 11128 /* Check accumulators 1, 2, 3. */ 11129 for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2) 11130 if (mips_save_reg_p (i) || mips_save_reg_p (i + 1)) 11131 { 11132 frame->num_acc++; 11133 frame->acc_mask |= 1 << (((i - DSP_ACC_REG_FIRST) / 2) + 1); 11134 } 11135 11136 /* All interrupt context functions need space to preserve STATUS. */ 11137 frame->num_cop0_regs++; 11138 11139 /* We need to save EPC regardless of whether interrupts remain masked 11140 as exceptions will corrupt EPC. */ 11141 frame->num_cop0_regs++; 11142 } 11143 11144 /* Move above the accumulator save area. */ 11145 if (frame->num_acc > 0) 11146 { 11147 /* Each accumulator needs 2 words. */ 11148 offset += frame->num_acc * 2 * UNITS_PER_WORD; 11149 frame->acc_sp_offset = offset - UNITS_PER_WORD; 11150 } 11151 11152 /* Move above the COP0 register save area. */ 11153 if (frame->num_cop0_regs > 0) 11154 { 11155 offset += frame->num_cop0_regs * UNITS_PER_WORD; 11156 frame->cop0_sp_offset = offset - UNITS_PER_WORD; 11157 } 11158 11159 /* Determine if we can save the callee-saved registers in the frame 11160 header. Restrict this to functions where there is no other reason 11161 to allocate stack space so that we can eliminate the instructions 11162 that modify the stack pointer. */ 11163 11164 if (TARGET_OLDABI 11165 && optimize > 0 11166 && flag_frame_header_optimization 11167 && !MAIN_NAME_P (DECL_NAME (current_function_decl)) 11168 && cfun->machine->varargs_size == 0 11169 && crtl->args.pretend_args_size == 0 11170 && frame->var_size == 0 11171 && frame->num_acc == 0 11172 && frame->num_cop0_regs == 0 11173 && frame->num_fp == 0 11174 && frame->num_gp > 0 11175 && frame->num_gp <= MAX_ARGS_IN_REGISTERS 11176 && !GENERATE_MIPS16E_SAVE_RESTORE 11177 && !cfun->machine->interrupt_handler_p 11178 && cfun->machine->does_not_use_frame_header 11179 && cfun->machine->optimize_call_stack 11180 && !cfun->machine->callers_may_not_allocate_frame 11181 && !mips_cfun_has_cprestore_slot_p ()) 11182 { 11183 offset = 0; 11184 frame->gp_sp_offset = REG_PARM_STACK_SPACE(cfun) - UNITS_PER_WORD; 11185 cfun->machine->use_frame_header_for_callee_saved_regs = true; 11186 } 11187 11188 /* Move above the callee-allocated varargs save area. */ 11189 offset += MIPS_STACK_ALIGN (cfun->machine->varargs_size); 11190 frame->arg_pointer_offset = offset; 11191 11192 /* Move above the callee-allocated area for pretend stack arguments. */ 11193 offset += crtl->args.pretend_args_size; 11194 frame->total_size = offset; 11195 11196 /* Work out the offsets of the save areas from the top of the frame. */ 11197 if (frame->gp_sp_offset > 0) 11198 frame->gp_save_offset = frame->gp_sp_offset - offset; 11199 if (frame->fp_sp_offset > 0) 11200 frame->fp_save_offset = frame->fp_sp_offset - offset; 11201 if (frame->acc_sp_offset > 0) 11202 frame->acc_save_offset = frame->acc_sp_offset - offset; 11203 if (frame->num_cop0_regs > 0) 11204 frame->cop0_save_offset = frame->cop0_sp_offset - offset; 11205 } 11206 11207 /* Return the style of GP load sequence that is being used for the 11208 current function. */ 11209 11210 enum mips_loadgp_style 11211 mips_current_loadgp_style (void) 11212 { 11213 if (!TARGET_USE_GOT || cfun->machine->global_pointer == INVALID_REGNUM) 11214 return LOADGP_NONE; 11215 11216 if (TARGET_RTP_PIC) 11217 return LOADGP_RTP; 11218 11219 if (TARGET_ABSOLUTE_ABICALLS) 11220 return LOADGP_ABSOLUTE; 11221 11222 return TARGET_NEWABI ? LOADGP_NEWABI : LOADGP_OLDABI; 11223 } 11224 11225 /* Implement TARGET_FRAME_POINTER_REQUIRED. */ 11226 11227 static bool 11228 mips_frame_pointer_required (void) 11229 { 11230 /* If the function contains dynamic stack allocations, we need to 11231 use the frame pointer to access the static parts of the frame. */ 11232 if (cfun->calls_alloca) 11233 return true; 11234 11235 /* In MIPS16 mode, we need a frame pointer for a large frame; otherwise, 11236 reload may be unable to compute the address of a local variable, 11237 since there is no way to add a large constant to the stack pointer 11238 without using a second temporary register. */ 11239 if (TARGET_MIPS16) 11240 { 11241 mips_compute_frame_info (); 11242 if (!SMALL_OPERAND (cfun->machine->frame.total_size)) 11243 return true; 11244 } 11245 11246 return false; 11247 } 11248 11249 /* Make sure that we're not trying to eliminate to the wrong hard frame 11250 pointer. */ 11251 11252 static bool 11253 mips_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to) 11254 { 11255 return (to == HARD_FRAME_POINTER_REGNUM || to == STACK_POINTER_REGNUM); 11256 } 11257 11258 /* Implement INITIAL_ELIMINATION_OFFSET. FROM is either the frame pointer 11259 or argument pointer. TO is either the stack pointer or hard frame 11260 pointer. */ 11261 11262 HOST_WIDE_INT 11263 mips_initial_elimination_offset (int from, int to) 11264 { 11265 HOST_WIDE_INT offset; 11266 11267 mips_compute_frame_info (); 11268 11269 /* Set OFFSET to the offset from the end-of-prologue stack pointer. */ 11270 switch (from) 11271 { 11272 case FRAME_POINTER_REGNUM: 11273 if (FRAME_GROWS_DOWNWARD) 11274 offset = (cfun->machine->frame.args_size 11275 + cfun->machine->frame.cprestore_size 11276 + cfun->machine->frame.var_size); 11277 else 11278 offset = 0; 11279 break; 11280 11281 case ARG_POINTER_REGNUM: 11282 offset = cfun->machine->frame.arg_pointer_offset; 11283 break; 11284 11285 default: 11286 gcc_unreachable (); 11287 } 11288 11289 if (to == HARD_FRAME_POINTER_REGNUM) 11290 offset -= cfun->machine->frame.hard_frame_pointer_offset; 11291 11292 return offset; 11293 } 11294 11295 /* Implement TARGET_EXTRA_LIVE_ON_ENTRY. */ 11296 11297 static void 11298 mips_extra_live_on_entry (bitmap regs) 11299 { 11300 if (TARGET_USE_GOT) 11301 { 11302 /* PIC_FUNCTION_ADDR_REGNUM is live if we need it to set up 11303 the global pointer. */ 11304 if (!TARGET_ABSOLUTE_ABICALLS) 11305 bitmap_set_bit (regs, PIC_FUNCTION_ADDR_REGNUM); 11306 11307 /* The prologue may set MIPS16_PIC_TEMP_REGNUM to the value of 11308 the global pointer. */ 11309 if (TARGET_MIPS16) 11310 bitmap_set_bit (regs, MIPS16_PIC_TEMP_REGNUM); 11311 11312 /* See the comment above load_call<mode> for details. */ 11313 bitmap_set_bit (regs, GOT_VERSION_REGNUM); 11314 } 11315 } 11316 11317 /* Implement RETURN_ADDR_RTX. We do not support moving back to a 11318 previous frame. */ 11319 11320 rtx 11321 mips_return_addr (int count, rtx frame ATTRIBUTE_UNUSED) 11322 { 11323 if (count != 0) 11324 return const0_rtx; 11325 11326 return get_hard_reg_initial_val (Pmode, RETURN_ADDR_REGNUM); 11327 } 11328 11329 /* Emit code to change the current function's return address to 11330 ADDRESS. SCRATCH is available as a scratch register, if needed. 11331 ADDRESS and SCRATCH are both word-mode GPRs. */ 11332 11333 void 11334 mips_set_return_address (rtx address, rtx scratch) 11335 { 11336 rtx slot_address; 11337 11338 gcc_assert (BITSET_P (cfun->machine->frame.mask, RETURN_ADDR_REGNUM)); 11339 slot_address = mips_add_offset (scratch, stack_pointer_rtx, 11340 cfun->machine->frame.gp_sp_offset); 11341 mips_emit_move (gen_frame_mem (GET_MODE (address), slot_address), address); 11342 } 11343 11344 /* Return true if the current function has a cprestore slot. */ 11345 11346 bool 11347 mips_cfun_has_cprestore_slot_p (void) 11348 { 11349 return (cfun->machine->global_pointer != INVALID_REGNUM 11350 && cfun->machine->frame.cprestore_size > 0); 11351 } 11352 11353 /* Fill *BASE and *OFFSET such that *BASE + *OFFSET refers to the 11354 cprestore slot. LOAD_P is true if the caller wants to load from 11355 the cprestore slot; it is false if the caller wants to store to 11356 the slot. */ 11357 11358 static void 11359 mips_get_cprestore_base_and_offset (rtx *base, HOST_WIDE_INT *offset, 11360 bool load_p) 11361 { 11362 const struct mips_frame_info *frame; 11363 11364 frame = &cfun->machine->frame; 11365 /* .cprestore always uses the stack pointer instead of the frame pointer. 11366 We have a free choice for direct stores for non-MIPS16 functions, 11367 and for MIPS16 functions whose cprestore slot is in range of the 11368 stack pointer. Using the stack pointer would sometimes give more 11369 (early) scheduling freedom, but using the frame pointer would 11370 sometimes give more (late) scheduling freedom. It's hard to 11371 predict which applies to a given function, so let's keep things 11372 simple. 11373 11374 Loads must always use the frame pointer in functions that call 11375 alloca, and there's little benefit to using the stack pointer 11376 otherwise. */ 11377 if (frame_pointer_needed && !(TARGET_CPRESTORE_DIRECTIVE && !load_p)) 11378 { 11379 *base = hard_frame_pointer_rtx; 11380 *offset = frame->args_size - frame->hard_frame_pointer_offset; 11381 } 11382 else 11383 { 11384 *base = stack_pointer_rtx; 11385 *offset = frame->args_size; 11386 } 11387 } 11388 11389 /* Return true if X is the load or store address of the cprestore slot; 11390 LOAD_P says which. */ 11391 11392 bool 11393 mips_cprestore_address_p (rtx x, bool load_p) 11394 { 11395 rtx given_base, required_base; 11396 HOST_WIDE_INT given_offset, required_offset; 11397 11398 mips_split_plus (x, &given_base, &given_offset); 11399 mips_get_cprestore_base_and_offset (&required_base, &required_offset, load_p); 11400 return given_base == required_base && given_offset == required_offset; 11401 } 11402 11403 /* Return a MEM rtx for the cprestore slot. LOAD_P is true if we are 11404 going to load from it, false if we are going to store to it. 11405 Use TEMP as a temporary register if need be. */ 11406 11407 static rtx 11408 mips_cprestore_slot (rtx temp, bool load_p) 11409 { 11410 rtx base; 11411 HOST_WIDE_INT offset; 11412 11413 mips_get_cprestore_base_and_offset (&base, &offset, load_p); 11414 return gen_frame_mem (Pmode, mips_add_offset (temp, base, offset)); 11415 } 11416 11417 /* Emit instructions to save global pointer value GP into cprestore 11418 slot MEM. OFFSET is the offset that MEM applies to the base register. 11419 11420 MEM may not be a legitimate address. If it isn't, TEMP is a 11421 temporary register that can be used, otherwise it is a SCRATCH. */ 11422 11423 void 11424 mips_save_gp_to_cprestore_slot (rtx mem, rtx offset, rtx gp, rtx temp) 11425 { 11426 if (TARGET_CPRESTORE_DIRECTIVE) 11427 { 11428 gcc_assert (gp == pic_offset_table_rtx); 11429 emit_insn (PMODE_INSN (gen_cprestore, (mem, offset))); 11430 } 11431 else 11432 mips_emit_move (mips_cprestore_slot (temp, false), gp); 11433 } 11434 11435 /* Restore $gp from its save slot, using TEMP as a temporary base register 11436 if need be. This function is for o32 and o64 abicalls only. 11437 11438 See mips_must_initialize_gp_p for details about how we manage the 11439 global pointer. */ 11440 11441 void 11442 mips_restore_gp_from_cprestore_slot (rtx temp) 11443 { 11444 gcc_assert (TARGET_ABICALLS && TARGET_OLDABI && epilogue_completed); 11445 11446 if (!cfun->machine->must_restore_gp_when_clobbered_p) 11447 { 11448 emit_note (NOTE_INSN_DELETED); 11449 return; 11450 } 11451 11452 if (TARGET_MIPS16) 11453 { 11454 mips_emit_move (temp, mips_cprestore_slot (temp, true)); 11455 mips_emit_move (pic_offset_table_rtx, temp); 11456 } 11457 else 11458 mips_emit_move (pic_offset_table_rtx, mips_cprestore_slot (temp, true)); 11459 if (!TARGET_EXPLICIT_RELOCS) 11460 emit_insn (gen_blockage ()); 11461 } 11462 11463 /* A function to save or store a register. The first argument is the 11464 register and the second is the stack slot. */ 11465 typedef void (*mips_save_restore_fn) (rtx, rtx); 11466 11467 /* Use FN to save or restore register REGNO. MODE is the register's 11468 mode and OFFSET is the offset of its save slot from the current 11469 stack pointer. */ 11470 11471 static void 11472 mips_save_restore_reg (machine_mode mode, int regno, 11473 HOST_WIDE_INT offset, mips_save_restore_fn fn) 11474 { 11475 rtx mem; 11476 11477 mem = gen_frame_mem (mode, plus_constant (Pmode, stack_pointer_rtx, 11478 offset)); 11479 fn (gen_rtx_REG (mode, regno), mem); 11480 } 11481 11482 /* Call FN for each accumulator that is saved by the current function. 11483 SP_OFFSET is the offset of the current stack pointer from the start 11484 of the frame. */ 11485 11486 static void 11487 mips_for_each_saved_acc (HOST_WIDE_INT sp_offset, mips_save_restore_fn fn) 11488 { 11489 HOST_WIDE_INT offset; 11490 int regno; 11491 11492 offset = cfun->machine->frame.acc_sp_offset - sp_offset; 11493 if (BITSET_P (cfun->machine->frame.acc_mask, 0)) 11494 { 11495 mips_save_restore_reg (word_mode, LO_REGNUM, offset, fn); 11496 offset -= UNITS_PER_WORD; 11497 mips_save_restore_reg (word_mode, HI_REGNUM, offset, fn); 11498 offset -= UNITS_PER_WORD; 11499 } 11500 11501 for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno++) 11502 if (BITSET_P (cfun->machine->frame.acc_mask, 11503 ((regno - DSP_ACC_REG_FIRST) / 2) + 1)) 11504 { 11505 mips_save_restore_reg (word_mode, regno, offset, fn); 11506 offset -= UNITS_PER_WORD; 11507 } 11508 } 11509 11510 /* Save register REG to MEM. Make the instruction frame-related. */ 11511 11512 static void 11513 mips_save_reg (rtx reg, rtx mem) 11514 { 11515 if (GET_MODE (reg) == DFmode 11516 && (!TARGET_FLOAT64 11517 || mips_abi == ABI_32)) 11518 { 11519 rtx x1, x2; 11520 11521 mips_emit_move_or_split (mem, reg, SPLIT_IF_NECESSARY); 11522 11523 x1 = mips_frame_set (mips_subword (mem, false), 11524 mips_subword (reg, false)); 11525 x2 = mips_frame_set (mips_subword (mem, true), 11526 mips_subword (reg, true)); 11527 mips_set_frame_expr (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, x1, x2))); 11528 } 11529 else 11530 mips_emit_save_slot_move (mem, reg, MIPS_PROLOGUE_TEMP (GET_MODE (reg))); 11531 } 11532 11533 /* Capture the register combinations that are allowed in a SWM or LWM 11534 instruction. The entries are ordered by number of registers set in 11535 the mask. We also ignore the single register encodings because a 11536 normal SW/LW is preferred. */ 11537 11538 static const unsigned int umips_swm_mask[17] = { 11539 0xc0ff0000, 0x80ff0000, 0x40ff0000, 0x807f0000, 11540 0x00ff0000, 0x803f0000, 0x007f0000, 0x801f0000, 11541 0x003f0000, 0x800f0000, 0x001f0000, 0x80070000, 11542 0x000f0000, 0x80030000, 0x00070000, 0x80010000, 11543 0x00030000 11544 }; 11545 11546 static const unsigned int umips_swm_encoding[17] = { 11547 25, 24, 9, 23, 8, 22, 7, 21, 6, 20, 5, 19, 4, 18, 3, 17, 2 11548 }; 11549 11550 /* Try to use a microMIPS LWM or SWM instruction to save or restore 11551 as many GPRs in *MASK as possible. *OFFSET is the offset from the 11552 stack pointer of the topmost save slot. 11553 11554 Remove from *MASK all registers that were handled using LWM and SWM. 11555 Update *OFFSET so that it points to the first unused save slot. */ 11556 11557 static bool 11558 umips_build_save_restore (mips_save_restore_fn fn, 11559 unsigned *mask, HOST_WIDE_INT *offset) 11560 { 11561 int nregs; 11562 unsigned int i, j; 11563 rtx pattern, set, reg, mem; 11564 HOST_WIDE_INT this_offset; 11565 rtx this_base; 11566 11567 /* Try matching $16 to $31 (s0 to ra). */ 11568 for (i = 0; i < ARRAY_SIZE (umips_swm_mask); i++) 11569 if ((*mask & 0xffff0000) == umips_swm_mask[i]) 11570 break; 11571 11572 if (i == ARRAY_SIZE (umips_swm_mask)) 11573 return false; 11574 11575 /* Get the offset of the lowest save slot. */ 11576 nregs = (umips_swm_encoding[i] & 0xf) + (umips_swm_encoding[i] >> 4); 11577 this_offset = *offset - UNITS_PER_WORD * (nregs - 1); 11578 11579 /* LWM/SWM can only support offsets from -2048 to 2047. */ 11580 if (!UMIPS_12BIT_OFFSET_P (this_offset)) 11581 return false; 11582 11583 /* Create the final PARALLEL. */ 11584 pattern = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs)); 11585 this_base = stack_pointer_rtx; 11586 11587 /* For registers $16-$23 and $30. */ 11588 for (j = 0; j < (umips_swm_encoding[i] & 0xf); j++) 11589 { 11590 HOST_WIDE_INT offset = this_offset + j * UNITS_PER_WORD; 11591 mem = gen_frame_mem (SImode, plus_constant (Pmode, this_base, offset)); 11592 unsigned int regno = (j != 8) ? 16 + j : 30; 11593 *mask &= ~(1 << regno); 11594 reg = gen_rtx_REG (SImode, regno); 11595 if (fn == mips_save_reg) 11596 set = mips_frame_set (mem, reg); 11597 else 11598 { 11599 set = gen_rtx_SET (reg, mem); 11600 mips_add_cfa_restore (reg); 11601 } 11602 XVECEXP (pattern, 0, j) = set; 11603 } 11604 11605 /* For register $31. */ 11606 if (umips_swm_encoding[i] >> 4) 11607 { 11608 HOST_WIDE_INT offset = this_offset + j * UNITS_PER_WORD; 11609 *mask &= ~(1 << 31); 11610 mem = gen_frame_mem (SImode, plus_constant (Pmode, this_base, offset)); 11611 reg = gen_rtx_REG (SImode, 31); 11612 if (fn == mips_save_reg) 11613 set = mips_frame_set (mem, reg); 11614 else 11615 { 11616 set = gen_rtx_SET (reg, mem); 11617 mips_add_cfa_restore (reg); 11618 } 11619 XVECEXP (pattern, 0, j) = set; 11620 } 11621 11622 pattern = emit_insn (pattern); 11623 if (fn == mips_save_reg) 11624 RTX_FRAME_RELATED_P (pattern) = 1; 11625 11626 /* Adjust the last offset. */ 11627 *offset -= UNITS_PER_WORD * nregs; 11628 11629 return true; 11630 } 11631 11632 /* Call FN for each register that is saved by the current function. 11633 SP_OFFSET is the offset of the current stack pointer from the start 11634 of the frame. */ 11635 11636 static void 11637 mips_for_each_saved_gpr_and_fpr (HOST_WIDE_INT sp_offset, 11638 mips_save_restore_fn fn) 11639 { 11640 machine_mode fpr_mode; 11641 int regno; 11642 const struct mips_frame_info *frame = &cfun->machine->frame; 11643 HOST_WIDE_INT offset; 11644 unsigned int mask; 11645 11646 /* Save registers starting from high to low. The debuggers prefer at least 11647 the return register be stored at func+4, and also it allows us not to 11648 need a nop in the epilogue if at least one register is reloaded in 11649 addition to return address. */ 11650 offset = frame->gp_sp_offset - sp_offset; 11651 mask = frame->mask; 11652 11653 if (TARGET_MICROMIPS) 11654 umips_build_save_restore (fn, &mask, &offset); 11655 11656 for (regno = GP_REG_LAST; regno >= GP_REG_FIRST; regno--) 11657 if (BITSET_P (mask, regno - GP_REG_FIRST)) 11658 { 11659 /* Record the ra offset for use by mips_function_profiler. */ 11660 if (regno == RETURN_ADDR_REGNUM) 11661 cfun->machine->frame.ra_fp_offset = offset + sp_offset; 11662 mips_save_restore_reg (word_mode, regno, offset, fn); 11663 offset -= UNITS_PER_WORD; 11664 } 11665 11666 /* This loop must iterate over the same space as its companion in 11667 mips_compute_frame_info. */ 11668 offset = cfun->machine->frame.fp_sp_offset - sp_offset; 11669 fpr_mode = (TARGET_SINGLE_FLOAT ? SFmode : DFmode); 11670 for (regno = FP_REG_LAST - MAX_FPRS_PER_FMT + 1; 11671 regno >= FP_REG_FIRST; 11672 regno -= MAX_FPRS_PER_FMT) 11673 if (BITSET_P (cfun->machine->frame.fmask, regno - FP_REG_FIRST)) 11674 { 11675 if (!TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT 11676 && (fixed_regs[regno] || fixed_regs[regno + 1])) 11677 { 11678 if (fixed_regs[regno]) 11679 mips_save_restore_reg (SFmode, regno + 1, offset, fn); 11680 else 11681 mips_save_restore_reg (SFmode, regno, offset, fn); 11682 } 11683 else 11684 mips_save_restore_reg (fpr_mode, regno, offset, fn); 11685 offset -= GET_MODE_SIZE (fpr_mode); 11686 } 11687 } 11688 11689 /* Return true if a move between register REGNO and its save slot (MEM) 11690 can be done in a single move. LOAD_P is true if we are loading 11691 from the slot, false if we are storing to it. */ 11692 11693 static bool 11694 mips_direct_save_slot_move_p (unsigned int regno, rtx mem, bool load_p) 11695 { 11696 /* There is a specific MIPS16 instruction for saving $31 to the stack. */ 11697 if (TARGET_MIPS16 && !load_p && regno == RETURN_ADDR_REGNUM) 11698 return false; 11699 11700 return mips_secondary_reload_class (REGNO_REG_CLASS (regno), 11701 GET_MODE (mem), mem, load_p) == NO_REGS; 11702 } 11703 11704 /* Emit a move from SRC to DEST, given that one of them is a register 11705 save slot and that the other is a register. TEMP is a temporary 11706 GPR of the same mode that is available if need be. */ 11707 11708 void 11709 mips_emit_save_slot_move (rtx dest, rtx src, rtx temp) 11710 { 11711 unsigned int regno; 11712 rtx mem; 11713 11714 if (REG_P (src)) 11715 { 11716 regno = REGNO (src); 11717 mem = dest; 11718 } 11719 else 11720 { 11721 regno = REGNO (dest); 11722 mem = src; 11723 } 11724 11725 if (regno == cfun->machine->global_pointer && !mips_must_initialize_gp_p ()) 11726 { 11727 /* We don't yet know whether we'll need this instruction or not. 11728 Postpone the decision by emitting a ghost move. This move 11729 is specifically not frame-related; only the split version is. */ 11730 if (TARGET_64BIT) 11731 emit_insn (gen_move_gpdi (dest, src)); 11732 else 11733 emit_insn (gen_move_gpsi (dest, src)); 11734 return; 11735 } 11736 11737 if (regno == HI_REGNUM) 11738 { 11739 if (REG_P (dest)) 11740 { 11741 mips_emit_move (temp, src); 11742 if (TARGET_64BIT) 11743 emit_insn (gen_mthidi_ti (gen_rtx_REG (TImode, MD_REG_FIRST), 11744 temp, gen_rtx_REG (DImode, LO_REGNUM))); 11745 else 11746 emit_insn (gen_mthisi_di (gen_rtx_REG (DImode, MD_REG_FIRST), 11747 temp, gen_rtx_REG (SImode, LO_REGNUM))); 11748 } 11749 else 11750 { 11751 if (TARGET_64BIT) 11752 emit_insn (gen_mfhidi_ti (temp, 11753 gen_rtx_REG (TImode, MD_REG_FIRST))); 11754 else 11755 emit_insn (gen_mfhisi_di (temp, 11756 gen_rtx_REG (DImode, MD_REG_FIRST))); 11757 mips_emit_move (dest, temp); 11758 } 11759 } 11760 else if (mips_direct_save_slot_move_p (regno, mem, mem == src)) 11761 mips_emit_move (dest, src); 11762 else 11763 { 11764 gcc_assert (!reg_overlap_mentioned_p (dest, temp)); 11765 mips_emit_move (temp, src); 11766 mips_emit_move (dest, temp); 11767 } 11768 if (MEM_P (dest)) 11769 mips_set_frame_expr (mips_frame_set (dest, src)); 11770 } 11771 11772 /* If we're generating n32 or n64 abicalls, and the current function 11773 does not use $28 as its global pointer, emit a cplocal directive. 11774 Use pic_offset_table_rtx as the argument to the directive. */ 11775 11776 static void 11777 mips_output_cplocal (void) 11778 { 11779 if (!TARGET_EXPLICIT_RELOCS 11780 && mips_must_initialize_gp_p () 11781 && cfun->machine->global_pointer != GLOBAL_POINTER_REGNUM) 11782 output_asm_insn (".cplocal %+", 0); 11783 } 11784 11785 /* Implement TARGET_OUTPUT_FUNCTION_PROLOGUE. */ 11786 11787 static void 11788 mips_output_function_prologue (FILE *file) 11789 { 11790 const char *fnname; 11791 11792 /* In MIPS16 mode, we may need to generate a non-MIPS16 stub to handle 11793 floating-point arguments. */ 11794 if (TARGET_MIPS16 11795 && TARGET_HARD_FLOAT_ABI 11796 && crtl->args.info.fp_code != 0) 11797 mips16_build_function_stub (); 11798 11799 /* Get the function name the same way that toplev.c does before calling 11800 assemble_start_function. This is needed so that the name used here 11801 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */ 11802 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); 11803 mips_start_function_definition (fnname, TARGET_MIPS16); 11804 11805 /* Output MIPS-specific frame information. */ 11806 if (!flag_inhibit_size_directive) 11807 { 11808 const struct mips_frame_info *frame; 11809 11810 frame = &cfun->machine->frame; 11811 11812 /* .frame FRAMEREG, FRAMESIZE, RETREG. */ 11813 fprintf (file, 11814 "\t.frame\t%s," HOST_WIDE_INT_PRINT_DEC ",%s\t\t" 11815 "# vars= " HOST_WIDE_INT_PRINT_DEC 11816 ", regs= %d/%d" 11817 ", args= " HOST_WIDE_INT_PRINT_DEC 11818 ", gp= " HOST_WIDE_INT_PRINT_DEC "\n", 11819 reg_names[frame_pointer_needed 11820 ? HARD_FRAME_POINTER_REGNUM 11821 : STACK_POINTER_REGNUM], 11822 (frame_pointer_needed 11823 ? frame->total_size - frame->hard_frame_pointer_offset 11824 : frame->total_size), 11825 reg_names[RETURN_ADDR_REGNUM], 11826 frame->var_size, 11827 frame->num_gp, frame->num_fp, 11828 frame->args_size, 11829 frame->cprestore_size); 11830 11831 /* .mask MASK, OFFSET. */ 11832 fprintf (file, "\t.mask\t0x%08x," HOST_WIDE_INT_PRINT_DEC "\n", 11833 frame->mask, frame->gp_save_offset); 11834 11835 /* .fmask MASK, OFFSET. */ 11836 fprintf (file, "\t.fmask\t0x%08x," HOST_WIDE_INT_PRINT_DEC "\n", 11837 frame->fmask, frame->fp_save_offset); 11838 } 11839 11840 /* Handle the initialization of $gp for SVR4 PIC, if applicable. 11841 Also emit the ".set noreorder; .set nomacro" sequence for functions 11842 that need it. */ 11843 if (mips_must_initialize_gp_p () 11844 && mips_current_loadgp_style () == LOADGP_OLDABI) 11845 { 11846 if (TARGET_MIPS16) 11847 { 11848 /* This is a fixed-form sequence. The position of the 11849 first two instructions is important because of the 11850 way _gp_disp is defined. */ 11851 output_asm_insn ("li\t$2,%%hi(_gp_disp)", 0); 11852 output_asm_insn ("addiu\t$3,$pc,%%lo(_gp_disp)", 0); 11853 output_asm_insn ("sll\t$2,16", 0); 11854 output_asm_insn ("addu\t$2,$3", 0); 11855 } 11856 else 11857 { 11858 /* .cpload must be in a .set noreorder but not a 11859 .set nomacro block. */ 11860 mips_push_asm_switch (&mips_noreorder); 11861 output_asm_insn (".cpload\t%^", 0); 11862 if (!cfun->machine->all_noreorder_p) 11863 mips_pop_asm_switch (&mips_noreorder); 11864 else 11865 mips_push_asm_switch (&mips_nomacro); 11866 } 11867 } 11868 else if (cfun->machine->all_noreorder_p) 11869 { 11870 mips_push_asm_switch (&mips_noreorder); 11871 mips_push_asm_switch (&mips_nomacro); 11872 } 11873 11874 /* Tell the assembler which register we're using as the global 11875 pointer. This is needed for thunks, since they can use either 11876 explicit relocs or assembler macros. */ 11877 mips_output_cplocal (); 11878 } 11879 11880 /* Implement TARGET_OUTPUT_FUNCTION_EPILOGUE. */ 11881 11882 static void 11883 mips_output_function_epilogue (FILE *) 11884 { 11885 const char *fnname; 11886 11887 /* Reinstate the normal $gp. */ 11888 SET_REGNO (pic_offset_table_rtx, GLOBAL_POINTER_REGNUM); 11889 mips_output_cplocal (); 11890 11891 if (cfun->machine->all_noreorder_p) 11892 { 11893 mips_pop_asm_switch (&mips_nomacro); 11894 mips_pop_asm_switch (&mips_noreorder); 11895 } 11896 11897 /* Get the function name the same way that toplev.c does before calling 11898 assemble_start_function. This is needed so that the name used here 11899 exactly matches the name used in ASM_DECLARE_FUNCTION_NAME. */ 11900 fnname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); 11901 mips_end_function_definition (fnname); 11902 } 11903 11904 /* Emit an optimisation barrier for accesses to the current frame. */ 11905 11906 static void 11907 mips_frame_barrier (void) 11908 { 11909 emit_clobber (gen_frame_mem (BLKmode, stack_pointer_rtx)); 11910 } 11911 11912 11913 /* The __gnu_local_gp symbol. */ 11914 11915 static GTY(()) rtx mips_gnu_local_gp; 11916 11917 /* If we're generating n32 or n64 abicalls, emit instructions 11918 to set up the global pointer. */ 11919 11920 static void 11921 mips_emit_loadgp (void) 11922 { 11923 rtx addr, offset, incoming_address, base, index, pic_reg; 11924 11925 pic_reg = TARGET_MIPS16 ? MIPS16_PIC_TEMP : pic_offset_table_rtx; 11926 switch (mips_current_loadgp_style ()) 11927 { 11928 case LOADGP_ABSOLUTE: 11929 if (mips_gnu_local_gp == NULL) 11930 { 11931 mips_gnu_local_gp = gen_rtx_SYMBOL_REF (Pmode, "__gnu_local_gp"); 11932 SYMBOL_REF_FLAGS (mips_gnu_local_gp) |= SYMBOL_FLAG_LOCAL; 11933 } 11934 emit_insn (PMODE_INSN (gen_loadgp_absolute, 11935 (pic_reg, mips_gnu_local_gp))); 11936 break; 11937 11938 case LOADGP_OLDABI: 11939 /* Added by mips_output_function_prologue. */ 11940 break; 11941 11942 case LOADGP_NEWABI: 11943 addr = XEXP (DECL_RTL (current_function_decl), 0); 11944 offset = mips_unspec_address (addr, SYMBOL_GOTOFF_LOADGP); 11945 incoming_address = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM); 11946 emit_insn (PMODE_INSN (gen_loadgp_newabi, 11947 (pic_reg, offset, incoming_address))); 11948 break; 11949 11950 case LOADGP_RTP: 11951 base = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (VXWORKS_GOTT_BASE)); 11952 index = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (VXWORKS_GOTT_INDEX)); 11953 emit_insn (PMODE_INSN (gen_loadgp_rtp, (pic_reg, base, index))); 11954 break; 11955 11956 default: 11957 return; 11958 } 11959 11960 if (TARGET_MIPS16) 11961 emit_insn (PMODE_INSN (gen_copygp_mips16, 11962 (pic_offset_table_rtx, pic_reg))); 11963 11964 /* Emit a blockage if there are implicit uses of the GP register. 11965 This includes profiled functions, because FUNCTION_PROFILE uses 11966 a jal macro. */ 11967 if (!TARGET_EXPLICIT_RELOCS || crtl->profile) 11968 emit_insn (gen_loadgp_blockage ()); 11969 } 11970 11971 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP) 11972 11973 #if PROBE_INTERVAL > 32768 11974 #error Cannot use indexed addressing mode for stack probing 11975 #endif 11976 11977 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE, 11978 inclusive. These are offsets from the current stack pointer. */ 11979 11980 static void 11981 mips_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size) 11982 { 11983 if (TARGET_MIPS16) 11984 sorry ("%<-fstack-check=specific%> not implemented for MIPS16"); 11985 11986 /* See if we have a constant small number of probes to generate. If so, 11987 that's the easy case. */ 11988 if (first + size <= 32768) 11989 { 11990 HOST_WIDE_INT i; 11991 11992 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until 11993 it exceeds SIZE. If only one probe is needed, this will not 11994 generate any code. Then probe at FIRST + SIZE. */ 11995 for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL) 11996 emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx, 11997 -(first + i))); 11998 11999 emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx, 12000 -(first + size))); 12001 } 12002 12003 /* Otherwise, do the same as above, but in a loop. Note that we must be 12004 extra careful with variables wrapping around because we might be at 12005 the very top (or the very bottom) of the address space and we have 12006 to be able to handle this case properly; in particular, we use an 12007 equality test for the loop condition. */ 12008 else 12009 { 12010 HOST_WIDE_INT rounded_size; 12011 rtx r3 = MIPS_PROLOGUE_TEMP (Pmode); 12012 rtx r12 = MIPS_PROLOGUE_TEMP2 (Pmode); 12013 12014 /* Sanity check for the addressing mode we're going to use. */ 12015 gcc_assert (first <= 32768); 12016 12017 12018 /* Step 1: round SIZE to the previous multiple of the interval. */ 12019 12020 rounded_size = ROUND_DOWN (size, PROBE_INTERVAL); 12021 12022 12023 /* Step 2: compute initial and final value of the loop counter. */ 12024 12025 /* TEST_ADDR = SP + FIRST. */ 12026 emit_insn (gen_rtx_SET (r3, plus_constant (Pmode, stack_pointer_rtx, 12027 -first))); 12028 12029 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */ 12030 if (rounded_size > 32768) 12031 { 12032 emit_move_insn (r12, GEN_INT (rounded_size)); 12033 emit_insn (gen_rtx_SET (r12, gen_rtx_MINUS (Pmode, r3, r12))); 12034 } 12035 else 12036 emit_insn (gen_rtx_SET (r12, plus_constant (Pmode, r3, 12037 -rounded_size))); 12038 12039 12040 /* Step 3: the loop 12041 12042 do 12043 { 12044 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL 12045 probe at TEST_ADDR 12046 } 12047 while (TEST_ADDR != LAST_ADDR) 12048 12049 probes at FIRST + N * PROBE_INTERVAL for values of N from 1 12050 until it is equal to ROUNDED_SIZE. */ 12051 12052 emit_insn (PMODE_INSN (gen_probe_stack_range, (r3, r3, r12))); 12053 12054 12055 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time 12056 that SIZE is equal to ROUNDED_SIZE. */ 12057 12058 if (size != rounded_size) 12059 emit_stack_probe (plus_constant (Pmode, r12, rounded_size - size)); 12060 } 12061 12062 /* Make sure nothing is scheduled before we are done. */ 12063 emit_insn (gen_blockage ()); 12064 } 12065 12066 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are 12067 absolute addresses. */ 12068 12069 const char * 12070 mips_output_probe_stack_range (rtx reg1, rtx reg2) 12071 { 12072 static int labelno = 0; 12073 char loop_lab[32], tmp[64]; 12074 rtx xops[2]; 12075 12076 ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno++); 12077 12078 /* Loop. */ 12079 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab); 12080 12081 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */ 12082 xops[0] = reg1; 12083 xops[1] = GEN_INT (-PROBE_INTERVAL); 12084 if (TARGET_64BIT && TARGET_LONG64) 12085 output_asm_insn ("daddiu\t%0,%0,%1", xops); 12086 else 12087 output_asm_insn ("addiu\t%0,%0,%1", xops); 12088 12089 /* Probe at TEST_ADDR, test if TEST_ADDR == LAST_ADDR and branch. */ 12090 xops[1] = reg2; 12091 strcpy (tmp, "%(%<bne\t%0,%1,"); 12092 output_asm_insn (strcat (tmp, &loop_lab[1]), xops); 12093 if (TARGET_64BIT) 12094 output_asm_insn ("sd\t$0,0(%0)%)", xops); 12095 else 12096 output_asm_insn ("sw\t$0,0(%0)%)", xops); 12097 12098 return ""; 12099 } 12100 12101 /* Return true if X contains a kernel register. */ 12102 12103 static bool 12104 mips_refers_to_kernel_reg_p (const_rtx x) 12105 { 12106 subrtx_iterator::array_type array; 12107 FOR_EACH_SUBRTX (iter, array, x, NONCONST) 12108 if (REG_P (*iter) && KERNEL_REG_P (REGNO (*iter))) 12109 return true; 12110 return false; 12111 } 12112 12113 /* Expand the "prologue" pattern. */ 12114 12115 void 12116 mips_expand_prologue (void) 12117 { 12118 const struct mips_frame_info *frame; 12119 HOST_WIDE_INT size; 12120 unsigned int nargs; 12121 12122 if (cfun->machine->global_pointer != INVALID_REGNUM) 12123 { 12124 /* Check whether an insn uses pic_offset_table_rtx, either explicitly 12125 or implicitly. If so, we can commit to using a global pointer 12126 straight away, otherwise we need to defer the decision. */ 12127 if (mips_cfun_has_inflexible_gp_ref_p () 12128 || mips_cfun_has_flexible_gp_ref_p ()) 12129 { 12130 cfun->machine->must_initialize_gp_p = true; 12131 cfun->machine->must_restore_gp_when_clobbered_p = true; 12132 } 12133 12134 SET_REGNO (pic_offset_table_rtx, cfun->machine->global_pointer); 12135 } 12136 12137 frame = &cfun->machine->frame; 12138 size = frame->total_size; 12139 12140 if (flag_stack_usage_info) 12141 current_function_static_stack_size = size; 12142 12143 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK 12144 || flag_stack_clash_protection) 12145 { 12146 if (crtl->is_leaf && !cfun->calls_alloca) 12147 { 12148 if (size > PROBE_INTERVAL && size > get_stack_check_protect ()) 12149 mips_emit_probe_stack_range (get_stack_check_protect (), 12150 size - get_stack_check_protect ()); 12151 } 12152 else if (size > 0) 12153 mips_emit_probe_stack_range (get_stack_check_protect (), size); 12154 } 12155 12156 /* Save the registers. Allocate up to MIPS_MAX_FIRST_STACK_STEP 12157 bytes beforehand; this is enough to cover the register save area 12158 without going out of range. */ 12159 if (((frame->mask | frame->fmask | frame->acc_mask) != 0) 12160 || frame->num_cop0_regs > 0) 12161 { 12162 HOST_WIDE_INT step1; 12163 12164 step1 = MIN (size, MIPS_MAX_FIRST_STACK_STEP); 12165 if (GENERATE_MIPS16E_SAVE_RESTORE) 12166 { 12167 HOST_WIDE_INT offset; 12168 unsigned int mask, regno; 12169 12170 /* Try to merge argument stores into the save instruction. */ 12171 nargs = mips16e_collect_argument_saves (); 12172 12173 /* Build the save instruction. */ 12174 mask = frame->mask; 12175 rtx insn = mips16e_build_save_restore (false, &mask, &offset, 12176 nargs, step1); 12177 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; 12178 mips_frame_barrier (); 12179 size -= step1; 12180 12181 /* Check if we need to save other registers. */ 12182 for (regno = GP_REG_FIRST; regno < GP_REG_LAST; regno++) 12183 if (BITSET_P (mask, regno - GP_REG_FIRST)) 12184 { 12185 offset -= UNITS_PER_WORD; 12186 mips_save_restore_reg (word_mode, regno, 12187 offset, mips_save_reg); 12188 } 12189 } 12190 else 12191 { 12192 if (cfun->machine->interrupt_handler_p) 12193 { 12194 HOST_WIDE_INT offset; 12195 rtx mem; 12196 12197 /* If this interrupt is using a shadow register set, we need to 12198 get the stack pointer from the previous register set. */ 12199 if (cfun->machine->use_shadow_register_set == SHADOW_SET_YES) 12200 emit_insn (PMODE_INSN (gen_mips_rdpgpr, (stack_pointer_rtx, 12201 stack_pointer_rtx))); 12202 12203 if (!cfun->machine->keep_interrupts_masked_p) 12204 { 12205 if (cfun->machine->int_mask == INT_MASK_EIC) 12206 /* Move from COP0 Cause to K0. */ 12207 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K0_REG_NUM), 12208 gen_rtx_REG (SImode, COP0_CAUSE_REG_NUM))); 12209 } 12210 /* Move from COP0 EPC to K1. */ 12211 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM), 12212 gen_rtx_REG (SImode, 12213 COP0_EPC_REG_NUM))); 12214 12215 /* Allocate the first part of the frame. */ 12216 rtx insn = gen_add3_insn (stack_pointer_rtx, stack_pointer_rtx, 12217 GEN_INT (-step1)); 12218 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; 12219 mips_frame_barrier (); 12220 size -= step1; 12221 12222 /* Start at the uppermost location for saving. */ 12223 offset = frame->cop0_sp_offset - size; 12224 12225 /* Push EPC into its stack slot. */ 12226 mem = gen_frame_mem (word_mode, 12227 plus_constant (Pmode, stack_pointer_rtx, 12228 offset)); 12229 mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM)); 12230 offset -= UNITS_PER_WORD; 12231 12232 /* Move from COP0 Status to K1. */ 12233 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, K1_REG_NUM), 12234 gen_rtx_REG (SImode, 12235 COP0_STATUS_REG_NUM))); 12236 12237 /* Right justify the RIPL in k0. */ 12238 if (!cfun->machine->keep_interrupts_masked_p 12239 && cfun->machine->int_mask == INT_MASK_EIC) 12240 emit_insn (gen_lshrsi3 (gen_rtx_REG (SImode, K0_REG_NUM), 12241 gen_rtx_REG (SImode, K0_REG_NUM), 12242 GEN_INT (CAUSE_IPL))); 12243 12244 /* Push Status into its stack slot. */ 12245 mem = gen_frame_mem (word_mode, 12246 plus_constant (Pmode, stack_pointer_rtx, 12247 offset)); 12248 mips_emit_move (mem, gen_rtx_REG (word_mode, K1_REG_NUM)); 12249 offset -= UNITS_PER_WORD; 12250 12251 /* Insert the RIPL into our copy of SR (k1) as the new IPL. */ 12252 if (!cfun->machine->keep_interrupts_masked_p 12253 && cfun->machine->int_mask == INT_MASK_EIC) 12254 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM), 12255 GEN_INT (6), 12256 GEN_INT (SR_IPL), 12257 gen_rtx_REG (SImode, K0_REG_NUM))); 12258 12259 /* Clear all interrupt mask bits up to and including the 12260 handler's interrupt line. */ 12261 if (!cfun->machine->keep_interrupts_masked_p 12262 && cfun->machine->int_mask != INT_MASK_EIC) 12263 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM), 12264 GEN_INT (cfun->machine->int_mask + 1), 12265 GEN_INT (SR_IM0), 12266 gen_rtx_REG (SImode, GP_REG_FIRST))); 12267 12268 if (!cfun->machine->keep_interrupts_masked_p) 12269 /* Enable interrupts by clearing the KSU ERL and EXL bits. 12270 IE is already the correct value, so we don't have to do 12271 anything explicit. */ 12272 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM), 12273 GEN_INT (4), 12274 GEN_INT (SR_EXL), 12275 gen_rtx_REG (SImode, GP_REG_FIRST))); 12276 else 12277 /* Disable interrupts by clearing the KSU, ERL, EXL, 12278 and IE bits. */ 12279 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM), 12280 GEN_INT (5), 12281 GEN_INT (SR_IE), 12282 gen_rtx_REG (SImode, GP_REG_FIRST))); 12283 12284 if (TARGET_HARD_FLOAT) 12285 /* Disable COP1 for hard-float. This will lead to an exception 12286 if floating-point code is executed in an ISR. */ 12287 emit_insn (gen_insvsi (gen_rtx_REG (SImode, K1_REG_NUM), 12288 GEN_INT (1), 12289 GEN_INT (SR_COP1), 12290 gen_rtx_REG (SImode, GP_REG_FIRST))); 12291 } 12292 else 12293 { 12294 if (step1 != 0) 12295 { 12296 rtx insn = gen_add3_insn (stack_pointer_rtx, 12297 stack_pointer_rtx, 12298 GEN_INT (-step1)); 12299 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; 12300 mips_frame_barrier (); 12301 size -= step1; 12302 } 12303 } 12304 mips_for_each_saved_acc (size, mips_save_reg); 12305 mips_for_each_saved_gpr_and_fpr (size, mips_save_reg); 12306 } 12307 } 12308 12309 /* Allocate the rest of the frame. */ 12310 if (size > 0) 12311 { 12312 if (SMALL_OPERAND (-size)) 12313 RTX_FRAME_RELATED_P (emit_insn (gen_add3_insn (stack_pointer_rtx, 12314 stack_pointer_rtx, 12315 GEN_INT (-size)))) = 1; 12316 else 12317 { 12318 mips_emit_move (MIPS_PROLOGUE_TEMP (Pmode), GEN_INT (size)); 12319 if (TARGET_MIPS16) 12320 { 12321 /* There are no instructions to add or subtract registers 12322 from the stack pointer, so use the frame pointer as a 12323 temporary. We should always be using a frame pointer 12324 in this case anyway. */ 12325 gcc_assert (frame_pointer_needed); 12326 mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx); 12327 emit_insn (gen_sub3_insn (hard_frame_pointer_rtx, 12328 hard_frame_pointer_rtx, 12329 MIPS_PROLOGUE_TEMP (Pmode))); 12330 mips_emit_move (stack_pointer_rtx, hard_frame_pointer_rtx); 12331 } 12332 else 12333 emit_insn (gen_sub3_insn (stack_pointer_rtx, 12334 stack_pointer_rtx, 12335 MIPS_PROLOGUE_TEMP (Pmode))); 12336 12337 /* Describe the combined effect of the previous instructions. */ 12338 mips_set_frame_expr 12339 (gen_rtx_SET (stack_pointer_rtx, 12340 plus_constant (Pmode, stack_pointer_rtx, -size))); 12341 } 12342 mips_frame_barrier (); 12343 } 12344 12345 /* Set up the frame pointer, if we're using one. */ 12346 if (frame_pointer_needed) 12347 { 12348 HOST_WIDE_INT offset; 12349 12350 offset = frame->hard_frame_pointer_offset; 12351 if (offset == 0) 12352 { 12353 rtx insn = mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx); 12354 RTX_FRAME_RELATED_P (insn) = 1; 12355 } 12356 else if (SMALL_OPERAND (offset)) 12357 { 12358 rtx insn = gen_add3_insn (hard_frame_pointer_rtx, 12359 stack_pointer_rtx, GEN_INT (offset)); 12360 RTX_FRAME_RELATED_P (emit_insn (insn)) = 1; 12361 } 12362 else 12363 { 12364 mips_emit_move (MIPS_PROLOGUE_TEMP (Pmode), GEN_INT (offset)); 12365 mips_emit_move (hard_frame_pointer_rtx, stack_pointer_rtx); 12366 emit_insn (gen_add3_insn (hard_frame_pointer_rtx, 12367 hard_frame_pointer_rtx, 12368 MIPS_PROLOGUE_TEMP (Pmode))); 12369 mips_set_frame_expr 12370 (gen_rtx_SET (hard_frame_pointer_rtx, 12371 plus_constant (Pmode, stack_pointer_rtx, offset))); 12372 } 12373 } 12374 12375 mips_emit_loadgp (); 12376 12377 /* Initialize the $gp save slot. */ 12378 if (mips_cfun_has_cprestore_slot_p ()) 12379 { 12380 rtx base, mem, gp, temp; 12381 HOST_WIDE_INT offset; 12382 12383 mips_get_cprestore_base_and_offset (&base, &offset, false); 12384 mem = gen_frame_mem (Pmode, plus_constant (Pmode, base, offset)); 12385 gp = TARGET_MIPS16 ? MIPS16_PIC_TEMP : pic_offset_table_rtx; 12386 temp = (SMALL_OPERAND (offset) 12387 ? gen_rtx_SCRATCH (Pmode) 12388 : MIPS_PROLOGUE_TEMP (Pmode)); 12389 emit_insn (PMODE_INSN (gen_potential_cprestore, 12390 (mem, GEN_INT (offset), gp, temp))); 12391 12392 mips_get_cprestore_base_and_offset (&base, &offset, true); 12393 mem = gen_frame_mem (Pmode, plus_constant (Pmode, base, offset)); 12394 emit_insn (PMODE_INSN (gen_use_cprestore, (mem))); 12395 } 12396 12397 /* We need to search back to the last use of K0 or K1. */ 12398 if (cfun->machine->interrupt_handler_p) 12399 { 12400 rtx_insn *insn; 12401 for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn)) 12402 if (INSN_P (insn) 12403 && mips_refers_to_kernel_reg_p (PATTERN (insn))) 12404 break; 12405 /* Emit a move from K1 to COP0 Status after insn. */ 12406 gcc_assert (insn != NULL_RTX); 12407 emit_insn_after (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM), 12408 gen_rtx_REG (SImode, K1_REG_NUM)), 12409 insn); 12410 } 12411 12412 /* If we are profiling, make sure no instructions are scheduled before 12413 the call to mcount. */ 12414 if (crtl->profile) 12415 emit_insn (gen_blockage ()); 12416 } 12417 12418 /* Attach all pending register saves to the previous instruction. 12419 Return that instruction. */ 12420 12421 static rtx_insn * 12422 mips_epilogue_emit_cfa_restores (void) 12423 { 12424 rtx_insn *insn; 12425 12426 insn = get_last_insn (); 12427 if (mips_epilogue.cfa_restores) 12428 { 12429 gcc_assert (insn && !REG_NOTES (insn)); 12430 RTX_FRAME_RELATED_P (insn) = 1; 12431 REG_NOTES (insn) = mips_epilogue.cfa_restores; 12432 mips_epilogue.cfa_restores = 0; 12433 } 12434 return insn; 12435 } 12436 12437 /* Like mips_epilogue_emit_cfa_restores, but also record that the CFA is 12438 now at REG + OFFSET. */ 12439 12440 static void 12441 mips_epilogue_set_cfa (rtx reg, HOST_WIDE_INT offset) 12442 { 12443 rtx_insn *insn; 12444 12445 insn = mips_epilogue_emit_cfa_restores (); 12446 if (reg != mips_epilogue.cfa_reg || offset != mips_epilogue.cfa_offset) 12447 { 12448 RTX_FRAME_RELATED_P (insn) = 1; 12449 REG_NOTES (insn) = alloc_reg_note (REG_CFA_DEF_CFA, 12450 plus_constant (Pmode, reg, offset), 12451 REG_NOTES (insn)); 12452 mips_epilogue.cfa_reg = reg; 12453 mips_epilogue.cfa_offset = offset; 12454 } 12455 } 12456 12457 /* Emit instructions to restore register REG from slot MEM. Also update 12458 the cfa_restores list. */ 12459 12460 static void 12461 mips_restore_reg (rtx reg, rtx mem) 12462 { 12463 /* There's no MIPS16 instruction to load $31 directly. Load into 12464 $7 instead and adjust the return insn appropriately. */ 12465 if (TARGET_MIPS16 && REGNO (reg) == RETURN_ADDR_REGNUM) 12466 reg = gen_rtx_REG (GET_MODE (reg), GP_REG_FIRST + 7); 12467 else if (GET_MODE (reg) == DFmode 12468 && (!TARGET_FLOAT64 12469 || mips_abi == ABI_32)) 12470 { 12471 mips_add_cfa_restore (mips_subword (reg, true)); 12472 mips_add_cfa_restore (mips_subword (reg, false)); 12473 } 12474 else 12475 mips_add_cfa_restore (reg); 12476 12477 mips_emit_save_slot_move (reg, mem, MIPS_EPILOGUE_TEMP (GET_MODE (reg))); 12478 if (REGNO (reg) == REGNO (mips_epilogue.cfa_reg)) 12479 /* The CFA is currently defined in terms of the register whose 12480 value we have just restored. Redefine the CFA in terms of 12481 the stack pointer. */ 12482 mips_epilogue_set_cfa (stack_pointer_rtx, 12483 mips_epilogue.cfa_restore_sp_offset); 12484 } 12485 12486 /* Emit code to set the stack pointer to BASE + OFFSET, given that 12487 BASE + OFFSET is NEW_FRAME_SIZE bytes below the top of the frame. 12488 BASE, if not the stack pointer, is available as a temporary. */ 12489 12490 static void 12491 mips_deallocate_stack (rtx base, rtx offset, HOST_WIDE_INT new_frame_size) 12492 { 12493 if (base == stack_pointer_rtx && offset == const0_rtx) 12494 return; 12495 12496 mips_frame_barrier (); 12497 if (offset == const0_rtx) 12498 { 12499 emit_move_insn (stack_pointer_rtx, base); 12500 mips_epilogue_set_cfa (stack_pointer_rtx, new_frame_size); 12501 } 12502 else if (TARGET_MIPS16 && base != stack_pointer_rtx) 12503 { 12504 emit_insn (gen_add3_insn (base, base, offset)); 12505 mips_epilogue_set_cfa (base, new_frame_size); 12506 emit_move_insn (stack_pointer_rtx, base); 12507 } 12508 else 12509 { 12510 emit_insn (gen_add3_insn (stack_pointer_rtx, base, offset)); 12511 mips_epilogue_set_cfa (stack_pointer_rtx, new_frame_size); 12512 } 12513 } 12514 12515 /* Emit any instructions needed before a return. */ 12516 12517 void 12518 mips_expand_before_return (void) 12519 { 12520 /* When using a call-clobbered gp, we start out with unified call 12521 insns that include instructions to restore the gp. We then split 12522 these unified calls after reload. These split calls explicitly 12523 clobber gp, so there is no need to define 12524 PIC_OFFSET_TABLE_REG_CALL_CLOBBERED. 12525 12526 For consistency, we should also insert an explicit clobber of $28 12527 before return insns, so that the post-reload optimizers know that 12528 the register is not live on exit. */ 12529 if (TARGET_CALL_CLOBBERED_GP) 12530 emit_clobber (pic_offset_table_rtx); 12531 } 12532 12533 /* Expand an "epilogue" or "sibcall_epilogue" pattern; SIBCALL_P 12534 says which. */ 12535 12536 void 12537 mips_expand_epilogue (bool sibcall_p) 12538 { 12539 const struct mips_frame_info *frame; 12540 HOST_WIDE_INT step1, step2; 12541 rtx base, adjust; 12542 rtx_insn *insn; 12543 bool use_jraddiusp_p = false; 12544 12545 if (!sibcall_p && mips_can_use_return_insn ()) 12546 { 12547 emit_jump_insn (gen_return ()); 12548 return; 12549 } 12550 12551 /* In MIPS16 mode, if the return value should go into a floating-point 12552 register, we need to call a helper routine to copy it over. */ 12553 if (mips16_cfun_returns_in_fpr_p ()) 12554 mips16_copy_fpr_return_value (); 12555 12556 /* Split the frame into two. STEP1 is the amount of stack we should 12557 deallocate before restoring the registers. STEP2 is the amount we 12558 should deallocate afterwards. 12559 12560 Start off by assuming that no registers need to be restored. */ 12561 frame = &cfun->machine->frame; 12562 step1 = frame->total_size; 12563 step2 = 0; 12564 12565 /* Work out which register holds the frame address. */ 12566 if (!frame_pointer_needed) 12567 base = stack_pointer_rtx; 12568 else 12569 { 12570 base = hard_frame_pointer_rtx; 12571 step1 -= frame->hard_frame_pointer_offset; 12572 } 12573 mips_epilogue.cfa_reg = base; 12574 mips_epilogue.cfa_offset = step1; 12575 mips_epilogue.cfa_restores = NULL_RTX; 12576 12577 /* If we need to restore registers, deallocate as much stack as 12578 possible in the second step without going out of range. */ 12579 if ((frame->mask | frame->fmask | frame->acc_mask) != 0 12580 || frame->num_cop0_regs > 0) 12581 { 12582 step2 = MIN (step1, MIPS_MAX_FIRST_STACK_STEP); 12583 step1 -= step2; 12584 } 12585 12586 /* Get an rtx for STEP1 that we can add to BASE. */ 12587 adjust = GEN_INT (step1); 12588 if (!SMALL_OPERAND (step1)) 12589 { 12590 mips_emit_move (MIPS_EPILOGUE_TEMP (Pmode), adjust); 12591 adjust = MIPS_EPILOGUE_TEMP (Pmode); 12592 } 12593 mips_deallocate_stack (base, adjust, step2); 12594 12595 /* If we're using addressing macros, $gp is implicitly used by all 12596 SYMBOL_REFs. We must emit a blockage insn before restoring $gp 12597 from the stack. */ 12598 if (TARGET_CALL_SAVED_GP && !TARGET_EXPLICIT_RELOCS) 12599 emit_insn (gen_blockage ()); 12600 12601 mips_epilogue.cfa_restore_sp_offset = step2; 12602 if (GENERATE_MIPS16E_SAVE_RESTORE && frame->mask != 0) 12603 { 12604 unsigned int regno, mask; 12605 HOST_WIDE_INT offset; 12606 rtx restore; 12607 12608 /* Generate the restore instruction. */ 12609 mask = frame->mask; 12610 restore = mips16e_build_save_restore (true, &mask, &offset, 0, step2); 12611 12612 /* Restore any other registers manually. */ 12613 for (regno = GP_REG_FIRST; regno < GP_REG_LAST; regno++) 12614 if (BITSET_P (mask, regno - GP_REG_FIRST)) 12615 { 12616 offset -= UNITS_PER_WORD; 12617 mips_save_restore_reg (word_mode, regno, offset, mips_restore_reg); 12618 } 12619 12620 /* Restore the remaining registers and deallocate the final bit 12621 of the frame. */ 12622 mips_frame_barrier (); 12623 emit_insn (restore); 12624 mips_epilogue_set_cfa (stack_pointer_rtx, 0); 12625 } 12626 else 12627 { 12628 /* Restore the registers. */ 12629 mips_for_each_saved_acc (frame->total_size - step2, mips_restore_reg); 12630 mips_for_each_saved_gpr_and_fpr (frame->total_size - step2, 12631 mips_restore_reg); 12632 12633 if (cfun->machine->interrupt_handler_p) 12634 { 12635 HOST_WIDE_INT offset; 12636 rtx mem; 12637 12638 offset = frame->cop0_sp_offset - (frame->total_size - step2); 12639 12640 /* Restore the original EPC. */ 12641 mem = gen_frame_mem (word_mode, 12642 plus_constant (Pmode, stack_pointer_rtx, 12643 offset)); 12644 mips_emit_move (gen_rtx_REG (word_mode, K1_REG_NUM), mem); 12645 offset -= UNITS_PER_WORD; 12646 12647 /* Move to COP0 EPC. */ 12648 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_EPC_REG_NUM), 12649 gen_rtx_REG (SImode, K1_REG_NUM))); 12650 12651 /* Restore the original Status. */ 12652 mem = gen_frame_mem (word_mode, 12653 plus_constant (Pmode, stack_pointer_rtx, 12654 offset)); 12655 mips_emit_move (gen_rtx_REG (word_mode, K1_REG_NUM), mem); 12656 offset -= UNITS_PER_WORD; 12657 12658 /* If we don't use shadow register set, we need to update SP. */ 12659 if (cfun->machine->use_shadow_register_set == SHADOW_SET_NO) 12660 mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0); 12661 else 12662 /* The choice of position is somewhat arbitrary in this case. */ 12663 mips_epilogue_emit_cfa_restores (); 12664 12665 /* Move to COP0 Status. */ 12666 emit_insn (gen_cop0_move (gen_rtx_REG (SImode, COP0_STATUS_REG_NUM), 12667 gen_rtx_REG (SImode, K1_REG_NUM))); 12668 } 12669 else if (TARGET_MICROMIPS 12670 && !crtl->calls_eh_return 12671 && !sibcall_p 12672 && step2 > 0 12673 && mips_unsigned_immediate_p (step2, 5, 2)) 12674 use_jraddiusp_p = true; 12675 else 12676 /* Deallocate the final bit of the frame. */ 12677 mips_deallocate_stack (stack_pointer_rtx, GEN_INT (step2), 0); 12678 } 12679 12680 if (cfun->machine->use_frame_header_for_callee_saved_regs) 12681 mips_epilogue_emit_cfa_restores (); 12682 else if (!use_jraddiusp_p) 12683 gcc_assert (!mips_epilogue.cfa_restores); 12684 12685 /* Add in the __builtin_eh_return stack adjustment. We need to 12686 use a temporary in MIPS16 code. */ 12687 if (crtl->calls_eh_return) 12688 { 12689 if (TARGET_MIPS16) 12690 { 12691 mips_emit_move (MIPS_EPILOGUE_TEMP (Pmode), stack_pointer_rtx); 12692 emit_insn (gen_add3_insn (MIPS_EPILOGUE_TEMP (Pmode), 12693 MIPS_EPILOGUE_TEMP (Pmode), 12694 EH_RETURN_STACKADJ_RTX)); 12695 mips_emit_move (stack_pointer_rtx, MIPS_EPILOGUE_TEMP (Pmode)); 12696 } 12697 else 12698 emit_insn (gen_add3_insn (stack_pointer_rtx, 12699 stack_pointer_rtx, 12700 EH_RETURN_STACKADJ_RTX)); 12701 } 12702 12703 if (!sibcall_p) 12704 { 12705 mips_expand_before_return (); 12706 if (cfun->machine->interrupt_handler_p) 12707 { 12708 /* Interrupt handlers generate eret or deret. */ 12709 if (cfun->machine->use_debug_exception_return_p) 12710 emit_jump_insn (gen_mips_deret ()); 12711 else 12712 emit_jump_insn (gen_mips_eret ()); 12713 } 12714 else 12715 { 12716 rtx pat; 12717 12718 /* When generating MIPS16 code, the normal 12719 mips_for_each_saved_gpr_and_fpr path will restore the return 12720 address into $7 rather than $31. */ 12721 if (TARGET_MIPS16 12722 && !GENERATE_MIPS16E_SAVE_RESTORE 12723 && BITSET_P (frame->mask, RETURN_ADDR_REGNUM)) 12724 { 12725 /* simple_returns cannot rely on values that are only available 12726 on paths through the epilogue (because return paths that do 12727 not pass through the epilogue may nevertheless reuse a 12728 simple_return that occurs at the end of the epilogue). 12729 Use a normal return here instead. */ 12730 rtx reg = gen_rtx_REG (Pmode, GP_REG_FIRST + 7); 12731 pat = gen_return_internal (reg); 12732 } 12733 else if (use_jraddiusp_p) 12734 pat = gen_jraddiusp (GEN_INT (step2)); 12735 else 12736 { 12737 rtx reg = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM); 12738 pat = gen_simple_return_internal (reg); 12739 } 12740 emit_jump_insn (pat); 12741 if (use_jraddiusp_p) 12742 mips_epilogue_set_cfa (stack_pointer_rtx, step2); 12743 } 12744 } 12745 12746 /* Search from the beginning to the first use of K0 or K1. */ 12747 if (cfun->machine->interrupt_handler_p 12748 && !cfun->machine->keep_interrupts_masked_p) 12749 { 12750 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn)) 12751 if (INSN_P (insn) 12752 && mips_refers_to_kernel_reg_p (PATTERN (insn))) 12753 break; 12754 gcc_assert (insn != NULL_RTX); 12755 /* Insert disable interrupts before the first use of K0 or K1. */ 12756 emit_insn_before (gen_mips_di (), insn); 12757 emit_insn_before (gen_mips_ehb (), insn); 12758 } 12759 } 12760 12761 /* Return nonzero if this function is known to have a null epilogue. 12762 This allows the optimizer to omit jumps to jumps if no stack 12763 was created. */ 12764 12765 bool 12766 mips_can_use_return_insn (void) 12767 { 12768 /* Interrupt handlers need to go through the epilogue. */ 12769 if (cfun->machine->interrupt_handler_p) 12770 return false; 12771 12772 if (!reload_completed) 12773 return false; 12774 12775 if (crtl->profile) 12776 return false; 12777 12778 /* In MIPS16 mode, a function that returns a floating-point value 12779 needs to arrange to copy the return value into the floating-point 12780 registers. */ 12781 if (mips16_cfun_returns_in_fpr_p ()) 12782 return false; 12783 12784 return (cfun->machine->frame.total_size == 0 12785 && !cfun->machine->use_frame_header_for_callee_saved_regs); 12786 } 12787 12788 /* Return true if register REGNO can store a value of mode MODE. 12789 The result of this function is cached in mips_hard_regno_mode_ok. */ 12790 12791 static bool 12792 mips_hard_regno_mode_ok_uncached (unsigned int regno, machine_mode mode) 12793 { 12794 unsigned int size; 12795 enum mode_class mclass; 12796 12797 if (mode == CCV2mode) 12798 return (ISA_HAS_8CC 12799 && ST_REG_P (regno) 12800 && (regno - ST_REG_FIRST) % 2 == 0); 12801 12802 if (mode == CCV4mode) 12803 return (ISA_HAS_8CC 12804 && ST_REG_P (regno) 12805 && (regno - ST_REG_FIRST) % 4 == 0); 12806 12807 if (mode == CCmode) 12808 return ISA_HAS_8CC ? ST_REG_P (regno) : regno == FPSW_REGNUM; 12809 12810 size = GET_MODE_SIZE (mode); 12811 mclass = GET_MODE_CLASS (mode); 12812 12813 if (GP_REG_P (regno) && mode != CCFmode && !MSA_SUPPORTED_MODE_P (mode)) 12814 return ((regno - GP_REG_FIRST) & 1) == 0 || size <= UNITS_PER_WORD; 12815 12816 /* For MSA, allow TImode and 128-bit vector modes in all FPR. */ 12817 if (FP_REG_P (regno) && MSA_SUPPORTED_MODE_P (mode)) 12818 return true; 12819 12820 if (FP_REG_P (regno) 12821 && (((regno - FP_REG_FIRST) % MAX_FPRS_PER_FMT) == 0 12822 || (MIN_FPRS_PER_FMT == 1 && size <= UNITS_PER_FPREG))) 12823 { 12824 /* Deny use of odd-numbered registers for 32-bit data for 12825 the o32 FP64A ABI. */ 12826 if (TARGET_O32_FP64A_ABI && size <= 4 && (regno & 1) != 0) 12827 return false; 12828 12829 /* The FPXX ABI requires double-precision values to be placed in 12830 even-numbered registers. Disallow odd-numbered registers with 12831 CCFmode because CCFmode double-precision compares will write a 12832 64-bit value to a register. */ 12833 if (mode == CCFmode) 12834 return !(TARGET_FLOATXX && (regno & 1) != 0); 12835 12836 /* Allow 64-bit vector modes for Loongson MultiMedia extensions 12837 Instructions (MMI). */ 12838 if (TARGET_LOONGSON_MMI 12839 && (mode == V2SImode 12840 || mode == V4HImode 12841 || mode == V8QImode 12842 || mode == DImode)) 12843 return true; 12844 12845 if (mclass == MODE_FLOAT 12846 || mclass == MODE_COMPLEX_FLOAT 12847 || mclass == MODE_VECTOR_FLOAT) 12848 return size <= UNITS_PER_FPVALUE; 12849 12850 /* Allow integer modes that fit into a single register. We need 12851 to put integers into FPRs when using instructions like CVT 12852 and TRUNC. There's no point allowing sizes smaller than a word, 12853 because the FPU has no appropriate load/store instructions. */ 12854 if (mclass == MODE_INT) 12855 return size >= MIN_UNITS_PER_WORD && size <= UNITS_PER_FPREG; 12856 } 12857 12858 /* Don't allow vector modes in accumulators. */ 12859 if (ACC_REG_P (regno) 12860 && !VECTOR_MODE_P (mode) 12861 && (INTEGRAL_MODE_P (mode) || ALL_FIXED_POINT_MODE_P (mode))) 12862 { 12863 if (MD_REG_P (regno)) 12864 { 12865 /* After a multiplication or division, clobbering HI makes 12866 the value of LO unpredictable, and vice versa. This means 12867 that, for all interesting cases, HI and LO are effectively 12868 a single register. 12869 12870 We model this by requiring that any value that uses HI 12871 also uses LO. */ 12872 if (size <= UNITS_PER_WORD * 2) 12873 return regno == (size <= UNITS_PER_WORD ? LO_REGNUM : MD_REG_FIRST); 12874 } 12875 else 12876 { 12877 /* DSP accumulators do not have the same restrictions as 12878 HI and LO, so we can treat them as normal doubleword 12879 registers. */ 12880 if (size <= UNITS_PER_WORD) 12881 return true; 12882 12883 if (size <= UNITS_PER_WORD * 2 12884 && ((regno - DSP_ACC_REG_FIRST) & 1) == 0) 12885 return true; 12886 } 12887 } 12888 12889 if (ALL_COP_REG_P (regno)) 12890 return mclass == MODE_INT && size <= UNITS_PER_WORD; 12891 12892 if (regno == GOT_VERSION_REGNUM) 12893 return mode == SImode; 12894 12895 return false; 12896 } 12897 12898 /* Implement TARGET_HARD_REGNO_MODE_OK. */ 12899 12900 static bool 12901 mips_hard_regno_mode_ok (unsigned int regno, machine_mode mode) 12902 { 12903 return mips_hard_regno_mode_ok_p[mode][regno]; 12904 } 12905 12906 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG. */ 12907 12908 bool 12909 mips_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED, 12910 unsigned int new_reg) 12911 { 12912 /* Interrupt functions can only use registers that have already been 12913 saved by the prologue, even if they would normally be call-clobbered. */ 12914 if (cfun->machine->interrupt_handler_p && !df_regs_ever_live_p (new_reg)) 12915 return false; 12916 12917 return true; 12918 } 12919 12920 /* Return nonzero if register REGNO can be used as a scratch register 12921 in peephole2. */ 12922 12923 bool 12924 mips_hard_regno_scratch_ok (unsigned int regno) 12925 { 12926 /* See mips_hard_regno_rename_ok. */ 12927 if (cfun->machine->interrupt_handler_p && !df_regs_ever_live_p (regno)) 12928 return false; 12929 12930 return true; 12931 } 12932 12933 /* Implement TARGET_HARD_REGNO_CALL_PART_CLOBBERED. Odd-numbered 12934 single-precision registers are not considered callee-saved for o32 12935 FPXX as they will be clobbered when run on an FR=1 FPU. MSA vector 12936 registers with MODE > 64 bits are part clobbered too. */ 12937 12938 static bool 12939 mips_hard_regno_call_part_clobbered (unsigned int, unsigned int regno, 12940 machine_mode mode) 12941 { 12942 if (TARGET_FLOATXX 12943 && hard_regno_nregs (regno, mode) == 1 12944 && FP_REG_P (regno) 12945 && (regno & 1) != 0) 12946 return true; 12947 12948 if (ISA_HAS_MSA && FP_REG_P (regno) && GET_MODE_SIZE (mode) > 8) 12949 return true; 12950 12951 return false; 12952 } 12953 12954 /* Implement TARGET_HARD_REGNO_NREGS. */ 12955 12956 static unsigned int 12957 mips_hard_regno_nregs (unsigned int regno, machine_mode mode) 12958 { 12959 if (ST_REG_P (regno)) 12960 /* The size of FP status registers is always 4, because they only hold 12961 CCmode values, and CCmode is always considered to be 4 bytes wide. */ 12962 return (GET_MODE_SIZE (mode) + 3) / 4; 12963 12964 if (FP_REG_P (regno)) 12965 { 12966 if (MSA_SUPPORTED_MODE_P (mode)) 12967 return 1; 12968 12969 return (GET_MODE_SIZE (mode) + UNITS_PER_FPREG - 1) / UNITS_PER_FPREG; 12970 } 12971 12972 /* All other registers are word-sized. */ 12973 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; 12974 } 12975 12976 /* Implement CLASS_MAX_NREGS, taking the maximum of the cases 12977 in mips_hard_regno_nregs. */ 12978 12979 int 12980 mips_class_max_nregs (enum reg_class rclass, machine_mode mode) 12981 { 12982 int size; 12983 HARD_REG_SET left; 12984 12985 size = 0x8000; 12986 left = reg_class_contents[rclass]; 12987 if (hard_reg_set_intersect_p (left, reg_class_contents[(int) ST_REGS])) 12988 { 12989 if (mips_hard_regno_mode_ok (ST_REG_FIRST, mode)) 12990 size = MIN (size, 4); 12991 12992 left &= ~reg_class_contents[ST_REGS]; 12993 } 12994 if (hard_reg_set_intersect_p (left, reg_class_contents[(int) FP_REGS])) 12995 { 12996 if (mips_hard_regno_mode_ok (FP_REG_FIRST, mode)) 12997 { 12998 if (MSA_SUPPORTED_MODE_P (mode)) 12999 size = MIN (size, UNITS_PER_MSA_REG); 13000 else 13001 size = MIN (size, UNITS_PER_FPREG); 13002 } 13003 13004 left &= ~reg_class_contents[FP_REGS]; 13005 } 13006 if (!hard_reg_set_empty_p (left)) 13007 size = MIN (size, UNITS_PER_WORD); 13008 return (GET_MODE_SIZE (mode) + size - 1) / size; 13009 } 13010 13011 /* Implement TARGET_CAN_CHANGE_MODE_CLASS. */ 13012 13013 static bool 13014 mips_can_change_mode_class (machine_mode from, 13015 machine_mode to, reg_class_t rclass) 13016 { 13017 /* Allow conversions between different Loongson integer vectors, 13018 and between those vectors and DImode. */ 13019 if (GET_MODE_SIZE (from) == 8 && GET_MODE_SIZE (to) == 8 13020 && INTEGRAL_MODE_P (from) && INTEGRAL_MODE_P (to)) 13021 return true; 13022 13023 /* Allow conversions between different MSA vector modes. */ 13024 if (MSA_SUPPORTED_MODE_P (from) && MSA_SUPPORTED_MODE_P (to)) 13025 return true; 13026 13027 /* Otherwise, there are several problems with changing the modes of 13028 values in floating-point registers: 13029 13030 - When a multi-word value is stored in paired floating-point 13031 registers, the first register always holds the low word. We 13032 therefore can't allow FPRs to change between single-word and 13033 multi-word modes on big-endian targets. 13034 13035 - GCC assumes that each word of a multiword register can be 13036 accessed individually using SUBREGs. This is not true for 13037 floating-point registers if they are bigger than a word. 13038 13039 - Loading a 32-bit value into a 64-bit floating-point register 13040 will not sign-extend the value, despite what LOAD_EXTEND_OP 13041 says. We can't allow FPRs to change from SImode to a wider 13042 mode on 64-bit targets. 13043 13044 - If the FPU has already interpreted a value in one format, we 13045 must not ask it to treat the value as having a different 13046 format. 13047 13048 We therefore disallow all mode changes involving FPRs. */ 13049 13050 return !reg_classes_intersect_p (FP_REGS, rclass); 13051 } 13052 13053 /* Implement target hook small_register_classes_for_mode_p. */ 13054 13055 static bool 13056 mips_small_register_classes_for_mode_p (machine_mode mode 13057 ATTRIBUTE_UNUSED) 13058 { 13059 return TARGET_MIPS16; 13060 } 13061 13062 /* Return true if moves in mode MODE can use the FPU's mov.fmt instruction, 13063 or use the MSA's move.v instruction. */ 13064 13065 static bool 13066 mips_mode_ok_for_mov_fmt_p (machine_mode mode) 13067 { 13068 switch (mode) 13069 { 13070 case E_CCFmode: 13071 case E_SFmode: 13072 return TARGET_HARD_FLOAT; 13073 13074 case E_DFmode: 13075 return TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT; 13076 13077 case E_V2SFmode: 13078 return TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT; 13079 13080 default: 13081 return MSA_SUPPORTED_MODE_P (mode); 13082 } 13083 } 13084 13085 /* Implement TARGET_MODES_TIEABLE_P. */ 13086 13087 static bool 13088 mips_modes_tieable_p (machine_mode mode1, machine_mode mode2) 13089 { 13090 /* FPRs allow no mode punning, so it's not worth tying modes if we'd 13091 prefer to put one of them in FPRs. */ 13092 return (mode1 == mode2 13093 || (!mips_mode_ok_for_mov_fmt_p (mode1) 13094 && !mips_mode_ok_for_mov_fmt_p (mode2))); 13095 } 13096 13097 /* Implement TARGET_PREFERRED_RELOAD_CLASS. */ 13098 13099 static reg_class_t 13100 mips_preferred_reload_class (rtx x, reg_class_t rclass) 13101 { 13102 if (mips_dangerous_for_la25_p (x) && reg_class_subset_p (LEA_REGS, rclass)) 13103 return LEA_REGS; 13104 13105 if (reg_class_subset_p (FP_REGS, rclass) 13106 && mips_mode_ok_for_mov_fmt_p (GET_MODE (x))) 13107 return FP_REGS; 13108 13109 if (reg_class_subset_p (GR_REGS, rclass)) 13110 rclass = GR_REGS; 13111 13112 if (TARGET_MIPS16 && reg_class_subset_p (M16_REGS, rclass)) 13113 rclass = M16_REGS; 13114 13115 return rclass; 13116 } 13117 13118 /* RCLASS is a class involved in a REGISTER_MOVE_COST calculation. 13119 Return a "canonical" class to represent it in later calculations. */ 13120 13121 static reg_class_t 13122 mips_canonicalize_move_class (reg_class_t rclass) 13123 { 13124 /* All moves involving accumulator registers have the same cost. */ 13125 if (reg_class_subset_p (rclass, ACC_REGS)) 13126 rclass = ACC_REGS; 13127 13128 /* Likewise promote subclasses of general registers to the most 13129 interesting containing class. */ 13130 if (TARGET_MIPS16 && reg_class_subset_p (rclass, M16_REGS)) 13131 rclass = M16_REGS; 13132 else if (reg_class_subset_p (rclass, GENERAL_REGS)) 13133 rclass = GENERAL_REGS; 13134 13135 return rclass; 13136 } 13137 13138 /* Return the cost of moving a value from a register of class FROM to a GPR. 13139 Return 0 for classes that are unions of other classes handled by this 13140 function. */ 13141 13142 static int 13143 mips_move_to_gpr_cost (reg_class_t from) 13144 { 13145 switch (from) 13146 { 13147 case M16_REGS: 13148 case GENERAL_REGS: 13149 /* A MIPS16 MOVE instruction, or a non-MIPS16 MOVE macro. */ 13150 return 2; 13151 13152 case ACC_REGS: 13153 /* MFLO and MFHI. */ 13154 return 6; 13155 13156 case FP_REGS: 13157 /* MFC1, etc. */ 13158 return 4; 13159 13160 case COP0_REGS: 13161 case COP2_REGS: 13162 case COP3_REGS: 13163 /* This choice of value is historical. */ 13164 return 5; 13165 13166 default: 13167 return 0; 13168 } 13169 } 13170 13171 /* Return the cost of moving a value from a GPR to a register of class TO. 13172 Return 0 for classes that are unions of other classes handled by this 13173 function. */ 13174 13175 static int 13176 mips_move_from_gpr_cost (reg_class_t to) 13177 { 13178 switch (to) 13179 { 13180 case M16_REGS: 13181 case GENERAL_REGS: 13182 /* A MIPS16 MOVE instruction, or a non-MIPS16 MOVE macro. */ 13183 return 2; 13184 13185 case ACC_REGS: 13186 /* MTLO and MTHI. */ 13187 return 6; 13188 13189 case FP_REGS: 13190 /* MTC1, etc. */ 13191 return 4; 13192 13193 case COP0_REGS: 13194 case COP2_REGS: 13195 case COP3_REGS: 13196 /* This choice of value is historical. */ 13197 return 5; 13198 13199 default: 13200 return 0; 13201 } 13202 } 13203 13204 /* Implement TARGET_REGISTER_MOVE_COST. Return 0 for classes that are the 13205 maximum of the move costs for subclasses; regclass will work out 13206 the maximum for us. */ 13207 13208 static int 13209 mips_register_move_cost (machine_mode mode, 13210 reg_class_t from, reg_class_t to) 13211 { 13212 reg_class_t dregs; 13213 int cost1, cost2; 13214 13215 from = mips_canonicalize_move_class (from); 13216 to = mips_canonicalize_move_class (to); 13217 13218 /* Handle moves that can be done without using general-purpose registers. */ 13219 if (from == FP_REGS) 13220 { 13221 if (to == FP_REGS && mips_mode_ok_for_mov_fmt_p (mode)) 13222 /* MOV.FMT. */ 13223 return 4; 13224 } 13225 13226 /* Handle cases in which only one class deviates from the ideal. */ 13227 dregs = TARGET_MIPS16 ? M16_REGS : GENERAL_REGS; 13228 if (from == dregs) 13229 return mips_move_from_gpr_cost (to); 13230 if (to == dregs) 13231 return mips_move_to_gpr_cost (from); 13232 13233 /* Handles cases that require a GPR temporary. */ 13234 cost1 = mips_move_to_gpr_cost (from); 13235 if (cost1 != 0) 13236 { 13237 cost2 = mips_move_from_gpr_cost (to); 13238 if (cost2 != 0) 13239 return cost1 + cost2; 13240 } 13241 13242 return 0; 13243 } 13244 13245 /* Implement TARGET_REGISTER_PRIORITY. */ 13246 13247 static int 13248 mips_register_priority (int hard_regno) 13249 { 13250 /* Treat MIPS16 registers with higher priority than other regs. */ 13251 if (TARGET_MIPS16 13252 && TEST_HARD_REG_BIT (reg_class_contents[M16_REGS], hard_regno)) 13253 return 1; 13254 return 0; 13255 } 13256 13257 /* Implement TARGET_MEMORY_MOVE_COST. */ 13258 13259 static int 13260 mips_memory_move_cost (machine_mode mode, reg_class_t rclass, bool in) 13261 { 13262 return (mips_cost->memory_latency 13263 + memory_move_secondary_cost (mode, rclass, in)); 13264 } 13265 13266 /* Implement TARGET_SECONDARY_MEMORY_NEEDED. 13267 13268 When targeting the o32 FPXX ABI, all moves with a length of doubleword 13269 or greater must be performed by FR-mode-aware instructions. 13270 This can be achieved using MFHC1/MTHC1 when these instructions are 13271 available but otherwise moves must go via memory. 13272 For the o32 FP64A ABI, all odd-numbered moves with a length of 13273 doubleword or greater are required to use memory. Using MTC1/MFC1 13274 to access the lower-half of these registers would require a forbidden 13275 single-precision access. We require all double-word moves to use 13276 memory because adding even and odd floating-point registers classes 13277 would have a significant impact on the backend. */ 13278 13279 static bool 13280 mips_secondary_memory_needed (machine_mode mode, reg_class_t class1, 13281 reg_class_t class2) 13282 { 13283 /* Ignore spilled pseudos. */ 13284 if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS)) 13285 return false; 13286 13287 if (((class1 == FP_REGS) != (class2 == FP_REGS)) 13288 && ((TARGET_FLOATXX && !ISA_HAS_MXHC1) 13289 || TARGET_O32_FP64A_ABI) 13290 && GET_MODE_SIZE (mode) >= 8) 13291 return true; 13292 13293 return false; 13294 } 13295 13296 /* Return the register class required for a secondary register when 13297 copying between one of the registers in RCLASS and value X, which 13298 has mode MODE. X is the source of the move if IN_P, otherwise it 13299 is the destination. Return NO_REGS if no secondary register is 13300 needed. */ 13301 13302 enum reg_class 13303 mips_secondary_reload_class (enum reg_class rclass, 13304 machine_mode mode, rtx x, bool) 13305 { 13306 int regno; 13307 13308 /* If X is a constant that cannot be loaded into $25, it must be loaded 13309 into some other GPR. No other register class allows a direct move. */ 13310 if (mips_dangerous_for_la25_p (x)) 13311 return reg_class_subset_p (rclass, LEA_REGS) ? NO_REGS : LEA_REGS; 13312 13313 regno = true_regnum (x); 13314 if (TARGET_MIPS16) 13315 { 13316 /* In MIPS16 mode, every move must involve a member of M16_REGS. */ 13317 if (!reg_class_subset_p (rclass, M16_REGS) && !M16_REG_P (regno)) 13318 return M16_REGS; 13319 13320 return NO_REGS; 13321 } 13322 13323 /* Copying from accumulator registers to anywhere other than a general 13324 register requires a temporary general register. */ 13325 if (reg_class_subset_p (rclass, ACC_REGS)) 13326 return GP_REG_P (regno) ? NO_REGS : GR_REGS; 13327 if (ACC_REG_P (regno)) 13328 return reg_class_subset_p (rclass, GR_REGS) ? NO_REGS : GR_REGS; 13329 13330 if (reg_class_subset_p (rclass, FP_REGS)) 13331 { 13332 if (regno < 0 13333 || (MEM_P (x) 13334 && (GET_MODE_SIZE (mode) == 4 || GET_MODE_SIZE (mode) == 8))) 13335 /* In this case we can use lwc1, swc1, ldc1 or sdc1. We'll use 13336 pairs of lwc1s and swc1s if ldc1 and sdc1 are not supported. */ 13337 return NO_REGS; 13338 13339 if (MEM_P (x) && MSA_SUPPORTED_MODE_P (mode)) 13340 /* In this case we can use MSA LD.* and ST.*. */ 13341 return NO_REGS; 13342 13343 if (GP_REG_P (regno) || x == CONST0_RTX (mode)) 13344 /* In this case we can use mtc1, mfc1, dmtc1 or dmfc1. */ 13345 return NO_REGS; 13346 13347 if (CONSTANT_P (x) && !targetm.cannot_force_const_mem (mode, x)) 13348 /* We can force the constant to memory and use lwc1 13349 and ldc1. As above, we will use pairs of lwc1s if 13350 ldc1 is not supported. */ 13351 return NO_REGS; 13352 13353 if (FP_REG_P (regno) && mips_mode_ok_for_mov_fmt_p (mode)) 13354 /* In this case we can use mov.fmt. */ 13355 return NO_REGS; 13356 13357 /* Otherwise, we need to reload through an integer register. */ 13358 return GR_REGS; 13359 } 13360 if (FP_REG_P (regno)) 13361 return reg_class_subset_p (rclass, GR_REGS) ? NO_REGS : GR_REGS; 13362 13363 return NO_REGS; 13364 } 13365 13366 /* Implement TARGET_MODE_REP_EXTENDED. */ 13367 13368 static int 13369 mips_mode_rep_extended (scalar_int_mode mode, scalar_int_mode mode_rep) 13370 { 13371 /* On 64-bit targets, SImode register values are sign-extended to DImode. */ 13372 if (TARGET_64BIT && mode == SImode && mode_rep == DImode) 13373 return SIGN_EXTEND; 13374 13375 return UNKNOWN; 13376 } 13377 13378 /* Implement TARGET_VALID_POINTER_MODE. */ 13379 13380 static bool 13381 mips_valid_pointer_mode (scalar_int_mode mode) 13382 { 13383 return mode == SImode || (TARGET_64BIT && mode == DImode); 13384 } 13385 13386 /* Implement TARGET_VECTOR_MODE_SUPPORTED_P. */ 13387 13388 static bool 13389 mips_vector_mode_supported_p (machine_mode mode) 13390 { 13391 switch (mode) 13392 { 13393 case E_V2SFmode: 13394 return TARGET_PAIRED_SINGLE_FLOAT; 13395 13396 case E_V2HImode: 13397 case E_V4QImode: 13398 case E_V2HQmode: 13399 case E_V2UHQmode: 13400 case E_V2HAmode: 13401 case E_V2UHAmode: 13402 case E_V4QQmode: 13403 case E_V4UQQmode: 13404 return TARGET_DSP; 13405 13406 case E_V2SImode: 13407 case E_V4HImode: 13408 case E_V8QImode: 13409 return TARGET_LOONGSON_MMI; 13410 13411 default: 13412 return MSA_SUPPORTED_MODE_P (mode); 13413 } 13414 } 13415 13416 /* Implement TARGET_SCALAR_MODE_SUPPORTED_P. */ 13417 13418 static bool 13419 mips_scalar_mode_supported_p (scalar_mode mode) 13420 { 13421 if (ALL_FIXED_POINT_MODE_P (mode) 13422 && GET_MODE_PRECISION (mode) <= 2 * BITS_PER_WORD) 13423 return true; 13424 13425 return default_scalar_mode_supported_p (mode); 13426 } 13427 13428 /* Implement TARGET_VECTORIZE_PREFERRED_SIMD_MODE. */ 13429 13430 static machine_mode 13431 mips_preferred_simd_mode (scalar_mode mode) 13432 { 13433 if (TARGET_PAIRED_SINGLE_FLOAT 13434 && mode == SFmode) 13435 return V2SFmode; 13436 13437 if (!ISA_HAS_MSA) 13438 return word_mode; 13439 13440 switch (mode) 13441 { 13442 case E_QImode: 13443 return V16QImode; 13444 case E_HImode: 13445 return V8HImode; 13446 case E_SImode: 13447 return V4SImode; 13448 case E_DImode: 13449 return V2DImode; 13450 13451 case E_SFmode: 13452 return V4SFmode; 13453 13454 case E_DFmode: 13455 return V2DFmode; 13456 13457 default: 13458 break; 13459 } 13460 return word_mode; 13461 } 13462 13463 /* Implement TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES. */ 13464 13465 static unsigned int 13466 mips_autovectorize_vector_modes (vector_modes *modes, bool) 13467 { 13468 if (ISA_HAS_MSA) 13469 modes->safe_push (V16QImode); 13470 return 0; 13471 } 13472 13473 /* Implement TARGET_INIT_LIBFUNCS. */ 13474 13475 static void 13476 mips_init_libfuncs (void) 13477 { 13478 if (TARGET_FIX_VR4120) 13479 { 13480 /* Register the special divsi3 and modsi3 functions needed to work 13481 around VR4120 division errata. */ 13482 set_optab_libfunc (sdiv_optab, SImode, "__vr4120_divsi3"); 13483 set_optab_libfunc (smod_optab, SImode, "__vr4120_modsi3"); 13484 } 13485 13486 if (TARGET_MIPS16 && TARGET_HARD_FLOAT_ABI) 13487 { 13488 /* Register the MIPS16 -mhard-float stubs. */ 13489 set_optab_libfunc (add_optab, SFmode, "__mips16_addsf3"); 13490 set_optab_libfunc (sub_optab, SFmode, "__mips16_subsf3"); 13491 set_optab_libfunc (smul_optab, SFmode, "__mips16_mulsf3"); 13492 set_optab_libfunc (sdiv_optab, SFmode, "__mips16_divsf3"); 13493 13494 set_optab_libfunc (eq_optab, SFmode, "__mips16_eqsf2"); 13495 set_optab_libfunc (ne_optab, SFmode, "__mips16_nesf2"); 13496 set_optab_libfunc (gt_optab, SFmode, "__mips16_gtsf2"); 13497 set_optab_libfunc (ge_optab, SFmode, "__mips16_gesf2"); 13498 set_optab_libfunc (lt_optab, SFmode, "__mips16_ltsf2"); 13499 set_optab_libfunc (le_optab, SFmode, "__mips16_lesf2"); 13500 set_optab_libfunc (unord_optab, SFmode, "__mips16_unordsf2"); 13501 13502 set_conv_libfunc (sfix_optab, SImode, SFmode, "__mips16_fix_truncsfsi"); 13503 set_conv_libfunc (sfloat_optab, SFmode, SImode, "__mips16_floatsisf"); 13504 set_conv_libfunc (ufloat_optab, SFmode, SImode, "__mips16_floatunsisf"); 13505 13506 if (TARGET_DOUBLE_FLOAT) 13507 { 13508 set_optab_libfunc (add_optab, DFmode, "__mips16_adddf3"); 13509 set_optab_libfunc (sub_optab, DFmode, "__mips16_subdf3"); 13510 set_optab_libfunc (smul_optab, DFmode, "__mips16_muldf3"); 13511 set_optab_libfunc (sdiv_optab, DFmode, "__mips16_divdf3"); 13512 13513 set_optab_libfunc (eq_optab, DFmode, "__mips16_eqdf2"); 13514 set_optab_libfunc (ne_optab, DFmode, "__mips16_nedf2"); 13515 set_optab_libfunc (gt_optab, DFmode, "__mips16_gtdf2"); 13516 set_optab_libfunc (ge_optab, DFmode, "__mips16_gedf2"); 13517 set_optab_libfunc (lt_optab, DFmode, "__mips16_ltdf2"); 13518 set_optab_libfunc (le_optab, DFmode, "__mips16_ledf2"); 13519 set_optab_libfunc (unord_optab, DFmode, "__mips16_unorddf2"); 13520 13521 set_conv_libfunc (sext_optab, DFmode, SFmode, 13522 "__mips16_extendsfdf2"); 13523 set_conv_libfunc (trunc_optab, SFmode, DFmode, 13524 "__mips16_truncdfsf2"); 13525 set_conv_libfunc (sfix_optab, SImode, DFmode, 13526 "__mips16_fix_truncdfsi"); 13527 set_conv_libfunc (sfloat_optab, DFmode, SImode, 13528 "__mips16_floatsidf"); 13529 set_conv_libfunc (ufloat_optab, DFmode, SImode, 13530 "__mips16_floatunsidf"); 13531 } 13532 } 13533 13534 /* The MIPS16 ISA does not have an encoding for "sync", so we rely 13535 on an external non-MIPS16 routine to implement __sync_synchronize. 13536 Similarly for the rest of the ll/sc libfuncs. */ 13537 if (TARGET_MIPS16) 13538 { 13539 synchronize_libfunc = init_one_libfunc ("__sync_synchronize"); 13540 init_sync_libfuncs (UNITS_PER_WORD); 13541 } 13542 } 13543 13544 /* Build up a multi-insn sequence that loads label TARGET into $AT. */ 13545 13546 static void 13547 mips_process_load_label (rtx target) 13548 { 13549 rtx base, gp, intop; 13550 HOST_WIDE_INT offset; 13551 13552 mips_multi_start (); 13553 switch (mips_abi) 13554 { 13555 case ABI_N32: 13556 mips_multi_add_insn ("lw\t%@,%%got_page(%0)(%+)", target, 0); 13557 mips_multi_add_insn ("addiu\t%@,%@,%%got_ofst(%0)", target, 0); 13558 break; 13559 13560 case ABI_64: 13561 mips_multi_add_insn ("ld\t%@,%%got_page(%0)(%+)", target, 0); 13562 mips_multi_add_insn ("daddiu\t%@,%@,%%got_ofst(%0)", target, 0); 13563 break; 13564 13565 default: 13566 gp = pic_offset_table_rtx; 13567 if (mips_cfun_has_cprestore_slot_p ()) 13568 { 13569 gp = gen_rtx_REG (Pmode, AT_REGNUM); 13570 mips_get_cprestore_base_and_offset (&base, &offset, true); 13571 if (!SMALL_OPERAND (offset)) 13572 { 13573 intop = GEN_INT (CONST_HIGH_PART (offset)); 13574 mips_multi_add_insn ("lui\t%0,%1", gp, intop, 0); 13575 mips_multi_add_insn ("addu\t%0,%0,%1", gp, base, 0); 13576 13577 base = gp; 13578 offset = CONST_LOW_PART (offset); 13579 } 13580 intop = GEN_INT (offset); 13581 if (ISA_HAS_LOAD_DELAY) 13582 mips_multi_add_insn ("lw\t%0,%1(%2)%#", gp, intop, base, 0); 13583 else 13584 mips_multi_add_insn ("lw\t%0,%1(%2)", gp, intop, base, 0); 13585 } 13586 if (ISA_HAS_LOAD_DELAY) 13587 mips_multi_add_insn ("lw\t%@,%%got(%0)(%1)%#", target, gp, 0); 13588 else 13589 mips_multi_add_insn ("lw\t%@,%%got(%0)(%1)", target, gp, 0); 13590 mips_multi_add_insn ("addiu\t%@,%@,%%lo(%0)", target, 0); 13591 break; 13592 } 13593 } 13594 13595 /* Return the number of instructions needed to load a label into $AT. */ 13596 13597 static unsigned int 13598 mips_load_label_num_insns (void) 13599 { 13600 if (cfun->machine->load_label_num_insns == 0) 13601 { 13602 mips_process_load_label (pc_rtx); 13603 cfun->machine->load_label_num_insns = mips_multi_num_insns; 13604 } 13605 return cfun->machine->load_label_num_insns; 13606 } 13607 13608 /* Emit an asm sequence to start a noat block and load the address 13609 of a label into $1. */ 13610 13611 void 13612 mips_output_load_label (rtx target) 13613 { 13614 mips_push_asm_switch (&mips_noat); 13615 if (TARGET_EXPLICIT_RELOCS) 13616 { 13617 mips_process_load_label (target); 13618 mips_multi_write (); 13619 } 13620 else 13621 { 13622 if (Pmode == DImode) 13623 output_asm_insn ("dla\t%@,%0", &target); 13624 else 13625 output_asm_insn ("la\t%@,%0", &target); 13626 } 13627 } 13628 13629 /* Return the length of INSN. LENGTH is the initial length computed by 13630 attributes in the machine-description file. */ 13631 13632 int 13633 mips_adjust_insn_length (rtx_insn *insn, int length) 13634 { 13635 /* mips.md uses MAX_PIC_BRANCH_LENGTH as a placeholder for the length 13636 of a PIC long-branch sequence. Substitute the correct value. */ 13637 if (length == MAX_PIC_BRANCH_LENGTH 13638 && JUMP_P (insn) 13639 && INSN_CODE (insn) >= 0 13640 && get_attr_type (insn) == TYPE_BRANCH) 13641 { 13642 /* Add the branch-over instruction and its delay slot, if this 13643 is a conditional branch. */ 13644 length = simplejump_p (insn) ? 0 : 8; 13645 13646 /* Add the size of a load into $AT. */ 13647 length += BASE_INSN_LENGTH * mips_load_label_num_insns (); 13648 13649 /* Add the length of an indirect jump, ignoring the delay slot. */ 13650 length += TARGET_COMPRESSION ? 2 : 4; 13651 } 13652 13653 /* A unconditional jump has an unfilled delay slot if it is not part 13654 of a sequence. A conditional jump normally has a delay slot, but 13655 does not on MIPS16. */ 13656 if (CALL_P (insn) || (TARGET_MIPS16 ? simplejump_p (insn) : JUMP_P (insn))) 13657 length += TARGET_MIPS16 ? 2 : 4; 13658 13659 /* See how many nops might be needed to avoid hardware hazards. */ 13660 if (!cfun->machine->ignore_hazard_length_p 13661 && INSN_P (insn) 13662 && INSN_CODE (insn) >= 0) 13663 switch (get_attr_hazard (insn)) 13664 { 13665 case HAZARD_NONE: 13666 break; 13667 13668 case HAZARD_DELAY: 13669 case HAZARD_FORBIDDEN_SLOT: 13670 length += NOP_INSN_LENGTH; 13671 break; 13672 13673 case HAZARD_HILO: 13674 length += NOP_INSN_LENGTH * 2; 13675 break; 13676 } 13677 13678 return length; 13679 } 13680 13681 /* Return the asm template for a call. OPERANDS are the operands, TARGET_OPNO 13682 is the operand number of the target. SIZE_OPNO is the operand number of 13683 the argument size operand that can optionally hold the call attributes. If 13684 SIZE_OPNO is not -1 and the call is indirect, use the function symbol from 13685 the call attributes to attach a R_MIPS_JALR relocation to the call. LINK_P 13686 indicates whether the jump is a call and needs to set the link register. 13687 13688 When generating GOT code without explicit relocation operators, all calls 13689 should use assembly macros. Otherwise, all indirect calls should use "jr" 13690 or "jalr"; we will arrange to restore $gp afterwards if necessary. Finally, 13691 we can only generate direct calls for -mabicalls by temporarily switching 13692 to non-PIC mode. 13693 13694 For microMIPS jal(r), we try to generate jal(r)s when a 16-bit 13695 instruction is in the delay slot of jal(r). 13696 13697 Where compact branches are available, we try to use them if the delay slot 13698 has a NOP (or equivalently delay slots were not enabled for the instruction 13699 anyway). */ 13700 13701 const char * 13702 mips_output_jump (rtx *operands, int target_opno, int size_opno, bool link_p) 13703 { 13704 static char buffer[300]; 13705 char *s = buffer; 13706 bool reg_p = REG_P (operands[target_opno]); 13707 13708 const char *and_link = link_p ? "al" : ""; 13709 const char *reg = reg_p ? "r" : ""; 13710 const char *compact = ""; 13711 const char *nop = "%/"; 13712 const char *short_delay = link_p ? "%!" : ""; 13713 const char *insn_name = TARGET_CB_NEVER || reg_p ? "j" : "b"; 13714 13715 /* Compact branches can only be described when the ISA has support for them 13716 as both the compact formatter '%:' and the delay slot NOP formatter '%/' 13717 work as a mutually exclusive pair. I.e. a NOP is never required if a 13718 compact form is available. */ 13719 if (!final_sequence 13720 && (TARGET_CB_MAYBE 13721 || (ISA_HAS_JRC && !link_p && reg_p))) 13722 { 13723 compact = "c"; 13724 nop = ""; 13725 } 13726 13727 if (TARGET_USE_GOT && !TARGET_EXPLICIT_RELOCS) 13728 sprintf (s, "%%*%s%s\t%%%d%%/", insn_name, and_link, target_opno); 13729 else 13730 { 13731 if (!reg_p && TARGET_ABICALLS_PIC2) 13732 s += sprintf (s, ".option\tpic0\n\t"); 13733 13734 if (reg_p && mips_get_pic_call_symbol (operands, size_opno)) 13735 s += sprintf (s, "%%*.reloc\t1f,%s,%%%d\n1:\t", 13736 TARGET_MICROMIPS ? "R_MICROMIPS_JALR" : "R_MIPS_JALR", 13737 size_opno); 13738 else 13739 s += sprintf (s, "%%*"); 13740 13741 s += sprintf (s, "%s%s%s%s%s\t%%%d%s", 13742 insn_name, and_link, reg, compact, short_delay, 13743 target_opno, nop); 13744 13745 if (!reg_p && TARGET_ABICALLS_PIC2) 13746 s += sprintf (s, "\n\t.option\tpic2"); 13747 } 13748 return buffer; 13749 } 13750 13751 /* Return the assembly code for INSN, which has the operands given by 13752 OPERANDS, and which branches to OPERANDS[0] if some condition is true. 13753 BRANCH_IF_TRUE is the asm template that should be used if OPERANDS[0] 13754 is in range of a direct branch. BRANCH_IF_FALSE is an inverted 13755 version of BRANCH_IF_TRUE. */ 13756 13757 const char * 13758 mips_output_conditional_branch (rtx_insn *insn, rtx *operands, 13759 const char *branch_if_true, 13760 const char *branch_if_false) 13761 { 13762 unsigned int length; 13763 rtx taken; 13764 13765 gcc_assert (LABEL_P (operands[0])); 13766 13767 length = get_attr_length (insn); 13768 if (length <= 8) 13769 { 13770 /* Just a simple conditional branch. */ 13771 mips_branch_likely = (final_sequence && INSN_ANNULLED_BRANCH_P (insn)); 13772 return branch_if_true; 13773 } 13774 13775 /* Generate a reversed branch around a direct jump. This fallback does 13776 not use branch-likely instructions. */ 13777 mips_branch_likely = false; 13778 rtx_code_label *not_taken = gen_label_rtx (); 13779 taken = operands[0]; 13780 13781 /* Generate the reversed branch to NOT_TAKEN. */ 13782 operands[0] = not_taken; 13783 output_asm_insn (branch_if_false, operands); 13784 13785 /* If INSN has a delay slot, we must provide delay slots for both the 13786 branch to NOT_TAKEN and the conditional jump. We must also ensure 13787 that INSN's delay slot is executed in the appropriate cases. */ 13788 if (final_sequence) 13789 { 13790 /* This first delay slot will always be executed, so use INSN's 13791 delay slot if is not annulled. */ 13792 if (!INSN_ANNULLED_BRANCH_P (insn)) 13793 { 13794 final_scan_insn (final_sequence->insn (1), 13795 asm_out_file, optimize, 1, NULL); 13796 final_sequence->insn (1)->set_deleted (); 13797 } 13798 else 13799 output_asm_insn ("nop", 0); 13800 fprintf (asm_out_file, "\n"); 13801 } 13802 13803 /* Output the unconditional branch to TAKEN. */ 13804 if (TARGET_ABSOLUTE_JUMPS && TARGET_CB_MAYBE) 13805 { 13806 /* Add a hazard nop. */ 13807 if (!final_sequence) 13808 { 13809 output_asm_insn ("nop\t\t# hazard nop", 0); 13810 fprintf (asm_out_file, "\n"); 13811 } 13812 output_asm_insn (MIPS_ABSOLUTE_JUMP ("bc\t%0"), &taken); 13813 } 13814 else if (TARGET_ABSOLUTE_JUMPS) 13815 output_asm_insn (MIPS_ABSOLUTE_JUMP ("j\t%0%/"), &taken); 13816 else 13817 { 13818 mips_output_load_label (taken); 13819 if (TARGET_CB_MAYBE) 13820 output_asm_insn ("jrc\t%@%]", 0); 13821 else 13822 output_asm_insn ("jr\t%@%]%/", 0); 13823 } 13824 13825 /* Now deal with its delay slot; see above. */ 13826 if (final_sequence) 13827 { 13828 /* This delay slot will only be executed if the branch is taken. 13829 Use INSN's delay slot if is annulled. */ 13830 if (INSN_ANNULLED_BRANCH_P (insn)) 13831 { 13832 final_scan_insn (final_sequence->insn (1), 13833 asm_out_file, optimize, 1, NULL); 13834 final_sequence->insn (1)->set_deleted (); 13835 } 13836 else if (TARGET_CB_NEVER) 13837 output_asm_insn ("nop", 0); 13838 fprintf (asm_out_file, "\n"); 13839 } 13840 13841 /* Output NOT_TAKEN. */ 13842 targetm.asm_out.internal_label (asm_out_file, "L", 13843 CODE_LABEL_NUMBER (not_taken)); 13844 return ""; 13845 } 13846 13847 /* Return the assembly code for INSN, which branches to OPERANDS[0] 13848 if some equality condition is true. The condition is given by 13849 OPERANDS[1] if !INVERTED_P, otherwise it is the inverse of 13850 OPERANDS[1]. OPERANDS[2] is the comparison's first operand; 13851 OPERANDS[3] is the second operand and may be zero or a register. */ 13852 13853 const char * 13854 mips_output_equal_conditional_branch (rtx_insn* insn, rtx *operands, 13855 bool inverted_p) 13856 { 13857 const char *branch[2]; 13858 /* For a simple BNEZ or BEQZ microMIPSr3 branch. */ 13859 if (TARGET_MICROMIPS 13860 && mips_isa_rev <= 5 13861 && operands[3] == const0_rtx 13862 && get_attr_length (insn) <= 8) 13863 { 13864 if (mips_cb == MIPS_CB_OPTIMAL) 13865 { 13866 branch[!inverted_p] = "%*b%C1z%:\t%2,%0"; 13867 branch[inverted_p] = "%*b%N1z%:\t%2,%0"; 13868 } 13869 else 13870 { 13871 branch[!inverted_p] = "%*b%C1z\t%2,%0%/"; 13872 branch[inverted_p] = "%*b%N1z\t%2,%0%/"; 13873 } 13874 } 13875 else if (TARGET_CB_MAYBE) 13876 { 13877 if (operands[3] == const0_rtx) 13878 { 13879 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1z", "%2,%0"); 13880 branch[inverted_p] = MIPS_BRANCH_C ("b%N1z", "%2,%0"); 13881 } 13882 else if (REGNO (operands[2]) != REGNO (operands[3])) 13883 { 13884 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1", "%2,%3,%0"); 13885 branch[inverted_p] = MIPS_BRANCH_C ("b%N1", "%2,%3,%0"); 13886 } 13887 else 13888 { 13889 /* This case is degenerate. It should not happen, but does. */ 13890 if (GET_CODE (operands[1]) == NE) 13891 inverted_p = !inverted_p; 13892 13893 branch[!inverted_p] = MIPS_BRANCH_C ("b", "%0"); 13894 branch[inverted_p] = "%*\t\t# branch never"; 13895 } 13896 } 13897 else 13898 { 13899 branch[!inverted_p] = MIPS_BRANCH ("b%C1", "%2,%z3,%0"); 13900 branch[inverted_p] = MIPS_BRANCH ("b%N1", "%2,%z3,%0"); 13901 } 13902 13903 return mips_output_conditional_branch (insn, operands, branch[1], branch[0]); 13904 } 13905 13906 /* Return the assembly code for INSN, which branches to OPERANDS[0] 13907 if some ordering condition is true. The condition is given by 13908 OPERANDS[1] if !INVERTED_P, otherwise it is the inverse of 13909 OPERANDS[1]. OPERANDS[2] is the comparison's first operand; 13910 OPERANDS[3] is the second operand and may be zero or a register. */ 13911 13912 const char * 13913 mips_output_order_conditional_branch (rtx_insn *insn, rtx *operands, 13914 bool inverted_p) 13915 { 13916 const char *branch[2]; 13917 13918 /* Make BRANCH[1] branch to OPERANDS[0] when the condition is true. 13919 Make BRANCH[0] branch on the inverse condition. */ 13920 if (operands[3] != const0_rtx) 13921 { 13922 /* Handle degenerate cases that should not, but do, occur. */ 13923 if (REGNO (operands[2]) == REGNO (operands[3])) 13924 { 13925 switch (GET_CODE (operands[1])) 13926 { 13927 case LT: 13928 case LTU: 13929 inverted_p = !inverted_p; 13930 /* Fall through. */ 13931 case GE: 13932 case GEU: 13933 branch[!inverted_p] = MIPS_BRANCH_C ("b", "%0"); 13934 branch[inverted_p] = "%*\t\t# branch never"; 13935 break; 13936 default: 13937 gcc_unreachable (); 13938 } 13939 } 13940 else 13941 { 13942 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1", "%2,%3,%0"); 13943 branch[inverted_p] = MIPS_BRANCH_C ("b%N1", "%2,%3,%0"); 13944 } 13945 } 13946 else 13947 { 13948 switch (GET_CODE (operands[1])) 13949 { 13950 /* These cases are equivalent to comparisons against zero. */ 13951 case LEU: 13952 inverted_p = !inverted_p; 13953 /* Fall through. */ 13954 case GTU: 13955 if (TARGET_CB_MAYBE) 13956 { 13957 branch[!inverted_p] = MIPS_BRANCH_C ("bnez", "%2,%0"); 13958 branch[inverted_p] = MIPS_BRANCH_C ("beqz", "%2,%0"); 13959 } 13960 else 13961 { 13962 branch[!inverted_p] = MIPS_BRANCH ("bne", "%2,%.,%0"); 13963 branch[inverted_p] = MIPS_BRANCH ("beq", "%2,%.,%0"); 13964 } 13965 break; 13966 13967 /* These cases are always true or always false. */ 13968 case LTU: 13969 inverted_p = !inverted_p; 13970 /* Fall through. */ 13971 case GEU: 13972 if (TARGET_CB_MAYBE) 13973 { 13974 branch[!inverted_p] = MIPS_BRANCH_C ("b", "%0"); 13975 branch[inverted_p] = "%*\t\t# branch never"; 13976 } 13977 else 13978 { 13979 branch[!inverted_p] = MIPS_BRANCH ("beq", "%.,%.,%0"); 13980 branch[inverted_p] = MIPS_BRANCH ("bne", "%.,%.,%0"); 13981 } 13982 break; 13983 13984 default: 13985 if (TARGET_CB_MAYBE) 13986 { 13987 branch[!inverted_p] = MIPS_BRANCH_C ("b%C1z", "%2,%0"); 13988 branch[inverted_p] = MIPS_BRANCH_C ("b%N1z", "%2,%0"); 13989 } 13990 else 13991 { 13992 branch[!inverted_p] = MIPS_BRANCH ("b%C1z", "%2,%0"); 13993 branch[inverted_p] = MIPS_BRANCH ("b%N1z", "%2,%0"); 13994 } 13995 break; 13996 } 13997 } 13998 return mips_output_conditional_branch (insn, operands, branch[1], branch[0]); 13999 } 14000 14001 /* Start a block of code that needs access to the LL, SC and SYNC 14002 instructions. */ 14003 14004 static void 14005 mips_start_ll_sc_sync_block (void) 14006 { 14007 if (!ISA_HAS_LL_SC) 14008 { 14009 output_asm_insn (".set\tpush", 0); 14010 if (TARGET_64BIT) 14011 output_asm_insn (".set\tmips3", 0); 14012 else 14013 output_asm_insn (".set\tmips2", 0); 14014 } 14015 } 14016 14017 /* End a block started by mips_start_ll_sc_sync_block. */ 14018 14019 static void 14020 mips_end_ll_sc_sync_block (void) 14021 { 14022 if (!ISA_HAS_LL_SC) 14023 output_asm_insn (".set\tpop", 0); 14024 } 14025 14026 /* Output and/or return the asm template for a sync instruction. */ 14027 14028 const char * 14029 mips_output_sync (void) 14030 { 14031 mips_start_ll_sc_sync_block (); 14032 output_asm_insn ("sync", 0); 14033 mips_end_ll_sc_sync_block (); 14034 return ""; 14035 } 14036 14037 /* Return the asm template associated with sync_insn1 value TYPE. 14038 IS_64BIT_P is true if we want a 64-bit rather than 32-bit operation. */ 14039 14040 static const char * 14041 mips_sync_insn1_template (enum attr_sync_insn1 type, bool is_64bit_p) 14042 { 14043 switch (type) 14044 { 14045 case SYNC_INSN1_MOVE: 14046 return "move\t%0,%z2"; 14047 case SYNC_INSN1_LI: 14048 return "li\t%0,%2"; 14049 case SYNC_INSN1_ADDU: 14050 return is_64bit_p ? "daddu\t%0,%1,%z2" : "addu\t%0,%1,%z2"; 14051 case SYNC_INSN1_ADDIU: 14052 return is_64bit_p ? "daddiu\t%0,%1,%2" : "addiu\t%0,%1,%2"; 14053 case SYNC_INSN1_SUBU: 14054 return is_64bit_p ? "dsubu\t%0,%1,%z2" : "subu\t%0,%1,%z2"; 14055 case SYNC_INSN1_AND: 14056 return "and\t%0,%1,%z2"; 14057 case SYNC_INSN1_ANDI: 14058 return "andi\t%0,%1,%2"; 14059 case SYNC_INSN1_OR: 14060 return "or\t%0,%1,%z2"; 14061 case SYNC_INSN1_ORI: 14062 return "ori\t%0,%1,%2"; 14063 case SYNC_INSN1_XOR: 14064 return "xor\t%0,%1,%z2"; 14065 case SYNC_INSN1_XORI: 14066 return "xori\t%0,%1,%2"; 14067 } 14068 gcc_unreachable (); 14069 } 14070 14071 /* Return the asm template associated with sync_insn2 value TYPE. */ 14072 14073 static const char * 14074 mips_sync_insn2_template (enum attr_sync_insn2 type) 14075 { 14076 switch (type) 14077 { 14078 case SYNC_INSN2_NOP: 14079 gcc_unreachable (); 14080 case SYNC_INSN2_AND: 14081 return "and\t%0,%1,%z2"; 14082 case SYNC_INSN2_XOR: 14083 return "xor\t%0,%1,%z2"; 14084 case SYNC_INSN2_NOT: 14085 return "nor\t%0,%1,%."; 14086 } 14087 gcc_unreachable (); 14088 } 14089 14090 /* OPERANDS are the operands to a sync loop instruction and INDEX is 14091 the value of the one of the sync_* attributes. Return the operand 14092 referred to by the attribute, or DEFAULT_VALUE if the insn doesn't 14093 have the associated attribute. */ 14094 14095 static rtx 14096 mips_get_sync_operand (rtx *operands, int index, rtx default_value) 14097 { 14098 if (index > 0) 14099 default_value = operands[index - 1]; 14100 return default_value; 14101 } 14102 14103 /* INSN is a sync loop with operands OPERANDS. Build up a multi-insn 14104 sequence for it. */ 14105 14106 static void 14107 mips_process_sync_loop (rtx_insn *insn, rtx *operands) 14108 { 14109 rtx at, mem, oldval, newval, inclusive_mask, exclusive_mask; 14110 rtx required_oldval, insn1_op2, tmp1, tmp2, tmp3, cmp; 14111 unsigned int tmp3_insn; 14112 enum attr_sync_insn1 insn1; 14113 enum attr_sync_insn2 insn2; 14114 bool is_64bit_p; 14115 int memmodel_attr; 14116 enum memmodel model; 14117 14118 /* Read an operand from the sync_WHAT attribute and store it in 14119 variable WHAT. DEFAULT is the default value if no attribute 14120 is specified. */ 14121 #define READ_OPERAND(WHAT, DEFAULT) \ 14122 WHAT = mips_get_sync_operand (operands, (int) get_attr_sync_##WHAT (insn), \ 14123 DEFAULT) 14124 14125 /* Read the memory. */ 14126 READ_OPERAND (mem, 0); 14127 gcc_assert (mem); 14128 is_64bit_p = (GET_MODE_BITSIZE (GET_MODE (mem)) == 64); 14129 14130 /* Read the other attributes. */ 14131 at = gen_rtx_REG (GET_MODE (mem), AT_REGNUM); 14132 READ_OPERAND (oldval, at); 14133 READ_OPERAND (cmp, 0); 14134 READ_OPERAND (newval, at); 14135 READ_OPERAND (inclusive_mask, 0); 14136 READ_OPERAND (exclusive_mask, 0); 14137 READ_OPERAND (required_oldval, 0); 14138 READ_OPERAND (insn1_op2, 0); 14139 insn1 = get_attr_sync_insn1 (insn); 14140 insn2 = get_attr_sync_insn2 (insn); 14141 14142 /* Don't bother setting CMP result that is never used. */ 14143 if (cmp && find_reg_note (insn, REG_UNUSED, cmp)) 14144 cmp = 0; 14145 14146 memmodel_attr = get_attr_sync_memmodel (insn); 14147 switch (memmodel_attr) 14148 { 14149 case 10: 14150 model = MEMMODEL_ACQ_REL; 14151 break; 14152 case 11: 14153 model = MEMMODEL_ACQUIRE; 14154 break; 14155 default: 14156 model = memmodel_from_int (INTVAL (operands[memmodel_attr])); 14157 } 14158 14159 mips_multi_start (); 14160 14161 /* Output the release side of the memory barrier. */ 14162 if (need_atomic_barrier_p (model, true)) 14163 { 14164 if (required_oldval == 0 && TARGET_OCTEON) 14165 { 14166 /* Octeon doesn't reorder reads, so a full barrier can be 14167 created by using SYNCW to order writes combined with the 14168 write from the following SC. When the SC successfully 14169 completes, we know that all preceding writes are also 14170 committed to the coherent memory system. It is possible 14171 for a single SYNCW to fail, but a pair of them will never 14172 fail, so we use two. */ 14173 mips_multi_add_insn ("syncw", NULL); 14174 mips_multi_add_insn ("syncw", NULL); 14175 } 14176 else 14177 mips_multi_add_insn ("sync", NULL); 14178 } 14179 14180 /* Output the branch-back label. */ 14181 mips_multi_add_label ("1:"); 14182 14183 /* OLDVAL = *MEM. */ 14184 mips_multi_add_insn (is_64bit_p ? "lld\t%0,%1" : "ll\t%0,%1", 14185 oldval, mem, NULL); 14186 14187 /* if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2. */ 14188 if (required_oldval) 14189 { 14190 if (inclusive_mask == 0) 14191 tmp1 = oldval; 14192 else 14193 { 14194 gcc_assert (oldval != at); 14195 mips_multi_add_insn ("and\t%0,%1,%2", 14196 at, oldval, inclusive_mask, NULL); 14197 tmp1 = at; 14198 } 14199 if (TARGET_CB_NEVER) 14200 mips_multi_add_insn ("bne\t%0,%z1,2f", tmp1, required_oldval, NULL); 14201 14202 /* CMP = 0 [delay slot]. */ 14203 if (cmp) 14204 mips_multi_add_insn ("li\t%0,0", cmp, NULL); 14205 14206 if (TARGET_CB_MAYBE && required_oldval == const0_rtx) 14207 mips_multi_add_insn ("bnezc\t%0,2f", tmp1, NULL); 14208 else if (TARGET_CB_MAYBE) 14209 mips_multi_add_insn ("bnec\t%0,%1,2f", tmp1, required_oldval, NULL); 14210 14211 } 14212 14213 /* $TMP1 = OLDVAL & EXCLUSIVE_MASK. */ 14214 if (exclusive_mask == 0) 14215 tmp1 = const0_rtx; 14216 else 14217 { 14218 gcc_assert (oldval != at); 14219 mips_multi_add_insn ("and\t%0,%1,%z2", 14220 at, oldval, exclusive_mask, NULL); 14221 tmp1 = at; 14222 } 14223 14224 /* $TMP2 = INSN1 (OLDVAL, INSN1_OP2). 14225 14226 We can ignore moves if $TMP4 != INSN1_OP2, since we'll still emit 14227 at least one instruction in that case. */ 14228 if (insn1 == SYNC_INSN1_MOVE 14229 && (tmp1 != const0_rtx || insn2 != SYNC_INSN2_NOP)) 14230 tmp2 = insn1_op2; 14231 else 14232 { 14233 mips_multi_add_insn (mips_sync_insn1_template (insn1, is_64bit_p), 14234 newval, oldval, insn1_op2, NULL); 14235 tmp2 = newval; 14236 } 14237 14238 /* $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK). */ 14239 if (insn2 == SYNC_INSN2_NOP) 14240 tmp3 = tmp2; 14241 else 14242 { 14243 mips_multi_add_insn (mips_sync_insn2_template (insn2), 14244 newval, tmp2, inclusive_mask, NULL); 14245 tmp3 = newval; 14246 } 14247 tmp3_insn = mips_multi_last_index (); 14248 14249 /* $AT = $TMP1 | $TMP3. */ 14250 if (tmp1 == const0_rtx || tmp3 == const0_rtx) 14251 { 14252 mips_multi_set_operand (tmp3_insn, 0, at); 14253 tmp3 = at; 14254 } 14255 else 14256 { 14257 gcc_assert (tmp1 != tmp3); 14258 mips_multi_add_insn ("or\t%0,%1,%2", at, tmp1, tmp3, NULL); 14259 } 14260 14261 /* if (!commit (*MEM = $AT)) goto 1. 14262 14263 This will sometimes be a delayed branch; see the write code below 14264 for details. */ 14265 mips_multi_add_insn (is_64bit_p ? "scd\t%0,%1" : "sc\t%0,%1", at, mem, NULL); 14266 14267 /* When using branch likely (-mfix-r10000), the delay slot instruction 14268 will be annulled on false. The normal delay slot instructions 14269 calculate the overall result of the atomic operation and must not 14270 be annulled. To ensure this behavior unconditionally use a NOP 14271 in the delay slot for the branch likely case. */ 14272 14273 if (TARGET_CB_MAYBE) 14274 mips_multi_add_insn ("beqzc\t%0,1b", at, NULL); 14275 else 14276 mips_multi_add_insn ("beq%?\t%0,%.,1b%~", at, NULL); 14277 14278 /* if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]. */ 14279 if (insn1 != SYNC_INSN1_MOVE && insn1 != SYNC_INSN1_LI && tmp3 != newval) 14280 { 14281 mips_multi_copy_insn (tmp3_insn); 14282 mips_multi_set_operand (mips_multi_last_index (), 0, newval); 14283 } 14284 else if (!(required_oldval && cmp) && !mips_branch_likely) 14285 mips_multi_add_insn ("nop", NULL); 14286 14287 /* CMP = 1 -- either standalone or in a delay slot. */ 14288 if (required_oldval && cmp) 14289 mips_multi_add_insn ("li\t%0,1", cmp, NULL); 14290 14291 /* Output the acquire side of the memory barrier. */ 14292 if (TARGET_SYNC_AFTER_SC && need_atomic_barrier_p (model, false)) 14293 mips_multi_add_insn ("sync", NULL); 14294 14295 /* Output the exit label, if needed. */ 14296 if (required_oldval) 14297 mips_multi_add_label ("2:"); 14298 14299 #undef READ_OPERAND 14300 } 14301 14302 /* Output and/or return the asm template for sync loop INSN, which has 14303 the operands given by OPERANDS. */ 14304 14305 const char * 14306 mips_output_sync_loop (rtx_insn *insn, rtx *operands) 14307 { 14308 /* Use branch-likely instructions to work around the LL/SC R10000 14309 errata. */ 14310 mips_branch_likely = TARGET_FIX_R10000; 14311 14312 mips_process_sync_loop (insn, operands); 14313 14314 mips_push_asm_switch (&mips_noreorder); 14315 mips_push_asm_switch (&mips_nomacro); 14316 mips_push_asm_switch (&mips_noat); 14317 mips_start_ll_sc_sync_block (); 14318 14319 mips_multi_write (); 14320 14321 mips_end_ll_sc_sync_block (); 14322 mips_pop_asm_switch (&mips_noat); 14323 mips_pop_asm_switch (&mips_nomacro); 14324 mips_pop_asm_switch (&mips_noreorder); 14325 14326 return ""; 14327 } 14328 14329 /* Return the number of individual instructions in sync loop INSN, 14330 which has the operands given by OPERANDS. */ 14331 14332 unsigned int 14333 mips_sync_loop_insns (rtx_insn *insn, rtx *operands) 14334 { 14335 /* Use branch-likely instructions to work around the LL/SC R10000 14336 errata. */ 14337 mips_branch_likely = TARGET_FIX_R10000; 14338 mips_process_sync_loop (insn, operands); 14339 return mips_multi_num_insns; 14340 } 14341 14342 /* Return the assembly code for DIV or DDIV instruction DIVISION, which has 14343 the operands given by OPERANDS. Add in a divide-by-zero check if needed. 14344 14345 When working around R4000 and R4400 errata, we need to make sure that 14346 the division is not immediately followed by a shift[1][2]. We also 14347 need to stop the division from being put into a branch delay slot[3]. 14348 The easiest way to avoid both problems is to add a nop after the 14349 division. When a divide-by-zero check is needed, this nop can be 14350 used to fill the branch delay slot. 14351 14352 [1] If a double-word or a variable shift executes immediately 14353 after starting an integer division, the shift may give an 14354 incorrect result. See quotations of errata #16 and #28 from 14355 "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0" 14356 in mips.md for details. 14357 14358 [2] A similar bug to [1] exists for all revisions of the 14359 R4000 and the R4400 when run in an MC configuration. 14360 From "MIPS R4000MC Errata, Processor Revision 2.2 and 3.0": 14361 14362 "19. In this following sequence: 14363 14364 ddiv (or ddivu or div or divu) 14365 dsll32 (or dsrl32, dsra32) 14366 14367 if an MPT stall occurs, while the divide is slipping the cpu 14368 pipeline, then the following double shift would end up with an 14369 incorrect result. 14370 14371 Workaround: The compiler needs to avoid generating any 14372 sequence with divide followed by extended double shift." 14373 14374 This erratum is also present in "MIPS R4400MC Errata, Processor 14375 Revision 1.0" and "MIPS R4400MC Errata, Processor Revision 2.0 14376 & 3.0" as errata #10 and #4, respectively. 14377 14378 [3] From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0" 14379 (also valid for MIPS R4000MC processors): 14380 14381 "52. R4000SC: This bug does not apply for the R4000PC. 14382 14383 There are two flavors of this bug: 14384 14385 1) If the instruction just after divide takes an RF exception 14386 (tlb-refill, tlb-invalid) and gets an instruction cache 14387 miss (both primary and secondary) and the line which is 14388 currently in secondary cache at this index had the first 14389 data word, where the bits 5..2 are set, then R4000 would 14390 get a wrong result for the div. 14391 14392 ##1 14393 nop 14394 div r8, r9 14395 ------------------- # end-of page. -tlb-refill 14396 nop 14397 ##2 14398 nop 14399 div r8, r9 14400 ------------------- # end-of page. -tlb-invalid 14401 nop 14402 14403 2) If the divide is in the taken branch delay slot, where the 14404 target takes RF exception and gets an I-cache miss for the 14405 exception vector or where I-cache miss occurs for the 14406 target address, under the above mentioned scenarios, the 14407 div would get wrong results. 14408 14409 ##1 14410 j r2 # to next page mapped or unmapped 14411 div r8,r9 # this bug would be there as long 14412 # as there is an ICache miss and 14413 nop # the "data pattern" is present 14414 14415 ##2 14416 beq r0, r0, NextPage # to Next page 14417 div r8,r9 14418 nop 14419 14420 This bug is present for div, divu, ddiv, and ddivu 14421 instructions. 14422 14423 Workaround: For item 1), OS could make sure that the next page 14424 after the divide instruction is also mapped. For item 2), the 14425 compiler could make sure that the divide instruction is not in 14426 the branch delay slot." 14427 14428 These processors have PRId values of 0x00004220 and 0x00004300 for 14429 the R4000 and 0x00004400, 0x00004500 and 0x00004600 for the R4400. */ 14430 14431 const char * 14432 mips_output_division (const char *division, rtx *operands) 14433 { 14434 const char *s; 14435 14436 s = division; 14437 if (TARGET_FIX_R4000 || TARGET_FIX_R4400) 14438 { 14439 output_asm_insn (s, operands); 14440 s = "nop"; 14441 } 14442 if (TARGET_CHECK_ZERO_DIV) 14443 { 14444 if (TARGET_MIPS16) 14445 { 14446 output_asm_insn (s, operands); 14447 s = "bnez\t%2,1f\n\tbreak\t7\n1:"; 14448 } 14449 else if (GENERATE_DIVIDE_TRAPS) 14450 { 14451 /* Avoid long replay penalty on load miss by putting the trap before 14452 the divide. */ 14453 if (TUNE_74K) 14454 output_asm_insn ("teq\t%2,%.,7", operands); 14455 else 14456 { 14457 output_asm_insn (s, operands); 14458 s = "teq\t%2,%.,7"; 14459 } 14460 } 14461 else 14462 { 14463 if (flag_delayed_branch) 14464 { 14465 output_asm_insn ("%(bne\t%2,%.,1f", operands); 14466 output_asm_insn (s, operands); 14467 s = "break\t7%)\n1:"; 14468 } 14469 else 14470 { 14471 output_asm_insn (s, operands); 14472 s = "bne\t%2,%.,1f\n\tnop\n\tbreak\t7\n1:"; 14473 } 14474 } 14475 } 14476 return s; 14477 } 14478 14479 /* Return the assembly code for MSA DIV_{S,U}.DF or MOD_{S,U}.DF instructions, 14480 which has the operands given by OPERANDS. Add in a divide-by-zero check 14481 if needed. */ 14482 14483 const char * 14484 mips_msa_output_division (const char *division, rtx *operands) 14485 { 14486 const char *s; 14487 14488 s = division; 14489 if (TARGET_CHECK_ZERO_DIV) 14490 { 14491 output_asm_insn ("%(bnz.%v0\t%w2,1f", operands); 14492 output_asm_insn (s, operands); 14493 s = "break\t7%)\n1:"; 14494 } 14495 return s; 14496 } 14497 14498 /* Return true if destination of IN_INSN is used as add source in 14499 OUT_INSN. Both IN_INSN and OUT_INSN are of type fmadd. Example: 14500 madd.s dst, x, y, z 14501 madd.s a, dst, b, c */ 14502 14503 bool 14504 mips_fmadd_bypass (rtx_insn *out_insn, rtx_insn *in_insn) 14505 { 14506 int dst_reg, src_reg; 14507 14508 gcc_assert (get_attr_type (in_insn) == TYPE_FMADD); 14509 gcc_assert (get_attr_type (out_insn) == TYPE_FMADD); 14510 14511 extract_insn (in_insn); 14512 dst_reg = REG_P (recog_data.operand[0]); 14513 14514 extract_insn (out_insn); 14515 src_reg = REG_P (recog_data.operand[1]); 14516 14517 if (dst_reg == src_reg) 14518 return true; 14519 14520 return false; 14521 } 14522 14523 /* Return true if IN_INSN is a multiply-add or multiply-subtract 14524 instruction and if OUT_INSN assigns to the accumulator operand. */ 14525 14526 bool 14527 mips_linked_madd_p (rtx_insn *out_insn, rtx_insn *in_insn) 14528 { 14529 enum attr_accum_in accum_in; 14530 int accum_in_opnum; 14531 rtx accum_in_op; 14532 14533 if (recog_memoized (in_insn) < 0) 14534 return false; 14535 14536 accum_in = get_attr_accum_in (in_insn); 14537 if (accum_in == ACCUM_IN_NONE) 14538 return false; 14539 14540 accum_in_opnum = accum_in - ACCUM_IN_0; 14541 14542 extract_insn (in_insn); 14543 gcc_assert (accum_in_opnum < recog_data.n_operands); 14544 accum_in_op = recog_data.operand[accum_in_opnum]; 14545 14546 return reg_set_p (accum_in_op, out_insn); 14547 } 14548 14549 /* True if the dependency between OUT_INSN and IN_INSN is on the store 14550 data rather than the address. We need this because the cprestore 14551 pattern is type "store", but is defined using an UNSPEC_VOLATILE, 14552 which causes the default routine to abort. We just return false 14553 for that case. */ 14554 14555 bool 14556 mips_store_data_bypass_p (rtx_insn *out_insn, rtx_insn *in_insn) 14557 { 14558 if (GET_CODE (PATTERN (in_insn)) == UNSPEC_VOLATILE) 14559 return false; 14560 14561 return store_data_bypass_p (out_insn, in_insn); 14562 } 14563 14564 14565 /* Variables and flags used in scheduler hooks when tuning for 14566 Loongson 2E/2F. */ 14567 static struct 14568 { 14569 /* Variables to support Loongson 2E/2F round-robin [F]ALU1/2 dispatch 14570 strategy. */ 14571 14572 /* If true, then next ALU1/2 instruction will go to ALU1. */ 14573 bool alu1_turn_p; 14574 14575 /* If true, then next FALU1/2 unstruction will go to FALU1. */ 14576 bool falu1_turn_p; 14577 14578 /* Codes to query if [f]alu{1,2}_core units are subscribed or not. */ 14579 int alu1_core_unit_code; 14580 int alu2_core_unit_code; 14581 int falu1_core_unit_code; 14582 int falu2_core_unit_code; 14583 14584 /* True if current cycle has a multi instruction. 14585 This flag is used in mips_ls2_dfa_post_advance_cycle. */ 14586 bool cycle_has_multi_p; 14587 14588 /* Instructions to subscribe ls2_[f]alu{1,2}_turn_enabled units. 14589 These are used in mips_ls2_dfa_post_advance_cycle to initialize 14590 DFA state. 14591 E.g., when alu1_turn_enabled_insn is issued it makes next ALU1/2 14592 instruction to go ALU1. */ 14593 rtx_insn *alu1_turn_enabled_insn; 14594 rtx_insn *alu2_turn_enabled_insn; 14595 rtx_insn *falu1_turn_enabled_insn; 14596 rtx_insn *falu2_turn_enabled_insn; 14597 } mips_ls2; 14598 14599 /* Implement TARGET_SCHED_ADJUST_COST. We assume that anti and output 14600 dependencies have no cost, except on the 20Kc where output-dependence 14601 is treated like input-dependence. */ 14602 14603 static int 14604 mips_adjust_cost (rtx_insn *, int dep_type, rtx_insn *, int cost, unsigned int) 14605 { 14606 if (dep_type != 0 && (dep_type != REG_DEP_OUTPUT || !TUNE_20KC)) 14607 return 0; 14608 return cost; 14609 } 14610 14611 /* Return the number of instructions that can be issued per cycle. */ 14612 14613 static int 14614 mips_issue_rate (void) 14615 { 14616 switch (mips_tune) 14617 { 14618 case PROCESSOR_74KC: 14619 case PROCESSOR_74KF2_1: 14620 case PROCESSOR_74KF1_1: 14621 case PROCESSOR_74KF3_2: 14622 /* The 74k is not strictly quad-issue cpu, but can be seen as one 14623 by the scheduler. It can issue 1 ALU, 1 AGEN and 2 FPU insns, 14624 but in reality only a maximum of 3 insns can be issued as 14625 floating-point loads and stores also require a slot in the 14626 AGEN pipe. */ 14627 case PROCESSOR_R10000: 14628 /* All R10K Processors are quad-issue (being the first MIPS 14629 processors to support this feature). */ 14630 return 4; 14631 14632 case PROCESSOR_20KC: 14633 case PROCESSOR_R4130: 14634 case PROCESSOR_R5400: 14635 case PROCESSOR_R5500: 14636 case PROCESSOR_R5900: 14637 case PROCESSOR_R7000: 14638 case PROCESSOR_R9000: 14639 case PROCESSOR_OCTEON: 14640 case PROCESSOR_OCTEON2: 14641 case PROCESSOR_OCTEON3: 14642 case PROCESSOR_I6400: 14643 case PROCESSOR_GS264E: 14644 return 2; 14645 14646 case PROCESSOR_SB1: 14647 case PROCESSOR_SB1A: 14648 /* This is actually 4, but we get better performance if we claim 3. 14649 This is partly because of unwanted speculative code motion with the 14650 larger number, and partly because in most common cases we can't 14651 reach the theoretical max of 4. */ 14652 return 3; 14653 14654 case PROCESSOR_LOONGSON_2E: 14655 case PROCESSOR_LOONGSON_2F: 14656 case PROCESSOR_GS464: 14657 case PROCESSOR_GS464E: 14658 case PROCESSOR_P5600: 14659 case PROCESSOR_P6600: 14660 return 4; 14661 14662 case PROCESSOR_XLP: 14663 return (reload_completed ? 4 : 3); 14664 14665 default: 14666 return 1; 14667 } 14668 } 14669 14670 /* Implement TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN hook for Loongson2. */ 14671 14672 static void 14673 mips_ls2_init_dfa_post_cycle_insn (void) 14674 { 14675 start_sequence (); 14676 emit_insn (gen_ls2_alu1_turn_enabled_insn ()); 14677 mips_ls2.alu1_turn_enabled_insn = get_insns (); 14678 end_sequence (); 14679 14680 start_sequence (); 14681 emit_insn (gen_ls2_alu2_turn_enabled_insn ()); 14682 mips_ls2.alu2_turn_enabled_insn = get_insns (); 14683 end_sequence (); 14684 14685 start_sequence (); 14686 emit_insn (gen_ls2_falu1_turn_enabled_insn ()); 14687 mips_ls2.falu1_turn_enabled_insn = get_insns (); 14688 end_sequence (); 14689 14690 start_sequence (); 14691 emit_insn (gen_ls2_falu2_turn_enabled_insn ()); 14692 mips_ls2.falu2_turn_enabled_insn = get_insns (); 14693 end_sequence (); 14694 14695 mips_ls2.alu1_core_unit_code = get_cpu_unit_code ("ls2_alu1_core"); 14696 mips_ls2.alu2_core_unit_code = get_cpu_unit_code ("ls2_alu2_core"); 14697 mips_ls2.falu1_core_unit_code = get_cpu_unit_code ("ls2_falu1_core"); 14698 mips_ls2.falu2_core_unit_code = get_cpu_unit_code ("ls2_falu2_core"); 14699 } 14700 14701 /* Implement TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN hook. 14702 Init data used in mips_dfa_post_advance_cycle. */ 14703 14704 static void 14705 mips_init_dfa_post_cycle_insn (void) 14706 { 14707 if (TUNE_LOONGSON_2EF) 14708 mips_ls2_init_dfa_post_cycle_insn (); 14709 } 14710 14711 /* Initialize STATE when scheduling for Loongson 2E/2F. 14712 Support round-robin dispatch scheme by enabling only one of 14713 ALU1/ALU2 and one of FALU1/FALU2 units for ALU1/2 and FALU1/2 instructions 14714 respectively. */ 14715 14716 static void 14717 mips_ls2_dfa_post_advance_cycle (state_t state) 14718 { 14719 if (cpu_unit_reservation_p (state, mips_ls2.alu1_core_unit_code)) 14720 { 14721 /* Though there are no non-pipelined ALU1 insns, 14722 we can get an instruction of type 'multi' before reload. */ 14723 gcc_assert (mips_ls2.cycle_has_multi_p); 14724 mips_ls2.alu1_turn_p = false; 14725 } 14726 14727 mips_ls2.cycle_has_multi_p = false; 14728 14729 if (cpu_unit_reservation_p (state, mips_ls2.alu2_core_unit_code)) 14730 /* We have a non-pipelined alu instruction in the core, 14731 adjust round-robin counter. */ 14732 mips_ls2.alu1_turn_p = true; 14733 14734 if (mips_ls2.alu1_turn_p) 14735 { 14736 if (state_transition (state, mips_ls2.alu1_turn_enabled_insn) >= 0) 14737 gcc_unreachable (); 14738 } 14739 else 14740 { 14741 if (state_transition (state, mips_ls2.alu2_turn_enabled_insn) >= 0) 14742 gcc_unreachable (); 14743 } 14744 14745 if (cpu_unit_reservation_p (state, mips_ls2.falu1_core_unit_code)) 14746 { 14747 /* There are no non-pipelined FALU1 insns. */ 14748 gcc_unreachable (); 14749 mips_ls2.falu1_turn_p = false; 14750 } 14751 14752 if (cpu_unit_reservation_p (state, mips_ls2.falu2_core_unit_code)) 14753 /* We have a non-pipelined falu instruction in the core, 14754 adjust round-robin counter. */ 14755 mips_ls2.falu1_turn_p = true; 14756 14757 if (mips_ls2.falu1_turn_p) 14758 { 14759 if (state_transition (state, mips_ls2.falu1_turn_enabled_insn) >= 0) 14760 gcc_unreachable (); 14761 } 14762 else 14763 { 14764 if (state_transition (state, mips_ls2.falu2_turn_enabled_insn) >= 0) 14765 gcc_unreachable (); 14766 } 14767 } 14768 14769 /* Implement TARGET_SCHED_DFA_POST_ADVANCE_CYCLE. 14770 This hook is being called at the start of each cycle. */ 14771 14772 static void 14773 mips_dfa_post_advance_cycle (void) 14774 { 14775 if (TUNE_LOONGSON_2EF) 14776 mips_ls2_dfa_post_advance_cycle (curr_state); 14777 } 14778 14779 /* Implement TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD. This should 14780 be as wide as the scheduling freedom in the DFA. */ 14781 14782 static int 14783 mips_multipass_dfa_lookahead (void) 14784 { 14785 /* Can schedule up to 4 of the 6 function units in any one cycle. */ 14786 if (TUNE_SB1) 14787 return 4; 14788 14789 if (TUNE_LOONGSON_2EF || TUNE_GS464 || TUNE_GS464E) 14790 return 4; 14791 14792 if (TUNE_OCTEON || TUNE_GS264E) 14793 return 2; 14794 14795 if (TUNE_P5600 || TUNE_P6600 || TUNE_I6400) 14796 return 4; 14797 14798 return 0; 14799 } 14800 14801 /* Remove the instruction at index LOWER from ready queue READY and 14802 reinsert it in front of the instruction at index HIGHER. LOWER must 14803 be <= HIGHER. */ 14804 14805 static void 14806 mips_promote_ready (rtx_insn **ready, int lower, int higher) 14807 { 14808 rtx_insn *new_head; 14809 int i; 14810 14811 new_head = ready[lower]; 14812 for (i = lower; i < higher; i++) 14813 ready[i] = ready[i + 1]; 14814 ready[i] = new_head; 14815 } 14816 14817 /* If the priority of the instruction at POS2 in the ready queue READY 14818 is within LIMIT units of that of the instruction at POS1, swap the 14819 instructions if POS2 is not already less than POS1. */ 14820 14821 static void 14822 mips_maybe_swap_ready (rtx_insn **ready, int pos1, int pos2, int limit) 14823 { 14824 if (pos1 < pos2 14825 && INSN_PRIORITY (ready[pos1]) + limit >= INSN_PRIORITY (ready[pos2])) 14826 { 14827 rtx_insn *temp; 14828 14829 temp = ready[pos1]; 14830 ready[pos1] = ready[pos2]; 14831 ready[pos2] = temp; 14832 } 14833 } 14834 14835 /* Used by TUNE_MACC_CHAINS to record the last scheduled instruction 14836 that may clobber hi or lo. */ 14837 static rtx_insn *mips_macc_chains_last_hilo; 14838 14839 /* A TUNE_MACC_CHAINS helper function. Record that instruction INSN has 14840 been scheduled, updating mips_macc_chains_last_hilo appropriately. */ 14841 14842 static void 14843 mips_macc_chains_record (rtx_insn *insn) 14844 { 14845 if (get_attr_may_clobber_hilo (insn)) 14846 mips_macc_chains_last_hilo = insn; 14847 } 14848 14849 /* A TUNE_MACC_CHAINS helper function. Search ready queue READY, which 14850 has NREADY elements, looking for a multiply-add or multiply-subtract 14851 instruction that is cumulative with mips_macc_chains_last_hilo. 14852 If there is one, promote it ahead of anything else that might 14853 clobber hi or lo. */ 14854 14855 static void 14856 mips_macc_chains_reorder (rtx_insn **ready, int nready) 14857 { 14858 int i, j; 14859 14860 if (mips_macc_chains_last_hilo != 0) 14861 for (i = nready - 1; i >= 0; i--) 14862 if (mips_linked_madd_p (mips_macc_chains_last_hilo, ready[i])) 14863 { 14864 for (j = nready - 1; j > i; j--) 14865 if (recog_memoized (ready[j]) >= 0 14866 && get_attr_may_clobber_hilo (ready[j])) 14867 { 14868 mips_promote_ready (ready, i, j); 14869 break; 14870 } 14871 break; 14872 } 14873 } 14874 14875 /* The last instruction to be scheduled. */ 14876 static rtx_insn *vr4130_last_insn; 14877 14878 /* A note_stores callback used by vr4130_true_reg_dependence_p. DATA 14879 points to an rtx that is initially an instruction. Nullify the rtx 14880 if the instruction uses the value of register X. */ 14881 14882 static void 14883 vr4130_true_reg_dependence_p_1 (rtx x, const_rtx pat ATTRIBUTE_UNUSED, 14884 void *data) 14885 { 14886 rtx *insn_ptr; 14887 14888 insn_ptr = (rtx *) data; 14889 if (REG_P (x) 14890 && *insn_ptr != 0 14891 && reg_referenced_p (x, PATTERN (*insn_ptr))) 14892 *insn_ptr = 0; 14893 } 14894 14895 /* Return true if there is true register dependence between vr4130_last_insn 14896 and INSN. */ 14897 14898 static bool 14899 vr4130_true_reg_dependence_p (rtx insn) 14900 { 14901 note_stores (vr4130_last_insn, vr4130_true_reg_dependence_p_1, &insn); 14902 return insn == 0; 14903 } 14904 14905 /* A TUNE_MIPS4130 helper function. Given that INSN1 is at the head of 14906 the ready queue and that INSN2 is the instruction after it, return 14907 true if it is worth promoting INSN2 ahead of INSN1. Look for cases 14908 in which INSN1 and INSN2 can probably issue in parallel, but for 14909 which (INSN2, INSN1) should be less sensitive to instruction 14910 alignment than (INSN1, INSN2). See 4130.md for more details. */ 14911 14912 static bool 14913 vr4130_swap_insns_p (rtx_insn *insn1, rtx_insn *insn2) 14914 { 14915 sd_iterator_def sd_it; 14916 dep_t dep; 14917 14918 /* Check for the following case: 14919 14920 1) there is some other instruction X with an anti dependence on INSN1; 14921 2) X has a higher priority than INSN2; and 14922 3) X is an arithmetic instruction (and thus has no unit restrictions). 14923 14924 If INSN1 is the last instruction blocking X, it would better to 14925 choose (INSN1, X) over (INSN2, INSN1). */ 14926 FOR_EACH_DEP (insn1, SD_LIST_FORW, sd_it, dep) 14927 if (DEP_TYPE (dep) == REG_DEP_ANTI 14928 && INSN_PRIORITY (DEP_CON (dep)) > INSN_PRIORITY (insn2) 14929 && recog_memoized (DEP_CON (dep)) >= 0 14930 && get_attr_vr4130_class (DEP_CON (dep)) == VR4130_CLASS_ALU) 14931 return false; 14932 14933 if (vr4130_last_insn != 0 14934 && recog_memoized (insn1) >= 0 14935 && recog_memoized (insn2) >= 0) 14936 { 14937 /* See whether INSN1 and INSN2 use different execution units, 14938 or if they are both ALU-type instructions. If so, they can 14939 probably execute in parallel. */ 14940 enum attr_vr4130_class class1 = get_attr_vr4130_class (insn1); 14941 enum attr_vr4130_class class2 = get_attr_vr4130_class (insn2); 14942 if (class1 != class2 || class1 == VR4130_CLASS_ALU) 14943 { 14944 /* If only one of the instructions has a dependence on 14945 vr4130_last_insn, prefer to schedule the other one first. */ 14946 bool dep1_p = vr4130_true_reg_dependence_p (insn1); 14947 bool dep2_p = vr4130_true_reg_dependence_p (insn2); 14948 if (dep1_p != dep2_p) 14949 return dep1_p; 14950 14951 /* Prefer to schedule INSN2 ahead of INSN1 if vr4130_last_insn 14952 is not an ALU-type instruction and if INSN1 uses the same 14953 execution unit. (Note that if this condition holds, we already 14954 know that INSN2 uses a different execution unit.) */ 14955 if (class1 != VR4130_CLASS_ALU 14956 && recog_memoized (vr4130_last_insn) >= 0 14957 && class1 == get_attr_vr4130_class (vr4130_last_insn)) 14958 return true; 14959 } 14960 } 14961 return false; 14962 } 14963 14964 /* A TUNE_MIPS4130 helper function. (READY, NREADY) describes a ready 14965 queue with at least two instructions. Swap the first two if 14966 vr4130_swap_insns_p says that it could be worthwhile. */ 14967 14968 static void 14969 vr4130_reorder (rtx_insn **ready, int nready) 14970 { 14971 if (vr4130_swap_insns_p (ready[nready - 1], ready[nready - 2])) 14972 mips_promote_ready (ready, nready - 2, nready - 1); 14973 } 14974 14975 /* Record whether last 74k AGEN instruction was a load or store. */ 14976 static enum attr_type mips_last_74k_agen_insn = TYPE_UNKNOWN; 14977 14978 /* Initialize mips_last_74k_agen_insn from INSN. A null argument 14979 resets to TYPE_UNKNOWN state. */ 14980 14981 static void 14982 mips_74k_agen_init (rtx_insn *insn) 14983 { 14984 if (!insn || CALL_P (insn) || JUMP_P (insn)) 14985 mips_last_74k_agen_insn = TYPE_UNKNOWN; 14986 else 14987 { 14988 enum attr_type type = get_attr_type (insn); 14989 if (type == TYPE_LOAD || type == TYPE_STORE) 14990 mips_last_74k_agen_insn = type; 14991 } 14992 } 14993 14994 /* A TUNE_74K helper function. The 74K AGEN pipeline likes multiple 14995 loads to be grouped together, and multiple stores to be grouped 14996 together. Swap things around in the ready queue to make this happen. */ 14997 14998 static void 14999 mips_74k_agen_reorder (rtx_insn **ready, int nready) 15000 { 15001 int i; 15002 int store_pos, load_pos; 15003 15004 store_pos = -1; 15005 load_pos = -1; 15006 15007 for (i = nready - 1; i >= 0; i--) 15008 { 15009 rtx_insn *insn = ready[i]; 15010 if (USEFUL_INSN_P (insn)) 15011 switch (get_attr_type (insn)) 15012 { 15013 case TYPE_STORE: 15014 if (store_pos == -1) 15015 store_pos = i; 15016 break; 15017 15018 case TYPE_LOAD: 15019 if (load_pos == -1) 15020 load_pos = i; 15021 break; 15022 15023 default: 15024 break; 15025 } 15026 } 15027 15028 if (load_pos == -1 || store_pos == -1) 15029 return; 15030 15031 switch (mips_last_74k_agen_insn) 15032 { 15033 case TYPE_UNKNOWN: 15034 /* Prefer to schedule loads since they have a higher latency. */ 15035 case TYPE_LOAD: 15036 /* Swap loads to the front of the queue. */ 15037 mips_maybe_swap_ready (ready, load_pos, store_pos, 4); 15038 break; 15039 case TYPE_STORE: 15040 /* Swap stores to the front of the queue. */ 15041 mips_maybe_swap_ready (ready, store_pos, load_pos, 4); 15042 break; 15043 default: 15044 break; 15045 } 15046 } 15047 15048 /* Implement TARGET_SCHED_INIT. */ 15049 15050 static void 15051 mips_sched_init (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED, 15052 int max_ready ATTRIBUTE_UNUSED) 15053 { 15054 mips_macc_chains_last_hilo = 0; 15055 vr4130_last_insn = 0; 15056 mips_74k_agen_init (NULL); 15057 15058 /* When scheduling for Loongson2, branch instructions go to ALU1, 15059 therefore basic block is most likely to start with round-robin counter 15060 pointed to ALU2. */ 15061 mips_ls2.alu1_turn_p = false; 15062 mips_ls2.falu1_turn_p = true; 15063 } 15064 15065 /* Subroutine used by TARGET_SCHED_REORDER and TARGET_SCHED_REORDER2. */ 15066 15067 static void 15068 mips_sched_reorder_1 (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED, 15069 rtx_insn **ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED) 15070 { 15071 if (!reload_completed 15072 && TUNE_MACC_CHAINS 15073 && *nreadyp > 0) 15074 mips_macc_chains_reorder (ready, *nreadyp); 15075 15076 if (reload_completed 15077 && TUNE_MIPS4130 15078 && !TARGET_VR4130_ALIGN 15079 && *nreadyp > 1) 15080 vr4130_reorder (ready, *nreadyp); 15081 15082 if (TUNE_74K) 15083 mips_74k_agen_reorder (ready, *nreadyp); 15084 } 15085 15086 /* Implement TARGET_SCHED_REORDER. */ 15087 15088 static int 15089 mips_sched_reorder (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED, 15090 rtx_insn **ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED) 15091 { 15092 mips_sched_reorder_1 (file, verbose, ready, nreadyp, cycle); 15093 return mips_issue_rate (); 15094 } 15095 15096 /* Implement TARGET_SCHED_REORDER2. */ 15097 15098 static int 15099 mips_sched_reorder2 (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED, 15100 rtx_insn **ready, int *nreadyp, int cycle ATTRIBUTE_UNUSED) 15101 { 15102 mips_sched_reorder_1 (file, verbose, ready, nreadyp, cycle); 15103 return cached_can_issue_more; 15104 } 15105 15106 /* Update round-robin counters for ALU1/2 and FALU1/2. */ 15107 15108 static void 15109 mips_ls2_variable_issue (rtx_insn *insn) 15110 { 15111 if (mips_ls2.alu1_turn_p) 15112 { 15113 if (cpu_unit_reservation_p (curr_state, mips_ls2.alu1_core_unit_code)) 15114 mips_ls2.alu1_turn_p = false; 15115 } 15116 else 15117 { 15118 if (cpu_unit_reservation_p (curr_state, mips_ls2.alu2_core_unit_code)) 15119 mips_ls2.alu1_turn_p = true; 15120 } 15121 15122 if (mips_ls2.falu1_turn_p) 15123 { 15124 if (cpu_unit_reservation_p (curr_state, mips_ls2.falu1_core_unit_code)) 15125 mips_ls2.falu1_turn_p = false; 15126 } 15127 else 15128 { 15129 if (cpu_unit_reservation_p (curr_state, mips_ls2.falu2_core_unit_code)) 15130 mips_ls2.falu1_turn_p = true; 15131 } 15132 15133 if (recog_memoized (insn) >= 0) 15134 mips_ls2.cycle_has_multi_p |= (get_attr_type (insn) == TYPE_MULTI); 15135 } 15136 15137 /* Implement TARGET_SCHED_VARIABLE_ISSUE. */ 15138 15139 static int 15140 mips_variable_issue (FILE *file ATTRIBUTE_UNUSED, int verbose ATTRIBUTE_UNUSED, 15141 rtx_insn *insn, int more) 15142 { 15143 /* Ignore USEs and CLOBBERs; don't count them against the issue rate. */ 15144 if (USEFUL_INSN_P (insn)) 15145 { 15146 if (get_attr_type (insn) != TYPE_GHOST) 15147 more--; 15148 if (!reload_completed && TUNE_MACC_CHAINS) 15149 mips_macc_chains_record (insn); 15150 vr4130_last_insn = insn; 15151 if (TUNE_74K) 15152 mips_74k_agen_init (insn); 15153 else if (TUNE_LOONGSON_2EF) 15154 mips_ls2_variable_issue (insn); 15155 } 15156 15157 /* Instructions of type 'multi' should all be split before 15158 the second scheduling pass. */ 15159 gcc_assert (!reload_completed 15160 || recog_memoized (insn) < 0 15161 || get_attr_type (insn) != TYPE_MULTI); 15162 15163 cached_can_issue_more = more; 15164 return more; 15165 } 15166 15167 /* Given that we have an rtx of the form (prefetch ... WRITE LOCALITY), 15168 return the first operand of the associated PREF or PREFX insn. */ 15169 15170 rtx 15171 mips_prefetch_cookie (rtx write, rtx locality) 15172 { 15173 /* store_streamed / load_streamed. */ 15174 if (INTVAL (locality) <= 0) 15175 return GEN_INT (INTVAL (write) + 4); 15176 15177 /* store / load. */ 15178 if (INTVAL (locality) <= 2) 15179 return write; 15180 15181 /* store_retained / load_retained. */ 15182 return GEN_INT (INTVAL (write) + 6); 15183 } 15184 15185 /* Loongson EXT2 only implements pref hint=0 (prefetch for load) and hint=1 15186 (prefetch for store), other hint just scale to hint = 0 and hint = 1. */ 15187 15188 rtx 15189 mips_loongson_ext2_prefetch_cookie (rtx write, rtx) 15190 { 15191 /* store. */ 15192 if (INTVAL (write) == 1) 15193 return GEN_INT (INTVAL (write)); 15194 15195 /* load. */ 15196 if (INTVAL (write) == 0) 15197 return GEN_INT (INTVAL (write)); 15198 15199 gcc_unreachable (); 15200 } 15201 15202 15203 /* Flags that indicate when a built-in function is available. 15204 15205 BUILTIN_AVAIL_NON_MIPS16 15206 The function is available on the current target if !TARGET_MIPS16. 15207 15208 BUILTIN_AVAIL_MIPS16 15209 The function is available on the current target if TARGET_MIPS16. */ 15210 #define BUILTIN_AVAIL_NON_MIPS16 1 15211 #define BUILTIN_AVAIL_MIPS16 2 15212 15213 /* Declare an availability predicate for built-in functions that 15214 require non-MIPS16 mode and also require COND to be true. 15215 NAME is the main part of the predicate's name. */ 15216 #define AVAIL_NON_MIPS16(NAME, COND) \ 15217 static unsigned int \ 15218 mips_builtin_avail_##NAME (void) \ 15219 { \ 15220 return (COND) ? BUILTIN_AVAIL_NON_MIPS16 : 0; \ 15221 } 15222 15223 /* Declare an availability predicate for built-in functions that 15224 support both MIPS16 and non-MIPS16 code and also require COND 15225 to be true. NAME is the main part of the predicate's name. */ 15226 #define AVAIL_ALL(NAME, COND) \ 15227 static unsigned int \ 15228 mips_builtin_avail_##NAME (void) \ 15229 { \ 15230 return (COND) ? BUILTIN_AVAIL_NON_MIPS16 | BUILTIN_AVAIL_MIPS16 : 0; \ 15231 } 15232 15233 /* This structure describes a single built-in function. */ 15234 struct mips_builtin_description { 15235 /* The code of the main .md file instruction. See mips_builtin_type 15236 for more information. */ 15237 enum insn_code icode; 15238 15239 /* The floating-point comparison code to use with ICODE, if any. */ 15240 enum mips_fp_condition cond; 15241 15242 /* The name of the built-in function. */ 15243 const char *name; 15244 15245 /* Specifies how the function should be expanded. */ 15246 enum mips_builtin_type builtin_type; 15247 15248 /* The function's prototype. */ 15249 enum mips_function_type function_type; 15250 15251 /* Whether the function is available. */ 15252 unsigned int (*avail) (void); 15253 15254 /* Whether the function is pure. */ 15255 bool is_pure; 15256 }; 15257 15258 AVAIL_ALL (hard_float, TARGET_HARD_FLOAT_ABI) 15259 AVAIL_NON_MIPS16 (paired_single, TARGET_PAIRED_SINGLE_FLOAT) 15260 AVAIL_NON_MIPS16 (sb1_paired_single, TARGET_SB1 && TARGET_PAIRED_SINGLE_FLOAT) 15261 AVAIL_NON_MIPS16 (mips3d, TARGET_MIPS3D) 15262 AVAIL_NON_MIPS16 (dsp, TARGET_DSP) 15263 AVAIL_NON_MIPS16 (dspr2, TARGET_DSPR2) 15264 AVAIL_NON_MIPS16 (dsp_32, !TARGET_64BIT && TARGET_DSP) 15265 AVAIL_NON_MIPS16 (dsp_64, TARGET_64BIT && TARGET_DSP) 15266 AVAIL_NON_MIPS16 (dspr2_32, !TARGET_64BIT && TARGET_DSPR2) 15267 AVAIL_NON_MIPS16 (loongson, TARGET_LOONGSON_MMI) 15268 AVAIL_NON_MIPS16 (cache, TARGET_CACHE_BUILTIN) 15269 AVAIL_NON_MIPS16 (msa, TARGET_MSA) 15270 15271 /* Construct a mips_builtin_description from the given arguments. 15272 15273 INSN is the name of the associated instruction pattern, without the 15274 leading CODE_FOR_mips_. 15275 15276 CODE is the floating-point condition code associated with the 15277 function. It can be 'f' if the field is not applicable. 15278 15279 NAME is the name of the function itself, without the leading 15280 "__builtin_mips_". 15281 15282 BUILTIN_TYPE and FUNCTION_TYPE are mips_builtin_description fields. 15283 15284 AVAIL is the name of the availability predicate, without the leading 15285 mips_builtin_avail_. */ 15286 #define MIPS_BUILTIN(INSN, COND, NAME, BUILTIN_TYPE, \ 15287 FUNCTION_TYPE, AVAIL, PURE) \ 15288 { CODE_FOR_mips_ ## INSN, MIPS_FP_COND_ ## COND, \ 15289 "__builtin_mips_" NAME, BUILTIN_TYPE, FUNCTION_TYPE, \ 15290 mips_builtin_avail_ ## AVAIL, PURE } 15291 15292 /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT function 15293 mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE and AVAIL 15294 are as for MIPS_BUILTIN. */ 15295 #define DIRECT_BUILTIN(INSN, FUNCTION_TYPE, AVAIL) \ 15296 MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT, FUNCTION_TYPE, \ 15297 AVAIL, false) 15298 15299 /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT pure function 15300 mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE and AVAIL 15301 are as for MIPS_BUILTIN. */ 15302 #define DIRECT_BUILTIN_PURE(INSN, FUNCTION_TYPE, AVAIL) \ 15303 MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT, FUNCTION_TYPE, \ 15304 AVAIL, true) 15305 15306 /* Define __builtin_mips_<INSN>_<COND>_{s,d} functions, both of which 15307 are subject to mips_builtin_avail_<AVAIL>. */ 15308 #define CMP_SCALAR_BUILTINS(INSN, COND, AVAIL) \ 15309 MIPS_BUILTIN (INSN ## _cond_s, COND, #INSN "_" #COND "_s", \ 15310 MIPS_BUILTIN_CMP_SINGLE, MIPS_INT_FTYPE_SF_SF, AVAIL, \ 15311 false), \ 15312 MIPS_BUILTIN (INSN ## _cond_d, COND, #INSN "_" #COND "_d", \ 15313 MIPS_BUILTIN_CMP_SINGLE, MIPS_INT_FTYPE_DF_DF, AVAIL, false) 15314 15315 /* Define __builtin_mips_{any,all,upper,lower}_<INSN>_<COND>_ps. 15316 The lower and upper forms are subject to mips_builtin_avail_<AVAIL> 15317 while the any and all forms are subject to mips_builtin_avail_mips3d. */ 15318 #define CMP_PS_BUILTINS(INSN, COND, AVAIL) \ 15319 MIPS_BUILTIN (INSN ## _cond_ps, COND, "any_" #INSN "_" #COND "_ps", \ 15320 MIPS_BUILTIN_CMP_ANY, MIPS_INT_FTYPE_V2SF_V2SF, \ 15321 mips3d, false), \ 15322 MIPS_BUILTIN (INSN ## _cond_ps, COND, "all_" #INSN "_" #COND "_ps", \ 15323 MIPS_BUILTIN_CMP_ALL, MIPS_INT_FTYPE_V2SF_V2SF, \ 15324 mips3d, false), \ 15325 MIPS_BUILTIN (INSN ## _cond_ps, COND, "lower_" #INSN "_" #COND "_ps", \ 15326 MIPS_BUILTIN_CMP_LOWER, MIPS_INT_FTYPE_V2SF_V2SF, \ 15327 AVAIL, false), \ 15328 MIPS_BUILTIN (INSN ## _cond_ps, COND, "upper_" #INSN "_" #COND "_ps", \ 15329 MIPS_BUILTIN_CMP_UPPER, MIPS_INT_FTYPE_V2SF_V2SF, \ 15330 AVAIL, false) 15331 15332 /* Define __builtin_mips_{any,all}_<INSN>_<COND>_4s. The functions 15333 are subject to mips_builtin_avail_mips3d. */ 15334 #define CMP_4S_BUILTINS(INSN, COND) \ 15335 MIPS_BUILTIN (INSN ## _cond_4s, COND, "any_" #INSN "_" #COND "_4s", \ 15336 MIPS_BUILTIN_CMP_ANY, \ 15337 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, mips3d, false), \ 15338 MIPS_BUILTIN (INSN ## _cond_4s, COND, "all_" #INSN "_" #COND "_4s", \ 15339 MIPS_BUILTIN_CMP_ALL, \ 15340 MIPS_INT_FTYPE_V2SF_V2SF_V2SF_V2SF, mips3d, false) 15341 15342 /* Define __builtin_mips_mov{t,f}_<INSN>_<COND>_ps. The comparison 15343 instruction requires mips_builtin_avail_<AVAIL>. */ 15344 #define MOVTF_BUILTINS(INSN, COND, AVAIL) \ 15345 MIPS_BUILTIN (INSN ## _cond_ps, COND, "movt_" #INSN "_" #COND "_ps", \ 15346 MIPS_BUILTIN_MOVT, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, \ 15347 AVAIL, false), \ 15348 MIPS_BUILTIN (INSN ## _cond_ps, COND, "movf_" #INSN "_" #COND "_ps", \ 15349 MIPS_BUILTIN_MOVF, MIPS_V2SF_FTYPE_V2SF_V2SF_V2SF_V2SF, \ 15350 AVAIL, false) 15351 15352 /* Define all the built-in functions related to C.cond.fmt condition COND. */ 15353 #define CMP_BUILTINS(COND) \ 15354 MOVTF_BUILTINS (c, COND, paired_single), \ 15355 MOVTF_BUILTINS (cabs, COND, mips3d), \ 15356 CMP_SCALAR_BUILTINS (cabs, COND, mips3d), \ 15357 CMP_PS_BUILTINS (c, COND, paired_single), \ 15358 CMP_PS_BUILTINS (cabs, COND, mips3d), \ 15359 CMP_4S_BUILTINS (c, COND), \ 15360 CMP_4S_BUILTINS (cabs, COND) 15361 15362 /* Define __builtin_mips_<INSN>, which is a MIPS_BUILTIN_DIRECT_NO_TARGET 15363 function mapped to instruction CODE_FOR_mips_<INSN>, FUNCTION_TYPE 15364 and AVAIL are as for MIPS_BUILTIN. */ 15365 #define DIRECT_NO_TARGET_BUILTIN(INSN, FUNCTION_TYPE, AVAIL) \ 15366 MIPS_BUILTIN (INSN, f, #INSN, MIPS_BUILTIN_DIRECT_NO_TARGET, \ 15367 FUNCTION_TYPE, AVAIL, false) 15368 15369 /* Define __builtin_mips_bposge<VALUE>. <VALUE> is 32 for the MIPS32 DSP 15370 branch instruction. AVAIL is as for MIPS_BUILTIN. */ 15371 #define BPOSGE_BUILTIN(VALUE, AVAIL) \ 15372 MIPS_BUILTIN (bposge, f, "bposge" #VALUE, \ 15373 MIPS_BUILTIN_BPOSGE ## VALUE, MIPS_SI_FTYPE_VOID, AVAIL, false) 15374 15375 /* Define a Loongson MIPS_BUILTIN_DIRECT function __builtin_loongson_<FN_NAME> 15376 for instruction CODE_FOR_loongson_<INSN>. FUNCTION_TYPE is a 15377 builtin_description field. */ 15378 #define LOONGSON_BUILTIN_ALIAS(INSN, FN_NAME, FUNCTION_TYPE) \ 15379 { CODE_FOR_loongson_ ## INSN, MIPS_FP_COND_f, \ 15380 "__builtin_loongson_" #FN_NAME, MIPS_BUILTIN_DIRECT, \ 15381 FUNCTION_TYPE, mips_builtin_avail_loongson, false } 15382 15383 /* Define a Loongson MIPS_BUILTIN_DIRECT function __builtin_loongson_<INSN> 15384 for instruction CODE_FOR_loongson_<INSN>. FUNCTION_TYPE is a 15385 builtin_description field. */ 15386 #define LOONGSON_BUILTIN(INSN, FUNCTION_TYPE) \ 15387 LOONGSON_BUILTIN_ALIAS (INSN, INSN, FUNCTION_TYPE) 15388 15389 /* Like LOONGSON_BUILTIN, but add _<SUFFIX> to the end of the function name. 15390 We use functions of this form when the same insn can be usefully applied 15391 to more than one datatype. */ 15392 #define LOONGSON_BUILTIN_SUFFIX(INSN, SUFFIX, FUNCTION_TYPE) \ 15393 LOONGSON_BUILTIN_ALIAS (INSN, INSN ## _ ## SUFFIX, FUNCTION_TYPE) 15394 15395 /* Define an MSA MIPS_BUILTIN_DIRECT pure function __builtin_msa_<INSN> 15396 for instruction CODE_FOR_msa_<INSN>. FUNCTION_TYPE is a builtin_description 15397 field. */ 15398 #define MSA_BUILTIN_PURE(INSN, FUNCTION_TYPE) \ 15399 { CODE_FOR_msa_ ## INSN, MIPS_FP_COND_f, \ 15400 "__builtin_msa_" #INSN, MIPS_BUILTIN_DIRECT, \ 15401 FUNCTION_TYPE, mips_builtin_avail_msa, true } 15402 15403 /* Define an MSA MIPS_BUILTIN_DIRECT non-pure function __builtin_msa_<INSN> 15404 for instruction CODE_FOR_msa_<INSN>. FUNCTION_TYPE is a builtin_description 15405 field. */ 15406 #define MSA_BUILTIN(INSN, FUNCTION_TYPE) \ 15407 { CODE_FOR_msa_ ## INSN, MIPS_FP_COND_f, \ 15408 "__builtin_msa_" #INSN, MIPS_BUILTIN_DIRECT, \ 15409 FUNCTION_TYPE, mips_builtin_avail_msa, false } 15410 15411 /* Define a remapped MSA MIPS_BUILTIN_DIRECT function __builtin_msa_<INSN> 15412 for instruction CODE_FOR_msa_<INSN2>. FUNCTION_TYPE is 15413 a builtin_description field. */ 15414 #define MSA_BUILTIN_REMAP(INSN, INSN2, FUNCTION_TYPE) \ 15415 { CODE_FOR_msa_ ## INSN2, MIPS_FP_COND_f, \ 15416 "__builtin_msa_" #INSN, MIPS_BUILTIN_DIRECT, \ 15417 FUNCTION_TYPE, mips_builtin_avail_msa, false } 15418 15419 /* Define an MSA MIPS_BUILTIN_MSA_TEST_BRANCH function __builtin_msa_<INSN> 15420 for instruction CODE_FOR_msa_<INSN>. FUNCTION_TYPE is a builtin_description 15421 field. */ 15422 #define MSA_BUILTIN_TEST_BRANCH(INSN, FUNCTION_TYPE) \ 15423 { CODE_FOR_msa_ ## INSN, MIPS_FP_COND_f, \ 15424 "__builtin_msa_" #INSN, MIPS_BUILTIN_MSA_TEST_BRANCH, \ 15425 FUNCTION_TYPE, mips_builtin_avail_msa, false } 15426 15427 /* Define an MSA MIPS_BUILTIN_DIRECT_NO_TARGET function __builtin_msa_<INSN> 15428 for instruction CODE_FOR_msa_<INSN>. FUNCTION_TYPE is a builtin_description 15429 field. */ 15430 #define MSA_NO_TARGET_BUILTIN(INSN, FUNCTION_TYPE) \ 15431 { CODE_FOR_msa_ ## INSN, MIPS_FP_COND_f, \ 15432 "__builtin_msa_" #INSN, MIPS_BUILTIN_DIRECT_NO_TARGET, \ 15433 FUNCTION_TYPE, mips_builtin_avail_msa, false } 15434 15435 #define CODE_FOR_mips_sqrt_ps CODE_FOR_sqrtv2sf2 15436 #define CODE_FOR_mips_addq_ph CODE_FOR_addv2hi3 15437 #define CODE_FOR_mips_addu_qb CODE_FOR_addv4qi3 15438 #define CODE_FOR_mips_subq_ph CODE_FOR_subv2hi3 15439 #define CODE_FOR_mips_subu_qb CODE_FOR_subv4qi3 15440 #define CODE_FOR_mips_mul_ph CODE_FOR_mulv2hi3 15441 #define CODE_FOR_mips_mult CODE_FOR_mulsidi3_32bit 15442 #define CODE_FOR_mips_multu CODE_FOR_umulsidi3_32bit 15443 15444 #define CODE_FOR_loongson_packsswh CODE_FOR_vec_pack_ssat_v2si 15445 #define CODE_FOR_loongson_packsshb CODE_FOR_vec_pack_ssat_v4hi 15446 #define CODE_FOR_loongson_packushb CODE_FOR_vec_pack_usat_v4hi 15447 #define CODE_FOR_loongson_paddw CODE_FOR_addv2si3 15448 #define CODE_FOR_loongson_paddh CODE_FOR_addv4hi3 15449 #define CODE_FOR_loongson_paddb CODE_FOR_addv8qi3 15450 #define CODE_FOR_loongson_paddsh CODE_FOR_ssaddv4hi3 15451 #define CODE_FOR_loongson_paddsb CODE_FOR_ssaddv8qi3 15452 #define CODE_FOR_loongson_paddush CODE_FOR_usaddv4hi3 15453 #define CODE_FOR_loongson_paddusb CODE_FOR_usaddv8qi3 15454 #define CODE_FOR_loongson_pmaxsh CODE_FOR_smaxv4hi3 15455 #define CODE_FOR_loongson_pmaxub CODE_FOR_umaxv8qi3 15456 #define CODE_FOR_loongson_pminsh CODE_FOR_sminv4hi3 15457 #define CODE_FOR_loongson_pminub CODE_FOR_uminv8qi3 15458 #define CODE_FOR_loongson_pmulhuh CODE_FOR_umulv4hi3_highpart 15459 #define CODE_FOR_loongson_pmulhh CODE_FOR_smulv4hi3_highpart 15460 #define CODE_FOR_loongson_pmullh CODE_FOR_mulv4hi3 15461 #define CODE_FOR_loongson_psllh CODE_FOR_ashlv4hi3 15462 #define CODE_FOR_loongson_psllw CODE_FOR_ashlv2si3 15463 #define CODE_FOR_loongson_psrlh CODE_FOR_lshrv4hi3 15464 #define CODE_FOR_loongson_psrlw CODE_FOR_lshrv2si3 15465 #define CODE_FOR_loongson_psrah CODE_FOR_ashrv4hi3 15466 #define CODE_FOR_loongson_psraw CODE_FOR_ashrv2si3 15467 #define CODE_FOR_loongson_psubw CODE_FOR_subv2si3 15468 #define CODE_FOR_loongson_psubh CODE_FOR_subv4hi3 15469 #define CODE_FOR_loongson_psubb CODE_FOR_subv8qi3 15470 #define CODE_FOR_loongson_psubsh CODE_FOR_sssubv4hi3 15471 #define CODE_FOR_loongson_psubsb CODE_FOR_sssubv8qi3 15472 #define CODE_FOR_loongson_psubush CODE_FOR_ussubv4hi3 15473 #define CODE_FOR_loongson_psubusb CODE_FOR_ussubv8qi3 15474 15475 #define CODE_FOR_msa_adds_s_b CODE_FOR_ssaddv16qi3 15476 #define CODE_FOR_msa_adds_s_h CODE_FOR_ssaddv8hi3 15477 #define CODE_FOR_msa_adds_s_w CODE_FOR_ssaddv4si3 15478 #define CODE_FOR_msa_adds_s_d CODE_FOR_ssaddv2di3 15479 #define CODE_FOR_msa_adds_u_b CODE_FOR_usaddv16qi3 15480 #define CODE_FOR_msa_adds_u_h CODE_FOR_usaddv8hi3 15481 #define CODE_FOR_msa_adds_u_w CODE_FOR_usaddv4si3 15482 #define CODE_FOR_msa_adds_u_d CODE_FOR_usaddv2di3 15483 #define CODE_FOR_msa_addv_b CODE_FOR_addv16qi3 15484 #define CODE_FOR_msa_addv_h CODE_FOR_addv8hi3 15485 #define CODE_FOR_msa_addv_w CODE_FOR_addv4si3 15486 #define CODE_FOR_msa_addv_d CODE_FOR_addv2di3 15487 #define CODE_FOR_msa_addvi_b CODE_FOR_addv16qi3 15488 #define CODE_FOR_msa_addvi_h CODE_FOR_addv8hi3 15489 #define CODE_FOR_msa_addvi_w CODE_FOR_addv4si3 15490 #define CODE_FOR_msa_addvi_d CODE_FOR_addv2di3 15491 #define CODE_FOR_msa_and_v CODE_FOR_andv16qi3 15492 #define CODE_FOR_msa_andi_b CODE_FOR_andv16qi3 15493 #define CODE_FOR_msa_bmnz_v CODE_FOR_msa_bmnz_b 15494 #define CODE_FOR_msa_bmnzi_b CODE_FOR_msa_bmnz_b 15495 #define CODE_FOR_msa_bmz_v CODE_FOR_msa_bmz_b 15496 #define CODE_FOR_msa_bmzi_b CODE_FOR_msa_bmz_b 15497 #define CODE_FOR_msa_bnz_v CODE_FOR_msa_bnz_v_b 15498 #define CODE_FOR_msa_bz_v CODE_FOR_msa_bz_v_b 15499 #define CODE_FOR_msa_bsel_v CODE_FOR_msa_bsel_b 15500 #define CODE_FOR_msa_bseli_b CODE_FOR_msa_bsel_b 15501 #define CODE_FOR_msa_ceqi_b CODE_FOR_msa_ceq_b 15502 #define CODE_FOR_msa_ceqi_h CODE_FOR_msa_ceq_h 15503 #define CODE_FOR_msa_ceqi_w CODE_FOR_msa_ceq_w 15504 #define CODE_FOR_msa_ceqi_d CODE_FOR_msa_ceq_d 15505 #define CODE_FOR_msa_clti_s_b CODE_FOR_msa_clt_s_b 15506 #define CODE_FOR_msa_clti_s_h CODE_FOR_msa_clt_s_h 15507 #define CODE_FOR_msa_clti_s_w CODE_FOR_msa_clt_s_w 15508 #define CODE_FOR_msa_clti_s_d CODE_FOR_msa_clt_s_d 15509 #define CODE_FOR_msa_clti_u_b CODE_FOR_msa_clt_u_b 15510 #define CODE_FOR_msa_clti_u_h CODE_FOR_msa_clt_u_h 15511 #define CODE_FOR_msa_clti_u_w CODE_FOR_msa_clt_u_w 15512 #define CODE_FOR_msa_clti_u_d CODE_FOR_msa_clt_u_d 15513 #define CODE_FOR_msa_clei_s_b CODE_FOR_msa_cle_s_b 15514 #define CODE_FOR_msa_clei_s_h CODE_FOR_msa_cle_s_h 15515 #define CODE_FOR_msa_clei_s_w CODE_FOR_msa_cle_s_w 15516 #define CODE_FOR_msa_clei_s_d CODE_FOR_msa_cle_s_d 15517 #define CODE_FOR_msa_clei_u_b CODE_FOR_msa_cle_u_b 15518 #define CODE_FOR_msa_clei_u_h CODE_FOR_msa_cle_u_h 15519 #define CODE_FOR_msa_clei_u_w CODE_FOR_msa_cle_u_w 15520 #define CODE_FOR_msa_clei_u_d CODE_FOR_msa_cle_u_d 15521 #define CODE_FOR_msa_div_s_b CODE_FOR_divv16qi3 15522 #define CODE_FOR_msa_div_s_h CODE_FOR_divv8hi3 15523 #define CODE_FOR_msa_div_s_w CODE_FOR_divv4si3 15524 #define CODE_FOR_msa_div_s_d CODE_FOR_divv2di3 15525 #define CODE_FOR_msa_div_u_b CODE_FOR_udivv16qi3 15526 #define CODE_FOR_msa_div_u_h CODE_FOR_udivv8hi3 15527 #define CODE_FOR_msa_div_u_w CODE_FOR_udivv4si3 15528 #define CODE_FOR_msa_div_u_d CODE_FOR_udivv2di3 15529 #define CODE_FOR_msa_fadd_w CODE_FOR_addv4sf3 15530 #define CODE_FOR_msa_fadd_d CODE_FOR_addv2df3 15531 #define CODE_FOR_msa_fexdo_w CODE_FOR_vec_pack_trunc_v2df 15532 #define CODE_FOR_msa_ftrunc_s_w CODE_FOR_fix_truncv4sfv4si2 15533 #define CODE_FOR_msa_ftrunc_s_d CODE_FOR_fix_truncv2dfv2di2 15534 #define CODE_FOR_msa_ftrunc_u_w CODE_FOR_fixuns_truncv4sfv4si2 15535 #define CODE_FOR_msa_ftrunc_u_d CODE_FOR_fixuns_truncv2dfv2di2 15536 #define CODE_FOR_msa_ffint_s_w CODE_FOR_floatv4siv4sf2 15537 #define CODE_FOR_msa_ffint_s_d CODE_FOR_floatv2div2df2 15538 #define CODE_FOR_msa_ffint_u_w CODE_FOR_floatunsv4siv4sf2 15539 #define CODE_FOR_msa_ffint_u_d CODE_FOR_floatunsv2div2df2 15540 #define CODE_FOR_msa_fsub_w CODE_FOR_subv4sf3 15541 #define CODE_FOR_msa_fsub_d CODE_FOR_subv2df3 15542 #define CODE_FOR_msa_fmadd_w CODE_FOR_fmav4sf4 15543 #define CODE_FOR_msa_fmadd_d CODE_FOR_fmav2df4 15544 #define CODE_FOR_msa_fmsub_w CODE_FOR_fnmav4sf4 15545 #define CODE_FOR_msa_fmsub_d CODE_FOR_fnmav2df4 15546 #define CODE_FOR_msa_fmul_w CODE_FOR_mulv4sf3 15547 #define CODE_FOR_msa_fmul_d CODE_FOR_mulv2df3 15548 #define CODE_FOR_msa_fdiv_w CODE_FOR_divv4sf3 15549 #define CODE_FOR_msa_fdiv_d CODE_FOR_divv2df3 15550 #define CODE_FOR_msa_fmax_w CODE_FOR_smaxv4sf3 15551 #define CODE_FOR_msa_fmax_d CODE_FOR_smaxv2df3 15552 #define CODE_FOR_msa_fmin_w CODE_FOR_sminv4sf3 15553 #define CODE_FOR_msa_fmin_d CODE_FOR_sminv2df3 15554 #define CODE_FOR_msa_fsqrt_w CODE_FOR_sqrtv4sf2 15555 #define CODE_FOR_msa_fsqrt_d CODE_FOR_sqrtv2df2 15556 #define CODE_FOR_msa_max_s_b CODE_FOR_smaxv16qi3 15557 #define CODE_FOR_msa_max_s_h CODE_FOR_smaxv8hi3 15558 #define CODE_FOR_msa_max_s_w CODE_FOR_smaxv4si3 15559 #define CODE_FOR_msa_max_s_d CODE_FOR_smaxv2di3 15560 #define CODE_FOR_msa_maxi_s_b CODE_FOR_smaxv16qi3 15561 #define CODE_FOR_msa_maxi_s_h CODE_FOR_smaxv8hi3 15562 #define CODE_FOR_msa_maxi_s_w CODE_FOR_smaxv4si3 15563 #define CODE_FOR_msa_maxi_s_d CODE_FOR_smaxv2di3 15564 #define CODE_FOR_msa_max_u_b CODE_FOR_umaxv16qi3 15565 #define CODE_FOR_msa_max_u_h CODE_FOR_umaxv8hi3 15566 #define CODE_FOR_msa_max_u_w CODE_FOR_umaxv4si3 15567 #define CODE_FOR_msa_max_u_d CODE_FOR_umaxv2di3 15568 #define CODE_FOR_msa_maxi_u_b CODE_FOR_umaxv16qi3 15569 #define CODE_FOR_msa_maxi_u_h CODE_FOR_umaxv8hi3 15570 #define CODE_FOR_msa_maxi_u_w CODE_FOR_umaxv4si3 15571 #define CODE_FOR_msa_maxi_u_d CODE_FOR_umaxv2di3 15572 #define CODE_FOR_msa_min_s_b CODE_FOR_sminv16qi3 15573 #define CODE_FOR_msa_min_s_h CODE_FOR_sminv8hi3 15574 #define CODE_FOR_msa_min_s_w CODE_FOR_sminv4si3 15575 #define CODE_FOR_msa_min_s_d CODE_FOR_sminv2di3 15576 #define CODE_FOR_msa_mini_s_b CODE_FOR_sminv16qi3 15577 #define CODE_FOR_msa_mini_s_h CODE_FOR_sminv8hi3 15578 #define CODE_FOR_msa_mini_s_w CODE_FOR_sminv4si3 15579 #define CODE_FOR_msa_mini_s_d CODE_FOR_sminv2di3 15580 #define CODE_FOR_msa_min_u_b CODE_FOR_uminv16qi3 15581 #define CODE_FOR_msa_min_u_h CODE_FOR_uminv8hi3 15582 #define CODE_FOR_msa_min_u_w CODE_FOR_uminv4si3 15583 #define CODE_FOR_msa_min_u_d CODE_FOR_uminv2di3 15584 #define CODE_FOR_msa_mini_u_b CODE_FOR_uminv16qi3 15585 #define CODE_FOR_msa_mini_u_h CODE_FOR_uminv8hi3 15586 #define CODE_FOR_msa_mini_u_w CODE_FOR_uminv4si3 15587 #define CODE_FOR_msa_mini_u_d CODE_FOR_uminv2di3 15588 #define CODE_FOR_msa_mod_s_b CODE_FOR_modv16qi3 15589 #define CODE_FOR_msa_mod_s_h CODE_FOR_modv8hi3 15590 #define CODE_FOR_msa_mod_s_w CODE_FOR_modv4si3 15591 #define CODE_FOR_msa_mod_s_d CODE_FOR_modv2di3 15592 #define CODE_FOR_msa_mod_u_b CODE_FOR_umodv16qi3 15593 #define CODE_FOR_msa_mod_u_h CODE_FOR_umodv8hi3 15594 #define CODE_FOR_msa_mod_u_w CODE_FOR_umodv4si3 15595 #define CODE_FOR_msa_mod_u_d CODE_FOR_umodv2di3 15596 #define CODE_FOR_msa_mod_s_b CODE_FOR_modv16qi3 15597 #define CODE_FOR_msa_mod_s_h CODE_FOR_modv8hi3 15598 #define CODE_FOR_msa_mod_s_w CODE_FOR_modv4si3 15599 #define CODE_FOR_msa_mod_s_d CODE_FOR_modv2di3 15600 #define CODE_FOR_msa_mod_u_b CODE_FOR_umodv16qi3 15601 #define CODE_FOR_msa_mod_u_h CODE_FOR_umodv8hi3 15602 #define CODE_FOR_msa_mod_u_w CODE_FOR_umodv4si3 15603 #define CODE_FOR_msa_mod_u_d CODE_FOR_umodv2di3 15604 #define CODE_FOR_msa_mulv_b CODE_FOR_mulv16qi3 15605 #define CODE_FOR_msa_mulv_h CODE_FOR_mulv8hi3 15606 #define CODE_FOR_msa_mulv_w CODE_FOR_mulv4si3 15607 #define CODE_FOR_msa_mulv_d CODE_FOR_mulv2di3 15608 #define CODE_FOR_msa_nlzc_b CODE_FOR_clzv16qi2 15609 #define CODE_FOR_msa_nlzc_h CODE_FOR_clzv8hi2 15610 #define CODE_FOR_msa_nlzc_w CODE_FOR_clzv4si2 15611 #define CODE_FOR_msa_nlzc_d CODE_FOR_clzv2di2 15612 #define CODE_FOR_msa_nor_v CODE_FOR_msa_nor_b 15613 #define CODE_FOR_msa_or_v CODE_FOR_iorv16qi3 15614 #define CODE_FOR_msa_ori_b CODE_FOR_iorv16qi3 15615 #define CODE_FOR_msa_nori_b CODE_FOR_msa_nor_b 15616 #define CODE_FOR_msa_pcnt_b CODE_FOR_popcountv16qi2 15617 #define CODE_FOR_msa_pcnt_h CODE_FOR_popcountv8hi2 15618 #define CODE_FOR_msa_pcnt_w CODE_FOR_popcountv4si2 15619 #define CODE_FOR_msa_pcnt_d CODE_FOR_popcountv2di2 15620 #define CODE_FOR_msa_xor_v CODE_FOR_xorv16qi3 15621 #define CODE_FOR_msa_xori_b CODE_FOR_xorv16qi3 15622 #define CODE_FOR_msa_sll_b CODE_FOR_vashlv16qi3 15623 #define CODE_FOR_msa_sll_h CODE_FOR_vashlv8hi3 15624 #define CODE_FOR_msa_sll_w CODE_FOR_vashlv4si3 15625 #define CODE_FOR_msa_sll_d CODE_FOR_vashlv2di3 15626 #define CODE_FOR_msa_slli_b CODE_FOR_vashlv16qi3 15627 #define CODE_FOR_msa_slli_h CODE_FOR_vashlv8hi3 15628 #define CODE_FOR_msa_slli_w CODE_FOR_vashlv4si3 15629 #define CODE_FOR_msa_slli_d CODE_FOR_vashlv2di3 15630 #define CODE_FOR_msa_sra_b CODE_FOR_vashrv16qi3 15631 #define CODE_FOR_msa_sra_h CODE_FOR_vashrv8hi3 15632 #define CODE_FOR_msa_sra_w CODE_FOR_vashrv4si3 15633 #define CODE_FOR_msa_sra_d CODE_FOR_vashrv2di3 15634 #define CODE_FOR_msa_srai_b CODE_FOR_vashrv16qi3 15635 #define CODE_FOR_msa_srai_h CODE_FOR_vashrv8hi3 15636 #define CODE_FOR_msa_srai_w CODE_FOR_vashrv4si3 15637 #define CODE_FOR_msa_srai_d CODE_FOR_vashrv2di3 15638 #define CODE_FOR_msa_srl_b CODE_FOR_vlshrv16qi3 15639 #define CODE_FOR_msa_srl_h CODE_FOR_vlshrv8hi3 15640 #define CODE_FOR_msa_srl_w CODE_FOR_vlshrv4si3 15641 #define CODE_FOR_msa_srl_d CODE_FOR_vlshrv2di3 15642 #define CODE_FOR_msa_srli_b CODE_FOR_vlshrv16qi3 15643 #define CODE_FOR_msa_srli_h CODE_FOR_vlshrv8hi3 15644 #define CODE_FOR_msa_srli_w CODE_FOR_vlshrv4si3 15645 #define CODE_FOR_msa_srli_d CODE_FOR_vlshrv2di3 15646 #define CODE_FOR_msa_subv_b CODE_FOR_subv16qi3 15647 #define CODE_FOR_msa_subv_h CODE_FOR_subv8hi3 15648 #define CODE_FOR_msa_subv_w CODE_FOR_subv4si3 15649 #define CODE_FOR_msa_subv_d CODE_FOR_subv2di3 15650 #define CODE_FOR_msa_subvi_b CODE_FOR_subv16qi3 15651 #define CODE_FOR_msa_subvi_h CODE_FOR_subv8hi3 15652 #define CODE_FOR_msa_subvi_w CODE_FOR_subv4si3 15653 #define CODE_FOR_msa_subvi_d CODE_FOR_subv2di3 15654 15655 #define CODE_FOR_msa_move_v CODE_FOR_movv16qi 15656 15657 #define CODE_FOR_msa_vshf_b CODE_FOR_vec_permv16qi 15658 #define CODE_FOR_msa_vshf_h CODE_FOR_vec_permv8hi 15659 #define CODE_FOR_msa_vshf_w CODE_FOR_vec_permv4si 15660 #define CODE_FOR_msa_vshf_d CODE_FOR_vec_permv2di 15661 15662 #define CODE_FOR_msa_ilvod_d CODE_FOR_msa_ilvl_d 15663 #define CODE_FOR_msa_ilvev_d CODE_FOR_msa_ilvr_d 15664 #define CODE_FOR_msa_pckod_d CODE_FOR_msa_ilvl_d 15665 #define CODE_FOR_msa_pckev_d CODE_FOR_msa_ilvr_d 15666 15667 #define CODE_FOR_msa_ldi_b CODE_FOR_msa_ldiv16qi 15668 #define CODE_FOR_msa_ldi_h CODE_FOR_msa_ldiv8hi 15669 #define CODE_FOR_msa_ldi_w CODE_FOR_msa_ldiv4si 15670 #define CODE_FOR_msa_ldi_d CODE_FOR_msa_ldiv2di 15671 15672 static const struct mips_builtin_description mips_builtins[] = { 15673 #define MIPS_GET_FCSR 0 15674 DIRECT_BUILTIN (get_fcsr, MIPS_USI_FTYPE_VOID, hard_float), 15675 #define MIPS_SET_FCSR 1 15676 DIRECT_NO_TARGET_BUILTIN (set_fcsr, MIPS_VOID_FTYPE_USI, hard_float), 15677 15678 DIRECT_BUILTIN_PURE (pll_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single), 15679 DIRECT_BUILTIN_PURE (pul_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single), 15680 DIRECT_BUILTIN_PURE (plu_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single), 15681 DIRECT_BUILTIN_PURE (puu_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, paired_single), 15682 DIRECT_BUILTIN_PURE (cvt_ps_s, MIPS_V2SF_FTYPE_SF_SF, paired_single), 15683 DIRECT_BUILTIN_PURE (cvt_s_pl, MIPS_SF_FTYPE_V2SF, paired_single), 15684 DIRECT_BUILTIN_PURE (cvt_s_pu, MIPS_SF_FTYPE_V2SF, paired_single), 15685 DIRECT_BUILTIN_PURE (abs_ps, MIPS_V2SF_FTYPE_V2SF, paired_single), 15686 15687 DIRECT_BUILTIN_PURE (alnv_ps, MIPS_V2SF_FTYPE_V2SF_V2SF_INT, paired_single), 15688 DIRECT_BUILTIN_PURE (addr_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d), 15689 DIRECT_BUILTIN_PURE (mulr_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d), 15690 DIRECT_BUILTIN_PURE (cvt_pw_ps, MIPS_V2SF_FTYPE_V2SF, mips3d), 15691 DIRECT_BUILTIN_PURE (cvt_ps_pw, MIPS_V2SF_FTYPE_V2SF, mips3d), 15692 15693 DIRECT_BUILTIN_PURE (recip1_s, MIPS_SF_FTYPE_SF, mips3d), 15694 DIRECT_BUILTIN_PURE (recip1_d, MIPS_DF_FTYPE_DF, mips3d), 15695 DIRECT_BUILTIN_PURE (recip1_ps, MIPS_V2SF_FTYPE_V2SF, mips3d), 15696 DIRECT_BUILTIN_PURE (recip2_s, MIPS_SF_FTYPE_SF_SF, mips3d), 15697 DIRECT_BUILTIN_PURE (recip2_d, MIPS_DF_FTYPE_DF_DF, mips3d), 15698 DIRECT_BUILTIN_PURE (recip2_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d), 15699 15700 DIRECT_BUILTIN_PURE (rsqrt1_s, MIPS_SF_FTYPE_SF, mips3d), 15701 DIRECT_BUILTIN_PURE (rsqrt1_d, MIPS_DF_FTYPE_DF, mips3d), 15702 DIRECT_BUILTIN_PURE (rsqrt1_ps, MIPS_V2SF_FTYPE_V2SF, mips3d), 15703 DIRECT_BUILTIN_PURE (rsqrt2_s, MIPS_SF_FTYPE_SF_SF, mips3d), 15704 DIRECT_BUILTIN_PURE (rsqrt2_d, MIPS_DF_FTYPE_DF_DF, mips3d), 15705 DIRECT_BUILTIN_PURE (rsqrt2_ps, MIPS_V2SF_FTYPE_V2SF_V2SF, mips3d), 15706 15707 MIPS_FP_CONDITIONS (CMP_BUILTINS), 15708 15709 /* Built-in functions for the SB-1 processor. */ 15710 DIRECT_BUILTIN (sqrt_ps, MIPS_V2SF_FTYPE_V2SF, sb1_paired_single), 15711 15712 /* Built-in functions for the DSP ASE (32-bit and 64-bit). */ 15713 DIRECT_BUILTIN_PURE (addq_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15714 DIRECT_BUILTIN_PURE (addq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15715 DIRECT_BUILTIN_PURE (addq_s_w, MIPS_SI_FTYPE_SI_SI, dsp), 15716 DIRECT_BUILTIN_PURE (addu_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp), 15717 DIRECT_BUILTIN_PURE (addu_s_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp), 15718 DIRECT_BUILTIN_PURE (subq_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15719 DIRECT_BUILTIN_PURE (subq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15720 DIRECT_BUILTIN_PURE (subq_s_w, MIPS_SI_FTYPE_SI_SI, dsp), 15721 DIRECT_BUILTIN_PURE (subu_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp), 15722 DIRECT_BUILTIN_PURE (subu_s_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp), 15723 DIRECT_BUILTIN_PURE (addsc, MIPS_SI_FTYPE_SI_SI, dsp), 15724 DIRECT_BUILTIN_PURE (addwc, MIPS_SI_FTYPE_SI_SI, dsp), 15725 DIRECT_BUILTIN_PURE (modsub, MIPS_SI_FTYPE_SI_SI, dsp), 15726 DIRECT_BUILTIN_PURE (raddu_w_qb, MIPS_SI_FTYPE_V4QI, dsp), 15727 DIRECT_BUILTIN_PURE (absq_s_ph, MIPS_V2HI_FTYPE_V2HI, dsp), 15728 DIRECT_BUILTIN_PURE (absq_s_w, MIPS_SI_FTYPE_SI, dsp), 15729 DIRECT_BUILTIN_PURE (precrq_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dsp), 15730 DIRECT_BUILTIN_PURE (precrq_ph_w, MIPS_V2HI_FTYPE_SI_SI, dsp), 15731 DIRECT_BUILTIN_PURE (precrq_rs_ph_w, MIPS_V2HI_FTYPE_SI_SI, dsp), 15732 DIRECT_BUILTIN_PURE (precrqu_s_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dsp), 15733 DIRECT_BUILTIN_PURE (preceq_w_phl, MIPS_SI_FTYPE_V2HI, dsp), 15734 DIRECT_BUILTIN_PURE (preceq_w_phr, MIPS_SI_FTYPE_V2HI, dsp), 15735 DIRECT_BUILTIN_PURE (precequ_ph_qbl, MIPS_V2HI_FTYPE_V4QI, dsp), 15736 DIRECT_BUILTIN_PURE (precequ_ph_qbr, MIPS_V2HI_FTYPE_V4QI, dsp), 15737 DIRECT_BUILTIN_PURE (precequ_ph_qbla, MIPS_V2HI_FTYPE_V4QI, dsp), 15738 DIRECT_BUILTIN_PURE (precequ_ph_qbra, MIPS_V2HI_FTYPE_V4QI, dsp), 15739 DIRECT_BUILTIN_PURE (preceu_ph_qbl, MIPS_V2HI_FTYPE_V4QI, dsp), 15740 DIRECT_BUILTIN_PURE (preceu_ph_qbr, MIPS_V2HI_FTYPE_V4QI, dsp), 15741 DIRECT_BUILTIN_PURE (preceu_ph_qbla, MIPS_V2HI_FTYPE_V4QI, dsp), 15742 DIRECT_BUILTIN_PURE (preceu_ph_qbra, MIPS_V2HI_FTYPE_V4QI, dsp), 15743 DIRECT_BUILTIN_PURE (shll_qb, MIPS_V4QI_FTYPE_V4QI_SI, dsp), 15744 DIRECT_BUILTIN_PURE (shll_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp), 15745 DIRECT_BUILTIN_PURE (shll_s_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp), 15746 DIRECT_BUILTIN_PURE (shll_s_w, MIPS_SI_FTYPE_SI_SI, dsp), 15747 DIRECT_BUILTIN_PURE (shrl_qb, MIPS_V4QI_FTYPE_V4QI_SI, dsp), 15748 DIRECT_BUILTIN_PURE (shra_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp), 15749 DIRECT_BUILTIN_PURE (shra_r_ph, MIPS_V2HI_FTYPE_V2HI_SI, dsp), 15750 DIRECT_BUILTIN_PURE (shra_r_w, MIPS_SI_FTYPE_SI_SI, dsp), 15751 DIRECT_BUILTIN_PURE (muleu_s_ph_qbl, MIPS_V2HI_FTYPE_V4QI_V2HI, dsp), 15752 DIRECT_BUILTIN_PURE (muleu_s_ph_qbr, MIPS_V2HI_FTYPE_V4QI_V2HI, dsp), 15753 DIRECT_BUILTIN_PURE (mulq_rs_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15754 DIRECT_BUILTIN_PURE (muleq_s_w_phl, MIPS_SI_FTYPE_V2HI_V2HI, dsp), 15755 DIRECT_BUILTIN_PURE (muleq_s_w_phr, MIPS_SI_FTYPE_V2HI_V2HI, dsp), 15756 DIRECT_BUILTIN_PURE (bitrev, MIPS_SI_FTYPE_SI, dsp), 15757 DIRECT_BUILTIN_PURE (insv, MIPS_SI_FTYPE_SI_SI, dsp), 15758 DIRECT_BUILTIN_PURE (repl_qb, MIPS_V4QI_FTYPE_SI, dsp), 15759 DIRECT_BUILTIN_PURE (repl_ph, MIPS_V2HI_FTYPE_SI, dsp), 15760 DIRECT_NO_TARGET_BUILTIN (cmpu_eq_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp), 15761 DIRECT_NO_TARGET_BUILTIN (cmpu_lt_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp), 15762 DIRECT_NO_TARGET_BUILTIN (cmpu_le_qb, MIPS_VOID_FTYPE_V4QI_V4QI, dsp), 15763 DIRECT_BUILTIN_PURE (cmpgu_eq_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp), 15764 DIRECT_BUILTIN_PURE (cmpgu_lt_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp), 15765 DIRECT_BUILTIN_PURE (cmpgu_le_qb, MIPS_SI_FTYPE_V4QI_V4QI, dsp), 15766 DIRECT_NO_TARGET_BUILTIN (cmp_eq_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp), 15767 DIRECT_NO_TARGET_BUILTIN (cmp_lt_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp), 15768 DIRECT_NO_TARGET_BUILTIN (cmp_le_ph, MIPS_VOID_FTYPE_V2HI_V2HI, dsp), 15769 DIRECT_BUILTIN_PURE (pick_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dsp), 15770 DIRECT_BUILTIN_PURE (pick_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15771 DIRECT_BUILTIN_PURE (packrl_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dsp), 15772 DIRECT_NO_TARGET_BUILTIN (wrdsp, MIPS_VOID_FTYPE_SI_SI, dsp), 15773 DIRECT_BUILTIN_PURE (rddsp, MIPS_SI_FTYPE_SI, dsp), 15774 DIRECT_BUILTIN (lbux, MIPS_SI_FTYPE_POINTER_SI, dsp), 15775 DIRECT_BUILTIN (lhx, MIPS_SI_FTYPE_POINTER_SI, dsp), 15776 DIRECT_BUILTIN (lwx, MIPS_SI_FTYPE_POINTER_SI, dsp), 15777 BPOSGE_BUILTIN (32, dsp), 15778 15779 /* The following are for the MIPS DSP ASE REV 2 (32-bit and 64-bit). */ 15780 DIRECT_BUILTIN_PURE (absq_s_qb, MIPS_V4QI_FTYPE_V4QI, dspr2), 15781 DIRECT_BUILTIN_PURE (addu_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15782 DIRECT_BUILTIN_PURE (addu_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15783 DIRECT_BUILTIN_PURE (adduh_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2), 15784 DIRECT_BUILTIN_PURE (adduh_r_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2), 15785 DIRECT_BUILTIN_PURE (append, MIPS_SI_FTYPE_SI_SI_SI, dspr2), 15786 DIRECT_BUILTIN_PURE (balign, MIPS_SI_FTYPE_SI_SI_SI, dspr2), 15787 DIRECT_BUILTIN_PURE (cmpgdu_eq_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2), 15788 DIRECT_BUILTIN_PURE (cmpgdu_lt_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2), 15789 DIRECT_BUILTIN_PURE (cmpgdu_le_qb, MIPS_SI_FTYPE_V4QI_V4QI, dspr2), 15790 DIRECT_BUILTIN_PURE (mul_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15791 DIRECT_BUILTIN_PURE (mul_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15792 DIRECT_BUILTIN_PURE (mulq_rs_w, MIPS_SI_FTYPE_SI_SI, dspr2), 15793 DIRECT_BUILTIN_PURE (mulq_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15794 DIRECT_BUILTIN_PURE (mulq_s_w, MIPS_SI_FTYPE_SI_SI, dspr2), 15795 DIRECT_BUILTIN_PURE (precr_qb_ph, MIPS_V4QI_FTYPE_V2HI_V2HI, dspr2), 15796 DIRECT_BUILTIN_PURE (precr_sra_ph_w, MIPS_V2HI_FTYPE_SI_SI_SI, dspr2), 15797 DIRECT_BUILTIN_PURE (precr_sra_r_ph_w, MIPS_V2HI_FTYPE_SI_SI_SI, dspr2), 15798 DIRECT_BUILTIN_PURE (prepend, MIPS_SI_FTYPE_SI_SI_SI, dspr2), 15799 DIRECT_BUILTIN_PURE (shra_qb, MIPS_V4QI_FTYPE_V4QI_SI, dspr2), 15800 DIRECT_BUILTIN_PURE (shra_r_qb, MIPS_V4QI_FTYPE_V4QI_SI, dspr2), 15801 DIRECT_BUILTIN_PURE (shrl_ph, MIPS_V2HI_FTYPE_V2HI_SI, dspr2), 15802 DIRECT_BUILTIN_PURE (subu_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15803 DIRECT_BUILTIN_PURE (subu_s_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15804 DIRECT_BUILTIN_PURE (subuh_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2), 15805 DIRECT_BUILTIN_PURE (subuh_r_qb, MIPS_V4QI_FTYPE_V4QI_V4QI, dspr2), 15806 DIRECT_BUILTIN_PURE (addqh_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15807 DIRECT_BUILTIN_PURE (addqh_r_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15808 DIRECT_BUILTIN_PURE (addqh_w, MIPS_SI_FTYPE_SI_SI, dspr2), 15809 DIRECT_BUILTIN_PURE (addqh_r_w, MIPS_SI_FTYPE_SI_SI, dspr2), 15810 DIRECT_BUILTIN_PURE (subqh_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15811 DIRECT_BUILTIN_PURE (subqh_r_ph, MIPS_V2HI_FTYPE_V2HI_V2HI, dspr2), 15812 DIRECT_BUILTIN_PURE (subqh_w, MIPS_SI_FTYPE_SI_SI, dspr2), 15813 DIRECT_BUILTIN_PURE (subqh_r_w, MIPS_SI_FTYPE_SI_SI, dspr2), 15814 15815 /* Built-in functions for the DSP ASE (32-bit only). */ 15816 DIRECT_BUILTIN_PURE (dpau_h_qbl, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32), 15817 DIRECT_BUILTIN_PURE (dpau_h_qbr, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32), 15818 DIRECT_BUILTIN_PURE (dpsu_h_qbl, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32), 15819 DIRECT_BUILTIN_PURE (dpsu_h_qbr, MIPS_DI_FTYPE_DI_V4QI_V4QI, dsp_32), 15820 DIRECT_BUILTIN_PURE (dpaq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15821 DIRECT_BUILTIN_PURE (dpsq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15822 DIRECT_BUILTIN_PURE (mulsaq_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15823 DIRECT_BUILTIN_PURE (dpaq_sa_l_w, MIPS_DI_FTYPE_DI_SI_SI, dsp_32), 15824 DIRECT_BUILTIN_PURE (dpsq_sa_l_w, MIPS_DI_FTYPE_DI_SI_SI, dsp_32), 15825 DIRECT_BUILTIN_PURE (maq_s_w_phl, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15826 DIRECT_BUILTIN_PURE (maq_s_w_phr, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15827 DIRECT_BUILTIN_PURE (maq_sa_w_phl, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15828 DIRECT_BUILTIN_PURE (maq_sa_w_phr, MIPS_DI_FTYPE_DI_V2HI_V2HI, dsp_32), 15829 DIRECT_BUILTIN_PURE (extr_w, MIPS_SI_FTYPE_DI_SI, dsp_32), 15830 DIRECT_BUILTIN_PURE (extr_r_w, MIPS_SI_FTYPE_DI_SI, dsp_32), 15831 DIRECT_BUILTIN_PURE (extr_rs_w, MIPS_SI_FTYPE_DI_SI, dsp_32), 15832 DIRECT_BUILTIN_PURE (extr_s_h, MIPS_SI_FTYPE_DI_SI, dsp_32), 15833 DIRECT_BUILTIN_PURE (extp, MIPS_SI_FTYPE_DI_SI, dsp_32), 15834 DIRECT_BUILTIN_PURE (extpdp, MIPS_SI_FTYPE_DI_SI, dsp_32), 15835 DIRECT_BUILTIN_PURE (shilo, MIPS_DI_FTYPE_DI_SI, dsp_32), 15836 DIRECT_BUILTIN_PURE (mthlip, MIPS_DI_FTYPE_DI_SI, dsp_32), 15837 DIRECT_BUILTIN_PURE (madd, MIPS_DI_FTYPE_DI_SI_SI, dsp_32), 15838 DIRECT_BUILTIN_PURE (maddu, MIPS_DI_FTYPE_DI_USI_USI, dsp_32), 15839 DIRECT_BUILTIN_PURE (msub, MIPS_DI_FTYPE_DI_SI_SI, dsp_32), 15840 DIRECT_BUILTIN_PURE (msubu, MIPS_DI_FTYPE_DI_USI_USI, dsp_32), 15841 DIRECT_BUILTIN_PURE (mult, MIPS_DI_FTYPE_SI_SI, dsp_32), 15842 DIRECT_BUILTIN_PURE (multu, MIPS_DI_FTYPE_USI_USI, dsp_32), 15843 15844 /* Built-in functions for the DSP ASE (64-bit only). */ 15845 DIRECT_BUILTIN (ldx, MIPS_DI_FTYPE_POINTER_SI, dsp_64), 15846 15847 /* The following are for the MIPS DSP ASE REV 2 (32-bit only). */ 15848 DIRECT_BUILTIN_PURE (dpa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15849 DIRECT_BUILTIN_PURE (dps_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15850 DIRECT_BUILTIN_PURE (mulsa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15851 DIRECT_BUILTIN_PURE (dpax_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15852 DIRECT_BUILTIN_PURE (dpsx_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15853 DIRECT_BUILTIN_PURE (dpaqx_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15854 DIRECT_BUILTIN_PURE (dpaqx_sa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15855 DIRECT_BUILTIN_PURE (dpsqx_s_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15856 DIRECT_BUILTIN_PURE (dpsqx_sa_w_ph, MIPS_DI_FTYPE_DI_V2HI_V2HI, dspr2_32), 15857 15858 /* Builtin functions for ST Microelectronics Loongson-2E/2F cores. */ 15859 LOONGSON_BUILTIN (packsswh, MIPS_V4HI_FTYPE_V2SI_V2SI), 15860 LOONGSON_BUILTIN (packsshb, MIPS_V8QI_FTYPE_V4HI_V4HI), 15861 LOONGSON_BUILTIN (packushb, MIPS_UV8QI_FTYPE_UV4HI_UV4HI), 15862 LOONGSON_BUILTIN_SUFFIX (paddw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15863 LOONGSON_BUILTIN_SUFFIX (paddh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15864 LOONGSON_BUILTIN_SUFFIX (paddb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15865 LOONGSON_BUILTIN_SUFFIX (paddw, s, MIPS_V2SI_FTYPE_V2SI_V2SI), 15866 LOONGSON_BUILTIN_SUFFIX (paddh, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15867 LOONGSON_BUILTIN_SUFFIX (paddb, s, MIPS_V8QI_FTYPE_V8QI_V8QI), 15868 LOONGSON_BUILTIN_SUFFIX (paddd, u, MIPS_UDI_FTYPE_UDI_UDI), 15869 LOONGSON_BUILTIN_SUFFIX (paddd, s, MIPS_DI_FTYPE_DI_DI), 15870 LOONGSON_BUILTIN (paddsh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15871 LOONGSON_BUILTIN (paddsb, MIPS_V8QI_FTYPE_V8QI_V8QI), 15872 LOONGSON_BUILTIN (paddush, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15873 LOONGSON_BUILTIN (paddusb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15874 LOONGSON_BUILTIN_ALIAS (pandn_d, pandn_ud, MIPS_UDI_FTYPE_UDI_UDI), 15875 LOONGSON_BUILTIN_ALIAS (pandn_w, pandn_uw, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15876 LOONGSON_BUILTIN_ALIAS (pandn_h, pandn_uh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15877 LOONGSON_BUILTIN_ALIAS (pandn_b, pandn_ub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15878 LOONGSON_BUILTIN_ALIAS (pandn_d, pandn_sd, MIPS_DI_FTYPE_DI_DI), 15879 LOONGSON_BUILTIN_ALIAS (pandn_w, pandn_sw, MIPS_V2SI_FTYPE_V2SI_V2SI), 15880 LOONGSON_BUILTIN_ALIAS (pandn_h, pandn_sh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15881 LOONGSON_BUILTIN_ALIAS (pandn_b, pandn_sb, MIPS_V8QI_FTYPE_V8QI_V8QI), 15882 LOONGSON_BUILTIN (pavgh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15883 LOONGSON_BUILTIN (pavgb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15884 LOONGSON_BUILTIN_SUFFIX (pcmpeqw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15885 LOONGSON_BUILTIN_SUFFIX (pcmpeqh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15886 LOONGSON_BUILTIN_SUFFIX (pcmpeqb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15887 LOONGSON_BUILTIN_SUFFIX (pcmpeqw, s, MIPS_V2SI_FTYPE_V2SI_V2SI), 15888 LOONGSON_BUILTIN_SUFFIX (pcmpeqh, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15889 LOONGSON_BUILTIN_SUFFIX (pcmpeqb, s, MIPS_V8QI_FTYPE_V8QI_V8QI), 15890 LOONGSON_BUILTIN_SUFFIX (pcmpgtw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15891 LOONGSON_BUILTIN_SUFFIX (pcmpgth, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15892 LOONGSON_BUILTIN_SUFFIX (pcmpgtb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15893 LOONGSON_BUILTIN_SUFFIX (pcmpgtw, s, MIPS_V2SI_FTYPE_V2SI_V2SI), 15894 LOONGSON_BUILTIN_SUFFIX (pcmpgth, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15895 LOONGSON_BUILTIN_SUFFIX (pcmpgtb, s, MIPS_V8QI_FTYPE_V8QI_V8QI), 15896 LOONGSON_BUILTIN_SUFFIX (pextrh, u, MIPS_UV4HI_FTYPE_UV4HI_USI), 15897 LOONGSON_BUILTIN_SUFFIX (pextrh, s, MIPS_V4HI_FTYPE_V4HI_USI), 15898 LOONGSON_BUILTIN_SUFFIX (pinsrh_0, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15899 LOONGSON_BUILTIN_SUFFIX (pinsrh_1, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15900 LOONGSON_BUILTIN_SUFFIX (pinsrh_2, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15901 LOONGSON_BUILTIN_SUFFIX (pinsrh_3, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15902 LOONGSON_BUILTIN_SUFFIX (pinsrh_0, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15903 LOONGSON_BUILTIN_SUFFIX (pinsrh_1, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15904 LOONGSON_BUILTIN_SUFFIX (pinsrh_2, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15905 LOONGSON_BUILTIN_SUFFIX (pinsrh_3, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15906 LOONGSON_BUILTIN (pmaddhw, MIPS_V2SI_FTYPE_V4HI_V4HI), 15907 LOONGSON_BUILTIN (pmaxsh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15908 LOONGSON_BUILTIN (pmaxub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15909 LOONGSON_BUILTIN (pminsh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15910 LOONGSON_BUILTIN (pminub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15911 LOONGSON_BUILTIN_SUFFIX (pmovmskb, u, MIPS_UV8QI_FTYPE_UV8QI), 15912 LOONGSON_BUILTIN_SUFFIX (pmovmskb, s, MIPS_V8QI_FTYPE_V8QI), 15913 LOONGSON_BUILTIN (pmulhuh, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15914 LOONGSON_BUILTIN (pmulhh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15915 LOONGSON_BUILTIN (pmullh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15916 LOONGSON_BUILTIN (pmuluw, MIPS_UDI_FTYPE_UV2SI_UV2SI), 15917 LOONGSON_BUILTIN (pasubub, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15918 LOONGSON_BUILTIN (biadd, MIPS_UV4HI_FTYPE_UV8QI), 15919 LOONGSON_BUILTIN (psadbh, MIPS_UV4HI_FTYPE_UV8QI_UV8QI), 15920 LOONGSON_BUILTIN_SUFFIX (pshufh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI), 15921 LOONGSON_BUILTIN_SUFFIX (pshufh, s, MIPS_V4HI_FTYPE_V4HI_UQI), 15922 LOONGSON_BUILTIN_SUFFIX (psllh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI), 15923 LOONGSON_BUILTIN_SUFFIX (psllh, s, MIPS_V4HI_FTYPE_V4HI_UQI), 15924 LOONGSON_BUILTIN_SUFFIX (psllw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI), 15925 LOONGSON_BUILTIN_SUFFIX (psllw, s, MIPS_V2SI_FTYPE_V2SI_UQI), 15926 LOONGSON_BUILTIN_SUFFIX (psrah, u, MIPS_UV4HI_FTYPE_UV4HI_UQI), 15927 LOONGSON_BUILTIN_SUFFIX (psrah, s, MIPS_V4HI_FTYPE_V4HI_UQI), 15928 LOONGSON_BUILTIN_SUFFIX (psraw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI), 15929 LOONGSON_BUILTIN_SUFFIX (psraw, s, MIPS_V2SI_FTYPE_V2SI_UQI), 15930 LOONGSON_BUILTIN_SUFFIX (psrlh, u, MIPS_UV4HI_FTYPE_UV4HI_UQI), 15931 LOONGSON_BUILTIN_SUFFIX (psrlh, s, MIPS_V4HI_FTYPE_V4HI_UQI), 15932 LOONGSON_BUILTIN_SUFFIX (psrlw, u, MIPS_UV2SI_FTYPE_UV2SI_UQI), 15933 LOONGSON_BUILTIN_SUFFIX (psrlw, s, MIPS_V2SI_FTYPE_V2SI_UQI), 15934 LOONGSON_BUILTIN_SUFFIX (psubw, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15935 LOONGSON_BUILTIN_SUFFIX (psubh, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15936 LOONGSON_BUILTIN_SUFFIX (psubb, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15937 LOONGSON_BUILTIN_SUFFIX (psubw, s, MIPS_V2SI_FTYPE_V2SI_V2SI), 15938 LOONGSON_BUILTIN_SUFFIX (psubh, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15939 LOONGSON_BUILTIN_SUFFIX (psubb, s, MIPS_V8QI_FTYPE_V8QI_V8QI), 15940 LOONGSON_BUILTIN_SUFFIX (psubd, u, MIPS_UDI_FTYPE_UDI_UDI), 15941 LOONGSON_BUILTIN_SUFFIX (psubd, s, MIPS_DI_FTYPE_DI_DI), 15942 LOONGSON_BUILTIN (psubsh, MIPS_V4HI_FTYPE_V4HI_V4HI), 15943 LOONGSON_BUILTIN (psubsb, MIPS_V8QI_FTYPE_V8QI_V8QI), 15944 LOONGSON_BUILTIN (psubush, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15945 LOONGSON_BUILTIN (psubusb, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15946 LOONGSON_BUILTIN_SUFFIX (punpckhbh, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15947 LOONGSON_BUILTIN_SUFFIX (punpckhhw, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15948 LOONGSON_BUILTIN_SUFFIX (punpckhwd, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15949 LOONGSON_BUILTIN_SUFFIX (punpckhbh, s, MIPS_V8QI_FTYPE_V8QI_V8QI), 15950 LOONGSON_BUILTIN_SUFFIX (punpckhhw, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15951 LOONGSON_BUILTIN_SUFFIX (punpckhwd, s, MIPS_V2SI_FTYPE_V2SI_V2SI), 15952 LOONGSON_BUILTIN_SUFFIX (punpcklbh, u, MIPS_UV8QI_FTYPE_UV8QI_UV8QI), 15953 LOONGSON_BUILTIN_SUFFIX (punpcklhw, u, MIPS_UV4HI_FTYPE_UV4HI_UV4HI), 15954 LOONGSON_BUILTIN_SUFFIX (punpcklwd, u, MIPS_UV2SI_FTYPE_UV2SI_UV2SI), 15955 LOONGSON_BUILTIN_SUFFIX (punpcklbh, s, MIPS_V8QI_FTYPE_V8QI_V8QI), 15956 LOONGSON_BUILTIN_SUFFIX (punpcklhw, s, MIPS_V4HI_FTYPE_V4HI_V4HI), 15957 LOONGSON_BUILTIN_SUFFIX (punpcklwd, s, MIPS_V2SI_FTYPE_V2SI_V2SI), 15958 15959 /* Sundry other built-in functions. */ 15960 DIRECT_NO_TARGET_BUILTIN (cache, MIPS_VOID_FTYPE_SI_CVPOINTER, cache), 15961 15962 /* Built-in functions for MSA. */ 15963 MSA_BUILTIN_PURE (sll_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 15964 MSA_BUILTIN_PURE (sll_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 15965 MSA_BUILTIN_PURE (sll_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 15966 MSA_BUILTIN_PURE (sll_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 15967 MSA_BUILTIN_PURE (slli_b, MIPS_V16QI_FTYPE_V16QI_UQI), 15968 MSA_BUILTIN_PURE (slli_h, MIPS_V8HI_FTYPE_V8HI_UQI), 15969 MSA_BUILTIN_PURE (slli_w, MIPS_V4SI_FTYPE_V4SI_UQI), 15970 MSA_BUILTIN_PURE (slli_d, MIPS_V2DI_FTYPE_V2DI_UQI), 15971 MSA_BUILTIN_PURE (sra_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 15972 MSA_BUILTIN_PURE (sra_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 15973 MSA_BUILTIN_PURE (sra_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 15974 MSA_BUILTIN_PURE (sra_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 15975 MSA_BUILTIN_PURE (srai_b, MIPS_V16QI_FTYPE_V16QI_UQI), 15976 MSA_BUILTIN_PURE (srai_h, MIPS_V8HI_FTYPE_V8HI_UQI), 15977 MSA_BUILTIN_PURE (srai_w, MIPS_V4SI_FTYPE_V4SI_UQI), 15978 MSA_BUILTIN_PURE (srai_d, MIPS_V2DI_FTYPE_V2DI_UQI), 15979 MSA_BUILTIN_PURE (srar_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 15980 MSA_BUILTIN_PURE (srar_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 15981 MSA_BUILTIN_PURE (srar_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 15982 MSA_BUILTIN_PURE (srar_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 15983 MSA_BUILTIN_PURE (srari_b, MIPS_V16QI_FTYPE_V16QI_UQI), 15984 MSA_BUILTIN_PURE (srari_h, MIPS_V8HI_FTYPE_V8HI_UQI), 15985 MSA_BUILTIN_PURE (srari_w, MIPS_V4SI_FTYPE_V4SI_UQI), 15986 MSA_BUILTIN_PURE (srari_d, MIPS_V2DI_FTYPE_V2DI_UQI), 15987 MSA_BUILTIN_PURE (srl_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 15988 MSA_BUILTIN_PURE (srl_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 15989 MSA_BUILTIN_PURE (srl_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 15990 MSA_BUILTIN_PURE (srl_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 15991 MSA_BUILTIN_PURE (srli_b, MIPS_V16QI_FTYPE_V16QI_UQI), 15992 MSA_BUILTIN_PURE (srli_h, MIPS_V8HI_FTYPE_V8HI_UQI), 15993 MSA_BUILTIN_PURE (srli_w, MIPS_V4SI_FTYPE_V4SI_UQI), 15994 MSA_BUILTIN_PURE (srli_d, MIPS_V2DI_FTYPE_V2DI_UQI), 15995 MSA_BUILTIN_PURE (srlr_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 15996 MSA_BUILTIN_PURE (srlr_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 15997 MSA_BUILTIN_PURE (srlr_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 15998 MSA_BUILTIN_PURE (srlr_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 15999 MSA_BUILTIN_PURE (srlri_b, MIPS_V16QI_FTYPE_V16QI_UQI), 16000 MSA_BUILTIN_PURE (srlri_h, MIPS_V8HI_FTYPE_V8HI_UQI), 16001 MSA_BUILTIN_PURE (srlri_w, MIPS_V4SI_FTYPE_V4SI_UQI), 16002 MSA_BUILTIN_PURE (srlri_d, MIPS_V2DI_FTYPE_V2DI_UQI), 16003 MSA_BUILTIN_PURE (bclr_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16004 MSA_BUILTIN_PURE (bclr_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16005 MSA_BUILTIN_PURE (bclr_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16006 MSA_BUILTIN_PURE (bclr_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16007 MSA_BUILTIN_PURE (bclri_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16008 MSA_BUILTIN_PURE (bclri_h, MIPS_UV8HI_FTYPE_UV8HI_UQI), 16009 MSA_BUILTIN_PURE (bclri_w, MIPS_UV4SI_FTYPE_UV4SI_UQI), 16010 MSA_BUILTIN_PURE (bclri_d, MIPS_UV2DI_FTYPE_UV2DI_UQI), 16011 MSA_BUILTIN_PURE (bset_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16012 MSA_BUILTIN_PURE (bset_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16013 MSA_BUILTIN_PURE (bset_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16014 MSA_BUILTIN_PURE (bset_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16015 MSA_BUILTIN_PURE (bseti_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16016 MSA_BUILTIN_PURE (bseti_h, MIPS_UV8HI_FTYPE_UV8HI_UQI), 16017 MSA_BUILTIN_PURE (bseti_w, MIPS_UV4SI_FTYPE_UV4SI_UQI), 16018 MSA_BUILTIN_PURE (bseti_d, MIPS_UV2DI_FTYPE_UV2DI_UQI), 16019 MSA_BUILTIN_PURE (bneg_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16020 MSA_BUILTIN_PURE (bneg_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16021 MSA_BUILTIN_PURE (bneg_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16022 MSA_BUILTIN_PURE (bneg_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16023 MSA_BUILTIN_PURE (bnegi_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16024 MSA_BUILTIN_PURE (bnegi_h, MIPS_UV8HI_FTYPE_UV8HI_UQI), 16025 MSA_BUILTIN_PURE (bnegi_w, MIPS_UV4SI_FTYPE_UV4SI_UQI), 16026 MSA_BUILTIN_PURE (bnegi_d, MIPS_UV2DI_FTYPE_UV2DI_UQI), 16027 MSA_BUILTIN_PURE (binsl_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI), 16028 MSA_BUILTIN_PURE (binsl_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UV8HI), 16029 MSA_BUILTIN_PURE (binsl_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UV4SI), 16030 MSA_BUILTIN_PURE (binsl_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UV2DI), 16031 MSA_BUILTIN_PURE (binsli_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI), 16032 MSA_BUILTIN_PURE (binsli_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UQI), 16033 MSA_BUILTIN_PURE (binsli_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UQI), 16034 MSA_BUILTIN_PURE (binsli_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UQI), 16035 MSA_BUILTIN_PURE (binsr_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI), 16036 MSA_BUILTIN_PURE (binsr_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UV8HI), 16037 MSA_BUILTIN_PURE (binsr_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UV4SI), 16038 MSA_BUILTIN_PURE (binsr_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UV2DI), 16039 MSA_BUILTIN_PURE (binsri_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI), 16040 MSA_BUILTIN_PURE (binsri_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI_UQI), 16041 MSA_BUILTIN_PURE (binsri_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI_UQI), 16042 MSA_BUILTIN_PURE (binsri_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI_UQI), 16043 MSA_BUILTIN_PURE (addv_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16044 MSA_BUILTIN_PURE (addv_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16045 MSA_BUILTIN_PURE (addv_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16046 MSA_BUILTIN_PURE (addv_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16047 MSA_BUILTIN_PURE (addvi_b, MIPS_V16QI_FTYPE_V16QI_UQI), 16048 MSA_BUILTIN_PURE (addvi_h, MIPS_V8HI_FTYPE_V8HI_UQI), 16049 MSA_BUILTIN_PURE (addvi_w, MIPS_V4SI_FTYPE_V4SI_UQI), 16050 MSA_BUILTIN_PURE (addvi_d, MIPS_V2DI_FTYPE_V2DI_UQI), 16051 MSA_BUILTIN_PURE (subv_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16052 MSA_BUILTIN_PURE (subv_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16053 MSA_BUILTIN_PURE (subv_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16054 MSA_BUILTIN_PURE (subv_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16055 MSA_BUILTIN_PURE (subvi_b, MIPS_V16QI_FTYPE_V16QI_UQI), 16056 MSA_BUILTIN_PURE (subvi_h, MIPS_V8HI_FTYPE_V8HI_UQI), 16057 MSA_BUILTIN_PURE (subvi_w, MIPS_V4SI_FTYPE_V4SI_UQI), 16058 MSA_BUILTIN_PURE (subvi_d, MIPS_V2DI_FTYPE_V2DI_UQI), 16059 MSA_BUILTIN_PURE (max_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16060 MSA_BUILTIN_PURE (max_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16061 MSA_BUILTIN_PURE (max_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16062 MSA_BUILTIN_PURE (max_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16063 MSA_BUILTIN_PURE (maxi_s_b, MIPS_V16QI_FTYPE_V16QI_QI), 16064 MSA_BUILTIN_PURE (maxi_s_h, MIPS_V8HI_FTYPE_V8HI_QI), 16065 MSA_BUILTIN_PURE (maxi_s_w, MIPS_V4SI_FTYPE_V4SI_QI), 16066 MSA_BUILTIN_PURE (maxi_s_d, MIPS_V2DI_FTYPE_V2DI_QI), 16067 MSA_BUILTIN_PURE (max_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16068 MSA_BUILTIN_PURE (max_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16069 MSA_BUILTIN_PURE (max_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16070 MSA_BUILTIN_PURE (max_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16071 MSA_BUILTIN_PURE (maxi_u_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16072 MSA_BUILTIN_PURE (maxi_u_h, MIPS_UV8HI_FTYPE_UV8HI_UQI), 16073 MSA_BUILTIN_PURE (maxi_u_w, MIPS_UV4SI_FTYPE_UV4SI_UQI), 16074 MSA_BUILTIN_PURE (maxi_u_d, MIPS_UV2DI_FTYPE_UV2DI_UQI), 16075 MSA_BUILTIN_PURE (min_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16076 MSA_BUILTIN_PURE (min_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16077 MSA_BUILTIN_PURE (min_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16078 MSA_BUILTIN_PURE (min_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16079 MSA_BUILTIN_PURE (mini_s_b, MIPS_V16QI_FTYPE_V16QI_QI), 16080 MSA_BUILTIN_PURE (mini_s_h, MIPS_V8HI_FTYPE_V8HI_QI), 16081 MSA_BUILTIN_PURE (mini_s_w, MIPS_V4SI_FTYPE_V4SI_QI), 16082 MSA_BUILTIN_PURE (mini_s_d, MIPS_V2DI_FTYPE_V2DI_QI), 16083 MSA_BUILTIN_PURE (min_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16084 MSA_BUILTIN_PURE (min_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16085 MSA_BUILTIN_PURE (min_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16086 MSA_BUILTIN_PURE (min_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16087 MSA_BUILTIN_PURE (mini_u_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16088 MSA_BUILTIN_PURE (mini_u_h, MIPS_UV8HI_FTYPE_UV8HI_UQI), 16089 MSA_BUILTIN_PURE (mini_u_w, MIPS_UV4SI_FTYPE_UV4SI_UQI), 16090 MSA_BUILTIN_PURE (mini_u_d, MIPS_UV2DI_FTYPE_UV2DI_UQI), 16091 MSA_BUILTIN_PURE (max_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16092 MSA_BUILTIN_PURE (max_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16093 MSA_BUILTIN_PURE (max_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16094 MSA_BUILTIN_PURE (max_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16095 MSA_BUILTIN_PURE (min_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16096 MSA_BUILTIN_PURE (min_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16097 MSA_BUILTIN_PURE (min_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16098 MSA_BUILTIN_PURE (min_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16099 MSA_BUILTIN (ceq_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16100 MSA_BUILTIN (ceq_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16101 MSA_BUILTIN (ceq_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16102 MSA_BUILTIN (ceq_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16103 MSA_BUILTIN (ceqi_b, MIPS_V16QI_FTYPE_V16QI_QI), 16104 MSA_BUILTIN (ceqi_h, MIPS_V8HI_FTYPE_V8HI_QI), 16105 MSA_BUILTIN (ceqi_w, MIPS_V4SI_FTYPE_V4SI_QI), 16106 MSA_BUILTIN (ceqi_d, MIPS_V2DI_FTYPE_V2DI_QI), 16107 MSA_BUILTIN (clt_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16108 MSA_BUILTIN (clt_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16109 MSA_BUILTIN (clt_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16110 MSA_BUILTIN (clt_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16111 MSA_BUILTIN (clti_s_b, MIPS_V16QI_FTYPE_V16QI_QI), 16112 MSA_BUILTIN (clti_s_h, MIPS_V8HI_FTYPE_V8HI_QI), 16113 MSA_BUILTIN (clti_s_w, MIPS_V4SI_FTYPE_V4SI_QI), 16114 MSA_BUILTIN (clti_s_d, MIPS_V2DI_FTYPE_V2DI_QI), 16115 MSA_BUILTIN (clt_u_b, MIPS_V16QI_FTYPE_UV16QI_UV16QI), 16116 MSA_BUILTIN (clt_u_h, MIPS_V8HI_FTYPE_UV8HI_UV8HI), 16117 MSA_BUILTIN (clt_u_w, MIPS_V4SI_FTYPE_UV4SI_UV4SI), 16118 MSA_BUILTIN (clt_u_d, MIPS_V2DI_FTYPE_UV2DI_UV2DI), 16119 MSA_BUILTIN (clti_u_b, MIPS_V16QI_FTYPE_UV16QI_UQI), 16120 MSA_BUILTIN (clti_u_h, MIPS_V8HI_FTYPE_UV8HI_UQI), 16121 MSA_BUILTIN (clti_u_w, MIPS_V4SI_FTYPE_UV4SI_UQI), 16122 MSA_BUILTIN (clti_u_d, MIPS_V2DI_FTYPE_UV2DI_UQI), 16123 MSA_BUILTIN (cle_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16124 MSA_BUILTIN (cle_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16125 MSA_BUILTIN (cle_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16126 MSA_BUILTIN (cle_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16127 MSA_BUILTIN (clei_s_b, MIPS_V16QI_FTYPE_V16QI_QI), 16128 MSA_BUILTIN (clei_s_h, MIPS_V8HI_FTYPE_V8HI_QI), 16129 MSA_BUILTIN (clei_s_w, MIPS_V4SI_FTYPE_V4SI_QI), 16130 MSA_BUILTIN (clei_s_d, MIPS_V2DI_FTYPE_V2DI_QI), 16131 MSA_BUILTIN (cle_u_b, MIPS_V16QI_FTYPE_UV16QI_UV16QI), 16132 MSA_BUILTIN (cle_u_h, MIPS_V8HI_FTYPE_UV8HI_UV8HI), 16133 MSA_BUILTIN (cle_u_w, MIPS_V4SI_FTYPE_UV4SI_UV4SI), 16134 MSA_BUILTIN (cle_u_d, MIPS_V2DI_FTYPE_UV2DI_UV2DI), 16135 MSA_BUILTIN (clei_u_b, MIPS_V16QI_FTYPE_UV16QI_UQI), 16136 MSA_BUILTIN (clei_u_h, MIPS_V8HI_FTYPE_UV8HI_UQI), 16137 MSA_BUILTIN (clei_u_w, MIPS_V4SI_FTYPE_UV4SI_UQI), 16138 MSA_BUILTIN (clei_u_d, MIPS_V2DI_FTYPE_UV2DI_UQI), 16139 MSA_BUILTIN (ld_b, MIPS_V16QI_FTYPE_CVPOINTER_SI), 16140 MSA_BUILTIN (ld_h, MIPS_V8HI_FTYPE_CVPOINTER_SI), 16141 MSA_BUILTIN (ld_w, MIPS_V4SI_FTYPE_CVPOINTER_SI), 16142 MSA_BUILTIN (ld_d, MIPS_V2DI_FTYPE_CVPOINTER_SI), 16143 MSA_NO_TARGET_BUILTIN (st_b, MIPS_VOID_FTYPE_V16QI_CVPOINTER_SI), 16144 MSA_NO_TARGET_BUILTIN (st_h, MIPS_VOID_FTYPE_V8HI_CVPOINTER_SI), 16145 MSA_NO_TARGET_BUILTIN (st_w, MIPS_VOID_FTYPE_V4SI_CVPOINTER_SI), 16146 MSA_NO_TARGET_BUILTIN (st_d, MIPS_VOID_FTYPE_V2DI_CVPOINTER_SI), 16147 MSA_BUILTIN_PURE (sat_s_b, MIPS_V16QI_FTYPE_V16QI_UQI), 16148 MSA_BUILTIN_PURE (sat_s_h, MIPS_V8HI_FTYPE_V8HI_UQI), 16149 MSA_BUILTIN_PURE (sat_s_w, MIPS_V4SI_FTYPE_V4SI_UQI), 16150 MSA_BUILTIN_PURE (sat_s_d, MIPS_V2DI_FTYPE_V2DI_UQI), 16151 MSA_BUILTIN_PURE (sat_u_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16152 MSA_BUILTIN_PURE (sat_u_h, MIPS_UV8HI_FTYPE_UV8HI_UQI), 16153 MSA_BUILTIN_PURE (sat_u_w, MIPS_UV4SI_FTYPE_UV4SI_UQI), 16154 MSA_BUILTIN_PURE (sat_u_d, MIPS_UV2DI_FTYPE_UV2DI_UQI), 16155 MSA_BUILTIN_PURE (add_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16156 MSA_BUILTIN_PURE (add_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16157 MSA_BUILTIN_PURE (add_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16158 MSA_BUILTIN_PURE (add_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16159 MSA_BUILTIN_PURE (adds_a_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16160 MSA_BUILTIN_PURE (adds_a_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16161 MSA_BUILTIN_PURE (adds_a_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16162 MSA_BUILTIN_PURE (adds_a_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16163 MSA_BUILTIN_PURE (adds_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16164 MSA_BUILTIN_PURE (adds_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16165 MSA_BUILTIN_PURE (adds_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16166 MSA_BUILTIN_PURE (adds_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16167 MSA_BUILTIN_PURE (adds_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16168 MSA_BUILTIN_PURE (adds_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16169 MSA_BUILTIN_PURE (adds_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16170 MSA_BUILTIN_PURE (adds_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16171 MSA_BUILTIN_PURE (ave_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16172 MSA_BUILTIN_PURE (ave_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16173 MSA_BUILTIN_PURE (ave_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16174 MSA_BUILTIN_PURE (ave_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16175 MSA_BUILTIN_PURE (ave_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16176 MSA_BUILTIN_PURE (ave_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16177 MSA_BUILTIN_PURE (ave_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16178 MSA_BUILTIN_PURE (ave_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16179 MSA_BUILTIN_PURE (aver_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16180 MSA_BUILTIN_PURE (aver_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16181 MSA_BUILTIN_PURE (aver_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16182 MSA_BUILTIN_PURE (aver_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16183 MSA_BUILTIN_PURE (aver_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16184 MSA_BUILTIN_PURE (aver_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16185 MSA_BUILTIN_PURE (aver_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16186 MSA_BUILTIN_PURE (aver_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16187 MSA_BUILTIN_PURE (subs_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16188 MSA_BUILTIN_PURE (subs_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16189 MSA_BUILTIN_PURE (subs_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16190 MSA_BUILTIN_PURE (subs_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16191 MSA_BUILTIN_PURE (subs_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16192 MSA_BUILTIN_PURE (subs_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16193 MSA_BUILTIN_PURE (subs_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16194 MSA_BUILTIN_PURE (subs_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16195 MSA_BUILTIN_PURE (subsuu_s_b, MIPS_V16QI_FTYPE_UV16QI_UV16QI), 16196 MSA_BUILTIN_PURE (subsuu_s_h, MIPS_V8HI_FTYPE_UV8HI_UV8HI), 16197 MSA_BUILTIN_PURE (subsuu_s_w, MIPS_V4SI_FTYPE_UV4SI_UV4SI), 16198 MSA_BUILTIN_PURE (subsuu_s_d, MIPS_V2DI_FTYPE_UV2DI_UV2DI), 16199 MSA_BUILTIN_PURE (subsus_u_b, MIPS_UV16QI_FTYPE_UV16QI_V16QI), 16200 MSA_BUILTIN_PURE (subsus_u_h, MIPS_UV8HI_FTYPE_UV8HI_V8HI), 16201 MSA_BUILTIN_PURE (subsus_u_w, MIPS_UV4SI_FTYPE_UV4SI_V4SI), 16202 MSA_BUILTIN_PURE (subsus_u_d, MIPS_UV2DI_FTYPE_UV2DI_V2DI), 16203 MSA_BUILTIN_PURE (asub_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16204 MSA_BUILTIN_PURE (asub_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16205 MSA_BUILTIN_PURE (asub_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16206 MSA_BUILTIN_PURE (asub_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16207 MSA_BUILTIN_PURE (asub_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16208 MSA_BUILTIN_PURE (asub_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16209 MSA_BUILTIN_PURE (asub_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16210 MSA_BUILTIN_PURE (asub_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16211 MSA_BUILTIN_PURE (mulv_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16212 MSA_BUILTIN_PURE (mulv_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16213 MSA_BUILTIN_PURE (mulv_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16214 MSA_BUILTIN_PURE (mulv_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16215 MSA_BUILTIN_PURE (maddv_b, MIPS_V16QI_FTYPE_V16QI_V16QI_V16QI), 16216 MSA_BUILTIN_PURE (maddv_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16217 MSA_BUILTIN_PURE (maddv_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16218 MSA_BUILTIN_PURE (maddv_d, MIPS_V2DI_FTYPE_V2DI_V2DI_V2DI), 16219 MSA_BUILTIN_PURE (msubv_b, MIPS_V16QI_FTYPE_V16QI_V16QI_V16QI), 16220 MSA_BUILTIN_PURE (msubv_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16221 MSA_BUILTIN_PURE (msubv_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16222 MSA_BUILTIN_PURE (msubv_d, MIPS_V2DI_FTYPE_V2DI_V2DI_V2DI), 16223 MSA_BUILTIN_PURE (div_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16224 MSA_BUILTIN_PURE (div_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16225 MSA_BUILTIN_PURE (div_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16226 MSA_BUILTIN_PURE (div_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16227 MSA_BUILTIN_PURE (div_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16228 MSA_BUILTIN_PURE (div_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16229 MSA_BUILTIN_PURE (div_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16230 MSA_BUILTIN_PURE (div_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16231 MSA_BUILTIN_PURE (hadd_s_h, MIPS_V8HI_FTYPE_V16QI_V16QI), 16232 MSA_BUILTIN_PURE (hadd_s_w, MIPS_V4SI_FTYPE_V8HI_V8HI), 16233 MSA_BUILTIN_PURE (hadd_s_d, MIPS_V2DI_FTYPE_V4SI_V4SI), 16234 MSA_BUILTIN_PURE (hadd_u_h, MIPS_UV8HI_FTYPE_UV16QI_UV16QI), 16235 MSA_BUILTIN_PURE (hadd_u_w, MIPS_UV4SI_FTYPE_UV8HI_UV8HI), 16236 MSA_BUILTIN_PURE (hadd_u_d, MIPS_UV2DI_FTYPE_UV4SI_UV4SI), 16237 MSA_BUILTIN_PURE (hsub_s_h, MIPS_V8HI_FTYPE_V16QI_V16QI), 16238 MSA_BUILTIN_PURE (hsub_s_w, MIPS_V4SI_FTYPE_V8HI_V8HI), 16239 MSA_BUILTIN_PURE (hsub_s_d, MIPS_V2DI_FTYPE_V4SI_V4SI), 16240 MSA_BUILTIN_PURE (hsub_u_h, MIPS_V8HI_FTYPE_UV16QI_UV16QI), 16241 MSA_BUILTIN_PURE (hsub_u_w, MIPS_V4SI_FTYPE_UV8HI_UV8HI), 16242 MSA_BUILTIN_PURE (hsub_u_d, MIPS_V2DI_FTYPE_UV4SI_UV4SI), 16243 MSA_BUILTIN_PURE (mod_s_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16244 MSA_BUILTIN_PURE (mod_s_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16245 MSA_BUILTIN_PURE (mod_s_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16246 MSA_BUILTIN_PURE (mod_s_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16247 MSA_BUILTIN_PURE (mod_u_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16248 MSA_BUILTIN_PURE (mod_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV8HI), 16249 MSA_BUILTIN_PURE (mod_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV4SI), 16250 MSA_BUILTIN_PURE (mod_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV2DI), 16251 MSA_BUILTIN_PURE (dotp_s_h, MIPS_V8HI_FTYPE_V16QI_V16QI), 16252 MSA_BUILTIN_PURE (dotp_s_w, MIPS_V4SI_FTYPE_V8HI_V8HI), 16253 MSA_BUILTIN_PURE (dotp_s_d, MIPS_V2DI_FTYPE_V4SI_V4SI), 16254 MSA_BUILTIN_PURE (dotp_u_h, MIPS_UV8HI_FTYPE_UV16QI_UV16QI), 16255 MSA_BUILTIN_PURE (dotp_u_w, MIPS_UV4SI_FTYPE_UV8HI_UV8HI), 16256 MSA_BUILTIN_PURE (dotp_u_d, MIPS_UV2DI_FTYPE_UV4SI_UV4SI), 16257 MSA_BUILTIN_PURE (dpadd_s_h, MIPS_V8HI_FTYPE_V8HI_V16QI_V16QI), 16258 MSA_BUILTIN_PURE (dpadd_s_w, MIPS_V4SI_FTYPE_V4SI_V8HI_V8HI), 16259 MSA_BUILTIN_PURE (dpadd_s_d, MIPS_V2DI_FTYPE_V2DI_V4SI_V4SI), 16260 MSA_BUILTIN_PURE (dpadd_u_h, MIPS_UV8HI_FTYPE_UV8HI_UV16QI_UV16QI), 16261 MSA_BUILTIN_PURE (dpadd_u_w, MIPS_UV4SI_FTYPE_UV4SI_UV8HI_UV8HI), 16262 MSA_BUILTIN_PURE (dpadd_u_d, MIPS_UV2DI_FTYPE_UV2DI_UV4SI_UV4SI), 16263 MSA_BUILTIN_PURE (dpsub_s_h, MIPS_V8HI_FTYPE_V8HI_V16QI_V16QI), 16264 MSA_BUILTIN_PURE (dpsub_s_w, MIPS_V4SI_FTYPE_V4SI_V8HI_V8HI), 16265 MSA_BUILTIN_PURE (dpsub_s_d, MIPS_V2DI_FTYPE_V2DI_V4SI_V4SI), 16266 MSA_BUILTIN_PURE (dpsub_u_h, MIPS_V8HI_FTYPE_V8HI_UV16QI_UV16QI), 16267 MSA_BUILTIN_PURE (dpsub_u_w, MIPS_V4SI_FTYPE_V4SI_UV8HI_UV8HI), 16268 MSA_BUILTIN_PURE (dpsub_u_d, MIPS_V2DI_FTYPE_V2DI_UV4SI_UV4SI), 16269 MSA_BUILTIN_PURE (sld_b, MIPS_V16QI_FTYPE_V16QI_V16QI_SI), 16270 MSA_BUILTIN_PURE (sld_h, MIPS_V8HI_FTYPE_V8HI_V8HI_SI), 16271 MSA_BUILTIN_PURE (sld_w, MIPS_V4SI_FTYPE_V4SI_V4SI_SI), 16272 MSA_BUILTIN_PURE (sld_d, MIPS_V2DI_FTYPE_V2DI_V2DI_SI), 16273 MSA_BUILTIN_PURE (sldi_b, MIPS_V16QI_FTYPE_V16QI_V16QI_UQI), 16274 MSA_BUILTIN_PURE (sldi_h, MIPS_V8HI_FTYPE_V8HI_V8HI_UQI), 16275 MSA_BUILTIN_PURE (sldi_w, MIPS_V4SI_FTYPE_V4SI_V4SI_UQI), 16276 MSA_BUILTIN_PURE (sldi_d, MIPS_V2DI_FTYPE_V2DI_V2DI_UQI), 16277 MSA_BUILTIN_PURE (splat_b, MIPS_V16QI_FTYPE_V16QI_SI), 16278 MSA_BUILTIN_PURE (splat_h, MIPS_V8HI_FTYPE_V8HI_SI), 16279 MSA_BUILTIN_PURE (splat_w, MIPS_V4SI_FTYPE_V4SI_SI), 16280 MSA_BUILTIN_PURE (splat_d, MIPS_V2DI_FTYPE_V2DI_SI), 16281 MSA_BUILTIN_PURE (splati_b, MIPS_V16QI_FTYPE_V16QI_UQI), 16282 MSA_BUILTIN_PURE (splati_h, MIPS_V8HI_FTYPE_V8HI_UQI), 16283 MSA_BUILTIN_PURE (splati_w, MIPS_V4SI_FTYPE_V4SI_UQI), 16284 MSA_BUILTIN_PURE (splati_d, MIPS_V2DI_FTYPE_V2DI_UQI), 16285 MSA_BUILTIN_PURE (pckev_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16286 MSA_BUILTIN_PURE (pckev_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16287 MSA_BUILTIN_PURE (pckev_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16288 MSA_BUILTIN_PURE (pckev_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16289 MSA_BUILTIN_PURE (pckod_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16290 MSA_BUILTIN_PURE (pckod_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16291 MSA_BUILTIN_PURE (pckod_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16292 MSA_BUILTIN_PURE (pckod_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16293 MSA_BUILTIN_PURE (ilvl_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16294 MSA_BUILTIN_PURE (ilvl_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16295 MSA_BUILTIN_PURE (ilvl_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16296 MSA_BUILTIN_PURE (ilvl_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16297 MSA_BUILTIN_PURE (ilvr_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16298 MSA_BUILTIN_PURE (ilvr_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16299 MSA_BUILTIN_PURE (ilvr_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16300 MSA_BUILTIN_PURE (ilvr_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16301 MSA_BUILTIN_PURE (ilvev_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16302 MSA_BUILTIN_PURE (ilvev_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16303 MSA_BUILTIN_PURE (ilvev_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16304 MSA_BUILTIN_PURE (ilvev_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16305 MSA_BUILTIN_PURE (ilvod_b, MIPS_V16QI_FTYPE_V16QI_V16QI), 16306 MSA_BUILTIN_PURE (ilvod_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16307 MSA_BUILTIN_PURE (ilvod_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16308 MSA_BUILTIN_PURE (ilvod_d, MIPS_V2DI_FTYPE_V2DI_V2DI), 16309 MSA_BUILTIN_PURE (vshf_b, MIPS_V16QI_FTYPE_V16QI_V16QI_V16QI), 16310 MSA_BUILTIN_PURE (vshf_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16311 MSA_BUILTIN_PURE (vshf_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16312 MSA_BUILTIN_PURE (vshf_d, MIPS_V2DI_FTYPE_V2DI_V2DI_V2DI), 16313 MSA_BUILTIN_PURE (and_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16314 MSA_BUILTIN_PURE (andi_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16315 MSA_BUILTIN_PURE (or_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16316 MSA_BUILTIN_PURE (ori_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16317 MSA_BUILTIN_PURE (nor_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16318 MSA_BUILTIN_PURE (nori_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16319 MSA_BUILTIN_PURE (xor_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI), 16320 MSA_BUILTIN_PURE (xori_b, MIPS_UV16QI_FTYPE_UV16QI_UQI), 16321 MSA_BUILTIN_PURE (bmnz_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI), 16322 MSA_BUILTIN_PURE (bmnzi_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI), 16323 MSA_BUILTIN_PURE (bmz_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI), 16324 MSA_BUILTIN_PURE (bmzi_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI), 16325 MSA_BUILTIN_PURE (bsel_v, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UV16QI), 16326 MSA_BUILTIN_PURE (bseli_b, MIPS_UV16QI_FTYPE_UV16QI_UV16QI_UQI), 16327 MSA_BUILTIN_PURE (shf_b, MIPS_V16QI_FTYPE_V16QI_UQI), 16328 MSA_BUILTIN_PURE (shf_h, MIPS_V8HI_FTYPE_V8HI_UQI), 16329 MSA_BUILTIN_PURE (shf_w, MIPS_V4SI_FTYPE_V4SI_UQI), 16330 MSA_BUILTIN_TEST_BRANCH (bnz_v, MIPS_SI_FTYPE_UV16QI), 16331 MSA_BUILTIN_TEST_BRANCH (bz_v, MIPS_SI_FTYPE_UV16QI), 16332 MSA_BUILTIN_PURE (fill_b, MIPS_V16QI_FTYPE_SI), 16333 MSA_BUILTIN_PURE (fill_h, MIPS_V8HI_FTYPE_SI), 16334 MSA_BUILTIN_PURE (fill_w, MIPS_V4SI_FTYPE_SI), 16335 MSA_BUILTIN_PURE (fill_d, MIPS_V2DI_FTYPE_DI), 16336 MSA_BUILTIN_PURE (pcnt_b, MIPS_V16QI_FTYPE_V16QI), 16337 MSA_BUILTIN_PURE (pcnt_h, MIPS_V8HI_FTYPE_V8HI), 16338 MSA_BUILTIN_PURE (pcnt_w, MIPS_V4SI_FTYPE_V4SI), 16339 MSA_BUILTIN_PURE (pcnt_d, MIPS_V2DI_FTYPE_V2DI), 16340 MSA_BUILTIN_PURE (nloc_b, MIPS_V16QI_FTYPE_V16QI), 16341 MSA_BUILTIN_PURE (nloc_h, MIPS_V8HI_FTYPE_V8HI), 16342 MSA_BUILTIN_PURE (nloc_w, MIPS_V4SI_FTYPE_V4SI), 16343 MSA_BUILTIN_PURE (nloc_d, MIPS_V2DI_FTYPE_V2DI), 16344 MSA_BUILTIN_PURE (nlzc_b, MIPS_V16QI_FTYPE_V16QI), 16345 MSA_BUILTIN_PURE (nlzc_h, MIPS_V8HI_FTYPE_V8HI), 16346 MSA_BUILTIN_PURE (nlzc_w, MIPS_V4SI_FTYPE_V4SI), 16347 MSA_BUILTIN_PURE (nlzc_d, MIPS_V2DI_FTYPE_V2DI), 16348 MSA_BUILTIN_PURE (copy_s_b, MIPS_SI_FTYPE_V16QI_UQI), 16349 MSA_BUILTIN_PURE (copy_s_h, MIPS_SI_FTYPE_V8HI_UQI), 16350 MSA_BUILTIN_PURE (copy_s_w, MIPS_SI_FTYPE_V4SI_UQI), 16351 MSA_BUILTIN_PURE (copy_s_d, MIPS_DI_FTYPE_V2DI_UQI), 16352 MSA_BUILTIN_PURE (copy_u_b, MIPS_USI_FTYPE_V16QI_UQI), 16353 MSA_BUILTIN_PURE (copy_u_h, MIPS_USI_FTYPE_V8HI_UQI), 16354 MSA_BUILTIN_REMAP (copy_u_w, copy_s_w, MIPS_USI_FTYPE_V4SI_UQI), 16355 MSA_BUILTIN_REMAP (copy_u_d, copy_s_d, MIPS_UDI_FTYPE_V2DI_UQI), 16356 MSA_BUILTIN_PURE (insert_b, MIPS_V16QI_FTYPE_V16QI_UQI_SI), 16357 MSA_BUILTIN_PURE (insert_h, MIPS_V8HI_FTYPE_V8HI_UQI_SI), 16358 MSA_BUILTIN_PURE (insert_w, MIPS_V4SI_FTYPE_V4SI_UQI_SI), 16359 MSA_BUILTIN_PURE (insert_d, MIPS_V2DI_FTYPE_V2DI_UQI_DI), 16360 MSA_BUILTIN_PURE (insve_b, MIPS_V16QI_FTYPE_V16QI_UQI_V16QI), 16361 MSA_BUILTIN_PURE (insve_h, MIPS_V8HI_FTYPE_V8HI_UQI_V8HI), 16362 MSA_BUILTIN_PURE (insve_w, MIPS_V4SI_FTYPE_V4SI_UQI_V4SI), 16363 MSA_BUILTIN_PURE (insve_d, MIPS_V2DI_FTYPE_V2DI_UQI_V2DI), 16364 MSA_BUILTIN_TEST_BRANCH (bnz_b, MIPS_SI_FTYPE_UV16QI), 16365 MSA_BUILTIN_TEST_BRANCH (bnz_h, MIPS_SI_FTYPE_UV8HI), 16366 MSA_BUILTIN_TEST_BRANCH (bnz_w, MIPS_SI_FTYPE_UV4SI), 16367 MSA_BUILTIN_TEST_BRANCH (bnz_d, MIPS_SI_FTYPE_UV2DI), 16368 MSA_BUILTIN_TEST_BRANCH (bz_b, MIPS_SI_FTYPE_UV16QI), 16369 MSA_BUILTIN_TEST_BRANCH (bz_h, MIPS_SI_FTYPE_UV8HI), 16370 MSA_BUILTIN_TEST_BRANCH (bz_w, MIPS_SI_FTYPE_UV4SI), 16371 MSA_BUILTIN_TEST_BRANCH (bz_d, MIPS_SI_FTYPE_UV2DI), 16372 MSA_BUILTIN_PURE (ldi_b, MIPS_V16QI_FTYPE_HI), 16373 MSA_BUILTIN_PURE (ldi_h, MIPS_V8HI_FTYPE_HI), 16374 MSA_BUILTIN_PURE (ldi_w, MIPS_V4SI_FTYPE_HI), 16375 MSA_BUILTIN_PURE (ldi_d, MIPS_V2DI_FTYPE_HI), 16376 MSA_BUILTIN_PURE (fcaf_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16377 MSA_BUILTIN_PURE (fcaf_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16378 MSA_BUILTIN_PURE (fcor_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16379 MSA_BUILTIN_PURE (fcor_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16380 MSA_BUILTIN_PURE (fcun_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16381 MSA_BUILTIN_PURE (fcun_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16382 MSA_BUILTIN_PURE (fcune_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16383 MSA_BUILTIN_PURE (fcune_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16384 MSA_BUILTIN_PURE (fcueq_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16385 MSA_BUILTIN_PURE (fcueq_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16386 MSA_BUILTIN_PURE (fceq_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16387 MSA_BUILTIN_PURE (fceq_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16388 MSA_BUILTIN_PURE (fcne_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16389 MSA_BUILTIN_PURE (fcne_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16390 MSA_BUILTIN_PURE (fclt_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16391 MSA_BUILTIN_PURE (fclt_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16392 MSA_BUILTIN_PURE (fcult_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16393 MSA_BUILTIN_PURE (fcult_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16394 MSA_BUILTIN_PURE (fcle_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16395 MSA_BUILTIN_PURE (fcle_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16396 MSA_BUILTIN_PURE (fcule_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16397 MSA_BUILTIN_PURE (fcule_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16398 MSA_BUILTIN_PURE (fsaf_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16399 MSA_BUILTIN_PURE (fsaf_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16400 MSA_BUILTIN_PURE (fsor_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16401 MSA_BUILTIN_PURE (fsor_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16402 MSA_BUILTIN_PURE (fsun_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16403 MSA_BUILTIN_PURE (fsun_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16404 MSA_BUILTIN_PURE (fsune_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16405 MSA_BUILTIN_PURE (fsune_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16406 MSA_BUILTIN_PURE (fsueq_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16407 MSA_BUILTIN_PURE (fsueq_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16408 MSA_BUILTIN_PURE (fseq_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16409 MSA_BUILTIN_PURE (fseq_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16410 MSA_BUILTIN_PURE (fsne_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16411 MSA_BUILTIN_PURE (fsne_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16412 MSA_BUILTIN_PURE (fslt_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16413 MSA_BUILTIN_PURE (fslt_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16414 MSA_BUILTIN_PURE (fsult_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16415 MSA_BUILTIN_PURE (fsult_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16416 MSA_BUILTIN_PURE (fsle_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16417 MSA_BUILTIN_PURE (fsle_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16418 MSA_BUILTIN_PURE (fsule_w, MIPS_V4SI_FTYPE_V4SF_V4SF), 16419 MSA_BUILTIN_PURE (fsule_d, MIPS_V2DI_FTYPE_V2DF_V2DF), 16420 MSA_BUILTIN_PURE (fadd_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16421 MSA_BUILTIN_PURE (fadd_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16422 MSA_BUILTIN_PURE (fsub_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16423 MSA_BUILTIN_PURE (fsub_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16424 MSA_BUILTIN_PURE (fmul_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16425 MSA_BUILTIN_PURE (fmul_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16426 MSA_BUILTIN_PURE (fdiv_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16427 MSA_BUILTIN_PURE (fdiv_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16428 MSA_BUILTIN_PURE (fmadd_w, MIPS_V4SF_FTYPE_V4SF_V4SF_V4SF), 16429 MSA_BUILTIN_PURE (fmadd_d, MIPS_V2DF_FTYPE_V2DF_V2DF_V2DF), 16430 MSA_BUILTIN_PURE (fmsub_w, MIPS_V4SF_FTYPE_V4SF_V4SF_V4SF), 16431 MSA_BUILTIN_PURE (fmsub_d, MIPS_V2DF_FTYPE_V2DF_V2DF_V2DF), 16432 MSA_BUILTIN_PURE (fexp2_w, MIPS_V4SF_FTYPE_V4SF_V4SI), 16433 MSA_BUILTIN_PURE (fexp2_d, MIPS_V2DF_FTYPE_V2DF_V2DI), 16434 MSA_BUILTIN_PURE (fexdo_h, MIPS_V8HI_FTYPE_V4SF_V4SF), 16435 MSA_BUILTIN_PURE (fexdo_w, MIPS_V4SF_FTYPE_V2DF_V2DF), 16436 MSA_BUILTIN_PURE (ftq_h, MIPS_V8HI_FTYPE_V4SF_V4SF), 16437 MSA_BUILTIN_PURE (ftq_w, MIPS_V4SI_FTYPE_V2DF_V2DF), 16438 MSA_BUILTIN_PURE (fmin_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16439 MSA_BUILTIN_PURE (fmin_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16440 MSA_BUILTIN_PURE (fmin_a_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16441 MSA_BUILTIN_PURE (fmin_a_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16442 MSA_BUILTIN_PURE (fmax_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16443 MSA_BUILTIN_PURE (fmax_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16444 MSA_BUILTIN_PURE (fmax_a_w, MIPS_V4SF_FTYPE_V4SF_V4SF), 16445 MSA_BUILTIN_PURE (fmax_a_d, MIPS_V2DF_FTYPE_V2DF_V2DF), 16446 MSA_BUILTIN_PURE (mul_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16447 MSA_BUILTIN_PURE (mul_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16448 MSA_BUILTIN_PURE (mulr_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI), 16449 MSA_BUILTIN_PURE (mulr_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI), 16450 MSA_BUILTIN_PURE (madd_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16451 MSA_BUILTIN_PURE (madd_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16452 MSA_BUILTIN_PURE (maddr_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16453 MSA_BUILTIN_PURE (maddr_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16454 MSA_BUILTIN_PURE (msub_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16455 MSA_BUILTIN_PURE (msub_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16456 MSA_BUILTIN_PURE (msubr_q_h, MIPS_V8HI_FTYPE_V8HI_V8HI_V8HI), 16457 MSA_BUILTIN_PURE (msubr_q_w, MIPS_V4SI_FTYPE_V4SI_V4SI_V4SI), 16458 MSA_BUILTIN_PURE (fclass_w, MIPS_V4SI_FTYPE_V4SF), 16459 MSA_BUILTIN_PURE (fclass_d, MIPS_V2DI_FTYPE_V2DF), 16460 MSA_BUILTIN_PURE (fsqrt_w, MIPS_V4SF_FTYPE_V4SF), 16461 MSA_BUILTIN_PURE (fsqrt_d, MIPS_V2DF_FTYPE_V2DF), 16462 MSA_BUILTIN_PURE (frcp_w, MIPS_V4SF_FTYPE_V4SF), 16463 MSA_BUILTIN_PURE (frcp_d, MIPS_V2DF_FTYPE_V2DF), 16464 MSA_BUILTIN_PURE (frint_w, MIPS_V4SF_FTYPE_V4SF), 16465 MSA_BUILTIN_PURE (frint_d, MIPS_V2DF_FTYPE_V2DF), 16466 MSA_BUILTIN_PURE (frsqrt_w, MIPS_V4SF_FTYPE_V4SF), 16467 MSA_BUILTIN_PURE (frsqrt_d, MIPS_V2DF_FTYPE_V2DF), 16468 MSA_BUILTIN_PURE (flog2_w, MIPS_V4SF_FTYPE_V4SF), 16469 MSA_BUILTIN_PURE (flog2_d, MIPS_V2DF_FTYPE_V2DF), 16470 MSA_BUILTIN_PURE (fexupl_w, MIPS_V4SF_FTYPE_V8HI), 16471 MSA_BUILTIN_PURE (fexupl_d, MIPS_V2DF_FTYPE_V4SF), 16472 MSA_BUILTIN_PURE (fexupr_w, MIPS_V4SF_FTYPE_V8HI), 16473 MSA_BUILTIN_PURE (fexupr_d, MIPS_V2DF_FTYPE_V4SF), 16474 MSA_BUILTIN_PURE (ffql_w, MIPS_V4SF_FTYPE_V8HI), 16475 MSA_BUILTIN_PURE (ffql_d, MIPS_V2DF_FTYPE_V4SI), 16476 MSA_BUILTIN_PURE (ffqr_w, MIPS_V4SF_FTYPE_V8HI), 16477 MSA_BUILTIN_PURE (ffqr_d, MIPS_V2DF_FTYPE_V4SI), 16478 MSA_BUILTIN_PURE (ftint_s_w, MIPS_V4SI_FTYPE_V4SF), 16479 MSA_BUILTIN_PURE (ftint_s_d, MIPS_V2DI_FTYPE_V2DF), 16480 MSA_BUILTIN_PURE (ftint_u_w, MIPS_UV4SI_FTYPE_V4SF), 16481 MSA_BUILTIN_PURE (ftint_u_d, MIPS_UV2DI_FTYPE_V2DF), 16482 MSA_BUILTIN_PURE (ftrunc_s_w, MIPS_V4SI_FTYPE_V4SF), 16483 MSA_BUILTIN_PURE (ftrunc_s_d, MIPS_V2DI_FTYPE_V2DF), 16484 MSA_BUILTIN_PURE (ftrunc_u_w, MIPS_UV4SI_FTYPE_V4SF), 16485 MSA_BUILTIN_PURE (ftrunc_u_d, MIPS_UV2DI_FTYPE_V2DF), 16486 MSA_BUILTIN_PURE (ffint_s_w, MIPS_V4SF_FTYPE_V4SI), 16487 MSA_BUILTIN_PURE (ffint_s_d, MIPS_V2DF_FTYPE_V2DI), 16488 MSA_BUILTIN_PURE (ffint_u_w, MIPS_V4SF_FTYPE_UV4SI), 16489 MSA_BUILTIN_PURE (ffint_u_d, MIPS_V2DF_FTYPE_UV2DI), 16490 MSA_NO_TARGET_BUILTIN (ctcmsa, MIPS_VOID_FTYPE_UQI_SI), 16491 MSA_BUILTIN_PURE (cfcmsa, MIPS_SI_FTYPE_UQI), 16492 MSA_BUILTIN_PURE (move_v, MIPS_V16QI_FTYPE_V16QI), 16493 }; 16494 16495 /* Index I is the function declaration for mips_builtins[I], or null if the 16496 function isn't defined on this target. */ 16497 static GTY(()) tree mips_builtin_decls[ARRAY_SIZE (mips_builtins)]; 16498 /* Get the index I of the function declaration for mips_builtin_decls[I] 16499 using the instruction code or return null if not defined for the target. */ 16500 static GTY(()) int mips_get_builtin_decl_index[NUM_INSN_CODES]; 16501 16502 /* MODE is a vector mode whose elements have type TYPE. Return the type 16503 of the vector itself. */ 16504 16505 static tree 16506 mips_builtin_vector_type (tree type, machine_mode mode) 16507 { 16508 static tree types[2 * (int) MAX_MACHINE_MODE]; 16509 int mode_index; 16510 16511 mode_index = (int) mode; 16512 16513 if (TREE_CODE (type) == INTEGER_TYPE && TYPE_UNSIGNED (type)) 16514 mode_index += MAX_MACHINE_MODE; 16515 16516 if (types[mode_index] == NULL_TREE) 16517 types[mode_index] = build_vector_type_for_mode (type, mode); 16518 return types[mode_index]; 16519 } 16520 16521 /* Return a type for 'const volatile void *'. */ 16522 16523 static tree 16524 mips_build_cvpointer_type (void) 16525 { 16526 static tree cache; 16527 16528 if (cache == NULL_TREE) 16529 cache = build_pointer_type (build_qualified_type 16530 (void_type_node, 16531 TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE)); 16532 return cache; 16533 } 16534 16535 /* Source-level argument types. */ 16536 #define MIPS_ATYPE_VOID void_type_node 16537 #define MIPS_ATYPE_INT integer_type_node 16538 #define MIPS_ATYPE_POINTER ptr_type_node 16539 #define MIPS_ATYPE_CVPOINTER mips_build_cvpointer_type () 16540 16541 /* Standard mode-based argument types. */ 16542 #define MIPS_ATYPE_QI intQI_type_node 16543 #define MIPS_ATYPE_UQI unsigned_intQI_type_node 16544 #define MIPS_ATYPE_HI intHI_type_node 16545 #define MIPS_ATYPE_SI intSI_type_node 16546 #define MIPS_ATYPE_USI unsigned_intSI_type_node 16547 #define MIPS_ATYPE_DI intDI_type_node 16548 #define MIPS_ATYPE_UDI unsigned_intDI_type_node 16549 #define MIPS_ATYPE_SF float_type_node 16550 #define MIPS_ATYPE_DF double_type_node 16551 16552 /* Vector argument types. */ 16553 #define MIPS_ATYPE_V2SF mips_builtin_vector_type (float_type_node, V2SFmode) 16554 #define MIPS_ATYPE_V2HI mips_builtin_vector_type (intHI_type_node, V2HImode) 16555 #define MIPS_ATYPE_V2SI mips_builtin_vector_type (intSI_type_node, V2SImode) 16556 #define MIPS_ATYPE_V4QI mips_builtin_vector_type (intQI_type_node, V4QImode) 16557 #define MIPS_ATYPE_V4HI mips_builtin_vector_type (intHI_type_node, V4HImode) 16558 #define MIPS_ATYPE_V8QI mips_builtin_vector_type (intQI_type_node, V8QImode) 16559 16560 #define MIPS_ATYPE_V2DI \ 16561 mips_builtin_vector_type (long_long_integer_type_node, V2DImode) 16562 #define MIPS_ATYPE_V4SI mips_builtin_vector_type (intSI_type_node, V4SImode) 16563 #define MIPS_ATYPE_V8HI mips_builtin_vector_type (intHI_type_node, V8HImode) 16564 #define MIPS_ATYPE_V16QI mips_builtin_vector_type (intQI_type_node, V16QImode) 16565 #define MIPS_ATYPE_V2DF mips_builtin_vector_type (double_type_node, V2DFmode) 16566 #define MIPS_ATYPE_V4SF mips_builtin_vector_type (float_type_node, V4SFmode) 16567 16568 #define MIPS_ATYPE_UV2DI \ 16569 mips_builtin_vector_type (long_long_unsigned_type_node, V2DImode) 16570 #define MIPS_ATYPE_UV4SI \ 16571 mips_builtin_vector_type (unsigned_intSI_type_node, V4SImode) 16572 #define MIPS_ATYPE_UV8HI \ 16573 mips_builtin_vector_type (unsigned_intHI_type_node, V8HImode) 16574 #define MIPS_ATYPE_UV16QI \ 16575 mips_builtin_vector_type (unsigned_intQI_type_node, V16QImode) 16576 16577 #define MIPS_ATYPE_UV2SI \ 16578 mips_builtin_vector_type (unsigned_intSI_type_node, V2SImode) 16579 #define MIPS_ATYPE_UV4HI \ 16580 mips_builtin_vector_type (unsigned_intHI_type_node, V4HImode) 16581 #define MIPS_ATYPE_UV8QI \ 16582 mips_builtin_vector_type (unsigned_intQI_type_node, V8QImode) 16583 16584 /* MIPS_FTYPE_ATYPESN takes N MIPS_FTYPES-like type codes and lists 16585 their associated MIPS_ATYPEs. */ 16586 #define MIPS_FTYPE_ATYPES1(A, B) \ 16587 MIPS_ATYPE_##A, MIPS_ATYPE_##B 16588 16589 #define MIPS_FTYPE_ATYPES2(A, B, C) \ 16590 MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C 16591 16592 #define MIPS_FTYPE_ATYPES3(A, B, C, D) \ 16593 MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C, MIPS_ATYPE_##D 16594 16595 #define MIPS_FTYPE_ATYPES4(A, B, C, D, E) \ 16596 MIPS_ATYPE_##A, MIPS_ATYPE_##B, MIPS_ATYPE_##C, MIPS_ATYPE_##D, \ 16597 MIPS_ATYPE_##E 16598 16599 /* Return the function type associated with function prototype TYPE. */ 16600 16601 static tree 16602 mips_build_function_type (enum mips_function_type type) 16603 { 16604 static tree types[(int) MIPS_MAX_FTYPE_MAX]; 16605 16606 if (types[(int) type] == NULL_TREE) 16607 switch (type) 16608 { 16609 #define DEF_MIPS_FTYPE(NUM, ARGS) \ 16610 case MIPS_FTYPE_NAME##NUM ARGS: \ 16611 types[(int) type] \ 16612 = build_function_type_list (MIPS_FTYPE_ATYPES##NUM ARGS, \ 16613 NULL_TREE); \ 16614 break; 16615 #include "config/mips/mips-ftypes.def" 16616 #undef DEF_MIPS_FTYPE 16617 default: 16618 gcc_unreachable (); 16619 } 16620 16621 return types[(int) type]; 16622 } 16623 16624 /* Implement TARGET_INIT_BUILTINS. */ 16625 16626 static void 16627 mips_init_builtins (void) 16628 { 16629 const struct mips_builtin_description *d; 16630 unsigned int i; 16631 16632 /* Iterate through all of the bdesc arrays, initializing all of the 16633 builtin functions. */ 16634 for (i = 0; i < ARRAY_SIZE (mips_builtins); i++) 16635 { 16636 d = &mips_builtins[i]; 16637 if (d->avail ()) 16638 { 16639 mips_builtin_decls[i] 16640 = add_builtin_function (d->name, 16641 mips_build_function_type (d->function_type), 16642 i, BUILT_IN_MD, NULL, NULL); 16643 if (mips_builtin_decls[i] && d->is_pure) 16644 DECL_PURE_P (mips_builtin_decls[i]) = 1; 16645 mips_get_builtin_decl_index[d->icode] = i; 16646 } 16647 } 16648 } 16649 16650 /* Implement TARGET_BUILTIN_DECL. */ 16651 16652 static tree 16653 mips_builtin_decl (unsigned int code, bool initialize_p ATTRIBUTE_UNUSED) 16654 { 16655 if (code >= ARRAY_SIZE (mips_builtins)) 16656 return error_mark_node; 16657 return mips_builtin_decls[code]; 16658 } 16659 16660 /* Implement TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION. */ 16661 16662 static tree 16663 mips_builtin_vectorized_function (unsigned int fn, tree type_out, tree type_in) 16664 { 16665 machine_mode in_mode, out_mode; 16666 int in_n, out_n; 16667 16668 if (TREE_CODE (type_out) != VECTOR_TYPE 16669 || TREE_CODE (type_in) != VECTOR_TYPE 16670 || !ISA_HAS_MSA) 16671 return NULL_TREE; 16672 16673 out_mode = TYPE_MODE (TREE_TYPE (type_out)); 16674 out_n = TYPE_VECTOR_SUBPARTS (type_out); 16675 in_mode = TYPE_MODE (TREE_TYPE (type_in)); 16676 in_n = TYPE_VECTOR_SUBPARTS (type_in); 16677 16678 /* INSN is the name of the associated instruction pattern, without 16679 the leading CODE_FOR_. */ 16680 #define MIPS_GET_BUILTIN(INSN) \ 16681 mips_builtin_decls[mips_get_builtin_decl_index[CODE_FOR_##INSN]] 16682 16683 switch (fn) 16684 { 16685 case BUILT_IN_SQRT: 16686 if (out_mode == DFmode && out_n == 2 16687 && in_mode == DFmode && in_n == 2) 16688 return MIPS_GET_BUILTIN (msa_fsqrt_d); 16689 break; 16690 case BUILT_IN_SQRTF: 16691 if (out_mode == SFmode && out_n == 4 16692 && in_mode == SFmode && in_n == 4) 16693 return MIPS_GET_BUILTIN (msa_fsqrt_w); 16694 break; 16695 default: 16696 break; 16697 } 16698 16699 return NULL_TREE; 16700 } 16701 16702 /* Take argument ARGNO from EXP's argument list and convert it into 16703 an expand operand. Store the operand in *OP. */ 16704 16705 static void 16706 mips_prepare_builtin_arg (struct expand_operand *op, tree exp, 16707 unsigned int argno) 16708 { 16709 tree arg; 16710 rtx value; 16711 16712 arg = CALL_EXPR_ARG (exp, argno); 16713 value = expand_normal (arg); 16714 create_input_operand (op, value, TYPE_MODE (TREE_TYPE (arg))); 16715 } 16716 16717 /* Expand instruction ICODE as part of a built-in function sequence. 16718 Use the first NOPS elements of OPS as the instruction's operands. 16719 HAS_TARGET_P is true if operand 0 is a target; it is false if the 16720 instruction has no target. 16721 16722 Return the target rtx if HAS_TARGET_P, otherwise return const0_rtx. */ 16723 16724 static rtx 16725 mips_expand_builtin_insn (enum insn_code icode, unsigned int nops, 16726 struct expand_operand *ops, bool has_target_p) 16727 { 16728 machine_mode imode; 16729 int rangelo = 0, rangehi = 0, error_opno = 0; 16730 rtx sireg; 16731 16732 switch (icode) 16733 { 16734 /* The third operand of these instructions is in SImode, so we need to 16735 bring the corresponding builtin argument from QImode into SImode. */ 16736 case CODE_FOR_loongson_pshufh: 16737 case CODE_FOR_loongson_psllh: 16738 case CODE_FOR_loongson_psllw: 16739 case CODE_FOR_loongson_psrah: 16740 case CODE_FOR_loongson_psraw: 16741 case CODE_FOR_loongson_psrlh: 16742 case CODE_FOR_loongson_psrlw: 16743 gcc_assert (has_target_p && nops == 3 && ops[2].mode == QImode); 16744 sireg = gen_reg_rtx (SImode); 16745 emit_insn (gen_zero_extendqisi2 (sireg, 16746 force_reg (QImode, ops[2].value))); 16747 ops[2].value = sireg; 16748 ops[2].mode = SImode; 16749 break; 16750 16751 case CODE_FOR_msa_addvi_b: 16752 case CODE_FOR_msa_addvi_h: 16753 case CODE_FOR_msa_addvi_w: 16754 case CODE_FOR_msa_addvi_d: 16755 case CODE_FOR_msa_clti_u_b: 16756 case CODE_FOR_msa_clti_u_h: 16757 case CODE_FOR_msa_clti_u_w: 16758 case CODE_FOR_msa_clti_u_d: 16759 case CODE_FOR_msa_clei_u_b: 16760 case CODE_FOR_msa_clei_u_h: 16761 case CODE_FOR_msa_clei_u_w: 16762 case CODE_FOR_msa_clei_u_d: 16763 case CODE_FOR_msa_maxi_u_b: 16764 case CODE_FOR_msa_maxi_u_h: 16765 case CODE_FOR_msa_maxi_u_w: 16766 case CODE_FOR_msa_maxi_u_d: 16767 case CODE_FOR_msa_mini_u_b: 16768 case CODE_FOR_msa_mini_u_h: 16769 case CODE_FOR_msa_mini_u_w: 16770 case CODE_FOR_msa_mini_u_d: 16771 case CODE_FOR_msa_subvi_b: 16772 case CODE_FOR_msa_subvi_h: 16773 case CODE_FOR_msa_subvi_w: 16774 case CODE_FOR_msa_subvi_d: 16775 gcc_assert (has_target_p && nops == 3); 16776 /* We only generate a vector of constants iff the second argument 16777 is an immediate. We also validate the range of the immediate. */ 16778 if (CONST_INT_P (ops[2].value)) 16779 { 16780 rangelo = 0; 16781 rangehi = 31; 16782 if (IN_RANGE (INTVAL (ops[2].value), rangelo, rangehi)) 16783 { 16784 ops[2].mode = ops[0].mode; 16785 ops[2].value = mips_gen_const_int_vector (ops[2].mode, 16786 INTVAL (ops[2].value)); 16787 } 16788 else 16789 error_opno = 2; 16790 } 16791 break; 16792 16793 case CODE_FOR_msa_ceqi_b: 16794 case CODE_FOR_msa_ceqi_h: 16795 case CODE_FOR_msa_ceqi_w: 16796 case CODE_FOR_msa_ceqi_d: 16797 case CODE_FOR_msa_clti_s_b: 16798 case CODE_FOR_msa_clti_s_h: 16799 case CODE_FOR_msa_clti_s_w: 16800 case CODE_FOR_msa_clti_s_d: 16801 case CODE_FOR_msa_clei_s_b: 16802 case CODE_FOR_msa_clei_s_h: 16803 case CODE_FOR_msa_clei_s_w: 16804 case CODE_FOR_msa_clei_s_d: 16805 case CODE_FOR_msa_maxi_s_b: 16806 case CODE_FOR_msa_maxi_s_h: 16807 case CODE_FOR_msa_maxi_s_w: 16808 case CODE_FOR_msa_maxi_s_d: 16809 case CODE_FOR_msa_mini_s_b: 16810 case CODE_FOR_msa_mini_s_h: 16811 case CODE_FOR_msa_mini_s_w: 16812 case CODE_FOR_msa_mini_s_d: 16813 gcc_assert (has_target_p && nops == 3); 16814 /* We only generate a vector of constants iff the second argument 16815 is an immediate. We also validate the range of the immediate. */ 16816 if (CONST_INT_P (ops[2].value)) 16817 { 16818 rangelo = -16; 16819 rangehi = 15; 16820 if (IN_RANGE (INTVAL (ops[2].value), rangelo, rangehi)) 16821 { 16822 ops[2].mode = ops[0].mode; 16823 ops[2].value = mips_gen_const_int_vector (ops[2].mode, 16824 INTVAL (ops[2].value)); 16825 } 16826 else 16827 error_opno = 2; 16828 } 16829 break; 16830 16831 case CODE_FOR_msa_andi_b: 16832 case CODE_FOR_msa_ori_b: 16833 case CODE_FOR_msa_nori_b: 16834 case CODE_FOR_msa_xori_b: 16835 gcc_assert (has_target_p && nops == 3); 16836 if (!CONST_INT_P (ops[2].value)) 16837 break; 16838 ops[2].mode = ops[0].mode; 16839 ops[2].value = mips_gen_const_int_vector (ops[2].mode, 16840 INTVAL (ops[2].value)); 16841 break; 16842 16843 case CODE_FOR_msa_bmzi_b: 16844 case CODE_FOR_msa_bmnzi_b: 16845 case CODE_FOR_msa_bseli_b: 16846 gcc_assert (has_target_p && nops == 4); 16847 if (!CONST_INT_P (ops[3].value)) 16848 break; 16849 ops[3].mode = ops[0].mode; 16850 ops[3].value = mips_gen_const_int_vector (ops[3].mode, 16851 INTVAL (ops[3].value)); 16852 break; 16853 16854 case CODE_FOR_msa_fill_b: 16855 case CODE_FOR_msa_fill_h: 16856 case CODE_FOR_msa_fill_w: 16857 case CODE_FOR_msa_fill_d: 16858 /* Map the built-ins to vector fill operations. We need fix up the mode 16859 for the element being inserted. */ 16860 gcc_assert (has_target_p && nops == 2); 16861 imode = GET_MODE_INNER (ops[0].mode); 16862 ops[1].value = lowpart_subreg (imode, ops[1].value, ops[1].mode); 16863 ops[1].mode = imode; 16864 break; 16865 16866 case CODE_FOR_msa_ilvl_b: 16867 case CODE_FOR_msa_ilvl_h: 16868 case CODE_FOR_msa_ilvl_w: 16869 case CODE_FOR_msa_ilvl_d: 16870 case CODE_FOR_msa_ilvr_b: 16871 case CODE_FOR_msa_ilvr_h: 16872 case CODE_FOR_msa_ilvr_w: 16873 case CODE_FOR_msa_ilvr_d: 16874 case CODE_FOR_msa_ilvev_b: 16875 case CODE_FOR_msa_ilvev_h: 16876 case CODE_FOR_msa_ilvev_w: 16877 case CODE_FOR_msa_ilvod_b: 16878 case CODE_FOR_msa_ilvod_h: 16879 case CODE_FOR_msa_ilvod_w: 16880 case CODE_FOR_msa_pckev_b: 16881 case CODE_FOR_msa_pckev_h: 16882 case CODE_FOR_msa_pckev_w: 16883 case CODE_FOR_msa_pckod_b: 16884 case CODE_FOR_msa_pckod_h: 16885 case CODE_FOR_msa_pckod_w: 16886 /* Swap the operands 1 and 2 for interleave operations. Built-ins follow 16887 convention of ISA, which have op1 as higher component and op2 as lower 16888 component. However, the VEC_PERM op in tree and vec_concat in RTL 16889 expects first operand to be lower component, because of which this 16890 swap is needed for builtins. */ 16891 gcc_assert (has_target_p && nops == 3); 16892 std::swap (ops[1], ops[2]); 16893 break; 16894 16895 case CODE_FOR_msa_maddv_b: 16896 case CODE_FOR_msa_maddv_h: 16897 case CODE_FOR_msa_maddv_w: 16898 case CODE_FOR_msa_maddv_d: 16899 case CODE_FOR_msa_fmadd_w: 16900 case CODE_FOR_msa_fmadd_d: 16901 case CODE_FOR_msa_fmsub_w: 16902 case CODE_FOR_msa_fmsub_d: 16903 /* fma(a, b, c) results into (a * b + c), however builtin_msa_fmadd expects 16904 it to be (a + b * c). Swap the 1st and 3rd operands. */ 16905 std::swap (ops[1], ops[3]); 16906 break; 16907 16908 case CODE_FOR_msa_slli_b: 16909 case CODE_FOR_msa_slli_h: 16910 case CODE_FOR_msa_slli_w: 16911 case CODE_FOR_msa_slli_d: 16912 case CODE_FOR_msa_srai_b: 16913 case CODE_FOR_msa_srai_h: 16914 case CODE_FOR_msa_srai_w: 16915 case CODE_FOR_msa_srai_d: 16916 case CODE_FOR_msa_srli_b: 16917 case CODE_FOR_msa_srli_h: 16918 case CODE_FOR_msa_srli_w: 16919 case CODE_FOR_msa_srli_d: 16920 gcc_assert (has_target_p && nops == 3); 16921 if (CONST_INT_P (ops[2].value)) 16922 { 16923 rangelo = 0; 16924 rangehi = GET_MODE_UNIT_BITSIZE (ops[0].mode) - 1; 16925 if (IN_RANGE (INTVAL (ops[2].value), rangelo, rangehi)) 16926 { 16927 ops[2].mode = ops[0].mode; 16928 ops[2].value = mips_gen_const_int_vector (ops[2].mode, 16929 INTVAL (ops[2].value)); 16930 } 16931 else 16932 error_opno = 2; 16933 } 16934 break; 16935 16936 case CODE_FOR_msa_insert_b: 16937 case CODE_FOR_msa_insert_h: 16938 case CODE_FOR_msa_insert_w: 16939 case CODE_FOR_msa_insert_d: 16940 /* Map the built-ins to insert operations. We need to swap operands, 16941 fix up the mode for the element being inserted, and generate 16942 a bit mask for vec_merge. */ 16943 gcc_assert (has_target_p && nops == 4); 16944 std::swap (ops[1], ops[2]); 16945 std::swap (ops[1], ops[3]); 16946 imode = GET_MODE_INNER (ops[0].mode); 16947 ops[1].value = lowpart_subreg (imode, ops[1].value, ops[1].mode); 16948 ops[1].mode = imode; 16949 rangelo = 0; 16950 rangehi = GET_MODE_NUNITS (ops[0].mode) - 1; 16951 if (CONST_INT_P (ops[3].value) 16952 && IN_RANGE (INTVAL (ops[3].value), rangelo, rangehi)) 16953 ops[3].value = GEN_INT (1 << INTVAL (ops[3].value)); 16954 else 16955 error_opno = 2; 16956 break; 16957 16958 case CODE_FOR_msa_insve_b: 16959 case CODE_FOR_msa_insve_h: 16960 case CODE_FOR_msa_insve_w: 16961 case CODE_FOR_msa_insve_d: 16962 /* Map the built-ins to element insert operations. We need to swap 16963 operands and generate a bit mask. */ 16964 gcc_assert (has_target_p && nops == 4); 16965 std::swap (ops[1], ops[2]); 16966 std::swap (ops[1], ops[3]); 16967 rangelo = 0; 16968 rangehi = GET_MODE_NUNITS (ops[0].mode) - 1; 16969 if (CONST_INT_P (ops[3].value) 16970 && IN_RANGE (INTVAL (ops[3].value), rangelo, rangehi)) 16971 ops[3].value = GEN_INT (1 << INTVAL (ops[3].value)); 16972 else 16973 error_opno = 2; 16974 break; 16975 16976 case CODE_FOR_msa_shf_b: 16977 case CODE_FOR_msa_shf_h: 16978 case CODE_FOR_msa_shf_w: 16979 case CODE_FOR_msa_shf_w_f: 16980 gcc_assert (has_target_p && nops == 3); 16981 ops[2].value = mips_gen_const_int_vector_shuffle (ops[0].mode, 16982 INTVAL (ops[2].value)); 16983 break; 16984 16985 case CODE_FOR_msa_vshf_b: 16986 case CODE_FOR_msa_vshf_h: 16987 case CODE_FOR_msa_vshf_w: 16988 case CODE_FOR_msa_vshf_d: 16989 gcc_assert (has_target_p && nops == 4); 16990 std::swap (ops[1], ops[3]); 16991 break; 16992 16993 case CODE_FOR_msa_dpadd_s_w: 16994 case CODE_FOR_msa_dpadd_s_h: 16995 case CODE_FOR_msa_dpadd_s_d: 16996 case CODE_FOR_msa_dpadd_u_w: 16997 case CODE_FOR_msa_dpadd_u_h: 16998 case CODE_FOR_msa_dpadd_u_d: 16999 case CODE_FOR_msa_dpsub_s_w: 17000 case CODE_FOR_msa_dpsub_s_h: 17001 case CODE_FOR_msa_dpsub_s_d: 17002 case CODE_FOR_msa_dpsub_u_w: 17003 case CODE_FOR_msa_dpsub_u_h: 17004 case CODE_FOR_msa_dpsub_u_d: 17005 /* Force the operands which correspond to the same in-out register 17006 to have the same pseudo assigned to them. If the input operand 17007 is not REG, create one for it. */ 17008 if (!REG_P (ops[1].value)) 17009 ops[1].value = copy_to_mode_reg (ops[1].mode, ops[1].value); 17010 create_output_operand (&ops[0], ops[1].value, ops[1].mode); 17011 break; 17012 17013 default: 17014 break; 17015 } 17016 17017 if (error_opno != 0) 17018 { 17019 error ("argument %d to the built-in must be a constant" 17020 " in range %d to %d", error_opno, rangelo, rangehi); 17021 return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx; 17022 } 17023 else if (!maybe_expand_insn (icode, nops, ops)) 17024 { 17025 error ("invalid argument to built-in function"); 17026 return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx; 17027 } 17028 return has_target_p ? ops[0].value : const0_rtx; 17029 } 17030 17031 /* Expand a floating-point comparison for built-in function call EXP. 17032 The first NARGS arguments are the values to be compared. ICODE is 17033 the .md pattern that does the comparison and COND is the condition 17034 that is being tested. Return an rtx for the result. */ 17035 17036 static rtx 17037 mips_expand_builtin_compare_1 (enum insn_code icode, 17038 enum mips_fp_condition cond, 17039 tree exp, int nargs) 17040 { 17041 struct expand_operand ops[MAX_RECOG_OPERANDS]; 17042 rtx output; 17043 int opno, argno; 17044 17045 /* The instruction should have a target operand, an operand for each 17046 argument, and an operand for COND. */ 17047 gcc_assert (nargs + 2 == insn_data[(int) icode].n_generator_args); 17048 17049 output = mips_allocate_fcc (insn_data[(int) icode].operand[0].mode); 17050 opno = 0; 17051 create_fixed_operand (&ops[opno++], output); 17052 for (argno = 0; argno < nargs; argno++) 17053 mips_prepare_builtin_arg (&ops[opno++], exp, argno); 17054 create_integer_operand (&ops[opno++], (int) cond); 17055 return mips_expand_builtin_insn (icode, opno, ops, true); 17056 } 17057 17058 /* Expand a MIPS_BUILTIN_DIRECT or MIPS_BUILTIN_DIRECT_NO_TARGET function; 17059 HAS_TARGET_P says which. EXP is the CALL_EXPR that calls the function 17060 and ICODE is the code of the associated .md pattern. TARGET, if nonnull, 17061 suggests a good place to put the result. */ 17062 17063 static rtx 17064 mips_expand_builtin_direct (enum insn_code icode, rtx target, tree exp, 17065 bool has_target_p) 17066 { 17067 struct expand_operand ops[MAX_RECOG_OPERANDS]; 17068 int opno, argno; 17069 17070 /* Map any target to operand 0. */ 17071 opno = 0; 17072 if (has_target_p) 17073 create_output_operand (&ops[opno++], target, TYPE_MODE (TREE_TYPE (exp))); 17074 17075 /* Map the arguments to the other operands. */ 17076 gcc_assert (opno + call_expr_nargs (exp) 17077 == insn_data[icode].n_generator_args); 17078 for (argno = 0; argno < call_expr_nargs (exp); argno++) 17079 mips_prepare_builtin_arg (&ops[opno++], exp, argno); 17080 17081 return mips_expand_builtin_insn (icode, opno, ops, has_target_p); 17082 } 17083 17084 /* Expand a __builtin_mips_movt_*_ps or __builtin_mips_movf_*_ps 17085 function; TYPE says which. EXP is the CALL_EXPR that calls the 17086 function, ICODE is the instruction that should be used to compare 17087 the first two arguments, and COND is the condition it should test. 17088 TARGET, if nonnull, suggests a good place to put the result. */ 17089 17090 static rtx 17091 mips_expand_builtin_movtf (enum mips_builtin_type type, 17092 enum insn_code icode, enum mips_fp_condition cond, 17093 rtx target, tree exp) 17094 { 17095 struct expand_operand ops[4]; 17096 rtx cmp_result; 17097 17098 cmp_result = mips_expand_builtin_compare_1 (icode, cond, exp, 2); 17099 create_output_operand (&ops[0], target, TYPE_MODE (TREE_TYPE (exp))); 17100 if (type == MIPS_BUILTIN_MOVT) 17101 { 17102 mips_prepare_builtin_arg (&ops[2], exp, 2); 17103 mips_prepare_builtin_arg (&ops[1], exp, 3); 17104 } 17105 else 17106 { 17107 mips_prepare_builtin_arg (&ops[1], exp, 2); 17108 mips_prepare_builtin_arg (&ops[2], exp, 3); 17109 } 17110 create_fixed_operand (&ops[3], cmp_result); 17111 return mips_expand_builtin_insn (CODE_FOR_mips_cond_move_tf_ps, 17112 4, ops, true); 17113 } 17114 17115 /* Expand an MSA built-in for a compare and branch instruction specified by 17116 ICODE, set a general-purpose register to 1 if the branch was taken, 17117 0 otherwise. */ 17118 17119 static rtx 17120 mips_expand_builtin_msa_test_branch (enum insn_code icode, tree exp) 17121 { 17122 struct expand_operand ops[3]; 17123 rtx_insn *cbranch; 17124 rtx_code_label *true_label, *done_label; 17125 rtx cmp_result; 17126 17127 true_label = gen_label_rtx (); 17128 done_label = gen_label_rtx (); 17129 17130 create_input_operand (&ops[0], true_label, TYPE_MODE (TREE_TYPE (exp))); 17131 mips_prepare_builtin_arg (&ops[1], exp, 0); 17132 create_fixed_operand (&ops[2], const0_rtx); 17133 17134 /* Make sure that the operand 1 is a REG. */ 17135 if (GET_CODE (ops[1].value) != REG) 17136 ops[1].value = force_reg (ops[1].mode, ops[1].value); 17137 17138 if ((cbranch = maybe_gen_insn (icode, 3, ops)) == NULL_RTX) 17139 error ("failed to expand built-in function"); 17140 17141 cmp_result = gen_reg_rtx (SImode); 17142 17143 /* First assume that CMP_RESULT is false. */ 17144 mips_emit_move (cmp_result, const0_rtx); 17145 17146 /* Branch to TRUE_LABEL if CBRANCH is taken and DONE_LABEL otherwise. */ 17147 emit_jump_insn (cbranch); 17148 emit_jump_insn (gen_jump (done_label)); 17149 emit_barrier (); 17150 17151 /* Set CMP_RESULT to true if the branch was taken. */ 17152 emit_label (true_label); 17153 mips_emit_move (cmp_result, const1_rtx); 17154 17155 emit_label (done_label); 17156 return cmp_result; 17157 } 17158 17159 /* Move VALUE_IF_TRUE into TARGET if CONDITION is true; move VALUE_IF_FALSE 17160 into TARGET otherwise. Return TARGET. */ 17161 17162 static rtx 17163 mips_builtin_branch_and_move (rtx condition, rtx target, 17164 rtx value_if_true, rtx value_if_false) 17165 { 17166 rtx_code_label *true_label, *done_label; 17167 17168 true_label = gen_label_rtx (); 17169 done_label = gen_label_rtx (); 17170 17171 /* First assume that CONDITION is false. */ 17172 mips_emit_move (target, value_if_false); 17173 17174 /* Branch to TRUE_LABEL if CONDITION is true and DONE_LABEL otherwise. */ 17175 emit_jump_insn (gen_condjump (condition, true_label)); 17176 emit_jump_insn (gen_jump (done_label)); 17177 emit_barrier (); 17178 17179 /* Fix TARGET if CONDITION is true. */ 17180 emit_label (true_label); 17181 mips_emit_move (target, value_if_true); 17182 17183 emit_label (done_label); 17184 return target; 17185 } 17186 17187 /* Expand a comparison built-in function of type BUILTIN_TYPE. EXP is 17188 the CALL_EXPR that calls the function, ICODE is the code of the 17189 comparison instruction, and COND is the condition it should test. 17190 TARGET, if nonnull, suggests a good place to put the boolean result. */ 17191 17192 static rtx 17193 mips_expand_builtin_compare (enum mips_builtin_type builtin_type, 17194 enum insn_code icode, enum mips_fp_condition cond, 17195 rtx target, tree exp) 17196 { 17197 rtx offset, condition, cmp_result; 17198 17199 if (target == 0 || GET_MODE (target) != SImode) 17200 target = gen_reg_rtx (SImode); 17201 cmp_result = mips_expand_builtin_compare_1 (icode, cond, exp, 17202 call_expr_nargs (exp)); 17203 17204 /* If the comparison sets more than one register, we define the result 17205 to be 0 if all registers are false and -1 if all registers are true. 17206 The value of the complete result is indeterminate otherwise. */ 17207 switch (builtin_type) 17208 { 17209 case MIPS_BUILTIN_CMP_ALL: 17210 condition = gen_rtx_NE (VOIDmode, cmp_result, constm1_rtx); 17211 return mips_builtin_branch_and_move (condition, target, 17212 const0_rtx, const1_rtx); 17213 17214 case MIPS_BUILTIN_CMP_UPPER: 17215 case MIPS_BUILTIN_CMP_LOWER: 17216 offset = GEN_INT (builtin_type == MIPS_BUILTIN_CMP_UPPER); 17217 condition = gen_single_cc (cmp_result, offset); 17218 return mips_builtin_branch_and_move (condition, target, 17219 const1_rtx, const0_rtx); 17220 17221 default: 17222 condition = gen_rtx_NE (VOIDmode, cmp_result, const0_rtx); 17223 return mips_builtin_branch_and_move (condition, target, 17224 const1_rtx, const0_rtx); 17225 } 17226 } 17227 17228 /* Expand a bposge built-in function of type BUILTIN_TYPE. TARGET, 17229 if nonnull, suggests a good place to put the boolean result. */ 17230 17231 static rtx 17232 mips_expand_builtin_bposge (enum mips_builtin_type builtin_type, rtx target) 17233 { 17234 rtx condition, cmp_result; 17235 int cmp_value; 17236 17237 if (target == 0 || GET_MODE (target) != SImode) 17238 target = gen_reg_rtx (SImode); 17239 17240 cmp_result = gen_rtx_REG (CCDSPmode, CCDSP_PO_REGNUM); 17241 17242 if (builtin_type == MIPS_BUILTIN_BPOSGE32) 17243 cmp_value = 32; 17244 else 17245 gcc_assert (0); 17246 17247 condition = gen_rtx_GE (VOIDmode, cmp_result, GEN_INT (cmp_value)); 17248 return mips_builtin_branch_and_move (condition, target, 17249 const1_rtx, const0_rtx); 17250 } 17251 17252 /* Implement TARGET_EXPAND_BUILTIN. */ 17253 17254 static rtx 17255 mips_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED, 17256 machine_mode mode, int ignore) 17257 { 17258 tree fndecl; 17259 unsigned int fcode, avail; 17260 const struct mips_builtin_description *d; 17261 17262 fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0); 17263 fcode = DECL_MD_FUNCTION_CODE (fndecl); 17264 gcc_assert (fcode < ARRAY_SIZE (mips_builtins)); 17265 d = &mips_builtins[fcode]; 17266 avail = d->avail (); 17267 gcc_assert (avail != 0); 17268 if (TARGET_MIPS16 && !(avail & BUILTIN_AVAIL_MIPS16)) 17269 { 17270 error ("built-in function %qE not supported for MIPS16", 17271 DECL_NAME (fndecl)); 17272 return ignore ? const0_rtx : CONST0_RTX (mode); 17273 } 17274 switch (d->builtin_type) 17275 { 17276 case MIPS_BUILTIN_DIRECT: 17277 return mips_expand_builtin_direct (d->icode, target, exp, true); 17278 17279 case MIPS_BUILTIN_DIRECT_NO_TARGET: 17280 return mips_expand_builtin_direct (d->icode, target, exp, false); 17281 17282 case MIPS_BUILTIN_MOVT: 17283 case MIPS_BUILTIN_MOVF: 17284 return mips_expand_builtin_movtf (d->builtin_type, d->icode, 17285 d->cond, target, exp); 17286 17287 case MIPS_BUILTIN_CMP_ANY: 17288 case MIPS_BUILTIN_CMP_ALL: 17289 case MIPS_BUILTIN_CMP_UPPER: 17290 case MIPS_BUILTIN_CMP_LOWER: 17291 case MIPS_BUILTIN_CMP_SINGLE: 17292 return mips_expand_builtin_compare (d->builtin_type, d->icode, 17293 d->cond, target, exp); 17294 17295 case MIPS_BUILTIN_MSA_TEST_BRANCH: 17296 return mips_expand_builtin_msa_test_branch (d->icode, exp); 17297 17298 case MIPS_BUILTIN_BPOSGE32: 17299 return mips_expand_builtin_bposge (d->builtin_type, target); 17300 } 17301 gcc_unreachable (); 17302 } 17303 17304 /* An entry in the MIPS16 constant pool. VALUE is the pool constant, 17305 MODE is its mode, and LABEL is the CODE_LABEL associated with it. */ 17306 struct mips16_constant { 17307 struct mips16_constant *next; 17308 rtx value; 17309 rtx_code_label *label; 17310 machine_mode mode; 17311 }; 17312 17313 /* Information about an incomplete MIPS16 constant pool. FIRST is the 17314 first constant, HIGHEST_ADDRESS is the highest address that the first 17315 byte of the pool can have, and INSN_ADDRESS is the current instruction 17316 address. */ 17317 struct mips16_constant_pool { 17318 struct mips16_constant *first; 17319 int highest_address; 17320 int insn_address; 17321 }; 17322 17323 /* Add constant VALUE to POOL and return its label. MODE is the 17324 value's mode (used for CONST_INTs, etc.). */ 17325 17326 static rtx_code_label * 17327 mips16_add_constant (struct mips16_constant_pool *pool, 17328 rtx value, machine_mode mode) 17329 { 17330 struct mips16_constant **p, *c; 17331 bool first_of_size_p; 17332 17333 /* See whether the constant is already in the pool. If so, return the 17334 existing label, otherwise leave P pointing to the place where the 17335 constant should be added. 17336 17337 Keep the pool sorted in increasing order of mode size so that we can 17338 reduce the number of alignments needed. */ 17339 first_of_size_p = true; 17340 for (p = &pool->first; *p != 0; p = &(*p)->next) 17341 { 17342 if (mode == (*p)->mode && rtx_equal_p (value, (*p)->value)) 17343 return (*p)->label; 17344 if (GET_MODE_SIZE (mode) < GET_MODE_SIZE ((*p)->mode)) 17345 break; 17346 if (GET_MODE_SIZE (mode) == GET_MODE_SIZE ((*p)->mode)) 17347 first_of_size_p = false; 17348 } 17349 17350 /* In the worst case, the constant needed by the earliest instruction 17351 will end up at the end of the pool. The entire pool must then be 17352 accessible from that instruction. 17353 17354 When adding the first constant, set the pool's highest address to 17355 the address of the first out-of-range byte. Adjust this address 17356 downwards each time a new constant is added. */ 17357 if (pool->first == 0) 17358 /* For LWPC, ADDIUPC and DADDIUPC, the base PC value is the address 17359 of the instruction with the lowest two bits clear. The base PC 17360 value for LDPC has the lowest three bits clear. Assume the worst 17361 case here; namely that the PC-relative instruction occupies the 17362 last 2 bytes in an aligned word. */ 17363 pool->highest_address = pool->insn_address - (UNITS_PER_WORD - 2) + 0x8000; 17364 pool->highest_address -= GET_MODE_SIZE (mode); 17365 if (first_of_size_p) 17366 /* Take into account the worst possible padding due to alignment. */ 17367 pool->highest_address -= GET_MODE_SIZE (mode) - 1; 17368 17369 /* Create a new entry. */ 17370 c = XNEW (struct mips16_constant); 17371 c->value = value; 17372 c->mode = mode; 17373 c->label = gen_label_rtx (); 17374 c->next = *p; 17375 *p = c; 17376 17377 return c->label; 17378 } 17379 17380 /* Output constant VALUE after instruction INSN and return the last 17381 instruction emitted. MODE is the mode of the constant. */ 17382 17383 static rtx_insn * 17384 mips16_emit_constants_1 (machine_mode mode, rtx value, rtx_insn *insn) 17385 { 17386 if (SCALAR_INT_MODE_P (mode) || ALL_SCALAR_FIXED_POINT_MODE_P (mode)) 17387 { 17388 rtx size = GEN_INT (GET_MODE_SIZE (mode)); 17389 return emit_insn_after (gen_consttable_int (value, size), insn); 17390 } 17391 17392 if (SCALAR_FLOAT_MODE_P (mode)) 17393 return emit_insn_after (gen_consttable_float (value), insn); 17394 17395 if (VECTOR_MODE_P (mode)) 17396 { 17397 int i; 17398 17399 for (i = 0; i < CONST_VECTOR_NUNITS (value); i++) 17400 insn = mips16_emit_constants_1 (GET_MODE_INNER (mode), 17401 CONST_VECTOR_ELT (value, i), insn); 17402 return insn; 17403 } 17404 17405 gcc_unreachable (); 17406 } 17407 17408 /* Dump out the constants in CONSTANTS after INSN. Record the initial 17409 label number in the `consttable' and `consttable_end' insns emitted 17410 at the beginning and the end of the constant pool respectively, so 17411 that individual pools can be uniquely marked as data for the purpose 17412 of disassembly. */ 17413 17414 static void 17415 mips16_emit_constants (struct mips16_constant *constants, rtx_insn *insn) 17416 { 17417 int label_num = constants ? CODE_LABEL_NUMBER (constants->label) : 0; 17418 struct mips16_constant *c, *next; 17419 int align; 17420 17421 align = 0; 17422 if (constants) 17423 insn = emit_insn_after (gen_consttable (GEN_INT (label_num)), insn); 17424 for (c = constants; c != NULL; c = next) 17425 { 17426 /* If necessary, increase the alignment of PC. */ 17427 if (align < GET_MODE_SIZE (c->mode)) 17428 { 17429 int align_log = floor_log2 (GET_MODE_SIZE (c->mode)); 17430 insn = emit_insn_after (gen_align (GEN_INT (align_log)), insn); 17431 } 17432 align = GET_MODE_SIZE (c->mode); 17433 17434 insn = emit_label_after (c->label, insn); 17435 insn = mips16_emit_constants_1 (c->mode, c->value, insn); 17436 17437 next = c->next; 17438 free (c); 17439 } 17440 if (constants) 17441 insn = emit_insn_after (gen_consttable_end (GEN_INT (label_num)), insn); 17442 17443 emit_barrier_after (insn); 17444 } 17445 17446 /* Return the length of instruction INSN. */ 17447 17448 static int 17449 mips16_insn_length (rtx_insn *insn) 17450 { 17451 if (JUMP_TABLE_DATA_P (insn)) 17452 { 17453 rtx body = PATTERN (insn); 17454 if (GET_CODE (body) == ADDR_VEC) 17455 return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, 0); 17456 else if (GET_CODE (body) == ADDR_DIFF_VEC) 17457 return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, 1); 17458 else 17459 gcc_unreachable (); 17460 } 17461 return get_attr_length (insn); 17462 } 17463 17464 /* If *X is a symbolic constant that refers to the constant pool, add 17465 the constant to POOL and rewrite *X to use the constant's label. */ 17466 17467 static void 17468 mips16_rewrite_pool_constant (struct mips16_constant_pool *pool, rtx *x) 17469 { 17470 rtx base, offset; 17471 rtx_code_label *label; 17472 17473 split_const (*x, &base, &offset); 17474 if (GET_CODE (base) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (base)) 17475 { 17476 label = mips16_add_constant (pool, copy_rtx (get_pool_constant (base)), 17477 get_pool_mode (base)); 17478 base = gen_rtx_LABEL_REF (Pmode, label); 17479 *x = mips_unspec_address_offset (base, offset, SYMBOL_PC_RELATIVE); 17480 } 17481 } 17482 17483 /* Rewrite INSN so that constant pool references refer to the constant's 17484 label instead. */ 17485 17486 static void 17487 mips16_rewrite_pool_refs (rtx_insn *insn, struct mips16_constant_pool *pool) 17488 { 17489 subrtx_ptr_iterator::array_type array; 17490 FOR_EACH_SUBRTX_PTR (iter, array, &PATTERN (insn), ALL) 17491 { 17492 rtx *loc = *iter; 17493 17494 if (force_to_mem_operand (*loc, Pmode)) 17495 { 17496 rtx mem = force_const_mem (GET_MODE (*loc), *loc); 17497 validate_change (insn, loc, mem, false); 17498 } 17499 17500 if (MEM_P (*loc)) 17501 { 17502 mips16_rewrite_pool_constant (pool, &XEXP (*loc, 0)); 17503 iter.skip_subrtxes (); 17504 } 17505 else 17506 { 17507 if (TARGET_MIPS16_TEXT_LOADS) 17508 mips16_rewrite_pool_constant (pool, loc); 17509 if (GET_CODE (*loc) == CONST 17510 /* Don't rewrite the __mips16_rdwr symbol. */ 17511 || (GET_CODE (*loc) == UNSPEC 17512 && XINT (*loc, 1) == UNSPEC_TLS_GET_TP)) 17513 iter.skip_subrtxes (); 17514 } 17515 } 17516 } 17517 17518 /* Return whether CFG is used in mips_reorg. */ 17519 17520 static bool 17521 mips_cfg_in_reorg (void) 17522 { 17523 return (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE 17524 || TARGET_RELAX_PIC_CALLS); 17525 } 17526 17527 /* Build MIPS16 constant pools. Split the instructions if SPLIT_P, 17528 otherwise assume that they are already split. */ 17529 17530 static void 17531 mips16_lay_out_constants (bool split_p) 17532 { 17533 struct mips16_constant_pool pool; 17534 rtx_insn *insn, *barrier; 17535 17536 if (!TARGET_MIPS16_PCREL_LOADS) 17537 return; 17538 17539 if (split_p) 17540 { 17541 if (mips_cfg_in_reorg ()) 17542 split_all_insns (); 17543 else 17544 split_all_insns_noflow (); 17545 } 17546 barrier = 0; 17547 memset (&pool, 0, sizeof (pool)); 17548 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 17549 { 17550 /* Rewrite constant pool references in INSN. */ 17551 if (USEFUL_INSN_P (insn)) 17552 mips16_rewrite_pool_refs (insn, &pool); 17553 17554 pool.insn_address += mips16_insn_length (insn); 17555 17556 if (pool.first != NULL) 17557 { 17558 /* If there are no natural barriers between the first user of 17559 the pool and the highest acceptable address, we'll need to 17560 create a new instruction to jump around the constant pool. 17561 In the worst case, this instruction will be 4 bytes long. 17562 17563 If it's too late to do this transformation after INSN, 17564 do it immediately before INSN. */ 17565 if (barrier == 0 && pool.insn_address + 4 > pool.highest_address) 17566 { 17567 rtx_code_label *label; 17568 rtx_insn *jump; 17569 17570 label = gen_label_rtx (); 17571 17572 jump = emit_jump_insn_before (gen_jump (label), insn); 17573 JUMP_LABEL (jump) = label; 17574 LABEL_NUSES (label) = 1; 17575 barrier = emit_barrier_after (jump); 17576 17577 emit_label_after (label, barrier); 17578 pool.insn_address += 4; 17579 } 17580 17581 /* See whether the constant pool is now out of range of the first 17582 user. If so, output the constants after the previous barrier. 17583 Note that any instructions between BARRIER and INSN (inclusive) 17584 will use negative offsets to refer to the pool. */ 17585 if (pool.insn_address > pool.highest_address) 17586 { 17587 mips16_emit_constants (pool.first, barrier); 17588 pool.first = NULL; 17589 barrier = 0; 17590 } 17591 else if (BARRIER_P (insn)) 17592 barrier = insn; 17593 } 17594 } 17595 mips16_emit_constants (pool.first, get_last_insn ()); 17596 } 17597 17598 /* Return true if it is worth r10k_simplify_address's while replacing 17599 an address with X. We are looking for constants, and for addresses 17600 at a known offset from the incoming stack pointer. */ 17601 17602 static bool 17603 r10k_simplified_address_p (rtx x) 17604 { 17605 if (GET_CODE (x) == PLUS && CONST_INT_P (XEXP (x, 1))) 17606 x = XEXP (x, 0); 17607 return x == virtual_incoming_args_rtx || CONSTANT_P (x); 17608 } 17609 17610 /* X is an expression that appears in INSN. Try to use the UD chains 17611 to simplify it, returning the simplified form on success and the 17612 original form otherwise. Replace the incoming value of $sp with 17613 virtual_incoming_args_rtx (which should never occur in X otherwise). */ 17614 17615 static rtx 17616 r10k_simplify_address (rtx x, rtx_insn *insn) 17617 { 17618 rtx newx, op0, op1, set, note; 17619 rtx_insn *def_insn; 17620 df_ref use, def; 17621 struct df_link *defs; 17622 17623 newx = NULL_RTX; 17624 if (UNARY_P (x)) 17625 { 17626 op0 = r10k_simplify_address (XEXP (x, 0), insn); 17627 if (op0 != XEXP (x, 0)) 17628 newx = simplify_gen_unary (GET_CODE (x), GET_MODE (x), 17629 op0, GET_MODE (XEXP (x, 0))); 17630 } 17631 else if (BINARY_P (x)) 17632 { 17633 op0 = r10k_simplify_address (XEXP (x, 0), insn); 17634 op1 = r10k_simplify_address (XEXP (x, 1), insn); 17635 if (op0 != XEXP (x, 0) || op1 != XEXP (x, 1)) 17636 newx = simplify_gen_binary (GET_CODE (x), GET_MODE (x), op0, op1); 17637 } 17638 else if (GET_CODE (x) == LO_SUM) 17639 { 17640 /* LO_SUMs can be offset from HIGHs, if we know they won't 17641 overflow. See mips_classify_address for the rationale behind 17642 the lax check. */ 17643 op0 = r10k_simplify_address (XEXP (x, 0), insn); 17644 if (GET_CODE (op0) == HIGH) 17645 newx = XEXP (x, 1); 17646 } 17647 else if (REG_P (x)) 17648 { 17649 /* Uses are recorded by regno_reg_rtx, not X itself. */ 17650 use = df_find_use (insn, regno_reg_rtx[REGNO (x)]); 17651 gcc_assert (use); 17652 defs = DF_REF_CHAIN (use); 17653 17654 /* Require a single definition. */ 17655 if (defs && defs->next == NULL) 17656 { 17657 def = defs->ref; 17658 if (DF_REF_IS_ARTIFICIAL (def)) 17659 { 17660 /* Replace the incoming value of $sp with 17661 virtual_incoming_args_rtx. */ 17662 if (x == stack_pointer_rtx 17663 && DF_REF_BB (def) == ENTRY_BLOCK_PTR_FOR_FN (cfun)) 17664 newx = virtual_incoming_args_rtx; 17665 } 17666 else if (dominated_by_p (CDI_DOMINATORS, DF_REF_BB (use), 17667 DF_REF_BB (def))) 17668 { 17669 /* Make sure that DEF_INSN is a single set of REG. */ 17670 def_insn = DF_REF_INSN (def); 17671 if (NONJUMP_INSN_P (def_insn)) 17672 { 17673 set = single_set (def_insn); 17674 if (set && rtx_equal_p (SET_DEST (set), x)) 17675 { 17676 /* Prefer to use notes, since the def-use chains 17677 are often shorter. */ 17678 note = find_reg_equal_equiv_note (def_insn); 17679 if (note) 17680 newx = XEXP (note, 0); 17681 else 17682 newx = SET_SRC (set); 17683 newx = r10k_simplify_address (newx, def_insn); 17684 } 17685 } 17686 } 17687 } 17688 } 17689 if (newx && r10k_simplified_address_p (newx)) 17690 return newx; 17691 return x; 17692 } 17693 17694 /* Return true if ADDRESS is known to be an uncached address 17695 on R10K systems. */ 17696 17697 static bool 17698 r10k_uncached_address_p (unsigned HOST_WIDE_INT address) 17699 { 17700 unsigned HOST_WIDE_INT upper; 17701 17702 /* Check for KSEG1. */ 17703 if (address + 0x60000000 < 0x20000000) 17704 return true; 17705 17706 /* Check for uncached XKPHYS addresses. */ 17707 if (Pmode == DImode) 17708 { 17709 upper = (address >> 40) & 0xf9ffff; 17710 if (upper == 0x900000 || upper == 0xb80000) 17711 return true; 17712 } 17713 return false; 17714 } 17715 17716 /* Return true if we can prove that an access to address X in instruction 17717 INSN would be safe from R10K speculation. This X is a general 17718 expression; it might not be a legitimate address. */ 17719 17720 static bool 17721 r10k_safe_address_p (rtx x, rtx_insn *insn) 17722 { 17723 rtx base, offset; 17724 HOST_WIDE_INT offset_val; 17725 17726 x = r10k_simplify_address (x, insn); 17727 17728 /* Check for references to the stack frame. It doesn't really matter 17729 how much of the frame has been allocated at INSN; -mr10k-cache-barrier 17730 allows us to assume that accesses to any part of the eventual frame 17731 is safe from speculation at any point in the function. */ 17732 mips_split_plus (x, &base, &offset_val); 17733 if (base == virtual_incoming_args_rtx 17734 && offset_val >= -cfun->machine->frame.total_size 17735 && offset_val < cfun->machine->frame.args_size) 17736 return true; 17737 17738 /* Check for uncached addresses. */ 17739 if (CONST_INT_P (x)) 17740 return r10k_uncached_address_p (INTVAL (x)); 17741 17742 /* Check for accesses to a static object. */ 17743 split_const (x, &base, &offset); 17744 return offset_within_block_p (base, INTVAL (offset)); 17745 } 17746 17747 /* Return true if a MEM with MEM_EXPR EXPR and MEM_OFFSET OFFSET is 17748 an in-range access to an automatic variable, or to an object with 17749 a link-time-constant address. */ 17750 17751 static bool 17752 r10k_safe_mem_expr_p (tree expr, unsigned HOST_WIDE_INT offset) 17753 { 17754 poly_int64 bitoffset, bitsize; 17755 tree inner, var_offset; 17756 machine_mode mode; 17757 int unsigned_p, reverse_p, volatile_p; 17758 17759 inner = get_inner_reference (expr, &bitsize, &bitoffset, &var_offset, &mode, 17760 &unsigned_p, &reverse_p, &volatile_p); 17761 if (!DECL_P (inner) || !DECL_SIZE_UNIT (inner) || var_offset) 17762 return false; 17763 17764 offset += bitoffset / BITS_PER_UNIT; 17765 return offset < tree_to_uhwi (DECL_SIZE_UNIT (inner)); 17766 } 17767 17768 /* Return true if X contains a MEM that is not safe from R10K speculation. 17769 INSN is the instruction that contains X. */ 17770 17771 static bool 17772 r10k_needs_protection_p_1 (rtx x, rtx_insn *insn) 17773 { 17774 subrtx_var_iterator::array_type array; 17775 FOR_EACH_SUBRTX_VAR (iter, array, x, NONCONST) 17776 { 17777 rtx mem = *iter; 17778 if (MEM_P (mem)) 17779 { 17780 if ((MEM_EXPR (mem) 17781 && MEM_OFFSET_KNOWN_P (mem) 17782 && r10k_safe_mem_expr_p (MEM_EXPR (mem), MEM_OFFSET (mem))) 17783 || r10k_safe_address_p (XEXP (mem, 0), insn)) 17784 iter.skip_subrtxes (); 17785 else 17786 return true; 17787 } 17788 } 17789 return false; 17790 } 17791 17792 /* A note_stores callback for which DATA points to an instruction pointer. 17793 If *DATA is nonnull, make it null if it X contains a MEM that is not 17794 safe from R10K speculation. */ 17795 17796 static void 17797 r10k_needs_protection_p_store (rtx x, const_rtx pat ATTRIBUTE_UNUSED, 17798 void *data) 17799 { 17800 rtx_insn **insn_ptr; 17801 17802 insn_ptr = (rtx_insn **) data; 17803 if (*insn_ptr && r10k_needs_protection_p_1 (x, *insn_ptr)) 17804 *insn_ptr = NULL; 17805 } 17806 17807 /* X is the pattern of a call instruction. Return true if the call is 17808 not to a declared function. */ 17809 17810 static bool 17811 r10k_needs_protection_p_call (const_rtx x) 17812 { 17813 subrtx_iterator::array_type array; 17814 FOR_EACH_SUBRTX (iter, array, x, NONCONST) 17815 { 17816 const_rtx mem = *iter; 17817 if (MEM_P (mem)) 17818 { 17819 const_rtx addr = XEXP (mem, 0); 17820 if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DECL (addr)) 17821 iter.skip_subrtxes (); 17822 else 17823 return true; 17824 } 17825 } 17826 return false; 17827 } 17828 17829 /* Return true if instruction INSN needs to be protected by an R10K 17830 cache barrier. */ 17831 17832 static bool 17833 r10k_needs_protection_p (rtx_insn *insn) 17834 { 17835 if (CALL_P (insn)) 17836 return r10k_needs_protection_p_call (PATTERN (insn)); 17837 17838 if (mips_r10k_cache_barrier == R10K_CACHE_BARRIER_STORE) 17839 { 17840 note_stores (insn, r10k_needs_protection_p_store, &insn); 17841 return insn == NULL_RTX; 17842 } 17843 17844 return r10k_needs_protection_p_1 (PATTERN (insn), insn); 17845 } 17846 17847 /* Return true if BB is only reached by blocks in PROTECTED_BBS and if every 17848 edge is unconditional. */ 17849 17850 static bool 17851 r10k_protected_bb_p (basic_block bb, sbitmap protected_bbs) 17852 { 17853 edge_iterator ei; 17854 edge e; 17855 17856 FOR_EACH_EDGE (e, ei, bb->preds) 17857 if (!single_succ_p (e->src) 17858 || !bitmap_bit_p (protected_bbs, e->src->index) 17859 || (e->flags & EDGE_COMPLEX) != 0) 17860 return false; 17861 return true; 17862 } 17863 17864 /* Implement -mr10k-cache-barrier= for the current function. */ 17865 17866 static void 17867 r10k_insert_cache_barriers (void) 17868 { 17869 int *rev_post_order; 17870 unsigned int i, n; 17871 basic_block bb; 17872 sbitmap protected_bbs; 17873 rtx_insn *insn, *end; 17874 rtx unprotected_region; 17875 17876 if (TARGET_MIPS16) 17877 { 17878 sorry ("%qs does not support MIPS16 code", "-mr10k-cache-barrier"); 17879 return; 17880 } 17881 17882 /* Calculate dominators. */ 17883 calculate_dominance_info (CDI_DOMINATORS); 17884 17885 /* Bit X of PROTECTED_BBS is set if the last operation in basic block 17886 X is protected by a cache barrier. */ 17887 protected_bbs = sbitmap_alloc (last_basic_block_for_fn (cfun)); 17888 bitmap_clear (protected_bbs); 17889 17890 /* Iterate over the basic blocks in reverse post-order. */ 17891 rev_post_order = XNEWVEC (int, last_basic_block_for_fn (cfun)); 17892 n = pre_and_rev_post_order_compute (NULL, rev_post_order, false); 17893 for (i = 0; i < n; i++) 17894 { 17895 bb = BASIC_BLOCK_FOR_FN (cfun, rev_post_order[i]); 17896 17897 /* If this block is only reached by unconditional edges, and if the 17898 source of every edge is protected, the beginning of the block is 17899 also protected. */ 17900 if (r10k_protected_bb_p (bb, protected_bbs)) 17901 unprotected_region = NULL_RTX; 17902 else 17903 unprotected_region = pc_rtx; 17904 end = NEXT_INSN (BB_END (bb)); 17905 17906 /* UNPROTECTED_REGION is: 17907 17908 - null if we are processing a protected region, 17909 - pc_rtx if we are processing an unprotected region but have 17910 not yet found the first instruction in it 17911 - the first instruction in an unprotected region otherwise. */ 17912 for (insn = BB_HEAD (bb); insn != end; insn = NEXT_INSN (insn)) 17913 { 17914 if (unprotected_region && USEFUL_INSN_P (insn)) 17915 { 17916 if (recog_memoized (insn) == CODE_FOR_mips_cache) 17917 /* This CACHE instruction protects the following code. */ 17918 unprotected_region = NULL_RTX; 17919 else 17920 { 17921 /* See if INSN is the first instruction in this 17922 unprotected region. */ 17923 if (unprotected_region == pc_rtx) 17924 unprotected_region = insn; 17925 17926 /* See if INSN needs to be protected. If so, 17927 we must insert a cache barrier somewhere between 17928 PREV_INSN (UNPROTECTED_REGION) and INSN. It isn't 17929 clear which position is better performance-wise, 17930 but as a tie-breaker, we assume that it is better 17931 to allow delay slots to be back-filled where 17932 possible, and that it is better not to insert 17933 barriers in the middle of already-scheduled code. 17934 We therefore insert the barrier at the beginning 17935 of the region. */ 17936 if (r10k_needs_protection_p (insn)) 17937 { 17938 emit_insn_before (gen_r10k_cache_barrier (), 17939 as_a <rtx_insn *> (unprotected_region)); 17940 unprotected_region = NULL_RTX; 17941 } 17942 } 17943 } 17944 17945 if (CALL_P (insn)) 17946 /* The called function is not required to protect the exit path. 17947 The code that follows a call is therefore unprotected. */ 17948 unprotected_region = pc_rtx; 17949 } 17950 17951 /* Record whether the end of this block is protected. */ 17952 if (unprotected_region == NULL_RTX) 17953 bitmap_set_bit (protected_bbs, bb->index); 17954 } 17955 XDELETEVEC (rev_post_order); 17956 17957 sbitmap_free (protected_bbs); 17958 17959 free_dominance_info (CDI_DOMINATORS); 17960 } 17961 17962 /* If INSN is a call, return the underlying CALL expr. Return NULL_RTX 17963 otherwise. If INSN has two call rtx, then store the second one in 17964 SECOND_CALL. */ 17965 17966 static rtx 17967 mips_call_expr_from_insn (rtx_insn *insn, rtx *second_call) 17968 { 17969 rtx x; 17970 rtx x2; 17971 17972 if (!CALL_P (insn)) 17973 return NULL_RTX; 17974 17975 x = PATTERN (insn); 17976 if (GET_CODE (x) == PARALLEL) 17977 { 17978 /* Calls returning complex values have two CALL rtx. Look for the second 17979 one here, and return it via the SECOND_CALL arg. */ 17980 x2 = XVECEXP (x, 0, 1); 17981 if (GET_CODE (x2) == SET) 17982 x2 = XEXP (x2, 1); 17983 if (GET_CODE (x2) == CALL) 17984 *second_call = x2; 17985 17986 x = XVECEXP (x, 0, 0); 17987 } 17988 if (GET_CODE (x) == SET) 17989 x = XEXP (x, 1); 17990 gcc_assert (GET_CODE (x) == CALL); 17991 17992 return x; 17993 } 17994 17995 /* REG is set in DEF. See if the definition is one of the ways we load a 17996 register with a symbol address for a mips_use_pic_fn_addr_reg_p call. 17997 If it is, return the symbol reference of the function, otherwise return 17998 NULL_RTX. 17999 18000 If RECURSE_P is true, use mips_find_pic_call_symbol to interpret 18001 the values of source registers, otherwise treat such registers as 18002 having an unknown value. */ 18003 18004 static rtx 18005 mips_pic_call_symbol_from_set (df_ref def, rtx reg, bool recurse_p) 18006 { 18007 rtx_insn *def_insn; 18008 rtx set; 18009 18010 if (DF_REF_IS_ARTIFICIAL (def)) 18011 return NULL_RTX; 18012 18013 def_insn = DF_REF_INSN (def); 18014 set = single_set (def_insn); 18015 if (set && rtx_equal_p (SET_DEST (set), reg)) 18016 { 18017 rtx note, src, symbol; 18018 18019 /* First see whether the source is a plain symbol. This is used 18020 when calling symbols that are not lazily bound. */ 18021 src = SET_SRC (set); 18022 if (GET_CODE (src) == SYMBOL_REF) 18023 return src; 18024 18025 /* Handle %call16 references. */ 18026 symbol = mips_strip_unspec_call (src); 18027 if (symbol) 18028 { 18029 gcc_assert (GET_CODE (symbol) == SYMBOL_REF); 18030 return symbol; 18031 } 18032 18033 /* If we have something more complicated, look for a 18034 REG_EQUAL or REG_EQUIV note. */ 18035 note = find_reg_equal_equiv_note (def_insn); 18036 if (note && GET_CODE (XEXP (note, 0)) == SYMBOL_REF) 18037 return XEXP (note, 0); 18038 18039 /* Follow at most one simple register copy. Such copies are 18040 interesting in cases like: 18041 18042 for (...) 18043 { 18044 locally_binding_fn (...); 18045 } 18046 18047 and: 18048 18049 locally_binding_fn (...); 18050 ... 18051 locally_binding_fn (...); 18052 18053 where the load of locally_binding_fn can legitimately be 18054 hoisted or shared. However, we do not expect to see complex 18055 chains of copies, so a full worklist solution to the problem 18056 would probably be overkill. */ 18057 if (recurse_p && REG_P (src)) 18058 return mips_find_pic_call_symbol (def_insn, src, false); 18059 } 18060 18061 return NULL_RTX; 18062 } 18063 18064 /* Find the definition of the use of REG in INSN. See if the definition 18065 is one of the ways we load a register with a symbol address for a 18066 mips_use_pic_fn_addr_reg_p call. If it is return the symbol reference 18067 of the function, otherwise return NULL_RTX. RECURSE_P is as for 18068 mips_pic_call_symbol_from_set. */ 18069 18070 static rtx 18071 mips_find_pic_call_symbol (rtx_insn *insn, rtx reg, bool recurse_p) 18072 { 18073 df_ref use; 18074 struct df_link *defs; 18075 rtx symbol; 18076 18077 use = df_find_use (insn, regno_reg_rtx[REGNO (reg)]); 18078 if (!use) 18079 return NULL_RTX; 18080 defs = DF_REF_CHAIN (use); 18081 if (!defs) 18082 return NULL_RTX; 18083 symbol = mips_pic_call_symbol_from_set (defs->ref, reg, recurse_p); 18084 if (!symbol) 18085 return NULL_RTX; 18086 18087 /* If we have more than one definition, they need to be identical. */ 18088 for (defs = defs->next; defs; defs = defs->next) 18089 { 18090 rtx other; 18091 18092 other = mips_pic_call_symbol_from_set (defs->ref, reg, recurse_p); 18093 if (!rtx_equal_p (symbol, other)) 18094 return NULL_RTX; 18095 } 18096 18097 return symbol; 18098 } 18099 18100 /* Replace the args_size operand of the call expression CALL with the 18101 call-attribute UNSPEC and fill in SYMBOL as the function symbol. */ 18102 18103 static void 18104 mips_annotate_pic_call_expr (rtx call, rtx symbol) 18105 { 18106 rtx args_size; 18107 18108 args_size = XEXP (call, 1); 18109 XEXP (call, 1) = gen_rtx_UNSPEC (GET_MODE (args_size), 18110 gen_rtvec (2, args_size, symbol), 18111 UNSPEC_CALL_ATTR); 18112 } 18113 18114 /* OPERANDS[ARGS_SIZE_OPNO] is the arg_size operand of a CALL expression. See 18115 if instead of the arg_size argument it contains the call attributes. If 18116 yes return true along with setting OPERANDS[ARGS_SIZE_OPNO] to the function 18117 symbol from the call attributes. Also return false if ARGS_SIZE_OPNO is 18118 -1. */ 18119 18120 bool 18121 mips_get_pic_call_symbol (rtx *operands, int args_size_opno) 18122 { 18123 rtx args_size, symbol; 18124 18125 if (!TARGET_RELAX_PIC_CALLS || args_size_opno == -1) 18126 return false; 18127 18128 args_size = operands[args_size_opno]; 18129 if (GET_CODE (args_size) != UNSPEC) 18130 return false; 18131 gcc_assert (XINT (args_size, 1) == UNSPEC_CALL_ATTR); 18132 18133 symbol = XVECEXP (args_size, 0, 1); 18134 gcc_assert (GET_CODE (symbol) == SYMBOL_REF); 18135 18136 operands[args_size_opno] = symbol; 18137 return true; 18138 } 18139 18140 /* Use DF to annotate PIC indirect calls with the function symbol they 18141 dispatch to. */ 18142 18143 static void 18144 mips_annotate_pic_calls (void) 18145 { 18146 basic_block bb; 18147 rtx_insn *insn; 18148 18149 FOR_EACH_BB_FN (bb, cfun) 18150 FOR_BB_INSNS (bb, insn) 18151 { 18152 rtx call, reg, symbol, second_call; 18153 18154 second_call = 0; 18155 call = mips_call_expr_from_insn (insn, &second_call); 18156 if (!call) 18157 continue; 18158 gcc_assert (MEM_P (XEXP (call, 0))); 18159 reg = XEXP (XEXP (call, 0), 0); 18160 if (!REG_P (reg)) 18161 continue; 18162 18163 symbol = mips_find_pic_call_symbol (insn, reg, true); 18164 if (symbol) 18165 { 18166 mips_annotate_pic_call_expr (call, symbol); 18167 if (second_call) 18168 mips_annotate_pic_call_expr (second_call, symbol); 18169 } 18170 } 18171 } 18172 18173 /* A temporary variable used by note_uses callbacks, etc. */ 18174 static rtx_insn *mips_sim_insn; 18175 18176 /* A structure representing the state of the processor pipeline. 18177 Used by the mips_sim_* family of functions. */ 18178 struct mips_sim { 18179 /* The maximum number of instructions that can be issued in a cycle. 18180 (Caches mips_issue_rate.) */ 18181 unsigned int issue_rate; 18182 18183 /* The current simulation time. */ 18184 unsigned int time; 18185 18186 /* How many more instructions can be issued in the current cycle. */ 18187 unsigned int insns_left; 18188 18189 /* LAST_SET[X].INSN is the last instruction to set register X. 18190 LAST_SET[X].TIME is the time at which that instruction was issued. 18191 INSN is null if no instruction has yet set register X. */ 18192 struct { 18193 rtx_insn *insn; 18194 unsigned int time; 18195 } last_set[FIRST_PSEUDO_REGISTER]; 18196 18197 /* The pipeline's current DFA state. */ 18198 state_t dfa_state; 18199 }; 18200 18201 /* Reset STATE to the initial simulation state. */ 18202 18203 static void 18204 mips_sim_reset (struct mips_sim *state) 18205 { 18206 curr_state = state->dfa_state; 18207 18208 state->time = 0; 18209 state->insns_left = state->issue_rate; 18210 memset (&state->last_set, 0, sizeof (state->last_set)); 18211 state_reset (curr_state); 18212 18213 targetm.sched.init (0, false, 0); 18214 advance_state (curr_state); 18215 } 18216 18217 /* Initialize STATE before its first use. DFA_STATE points to an 18218 allocated but uninitialized DFA state. */ 18219 18220 static void 18221 mips_sim_init (struct mips_sim *state, state_t dfa_state) 18222 { 18223 if (targetm.sched.init_dfa_pre_cycle_insn) 18224 targetm.sched.init_dfa_pre_cycle_insn (); 18225 18226 if (targetm.sched.init_dfa_post_cycle_insn) 18227 targetm.sched.init_dfa_post_cycle_insn (); 18228 18229 state->issue_rate = mips_issue_rate (); 18230 state->dfa_state = dfa_state; 18231 mips_sim_reset (state); 18232 } 18233 18234 /* Advance STATE by one clock cycle. */ 18235 18236 static void 18237 mips_sim_next_cycle (struct mips_sim *state) 18238 { 18239 curr_state = state->dfa_state; 18240 18241 state->time++; 18242 state->insns_left = state->issue_rate; 18243 advance_state (curr_state); 18244 } 18245 18246 /* Advance simulation state STATE until instruction INSN can read 18247 register REG. */ 18248 18249 static void 18250 mips_sim_wait_reg (struct mips_sim *state, rtx_insn *insn, rtx reg) 18251 { 18252 unsigned int regno, end_regno; 18253 18254 end_regno = END_REGNO (reg); 18255 for (regno = REGNO (reg); regno < end_regno; regno++) 18256 if (state->last_set[regno].insn != 0) 18257 { 18258 unsigned int t; 18259 18260 t = (state->last_set[regno].time 18261 + insn_latency (state->last_set[regno].insn, insn)); 18262 while (state->time < t) 18263 mips_sim_next_cycle (state); 18264 } 18265 } 18266 18267 /* A note_uses callback. For each register in *X, advance simulation 18268 state DATA until mips_sim_insn can read the register's value. */ 18269 18270 static void 18271 mips_sim_wait_regs_1 (rtx *x, void *data) 18272 { 18273 subrtx_var_iterator::array_type array; 18274 FOR_EACH_SUBRTX_VAR (iter, array, *x, NONCONST) 18275 if (REG_P (*iter)) 18276 mips_sim_wait_reg ((struct mips_sim *) data, mips_sim_insn, *iter); 18277 } 18278 18279 /* Advance simulation state STATE until all of INSN's register 18280 dependencies are satisfied. */ 18281 18282 static void 18283 mips_sim_wait_regs (struct mips_sim *state, rtx_insn *insn) 18284 { 18285 mips_sim_insn = insn; 18286 note_uses (&PATTERN (insn), mips_sim_wait_regs_1, state); 18287 } 18288 18289 /* Advance simulation state STATE until the units required by 18290 instruction INSN are available. */ 18291 18292 static void 18293 mips_sim_wait_units (struct mips_sim *state, rtx_insn *insn) 18294 { 18295 state_t tmp_state; 18296 18297 tmp_state = alloca (state_size ()); 18298 while (state->insns_left == 0 18299 || (memcpy (tmp_state, state->dfa_state, state_size ()), 18300 state_transition (tmp_state, insn) >= 0)) 18301 mips_sim_next_cycle (state); 18302 } 18303 18304 /* Advance simulation state STATE until INSN is ready to issue. */ 18305 18306 static void 18307 mips_sim_wait_insn (struct mips_sim *state, rtx_insn *insn) 18308 { 18309 mips_sim_wait_regs (state, insn); 18310 mips_sim_wait_units (state, insn); 18311 } 18312 18313 /* mips_sim_insn has just set X. Update the LAST_SET array 18314 in simulation state DATA. */ 18315 18316 static void 18317 mips_sim_record_set (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data) 18318 { 18319 struct mips_sim *state; 18320 18321 state = (struct mips_sim *) data; 18322 if (REG_P (x)) 18323 { 18324 unsigned int regno, end_regno; 18325 18326 end_regno = END_REGNO (x); 18327 for (regno = REGNO (x); regno < end_regno; regno++) 18328 { 18329 state->last_set[regno].insn = mips_sim_insn; 18330 state->last_set[regno].time = state->time; 18331 } 18332 } 18333 } 18334 18335 /* Issue instruction INSN in scheduler state STATE. Assume that INSN 18336 can issue immediately (i.e., that mips_sim_wait_insn has already 18337 been called). */ 18338 18339 static void 18340 mips_sim_issue_insn (struct mips_sim *state, rtx_insn *insn) 18341 { 18342 curr_state = state->dfa_state; 18343 18344 state_transition (curr_state, insn); 18345 state->insns_left = targetm.sched.variable_issue (0, false, insn, 18346 state->insns_left); 18347 18348 mips_sim_insn = insn; 18349 note_stores (insn, mips_sim_record_set, state); 18350 } 18351 18352 /* Simulate issuing a NOP in state STATE. */ 18353 18354 static void 18355 mips_sim_issue_nop (struct mips_sim *state) 18356 { 18357 if (state->insns_left == 0) 18358 mips_sim_next_cycle (state); 18359 state->insns_left--; 18360 } 18361 18362 /* Update simulation state STATE so that it's ready to accept the instruction 18363 after INSN. INSN should be part of the main rtl chain, not a member of a 18364 SEQUENCE. */ 18365 18366 static void 18367 mips_sim_finish_insn (struct mips_sim *state, rtx_insn *insn) 18368 { 18369 /* If INSN is a jump with an implicit delay slot, simulate a nop. */ 18370 if (JUMP_P (insn)) 18371 mips_sim_issue_nop (state); 18372 18373 switch (GET_CODE (SEQ_BEGIN (insn))) 18374 { 18375 case CODE_LABEL: 18376 case CALL_INSN: 18377 /* We can't predict the processor state after a call or label. */ 18378 mips_sim_reset (state); 18379 break; 18380 18381 case JUMP_INSN: 18382 /* The delay slots of branch likely instructions are only executed 18383 when the branch is taken. Therefore, if the caller has simulated 18384 the delay slot instruction, STATE does not really reflect the state 18385 of the pipeline for the instruction after the delay slot. Also, 18386 branch likely instructions tend to incur a penalty when not taken, 18387 so there will probably be an extra delay between the branch and 18388 the instruction after the delay slot. */ 18389 if (INSN_ANNULLED_BRANCH_P (SEQ_BEGIN (insn))) 18390 mips_sim_reset (state); 18391 break; 18392 18393 default: 18394 break; 18395 } 18396 } 18397 18398 /* Use simulator state STATE to calculate the execution time of 18399 instruction sequence SEQ. */ 18400 18401 static unsigned int 18402 mips_seq_time (struct mips_sim *state, rtx_insn *seq) 18403 { 18404 mips_sim_reset (state); 18405 for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn)) 18406 { 18407 mips_sim_wait_insn (state, insn); 18408 mips_sim_issue_insn (state, insn); 18409 } 18410 return state->time; 18411 } 18412 18413 /* Return the execution-time cost of mips_tuning_info.fast_mult_zero_zero_p 18414 setting SETTING, using STATE to simulate instruction sequences. */ 18415 18416 static unsigned int 18417 mips_mult_zero_zero_cost (struct mips_sim *state, bool setting) 18418 { 18419 mips_tuning_info.fast_mult_zero_zero_p = setting; 18420 start_sequence (); 18421 18422 machine_mode dword_mode = TARGET_64BIT ? TImode : DImode; 18423 rtx hilo = gen_rtx_REG (dword_mode, MD_REG_FIRST); 18424 mips_emit_move_or_split (hilo, const0_rtx, SPLIT_FOR_SPEED); 18425 18426 /* If the target provides mulsidi3_32bit then that's the most likely 18427 consumer of the result. Test for bypasses. */ 18428 if (dword_mode == DImode && HAVE_maddsidi4) 18429 { 18430 rtx gpr = gen_rtx_REG (SImode, GP_REG_FIRST + 4); 18431 emit_insn (gen_maddsidi4 (hilo, gpr, gpr, hilo)); 18432 } 18433 18434 unsigned int time = mips_seq_time (state, get_insns ()); 18435 end_sequence (); 18436 return time; 18437 } 18438 18439 /* Check the relative speeds of "MULT $0,$0" and "MTLO $0; MTHI $0" 18440 and set up mips_tuning_info.fast_mult_zero_zero_p accordingly. 18441 Prefer MULT -- which is shorter -- in the event of a tie. */ 18442 18443 static void 18444 mips_set_fast_mult_zero_zero_p (struct mips_sim *state) 18445 { 18446 if (TARGET_MIPS16 || !ISA_HAS_HILO) 18447 /* No MTLO or MTHI available for MIPS16. Also, when there are no HI or LO 18448 registers then there is no reason to zero them, arbitrarily choose to 18449 say that "MULT $0,$0" would be faster. */ 18450 mips_tuning_info.fast_mult_zero_zero_p = true; 18451 else 18452 { 18453 unsigned int true_time = mips_mult_zero_zero_cost (state, true); 18454 unsigned int false_time = mips_mult_zero_zero_cost (state, false); 18455 mips_tuning_info.fast_mult_zero_zero_p = (true_time <= false_time); 18456 } 18457 } 18458 18459 /* Set up costs based on the current architecture and tuning settings. */ 18460 18461 static void 18462 mips_set_tuning_info (void) 18463 { 18464 if (mips_tuning_info.initialized_p 18465 && mips_tuning_info.arch == mips_arch 18466 && mips_tuning_info.tune == mips_tune 18467 && mips_tuning_info.mips16_p == TARGET_MIPS16) 18468 return; 18469 18470 mips_tuning_info.arch = mips_arch; 18471 mips_tuning_info.tune = mips_tune; 18472 mips_tuning_info.mips16_p = TARGET_MIPS16; 18473 mips_tuning_info.initialized_p = true; 18474 18475 dfa_start (); 18476 18477 struct mips_sim state; 18478 mips_sim_init (&state, alloca (state_size ())); 18479 18480 mips_set_fast_mult_zero_zero_p (&state); 18481 18482 dfa_finish (); 18483 } 18484 18485 /* Implement TARGET_EXPAND_TO_RTL_HOOK. */ 18486 18487 static void 18488 mips_expand_to_rtl_hook (void) 18489 { 18490 /* We need to call this at a point where we can safely create sequences 18491 of instructions, so TARGET_OVERRIDE_OPTIONS is too early. We also 18492 need to call it at a point where the DFA infrastructure is not 18493 already in use, so we can't just call it lazily on demand. 18494 18495 At present, mips_tuning_info is only needed during post-expand 18496 RTL passes such as split_insns, so this hook should be early enough. 18497 We may need to move the call elsewhere if mips_tuning_info starts 18498 to be used for other things (such as rtx_costs, or expanders that 18499 could be called during gimple optimization). */ 18500 mips_set_tuning_info (); 18501 } 18502 18503 /* The VR4130 pipeline issues aligned pairs of instructions together, 18504 but it stalls the second instruction if it depends on the first. 18505 In order to cut down the amount of logic required, this dependence 18506 check is not based on a full instruction decode. Instead, any non-SPECIAL 18507 instruction is assumed to modify the register specified by bits 20-16 18508 (which is usually the "rt" field). 18509 18510 In BEQ, BEQL, BNE and BNEL instructions, the rt field is actually an 18511 input, so we can end up with a false dependence between the branch 18512 and its delay slot. If this situation occurs in instruction INSN, 18513 try to avoid it by swapping rs and rt. */ 18514 18515 static void 18516 vr4130_avoid_branch_rt_conflict (rtx_insn *insn) 18517 { 18518 rtx_insn *first, *second; 18519 18520 first = SEQ_BEGIN (insn); 18521 second = SEQ_END (insn); 18522 if (JUMP_P (first) 18523 && NONJUMP_INSN_P (second) 18524 && GET_CODE (PATTERN (first)) == SET 18525 && GET_CODE (SET_DEST (PATTERN (first))) == PC 18526 && GET_CODE (SET_SRC (PATTERN (first))) == IF_THEN_ELSE) 18527 { 18528 /* Check for the right kind of condition. */ 18529 rtx cond = XEXP (SET_SRC (PATTERN (first)), 0); 18530 if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE) 18531 && REG_P (XEXP (cond, 0)) 18532 && REG_P (XEXP (cond, 1)) 18533 && reg_referenced_p (XEXP (cond, 1), PATTERN (second)) 18534 && !reg_referenced_p (XEXP (cond, 0), PATTERN (second))) 18535 { 18536 /* SECOND mentions the rt register but not the rs register. */ 18537 rtx tmp = XEXP (cond, 0); 18538 XEXP (cond, 0) = XEXP (cond, 1); 18539 XEXP (cond, 1) = tmp; 18540 } 18541 } 18542 } 18543 18544 /* Implement -mvr4130-align. Go through each basic block and simulate the 18545 processor pipeline. If we find that a pair of instructions could execute 18546 in parallel, and the first of those instructions is not 8-byte aligned, 18547 insert a nop to make it aligned. */ 18548 18549 static void 18550 vr4130_align_insns (void) 18551 { 18552 struct mips_sim state; 18553 rtx_insn *insn, *subinsn, *last, *last2, *next; 18554 bool aligned_p; 18555 18556 dfa_start (); 18557 18558 /* LAST is the last instruction before INSN to have a nonzero length. 18559 LAST2 is the last such instruction before LAST. */ 18560 last = 0; 18561 last2 = 0; 18562 18563 /* ALIGNED_P is true if INSN is known to be at an aligned address. */ 18564 aligned_p = true; 18565 18566 mips_sim_init (&state, alloca (state_size ())); 18567 for (insn = get_insns (); insn != 0; insn = next) 18568 { 18569 unsigned int length; 18570 18571 next = NEXT_INSN (insn); 18572 18573 /* See the comment above vr4130_avoid_branch_rt_conflict for details. 18574 This isn't really related to the alignment pass, but we do it on 18575 the fly to avoid a separate instruction walk. */ 18576 vr4130_avoid_branch_rt_conflict (insn); 18577 18578 length = get_attr_length (insn); 18579 if (length > 0 && USEFUL_INSN_P (insn)) 18580 FOR_EACH_SUBINSN (subinsn, insn) 18581 { 18582 mips_sim_wait_insn (&state, subinsn); 18583 18584 /* If we want this instruction to issue in parallel with the 18585 previous one, make sure that the previous instruction is 18586 aligned. There are several reasons why this isn't worthwhile 18587 when the second instruction is a call: 18588 18589 - Calls are less likely to be performance critical, 18590 - There's a good chance that the delay slot can execute 18591 in parallel with the call. 18592 - The return address would then be unaligned. 18593 18594 In general, if we're going to insert a nop between instructions 18595 X and Y, it's better to insert it immediately after X. That 18596 way, if the nop makes Y aligned, it will also align any labels 18597 between X and Y. */ 18598 if (state.insns_left != state.issue_rate 18599 && !CALL_P (subinsn)) 18600 { 18601 if (subinsn == SEQ_BEGIN (insn) && aligned_p) 18602 { 18603 /* SUBINSN is the first instruction in INSN and INSN is 18604 aligned. We want to align the previous instruction 18605 instead, so insert a nop between LAST2 and LAST. 18606 18607 Note that LAST could be either a single instruction 18608 or a branch with a delay slot. In the latter case, 18609 LAST, like INSN, is already aligned, but the delay 18610 slot must have some extra delay that stops it from 18611 issuing at the same time as the branch. We therefore 18612 insert a nop before the branch in order to align its 18613 delay slot. */ 18614 gcc_assert (last2); 18615 emit_insn_after (gen_nop (), last2); 18616 aligned_p = false; 18617 } 18618 else if (subinsn != SEQ_BEGIN (insn) && !aligned_p) 18619 { 18620 /* SUBINSN is the delay slot of INSN, but INSN is 18621 currently unaligned. Insert a nop between 18622 LAST and INSN to align it. */ 18623 gcc_assert (last); 18624 emit_insn_after (gen_nop (), last); 18625 aligned_p = true; 18626 } 18627 } 18628 mips_sim_issue_insn (&state, subinsn); 18629 } 18630 mips_sim_finish_insn (&state, insn); 18631 18632 /* Update LAST, LAST2 and ALIGNED_P for the next instruction. */ 18633 length = get_attr_length (insn); 18634 if (length > 0) 18635 { 18636 /* If the instruction is an asm statement or multi-instruction 18637 mips.md pattern, the length is only an estimate. Insert an 18638 8 byte alignment after it so that the following instructions 18639 can be handled correctly. */ 18640 if (NONJUMP_INSN_P (SEQ_BEGIN (insn)) 18641 && (recog_memoized (insn) < 0 || length >= 8)) 18642 { 18643 next = emit_insn_after (gen_align (GEN_INT (3)), insn); 18644 next = NEXT_INSN (next); 18645 mips_sim_next_cycle (&state); 18646 aligned_p = true; 18647 } 18648 else if (length & 4) 18649 aligned_p = !aligned_p; 18650 last2 = last; 18651 last = insn; 18652 } 18653 18654 /* See whether INSN is an aligned label. */ 18655 if (LABEL_P (insn) && label_to_alignment (insn).levels[0].log >= 3) 18656 aligned_p = true; 18657 } 18658 dfa_finish (); 18659 } 18660 18661 /* This structure records that the current function has a LO_SUM 18662 involving SYMBOL_REF or LABEL_REF BASE and that MAX_OFFSET is 18663 the largest offset applied to BASE by all such LO_SUMs. */ 18664 struct mips_lo_sum_offset { 18665 rtx base; 18666 HOST_WIDE_INT offset; 18667 }; 18668 18669 /* Return a hash value for SYMBOL_REF or LABEL_REF BASE. */ 18670 18671 static hashval_t 18672 mips_hash_base (rtx base) 18673 { 18674 int do_not_record_p; 18675 18676 return hash_rtx (base, GET_MODE (base), &do_not_record_p, NULL, false); 18677 } 18678 18679 /* Hashtable helpers. */ 18680 18681 struct mips_lo_sum_offset_hasher : free_ptr_hash <mips_lo_sum_offset> 18682 { 18683 typedef rtx_def *compare_type; 18684 static inline hashval_t hash (const mips_lo_sum_offset *); 18685 static inline bool equal (const mips_lo_sum_offset *, const rtx_def *); 18686 }; 18687 18688 /* Hash-table callbacks for mips_lo_sum_offsets. */ 18689 18690 inline hashval_t 18691 mips_lo_sum_offset_hasher::hash (const mips_lo_sum_offset *entry) 18692 { 18693 return mips_hash_base (entry->base); 18694 } 18695 18696 inline bool 18697 mips_lo_sum_offset_hasher::equal (const mips_lo_sum_offset *entry, 18698 const rtx_def *value) 18699 { 18700 return rtx_equal_p (entry->base, value); 18701 } 18702 18703 typedef hash_table<mips_lo_sum_offset_hasher> mips_offset_table; 18704 18705 /* Look up symbolic constant X in HTAB, which is a hash table of 18706 mips_lo_sum_offsets. If OPTION is NO_INSERT, return true if X can be 18707 paired with a recorded LO_SUM, otherwise record X in the table. */ 18708 18709 static bool 18710 mips_lo_sum_offset_lookup (mips_offset_table *htab, rtx x, 18711 enum insert_option option) 18712 { 18713 rtx base, offset; 18714 mips_lo_sum_offset **slot; 18715 struct mips_lo_sum_offset *entry; 18716 18717 /* Split X into a base and offset. */ 18718 split_const (x, &base, &offset); 18719 if (UNSPEC_ADDRESS_P (base)) 18720 base = UNSPEC_ADDRESS (base); 18721 18722 /* Look up the base in the hash table. */ 18723 slot = htab->find_slot_with_hash (base, mips_hash_base (base), option); 18724 if (slot == NULL) 18725 return false; 18726 18727 entry = (struct mips_lo_sum_offset *) *slot; 18728 if (option == INSERT) 18729 { 18730 if (entry == NULL) 18731 { 18732 entry = XNEW (struct mips_lo_sum_offset); 18733 entry->base = base; 18734 entry->offset = INTVAL (offset); 18735 *slot = entry; 18736 } 18737 else 18738 { 18739 if (INTVAL (offset) > entry->offset) 18740 entry->offset = INTVAL (offset); 18741 } 18742 } 18743 return INTVAL (offset) <= entry->offset; 18744 } 18745 18746 /* Search X for LO_SUMs and record them in HTAB. */ 18747 18748 static void 18749 mips_record_lo_sums (const_rtx x, mips_offset_table *htab) 18750 { 18751 subrtx_iterator::array_type array; 18752 FOR_EACH_SUBRTX (iter, array, x, NONCONST) 18753 if (GET_CODE (*iter) == LO_SUM) 18754 mips_lo_sum_offset_lookup (htab, XEXP (*iter, 1), INSERT); 18755 } 18756 18757 /* Return true if INSN is a SET of an orphaned high-part relocation. 18758 HTAB is a hash table of mips_lo_sum_offsets that describes all the 18759 LO_SUMs in the current function. */ 18760 18761 static bool 18762 mips_orphaned_high_part_p (mips_offset_table *htab, rtx_insn *insn) 18763 { 18764 enum mips_symbol_type type; 18765 rtx x, set; 18766 18767 set = single_set (insn); 18768 if (set) 18769 { 18770 /* Check for %his. */ 18771 x = SET_SRC (set); 18772 if (GET_CODE (x) == HIGH 18773 && absolute_symbolic_operand (XEXP (x, 0), VOIDmode)) 18774 return !mips_lo_sum_offset_lookup (htab, XEXP (x, 0), NO_INSERT); 18775 18776 /* Check for local %gots (and %got_pages, which is redundant but OK). */ 18777 if (GET_CODE (x) == UNSPEC 18778 && XINT (x, 1) == UNSPEC_LOAD_GOT 18779 && mips_symbolic_constant_p (XVECEXP (x, 0, 1), 18780 SYMBOL_CONTEXT_LEA, &type) 18781 && type == SYMBOL_GOTOFF_PAGE) 18782 return !mips_lo_sum_offset_lookup (htab, XVECEXP (x, 0, 1), NO_INSERT); 18783 } 18784 return false; 18785 } 18786 18787 /* Subroutine of mips_avoid_hazard. We classify unconditional branches 18788 of interest for the P6600 for performance reasons. We're interested 18789 in differentiating BALC from JIC, JIALC and BC. */ 18790 18791 static enum mips_ucbranch_type 18792 mips_classify_branch_p6600 (rtx_insn *insn) 18793 { 18794 /* We ignore sequences here as they represent a filled delay slot. */ 18795 if (!insn 18796 || !USEFUL_INSN_P (insn) 18797 || GET_CODE (PATTERN (insn)) == SEQUENCE) 18798 return UC_UNDEFINED; 18799 18800 if (get_attr_jal (insn) == JAL_INDIRECT /* JIC and JIALC. */ 18801 || get_attr_type (insn) == TYPE_JUMP) /* BC. */ 18802 return UC_OTHER; 18803 18804 if (CALL_P (insn) && get_attr_jal (insn) == JAL_DIRECT) 18805 return UC_BALC; 18806 18807 return UC_UNDEFINED; 18808 } 18809 18810 /* Subroutine of mips_reorg_process_insns. If there is a hazard between 18811 INSN and a previous instruction, avoid it by inserting nops after 18812 instruction AFTER. 18813 18814 *DELAYED_REG and *HILO_DELAY describe the hazards that apply at 18815 this point. If *DELAYED_REG is non-null, INSN must wait a cycle 18816 before using the value of that register. *HILO_DELAY counts the 18817 number of instructions since the last hilo hazard (that is, 18818 the number of instructions since the last MFLO or MFHI). 18819 18820 After inserting nops for INSN, update *DELAYED_REG and *HILO_DELAY 18821 for the next instruction. 18822 18823 LO_REG is an rtx for the LO register, used in dependence checking. */ 18824 18825 static void 18826 mips_avoid_hazard (rtx_insn *after, rtx_insn *insn, int *hilo_delay, 18827 rtx *delayed_reg, rtx lo_reg, bool *fs_delay) 18828 { 18829 rtx pattern, set; 18830 int nops, ninsns; 18831 18832 pattern = PATTERN (insn); 18833 18834 /* Do not put the whole function in .set noreorder if it contains 18835 an asm statement. We don't know whether there will be hazards 18836 between the asm statement and the gcc-generated code. */ 18837 if (GET_CODE (pattern) == ASM_INPUT || asm_noperands (pattern) >= 0) 18838 cfun->machine->all_noreorder_p = false; 18839 18840 /* Ignore zero-length instructions (barriers and the like). */ 18841 ninsns = get_attr_length (insn) / 4; 18842 if (ninsns == 0) 18843 return; 18844 18845 /* Work out how many nops are needed. Note that we only care about 18846 registers that are explicitly mentioned in the instruction's pattern. 18847 It doesn't matter that calls use the argument registers or that they 18848 clobber hi and lo. */ 18849 if (*hilo_delay < 2 && reg_set_p (lo_reg, pattern)) 18850 nops = 2 - *hilo_delay; 18851 else if (*delayed_reg != 0 && reg_referenced_p (*delayed_reg, pattern)) 18852 nops = 1; 18853 /* If processing a forbidden slot hazard then a NOP is required if the 18854 branch instruction was not in a sequence (as the sequence would 18855 imply it is not actually a compact branch anyway) and the current 18856 insn is not an inline asm, and can't go in a delay slot. */ 18857 else if (*fs_delay && get_attr_can_delay (insn) == CAN_DELAY_NO 18858 && GET_CODE (PATTERN (after)) != SEQUENCE 18859 && GET_CODE (pattern) != ASM_INPUT 18860 && asm_noperands (pattern) < 0) 18861 nops = 1; 18862 /* The P6600's branch predictor can handle static sequences of back-to-back 18863 branches in the following cases: 18864 18865 (1) BALC followed by any conditional compact branch 18866 (2) BALC followed by BALC 18867 18868 Any other combinations of compact branches will incur performance 18869 penalty. Inserting a no-op only costs space as the dispatch unit will 18870 disregard the nop. */ 18871 else if (TUNE_P6600 && TARGET_CB_MAYBE && !optimize_size 18872 && ((mips_classify_branch_p6600 (after) == UC_BALC 18873 && mips_classify_branch_p6600 (insn) == UC_OTHER) 18874 || (mips_classify_branch_p6600 (insn) == UC_BALC 18875 && mips_classify_branch_p6600 (after) == UC_OTHER))) 18876 nops = 1; 18877 else 18878 nops = 0; 18879 18880 /* Insert the nops between this instruction and the previous one. 18881 Each new nop takes us further from the last hilo hazard. */ 18882 *hilo_delay += nops; 18883 18884 /* Move to the next real instruction if we are inserting a NOP and this 18885 instruction is a call with debug information. The reason being that 18886 we can't separate the call from the debug info. */ 18887 rtx_insn *real_after = after; 18888 if (real_after && nops && CALL_P (real_after)) 18889 while (real_after 18890 && (NOTE_P (NEXT_INSN (real_after)) 18891 || BARRIER_P (NEXT_INSN (real_after)))) 18892 real_after = NEXT_INSN (real_after); 18893 18894 while (nops-- > 0) 18895 emit_insn_after (gen_hazard_nop (), real_after); 18896 18897 /* Set up the state for the next instruction. */ 18898 *hilo_delay += ninsns; 18899 *delayed_reg = 0; 18900 *fs_delay = false; 18901 if (INSN_CODE (insn) >= 0) 18902 switch (get_attr_hazard (insn)) 18903 { 18904 case HAZARD_NONE: 18905 /* For the P6600, flag some unconditional branches as having a 18906 pseudo-forbidden slot. This will cause additional nop insertion 18907 or SEQUENCE breaking as required. This is for performance 18908 reasons not correctness. */ 18909 if (TUNE_P6600 18910 && !optimize_size 18911 && TARGET_CB_MAYBE 18912 && mips_classify_branch_p6600 (insn) == UC_OTHER) 18913 *fs_delay = true; 18914 break; 18915 18916 case HAZARD_FORBIDDEN_SLOT: 18917 if (TARGET_CB_MAYBE) 18918 *fs_delay = true; 18919 break; 18920 18921 case HAZARD_HILO: 18922 *hilo_delay = 0; 18923 break; 18924 18925 case HAZARD_DELAY: 18926 set = single_set (insn); 18927 gcc_assert (set); 18928 *delayed_reg = SET_DEST (set); 18929 break; 18930 } 18931 } 18932 18933 /* A SEQUENCE is breakable iff the branch inside it has a compact form 18934 and the target has compact branches. */ 18935 18936 static bool 18937 mips_breakable_sequence_p (rtx_insn *insn) 18938 { 18939 return (insn && GET_CODE (PATTERN (insn)) == SEQUENCE 18940 && TARGET_CB_MAYBE 18941 && get_attr_compact_form (SEQ_BEGIN (insn)) != COMPACT_FORM_NEVER); 18942 } 18943 18944 /* Remove a SEQUENCE and replace it with the delay slot instruction 18945 followed by the branch and return the instruction in the delay slot. 18946 Return the first of the two new instructions. 18947 Subroutine of mips_reorg_process_insns. */ 18948 18949 static rtx_insn * 18950 mips_break_sequence (rtx_insn *insn) 18951 { 18952 rtx_insn *before = PREV_INSN (insn); 18953 rtx_insn *branch = SEQ_BEGIN (insn); 18954 rtx_insn *ds = SEQ_END (insn); 18955 remove_insn (insn); 18956 add_insn_after (ds, before, NULL); 18957 add_insn_after (branch, ds, NULL); 18958 return ds; 18959 } 18960 18961 /* Go through the instruction stream and insert nops where necessary. 18962 Also delete any high-part relocations whose partnering low parts 18963 are now all dead. See if the whole function can then be put into 18964 .set noreorder and .set nomacro. */ 18965 18966 static void 18967 mips_reorg_process_insns (void) 18968 { 18969 rtx_insn *insn, *last_insn, *subinsn, *next_insn; 18970 rtx lo_reg, delayed_reg; 18971 int hilo_delay; 18972 bool fs_delay; 18973 18974 /* Force all instructions to be split into their final form. */ 18975 split_all_insns_noflow (); 18976 18977 /* Recalculate instruction lengths without taking nops into account. */ 18978 cfun->machine->ignore_hazard_length_p = true; 18979 shorten_branches (get_insns ()); 18980 18981 cfun->machine->all_noreorder_p = true; 18982 18983 /* We don't track MIPS16 PC-relative offsets closely enough to make 18984 a good job of "set .noreorder" code in MIPS16 mode. */ 18985 if (TARGET_MIPS16) 18986 cfun->machine->all_noreorder_p = false; 18987 18988 /* Code that doesn't use explicit relocs can't be ".set nomacro". */ 18989 if (!TARGET_EXPLICIT_RELOCS) 18990 cfun->machine->all_noreorder_p = false; 18991 18992 /* Profiled functions can't be all noreorder because the profiler 18993 support uses assembler macros. */ 18994 if (crtl->profile) 18995 cfun->machine->all_noreorder_p = false; 18996 18997 /* Code compiled with -mfix-vr4120, -mfix-r5900, -mfix-rm7000 or 18998 -mfix-24k can't be all noreorder because we rely on the assembler 18999 to work around some errata. The R5900 target has several bugs. */ 19000 if (TARGET_FIX_VR4120 19001 || TARGET_FIX_RM7000 19002 || TARGET_FIX_24K 19003 || TARGET_FIX_R5900) 19004 cfun->machine->all_noreorder_p = false; 19005 19006 /* The same is true for -mfix-vr4130 if we might generate MFLO or 19007 MFHI instructions. Note that we avoid using MFLO and MFHI if 19008 the VR4130 MACC and DMACC instructions are available instead; 19009 see the *mfhilo_{si,di}_macc patterns. */ 19010 if (TARGET_FIX_VR4130 && !ISA_HAS_MACCHI) 19011 cfun->machine->all_noreorder_p = false; 19012 19013 mips_offset_table htab (37); 19014 19015 /* Make a first pass over the instructions, recording all the LO_SUMs. */ 19016 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn)) 19017 FOR_EACH_SUBINSN (subinsn, insn) 19018 if (USEFUL_INSN_P (subinsn)) 19019 { 19020 rtx body = PATTERN (insn); 19021 int noperands = asm_noperands (body); 19022 if (noperands >= 0) 19023 { 19024 rtx *ops = XALLOCAVEC (rtx, noperands); 19025 bool *used = XALLOCAVEC (bool, noperands); 19026 const char *string = decode_asm_operands (body, ops, NULL, NULL, 19027 NULL, NULL); 19028 get_referenced_operands (string, used, noperands); 19029 for (int i = 0; i < noperands; ++i) 19030 if (used[i]) 19031 mips_record_lo_sums (ops[i], &htab); 19032 } 19033 else 19034 mips_record_lo_sums (PATTERN (subinsn), &htab); 19035 } 19036 19037 last_insn = 0; 19038 hilo_delay = 2; 19039 delayed_reg = 0; 19040 lo_reg = gen_rtx_REG (SImode, LO_REGNUM); 19041 fs_delay = false; 19042 19043 /* Make a second pass over the instructions. Delete orphaned 19044 high-part relocations or turn them into NOPs. Avoid hazards 19045 by inserting NOPs. */ 19046 for (insn = get_insns (); insn != 0; insn = next_insn) 19047 { 19048 next_insn = NEXT_INSN (insn); 19049 if (USEFUL_INSN_P (insn)) 19050 { 19051 if (GET_CODE (PATTERN (insn)) == SEQUENCE) 19052 { 19053 rtx_insn *next_active = next_active_insn (insn); 19054 /* Undo delay slots to avoid bubbles if the next instruction can 19055 be placed in a forbidden slot or the cost of adding an 19056 explicit NOP in a forbidden slot is OK and if the SEQUENCE is 19057 safely breakable. */ 19058 if (TARGET_CB_MAYBE 19059 && mips_breakable_sequence_p (insn) 19060 && INSN_P (SEQ_BEGIN (insn)) 19061 && INSN_P (SEQ_END (insn)) 19062 && ((next_active 19063 && INSN_P (next_active) 19064 && GET_CODE (PATTERN (next_active)) != SEQUENCE 19065 && get_attr_can_delay (next_active) == CAN_DELAY_YES) 19066 || !optimize_size)) 19067 { 19068 /* To hide a potential pipeline bubble, if we scan backwards 19069 from the current SEQUENCE and find that there is a load 19070 of a value that is used in the CTI and there are no 19071 dependencies between the CTI and instruction in the delay 19072 slot, break the sequence so the load delay is hidden. */ 19073 HARD_REG_SET uses; 19074 CLEAR_HARD_REG_SET (uses); 19075 note_uses (&PATTERN (SEQ_BEGIN (insn)), record_hard_reg_uses, 19076 &uses); 19077 HARD_REG_SET delay_sets; 19078 CLEAR_HARD_REG_SET (delay_sets); 19079 note_stores (SEQ_END (insn), record_hard_reg_sets, 19080 &delay_sets); 19081 19082 rtx_insn *prev = prev_active_insn (insn); 19083 if (prev 19084 && GET_CODE (PATTERN (prev)) == SET 19085 && MEM_P (SET_SRC (PATTERN (prev)))) 19086 { 19087 HARD_REG_SET sets; 19088 CLEAR_HARD_REG_SET (sets); 19089 note_stores (prev, record_hard_reg_sets, &sets); 19090 19091 /* Re-order if safe. */ 19092 if (!hard_reg_set_intersect_p (delay_sets, uses) 19093 && hard_reg_set_intersect_p (uses, sets)) 19094 { 19095 next_insn = mips_break_sequence (insn); 19096 /* Need to process the hazards of the newly 19097 introduced instructions. */ 19098 continue; 19099 } 19100 } 19101 19102 /* If we find an orphaned high-part relocation in a delay 19103 slot then we can convert to a compact branch and get 19104 the orphaned high part deleted. */ 19105 if (mips_orphaned_high_part_p (&htab, SEQ_END (insn))) 19106 { 19107 next_insn = mips_break_sequence (insn); 19108 /* Need to process the hazards of the newly 19109 introduced instructions. */ 19110 continue; 19111 } 19112 } 19113 19114 /* If we find an orphaned high-part relocation in a delay 19115 slot, it's easier to turn that instruction into a NOP than 19116 to delete it. The delay slot will be a NOP either way. */ 19117 FOR_EACH_SUBINSN (subinsn, insn) 19118 if (INSN_P (subinsn)) 19119 { 19120 if (mips_orphaned_high_part_p (&htab, subinsn)) 19121 { 19122 PATTERN (subinsn) = gen_nop (); 19123 INSN_CODE (subinsn) = CODE_FOR_nop; 19124 } 19125 mips_avoid_hazard (last_insn, subinsn, &hilo_delay, 19126 &delayed_reg, lo_reg, &fs_delay); 19127 } 19128 last_insn = insn; 19129 } 19130 else 19131 { 19132 /* INSN is a single instruction. Delete it if it's an 19133 orphaned high-part relocation. */ 19134 if (mips_orphaned_high_part_p (&htab, insn)) 19135 delete_insn (insn); 19136 /* Also delete cache barriers if the last instruction 19137 was an annulled branch. INSN will not be speculatively 19138 executed. */ 19139 else if (recog_memoized (insn) == CODE_FOR_r10k_cache_barrier 19140 && last_insn 19141 && JUMP_P (SEQ_BEGIN (last_insn)) 19142 && INSN_ANNULLED_BRANCH_P (SEQ_BEGIN (last_insn))) 19143 delete_insn (insn); 19144 else 19145 { 19146 mips_avoid_hazard (last_insn, insn, &hilo_delay, 19147 &delayed_reg, lo_reg, &fs_delay); 19148 /* When a compact branch introduces a forbidden slot hazard 19149 and the next useful instruction is a SEQUENCE of a jump 19150 and a non-nop instruction in the delay slot, remove the 19151 sequence and replace it with the delay slot instruction 19152 then the jump to clear the forbidden slot hazard. 19153 19154 For the P6600, this optimisation solves the performance 19155 penalty associated with BALC followed by a delay slot 19156 branch. We do not set fs_delay as we do not want 19157 the full logic of a forbidden slot; the penalty exists 19158 only against branches not the full class of forbidden 19159 slot instructions. */ 19160 19161 if (fs_delay || (TUNE_P6600 19162 && TARGET_CB_MAYBE 19163 && mips_classify_branch_p6600 (insn) 19164 == UC_BALC)) 19165 { 19166 /* Search onwards from the current position looking for 19167 a SEQUENCE. We are looking for pipeline hazards here 19168 and do not need to worry about labels or barriers as 19169 the optimization only undoes delay slot filling which 19170 only affects the order of the branch and its delay 19171 slot. */ 19172 rtx_insn *next = next_active_insn (insn); 19173 if (next 19174 && USEFUL_INSN_P (next) 19175 && GET_CODE (PATTERN (next)) == SEQUENCE 19176 && mips_breakable_sequence_p (next)) 19177 { 19178 last_insn = insn; 19179 next_insn = mips_break_sequence (next); 19180 /* Need to process the hazards of the newly 19181 introduced instructions. */ 19182 continue; 19183 } 19184 } 19185 last_insn = insn; 19186 } 19187 } 19188 } 19189 } 19190 } 19191 19192 /* Return true if the function has a long branch instruction. */ 19193 19194 static bool 19195 mips_has_long_branch_p (void) 19196 { 19197 rtx_insn *insn, *subinsn; 19198 int normal_length; 19199 19200 /* We need up-to-date instruction lengths. */ 19201 shorten_branches (get_insns ()); 19202 19203 /* Look for a branch that is longer than normal. The normal length for 19204 non-MIPS16 branches is 8, because the length includes the delay slot. 19205 It is 4 for MIPS16, because MIPS16 branches are extended instructions, 19206 but they have no delay slot. */ 19207 normal_length = (TARGET_MIPS16 ? 4 : 8); 19208 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 19209 FOR_EACH_SUBINSN (subinsn, insn) 19210 if (JUMP_P (subinsn) 19211 && get_attr_length (subinsn) > normal_length 19212 && (any_condjump_p (subinsn) || any_uncondjump_p (subinsn))) 19213 return true; 19214 19215 return false; 19216 } 19217 19218 /* If we are using a GOT, but have not decided to use a global pointer yet, 19219 see whether we need one to implement long branches. Convert the ghost 19220 global-pointer instructions into real ones if so. */ 19221 19222 static bool 19223 mips_expand_ghost_gp_insns (void) 19224 { 19225 /* Quick exit if we already know that we will or won't need a 19226 global pointer. */ 19227 if (!TARGET_USE_GOT 19228 || cfun->machine->global_pointer == INVALID_REGNUM 19229 || mips_must_initialize_gp_p ()) 19230 return false; 19231 19232 /* Run a full check for long branches. */ 19233 if (!mips_has_long_branch_p ()) 19234 return false; 19235 19236 /* We've now established that we need $gp. */ 19237 cfun->machine->must_initialize_gp_p = true; 19238 split_all_insns_noflow (); 19239 19240 return true; 19241 } 19242 19243 /* Subroutine of mips_reorg to manage passes that require DF. */ 19244 19245 static void 19246 mips_df_reorg (void) 19247 { 19248 /* Create def-use chains. */ 19249 df_set_flags (DF_EQ_NOTES); 19250 df_chain_add_problem (DF_UD_CHAIN); 19251 df_analyze (); 19252 19253 if (TARGET_RELAX_PIC_CALLS) 19254 mips_annotate_pic_calls (); 19255 19256 if (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE) 19257 r10k_insert_cache_barriers (); 19258 19259 df_finish_pass (false); 19260 } 19261 19262 /* Emit code to load LABEL_REF SRC into MIPS16 register DEST. This is 19263 called very late in mips_reorg, but the caller is required to run 19264 mips16_lay_out_constants on the result. */ 19265 19266 static void 19267 mips16_load_branch_target (rtx dest, rtx src) 19268 { 19269 if (TARGET_ABICALLS && !TARGET_ABSOLUTE_ABICALLS) 19270 { 19271 rtx page, low; 19272 19273 if (mips_cfun_has_cprestore_slot_p ()) 19274 mips_emit_move (dest, mips_cprestore_slot (dest, true)); 19275 else 19276 mips_emit_move (dest, pic_offset_table_rtx); 19277 page = mips_unspec_address (src, SYMBOL_GOTOFF_PAGE); 19278 low = mips_unspec_address (src, SYMBOL_GOT_PAGE_OFST); 19279 emit_insn (gen_rtx_SET (dest, 19280 PMODE_INSN (gen_unspec_got, (dest, page)))); 19281 emit_insn (gen_rtx_SET (dest, gen_rtx_LO_SUM (Pmode, dest, low))); 19282 } 19283 else 19284 { 19285 src = mips_unspec_address (src, SYMBOL_ABSOLUTE); 19286 mips_emit_move (dest, src); 19287 } 19288 } 19289 19290 /* If we're compiling a MIPS16 function, look for and split any long branches. 19291 This must be called after all other instruction modifications in 19292 mips_reorg. */ 19293 19294 static void 19295 mips16_split_long_branches (void) 19296 { 19297 bool something_changed; 19298 19299 if (!TARGET_MIPS16) 19300 return; 19301 19302 /* Loop until the alignments for all targets are sufficient. */ 19303 do 19304 { 19305 rtx_insn *insn; 19306 rtx_jump_insn *jump_insn; 19307 19308 shorten_branches (get_insns ()); 19309 something_changed = false; 19310 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 19311 if ((jump_insn = dyn_cast <rtx_jump_insn *> (insn)) 19312 && get_attr_length (jump_insn) > 4 19313 && (any_condjump_p (jump_insn) || any_uncondjump_p (jump_insn))) 19314 { 19315 rtx old_label, temp, saved_temp; 19316 rtx_code_label *new_label; 19317 rtx target; 19318 rtx_insn *jump, *jump_sequence; 19319 19320 start_sequence (); 19321 19322 /* Free up a MIPS16 register by saving it in $1. */ 19323 saved_temp = gen_rtx_REG (Pmode, AT_REGNUM); 19324 temp = gen_rtx_REG (Pmode, GP_REG_FIRST + 2); 19325 emit_move_insn (saved_temp, temp); 19326 19327 /* Load the branch target into TEMP. */ 19328 old_label = JUMP_LABEL (jump_insn); 19329 target = gen_rtx_LABEL_REF (Pmode, old_label); 19330 mips16_load_branch_target (temp, target); 19331 19332 /* Jump to the target and restore the register's 19333 original value. */ 19334 jump = emit_jump_insn (PMODE_INSN (gen_indirect_jump_and_restore, 19335 (temp, temp, saved_temp))); 19336 JUMP_LABEL (jump) = old_label; 19337 LABEL_NUSES (old_label)++; 19338 19339 /* Rewrite any symbolic references that are supposed to use 19340 a PC-relative constant pool. */ 19341 mips16_lay_out_constants (false); 19342 19343 if (simplejump_p (jump_insn)) 19344 /* We're going to replace INSN with a longer form. */ 19345 new_label = NULL; 19346 else 19347 { 19348 /* Create a branch-around label for the original 19349 instruction. */ 19350 new_label = gen_label_rtx (); 19351 emit_label (new_label); 19352 } 19353 19354 jump_sequence = get_insns (); 19355 end_sequence (); 19356 19357 emit_insn_after (jump_sequence, jump_insn); 19358 if (new_label) 19359 invert_jump (jump_insn, new_label, false); 19360 else 19361 delete_insn (jump_insn); 19362 something_changed = true; 19363 } 19364 } 19365 while (something_changed); 19366 } 19367 19368 /* Insert a `.insn' assembly pseudo-op after any labels followed by 19369 a MIPS16 constant pool or no insn at all. This is needed so that 19370 targets that have been optimized away are still marked as code 19371 and therefore branches that remained and point to them are known 19372 to retain the ISA mode and as such can be successfully assembled. */ 19373 19374 static void 19375 mips_insert_insn_pseudos (void) 19376 { 19377 bool insn_pseudo_needed = TRUE; 19378 rtx_insn *insn; 19379 19380 for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn)) 19381 switch (GET_CODE (insn)) 19382 { 19383 case INSN: 19384 if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE 19385 && XINT (PATTERN (insn), 1) == UNSPEC_CONSTTABLE) 19386 { 19387 insn_pseudo_needed = TRUE; 19388 break; 19389 } 19390 /* Fall through. */ 19391 case JUMP_INSN: 19392 case CALL_INSN: 19393 case JUMP_TABLE_DATA: 19394 insn_pseudo_needed = FALSE; 19395 break; 19396 case CODE_LABEL: 19397 if (insn_pseudo_needed) 19398 { 19399 emit_insn_after (gen_insn_pseudo (), insn); 19400 insn_pseudo_needed = FALSE; 19401 } 19402 break; 19403 default: 19404 break; 19405 } 19406 } 19407 19408 /* Implement TARGET_MACHINE_DEPENDENT_REORG. */ 19409 19410 static void 19411 mips_reorg (void) 19412 { 19413 /* Restore the BLOCK_FOR_INSN pointers, which are needed by DF. Also during 19414 insn splitting in mips16_lay_out_constants, DF insn info is only kept up 19415 to date if the CFG is available. */ 19416 if (mips_cfg_in_reorg ()) 19417 compute_bb_for_insn (); 19418 mips16_lay_out_constants (true); 19419 if (mips_cfg_in_reorg ()) 19420 { 19421 mips_df_reorg (); 19422 free_bb_for_insn (); 19423 } 19424 } 19425 19426 /* We use a machine specific pass to do a second machine dependent reorg 19427 pass after delay branch scheduling. */ 19428 19429 static unsigned int 19430 mips_machine_reorg2 (void) 19431 { 19432 mips_reorg_process_insns (); 19433 if (!TARGET_MIPS16 19434 && TARGET_EXPLICIT_RELOCS 19435 && TUNE_MIPS4130 19436 && TARGET_VR4130_ALIGN) 19437 vr4130_align_insns (); 19438 if (mips_expand_ghost_gp_insns ()) 19439 /* The expansion could invalidate some of the VR4130 alignment 19440 optimizations, but this should be an extremely rare case anyhow. */ 19441 mips_reorg_process_insns (); 19442 mips16_split_long_branches (); 19443 mips_insert_insn_pseudos (); 19444 return 0; 19445 } 19446 19447 namespace { 19448 19449 const pass_data pass_data_mips_machine_reorg2 = 19450 { 19451 RTL_PASS, /* type */ 19452 "mach2", /* name */ 19453 OPTGROUP_NONE, /* optinfo_flags */ 19454 TV_MACH_DEP, /* tv_id */ 19455 0, /* properties_required */ 19456 0, /* properties_provided */ 19457 0, /* properties_destroyed */ 19458 0, /* todo_flags_start */ 19459 0, /* todo_flags_finish */ 19460 }; 19461 19462 class pass_mips_machine_reorg2 : public rtl_opt_pass 19463 { 19464 public: 19465 pass_mips_machine_reorg2(gcc::context *ctxt) 19466 : rtl_opt_pass(pass_data_mips_machine_reorg2, ctxt) 19467 {} 19468 19469 /* opt_pass methods: */ 19470 virtual unsigned int execute (function *) { return mips_machine_reorg2 (); } 19471 19472 }; // class pass_mips_machine_reorg2 19473 19474 } // anon namespace 19475 19476 rtl_opt_pass * 19477 make_pass_mips_machine_reorg2 (gcc::context *ctxt) 19478 { 19479 return new pass_mips_machine_reorg2 (ctxt); 19480 } 19481 19482 19483 /* Implement TARGET_ASM_OUTPUT_MI_THUNK. Generate rtl rather than asm text 19484 in order to avoid duplicating too much logic from elsewhere. */ 19485 19486 static void 19487 mips_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED, 19488 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset, 19489 tree function) 19490 { 19491 const char *fnname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (thunk_fndecl)); 19492 rtx this_rtx, temp1, temp2, fnaddr; 19493 rtx_insn *insn; 19494 bool use_sibcall_p; 19495 19496 /* Pretend to be a post-reload pass while generating rtl. */ 19497 reload_completed = 1; 19498 19499 /* Mark the end of the (empty) prologue. */ 19500 emit_note (NOTE_INSN_PROLOGUE_END); 19501 19502 /* Determine if we can use a sibcall to call FUNCTION directly. */ 19503 fnaddr = XEXP (DECL_RTL (function), 0); 19504 use_sibcall_p = (mips_function_ok_for_sibcall (function, NULL) 19505 && const_call_insn_operand (fnaddr, Pmode)); 19506 19507 /* Determine if we need to load FNADDR from the GOT. */ 19508 if (!use_sibcall_p 19509 && (mips_got_symbol_type_p 19510 (mips_classify_symbol (fnaddr, SYMBOL_CONTEXT_LEA)))) 19511 { 19512 /* Pick a global pointer. Use a call-clobbered register if 19513 TARGET_CALL_SAVED_GP. */ 19514 cfun->machine->global_pointer 19515 = TARGET_CALL_SAVED_GP ? 15 : GLOBAL_POINTER_REGNUM; 19516 cfun->machine->must_initialize_gp_p = true; 19517 SET_REGNO (pic_offset_table_rtx, cfun->machine->global_pointer); 19518 19519 /* Set up the global pointer for n32 or n64 abicalls. */ 19520 mips_emit_loadgp (); 19521 } 19522 19523 /* We need two temporary registers in some cases. */ 19524 temp1 = gen_rtx_REG (Pmode, 2); 19525 temp2 = gen_rtx_REG (Pmode, 3); 19526 19527 /* Find out which register contains the "this" pointer. */ 19528 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function)) 19529 this_rtx = gen_rtx_REG (Pmode, GP_ARG_FIRST + 1); 19530 else 19531 this_rtx = gen_rtx_REG (Pmode, GP_ARG_FIRST); 19532 19533 /* Add DELTA to THIS_RTX. */ 19534 if (delta != 0) 19535 { 19536 rtx offset = GEN_INT (delta); 19537 if (!SMALL_OPERAND (delta)) 19538 { 19539 mips_emit_move (temp1, offset); 19540 offset = temp1; 19541 } 19542 emit_insn (gen_add3_insn (this_rtx, this_rtx, offset)); 19543 } 19544 19545 /* If needed, add *(*THIS_RTX + VCALL_OFFSET) to THIS_RTX. */ 19546 if (vcall_offset != 0) 19547 { 19548 rtx addr; 19549 19550 /* Set TEMP1 to *THIS_RTX. */ 19551 mips_emit_move (temp1, gen_rtx_MEM (Pmode, this_rtx)); 19552 19553 /* Set ADDR to a legitimate address for *THIS_RTX + VCALL_OFFSET. */ 19554 addr = mips_add_offset (temp2, temp1, vcall_offset); 19555 19556 /* Load the offset and add it to THIS_RTX. */ 19557 mips_emit_move (temp1, gen_rtx_MEM (Pmode, addr)); 19558 emit_insn (gen_add3_insn (this_rtx, this_rtx, temp1)); 19559 } 19560 19561 /* Jump to the target function. Use a sibcall if direct jumps are 19562 allowed, otherwise load the address into a register first. */ 19563 if (use_sibcall_p) 19564 { 19565 insn = emit_call_insn (gen_sibcall_internal (fnaddr, const0_rtx)); 19566 SIBLING_CALL_P (insn) = 1; 19567 } 19568 else 19569 { 19570 /* This is messy. GAS treats "la $25,foo" as part of a call 19571 sequence and may allow a global "foo" to be lazily bound. 19572 The general move patterns therefore reject this combination. 19573 19574 In this context, lazy binding would actually be OK 19575 for TARGET_CALL_CLOBBERED_GP, but it's still wrong for 19576 TARGET_CALL_SAVED_GP; see mips_load_call_address. 19577 We must therefore load the address via a temporary 19578 register if mips_dangerous_for_la25_p. 19579 19580 If we jump to the temporary register rather than $25, 19581 the assembler can use the move insn to fill the jump's 19582 delay slot. 19583 19584 We can use the same technique for MIPS16 code, where $25 19585 is not a valid JR register. */ 19586 if (TARGET_USE_PIC_FN_ADDR_REG 19587 && !TARGET_MIPS16 19588 && !mips_dangerous_for_la25_p (fnaddr)) 19589 temp1 = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM); 19590 mips_load_call_address (MIPS_CALL_SIBCALL, temp1, fnaddr); 19591 19592 if (TARGET_USE_PIC_FN_ADDR_REG 19593 && REGNO (temp1) != PIC_FUNCTION_ADDR_REGNUM) 19594 mips_emit_move (gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM), temp1); 19595 emit_jump_insn (gen_indirect_jump (temp1)); 19596 } 19597 19598 /* Run just enough of rest_of_compilation. This sequence was 19599 "borrowed" from alpha.c. */ 19600 insn = get_insns (); 19601 split_all_insns_noflow (); 19602 mips16_lay_out_constants (true); 19603 shorten_branches (insn); 19604 assemble_start_function (thunk_fndecl, fnname); 19605 final_start_function (insn, file, 1); 19606 final (insn, file, 1); 19607 final_end_function (); 19608 assemble_end_function (thunk_fndecl, fnname); 19609 19610 /* Clean up the vars set above. Note that final_end_function resets 19611 the global pointer for us. */ 19612 reload_completed = 0; 19613 } 19614 19615 19616 /* The last argument passed to mips_set_compression_mode, 19617 or negative if the function hasn't been called yet. */ 19618 static unsigned int old_compression_mode = -1; 19619 19620 /* Set up the target-dependent global state for ISA mode COMPRESSION_MODE, 19621 which is either MASK_MIPS16 or MASK_MICROMIPS. */ 19622 19623 static void 19624 mips_set_compression_mode (unsigned int compression_mode) 19625 { 19626 19627 if (compression_mode == old_compression_mode) 19628 return; 19629 19630 /* Restore base settings of various flags. */ 19631 target_flags = mips_base_target_flags; 19632 flag_schedule_insns = mips_base_schedule_insns; 19633 flag_reorder_blocks_and_partition = mips_base_reorder_blocks_and_partition; 19634 flag_move_loop_invariants = mips_base_move_loop_invariants; 19635 str_align_loops = mips_base_align_loops; 19636 str_align_jumps = mips_base_align_jumps; 19637 str_align_functions = mips_base_align_functions; 19638 target_flags &= ~(MASK_MIPS16 | MASK_MICROMIPS); 19639 target_flags |= compression_mode; 19640 19641 if (compression_mode & MASK_MIPS16) 19642 { 19643 /* Switch to MIPS16 mode. */ 19644 target_flags |= MASK_MIPS16; 19645 19646 /* Turn off SYNCI if it was on, MIPS16 doesn't support it. */ 19647 target_flags &= ~MASK_SYNCI; 19648 19649 /* Don't run the scheduler before reload, since it tends to 19650 increase register pressure. */ 19651 flag_schedule_insns = 0; 19652 19653 /* Don't do hot/cold partitioning. mips16_lay_out_constants expects 19654 the whole function to be in a single section. */ 19655 flag_reorder_blocks_and_partition = 0; 19656 19657 /* Don't move loop invariants, because it tends to increase 19658 register pressure. It also introduces an extra move in cases 19659 where the constant is the first operand in a two-operand binary 19660 instruction, or when it forms a register argument to a functon 19661 call. */ 19662 flag_move_loop_invariants = 0; 19663 19664 target_flags |= MASK_EXPLICIT_RELOCS; 19665 19666 /* Experiments suggest we get the best overall section-anchor 19667 results from using the range of an unextended LW or SW. Code 19668 that makes heavy use of byte or short accesses can do better 19669 with ranges of 0...31 and 0...63 respectively, but most code is 19670 sensitive to the range of LW and SW instead. */ 19671 targetm.min_anchor_offset = 0; 19672 targetm.max_anchor_offset = 127; 19673 19674 targetm.const_anchor = 0; 19675 19676 /* MIPS16 has no BAL instruction. */ 19677 target_flags &= ~MASK_RELAX_PIC_CALLS; 19678 19679 /* The R4000 errata don't apply to any known MIPS16 cores. 19680 It's simpler to make the R4000 fixes and MIPS16 mode 19681 mutually exclusive. */ 19682 target_flags &= ~MASK_FIX_R4000; 19683 19684 if (flag_pic && !TARGET_OLDABI) 19685 sorry ("MIPS16 PIC for ABIs other than o32 and o64"); 19686 19687 if (TARGET_XGOT) 19688 sorry ("MIPS16 %<-mxgot%> code"); 19689 19690 if (TARGET_HARD_FLOAT_ABI && !TARGET_OLDABI) 19691 sorry ("hard-float MIPS16 code for ABIs other than o32 and o64"); 19692 19693 if (TARGET_MSA) 19694 sorry ("MSA MIPS16 code"); 19695 } 19696 else 19697 { 19698 /* Switch to microMIPS or the standard encoding. */ 19699 19700 if (TARGET_MICROMIPS) 19701 /* Avoid branch likely. */ 19702 target_flags &= ~MASK_BRANCHLIKELY; 19703 19704 /* Provide default values for align_* for 64-bit targets. */ 19705 if (TARGET_64BIT) 19706 { 19707 if (flag_align_loops && !str_align_loops) 19708 str_align_loops = "8"; 19709 if (flag_align_jumps && !str_align_jumps) 19710 str_align_jumps = "8"; 19711 if (flag_align_functions && !str_align_functions) 19712 str_align_functions = "8"; 19713 } 19714 19715 targetm.min_anchor_offset = -32768; 19716 targetm.max_anchor_offset = 32767; 19717 19718 targetm.const_anchor = 0x8000; 19719 } 19720 19721 /* (Re)initialize MIPS target internals for new ISA. */ 19722 mips_init_relocs (); 19723 19724 if (compression_mode & MASK_MIPS16) 19725 { 19726 if (!mips16_globals) 19727 mips16_globals = save_target_globals_default_opts (); 19728 else 19729 restore_target_globals (mips16_globals); 19730 } 19731 else if (compression_mode & MASK_MICROMIPS) 19732 { 19733 if (!micromips_globals) 19734 micromips_globals = save_target_globals_default_opts (); 19735 else 19736 restore_target_globals (micromips_globals); 19737 } 19738 else 19739 restore_target_globals (&default_target_globals); 19740 19741 old_compression_mode = compression_mode; 19742 } 19743 19744 /* Implement TARGET_SET_CURRENT_FUNCTION. Decide whether the current 19745 function should use the MIPS16 or microMIPS ISA and switch modes 19746 accordingly. */ 19747 19748 static void 19749 mips_set_current_function (tree fndecl) 19750 { 19751 mips_set_compression_mode (mips_get_compress_mode (fndecl)); 19752 } 19753 19754 /* Allocate a chunk of memory for per-function machine-dependent data. */ 19755 19756 static struct machine_function * 19757 mips_init_machine_status (void) 19758 { 19759 return ggc_cleared_alloc<machine_function> (); 19760 } 19761 19762 /* Return the processor associated with the given ISA level, or null 19763 if the ISA isn't valid. */ 19764 19765 static const struct mips_cpu_info * 19766 mips_cpu_info_from_isa (int isa) 19767 { 19768 unsigned int i; 19769 19770 for (i = 0; i < ARRAY_SIZE (mips_cpu_info_table); i++) 19771 if (mips_cpu_info_table[i].isa == isa) 19772 return mips_cpu_info_table + i; 19773 19774 return NULL; 19775 } 19776 19777 /* Return a mips_cpu_info entry determined by an option valued 19778 OPT. */ 19779 19780 static const struct mips_cpu_info * 19781 mips_cpu_info_from_opt (int opt) 19782 { 19783 switch (opt) 19784 { 19785 case MIPS_ARCH_OPTION_FROM_ABI: 19786 /* 'from-abi' selects the most compatible architecture for the 19787 given ABI: MIPS I for 32-bit ABIs and MIPS III for 64-bit 19788 ABIs. For the EABIs, we have to decide whether we're using 19789 the 32-bit or 64-bit version. */ 19790 return mips_cpu_info_from_isa (ABI_NEEDS_32BIT_REGS ? 1 19791 : ABI_NEEDS_64BIT_REGS ? 3 19792 : (TARGET_64BIT ? 3 : 1)); 19793 19794 case MIPS_ARCH_OPTION_NATIVE: 19795 gcc_unreachable (); 19796 19797 default: 19798 return &mips_cpu_info_table[opt]; 19799 } 19800 } 19801 19802 /* Return a default mips_cpu_info entry, given that no -march= option 19803 was explicitly specified. */ 19804 19805 static const struct mips_cpu_info * 19806 mips_default_arch (void) 19807 { 19808 #if defined (MIPS_CPU_STRING_DEFAULT) 19809 unsigned int i; 19810 for (i = 0; i < ARRAY_SIZE (mips_cpu_info_table); i++) 19811 if (strcmp (mips_cpu_info_table[i].name, MIPS_CPU_STRING_DEFAULT) == 0) 19812 return mips_cpu_info_table + i; 19813 gcc_unreachable (); 19814 #elif defined (MIPS_ISA_DEFAULT) 19815 return mips_cpu_info_from_isa (MIPS_ISA_DEFAULT); 19816 #else 19817 /* 'from-abi' makes a good default: you get whatever the ABI 19818 requires. */ 19819 return mips_cpu_info_from_opt (MIPS_ARCH_OPTION_FROM_ABI); 19820 #endif 19821 } 19822 19823 /* Set up globals to generate code for the ISA or processor 19824 described by INFO. */ 19825 19826 static void 19827 mips_set_architecture (const struct mips_cpu_info *info) 19828 { 19829 if (info != 0) 19830 { 19831 mips_arch_info = info; 19832 mips_arch = info->cpu; 19833 mips_isa = info->isa; 19834 if (mips_isa < 32) 19835 mips_isa_rev = 0; 19836 else 19837 mips_isa_rev = (mips_isa & 31) + 1; 19838 } 19839 } 19840 19841 /* Likewise for tuning. */ 19842 19843 static void 19844 mips_set_tune (const struct mips_cpu_info *info) 19845 { 19846 if (info != 0) 19847 { 19848 mips_tune_info = info; 19849 mips_tune = info->cpu; 19850 } 19851 } 19852 19853 /* Implement TARGET_OPTION_OVERRIDE. */ 19854 19855 static void 19856 mips_option_override (void) 19857 { 19858 int i, start, regno, mode; 19859 19860 if (global_options_set.x_mips_isa_option) 19861 mips_isa_option_info = &mips_cpu_info_table[mips_isa_option]; 19862 19863 #ifdef SUBTARGET_OVERRIDE_OPTIONS 19864 SUBTARGET_OVERRIDE_OPTIONS; 19865 #endif 19866 19867 /* MIPS16 and microMIPS cannot coexist. */ 19868 if (TARGET_MICROMIPS && TARGET_MIPS16) 19869 error ("unsupported combination: %s", "-mips16 -mmicromips"); 19870 19871 /* Prohibit Paired-Single and MSA combination. This is software restriction 19872 rather than architectural. */ 19873 if (ISA_HAS_MSA && TARGET_PAIRED_SINGLE_FLOAT) 19874 error ("unsupported combination: %s", "-mmsa -mpaired-single"); 19875 19876 /* Save the base compression state and process flags as though we 19877 were generating uncompressed code. */ 19878 mips_base_compression_flags = TARGET_COMPRESSION; 19879 target_flags &= ~TARGET_COMPRESSION; 19880 19881 /* -mno-float overrides -mhard-float and -msoft-float. */ 19882 if (TARGET_NO_FLOAT) 19883 { 19884 target_flags |= MASK_SOFT_FLOAT_ABI; 19885 target_flags_explicit |= MASK_SOFT_FLOAT_ABI; 19886 } 19887 19888 if (TARGET_FLIP_MIPS16) 19889 TARGET_INTERLINK_COMPRESSED = 1; 19890 19891 /* Set the small data limit. */ 19892 mips_small_data_threshold = (global_options_set.x_g_switch_value 19893 ? g_switch_value 19894 : MIPS_DEFAULT_GVALUE); 19895 19896 /* The following code determines the architecture and register size. 19897 Similar code was added to GAS 2.14 (see tc-mips.c:md_after_parse_args()). 19898 The GAS and GCC code should be kept in sync as much as possible. */ 19899 19900 if (global_options_set.x_mips_arch_option) 19901 mips_set_architecture (mips_cpu_info_from_opt (mips_arch_option)); 19902 19903 if (mips_isa_option_info != 0) 19904 { 19905 if (mips_arch_info == 0) 19906 mips_set_architecture (mips_isa_option_info); 19907 else if (mips_arch_info->isa != mips_isa_option_info->isa) 19908 error ("%<-%s%> conflicts with the other architecture options, " 19909 "which specify a %s processor", 19910 mips_isa_option_info->name, 19911 mips_cpu_info_from_isa (mips_arch_info->isa)->name); 19912 } 19913 19914 if (mips_arch_info == 0) 19915 mips_set_architecture (mips_default_arch ()); 19916 19917 if (ABI_NEEDS_64BIT_REGS && !ISA_HAS_64BIT_REGS) 19918 error ("%<-march=%s%> is not compatible with the selected ABI", 19919 mips_arch_info->name); 19920 19921 /* Optimize for mips_arch, unless -mtune selects a different processor. */ 19922 if (global_options_set.x_mips_tune_option) 19923 mips_set_tune (mips_cpu_info_from_opt (mips_tune_option)); 19924 19925 if (mips_tune_info == 0) 19926 mips_set_tune (mips_arch_info); 19927 19928 if ((target_flags_explicit & MASK_64BIT) != 0) 19929 { 19930 /* The user specified the size of the integer registers. Make sure 19931 it agrees with the ABI and ISA. */ 19932 if (TARGET_64BIT && !ISA_HAS_64BIT_REGS) 19933 error ("%<-mgp64%> used with a 32-bit processor"); 19934 else if (!TARGET_64BIT && ABI_NEEDS_64BIT_REGS) 19935 error ("%<-mgp32%> used with a 64-bit ABI"); 19936 else if (TARGET_64BIT && ABI_NEEDS_32BIT_REGS) 19937 error ("%<-mgp64%> used with a 32-bit ABI"); 19938 } 19939 else 19940 { 19941 /* Infer the integer register size from the ABI and processor. 19942 Restrict ourselves to 32-bit registers if that's all the 19943 processor has, or if the ABI cannot handle 64-bit registers. */ 19944 if (ABI_NEEDS_32BIT_REGS || !ISA_HAS_64BIT_REGS) 19945 target_flags &= ~MASK_64BIT; 19946 else 19947 target_flags |= MASK_64BIT; 19948 } 19949 19950 if ((target_flags_explicit & MASK_FLOAT64) != 0) 19951 { 19952 if (mips_isa_rev >= 6 && !TARGET_FLOAT64) 19953 error ("the %qs architecture does not support %<-mfp32%>", 19954 mips_arch_info->name); 19955 else if (TARGET_SINGLE_FLOAT && TARGET_FLOAT64) 19956 error ("unsupported combination: %s", "-mfp64 -msingle-float"); 19957 else if (TARGET_64BIT && TARGET_DOUBLE_FLOAT && !TARGET_FLOAT64) 19958 error ("unsupported combination: %s", "-mgp64 -mfp32 -mdouble-float"); 19959 else if (!TARGET_64BIT && TARGET_FLOAT64) 19960 { 19961 if (!ISA_HAS_MXHC1) 19962 error ("%<-mgp32%> and %<-mfp64%> can only be combined if" 19963 " the target supports the mfhc1 and mthc1 instructions"); 19964 else if (mips_abi != ABI_32) 19965 error ("%<-mgp32%> and %<-mfp64%> can only be combined when using" 19966 " the o32 ABI"); 19967 } 19968 } 19969 else 19970 { 19971 /* -msingle-float selects 32-bit float registers. On r6 and later, 19972 -mdouble-float selects 64-bit float registers, since the old paired 19973 register model is not supported. In other cases the float registers 19974 should be the same size as the integer ones. */ 19975 if (mips_isa_rev >= 6 && TARGET_DOUBLE_FLOAT && !TARGET_FLOATXX) 19976 target_flags |= MASK_FLOAT64; 19977 else if (TARGET_64BIT && TARGET_DOUBLE_FLOAT) 19978 target_flags |= MASK_FLOAT64; 19979 else if (mips_abi == ABI_32 && ISA_HAS_MSA && !TARGET_FLOATXX) 19980 target_flags |= MASK_FLOAT64; 19981 else 19982 target_flags &= ~MASK_FLOAT64; 19983 } 19984 19985 if (mips_abi != ABI_32 && TARGET_FLOATXX) 19986 error ("%<-mfpxx%> can only be used with the o32 ABI"); 19987 else if (TARGET_FLOAT64 && TARGET_FLOATXX) 19988 error ("unsupported combination: %s", "-mfp64 -mfpxx"); 19989 else if (ISA_MIPS1 && !TARGET_FLOAT32) 19990 error ("%<-march=%s%> requires %<-mfp32%>", mips_arch_info->name); 19991 else if (TARGET_FLOATXX && !mips_lra_flag) 19992 error ("%<-mfpxx%> requires %<-mlra%>"); 19993 19994 /* End of code shared with GAS. */ 19995 19996 /* The R5900 FPU only supports single precision. */ 19997 if (TARGET_MIPS5900 && TARGET_HARD_FLOAT_ABI && TARGET_DOUBLE_FLOAT) 19998 error ("unsupported combination: %s", 19999 "-march=r5900 -mhard-float -mdouble-float"); 20000 20001 /* If a -mlong* option was given, check that it matches the ABI, 20002 otherwise infer the -mlong* setting from the other options. */ 20003 if ((target_flags_explicit & MASK_LONG64) != 0) 20004 { 20005 if (TARGET_LONG64) 20006 { 20007 if (mips_abi == ABI_N32) 20008 error ("%qs is incompatible with %qs", "-mabi=n32", "-mlong64"); 20009 else if (mips_abi == ABI_32) 20010 error ("%qs is incompatible with %qs", "-mabi=32", "-mlong64"); 20011 else if (mips_abi == ABI_O64 && TARGET_ABICALLS) 20012 /* We have traditionally allowed non-abicalls code to use 20013 an LP64 form of o64. However, it would take a bit more 20014 effort to support the combination of 32-bit GOT entries 20015 and 64-bit pointers, so we treat the abicalls case as 20016 an error. */ 20017 error ("the combination of %qs and %qs is incompatible with %qs", 20018 "-mabi=o64", "-mabicalls", "-mlong64"); 20019 } 20020 else 20021 { 20022 if (mips_abi == ABI_64) 20023 error ("%qs is incompatible with %qs", "-mabi=64", "-mlong32"); 20024 } 20025 } 20026 else 20027 { 20028 if ((mips_abi == ABI_EABI && TARGET_64BIT) || mips_abi == ABI_64) 20029 target_flags |= MASK_LONG64; 20030 else 20031 target_flags &= ~MASK_LONG64; 20032 } 20033 20034 if (!TARGET_OLDABI) 20035 flag_pcc_struct_return = 0; 20036 20037 /* Decide which rtx_costs structure to use. */ 20038 if (optimize_size) 20039 mips_cost = &mips_rtx_cost_optimize_size; 20040 else 20041 mips_cost = &mips_rtx_cost_data[mips_tune]; 20042 20043 /* If the user hasn't specified a branch cost, use the processor's 20044 default. */ 20045 if (mips_branch_cost == 0) 20046 mips_branch_cost = mips_cost->branch_cost; 20047 20048 /* If neither -mbranch-likely nor -mno-branch-likely was given 20049 on the command line, set MASK_BRANCHLIKELY based on the target 20050 architecture and tuning flags. Annulled delay slots are a 20051 size win, so we only consider the processor-specific tuning 20052 for !optimize_size. */ 20053 if ((target_flags_explicit & MASK_BRANCHLIKELY) == 0) 20054 { 20055 if (ISA_HAS_BRANCHLIKELY 20056 && ((optimize_size 20057 && (mips_tune_info->tune_flags 20058 & PTF_AVOID_BRANCHLIKELY_SIZE) == 0) 20059 || (!optimize_size 20060 && optimize > 0 20061 && (mips_tune_info->tune_flags 20062 & PTF_AVOID_BRANCHLIKELY_SPEED) == 0) 20063 || (mips_tune_info->tune_flags 20064 & PTF_AVOID_BRANCHLIKELY_ALWAYS) == 0)) 20065 target_flags |= MASK_BRANCHLIKELY; 20066 else 20067 target_flags &= ~MASK_BRANCHLIKELY; 20068 } 20069 else if (TARGET_BRANCHLIKELY && !ISA_HAS_BRANCHLIKELY) 20070 warning (0, "the %qs architecture does not support branch-likely" 20071 " instructions", mips_arch_info->name); 20072 20073 /* If the user hasn't specified -mimadd or -mno-imadd set 20074 MASK_IMADD based on the target architecture and tuning 20075 flags. */ 20076 if ((target_flags_explicit & MASK_IMADD) == 0) 20077 { 20078 if (ISA_HAS_MADD_MSUB && 20079 (mips_tune_info->tune_flags & PTF_AVOID_IMADD) == 0) 20080 target_flags |= MASK_IMADD; 20081 else 20082 target_flags &= ~MASK_IMADD; 20083 } 20084 else if (TARGET_IMADD && !ISA_HAS_MADD_MSUB) 20085 warning (0, "the %qs architecture does not support madd or msub" 20086 " instructions", mips_arch_info->name); 20087 20088 /* If neither -modd-spreg nor -mno-odd-spreg was given on the command 20089 line, set MASK_ODD_SPREG based on the ISA and ABI. */ 20090 if ((target_flags_explicit & MASK_ODD_SPREG) == 0) 20091 { 20092 /* Disable TARGET_ODD_SPREG when using the o32 FPXX ABI. */ 20093 if (!ISA_HAS_ODD_SPREG || TARGET_FLOATXX) 20094 target_flags &= ~MASK_ODD_SPREG; 20095 else 20096 target_flags |= MASK_ODD_SPREG; 20097 } 20098 else if (TARGET_ODD_SPREG && !ISA_HAS_ODD_SPREG) 20099 warning (0, "the %qs architecture does not support odd single-precision" 20100 " registers", mips_arch_info->name); 20101 20102 if (!TARGET_ODD_SPREG && TARGET_64BIT) 20103 { 20104 error ("unsupported combination: %s", "-mgp64 -mno-odd-spreg"); 20105 /* Allow compilation to continue further even though invalid output 20106 will be produced. */ 20107 target_flags |= MASK_ODD_SPREG; 20108 } 20109 20110 if (!ISA_HAS_COMPACT_BRANCHES && mips_cb == MIPS_CB_ALWAYS) 20111 { 20112 error ("unsupported combination: %qs%s %s", 20113 mips_arch_info->name, TARGET_MICROMIPS ? " -mmicromips" : "", 20114 "-mcompact-branches=always"); 20115 } 20116 else if (!ISA_HAS_DELAY_SLOTS && mips_cb == MIPS_CB_NEVER) 20117 { 20118 error ("unsupported combination: %qs%s %s", 20119 mips_arch_info->name, TARGET_MICROMIPS ? " -mmicromips" : "", 20120 "-mcompact-branches=never"); 20121 } 20122 20123 /* Require explicit relocs for MIPS R6 onwards. This enables simplification 20124 of the compact branch and jump support through the backend. */ 20125 if (!TARGET_EXPLICIT_RELOCS && mips_isa_rev >= 6) 20126 { 20127 error ("unsupported combination: %qs %s", 20128 mips_arch_info->name, "-mno-explicit-relocs"); 20129 } 20130 20131 /* The effect of -mabicalls isn't defined for the EABI. */ 20132 if (mips_abi == ABI_EABI && TARGET_ABICALLS) 20133 { 20134 error ("unsupported combination: %s", "-mabicalls -mabi=eabi"); 20135 target_flags &= ~MASK_ABICALLS; 20136 } 20137 20138 /* PIC requires -mabicalls. */ 20139 if (flag_pic) 20140 { 20141 if (mips_abi == ABI_EABI) 20142 error ("cannot generate position-independent code for %qs", 20143 "-mabi=eabi"); 20144 else if (!TARGET_ABICALLS) 20145 error ("position-independent code requires %qs", "-mabicalls"); 20146 } 20147 20148 if (TARGET_ABICALLS_PIC2) 20149 /* We need to set flag_pic for executables as well as DSOs 20150 because we may reference symbols that are not defined in 20151 the final executable. (MIPS does not use things like 20152 copy relocs, for example.) 20153 20154 There is a body of code that uses __PIC__ to distinguish 20155 between -mabicalls and -mno-abicalls code. The non-__PIC__ 20156 variant is usually appropriate for TARGET_ABICALLS_PIC0, as 20157 long as any indirect jumps use $25. */ 20158 flag_pic = 1; 20159 20160 /* -mvr4130-align is a "speed over size" optimization: it usually produces 20161 faster code, but at the expense of more nops. Enable it at -O3 and 20162 above. */ 20163 if (optimize > 2 && (target_flags_explicit & MASK_VR4130_ALIGN) == 0) 20164 target_flags |= MASK_VR4130_ALIGN; 20165 20166 /* Prefer a call to memcpy over inline code when optimizing for size, 20167 though see MOVE_RATIO in mips.h. */ 20168 if (optimize_size && (target_flags_explicit & MASK_MEMCPY) == 0) 20169 target_flags |= MASK_MEMCPY; 20170 20171 /* If we have a nonzero small-data limit, check that the -mgpopt 20172 setting is consistent with the other target flags. */ 20173 if (mips_small_data_threshold > 0) 20174 { 20175 if (!TARGET_GPOPT) 20176 { 20177 if (!TARGET_EXPLICIT_RELOCS) 20178 error ("%<-mno-gpopt%> needs %<-mexplicit-relocs%>"); 20179 20180 TARGET_LOCAL_SDATA = false; 20181 TARGET_EXTERN_SDATA = false; 20182 } 20183 else 20184 { 20185 if (TARGET_VXWORKS_RTP) 20186 warning (0, "cannot use small-data accesses for %qs", "-mrtp"); 20187 20188 if (TARGET_ABICALLS) 20189 warning (0, "cannot use small-data accesses for %qs", 20190 "-mabicalls"); 20191 } 20192 } 20193 20194 /* Set NaN and ABS defaults. */ 20195 if (mips_nan == MIPS_IEEE_754_DEFAULT && !ISA_HAS_IEEE_754_LEGACY) 20196 mips_nan = MIPS_IEEE_754_2008; 20197 if (mips_abs == MIPS_IEEE_754_DEFAULT && !ISA_HAS_IEEE_754_LEGACY) 20198 mips_abs = MIPS_IEEE_754_2008; 20199 20200 /* Check for IEEE 754 legacy/2008 support. */ 20201 if ((mips_nan == MIPS_IEEE_754_LEGACY 20202 || mips_abs == MIPS_IEEE_754_LEGACY) 20203 && !ISA_HAS_IEEE_754_LEGACY) 20204 warning (0, "the %qs architecture does not support %<-m%s=legacy%>", 20205 mips_arch_info->name, 20206 mips_nan == MIPS_IEEE_754_LEGACY ? "nan" : "abs"); 20207 20208 if ((mips_nan == MIPS_IEEE_754_2008 20209 || mips_abs == MIPS_IEEE_754_2008) 20210 && !ISA_HAS_IEEE_754_2008) 20211 warning (0, "the %qs architecture does not support %<-m%s=2008%>", 20212 mips_arch_info->name, 20213 mips_nan == MIPS_IEEE_754_2008 ? "nan" : "abs"); 20214 20215 /* Pre-IEEE 754-2008 MIPS hardware has a quirky almost-IEEE format 20216 for all its floating point. */ 20217 if (mips_nan != MIPS_IEEE_754_2008) 20218 { 20219 REAL_MODE_FORMAT (SFmode) = &mips_single_format; 20220 REAL_MODE_FORMAT (DFmode) = &mips_double_format; 20221 REAL_MODE_FORMAT (TFmode) = &mips_quad_format; 20222 } 20223 20224 /* Make sure that the user didn't turn off paired single support when 20225 MIPS-3D support is requested. */ 20226 if (TARGET_MIPS3D 20227 && (target_flags_explicit & MASK_PAIRED_SINGLE_FLOAT) 20228 && !TARGET_PAIRED_SINGLE_FLOAT) 20229 error ("%<-mips3d%> requires %<-mpaired-single%>"); 20230 20231 /* If TARGET_MIPS3D, enable MASK_PAIRED_SINGLE_FLOAT. */ 20232 if (TARGET_MIPS3D) 20233 target_flags |= MASK_PAIRED_SINGLE_FLOAT; 20234 20235 /* Make sure that when TARGET_PAIRED_SINGLE_FLOAT is true, TARGET_FLOAT64 20236 and TARGET_HARD_FLOAT_ABI are both true. */ 20237 if (TARGET_PAIRED_SINGLE_FLOAT && !(TARGET_FLOAT64 && TARGET_HARD_FLOAT_ABI)) 20238 { 20239 error ("%qs must be used with %qs", 20240 TARGET_MIPS3D ? "-mips3d" : "-mpaired-single", 20241 TARGET_HARD_FLOAT_ABI ? "-mfp64" : "-mhard-float"); 20242 target_flags &= ~MASK_PAIRED_SINGLE_FLOAT; 20243 TARGET_MIPS3D = 0; 20244 } 20245 20246 /* Make sure that when ISA_HAS_MSA is true, TARGET_FLOAT64 and 20247 TARGET_HARD_FLOAT_ABI and both true. */ 20248 if (ISA_HAS_MSA && !(TARGET_FLOAT64 && TARGET_HARD_FLOAT_ABI)) 20249 error ("%<-mmsa%> must be used with %<-mfp64%> and %<-mhard-float%>"); 20250 20251 /* Make sure that -mpaired-single is only used on ISAs that support it. 20252 We must disable it otherwise since it relies on other ISA properties 20253 like ISA_HAS_8CC having their normal values. */ 20254 if (TARGET_PAIRED_SINGLE_FLOAT && !ISA_HAS_PAIRED_SINGLE) 20255 { 20256 error ("the %qs architecture does not support paired-single" 20257 " instructions", mips_arch_info->name); 20258 target_flags &= ~MASK_PAIRED_SINGLE_FLOAT; 20259 TARGET_MIPS3D = 0; 20260 } 20261 20262 if (mips_r10k_cache_barrier != R10K_CACHE_BARRIER_NONE 20263 && !TARGET_CACHE_BUILTIN) 20264 { 20265 error ("%qs requires a target that provides the %qs instruction", 20266 "-mr10k-cache-barrier", "cache"); 20267 mips_r10k_cache_barrier = R10K_CACHE_BARRIER_NONE; 20268 } 20269 20270 /* If TARGET_DSPR2, enable TARGET_DSP. */ 20271 if (TARGET_DSPR2) 20272 TARGET_DSP = true; 20273 20274 if (TARGET_DSP && mips_isa_rev >= 6) 20275 { 20276 error ("the %qs architecture does not support DSP instructions", 20277 mips_arch_info->name); 20278 TARGET_DSP = false; 20279 TARGET_DSPR2 = false; 20280 } 20281 20282 /* Make sure that when TARGET_LOONGSON_MMI is true, TARGET_HARD_FLOAT_ABI 20283 is true. In o32 pairs of floating-point registers provide 64-bit 20284 values. */ 20285 if (TARGET_LOONGSON_MMI && !TARGET_HARD_FLOAT_ABI) 20286 error ("%<-mloongson-mmi%> must be used with %<-mhard-float%>"); 20287 20288 /* If TARGET_LOONGSON_EXT2, enable TARGET_LOONGSON_EXT. */ 20289 if (TARGET_LOONGSON_EXT2) 20290 { 20291 /* Make sure that when TARGET_LOONGSON_EXT2 is true, TARGET_LOONGSON_EXT 20292 is true. If a user explicitly says -mloongson-ext2 -mno-loongson-ext 20293 then that is an error. */ 20294 if (!TARGET_LOONGSON_EXT 20295 && (target_flags_explicit & MASK_LOONGSON_EXT) != 0) 20296 error ("%<-mloongson-ext2%> must be used with %<-mloongson-ext%>"); 20297 target_flags |= MASK_LOONGSON_EXT; 20298 } 20299 20300 /* .eh_frame addresses should be the same width as a C pointer. 20301 Most MIPS ABIs support only one pointer size, so the assembler 20302 will usually know exactly how big an .eh_frame address is. 20303 20304 Unfortunately, this is not true of the 64-bit EABI. The ABI was 20305 originally defined to use 64-bit pointers (i.e. it is LP64), and 20306 this is still the default mode. However, we also support an n32-like 20307 ILP32 mode, which is selected by -mlong32. The problem is that the 20308 assembler has traditionally not had an -mlong option, so it has 20309 traditionally not known whether we're using the ILP32 or LP64 form. 20310 20311 As it happens, gas versions up to and including 2.19 use _32-bit_ 20312 addresses for EABI64 .cfi_* directives. This is wrong for the 20313 default LP64 mode, so we can't use the directives by default. 20314 Moreover, since gas's current behavior is at odds with gcc's 20315 default behavior, it seems unwise to rely on future versions 20316 of gas behaving the same way. We therefore avoid using .cfi 20317 directives for -mlong32 as well. */ 20318 if (mips_abi == ABI_EABI && TARGET_64BIT) 20319 flag_dwarf2_cfi_asm = 0; 20320 20321 /* .cfi_* directives generate a read-only section, so fall back on 20322 manual .eh_frame creation if we need the section to be writable. */ 20323 if (TARGET_WRITABLE_EH_FRAME) 20324 flag_dwarf2_cfi_asm = 0; 20325 20326 mips_init_print_operand_punct (); 20327 20328 /* Set up array to map GCC register number to debug register number. 20329 Ignore the special purpose register numbers. */ 20330 20331 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) 20332 { 20333 mips_dbx_regno[i] = IGNORED_DWARF_REGNUM; 20334 if (GP_REG_P (i) || FP_REG_P (i) || ALL_COP_REG_P (i)) 20335 mips_dwarf_regno[i] = i; 20336 else 20337 mips_dwarf_regno[i] = INVALID_REGNUM; 20338 } 20339 20340 start = GP_DBX_FIRST - GP_REG_FIRST; 20341 for (i = GP_REG_FIRST; i <= GP_REG_LAST; i++) 20342 mips_dbx_regno[i] = i + start; 20343 20344 start = FP_DBX_FIRST - FP_REG_FIRST; 20345 for (i = FP_REG_FIRST; i <= FP_REG_LAST; i++) 20346 mips_dbx_regno[i] = i + start; 20347 20348 /* Accumulator debug registers use big-endian ordering. */ 20349 mips_dbx_regno[HI_REGNUM] = MD_DBX_FIRST + 0; 20350 mips_dbx_regno[LO_REGNUM] = MD_DBX_FIRST + 1; 20351 mips_dwarf_regno[HI_REGNUM] = MD_REG_FIRST + 0; 20352 mips_dwarf_regno[LO_REGNUM] = MD_REG_FIRST + 1; 20353 for (i = DSP_ACC_REG_FIRST; i <= DSP_ACC_REG_LAST; i += 2) 20354 { 20355 mips_dwarf_regno[i + TARGET_LITTLE_ENDIAN] = i; 20356 mips_dwarf_regno[i + TARGET_BIG_ENDIAN] = i + 1; 20357 } 20358 20359 /* Set up mips_hard_regno_mode_ok. */ 20360 for (mode = 0; mode < MAX_MACHINE_MODE; mode++) 20361 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) 20362 mips_hard_regno_mode_ok_p[mode][regno] 20363 = mips_hard_regno_mode_ok_uncached (regno, (machine_mode) mode); 20364 20365 /* Function to allocate machine-dependent function status. */ 20366 init_machine_status = &mips_init_machine_status; 20367 20368 /* Default to working around R4000 errata only if the processor 20369 was selected explicitly. */ 20370 if ((target_flags_explicit & MASK_FIX_R4000) == 0 20371 && strcmp (mips_arch_info->name, "r4000") == 0) 20372 target_flags |= MASK_FIX_R4000; 20373 20374 /* Default to working around R4400 errata only if the processor 20375 was selected explicitly. */ 20376 if ((target_flags_explicit & MASK_FIX_R4400) == 0 20377 && strcmp (mips_arch_info->name, "r4400") == 0) 20378 target_flags |= MASK_FIX_R4400; 20379 20380 /* Default to working around R5900 errata only if the processor 20381 was selected explicitly. */ 20382 if ((target_flags_explicit & MASK_FIX_R5900) == 0 20383 && strcmp (mips_arch_info->name, "r5900") == 0) 20384 target_flags |= MASK_FIX_R5900; 20385 20386 /* Default to working around R10000 errata only if the processor 20387 was selected explicitly. */ 20388 if ((target_flags_explicit & MASK_FIX_R10000) == 0 20389 && strcmp (mips_arch_info->name, "r10000") == 0) 20390 target_flags |= MASK_FIX_R10000; 20391 20392 /* Make sure that branch-likely instructions available when using 20393 -mfix-r10000. The instructions are not available if either: 20394 20395 1. -mno-branch-likely was passed. 20396 2. The selected ISA does not support branch-likely and 20397 the command line does not include -mbranch-likely. */ 20398 if (TARGET_FIX_R10000 20399 && ((target_flags_explicit & MASK_BRANCHLIKELY) == 0 20400 ? !ISA_HAS_BRANCHLIKELY 20401 : !TARGET_BRANCHLIKELY)) 20402 sorry ("%qs requires branch-likely instructions", "-mfix-r10000"); 20403 20404 if (TARGET_SYNCI && !ISA_HAS_SYNCI) 20405 { 20406 warning (0, "the %qs architecture does not support the synci " 20407 "instruction", mips_arch_info->name); 20408 target_flags &= ~MASK_SYNCI; 20409 } 20410 20411 /* Only optimize PIC indirect calls if they are actually required. */ 20412 if (!TARGET_USE_GOT || !TARGET_EXPLICIT_RELOCS) 20413 target_flags &= ~MASK_RELAX_PIC_CALLS; 20414 20415 /* Save base state of options. */ 20416 mips_base_target_flags = target_flags; 20417 mips_base_schedule_insns = flag_schedule_insns; 20418 mips_base_reorder_blocks_and_partition = flag_reorder_blocks_and_partition; 20419 mips_base_move_loop_invariants = flag_move_loop_invariants; 20420 mips_base_align_loops = str_align_loops; 20421 mips_base_align_jumps = str_align_jumps; 20422 mips_base_align_functions = str_align_functions; 20423 20424 /* Now select the ISA mode. 20425 20426 Do all CPP-sensitive stuff in uncompressed mode; we'll switch modes 20427 later if required. */ 20428 mips_set_compression_mode (0); 20429 20430 /* We register a second machine specific reorg pass after delay slot 20431 filling. Registering the pass must be done at start up. It's 20432 convenient to do it here. */ 20433 opt_pass *new_pass = make_pass_mips_machine_reorg2 (g); 20434 struct register_pass_info insert_pass_mips_machine_reorg2 = 20435 { 20436 new_pass, /* pass */ 20437 "dbr", /* reference_pass_name */ 20438 1, /* ref_pass_instance_number */ 20439 PASS_POS_INSERT_AFTER /* po_op */ 20440 }; 20441 register_pass (&insert_pass_mips_machine_reorg2); 20442 20443 if (TARGET_HARD_FLOAT_ABI && TARGET_MIPS5900) 20444 REAL_MODE_FORMAT (SFmode) = &spu_single_format; 20445 20446 mips_register_frame_header_opt (); 20447 } 20448 20449 /* Swap the register information for registers I and I + 1, which 20450 currently have the wrong endianness. Note that the registers' 20451 fixedness and call-clobberedness might have been set on the 20452 command line. */ 20453 20454 static void 20455 mips_swap_registers (unsigned int i) 20456 { 20457 int tmpi; 20458 const char *tmps; 20459 20460 #define SWAP_INT(X, Y) (tmpi = (X), (X) = (Y), (Y) = tmpi) 20461 #define SWAP_STRING(X, Y) (tmps = (X), (X) = (Y), (Y) = tmps) 20462 20463 SWAP_INT (fixed_regs[i], fixed_regs[i + 1]); 20464 SWAP_INT (call_used_regs[i], call_used_regs[i + 1]); 20465 SWAP_STRING (reg_names[i], reg_names[i + 1]); 20466 20467 #undef SWAP_STRING 20468 #undef SWAP_INT 20469 } 20470 20471 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE. */ 20472 20473 static void 20474 mips_conditional_register_usage (void) 20475 { 20476 20477 if (ISA_HAS_DSP) 20478 { 20479 /* These DSP control register fields are global. */ 20480 global_regs[CCDSP_PO_REGNUM] = 1; 20481 global_regs[CCDSP_SC_REGNUM] = 1; 20482 } 20483 else 20484 accessible_reg_set &= ~reg_class_contents[DSP_ACC_REGS]; 20485 20486 if (!ISA_HAS_HILO) 20487 accessible_reg_set &= ~reg_class_contents[MD_REGS]; 20488 20489 if (!TARGET_HARD_FLOAT) 20490 accessible_reg_set &= ~(reg_class_contents[FP_REGS] 20491 | reg_class_contents[ST_REGS]); 20492 else if (!ISA_HAS_8CC) 20493 { 20494 /* We only have a single condition-code register. We implement 20495 this by fixing all the condition-code registers and generating 20496 RTL that refers directly to ST_REG_FIRST. */ 20497 accessible_reg_set &= ~reg_class_contents[ST_REGS]; 20498 if (!ISA_HAS_CCF) 20499 SET_HARD_REG_BIT (accessible_reg_set, FPSW_REGNUM); 20500 fixed_regs[FPSW_REGNUM] = 1; 20501 } 20502 if (TARGET_MIPS16) 20503 { 20504 /* In MIPS16 mode, we prohibit the unused $s registers, since they 20505 are call-saved, and saving them via a MIPS16 register would 20506 probably waste more time than just reloading the value. 20507 20508 We permit the $t temporary registers when optimizing for speed 20509 but not when optimizing for space because using them results in 20510 code that is larger (but faster) then not using them. We do 20511 allow $24 (t8) because it is used in CMP and CMPI instructions 20512 and $25 (t9) because it is used as the function call address in 20513 SVR4 PIC code. */ 20514 20515 fixed_regs[18] = 1; 20516 fixed_regs[19] = 1; 20517 fixed_regs[20] = 1; 20518 fixed_regs[21] = 1; 20519 fixed_regs[22] = 1; 20520 fixed_regs[23] = 1; 20521 fixed_regs[26] = 1; 20522 fixed_regs[27] = 1; 20523 fixed_regs[30] = 1; 20524 if (optimize_size) 20525 { 20526 fixed_regs[8] = 1; 20527 fixed_regs[9] = 1; 20528 fixed_regs[10] = 1; 20529 fixed_regs[11] = 1; 20530 fixed_regs[12] = 1; 20531 fixed_regs[13] = 1; 20532 fixed_regs[14] = 1; 20533 fixed_regs[15] = 1; 20534 } 20535 20536 /* Do not allow HI and LO to be treated as register operands. 20537 There are no MTHI or MTLO instructions (or any real need 20538 for them) and one-way registers cannot easily be reloaded. */ 20539 operand_reg_set &= ~reg_class_contents[MD_REGS]; 20540 } 20541 /* $f20-$f23 are call-clobbered for n64. */ 20542 if (mips_abi == ABI_64) 20543 { 20544 int regno; 20545 for (regno = FP_REG_FIRST + 20; regno < FP_REG_FIRST + 24; regno++) 20546 call_used_regs[regno] = 1; 20547 } 20548 /* Odd registers in the range $f21-$f31 (inclusive) are call-clobbered 20549 for n32 and o32 FP64. */ 20550 if (mips_abi == ABI_N32 20551 || (mips_abi == ABI_32 20552 && TARGET_FLOAT64)) 20553 { 20554 int regno; 20555 for (regno = FP_REG_FIRST + 21; regno <= FP_REG_FIRST + 31; regno+=2) 20556 call_used_regs[regno] = 1; 20557 } 20558 /* Make sure that double-register accumulator values are correctly 20559 ordered for the current endianness. */ 20560 if (TARGET_LITTLE_ENDIAN) 20561 { 20562 unsigned int regno; 20563 20564 mips_swap_registers (MD_REG_FIRST); 20565 for (regno = DSP_ACC_REG_FIRST; regno <= DSP_ACC_REG_LAST; regno += 2) 20566 mips_swap_registers (regno); 20567 } 20568 } 20569 20570 /* Implement EH_USES. */ 20571 20572 bool 20573 mips_eh_uses (unsigned int regno) 20574 { 20575 if (reload_completed && !TARGET_ABSOLUTE_JUMPS) 20576 { 20577 /* We need to force certain registers to be live in order to handle 20578 PIC long branches correctly. See mips_must_initialize_gp_p for 20579 details. */ 20580 if (mips_cfun_has_cprestore_slot_p ()) 20581 { 20582 if (regno == CPRESTORE_SLOT_REGNUM) 20583 return true; 20584 } 20585 else 20586 { 20587 if (cfun->machine->global_pointer == regno) 20588 return true; 20589 } 20590 } 20591 20592 return false; 20593 } 20594 20595 /* Implement EPILOGUE_USES. */ 20596 20597 bool 20598 mips_epilogue_uses (unsigned int regno) 20599 { 20600 /* Say that the epilogue uses the return address register. Note that 20601 in the case of sibcalls, the values "used by the epilogue" are 20602 considered live at the start of the called function. */ 20603 if (regno == RETURN_ADDR_REGNUM) 20604 return true; 20605 20606 /* If using a GOT, say that the epilogue also uses GOT_VERSION_REGNUM. 20607 See the comment above load_call<mode> for details. */ 20608 if (TARGET_USE_GOT && (regno) == GOT_VERSION_REGNUM) 20609 return true; 20610 20611 /* An interrupt handler must preserve some registers that are 20612 ordinarily call-clobbered. */ 20613 if (cfun->machine->interrupt_handler_p 20614 && mips_interrupt_extra_call_saved_reg_p (regno)) 20615 return true; 20616 20617 return false; 20618 } 20619 20620 /* Return true if INSN needs to be wrapped in ".set noat". 20621 INSN has NOPERANDS operands, stored in OPVEC. */ 20622 20623 static bool 20624 mips_need_noat_wrapper_p (rtx_insn *insn, rtx *opvec, int noperands) 20625 { 20626 if (recog_memoized (insn) >= 0) 20627 { 20628 subrtx_iterator::array_type array; 20629 for (int i = 0; i < noperands; i++) 20630 FOR_EACH_SUBRTX (iter, array, opvec[i], NONCONST) 20631 if (REG_P (*iter) && REGNO (*iter) == AT_REGNUM) 20632 return true; 20633 } 20634 return false; 20635 } 20636 20637 /* Implement FINAL_PRESCAN_INSN. Mark MIPS16 inline constant pools 20638 as data for the purpose of disassembly. For simplicity embed the 20639 pool's initial label number in the local symbol produced so that 20640 multiple pools within a single function end up marked with unique 20641 symbols. The label number is carried by the `consttable' insn 20642 emitted at the beginning of each pool. */ 20643 20644 void 20645 mips_final_prescan_insn (rtx_insn *insn, rtx *opvec, int noperands) 20646 { 20647 if (INSN_P (insn) 20648 && GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE 20649 && XINT (PATTERN (insn), 1) == UNSPEC_CONSTTABLE) 20650 mips_set_text_contents_type (asm_out_file, "__pool_", 20651 INTVAL (XVECEXP (PATTERN (insn), 0, 0)), 20652 FALSE); 20653 20654 if (mips_need_noat_wrapper_p (insn, opvec, noperands)) 20655 mips_push_asm_switch (&mips_noat); 20656 } 20657 20658 /* Implement TARGET_ASM_FINAL_POSTSCAN_INSN. Reset text marking to 20659 code after a MIPS16 inline constant pool. Like with the beginning 20660 of a pool table use the pool's initial label number to keep symbols 20661 unique. The label number is carried by the `consttable_end' insn 20662 emitted at the end of each pool. */ 20663 20664 static void 20665 mips_final_postscan_insn (FILE *file ATTRIBUTE_UNUSED, rtx_insn *insn, 20666 rtx *opvec, int noperands) 20667 { 20668 if (mips_need_noat_wrapper_p (insn, opvec, noperands)) 20669 mips_pop_asm_switch (&mips_noat); 20670 20671 if (INSN_P (insn) 20672 && GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE 20673 && XINT (PATTERN (insn), 1) == UNSPEC_CONSTTABLE_END) 20674 { 20675 rtx_insn *next_insn = next_real_nondebug_insn (insn); 20676 bool code_p = (next_insn != NULL 20677 && INSN_P (next_insn) 20678 && (GET_CODE (PATTERN (next_insn)) != UNSPEC_VOLATILE 20679 || XINT (PATTERN (next_insn), 1) != UNSPEC_CONSTTABLE)); 20680 20681 /* Switch content type depending on whether there is code beyond 20682 the constant pool. */ 20683 mips_set_text_contents_type (asm_out_file, "__pend_", 20684 INTVAL (XVECEXP (PATTERN (insn), 0, 0)), 20685 code_p); 20686 } 20687 } 20688 20689 /* Return the function that is used to expand the <u>mulsidi3 pattern. 20690 EXT_CODE is the code of the extension used. Return NULL if widening 20691 multiplication shouldn't be used. */ 20692 20693 mulsidi3_gen_fn 20694 mips_mulsidi3_gen_fn (enum rtx_code ext_code) 20695 { 20696 bool signed_p; 20697 20698 signed_p = ext_code == SIGN_EXTEND; 20699 if (TARGET_64BIT) 20700 { 20701 /* Don't use widening multiplication with MULT when we have DMUL. Even 20702 with the extension of its input operands DMUL is faster. Note that 20703 the extension is not needed for signed multiplication. In order to 20704 ensure that we always remove the redundant sign-extension in this 20705 case we still expand mulsidi3 for DMUL. */ 20706 if (ISA_HAS_R6DMUL) 20707 return signed_p ? gen_mulsidi3_64bit_r6dmul : NULL; 20708 if (ISA_HAS_DMUL3) 20709 return signed_p ? gen_mulsidi3_64bit_dmul : NULL; 20710 if (TARGET_MIPS16) 20711 return (signed_p 20712 ? gen_mulsidi3_64bit_mips16 20713 : gen_umulsidi3_64bit_mips16); 20714 if (TARGET_FIX_R4000) 20715 return NULL; 20716 return signed_p ? gen_mulsidi3_64bit : gen_umulsidi3_64bit; 20717 } 20718 else 20719 { 20720 if (ISA_HAS_R6MUL) 20721 return (signed_p ? gen_mulsidi3_32bit_r6 : gen_umulsidi3_32bit_r6); 20722 if (TARGET_MIPS16) 20723 return (signed_p 20724 ? gen_mulsidi3_32bit_mips16 20725 : gen_umulsidi3_32bit_mips16); 20726 if (TARGET_FIX_R4000 && !ISA_HAS_DSP) 20727 return signed_p ? gen_mulsidi3_32bit_r4000 : gen_umulsidi3_32bit_r4000; 20728 return signed_p ? gen_mulsidi3_32bit : gen_umulsidi3_32bit; 20729 } 20730 } 20731 20732 /* Return true if PATTERN matches the kind of instruction generated by 20733 umips_build_save_restore. SAVE_P is true for store. */ 20734 20735 bool 20736 umips_save_restore_pattern_p (bool save_p, rtx pattern) 20737 { 20738 int n; 20739 unsigned int i; 20740 HOST_WIDE_INT first_offset = 0; 20741 rtx first_base = 0; 20742 unsigned int regmask = 0; 20743 20744 for (n = 0; n < XVECLEN (pattern, 0); n++) 20745 { 20746 rtx set, reg, mem, this_base; 20747 HOST_WIDE_INT this_offset; 20748 20749 /* Check that we have a SET. */ 20750 set = XVECEXP (pattern, 0, n); 20751 if (GET_CODE (set) != SET) 20752 return false; 20753 20754 /* Check that the SET is a load (if restoring) or a store 20755 (if saving). */ 20756 mem = save_p ? SET_DEST (set) : SET_SRC (set); 20757 if (!MEM_P (mem) || MEM_VOLATILE_P (mem)) 20758 return false; 20759 20760 /* Check that the address is the sum of base and a possibly-zero 20761 constant offset. Determine if the offset is in range. */ 20762 mips_split_plus (XEXP (mem, 0), &this_base, &this_offset); 20763 if (!REG_P (this_base)) 20764 return false; 20765 20766 if (n == 0) 20767 { 20768 if (!UMIPS_12BIT_OFFSET_P (this_offset)) 20769 return false; 20770 first_base = this_base; 20771 first_offset = this_offset; 20772 } 20773 else 20774 { 20775 /* Check that the save slots are consecutive. */ 20776 if (REGNO (this_base) != REGNO (first_base) 20777 || this_offset != first_offset + UNITS_PER_WORD * n) 20778 return false; 20779 } 20780 20781 /* Check that SET's other operand is a register. */ 20782 reg = save_p ? SET_SRC (set) : SET_DEST (set); 20783 if (!REG_P (reg)) 20784 return false; 20785 20786 regmask |= 1 << REGNO (reg); 20787 } 20788 20789 for (i = 0; i < ARRAY_SIZE (umips_swm_mask); i++) 20790 if (regmask == umips_swm_mask[i]) 20791 return true; 20792 20793 return false; 20794 } 20795 20796 /* Return the assembly instruction for microMIPS LWM or SWM. 20797 SAVE_P and PATTERN are as for umips_save_restore_pattern_p. */ 20798 20799 const char * 20800 umips_output_save_restore (bool save_p, rtx pattern) 20801 { 20802 static char buffer[300]; 20803 char *s; 20804 int n; 20805 HOST_WIDE_INT offset; 20806 rtx base, mem, set, last_set, last_reg; 20807 20808 /* Parse the pattern. */ 20809 gcc_assert (umips_save_restore_pattern_p (save_p, pattern)); 20810 20811 s = strcpy (buffer, save_p ? "swm\t" : "lwm\t"); 20812 s += strlen (s); 20813 n = XVECLEN (pattern, 0); 20814 20815 set = XVECEXP (pattern, 0, 0); 20816 mem = save_p ? SET_DEST (set) : SET_SRC (set); 20817 mips_split_plus (XEXP (mem, 0), &base, &offset); 20818 20819 last_set = XVECEXP (pattern, 0, n - 1); 20820 last_reg = save_p ? SET_SRC (last_set) : SET_DEST (last_set); 20821 20822 if (REGNO (last_reg) == 31) 20823 n--; 20824 20825 gcc_assert (n <= 9); 20826 if (n == 0) 20827 ; 20828 else if (n == 1) 20829 s += sprintf (s, "%s,", reg_names[16]); 20830 else if (n < 9) 20831 s += sprintf (s, "%s-%s,", reg_names[16], reg_names[15 + n]); 20832 else if (n == 9) 20833 s += sprintf (s, "%s-%s,%s,", reg_names[16], reg_names[23], 20834 reg_names[30]); 20835 20836 if (REGNO (last_reg) == 31) 20837 s += sprintf (s, "%s,", reg_names[31]); 20838 20839 s += sprintf (s, "%d(%s)", (int)offset, reg_names[REGNO (base)]); 20840 return buffer; 20841 } 20842 20843 /* Return true if MEM1 and MEM2 use the same base register, and the 20844 offset of MEM2 equals the offset of MEM1 plus 4. FIRST_REG is the 20845 register into (from) which the contents of MEM1 will be loaded 20846 (stored), depending on the value of LOAD_P. 20847 SWAP_P is true when the 1st and 2nd instructions are swapped. */ 20848 20849 static bool 20850 umips_load_store_pair_p_1 (bool load_p, bool swap_p, 20851 rtx first_reg, rtx mem1, rtx mem2) 20852 { 20853 rtx base1, base2; 20854 HOST_WIDE_INT offset1, offset2; 20855 20856 if (!MEM_P (mem1) || !MEM_P (mem2)) 20857 return false; 20858 20859 mips_split_plus (XEXP (mem1, 0), &base1, &offset1); 20860 mips_split_plus (XEXP (mem2, 0), &base2, &offset2); 20861 20862 if (!REG_P (base1) || !rtx_equal_p (base1, base2)) 20863 return false; 20864 20865 /* Avoid invalid load pair instructions. */ 20866 if (load_p && REGNO (first_reg) == REGNO (base1)) 20867 return false; 20868 20869 /* We must avoid this case for anti-dependence. 20870 Ex: lw $3, 4($3) 20871 lw $2, 0($3) 20872 first_reg is $2, but the base is $3. */ 20873 if (load_p 20874 && swap_p 20875 && REGNO (first_reg) + 1 == REGNO (base1)) 20876 return false; 20877 20878 if (offset2 != offset1 + 4) 20879 return false; 20880 20881 if (!UMIPS_12BIT_OFFSET_P (offset1)) 20882 return false; 20883 20884 return true; 20885 } 20886 20887 bool 20888 mips_load_store_bonding_p (rtx *operands, machine_mode mode, bool load_p) 20889 { 20890 rtx reg1, reg2, mem1, mem2, base1, base2; 20891 enum reg_class rc1, rc2; 20892 HOST_WIDE_INT offset1, offset2; 20893 20894 if (load_p) 20895 { 20896 reg1 = operands[0]; 20897 reg2 = operands[2]; 20898 mem1 = operands[1]; 20899 mem2 = operands[3]; 20900 } 20901 else 20902 { 20903 reg1 = operands[1]; 20904 reg2 = operands[3]; 20905 mem1 = operands[0]; 20906 mem2 = operands[2]; 20907 } 20908 20909 if (mips_address_insns (XEXP (mem1, 0), mode, false) == 0 20910 || mips_address_insns (XEXP (mem2, 0), mode, false) == 0) 20911 return false; 20912 20913 mips_split_plus (XEXP (mem1, 0), &base1, &offset1); 20914 mips_split_plus (XEXP (mem2, 0), &base2, &offset2); 20915 20916 /* Base regs do not match. */ 20917 if (!REG_P (base1) || !rtx_equal_p (base1, base2)) 20918 return false; 20919 20920 /* Either of the loads is clobbering base register. It is legitimate to bond 20921 loads if second load clobbers base register. However, hardware does not 20922 support such bonding. */ 20923 if (load_p 20924 && (REGNO (reg1) == REGNO (base1) 20925 || (REGNO (reg2) == REGNO (base1)))) 20926 return false; 20927 20928 /* Loading in same registers. */ 20929 if (load_p 20930 && REGNO (reg1) == REGNO (reg2)) 20931 return false; 20932 20933 /* The loads/stores are not of same type. */ 20934 rc1 = REGNO_REG_CLASS (REGNO (reg1)); 20935 rc2 = REGNO_REG_CLASS (REGNO (reg2)); 20936 if (rc1 != rc2 20937 && !reg_class_subset_p (rc1, rc2) 20938 && !reg_class_subset_p (rc2, rc1)) 20939 return false; 20940 20941 if (abs (offset1 - offset2) != GET_MODE_SIZE (mode)) 20942 return false; 20943 20944 return true; 20945 } 20946 20947 /* OPERANDS describes the operands to a pair of SETs, in the order 20948 dest1, src1, dest2, src2. Return true if the operands can be used 20949 in an LWP or SWP instruction; LOAD_P says which. */ 20950 20951 bool 20952 umips_load_store_pair_p (bool load_p, rtx *operands) 20953 { 20954 rtx reg1, reg2, mem1, mem2; 20955 20956 if (load_p) 20957 { 20958 reg1 = operands[0]; 20959 reg2 = operands[2]; 20960 mem1 = operands[1]; 20961 mem2 = operands[3]; 20962 } 20963 else 20964 { 20965 reg1 = operands[1]; 20966 reg2 = operands[3]; 20967 mem1 = operands[0]; 20968 mem2 = operands[2]; 20969 } 20970 20971 if (REGNO (reg2) == REGNO (reg1) + 1) 20972 return umips_load_store_pair_p_1 (load_p, false, reg1, mem1, mem2); 20973 20974 if (REGNO (reg1) == REGNO (reg2) + 1) 20975 return umips_load_store_pair_p_1 (load_p, true, reg2, mem2, mem1); 20976 20977 return false; 20978 } 20979 20980 /* Return the assembly instruction for a microMIPS LWP or SWP in which 20981 the first register is REG and the first memory slot is MEM. 20982 LOAD_P is true for LWP. */ 20983 20984 static void 20985 umips_output_load_store_pair_1 (bool load_p, rtx reg, rtx mem) 20986 { 20987 rtx ops[] = {reg, mem}; 20988 20989 if (load_p) 20990 output_asm_insn ("lwp\t%0,%1", ops); 20991 else 20992 output_asm_insn ("swp\t%0,%1", ops); 20993 } 20994 20995 /* Output the assembly instruction for a microMIPS LWP or SWP instruction. 20996 LOAD_P and OPERANDS are as for umips_load_store_pair_p. */ 20997 20998 void 20999 umips_output_load_store_pair (bool load_p, rtx *operands) 21000 { 21001 rtx reg1, reg2, mem1, mem2; 21002 if (load_p) 21003 { 21004 reg1 = operands[0]; 21005 reg2 = operands[2]; 21006 mem1 = operands[1]; 21007 mem2 = operands[3]; 21008 } 21009 else 21010 { 21011 reg1 = operands[1]; 21012 reg2 = operands[3]; 21013 mem1 = operands[0]; 21014 mem2 = operands[2]; 21015 } 21016 21017 if (REGNO (reg2) == REGNO (reg1) + 1) 21018 { 21019 umips_output_load_store_pair_1 (load_p, reg1, mem1); 21020 return; 21021 } 21022 21023 gcc_assert (REGNO (reg1) == REGNO (reg2) + 1); 21024 umips_output_load_store_pair_1 (load_p, reg2, mem2); 21025 } 21026 21027 /* Return true if REG1 and REG2 match the criteria for a movep insn. */ 21028 21029 bool 21030 umips_movep_target_p (rtx reg1, rtx reg2) 21031 { 21032 int regno1, regno2, pair; 21033 unsigned int i; 21034 static const int match[8] = { 21035 0x00000060, /* 5, 6 */ 21036 0x000000a0, /* 5, 7 */ 21037 0x000000c0, /* 6, 7 */ 21038 0x00200010, /* 4, 21 */ 21039 0x00400010, /* 4, 22 */ 21040 0x00000030, /* 4, 5 */ 21041 0x00000050, /* 4, 6 */ 21042 0x00000090 /* 4, 7 */ 21043 }; 21044 21045 if (!REG_P (reg1) || !REG_P (reg2)) 21046 return false; 21047 21048 regno1 = REGNO (reg1); 21049 regno2 = REGNO (reg2); 21050 21051 if (!GP_REG_P (regno1) || !GP_REG_P (regno2)) 21052 return false; 21053 21054 pair = (1 << regno1) | (1 << regno2); 21055 21056 for (i = 0; i < ARRAY_SIZE (match); i++) 21057 if (pair == match[i]) 21058 return true; 21059 21060 return false; 21061 } 21062 21063 /* Return the size in bytes of the trampoline code, padded to 21064 TRAMPOLINE_ALIGNMENT bits. The static chain pointer and target 21065 function address immediately follow. */ 21066 21067 int 21068 mips_trampoline_code_size (void) 21069 { 21070 if (TARGET_USE_PIC_FN_ADDR_REG) 21071 return 4 * 4; 21072 else if (ptr_mode == DImode) 21073 return 8 * 4; 21074 else if (ISA_HAS_LOAD_DELAY) 21075 return 6 * 4; 21076 else 21077 return 4 * 4; 21078 } 21079 21080 /* Implement TARGET_TRAMPOLINE_INIT. */ 21081 21082 static void 21083 mips_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) 21084 { 21085 rtx addr, end_addr, high, low, opcode, mem; 21086 rtx trampoline[8]; 21087 unsigned int i, j; 21088 HOST_WIDE_INT end_addr_offset, static_chain_offset, target_function_offset; 21089 21090 /* Work out the offsets of the pointers from the start of the 21091 trampoline code. */ 21092 end_addr_offset = mips_trampoline_code_size (); 21093 static_chain_offset = end_addr_offset; 21094 target_function_offset = static_chain_offset + GET_MODE_SIZE (ptr_mode); 21095 21096 /* Get pointers to the beginning and end of the code block. */ 21097 addr = force_reg (Pmode, XEXP (m_tramp, 0)); 21098 end_addr = mips_force_binary (Pmode, PLUS, addr, GEN_INT (end_addr_offset)); 21099 21100 #define OP(X) gen_int_mode (X, SImode) 21101 21102 /* Build up the code in TRAMPOLINE. */ 21103 i = 0; 21104 if (TARGET_USE_PIC_FN_ADDR_REG) 21105 { 21106 /* $25 contains the address of the trampoline. Emit code of the form: 21107 21108 l[wd] $1, target_function_offset($25) 21109 l[wd] $static_chain, static_chain_offset($25) 21110 jr $1 21111 move $25,$1. */ 21112 trampoline[i++] = OP (MIPS_LOAD_PTR (AT_REGNUM, 21113 target_function_offset, 21114 PIC_FUNCTION_ADDR_REGNUM)); 21115 trampoline[i++] = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM, 21116 static_chain_offset, 21117 PIC_FUNCTION_ADDR_REGNUM)); 21118 trampoline[i++] = OP (MIPS_JR (AT_REGNUM)); 21119 trampoline[i++] = OP (MIPS_MOVE (PIC_FUNCTION_ADDR_REGNUM, AT_REGNUM)); 21120 } 21121 else if (ptr_mode == DImode) 21122 { 21123 /* It's too cumbersome to create the full 64-bit address, so let's 21124 instead use: 21125 21126 move $1, $31 21127 bal 1f 21128 nop 21129 1: l[wd] $25, target_function_offset - 12($31) 21130 l[wd] $static_chain, static_chain_offset - 12($31) 21131 jr $25 21132 move $31, $1 21133 21134 where 12 is the offset of "1:" from the start of the code block. */ 21135 trampoline[i++] = OP (MIPS_MOVE (AT_REGNUM, RETURN_ADDR_REGNUM)); 21136 trampoline[i++] = OP (MIPS_BAL (1)); 21137 trampoline[i++] = OP (MIPS_NOP); 21138 trampoline[i++] = OP (MIPS_LOAD_PTR (PIC_FUNCTION_ADDR_REGNUM, 21139 target_function_offset - 12, 21140 RETURN_ADDR_REGNUM)); 21141 trampoline[i++] = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM, 21142 static_chain_offset - 12, 21143 RETURN_ADDR_REGNUM)); 21144 trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM)); 21145 trampoline[i++] = OP (MIPS_MOVE (RETURN_ADDR_REGNUM, AT_REGNUM)); 21146 } 21147 else 21148 { 21149 /* If the target has load delays, emit: 21150 21151 lui $1, %hi(end_addr) 21152 lw $25, %lo(end_addr + ...)($1) 21153 lw $static_chain, %lo(end_addr + ...)($1) 21154 jr $25 21155 nop 21156 21157 Otherwise emit: 21158 21159 lui $1, %hi(end_addr) 21160 lw $25, %lo(end_addr + ...)($1) 21161 jr $25 21162 lw $static_chain, %lo(end_addr + ...)($1). */ 21163 21164 /* Split END_ADDR into %hi and %lo values. Trampolines are aligned 21165 to 64 bits, so the %lo value will have the bottom 3 bits clear. */ 21166 high = expand_simple_binop (SImode, PLUS, end_addr, GEN_INT (0x8000), 21167 NULL, false, OPTAB_WIDEN); 21168 high = expand_simple_binop (SImode, LSHIFTRT, high, GEN_INT (16), 21169 NULL, false, OPTAB_WIDEN); 21170 low = convert_to_mode (SImode, gen_lowpart (HImode, end_addr), true); 21171 21172 /* Emit the LUI. */ 21173 opcode = OP (MIPS_LUI (AT_REGNUM, 0)); 21174 trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, high, 21175 NULL, false, OPTAB_WIDEN); 21176 21177 /* Emit the load of the target function. */ 21178 opcode = OP (MIPS_LOAD_PTR (PIC_FUNCTION_ADDR_REGNUM, 21179 target_function_offset - end_addr_offset, 21180 AT_REGNUM)); 21181 trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low, 21182 NULL, false, OPTAB_WIDEN); 21183 21184 /* Emit the JR here, if we can. */ 21185 if (!ISA_HAS_LOAD_DELAY) 21186 trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM)); 21187 21188 /* Emit the load of the static chain register. */ 21189 opcode = OP (MIPS_LOAD_PTR (STATIC_CHAIN_REGNUM, 21190 static_chain_offset - end_addr_offset, 21191 AT_REGNUM)); 21192 trampoline[i++] = expand_simple_binop (SImode, IOR, opcode, low, 21193 NULL, false, OPTAB_WIDEN); 21194 21195 /* Emit the JR, if we couldn't above. */ 21196 if (ISA_HAS_LOAD_DELAY) 21197 { 21198 trampoline[i++] = OP (MIPS_JR (PIC_FUNCTION_ADDR_REGNUM)); 21199 trampoline[i++] = OP (MIPS_NOP); 21200 } 21201 } 21202 21203 #undef OP 21204 21205 /* If we are using compact branches we don't have delay slots so 21206 place the instruction that was in the delay slot before the JRC 21207 instruction. */ 21208 21209 if (TARGET_CB_ALWAYS) 21210 { 21211 rtx temp; 21212 temp = trampoline[i-2]; 21213 trampoline[i-2] = trampoline[i-1]; 21214 trampoline[i-1] = temp; 21215 } 21216 21217 /* Copy the trampoline code. Leave any padding uninitialized. */ 21218 for (j = 0; j < i; j++) 21219 { 21220 mem = adjust_address (m_tramp, SImode, j * GET_MODE_SIZE (SImode)); 21221 mips_emit_move (mem, trampoline[j]); 21222 } 21223 21224 /* Set up the static chain pointer field. */ 21225 mem = adjust_address (m_tramp, ptr_mode, static_chain_offset); 21226 mips_emit_move (mem, chain_value); 21227 21228 /* Set up the target function field. */ 21229 mem = adjust_address (m_tramp, ptr_mode, target_function_offset); 21230 mips_emit_move (mem, XEXP (DECL_RTL (fndecl), 0)); 21231 21232 /* Flush the code part of the trampoline. */ 21233 emit_insn (gen_add3_insn (end_addr, addr, GEN_INT (TRAMPOLINE_SIZE))); 21234 emit_insn (gen_clear_cache (addr, end_addr)); 21235 } 21236 21237 /* Implement FUNCTION_PROFILER. */ 21238 21239 void mips_function_profiler (FILE *file) 21240 { 21241 if (TARGET_MIPS16) 21242 sorry ("mips16 function profiling"); 21243 if (TARGET_LONG_CALLS) 21244 { 21245 /* For TARGET_LONG_CALLS use $3 for the address of _mcount. */ 21246 if (Pmode == DImode) 21247 fprintf (file, "\tdla\t%s,_mcount\n", reg_names[3]); 21248 else 21249 fprintf (file, "\tla\t%s,_mcount\n", reg_names[3]); 21250 } 21251 mips_push_asm_switch (&mips_noat); 21252 fprintf (file, "\tmove\t%s,%s\t\t# save current return address\n", 21253 reg_names[AT_REGNUM], reg_names[RETURN_ADDR_REGNUM]); 21254 /* _mcount treats $2 as the static chain register. */ 21255 if (cfun->static_chain_decl != NULL) 21256 fprintf (file, "\tmove\t%s,%s\n", reg_names[2], 21257 reg_names[STATIC_CHAIN_REGNUM]); 21258 if (TARGET_MCOUNT_RA_ADDRESS) 21259 { 21260 /* If TARGET_MCOUNT_RA_ADDRESS load $12 with the address of the 21261 ra save location. */ 21262 if (cfun->machine->frame.ra_fp_offset == 0) 21263 /* ra not saved, pass zero. */ 21264 fprintf (file, "\tmove\t%s,%s\n", reg_names[12], reg_names[0]); 21265 else 21266 fprintf (file, "\t%s\t%s," HOST_WIDE_INT_PRINT_DEC "(%s)\n", 21267 Pmode == DImode ? "dla" : "la", reg_names[12], 21268 cfun->machine->frame.ra_fp_offset, 21269 reg_names[STACK_POINTER_REGNUM]); 21270 } 21271 if (!TARGET_NEWABI) 21272 fprintf (file, 21273 "\t%s\t%s,%s,%d\t\t# _mcount pops 2 words from stack\n", 21274 TARGET_64BIT ? "dsubu" : "subu", 21275 reg_names[STACK_POINTER_REGNUM], 21276 reg_names[STACK_POINTER_REGNUM], 21277 Pmode == DImode ? 16 : 8); 21278 21279 if (TARGET_LONG_CALLS) 21280 fprintf (file, "\tjalr\t%s\n", reg_names[3]); 21281 else 21282 fprintf (file, "\tjal\t_mcount\n"); 21283 mips_pop_asm_switch (&mips_noat); 21284 /* _mcount treats $2 as the static chain register. */ 21285 if (cfun->static_chain_decl != NULL) 21286 fprintf (file, "\tmove\t%s,%s\n", reg_names[STATIC_CHAIN_REGNUM], 21287 reg_names[2]); 21288 } 21289 21290 /* Implement TARGET_SHIFT_TRUNCATION_MASK. We want to keep the default 21291 behavior of TARGET_SHIFT_TRUNCATION_MASK for non-vector modes even 21292 when TARGET_LOONGSON_MMI is true. */ 21293 21294 static unsigned HOST_WIDE_INT 21295 mips_shift_truncation_mask (machine_mode mode) 21296 { 21297 if (TARGET_LOONGSON_MMI && VECTOR_MODE_P (mode)) 21298 return 0; 21299 21300 return GET_MODE_BITSIZE (mode) - 1; 21301 } 21302 21303 /* Implement TARGET_PREPARE_PCH_SAVE. */ 21304 21305 static void 21306 mips_prepare_pch_save (void) 21307 { 21308 /* We are called in a context where the current compression vs. 21309 non-compression setting should be irrelevant. The question then is: 21310 which setting makes most sense at load time? 21311 21312 The PCH is loaded before the first token is read. We should never have 21313 switched into a compression mode by that point, and thus should not have 21314 populated mips16_globals or micromips_globals. Nor can we load the 21315 entire contents of mips16_globals or micromips_globals from the PCH file, 21316 because they contain a combination of GGC and non-GGC data. 21317 21318 There is therefore no point in trying save the GGC part of 21319 mips16_globals/micromips_globals to the PCH file, or to preserve a 21320 compression setting across the PCH save and load. The loading compiler 21321 would not have access to the non-GGC parts of mips16_globals or 21322 micromips_globals (either from the PCH file, or from a copy that the 21323 loading compiler generated itself) and would have to call target_reinit 21324 anyway. 21325 21326 It therefore seems best to switch back to non-MIPS16 mode and 21327 non-microMIPS mode to save time, and to ensure that mips16_globals and 21328 micromips_globals remain null after a PCH load. */ 21329 mips_set_compression_mode (0); 21330 mips16_globals = 0; 21331 micromips_globals = 0; 21332 } 21333 21334 /* Generate or test for an insn that supports a constant permutation. */ 21335 21336 #define MAX_VECT_LEN 16 21337 21338 struct expand_vec_perm_d 21339 { 21340 rtx target, op0, op1; 21341 unsigned char perm[MAX_VECT_LEN]; 21342 machine_mode vmode; 21343 unsigned char nelt; 21344 bool one_vector_p; 21345 bool testing_p; 21346 }; 21347 21348 /* Construct (set target (vec_select op0 (parallel perm))) and 21349 return true if that's a valid instruction in the active ISA. */ 21350 21351 static bool 21352 mips_expand_vselect (rtx target, rtx op0, 21353 const unsigned char *perm, unsigned nelt) 21354 { 21355 rtx rperm[MAX_VECT_LEN], x; 21356 rtx_insn *insn; 21357 unsigned i; 21358 21359 for (i = 0; i < nelt; ++i) 21360 rperm[i] = GEN_INT (perm[i]); 21361 21362 x = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, rperm)); 21363 x = gen_rtx_VEC_SELECT (GET_MODE (target), op0, x); 21364 x = gen_rtx_SET (target, x); 21365 21366 insn = emit_insn (x); 21367 if (recog_memoized (insn) < 0) 21368 { 21369 remove_insn (insn); 21370 return false; 21371 } 21372 return true; 21373 } 21374 21375 /* Similar, but generate a vec_concat from op0 and op1 as well. */ 21376 21377 static bool 21378 mips_expand_vselect_vconcat (rtx target, rtx op0, rtx op1, 21379 const unsigned char *perm, unsigned nelt) 21380 { 21381 machine_mode v2mode; 21382 rtx x; 21383 21384 if (!GET_MODE_2XWIDER_MODE (GET_MODE (op0)).exists (&v2mode)) 21385 return false; 21386 x = gen_rtx_VEC_CONCAT (v2mode, op0, op1); 21387 return mips_expand_vselect (target, x, perm, nelt); 21388 } 21389 21390 /* Recognize patterns for even-odd extraction. */ 21391 21392 static bool 21393 mips_expand_vpc_loongson_even_odd (struct expand_vec_perm_d *d) 21394 { 21395 unsigned i, odd, nelt = d->nelt; 21396 rtx t0, t1, t2, t3; 21397 21398 if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI)) 21399 return false; 21400 /* Even-odd for V2SI/V2SFmode is matched by interleave directly. */ 21401 if (nelt < 4) 21402 return false; 21403 21404 odd = d->perm[0]; 21405 if (odd > 1) 21406 return false; 21407 for (i = 1; i < nelt; ++i) 21408 if (d->perm[i] != i * 2 + odd) 21409 return false; 21410 21411 if (d->testing_p) 21412 return true; 21413 21414 /* We need 2*log2(N)-1 operations to achieve odd/even with interleave. */ 21415 t0 = gen_reg_rtx (d->vmode); 21416 t1 = gen_reg_rtx (d->vmode); 21417 switch (d->vmode) 21418 { 21419 case E_V4HImode: 21420 emit_insn (gen_loongson_punpckhhw (t0, d->op0, d->op1)); 21421 emit_insn (gen_loongson_punpcklhw (t1, d->op0, d->op1)); 21422 if (odd) 21423 emit_insn (gen_loongson_punpckhhw (d->target, t1, t0)); 21424 else 21425 emit_insn (gen_loongson_punpcklhw (d->target, t1, t0)); 21426 break; 21427 21428 case E_V8QImode: 21429 t2 = gen_reg_rtx (d->vmode); 21430 t3 = gen_reg_rtx (d->vmode); 21431 emit_insn (gen_loongson_punpckhbh (t0, d->op0, d->op1)); 21432 emit_insn (gen_loongson_punpcklbh (t1, d->op0, d->op1)); 21433 emit_insn (gen_loongson_punpckhbh (t2, t1, t0)); 21434 emit_insn (gen_loongson_punpcklbh (t3, t1, t0)); 21435 if (odd) 21436 emit_insn (gen_loongson_punpckhbh (d->target, t3, t2)); 21437 else 21438 emit_insn (gen_loongson_punpcklbh (d->target, t3, t2)); 21439 break; 21440 21441 default: 21442 gcc_unreachable (); 21443 } 21444 return true; 21445 } 21446 21447 /* Recognize patterns for the Loongson PSHUFH instruction. */ 21448 21449 static bool 21450 mips_expand_vpc_loongson_pshufh (struct expand_vec_perm_d *d) 21451 { 21452 unsigned i, mask; 21453 rtx rmask; 21454 21455 if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI)) 21456 return false; 21457 if (d->vmode != V4HImode) 21458 return false; 21459 if (d->testing_p) 21460 return true; 21461 21462 /* Convert the selector into the packed 8-bit form for pshufh. */ 21463 /* Recall that loongson is little-endian only. No big-endian 21464 adjustment required. */ 21465 for (i = mask = 0; i < 4; i++) 21466 mask |= (d->perm[i] & 3) << (i * 2); 21467 rmask = force_reg (SImode, GEN_INT (mask)); 21468 21469 if (d->one_vector_p) 21470 emit_insn (gen_loongson_pshufh (d->target, d->op0, rmask)); 21471 else 21472 { 21473 rtx t0, t1, x, merge, rmerge[4]; 21474 21475 t0 = gen_reg_rtx (V4HImode); 21476 t1 = gen_reg_rtx (V4HImode); 21477 emit_insn (gen_loongson_pshufh (t1, d->op1, rmask)); 21478 emit_insn (gen_loongson_pshufh (t0, d->op0, rmask)); 21479 21480 for (i = 0; i < 4; ++i) 21481 rmerge[i] = (d->perm[i] & 4 ? constm1_rtx : const0_rtx); 21482 merge = gen_rtx_CONST_VECTOR (V4HImode, gen_rtvec_v (4, rmerge)); 21483 merge = force_reg (V4HImode, merge); 21484 21485 x = gen_rtx_AND (V4HImode, merge, t1); 21486 emit_insn (gen_rtx_SET (t1, x)); 21487 21488 x = gen_rtx_NOT (V4HImode, merge); 21489 x = gen_rtx_AND (V4HImode, x, t0); 21490 emit_insn (gen_rtx_SET (t0, x)); 21491 21492 x = gen_rtx_IOR (V4HImode, t0, t1); 21493 emit_insn (gen_rtx_SET (d->target, x)); 21494 } 21495 21496 return true; 21497 } 21498 21499 /* Recognize broadcast patterns for the Loongson. */ 21500 21501 static bool 21502 mips_expand_vpc_loongson_bcast (struct expand_vec_perm_d *d) 21503 { 21504 unsigned i, elt; 21505 rtx t0, t1; 21506 21507 if (!(TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI)) 21508 return false; 21509 /* Note that we've already matched V2SI via punpck and V4HI via pshufh. */ 21510 if (d->vmode != V8QImode) 21511 return false; 21512 if (!d->one_vector_p) 21513 return false; 21514 21515 elt = d->perm[0]; 21516 for (i = 1; i < 8; ++i) 21517 if (d->perm[i] != elt) 21518 return false; 21519 21520 if (d->testing_p) 21521 return true; 21522 21523 /* With one interleave we put two of the desired element adjacent. */ 21524 t0 = gen_reg_rtx (V8QImode); 21525 if (elt < 4) 21526 emit_insn (gen_loongson_punpcklbh (t0, d->op0, d->op0)); 21527 else 21528 emit_insn (gen_loongson_punpckhbh (t0, d->op0, d->op0)); 21529 21530 /* Shuffle that one HImode element into all locations. */ 21531 elt &= 3; 21532 elt *= 0x55; 21533 t1 = gen_reg_rtx (V4HImode); 21534 emit_insn (gen_loongson_pshufh (t1, gen_lowpart (V4HImode, t0), 21535 force_reg (SImode, GEN_INT (elt)))); 21536 21537 emit_move_insn (d->target, gen_lowpart (V8QImode, t1)); 21538 return true; 21539 } 21540 21541 /* Construct (set target (vec_select op0 (parallel selector))) and 21542 return true if that's a valid instruction in the active ISA. */ 21543 21544 static bool 21545 mips_expand_msa_shuffle (struct expand_vec_perm_d *d) 21546 { 21547 rtx x, elts[MAX_VECT_LEN]; 21548 rtvec v; 21549 rtx_insn *insn; 21550 unsigned i; 21551 21552 if (!ISA_HAS_MSA) 21553 return false; 21554 21555 for (i = 0; i < d->nelt; i++) 21556 elts[i] = GEN_INT (d->perm[i]); 21557 21558 v = gen_rtvec_v (d->nelt, elts); 21559 x = gen_rtx_PARALLEL (VOIDmode, v); 21560 21561 if (!mips_const_vector_shuffle_set_p (x, d->vmode)) 21562 return false; 21563 21564 x = gen_rtx_VEC_SELECT (d->vmode, d->op0, x); 21565 x = gen_rtx_SET (d->target, x); 21566 21567 insn = emit_insn (x); 21568 if (recog_memoized (insn) < 0) 21569 { 21570 remove_insn (insn); 21571 return false; 21572 } 21573 return true; 21574 } 21575 21576 static bool 21577 mips_expand_vec_perm_const_1 (struct expand_vec_perm_d *d) 21578 { 21579 unsigned int i, nelt = d->nelt; 21580 unsigned char perm2[MAX_VECT_LEN]; 21581 21582 if (d->one_vector_p) 21583 { 21584 /* Try interleave with alternating operands. */ 21585 memcpy (perm2, d->perm, sizeof(perm2)); 21586 for (i = 1; i < nelt; i += 2) 21587 perm2[i] += nelt; 21588 if (mips_expand_vselect_vconcat (d->target, d->op0, d->op1, perm2, nelt)) 21589 return true; 21590 } 21591 else 21592 { 21593 if (mips_expand_vselect_vconcat (d->target, d->op0, d->op1, 21594 d->perm, nelt)) 21595 return true; 21596 21597 /* Try again with swapped operands. */ 21598 for (i = 0; i < nelt; ++i) 21599 perm2[i] = (d->perm[i] + nelt) & (2 * nelt - 1); 21600 if (mips_expand_vselect_vconcat (d->target, d->op1, d->op0, perm2, nelt)) 21601 return true; 21602 } 21603 21604 if (mips_expand_vpc_loongson_even_odd (d)) 21605 return true; 21606 if (mips_expand_vpc_loongson_pshufh (d)) 21607 return true; 21608 if (mips_expand_vpc_loongson_bcast (d)) 21609 return true; 21610 if (mips_expand_msa_shuffle (d)) 21611 return true; 21612 return false; 21613 } 21614 21615 /* Implement TARGET_VECTORIZE_VEC_PERM_CONST. */ 21616 21617 static bool 21618 mips_vectorize_vec_perm_const (machine_mode vmode, rtx target, rtx op0, 21619 rtx op1, const vec_perm_indices &sel) 21620 { 21621 struct expand_vec_perm_d d; 21622 int i, nelt, which; 21623 unsigned char orig_perm[MAX_VECT_LEN]; 21624 bool ok; 21625 21626 d.target = target; 21627 d.op0 = op0; 21628 d.op1 = op1; 21629 21630 d.vmode = vmode; 21631 gcc_assert (VECTOR_MODE_P (vmode)); 21632 d.nelt = nelt = GET_MODE_NUNITS (vmode); 21633 d.testing_p = !target; 21634 21635 /* This is overly conservative, but ensures we don't get an 21636 uninitialized warning on ORIG_PERM. */ 21637 memset (orig_perm, 0, MAX_VECT_LEN); 21638 for (i = which = 0; i < nelt; ++i) 21639 { 21640 int ei = sel[i] & (2 * nelt - 1); 21641 which |= (ei < nelt ? 1 : 2); 21642 orig_perm[i] = ei; 21643 } 21644 memcpy (d.perm, orig_perm, MAX_VECT_LEN); 21645 21646 switch (which) 21647 { 21648 default: 21649 gcc_unreachable(); 21650 21651 case 3: 21652 d.one_vector_p = false; 21653 if (d.testing_p || !rtx_equal_p (d.op0, d.op1)) 21654 break; 21655 /* FALLTHRU */ 21656 21657 case 2: 21658 for (i = 0; i < nelt; ++i) 21659 d.perm[i] &= nelt - 1; 21660 d.op0 = d.op1; 21661 d.one_vector_p = true; 21662 break; 21663 21664 case 1: 21665 d.op1 = d.op0; 21666 d.one_vector_p = true; 21667 break; 21668 } 21669 21670 if (d.testing_p) 21671 { 21672 d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1); 21673 d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2); 21674 if (!d.one_vector_p) 21675 d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3); 21676 21677 start_sequence (); 21678 ok = mips_expand_vec_perm_const_1 (&d); 21679 end_sequence (); 21680 return ok; 21681 } 21682 21683 ok = mips_expand_vec_perm_const_1 (&d); 21684 21685 /* If we were given a two-vector permutation which just happened to 21686 have both input vectors equal, we folded this into a one-vector 21687 permutation. There are several loongson patterns that are matched 21688 via direct vec_select+vec_concat expansion, but we do not have 21689 support in mips_expand_vec_perm_const_1 to guess the adjustment 21690 that should be made for a single operand. Just try again with 21691 the original permutation. */ 21692 if (!ok && which == 3) 21693 { 21694 d.op0 = op0; 21695 d.op1 = op1; 21696 d.one_vector_p = false; 21697 memcpy (d.perm, orig_perm, MAX_VECT_LEN); 21698 ok = mips_expand_vec_perm_const_1 (&d); 21699 } 21700 21701 return ok; 21702 } 21703 21704 /* Implement TARGET_SCHED_REASSOCIATION_WIDTH. */ 21705 21706 static int 21707 mips_sched_reassociation_width (unsigned int opc ATTRIBUTE_UNUSED, 21708 machine_mode mode) 21709 { 21710 if (MSA_SUPPORTED_MODE_P (mode)) 21711 return 2; 21712 return 1; 21713 } 21714 21715 /* Expand an integral vector unpack operation. */ 21716 21717 void 21718 mips_expand_vec_unpack (rtx operands[2], bool unsigned_p, bool high_p) 21719 { 21720 machine_mode imode = GET_MODE (operands[1]); 21721 rtx (*unpack) (rtx, rtx, rtx); 21722 rtx (*cmpFunc) (rtx, rtx, rtx); 21723 rtx tmp, dest, zero; 21724 21725 if (ISA_HAS_MSA) 21726 { 21727 switch (imode) 21728 { 21729 case E_V4SImode: 21730 if (BYTES_BIG_ENDIAN != high_p) 21731 unpack = gen_msa_ilvl_w; 21732 else 21733 unpack = gen_msa_ilvr_w; 21734 21735 cmpFunc = gen_msa_clt_s_w; 21736 break; 21737 21738 case E_V8HImode: 21739 if (BYTES_BIG_ENDIAN != high_p) 21740 unpack = gen_msa_ilvl_h; 21741 else 21742 unpack = gen_msa_ilvr_h; 21743 21744 cmpFunc = gen_msa_clt_s_h; 21745 break; 21746 21747 case E_V16QImode: 21748 if (BYTES_BIG_ENDIAN != high_p) 21749 unpack = gen_msa_ilvl_b; 21750 else 21751 unpack = gen_msa_ilvr_b; 21752 21753 cmpFunc = gen_msa_clt_s_b; 21754 break; 21755 21756 default: 21757 gcc_unreachable (); 21758 break; 21759 } 21760 21761 if (!unsigned_p) 21762 { 21763 /* Extract sign extention for each element comparing each element 21764 with immediate zero. */ 21765 tmp = gen_reg_rtx (imode); 21766 emit_insn (cmpFunc (tmp, operands[1], CONST0_RTX (imode))); 21767 } 21768 else 21769 tmp = force_reg (imode, CONST0_RTX (imode)); 21770 21771 dest = gen_reg_rtx (imode); 21772 21773 emit_insn (unpack (dest, operands[1], tmp)); 21774 emit_move_insn (operands[0], gen_lowpart (GET_MODE (operands[0]), dest)); 21775 return; 21776 } 21777 21778 switch (imode) 21779 { 21780 case E_V8QImode: 21781 if (high_p) 21782 unpack = gen_loongson_punpckhbh; 21783 else 21784 unpack = gen_loongson_punpcklbh; 21785 cmpFunc = gen_loongson_pcmpgtb; 21786 break; 21787 case E_V4HImode: 21788 if (high_p) 21789 unpack = gen_loongson_punpckhhw; 21790 else 21791 unpack = gen_loongson_punpcklhw; 21792 cmpFunc = gen_loongson_pcmpgth; 21793 break; 21794 default: 21795 gcc_unreachable (); 21796 } 21797 21798 zero = force_reg (imode, CONST0_RTX (imode)); 21799 if (unsigned_p) 21800 tmp = zero; 21801 else 21802 { 21803 tmp = gen_reg_rtx (imode); 21804 emit_insn (cmpFunc (tmp, zero, operands[1])); 21805 } 21806 21807 dest = gen_reg_rtx (imode); 21808 emit_insn (unpack (dest, operands[1], tmp)); 21809 21810 emit_move_insn (operands[0], gen_lowpart (GET_MODE (operands[0]), dest)); 21811 } 21812 21813 /* Construct and return PARALLEL RTX with CONST_INTs for HIGH (high_p == TRUE) 21814 or LOW (high_p == FALSE) half of a vector for mode MODE. */ 21815 21816 rtx 21817 mips_msa_vec_parallel_const_half (machine_mode mode, bool high_p) 21818 { 21819 int nunits = GET_MODE_NUNITS (mode); 21820 rtvec v = rtvec_alloc (nunits / 2); 21821 int base; 21822 int i; 21823 21824 if (BYTES_BIG_ENDIAN) 21825 base = high_p ? 0 : nunits / 2; 21826 else 21827 base = high_p ? nunits / 2 : 0; 21828 21829 for (i = 0; i < nunits / 2; i++) 21830 RTVEC_ELT (v, i) = GEN_INT (base + i); 21831 21832 return gen_rtx_PARALLEL (VOIDmode, v); 21833 } 21834 21835 /* A subroutine of mips_expand_vec_init, match constant vector elements. */ 21836 21837 static inline bool 21838 mips_constant_elt_p (rtx x) 21839 { 21840 return CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE; 21841 } 21842 21843 /* A subroutine of mips_expand_vec_init, expand via broadcast. */ 21844 21845 static void 21846 mips_expand_vi_broadcast (machine_mode vmode, rtx target, rtx elt) 21847 { 21848 struct expand_vec_perm_d d; 21849 rtx t1; 21850 bool ok; 21851 21852 if (elt != const0_rtx) 21853 elt = force_reg (GET_MODE_INNER (vmode), elt); 21854 if (REG_P (elt)) 21855 elt = gen_lowpart (DImode, elt); 21856 21857 t1 = gen_reg_rtx (vmode); 21858 switch (vmode) 21859 { 21860 case E_V8QImode: 21861 emit_insn (gen_loongson_vec_init1_v8qi (t1, elt)); 21862 break; 21863 case E_V4HImode: 21864 emit_insn (gen_loongson_vec_init1_v4hi (t1, elt)); 21865 break; 21866 default: 21867 gcc_unreachable (); 21868 } 21869 21870 memset (&d, 0, sizeof (d)); 21871 d.target = target; 21872 d.op0 = t1; 21873 d.op1 = t1; 21874 d.vmode = vmode; 21875 d.nelt = GET_MODE_NUNITS (vmode); 21876 d.one_vector_p = true; 21877 21878 ok = mips_expand_vec_perm_const_1 (&d); 21879 gcc_assert (ok); 21880 } 21881 21882 /* Return a const_int vector of VAL with mode MODE. */ 21883 21884 rtx 21885 mips_gen_const_int_vector (machine_mode mode, HOST_WIDE_INT val) 21886 { 21887 rtx c = gen_int_mode (val, GET_MODE_INNER (mode)); 21888 return gen_const_vec_duplicate (mode, c); 21889 } 21890 21891 /* Return a vector of repeated 4-element sets generated from 21892 immediate VAL in mode MODE. */ 21893 21894 static rtx 21895 mips_gen_const_int_vector_shuffle (machine_mode mode, int val) 21896 { 21897 int nunits = GET_MODE_NUNITS (mode); 21898 int nsets = nunits / 4; 21899 rtx elts[MAX_VECT_LEN]; 21900 int set = 0; 21901 int i, j; 21902 21903 /* Generate a const_int vector replicating the same 4-element set 21904 from an immediate. */ 21905 for (j = 0; j < nsets; j++, set = 4 * j) 21906 for (i = 0; i < 4; i++) 21907 elts[set + i] = GEN_INT (set + ((val >> (2 * i)) & 0x3)); 21908 21909 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nunits, elts)); 21910 } 21911 21912 /* A subroutine of mips_expand_vec_init, replacing all of the non-constant 21913 elements of VALS with zeros, copy the constant vector to TARGET. */ 21914 21915 static void 21916 mips_expand_vi_constant (machine_mode vmode, unsigned nelt, 21917 rtx target, rtx vals) 21918 { 21919 rtvec vec = shallow_copy_rtvec (XVEC (vals, 0)); 21920 unsigned i; 21921 21922 for (i = 0; i < nelt; ++i) 21923 { 21924 rtx elem = RTVEC_ELT (vec, i); 21925 if (!mips_constant_elt_p (elem)) 21926 RTVEC_ELT (vec, i) = CONST0_RTX (GET_MODE (elem)); 21927 } 21928 21929 emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, vec)); 21930 } 21931 21932 21933 /* A subroutine of mips_expand_vec_init, expand via pinsrh. */ 21934 21935 static void 21936 mips_expand_vi_loongson_one_pinsrh (rtx target, rtx vals, unsigned one_var) 21937 { 21938 mips_expand_vi_constant (V4HImode, 4, target, vals); 21939 21940 emit_insn (gen_vec_setv4hi (target, target, XVECEXP (vals, 0, one_var), 21941 GEN_INT (one_var))); 21942 } 21943 21944 /* A subroutine of mips_expand_vec_init, expand anything via memory. */ 21945 21946 static void 21947 mips_expand_vi_general (machine_mode vmode, machine_mode imode, 21948 unsigned nelt, unsigned nvar, rtx target, rtx vals) 21949 { 21950 rtx mem = assign_stack_temp (vmode, GET_MODE_SIZE (vmode)); 21951 unsigned int i, isize = GET_MODE_SIZE (imode); 21952 21953 if (nvar < nelt) 21954 mips_expand_vi_constant (vmode, nelt, mem, vals); 21955 21956 for (i = 0; i < nelt; ++i) 21957 { 21958 rtx x = XVECEXP (vals, 0, i); 21959 if (!mips_constant_elt_p (x)) 21960 emit_move_insn (adjust_address (mem, imode, i * isize), x); 21961 } 21962 21963 emit_move_insn (target, mem); 21964 } 21965 21966 /* Expand a vector initialization. */ 21967 21968 void 21969 mips_expand_vector_init (rtx target, rtx vals) 21970 { 21971 machine_mode vmode = GET_MODE (target); 21972 machine_mode imode = GET_MODE_INNER (vmode); 21973 unsigned i, nelt = GET_MODE_NUNITS (vmode); 21974 unsigned nvar = 0, one_var = -1u; 21975 bool all_same = true; 21976 rtx x; 21977 21978 for (i = 0; i < nelt; ++i) 21979 { 21980 x = XVECEXP (vals, 0, i); 21981 if (!mips_constant_elt_p (x)) 21982 nvar++, one_var = i; 21983 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0))) 21984 all_same = false; 21985 } 21986 21987 if (ISA_HAS_MSA) 21988 { 21989 if (all_same) 21990 { 21991 rtx same = XVECEXP (vals, 0, 0); 21992 rtx temp, temp2; 21993 21994 if (CONST_INT_P (same) && nvar == 0 21995 && mips_signed_immediate_p (INTVAL (same), 10, 0)) 21996 { 21997 switch (vmode) 21998 { 21999 case E_V16QImode: 22000 case E_V8HImode: 22001 case E_V4SImode: 22002 case E_V2DImode: 22003 temp = gen_rtx_CONST_VECTOR (vmode, XVEC (vals, 0)); 22004 emit_move_insn (target, temp); 22005 return; 22006 22007 default: 22008 gcc_unreachable (); 22009 } 22010 } 22011 temp = gen_reg_rtx (imode); 22012 if (imode == GET_MODE (same)) 22013 temp2 = same; 22014 else if (GET_MODE_SIZE (imode) >= UNITS_PER_WORD) 22015 temp2 = simplify_gen_subreg (imode, same, GET_MODE (same), 0); 22016 else 22017 temp2 = lowpart_subreg (imode, same, GET_MODE (same)); 22018 emit_move_insn (temp, temp2); 22019 22020 switch (vmode) 22021 { 22022 case E_V16QImode: 22023 case E_V8HImode: 22024 case E_V4SImode: 22025 case E_V2DImode: 22026 mips_emit_move (target, gen_rtx_VEC_DUPLICATE (vmode, temp)); 22027 break; 22028 22029 case E_V4SFmode: 22030 emit_insn (gen_msa_splati_w_f_scalar (target, temp)); 22031 break; 22032 22033 case E_V2DFmode: 22034 emit_insn (gen_msa_splati_d_f_scalar (target, temp)); 22035 break; 22036 22037 default: 22038 gcc_unreachable (); 22039 } 22040 } 22041 else 22042 { 22043 emit_move_insn (target, CONST0_RTX (vmode)); 22044 22045 for (i = 0; i < nelt; ++i) 22046 { 22047 rtx temp = gen_reg_rtx (imode); 22048 emit_move_insn (temp, XVECEXP (vals, 0, i)); 22049 switch (vmode) 22050 { 22051 case E_V16QImode: 22052 emit_insn (gen_vec_setv16qi (target, temp, GEN_INT (i))); 22053 break; 22054 22055 case E_V8HImode: 22056 emit_insn (gen_vec_setv8hi (target, temp, GEN_INT (i))); 22057 break; 22058 22059 case E_V4SImode: 22060 emit_insn (gen_vec_setv4si (target, temp, GEN_INT (i))); 22061 break; 22062 22063 case E_V2DImode: 22064 emit_insn (gen_vec_setv2di (target, temp, GEN_INT (i))); 22065 break; 22066 22067 case E_V4SFmode: 22068 emit_insn (gen_vec_setv4sf (target, temp, GEN_INT (i))); 22069 break; 22070 22071 case E_V2DFmode: 22072 emit_insn (gen_vec_setv2df (target, temp, GEN_INT (i))); 22073 break; 22074 22075 default: 22076 gcc_unreachable (); 22077 } 22078 } 22079 } 22080 return; 22081 } 22082 22083 /* Load constants from the pool, or whatever's handy. */ 22084 if (nvar == 0) 22085 { 22086 emit_move_insn (target, gen_rtx_CONST_VECTOR (vmode, XVEC (vals, 0))); 22087 return; 22088 } 22089 22090 /* For two-part initialization, always use CONCAT. */ 22091 if (nelt == 2) 22092 { 22093 rtx op0 = force_reg (imode, XVECEXP (vals, 0, 0)); 22094 rtx op1 = force_reg (imode, XVECEXP (vals, 0, 1)); 22095 x = gen_rtx_VEC_CONCAT (vmode, op0, op1); 22096 emit_insn (gen_rtx_SET (target, x)); 22097 return; 22098 } 22099 22100 /* Loongson is the only cpu with vectors with more elements. */ 22101 gcc_assert (TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI); 22102 22103 /* If all values are identical, broadcast the value. */ 22104 if (all_same) 22105 { 22106 mips_expand_vi_broadcast (vmode, target, XVECEXP (vals, 0, 0)); 22107 return; 22108 } 22109 22110 /* If we've only got one non-variable V4HImode, use PINSRH. */ 22111 if (nvar == 1 && vmode == V4HImode) 22112 { 22113 mips_expand_vi_loongson_one_pinsrh (target, vals, one_var); 22114 return; 22115 } 22116 22117 mips_expand_vi_general (vmode, imode, nelt, nvar, target, vals); 22118 } 22119 22120 /* Expand a vector reduction. */ 22121 22122 void 22123 mips_expand_vec_reduc (rtx target, rtx in, rtx (*gen)(rtx, rtx, rtx)) 22124 { 22125 machine_mode vmode = GET_MODE (in); 22126 unsigned char perm2[2]; 22127 rtx last, next, fold, x; 22128 bool ok; 22129 22130 last = in; 22131 fold = gen_reg_rtx (vmode); 22132 switch (vmode) 22133 { 22134 case E_V2SFmode: 22135 /* Use PUL/PLU to produce { L, H } op { H, L }. 22136 By reversing the pair order, rather than a pure interleave high, 22137 we avoid erroneous exceptional conditions that we might otherwise 22138 produce from the computation of H op H. */ 22139 perm2[0] = 1; 22140 perm2[1] = 2; 22141 ok = mips_expand_vselect_vconcat (fold, last, last, perm2, 2); 22142 gcc_assert (ok); 22143 break; 22144 22145 case E_V2SImode: 22146 /* Use interleave to produce { H, L } op { H, H }. */ 22147 emit_insn (gen_loongson_punpckhwd (fold, last, last)); 22148 break; 22149 22150 case E_V4HImode: 22151 /* Perform the first reduction with interleave, 22152 and subsequent reductions with shifts. */ 22153 emit_insn (gen_loongson_punpckhwd_hi (fold, last, last)); 22154 22155 next = gen_reg_rtx (vmode); 22156 emit_insn (gen (next, last, fold)); 22157 last = next; 22158 22159 fold = gen_reg_rtx (vmode); 22160 x = force_reg (SImode, GEN_INT (16)); 22161 emit_insn (gen_vec_shr_v4hi (fold, last, x)); 22162 break; 22163 22164 case E_V8QImode: 22165 emit_insn (gen_loongson_punpckhwd_qi (fold, last, last)); 22166 22167 next = gen_reg_rtx (vmode); 22168 emit_insn (gen (next, last, fold)); 22169 last = next; 22170 22171 fold = gen_reg_rtx (vmode); 22172 x = force_reg (SImode, GEN_INT (16)); 22173 emit_insn (gen_vec_shr_v8qi (fold, last, x)); 22174 22175 next = gen_reg_rtx (vmode); 22176 emit_insn (gen (next, last, fold)); 22177 last = next; 22178 22179 fold = gen_reg_rtx (vmode); 22180 x = force_reg (SImode, GEN_INT (8)); 22181 emit_insn (gen_vec_shr_v8qi (fold, last, x)); 22182 break; 22183 22184 default: 22185 gcc_unreachable (); 22186 } 22187 22188 emit_insn (gen (target, last, fold)); 22189 } 22190 22191 /* Expand a vector minimum/maximum. */ 22192 22193 void 22194 mips_expand_vec_minmax (rtx target, rtx op0, rtx op1, 22195 rtx (*cmp) (rtx, rtx, rtx), bool min_p) 22196 { 22197 machine_mode vmode = GET_MODE (target); 22198 rtx tc, t0, t1, x; 22199 22200 tc = gen_reg_rtx (vmode); 22201 t0 = gen_reg_rtx (vmode); 22202 t1 = gen_reg_rtx (vmode); 22203 22204 /* op0 > op1 */ 22205 emit_insn (cmp (tc, op0, op1)); 22206 22207 x = gen_rtx_AND (vmode, tc, (min_p ? op1 : op0)); 22208 emit_insn (gen_rtx_SET (t0, x)); 22209 22210 x = gen_rtx_NOT (vmode, tc); 22211 x = gen_rtx_AND (vmode, x, (min_p ? op0 : op1)); 22212 emit_insn (gen_rtx_SET (t1, x)); 22213 22214 x = gen_rtx_IOR (vmode, t0, t1); 22215 emit_insn (gen_rtx_SET (target, x)); 22216 } 22217 22218 /* Implement HARD_REGNO_CALLER_SAVE_MODE. */ 22219 22220 machine_mode 22221 mips_hard_regno_caller_save_mode (unsigned int regno, 22222 unsigned int nregs, 22223 machine_mode mode) 22224 { 22225 /* For performance, avoid saving/restoring upper parts of a register 22226 by returning MODE as save mode when the mode is known. */ 22227 if (mode == VOIDmode) 22228 return choose_hard_reg_mode (regno, nregs, NULL); 22229 else 22230 return mode; 22231 } 22232 22233 /* Generate RTL for comparing CMP_OP0 and CMP_OP1 using condition COND and 22234 store the result -1 or 0 in DEST. */ 22235 22236 static void 22237 mips_expand_msa_cmp (rtx dest, enum rtx_code cond, rtx op0, rtx op1) 22238 { 22239 machine_mode cmp_mode = GET_MODE (op0); 22240 int unspec = -1; 22241 bool negate = false; 22242 22243 switch (cmp_mode) 22244 { 22245 case E_V16QImode: 22246 case E_V8HImode: 22247 case E_V4SImode: 22248 case E_V2DImode: 22249 switch (cond) 22250 { 22251 case NE: 22252 cond = reverse_condition (cond); 22253 negate = true; 22254 break; 22255 case EQ: 22256 case LT: 22257 case LE: 22258 case LTU: 22259 case LEU: 22260 break; 22261 case GE: 22262 case GT: 22263 case GEU: 22264 case GTU: 22265 std::swap (op0, op1); 22266 cond = swap_condition (cond); 22267 break; 22268 default: 22269 gcc_unreachable (); 22270 } 22271 mips_emit_binary (cond, dest, op0, op1); 22272 if (negate) 22273 emit_move_insn (dest, gen_rtx_NOT (GET_MODE (dest), dest)); 22274 break; 22275 22276 case E_V4SFmode: 22277 case E_V2DFmode: 22278 switch (cond) 22279 { 22280 case UNORDERED: 22281 case ORDERED: 22282 case EQ: 22283 case NE: 22284 case UNEQ: 22285 case UNLE: 22286 case UNLT: 22287 break; 22288 case LTGT: cond = NE; break; 22289 case UNGE: cond = UNLE; std::swap (op0, op1); break; 22290 case UNGT: cond = UNLT; std::swap (op0, op1); break; 22291 case LE: unspec = UNSPEC_MSA_FSLE; break; 22292 case LT: unspec = UNSPEC_MSA_FSLT; break; 22293 case GE: unspec = UNSPEC_MSA_FSLE; std::swap (op0, op1); break; 22294 case GT: unspec = UNSPEC_MSA_FSLT; std::swap (op0, op1); break; 22295 default: 22296 gcc_unreachable (); 22297 } 22298 if (unspec < 0) 22299 mips_emit_binary (cond, dest, op0, op1); 22300 else 22301 { 22302 rtx x = gen_rtx_UNSPEC (GET_MODE (dest), 22303 gen_rtvec (2, op0, op1), unspec); 22304 emit_insn (gen_rtx_SET (dest, x)); 22305 } 22306 break; 22307 22308 default: 22309 gcc_unreachable (); 22310 break; 22311 } 22312 } 22313 22314 /* Expand VEC_COND_EXPR, where: 22315 MODE is mode of the result 22316 VIMODE equivalent integer mode 22317 OPERANDS operands of VEC_COND_EXPR. */ 22318 22319 void 22320 mips_expand_vec_cond_expr (machine_mode mode, machine_mode vimode, 22321 rtx *operands) 22322 { 22323 rtx cond = operands[3]; 22324 rtx cmp_op0 = operands[4]; 22325 rtx cmp_op1 = operands[5]; 22326 rtx cmp_res = gen_reg_rtx (vimode); 22327 22328 mips_expand_msa_cmp (cmp_res, GET_CODE (cond), cmp_op0, cmp_op1); 22329 22330 /* We handle the following cases: 22331 1) r = a CMP b ? -1 : 0 22332 2) r = a CMP b ? -1 : v 22333 3) r = a CMP b ? v : 0 22334 4) r = a CMP b ? v1 : v2 */ 22335 22336 /* Case (1) above. We only move the results. */ 22337 if (operands[1] == CONSTM1_RTX (vimode) 22338 && operands[2] == CONST0_RTX (vimode)) 22339 emit_move_insn (operands[0], cmp_res); 22340 else 22341 { 22342 rtx src1 = gen_reg_rtx (vimode); 22343 rtx src2 = gen_reg_rtx (vimode); 22344 rtx mask = gen_reg_rtx (vimode); 22345 rtx bsel; 22346 22347 /* Move the vector result to use it as a mask. */ 22348 emit_move_insn (mask, cmp_res); 22349 22350 if (register_operand (operands[1], mode)) 22351 { 22352 rtx xop1 = operands[1]; 22353 if (mode != vimode) 22354 { 22355 xop1 = gen_reg_rtx (vimode); 22356 emit_move_insn (xop1, gen_lowpart (vimode, operands[1])); 22357 } 22358 emit_move_insn (src1, xop1); 22359 } 22360 else 22361 { 22362 gcc_assert (operands[1] == CONSTM1_RTX (vimode)); 22363 /* Case (2) if the below doesn't move the mask to src2. */ 22364 emit_move_insn (src1, mask); 22365 } 22366 22367 if (register_operand (operands[2], mode)) 22368 { 22369 rtx xop2 = operands[2]; 22370 if (mode != vimode) 22371 { 22372 xop2 = gen_reg_rtx (vimode); 22373 emit_move_insn (xop2, gen_lowpart (vimode, operands[2])); 22374 } 22375 emit_move_insn (src2, xop2); 22376 } 22377 else 22378 { 22379 gcc_assert (operands[2] == CONST0_RTX (mode)); 22380 /* Case (3) if the above didn't move the mask to src1. */ 22381 emit_move_insn (src2, mask); 22382 } 22383 22384 /* We deal with case (4) if the mask wasn't moved to either src1 or src2. 22385 In any case, we eventually do vector mask-based copy. */ 22386 bsel = gen_rtx_IOR (vimode, 22387 gen_rtx_AND (vimode, 22388 gen_rtx_NOT (vimode, mask), src2), 22389 gen_rtx_AND (vimode, mask, src1)); 22390 /* The result is placed back to a register with the mask. */ 22391 emit_insn (gen_rtx_SET (mask, bsel)); 22392 emit_move_insn (operands[0], gen_rtx_SUBREG (mode, mask, 0)); 22393 } 22394 } 22395 22396 /* Implement TARGET_CASE_VALUES_THRESHOLD. */ 22397 22398 unsigned int 22399 mips_case_values_threshold (void) 22400 { 22401 /* In MIPS16 mode using a larger case threshold generates smaller code. */ 22402 if (TARGET_MIPS16 && optimize_size) 22403 return 10; 22404 else 22405 return default_case_values_threshold (); 22406 } 22407 22408 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV. */ 22409 22410 static void 22411 mips_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update) 22412 { 22413 if (!TARGET_HARD_FLOAT_ABI) 22414 return; 22415 tree exceptions_var = create_tmp_var_raw (MIPS_ATYPE_USI); 22416 tree fcsr_orig_var = create_tmp_var_raw (MIPS_ATYPE_USI); 22417 tree fcsr_mod_var = create_tmp_var_raw (MIPS_ATYPE_USI); 22418 tree get_fcsr = mips_builtin_decls[MIPS_GET_FCSR]; 22419 tree set_fcsr = mips_builtin_decls[MIPS_SET_FCSR]; 22420 tree get_fcsr_hold_call = build_call_expr (get_fcsr, 0); 22421 tree hold_assign_orig = build4 (TARGET_EXPR, MIPS_ATYPE_USI, 22422 fcsr_orig_var, get_fcsr_hold_call, NULL, NULL); 22423 tree hold_mod_val = build2 (BIT_AND_EXPR, MIPS_ATYPE_USI, fcsr_orig_var, 22424 build_int_cst (MIPS_ATYPE_USI, 0xfffff003)); 22425 tree hold_assign_mod = build4 (TARGET_EXPR, MIPS_ATYPE_USI, 22426 fcsr_mod_var, hold_mod_val, NULL, NULL); 22427 tree set_fcsr_hold_call = build_call_expr (set_fcsr, 1, fcsr_mod_var); 22428 tree hold_all = build2 (COMPOUND_EXPR, MIPS_ATYPE_USI, 22429 hold_assign_orig, hold_assign_mod); 22430 *hold = build2 (COMPOUND_EXPR, void_type_node, hold_all, 22431 set_fcsr_hold_call); 22432 22433 *clear = build_call_expr (set_fcsr, 1, fcsr_mod_var); 22434 22435 tree get_fcsr_update_call = build_call_expr (get_fcsr, 0); 22436 *update = build4 (TARGET_EXPR, MIPS_ATYPE_USI, 22437 exceptions_var, get_fcsr_update_call, NULL, NULL); 22438 tree set_fcsr_update_call = build_call_expr (set_fcsr, 1, fcsr_orig_var); 22439 *update = build2 (COMPOUND_EXPR, void_type_node, *update, 22440 set_fcsr_update_call); 22441 tree atomic_feraiseexcept 22442 = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT); 22443 tree int_exceptions_var = fold_convert (integer_type_node, 22444 exceptions_var); 22445 tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept, 22446 1, int_exceptions_var); 22447 *update = build2 (COMPOUND_EXPR, void_type_node, *update, 22448 atomic_feraiseexcept_call); 22449 } 22450 22451 /* Implement TARGET_SPILL_CLASS. */ 22452 22453 static reg_class_t 22454 mips_spill_class (reg_class_t rclass ATTRIBUTE_UNUSED, 22455 machine_mode mode ATTRIBUTE_UNUSED) 22456 { 22457 if (TARGET_MIPS16) 22458 return SPILL_REGS; 22459 return NO_REGS; 22460 } 22461 22462 /* Implement TARGET_LRA_P. */ 22463 22464 static bool 22465 mips_lra_p (void) 22466 { 22467 return mips_lra_flag; 22468 } 22469 22470 /* Implement TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS. */ 22471 22472 static reg_class_t 22473 mips_ira_change_pseudo_allocno_class (int regno, reg_class_t allocno_class, 22474 reg_class_t best_class ATTRIBUTE_UNUSED) 22475 { 22476 /* LRA will allocate an FPR for an integer mode pseudo instead of spilling 22477 to memory if an FPR is present in the allocno class. It is rare that 22478 we actually need to place an integer mode value in an FPR so where 22479 possible limit the allocation to GR_REGS. This will slightly pessimize 22480 code that involves integer to/from float conversions as these will have 22481 to reload into FPRs in LRA. Such reloads are sometimes eliminated and 22482 sometimes only partially eliminated. We choose to take this penalty 22483 in order to eliminate usage of FPRs in code that does not use floating 22484 point data. 22485 22486 This change has a similar effect to increasing the cost of FPR->GPR 22487 register moves for integer modes so that they are higher than the cost 22488 of memory but changing the allocno class is more reliable. 22489 22490 This is also similar to forbidding integer mode values in FPRs entirely 22491 but this would lead to an inconsistency in the integer to/from float 22492 instructions that say integer mode values must be placed in FPRs. */ 22493 if (INTEGRAL_MODE_P (PSEUDO_REGNO_MODE (regno)) && allocno_class == ALL_REGS) 22494 return GR_REGS; 22495 return allocno_class; 22496 } 22497 22498 /* Implement TARGET_PROMOTE_FUNCTION_MODE */ 22499 22500 /* This function is equivalent to default_promote_function_mode_always_promote 22501 except that it returns a promoted mode even if type is NULL_TREE. This is 22502 needed by libcalls which have no type (only a mode) such as fixed conversion 22503 routines that take a signed or unsigned char/short argument and convert it 22504 to a fixed type. */ 22505 22506 static machine_mode 22507 mips_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, 22508 machine_mode mode, 22509 int *punsignedp ATTRIBUTE_UNUSED, 22510 const_tree fntype ATTRIBUTE_UNUSED, 22511 int for_return ATTRIBUTE_UNUSED) 22512 { 22513 int unsignedp; 22514 22515 if (type != NULL_TREE) 22516 return promote_mode (type, mode, punsignedp); 22517 22518 unsignedp = *punsignedp; 22519 PROMOTE_MODE (mode, unsignedp, type); 22520 *punsignedp = unsignedp; 22521 return mode; 22522 } 22523 22524 /* Implement TARGET_TRULY_NOOP_TRUNCATION. */ 22525 22526 static bool 22527 mips_truly_noop_truncation (poly_uint64 outprec, poly_uint64 inprec) 22528 { 22529 return !TARGET_64BIT || inprec <= 32 || outprec > 32; 22530 } 22531 22532 /* Implement TARGET_CONSTANT_ALIGNMENT. */ 22533 22534 static HOST_WIDE_INT 22535 mips_constant_alignment (const_tree exp, HOST_WIDE_INT align) 22536 { 22537 if (TREE_CODE (exp) == STRING_CST || TREE_CODE (exp) == CONSTRUCTOR) 22538 return MAX (align, BITS_PER_WORD); 22539 return align; 22540 } 22541 22542 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */ 22543 22544 static unsigned HOST_WIDE_INT 22545 mips_asan_shadow_offset (void) 22546 { 22547 return 0x0aaa0000; 22548 } 22549 22550 /* Implement TARGET_STARTING_FRAME_OFFSET. See mips_compute_frame_info 22551 for details about the frame layout. */ 22552 22553 static HOST_WIDE_INT 22554 mips_starting_frame_offset (void) 22555 { 22556 if (FRAME_GROWS_DOWNWARD) 22557 return 0; 22558 return crtl->outgoing_args_size + MIPS_GP_SAVE_AREA_SIZE; 22559 } 22560 22561 static void 22562 mips_asm_file_end (void) 22563 { 22564 if (NEED_INDICATE_EXEC_STACK) 22565 file_end_indicate_exec_stack (); 22566 } 22567 22568 /* Initialize the GCC target structure. */ 22569 #undef TARGET_ASM_ALIGNED_HI_OP 22570 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" 22571 #undef TARGET_ASM_ALIGNED_SI_OP 22572 #define TARGET_ASM_ALIGNED_SI_OP "\t.word\t" 22573 #undef TARGET_ASM_ALIGNED_DI_OP 22574 #define TARGET_ASM_ALIGNED_DI_OP "\t.dword\t" 22575 22576 #undef TARGET_OPTION_OVERRIDE 22577 #define TARGET_OPTION_OVERRIDE mips_option_override 22578 22579 #undef TARGET_LEGITIMIZE_ADDRESS 22580 #define TARGET_LEGITIMIZE_ADDRESS mips_legitimize_address 22581 22582 #undef TARGET_ASM_FUNCTION_PROLOGUE 22583 #define TARGET_ASM_FUNCTION_PROLOGUE mips_output_function_prologue 22584 #undef TARGET_ASM_FUNCTION_EPILOGUE 22585 #define TARGET_ASM_FUNCTION_EPILOGUE mips_output_function_epilogue 22586 #undef TARGET_ASM_SELECT_RTX_SECTION 22587 #define TARGET_ASM_SELECT_RTX_SECTION mips_select_rtx_section 22588 #undef TARGET_ASM_FUNCTION_RODATA_SECTION 22589 #define TARGET_ASM_FUNCTION_RODATA_SECTION mips_function_rodata_section 22590 22591 #undef TARGET_SCHED_INIT 22592 #define TARGET_SCHED_INIT mips_sched_init 22593 #undef TARGET_SCHED_REORDER 22594 #define TARGET_SCHED_REORDER mips_sched_reorder 22595 #undef TARGET_SCHED_REORDER2 22596 #define TARGET_SCHED_REORDER2 mips_sched_reorder2 22597 #undef TARGET_SCHED_VARIABLE_ISSUE 22598 #define TARGET_SCHED_VARIABLE_ISSUE mips_variable_issue 22599 #undef TARGET_SCHED_ADJUST_COST 22600 #define TARGET_SCHED_ADJUST_COST mips_adjust_cost 22601 #undef TARGET_SCHED_ISSUE_RATE 22602 #define TARGET_SCHED_ISSUE_RATE mips_issue_rate 22603 #undef TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN 22604 #define TARGET_SCHED_INIT_DFA_POST_CYCLE_INSN mips_init_dfa_post_cycle_insn 22605 #undef TARGET_SCHED_DFA_POST_ADVANCE_CYCLE 22606 #define TARGET_SCHED_DFA_POST_ADVANCE_CYCLE mips_dfa_post_advance_cycle 22607 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD 22608 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \ 22609 mips_multipass_dfa_lookahead 22610 #undef TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P 22611 #define TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P \ 22612 mips_small_register_classes_for_mode_p 22613 22614 #undef TARGET_FUNCTION_OK_FOR_SIBCALL 22615 #define TARGET_FUNCTION_OK_FOR_SIBCALL mips_function_ok_for_sibcall 22616 22617 #undef TARGET_INSERT_ATTRIBUTES 22618 #define TARGET_INSERT_ATTRIBUTES mips_insert_attributes 22619 #undef TARGET_MERGE_DECL_ATTRIBUTES 22620 #define TARGET_MERGE_DECL_ATTRIBUTES mips_merge_decl_attributes 22621 #undef TARGET_CAN_INLINE_P 22622 #define TARGET_CAN_INLINE_P mips_can_inline_p 22623 #undef TARGET_SET_CURRENT_FUNCTION 22624 #define TARGET_SET_CURRENT_FUNCTION mips_set_current_function 22625 22626 #undef TARGET_VALID_POINTER_MODE 22627 #define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode 22628 #undef TARGET_REGISTER_MOVE_COST 22629 #define TARGET_REGISTER_MOVE_COST mips_register_move_cost 22630 #undef TARGET_REGISTER_PRIORITY 22631 #define TARGET_REGISTER_PRIORITY mips_register_priority 22632 #undef TARGET_MEMORY_MOVE_COST 22633 #define TARGET_MEMORY_MOVE_COST mips_memory_move_cost 22634 #undef TARGET_RTX_COSTS 22635 #define TARGET_RTX_COSTS mips_rtx_costs 22636 #undef TARGET_ADDRESS_COST 22637 #define TARGET_ADDRESS_COST mips_address_cost 22638 22639 #undef TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P 22640 #define TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P mips_no_speculation_in_delay_slots_p 22641 22642 #undef TARGET_IN_SMALL_DATA_P 22643 #define TARGET_IN_SMALL_DATA_P mips_in_small_data_p 22644 22645 #undef TARGET_MACHINE_DEPENDENT_REORG 22646 #define TARGET_MACHINE_DEPENDENT_REORG mips_reorg 22647 22648 #undef TARGET_PREFERRED_RELOAD_CLASS 22649 #define TARGET_PREFERRED_RELOAD_CLASS mips_preferred_reload_class 22650 22651 #undef TARGET_EXPAND_TO_RTL_HOOK 22652 #define TARGET_EXPAND_TO_RTL_HOOK mips_expand_to_rtl_hook 22653 #undef TARGET_ASM_FILE_START 22654 #define TARGET_ASM_FILE_START mips_file_start 22655 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE 22656 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true 22657 #undef TARGET_ASM_CODE_END 22658 #define TARGET_ASM_CODE_END mips_code_end 22659 22660 #undef TARGET_INIT_LIBFUNCS 22661 #define TARGET_INIT_LIBFUNCS mips_init_libfuncs 22662 22663 #undef TARGET_BUILD_BUILTIN_VA_LIST 22664 #define TARGET_BUILD_BUILTIN_VA_LIST mips_build_builtin_va_list 22665 #undef TARGET_EXPAND_BUILTIN_VA_START 22666 #define TARGET_EXPAND_BUILTIN_VA_START mips_va_start 22667 #undef TARGET_GIMPLIFY_VA_ARG_EXPR 22668 #define TARGET_GIMPLIFY_VA_ARG_EXPR mips_gimplify_va_arg_expr 22669 22670 #undef TARGET_PROMOTE_FUNCTION_MODE 22671 #define TARGET_PROMOTE_FUNCTION_MODE mips_promote_function_mode 22672 #undef TARGET_FUNCTION_VALUE 22673 #define TARGET_FUNCTION_VALUE mips_function_value 22674 #undef TARGET_LIBCALL_VALUE 22675 #define TARGET_LIBCALL_VALUE mips_libcall_value 22676 #undef TARGET_FUNCTION_VALUE_REGNO_P 22677 #define TARGET_FUNCTION_VALUE_REGNO_P mips_function_value_regno_p 22678 #undef TARGET_RETURN_IN_MEMORY 22679 #define TARGET_RETURN_IN_MEMORY mips_return_in_memory 22680 #undef TARGET_RETURN_IN_MSB 22681 #define TARGET_RETURN_IN_MSB mips_return_in_msb 22682 22683 #undef TARGET_ASM_OUTPUT_MI_THUNK 22684 #define TARGET_ASM_OUTPUT_MI_THUNK mips_output_mi_thunk 22685 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK 22686 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true 22687 22688 #undef TARGET_PRINT_OPERAND 22689 #define TARGET_PRINT_OPERAND mips_print_operand 22690 #undef TARGET_PRINT_OPERAND_ADDRESS 22691 #define TARGET_PRINT_OPERAND_ADDRESS mips_print_operand_address 22692 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P 22693 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P mips_print_operand_punct_valid_p 22694 22695 #undef TARGET_SETUP_INCOMING_VARARGS 22696 #define TARGET_SETUP_INCOMING_VARARGS mips_setup_incoming_varargs 22697 #undef TARGET_STRICT_ARGUMENT_NAMING 22698 #define TARGET_STRICT_ARGUMENT_NAMING mips_strict_argument_naming 22699 #undef TARGET_MUST_PASS_IN_STACK 22700 #define TARGET_MUST_PASS_IN_STACK must_pass_in_stack_var_size 22701 #undef TARGET_PASS_BY_REFERENCE 22702 #define TARGET_PASS_BY_REFERENCE mips_pass_by_reference 22703 #undef TARGET_CALLEE_COPIES 22704 #define TARGET_CALLEE_COPIES mips_callee_copies 22705 #undef TARGET_ARG_PARTIAL_BYTES 22706 #define TARGET_ARG_PARTIAL_BYTES mips_arg_partial_bytes 22707 #undef TARGET_FUNCTION_ARG 22708 #define TARGET_FUNCTION_ARG mips_function_arg 22709 #undef TARGET_FUNCTION_ARG_ADVANCE 22710 #define TARGET_FUNCTION_ARG_ADVANCE mips_function_arg_advance 22711 #undef TARGET_FUNCTION_ARG_PADDING 22712 #define TARGET_FUNCTION_ARG_PADDING mips_function_arg_padding 22713 #undef TARGET_FUNCTION_ARG_BOUNDARY 22714 #define TARGET_FUNCTION_ARG_BOUNDARY mips_function_arg_boundary 22715 #undef TARGET_GET_RAW_RESULT_MODE 22716 #define TARGET_GET_RAW_RESULT_MODE mips_get_reg_raw_mode 22717 #undef TARGET_GET_RAW_ARG_MODE 22718 #define TARGET_GET_RAW_ARG_MODE mips_get_reg_raw_mode 22719 22720 #undef TARGET_MODE_REP_EXTENDED 22721 #define TARGET_MODE_REP_EXTENDED mips_mode_rep_extended 22722 22723 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION 22724 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \ 22725 mips_builtin_vectorized_function 22726 #undef TARGET_VECTOR_MODE_SUPPORTED_P 22727 #define TARGET_VECTOR_MODE_SUPPORTED_P mips_vector_mode_supported_p 22728 22729 #undef TARGET_SCALAR_MODE_SUPPORTED_P 22730 #define TARGET_SCALAR_MODE_SUPPORTED_P mips_scalar_mode_supported_p 22731 22732 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE 22733 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE mips_preferred_simd_mode 22734 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES 22735 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_MODES \ 22736 mips_autovectorize_vector_modes 22737 22738 #undef TARGET_INIT_BUILTINS 22739 #define TARGET_INIT_BUILTINS mips_init_builtins 22740 #undef TARGET_BUILTIN_DECL 22741 #define TARGET_BUILTIN_DECL mips_builtin_decl 22742 #undef TARGET_EXPAND_BUILTIN 22743 #define TARGET_EXPAND_BUILTIN mips_expand_builtin 22744 22745 #undef TARGET_HAVE_TLS 22746 #define TARGET_HAVE_TLS HAVE_AS_TLS 22747 22748 #undef TARGET_CANNOT_FORCE_CONST_MEM 22749 #define TARGET_CANNOT_FORCE_CONST_MEM mips_cannot_force_const_mem 22750 22751 #undef TARGET_LEGITIMATE_CONSTANT_P 22752 #define TARGET_LEGITIMATE_CONSTANT_P mips_legitimate_constant_p 22753 22754 #undef TARGET_ENCODE_SECTION_INFO 22755 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info 22756 22757 #undef TARGET_ATTRIBUTE_TABLE 22758 #define TARGET_ATTRIBUTE_TABLE mips_attribute_table 22759 /* All our function attributes are related to how out-of-line copies should 22760 be compiled or called. They don't in themselves prevent inlining. */ 22761 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P 22762 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true 22763 22764 #undef TARGET_EXTRA_LIVE_ON_ENTRY 22765 #define TARGET_EXTRA_LIVE_ON_ENTRY mips_extra_live_on_entry 22766 22767 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P 22768 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P mips_use_blocks_for_constant_p 22769 #undef TARGET_USE_ANCHORS_FOR_SYMBOL_P 22770 #define TARGET_USE_ANCHORS_FOR_SYMBOL_P mips_use_anchors_for_symbol_p 22771 22772 #undef TARGET_COMP_TYPE_ATTRIBUTES 22773 #define TARGET_COMP_TYPE_ATTRIBUTES mips_comp_type_attributes 22774 22775 #ifdef HAVE_AS_DTPRELWORD 22776 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL 22777 #define TARGET_ASM_OUTPUT_DWARF_DTPREL mips_output_dwarf_dtprel 22778 #endif 22779 #undef TARGET_DWARF_REGISTER_SPAN 22780 #define TARGET_DWARF_REGISTER_SPAN mips_dwarf_register_span 22781 #undef TARGET_DWARF_FRAME_REG_MODE 22782 #define TARGET_DWARF_FRAME_REG_MODE mips_dwarf_frame_reg_mode 22783 22784 #undef TARGET_ASM_FINAL_POSTSCAN_INSN 22785 #define TARGET_ASM_FINAL_POSTSCAN_INSN mips_final_postscan_insn 22786 22787 #undef TARGET_LEGITIMATE_ADDRESS_P 22788 #define TARGET_LEGITIMATE_ADDRESS_P mips_legitimate_address_p 22789 22790 #undef TARGET_FRAME_POINTER_REQUIRED 22791 #define TARGET_FRAME_POINTER_REQUIRED mips_frame_pointer_required 22792 22793 #undef TARGET_CAN_ELIMINATE 22794 #define TARGET_CAN_ELIMINATE mips_can_eliminate 22795 22796 #undef TARGET_CONDITIONAL_REGISTER_USAGE 22797 #define TARGET_CONDITIONAL_REGISTER_USAGE mips_conditional_register_usage 22798 22799 #undef TARGET_TRAMPOLINE_INIT 22800 #define TARGET_TRAMPOLINE_INIT mips_trampoline_init 22801 22802 #ifndef MIPS_USE_GCC_DEFAULT_OUTPUT_SOURCE_FILENAME 22803 #undef TARGET_ASM_OUTPUT_SOURCE_FILENAME 22804 #define TARGET_ASM_OUTPUT_SOURCE_FILENAME mips_output_filename 22805 #endif /* MIPS_USE_GCC_DEFAULT_OUTPUT_SOURCE_FILENAME */ 22806 22807 #undef TARGET_SHIFT_TRUNCATION_MASK 22808 #define TARGET_SHIFT_TRUNCATION_MASK mips_shift_truncation_mask 22809 22810 #undef TARGET_PREPARE_PCH_SAVE 22811 #define TARGET_PREPARE_PCH_SAVE mips_prepare_pch_save 22812 22813 #undef TARGET_VECTORIZE_VEC_PERM_CONST 22814 #define TARGET_VECTORIZE_VEC_PERM_CONST mips_vectorize_vec_perm_const 22815 22816 #undef TARGET_SCHED_REASSOCIATION_WIDTH 22817 #define TARGET_SCHED_REASSOCIATION_WIDTH mips_sched_reassociation_width 22818 22819 #undef TARGET_CASE_VALUES_THRESHOLD 22820 #define TARGET_CASE_VALUES_THRESHOLD mips_case_values_threshold 22821 22822 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV 22823 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV mips_atomic_assign_expand_fenv 22824 22825 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS 22826 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true 22827 22828 #undef TARGET_USE_BY_PIECES_INFRASTRUCTURE_P 22829 #define TARGET_USE_BY_PIECES_INFRASTRUCTURE_P \ 22830 mips_use_by_pieces_infrastructure_p 22831 22832 #undef TARGET_SPILL_CLASS 22833 #define TARGET_SPILL_CLASS mips_spill_class 22834 #undef TARGET_LRA_P 22835 #define TARGET_LRA_P mips_lra_p 22836 #undef TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS 22837 #define TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS mips_ira_change_pseudo_allocno_class 22838 22839 #undef TARGET_HARD_REGNO_SCRATCH_OK 22840 #define TARGET_HARD_REGNO_SCRATCH_OK mips_hard_regno_scratch_ok 22841 22842 #undef TARGET_HARD_REGNO_NREGS 22843 #define TARGET_HARD_REGNO_NREGS mips_hard_regno_nregs 22844 #undef TARGET_HARD_REGNO_MODE_OK 22845 #define TARGET_HARD_REGNO_MODE_OK mips_hard_regno_mode_ok 22846 22847 #undef TARGET_MODES_TIEABLE_P 22848 #define TARGET_MODES_TIEABLE_P mips_modes_tieable_p 22849 22850 #undef TARGET_HARD_REGNO_CALL_PART_CLOBBERED 22851 #define TARGET_HARD_REGNO_CALL_PART_CLOBBERED \ 22852 mips_hard_regno_call_part_clobbered 22853 22854 /* The architecture reserves bit 0 for MIPS16 so use bit 1 for descriptors. */ 22855 #undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS 22856 #define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 2 22857 22858 #undef TARGET_SECONDARY_MEMORY_NEEDED 22859 #define TARGET_SECONDARY_MEMORY_NEEDED mips_secondary_memory_needed 22860 22861 #undef TARGET_CAN_CHANGE_MODE_CLASS 22862 #define TARGET_CAN_CHANGE_MODE_CLASS mips_can_change_mode_class 22863 22864 #undef TARGET_TRULY_NOOP_TRUNCATION 22865 #define TARGET_TRULY_NOOP_TRUNCATION mips_truly_noop_truncation 22866 22867 #undef TARGET_CONSTANT_ALIGNMENT 22868 #define TARGET_CONSTANT_ALIGNMENT mips_constant_alignment 22869 22870 #undef TARGET_ASAN_SHADOW_OFFSET 22871 #define TARGET_ASAN_SHADOW_OFFSET mips_asan_shadow_offset 22872 22873 #undef TARGET_STARTING_FRAME_OFFSET 22874 #define TARGET_STARTING_FRAME_OFFSET mips_starting_frame_offset 22875 22876 #undef TARGET_ASM_FILE_END 22877 #define TARGET_ASM_FILE_END mips_asm_file_end 22878 22879 22880 struct gcc_target targetm = TARGET_INITIALIZER; 22881 22882 #include "gt-mips.h" 22883