25 #define DEBUG_TYPE "si-fold-operands" 30 struct FoldCandidate {
38 unsigned char UseOpNo;
43 bool Commuted_ =
false,
45 UseMI(MI), OpToFold(
nullptr), ShrinkOpcode(ShrinkOp), UseOpNo(OpNo),
48 if (FoldOp->
isImm()) {
49 ImmToFold = FoldOp->
getImm();
50 }
else if (FoldOp->
isFI()) {
51 FrameIndexToFold = FoldOp->
getIndex();
72 bool isCommuted()
const {
76 bool needsShrink()
const {
77 return ShrinkOpcode != -1;
80 int getShrinkOpcode()
const {
105 std::pair<const MachineOperand *, int> isOMod(
const MachineInstr &MI)
const;
115 StringRef getPassName()
const override {
return "SI Fold Operands"; }
126 "SI Fold Operands",
false,
false)
143 case AMDGPU::V_MAC_F32_e64:
144 case AMDGPU::V_MAC_F16_e64:
145 case AMDGPU::V_FMAC_F32_e64:
146 case AMDGPU::V_FMAC_F16_e64: {
150 if (static_cast<int>(OpNo) == Src2Idx) {
151 bool IsFMA = Opc == AMDGPU::V_FMAC_F32_e64 ||
152 Opc == AMDGPU::V_FMAC_F16_e64;
153 bool IsF32 = Opc == AMDGPU::V_MAC_F32_e64 ||
154 Opc == AMDGPU::V_FMAC_F32_e64;
156 unsigned Opc = IsFMA ?
157 (IsF32 ? AMDGPU::V_FMA_F32 : AMDGPU::V_FMA_F16_gfx9) :
158 (IsF32 ? AMDGPU::V_MAD_F32 : AMDGPU::V_MAD_F16);
175 return OpToFold.
isFI() &&
181 return new SIFoldOperands();
203 ModIdx = AMDGPU::OpName::src0_modifiers;
205 ModIdx = AMDGPU::OpName::src1_modifiers;
207 ModIdx = AMDGPU::OpName::src2_modifiers;
211 unsigned Val = Mod.
getImm();
216 switch (TII.get(Opcode).OpInfo[OpNo].OperandType) {
223 if (!(Fold.ImmToFold & 0xffff)) {
240 if ((Fold.isImm() || Fold.isFI() || Fold.isGlobal()) && Fold.needsShrink()) {
244 LLVM_DEBUG(
dbgs() <<
"Not shrinking " << MI <<
" due to vcc liveness\n");
249 int Op32 = Fold.getShrinkOpcode();
261 if (HaveNonDbgCarryUse) {
275 MI->
setDesc(TII.get(AMDGPU::IMPLICIT_DEF));
277 if (Fold.isCommuted())
278 TII.commuteInstruction(*Inst32,
false);
282 assert(!Fold.needsShrink() &&
"not handled");
289 if (Fold.isGlobal()) {
290 Old.
ChangeToGA(Fold.OpToFold->getGlobal(), Fold.OpToFold->getOffset(),
291 Fold.OpToFold->getTargetFlags());
308 for (
auto Candidate : FoldList) {
309 if (Candidate.UseMI == MI)
320 for (FoldCandidate &Fold : FoldList)
321 if (Fold.UseMI == MI && Fold.UseOpNo == OpNo)
323 LLVM_DEBUG(
dbgs() <<
"Append " << (Commuted ?
"commuted" :
"normal")
324 <<
" operand " << OpNo <<
"\n " << *MI <<
'\n');
325 FoldList.push_back(FoldCandidate(MI, OpNo, FoldOp, Commuted, ShrinkOp));
335 if ((Opc == AMDGPU::V_MAC_F32_e64 || Opc == AMDGPU::V_MAC_F16_e64 ||
336 Opc == AMDGPU::V_FMAC_F32_e64 || Opc == AMDGPU::V_FMAC_F16_e64) &&
338 bool IsFMA = Opc == AMDGPU::V_FMAC_F32_e64 ||
339 Opc == AMDGPU::V_FMAC_F16_e64;
340 bool IsF32 = Opc == AMDGPU::V_MAC_F32_e64 ||
341 Opc == AMDGPU::V_FMAC_F32_e64;
342 unsigned NewOpc = IsFMA ?
343 (IsF32 ? AMDGPU::V_FMA_F32 : AMDGPU::V_FMA_F16_gfx9) :
344 (IsF32 ? AMDGPU::V_MAD_F32 : AMDGPU::V_MAD_F16);
358 if (Opc == AMDGPU::S_SETREG_B32 && OpToFold->
isImm()) {
359 MI->
setDesc(TII->get(AMDGPU::S_SETREG_IMM32_B32));
370 unsigned CommuteOpNo = OpNo;
379 if (CommuteIdx0 == OpNo)
380 CommuteOpNo = CommuteIdx1;
381 else if (CommuteIdx1 == OpNo)
382 CommuteOpNo = CommuteIdx0;
395 !TII->commuteInstruction(*MI,
false, CommuteIdx0, CommuteIdx1))
399 if ((Opc == AMDGPU::V_ADD_I32_e64 ||
400 Opc == AMDGPU::V_SUB_I32_e64 ||
401 Opc == AMDGPU::V_SUBREV_I32_e64) &&
407 unsigned OtherIdx = CommuteOpNo == CommuteIdx0 ? CommuteIdx1 : CommuteIdx0;
409 if (!OtherOp.
isReg() ||
416 unsigned MaybeCommutedOpc = MI->
getOpcode();
423 TII->commuteInstruction(*MI,
false, CommuteIdx0, CommuteIdx1);
439 if (OpToFold->
isImm()) {
524 if (!OpToFold.
isReg())
532 return FC.UseMI ==
UseMI; }) != FoldList.
end())
541 for (
unsigned I = 0,
E = Defs.
size();
I !=
E; ++
I) {
546 auto SubImm = Op->
getImm();
563 void SIFoldOperands::foldOperand(
589 RSUse =
MRI->use_begin(RegSeqDstReg), RSE =
MRI->use_end();
590 RSUse != RSE; RSUse = Next) {
591 Next = std::next(RSUse);
599 if (RSUse->getSubReg() != RegSeqDstSubReg)
602 foldOperand(OpToFold, RSUseMI, RSUse.
getOperandNo(), FoldList,
616 if (!SOff->
isReg() || (SOff->
getReg() != MFI->getScratchWaveOffsetReg() &&
617 SOff->
getReg() != MFI->getStackPtrOffsetReg()))
620 if (
TII->getNamedOperand(*UseMI, AMDGPU::OpName::srsrc)->getReg() !=
621 MFI->getScratchRSrcReg())
627 SOff->
setReg(MFI->getStackPtrOffsetReg());
631 bool FoldingImmLike =
634 if (FoldingImmLike && UseMI->
isCopy()) {
648 if (
TRI->isSGPRClass(SrcRC) &&
TRI->hasVectorRegisters(DestRC)) {
652 Use =
MRI->use_begin(DestReg),
E =
MRI->use_end();
654 NextUse = std::next(
Use);
655 FoldCandidate
FC = FoldCandidate(
Use->getParent(),
659 for (
auto &
F : CopyUses) {
660 foldOperand(*
F.OpToFold,
F.UseMI,
F.UseOpNo,
661 FoldList, CopiesToReplace);
666 if (DestRC == &AMDGPU::AGPR_32RegClass &&
668 UseMI->
setDesc(
TII->get(AMDGPU::V_ACCVGPR_WRITE_B32));
677 unsigned MovOp =
TII->getMovOpcode(DestRC);
678 if (MovOp == AMDGPU::COPY)
684 while (ImpOpI != ImpOpE) {
695 <<
"\n into " << *UseMI <<
'\n');
696 unsigned Size =
TII->getOpSize(*UseMI, 1);
715 UseMI->
setDesc(
TII->get(AMDGPU::REG_SEQUENCE));
722 for (
unsigned I = 0;
I < Size / 4; ++
I) {
727 int64_t Imm = Def->
getImm();
729 auto Tmp =
MRI->createVirtualRegister(&AMDGPU::AGPR_32RegClass);
731 TII->get(AMDGPU::V_ACCVGPR_WRITE_B32), Tmp).addImm(Imm);
736 if (!SeenAGPRs.
insert(Src)) {
753 if (
TRI->isSGPRReg(*
MRI, Src.Reg)) {
756 auto Tmp =
MRI->createVirtualRegister(&AMDGPU::AGPR_32RegClass);
757 BuildMI(MBB, UseMI, DL,
TII->get(AMDGPU::COPY), Tmp).
add(*Def);
762 if (CopyToVGPR.
Reg) {
764 if (VGPRCopies.count(CopyToVGPR)) {
765 Vgpr = VGPRCopies[CopyToVGPR];
767 Vgpr =
MRI->createVirtualRegister(&AMDGPU::VGPR_32RegClass);
768 BuildMI(MBB, UseMI, DL,
TII->get(AMDGPU::COPY), Vgpr).
add(*Def);
769 VGPRCopies[CopyToVGPR] = Vgpr;
771 auto Tmp =
MRI->createVirtualRegister(&AMDGPU::AGPR_32RegClass);
773 TII->get(AMDGPU::V_ACCVGPR_WRITE_B32), Tmp).addReg(Vgpr);
787 UseMI->
setDesc(
TII->get(AMDGPU::V_ACCVGPR_WRITE_B32));
790 UseMI->
setDesc(
TII->get(AMDGPU::V_ACCVGPR_READ_B32));
795 if (UseOpc == AMDGPU::V_READFIRSTLANE_B32 ||
796 (UseOpc == AMDGPU::V_READLANE_B32 &&
803 if (FoldingImmLike) {
814 if (OpToFold.
isImm())
852 if (!FoldingImmLike) {
879 Imm = Imm.getHiBits(32);
895 case AMDGPU::V_AND_B32_e64:
896 case AMDGPU::V_AND_B32_e32:
897 case AMDGPU::S_AND_B32:
900 case AMDGPU::V_OR_B32_e64:
901 case AMDGPU::V_OR_B32_e32:
902 case AMDGPU::S_OR_B32:
905 case AMDGPU::V_XOR_B32_e64:
906 case AMDGPU::V_XOR_B32_e32:
907 case AMDGPU::S_XOR_B32:
910 case AMDGPU::V_LSHL_B32_e64:
911 case AMDGPU::V_LSHL_B32_e32:
912 case AMDGPU::S_LSHL_B32:
914 Result = LHS << (RHS & 31);
916 case AMDGPU::V_LSHLREV_B32_e64:
917 case AMDGPU::V_LSHLREV_B32_e32:
918 Result = RHS << (LHS & 31);
920 case AMDGPU::V_LSHR_B32_e64:
921 case AMDGPU::V_LSHR_B32_e32:
922 case AMDGPU::S_LSHR_B32:
923 Result = LHS >> (RHS & 31);
925 case AMDGPU::V_LSHRREV_B32_e64:
926 case AMDGPU::V_LSHRREV_B32_e32:
927 Result = RHS >> (LHS & 31);
929 case AMDGPU::V_ASHR_I32_e64:
930 case AMDGPU::V_ASHR_I32_e32:
931 case AMDGPU::S_ASHR_I32:
932 Result =
static_cast<int32_t
>(LHS) >> (RHS & 31);
934 case AMDGPU::V_ASHRREV_I32_e64:
935 case AMDGPU::V_ASHRREV_I32_e32:
936 Result =
static_cast<int32_t
>(RHS) >> (LHS & 31);
944 return IsScalar ? AMDGPU::S_MOV_B32 : AMDGPU::V_MOV_B32_e32;
969 if (Op.
getSubReg() != AMDGPU::NoSubRegister ||
992 if (Opc == AMDGPU::V_NOT_B32_e64 || Opc == AMDGPU::V_NOT_B32_e32 ||
993 Opc == AMDGPU::S_NOT_B32) {
1007 if (!Src0->
isImm() && !Src1->isImm())
1010 if (MI->
getOpcode() == AMDGPU::V_LSHL_OR_B32) {
1018 MI->
setDesc(TII->get(UseCopy ? AMDGPU::COPY : AMDGPU::V_MOV_B32_e32));
1026 if (Src0->
isImm() && Src1->isImm()) {
1045 if (Src0->
isImm() && !Src1->isImm()) {
1050 int32_t Src1Val =
static_cast<int32_t
>(Src1->getImm());
1051 if (Opc == AMDGPU::V_OR_B32_e64 ||
1052 Opc == AMDGPU::V_OR_B32_e32 ||
1053 Opc == AMDGPU::S_OR_B32) {
1058 }
else if (Src1Val == -1) {
1068 if (MI->
getOpcode() == AMDGPU::V_AND_B32_e64 ||
1069 MI->
getOpcode() == AMDGPU::V_AND_B32_e32 ||
1075 }
else if (Src1Val == -1) {
1086 if (MI->
getOpcode() == AMDGPU::V_XOR_B32_e64 ||
1087 MI->
getOpcode() == AMDGPU::V_XOR_B32_e32 ||
1105 if (Opc == AMDGPU::V_CNDMASK_B32_e32 ||
1106 Opc == AMDGPU::V_CNDMASK_B32_e64 ||
1107 Opc == AMDGPU::V_CNDMASK_B64_PSEUDO) {
1122 if (Src1ModIdx != -1)
1124 if (Src0ModIdx != -1)
1146 unsigned NumLiteralUses = 0;
1148 int NonInlineUseOpNo = -1;
1154 NextUse = std::next(
Use);
1195 foldOperand(OpToFold, UseMI, OpNo, FoldList, CopiesToReplace);
1197 foldOperand(OpToFold, UseMI, OpNo, FoldList,
1200 if (++NumLiteralUses == 1) {
1201 NonInlineUse = &*
Use;
1202 NonInlineUseOpNo = OpNo;
1207 if (NumLiteralUses == 1) {
1209 foldOperand(OpToFold, UseMI, NonInlineUseOpNo, FoldList, CopiesToReplace);
1219 for (
auto U : UsesToProcess) {
1223 FoldList, CopiesToReplace);
1230 Copy->addImplicitDefUseOperands(*MF);
1232 for (FoldCandidate &Fold : FoldList) {
1233 assert(!Fold.isReg() || Fold.OpToFold);
1244 assert(Fold.OpToFold && Fold.OpToFold->isReg());
1248 MRI->clearKillFlags(Fold.OpToFold->getReg());
1250 LLVM_DEBUG(
dbgs() <<
"Folded source from " << MI <<
" into OpNo " 1251 << static_cast<int>(Fold.UseOpNo) <<
" of " 1252 << *Fold.UseMI <<
'\n');
1254 }
else if (Fold.isCommuted()) {
1256 TII->commuteInstruction(*Fold.UseMI,
false);
1266 case AMDGPU::V_MAX_F32_e64:
1267 case AMDGPU::V_MAX_F16_e64:
1268 case AMDGPU::V_MAX_F64:
1269 case AMDGPU::V_PK_MAX_F16: {
1270 if (!
TII->getNamedOperand(MI, AMDGPU::OpName::clamp)->getImm())
1279 Src0->
getSubReg() != AMDGPU::NoSubRegister)
1283 if (
TII->hasModifiersSet(MI, AMDGPU::OpName::omod))
1287 =
TII->getNamedOperand(MI, AMDGPU::OpName::src0_modifiers)->getImm();
1289 =
TII->getNamedOperand(MI, AMDGPU::OpName::src1_modifiers)->getImm();
1295 if (Src0Mods != UnsetMods && Src1Mods != UnsetMods)
1326 if (
TII->getClampMask(*Def) !=
TII->getClampMask(MI))
1333 LLVM_DEBUG(
dbgs() <<
"Folding clamp " << *DefClamp <<
" into " << *Def
1345 case AMDGPU::V_MUL_F32_e64: {
1346 switch (static_cast<uint32_t>(Val)) {
1357 case AMDGPU::V_MUL_F16_e64: {
1358 switch (static_cast<uint16_t>(Val)) {
1377 std::pair<const MachineOperand *, int>
1381 case AMDGPU::V_MUL_F32_e64:
1382 case AMDGPU::V_MUL_F16_e64: {
1384 if ((Op == AMDGPU::V_MUL_F32_e64 && MFI->getMode().FP32Denormals) ||
1385 (Op == AMDGPU::V_MUL_F16_e64 && MFI->getMode().FP64FP16Denormals))
1392 if (Src0->
isImm()) {
1395 }
else if (Src1->
isImm()) {
1403 TII->hasModifiersSet(MI, AMDGPU::OpName::src0_modifiers) ||
1404 TII->hasModifiersSet(MI, AMDGPU::OpName::src1_modifiers) ||
1405 TII->hasModifiersSet(MI, AMDGPU::OpName::omod) ||
1406 TII->hasModifiersSet(MI, AMDGPU::OpName::clamp))
1409 return std::make_pair(RegOp, OMod);
1411 case AMDGPU::V_ADD_F32_e64:
1412 case AMDGPU::V_ADD_F16_e64: {
1414 if ((Op == AMDGPU::V_ADD_F32_e64 && MFI->getMode().FP32Denormals) ||
1415 (Op == AMDGPU::V_ADD_F16_e64 && MFI->getMode().FP64FP16Denormals))
1424 !
TII->hasModifiersSet(MI, AMDGPU::OpName::src0_modifiers) &&
1425 !
TII->hasModifiersSet(MI, AMDGPU::OpName::src1_modifiers) &&
1426 !
TII->hasModifiersSet(MI, AMDGPU::OpName::clamp) &&
1427 !
TII->hasModifiersSet(MI, AMDGPU::OpName::omod))
1441 std::tie(RegOp, OMod) = isOMod(MI);
1443 RegOp->
getSubReg() != AMDGPU::NoSubRegister ||
1454 if (
TII->hasModifiersSet(*Def, AMDGPU::OpName::clamp))
1457 LLVM_DEBUG(
dbgs() <<
"Folding omod " << MI <<
" into " << *Def <<
'\n');
1471 TII =
ST->getInstrInfo();
1480 bool HasNSZ = MFI->hasNoSignedZerosFPMath();
1486 for (I = MBB->begin(); I != MBB->end(); I = Next) {
1487 Next = std::next(I);
1492 if (!TII->isFoldableCopy(MI)) {
1495 CurrentKnownM0Val =
nullptr;
1510 if (CurrentKnownM0Val && CurrentKnownM0Val->
isIdenticalTo(NewM0Val)) {
1517 nullptr : &NewM0Val;
1526 if (!FoldingImm && !OpToFold.
isReg())
1542 foldInstOperand(MI, OpToFold);
static bool isReg(const MCInst &MI, unsigned OpNo)
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool use_nodbg_empty(unsigned RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register...
AMDGPU specific subclass of TargetSubtarget.
unsigned getNumImplicitDefs() const
Return the number of implicit defs this instruct has.
This class represents lattice values for constants.
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, unsigned Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been defined and not killed as of just before Before...
static bool isUseMIInFoldList(ArrayRef< FoldCandidate > FoldList, const MachineInstr *MI)
bool isOperandLegal(const MachineInstr &MI, unsigned OpIdx, const MachineOperand *MO=nullptr) const
Check if MO is a legal operand if it was the OpIdx Operand for MI.
static bool isUseSafeToFold(const SIInstrInfo *TII, const MachineInstr &MI, const MachineOperand &UseMO)
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Describe properties that are true of each instruction in the target description file.
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
void setIsUndef(bool Val=true)
unsigned getSubReg() const
unsigned getRegBitWidth(unsigned RCID)
Get the size in bits of a register from the register class RC.
void substVirtReg(Register Reg, unsigned SubIdx, const TargetRegisterInfo &)
substVirtReg - Substitute the current register with the virtual subregister Reg:SubReg.
bool isRegSequence() const
void ChangeToGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
ChangeToGA - Replace this operand with a new global address operand.
unsigned const TargetRegisterInfo * TRI
bool isInlinableLiteralV216(int32_t Literal, bool HasInv2Pi)
bool isInlineConstant(const APInt &Imm) const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const SIRegisterInfo & getRegisterInfo() const
bool isMoveImmediate(QueryType Type=IgnoreBundle) const
Return true if this instruction is a move immediate (including conditional moves) instruction...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
static unsigned getMovOpc(bool IsScalar)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const HexagonInstrInfo * TII
bool isSGPRReg(const MachineRegisterInfo &MRI, unsigned Reg) const
unsigned getNumOperands() const
Retuns the total number of operands.
static bool hasOneNonDBGUseInst(const MachineRegisterInfo &MRI, unsigned Reg)
A Use represents the edge between a Value definition and its users.
static bool tryAddToFoldList(SmallVectorImpl< FoldCandidate > &FoldList, MachineInstr *MI, unsigned OpNo, MachineOperand *OpToFold, const SIInstrInfo *TII)
bool IEEE
Floating point opcodes that support exception flag gathering quiet and propagate signaling NaN inputs...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
static MachineOperand * getImmOrMaterializedImm(MachineRegisterInfo &MRI, MachineOperand &Op)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned getID() const
Return the register class ID number.
static int getOModValue(unsigned Opc, int64_t Val)
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
uint8_t OperandType
Information about the type of the operand.
bool isVGPR(const MachineRegisterInfo &MRI, unsigned Reg) const
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
bool opCanUseInlineConstant(unsigned OpType) const
bool insert(const value_type &X)
Insert a new element into the SetVector.
static bool isMUBUF(const MachineInstr &MI)
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void untieRegOperand(unsigned OpIdx)
Break any tie involving OpIdx.
bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
void setReg(Register Reg)
Change the register this operand corresponds to.
unsigned getOperandNo() const
Return the operand # of this use in its User.
static bool getRegSeqInit(SmallVectorImpl< std::pair< MachineOperand *, unsigned >> &Defs, Register UseReg, uint8_t OpTy, const SIInstrInfo *TII, const MachineRegisterInfo &MRI)
bool execMayBeModifiedBeforeUse(const MachineRegisterInfo &MRI, Register VReg, const MachineInstr &DefMI, const MachineInstr &UseMI)
Return false if EXEC is not changed between the def of VReg at DefMI and the use at UseMI...
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
static const unsigned CommuteAnyOperandIndex
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
static bool updateOperand(FoldCandidate &Fold, const SIInstrInfo &TII, const TargetRegisterInfo &TRI, const GCNSubtarget &ST)
Address of a global value.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
bool isFoldableCopy(const MachineInstr &MI) const
static void mutateCopyOp(MachineInstr &MI, const MCInstrDesc &NewDesc)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool isVariadic() const
Return true if this instruction can have a variable number of operands.
MachineInstrBuilder & UseMI
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static Register UseReg(const MachineOperand &MO)
AMDGPU::SIModeRegisterDefaults getMode() const
Register is known to be fully dead.
Represent the analysis usage information of a pass.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
void setImm(int64_t immVal)
FunctionPass class - This class is used to implement most global optimizations.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
static bool frameIndexMayFold(const SIInstrInfo *TII, const MachineInstr &UseMI, int OpNo, const MachineOperand &OpToFold)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
void setIsKill(bool Val=true)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool readsRegister(Register Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr reads the specified register.
A SetVector that performs no allocations if smaller than a certain size.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
LLVM_READONLY int getVOPe32(uint16_t Opcode)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
TargetInstrInfo::RegSubRegPair getRegSubRegPair(const MachineOperand &O)
Create RegSubRegPair from a register MachineOperand.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
static bool isSALU(const MachineInstr &MI)
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isLiteralConstantLike(const MachineOperand &MO, const MCOperandInfo &OpInfo) const
A pair composed of a register and a sub-register index.
MachineInstrBuilder MachineInstrBuilder & DefMI
bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
static bool tryFoldInst(const SIInstrInfo *TII, MachineInstr *MI)
static void stripExtraCopyOperands(MachineInstr &MI)
Remove any leftover implicit operands from mutating the instruction.
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The access may modify the value stored in memory.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
iterator_range< mop_iterator > implicit_operands()
static bool evalBinaryInstruction(unsigned Opcode, int32_t &Result, uint32_t LHS, uint32_t RHS)
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Provides AMDGPU specific target descriptions.
Representation of each machine instruction.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
void initializeSIFoldOperandsPass(PassRegistry &)
bool hasInv2PiInlineImm() const
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Interface definition for SIInstrInfo.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
FunctionPass * createSIFoldOperandsPass()
static MachineOperand CreateImm(int64_t Val)
void setSubReg(unsigned subReg)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
static bool isInlineConstantIfFolded(const SIInstrInfo *TII, const MachineInstr &UseMI, unsigned OpNo, const MachineOperand &OpToFold)
Abstract Stack Frame Index.
constexpr bool isUInt< 16 >(uint64_t x)
static void appendFoldCandidate(SmallVectorImpl< FoldCandidate > &FoldList, MachineInstr *MI, unsigned OpNo, MachineOperand *FoldOp, bool Commuted=false, int ShrinkOp=-1)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
iterator_range< df_iterator< T > > depth_first(const T &G)
static use_instr_nodbg_iterator use_instr_nodbg_end()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
use_instr_nodbg_iterator use_instr_nodbg_begin(unsigned RegNo) const
static bool isSDWA(const MachineInstr &MI)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MCOperandInfo * OpInfo
void ChangeToFrameIndex(int Idx)
Replace this operand with a frame index.
bool findCommutedOpIndices(const MachineInstr &MI, unsigned &SrcOpIdx1, unsigned &SrcOpIdx2) const override
StringRef - Represent a constant reference to a string, i.e.
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
Register getReg() const
getReg - Returns the register number.
static bool tryConstantFoldOp(MachineRegisterInfo &MRI, const SIInstrInfo *TII, MachineInstr *MI, MachineOperand *ImmOp)
This holds information about one operand of a machine instruction, indicating the register class for ...
const MachineOperand & getOperand(unsigned i) const
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
MachineInstr * buildShrunkInst(MachineInstr &MI, unsigned NewOpcode) const
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
bool isCommutable(QueryType Type=IgnoreBundle) const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z, ..."), which produces the same result if Y and Z are exchanged.
Wrapper class representing virtual and physical registers.
static bool tryToFoldACImm(const SIInstrInfo *TII, const MachineOperand &OpToFold, MachineInstr *UseMI, unsigned UseOpIdx, SmallVectorImpl< FoldCandidate > &FoldList)
const SIRegisterInfo * getRegisterInfo() const override
static bool isFLATScratch(const MachineInstr &MI)