1 //===-- PPCISelLowering.h - PPC32 DAG Lowering Interface --------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the interfaces that PPC uses to lower LLVM code into a 10 // selection DAG. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H 15 #define LLVM_LIB_TARGET_POWERPC_PPCISELLOWERING_H 16 17 #include "PPCInstrInfo.h" 18 #include "llvm/CodeGen/CallingConvLower.h" 19 #include "llvm/CodeGen/MachineFunction.h" 20 #include "llvm/CodeGen/MachineMemOperand.h" 21 #include "llvm/CodeGen/SelectionDAG.h" 22 #include "llvm/CodeGen/SelectionDAGNodes.h" 23 #include "llvm/CodeGen/TargetLowering.h" 24 #include "llvm/CodeGen/ValueTypes.h" 25 #include "llvm/IR/Attributes.h" 26 #include "llvm/IR/CallingConv.h" 27 #include "llvm/IR/Function.h" 28 #include "llvm/IR/InlineAsm.h" 29 #include "llvm/IR/Metadata.h" 30 #include "llvm/IR/Type.h" 31 #include "llvm/Support/MachineValueType.h" 32 #include <utility> 33 34 namespace llvm { 35 36 namespace PPCISD { 37 38 // When adding a NEW PPCISD node please add it to the correct position in 39 // the enum. The order of elements in this enum matters! 40 // Values that are added after this entry: 41 // STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE 42 // are considered memory opcodes and are treated differently than entries 43 // that come before it. For example, ADD or MUL should be placed before 44 // the ISD::FIRST_TARGET_MEMORY_OPCODE while a LOAD or STORE should come 45 // after it. 46 enum NodeType : unsigned { 47 // Start the numbering where the builtin ops and target ops leave off. 48 FIRST_NUMBER = ISD::BUILTIN_OP_END, 49 50 /// FSEL - Traditional three-operand fsel node. 51 /// 52 FSEL, 53 54 /// XSMAXCDP, XSMINCDP - C-type min/max instructions. 55 XSMAXCDP, 56 XSMINCDP, 57 58 /// FCFID - The FCFID instruction, taking an f64 operand and producing 59 /// and f64 value containing the FP representation of the integer that 60 /// was temporarily in the f64 operand. 61 FCFID, 62 63 /// Newer FCFID[US] integer-to-floating-point conversion instructions for 64 /// unsigned integers and single-precision outputs. 65 FCFIDU, 66 FCFIDS, 67 FCFIDUS, 68 69 /// FCTI[D,W]Z - The FCTIDZ and FCTIWZ instructions, taking an f32 or f64 70 /// operand, producing an f64 value containing the integer representation 71 /// of that FP value. 72 FCTIDZ, 73 FCTIWZ, 74 75 /// Newer FCTI[D,W]UZ floating-point-to-integer conversion instructions for 76 /// unsigned integers with round toward zero. 77 FCTIDUZ, 78 FCTIWUZ, 79 80 /// Floating-point-to-interger conversion instructions 81 FP_TO_UINT_IN_VSR, 82 FP_TO_SINT_IN_VSR, 83 84 /// VEXTS, ByteWidth - takes an input in VSFRC and produces an output in 85 /// VSFRC that is sign-extended from ByteWidth to a 64-byte integer. 86 VEXTS, 87 88 /// Reciprocal estimate instructions (unary FP ops). 89 FRE, 90 FRSQRTE, 91 92 /// VPERM - The PPC VPERM Instruction. 93 /// 94 VPERM, 95 96 /// XXSPLT - The PPC VSX splat instructions 97 /// 98 XXSPLT, 99 100 /// XXSPLTI_SP_TO_DP - The PPC VSX splat instructions for immediates for 101 /// converting immediate single precision numbers to double precision 102 /// vector or scalar. 103 XXSPLTI_SP_TO_DP, 104 105 /// XXSPLTI32DX - The PPC XXSPLTI32DX instruction. 106 /// 107 XXSPLTI32DX, 108 109 /// VECINSERT - The PPC vector insert instruction 110 /// 111 VECINSERT, 112 113 /// VECSHL - The PPC vector shift left instruction 114 /// 115 VECSHL, 116 117 /// XXPERMDI - The PPC XXPERMDI instruction 118 /// 119 XXPERMDI, 120 121 /// The CMPB instruction (takes two operands of i32 or i64). 122 CMPB, 123 124 /// Hi/Lo - These represent the high and low 16-bit parts of a global 125 /// address respectively. These nodes have two operands, the first of 126 /// which must be a TargetGlobalAddress, and the second of which must be a 127 /// Constant. Selected naively, these turn into 'lis G+C' and 'li G+C', 128 /// though these are usually folded into other nodes. 129 Hi, 130 Lo, 131 132 /// The following two target-specific nodes are used for calls through 133 /// function pointers in the 64-bit SVR4 ABI. 134 135 /// OPRC, CHAIN = DYNALLOC(CHAIN, NEGSIZE, FRAME_INDEX) 136 /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to 137 /// compute an allocation on the stack. 138 DYNALLOC, 139 140 /// This instruction is lowered in PPCRegisterInfo::eliminateFrameIndex to 141 /// compute an offset from native SP to the address of the most recent 142 /// dynamic alloca. 143 DYNAREAOFFSET, 144 145 /// To avoid stack clash, allocation is performed by block and each block is 146 /// probed. 147 PROBED_ALLOCA, 148 149 /// GlobalBaseReg - On Darwin, this node represents the result of the mflr 150 /// at function entry, used for PIC code. 151 GlobalBaseReg, 152 153 /// These nodes represent PPC shifts. 154 /// 155 /// For scalar types, only the last `n + 1` bits of the shift amounts 156 /// are used, where n is log2(sizeof(element) * 8). See sld/slw, etc. 157 /// for exact behaviors. 158 /// 159 /// For vector types, only the last n bits are used. See vsld. 160 SRL, 161 SRA, 162 SHL, 163 164 /// FNMSUB - Negated multiply-subtract instruction. 165 FNMSUB, 166 167 /// EXTSWSLI = The PPC extswsli instruction, which does an extend-sign 168 /// word and shift left immediate. 169 EXTSWSLI, 170 171 /// The combination of sra[wd]i and addze used to implemented signed 172 /// integer division by a power of 2. The first operand is the dividend, 173 /// and the second is the constant shift amount (representing the 174 /// divisor). 175 SRA_ADDZE, 176 177 /// CALL - A direct function call. 178 /// CALL_NOP is a call with the special NOP which follows 64-bit 179 /// CALL_NOTOC the caller does not use the TOC. 180 /// SVR4 calls and 32-bit/64-bit AIX calls. 181 CALL, 182 CALL_NOP, 183 CALL_NOTOC, 184 185 /// CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a 186 /// MTCTR instruction. 187 MTCTR, 188 189 /// CHAIN,FLAG = BCTRL(CHAIN, INFLAG) - Directly corresponds to a 190 /// BCTRL instruction. 191 BCTRL, 192 193 /// CHAIN,FLAG = BCTRL(CHAIN, ADDR, INFLAG) - The combination of a bctrl 194 /// instruction and the TOC reload required on 64-bit ELF, 32-bit AIX 195 /// and 64-bit AIX. 196 BCTRL_LOAD_TOC, 197 198 /// Return with a flag operand, matched by 'blr' 199 RET_FLAG, 200 201 /// R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction. 202 /// This copies the bits corresponding to the specified CRREG into the 203 /// resultant GPR. Bits corresponding to other CR regs are undefined. 204 MFOCRF, 205 206 /// Direct move from a VSX register to a GPR 207 MFVSR, 208 209 /// Direct move from a GPR to a VSX register (algebraic) 210 MTVSRA, 211 212 /// Direct move from a GPR to a VSX register (zero) 213 MTVSRZ, 214 215 /// Direct move of 2 consecutive GPR to a VSX register. 216 BUILD_FP128, 217 218 /// BUILD_SPE64 and EXTRACT_SPE are analogous to BUILD_PAIR and 219 /// EXTRACT_ELEMENT but take f64 arguments instead of i64, as i64 is 220 /// unsupported for this target. 221 /// Merge 2 GPRs to a single SPE register. 222 BUILD_SPE64, 223 224 /// Extract SPE register component, second argument is high or low. 225 EXTRACT_SPE, 226 227 /// Extract a subvector from signed integer vector and convert to FP. 228 /// It is primarily used to convert a (widened) illegal integer vector 229 /// type to a legal floating point vector type. 230 /// For example v2i32 -> widened to v4i32 -> v2f64 231 SINT_VEC_TO_FP, 232 233 /// Extract a subvector from unsigned integer vector and convert to FP. 234 /// As with SINT_VEC_TO_FP, used for converting illegal types. 235 UINT_VEC_TO_FP, 236 237 /// PowerPC instructions that have SCALAR_TO_VECTOR semantics tend to 238 /// place the value into the least significant element of the most 239 /// significant doubleword in the vector. This is not element zero for 240 /// anything smaller than a doubleword on either endianness. This node has 241 /// the same semantics as SCALAR_TO_VECTOR except that the value remains in 242 /// the aforementioned location in the vector register. 243 SCALAR_TO_VECTOR_PERMUTED, 244 245 // FIXME: Remove these once the ANDI glue bug is fixed: 246 /// i1 = ANDI_rec_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the 247 /// eq or gt bit of CR0 after executing andi. x, 1. This is used to 248 /// implement truncation of i32 or i64 to i1. 249 ANDI_rec_1_EQ_BIT, 250 ANDI_rec_1_GT_BIT, 251 252 // READ_TIME_BASE - A read of the 64-bit time-base register on a 32-bit 253 // target (returns (Lo, Hi)). It takes a chain operand. 254 READ_TIME_BASE, 255 256 // EH_SJLJ_SETJMP - SjLj exception handling setjmp. 257 EH_SJLJ_SETJMP, 258 259 // EH_SJLJ_LONGJMP - SjLj exception handling longjmp. 260 EH_SJLJ_LONGJMP, 261 262 /// RESVEC = VCMP(LHS, RHS, OPC) - Represents one of the altivec VCMP* 263 /// instructions. For lack of better number, we use the opcode number 264 /// encoding for the OPC field to identify the compare. For example, 838 265 /// is VCMPGTSH. 266 VCMP, 267 268 /// RESVEC, OUTFLAG = VCMPo(LHS, RHS, OPC) - Represents one of the 269 /// altivec VCMP*o instructions. For lack of better number, we use the 270 /// opcode number encoding for the OPC field to identify the compare. For 271 /// example, 838 is VCMPGTSH. 272 VCMPo, 273 274 /// CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This 275 /// corresponds to the COND_BRANCH pseudo instruction. CRRC is the 276 /// condition register to branch on, OPC is the branch opcode to use (e.g. 277 /// PPC::BLE), DESTBB is the destination block to branch to, and INFLAG is 278 /// an optional input flag argument. 279 COND_BRANCH, 280 281 /// CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based 282 /// loops. 283 BDNZ, 284 BDZ, 285 286 /// F8RC = FADDRTZ F8RC, F8RC - This is an FADD done with rounding 287 /// towards zero. Used only as part of the long double-to-int 288 /// conversion sequence. 289 FADDRTZ, 290 291 /// F8RC = MFFS - This moves the FPSCR (not modeled) into the register. 292 MFFS, 293 294 /// TC_RETURN - A tail call return. 295 /// operand #0 chain 296 /// operand #1 callee (register or absolute) 297 /// operand #2 stack adjustment 298 /// operand #3 optional in flag 299 TC_RETURN, 300 301 /// ch, gl = CR6[UN]SET ch, inglue - Toggle CR bit 6 for SVR4 vararg calls 302 CR6SET, 303 CR6UNSET, 304 305 /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by initial-exec TLS 306 /// for non-position independent code on PPC32. 307 PPC32_GOT, 308 309 /// GPRC = address of _GLOBAL_OFFSET_TABLE_. Used by general dynamic and 310 /// local dynamic TLS and position indendepent code on PPC32. 311 PPC32_PICGOT, 312 313 /// G8RC = ADDIS_GOT_TPREL_HA %x2, Symbol - Used by the initial-exec 314 /// TLS model, produces an ADDIS8 instruction that adds the GOT 315 /// base to sym\@got\@tprel\@ha. 316 ADDIS_GOT_TPREL_HA, 317 318 /// G8RC = LD_GOT_TPREL_L Symbol, G8RReg - Used by the initial-exec 319 /// TLS model, produces a LD instruction with base register G8RReg 320 /// and offset sym\@got\@tprel\@l. This completes the addition that 321 /// finds the offset of "sym" relative to the thread pointer. 322 LD_GOT_TPREL_L, 323 324 /// G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS 325 /// model, produces an ADD instruction that adds the contents of 326 /// G8RReg to the thread pointer. Symbol contains a relocation 327 /// sym\@tls which is to be replaced by the thread pointer and 328 /// identifies to the linker that the instruction is part of a 329 /// TLS sequence. 330 ADD_TLS, 331 332 /// G8RC = ADDIS_TLSGD_HA %x2, Symbol - For the general-dynamic TLS 333 /// model, produces an ADDIS8 instruction that adds the GOT base 334 /// register to sym\@got\@tlsgd\@ha. 335 ADDIS_TLSGD_HA, 336 337 /// %x3 = ADDI_TLSGD_L G8RReg, Symbol - For the general-dynamic TLS 338 /// model, produces an ADDI8 instruction that adds G8RReg to 339 /// sym\@got\@tlsgd\@l and stores the result in X3. Hidden by 340 /// ADDIS_TLSGD_L_ADDR until after register assignment. 341 ADDI_TLSGD_L, 342 343 /// %x3 = GET_TLS_ADDR %x3, Symbol - For the general-dynamic TLS 344 /// model, produces a call to __tls_get_addr(sym\@tlsgd). Hidden by 345 /// ADDIS_TLSGD_L_ADDR until after register assignment. 346 GET_TLS_ADDR, 347 348 /// G8RC = ADDI_TLSGD_L_ADDR G8RReg, Symbol, Symbol - Op that 349 /// combines ADDI_TLSGD_L and GET_TLS_ADDR until expansion following 350 /// register assignment. 351 ADDI_TLSGD_L_ADDR, 352 353 /// G8RC = ADDIS_TLSLD_HA %x2, Symbol - For the local-dynamic TLS 354 /// model, produces an ADDIS8 instruction that adds the GOT base 355 /// register to sym\@got\@tlsld\@ha. 356 ADDIS_TLSLD_HA, 357 358 /// %x3 = ADDI_TLSLD_L G8RReg, Symbol - For the local-dynamic TLS 359 /// model, produces an ADDI8 instruction that adds G8RReg to 360 /// sym\@got\@tlsld\@l and stores the result in X3. Hidden by 361 /// ADDIS_TLSLD_L_ADDR until after register assignment. 362 ADDI_TLSLD_L, 363 364 /// %x3 = GET_TLSLD_ADDR %x3, Symbol - For the local-dynamic TLS 365 /// model, produces a call to __tls_get_addr(sym\@tlsld). Hidden by 366 /// ADDIS_TLSLD_L_ADDR until after register assignment. 367 GET_TLSLD_ADDR, 368 369 /// G8RC = ADDI_TLSLD_L_ADDR G8RReg, Symbol, Symbol - Op that 370 /// combines ADDI_TLSLD_L and GET_TLSLD_ADDR until expansion 371 /// following register assignment. 372 ADDI_TLSLD_L_ADDR, 373 374 /// G8RC = ADDIS_DTPREL_HA %x3, Symbol - For the local-dynamic TLS 375 /// model, produces an ADDIS8 instruction that adds X3 to 376 /// sym\@dtprel\@ha. 377 ADDIS_DTPREL_HA, 378 379 /// G8RC = ADDI_DTPREL_L G8RReg, Symbol - For the local-dynamic TLS 380 /// model, produces an ADDI8 instruction that adds G8RReg to 381 /// sym\@got\@dtprel\@l. 382 ADDI_DTPREL_L, 383 384 /// G8RC = PADDI_DTPREL %x3, Symbol - For the pc-rel based local-dynamic TLS 385 /// model, produces a PADDI8 instruction that adds X3 to sym\@dtprel. 386 PADDI_DTPREL, 387 388 /// VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded 389 /// during instruction selection to optimize a BUILD_VECTOR into 390 /// operations on splats. This is necessary to avoid losing these 391 /// optimizations due to constant folding. 392 VADD_SPLAT, 393 394 /// CHAIN = SC CHAIN, Imm128 - System call. The 7-bit unsigned 395 /// operand identifies the operating system entry point. 396 SC, 397 398 /// CHAIN = CLRBHRB CHAIN - Clear branch history rolling buffer. 399 CLRBHRB, 400 401 /// GPRC, CHAIN = MFBHRBE CHAIN, Entry, Dummy - Move from branch 402 /// history rolling buffer entry. 403 MFBHRBE, 404 405 /// CHAIN = RFEBB CHAIN, State - Return from event-based branch. 406 RFEBB, 407 408 /// VSRC, CHAIN = XXSWAPD CHAIN, VSRC - Occurs only for little 409 /// endian. Maps to an xxswapd instruction that corrects an lxvd2x 410 /// or stxvd2x instruction. The chain is necessary because the 411 /// sequence replaces a load and needs to provide the same number 412 /// of outputs. 413 XXSWAPD, 414 415 /// An SDNode for swaps that are not associated with any loads/stores 416 /// and thereby have no chain. 417 SWAP_NO_CHAIN, 418 419 /// An SDNode for Power9 vector absolute value difference. 420 /// operand #0 vector 421 /// operand #1 vector 422 /// operand #2 constant i32 0 or 1, to indicate whether needs to patch 423 /// the most significant bit for signed i32 424 /// 425 /// Power9 VABSD* instructions are designed to support unsigned integer 426 /// vectors (byte/halfword/word), if we want to make use of them for signed 427 /// integer vectors, we have to flip their sign bits first. To flip sign bit 428 /// for byte/halfword integer vector would become inefficient, but for word 429 /// integer vector, we can leverage XVNEGSP to make it efficiently. eg: 430 /// abs(sub(a,b)) => VABSDUW(a+0x80000000, b+0x80000000) 431 /// => VABSDUW((XVNEGSP a), (XVNEGSP b)) 432 VABSD, 433 434 /// FP_EXTEND_HALF(VECTOR, IDX) - Custom extend upper (IDX=0) half or 435 /// lower (IDX=1) half of v4f32 to v2f64. 436 FP_EXTEND_HALF, 437 438 /// MAT_PCREL_ADDR = Materialize a PC Relative address. This can be done 439 /// either through an add like PADDI or through a PC Relative load like 440 /// PLD. 441 MAT_PCREL_ADDR, 442 443 /// TLS_DYNAMIC_MAT_PCREL_ADDR = Materialize a PC Relative address for 444 /// TLS global address when using dynamic access models. This can be done 445 /// through an add like PADDI. 446 TLS_DYNAMIC_MAT_PCREL_ADDR, 447 448 /// TLS_LOCAL_EXEC_MAT_ADDR = Materialize an address for TLS global address 449 /// when using local exec access models, and when prefixed instructions are 450 /// available. This is used with ADD_TLS to produce an add like PADDI. 451 TLS_LOCAL_EXEC_MAT_ADDR, 452 453 /// ACC_BUILD = Build an accumulator register from 4 VSX registers. 454 ACC_BUILD, 455 456 /// PAIR_BUILD = Build a vector pair register from 2 VSX registers. 457 PAIR_BUILD, 458 459 /// EXTRACT_VSX_REG = Extract one of the underlying vsx registers of 460 /// an accumulator or pair register. This node is needed because 461 /// EXTRACT_SUBVECTOR expects the input and output vectors to have the same 462 /// element type. 463 EXTRACT_VSX_REG, 464 465 /// XXMFACC = This corresponds to the xxmfacc instruction. 466 XXMFACC, 467 468 // Constrained conversion from floating point to int 469 STRICT_FCTIDZ = ISD::FIRST_TARGET_STRICTFP_OPCODE, 470 STRICT_FCTIWZ, 471 STRICT_FCTIDUZ, 472 STRICT_FCTIWUZ, 473 474 /// Constrained integer-to-floating-point conversion instructions. 475 STRICT_FCFID, 476 STRICT_FCFIDU, 477 STRICT_FCFIDS, 478 STRICT_FCFIDUS, 479 480 /// Constrained floating point add in round-to-zero mode. 481 STRICT_FADDRTZ, 482 483 /// CHAIN = STBRX CHAIN, GPRC, Ptr, Type - This is a 484 /// byte-swapping store instruction. It byte-swaps the low "Type" bits of 485 /// the GPRC input, then stores it through Ptr. Type can be either i16 or 486 /// i32. 487 STBRX = ISD::FIRST_TARGET_MEMORY_OPCODE, 488 489 /// GPRC, CHAIN = LBRX CHAIN, Ptr, Type - This is a 490 /// byte-swapping load instruction. It loads "Type" bits, byte swaps it, 491 /// then puts it in the bottom bits of the GPRC. TYPE can be either i16 492 /// or i32. 493 LBRX, 494 495 /// STFIWX - The STFIWX instruction. The first operand is an input token 496 /// chain, then an f64 value to store, then an address to store it to. 497 STFIWX, 498 499 /// GPRC, CHAIN = LFIWAX CHAIN, Ptr - This is a floating-point 500 /// load which sign-extends from a 32-bit integer value into the 501 /// destination 64-bit register. 502 LFIWAX, 503 504 /// GPRC, CHAIN = LFIWZX CHAIN, Ptr - This is a floating-point 505 /// load which zero-extends from a 32-bit integer value into the 506 /// destination 64-bit register. 507 LFIWZX, 508 509 /// GPRC, CHAIN = LXSIZX, CHAIN, Ptr, ByteWidth - This is a load of an 510 /// integer smaller than 64 bits into a VSR. The integer is zero-extended. 511 /// This can be used for converting loaded integers to floating point. 512 LXSIZX, 513 514 /// STXSIX - The STXSI[bh]X instruction. The first operand is an input 515 /// chain, then an f64 value to store, then an address to store it to, 516 /// followed by a byte-width for the store. 517 STXSIX, 518 519 /// VSRC, CHAIN = LXVD2X_LE CHAIN, Ptr - Occurs only for little endian. 520 /// Maps directly to an lxvd2x instruction that will be followed by 521 /// an xxswapd. 522 LXVD2X, 523 524 /// LXVRZX - Load VSX Vector Rightmost and Zero Extend 525 /// This node represents v1i128 BUILD_VECTOR of a zero extending load 526 /// instruction from <byte, halfword, word, or doubleword> to i128. 527 /// Allows utilization of the Load VSX Vector Rightmost Instructions. 528 LXVRZX, 529 530 /// VSRC, CHAIN = LOAD_VEC_BE CHAIN, Ptr - Occurs only for little endian. 531 /// Maps directly to one of lxvd2x/lxvw4x/lxvh8x/lxvb16x depending on 532 /// the vector type to load vector in big-endian element order. 533 LOAD_VEC_BE, 534 535 /// VSRC, CHAIN = LD_VSX_LH CHAIN, Ptr - This is a floating-point load of a 536 /// v2f32 value into the lower half of a VSR register. 537 LD_VSX_LH, 538 539 /// VSRC, CHAIN = LD_SPLAT, CHAIN, Ptr - a splatting load memory 540 /// instructions such as LXVDSX, LXVWSX. 541 LD_SPLAT, 542 543 /// CHAIN = STXVD2X CHAIN, VSRC, Ptr - Occurs only for little endian. 544 /// Maps directly to an stxvd2x instruction that will be preceded by 545 /// an xxswapd. 546 STXVD2X, 547 548 /// CHAIN = STORE_VEC_BE CHAIN, VSRC, Ptr - Occurs only for little endian. 549 /// Maps directly to one of stxvd2x/stxvw4x/stxvh8x/stxvb16x depending on 550 /// the vector type to store vector in big-endian element order. 551 STORE_VEC_BE, 552 553 /// Store scalar integers from VSR. 554 ST_VSR_SCAL_INT, 555 556 /// ATOMIC_CMP_SWAP - the exact same as the target-independent nodes 557 /// except they ensure that the compare input is zero-extended for 558 /// sub-word versions because the atomic loads zero-extend. 559 ATOMIC_CMP_SWAP_8, 560 ATOMIC_CMP_SWAP_16, 561 562 /// GPRC = TOC_ENTRY GA, TOC 563 /// Loads the entry for GA from the TOC, where the TOC base is given by 564 /// the last operand. 565 TOC_ENTRY 566 }; 567 568 } // end namespace PPCISD 569 570 /// Define some predicates that are used for node matching. 571 namespace PPC { 572 573 /// isVPKUHUMShuffleMask - Return true if this is the shuffle mask for a 574 /// VPKUHUM instruction. 575 bool isVPKUHUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind, 576 SelectionDAG &DAG); 577 578 /// isVPKUWUMShuffleMask - Return true if this is the shuffle mask for a 579 /// VPKUWUM instruction. 580 bool isVPKUWUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind, 581 SelectionDAG &DAG); 582 583 /// isVPKUDUMShuffleMask - Return true if this is the shuffle mask for a 584 /// VPKUDUM instruction. 585 bool isVPKUDUMShuffleMask(ShuffleVectorSDNode *N, unsigned ShuffleKind, 586 SelectionDAG &DAG); 587 588 /// isVMRGLShuffleMask - Return true if this is a shuffle mask suitable for 589 /// a VRGL* instruction with the specified unit size (1,2 or 4 bytes). 590 bool isVMRGLShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize, 591 unsigned ShuffleKind, SelectionDAG &DAG); 592 593 /// isVMRGHShuffleMask - Return true if this is a shuffle mask suitable for 594 /// a VRGH* instruction with the specified unit size (1,2 or 4 bytes). 595 bool isVMRGHShuffleMask(ShuffleVectorSDNode *N, unsigned UnitSize, 596 unsigned ShuffleKind, SelectionDAG &DAG); 597 598 /// isVMRGEOShuffleMask - Return true if this is a shuffle mask suitable for 599 /// a VMRGEW or VMRGOW instruction 600 bool isVMRGEOShuffleMask(ShuffleVectorSDNode *N, bool CheckEven, 601 unsigned ShuffleKind, SelectionDAG &DAG); 602 /// isXXSLDWIShuffleMask - Return true if this is a shuffle mask suitable 603 /// for a XXSLDWI instruction. 604 bool isXXSLDWIShuffleMask(ShuffleVectorSDNode *N, unsigned &ShiftElts, 605 bool &Swap, bool IsLE); 606 607 /// isXXBRHShuffleMask - Return true if this is a shuffle mask suitable 608 /// for a XXBRH instruction. 609 bool isXXBRHShuffleMask(ShuffleVectorSDNode *N); 610 611 /// isXXBRWShuffleMask - Return true if this is a shuffle mask suitable 612 /// for a XXBRW instruction. 613 bool isXXBRWShuffleMask(ShuffleVectorSDNode *N); 614 615 /// isXXBRDShuffleMask - Return true if this is a shuffle mask suitable 616 /// for a XXBRD instruction. 617 bool isXXBRDShuffleMask(ShuffleVectorSDNode *N); 618 619 /// isXXBRQShuffleMask - Return true if this is a shuffle mask suitable 620 /// for a XXBRQ instruction. 621 bool isXXBRQShuffleMask(ShuffleVectorSDNode *N); 622 623 /// isXXPERMDIShuffleMask - Return true if this is a shuffle mask suitable 624 /// for a XXPERMDI instruction. 625 bool isXXPERMDIShuffleMask(ShuffleVectorSDNode *N, unsigned &ShiftElts, 626 bool &Swap, bool IsLE); 627 628 /// isVSLDOIShuffleMask - If this is a vsldoi shuffle mask, return the 629 /// shift amount, otherwise return -1. 630 int isVSLDOIShuffleMask(SDNode *N, unsigned ShuffleKind, 631 SelectionDAG &DAG); 632 633 /// isSplatShuffleMask - Return true if the specified VECTOR_SHUFFLE operand 634 /// specifies a splat of a single element that is suitable for input to 635 /// VSPLTB/VSPLTH/VSPLTW. 636 bool isSplatShuffleMask(ShuffleVectorSDNode *N, unsigned EltSize); 637 638 /// isXXINSERTWMask - Return true if this VECTOR_SHUFFLE can be handled by 639 /// the XXINSERTW instruction introduced in ISA 3.0. This is essentially any 640 /// shuffle of v4f32/v4i32 vectors that just inserts one element from one 641 /// vector into the other. This function will also set a couple of 642 /// output parameters for how much the source vector needs to be shifted and 643 /// what byte number needs to be specified for the instruction to put the 644 /// element in the desired location of the target vector. 645 bool isXXINSERTWMask(ShuffleVectorSDNode *N, unsigned &ShiftElts, 646 unsigned &InsertAtByte, bool &Swap, bool IsLE); 647 648 /// getSplatIdxForPPCMnemonics - Return the splat index as a value that is 649 /// appropriate for PPC mnemonics (which have a big endian bias - namely 650 /// elements are counted from the left of the vector register). 651 unsigned getSplatIdxForPPCMnemonics(SDNode *N, unsigned EltSize, 652 SelectionDAG &DAG); 653 654 /// get_VSPLTI_elt - If this is a build_vector of constants which can be 655 /// formed by using a vspltis[bhw] instruction of the specified element 656 /// size, return the constant being splatted. The ByteSize field indicates 657 /// the number of bytes of each element [124] -> [bhw]. 658 SDValue get_VSPLTI_elt(SDNode *N, unsigned ByteSize, SelectionDAG &DAG); 659 660 /// If this is a qvaligni shuffle mask, return the shift 661 /// amount, otherwise return -1. 662 int isQVALIGNIShuffleMask(SDNode *N); 663 664 } // end namespace PPC 665 666 class PPCTargetLowering : public TargetLowering { 667 const PPCSubtarget &Subtarget; 668 669 public: 670 explicit PPCTargetLowering(const PPCTargetMachine &TM, 671 const PPCSubtarget &STI); 672 673 /// getTargetNodeName() - This method returns the name of a target specific 674 /// DAG node. 675 const char *getTargetNodeName(unsigned Opcode) const override; 676 677 bool isSelectSupported(SelectSupportKind Kind) const override { 678 // PowerPC does not support scalar condition selects on vectors. 679 return (Kind != SelectSupportKind::ScalarCondVectorVal); 680 } 681 682 /// getPreferredVectorAction - The code we generate when vector types are 683 /// legalized by promoting the integer element type is often much worse 684 /// than code we generate if we widen the type for applicable vector types. 685 /// The issue with promoting is that the vector is scalaraized, individual 686 /// elements promoted and then the vector is rebuilt. So say we load a pair 687 /// of v4i8's and shuffle them. This will turn into a mess of 8 extending 688 /// loads, moves back into VSR's (or memory ops if we don't have moves) and 689 /// then the VPERM for the shuffle. All in all a very slow sequence. 690 TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) 691 const override { 692 if (VT.getVectorNumElements() != 1 && VT.getScalarSizeInBits() % 8 == 0) 693 return TypeWidenVector; 694 return TargetLoweringBase::getPreferredVectorAction(VT); 695 } 696 697 bool useSoftFloat() const override; 698 699 bool hasSPE() const; 700 701 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override { 702 return MVT::i32; 703 } 704 705 bool isCheapToSpeculateCttz() const override { 706 return true; 707 } 708 709 bool isCheapToSpeculateCtlz() const override { 710 return true; 711 } 712 713 bool isCtlzFast() const override { 714 return true; 715 } 716 717 bool isEqualityCmpFoldedWithSignedCmp() const override { 718 return false; 719 } 720 721 bool hasAndNotCompare(SDValue) const override { 722 return true; 723 } 724 725 bool preferIncOfAddToSubOfNot(EVT VT) const override; 726 727 bool convertSetCCLogicToBitwiseLogic(EVT VT) const override { 728 return VT.isScalarInteger(); 729 } 730 731 SDValue getNegatedExpression(SDValue Op, SelectionDAG &DAG, bool LegalOps, 732 bool OptForSize, NegatibleCost &Cost, 733 unsigned Depth = 0) const override; 734 735 /// getSetCCResultType - Return the ISD::SETCC ValueType 736 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, 737 EVT VT) const override; 738 739 /// Return true if target always beneficiates from combining into FMA for a 740 /// given value type. This must typically return false on targets where FMA 741 /// takes more cycles to execute than FADD. 742 bool enableAggressiveFMAFusion(EVT VT) const override; 743 744 /// getPreIndexedAddressParts - returns true by value, base pointer and 745 /// offset pointer and addressing mode by reference if the node's address 746 /// can be legally represented as pre-indexed load / store address. 747 bool getPreIndexedAddressParts(SDNode *N, SDValue &Base, 748 SDValue &Offset, 749 ISD::MemIndexedMode &AM, 750 SelectionDAG &DAG) const override; 751 752 /// SelectAddressEVXRegReg - Given the specified addressed, check to see if 753 /// it can be more efficiently represented as [r+imm]. 754 bool SelectAddressEVXRegReg(SDValue N, SDValue &Base, SDValue &Index, 755 SelectionDAG &DAG) const; 756 757 /// SelectAddressRegReg - Given the specified addressed, check to see if it 758 /// can be more efficiently represented as [r+imm]. If \p EncodingAlignment 759 /// is non-zero, only accept displacement which is not suitable for [r+imm]. 760 /// Returns false if it can be represented by [r+imm], which are preferred. 761 bool SelectAddressRegReg(SDValue N, SDValue &Base, SDValue &Index, 762 SelectionDAG &DAG, 763 MaybeAlign EncodingAlignment = None) const; 764 765 /// SelectAddressRegImm - Returns true if the address N can be represented 766 /// by a base register plus a signed 16-bit displacement [r+imm], and if it 767 /// is not better represented as reg+reg. If \p EncodingAlignment is 768 /// non-zero, only accept displacements suitable for instruction encoding 769 /// requirement, i.e. multiples of 4 for DS form. 770 bool SelectAddressRegImm(SDValue N, SDValue &Disp, SDValue &Base, 771 SelectionDAG &DAG, 772 MaybeAlign EncodingAlignment) const; 773 774 /// SelectAddressRegRegOnly - Given the specified addressed, force it to be 775 /// represented as an indexed [r+r] operation. 776 bool SelectAddressRegRegOnly(SDValue N, SDValue &Base, SDValue &Index, 777 SelectionDAG &DAG) const; 778 779 /// SelectAddressPCRel - Represent the specified address as pc relative to 780 /// be represented as [pc+imm] 781 bool SelectAddressPCRel(SDValue N, SDValue &Base) const; 782 783 Sched::Preference getSchedulingPreference(SDNode *N) const override; 784 785 /// LowerOperation - Provide custom lowering hooks for some operations. 786 /// 787 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; 788 789 /// LowerOperationWrapper - Place custom new result values for node in 790 /// Results. 791 void LowerOperationWrapper(SDNode *N, 792 SmallVectorImpl<SDValue> &Results, 793 SelectionDAG &DAG) const override; 794 795 /// ReplaceNodeResults - Replace the results of node with an illegal result 796 /// type with new values built out of custom code. 797 /// 798 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 799 SelectionDAG &DAG) const override; 800 801 SDValue expandVSXLoadForLE(SDNode *N, DAGCombinerInfo &DCI) const; 802 SDValue expandVSXStoreForLE(SDNode *N, DAGCombinerInfo &DCI) const; 803 804 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; 805 806 SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG, 807 SmallVectorImpl<SDNode *> &Created) const override; 808 809 Register getRegisterByName(const char* RegName, LLT VT, 810 const MachineFunction &MF) const override; 811 812 void computeKnownBitsForTargetNode(const SDValue Op, 813 KnownBits &Known, 814 const APInt &DemandedElts, 815 const SelectionDAG &DAG, 816 unsigned Depth = 0) const override; 817 818 Align getPrefLoopAlignment(MachineLoop *ML) const override; 819 820 bool shouldInsertFencesForAtomic(const Instruction *I) const override { 821 return true; 822 } 823 824 Instruction *emitLeadingFence(IRBuilder<> &Builder, Instruction *Inst, 825 AtomicOrdering Ord) const override; 826 Instruction *emitTrailingFence(IRBuilder<> &Builder, Instruction *Inst, 827 AtomicOrdering Ord) const override; 828 829 MachineBasicBlock * 830 EmitInstrWithCustomInserter(MachineInstr &MI, 831 MachineBasicBlock *MBB) const override; 832 MachineBasicBlock *EmitAtomicBinary(MachineInstr &MI, 833 MachineBasicBlock *MBB, 834 unsigned AtomicSize, 835 unsigned BinOpcode, 836 unsigned CmpOpcode = 0, 837 unsigned CmpPred = 0) const; 838 MachineBasicBlock *EmitPartwordAtomicBinary(MachineInstr &MI, 839 MachineBasicBlock *MBB, 840 bool is8bit, 841 unsigned Opcode, 842 unsigned CmpOpcode = 0, 843 unsigned CmpPred = 0) const; 844 845 MachineBasicBlock *emitEHSjLjSetJmp(MachineInstr &MI, 846 MachineBasicBlock *MBB) const; 847 848 MachineBasicBlock *emitEHSjLjLongJmp(MachineInstr &MI, 849 MachineBasicBlock *MBB) const; 850 851 MachineBasicBlock *emitProbedAlloca(MachineInstr &MI, 852 MachineBasicBlock *MBB) const; 853 854 bool hasInlineStackProbe(MachineFunction &MF) const override; 855 856 unsigned getStackProbeSize(MachineFunction &MF) const; 857 858 ConstraintType getConstraintType(StringRef Constraint) const override; 859 860 /// Examine constraint string and operand type and determine a weight value. 861 /// The operand object must already have been set up with the operand type. 862 ConstraintWeight getSingleConstraintMatchWeight( 863 AsmOperandInfo &info, const char *constraint) const override; 864 865 std::pair<unsigned, const TargetRegisterClass *> 866 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, 867 StringRef Constraint, MVT VT) const override; 868 869 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 870 /// function arguments in the caller parameter area. This is the actual 871 /// alignment, not its logarithm. 872 unsigned getByValTypeAlignment(Type *Ty, 873 const DataLayout &DL) const override; 874 875 /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops 876 /// vector. If it is invalid, don't add anything to Ops. 877 void LowerAsmOperandForConstraint(SDValue Op, 878 std::string &Constraint, 879 std::vector<SDValue> &Ops, 880 SelectionDAG &DAG) const override; 881 882 unsigned 883 getInlineAsmMemConstraint(StringRef ConstraintCode) const override { 884 if (ConstraintCode == "es") 885 return InlineAsm::Constraint_es; 886 else if (ConstraintCode == "o") 887 return InlineAsm::Constraint_o; 888 else if (ConstraintCode == "Q") 889 return InlineAsm::Constraint_Q; 890 else if (ConstraintCode == "Z") 891 return InlineAsm::Constraint_Z; 892 else if (ConstraintCode == "Zy") 893 return InlineAsm::Constraint_Zy; 894 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode); 895 } 896 897 /// isLegalAddressingMode - Return true if the addressing mode represented 898 /// by AM is legal for this target, for a load/store of the specified type. 899 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, 900 Type *Ty, unsigned AS, 901 Instruction *I = nullptr) const override; 902 903 /// isLegalICmpImmediate - Return true if the specified immediate is legal 904 /// icmp immediate, that is the target has icmp instructions which can 905 /// compare a register against the immediate without having to materialize 906 /// the immediate into a register. 907 bool isLegalICmpImmediate(int64_t Imm) const override; 908 909 /// isLegalAddImmediate - Return true if the specified immediate is legal 910 /// add immediate, that is the target has add instructions which can 911 /// add a register and the immediate without having to materialize 912 /// the immediate into a register. 913 bool isLegalAddImmediate(int64_t Imm) const override; 914 915 /// isTruncateFree - Return true if it's free to truncate a value of 916 /// type Ty1 to type Ty2. e.g. On PPC it's free to truncate a i64 value in 917 /// register X1 to i32 by referencing its sub-register R1. 918 bool isTruncateFree(Type *Ty1, Type *Ty2) const override; 919 bool isTruncateFree(EVT VT1, EVT VT2) const override; 920 921 bool isZExtFree(SDValue Val, EVT VT2) const override; 922 923 bool isFPExtFree(EVT DestVT, EVT SrcVT) const override; 924 925 /// Returns true if it is beneficial to convert a load of a constant 926 /// to just the constant itself. 927 bool shouldConvertConstantLoadToIntImm(const APInt &Imm, 928 Type *Ty) const override; 929 930 bool convertSelectOfConstantsToMath(EVT VT) const override { 931 return true; 932 } 933 934 bool decomposeMulByConstant(LLVMContext &Context, EVT VT, 935 SDValue C) const override; 936 937 bool isDesirableToTransformToIntegerOp(unsigned Opc, 938 EVT VT) const override { 939 // Only handle float load/store pair because float(fpr) load/store 940 // instruction has more cycles than integer(gpr) load/store in PPC. 941 if (Opc != ISD::LOAD && Opc != ISD::STORE) 942 return false; 943 if (VT != MVT::f32 && VT != MVT::f64) 944 return false; 945 946 return true; 947 } 948 949 // Returns true if the address of the global is stored in TOC entry. 950 bool isAccessedAsGotIndirect(SDValue N) const; 951 952 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override; 953 954 bool getTgtMemIntrinsic(IntrinsicInfo &Info, 955 const CallInst &I, 956 MachineFunction &MF, 957 unsigned Intrinsic) const override; 958 959 /// It returns EVT::Other if the type should be determined using generic 960 /// target-independent logic. 961 EVT getOptimalMemOpType(const MemOp &Op, 962 const AttributeList &FuncAttributes) const override; 963 964 /// Is unaligned memory access allowed for the given type, and is it fast 965 /// relative to software emulation. 966 bool allowsMisalignedMemoryAccesses( 967 EVT VT, unsigned AddrSpace, unsigned Align = 1, 968 MachineMemOperand::Flags Flags = MachineMemOperand::MONone, 969 bool *Fast = nullptr) const override; 970 971 /// isFMAFasterThanFMulAndFAdd - Return true if an FMA operation is faster 972 /// than a pair of fmul and fadd instructions. fmuladd intrinsics will be 973 /// expanded to FMAs when this method returns true, otherwise fmuladd is 974 /// expanded to fmul + fadd. 975 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, 976 EVT VT) const override; 977 978 bool isFMAFasterThanFMulAndFAdd(const Function &F, Type *Ty) const override; 979 980 /// isProfitableToHoist - Check if it is profitable to hoist instruction 981 /// \p I to its dominator block. 982 /// For example, it is not profitable if \p I and it's only user can form a 983 /// FMA instruction, because Powerpc prefers FMADD. 984 bool isProfitableToHoist(Instruction *I) const override; 985 986 const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override; 987 988 // Should we expand the build vector with shuffles? 989 bool 990 shouldExpandBuildVectorWithShuffles(EVT VT, 991 unsigned DefinedValues) const override; 992 993 /// createFastISel - This method returns a target-specific FastISel object, 994 /// or null if the target does not support "fast" instruction selection. 995 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo, 996 const TargetLibraryInfo *LibInfo) const override; 997 998 /// Returns true if an argument of type Ty needs to be passed in a 999 /// contiguous block of registers in calling convention CallConv. 1000 bool functionArgumentNeedsConsecutiveRegisters( 1001 Type *Ty, CallingConv::ID CallConv, bool isVarArg) const override { 1002 // We support any array type as "consecutive" block in the parameter 1003 // save area. The element type defines the alignment requirement and 1004 // whether the argument should go in GPRs, FPRs, or VRs if available. 1005 // 1006 // Note that clang uses this capability both to implement the ELFv2 1007 // homogeneous float/vector aggregate ABI, and to avoid having to use 1008 // "byval" when passing aggregates that might fully fit in registers. 1009 return Ty->isArrayTy(); 1010 } 1011 1012 /// If a physical register, this returns the register that receives the 1013 /// exception address on entry to an EH pad. 1014 Register 1015 getExceptionPointerRegister(const Constant *PersonalityFn) const override; 1016 1017 /// If a physical register, this returns the register that receives the 1018 /// exception typeid on entry to a landing pad. 1019 Register 1020 getExceptionSelectorRegister(const Constant *PersonalityFn) const override; 1021 1022 /// Override to support customized stack guard loading. 1023 bool useLoadStackGuardNode() const override; 1024 void insertSSPDeclarations(Module &M) const override; 1025 1026 bool isFPImmLegal(const APFloat &Imm, EVT VT, 1027 bool ForCodeSize) const override; 1028 1029 unsigned getJumpTableEncoding() const override; 1030 bool isJumpTableRelative() const override; 1031 SDValue getPICJumpTableRelocBase(SDValue Table, 1032 SelectionDAG &DAG) const override; 1033 const MCExpr *getPICJumpTableRelocBaseExpr(const MachineFunction *MF, 1034 unsigned JTI, 1035 MCContext &Ctx) const override; 1036 1037 /// Structure that collects some common arguments that get passed around 1038 /// between the functions for call lowering. 1039 struct CallFlags { 1040 const CallingConv::ID CallConv; 1041 const bool IsTailCall : 1; 1042 const bool IsVarArg : 1; 1043 const bool IsPatchPoint : 1; 1044 const bool IsIndirect : 1; 1045 const bool HasNest : 1; 1046 const bool NoMerge : 1; 1047 1048 CallFlags(CallingConv::ID CC, bool IsTailCall, bool IsVarArg, 1049 bool IsPatchPoint, bool IsIndirect, bool HasNest, bool NoMerge) 1050 : CallConv(CC), IsTailCall(IsTailCall), IsVarArg(IsVarArg), 1051 IsPatchPoint(IsPatchPoint), IsIndirect(IsIndirect), 1052 HasNest(HasNest), NoMerge(NoMerge) {} 1053 }; 1054 1055 private: 1056 struct ReuseLoadInfo { 1057 SDValue Ptr; 1058 SDValue Chain; 1059 SDValue ResChain; 1060 MachinePointerInfo MPI; 1061 bool IsDereferenceable = false; 1062 bool IsInvariant = false; 1063 Align Alignment; 1064 AAMDNodes AAInfo; 1065 const MDNode *Ranges = nullptr; 1066 1067 ReuseLoadInfo() = default; 1068 1069 MachineMemOperand::Flags MMOFlags() const { 1070 MachineMemOperand::Flags F = MachineMemOperand::MONone; 1071 if (IsDereferenceable) 1072 F |= MachineMemOperand::MODereferenceable; 1073 if (IsInvariant) 1074 F |= MachineMemOperand::MOInvariant; 1075 return F; 1076 } 1077 }; 1078 1079 bool canReuseLoadAddress(SDValue Op, EVT MemVT, ReuseLoadInfo &RLI, 1080 SelectionDAG &DAG, 1081 ISD::LoadExtType ET = ISD::NON_EXTLOAD) const; 1082 void spliceIntoChain(SDValue ResChain, SDValue NewResChain, 1083 SelectionDAG &DAG) const; 1084 1085 void LowerFP_TO_INTForReuse(SDValue Op, ReuseLoadInfo &RLI, 1086 SelectionDAG &DAG, const SDLoc &dl) const; 1087 SDValue LowerFP_TO_INTDirectMove(SDValue Op, SelectionDAG &DAG, 1088 const SDLoc &dl) const; 1089 1090 bool directMoveIsProfitable(const SDValue &Op) const; 1091 SDValue LowerINT_TO_FPDirectMove(SDValue Op, SelectionDAG &DAG, 1092 const SDLoc &dl) const; 1093 1094 SDValue LowerINT_TO_FPVector(SDValue Op, SelectionDAG &DAG, 1095 const SDLoc &dl) const; 1096 1097 SDValue LowerTRUNCATEVector(SDValue Op, SelectionDAG &DAG) const; 1098 1099 SDValue getFramePointerFrameIndex(SelectionDAG & DAG) const; 1100 SDValue getReturnAddrFrameIndex(SelectionDAG & DAG) const; 1101 1102 bool 1103 IsEligibleForTailCallOptimization(SDValue Callee, 1104 CallingConv::ID CalleeCC, 1105 bool isVarArg, 1106 const SmallVectorImpl<ISD::InputArg> &Ins, 1107 SelectionDAG& DAG) const; 1108 1109 bool IsEligibleForTailCallOptimization_64SVR4( 1110 SDValue Callee, CallingConv::ID CalleeCC, const CallBase *CB, 1111 bool isVarArg, const SmallVectorImpl<ISD::OutputArg> &Outs, 1112 const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const; 1113 1114 SDValue EmitTailCallLoadFPAndRetAddr(SelectionDAG &DAG, int SPDiff, 1115 SDValue Chain, SDValue &LROpOut, 1116 SDValue &FPOpOut, 1117 const SDLoc &dl) const; 1118 1119 SDValue getTOCEntry(SelectionDAG &DAG, const SDLoc &dl, SDValue GA) const; 1120 1121 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; 1122 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; 1123 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; 1124 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; 1125 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const; 1126 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; 1127 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const; 1128 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const; 1129 SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const; 1130 SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const; 1131 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; 1132 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const; 1133 SDValue LowerVACOPY(SDValue Op, SelectionDAG &DAG) const; 1134 SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const; 1135 SDValue LowerGET_DYNAMIC_AREA_OFFSET(SDValue Op, SelectionDAG &DAG) const; 1136 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const; 1137 SDValue LowerEH_DWARF_CFA(SDValue Op, SelectionDAG &DAG) const; 1138 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const; 1139 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const; 1140 SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG) const; 1141 SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const; 1142 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG, 1143 const SDLoc &dl) const; 1144 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const; 1145 SDValue LowerFLT_ROUNDS_(SDValue Op, SelectionDAG &DAG) const; 1146 SDValue LowerSHL_PARTS(SDValue Op, SelectionDAG &DAG) const; 1147 SDValue LowerSRL_PARTS(SDValue Op, SelectionDAG &DAG) const; 1148 SDValue LowerSRA_PARTS(SDValue Op, SelectionDAG &DAG) const; 1149 SDValue LowerFunnelShift(SDValue Op, SelectionDAG &DAG) const; 1150 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const; 1151 SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const; 1152 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const; 1153 SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const; 1154 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; 1155 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const; 1156 SDValue LowerBSWAP(SDValue Op, SelectionDAG &DAG) const; 1157 SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const; 1158 SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const; 1159 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const; 1160 SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) const; 1161 SDValue LowerABS(SDValue Op, SelectionDAG &DAG) const; 1162 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const; 1163 SDValue LowerROTL(SDValue Op, SelectionDAG &DAG) const; 1164 1165 SDValue LowerVectorLoad(SDValue Op, SelectionDAG &DAG) const; 1166 SDValue LowerVectorStore(SDValue Op, SelectionDAG &DAG) const; 1167 1168 SDValue LowerCallResult(SDValue Chain, SDValue InFlag, 1169 CallingConv::ID CallConv, bool isVarArg, 1170 const SmallVectorImpl<ISD::InputArg> &Ins, 1171 const SDLoc &dl, SelectionDAG &DAG, 1172 SmallVectorImpl<SDValue> &InVals) const; 1173 1174 SDValue FinishCall(CallFlags CFlags, const SDLoc &dl, SelectionDAG &DAG, 1175 SmallVector<std::pair<unsigned, SDValue>, 8> &RegsToPass, 1176 SDValue InFlag, SDValue Chain, SDValue CallSeqStart, 1177 SDValue &Callee, int SPDiff, unsigned NumBytes, 1178 const SmallVectorImpl<ISD::InputArg> &Ins, 1179 SmallVectorImpl<SDValue> &InVals, 1180 const CallBase *CB) const; 1181 1182 SDValue 1183 LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 1184 const SmallVectorImpl<ISD::InputArg> &Ins, 1185 const SDLoc &dl, SelectionDAG &DAG, 1186 SmallVectorImpl<SDValue> &InVals) const override; 1187 1188 SDValue LowerCall(TargetLowering::CallLoweringInfo &CLI, 1189 SmallVectorImpl<SDValue> &InVals) const override; 1190 1191 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, 1192 bool isVarArg, 1193 const SmallVectorImpl<ISD::OutputArg> &Outs, 1194 LLVMContext &Context) const override; 1195 1196 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 1197 const SmallVectorImpl<ISD::OutputArg> &Outs, 1198 const SmallVectorImpl<SDValue> &OutVals, 1199 const SDLoc &dl, SelectionDAG &DAG) const override; 1200 1201 SDValue extendArgForPPC64(ISD::ArgFlagsTy Flags, EVT ObjectVT, 1202 SelectionDAG &DAG, SDValue ArgVal, 1203 const SDLoc &dl) const; 1204 1205 SDValue LowerFormalArguments_AIX( 1206 SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 1207 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, 1208 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const; 1209 SDValue LowerFormalArguments_Darwin( 1210 SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 1211 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, 1212 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const; 1213 SDValue LowerFormalArguments_64SVR4( 1214 SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 1215 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, 1216 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const; 1217 SDValue LowerFormalArguments_32SVR4( 1218 SDValue Chain, CallingConv::ID CallConv, bool isVarArg, 1219 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, 1220 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const; 1221 1222 SDValue createMemcpyOutsideCallSeq(SDValue Arg, SDValue PtrOff, 1223 SDValue CallSeqStart, 1224 ISD::ArgFlagsTy Flags, SelectionDAG &DAG, 1225 const SDLoc &dl) const; 1226 1227 SDValue LowerCall_Darwin(SDValue Chain, SDValue Callee, CallFlags CFlags, 1228 const SmallVectorImpl<ISD::OutputArg> &Outs, 1229 const SmallVectorImpl<SDValue> &OutVals, 1230 const SmallVectorImpl<ISD::InputArg> &Ins, 1231 const SDLoc &dl, SelectionDAG &DAG, 1232 SmallVectorImpl<SDValue> &InVals, 1233 const CallBase *CB) const; 1234 SDValue LowerCall_64SVR4(SDValue Chain, SDValue Callee, CallFlags CFlags, 1235 const SmallVectorImpl<ISD::OutputArg> &Outs, 1236 const SmallVectorImpl<SDValue> &OutVals, 1237 const SmallVectorImpl<ISD::InputArg> &Ins, 1238 const SDLoc &dl, SelectionDAG &DAG, 1239 SmallVectorImpl<SDValue> &InVals, 1240 const CallBase *CB) const; 1241 SDValue LowerCall_32SVR4(SDValue Chain, SDValue Callee, CallFlags CFlags, 1242 const SmallVectorImpl<ISD::OutputArg> &Outs, 1243 const SmallVectorImpl<SDValue> &OutVals, 1244 const SmallVectorImpl<ISD::InputArg> &Ins, 1245 const SDLoc &dl, SelectionDAG &DAG, 1246 SmallVectorImpl<SDValue> &InVals, 1247 const CallBase *CB) const; 1248 SDValue LowerCall_AIX(SDValue Chain, SDValue Callee, CallFlags CFlags, 1249 const SmallVectorImpl<ISD::OutputArg> &Outs, 1250 const SmallVectorImpl<SDValue> &OutVals, 1251 const SmallVectorImpl<ISD::InputArg> &Ins, 1252 const SDLoc &dl, SelectionDAG &DAG, 1253 SmallVectorImpl<SDValue> &InVals, 1254 const CallBase *CB) const; 1255 1256 SDValue lowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const; 1257 SDValue lowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const; 1258 SDValue LowerBITCAST(SDValue Op, SelectionDAG &DAG) const; 1259 1260 SDValue DAGCombineExtBoolTrunc(SDNode *N, DAGCombinerInfo &DCI) const; 1261 SDValue DAGCombineBuildVector(SDNode *N, DAGCombinerInfo &DCI) const; 1262 SDValue DAGCombineTruncBoolExt(SDNode *N, DAGCombinerInfo &DCI) const; 1263 SDValue combineStoreFPToInt(SDNode *N, DAGCombinerInfo &DCI) const; 1264 SDValue combineFPToIntToFP(SDNode *N, DAGCombinerInfo &DCI) const; 1265 SDValue combineSHL(SDNode *N, DAGCombinerInfo &DCI) const; 1266 SDValue combineSRA(SDNode *N, DAGCombinerInfo &DCI) const; 1267 SDValue combineSRL(SDNode *N, DAGCombinerInfo &DCI) const; 1268 SDValue combineMUL(SDNode *N, DAGCombinerInfo &DCI) const; 1269 SDValue combineADD(SDNode *N, DAGCombinerInfo &DCI) const; 1270 SDValue combineFMALike(SDNode *N, DAGCombinerInfo &DCI) const; 1271 SDValue combineTRUNCATE(SDNode *N, DAGCombinerInfo &DCI) const; 1272 SDValue combineSetCC(SDNode *N, DAGCombinerInfo &DCI) const; 1273 SDValue combineABS(SDNode *N, DAGCombinerInfo &DCI) const; 1274 SDValue combineVSelect(SDNode *N, DAGCombinerInfo &DCI) const; 1275 SDValue combineVectorShuffle(ShuffleVectorSDNode *SVN, 1276 SelectionDAG &DAG) const; 1277 SDValue combineVReverseMemOP(ShuffleVectorSDNode *SVN, LSBaseSDNode *LSBase, 1278 DAGCombinerInfo &DCI) const; 1279 1280 /// ConvertSETCCToSubtract - looks at SETCC that compares ints. It replaces 1281 /// SETCC with integer subtraction when (1) there is a legal way of doing it 1282 /// (2) keeping the result of comparison in GPR has performance benefit. 1283 SDValue ConvertSETCCToSubtract(SDNode *N, DAGCombinerInfo &DCI) const; 1284 1285 SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, 1286 int &RefinementSteps, bool &UseOneConstNR, 1287 bool Reciprocal) const override; 1288 SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, 1289 int &RefinementSteps) const override; 1290 unsigned combineRepeatedFPDivisors() const override; 1291 1292 SDValue 1293 combineElementTruncationToVectorTruncation(SDNode *N, 1294 DAGCombinerInfo &DCI) const; 1295 1296 /// lowerToVINSERTH - Return the SDValue if this VECTOR_SHUFFLE can be 1297 /// handled by the VINSERTH instruction introduced in ISA 3.0. This is 1298 /// essentially any shuffle of v8i16 vectors that just inserts one element 1299 /// from one vector into the other. 1300 SDValue lowerToVINSERTH(ShuffleVectorSDNode *N, SelectionDAG &DAG) const; 1301 1302 /// lowerToVINSERTB - Return the SDValue if this VECTOR_SHUFFLE can be 1303 /// handled by the VINSERTB instruction introduced in ISA 3.0. This is 1304 /// essentially v16i8 vector version of VINSERTH. 1305 SDValue lowerToVINSERTB(ShuffleVectorSDNode *N, SelectionDAG &DAG) const; 1306 1307 /// lowerToXXSPLTI32DX - Return the SDValue if this VECTOR_SHUFFLE can be 1308 /// handled by the XXSPLTI32DX instruction introduced in ISA 3.1. 1309 SDValue lowerToXXSPLTI32DX(ShuffleVectorSDNode *N, SelectionDAG &DAG) const; 1310 1311 // Return whether the call instruction can potentially be optimized to a 1312 // tail call. This will cause the optimizers to attempt to move, or 1313 // duplicate return instructions to help enable tail call optimizations. 1314 bool mayBeEmittedAsTailCall(const CallInst *CI) const override; 1315 bool hasBitPreservingFPLogic(EVT VT) const override; 1316 bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override; 1317 }; // end class PPCTargetLowering 1318 1319 namespace PPC { 1320 1321 FastISel *createFastISel(FunctionLoweringInfo &FuncInfo, 1322 const TargetLibraryInfo *LibInfo); 1323 1324 } // end namespace PPC 1325 1326 bool isIntS16Immediate(SDNode *N, int16_t &Imm); 1327 bool isIntS16Immediate(SDValue Op, int16_t &Imm); 1328 1329 bool convertToNonDenormSingle(APInt &ArgAPInt); 1330 bool convertToNonDenormSingle(APFloat &ArgAPFloat); 1331 1332 } // end namespace llvm 1333 1334 #endif // LLVM_TARGET_POWERPC_PPC32ISELLOWERING_H 1335