55 #define DEBUG_TYPE "twoaddressinstruction"
57 STATISTIC(NumTwoAddressInstrs,
"Number of two-address instructions");
58 STATISTIC(NumCommuted ,
"Number of instructions commuted to coalesce");
59 STATISTIC(NumAggrCommuted ,
"Number of instructions aggressively commuted");
60 STATISTIC(NumConvertedTo3Addr,
"Number of instructions promoted to 3-address");
61 STATISTIC(Num3AddrSunk,
"Number of 3-address instructions sunk");
62 STATISTIC(NumReSchedUps,
"Number of instructions re-scheduled up");
63 STATISTIC(NumReSchedDowns,
"Number of instructions re-scheduled down");
68 cl::desc(
"Coalesce copies by rescheduling (default=true)"),
75 cl::desc(
"Maximum number of dataflow edges to traverse when evaluating "
76 "the benefit of commuting operands"));
112 bool isRevCopyChain(
unsigned FromReg,
unsigned ToReg,
int Maxlen);
114 bool noUseAfterLastDef(
unsigned Reg,
unsigned Dist,
unsigned &LastDef);
116 bool isProfitableToCommute(
unsigned regA,
unsigned regB,
unsigned regC,
120 unsigned RegBIdx,
unsigned RegCIdx,
unsigned Dist);
122 bool isProfitableToConv3Addr(
unsigned RegA,
unsigned RegB);
126 unsigned RegA,
unsigned RegB,
unsigned Dist);
139 unsigned SrcIdx,
unsigned DstIdx,
140 unsigned Dist,
bool shouldOnlyCommute);
147 void scanUses(
unsigned DstReg);
154 void processTiedPairs(
MachineInstr *
MI, TiedPairList&,
unsigned &Dist);
182 "Two-Address instruction pass",
false,
false)
194 bool TwoAddressInstructionPass::
195 sink3AddrInstruction(
MachineInstr *MI,
unsigned SavedReg,
202 bool SeenStore =
true;
203 if (!MI->isSafeToMove(AA, SeenStore))
212 unsigned MOReg = MO.getReg();
215 if (MO.isUse() && MOReg != SavedReg)
216 UseRegs.
insert(MO.getReg());
225 DefReg = MO.getReg();
233 "Reg should not have empty live interval.");
237 if (I != LI.
end() && I->start < MBBEndIdx)
241 KillMI = LIS->getInstructionFromIndex(I->end);
255 if (!KillMI || KillMI->
getParent() != MBB || KillMI == MI ||
269 unsigned NumVisited = 0;
272 if (OtherMI.isDebugValue())
277 for (
unsigned i = 0, e = OtherMI.getNumOperands(); i != e; ++i) {
281 unsigned MOReg = MO.
getReg();
288 if (&OtherMI == KillMI && MOReg == SavedReg)
292 else if (UseRegs.
count(MOReg))
298 assert(KillMO &&
"Didn't find kill");
303 KillMO = MI->findRegisterUseOperand(SavedReg,
false, TRI);
307 LV->replaceKillInstruction(SavedReg, *KillMI, *MI);
312 MBB->insert(KillPos, MI);
315 LIS->handleMove(*MI);
326 if (DefMI.getParent() != BB || DefMI.isDebugValue())
330 else if (Ret != &DefMI)
343 bool TwoAddressInstructionPass::isRevCopyChain(
unsigned FromReg,
unsigned ToReg,
345 unsigned TmpReg = FromReg;
346 for (
int i = 0; i < Maxlen; i++) {
348 if (!Def || !Def->
isCopy())
363 bool TwoAddressInstructionPass::noUseAfterLastDef(
unsigned Reg,
unsigned Dist,
366 unsigned LastUse = Dist;
372 if (DI == DistanceMap.
end())
374 if (MO.isUse() && DI->second < LastUse)
375 LastUse = DI->second;
376 if (MO.isDef() && DI->second > LastDef)
377 LastDef = DI->second;
380 return !(LastUse > LastDef && LastUse < Dist);
387 unsigned &SrcReg,
unsigned &DstReg,
388 bool &IsSrcPhys,
bool &IsDstPhys) {
425 assert(I != LI.
end() &&
"Reg must be live-in to use.");
453 bool allowFalsePositives) {
458 (allowFalsePositives || MRI->
hasOneUse(Reg)))
467 if (std::next(Begin) != MRI->
def_end())
470 bool IsSrcPhys, IsDstPhys;
471 unsigned SrcReg, DstReg;
474 if (!
isCopyToReg(*DefMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys))
483 for (
unsigned i = 0, NumOps = MI.
getNumOperands(); i != NumOps; ++i) {
503 unsigned &DstReg,
bool &IsDstPhys) {
512 if (
isCopyToReg(UseMI, TII, SrcReg, DstReg, IsSrcPhys, IsDstPhys)) {
530 if (SI == RegMap.
end())
552 for (
unsigned R : Set)
562 TwoAddressInstructionPass::
563 isProfitableToCommute(
unsigned regA,
unsigned regB,
unsigned regC,
610 if ((!FromRegB && CompC) || (FromRegB && !CompB && (!FromRegC || CompC)))
616 if ((!FromRegC && CompB) || (FromRegC && !CompC && (!FromRegB || CompB)))
622 unsigned LastDefC = 0;
623 if (!noUseAfterLastDef(regC, Dist, LastDefC))
628 unsigned LastDefB = 0;
629 if (!noUseAfterLastDef(regB, Dist, LastDefB))
655 return LastDefB && LastDefC && LastDefC > LastDefB;
660 bool TwoAddressInstructionPass::commuteInstruction(
MachineInstr *MI,
666 DEBUG(
dbgs() <<
"2addr: COMMUTING : " << *MI);
667 MachineInstr *NewMI =
TII->commuteInstruction(*MI,
false, RegBIdx, RegCIdx);
669 if (NewMI ==
nullptr) {
670 DEBUG(
dbgs() <<
"2addr: COMMUTING FAILED!\n");
674 DEBUG(
dbgs() <<
"2addr: COMMUTED TO: " << *NewMI);
676 "TargetInstrInfo::commuteInstruction() should not return a new "
677 "instruction unless it was requested.");
683 SrcRegMap[RegA] = FromRegC;
692 TwoAddressInstructionPass::isProfitableToConv3Addr(
unsigned RegA,
unsigned RegB){
711 unsigned RegA,
unsigned RegB,
716 assert(MBB->getIterator() == MFI &&
717 "convertToThreeAddress changed iterator reference");
721 DEBUG(
dbgs() <<
"2addr: CONVERTING 2-ADDR: " << *mi);
722 DEBUG(
dbgs() <<
"2addr: TO 3-ADDR: " << *NewMI);
726 LIS->ReplaceMachineInstrInMaps(*mi, *NewMI);
732 Sunk = sink3AddrInstruction(NewMI, RegB, mi);
737 DistanceMap.insert(std::make_pair(NewMI, Dist));
743 SrcRegMap.erase(RegA);
744 DstRegMap.erase(RegB);
751 TwoAddressInstructionPass::scanUses(
unsigned DstReg) {
756 unsigned Reg = DstReg;
758 NewReg, IsDstPhys)) {
759 if (IsCopy && !Processed.insert(
UseMI).second)
763 if (DI != DistanceMap.
end())
771 bool isNew = SrcRegMap.insert(std::make_pair(NewReg, Reg)).second;
773 assert(SrcRegMap[NewReg] == Reg &&
"Can't map to two src registers!");
778 if (!VirtRegPairs.
empty()) {
779 unsigned ToReg = VirtRegPairs.
back();
781 while (!VirtRegPairs.
empty()) {
782 unsigned FromReg = VirtRegPairs.
back();
784 bool isNew = DstRegMap.insert(std::make_pair(FromReg, ToReg)).second;
786 assert(DstRegMap[FromReg] == ToReg &&
"Can't map to two dst registers!");
789 bool isNew = DstRegMap.insert(std::make_pair(DstReg, ToReg)).second;
791 assert(DstRegMap[DstReg] == ToReg &&
"Can't map to two dst registers!");
807 void TwoAddressInstructionPass::processCopy(
MachineInstr *MI) {
808 if (Processed.count(MI))
811 bool IsSrcPhys, IsDstPhys;
812 unsigned SrcReg, DstReg;
816 if (IsDstPhys && !IsSrcPhys)
817 DstRegMap.insert(std::make_pair(SrcReg, DstReg));
818 else if (!IsDstPhys && IsSrcPhys) {
819 bool isNew = SrcRegMap.insert(std::make_pair(DstReg, SrcReg)).second;
821 assert(SrcRegMap[DstReg] == SrcReg &&
822 "Can't map to two src physical registers!");
827 Processed.insert(MI);
833 bool TwoAddressInstructionPass::
844 if (DI == DistanceMap.
end())
852 "Reg should not have empty live interval.");
856 if (I != LI.
end() && I->start < MBBEndIdx)
860 KillMI = LIS->getInstructionFromIndex(I->end);
862 KillMI = LV->getVarInfo(Reg).findKill(MBB);
877 bool SeenStore =
true;
891 unsigned MOReg = MO.getReg();
898 if (MOReg != Reg && (MO.isKill() ||
909 while (End->isCopy() &&
911 Defs.
push_back(End->getOperand(0).getReg());
916 unsigned NumVisited = 0;
921 if (OtherMI.isDebugValue())
926 if (OtherMI.hasUnmodeledSideEffects() || OtherMI.isCall() ||
927 OtherMI.isBranch() || OtherMI.isTerminator())
933 unsigned MOReg = MO.getReg();
950 if (MOReg != Reg && ((isKill &&
regOverlapsSet(Uses, MOReg, TRI)) ||
954 if (MOReg == Reg && !isKill)
958 assert((MOReg != Reg || &OtherMI == KillMI) &&
959 "Found multiple kills of a register in a basic block");
965 while (Begin != MBB->begin() && std::prev(Begin)->isDebugValue())
974 auto CopyMI = MBBI++;
975 MBB->splice(InsertPos, MBB, CopyMI);
976 LIS->handleMove(*CopyMI);
983 MBB->splice(InsertPos, MBB, Begin, End);
984 DistanceMap.erase(DI);
988 LIS->handleMove(*MI);
990 LV->removeVirtualRegisterKilled(Reg, *KillMI);
991 LV->addVirtualRegisterKilled(Reg, *MI);
994 DEBUG(
dbgs() <<
"\trescheduled below kill: " << *KillMI);
1000 bool TwoAddressInstructionPass::isDefTooClose(
unsigned Reg,
unsigned Dist,
1003 if (DefMI.getParent() != MBB || DefMI.isCopy() || DefMI.isCopyLike())
1008 if (DDI == DistanceMap.
end())
1010 unsigned DefDist = DDI->second;
1011 assert(Dist > DefDist &&
"Visited def already?");
1021 bool TwoAddressInstructionPass::
1032 if (DI == DistanceMap.
end())
1040 "Reg should not have empty live interval.");
1044 if (I != LI.
end() && I->start < MBBEndIdx)
1048 KillMI = LIS->getInstructionFromIndex(I->end);
1050 KillMI = LV->getVarInfo(Reg).findKill(MBB);
1060 bool SeenStore =
true;
1071 unsigned MOReg = MO.getReg();
1075 if (isDefTooClose(MOReg, DI->second, MI))
1077 bool isKill = MO.isKill() || (LIS &&
isPlainlyKilled(KillMI, MOReg, LIS));
1078 if (MOReg == Reg && !isKill)
1081 if (isKill && MOReg != Reg)
1091 unsigned NumVisited = 0;
1095 if (OtherMI.isDebugValue())
1097 if (NumVisited > 10)
1100 if (OtherMI.hasUnmodeledSideEffects() || OtherMI.isCall() ||
1101 OtherMI.isBranch() || OtherMI.isTerminator())
1108 unsigned MOReg = MO.getReg();
1112 if (Defs.
count(MOReg))
1116 if (Kills.
count(MOReg))
1119 if (&OtherMI != MI && MOReg == Reg &&
1128 for (
unsigned i = 0, e = OtherDefs.
size(); i != e; ++i) {
1129 unsigned MOReg = OtherDefs[i];
1130 if (Uses.
count(MOReg))
1133 LiveDefs.
count(MOReg))
1142 while (InsertPos != MBB->begin() && std::prev(InsertPos)->isDebugValue())
1146 while (std::prev(From)->isDebugValue())
1148 MBB->splice(InsertPos, MBB, From, To);
1150 nmi = std::prev(InsertPos);
1151 DistanceMap.erase(DI);
1155 LIS->handleMove(*KillMI);
1157 LV->removeVirtualRegisterKilled(Reg, *KillMI);
1158 LV->addVirtualRegisterKilled(Reg, *MI);
1161 DEBUG(
dbgs() <<
"\trescheduled kill: " << *KillMI);
1177 bool TwoAddressInstructionPass::tryInstructionCommute(
MachineInstr *MI,
1189 for (; OtherOpIdx < OpsNum; OtherOpIdx++) {
1195 !
TII->findCommutedOpIndices(*MI, BaseOpIdx, OtherOpIdx))
1199 bool AggressiveCommute =
false;
1204 !BaseOpKilled &&
isKilled(*MI, OtherOpReg,
MRI,
TII, LIS,
false);
1207 isProfitableToCommute(DstOpReg, BaseOpReg, OtherOpReg, MI, Dist)) {
1209 AggressiveCommute =
true;
1213 if (DoCommute && commuteInstruction(MI, DstOpIdx, BaseOpIdx, OtherOpIdx,
1216 if (AggressiveCommute)
1231 bool TwoAddressInstructionPass::
1234 unsigned SrcIdx,
unsigned DstIdx,
1235 unsigned Dist,
bool shouldOnlyCommute) {
1244 "cannot make instruction into two-address form");
1250 bool Commuted = tryInstructionCommute(&MI, DstIdx, SrcIdx, regBKilled, Dist);
1263 if (shouldOnlyCommute)
1283 if (!regBKilled || isProfitableToConv3Addr(regA, regB)) {
1285 if (convertInstTo3Addr(mi, nmi, regA, regB, Dist)) {
1286 ++NumConvertedTo3Addr;
1311 if (MI.
mayLoad() && !regBKilled) {
1313 unsigned LoadRegIndex;
1323 DEBUG(
dbgs() <<
"2addr: UNFOLDING: " << MI);
1325 TRI->getAllocatableClass(
1326 TII->getRegClass(UnfoldMCID, LoadRegIndex, TRI, *MF));
1327 unsigned Reg =
MRI->createVirtualRegister(RC);
1329 if (!
TII->unfoldMemoryOperand(*MF, MI, Reg,
1332 DEBUG(
dbgs() <<
"2addr: ABANDONING UNFOLD\n");
1336 "Unfolded a load into multiple instructions!");
1338 NewMIs[1]->addRegisterKilled(Reg, TRI);
1342 MBB->
insert(mi, NewMIs[0]);
1343 MBB->insert(mi, NewMIs[1]);
1345 DEBUG(
dbgs() <<
"2addr: NEW LOAD: " << *NewMIs[0]
1346 <<
"2addr: NEW INST: " << *NewMIs[1]);
1349 unsigned NewDstIdx = NewMIs[1]->findRegisterDefOperandIdx(regA);
1350 unsigned NewSrcIdx = NewMIs[1]->findRegisterUseOperandIdx(regB);
1352 bool TransformResult =
1353 tryInstructionTransform(NewMI, mi, NewSrcIdx, NewDstIdx, Dist,
true);
1354 (void)TransformResult;
1355 assert(!TransformResult &&
1356 "tryInstructionTransform() should return false.");
1357 if (NewMIs[1]->getOperand(NewSrcIdx).isKill()) {
1367 if (NewMIs[0]->killsRegister(MO.
getReg()))
1368 LV->replaceKillInstruction(MO.
getReg(),
MI, *NewMIs[0]);
1371 "Kill missing after load unfold!");
1372 LV->replaceKillInstruction(MO.
getReg(),
MI, *NewMIs[1]);
1375 }
else if (LV->removeVirtualRegisterDead(MO.
getReg(),
MI)) {
1376 if (NewMIs[1]->registerDefIsDead(MO.
getReg()))
1377 LV->addVirtualRegisterDead(MO.
getReg(), *NewMIs[1]);
1380 "Dead flag missing after load unfold!");
1381 LV->addVirtualRegisterDead(MO.
getReg(), *NewMIs[0]);
1386 LV->addVirtualRegisterKilled(Reg, *NewMIs[1]);
1403 LIS->repairIntervalsInRange(MBB, Begin, End, OrigRegs);
1411 DEBUG(
dbgs() <<
"2addr: ABANDONING UNFOLD\n");
1412 NewMIs[0]->eraseFromParent();
1413 NewMIs[1]->eraseFromParent();
1425 bool TwoAddressInstructionPass::
1426 collectTiedOperands(
MachineInstr *MI, TiedOperandMap &TiedOperands) {
1428 bool AnyOps =
false;
1431 for (
unsigned SrcIdx = 0; SrcIdx < NumOps; ++SrcIdx) {
1432 unsigned DstIdx = 0;
1438 unsigned SrcReg = SrcMO.
getReg();
1439 unsigned DstReg = DstMO.
getReg();
1441 if (SrcReg == DstReg)
1444 assert(SrcReg && SrcMO.
isUse() &&
"two address instruction invalid");
1452 MRI->constrainRegClass(DstReg, RC);
1455 DEBUG(
dbgs() <<
"\t\trewrite undef:\t" << *MI);
1458 TiedOperands[SrcReg].push_back(std::make_pair(SrcIdx, DstIdx));
1466 TwoAddressInstructionPass::processTiedPairs(
MachineInstr *MI,
1467 TiedPairList &TiedPairs,
1469 bool IsEarlyClobber =
false;
1470 for (
unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
1475 bool RemovedKillFlag =
false;
1476 bool AllUsesCopied =
true;
1477 unsigned LastCopiedReg = 0;
1480 unsigned SubRegB = 0;
1481 for (
unsigned tpi = 0, tpe = TiedPairs.size(); tpi != tpe; ++tpi) {
1482 unsigned SrcIdx = TiedPairs[tpi].first;
1483 unsigned DstIdx = TiedPairs[tpi].second;
1486 unsigned RegA = DstMO.
getReg();
1497 AllUsesCopied =
false;
1500 LastCopiedReg = RegA;
1503 "cannot make instruction into two-address form");
1517 TII->get(TargetOpcode::COPY), RegA);
1520 MIB.
addReg(RegB, 0, SubRegB);
1524 assert(TRI->getMatchingSuperRegClass(RC,
MRI->getRegClass(RegA),
1526 "tied subregister must be a truncation");
1531 assert(TRI->getMatchingSuperReg(RegA, SubRegB,
MRI->getRegClass(RegB))
1532 &&
"tied subregister must be a truncation");
1539 DistanceMap.insert(std::make_pair(&*PrevMI, Dist));
1540 DistanceMap[
MI] = ++Dist;
1543 LastCopyIdx = LIS->InsertMachineInstrInMaps(*PrevMI).
getRegSlot();
1549 LIS->getInstructionIndex(*MI).
getRegSlot(IsEarlyClobber);
1550 LI.
addSegment(LiveInterval::Segment(LastCopyIdx, endIdx, VNI));
1554 DEBUG(
dbgs() <<
"\t\tprepend:\t" << *MIB);
1558 "inconsistent operand info for 2-reg pass");
1561 RemovedKillFlag =
true;
1567 MRI->constrainRegClass(RegA, RC);
1575 SrcRegMap[RegA] = RegB;
1578 if (AllUsesCopied) {
1579 if (!IsEarlyClobber) {
1586 RemovedKillFlag =
true;
1588 MO.
setReg(LastCopiedReg);
1595 if (RemovedKillFlag && LV && LV->getVarInfo(RegB).removeKill(*MI)) {
1598 LV->addVirtualRegisterKilled(RegB, *PrevMI);
1604 SlotIndex MIIdx = LIS->getInstructionIndex(*MI);
1606 assert(I != LI.
end() &&
"RegB must be live-in to use.");
1609 if (I->end == UseIdx)
1613 }
else if (RemovedKillFlag) {
1628 bool TwoAddressInstructionPass::runOnMachineFunction(
MachineFunction &Func) {
1631 MRI = &MF->getRegInfo();
1632 TII = MF->getSubtarget().getInstrInfo();
1634 InstrItins = MF->getSubtarget().getInstrItineraryData();
1635 LV = getAnalysisIfAvailable<LiveVariables>();
1636 LIS = getAnalysisIfAvailable<LiveIntervals>();
1637 if (
auto *AAPass = getAnalysisIfAvailable<AAResultsWrapperPass>())
1638 AA = &AAPass->getAAResults();
1643 bool MadeChange =
false;
1645 DEBUG(
dbgs() <<
"********** REWRITING TWO-ADDR INSTRS **********\n");
1647 << MF->getName() <<
'\n');
1652 TiedOperandMap TiedOperands;
1654 MBBI != MBBE; ++MBBI) {
1657 DistanceMap.clear();
1664 if (mi->isDebugValue()) {
1671 if (mi->isRegSequence())
1672 eliminateRegSequence(mi);
1674 DistanceMap.insert(std::make_pair(&*mi, ++Dist));
1680 if (!collectTiedOperands(&*mi, TiedOperands)) {
1685 ++NumTwoAddressInstrs;
1692 if (TiedOperands.size() == 1) {
1694 = TiedOperands.
begin()->second;
1695 if (TiedPairs.
size() == 1) {
1696 unsigned SrcIdx = TiedPairs[0].first;
1697 unsigned DstIdx = TiedPairs[0].second;
1698 unsigned SrcReg = mi->getOperand(SrcIdx).getReg();
1699 unsigned DstReg = mi->getOperand(DstIdx).getReg();
1700 if (SrcReg != DstReg &&
1701 tryInstructionTransform(mi, nmi, SrcIdx, DstIdx, Dist,
false)) {
1704 TiedOperands.clear();
1712 for (
auto &TO : TiedOperands) {
1713 processTiedPairs(&*mi, TO.second, Dist);
1714 DEBUG(
dbgs() <<
"\t\trewrite to:\t" << *mi);
1718 if (mi->isInsertSubreg()) {
1721 unsigned SubIdx = mi->getOperand(3).getImm();
1722 mi->RemoveOperand(3);
1723 assert(mi->getOperand(0).getSubReg() == 0 &&
"Unexpected subreg idx");
1724 mi->getOperand(0).setSubReg(SubIdx);
1725 mi->getOperand(0).setIsUndef(mi->getOperand(1).isUndef());
1726 mi->RemoveOperand(1);
1727 mi->setDesc(
TII->get(TargetOpcode::COPY));
1728 DEBUG(
dbgs() <<
"\t\tconvert to:\t" << *mi);
1733 TiedOperands.clear();
1739 MF->verify(
this,
"After two-address instruction pass");
1755 void TwoAddressInstructionPass::
1762 DEBUG(
dbgs() <<
"Illegal REG_SEQUENCE instruction:" << MI);
1773 bool DefEmitted =
false;
1776 unsigned SrcReg = UseMO.
getReg();
1784 bool isKill = UseMO.
isKill();
1786 for (
unsigned j = i + 2; j < e; j += 2)
1796 TII->get(TargetOpcode::COPY))
1811 LV->replaceKillInstruction(SrcReg, MI, *CopyMI);
1813 DEBUG(
dbgs() <<
"Inserted: " << *CopyMI);
1820 DEBUG(
dbgs() <<
"Turned: " << MI <<
" into an IMPLICIT_DEF");
1821 MI.
setDesc(
TII->get(TargetOpcode::IMPLICIT_DEF));
1831 LIS->repairIntervalsInRange(MBB, MBBI, EndMBBI, OrigRegs);
void push_back(const T &Elt)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
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 isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
STATISTIC(NumFunctions,"Total number of functions")
static MachineInstr * getSingleDef(unsigned Reg, MachineBasicBlock *BB, const MachineRegisterInfo *MRI)
Return the MachineInstr* if it is the single def of the Reg in current BB.
bool isConvertibleTo3Addr(QueryType Type=IgnoreBundle) const
Return true if this is a 2-address instruction which can be changed into a 3-address instruction if n...
static unsigned getMappedReg(unsigned Reg, DenseMap< unsigned, unsigned > &RegMap)
Return the physical register the specified virtual register might be mapped to.
static bool isKilled(MachineInstr &MI, unsigned Reg, const MachineRegisterInfo *MRI, const TargetInstrInfo *TII, LiveIntervals *LIS, bool allowFalsePositives)
Test if the given register value, which is used by the given instruction, is killed by the given inst...
use_instr_nodbg_iterator use_instr_nodbg_begin(unsigned RegNo) const
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
Describe properties that are true of each instruction in the target description file.
void setIsUndef(bool Val=true)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MachineInstrBuilder & add(const MachineOperand &MO) const
MachineOperand * findRegisterUseOperand(unsigned Reg, bool isKill=false, const TargetRegisterInfo *TRI=nullptr)
Wrapper for findRegisterUseOperandIdx, it returns a pointer to the MachineOperand rather than an inde...
static cl::opt< bool > EnableRescheduling("twoaddr-reschedule", cl::desc("Coalesce copies by rescheduling (default=true)"), cl::init(true), cl::Hidden)
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
VNInfo - Value Number Information.
iterator_range< mop_iterator > operands()
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
#define INITIALIZE_PASS_DEPENDENCY(depName)
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
static bool regOverlapsSet(const SmallVectorImpl< unsigned > &Set, unsigned Reg, const TargetRegisterInfo *TRI)
MCInst const & instruction(MCInst const &MCB, size_t Index)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
Reg
All possible values of the reg field in the ModR/M byte.
void initializeTwoAddressInstructionPassPass(PassRegistry &)
LLVM_NODISCARD bool empty() const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
const HexagonRegisterInfo & getRegisterInfo() const
HexagonInstrInfo specifics.
static bool regsAreCompatible(unsigned RegA, unsigned RegB, const TargetRegisterInfo *TRI)
Return true if the two registers are equal or aliased.
Two Address instruction false
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
bool isCopyLike() const
Return true if the instruction behaves like a copy.
AnalysisUsage & addPreservedID(const void *ID)
Itinerary data supplied by a subtarget to be used by a target.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
unsigned getInstrLatency(const InstrItineraryData *ItinData, const MachineInstr &MI, unsigned *PredCost=nullptr) const override
Compute the instruction latency of a given instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
iterator find(const_arg_type_t< KeyT > Val)
bool isDebugValue() const
bool isInsertSubreg() const
bool isEarlyClobber() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
MachineInstrBundleIterator< MachineInstr > iterator
bool hasAtLeastOneValue() const
bool regsOverlap(unsigned regA, unsigned regB) const
Returns true if the two registers are equal or alias each other.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
static cl::opt< unsigned > MaxDataFlowEdge("dataflow-edge-limit", cl::Hidden, cl::init(3), cl::desc("Maximum number of dataflow edges to traverse when evaluating ""the benefit of commuting operands"))
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Two Address instruction pass
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static const unsigned End
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static MachineInstr * findOnlyInterestingUse(unsigned Reg, MachineBasicBlock *MBB, MachineRegisterInfo *MRI, const TargetInstrInfo *TII, bool &IsCopy, unsigned &DstReg, bool &IsDstPhys)
Given a register, if has a single in-basic block use, return the use instruction if it's a copy or a ...
unsigned getSubReg() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
void setIsKill(bool Val=true)
iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified segment from this range.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
static bool isCopyToReg(MachineInstr &MI, const TargetInstrInfo *TII, unsigned &SrcReg, unsigned &DstReg, bool &IsSrcPhys, bool &IsDstPhys)
Return true if the specified MI is a copy instruction or an extract_subreg instruction.
Segments::const_iterator const_iterator
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 hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
LiveInterval & getInterval(unsigned Reg)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isSubregToReg() const
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
iterator insert(iterator I, T &&Elt)
def_iterator def_begin(unsigned RegNo) const
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
INITIALIZE_PASS_BEGIN(TwoAddressInstructionPass, DEBUG_TYPE,"Two-Address instruction pass", false, false) INITIALIZE_PASS_END(TwoAddressInstructionPass
bool hasOneNonDBGUse(unsigned RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void setSubReg(unsigned subReg)
static bool isPlainlyKilled(MachineInstr *MI, unsigned Reg, LiveIntervals *LIS)
Test if the given register value, which is used by the given instruction, is killed by the given inst...
char & TwoAddressInstructionPassID
TwoAddressInstruction - This pass reduces two-address instructions to use two operands.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
unsigned getReg() const
getReg - Returns the register number.
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static def_iterator def_end()
bool killsRegister(unsigned Reg, const TargetRegisterInfo *TRI=nullptr) const
Return true if the MachineInstr kills the specified register.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
iterator_range< def_instr_iterator > def_instructions(unsigned Reg) const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
bool isNotInMIMap(const MachineInstr &Instr) const
Returns true if the specified machine instr has been removed or was never entered in the map...
Primary interface to the complete machine description for the target machine.
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
SlotIndex - An opaque wrapper around machine indexes.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
static bool isTwoAddrUse(MachineInstr &MI, unsigned Reg, unsigned &DstReg)
Return true if the specified MI uses the specified register as a two-address use. ...