77 ~AMDGPUDAGToDAGISel()
override =
default;
82 void PostprocessISelDAG()
override;
85 std::pair<SDValue, SDValue> foldFrameIndex(
SDValue N)
const;
87 bool isInlineImmediate(
const SDNode *
N)
const;
90 bool FoldOperands(
unsigned,
const R600InstrInfo *, std::vector<SDValue> &);
91 bool FoldDotOperands(
unsigned,
const R600InstrInfo *, std::vector<SDValue> &);
93 bool isConstantLoad(
const MemSDNode *
N,
int cbID)
const;
94 bool isUniformBr(
const SDNode *
N)
const;
99 bool SelectGlobalValueConstantOffset(
SDValue Addr,
SDValue& IntPtr);
100 bool SelectGlobalValueVariableOffset(
SDValue Addr,
SDValue &BaseReg,
105 unsigned OffsetBits)
const;
119 bool SelectMUBUFScratchOffen(
SDNode *Root,
122 bool SelectMUBUFScratchOffset(
SDNode *Root,
177 void SelectADD_SUB_I64(
SDNode *
N);
178 void SelectUADDO_USUBO(
SDNode *
N);
179 void SelectDIV_SCALE(
SDNode *
N);
180 void SelectFMA_W_CHAIN(
SDNode *
N);
181 void SelectFMUL_W_CHAIN(
SDNode *
N);
185 void SelectS_BFEFromShifts(
SDNode *
N);
187 bool isCBranchSCC(
const SDNode *
N)
const;
189 void SelectATOMIC_CMP_SWAP(
SDNode *
N);
192 #include "AMDGPUGenDAGISel.inc"
201 return new AMDGPUDAGToDAGISel(TM, OptLevel);
209 bool AMDGPUDAGToDAGISel::isNoNanSrc(
SDValue N)
const {
210 if (
TM.Options.NoNaNsFPMath)
217 return CurDAG->isKnownNeverNaN(N);
220 bool AMDGPUDAGToDAGISel::isInlineImmediate(
const SDNode *N)
const {
222 =
static_cast<const SISubtarget *
>(Subtarget)->getInstrInfo();
238 unsigned OpNo)
const {
248 =
static_cast<const SISubtarget *
>(Subtarget)->getRegisterInfo();
266 return Subtarget->getRegisterInfo()->getRegClass(RegClass);
268 case AMDGPU::REG_SEQUENCE: {
269 unsigned RCID = cast<ConstantSDNode>(N->
getOperand(0))->getZExtValue();
271 Subtarget->getRegisterInfo()->getRegClass(RCID);
274 unsigned SubRegIdx = cast<ConstantSDNode>(SubRegOp)->getZExtValue();
275 return Subtarget->getRegisterInfo()->getSubClassWithSubReg(SuperRC,
281 SDNode *AMDGPUDAGToDAGISel::glueCopyToM0(
SDNode *N)
const {
283 cast<MemSDNode>(
N)->getAddressSpace() != AMDGPUASI.LOCAL_ADDRESS)
307 switch (NumVectorElts) {
309 return AMDGPU::SReg_32_XM0RegClassID;
311 return AMDGPU::SReg_64RegClassID;
313 return AMDGPU::SReg_128RegClassID;
315 return AMDGPU::SReg_256RegClassID;
317 return AMDGPU::SReg_512RegClassID;
325 Out =
C->getAPIntValue().getZExtValue();
330 Out =
C->getValueAPF().bitcastToAPInt().getZExtValue();
344 if (isa<AtomicSDNode>(N) ||
363 SelectADD_SUB_I64(N);
368 SelectUADDO_USUBO(N);
372 SelectFMUL_W_CHAIN(N);
376 SelectFMA_W_CHAIN(N);
394 uint32_t K = LHSVal | (RHSVal << 16);
395 CurDAG->SelectNodeTo(N, AMDGPU::S_MOV_B32, VT,
413 switch(NumVectorElts) {
414 case 2: RegClassID = AMDGPU::R600_Reg64RegClassID;
break;
417 RegClassID = AMDGPU::R600_Reg128VerticalRegClassID;
419 RegClassID = AMDGPU::R600_Reg128RegClassID;
428 if (NumVectorElts == 1) {
429 CurDAG->SelectNodeTo(N, AMDGPU::COPY_TO_REGCLASS, EltVT, N->
getOperand(0),
434 assert(NumVectorElts <= 16 &&
"Vectors with more than 16 elements not "
441 RegSeqArgs[0] = CurDAG->getTargetConstant(RegClassID,
DL,
MVT::i32);
442 bool IsRegSeq =
true;
444 for (
unsigned i = 0; i < NOps; i++) {
451 RegSeqArgs[1 + (2 * i) + 1] =
456 if (NOps != NumVectorElts) {
460 MachineSDNode *ImpDef = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
462 for (
unsigned i = NOps; i < NumVectorElts; ++i) {
463 RegSeqArgs[1 + (2 * i)] =
SDValue(ImpDef, 0);
464 RegSeqArgs[1 + (2 * i) + 1] =
471 CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, N->
getVTList(), RegSeqArgs);
481 RC = CurDAG->getTargetConstant(AMDGPU::SReg_128RegClassID,
DL,
MVT::i32);
482 SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0_sub1,
DL,
MVT::i32);
483 SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub2_sub3,
DL,
MVT::i32);
485 RC = CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID,
DL,
MVT::i32);
486 SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0,
DL,
MVT::i32);
487 SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub1,
DL,
MVT::i32);
493 ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
DL,
506 Imm = FP->getValueAPF().bitcastToAPInt().getZExtValue();
514 CurDAG->getConstant(Imm & 0xFFFFFFFF,
DL,
517 CurDAG->getConstant(Imm >> 32,
DL,
MVT::i32));
519 CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID,
DL,
MVT::i32),
524 ReplaceNode(N, CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
DL,
560 ReplaceNode(N, getS_BFE(Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32,
589 SelectATOMIC_CMP_SWAP(N);
596 bool AMDGPUDAGToDAGISel::isConstantLoad(
const MemSDNode *N,
int CbId)
const {
605 bool AMDGPUDAGToDAGISel::isUniformBr(
const SDNode *N)
const {
606 const BasicBlock *BB = FuncInfo->MBB->getBasicBlock();
612 StringRef AMDGPUDAGToDAGISel::getPassName()
const {
613 return "AMDGPU DAG->DAG Pattern Instruction Selection";
620 bool AMDGPUDAGToDAGISel::SelectGlobalValueConstantOffset(
SDValue Addr,
623 IntPtr = CurDAG->getIntPtrConstant(Cst->getZExtValue() / 4,
SDLoc(Addr),
630 bool AMDGPUDAGToDAGISel::SelectGlobalValueVariableOffset(
SDValue Addr,
632 if (!isa<ConstantSDNode>(Addr)) {
634 Offset = CurDAG->getIntPtrConstant(0,
SDLoc(Addr),
true);
646 &&
isInt<16>(IMMOffset->getZExtValue())) {
649 Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(),
SDLoc(Addr),
653 }
else if ((IMMOffset = dyn_cast<ConstantSDNode>(Addr))
654 &&
isInt<16>(IMMOffset->getZExtValue())) {
655 Base = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
656 SDLoc(CurDAG->getEntryNode()),
658 Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(),
SDLoc(Addr),
665 Offset = CurDAG->getTargetConstant(0,
SDLoc(Addr),
MVT::i32);
669 bool AMDGPUDAGToDAGISel::SelectADDRIndirect(
SDValue Addr,
SDValue &Base,
674 if ((C = dyn_cast<ConstantSDNode>(Addr))) {
675 Base = CurDAG->getRegister(AMDGPU::INDIRECT_BASE_ADDR,
MVT::i32);
678 (C = dyn_cast<ConstantSDNode>(Addr.
getOperand(0)))) {
679 Base = CurDAG->getRegister(AMDGPU::INDIRECT_BASE_ADDR,
MVT::i32);
682 (C = dyn_cast<ConstantSDNode>(Addr.
getOperand(1)))) {
687 Offset = CurDAG->getTargetConstant(0,
DL,
MVT::i32);
693 void AMDGPUDAGToDAGISel::SelectADD_SUB_I64(
SDNode *N) {
708 SDNode *Lo0 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
710 SDNode *Hi0 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
713 SDNode *Lo1 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
715 SDNode *Hi1 = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
720 unsigned Opc = IsAdd ? AMDGPU::S_ADD_U32 : AMDGPU::S_SUB_U32;
721 unsigned CarryOpc = IsAdd ? AMDGPU::S_ADDC_U32 : AMDGPU::S_SUBB_U32;
726 AddLo = CurDAG->getMachineNode(Opc,
DL, VTList, Args);
729 AddLo = CurDAG->getMachineNode(CarryOpc,
DL, VTList, Args);
736 SDNode *AddHi = CurDAG->getMachineNode(CarryOpc,
DL, VTList, AddHiArgs);
739 CurDAG->getTargetConstant(AMDGPU::SReg_64RegClassID,
DL,
MVT::i32),
750 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 1),
SDValue(AddHi, 1));
754 CurDAG->ReplaceAllUsesWith(N, RegSequence);
755 CurDAG->RemoveDeadNode(N);
758 void AMDGPUDAGToDAGISel::SelectUADDO_USUBO(
SDNode *N) {
763 AMDGPU::V_ADD_I32_e64 : AMDGPU::V_SUB_I32_e64;
765 CurDAG->SelectNodeTo(N, Opc, N->
getVTList(),
769 void AMDGPUDAGToDAGISel::SelectFMA_W_CHAIN(
SDNode *N) {
774 SelectVOP3Mods0(N->
getOperand(1), Ops[1], Ops[0], Ops[6], Ops[7]);
775 SelectVOP3Mods(N->
getOperand(2), Ops[3], Ops[2]);
776 SelectVOP3Mods(N->
getOperand(3), Ops[5], Ops[4]);
780 CurDAG->SelectNodeTo(N, AMDGPU::V_FMA_F32, N->
getVTList(), Ops);
783 void AMDGPUDAGToDAGISel::SelectFMUL_W_CHAIN(
SDNode *N) {
788 SelectVOP3Mods0(N->
getOperand(1), Ops[1], Ops[0], Ops[4], Ops[5]);
789 SelectVOP3Mods(N->
getOperand(2), Ops[3], Ops[2]);
793 CurDAG->SelectNodeTo(N, AMDGPU::V_MUL_F32_e64, N->
getVTList(), Ops);
798 void AMDGPUDAGToDAGISel::SelectDIV_SCALE(
SDNode *N) {
805 = (VT ==
MVT::f64) ? AMDGPU::V_DIV_SCALE_F64 : AMDGPU::V_DIV_SCALE_F32;
808 CurDAG->SelectNodeTo(N, Opc, N->
getVTList(), Ops);
811 bool AMDGPUDAGToDAGISel::isDSOffsetLegal(
const SDValue &Base,
unsigned Offset,
812 unsigned OffsetBits)
const {
813 if ((OffsetBits == 16 && !
isUInt<16>(Offset)) ||
818 Subtarget->unsafeDSOffsetFoldingEnabled())
823 return CurDAG->SignBitIsZero(Base);
826 bool AMDGPUDAGToDAGISel::SelectDS1Addr1Offset(
SDValue Addr,
SDValue &Base,
829 if (CurDAG->isBaseWithConstantOffset(Addr)) {
852 if (isDSOffsetLegal(Sub, ByteOffset, 16)) {
854 = CurDAG->getMachineNode(AMDGPU::V_SUB_I32_e32,
DL,
MVT::i32,
858 Offset = CurDAG->getTargetConstant(ByteOffset,
DL,
MVT::i16);
863 }
else if (
const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
873 MachineSDNode *MovZero = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
876 Offset = CurDAG->getTargetConstant(CAddr->getZExtValue(),
DL,
MVT::i16);
883 Offset = CurDAG->getTargetConstant(0,
SDLoc(Addr),
MVT::i16);
888 bool AMDGPUDAGToDAGISel::SelectDS64Bit4ByteAligned(
SDValue Addr,
SDValue &Base,
893 if (CurDAG->isBaseWithConstantOffset(Addr)) {
898 unsigned DWordOffset1 = DWordOffset0 + 1;
900 if (isDSOffsetLegal(N0, DWordOffset1, 8)) {
902 Offset0 = CurDAG->getTargetConstant(DWordOffset0,
DL,
MVT::i8);
903 Offset1 = CurDAG->getTargetConstant(DWordOffset1,
DL,
MVT::i8);
910 unsigned DWordOffset1 = DWordOffset0 + 1;
922 if (isDSOffsetLegal(Sub, DWordOffset1, 8)) {
924 = CurDAG->getMachineNode(AMDGPU::V_SUB_I32_e32,
DL,
MVT::i32,
928 Offset0 = CurDAG->getTargetConstant(DWordOffset0,
DL,
MVT::i8);
929 Offset1 = CurDAG->getTargetConstant(DWordOffset1,
DL,
MVT::i8);
934 }
else if (
const ConstantSDNode *CAddr = dyn_cast<ConstantSDNode>(Addr)) {
935 unsigned DWordOffset0 = CAddr->getZExtValue() / 4;
936 unsigned DWordOffset1 = DWordOffset0 + 1;
937 assert(4 * DWordOffset0 == CAddr->getZExtValue());
942 = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
945 Offset0 = CurDAG->getTargetConstant(DWordOffset0,
DL,
MVT::i8);
946 Offset1 = CurDAG->getTargetConstant(DWordOffset1,
DL,
MVT::i8);
956 Offset0 = CurDAG->getTargetConstant(0,
DL,
MVT::i8);
957 Offset1 = CurDAG->getTargetConstant(1,
DL,
MVT::i8);
962 return isUInt<12>(Imm);
976 if (Subtarget->useFlatForGlobal())
982 GLC = CurDAG->getTargetConstant(0,
DL,
MVT::i1);
984 SLC = CurDAG->getTargetConstant(0,
DL,
MVT::i1);
985 TFE = CurDAG->getTargetConstant(0,
DL,
MVT::i1);
987 Idxen = CurDAG->getTargetConstant(0,
DL,
MVT::i1);
988 Offen = CurDAG->getTargetConstant(0,
DL,
MVT::i1);
989 Addr64 = CurDAG->getTargetConstant(0,
DL,
MVT::i1);
990 SOffset = CurDAG->getTargetConstant(0,
DL,
MVT::i32);
992 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1001 Addr64 = CurDAG->getTargetConstant(1,
DL,
MVT::i1);
1006 VAddr = CurDAG->getTargetConstant(0,
DL,
MVT::i32);
1017 Offset = CurDAG->getTargetConstant(0,
DL,
MVT::i16);
1029 Addr64 = CurDAG->getTargetConstant(1,
DL,
MVT::i1);
1032 Offset = CurDAG->getTargetConstant(0,
DL,
MVT::i16);
1037 VAddr = CurDAG->getTargetConstant(0,
DL,
MVT::i32);
1039 Offset = CurDAG->getTargetConstant(0,
DL,
MVT::i16);
1044 bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(
SDValue Addr,
SDValue &SRsrc,
1054 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
1072 bool AMDGPUDAGToDAGISel::SelectMUBUFAddr64(
SDValue Addr,
SDValue &SRsrc,
1076 SLC = CurDAG->getTargetConstant(0,
SDLoc(Addr),
MVT::i1);
1079 return SelectMUBUFAddr64(Addr, SRsrc, VAddr, SOffset, Offset, GLC, SLC, TFE);
1087 std::pair<SDValue, SDValue> AMDGPUDAGToDAGISel::foldFrameIndex(
SDValue N)
const {
1091 if (
auto FI = dyn_cast<FrameIndexSDNode>(N)) {
1092 SDValue TFI = CurDAG->getTargetFrameIndex(FI->getIndex(),
1093 FI->getValueType(0));
1107 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(
SDNode *Root,
1119 unsigned Imm = CAddr->getZExtValue();
1121 "should have been selected by other pattern");
1124 MachineSDNode *MovHighBits = CurDAG->getMachineNode(AMDGPU::V_MOV_B32_e32,
1126 VAddr =
SDValue(MovHighBits, 0);
1134 SOffset = CurDAG->getRegister(SOffsetReg,
MVT::i32);
1135 ImmOffset = CurDAG->getTargetConstant(Imm & 4095,
DL,
MVT::i16);
1139 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1148 std::tie(VAddr, SOffset) = foldFrameIndex(N0);
1155 std::tie(VAddr, SOffset) = foldFrameIndex(Addr);
1156 ImmOffset = CurDAG->getTargetConstant(0,
DL,
MVT::i16);
1160 bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffset(
SDNode *Root,
1181 SOffset = CurDAG->getRegister(SOffsetReg,
MVT::i32);
1187 bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1193 static_cast<const SIInstrInfo *
>(Subtarget->getInstrInfo());
1195 if (!SelectMUBUF(Addr, Ptr, VAddr, SOffset, Offset, Offen, Idxen, Addr64,
1199 if (!cast<ConstantSDNode>(Offen)->getSExtValue() &&
1200 !cast<ConstantSDNode>(Idxen)->getSExtValue() &&
1201 !cast<ConstantSDNode>(Addr64)->getSExtValue()) {
1215 bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1220 return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE);
1222 bool AMDGPUDAGToDAGISel::SelectMUBUFOffset(
SDValue Addr,
SDValue &SRsrc,
1227 return SelectMUBUFOffset(Addr, SRsrc, Soffset, Offset, GLC, SLC, TFE);
1234 uint32_t Imm = cast<ConstantSDNode>(Constant)->getZExtValue();
1238 if (Imm <= 4095 + 64) {
1240 Overflow = Imm - 4095;
1251 Overflow = High - 1;
1262 ImmOffset = CurDAG->getTargetConstant(Imm,
DL,
MVT::i16);
1265 SOffset = CurDAG->getTargetConstant(Overflow,
DL,
MVT::i32);
1268 CurDAG->getTargetConstant(Overflow,
DL,
MVT::i32)),
1274 bool AMDGPUDAGToDAGISel::SelectMUBUFIntrinsicOffset(
SDValue Offset,
1279 if (!isa<ConstantSDNode>(Offset))
1282 return SelectMUBUFConstant(Offset, SOffset, ImmOffset);
1285 bool AMDGPUDAGToDAGISel::SelectMUBUFIntrinsicVOffset(
SDValue Offset,
1292 if (isa<ConstantSDNode>(Offset)) {
1298 SelectMUBUFConstant(Offset, Tmp1, Tmp2))
1302 if (CurDAG->isBaseWithConstantOffset(Offset)) {
1305 if (cast<ConstantSDNode>(N1)->getSExtValue() >= 0 &&
1306 SelectMUBUFConstant(N1, SOffset, ImmOffset)) {
1312 SOffset = CurDAG->getTargetConstant(0,
DL,
MVT::i32);
1313 ImmOffset = CurDAG->getTargetConstant(0,
DL,
MVT::i16);
1319 bool AMDGPUDAGToDAGISel::SelectFlatOffset(
SDValue Addr,
1323 int64_t OffsetVal = 0;
1325 if (Subtarget->hasFlatInstOffsets() &&
1326 CurDAG->isBaseWithConstantOffset(Addr)) {
1329 uint64_t COffsetVal = cast<ConstantSDNode>(N1)->getZExtValue();
1330 if (isUInt<12>(COffsetVal)) {
1332 OffsetVal = COffsetVal;
1337 Offset = CurDAG->getTargetConstant(OffsetVal,
SDLoc(),
MVT::i16);
1343 bool AMDGPUDAGToDAGISel::SelectFlatAtomic(
SDValue Addr,
1347 return SelectFlatOffset(Addr, VAddr, Offset, SLC);
1350 bool AMDGPUDAGToDAGISel::SelectSMRDOffset(
SDValue ByteOffsetNode,
1351 SDValue &Offset,
bool &Imm)
const {
1358 SDLoc SL(ByteOffsetNode);
1364 Offset = CurDAG->getTargetConstant(EncodedOffset, SL,
MVT::i32);
1374 Offset = CurDAG->getTargetConstant(EncodedOffset, SL,
MVT::i32);
1377 Offset =
SDValue(CurDAG->getMachineNode(AMDGPU::S_MOV_B32, SL,
MVT::i32,
1384 bool AMDGPUDAGToDAGISel::SelectSMRD(
SDValue Addr,
SDValue &SBase,
1385 SDValue &Offset,
bool &Imm)
const {
1387 if (CurDAG->isBaseWithConstantOffset(Addr)) {
1391 if (SelectSMRDOffset(N1, Offset, Imm)) {
1397 Offset = CurDAG->getTargetConstant(0, SL,
MVT::i32);
1402 bool AMDGPUDAGToDAGISel::SelectSMRDImm(
SDValue Addr,
SDValue &SBase,
1405 return SelectSMRD(Addr, SBase, Offset, Imm) && Imm;
1408 bool AMDGPUDAGToDAGISel::SelectSMRDImm32(
SDValue Addr,
SDValue &SBase,
1415 if (!SelectSMRD(Addr, SBase, Offset, Imm))
1418 return !Imm && isa<ConstantSDNode>(
Offset);
1421 bool AMDGPUDAGToDAGISel::SelectSMRDSgpr(
SDValue Addr,
SDValue &SBase,
1424 return SelectSMRD(Addr, SBase, Offset, Imm) && !Imm &&
1425 !isa<ConstantSDNode>(
Offset);
1428 bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm(
SDValue Addr,
1431 return SelectSMRDOffset(Addr, Offset, Imm) && Imm;
1434 bool AMDGPUDAGToDAGISel::SelectSMRDBufferImm32(
SDValue Addr,
1440 if (!SelectSMRDOffset(Addr, Offset, Imm))
1443 return !Imm && isa<ConstantSDNode>(
Offset);
1446 bool AMDGPUDAGToDAGISel::SelectSMRDBufferSgpr(
SDValue Addr,
1449 return SelectSMRDOffset(Addr, Offset, Imm) && !Imm &&
1450 !isa<ConstantSDNode>(
Offset);
1453 bool AMDGPUDAGToDAGISel::SelectMOVRELOffset(
SDValue Index,
1458 if (CurDAG->isBaseWithConstantOffset(Index)) {
1469 if (isa<ConstantSDNode>(Index))
1473 Offset = CurDAG->getTargetConstant(0,
DL,
MVT::i32);
1477 SDNode *AMDGPUDAGToDAGISel::getS_BFE(
unsigned Opcode,
const SDLoc &
DL,
1483 uint32_t PackedVal = Offset | (Width << 16);
1484 SDValue PackedConst = CurDAG->getTargetConstant(PackedVal, DL,
MVT::i32);
1486 return CurDAG->getMachineNode(Opcode, DL,
MVT::i32, Val, PackedConst);
1489 void AMDGPUDAGToDAGISel::SelectS_BFEFromShifts(
SDNode *N) {
1502 if (0 < BVal && BVal <= CVal && CVal < 32) {
1504 unsigned Opcode = Signed ? AMDGPU::S_BFE_I32 : AMDGPU::S_BFE_U32;
1506 ReplaceNode(N, getS_BFE(Opcode,
SDLoc(N), Shl.
getOperand(0), CVal - BVal,
1514 void AMDGPUDAGToDAGISel::SelectS_BFE(
SDNode *N) {
1524 if (Shift && Mask) {
1526 uint32_t MaskVal = Mask->getZExtValue();
1531 ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_U32,
SDLoc(N),
1546 if (Shift && Mask) {
1548 uint32_t MaskVal = Mask->getZExtValue() >> ShiftVal;
1553 ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_U32,
SDLoc(N),
1559 SelectS_BFEFromShifts(N);
1565 SelectS_BFEFromShifts(N);
1580 unsigned Width = cast<VTSDNode>(N->
getOperand(1))->getVT().getSizeInBits();
1581 ReplaceNode(N, getS_BFE(AMDGPU::S_BFE_I32,
SDLoc(N), Src.
getOperand(0),
1590 bool AMDGPUDAGToDAGISel::isCBranchSCC(
const SDNode *N)
const {
1616 void AMDGPUDAGToDAGISel::SelectBRCOND(
SDNode *N) {
1620 CurDAG->SelectNodeTo(N, AMDGPU::SI_BR_UNDEF,
MVT::Other,
1625 if (isCBranchSCC(N)) {
1634 CurDAG->SelectNodeTo(N, AMDGPU::S_CBRANCH_VCCNZ,
MVT::Other,
1641 void AMDGPUDAGToDAGISel::SelectATOMIC_CMP_SWAP(
SDNode *N) {
1644 if (AS == AMDGPUASI.FLAT_ADDRESS) {
1654 if (Subtarget->hasAddr64()) {
1657 if (SelectMUBUFAddr64(Mem->
getBasePtr(), SRsrc, VAddr, SOffset,
Offset, SLC)) {
1658 unsigned Opcode = Is32 ? AMDGPU::BUFFER_ATOMIC_CMPSWAP_RTN_ADDR64 :
1659 AMDGPU::BUFFER_ATOMIC_CMPSWAP_X2_RTN_ADDR64;
1668 CmpSwap = CurDAG->getMachineNode(Opcode, SL, Mem->
getVTList(), Ops);
1675 unsigned Opcode = Is32 ? AMDGPU::BUFFER_ATOMIC_CMPSWAP_RTN_OFFSET :
1676 AMDGPU::BUFFER_ATOMIC_CMPSWAP_X2_RTN_OFFSET;
1683 CmpSwap = CurDAG->getMachineNode(Opcode, SL, Mem->
getVTList(), Ops);
1696 unsigned SubReg = Is32 ? AMDGPU::sub0 : AMDGPU::sub0_sub1;
1698 = CurDAG->getTargetExtractSubreg(SubReg, SL, VT,
SDValue(CmpSwap, 0));
1700 ReplaceUses(
SDValue(N, 0), Extract);
1702 CurDAG->RemoveDeadNode(N);
1720 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
1724 bool AMDGPUDAGToDAGISel::SelectVOP3Mods_NNaN(
SDValue In,
SDValue &Src,
1726 SelectVOP3Mods(In, Src, SrcMods);
1727 return isNoNanSrc(Src);
1730 bool AMDGPUDAGToDAGISel::SelectVOP3NoMods(
SDValue In,
SDValue &Src)
const {
1738 bool AMDGPUDAGToDAGISel::SelectVOP3Mods0(
SDValue In,
SDValue &Src,
1742 Clamp = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1743 Omod = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1745 return SelectVOP3Mods(In, Src, SrcMods);
1748 bool AMDGPUDAGToDAGISel::SelectVOP3Mods0Clamp0OMod(
SDValue In,
SDValue &Src,
1752 Clamp = Omod = CurDAG->getTargetConstant(0,
SDLoc(In),
MVT::i32);
1753 return SelectVOP3Mods(In, Src, SrcMods);
1756 bool AMDGPUDAGToDAGISel::SelectVOP3OMods(
SDValue In,
SDValue &Src,
1761 Clamp = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1762 Omod = CurDAG->getTargetConstant(0, DL,
MVT::i1);
1780 if (ShiftAmt->getZExtValue() == 16) {
1802 bool AMDGPUDAGToDAGISel::SelectVOP3PMods(
SDValue In,
SDValue &Src,
1813 unsigned VecMods = Mods;
1837 if (Lo == Hi && !isInlineImmediate(Lo.
getNode())) {
1842 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
1852 SrcMods = CurDAG->getTargetConstant(Mods,
SDLoc(In),
MVT::i32);
1856 bool AMDGPUDAGToDAGISel::SelectVOP3PMods0(
SDValue In,
SDValue &Src,
1862 Clamp = CurDAG->getTargetConstant(0, SL,
MVT::i32);
1864 return SelectVOP3PMods(In, Src, SrcMods);
1867 void AMDGPUDAGToDAGISel::PostprocessISelDAG() {
1870 bool IsModified =
false;
1874 for (
SDNode &Node : CurDAG->allnodes()) {
1880 if (ResNode != &Node) {
1881 ReplaceUses(&Node, ResNode);
1885 CurDAG->RemoveDeadNodes();
1886 }
while (IsModified);
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
constexpr bool isUInt< 32 >(uint64_t x)
void push_back(const T &Elt)
MachineSDNode * wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr) const
static bool isExtractHiElt(SDValue In, SDValue &Out)
Interface definition for SIRegisterInfo.
SDValue getValue(unsigned R) const
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
AMDGPU specific subclass of TargetSubtarget.
uint64_t getZExtValue() const
Get zero extended value.
void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd)
Assign this MachineSDNodes's memory reference descriptor list.
bool hasOneUse() const
Return true if there is exactly one use of this node.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
SDVTList getVTList() const
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Carry-setting nodes for multiple precision addition and subtraction.
Describe properties that are true of each instruction in the target description file.
T dyn_cast() const
Returns the current pointer if it is of the specified pointer type, otherwises returns null...
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
AMDGPUAS getAMDGPUAS(const Module &M)
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
unsigned getScratchWaveOffsetReg() const
unsigned getNumOperands() const
Return the number of values used by this operation.
virtual SDNode * PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const =0
static bool getConstantValue(SDValue N, uint32_t &Out)
constexpr bool isInt< 16 >(int64_t x)
const SDValue & getOperand(unsigned Num) const
void setNodeId(int Id)
Set unique node id.
FunctionPass * createAMDGPUISelDag(TargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a AMDGPU-specific.
constexpr bool isMask_32(uint32_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
unsigned getScratchRSrcReg() const
Returns the physical register reserved for use as the resource descriptor for scratch accesses...
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
OpenCL uses address spaces to differentiate between various memory regions on the hardware...
const HexagonInstrInfo * TII
static bool isLegalMUBUFImmOffset(unsigned Imm)
Shift and rotation operations.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
CopyToReg - This node has three operands: a chain, a register number to set to this value...
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
This file implements a class to represent arbitrary precision integral constant values and operations...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
bool isDefined() const
Returns true if the flags are in a defined state.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
TargetRegisterInfo interface that is implemented by all hw codegen targets.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Simple integer binary arithmetic operators.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
This node is for VLIW targets and it is used to represent a vector that is stored in consecutive regi...
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
SDNode * getNode() const
get the SDNode which holds the desired result
int64_t getSMRDEncodedOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
const SDValue & getBasePtr() const
constexpr bool isUInt< 8 >(uint64_t x)
unsigned const MachineRegisterInfo * MRI
LLVM Basic Block Representation.
const SDValue & getOperand(unsigned i) const
PointerUnion< const Value *, const PseudoSourceValue * > V
This is the IR pointer value for the access, or it is null if unknown.
This is an important base class in LLVM.
const SDNodeFlags getFlags() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
unsigned getSubRegFromChannel(unsigned Channel) const
Carry-using nodes for multiple precision addition and subtraction.
SI DAG Lowering interface definition.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
uint64_t getDefaultRsrcDataFormat() const
bool isLegalSMRDImmOffset(const MCSubtargetInfo &ST, int64_t ByteOffset)
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
This class contains a discriminated union of information about pointers in memory operands...
static unsigned selectSGPRVectorRegClassID(unsigned NumVectorElts)
bool isInlineConstant(const APInt &Imm) const
unsigned countPopulation(T Value)
Count the number of set bits in a value.
Interface definition of the TargetLowering class that is common to all AMD GPUs.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
SDNode * legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const
Legalize target independent instructions (e.g.
BRCOND - Conditional branch.
An SDNode that represents everything that will be needed to construct a MachineInstr.
const SDValue & getChain() const
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
This is an abstract virtual class for memory operations.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
Special value supplied for machine level alias analysis.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
static bool isStackPtrRelative(const MachinePointerInfo &PtrInfo)
int64_t getSExtValue() const
static SDValue stripExtractLoElt(SDValue In)
SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL, SDValue V) const
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
llvm_unreachable("Unknown RegBank!")
Contains the definition of a TargetInstrInfo class that is common to all AMD GPUs.
unsigned getAddressSpace() const
Return the address space for the associated pointer.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
Bitwise operators - logical and, logical or, logical xor.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
constexpr bool isUInt< 16 >(uint64_t x)
EVT getValueType() const
Return the ValueType of the referenced return value.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getFrameOffsetReg() const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const MCOperandInfo * OpInfo
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Primary interface to the complete machine description for the target machine.
unsigned getStackPtrOffsetReg() const
static SDValue stripBitcast(SDValue Val)
StringRef - Represent a constant reference to a string, i.e.
SetCC operator - This evaluates to a true value iff the condition is true.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
MachineSDNode * buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr, uint32_t RsrcDword1, uint64_t RsrcDword2And3) const
Return a resource descriptor with the 'Add TID' bit enabled The TID (Thread ID) is multiplied by the ...
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
allocateMemRefsArray - Allocate an array to hold MachineMemOperand pointers.
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
uint64_t getZExtValue() const
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.